0
0

I’m new to the FMOD Lib and i want some help.Please!!!!!!!!!!!!!

I’m making a game and want to use the lib for 3d sound.

I use the FSOUND_Stream_OpenFile(pMusicFileName,FSOUND_HW3D,0) function
to load the background music and FSOUND_Sample_Load to load the sound effects in the game
such as shoots for shootgun etc…
The problem starts here.
when the game starts the music sound from all the speakers but when i’m moving
the MUSIC sounds lower or louder depending of the distance from one object in the scene.

The class that i’v made for Objects is:

Object.h

class ObjectVector
{
public:

float x,y,z;

};

class Objects
{
public:

FSOUND_SAMPLE *p3dObjectSound;

int i, ObjectChannel;

float MaxDist;

ObjectVector ObjVect[500];
ObjectVector Distance;
Objects();
~Objects();

void LoadObject(char *pObjectFileName);

void RenderObject();

void LoadObjectSong(char *pObjectSoundName,float MinDistFromSource,float MaxDistFromSource);

void PlayObjectSong();

void BoundingBox();

float CenterBBox[3];

void InitSoundDist();

};

and the Object.cpp

float pos[3];

Objects::Objects()
{
i = 0;
ObjectChannel = -1;
p3dObjectSound = NULL;
}

Objects::~Objects()
{
FSOUND_Close();
}

void Objects::RenderObject()
{

glPushMatrix();
glTranslatef(CenterBBox[0],CenterBBox[1],CenterBBox[2]);

glColor3f(1.0,0.0,0.0);

auxWireBox(Distance.x,Distance.y,Distance.z);

glPopMatrix();

glColor3f(1.0,1.0,1.0);

glBegin(GL_TRIANGLES);

for(int j = 0;j<i;j++)
{
    glVertex3f(ObjVect[j].x,ObjVect[j].y,ObjVect[j].z);
}
glEnd();

}

void Objects::LoadObjectSong(char *pObjectSoundName,float MinDistFromSource,float MaxDistFromSource)
{
p3dObjectSound= FSOUND_Sample_Load(FSOUND_FREE,pObjectSoundName,FSOUND_HW3D,0);

if(!p3dObjectSound)
{
    char p3derror[255];
    sprintf(p3derror,"%s",FMOD_ErrorString(FSOUND_GetError()));
    MessageBox(NULL,p3derror,"ERROR",MB_OK);
    FSOUND_Close();
    return ;
}

MaxDist = MaxDistFromSource;

FSOUND_Sample_SetMinMaxDistance(p3dObjectSound,MinDistFromSource,MaxDistFromSource);

FSOUND_Sample_SetMode(p3dObjectSound, FSOUND_LOOP_NORMAL);

}

void Objects::PlayObjectSong()
{
float pos[3] = {CenterBBox[0],CenterBBox[1],CenterBBox[2]};

float vel[3] = {0.0,0.0,0.0};

ObjectChannel = FSOUND_PlaySoundEx(FSOUND_FREE, p3dObjectSound, NULL, TRUE);

FSOUND_3D_SetAttributes(ObjectChannel,pos,vel);

if (!FSOUND_SetPaused(ObjectChannel, FALSE))
{
    char paused1[255];
    sprintf(paused1,"%s\n", FMOD_ErrorString(FSOUND_GetError()));
    MessageBox(NULL,paused1,"ERROR p3dObj",MB_OK);
}

}

void Objects::BoundingBox()
{
ObjectVector BBoxMin,BBoxMax;

BBoxMin.x = BBoxMin.y = BBoxMin.z = 10000000.0f;
BBoxMax.x = BBoxMax.y = BBoxMax.z =-10000000.0f;

for(int j=0;j<i;j++)
{
    if(ObjVect[j].x < BBoxMin.x)
    {
        BBoxMin.x = ObjVect[j].x;
    }
    if(ObjVect[j].y < BBoxMin.y)
    {
        BBoxMin.y = ObjVect[j].y;
    }
    if(ObjVect[j].z < BBoxMin.z)
    {
        BBoxMin.z = ObjVect[j].z;
    }

    if(ObjVect[j].x > BBoxMax.x)
    {
        BBoxMax.x = ObjVect[j].x;
    }
    if(ObjVect[j].y > BBoxMax.y)
    {
        BBoxMax.y = ObjVect[j].y;
    }
    if(ObjVect[j].z > BBoxMax.z)
    {
        BBoxMax.z = ObjVect[j].z;
    }

}
    CenterBBox[0] = (BBoxMin.x + BBoxMax.x)*0.5f;
    CenterBBox[1] = (BBoxMin.y + BBoxMax.y)*0.5f;
    CenterBBox[2] = (BBoxMin.z + BBoxMax.z)*0.5f;

    Distance.x = BBoxMax.x - BBoxMin.x;
    Distance.y = BBoxMax.y - BBoxMin.y;
    Distance.z = BBoxMax.z - BBoxMin.z;

}

