Skip to content

Commit

Permalink
Merge pull request #7 from TianZerL/master
Browse files Browse the repository at this point in the history
Improve the accuracy of FPS limiter and audio quality
  • Loading branch information
GZYangKui authored Feb 27, 2024
2 parents 392cce3 + bfea871 commit e691975
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
3 changes: 2 additions & 1 deletion app/src/main/java/cn/navclub/nes4j/app/view/GameWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
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;
import cn.navclub.nes4j.app.model.KeyMapper;
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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
3 changes: 2 additions & 1 deletion bin/src/main/java/cn/navclub/nes4j/bin/ppu/PPU.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e691975

Please sign in to comment.