SoundPan sound,pan#
Parameters
|
sound - handle of a sound loaded with LoadSound pan# - stereo position from -1.0 (full left) through 0.0 (centre) to 1.0 (full right) |
Description
|
Sets the stereo position a sound will start at the next time it is played. This is a Sound command: it changes the loaded sound so that every PlaySound after it starts at that position. For a sound that should move while it plays - an enemy crossing the screen, a car going past - set the position on the channel with ChannelPan instead. The useful pattern with this command is to set the pan just before playing, so each shot of a repeated effect lands where the action is. Work the value out from screen position - something like (x-GraphicsWidth()/2.0)/(GraphicsWidth()/2.0), clamped to -1 to 1 - and a flat 2D game gets a surprising amount of space for very little effort. Panning needs a stereo output to be audible; on a mono device the value has nothing to work with. Hard-panned effects can also vanish entirely for a player wearing one headphone, so keep anything the player must hear closer to the centre. See also: ChannelPan, SoundVolume, SoundPitch, PlaySound, LoadSound. |
Example
; SoundPan Example ; ---------------- Graphics 640,480,0,2 SetBuffer BackBuffer() ; Load the sound into memory snd=LoadSound("media/beep.wav") ; Pan as a percentage: -100 = full left, 0 = centre, 100 = full right pan_pct=0 While Not KeyDown(1) ; Left/Right arrows slide the pan If KeyDown(203) And pan_pct>-100 Then pan_pct=pan_pct-2 If KeyDown(205) And pan_pct<100 Then pan_pct=pan_pct+2 ; SoundPan changes the SOUND itself, so it must be set BEFORE ; PlaySound - every later play uses it. To pan a sound that is ; already playing, use ChannelPan on its channel instead. SoundPan snd,pan_pct/100.0 ; Space plays the sound with the current pan If KeyHit(57) Then PlaySound snd Cls ; The pan slider with a moving marker Color 100,100,100 Rect 120,240,401,3 Color 80,220,255 Rect 318+pan_pct*2,228,6,27 Color 255,255,255 Text 100,270,"L" Text 320,270,"C",True Text 534,270,"R" Text 0,0,"Left/Right: set pan Space: play sound Esc: exit" Text 0,20,"SoundPan snd,pan# pan = "+pan_pct+"% (-100 left ... +100 right)" Flip Wend End
Index