3D audio class.

Discussion about everything. New games, 3d math, development tips...
Guest

Post by Guest »

in the Real 3D function :roll:
Francis tHe Barbare

Post by Francis tHe Barbare »

To what correspond the variable px, sx, pz, sz, pangley in the Real 3D function?

Do anybody can help me?
:oops:
disanti
Posts: 367
Joined: Sat Jan 17, 2004 1:36 am
Location: California, US
Contact:

Post by disanti »

px: player x
sx: sound x
pz: player z
sz: sound z
pangle: angle the player is facing (camera angle, etc) This is the Y coordinate.

I'm also made a version the works even better and more efficiently.

Update:

Code: Select all

	inline void playsound3d(int snumber,float px, float sx, float pz, float sz,float pangley)
	{
		float distance = sqrt(pow(abs(px-sx),2)+pow(abs(pz-sz),2));
		sound_[snumber]->setVolume(abs(distance-1000)/1000.0);

		float pan = (atan2((sz-pz),(sx,px))*(180.0/GAME_PI)) + pangley;

		sound_[snumber]->setPan(pan);
		sound_[snumber]->setVolume(abs(distance-1000)/1000.0);

		if(soundlength_[snumber]->isPlaying() == false)
		{
			if(distance > 1000)
			{
				//do nothing!
			}
			else
			{
				soundlength_[snumber]->play();
			}
		}
	}
Just replace the old with the new! ;)
________
Yamaha Psr-S500
Last edited by disanti on Tue Feb 22, 2011 8:03 am, edited 1 time in total.
Tels
Posts: 65
Joined: Fri Feb 27, 2004 7:56 pm
Location: Antarctica
Contact:

Post by Tels »

Wooow!

I planned to make a (fake) 3D sound (on top of audiere) for quite a while. My initial plans can be seen in my diary. I just stumbled on this post today. That'll save me some work. Now I know that it was wise to spend the evening surfing the net and updating my photo-gallery, instead of working on my 3D sound API :-)

I'll re-use your stuff and toy around with it later.

Some ideas how to improve it:

* make sound in front of the player 10% less in volume. (0% at straight from the ears, decresing to the front.)
* the same for behind, but this time about 20%.

These values are fudges, e.g. they might be slightly different.

The idea is that you hear sound much better if you ear is pointing in the direction, and slightly better if it is in front of you (notice shape of you ears via bathroom mirror :)

This is the reason people tilt their head to the side when they want to hear something better :)

Also, when a sound is behind the player, you could set the pitchshift to a negative value, and thus make it "darker". that would support the feeling that the sound is behind you.

Some other imrpovements:

* You set accidentily the volume twice
* if the volume is below a certain thresshold (0.01?), mute the sound (note: audiere does currently not support mute, so setting the volume to 0 as a workaround (I hope audiere does no mix sounds with a volume of 0 needlessly :)
* if the distances is farther than the cutoff value (pre-calculate this), set volume to 0 and be done
* And as far as I can see your sound is 2.5D, e.g. it does not handle players head tilting (like special effects, player is walking on a well etc).
* moving sound sources as well as sound sources that are not omnidirectional (not equally loud in each direction) are not yet covered

I planed to use three vectors for the player (look direction (eyes => forward), head-up direction (between ears => up, this one is perpendicular to the look direction, and movement direction/speed (which does not need to equal look direction!) and two per sound (position, and speed vector). However, your simple version would be good for a game like Doom or possible Thief :)

HTH,

Tels
Perl + Irrlicht + Audiere = Game: http://bloodgate.com/perl/game
jeromegz
Posts: 14
Joined: Sat Aug 02, 2008 10:51 am

Post by jeromegz »

float distance = sqrt(pow(abs(px-sx),2)+pow(abs(pz-sz),2));

put this before

Code: Select all


double fSqrt (double y) {//copyright :see below (this is not lemont //or q3)
    double x, z, tempf;
    unsigned long *tfptr = ((unsigned long *)&tempf) + 1;

	tempf = y;
	*tfptr = (0xbfcdd90a - *tfptr)>>1; /* estimate of 1/sqrt(y) */
	x =  tempf;
	z =  y*0.5;                        /* hoist out the “/2”    */
	x = (1.5*x) - (x*x)*(x*z);         /* iteration formula     */ 
//	x = (1.5*x) – (x*x)*(x*z); //répéter pour plus de pécision (dans un fps , faut pas réver )
	//x = (1.5*x) – (x*x)*(x*z); //repeat for more 
	//x = (1.5*x) – (x*x)*(x*z);
	//x = (1.5*x) – (x*x)*(x*z);//tout cela est puissant, les modèles se changent vite
	return x*y;
    }
    

//---fast pow
     unsigned pow_a(unsigned int x, unsigned int exp) 
{
unsigned int retval = 1;
 
for (;exp;--exp) retval *= x;
 
return retval;
} 

//--or 
#define CARRE(x) x*x
int pow_a(int a, int b)
{return  CARRE(a);
}//not tested but it is working


and replace float distance = sqrt(pow(abs(px-sx),2)+pow(abs(pz-sz),2));

Code: Select all

 float distance = fsqrt(pow_a(abs(px-sx),2)+pow_a(abs(pz-sz),2)); 
, thanks for your code, my code is free even for commercial use if you permite to use your code freely too . :)
Hello
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

Wow... 6 year old thread revival.

There's not much point to something like this, seeing as there's a metric ton of audio engines out there. Many of which, including irrKlang and FMOD, are free for noncommercial use and fairly cheap for commercial use if you look in the right place.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Holy necro batman
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

In my test with this function a while back, sqrtf actually performed faster.
Post Reply