Changeset 68 for libmpcdec/branches/zorg/src/requant.c
- Timestamp:
- 10/06/06 17:14:05 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libmpcdec/branches/zorg/src/requant.c
r10 r68 32 32 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 33 */ 34 35 34 /// \file requant.c 36 35 /// Requantization function implementations. 37 36 /// \todo document me 37 #include <mpcdec/mpcdec.h> 38 38 39 #include <mpcdec/mpcdec.h> 40 #include <mpcdec/internal.h> 39 #include "requant.h" 40 #include "math.h" 41 #include "decoder.h" 41 42 42 43 /* C O N S T A N T S */ 43 // bits per sample for chosen quantizer44 // Bits per sample for chosen quantizer 44 45 const mpc_uint32_t Res_bit [18] = { 45 46 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 46 47 }; 47 48 48 // coefficients for requantization49 // Requantization coefficients 49 50 // 65536/step bzw. 65536/(2*D+1) 50 51 … … 52 53 53 54 const MPC_SAMPLE_FORMAT __Cc [1 + 18] = { 54 _(111.285962475327f),// 32768/2/255*sqrt(3)55 _(111.285962475327f), // 32768/2/255*sqrt(3) 55 56 _(65536.000000000000f), _(21845.333333333332f), _(13107.200000000001f), _(9362.285714285713f), 56 _(7281.777777777777f), _(4369.066666666666f), _(2114.064516129032f), _(1040.253968253968f),57 _(516.031496062992f),_(257.003921568627f), _(128.250489236790f), _(64.062561094819f),58 _(32.015632633121f), _(16.003907203907f), _(8.000976681723f),_(4.000244155527f),59 57 _(7281.777777777777f), _(4369.066666666666f), _(2114.064516129032f), _(1040.253968253968f), 58 _(516.031496062992f), _(257.003921568627f), _(128.250489236790f), _(64.062561094819f), 59 _(32.015632633121f), _(16.003907203907f), _(8.000976681723f), _(4.000244155527f), 60 _(2.000061037018f), _(1.000015259021f) 60 61 }; 61 62 62 63 #undef _ 63 64 64 // offset for requantization65 // Requantization offset 65 66 // 2*D+1 = steps of quantizer 66 67 const mpc_int32_t __Dc [1 + 18] = { … … 73 74 static mpc_uint32_t find_shift(double fval) 74 75 { 75 mpc_int64_t val = (mpc_int64_t) fval;76 mpc_int64_t val = (mpc_int64_t) fval; 76 77 mpc_uint32_t ptr = 0; 77 if (val<0) val = -val; 78 while(val) {val>>=1;ptr++;} 79 78 if(val<0) 79 val = -val; 80 while(val) 81 { 82 val >>= 1; 83 ptr++; 84 } 80 85 return ptr > 31 ? 0 : 31 - ptr; 81 86 } … … 84 89 /* F U N C T I O N S */ 85 90 86 #define SET_SCF(N,X) d->SCF[N] = MAKE_MPC_SAMPLE_EX(X,d->SCF_shift[N] = ( unsigned char)find_shift(X));91 #define SET_SCF(N,X) d->SCF[N] = MAKE_MPC_SAMPLE_EX(X,d->SCF_shift[N] = (mpc_uint8_t) find_shift(X)); 87 92 88 93 void 89 94 mpc_decoder_scale_output(mpc_decoder *d, double factor) 90 95 { 91 mpc_int32_t n; 92 double f1; 93 double f2; 96 mpc_int32_t n; double f1, f2; 97 94 98 #ifndef MPC_FIXED_POINT 95 factor *= 1.0 / (double) (1<<(MPC_FIXED_POINT_SHIFT-1));99 factor *= 1.0 / (double) (1<<(MPC_FIXED_POINT_SHIFT-1)); 96 100 #else 97 factor *= 1.0 / (double) (1<<(16 -MPC_FIXED_POINT_SHIFT));101 factor *= 1.0 / (double) (1<<(16-MPC_FIXED_POINT_SHIFT)); 98 102 #endif 99 103 f1 = f2 = factor; … … 107 111 108 112 for ( n = 1; n <= 128; n++ ) { 109 SET_SCF(( unsigned char)(1+n),f1);110 SET_SCF(( unsigned char)(1-n),f2);113 SET_SCF((mpc_uint8_t)(1+n),f1); 114 SET_SCF((mpc_uint8_t)(1-n),f2); 111 115 f1 *= 0.83298066476582673961; 112 116 f2 *= 1/0.83298066476582673961;
Note: See TracChangeset
for help on using the changeset viewer.