From ff40af42babedfccd767ccf48a78e9a8eecb9a95 Mon Sep 17 00:00:00 2001 From: Dave Bryant Date: Mon, 6 Feb 2006 07:40:35 +0000 Subject: Streamlined WavPack decoder by utilizing dsp functionality where it was applicable (like mono conversion and clipping) and eliminating the conversion to 16-bit samples (everything is now returned as 28-bit). This reduced boost ratio (on iRiver) by about 7% on those tracks that require it. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8598 a1c6a512-1295-4272-9138-f99709370657 --- apps/codecs/libwavpack/unpack.c | 50 +++++++++++------------------------------ 1 file changed, 13 insertions(+), 37 deletions(-) (limited to 'apps/codecs/libwavpack/unpack.c') diff --git a/apps/codecs/libwavpack/unpack.c b/apps/codecs/libwavpack/unpack.c index a3a689ebb6..8f5c1ee46f 100644 --- a/apps/codecs/libwavpack/unpack.c +++ b/apps/codecs/libwavpack/unpack.c @@ -675,11 +675,17 @@ static void decorr_mono_pass (struct decorr_pass *dpp, long *buffer, long sample // it is clipped and shifted in a single operation. Otherwise, if it's // lossless then the last step is to apply the final shift (if any). +// This function has been modified for RockBox to return all integer samples +// as 28-bits, and clipping (for lossy mode) has been eliminated because this +// now happens in the dsp module. + static void fixup_samples (WavpackStream *wps, long *buffer, ulong sample_count) { ulong flags = wps->wphdr.flags; int shift = (flags & SHIFT_MASK) >> SHIFT_LSB; + shift += 20 - (flags & BYTES_STORED) * 8; // this provides RockBox with 28-bit data + if (flags & FLOAT_DATA) { float_values (wps, buffer, (flags & MONO_FLAG) ? sample_count : sample_count * 2); return; @@ -689,7 +695,6 @@ static void fixup_samples (WavpackStream *wps, long *buffer, ulong sample_count) ulong count = (flags & MONO_FLAG) ? sample_count : sample_count * 2; int sent_bits = wps->int32_sent_bits, zeros = wps->int32_zeros; int ones = wps->int32_ones, dups = wps->int32_dups; -// ulong mask = (1 << sent_bits) - 1; long *dptr = buffer; if (!(flags & HYBRID_FLAG) && !sent_bits && (zeros + ones + dups)) @@ -707,50 +712,21 @@ static void fixup_samples (WavpackStream *wps, long *buffer, ulong sample_count) shift += zeros + sent_bits + ones + dups; } - if (flags & HYBRID_FLAG) { - long min_value, max_value, min_shifted, max_shifted; - - switch (flags & BYTES_STORED) { - case 0: - min_shifted = (min_value = -128 >> shift) << shift; - max_shifted = (max_value = 127 >> shift) << shift; - break; - - case 1: - min_shifted = (min_value = -32768 >> shift) << shift; - max_shifted = (max_value = 32767 >> shift) << shift; - break; - - case 2: - min_shifted = (min_value = -8388608 >> shift) << shift; - max_shifted = (max_value = 8388607 >> shift) << shift; - break; - - case 3: - default: - min_shifted = (min_value = (long) 0x80000000 >> shift) << shift; - max_shifted = (max_value = (long) 0x7FFFFFFF >> shift) << shift; - break; - } - + if (shift > 0) { if (!(flags & MONO_FLAG)) sample_count *= 2; - while (sample_count--) { - if (*buffer < min_value) - *buffer++ = min_shifted; - else if (*buffer > max_value) - *buffer++ = max_shifted; - else - *buffer++ <<= shift; - } + while (sample_count--) + *buffer++ <<= shift; } - else if (shift) { + else if (shift < 0) { + shift = -shift; + if (!(flags & MONO_FLAG)) sample_count *= 2; while (sample_count--) - *buffer++ <<= shift; + *buffer++ >>= shift; } } -- cgit v1.2.3