This commit is contained in:
Robert Dean 2025-12-01 17:18:14 -05:00 committed by GitHub
commit 4a64d84e7d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -100,9 +100,22 @@ export function BinauralModal({ onClose, show }: BinauralProps) {
const stopSound = useCallback(() => {
if (!isPlaying) return;
// Stop oscillators
leftOscillatorRef.current?.stop();
rightOscillatorRef.current?.stop();
audioContextRef.current?.close();
// Unload oscillators
leftOscillatorRef.current = null;
rightOscillatorRef.current = null;
// Close and unload AudioContext
if (audioContextRef.current) {
audioContextRef.current.close();
audioContextRef.current = null;
}
// Unload gain node
gainNodeRef.current = null;
setIsPlaying(false);
}, [isPlaying]);
@ -127,11 +140,9 @@ export function BinauralModal({ onClose, show }: BinauralProps) {
useEffect(() => {
// Cleanup when component unmounts
return () => {
if (isPlaying) {
stopSound();
}
stopSound();
};
}, [isPlaying, stopSound]);
}, [stopSound]);
useEffect(() => {
// Update frequencies when a preset is selected