11 typedef struct fftw_plan_desc
{
13 fftw_plan plan_forward
;
14 fftw_plan plan_backward
;
24 int do_fft(unsigned int samples
, // must be a power of 2
25 int inverse
, // 0 = forward FFT, 1 = inverse
26 double *real_in
, // array of input's real samples
27 double *imag_in
, // array of input's imag samples
28 double *real_out
, // array of output's reals
29 double *imag_out
); // array of output's imaginaries
30 int symmetry(int size
, double *freq_real
, double *freq_imag
);
31 unsigned int samples_to_bits(unsigned int samples
);
32 unsigned int reverse_bits(unsigned int index
, unsigned int bits
);
33 virtual int update_progress(int current_position
);
35 fftw_plan_desc
*my_fftw_plan
;
36 int ready_fftw(unsigned int samples
);
37 int do_fftw_inplace(unsigned int samples
,
41 // We have to get around the thread unsafety of fftw
42 static fftw_plan_desc
*fftw_plans
;
43 static Mutex plans_lock
;
49 class CrossfadeFFT
: public FFT
53 virtual ~CrossfadeFFT();
56 int initialize(int window_size
);
57 long get_delay(); // Number of samples fifo is delayed
59 int fix_window_size();
61 // functioy to be called to initialize oversampling
62 void set_oversample(int oversample
); // 2, 4,8 are good values
66 // Read enough samples from input to generate the requested number of samples.
67 // output_sample - tells it if we've seeked and the output overflow is invalid.
68 // return - 0 on success 1 on failure
69 // output_sample - start of samples if forward. End of samples if reverse.
70 // It's always contiguous.
71 // output_ptr - if nonzero, output is put here
72 // direction - PLAY_FORWARD or PLAY_REVERSE
73 int process_buffer(int64_t output_sample
,
78 int process_buffer_oversample(int64_t output_sample
,
83 // Called by process_buffer to read samples from input.
84 // Returns 1 on error or 0 on success.
85 virtual int read_samples(int64_t output_sample
,
89 // Process a window in the frequency domain, called by process_buffer()
90 virtual int signal_process();
92 // Process a window in the frequency domain, called by process_buffer_oversample()
93 // Reset parameter should cause to reset all accumulated data
94 virtual int signal_process_oversample(int reset
);
97 // Size of a window. Automatically fixed to a power of 2
103 // data for FFT that is going to be done by FFTW
104 fftw_complex
*fftw_data
;
108 // input for complete windows
109 double *input_buffer
;
110 // output for crossfaded windows with overflow
111 double *output_buffer
;
116 // samples in input_buffer
119 long input_allocation
;
120 // Samples in output buffer less window border
122 // Space in output buffer including window border
123 long output_allocation
;
124 // Starting sample of output buffer in project
125 int64_t output_sample
;
126 // Starting sample of input buffer in project
127 int64_t input_sample
;
128 // Don't crossfade the first window
132 // Number of samples that are already processed and waiting in output_buffer
134 // Hanning window precalculated
136 // Triangle window precalculated