Skip to content

Latest commit

 

History

History
174 lines (156 loc) · 5.16 KB

File metadata and controls

174 lines (156 loc) · 5.16 KB
title p5.Oscillator
module p5.sound
submodule p5.sound
file lib/addons/p5.sound.js
description <p>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).</p> <p>Set the type of oscillation with setType(), or by instantiating a specific oscillator: <a href="/reference/p5.sound/p5.SinOsc/">p5.SinOsc</a>, <a href="/reference/p5.sound/p5.TriOsc/">p5.TriOsc</a>, <a href="/reference/p5.sound/p5.SqrOsc/">p5.SqrOsc</a>, or <a href="/reference/p5.sound/p5.SawOsc/">p5.SawOsc</a>. </p>
line 4060
isConstructor true
params
name description type optional
freq
<p>frequency defaults to 440Hz</p>
Number
true
name description type optional
type
<p>type of oscillator. Options: 'sine' (default), 'triangle', 'sawtooth', 'square'</p>
String
true
example
<div><code> let osc, playing, freq, amp; function setup() { let cnv = createCanvas(100, 100); cnv.mousePressed(playOscillator); osc = new p5.Oscillator('sine'); } function draw() { background(220) freq = constrain(map(mouseX, 0, width, 100, 500), 100, 500); amp = constrain(map(mouseY, height, 0, 0, 1), 0, 1); text('tap to play', 20, 20); text('freq: ' + freq, 20, 40); text('amp: ' + amp, 20, 60); if (playing) { // smooth the transitions by 0.1 seconds osc.freq(freq, 0.1); osc.amp(amp, 0.1); } } function playOscillator() { // starting an oscillator on a user gesture will enable audio // in browsers that have a strict autoplay policy. // See also: userStartAudio(); osc.start(); playing = true; } function mouseReleased() { // ramp amplitude to 0 over 0.5 seconds osc.amp(0, 0.5); playing = false; } </code> </div>
methods
start stop amp getAmp freq getFreq setType getType connect disconnect pan getPan phase add mult scale
description path
<p>Start an oscillator.</p> <p>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: <code>userStartAudio()</code>.</p>
p5.Oscillator/start
description path
<p>Stop an oscillator. Accepts an optional parameter to determine how long (in seconds from now) until the oscillator stops.</p>
p5.Oscillator/stop
description path
<p>Set the amplitude between 0 and 1.0. Or, pass in an object such as an oscillator to modulate amplitude with an audio signal.</p>
p5.Oscillator/amp
description path
<p>Returns the value of output gain</p>
p5.Oscillator/getAmp
description path
<p>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.</p>
p5.Oscillator/freq
description path
<p>Returns the value of frequency of oscillator</p>
p5.Oscillator/getFreq
description path
<p>Set type to 'sine', 'triangle', 'sawtooth' or 'square'.</p>
p5.Oscillator/setType
description path
<p>Returns current type of oscillator eg. 'sine', 'triangle', 'sawtooth' or 'square'.</p>
p5.Oscillator/getType
description path
<p>Connect to a p5.sound / Web Audio object.</p>
p5.Oscillator/connect
description path
<p>Disconnect all outputs</p>
p5.Oscillator/disconnect
description path
<p>Pan between Left (-1) and Right (1)</p>
p5.Oscillator/pan
description path
<p>Returns the current value of panPosition , between Left (-1) and Right (1)</p>
p5.Oscillator/getPan
description path
<p>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.</p>
p5.Oscillator/phase
description path
<p>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.</p>
p5.Oscillator/add
description path
<p>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.</p>
p5.Oscillator/mult
description path
<p>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.</p>
p5.Oscillator/scale
chainable false

p5.Oscillator