Skip to content

Commit d9d7003

Browse files
committed
Constants optimizations
1 parent 8fdbb8a commit d9d7003

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

include/lsp-plug.in/dsp-units/const.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
#define LSP_PLUG_IN_DSP_UNITS_CONST_H_
2424

2525
#define LSP_DSP_UNITS_DEFAULT_SAMPLE_RATE 48000 /* Default sample rate */
26-
#define LSP_DSP_UNITS_AIR_ADIABATIC_INDEX 1.4 /* Adiabatic index for the Air */
27-
#define LSP_DSP_UNITS_AIR_MOLAR_MASS 28.98 /* Molar mass of the air [g/mol] */
28-
#define LSP_DSP_UNITS_GAS_CONSTANT 8.3144598 /* Gas constant [ j/(mol * K) } */
29-
#define LSP_DSP_UNITS_TEMP_ABS_ZERO -273.15 /* Temperature of the absolute zero [ C ] */
26+
#define LSP_DSP_UNITS_AIR_ADIABATIC_INDEX 1.4f /* Adiabatic index for the Air */
27+
#define LSP_DSP_UNITS_AIR_MOLAR_MASS 28.98f /* Molar mass of the air [g/mol] */
28+
#define LSP_DSP_UNITS_GAS_CONSTANT 8.3144598f /* Gas constant [ j/(mol * K) } */
29+
#define LSP_DSP_UNITS_TEMP_ABS_ZERO -273.15f /* Temperature of the absolute zero [ C ] */
3030
#define LSP_DSP_UNITS_SPEC_FREQ_MIN 10.0f /* Minimum frequency range [ Hz ] */
3131
#define LSP_DSP_UNITS_SPEC_FREQ_MAX 24000.0f /* Maximum frequency range [ Hz ] */
3232
#define LSP_DSP_UNITS_SOUND_SPEED_M_S 340.29f /* The default sound speed [ m / s ] */

include/lsp-plug.in/dsp-units/units.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ namespace lsp
136136
*/
137137
inline float db_to_gain(float db)
138138
{
139-
return expf(db * M_LN10 * 0.05f);
139+
return expf(db * float(M_LN10) * 0.05f);
140140
}
141141

142142
/** Convert decibels to power value
@@ -146,7 +146,7 @@ namespace lsp
146146
*/
147147
inline float db_to_power(float db)
148148
{
149-
return expf(db * M_LN10 * 0.1f);
149+
return expf(db * float(M_LN10) * 0.1f);
150150
}
151151

152152
/** Convert decibels to nepers
@@ -166,7 +166,7 @@ namespace lsp
166166
*/
167167
inline float db_to_lufs(float db)
168168
{
169-
return db - 0.691;
169+
return db - 0.691f;
170170
}
171171

172172
/** Convert gain value to decibels
@@ -176,7 +176,7 @@ namespace lsp
176176
*/
177177
inline float gain_to_db(float gain)
178178
{
179-
return (20.0f / M_LN10) * logf(gain);
179+
return (20.0f / float(M_LN10)) * logf(gain);
180180
}
181181

182182
/** Convert powerr value to decibels
@@ -186,7 +186,7 @@ namespace lsp
186186
*/
187187
inline float power_to_db(float pwr)
188188
{
189-
return (10.0f / M_LN10) * logf(pwr);
189+
return (10.0f / float(M_LN10)) * logf(pwr);
190190
}
191191

192192
/**
@@ -196,7 +196,7 @@ namespace lsp
196196
*/
197197
inline float gain_to_lufs(float gain)
198198
{
199-
return (20.0f / M_LN10) * logf(gain) - 0.691f;
199+
return (20.0f / float(M_LN10)) * logf(gain) - 0.691f;
200200
}
201201

202202
/**
@@ -206,7 +206,7 @@ namespace lsp
206206
*/
207207
inline float lufs_to_gain(float lufs)
208208
{
209-
return expf((lufs + 0.691f) * M_LN10 * 0.05f);
209+
return expf((lufs + 0.691f) * float(M_LN10) * 0.05f);
210210
}
211211

212212
/** Convert LKFS/LUFS to power value
@@ -216,7 +216,7 @@ namespace lsp
216216
*/
217217
inline float lufs_to_power(float lufs)
218218
{
219-
return expf((lufs + 0.691f) * M_LN10 * 0.1f);
219+
return expf((lufs + 0.691f) * float(M_LN10) * 0.1f);
220220
}
221221

222222
/** Convert LKFS/LUFS to nepers
@@ -236,7 +236,7 @@ namespace lsp
236236
*/
237237
inline float lufs_to_db(float lufs)
238238
{
239-
return lufs + 0.691;
239+
return lufs + 0.691f;
240240
}
241241

242242
/**
@@ -246,7 +246,7 @@ namespace lsp
246246
*/
247247
inline float gain_to_lu(float gain)
248248
{
249-
return (20.0f / M_LN10) * logf(gain) + 22.309f;
249+
return (20.0f / float(M_LN10)) * logf(gain) + 22.309f;
250250
}
251251

252252
/**
@@ -256,7 +256,7 @@ namespace lsp
256256
*/
257257
inline float lu_to_gain(float lu)
258258
{
259-
return expf((lu - 22.309f) * M_LN10 * 0.05f);
259+
return expf((lu - 22.309f) * float(M_LN10) * 0.05f);
260260
}
261261

262262
/** Convert nepers to gain value
@@ -326,7 +326,7 @@ namespace lsp
326326
*/
327327
inline float semitones_to_frequency_shift(float pitch)
328328
{
329-
return expf(pitch * (M_LN2 / 12.0f));
329+
return expf(pitch * (float(M_LN2) / 12.0f));
330330
}
331331

332332
/**
@@ -336,7 +336,7 @@ namespace lsp
336336
*/
337337
inline float frequency_shift_to_semitones(float pitch)
338338
{
339-
return (12.0f / M_LN2) * logf(pitch);
339+
return (12.0f / float(M_LN2)) * logf(pitch);
340340
}
341341

342342
/**

0 commit comments

Comments
 (0)