Search code examples
iphonefmod

Fmod listener position


Is it possible to have several sounds on different places in a 3D sound world in Fmod? I would like to plot up all the sounds in this 3D world and move around the player.

I am developing for iPhone.


Solution

  • The following code allowed me to place several sounds that were made into events in Fmod Designer into a 3D world of Fmod:

    FMOD_RESULT     result = FMOD_OK;
    FMOD_VECTOR     listenerpos = { 0.0f, 0.0f, 1.0f };
    FMOD_VECTOR     eventpos        = { 0.0f, 0.0f, 1.0f };
    FMOD_VECTOR     eventpos2        = { 0.0f, 0.0f, 1.0f };
    
    float DISTANCEFACTOR          = 2.0f;
    

    Event 1 is one of the sounds I want to place in my 3D world:

    result = group->getEvent("Event 1", FMOD_EVENT_DEFAULT, &event1);
    ERRCHECK(result);
    

    Event 2 is the other event I want to place in the same sounds landscape:

    result = group->getEvent("Event 2", FMOD_EVENT_DEFAULT, &event2);
    ERRCHECK(result);
    

    I place the listener position in the middle of this world:

    listenerpos.x = 0;
    listenerpos.y = 0;
    listenerpos.z = 0;
    
    result = eventSystem->set3DListenerAttributes(0, &listenerpos,NULL,NULL,NULL);
    ERRCHECK(result);
    

    I set the position of one of the events to an object I move around on the iPhone screen:

    eventpos.x = xPos;
    eventpos.z = yPos;
    result = event1->set3DAttributes(&eventpos,&vel);
    ERRCHECK(result);
    

    I set the other event to another position:

    eventpos2.x = xPos2;
    eventpos2.y = yPos2;
    
    result = event2->set3DAttributes(&eventpos2,&vel);
    ERRCHECK(result);
    

    The entire event system and 3D world is updated with these positions:

    result = eventSystem->update();
    ERRCHECK(result);
    

    I trigger the 2 events and hear how they move around the listener:

    result = event1->start();
    ERRCHECK(result);
    
    result = event2->start();
    ERRCHECK(result);