MaKiPL / OpenVIII-monogame

Open source Final Fantasy VIII engine implementation in C# working on Windows and Linux (Android and iOS planned too!) [Monogame]
MIT License
642 stars 59 forks source link

SoundEffect LOOPSTART support broken #13

Closed Sebanisu closed 5 years ago

Sebanisu commented 5 years ago

Music will play and loop but it will not loop from marked loop point. MonoGame issue 5186 MonoGame pull 6607 Looks like this user has an open pull request for a fix. I had trouble finding his code to test. So if his change gets approved this issue should go away.

I might be able to do a correct loop in naudio for windows only. I was reading about it someone using a custom class to wrap around the wavestream or something like that.

Sebanisu commented 5 years ago

I got woke up this morning instead of going back to bed I fixed this. It's on my fork right now. I plan on doing a pull request once I get the linux working.

I worked around this issue by swapping from Naudio to Ffmpeg. It works. I feed the audio to a DynamicSoundEffectInstance. A timer runs in the background and when it gets close to running out of audio it runs the GetFrame() function again. This time getting the next bit of audio but starting from LOOPSTART and changing the duration to total-loopstart. It works when the timebase = 1/sample_rate. If we run into files where this isn't the case it won't work and will have to tweak the code. Also if a file is long enough that duration > int32.maxvalue than could also have issues. As duration is stored in a int64 and we are running on 32bit.