Changeset 66 for mppenc/branches/r2d/libmpcenc
- Timestamp:
- 10/02/06 23:20:16 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
mppenc/branches/r2d/libmpcenc/encode_sv7.c
r65 r66 22 22 #include "libmpcenc.h" 23 23 24 void WriteBits ( mpc_encoder_t*, const mpc_uint32_t input, const unsigned int bits ); 25 24 26 // huffsv7.c 25 27 extern Huffman_t HuffHdr [10]; // contains tables for SV7-header … … 60 62 // writes SV7-header 61 63 void 62 WriteHeader_SV7 ( const unsigned int MaxBand, 64 WriteHeader_SV7 ( mpc_encoder_t*e, 65 const unsigned int MaxBand, 63 66 const unsigned int Profile, 64 67 const unsigned int MS_on, … … 68 71 const unsigned int SampleFreq ) 69 72 { 70 WriteBits ( StreamVersion, 8 ); // StreamVersion71 WriteBits (0x2B504D , 24 ); // Magic Number "MP+"72 73 WriteBits (TotalFrames , 32 ); // # of frames74 75 WriteBits (0 , 1 ); // former IS-Flag (not supported anymore)76 WriteBits (MS_on , 1 ); // MS-Coding Flag77 WriteBits (MaxBand , 6 ); // Bandwidth73 WriteBits ( e, StreamVersion, 8 ); // StreamVersion 74 WriteBits ( e, 0x2B504D , 24 ); // Magic Number "MP+" 75 76 WriteBits ( e, TotalFrames , 32 ); // # of frames 77 78 WriteBits ( e, 0 , 1 ); // former IS-Flag (not supported anymore) 79 WriteBits ( e, MS_on , 1 ); // MS-Coding Flag 80 WriteBits ( e, MaxBand , 6 ); // Bandwidth 78 81 79 82 #if 0 80 83 if ( MPPENC_VERSION [3] & 1 ) 81 WriteBits ( 1 , 4 ); // 1: Experimental profile84 WriteBits ( e, 1 , 4 ); // 1: Experimental profile 82 85 else 83 86 #endif 84 87 85 WriteBits ( Profile , 4 ); // 5...15: below Telephone...above BrainDead86 WriteBits (0 , 2 ); // for future use88 WriteBits ( e, Profile , 4 ); // 5...15: below Telephone...above BrainDead 89 WriteBits ( e, 0 , 2 ); // for future use 87 90 switch ( SampleFreq ) { 88 case 44100: WriteBits (0, 2 ); break;89 case 48000: WriteBits (1, 2 ); break;90 case 37800: WriteBits (2, 2 ); break;91 case 32000: WriteBits (3, 2 ); break;91 case 44100: WriteBits ( e, 0, 2 ); break; 92 case 48000: WriteBits ( e, 1, 2 ); break; 93 case 37800: WriteBits ( e, 2, 2 ); break; 94 case 32000: WriteBits ( e, 3, 2 ); break; 92 95 default : stderr_printf ( "Internal error\n"); 93 96 exit (1); 94 97 } 95 WriteBits (0 , 16 ); // maximum input sample value, currently filled by replaygain96 97 WriteBits (0 , 32 ); // title based gain controls, currently filled by replaygain98 99 WriteBits (0 , 32 ); // album based gain controls, currently filled by replaygain100 101 WriteBits (1 , 1 ); // true gapless: used?102 WriteBits (SamplesRest , 11 ); // true gapless: valid samples in last frame103 WriteBits (1 , 1 ); // we now support fast seeking104 WriteBits (0 , 19 );105 106 WriteBits ((MPPENC_VERSION[0]&15)*100 + (MPPENC_VERSION[2]&15)*10 + (MPPENC_VERSION[3]&15),98 WriteBits ( e, 0 , 16 ); // maximum input sample value, currently filled by replaygain 99 100 WriteBits ( e, 0 , 32 ); // title based gain controls, currently filled by replaygain 101 102 WriteBits ( e, 0 , 32 ); // album based gain controls, currently filled by replaygain 103 104 WriteBits ( e, 1 , 1 ); // true gapless: used? 105 WriteBits ( e, SamplesRest , 11 ); // true gapless: valid samples in last frame 106 WriteBits ( e, 1 , 1 ); // we now support fast seeking 107 WriteBits ( e, 0 , 19 ); 108 109 WriteBits ( e, (MPPENC_VERSION[0]&15)*100 + (MPPENC_VERSION[2]&15)*10 + (MPPENC_VERSION[3]&15), 107 110 8 ); // for future use 108 111 } … … 119 122 d = new - old + 7; \ 120 123 if ( d <= 14u && rll < 32) { \ 121 WriteBits ( Table[d].Code, Table[d].Length ); \124 WriteBits ( e, Table[d].Code, Table[d].Length ); \ 122 125 } \ 123 126 else { \ 124 127 if ( new < 0 ) new = 0, e->Overflows++; \ 125 WriteBits ( Table[15].Code, Table[15].Length ); \126 WriteBits ( (unsigned int)new, 6 ); \128 WriteBits ( e, Table[15].Code, Table[15].Length ); \ 129 WriteBits ( e, (unsigned int)new, 6 ); \ 127 130 rll = 0; \ 128 131 } … … 131 134 d = new - old + 7; \ 132 135 if ( d <= 14u ) { \ 133 WriteBits ( Table[d].Code, Table[d].Length ); \136 WriteBits ( e, Table[d].Code, Table[d].Length ); \ 134 137 } \ 135 138 else { \ 136 139 if ( new < 0 ) new = 0, e->Overflows++; \ 137 WriteBits ( Table[15].Code, Table[15].Length ); \138 WriteBits ( (unsigned int)new, 6 ); \140 WriteBits ( e, Table[15].Code, Table[15].Length ); \ 141 WriteBits ( e, (unsigned int)new, 6 ); \ 139 142 rll = 0; \ 140 143 } … … 187 190 188 191 /************************************ Resolution *********************************/ 189 WriteBits ( (unsigned int)Res_L[0], 4 ); // subband 0190 WriteBits ((unsigned int)Res_R[0], 4 );192 WriteBits ( e, (unsigned int)Res_L[0], 4 ); // subband 0 193 WriteBits ( e, (unsigned int)Res_R[0], 4 ); 191 194 if ( e->MS_Channelmode > 0 && !(Res_L[0]==0 && Res_R[0]==0) ) 192 WriteBits (MS_Flag[0] , 1 );195 WriteBits ( e, MS_Flag[0] , 1 ); 193 196 194 197 Table = HuffHdr; // subband 1...MaxBand … … 198 201 d = Res_L[n] - Res_L[n-1] + 5; 199 202 if ( d <= 8u ) { 200 WriteBits (Table[d].Code, Table[d].Length );203 WriteBits ( e, Table[d].Code, Table[d].Length ); 201 204 } 202 205 else { 203 WriteBits (Table[9].Code, Table[9].Length );204 WriteBits (Res_L[n] , 4 );206 WriteBits ( e, Table[9].Code, Table[9].Length ); 207 WriteBits ( e, Res_L[n] , 4 ); 205 208 } 206 209 … … 208 211 d = Res_R[n] - Res_R[n-1] + 5; 209 212 if ( d <= 8u ) { 210 WriteBits (Table[d].Code, Table[d].Length );213 WriteBits ( e, Table[d].Code, Table[d].Length ); 211 214 } 212 215 else { 213 WriteBits (Table[9].Code, Table[9].Length );214 WriteBits (Res_R[n] , 4 );216 WriteBits ( e, Table[9].Code, Table[9].Length ); 217 WriteBits ( e, Res_R[n] , 4 ); 215 218 } 216 219 if ( e->MS_Channelmode > 0 && !(Res_L[n]==0 && Res_R[n]==0) ) 217 WriteBits (MS_Flag[n], 1 );220 WriteBits ( e, MS_Flag[n], 1 ); 218 221 } 219 222 … … 223 226 if ( Res_L[n] ) { 224 227 SCFI_L[n] = 2 * (SCF_Index_L[n][0] == SCF_Index_L[n][1]) + (SCF_Index_L[n][1] == SCF_Index_L[n][2]); 225 WriteBits (Table[SCFI_L[n]].Code, Table[SCFI_L[n]].Length );228 WriteBits ( e, Table[SCFI_L[n]].Code, Table[SCFI_L[n]].Length ); 226 229 } 227 230 if ( Res_R[n] ) { 228 231 SCFI_R[n] = 2 * (SCF_Index_R[n][0] == SCF_Index_R[n][1]) + (SCF_Index_R[n][1] == SCF_Index_R[n][2]); 229 WriteBits (Table[SCFI_R[n]].Code, Table[SCFI_R[n]].Length );232 WriteBits ( e, Table[SCFI_R[n]].Code, Table[SCFI_R[n]].Length ); 230 233 } 231 234 } … … 309 312 } 310 313 book = sum >= 0; 311 WriteBits (book, 1 );314 WriteBits ( e, book, 1 ); 312 315 Table = HuffQ [book][1]; 313 316 for ( k = 0; k < 36; k += 3 ) { 314 317 idx = q[k+0] + 3*q[k+1] + 9*q[k+2]; 315 WriteBits (Table[idx].Code, Table[idx].Length );318 WriteBits ( e, Table[idx].Code, Table[idx].Length ); 316 319 } 317 320 break; … … 325 328 } 326 329 book = sum >= 0; 327 WriteBits (book, 1 );330 WriteBits ( e, book, 1 ); 328 331 Table = HuffQ [book][2]; 329 332 for ( k = 0; k < 36; k += 2 ) { 330 333 idx = q[k+0] + 5*q[k+1]; 331 WriteBits (Table[idx].Code, Table[idx].Length );334 WriteBits ( e, Table[idx].Code, Table[idx].Length ); 332 335 } 333 336 break; … … 344 347 } 345 348 book = sum >= 0; 346 WriteBits (book, 1 );349 WriteBits ( e, book, 1 ); 347 350 Table = HuffQ [book][Res_L[n]]; 348 351 for ( k = 0; k < 36; k++ ) { 349 352 idx = q[k]; 350 WriteBits (Table[idx].Code, Table[idx].Length );353 WriteBits ( e, Table[idx].Code, Table[idx].Length ); 351 354 } 352 355 break; 353 356 default: 354 357 for ( k = 0; k < 36; k++ ) 355 WriteBits (q[k], Res_L[n]-1 );358 WriteBits ( e, q[k], Res_L[n]-1 ); 356 359 break; 357 360 } … … 373 376 } 374 377 book = sum >= 0; 375 WriteBits (book, 1 );378 WriteBits ( e, book, 1 ); 376 379 Table = HuffQ [book][1]; 377 380 for ( k = 0; k < 36; k += 3 ) { 378 381 idx = q[k+0] + 3*q[k+1] + 9*q[k+2]; 379 WriteBits (Table[idx].Code, Table[idx].Length );382 WriteBits ( e, Table[idx].Code, Table[idx].Length ); 380 383 } 381 384 break; … … 389 392 } 390 393 book = sum >= 0; 391 WriteBits (book, 1 );394 WriteBits ( e, book, 1 ); 392 395 Table = HuffQ [book][2]; 393 396 for ( k = 0; k < 36; k += 2 ) { 394 397 idx = q[k+0] + 5*q[k+1]; 395 WriteBits (Table[idx].Code, Table[idx].Length );398 WriteBits ( e, Table[idx].Code, Table[idx].Length ); 396 399 } 397 400 break; … … 408 411 } 409 412 book = sum >= 0; 410 WriteBits (book, 1 );413 WriteBits ( e, book, 1 ); 411 414 Table = HuffQ [book][Res_R[n]]; 412 415 for ( k = 0; k < 36; k++ ) { 413 416 idx = q[k]; 414 WriteBits (Table[idx].Code, Table[idx].Length );417 WriteBits ( e, Table[idx].Code, Table[idx].Length ); 415 418 } 416 419 break; 417 420 default: 418 421 for ( k = 0; k < 36; k++ ) 419 WriteBits (q[k], Res_R[n] - 1 );422 WriteBits ( e, q[k], Res_R[n] - 1 ); 420 423 break; 421 424 }
Note: See TracChangeset
for help on using the changeset viewer.