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
qaudiohelpers_p.h
Go to the documentation of this file.
1
// Copyright (C) 2022 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
QAUDIOHELPERS_P_H
5
#
define
QAUDIOHELPERS_P_H
6
7
//
8
// W A R N I N G
9
// -------------
10
//
11
// This file is not part of the Qt API. It exists purely as an
12
// implementation detail. This header file may change from version to
13
// version without notice, or even be removed.
14
//
15
// We mean it.
16
//
17
18
#
include
<
QtMultimedia
/
private
/
qtmultimediaglobal_p
.
h
>
19
#
include
<
QtMultimedia
/
qaudioformat
.
h
>
20
#
include
<
QtCore
/
qspan
.
h
>
21
#
include
<
QtCore
/
qmath
.
h
>
22
23
#
include
<
vector
>
24
25
QT_BEGIN_NAMESPACE
26
27
namespace
QAudioHelperInternal
{
28
Q_MULTIMEDIA_EXPORT
void
qMultiplySamples
(
float
factor
,
29
const
QAudioFormat
&
format
,
30
const
void
*
src
,
31
void
*
dest
,
32
int
len
)
noexcept
Q_DECL_NONBLOCKING_FUNCTION
;
33
34
Q_MULTIMEDIA_EXPORT
35
void
applyVolume
(
float
volume
,
36
const
QAudioFormat
&,
37
QSpan
<
const
std
::
byte
>
source
,
38
QSpan
<
std
::
byte
>
destination
)
noexcept
Q_DECL_NONBLOCKING_FUNCTION
;
39
40
enum
class
NativeSampleFormat
:
uint8_t
{
41
uint8_t
,
42
int16_t
,
43
int32_t
,
44
int24_t_3b
,
// 3 byte lsb
45
int24_t_4b_low
,
// 4 byte
46
float32_t
,
47
};
48
49
Q_MULTIMEDIA_EXPORT
50
void
convertSampleFormat
(
QSpan
<
const
std
::
byte
>
source
,
NativeSampleFormat
sourceFormat
,
51
QSpan
<
std
::
byte
>
destination
,
52
NativeSampleFormat
destinationFormat
)
noexcept
Q_DECL_NONBLOCKING_FUNCTION
;
53
54
Q_MULTIMEDIA_EXPORT
55
NativeSampleFormat
bestNativeSampleFormat
(
const
QAudioFormat
&
fmt
,
56
QSpan
<
const
NativeSampleFormat
>
supportedNativeFormats
);
57
Q_MULTIMEDIA_EXPORT
58
QAudioFormat
::
SampleFormat
bestSampleFormat
(
NativeSampleFormat
);
59
60
Q_MULTIMEDIA_EXPORT
61
NativeSampleFormat
toNativeSampleFormat
(
QAudioFormat
::
SampleFormat
);
62
63
constexpr
size_t
bytesPerSample
(
NativeSampleFormat
fmt
)
noexcept
Q_DECL_NONBLOCKING_FUNCTION
64
{
65
switch
(
fmt
) {
66
case
NativeSampleFormat
::
uint8_t
:
67
return
1;
68
case
NativeSampleFormat
::
int16_t
:
69
return
2;
70
case
NativeSampleFormat
::
int24_t_3b
:
71
return
3;
72
case
NativeSampleFormat
::
int24_t_4b_low
:
73
case
NativeSampleFormat
::
float32_t
:
74
case
NativeSampleFormat
::
int32_t
:
75
return
4;
76
default
:
77
Q_UNREACHABLE_RETURN
(0);
78
}
79
}
80
81
Q_MULTIMEDIA_EXPORT
82
std
::
optional
<
float
>
sanitizeVolume
(
float
volume
,
float
lastVolume
);
83
84
Q_MULTIMEDIA_EXPORT
85
void
fillSilence
(
QSpan
<
std
::
byte
>,
NativeSampleFormat
)
noexcept
Q_DECL_NONBLOCKING_FUNCTION
;
86
Q_MULTIMEDIA_EXPORT
87
void
fillSilence
(
QSpan
<
std
::
byte
>,
QAudioFormat
)
noexcept
Q_DECL_NONBLOCKING_FUNCTION
;
88
89
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
90
91
// Resample interleaved float32 PCM using Catmull-Rom interpolation.
92
Q_MULTIMEDIA_EXPORT
93
QByteArray
resampleAudioCatmullRom
(
QSpan
<
const
float
>
input
,
int
nChannels
,
94
int
inputRate
,
int
outputRate
);
95
96
class
Q_MULTIMEDIA_EXPORT
CatmullRomInterpolator
97
{
98
public
:
99
CatmullRomInterpolator
(
int
nChannels
,
int
inputRate
,
int
outputRate
);
100
~
CatmullRomInterpolator
() =
default
;
101
102
CatmullRomInterpolator
(
const
CatmullRomInterpolator
&) =
delete
;
103
CatmullRomInterpolator
&
operator
=(
const
CatmullRomInterpolator
&) =
delete
;
104
105
void
reset
();
106
107
struct
ResampleResult
108
{
109
QSpan
<
const
float
>
remainingInput
;
110
QSpan
<
float
>
output
;
111
};
112
113
ResampleResult
process
(
QSpan
<
const
float
>
input
,
114
QSpan
<
float
>
output
)
noexcept
Q_DECL_NONBLOCKING_FUNCTION
;
115
116
private
:
117
void
advancePosition
();
118
119
int
m_nChannels
= 0;
120
float
m_ratio
= 1.0f;
121
qsizetype
m_iPos
= 0;
// integer frame index in absolute frame space
122
float
m_fPos
= 0.0f;
// fractional phase [0, 1) within current frame
123
qsizetype
m_inputFramesConsumed
= 0;
124
std
::
vector
<
float
>
m_history
;
// history of 3 frames
125
};
126
127
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
128
129
enum
class
UpmixScaling
{
130
Duplicate
,
// mono → L=R=src[0]
131
EqualPower
,
// mono → L=R=0.707*src[0]
132
};
133
134
Q_MULTIMEDIA_EXPORT
135
QByteArray
upmixMonoToStereo
(
QSpan
<
const
float
>,
UpmixScaling
scaling
=
UpmixScaling
::
Duplicate
);
136
Q_MULTIMEDIA_EXPORT
137
void
upmixMonoToStereo
(
QSpan
<
float
>
out
,
QSpan
<
const
float
>
in
,
138
UpmixScaling
scaling
=
UpmixScaling
::
Duplicate
)
noexcept
139
Q_DECL_NONBLOCKING_FUNCTION
;
140
141
enum
class
DownmixScaling
{
142
Average
,
// L+R → 0.5*L + 0.5*R
143
KeepPower
,
// L+R → 0.707*L + 0.707*R
144
};
145
Q_MULTIMEDIA_EXPORT
146
QByteArray
downmixStereoToMono
(
QSpan
<
const
float
>
input
,
147
DownmixScaling
scaling
=
DownmixScaling
::
Average
);
148
Q_MULTIMEDIA_EXPORT
149
void
downmixStereoToMono
(
QSpan
<
float
>
out
,
QSpan
<
const
float
>
in
,
150
DownmixScaling
scaling
=
DownmixScaling
::
Average
)
noexcept
151
Q_DECL_NONBLOCKING_FUNCTION
;
152
153
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
154
155
}
// namespace QAudioHelperInternal
156
157
Q_MULTIMEDIA_EXPORT
158
QDebug
operator<<(QDebug dbg, QAudioHelperInternal::NativeSampleFormat);
159
160
QT_END_NAMESPACE
161
162
#
endif
// QAUDIOHELPERS_P_H
QAudioHelperInternal::CatmullRomInterpolator
Definition
qaudiohelpers_p.h:97
QAudioHelperInternal
Definition
qaudiohelpers.cpp:17
QAudioHelperInternal::NativeSampleFormat
NativeSampleFormat
Definition
qaudiohelpers_p.h:40
QAudioHelperInternal::NativeSampleFormat::float32_t
@ float32_t
Definition
qaudiohelpers_p.h:46
QAudioHelperInternal::NativeSampleFormat::int16_t
@ int16_t
Definition
qaudiohelpers_p.h:42
QAudioHelperInternal::NativeSampleFormat::int24_t_3b
@ int24_t_3b
Definition
qaudiohelpers_p.h:44
QAudioHelperInternal::NativeSampleFormat::uint8_t
@ uint8_t
Definition
qaudiohelpers_p.h:41
QAudioHelperInternal::NativeSampleFormat::int32_t
@ int32_t
Definition
qaudiohelpers_p.h:43
QAudioHelperInternal::NativeSampleFormat::int24_t_4b_low
@ int24_t_4b_low
Definition
qaudiohelpers_p.h:45
QAudioHelperInternal::UpmixScaling
UpmixScaling
Definition
qaudiohelpers_p.h:129
QAudioHelperInternal::UpmixScaling::EqualPower
@ EqualPower
Definition
qaudiohelpers_p.h:131
QAudioHelperInternal::UpmixScaling::Duplicate
@ Duplicate
Definition
qaudiohelpers_p.h:130
QAudioHelperInternal::DownmixScaling
DownmixScaling
Definition
qaudiohelpers_p.h:141
QAudioHelperInternal::DownmixScaling::KeepPower
@ KeepPower
Definition
qaudiohelpers_p.h:143
QAudioHelperInternal::DownmixScaling::Average
@ Average
Definition
qaudiohelpers_p.h:142
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
QT_MM_MAKE_STRING_RESOLVER
QT_MM_MAKE_STRING_RESOLVER(QAudioHelperInternal::NativeSampleFormat, QtMultimediaPrivate::EnumName,(QAudioHelperInternal::NativeSampleFormat::uint8_t, "uint8_t")(QAudioHelperInternal::NativeSampleFormat::int16_t, "int16_t")(QAudioHelperInternal::NativeSampleFormat::int32_t, "int32_t")(QAudioHelperInternal::NativeSampleFormat::int24_t_3b, "int24_t_3b")(QAudioHelperInternal::NativeSampleFormat::int24_t_4b_low, "int24_t_4b_low")(QAudioHelperInternal::NativeSampleFormat::float32_t, "float32_t"))
QT_MM_RESTRICT
#define QT_MM_RESTRICT
Definition
qaudiohelpers.cpp:24
QT_MM_DEFINE_QDEBUG_ENUM
QT_MM_DEFINE_QDEBUG_ENUM(QAudioHelperInternal::NativeSampleFormat)
operator<<
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition
qdir.cpp:2620
qtmultimedia
src
multimedia
audio
qaudiohelpers_p.h
Generated on
for Qt by
1.18.0