0
0

I know that in FMOD, the 3D effect can make a sound to move from left to right and vice versa. But is it possible to make the sound fade out?

I set the attributes, MinMaxDistance, etc. but somehow, the sound just wun fade out.

[code:wdt43ro0]
CAudioEngine::CAudioEngine()
{
result = FMOD::System_Create(&system);
ERRCHECK(result);

result = system->getDriverCaps(0, 0, 0, 0, &speakermode);
ERRCHECK(result);

result = system->init(100, FMOD_INIT_3D_RIGHTHANDED, 0);
ERRCHECK(result);

LoadSounds();

}

void CAudioEngine::LoadSounds()
{
//Load some sounds

result = system->createSound("data/sounds/09.mp3",  FMOD_3D, 0, &sound);
ERRCHECK(result);

result = sound->set3DMinMaxDistance(1,2);
ERRCHECK(result);
result = sound->setMode(FMOD_LOOP_OFF);
ERRCHECK(result);

}

void CAudioEngine::TickAudio(CCamera * cam, CVECTOR playerPos)
{

ChangeListenerPos(cam, playerPos);

}

void CAudioEngine::PlaySound()
{

FMOD_VECTOR pos = { 0.0f, 0.0f, 0.0f };
FMOD_VECTOR vel = { 0.0f, 0.0f, 0.0f };

result = system->playSound(FMOD_CHANNEL_FREE, sound, true, &channel);
cout << "Channel: " << channel;
ERRCHECK(result);

channel->set3DMinMaxDistance(1,2);
result = channel->set3DAttributes(&pos, 0);
ERRCHECK(result);

channel->setPaused(false);

}

void CAudioEngine::ChangeListenerPos(CCamera * cam, CVECTOR playerPos)
{
CVECTOR campos = cam->getPosition();
FMOD_VECTOR fcampos = {campos.fX, campos.fY, campos.fZ};

CVECTOR camforward = playerPos - campos;

static FMOD_VECTOR lastpos = { 0.0f, 0.0f, 0.0f };
FMOD_VECTOR forward        = { camforward.fX, camforward.fY, camforward.fZ };

// 255 - (((soundPos - cameraPos) / soundAreaDistance) * 255)

FMOD_VECTOR *oldPos;
oldPos->x = 0;
oldPos->y = 0;
oldPos->z = 0;

channel->get3DAttributes(oldPos, 0);

CVECTOR cOldPos;
cOldPos.fX = oldPos->x;
cOldPos.fY = oldPos->y;
cOldPos.fZ = oldPos->z;

CVECTOR cCamPos;
cCamPos.fX = campos.fX;
cCamPos.fY = campos.fY;
cCamPos.fZ = campos.fZ;


result = system->set3DListenerAttributes(0, &fcampos, 0, &forward, 0);
ERRCHECK(result);

system->update();

}
[/code:wdt43ro0]

CVECTOR is just a class with x, y, z coordinates. And TickAudio is a method that is called during MainGameLoop. For now, the audio can rotate when the camera is rotating in the 3D game. And when my camera move to the left or right of the Sound location, the Sound will differ from left to right. However, the sound don’t fade out. Is it something wrong wif the set3DMinMaxDistance()? If yes, please advice on what parameter to enter to here a clear difference, thanks. :(

  • You must to post comments
0
0

You set the max distance to 2, please read the documentation on what max distance means

  • You must to post comments
0
0

I don’t quite understand the documentation, can you explain abit further here please? It will help alot, thanks in advance.

  • You must to post comments
0
0

The min distance is the size the sound will be full volume, the max distance is what distance the sound will stop getting quieter – it freezes volume. Mostly you’re max distance will be a really large number.

  • You must to post comments
0
0

maxdistance is where it -stops- fading out. Just set maxdistance to 10000.

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.