I try to use FMOD_OPENUSER | FMOD_CREATESTREAM mode to play audio decoded by ffmpeg. This is good in Windows as pcmreadcallback is called continuously and I can put decoded data in this function. However, pcmreadcallback is called only once in my iphone. How can I solve this problem? Here is my code:
FMOD_RESULT result;
FMOD_CREATESOUNDEXINFO exinfo;
uint32_t version;
FMOD_MODE mode = FMOD_OPENUSER | FMOD_LOOP_NORMAL | FMOD_CREATESTREAM;
result = FMOD::System_Create(&mFmodSystem);
if (result != FMOD_OK)
return;
mFmodSystem->setDriver(0);
mFmodSystem->init(32, FMOD_INIT_NORMAL, nullptr);
memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
exinfo.numchannels = 2;
exinfo.defaultfrequency = 48000;
exinfo.decodebuffersize = 1024;
exinfo.length = exinfo.defaultfrequency * exinfo.numchannels * sizeof(uint16_t) * mMediaTotalLength;
exinfo.format = FMOD_SOUND_FORMAT_PCM16;
exinfo.pcmreadcallback = pcmreadcallback;
exinfo.pcmsetposcallback = pcmreadpostcallback;
result = mFmodSystem->createSound(0, mode, &exinfo, &mFmodSound);
if (result != FMOD_OK)
return;
result = mFmodSystem->playSound(FMOD_CHANNEL_FREE, mFmodSound, false, &mFmodChannel);
if (result != FMOD_OK)
return;