mirror of
				https://github.com/AlexandreRouma/SDRPlusPlus.git
				synced 2025-10-31 08:58:13 +01:00 
			
		
		
		
	Fixed file source and cleaned up buffering code
This commit is contained in:
		| @@ -198,13 +198,14 @@ private: | ||||
|         AudioSink* _this = (AudioSink*)userData; | ||||
|         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"); } | ||||
|         } | ||||
|         // For debug purposes only... | ||||
|         // 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(); | ||||
|   | ||||
| @@ -224,14 +224,6 @@ namespace dsp { | ||||
|  | ||||
|         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) { | ||||
|             _in = in; | ||||
|  | ||||
| @@ -241,8 +233,6 @@ namespace dsp { | ||||
|  | ||||
|             generic_block<SampleFrameBuffer<T>>::registerInput(in); | ||||
|             generic_block<SampleFrameBuffer<T>>::registerOutput(&out); | ||||
|  | ||||
|             readWorkerThread = std::thread(&SampleFrameBuffer::worker, this); | ||||
|         } | ||||
|  | ||||
|         void setInput(stream<T>* in) { | ||||
| @@ -275,9 +265,9 @@ namespace dsp { | ||||
|                 writeCur++; | ||||
|                 writeCur = ((writeCur) % TEST_BUFFER_SIZE); | ||||
|  | ||||
|                 if (((writeCur - readCur + TEST_BUFFER_SIZE) % TEST_BUFFER_SIZE) >= (TEST_BUFFER_SIZE-2)) { | ||||
|                     spdlog::warn("Overflow"); | ||||
|                 } | ||||
|                 // if (((writeCur - readCur + TEST_BUFFER_SIZE) % TEST_BUFFER_SIZE) >= (TEST_BUFFER_SIZE-2)) { | ||||
|                 //     spdlog::warn("Overflow"); | ||||
|                 // } | ||||
|             } | ||||
|             cnd.notify_all(); | ||||
|             _in->flush(); | ||||
| @@ -311,6 +301,25 @@ namespace dsp { | ||||
|         bool bypass = false; | ||||
|  | ||||
|     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; | ||||
|  | ||||
|         std::thread readWorkerThread; | ||||
|   | ||||
| @@ -461,7 +461,7 @@ void MainWindow::draw() { | ||||
|  | ||||
|             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")) { | ||||
|                 spdlog::error("Will this make the software crash?"); | ||||
|   | ||||
| @@ -1,7 +1,7 @@ | ||||
| #include <gui/menus/theme.h> | ||||
| #include <gui/gui.h> | ||||
| #include <options.h> | ||||
| #include <core.h>> | ||||
| #include <core.h> | ||||
|  | ||||
| namespace thememenu { | ||||
|     int themeId; | ||||
|   | ||||
| @@ -116,4 +116,8 @@ void SignalPath::startFFT() { | ||||
| void SignalPath::stopFFT() { | ||||
|     reshape.stop(); | ||||
|     fftHandlerSink.stop(); | ||||
| } | ||||
|  | ||||
| void SignalPath::setBuffering(bool enabled) { | ||||
|     inputBuffer.bypass = !enabled; | ||||
| } | ||||
| @@ -20,6 +20,7 @@ public: | ||||
|     void setFFTSize(int size); | ||||
|     void startFFT(); | ||||
|     void stopFFT(); | ||||
|     void setBuffering(bool enabled); | ||||
|  | ||||
|     dsp::SampleFrameBuffer<dsp::complex_t> inputBuffer; | ||||
|  | ||||
| @@ -43,4 +44,5 @@ private: | ||||
|     double fftRate; | ||||
|     int fftSize; | ||||
|     int inputBlockSize; | ||||
|     bool bufferingEnabled = false; | ||||
| }; | ||||
| @@ -63,11 +63,13 @@ private: | ||||
|     static void menuSelected(void* ctx) { | ||||
|         FileSourceModule* _this = (FileSourceModule*)ctx; | ||||
|         core::setInputSampleRate(_this->sampleRate); | ||||
|         sigpath::signalPath.setBuffering(false); | ||||
|         spdlog::info("FileSourceModule '{0}': Menu Select!", _this->name); | ||||
|     } | ||||
|  | ||||
|     static void menuDeselected(void* ctx) { | ||||
|         FileSourceModule* _this = (FileSourceModule*)ctx; | ||||
|         sigpath::signalPath.setBuffering(true); | ||||
|         spdlog::info("FileSourceModule '{0}': Menu Deselect!", _this->name); | ||||
|     } | ||||
|      | ||||
|   | ||||
| @@ -314,8 +314,8 @@ private: | ||||
|     static void _audioHandler(dsp::stereo_t *data, int count, void *ctx) { | ||||
|         RecorderModule* _this = (RecorderModule*)ctx; | ||||
|         for (int i = 0; i < count; i++) { | ||||
|             _this->wavSampleBuf[(2*i)] = data[i].l * 32767.0f; | ||||
|             _this->wavSampleBuf[(2*i) + 1] = data[i].r * 32767.0f; | ||||
|             _this->wavSampleBuf[(2*i)] = std::clamp<int>(data[i].l * 32767.0f, -32768, 32767); | ||||
|             _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->samplesWritten += count; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user