Skip to content

Commit

Permalink
Simplify stft coroutines
Browse files Browse the repository at this point in the history
  • Loading branch information
jurihock committed Nov 16, 2023
1 parent ccf9005 commit 2f09eca
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions cpp/StftPitchShift/STFT.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ namespace stftpitchshift
for (size_t hop = 0; (hop + synthesis_window_size) < size; hop += hopsize)
{
timers.analysis.tic();
reject(hop, input, frame, windows.analysis);
reject(input + hop, frame, windows.analysis);
transform(frame, dft);
timers.analysis.toc();

Expand All @@ -102,7 +102,7 @@ namespace stftpitchshift

timers.synthesis.tic();
transform(dft, frame);
inject(hop, output, frame, windows.synthesis);
inject(output + hop, frame, windows.synthesis);
timers.synthesis.toc();
}
timers.loop.toc();
Expand All @@ -116,13 +116,13 @@ namespace stftpitchshift
{
for (size_t hop = 0; (hop + synthesis_window_size) < size; hop += hopsize)
{
reject(hop, input, frame, windows.analysis);
reject(input + hop, frame, windows.analysis);
transform(frame, dft);

callback(dft);

transform(dft, frame);
inject(hop, output, frame, windows.synthesis);
inject(output + hop, frame, windows.synthesis);
}
}
}
Expand Down Expand Up @@ -163,19 +163,19 @@ namespace stftpitchshift
fft->ifft(dft, frame);
}

static void reject(const size_t hop, const T* input, std::vector<T>& frame, const std::vector<T>& window)
inline void reject(const T* input, std::vector<T>& frame, const std::vector<T>& window) const
{
for (size_t i = 0; i < frame.size(); ++i)
{
frame[i] = input[hop + i] * window[i];
frame[i] = input[i] * window[i];
}
}

static void inject(const size_t hop, T* const output, const std::vector<T>& frame, const std::vector<T>& window)
inline void inject(T* const output, const std::vector<T>& frame, const std::vector<T>& window) const
{
for (size_t i = 0; i < frame.size(); ++i)
{
output[hop + i] += frame[i] * window[i];
output[i] += frame[i] * window[i];
}
}

Expand Down

0 comments on commit 2f09eca

Please sign in to comment.