Changeset 149 for libmpc/branches/r2d/libmpcenc
- Timestamp:
- 11/23/06 19:17:14 (18 years ago)
- Location:
- libmpc/branches/r2d/libmpcenc
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
libmpc/branches/r2d/libmpcenc/bitstream.c
r147 r149 136 136 void writeSeekTable (mpc_encoder_t * e) 137 137 { 138 mpc_uint32_t tmp1, tmp2,i, len;138 mpc_uint32_t i, len; 139 139 mpc_uint32_t * table = e->seek_table; 140 140 mpc_uint8_t tmp[10]; 141 141 142 142 // write the position to header 143 tmp1 = ftell(e->outputFile); // get the seek table position 144 tmp[0] = (mpc_uint8_t) (tmp1 >> 24); 145 tmp[1] = (mpc_uint8_t) (tmp1 >> 16); 146 tmp[2] = (mpc_uint8_t) (tmp1 >> 8); 147 tmp[3] = (mpc_uint8_t) tmp1; 148 fseek(e->outputFile, e->seek_ref + 3, SEEK_SET); 149 fwrite(tmp, sizeof(mpc_uint8_t), 4, e->outputFile); 150 fseek(e->outputFile, tmp1, SEEK_SET); 143 i = ftell(e->outputFile); // get the seek table position 144 len = encodeSize(i - e->seek_ptr, (char*)tmp, MPC_FALSE); 145 fseek(e->outputFile, e->seek_ptr + 3, SEEK_SET); 146 fwrite(tmp, sizeof(mpc_uint8_t), len, e->outputFile); 147 fseek(e->outputFile, i, SEEK_SET); 151 148 152 tmp1 = table[0]; 153 tmp2 = table[1]; 154 155 len = encodeSize(tmp1 - e->seek_ref, tmp, MPC_FALSE); 149 // write the seek table datas 150 len = encodeSize(e->seek_pos, (char*)tmp, MPC_FALSE); 156 151 for( i = 0; i < len; i++) 157 152 writeBits ( e, tmp[i], 8 ); 158 len = encodeSize(tmp2 - e->seek_ref, tmp, MPC_FALSE); 153 writeBits ( e, e->seek_pwr, 4 ); 154 155 len = encodeSize(table[0] - e->seek_ref, (char*)tmp, MPC_FALSE); 159 156 for( i = 0; i < len; i++) 160 157 writeBits ( e, tmp[i], 8 ); 158 if (e->seek_pos > 1) { 159 len = encodeSize(table[1] - e->seek_ref, (char*)tmp, MPC_FALSE); 160 for( i = 0; i < len; i++) 161 writeBits ( e, tmp[i], 8 ); 162 } 161 163 162 164 for( i = 2; i < e->seek_pos; i++){ 163 int code = table[i] - 2 * tmp2 + tmp1; 164 tmp1 = tmp2; 165 tmp2 = table[i]; 166 if (code >= 0) { 167 writeBits(e, 0, 1); 168 encodeGolomb(e, code, 10); 169 } else { 170 writeBits(e, 1, 1); 171 encodeGolomb(e, -code, 10); 172 } 165 int code = (table[i] - 2 * table[i-1] + table[i-2]) << 1; 166 if (code < 0) 167 code = -code | 1; 168 encodeGolomb(e, code, 12); 173 169 } 174 170 } -
libmpc/branches/r2d/libmpcenc/encode_sv7.c
r147 r149 76 76 e->Overflows = 0; 77 77 e->seek_pos = 0; 78 } 79 78 e->block_cnt = 0; 79 e->seek_pwr = 1; 80 } 81 82 // writes replay gain info 83 static void writeGainInfo ( mpc_encoder_t * e ) 84 { 85 writeBits ( e, 1, 8 ); // version 86 writeBits ( e, 0, 16 ); // Title gain 87 writeBits ( e, 0, 16 ); // Title peak 88 writeBits ( e, 0, 16 ); // Album gain 89 writeBits ( e, 0, 16 ); // Album peak 90 } 80 91 81 92 // writes SV8-header … … 88 99 const unsigned int ChannelCount) 89 100 { 90 unsigned char samplesCount[10]; 91 int samplesCountLen = encodeSize(SamplesCount, (char *)samplesCount, MPC_FALSE); 92 int i; 101 unsigned char tmp[10]; 102 int i, len = encodeSize(SamplesCount, (char *)tmp, MPC_FALSE); 103 104 len = encodeSize(len + 4, (char *)tmp, MPC_TRUE); 105 writeBits ( e, tmp[0] , 8 ); 93 106 94 107 writeBits ( e, 0x08, 8 ); // StreamVersion 95 108 96 for( i = 0; i < samplesCountLen; i++) // nb of samples 97 writeBits ( e, samplesCount[i] , 8 ); 109 len = encodeSize(SamplesCount, (char *)tmp, MPC_FALSE); 110 for( i = 0; i < len; i++) // nb of samples 111 writeBits ( e, tmp[i] , 8 ); 98 112 99 113 switch ( SampleFreq ) { … … 110 124 writeBits ( e, MS_on , 1 ); // MS-Coding Flag 111 125 writeBits ( e, FRAMES_PER_BLOCK_PWR, 4 ); // frames per block (log2 unit) 126 writeBits ( e, 0, 6 ); // unused 127 128 writeGainInfo(e); 112 129 } 113 130 … … 128 145 writeBits ( e, version_implement, 4 ); 129 146 writeBits ( e, version_build, 8 ); 130 }131 132 // writes replay gain info133 void writeGainInfo ( mpc_encoder_t * e )134 {135 writeBits ( e, 1, 8 ); // version136 writeBits ( e, 0, 16 ); // Title gain137 writeBits ( e, 0, 16 ); // Title peak138 writeBits ( e, 0, 16 ); // Album gain139 writeBits ( e, 0, 16 ); // Album peak140 147 } 141 148 … … 417 424 e->framesInBlock++; 418 425 if (e->framesInBlock == FRAMES_PER_BLOCK) { 419 e->seek_table[e->seek_pos] = ftell(e->outputFile); 420 e->seek_pos++; 426 if ((e->block_cnt & ((1 << e->seek_pwr) - 1)) == 0) { 427 e->seek_table[e->seek_pos] = ftell(e->outputFile); 428 e->seek_pos++; 429 } 430 e->block_cnt++; 421 431 writeBlock(e, "AD", MPC_FALSE); 422 432 } -
libmpc/branches/r2d/libmpcenc/libmpcenc.h
r147 r149 57 57 mpc_uint32_t seek_pos; /// current position in the seek table 58 58 mpc_uint32_t seek_ref; /// reference position for the seek information 59 mpc_uint32_t seek_ptr; /// position of the seek pointer block 60 mpc_uint32_t seek_pwr; /// keep a seek table entry every 2^seek_pwr block 61 mpc_uint32_t block_cnt; /// number of encoded blocks 59 62 60 63 FILE * outputFile; // ouput file
Note: See TracChangeset
for help on using the changeset viewer.