From a73b64ce3c7bffa8a9a97f517bcce7b7604f44a3 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 28 Nov 2021 05:21:33 -0800 Subject: Slight update to the UHJ coefficients The extended precision of the encoder's 0.6512*X term was guesswork, with no real basis for it. Switch back to the original value until something better actually comes up. Also updates the decoder to account for the change in the encoder. --- utils/uhjdecoder.cpp | 66 ++++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) (limited to 'utils/uhjdecoder.cpp') diff --git a/utils/uhjdecoder.cpp b/utils/uhjdecoder.cpp index 4c45afd7..7bb1a51a 100644 --- a/utils/uhjdecoder.cpp +++ b/utils/uhjdecoder.cpp @@ -141,9 +141,9 @@ const PhaseShifterT PShift{}; * S = Left + Right * D = Left - Right * - * W = 0.981530*S + 0.197484*j(0.828347*D + 0.767835*T) - * X = 0.418504*S - j(0.828347*D + 0.767835*T) - * Y = 0.795954*D - 0.676406*T + j(0.186626*S) + * W = 0.981532*S + 0.197484*j(0.828331*D + 0.767820*T) + * X = 0.418496*S - j(0.828331*D + 0.767820*T) + * Y = 0.795968*D - 0.676392*T + j(0.186633*S) * Z = 1.023332*Q * * where j is a +90 degree phase shift. 3-channel UHJ excludes Q, while 2- @@ -162,49 +162,49 @@ const PhaseShifterT PShift{}; * Gerzon's original paper for deriving Sigma (S) or Delta (D) from the L and R * signals. As proof, taking Y for example: * - * Y = 0.795954*D - 0.676406*T + j(0.186626*S) + * Y = 0.795968*D - 0.676392*T + j(0.186633*S) * * * Plug in the encoding parameters, using ? as a placeholder for whether S * and D should receive an extra 0.5 factor - * Y = 0.795954*(j(-0.3420201*W + 0.5098604*X) + 0.6554516*Y)*? - - * 0.676406*(j(-0.1432*W + 0.6511746*X) - 0.7071068*Y) + - * 0.186626*j(0.9396926*W + 0.1855740*X)*? + * Y = 0.795968*(j(-0.3420201*W + 0.5098604*X) + 0.6554516*Y)*? - + * 0.676392*(j(-0.1432*W + 0.6512*X) - 0.7071068*Y) + + * 0.186633*j(0.9396926*W + 0.1855740*X)*? * * * Move common factors in - * Y = (j(-0.3420201*0.795954*?*W + 0.5098604*0.795954*?*X) + 0.6554516*0.795954*?*Y) - - * (j(-0.1432*0.676406*W + 0.6511746*0.676406*X) - 0.7071068*0.676406*Y) + - * j(0.9396926*0.186626*?*W + 0.1855740*0.186626*?*X) + * Y = (j(-0.3420201*0.795968*?*W + 0.5098604*0.795968*?*X) + 0.6554516*0.795968*?*Y) - + * (j(-0.1432*0.676392*W + 0.6512*0.676392*X) - 0.7071068*0.676392*Y) + + * j(0.9396926*0.186633*?*W + 0.1855740*0.186633*?*X) * * * Clean up extraneous groupings - * Y = j(-0.3420201*0.795954*?*W + 0.5098604*0.795954*?*X) + 0.6554516*0.795954*?*Y - - * j(-0.1432*0.676406*W + 0.6511746*0.676406*X) + 0.7071068*0.676406*Y + - * j*(0.9396926*0.186626*?*W + 0.1855740*0.186626*?*X) + * Y = j(-0.3420201*0.795968*?*W + 0.5098604*0.795968*?*X) + 0.6554516*0.795968*?*Y - + * j(-0.1432*0.676392*W + 0.6512*0.676392*X) + 0.7071068*0.676392*Y + + * j*(0.9396926*0.186633*?*W + 0.1855740*0.186633*?*X) * * * Move phase shifts together and combine them - * Y = j(-0.3420201*0.795954*?*W + 0.5098604*0.795954*?*X - -0.1432*0.676406*W - - * 0.6511746*0.676406*X + 0.9396926*0.186626*?*W + 0.1855740*0.186626*?*X) + - * 0.6554516*0.795954*?*Y + 0.7071068*0.676406*Y + * Y = j(-0.3420201*0.795968*?*W + 0.5098604*0.795968*?*X - -0.1432*0.676392*W - + * 0.6512*0.676392*X + 0.9396926*0.186633*?*W + 0.1855740*0.186633*?*X) + + * 0.6554516*0.795968*?*Y + 0.7071068*0.676392*Y * * * Reorder terms - * Y = j(-0.3420201*0.795954*?*W + 0.1432*0.676406*W + 0.9396926*0.186626*?*W + - * 0.5098604*0.795954*?*X + -0.6511746*0.676406*X + 0.1855740*0.186626*?*X) + - * 0.7071068*0.676406*Y + 0.6554516*0.795954*?*Y + * Y = j(-0.3420201*0.795968*?*W + 0.1432*0.676392*W + 0.9396926*0.186633*?*W + + * 0.5098604*0.795968*?*X + -0.6512*0.676392*X + 0.1855740*0.186633*?*X) + + * 0.7071068*0.676392*Y + 0.6554516*0.795968*?*Y * * * Move common factors out - * Y = j((-0.3420201*0.795954*? + 0.1432*0.676406 + 0.9396926*0.186626*?)*W + - * ( 0.5098604*0.795954*? + -0.6511746*0.676406 + 0.1855740*0.186626*?)*X) + - * (0.7071068*0.676406 + 0.6554516*0.795954*?)*Y + * Y = j((-0.3420201*0.795968*? + 0.1432*0.676392 + 0.9396926*0.186633*?)*W + + * ( 0.5098604*0.795968*? + -0.6512*0.676392 + 0.1855740*0.186633*?)*X) + + * (0.7071068*0.676392 + 0.6554516*0.795968*?)*Y * * * Result w/ 0.5 factor: - * -0.3420201*0.795954*0.5 + 0.1432*0.676406 + 0.9396926*0.186626*0.5 = 0.04843*W - * 0.5098604*0.795954*0.5 + -0.6511746*0.676406 + 0.1855740*0.186626*0.5 = -0.22023*X - * 0.7071068*0.676406 + 0.6554516*0.795954*0.5 = 0.73915*Y - * -> Y = j(0.04843*W + -0.22023*X) + 0.73915*Y + * -0.3420201*0.795968*0.5 + 0.1432*0.676392 + 0.9396926*0.186633*0.5 = 0.04843*W + * 0.5098604*0.795968*0.5 + -0.6512*0.676392 + 0.1855740*0.186633*0.5 = -0.22023*X + * 0.7071068*0.676392 + 0.6554516*0.795968*0.5 = 0.73914*Y + * -> Y = j(0.04843*W + -0.22023*X) + 0.73914*Y * * * Result w/o 0.5 factor: - * -0.3420201*0.795954 + 0.1432*0.676406 + 0.9396926*0.186626 = 0.00000*W - * 0.5098604*0.795954 + -0.6511746*0.676406 + 0.1855740*0.186626 = 0.00000*X - * 0.7071068*0.676406 + 0.6554516*0.795954 = 1.00000*Y + * -0.3420201*0.795968 + 0.1432*0.676392 + 0.9396926*0.186633 = 0.00000*W + * 0.5098604*0.795968 + -0.6512*0.676392 + 0.1855740*0.186633 = 0.00000*X + * 0.7071068*0.676392 + 0.6554516*0.795968 = 1.00000*Y * -> Y = j(0.00000*W + 0.00000*X) + 1.00000*Y * * Not halving produces a result matching the original input. @@ -252,8 +252,8 @@ void UhjDecoder::decode(const float *RESTRICT InSamples, const size_t InChannels for(size_t i{0};i < SamplesToDo;++i) { - /* W = 0.981530*S + 0.197484*j(0.828347*D + 0.767835*T) */ - woutput[i] = 0.981530f*mS[i] + 0.197484f*xoutput[i]; + /* W = 0.981532*S + 0.197484*j(0.828347*D + 0.767835*T) */ + woutput[i] = 0.981532f*mS[i] + 0.197484f*xoutput[i]; /* X = 0.418504*S - j(0.828347*D + 0.767835*T) */ xoutput[i] = 0.418504f*mS[i] - xoutput[i]; } @@ -266,8 +266,8 @@ void UhjDecoder::decode(const float *RESTRICT InSamples, const size_t InChannels for(size_t i{0};i < SamplesToDo;++i) { - /* Y = 0.795954*D - 0.676406*T + j(0.186626*S) */ - youtput[i] = 0.795954f*mD[i] - 0.676406f*mT[i] + 0.186626f*youtput[i]; + /* Y = 0.795968*D - 0.676392*T + j(0.186633*S) */ + youtput[i] = 0.795968f*mD[i] - 0.676392f*mT[i] + 0.186633f*youtput[i]; } if(OutSamples.size() > 3) -- cgit v1.2.3