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.
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;
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
- bb586 asked 5 years ago
- You must login to post comments