summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndree Buschmann <AndreeBuschmann@t-online.de>2010-02-15 13:00:02 +0000
committerAndree Buschmann <AndreeBuschmann@t-online.de>2010-02-15 13:00:02 +0000
commit57461d7c4f612bed0e8cd9644a0689dbfe56d684 (patch)
treef3d574b7f7b9433d3aef18b828c5687993a9ea0f
parent651b55488ef2c35c0b0a17781a466bf14cc1f71a (diff)
downloadrockbox-57461d7c4f612bed0e8cd9644a0689dbfe56d684.tar.gz
rockbox-57461d7c4f612bed0e8cd9644a0689dbfe56d684.zip
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
-rw-r--r--apps/codecs/libatrac/atrac3.c31
-rw-r--r--apps/codecs/libatrac/atrac3data_fixed.h12
-rw-r--r--apps/codecs/libatrac/fixp_math.h43
3 files changed, 34 insertions, 52 deletions
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
628 return lastPos; 628 return lastPos;
629} 629}
630 630
631 631/**
632#define INTERPOLATE(old,new,nsample) ((old*ONE_16) + fixmul16(((nsample*ONE_16)>>3), (((new) - (old))*ONE_16))) 632 * Linear equidistant interpolation between two points x and y. 7 interpolation
633 * points can be calculated. Result is scaled by <<16.
634 * Result for s=0 is x*ONE_16
635 * Result for s=8 is y*ONE_16
636 *
637 * @param x first input point
638 * @param y second input point
639 * @param s index of interpolation point (0..7)
640 */
641
642/*
643#define INTERPOLATE(x, y, s) ((x*ONE_16) + fixmul16(((s*ONE_16)>>3), (((x) - (y))*ONE_16)))
644*/
645#define INTERPOLATE(x, y, s) ((((x)<<3) + s*((y)-(x)))<<13)
633 646
634static void reverseMatrixing(int32_t *su1, int32_t *su2, int *pPrevCode, int *pCurrCode) 647static void reverseMatrixing(int32_t *su1, int32_t *su2, int *pPrevCode, int *pCurrCode)
635{ 648{
@@ -695,14 +708,14 @@ static void reverseMatrixing(int32_t *su1, int32_t *su2, int *pPrevCode, int *pC
695} 708}
696 709
697static void getChannelWeights (int indx, int flag, int32_t ch[2]){ 710static void getChannelWeights (int indx, int flag, int32_t ch[2]){
698 if (indx == 7) { 711 /* Read channel weights from table */
699 ch[0] = ONE_16; 712 if (flag) {
700 ch[1] = ONE_16; 713 /* Swap channel weights */
714 ch[1] = channelWeights0[indx&7];
715 ch[0] = channelWeights1[indx&7];
701 } else { 716 } else {
702 ch[0] = fixdiv16(((indx & 7)*ONE_16), 7*ONE_16); 717 ch[0] = channelWeights0[indx&7];
703 ch[1] = fastSqrt((ONE_16 << 1) - fixmul16(ch[0], ch[0])); 718 ch[1] = channelWeights1[indx&7];
704 if(flag)
705 FFSWAP(int32_t, ch[0], ch[1]);
706 } 719 }
707} 720}
708 721
diff --git a/apps/codecs/libatrac/atrac3data_fixed.h b/apps/codecs/libatrac/atrac3data_fixed.h
index f0924a5190..d73ded35f9 100644
--- a/apps/codecs/libatrac/atrac3data_fixed.h
+++ b/apps/codecs/libatrac/atrac3data_fixed.h
@@ -80,3 +80,15 @@ static const int32_t matrixCoeffs_fix[8] ICONST_ATTR = {
80 0x00000000, 0x00000000, 0x00010000, 0x00010000, 80 0x00000000, 0x00000000, 0x00010000, 0x00010000,
81}; 81};
82 82
83/* channelWeights0[i] = ONE_16 * ((i & 7)/7) */
84static const int32_t channelWeights0[8] ICONST_ATTR = {
85 0x00000000, 0x00002492, 0x00004925, 0x00006DB7,
86 0x00009249, 0x0000B6DB, 0x0000DB6D, 0x00010000,
87};
88
89/* channelWeights1[i] = ONE_16 * sqrt(2-channelWeights0^2) */
90static const int32_t channelWeights1[8] ICONST_ATTR = {
91 0x00016A0A, 0x00016830, 0x00016293, 0x00015904,
92 0x00014B2B, 0x00013877, 0x00011FF7, 0x00010000,
93};
94
diff --git a/apps/codecs/libatrac/fixp_math.h b/apps/codecs/libatrac/fixp_math.h
index 5174cc7cc6..29d47a9e53 100644
--- a/apps/codecs/libatrac/fixp_math.h
+++ b/apps/codecs/libatrac/fixp_math.h
@@ -91,46 +91,3 @@
91 return (int32_t)temp; 91 return (int32_t)temp;
92 } 92 }
93#endif 93#endif
94
95static inline int32_t fixdiv16(int32_t x, int32_t y)
96{
97 int64_t temp;
98 temp = x << 16;
99 temp /= y;
100
101 return (int32_t)temp;
102}
103
104/*
105 * Fast integer square root adapted from algorithm,
106 * Martin Guy @ UKC, June 1985.
107 * Originally from a book on programming abaci by Mr C. Woo.
108 * This is taken from :
109 * http://wiki.forum.nokia.com/index.php/How_to_use_fixed_point_maths#How_to_get_square_root_for_integers
110 * with a added shift up of the result by 8 bits to return result in 16.16 fixed-point representation.
111 */
112static inline int32_t fastSqrt(int32_t n)
113{
114 /*
115 * Logically, these are unsigned.
116 * We need the sign bit to test
117 * whether (op - res - one) underflowed.
118 */
119 int32_t op, res, one;
120 op = n;
121 res = 0;
122 /* "one" starts at the highest power of four <= than the argument. */
123 one = 1 << 30; /* second-to-top bit set */
124 while (one > op) one >>= 2;
125 while (one != 0)
126 {
127 if (op >= res + one)
128 {
129 op = op - (res + one);
130 res = res + (one<<1);
131 }
132 res >>= 1;
133 one >>= 2;
134 }
135 return(res << 8);
136}