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
This commit is contained in:
Jens Arnold 2008-12-21 01:29:36 +00:00
parent 558cce6027
commit 0bf6e36628
2 changed files with 38 additions and 35 deletions

View file

@ -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;
}
}
}

View file

@ -91,14 +91,14 @@ int ICODE_ATTR_DEMAC decode_chunk(struct ape_ctx_t* ape_ctx,
#endif
if ((ape_ctx->channels==1) || (ape_ctx->frameflags & APE_FRAMECODE_PSEUDO_STEREO)) {
if (ape_ctx->frameflags & APE_FRAMECODE_STEREO_SILENCE) {
if (ape_ctx->frameflags & APE_FRAMECODE_STEREO_SILENCE) {
entropy_decode(ape_ctx, inbuffer, firstbyte, bytesconsumed, decoded0, decoded1, count);
/* 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,26 +124,23 @@ 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) {
/* We are pure silence, so we're done. */
@ -177,18 +174,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;