MIDIs Fail to Loop Using createStream()

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

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

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.

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.

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.

2 Likes

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.