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