Skip to content

Commit dd89e7f

Browse files
committed
documentation of amplitude.connect() method
1 parent 1025565 commit dd89e7f

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

src/amplitude.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,60 @@ class Amplitude {
177177
}
178178
}
179179

180+
/**
181+
* Connects the output of a p5.Amplitude object to input of another
182+
* p5.sound object. For example, you may connect a p5.Amplitude to an
183+
* FFT or an Effect.
184+
*
185+
* @method connect
186+
* @for p5.Amplitude
187+
* @param {Object} object Audio object that accepts an input
188+
* @example
189+
* <div><code>
190+
* let sound, amplitude, fft, button;
191+
* function preload(){
192+
* sound = loadSound('assets/beat.mp3');
193+
* }
194+
*
195+
* function setup() {
196+
* let cnv = createCanvas(100,100);
197+
* cnv.mouseClicked(togglePlay);
198+
* amplitude = new p5.Amplitude();
199+
* button = createButton("tap to disconnect amp");
200+
* button.mouseClicked(amp_disconnect);
201+
* button.position(0,110);
202+
* fft = new p5.FFT();
203+
* sound.loop();
204+
* }
205+
*
206+
* function draw() {
207+
* background(220);
208+
* text('tap to play', 20, 20);
209+
* let level = amplitude.getLevel();
210+
* let size = map(level, 0, 1, 0, 200);
211+
* ellipse(width/2, height/2, size, size);
212+
* }
213+
*
214+
* function togglePlay() {
215+
* if (sound.isPlaying()){
216+
* sound.pause();
217+
* }
218+
* else{
219+
* sound.play();
220+
* }
221+
* }
222+
* function amp_disconnect(){
223+
* if (button.html()=="tap to disconnect amp"){
224+
* amplitude.disconnect();
225+
* button.html("tap to connect fft");
226+
* }
227+
* else{
228+
* amplitude.connect(fft);
229+
* button.html("tap to disconnect amp");
230+
* }
231+
* }
232+
* </code></div>
233+
*/
180234
connect(unit) {
181235
if (unit) {
182236
if (unit.hasOwnProperty('input')) {

0 commit comments

Comments
 (0)