Audacity 3.2.0
Functions
anonymous_namespace{SpectrumCache.cpp} Namespace Reference

Functions

static void ComputeSpectrumUsingRealFFTf (float *__restrict buffer, const FFTParam *hFFT, const float *__restrict window, size_t len, float *__restrict out)
 
void ComputeSpectrogramGainFactors (size_t fftLen, double rate, int frequencyGain, std::vector< float > &gainFactors)
 

Function Documentation

◆ ComputeSpectrogramGainFactors()

void anonymous_namespace{SpectrumCache.cpp}::ComputeSpectrogramGainFactors ( size_t  fftLen,
double  rate,
int  frequencyGain,
std::vector< float > &  gainFactors 
)

Definition at line 53 of file SpectrumCache.cpp.

55{
56 if (frequencyGain > 0) {
57 // Compute a frequency-dependent gain factor
58 // scaled such that 1000 Hz gets a gain of 0dB
59
60 // This is the reciprocal of the bin number of 1000 Hz:
61 const double factor = ((double)rate / (double)fftLen) / 1000.0;
62
63 auto half = fftLen / 2;
64 gainFactors.reserve(half);
65 // Don't take logarithm of zero! Let bin 0 replicate the gain factor for bin 1.
66 gainFactors.push_back(frequencyGain*log10(factor));
67 for (decltype(half) x = 1; x < half; x++) {
68 gainFactors.push_back(frequencyGain*log10(factor * x));
69 }
70 }
71}

Referenced by SpecCache::Populate().

Here is the caller graph for this function:

◆ ComputeSpectrumUsingRealFFTf()

static void anonymous_namespace{SpectrumCache.cpp}::ComputeSpectrumUsingRealFFTf ( float *__restrict  buffer,
const FFTParam hFFT,
const float *__restrict  window,
size_t  len,
float *__restrict  out 
)
static

Definition at line 24 of file SpectrumCache.cpp.

27{
28 size_t i;
29 if(len > hFFT->Points * 2)
30 len = hFFT->Points * 2;
31 for(i = 0; i < len; i++)
32 buffer[i] *= window[i];
33 for( ; i < (hFFT->Points * 2); i++)
34 buffer[i] = 0; // zero pad as needed
35 RealFFTf(buffer, hFFT);
36 // Handle the (real-only) DC
37 float power = buffer[0] * buffer[0];
38 if(power <= 0)
39 out[0] = -160.0;
40 else
41 out[0] = 10.0 * log10f(power);
42 for(i = 1; i < hFFT->Points; i++) {
43 const int index = hFFT->BitReversed[i];
44 const float re = buffer[index], im = buffer[index + 1];
45 power = re * re + im * im;
46 if(power <= 0)
47 out[i] = -160.0;
48 else
49 out[i] = 10.0*log10f(power);
50 }
51}
void RealFFTf(fft_type *buffer, const FFTParam *h)
Definition: RealFFTf.cpp:161
constexpr fastfloat_really_inline int32_t power(int32_t q) noexcept
Definition: fast_float.h:1454
size_t Points
Definition: RealFFTf.h:10
ArrayOf< int > BitReversed
Definition: RealFFTf.h:8

References FFTParam::BitReversed, FFTParam::Points, fast_float::detail::power(), and RealFFTf().

Referenced by SpecCache::CalculateOneSpectrum().

Here is the call graph for this function:
Here is the caller graph for this function: