Changeset 78 for mppenc/branches/r2d/libmpcenc
- Timestamp:
- 10/27/06 18:42:05 (18 years ago)
- Location:
- mppenc/branches/r2d/libmpcenc
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
mppenc/branches/r2d/libmpcenc/Makefile.am
r76 r78 2 2 METASOURCES = AUTO 3 3 lib_LIBRARIES = libmpcenc.a 4 libmpcenc_a_SOURCES = analy_filter.c bitstream.c encode_sv7.c huffsv7.c quant.c 4 libmpcenc_a_SOURCES = analy_filter.c bitstream.c encode_sv7.c huffsv7.c quant.c \ 5 crc32.c 5 6 6 7 -
mppenc/branches/r2d/libmpcenc/bitstream.c
r71 r78 23 23 #include "stdio.h" 24 24 25 unsigned long crc32(unsigned char *buf, int len); 25 26 26 /* 27 * Change_Endian32() changes the endianess of a 32-bit memory block in-place 28 * by swapping the byte order. This is a little bit tricky, but a well 29 * known method which is much much faster, especially on modern CPUs, than 30 * byte picking, because it avoids memory aliasing. Note that this method 31 * is poison for old 16-bit compilers! 32 */ 33 34 #if ENDIAN == HAVE_BIG_ENDIAN 35 36 static void 37 Change_Endian32 ( unsigned int* dst, mpc_size_t words32bit ) 27 void emptyBits(mpc_encoder_t * e) 38 28 { 39 for ( ; words32bit--; dst++ ) { 40 # if INT_MAX >= 2147483647L 41 unsigned int tmp = *dst; 42 tmp = ((tmp << 0x10) & 0xFFFF0000) | ((tmp >> 0x10) & 0x0000FFFF); 43 tmp = ((tmp << 0x08) & 0xFF00FF00) | ((tmp >> 0x08) & 0x00FF00FF); 44 *dst = tmp; 45 # else 46 char tmp; 47 tmp = ((char*)dst)[0]; 48 ((char*)dst)[0] = ((char*)dst)[3]; 49 ((char*)dst)[3] = tmp; 50 tmp = ((char*)dst)[1]; 51 ((char*)dst)[1] = ((char*)dst)[2]; 52 ((char*)dst)[2] = tmp; 53 # endif 54 } 55 return; 29 while( e->bitsCount >= 8 ){ 30 e->bitsCount -= 8; 31 e->buffer[e->pos] = (mpc_uint8_t) (e->bitsBuff >> e->bitsCount); 32 e->pos++; 33 } 56 34 } 57 35 58 #endif /* ENDIAN == HAVE_BIG_ENDIAN */ 36 void writeBits (mpc_encoder_t * e, mpc_uint32_t input, unsigned int bits ) 37 { 38 e->outputBits += bits; 39 40 if (e->bitsCount + bits > sizeof(e->bitsBuff) * 8) { 41 int tmp = (sizeof(e->bitsBuff) * 8 - e->bitsCount); 42 bits -= tmp; 43 e->bitsBuff = (e->bitsBuff << tmp) | (input >> bits); 44 e->bitsCount = sizeof(e->bitsBuff) * 8; 45 emptyBits(e); 46 input &= (1 << bits) - 1; 47 } 48 e->bitsBuff = (e->bitsBuff << bits) | input; 49 e->bitsCount += bits; 50 } 51 52 unsigned int encodeSize(mpc_uint64_t size, char * buff, mpc_bool_t addCodeSize) 53 { 54 unsigned int i = 1; 55 int j; 56 57 if (addCodeSize) { 58 while ((1 << (7 * i)) - i <= size) i++; 59 size += i; 60 } else 61 while ((1 << (7 * i)) <= size) i++; 62 63 for( j = i - 1; j >= 0; j--){ 64 buff[j] = (char) (size | 0x80); 65 size >>= 7; 66 } 67 buff[i - 1] &= 0x7F; 68 69 return i; 70 } 71 72 void writeMagic(mpc_encoder_t * e) 73 { 74 fwrite("MPCK", sizeof(char), 4, e->outputFile); 75 e->outputBits += 32; 76 e->framesInBlock = 0; 77 } 78 79 void writeBlock ( mpc_encoder_t * e, const char * key, const mpc_bool_t addCRC) 80 { 81 FILE * fp = e->outputFile; 82 mpc_uint32_t written = 0; 83 mpc_uint8_t * datas = e->buffer; 84 char blockSize[10]; 85 mpc_uint_t len; 86 87 writeBits(e, 0, (8 - e->bitsCount) % 8); 88 emptyBits(e); 89 90 // write block header (key / length) 91 len = encodeSize(e->pos + 2, blockSize, TRUE); 92 fwrite(key, sizeof(char), 2, fp); 93 fwrite(blockSize, sizeof(char), len, fp); 94 e->outputBits += (len + 2) * 8; 59 95 60 96 61 void 62 FlushBitstream ( FILE* fp, const mpc_uint32_t* buffer, mpc_size_t words32bit ) 63 { 64 mpc_size_t WrittenDwords = 0; 65 const mpc_uint32_t* p = buffer; 66 #if ENDIAN == HAVE_BIG_ENDIAN 67 mpc_size_t CC = words32bit; 68 #endif 97 if (addCRC) { 98 char tmp[4]; 99 unsigned long CRC32 = crc32((unsigned char *) e->buffer, e->pos); 100 tmp[0] = (char) (CRC32 >> 24); 101 tmp[1] = (char) (CRC32 >> 16); 102 tmp[2] = (char) (CRC32 >> 8); 103 tmp[3] = (char) CRC32; 104 fwrite(tmp, sizeof(char), 4, fp); 105 e->outputBits += 32; 106 } 69 107 70 #if ENDIAN == HAVE_BIG_ENDIAN 71 Change_Endian32 ( (mpc_uint32_t*)buffer, CC ); 72 #endif 73 74 // Write e->Buffer 75 do { 76 WrittenDwords = fwrite ( p, sizeof(*buffer), words32bit, fp ); 77 if ( WrittenDwords == 0 ) { 78 // FIXME : move stderr_printf to common 79 // stderr_printf ( "\b\n WARNING: Disk full?, retry after 10 sec ...\a" ); 108 // write datas 109 while ( e->pos != 0 ) { 110 written = fwrite ( datas, sizeof(*e->buffer), e->pos, fp ); 111 if ( written == 0 ) { 80 112 sprintf(stderr, "\b\n WARNING: Disk full?, retry after 10 sec ...\a"); 81 113 sleep (10); 82 114 } 83 if ( WrittenDwords> 0 ) {84 p += WrittenDwords;85 words32bit -= WrittenDwords;115 if ( written > 0 ) { 116 datas += written; 117 e->pos -= written; 86 118 } 87 } while ( words32bit != 0 ); 88 89 #if ENDIAN == HAVE_BIG_ENDIAN 90 Change_Endian32 ( (mpc_uint32_t*)buffer, CC ); 91 #endif 92 } 93 94 95 void 96 UpdateHeader ( FILE* fp, mpc_uint32_t Frames, mpc_uint_t ValidSamples ) 97 { 98 mpc_uint8_t buff [4]; 99 100 // Write framecount to header 101 if ( fseek ( fp, 4L, SEEK_SET ) < 0 ) 102 return; 103 104 buff [0] = (mpc_uint8_t)(Frames >> 0); 105 buff [1] = (mpc_uint8_t)(Frames >> 8); 106 buff [2] = (mpc_uint8_t)(Frames >> 16); 107 buff [3] = (mpc_uint8_t)(Frames >> 24); 108 109 fwrite ( buff, 1, 4, fp ); 110 111 // Write ValidSamples to header 112 if ( fseek ( fp, 22L, SEEK_SET ) < 0 ) 113 return; 114 fread ( buff, 1, 2, fp ); 115 if ( ferror(fp) ) 116 return; 117 if ( fseek ( fp, 22L, SEEK_SET ) < 0 ) 118 return; 119 120 ValidSamples <<= 4; 121 ValidSamples |= 0x800F & (((mpc_uint_t) buff[1] << 8) | buff[0]); 122 buff [0] = (mpc_uint8_t)(ValidSamples >> 0); 123 buff [1] = (mpc_uint8_t)(ValidSamples >> 8); 124 125 fwrite ( buff, 1, 2, fp ); 126 127 128 // Set filepointer to end of file (dirty method, should be old position!!) 129 fseek ( fp, 0L, SEEK_END ); 130 } 131 132 133 void WriteBits (mpc_encoder_t * e, const mpc_uint32_t input, const unsigned int bits ) 134 { 135 e->BufferedBits += bits; 136 e->filled -= bits; 137 138 if ( e->filled > 0 ) { 139 e->dword |= input << e->filled; 140 } 141 else if ( e->filled < 0 ) { 142 e->Buffer [e->Zaehler++] = e->dword | ( input >> -e->filled ); 143 e->filled += 32; 144 e->dword = input << e->filled; 145 } 146 else { 147 e->Buffer [e->Zaehler++] = e->dword | input; 148 e->filled = 32; 149 e->dword = 0; 150 } 151 } 152 153 // Bits in the original stream have to be 0, maximum X bits allowed to be set in input 154 // Actual bitstream must have already written ptr[0] and ptr[1] 155 void WriteBitsAt (mpc_encoder_t * e, const mpc_uint32_t input, const unsigned int bits, BitstreamPos const pos ) 156 { 157 mpc_uint32_t* ptr = pos.ptr; 158 int filled = pos.bit - bits; 159 160 // fprintf ( stderr, "%5u %2u %08lX %2u\n", input, bits, pos.ptr, pos.bit ); 161 162 e->Buffer [e->Zaehler] = e->dword; 163 164 if ( filled > 0 ) { 165 ptr [0] |= input << ( +filled); 166 } 167 else if ( filled < 0 ) { 168 ptr [0] |= input >> ( -filled); 169 ptr [1] |= input << (32+filled); 170 } 171 else { 172 ptr [0] |= input; 173 } 174 175 e->dword = e->Buffer [e->Zaehler]; 176 } 177 178 179 void GetBitstreamPos (mpc_encoder_t * e, BitstreamPos* const pos ) 180 { 181 pos -> ptr = e->Buffer + e->Zaehler; 182 pos -> bit = e->filled; 119 } 120 e->framesInBlock = 0; 183 121 } 184 122 -
mppenc/branches/r2d/libmpcenc/encode_sv7.c
r77 r78 23 23 #include "libmpcenc.h" 24 24 25 void WriteBits ( mpc_encoder_t*, const mpc_uint32_t input, const unsigned int bits ); 25 // bitstream.c 26 void writeBits (mpc_encoder_t * e, mpc_uint32_t input, unsigned int bits ); 27 unsigned int encodeSize(mpc_uint64_t, char *, mpc_bool_t); 28 void writeBlock ( mpc_encoder_t * e, const char * key, const mpc_bool_t addCRC); 29 26 30 void Init_Huffman_Encoder_SV7 ( void ); 27 31 … … 58 62 59 63 60 // initialize SV 764 // initialize SV8 61 65 void 62 Init_SV 7( mpc_encoder_t * e )66 Init_SV8 ( mpc_encoder_t * e ) 63 67 { 64 68 Init_Huffman_Encoder_SV7 (); … … 66 70 Klemm (); 67 71 68 e-> dword= 0;69 e-> filled = 32;70 e-> Zaehler= 0;71 e-> BufferedBits= 0;72 e->pos = 0; 73 e->bitsCount = 0; 74 e->outputBits = 0; 75 e->bitsBuff = 0; 72 76 e->Overflows = 0; 73 77 } 74 78 75 79 76 // writes SV 7-header80 // writes SV8-header 77 81 void 78 WriteHeader_SV 7( mpc_encoder_t*e,82 WriteHeader_SV8 ( mpc_encoder_t*e, 79 83 const unsigned int MaxBand, 80 const unsigned int Profile,81 84 const unsigned int MS_on, 82 const mpc_uint32_t TotalFrames, 83 const unsigned int SamplesRest, 85 const unsigned int SamplesCount, 84 86 const unsigned int StreamVersion, 85 const unsigned int SampleFreq ) 87 const unsigned int PNS_on, 88 const unsigned int SampleFreq, 89 const unsigned int ChannelCount) 86 90 { 87 WriteBits ( e, StreamVersion, 8 ); // StreamVersion 88 WriteBits ( e, 0x2B504D , 24 ); // Magic Number "MP+" 89 90 WriteBits ( e, TotalFrames , 32 ); // # of frames 91 92 WriteBits ( e, 0 , 1 ); // former IS-Flag (not supported anymore) 93 WriteBits ( e, MS_on , 1 ); // MS-Coding Flag 94 WriteBits ( e, MaxBand , 6 ); // Bandwidth 95 96 #if 0 97 if ( MPPENC_VERSION [3] & 1 ) 98 WriteBits ( e, 1 , 4 ); // 1: Experimental profile 99 else 100 #endif 101 102 WriteBits ( e, Profile , 4 ); // 5...15: below Telephone...above BrainDead 103 WriteBits ( e, 0 , 2 ); // for future use 104 switch ( SampleFreq ) { 105 case 44100: WriteBits ( e, 0, 2 ); break; 106 case 48000: WriteBits ( e, 1, 2 ); break; 107 case 37800: WriteBits ( e, 2, 2 ); break; 108 case 32000: WriteBits ( e, 3, 2 ); break; 91 unsigned char samplesCount[10]; 92 int samplesCountLen = encodeSize(SamplesCount, (char *)samplesCount, FALSE); 93 int i; 94 95 writeBits ( e, StreamVersion, 8 ); // StreamVersion 96 97 for( i = 0; i < samplesCountLen; i++) // nb of samples 98 writeBits ( e, samplesCount[i] , 8 ); 99 100 switch ( SampleFreq ) { 101 case 44100: writeBits ( e, 0, 4 ); break; 102 case 48000: writeBits ( e, 1, 4 ); break; 103 case 37800: writeBits ( e, 2, 4 ); break; 104 case 32000: writeBits ( e, 3, 4 ); break; 109 105 default : sprintf(stderr, "Internal error\n");// FIXME : stderr_printf ( "Internal error\n"); 110 exit (1); 111 } 112 WriteBits ( e, 0 , 16 ); // maximum input sample value, currently filled by replaygain 113 114 WriteBits ( e, 0 , 32 ); // title based gain controls, currently filled by replaygain 115 116 WriteBits ( e, 0 , 32 ); // album based gain controls, currently filled by replaygain 117 118 WriteBits ( e, 1 , 1 ); // true gapless: used? 119 WriteBits ( e, SamplesRest , 11 ); // true gapless: valid samples in last frame 120 WriteBits ( e, 1 , 1 ); // we now support fast seeking 121 WriteBits ( e, 0 , 19 ); 122 123 WriteBits ( e, (MPPENC_VERSION[0]&15)*100 + (MPPENC_VERSION[2]&15)*10 + (MPPENC_VERSION[3]&15), 124 8 ); // for future use 106 exit (1); 107 } 108 109 writeBits ( e, ChannelCount - 1 , 4 ); // Channels 110 writeBits ( e, MaxBand - 1 , 5 ); // Bandwidth 111 writeBits ( e, 0 , 1 ); // former IS-Flag (not supported anymore) 112 writeBits ( e, MS_on , 1 ); // MS-Coding Flag 113 writeBits ( e, PNS_on , 1 ); // PNS flag 114 writeBits ( e, FRAMES_PER_BLOCK_PWR, 4 ); // frames per block (log2 unit) 125 115 } 126 127 128 void129 FinishBitstream ( mpc_encoder_t* e )130 {131 e->Buffer [e->Zaehler++] = e->dword; // Assigning the "last" word132 }133 134 116 135 117 #define ENCODE_SCF1( new, old, rll ) \ 136 118 d = new - old + 7; \ 137 if ( d <= 14u && rll < 32) { \ 138 WriteBits ( e, Table[d].Code, Table[d].Length ); \ 139 } \ 140 else { \ 119 if ( d <= 14u && rll < 1) { \ 120 writeBits ( e, Table[d].Code, Table[d].Length ); \ 121 } else { \ 141 122 if ( new < 0 ) new = 0, e->Overflows++; \ 142 WriteBits ( e, Table[15].Code, Table[15].Length ); \143 WriteBits ( e, (unsigned int)new, 6 ); \123 writeBits ( e, Table[15].Code, Table[15].Length ); \ 124 writeBits ( e, (unsigned int)new, 6 ); \ 144 125 rll = 0; \ 145 126 } … … 148 129 d = new - old + 7; \ 149 130 if ( d <= 14u ) { \ 150 WriteBits ( e, Table[d].Code, Table[d].Length ); \ 151 } \ 152 else { \ 131 writeBits ( e, Table[d].Code, Table[d].Length ); \ 132 } else { \ 153 133 if ( new < 0 ) new = 0, e->Overflows++; \ 154 WriteBits ( e, Table[15].Code, Table[15].Length ); \155 WriteBits ( e, (unsigned int)new, 6 ); \134 writeBits ( e, Table[15].Code, Table[15].Length ); \ 135 writeBits ( e, (unsigned int)new, 6 ); \ 156 136 rll = 0; \ 157 137 } 158 159 160 static void161 test ( const int* const Res, const unsigned int* q )162 {163 #if 0164 int i;165 166 switch ( *Res ) {167 case 1:168 for ( i = 0; i < 36; i ++ )169 if ( q[i] != 1 )170 return;171 fprintf ( stderr, "Alles Nullsamples, aber Auflï¿œung = %u\n", *Res );172 *Res = 0;173 break;174 case 2:175 for ( i = 0; i < 36; i ++ )176 if ( q[i] != 2 )177 return;178 fprintf ( stderr, "Alles Nullsamples, aber Auflï¿œung = %u\n", *Res );179 *Res = 0;180 break;181 }182 #endif183 }184 138 185 139 … … 204 158 205 159 /************************************ Resolution *********************************/ 206 WriteBits ( e, (unsigned int)Res_L[0], 4 ); // subband 0207 WriteBits ( e, (unsigned int)Res_R[0], 4 );160 writeBits ( e, (unsigned int)Res_L[0], 4 ); // subband 0 161 writeBits ( e, (unsigned int)Res_R[0], 4 ); 208 162 if ( e->MS_Channelmode > 0 && !(Res_L[0]==0 && Res_R[0]==0) ) 209 WriteBits ( e, MS_Flag[0] , 1 );163 writeBits ( e, MS_Flag[0] , 1 ); 210 164 211 165 Table = HuffHdr; // subband 1...MaxBand 212 166 for ( n = 1; n <= MaxBand; n++ ) { 213 test ( Res_L+n, Q[n].L );214 215 167 d = Res_L[n] - Res_L[n-1] + 5; 216 168 if ( d <= 8u ) { 217 WriteBits ( e, Table[d].Code, Table[d].Length );169 writeBits ( e, Table[d].Code, Table[d].Length ); 218 170 } 219 171 else { 220 WriteBits ( e, Table[9].Code, Table[9].Length ); 221 WriteBits ( e, Res_L[n] , 4 ); 222 } 223 224 test ( Res_R+n, Q[n].R ); 172 writeBits ( e, Table[9].Code, Table[9].Length ); 173 writeBits ( e, Res_L[n] , 4 ); 174 } 175 225 176 d = Res_R[n] - Res_R[n-1] + 5; 226 177 if ( d <= 8u ) { 227 WriteBits ( e, Table[d].Code, Table[d].Length );178 writeBits ( e, Table[d].Code, Table[d].Length ); 228 179 } 229 180 else { 230 WriteBits ( e, Table[9].Code, Table[9].Length );231 WriteBits ( e, Res_R[n] , 4 );181 writeBits ( e, Table[9].Code, Table[9].Length ); 182 writeBits ( e, Res_R[n] , 4 ); 232 183 } 233 184 if ( e->MS_Channelmode > 0 && !(Res_L[n]==0 && Res_R[n]==0) ) 234 WriteBits ( e, MS_Flag[n], 1 );185 writeBits ( e, MS_Flag[n], 1 ); 235 186 } 236 187 … … 240 191 if ( Res_L[n] ) { 241 192 SCFI_L[n] = 2 * (SCF_Index_L[n][0] == SCF_Index_L[n][1]) + (SCF_Index_L[n][1] == SCF_Index_L[n][2]); 242 WriteBits ( e, Table[SCFI_L[n]].Code, Table[SCFI_L[n]].Length );193 writeBits ( e, Table[SCFI_L[n]].Code, Table[SCFI_L[n]].Length ); 243 194 } 244 195 if ( Res_R[n] ) { 245 196 SCFI_R[n] = 2 * (SCF_Index_R[n][0] == SCF_Index_R[n][1]) + (SCF_Index_R[n][1] == SCF_Index_R[n][2]); 246 WriteBits ( e, Table[SCFI_R[n]].Code, Table[SCFI_R[n]].Length );197 writeBits ( e, Table[SCFI_R[n]].Code, Table[SCFI_R[n]].Length ); 247 198 } 248 199 } … … 250 201 /************************************* SCF **********************************/ 251 202 Table = HuffDSCF; 252 for ( n = 0; n <= MaxBand; n++ ) { 203 for ( n = 0; n <= MaxBand; n++ ) { 204 if (e->framesInBlock == 0){ 205 DSCF_RLL_L[n] = DSCF_RLL_R[n] = 1; // new block -> force key frame 206 } 253 207 254 208 if ( Res_L[n] ) { … … 276 230 } 277 231 } 278 if (DSCF_RLL_L[n] <= 32)279 DSCF_RLL_L[n]++; // Increased counters for SCF that haven't been initialized again280 232 281 233 if ( Res_R[n] ) { … … 303 255 } 304 256 } 305 if (DSCF_RLL_R[n] <= 32)306 DSCF_RLL_R[n]++; // Increased counters for SCF that haven't been freshly initialized307 257 } 308 258 … … 326 276 } 327 277 book = sum >= 0; 328 WriteBits ( e, book, 1 );278 writeBits ( e, book, 1 ); 329 279 Table = HuffQ [book][1]; 330 280 for ( k = 0; k < 36; k += 3 ) { 331 281 idx = q[k+0] + 3*q[k+1] + 9*q[k+2]; 332 WriteBits ( e, Table[idx].Code, Table[idx].Length );282 writeBits ( e, Table[idx].Code, Table[idx].Length ); 333 283 } 334 284 break; … … 342 292 } 343 293 book = sum >= 0; 344 WriteBits ( e, book, 1 );294 writeBits ( e, book, 1 ); 345 295 Table = HuffQ [book][2]; 346 296 for ( k = 0; k < 36; k += 2 ) { 347 297 idx = q[k+0] + 5*q[k+1]; 348 WriteBits ( e, Table[idx].Code, Table[idx].Length );298 writeBits ( e, Table[idx].Code, Table[idx].Length ); 349 299 } 350 300 break; … … 361 311 } 362 312 book = sum >= 0; 363 WriteBits ( e, book, 1 );313 writeBits ( e, book, 1 ); 364 314 Table = HuffQ [book][Res_L[n]]; 365 315 for ( k = 0; k < 36; k++ ) { 366 316 idx = q[k]; 367 WriteBits ( e, Table[idx].Code, Table[idx].Length );317 writeBits ( e, Table[idx].Code, Table[idx].Length ); 368 318 } 369 319 break; 370 320 default: 371 321 for ( k = 0; k < 36; k++ ) 372 WriteBits ( e, q[k], Res_L[n]-1 );322 writeBits ( e, q[k], Res_L[n]-1 ); 373 323 break; 374 324 } … … 390 340 } 391 341 book = sum >= 0; 392 WriteBits ( e, book, 1 );342 writeBits ( e, book, 1 ); 393 343 Table = HuffQ [book][1]; 394 344 for ( k = 0; k < 36; k += 3 ) { 395 345 idx = q[k+0] + 3*q[k+1] + 9*q[k+2]; 396 WriteBits ( e, Table[idx].Code, Table[idx].Length );346 writeBits ( e, Table[idx].Code, Table[idx].Length ); 397 347 } 398 348 break; … … 406 356 } 407 357 book = sum >= 0; 408 WriteBits ( e, book, 1 );358 writeBits ( e, book, 1 ); 409 359 Table = HuffQ [book][2]; 410 360 for ( k = 0; k < 36; k += 2 ) { 411 361 idx = q[k+0] + 5*q[k+1]; 412 WriteBits ( e, Table[idx].Code, Table[idx].Length );362 writeBits ( e, Table[idx].Code, Table[idx].Length ); 413 363 } 414 364 break; … … 425 375 } 426 376 book = sum >= 0; 427 WriteBits ( e, book, 1 );377 writeBits ( e, book, 1 ); 428 378 Table = HuffQ [book][Res_R[n]]; 429 379 for ( k = 0; k < 36; k++ ) { 430 380 idx = q[k]; 431 WriteBits ( e, Table[idx].Code, Table[idx].Length );381 writeBits ( e, Table[idx].Code, Table[idx].Length ); 432 382 } 433 383 break; 434 384 default: 435 385 for ( k = 0; k < 36; k++ ) 436 WriteBits ( e, q[k], Res_R[n] - 1 );386 writeBits ( e, q[k], Res_R[n] - 1 ); 437 387 break; 438 388 } 439 389 440 390 } 441 return; 391 392 e->framesInBlock++; 393 if (e->framesInBlock == FRAMES_PER_BLOCK) 394 writeBlock(e, "AD", FALSE); 442 395 } 443 396 -
mppenc/branches/r2d/libmpcenc/huffsv7.c
r76 r78 62 62 #endif 63 63 64 static const Huff Src_t HuffSCFI_src [4] = {64 static const Huffman_t HuffSCFI_src [4] = { 65 65 { 2, 3 }, { 1, 1 }, { 3, 3 }, { 0, 2 } 66 66 }; 67 67 68 static const Huff Src_t HuffDSCF_src [16] = {68 static const Huffman_t HuffDSCF_src [16] = { 69 69 { 32, 6 }, { 4, 5 }, { 17, 5 }, { 30, 5 }, { 13, 4 }, { 0, 3 }, { 3, 3 }, { 9, 4 }, 70 70 { 5, 3 }, { 2, 3 }, { 14, 4 }, { 3, 4 }, { 31, 5 }, { 5, 5 }, { 33, 6 }, { 12, 4 } 71 71 }; 72 72 73 static const Huff Src_t HuffHdr_src [10] = {73 static const Huffman_t HuffHdr_src [10] = { 74 74 { 92, 8 }, { 47, 7 }, { 10, 5 }, { 4, 4 }, { 0, 2 }, 75 75 { 1, 1 }, { 3, 3 }, { 22, 6 }, { 187, 9 }, { 186, 9 } 76 76 }; 77 77 78 static const Huff Src_t HuffQ1_src [2] [3*3*3] = { {78 static const Huffman_t HuffQ1_src [2] [3*3*3] = { { 79 79 { 54, 6 }, { 9, 5 }, { 32, 6 }, { 5, 5 }, { 10, 4 }, { 7, 5 }, { 52, 6 }, { 0, 5 }, { 35, 6 }, 80 80 { 10, 5 }, { 6, 4 }, { 4, 5 }, { 11, 4 }, { 7, 3 }, { 12, 4 }, { 3, 5 }, { 7, 4 }, { 11, 5 }, … … 86 86 } }; 87 87 88 static const Huff Src_t HuffQ2_src [2] [5*5] = { {88 static const Huffman_t HuffQ2_src [2] [5*5] = { { 89 89 { 89, 7 }, { 47, 6 }, { 15, 5 }, { 0, 5 }, { 91, 7 }, 90 90 { 4, 5 }, { 6, 4 }, { 13, 4 }, { 4, 4 }, { 5, 5 }, … … 101 101 102 102 #ifdef USE_SV8 103 static const Huff Src_t HuffN3_src [2] [7*7] = { {103 static const Huffman_t HuffN3_src [2] [7*7] = { { 104 104 { 78, 7 }, { 20, 6 }, { 36, 6 }, { 51, 6 }, { 21, 6 }, { 101, 7 }, { 255, 8 }, 105 105 { 37, 6 }, { 0, 5 }, { 62, 6 }, { 7, 5 }, { 60, 6 }, { 49, 6 }, { 100, 7 }, … … 120 120 #endif 121 121 122 static const Huff Src_t HuffQ3_src [2] [ 7] = { {122 static const Huffman_t HuffQ3_src [2] [ 7] = { { 123 123 { 12, 4 }, { 4, 3 }, { 0, 2 }, { 1, 2 }, { 7, 3 }, { 5, 3 }, { 13, 4 } 124 124 }, { … … 126 126 } }; 127 127 128 static const Huff Src_t HuffQ4_src [2] [ 9] = { {128 static const Huffman_t HuffQ4_src [2] [ 9] = { { 129 129 { 5, 4 }, { 0, 3 }, { 4, 3 }, { 6, 3 }, { 7, 3 }, { 5, 3 }, { 3, 3 }, { 1, 3 }, { 4, 4 } 130 130 }, { … … 132 132 } }; 133 133 134 static const Huff Src_t HuffQ5_src [2] [15] = { {134 static const Huffman_t HuffQ5_src [2] [15] = { { 135 135 { 57, 6 }, { 23, 5 }, { 8, 4 }, { 10, 4 }, { 13, 4 }, { 0, 3 }, { 2, 3 }, { 3, 3 }, 136 136 { 1, 3 }, { 15, 4 }, { 12, 4 }, { 9, 4 }, { 29, 5 }, { 22, 5 }, { 56, 6 } … … 140 140 } }; 141 141 142 static const Huff Src_t HuffQ6_src [2] [31] = { {142 static const Huffman_t HuffQ6_src [2] [31] = { { 143 143 { 65, 7 }, { 6, 6 }, { 44, 6 }, { 45, 6 }, { 59, 6 }, { 13, 5 }, { 17, 5 }, { 19, 5 }, 144 144 { 23, 5 }, { 21, 5 }, { 26, 5 }, { 30, 5 }, { 0, 4 }, { 2, 4 }, { 5, 4 }, { 7, 4 }, … … 152 152 } }; 153 153 154 static const Huff Src_t HuffQ7_src [2] [63] = { {154 static const Huffman_t HuffQ7_src [2] [63] = { { 155 155 { 103, 8 }, // 0.3338 01100111 156 156 { 153, 8 }, // 0.3766 10011001 … … 283 283 284 284 #ifdef USE_SV8 285 static const Huff Src_t HuffN8_src [2] [127] = { {285 static const Huffman_t HuffN8_src [2] [127] = { { 286 286 { 2426, 13 }, { 4943, 13 }, { 787, 12 }, { 2470, 12 }, { 7270, 13 }, { 1764, 12 }, 287 287 { 3632, 12 }, { 3633, 12 }, { 2486, 12 }, { 395, 11 }, { 607, 11 }, { 1242, 11 }, … … 341 341 */ 342 342 343 void Make_HuffTable ( Huffman_t* dst, const Huff Src_t* src, mpc_size_t len )343 void Make_HuffTable ( Huffman_t* dst, const Huffman_t* src, mpc_size_t len ) 344 344 { 345 345 mpc_size_t i; -
mppenc/branches/r2d/libmpcenc/libmpcenc.h
r71 r78 20 20 21 21 #include "config_types.h" 22 #include <stdio.h> 22 23 23 24 // FIXME : define this somewhere else … … 32 33 33 34 // bitstream.c 34 #define BUFFER_ALMOST_FULL 8192 35 #define BUFFER_FULL (BUFFER_ALMOST_FULL + 4352) // 34490 bit/frame 1320.3 kbps 36 37 #ifndef ENDIAN 38 #define HAVE_LITTLE_ENDIAN 1234 39 #define HAVE_BIG_ENDIAN 4321 40 41 #define ENDIAN HAVE_LITTLE_ENDIAN 42 #endif 43 44 // bitstream.c 45 typedef struct { 46 mpc_uint32_t* ptr; 47 unsigned int bit; 48 } BitstreamPos; 35 #define FRAMES_PER_BLOCK_PWR 6 36 #define FRAMES_PER_BLOCK (1 << FRAMES_PER_BLOCK_PWR) 37 #define BUFFER_FULL (4352 * FRAMES_PER_BLOCK) // 34490 bit/frame 1320.3 kbps 49 38 50 39 typedef struct { … … 55 44 // TODO : enc/dec common struct 56 45 // just the same struct as below, dup ? 57 typedef struct {58 mpc_uint16_t Code; // >= 14 bit59 mpc_uint16_t Length; // >= 4 bit60 } HuffSrc_t ;61 46 62 47 typedef struct { 63 48 mpc_uint16_t Code; // >= 14 bit 64 49 mpc_uint16_t Length; // >= 4 bit 65 } Huffman_t 50 } Huffman_t; 66 51 67 // TODO : match with mpc_decoder_t68 // FIXME : add init code69 52 typedef struct { 70 mpc_uint32_t Buffer [BUFFER_FULL]; // Buffer for bitstream-file 71 mpc_uint32_t dword; // = 0; // 32-bit-Word for Bitstream-I/O 72 mpc_int32_t filled; // = 32; // Position in the the 32-bit-word that's currently about to be filled 73 mpc_uint32_t Zaehler; // = 0; // Position pointer for the processed bitstream-word (32 bit) 74 mpc_uint64_t BufferedBits; // = 0; // Counter for the number of written bits in the bitstream 53 mpc_uint_t pos; // next free byte position in the buffer 54 mpc_uint_t bitsCount; // number of used bits in bitsBuff 55 mpc_uint64_t outputBits; // Counter for the number of written bits in the bitstream 56 mpc_uint32_t bitsBuff; // bits buffer 57 mpc_uint8_t buffer [BUFFER_FULL]; // Buffer for bitstream-file 58 mpc_uint_t framesInBlock; 59 60 FILE * outputFile; // ouput file 75 61 76 62 unsigned int MS_Channelmode; 77 63 unsigned int Overflows; // = 0; // number of internal (filterbank) clippings 78 } mpc_encoder_t;64 } mpc_encoder_t; 79 65
Note: See TracChangeset
for help on using the changeset viewer.