Skip to content

Commit

Permalink
Fix airspy SW AGC
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbrechtL committed Sep 7, 2019
1 parent b971a49 commit 66832e2
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/input/airspy_sdr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,24 +194,25 @@ int CAirspy::data_available(const DSPCOMPLEX* buf, size_t num_samples)
const auto z = 0.5f * (sbuf[2*i] + sbuf[2*i+1]);
temp[i] = z;

if (sw_agc and (num_frames % 200) == 0) {
if (sw_agc and (num_frames % 10) == 0) {
if (norm(z) > maxnorm) {
maxnorm = norm(z);
}
}
}

if (sw_agc and (num_frames % 200) == 0) {
if (sw_agc and (num_frames % 10) == 0) {
const float maxampl = sqrt(maxnorm);
// std::clog << "Airspy: maxampl: " << maxampl << std::endl;

if (maxampl > 0.2f) {
const int newgain = currentLinearityGain--;
const int newgain = currentLinearityGain - 1;
if (newgain >= AIRSPY_GAIN_MIN) {
setGain(newgain);
}
}
else if (maxampl < 0.02f) {
const int newgain = currentLinearityGain++;
const int newgain = currentLinearityGain + 1;
if (newgain <= AIRSPY_GAIN_MAX) {
setGain(newgain);
}
Expand Down Expand Up @@ -312,6 +313,7 @@ float CAirspy::getGain() const

float CAirspy::setGain(int gain)
{
std::clog << "Airspy: setgain: " << gain << std::endl;
currentLinearityGain = gain;

int result = airspy_set_linearity_gain(device, currentLinearityGain);
Expand Down

0 comments on commit 66832e2

Please sign in to comment.