fft: FFT,
fwd: bool,
size: usize,
+ fwd_fft: bool,
}
fn crossadd(a: &FFTComplex, b: &FFTComplex) -> FFTComplex {
buf[0].re = a - b;
buf[0].im = a + b;
}
- self.fft.do_fft_inplace(buf, true);
+ self.fft.do_fft_inplace(buf, self.fwd_fft);
if self.fwd {
for n in 0..self.size/2 {
let in0 = buf[n + 1];
}
impl RDFTBuilder {
- pub fn new_rdft(mode: FFTMode, size: usize, forward: bool) -> RDFT {
+ pub fn new_rdft(mode: FFTMode, size: usize, forward: bool, forward_fft: bool) -> RDFT {
let mut table: Vec<FFTComplex> = Vec::with_capacity(size / 4);
let (base, scale) = if forward { (consts::PI / (size as f32), 0.5) } else { (-consts::PI / (size as f32), 1.0) };
for i in 0..size/2 {
table.push(FFTComplex::exp(base * ((i + 1) as f32)).scale(scale));
}
let fft = FFTBuilder::new_fft(mode, size);
- RDFT { table, fft, size, fwd: forward }
+ RDFT { table, fft, size, fwd: forward, fwd_fft: forward_fft }
}
}
fn test_rdft() {
let mut fin: [FFTComplex; 128] = [FFTC_ZERO; 128];
let mut fout1: [FFTComplex; 128] = [FFTC_ZERO; 128];
- let mut rdft = RDFTBuilder::new_rdft(FFTMode::SplitRadix, fin.len(), true);
+ let mut rdft = RDFTBuilder::new_rdft(FFTMode::SplitRadix, fin.len(), true, true);
let mut seed: u32 = 42;
for i in 0..fin.len() {
seed = seed.wrapping_mul(1664525).wrapping_add(1013904223);
fin[i].im = (val as f32) / 256.0;
}
rdft.do_rdft(&fin, &mut fout1);
- let mut irdft = RDFTBuilder::new_rdft(FFTMode::SplitRadix, fin.len(), false);
+ let mut irdft = RDFTBuilder::new_rdft(FFTMode::SplitRadix, fin.len(), false, true);
irdft.do_rdft_inplace(&mut fout1);
for i in 0..fin.len() {
for i in 0..(self.len >> 4) {
self.delay[chno][i] = self.coeffs[self.duration + i];
}
- } else { // somehow it ends here in reverse order
- for i in 0..self.len >> 2 {
- let t0 = self.coeffs[self.len - 2 - i * 2];
- let t1 = self.coeffs[self.len - 1 - i * 2];
- self.coeffs[self.len - 2 - i * 2] = self.coeffs[i * 2];
- self.coeffs[self.len - 1 - i * 2] = self.coeffs[i * 2 + 1];
- self.coeffs[i * 2] = t0;
- self.coeffs[i * 2 + 1] = t1;
- }
+ } else {
let overlap_len = if self.first_frm { 0 } else { self.len >> 8 };
overlap(&self.delay[0], &self.coeffs[0..], &mut dst[off0..], overlap_len, 2);
overlap(&self.delay[1], &self.coeffs[1..], &mut dst[off1..], overlap_len, 2);
self.duration >>= 1;
}
self.transform = if !self.use_dct {
- Transform::RDFT(RDFTBuilder::new_rdft(FFTMode::SplitRadix, self.len >> 1, false))
+ Transform::RDFT(RDFTBuilder::new_rdft(FFTMode::SplitRadix, self.len >> 1, false, false))
} else {
Transform::DCT(DCT::new(DCTMode::DCT_III, self.len))
};