summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/codecs/atrac3_rm.c9
-rw-r--r--apps/codecs/libatrac/atrac3.c46
-rw-r--r--apps/codecs/libatrac/atrac3.h11
-rw-r--r--apps/codecs/libatrac/fixp_math.h58
4 files changed, 64 insertions, 60 deletions
diff --git a/apps/codecs/atrac3_rm.c b/apps/codecs/atrac3_rm.c
index a8610f5764..f3bfa2f801 100644
--- a/apps/codecs/atrac3_rm.c
+++ b/apps/codecs/atrac3_rm.c
@@ -41,7 +41,6 @@ enum codec_status codec_main(void)
41 static size_t buff_size; 41 static size_t buff_size;
42 int datasize, res, consumed, i, time_offset; 42 int datasize, res, consumed, i, time_offset;
43 uint8_t *bit_buffer; 43 uint8_t *bit_buffer;
44 int16_t outbuf[2048] __attribute__((aligned(32)));
45 uint16_t fs,sps,h; 44 uint16_t fs,sps,h;
46 uint32_t packet_count; 45 uint32_t packet_count;
47 int scrambling_unit_size, num_units, elapsed = 0; 46 int scrambling_unit_size, num_units, elapsed = 0;
@@ -62,9 +61,9 @@ next_track:
62 init_rm(&rmctx); 61 init_rm(&rmctx);
63 62
64 ci->configure(DSP_SET_FREQUENCY, ci->id3->frequency); 63 ci->configure(DSP_SET_FREQUENCY, ci->id3->frequency);
65 ci->configure(DSP_SET_SAMPLE_DEPTH, 16); 64 ci->configure(DSP_SET_SAMPLE_DEPTH, 17); /* Remark: atrac3 uses s15.0 by default, s15.2 was hacked. */
66 ci->configure(DSP_SET_STEREO_MODE, rmctx.nb_channels == 1 ? 65 ci->configure(DSP_SET_STEREO_MODE, rmctx.nb_channels == 1 ?
67 STEREO_MONO : STEREO_INTERLEAVED); 66 STEREO_MONO : STEREO_NONINTERLEAVED);
68 67
69 packet_count = rmctx.nb_packets; 68 packet_count = rmctx.nb_packets;
70 rmctx.audio_framesize = rmctx.block_align; 69 rmctx.audio_framesize = rmctx.block_align;
@@ -145,7 +144,7 @@ seek_start :
145 ci->seek_complete(); 144 ci->seek_complete();
146 } 145 }
147 if(pkt.length) 146 if(pkt.length)
148 res = atrac3_decode_frame(&rmctx,&q, outbuf, &datasize, pkt.frames[i], rmctx.block_align); 147 res = atrac3_decode_frame(&rmctx, &q, &datasize, pkt.frames[i], rmctx.block_align);
149 else /* indicates that there are no remaining frames */ 148 else /* indicates that there are no remaining frames */
150 goto done; 149 goto done;
151 150
@@ -155,7 +154,7 @@ seek_start :
155 } 154 }
156 155
157 if(datasize) 156 if(datasize)
158 ci->pcmbuf_insert(outbuf, NULL, q.samples_per_frame / rmctx.nb_channels); 157 ci->pcmbuf_insert(q.outSamples, q.outSamples + 1024, q.samples_per_frame / rmctx.nb_channels);
159 elapsed = rmctx.audiotimestamp+(1000*8*sps/rmctx.bit_rate)*i; 158 elapsed = rmctx.audiotimestamp+(1000*8*sps/rmctx.bit_rate)*i;
160 ci->set_elapsed(elapsed); 159 ci->set_elapsed(elapsed);
161 rmctx.frame_number++; 160 rmctx.frame_number++;
diff --git a/apps/codecs/libatrac/atrac3.c b/apps/codecs/libatrac/atrac3.c
index dd00224e48..cd49aec348 100644
--- a/apps/codecs/libatrac/atrac3.c
+++ b/apps/codecs/libatrac/atrac3.c
@@ -55,18 +55,9 @@
55#define FFMIN(a,b) ((a) > (b) ? (b) : (a)) 55#define FFMIN(a,b) ((a) > (b) ? (b) : (a))
56#define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0) 56#define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0)
57 57
58/**
59 * Clips a signed integer value into the -32768,32767 range.
60 */
61static inline int16_t av_clip_int16(int a)
62{
63 if ((a+32768) & ~65535) return (a>>31) ^ 32767;
64 else return a;
65}
66
67static int32_t qmf_window[48] IBSS_ATTR; 58static int32_t qmf_window[48] IBSS_ATTR;
68static VLC spectral_coeff_tab[7]; 59static VLC spectral_coeff_tab[7];
69static channel_unit channel_units[2]; 60static channel_unit channel_units[2] IBSS_ATTR_LARGE_IRAM;
70 61
71/** 62/**
72 * Matrixing within quadrature mirror synthesis filter. 63 * Matrixing within quadrature mirror synthesis filter.
@@ -516,7 +507,6 @@ static void gainCompensateAndOverlap (int32_t *pIn, int32_t *pPrev, int32_t *pOu
516 int32_t gain1, gain2, gain_inc; 507 int32_t gain1, gain2, gain_inc;
517 int cnt, numdata, nsample, startLoc, endLoc; 508 int cnt, numdata, nsample, startLoc, endLoc;
518 509
519
520 if (pGain2->num_gain_data == 0) 510 if (pGain2->num_gain_data == 0)
521 gain1 = ONE_16; 511 gain1 = ONE_16;
522 else 512 else
@@ -735,7 +725,16 @@ static int decodeChannelSoundUnit (GetBitContext *gb, channel_unit *pSnd, int32_
735 numBands = (subbandTab[numSubbands] - 1) >> 8; 725 numBands = (subbandTab[numSubbands] - 1) >> 8;
736 if (lastTonal >= 0) 726 if (lastTonal >= 0)
737 numBands = FFMAX((lastTonal + 256) >> 8, numBands); 727 numBands = FFMAX((lastTonal + 256) >> 8, numBands);
738 728
729 /* Remark: Hardcoded hack to add 2 bits (empty) fract part to internal sample
730 * representation. Needed for higher accuracy in internal calculations as
731 * well as for DSP configuration. See also: ../atrac3_rm.c, DSP_SET_SAMPLE_DEPTH
732 * Todo: Check spectral requantisation for using and outputting samples with
733 * fract part. */
734 int32_t i;
735 for (i=0; i<1024; ++i) {
736 pSnd->spectrum[i] <<= 2;
737 }
739 738
740 /* Reconstruct time domain samples. */ 739 /* Reconstruct time domain samples. */
741 for (band=0; band<4; band++) { 740 for (band=0; band<4; band++) {
@@ -863,11 +862,9 @@ static int decodeFrame(ATRAC3Context *q, const uint8_t* databuf, int off)
863 */ 862 */
864 863
865int atrac3_decode_frame(RMContext *rmctx, ATRAC3Context *q, 864int atrac3_decode_frame(RMContext *rmctx, ATRAC3Context *q,
866 void *data, int *data_size, 865 int *data_size, const uint8_t *buf, int buf_size) {
867 const uint8_t *buf, int buf_size) { 866 int result = 0, off = 0;
868 int result = 0, off = 0, i;
869 const uint8_t* databuf; 867 const uint8_t* databuf;
870 int16_t* samples = data;
871 868
872 if (buf_size < rmctx->block_align) 869 if (buf_size < rmctx->block_align)
873 return buf_size; 870 return buf_size;
@@ -887,19 +884,10 @@ int atrac3_decode_frame(RMContext *rmctx, ATRAC3Context *q,
887 return -1; 884 return -1;
888 } 885 }
889 886
890 if (q->channels == 1) { 887 if (q->channels == 1)
891 /* mono */ 888 *data_size = 1024 * sizeof(int32_t);
892 for (i = 0; i<1024; i++) 889 else
893 samples[i] = av_clip_int16(q->outSamples[i]); 890 *data_size = 2048 * sizeof(int32_t);
894 *data_size = 1024 * sizeof(int16_t);
895 } else {
896 /* stereo */
897 for (i = 0; i < 1024; i++) {
898 samples[i*2] = av_clip_int16(q->outSamples[i]);
899 samples[i*2+1] = av_clip_int16(q->outSamples[1024+i]);
900 }
901 *data_size = 2048 * sizeof(int16_t);
902 }
903 891
904 return rmctx->block_align; 892 return rmctx->block_align;
905} 893}
diff --git a/apps/codecs/libatrac/atrac3.h b/apps/codecs/libatrac/atrac3.h
index f81fc0a734..a817db2b55 100644
--- a/apps/codecs/libatrac/atrac3.h
+++ b/apps/codecs/libatrac/atrac3.h
@@ -1,6 +1,14 @@
1#include "ffmpeg_bitstream.h" 1#include "ffmpeg_bitstream.h"
2#include "../librm/rm.h" 2#include "../librm/rm.h"
3 3
4#if (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024) || (CONFIG_CPU == MCF5250)
5/* PP5022/24 and MCF5250 have larger IRAM */
6#define IBSS_ATTR_LARGE_IRAM IBSS_ATTR
7#else
8/* other CPUs IRAM is not large enough */
9#define IBSS_ATTR_LARGE_IRAM
10#endif
11
4/* These structures are needed to store the parsed gain control data. */ 12/* These structures are needed to store the parsed gain control data. */
5typedef struct { 13typedef struct {
6 int num_gain_data; 14 int num_gain_data;
@@ -75,6 +83,5 @@ typedef struct {
75int atrac3_decode_init(ATRAC3Context *q, RMContext *rmctx); 83int atrac3_decode_init(ATRAC3Context *q, RMContext *rmctx);
76 84
77int atrac3_decode_frame(RMContext *rmctx, ATRAC3Context *q, 85int atrac3_decode_frame(RMContext *rmctx, ATRAC3Context *q,
78 void *data, int *data_size, 86 int *data_size, const uint8_t *buf, int buf_size);
79 const uint8_t *buf, int buf_size);
80 87
diff --git a/apps/codecs/libatrac/fixp_math.h b/apps/codecs/libatrac/fixp_math.h
index 88cb5e4b66..5174cc7cc6 100644
--- a/apps/codecs/libatrac/fixp_math.h
+++ b/apps/codecs/libatrac/fixp_math.h
@@ -36,17 +36,38 @@
36 : "r"(X),"r"(Y)); \ 36 : "r"(X),"r"(Y)); \
37 low; \ 37 low; \
38 }) 38 })
39 39#elif defined(CPU_COLDFIRE)
40 #define fixmul32(X,Y) \ 40 #define fixmul16(X,Y) \
41 ({ \ 41 ({ \
42 int32_t low; \ 42 int32_t t1, t2; \
43 int32_t high; \ 43 asm volatile ( \
44 asm volatile ( /* calculates: result = (X*Y)>>32 */ \ 44 "mac.l %[x],%[y],%%acc0\n\t" /* multiply */ \
45 "smull %0,%1,%2,%3 \n\t" /* 64 = 32x32 multiply */ \ 45 "mulu.l %[y],%[x] \n\t" /* get lower half, avoid emac stall */ \
46 : "=&r"(low), "=&r" (high) \ 46 "movclr.l %%acc0,%[t1] \n\t" /* get higher half */ \
47 : "r"(X),"r"(Y)); \ 47 "moveq.l #15,%[t2] \n\t" \
48 high; \ 48 "asl.l %[t2],%[t1] \n\t" /* hi <<= 15, plus one free */ \
49 }) 49 "moveq.l #16,%[t2] \n\t" \
50 "lsr.l %[t2],%[x] \n\t" /* (unsigned)lo >>= 16 */ \
51 "or.l %[x],%[t1] \n\t" /* combine result */ \
52 : /* outputs */ \
53 [t1]"=&d"(t1), \
54 [t2]"=&d"(t2) \
55 : /* inputs */ \
56 [x] "d" ((X)), \
57 [y] "d" ((Y))); \
58 t1; \
59 })
60
61 #define fixmul31(X,Y) \
62 ({ \
63 int32_t t; \
64 asm volatile ( \
65 "mac.l %[x], %[y], %%acc0\n\t" /* multiply */ \
66 "movclr.l %%acc0, %[t]\n\t" /* get higher half as result */ \
67 : [t] "=d" (t) \
68 : [x] "r" ((X)), [y] "r" ((Y))); \
69 t; \
70 })
50#else 71#else
51 static inline int32_t fixmul16(int32_t x, int32_t y) 72 static inline int32_t fixmul16(int32_t x, int32_t y)
52 { 73 {
@@ -69,17 +90,6 @@
69 90
70 return (int32_t)temp; 91 return (int32_t)temp;
71 } 92 }
72
73 static inline int32_t fixmul32(int32_t x, int32_t y)
74 {
75 int64_t temp;
76 temp = x;
77 temp *= y;
78
79 temp >>= 32; //16+31-16 = 31 bits
80
81 return (int32_t)temp;
82 }
83#endif 93#endif
84 94
85static inline int32_t fixdiv16(int32_t x, int32_t y) 95static inline int32_t fixdiv16(int32_t x, int32_t y)
@@ -104,13 +114,13 @@ static inline int32_t fastSqrt(int32_t n)
104 /* 114 /*
105 * Logically, these are unsigned. 115 * Logically, these are unsigned.
106 * We need the sign bit to test 116 * We need the sign bit to test
107 * whether (op - res - one) underflowed. 117 * whether (op - res - one) underflowed.
108 */ 118 */
109 int32_t op, res, one; 119 int32_t op, res, one;
110 op = n; 120 op = n;
111 res = 0; 121 res = 0;
112 /* "one" starts at the highest power of four <= than the argument. */ 122 /* "one" starts at the highest power of four <= than the argument. */
113 one = 1 << 30; /* second-to-top bit set */ 123 one = 1 << 30; /* second-to-top bit set */
114 while (one > op) one >>= 2; 124 while (one > op) one >>= 2;
115 while (one != 0) 125 while (one != 0)
116 { 126 {