Callers pass the sample rate they render at (timeline, speech-loss emit, wasm compile, WordRender); AquaLower stays 48000
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
af0e44f9b6
commit
eceaae29c2
7 changed files with 22 additions and 9 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<float[]> EstimateGradientAsync(
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ if (args.Length == 2 && args[0] == "--dings")
|
|||
var instruments = new List<object>();
|
||||
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<string>();
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -264,7 +264,7 @@ static async Task SongScoreAsync(Dictionary<string, string> options)
|
|||
var timelineNetwork = patch.VocalNetworks.FirstOrDefault();
|
||||
var timeline = timelineNetwork is null
|
||||
? Array.Empty<ProbeTimelineSample>()
|
||||
: 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;
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue