Bad Access when setting sample rate - Synth

dsp
dsp_module

#1

I am trying to create a synth. There is a Bad Access Error pointing to this peice of code below where the sample rate is set to sr,

sr = 44100 set in a function just above.

void OscillatorBase::setSampleRate (float sr)
{
    sampleRate = sr;
    setFrequency (frequency); //just to update the phaseInc
}

In the audio class, an instance of the oscillator base class is called like so:

Atomic<OscillatorBase*> oscillatorBasePtr;

Along with the error, this is shown as:

this OscillatorBase * NULL 0x0000000000000000

I believe it’s an issue with the way the classes are communicating. I have the correct #includes in place etc. Any input is much appreciated.

Thanks.


#2

Apparently you never assign a new instance of the oscillator into the pointer? It’s impossible to say anything more based on the information you have provided so far.


#3

This line assigns a new instance within the audio .cpp file

oscillatorBasePtr = new SinOscillator;

OscillatorBase is a base from which SinOscillator inherits. OscillatorbasePtr is an instance of a SinOscillator.