From 57461d7c4f612bed0e8cd9644a0689dbfe56d684 Mon Sep 17 00:00:00 2001 From: Andree Buschmann Date: Mon, 15 Feb 2010 13:00:02 +0000 Subject: Work on atrac Joint Stereo mode. Correct calculation in getChannelWeights(), introduce lookup table and remove obsolete code. Optimize interpolation macro. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24665 a1c6a512-1295-4272-9138-f99709370657 --- apps/codecs/libatrac/atrac3.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'apps/codecs/libatrac/atrac3.c') diff --git a/apps/codecs/libatrac/atrac3.c b/apps/codecs/libatrac/atrac3.c index 467f42f161..5ff3a8587b 100644 --- a/apps/codecs/libatrac/atrac3.c +++ b/apps/codecs/libatrac/atrac3.c @@ -628,8 +628,21 @@ static int addTonalComponents (int32_t *pSpectrum, int numComponents, tonal_comp return lastPos; } - -#define INTERPOLATE(old,new,nsample) ((old*ONE_16) + fixmul16(((nsample*ONE_16)>>3), (((new) - (old))*ONE_16))) +/** + * Linear equidistant interpolation between two points x and y. 7 interpolation + * points can be calculated. Result is scaled by <<16. + * Result for s=0 is x*ONE_16 + * Result for s=8 is y*ONE_16 + * + * @param x first input point + * @param y second input point + * @param s index of interpolation point (0..7) + */ + +/* +#define INTERPOLATE(x, y, s) ((x*ONE_16) + fixmul16(((s*ONE_16)>>3), (((x) - (y))*ONE_16))) +*/ +#define INTERPOLATE(x, y, s) ((((x)<<3) + s*((y)-(x)))<<13) static void reverseMatrixing(int32_t *su1, int32_t *su2, int *pPrevCode, int *pCurrCode) { @@ -695,14 +708,14 @@ static void reverseMatrixing(int32_t *su1, int32_t *su2, int *pPrevCode, int *pC } static void getChannelWeights (int indx, int flag, int32_t ch[2]){ - if (indx == 7) { - ch[0] = ONE_16; - ch[1] = ONE_16; + /* Read channel weights from table */ + if (flag) { + /* Swap channel weights */ + ch[1] = channelWeights0[indx&7]; + ch[0] = channelWeights1[indx&7]; } else { - ch[0] = fixdiv16(((indx & 7)*ONE_16), 7*ONE_16); - ch[1] = fastSqrt((ONE_16 << 1) - fixmul16(ch[0], ch[0])); - if(flag) - FFSWAP(int32_t, ch[0], ch[1]); + ch[0] = channelWeights0[indx&7]; + ch[1] = channelWeights1[indx&7]; } } -- cgit v1.2.3