Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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
25QT_BEGIN_NAMESPACE
26
27namespace QAudioHelperInternal {
29 const QAudioFormat &format,
30 const void *src,
31 void *dest,
32 int len) noexcept Q_DECL_NONBLOCKING_FUNCTION;
33
35void applyVolume(float volume,
36 const QAudioFormat &,
37 QSpan<const std::byte> source,
39
48
53
59
62
64{
65 switch (fmt) {
67 return 1;
69 return 2;
71 return 3;
75 return 4;
76 default:
78 }
79}
80
82std::optional<float> sanitizeVolume(float volume, float lastVolume);
83
88
89////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
90
91// Resample interleaved float32 PCM using Catmull-Rom interpolation.
92Q_MULTIMEDIA_EXPORT
93QByteArray resampleAudioCatmullRom(QSpan<const float> input, int nChannels,
94 int inputRate, int outputRate);
95
96class Q_MULTIMEDIA_EXPORT CatmullRomInterpolator
97{
98public:
101
104
105 void reset();
106
108 {
109 QSpan<const float> remainingInput;
110 QSpan<float> output;
111 };
112
113 ResampleResult process(QSpan<const float> input,
115
116private:
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
124 std::vector<float> m_history; // history of 3 frames
125};
126
127////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
128
129enum class UpmixScaling {
130 Duplicate, // mono → L=R=src[0]
131 EqualPower, // mono → L=R=0.707*src[0]
132};
133
134Q_MULTIMEDIA_EXPORT
137void upmixMonoToStereo(QSpan<float> out, QSpan<const float> in,
140
141enum class DownmixScaling {
142 Average, // L+R → 0.5*L + 0.5*R
143 KeepPower, // L+R → 0.707*L + 0.707*R
144};
145Q_MULTIMEDIA_EXPORT
146QByteArray downmixStereoToMono(QSpan<const float> input,
149void downmixStereoToMono(QSpan<float> out, QSpan<const float> in,
152
153////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
154
155} // namespace QAudioHelperInternal
156
158QDebug operator<<(QDebug dbg, QAudioHelperInternal::NativeSampleFormat);
159
160QT_END_NAMESPACE
161
162#endif // QAUDIOHELPERS_P_H
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"))
#define QT_MM_RESTRICT
QT_MM_DEFINE_QDEBUG_ENUM(QAudioHelperInternal::NativeSampleFormat)
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2598