41 template <
typename SampleType>
48 using NumericType =
typename SampleTypeHelpers::ElementType<SampleType>::Type;
59 size_t lookupTableNumPoints = 0)
65 bool isInitialised() const noexcept {
return static_cast<bool> (generator); }
69 size_t lookupTableNumPoints = 0)
71 if (lookupTableNumPoints != 0)
76 lookupTableNumPoints);
78 lookupTable.reset (table);
79 generator = [table] (
NumericType x) {
return (*table) (x); };
107 sampleRate =
static_cast<NumericType> (spec.sampleRate);
108 rampBuffer.
resize ((
int) spec.maximumBlockSize);
119 frequency.
reset (sampleRate, 0.05);
132 template <
typename ProcessContext>
133 void process (
const ProcessContext& context) noexcept
136 auto&& outBlock = context.getOutputBlock();
137 auto&& inBlock = context.getInputBlock();
140 jassert (outBlock.getNumSamples() <=
static_cast<size_t> (rampBuffer.
size()));
142 auto len = outBlock.getNumSamples();
143 auto numChannels = outBlock.getNumChannels();
144 auto inputChannels = inBlock.getNumChannels();
147 if (context.isBypassed)
148 context.getOutputBlock().clear();
154 for (
size_t i = 0; i < len; ++i)
158 if (! context.isBypassed)
162 if (context.usesSeparateInputAndOutputBlocks())
164 for (ch = 0; ch < jmin (numChannels, inputChannels); ++ch)
166 auto* dst = outBlock.getChannelPointer (ch);
167 auto* src = inBlock.getChannelPointer (ch);
169 for (
size_t i = 0; i < len; ++i)
170 dst[i] = src[i] + generator (buffer[i]);
175 for (ch = 0; ch < jmin (numChannels, inputChannels); ++ch)
177 auto* dst = outBlock.getChannelPointer (ch);
179 for (
size_t i = 0; i < len; ++i)
180 dst[i] += generator (buffer[i]);
184 for (; ch < numChannels; ++ch)
186 auto* dst = outBlock.getChannelPointer (ch);
188 for (
size_t i = 0; i < len; ++i)
189 dst[i] = generator (buffer[i]);
198 if (context.isBypassed)
200 frequency.
skip (
static_cast<int> (len));
207 if (context.usesSeparateInputAndOutputBlocks())
209 for (ch = 0; ch < jmin (numChannels, inputChannels); ++ch)
212 auto* dst = outBlock.getChannelPointer (ch);
213 auto* src = inBlock.getChannelPointer (ch);
215 for (
size_t i = 0; i < len; ++i)
221 for (ch = 0; ch < jmin (numChannels, inputChannels); ++ch)
224 auto* dst = outBlock.getChannelPointer (ch);
226 for (
size_t i = 0; i < len; ++i)
231 for (; ch < numChannels; ++ch)
234 auto* dst = outBlock.getChannelPointer (ch);
236 for (
size_t i = 0; i < len; ++i)
248 std::unique_ptr<LookupTableTransform<NumericType>> lookupTable;
252 Phase<NumericType> phase;
int size() const noexcept
Returns the current number of elements in the array.
ElementType * getRawDataPointer() noexcept
Returns a pointer to the actual array data.
void resize(int targetNumItems)
This will enlarge or shrink the array to the given number of elements, by adding or removing items fr...
bool isSmoothing() const noexcept
Returns true if the current value is currently being interpolated.
void setCurrentAndTargetValue(FloatType newValue)
Sets the current value and the target value.
FloatType getTargetValue() const noexcept
Returns the target value towards which the smoothed value is currently moving.
FloatType skip(int numSamples) noexcept
Skip the next numSamples samples.
FloatType getNextValue() noexcept
Compute the next value.
void reset(double sampleRate, double rampLengthInSeconds) noexcept
Reset to a new sample rate and ramp length.
void setTargetValue(FloatType newValue) noexcept
Set the next value to ramp towards.
Generates a signal based on a user-supplied function.
SampleType JUCE_VECTOR_CALLTYPE processSample(SampleType input) noexcept
Returns the result of processing a single sample.
Oscillator(const std::function< NumericType(NumericType)> &function, size_t lookupTableNumPoints=0)
Creates an oscillator with a periodic input function (-pi..pi).
Oscillator()=default
Creates an uninitialised oscillator.
void prepare(const ProcessSpec &spec) noexcept
Called before processing starts.
bool isInitialised() const noexcept
Returns true if the Oscillator has been initialised.
typename SampleTypeHelpers::ElementType< SampleType >::Type NumericType
The NumericType is the underlying primitive type used by the SampleType (which could be either a prim...
void reset() noexcept
Resets the internal state of the oscillator.
NumericType getFrequency() const noexcept
Returns the current frequency of the oscillator.
void process(const ProcessContext &context) noexcept
Processes the input and output buffers supplied in the processing context.
void setFrequency(NumericType newFrequency, bool force=false) noexcept
Sets the frequency of the oscillator.
void initialise(const std::function< NumericType(NumericType)> &function, size_t lookupTableNumPoints=0)
Initialises the oscillator with a waveform.
Commonly used mathematical constants.
void reset() noexcept
Resets the phase to 0.
Type advance(Type increment) noexcept
Returns the current value, and increments the phase by the given increment.
This structure is passed into a DSP algorithm's prepare() method, and contains information about vari...