mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 00:01:34 +11:00
Improve web emulator audio quality (#776)
- [x] no changelog update needed
This commit is contained in:
commit
93dabdb8ca
|
@ -8,7 +8,6 @@ import {
|
|||
import mGBA, { mGBAEmulator } from "./vendor/mgba";
|
||||
import { GbaKey, KeyBindings } from "./bindings";
|
||||
import { styled } from "styled-components";
|
||||
import { useFrameSkip } from "./useFrameSkip.hook";
|
||||
import { useController } from "./useController.hook";
|
||||
import { useLocalStorage } from "./useLocalStorage.hook";
|
||||
|
||||
|
@ -148,7 +147,6 @@ export const Mgba = forwardRef<MgbaHandle, MgbaProps>(
|
|||
};
|
||||
}, [state]);
|
||||
|
||||
useFrameSkip(mgbaModule);
|
||||
useController(mgbaModule);
|
||||
|
||||
useEffect(() => {
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
import { MutableRefObject, useEffect } from "react";
|
||||
import { mGBAEmulator } from "./vendor/mgba";
|
||||
|
||||
export function useFrameSkip(
|
||||
mgbaModule: MutableRefObject<mGBAEmulator | undefined>
|
||||
) {
|
||||
useEffect(() => {
|
||||
let previous: number | undefined = undefined;
|
||||
let stopped = false;
|
||||
let smoothedFrameTime = 60;
|
||||
|
||||
let totalTime = 0;
|
||||
let paused = false;
|
||||
|
||||
function raf(time: DOMHighResTimeStamp) {
|
||||
if (previous) {
|
||||
const delta = time - previous;
|
||||
|
||||
smoothedFrameTime = (smoothedFrameTime * 3 + delta) / 4;
|
||||
|
||||
const smoothedFrameRate = Math.round(1 / (smoothedFrameTime / 1000));
|
||||
|
||||
totalTime += 1 / smoothedFrameRate;
|
||||
|
||||
if (totalTime >= 1 / 60) {
|
||||
totalTime -= 1 / 60;
|
||||
if (paused) {
|
||||
mgbaModule.current?.resumeGame();
|
||||
paused = false;
|
||||
}
|
||||
} else {
|
||||
if (!paused) {
|
||||
mgbaModule.current?.pauseGame();
|
||||
paused = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
previous = time;
|
||||
|
||||
if (!stopped) {
|
||||
window.requestAnimationFrame(raf);
|
||||
}
|
||||
}
|
||||
|
||||
window.requestAnimationFrame(raf);
|
||||
return () => {
|
||||
stopped = true;
|
||||
};
|
||||
}, [mgbaModule]);
|
||||
}
|
|
@ -10,10 +10,10 @@ ENV BUILD_DIR=build-wasm
|
|||
|
||||
WORKDIR /
|
||||
|
||||
RUN git clone https://github.com/thenick775/mgba.git --filter=tree:0 -b feature/wasm
|
||||
RUN git clone https://github.com/corwinkuiper/mgba.git --filter=tree:0 -b wasm
|
||||
RUN mkdir /mgba/build-wasm
|
||||
WORKDIR /mgba/build-wasm
|
||||
RUN git checkout 27dede256b6de36303a87d0886f81505a0f30c28
|
||||
RUN git checkout 26a2701cef6fcad47c67559fcb7892004f8d489c
|
||||
|
||||
|
||||
RUN emcmake cmake .. && make install DESTDIR=install
|
||||
|
|
Loading…
Reference in a new issue