mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2026-04-19 23:02:43 +00:00
attemt at a CI build with new DSP
This commit is contained in:
@@ -8,11 +8,14 @@ namespace dsp::loop {
|
||||
public:
|
||||
AGC() {}
|
||||
|
||||
AGC(stream<T>* in) { init(in); }
|
||||
AGC(stream<T>* in, double setPoint, double rate, double maxGain, double maxOutputAmp, double initGain = 1.0) { init(in, setPoint, rate, maxGain, maxOutputAmp, initGain); }
|
||||
|
||||
void init(stream<T>* in, double setPoint, double rate, double initGain = 1.0) {
|
||||
void init(stream<T>* in, double setPoint, double rate, double maxGain, double maxOutputAmp, double initGain = 1.0) {
|
||||
_setPoint = setPoint;
|
||||
_rate = rate;
|
||||
_invRate = 1.0f - _rate;
|
||||
_maxGain = maxGain;
|
||||
_maxOutputAmp = maxOutputAmp;
|
||||
_initGain = initGain;
|
||||
gain = _initGain;
|
||||
base_type::init(in);
|
||||
@@ -28,6 +31,19 @@ namespace dsp::loop {
|
||||
assert(base_type::_block_init);
|
||||
std::lock_guard<std::recursive_mutex> lck(base_type::ctrlMtx);
|
||||
_rate = rate;
|
||||
_invRate = 1.0f - _rate;
|
||||
}
|
||||
|
||||
void setMaxGain(double maxGain) {
|
||||
assert(base_type::_block_init);
|
||||
std::lock_guard<std::recursive_mutex> lck(base_type::ctrlMtx);
|
||||
_maxGain = maxGain;
|
||||
}
|
||||
|
||||
void setMaxOutputAmp(double maxOutputAmp) {
|
||||
assert(base_type::_block_init);
|
||||
std::lock_guard<std::recursive_mutex> lck(base_type::ctrlMtx);
|
||||
_maxOutputAmp = maxOutputAmp;
|
||||
}
|
||||
|
||||
void setInitialGain(double initGain) {
|
||||
@@ -40,22 +56,29 @@ namespace dsp::loop {
|
||||
assert(base_type::_block_init);
|
||||
std::lock_guard<std::recursive_mutex> lck(base_type::ctrlMtx);
|
||||
gain = _initGain;
|
||||
amp = 1.0f;
|
||||
}
|
||||
|
||||
inline int process(int count, T* in, T* out) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
// Scale output by gain
|
||||
out[i] = in[i] * gain;
|
||||
|
||||
// Update gain according to setpoint and rate
|
||||
// Get signal amplitude
|
||||
float inAmp;
|
||||
if constexpr (std::is_same_v<T, complex_t>) {
|
||||
gain += (_setPoint - out[i].amplitude()) * _rate;
|
||||
inAmp = in[i].amplitude();
|
||||
}
|
||||
if constexpr (std::is_same_v<T, float>) {
|
||||
gain += (_setPoint - fabsf(out[i])) * _rate;
|
||||
inAmp = fabsf(in[i]);
|
||||
}
|
||||
|
||||
// Update average amplitude
|
||||
if (inAmp != 0.0f) {
|
||||
amp = (amp * _invRate) + (inAmp * _rate);
|
||||
gain = std::min<float>(_setPoint / amp, _maxGain);
|
||||
}
|
||||
|
||||
// Scale output by gain
|
||||
out[i] = in[i] * gain;
|
||||
}
|
||||
printf("%f\n", gain);
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -73,9 +96,13 @@ namespace dsp::loop {
|
||||
protected:
|
||||
float _setPoint;
|
||||
float _rate;
|
||||
float _invRate;
|
||||
float _maxGain;
|
||||
float _maxOutputAmp;
|
||||
float _initGain;
|
||||
|
||||
float gain;
|
||||
float amp = 1.0;
|
||||
|
||||
};
|
||||
}
|
||||
@@ -35,6 +35,11 @@ namespace dsp::loop {
|
||||
beta = (4 * bandwidth * bandwidth) / denominator;
|
||||
}
|
||||
|
||||
void setCoefficients(T alpha, T beta) {
|
||||
_alpha = alpha:
|
||||
_beta = beta;
|
||||
}
|
||||
|
||||
void setPhaseLimits(T minPhase, T maxPhase) {
|
||||
assert(maxPhase > minPhase);
|
||||
_minPhase = minPhase;
|
||||
|
||||
@@ -24,6 +24,16 @@ namespace dsp::loop {
|
||||
base_type::init(in);
|
||||
}
|
||||
|
||||
void setBandwidth(double bandwidth) {
|
||||
assert(base_type::_block_init);
|
||||
std::lock_guard<std::recursive_mutex> lck(base_type::ctrlMtx);
|
||||
base_type::tempStop();
|
||||
float alpha, beta;
|
||||
PhaseControlLoop<float>::criticallyDamped(bandwidth, alpha, beta);
|
||||
|
||||
base_type::tempStart();
|
||||
}
|
||||
|
||||
void setInitialPhase(double initPhase) {
|
||||
assert(base_type::_block_init);
|
||||
std::lock_guard<std::recursive_mutex> lck(base_type::ctrlMtx);
|
||||
|
||||
Reference in New Issue
Block a user