LMMS
Loading...
Searching...
No Matches
juce_Bias.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
42template <typename FloatType>
43class Bias
44{
45public:
46 Bias() noexcept = default;
47
48 //==============================================================================
52 void setBias (FloatType newBias) noexcept
53 {
54 jassert (newBias >= static_cast<FloatType> (-1) && newBias <= static_cast<FloatType> (1));
55 bias.setTargetValue (newBias);
56 }
57
58 //==============================================================================
62 FloatType getBias() const noexcept { return bias.getTargetValue(); }
63
65 void setRampDurationSeconds (double newDurationSeconds) noexcept
66 {
67 if (rampDurationSeconds != newDurationSeconds)
68 {
69 rampDurationSeconds = newDurationSeconds;
70 updateRamp();
71 }
72 }
73
75
76 //==============================================================================
78 void prepare (const ProcessSpec& spec) noexcept
79 {
80 sampleRate = spec.sampleRate;
81 updateRamp();
82 }
83
85 {
87 }
88
89 //==============================================================================
91 template <typename SampleType>
92 SampleType processSample (SampleType inputSample) noexcept
93 {
94 return inputSample + bias.getNextValue();
95 }
96
97 //==============================================================================
99 template <typename ProcessContext>
100 void process (const ProcessContext& context) noexcept
101 {
102 auto&& inBlock = context.getInputBlock();
103 auto&& outBlock = context.getOutputBlock();
104
105 jassert (inBlock.getNumChannels() == outBlock.getNumChannels());
106 jassert (inBlock.getNumSamples() == outBlock.getNumSamples());
107
108 auto len = inBlock.getNumSamples();
109 auto numChannels = inBlock.getNumChannels();
110
111 if (context.isBypassed)
112 {
113 bias.skip (static_cast<int> (len));
114
115 if (context.usesSeparateInputAndOutputBlocks())
116 outBlock.copyFrom (inBlock);
117
118 return;
119 }
120
121 if (numChannels == 1)
122 {
123 auto* src = inBlock.getChannelPointer (0);
124 auto* dst = outBlock.getChannelPointer (0);
125
126 for (size_t i = 0; i < len; ++i)
127 dst[i] = src[i] + bias.getNextValue();
128 }
129 else
130 {
132 auto* biases = static_cast<FloatType*> (alloca (sizeof (FloatType) * len));
133
134 for (size_t i = 0; i < len; ++i)
135 biases[i] = bias.getNextValue();
136
137 for (size_t chan = 0; chan < numChannels; ++chan)
138 FloatVectorOperations::add (outBlock.getChannelPointer (chan),
139 inBlock.getChannelPointer (chan),
140 biases, static_cast<int> (len));
142 }
143 }
144
145
146private:
147 //==============================================================================
150
152 {
153 if (sampleRate > 0)
155 }
156};
157
158} // namespace dsp
159} // namespace juce
#define noexcept
Definition DistrhoDefines.h:72
Definition juce_SmoothedValue.h:227
SmoothedValue< FloatType > bias
Definition juce_Bias.h:148
SampleType processSample(SampleType inputSample) noexcept
Definition juce_Bias.h:92
Bias() noexcept=default
double getRampDurationSeconds() const noexcept
Definition juce_Bias.h:74
FloatType getBias() const noexcept
Definition juce_Bias.h:62
double rampDurationSeconds
Definition juce_Bias.h:149
double sampleRate
Definition juce_Bias.h:149
void prepare(const ProcessSpec &spec) noexcept
Definition juce_Bias.h:78
void updateRamp() noexcept
Definition juce_Bias.h:151
void setRampDurationSeconds(double newDurationSeconds) noexcept
Definition juce_Bias.h:65
void setBias(FloatType newBias) noexcept
Definition juce_Bias.h:52
void reset() noexcept
Definition juce_Bias.h:84
void process(const ProcessContext &context) noexcept
Definition juce_Bias.h:100
register unsigned i
Definition inflate.c:1575
#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)
Definition juce_AudioBlock.h:29
Definition carla_juce.cpp:31
Definition juce_ProcessContext.h:38
#define const
Definition zconf.h:137