3d sound made using audihere!!

A forum to store posts deemed exceptionally wise and useful
Post Reply
omaremad

3d sound made using audihere!!

Post by omaremad »

i thought i would pu this here since cristian said it is useful and should be transfered from advanced help
hello ppl
u may say that fmod and openal have 3d sound so whats the point of using simple(non 3d sound) audihere for 3d sound

the answer is that audihere is simple to use and free

i also made this since iam a noob who doesnt want to waste time learning complex sound api-s

so here is the solution

first of all we will use this function alot so keep it in ur header files



code:
--------------------------------------------------------------------------------
vector3df getTargetAngle(vector3df v, vector3df r)
{
//v -position
//r -target

vector3df angle;
float x,y,z;
x = r.X - v.X;
y = r.Y - v.Y;
z = r.Z - v.Z;

//angle in X-Z plane
angle.Y = atan2 (x, z);
angle.Y *= (180 / PI); //converting from rad to degrees
//angle.Y-=90;
//just making sure angle is somewhere between 0-360 degrees
if(angle.Y < 0) angle.Y += 360;
if(angle.Y >= 360) angle.Y -= 360;

//angle in Y-Z plane while Z and X axes are already rotated around Y
float z1 = sqrt(x*x + z*z);

angle.X = atan2 (z1, y);
angle.X *= (180 / PI); //converting from rad to degrees
//angle.X -= 90;

//just making sure angle is somewhere between 0-360 degrees
if(angle.X < 0) angle.X += 360;
if(angle.X >= 360) angle.X -= 360;

return angle;
}
--------------------------------------------------------------------------------





next bit

create the following vars for each sound emitter


code:
--------------------------------------------------------------------------------

float dist;
float vol;
int bal;
f32 rotaddy;

--------------------------------------------------------------------------------




every thing past this point should be updated evry time any thing is rendered

u have 2 find the distance between the emitter and the reciever


code:
--------------------------------------------------------------------------------

core::vector3df start = targetNodeint->getAbsolutePosition();
core::vector3df end = camera->getAbsolutePosition();

core::line3d<f32> line(start, end);
dist=line.getLength();

--------------------------------------------------------------------------------




the vol variable would be the volume so it is inversely proportinal to the dist


code:
--------------------------------------------------------------------------------

vol=(1/(dist/150));

--------------------------------------------------------------------------------




to get the balance

code:
--------------------------------------------------------------------------------

vector3df aimrot=getTargetAngle(targetNodeint->getAbsolutePosition,camera->getAbsolutePosition);

rotaddy=aimrot.Y-camera->getRotation().Y;

if (rotaddy>0&rotaddy<180)
{bal=1; //right}
else
{
bal=-1;//left
};

--------------------------------------------------------------------------------





now apply
the sstting to the sound u made

code:
--------------------------------------------------------------------------------

ahh->setRepeat(false);
ahh->setVolume(vol);
ahh->setPan(bal);


--------------------------------------------------------------------------------




i am trying to clean my project up so i can use it as a demo for this feature
omaremad

Post by omaremad »

float calculatevolume(core::vector3df epos,core::vector3df lpos)
{

core::line3d<f32> line(epos, lpos);
float dist=line.getLength();
float vol=(1/(dist/150));

return vol;

}

int calculatebalance(core::vector3df epos,core::vector3df lpos)
{

int bal;

core::vector3df aimrot=getTargetAngle(pos,epos);
rotaddy=aimrot.Y-camera->getRotation().Y;


if (rotaddy>0&rotaddy<180)

{
bal=1;
}

else

{

bal=-1;

};


return bal;

}


the demo is in the the project annoucements
under
"state of the art fps
Post Reply