0
0

The documentation for System::update states that it updates the 3d positions of sounds, but there is one aspect about this that that caught me and I’m not sure if it was designed to work this way.

The following code works:

while (1) {
System::update();
System::PlaySound();
Channel::Set3DAttributes();
Channel::SetPaused(false);
Sleep(100);
}

And so does this:

while (1) {
System::PlaySound();
Channel::Set3DAttributes();
Channel::SetChannelGroup();
Channel::SetPaused(false);
System::update();
Sleep(100);
}

However, if the sleep is between the call to SetPaused and the call to update, and the channel is put in a channelgroup, like this:

while (1) {
System::update();
System::PlaySound();
Channel::Set3DAttributes();
Channel::SetChannelGroup();
Channel::SetPaused(false);
Sleep(100);
}

Then the sound starts at the origin and moves to the correct location when update gets called.

This is the code I used to test this:
[code:ifq002q0]
static void _testFmod(void)
{
FMOD_SYSTEM * system;
FMOD_SOUND * sound;
FMOD_CHANNELGROUP * masterChannelGroup;
FMOD_CHANNELGROUP * channelGroup;
int running=1;
int setChannelGroup=1;
int callSleep=1;

FMOD_System_Create(&system);
FMOD_System_SetStreamBufferSize(system,32768,FMOD_TIMEUNIT_RAWBYTES);
FMOD_System_Init(system,4,FMOD_INIT_NORMAL,NULL);
FMOD_System_Set3DSettings(system,1.0f,1.0f,1.0f);

FMOD_System_CreateSound(system,"test_fmod.wav",FMOD_CREATESAMPLE|FMOD_SOFTWARE|FMOD_LOOP_OFF|FMOD_3D,NULL,&sound);

FMOD_System_LockDSP(system);
FMOD_System_GetMasterChannelGroup(system,&masterChannelGroup);
FMOD_System_CreateChannelGroup(system,NULL,&channelGroup);
FMOD_ChannelGroup_AddGroup(masterChannelGroup,channelGroup);
FMOD_System_UnlockDSP(system);

FMOD_VECTOR listener_position={0.0f,0.0f,0.0f};
FMOD_VECTOR listener_velocity={0.0f,0.0f,0.0f};
FMOD_VECTOR listener_front={0.0f,0.0f,1.0f};
FMOD_VECTOR listener_up={0.0f,1.0f,0.0f};
FMOD_System_Set3DListenerAttributes(system,0,&listener_position,&listener_velocity,&listener_front,&listener_up);

do {
FMOD_System_Update(system);

  if (_kbhit()) {
     char key=_getch();

     if (key=='l' || key=='r') {
        FMOD_VECTOR sound_position={1.0f,0.0f,0.0f};
        FMOD_CHANNEL * channel;
        int needsNewline=1;

        if (key=='l')
           sound_position.x=-1.0f;

        FMOD_System_PlaySound(system,FMOD_CHANNEL_FREE,sound,TRUE,&channel);
        FMOD_Channel_SetVolume(channel,1.0f);
        FMOD_Channel_Set3DMinMaxDistance(channel,0.5f,100.0f);
        FMOD_Channel_Set3DAttributes(channel,&sound_position,NULL);

        if (setChannelGroup)
           FMOD_Channel_SetChannelGroup(channel,channelGroup);

        FMOD_Channel_SetPaused(channel,FALSE);

        if (callSleep)
           Sleep(100);
     } else if (key=='c') {
        setChannelGroup=!setChannelGroup;
        printf("ChannelGroup will%sbe set\n",(setChannelGroup)?" ":" not ");
     } else if (key=='s') {
        callSleep=!callSleep;
        printf("Sleep will%sbe called\n",(callSleep)?" ":" not ");
     } else if (key=='e' || key==0x1B) {
        running=0;
     }
  } else {
     Sleep(100);
  }

} while (running);

FMOD_Sound_Release(sound);
FMOD_System_Close(system);
FMOD_System_Release(system);
}
[/code:ifq002q0]

  • You must to post comments
0
0

The code is working, but you have changed channelgroups after setting the 3d position.
What this does is disconnect any dsp connections inside the network (which have just had their pan matrices set up) and connects it to a fresh connection, which doesnt have the 3d matrix set up, so you get a frame of no 3d panning at all.
It looks like something i can probably fix, but an easy change for you to make is just move the setChannelGroup up one line, to before the set3dattributes call, and it will work.

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.