From 817fb5261bfc84ba3bdd40e4098f992ca0779420 Mon Sep 17 00:00:00 2001 From: KristofferStrube Date: Sun, 15 Oct 2023 17:09:32 +0200 Subject: [PATCH] Added support for `DelayNode` and cleaned up. --- .../Pages/ApplyFilter.razor | 2 +- .../Pages/Status.razor | 2 +- .../AudioNodes/DelayNode.cs | 15 +++++++++++++++ .../Options/BiquadFilterOptions.cs | 2 +- .../Options/DelayOptions.cs | 4 ++-- .../Options/GainOptions.cs | 2 +- .../Options/PeriodicWaveConstraints.cs | 3 ++- .../Options/PeriodicWaveOptions.cs | 2 +- 8 files changed, 24 insertions(+), 8 deletions(-) diff --git a/samples/KristofferStrube.Blazor.WebAudio.WasmExample/Pages/ApplyFilter.razor b/samples/KristofferStrube.Blazor.WebAudio.WasmExample/Pages/ApplyFilter.razor index cbfd920..7331712 100644 --- a/samples/KristofferStrube.Blazor.WebAudio.WasmExample/Pages/ApplyFilter.razor +++ b/samples/KristofferStrube.Blazor.WebAudio.WasmExample/Pages/ApplyFilter.razor @@ -110,7 +110,7 @@ else var convolver = await ConvolverNode.CreateAsync(JSRuntime, audioContext, new() { Buffer = audioBuffer }); var destination = await audioContext.GetDestinationAsync(); - var delayNode = await DelayNode.CreateAsync(JSRuntime, audioContext, new() { DelayTime = 1, MaxDelayTime = 1 }); + var delayNode = await DelayNode.CreateAsync(JSRuntime, audioContext, new() { DelayTime = 0.01, MaxDelayTime = 1 }); var filterNode = await BiquadFilterNode.CreateAsync(JSRuntime, audioContext, options); var filteredAnalyserNode = await audioContext.CreateAnalyserAsync(); var analyserNode = await audioContext.CreateAnalyserAsync(); diff --git a/samples/KristofferStrube.Blazor.WebAudio.WasmExample/Pages/Status.razor b/samples/KristofferStrube.Blazor.WebAudio.WasmExample/Pages/Status.razor index e99dde1..a1d0212 100644 --- a/samples/KristofferStrube.Blazor.WebAudio.WasmExample/Pages/Status.razor +++ b/samples/KristofferStrube.Blazor.WebAudio.WasmExample/Pages/Status.razor @@ -32,7 +32,7 @@ (157, 200), (202, 252), (254, 254), - (285, 355), + (285, 366), (388, 396), (446, 456), (461, 468) diff --git a/src/KristofferStrube.Blazor.WebAudio/AudioNodes/DelayNode.cs b/src/KristofferStrube.Blazor.WebAudio/AudioNodes/DelayNode.cs index cb31500..95ab928 100644 --- a/src/KristofferStrube.Blazor.WebAudio/AudioNodes/DelayNode.cs +++ b/src/KristofferStrube.Blazor.WebAudio/AudioNodes/DelayNode.cs @@ -45,4 +45,19 @@ public static async Task CreateAsync(IJSRuntime jSRuntime, BaseAudioC /// An instance. /// A JS reference to an existing . protected DelayNode(IJSRuntime jSRuntime, IJSObjectReference jSReference) : base(jSRuntime, jSReference) { } + + /// + /// An object representing the amount of delay (in seconds) to apply. + /// Its default value is 0 (no delay). + /// The minimum value is 0 and the maximum value is determined by the maxDelayTime argument parsed to or the if constructed using the method. + /// + /// + /// If is part of a cycle, then the value is clamped to a minimum of one render quantum. + /// + public async Task GetDelayTimeAsync() + { + IJSObjectReference helper = await webAudioHelperTask.Value; + IJSObjectReference jSInstance = await helper.InvokeAsync("getAttribute", JSReference, "delayTime"); + return await AudioParam.CreateAsync(JSRuntime, jSInstance); + } } diff --git a/src/KristofferStrube.Blazor.WebAudio/Options/BiquadFilterOptions.cs b/src/KristofferStrube.Blazor.WebAudio/Options/BiquadFilterOptions.cs index c02b3a4..4c826a5 100644 --- a/src/KristofferStrube.Blazor.WebAudio/Options/BiquadFilterOptions.cs +++ b/src/KristofferStrube.Blazor.WebAudio/Options/BiquadFilterOptions.cs @@ -6,7 +6,7 @@ namespace KristofferStrube.Blazor.WebAudio; /// This specifies the options to be used when constructing a . /// /// See the API definition here. -public class BiquadFilterOptions +public class BiquadFilterOptions : AudioNodeOptions { /// /// The desired initial type of the filter. diff --git a/src/KristofferStrube.Blazor.WebAudio/Options/DelayOptions.cs b/src/KristofferStrube.Blazor.WebAudio/Options/DelayOptions.cs index afd216b..f0a669f 100644 --- a/src/KristofferStrube.Blazor.WebAudio/Options/DelayOptions.cs +++ b/src/KristofferStrube.Blazor.WebAudio/Options/DelayOptions.cs @@ -5,8 +5,8 @@ namespace KristofferStrube.Blazor.WebAudio; /// /// This specifies options for constructing a . /// -/// See the API definition here. -public class DelayOptions +/// See the API definition here. +public class DelayOptions : AudioNodeOptions { /// /// The maximum delay time for the node. Time is in seconds and must be greater than 0 and less than 3 minutes (180 seconds). diff --git a/src/KristofferStrube.Blazor.WebAudio/Options/GainOptions.cs b/src/KristofferStrube.Blazor.WebAudio/Options/GainOptions.cs index 5b12af9..c81a510 100644 --- a/src/KristofferStrube.Blazor.WebAudio/Options/GainOptions.cs +++ b/src/KristofferStrube.Blazor.WebAudio/Options/GainOptions.cs @@ -6,7 +6,7 @@ namespace KristofferStrube.Blazor.WebAudio; /// This specifies options to use in constructing a . /// /// See the API definition here. -public class GainOptions +public class GainOptions : AudioNodeOptions { /// /// The initial gain value for diff --git a/src/KristofferStrube.Blazor.WebAudio/Options/PeriodicWaveConstraints.cs b/src/KristofferStrube.Blazor.WebAudio/Options/PeriodicWaveConstraints.cs index 561e397..6222e61 100644 --- a/src/KristofferStrube.Blazor.WebAudio/Options/PeriodicWaveConstraints.cs +++ b/src/KristofferStrube.Blazor.WebAudio/Options/PeriodicWaveConstraints.cs @@ -9,7 +9,8 @@ namespace KristofferStrube.Blazor.WebAudio; public class PeriodicWaveConstraints { /// - /// Controls whether the periodic wave is normalized or not. If , the waveform is not normalized; otherwise, the waveform is normalized. + /// Controls whether the periodic wave is normalized or not. + /// If , the waveform is not normalized; otherwise, the waveform is normalized. /// [JsonPropertyName("disableNormalization")] public bool DisableNormalization { get; set; } = false; diff --git a/src/KristofferStrube.Blazor.WebAudio/Options/PeriodicWaveOptions.cs b/src/KristofferStrube.Blazor.WebAudio/Options/PeriodicWaveOptions.cs index 5ce22e1..e9f21f0 100644 --- a/src/KristofferStrube.Blazor.WebAudio/Options/PeriodicWaveOptions.cs +++ b/src/KristofferStrube.Blazor.WebAudio/Options/PeriodicWaveOptions.cs @@ -11,7 +11,7 @@ namespace KristofferStrube.Blazor.WebAudio; /// If both are given, the sequences must have the same length; otherwise an error of type will be thrown. /// /// See the API definition here. -public class PeriodicWaveOptions +public class PeriodicWaveOptions : PeriodicWaveConstraints { /// /// The imag parameter represents an array of sine terms.