mirror of
https://github.com/exoticorn/microw8.git
synced 2026-01-20 11:16:42 +01:00
implement backchannel from audio thread
This commit is contained in:
@@ -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 });
|
||||
|
||||
Reference in New Issue
Block a user