diff --git a/src/AquaSynth.Faust/NativeFaustRuntime.cs b/src/AquaSynth.Faust/NativeFaustRuntime.cs index e6b44c4..bf707ef 100644 --- a/src/AquaSynth.Faust/NativeFaustRuntime.cs +++ b/src/AquaSynth.Faust/NativeFaustRuntime.cs @@ -840,32 +840,16 @@ internal sealed class FaustNativeToolchain : IDisposable public void SetControls(IntPtr dsp, IReadOnlyDictionary controls, IReadOnlyDictionary map) { - // Dictionary's struct enumerator avoids boxing one through the interface on every audio block. - if (controls is Dictionary dictionary) - { - foreach (var (path, value) in dictionary) - { - WriteControl(map, path, value); - } - - return; - } - foreach (var (path, value) in controls) { - WriteControl(map, path, value); - } - } + if (!map.TryGetValue(path, out var zone) && + !map.TryGetValue(path.TrimStart('/'), out zone)) + { + throw new ArgumentException($"Faust control `{path}` was not exported by the compiled patch.", nameof(controls)); + } - private static void WriteControl(IReadOnlyDictionary map, string path, float value) - { - if (!map.TryGetValue(path, out var zone) && - !map.TryGetValue(path.TrimStart('/'), out zone)) - { - throw new ArgumentException($"Faust control `{path}` was not exported by the compiled patch.", "controls"); + Marshal.Copy([value], 0, zone, 1); } - - Marshal.WriteInt32(zone, BitConverter.SingleToInt32Bits(value)); } public void Dispose()