34template <
typename SampleType>
41 using NumericType =
typename SampleTypeHelpers::ElementType<SampleType>::Type;
52 size_t lookupTableNumPoints = 0)
58 bool isInitialised() const noexcept {
return static_cast<bool> (generator); }
62 size_t lookupTableNumPoints = 0)
64 if (lookupTableNumPoints != 0)
69 lookupTableNumPoints);
71 lookupTable.reset (table);
72 generator = [table] (
NumericType x) {
return (*table) (x); };
100 sampleRate =
static_cast<NumericType> (spec.sampleRate);
101 rampBuffer.
resize ((
int) spec.maximumBlockSize);
112 frequency.
reset (sampleRate, 0.05);
125 template <
typename ProcessContext>
126 void process (
const ProcessContext& context)
noexcept
129 auto&& outBlock = context.getOutputBlock();
130 auto&& inBlock = context.getInputBlock();
133 jassert (outBlock.getNumSamples() <=
static_cast<size_t> (rampBuffer.
size()));
135 auto len = outBlock.getNumSamples();
136 auto numChannels = outBlock.getNumChannels();
137 auto inputChannels = inBlock.getNumChannels();
140 if (context.isBypassed)
141 context.getOutputBlock().clear();
147 for (
size_t i = 0; i < len; ++i)
151 if (! context.isBypassed)
155 if (context.usesSeparateInputAndOutputBlocks())
157 for (ch = 0; ch < jmin (numChannels, inputChannels); ++ch)
159 auto* dst = outBlock.getChannelPointer (ch);
160 auto* src = inBlock.getChannelPointer (ch);
162 for (
size_t i = 0; i < len; ++i)
163 dst[i] = src[i] + generator (buffer[i]);
168 for (ch = 0; ch < jmin (numChannels, inputChannels); ++ch)
170 auto* dst = outBlock.getChannelPointer (ch);
172 for (
size_t i = 0; i < len; ++i)
173 dst[i] += generator (buffer[i]);
177 for (; ch < numChannels; ++ch)
179 auto* dst = outBlock.getChannelPointer (ch);
181 for (
size_t i = 0; i < len; ++i)
182 dst[i] = generator (buffer[i]);
191 if (context.isBypassed)
193 frequency.
skip (
static_cast<int> (len));
200 if (context.usesSeparateInputAndOutputBlocks())
202 for (ch = 0; ch < jmin (numChannels, inputChannels); ++ch)
205 auto* dst = outBlock.getChannelPointer (ch);
206 auto* src = inBlock.getChannelPointer (ch);
208 for (
size_t i = 0; i < len; ++i)
214 for (ch = 0; ch < jmin (numChannels, inputChannels); ++ch)
217 auto* dst = outBlock.getChannelPointer (ch);
219 for (
size_t i = 0; i < len; ++i)
224 for (; ch < numChannels; ++ch)
227 auto* dst = outBlock.getChannelPointer (ch);
229 for (
size_t i = 0; i < len; ++i)
241 std::unique_ptr<LookupTableTransform<NumericType>> lookupTable;
245 Phase<NumericType> phase;
int size() const noexcept
ElementType * getRawDataPointer() noexcept
void resize(int targetNumItems)
bool isSmoothing() const noexcept
void setCurrentAndTargetValue(FloatType newValue)
FloatType getTargetValue() const noexcept
FloatType skip(int numSamples) noexcept
FloatType getNextValue() noexcept
void reset(double sampleRate, double rampLengthInSeconds) noexcept
void setTargetValue(FloatType newValue) noexcept
SampleType JUCE_VECTOR_CALLTYPE processSample(SampleType input) noexcept
Oscillator(const std::function< NumericType(NumericType)> &function, size_t lookupTableNumPoints=0)
void prepare(const ProcessSpec &spec) noexcept
bool isInitialised() const noexcept
typename SampleTypeHelpers::ElementType< SampleType >::Type NumericType
NumericType getFrequency() const noexcept
void process(const ProcessContext &context) noexcept
void setFrequency(NumericType newFrequency, bool force=false) noexcept
void initialise(const std::function< NumericType(NumericType)> &function, size_t lookupTableNumPoints=0)
Type advance(Type increment) noexcept