Skip to content

Commit 966e80f

Browse files
committed
Introduction of the AudioDestinationNode module
AudioDestinationNode is a subclass of AudioNode with no constructor and no extra method. The only effective difference is the `maxChannelCount` instance property, which is already covered by the `audioDestinationNode` type in the `WebAudioAPI` module. This PR allows for `AudioContext`'s `destination` property to be used like an `AudioNode`, especially being connected to by other nodes since this is the only way to output audio to speakers. For more information, check [MDN](https://developer.mozilla.org/en-US/docs/Web/API/AudioDestinationNode)
1 parent c909d30 commit 966e80f

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

src/WebAudioAPI/AudioDestinationNode.js

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
open WebAudioAPI
2+
3+
include AudioNode.Impl({
4+
type t = audioDestinationNode
5+
})

tests/WebAudioAPI/AudioDestinationNode__.test.js

+32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
open WebAudioAPI
2+
3+
let ctx = AudioContext.make()
4+
5+
let destinationNode = ctx.destination->AudioDestinationNode.asAudioNode
6+
let context = AudioContext.asBaseAudioContext(ctx)
7+
8+
let osc = OscillatorNode.make(
9+
~context,
10+
~options={
11+
type_: Sine,
12+
frequency: 440.0,
13+
},
14+
)
15+
let gain = GainNode.make(
16+
~context,
17+
~options={
18+
gain: 0.3,
19+
},
20+
)
21+
let _ = gain->GainNode.connect(~destinationNode)
22+
let _ =
23+
osc
24+
->OscillatorNode.asAudioScheduledSourceNode
25+
->AudioScheduledSourceNode.connect(~destinationNode=gain->GainNode.asAudioNode)
26+
27+
osc->OscillatorNode.start

0 commit comments

Comments
 (0)