Skip to content

Commit

Permalink
Prevent UI lockup and audio speedup when replaying from file
Browse files Browse the repository at this point in the history
  • Loading branch information
williamyang98 committed Jan 26, 2024
1 parent fde4b19 commit 7634b81
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/dab_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
11 changes: 7 additions & 4 deletions src/radio_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -62,13 +64,14 @@ void Radio_Block::reset_radio() {
auto audio_source = std::make_shared<AudioPipelineSource>();
audio_pipeline->add_source(audio_source);
channel.OnAudioData().Attach(
[&controls, audio_source]
[&controls, audio_source, audio_pipeline]
(BasicAudioParams params, tcb::span<const uint8_t> buf) {
if (!controls.GetIsPlayAudio()) return;
auto frame_ptr = reinterpret_cast<const Frame<int16_t>*>(buf.data());
const size_t total_frames = buf.size() / sizeof(Frame<int16_t>);
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);
}
);
}
Expand Down

0 comments on commit 7634b81

Please sign in to comment.