Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Free alternative to 3D sounds...Can anyone test this out a little more extensively ?

Author
Message
Baggers
19
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 27th Feb 2006 21:15 Edited at: 28th Feb 2006 11:24
Hey folks...was messing around with 3D sounds for my game the other day and I got a little fustrated that the sounds had to be all converted to mono, and I wasn't really sure how volume equated to the range of the sound.

This for some reason was enough to trigger my brain into making my own system...and here it is.



And here are the commands

Gosub SetupBagSound: This sets up the vectors and arrays used by the system.

`========`
`Listener`
`========`
PositionBagListener(X#,Y#,Z#): Positions your 'ears' in the game.

PositionBagListenerToCam(): Positions your "ears" at the position of the camera.

SetBagListenerDirection(X#,Y#,Z#):Sets the direction your listener is facing in the game.

SetBagListenerDirectionToCam():points your listener in the direction the camera is facing.

`====================`
`Load & Delete Sounds`
`====================`
LoadBagSound(File$,Number): Loads your sound. You specify the filename and number as usual.

DeleteBagSound(Number): Deletes the specified sound

`=====`
`Range`
`=====`
SetBagSoundRange(Number,Range#): Sets the total range of the sound. By this distance the sound will be totaly in-audible

GetBagSoundRange(Number): Returns the range of the sound

SetBagSoundDropOffStart(Numb,Start#): Now this is new to you. This is the distance from the sounds origin that the sound will start fading, being inaudible by the range value (see above)

GetBagSoundDropOffStart(Numb): Gets the Drop off range#

`===========`
`Positioning`
`===========`
PositionBagSound(Number,X#,Y#,Z#): Positions the sound in 3D space

BagSoundPositionX(number): Gets the X position of the sound
BagSoundPositionY(number): Gets the Y position of the sound
BagSoundPositionZ(number): Gets the Z position of the sound

`=========`
`Direction`
`=========`
SetBagSoundDirection(number,x#,y#,z#): Sets the direction of the sound. X#, Y# & Z# specify the componants of a vector.

SetBagSoundDirectionFromVector(number,vectornum): Sets the direction of the sound to the contents of the specified vector

BagSoundDirectiontoVector(numb,vecnum): Puts the direction of the sound into the specified vector

BagSoundDirectionX(): Gets the X componant of the sound direction

BagSoundDirectionY(): Gets the Y componant of the sound direction

BagSoundDirectionZ(): Gets the Z componant of the sound direction

`=======`
`Panning`
`=======`
SetBagSoundPanStart(Numb,Angle#): The Pan is the angle the listner must be to the sound to hear it. The Pan start is the angle that the, until which the soundwill be perfectly clear. after this until Pan end the sound will fade.

SetBagSoundPanEnd(Numb,Angle#): specifies the end of the pan range. By this angle the sound is in audible.

GetBagSoundPanStart(Numb,Angle#):Gets the angle of the pan start

GetBagSoundPanEnd(Numb,Angle#):gets the angle of the pan end

`=====`
`Speed`
`=====`
SetBagSoundSpeed(Numb,Speed): sets the playing speed of the sound

GetBagSoundSpeed(Numb): gets the current speed the sound is playing at

`=============================`
`Playing, Looping and Stopping`
`=============================`
PlayBagSound(Numb)

LoopBagSound(Numb)

StopBagSound

`======`
`Update`
`======`
UpdateBagSounds(): You put this in your main loop to update the sound system. Remember this one!


Ok so I hope this helps someone. I am more than happy to explain any part of the code or to add extra functions.
Please report any problems as it helps me as much as you. Thanks again folks and sorry in advance for any unfound bugs.

Oh and please have a we look at the demo attached...i'm affraid its a bit crappy but It gives a vague idea of how thigs work...please play with it as you will.

As usual all this is royalty free, just please update me with any problems you find or features you need. Also a wee mention in credits if it is used would be lovely.
Thanks people
Chris

p.s.
Oh you will need to know that this system uses normal sounds to emulate 3D sound effects.
It uses the sounds between BStart and BEnd which can be specified by you in the Setup gosub.

p.p.s.
This bit is for those who may have lost me on the Pan start Pan end bit..I hope here I can explain.


This terrible image is how the sounds can work.
The sound itself is the red dot with the orange line showing the direction in which the sound is facing.
We have the pink line showing where the sound starts to fade off and the dirty green line showing where the sound finally is in-audible...between the points the volume of the sound fades away smoothly.
The blue line shows the start of the volume fade based on the angle from the sound's direction and the green lines showing where the volume finally dissipates.

As default both the startpan and endpan are set to 180 so the effect is that it behaves as a point sound.
e.g.


Attachments

Login to view attachments
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 27th Feb 2006 21:19
ooo this yust looks amazing yust have to try this out some day for my game as i was on my way to try to do something similar.
Matinuker
20
Years of Service
User Offline
Joined: 25th Mar 2004
Location:
Posted: 27th Feb 2006 21:23
Brilliant, I'm surprised this thread hasn't got more
replys allready

Baggers
19
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 27th Feb 2006 21:40
Wow thanks guys...damn your quick!
But I think today so am I...the bug is fixed.

Also the demo is attached now....WARNING very very basic...you'll gain more trying it out in your own code...however it shows the basics.

Baggers
19
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 28th Feb 2006 08:24 Edited at: 28th Feb 2006 11:26
Just finished the sound culling system. This means if a sound is out of range it is stopped playing so your sound slots are free.
The clever bit is the way it gets round a potential problem of culling.

Imagine you have a sound that is 30 seconds long. You are within range at the start after 5 seconds leave range...so the sound is culled... seconds later you go back into range and the sound starts again, even though in real life the sound is still playing even if you are out of range to hear it.
The culling system fixes this by keeping track of the position your sound would have been at if it were still playing and makes sure that when you re-enter range the sound is within a few hundreds of a second's accuracy to where it would have been if it were never culled.

Right so why havnt I posted it yet.
The problem is that currently I have to retirve the sound's length by timing the sound playing...this is very accurate but very slow in comparision to normal sound loading...so I want to fix it. This means I need a fast way of grabbing the lengh of a sound in milliseconds.
As soon as I have this, I will release the update for all.



[EDIT]
*Sits back smuggly and adjusts tie*
Oh yea....its done !
The documentation didnt mention that the header for the sound memblock contained the bytes per second of the sound...so when I saw that it was easy.
Updating all the source code and demo now.


[EDIT]
All done!...it should be ready to go now. As usua, any bugs, please let me know !

Philip
20
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 28th Feb 2006 13:35
This has got "new DLL" written all over it?

Cheer if you like bears! Cheer if you like jam sandwiches!
Quote of the week: "... I started learning DBP while I was a Satellite Network Controller for the US Army Space Command ... "
CodemanV
18
Years of Service
User Offline
Joined: 25th Aug 2005
Location: South Wales Valleys, UK
Posted: 28th Feb 2006 18:19
Hello

I haven't hardly touched 3D sound yet but I have been working on Oscillators and an FM synth which uses Sound Memblocks. This is what I **currently** think is **correct** with regards to the DBP Sound Memblock Header format. It may help you if you want to save your 3D sounds or edit them or something.

If I am wrong then you get permission to make me dance in my pants.

Wave Header


Assuming correctness, wFormatTag and cbSize variables have no use as
Load Sound seems to work with uncompressed PCM WAVE Format only.

The WAVE_FORMAT_TAG UDT is setup for implementing alternative sampling methods to uncompressed PCM Data, Other values for wFormatTag and cbSize usually means that other information follows in the WAVE HEADER for the decoder to read so it knows how to translate the wave format used.

Therefore, using <Load Sound> in DBP, wFormatTag will always be 1 and cbSize will always be zero.


Wave Sound Data
Each channel uses a WORD (2 bytes) to store each sample of it's sound data.

If the sound is MONO then the samples are stored like this
Mono Sample 1 (BytePos = 28 + 0)
Mono Sample 2 (BytePos = 28 + 2 = 30)
Mono Sample 3 (BytePos = 30 + 2 = 32)
Mono Sample 4 (BytePos = 32 + 2 = 34)
etc.....

If there are 2 channels then the samples get stored like this
Left Sample 1 (BytePos = 28)
Right Sample 1 (BytePos = 30 = LeftBytePos + 2)

Left Sample 2 (BytePos = 32)
Right Sample 2 (BytePos = 34 = LeftBytePos + 2)
etc.......

If you ever want to save the Sound Memblock, the header is calculated like this,


And from byte 28 you can read or write the data.



That's about it really. Hope this helps in expanding your project further.
Baggers
19
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 1st Mar 2006 06:34
CodemanV: Fantastic !..Thanks so much man. Well this means I have one slight inacuarcy in the code but it's only to the tune of a few bytes so not too bad.
Well thanks again man thats cleared things up nicely.

Philip: I read your post...but the question makr at the end lost me. But without it I'd say
Thanks, yeah if I could code dll's I probably would be tempted but thats not my current fortay so these snippets are my best attempt.
If anyone fancies converting them then of course feel free (as long as I get a copy !)

Thanks folks !

Login to post a reply

Server time is: 2024-05-14 13:16:06
Your offset time is: 2024-05-14 13:16:06