Merge branch 'feat-dropped-frames' into develop

This commit is contained in:
Bill Somerville 2020-09-12 04:44:09 +01:00
commit c032f0655b
No known key found for this signature in database
GPG Key ID: D864B06D1E81618F
4 changed files with 55 additions and 32 deletions

View File

@ -1,5 +1,7 @@
#include "soundin.h"
#include <cstdlib>
#include <cmath>
#include <QAudioDeviceInfo>
#include <QAudioFormat>
#include <QAudioInput>
@ -166,15 +168,21 @@ void SoundInput::reset (bool report_dropped_frames)
{
if (m_stream)
{
if (cummulative_lost_usec_ >= 0 // don't report first time as we
// don't yet known latency
&& report_dropped_frames)
auto elapsed_usecs = m_stream->elapsedUSecs ();
while (std::abs (elapsed_usecs - m_stream->processedUSecs ())
> 24 * 60 * 60 * 500000ll) // half day
{
auto lost_usec = m_stream->elapsedUSecs () - m_stream->processedUSecs () - cummulative_lost_usec_;
// QAudioInput::elapsedUSecs() wraps after 24 hours
elapsed_usecs += 24 * 60 * 60 * 1000000ll;
}
// don't report first time as we don't yet known latency
if (cummulative_lost_usec_ != std::numeric_limits<qint64>::min () && report_dropped_frames)
{
auto lost_usec = elapsed_usecs - m_stream->processedUSecs () - cummulative_lost_usec_;
Q_EMIT dropped_frames (m_stream->format ().framesForDuration (lost_usec), lost_usec);
//qDebug () << "SoundInput::reset: frames dropped:" << m_stream->format ().framesForDuration (lost_usec) << "sec:" << lost_usec / 1.e6;
}
cummulative_lost_usec_ = m_stream->elapsedUSecs () - m_stream->processedUSecs ();
cummulative_lost_usec_ = elapsed_usecs - m_stream->processedUSecs ();
}
}

View File

@ -2,6 +2,7 @@
#ifndef SOUNDIN_H__
#define SOUNDIN_H__
#include <limits>
#include <QObject>
#include <QString>
#include <QDateTime>
@ -24,7 +25,7 @@ public:
SoundInput (QObject * parent = nullptr)
: QObject {parent}
, m_sink {nullptr}
, cummulative_lost_usec_ {0}
, cummulative_lost_usec_ {std::numeric_limits<qint64>::min ()}
{
}

View File

