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
qaudiobuffer.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#ifndef QAUDIOBUFFER_H
5#define QAUDIOBUFFER_H
6
7#include <QtCore/qshareddata.h>
8
9#include <QtMultimedia/qtmultimediaglobal.h>
10
11#include <QtMultimedia/qtaudio.h>
12#include <QtMultimedia/qaudioformat.h>
13
15
16namespace QtPrivate {
17template <QAudioFormat::SampleFormat> struct AudioSampleFormatHelper
18{
19};
20
21template <> struct AudioSampleFormatHelper<QAudioFormat::UInt8>
22{
23 using value_type = unsigned char;
24 static constexpr value_type Default = 128;
25};
26
28{
29 using value_type = short;
30 static constexpr value_type Default = 0;
31};
32
34{
35 using value_type = int;
36 static constexpr value_type Default = 0;
37};
38
39template <> struct AudioSampleFormatHelper<QAudioFormat::Float>
40{
41 using value_type = float;
42 static constexpr value_type Default = 0.;
43};
44
45}
46
47template <QAudioFormat::ChannelConfig config, QAudioFormat::SampleFormat format>
49{
50private:
51 // popcount in qalgorithms.h is unfortunately not constexpr on MSVC.
52 // Use this here as a fallback
53 static constexpr int constexprPopcount(quint32 i)
54 {
55 i = i - ((i >> 1) & 0x55555555); // add pairs of bits
56 i = (i & 0x33333333) + ((i >> 2) & 0x33333333); // quads
57 i = (i + (i >> 4)) & 0x0F0F0F0F; // groups of 8
58 return (i * 0x01010101) >> 24; // horizontal sum of bytes
59 }
60 static constexpr int nChannels = constexprPopcount(config);
61public:
63 value_type channels[nChannels];
65 {
66 if (!(config & (1u << pos)))
67 return -1;
68
69 uint maskedChannels = config & ((1u << pos) - 1);
70 return qPopulationCount(maskedChannels);
71 }
72
73
81 int idx = positionToIndex(pos);
82 if (idx < 0)
83 return;
84 channels[idx] = val;
85 }
89 constexpr void clear() {
90 for (int i = 0; i < nChannels; ++i)
92 }
93};
94
95template <QAudioFormat::SampleFormat Format>
96using QAudioFrameMono = QAudioFrame<QAudioFormat::ChannelConfigMono, Format>;
97
98template <QAudioFormat::SampleFormat Format>
99using QAudioFrameStereo = QAudioFrame<QAudioFormat::ChannelConfigStereo, Format>;
100
101template <QAudioFormat::SampleFormat Format>
102using QAudioFrame2Dot1 = QAudioFrame<QAudioFormat::ChannelConfig2Dot1, Format>;
103
104template <QAudioFormat::SampleFormat Format>
105using QAudioFrameSurround5Dot1 = QAudioFrame<QAudioFormat::ChannelConfigSurround5Dot1, Format>;
106
107template <QAudioFormat::SampleFormat Format>
108using QAudioFrameSurround7Dot1 = QAudioFrame<QAudioFormat::ChannelConfigSurround7Dot1, Format>;
109
110
113
114class Q_MULTIMEDIA_EXPORT QAudioBuffer
115{
116public:
117 QAudioBuffer() noexcept;
120 QAudioBuffer(int numFrames, const QAudioFormat &format, qint64 startTime = -1); // Initialized to empty
122
123 QAudioBuffer& operator=(const QAudioBuffer &other);
124
125 QAudioBuffer(QAudioBuffer &&other) noexcept = default;
126 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QAudioBuffer)
127 void swap(QAudioBuffer &other) noexcept
128 { d.swap(other.d); }
129
130 bool isValid() const noexcept { return d != nullptr; };
131
132 void detach();
133
134 QAudioFormat format() const noexcept;
135
136 qsizetype frameCount() const noexcept;
137 qsizetype sampleCount() const noexcept;
138 qsizetype byteCount() const noexcept;
139
140 qint64 duration() const noexcept;
141 qint64 startTime() const noexcept;
142
143 // Structures for easier access to data
148
153
154 template <typename T> const T* constData() const {
155 return static_cast<const T*>(constData());
156 }
157 template <typename T> const T* data() const {
158 return static_cast<const T*>(data());
159 }
160 template <typename T> T* data() {
161 return static_cast<T*>(data());
162 }
163private:
164 const void* constData() const noexcept;
165 const void* data() const noexcept;
166 void *data();
167
169};
170
172
174
175#endif // QAUDIOBUFFER_H
\inmodule QtMultimedia
QAudioBuffer() noexcept
Create a new, empty, invalid buffer.
bool isValid() const noexcept
Returns true if this is a valid buffer.
QAudioFrameMono< QAudioFormat::Float > F32M
This is a predefined specialization for a 32 bit float mono sample.
QAudioFrameMono< QAudioFormat::Int32 > S32M
This is a predefined specialization for a signed 32 bit mono sample.
QAudioFrameStereo< QAudioFormat::Int32 > S32S
This is a predifined specialization for a siged 32 bit stereo sample.
void swap(QAudioBuffer &other) noexcept
Swaps the audio buffer with other.
QAudioFrameMono< QAudioFormat::UInt8 > U8M
This is a predefined specialization for an unsigned 8 bit mono sample.
T * data()
Returns a pointer to this buffer's data.
QAudioFrameStereo< QAudioFormat::Int16 > S16S
This is a predefined specialization for a signed stereo 16 bit sample.
const T * data() const
Returns a pointer to this buffer's data.
QAudioFrameMono< QAudioFormat::Int16 > S16M
QAudioFrameStereo< QAudioFormat::UInt8 > U8S
This is a predifined specialization for an unsiged 8 bit stereo sample.
QAudioFrameStereo< QAudioFormat::Float > F32S
This is a predifined specialization for a 32 bit float stereo sample.
The QAudioFormat class stores audio stream parameter information.
AudioChannelPosition
Describes the possible audio channel positions.
\inmodule QtCore
Definition qbytearray.h:57
Combined button and popup list for selecting options.
\macro QT_NO_KEYWORDS >
Q_DECL_CONST_FUNCTION QT_POPCOUNT_CONSTEXPR uint qPopulationCount(quint32 v) noexcept
QAudioFrame< QAudioFormat::ChannelConfig2Dot1, Format > QAudioFrame2Dot1
QAudioFrame< QAudioFormat::ChannelConfigSurround7Dot1, Format > QAudioFrameSurround7Dot1
QAudioFrame< QAudioFormat::ChannelConfigMono, Format > QAudioFrameMono
QAudioFrame< QAudioFormat::ChannelConfigStereo, Format > QAudioFrameStereo
QAudioFrame< QAudioFormat::ChannelConfigSurround5Dot1, Format > QAudioFrameSurround5Dot1
qint64 startTime
EGLConfig config
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define Q_DECLARE_METATYPE(TYPE)
Definition qmetatype.h:1525
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLsizei GLsizei GLenum format
GLuint GLfloat * val
#define QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(Class, ExportMacro)
static QT_BEGIN_NAMESPACE const uint Default
Definition qsplitter_p.h:27
unsigned int quint32
Definition qtypes.h:50
ptrdiff_t qsizetype
Definition qtypes.h:165
unsigned int uint
Definition qtypes.h:34
long long qint64
Definition qtypes.h:60
QSharedPointer< T > other(t)
[5]
this swap(other)
static constexpr int positionToIndex(QAudioFormat::AudioChannelPosition pos)
void setValue(QAudioFormat::AudioChannelPosition pos, value_type val)
value_type channels[nChannels]
constexpr void clear()
value_type value(QAudioFormat::AudioChannelPosition pos) const
value_type operator[](QAudioFormat::AudioChannelPosition pos) const
typename QtPrivate::AudioSampleFormatHelper< format >::value_type value_type