Fixed weird audio glitch on some AM station

pull/97/head
Ryzerth 2021-05-09 03:06:57 +02:00
rodzic 1b27916c24
commit 0b276bed1d
4 zmienionych plików z 24 dodań i 96 usunięć

Wyświetl plik

@ -199,6 +199,13 @@ private:
int count = _this->stereoPacker.out.read();
if (count < 0) { return 0; }
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));
_this->stereoPacker.out.flush();
return 0;

Wyświetl plik

@ -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;
};

Wyświetl plik

@ -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() {}

Wyświetl plik

@ -32,8 +32,11 @@ namespace module_manager_menu {
ImGui::BeginTable("Module Manager Table", 3, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg);
ImGui::TableSetupColumn("Name");
ImGui::TableSetupColumn("Type");
ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, 16);
ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, 10);
ImGui::TableHeadersRow();
float height = ImGui::CalcTextSize("-").y;
for (auto& [name, inst] : core::moduleManager.instances) {
// TEMPORARY EXCLUSION FOR SOURCES AND SINKS
std::string type = inst.module.info->name;
@ -51,12 +54,21 @@ namespace module_manager_menu {
ImGui::Text(inst.module.info->name);
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);
}
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::TableSetColumnIndex(0);
@ -73,7 +85,6 @@ namespace module_manager_menu {
core::moduleManager.createInstance(modName, modTypes[modTypeId]);
}
if (strlen(modName) == 0) { style::endDisabled(); }
ImGui::EndTable();
}
}