Skip to content

Commit 6cc8dda

Browse files
Merge branch 'main' of https://github.com/processing/p5.js-sound into adding-new-tests-for-uncovered-files
1 parent 5c8f5ff commit 6cc8dda

16 files changed

+885
-539
lines changed

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
},
3636
"parserOptions": {
37-
"ecmaVersion": 6,
37+
"ecmaVersion": 8,
3838
"sourceType": "module",
3939
"allowImportExportEverywhere": true
4040
}

lib/p5.sound.js

Lines changed: 809 additions & 463 deletions
Large diffs are not rendered by default.

lib/p5.sound.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/p5.sound.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/p5.sound.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/looper.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,9 @@ class Score {
392392
var thisScore = this;
393393
for (var i in arguments) {
394394
this.parts[i] = arguments[i];
395-
if (i > 0) this.parts[i - 1].nextPart = this.parts[i];
395+
if (i > 0) {
396+
this.parts[i - 1].nextPart = this.parts[i];
397+
}
396398
this.parts[i].onended = function () {
397399
thisScore.resetPart(i);
398400
playNextPart(thisScore);

src/polysynth.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import p5sound from './main';
22
import TimelineSignal from 'Tone/signal/TimelineSignal.js';
3-
import { noteToFreq, freqToMidi } from './helpers';
3+
import { noteToFreq } from './helpers';
44

55
/**
66
* An AudioVoice is used as a single voice for sound synthesis.
@@ -274,9 +274,7 @@ class PolySynth {
274274
else {
275275
currentVoice = this._oldest;
276276

277-
oldestNote = freqToMidi(
278-
this.audiovoices[this._oldest].oscillator.freq().value
279-
);
277+
let oldestNote = this.audiovoices[this._oldest].oscillator.freq().value;
280278
this.noteRelease(oldestNote);
281279
this._oldest = (this._oldest + 1) % (this.maxVoices - 1);
282280
}
@@ -389,6 +387,8 @@ class PolySynth {
389387
this.notes[n].dispose();
390388
delete this.notes[n];
391389
}
390+
this._newest = 0;
391+
this._oldest = 0;
392392
return;
393393
}
394394

@@ -400,10 +400,7 @@ class PolySynth {
400400
} else {
401401
//Find the scheduled change in this._voicesInUse that will be previous to this new note
402402
//subtract 1 and schedule this value at time 't', when this note will stop playing
403-
var previousVal = Math.max(
404-
~~this._voicesInUse.getValueAtTime(t).value,
405-
1
406-
);
403+
var previousVal = Math.max(~~this._voicesInUse.getValueAtTime(t), 1);
407404
this._voicesInUse.setValueAtTime(previousVal - 1, t);
408405
//Then update all scheduled values that follow to decrease by 1 but never go below 0
409406
if (previousVal > 0) {

src/reverb.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,7 @@ class Reverb extends Effect {
103103
*/
104104
process(src, seconds, decayRate, reverse) {
105105
src.connect(this.input);
106-
var rebuild = false;
107-
if (seconds) {
108-
this._seconds = seconds;
109-
rebuild = true;
110-
}
111-
if (decayRate) {
112-
this._decay = decayRate;
113-
}
114-
if (reverse) {
115-
this._reverse = reverse;
116-
}
117-
if (rebuild) {
118-
this._buildImpulse();
119-
}
106+
this.set(seconds, decayRate, reverse);
120107
}
121108

122109
/**

src/soundRecorder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class SoundRecorder {
9191
this._inputChannels = 2;
9292
this._outputChannels = 2; // stereo output, even if input is mono
9393

94-
const workletBufferSize = safeBufferSize(1024);
94+
const workletBufferSize = (this.bufferSize = safeBufferSize(1024));
9595

9696
this._workletNode = new AudioWorkletNode(
9797
ac,

src/soundfile.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -515,11 +515,11 @@ class SoundFile {
515515
* </code></div>
516516
*/
517517
playMode(str) {
518-
var s = str.toLowerCase();
518+
var s = str.toLowerCase().trim();
519519

520520
// if restart, stop all other sounds from playing
521521
if (s === 'restart' && this.buffer && this.bufferSourceNode) {
522-
for (var i = 0; i < this.bufferSourceNodes.length - 1; i++) {
522+
for (var i = 0; i < this.bufferSourceNodes.length; i++) {
523523
var now = p5sound.audiocontext.currentTime;
524524
this.bufferSourceNodes[i].stop(now);
525525
}
@@ -715,10 +715,9 @@ class SoundFile {
715715
this._paused = false;
716716
} else if (this.buffer && this.bufferSourceNode) {
717717
var now = p5sound.audiocontext.currentTime;
718-
var t = time || 0;
719718
this.pauseTime = 0;
720-
this.bufferSourceNode.stop(now + t);
721-
this._counterNode.stop(now + t);
719+
this.bufferSourceNode.stop(now + time);
720+
this._counterNode.stop(now + time);
722721
this._playing = false;
723722
this._paused = false;
724723
}
@@ -999,7 +998,7 @@ class SoundFile {
999998
* @return {Number} [channels]
1000999
*/
10011000
channels() {
1002-
return this.buffer.numberOfChannels;
1001+
if (this.buffer) return this.buffer.numberOfChannels;
10031002
}
10041003

10051004
/**
@@ -1010,7 +1009,7 @@ class SoundFile {
10101009
* @return {Number} [sampleRate]
10111010
*/
10121011
sampleRate() {
1013-
return this.buffer.sampleRate;
1012+
if (this.buffer) return this.buffer.sampleRate;
10141013
}
10151014

10161015
/**
@@ -1022,7 +1021,7 @@ class SoundFile {
10221021
* @return {Number} [sampleCount]
10231022
*/
10241023
frames() {
1025-
return this.buffer.length;
1024+
if (this.buffer) return this.buffer.length;
10261025
}
10271026

10281027
/**
@@ -1045,7 +1044,7 @@ class SoundFile {
10451044
if (this.buffer) {
10461045
// set length to window's width if no length is provided
10471046
if (!length) {
1048-
length = window.width * 5;
1047+
length = window.innerWidth * 5;
10491048
}
10501049
if (this.buffer) {
10511050
var buffer = this.buffer;

0 commit comments

Comments
 (0)