LMMS
Loading...
Searching...
No Matches
juce_Gain.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 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28namespace dsp
29{
30
36template <typename FloatType>
37class Gain
38{
39public:
40 Gain() noexcept = default;
41
42 //==============================================================================
44 void setGainLinear (FloatType newGain) noexcept { gain.setTargetValue (newGain); }
45
47 void setGainDecibels (FloatType newGainDecibels) noexcept { setGainLinear (Decibels::decibelsToGain<FloatType> (newGainDecibels)); }
48
50 FloatType getGainLinear() const noexcept { return gain.getTargetValue(); }
51
54
56 void setRampDurationSeconds (double newDurationSeconds) noexcept
57 {
58 if (rampDurationSeconds != newDurationSeconds)
59 {
60 rampDurationSeconds = newDurationSeconds;
61 reset();
62 }
63 }
64
67
69 bool isSmoothing() const noexcept { return gain.isSmoothing(); }
70
71 //==============================================================================
73 void prepare (const ProcessSpec& spec) noexcept
74 {
75 sampleRate = spec.sampleRate;
76 reset();
77 }
78
81 {
82 if (sampleRate > 0)
84 }
85
86 //==============================================================================
88 template <typename SampleType>
89 SampleType JUCE_VECTOR_CALLTYPE processSample (SampleType s) noexcept
90 {
91 return s * gain.getNextValue();
92 }
93
95 template <typename ProcessContext>
96 void process (const ProcessContext& context) noexcept
97 {
98 auto&& inBlock = context.getInputBlock();
99 auto&& outBlock = context.getOutputBlock();
100
101 jassert (inBlock.getNumChannels() == outBlock.getNumChannels());
102 jassert (inBlock.getNumSamples() == outBlock.getNumSamples());
103
104 auto len = inBlock.getNumSamples();
105 auto numChannels = inBlock.getNumChannels();
106
107 if (context.isBypassed)
108 {
109 gain.skip (static_cast<int> (len));
110
111 if (context.usesSeparateInputAndOutputBlocks())
112 outBlock.copyFrom (inBlock);
113
114 return;
115 }
116
117 if (numChannels == 1)
118 {
119 auto* src = inBlock.getChannelPointer (0);
120 auto* dst = outBlock.getChannelPointer (0);
121
122 for (size_t i = 0; i < len; ++i)
123 dst[i] = src[i] * gain.getNextValue();
124 }
125 else
126 {
128 auto* gains = static_cast<FloatType*> (alloca (sizeof (FloatType) * len));
129
130 for (size_t i = 0; i < len; ++i)
131 gains[i] = gain.getNextValue();
133
134 for (size_t chan = 0; chan < numChannels; ++chan)
135 FloatVectorOperations::multiply (outBlock.getChannelPointer (chan),
136 inBlock.getChannelPointer (chan),
137 gains, static_cast<int> (len));
138 }
139 }
140
141private:
142 //==============================================================================
145};
146
147} // namespace dsp
148} // namespace juce
#define noexcept
Definition DistrhoDefines.h:72
static Type decibelsToGain(Type decibels, Type minusInfinityDb=Type(defaultMinusInfinitydB))
Definition juce_Decibels.h:42
static Type gainToDecibels(Type gain, Type minusInfinityDb=Type(defaultMinusInfinitydB))
Definition juce_Decibels.h:56
Definition juce_SmoothedValue.h:227
FloatType getGainDecibels() const noexcept
Definition juce_Gain.h:53
double rampDurationSeconds
Definition juce_Gain.h:144
FloatType getGainLinear() const noexcept
Definition juce_Gain.h:50
double sampleRate
Definition juce_Gain.h:144
void prepare(const ProcessSpec &spec) noexcept
Definition juce_Gain.h:73
double getRampDurationSeconds() const noexcept
Definition juce_Gain.h:66
bool isSmoothing() const noexcept
Definition juce_Gain.h:69
void setGainLinear(FloatType newGain) noexcept
Definition juce_Gain.h:44
SampleType JUCE_VECTOR_CALLTYPE processSample(SampleType s) noexcept
Definition juce_Gain.h:89
Gain() noexcept=default
void reset() noexcept
Definition juce_Gain.h:80
void process(const ProcessContext &context) noexcept
Definition juce_Gain.h:96
SmoothedValue< FloatType > gain
Definition juce_Gain.h:143
void setRampDurationSeconds(double newDurationSeconds) noexcept
Definition juce_Gain.h:56
void setGainDecibels(FloatType newGainDecibels) noexcept
Definition juce_Gain.h:47
register unsigned i
Definition inflate.c:1575
unsigned s
Definition inflate.c:1555
#define JUCE_BEGIN_IGNORE_WARNINGS_MSVC(warnings)
Definition juce_CompilerWarnings.h:198
#define JUCE_END_IGNORE_WARNINGS_MSVC
Definition juce_CompilerWarnings.h:199
#define jassert(expression)
#define JUCE_VECTOR_CALLTYPE
Definition juce_dsp.h:100
Definition juce_AudioBlock.h:29
Definition carla_juce.cpp:31
Definition juce_ProcessContext.h:38
#define const
Definition zconf.h:137