@ -1522,19 +1522,25 @@ void Configuration::impl::find_audio_devices ()
// retrieve audio input device
//
auto saved_name = settings_->value ("SoundInName").toString ();
audio_input_device_ = find_audio_device (QAudio::AudioInput, ui_->sound_input_combo_box, saved_name);
audio_input_channel_ = AudioDevice::fromString (settings_->value ("AudioInputChannel", "Mono").toString ());
update_audio_channels (ui_->sound_input_combo_box, ui_->sound_input_combo_box->currentIndex (), ui_->sound_input_channel_combo_box, false);
ui_->sound_input_channel_combo_box->setCurrentIndex (audio_input_channel_);
if (audio_input_device_.deviceName () != saved_name)
{
audio_input_device_ = find_audio_device (QAudio::AudioInput, ui_->sound_input_combo_box, saved_name);
audio_input_channel_ = AudioDevice::fromString (settings_->value ("AudioInputChannel", "Mono").toString ());
update_audio_channels (ui_->sound_input_combo_box, ui_->sound_input_combo_box->currentIndex (), ui_->sound_input_channel_combo_box, false);
ui_->sound_input_channel_combo_box->setCurrentIndex (audio_input_channel_);
}
//
// retrieve audio output device
//
saved_name = settings_->value("SoundOutName").toString();
audio_output_channel_ = AudioDevice::fromString (settings_->value ("AudioOutputChannel", "Mono").toString ());
audio_output_device_ = find_audio_device (QAudio::AudioOutput, ui_->sound_output_combo_box, saved_name);
update_audio_channels (ui_->sound_output_combo_box, ui_->sound_output_combo_box->currentIndex (), ui_->sound_output_channel_combo_box, true);
ui_->sound_output_channel_combo_box->setCurrentIndex (audio_output_channel_);
if (audio_output_device_.deviceName () != saved_name)
{
audio_output_channel_ = AudioDevice::fromString (settings_->value ("AudioOutputChannel", "Mono").toString ());
audio_output_device_ = find_audio_device (QAudio::AudioOutput, ui_->sound_output_combo_box, saved_name);
update_audio_channels (ui_->sound_output_combo_box, ui_->sound_output_combo_box->currentIndex (), ui_->sound_output_channel_combo_box, true);
ui_->sound_output_channel_combo_box->setCurrentIndex (audio_output_channel_);
}
}
void Configuration::impl::write_settings ()
@ -1836,6 +1842,8 @@ int Configuration::impl::exec ()
rig_changed_ = false;
initialize_models ();
lazy_models_load (ui_->configuration_tabs->currentIndex ());
return QDialog::exec();
}
@ -2762,28 +2770,30 @@ QAudioDeviceInfo Configuration::impl::find_audio_device (QAudio::Mode mode, QCom
using std::copy;
using std::back_inserter;
combo_box->clear ();
int current_index = -1;
auto const& devices = QAudioDeviceInfo::availableDevices (mode);
Q_FOREACH (auto const& p, devices)
if (device_name.size ())
{
// qDebug () << "Audio device: input:" << (QAudio::AudioInput == mode) << "name:" << p.deviceName () << "preferred format:" << p.preferredFormat () << "endians:" << p.supportedByteOrders () << "codecs:" << p.supportedCodecs () << "channels:" << p.supportedChannelCounts () << "rates:" << p.supportedSampleRates () << "sizes:" << p.supportedSampleSizes () << "types:" << p.supportedSampleTypes ();
combo_box->clear ();
// convert supported channel counts into something we can store in the item model
QList<QVariant> channel_counts;
auto scc = p.supportedChannelCounts ();
copy (scc.cbegin (), scc.cend (), back_inserter (channel_counts));
combo_box->addItem (p.deviceName (), QVariant::fromValue (audio_info_type {p, channel_counts}));
if (p.deviceName () == device_name)
int current_index = -1;
auto const& devices = QAudioDeviceInfo::availableDevices (mode);
Q_FOREACH (auto const& p, devices)
{
current_index = combo_box->count () - 1;
combo_box->setCurrentIndex (current_index);
return p;
// convert supported channel counts into something we can store in the item model
QList<QVariant> channel_counts;
auto scc = p.supportedChannelCounts ();
copy (scc.cbegin (), scc.cend (), back_inserter (channel_counts));
combo_box->addItem (p.deviceName (), QVariant::fromValue (audio_info_type {p, channel_counts}));
if (p.deviceName () == device_name)
{
current_index = combo_box->count () - 1;
combo_box->setCurrentIndex (current_index);
return p;
}
}
combo_box->setCurrentIndex (current_index);
}
combo_box->setCurrentIndex (current_index);
return {};
}

View File

@ -480,10 +480,14 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple,
}
if (dropped_frames > 48000) // 1 second
{
auto period = qt_truncate_date_time_to (QDateTime::currentDateTimeUtc ().addMSecs (-m_TRperiod / 2.), m_TRperiod * 1e3);
MessageBox::warning_message (this
, tr ("Audio Source")
, tr ("Reduce system load")
, tr ("Excessive dropped samples - %1 (%2 sec) audio frames dropped").arg (dropped_frames).arg (usec / 1.e6, 5, 'f', 3));
, tr ("Excessive dropped samples - %1 (%2 sec) audio frames dropped in period starting %3")
.arg (dropped_frames)
.arg (usec / 1.e6, 5, 'f', 3)
.arg (period.toString ("hh:mm:ss")));
}
});
connect (&m_audioThread, &QThread::finished, m_soundInput, &QObject::deleteLater);