mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 17:35:34 +08:00
refs #129 , start method as proposed by RW in https://dev.vatsim-germany.org/issues/129#note-4 , using lambda.
On top addded a simple check to avoid overlapping SELCAL tones
This commit is contained in:
@@ -9,12 +9,15 @@
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
|
|
||||||
using namespace BlackMisc::Aviation;
|
using namespace BlackMisc::Aviation;
|
||||||
using namespace BlackMisc::PhysicalQuantities;
|
using namespace BlackMisc::PhysicalQuantities;
|
||||||
using namespace BlackMisc::Voice;
|
using namespace BlackMisc::Voice;
|
||||||
|
|
||||||
namespace BlackSound
|
namespace BlackSound
|
||||||
{
|
{
|
||||||
|
QDateTime CSoundGenerator::selcalStarted = QDateTime::currentDateTimeUtc();
|
||||||
|
|
||||||
CSoundGenerator::CSoundGenerator(const QAudioDeviceInfo &device, const QAudioFormat &format, const QList<Tone> &tones, PlayMode mode, QObject *parent)
|
CSoundGenerator::CSoundGenerator(const QAudioDeviceInfo &device, const QAudioFormat &format, const QList<Tone> &tones, PlayMode mode, QObject *parent)
|
||||||
: QIODevice(parent),
|
: QIODevice(parent),
|
||||||
m_tones(tones), m_position(0), m_playMode(mode), m_endReached(false), m_oneCycleDurationMs(calculateDurationMs(tones)),
|
m_tones(tones), m_position(0), m_playMode(mode), m_endReached(false), m_oneCycleDurationMs(calculateDurationMs(tones)),
|
||||||
@@ -71,7 +74,9 @@ namespace BlackSound
|
|||||||
{
|
{
|
||||||
this->m_ownThread = new QThread(); // deleted by signals, hence no parent
|
this->m_ownThread = new QThread(); // deleted by signals, hence no parent
|
||||||
this->moveToThread(this->m_ownThread);
|
this->moveToThread(this->m_ownThread);
|
||||||
connect(this, &CSoundGenerator::startThread, this, &CSoundGenerator::start);
|
// connect(this, &CSoundGenerator::startThread, this, &CSoundGenerator::start);
|
||||||
|
|
||||||
|
connect(this->m_ownThread, &QThread::started, this, [ = ]() { this->start(volume, false); });
|
||||||
connect(this, &CSoundGenerator::stopping, this->m_ownThread, &QThread::quit);
|
connect(this, &CSoundGenerator::stopping, this->m_ownThread, &QThread::quit);
|
||||||
|
|
||||||
// in auto delete mode force deleteLater when thread is finished
|
// in auto delete mode force deleteLater when thread is finished
|
||||||
@@ -80,7 +85,6 @@ namespace BlackSound
|
|||||||
|
|
||||||
// start thread and begin processing by calling start via signal startThread
|
// start thread and begin processing by calling start via signal startThread
|
||||||
this->m_ownThread->start();
|
this->m_ownThread->start();
|
||||||
emit startThread(volume, false); // this signal will trigger start in own thread
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSoundGenerator::stop(bool destructor)
|
void CSoundGenerator::stop(bool destructor)
|
||||||
@@ -261,7 +265,7 @@ namespace BlackSound
|
|||||||
QAudioFormat format;
|
QAudioFormat format;
|
||||||
format.setSampleRate(44100);
|
format.setSampleRate(44100);
|
||||||
format.setChannelCount(1);
|
format.setChannelCount(1);
|
||||||
format.setSampleSize(16);
|
format.setSampleSize(16); // 8 or 16 works
|
||||||
format.setCodec("audio/pcm");
|
format.setCodec("audio/pcm");
|
||||||
format.setByteOrder(QAudioFormat::LittleEndian);
|
format.setByteOrder(QAudioFormat::LittleEndian);
|
||||||
format.setSampleType(QAudioFormat::SignedInt);
|
format.setSampleType(QAudioFormat::SignedInt);
|
||||||
@@ -345,6 +349,8 @@ namespace BlackSound
|
|||||||
|
|
||||||
void CSoundGenerator::playSelcal(qint32 volume, const CSelcal &selcal, const CAudioDevice &audioDevice)
|
void CSoundGenerator::playSelcal(qint32 volume, const CSelcal &selcal, const CAudioDevice &audioDevice)
|
||||||
{
|
{
|
||||||
|
if (CSoundGenerator::selcalStarted.msecsTo(QDateTime::currentDateTimeUtc()) < 2500) return; // simple check not to play 2 SELCAL at the same time
|
||||||
|
CSoundGenerator::selcalStarted = QDateTime::currentDateTimeUtc();
|
||||||
CSoundGenerator::playSelcal(volume, selcal, CSoundGenerator::findClosestOutputDevice(audioDevice));
|
CSoundGenerator::playSelcal(volume, selcal, CSoundGenerator::findClosestOutputDevice(audioDevice));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include <QIODevice>
|
#include <QIODevice>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
#include <QDateTime>
|
||||||
#include <QAudioFormat>
|
#include <QAudioFormat>
|
||||||
#include <QAudioOutput>
|
#include <QAudioOutput>
|
||||||
#include <QAudioDeviceInfo>
|
#include <QAudioDeviceInfo>
|
||||||
@@ -242,13 +243,6 @@ namespace BlackSound
|
|||||||
void startInOwnThread(int volume);
|
void startInOwnThread(int volume);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/*!
|
|
||||||
* \brief Used to start in own thread
|
|
||||||
* \param volume 0..100
|
|
||||||
* \param pull
|
|
||||||
* \remarks only works with push, but signature has to be identical with CSoundGenerator::start
|
|
||||||
*/
|
|
||||||
void startThread(int volume, bool pull);
|
|
||||||
|
|
||||||
//! \brief Generator is stopping
|
//! \brief Generator is stopping
|
||||||
void stopping();
|
void stopping();
|
||||||
@@ -278,6 +272,7 @@ namespace BlackSound
|
|||||||
QTimer *m_pushTimer; /*!< Push mode timer */
|
QTimer *m_pushTimer; /*!< Push mode timer */
|
||||||
QIODevice *m_pushModeIODevice; /*!< IO device when used in push mode */
|
QIODevice *m_pushModeIODevice; /*!< IO device when used in push mode */
|
||||||
QThread *m_ownThread;
|
QThread *m_ownThread;
|
||||||
|
static QDateTime selcalStarted;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Duration of these tones
|
* \brief Duration of these tones
|
||||||
|
|||||||
Reference in New Issue
Block a user