implement backchannel from audio thread

This commit is contained in:
2022-04-22 00:28:19 +02:00
parent df0c169d54
commit e05701300c
4 changed files with 48 additions and 6 deletions

View File

@@ -126,7 +126,6 @@ export default function MicroW8(screen, config = {}) {
audioReadyResolve = null;
}
};
audioNode.port.onmessage = (e) => updateAudioReady(e.data);
let audioStateChange = () => {
if(audioContext.state == 'suspended') {
if(config.startButton) {
@@ -211,6 +210,14 @@ export default function MicroW8(screen, config = {}) {
data = loadModuleData(data);
let platform_data = await loadModuleURL(platformUrl);
audioNode.port.onmessage = (e) => {
if(isNaN(e.data)) {
U8(memory.buffer, 0x12c80, 32).set(U8(e.data));
} else {
updateAudioReady(e.data);
}
};
audioNode.port.postMessage([platform_data, data]);
let platform_instance = await instantiate(platform_data);
@@ -240,10 +247,12 @@ export default function MicroW8(screen, config = {}) {
isPaused = false;
audioContext.resume();
startTime += now - pauseTime;
audioNode.port.postMessage(startTime);
} else {
isPaused = true;
audioContext.suspend();
pauseTime = now;
audioNode.port.postMessage(0);
}
};
window.addEventListener('focus', () => updateVisibility(true), { signal: abortController.signal });