Closing ramp into a stop makes no hiss: burst gain only from the release; shut lips; spline handles follow their segment; release windows from one owner
The exporter's burst noise is 4*opening*(1-opening) times a gain held through the whole stop gesture, so the 30 ms boundary ramp into a stop was a 15-20 ms hiss (>4 kHz share of 6 ms frames at 188 ms of /ata/ -1 dB, base -57). The gain window now starts at PatchScript.StopReleaseStartSeconds, the one owner of the release time (tests read it instead of 0.65 / 0.6 literals). Stop lips are shut (0) rather than a 0.04 leak: word-initial /b/ voice bar -19.1 -> -27.7 dB, /p/ -30.1 -> -38.8 re the vowel, inside the asserted -34..-26 and -60..-38. Spline handle times are a third of their segment: the Faust lowering ignores them, the C# timeline folded a 12 ms opening with 23.75 ms handles. Closure windows start at the end of the boundary ramp (PhoneTransitionSeconds). New tests: closing-ramp >4 kHz energy for /t/ /p/ /b/, the DSP's own stop opening read through its reservoir probe, the emitted smoother (sample 0 and si.smoo pace) and the word's 12 ms attack rendered. Faust pins re-taken. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
20aec42577
commit
3e544288e6
5 changed files with 263 additions and 42 deletions
|
|
@ -24,17 +24,27 @@ any change, and again after.
|
|||
around each boundary of nibu: below 0.03; before, 0.77: the vowel's 1 against the nasal's released 0.23).
|
||||
2. A stop holds all its articulators shut until 12 ms before its end and opens in those 12 ms (`StopReleaseSeconds`, a design value);
|
||||
it used to open over 0.65 to 1 of its gesture. Test: `AStopOpensInTwelveMillisecondsNotAThirdOfItsGesture`.
|
||||
3. `smoo_init` replaces `si.smoo` on every control-surface and spline-point slider of the emitted DSP: the smoother starts at its input.
|
||||
Patch parameters keep `si.smoo`. Test: `ControlSmoothersStartAtTheirInputNotAtZero`.
|
||||
3. `smoo_init` replaces `si.smoo` on every control-surface and spline-point slider of the emitted DSP: the smoother starts at its input
|
||||
and keeps si.smoo's pole (a 22.7 ms time constant), so live control moves as fast as before. Patch parameters keep `si.smoo`. The
|
||||
source's own 10 ms pitch-ratio smoother starts at its input too. Tests: `ControlSmoothersStartAtTheirInputNotAtZero` (text) and
|
||||
`ASmootherStartsAtItsInputAndMovesAtSiSmoosPace` (the emitted smoother, rendered).
|
||||
4. The word scaffold's vocal envelope gets a 12 ms attack (it was 0, so the now-instant start was itself a click: first-sample peak 0.22).
|
||||
5. `tools/formant-check/ear_metrics.py` (click ratio, largest sample step, LPC bandwidths, HNR, energy above 4 kHz) and
|
||||
5. The ramp into a stop (item 1) sweeps the contact through every aperture between open and shut, and the exporter's burst noise is
|
||||
`4 * opening * (1 - opening)` times a gain that was held through the whole gesture: each closing ramp was a 15-20 ms hiss before the
|
||||
stop (>4 kHz share of the 6 ms frames at 188 ms of /ata/: -1 dB, against -57 dB with the closure stepped). The burst gain now exists
|
||||
only from the stop's release start (`PatchScript.StopReleaseStartSeconds`, the one owner of the release time), one ramp either side.
|
||||
A stop's lips are shut (aperture 0), not at 0.04: the word-initial /b/ voice bar read -19.1 dB re the vowel after it and /p/ -30.1
|
||||
against the design -34 to -26 and -60 to -38; shut they read -27.7 and -38.8. Spline handle times follow their segment (a third of
|
||||
it), so the C# timeline and the DSP agree on the 12 ms opening (the lowering ignores handle times). Tests:
|
||||
`ClosingIntoAStopMakesNoHighFrequencyNoise`, `TheDspRendersTheStopOpeningAsTheTimelineEvaluatesIt`, `PlosiveClosureCarriesTheVoiceBarOnlyWhenVoiced`.
|
||||
6. `tools/formant-check/ear_metrics.py` (click ratio, largest sample step, LPC bandwidths, HNR, energy above 4 kHz) and
|
||||
`tools/formant-check/phone_probe.py` (a speech recogniser as a machine ear) so these faults are measured, not heard first by Meta.
|
||||
|
||||
### After (same words, same 140 Hz, `fix-out-c`)
|
||||
|
||||
| word | before | after |
|
||||
|---|---|---|
|
||||
| nibu_flat | click ratio 3.54, peaks 0.399 / 0.487; recogniser `i b u` | peaks at the boundaries 0.08; click ratio 1.76 (the vowel's own pulses); recogniser `n i l t uː` (the /n/ is back, the /b/ reads as `l t`: see below) |
|
||||
| nibu_flat | click ratio 3.54, peaks 0.399 / 0.487; recogniser `i b u` | peaks at the boundaries 0.077 / 0.089; click ratio 1.79 (the vowel's own pulses); median sample step in the /b/ closure 0.0007 (0.0005 before; 0.0161 with the ramp hiss); recogniser `n i l t uː` as read before the closure-noise and shut-lips fixes (not re-run: no torch on this host; the /n/ is back, the /b/ reads as `l t`: see below) |
|
||||
| ba (burst) | recogniser `v ɑ`; burst 33 ms | `b ɑ`; opening 12 ms |
|
||||
| ba (no burst) | `b ɑ` | `m ɑ` |
|
||||
| ana / ama | `v ɑ m ɑ` / `v ɑ m ɑ` | `ɑ n ɑ` / `ɑ m ɑ` |
|
||||
|
|
@ -55,7 +65,7 @@ any change, and again after.
|
|||
reads as "bit" is for her ear; lax vowels in isolation and without vowel-inherent spectral change are known to be misheard
|
||||
(Hillenbrand et al. 1995, Strange et al. 1983), so the next kit also carries /ɪ/ in a word.
|
||||
- **The medial /b/ of nibu reads as `l t` to the recogniser after the fix, where it read `b` with the click and the long burst.** The closure
|
||||
voice bar sits 10 dB under the vowel (a murmur-like level; a stop's runs 20+ dB under), and a labial burst is injected at the glottal
|
||||
voice bar sat 10 dB under the vowel (a murmur-like level; a stop's runs 20+ dB under; 16-19 dB with the lips shut), and a labial burst is injected at the glottal
|
||||
end in a word with no other plosive (`FaustExport` burst injection), so it is filtered by the whole tract like aspiration. Both are
|
||||
next, with the listening to decide.
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,22 @@ public static class PatchScript
|
|||
/// A script that gestures a lateral without declaring it is refused, not approximated.</summary>
|
||||
public const string SideStubBranch = "side_stub";
|
||||
|
||||
// Seconds an articulator takes to move from where the previous phone left it to this phone's first value. A tract does not step
|
||||
// between phones: the merged surface curve held the previous value up to the boundary and jumped, and a jump in a ladder cell's
|
||||
// area is a transient the ear hears as a click (nibu: peak 0.40 and 0.49 against a 0.2 vowel, at the 95 and 275 ms boundaries),
|
||||
// and it leaves the consonant without the formant transitions that tell /b/ from a fade-in. A DESIGN VALUE inside the 20-50 ms
|
||||
// of a CV formant transition; no measurement of this tract retrieved.
|
||||
public const float PhoneTransitionSeconds = 0.03f;
|
||||
|
||||
// Seconds a stop takes to open from full closure; its burst lasts about this long. A DESIGN VALUE inside the 5-15 ms of a
|
||||
// stop burst; no measurement of this tract retrieved. The opening's noise is still shaped by the exporter.
|
||||
private const float StopReleaseSeconds = 0.012f;
|
||||
|
||||
/// <summary>Seconds after the start of a stop gesture of the given duration at which its articulators begin to open (the stop is
|
||||
/// shut until then). The one owner of the release time: the contact, lip and constriction splines hold shut to here and the burst
|
||||
/// gain window opens here; a test that wants the release reads it from here.</summary>
|
||||
public static float StopReleaseStartSeconds(float durationSeconds) => durationSeconds - MathF.Min(StopReleaseSeconds, 0.3f * durationSeconds);
|
||||
|
||||
public static bool TryIpaDescriptor(string ipa, out string descriptor)
|
||||
{
|
||||
if (StoryVowelAreas.TryVowelForIpa(ipa, out var vowelDescriptor, out _))
|
||||
|
|
@ -1494,22 +1510,13 @@ public static class PatchScript
|
|||
duration * 0.25f,
|
||||
Math.Clamp(point.value, 0, 1)))
|
||||
.ToArray();
|
||||
splinePoints = WithPhoneTransition(surfacePath, start, duration, splinePoints);
|
||||
splinePoints = FollowSegments(WithPhoneTransition(surfacePath, start, duration, splinePoints));
|
||||
var spline = new ControlSpline(splineName, surfacePath, splinePoints, ControlSplineInterpolation.Bezier);
|
||||
_controlSplines.Add(spline);
|
||||
_controlSplinesByName[spline.Name] = spline;
|
||||
}
|
||||
|
||||
// Seconds an articulator takes to move from where the previous phone left it to this phone's first value. A tract does not step
|
||||
// between phones: the merged surface curve held the previous value up to the boundary and jumped, and a jump in a ladder cell's
|
||||
// area is a transient the ear hears as a click (nibu: peak 0.40 and 0.49 against a 0.2 vowel, at the 95 and 275 ms boundaries),
|
||||
// and it leaves the consonant without the formant transitions that tell /b/ from a fade-in. A DESIGN VALUE inside the 20-50 ms
|
||||
// of a CV formant transition; no measurement of this tract retrieved.
|
||||
private const float PhoneTransitionSeconds = 0.03f;
|
||||
|
||||
// Seconds a stop takes to open from full closure; its burst lasts about this long. A DESIGN VALUE inside the 5-15 ms of a
|
||||
// stop burst; no measurement of this tract retrieved. The opening's noise is still shaped by the exporter.
|
||||
private const float StopReleaseSeconds = 0.012f;
|
||||
|
||||
// Prepends the boundary ramp: a point at the gesture start holding the value the surface has there, then the gesture's first
|
||||
// point PhoneTransitionSeconds later (at most 0.4 of the gesture, and before its second point). The first phone of a word, and
|
||||
|
|
@ -1537,6 +1544,24 @@ public static class PatchScript
|
|||
return [lead, arrival, .. points.Skip(1)];
|
||||
}
|
||||
|
||||
// Sets every handle's time to a third of the segment it belongs to. The Faust lowering evaluates a segment's Bezier on the
|
||||
// linear fraction of its time and ignores the handle times; a handle of a third makes the C# timeline (which solves the curve's
|
||||
// time for its parameter) agree with it exactly. A handle longer than the segment (0.25 of the gesture on a 12 ms opening) folds
|
||||
// the C# curve back on itself.
|
||||
private static ControlSplinePoint[] FollowSegments(ControlSplinePoint[] points)
|
||||
{
|
||||
if (points.Length < 2) return points;
|
||||
var shaped = new ControlSplinePoint[points.Length];
|
||||
for (var i = 0; i < points.Length; i++)
|
||||
{
|
||||
var after = (i + 1 < points.Length ? points[i + 1].TimeSeconds - points[i].TimeSeconds : points[i].TimeSeconds - points[i - 1].TimeSeconds) / 3;
|
||||
var before = (i > 0 ? points[i].TimeSeconds - points[i - 1].TimeSeconds : points[1].TimeSeconds - points[0].TimeSeconds) / 3;
|
||||
shaped[i] = points[i] with { InTimeOffsetSeconds = before, OutTimeOffsetSeconds = after };
|
||||
}
|
||||
|
||||
return shaped;
|
||||
}
|
||||
|
||||
private string UniqueSplineName(string name)
|
||||
{
|
||||
var safe = SafeName(name);
|
||||
|
|
@ -1606,14 +1631,16 @@ public static class PatchScript
|
|||
// opening, and an opening spread over a third of the gesture (33 ms of the 95 ms /b/) made the burst a fricative's length
|
||||
// (the phone recogniser heard /v/ before the vowel, Meta heard "fah then bah").
|
||||
var isStop = tokens.Contains("plosive") || tokens.Contains("stop");
|
||||
var stopHold = 1 - MathF.Min(StopReleaseSeconds, 0.3f * duration) / duration;
|
||||
var stopHold = StopReleaseStartSeconds(duration) / duration;
|
||||
var closureHold = tokens.Contains("nasal") || tokens.Contains("lateral") ? 0.8f : isStop ? stopHold : 0.5f;
|
||||
var closed = stopsBehindTheLips ? 0f : constriction;
|
||||
AddAuthoredSpline($"{name}_constriction_diameter", "/vocal/areas/0/area/constriction_diameter", start, duration, (0, closed), (closureHold, closed), (1, Math.Min(0.65f, constriction + 0.2f)));
|
||||
|
||||
if (tokens.Contains("bilabial") || tokens.Contains("labiodental") || tokens.Contains("labial") || tokens.Contains("rounded"))
|
||||
{
|
||||
var lipTarget = tokens.Contains("approximant") ? 0.38f : tokens.Contains("fricative") ? 0.18f : 0.04f;
|
||||
// A stop's lips are shut, not at a 0.04 leak: at 0.04 the closed-mouth voice bar of /b/ read -19.1 dB re the following vowel (the
|
||||
// test's design value is -34 to -26) and /p/ -30.1 (-60 to -38); shut, -27.7 and -38.8. A nasal keeps its murmur's small opening.
|
||||
var lipTarget = tokens.Contains("approximant") ? 0.38f : tokens.Contains("fricative") ? 0.18f : isStop ? 0f : 0.04f;
|
||||
AddAuthoredSpline($"{name}_lip_area", "/vocal/areas/0/area/lip_opening", start, duration, (0, lipTarget), (isStop ? stopHold : 0.7f, lipTarget), (1, 0.45f));
|
||||
AddAuthoredSpline($"{name}_lip_radiation", "/vocal/radiation/0/aperture", start, duration, (0, lipTarget), (isStop ? stopHold : 0.7f, lipTarget), (1, 0.75f));
|
||||
}
|
||||
|
|
@ -1631,7 +1658,12 @@ public static class PatchScript
|
|||
// it by the stored pressure and the opening (see PrimitiveContactExpression). The gain exists only around this plosive:
|
||||
// a surface holds its last value after its last point (and its first before its first), so a gain left at its level
|
||||
// made noise at every later contact state, the final nasal's closure and the tail included.
|
||||
GainAroundGesture($"{name}_release_flow", "/vocal/contacts/0/release_flow", start, duration, stopsBehindTheLips ? TongueStopBurstGain : PlosiveBurstGain);
|
||||
// The exporter's burst is noise times 4 * opening * (1 - opening): it sounds whenever the contact passes between shut and open
|
||||
// in either direction, so a gain held through the closure made the 30 ms closing ramp a 15-20 ms hiss before every stop (the
|
||||
// >4 kHz share of the frames before /t/ was -1 dB against -57 dB with the closure stepped). The gain exists only from the
|
||||
// stop's release start to its end, one ramp (0.15 of that window) either side.
|
||||
var releaseStart = StopReleaseStartSeconds(duration);
|
||||
GainAroundGesture($"{name}_release_flow", "/vocal/contacts/0/release_flow", start + releaseStart, duration - releaseStart, stopsBehindTheLips ? TongueStopBurstGain : PlosiveBurstGain);
|
||||
PlaceBurst(name, tokens, place, start, duration);
|
||||
AddAuthoredSpline($"{name}_velum", "/vocal/branches/0/opening", start, duration, (0, VelumClosed), (1, VelumClosed));
|
||||
}
|
||||
|
|
@ -1713,15 +1745,14 @@ public static class PatchScript
|
|||
}
|
||||
|
||||
var level = Math.Clamp((gain - surface.MinValue) / (surface.MaxValue - surface.MinValue), 0, 1);
|
||||
var handle = duration * 0.25f;
|
||||
ControlSplinePoint At(float time, float value) => new(time, value, handle, value, handle, value);
|
||||
ControlSplinePoint At(float time, float value) => new(time, value, 0, value, 0, value);
|
||||
var ramp = duration * 0.15f;
|
||||
var points = new List<ControlSplinePoint>();
|
||||
if (start > 0) points.Add(At(Math.Max(0, start - ramp), 0));
|
||||
points.Add(At(start, level));
|
||||
points.Add(At(start + duration, level));
|
||||
points.Add(At(start + duration + ramp, 0));
|
||||
var spline = new ControlSpline(UniqueSplineName(name), surfacePath, points.ToArray(), ControlSplineInterpolation.Bezier);
|
||||
var spline = new ControlSpline(UniqueSplineName(name), surfacePath, FollowSegments(points.ToArray()), ControlSplineInterpolation.Bezier);
|
||||
_controlSplines.Add(spline);
|
||||
_controlSplinesByName[spline.Name] = spline;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ public sealed class PlaceTableTests(ITestOutputHelper output)
|
|||
.Single(s => s.Name.StartsWith($"{name}_constriction_index", StringComparison.Ordinal) && s.SurfacePath == "/vocal/areas/0/area/constriction_index").Points[^1].Value; // the held place; a boundary ramp may precede it
|
||||
|
||||
// Re-pinned on the phone-transition cut (boundary ramps, 12 ms stop release, smoo_init, vocal attack): these ids moved on purpose; the invariant
|
||||
// that survives is that a word of labials writes no position surface (below), not these bytes. Pre-cut values on af0e44f: the vowel_set constriction_index spline value of /b/ and /n/ (and the hash of the whole script and of the
|
||||
// that survives is that a word of labials writes no position surface (below), not these bytes. Faust ids re-pinned again on the PR 52 fix pass (smoo_init pole and step, pitch-ratio smoother, shut lips for stops, spline handles; the scripts are unchanged). Pre-cut values on af0e44f: the vowel_set constriction_index spline value of /b/ and /n/ (and the hash of the whole script and of the
|
||||
// Faust source for /apa/ and /aba/, which this cut must not change by a byte; the ids are a SHA-256 prefix).
|
||||
private const float BIndex = 0.8333333f, NIndex = 0.7118056f;
|
||||
|
||||
|
|
@ -29,7 +29,7 @@ public sealed class PlaceTableTests(ITestOutputHelper output)
|
|||
var b = ConstrictionIndex(Word("b"), "w_1_c");
|
||||
var n = ConstrictionIndex(Word("n"), "w_1_c");
|
||||
output.WriteLine($"b {b:R} n {n:R}");
|
||||
foreach (var (ipa, scriptSha, faustSha) in new[] { ("p", "0E86DB0F40C0F12A", "7FDFCB446676787E"), ("b", "A63403EBAAD016FB", "574AC2CE7AD191FC") })
|
||||
foreach (var (ipa, scriptSha, faustSha) in new[] { ("p", "0E86DB0F40C0F12A", "784DFE4F27E0C6FA"), ("b", "A63403EBAAD016FB", "A9CF3BE4FC70CEBC") })
|
||||
{
|
||||
var script = Word(ipa);
|
||||
var faust = FaustEmitter.Emit(PatchScript.Parse(script), new FaustExportOptions("pin", SampleRate: 48000)).Source;
|
||||
|
|
@ -48,8 +48,8 @@ public sealed class PlaceTableTests(ITestOutputHelper output)
|
|||
{
|
||||
foreach (var (ipa, scriptSha, faustSha) in new[]
|
||||
{
|
||||
("p", "0E86DB0F40C0F12A", "7FDFCB446676787E"), ("b", "A63403EBAAD016FB", "574AC2CE7AD191FC"),
|
||||
("n", "5C3FA24E40D9DE26", "AD4C6E3371E089CF"), ("t", "45941CCFD93561B3", "3FF82CED153C1543"),
|
||||
("p", "0E86DB0F40C0F12A", "784DFE4F27E0C6FA"), ("b", "A63403EBAAD016FB", "A9CF3BE4FC70CEBC"),
|
||||
("n", "5C3FA24E40D9DE26", "45D129AFFDE320EC"), ("t", "45941CCFD93561B3", "95FABFEA9E608DC9"),
|
||||
})
|
||||
{
|
||||
var script = Word(ipa);
|
||||
|
|
|
|||
171
tests/AquaSynth.Dsl.Tests/StopClosureAndControlRenderTests.cs
Normal file
171
tests/AquaSynth.Dsl.Tests/StopClosureAndControlRenderTests.cs
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
using AquaSynth.Dsl;
|
||||
using AquaSynth.Faust;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace AquaSynth.Dsl.Tests;
|
||||
|
||||
// Renders behind the tract-coarticulation findings of the PR 52 Soul pass: what the closing ramp into a stop sounds like, what the DSP
|
||||
// does with a stop's 12 ms opening, and what the control smoothers and the word attack do at the start of a render. Each reads the
|
||||
// rendered signal (or the DSP's own probe), not the emitted text.
|
||||
[Collection("NativeFaust")]
|
||||
public sealed class StopClosureAndControlRenderTests(ITestOutputHelper output)
|
||||
{
|
||||
private const int Rate = 48000;
|
||||
|
||||
private static AquaSynthCompiledPatch? Compile(string source, float seconds)
|
||||
{
|
||||
using var compiler = new AquaSynthPatchCompiler(new AquaSynthNativeOptions(SampleRate: Rate));
|
||||
if (!compiler.TryCompileSource(new AquaSynthCompileIdentity("stop_closure", "stop_closure", ""), source, seconds, out var patch, out var error))
|
||||
{
|
||||
Assert.Fail($"compile failed: {error}");
|
||||
}
|
||||
|
||||
return patch;
|
||||
}
|
||||
|
||||
private static string Word(string ipa) => IpaGestureExperiment.BuildWordScript(
|
||||
[(new IpaGestureExperimentTarget("w_0_a", "a", "", 0.18f), 1f), (new IpaGestureExperimentTarget("w_1_c", ipa, "", 0.095f), 1f), (new IpaGestureExperimentTarget("w_2_a", "a", "", 0.18f), 1f)], 140);
|
||||
|
||||
// Power above 4 kHz (100 Hz grid to 12 kHz) of a Hann-windowed stretch.
|
||||
private static double HighPower(float[] x, double from, double to)
|
||||
{
|
||||
var a = (int)(from * Rate);
|
||||
var n = (int)((to - from) * Rate);
|
||||
var seg = Enumerable.Range(0, n).Select(i => x[a + i] * (0.5 - 0.5 * Math.Cos(2 * Math.PI * i / (n - 1)))).ToArray();
|
||||
double sum = 0;
|
||||
for (var hz = 4000; hz < 12000; hz += 100)
|
||||
{
|
||||
double re = 0, im = 0;
|
||||
for (var i = 0; i < n; i++) { var w = 2 * Math.PI * hz * i / Rate; re += seg[i] * Math.Cos(w); im -= seg[i] * Math.Sin(w); }
|
||||
sum += re * re + im * im;
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
// The 30 ms boundary ramp into a stop moves the contact, constriction and lip surfaces through every aperture between open and shut. The
|
||||
// burst noise is 4 * opening * (1 - opening) times a gain, and the gain was held through the closure, so each of those passes was a 15-20 ms
|
||||
// hiss before the stop (>4 kHz share of the 6 ms frames at 188 ms of /ata/: -1 dB; 5 dB over the vowel's own >4 kHz energy in /apa/'s whole
|
||||
// closing interval, 14 dB in /ata/, against 33 and 21 dB under it with the closure stepped). The interval is the stop's start to its release,
|
||||
// against the same length of the vowel before it.
|
||||
[FaustTheory]
|
||||
[InlineData("t")]
|
||||
[InlineData("p")]
|
||||
[InlineData("b")]
|
||||
public void ClosingIntoAStopMakesNoHighFrequencyNoise(string ipa)
|
||||
{
|
||||
using var patch = Compile(FaustEmitter.Emit(PatchScript.Parse(Word(ipa)), new FaustExportOptions("stop_closure", SampleRate: Rate)).Source, 0.5f);
|
||||
var x = patch!.Render(0.5f);
|
||||
const double from = 0.18;
|
||||
var release = PatchScript.StopReleaseStartSeconds(0.095f);
|
||||
var closing = HighPower(x, from, from + release);
|
||||
var vowel = HighPower(x, from - release, from);
|
||||
var db = 10 * Math.Log10(closing / vowel);
|
||||
output.WriteLine($"/{ipa}/ >4 kHz energy of the closing interval {db:F1} dB re the vowel's before it");
|
||||
Assert.True(db < -12, $"/{ipa}/ closes with {db:F1} dB re the vowel's own >4 kHz energy");
|
||||
}
|
||||
|
||||
// The Faust lowering of a Bezier segment ignores the handle times and runs the curve on the linear fraction of the segment; the C# timeline
|
||||
// solves the curve's time, so a handle longer than the segment folds it. The stop's 12 ms opening had 23.75 ms handles: the contact opening
|
||||
// read 0.05 to 0.87 between 6 and 7 ms in C# and 0.46 to 0.57 in the DSP. This reads the opening through the DSP's own contact reservoir probe
|
||||
// (stored pressure + (1 - opening) * resistance, both at their defaults once the other splines are dropped) and compares it with the timeline.
|
||||
[FaustFact]
|
||||
public void TheDspRendersTheStopOpeningAsTheTimelineEvaluatesIt()
|
||||
{
|
||||
var script = Word("p");
|
||||
var parsed = PatchScript.Parse(script);
|
||||
var contact = parsed.ControlSplines.Where(s => s.SurfacePath == "/vocal/contacts/0/opening").ToArray();
|
||||
var alone = parsed with { ControlSplines = contact };
|
||||
var timeline = new ControlSplineTimeline(contact);
|
||||
var source = FaustEmitter.Emit(alone, new FaustExportOptions("stop_opening", SampleRate: Rate, DebugProbeUi: true)).Source;
|
||||
using var patch = Compile(source, 0.5f);
|
||||
using var stream = patch!.CreateStreamingPatch();
|
||||
var reservoir = stream.ProbePaths.Single(p => p.EndsWith("/contact/contact/reservoir", StringComparison.Ordinal));
|
||||
var release = 0.18f + PatchScript.StopReleaseStartSeconds(0.095f);
|
||||
var outputs = new[] { new float[48] };
|
||||
var dsp = new List<(float Time, float Reservoir)>();
|
||||
for (var block = 0; block < 400; block++)
|
||||
{
|
||||
stream.ProcessBlock([], outputs, 48);
|
||||
var t = (block + 1) * 48f / Rate;
|
||||
if (t >= release - 0.004f && t <= release + 0.016f) dsp.Add((t, stream.ReadProbe(reservoir)));
|
||||
}
|
||||
|
||||
// reservoir is linear in the opening; scale it by its own end points
|
||||
var shut = dsp.First().Reservoir;
|
||||
var open = dsp.Last().Reservoir;
|
||||
var worst = 0f;
|
||||
foreach (var (time, value) in dsp)
|
||||
{
|
||||
var dspOpening = (value - shut) / (open - shut);
|
||||
var curve = timeline.ValueAt("/vocal/contacts/0/opening", time);
|
||||
var shutValue = timeline.ValueAt("/vocal/contacts/0/opening", dsp.First().Time);
|
||||
var openValue = timeline.ValueAt("/vocal/contacts/0/opening", dsp.Last().Time);
|
||||
var timelineOpening = (curve - shutValue) / (openValue - shutValue);
|
||||
worst = MathF.Max(worst, MathF.Abs(dspOpening - timelineOpening));
|
||||
}
|
||||
|
||||
output.WriteLine($"worst difference between the DSP's opening and the timeline's over the release: {worst:F3}");
|
||||
Assert.True(worst < 0.08f, $"the DSP's stop opening departs from the timeline by {worst:F3}");
|
||||
}
|
||||
|
||||
// The same fact without the DSP: every handle of an authored spline is a third of its segment, so the C# curve is the curve the lowering runs.
|
||||
[Fact]
|
||||
public void EveryAuthoredSplineHandleIsAThirdOfItsSegment()
|
||||
{
|
||||
var splines = PatchScript.Parse(Word("p")).ControlSplines.Where(s => s.Points.Count > 1).ToArray();
|
||||
Assert.NotEmpty(splines);
|
||||
foreach (var spline in splines)
|
||||
{
|
||||
for (var i = 0; i + 1 < spline.Points.Count; i++)
|
||||
{
|
||||
var third = (spline.Points[i + 1].TimeSeconds - spline.Points[i].TimeSeconds) / 3;
|
||||
Assert.Equal(third, spline.Points[i].OutTimeOffsetSeconds, 5);
|
||||
Assert.Equal(third, spline.Points[i + 1].InTimeOffsetSeconds, 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Replaces the emitted patch's process with one control through the emitted smoo_init, so the smoother under test is the one the exporter
|
||||
// writes. Starts at its input at sample 0, and moves at si.smoo's 22.7 ms time constant when the control moves (5 ms gave 0.89 here).
|
||||
[FaustFact]
|
||||
public void ASmootherStartsAtItsInputAndMovesAtSiSmoosPace()
|
||||
{
|
||||
var emitted = FaustEmitter.Emit(PatchScript.Parse(Word("p")), new FaustExportOptions("smoo", SampleRate: Rate)).Source;
|
||||
var lines = emitted.Split('\n').Select(l => l.StartsWith("process =", StringComparison.Ordinal) ? "process = hslider(\"/vocal/sources/0/pressure\", 0.7, 0, 1, 0.001) : smoo_init;" : l);
|
||||
using var patch = Compile(string.Join('\n', lines), 0.2f);
|
||||
using var stream = patch!.CreateStreamingPatch();
|
||||
var first = new[] { new float[480] };
|
||||
stream.ProcessBlock([], first, 480);
|
||||
output.WriteLine($"sample 0 {first[0][0]:F4}, after 10 ms {first[0][479]:F4}");
|
||||
Assert.Equal(0.7f, first[0][0], 4);
|
||||
Assert.Equal(0.7f, first[0][479], 4);
|
||||
var after = new[] { new float[240] };
|
||||
stream.ProcessBlock([], after, 240, new Dictionary<string, float> { ["/vocal/sources/0/pressure"] = 1f });
|
||||
// 5 ms into a step from 0.7 to 1 with a 22.7 ms time constant
|
||||
var expected = 0.7 + 0.3 * (1 - Math.Pow(1 - 44.1 / Rate, 0.005 * Rate));
|
||||
output.WriteLine($"5 ms after a step to 1: {after[0][239]:F4}, si.smoo would be {expected:F4}");
|
||||
Assert.InRange(after[0][239], expected - 0.01, expected + 0.01);
|
||||
}
|
||||
|
||||
// A word starts with a 12 ms attack, not a step: the control smoothers no longer fade it in, and a step onset would be a click.
|
||||
[FaustFact]
|
||||
public void AWordBeginsWithATwelveMillisecondAttack()
|
||||
{
|
||||
double FirstMillisecondsPeak(string script)
|
||||
{
|
||||
using var patch = Compile(FaustEmitter.Emit(PatchScript.Parse(script), new FaustExportOptions("attack", SampleRate: Rate)).Source, 0.4f);
|
||||
var x = patch!.Render(0.4f);
|
||||
var steady = x.Skip((int)(0.05 * Rate)).Take((int)(0.1 * Rate)).Max(Math.Abs);
|
||||
return x.Take((int)(0.002 * Rate)).Max(Math.Abs) / steady;
|
||||
}
|
||||
|
||||
var script = IpaGestureExperiment.BuildWordScript([(new IpaGestureExperimentTarget("w_0_a", "a", "", 0.3f), 1f)], 140);
|
||||
Assert.Contains("attack=.012", script);
|
||||
var attacked = FirstMillisecondsPeak(script);
|
||||
var stepped = FirstMillisecondsPeak(script.Replace("attack=.012 ", "", StringComparison.Ordinal));
|
||||
output.WriteLine($"peak of the first 2 ms re the steady peak: with the attack {attacked:F3}, without {stepped:F3}");
|
||||
Assert.True(attacked < 0.25, $"the first 2 ms reach {attacked:F2} of the steady peak");
|
||||
Assert.True(stepped > 2 * attacked, "without the attack the onset is a step");
|
||||
}
|
||||
}
|
||||
|
|
@ -24,6 +24,11 @@ public sealed class StressAndReleaseRenderTests(ITestOutputHelper output)
|
|||
using (patch) return patch!.Render(seconds);
|
||||
}
|
||||
|
||||
// The stop's release time and the start of its closure (every articulator at its shut value, after the boundary ramp into it), both from the
|
||||
// one owner in PatchScript rather than as fractions of the gesture; the consonant is [from, to).
|
||||
private static double ReleaseAt(double from, double to) => from + PatchScript.StopReleaseStartSeconds((float)(to - from));
|
||||
private static double ClosureFrom(double from) => from + PatchScript.PhoneTransitionSeconds;
|
||||
|
||||
private static double Rms(float[] x, double from, double to)
|
||||
{
|
||||
var a = (int)(from * Rate);
|
||||
|
|
@ -95,7 +100,8 @@ public sealed class StressAndReleaseRenderTests(ITestOutputHelper output)
|
|||
var withoutBurst = Render(script, 0.4f, p => p with { ControlSplines = p.ControlSplines.Where(s => !s.SurfacePath.EndsWith("/release_flow", StringComparison.Ordinal)).ToArray() });
|
||||
// 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;
|
||||
const double vowelFrom = 0.095;
|
||||
var releaseFrom = ReleaseAt(0, vowelFrom);
|
||||
var vowelPeak = Peak(withBurst, vowelFrom + 0.06, vowelFrom + 0.18);
|
||||
var burstPeak = Peak(burst, releaseFrom, vowelFrom + 0.01);
|
||||
var burstBeforeRelease = Peak(burst, 0, releaseFrom - 0.005);
|
||||
|
|
@ -121,7 +127,7 @@ public sealed class StressAndReleaseRenderTests(ITestOutputHelper output)
|
|||
var withoutBurst = Render(script, 0.77f, p => p with { ControlSplines = p.ControlSplines.Where(s => !s.SurfacePath.EndsWith("/release_flow", StringComparison.Ordinal)).ToArray() });
|
||||
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);
|
||||
var atRelease = Peak(burst, ReleaseAt(bFrom, bTo) - 0.003, bTo + 0.02);
|
||||
var leading = Peak(burst, 0, bFrom);
|
||||
var trailing = Peak(burst, bTo + 0.12, 0.77);
|
||||
output.WriteLine($"burst peak {atRelease:F4} at the release, {leading:F4} before the plosive (n, a), {trailing:F4} after it (a, n, tail)");
|
||||
|
|
@ -130,17 +136,19 @@ public sealed class StressAndReleaseRenderTests(ITestOutputHelper output)
|
|||
Assert.True(trailing < atRelease / 10, "no burst noise in the vowel, the nasal and the tail after the plosive");
|
||||
}
|
||||
|
||||
// The burst gain's window, read off the spline itself: it opens one ramp (0.15 of the gesture) before the plosive and has closed one ramp after it.
|
||||
// The rendered test above survived three mutants of the window (ramp 0, ramp 1.0 of the gesture, end moved to 3 ramps), so the bound is pinned here.
|
||||
// The burst gain's window, read off the spline itself: it exists only from the stop's release start, one ramp (0.15 of the release window)
|
||||
// before it and one after the stop's end. A gain held through the closure made the closing ramp a hiss (ClosingIntoAStopMakesNoHighFrequencyNoise).
|
||||
[Fact]
|
||||
public void PlosiveBurstGainWindowIsOneRampEitherSide()
|
||||
public void PlosiveBurstGainWindowIsOneRampEitherSideOfTheRelease()
|
||||
{
|
||||
IpaGestureExperimentTarget Phone(string label, string ipa, float seconds) => new($"w_{label}", ipa, "", seconds);
|
||||
var script = IpaGestureExperiment.BuildWordScript(
|
||||
[(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 window = PatchScript.Parse(script).ControlSplines.Single(s => s.SurfacePath.EndsWith("/release_flow", StringComparison.Ordinal) && s.Points.Any(p => p.Value > 0));
|
||||
const double start = 0.275, duration = 0.095, ramp = 0.15 * duration;
|
||||
Assert.Equal((start - ramp, start + duration + ramp), (window.Points.Min(p => (double)p.TimeSeconds), window.Points.Max(p => (double)p.TimeSeconds)), new TupleTolerance(1e-4));
|
||||
const double start = 0.275, duration = 0.095;
|
||||
var release = start + PatchScript.StopReleaseStartSeconds((float)duration);
|
||||
var ramp = 0.15 * (start + duration - release);
|
||||
Assert.Equal((release - ramp, start + duration + ramp), (window.Points.Min(p => (double)p.TimeSeconds), window.Points.Max(p => (double)p.TimeSeconds)), new TupleTolerance(1e-4));
|
||||
}
|
||||
|
||||
// /ɑ C ɑ/ at the scaffold's own durations (vowel 0.18 s, consonant 0.095 s). Returns the render and the consonant's [start, end).
|
||||
|
|
@ -241,7 +249,8 @@ public sealed class StressAndReleaseRenderTests(ITestOutputHelper output)
|
|||
private static SynthPatch WithoutBurst(SynthPatch p) =>
|
||||
p with { ControlSplines = p.ControlSplines.Where(s => !s.SurfacePath.EndsWith("/release_flow", StringComparison.Ordinal)).ToArray() };
|
||||
|
||||
// The closure of a stop is the part before its contact opens (0.65 of the gesture), 0.2 of the gesture in from its start, without the burst.
|
||||
// The closure of a stop is the part after the boundary ramp into it and before its release, without the burst (the ramp is the tract still
|
||||
// shutting on the vowel's decaying voicing; its noise is measured by ClosingIntoAStopMakesNoHighFrequencyNoise).
|
||||
// A tongue closure at the nasal's 0.03 cm aperture leaked: /t/ read -14.3 dB re the flanking vowels against /p/ -22.1 (the lips seal /p/);
|
||||
// completely closed it reads -24.3.
|
||||
[Fact]
|
||||
|
|
@ -252,7 +261,7 @@ public sealed class StressAndReleaseRenderTests(ITestOutputHelper output)
|
|||
var (x, from, to) = VowelConsonantVowel(ipa, descriptor: descriptor, edit: WithoutBurst);
|
||||
if (x is null) return double.NaN;
|
||||
var vowels = Math.Sqrt((Math.Pow(Rms(x, from - 0.08, from - 0.01), 2) + Math.Pow(Rms(x, to + 0.03, to + 0.12), 2)) / 2);
|
||||
return 20 * Math.Log10(Rms(x, from + 0.2 * (to - from), from + 0.65 * (to - from)) / vowels);
|
||||
return 20 * Math.Log10(Rms(x, ClosureFrom(from), ReleaseAt(from, to)) / vowels);
|
||||
}
|
||||
|
||||
var p = Closure("p", "voiceless_bilabial_plosive");
|
||||
|
|
@ -269,7 +278,7 @@ public sealed class StressAndReleaseRenderTests(ITestOutputHelper output)
|
|||
var (nb, _, _) = VowelConsonantVowel("t", descriptor: "voiceless_alveolar_plosive", edit: WithoutBurst);
|
||||
if (x is null || nb is null) return;
|
||||
var burst = x.Zip(nb, (a, b) => a - b).ToArray();
|
||||
var peak = Peak(burst, from + 0.6 * (to - from), to + 0.01);
|
||||
var peak = Peak(burst, ReleaseAt(from, to) - 0.003, to + 0.01);
|
||||
var vowel = Peak(x, to + 0.06, to + 0.17);
|
||||
output.WriteLine($"/t/ burst peak {peak:F4}, vowel peak {vowel:F4}, ratio {peak / vowel:F2}");
|
||||
Assert.True(peak > 0.004, "audible");
|
||||
|
|
@ -288,7 +297,7 @@ public sealed class StressAndReleaseRenderTests(ITestOutputHelper output)
|
|||
if (withBurst is null || withoutBurst is null) return;
|
||||
var burst = withBurst.Zip(withoutBurst, (x, y) => x - y).ToArray();
|
||||
const double tFrom = 0.275, tTo = 0.37;
|
||||
var atRelease = Peak(burst, tFrom + 0.095 * 0.6, tTo + 0.02);
|
||||
var atRelease = Peak(burst, ReleaseAt(tFrom, tTo) - 0.003, tTo + 0.02);
|
||||
var leading = Peak(burst, 0, tFrom);
|
||||
var trailing = Peak(burst, tTo + 0.12, 0.77);
|
||||
output.WriteLine($"/t/ burst peak {atRelease:F4} at the release, {leading:F5} before the plosive, {trailing:F5} after it");
|
||||
|
|
@ -305,7 +314,7 @@ public sealed class StressAndReleaseRenderTests(ITestOutputHelper output)
|
|||
var (x, from, to) = VowelConsonantVowel("t");
|
||||
var (nb, _, _) = VowelConsonantVowel("t", edit: WithoutBurst);
|
||||
if (x is null || nb is null) return;
|
||||
var start = (int)((from + 0.65 * (to - from)) * Rate);
|
||||
var start = (int)(ReleaseAt(from, to) * Rate);
|
||||
const int n = 960;
|
||||
var seg = Enumerable.Range(0, n).Select(i => (x[start + i] - nb[start + i]) * (0.5 - 0.5 * Math.Cos(2 * Math.PI * i / (n - 1)))).ToArray();
|
||||
double Power(double hz)
|
||||
|
|
@ -347,7 +356,7 @@ public sealed class StressAndReleaseRenderTests(ITestOutputHelper output)
|
|||
var (x, from, to) = VowelConsonantVowel(ipa, descriptor: descriptor, edit: edit);
|
||||
if (x is null) return double.NaN;
|
||||
var vowels = Math.Sqrt((Math.Pow(Rms(x, from - 0.08, from - 0.01), 2) + Math.Pow(Rms(x, to + 0.03, to + 0.12), 2)) / 2);
|
||||
return 20 * Math.Log10(Rms(x, from + 0.2 * (to - from), from + 0.65 * (to - from)) / vowels);
|
||||
return 20 * Math.Log10(Rms(x, ClosureFrom(from), ReleaseAt(from, to)) / vowels);
|
||||
}
|
||||
|
||||
var p = Closure("p", "voiceless_bilabial_plosive", WithoutBurst);
|
||||
|
|
@ -366,7 +375,7 @@ public sealed class StressAndReleaseRenderTests(ITestOutputHelper output)
|
|||
var (nb, _, _) = VowelConsonantVowel("k", descriptor: "voiceless_velar_plosive", edit: WithoutBurst);
|
||||
if (x is null || nb is null) return;
|
||||
var burst = x.Zip(nb, (a, b) => a - b).ToArray();
|
||||
var peak = Peak(burst, from + 0.6 * (to - from), to + 0.01);
|
||||
var peak = Peak(burst, ReleaseAt(from, to) - 0.003, to + 0.01);
|
||||
var vowel = Peak(x, to + 0.06, to + 0.17);
|
||||
output.WriteLine($"/k/ burst peak {peak:F4}, vowel peak {vowel:F4}, ratio {peak / vowel:F2}");
|
||||
Assert.True(peak > 0.004, "audible");
|
||||
|
|
@ -384,7 +393,7 @@ public sealed class StressAndReleaseRenderTests(ITestOutputHelper output)
|
|||
if (withBurst is null || withoutBurst is null) return;
|
||||
var burst = withBurst.Zip(withoutBurst, (x, y) => x - y).ToArray();
|
||||
const double kFrom = 0.275, kTo = 0.37;
|
||||
var atRelease = Peak(burst, kFrom + 0.095 * 0.6, kTo + 0.02);
|
||||
var atRelease = Peak(burst, ReleaseAt(kFrom, kTo) - 0.003, kTo + 0.02);
|
||||
var leading = Peak(burst, 0, kFrom);
|
||||
var trailing = Peak(burst, kTo + 0.12, 0.77);
|
||||
output.WriteLine($"/k/ burst peak {atRelease:F4} at the release, {leading:F5} before the plosive, {trailing:F5} after it");
|
||||
|
|
@ -402,7 +411,7 @@ public sealed class StressAndReleaseRenderTests(ITestOutputHelper output)
|
|||
var (x, from, to) = VowelConsonantVowel(ipa, descriptor: descriptor);
|
||||
var (nb, _, _) = VowelConsonantVowel(ipa, descriptor: descriptor, edit: WithoutBurst);
|
||||
if (x is null || nb is null) return (double.NaN, double.NaN);
|
||||
var start = (int)((from + 0.65 * (to - from)) * Rate);
|
||||
var start = (int)(ReleaseAt(from, to) * Rate);
|
||||
const int n = 960;
|
||||
var seg = Enumerable.Range(0, n).Select(i => (x[start + i] - nb[start + i]) * (0.5 - 0.5 * Math.Cos(2 * Math.PI * i / (n - 1)))).ToArray();
|
||||
double Power(double hz)
|
||||
|
|
@ -468,7 +477,7 @@ public sealed class StressAndReleaseRenderTests(ITestOutputHelper output)
|
|||
if (withBurst is null || withoutBurst is null) return;
|
||||
var burst = withBurst.Zip(withoutBurst, (x, y) => x - y).ToArray();
|
||||
const double dFrom = 0.275, dTo = 0.37;
|
||||
var atRelease = Peak(burst, dFrom + 0.095 * 0.6, dTo + 0.02);
|
||||
var atRelease = Peak(burst, ReleaseAt(dFrom, dTo) - 0.003, dTo + 0.02);
|
||||
var leading = Peak(burst, 0, dFrom);
|
||||
var trailing = Peak(burst, dTo + 0.12, 0.77);
|
||||
output.WriteLine($"/d/ burst peak {atRelease:F4} at the release, {leading:F5} before the plosive, {trailing:F5} after it");
|
||||
|
|
|
|||
Loading…
Reference in a new issue