diff options
-rw-r--r-- | Alc/hrtf.c | 38 |
1 files changed, 19 insertions, 19 deletions
@@ -204,8 +204,9 @@ void BuildBFormatHrtf(const struct Hrtf *Hrtf, DirectHrtfState *state, ALsizei N ALdouble (*tmpres)[HRIR_LENGTH][2]; 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 max_length; ALsizei i, c, b; for(c = 0;c < AmbiCount;c++) @@ -228,6 +229,7 @@ void BuildBFormatHrtf(const struct Hrtf *Hrtf, DirectHrtfState *state, ALsizei N idx[c] = evoffset + azidx; min_delay = mini(min_delay, mini(Hrtf->delays[idx[c]][0], Hrtf->delays[idx[c]][1])); + max_delay = maxi(max_delay, maxi(Hrtf->delays[idx[c]][0], Hrtf->delays[idx[c]][1])); } tmpres = al_calloc(16, NumChannels * sizeof(*tmpres)); @@ -242,10 +244,6 @@ void BuildBFormatHrtf(const struct Hrtf *Hrtf, DirectHrtfState *state, ALsizei N if(NUM_BANDS == 1) { - max_length = maxi(max_length, - mini(maxi(ldelay, rdelay) + Hrtf->irSize, HRIR_LENGTH) - ); - for(i = 0;i < NumChannels;++i) { ALdouble mult = (ALdouble)AmbiOrderHFGain[(ALsizei)sqrt(i)] * AmbiMatrix[c][i]; @@ -261,15 +259,6 @@ void BuildBFormatHrtf(const struct Hrtf *Hrtf, DirectHrtfState *state, ALsizei N } else { - /* Increase the IR size by 2/3rds to account for the tail generated - * by the band-split filter. - */ - const ALsizei irsize = mini(Hrtf->irSize*5/3, HRIR_LENGTH); - - max_length = maxi(max_length, - mini(maxi(ldelay, rdelay) + irsize, HRIR_LENGTH) - ); - /* Band-split left HRIR into low and high frequency responses. */ bandsplit_clear(&splitter); for(i = 0;i < Hrtf->irSize;i++) @@ -311,9 +300,6 @@ void BuildBFormatHrtf(const struct Hrtf *Hrtf, DirectHrtfState *state, ALsizei N } } } - /* Round up to the next IR size multiple. */ - max_length += MOD_IR_SIZE-1; - max_length -= max_length%MOD_IR_SIZE; for(i = 0;i < NumChannels;++i) { @@ -324,11 +310,25 @@ void BuildBFormatHrtf(const struct Hrtf *Hrtf, DirectHrtfState *state, ALsizei N state->Chan[i].Coeffs[idx][1] = (ALfloat)tmpres[i][idx][1]; } } - al_free(tmpres); tmpres = NULL; - TRACE("Skipped delay: %d, new FIR length: %d\n", min_delay, max_length); + if(NUM_BANDS == 1) + max_length = mini(max_delay-min_delay + Hrtf->irSize, HRIR_LENGTH); + else + { + /* Increase the IR size by 2/3rds to account for the tail generated by + * the band-split filter. + */ + const ALsizei irsize = mini(Hrtf->irSize*5/3, HRIR_LENGTH); + max_length = mini(max_delay-min_delay + irsize, HRIR_LENGTH); + } + /* Round up to the next IR size multiple. */ + max_length += MOD_IR_SIZE-1; + max_length -= max_length%MOD_IR_SIZE; + + TRACE("Skipped delay: %d, max delay: %d, new FIR length: %d\n", + min_delay, max_delay-min_delay, max_length); state->IrSize = max_length; #undef NUM_BANDS } |