summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/codecs/atrac3_oma.c27
-rw-r--r--apps/codecs/atrac3_rm.c8
-rw-r--r--apps/codecs/libatrac/atrac3.c36
-rw-r--r--apps/codecs/libatrac/atrac3.h7
-rw-r--r--apps/metadata/oma.c21
-rw-r--r--apps/metadata/rm.c2
6 files changed, 46 insertions, 55 deletions
diff --git a/apps/codecs/atrac3_oma.c b/apps/codecs/atrac3_oma.c
index b080b71524..55299007d7 100644
--- a/apps/codecs/atrac3_oma.c
+++ b/apps/codecs/atrac3_oma.c
@@ -31,24 +31,8 @@ CODEC_HEADER
31#define FRAMESIZE ci->id3->bytesperframe 31#define FRAMESIZE ci->id3->bytesperframe
32#define BITRATE ci->id3->bitrate 32#define BITRATE ci->id3->bitrate
33 33
34/* The codec has nothing to do with RM, it just uses an RMContext struct to *
35 * store the data needs to be passed to the decoder initializing function. */
36RMContext rmctx;
37ATRAC3Context q IBSS_ATTR; 34ATRAC3Context q IBSS_ATTR;
38 35
39static void init_rm(RMContext *rmctx, struct mp3entry *id3)
40{
41 rmctx->sample_rate = id3->frequency;
42 rmctx->nb_channels = 2;
43 rmctx->bit_rate = id3->bitrate;
44 rmctx->block_align = id3->bytesperframe;
45
46 /* 14-byte extra-data was faked in the metadata parser so that *
47 * the ATRAC3 decoder would parse it as WAV format extra-data. */
48 rmctx->extradata_size = 14;
49 memcpy(rmctx->codec_extradata, &id3->id3v1buf[0][0], 14);
50}
51
52/* this is the codec entry point */ 36/* this is the codec entry point */
53enum codec_status codec_main(void) 37enum codec_status codec_main(void)
54{ 38{
@@ -67,17 +51,14 @@ next_track:
67 ci->sleep(1); 51 ci->sleep(1);
68 52
69 codec_set_replaygain(ci->id3); 53 codec_set_replaygain(ci->id3);
70 ci->memset(&rmctx,0,sizeof(RMContext));
71 ci->memset(&q,0,sizeof(ATRAC3Context)); 54 ci->memset(&q,0,sizeof(ATRAC3Context));
72
73 init_rm(&rmctx, ci->id3);
74 55
75 ci->configure(DSP_SET_FREQUENCY, ci->id3->frequency); 56 ci->configure(DSP_SET_FREQUENCY, ci->id3->frequency);
76 ci->configure(DSP_SET_SAMPLE_DEPTH, 17); /* Remark: atrac3 uses s15.0 by default, s15.2 was hacked. */ 57 ci->configure(DSP_SET_SAMPLE_DEPTH, 17); /* Remark: atrac3 uses s15.0 by default, s15.2 was hacked. */
77 ci->configure(DSP_SET_STEREO_MODE, rmctx.nb_channels == 1 ? 58 ci->configure(DSP_SET_STEREO_MODE, ci->id3->channels == 1 ?
78 STEREO_MONO : STEREO_NONINTERLEAVED); 59 STEREO_MONO : STEREO_NONINTERLEAVED);
79 60
80 res =atrac3_decode_init(&q, &rmctx); 61 res =atrac3_decode_init(&q, ci->id3);
81 if(res < 0) { 62 if(res < 0) {
82 DEBUGF("failed to initialize atrac decoder\n"); 63 DEBUGF("failed to initialize atrac decoder\n");
83 return CODEC_ERROR; 64 return CODEC_ERROR;
@@ -133,7 +114,7 @@ seek_start :
133 ci->seek_complete(); 114 ci->seek_complete();
134 } 115 }
135 116
136 res = atrac3_decode_frame(&rmctx, &q, &datasize, bit_buffer, FRAMESIZE); 117 res = atrac3_decode_frame(FRAMESIZE, &q, &datasize, bit_buffer, FRAMESIZE);
137 118
138 if(res != (int)FRAMESIZE) { 119 if(res != (int)FRAMESIZE) {
139 DEBUGF("codec error\n"); 120 DEBUGF("codec error\n");
@@ -141,7 +122,7 @@ seek_start :
141 } 122 }
142 123
143 if(datasize) 124 if(datasize)
144 ci->pcmbuf_insert(q.outSamples, q.outSamples + 1024, q.samples_per_frame / rmctx.nb_channels); 125 ci->pcmbuf_insert(q.outSamples, q.outSamples + 1024, q.samples_per_frame / ci->id3->channels);
145 126
146 elapsed += (FRAMESIZE * 8) / BITRATE; 127 elapsed += (FRAMESIZE * 8) / BITRATE;
147 ci->set_elapsed(elapsed); 128 ci->set_elapsed(elapsed);
diff --git a/apps/codecs/atrac3_rm.c b/apps/codecs/atrac3_rm.c
index 41399fda3d..b8f8489b1a 100644
--- a/apps/codecs/atrac3_rm.c
+++ b/apps/codecs/atrac3_rm.c
@@ -34,7 +34,11 @@ ATRAC3Context q IBSS_ATTR;
34 34
35static void init_rm(RMContext *rmctx) 35static void init_rm(RMContext *rmctx)
36{ 36{
37 /* initialize the RMContext */
37 memcpy(rmctx, (void*)(( (intptr_t)ci->id3->id3v2buf + 3 ) &~ 3), sizeof(RMContext)); 38 memcpy(rmctx, (void*)(( (intptr_t)ci->id3->id3v2buf + 3 ) &~ 3), sizeof(RMContext));
39
40 /* and atrac3 expects extadata in id3v2buf, so we shall give it that */
41 memcpy(ci->id3->id3v2buf, (char*)rmctx->codec_extradata, rmctx->extradata_size*sizeof(char));
38} 42}
39 43
40/* this is the codec entry point */ 44/* this is the codec entry point */
@@ -77,7 +81,7 @@ next_track:
77 h = rmctx.sub_packet_h; 81 h = rmctx.sub_packet_h;
78 scrambling_unit_size = h*fs; 82 scrambling_unit_size = h*fs;
79 83
80 res =atrac3_decode_init(&q, &rmctx); 84 res =atrac3_decode_init(&q, ci->id3);
81 if(res < 0) { 85 if(res < 0) {
82 DEBUGF("failed to initialize atrac decoder\n"); 86 DEBUGF("failed to initialize atrac decoder\n");
83 return CODEC_ERROR; 87 return CODEC_ERROR;
@@ -168,7 +172,7 @@ seek_start :
168 ci->seek_complete(); 172 ci->seek_complete();
169 } 173 }
170 if(pkt.length) 174 if(pkt.length)
171 res = atrac3_decode_frame(&rmctx, &q, &datasize, pkt.frames[i], rmctx.block_align); 175 res = atrac3_decode_frame(rmctx.block_align, &q, &datasize, pkt.frames[i], rmctx.block_align);
172 else /* indicates that there are no remaining frames */ 176 else /* indicates that there are no remaining frames */
173 goto done; 177 goto done;
174 178
diff --git a/apps/codecs/libatrac/atrac3.c b/apps/codecs/libatrac/atrac3.c
index 3c6ecc9197..2f4d44b6af 100644
--- a/apps/codecs/libatrac/atrac3.c
+++ b/apps/codecs/libatrac/atrac3.c
@@ -1074,17 +1074,17 @@ static int decodeFrame(ATRAC3Context *q, const uint8_t* databuf, int off)
1074 * @param rmctx pointer to the AVCodecContext 1074 * @param rmctx pointer to the AVCodecContext
1075 */ 1075 */
1076 1076
1077int atrac3_decode_frame(RMContext *rmctx, ATRAC3Context *q, 1077int atrac3_decode_frame(unsigned long block_align, ATRAC3Context *q,
1078 int *data_size, const uint8_t *buf, int buf_size) { 1078 int *data_size, const uint8_t *buf, int buf_size) {
1079 int result = 0, off = 0; 1079 int result = 0, off = 0;
1080 const uint8_t* databuf; 1080 const uint8_t* databuf;
1081 1081
1082 if (buf_size < rmctx->block_align) 1082 if (buf_size < block_align)
1083 return buf_size; 1083 return buf_size;
1084 1084
1085 /* Check if we need to descramble and what buffer to pass on. */ 1085 /* Check if we need to descramble and what buffer to pass on. */
1086 if (q->scrambled_stream) { 1086 if (q->scrambled_stream) {
1087 off = decode_bytes(buf, q->decoded_bytes_buffer, rmctx->block_align); 1087 off = decode_bytes(buf, q->decoded_bytes_buffer, block_align);
1088 databuf = q->decoded_bytes_buffer; 1088 databuf = q->decoded_bytes_buffer;
1089 } else { 1089 } else {
1090 databuf = buf; 1090 databuf = buf;
@@ -1102,7 +1102,7 @@ int atrac3_decode_frame(RMContext *rmctx, ATRAC3Context *q,
1102 else 1102 else
1103 *data_size = 2048 * sizeof(int32_t); 1103 *data_size = 2048 * sizeof(int32_t);
1104 1104
1105 return rmctx->block_align; 1105 return block_align;
1106} 1106}
1107 1107
1108 1108
@@ -1111,23 +1111,23 @@ int atrac3_decode_frame(RMContext *rmctx, ATRAC3Context *q,
1111 * 1111 *
1112 * @param rmctx pointer to the RMContext 1112 * @param rmctx pointer to the RMContext
1113 */ 1113 */
1114 1114int atrac3_decode_init(ATRAC3Context *q, struct mp3entry *id3)
1115int atrac3_decode_init(ATRAC3Context *q, RMContext *rmctx)
1116{ 1115{
1117 int i; 1116 int i;
1118 uint8_t *edata_ptr = rmctx->codec_extradata; 1117 uint8_t *edata_ptr = (uint8_t*)&id3->id3v2buf;
1119 static VLC_TYPE atrac3_vlc_table[4096][2]; 1118 static VLC_TYPE atrac3_vlc_table[4096][2];
1120 static int vlcs_initialized = 0; 1119 static int vlcs_initialized = 0;
1121 1120
1122 /* Take data from the AVCodecContext (RM container). */ 1121 /* Take data from the RM container. */
1123 q->sample_rate = rmctx->sample_rate; 1122 q->sample_rate = id3->frequency;
1124 q->channels = rmctx->nb_channels; 1123 q->channels = id3->channels;
1125 q->bit_rate = rmctx->bit_rate; 1124 q->bit_rate = id3->bitrate * 1000;
1126 q->bits_per_frame = rmctx->block_align * 8; 1125 q->bits_per_frame = id3->bytesperframe * 8;
1127 q->bytes_per_frame = rmctx->block_align; 1126 q->bytes_per_frame = id3->bytesperframe;
1128 1127
1129 /* Take care of the codec-specific extradata. */ 1128 /* Take care of the codec-specific extradata. */
1130 if (rmctx->extradata_size == 14) { 1129
1130 if (id3->extradata_size == 14) {
1131 /* Parse the extradata, WAV format */ 1131 /* Parse the extradata, WAV format */
1132 DEBUGF("[0-1] %d\n",rm_get_uint16le(&edata_ptr[0])); /* Unknown value always 1 */ 1132 DEBUGF("[0-1] %d\n",rm_get_uint16le(&edata_ptr[0])); /* Unknown value always 1 */
1133 q->samples_per_channel = rm_get_uint32le(&edata_ptr[2]); 1133 q->samples_per_channel = rm_get_uint32le(&edata_ptr[2]);
@@ -1152,7 +1152,7 @@ int atrac3_decode_init(ATRAC3Context *q, RMContext *rmctx)
1152 return -1; 1152 return -1;
1153 } 1153 }
1154 1154
1155 } else if (rmctx->extradata_size == 10) { 1155 } else if (id3->extradata_size == 10) {
1156 /* Parse the extradata, RM format. */ 1156 /* Parse the extradata, RM format. */
1157 q->atrac3version = rm_get_uint32be(&edata_ptr[0]); 1157 q->atrac3version = rm_get_uint32be(&edata_ptr[0]);
1158 q->samples_per_frame = rm_get_uint16be(&edata_ptr[4]); 1158 q->samples_per_frame = rm_get_uint16be(&edata_ptr[4]);
@@ -1163,7 +1163,7 @@ int atrac3_decode_init(ATRAC3Context *q, RMContext *rmctx)
1163 q->scrambled_stream = 1; 1163 q->scrambled_stream = 1;
1164 1164
1165 } else { 1165 } else {
1166 DEBUGF("Unknown extradata size %d.\n",rmctx->extradata_size); 1166 DEBUGF("Unknown extradata size %d.\n",id3->extradata_size);
1167 } 1167 }
1168 /* Check the extradata. */ 1168 /* Check the extradata. */
1169 1169
@@ -1191,13 +1191,13 @@ int atrac3_decode_init(ATRAC3Context *q, RMContext *rmctx)
1191 return -1; 1191 return -1;
1192 } 1192 }
1193 1193
1194 if (rmctx->nb_channels <= 0 || rmctx->nb_channels > 2 /*|| ((rmctx->channels * 1024) != q->samples_per_frame)*/) { 1194 if (id3->channels <= 0 || id3->channels > 2 ) {
1195 DEBUGF("Channel configuration error!\n"); 1195 DEBUGF("Channel configuration error!\n");
1196 return -1; 1196 return -1;
1197 } 1197 }
1198 1198
1199 1199
1200 if(rmctx->block_align >= UINT16_MAX/2) 1200 if(id3->bytesperframe >= UINT16_MAX/2)
1201 return -1; 1201 return -1;
1202 1202
1203 1203
diff --git a/apps/codecs/libatrac/atrac3.h b/apps/codecs/libatrac/atrac3.h
index 5bed9c60bf..0e31821279 100644
--- a/apps/codecs/libatrac/atrac3.h
+++ b/apps/codecs/libatrac/atrac3.h
@@ -1,5 +1,8 @@
1#include "ffmpeg_bitstream.h" 1#include "ffmpeg_bitstream.h"
2#include "../librm/rm.h" 2#include "../librm/rm.h"
3#ifdef ROCKBOX
4#include "codeclib.h"
5#endif
3 6
4#if (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024) || (CONFIG_CPU == MCF5250) 7#if (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024) || (CONFIG_CPU == MCF5250)
5/* PP5022/24 and MCF5250 have larger IRAM */ 8/* PP5022/24 and MCF5250 have larger IRAM */
@@ -82,8 +85,8 @@ typedef struct {
82 //@} 85 //@}
83} ATRAC3Context; 86} ATRAC3Context;
84 87
85int atrac3_decode_init(ATRAC3Context *q, RMContext *rmctx); 88int atrac3_decode_init(ATRAC3Context *q, struct mp3entry *id3);
86 89
87int atrac3_decode_frame(RMContext *rmctx, ATRAC3Context *q, 90int atrac3_decode_frame(unsigned long block_align, ATRAC3Context *q,
88 int *data_size, const uint8_t *buf, int buf_size); 91 int *data_size, const uint8_t *buf, int buf_size);
89 92
diff --git a/apps/metadata/oma.c b/apps/metadata/oma.c
index 695ae0b114..0f42a57a8c 100644
--- a/apps/metadata/oma.c
+++ b/apps/metadata/oma.c
@@ -137,7 +137,7 @@ int oma_read_header(int fd, struct mp3entry* id3)
137 case OMA_CODECID_ATRAC3: 137 case OMA_CODECID_ATRAC3:
138 id3->frequency = srate_tab[(codec_params >> 13) & 7]*100; 138 id3->frequency = srate_tab[(codec_params >> 13) & 7]*100;
139 if (id3->frequency != 44100) { 139 if (id3->frequency != 44100) {
140 DEBUGF("Unsupported sample rate, send sample file to developers: %d\n", samplerate); 140 DEBUGF("Unsupported sample rate, send sample file to developers: %d\n", id3->frequency);
141 return -1; 141 return -1;
142 } 142 }
143 143
@@ -149,16 +149,17 @@ int oma_read_header(int fd, struct mp3entry* id3)
149 149
150 /* fake the atrac3 extradata (wav format, makes stream copy to wav work) */ 150 /* fake the atrac3 extradata (wav format, makes stream copy to wav work) */
151 /* ATRAC3 expects and extra-data size of 14 bytes for wav format; extra-data size * 151 /* ATRAC3 expects and extra-data size of 14 bytes for wav format; extra-data size *
152 * is stored in ATRAC3Context before initializing the decoder. See atrac3_oma.codec. * 152 * is stored in ATRAC3Context before initializing the decoder. *
153 * We use id3v2buf to hold the (fake) extra-data provided from the container. */ 153 * We use id3v2buf to hold the (fake) extra-data provided from the container. */
154 154 id3->extradata_size = 14;
155 AV_WL16(&id3->id3v1buf[0][0], 1); // always 1 155 AV_WL16(&id3->id3v2buf[0], 1); // always 1
156 AV_WL32(&id3->id3v1buf[0][2], id3->frequency); // samples rate 156 AV_WL32(&id3->id3v2buf[2], id3->frequency); // samples rate
157 AV_WL16(&id3->id3v1buf[0][6], jsflag); // coding mode 157 AV_WL16(&id3->id3v2buf[6], jsflag); // coding mode
158 AV_WL16(&id3->id3v1buf[0][8], jsflag); // coding mode 158 AV_WL16(&id3->id3v2buf[8], jsflag); // coding mode
159 AV_WL16(&id3->id3v1buf[0][10], 1); // always 1 159 AV_WL16(&id3->id3v2buf[10], 1); // always 1
160 AV_WL16(&id3->id3v1buf[0][12], 0); // always 0 160 AV_WL16(&id3->id3v2buf[12], 0); // always 0
161 161
162 id3->channels = 2;
162 DEBUGF("sample_rate = %d\n", id3->frequency); 163 DEBUGF("sample_rate = %d\n", id3->frequency);
163 DEBUGF("frame_size = %d\n", id3->bytesperframe); 164 DEBUGF("frame_size = %d\n", id3->bytesperframe);
164 DEBUGF("stereo_coding_mode = %d\n", jsflag); 165 DEBUGF("stereo_coding_mode = %d\n", jsflag);
diff --git a/apps/metadata/rm.c b/apps/metadata/rm.c
index 5740616042..63328a3ab1 100644
--- a/apps/metadata/rm.c
+++ b/apps/metadata/rm.c
@@ -438,6 +438,8 @@ bool get_rm_metadata(int fd, struct mp3entry* id3)
438 break; 438 break;
439 } 439 }
440 440
441 id3->channels = rmctx->nb_channels;
442 id3->extradata_size = rmctx->extradata_size;
441 id3->bitrate = rmctx->bit_rate / 1000; 443 id3->bitrate = rmctx->bit_rate / 1000;
442 id3->frequency = rmctx->sample_rate; 444 id3->frequency = rmctx->sample_rate;
443 id3->length = rmctx->duration; 445 id3->length = rmctx->duration;