4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
26 #include "samples.inc"
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);
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);
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);
54 class CrossfadeFFT : public FFT
58 virtual ~CrossfadeFFT();
61 int initialize(int window_size);
62 long get_delay(); // Number of samples fifo is delayed
64 int fix_window_size();
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,
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,
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();
91 // Size of a window. Automatically fixed to a power of 2
94 // Frequency domain output of FFT
97 // Time domain output of FFT
103 // input for complete windows
104 Samples *input_buffer;
105 // output for crossfaded windows with overflow
106 double *output_buffer;
108 // samples in input_buffer
111 long input_allocation;
112 // Samples in output buffer less window border
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