Pcmreadcallback called with wrong expected args


Hey All, I’ve been working on streaming voice audio to FMOD, and have run into a few problems with fmod’s pcmreadcallback. Specifically, I seem to be over, then underbuffering the audio buffer so I have a gap in the beginning, then under-buffering pops mid stream.

From what I can tell, the pcmreadcallback is not being called with the DecodeBufferSize as described, but instead is being called with the length parameter of FMOD_CREATESOUNDEXINFO

    		exInfo.cbsize  = sizeof(FMOD_CREATESOUNDEXINFO);
    		exInfo.pcmreadcallback = ProgrammerSoundPCMReadCallback;
    		exInfo.userdata = this;
    		exInfo.numchannels = CustomPCMChannelCount;
    		exInfo.defaultfrequency  = CustomPCMSampleRate;                           /* Default playback rate of sound. */

    		float BytesPerSeconds = exInfo.defaultfrequency * exInfo.numchannels * sizeof(signed short);

    		float BufferSize = BytesPerSeconds * BufferSizeTimeSeconds;
    		exInfo.decodebuffersize  = BufferSize; /* Chunk size of stream update in samples. This will be the amount of data passed to the user callback. */

    		float FullLength = BytesPerSeconds * ProgrammerSoundLengthSeconds;
    		exInfo.length            = FullLength; /* Length of PCM data in bytes of whole song (for Sound::getLength) */
    		exInfo.format = FMOD_SOUND_FORMAT_PCM16;


       		FMOD::Sound *Sound = nullptr;
    		if (LowLevelSystem->createSound(TCHAR_TO_UTF8(*ProgrammerSoundNameCopy), SoundMode, &exInfo, &Sound) == FMOD_OK)
    			props->sound = reinterpret_cast<FMOD_SOUND*>(Sound);
    			props->subsoundIndex = -1;
    			NeedDestroyProgrammerSoundCallback = true;
cbsize = {int} 224
length = {unsigned int} 96000
fileoffset = {unsigned int} 0
numchannels = {int} 1
defaultfrequency = {int} 48000
decodebuffersize = {unsigned int} 9600

This all seems correct according to documentation, however when the pcmreadcallback is hit the datalen variable is 96000, and seems to mirror any changes to the sound length.

Not sure if this is a bug in the SDK, or if I need to hack around this to enforce the correct buffer rate.

FMod for UE4 2.02.05

Any advice is appreciated, thanks!

If you are wanting to continuously stream in audio, you will want to use the FMOD_CREATESTREAM flag when creating your sound.


Otherwise FMOD will open the file as FMOD_CREATESAMPLE and will try to load and decompress the whole sound into memory.