void Objects::InitSoundDist()
{
float SoundDistance[3];
float Length;

    SoundDistance[0] = Camera.CameraPosition.x - pos[0];
    SoundDistance[1] = Camera.CameraPosition.y - pos[1];
    SoundDistance[2] = Camera.CameraPosition.z - pos[2];

    Length = sqrt(SoundDistance[0]*SoundDistance[0] +SoundDistance[1]*SoundDistance[1] +SoundDistance[2]*SoundDistance[2]);

    if(Length > MaxDist)
    {
        FSOUND_SetVolume(ObjectChannel,0);
    }
    else 
    {
        FSOUND_SetVolume(ObjectChannel,256);
    }

}

The music.h file is :

class MusicLib
{
public:
FSOUND_STREAM *p2DMusic;

int MusicChannel;

MusicLib();
~MusicLib();

void LoadMusic(char *pMusicFileName);

void PlayMusic();

void MusicAndSoundInitialize();

};

And the Music.cpp is:

MusicLib::MusicLib()
{
p2DMusic = NULL;

MusicChannel = -1;

}

MusicLib::~MusicLib()
{
}

void MusicLib::MusicAndSoundInitialize()
{
if (FSOUND_GetVersion() < FMOD_VERSION)
{
char ver[255];
sprintf(ver,”%.02f\n”, FMOD_VERSION);
MessageBox(NULL,ver,”ERROR in ver”,MB_OK);
return ;
}

FSOUND_SetOutput(FSOUND_OUTPUT_DSOUND);

FSOUND_SetDriver(1);                            

FSOUND_SetMixer(FSOUND_MIXER_MMXP6);    

if (!FSOUND_Init(44100, 32, 0))
{
    char init[255];
    sprintf(init,"%s\n", FMOD_ErrorString(FSOUND_GetError()));
    MessageBox(NULL,init,"ERROR in init",MB_OK);
}

}

void MusicLib::LoadMusic(char *pMusicFileName)
{
p2DMusic = FSOUND_Stream_OpenFile(pMusicFileName,FSOUND_HW2D,0);

FSOUND_SetSpeakerMode(FSOUND_SPEAKERMODE_DOLBYDIGITAL);

if(!p2DMusic)
{
    char p2derror[255];
    sprintf(p2derror,"%s",FMOD_ErrorString(FSOUND_GetError()));
    MessageBox(NULL,p2derror,"ERROR",MB_OK);
    FSOUND_Close();
    return ;
}

}

void MusicLib::PlayMusic()
{
float pos[3] = {Camera.CameraPosition.x,Camera.CameraPosition.y,Camera.CameraPosition.z};
float vel[3] = {0.0,0.0,0.0};

MusicChannel = FSOUND_Stream_PlayEx(FSOUND_FREE,p2DMusic,NULL,TRUE);

FSOUND_SetSpeakerMode(FSOUND_SPEAKERMODE_SURROUND);


if (!FSOUND_SetPaused(MusicChannel, FALSE))
{
    char paused1[255];
    sprintf(paused1,"%s\n", FMOD_ErrorString(FSOUND_GetError()));
    MessageBox(NULL,paused1,"ERROR",MB_OK);
}

}

void Sound3DInit()
{
{
float lastpos[3] ={Camera.CameraPosition.x,Camera.CameraPosition.y,Camera.CameraPosition.z};
float listenerpos[3] = {0.0,0.0,0.0};
float vel[3];

    listenerpos[0] = Camera.CameraPosition.x;
    listenerpos[1] = Camera.CameraPosition.y;
    listenerpos[2] = Camera.CameraPosition.z;

    vel[0] = (listenerpos[0] - lastpos[0])/(1000.0/100.0);
    vel[1] = (listenerpos[1] - lastpos[1])/(1000.0/100.0);
    vel[2] = (listenerpos[2] - lastpos[2])/(1000.0/100.0);

    lastpos[0] = listenerpos[0];
    lastpos[1] = listenerpos[1];
    lastpos[2] = listenerpos[2];

FSOUND_3D_Listener_SetAttributes(&amp;listenerpos[0],&amp;vel[0],Camera.CameraView.x - Camera.CameraPosition.x,Camera.CameraView.y - Camera.CameraPosition.y,Camera.CameraView.z - Camera.CameraPosition.z,UpVector.x, UpVector.y, UpVector.z);

}
Obj.InitSoundDist();
Obj1.InitSoundDist();
FSOUND_Update();

}

I’m calling the Sound3dInit() func to the keys update;
The problem is that when i create an object of class Objects ,in example
Objects Obj;

And start the game the sound from the object is playing just fine.
I’m moving around the screen and the sound seems to be 3d.
But when i create another object of the same class ,in example Objects Obj1;
and call it in the WinMain, just like the prev obj, the sound of the second
object is playing from the same potition with the prev object.
The object aren’t in the same position , and the bounding boxes are different.
Also the Music is playing from the same position of the obj.
I DON’T ANYMORE KNOW WHAT TO DO!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Why the MUSIC plays at the start of the game from all the speakers, but when
i’m moving the MUSIC sounds lower or louder?
If I use the FSOUND_HW2D parameter in the Stream_OpenFile the MUSIC sounds only
from 2 speakers and not from all(4 Speakers).
May i ask WHY?????????

Please answer!!!!
I’m desperate….

Thanks in advance.

  • You must to post comments
Showing 0 results
Your Answer

Please first to submit.