1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

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

This commit is contained in:
jules 2017-11-01 17:31:00 +00:00
parent 0b19702306
commit c1bdfc6a55

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