3 #ifndef SPECTMORPH_IFFT_SYNTH_HH 4 #define SPECTMORPH_IFFT_SYNTH_HH 22 double freq256_factor;
30 SIN_TABLE_SIZE = 4096,
34 static std::vector<float> sin_table;
37 enum WindowType { WIN_BLACKMAN_HARRIS_92, WIN_HANNING };
38 enum OutputMode { REPLACE, ADD };
40 IFFTSynth (
size_t block_size,
double mix_freq, WindowType win_type);
46 zero_float_block (block_size, fft_in);
55 inline void render_partial (
double freq,
double mag,
double phase);
56 void get_samples (
float *samples, OutputMode output_mode = REPLACE);
58 double quantized_freq (
double freq);
63 std::vector<float> win_trans;
69 IFFTSynth::render_partial (
double mf_freq,
double mag,
double phase)
73 const int freq256 = sm_round_positive (mf_freq * freq256_factor);
74 const int ibin = freq256 >> 8;
75 float *sp = fft_in + 2 * (ibin - range);
76 const float *wmag_p = &table->win_trans[(freq256 & 0xff) * (range * 2 + 1)];
78 const float nmag = mag * mag_norm;
83 int iarg = sm_round_positive (phase * (SIN_TABLE_SIZE / (2 * M_PI)));
87 int iphase_adjust = freq256 * SIN_TABLE_SIZE / 512 + (SIN_TABLE_SIZE - SIN_TABLE_SIZE / 4);
88 iarg += iphase_adjust;
90 const float phase_rsmag = sin_table [iarg & SIN_TABLE_MASK] * nmag;
91 iarg += SIN_TABLE_SIZE / 4;
92 const float phase_rcmag = sin_table [iarg & SIN_TABLE_MASK] * nmag;
95 if (ibin > range && 2 * (ibin + range) <
static_cast<int> (block_size))
97 for (
int i = 0; i <= 2 * range; i++)
99 const float wmag = wmag_p[i];
100 *sp++ += phase_rcmag * wmag;
101 *sp++ += phase_rsmag * wmag;
107 for (
int i = -range; i <= range; i++)
109 const float wmag = wmag_p[i];
112 fft_in[-(ibin + i) * 2] += phase_rcmag * wmag;
113 fft_in[-(ibin + i) * 2 + 1] -= phase_rsmag * wmag;
115 else if ((ibin + i) == 0)
117 fft_in[0] += 2 * phase_rcmag * wmag;
119 else if (2 * (ibin + i) ==
static_cast<int> (block_size))
121 fft_in[1] += 2 * phase_rcmag * wmag;
123 else if (2 * (ibin + i) >
static_cast<int> (block_size))
125 int p = block_size - (2 * (ibin + i) - block_size);
127 fft_in[p] += phase_rcmag * wmag;
128 fft_in[p + 1] -= phase_rsmag * wmag;
132 fft_in[(ibin + i) * 2] += phase_rcmag * wmag;
133 fft_in[(ibin + i) * 2 + 1] += phase_rsmag * wmag;
Definition: smifftsynth.hh:61
Definition: smifftsynth.hh:15
Definition: smalignedarray.cc:7