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
qtaudio.cpp
Go to the documentation of this file.
1// Copyright (C) 2024 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 <qtaudio.h>
6#include <qmath.h>
7#include <QDebug>
8
10
11#define LOG100 4.60517018599
12
65#if defined(Q_QDOC)
66namespace QtAudio
67#else
68namespace QAudio
69#endif
70{
71
93float convertVolume(float volume, VolumeScale from, VolumeScale to)
94{
95 switch (from) {
97 volume = qMax(float(0), volume);
98 switch (to) {
100 return volume;
101 case CubicVolumeScale:
102 return qPow(volume, float(1 / 3.0));
104 return 1 - std::exp(-volume * LOG100);
106 if (volume < 0.001)
107 return float(-200);
108 else
109 return float(20.0) * std::log10(volume);
110 }
111 break;
112 case CubicVolumeScale:
113 volume = qMax(float(0), volume);
114 switch (to) {
116 return volume * volume * volume;
117 case CubicVolumeScale:
118 return volume;
120 return 1 - std::exp(-volume * volume * volume * LOG100);
122 if (volume < 0.001)
123 return float(-200);
124 else
125 return float(3.0 * 20.0) * std::log10(volume);
126 }
127 break;
129 volume = qMax(float(0), volume);
130 switch (to) {
132 if (volume > 0.99)
133 return 1;
134 else
135 return -std::log(1 - volume) / LOG100;
136 case CubicVolumeScale:
137 if (volume > 0.99)
138 return 1;
139 else
140 return qPow(-std::log(1 - volume) / LOG100, float(1 / 3.0));
142 return volume;
144 if (volume < 0.001)
145 return float(-200);
146 else if (volume > 0.99)
147 return 0;
148 else
149 return float(20.0) * std::log10(-std::log(1 - volume) / LOG100);
150 }
151 break;
153 switch (to) {
155 return qPow(float(10.0), volume / float(20.0));
156 case CubicVolumeScale:
157 return qPow(float(10.0), volume / float(3.0 * 20.0));
159 if (qFuzzyIsNull(volume))
160 return 1;
161 else
162 return 1 - std::exp(-qPow(float(10.0), volume / float(20.0)) * LOG100);
164 return volume;
165 }
166 break;
167 }
168
169 return volume;
170}
171
172}
173
174#ifndef QT_NO_DEBUG_STREAM
176{
177 QDebugStateSaver saver(dbg);
178 dbg.nospace();
179 switch (error) {
180 case QAudio::NoError:
181 dbg << "NoError";
182 break;
184 dbg << "OpenError";
185 break;
186 case QAudio::IOError:
187 dbg << "IOError";
188 break;
190 dbg << "UnderrunError";
191 break;
193 dbg << "FatalError";
194 break;
195 }
196 return dbg;
197}
198
200{
201 QDebugStateSaver saver(dbg);
202 dbg.nospace();
203 switch (state) {
205 dbg << "ActiveState";
206 break;
208 dbg << "SuspendedState";
209 break;
211 dbg << "StoppedState";
212 break;
214 dbg << "IdleState";
215 break;
216 }
217 return dbg;
218}
219
221{
222 QDebugStateSaver saver(dbg);
223 dbg.nospace();
224 switch (scale) {
226 dbg << "LinearVolumeScale";
227 break;
229 dbg << "CubicVolumeScale";
230 break;
232 dbg << "LogarithmicVolumeScale";
233 break;
235 dbg << "DecibelVolumeScale";
236 break;
237 }
238 return dbg;
239}
240
241#endif
242
243
245
\inmodule QtCore
\inmodule QtCore
else opt state
[0]
State
Definition qaudio.h:29
@ StoppedState
Definition qaudio.h:29
@ SuspendedState
Definition qaudio.h:29
@ IdleState
Definition qaudio.h:29
@ ActiveState
Definition qaudio.h:29
Q_MULTIMEDIA_EXPORT float convertVolume(float volume, VolumeScale from, VolumeScale to)
Converts an audio volume from a volume scale to another, and returns the result.
Definition qtaudio.cpp:93
Error
Definition qaudio.h:28
@ UnderrunError
Definition qaudio.h:28
@ FatalError
Definition qaudio.h:28
@ OpenError
Definition qaudio.h:28
@ NoError
Definition qaudio.h:28
@ IOError
Definition qaudio.h:28
VolumeScale
Definition qaudio.h:31
@ LogarithmicVolumeScale
Definition qaudio.h:34
@ DecibelVolumeScale
Definition qaudio.h:35
@ LinearVolumeScale
Definition qaudio.h:32
@ CubicVolumeScale
Definition qaudio.h:33
Combined button and popup list for selecting options.
DBusConnection const char DBusError * error
bool qFuzzyIsNull(qfloat16 f) noexcept
Definition qfloat16.h:349
auto qPow(T1 x, T2 y)
Definition qmath.h:180
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
GLenum GLenum GLenum GLenum GLenum scale
#define LOG100
Definition qtaudio.cpp:11
QDebug operator<<(QDebug dbg, QAudio::Error error)
Definition qtaudio.cpp:175