{{DISPLAYTITLE:_SNDBAL}}
The [[_SNDBAL]] statement attempts to set the balance or 3D position of a sound.


{{PageSyntax}}
: [[_SNDBAL]] {{Parameter|handle&amp;}}[, {{Parameter|x!}}][, {{Parameter|y!}}][, {{Parameter|z!}}][, {{Parameter|channel&amp;}}]]


{{PageParameters}}
* ''handle&amp;'' is a valid sound handle created by the [[_SNDOPEN]] function.
* {{Parameter|x!}} distance values go from left (negative) to right (positive).
* {{Parameter|y!}} distance values go from below (negative) to above (positive).
* {{Parameter|z!}} distance values go from behind (negative) to in front (positive).
* {{Parameter|channel&amp;}} value 1 denotes left (mono) and 2 denotes right (stereo) channel (beginning with '''build 20170811/60''')


{{PageDescription}}
*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 [[_SNDOPEN|"VOL"]] capability to use this statement in versions '''before build 20170811/60.'''


{{PageExamples}}
''Example 1:''
{{CodeStart}} '' ''
h&amp; = {{Cl|_SNDOPEN}}("LOL.wav", "SYNC,VOL")
{{Cl|_SNDBAL}} h&amp;, 1
{{Cl|_SNDPLAY}} h&amp; '' ''
{{CodeEnd}}


''Example:'' Loading a sound after '''build 20170811/60''' - no need to specify "sound capabilities" in [[_SNDOPEN]]. 
{{CodeStart}}
s&amp; = {{Cl|_SNDOPEN}}("song.ogg")
{{Cl|PRINT}} "{{Cl|READ}}Y"; s&amp;
{{Cl|_SNDPLAY}} s&amp;
{{Cl|_SNDLOOP}} s&amp;


xleft = -1
xright = 1
DO
    k$ = {{Cl|INKEY$}}
    {{Cl|SELECT CASE}} k$
        {{Cl|CASE}} "f"
            xleft = xleft - 0.1
            {{Cl|_SNDBAL}} s&amp;, xleft, , , 1
        {{Cl|CASE}} "g"
            xleft = xleft + 0.1
            {{Cl|_SNDBAL}} s&amp;, xleft, , , 1
        {{Cl|CASE}} "h"
            xright = xright - 0.1
            {{Cl|_SNDBAL}} s&amp;, xright, , , 2
        {{Cl|CASE}} "j"
            xright = xright + 0.1
            {{Cl|_SNDBAL}} s&amp;, xright, , , 2
        {{Cl|CASE}} "n"
            volume = volume - 0.1
            {{Cl|_SNDVOL}} s&amp;, volume
        {{Cl|CASE}} "m"
            volume = volume + 0.1
            {{Cl|_SNDVOL}} s&amp;, volume
        {{Cl|CASE}} "p"
            {{Cl|_SNDPAUSE}} s&amp;
        {{Cl|CASE}} " "
            {{Cl|_SNDPLAY}} s&amp;
        {{Cl|CASE}} "i"
            {{Cl|PRINT}} {{Cl|_SNDPLAYING}}(s&amp;)
            {{Cl|PRINT}} {{Cl|_SNDPAUSED}}(s&amp;)
            {{Cl|SLEEP}}
        {{Cl|CASE}} "b"
            {{Cl|_SNDSETPOS}} s&amp;, 110
        {{Cl|CASE}} "l"
            {{Cl|_SNDLIMIT}} s&amp;, 10
            {{Cl|PRINT}} "LIM"
            {{Cl|SLEEP}}
        {{Cl|CASE}} "k"
            {{Cl|_SNDSTOP}} s&amp;
        {{Cl|CASE}} "c"
            {{Cl|_SNDCLOSE}} s&amp;
            {{Cl|SLEEP}}
            s2&amp; = {{Cl|_SNDOPEN}}("song.ogg")
        {{Cl|CASE}} "d"
            s2&amp; = {{Cl|_SNDCOPY}}(s&amp;)
            {{Cl|_SNDPLAY}} s2&amp;
    {{Cl|END SELECT}}
    {{Cl|LOCATE}} 1, 1
    {{Cl|PRINT}} xleft, xright, volume, {{Cl|_SNDGETPOS}}(s&amp;); "   "
LOOP
{{CodeEnd}}{{small|Code by Johny B}}


{{PageSeeAlso}}
*[[_SNDOPEN]], [[_SNDVOL]], [[_SNDLIMIT]]


{{PageNavigation}}
