Skip to content

Commit b1a7b53

Browse files
Update to use compressor.
1 parent 7a24ec8 commit b1a7b53

File tree

1 file changed

+6
-2
lines changed
  • samples/KristofferStrube.Blazor.WebAudio.WasmExample/Pages

1 file changed

+6
-2
lines changed

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@page "/Keyboard"
22
@inject IJSRuntime JSRuntime
33
@using KristofferStrube.Blazor.WebAudio.WasmExample.ADSREditor
4+
45
<PageTitle>WebAudio - Keyboard</PageTitle>
56
<h2>Keyboard</h2>
67

@@ -62,6 +63,7 @@
6263

6364
AudioContext context = default!;
6465
GainNode? mainNode;
66+
DynamicsCompressorNode? compressor;
6567
GainNode? keyboardMain;
6668
OscillatorNode? oscillator;
6769

@@ -91,11 +93,13 @@
9193

9294
public async Task InitializeContext()
9395
{
94-
if (context is null || mainNode is null)
96+
if (context is null || mainNode is null || compressor is null)
9597
{
9698
context = await AudioContext.CreateAsync(JSRuntime);
9799
mainNode = await GainNode.CreateAsync(JSRuntime, context, new() { Gain = 0.5f });
100+
compressor = await DynamicsCompressorNode.CreateAsync(JSRuntime, context);
98101
await using AudioDestinationNode destination = await context.GetDestinationAsync();
102+
await compressor.ConnectAsync(mainNode);
99103
await mainNode.ConnectAsync(destination);
100104
}
101105
}
@@ -121,7 +125,7 @@
121125
keyboardMain = await GainNode.CreateAsync(JSRuntime, context, new() { Gain = 0 });
122126

123127
await oscillator.ConnectAsync(keyboardMain);
124-
await keyboardMain.ConnectAsync(mainNode!);
128+
await keyboardMain.ConnectAsync(compressor!);
125129
await oscillator.StartAsync();
126130

127131
var time = await context.GetCurrentTimeAsync();

0 commit comments

Comments
 (0)