After some digging finally found out where the issues are but don’t understand why it is.
So we have a DSP attached the master channel group, does not alter the sound but just to pull a precise DSP Clock from. It is created with the following code:
FMOD_DSP_DESCRIPTION dspdesc;
memset(&dspdesc, 0, sizeof(FMOD_DSP_DESCRIPTION));
strcpy(dspdesc.name, "Clock Sync");
dspdesc.read = clockSyncDSPCallback;
dspdesc.version = 0x00010000;
dspdesc.userdata = (void *)0x12345678;
dspdesc.numinputbuffers = 1; // 0 to generate sound, 1 to process sound
dspdesc.numoutputbuffers = 1;
FMOD_RESULT result = pSys->createDSP(&dspdesc, &dspClockSync_);
ERRCHECK(result);
FMOD::ChannelGroup *channelgroup_master;
FMOD::DSP* dspHead;
result = pSys->getMasterChannelGroup(&channelgroup_master);
result = channelgroup_master->getDSP(FMOD_CHANNELCONTROL_DSP_HEAD, &dspHead);
ERRCHECK(result );
result = dspHead->addInput( dspClockSync_, &syncConnection_ );
dspClockSync_->setActive( true );
And the callback function is just passing the data to out buffer, and grab position from a bgm channel:
for (unsigned int samp = 0; samp < length; samp++)
for (int chan = 0; chan < *outchannels; chan++)
outbuffer[(samp * *outchannels) + chan] = inbuffer[(samp * inchannels) + chan];
unsigned int channelPos = 0;
syncChannel_->getPosition( &channelPos, FMOD_TIMEUNIT_MS )
return FMOD_OK;
And then on each note channel, we’ve added a simple envelope DSP to do the fade out. It is created as below:
FMOD_DSP_DESCRIPTION dspdesc;
memset(&dspdesc, 0, sizeof(FMOD_DSP_DESCRIPTION));
strcpy(dspdesc.name, "Volume Envelope");
dspdesc.read = volEnvelopeDSPCallback;
dspdesc.userdata = (void *)(envelopeSetIndex);
dspdesc.version = 0x00010000;
dspdesc.numinputbuffers = 1; // 0 to generate sound, 1 to process sound
dspdesc.numoutputbuffers = 1;
FMOD_RESULT result = pSys->createDSP(&dspdesc, &dsp_);
these envelope DSP are added to the generated channels per each note, and just does some standard processing.
The weird behaviour is - if I omit the data copying code in the clock DSP, then half the note will be making sound (as described in the previous comments); if I have the clock DSP copying buffer, then no sound is generated; if I remove the envelope DSPs, then all notes start to make sound.
Is there anything wrong in the way I’m creating the DSPs?