Skip to content

Commit dd82572

Browse files
committed
seconds mode interval not affected by bpm and time signature
1 parent 157eee0 commit dd82572

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

examples/Gymnopedia.mp3

-3.22 MB
Binary file not shown.

examples/sound_loop/sketch.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,21 @@ function setup() {
3131
count2 = 0;
3232
c = color(50);
3333
d = color(50);
34-
// create a part with 8 spaces, where each space represents 1/16th note (default)
35-
looper1 = new p5.SoundLoop(function(time){
36-
click.play();
37-
console.log('looper1 '+this.clock._nextTick);
34+
35+
//the looper's callback is passed the timeFromNow
36+
//this value should be used as a reference point from
37+
//which to schedule sounds
38+
39+
looper1 = new p5.SoundLoop(function(timeFromNow){
40+
click.play(timeFromNow);
3841
}, 1);
3942

40-
looper2 = new p5.SoundLoop(function(time){
41-
42-
beatbox.play();
43-
// console.log(this.clock.ticks);
44-
console.log('looper2 ' + this.clock._nextTick);
43+
looper2 = new p5.SoundLoop(function(timeFromNow){
44+
beatbox.play(timeFromNow);
4545
}, "16n");
4646

47-
looper1.start();
48-
49-
// looper1.start();
50-
47+
//start the loops together
48+
looper1.syncedStart(looper2);
5149
}
5250

5351

src/soundLoop.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ define(function (require) {
3030
this.clock = new Clock({
3131
'callback' : function(time) {
3232
var timeFromNow = time - p5sound.audiocontext.currentTime;
33+
//Do not initiate the callback if timeFromNow is < 0
34+
//This ususually occurs for a few milliseconds when the page
35+
//is not fully loaded
3336
if (timeFromNow > 0) {self.callback(timeFromNow);}
3437
},
3538
'frequency' : this._calcFreq()
@@ -111,7 +114,6 @@ define(function (require) {
111114
};
112115

113116

114-
115117
/**
116118
* Updates frequency value, reflected in next callback
117119
* @private
@@ -128,10 +130,13 @@ define(function (require) {
128130
* @return {Number} new clock frequency value
129131
*/
130132
p5.SoundLoop.prototype._calcFreq = function() {
133+
//Seconds mode, bpm / timesignature has no effect
131134
if (typeof this._interval === 'number') {
132135
this.musicalTimeMode = false;
133-
return this._bpm / 60 / this._interval * (this._timeSignature / 4);
134-
} else if (typeof this._interval === 'string') {
136+
return 1 / this._interval;
137+
}
138+
//Musical timing mode, calculate interval based bpm, interval,and time signature
139+
else if (typeof this._interval === 'string') {
135140
this.musicalTimeMode = true;
136141
return this._bpm / 60 / this._convertNotation(this._interval) * (this._timeSignature / 4);
137142
}

0 commit comments

Comments
 (0)