I am using FMOD to make a basic synthesiser.
Consequently I am using the pcmreadcallback to call a function that generates a sine wave at different frequencies depending on the key pressed on a MID keyboard.
A bit of my code is shown below that I have put together from various sources.
It works OK apart from I get clicking everytime I cut or restore the volume (but that’s another story).

My question is that since FMOD is calling the callback function whenever it needs more samples of my sine wave why do I have too set up looping?
What actually loops? I would expect it to always be getting new data (even if it is just a repeating sine wave in this case).
Without the looping lines I get no sound.

Thanks in advance for any help.
[code:2nishyfd]FMOD_CREATESOUNDEXINFO soundInfo;
memset(&soundInfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
soundInfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
soundInfo.decodebuffersize = 2000;
soundInfo.length = sampleRate * channels * sizeof(signed short) * lengthInSeconds;
soundInfo.numchannels = channels;
soundInfo.defaultfrequency = sampleRate;
soundInfo.format = FMOD_SOUND_FORMAT_PCM16;
soundInfo.pcmreadcallback = PCMRead;
soundInfo.userdata = this;
FMOD::Sound *sound;
fmodsystem->createStream(nullptr, FMOD_OPENUSER, &soundInfo, &sound);
fmodsystem->playSound(FMOD_CHANNEL_FREE, sound, true, &channel);
channel->setPosition(0, FMOD_TIMEUNIT_MS); // this flushes the buffer to ensure the loop mode takes effect

  • You must to post comments
Showing 0 results
Your Answer

Please first to submit.