@ekx/auph
Version:
[](https://github.com/eliasku/auph/actions/workflows/build.yml) [](https://www.npmjs.com/package/auph) [ {
if (ctx && ctx.state !== "closed") {
return ctx;
}
warn(2 /* InvalidState */);
}
export function getAudioContextObject() {
return ctx;
}
export function getContextState(ctx) {
var state = 0;
if (ctx.state !== "closed") {
state |= 1 /* Active */;
if (ctx.state === "running") {
state |= 2 /* Running */;
}
}
return state;
}
export function audioContextResume(ctx) {
log(3 /* DeviceResuming */);
ctx.resume().then(function () {
log(4 /* DeviceResumed */);
}).catch(function (reason) {
error(5 /* DeviceResumeError */, reason);
});
}
export function audioContextPause(ctx) {
log(6 /* DevicePausing */);
ctx.suspend().then(function () {
log(7 /* DevicePaused */);
}).catch(function (reason) {
error(8 /* DevicePauseError */, reason);
});
}
function newAudioContext(options) {
var scope = window;
var audioContext = scope.AudioContext || scope.webkitAudioContext;
// TODO: set sample rate could lead to wrong playback on safari mobile (maybe it should be recreated after unlock?)
//try {
// return new audioContext(options);
//} catch (err) {
// error(Message.WebAudio_TryDefaultOptions, err);
//}
try {
return new audioContext();
}
catch (err) {
error(1 /* NotSupported */, err);
}
}
export function initContext() {
if (ctx) {
warn(14 /* Warning_AlreadyInitialized */);
return ctx;
}
ctx = newAudioContext({
latencyHint: "interactive",
sampleRate: defaultSampleRate
});
if (ctx) {
emptyAudioBuffer = ctx.createBuffer(1, 1, defaultSampleRate);
unlock(function () {
if (ctx.state === "suspended") {
audioContextResume(ctx);
return false;
}
return true;
});
}
return ctx;
}
export function closeContext(context) {
log(9 /* DeviceClosing */);
context.close().then(function () {
log(10 /* DeviceClosed */);
}).catch(function (reason) {
error(11 /* DeviceCloseError */, reason);
});
ctx = undefined;
}
//# sourceMappingURL=Mixer.js.map