summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2008-12-22 00:01:30 +0000
committerJens Arnold <amiconn@rockbox.org>2008-12-22 00:01:30 +0000
commitd3a3975d27ecf0400d5558a6e1a6184d29f14b52 (patch)
tree1506745fd7f5e964f8de7a074910152215b2ceaa
parentb4681ed66c8f91e88c84d6bf9879433ff983963b (diff)
downloadrockbox-d3a3975d27ecf0400d5558a6e1a6184d29f14b52.tar.gz
rockbox-d3a3975d27ecf0400d5558a6e1a6184d29f14b52.zip
Port r19517 (handling of 8 bit mono & stereo files) and r19552 (handling of stereo frames with silence in only one channel) to the 3.1 branch.
git-svn-id: svn://svn.rockbox.org/rockbox/branches/v3_1@19553 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/codecs/demac/Makefile2
-rw-r--r--apps/codecs/demac/demac.c26
-rw-r--r--apps/codecs/demac/libdemac/decoder.c64
-rw-r--r--apps/codecs/demac/libdemac/entropy.c7
-rw-r--r--apps/codecs/demac/libdemac/parser.h4
5 files changed, 58 insertions, 45 deletions
diff --git a/apps/codecs/demac/Makefile b/apps/codecs/demac/Makefile
index c366237480..7843be6e49 100644
--- a/apps/codecs/demac/Makefile
+++ b/apps/codecs/demac/Makefile
@@ -4,7 +4,7 @@ FILTERS = libdemac/filter_16_11.o libdemac/filter_64_11.o libdemac/filter_256_13
LIBOBJS = libdemac/parser.o libdemac/decoder.o libdemac/entropy.o libdemac/predictor.o libdemac/crc.o $(FILTERS)
OBJS = demac.o wavwrite.o $(LIBOBJS)
-CFLAGS = -Wall -O3 -Ilibdemac
+CFLAGS = -Wall -g -O3 -Ilibdemac
ifeq ($(findstring CYGWIN,$(shell uname)),CYGWIN)
EXT = .exe
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 @@
demac - A Monkey's Audio decoder
-$Id:$
+$Id$
Copyright (C) Dave Chapman 2007
@@ -180,17 +180,27 @@ int ape_decode(char* infile, char* outfile)
/* Convert the output samples to WAV format and write to output file */
p = wavbuffer;
- if (ape_ctx.bps == 16) {
+ if (ape_ctx.bps == 8) {
+ for (i = 0 ; i < blockstodecode ; i++)
+ {
+ /* 8 bit WAV uses unsigned samples */
+ *(p++) = (decoded0[i] + 0x80) & 0xff;
+
+ if (ape_ctx.channels == 2) {
+ *(p++) = (decoded1[i] + 0x80) & 0xff;
+ }
+ }
+ } else if (ape_ctx.bps == 16) {
for (i = 0 ; i < blockstodecode ; i++)
{
sample16 = decoded0[i];
*(p++) = sample16 & 0xff;
- *(p++) = (sample16&0xff00) >> 8;
+ *(p++) = (sample16 >> 8) & 0xff;
if (ape_ctx.channels == 2) {
sample16 = decoded1[i];
*(p++) = sample16 & 0xff;
- *(p++) = (sample16&0xff00) >> 8;
+ *(p++) = (sample16 >> 8) & 0xff;
}
}
} else if (ape_ctx.bps == 24) {
@@ -198,14 +208,14 @@ int ape_decode(char* infile, char* outfile)
{
sample32 = decoded0[i];
*(p++) = sample32 & 0xff;
- *(p++) = (sample32&0xff00) >> 8;
- *(p++) = (sample32&0xff0000) >> 16;
+ *(p++) = (sample32 >> 8) & 0xff;
+ *(p++) = (sample32 >> 16) & 0xff;
if (ape_ctx.channels == 2) {
sample32 = decoded1[i];
*(p++) = sample32 & 0xff;
- *(p++) = (sample32&0xff00) >> 8;
- *(p++) = (sample32&0xff0000) >> 16;
+ *(p++) = (sample32 >> 8) & 0xff;
+ *(p++) = (sample32 >> 16) & 0xff;
}
}
}
diff --git a/apps/codecs/demac/libdemac/decoder.c b/apps/codecs/demac/libdemac/decoder.c
index 79b5255ce0..0763c11037 100644
--- a/apps/codecs/demac/libdemac/decoder.c
+++ b/apps/codecs/demac/libdemac/decoder.c
@@ -89,16 +89,19 @@ int ICODE_ATTR_DEMAC decode_chunk(struct ape_ctx_t* ape_ctx,
#else
#define SCALE(x) (x)
#endif
+
+ if ((ape_ctx->channels==1) || ((ape_ctx->frameflags
+ & (APE_FRAMECODE_PSEUDO_STEREO|APE_FRAMECODE_STEREO_SILENCE))
+ == APE_FRAMECODE_PSEUDO_STEREO)) {
- if ((ape_ctx->channels==1) || (ape_ctx->frameflags & APE_FRAMECODE_PSEUDO_STEREO)) {
- if (ape_ctx->frameflags & APE_FRAMECODE_STEREO_SILENCE) {
- entropy_decode(ape_ctx, inbuffer, firstbyte, bytesconsumed, decoded0, decoded1, count);
+ entropy_decode(ape_ctx, inbuffer, firstbyte, bytesconsumed,
+ decoded0, NULL, count);
+
+ if (ape_ctx->frameflags & APE_FRAMECODE_MONO_SILENCE) {
/* We are pure silence, so we're done. */
return 0;
- } else {
- entropy_decode(ape_ctx, inbuffer, firstbyte, bytesconsumed, decoded0, NULL, count);
}
-
+
switch (ape_ctx->compressiontype)
{
case 2000:
@@ -124,33 +127,32 @@ int ICODE_ATTR_DEMAC decode_chunk(struct ape_ctx_t* ape_ctx,
predictor_decode_mono(&ape_ctx->predictor,decoded0,count);
if (ape_ctx->channels==2) {
- /* Pseudo-stereo - just copy left channel to right channel */
+ /* Pseudo-stereo - copy left channel to right channel */
while (count--)
{
left = *decoded0;
*(decoded1++) = *(decoded0++) = SCALE(left);
}
- } else {
- /* Mono - do nothing unless it's 8-bit audio */
- if (ape_ctx->bps == 8) {
- /* TODO: Handle 8-bit streams */
- } else {
- /* Scale to output depth */
- while (count--)
- {
- left = *decoded0;
- *(decoded0++) = SCALE(left);
- }
+ }
+#ifdef ROCKBOX
+ else {
+ /* Scale to output depth */
+ while (count--)
+ {
+ left = *decoded0;
+ *(decoded0++) = SCALE(left);
}
-
}
+#endif
} else { /* Stereo */
- if (ape_ctx->frameflags & APE_FRAMECODE_STEREO_SILENCE) {
+ entropy_decode(ape_ctx, inbuffer, firstbyte, bytesconsumed,
+ decoded0, decoded1, count);
+
+ if ((ape_ctx->frameflags & APE_FRAMECODE_STEREO_SILENCE)
+ == APE_FRAMECODE_STEREO_SILENCE) {
/* We are pure silence, so we're done. */
return 0;
}
-
- entropy_decode(ape_ctx, inbuffer, firstbyte, bytesconsumed, decoded0, decoded1, count);
/* Apply filters - compression type 1000 doesn't have any */
switch (ape_ctx->compressiontype)
@@ -177,18 +179,14 @@ int ICODE_ATTR_DEMAC decode_chunk(struct ape_ctx_t* ape_ctx,
/* Now apply the predictor decoding */
predictor_decode_stereo(&ape_ctx->predictor,decoded0,decoded1,count);
- if (ape_ctx->bps == 8) {
- /* TODO: Handle 8-bit streams */
- } else {
- /* Decorrelate and scale to output depth */
- while (count--)
- {
- left = *decoded1 - (*decoded0 / 2);
- right = left + *decoded0;
+ /* Decorrelate and scale to output depth */
+ while (count--)
+ {
+ left = *decoded1 - (*decoded0 / 2);
+ right = left + *decoded0;
- *(decoded0++) = SCALE(left);
- *(decoded1++) = SCALE(right);
- }
+ *(decoded0++) = SCALE(left);
+ *(decoded1++) = SCALE(right);
}
}
return 0;
diff --git a/apps/codecs/demac/libdemac/entropy.c b/apps/codecs/demac/libdemac/entropy.c
index 54b5cc57b6..24f5932de6 100644
--- a/apps/codecs/demac/libdemac/entropy.c
+++ b/apps/codecs/demac/libdemac/entropy.c
@@ -430,10 +430,13 @@ void ICODE_ATTR_DEMAC entropy_decode(struct ape_ctx_t* ape_ctx,
ape_ctx->blocksdecoded += blockstodecode;
- if (ape_ctx->frameflags & APE_FRAMECODE_STEREO_SILENCE) {
+ if ((ape_ctx->frameflags & APE_FRAMECODE_LEFT_SILENCE)
+ && ((ape_ctx->frameflags & APE_FRAMECODE_RIGHT_SILENCE)
+ || (decoded1 == NULL))) {
/* We are pure silence, just memset the output buffer. */
memset(decoded0, 0, blockstodecode * sizeof(int32_t));
- memset(decoded1, 0, blockstodecode * sizeof(int32_t));
+ if (decoded1 != NULL)
+ memset(decoded1, 0, blockstodecode * sizeof(int32_t));
} else {
if (ape_ctx->fileversion > 3970) {
while (LIKELY(blockstodecode--)) {
diff --git a/apps/codecs/demac/libdemac/parser.h b/apps/codecs/demac/libdemac/parser.h
index 53157f7681..6f07deac12 100644
--- a/apps/codecs/demac/libdemac/parser.h
+++ b/apps/codecs/demac/libdemac/parser.h
@@ -50,7 +50,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
*/
#define APE_FRAMECODE_MONO_SILENCE 1
-#define APE_FRAMECODE_STEREO_SILENCE 3
+#define APE_FRAMECODE_LEFT_SILENCE 1 /* same as mono */
+#define APE_FRAMECODE_RIGHT_SILENCE 2
+#define APE_FRAMECODE_STEREO_SILENCE 3 /* combined */
#define APE_FRAMECODE_PSEUDO_STEREO 4
#define PREDICTOR_ORDER 8