fix: double registering

This commit is contained in:
Felix Roos 2023-08-30 15:32:45 +02:00
parent 1463f27a0f
commit 90cdea3656
4 changed files with 8 additions and 20 deletions

View File

@ -6,7 +6,6 @@ import {
panic,
webaudioOutput,
registerSynthSounds,
registerZZFXSounds,
} from '@strudel.cycles/webaudio';
import { registerSoundfonts } from '@strudel.cycles/soundfonts';
import { useCallback, useState } from 'react';
@ -27,7 +26,7 @@ async function init() {
import('@strudel.cycles/osc'),
);
await Promise.all([loadModules, registerSynthSounds(), registerZZFXSounds(), registerSoundfonts()]);
await Promise.all([loadModules, registerSynthSounds(), registerSoundfonts()]);
}
init();

View File

@ -21,21 +21,6 @@ const fm = (osc, harmonicityRatio, modulationIndex, wave = 'sine') => {
};
export function registerSynthSounds() {
['zsine', 'zsaw', 'ztri', 'ztan', 'znoise'].forEach((wave) => {
registerSound(wave, (t, value, onended) => {
const duration = 0.2;
const { node: o } = getZZFX({ s: wave, ...value }, t, duration);
o.onended = () => {
o.disconnect();
onended();
};
return {
node: o,
stop: () => {},
};
});
});
['sine', 'square', 'triangle', 'sawtooth'].forEach((wave) => {
registerSound(
wave,

View File

@ -1,4 +1,6 @@
import { ZZFX } from 'zzfx';
import { midiToFreq, noteToMidi } from './util.mjs';
import { registerSound, getAudioContext } from './superdough.mjs';
export const getZZFX = (value, t, duration) => {
let {
@ -27,8 +29,8 @@ export const getZZFX = (value, t, duration) => {
note = noteToMidi(note); // e.g. c3 => 48
}
// get frequency
if (!freq && typeof n === 'number') {
freq = midiToFreq(n);
if (!freq && typeof note === 'number') {
freq = midiToFreq(note);
}
const shape = ['zsine', 'ztri', 'zsaw', 'ztan', 'znoise'].indexOf(s) || 0;
@ -93,6 +95,7 @@ export const getZZFX = (value, t, duration) => {
};
export function registerZZFXSounds() {
console.log('registerZZFXSounds');
['zsine', 'zsaw', 'ztri', 'ztan', 'znoise'].forEach((wave) => {
registerSound(wave, (t, value, onended) => {
const duration = 0.2;

View File

@ -1,5 +1,5 @@
import { Pattern, noteToMidi, valueToMidi } from '@strudel.cycles/core';
import { registerSynthSounds, samples } from '@strudel.cycles/webaudio';
import { registerSynthSounds, registerZZFXSounds, samples } from '@strudel.cycles/webaudio';
import './piano.mjs';
import './files.mjs';
@ -8,6 +8,7 @@ export async function prebake() {
// License: CC-by http://creativecommons.org/licenses/by/3.0/ Author: Alexander Holm
await Promise.all([
registerSynthSounds(),
registerZZFXSounds(),
//registerSoundfonts(),
// need dynamic import here, because importing @strudel.cycles/soundfonts fails on server:
// => getting "window is not defined", as soon as "@strudel.cycles/soundfonts" is imported statically