diff --git a/src/dab_module.cpp b/src/dab_module.cpp index 7cd3f89..714fcb1 100644 --- a/src/dab_module.cpp +++ b/src/dab_module.cpp @@ -120,7 +120,7 @@ DABModule::~DABModule() { void DABModule::enable() { is_enabled = true; - if (!vfo) { + if (vfo == nullptr) { // NOTE: Use the entire 2.048e6 frequency range so that if we have a large // frequency offset the VFO doesn't low pass filter out subcarriers const float MIN_BANDWIDTH = 2.048e6f; @@ -137,7 +137,7 @@ void DABModule::enable() { } void DABModule::disable() { is_enabled = false; - if (vfo) { + if (vfo != nullptr) { ofdm_demodulator_sink->stop(); sigpath::vfoManager.deleteVFO(vfo); vfo = nullptr; diff --git a/src/radio_block.cpp b/src/radio_block.cpp index 403cea4..f7348fa 100644 --- a/src/radio_block.cpp +++ b/src/radio_block.cpp @@ -34,9 +34,11 @@ Radio_Block::Radio_Block(size_t ofdm_total_threads, size_t dab_total_threads) while (m_is_radio_thread_running) { const size_t length = m_ofdm_to_radio_buffer->read(data); if (length != data.size()) break; - auto lock = std::scoped_lock(m_mutex_basic_radio); + auto lock = std::unique_lock(m_mutex_basic_radio); if (m_basic_radio == nullptr) continue; - m_basic_radio->Process(data); + auto radio = m_basic_radio; + lock.unlock(); // prevent locking in gui thread + radio->Process(data); } }); // setup audio @@ -62,13 +64,14 @@ void Radio_Block::reset_radio() { auto audio_source = std::make_shared(); audio_pipeline->add_source(audio_source); channel.OnAudioData().Attach( - [&controls, audio_source] + [&controls, audio_source, audio_pipeline] (BasicAudioParams params, tcb::span buf) { if (!controls.GetIsPlayAudio()) return; auto frame_ptr = reinterpret_cast*>(buf.data()); const size_t total_frames = buf.size() / sizeof(Frame); auto frame_buf = tcb::span(frame_ptr, total_frames); - audio_source->write(frame_buf, float(params.frequency), false); + const bool is_blocking = audio_pipeline->get_sink() != nullptr; + audio_source->write(frame_buf, float(params.frequency), is_blocking); } ); }