SNDOPEN-v0.954: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{DISPLAYTITLE:_SNDOPEN-v0.954}}
{{DISPLAYTITLE:_SNDOPEN-v0.954}}
'''{{Text|Attention!! - This page is outdated and provided for reference only. Follow the link in the line below to get the current page.|red}}'''
----
----
<center>'''{{Text|Attention!! - This page is outdated and provided for reference and/or education only.|red}}'''</center>
<center>([[Historic Pages|Return to historic Table of Contents]])</center>
----
----<br>


The [[_SNDOPEN]] function loads a sound file into memory and returns a valid [[LONG]] handle value when it is not zero.
The [[_SNDOPEN]] function loads a sound file into memory and returns a valid [[LONG]] handle value when it is not zero.
Line 66: Line 71:
{{Cl|_SNDPLAY}} Laff&                    'play sound
{{Cl|_SNDPLAY}} Laff&                    'play sound
{{CodeEnd}}
{{CodeEnd}}




Line 76: Line 80:
* [[_SNDCOPY]], [[_SNDPLAYCOPY]]
* [[_SNDCOPY]], [[_SNDPLAYCOPY]]
* [[_SNDBAL]], [[_SNDLEN]], [[_SNDVOL]]
* [[_SNDBAL]], [[_SNDLEN]], [[_SNDVOL]]
* [[_SNDPLAYFILE]] {{text|(plays a named sound file directly and closes)}}
* [[_SNDPLAYFILE]]
* [[_SNDRAW]], [[_SNDRATE]], [[_SNDRAWLEN]] {{text|{raw sounds without files)}}
* [[_SNDRAW]], [[_SNDRATE]], [[_SNDRAWLEN]]




{{PageNavigation}}
{{PageNavigation}}
[[Category:Historic]]

Latest revision as of 10:15, 24 September 2023



Attention!! - This page is outdated and provided for reference and/or education only.
(Return to historic Table of Contents)



The _SNDOPEN function loads a sound file into memory and returns a valid LONG handle value when it is not zero.


Syntax

sound_handle& = _SNDOPEN (filename$[, "[VOL][,][SYNC][,][LEN][,][PAUSE][,][SETPOS]"])


Description

  • Sound file support for: WAV, OGG, AIFF, RIFF, VOC, MP3, MOD, MIDI
  • Capabilities of VOL, LEN, SYNC, SETPOS and PAUSE is a string of parameters separated by commas. It is NOT case sensitive.
  • The value returned by _SNDOPEN is a handle to the sound or 0. A zero return means the sound could NOT be loaded. ALWAYS check the handle value returned before attempting to play them!
  • The handle can be used by most of the SND sound playing Functions and Subs in QB64 except _SNDPLAYFILE which plays a sound file name directly and does not use a handle value.
  • Handles can be closed with _SNDCLOSE when the sound is no longer necessary.
  • An ILLEGAL FUNCTION CALL error message means the capabilities$ string was invalid or two NON-SYNC sounds are using the same channel!


Sound File Capabilities
  • Each capability can only be specified once and must be valid for that file or it won't play. Capabilities can be listed in any order.
    QB64 supports the following sound file formats (Bold is a guaranteed capability):

             WAV = "VOL,SYNC,LEN,PAUSE"      Free WAV to OGG GUI converter
             OGG = "VOL,SYNC,LEN,PAUSE"      Free WAV to OGG converter
             AIF = "VOL,SYNC,LEN,PAUSE"
             RIF = "VOL,SYNC,LEN,PAUSE"
             VOC = "VOL,SYNC,LEN,PAUSE"
             MID = "VOL"
             MOD = "VOL,PAUSE"
             MP3 = "VOL,PAUSE,SETPOS"        Free WMA, MP3 and OGG converter

        Note: _SNDBAL only affects MP3 volume. Sound will reside in main channel.
  • The required sound file capabilities can make a difference as to whether a sound file can be played or not and how it can be used.
Only one sound can exist on the primary channel, and it must be closed before playing another non-SYNC sound.
See _SNDCOPY and _SNDPLAYCOPY
                                  Capability Descriptions

   "VOL" can change the volume or balance of the sound using _SNDVOL and _SNDBAL.
   "LEN" can get the length of the sound using the _SNDLEN function.
   "PAUSE" can pause the sound using _SNDPAUSE and the _SNDPAUSED function can check it.
   "SETPOS" can change the position the sound is (or will be) playing from. See _SNDSETPOS.
   "SYNC" can load the sound onto a unique channel, to be played simultaneously with others.

        When SYNC is not specified, the sound is loaded onto the primary channel.


Snippet 1: Loading a sound file to use in the program later. Only load it ONCE and use the handle any time you want!

h& = _SNDOPEN("dog.wav","sync,vol")       'only use the capabilities of that file type
IF h& = 0 THEN BEEP ELSE _SNDPLAY h&      'check for valid handle before using!


Snippet 2: Playing a sound from 2 different speakers based on program results. Must use SYNC!

Laff& = _SNDOPEN("KONGlaff.ogg", "SYNC,VOL") 'load sound file and get LONG handle value
IF LaffX! < -1 THEN LaffX! = -1   'set full volume to left speaker
IF LaffX! > 1 THEN LaffX! = 1     'set full volume to right speaker

_SNDBAL Laff&, LaffX!             'balance sound to left or right speaker
_SNDPLAY Laff&                    'play sound


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link