Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qaudio.cpp
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
5#include <qaudio.h>
6#include <qmath.h>
7#include <QDebug>
8
10
11#define LOG100 4.60517018599
12
66namespace QAudio
67{
68
91float convertVolume(float volume, VolumeScale from, VolumeScale to)
92{
93 switch (from) {
95 volume = qMax(float(0), volume);
96 switch (to) {
98 return volume;
100 return qPow(volume, float(1 / 3.0));
102 return 1 - std::exp(-volume * LOG100);
104 if (volume < 0.001)
105 return float(-200);
106 else
107 return float(20.0) * std::log10(volume);
108 }
109 break;
110 case CubicVolumeScale:
111 volume = qMax(float(0), volume);
112 switch (to) {
114 return volume * volume * volume;
115 case CubicVolumeScale:
116 return volume;
118 return 1 - std::exp(-volume * volume * volume * LOG100);
120 if (volume < 0.001)
121 return float(-200);
122 else
123 return float(3.0 * 20.0) * std::log10(volume);
124 }
125 break;
127 volume = qMax(float(0), volume);
128 switch (to) {
130 if (volume > 0.99)
131 return 1;
132 else
133 return -std::log(1 - volume) / LOG100;
134 case CubicVolumeScale:
135 if (volume > 0.99)
136 return 1;
137 else
138 return qPow(-std::log(1 - volume) / LOG100, float(1 / 3.0));
140 return volume;
142 if (volume < 0.001)
143 return float(-200);
144 else if (volume > 0.99)
145 return 0;
146 else
147 return float(20.0) * std::log10(-std::log(1 - volume) / LOG100);
148 }
149 break;
151 switch (to) {
153 return qPow(float(10.0), volume / float(20.0));
154 case CubicVolumeScale:
155 return qPow(float(10.0), volume / float(3.0 * 20.0));
157 if (qFuzzyIsNull(volume))
158 return 1;
159 else
160 return 1 - std::exp(-qPow(float(10.0), volume / float(20.0)) * LOG100);
162 return volume;
163 }
164 break;
165 }
166
167 return volume;
168}
169
170}
171
172#ifndef QT_NO_DEBUG_STREAM
174{
175 QDebugStateSaver saver(dbg);
176 dbg.nospace();
177 switch (error) {
178 case QAudio::NoError:
179 dbg << "NoError";
180 break;
182 dbg << "OpenError";
183 break;
184 case QAudio::IOError:
185 dbg << "IOError";
186 break;
188 dbg << "UnderrunError";
189 break;
191 dbg << "FatalError";
192 break;
193 }
194 return dbg;
195}
196
198{
199 QDebugStateSaver saver(dbg);
200 dbg.nospace();
201 switch (state) {
203 dbg << "ActiveState";
204 break;
206 dbg << "SuspendedState";
207 break;
209 dbg << "StoppedState";
210 break;
212 dbg << "IdleState";
213 break;
214 }
215 return dbg;
216}
217
219{
220 QDebugStateSaver saver(dbg);
221 dbg.nospace();
222 switch (scale) {
224 dbg << "LinearVolumeScale";
225 break;
227 dbg << "CubicVolumeScale";
228 break;
230 dbg << "LogarithmicVolumeScale";
231 break;
233 dbg << "DecibelVolumeScale";
234 break;
235 }
236 return dbg;
237}
238
239#endif
240
241
243
\inmodule QtCore
\inmodule QtCore
else opt state
[0]
The QAudio namespace contains enums used by the audio classes.
State
\value ActiveState Audio data is being processed, this state is set after start() is called and while...
Definition qaudio.h:25
@ StoppedState
Definition qaudio.h:25
@ SuspendedState
Definition qaudio.h:25
@ IdleState
Definition qaudio.h:25
@ ActiveState
Definition qaudio.h:25
Error
\value NoError No errors have occurred \value OpenError An error occurred opening the audio device \v...
Definition qaudio.h:24
@ UnderrunError
Definition qaudio.h:24
@ FatalError
Definition qaudio.h:24
@ OpenError
Definition qaudio.h:24
@ NoError
Definition qaudio.h:24
@ IOError
Definition qaudio.h:24
float convertVolume(float volume, VolumeScale from, VolumeScale to)
Converts an audio volume from a volume scale to another, and returns the result.
Definition qaudio.cpp:91
VolumeScale
This enum defines the different audio volume scales.
Definition qaudio.h:27
@ LogarithmicVolumeScale
Definition qaudio.h:30
@ DecibelVolumeScale
Definition qaudio.h:31
@ LinearVolumeScale
Definition qaudio.h:28
@ CubicVolumeScale
Definition qaudio.h:29
Combined button and popup list for selecting options.
#define LOG100
Definition qaudio.cpp:11
QDebug operator<<(QDebug dbg, QAudio::Error error)
Definition qaudio.cpp:173
DBusConnection const char DBusError * error
bool qFuzzyIsNull(qfloat16 f) noexcept
Definition qfloat16.h:303
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