1
0
mirror of https://github.com/TomHarte/CLK.git synced 2026-04-20 10:17:05 +00:00

Attempt to use biquad filter; fix signs.

This commit is contained in:
Thomas Harte
2025-11-12 23:08:35 -05:00
parent c5c6c5ff72
commit cf33e17688
3 changed files with 37 additions and 12 deletions
+29 -1
View File
@@ -81,7 +81,35 @@ void SID::write(const Numeric::SizedInt<5> address, const uint8_t value) {
}
void SID::update_filter() {
// TODO!
using Type = SignalProcessing::BiquadFilter::Type;
Type type = Type::AllPass;
switch(filter_mode_.get()) {
case 0:
filter_ = SignalProcessing::BiquadFilter();
return;
case 1:
case 3: type = Type::LowPass; break;
case 2: type = Type::BandPass; break;
case 5: type = Type::Notch; break;
case 4:
case 6: type = Type::HighPass; break;
case 7: type = Type::AllPass; break;
}
filter_ =
SignalProcessing::BiquadFilter(
type,
1'000'000.0f,
30.0f + float(filter_cutoff_.get()) * 5.8f,
0.707f + float(filter_resonance_.get()) * 0.25f,
6.0f,
true
);
}
uint8_t SID::read(const Numeric::SizedInt<5> address) {
+1 -1
View File
@@ -297,7 +297,7 @@ private:
Numeric::SizedInt<11> filter_cutoff_;
Numeric::SizedInt<4> filter_resonance_;
Numeric::SizedInt<4> filter_channels_;
Numeric::SizedInt<4> filter_mode_;
Numeric::SizedInt<3> filter_mode_;
void update_filter();
};
+7 -10
View File
@@ -15,10 +15,7 @@ namespace SignalProcessing {
class BiquadFilter {
public:
BiquadFilter() {
// Default construction: no filter.
coefficients_[0] = int16_t(1 << 15);
}
BiquadFilter() {}
enum class Type {
LowPass,
@@ -47,7 +44,7 @@ public:
switch(type) {
case Type::LowPass:
coefficients[0] = (1.0f - cos_w0) / 2.0f;
coefficients[1] = 1.0f + cos_w0;
coefficients[1] = 1.0f - cos_w0;
coefficients[2] = (1.0f - cos_w0) / 2.0f;
magnitude = 1.0f + alpha;
coefficients[3] = -2.0f * cos_w0;
@@ -136,7 +133,7 @@ public:
}
}
for(int c = 0; c < 5; c++) {
coefficients_[c] = int16_t(coefficients[c] * 32767.0f);
coefficients_[c] = int16_t(coefficients[c] * 4096.0f);
}
}
@@ -144,17 +141,17 @@ public:
const int16_t output = (
coefficients_[0] * input +
coefficients_[1] * inputs_[0] +
coefficients_[2] * inputs_[1] +
coefficients_[3] * outputs_[0] +
coefficients_[2] * inputs_[1] -
coefficients_[3] * outputs_[0] -
coefficients_[4] * outputs_[1]
) >> 15;
) >> 12;
inputs_[1] = inputs_[0];
inputs_[0] = input;
outputs_[1] = outputs_[0];
outputs_[0] = output;
return output;
return int16_t(output);
}
private: