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