Skip to content

Commit ea1acdd

Browse files
Added support for StereoPannerNode.
1 parent d8f86a0 commit ea1acdd

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

samples/KristofferStrube.Blazor.WebAudio.WasmExample/Pages/Status.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
(285, 396),
5353
(421, 497),
5454
(500, 531),
55+
(539, 547),
5556
(582, 583),
5657
(585, 592),
5758
(594, 602)

src/KristofferStrube.Blazor.WebAudio/AudioNodes/StereoPannerNode.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using KristofferStrube.Blazor.WebIDL;
1+
using KristofferStrube.Blazor.WebAudio.Extensions;
2+
using KristofferStrube.Blazor.WebIDL;
23
using Microsoft.JSInterop;
34

45
namespace KristofferStrube.Blazor.WebAudio;
@@ -26,8 +27,32 @@ public class StereoPannerNode : AudioNode, IJSCreatable<StereoPannerNode>
2627
return Task.FromResult(new StereoPannerNode(jSRuntime, jSReference, options));
2728
}
2829

30+
/// <summary>
31+
/// Creates a <see cref="StereoPannerNode"/> using the standard constructor.
32+
/// </summary>
33+
/// <param name="jSRuntime">An <see cref="IJSRuntime"/> instance.</param>
34+
/// <param name="context">The <see cref="BaseAudioContext"/> this new <see cref="StereoPannerNode"/> will be associated with.</param>
35+
/// <param name="options">Optional initial parameter value for this <see cref="StereoPannerNode"/>.</param>
36+
/// <returns>A new instance of a <see cref="StereoPannerNode"/>.</returns>
37+
public static async Task<StereoPannerNode> CreateAsync(IJSRuntime jSRuntime, BaseAudioContext context, StereoPannerOptions? options = null)
38+
{
39+
IJSObjectReference helper = await jSRuntime.GetHelperAsync();
40+
IJSObjectReference jSInstance = await helper.InvokeAsync<IJSObjectReference>("constructStereoPannerNode", context, options);
41+
return new StereoPannerNode(jSRuntime, jSInstance, new() { DisposesJSReference = true });
42+
}
43+
2944
/// <inheritdoc cref="CreateAsync(IJSRuntime, IJSObjectReference, CreationOptions)"/>
3045
protected StereoPannerNode(IJSRuntime jSRuntime, IJSObjectReference jSReference, CreationOptions options) : base(jSRuntime, jSReference, options)
3146
{
3247
}
48+
49+
/// <summary>
50+
/// The position of the input in the output’s stereo image. <c>-1</c> represents full left, <c>+1</c> represents full right.
51+
/// </summary>
52+
public async Task<AudioParam> GetPanAsync()
53+
{
54+
IJSObjectReference helper = await webAudioHelperTask.Value;
55+
IJSObjectReference jSInstance = await helper.InvokeAsync<IJSObjectReference>("getAttribute", JSReference, "pan");
56+
return await AudioParam.CreateAsync(JSRuntime, jSInstance, new() { DisposesJSReference = true });
57+
}
3358
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace KristofferStrube.Blazor.WebAudio;
4+
5+
/// <summary>
6+
/// This specifies options for constructing a <see cref="StereoPannerNode"/>.
7+
/// </summary>
8+
/// <remarks><see href="https://www.w3.org/TR/webaudio/#StereoPannerOptions">See the API definition here</see>.</remarks>
9+
public class StereoPannerOptions : AudioNodeOptions
10+
{
11+
/// <summary>
12+
/// The initial value for <see cref="StereoPannerNode.GetPanAsync"/>
13+
/// </summary>
14+
[JsonPropertyName("pan")]
15+
public float Pan { get; set; } = 0;
16+
}

src/KristofferStrube.Blazor.WebAudio/wwwroot/KristofferStrube.Blazor.WebAudio.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ export function constructPannerNode(context, options) {
7878
return new PannerNode(context, options);
7979
}
8080

81+
export function constructStereoPannerNode(context, options) {
82+
return new StereoPannerNode(context, options);
83+
}
84+
8185
export function constructPeriodicWave(context, options) {
8286
return new PeriodicWave(context, options);
8387
}

0 commit comments

Comments
 (0)