1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#![allow(unused_imports)]
#![warn(missing_docs)]
#![no_std]
extern crate alloc;
#[cfg(not(feature = "no_std"))]
extern crate std;
mod adapt;
mod constant;
mod cycle;
mod downmix;
mod filter;
mod frame;
mod frames;
mod gain;
mod math;
mod mixer;
mod reinhard;
mod ring;
mod set;
mod signal;
mod sine;
mod smooth;
mod spatial;
mod speed;
mod spsc;
mod stop;
mod stream;
mod swap;
mod tanh;
pub use adapt::{Adapt, AdaptOptions};
pub use constant::Constant;
pub use cycle::Cycle;
pub use downmix::Downmix;
pub use filter::*;
pub use frame::Frame;
pub use frames::*;
pub use gain::{Gain, GainControl};
pub use mixer::*;
pub use reinhard::Reinhard;
use set::*;
pub use signal::*;
pub use sine::*;
pub use smooth::{Interpolate, Smoothed};
pub use spatial::*;
pub use speed::{Speed, SpeedControl};
pub use stop::*;
pub use stream::{Stream, StreamControl};
pub use swap::Swap;
pub use tanh::Tanh;
pub type Sample = f32;
pub fn run<S: Signal + ?Sized>(signal: &S, sample_rate: u32, out: &mut [S::Frame]) {
let interval = 1.0 / sample_rate as f32;
signal.sample(interval, out);
}
pub fn split<S: Signal>(signal: S) -> (Handle<S>, SplitSignal<S>) {
let signal = alloc::sync::Arc::new(signal);
let handle = unsafe { Handle::from_arc(signal.clone()) };
(handle, SplitSignal(signal))
}
pub struct SplitSignal<S: ?Sized>(alloc::sync::Arc<S>);
impl<S> Signal for SplitSignal<S>
where
S: Signal + ?Sized,
{
type Frame = S::Frame;
fn sample(&self, interval: f32, out: &mut [Self::Frame]) {
self.0.sample(interval, out);
}
fn remaining(&self) -> f32 {
self.0.remaining()
}
}
unsafe impl<S: ?Sized> Send for SplitSignal<S> {}
pub fn frame_stereo(xs: &mut [Sample]) -> &mut [[Sample; 2]] {
unsafe { core::slice::from_raw_parts_mut(xs.as_mut_ptr() as _, xs.len() / 2) }
}
fn flatten_stereo(xs: &mut [[Sample; 2]]) -> &mut [Sample] {
unsafe { core::slice::from_raw_parts_mut(xs.as_mut_ptr() as _, xs.len() * 2) }
}