Environment variables to set audio buffer sizes and fix Windows Rx timing

The two environment variables:

    WSJT_RX_AUDIO_BUFFER_FRAMES
    WSJT_TX_AUDIO_BUFFER_FRAMES

each can  be defined to  an integer number which  will be used  as the
suggested audio  buffer size for  Rx and Tx respectively.  Not setting
the variable  or setting  it to  zero or less  will cause  the default
buffer size to be used, which should be a good choice for most, if not
all, systems.
This commit is contained in:
Bill Somerville 2020-12-07 20:34:56 +00:00
parent cefc8e2645
commit 60792182ad
No known key found for this signature in database
GPG Key ID: D864B06D1E81618F
4 changed files with 14 additions and 11 deletions

View File

@ -88,17 +88,16 @@ void SoundInput::start(QAudioDeviceInfo const& device, int framesPerBuffer, Audi
//qDebug () << "SoundIn default buffer size (bytes):" << m_stream->bufferSize () << "period size:" << m_stream->periodSize ();
// the Windows MME version of QAudioInput uses 1/5 of the buffer
// size for period size other platforms seem to optimize themselves
#if defined (Q_OS_WIN)
m_stream->setBufferSize (m_stream->format ().bytesForFrames (framesPerBuffer * 5));
#else
Q_UNUSED (framesPerBuffer);
#endif
if (framesPerBuffer > 0)
{
m_stream->setBufferSize (m_stream->format ().bytesForFrames (framesPerBuffer));
}
if (m_sink->initialize (QIODevice::WriteOnly, channel))
{
m_stream->start (sink);
checkStream ();
cummulative_lost_usec_ = -1;
//qDebug () << "SoundIn selected buffer size (bytes):" << m_stream->bufferSize () << "peirod size:" << m_stream->periodSize ();
LOG_DEBUG ("Selected buffer size (bytes): " << m_stream->bufferSize () << " period size: " << m_stream->periodSize ());
}
else
{

View File

@ -111,7 +111,7 @@ void SoundOutput::restart (QIODevice * source)
}
m_stream->setCategory ("production");
m_stream->start (source);
LOG_INFO ("Selected buffer size (bytes): " << m_stream->bufferSize () << " period size: " << m_stream->periodSize ());
LOG_DEBUG ("Selected buffer size (bytes): " << m_stream->bufferSize () << " period size: " << m_stream->periodSize ());
}
void SoundOutput::suspend ()

View File

@ -211,7 +211,7 @@ namespace
QRegularExpression grid_regexp {"\\A(?![Rr]{2}73)[A-Ra-r]{2}[0-9]{2}([A-Xa-x]{2}){0,1}\\z"};
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 default_rx_audio_buffer_frames {-1}; // lets Qt decide
constexpr int default_tx_audio_buffer_frames {-1}; // lets Qt decide
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_rx_audio_buffer_frames {0},
m_tx_audio_buffer_frames {0},
m_msErase {0},
m_secBandChanged {0},
@ -457,7 +458,9 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple,
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);
auto buffer_size = env.value ("WSJT_RX_AUDIO_BUFFER_FRAMES", "0").toInt (&ok);
m_rx_audio_buffer_frames = ok && buffer_size ? buffer_size : default_rx_audio_buffer_frames;
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
@ -939,7 +942,7 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple,
if (!m_config.audio_input_device ().isNull ())
{
Q_EMIT startAudioInputStream (m_config.audio_input_device ()
, rx_chunk_size * m_downSampleFactor
, m_rx_audio_buffer_frames
, m_detector, m_downSampleFactor, m_config.audio_input_channel ());
}
if (!m_config.audio_output_device ().isNull ())
@ -1851,7 +1854,7 @@ void MainWindow::on_actionSettings_triggered() //Setup Dialog
if(m_config.restart_audio_input () && !m_config.audio_input_device ().isNull ()) {
Q_EMIT startAudioInputStream (m_config.audio_input_device ()
, rx_chunk_size * m_downSampleFactor
, m_rx_audio_buffer_frames
, m_detector, m_downSampleFactor
, m_config.audio_input_channel ());
}

View File

@ -404,6 +404,7 @@ private:
SoundInput * m_soundInput;
Modulator * m_modulator;
SoundOutput * m_soundOutput;
int m_rx_audio_buffer_frames;
int m_tx_audio_buffer_frames;
QThread m_audioThread;