openshot-audio  0.1.7
juce_Decibels.h
Go to the documentation of this file.
1 /*
2  ==============================================================================
3 
4  This file is part of the JUCE library.
5  Copyright (c) 2015 - ROLI Ltd.
6 
7  Permission is granted to use this software under the terms of either:
8  a) the GPL v2 (or any later version)
9  b) the Affero GPL v3
10 
11  Details of these licenses can be found at: www.gnu.org/licenses
12 
13  JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
14  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15  A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 
17  ------------------------------------------------------------------------------
18 
19  To release a closed-source product which uses JUCE, commercial licenses are
20  available: visit www.juce.com for more information.
21 
22  ==============================================================================
23 */
24 
25 #ifndef JUCE_DECIBELS_H_INCLUDED
26 #define JUCE_DECIBELS_H_INCLUDED
27 
28 
29 //==============================================================================
33 class Decibels
34 {
35 public:
36  //==============================================================================
42  template <typename Type>
43  static Type decibelsToGain (const Type decibels,
44  const Type minusInfinityDb = (Type) defaultMinusInfinitydB)
45  {
46  return decibels > minusInfinityDb ? std::pow ((Type) 10.0, decibels * (Type) 0.05)
47  : Type();
48  }
49 
56  template <typename Type>
57  static Type gainToDecibels (const Type gain,
58  const Type minusInfinityDb = (Type) defaultMinusInfinitydB)
59  {
60  return gain > Type() ? jmax (minusInfinityDb, (Type) std::log10 (gain) * (Type) 20.0)
61  : minusInfinityDb;
62  }
63 
64  //==============================================================================
69  template <typename Type>
70  static String toString (const Type decibels,
71  const int decimalPlaces = 2,
72  const Type minusInfinityDb = (Type) defaultMinusInfinitydB)
73  {
74  String s;
75 
76  if (decibels <= minusInfinityDb)
77  {
78  s = "-INF dB";
79  }
80  else
81  {
82  if (decibels >= Type())
83  s << '+';
84 
85  s << String (decibels, decimalPlaces) << " dB";
86  }
87 
88  return s;
89  }
90 
91 
92 private:
93  //==============================================================================
94  enum
95  {
96  defaultMinusInfinitydB = -100
97  };
98 
99  Decibels(); // This class can't be instantiated, it's just a holder for static methods..
101 };
102 
103 
104 #endif // JUCE_DECIBELS_H_INCLUDED
Definition: juce_Decibels.h:33
static Type decibelsToGain(const Type decibels, const Type minusInfinityDb=(Type) defaultMinusInfinitydB)
Definition: juce_Decibels.h:43
Definition: juce_String.h:43
Type jmax(const Type a, const Type b)
Definition: juce_core.h:101
#define JUCE_DECLARE_NON_COPYABLE(className)
Definition: juce_PlatformDefs.h:191
static Type gainToDecibels(const Type gain, const Type minusInfinityDb=(Type) defaultMinusInfinitydB)
Definition: juce_Decibels.h:57
static String toString(const Type decibels, const int decimalPlaces=2, const Type minusInfinityDb=(Type) defaultMinusInfinitydB)
Definition: juce_Decibels.h:70