mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2025-08-03 06:32:26 -04:00
Merge branch 'feat-dropped-frames' into develop
This commit is contained in:
commit
c032f0655b
@ -1,5 +1,7 @@
|
|||||||
#include "soundin.h"
|
#include "soundin.h"
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cmath>
|
||||||
#include <QAudioDeviceInfo>
|
#include <QAudioDeviceInfo>
|
||||||
#include <QAudioFormat>
|
#include <QAudioFormat>
|
||||||
#include <QAudioInput>
|
#include <QAudioInput>
|
||||||
@ -166,15 +168,21 @@ void SoundInput::reset (bool report_dropped_frames)
|
|||||||
{
|
{
|
||||||
if (m_stream)
|
if (m_stream)
|
||||||
{
|
{
|
||||||
if (cummulative_lost_usec_ >= 0 // don't report first time as we
|
auto elapsed_usecs = m_stream->elapsedUSecs ();
|
||||||
// don't yet known latency
|
while (std::abs (elapsed_usecs - m_stream->processedUSecs ())
|
||||||
&& report_dropped_frames)
|
> 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);
|
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;
|
//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 ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#ifndef SOUNDIN_H__
|
#ifndef SOUNDIN_H__
|
||||||
#define SOUNDIN_H__
|
#define SOUNDIN_H__
|
||||||
|
|
||||||
|
#include <limits>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
@ -24,7 +25,7 @@ public:
|
|||||||
SoundInput (QObject * parent = nullptr)
|
SoundInput (QObject * parent = nullptr)
|
||||||
: QObject {parent}
|
: QObject {parent}
|
||||||
, m_sink {nullptr}
|
, m_sink {nullptr}
|
||||||
, cummulative_lost_usec_ {0}
|
, cummulative_lost_usec_ {std::numeric_limits<qint64>::min ()}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1522,20 +1522,26 @@ void Configuration::impl::find_audio_devices ()
|
|||||||
// retrieve audio input device
|
// retrieve audio input device
|
||||||
//
|
//
|
||||||
auto saved_name = settings_->value ("SoundInName").toString ();
|
auto saved_name = settings_->value ("SoundInName").toString ();
|
||||||
|
if (audio_input_device_.deviceName () != saved_name)
|
||||||
|
{
|
||||||
audio_input_device_ = find_audio_device (QAudio::AudioInput, ui_->sound_input_combo_box, 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 ());
|
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);
|
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_);
|
ui_->sound_input_channel_combo_box->setCurrentIndex (audio_input_channel_);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// retrieve audio output device
|
// retrieve audio output device
|
||||||
//
|
//
|
||||||
saved_name = settings_->value("SoundOutName").toString();
|
saved_name = settings_->value("SoundOutName").toString();
|
||||||
|
if (audio_output_device_.deviceName () != saved_name)
|
||||||
|
{
|
||||||
audio_output_channel_ = AudioDevice::fromString (settings_->value ("AudioOutputChannel", "Mono").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);
|
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);
|
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_);
|
ui_->sound_output_channel_combo_box->setCurrentIndex (audio_output_channel_);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Configuration::impl::write_settings ()
|
void Configuration::impl::write_settings ()
|
||||||
{
|
{
|
||||||
@ -1836,6 +1842,8 @@ int Configuration::impl::exec ()
|
|||||||
rig_changed_ = false;
|
rig_changed_ = false;
|
||||||
|
|
||||||
initialize_models ();
|
initialize_models ();
|
||||||
|
lazy_models_load (ui_->configuration_tabs->currentIndex ());
|
||||||
|
|
||||||
return QDialog::exec();
|
return QDialog::exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2762,13 +2770,14 @@ QAudioDeviceInfo Configuration::impl::find_audio_device (QAudio::Mode mode, QCom
|
|||||||
using std::copy;
|
using std::copy;
|
||||||
using std::back_inserter;
|
using std::back_inserter;
|
||||||
|
|
||||||
|
if (device_name.size ())
|
||||||
|
{
|
||||||
combo_box->clear ();
|
combo_box->clear ();
|
||||||
|
|
||||||
int current_index = -1;
|
int current_index = -1;
|
||||||
auto const& devices = QAudioDeviceInfo::availableDevices (mode);
|
auto const& devices = QAudioDeviceInfo::availableDevices (mode);
|
||||||
Q_FOREACH (auto const& p, devices)
|
Q_FOREACH (auto const& p, devices)
|
||||||
{
|
{
|
||||||
// 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 ();
|
|
||||||
|
|
||||||
// convert supported channel counts into something we can store in the item model
|
// convert supported channel counts into something we can store in the item model
|
||||||
QList<QVariant> channel_counts;
|
QList<QVariant> channel_counts;
|
||||||
@ -2784,6 +2793,7 @@ QAudioDeviceInfo Configuration::impl::find_audio_device (QAudio::Mode mode, QCom
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
combo_box->setCurrentIndex (current_index);
|
combo_box->setCurrentIndex (current_index);
|
||||||
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -480,10 +480,14 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple,
|
|||||||
}
|
}
|
||||||
if (dropped_frames > 48000) // 1 second
|
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
|
MessageBox::warning_message (this
|
||||||
, tr ("Audio Source")
|
, tr ("Audio Source")
|
||||||
, tr ("Reduce system load")
|
, 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);
|
connect (&m_audioThread, &QThread::finished, m_soundInput, &QObject::deleteLater);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user