1#include <math.h> 2#include "requant.h" 3 4/* C O N S T A N T S */ 5// bits per sample for chosen quantizer 6const unsigned int Res_bit [18] = { 7 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 8}; 9 10// coefficients for requantization 11// 65536/step bzw. 65536/(2*D+1) 12const float __Cc [1 + 18] = { 13 111.285962475327f, // 32768/2/255*sqrt(3) 14 65536.000000000000f, 21845.333333333332f, 13107.200000000001f, 9362.285714285713f, 15 7281.777777777777f, 4369.066666666666f, 2114.064516129032f, 1040.253968253968f, 16 516.031496062992f, 257.003921568627f, 128.250489236790f, 64.062561094819f, 17 32.015632633121f, 16.003907203907f, 8.000976681723f, 4.000244155527f, 18 2.000061037018f, 1.000015259021f 19}; 20 21// offset for requantization 22// 2*D+1 = steps of quantizer 23const int __Dc [1 + 18] = { 24 2, 25 0, 1, 2, 3, 4, 7, 15, 31, 63, 26 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767 27}; 28 29/* F U N C T I O N S */ 30void 31MPC_decoder::ScaleOutput ( double factor ) 32{ 33 int n; 34 double f1 = factor; 35 double f2 = factor; 36 37 // handles +1.58...-98.41 dB, where's scf[n] / scf[n-1] = 1.20050805774840750476 38 for ( n = 0; n <= 128; n++ ) { 39 SCF [(unsigned char)(1+n)] = (float) f1; 40 SCF [(unsigned char)(1-n)] = (float) f2; 41 f1 *= 0.83298066476582673961; 42 f2 *= 1/0.83298066476582673961; 43 } 44} 45 46void 47MPC_decoder::Quantisierungsmodes ( void ) // conversion: index -> quantizer (bitstream reading) 48{ // conversion: quantizer -> index (bitstream writing) 49 int Band = 0; 50 int i; 51 52 do { 53 Q_bit [Band] = 4; 54 for ( i = 0; i < 16-1; i++ ) 55 Q_res [Band] [i] = i; 56 Q_res [Band][i] = 17; 57 Band++; 58 } while ( Band < 11 ); 59 60 do { 61 Q_bit [Band] = 3; 62 for ( i = 0; i < 8-1; i++ ) 63 Q_res [Band] [i] = i; 64 Q_res [Band] [i] = 17; 65 Band++; 66 } while ( Band < 23 ); 67 68 do { 69 Q_bit [Band] = 2; 70 for ( i = 0; i < 4-1; i++ ) 71 Q_res [Band] [i] = i; 72 Q_res [Band] [i] = 17; 73 Band++; 74 } while ( Band < 32 ); 75} 76 77void 78MPC_decoder::initialisiere_Quantisierungstabellen ( void ) 79{ 80 Quantisierungsmodes (); 81 ScaleOutput ( 1.0 ); 82} 83