fast drag unselected edit, ctrl drag select in arrow mode
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / fourier.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #ifndef FOURIER_H
23 #define FOURIER_H
24
25
26 #include "samples.inc"
27
28 #include <stdint.h>
29
30
31 class FFT
32 {
33         static uint8_t rev_bytes[256];
34         static unsigned int reverse_bits(unsigned int index, unsigned int bits);
35         static void bit_reverse(unsigned int samples,
36                 double *real_in, double *imag_in,
37                 double *real_out, double *imag_out);
38 public:
39         FFT();
40         virtual ~FFT();
41         // can be in place, but imag_out must exist, imag_in optional
42         int do_fft(int samples, // must be a power of 2
43                 int inverse,             // 0 = forward FFT, 1 = inverse
44                 double *real_in, double *imag_in,       // complex input
45                 double *real_out, double *imag_out);    // complex output
46         int do_fft(int samples, int inverse, double *real, double *imag) {
47                 return do_fft(samples, inverse, real, imag, real, imag);
48         }
49         static unsigned int samples_to_bits(unsigned int samples);
50         static int symmetry(int size, double *freq_real, double *freq_imag);
51         virtual int update_progress(int current_position);
52 };
53
54 class CrossfadeFFT : public FFT
55 {
56 public:
57         CrossfadeFFT();
58         virtual ~CrossfadeFFT();
59
60         int reset();
61         int initialize(int window_size);
62         long get_delay();     // Number of samples fifo is delayed
63         int reconfigure();
64         int fix_window_size();
65         int delete_fft();
66
67
68 // Read enough samples from input to generate the requested number of samples.
69 // output_sample - tells it if we've seeked and the output overflow is invalid.
70 // return - 0 on success 1 on failure
71 // output_sample - start of samples if forward.  End of samples if reverse.
72 //               It's always contiguous.
73 // output_ptr - if nonzero, output is put here
74 // direction - PLAY_FORWARD or PLAY_REVERSE
75         int process_buffer(int64_t output_sample,
76                 long size,
77                 Samples *output_ptr,
78                 int direction);
79
80 // Called by process_buffer to read samples from input.
81 // Returns 1 on error or 0 on success.
82         virtual int read_samples(int64_t output_sample,
83                 int samples,
84                 Samples *buffer);
85
86 // Process a window in the frequency domain
87         virtual int signal_process();
88 // Process a window in the time domain after the frequency domain
89         virtual int post_process();
90
91 // Size of a window.  Automatically fixed to a power of 2
92         long window_size;
93
94 // Frequency domain output of FFT
95         double *freq_real;
96         double *freq_imag;
97 // Time domain output of FFT
98         double *output_real;
99         double *output_imag;
100
101 private:
102
103 // input for complete windows
104         Samples *input_buffer;
105 // output for crossfaded windows with overflow
106         double *output_buffer;
107
108 // samples in input_buffer
109         long input_size;
110 // window_size
111         long input_allocation;
112 // Samples in output buffer less window border
113         long output_size;
114 // Space in output buffer including window border
115         long output_allocation;
116 // Starting sample of output buffer in project
117         int64_t output_sample;
118 // Starting sample of input buffer in project
119         int64_t input_sample;
120 // Don't crossfade the first window
121         int first_window;
122 };
123
124 #endif