Problem with PlaySound...

Blitz3D Forums/Blitz3D Programming/Problem with PlaySound...

Ok, this is strange. I assumed that when using playsound, it would NOT be a 3D sound. However, when I play my music using this command, or even playmusic, the result can be heard properly while my player is at 0,0,0, but quickly fades out as he moves away from that point.

I do use 3D sounds for in-game effects, obviously, and have a listener attached to the camera, but I really need to be able to use 2D sounds as well, which are the same regardless of player location.

Anyone know what's going wrong here?

Why not just create a music channel and assign the sound to that?

Stevie

I've tried it two ways:

Global Music = LoadSound("music.ogg")
LoopSound(Music)
PlaySound(Music)

Global Music = PlayMusic("music.ogg")

Both ways it acts like it's actually a 3D sound at position 0,0,0.

I did however try loading it as a 3D sound, setting it to loop, and emitting it from the cam (same as listener), and it seems to work properly.

Is this the only way it can be done?

Does this work?

global MUSIC = loadsound("music.ogg")
Loopsound( MUSIC )
global MUSICchannel = playsound( MUSIC )

Same result...I suppose I'll have to use it as a 3D sound emitted from the cam...though thanks for reminding me about the channel thing. I'll need to use that anyway so I can control the playback.

try this test, it shows all scene objects/entitys moving away from 0,0,0 won't affect playsound volume.
you'll need to load a valid sound file.

;PlaySound 3D test

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

cam=CreateCamera() ;init scene
lit=CreateLight()
box=CreateCube()
PositionEntity box,0,0,5

hsnd=LoadSound("yourname.wav") ;load sound
LoopSound hsnd ;set sound to loop
sndchn=PlaySound(hsnd) ;play the sound channel

While Not KeyHit(1)

 z=z+1
 PositionEntity cam,0,0,-z ;move cam away from 0,0,0
 PositionEntity box,0,0,z ;move box away in other dir
 PositionEntity lit,z,0,0 ;move lit away on other axis
 TurnEntity box,0.4,0.3,0.2 ;spin box

 RenderWorld

 Text 0,0,"camX="+EntityX(cam)+" camY="+EntityY(cam)+" camZ="+EntityZ(cam)
 Text 0,12,"boxX="+EntityX(box)+" boxY="+EntityY(box)+" boxZ="+EntityZ(box)
 Text 0,24,"litX="+EntityX(lit)+" litY="+EntityY(lit)+" litZ="+EntityZ(lit)

 Flip
Wend


Ok, that helped me figure it out. If I add a listener in there it DOES act as a 3D sound positioned at 0,0,0, even if it's not loaded as one. So apparently if you use a listener for 3D audio (which in my game is obviously important), every audio file will be treated that way.