3D Sound

BlitzMax Forums/MiniB3D Module/3D Sound

FreetimeCoder(Posted 2009) [#1]
Hi,

I want to implement 3D sound like in Blitz3D into my game, but there is one problem: simonh MiniB3d has no 3D sound. Then I discovered the sound module in klepto's Minib3d ext. Tried to implement it but it does not play 3d sound, just mono sound and I have no way to set the soundrange or a dopplereffect.

Then I found this topic.

The Module itself seems to be exactly what I need. But: I copied the code, compiled it and used the module in my Code -> no sound at all.
Local emitter:TEntity = CreateSphere()
Init3DSound(Camera, 1, - 1)
Local onesound:TSound = LoadSound("Data/SFX/mysound.ogg")
Start3DSound(onesound, emitter, 1, 1)

[...]

Update3DSounds()


So I tried to download the new version (at the end of the topic there is a link) but the whole page seems dead.

Is there someone who succesfuly implemented 3D sound, yet? who can help me?

greetings


ima747(Posted 2009) [#2]
http://toscaledesign.com/minib3d/minib3dSoundv1.2.zip

my old server died and I forgot where the links came from, hope that helps.

It's much easier to implement it as a module, but with a bit of poking you can probably make it includable if you prefer.

It works with the blitz max sound system, not an external library, so if you can't get sounds playing try playing some old fashioned 2d sounds in blitz and if that doesn't work it's probably your sound card. If the 2d stuff works but you can't get the 3d working make sure your distances and ranges are set and make sense.

good luck.


FreetimeCoder(Posted 2009) [#3]
So I guess it was the old version that made the problems. The samples included in your new version are working perfectly!
Big Thanks man, made my day :D

greetings


FreetimeCoder(Posted 2009) [#4]
Hm very often at Start3DSound(mysound, myEntity) I get this error:
Unhandled Exception:Unhandled Memory Exception Error

It does not matter, how many sounds I use, how long the sound is or how loud the sound plays. :? any Clues on solving this? Sometimes it works but more often it crashes.

greetings


ima747(Posted 2009) [#5]
can you post a sample? are you sure myEntity hasn't been freed? have you called the Init3DSound() function with a listener prior to trying to start playback?


FreetimeCoder(Posted 2009) [#6]
SuperStrict

Import sidesign.minib3d
Import ima.minib3dsound

Global mySound:TSound = LoadSound("../Data/SFX/sound.ogg", SOUND_LOOP)

Type myObject
	Field myMesh:TEntity = CreateSphere()
	Function init:myObject(X:Int, Y:Int, Z:Int)
		Local tmp:myObject = New myObject
		tmp.myMesh.PositionEntity(X, Y, Z)
		Start3DSound(mySound, tmp.myMesh, 0.5, 1)
		Return tmp
	End Function
End Type

Graphics3D(640, 480, 0, 2)

Local camera:TCamera = CreateCamera()
Init3DSound(Camera, 100)

Local Objectlist:TList = CreateList()
For Local i:Int = 0 To 20
	Objectlist.AddLast(myObject.init(Rnd(- 100, 100), Rnd(- 10, 10), Rnd(- 100, 100)))
Next

While Not KeyHit(KEY_ESCAPE)
	Cls
	Camera.TurnEntity(0, KeyDown(KEY_LEFT) - KeyDown(KEY_RIGHT), 0)
	Camera.MoveEntity(0, 0, KeyDown(KEY_UP) - KeyDown(KEY_DOWN))
	Update3DSounds()
	UpdateWorld()
	RenderWorld()
	Flip()
Wend
ClearWorld()
End


However, when starting the Sounds after all Objects are added to the list, there is no error.

greetings


ima747(Posted 2009) [#7]
Interesting, I'm a little rusty at blitz at the moment but that looks like it should work. my assumption on why it doesn't is there's something getting juggled regarding the pointer of the mesh when the list is modified.

I don't have blitz installed on the computer I'm on, but here's a couple things you could try

see if breaking the create out of the list add makes any difference i.e.
For Local i:Int = 0 To 20
	Local tempObject:myObject = new myObject.init(Rnd(- 100, 100), Rnd(- 10, 10), Rnd(- 100, 100));
	Objectlist.AddLast(tempObject)
Next


if that doesn't work then start it playing after the list add (remove the play from the init)
For Local i:Int = 0 To 20
	Local tempObject:myObject = new myObject.init(Rnd(- 100, 100), Rnd(- 10, 10), Rnd(- 100, 100));
	Objectlist.AddLast(tempObject)
	Start3DSound(mySound, tempObject.myMesh, 0.5, 1)
Next


if that doesn't work then add a start sound loop after the create loop that starts everything, in the end you're likely to be doing this anyway if you're creating a bunch of objects at once since the sounds would start to play before anything started happening on screen.

You could also look into Que3DSound and EntityResume3DSound as that should allow you to prep the sounds when you make the objects and then start them playing later (i.e. after all the objects have been made so the sound is in sync with the screen)


FreetimeCoder(Posted 2009) [#8]
Yeah that worked. Thanks