swift
selcalplayer.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
4 #include "selcalplayer.h"
5 
6 #include <QTimer>
7 
8 using namespace swift::misc;
9 using namespace swift::misc::audio;
10 using namespace swift::misc::aviation;
11 using namespace swift::misc::physical_quantities;
12 
13 namespace swift::sound
14 {
15  CSelcalPlayer::CSelcalPlayer(const CAudioDeviceInfo &device, QObject *parent)
16  : QObject(parent), m_threadedPlayer(new CThreadedTonePairPlayer(this, "CSelcalPlayer", device))
17  {
18  m_threadedPlayer->start();
19  }
20 
22 
23  void CSelcalPlayer::gracefulShutdown() { m_threadedPlayer->quitAndWait(); }
24 
25  std::chrono::milliseconds CSelcalPlayer::play(int volume, const CSelcal &selcal)
26  {
27  std::chrono::milliseconds duration {};
28  if (selcal.isValid())
29  {
30  const QList<CFrequency> frequencies = selcal.getFrequencies();
31  Q_ASSERT(frequencies.size() == 4);
32  const std::chrono::milliseconds oneSec(1000);
33  const CTonePair t1(frequencies.at(0), frequencies.at(1), oneSec);
34  const CTonePair t2({}, {}, oneSec / 5);
35  const CTonePair t3(frequencies.at(2), frequencies.at(3), oneSec);
36  QList<CTonePair> tonePairs;
37  tonePairs << t1 << t2 << t3;
38  m_threadedPlayer->play(volume, tonePairs);
39  duration = std::chrono::milliseconds(2500);
40  }
41  return duration;
42  }
43 } // namespace swift::sound
void quitAndWait() noexcept final
Calls quit() and blocks until the thread is finished.
Definition: worker.cpp:205
void start(QThread::Priority priority=QThread::InheritPriority)
Starts a thread and moves the worker into it.
Definition: worker.cpp:166
Value object encapsulating information of a audio device.
Value object for SELCAL.
Definition: selcal.h:31
bool isValid() const
Is valid?
Definition: selcal.h:43
QList< physical_quantities::CFrequency > getFrequencies() const
List of 4 frequencies, if list is empty SELCAL code is not valid.
Definition: selcal.cpp:37
void gracefulShutdown()
Stop the player thread.
std::chrono::milliseconds play(int volume, const swift::misc::aviation::CSelcal &selcal)
Play SELCAL.
virtual ~CSelcalPlayer()
Destructor.
Threaded tone player. Don't use it directly but use.
void play(int volume, const QList< swift::sound::CTonePair > &tonePairs)
Play the list of tones. If the player is currently active, this call will be ignored.
Tone pair to be played.
Definition: tonepair.h:20
Free functions in swift::misc.