mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-06-30 14:17:51 +02:00
Fixed weird audio glitch on some AM station
This commit is contained in:
@ -213,12 +213,9 @@ namespace dsp {
|
||||
|
||||
_in->flush();
|
||||
|
||||
float avg;
|
||||
volk_32f_accumulator_s32f(&avg, out.writeBuf, count);
|
||||
avg /= (float)count;
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
out.writeBuf[i] -= avg;
|
||||
avg += out.writeBuf[i] * 10e-4;
|
||||
}
|
||||
|
||||
if (!out.swap(count)) { return -1; }
|
||||
@ -229,6 +226,7 @@ namespace dsp {
|
||||
|
||||
private:
|
||||
stream<complex_t>* _in;
|
||||
float avg = 0;
|
||||
|
||||
};
|
||||
|
||||
|
@ -147,94 +147,6 @@ namespace dsp {
|
||||
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class FeedForwardAGC : public generic_block<FeedForwardAGC<T>> {
|
||||
public:
|
||||
FeedForwardAGC() {}
|
||||
|
||||
FeedForwardAGC(stream<T>* in) { init(in); }
|
||||
|
||||
~FeedForwardAGC() {
|
||||
generic_block<FeedForwardAGC<T>>::stop();
|
||||
delete[] buffer;
|
||||
}
|
||||
|
||||
void init(stream<T>* in) {
|
||||
_in = in;
|
||||
buffer = new T[STREAM_BUFFER_SIZE];
|
||||
generic_block<FeedForwardAGC<T>>::registerInput(_in);
|
||||
generic_block<FeedForwardAGC<T>>::registerOutput(&out);
|
||||
}
|
||||
|
||||
void setInput(stream<T>* in) {
|
||||
std::lock_guard<std::mutex> lck(generic_block<FeedForwardAGC<T>>::ctrlMtx);
|
||||
generic_block<FeedForwardAGC<T>>::tempStop();
|
||||
generic_block<FeedForwardAGC<T>>::unregisterInput(_in);
|
||||
_in = in;
|
||||
generic_block<FeedForwardAGC<T>>::registerInput(_in);
|
||||
generic_block<FeedForwardAGC<T>>::tempStart();
|
||||
}
|
||||
|
||||
int run() {
|
||||
int count = _in->read();
|
||||
if (count < 0) { return -1; }
|
||||
|
||||
float level;
|
||||
float val;
|
||||
|
||||
// Process buffer
|
||||
memcpy(&buffer[inBuffer], _in->readBuf, count * sizeof(T));
|
||||
inBuffer += count;
|
||||
|
||||
// If there aren't enough samples, wait for more
|
||||
if (inBuffer < sampleCount) {
|
||||
_in->flush();
|
||||
return count;
|
||||
}
|
||||
|
||||
int toProcess = (inBuffer - sampleCount) + 1;
|
||||
|
||||
if constexpr (std::is_same_v<T, float>) {
|
||||
for (int i = 0; i < toProcess; i++) {
|
||||
level = 1e-4;
|
||||
for (int j = 0; j < sampleCount; j++) {
|
||||
val = fabsf(buffer[i + j]);
|
||||
if (val > level) { level = val; }
|
||||
}
|
||||
out.writeBuf[i] = buffer[i] / level;
|
||||
}
|
||||
}
|
||||
if constexpr (std::is_same_v<T, complex_t>) {
|
||||
for (int i = 0; i < toProcess; i++) {
|
||||
level = 1e-4;
|
||||
for (int j = 0; j < sampleCount; j++) {
|
||||
val = buffer[i + j].fastAmplitude();
|
||||
if (val > level) { level = val; }
|
||||
}
|
||||
out.writeBuf[i] = buffer[i] / level;
|
||||
}
|
||||
}
|
||||
|
||||
_in->flush();
|
||||
|
||||
// Move rest of buffer
|
||||
memmove(buffer, &buffer[toProcess], (sampleCount - 1) * sizeof(T));
|
||||
inBuffer -= toProcess;
|
||||
|
||||
if (!out.swap(count)) { return -1; }
|
||||
return toProcess;
|
||||
}
|
||||
|
||||
stream<T> out;
|
||||
|
||||
private:
|
||||
T* buffer;
|
||||
int inBuffer = 0;
|
||||
int sampleCount = 1024;
|
||||
stream<T>* _in;
|
||||
|
||||
};
|
||||
|
||||
class ComplexAGC : public generic_block<ComplexAGC> {
|
||||
public:
|
||||
ComplexAGC() {}
|
||||
|
Reference in New Issue
Block a user