diff options
author | Chris Robinson <[email protected]> | 2016-08-11 23:20:35 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2016-08-11 23:20:35 -0700 |
commit | c6c6e3324dd9d5d864b6146ca7a6c6e6369978a6 (patch) | |
tree | 15e7062717c5c81be597779698444abb833c84b2 /Alc/panning.c | |
parent | 9a60184bf63640f0b12b9e4a894b98e83212d229 (diff) |
Decode directly from B-Format to HRTF instead of a cube
Last time this attempted to average the HRIRs according to their contribution
to a given B-Format channel as if they were loudspeakers, as well as averaging
the HRIR delays. The latter part resulted in the loss of the ITD (inter-aural
time delay), a key component of HRTF.
This time, the HRIRs are averaged similar to above, except instead of averaging
the delays, they're applied to the resulting coefficients (for example, a delay
of 8 would apply the HRIR starting at the 8th sample of the target HRIR). This
does roughly double the IR length, as the largest delay is about 35 samples
while the filter is normally 32 samples. However, this is still smaller the
original data set IR (which was 256 samples), it also only needs to be applied
to 4 channels for first-order ambisonics, rather than the 8-channel cube. So
it's doing twice as much work per sample, but only working on half the number
of samples.
Additionally, since the resulting HRIRs no longer rely on an extra delay line,
a more efficient HRTF mixing function can be made that doesn't use one. Such a
function can also avoid the per-sample stepping parameters the original uses.
Diffstat (limited to 'Alc/panning.c')
-rw-r--r-- | Alc/panning.c | 61 |
1 files changed, 22 insertions, 39 deletions
diff --git a/Alc/panning.c b/Alc/panning.c index 2d7502ec..65506303 100644 --- a/Alc/panning.c +++ b/Alc/panning.c @@ -758,52 +758,35 @@ static void InitHQPanning(ALCdevice *device, const AmbDecConf *conf, const ALuin static void InitHrtfPanning(ALCdevice *device) { - static const enum Channel CubeChannels[MAX_OUTPUT_CHANNELS] = { - UpperFrontLeft, UpperFrontRight, UpperBackLeft, UpperBackRight, - LowerFrontLeft, LowerFrontRight, LowerBackLeft, LowerBackRight, - InvalidChannel, InvalidChannel, InvalidChannel, InvalidChannel, - InvalidChannel, InvalidChannel, InvalidChannel, InvalidChannel - }; - static const ChannelMap Cube8Cfg[8] = { - { UpperFrontLeft, { 0.176776695f, 0.072168784f, 0.072168784f, 0.072168784f } }, - { UpperFrontRight, { 0.176776695f, 0.072168784f, -0.072168784f, 0.072168784f } }, - { UpperBackLeft, { 0.176776695f, -0.072168784f, 0.072168784f, 0.072168784f } }, - { UpperBackRight, { 0.176776695f, -0.072168784f, -0.072168784f, 0.072168784f } }, - { LowerFrontLeft, { 0.176776695f, 0.072168784f, 0.072168784f, -0.072168784f } }, - { LowerFrontRight, { 0.176776695f, 0.072168784f, -0.072168784f, -0.072168784f } }, - { LowerBackLeft, { 0.176776695f, -0.072168784f, 0.072168784f, -0.072168784f } }, - { LowerBackRight, { 0.176776695f, -0.072168784f, -0.072168784f, -0.072168784f } }, - }; - static const struct { - enum Channel Channel; - ALfloat Angle; - ALfloat Elevation; - } CubeInfo[8] = { - { UpperFrontLeft, DEG2RAD( -45.0f), DEG2RAD( 45.0f) }, - { UpperFrontRight, DEG2RAD( 45.0f), DEG2RAD( 45.0f) }, - { UpperBackLeft, DEG2RAD(-135.0f), DEG2RAD( 45.0f) }, - { UpperBackRight, DEG2RAD( 135.0f), DEG2RAD( 45.0f) }, - { LowerFrontLeft, DEG2RAD( -45.0f), DEG2RAD(-45.0f) }, - { LowerFrontRight, DEG2RAD( 45.0f), DEG2RAD(-45.0f) }, - { LowerBackLeft, DEG2RAD(-135.0f), DEG2RAD(-45.0f) }, - { LowerBackRight, DEG2RAD( 135.0f), DEG2RAD(-45.0f) }, - }; - const ChannelMap *chanmap = Cube8Cfg; - size_t count = COUNTOF(Cube8Cfg); - ALuint i; + ALfloat hrtf_coeffs[4][HRIR_LENGTH][2]; + size_t count = 4; + ALuint i, j; - SetChannelMap(CubeChannels, device->Dry.Ambi.Coeffs, chanmap, count, - &device->Dry.NumChannels, AL_TRUE); - device->Dry.CoeffCount = 4; + for(i = 0;i < count;i++) + { + device->Dry.Ambi.Map[i].Scale = 1.0f; + device->Dry.Ambi.Map[i].Index = i; + } + device->Dry.CoeffCount = 0; + device->Dry.NumChannels = count; device->FOAOut.Ambi = device->Dry.Ambi; device->FOAOut.CoeffCount = device->Dry.CoeffCount; + memset(hrtf_coeffs, 0, sizeof(hrtf_coeffs)); + device->Hrtf_IrSize = BuildBFormatHrtf(device->Hrtf, hrtf_coeffs, device->Dry.NumChannels); + + /* Round up to the nearest multiple of 8 */ + device->Hrtf_IrSize = (device->Hrtf_IrSize+7)&~7; for(i = 0;i < device->Dry.NumChannels;i++) { - int chan = GetChannelIndex(CubeChannels, CubeInfo[i].Channel); - GetLerpedHrtfCoeffs(device->Hrtf, CubeInfo[i].Elevation, CubeInfo[i].Angle, 1.0f, 0.0f, - device->Hrtf_Params[chan].Coeffs, device->Hrtf_Params[chan].Delay); + for(j = 0;j < HRIR_LENGTH;j++) + { + device->Hrtf_Params[i].Coeffs[j][0] = hrtf_coeffs[i][j][0]; + device->Hrtf_Params[i].Coeffs[j][1] = hrtf_coeffs[i][j][1]; + } + device->Hrtf_Params[i].Delay[0] = 0; + device->Hrtf_Params[i].Delay[1] = 0; } } |