Sound.waveform

From MiniScript Wiki
Revision as of 17:29, 17 April 2021 by SicariusVelox (talk | contribs) (Initial page creation)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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.)

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

Waveform sinewave.png

the following example plays a 120hz sinewave

sine = new Sound
sine.init 1, 120, 1, Sound.sineWave
sine.play

Sound.triangleWave

Waveform triangleWave.png

the following example plays a 120hz triangleWave

triangle = new Sound
triangle.init 1, 120, 1, Sound.triangleWave
triangle.play

Sound.sawtoothWave

Waveform sawtoothWave.png

the following example plays a 120hz sawtoothWave

sawtooth = new Sound
sawtooth.init 1, 120, 1, Sound.sawtoothWave
sawtooth.play

Sound.squareWave

Waveform squareWave.png

the following example plays a 120hz squareWave

square = new Sound
square.init 1, 120, 1, Sound.squareWave
square.play

Sound.noiseWave

Waveform noiseWave.png

the following example plays a 120hz noiseWave

noise = new Sound
noise.init 1, 120, 1, Sound.noiseWave
noise.play

Using a custom waveform

Waveform trapezoidWave.png

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