Qt 6.x
The Qt SDK
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
87{
88}
89
98{
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
248{
249 if (d)
251}
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
363
364#include "moc_qaudiosource.cpp"
365
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.
QAudio::Error error() const
Returns the error state.
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.
qsizetype bytesAvailable() const
Returns the amount of audio data available to read in bytes.
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.
QAudio::State state() const
Returns the state of audio processing.
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 start() noexcept
Starts this timer.
qint64 nsecsElapsed() const noexcept
\inmodule QtCore \reentrant
Definition qiodevice.h:34
\inmodule QtCore
Definition qobject.h:90
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:311
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2823
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
void stateChanged(QAudio::State state)
virtual void setVolume(qreal)=0
virtual void suspend()=0
static QPlatformMediaDevices * instance()
QPlatformAudioSource * audioInputDevice(const QAudioFormat &format, const QAudioDevice &deviceInfo, QObject *parent)
State
\value ActiveState Audio data is being processed, this state is set after start() is called and while...
Definition qaudio.h:25
@ StoppedState
Definition qaudio.h:25
Error
\value NoError No errors have occurred \value OpenError An error occurred opening the audio device \v...
Definition qaudio.h:24
@ OpenError
Definition qaudio.h:24
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define qWarning
Definition qlogging.h:162
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:70
long long qint64
Definition qtypes.h:55
double qreal
Definition qtypes.h:92
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent