mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-04-02 10:42:14 -04:00
byuu says: First 32 instructions implemented in the TLCS900H disassembler. Only 992 to go! I removed the use of anonymous namespaces in nall. It was something I rarely used, because it rarely did what I wanted. I updated all nested namespaces to use C++17-style namespace Foo::Bar {} syntax instead of classic C++-style namespace Foo { namespace Bar {}}. I updated ruby::Video::acquire() to return a struct, so we can use C++17 structured bindings. Long term, I want to get away from all functions that take references for output only. Even though C++ botched structured bindings by not allowing you to bind to existing variables, it's even worse to have function calls that take arguments by reference and then write to them. From the caller side, you can't tell the value is being written, nor that the value passed in doesn't matter, which is terrible.
46 lines
1 KiB
C++
46 lines
1 KiB
C++
#pragma once
|
|
|
|
#include <nall/dsp/dsp.hpp>
|
|
|
|
//one-pole first-order IIR filter
|
|
|
|
namespace nall::DSP::IIR {
|
|
|
|
struct OnePole {
|
|
enum class Type : uint {
|
|
LowPass,
|
|
HighPass,
|
|
};
|
|
|
|
inline auto reset(Type type, double cutoffFrequency, double samplingFrequency) -> void;
|
|
inline auto process(double in) -> double; //normalized sample (-1.0 to +1.0)
|
|
|
|
private:
|
|
Type type;
|
|
double cutoffFrequency;
|
|
double samplingFrequency;
|
|
double a0, b1; //coefficients
|
|
double z1; //first-order IIR
|
|
};
|
|
|
|
auto OnePole::reset(Type type, double cutoffFrequency, double samplingFrequency) -> void {
|
|
this->type = type;
|
|
this->cutoffFrequency = cutoffFrequency;
|
|
this->samplingFrequency = samplingFrequency;
|
|
|
|
z1 = 0.0;
|
|
double x = cos(2.0 * Math::Pi * cutoffFrequency / samplingFrequency);
|
|
if(type == Type::LowPass) {
|
|
b1 = +2.0 - x - sqrt((+2.0 - x) * (+2.0 - x) - 1);
|
|
a0 = 1.0 - b1;
|
|
} else {
|
|
b1 = -2.0 - x + sqrt((-2.0 - x) * (-2.0 - x) - 1);
|
|
a0 = 1.0 + b1;
|
|
}
|
|
}
|
|
|
|
auto OnePole::process(double in) -> double {
|
|
return z1 = in * a0 + z1 * b1;
|
|
}
|
|
|
|
}
|