56 lines
1.7 KiB
C++
56 lines
1.7 KiB
C++
/** inc/complex_frames.h
|
|
|
|
Defines the interface for the `RealtimeHilbert` class.
|
|
|
|
This is a stateful processor designed for continuous, low-latency, real-time
|
|
audio streaming. It uses an internal history buffer and an overlap-add to prevent
|
|
artifacts that would occur with block-based processing of the same chunk-sizes.
|
|
|
|
The point of this is to provide a complex stream alongside the raw real stream simultaneously.
|
|
It's kind of the core of this whole engine. This is what allowed the spiral visualizer idea to work in real-time.
|
|
|
|
**/
|
|
|
|
#ifndef COMPLEX_FRAMES_H
|
|
#define COMPLEX_FRAMES_H
|
|
|
|
#include <vector>
|
|
#include <complex>
|
|
#include <utility>
|
|
#include <fftw3.h>
|
|
|
|
class RealtimeHilbert {
|
|
public:
|
|
RealtimeHilbert();
|
|
~RealtimeHilbert();
|
|
|
|
void reinit(size_t fft_size);
|
|
std::pair<std::vector<std::complex<double>>, std::vector<std::complex<double>>>
|
|
process(const std::vector<double>& left_input_block, const std::vector<double>& right_input_block);
|
|
|
|
private:
|
|
void cleanup();
|
|
|
|
size_t m_fft_size;
|
|
size_t m_hop_size;
|
|
std::vector<double> m_history_buffer_L;
|
|
std::vector<double> m_history_buffer_R;
|
|
|
|
// --- Left Channel Resources ---
|
|
fftw_plan m_plan_forward_L;
|
|
fftw_plan m_plan_backward_L;
|
|
double* m_fft_input_real_L;
|
|
fftw_complex* m_fft_output_spectrum_L;
|
|
fftw_complex* m_ifft_input_spectrum_L;
|
|
fftw_complex* m_ifft_output_complex_L;
|
|
|
|
// --- Right Channel Resources ---
|
|
fftw_plan m_plan_forward_R;
|
|
fftw_plan m_plan_backward_R;
|
|
double* m_fft_input_real_R;
|
|
fftw_complex* m_fft_output_spectrum_R;
|
|
fftw_complex* m_ifft_input_spectrum_R;
|
|
fftw_complex* m_ifft_output_complex_R;
|
|
};
|
|
|
|
#endif // COMPLEX_FRAMES_H
|