Vowel gesture without vowel_set is a parse error; stress tests skip without Faust and read the live primary amplitude
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
eceaae29c2
commit
5dc7d1361f
3 changed files with 74 additions and 32 deletions
|
|
@ -1504,7 +1504,7 @@ public static class PatchScript
|
|||
}
|
||||
}
|
||||
|
||||
private void EmitPhonemeGestureSplines(string name, string descriptor, float start, float duration, float intensity, float pitchRatio = 1f)
|
||||
private void EmitPhonemeGestureSplines(string name, string descriptor, float start, float duration, float intensity, int line, float pitchRatio = 1f)
|
||||
{
|
||||
var tokens = DescriptorTokens(descriptor);
|
||||
var voiced = tokens.Contains("voiced") || tokens.Contains("vowel") || tokens.Contains("nasal") || tokens.Contains("approximant");
|
||||
|
|
@ -1527,7 +1527,7 @@ public static class PatchScript
|
|||
|
||||
if (tokens.Contains("vowel"))
|
||||
{
|
||||
EmitVowelGesture(name, descriptor, start, duration);
|
||||
EmitVowelGesture(name, descriptor, start, duration, line);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1587,9 +1587,14 @@ public static class PatchScript
|
|||
|
||||
// A vowel gesture raises the weight of the descriptor's Story vowel to 1 and holds every other vowel weight at 0 (the schwa and
|
||||
// any vowel descriptor without a Story shape hold all of them at 0: the geometric-mean shape). The constriction and the lip cap
|
||||
// stay open, the velum closed. On a morphology without vowel_set the vowel surfaces do not exist and nothing is held.
|
||||
private void EmitVowelGesture(string name, string descriptor, float start, float duration)
|
||||
// stay open, the velum closed. A vowel gesture on a morphology without vowel_set is a parse error: the vowel surfaces do not exist.
|
||||
private void EmitVowelGesture(string name, string descriptor, float start, float duration, int line)
|
||||
{
|
||||
if (_areaFunctions.Count == 0 || _areaFunctions[0].Vowels is null)
|
||||
{
|
||||
throw new PatchScriptException(line, $"vowel gesture `{name}` needs a vowel_set before it: without one the vowel surfaces do not exist and the gesture would shape nothing");
|
||||
}
|
||||
|
||||
var target = StoryVowelAreas.IdForDescriptor(descriptor);
|
||||
foreach (var vowel in StoryVowelAreas.All)
|
||||
{
|
||||
|
|
@ -2714,7 +2719,7 @@ public static class PatchScript
|
|||
: $"ipa_{SafeName(ipa)}_{_phonemeGestures.Count}";
|
||||
|
||||
_phonemeGestures.Add(new PhonemeGesture(name, ipa, descriptor, start, duration, intensity));
|
||||
EmitPhonemeGestureSplines(name, descriptor, start, duration, intensity, pitchRatio);
|
||||
EmitPhonemeGestureSplines(name, descriptor, start, duration, intensity, line, pitchRatio);
|
||||
}
|
||||
|
||||
private void AddControlCurve(IReadOnlyDictionary<string, string> fields, int line)
|
||||
|
|
|
|||
|
|
@ -577,6 +577,26 @@ public sealed class PatchScriptTests
|
|||
timeline.SetFuturePoint("/vocal/nope", timeSeconds: .02f, normalizedValue: .5f, nowSeconds: .0f));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VowelGestureWithoutVowelSetFailsLoudly()
|
||||
{
|
||||
const string tract = """
|
||||
morphology name=oral length_cm=17 diameters=.6,.8,1.2,1.6,1.3,.9 tongue_index=3 tongue_diameter=1.4 constriction_index=4 constriction_diameter=1 lip_opening=1.5
|
||||
waveguide_path name=oral_path morphology=oral loss=.998
|
||||
source_port name=folds path=oral_path pressure=.7 tension=.55 opening=.45 noise=.05 impedance=.3
|
||||
constriction_contact name=contact path=oral_path position=.92 opening=.5 resistance=.4 stored_pressure=.1
|
||||
radiation_load name=mouth path=oral_path aperture=.8 reflection=-.82 impedance=.28
|
||||
vocal_network name=voice paths=oral_path sources=folds contacts=contact radiation=mouth
|
||||
phoneme_gesture name=vowel ipa=a start=0 dur=.2 intensity=.7
|
||||
vocal network=voice freq=150 gain=.2 sustain=.3
|
||||
""";
|
||||
var error = Assert.Throws<PatchScriptException>(() => PatchScript.Parse(tract));
|
||||
Assert.StartsWith("line 7:", error.Message);
|
||||
Assert.Contains("vowel_set", error.Message);
|
||||
// With the vowel_set in front of it the same gesture parses.
|
||||
PatchScript.Parse(tract.Replace("waveguide_path name=oral_path", "vowel_set area_function=oral source=story2008\nwaveguide_path name=oral_path"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PhonemeGestureDslEmitsAnatomicalControlSplines()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,19 +11,13 @@ public sealed class StressAndReleaseRenderTests(ITestOutputHelper output)
|
|||
{
|
||||
private const int Rate = 48000;
|
||||
|
||||
private static float[]? Render(string script, float seconds, Func<SynthPatch, SynthPatch>? edit = null)
|
||||
private static float[] Render(string script, float seconds, Func<SynthPatch, SynthPatch>? edit = null)
|
||||
{
|
||||
var parsed = PatchScript.Parse(script);
|
||||
var source = FaustEmitter.Emit(edit is null ? parsed : edit(parsed), new FaustExportOptions("stress_release", SampleRate: Rate)).Source;
|
||||
using var compiler = new AquaSynthPatchCompiler(new AquaSynthNativeOptions(SampleRate: Rate));
|
||||
if (!compiler.TryCompileSource(new AquaSynthCompileIdentity("stress_release", "stress_release", ""), source, seconds, out var patch, out var error))
|
||||
{
|
||||
if (error?.Contains("Faust toolchain not found", StringComparison.OrdinalIgnoreCase) == true ||
|
||||
error?.Contains("Faust DLL not found", StringComparison.OrdinalIgnoreCase) == true)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Assert.Fail($"compile failed: {error}");
|
||||
}
|
||||
|
||||
|
|
@ -57,49 +51,48 @@ public sealed class StressAndReleaseRenderTests(ITestOutputHelper output)
|
|||
return (double)Rate / bestLag;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[FaustFact]
|
||||
public void SourcePitchRatioScalesTheRenderedF0()
|
||||
{
|
||||
var f0 = (float ratio) =>
|
||||
{
|
||||
var script = IpaGestureExperiment.BuildWordScript([(new IpaGestureExperimentTarget("w_0_a", "a", "", 0.5f, PitchRatio: ratio), 1f)], 110);
|
||||
var x = Render(script, 0.6f);
|
||||
return x is null ? double.NaN : F0(x, 0.2, 0.5);
|
||||
return F0(x, 0.2, 0.5);
|
||||
};
|
||||
var unity = f0(1f);
|
||||
var up = f0(1.5f);
|
||||
output.WriteLine($"f0 at ratio 1: {unity:F1}, ratio 1.5: {up:F1}");
|
||||
if (double.IsNaN(unity)) return;
|
||||
Assert.InRange(unity, 108, 112);
|
||||
Assert.InRange(up, 163, 167);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[FaustFact]
|
||||
public void IntensityIsAnAmplitudeFactorOnTheRenderedLevel()
|
||||
{
|
||||
double Level(float intensity)
|
||||
{
|
||||
var script = IpaGestureExperiment.BuildWordScript([(new IpaGestureExperimentTarget("w_0_a", "a", "", 0.5f), intensity)], 110);
|
||||
var x = Render(script, 0.6f);
|
||||
return x is null ? double.NaN : Rms(x, 0.3, 0.5);
|
||||
return Rms(x, 0.3, 0.5);
|
||||
}
|
||||
|
||||
var unity = Level(1f);
|
||||
var stressed = Level(1.26f);
|
||||
if (double.IsNaN(unity)) return;
|
||||
var amplitude = WeksaWordPlan.CueFor(WeksaStress.Primary).Amplitude;
|
||||
var stressed = Level(amplitude);
|
||||
var db = 20 * Math.Log10(stressed / unity);
|
||||
output.WriteLine($"level at intensity 1.26 against 1: {db:F2} dB (factor wanted {20 * Math.Log10(1.26):F2})");
|
||||
Assert.InRange(db, 1.7, 2.3);
|
||||
output.WriteLine($"level at the primary-stress amplitude against 1: {db:F2} dB (factor wanted {20 * Math.Log10(amplitude):F2})");
|
||||
var wanted = 20 * Math.Log10(amplitude);
|
||||
Assert.InRange(db, wanted - 0.3, wanted + 0.3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[FaustFact]
|
||||
public void PlosiveReleaseBurstIsAboveTheClosureAndBelowTheFollowingVowel()
|
||||
{
|
||||
var script = IpaGestureExperiment.BuildWordScript(
|
||||
[(new IpaGestureExperimentTarget("w_0_b", "b", "", 0.095f), 1f), (new IpaGestureExperimentTarget("w_1_a", "a", "", 0.18f), 1f)], 140);
|
||||
var withBurst = Render(script, 0.4f);
|
||||
var withoutBurst = Render(script, 0.4f, p => p with { ControlSplines = p.ControlSplines.Where(s => !s.SurfacePath.EndsWith("/release_flow", StringComparison.Ordinal)).ToArray() });
|
||||
if (withBurst is null || withoutBurst is null) return;
|
||||
// Everything but the burst's noise is deterministic and shared, so the difference of the two renders is the burst alone.
|
||||
var burst = withBurst.Zip(withoutBurst, (x, y) => x - y).ToArray();
|
||||
const double releaseFrom = 0.095 * 0.65, vowelFrom = 0.095;
|
||||
|
|
@ -118,7 +111,7 @@ public sealed class StressAndReleaseRenderTests(ITestOutputHelper output)
|
|||
// gain from the plosive's gesture on, so it never ended: every later contact state made noise too. In /bin/ the "burst" alone (the
|
||||
// difference of the renders with and without release_flow) peaked at 0.0302 in the final /n/ and the tail, above its 0.0226 at the
|
||||
// release itself, and in /nibu/ the leading /n/ and /i/ carried it backward (a spline holds its first value before its first point).
|
||||
[Fact]
|
||||
[FaustFact]
|
||||
public void PlosiveBurstExistsOnlyAroundItsOwnRelease()
|
||||
{
|
||||
IpaGestureExperimentTarget Phone(string label, string ipa, float seconds) => new($"w_{label}", ipa, "", seconds);
|
||||
|
|
@ -126,7 +119,6 @@ public sealed class StressAndReleaseRenderTests(ITestOutputHelper output)
|
|||
[(Phone("0_n", "n", 0.095f), 1f), (Phone("1_a", "a", 0.18f), 1f), (Phone("2_b", "b", 0.095f), 1f), (Phone("3_a", "a", 0.18f), 1f), (Phone("4_n", "n", 0.095f), 1f)], 140);
|
||||
var withBurst = Render(script, 0.77f);
|
||||
var withoutBurst = Render(script, 0.77f, p => p with { ControlSplines = p.ControlSplines.Where(s => !s.SurfacePath.EndsWith("/release_flow", StringComparison.Ordinal)).ToArray() });
|
||||
if (withBurst is null || withoutBurst is null) return;
|
||||
var burst = withBurst.Zip(withoutBurst, (x, y) => x - y).ToArray();
|
||||
const double bFrom = 0.275, bTo = 0.37;
|
||||
var atRelease = Peak(burst, bFrom + 0.095 * 0.6, bTo + 0.02);
|
||||
|
|
@ -162,13 +154,12 @@ public sealed class StressAndReleaseRenderTests(ITestOutputHelper output)
|
|||
// read -3.8 dB while its alveolar closure began to open at half the gesture, a third before the velum and the contact did (now held to
|
||||
// 0.8: /n/ -8.8, /m/ -12.8), and once the nasal junction sat on its own interface the nose took its share and both read -2.2 and -4.2 dB
|
||||
// until the nasal path carried its real damping (loss .975 per cell; /m/ -11.8, /n/ -9.6).
|
||||
[Theory]
|
||||
[FaustTheory]
|
||||
[InlineData("m")]
|
||||
[InlineData("n")]
|
||||
public void NasalMurmurIsWellBelowTheFlankingVowels(string ipa)
|
||||
{
|
||||
var (x, from, to) = VowelConsonantVowel(ipa);
|
||||
if (x is null) return;
|
||||
var db = ConsonantDbReVowels(x, from, to);
|
||||
output.WriteLine($"/{ipa}/ murmur {db:F1} dB re the flanking vowels");
|
||||
Assert.InRange(db, -16, -8);
|
||||
|
|
@ -177,7 +168,7 @@ public sealed class StressAndReleaseRenderTests(ITestOutputHelper output)
|
|||
// The primary-stress cue as the plan applies it (amplitude and f0 ratio, same vowel length) against the unstressed vowel, over five vowels:
|
||||
// the f0 rise alone moves the harmonics against F1 and the level by -1.3 to +1.8 dB by vowel, so the amplitude factor is held to the mean
|
||||
// rendered result, 2 dB (Sluijter and van Heuven 1996: 1 to 3 dB overall). Measured 1.7 dB with the amplitude at 1.26 (outside the band), 2.0 dB at 1.30.
|
||||
[Fact]
|
||||
[FaustFact]
|
||||
public void PrimaryStressRendersAboutTwoDecibelsLouderOnAverageOverVowels()
|
||||
{
|
||||
var cue = WeksaWordPlan.CueFor(WeksaStress.Primary);
|
||||
|
|
@ -188,11 +179,10 @@ public sealed class StressAndReleaseRenderTests(ITestOutputHelper output)
|
|||
{
|
||||
var script = IpaGestureExperiment.BuildWordScript([(new IpaGestureExperimentTarget($"w_0_{vowel}", vowel, "", 0.25f, PitchRatio: ratio), intensity)], 140, 0.2f);
|
||||
var x = Render(script, 0.45f);
|
||||
return x is null ? double.NaN : Rms(x, 0.12, 0.22);
|
||||
return Rms(x, 0.12, 0.22);
|
||||
}
|
||||
|
||||
var flat = Level(1f, 1f);
|
||||
if (double.IsNaN(flat)) return;
|
||||
var db = 20 * Math.Log10(Level(cue.PitchRatio, cue.Amplitude) / flat);
|
||||
output.WriteLine($"/{vowel}/ stressed against unstressed: {db:F2} dB");
|
||||
diffs.Add(db);
|
||||
|
|
@ -214,7 +204,7 @@ public sealed class StressAndReleaseRenderTests(ITestOutputHelper output)
|
|||
// mouth is shut, so all that gets out is the tract wall radiation of the voiced source: the voice bar, about 30 dB under the vowel for /b/
|
||||
// (a DESIGN value, no primary level retrieved; Stevens 1998 per secondary sources has voicing weaker as transglottal pressure falls), and
|
||||
// near-silent for /p/, whose source is weak. The closure was 0.0000 (below 16 bits) before the wall radiation.
|
||||
[Theory]
|
||||
[FaustTheory]
|
||||
[InlineData("b", -34, -26)]
|
||||
[InlineData("p", -60, -38)]
|
||||
public void PlosiveClosureCarriesTheVoiceBarOnlyWhenVoiced(string ipa, double lowDb, double highDb)
|
||||
|
|
@ -222,9 +212,36 @@ public sealed class StressAndReleaseRenderTests(ITestOutputHelper output)
|
|||
var script = IpaGestureExperiment.BuildWordScript(
|
||||
[(new IpaGestureExperimentTarget("w_0_c", ipa, "", 0.095f), 1f), (new IpaGestureExperimentTarget("w_1_a", "a", "", 0.18f), 1f)], 140);
|
||||
var x = Render(script, 0.4f);
|
||||
if (x is null) return;
|
||||
var db = 20 * Math.Log10(Math.Max(1e-9, Deviation(x, 0.03, 0.058)) / Deviation(x, 0.15, 0.25));
|
||||
output.WriteLine($"/{ipa}/ closure {db:F1} dB re the following vowel");
|
||||
Assert.InRange(db, lowDb, highDb);
|
||||
}
|
||||
}
|
||||
|
||||
// Reports Skipped, not Passed, when the Faust toolchain is absent: a test that returns early reads as a pass nobody earned.
|
||||
public sealed class FaustFactAttribute : FactAttribute
|
||||
{
|
||||
public FaustFactAttribute()
|
||||
{
|
||||
if (AquaSynthFaustToolchain.Find() is null) Skip = "Faust toolchain not found";
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class FaustTheoryAttribute : TheoryAttribute
|
||||
{
|
||||
public FaustTheoryAttribute()
|
||||
{
|
||||
if (AquaSynthFaustToolchain.Find() is null) Skip = "Faust toolchain not found";
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class FaustSkipTests
|
||||
{
|
||||
[Fact]
|
||||
public void StressTestsSkipWithoutFaust()
|
||||
{
|
||||
var toolchain = AquaSynthFaustToolchain.Find();
|
||||
Assert.Equal(toolchain is null, new FaustFactAttribute().Skip is not null);
|
||||
Assert.Equal(toolchain is null, new FaustTheoryAttribute().Skip is not null);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue