Skip to content

Commit

Permalink
Fix NaN values crashing the audio system
Browse files Browse the repository at this point in the history
Render NaN frequencies without a metric prefix.
  • Loading branch information
frostburn committed Apr 2, 2024
1 parent 924c84a commit 1067b36
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ const midiOut = computed(() => new MidiOut(midi.output as Output, midi.outputCha
function sendNoteOn(frequency: number, rawAttack: number) {
frequency = clamp(-24000, 24000, frequency)
if (isNaN(frequency)) {
frequency = 0
}
const midiOff = midiOut.value.sendNoteOn(frequency, rawAttack)
if (audio.synth === null || audio.virtualSynth === null) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export function formatHertz(frequency: number, fractionDigits = 3) {
}

// Too large. Use scientific notation.
if (magnitude > 1e34) {
if (magnitude > 1e34 || isNaN(magnitude)) {
return formatExponential(frequency) + 'Hz'
}

Expand Down

0 comments on commit 1067b36

Please sign in to comment.