Why does Channel::getPan exist in FMOD 4 but not FMOD 5 low level API?

  • You must to post comments
Best Answer

Calling setPan, setMixLevelsOutput and setMixMatrix all generate a final matrix that is used for panning.
If all 3 are used interchangeably, then get functions for everything except the getMixMatrix function can be meaningless.

For example if setPan was used and then setMixLevelsOutput was used with random values for each parameter, what would getPan return?

Another example, if setMixMatrix was called with random values, what would getPan return?

They could return the last values ‘set’, but then they would be obsolete, and not representing what is heard (and therefore wrong). Also storing last values set, would consume a lot more memory per channel which could add up to megabytes of wasted memory if redundant 32×32 matrices were stored for example.

An interim solution for getPan is to calculate it based on front right and front left values.
This function does this for channels that play a mono signal, as it works on column 0 only.

    Calculate a 'pan' value from a mix matrix.  Should handle anything even if setPan is not used.
float calcPanFromMatrix(FMOD::ChannelControl *cc)
    int out, in;
    float mat[32][32], pan;

    // These 3 lines are to work around a bug if thread safe fmod calls are used, 
    // its not flushing the matrix values from a setpan call when trying to use getMixMatrix.
    // Should be fixed in FMOD Studio API 1.05.09 release.
    FMOD::System *sys;

    // Get the pan matrix
    cc->getMixMatrix(0, &out, &in,32);
    cc->getMixMatrix(&mat[0][0], &out, &in,32);

    // calculate a pan value based on front left/front right.
    float l =  1.0f - (2 * (mat[0][0]*mat[0][0]));
    float r =         (2 * (mat[1][0]*mat[1][0]) - 1.0f);

    pan = (l+r) * 0.5f;

    return pan < -1.0f ? -1.0f : pan > 1.0f ? 1.0f : pan;
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.