mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-01-24 00:34:44 +01:00
Fixed file source and cleaned up buffering code
This commit is contained in:
parent
70cf463881
commit
aaa15315ce
@ -198,13 +198,14 @@ private:
|
|||||||
AudioSink* _this = (AudioSink*)userData;
|
AudioSink* _this = (AudioSink*)userData;
|
||||||
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); }
|
|
||||||
|
|
||||||
for (int i = 0; i < count; i++) {
|
// For debug purposes only...
|
||||||
if (_this->stereoPacker.out.readBuf[i].l == NAN || _this->stereoPacker.out.readBuf[i].r == NAN) { spdlog::error("NAN in audio data"); }
|
// if (nBufferFrames != count) { spdlog::warn("Buffer size missmatch, wanted {0}, was asked for {1}", count, nBufferFrames); }
|
||||||
if (_this->stereoPacker.out.readBuf[i].l == INFINITY || _this->stereoPacker.out.readBuf[i].r == INFINITY) { spdlog::error("INFINITY in audio data"); }
|
// for (int i = 0; i < count; i++) {
|
||||||
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 == 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();
|
||||||
|
@ -224,14 +224,6 @@ namespace dsp {
|
|||||||
|
|
||||||
SampleFrameBuffer(stream<T>* in) { init(in); }
|
SampleFrameBuffer(stream<T>* in) { init(in); }
|
||||||
|
|
||||||
~SampleFrameBuffer() {
|
|
||||||
generic_block<SampleFrameBuffer<T>>::stop();
|
|
||||||
out.stopWriter();
|
|
||||||
stopWorker = true;
|
|
||||||
cnd.notify_all();
|
|
||||||
if (readWorkerThread.joinable()) { readWorkerThread.join(); }
|
|
||||||
}
|
|
||||||
|
|
||||||
void init(stream<T>* in) {
|
void init(stream<T>* in) {
|
||||||
_in = in;
|
_in = in;
|
||||||
|
|
||||||
@ -241,8 +233,6 @@ namespace dsp {
|
|||||||
|
|
||||||
generic_block<SampleFrameBuffer<T>>::registerInput(in);
|
generic_block<SampleFrameBuffer<T>>::registerInput(in);
|
||||||
generic_block<SampleFrameBuffer<T>>::registerOutput(&out);
|
generic_block<SampleFrameBuffer<T>>::registerOutput(&out);
|
||||||
|
|
||||||
readWorkerThread = std::thread(&SampleFrameBuffer::worker, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setInput(stream<T>* in) {
|
void setInput(stream<T>* in) {
|
||||||
@ -275,9 +265,9 @@ namespace dsp {
|
|||||||
writeCur++;
|
writeCur++;
|
||||||
writeCur = ((writeCur) % TEST_BUFFER_SIZE);
|
writeCur = ((writeCur) % TEST_BUFFER_SIZE);
|
||||||
|
|
||||||
if (((writeCur - readCur + TEST_BUFFER_SIZE) % TEST_BUFFER_SIZE) >= (TEST_BUFFER_SIZE-2)) {
|
// if (((writeCur - readCur + TEST_BUFFER_SIZE) % TEST_BUFFER_SIZE) >= (TEST_BUFFER_SIZE-2)) {
|
||||||
spdlog::warn("Overflow");
|
// spdlog::warn("Overflow");
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
cnd.notify_all();
|
cnd.notify_all();
|
||||||
_in->flush();
|
_in->flush();
|
||||||
@ -311,6 +301,25 @@ namespace dsp {
|
|||||||
bool bypass = false;
|
bool bypass = false;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void doStart() {
|
||||||
|
generic_block<SampleFrameBuffer<T>>::workerThread = std::thread(&generic_block<SampleFrameBuffer<T>>::workerLoop, this);
|
||||||
|
readWorkerThread = std::thread(&SampleFrameBuffer<T>::worker, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void doStop() {
|
||||||
|
_in->stopReader();
|
||||||
|
out.stopWriter();
|
||||||
|
stopWorker = true;
|
||||||
|
cnd.notify_all();
|
||||||
|
|
||||||
|
if (generic_block<SampleFrameBuffer<T>>::workerThread.joinable()) { generic_block<SampleFrameBuffer<T>>::workerThread.join(); }
|
||||||
|
if (readWorkerThread.joinable()) { readWorkerThread.join(); }
|
||||||
|
|
||||||
|
_in->clearReadStop();
|
||||||
|
out.clearWriteStop();
|
||||||
|
stopWorker = false;
|
||||||
|
}
|
||||||
|
|
||||||
stream<T>* _in;
|
stream<T>* _in;
|
||||||
|
|
||||||
std::thread readWorkerThread;
|
std::thread readWorkerThread;
|
||||||
|
@ -461,7 +461,7 @@ void MainWindow::draw() {
|
|||||||
|
|
||||||
ImGui::Checkbox("Bypass buffering", &sigpath::signalPath.inputBuffer.bypass);
|
ImGui::Checkbox("Bypass buffering", &sigpath::signalPath.inputBuffer.bypass);
|
||||||
|
|
||||||
ImGui::Text("Buffering: %d", (sigpath::signalPath.inputBuffer.writeCur - sigpath::signalPath.inputBuffer.readCur + 20) % 20);
|
ImGui::Text("Buffering: %d", (sigpath::signalPath.inputBuffer.writeCur - sigpath::signalPath.inputBuffer.readCur + 32) % 32);
|
||||||
|
|
||||||
if (ImGui::Button("Test Bug")) {
|
if (ImGui::Button("Test Bug")) {
|
||||||
spdlog::error("Will this make the software crash?");
|
spdlog::error("Will this make the software crash?");
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include <gui/menus/theme.h>
|
#include <gui/menus/theme.h>
|
||||||
#include <gui/gui.h>
|
#include <gui/gui.h>
|
||||||
#include <options.h>
|
#include <options.h>
|
||||||
#include <core.h>>
|
#include <core.h>
|
||||||
|
|
||||||
namespace thememenu {
|
namespace thememenu {
|
||||||
int themeId;
|
int themeId;
|
||||||
|
@ -116,4 +116,8 @@ void SignalPath::startFFT() {
|
|||||||
void SignalPath::stopFFT() {
|
void SignalPath::stopFFT() {
|
||||||
reshape.stop();
|
reshape.stop();
|
||||||
fftHandlerSink.stop();
|
fftHandlerSink.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SignalPath::setBuffering(bool enabled) {
|
||||||
|
inputBuffer.bypass = !enabled;
|
||||||
}
|
}
|
@ -20,6 +20,7 @@ public:
|
|||||||
void setFFTSize(int size);
|
void setFFTSize(int size);
|
||||||
void startFFT();
|
void startFFT();
|
||||||
void stopFFT();
|
void stopFFT();
|
||||||
|
void setBuffering(bool enabled);
|
||||||
|
|
||||||
dsp::SampleFrameBuffer<dsp::complex_t> inputBuffer;
|
dsp::SampleFrameBuffer<dsp::complex_t> inputBuffer;
|
||||||
|
|
||||||
@ -43,4 +44,5 @@ private:
|
|||||||
double fftRate;
|
double fftRate;
|
||||||
int fftSize;
|
int fftSize;
|
||||||
int inputBlockSize;
|
int inputBlockSize;
|
||||||
|
bool bufferingEnabled = false;
|
||||||
};
|
};
|
@ -63,11 +63,13 @@ private:
|
|||||||
static void menuSelected(void* ctx) {
|
static void menuSelected(void* ctx) {
|
||||||
FileSourceModule* _this = (FileSourceModule*)ctx;
|
FileSourceModule* _this = (FileSourceModule*)ctx;
|
||||||
core::setInputSampleRate(_this->sampleRate);
|
core::setInputSampleRate(_this->sampleRate);
|
||||||
|
sigpath::signalPath.setBuffering(false);
|
||||||
spdlog::info("FileSourceModule '{0}': Menu Select!", _this->name);
|
spdlog::info("FileSourceModule '{0}': Menu Select!", _this->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void menuDeselected(void* ctx) {
|
static void menuDeselected(void* ctx) {
|
||||||
FileSourceModule* _this = (FileSourceModule*)ctx;
|
FileSourceModule* _this = (FileSourceModule*)ctx;
|
||||||
|
sigpath::signalPath.setBuffering(true);
|
||||||
spdlog::info("FileSourceModule '{0}': Menu Deselect!", _this->name);
|
spdlog::info("FileSourceModule '{0}': Menu Deselect!", _this->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,8 +314,8 @@ private:
|
|||||||
static void _audioHandler(dsp::stereo_t *data, int count, void *ctx) {
|
static void _audioHandler(dsp::stereo_t *data, int count, void *ctx) {
|
||||||
RecorderModule* _this = (RecorderModule*)ctx;
|
RecorderModule* _this = (RecorderModule*)ctx;
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
_this->wavSampleBuf[(2*i)] = data[i].l * 32767.0f;
|
_this->wavSampleBuf[(2*i)] = std::clamp<int>(data[i].l * 32767.0f, -32768, 32767);
|
||||||
_this->wavSampleBuf[(2*i) + 1] = data[i].r * 32767.0f;
|
_this->wavSampleBuf[(2*i) + 1] = std::clamp<int>(data[i].r * 32767.0f, -32768, 32767);
|
||||||
}
|
}
|
||||||
_this->audioWriter->writeSamples(_this->wavSampleBuf, count * 2 * sizeof(int16_t));
|
_this->audioWriter->writeSamples(_this->wavSampleBuf, count * 2 * sizeof(int16_t));
|
||||||
_this->samplesWritten += count;
|
_this->samplesWritten += count;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user