audio-processor-standalone-0.1.0 has been yanked.
audio-processor-standalone

Provides a stand-alone audio-processor runner for AudioProcessor
implementations.
use std::time::Duration;
use audio_processor_traits::{AudioBuffer, AudioProcessor};
use circular_data_structures::CircularVec;
struct SimpleDelayProcessor {
current_write_position: usize,
current_read_position: usize,
delay_buffers: Vec<CircularVec<f32>>,
}
impl SimpleDelayProcessor {
fn new() -> Self {
Self {
current_write_position: (Duration::from_millis(800).as_secs_f32() * 44100.0) as usize,
current_read_position: 0,
delay_buffers: vec![
CircularVec::with_size(
(Duration::from_secs(5).as_secs_f32() * 44100.0) as usize,
0.0,
),
CircularVec::with_size(
(Duration::from_secs(5).as_secs_f32() * 44100.0) as usize,
0.0,
),
],
}
}
}
impl AudioProcessor for SimpleDelayProcessor {
type SampleType = f32;
fn process<BufferType: AudioBuffer<SampleType = Self::SampleType>>(
&mut self,
data: &mut BufferType,
) {
for sample_index in 0..data.num_samples() {
data.set(0, sample_index, *data.get(1, sample_index));
}
for sample_index in 0..data.num_samples() {
for channel_index in 0..data.num_channels() {
let input = *data.get(channel_index, sample_index);
let delay_output = self.delay_buffers[channel_index][self.current_read_position];
let feedback = 0.3;
self.delay_buffers[channel_index][self.current_write_position] =
input + delay_output * feedback;
data.set(channel_index, sample_index, input + delay_output);
}
self.current_read_position += 1;
self.current_write_position += 1;
}
}
}
fn main() {
let processor = SimpleDelayProcessor::new();
audio_processor_standalone::audio_processor_main(processor);
}