Browse Source

Added a safety assertion to check if an Oscillator's been initialised

tags/2021-05-28
jules 7 years ago
parent
commit
c1bdfc6a55
1 changed files with 5 additions and 0 deletions
  1. +5
    -0
      modules/juce_dsp/processors/juce_Oscillator.h

+ 5
- 0
modules/juce_dsp/processors/juce_Oscillator.h View File

@@ -55,6 +55,9 @@ public:
initialise (function, lookupTableNumPoints);
}
/** Returns true if the Oscillator has been initialised. */
bool isInitialised() const noexcept { return static_cast<bool> (generator); }
/** Initialises the oscillator with a waveform. */
void initialise (const std::function<NumericType (NumericType)>& function, size_t lookupTableNumPoints = 0)
{
@@ -102,6 +105,7 @@ public:
/** Returns the result of processing a single sample. */
SampleType JUCE_VECTOR_CALLTYPE processSample (SampleType) noexcept
{
jassert (isInitialised());
auto increment = static_cast<NumericType> (2.0 * double_Pi) * frequency.getNextValue() / sampleRate;
auto value = generator (pos - static_cast<NumericType> (double_Pi));
pos = std::fmod (pos + increment, static_cast<NumericType> (2.0 * double_Pi));
@@ -113,6 +117,7 @@ public:
template <typename ProcessContext>
void process (const ProcessContext& context) noexcept
{
jassert (isInitialised());
auto&& outBlock = context.getOutputBlock();
// this is an output-only processory


Loading…
Cancel
Save