Changeset 156 for libmpc/branches/r2d/libmpcenc
- Timestamp:
- 12/09/06 22:45:39 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libmpc/branches/r2d/libmpcenc/quant.c
r142 r156 22 22 #include "libmpcenc.h" 23 23 #include <mpc/minimax.h> 24 #include <mpc/mpcmath.h> 24 25 25 26 /* V A R I A B L E S */ … … 158 159 { 159 160 int k; 160 float fac = A [res]; 161 float invfac = C [res]; 162 float Signal = 1.e-30f; 163 float Fehler = 1.e-30f; 164 float tmp ; 165 float tmp2; 161 const float fac = A [res]; 162 const float invfac = C [res]; 163 float signal = 1.e-30f; 164 float error = 1.e-30f; 165 float sig, err; 166 166 167 167 // Summation of the absolute power and the quadratic error 168 168 for ( k = 0; k < 36; k++ ) { 169 tmp2= input[k] * NoiseInjectionCompensation1D [res];170 tmp = __builtin_nearbyintf(tmp2 * fac) * invfac - tmp2;171 172 Fehler += tmp * tmp;173 Signal += tmp2 * tmp2;169 err = input[k] * NoiseInjectionCompensation1D [res]; 170 sig = mpc_nearbyintf(err * fac) * invfac - err; 171 172 error += sig * sig; 173 signal += err * err; 174 174 } 175 175 176 176 // Utilization of SNRcomp only if SNR > 1 !!! 177 return Signal > Fehler ? Fehler / (SNRcomp * Signal) : Fehler / Signal;177 return signal > error ? error / (SNRcomp * signal) : error / signal; 178 178 } 179 179 … … 185 185 float fac = A [res]; 186 186 float invfac = C [res]; 187 float Signal; 188 float Fehler; 189 float ret ; 190 float tmp ; 191 float tmp2; 187 float signal, error, ret, sig, err; 192 188 193 189 // Summation of the absolute power and the quadratic error 194 195 Signal = Fehler = 1.e-30f;190 k = 0; 191 signal = error = 1.e-30f; 196 192 for ( ; k < 12; k++ ) { 197 tmp2= input[k] * NoiseInjectionCompensation1D [res];198 tmp = __builtin_nearbyintf(tmp2 * fac) * invfac - tmp2;199 200 Fehler += tmp * tmp;201 Signal += tmp2 * tmp2;202 } 203 tmp = Signal > Fehler ? Fehler / (SNRcomp * Signal) : Fehler / Signal;204 ret = tmp;205 Signal = Fehler = 1.e-30f;193 err = input[k] * NoiseInjectionCompensation1D [res]; 194 sig = mpc_nearbyintf(err * fac) * invfac - err; 195 196 error += sig * sig; 197 signal += err * err; 198 } 199 sig = signal > error ? error / (SNRcomp * signal) : error / signal; 200 ret = sig; 201 signal = error = 1.e-30f; 206 202 for ( ; k < 24; k++ ) { 207 tmp2= input[k] * NoiseInjectionCompensation1D [res];208 tmp = __builtin_nearbyintf(tmp2 * fac) * invfac - tmp2;209 210 Fehler += tmp * tmp;211 Signal += tmp2 * tmp2;212 } 213 tmp = Signal > Fehler ? Fehler / (SNRcomp * Signal) : Fehler / Signal;214 if ( tmp > ret ) ret = tmp;215 //ret += tmp; 216 Signal = Fehler = 1.e-30f;203 err = input[k] * NoiseInjectionCompensation1D [res]; 204 sig = mpc_nearbyintf(err * fac) * invfac - err; 205 206 error += sig * sig; 207 signal += err * err; 208 } 209 sig = signal > error ? error / (SNRcomp * signal) : error / signal; 210 ret = maxf(ret, sig); 211 212 signal = error = 1.e-30f; 217 213 for ( ; k < 36; k++ ) { 218 tmp2 = input[k] * NoiseInjectionCompensation1D [res]; 219 tmp = __builtin_nearbyintf(tmp2 * fac) * invfac - tmp2; 220 221 Fehler += tmp * tmp; 222 Signal += tmp2 * tmp2; 223 } 224 tmp = Signal > Fehler ? Fehler / (SNRcomp * Signal) : Fehler / Signal; 225 if ( tmp > ret ) ret = tmp; 226 //ret += tmp; 227 //ret *= 0.33333333333f; 214 err = input[k] * NoiseInjectionCompensation1D [res]; 215 sig = mpc_nearbyintf(err * fac) * invfac - err; 216 217 error += sig * sig; 218 signal += err * err; 219 } 220 sig = signal > error ? error / (SNRcomp * signal) : error / signal; 221 ret = maxf(ret, sig); 228 222 229 223 return ret; … … 235 229 QuantizeSubband ( unsigned int* qu_output, const float* input, const int res, float* errors, const int maxNsOrder ) 236 230 { 237 int n;231 int n, quant; 238 232 int offset = D [res]; 239 233 float mult = A [res] * NoiseInjectionCompensation1D [res]; 240 234 float invmult = C [res]; 241 int quant;242 235 float signal; 243 236 244 for ( n = 0; n < 36 - maxNsOrder; n++ , input++, qu_output++) {245 quant = (unsigned int)( __builtin_lrintf(*input* mult) + offset);237 for ( n = 0; n < 36 - maxNsOrder; n++) { 238 quant = (unsigned int)(mpc_lrintf(input[n] * mult) + offset); 246 239 247 240 // limitation to 0...2D 248 if ((unsigned int)quant > (unsigned int) 2*offset) {249 quant = mini ( quant, 2*offset);250 quant = maxi ( quant, 241 if ((unsigned int)quant > (unsigned int)offset * 2 ) { 242 quant = mini ( quant, offset * 2 ); 243 quant = maxi ( quant, 0 ); 251 244 } 252 *qu_output= quant;253 } 254 255 for ( ; n < 36; n++ , input++, qu_output++) {256 signal = *input* mult;257 quant = (unsigned int)( __builtin_lrintf(signal) + offset);245 qu_output[n] = quant; 246 } 247 248 for ( ; n < 36; n++) { 249 signal = input[n] * mult; 250 quant = (unsigned int)(mpc_lrintf(signal) + offset); 258 251 259 252 // calculate the current error and save it for error refeeding … … 261 254 262 255 // limitation to 0...2D 263 if ((unsigned int)quant > (unsigned int) 2*offset) {264 quant = mini ( quant, 2*offset);265 quant = maxi ( quant, 256 if ((unsigned int)quant > (unsigned int)offset * 2 ) { 257 quant = mini ( quant, offset * 2 ); 258 quant = maxi ( quant, 0 ); 266 259 } 267 *qu_output= quant;260 qu_output[n] = quant; 268 261 } 269 262 } … … 274 267 QuantizeSubbandWithNoiseShaping ( unsigned int* qu_output, const float* input, const int res, float* errors, const float* FIR ) 275 268 { 276 #define E(x) *((int*)errors+(x))277 278 269 float signal; 279 270 float mult = A [res]; 280 271 float invmult = C [res]; 281 272 int offset = D [res]; 282 int n; 283 int quant; 284 285 E(0) = E(1) = E(2) = E(3) = E(4) = E(5) = 0; // arghh, it produces pops on each frame boundary! 286 287 for ( n = 0; n < 36; n++, input++, qu_output++ ) { 288 signal = *input * NoiseInjectionCompensation1D [res] - (FIR[5]*errors[n+0] + FIR[4]*errors[n+1] + FIR[3]*errors[n+2] + FIR[2]*errors[n+3] + FIR[1]*errors[n+4] + FIR[0]*errors[n+5]); 289 quant = __builtin_lrintf(signal * mult); 273 int n, quant; 274 275 memset(errors, 0, 6 * sizeof *errors); // arghh, it produces pops on each frame boundary! 276 277 for ( n = 0; n < 36; n++) { 278 signal = input[n] * NoiseInjectionCompensation1D [res] - (FIR[5]*errors[n+0] + FIR[4]*errors[n+1] + FIR[3]*errors[n+2] + FIR[2]*errors[n+3] + FIR[1]*errors[n+4] + FIR[0]*errors[n+5]); 279 quant = mpc_lrintf(signal * mult); 290 280 291 281 // calculate the current error and save it for error refeeding … … 296 286 quant = maxf ( quant, -offset ); 297 287 298 *qu_output= (unsigned int)(quant + offset);288 qu_output[n] = (unsigned int)(quant + offset); 299 289 } 300 290 }
Note: See TracChangeset
for help on using the changeset viewer.