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