cepstrum_extractor/
conversions.rs1use rustfft::num_complex::Complex;
2use rustfft::num_traits::Num;
3
4pub trait RealToComplex<T> {
6 fn to_complex_vec(&self) -> Vec<Complex<T>>;
8}
9
10pub trait ComplexToReal<T> {
12 fn to_real_vec(&self) -> Vec<T>;
14}
15
16#[inline(always)]
18pub fn real_to_complex<T: Copy + Num>(this: &[T]) -> Vec<Complex<T>> {
19 this.iter().map(|r| Complex::from(r)).collect()
20}
21
22#[inline(always)]
23pub fn complex_to_real<T: Copy + Num>(this: &[Complex<T>]) -> Vec<T> {
25 this.iter().map(|c| c.re).collect()
26}
27
28impl<T: Copy + Num> RealToComplex<T> for [T] {
29 #[inline(always)]
30 fn to_complex_vec(&self) -> Vec<Complex<T>> {
31 real_to_complex(self)
32 }
33}
34impl<T: Copy + Num> ComplexToReal<T> for [Complex<T>] {
35 #[inline(always)]
36 fn to_real_vec(&self) -> Vec<T> {
37 complex_to_real(self)
38 }
39}