Add vibrato support + fix feedback loop + GUI improvements

Vibrato (LFO frequency modulation):
- New VibratoSpec in SoundSpec: rate (Hz), depth (cents), delay (s)
- ChannelRenderer applies vibrato to frequency each tick
- Supported on Pulse and Triangle channels
- GUI: vibrato controls (enable, rate, depth) in channel panel
- Enables bird chirps, sirens, wobbles

Feedback loop fixes:
- generate_batch now accepts full SoundSpec array (not just names)
  so each sound is unique
- render_sound returns reference examples from feedback DB
- Fixed GUI bug: clicking stars no longer erases feedback text
- Feedback text auto-saves on Enter / focus loss
- Replaced emoji buttons (✓/🗑) with text (Save/Del)
- Green saved indicator when feedback exists in DB

99 tests passing, 0 warnings
This commit is contained in:
Emil
2026-06-21 23:54:25 +03:00
parent 3e2376ac26
commit 58c47fe286
12 changed files with 243 additions and 68 deletions
+25
View File
@@ -37,6 +37,23 @@ pub struct EnvelopeSpec {
pub release: f32,
}
/// Vibrato/tremolo spec — LFO for frequency modulation (bird chirps, sirens, etc.).
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct VibratoSpec {
/// LFO frequency in Hz (e.g., 5-20 for bird chirps).
pub rate: f32,
/// Depth in cents (e.g., 200-800 for bird chirps, 50 for subtle vibrato).
#[serde(default = "default_vibrato_depth")]
pub depth: f32,
/// Delay before vibrato starts (seconds). Default 0.
#[serde(default)]
pub delay: f32,
}
fn default_vibrato_depth() -> f32 {
100.0
}
/// Filter spec with optional cutoff automation.
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct FilterSpec {
@@ -81,6 +98,9 @@ pub enum ChannelSpec {
envelope: Option<EnvelopeSpec>,
#[serde(default)]
filter: Option<FilterSpec>,
/// Optional vibrato/frequency modulation (for bird chirps, sirens, etc.).
#[serde(default)]
vibrato: Option<VibratoSpec>,
#[serde(default = "default_volume")]
volume: f32,
#[serde(default)]
@@ -93,6 +113,8 @@ pub enum ChannelSpec {
envelope: Option<EnvelopeSpec>,
#[serde(default)]
filter: Option<FilterSpec>,
#[serde(default)]
vibrato: Option<VibratoSpec>,
#[serde(default = "default_volume")]
volume: f32,
#[serde(default)]
@@ -109,6 +131,8 @@ pub enum ChannelSpec {
envelope: Option<EnvelopeSpec>,
#[serde(default)]
filter: Option<FilterSpec>,
#[serde(default)]
vibrato: Option<VibratoSpec>,
#[serde(default = "default_volume")]
volume: f32,
#[serde(default)]
@@ -267,6 +291,7 @@ mod tests {
release: 0.2,
}),
filter: None,
vibrato: None,
volume: 0.8,
pan: -0.5,
}],
+1
View File
@@ -172,6 +172,7 @@ mod tests {
frequency: FrequencyAutomation::fixed(440.0),
envelope: None,
filter: None,
vibrato: None,
volume: 0.5,
pan: 0.0,
}],
+35 -6
View File
@@ -1,10 +1,11 @@
//! Render a [`SoundSpec`] to interleaved stereo `Vec<f32>`.
use soundgen_core::{
ChannelRenderer, Envelope, Filter, FilterType, FrequencyAutomation, NoiseMode, Sweep, VoiceKind,
ChannelRenderer, Envelope, Filter, FilterType, FrequencyAutomation, NoiseMode, Sweep, Vibrato,
VoiceKind,
};
use VoiceKind as VK;
use crate::{ChannelSpec, EnvelopeSpec, FilterSpec, SoundSpec};
use crate::{ChannelSpec, EnvelopeSpec, FilterSpec, SoundSpec, VibratoSpec};
/// Render a [`SoundSpec`] to interleaved stereo samples (L, R, L, R, ...).
pub fn render_spec(spec: &SoundSpec) -> Vec<f32> {
@@ -30,25 +31,43 @@ fn build_channel(spec: &ChannelSpec, sr: f32, duration: f32) -> ChannelRenderer
frequency,
envelope,
filter,
vibrato,
volume,
pan,
} => {
let duty_cycle = soundgen_core::voice::DutyCycle::from_percent(*duty);
let voice = VK::Pulse(soundgen_core::voice::PulseChannel::new(sr, duty_cycle));
build_renderer(
voice, sr, duration, frequency, envelope, filter, *volume, *pan,
voice,
sr,
duration,
frequency,
envelope,
filter,
vibrato.as_ref(),
*volume,
*pan,
)
}
ChannelSpec::Triangle {
frequency,
envelope,
filter,
vibrato,
volume,
pan,
} => {
let voice = VK::Triangle(soundgen_core::voice::TriangleChannel::new(sr));
build_renderer(
voice, sr, duration, frequency, envelope, filter, *volume, *pan,
voice,
sr,
duration,
frequency,
envelope,
filter,
vibrato.as_ref(),
*volume,
*pan,
)
}
ChannelSpec::Noise {
@@ -56,6 +75,7 @@ fn build_channel(spec: &ChannelSpec, sr: f32, duration: f32) -> ChannelRenderer
frequency,
envelope,
filter,
vibrato: _,
volume,
pan,
} => {
@@ -65,10 +85,9 @@ fn build_channel(spec: &ChannelSpec, sr: f32, duration: f32) -> ChannelRenderer
};
let noise = soundgen_core::voice::NoiseChannel::new(sr, noise_mode);
let voice = VK::Noise(noise);
// Noise "frequency" is a static clock rate — wrap as fixed automation.
let freq_auto = FrequencyAutomation::fixed(*frequency);
build_renderer(
voice, sr, duration, &freq_auto, envelope, filter, *volume, *pan,
voice, sr, duration, &freq_auto, envelope, filter, None, *volume, *pan,
)
}
}
@@ -82,6 +101,7 @@ fn build_renderer(
frequency: &FrequencyAutomation,
envelope: &Option<EnvelopeSpec>,
filter: &Option<FilterSpec>,
vibrato: Option<&VibratoSpec>,
volume: f32,
pan: f32,
) -> ChannelRenderer {
@@ -95,6 +115,11 @@ fn build_renderer(
cr = cr.with_freq_sweep(frequency.to_sweep(sr, duration));
}
// Vibrato
if let Some(vib) = vibrato {
cr = cr.with_vibrato(Vibrato::new(sr, vib.rate, vib.depth));
}
// Envelope
if let Some(env) = envelope {
cr = cr.with_envelope(Envelope::adsr(
@@ -150,6 +175,7 @@ mod tests {
release: 0.0,
}),
filter: None,
vibrato: None,
volume: 0.5,
pan: 0.0,
}],
@@ -178,6 +204,7 @@ mod tests {
release: 0.0,
}),
filter: None,
vibrato: None,
volume: 0.5,
pan: 0.0,
}],
@@ -223,6 +250,7 @@ mod tests {
release: 0.0,
}),
filter: None,
vibrato: None,
volume: 0.5,
pan: 0.0,
}],
@@ -255,6 +283,7 @@ mod tests {
cutoff_sweep: None,
q: 0.707,
}),
vibrato: None,
volume: 0.5,
pan: 0.0,
}],
+6
View File
@@ -41,6 +41,7 @@ fn test_render_spec_to_wav_and_verify() {
release: 0.1,
}),
filter: None,
vibrato: None,
volume: 0.6,
pan: 0.0,
}],
@@ -141,6 +142,7 @@ fn test_json_spec_roundtrip() {
}),
q: 0.707,
}),
vibrato: None,
volume: 0.7,
pan: 0.0,
}],
@@ -170,6 +172,7 @@ fn test_wav_file_format_correct() {
release: 0.0,
}),
filter: None,
vibrato: None,
volume: 0.5,
pan: 0.0,
}],
@@ -204,6 +207,7 @@ fn test_multi_channel_render() {
frequency: FrequencyAutomation::fixed(440.0),
envelope: Some(EnvelopeSpec::default()),
filter: None,
vibrato: None,
volume: 0.5,
pan: -0.5,
},
@@ -211,6 +215,7 @@ fn test_multi_channel_render() {
frequency: FrequencyAutomation::fixed(220.0),
envelope: Some(EnvelopeSpec::default()),
filter: None,
vibrato: None,
volume: 0.4,
pan: 0.5,
},
@@ -219,6 +224,7 @@ fn test_multi_channel_render() {
frequency: 5000.0,
envelope: Some(EnvelopeSpec::default()),
filter: None,
vibrato: None,
volume: 0.3,
pan: 0.0,
},