Audacity 3.2.0
Gain.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 Gain.h
6
7 Dmitry Vedenko
8
9**********************************************************************/
10
11#pragma once
12
13#include <type_traits>
14#include <cmath>
15#include <limits>
16
17// Implementation is based on https://www.dr-lex.be/info-stuff/volumecontrols.html
18template<typename Type>
19Type ExpGain(Type gain) noexcept
20{
21 static_assert(std::is_floating_point_v<Type>);
22
23 constexpr Type a(1e-3);
24 constexpr Type b(6.908);
25
26 if (gain < std::numeric_limits<Type>::epsilon())
27 return {};
28
29 const Type expGain = a * std::exp(b * gain);
30
31 if (expGain > Type(1))
32 return Type(1);
33
34 return expGain;
35}
36
Type ExpGain(Type gain) noexcept
Definition: Gain.h:19