Skip to content

Commit 8de82dc

Browse files
committed
🎸 Can switch instruments and change volume
🎸 Added instrument select in sidebar 🔊 Can change volume
1 parent 09f8f6d commit 8de82dc

23 files changed

+192
-68
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/audio/instruments.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { PolySynth, Sampler } from "tone";
2+
3+
/** The different instruments that users can choose for audio output */
4+
export enum AppInstrument {
5+
PIANO = "Piano",
6+
SYNTH = "Synth"
7+
}
8+
9+
/** Create the Tone.js instrument */
10+
export const createInstrument = (chosenInstrument: AppInstrument) => {
11+
switch (chosenInstrument) {
12+
case AppInstrument.PIANO:
13+
return createPianoSampler();
14+
case AppInstrument.SYNTH:
15+
return createSynth();
16+
default:
17+
return null;
18+
}
19+
}
20+
21+
/** Create the synth instrument */
22+
export const createSynth = () => new PolySynth().toDestination();
23+
24+
/** Create the piano sampler */
25+
const createPianoSampler = () => new Sampler(pianoSamples, { release: 1, baseUrl: "audio/piano/" }).toDestination();
26+
const pianoSamples = {
27+
"C4": "C4.wav",
28+
"D#4": "Ds4.wav",
29+
"F#4": "Fs4.wav",
30+
"A4": "A4.wav",
31+
"C5": "C5.wav",
32+
"D#5": "Ds5.wav",
33+
"A5": "A5.wav",
34+
"C6": "C6.wav"
35+
};

src/audio/pianoSampler.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)