|
8 | 8 | <PageTitle>WebAudio - Panning</PageTitle> |
9 | 9 | <h2>Panning</h2> |
10 | 10 |
|
11 | | -<p>On this page we present a view of two speakers directed towards the listener. |
| 11 | +<p> |
| 12 | + On this page we present a view of two speakers directed towards the listener. |
12 | 13 | The speakers can then be moved using a <code>PannerNode</code> in 3D space and be directed towards another orientation. |
13 | | - To simplify this demo we have limited ourselves to only edit the position in 2 dimensions</p> |
| 14 | + To simplify this demo we have limited ourselves to only edit the position in 2 dimensions |
| 15 | +</p> |
14 | 16 |
|
15 | 17 | @if (oscillatorDark is null) |
16 | 18 | { |
|
23 | 25 | <br /> |
24 | 26 | <GainSlider GainNode="gainNode" /> |
25 | 27 |
|
26 | | -<div style="height: 40vh;"> |
| 28 | +<div style="height: 30vh;"> |
27 | 29 | <SVGEditor @ref=sVGEditor |
28 | | - Input=@input |
29 | | - InputUpdated="(string s) => { input = s; StateHasChanged(); }" |
30 | | - SupportedElements="supportedElements" |
31 | | - InputRendered="EditorLoaded" /> |
| 30 | + Input=@input |
| 31 | + InputUpdated="(string s) => { input = s; StateHasChanged(); }" |
| 32 | + SupportedElements="supportedElements" |
| 33 | + InputRendered="EditorLoaded" /> |
32 | 34 | </div> |
33 | 35 |
|
34 | 36 | <h3>Left speaker</h3> |
35 | | -<Plot Data="leftTimeDomainMeasurements" /> |
| 37 | +<Plot Height=100 Data="leftTimeDomainMeasurements" /> |
36 | 38 |
|
37 | 39 | <h3>Right speaker</h3> |
38 | | -<Plot Data="rightTimeDomainMeasurements" /> |
| 40 | +<Plot Height=100 Data="rightTimeDomainMeasurements" /> |
39 | 41 |
|
40 | 42 | @code { |
41 | 43 | AudioContext context = default!; |
|
68 | 70 | { |
69 | 71 | ConeInnerAngle = 20, |
70 | 72 | ConeOuterAngle = 40, |
| 73 | + MaxDistance = 10 |
71 | 74 | }); |
72 | 75 | pannerDark = await PannerNode.CreateAsync(JSRuntime, context, new() |
73 | 76 | { |
74 | 77 | ConeInnerAngle = 20, |
75 | 78 | ConeOuterAngle = 40, |
| 79 | + MaxDistance = 10 |
76 | 80 | }); |
| 81 | + |
77 | 82 | gainNode = await GainNode.CreateAsync(JSRuntime, context, new() { Gain = 0.1f }); |
78 | 83 | AudioDestinationNode destination = await context.GetDestinationAsync(); |
79 | 84 |
|
|
91 | 96 | await gainNode.ConnectAsync(destination); |
92 | 97 |
|
93 | 98 | int bufferLength = (int)await leftAnalyzerNode.GetFrequencyBinCountAsync(); |
94 | | - await using var timeDomainDataArray = await Uint8Array.CreateAsync(JSRuntime, bufferLength); |
| 99 | + await using var leftTimeDomainDataArray = await Uint8Array.CreateAsync(JSRuntime, bufferLength); |
| 100 | + await using var rightTimeDomainDataArray = await Uint8Array.CreateAsync(JSRuntime, bufferLength); |
95 | 101 |
|
96 | | - while(true) |
| 102 | + while (true) |
97 | 103 | { |
98 | 104 | await Task.Delay(500); |
99 | 105 |
|
100 | | - await leftAnalyzerNode.GetByteTimeDomainDataAsync(timeDomainDataArray); |
101 | | - leftTimeDomainMeasurements = await timeDomainDataArray.GetAsArrayAsync(); |
| 106 | + await leftAnalyzerNode.GetByteTimeDomainDataAsync(leftTimeDomainDataArray); |
| 107 | + leftTimeDomainMeasurements = await leftTimeDomainDataArray.GetAsArrayAsync(); |
102 | 108 |
|
103 | | - await rightAnalyzerNode.GetByteTimeDomainDataAsync(timeDomainDataArray); |
104 | | - rightTimeDomainMeasurements = await timeDomainDataArray.GetAsArrayAsync(); |
| 109 | + await rightAnalyzerNode.GetByteTimeDomainDataAsync(rightTimeDomainDataArray); |
| 110 | + rightTimeDomainMeasurements = await rightTimeDomainDataArray.GetAsArrayAsync(); |
105 | 111 |
|
106 | | - await Task.Delay(50); |
| 112 | + await Task.Delay(10); |
107 | 113 | StateHasChanged(); |
108 | 114 | } |
109 | 115 | } |
|
0 commit comments