Fixed audio crackling in Super Game Boy emulation.

This commit is contained in:
byuu 2019-10-05 14:29:31 +09:00
parent e598e81ab9
commit e3f2e634c8
4 changed files with 12 additions and 6 deletions

View File

@ -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<double> 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;

View File

@ -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<double> 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 {

View File

@ -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();
}

View File

@ -41,7 +41,7 @@ struct queue {
template<typename U = T> auto capacity() const -> uint { return _capacity * sizeof(T) / sizeof(U); }
template<typename U = T> 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; }