Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qaudiosource.cpp
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#include "qaudio.h"
6#include "qaudiodevice.h"
7#include "qaudiosystem_p.h"
8#include "qaudiosource.h"
9
10#include <private/qplatformmediadevices_p.h>
11#include <private/qplatformmediaintegration_p.h>
12
14
86 : QAudioSource({}, format, parent)
87{
88}
89
97 QObject(parent)
98{
99 d = QPlatformMediaIntegration::instance()->mediaDevices()->audioInputDevice(format, audioDevice, parent);
100 if (d) {
102 // if the signal has been emitted from another thread,
103 // the state may be already changed by main one
104 if (state == d->state())
106 });
107 }
108 else
109 qWarning() << ("No audio device detected");
110
111}
112
124{
125 delete d;
126}
127
144{
145 if (!d)
146 return;
147 d->elapsedTime.start();
148 d->start(device);
149}
150
170{
171 if (!d)
172 return nullptr;
173 d->elapsedTime.start();
174 return d->start();
175}
176
182{
183 return d ? d->format() : QAudioFormat();
184}
185
194{
195 if (d)
196 d->stop();
197}
198
204{
205 if (d)
206 d->reset();
207}
208
217{
218 if (d)
219 d->suspend();
220}
221
232{
233 if (d)
234 d->resume();
235}
236
252
264{
265 return d ? d->bufferSize() : 0;
266}
267
276{
277 /*
278 -If not ActiveState|IdleState, return 0
279 -return amount of audio data available to read
280 */
281 return d ? d->bytesReady() : 0;
282}
283
299{
300 if (!d)
301 return;
302 qreal v = qBound(qreal(0.0), volume, qreal(1.0));
303 d->setVolume(v);
304}
305
313{
314 return d ? d->volume() : 1.0;
315}
316
323{
324 return d ? d->processedUSecs() : 0;
325}
326
332#include <qdebug.h>
333
335{
336 return state() == QAudio::StoppedState ? 0 : d->elapsedTime.nsecsElapsed()/1000;
337}
338
344{
345 return d ? d->error() : QAudio::OpenError;
346}
347
353{
354 return d ? d->state() : QAudio::StoppedState;
355}
356
367
368#include "moc_qaudiosource.cpp"
369
IOBluetoothDevice * device
The QAudioDevice class provides an information about audio devices and their functionality.
The QAudioFormat class stores audio stream parameter information.
The QAudioSource class provides an interface for receiving audio data from an audio input device.
qreal volume() const
Returns the input volume.
~QAudioSource()
Destroy this audio input.
void setBufferSize(qsizetype bytes)
Sets the audio buffer size to value bytes.
void setVolume(qreal volume)
Sets the input volume to volume.
void stop()
Stops the audio input, detaching from the system resource.
QAudioSource(const QAudioFormat &format=QAudioFormat(), QObject *parent=nullptr)
Construct a new audio input and attach it to parent.
QtAudio::Error error() const
Returns the error state.
qsizetype bytesAvailable() const
Returns the amount of audio data available to read in bytes.
QtAudio::State state() const
Returns the state of audio processing.
QAudioFormat format() const
Returns the QAudioFormat being used.
qint64 processedUSecs() const
Returns the amount of audio data processed since start() was called in microseconds.
void suspend()
Stops processing audio data, preserving buffered audio data.
qsizetype bufferSize() const
Returns the audio buffer size in bytes.
void resume()
Resumes processing audio data after a suspend().
void reset()
Drops all audio data in the buffers, resets buffers to zero.
qint64 elapsedUSecs() const
Returns the microseconds since start() was called, including time in Idle and Suspend states.
QIODevice * start()
Returns a pointer to the internal QIODevice being used to transfer data from the system's audio input...
void stateChanged(QAudio::State state)
This signal is emitted when the device state has changed.
void stateChanged(QAudio::State state)
void start() noexcept
\typealias QElapsedTimer::Duration Synonym for std::chrono::nanoseconds.
qint64 nsecsElapsed() const noexcept
\inmodule QtCore \reentrant
Definition qiodevice.h:34
\inmodule QtCore
Definition qobject.h:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
virtual QAudio::State state() const =0
virtual void stop()=0
virtual QAudio::Error error() const =0
virtual qreal volume() const =0
QElapsedTimer elapsedTime
virtual qsizetype bytesReady() const =0
virtual QAudioFormat format() const =0
virtual qint64 processedUSecs() const =0
virtual void setBufferSize(qsizetype value)=0
virtual void reset()=0
virtual qsizetype bufferSize() const =0
virtual void resume()=0
virtual void start(QIODevice *device)=0
virtual void setVolume(qreal)=0
virtual void suspend()=0
static QPlatformMediaIntegration * instance()
State
Definition qaudio.h:29
@ StoppedState
Definition qaudio.h:29
Error
Definition qaudio.h:28
@ OpenError
Definition qaudio.h:28
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define qWarning
Definition qlogging.h:166
constexpr const T & qBound(const T &min, const T &val, const T &max)
Definition qminmax.h:44
GLsizei const GLfloat * v
[13]
GLint GLsizei GLsizei GLenum format
#define emit
ptrdiff_t qsizetype
Definition qtypes.h:165
long long qint64
Definition qtypes.h:60
double qreal
Definition qtypes.h:187