add freq support to sampler

This commit is contained in:
Felix Roos 2022-12-12 20:41:09 +01:00
parent 8b22c2e04f
commit df73ce8a60
5 changed files with 43 additions and 8 deletions

View file

@ -1,4 +1,4 @@
import { logger, toMidi } from '@strudel.cycles/core';
import { logger, toMidi, valueToMidi } from '@strudel.cycles/core';
import { getAudioContext } from './index.mjs';
const bufferCache = {}; // string: Promise<ArrayBuffer>
@ -20,9 +20,12 @@ function humanFileSize(bytes, si) {
return bytes.toFixed(1) + ' ' + units[u];
}
export const getSampleBufferSource = async (s, n, note, speed) => {
export const getSampleBufferSource = async (s, n, note, speed, freq) => {
let transpose = 0;
let midi = typeof note === 'string' ? toMidi(note) : note || 36;
if (freq !== undefined && note !== undefined) {
logger('[sampler] hap has note and freq. ignoring note', 'warning');
}
let midi = valueToMidi({ freq, n, note }, 36);
transpose = midi - 36; // C3 is middle C
const ac = getAudioContext();

View file

@ -288,10 +288,10 @@ export const webaudioOutput = async (hap, deadline, hapDuration) => {
if (soundfont) {
// is soundfont
bufferSource = await globalThis.getFontBufferSource(soundfont, note || n, ac);
bufferSource = await globalThis.getFontBufferSource(soundfont, note || n, ac, freq);
} else {
// is sample from loaded samples(..)
bufferSource = await getSampleBufferSource(s, n, note, speed);
bufferSource = await getSampleBufferSource(s, n, note, speed, freq);
}
// asny stuff above took too long?
if (ac.currentTime > t) {