08-14-2024, 04:48 PM
@justsomeguy QB64-PE v3.14.0 loads and decodes the audio files asynchronously on another thread after a call to _SNDOPEN. This means _SNDOPEN does not block the caller for extended period of time and almost instantaneously returns control. Not doing this would be problematic especially for large files and files that needs to render samples using some kind of instructions like MIDI, MOD etc. We had folks complain about the long load times in the past.
To work around your issue, just use the "noasync" flag with _SNDOPEN. This flag will force QB64-PE to completely render the audio in memory and then return control.
See https://qb64phoenix.com/qb64wiki/index.php/SNDOPEN for more fun stuff.
Now, a question may arise - why the hell does MP3 and formats report the correct length even when "noasync" is not used? Well, the answer to that questions is in the way miniaudio internally uses stb_vorbis unfortunately. It's the same reason why _MEMSOUND never works with Ogg Vorbis sounds. Fortunately though, the issue is limited to just Ogg Vorbis and does not impact other formats supported by _SNDOPEN.
Hope this helps.
To work around your issue, just use the "noasync" flag with _SNDOPEN. This flag will force QB64-PE to completely render the audio in memory and then return control.
Code: (Select All)
_DEFINE A-Z AS LONG
OPTION _EXPLICIT
DIM sndFile AS STRING: sndFile = _OPENFILEDIALOG$("Open Sound File", , "*.mp3|*.ogg|*.wav|*.flac", "Audio files")
IF LEN(sndFile) THEN
DIM sndH AS LONG: sndH = _SNDOPEN(sndFile, "noasync")
IF sndH > 0 THEN
DIM sndL AS DOUBLE: sndL = _SNDLEN(sndH)
_SNDVOL sndH, .25
_SNDPLAY sndH
PRINT "File:"; sndFile
PRINT "Sound Handle:"; sndH
PRINT "Sound Length:"; sndL
END IF
END IF
See https://qb64phoenix.com/qb64wiki/index.php/SNDOPEN for more fun stuff.
Now, a question may arise - why the hell does MP3 and formats report the correct length even when "noasync" is not used? Well, the answer to that questions is in the way miniaudio internally uses stb_vorbis unfortunately. It's the same reason why _MEMSOUND never works with Ogg Vorbis sounds. Fortunately though, the issue is limited to just Ogg Vorbis and does not impact other formats supported by _SNDOPEN.
Hope this helps.