summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/codecs/SOURCES1
-rw-r--r--apps/codecs/atrac3_rm.c173
-rw-r--r--apps/codecs/codecs.make3
-rw-r--r--apps/codecs/libatrac/SOURCES3
-rw-r--r--apps/codecs/libatrac/atrac3.c25
-rw-r--r--apps/codecs/libatrac/atrac3data.h2
-rw-r--r--apps/codecs/libatrac/libatrac.make18
-rw-r--r--apps/metadata.c3
-rw-r--r--apps/metadata.h1
-rw-r--r--apps/metadata/rm.c10
10 files changed, 227 insertions, 12 deletions
diff --git a/apps/codecs/SOURCES b/apps/codecs/SOURCES
index 4e6c891d9a..75d74ab33b 100644
--- a/apps/codecs/SOURCES
+++ b/apps/codecs/SOURCES
@@ -12,6 +12,7 @@ alac.c
12cook.c 12cook.c
13raac.c 13raac.c
14a52_rm.c 14a52_rm.c
15atrac3_rm.c
15mpc.c 16mpc.c
16wma.c 17wma.c
17sid.c 18sid.c
diff --git a/apps/codecs/atrac3_rm.c b/apps/codecs/atrac3_rm.c
new file mode 100644
index 0000000000..a9c1c49fea
--- /dev/null
+++ b/apps/codecs/atrac3_rm.c
@@ -0,0 +1,173 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * Copyright (C) 2009 Mohamed Tarek
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include <string.h>
21
22#include "logf.h"
23#include "codeclib.h"
24#include "inttypes.h"
25#include "libatrac/atrac3.h"
26
27CODEC_HEADER
28
29RMContext rmctx;
30RMPacket pkt;
31ATRAC3Context q;
32
33static void init_rm(RMContext *rmctx)
34{
35 memcpy(rmctx, (void*)(( (intptr_t)ci->id3->id3v2buf + 3 ) &~ 3), sizeof(RMContext));
36}
37
38/* this is the codec entry point */
39enum codec_status codec_main(void)
40{
41 static size_t buff_size;
42 int datasize, res, consumed, i, time_offset;
43 uint8_t *bit_buffer;
44 int16_t outbuf[2048] __attribute__((aligned(32)));
45 uint16_t fs,sps,h;
46 uint32_t packet_count;
47 int scrambling_unit_size, num_units, elapsed = 0;
48
49next_track:
50 if (codec_init()) {
51 DEBUGF("codec init failed\n");
52 return CODEC_ERROR;
53 }
54 while (!*ci->taginfo_ready && !ci->stop_codec)
55 ci->sleep(1);
56
57 codec_set_replaygain(ci->id3);
58 ci->memset(&rmctx,0,sizeof(RMContext));
59 ci->memset(&pkt,0,sizeof(RMPacket));
60 ci->memset(&q,0,sizeof(ATRAC3Context));
61
62 init_rm(&rmctx);
63
64 ci->configure(DSP_SET_FREQUENCY, ci->id3->frequency);
65 ci->configure(DSP_SET_SAMPLE_DEPTH, 16);
66 ci->configure(DSP_SET_STEREO_MODE, rmctx.nb_channels == 1 ?
67 STEREO_MONO : STEREO_INTERLEAVED);
68
69 packet_count = rmctx.nb_packets;
70 rmctx.audio_framesize = rmctx.block_align;
71 rmctx.block_align = rmctx.sub_packet_size;
72 fs = rmctx.audio_framesize;
73 sps= rmctx.block_align;
74 h = rmctx.sub_packet_h;
75 scrambling_unit_size = h*fs;
76
77 res =atrac3_decode_init(&q, &rmctx);
78 if(res < 0) {
79 DEBUGF("failed to initialize atrac decoder\n");
80 return CODEC_ERROR;
81 }
82
83 ci->set_elapsed(0);
84 ci->advance_buffer(rmctx.data_offset + DATA_HEADER_SIZE);
85
86 /* The main decoder loop */
87seek_start :
88 while((unsigned)elapsed < rmctx.duration)
89 {
90 bit_buffer = (uint8_t *) ci->request_buffer(&buff_size, scrambling_unit_size);
91 consumed = rm_get_packet(&bit_buffer, &rmctx, &pkt);
92 if(consumed < 0) {
93 DEBUGF("rm_get_packet failed\n");
94 return CODEC_ERROR;
95 }
96
97 for(i = 0; i < rmctx.audio_pkt_cnt*(fs/sps) ; i++)
98 {
99 ci->yield();
100 if (ci->stop_codec || ci->new_track)
101 goto done;
102
103 if (ci->seek_time) {
104 ci->set_elapsed(ci->seek_time);
105
106 /* Do not allow seeking beyond the file's length */
107 if ((unsigned) ci->seek_time > ci->id3->length) {
108 ci->seek_complete();
109 goto done;
110 }
111
112 ci->seek_buffer(rmctx.data_offset + DATA_HEADER_SIZE);
113 packet_count = rmctx.nb_packets;
114 rmctx.audio_pkt_cnt = 0;
115 rmctx.frame_number = 0;
116
117 /* Seek to the start of the track */
118 if (ci->seek_time == 1) {
119 ci->set_elapsed(0);
120 ci->seek_complete();
121 goto seek_start;
122 }
123 num_units = ((ci->seek_time)/(sps*1000*8/rmctx.bit_rate))/(h*(fs/sps));
124 ci->seek_buffer(rmctx.data_offset + DATA_HEADER_SIZE + consumed * num_units);
125 bit_buffer = (uint8_t *) ci->request_buffer(&buff_size, scrambling_unit_size);
126 consumed = rm_get_packet(&bit_buffer, &rmctx, &pkt);
127 if(consumed < 0) {
128 DEBUGF("rm_get_packet failed\n");
129 return CODEC_ERROR;
130 }
131 packet_count = rmctx.nb_packets - rmctx.audio_pkt_cnt * num_units;
132 rmctx.frame_number = ((ci->seek_time)/(sps*1000*8/rmctx.bit_rate));
133 while(rmctx.audiotimestamp > (unsigned) ci->seek_time) {
134 rmctx.audio_pkt_cnt = 0;
135 ci->seek_buffer(rmctx.data_offset + DATA_HEADER_SIZE + consumed * (num_units-1));
136 bit_buffer = (uint8_t *) ci->request_buffer(&buff_size, scrambling_unit_size);
137 consumed = rm_get_packet(&bit_buffer, &rmctx, &pkt);
138 packet_count += rmctx.audio_pkt_cnt;
139 num_units--;
140 }
141 time_offset = ci->seek_time - rmctx.audiotimestamp;
142 i = (time_offset/((sps * 8 * 1000)/rmctx.bit_rate));
143 elapsed = rmctx.audiotimestamp+(1000*8*sps/rmctx.bit_rate)*i;
144 ci->set_elapsed(elapsed);
145 ci->seek_complete();
146 }
147 if(pkt.length)
148 res = atrac3_decode_frame(&rmctx,&q, outbuf, &datasize, pkt.frames[i], rmctx.block_align);
149 else /* indicates that there are no remaining frames */
150 goto done;
151
152 if(res != rmctx.block_align) {
153 DEBUGF("codec error\n");
154 return CODEC_ERROR;
155 }
156
157 if(datasize)
158 ci->pcmbuf_insert(outbuf, NULL, q.samples_per_frame / rmctx.nb_channels);
159 elapsed = rmctx.audiotimestamp+(1000*8*sps/rmctx.bit_rate)*i;
160 ci->set_elapsed(elapsed);
161 rmctx.frame_number++;
162 }
163 packet_count -= rmctx.audio_pkt_cnt;
164 rmctx.audio_pkt_cnt = 0;
165 ci->advance_buffer(consumed);
166 }
167
168 done :
169 if (ci->request_next_track())
170 goto next_track;
171
172 return CODEC_OK;
173}
diff --git a/apps/codecs/codecs.make b/apps/codecs/codecs.make
index ba5f0ed8a3..85c10158d7 100644
--- a/apps/codecs/codecs.make
+++ b/apps/codecs/codecs.make
@@ -35,6 +35,7 @@ include $(APPSDIR)/codecs/libwavpack/libwavpack.make
35include $(APPSDIR)/codecs/libwma/libwma.make 35include $(APPSDIR)/codecs/libwma/libwma.make
36include $(APPSDIR)/codecs/libcook/libcook.make 36include $(APPSDIR)/codecs/libcook/libcook.make
37include $(APPSDIR)/codecs/librm/librm.make 37include $(APPSDIR)/codecs/librm/librm.make
38include $(APPSDIR)/codecs/libatrac/libatrac.make
38 39
39# compile flags for codecs 40# compile flags for codecs
40CODECFLAGS = $(CFLAGS) -I$(APPSDIR)/codecs -I$(APPSDIR)/codecs/lib \ 41CODECFLAGS = $(CFLAGS) -I$(APPSDIR)/codecs -I$(APPSDIR)/codecs/lib \
@@ -50,6 +51,7 @@ CODEC_CRT0 := $(CODECDIR)/codec_crt0.o
50CODECLIBS := $(DEMACLIB) $(A52LIB) $(ALACLIB) $(ASAPLIB) \ 51CODECLIBS := $(DEMACLIB) $(A52LIB) $(ALACLIB) $(ASAPLIB) \
51 $(FAADLIB) $(FFMPEGFLACLIB) $(M4ALIB) $(MADLIB) $(MUSEPACKLIB) \ 52 $(FAADLIB) $(FFMPEGFLACLIB) $(M4ALIB) $(MADLIB) $(MUSEPACKLIB) \
52 $(SPCLIB) $(SPEEXLIB) $(TREMORLIB) $(WAVPACKLIB) $(WMALIB) $(COOKLIB) \ 53 $(SPCLIB) $(SPEEXLIB) $(TREMORLIB) $(WAVPACKLIB) $(WMALIB) $(COOKLIB) \
54 $(ATRACLIB) \
53 $(CODECLIB) 55 $(CODECLIB)
54 56
55$(CODECS): $(CODEC_CRT0) $(CODECLINK_LDS) 57$(CODECS): $(CODEC_CRT0) $(CODECLINK_LDS)
@@ -78,6 +80,7 @@ $(CODECDIR)/asap.codec : $(CODECDIR)/libasap.a
78$(CODECDIR)/cook.codec : $(CODECDIR)/libcook.a $(CODECDIR)/librm.a 80$(CODECDIR)/cook.codec : $(CODECDIR)/libcook.a $(CODECDIR)/librm.a
79$(CODECDIR)/raac.codec : $(CODECDIR)/libfaad.a $(CODECDIR)/librm.a 81$(CODECDIR)/raac.codec : $(CODECDIR)/libfaad.a $(CODECDIR)/librm.a
80$(CODECDIR)/a52_rm.codec : $(CODECDIR)/liba52.a $(CODECDIR)/librm.a 82$(CODECDIR)/a52_rm.codec : $(CODECDIR)/liba52.a $(CODECDIR)/librm.a
83$(CODECDIR)/atrac3_rm.codec : $(CODECDIR)/libatrac.a $(CODECDIR)/librm.a
81 84
82$(CODECS): $(CODECLIB) # this must be last in codec dependency list 85$(CODECS): $(CODECLIB) # this must be last in codec dependency list
83 86
diff --git a/apps/codecs/libatrac/SOURCES b/apps/codecs/libatrac/SOURCES
new file mode 100644
index 0000000000..9db9ac3dab
--- /dev/null
+++ b/apps/codecs/libatrac/SOURCES
@@ -0,0 +1,3 @@
1atrac3.c
2fixp_math.c
3bitstream.c
diff --git a/apps/codecs/libatrac/atrac3.c b/apps/codecs/libatrac/atrac3.c
index 9e61db1686..7f2cb57356 100644
--- a/apps/codecs/libatrac/atrac3.c
+++ b/apps/codecs/libatrac/atrac3.c
@@ -45,7 +45,10 @@
45#define JOINT_STEREO 0x12 45#define JOINT_STEREO 0x12
46#define STEREO 0x2 46#define STEREO 0x2
47 47
48#define AVERROR(...) -1 48#ifdef ROCKBOX
49#undef DEBUGF
50#define DEBUGF(...)
51#endif /* ROCKBOX */
49 52
50/* FFMAX/MIN/SWAP and av_clip were taken from libavutil/common.h */ 53/* FFMAX/MIN/SWAP and av_clip were taken from libavutil/common.h */
51#define FFMAX(a,b) ((a) > (b) ? (a) : (b)) 54#define FFMAX(a,b) ((a) > (b) ? (a) : (b))
@@ -76,7 +79,7 @@ static channel_unit channel_units[2];
76 */ 79 */
77static void iqmf (int32_t *inlo, int32_t *inhi, unsigned int nIn, int32_t *pOut, int32_t *delayBuf, int32_t *temp) 80static void iqmf (int32_t *inlo, int32_t *inhi, unsigned int nIn, int32_t *pOut, int32_t *delayBuf, int32_t *temp)
78{ 81{
79 int i, j; 82 unsigned int i, j;
80 int32_t *p1, *p3; 83 int32_t *p1, *p3;
81 84
82 memcpy(temp, delayBuf, 46*sizeof(int32_t)); 85 memcpy(temp, delayBuf, 46*sizeof(int32_t));
@@ -163,7 +166,7 @@ static int decode_bytes(const uint8_t* inbuffer, uint8_t* out, int bytes){
163 const uint32_t* buf; 166 const uint32_t* buf;
164 uint32_t* obuf = (uint32_t*) out; 167 uint32_t* obuf = (uint32_t*) out;
165 168
166#ifdef TEST 169#if ((defined(TEST) || defined(SIMULATOR)) && !defined(CPU_ARM))
167 off = 0; //no check for memory alignment of inbuffer 170 off = 0; //no check for memory alignment of inbuffer
168#else 171#else
169 off = (intptr_t)inbuffer & 3; 172 off = (intptr_t)inbuffer & 3;
@@ -175,14 +178,16 @@ static int decode_bytes(const uint8_t* inbuffer, uint8_t* out, int bytes){
175 for (i = 0; i < bytes/4; i++) 178 for (i = 0; i < bytes/4; i++)
176 obuf[i] = c ^ buf[i]; 179 obuf[i] = c ^ buf[i];
177 180
178 if (off) 181 if (off) {
179 DEBUGF("Offset of %d not handled, post sample on ffmpeg-dev.\n",off); 182 DEBUGF("Offset of %d not handled, post sample on ffmpeg-dev.\n",off);
183 return off;
184 }
180 185
181 return off; 186 return off;
182} 187}
183 188
184 189
185static void init_atrac3_transforms(ATRAC3Context *q) { 190static void init_atrac3_transforms() {
186 int32_t s; 191 int32_t s;
187 int i; 192 int i;
188 193
@@ -630,7 +635,7 @@ static void channelWeighting (int32_t *su1, int32_t *su2, int *p3)
630 */ 635 */
631 636
632 637
633static int decodeChannelSoundUnit (ATRAC3Context *q, GetBitContext *gb, channel_unit *pSnd, int32_t *pOut, int channelNum, int codingMode) 638static int decodeChannelSoundUnit (GetBitContext *gb, channel_unit *pSnd, int32_t *pOut, int channelNum, int codingMode)
634{ 639{
635 int band, result=0, numSubbands, lastTonal, numBands; 640 int band, result=0, numSubbands, lastTonal, numBands;
636 if (codingMode == JOINT_STEREO && channelNum == 1) { 641 if (codingMode == JOINT_STEREO && channelNum == 1) {
@@ -705,7 +710,7 @@ static int decodeFrame(ATRAC3Context *q, const uint8_t* databuf)
705 /* decode Sound Unit 1 */ 710 /* decode Sound Unit 1 */
706 init_get_bits(&q->gb,databuf,q->bits_per_frame); 711 init_get_bits(&q->gb,databuf,q->bits_per_frame);
707 712
708 result = decodeChannelSoundUnit(q,&q->gb, q->pUnits, q->outSamples, 0, JOINT_STEREO); 713 result = decodeChannelSoundUnit(&q->gb, q->pUnits, q->outSamples, 0, JOINT_STEREO);
709 if (result != 0) 714 if (result != 0)
710 return (result); 715 return (result);
711 716
@@ -746,7 +751,7 @@ static int decodeFrame(ATRAC3Context *q, const uint8_t* databuf)
746 } 751 }
747 752
748 /* Decode Sound Unit 2. */ 753 /* Decode Sound Unit 2. */
749 result = decodeChannelSoundUnit(q,&q->gb, &q->pUnits[1], &q->outSamples[1024], 1, JOINT_STEREO); 754 result = decodeChannelSoundUnit(&q->gb, &q->pUnits[1], &q->outSamples[1024], 1, JOINT_STEREO);
750 if (result != 0) 755 if (result != 0)
751 return (result); 756 return (result);
752 757
@@ -763,7 +768,7 @@ static int decodeFrame(ATRAC3Context *q, const uint8_t* databuf)
763 /* Set the bitstream reader at the start of a channel sound unit. */ 768 /* Set the bitstream reader at the start of a channel sound unit. */
764 init_get_bits(&q->gb, databuf+((i*q->bytes_per_frame)/q->channels), (q->bits_per_frame)/q->channels); 769 init_get_bits(&q->gb, databuf+((i*q->bytes_per_frame)/q->channels), (q->bits_per_frame)/q->channels);
765 770
766 result = decodeChannelSoundUnit(q,&q->gb, &q->pUnits[i], &q->outSamples[i*1024], i, q->codingMode); 771 result = decodeChannelSoundUnit(&q->gb, &q->pUnits[i], &q->outSamples[i*1024], i, q->codingMode);
767 if (result != 0) 772 if (result != 0)
768 return (result); 773 return (result);
769 } 774 }
@@ -943,7 +948,7 @@ int atrac3_decode_init(ATRAC3Context *q, RMContext *rmctx)
943 948
944 } 949 }
945 950
946 init_atrac3_transforms(q); 951 init_atrac3_transforms();
947 952
948 /* init the joint-stereo decoding data */ 953 /* init the joint-stereo decoding data */
949 q->weighting_delay[0] = 0; 954 q->weighting_delay[0] = 0;
diff --git a/apps/codecs/libatrac/atrac3data.h b/apps/codecs/libatrac/atrac3data.h
index e71dc35560..8e7fe97c32 100644
--- a/apps/codecs/libatrac/atrac3data.h
+++ b/apps/codecs/libatrac/atrac3data.h
@@ -28,7 +28,7 @@
28#ifndef AVCODEC_ATRAC3DATA_H 28#ifndef AVCODEC_ATRAC3DATA_H
29#define AVCODEC_ATRAC3DATA_H 29#define AVCODEC_ATRAC3DATA_H
30 30
31#include <stdint.h> 31#include <inttypes.h>
32 32
33/* VLC tables */ 33/* VLC tables */
34 34
diff --git a/apps/codecs/libatrac/libatrac.make b/apps/codecs/libatrac/libatrac.make
new file mode 100644
index 0000000000..01606e1f15
--- /dev/null
+++ b/apps/codecs/libatrac/libatrac.make
@@ -0,0 +1,18 @@
1# __________ __ ___.
2# Open \______ \ ____ ____ | | _\_ |__ _______ ___
3# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
4# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
5# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
6# \/ \/ \/ \/ \/
7# $Id: libatrac.make 20151 2009-03-01 09:04:15Z amiconn $
8#
9
10# libatrac
11ATRACLIB := $(CODECDIR)/libatrac.a
12ATRACLIB_SRC := $(call preprocess, $(APPSDIR)/codecs/libatrac/SOURCES)
13ATRACLIB_OBJ := $(call c2obj, $(ATRACLIB_SRC))
14OTHER_SRC += $(ATRACLIB_SRC)
15
16$(ATRACLIB): $(ATRACLIB_OBJ)
17 $(SILENT)$(shell rm -f $@)
18 $(call PRINTS,AR $(@F))$(AR) rcs $@ $^ >/dev/null
diff --git a/apps/metadata.c b/apps/metadata.c
index 8414bf01ec..400ce6f469 100644
--- a/apps/metadata.c
+++ b/apps/metadata.c
@@ -124,6 +124,9 @@ const struct afmt_entry audio_formats[AFMT_NUM_CODECS] =
124 /* AC3 in RM/RA */ 124 /* AC3 in RM/RA */
125 [AFMT_RM_AC3] = 125 [AFMT_RM_AC3] =
126 AFMT_ENTRY("AC3", "a52_rm", NULL, "rm\0ra\0rmvb\0" ), 126 AFMT_ENTRY("AC3", "a52_rm", NULL, "rm\0ra\0rmvb\0" ),
127 /* ATRAC3 in RM/RA */
128 [AFMT_RM_ATRAC3] =
129 AFMT_ENTRY("ATRAC3","atrac3_rm", NULL, "rm\0ra\0rmvb\0" ),
127#endif 130#endif
128}; 131};
129 132
diff --git a/apps/metadata.h b/apps/metadata.h
index c43d2c2260..6144543aa6 100644
--- a/apps/metadata.h
+++ b/apps/metadata.h
@@ -64,6 +64,7 @@ enum
64 AFMT_RM_COOK, /* Cook in RM/RA */ 64 AFMT_RM_COOK, /* Cook in RM/RA */
65 AFMT_RM_AAC, /* AAC in RM/RA */ 65 AFMT_RM_AAC, /* AAC in RM/RA */
66 AFMT_RM_AC3, /* AC3 in RM/RA */ 66 AFMT_RM_AC3, /* AC3 in RM/RA */
67 AFMT_RM_ATRAC3, /* ATRAC3 in RM/RA */
67#endif 68#endif
68 69
69 /* add new formats at any index above this line to have a sensible order - 70 /* add new formats at any index above this line to have a sensible order -
diff --git a/apps/metadata/rm.c b/apps/metadata/rm.c
index fd6f1d984c..740ec1b1ed 100644
--- a/apps/metadata/rm.c
+++ b/apps/metadata/rm.c
@@ -182,6 +182,14 @@ static inline int real_read_audio_stream_info(int fd, RMContext *rmctx)
182 rmctx->codec_type = CODEC_AC3; 182 rmctx->codec_type = CODEC_AC3;
183 break; 183 break;
184 184
185 case FOURCC('a','t','r','c'):
186 rmctx->codec_type = CODEC_ATRAC;
187 read_uint32be(fd, &rmctx->extradata_size);
188 skipped += 4;
189 read(fd, rmctx->codec_extradata, rmctx->extradata_size);
190 skipped += rmctx->extradata_size;
191 break;
192
185 default: /* Not a supported codec */ 193 default: /* Not a supported codec */
186 return -1; 194 return -1;
187 } 195 }
@@ -421,7 +429,7 @@ bool get_rm_metadata(int fd, struct mp3entry* id3)
421 break; 429 break;
422 430
423 case CODEC_ATRAC: 431 case CODEC_ATRAC:
424 /* Not yet supported in rockbox, parsing fails before reaching here */ 432 id3->codectype = AFMT_RM_ATRAC3;
425 break; 433 break;
426 } 434 }
427 435