Skip to content

Commit 6a58e0d

Browse files
committed
p5.sound update, not ready for p5.Metro
1 parent afceb48 commit 6a58e0d

File tree

1 file changed

+2
-56
lines changed

1 file changed

+2
-56
lines changed

lib/addons/p5.sound.js

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4963,64 +4963,10 @@ soundRecorder = function () {
49634963
}
49644964
}
49654965
}(sndcore, master);
4966-
var metro;
4967-
metro = function () {
4968-
'use strict';
4969-
var p5sound = master;
4970-
var ac = p5sound.audiocontext;
4971-
var upTick = false;
4972-
var tatums = 4;
4973-
// lowest possible division of a beat
4974-
// Oscillator + Script Processor to keep time.
4975-
// inspired by Tone.js library's Transport (MIT license, Yotam Mann)
4976-
// https://github.com/TONEnoTONE/Tone.js/blob/master/Tone/core/Transport.js
4977-
p5.Metro = function () {
4978-
this.metroTicks = 0;
4979-
/**
4980-
* watch this.oscillator for timing ticks
4981-
*/
4982-
this._jsNode = p5sound.audiocontext.createScriptProcessor(this.bufferSize, 1, 1);
4983-
this._jsNode.onaudioprocess = this._processBuffer.bind(this);
4984-
this._jsNode.connect(p5.soundOut._silentNode);
4985-
this.oscillator = ac.createOscillator();
4986-
this.oscillator.type = 'square';
4987-
this.oscillator.connect(this._jsNode);
4988-
this.oscillator.start();
4989-
this.oscillator.frequency.value = 1;
4990-
this.lastTick = 0;
4991-
};
4992-
p5.Metro.prototype._processBuffer = function (event) {
4993-
var now = ac.currentTime;
4994-
var incomingBuffer = event.inputBuffer.getChannelData(0);
4995-
var bufferSize = this._jsNode.bufferSize;
4996-
for (var i = 0; i < bufferSize; i++) {
4997-
var sample = incomingBuffer[i];
4998-
if (sample > 0 && !upTick) {
4999-
upTick = true;
5000-
this._processTick(now + i / ac.sampleRate);
5001-
} else if (sample < 0 && upTick) {
5002-
upTick = false;
5003-
}
5004-
}
5005-
};
5006-
p5.Metro.prototype._processTick = function (tickTime) {
5007-
this.metroTicks += 1;
5008-
console.log('interval: ' + (tickTime - this.lastTick));
5009-
this.lastTick = tickTime;
5010-
};
5011-
p5.Metro.prototype.setBPM = function (bpm, rampTime) {
5012-
// var tatumFreq = this.secondsToFrequency(this.notationToSeconds(tatum.toString() + "n", bpm, transportTimeSignature));
5013-
var freq = bpm / 60 / 2 * tatums;
5014-
var ramp = rampTime || 0;
5015-
this.oscillator.frequency.linearRampToValueAtTime(freq, ramp);
5016-
};
5017-
p5.Metro.prototype.getBPM = function (tempo) {
5018-
return this.oscillator.frequency.value * 60 * 2;
5019-
};
5020-
}(master);
50214966
var src_app;
50224967
src_app = function () {
50234968
'use strict';
50244969
var p5SOUND = sndcore;
4970+
// require('metro');
50254971
return p5SOUND;
5026-
}(sndcore, master, helpers, soundfile, amplitude, fft, signal, oscillator, env, pulse, noise, audioin, filter, delay, reverb, looper, soundRecorder, metro);
4972+
}(sndcore, master, helpers, soundfile, amplitude, fft, signal, oscillator, env, pulse, noise, audioin, filter, delay, reverb, looper, soundRecorder);

0 commit comments

Comments
 (0)