Skip to content

Commit

Permalink
wizard 1
Browse files Browse the repository at this point in the history
  • Loading branch information
dxinteractive committed Jan 29, 2024
1 parent cd136ac commit 5327ad2
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 30 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
18 changes: 8 additions & 10 deletions dev/src/dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,14 @@ touchStart(liveAudioContext);

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
ReactDOM.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
<HashRouter>
<Routes>
<Route path="/" element={<Main />}>
<Route index element={<List />} />
<Route path=":id" element={<DspRoute />} />
</Route>
</Routes>
</HashRouter>
</React.StrictMode>
<HashRouter>
<Routes>
<Route path="/" element={<Main />}>
<Route index element={<List />} />
<Route path=":id" element={<DspRoute />} />
</Route>
</Routes>
</HashRouter>
);

function Main() {
Expand Down
12 changes: 4 additions & 8 deletions dev/src/dsp-definitions/35-recorded-guitar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
42 changes: 42 additions & 0 deletions dev/src/dsp-definitions/36-wizard-delay.ts
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 2 additions & 0 deletions dev/src/dsp-definitions/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -72,4 +73,5 @@ export const all: DspDefinition[] = [
pitchtracker3,
additiveSynth,
recordedGuitar,
wizardDelay,
];
25 changes: 13 additions & 12 deletions dev/src/faust-live-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand All @@ -19,19 +21,16 @@ export function useFaustLivePlayer(
audioContext: AudioContext,
dspDefinition: DspDefinition
): UseFaustLivePlayerResult | undefined {
const effectCountRef = useRef(0);
const audioNode = useRef<FaustNode>();
const [result, setResult] = useState<UseFaustLivePlayerResult | undefined>();

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) {
Expand All @@ -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);
Expand All @@ -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]);
Expand Down

0 comments on commit 5327ad2

Please sign in to comment.