From 50d0543c0384437a164816f929e033b104b72049 Mon Sep 17 00:00:00 2001 From: Bill Somerville Date: Thu, 3 Dec 2020 01:49:21 +0000 Subject: [PATCH] Test version with environment variable to set Tx audio buffer size WSJT_TX_AUDIO_BUFFER_FRAMES takes the following values: -1 - use Qt/system default 0 - use 200 mS (WSJT-X default) +ve integer - value is number of frames at 48 kHz -1 is likely to be a good choice on Windows and may macOS. 0 has proven to be good on Windows. On Linux 0 may be OK but we need to try other values. The value is only a hint, the actual value used along with the period size (the size of each chunk of samples requested by the system) is printed in an info level diagnostic message at the start of each transmission. --- Audio/soundout.cpp | 9 +++------ widgets/mainwindow.cpp | 10 +++++++--- widgets/mainwindow.h | 1 + 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Audio/soundout.cpp b/Audio/soundout.cpp index 6a99afd34..54b765e22 100644 --- a/Audio/soundout.cpp +++ b/Audio/soundout.cpp @@ -7,6 +7,7 @@ #include #include +#include "Logger.hpp" #include "Audio/AudioDevice.hpp" #include "moc_soundout.cpp" @@ -104,17 +105,13 @@ void SoundOutput::restart (QIODevice * source) // Windows implementation seems to forget the buffer size after a // stop. //qDebug () << "SoundOut default buffer size (bytes):" << m_stream->bufferSize () << "period size:" << m_stream->periodSize (); - if (m_framesBuffered) + if (m_framesBuffered > 0) { -#if defined (Q_OS_WIN) m_stream->setBufferSize (m_stream->format().bytesForFrames (m_framesBuffered)); -#else - m_stream->setBufferSize (m_stream->format().bytesForFrames (48000 / 10)); -#endif } m_stream->setCategory ("game"); m_stream->start (source); - // qDebug () << "SoundOut selected buffer size (bytes):" << m_stream->bufferSize () << "period size:" << m_stream->periodSize (); + LOG_INFO ("Selected buffer size (bytes): " << m_stream->bufferSize () << " period size: " << m_stream->periodSize ()); } void SoundOutput::suspend () diff --git a/widgets/mainwindow.cpp b/widgets/mainwindow.cpp index 7e7bf0ebf..aaec4e558 100644 --- a/widgets/mainwindow.cpp +++ b/widgets/mainwindow.cpp @@ -212,7 +212,7 @@ namespace auto quint32_max = std::numeric_limits::max (); constexpr int N_WIDGETS {36}; constexpr int rx_chunk_size {3456}; // audio samples at 12000 Hz - constexpr int tx_audio_buffer_size {48000 / 5}; // audio frames at 48000 Hz + constexpr int default_tx_audio_buffer_frames {48000 / 5}; // audio frames at 48000 Hz bool message_is_73 (int type, QStringList const& msg_parts) { @@ -265,6 +265,7 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple, m_soundInput {new SoundInput}, m_modulator {new Modulator {TX_SAMPLE_RATE, NTMAX}}, m_soundOutput {new SoundOutput}, + m_tx_audio_buffer_frames {0}, m_msErase {0}, m_secBandChanged {0}, m_freqNominal {0}, @@ -455,6 +456,9 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple, m_modulator->moveToThread (&m_audioThread); m_soundInput->moveToThread (&m_audioThread); m_detector->moveToThread (&m_audioThread); + bool ok; + auto buffer_size = env.value ("WSJT_TX_AUDIO_BUFFER_FRAMES", "0").toInt (&ok); + m_tx_audio_buffer_frames = ok && buffer_size ? buffer_size : default_tx_audio_buffer_frames; // hook up sound output stream slots & signals and disposal connect (this, &MainWindow::initializeAudioOutputStream, m_soundOutput, &SoundOutput::setFormat); @@ -942,7 +946,7 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple, { Q_EMIT initializeAudioOutputStream (m_config.audio_output_device () , AudioDevice::Mono == m_config.audio_output_channel () ? 1 : 2 - , tx_audio_buffer_size); + , m_tx_audio_buffer_frames); } Q_EMIT transmitFrequency (ui->TxFreqSpinBox->value () - m_XIT); @@ -1855,7 +1859,7 @@ void MainWindow::on_actionSettings_triggered() //Setup Dialog if(m_config.restart_audio_output () && !m_config.audio_output_device ().isNull ()) { Q_EMIT initializeAudioOutputStream (m_config.audio_output_device () , AudioDevice::Mono == m_config.audio_output_channel () ? 1 : 2 - , tx_audio_buffer_size); + , m_tx_audio_buffer_frames); } displayDialFrequency (); diff --git a/widgets/mainwindow.h b/widgets/mainwindow.h index dd53e8837..878e9c6c3 100644 --- a/widgets/mainwindow.h +++ b/widgets/mainwindow.h @@ -404,6 +404,7 @@ private: SoundInput * m_soundInput; Modulator * m_modulator; SoundOutput * m_soundOutput; + int m_tx_audio_buffer_frames; QThread m_audioThread; qint64 m_msErase;