- Modify `setDefaultAudioContext()` to accept an optional `existingAudioCtx` parameter. - If provided, it will use the existing context; otherwise, it creates a new one. - This allows for better integration with external audio systems that manage their own AudioContext.
18 lines
385 B
JavaScript
18 lines
385 B
JavaScript
let audioContext;
|
|
|
|
export const setDefaultAudioContext = (existingAudioCtx) => {
|
|
audioContext = existingAudioCtx ?? new AudioContext();
|
|
return audioContext;
|
|
};
|
|
|
|
export const getAudioContext = () => {
|
|
if (!audioContext) {
|
|
return setDefaultAudioContext();
|
|
}
|
|
|
|
return audioContext;
|
|
};
|
|
|
|
export function getAudioContextCurrentTime() {
|
|
return getAudioContext().currentTime;
|
|
}
|