pub use rustfft; pub use rustfft::num_complex; pub use rustfft::num_traits; use rustfft::Length; #[macro_use] mod common; /// Algorithms for computing the Modified Discrete Cosine Transform pub mod mdct; pub mod algorithm; mod array_utils; mod plan; mod twiddles; pub use crate::common::DctNum; pub use self::plan::DctPlanner; #[cfg(test)] mod test_utils; pub trait RequiredScratch { fn get_scratch_len(&self) -> usize; } /// A trait for algorithms which compute the Discrete Cosine Transform Type 1 (DCT1) pub trait Dct1: RequiredScratch + Length + Sync + Send { /// Computes the DCT Type 1 on the provided buffer, in-place. /// /// This method may allocate a Vec of scratch space as needed. If you'd like to reuse that allocation between /// multiple computations, consider calling `process_dct1_with_scratch` instead. /// /// Does not normalize outputs. fn process_dct1(&self, buffer: &mut [T]) { let mut scratch = vec![T::zero(); self.get_scratch_len()]; self.process_dct1_with_scratch(buffer, &mut scratch); } /// Computes the DCT Type 1 on the provided buffer, in-place. Uses the provided `scratch` buffer as scratch space. /// /// Does not normalize outputs. fn process_dct1_with_scratch(&self, buffer: &mut [T], scratch: &mut [T]); } /// A trait for algorithms which compute the Discrete Cosine Transform Type 2 (DCT2) pub trait Dct2: RequiredScratch + Length + Sync + Send { /// Computes the DCT Type 2 on the provided buffer, in-place. /// /// This method may allocate a Vec of scratch space as needed. If you'd like to reuse that allocation between /// multiple computations, consider calling `process_dct2_with_scratch` instead. /// /// Does not normalize outputs. fn process_dct2(&self, buffer: &mut [T]) { let mut scratch = vec![T::zero(); self.get_scratch_len()]; self.process_dct2_with_scratch(buffer, &mut scratch); } /// Computes the DCT Type 2 on the provided buffer, in-place. Uses the provided `scratch` buffer as scratch space. /// /// Does not normalize outputs. fn process_dct2_with_scratch(&self, buffer: &mut [T], scratch: &mut [T]); } /// A trait for algorithms which compute the Discrete Cosine Transform Type 3 (DCT3) pub trait Dct3: RequiredScratch + Length + Sync + Send { /// Computes the DCT Type 3 on the provided buffer, in-place. /// /// This method may allocate a Vec of scratch space as needed. If you'd like to reuse that allocation between /// multiple computations, consider calling `process_dct3_with_scratch` instead. /// /// Does not normalize outputs. fn process_dct3(&self, buffer: &mut [T]) { let mut scratch = vec![T::zero(); self.get_scratch_len()]; self.process_dct3_with_scratch(buffer, &mut scratch); } /// Computes the DCT Type 3 on the provided buffer, in-place. Uses the provided `scratch` buffer as scratch space. /// /// Does not normalize outputs. fn process_dct3_with_scratch(&self, buffer: &mut [T], scratch: &mut [T]); } /// A trait for algorithms which compute the Discrete Cosine Transform Type 4 (DCT4) pub trait Dct4: RequiredScratch + Length + Sync + Send { /// Computes the DCT Type 4 on the provided buffer, in-place. /// /// This method may allocate a Vec of scratch space as needed. If you'd like to reuse that allocation between /// multiple computations, consider calling `process_dst4_with_scratch` instead. /// /// Does not normalize outputs. fn process_dct4(&self, buffer: &mut [T]) { let mut scratch = vec![T::zero(); self.get_scratch_len()]; self.process_dct4_with_scratch(buffer, &mut scratch); } /// Computes the DCT Type 4 on the provided buffer, in-place. Uses the provided `scratch` buffer as scratch space. /// /// Does not normalize outputs. fn process_dct4_with_scratch(&self, buffer: &mut [T], scratch: &mut [T]); } /// A trait for algorithms which compute the Discrete Cosine Transform Type 5 (DCT5) pub trait Dct5: RequiredScratch + Length + Sync + Send { /// Computes the DCT Type 5 on the provided buffer, in-place. /// /// This method may allocate a Vec of scratch space as needed. If you'd like to reuse that allocation between /// multiple computations, consider calling `process_dct5_with_scratch` instead. /// /// Does not normalize outputs. fn process_dct5(&self, buffer: &mut [T]) { let mut scratch = vec![T::zero(); self.get_scratch_len()]; self.process_dct5_with_scratch(buffer, &mut scratch); } /// Computes the DCT Type 5 on the provided buffer, in-place. Uses the provided `scratch` buffer as scratch space. /// /// Does not normalize outputs. fn process_dct5_with_scratch(&self, buffer: &mut [T], scratch: &mut [T]); } /// A trait for algorithms which compute the Discrete Cosine Transform Type 6 (DCT6) pub trait Dct6: RequiredScratch + Length + Sync + Send { /// Computes the DCT Type 6 on the provided buffer, in-place. /// /// This method may allocate a Vec of scratch space as needed. If you'd like to reuse that allocation between /// multiple computations, consider calling `process_dct6_with_scratch` instead. /// /// Does not normalize outputs. fn process_dct6(&self, buffer: &mut [T]) { let mut scratch = vec![T::zero(); self.get_scratch_len()]; self.process_dct6_with_scratch(buffer, &mut scratch); } /// Computes the DCT Type 6 on the provided buffer, in-place. Uses the provided `scratch` buffer as scratch space. /// /// Does not normalize outputs. fn process_dct6_with_scratch(&self, buffer: &mut [T], scratch: &mut [T]); } /// A trait for algorithms which compute the Discrete Cosine Transform Type 7 (DCT7) pub trait Dct7: RequiredScratch + Length + Sync + Send { /// Computes the DCT Type 7 on the provided buffer, in-place. /// /// This method may allocate a Vec of scratch space as needed. If you'd like to reuse that allocation between /// multiple computations, consider calling `process_dct7_with_scratch` instead. /// /// Does not normalize outputs. fn process_dct7(&self, buffer: &mut [T]) { let mut scratch = vec![T::zero(); self.get_scratch_len()]; self.process_dct7_with_scratch(buffer, &mut scratch); } /// Computes the DCT Type 7 on the provided buffer, in-place. Uses the provided `scratch` buffer as scratch space. /// /// Does not normalize outputs. fn process_dct7_with_scratch(&self, buffer: &mut [T], scratch: &mut [T]); } /// A trait for algorithms which compute the Discrete Cosine Transform Type 8 (DCT8) pub trait Dct8: RequiredScratch + Length + Sync + Send { /// Computes the DCT Type 8 on the provided buffer, in-place. /// /// This method may allocate a Vec of scratch space as needed. If you'd like to reuse that allocation between /// multiple computations, consider calling `process_dct8_with_scratch` instead. /// /// Does not normalize outputs. fn process_dct8(&self, buffer: &mut [T]) { let mut scratch = vec![T::zero(); self.get_scratch_len()]; self.process_dct8_with_scratch(buffer, &mut scratch); } /// Computes the DCT Type 8 on the provided buffer, in-place. Uses the provided `scratch` buffer as scratch space. /// /// Does not normalize outputs. fn process_dct8_with_scratch(&self, buffer: &mut [T], scratch: &mut [T]); } /// A trait for algorithms which compute the Discrete Sine Transform Type 1 (DST1) pub trait Dst1: RequiredScratch + Length + Sync + Send { /// Computes the DST Type 1 on the provided buffer, in-place. /// /// This method may allocate a Vec of scratch space as needed. If you'd like to reuse that allocation between /// multiple computations, consider calling `process_dst1_with_scratch` instead. /// /// Does not normalize outputs. fn process_dst1(&self, buffer: &mut [T]) { let mut scratch = vec![T::zero(); self.get_scratch_len()]; self.process_dst1_with_scratch(buffer, &mut scratch); } /// Computes the DST Type 1 on the provided buffer, in-place. Uses the provided `scratch` buffer as scratch space. /// /// Does not normalize outputs. fn process_dst1_with_scratch(&self, buffer: &mut [T], scratch: &mut [T]); } /// A trait for algorithms which compute the Discrete Sine Transform Type 2 (DST2) pub trait Dst2: RequiredScratch + Length + Sync + Send { /// Computes the DST Type 2 on the provided buffer, in-place. /// /// This method may allocate a Vec of scratch space as needed. If you'd like to reuse that allocation between /// multiple computations, consider calling `process_dst2_with_scratch` instead. /// /// Does not normalize outputs. fn process_dst2(&self, buffer: &mut [T]) { let mut scratch = vec![T::zero(); self.get_scratch_len()]; self.process_dst2_with_scratch(buffer, &mut scratch); } /// Computes the DST Type 2 on the provided buffer, in-place. Uses the provided `scratch` buffer as scratch space. /// /// Does not normalize outputs. fn process_dst2_with_scratch(&self, buffer: &mut [T], scratch: &mut [T]); } /// A trait for algorithms which compute the Discrete Sine Transform Type 3 (DST3) pub trait Dst3: RequiredScratch + Length + Sync + Send { /// Computes the DST Type 3 on the provided buffer, in-place. /// /// This method may allocate a Vec of scratch space as needed. If you'd like to reuse that allocation between /// multiple computations, consider calling `process_dst3_with_scratch` instead. /// /// Does not normalize outputs. fn process_dst3(&self, buffer: &mut [T]) { let mut scratch = vec![T::zero(); self.get_scratch_len()]; self.process_dst3_with_scratch(buffer, &mut scratch); } /// Computes the DST Type 3 on the provided buffer, in-place. Uses the provided `scratch` buffer as scratch space. /// /// Does not normalize outputs. fn process_dst3_with_scratch(&self, buffer: &mut [T], scratch: &mut [T]); } /// A trait for algorithms which compute the Discrete Sine Transform Type 4 (DST4) pub trait Dst4: RequiredScratch + Length + Sync + Send { /// Computes the DST Type 4 on the provided buffer, in-place. /// /// This method may allocate a Vec of scratch space as needed. If you'd like to reuse that allocation between /// multiple computations, consider calling `process_dst4_with_scratch` instead. /// /// Does not normalize outputs. fn process_dst4(&self, buffer: &mut [T]) { let mut scratch = vec![T::zero(); self.get_scratch_len()]; self.process_dst4_with_scratch(buffer, &mut scratch); } /// Computes the DST Type 4 on the provided buffer, in-place. Uses the provided `scratch` buffer as scratch space. /// /// Does not normalize outputs. fn process_dst4_with_scratch(&self, buffer: &mut [T], scratch: &mut [T]); } /// A trait for algorithms which compute the Discrete Cosine Transform Type 5 (DST5) pub trait Dst5: RequiredScratch + Length + Sync + Send { /// Computes the DST Type 5 on the provided buffer, in-place. /// /// This method may allocate a Vec of scratch space as needed. If you'd like to reuse that allocation between /// multiple computations, consider calling `process_dst4_with_scratch` instead. /// /// Does not normalize outputs. fn process_dst5(&self, buffer: &mut [T]) { let mut scratch = vec![T::zero(); self.get_scratch_len()]; self.process_dst5_with_scratch(buffer, &mut scratch); } /// Computes the DST Type 5 on the provided buffer, in-place. Uses the provided `scratch` buffer as scratch space. /// /// Does not normalize outputs. fn process_dst5_with_scratch(&self, buffer: &mut [T], scratch: &mut [T]); } /// A trait for algorithms which compute the Discrete Cosine Transform Type 6 (DST6) pub trait Dst6: RequiredScratch + Length + Sync + Send { /// Computes the DST Type 6 on the provided buffer, in-place. /// /// This method may allocate a Vec of scratch space as needed. If you'd like to reuse that allocation between /// multiple computations, consider calling `process_dst6_with_scratch` instead. /// /// Does not normalize outputs. fn process_dst6(&self, buffer: &mut [T]) { let mut scratch = vec![T::zero(); self.get_scratch_len()]; self.process_dst6_with_scratch(buffer, &mut scratch); } /// Computes the DST Type 6 on the provided buffer, in-place. Uses the provided `scratch` buffer as scratch space. /// /// Does not normalize outputs. fn process_dst6_with_scratch(&self, buffer: &mut [T], scratch: &mut [T]); } /// A trait for algorithms which compute the Discrete Cosine Transform Type 7 (DST7) pub trait Dst7: RequiredScratch + Length + Sync + Send { /// Computes the DST Type 7 on the provided buffer, in-place. /// /// This method may allocate a Vec of scratch space as needed. If you'd like to reuse that allocation between /// multiple computations, consider calling `process_dst7_with_scratch` instead. /// /// Does not normalize outputs. fn process_dst7(&self, buffer: &mut [T]) { let mut scratch = vec![T::zero(); self.get_scratch_len()]; self.process_dst7_with_scratch(buffer, &mut scratch); } /// Computes the DST Type 7 on the provided buffer, in-place. Uses the provided `scratch` buffer as scratch space. /// /// Does not normalize outputs. fn process_dst7_with_scratch(&self, buffer: &mut [T], scratch: &mut [T]); } /// A trait for algorithms which compute the Discrete Cosine Transform Type 8 (DST8) pub trait Dst8: RequiredScratch + Length + Sync + Send { /// Computes the DST Type 8 on the provided buffer, in-place. /// /// This method may allocate a Vec of scratch space as needed. If you'd like to reuse that allocation between /// multiple computations, consider calling `process_dst8_with_scratch` instead. /// /// Does not normalize outputs. fn process_dst8(&self, buffer: &mut [T]) { let mut scratch = vec![T::zero(); self.get_scratch_len()]; self.process_dst8_with_scratch(buffer, &mut scratch); } /// Computes the DST Type 8 on the provided buffer, in-place. Uses the provided `scratch` buffer as scratch space. /// /// Does not normalize outputs. fn process_dst8_with_scratch(&self, buffer: &mut [T], scratch: &mut [T]); } /// A trait for algorithms that can compute all of DCT2, DCT3, DST2, DST3, all in one struct pub trait TransformType2And3: Dct2 + Dct3 + Dst2 + Dst3 {} /// A trait for algorithms that can compute both DCT4 and DST4, all in one struct pub trait TransformType4: Dct4 + Dst4 {} /// A trait for algorithms that can compute both DCT6 and DCT7, all in one struct pub trait Dct6And7: Dct6 + Dct7 {} /// A trait for algorithms that can compute both DST6 and DST7, all in one struct pub trait Dst6And7: Dst6 + Dst7 {} #[test] fn test_send_sync_impls() { fn assert_send_sync() where T: Send + Sync, { } assert_send_sync::>(); assert_send_sync::>(); assert_send_sync::>(); assert_send_sync::>(); assert_send_sync::>(); assert_send_sync::>(); assert_send_sync::>(); assert_send_sync::>(); assert_send_sync::>(); assert_send_sync::>(); assert_send_sync::>(); assert_send_sync::>(); assert_send_sync::>(); assert_send_sync::>(); assert_send_sync::>(); assert_send_sync::>(); assert_send_sync::>(); assert_send_sync::>(); assert_send_sync::>(); assert_send_sync::>(); assert_send_sync::>(); assert_send_sync::>(); assert_send_sync::>(); assert_send_sync::>(); assert_send_sync::>(); assert_send_sync::>(); assert_send_sync::>(); assert_send_sync::>(); assert_send_sync::>(); assert_send_sync::>(); assert_send_sync::>(); assert_send_sync::>(); assert_send_sync::>(); assert_send_sync::>(); }