- feat: add freq support to gm soundfonts

- refactor: toMidi -> noteToMidi
- refactor: fromMidi -> midiToFreq
This commit is contained in:
Felix Roos 2023-03-23 10:18:24 +01:00
parent 13133583ca
commit ba35a81e9b
10 changed files with 59 additions and 50 deletions

View file

@ -1,4 +1,4 @@
import { logger, toMidi, valueToMidi } from '@strudel.cycles/core';
import { logger, noteToMidi, valueToMidi } from '@strudel.cycles/core';
import { getAudioContext, registerSound } from './index.mjs';
import { getEnvelope } from './helpers.mjs';
@ -34,7 +34,7 @@ export const getSampleBufferSource = async (s, n, note, speed, freq, bank) => {
if (Array.isArray(bank)) {
sampleUrl = bank[n % bank.length];
} else {
const midiDiff = (noteA) => toMidi(noteA) - midi;
const midiDiff = (noteA) => noteToMidi(noteA) - midi;
// object format will expect keys as notes
const closest = Object.keys(bank)
.filter((k) => !k.startsWith('_'))

View file

@ -1,4 +1,4 @@
import { fromMidi, toMidi } from '@strudel.cycles/core';
import { midiToFreq, noteToMidi } from '@strudel.cycles/core';
import { registerSound } from './webaudio.mjs';
import { getOscillator, gainNode, getEnvelope } from './helpers.mjs';
@ -13,11 +13,11 @@ export function registerSynthSounds() {
// with synths, n and note are the same thing
n = note || n || 36;
if (typeof n === 'string') {
n = toMidi(n); // e.g. c3 => 48
n = noteToMidi(n); // e.g. c3 => 48
}
// get frequency
if (!freq && typeof n === 'number') {
freq = fromMidi(n); // + 48);
freq = midiToFreq(n); // + 48);
}
// maybe pull out the above frequency resolution?? (there is also getFrequency but it has no default)
// make oscillator