From 859cc703e75c2699531f041ccd3e8169d44bea50 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 10 Mar 2016 22:56:44 -0800 Subject: [PATCH] Use the proper left and right channels for UHJ output --- Alc/ALu.c | 13 ++++++++++--- Alc/uhjfilter.c | 6 +++--- Alc/uhjfilter.h | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Alc/ALu.c b/Alc/ALu.c index eb7afd90..17c91e52 100644 --- a/Alc/ALu.c +++ b/Alc/ALu.c @@ -1473,9 +1473,16 @@ ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size) { if(device->Uhj_Encoder) { - /* Encode to stereo-compatible 2-channel UHJ output. */ - EncodeUhj2(device->Uhj_Encoder, device->RealOut.Buffer, - device->VirtOut.Buffer, SamplesToDo); + int lidx = GetChannelIdxByName(device->RealOut, FrontLeft); + int ridx = GetChannelIdxByName(device->RealOut, FrontRight); + if(lidx != -1 && ridx != -1) + { + /* Encode to stereo-compatible 2-channel UHJ output. */ + EncodeUhj2(device->Uhj_Encoder, + device->RealOut.Buffer[lidx], device->RealOut.Buffer[ridx], + device->VirtOut.Buffer, SamplesToDo + ); + } } if(device->Bs2b) { diff --git a/Alc/uhjfilter.c b/Alc/uhjfilter.c index b410967a..4a71287f 100644 --- a/Alc/uhjfilter.c +++ b/Alc/uhjfilter.c @@ -36,7 +36,7 @@ static const ALfloat Filter2Coeff[4] = { * know which is the intended result. */ -void EncodeUhj2(Uhj2Encoder *enc, ALfloat (*restrict OutBuffer)[BUFFERSIZE], ALfloat (*restrict InSamples)[BUFFERSIZE], ALuint SamplesToDo) +void EncodeUhj2(Uhj2Encoder *enc, ALfloat *restrict LeftOut, ALfloat *restrict RightOut, ALfloat (*restrict InSamples)[BUFFERSIZE], ALuint SamplesToDo) { ALuint base, i, c; @@ -103,10 +103,10 @@ void EncodeUhj2(Uhj2Encoder *enc, ALfloat (*restrict OutBuffer)[BUFFERSIZE], ALf /* Left = (S + D)/2.0 */ for(i = 0;i < todo;i++) - OutBuffer[0][base + i] += (S[i] + D[i]) * 0.5f; + *(LeftOut++) += (S[i] + D[i]) * 0.5f; /* Right = (S - D)/2.0 */ for(i = 0;i < todo;i++) - OutBuffer[1][base + i] += (S[i] - D[i]) * 0.5f; + *(RightOut++) += (S[i] - D[i]) * 0.5f; base += todo; } diff --git a/Alc/uhjfilter.h b/Alc/uhjfilter.h index a5aa9275..14572bc3 100644 --- a/Alc/uhjfilter.h +++ b/Alc/uhjfilter.h @@ -43,6 +43,6 @@ typedef struct Uhj2Encoder { /* Encodes a 2-channel UHJ (stereo-compatible) signal from a B-Format input * signal. */ -void EncodeUhj2(Uhj2Encoder *enc, ALfloat (*restrict OutBuffer)[BUFFERSIZE], ALfloat (*restrict InSamples)[BUFFERSIZE], ALuint SamplesToDo); +void EncodeUhj2(Uhj2Encoder *enc, ALfloat *restrict LeftOut, ALfloat *restrict RightOut, ALfloat (*restrict InSamples)[BUFFERSIZE], ALuint SamplesToDo); #endif /* UHJFILTER_H */ -- 2.11.4.GIT