summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2008-12-21 01:29:36 +0000
committerJens Arnold <amiconn@rockbox.org>2008-12-21 01:29:36 +0000
commit0bf6e36628291855701de14e8575ac6fa5e25341 (patch)
tree2bfc3bac0a01ec753233661033a7ee04de2c3a45
parent558cce602766ee5d9faf6da7d70434e0657fc5b0 (diff)
downloadrockbox-0bf6e36628291855701de14e8575ac6fa5e25341.tar.gz
rockbox-0bf6e36628291855701de14e8575ac6fa5e25341.zip
Fix handling of 8 bit mono and stereo APE files, and also optimise 16 and 24 bit output in the standalone decoder a bit.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19517 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/codecs/demac/demac.c26
-rw-r--r--apps/codecs/demac/libdemac/decoder.c45
2 files changed, 37 insertions, 34 deletions
diff --git a/apps/codecs/demac/demac.c b/apps/codecs/demac/demac.c
index da132ff248..5e9893687d 100644
--- a/apps/codecs/demac/demac.c
+++ b/apps/codecs/demac/demac.c
@@ -2,7 +2,7 @@
2 2
3demac - A Monkey's Audio decoder 3demac - A Monkey's Audio decoder
4 4
5$Id:$ 5$Id$
6 6
7Copyright (C) Dave Chapman 2007 7Copyright (C) Dave Chapman 2007
8 8
@@ -180,17 +180,27 @@ int ape_decode(char* infile, char* outfile)
180 180
181 /* Convert the output samples to WAV format and write to output file */ 181 /* Convert the output samples to WAV format and write to output file */
182 p = wavbuffer; 182 p = wavbuffer;
183 if (ape_ctx.bps == 16) { 183 if (ape_ctx.bps == 8) {
184 for (i = 0 ; i < blockstodecode ; i++)
185 {
186 /* 8 bit WAV uses unsigned samples */
187 *(p++) = (decoded0[i] + 0x80) & 0xff;
188
189 if (ape_ctx.channels == 2) {
190 *(p++) = (decoded1[i] + 0x80) & 0xff;
191 }
192 }
193 } else if (ape_ctx.bps == 16) {
184 for (i = 0 ; i < blockstodecode ; i++) 194 for (i = 0 ; i < blockstodecode ; i++)
185 { 195 {
186 sample16 = decoded0[i]; 196 sample16 = decoded0[i];
187 *(p++) = sample16 & 0xff; 197 *(p++) = sample16 & 0xff;
188 *(p++) = (sample16&0xff00) >> 8; 198 *(p++) = (sample16 >> 8) & 0xff;
189 199
190 if (ape_ctx.channels == 2) { 200 if (ape_ctx.channels == 2) {
191 sample16 = decoded1[i]; 201 sample16 = decoded1[i];
192 *(p++) = sample16 & 0xff; 202 *(p++) = sample16 & 0xff;
193 *(p++) = (sample16&0xff00) >> 8; 203 *(p++) = (sample16 >> 8) & 0xff;
194 } 204 }
195 } 205 }
196 } else if (ape_ctx.bps == 24) { 206 } else if (ape_ctx.bps == 24) {
@@ -198,14 +208,14 @@ int ape_decode(char* infile, char* outfile)
198 { 208 {
199 sample32 = decoded0[i]; 209 sample32 = decoded0[i];
200 *(p++) = sample32 & 0xff; 210 *(p++) = sample32 & 0xff;
201 *(p++) = (sample32&0xff00) >> 8; 211 *(p++) = (sample32 >> 8) & 0xff;
202 *(p++) = (sample32&0xff0000) >> 16; 212 *(p++) = (sample32 >> 16) & 0xff;
203 213
204 if (ape_ctx.channels == 2) { 214 if (ape_ctx.channels == 2) {
205 sample32 = decoded1[i]; 215 sample32 = decoded1[i];
206 *(p++) = sample32 & 0xff; 216 *(p++) = sample32 & 0xff;
207 *(p++) = (sample32&0xff00) >> 8; 217 *(p++) = (sample32 >> 8) & 0xff;
208 *(p++) = (sample32&0xff0000) >> 16; 218 *(p++) = (sample32 >> 16) & 0xff;
209 } 219 }
210 } 220 }
211 } 221 }
diff --git a/apps/codecs/demac/libdemac/decoder.c b/apps/codecs/demac/libdemac/decoder.c
index 79b5255ce0..2200faf187 100644
--- a/apps/codecs/demac/libdemac/decoder.c
+++ b/apps/codecs/demac/libdemac/decoder.c
@@ -91,14 +91,14 @@ int ICODE_ATTR_DEMAC decode_chunk(struct ape_ctx_t* ape_ctx,
91#endif 91#endif
92 92
93 if ((ape_ctx->channels==1) || (ape_ctx->frameflags & APE_FRAMECODE_PSEUDO_STEREO)) { 93 if ((ape_ctx->channels==1) || (ape_ctx->frameflags & APE_FRAMECODE_PSEUDO_STEREO)) {
94 if (ape_ctx->frameflags & APE_FRAMECODE_STEREO_SILENCE) { 94 if (ape_ctx->frameflags & APE_FRAMECODE_STEREO_SILENCE) {
95 entropy_decode(ape_ctx, inbuffer, firstbyte, bytesconsumed, decoded0, decoded1, count); 95 entropy_decode(ape_ctx, inbuffer, firstbyte, bytesconsumed, decoded0, decoded1, count);
96 /* We are pure silence, so we're done. */ 96 /* We are pure silence, so we're done. */
97 return 0; 97 return 0;
98 } else { 98 } else {
99 entropy_decode(ape_ctx, inbuffer, firstbyte, bytesconsumed, decoded0, NULL, count); 99 entropy_decode(ape_ctx, inbuffer, firstbyte, bytesconsumed, decoded0, NULL, count);
100 } 100 }
101 101
102 switch (ape_ctx->compressiontype) 102 switch (ape_ctx->compressiontype)
103 { 103 {
104 case 2000: 104 case 2000:
@@ -124,26 +124,23 @@ int ICODE_ATTR_DEMAC decode_chunk(struct ape_ctx_t* ape_ctx,
124 predictor_decode_mono(&ape_ctx->predictor,decoded0,count); 124 predictor_decode_mono(&ape_ctx->predictor,decoded0,count);
125 125
126 if (ape_ctx->channels==2) { 126 if (ape_ctx->channels==2) {
127 /* Pseudo-stereo - just copy left channel to right channel */ 127 /* Pseudo-stereo - copy left channel to right channel */
128 while (count--) 128 while (count--)
129 { 129 {
130 left = *decoded0; 130 left = *decoded0;
131 *(decoded1++) = *(decoded0++) = SCALE(left); 131 *(decoded1++) = *(decoded0++) = SCALE(left);
132 } 132 }
133 } else { 133 }
134 /* Mono - do nothing unless it's 8-bit audio */ 134#ifdef ROCKBOX
135 if (ape_ctx->bps == 8) { 135 else {
136 /* TODO: Handle 8-bit streams */ 136 /* Scale to output depth */
137 } else { 137 while (count--)
138 /* Scale to output depth */ 138 {
139 while (count--) 139 left = *decoded0;
140 { 140 *(decoded0++) = SCALE(left);
141 left = *decoded0;
142 *(decoded0++) = SCALE(left);
143 }
144 } 141 }
145
146 } 142 }
143#endif
147 } else { /* Stereo */ 144 } else { /* Stereo */
148 if (ape_ctx->frameflags & APE_FRAMECODE_STEREO_SILENCE) { 145 if (ape_ctx->frameflags & APE_FRAMECODE_STEREO_SILENCE) {
149 /* We are pure silence, so we're done. */ 146 /* We are pure silence, so we're done. */
@@ -177,18 +174,14 @@ int ICODE_ATTR_DEMAC decode_chunk(struct ape_ctx_t* ape_ctx,
177 /* Now apply the predictor decoding */ 174 /* Now apply the predictor decoding */
178 predictor_decode_stereo(&ape_ctx->predictor,decoded0,decoded1,count); 175 predictor_decode_stereo(&ape_ctx->predictor,decoded0,decoded1,count);
179 176
180 if (ape_ctx->bps == 8) { 177 /* Decorrelate and scale to output depth */
181 /* TODO: Handle 8-bit streams */ 178 while (count--)
182 } else { 179 {
183 /* Decorrelate and scale to output depth */ 180 left = *decoded1 - (*decoded0 / 2);
184 while (count--) 181 right = left + *decoded0;
185 {
186 left = *decoded1 - (*decoded0 / 2);
187 right = left + *decoded0;
188 182
189 *(decoded0++) = SCALE(left); 183 *(decoded0++) = SCALE(left);
190 *(decoded1++) = SCALE(right); 184 *(decoded1++) = SCALE(right);
191 }
192 } 185 }
193 } 186 }
194 return 0; 187 return 0;