mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-06-26 12:27:51 +02:00
More work
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include "../processor.h"
|
||||
#include "../loop/agc.h"
|
||||
#include "../correction/dc_blocker.h"
|
||||
|
||||
namespace dsp::demod {
|
||||
class AM : public Processor<dsp::complex_t, float> {
|
||||
@ -13,13 +14,14 @@ namespace dsp::demod {
|
||||
|
||||
AM() {}
|
||||
|
||||
AM(stream<complex_t>* in, AGCMode agcMode, double agcRate) { init(in, agcMode, agcRate); }
|
||||
AM(stream<complex_t>* in, AGCMode agcMode, double agcAttack, double agcDecay, double dcBlockRate) { init(in, agcMode, agcAttack, agcDecay, dcBlockRate); }
|
||||
|
||||
void init(stream<complex_t>* in, AGCMode agcMode, double agcRate) {
|
||||
void init(stream<complex_t>* in, AGCMode agcMode, double agcAttack, double agcDecay, double dcBlockRate) {
|
||||
_agcMode = agcMode;
|
||||
|
||||
carrierAgc.init(NULL, 1.0, agcRate, 10e6, 10.0);
|
||||
audioAgc.init(NULL, 1.0, agcRate, 10e6, 10.0);
|
||||
carrierAgc.init(NULL, 1.0, agcAttack, agcDecay, 10e6, 10.0);
|
||||
audioAgc.init(NULL, 1.0, agcAttack, agcDecay, 10e6, 10.0);
|
||||
dcBlock.init(NULL, dcBlockRate);
|
||||
|
||||
base_type::init(in);
|
||||
}
|
||||
@ -33,11 +35,24 @@ namespace dsp::demod {
|
||||
base_type::tempStart();
|
||||
}
|
||||
|
||||
void setAGCRate(double agcRate) {
|
||||
void setAGCAttack(double attack) {
|
||||
assert(base_type::_block_init);
|
||||
std::lock_guard<std::recursive_mutex> lck(base_type::ctrlMtx);
|
||||
carrierAgc.setRate(agcRate);
|
||||
audioAgc.setRate(agcRate);
|
||||
carrierAgc.setAttack(attack);
|
||||
audioAgc.setAttack(attack);
|
||||
}
|
||||
|
||||
void setAGCDecay(double decay) {
|
||||
assert(base_type::_block_init);
|
||||
std::lock_guard<std::recursive_mutex> lck(base_type::ctrlMtx);
|
||||
carrierAgc.setDecay(decay);
|
||||
audioAgc.setDecay(decay);
|
||||
}
|
||||
|
||||
void setDCBlockRate(double rate) {
|
||||
assert(base_type::_block_init);
|
||||
std::lock_guard<std::recursive_mutex> lck(base_type::ctrlMtx);
|
||||
dcBlock.setRate(rate);
|
||||
}
|
||||
|
||||
void reset() {
|
||||
@ -46,6 +61,7 @@ namespace dsp::demod {
|
||||
base_type::tempStop();
|
||||
carrierAgc.reset();
|
||||
audioAgc.reset();
|
||||
dcBlock.reset();
|
||||
base_type::tempStart();
|
||||
}
|
||||
|
||||
@ -56,19 +72,14 @@ namespace dsp::demod {
|
||||
in = carrierAgc.out.writeBuf;
|
||||
}
|
||||
|
||||
// Get magnitude of each sample (TODO: use block instead)
|
||||
// Get magnitude of each sample and remove DC (TODO: use block instead)
|
||||
volk_32fc_magnitude_32f(out, (lv_32fc_t*)in, count);
|
||||
dcBlock.process(count, out, out);
|
||||
|
||||
// Apply audio AGC if needed
|
||||
if (_agcMode == AGCMode::AUDIO) {
|
||||
audioAgc.process(count, out, out);
|
||||
}
|
||||
else {
|
||||
// TODO: Find a volk function for it
|
||||
for (int i = 0; i < count; i++) {
|
||||
out[i] -= 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
@ -89,6 +100,7 @@ namespace dsp::demod {
|
||||
|
||||
loop::AGC<complex_t> carrierAgc;
|
||||
loop::AGC<float> audioAgc;
|
||||
correction::DCBlocker<float> dcBlock;
|
||||
|
||||
};
|
||||
}
|
@ -16,29 +16,17 @@ namespace dsp::demod {
|
||||
|
||||
SSB() {}
|
||||
|
||||
/** Calls the init function
|
||||
*/
|
||||
SSB(stream<complex_t>* in, Mode mode, double bandwidth, double samplerate, double agcRate) { init(in, mode, bandwidth, samplerate, agcRate); }
|
||||
SSB(stream<complex_t>* in, Mode mode, double bandwidth, double samplerate, double agcAttack, double agcDecay) { init(in, mode, bandwidth, samplerate, agcAttack, agcDecay); }
|
||||
|
||||
/** Initialize the SSB/DSB Demodulator
|
||||
* \param in Input stream
|
||||
* \param mode Demodulation mode, can be USB, LSB or DSB
|
||||
* \param bandwidth Bandwidth needed to shift back the IQ correctly
|
||||
* \param samplerate Samplerate of the IQ data
|
||||
* \param agcRate Speed at which the AGC corrects the audio level. This is NOT automatically scaled to the samplerate.
|
||||
*/
|
||||
void init(stream<complex_t>* in, Mode mode, double bandwidth, double samplerate, double agcRate) {
|
||||
void init(stream<complex_t>* in, Mode mode, double bandwidth, double samplerate, double agcAttack, double agcDecay) {
|
||||
_mode = mode;
|
||||
_bandwidth = bandwidth;
|
||||
_samplerate = samplerate;
|
||||
xlator.init(NULL, getTranslation(), _samplerate);
|
||||
agc.init(NULL, 1.0, agcRate, 10e6, 10.0);
|
||||
agc.init(NULL, 1.0, agcAttack, agcDecay, 10e6, 10.0);
|
||||
base_type::init(in);
|
||||
}
|
||||
|
||||
/** Set demodulation mode
|
||||
* \param mode Either USB, LSB or DSB
|
||||
*/
|
||||
void setMode(Mode mode) {
|
||||
assert(base_type::_block_init);
|
||||
std::lock_guard<std::recursive_mutex> lck(base_type::ctrlMtx);
|
||||
@ -48,9 +36,6 @@ namespace dsp::demod {
|
||||
base_type::tempStart();
|
||||
}
|
||||
|
||||
/** Set bandwidth
|
||||
* \param bandwidth Bandwidth in Hz
|
||||
*/
|
||||
void setBandwidth(double bandwidth) {
|
||||
assert(base_type::_block_init);
|
||||
std::lock_guard<std::recursive_mutex> lck(base_type::ctrlMtx);
|
||||
@ -60,9 +45,6 @@ namespace dsp::demod {
|
||||
base_type::tempStart();
|
||||
}
|
||||
|
||||
/** Set samplerate
|
||||
* \param samplerate Samplerate in Hz
|
||||
*/
|
||||
void setSamplerate(double samplerate) {
|
||||
assert(base_type::_block_init);
|
||||
std::lock_guard<std::recursive_mutex> lck(base_type::ctrlMtx);
|
||||
@ -72,20 +54,18 @@ namespace dsp::demod {
|
||||
base_type::tempStart();
|
||||
}
|
||||
|
||||
/** Set AGC rate
|
||||
* \param agcRate AGC rate in units per second
|
||||
*/
|
||||
void setAGCRate(double agcRate) {
|
||||
void setAGCAttack(double attack) {
|
||||
assert(base_type::_block_init);
|
||||
std::lock_guard<std::recursive_mutex> lck(base_type::ctrlMtx);
|
||||
agc.setRate(agcRate);
|
||||
agc.setAttack(attack);
|
||||
}
|
||||
|
||||
void setAGCDecay(double decay) {
|
||||
assert(base_type::_block_init);
|
||||
std::lock_guard<std::recursive_mutex> lck(base_type::ctrlMtx);
|
||||
agc.setDecay(decay);
|
||||
}
|
||||
|
||||
/** Process data
|
||||
* \param count Number of samples
|
||||
* \param in Input buffer
|
||||
* \param out Output buffer
|
||||
*/
|
||||
int process(int count, const complex_t* in, float* out) {
|
||||
// Move back sideband
|
||||
xlator.process(count, in, xlator.out.writeBuf);
|
||||
|
@ -8,12 +8,14 @@ namespace dsp::loop {
|
||||
public:
|
||||
AGC() {}
|
||||
|
||||
AGC(stream<T>* in, double setPoint, double rate, double maxGain, double maxOutputAmp, double initGain = 1.0) { init(in, setPoint, rate, maxGain, maxOutputAmp, initGain); }
|
||||
AGC(stream<T>* in, double setPoint, double attack, double decay, double maxGain, double maxOutputAmp, double initGain = 1.0) { init(in, setPoint, attack, decay, maxGain, maxOutputAmp, initGain); }
|
||||
|
||||
void init(stream<T>* in, double setPoint, double rate, double maxGain, double maxOutputAmp, double initGain = 1.0) {
|
||||
void init(stream<T>* in, double setPoint, double attack, double decay, double maxGain, double maxOutputAmp, double initGain = 1.0) {
|
||||
_setPoint = setPoint;
|
||||
_rate = rate;
|
||||
_invRate = 1.0f - _rate;
|
||||
_attack = attack;
|
||||
_invAttack = 1.0f - _attack;
|
||||
_decay = decay;
|
||||
_invDecay = 1.0f - _decay;
|
||||
_maxGain = maxGain;
|
||||
_maxOutputAmp = maxOutputAmp;
|
||||
_initGain = initGain;
|
||||
@ -27,11 +29,18 @@ namespace dsp::loop {
|
||||
_setPoint = setPoint;
|
||||
}
|
||||
|
||||
void setRate(double rate) {
|
||||
void setAttack(double attack) {
|
||||
assert(base_type::_block_init);
|
||||
std::lock_guard<std::recursive_mutex> lck(base_type::ctrlMtx);
|
||||
_rate = rate;
|
||||
_invRate = 1.0f - _rate;
|
||||
_attack = attack;
|
||||
_invAttack = 1.0f - _attack;
|
||||
}
|
||||
|
||||
void setDecay(double decay) {
|
||||
assert(base_type::_block_init);
|
||||
std::lock_guard<std::recursive_mutex> lck(base_type::ctrlMtx);
|
||||
_decay = decay;
|
||||
_invDecay = 1.0f - _decay;
|
||||
}
|
||||
|
||||
void setMaxGain(double maxGain) {
|
||||
@ -72,7 +81,7 @@ namespace dsp::loop {
|
||||
|
||||
// Update average amplitude
|
||||
if (inAmp != 0.0f) {
|
||||
amp = (amp * _invRate) + (inAmp * _rate);
|
||||
amp = (inAmp > amp) ? ((amp * _invAttack) + (inAmp * _attack)) : ((amp * _invDecay) + (inAmp * _decay));
|
||||
gain = std::min<float>(_setPoint / amp, _maxGain);
|
||||
}
|
||||
|
||||
@ -95,8 +104,10 @@ namespace dsp::loop {
|
||||
|
||||
protected:
|
||||
float _setPoint;
|
||||
float _rate;
|
||||
float _invRate;
|
||||
float _attack;
|
||||
float _invAttack;
|
||||
float _decay;
|
||||
float _invDecay;
|
||||
float _maxGain;
|
||||
float _maxOutputAmp;
|
||||
float _initGain;
|
||||
|
Reference in New Issue
Block a user