Sound.waveform
Sound.waveform
defines the waveform that repeats based on the Sound.freq. It can be set a value or list of values typically from -1 to 1 (it's possible to add values outside of this range but it may lead to clipping or incorrect volume expectations.)
Contents
Predefined Waveforms
the following table shows predefined waveforms included in the Sound class.
Waveform | Description |
---|---|
Sound.sineWave | represents a sine wave (pure tone) |
Sound.triangleWave | represents a triangle wave (almost pure) |
Sound.sawtoothWave | represents a sawtooth wave (slightly "buzzier") |
Sound.squareWave | represents a square wave (most buzzy/retro sound) |
Sound.noiseWave | creates a pseudo-random "static" waveform |
Examples
The following examples show basic uses and visual representations of each waveform. waveform images unless specified otherwise use a freq of 1 and duration of 5 to show clarity.
Sound.sineWave
the following example plays a 120hz sinewave
sine = new Sound
sine.init 1, 120, 1, Sound.sineWave
sine.play
Sound.triangleWave
the following example plays a 120hz triangleWave
triangle = new Sound
triangle.init 1, 120, 1, Sound.triangleWave
triangle.play
Sound.sawtoothWave
the following example plays a 120hz sawtoothWave
sawtooth = new Sound
sawtooth.init 1, 120, 1, Sound.sawtoothWave
sawtooth.play
Sound.squareWave
the following example plays a 120hz squareWave
square = new Sound
square.init 1, 120, 1, Sound.squareWave
square.play
Sound.noiseWave
the following example plays a 120hz noiseWave
noise = new Sound
noise.init 1, 120, 1, Sound.noiseWave
noise.play
Using a custom waveform
the following example shows how to use a custom waveform.
trapezoidWave = [0,1,1,1,0]
trapezoid = new Sound
trapezoid.init 1, 120, 1, trapezoidWave
trapezoid.play
See also: Sound.init