Generates a consistent tone, sometimes referred to as a pitch. A building block of sound design, this oscillator can produce the following "waveforms": Sine, Triangle, Square and Sawtooth. A repeating waveform produces a perceived pitch beginning at around 20 times a second, with additional textural or harmonic content dependent on the type of waveform you choose.
Examples
Syntax
p5.Oscillator([frequency], [type])
Parameters
frequency
Number: defaults to 440Hz, or 440 'cycles per second.' represents the pitch of the tone. Acts as a 'control-rate' or 'low frequency oscillator' (LFO) at values between 0 and 20. Creates a tone between 20 and about 20,000 Hertz depending on how well you can hear!
type
String: type of waveform: 'sine' (default), 'triangle', 'sawtooth', 'square'
Methods
freq
Adjusts the frequency of the oscillator. Frequency is measured int Hertz (Hz) and determines the amount of cycles a waveform (square, sawtooth, etc...) will repeat in a second. The amount of repetitions will result in a change in perceived 'pitch.' You can lookup corresponding frequency values for 'notes' if you would like to play a scale. For example, 'middle C' on the keyboard has a frequency of 261.63 Hz.
phase
Adjusts the phase of the oscillator. Effectively, this changes the starting point of waveform. You might want to adjust the phase of an oscillator in more advanced sound design tasks when layering multiple oscillators to produce a particular instrument or timbre.
setType
Sets the type of the oscillator.
Notice any errors or typos? Please let us know. Please feel free to edit src/sources/Oscillator.js and open a pull request!
Related References
getAudioContext
Get the window's audio context.
setAudioContext
Sets the AudioContext to a specified context to enable cross library compatibility.
userStartAudio
starts audio processing in the window when called from a user interaction (such as mousePressed()).
userStopAudio
stops audio processing in the browser window.