# MIDIs Fail to Loop Using createStream()

**URL:** <https://qa.fmod.com/t/midis-fail-to-loop-using-createstream/13362>\
**Category:** FMOD Engine\
**Created:** [August 15, 2017, 10:55pm UTC](https://qa.fmod.com/t/midis-fail-to-loop-using-createstream/13362 "2017-08-15T22:55:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Spirrwell](https://avatars.discourse-cdn.com/v4/letter/s/ecd19e/32.png) [@Spirrwell](https://qa.fmod.com/u/Spirrwell)\
**Post date:** [August 15, 2017, 10:55pm UTC](https://qa.fmod.com/t/midis-fail-to-loop-using-createstream/13362/1 "2017-08-15T22:55:04Z")

</div>

Hello there,

I’ve run into a weird issue with FMOD not wanting to loop MIDI files if I use createStream instead of createSound. Using createSound() works as intended.

I’m using version 1.09.06, and here is a pastebin of my code [https://pastebin.com/UJT5MNMj](https://pastebin.com/UJT5MNMj)

It’s fairly straightforward. Running in debug mode doesn’t show anything weird. At the end of the MIDI it will just just say that the thread finished with return code 0.

As far as I can tell, it happens with all midis, but here’s one in particular I tried [https://en.wikipedia.org/wiki/File:MIDI\_sample.mid?qsrc=3044](https://en.wikipedia.org/wiki/File:MIDI_sample.mid?qsrc=3044)

I’m using VS2017, running Windows 7 Ultimate 64 bit. I haven’t tried running the program with 32 bit FMOD, but I imagine it’s the same.

---

<div class="post-metadata">

**Author:** ![brett](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/brett/32/261_2.png) [@brett](https://qa.fmod.com/u/brett)\
**Post date:** [August 16, 2017, 12:27am UTC](https://qa.fmod.com/t/midis-fail-to-loop-using-createstream/13362/2 "2017-08-16T00:27:49Z")

</div>

Its hard for the stream to know the length of the stream at the time of opening, so by default it will either guess or set the length to -1 (0xfffffff) which is in effect ‘infinite’ length. This is the same issue with mod/s3m/xm/it, and to some extent, VBR mp3 files.

This is why you have to ‘preprocess’ the file at the start, to work out the correct length, so it can loop properly. This is done by using the FMOD\_ACCURATETIME flag.

---

<div class="post-metadata">

**Author:** ![Spirrwell](https://avatars.discourse-cdn.com/v4/letter/s/ecd19e/32.png) [@Spirrwell](https://qa.fmod.com/u/Spirrwell)\
**Post date:** [August 16, 2017, 12:47am UTC](https://qa.fmod.com/t/midis-fail-to-loop-using-createstream/13362/3 "2017-08-16T00:47:30Z")

</div>

> [@](#):
>
> Its hard for the stream to know the length of the stream at the time of opening, so by default it will either guess or set the length to -1 (0xfffffff) which is in effect ‘infinite’ length. This is the same issue with mod/s3m/xm/it, and to some extent, VBR mp3 files.
> 
> This is why you have to ‘preprocess’ the file at the start, to work out the correct length, so it can loop properly. This is done by using the FMOD\_ACCURATETIME flag.

I tried adding the FMOD\_ACCURATETIME flag and got the same result.  
createStream( argv[1], FMOD\_LOOP\_NORMAL | FMOD\_ACCURATETIME, nullptr, &pSound )

Even if that did fix it, I feel like having consistent and expected behavior makes a little more sense.

---

<div class="post-metadata">

**Author:** ![brett](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/brett/32/261_2.png) [@brett](https://qa.fmod.com/u/brett)\
**Post date:** [August 16, 2017, 2:14am UTC](https://qa.fmod.com/t/midis-fail-to-loop-using-createstream/13362/4 "2017-08-16T02:14:39Z")

</div>

Hi, i’ve looked into this further, and you don’t need to use FMOD\_ACCURATETIME with midi files, as it can calculate the length without it (so it applies more to mod/s3m/xm/it).  
I can see an issue was introduced in 1.09.00 , which was a side effect of reducing memory overhead. Unfortunately it stops a midi file from looping, so i’ve created a fix for this for the next 1.09 release.

Workarounds are to use the latest 1.08 release instead, or use createSound instead of createStream when loading a midi file.

---

<div class="post-metadata">

**Author:** ![Spirrwell](https://avatars.discourse-cdn.com/v4/letter/s/ecd19e/32.png) [@Spirrwell](https://qa.fmod.com/u/Spirrwell)\
**Post date:** [August 16, 2017, 2:45am UTC](https://qa.fmod.com/t/midis-fail-to-loop-using-createstream/13362/5 "2017-08-16T02:45:19Z")

</div>

> [@](#):
>
> Hi, i’ve looked into this further, and you don’t need to use FMOD\_ACCURATETIME with midi files, as it can calculate the length without it (so it applies more to mod/s3m/xm/it).  
> I can see an issue was introduced in 1.09.00 , which was a side effect of reducing memory overhead. Unfortunately it stops a midi file from looping, so i’ve created a fix for this for the next 1.09 release.
> 
> Workarounds are to use the latest 1.08 release instead, or use createSound instead of createStream when loading a midi file.

Alright, thanks a lot. Guessing it was a part of that overhaul huh? I’m surprised I’ve found these issues. FMOD does work really well for almost anything.
