Skip to content

Commit

Permalink
LIB: IFFTSynth: simplify quantized freq computation (performance)
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Westerfeld <[email protected]>
  • Loading branch information
swesterfeld committed Jun 7, 2024
1 parent 150ed96 commit a9b5a01
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/smifftsynth.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ namespace SpectMorph {
}

IFFTSynth::IFFTSynth (size_t block_size, double mix_freq, WindowType win_type) :
block_size (block_size),
mix_freq (mix_freq)
block_size (block_size)
{
std::lock_guard lg (table_mutex);

Expand Down Expand Up @@ -86,6 +85,7 @@ IFFTSynth::IFFTSynth (size_t block_size, double mix_freq, WindowType win_type) :
fft_in = FFT::new_array_float (block_size);
fft_out = FFT::new_array_float (block_size);
freq256_factor = 1 / mix_freq * block_size * zero_padding;
freq256_to_qfreq = mix_freq / 256.0 / block_size;
mag_norm = 0.5 / block_size;
}

Expand Down
7 changes: 2 additions & 5 deletions lib/smifftsynth.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class IFFTSynth

int zero_padding;
size_t block_size;
float mix_freq;
float freq256_factor;
float freq256_to_qfreq;
float mag_norm;

float *fft_in;
Expand Down Expand Up @@ -152,10 +152,7 @@ inline float
IFFTSynth::quantized_freq (float mf_freq)
{
const int freq256 = sm_round_positive (mf_freq * freq256_factor);
const float qfreq = freq256 * float (1 / 256.0);
const float mf_qfreq = qfreq / block_size * mix_freq;

return mf_qfreq;
return freq256 * freq256_to_qfreq;
}

}
Expand Down

0 comments on commit a9b5a01

Please sign in to comment.