Sound

Sound

new Sound(frequency, oscillatorType)

Source:
Construct a new Sound. Optionally set the frequency and the oscillator type.
Parameters:
Name Type Description
frequency number | string Either a number (Hertz) or note ("C#4" for middle C Sharp)
oscillatorType string several options basic types: "sine", "triangle", "square", "sawtooth" any basic type can be prefixed with "fat", "am" or "fm", ie "fatsawtooth" any basic type can be suffixed with a number ie "4" for the number of partials ie "square4" special types: "pwm", "pulse" drum instrument: "drum" cymbal instrument: "metal" https://tonejs.github.io/docs/13.8.25/OmniOscillator
AudioContext context

Methods

disconnect()

Source:
Disconnect the sound from the AudioNode. This generally should not be used by students. We use it to force stop sounds that are playing when the "STOP" button is pressed in the editor.

getFrequency()

Source:
Get the Sound's frequency
Returns:
The Sound's frequency

getOscillatorType()

Source:
Get the Sound's oscillator type
Returns:
a String representing the oscillator type

getVolume()

Source:
Get the Sound's volume
Returns:
the volume

play()

Source:
Play the sound indefinitely

playFor(duration)

Source:
Play the sound for a given duration.
Parameters:
Name Type Description
duration string duration in one of several formats, mainly: number: the number of seconds to play the sound for. "2" for 2 seconds "1.5" for 1.5 seconds OR notation: Describes time in BPM and time signature relative values. "4n" for quarter note "8t" for eigth note triplet, "2m" for 2 measures "8n." for dotted eighth note

setEffect(effectName, effectValue)

Source:
Add an effect to this sound
Parameters:
Name Type Description
effectName String the name of the prepackaged effect, ie "reverb"
effectValue float value from 0 to 1 defining how heavily the effect applies

setFrequency(frequency)

Source:
Set the Sound's frequency
Parameters:
Name Type Description
frequency Either a number (Hertz) or note ("C#4" for middle C Sharp)

setOscillatorType(oscillatorType)

Source:
Set the Sound's oscillator type
Parameters:
Name Type Description
oscillatorType string several options basic types: "sine", "triangle", "square", "sawtooth" any basic type can be prefixed with "fat", "am" or "fm", ie "fatsawtooth" any basic type can be suffixed with a number ie "4" for the number of partials ie "square4" special types: "pwm", "pulse" drum instrument: "drum" cymbal instrument: "metal" https://tonejs.github.io/docs/13.8.25/OmniOscillator

setVolume(volume)

Source:
Set the Sound's volume
Parameters:
Name Type Description
volume float the volume in decibels

stop()

Source:
Stop playing the sound immediately.