From f160c43e4cd7369d5685aa2e5f2a6337ea6d8122 Mon Sep 17 00:00:00 2001 From: TianZerL Date: Mon, 26 Feb 2024 16:05:41 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=92=A5=20Improve=20the=20accuracy=20o?= =?UTF-8?q?f=20FPS=20limiter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/src/main/java/cn/navclub/nes4j/bin/ppu/PPU.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/src/main/java/cn/navclub/nes4j/bin/ppu/PPU.java b/bin/src/main/java/cn/navclub/nes4j/bin/ppu/PPU.java index d92e2f3..9a64823 100644 --- a/bin/src/main/java/cn/navclub/nes4j/bin/ppu/PPU.java +++ b/bin/src/main/java/cn/navclub/nes4j/bin/ppu/PPU.java @@ -556,7 +556,8 @@ protected void calVideoPauseTime(long now) { var unit = 1000000000 / this.console.TVFps(); var span = unit - (now - this.lastFrameTime); if (span > 0) { - LockSupport.parkNanos(span); + LockSupport.parkNanos(span - 2000); + while(System.nanoTime() < now + span); this.lastFrameTime = System.nanoTime(); } else { this.lastFrameTime = now + span; From 66e04774b5b3bf580b59ee8d891cf5206ce43baa Mon Sep 17 00:00:00 2001 From: TianZerL Date: Mon, 26 Feb 2024 16:08:46 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=92=A5=20Improve=20audio=20quality=20?= =?UTF-8?q?mute=20triangle=20channle=20should't=20output=20zero?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/navclub/nes4j/bin/apu/impl/TriangleChannel.java | 6 +----- .../cn/navclub/nes4j/bin/apu/impl/timer/TriangleTimer.java | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/bin/src/main/java/cn/navclub/nes4j/bin/apu/impl/TriangleChannel.java b/bin/src/main/java/cn/navclub/nes4j/bin/apu/impl/TriangleChannel.java index 948b50d..adfe3ef 100644 --- a/bin/src/main/java/cn/navclub/nes4j/bin/apu/impl/TriangleChannel.java +++ b/bin/src/main/java/cn/navclub/nes4j/bin/apu/impl/TriangleChannel.java @@ -70,11 +70,7 @@ public void write(int address, byte b) { */ @Override public int output() { - if (!this.enable - || this.linearCounter.getCounter() == 0 - || this.lengthCounter.silence()) { - return 0; - } + // Silencing the triangle channel merely halts it. It will continue to output its last value rather than 0. return sequencer.value(); } diff --git a/bin/src/main/java/cn/navclub/nes4j/bin/apu/impl/timer/TriangleTimer.java b/bin/src/main/java/cn/navclub/nes4j/bin/apu/impl/timer/TriangleTimer.java index 68a1450..4bb4e52 100644 --- a/bin/src/main/java/cn/navclub/nes4j/bin/apu/impl/timer/TriangleTimer.java +++ b/bin/src/main/java/cn/navclub/nes4j/bin/apu/impl/timer/TriangleTimer.java @@ -32,7 +32,7 @@ public void tick() { if (this.counter == 0) { var linearCounter = this.channel.getLinearCounter(); var lengthCounter = this.channel.getLengthCounter(); - if (lengthCounter.getCounter() != 0 && linearCounter.getCounter() != 0) { + if (channel.isEnable() && lengthCounter.getCounter() != 0 && linearCounter.getCounter() != 0) { this.sequencer.tick(); } } From bfea8713ce3f3551f8a23bd5a4647357f074e517 Mon Sep 17 00:00:00 2001 From: TianZerL Date: Mon, 26 Feb 2024 16:10:31 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=92=A5=20Improve=20audio=20compatibil?= =?UTF-8?q?ity=20use=2044.1KHz=20sample=20rate=20by=20default=20for=20=20c?= =?UTF-8?q?ompatibility?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/cn/navclub/nes4j/app/view/GameWorld.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/cn/navclub/nes4j/app/view/GameWorld.java b/app/src/main/java/cn/navclub/nes4j/app/view/GameWorld.java index 534095a..dce0929 100644 --- a/app/src/main/java/cn/navclub/nes4j/app/view/GameWorld.java +++ b/app/src/main/java/cn/navclub/nes4j/app/view/GameWorld.java @@ -4,7 +4,6 @@ import cn.navclub.nes4j.app.INes; import cn.navclub.nes4j.app.audio.JavaXAudio; import cn.navclub.nes4j.app.config.NESConfig; -import cn.navclub.nes4j.app.control.IconPopup; import cn.navclub.nes4j.app.service.TaskService; import cn.navclub.nes4j.app.dialog.DHandle; import cn.navclub.nes4j.app.event.GameEventWrap; @@ -12,6 +11,7 @@ import cn.navclub.nes4j.app.util.StrUtil; import cn.navclub.nes4j.app.util.UIUtil; import cn.navclub.nes4j.bin.NesConsole; +import cn.navclub.nes4j.bin.config.AudioSampleRate; import cn.navclub.nes4j.bin.io.JoyPad; import cn.navclub.nes4j.bin.logging.LoggerDelegate; import cn.navclub.nes4j.bin.logging.LoggerFactory; @@ -125,6 +125,7 @@ protected Void call() { .newBuilder() .file(file) .player(JavaXAudio.class) + .sampleRate(AudioSampleRate.HZ44100) .gameLoopCallback(GameWorld.this::gameLoopCallback) .build(); GameWorld.this.console.execute();