# Several frame delay when playing "some" sounds

**URL:** <https://qa.fmod.com/t/several-frame-delay-when-playing-some-sounds/18914>\
**Category:** FMOD Engine\
**Created:** [June 18, 2022, 10:51pm UTC](https://qa.fmod.com/t/several-frame-delay-when-playing-some-sounds/18914 "2022-06-18T22:51:19Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![rontt](https://avatars.discourse-cdn.com/v4/letter/r/779978/32.png) [@rontt](https://qa.fmod.com/u/rontt)\
**Post date:** [June 18, 2022, 10:51pm UTC](https://qa.fmod.com/t/several-frame-delay-when-playing-some-sounds/18914/1 "2022-06-18T22:51:19Z")

</div>

Some sounds (not all) experience a 2 or 3 frame delay before they are played. I am using FMOD\_System\_SetFileSystem to load data. I under the impression that when using this the data is streamed. I don’t know if it is the load times causing the issue since some large sounds don’t cause a delay but small ones do. It’s perplexing.

I can’t just load the events because I rarely have knowledge of the sounds that will be played at any given time, and it would be a huge burden on memory to load hundreds of anticipated events.

I’m hoping there is something I am doing wrong.

My game is all in cpp and I don’t use Unity Unreal of any other game engine.

---

<div class="post-metadata">

**Author:** ![jeff\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jeff_fmod/32/1766_2.png) [@jeff\_fmod](https://qa.fmod.com/u/jeff_fmod)\
**Post date:** [June 21, 2022, 7:22am UTC](https://qa.fmod.com/t/several-frame-delay-when-playing-some-sounds/18914/2 "2022-06-21T07:22:31Z")

</div>

I haven’t been able to reproduce any noticable delays with various sounds in the asyncio example, what version of FMOD are you using?  
You can ensure sounds are being streamed in by creating offending sounds with [`System::createStream`](https://fmod.com/resources/documentation-api?version=2.02&page=core-api-system.html#system_createstream) instead of `createSound`. Otherwise, you should be getting “Loading delay exceeded” warnings when running FMOD in logging mode, which might provide some more useufl information.  
To run FMOD in logging will need to call [`Debug_Initialize`](https://fmod.com/resources/documentation-api?version=2.02&page=core-api-common.html#debug_initialize) and link to the logging versions of the libs.

---

<div class="post-metadata">

**Author:** ![rontt](https://avatars.discourse-cdn.com/v4/letter/r/779978/32.png) [@rontt](https://qa.fmod.com/u/rontt)\
**Post date:** [July 20, 2022, 10:15pm UTC](https://qa.fmod.com/t/several-frame-delay-when-playing-some-sounds/18914/3 "2022-07-20T22:15:23Z")

</div>

I finally got the debug libs installed on the Switch. There is a 6 second delay is starting a sound. That makes little sense. I see this all over the game, this is just an easy one to make happen. It’s not feasible to “preload” sounds. The game has hundreds and hundreds of sounds and based on game play and can’t be predicted. This isn’t a game with levels that can be loaded. I sometimes see 1 or 2 frame delays on the PC, but never 6 seconds like on the Switch.

The event has 3 tracks, each with a 8 sound Multi Instrument. The sounds last 1/10 of a second, so these aren’t large sounds.

```auto
[WRN] EventInstance::update : Event {b33005ad-c309-4d10-968a-8e27a118a4fe} waited 6616 milliseconds for sample data to load. Preload sample data to avoid this delay.
NX Memory Use: 552.6M / 4758.0M heap | 1.5M / 32.0M graphics firmware | 59.1M program bytes | 2.0M stack bytes
```

---

<div class="post-metadata">

**Author:** ![rontt](https://avatars.discourse-cdn.com/v4/letter/r/779978/32.png) [@rontt](https://qa.fmod.com/u/rontt)\
**Post date:** [July 20, 2022, 10:18pm UTC](https://qa.fmod.com/t/several-frame-delay-when-playing-some-sounds/18914/4 "2022-07-20T22:18:45Z")

</div>

Here is the log when it inits

```auto
[LOG] System::create : Header version = 2.02.06. Current version = 2.02.06.
[LOG] Manager::init : maxchannels = 64 studioflags = 00000000 flags 00000000 extradriverdata 0.
[LOG] SystemI::init : Initialize version=20206 (124257), maxchannels=64, flags=0x00020000
[LOG] SystemI::setOutputInternal : Setting output to 'FMOD nn::audio Output'
[LOG] Thread::initThread : Init FMOD stream thread. Affinity: 0x4000000000000003, Priority: 0xFFFF7FFB, Stack Size: 98304, Semaphore: No, Sleep Time: 10, Looping: Yes.
[LOG] Thread::initThread : Init FMOD mixer thread. Affinity: 0x4000000000000001, Priority: 0xFFFF7FFA, Stack Size: 81920, Semaphore: No, Sleep Time: 0, Looping: Yes.
[LOG] AsyncManager::init : manager 0x2090e73008 isAsync 1 updatePeriod 0.02
[LOG] Thread::initThread : Init FMOD Studio update thread. Affinity: 0x4000000000000002, Priority: 0xFFFF7FFD, Stack Size: 98304, Semaphore: No, Sleep Time: 1, Looping: No.
[LOG] AsyncManager::init : done
[LOG] PlaybackSystem::init : 
[LOG] Thread::initThread : Init FMOD Studio sample load thread. Affinity: 0x4000000000000003, Priority: 0xFFFF7FFD, Stack Size: 98304, Semaphore: No, Sleep Time: 1, Looping: No.
[LOG] PlaybackSystem::init : done
[LOG] Thread::initThread : Init FMOD Studio bank load thread. Affinity: 0x4000000000000003, Priority: 0xFFFF7FFD, Stack Size: 98304, Semaphore: No, Sleep Time: 1, Looping: No.
[LOG] Manager::init : done.

```

---

<div class="post-metadata">

**Author:** ![rontt](https://avatars.discourse-cdn.com/v4/letter/r/779978/32.png) [@rontt](https://qa.fmod.com/u/rontt)\
**Post date:** [July 20, 2022, 10:22pm UTC](https://qa.fmod.com/t/several-frame-delay-when-playing-some-sounds/18914/5 "2022-07-20T22:22:18Z")

</div>

I have noticed that if we wait a while before starting to play much of the delay goes away. It seems that FMOD might be sill getting everything loaded (strings). If this is the case, can we just wait for all that to be done?

---

<div class="post-metadata">

**Author:** ![rontt](https://avatars.discourse-cdn.com/v4/letter/r/779978/32.png) [@rontt](https://qa.fmod.com/u/rontt)\
**Post date:** [July 20, 2022, 11:25pm UTC](https://qa.fmod.com/t/several-frame-delay-when-playing-some-sounds/18914/6 "2022-07-20T23:25:33Z")

</div>

The log is filled with these:

```auto
[LOG] SystemI::createSoundInternal : Sample 0/1: name='amb_cave_drip_flooded_09', format=2, channels=2, frequency=48000, lengthbytes=151776, lengthpcm=138752, pcmblocksize=256, loopstart=0, loopend=0, mode=0x00000000, channelmask=0x00000000, channelorder=0, peakvolume=0.581861.
[LOG] SystemI::createSoundInternal : Create name='', mode=0x02000202
[LOG] SystemI::createSoundInternal : exinfo->cbsize = 224
[LOG] SystemI::createSoundInternal : exinfo->length = 1407156736
[LOG] SystemI::createSoundInternal : exinfo->fileoffset = 466176
[LOG] SystemI::createSoundInternal : exinfo->numsubsounds = 1
[LOG] SystemI::createSoundInternal : exinfo->inclusionlist = 0x107c22086c
[LOG] SystemI::createSoundInternal : exinfo->inclusionlistnum = 1
[LOG] SystemI::createSoundInternal : exinfo->encryptionkey = skkpycwtxzxnbozd0hb1ial0hxnrbuo0
[LOG] SystemI::createSoundInternal : exinfo->suggestedsoundtype = 5
[LOG] SystemI::createSoundInternal : exinfo->useropen = 0x8480bb0
[LOG] SystemI::createSoundInternal : exinfo->userclose = 0x8480c80
[LOG] SystemI::createSoundInternal : exinfo->userread = 0x8480cc0
[LOG] SystemI::createSoundInternal : exinfo->userseek = 0x8480d90
[LOG] SystemI::createSoundInternal : exinfo->fileuserdata = 0x2096c5a6c8
[LOG] SystemI::createSoundInternal : exinfo->initialseekpostype = 1
[LOG] SystemI::DSPCodecPoolRegister : register codec pool for pool type 7

```

These happen when the bank is loaded (FMOD\_Studio\_System\_LoadBankFile). I’m not playing any of these sounds. Is there a way to wait until this is over, or am I initing the banks wrong?

---

<div class="post-metadata">

**Author:** ![rontt](https://avatars.discourse-cdn.com/v4/letter/r/779978/32.png) [@rontt](https://qa.fmod.com/u/rontt)\
**Post date:** [July 21, 2022, 7:20pm UTC](https://qa.fmod.com/t/several-frame-delay-when-playing-some-sounds/18914/7 "2022-07-21T19:20:54Z")

</div>

I am using FMOD\_Studio\_EventInstance\_Start to start events, is there a way to make them streaming by default?

---

<div class="post-metadata">

**Author:** ![jeff\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jeff_fmod/32/1766_2.png) [@jeff\_fmod](https://qa.fmod.com/u/jeff_fmod)\
**Post date:** [July 22, 2022, 4:27am UTC](https://qa.fmod.com/t/several-frame-delay-when-playing-some-sounds/18914/8 "2022-07-22T04:27:52Z")

</div>

Thank you for the additional information. 6 seconfs is a significantly long time for such a short sound to load. If you are able to share your Master.bank file and the bank file that this event is contained in I can try reproducing this issue and see what’s going wrong?

> [@rontt](#):
>
> I’m not playing any of these sounds. Is there a way to wait until this is over, or am I initing the banks wrong?

Loading a bank alone shouldn’t result in all of these sounds being created. A call to [`FMOD_Studio_EventDescription_CreateInstance`](https://fmod.com/docs/2.02/api/studio-api-eventdescription.html#studio_eventdescription_createinstance) will cause sample data to be loaded, otherwise are you calling [`FMOD_Studio_Bank_LoadSampleData`](https://fmod.com/docs/2.02/api/studio-api-bank.html#studio_bank_loadsampledata) anywhere to load all of the sample data in a bank, or [`FMOD_Studio_EventDescription_LoadSampleData`](https://fmod.com/docs/2.02/api/studio-api-eventdescription.html#studio_eventdescription_loadsampledata) to load the sample data for individual events?

> [@rontt](#):
>
> I am using FMOD\_Studio\_EventInstance\_Start to start events, is there a way to make them streaming by default?

In FMOD Studio you can set inidividual assets to be streamed in by setting its [Loading Mode](https://fmod.com/docs/2.02/studio/managing-assets.html#loading-modes) in the Audio Bin, or you can set the loading mode for everything for a Platform by going to Edit\>Preferences…\>Build\>{Platform name}\>Advanced Loading Mode.  
For the offending sounds in this case, if they are encoded as an MP3, Vorbis or FADPCM then you will be able to take advantage of the [Compressed Sample](https://fmod.com/docs/2.02/api/glossary.html#compressed-sample) loading mode which will load faster than the default [Sample](https://fmod.com/docs/2.02/api/glossary.html#sample) (Decompressed Sample) loading mode. Stream is usually best suited for larger sounds and you should aim to limit the amount of them you have playing at any one time.

---

<div class="post-metadata">

**Author:** ![rontt](https://avatars.discourse-cdn.com/v4/letter/r/779978/32.png) [@rontt](https://qa.fmod.com/u/rontt)\
**Post date:** [August 8, 2022, 10:21pm UTC](https://qa.fmod.com/t/several-frame-delay-when-playing-some-sounds/18914/9 "2022-08-08T22:21:27Z")

</div>

I have some more information about what appears to be happening. All the ambient sounds for the entire game are in one event (made from 100’s of wav files) and I use a param to jump around based on the location. When I first start the ambience I get the stream of `SystemI::createSoundInternal` calls and while this is happening (in the background) all new events seem to be blocked.

Setting up the ambience like that was probably not a good idea, but it’s too late to change. Is there a API call I can do to know if new events are going to be blocked?

The only platform where this is causing issues is the Switch.

---

<div class="post-metadata">

**Author:** ![jeff\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jeff_fmod/32/1766_2.png) [@jeff\_fmod](https://qa.fmod.com/u/jeff_fmod)\
**Post date:** [August 9, 2022, 7:12am UTC](https://qa.fmod.com/t/several-frame-delay-when-playing-some-sounds/18914/10 "2022-08-09T07:12:03Z")

</div>

Thank you for the additional information, I will see if I can setup a similarly large event and reproduce this problem on Switch.

> [@rontt](#):
>
> Is there a API call I can do to know if new events are going to be blocked?

Perhaps you can try polling the sample loading state of that event using [EventDescription::getSampleLoadingState](https://fmod.com/docs/2.02/api/studio-api-eventdescription.html#studio_eventdescription_getsampleloadingstate).  
While that reports `FMOD_STUDIO_LOADING_STATE_LOADING` you will know that any subsequent events will not be able to load as that thread is occupied, and once it returns `FMOD_STUDIO_LOADING_STATE_LOADED` you can move on to loading other events. Alternatively, you can call [Studio::System::flushSampleLoading](https://fmod.com/docs/2.02/api/studio-api-system.html#studio_system_flushsampleloading) immediately after beginning to load that event’s sample data. This will block the calling thread until all sample loading and unloading has completed, and then you can try playing/loading any other events after that.
