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.

Program Announcements / Free 3D sound system replacement

Author
Message
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 10th Mar 2006 14:39 Edited at: 10th Mar 2006 15:08
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 below...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.

http://forum.thegamecreators.com/xt/xt_apollo_download.php?i=796616

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.


Some may have seen this on DBP discussion a little while back...however it didnt get much feedback so I'm reposting in the hope it will generate more interest and reach more people.
I'm completly open to any feature requests and would be very interested on expanding this.
Thanks people !


M.I.A is pending
FoxBlitzz
21
Years of Service
User Offline
Joined: 19th Nov 2003
Location: United States
Posted: 11th Mar 2006 02:29 Edited at: 11th Mar 2006 02:30
What's with all the code that sets the sound position? That seems like it would make the sounds run very choppy, especially since you used screen fps(), which only updates once a second. Correct me if I'm wrong.

AMD Athlon 64 X2 4200+
1GB DDR-SDRAM (May increase to 2GB one day)
512MB ATI Radeon X1800 Series - Finally! A card that does pixel shaders correctly!
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 11th Mar 2006 10:29
All the code for position ?
Theres one command: PositionBagSound(Number,X#,Y#,Z#)
There are then 3 commands to return the sound position (just like positioning any object)

if you man all the pan stuff then that is optional...you don't have to set it. If you dont it just behaves as an ordinary point sound.

Screen fps() gets your current fps....this value is used when the sound has been culled (when your out of range of it) to keep track of where the sound would be, so that when you re-enter range it continues playing from the correct point.

M.I.A is pending
Darkbasic MADPSP
19
Years of Service
User Offline
Joined: 15th Jun 2005
Location: Uk
Posted: 12th Mar 2006 21:40
Really nice

where i went on holiday to
www.portaventura.es and also http://themepark.nl/ubbthreads/showflat.php?Cat=0&Board=UBB7&Number=661483&page=0&fpart=all
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 13th Mar 2006 19:05
Thanks...is it being used in a project or just a general nice ?!

M.I.A is pending
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 15th Mar 2006 11:27
Good stuff Baggers. Some time ago while coding something in DBP to test Tempest with I coded myself a function for playing a sound at a particular volume depending on distance from specified coordinates, which was all very well but it didn't do panning so it kinda sucked(yet for some reason I prefered it over the built-in 3D sounds command set..). Anyway, I sure could have used this instead, but it wasn't around then, so oh well. I'll keep it in mind for future projects. Thanks dude.

Tempest - P2P UDP Multiplayer Plugin - 70%
Download the free version
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 15th Mar 2006 11:31
Anytime! When my current project comes out it will be a nice showcase to show what this sound engine can do.

M.I.A is pending
optical r
22
Years of Service
User Offline
Joined: 23rd Oct 2002
Location: Prime
Posted: 19th Mar 2006 00:29
extremely nice there baggers!
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 19th Mar 2006 13:34
Thanks!...I am starting on the main game engine of my project today so when I hit sounds I will probably find various ways to optimise this...I'll obviously release them when I make them.

M.I.A is pending
Chris Franklin
19
Years of Service
User Offline
Joined: 2nd Aug 2005
Location: UK
Posted: 29th Mar 2006 20:20
Looks cool probably gonna use this in my themepark sim

Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 29th Mar 2006 20:37
Excelent ! keep me posted on how it goes.
I'm planning on expanding it making use of Torrey's awesome advanced sound pluggin. This will allow for all the 3D goodies you have from this version plus you can use:
- Ogg Vorbis
- MP3
- FLAC
- WAV (uncompressed)
- AIFF
- MOD
- S3M
- XM
- IT

And also play with things like the pitch of the sound.

I will be developing that in my current project so when I have it all working there I will release it (free as ever obviously).

Goodnight

M.I.A is pending
Hawkeye
21
Years of Service
User Offline
Joined: 19th Sep 2003
Location: SC, USA
Posted: 29th Mar 2006 21:09
Oooo, this looks dread useful I can already think of several cool effects you could do with this - distant bullet shots, helicopter blades whirling, etc.


I am but mad north north-west; when the wind is southerly I know a hawk from a handsaw - Hamlet, Hamlet
Chris Franklin
19
Years of Service
User Offline
Joined: 2nd Aug 2005
Location: UK
Posted: 31st Mar 2006 17:13
nice just when i need an mp3 3d sound function as well anychance of wma support as well?

Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 31st Mar 2006 17:43
Sunrise: Like I said above, that will be in the next version.
Hawkeye: Yeah, I am certainly going to be using it with newton so I change the pitch and volume of an impact sound depending on how hard one surface hits another...should make for some cool sound effects.

M.I.A is pending
DARKGuy
20
Years of Service
User Offline
Joined: 28th Nov 2003
Location:
Posted: 2nd Apr 2006 09:02
If you do though, make sure you make a non-newton version for it, for those who might not use newton in their games

Either way, this might prove -really- useful in that secret project of mine overall because the builtin "3D" sound functions never convinced me.

*stores in safe place, ready for being used when the time is right, and gives a 5-star rating *

Quote: "Compaq Deskpro EN / Intel Pentium III 930Mhz / 256Mb RAM / Intel i82815E 64Mb AGP / SoundMAX Soundcard / Creative SBS 2.1 / Two 40Gb HDs / WinXP Pro & Debian Etch / 1280x1024x16b"
Oneka
20
Years of Service
User Offline
Joined: 24th Apr 2004
Location: Hampton,VA
Posted: 2nd Apr 2006 11:07
Oh forgot to say this,
This is really awesome great work with it man


Making better games everday!
Oh yeah and just so you know its Oh-nek-a not One-ka!
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 2nd Apr 2006 11:33
Wow thanks guys ! Thats brought a smile to my morning.
Yeah the commands themselves would be non newton you just feed in force vaues from whichever system you are using....but thats in the future!

M.I.A is pending
Xander
21
Years of Service
User Offline
Joined: 3rd Mar 2003
Location: In college...yeah!
Posted: 3rd Apr 2006 02:07
Wow, thanks so much Baggers. I am beginning work on my new project, a sequel of Firewall, and this will be awesome to add in. I'm a huge audio freak (have 6.2 surround sound in my dorm room, 2 subs including a 300 watt beast), and it will be great to have some decent sound in my next game. I am still in the way start of the new game, but I'll be sure to let you know how it goes, can't wait to play around with this. Thanks again man. This earns you a free copy of the sequel once I finish it

Xander Moser - Bolt Software - Firewall
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 3rd Apr 2006 09:17
Wow thanks very much. I hope I havnt miss-sold it though.
This as yet doesnt do proper surround sound. It is just like standard DB sounds in that respect. The sound panning works fine though and if you have any requests for features shout about 'em here. I however do want to expand this at a later date for proper full surround sound.
Thanks again man.

M.I.A is pending
Xander
21
Years of Service
User Offline
Joined: 3rd Mar 2003
Location: In college...yeah!
Posted: 3rd Apr 2006 10:12
Yeah, I understand that. But if it as it a least decent panning sound, then my receiver can convert that stereo signal into emulated surround sound. It works great with commerical RTS games. As long as it is good stereo sound, so this should work fine. Real surround sound would be crazy awesome, but I don't even have a decent computer right now with coax or direct 7.1 out, so I can't use real surround sound out of my computer until I build my own computer with a decent sound card anyway.

Xander Moser - Bolt Software - Firewall
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 3rd Apr 2006 10:28
In that case awesome !...I just hated the idea of you being dissapointed by this once you had started coding!

M.I.A is pending
Chris Franklin
19
Years of Service
User Offline
Joined: 2nd Aug 2005
Location: UK
Posted: 3rd Apr 2006 12:31 Edited at: 3rd Apr 2006 12:33
Quote: "Sunrise: Like I said above, that will be in the next version."

Lol sorry i meant wma

Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 3rd Apr 2006 12:46
Nope WMA won't be supported. I suggest finding a converter of some kind. Sorry about that.

M.I.A is pending
Hatsu
22
Years of Service
User Offline
Joined: 22nd Oct 2002
Location:
Posted: 5th Apr 2006 21:29
Looks good, I will have to try this out. I tell you what would make it amazing, would be if it took into affect the Doppler effect for sound.

Still good work though.
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 6th Apr 2006 12:05
Quote: "I tell you what would make it amazing, would be if it took into affect the Doppler effect for sound"


Indeed it would!...well I know nothing about it yet but who knows could be a future project!

M.I.A is pending
Xander
21
Years of Service
User Offline
Joined: 3rd Mar 2003
Location: In college...yeah!
Posted: 6th Apr 2006 23:36
It isn't a difficult thing to figure out. I am assuming you know the basics:

-when the difference between the velocities of the source and the listener < 0 (objects are moving closer to eachother) then the pitch is raised

-when the difference between the velocities of the source and the listener > 0 (objects are moving farther apart from one another) then the pitch is lowered

I can't remember the equation right now, I'll get it for you later after class if you don't get it before then, it'd be an awesome effect though

Xander Moser - Bolt Software - Firewall
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 7th Apr 2006 10:07
Yeah, I had a quick read around about dopler effect. I havnt looked up the equations yet either. Could have a nice little dopler function do you juse feed in a velocity and it does the rest.
Definately something i'll look into.

M.I.A is pending
Xander
21
Years of Service
User Offline
Joined: 3rd Mar 2003
Location: In college...yeah!
Posted: 7th Apr 2006 19:06
Yeah, all you'd need is the difference in velocities of the source of the sound and the listener, and the pitch of the sound being played. Then just adjust the pitch accordingly

Xander Moser - Bolt Software - Firewall
adr
21
Years of Service
User Offline
Joined: 21st May 2003
Location: Job Centre
Posted: 8th Apr 2006 05:22
I tried to hack together a doppler effect with Torrey's DLL. Even though you can change the pitch of a sound using a float, the results are too "crackley".

I don't know what the reason for that is, but every time you change the sound pitch, even with just a minute change to a float, there's a tiny, but audible, click. Do that several times per second and it sounds like your space ship engine is coming out of an old record player.

[center]
iv tryed everything!!!!!!!!!! could u please just add The gun and shooting Code thats All!!!!!!!!!
Xander
21
Years of Service
User Offline
Joined: 3rd Mar 2003
Location: In college...yeah!
Posted: 8th Apr 2006 23:31
That'd be quite annoying

Xander Moser - Bolt Software - Firewall
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 9th Apr 2006 09:02
Ouch...won't be doing that for a bit then!

M.I.A is pending

Login to post a reply

Server time is: 2024-11-22 20:07:40
Your offset time is: 2024-11-22 20:07:40