Skip to content

Commit 1db3db8

Browse files
(Gsoc'21)🔨Fixes some bugs in polysynth.js
1 parent 9092070 commit 1db3db8

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/polysynth.js

Lines changed: 4 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,7 @@ class PolySynth {
389387
this.notes[n].dispose();
390388
delete this.notes[n];
391389
}
390+
this._newest = 0;
392391
return;
393392
}
394393

@@ -400,10 +399,7 @@ class PolySynth {
400399
} else {
401400
//Find the scheduled change in this._voicesInUse that will be previous to this new note
402401
//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-
);
402+
var previousVal = Math.max(~~this._voicesInUse.getValueAtTime(t), 1);
407403
this._voicesInUse.setValueAtTime(previousVal - 1, t);
408404
//Then update all scheduled values that follow to decrease by 1 but never go below 0
409405
if (previousVal > 0) {

0 commit comments

Comments
 (0)