Author Topic: 32-bit sound - Hit & Miss  (Read 323 times)

bluejaywpg

  • Newbie
  • *
  • Posts: 2
32-bit sound - Hit & Miss
« on: February 11, 2017, 07:27:11 am »
I started using QB64 over 3 months ago & I ported an old QBasic app over which now has over 350 WAV files.  Previously I used an external WAV file app to play sounds but since QB64 supports playing audio files natively, I updated the app to use the QB64 sound commands instead.  What I've noticed is that some sounds don't play at all (there are no error messages), others play just fine.  And others play fine but when using the _SNDLEN function to make the app stop & delay for the length of the file (plus an extra 0.2 seconds), the timing is not 100% accurate - the delay stops just a split second before the sound file actually finishes.

Handle& = _SNDOPEN(PlayFile$, "SYNC,LEN")
_SNDPLAYCOPY Handle&
_DELAY _SNDLEN(Handle&) + .2
_SNDCLOSE Handle&

As far as I can tell, the issue may be limited to 32-bit WAV files.  When I changed 1 WAV file to 16-bit, it played fine. Previously the file (over 12 seconds long) wouldn't play at all unless I split it into 2 halves.  Tried other formats like MP3 & OGG but that didn't help either - results were mixed - but it may have had something to do with my unfamiliarity with the sound commands for QB64 at the time.  Timing seems better but I need to test this further - I probably have a few other 32-bit files still mixed in with the rest @ lower bit rates.  I haven't tested 24-bit files yet.

I use QB64 1.1, Windows 10, been using Audacity to edit & save WAV files.

Petr

  • Sr. Member
  • ****
  • Posts: 299
Re: 32-bit sound - Hit & Miss
« Reply #1 on: February 11, 2017, 11:03:11 am »
Hi. For long wave use _SNDPLAY. Its better to use this command. Its possible in the same time using _SNDPLAYFILE - but not for long files. I tried to play WAV files with a length of 66 minutes without any problems at a time. The problem is the solution. WAV whole is introduced into ram and then the application needed over one giga memory. I confirm that:
- _SNDBAL Not working as it should even with all types of WAV files even when using DOUBLE values (but with other type too not),
- MP3 play all NOT correctly, at low bitrate playback finishes prematurely - but only sometimes and I could not figure why.
This commands _SND... never making errors. All about this is in help (Shift + F1).
- SNDVOL is ok, no problem. I use  W7, QB64 1.1. Here is my first source code for sound play:

Code: [Select]
DO WHILE x < 5
    IF _SNDPLAYING(oldzvuk&) = 0 THEN
        READ hledat$
        hraj hledat$
        x = x + 1
    END IF

    'LOCATE 8, 1: PRINT x, stav
LOOP


END

DATA brzdy.mp3,odraz.mp3,srazka.mp3,t1.mp3,m16.mp3  'here insert your MP3s or OGGs.... - 5 files





SUB hraj (plaj AS STRING)
    SHARED oldzvuk&
    IF _SNDPLAYING(oldzvuk&) = -1 THEN PRINT "Sorry, now playing": EXIT SUB
    IF _SNDPLAYING(oldzvuk&) = 0 THEN _SNDCLOSE oldzvuk&: zvuk& = _SNDOPEN(plaj$, "VOL"): oldzvuk& = zvuk&
    IF zvuk& > 0 THEN PRINT "File ready" ELSE PRINT "File not ready - "; plaj$
    _SNDPLAY zvuk&

END SUB




Coding is relax.

Petr

  • Sr. Member
  • ****
  • Posts: 299
Re: 32-bit sound - Hit & Miss
« Reply #2 on: February 11, 2017, 11:09:34 am »
And muche one: If you use your code as is, then first muss be line with _Delay, and THEN line with _SNDPLAYCOPY
Coding is relax.

bluejaywpg

  • Newbie
  • *
  • Posts: 2
Re: 32-bit sound - Hit & Miss
« Reply #3 on: February 11, 2017, 12:37:01 pm »
I used _SNDPLAYCOPY over _SNDPLAY & _SNDPLAYFILE because it seemed like that method was working the best.  It's possible that because some sounds worked & others didn't (some inconsistently) not to mention the fact that I was still learning how to use these commands properly, it may make no difference whatsoever which method I use.  I'm pretty confident that the 32-bit rate is the issue at this point, & I don't think very many are 32-bit so converting them to a lower bitrate isn't a big deal but it would be nice to not have to convert.  But I will keep that in mind - thanks Petr.

All of my WAV files are less than 65 seconds long - the vast majority that get played range from less than a second to about 23 seconds.  I continue to use WAV because it seems to have the most flexibility & I thought I remembered reading somewhere that MP3s are not fully supported(?) beyond simple playback.

Why would I use _DELAY before _SNDPLAYCOPY?  That means there will be a delay for the length of the WAV file, then the WAV file will play & the app will continue executing after that, no?  I want the app to wait until the sound has finished playing when executing this subroutine.

Petr

  • Sr. Member
  • ****
  • Posts: 299
Re: 32-bit sound - Hit & Miss
« Reply #4 on: February 12, 2017, 02:22:40 am »
Yes, I wait until it plays the sound I used _SNDPLAYING (returns -1 when playing or 0 if he does not play) If you want to do this effect where the sound interrupt and then let go from the same spot until the end, we can do it using _SNDPAUSE if you use _SNDSTOP, begins playing from the beginning.
Coding is relax.