Reference p5.Oscillator

p5.Oscillator

Creates a signal that oscillates between -1.0 and 1.0. By default, the oscillation takes the form of a sinusoidal shape ('sine'). Additional types include 'triangle', 'sawtooth' and 'square'. The frequency defaults to 440 oscillations per second (440Hz, equal to the pitch of an 'A' note).

Set the type of oscillation with setType(), or by instantiating a specific oscillator: p5.SinOsc, p5.TriOsc, p5.SqrOsc, or p5.SawOsc.

Examples

Syntax

p5.Oscillator([freq], [type])

Parameters

freq

frequency defaults to 440Hz

type

type of oscillator. Options: 'sine' (default), 'triangle', 'sawtooth', 'square'

Methods

start

Start an oscillator.

Starting an oscillator on a user gesture will enable audio in browsers that have a strict autoplay policy, including Chrome and most mobile devices. See also: userStartAudio().

stop

Stop an oscillator. Accepts an optional parameter to determine how long (in seconds from now) until the oscillator stops.

amp

Set the amplitude between 0 and 1.0. Or, pass in an object such as an oscillator to modulate amplitude with an audio signal.

getAmp

Returns the value of output gain

freq

Set frequency of an oscillator to a value. Or, pass in an object such as an oscillator to modulate the frequency with an audio signal.

getFreq

Returns the value of frequency of oscillator

setType

Set type to 'sine', 'triangle', 'sawtooth' or 'square'.

getType

Returns current type of oscillator eg. 'sine', 'triangle', 'sawtooth' or 'square'.

connect

Connect to a p5.sound / Web Audio object.

disconnect

Disconnect all outputs

pan

Pan between Left (-1) and Right (1)

getPan

Returns the current value of panPosition , between Left (-1) and Right (1)

phase

Set the phase of an oscillator between 0.0 and 1.0. In this implementation, phase is a delay time based on the oscillator's current frequency.

add

Add a value to the p5.Oscillator's output amplitude, and return the oscillator. Calling this method again will override the initial add() with a new value.

mult

Multiply the p5.Oscillator's output amplitude by a fixed value (i.e. turn it up!). Calling this method again will override the initial mult() with a new value.

scale

Scale this oscillator's amplitude values to a given range, and return the oscillator. Calling this method again will override the initial scale() with new values.

Notice any errors or typos? Please let us know. Please feel free to edit lib/addons/p5.sound.js and open a pull request!

Related References