Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
<
QtMultimedia
/
qaudioformat
.
h
>
8
#
include
<
QtMultimedia
/
qtaudio
.
h
>
9
#
include
<
QtMultimedia
/
qtmultimediaglobal
.
h
>
10
#
include
<
QtCore
/
qshareddata
.
h
>
11
12
QT_BEGIN_NAMESPACE
13
14
namespace
QtPrivate
{
15
template
<
QAudioFormat
::
SampleFormat
>
struct
AudioSampleFormatHelper
16
{
17
};
18
19
template
<>
struct
AudioSampleFormatHelper
<
QAudioFormat
::
UInt8
>
20
{
21
using
value_type
=
unsigned
char
;
22
static
constexpr
value_type
Default
= 128;
23
};
24
25
template
<>
struct
AudioSampleFormatHelper
<
QAudioFormat
::
Int16
>
26
{
27
using
value_type
=
short
;
28
static
constexpr
value_type
Default
= 0;
29
};
30
31
template
<>
struct
AudioSampleFormatHelper
<
QAudioFormat
::
Int32
>
32
{
33
using
value_type
=
int
;
34
static
constexpr
value_type
Default
= 0;
35
};
36
37
template
<>
struct
AudioSampleFormatHelper
<
QAudioFormat
::
Float
>
38
{
39
using
value_type
=
float
;
40
static
constexpr
value_type
Default
= 0.;
41
};
42
43
}
44
45
template
<QAudioFormat::ChannelConfig config, QAudioFormat::SampleFormat format>
46
struct
QAudioFrame
47
{
48
private
:
49
// popcount in qalgorithms.h is unfortunately not constexpr on MSVC.
50
// Use this here as a fallback
51
static
constexpr
int
constexprPopcount(quint32 i)
52
{
53
i = i - ((i >> 1) & 0x55555555);
// add pairs of bits
54
i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
// quads
55
i = (i + (i >> 4)) & 0x0F0F0F0F;
// groups of 8
56
return
(i * 0x01010101) >> 24;
// horizontal sum of bytes
57
}
58
static
constexpr
int
nChannels = constexprPopcount(config);
59
public
:
60
using
value_type
=
typename
QtPrivate
::
AudioSampleFormatHelper
<format>::
value_type
;
61
value_type
channels
[nChannels];
62
static
constexpr
int
positionToIndex
(QAudioFormat::AudioChannelPosition pos)
63
{
64
if
(!(config & (1u << pos)))
65
return
-1;
66
67
uint maskedChannels = config & ((1u << pos) - 1);
68
return
qPopulationCount(maskedChannels);
69
}
70
71
72
value_type
value
(QAudioFormat::AudioChannelPosition pos)
const
{
73
int
idx = positionToIndex(pos);
74
if
(idx < 0)
75
return
QtPrivate
::
AudioSampleFormatHelper
<format>::Default;
76
return
channels[idx];
77
}
78
void
setValue
(QAudioFormat::AudioChannelPosition pos,
value_type
val) {
79
int
idx = positionToIndex(pos);
80
if
(idx < 0)
81
return
;
82
channels[idx] = val;
83
}
84
value_type
operator
[](QAudioFormat::AudioChannelPosition pos)
const
{
85
return
value(pos);
86
}
87
constexpr
void
clear
() {
88
for
(
int
i = 0; i < nChannels; ++i)
89
channels[i] = QtPrivate::AudioSampleFormatHelper<format>::Default;
90
}
91
};
92
93
template
<QAudioFormat::SampleFormat Format>
94
using
QAudioFrameMono = QAudioFrame<QAudioFormat::ChannelConfigMono, Format>;
95
96
template
<QAudioFormat::SampleFormat Format>
97
using
QAudioFrameStereo = QAudioFrame<QAudioFormat::ChannelConfigStereo, Format>;
98
99
template
<QAudioFormat::SampleFormat Format>
100
using
QAudioFrame2Dot1 = QAudioFrame<QAudioFormat::ChannelConfig2Dot1, Format>;
101
102
template
<QAudioFormat::SampleFormat Format>
103
using
QAudioFrameSurround5Dot1 = QAudioFrame<QAudioFormat::ChannelConfigSurround5Dot1, Format>;
104
105
template
<QAudioFormat::SampleFormat Format>
106
using
QAudioFrameSurround7Dot1 = QAudioFrame<QAudioFormat::ChannelConfigSurround7Dot1, Format>;
107
108
109
class
QAudioBufferPrivate;
110
QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QAudioBufferPrivate, Q_MULTIMEDIA_EXPORT)
111
112
class
Q_MULTIMEDIA_EXPORT
QAudioBuffer
113
{
114
public
:
115
QAudioBuffer()
noexcept
;
116
QAudioBuffer(
const
QAudioBuffer &other)
noexcept
;
117
QAudioBuffer(
const
QByteArray &data,
const
QAudioFormat &format, qint64 startTime = -1);
118
QAudioBuffer(
int
numFrames,
const
QAudioFormat &format, qint64 startTime = -1);
// Initialized to empty
119
~QAudioBuffer();
120
121
QAudioBuffer& operator=(
const
QAudioBuffer &other);
122
123
QAudioBuffer(QAudioBuffer &&other)
noexcept
=
default
;
124
QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QAudioBuffer)
125
void
swap(QAudioBuffer &other)
noexcept
126
{ d.swap(other.d); }
127
128
bool
isValid()
const
noexcept
{
return
d !=
nullptr
; };
129
130
void
detach();
131
132
QAudioFormat format()
const
noexcept
;
133
134
qsizetype frameCount()
const
noexcept
;
135
qsizetype sampleCount()
const
noexcept
;
136
qsizetype byteCount()
const
noexcept
;
137
138
qint64 duration()
const
noexcept
;
139
qint64 startTime()
const
noexcept
;
140
141
// Structures for easier access to data
142
typedef
QAudioFrameMono<QAudioFormat::UInt8> U8M;
143
typedef
QAudioFrameMono<QAudioFormat::Int16> S16M;
144
typedef
QAudioFrameMono<QAudioFormat::Int32> S32M;
145
typedef
QAudioFrameMono<QAudioFormat::Float> F32M;
146
147
typedef
QAudioFrameStereo<QAudioFormat::UInt8> U8S;
148
typedef
QAudioFrameStereo<QAudioFormat::Int16> S16S;
149
typedef
QAudioFrameStereo<QAudioFormat::Int32> S32S;
150
typedef
QAudioFrameStereo<QAudioFormat::Float> F32S;
151
152
template
<
typename
T>
const
T* constData()
const
{
153
return
static_cast
<
const
T*>(constData());
154
}
155
template
<
typename
T>
const
T* data()
const
{
156
return
static_cast
<
const
T*>(data());
157
}
158
template
<
typename
T> T* data() {
159
return
static_cast
<T*>(data());
160
}
161
private
:
162
const
void
* constData()
const
noexcept
;
163
const
void
* data()
const
noexcept
;
164
void
*data();
165
166
QExplicitlySharedDataPointer<QAudioBufferPrivate> d;
167
};
168
169
QT_END_NAMESPACE
170
171
Q_DECLARE_METATYPE
(
QAudioBuffer
)
172
173
#
endif
// QAUDIOBUFFER_H
QAudioBuffer
\inmodule QtMultimedia
Definition
qaudiobuffer.h:113
QtPrivate
Definition
qalloc.h:29
QT_DEFINE_QESDP_SPECIALIZATION_DTOR
QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QAudioBufferPrivate)
Q_DECLARE_METATYPE
QT_END_NAMESPACE Q_DECLARE_METATYPE(QT_PREPEND_NAMESPACE(QtOhosQpa::enums::kit::ShareKit::systemShare::SelectionMode))
QAudioFrame
Definition
qaudiobuffer.h:47
QAudioFrame::positionToIndex
static constexpr int positionToIndex(QAudioFormat::AudioChannelPosition pos)
Definition
qaudiobuffer.h:62
QAudioFrame::setValue
void setValue(QAudioFormat::AudioChannelPosition pos, value_type val)
Definition
qaudiobuffer.h:78
QAudioFrame::channels
value_type channels[nChannels]
Definition
qaudiobuffer.h:61
QAudioFrame::clear
constexpr void clear()
Definition
qaudiobuffer.h:87
QAudioFrame::value
value_type value(QAudioFormat::AudioChannelPosition pos) const
Definition
qaudiobuffer.h:72
QAudioFrame::operator[]
value_type operator[](QAudioFormat::AudioChannelPosition pos) const
Definition
qaudiobuffer.h:84
QAudioFrame::value_type
typename QtPrivate::AudioSampleFormatHelper< format >::value_type value_type
Definition
qaudiobuffer.h:60
QtPrivate::AudioSampleFormatHelper
Definition
qaudiobuffer.h:16
qtmultimedia
src
multimedia
audio
qaudiobuffer.h
Generated on
for Qt by
1.18.0