Fixed initialisation of tf in file_open(). Without setting the memory to 0,
[cinelerra_cv/mob.git] / plugins / libfourier / fourier.h
blob9aefc7b30099a8c4a94818fe246882b746655cb4
1 #ifndef FOURIER_H
2 #define FOURIER_H
6 #include <stdint.h>
7 #include <fftw3.h>
9 #include "mutex.h"
11 typedef struct fftw_plan_desc {
12 int samples;
13 fftw_plan plan_forward;
14 fftw_plan plan_backward;
15 fftw_plan_desc *next;
18 class FFT
20 public:
21 FFT();
22 ~FFT();
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,
38 int inverse,
39 fftw_complex *data);
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
51 public:
52 CrossfadeFFT();
53 virtual ~CrossfadeFFT();
55 int reset();
56 int initialize(int window_size);
57 long get_delay(); // Number of samples fifo is delayed
58 int reconfigure();
59 int fix_window_size();
60 int delete_fft();
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,
74 long size,
75 double *output_ptr,
76 int direction);
78 int process_buffer_oversample(int64_t output_sample,
79 long size,
80 double *output_ptr,
81 int direction);
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,
86 int samples,
87 double *buffer);
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
98 long window_size;
100 // Output of FFT
101 double *freq_real;
102 double *freq_imag;
103 // data for FFT that is going to be done by FFTW
104 fftw_complex *fftw_data;
106 private:
108 // input for complete windows
109 double *input_buffer;
110 // output for crossfaded windows with overflow
111 double *output_buffer;
113 double *temp_real;
114 double *temp_imag;
116 // samples in input_buffer
117 long input_size;
118 // window_size
119 long input_allocation;
120 // Samples in output buffer less window border
121 long output_size;
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
129 int first_window;
132 // Number of samples that are already processed and waiting in output_buffer
133 int samples_ready;
134 // Hanning window precalculated
135 double *pre_window;
136 // Triangle window precalculated
137 double *post_window;
138 protected:
139 // Oversample factor
140 int oversample;
144 #endif