Changeset 72 for mppenc/branches/r2d/libmpcenc
- Timestamp:
- 10/12/06 11:54:40 (18 years ago)
- Location:
- mppenc/branches/r2d/libmpcenc
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
mppenc/branches/r2d/libmpcenc/huffsv7.c
r71 r72 396 396 } 397 397 398 #ifndef MPP_ENCODER399 400 void401 Init_Huffman_Decoder_SV7 ( void )402 {403 Init_Huffman_Encoder_SV7 ();404 405 SORT ( HuffHdr , 5 );406 SORT ( HuffSCFI , 0 );407 SORT ( HuffDSCF , 7 );408 SORT ( HuffQ1[0], 0 );409 SORT ( HuffQ1[1], 0 );410 SORT ( HuffQ2[0], 0 );411 SORT ( HuffQ2[1], 0 );412 #ifdef USE_SV8413 SORT ( HuffN3[0], 0 );414 SORT ( HuffN3[1], 0 );415 #endif416 SORT ( HuffQ3[0], Dc[3] );417 SORT ( HuffQ3[1], Dc[3] );418 SORT ( HuffQ4[0], Dc[4] );419 SORT ( HuffQ4[1], Dc[4] );420 SORT ( HuffQ5[0], Dc[5] );421 SORT ( HuffQ5[1], Dc[5] );422 SORT ( HuffQ6[0], Dc[6] );423 SORT ( HuffQ6[1], Dc[6] );424 SORT ( HuffQ7[0], Dc[7] );425 SORT ( HuffQ7[1], Dc[7] );426 #ifdef USE_SV8427 SORT ( HuffN8[0], Dc[8] );428 SORT ( HuffN8[1], Dc[8] );429 #endif430 431 LOOKUP ( HuffQ1[0], LUT1_0 );432 LOOKUP ( HuffQ1[1], LUT1_1 );433 LOOKUP ( HuffQ2[0], LUT2_0 );434 LOOKUP ( HuffQ2[1], LUT2_1 );435 LOOKUP ( HuffQ3[0], LUT3_0 );436 LOOKUP ( HuffQ3[1], LUT3_1 );437 LOOKUP ( HuffQ4[0], LUT4_0 );438 LOOKUP ( HuffQ4[1], LUT4_1 );439 LOOKUP ( HuffQ5[0], LUT5_0 );440 LOOKUP ( HuffQ5[1], LUT5_1 );441 LOOKUP ( HuffQ6[0], LUT6_0 );442 LOOKUP ( HuffQ6[1], LUT6_1 );443 LOOKUP ( HuffQ7[0], LUT7_0 );444 LOOKUP ( HuffQ7[1], LUT7_1 );445 LOOKUP ( HuffDSCF , LUTDSCF );446 }447 448 #endif449 450 398 /* end of huffsv7.c */ -
mppenc/branches/r2d/libmpcenc/tools.c
r71 r72 33 33 #include <stdio.h> 34 34 35 // FIXME : not sure if it's a good idea 36 #include <fpu_control.h> 37 35 38 #include "libmpcenc.h" 36 39 … … 47 50 48 51 while ( bytes > 0 ) { 49 #if defined _WIN32 && defined USE_HTTP && !defined MPP_ENCODER50 ret = fd & 0x4000 ? recv ( fd & 0x3FFF, dest, bytes, 0) : read ( fd, dest, bytes );51 #else52 52 ret = read ( fd, dest, bytes ); 53 #endif54 53 if ( ret == 0 || ret == (mpc_size_t)-1 ) 55 54 break; … … 119 118 return wordsread; 120 119 } 121 122 #ifndef MPP_ENCODER123 124 /*125 * This is the main requantisation routine which does the following things:126 *127 * - rescaling the quantized values (int) to their original value (float)128 * - recalculating both stereo channels for MS stereo129 *130 * See also: Requantize_IntensityStereo()131 *132 * For performance reasons all cases are programmed separately and the code133 * is unrolled.134 *135 * Input is:136 * - Stop_Band:137 * the last band using MS or LR stereo138 * - used_MS[Band]:139 * MS or LR stereo flag for every band (0...Stop_Band), Value is 1140 * for MS and 0 for LR stereo.141 * - Res[Band].{L,R}:142 * Quantisation resolution for every band (0...Stop_Band) and143 * channels (L, R). Value is 0...17.144 * - SCF_Index[3][Band].{L,R}:145 * Scale factor for every band (0...Stop_Band), subframe (0...2)146 * and channel (L, R).147 * - Q[Band].{L,R}[36]148 * 36 subband samples for every band (0...Stop_Band) and channel (L, R).149 * - SCF[64], Cc[18], Dc[18]:150 * Lookup tables for Scale factor and Quantisation resolution.151 *152 * Output is:153 * - Y_L: Left channel subband signals154 * - Y_R: Right channel subband signals155 *156 * These signals are used for the synthesis filter in the synth*.[ch]157 * files to generate the PCM output signal.158 */159 160 static const float ISMatrix [32] [2] = {161 { 1.00000000f, 0.00000000f },162 { 0.98078528f, 0.19509032f },163 { 0.92387953f, 0.38268343f },164 { 0.83146961f, 0.55557023f },165 { 0.70710678f, 0.70710678f },166 { 0.55557023f, 0.83146961f },167 { 0.38268343f, 0.92387953f },168 { 0.19509032f, 0.98078528f },169 { 0.00000000f, 1.00000000f },170 { -0.19509032f, 0.98078528f },171 { -0.38268343f, 0.92387953f },172 { -0.55557023f, 0.83146961f },173 { -0.70710678f, 0.70710678f },174 { -0.83146961f, 0.55557023f },175 { -0.92387953f, 0.38268343f },176 { -0.98078528f, 0.19509032f },177 { -1.00000000f, 0.00000000f },178 { -0.98078528f, -0.19509032f },179 { -0.92387953f, -0.38268343f },180 { -0.83146961f, -0.55557023f },181 { -0.70710678f, -0.70710678f },182 { -0.55557023f, -0.83146961f },183 { -0.38268343f, -0.92387953f },184 { -0.19509032f, -0.98078528f },185 { -0.00000000f, -1.00000000f },186 { 0.19509032f, -0.98078528f },187 { 0.38268343f, -0.92387953f },188 { 0.55557023f, -0.83146961f },189 { 0.70710678f, -0.70710678f },190 { 0.83146961f, -0.55557023f },191 { 0.92387953f, -0.38268343f },192 { 0.98078528f, -0.19509032f },193 };194 195 196 void197 Requantize_MidSideStereo ( mpc_int_t Stop_Band, const mpc_bool_t* used_MS )198 {199 mpc_int_t Band; // 0...Stop_Band200 Uint k; // 0...35201 Float ML;202 Float MR;203 Float mid;204 Float side;205 206 for ( Band = 0; Band <= Stop_Band; Band++ ) {207 208 if ( used_MS[Band] ) // MidSide coded: left channel contains Mid signal, right channel Side signal209 if ( Res[Band].R < -1 ) {210 k = 0;211 ML = SCF[SCF_Index[0][Band].L] * Cc[Res[Band].L];212 do {213 mid = Q[Band].L[k] * ML;214 Y_L[k][Band] = mid * ISMatrix [used_MS[Band]][0];215 Y_R[k][Band] = mid * ISMatrix [used_MS[Band]][1];216 } while (++k < 12);217 ML = SCF[SCF_Index[1][Band].L] * Cc[Res[Band].L];218 do {219 mid = Q[Band].L[k] * ML;220 Y_L[k][Band] = mid * ISMatrix [used_MS[Band]][0];221 Y_R[k][Band] = mid * ISMatrix [used_MS[Band]][1];222 } while (++k < 24);223 ML = SCF[SCF_Index[2][Band].L] * Cc[Res[Band].L];224 do {225 mid = Q[Band].L[k] * ML;226 Y_L[k][Band] = mid * ISMatrix [used_MS[Band]][0];227 Y_R[k][Band] = mid * ISMatrix [used_MS[Band]][1];228 } while (++k < 36);229 }230 else if ( Res[Band].L < -1 ) {231 k = 0;232 ML = SCF[SCF_Index[0][Band].R] * Cc[Res[Band].R];233 do {234 mid = Q[Band].R[k] * ML;235 Y_R[k][Band] = mid * ISMatrix [used_MS[Band]][0];236 Y_L[k][Band] = mid * ISMatrix [used_MS[Band]][1];237 } while (++k < 12);238 ML = SCF[SCF_Index[1][Band].R] * Cc[Res[Band].R];239 do {240 mid = Q[Band].R[k] * ML;241 Y_R[k][Band] = mid * ISMatrix [used_MS[Band]][0];242 Y_L[k][Band] = mid * ISMatrix [used_MS[Band]][1];243 } while (++k < 24);244 ML = SCF[SCF_Index[2][Band].R] * Cc[Res[Band].R];245 do {246 mid = Q[Band].R[k] * ML;247 Y_R[k][Band] = mid * ISMatrix [used_MS[Band]][0];248 Y_L[k][Band] = mid * ISMatrix [used_MS[Band]][1];249 } while (++k < 36);250 }251 else if ( Res[Band].L )252 if ( Res[Band].R ) { // M!=0, S!=0253 k = 0;254 ML = SCF[SCF_Index[0][Band].L] * Cc[Res[Band].L];255 MR = SCF[SCF_Index[0][Band].R] * Cc[Res[Band].R];256 do {257 Y_R[k][Band] = (mid = Q[Band].L[k] * ML) - (side = Q[Band].R[k] * MR);258 Y_L[k][Band] = mid + side;259 } while (++k < 12);260 ML = SCF[SCF_Index[1][Band].L] * Cc[Res[Band].L];261 MR = SCF[SCF_Index[1][Band].R] * Cc[Res[Band].R];262 do {263 Y_R[k][Band] = (mid = Q[Band].L[k] * ML) - (side = Q[Band].R[k] * MR);264 Y_L[k][Band] = mid + side;265 } while (++k < 24);266 ML = SCF[SCF_Index[2][Band].L] * Cc[Res[Band].L];267 MR = SCF[SCF_Index[2][Band].R] * Cc[Res[Band].R];268 do {269 Y_R[k][Band] = (mid = Q[Band].L[k] * ML) - (side = Q[Band].R[k] * MR);270 Y_L[k][Band] = mid + side;271 } while (++k < 36);272 } else { // M!=0, S=0273 k = 0;274 ML = SCF[SCF_Index[0][Band].L] * Cc[Res[Band].L];275 do {276 Y_R[k][Band] =277 Y_L[k][Band] = Q[Band].L[k] * ML;278 } while (++k < 12);279 ML = SCF[SCF_Index[1][Band].L] * Cc[Res[Band].L];280 do {281 Y_R[k][Band] =282 Y_L[k][Band] = Q[Band].L[k] * ML;283 } while (++k < 24);284 ML = SCF[SCF_Index[2][Band].L] * Cc[Res[Band].L];285 do {286 Y_R[k][Band] =287 Y_L[k][Band] = Q[Band].L[k] * ML;288 } while (++k < 36);289 }290 else291 if ( Res[Band].R ) { // M==0, S!=0292 k = 0;293 ML = SCF[SCF_Index[0][Band].R] * Cc[Res[Band].R];294 do {295 Y_R[k][Band] = - (296 Y_L[k][Band] = Q[Band].R[k] * ML );297 } while (++k < 12);298 ML = SCF[SCF_Index[1][Band].R] * Cc[Res[Band].R];299 do {300 Y_R[k][Band] = - (301 Y_L[k][Band] = Q[Band].R[k] * ML );302 } while (++k < 24);303 ML = SCF[SCF_Index[2][Band].R] * Cc[Res[Band].R];304 do {305 Y_R[k][Band] = - (306 Y_L[k][Band] = Q[Band].R[k] * ML );307 } while (++k < 36);308 } else { // M==0, S==0309 for (k=0; k<36; k++) {310 Y_R[k][Band] =311 Y_L[k][Band] = 0.f;312 }313 }314 315 else // Left/Right coded: left channel contains left, right the right signal316 317 if ( Res[Band].L )318 if ( Res[Band].R ) { // L!=0, R!=0319 k = 0;320 ML = SCF[SCF_Index[0][Band].L] * Cc[Res[Band].L];321 MR = SCF[SCF_Index[0][Band].R] * Cc[Res[Band].R];322 do {323 Y_R[k][Band] = Q[Band].R[k] * MR;324 Y_L[k][Band] = Q[Band].L[k] * ML;325 } while (++k < 12);326 ML = SCF[SCF_Index[1][Band].L] * Cc[Res[Band].L];327 MR = SCF[SCF_Index[1][Band].R] * Cc[Res[Band].R];328 do {329 Y_R[k][Band] = Q[Band].R[k] * MR;330 Y_L[k][Band] = Q[Band].L[k] * ML;331 } while (++k < 24);332 ML = SCF[SCF_Index[2][Band].L] * Cc[Res[Band].L];333 MR = SCF[SCF_Index[2][Band].R] * Cc[Res[Band].R];334 do {335 Y_R[k][Band] = Q[Band].R[k] * MR;336 Y_L[k][Band] = Q[Band].L[k] * ML;337 } while (++k < 36);338 } else { // L!=0, R==0339 k = 0;340 ML = SCF[SCF_Index[0][Band].L] * Cc[Res[Band].L];341 do {342 Y_R[k][Band] = 0.f;343 Y_L[k][Band] = Q[Band].L[k] * ML;344 } while (++k < 12);345 ML = SCF[SCF_Index[1][Band].L] * Cc[Res[Band].L];346 do {347 Y_R[k][Band] = 0.f;348 Y_L[k][Band] = Q[Band].L[k] * ML;349 } while (++k < 24);350 ML = SCF[SCF_Index[2][Band].L] * Cc[Res[Band].L];351 do {352 Y_R[k][Band] = 0.f;353 Y_L[k][Band] = Q[Band].L[k] * ML;354 } while (++k < 36);355 }356 else357 if ( Res[Band].R ) { // L==0, R!=0358 k = 0;359 MR = SCF[SCF_Index[0][Band].R] * Cc[Res[Band].R];360 do {361 Y_R[k][Band] = Q[Band].R[k] * MR;362 Y_L[k][Band] = 0.f;363 } while (++k < 12);364 MR = SCF[SCF_Index[1][Band].R] * Cc[Res[Band].R];365 do {366 Y_R[k][Band] = Q[Band].R[k] * MR;367 Y_L[k][Band] = 0.f;368 } while (++k < 24);369 MR = SCF[SCF_Index[2][Band].R] * Cc[Res[Band].R];370 do {371 Y_R[k][Band] = Q[Band].R[k] * MR;372 Y_L[k][Band] = 0.f;373 } while (++k < 36);374 } else { // L==0, R==0375 for (k=0; k<36; k++) {376 Y_R[k][Band] =377 Y_L[k][Band] = 0.f;378 }379 }380 381 }382 return;383 }384 385 386 /*387 * This is the main requantisation routine for Intensity Stereo.388 * It does the same as Requantize_MidSideStereo() but for IS.389 *390 * Input is:391 * - Stop_Band:392 * the last band using MS or LR stereo393 * - Res[Band].L:394 * Quantisation resolution for every band (0...Stop_Band) and395 * the left channel which is used for both channels. Value is 0...17.396 * - SCF_Index[3][Band].{L,R}:397 * Scale factor for every band (0...Stop_Band), subframe (0...2)398 * and channel (L, R).399 * - Q[Band].L[36]400 * 36 subband samples for every band (0...Stop_Band), both channels use401 * the of the left channel402 * - SCF[64], Cc[18], Dc[18]:403 * Lookup tables for Scale factor and Quantisation resolution.404 *405 * Output is:406 * - Y_L: Left channel subband signals407 * - Y_R: Right channel subband signals408 *409 * These signals are used for the synthesis filter in the synth*.[ch]410 * files to generate the PCM output signal.411 */412 413 void414 Requantize_IntensityStereo ( mpc_int_t Start_Band, mpc_int_t Stop_Band )415 {416 mpc_int_t Band; // Start_Band...Stop_Band417 Uint k; // 0...35418 Float ML;419 Float MR;420 421 for ( Band = Start_Band; Band <= Stop_Band; Band++ ) {422 423 if ( Res[Band].L ) {424 k = 0;425 ML = SCF[SCF_Index[0][Band].L] * Cc[Res[Band].L] * SS05;426 MR = SCF[SCF_Index[0][Band].R] * Cc[Res[Band].L] * SS05;427 do {428 Y_R[k][Band] = Q[Band].L[k] * MR;429 Y_L[k][Band] = Q[Band].L[k] * ML;430 } while (++k < 12);431 ML = SCF[SCF_Index[1][Band].L] * Cc[Res[Band].L] * SS05;432 MR = SCF[SCF_Index[1][Band].R] * Cc[Res[Band].L] * SS05;433 do {434 Y_R[k][Band] = Q[Band].L[k] * MR;435 Y_L[k][Band] = Q[Band].L[k] * ML;436 } while (++k < 24);437 ML = SCF[SCF_Index[2][Band].L] * Cc[Res[Band].L] * SS05;438 MR = SCF[SCF_Index[2][Band].R] * Cc[Res[Band].L] * SS05;439 do {440 Y_R[k][Band] = Q[Band].L[k] * MR;441 Y_L[k][Band] = Q[Band].L[k] * ML;442 } while (++k < 36);443 } else {444 for (k=0; k<36; k++) {445 Y_R[k][Band] =446 Y_L[k][Band] = 0.f;447 }448 }449 450 }451 return;452 }453 454 455 /*456 * Helper function for the qsort() in Resort_HuffTable() to sort a Huffman table457 * by its codes.458 */459 460 static int Cdecl461 cmp_fn ( const void* p1, const void* p2 )462 {463 if ( ((const Huffman_t*)p1) -> Code < ((const Huffman_t*)p2) -> Code ) return +1;464 if ( ((const Huffman_t*)p1) -> Code > ((const Huffman_t*)p2) -> Code ) return -1;465 return 0;466 }467 468 469 /*470 * This functions sorts a Huffman table by its codes. It has also two other functions:471 *472 * - The table contains LSB aligned codes, these are first MSB aligned.473 * - The value entry is filled by its position plus 'offset' (Note that474 * Make_HuffTable() don't fill this item. Offset can be used to offset475 * range for instance from 0...6 to -3...+3.476 *477 * Note that this function generates trash if you call it twice!478 */479 480 void481 Resort_HuffTable ( Huffman_t* const Table, const mpc_size_t elements, mpc_int_t offset )482 {483 mpc_size_t i;484 485 for ( i = 0; i < elements; i++ ) {486 Table[i].Value = i + offset;487 Table[i].Code <<= (32 - Table[i].Length);488 }489 490 qsort ( Table, elements, sizeof(*Table), cmp_fn );491 return;492 }493 494 #endif /* MPP_ENCODER */495 496 120 497 121 /* … … 573 197 } 574 198 575 /* end of tools.c */ 199
Note: See TracChangeset
for help on using the changeset viewer.