Skip to content

Commit

Permalink
fix oscillator NaN on very, very rare occasion
Browse files Browse the repository at this point in the history
and increase soundfont name before cutoff to 30 (29 actually but shh)
  • Loading branch information
spessasus committed May 19, 2024
1 parent 07497d9 commit 0b53e16
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,19 @@ class ChannelProcessor extends AudioWorkletProcessor {
return;
}
v.sample.end = data.sampleData.length - 1 + v.generators[generatorTypes.endAddrOffset] + (v.generators[generatorTypes.endAddrsCoarseOffset] * 32768);
// calculate for how long the sample has been playing and move the cursor there
v.sample.cursor = (v.sample.playbackStep * sampleRate) * (currentTime - v.startTime);
if(v.sample.loopingMode === 0) // no loop
{
if (v.sample.cursor >= v.sample.end) {
v.finished = true;
}
}
else
{
// go through modulo (adjust cursor if the sample has looped
v.sample.cursor = v.sample.cursor % (v.sample.loopEnd - v.sample.loopStart) + v.sample.loopStart - 1;
}
})

break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function getOscillatorData(voice, sampleData, outputBuffer)
{
for (let i = 0; i < outputBuffer.length; i++) {
// check for loop
while(cur > voice.sample.loopEnd) {
while(cur >= voice.sample.loopEnd) {
cur -= loopLength;
}

Expand All @@ -33,6 +33,13 @@ export function getOscillatorData(voice, sampleData, outputBuffer)
const lower = sampleData[floor];
outputBuffer[i] = (lower + (upper - lower) * fraction);

// commented code because it's probably gonna come handy... (it did like 6 times already :/)
// if(isNaN(outputBuffer[i]))
// {
// console.error(voice, upper, lower, floor, ceil, cur)
// throw "NAN ALERT";
// }

cur += voice.sample.playbackStep * voice.currentTuningCalculated;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/website/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ fetch("soundfonts").then(async r => {
const option = document.createElement("option");
option.value = sf.name;
let displayName = sf.name
if(displayName.length > 20)
if(displayName.length > 29)
{
displayName = displayName.substring(0, 21) + "...";
displayName = displayName.substring(0, 30) + "...";
}
option.innerText = displayName;
sfSelector.appendChild(option);
Expand Down
4 changes: 1 addition & 3 deletions src/website/ui/settings_ui/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,7 @@ export class Settings
const keyboard = this.midiKeyboard;
const keyboardValues = savedSettings.keyboard;

// selected channel
keyboard.selectChannel(keyboardValues.selectedChannel);
keyboardControls.channelSelector.value = keyboardValues.selectedChannel;
// removed selected channel because it's not something you want to save

// keyboard size
keyboard.keyRange = keyboardValues.keyRange;
Expand Down

0 comments on commit 0b53e16

Please sign in to comment.