# Pcmreadcallback called with wrong expected args

**URL:** <https://qa.fmod.com/t/pcmreadcallback-called-with-wrong-expected-args/21561>\
**Category:** FMOD Engine\
**Tags:** ue4, cpp\
**Created:** [April 30, 2024, 3:14am UTC](https://qa.fmod.com/t/pcmreadcallback-called-with-wrong-expected-args/21561 "2024-04-30T03:14:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stryck](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/stryck/32/6615_2.png) [@Stryck](https://qa.fmod.com/u/Stryck)\
**Post date:** [April 30, 2024, 3:14am UTC](https://qa.fmod.com/t/pcmreadcallback-called-with-wrong-expected-args/21561/1 "2024-04-30T03:14:37Z")

</div>

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

```auto

FMOD_CREATESOUNDEXINFO exInfo = {};
    		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;

    		SoundMode = FMOD_OPENUSER | FMOD_LOOP_NORMAL;

       		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;
    		}

```

```auto
cbsize = {int} 224
length = {unsigned int} 96000
fileoffset = {unsigned int} 0
numchannels = {int} 1
defaultfrequency = {int} 48000
format = {FMOD_SOUND_FORMAT} FMOD_SOUND_FORMAT_PCM16
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.

Setup:  
FMod for UE4 2.02.05

Any advice is appreciated, thanks!

---

<div class="post-metadata">

**Author:** ![cameron-fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/cameron-fmod/32/261_2.png) [@cameron-fmod](https://qa.fmod.com/u/cameron-fmod)\
**Post date:** [May 7, 2024, 1:40am UTC](https://qa.fmod.com/t/pcmreadcallback-called-with-wrong-expected-args/21561/2 "2024-05-07T01:40:25Z")

</div>

If you are wanting to continuously stream in audio, you will want to use the [FMOD\_CREATESTREAM](https://www.fmod.com/docs/api/core-api-common.html#fmod_createstream) flag when creating your sound.

```auto
SoundMode = FMOD_OPENUSER | FMOD_LOOP_NORMAL | FMOD_CREATESTREAM;

```

Otherwise FMOD will open the file as [FMOD\_CREATESAMPLE](https://www.fmod.com/docs/api/core-api-common.html#fmod_createsample) and will try to load and decompress the whole sound into memory.
