diff --git a/src/AquaSynth.Faust/FaustCompiler.cs b/src/AquaSynth.Faust/FaustCompiler.cs index 94f363b..a6efc54 100644 --- a/src/AquaSynth.Faust/FaustCompiler.cs +++ b/src/AquaSynth.Faust/FaustCompiler.cs @@ -22,7 +22,8 @@ public sealed record FaustValidation(string Command, bool Success, int? StatusCo public sealed record FaustWebAssemblyCompileOptions( string OutputDirectory, string BaseName = "aquasynth_patch", - bool Stereo = false); + bool Stereo = false, + int SampleRate = 48000); public sealed record FaustWebAssemblyManifest( string Name, @@ -89,7 +90,7 @@ public static class FaustCompiler string? faustPath = null, CancellationToken cancellationToken = default) { - var export = FaustEmitter.Emit(patch, new FaustExportOptions(options.BaseName, options.Stereo)); + var export = FaustEmitter.Emit(patch, new FaustExportOptions(options.BaseName, options.Stereo, SampleRate: options.SampleRate)); return await CompileWebAssemblySourceAsync(export.Source, options, faustPath, cancellationToken); } @@ -99,7 +100,7 @@ public static class FaustCompiler string? faustPath = null, CancellationToken cancellationToken = default) { - var export = FaustEmitter.EmitScript(script, new FaustExportOptions(options.BaseName, options.Stereo)); + var export = FaustEmitter.EmitScript(script, new FaustExportOptions(options.BaseName, options.Stereo, SampleRate: options.SampleRate)); return await CompileWebAssemblySourceAsync(export.Source, options, faustPath, cancellationToken); } diff --git a/src/AquaSynth.Faust/FaustRenderedSpeechLossSurface.cs b/src/AquaSynth.Faust/FaustRenderedSpeechLossSurface.cs index 03f9341..2c85b65 100644 --- a/src/AquaSynth.Faust/FaustRenderedSpeechLossSurface.cs +++ b/src/AquaSynth.Faust/FaustRenderedSpeechLossSurface.cs @@ -93,7 +93,7 @@ public sealed class FaustRenderedSpeechLossSurface(FaustRenderedSpeechLossOption source.AppendLine(VoiceLine("sine", F(hz), F(gain), target, 0, tract)); } - return FaustEmitter.EmitScript(source.ToString(), new FaustExportOptions("aquasynth_speech_loss")).Source; + return FaustEmitter.EmitScript(source.ToString(), new FaustExportOptions("aquasynth_speech_loss", SampleRate: options.SampleRate)).Source; } private async Task EstimateGradientAsync( diff --git a/src/AquaSynth.Faust/IpaTrialOrchestrator.cs b/src/AquaSynth.Faust/IpaTrialOrchestrator.cs index 4454451..5d4e178 100644 --- a/src/AquaSynth.Faust/IpaTrialOrchestrator.cs +++ b/src/AquaSynth.Faust/IpaTrialOrchestrator.cs @@ -309,12 +309,12 @@ public static class IpaTrialOrchestrator File.Copy(candidate.ScriptPath, scriptCopy, overwrite: true); var script = await File.ReadAllTextAsync(scriptCopy, cancellationToken).ConfigureAwait(false); var patch = PatchScript.Parse(script); - var timeline = ProbeTimelineReport.Build(patch, "voice", Math.Max(1, options.TimelineBlocks)); + var referenceFixture = PinkTromboneParityFixtures.ById(mapped.target.ReferenceFixtureId); + var reference = referenceRenderer.Render(referenceFixture.Controls, mapped.target.Target.DurationSeconds + .18f); + var timeline = ProbeTimelineReport.Build(patch, "voice", Math.Max(1, options.TimelineBlocks), reference.SampleRate); var timelinePath = Path.Combine(timelineRoot, $"{safeCandidateId}.csv"); await File.WriteAllTextAsync(timelinePath, ProbeTimelineReport.ToCsv(timeline), cancellationToken).ConfigureAwait(false); - var referenceFixture = PinkTromboneParityFixtures.ById(mapped.target.ReferenceFixtureId); - var reference = referenceRenderer.Render(referenceFixture.Controls, mapped.target.Target.DurationSeconds + .18f); var source = FaustEmitter.EmitScript(script, new FaustExportOptions(safeCandidateId, SampleRate: reference.SampleRate)).Source; var dspPath = Path.Combine(candidateDir, "candidate.dsp"); await File.WriteAllTextAsync(dspPath, source, cancellationToken).ConfigureAwait(false); diff --git a/tests/AquaSynth.Dsl.Tests/ProbeTimelineSampleRateTests.cs b/tests/AquaSynth.Dsl.Tests/ProbeTimelineSampleRateTests.cs index 9d381d9..5756019 100644 --- a/tests/AquaSynth.Dsl.Tests/ProbeTimelineSampleRateTests.cs +++ b/tests/AquaSynth.Dsl.Tests/ProbeTimelineSampleRateTests.cs @@ -28,4 +28,14 @@ public sealed class ProbeTimelineSampleRateTests Assert.Equal(0.1752f / 325 * 48000, Delay(2, 48000), 3); Assert.Equal(0.1752f / 550 * 44100, Delay(2, 44100), 3); } + + [Fact] + public void EmittedSourceFollowsTheRequestedSampleRate() + { + // The vocal ladder's delay-line lengths are length / speed * rate samples, so the emitted DSP carries the rate it was asked for. + var at48 = FaustEmitter.EmitScript(TimelineScript, new FaustExportOptions("rate_probe", SampleRate: 48000)).Source; + var at44 = FaustEmitter.EmitScript(TimelineScript, new FaustExportOptions("rate_probe", SampleRate: 44100)).Source; + Assert.NotEqual(at48, at44); + Assert.Equal(at48, FaustEmitter.EmitScript(TimelineScript, new FaustExportOptions("rate_probe")).Source); + } } diff --git a/tools/AquaLower/Program.cs b/tools/AquaLower/Program.cs index 103b913..018a52c 100644 --- a/tools/AquaLower/Program.cs +++ b/tools/AquaLower/Program.cs @@ -16,6 +16,7 @@ if (args.Length == 2 && args[0] == "--dings") var instruments = new List(); foreach (var ins in DingCatalog.Instruments.Values.OrderBy(i => i.Id, StringComparer.Ordinal)) { + // 48000 (the FaustExportOptions default) is the Ding catalog contract: DingCatalogTests pins the sources at that rate. var export = FaustEmitter.EmitScript(ins.Script, new FaustExportOptions(DingCatalog.Identity(ins).FaustName)); File.WriteAllText(Path.Combine(dingDir, ins.Id + ".dsp"), export.Source); instruments.Add(new { id = ins.Id, rootFrequency = ins.RootFrequency, dsp = ins.Id + ".dsp", controlPath = "/ding/frequency", warnings = export.Warnings }); @@ -42,6 +43,7 @@ foreach (var spec in args.Skip(2)) var warnings = new List(); if (path.EndsWith(".aqua", StringComparison.Ordinal)) { + // 48000 (the FaustExportOptions default): AquaLower lowers for the 48 kHz hosts. var export = FaustEmitter.EmitScript(text, new FaustExportOptions(name)); source = export.Source; warnings.AddRange(export.Warnings); diff --git a/tools/IpaTrialWorker/Program.cs b/tools/IpaTrialWorker/Program.cs index 1e7cbbc..661a96d 100644 --- a/tools/IpaTrialWorker/Program.cs +++ b/tools/IpaTrialWorker/Program.cs @@ -264,7 +264,7 @@ static async Task SongScoreAsync(Dictionary options) var timelineNetwork = patch.VocalNetworks.FirstOrDefault(); var timeline = timelineNetwork is null ? Array.Empty() - : ProbeTimelineReport.Build(patch, timelineNetwork.Name, 12); + : ProbeTimelineReport.Build(patch, timelineNetwork.Name, 12, challenge.SampleRate); await File.WriteAllTextAsync(timelinePath, ProbeTimelineReport.ToCsv(timeline), Encoding.UTF8); timelineFacts = PrimitiveTimelineFactExtractor.Extract(timeline).ToArray(); var source = FaustEmitter.EmitScript(script, new FaustExportOptions(safeCandidateId, SampleRate: challenge.SampleRate)).Source; diff --git a/tools/WordRender/Program.cs b/tools/WordRender/Program.cs index bfee4d6..32e01c8 100644 --- a/tools/WordRender/Program.cs +++ b/tools/WordRender/Program.cs @@ -45,7 +45,7 @@ using var compiler = new AquaSynthPatchCompiler(new AquaSynthNativeOptions(Sampl // itself and no slider is driven from outside. var parsed = PatchScript.Parse(script); if (noBurst) parsed = parsed with { ControlSplines = parsed.ControlSplines.Where(s => !s.SurfacePath.EndsWith("/release_flow", StringComparison.Ordinal)).ToArray() }; -var source = FaustEmitter.Emit(parsed, new FaustExportOptions(label)).Source; +var source = FaustEmitter.Emit(parsed, new FaustExportOptions(label, SampleRate: Rate)).Source; File.WriteAllText(Path.Combine(outDir, "source.dsp"), source); if (!compiler.TryCompileSource(new AquaSynthCompileIdentity(label, label, ""), source, seconds, out var patch0, out var cerr)) {