That fixed it, and opened up a new issue, I swear we must be so very close! pcmreadcallback seems to only get called once.
If I just chain send the samples I get mostly working audio, but stuttering. So I changed it to give FMOD a linked list of samples, in hopes that fmod would use pcmreadcallback at it’s own leisure, and that would give each following sample as requested.
I suspect this is a problem with FMOD_CREATESOUNDEXINFO::Length? But unsure. I tried a number of things with it (including giving it the total size of the entire queue,) swapping createsound/createstream, and a wide number of mode setting with no luck. I got a slight improvement with FMOD_LOOP_NORMAL but it was mostly a wash. I did run a mp3 on the same groupchannel as a test so the rest of the system is working at least. As normal here is the latest codedump, callback function first.
FMOD_RESULT F_CALLBACK pcmQueue(FMOD_SOUND* pSound, void* pData, unsigned int nDataLen)
FMOD::Sound* pCurrentSound = (FMOD::Sound*)pSound;
void* pUserData = 0;
AudioCallbackQueue* pCurrent = 0;
FMOD_RESULT fError = FMOD_OK;
fError = pCurrentSound->getUserData( &pUserData );
pCurrent = (AudioCallbackQueue*)pUserData;
if(pCurrent != 0)
unsigned int nSize = sizeof(float) * (pCurrent->pRawAudio->frames) * (pCurrent->pRawAudio->channels);
if (nSize > nDataLen) //Not all samples are the same size.
nSize = nDataLen;
memcpy_s(pData, nDataLen, (pCurrent->pRawAudio->samples), nSize);
pCurrent = pCurrent->pNext;
void AudioSystem::RawAudio(RawSound* pAudio)
FMOD::Sound* pNewFSound = 0;
SoundHandle* pCurrentHandle = mapSoundObjects[pAudio->nID];
unsigned int nSampleSize = 0;
if (pCurrentHandle->pChannel != 0) //Checking we don't steal a channel by mistake
if (pNewFSound == pCurrentHandle->pSound)
pCurrentHandle->pChannel->stop(); //If we reached here, we where still using the channel, so we can tell it to stop.
while (pCurrentHandle->pQueueStart != 0) //Old queue out of date, clean up.
AudioCallbackQueue* pNext = pCurrentHandle->pQueueStart->pNext;
pCurrentHandle->pQueueStart = pNext;
pCurrentHandle->pQueueStart = pAudio->pQueue;
std::cout << "Giving Audio Queue \n"; //Lets me see in a console window the rate of function calls
nSampleSize = (sizeof(float) * (pCurrentHandle->pQueueStart->pRawAudio->frames) * (pCurrentHandle->pQueueStart->pRawAudio->channels));
memset(&fExtra, 0, sizeof(FMOD_CREATESOUNDEXINFO));
fExtra.length = nSampleSize;
fExtra.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
fExtra.defaultfrequency = pCurrentHandle->pQueueStart->pRawAudio->freq;
fExtra.numchannels = pCurrentHandle->pQueueStart->pRawAudio->channels;
fExtra.userdata = (void*)(pCurrentHandle->pQueueStart);
fExtra.format = FMOD_SOUND_FORMAT_PCMFLOAT;
fExtra.pcmreadcallback = pcmQueue;
resError = m_pSystem->createStream(0, FMOD_CREATESTREAM | FMOD_OPENUSER, &fExtra, &pNewFSound);
resError = m_pSystem->playSound(pNewFSound, vecSoundsAndChannels[ENUMSOUNDTYPE::eVIDEOAUDIO]->pChannelGroupData, false, &(pCurrentHandle->pChannel));
Sorry for messy code, doing this in the middle of a game jam so lots of panic!