mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-08-20 19:42:19 +02:00
v114.5
* improved appended firmware detection [devinacker] * added dynamic rate control support to ALSA and PulseAudio drivers [RedDwarf] * added option to use native file dialogs
This commit is contained in:
@@ -7,6 +7,9 @@
|
||||
namespace nall::DSP::Resampler {
|
||||
|
||||
struct Cubic {
|
||||
inline auto inputFrequency() const -> double { return _inputFrequency; }
|
||||
inline auto outputFrequency() const -> double { return _outputFrequency; }
|
||||
|
||||
inline auto reset(double inputFrequency, double outputFrequency = 0, uint queueSize = 0) -> void;
|
||||
inline auto setInputFrequency(double inputFrequency) -> void;
|
||||
inline auto pending() const -> bool;
|
||||
@@ -15,41 +18,41 @@ struct Cubic {
|
||||
inline auto serialize(serializer&) -> void;
|
||||
|
||||
private:
|
||||
double inputFrequency;
|
||||
double outputFrequency;
|
||||
double _inputFrequency;
|
||||
double _outputFrequency;
|
||||
|
||||
double ratio;
|
||||
double fraction;
|
||||
double history[4];
|
||||
queue<double> samples;
|
||||
double _ratio;
|
||||
double _fraction;
|
||||
double _history[4];
|
||||
queue<double> _samples;
|
||||
};
|
||||
|
||||
auto Cubic::reset(double inputFrequency, double outputFrequency, uint queueSize) -> void {
|
||||
this->inputFrequency = inputFrequency;
|
||||
this->outputFrequency = outputFrequency ? outputFrequency : this->inputFrequency;
|
||||
_inputFrequency = inputFrequency;
|
||||
_outputFrequency = outputFrequency ? outputFrequency : _inputFrequency;
|
||||
|
||||
ratio = inputFrequency / outputFrequency;
|
||||
fraction = 0.0;
|
||||
for(auto& sample : history) sample = 0.0;
|
||||
samples.resize(queueSize ? queueSize : this->outputFrequency * 0.02); //default to 20ms max queue size
|
||||
_ratio = _inputFrequency / _outputFrequency;
|
||||
_fraction = 0.0;
|
||||
for(auto& sample : _history) sample = 0.0;
|
||||
_samples.resize(queueSize ? queueSize : _outputFrequency * 0.02); //default to 20ms max queue size
|
||||
}
|
||||
|
||||
auto Cubic::setInputFrequency(double inputFrequency) -> void {
|
||||
this->inputFrequency = inputFrequency;
|
||||
ratio = inputFrequency / outputFrequency;
|
||||
_inputFrequency = inputFrequency;
|
||||
_ratio = _inputFrequency / _outputFrequency;
|
||||
}
|
||||
|
||||
auto Cubic::pending() const -> bool {
|
||||
return samples.pending();
|
||||
return _samples.pending();
|
||||
}
|
||||
|
||||
auto Cubic::read() -> double {
|
||||
return samples.read();
|
||||
return _samples.read();
|
||||
}
|
||||
|
||||
auto Cubic::write(double sample) -> void {
|
||||
auto& mu = fraction;
|
||||
auto& s = history;
|
||||
auto& mu = _fraction;
|
||||
auto& s = _history;
|
||||
|
||||
s[0] = s[1];
|
||||
s[1] = s[2];
|
||||
@@ -62,20 +65,20 @@ auto Cubic::write(double sample) -> void {
|
||||
double C = s[2] - s[0];
|
||||
double D = s[1];
|
||||
|
||||
samples.write(A * mu * mu * mu + B * mu * mu + C * mu + D);
|
||||
mu += ratio;
|
||||
_samples.write(A * mu * mu * mu + B * mu * mu + C * mu + D);
|
||||
mu += _ratio;
|
||||
}
|
||||
|
||||
mu -= 1.0;
|
||||
}
|
||||
|
||||
auto Cubic::serialize(serializer& s) -> void {
|
||||
s.real(inputFrequency);
|
||||
s.real(outputFrequency);
|
||||
s.real(ratio);
|
||||
s.real(fraction);
|
||||
s.array(history);
|
||||
samples.serialize(s);
|
||||
s.real(_inputFrequency);
|
||||
s.real(_outputFrequency);
|
||||
s.real(_ratio);
|
||||
s.real(_fraction);
|
||||
s.array(_history);
|
||||
_samples.serialize(s);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user