swift
Loading...
Searching...
No Matches
threadedtonepairplayer.h
Go to the documentation of this file.
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
5
6#ifndef SWIFT_SOUND_THREADEDTONEPAIRPLAYER_H
7#define SWIFT_SOUND_THREADEDTONEPAIRPLAYER_H
8
9#include <QAudioFormat>
10#include <QAudioSink>
11#include <QBuffer>
12#include <QMap>
13#include <QReadWriteLock>
14#include <QtEndian>
15#include <QtGlobal>
16
18#include "misc/worker.h"
20#include "sound/tonepair.h"
21
22class QTimer;
23
24namespace swift::sound
25{
28 {
30
31 public:
35
37 ~CThreadedTonePairPlayer() override = default;
38
41 void play(int volume, const QList<swift::sound::CTonePair> &tonePairs);
42
45
48
49 protected:
51 void initialize() override;
52
54 void beforeQuit() noexcept override;
55
56 private:
57 void handleStateChanged(QAudio::State newState);
58 void playBuffer();
59 QByteArray getAudioByTonePairs(const QList<CTonePair> &tonePairs);
60 QByteArray generateAudioFromTonePairs(const CTonePair &tonePair);
61
67 void writeAmplitudeToBuffer(double amplitude, unsigned char *bufferPointer);
68
69 swift::misc::audio::CAudioDeviceInfo m_deviceInfo;
70 QAudioSink *m_audioOutput = nullptr;
71 QByteArray m_bufferData;
72 QBuffer m_buffer;
73 QAudioFormat m_audioFormat;
74 QMap<CTonePair, QByteArray> m_tonePairCache;
75 mutable QRecursiveMutex m_mutex;
76 };
77} // namespace swift::sound
78
79#endif // SWIFT_SOUND_THREADEDTONEPAIRPLAYER_H
Base class for a long-lived worker object which lives in its own thread.
Definition worker.h:321
const QObject * owner() const
Owner of the worker.
Definition worker.h:352
Value object encapsulating information of a audio device.
swift::misc::audio::CAudioDeviceInfo getAudioDevice() const
Used audio device.
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.
~CThreadedTonePairPlayer()=default
Destructor.
CThreadedTonePairPlayer(QObject *owner, const QString &name, const swift::misc::audio::CAudioDeviceInfo &device)
Constructor.
bool reinitializeAudio(const swift::misc::audio::CAudioDeviceInfo &device)
Reinitialize audio.
void initialize()
Called when the thread is started.
void beforeQuit() noexcept
Called before quit is called.
Tone pair to be played.
Definition tonepair.h:20
Free functions in swift::misc.
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
#define SWIFT_SOUND_EXPORT
Export a class or function from the library.