Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Minor Issue with Audio
#9
(08-15-2024, 03:19 PM)justsomeguy Wrote: Thank you sir! I really appreciate you looking into it, and of course, it works now.

Using what you said, I found that this also works.

Code: (Select All)
DIM AS STRING sndFile
DIM AS LONG sndH
DIM AS DOUBLE sndL

sndFile = _OPENFILEDIALOG$("Open Sound File", "", "*.mp3|*.ogg|*.wav|*.flac", "Audio files", -1)

IF sndFile <> "" THEN
sndH = _SNDOPEN(sndFile)
IF sndH > 0 THEN
  _SNDVOL sndH, .25
  PRINT "Waiting for sound to render";
  DO
  sndL = _SNDLEN(sndH)
  PRINT ".";
  _DELAY .001
  LOOP WHILE sndL = 0
  PRINT
  _SNDPLAY sndH
  PRINT "File:"; sndFile
  PRINT "Sound Handle:"; sndH
  PRINT "Sound Length:"; sndL
END IF
END IF

This has the advantage of allowing it to "bake" and the program can do other things, and periodically check if the audio is ready.

Is this going to be normal behavior moving forward? I don't want to build a work around and have it patched out later.
No problem. You are welcome.

Well, the issue is only with the .ogg format. The asynchronous loading does not impact anything else other than .ogg. It may get patched out later but that fully depends on miniaudio and stb_vorbis. See:
Allow ma_decoder_get_length_in_pcm_frames() to work for OGG files · Issue #179 · mackron/miniaudio (github.com)
Better OGG support (and perhaps opus as well) · Issue #255 · mackron/miniaudio (github.com)

You solution has an issue. It might take a while for _SNDLEN to report the correct length if the audio is really long. In that case your loop will exit early because _DELAY .001 may be shorter than the time it takes to decode the complete audio. sndL in that case with report something shorter than the real length of the audio.

My recommendation would be to use:

Code: (Select All)
_SNDOPEN("foo.ogg", "noasync") ' to pre-render the complete audio to PCM in memory and then return < takes longer to return but is easier on the CPU during playback

Or

Code: (Select All)
_SNDOPEN("foo.ogg", "nodecode") ' to load the whole file in memory without decoding; decoding happens on-the-fly during playback < takes less time to return control but may place a tiny load on the CPU

Both workarounds will have zero impact if the program is compiled with an older version of QB64-PE. I personally would use "noasync" for short sounds like sound effects and "nodecode" for longer sounds like background music. But then, all of this only matter when using _SNDLEN and .ogg.
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)