JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
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) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
26//==============================================================================
33{
34public:
35 //==============================================================================
41 template <typename Type>
42 static Type decibelsToGain (Type decibels,
43 Type minusInfinityDb = Type (defaultMinusInfinitydB))
44 {
45 return decibels > minusInfinityDb ? std::pow (Type (10.0), decibels * Type (0.05))
46 : Type();
47 }
48
55 template <typename Type>
56 static Type gainToDecibels (Type gain,
57 Type minusInfinityDb = Type (defaultMinusInfinitydB))
58 {
59 return gain > Type() ? jmax (minusInfinityDb, static_cast<Type> (std::log10 (gain)) * Type (20.0))
61 }
62
67 template <typename Type>
68 static Type gainWithLowerBound (Type gain, Type lowerBoundDb)
69 {
70 // You probably want to use a negative decibel value or the gain will
71 // be restricted to boosting only!
72 jassert (lowerBoundDb < (Type) 0.0);
73
74 return jmax ((Type) gain, Decibels::decibelsToGain (lowerBoundDb, lowerBoundDb - (Type) 1.0));
75 }
76
77 //==============================================================================
85 template <typename Type>
86 static String toString (Type decibels,
87 int decimalPlaces = 2,
88 Type minusInfinityDb = Type (defaultMinusInfinitydB),
89 bool shouldIncludeSuffix = true,
91 {
92 String s;
93 s.preallocateBytes (20);
94
96 {
97 if (customMinusInfinityString.isEmpty())
98 s << "-INF";
99 else
101 }
102 else
103 {
104 if (decibels >= Type())
105 s << '+';
106
107 if (decimalPlaces <= 0)
108 s << roundToInt (decibels);
109 else
110 s << String (decibels, decimalPlaces);
111 }
112
114 s << " dB";
115
116 return s;
117 }
118
119private:
120 //==============================================================================
121 enum { defaultMinusInfinitydB = -100 };
122
123 Decibels() = delete; // This class can't be instantiated, it's just a holder for static methods..
124};
125
126} // namespace juce
This class contains some helpful static methods for dealing with decibel values.
static Type gainWithLowerBound(Type gain, Type lowerBoundDb)
Restricts a gain value based on a lower bound specified in dBFS.
static Type decibelsToGain(Type decibels, Type minusInfinityDb=Type(defaultMinusInfinitydB))
Converts a dBFS value to its equivalent gain level.
static Type gainToDecibels(Type gain, Type minusInfinityDb=Type(defaultMinusInfinitydB))
Converts a gain level into a dBFS value.
static String toString(Type decibels, int decimalPlaces=2, Type minusInfinityDb=Type(defaultMinusInfinitydB), bool shouldIncludeSuffix=true, StringRef customMinusInfinityString={})
Converts a decibel reading to a string.
A simple class for holding temporary references to a string literal or String.
The JUCE String class!
Definition juce_String.h:53
void preallocateBytes(size_t numBytesNeeded)
Increases the string's internally allocated storage.
#define jassert(expression)
Platform-independent assertion macro.
T log10(T... args)
JUCE Namespace.
constexpr Type jmax(Type a, Type b)
Returns the larger of two values.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
int roundToInt(const FloatType value) noexcept
Fast floating-point-to-integer conversion.
T pow(T... args)