summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/codecs/libwavpack/unpack.c50
-rw-r--r--apps/codecs/wavpack.c76
2 files changed, 19 insertions, 107 deletions
diff --git a/apps/codecs/libwavpack/unpack.c b/apps/codecs/libwavpack/unpack.c
index a3a689e..8f5c1ee 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;
}
}
diff --git a/apps/codecs/wavpack.c b/apps/codecs/wavpack.c
index 19c7581..ee21347 100644
--- a/apps/codecs/wavpack.c
+++ b/apps/codecs/wavpack.c
@@ -24,9 +24,6 @@ CODEC_HEADER
static struct codec_api *ci;
-#define FORCE_DSP_USE /* fixes some WavPack bugs; adds about 12% to boost ratio
- (when DSP would not have been used) */
-
#define BUFFER_SIZE 4096
static long temp_buffer [BUFFER_SIZE] IBSS_ATTR;
@@ -66,8 +63,7 @@ enum codec_status codec_start(struct codec_api* api)
ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*128));
ci->configure(DSP_DITHER, (bool *)false);
- ci->configure(DSP_SET_STEREO_MODE, (int *)STEREO_INTERLEAVED);
- ci->configure(DSP_SET_SAMPLE_DEPTH, (int *)(16));
+ ci->configure(DSP_SET_SAMPLE_DEPTH, (int *)(27)); // should be 28...
next_track:
@@ -79,20 +75,9 @@ enum codec_status codec_start(struct codec_api* api)
while (!*ci->taginfo_ready && !ci->stop_codec)
ci->sleep(1);
-#ifdef FORCE_DSP_USE
ci->configure(CODEC_DSP_ENABLE, (bool *)true);
ci->configure(DSP_SET_FREQUENCY, (long *)(ci->id3->frequency));
codec_set_replaygain(ci->id3);
-#else
- if (ci->id3->frequency != NATIVE_FREQUENCY ||
- ci->global_settings->replaygain) {
- ci->configure(CODEC_DSP_ENABLE, (bool *)true);
- ci->configure(DSP_SET_FREQUENCY, (long *)(ci->id3->frequency));
- codec_set_replaygain(ci->id3);
- }
- else
- ci->configure(CODEC_DSP_ENABLE, (bool *)false);
-#endif
/* Create a decoder instance */
wpc = WavpackOpenFileInput (read_callback, error);
@@ -104,6 +89,7 @@ enum codec_status codec_start(struct codec_api* api)
bps = WavpackGetBytesPerSample (wpc);
nchans = WavpackGetReducedChannels (wpc);
+ ci->configure(DSP_SET_STEREO_MODE, nchans == 2 ? (int *)STEREO_INTERLEAVED : (int *)STEREO_MONO);
sr_100 = ci->id3->frequency / 100;
ci->set_elapsed (0);
@@ -141,71 +127,21 @@ enum codec_status codec_start(struct codec_api* api)
ci->yield ();
}
- nsamples = WavpackUnpackSamples (wpc, temp_buffer, BUFFER_SIZE / 2);
+ nsamples = WavpackUnpackSamples (wpc, temp_buffer, BUFFER_SIZE / nchans);
if (!nsamples || ci->stop_codec || ci->reload_codec)
break;
- /* convert mono to stereo here, in place */
-
- if (nchans == 1) {
- long *dst = temp_buffer + (nsamples * 2);
- long *src = temp_buffer + nsamples;
- long count = nsamples;
-
- while (count--) {
- *--dst = *--src;
- *--dst = *src;
- if (!(count & 0x7f))
- ci->yield ();
- }
- }
-
- if (bps == 1) {
- short *dst = (short *) temp_buffer;
- long *src = temp_buffer;
- long count = nsamples;
-
- while (count--) {
- *dst++ = *src++ << 8;
- *dst++ = *src++ << 8;
- if (!(count & 0x7f))
- ci->yield ();
- }
- }
- else if (bps == 2) {
- short *dst = (short *) temp_buffer;
- long *src = temp_buffer;
- long count = nsamples;
-
- while (count--) {
- *dst++ = *src++;
- *dst++ = *src++;
- if (!(count & 0x7f))
- ci->yield ();
- }
- }
- else {
- short *dst = (short *) temp_buffer;
- int shift = (bps - 2) * 8;
- long *src = temp_buffer;
- long count = nsamples;
-
- while (count--) {
- *dst++ = *src++ >> shift;
- *dst++ = *src++ >> shift;
- if (!(count & 0x7f))
- ci->yield ();
- }
- }
+ ci->yield ();
if (ci->stop_codec || ci->reload_codec)
break;
- while (!ci->pcmbuf_insert ((char *) temp_buffer, nsamples * 4))
+ while (!ci->pcmbuf_insert ((char *) temp_buffer, nsamples * nchans * 4))
ci->sleep (1);
ci->set_elapsed (WavpackGetSampleIndex (wpc) / sr_100 * 10);
+ ci->yield ();
}
if (ci->request_next_track())