forked from QB64-Phoenix-Edition/QB64pe
-
Notifications
You must be signed in to change notification settings - Fork 0
CHR$
github-actions[bot] edited this page Jun 16, 2022
·
7 revisions
The _SNDBAL statement attempts to set the balance or 3D position of a sound.
- _SNDBAL [,][,][,][,]]
- handle& is a valid sound handle created by the _SNDOPEN function.
- distance values go from left (negative) to right (positive).
- distance values go from below (negative) to above (positive).
- distance values go from behind (negative) to in front (positive).
- value 1 denotes left (mono) and 2 denotes right (stereo) channel (beginning with build 20170811/60)
- Attempts to position a sound in 3D space, or as close to it as the underlying software libraries allow. In some cases, this will be true 3D positioning, in others, a mere volume adjustment based on distance alone.
- Omitted x!, y! or z! SINGLE values are set to 0 or not changed in build 20170811/60 onward.
- By setting the x! value to -1 or 1 it plays the sound at full volume from the appropriate speaker.
- Sounds at a distance of 1 or -1 are played at full volume. Sounds further than a distance of 1000 cannot be heard.
- The volume decreases linearly (at a constant gradient) over distance. Half volume = 500.
- An "Illegal Function Call" error can occur if another sound is using the primary or same channel position.
- Opened sound files must have the "VOL" capability to use this statement in versions before build 20170811/60.
Example: Loading a sound after build 20170811/60 - no need to specify "sound capabilities" in _SNDOPEN.
s& = ("song.ogg") "Y"; s& s& s&
xleft = -1 xright = 1 DO
k$ = {{Cl|INKEY$}}
{{Cl|SELECT CASE}} k$
{{Cl|CASE}} "f"
xleft = xleft - 0.1
{{Cl|_SNDBAL}} s&, xleft, , , 1
{{Cl|CASE}} "g"
xleft = xleft + 0.1
{{Cl|_SNDBAL}} s&, xleft, , , 1
{{Cl|CASE}} "h"
xright = xright - 0.1
{{Cl|_SNDBAL}} s&, xright, , , 2
{{Cl|CASE}} "j"
xright = xright + 0.1
{{Cl|_SNDBAL}} s&, xright, , , 2
{{Cl|CASE}} "n"
volume = volume - 0.1
{{Cl|_SNDVOL}} s&, volume
{{Cl|CASE}} "m"
volume = volume + 0.1
{{Cl|_SNDVOL}} s&, volume
{{Cl|CASE}} "p"
{{Cl|_SNDPAUSE}} s&
{{Cl|CASE}} " "
{{Cl|_SNDPLAY}} s&
{{Cl|CASE}} "i"
{{Cl|PRINT}} {{Cl|_SNDPLAYING}}(s&)
{{Cl|PRINT}} {{Cl|_SNDPAUSED}}(s&)
{{Cl|SLEEP}}
{{Cl|CASE}} "b"
{{Cl|_SNDSETPOS}} s&, 110
{{Cl|CASE}} "l"
{{Cl|_SNDLIMIT}} s&, 10
{{Cl|PRINT}} "LIM"
{{Cl|SLEEP}}
{{Cl|CASE}} "k"
{{Cl|_SNDSTOP}} s&
{{Cl|CASE}} "c"
{{Cl|_SNDCLOSE}} s&
{{Cl|SLEEP}}
s2& = {{Cl|_SNDOPEN}}("song.ogg")
{{Cl|CASE}} "d"
s2& = {{Cl|_SNDCOPY}}(s&)
{{Cl|_SNDPLAY}} s2&
{{Cl|END SELECT}}
{{Cl|LOCATE}} 1, 1
{{Cl|PRINT}} xleft, xright, volume, {{Cl|_SNDGETPOS}}(s&); " "
LOOP