Skip to content

Sources

Sources are audio-producing nodes that generate or play back sound. Unlike instruments, they don't respond to note triggers.

Oscillator

Generates a periodic waveform. Supports sine, square, sawtooth, and triangle types.

1let osc = Oscillator.make()
2let osc2 = Oscillator.makeWithOptions({
3 frequency: 440.0,
4 "type": "sawtooth",
5 detune: 0.0,
6 phase: 0.0,
7 volume: -12.0,
8})
9let osc3 = Oscillator.makeWithFreq(440.0, "sine")
10
11osc->Oscillator.asAudioNode->AudioNode.toDestination
12
13// Start/stop
14osc->Oscillator.start()
15osc->Oscillator.stop()
16osc->Oscillator.restart()
17
18// Properties
19osc->Oscillator.frequency // Param.t
20osc->Oscillator.detune // Param.t
21osc->Oscillator.volume // Param.t
22osc->Oscillator.getType() // oscillatorType
23osc->Oscillator.setType("square")
24osc->Oscillator.phase // degrees
25osc->Oscillator.partialCount // int
26osc->Oscillator.partials // array<float>
27
28// Frequency sync
29osc->Oscillator.syncFrequency()
30osc->Oscillator.unsyncFrequency()

Player

Plays an audio file. Supports loading from URL and various playback controls.

1let player = Player.make("path/to/audio.mp3")
2let player2 = Player.makeWithOptions({
3 url: "path/to/audio.mp3",
4 loop: true,
5 playbackRate: 1.0,
6 autostart: false,
7})
8
9player->Player.asAudioNode->AudioNode.toDestination
10
11// Playback
12player->Player.start()
13player->Player.stop()
14player->Player.restart()
15player->Player.seek("0:2:0")
16
17// Properties
18player->Player.loop // bool
19player->Player.setLoop(true)
20player->Player.playbackRate // Param.t
21player->Player.reverse // bool
22player->Player.setReverse(true)
23player->Player.loaded // bool
24player->Player.buffer // ToneAudioBuffer.t

Noise

Generates noise. Supports white, pink, and brown noise types.

1let noise = Noise.make()
2let noise2 = Noise.makeWithType("pink")
3let noise3 = Noise.makeWithOptions({
4 "type": "brown",
5 volume: -20.0,
6 playbackRate: 1.0,
7})
8
9noise->Noise.asAudioNode->AudioNode.toDestination
10noise->Noise.start()
11noise->Noise.stop()
12
13noise->Noise.getType() // "white" | "pink" | "brown"
14noise->Noise.setType("pink")
Was this page helpful?