Creating 1 listener?

Blitz3D Forums/Blitz3D Beginners Area/Creating 1 listener?

Chad(Posted 2005) [#1]
Is it true you can only create one, uno, 1 listener?? So if I want more than 1 background sound am I going have to mix the sounds in a 3rd party program for it to work?

Please correct me if I'm wrong,
Chad


jhocking(Posted 2005) [#2]
I think you are confused on what a listener is. A listener is the point in space where your sounds are being heard from. You can have multiple sounds emanating from multiple places, but they are all going to be heard in one place (kinda sensible, yes?)


jfk EO-11110(Posted 2005) [#3]
well if you could use two headphones (with diffrent sound) on one computer, it would make sense to have more than one listener. But since you have only one headphone plug, it makes sense to have only one virtual listener in virtual 3D space. Of course you may apply the listener to various locations/objects, so if the FPS Player is beamed by Scotty, the listener will be beamed too.

The only problem I see is: the falloff parameters etc. are declared with the listener. I'd rather like to see them as parameters for the 3D Sounds instead. But that's just the way it is (I think it's a DirectX thing).


Chad(Posted 2005) [#4]
Another question about this, is there a way to make an entity produce a sound. Also, what can I do so that when you press a button, say 1 for example, that a sound is played from another entity? I was looking at some examples so have examples, just need directions HOW to do it..

Thanks,
Chad


WolRon(Posted 2005) [#5]
If KeyHit(2)
  EmitSound entity, sound
EndIf
Any more questions?


Chad(Posted 2005) [#6]
Just one, I don't get what the entity is, I know it ties it to an object, but if I'm loading a sound what do I assign it too? For reference here's the sound code I have.

Load3dSound moo=("moo.wav")
If KeyHit(2)
 Emit Sound whatever, moo
EndIf


I just don't know what to assign the entity too, and that's why the sound isn't loading is my guess.

Also, don't know if it matters, but it's before End, and Repeat, and all that good stuff.

Thanks for your help,
Chad


Shambler(Posted 2005) [#7]
In your example 'whatever' has to be an entity.

An entity in Blitz3D is a mesh, so it could be a simple cube or a sphere or more practically it could be an enemy in your game or the players weapon.It could be a door, so when the door opens/closes you could emit an opening/closing sound and it would appear to be coming from the door.

When you load a sound in your example you are assigning it to 'moo' which is fine, that is where the sound is stored.

When you want the sound to play you emit it from a 3d entity in your game world and it will sound depending on how far away this entity is from the listener and in what direction.

Typically when you 'createlistener' you specify the camera as the parent, this means that the listener will move around with the camera which is usually what you want.

[Edit] in your example is should be
Emit Sound moo,whatever

Please download this small demo I made for you it should make things clearer, media included.

http://mysite.wanadoo-members.co.uk/shambler/emitsound.zip


_PJ_(Posted 2005) [#8]
The example in the docs is very simple and shows the 3Dsound commands well...

http://www.blitzbasic.com/b3ddocs/command.php?name=EmitSound&ref=3d_cat


Chad(Posted 2005) [#9]
Thanks for the little demo Shambler, I really appreciate it, and it's pretty cool too.

The problem is not a listener anymore, but just getting the sound to play when I press a button..

I've toyed with it but just can't get it, and it's very frustrating..

Also thanks Malice for the link, I appreciate everything you guys are doin for me :-)

moo=Load3DSound("moo.wav")
If KeyHit(2) 
EmitSound moo,cube
EndIf

no sound and have cube within range :(

Thanks again,
Chad


octothorpe(Posted 2005) [#10]
Remove code until you have the simplest possible program which demonstrates your problem. Post that. We'll be able to verify your problem and find a solution.

Hint: you can likely demonstrate this problem in less than 15 lines.


Chad(Posted 2005) [#11]
Octothorpe,
I did what you said to do and it worked.. Now trying in regular program..

Result:
Just as I suspected, I had to create another listener, but I already had the main listener that I cannot get rid of, well, maybe I can try, trying a new idea..

Result 2:
Didn't work, I need a listener for that sound too :-\
Basically this is what I've got..

wind=CreateListener(player,.00001,10,5)
wind_snd=LoadSound("wind.wav")
LoopSound wind_snd
EmitSound(wind_snd,watermesh)

microphone=CreateListener(player)
moo=Load3DSound("moo.wav")

If KeyHit(2) 
  EmitSound moo,cube
  EndIf

EmitSound water, water



jhocking(Posted 2005) [#12]
Why do you use the command CreateListener twice? Didn't we already go over how you can only have one listener?

At any rate, the very last line is fishy. You have the variable 'water' twice, but they should be different; one should be the sound, and one should be the entity. Morover, I'm curious how these lines are arranged with respect the resot of your code. All the setup stuff (ie. everything before If) should be called once at the beginning of your program, while that If statement should be in your main loop and thus called every frame.


Chad(Posted 2005) [#13]
Here's the entire code minus a couple of mesh's and other sorts of stuff I have along in the program. All mesh's are there, I just chose to disclude them in this example..

Also, everything I have here is in order in compliance with the program..

Graphics3D 1024, 768, 0, 1
SetBuffer BackBuffer()

;====================Sounds
wind=CreateListener(player,.00001,10,5)
wind_snd=LoadSound("wind.wav")
LoopSound wind_snd
EmitSound(wind_snd,watermesh)

microphone=CreateListener(player)
moo=Load3DSound("moo.wav")

player = CreatePivot()
camera = CreateCamera(player)

MoveEntity camera, 0, 4.9, 0
MoveEntity player, 20, 15, -20	

While Not KeyHit(1) 
If KeyHit(2) 
EmitSound moo,cube
EndIf

TranslateEntity player, 0, -.1, 0

UpdateWater()
UpdateWorld

RenderWorld
Flip
Wend
End

EmitSound water, water    ;dont ask it works, assigned to mesh not included..



octothorpe(Posted 2005) [#14]
where is the entity variable "cube" defined?


Chad(Posted 2005) [#15]
[code]
cube=CreateCube()
PositionEntity cube,0,1,0

microphone=CreateListener(player)
moo=Load3DSound("moo.wav")
[/cube]

right there.. sorry about that..

It works if I (;) out the other listener with the wind listener, but if I un (;) the other one, then it says multiple listeners, and I dont know a way around this.


jfk EO-11110(Posted 2005) [#16]
why don't you name your listener "EARS" so there won't be any misunderstanding.

Now, I guess you only have ONE pair of ears, do you? (Well unless you're living near Mr. Burns power plant or something)

With only one pair of ears (= one listener!) you can hear the wind and the cow too!


Jams(Posted 2005) [#17]
There are several problems in your code, firstly win_snd is not being loaded with Load3DSound, but just a regular LoadSound, which could cause problems with EmitSound. Secondly ofcourse you have multiple listeners, you only need one. Thirdly, you're setting your listener as a child of an entity that hasnt been created yet, Player = CreatePivot() should be called *before* microphone=CreateListener( player ), otherwise microphone is going to be a child of nothing.


Shambler(Posted 2005) [#18]
Also if you want an ambient wind background noise that is heard at equal volume anywhere in the level then just use LoadSound and Playsound, no need to load as a 3d sound and emit it from anything.


_PJ_(Posted 2005) [#19]



Try this!

And also, remember your 'player' object is gonna fall apst the cow and water VERY quickly (unless this is a grvity thing and he's kept firmly on the ground)


Chad(Posted 2005) [#20]
Got it working with Malice's example!

Many thanks to all of you for this simple, yet complex problem!


_PJ_(Posted 2005) [#21]
Glad to be able to help! :)


Rob Farley(Posted 2005) [#22]
I created this a while ago to help me play with the settings of a listener... it might help... you're going to need a sound for it though!