Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Minor Issue with Audio
#4
@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.

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.
Reply


Messages In This Thread
Minor Issue with Audio - by justsomeguy - 08-11-2024, 05:46 PM
RE: Minor Issue with Audio - by bplus - 08-11-2024, 09:14 PM
RE: Minor Issue with Audio - by a740g - 08-12-2024, 04:17 AM
RE: Minor Issue with Audio - by a740g - 08-14-2024, 04:48 PM
RE: Minor Issue with Audio - by justsomeguy - 08-15-2024, 03:19 PM
RE: Minor Issue with Audio - by a740g - 08-15-2024, 08:02 PM
RE: Minor Issue with Audio - by NakedApe - 08-15-2024, 06:15 PM
RE: Minor Issue with Audio - by justsomeguy - 08-15-2024, 06:28 PM
RE: Minor Issue with Audio - by NakedApe - 08-15-2024, 06:40 PM



Users browsing this thread: 4 Guest(s)