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.
This commit is contained in:
Bill Somerville 2020-12-03 01:49:21 +00:00
parent 94f0af72e3
commit 50d0543c03
No known key found for this signature in database
GPG Key ID: D864B06D1E81618F
3 changed files with 11 additions and 9 deletions

View File

@ -7,6 +7,7 @@
#include <qmath.h>
#include <QDebug>
#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 ()

View File

@ -212,7 +212,7 @@ namespace
auto quint32_max = std::numeric_limits<quint32>::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 ();

View File

@ -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;