JS8Call-Improved master
Loading...
Searching...
No Matches
NotificationSoundOutput.h
Go to the documentation of this file.
1
5
6#pragma once
7
8#include <QAudioDevice>
9#include <QAudioFormat>
10#include <QAudioSink>
11#include <QBuffer>
12#include <QObject>
13#include <qmath.h>
14
15#include <memory>
16
24class NotificationSoundOutput : public QObject
25{
26 Q_OBJECT
27
28public:
33 explicit NotificationSoundOutput(QObject *parent = nullptr);
34
38 ~NotificationSoundOutput() override;
39
49 void setDevice(QAudioDevice const &device, unsigned msBuffer);
50
55 void setAttenuation(qreal a);
56
66 void play(QByteArray const &data, QAudioFormat const &format);
67
71 void stop();
72
73signals:
78 void status(QString message);
79
84 void error(QString message);
85
86private slots:
91 void handleStateChanged(QAudio::State newState);
92
93private:
100 void release();
101
102 QAudioDevice m_device;
103 std::unique_ptr<QAudioSink> m_sink;
104 std::unique_ptr<QBuffer> m_buffer;
105 QAudioFormat m_currentFormat;
106 qreal m_volume = 1.0;
107 unsigned m_msBuffer = 0;
108};
void status(QString message)
Emitted to provide informational status messages.
NotificationSoundOutput(QObject *parent=nullptr)
Construct a NotificationSoundOutput instance.
Definition NotificationSoundOutput.cpp:15
void error(QString message)
Emitted when an error occurs during setup or playback.
~NotificationSoundOutput() override
Destroy the NotificationSoundOutput and release audio resources.
Definition NotificationSoundOutput.cpp:20
void setAttenuation(qreal a)
Set attenuation factor applied to played audio.
Definition NotificationSoundOutput.cpp:44
void play(QByteArray const &data, QAudioFormat const &format)
Play the provided audio data using the given format.
Definition NotificationSoundOutput.cpp:60
void stop()
Stop playback immediately and release the playback buffer.
Definition NotificationSoundOutput.cpp:133
void setDevice(QAudioDevice const &device, unsigned msBuffer)
Select the audio output device and set the internal buffer size.
Definition NotificationSoundOutput.cpp:33