mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-10-18 08:41:47 +00:00
Rebased code from new eried repo commits. Changed to to reflect strijar implementation. Fixed previous issue with old ssb-am-tx ui_mictx code.
This commit is contained in:
@@ -55,3 +55,29 @@ void IIRBiquadFilter::execute(const buffer_f32_t& buffer_in, const buffer_f32_t&
|
||||
void IIRBiquadFilter::execute_in_place(const buffer_f32_t& buffer) {
|
||||
execute(buffer, buffer);
|
||||
}
|
||||
|
||||
void IIRBiquadDF2Filter::configure(const iir_biquad_df2_config_t& config) {
|
||||
b0 = config[0] / config[3];
|
||||
b1 = config[1] / config[3];
|
||||
b2 = config[2] / config[3];
|
||||
a1 = config[4] / config[3];
|
||||
a2 = config[5] / config[3];
|
||||
}
|
||||
|
||||
// scipy.signal.sosfilt
|
||||
//
|
||||
// x_n = x[i, n] # make a temporary copy
|
||||
// # Use direct II transposed structure:
|
||||
// x[i, n] = b[s, 0] * x_n + zi[i, s, 0]
|
||||
// zi[i, s, 0] = (b[s, 1] * x_n - a[s, 0] * x[i, n] + zi[i, s, 1])
|
||||
// zi[i, s, 1] = (b[s, 2] * x_n - a[s, 1] * x[i, n])
|
||||
|
||||
float IIRBiquadDF2Filter::execute(float x) {
|
||||
float y;
|
||||
|
||||
y = b0 * x + z0;
|
||||
z0 = b1 * x - a1 * y + z1;
|
||||
z1 = b2 * x - a2 * y;
|
||||
|
||||
return y;
|
||||
}
|
||||
|
@@ -31,6 +31,9 @@ struct iir_biquad_config_t {
|
||||
std::array<float, 3> a;
|
||||
};
|
||||
|
||||
// 0..2 - b, 3..5 - a
|
||||
typedef std::array<float, 6> iir_biquad_df2_config_t;
|
||||
|
||||
constexpr iir_biquad_config_t iir_config_passthrough {
|
||||
{ { 1.0f, 0.0f, 0.0f } },
|
||||
{ { 0.0f, 0.0f, 0.0f } },
|
||||
@@ -67,4 +70,21 @@ private:
|
||||
std::array<float, 3> y { { 0.0f, 0.0f, 0.0f } };
|
||||
};
|
||||
|
||||
class IIRBiquadDF2Filter {
|
||||
public:
|
||||
|
||||
void configure(const iir_biquad_df2_config_t& config);
|
||||
float execute(float z);
|
||||
|
||||
private:
|
||||
float b0 = 0;
|
||||
float b1 = 0;
|
||||
float b2 = 0;
|
||||
float a1 = 0;
|
||||
float a2 = 0;
|
||||
|
||||
float z0 = 0;
|
||||
float z1 = 0;
|
||||
};
|
||||
|
||||
#endif/*__DSP_IIR_H__*/
|
||||
|
22
firmware/common/dsp_sos.cpp
Normal file
22
firmware/common/dsp_sos.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Belousov Oleg
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "dsp_sos.hpp"
|
51
firmware/common/dsp_sos.hpp
Normal file
51
firmware/common/dsp_sos.hpp
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Belousov Oleg
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __DSP_SOS_H__
|
||||
#define __DSP_SOS_H__
|
||||
|
||||
#include "dsp_iir.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
|
||||
template <size_t N>
|
||||
class SOSFilter {
|
||||
|
||||
public:
|
||||
|
||||
void configure(const iir_biquad_df2_config_t config[N]) {
|
||||
for (size_t i = 0; i < N; i++)
|
||||
filters[i].configure(config[i]);
|
||||
}
|
||||
|
||||
float execute(float value) {
|
||||
for (auto &filter : filters)
|
||||
value = filter.execute(value);
|
||||
return value;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
IIRBiquadDF2Filter filters[N];
|
||||
};
|
||||
|
||||
#endif/*__DSP_SOS_H__*/
|
37
firmware/common/dsp_sos_config.hpp
Normal file
37
firmware/common/dsp_sos_config.hpp
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Belousov Oleg
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __DSP_SOS_CONFIG_H__
|
||||
#define __DSP_SOS_CONFIG_H__
|
||||
|
||||
#include "dsp_iir.hpp"
|
||||
|
||||
// scipy.signal.iirfilter(ftype="ellip", N = 10, rp = 0.5, rs = 60.0, Wn = 0.5, btype = 'lowpass', output="sos")
|
||||
|
||||
constexpr iir_biquad_df2_config_t half_band_lpf_config[5] = {
|
||||
{ 0.02339042f, 0.0411599f, 0.02339042f, 1.0f, -0.95317621f, 0.33446485f },
|
||||
{ 1.0f, 0.82196114f, 1.0f, 1.0f, -0.50327735f, 0.63611027f },
|
||||
{ 1.0f, 0.32515305f, 1.0f, 1.0f, -0.18144446f, 0.85269598f },
|
||||
{ 1.0f, 0.14394122f, 1.0f, 1.0f, -0.04368236f, 0.94798064f },
|
||||
{ 1.0f, 0.08720754, 1.0f, 1.0f, 0.00220944f, 0.98743139f }
|
||||
};
|
||||
|
||||
#endif/*__DSP_SOS_CONFIG_H__*/
|
@@ -856,13 +856,21 @@ public:
|
||||
const float deviation_hz,
|
||||
const float audio_gain,
|
||||
const uint32_t tone_key_delta,
|
||||
const float tone_key_mix_weight
|
||||
const float tone_key_mix_weight,
|
||||
const bool am_enabled,
|
||||
const bool dsb_enabled,
|
||||
const bool usb_enabled,
|
||||
const bool lsb_enabled
|
||||
) : Message { ID::AudioTXConfig },
|
||||
divider(divider),
|
||||
deviation_hz(deviation_hz),
|
||||
audio_gain(audio_gain),
|
||||
tone_key_delta(tone_key_delta),
|
||||
tone_key_mix_weight(tone_key_mix_weight)
|
||||
tone_key_mix_weight(tone_key_mix_weight),
|
||||
am_enabled(am_enabled),
|
||||
dsb_enabled(dsb_enabled),
|
||||
usb_enabled(usb_enabled),
|
||||
lsb_enabled(lsb_enabled)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -871,6 +879,10 @@ public:
|
||||
const float audio_gain;
|
||||
const uint32_t tone_key_delta;
|
||||
const float tone_key_mix_weight;
|
||||
const bool am_enabled;
|
||||
const bool dsb_enabled;
|
||||
const bool usb_enabled;
|
||||
const bool lsb_enabled;
|
||||
};
|
||||
|
||||
class SigGenConfigMessage : public Message {
|
||||
|
Reference in New Issue
Block a user