[Audacity-devel] [PATCH] speeding up audacity, 2/6
A free multi-track audio editor and recorder
Brought to you by:
aosiniao
From: Sami L. <sl...@cc...> - 2009-05-11 02:21:07
|
On Mon, May 11, 2009 at 04:50:22AM +0300, Sami Liedes wrote: > #2 Use float versions of various math functions where possible. > Also use pow10f() instead of pow(10.0, ...) if available. Here's the patch. Note that pow10f() is a GNU extension, I don't know if it's available on Windows, so I made autoconf check for it. Hope I understood the autoconf stuff correctly, I haven't much experience with it. Sami ------------------------------------------------------------ commit 60f50d38e2d605103d281569df6a039904e70ae5 Author: Sami Liedes <sl...@cc...> Date: Mon May 11 01:31:52 2009 +0300 Use float versions of math routines where available. diff --git a/configure.in b/configure.in index eb1b19b..793b081 100644 --- a/configure.in +++ b/configure.in @@ -667,6 +667,7 @@ dnl Check for lrint/lrintf AC_C99_FUNC_LRINT AC_C99_FUNC_LRINTF +AC_CHECK_LIB(m, pow10f, AC_DEFINE(HAVE_POW10F)) if [[ "$use_ladspa" = "yes" ]] ; then OPTOBJS="$OPTOBJS effects/ladspa/LoadLadspa.o" diff --git a/src/Spectrum.cpp b/src/Spectrum.cpp index ea7677e..1e437e1 100644 --- a/src/Spectrum.cpp +++ b/src/Spectrum.cpp @@ -27,7 +27,7 @@ static inline float todB_a(const float *x){ #else static inline float todB_a(const float *x){ - return (*(x)==0?-400.f:log(*(x)**(x))*4.34294480f); + return (*(x)==0?-400.f:logf(*(x)**(x))*4.34294480f); } #endif @@ -75,7 +75,7 @@ bool ComputeSpectrum(float * data, int width, // of the power, instead of the square root for (i = 0; i < windowSize; i++) - in[i] = pow(in[i], 1.0f / 3.0f); + in[i] = powf(in[i], 1.0f / 3.0f); // Take FFT FFT(windowSize, false, in, NULL, out, out2); @@ -128,7 +128,7 @@ bool ComputeSpectrum(float * data, int width, for (i = 0; i < half; i++){ float temp=(processed[i] / windowSize / windows); if (temp > 0.0) - processed[i] = 10*log10(temp); + processed[i] = 10*log10f(temp); else processed[i] = 0; } diff --git a/src/TrackArtist.cpp b/src/TrackArtist.cpp index edd319c..2257402 100644 --- a/src/TrackArtist.cpp +++ b/src/TrackArtist.cpp @@ -1812,14 +1812,14 @@ void TrackArtist::DrawClipSpectrum(WaveTrack* track, WaveClip *clip, sampleCount w1 = (sampleCount) ((t0*rate + x *rate *tstep) + .5); const float -// e=exp(1.0f), - log2=log(2.0f), +// e=expf(1.0f), + log2=logf(2.0f), f=rate/2.0f/half, - lmin=log(float(minFreq)), - lmax=log(float(maxFreq)), + lmin=logf(float(minFreq)), + lmax=logf(float(maxFreq)), #ifdef EXPERIMENTAL_FFT_SKIP_POINTS - lmins=log(float(minFreq)/(fftSkipPoints+1)), - lmaxs=log(float(maxFreq)/(fftSkipPoints+1)), + lmins=logf(float(minFreq)/(fftSkipPoints+1)), + lmaxs=logf(float(maxFreq)/(fftSkipPoints+1)), #else //!EXPERIMENTAL_FFT_SKIP_POINTS lmins=lmin, lmaxs=lmax, @@ -1835,10 +1835,10 @@ void TrackArtist::DrawClipSpectrum(WaveTrack* track, WaveClip *clip, for (int y = 0; y < mid.height; y++) { float n =(float(y )/mid.height*scale2-lmin2)*12; float n2=(float(y+1)/mid.height*scale2-lmin2)*12; - float f =float(minFreq)/(fftSkipPoints+1)*pow(2.0f, n /12.0f+lmin2); - float f2=float(minFreq)/(fftSkipPoints+1)*pow(2.0f, n2/12.0f+lmin2); - n =log(f /440)/log2*12; - n2=log(f2/440)/log2*12; + float f =float(minFreq)/(fftSkipPoints+1)*powf(2.0f, n /12.0f+lmin2); + float f2=float(minFreq)/(fftSkipPoints+1)*powf(2.0f, n2/12.0f+lmin2); + n =logf(f /440)/log2*12; + n2=logf(f2/440)/log2*12; if (floor(n) < floor(n2)) yGrid[y]=true; else @@ -1856,9 +1856,9 @@ void TrackArtist::DrawClipSpectrum(WaveTrack* track, WaveClip *clip, f2bin = half/(rate/2.0f), #endif //EXPERIMENTAL_FFT_SKIP_POINTS bin2f = 1.0f/f2bin, - minDistance = pow(2.0f, 2.0f/12.0f), - i0=exp(lmin)/f, - i1=exp(scale+lmin)/f, + minDistance = powf(2.0f, 2.0f/12.0f), + i0=expf(lmin)/f, + i1=expf(scale+lmin)/f, minColor=0.0f; const int maxTableSize=1024; int *indexes=new int[maxTableSize]; @@ -1967,19 +1967,19 @@ void TrackArtist::DrawClipSpectrum(WaveTrack* track, WaveClip *clip, } // The f2pix helper macro converts a frequency into a pixel coordinate. -#define f2pix(f) (log(f)-lmins)/(lmaxs-lmins)*mid.height +#define f2pix(f) (logf(f)-lmins)/(lmaxs-lmins)*mid.height // Possibly quantize the maxima frequencies and create the pixel block limits. for (int i=0; i < maximas; i++) { int index=maxima[i]; float f = float(index)*bin2f; if (findNotesQuantize) - { f = exp(int(log(f/440)/log2*12-0.5)/12.0f*log2)*440; + { f = expf(int(logf(f/440)/log2*12-0.5)/12.0f*log2)*440; maxima[i] = f*f2bin; } - float f0 = exp((log(f/440)/log2*24-1)/24.0f*log2)*440; + float f0 = expf((logf(f/440)/log2*24-1)/24.0f*log2)*440; maxima0[i] = f2pix(f0); - float f1 = exp((log(f/440)/log2*24+1)/24.0f*log2)*440; + float f1 = expf((logf(f/440)/log2*24+1)/24.0f*log2)*440; maxima1[i] = f2pix(f1); } } @@ -1991,14 +1991,14 @@ void TrackArtist::DrawClipSpectrum(WaveTrack* track, WaveClip *clip, for (int yy = 0; yy < mid.height; yy++) { if(!usePxCache) { float h=float(yy)/mid.height; - float yy2=exp(h*scale+lmin)/f; + float yy2=expf(h*scale+lmin)/f; if (int(yy2)>=half) yy2=half-1; if (yy2<0) yy2=0; float bin0 = float(yy2); float h1=float(yy+1)/mid.height; - float yy3=exp(h1*scale+lmin)/f; + float yy3=expf(h1*scale+lmin)/f; if (int(yy3)>=half) yy3=half-1; if (yy3<0) diff --git a/src/configtemplate.h b/src/configtemplate.h index 1c439f2..12ab55a 100644 --- a/src/configtemplate.h +++ b/src/configtemplate.h @@ -22,6 +22,9 @@ /* Define if you have C99's lrintf function. */ #undef HAVE_LRINTF +/* Define if you have pow10f function. */ +#undef HAVE_POW10F + /* Define to 1 if you have the <memory.h> header file. */ #undef HAVE_MEMORY_H diff --git a/src/effects/NoiseRemoval.cpp b/src/effects/NoiseRemoval.cpp index 788ee9b..87c9921 100644 --- a/src/effects/NoiseRemoval.cpp +++ b/src/effects/NoiseRemoval.cpp @@ -469,7 +469,7 @@ void EffectNoiseRemoval::FillFirstHistoryWindow() double power = mRealFFTs[0][i] * mRealFFTs[0][i] + mImagFFTs[0][i] * mImagFFTs[0][i]; - mSpectrums[0][i] = (float)(10.0 * log10(power)); + mSpectrums[0][i] = (float)(10.0 * log10f(power)); mGains[0][i] = mNoiseGain; } } @@ -584,7 +584,11 @@ void EffectNoiseRemoval::RemoveNoise() // Apply gain to FFT for (j = 0; j < mSpectrumSize; j++) { - float mult = pow(10.0, mGains[out][j] / 20.0); +#ifdef HAVE_POW10F + float mult = pow10f(mGains[out][j] / 20.0); +#else + float mult = powf(10.0, mGains[out][j] / 20.0); +#endif mRealFFTs[out][j] *= mult; mImagFFTs[out][j] *= mult; ------------------------------------------------------------ |