Hello FMOD forum,
I’m stuck on something very simple. I have a function that creates a DSP unit and a new instance of a class, sets the dsp’s frequency, and pushes a pointer to the DSP onto a vector where all the DSP pointers are stored. Each object of the class is assigned the dsp’s name and index in the vector, and is also assigned a channel. During runtime, in an infinite loop I have a call to each instance of the class, telling it to turn the DSP it was assigned on or off if a certain condition is met.
Code is below. Disclaimer: I’m a novice and don’t understand how DSPs work.
//objects of my class are stored in vector objVec
//both vectors are declared globally (eep)
std::vector <Obj> objVec;
std::vector <FMOD::DSP *> dspVec;
/*newObj constructs an instance of the Obj class and a DSP, pushed the DSP onto dspVec*/
void newObj(FMOD::Channel** cn, FMOD::DSP* dspname, double freq, int dspindex){
FMOD_RESULT result;
Obj nObj = Obj( cn, dspname, freq, dspindex);
system->createDSPByType(
FMOD_DSP_TYPE_OSCILLATOR,
dspname
);
dspname->setParameter(
FMOD_DSP_OSCILLATOR_RATE,
freq
);
result = Asystem->playDSP(FMOD_CHANNEL_REUSE, dspname, false, cn);
dspVec.push_back(dspname);
objVec.push_back(nObj);
}
/* Obj class has functions getChannel() - which returns a pointer to a pointer to a channel - and getDspIndex(). */
void display() { //called continuously in infinite loop
FMOD_RESULT result;
//opengl stuff
for (int i = 0; i < objVec.size(); i++) {
FMOD::Channel* currentchannel = *objVec[i].getChannel();
FMOD::DSP* currentdsp = dspVec[(objlVec[i].getDspIndex())];
if (condition)
{
currentdsp->setActive(true);
}
else if (another condition)
{
currentdsp->setActive(false);
}
}
//opengl stuff
}
All this doesn’t work. It produces sound for a moment and then crashes. For what its worth, if instead of setting the dsps Active and Inactive I just pause and unpause the channels, the sound works fine (although obviously that work-around has little value, since I’ll have many DSPs on each channel).
Please let me know if I should provide more info. Thanks for any responses!