From 9d7de9a943eb1a03572f9fa988eeb2ac8af748d2 Mon Sep 17 00:00:00 2001 From: Aqua Date: Fri, 13 Nov 2026 14:30:38 +0000 Subject: [PATCH 01/12] voice-source-1: predictions written before any clip is rendered Co-Authored-By: Claude Sonnet 5.5 --- .../aqua-listen/kits/voice-source/predictions.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 tools/aqua-listen/kits/voice-source/predictions.md diff --git a/tools/aqua-listen/kits/voice-source/predictions.md b/tools/aqua-listen/kits/voice-source/predictions.md new file mode 100644 index 0000000..d89e48d --- /dev/null +++ b/tools/aqua-listen/kits/voice-source/predictions.md @@ -0,0 +1,16 @@ +# voice-source-1: predictions, written before any clip was rendered + +Phrase: /ɑmi/ (WordRender, 140 Hz, 48 kHz). Meta's verdict on tract-weak-spots-1 heard "a kazoo with a two pack a day smoking habit", "reedy ... pink trombone", "a basketball buzzer" for /m/ and /n/; the voice source (a band-limited saw through a one-pole lowpass, plus 0.08 x noise x white) is the shared suspect. Each pair below changes ONE source parameter, everything else is the scaffold's. + +Source-side numbers (computed from the two source formulas alone, harmonics of 140 Hz after the same tilt lowpass at 1131 Hz; the tract is not in them): Rosenberg minus saw, per harmonic: H1 +1.2 dB, H2 +0.3, H3 -6.3, H5 -10.5, H8 -17.2, H10 -17.8, H15 -22.0, H20 -24.5, H28 -27.4. Source rms differs +0.4 dB. + +| pair | A | B | what changes | prediction | falsified if | +|---|---|---|---|---|---| +| pulse | saw | rosenberg | `pulse=` | B is darker and rounder: less buzz, less edge, F2 of /i/ weaker (the harmonics near 2 kHz are ~22 dB lower). Loudness the same (rms within 0.5 dB). | no difference heard; or B heard as buzzier/brighter; or B heard as the same "kazoo" quality. | +| noise level | saw, noise at scaffold (.04) | saw, white noise raised to HNR 20 dB | `noise=` | B has audible breath/hiss under the voice; a listener who called A a "kazoo" or "buzzer" hears B as less pure-tone, but still a machine. | B is not noisier; or the noise is heard as a separate hiss stream not fused with the voice; or A and B are both still a kazoo to the same degree (then purity of the periodicity is not what makes it a kazoo). | +| noise colour | white noise, HNR 20 dB | noise high-passed at 2 kHz, HNR 20 dB | `noise_hp=` (noise level re-set to keep HNR 20) | B reads as hiss/"s"-like air, more separable from the voice than A; A reads as roughness/breathy voice. | no difference; or B heard as less hissy than A. | +| aspiration level | high-passed noise, HNR 25 dB | high-passed noise, HNR 15 dB | `noise=` | B is clearly hissy; A is at most faintly airy and may be called "no difference" from a clean voice. | A is already clearly hissy, or B is not hissier than A. | + +Measured HNR (hnr.py, Boersma autocorrelation, median over voiced frames) is reported next to each clip after rendering; a target missed by more than 2 dB is stated as missed, and the noise value is not retuned to the answer. + +What this kit cannot say: LF (the Liljencrants-Fant model) is not tested; the pulse is Rosenberg C with fixed open phase 0.4 and return 0.16. One listener, one phrase, one f0, one device. -- 2.47.3 From 8b9169e8c26e3295aff1628e81b95ba3065aa7a3 Mon Sep 17 00:00:00 2001 From: Aqua Date: Fri, 13 Nov 2026 14:44:15 +0000 Subject: [PATCH 02/12] voice-source-1: HNR tool, ami phrase, source fields pulse and noise_hp, WordRender --source; calibration noted before the kit renders Co-Authored-By: Claude Sonnet 5.5 --- src/AquaSynth.Core/FaustExport.cs | 11 ++++- src/AquaSynth.Core/Model.cs | 12 ++++- src/AquaSynth.Core/PatchScript.cs | 11 ++++- .../GlottalSourceSpectrumTests.cs | 46 +++++++++++++++++-- tools/WordRender/Program.cs | 28 +++++++++-- tools/aqua-listen/kits/voice-source/hnr.py | 44 ++++++++++++++++++ .../kits/voice-source/phones/ami.json | 1 + .../kits/voice-source/predictions.md | 8 ++++ 8 files changed, 149 insertions(+), 12 deletions(-) create mode 100644 tools/aqua-listen/kits/voice-source/hnr.py create mode 100644 tools/aqua-listen/kits/voice-source/phones/ami.json diff --git a/src/AquaSynth.Core/FaustExport.cs b/src/AquaSynth.Core/FaustExport.cs index 51ae72a..10e92b0 100644 --- a/src/AquaSynth.Core/FaustExport.cs +++ b/src/AquaSynth.Core/FaustExport.cs @@ -758,14 +758,21 @@ public static partial class FaustEmitter // Harmonic glottal source: a band-limited saw through a one-pole lowpass. Tilt 0 is the brightest source and 1 the // steepest rolloff; the cutoff sweeps five octaves, 6400 Hz down to 200 Hz, and sits below Nyquist. var cutoff = $"min(0.45 * ma.SR, 200.0 * pow(2.0, (1.0 - clip01({parameters.Expression(OwnerField(owner, "tilt"), port.Tilt)})) * 5.0))"; - source.AppendLine($" {voiced} = (os.sawtooth(({frequency}) * {pitchRatio}) : fi.lowpass(1, {cutoff})) * clip01({opening}) * clip01(0.25 + {tension});"); - source.AppendLine($" {flow} = {ProbeSignal(options, $"/debug/{voiceName}/source/{port.Name}/flow", $"({flowScale}) * (({voiced}) * ma.tanh((({pressure}) * (0.5 + {tension})) / max(0.05, {impedance})) + 0.08 * no.noise * {parameters.Expression(OwnerField(owner, "noise"), port.Noise)})", -2, 2)};"); + var wave = port.Pulse == GlottalPulse.Rosenberg ? RosenbergPulse($"(({frequency}) * {pitchRatio})") : $"os.sawtooth(({frequency}) * {pitchRatio})"; + source.AppendLine($" {voiced} = ({wave} : fi.lowpass(1, {cutoff})) * clip01({opening}) * clip01(0.25 + {tension});"); + source.AppendLine($" {flow} = {ProbeSignal(options, $"/debug/{voiceName}/source/{port.Name}/flow", $"({flowScale}) * (({voiced}) * ma.tanh((({pressure}) * (0.5 + {tension})) / max(0.05, {impedance})) + 0.08 * {(port.NoiseHighPassHz > 0 ? $"(no.noise : fi.highpass(2, {port.NoiseHighPassHz.ToString("0.###", CultureInfo.InvariantCulture)}))" : "no.noise")} * {parameters.Expression(OwnerField(owner, "noise"), port.Noise)})", -2, 2)};"); keepAlive.Add(load); keepAlive.Add(voiced); keepAlive.Add(flow); return flow; } + // Rosenberg C flow pulse of one period (phase p of 0..1): opening 0.5 (1 - cos(pi p / 0.4)) for p < 0.4, return cos(pi/2 (p - 0.4) / 0.16) + // for the next 0.16, closed after. Its mean is 0.4 / 2 + 0.16 * 2 / pi = 0.301859 and its rms about that mean is 0.372667; it is made zero-mean + // and scaled by 0.57735 / 0.372667 = 1.549 to the rms of os.sawtooth (1 / sqrt 3), so a swap of the pulse leaves the level where it was. + private static string RosenbergPulse(string frequency) => + $"(((os.lf_sawpos({frequency}) : (\\(p).(select2(p < 0.4, select2(p < 0.56, 0.0, cos(ma.PI * 0.5 * (p - 0.4) / 0.16)), 0.5 * (1.0 - cos(ma.PI * p / 0.4)))))) - 0.301859) * 1.549)"; + private static (string Released, string Burst) PrimitiveContactExpression( StringBuilder source, SynthPatch patch, diff --git a/src/AquaSynth.Core/Model.cs b/src/AquaSynth.Core/Model.cs index 175bdfa..867b112 100644 --- a/src/AquaSynth.Core/Model.cs +++ b/src/AquaSynth.Core/Model.cs @@ -474,7 +474,17 @@ public sealed record SourcePort( float Impedance = 0.35f, float FlowScale = 0.02f, float Tilt = 0.5f, - float PitchRatio = 1f); + float PitchRatio = 1f, + GlottalPulse Pulse = GlottalPulse.Saw, + float NoiseHighPassHz = 0f); + +// The glottal flow waveform of a primitive source port. Saw is the band-limited saw the tilt lowpass shapes; Rosenberg is the +// Rosenberg C pulse (open phase 0.4 of the period, return phase 0.16), zero-mean and scaled to the saw's rms so the two differ in shape, not level. +public enum GlottalPulse +{ + Saw, + Rosenberg +} public sealed record ConstrictionContact( string Name, diff --git a/src/AquaSynth.Core/PatchScript.cs b/src/AquaSynth.Core/PatchScript.cs index 7b5a89e..2fd43ec 100644 --- a/src/AquaSynth.Core/PatchScript.cs +++ b/src/AquaSynth.Core/PatchScript.cs @@ -968,7 +968,9 @@ public static class PatchScript GetBoundFloat(fields, line, 0.35f, $"/vocal/sources/{_sourcePorts.Count}/impedance", "impedance", "load", "source_impedance"), GetBoundFloat(fields, line, 0.02f, $"/vocal/sources/{_sourcePorts.Count}/flow_scale", "flow_scale", "scale"), GetBoundFloat(fields, line, 0.5f, $"/vocal/sources/{_sourcePorts.Count}/tilt", "tilt", "spectral_tilt"), - GetBoundFloat(fields, line, 1f, $"/vocal/sources/{_sourcePorts.Count}/pitch_ratio", "pitch_ratio", "f0_ratio")); + GetBoundFloat(fields, line, 1f, $"/vocal/sources/{_sourcePorts.Count}/pitch_ratio", "pitch_ratio", "f0_ratio"), + ParseGlottalPulse(GetAny(fields, ["pulse", "glottal_pulse"], "saw"), line), + Math.Clamp(GetFloat(fields, line, 0f, "noise_highpass", "noise_hp"), 0f, 8000f)); _sourcePorts.Add(port); _sourcePortsByName[name] = port; RegisterSourcePortSurfaces(_sourcePorts.Count - 1, port); @@ -4443,6 +4445,13 @@ public static class PatchScript _ => throw new PatchScriptException(line, $"unknown tract propagation mode `{value}`") }; + private static GlottalPulse ParseGlottalPulse(string value, int line) => value.ToLowerInvariant() switch + { + "saw" or "sawtooth" => GlottalPulse.Saw, + "rosenberg" => GlottalPulse.Rosenberg, + _ => throw new PatchScriptException(line, $"unknown glottal pulse `{value}` (saw, rosenberg)") + }; + private static AcousticSourceKind ParseAcousticSourceKind(string value, int line) => value.ToLowerInvariant() switch { "glottal" or "glottis" or "larynx" => AcousticSourceKind.Glottal, diff --git a/tests/AquaSynth.Dsl.Tests/GlottalSourceSpectrumTests.cs b/tests/AquaSynth.Dsl.Tests/GlottalSourceSpectrumTests.cs index 5d43dea..0051d78 100644 --- a/tests/AquaSynth.Dsl.Tests/GlottalSourceSpectrumTests.cs +++ b/tests/AquaSynth.Dsl.Tests/GlottalSourceSpectrumTests.cs @@ -12,19 +12,19 @@ public sealed class GlottalSourceSpectrumTests(ITestOutputHelper output) private const int Rate = 48000; private const float Pitch = 137f; - private static string Script(float tilt, float pitch) => $$""" + private static string Script(float tilt, float pitch, string extra = "") => $$""" morphology name=oral length_cm=17 diameters=.6,.8,1.2,1.5,.9 waveguide_path name=oral_path morphology=oral loss=.998 - source_port name=folds path=oral_path pressure=.7 tension=.55 opening=.45 noise=0 impedance=.3 tilt={{tilt}} + source_port name=folds path=oral_path pressure=.7 tension=.55 opening=.45 noise=0 impedance=.3 tilt={{tilt}} {{extra}} radiation_load name=mouth path=oral_path aperture=.8 reflection=-.82 impedance=.28 vocal_network name=voice paths=oral_path sources=folds radiation=mouth vocal network=voice freq={{pitch}} gain=.2 sustain=1.5 """; // One second of steady output, so every harmonic of Pitch and every other integer-Hz frequency sits on its own DFT bin. - private float[]? Render(float tilt, float pitch = Pitch, int skip = 4800) + private float[]? Render(float tilt, float pitch = Pitch, int skip = 4800, string extra = "") { - var source = FaustEmitter.Emit(PatchScript.Parse(Script(tilt, pitch)), new FaustExportOptions("glottal_spectrum")).Source; + var source = FaustEmitter.Emit(PatchScript.Parse(Script(tilt, pitch, extra)), new FaustExportOptions("glottal_spectrum")).Source; using var compiler = new AquaSynthPatchCompiler(new AquaSynthNativeOptions(SampleRate: Rate)); if (!compiler.TryCompileSource(new AquaSynthCompileIdentity("glottal_spectrum", "glottal_spectrum", ""), source, 1.4f, out var patch, out var error)) { @@ -122,4 +122,42 @@ public sealed class GlottalSourceSpectrumTests(ITestOutputHelper output) var defaulted = PatchScript.Parse(Script(.8f, Pitch).Replace("tilt=0.8", "", StringComparison.Ordinal)); Assert.Equal(.5f, Assert.Single(defaulted.SourcePorts).Tilt, 5); } + + [Fact] + public void PulseAndNoiseHighPassAreAuthoredSourceFieldsDefaultingToSawAndWhite() + { + var port = Assert.Single(PatchScript.Parse(Script(.5f, Pitch, "pulse=rosenberg noise_hp=2000")).SourcePorts); + Assert.Equal(GlottalPulse.Rosenberg, port.Pulse); + Assert.Equal(2000f, port.NoiseHighPassHz); + var defaulted = Assert.Single(PatchScript.Parse(Script(.5f, Pitch)).SourcePorts); + Assert.Equal(GlottalPulse.Saw, defaulted.Pulse); + Assert.Equal(0f, defaulted.NoiseHighPassHz); + Assert.Throws(() => PatchScript.Parse(Script(.5f, Pitch, "pulse=triangle"))); + } + + [Fact] + public void OnlyTheRosenbergPulseEmitsThePhasorAndOnlyAHighPassedSourceEmitsTheNoiseFilter() + { + string Emit(string extra) => FaustEmitter.Emit(PatchScript.Parse(Script(.5f, Pitch, extra)), new FaustExportOptions("pulse_emit")).Source; + Assert.DoesNotContain("lf_sawpos", Emit(""), StringComparison.Ordinal); + Assert.Contains("lf_sawpos", Emit("pulse=rosenberg"), StringComparison.Ordinal); + Assert.DoesNotContain("fi.highpass(2, 2000", Emit(""), StringComparison.Ordinal); + Assert.Contains("fi.highpass(2, 2000", Emit("noise_hp=2000"), StringComparison.Ordinal); + } + + [Fact] + public void RosenbergPulseIsPeriodicAtThePitchAndRendersWithinTwoDbOfTheSawsLevel() + { + var saw = Render(.5f); + var pulse = Render(.5f, extra: "pulse=rosenberg"); + if (saw is null || pulse is null) return; + + double Rms(float[] w) => Math.Sqrt(w.Sum(v => (double)v * v) / w.Length); + var difference = Db(Rms(pulse) / Rms(saw)); + output.WriteLine($"rosenberg rms {Rms(pulse):E3} saw rms {Rms(saw):E3} ({difference:F2} dB)"); + Assert.InRange(difference, -2, 2); + var fundamental = Magnitude(pulse, Pitch); + var between = Magnitude(pulse, Pitch * 1.5); + Assert.True(Db(between / fundamental) < -30, $"energy between harmonics {Db(between / fundamental):F1} dB re the fundamental"); + } } diff --git a/tools/WordRender/Program.cs b/tools/WordRender/Program.cs index 32e01c8..2f09ef5 100644 --- a/tools/WordRender/Program.cs +++ b/tools/WordRender/Program.cs @@ -8,12 +8,17 @@ using AquaSynth.Faust; // Offline probe: one word, segmented by Weksa (the phones line of `weksa lower --phones`), as a run of IPA gestures on the // IpaGestureExperiment scaffold, rendered through the native libfaust path to a mono 16-bit WAV plus script.aqua, source.dsp // and manifest.json. It measures peak, rms and NaN; it cannot say how the word sounds. -// usage: WordRender