Minimize each response delay for the ambisonic HRTF decode

This commit is contained in:
Chris Robinson 2018-02-17 21:15:39 -08:00
parent b5aa0c0759
commit fa9ab9af7c

View File

@ -204,6 +204,7 @@ void BuildBFormatHrtf(const struct Hrtf *Hrtf, DirectHrtfState *state, ALsizei N
BandSplitter splitter;
ALsizei idx[HRTF_AMBI_MAX_CHANNELS];
ALsizei min_delay = HRTF_HISTORY_LENGTH;
ALsizei max_delay = 0;
ALfloat temps[3][HRIR_LENGTH];
ALsizei max_length = 0;
ALsizei i, c, b;
@ -228,8 +229,6 @@ void BuildBFormatHrtf(const struct Hrtf *Hrtf, DirectHrtfState *state, ALsizei N
/* Calculate indices for left and right channels. */
idx[c] = evoffset + azidx;
min_delay = mini(min_delay, mini(Hrtf->delays[idx[c]][0], Hrtf->delays[idx[c]][1]));
}
memset(temps, 0, sizeof(temps));
@ -237,8 +236,12 @@ void BuildBFormatHrtf(const struct Hrtf *Hrtf, DirectHrtfState *state, ALsizei N
for(c = 0;c < AmbiCount;c++)
{
const ALfloat (*fir)[2] = &Hrtf->coeffs[idx[c] * Hrtf->irSize];
ALsizei ldelay = Hrtf->delays[idx[c]][0] - min_delay;
ALsizei rdelay = Hrtf->delays[idx[c]][1] - min_delay;
const ALsizei res_delay = mini(Hrtf->delays[idx[c]][0], Hrtf->delays[idx[c]][1]);
ALsizei ldelay = Hrtf->delays[idx[c]][0] - res_delay;
ALsizei rdelay = Hrtf->delays[idx[c]][1] - res_delay;
min_delay = mini(min_delay, res_delay);
max_delay = maxi(max_delay, res_delay);
max_length = maxi(max_length,
mini(maxi(ldelay, rdelay) + Hrtf->irSize, HRIR_LENGTH)
@ -308,7 +311,8 @@ void BuildBFormatHrtf(const struct Hrtf *Hrtf, DirectHrtfState *state, ALsizei N
max_length += MOD_IR_SIZE-1;
max_length -= max_length%MOD_IR_SIZE;
TRACE("Skipped min delay: %d, new combined length: %d\n", min_delay, max_length);
TRACE("Skipped delay min: %d, max: %d, new FIR length: %d\n", min_delay, max_delay,
max_length);
state->IrSize = max_length;
#undef NUM_BANDS
}