QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: Richard Frost on October 07, 2020, 11:10:08 pm

Title: Sounds
Post by: Richard Frost on October 07, 2020, 11:10:08 pm
What ways are there to play sounds with QB64? Ones I know of are:
1) SOUND
2) PLAY
3) WAV player someone posted here
4) MessageBeep library

With methods 1 and 3 there's an annoying "click" as the sound begins
and when it ends. Pleasant sounds don't seem possible with 1 or 2.
4 sounds nicest and there's no "click", but has a very limited selection.

I get all sorts of NICE short sounds when browsing with Chrome, with
no annoying "click".  How is it done?
Title: Re: Sounds
Post by: Dav on October 08, 2020, 10:55:34 am
The built-in sound playing capabilities of QB64 are pretty good, with which you can play mp3/ogg/wav sounds easily.  Here's the wiki page of _SNDOPEN that shows how to play sounds:  https://www.qb64.org/wiki/SNDOPEN (https://www.qb64.org/wiki/SNDOPEN).

- Dav
Title: Re: Sounds
Post by: Richard Frost on October 08, 2020, 02:49:55 pm
Yep, that's the way.  Variety with no clicking.

Thanks!
Title: Re: Sounds
Post by: Cobalt on October 08, 2020, 02:58:51 pm
Just a side note, if your doing loop-able sounds like Back Ground Music(BGM) you'll want to probably use OGG, as for some reason a lot of MP3 encoders add silence to the file, this also makes it better to use OGG for repeating Sound Effects (SFX) again because of the silence addition. of course if you have a MP3 encoder that doesn't add that I think you can get smaller file sizes with better quality in MP3 but thats just some things I have noted here recently when adding sounds to games.
Title: Re: Sounds
Post by: Richard Frost on October 09, 2020, 12:19:56 am
I finally remembered that the WAV player I tried used _SNDPLAY. 
Something about how it was implemented, or how I modified it,
led to a click at the beginning and end of sound.  I get no
such click now. 

Re using sound files in a program, is it better to load them
all during initialization and keep them open, or load/use/close?
Although there are 10 files involved, they're all small (20K)
except one (1M).  It's for my chess program, so some of them
are used rather often.  Even if the total was 2 megs, that's
peanuts for modern computers, right?
Title: Re: Sounds
Post by: Cobalt on October 09, 2020, 09:54:27 pm
I would say load everything at startup. Less to worry about later.
Title: Re: Sounds
Post by: FellippeHeitor on October 10, 2020, 05:21:39 pm
I usually load everything at startup too.