diff --git a/dev/public/audio/freesound/584282__yellowtree__clean-guitar-loop.wav b/dev/public/audio/freesound/584282__yellowtree__clean-guitar-loop.wav new file mode 100644 index 0000000..99ca2a6 Binary files /dev/null and b/dev/public/audio/freesound/584282__yellowtree__clean-guitar-loop.wav differ diff --git a/dev/public/audio/freesound/667253__garuda1982__electric-guitar-melody-2.mp3 b/dev/public/audio/freesound/667253__garuda1982__electric-guitar-melody-2.mp3 deleted file mode 100644 index b6697cc..0000000 Binary files a/dev/public/audio/freesound/667253__garuda1982__electric-guitar-melody-2.mp3 and /dev/null differ diff --git a/dev/public/audio/freesound/706196__garuda1982__sad-electric-guitar-loop-for-background-music.wav b/dev/public/audio/freesound/706196__garuda1982__sad-electric-guitar-loop-for-background-music.wav deleted file mode 100644 index ada3236..0000000 Binary files a/dev/public/audio/freesound/706196__garuda1982__sad-electric-guitar-loop-for-background-music.wav and /dev/null differ diff --git a/dev/src/dev.tsx b/dev/src/dev.tsx index 6978a67..ceb4715 100644 --- a/dev/src/dev.tsx +++ b/dev/src/dev.tsx @@ -30,16 +30,14 @@ touchStart(liveAudioContext); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion ReactDOM.createRoot(document.getElementById("root")!).render( - - - - }> - } /> - } /> - - - - + + + }> + } /> + } /> + + + ); function Main() { diff --git a/dev/src/dsp-definitions/35-recorded-guitar.ts b/dev/src/dsp-definitions/35-recorded-guitar.ts index c47344c..139d5e3 100644 --- a/dev/src/dsp-definitions/35-recorded-guitar.ts +++ b/dev/src/dsp-definitions/35-recorded-guitar.ts @@ -2,22 +2,18 @@ import type { DspDefinition } from "../types"; const dsp = ` import("stdfaust.lib"); -process = _; +process = _ <: *(1.0),*(1.0); `; -const files = { - a: "/audio/freesound/667253__garuda1982__electric-guitar-melody-2.mp3", - b: "/audio/freesound/706196__garuda1982__sad-electric-guitar-loop-for-background-music.wav", -}; - const dspDefinition: DspDefinition = { id: "recorded-guitar", name: "Recorded guitar", description: - "Plays a freesound recording of a guitar sound from garuda1982 with no alterations", + "Plays a freesound recording of a guitar sound from yellowtree with no alterations", dsp, type: "live", - inputFile: files.b, + inputFile: "/audio/freesound/584282__yellowtree__clean-guitar-loop.wav", + loopLength: 20, }; export default dspDefinition; diff --git a/dev/src/dsp-definitions/36-wizard-delay.ts b/dev/src/dsp-definitions/36-wizard-delay.ts new file mode 100644 index 0000000..b22b20c --- /dev/null +++ b/dev/src/dsp-definitions/36-wizard-delay.ts @@ -0,0 +1,42 @@ +import type { DspDefinition } from "../types"; + +const dsp = ` +import("stdfaust.lib"); + +delay_max = ma.SR * 5; + +wet_param = 0.5; +dry_param = 1.0; +fb_param = 0.5; +time_param = 0.5; + +mod_speed_param = 3.0; +mod_depth_param = 0.0001; +mod = 1.0 - ((os.osc(mod_speed_param) * 0.5 + 0.5) * mod_depth_param); + +// modx = mod * (os.lf_sawpos(time_param * 2) + 0.01); + +delay(time, fb, x) = x + fb : de.fdelay(delay_max, time * mod) : fi.highpass(2, 200.0) : fi.lowpass(2, 4000.0); +fb = *(fb_param); +echo(time) = delay(time) ~ fb; + +wet_l = echo(time_param * ma.SR * 0.8); +wet_r = echo(time_param * ma.SR); +wet = _ <: wet_l,wet_r : *(wet_param),*(wet_param); +dry = *(dry_param); + +process = _ <: (dry <: _,_),wet :> _,_; +`; + +const dspDefinition: DspDefinition = { + id: "wizard", + name: "Wizard delay", + description: "Rebeltech wizard-based delay pedal DSP", + dsp, + type: "live", + inputFile: "/audio/freesound/584282__yellowtree__clean-guitar-loop.wav", + inputOffset: 0, + loopLength: 16 + 8, +}; + +export default dspDefinition; diff --git a/dev/src/dsp-definitions/all.ts b/dev/src/dsp-definitions/all.ts index acd4947..970f6a1 100644 --- a/dev/src/dsp-definitions/all.ts +++ b/dev/src/dsp-definitions/all.ts @@ -35,6 +35,7 @@ import minSince from "./32-min-since"; import pitchtracker3 from "./33-pitchtracker-3"; import additiveSynth from "./34-additive-synth"; import recordedGuitar from "./35-recorded-guitar"; +import wizardDelay from "./36-wizard-delay"; export const all: DspDefinition[] = [ sineWave, @@ -72,4 +73,5 @@ export const all: DspDefinition[] = [ pitchtracker3, additiveSynth, recordedGuitar, + wizardDelay, ]; diff --git a/dev/src/faust-live-player.ts b/dev/src/faust-live-player.ts index 19aaf49..96d65d0 100644 --- a/dev/src/faust-live-player.ts +++ b/dev/src/faust-live-player.ts @@ -7,6 +7,8 @@ import { audioSource } from "mosfez-faust/audio-source"; import { fetchFile } from "./fetch"; import { toAudioBuffer } from "mosfez-faust/convert"; +let total = 0; + export type UseFaustLivePlayerResult = { ui: UIItem[]; params: string[]; @@ -19,19 +21,16 @@ export function useFaustLivePlayer( audioContext: AudioContext, dspDefinition: DspDefinition ): UseFaustLivePlayerResult | undefined { - const effectCountRef = useRef(0); const audioNode = useRef(); const [result, setResult] = useState(); useEffect(() => { - if (!isDspLive(dspDefinition)) return; - const count = ++effectCountRef.current; + if (!isDspLive(dspDefinition) || total >= 1) return; + total++; let source: MediaStreamAudioSourceNode | AudioBufferSourceNode | undefined; compile(audioContext, dspDefinition.dsp).then(async (node) => { - if (effectCountRef.current !== count) return; - const { inputFile, inputOffset = 0, loopLength = 0 } = dspDefinition; if (node.numberOfInputs > 0) { @@ -50,11 +49,12 @@ export function useFaustLivePlayer( if (inputOffset) { source.loopStart = inputOffset; source.loop = true; - if (loopLength) { - source.loopEnd = inputOffset + loopLength; - } } - source.start(inputOffset); + if (loopLength) { + source.loopEnd = loopLength; + source.loop = true; + } + source.start(0, inputOffset); } else { source = await audioSource(audioContext); source.connect(node); @@ -78,13 +78,14 @@ export function useFaustLivePlayer( }); return () => { + total--; if (audioNode.current) { audioNode.current.disconnect(); audioNode.current.destroy(); + } - if (source && source instanceof AudioBufferSourceNode) { - source.stop(); - } + if (source && source instanceof AudioBufferSourceNode) { + source.stop(); } }; }, [dspDefinition]);