mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-01-12 11:17:11 +01:00
Fixed weird audio glitch on some AM station
This commit is contained in:
parent
1b27916c24
commit
0b276bed1d
@ -199,6 +199,13 @@ private:
|
|||||||
int count = _this->stereoPacker.out.read();
|
int count = _this->stereoPacker.out.read();
|
||||||
if (count < 0) { return 0; }
|
if (count < 0) { return 0; }
|
||||||
if (nBufferFrames != count) { spdlog::warn("Buffer size missmatch, wanted {0}, was asked for {1}", count, nBufferFrames); }
|
if (nBufferFrames != count) { spdlog::warn("Buffer size missmatch, wanted {0}, was asked for {1}", count, nBufferFrames); }
|
||||||
|
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
if (_this->stereoPacker.out.readBuf[i].l == NAN || _this->stereoPacker.out.readBuf[i].r == NAN) { spdlog::error("NAN in audio data"); }
|
||||||
|
if (_this->stereoPacker.out.readBuf[i].l == INFINITY || _this->stereoPacker.out.readBuf[i].r == INFINITY) { spdlog::error("INFINITY in audio data"); }
|
||||||
|
if (_this->stereoPacker.out.readBuf[i].l == -INFINITY || _this->stereoPacker.out.readBuf[i].r == -INFINITY) { spdlog::error("-INFINITY in audio data"); }
|
||||||
|
}
|
||||||
|
|
||||||
memcpy(outputBuffer, _this->stereoPacker.out.readBuf, nBufferFrames * sizeof(dsp::stereo_t));
|
memcpy(outputBuffer, _this->stereoPacker.out.readBuf, nBufferFrames * sizeof(dsp::stereo_t));
|
||||||
_this->stereoPacker.out.flush();
|
_this->stereoPacker.out.flush();
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -213,12 +213,9 @@ namespace dsp {
|
|||||||
|
|
||||||
_in->flush();
|
_in->flush();
|
||||||
|
|
||||||
float avg;
|
|
||||||
volk_32f_accumulator_s32f(&avg, out.writeBuf, count);
|
|
||||||
avg /= (float)count;
|
|
||||||
|
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
out.writeBuf[i] -= avg;
|
out.writeBuf[i] -= avg;
|
||||||
|
avg += out.writeBuf[i] * 10e-4;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!out.swap(count)) { return -1; }
|
if (!out.swap(count)) { return -1; }
|
||||||
@ -229,6 +226,7 @@ namespace dsp {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
stream<complex_t>* _in;
|
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> {
|
class ComplexAGC : public generic_block<ComplexAGC> {
|
||||||
public:
|
public:
|
||||||
ComplexAGC() {}
|
ComplexAGC() {}
|
||||||
|
@ -32,8 +32,11 @@ namespace module_manager_menu {
|
|||||||
ImGui::BeginTable("Module Manager Table", 3, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg);
|
ImGui::BeginTable("Module Manager Table", 3, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg);
|
||||||
ImGui::TableSetupColumn("Name");
|
ImGui::TableSetupColumn("Name");
|
||||||
ImGui::TableSetupColumn("Type");
|
ImGui::TableSetupColumn("Type");
|
||||||
ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, 16);
|
ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, 10);
|
||||||
ImGui::TableHeadersRow();
|
ImGui::TableHeadersRow();
|
||||||
|
|
||||||
|
float height = ImGui::CalcTextSize("-").y;
|
||||||
|
|
||||||
for (auto& [name, inst] : core::moduleManager.instances) {
|
for (auto& [name, inst] : core::moduleManager.instances) {
|
||||||
// TEMPORARY EXCLUSION FOR SOURCES AND SINKS
|
// TEMPORARY EXCLUSION FOR SOURCES AND SINKS
|
||||||
std::string type = inst.module.info->name;
|
std::string type = inst.module.info->name;
|
||||||
@ -51,12 +54,21 @@ namespace module_manager_menu {
|
|||||||
ImGui::Text(inst.module.info->name);
|
ImGui::Text(inst.module.info->name);
|
||||||
|
|
||||||
ImGui::TableSetColumnIndex(2);
|
ImGui::TableSetColumnIndex(2);
|
||||||
if (ImGui::Button(("-##module_mgr_"+name).c_str(), ImVec2(16,0))) {
|
ImVec2 origPos = ImGui::GetCursorPos();
|
||||||
|
ImGui::SetCursorPos(ImVec2(origPos.x - 3, origPos.y));
|
||||||
|
if (ImGui::Button(("##module_mgr_"+name).c_str(), ImVec2(height,height))) {
|
||||||
core::moduleManager.deleteInstance(name);
|
core::moduleManager.deleteInstance(name);
|
||||||
}
|
}
|
||||||
|
ImGui::SetCursorPos(ImVec2(origPos.x + 2, origPos.y - 5));
|
||||||
|
ImGui::Text("_");
|
||||||
}
|
}
|
||||||
|
ImGui::EndTable();
|
||||||
|
|
||||||
// Add module row
|
// Add module row with slightly different settings
|
||||||
|
ImGui::BeginTable("Module Manager Add Table", 3);
|
||||||
|
ImGui::TableSetupColumn("Name");
|
||||||
|
ImGui::TableSetupColumn("Type");
|
||||||
|
ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, 16);
|
||||||
ImGui::TableNextRow();
|
ImGui::TableNextRow();
|
||||||
|
|
||||||
ImGui::TableSetColumnIndex(0);
|
ImGui::TableSetColumnIndex(0);
|
||||||
@ -73,7 +85,6 @@ namespace module_manager_menu {
|
|||||||
core::moduleManager.createInstance(modName, modTypes[modTypeId]);
|
core::moduleManager.createInstance(modName, modTypes[modTypeId]);
|
||||||
}
|
}
|
||||||
if (strlen(modName) == 0) { style::endDisabled(); }
|
if (strlen(modName) == 0) { style::endDisabled(); }
|
||||||
|
|
||||||
ImGui::EndTable();
|
ImGui::EndTable();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user