diff options
author | Chris Robinson <[email protected]> | 2016-03-01 13:37:12 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2016-03-01 15:48:23 -0800 |
commit | 9fdca9e29f15e05c26d9b80ec4ba97a34b7b5277 (patch) | |
tree | 7a9556607fbe3fc08f8569fdef521a3b875f2f75 | |
parent | c89511b95e6e6920c3be3086c98463284090de65 (diff) |
Remove the extra scaling on W for UHJ encoding
There seems to be some inconsistent info about whether W should be scaled by
sqrt(2) for encoding. Not applying the scaling results in a wider stereo image,
which seems more appropriate.
-rw-r--r-- | Alc/uhjfilter.c | 33 | ||||
-rw-r--r-- | Alc/uhjfilter.h | 5 |
2 files changed, 28 insertions, 10 deletions
diff --git a/Alc/uhjfilter.c b/Alc/uhjfilter.c index cb1a4348..b410967a 100644 --- a/Alc/uhjfilter.c +++ b/Alc/uhjfilter.c @@ -16,6 +16,26 @@ static const ALfloat Filter2Coeff[4] = { 0.4021921162426f, 0.8561710882420f, 0.9722909545651f, 0.9952884791278f }; +/* NOTE: There seems to be a bit of an inconsistency in how this encoding is + * supposed to work. Some references, such as + * + * http://members.tripod.com/martin_leese/Ambisonic/UHJ_file_format.html + * + * specify a pre-scaling of sqrt(2) on the W channel input, while other + * references, such as + * + * https://en.wikipedia.org/wiki/Ambisonic_UHJ_format#Encoding.5B1.5D + * and + * https://wiki.xiph.org/Ambisonics#UHJ_format + * + * do not. The sqrt(2) scaling is in line with B-Format decoder coefficients + * which include such a scaling for the W channel input, however the original + * source for this equation is a 1985 paper by Michael Gerzon, which does not + * apparently include the scaling. Applying the extra scaling creates a louder + * result with a narrower stereo image compared to not scaling, and I don't + * know which is the intended result. + */ + void EncodeUhj2(Uhj2Encoder *enc, ALfloat (*restrict OutBuffer)[BUFFERSIZE], ALfloat (*restrict InSamples)[BUFFERSIZE], ALuint SamplesToDo) { ALuint base, i, c; @@ -45,10 +65,10 @@ void EncodeUhj2(Uhj2Encoder *enc, ALfloat (*restrict OutBuffer)[BUFFERSIZE], ALf D[i] = enc->Filter1_Y[3].y[1]; } - /* D += j(-0.3420201*W' + 0.5098604*X) */ + /* D += j(-0.3420201*W + 0.5098604*X) */ for(i = 0;i < todo;i++) { - ALfloat in = -0.3420201f*1.414213562f*InSamples[0][base+i] + + ALfloat in = -0.3420201f*InSamples[0][base+i] + 0.5098604f*InSamples[1][base+i]; for(c = 0;c < 4;c++) { @@ -63,10 +83,10 @@ void EncodeUhj2(Uhj2Encoder *enc, ALfloat (*restrict OutBuffer)[BUFFERSIZE], ALf D[i] += enc->Filter2_WX[3].y[0]; } - /* S = 0.9396926*W' + 0.1855740*X */ + /* S = 0.9396926*W + 0.1855740*X */ for(i = 0;i < todo;i++) { - ALfloat in = 0.9396926f*1.414213562f*InSamples[0][base+i] + + ALfloat in = 0.9396926f*InSamples[0][base+i] + 0.1855740f*InSamples[1][base+i]; for(c = 0;c < 4;c++) { @@ -81,11 +101,10 @@ void EncodeUhj2(Uhj2Encoder *enc, ALfloat (*restrict OutBuffer)[BUFFERSIZE], ALf S[i] = enc->Filter1_WX[3].y[1]; } - /* Left = (S + D)/2.0 - * Right = (S - D)/2.0 - */ + /* Left = (S + D)/2.0 */ for(i = 0;i < todo;i++) OutBuffer[0][base + i] += (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; diff --git a/Alc/uhjfilter.h b/Alc/uhjfilter.h index 5238e202..a5aa9275 100644 --- a/Alc/uhjfilter.h +++ b/Alc/uhjfilter.h @@ -12,9 +12,8 @@ typedef struct AllPassState { /* Encoding 2-channel UHJ from B-Format is done as: * - * W' = W * sqrt(2) - * S = 0.9396926*W' + 0.1855740*X - * D = j(-0.3420201*W' + 0.5098604*X) + 0.6554516*Y + * S = 0.9396926*W + 0.1855740*X + * D = j(-0.3420201*W + 0.5098604*X) + 0.6554516*Y * * Left = (S + D)/2.0 * Right = (S - D)/2.0 |