1extern crate alloc;
4use alloc::vec::Vec;
5
6pub type Sample = f32;
8
9#[derive(Debug, Clone, Copy, PartialEq)]
11pub struct Complex {
12 pub re: f32,
13 pub im: f32,
14}
15
16impl Complex {
17 pub fn new(re: f32, im: f32) -> Self {
18 Self { re, im }
19 }
20
21 pub fn zero() -> Self {
22 Self { re: 0.0, im: 0.0 }
23 }
24
25 pub fn magnitude(&self) -> f32 {
26 (self.re * self.re + self.im * self.im).sqrt()
27 }
28}
29
30impl core::ops::Add for Complex {
31 type Output = Self;
32 fn add(self, rhs: Self) -> Self {
33 Self {
34 re: self.re + rhs.re,
35 im: self.im + rhs.im,
36 }
37 }
38}
39
40impl core::ops::Sub for Complex {
41 type Output = Self;
42 fn sub(self, rhs: Self) -> Self {
43 Self {
44 re: self.re - rhs.re,
45 im: self.im - rhs.im,
46 }
47 }
48}
49
50impl core::ops::Mul for Complex {
51 type Output = Self;
52 fn mul(self, rhs: Self) -> Self {
53 Self {
54 re: self.re * rhs.re - self.im * rhs.im,
55 im: self.re * rhs.im + self.im * rhs.re,
56 }
57 }
58}
59
60impl core::ops::Mul<f32> for Complex {
61 type Output = Self;
62 fn mul(self, rhs: f32) -> Self {
63 Self {
64 re: self.re * rhs,
65 im: self.im * rhs,
66 }
67 }
68}
69
70#[derive(Debug, Clone)]
72pub struct Block {
73 pub data: Vec<Sample>,
75 pub sample_rate: u32,
77 pub channels: u16,
79}
80
81impl Block {
82 pub fn frames(&self) -> usize {
84 if self.channels == 0 {
85 return 0;
86 }
87 self.data.len() / self.channels as usize
88 }
89}
90
91#[derive(Debug, Clone)]
93pub struct DspConfig {
94 pub block_size: usize,
96 pub sample_rate: u32,
98 pub channels: u16,
100}
101
102#[derive(Debug, Clone, Default)]
104pub struct DspStats {
105 pub blocks_processed: u64,
107 pub avg_latency_us: u64,
109 pub max_latency_us: u64,
111 pub jitter_us: u64,
113 pub overruns: u64,
115}