Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qaudiosink.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4
5#ifndef QAUDIOOUTPUT_H
6#define QAUDIOOUTPUT_H
7
8#include <QtMultimedia/qaudiodevice.h>
9#include <QtMultimedia/qaudioformat.h>
10#include <QtMultimedia/qtaudio.h>
11#include <QtMultimedia/qtmultimediaglobal.h>
12#include <QtCore/qiodevice.h>
13
14QT_BEGIN_NAMESPACE
15
16class QPlatformAudioSink;
17
18class Q_MULTIMEDIA_EXPORT QAudioSink : public QObject
19{
20 Q_OBJECT
21
22public:
23 explicit QAudioSink(const QAudioFormat &format = QAudioFormat(), QObject *parent = nullptr);
24 explicit QAudioSink(const QAudioDevice &audioDeviceInfo, const QAudioFormat &format = QAudioFormat(), QObject *parent = nullptr);
25 ~QAudioSink() override;
26
27 bool isNull() const { return !d; }
28
29 QAudioFormat format() const;
30
31 void start(QIODevice *device);
32 QIODevice* start();
33
34 template <typename Callback, QtAudio::if_audio_sink_callback<Callback> = true>
35 void start(Callback &&cb)
36 {
37 Q_ASSERT(QtAudioPrivate::isNonnullFunction(cb));
38
39 if constexpr (!std::is_copy_constructible_v<Callback>) {
40 // poor man's move-only function
41 using CallbackType = typename QtAudioPrivate::GetSampleType<Callback>::type;
42 auto callback = std::make_shared<std::decay_t<Callback>>(std::forward<Callback>(cb));
43 start([callback = std::move(callback)](QSpan<CallbackType> arg) {
44 (*callback)(arg);
45 });
46 } else {
47 startABIImpl(QtAudioPrivate::AudioSinkCallback(std::forward<Callback>(cb)));
48 }
49 }
50
51 void stop();
52 void reset();
53 void suspend();
54 void resume();
55
56 void setBufferSize(qsizetype bytes);
57 qsizetype bufferSize() const;
58
59 void setBufferFrameCount(qsizetype framesCount);
60 qsizetype bufferFrameCount() const;
61
62 qsizetype bytesFree() const;
63 qsizetype framesFree() const;
64
65 qint64 processedUSecs() const;
66 qint64 elapsedUSecs() const;
67
68 QtAudio::Error error() const;
69 QtAudio::State state() const;
70
71 void setVolume(qreal);
72 qreal volume() const;
73
74Q_SIGNALS:
75#if defined(Q_QDOC)
76 void stateChanged(QtAudio::State state);
77#else
78 // use QAudio here to keep string-based connections working
79 void stateChanged(QAudio::State state);
80#endif
81
82private:
83 template <typename T>
84 void startImpl(T &&callback);
85
86 void startABIImpl(QtAudioPrivate::AudioSinkCallback &&);
87
88 Q_DISABLE_COPY(QAudioSink)
89
90 friend class QPlatformAudioSink;
91 QPlatformAudioSink *d;
92};
93
94QT_END_NAMESPACE
95
96#endif // QAUDIOOUTPUT_H
The QAudioSink class provides an interface for sending audio data to an audio output device.
Definition qaudiosink.h:19
Combined button and popup list for selecting options.
static bool validateFormatAtStart(QPlatformAudioSink *d)