Add different wave and filter types
This commit is contained in:
41
crates/synth-core/src/audio_out.rs
Normal file
41
crates/synth-core/src/audio_out.rs
Normal file
@@ -0,0 +1,41 @@
|
||||
//! Audio output sink — final stage in the signal chain.
|
||||
//!
|
||||
//! In the patch bay this is the node you connect the last module to; it
|
||||
//! represents the physical speakers / DAC.
|
||||
|
||||
use crate::{AudioProcessor, config::SampleRate};
|
||||
use crate::descriptor::{ComponentDescriptor, Direction, JackDescriptor, ParamDescriptor, SignalKind};
|
||||
|
||||
pub struct AudioOut {
|
||||
pub level: f32,
|
||||
sample_rate: SampleRate,
|
||||
}
|
||||
|
||||
impl AudioOut {
|
||||
pub fn new(sample_rate: SampleRate) -> Self {
|
||||
Self { level: 0.8, sample_rate }
|
||||
}
|
||||
|
||||
pub const DESCRIPTOR: ComponentDescriptor = ComponentDescriptor {
|
||||
kind: "out",
|
||||
label: "Output",
|
||||
jacks: &[
|
||||
JackDescriptor { id: "audio_in", label: "In", direction: Direction::Input, signal: SignalKind::Audio },
|
||||
],
|
||||
params: &[
|
||||
ParamDescriptor { id: "level", label: "Level", min: 0.0, max: 1.0, default: 0.8, unit: "", labels: &[] },
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
impl<const B: usize> AudioProcessor<B> for AudioOut {
|
||||
fn process(&mut self, out: &mut [f32; B]) {
|
||||
for s in out.iter_mut() {
|
||||
*s *= self.level;
|
||||
}
|
||||
}
|
||||
|
||||
fn reset(&mut self) {
|
||||
let _ = self.sample_rate; // kept for API symmetry
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,10 @@ pub struct ParamDescriptor {
|
||||
pub default: f32,
|
||||
/// Display unit string (e.g. `"Hz"`, `"s"`, `""`).
|
||||
pub unit: &'static str,
|
||||
/// When non-empty, this param is a discrete enum selector.
|
||||
/// Each entry is the display label for that step (step 0 = index 0, etc.).
|
||||
/// `min` should be 0.0 and `max` should be `(labels.len() - 1) as f32`.
|
||||
pub labels: &'static [&'static str],
|
||||
}
|
||||
|
||||
/// Full compile-time descriptor for a DSP component type.
|
||||
|
||||
@@ -34,10 +34,10 @@ impl Adsr {
|
||||
JackDescriptor { id: "env_out", label: "Env", direction: Direction::Output, signal: SignalKind::Cv },
|
||||
],
|
||||
params: &[
|
||||
ParamDescriptor { id: "attack_s", label: "Attack", min: 0.001, max: 4.0, default: 0.01, unit: "s" },
|
||||
ParamDescriptor { id: "decay_s", label: "Decay", min: 0.001, max: 4.0, default: 0.1, unit: "s" },
|
||||
ParamDescriptor { id: "sustain", label: "Sustain", min: 0.0, max: 1.0, default: 0.7, unit: "" },
|
||||
ParamDescriptor { id: "release_s", label: "Release", min: 0.001, max: 8.0, default: 0.3, unit: "s" },
|
||||
ParamDescriptor { id: "attack_s", label: "Attack", min: 0.001, max: 4.0, default: 0.01, unit: "s", labels: &[] },
|
||||
ParamDescriptor { id: "decay_s", label: "Decay", min: 0.001, max: 4.0, default: 0.1, unit: "s", labels: &[] },
|
||||
ParamDescriptor { id: "sustain", label: "Sustain", min: 0.0, max: 1.0, default: 0.7, unit: "", labels: &[] },
|
||||
ParamDescriptor { id: "release_s", label: "Release", min: 0.001, max: 8.0, default: 0.3, unit: "s", labels: &[] },
|
||||
],
|
||||
};
|
||||
|
||||
|
||||
@@ -40,9 +40,8 @@ impl Svf {
|
||||
JackDescriptor { id: "audio_out", label: "Out", direction: Direction::Output, signal: SignalKind::Audio },
|
||||
],
|
||||
params: &[
|
||||
ParamDescriptor { id: "cutoff_hz", label: "Cutoff", min: 20.0, max: 20_000.0, default: 2_000.0, unit: "Hz" },
|
||||
ParamDescriptor { id: "resonance", label: "Res", min: 0.0, max: 1.0, default: 0.5, unit: "" },
|
||||
ParamDescriptor { id: "mode", label: "Mode", min: 0.0, max: 3.0, default: 0.0, unit: "" },
|
||||
ParamDescriptor { id: "cutoff_hz", label: "Cutoff", min: 20.0, max: 20_000.0, default: 2_000.0, unit: "Hz", labels: &[] },
|
||||
ParamDescriptor { id: "resonance", label: "Res", min: 0.0, max: 1.0, default: 0.5, unit: "", labels: &[] },
|
||||
],
|
||||
};
|
||||
|
||||
|
||||
@@ -27,9 +27,9 @@ impl Lfo {
|
||||
JackDescriptor { id: "cv_out", label: "Out", direction: Direction::Output, signal: SignalKind::Cv },
|
||||
],
|
||||
params: &[
|
||||
ParamDescriptor { id: "rate_hz", label: "Rate", min: 0.01, max: 20.0, default: 2.0, unit: "Hz" },
|
||||
ParamDescriptor { id: "depth", label: "Depth", min: 0.0, max: 1.0, default: 0.5, unit: "" },
|
||||
ParamDescriptor { id: "waveform", label: "Wave", min: 0.0, max: 4.0, default: 0.0, unit: "" },
|
||||
ParamDescriptor { id: "rate_hz", label: "Rate", min: 0.01, max: 20.0, default: 2.0, unit: "Hz", labels: &[] },
|
||||
ParamDescriptor { id: "depth", label: "Depth", min: 0.0, max: 1.0, default: 0.5, unit: "", labels: &[] },
|
||||
ParamDescriptor { id: "waveform", label: "Wave", min: 0.0, max: 4.0, default: 0.0, unit: "", labels: &["Sine", "Saw", "Sqr", "Tri", "Pls"] },
|
||||
],
|
||||
};
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ pub mod vca;
|
||||
pub mod lfo;
|
||||
pub mod midi;
|
||||
pub mod patch;
|
||||
pub mod audio_out;
|
||||
|
||||
pub use config::SampleRate;
|
||||
pub use math::{db_to_linear, linear_to_db, lerp, midi_note_to_hz};
|
||||
|
||||
@@ -35,8 +35,8 @@ impl Vco {
|
||||
JackDescriptor { id: "audio_out", label: "Out", direction: Direction::Output, signal: SignalKind::Audio },
|
||||
],
|
||||
params: &[
|
||||
ParamDescriptor { id: "freq_hz", label: "Freq", min: 20.0, max: 20_000.0, default: 440.0, unit: "Hz" },
|
||||
ParamDescriptor { id: "waveform", label: "Wave", min: 0.0, max: 4.0, default: 1.0, unit: "" },
|
||||
ParamDescriptor { id: "freq_hz", label: "Freq", min: 20.0, max: 20_000.0, default: 440.0, unit: "Hz", labels: &[] },
|
||||
ParamDescriptor { id: "waveform", label: "Wave", min: 0.0, max: 4.0, default: 1.0, unit: "", labels: &["Sine", "Saw", "Sqr", "Tri", "Pls"] },
|
||||
],
|
||||
};
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ impl Vca {
|
||||
JackDescriptor { id: "audio_out", label: "Out", direction: Direction::Output, signal: SignalKind::Audio },
|
||||
],
|
||||
params: &[
|
||||
ParamDescriptor { id: "gain", label: "Gain", min: 0.0, max: 1.0, default: 1.0, unit: "" },
|
||||
ParamDescriptor { id: "gain", label: "Gain", min: 0.0, max: 1.0, default: 1.0, unit: "", labels: &[] },
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user