From e3f2e634c85ff5ebcd27edaeffac93f8da5e814a Mon Sep 17 00:00:00 2001 From: byuu <2107894+byuu@users.noreply.github.com> Date: Sat, 5 Oct 2019 14:29:31 +0900 Subject: [PATCH] Fixed audio crackling in Super Game Boy emulation. --- bsnes/emulator/audio/audio.hpp | 3 ++- bsnes/emulator/audio/stream.cpp | 9 +++++++-- bsnes/sfc/coprocessor/icd/icd.cpp | 4 ++-- nall/queue.hpp | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/bsnes/emulator/audio/audio.hpp b/bsnes/emulator/audio/audio.hpp index 258f73a0..fd029403 100644 --- a/bsnes/emulator/audio/audio.hpp +++ b/bsnes/emulator/audio/audio.hpp @@ -56,13 +56,14 @@ struct Filter { struct Stream { auto reset(uint channels, double inputFrequency, double outputFrequency) -> void; + auto frequency() const -> double; auto setFrequency(double inputFrequency, maybe outputFrequency = nothing) -> void; auto addDCRemovalFilter() -> void; auto addLowPassFilter(double cutoffFrequency, Filter::Order order, uint passes = 1) -> void; auto addHighPassFilter(double cutoffFrequency, Filter::Order order, uint passes = 1) -> void; - auto pending() const -> bool; + auto pending() const -> uint; auto read(double samples[]) -> uint; auto write(const double samples[]) -> void; diff --git a/bsnes/emulator/audio/stream.cpp b/bsnes/emulator/audio/stream.cpp index b9817fb9..d22863b4 100644 --- a/bsnes/emulator/audio/stream.cpp +++ b/bsnes/emulator/audio/stream.cpp @@ -9,6 +9,10 @@ auto Stream::reset(uint channelCount, double inputFrequency, double outputFreque setFrequency(inputFrequency, outputFrequency); } +auto Stream::frequency() const -> double { + return inputFrequency; +} + auto Stream::setFrequency(double inputFrequency, maybe outputFrequency) -> void { this->inputFrequency = inputFrequency; if(outputFrequency) this->outputFrequency = outputFrequency(); @@ -77,8 +81,9 @@ auto Stream::addHighPassFilter(double cutoffFrequency, Filter::Order order, uint } } -auto Stream::pending() const -> bool { - return channels && channels[0].resampler.pending(); +auto Stream::pending() const -> uint { + if(!channels) return 0; + return channels[0].resampler.pending(); } auto Stream::read(double samples[]) -> uint { diff --git a/bsnes/sfc/coprocessor/icd/icd.cpp b/bsnes/sfc/coprocessor/icd/icd.cpp index b8887cea..eb334d6d 100644 --- a/bsnes/sfc/coprocessor/icd/icd.cpp +++ b/bsnes/sfc/coprocessor/icd/icd.cpp @@ -62,8 +62,8 @@ auto ICD::main() -> void { auto clocks = GB_run(&sameboy); step(clocks >> 1); } else { //DMG halted - stream->sample(float(0.0), float(0.0)); - step(128); + apuWrite(0.0, 0.0); + step(256); } synchronizeCPU(); } diff --git a/nall/queue.hpp b/nall/queue.hpp index 062eda77..8b791ee7 100644 --- a/nall/queue.hpp +++ b/nall/queue.hpp @@ -41,7 +41,7 @@ struct queue { template auto capacity() const -> uint { return _capacity * sizeof(T) / sizeof(U); } template auto size() const -> uint { return _size * sizeof(T) / sizeof(U); } auto empty() const -> bool { return _size == 0; } - auto pending() const -> bool { return _size > 0; } + auto pending() const -> bool { return _size; } auto full() const -> bool { return _size >= (int)_capacity; } auto underflow() const -> bool { return _size < 0; } auto overflow() const -> bool { return _size > (int)_capacity; }