34template <
typename SampleType>
41 using NumericType =
typename SampleTypeHelpers::ElementType<SampleType>::Type;
71 lookupTable.reset (table);
72 generator = [table] (
NumericType x) {
return (*table) (x); };
101 rampBuffer.
resize ((
int)
spec.maximumBlockSize);
112 frequency.
reset (sampleRate, 0.05);
125 template <
typename ProcessContext>
129 auto&&
outBlock = context.getOutputBlock();
130 auto&&
inBlock = context.getInputBlock();
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)
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)
172 for (
size_t i = 0; i < len; ++i)
173 dst[i] += generator (buffer[i]);
177 for (;
ch < numChannels; ++
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)
206 auto* src =
inBlock.getChannelPointer (
ch);
208 for (
size_t i = 0; i < len; ++i)
214 for (
ch = 0;
ch <
jmin (numChannels, inputChannels); ++
ch)
219 for (
size_t i = 0; i < len; ++i)
224 for (;
ch < numChannels; ++
ch)
229 for (
size_t i = 0; i < len; ++i)
245 Phase<NumericType> phase;
Holds a resizable array of primitive or copy-by-value objects.
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.
A utility class for values that need smoothing to avoid audio glitches.
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.
constexpr Type jmin(Type a, Type b)
Returns the smaller 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...
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...