From 8cb5b63bf7f41d836106022735bfc1db7f8a4057 Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Sat, 27 Oct 2018 18:56:48 +0200 Subject: [PATCH] dsp: make IDCT (un)scaled --- src/codecs/atrac3.rs | 2 +- src/codecs/real/cook.rs | 2 +- src/dsp/mdct.rs | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/codecs/atrac3.rs b/src/codecs/atrac3.rs index 2a6b44c..c61a262 100644 --- a/src/codecs/atrac3.rs +++ b/src/codecs/atrac3.rs @@ -288,7 +288,7 @@ impl DSP { } Self { - imdct: IMDCT::new(FFTMode::SplitRadix, 512), + imdct: IMDCT::new(FFTMode::SplitRadix, 512, false), tmp: [0.0; ATRAC3_FRAME_SIZE + 64], gain_tab, gain_tab2, window, } diff --git a/src/codecs/real/cook.rs b/src/codecs/real/cook.rs index a03a5bb..2e8b45c 100644 --- a/src/codecs/real/cook.rs +++ b/src/codecs/real/cook.rs @@ -112,7 +112,7 @@ impl CookDSP { gain_tab[i] = pow_tab[i + 53].powf(8.0 / fsamples); } let size = samples; - CookDSP { imdct: IMDCT::new(FFTMode::SplitRadix, samples*2), window: window, out: [0.0; 2048], size, pow_tab, hpow_tab, gain_tab } + CookDSP { imdct: IMDCT::new(FFTMode::SplitRadix, samples*2, false), window: window, out: [0.0; 2048], size, pow_tab, hpow_tab, gain_tab } } } diff --git a/src/dsp/mdct.rs b/src/dsp/mdct.rs index b292739..540ae45 100644 --- a/src/dsp/mdct.rs +++ b/src/dsp/mdct.rs @@ -19,11 +19,12 @@ fn imdct(src: &[f32], dst: &mut [f32], length: usize) { }*/ impl IMDCT { - pub fn new(mode: FFTMode, size: usize) -> Self { + pub fn new(mode: FFTMode, size: usize, scaledown: bool) -> Self { let mut twiddle: Vec = Vec::with_capacity(size / 4); let factor = 2.0 * consts::PI / ((8 * size) as f32); + let scale = if scaledown { (1.0 / (size as f32)).sqrt() } else { 1.0 }; for k in 0..size/4 { - twiddle.push(FFTComplex::exp(factor * ((8 * k + 1) as f32))); + twiddle.push(FFTComplex::exp(factor * ((8 * k + 1) as f32)).scale(scale)); } let fft = FFTBuilder::new_fft(mode, size/4); let mut z: Vec = Vec::with_capacity(size / 2); -- 2.39.5