Hi everyone,
I am a c ++ developer and use low level api fmod.
I want to make my sound distinguishable whether it is in front of me, behind me or at the top. Ordinary 3d is not enough for me, because it’s ordinary stereo.
I read that the sound can be panned using dsp object paner just as I want, but despite reading the documentation, I can’t make my test program work properly.
May I be very grateful for any help in solving my problem.
Below is the code.
C/C++
#include <iostream>
#include <windows.h>
#include <conio.h>
#include <fmod.hpp>
#define ercheck( r ) if( r != FMOD_OK) std::cout<<"error: " << r;
int main()
{
FMOD_RESULT result;
FMOD::System *system =0;
FMOD::Sound* sound=0;
FMOD::Channel *channel =0;
FMOD::DSP *dsp = 0;
result = FMOD::System_Create(&system);
result =system->setSoftwareFormat(0, FMOD_SPEAKERMODE_7POINT1POINT4, 0); //sets speakers to 7 1
ercheck(result);
result =system->setOutput(FMOD_OUTPUTTYPE_WINSONIC);
ercheck(result);
result = system->init(100, FMOD_INIT_NORMAL | FMOD_INIT_CHANNEL_LOWPASS | FMOD_INIT_3D_RIGHTHANDED , 0);
result = system->set3DSettings(1.f, 1.f, 0.1f);
ercheck( result );
//create dsp to object paner
result = system->createDSPByType(FMOD_DSP_TYPE_OBJECTPAN, &dsp);
ercheck(result);
//create sound
result = system->createSound( "test.wav", FMOD_3D, 0, &sound);
ercheck( result );
result = sound->set3DMinMaxDistance( 0.5f , 500);
ercheck( result );
//sound position
FMOD_VECTOR pos_sound = { 500, 110, 490};
FMOD_VECTOR vel_sound = { 0, 0, 0};
//listener
FMOD_VECTOR pos_listener = { 500, 100, 500};
FMOD_VECTOR vel_listener = { 0, 0, 0};
FMOD_VECTOR forward_listener = { 0, 0, -1};
FMOD_VECTOR up_listener = { 0, 1, 0};
bool close = false;
while( !close )
{
auto key =_getch();
if(key == 27) //key escape = close program
close = true;
Sleep(10);
result = system->update(); // update to system fmod
ercheck( result );
/*I don't know how to fill setparameterdata, I read something about this: FMOD_DSP_PARAMETER_3DATTRIBUTES_MULTI
I tried it but it doesn't work */
dsp->setParameterData(FMOD_DSP_OBJECTPAN_3D_POSITION , 0 , 0); // I do't know how to set this method argument two is type void *
//listener
result = system->set3DListenerAttributes(0, &pos_listener, &vel_listener, &forward_listener, &up_listener);
ercheck( result );
result = system->playSound( sound, 0, true, &channel);
ercheck( result );
result = channel->addDSP(0, dsp);
ercheck(result);
result = channel->set3DAttributes(&pos_sound, &vel_sound);
result = channel->setPaused(false);
}
//shut down
dsp->release();
sound->release();
result = system->close();
ercheck( result );
system->release();
return 0;
}