diff --git a/packages/react/examples/nano-repl/src/App.jsx b/packages/react/examples/nano-repl/src/App.jsx index f84356c7..086923ac 100644 --- a/packages/react/examples/nano-repl/src/App.jsx +++ b/packages/react/examples/nano-repl/src/App.jsx @@ -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(); diff --git a/packages/superdough/synth.mjs b/packages/superdough/synth.mjs index 02cf4c8a..57317133 100644 --- a/packages/superdough/synth.mjs +++ b/packages/superdough/synth.mjs @@ -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, diff --git a/packages/superdough/zzfx.mjs b/packages/superdough/zzfx.mjs index a8ddf30b..352a88a2 100644 --- a/packages/superdough/zzfx.mjs +++ b/packages/superdough/zzfx.mjs @@ -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; diff --git a/website/src/repl/prebake.mjs b/website/src/repl/prebake.mjs index 6bdc5c0d..28678c9d 100644 --- a/website/src/repl/prebake.mjs +++ b/website/src/repl/prebake.mjs @@ -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