Skip to content

Commit

Permalink
Added support for DelayNode and cleaned up.
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferStrube committed Oct 15, 2023
1 parent 3ada736 commit 817fb52
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
(157, 200),
(202, 252),
(254, 254),
(285, 355),
(285, 366),
(388, 396),
(446, 456),
(461, 468)
Expand Down
15 changes: 15 additions & 0 deletions src/KristofferStrube.Blazor.WebAudio/AudioNodes/DelayNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,19 @@ public static async Task<DelayNode> CreateAsync(IJSRuntime jSRuntime, BaseAudioC
/// <param name="jSRuntime">An <see cref="IJSRuntime"/> instance.</param>
/// <param name="jSReference">A JS reference to an existing <see cref="DelayNode"/>.</param>
protected DelayNode(IJSRuntime jSRuntime, IJSObjectReference jSReference) : base(jSRuntime, jSReference) { }

/// <summary>
/// An <see cref="AudioParam"/> object representing the amount of delay (in seconds) to apply.
/// Its default value is <c>0</c> (no delay).
/// The minimum value is <c>0</c> and the maximum value is determined by the maxDelayTime argument parsed to <see cref="BaseAudioContext.CreateDelayAsync(double)"/> or the <see cref="DelayOptions.MaxDelayTime"/> if constructed using the <see cref="CreateAsync(IJSRuntime, BaseAudioContext, DelayOptions?)"/> method.
/// </summary>
/// <remarks>
/// If <see cref="DelayNode"/> is part of a cycle, then the value is clamped to a minimum of one render quantum.
/// </remarks>
public async Task<AudioParam> GetDelayTimeAsync()
{
IJSObjectReference helper = await webAudioHelperTask.Value;
IJSObjectReference jSInstance = await helper.InvokeAsync<IJSObjectReference>("getAttribute", JSReference, "delayTime");
return await AudioParam.CreateAsync(JSRuntime, jSInstance);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace KristofferStrube.Blazor.WebAudio;
/// This specifies the options to be used when constructing a <see cref="BiquadFilterNode"/>.
/// </summary>
/// <remarks><see href="https://www.w3.org/TR/webaudio/#BiquadFilterOptions">See the API definition here</see>.</remarks>
public class BiquadFilterOptions
public class BiquadFilterOptions : AudioNodeOptions
{
/// <summary>
/// The desired initial type of the filter.
Expand Down
4 changes: 2 additions & 2 deletions src/KristofferStrube.Blazor.WebAudio/Options/DelayOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace KristofferStrube.Blazor.WebAudio;
/// <summary>
/// This specifies options for constructing a <see cref="DelayNode"/>.
/// </summary>
/// <remarks><see href="https://www.w3.org/TR/webaudio/#BiquadFilterOptions">See the API definition here</see>.</remarks>
public class DelayOptions
/// <remarks><see href="https://www.w3.org/TR/webaudio/#DelayOptions">See the API definition here</see>.</remarks>
public class DelayOptions : AudioNodeOptions
{
/// <summary>
/// The maximum delay time for the node. Time is in seconds and must be greater than <c>0</c> and less than <c>3</c> minutes (<c>180</c> seconds).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace KristofferStrube.Blazor.WebAudio;
/// This specifies options to use in constructing a <see cref="GainNode"/>.
/// </summary>
/// <remarks><see href="https://www.w3.org/TR/webaudio/#GainOptions">See the API definition here</see>.</remarks>
public class GainOptions
public class GainOptions : AudioNodeOptions
{
/// <summary>
/// The initial gain value for <see cref="AudioParam.GetValueAsync"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ namespace KristofferStrube.Blazor.WebAudio;
public class PeriodicWaveConstraints
{
/// <summary>
/// Controls whether the periodic wave is normalized or not. If <see langword="true"/>, the waveform is not normalized; otherwise, the waveform is normalized.
/// Controls whether the periodic wave is normalized or not.
/// If <see langword="true"/>, the waveform is not normalized; otherwise, the waveform is normalized.
/// </summary>
[JsonPropertyName("disableNormalization")]
public bool DisableNormalization { get; set; } = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace KristofferStrube.Blazor.WebAudio;
/// If both are given, the sequences must have the same length; otherwise an error of type <see cref="NotSupportedErrorException"/> will be thrown.
/// </summary>
/// <remarks><see href="https://www.w3.org/TR/webaudio/#PeriodicWaveOptions">See the API definition here</see>.</remarks>
public class PeriodicWaveOptions
public class PeriodicWaveOptions : PeriodicWaveConstraints
{
/// <summary>
/// The imag parameter represents an array of sine terms.
Expand Down

0 comments on commit 817fb52

Please sign in to comment.