Skip to content

Commit

Permalink
loop fix
Browse files Browse the repository at this point in the history
  • Loading branch information
spessasus committed Sep 19, 2023
1 parent 0afe2aa commit eb41c7f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/spessasynth_lib/sequencer/sequencer.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ export class Sequencer {
this.setTimeTicks(this.midiData.loop.start);
return;
}
else if(this.eventIndex >= this.events.length || current > this.duration)
else if(this.eventIndex >= this.events.length || current > this.duration + 1)
{
this.pause();
// if(this.loop) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,45 @@ class ChannelProcessor extends AudioWorkletProcessor {
const panLeft = Math.cos(HALF_PI * pan);
const panRight = Math.sin(HALF_PI * pan);


// LOWPASS
const filterQ = getModulated(voice, generatorTypes.initialFilterQ, this.midiControllers) - 3.01; // polyphone????
const filterQgain = Math.pow(10, filterQ / 20);
const filterFcHz = absCentsToHz(getModulated(voice, generatorTypes.initialFilterFc, this.midiControllers));
// calculate coefficients
const theta = 2 * Math.PI * filterFcHz / sampleRate;
let a0, a1, a2, b1, b2;
if (filterQgain <= 0)
{
a0 = 1;
a1 = 0;
a2 = 0;
b1 = 0;
b2 = 0;
}
else
{
const dTmp = Math.sin(theta) / (2 * filterQgain);
if (dTmp <= -1.0)
{
a0 = 1;
a1 = 0;
a2 = 0;
b1 = 0;
b2 = 0;
}
else
{
const beta = 0.5 * (1 - dTmp) / (1 + dTmp);
const gamma = (0.5 + beta) * Math.cos(theta);
a0 = (0.5 + beta - gamma) / 2;
a1 = 2 * a0;
a2 = a0;
b1 = -2 * gamma;
b2 = 2 * beta;
}
}

// SYNTHESIS
let actualTime = currentTime;
for (let outputSampleIndex = 0; outputSampleIndex < outputLeft.length; outputSampleIndex++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* startTime: number,
* midiNote: number,
* releaseStartTime: number,
* targetKey: number,
* targetKey: number
* }} WorkletVoice
*/

Expand Down Expand Up @@ -363,7 +363,7 @@ export class WorkletChannel {
startTime: this.ctx.currentTime,
isInRelease: false,
releaseStartTime: 0,
targetKey: targetKey
targetKey: targetKey,
};

});
Expand Down

0 comments on commit eb41c7f

Please sign in to comment.