Skip to content

Commit 7039244

Browse files
committed
Applying cosine window before and after spectral processing
1 parent 71aee69 commit 7039244

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/main/misc/windows.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ namespace lsp
251251
if (n == 0)
252252
return;
253253

254-
float f = M_PI / n;
254+
float f = M_PI / (n - 1);
255255
for (size_t i=0; i<n; ++i)
256256
{
257257
float a = sinf(f * i);

src/main/util/SpectralProcessor.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ namespace lsp
121121
pFftBuf = &pInBuf[buf_size];
122122

123123
// Clear buffers and reset pointers
124-
windows::sqr_cosine(pWnd, buf_size);
124+
windows::cosine(pWnd, buf_size);
125125
dsp::fill_zero(pOutBuf, buf_size*4); // OutBuf + InBuf + Fft(x2)
126126
nOffset = buf_size * (fPhase * 0.5f);
127127

@@ -161,19 +161,20 @@ namespace lsp
161161
if (pFunc != NULL)
162162
{
163163
// Perform FFT and processing
164-
dsp::pcomplex_r2c(pFftBuf, pInBuf, buf_size); // Convert from real to packed complex
165-
dsp::packed_direct_fft(pFftBuf, pFftBuf, nRank); // Perform direct FFT
166-
pFunc(pObject, pSubject, pFftBuf, nRank); // Call the function
167-
dsp::packed_reverse_fft(pFftBuf, pFftBuf, nRank); // Perform reverse FFT
168-
dsp::pcomplex_c2r(pFftBuf, pFftBuf, buf_size); // Unpack complex numbers
164+
dsp::mul3(&pFftBuf[buf_size], pInBuf, pWnd, buf_size); // Apply cosine window before transform
165+
dsp::pcomplex_r2c(pFftBuf, &pFftBuf[buf_size], buf_size); // Convert from real to packed complex
166+
dsp::packed_direct_fft(pFftBuf, pFftBuf, nRank); // Perform direct FFT
167+
pFunc(pObject, pSubject, pFftBuf, nRank); // Call the function
168+
dsp::packed_reverse_fft(pFftBuf, pFftBuf, nRank); // Perform reverse FFT
169+
dsp::pcomplex_c2r(pFftBuf, pFftBuf, buf_size); // Unpack complex numbers
169170
}
170171
else
171-
dsp::move(pFftBuf, pInBuf, buf_size); // Copy data to FFT buffer
172+
dsp::mul3(pFftBuf, pInBuf, pWnd, buf_size); // Copy data to FFT buffer
172173

173174
// Apply signal to buffer
174175
dsp::move(pOutBuf, &pOutBuf[frame_size], frame_size); // Shift output buffer
175176
dsp::fill_zero(&pOutBuf[frame_size], frame_size); // Fill tail of input buffer with zeros
176-
dsp::fmadd3(pOutBuf, pFftBuf, pWnd, buf_size); // Apply window and add to the output buffer
177+
dsp::fmadd3(pOutBuf, pFftBuf, pWnd, buf_size); // Apply cosine window (-> squared cosine) and add to the output buffer
177178

178179
// Shift input buffer
179180
dsp::move(pInBuf, &pInBuf[frame_size], frame_size); // Shift input buffer
@@ -214,9 +215,10 @@ namespace lsp
214215
if (pFunc != NULL)
215216
{
216217
// Perform FFT and processing
217-
dsp::pcomplex_r2c(pFftBuf, pInBuf, buf_size); // Convert from real to packed complex
218-
dsp::packed_direct_fft(pFftBuf, pFftBuf, nRank); // Perform direct FFT
219-
pFunc(pObject, pSubject, pFftBuf, nRank); // Call the function
218+
dsp::mul3(&pFftBuf[buf_size], pInBuf, pWnd, buf_size); // Apply cosine window before transform
219+
dsp::pcomplex_r2c(pFftBuf, &pFftBuf[buf_size], buf_size); // Convert from real to packed complex
220+
dsp::packed_direct_fft(pFftBuf, pFftBuf, nRank); // Perform direct FFT
221+
pFunc(pObject, pSubject, pFftBuf, nRank); // Call the function
220222
}
221223

222224
// Apply signal to buffer

0 commit comments

Comments
 (0)