31 #include <boost/format.hpp> 48 FFTW_FORWARD, FFTW_ESTIMATE);
64 float anginc = 2.0 * M_PI / ((float)
fft_len - 1);
67 ang = anginc * ((float) i);
68 w[i] = a0 - a1 * cos(ang) + a2 * cos(2.0 * ang) -a3 * cos(3.0 * ang);
75 unsigned int inveclen)
80 repl_count = floor(((
float) inveclen) / ((
float)
fft_len));
81 float gain_adj = 1.0 / repl_count;
85 if(fft_len > inveclen) {
86 throw std::runtime_error((boost::format(
"inveclen %d less than fftlen %d\n") % inveclen % fft_len).str());
89 for(i = 0; i < (inveclen + 1 -
fft_len); i += (fft_len / 2)) {
90 std::complex<float> *v = &(invec[i]);
105 result[j] += gain_adj * (re * re + im * im);
112 unsigned int inveclen,
114 float accumulation_gain)
118 std::cerr <<
"Input vector is shorter than FFT buffer " <<
119 inveclen <<
" less than " <<
fft_len << std::endl;
132 outvec[j] =
result[k] * (1.0 - accumulation_gain) +
133 outvec[j] * accumulation_gain;
137 outvec[j] =
result[k] * (1.0 - accumulation_gain) +
138 outvec[j] * accumulation_gain;
143 unsigned int inveclen,
156 if(first) outvec[j] =
result[k];
158 outvec[j] = (
result[k] > outvec[j]) ?
result[k] : outvec[j];
163 if(first) outvec[j] =
result[k];
165 outvec[j] = (
result[k] > outvec[j]) ?
result[k] : outvec[j];
float * initBlackmanHarris()
all spectrograms are under a blackman harris window
void apply_acc(std::complex< float > *invec, unsigned int inveclen, float *outvec, float accumulation_gain=0.0)
Calculate the spectrogram from an input vector – add it to an accumulation buffer.
Spectrogram(unsigned int fftlen)
Constructor.
std::complex< float > * win_samp
std::complex< float > * fft_out
void apply_max(std::complex< float > *invec, unsigned int inveclen, float *outvec, bool first=true)
Calculate the spectrogram from an input vector – add it to an accumulation buffer.
void apply_common(std::complex< float > *invec, unsigned int inveclen)
this is the common spectrogram calculation (window + fft + mag)