Changeset 156
- Timestamp:
- 12/09/06 22:45:39 (18 years ago)
- Location:
- libmpc/branches/r2d
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
libmpc/branches/r2d/include/mpc/mpcmath.h
r137 r156 17 17 */ 18 18 19 #include <mpc/mpc_types.h> 19 20 20 21 #ifndef M_PI … … 58 59 #define ATAN2F(x,y) ATAN2 (x,y) 59 60 #define IFLOORF(x) IFLOOR (x) 61 62 typedef union mpc_floatint 63 { 64 float f; 65 mpc_int32_t n; 66 } mpc_floatint; 67 68 static mpc_inline mpc_int32_t mpc_lrintf(float fVal) 69 { 70 mpc_floatint tmp; 71 tmp.f = fVal + 0x00FF8000; 72 return tmp.n - 0x4B7F8000; 73 } 74 75 static mpc_inline float mpc_nearbyintf(float fVal) 76 { 77 return (float) mpc_lrintf(fVal); 78 } 79 -
libmpc/branches/r2d/libmpc.kdevelop
r150 r156 3 3 <general> 4 4 <author>Nicolas Botti</author> 5 <email />5 <email></email> 6 6 <version>0.1</version> 7 7 <projectmanagement>KDevAutoProject</projectmanagement> … … 14 14 <projectdirectory>.</projectdirectory> 15 15 <absoluteprojectpath>false</absoluteprojectpath> 16 <description />16 <description></description> 17 17 </general> 18 18 <kdevautoproject> 19 19 <general> 20 <activetarget> libmpcdec/libmpcdec.la</activetarget>20 <activetarget>mppenc/mppenc</activetarget> 21 21 <useconfiguration>debug</useconfiguration> 22 22 </general> 23 23 <run> 24 <mainprogram> /usr/bin/xmms</mainprogram>24 <mainprogram>mppenc/mppenc</mainprogram> 25 25 <terminal>true</terminal> 26 <directoryradio> custom</directoryradio>26 <directoryradio>executable</directoryradio> 27 27 <runarguments> 28 28 <mppenc/> 29 29 </runarguments> 30 30 <customdirectory>/</customdirectory> 31 <programargs />31 <programargs></programargs> 32 32 <autocompile>true</autocompile> 33 33 <envvars/> … … 39 39 <cxxcompiler>kdevgppoptions</cxxcompiler> 40 40 <f77compiler>kdevg77options</f77compiler> 41 <cflags>-O3 -fomit-frame-pointer -pipe -Wall -ffast-math</cflags>41 <cflags>-O3 -fomit-frame-pointer -pipe -Wall</cflags> 42 42 <envvars/> 43 <configargs />44 <topsourcedir />43 <configargs></configargs> 44 <topsourcedir></topsourcedir> 45 45 <cppflags>-DMPP_ENCODER=1 -DTRUE=1 -DFALSE=0</cppflags> 46 <ldflags />47 <ccompilerbinary />48 <cxxcompilerbinary />49 <f77compilerbinary />50 <cxxflags />51 <f77flags />46 <ldflags></ldflags> 47 <ccompilerbinary></ccompilerbinary> 48 <cxxcompilerbinary></cxxcompilerbinary> 49 <f77compilerbinary></f77compilerbinary> 50 <cxxflags></cxxflags> 51 <f77flags></f77flags> 52 52 </optimized> 53 53 <debug> … … 77 77 <numberofjobs>1</numberofjobs> 78 78 <dontact>false</dontact> 79 <makebin />79 <makebin></makebin> 80 80 <prio>0</prio> 81 81 </make> … … 139 139 <group pattern="*.h" name="Header files" /> 140 140 <group pattern="*.c" name="Source files" /> 141 <hidenonprojectfiles>false</hidenonprojectfiles>142 <hidenonlocation>false</hidenonlocation>143 141 </groups> 144 142 <tree> … … 184 182 </codecompletion> 185 183 <creategettersetter> 186 <prefixGet />184 <prefixGet></prefixGet> 187 185 <prefixSet>set</prefixSet> 188 186 <prefixVariable>m_,_</prefixVariable> … … 200 198 <kdevdebugger> 201 199 <general> 202 <programargs> ~/08\ -\ Jimmy\ Jimmy.mpc</programargs>203 <gdbpath />200 <programargs>--overwrite /home/nico/08\ -\ Jimmy\ Jimmy.wav</programargs> 201 <gdbpath></gdbpath> 204 202 <dbgshell>libtool</dbgshell> 205 <configGdbScript />206 <runShellScript />207 <runGdbScript />203 <configGdbScript></configGdbScript> 204 <runShellScript></runShellScript> 205 <runGdbScript></runGdbScript> 208 206 <breakonloadinglibs>true</breakonloadinglibs> 209 207 <separatetty>false</separatetty> -
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.