Bass line Note Trigger Sound fixed

This commit is contained in:
AG
2025-12-20 20:48:15 +02:00
parent 26cedfca61
commit 13029f4277
3 changed files with 9 additions and 3 deletions

Binary file not shown.

View File

@@ -218,6 +218,7 @@ export class AudioEngine {
const freq = NOTE_FREQ_MAP[note];
if (!freq) return;
this.stopBassNote(note, time);
const osc = this.audioContext.createOscillator();
const gain = this.audioContext.createGain();
osc.type = 'sine';

View File

@@ -12,6 +12,7 @@ export const useDrumMachine = (_lastMessage: any, sendMessage: (message: any) =>
} = useStore();
const timerRef = useRef<number | null>(null);
const wasPlayingRef = useRef<boolean>(false);
const lookahead = 25.0;
const scheduleAheadTime = 0.1;
const nextNoteTimeRef = useRef<number>(0.0);
@@ -161,8 +162,8 @@ export const useDrumMachine = (_lastMessage: any, sendMessage: (message: any) =>
const triggerBassNote = async (note: string) => {
await audioEngine.init();
audioEngine.startBassNote(note, audioEngine.getCurrentTime());
// Stop after 1s for preview
setTimeout(() => audioEngine.stopBassNote(note, audioEngine.getCurrentTime()), 1000);
// Stop after 500ms for preview
setTimeout(() => audioEngine.stopBassNote(note, audioEngine.getCurrentTime()), 500);
};
const exportBeat = () => {
@@ -199,9 +200,13 @@ export const useDrumMachine = (_lastMessage: any, sendMessage: (message: any) =>
scheduler();
} else {
if (timerRef.current) clearTimeout(timerRef.current);
audioEngine.stopAllBassNotes();
// Only stop all notes if we just switched from playing to stopped
if (wasPlayingRef.current) {
audioEngine.stopAllBassNotes();
}
setCurrentStep(null);
}
wasPlayingRef.current = isPlaying;
return () => {
if (timerRef.current) clearTimeout(timerRef.current);
};