2005-02-25 17:05:30 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
2005-07-04 06:38:00 +00:00
|
|
|
// **** WAVPACK **** //
|
|
|
|
// Hybrid Lossless Wavefile Compressor //
|
|
|
|
// Copyright (c) 1998 - 2004 Conifer Software. //
|
|
|
|
// All Rights Reserved. //
|
2005-02-25 17:05:30 +00:00
|
|
|
// Distributed under the BSD Software License (see license.txt) //
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// unpack.c
|
|
|
|
|
|
|
|
// This module actually handles the decompression of the audio data, except
|
|
|
|
// for the entropy decoding which is handled by the words.c module. For
|
|
|
|
// maximum efficiency, the conversion is isolated to tight loops that handle
|
|
|
|
// an entire buffer.
|
|
|
|
|
|
|
|
#include "wavpack.h"
|
|
|
|
|
2005-07-04 06:38:00 +00:00
|
|
|
#include <stdlib.h>
|
2005-02-25 17:05:30 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2005-07-04 06:38:00 +00:00
|
|
|
static void strcpy_loc (char *dst, char *src) { while ((*dst++ = *src++) != 0); }
|
2005-05-17 06:32:49 +00:00
|
|
|
|
2005-02-25 17:05:30 +00:00
|
|
|
#define LOSSY_MUTE
|
|
|
|
|
|
|
|
///////////////////////////// executable code ////////////////////////////////
|
|
|
|
|
|
|
|
// This function initializes everything required to unpack a WavPack block
|
|
|
|
// and must be called before unpack_samples() is called to obtain audio data.
|
|
|
|
// It is assumed that the WavpackHeader has been read into the wps->wphdr
|
|
|
|
// (in the current WavpackStream). This is where all the metadata blocks are
|
|
|
|
// scanned up to the one containing the audio bitstream.
|
|
|
|
|
|
|
|
int unpack_init (WavpackContext *wpc)
|
|
|
|
{
|
|
|
|
WavpackStream *wps = &wpc->stream;
|
|
|
|
WavpackMetadata wpmd;
|
|
|
|
|
2006-03-26 22:54:15 +00:00
|
|
|
if (wps->wphdr.block_samples && wps->wphdr.block_index != (uint32_t) -1)
|
2005-07-04 06:38:00 +00:00
|
|
|
wps->sample_index = wps->wphdr.block_index;
|
2005-02-25 17:05:30 +00:00
|
|
|
|
|
|
|
wps->mute_error = FALSE;
|
|
|
|
wps->crc = 0xffffffff;
|
|
|
|
CLEAR (wps->wvbits);
|
|
|
|
CLEAR (wps->decorr_passes);
|
|
|
|
CLEAR (wps->w);
|
|
|
|
|
|
|
|
while (read_metadata_buff (wpc, &wpmd)) {
|
2005-07-04 06:38:00 +00:00
|
|
|
if (!process_metadata (wpc, &wpmd)) {
|
|
|
|
strcpy_loc (wpc->error_message, "invalid metadata!");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-02-25 17:05:30 +00:00
|
|
|
|
2005-07-04 06:38:00 +00:00
|
|
|
if (wpmd.id == ID_WV_BITSTREAM)
|
|
|
|
break;
|
2005-02-25 17:05:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (wps->wphdr.block_samples && !bs_is_open (&wps->wvbits)) {
|
2005-07-04 06:38:00 +00:00
|
|
|
strcpy_loc (wpc->error_message, "invalid WavPack file!");
|
|
|
|
return FALSE;
|
2005-02-25 17:05:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (wps->wphdr.block_samples) {
|
2005-07-04 06:38:00 +00:00
|
|
|
if ((wps->wphdr.flags & INT32_DATA) && wps->int32_sent_bits)
|
|
|
|
wpc->lossy_blocks = TRUE;
|
2005-02-25 17:05:30 +00:00
|
|
|
|
2005-07-04 06:38:00 +00:00
|
|
|
if ((wps->wphdr.flags & FLOAT_DATA) &&
|
|
|
|
wps->float_flags & (FLOAT_EXCEPTIONS | FLOAT_ZEROS_SENT | FLOAT_SHIFT_SENT | FLOAT_SHIFT_SAME))
|
|
|
|
wpc->lossy_blocks = TRUE;
|
2005-02-25 17:05:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This function initialzes the main bitstream for audio samples, which must
|
|
|
|
// be in the "wv" file.
|
|
|
|
|
|
|
|
int init_wv_bitstream (WavpackContext *wpc, WavpackMetadata *wpmd)
|
|
|
|
{
|
|
|
|
WavpackStream *wps = &wpc->stream;
|
|
|
|
|
|
|
|
if (wpmd->data)
|
2005-12-02 08:42:48 +00:00
|
|
|
bs_open_read (&wps->wvbits, wpmd->data, (unsigned char *) wpmd->data + wpmd->byte_length, NULL, 0);
|
2005-02-25 17:05:30 +00:00
|
|
|
else if (wpmd->byte_length)
|
2005-07-04 06:38:00 +00:00
|
|
|
bs_open_read (&wps->wvbits, wpc->read_buffer, wpc->read_buffer + sizeof (wpc->read_buffer),
|
|
|
|
wpc->infile, wpmd->byte_length + (wpmd->byte_length & 1));
|
2005-02-25 17:05:30 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read decorrelation terms from specified metadata block into the
|
|
|
|
// decorr_passes array. The terms range from -3 to 8, plus 17 & 18;
|
|
|
|
// other values are reserved and generate errors for now. The delta
|
|
|
|
// ranges from 0 to 7 with all values valid. Note that the terms are
|
|
|
|
// stored in the opposite order in the decorr_passes array compared
|
|
|
|
// to packing.
|
|
|
|
|
|
|
|
int read_decorr_terms (WavpackStream *wps, WavpackMetadata *wpmd)
|
|
|
|
{
|
|
|
|
int termcnt = wpmd->byte_length;
|
|
|
|
uchar *byteptr = wpmd->data;
|
|
|
|
struct decorr_pass *dpp;
|
|
|
|
|
|
|
|
if (termcnt > MAX_NTERMS)
|
2005-07-04 06:38:00 +00:00
|
|
|
return FALSE;
|
2005-02-25 17:05:30 +00:00
|
|
|
|
|
|
|
wps->num_terms = termcnt;
|
|
|
|
|
|
|
|
for (dpp = wps->decorr_passes + termcnt - 1; termcnt--; dpp--) {
|
2005-07-04 06:38:00 +00:00
|
|
|
dpp->term = (int)(*byteptr & 0x1f) - 5;
|
|
|
|
dpp->delta = (*byteptr++ >> 5) & 0x7;
|
2005-02-25 17:05:30 +00:00
|
|
|
|
2005-07-04 06:38:00 +00:00
|
|
|
if (!dpp->term || dpp->term < -3 || (dpp->term > MAX_TERM && dpp->term < 17) || dpp->term > 18)
|
|
|
|
return FALSE;
|
2005-02-25 17:05:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read decorrelation weights from specified metadata block into the
|
|
|
|
// decorr_passes array. The weights range +/-1024, but are rounded and
|
|
|
|
// truncated to fit in signed chars for metadata storage. Weights are
|
|
|
|
// separate for the two channels and are specified from the "last" term
|
|
|
|
// (first during encode). Unspecified weights are set to zero.
|
|
|
|
|
|
|
|
int read_decorr_weights (WavpackStream *wps, WavpackMetadata *wpmd)
|
|
|
|
{
|
|
|
|
int termcnt = wpmd->byte_length, tcount;
|
2005-12-19 03:12:20 +00:00
|
|
|
signed char *byteptr = wpmd->data;
|
2005-02-25 17:05:30 +00:00
|
|
|
struct decorr_pass *dpp;
|
|
|
|
|
2006-04-22 22:21:36 +00:00
|
|
|
if (!(wps->wphdr.flags & MONO_DATA))
|
2005-07-04 06:38:00 +00:00
|
|
|
termcnt /= 2;
|
2005-02-25 17:05:30 +00:00
|
|
|
|
|
|
|
if (termcnt > wps->num_terms)
|
2005-07-04 06:38:00 +00:00
|
|
|
return FALSE;
|
2005-02-25 17:05:30 +00:00
|
|
|
|
|
|
|
for (tcount = wps->num_terms, dpp = wps->decorr_passes; tcount--; dpp++)
|
2005-07-04 06:38:00 +00:00
|
|
|
dpp->weight_A = dpp->weight_B = 0;
|
2005-02-25 17:05:30 +00:00
|
|
|
|
|
|
|
while (--dpp >= wps->decorr_passes && termcnt--) {
|
2005-07-04 06:38:00 +00:00
|
|
|
dpp->weight_A = restore_weight (*byteptr++);
|
2005-02-25 17:05:30 +00:00
|
|
|
|
2006-04-22 22:21:36 +00:00
|
|
|
if (!(wps->wphdr.flags & MONO_DATA))
|
2005-07-04 06:38:00 +00:00
|
|
|
dpp->weight_B = restore_weight (*byteptr++);
|
2005-02-25 17:05:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read decorrelation samples from specified metadata block into the
|
|
|
|
// decorr_passes array. The samples are signed 32-bit values, but are
|
|
|
|
// converted to signed log2 values for storage in metadata. Values are
|
|
|
|
// stored for both channels and are specified from the "last" term
|
|
|
|
// (first during encode) with unspecified samples set to zero. The
|
|
|
|
// number of samples stored varies with the actual term value, so
|
|
|
|
// those must obviously come first in the metadata.
|
|
|
|
|
|
|
|
int read_decorr_samples (WavpackStream *wps, WavpackMetadata *wpmd)
|
|
|
|
{
|
|
|
|
uchar *byteptr = wpmd->data;
|
|
|
|
uchar *endptr = byteptr + wpmd->byte_length;
|
|
|
|
struct decorr_pass *dpp;
|
|
|
|
int tcount;
|
|
|
|
|
|
|
|
for (tcount = wps->num_terms, dpp = wps->decorr_passes; tcount--; dpp++) {
|
2005-07-04 06:38:00 +00:00
|
|
|
CLEAR (dpp->samples_A);
|
|
|
|
CLEAR (dpp->samples_B);
|
2005-02-25 17:05:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (wps->wphdr.version == 0x402 && (wps->wphdr.flags & HYBRID_FLAG)) {
|
2005-07-04 06:38:00 +00:00
|
|
|
byteptr += 2;
|
2005-02-25 17:05:30 +00:00
|
|
|
|
2006-04-22 22:21:36 +00:00
|
|
|
if (!(wps->wphdr.flags & MONO_DATA))
|
2005-07-04 06:38:00 +00:00
|
|
|
byteptr += 2;
|
2005-02-25 17:05:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while (dpp-- > wps->decorr_passes && byteptr < endptr)
|
2005-07-04 06:38:00 +00:00
|
|
|
if (dpp->term > MAX_TERM) {
|
|
|
|
dpp->samples_A [0] = exp2s ((short)(byteptr [0] + (byteptr [1] << 8)));
|
|
|
|
dpp->samples_A [1] = exp2s ((short)(byteptr [2] + (byteptr [3] << 8)));
|
|
|
|
byteptr += 4;
|
|
|
|
|
2006-04-22 22:21:36 +00:00
|
|
|
if (!(wps->wphdr.flags & MONO_DATA)) {
|
2005-07-04 06:38:00 +00:00
|
|
|
dpp->samples_B [0] = exp2s ((short)(byteptr [0] + (byteptr [1] << 8)));
|
|
|
|
dpp->samples_B [1] = exp2s ((short)(byteptr [2] + (byteptr [3] << 8)));
|
|
|
|
byteptr += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (dpp->term < 0) {
|
|
|
|
dpp->samples_A [0] = exp2s ((short)(byteptr [0] + (byteptr [1] << 8)));
|
|
|
|
dpp->samples_B [0] = exp2s ((short)(byteptr [2] + (byteptr [3] << 8)));
|
|
|
|
byteptr += 4;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int m = 0, cnt = dpp->term;
|
|
|
|
|
|
|
|
while (cnt--) {
|
|
|
|
dpp->samples_A [m] = exp2s ((short)(byteptr [0] + (byteptr [1] << 8)));
|
|
|
|
byteptr += 2;
|
|
|
|
|
2006-04-22 22:21:36 +00:00
|
|
|
if (!(wps->wphdr.flags & MONO_DATA)) {
|
2005-07-04 06:38:00 +00:00
|
|
|
dpp->samples_B [m] = exp2s ((short)(byteptr [0] + (byteptr [1] << 8)));
|
|
|
|
byteptr += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
m++;
|
|
|
|
}
|
|
|
|
}
|
2005-02-25 17:05:30 +00:00
|
|
|
|
|
|
|
return byteptr == endptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read the int32 data from the specified metadata into the specified stream.
|
|
|
|
// This data is used for integer data that has more than 24 bits of magnitude
|
|
|
|
// or, in some cases, used to eliminate redundant bits from any audio stream.
|
|
|
|
|
|
|
|
int read_int32_info (WavpackStream *wps, WavpackMetadata *wpmd)
|
|
|
|
{
|
|
|
|
int bytecnt = wpmd->byte_length;
|
|
|
|
char *byteptr = wpmd->data;
|
|
|
|
|
|
|
|
if (bytecnt != 4)
|
2005-07-04 06:38:00 +00:00
|
|
|
return FALSE;
|
2005-02-25 17:05:30 +00:00
|
|
|
|
|
|
|
wps->int32_sent_bits = *byteptr++;
|
|
|
|
wps->int32_zeros = *byteptr++;
|
|
|
|
wps->int32_ones = *byteptr++;
|
|
|
|
wps->int32_dups = *byteptr;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read multichannel information from metadata. The first byte is the total
|
|
|
|
// number of channels and the following bytes represent the channel_mask
|
|
|
|
// as described for Microsoft WAVEFORMATEX.
|
|
|
|
|
|
|
|
int read_channel_info (WavpackContext *wpc, WavpackMetadata *wpmd)
|
|
|
|
{
|
|
|
|
int bytecnt = wpmd->byte_length, shift = 0;
|
|
|
|
char *byteptr = wpmd->data;
|
2006-03-26 22:54:15 +00:00
|
|
|
uint32_t mask = 0;
|
2005-02-25 17:05:30 +00:00
|
|
|
|
|
|
|
if (!bytecnt || bytecnt > 5)
|
2005-07-04 06:38:00 +00:00
|
|
|
return FALSE;
|
2005-02-25 17:05:30 +00:00
|
|
|
|
|
|
|
wpc->config.num_channels = *byteptr++;
|
|
|
|
|
|
|
|
while (--bytecnt) {
|
2006-03-26 22:54:15 +00:00
|
|
|
mask |= (uint32_t) *byteptr++ << shift;
|
2005-07-04 06:38:00 +00:00
|
|
|
shift += 8;
|
2005-02-25 17:05:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wpc->config.channel_mask = mask;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read configuration information from metadata.
|
|
|
|
|
|
|
|
int read_config_info (WavpackContext *wpc, WavpackMetadata *wpmd)
|
|
|
|
{
|
|
|
|
int bytecnt = wpmd->byte_length;
|
|
|
|
uchar *byteptr = wpmd->data;
|
|
|
|
|
|
|
|
if (bytecnt >= 3) {
|
2005-07-04 06:38:00 +00:00
|
|
|
wpc->config.flags &= 0xff;
|
2006-03-26 22:54:15 +00:00
|
|
|
wpc->config.flags |= (int32_t) *byteptr++ << 8;
|
|
|
|
wpc->config.flags |= (int32_t) *byteptr++ << 16;
|
|
|
|
wpc->config.flags |= (int32_t) *byteptr << 24;
|
2005-02-25 17:05:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This monster actually unpacks the WavPack bitstream(s) into the specified
|
|
|
|
// buffer as 32-bit integers or floats (depending on orignal data). Lossy
|
|
|
|
// samples will be clipped to their original limits (i.e. 8-bit samples are
|
2006-03-26 22:54:15 +00:00
|
|
|
// clipped to -128/+127) but are still returned in int32_ts. It is up to the
|
2005-02-25 17:05:30 +00:00
|
|
|
// caller to potentially reformat this for the final output including any
|
|
|
|
// multichannel distribution, block alignment or endian compensation. The
|
|
|
|
// function unpack_init() must have been called and the entire WavPack block
|
|
|
|
// must still be visible (although wps->blockbuff will not be accessed again).
|
|
|
|
// For maximum clarity, the function is broken up into segments that handle
|
|
|
|
// various modes. This makes for a few extra infrequent flag checks, but
|
|
|
|
// makes the code easier to follow because the nesting does not become so
|
|
|
|
// deep. For maximum efficiency, the conversion is isolated to tight loops
|
|
|
|
// that handle an entire buffer. The function returns the total number of
|
|
|
|
// samples unpacked, which can be less than the number requested if an error
|
|
|
|
// occurs or the end of the block is reached.
|
|
|
|
|
2005-07-18 13:09:05 +00:00
|
|
|
#if defined(CPU_COLDFIRE) && !defined(SIMULATOR)
|
2006-03-26 22:54:15 +00:00
|
|
|
extern void decorr_stereo_pass_cont_mcf5249 (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count);
|
2006-02-23 20:53:59 +00:00
|
|
|
#elif defined(CPU_ARM) && !defined(SIMULATOR)
|
2006-03-26 22:54:15 +00:00
|
|
|
extern void decorr_stereo_pass_cont_arm (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count);
|
|
|
|
extern void decorr_stereo_pass_cont_arml (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count);
|
2005-05-31 07:56:28 +00:00
|
|
|
#else
|
2006-03-26 22:54:15 +00:00
|
|
|
static void decorr_stereo_pass_cont (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count);
|
2005-05-31 07:56:28 +00:00
|
|
|
#endif
|
|
|
|
|
2006-03-26 22:54:15 +00:00
|
|
|
static void decorr_mono_pass (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count);
|
|
|
|
static void decorr_stereo_pass (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count);
|
|
|
|
static void fixup_samples (WavpackStream *wps, int32_t *buffer, uint32_t sample_count);
|
2005-02-25 17:05:30 +00:00
|
|
|
|
2006-03-26 22:54:15 +00:00
|
|
|
int32_t unpack_samples (WavpackContext *wpc, int32_t *buffer, uint32_t sample_count)
|
2005-02-25 17:05:30 +00:00
|
|
|
{
|
|
|
|
WavpackStream *wps = &wpc->stream;
|
2006-03-26 22:54:15 +00:00
|
|
|
uint32_t flags = wps->wphdr.flags, crc = wps->crc, i;
|
|
|
|
int32_t mute_limit = (1L << ((flags & MAG_MASK) >> MAG_LSB)) + 2;
|
2005-02-25 17:05:30 +00:00
|
|
|
struct decorr_pass *dpp;
|
2006-03-26 22:54:15 +00:00
|
|
|
int32_t *bptr, *eptr;
|
2005-05-17 06:32:49 +00:00
|
|
|
int tcount;
|
2005-02-25 17:05:30 +00:00
|
|
|
|
|
|
|
if (wps->sample_index + sample_count > wps->wphdr.block_index + wps->wphdr.block_samples)
|
2005-07-04 06:38:00 +00:00
|
|
|
sample_count = wps->wphdr.block_index + wps->wphdr.block_samples - wps->sample_index;
|
2005-02-25 17:05:30 +00:00
|
|
|
|
|
|
|
if (wps->mute_error) {
|
2005-07-04 06:38:00 +00:00
|
|
|
memset (buffer, 0, sample_count * (flags & MONO_FLAG ? 4 : 8));
|
|
|
|
wps->sample_index += sample_count;
|
|
|
|
return sample_count;
|
2005-02-25 17:05:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & HYBRID_FLAG)
|
2005-07-04 06:38:00 +00:00
|
|
|
mute_limit *= 2;
|
2005-02-25 17:05:30 +00:00
|
|
|
|
|
|
|
///////////////////// handle version 4 mono data /////////////////////////
|
|
|
|
|
2006-04-22 22:21:36 +00:00
|
|
|
if (flags & MONO_DATA) {
|
2005-07-04 06:38:00 +00:00
|
|
|
eptr = buffer + sample_count;
|
|
|
|
i = get_words (buffer, sample_count, flags, &wps->w, &wps->wvbits);
|
2005-02-25 17:05:30 +00:00
|
|
|
|
2005-07-04 06:38:00 +00:00
|
|
|
for (tcount = wps->num_terms, dpp = wps->decorr_passes; tcount--; dpp++)
|
|
|
|
decorr_mono_pass (dpp, buffer, sample_count);
|
2005-02-25 17:05:30 +00:00
|
|
|
|
2005-07-04 06:38:00 +00:00
|
|
|
for (bptr = buffer; bptr < eptr; ++bptr) {
|
|
|
|
if (labs (bptr [0]) > mute_limit) {
|
|
|
|
i = bptr - buffer;
|
|
|
|
break;
|
|
|
|
}
|
2005-02-25 17:05:30 +00:00
|
|
|
|
2005-07-04 06:38:00 +00:00
|
|
|
crc = crc * 3 + bptr [0];
|
|
|
|
}
|
2005-05-17 06:32:49 +00:00
|
|
|
}
|
2005-02-25 17:05:30 +00:00
|
|
|
|
|
|
|
//////////////////// handle version 4 stereo data ////////////////////////
|
|
|
|
|
2005-05-17 06:32:49 +00:00
|
|
|
else {
|
2005-07-04 06:38:00 +00:00
|
|
|
eptr = buffer + (sample_count * 2);
|
|
|
|
i = get_words (buffer, sample_count, flags, &wps->w, &wps->wvbits);
|
|
|
|
|
|
|
|
if (sample_count < 16)
|
|
|
|
for (tcount = wps->num_terms, dpp = wps->decorr_passes; tcount--; dpp++)
|
|
|
|
decorr_stereo_pass (dpp, buffer, sample_count);
|
|
|
|
else
|
|
|
|
for (tcount = wps->num_terms, dpp = wps->decorr_passes; tcount--; dpp++) {
|
|
|
|
decorr_stereo_pass (dpp, buffer, 8);
|
2005-07-18 13:09:05 +00:00
|
|
|
#if defined(CPU_COLDFIRE) && !defined(SIMULATOR)
|
2005-07-04 06:38:00 +00:00
|
|
|
decorr_stereo_pass_cont_mcf5249 (dpp, buffer + 16, sample_count - 8);
|
2006-02-23 20:53:59 +00:00
|
|
|
#elif defined(CPU_ARM) && !defined(SIMULATOR)
|
2006-02-26 08:22:34 +00:00
|
|
|
if (((flags & MAG_MASK) >> MAG_LSB) > 15)
|
|
|
|
decorr_stereo_pass_cont_arml (dpp, buffer + 16, sample_count - 8);
|
|
|
|
else
|
|
|
|
decorr_stereo_pass_cont_arm (dpp, buffer + 16, sample_count - 8);
|
2005-05-31 07:56:28 +00:00
|
|
|
#else
|
2005-07-04 06:38:00 +00:00
|
|
|
decorr_stereo_pass_cont (dpp, buffer + 16, sample_count - 8);
|
2005-05-31 07:56:28 +00:00
|
|
|
#endif
|
2005-07-04 06:38:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & JOINT_STEREO)
|
|
|
|
for (bptr = buffer; bptr < eptr; bptr += 2) {
|
|
|
|
bptr [0] += (bptr [1] -= (bptr [0] >> 1));
|
|
|
|
|
|
|
|
if (labs (bptr [0]) > mute_limit || labs (bptr [1]) > mute_limit) {
|
|
|
|
i = (bptr - buffer) / 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
crc = (crc * 3 + bptr [0]) * 3 + bptr [1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
for (bptr = buffer; bptr < eptr; bptr += 2) {
|
|
|
|
if (labs (bptr [0]) > mute_limit || labs (bptr [1]) > mute_limit) {
|
|
|
|
i = (bptr - buffer) / 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
crc = (crc * 3 + bptr [0]) * 3 + bptr [1];
|
|
|
|
}
|
2005-05-17 06:32:49 +00:00
|
|
|
}
|
2005-02-25 17:05:30 +00:00
|
|
|
|
|
|
|
if (i != sample_count) {
|
2005-07-04 06:38:00 +00:00
|
|
|
memset (buffer, 0, sample_count * (flags & MONO_FLAG ? 4 : 8));
|
|
|
|
wps->mute_error = TRUE;
|
|
|
|
i = sample_count;
|
2005-02-25 17:05:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fixup_samples (wps, buffer, i);
|
|
|
|
|
|
|
|
if (flags & FLOAT_DATA)
|
2006-04-22 22:21:36 +00:00
|
|
|
float_normalize (buffer, (flags & MONO_DATA) ? i : i * 2,
|
2005-07-04 06:38:00 +00:00
|
|
|
127 - wps->float_norm_exp + wpc->norm_offset);
|
2005-02-25 17:05:30 +00:00
|
|
|
|
2006-04-22 22:21:36 +00:00
|
|
|
if (flags & FALSE_STEREO) {
|
|
|
|
int32_t *dptr = buffer + i * 2;
|
|
|
|
int32_t *sptr = buffer + i;
|
|
|
|
int32_t c = i;
|
|
|
|
|
|
|
|
while (c--) {
|
|
|
|
*--dptr = *--sptr;
|
|
|
|
*--dptr = *sptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-25 17:05:30 +00:00
|
|
|
wps->sample_index += i;
|
|
|
|
wps->crc = crc;
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2006-03-26 22:54:15 +00:00
|
|
|
static void decorr_stereo_pass (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count)
|
2005-05-17 06:32:49 +00:00
|
|
|
{
|
2006-03-26 22:54:15 +00:00
|
|
|
int32_t delta = dpp->delta, weight_A = dpp->weight_A, weight_B = dpp->weight_B;
|
|
|
|
int32_t *bptr, *eptr = buffer + (sample_count * 2), sam_A, sam_B;
|
2005-05-17 06:32:49 +00:00
|
|
|
int m, k;
|
|
|
|
|
|
|
|
switch (dpp->term) {
|
|
|
|
|
2005-07-04 06:38:00 +00:00
|
|
|
case 17:
|
|
|
|
for (bptr = buffer; bptr < eptr; bptr += 2) {
|
|
|
|
sam_A = 2 * dpp->samples_A [0] - dpp->samples_A [1];
|
|
|
|
dpp->samples_A [1] = dpp->samples_A [0];
|
|
|
|
dpp->samples_A [0] = apply_weight (weight_A, sam_A) + bptr [0];
|
|
|
|
update_weight (weight_A, delta, sam_A, bptr [0]);
|
|
|
|
bptr [0] = dpp->samples_A [0];
|
|
|
|
|
|
|
|
sam_A = 2 * dpp->samples_B [0] - dpp->samples_B [1];
|
|
|
|
dpp->samples_B [1] = dpp->samples_B [0];
|
|
|
|
dpp->samples_B [0] = apply_weight (weight_B, sam_A) + bptr [1];
|
|
|
|
update_weight (weight_B, delta, sam_A, bptr [1]);
|
|
|
|
bptr [1] = dpp->samples_B [0];
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 18:
|
|
|
|
for (bptr = buffer; bptr < eptr; bptr += 2) {
|
|
|
|
sam_A = (3 * dpp->samples_A [0] - dpp->samples_A [1]) >> 1;
|
|
|
|
dpp->samples_A [1] = dpp->samples_A [0];
|
|
|
|
dpp->samples_A [0] = apply_weight (weight_A, sam_A) + bptr [0];
|
|
|
|
update_weight (weight_A, delta, sam_A, bptr [0]);
|
|
|
|
bptr [0] = dpp->samples_A [0];
|
|
|
|
|
|
|
|
sam_A = (3 * dpp->samples_B [0] - dpp->samples_B [1]) >> 1;
|
|
|
|
dpp->samples_B [1] = dpp->samples_B [0];
|
|
|
|
dpp->samples_B [0] = apply_weight (weight_B, sam_A) + bptr [1];
|
|
|
|
update_weight (weight_B, delta, sam_A, bptr [1]);
|
|
|
|
bptr [1] = dpp->samples_B [0];
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
for (m = 0, k = dpp->term & (MAX_TERM - 1), bptr = buffer; bptr < eptr; bptr += 2) {
|
|
|
|
sam_A = dpp->samples_A [m];
|
|
|
|
dpp->samples_A [k] = apply_weight (weight_A, sam_A) + bptr [0];
|
|
|
|
update_weight (weight_A, delta, sam_A, bptr [0]);
|
|
|
|
bptr [0] = dpp->samples_A [k];
|
|
|
|
|
|
|
|
sam_A = dpp->samples_B [m];
|
|
|
|
dpp->samples_B [k] = apply_weight (weight_B, sam_A) + bptr [1];
|
|
|
|
update_weight (weight_B, delta, sam_A, bptr [1]);
|
|
|
|
bptr [1] = dpp->samples_B [k];
|
|
|
|
|
|
|
|
m = (m + 1) & (MAX_TERM - 1);
|
|
|
|
k = (k + 1) & (MAX_TERM - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m) {
|
2006-03-26 22:54:15 +00:00
|
|
|
int32_t temp_samples [MAX_TERM];
|
2005-07-04 06:38:00 +00:00
|
|
|
|
|
|
|
memcpy (temp_samples, dpp->samples_A, sizeof (dpp->samples_A));
|
|
|
|
|
|
|
|
for (k = 0; k < MAX_TERM; k++, m++)
|
|
|
|
dpp->samples_A [k] = temp_samples [m & (MAX_TERM - 1)];
|
|
|
|
|
|
|
|
memcpy (temp_samples, dpp->samples_B, sizeof (dpp->samples_B));
|
|
|
|
|
|
|
|
for (k = 0; k < MAX_TERM; k++, m++)
|
|
|
|
dpp->samples_B [k] = temp_samples [m & (MAX_TERM - 1)];
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case -1:
|
|
|
|
for (bptr = buffer; bptr < eptr; bptr += 2) {
|
|
|
|
sam_A = bptr [0] + apply_weight (weight_A, dpp->samples_A [0]);
|
|
|
|
update_weight_clip (weight_A, delta, dpp->samples_A [0], bptr [0]);
|
|
|
|
bptr [0] = sam_A;
|
|
|
|
dpp->samples_A [0] = bptr [1] + apply_weight (weight_B, sam_A);
|
|
|
|
update_weight_clip (weight_B, delta, sam_A, bptr [1]);
|
|
|
|
bptr [1] = dpp->samples_A [0];
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case -2:
|
|
|
|
for (bptr = buffer; bptr < eptr; bptr += 2) {
|
|
|
|
sam_B = bptr [1] + apply_weight (weight_B, dpp->samples_B [0]);
|
|
|
|
update_weight_clip (weight_B, delta, dpp->samples_B [0], bptr [1]);
|
|
|
|
bptr [1] = sam_B;
|
|
|
|
dpp->samples_B [0] = bptr [0] + apply_weight (weight_A, sam_B);
|
|
|
|
update_weight_clip (weight_A, delta, sam_B, bptr [0]);
|
|
|
|
bptr [0] = dpp->samples_B [0];
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case -3:
|
|
|
|
for (bptr = buffer; bptr < eptr; bptr += 2) {
|
|
|
|
sam_A = bptr [0] + apply_weight (weight_A, dpp->samples_A [0]);
|
|
|
|
update_weight_clip (weight_A, delta, dpp->samples_A [0], bptr [0]);
|
|
|
|
sam_B = bptr [1] + apply_weight (weight_B, dpp->samples_B [0]);
|
|
|
|
update_weight_clip (weight_B, delta, dpp->samples_B [0], bptr [1]);
|
|
|
|
bptr [0] = dpp->samples_B [0] = sam_A;
|
|
|
|
bptr [1] = dpp->samples_A [0] = sam_B;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2005-05-17 06:32:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dpp->weight_A = weight_A;
|
|
|
|
dpp->weight_B = weight_B;
|
|
|
|
}
|
|
|
|
|
2006-02-23 20:53:59 +00:00
|
|
|
#if (!defined(CPU_COLDFIRE) && !defined(CPU_ARM)) || defined(SIMULATOR)
|
2005-05-31 07:56:28 +00:00
|
|
|
|
2006-03-26 22:54:15 +00:00
|
|
|
static void decorr_stereo_pass_cont (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count)
|
2005-05-17 06:32:49 +00:00
|
|
|
{
|
2006-03-26 22:54:15 +00:00
|
|
|
int32_t delta = dpp->delta, weight_A = dpp->weight_A, weight_B = dpp->weight_B;
|
|
|
|
int32_t *bptr, *tptr, *eptr = buffer + (sample_count * 2), sam_A, sam_B;
|
2005-05-31 07:56:28 +00:00
|
|
|
int k, i;
|
2005-05-17 06:32:49 +00:00
|
|
|
|
|
|
|
switch (dpp->term) {
|
|
|
|
|
2005-07-04 06:38:00 +00:00
|
|
|
case 17:
|
|
|
|
for (bptr = buffer; bptr < eptr; bptr += 2) {
|
|
|
|
sam_A = 2 * bptr [-2] - bptr [-4];
|
|
|
|
bptr [0] = apply_weight (weight_A, sam_A) + (sam_B = bptr [0]);
|
|
|
|
update_weight (weight_A, delta, sam_A, sam_B);
|
|
|
|
|
|
|
|
sam_A = 2 * bptr [-1] - bptr [-3];
|
|
|
|
bptr [1] = apply_weight (weight_B, sam_A) + (sam_B = bptr [1]);
|
|
|
|
update_weight (weight_B, delta, sam_A, sam_B);
|
|
|
|
}
|
|
|
|
|
|
|
|
dpp->samples_B [0] = bptr [-1];
|
|
|
|
dpp->samples_A [0] = bptr [-2];
|
|
|
|
dpp->samples_B [1] = bptr [-3];
|
|
|
|
dpp->samples_A [1] = bptr [-4];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 18:
|
|
|
|
for (bptr = buffer; bptr < eptr; bptr += 2) {
|
|
|
|
sam_A = (3 * bptr [-2] - bptr [-4]) >> 1;
|
|
|
|
bptr [0] = apply_weight (weight_A, sam_A) + (sam_B = bptr [0]);
|
|
|
|
update_weight (weight_A, delta, sam_A, sam_B);
|
|
|
|
|
|
|
|
sam_A = (3 * bptr [-1] - bptr [-3]) >> 1;
|
|
|
|
bptr [1] = apply_weight (weight_B, sam_A) + (sam_B = bptr [1]);
|
|
|
|
update_weight (weight_B, delta, sam_A, sam_B);
|
|
|
|
}
|
|
|
|
|
|
|
|
dpp->samples_B [0] = bptr [-1];
|
|
|
|
dpp->samples_A [0] = bptr [-2];
|
|
|
|
dpp->samples_B [1] = bptr [-3];
|
|
|
|
dpp->samples_A [1] = bptr [-4];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
for (bptr = buffer, tptr = buffer - (dpp->term * 2); bptr < eptr; bptr += 2, tptr += 2) {
|
|
|
|
bptr [0] = apply_weight (weight_A, tptr [0]) + (sam_A = bptr [0]);
|
|
|
|
update_weight (weight_A, delta, tptr [0], sam_A);
|
|
|
|
|
|
|
|
bptr [1] = apply_weight (weight_B, tptr [1]) + (sam_A = bptr [1]);
|
|
|
|
update_weight (weight_B, delta, tptr [1], sam_A);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (k = dpp->term - 1, i = 8; i--; k--) {
|
|
|
|
dpp->samples_B [k & (MAX_TERM - 1)] = *--bptr;
|
|
|
|
dpp->samples_A [k & (MAX_TERM - 1)] = *--bptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case -1:
|
|
|
|
for (bptr = buffer; bptr < eptr; bptr += 2) {
|
|
|
|
bptr [0] = apply_weight (weight_A, bptr [-1]) + (sam_A = bptr [0]);
|
|
|
|
update_weight_clip (weight_A, delta, bptr [-1], sam_A);
|
|
|
|
bptr [1] = apply_weight (weight_B, bptr [0]) + (sam_A = bptr [1]);
|
|
|
|
update_weight_clip (weight_B, delta, bptr [0], sam_A);
|
|
|
|
}
|
|
|
|
|
|
|
|
dpp->samples_A [0] = bptr [-1];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case -2:
|
|
|
|
for (bptr = buffer; bptr < eptr; bptr += 2) {
|
|
|
|
bptr [1] = apply_weight (weight_B, bptr [-2]) + (sam_A = bptr [1]);
|
|
|
|
update_weight_clip (weight_B, delta, bptr [-2], sam_A);
|
|
|
|
bptr [0] = apply_weight (weight_A, bptr [1]) + (sam_A = bptr [0]);
|
|
|
|
update_weight_clip (weight_A, delta, bptr [1], sam_A);
|
|
|
|
}
|
|
|
|
|
|
|
|
dpp->samples_B [0] = bptr [-2];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case -3:
|
|
|
|
for (bptr = buffer; bptr < eptr; bptr += 2) {
|
|
|
|
bptr [0] = apply_weight (weight_A, bptr [-1]) + (sam_A = bptr [0]);
|
|
|
|
update_weight_clip (weight_A, delta, bptr [-1], sam_A);
|
|
|
|
bptr [1] = apply_weight (weight_B, bptr [-2]) + (sam_A = bptr [1]);
|
|
|
|
update_weight_clip (weight_B, delta, bptr [-2], sam_A);
|
|
|
|
}
|
|
|
|
|
|
|
|
dpp->samples_A [0] = bptr [-1];
|
|
|
|
dpp->samples_B [0] = bptr [-2];
|
|
|
|
break;
|
2005-05-17 06:32:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dpp->weight_A = weight_A;
|
|
|
|
dpp->weight_B = weight_B;
|
|
|
|
}
|
|
|
|
|
2005-05-31 07:56:28 +00:00
|
|
|
#endif
|
|
|
|
|
2006-03-26 22:54:15 +00:00
|
|
|
static void decorr_mono_pass (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count)
|
2005-05-17 06:32:49 +00:00
|
|
|
{
|
2006-03-26 22:54:15 +00:00
|
|
|
int32_t delta = dpp->delta, weight_A = dpp->weight_A;
|
|
|
|
int32_t *bptr, *eptr = buffer + sample_count, sam_A;
|
2005-05-17 06:32:49 +00:00
|
|
|
int m, k;
|
|
|
|
|
|
|
|
switch (dpp->term) {
|
|
|
|
|
2005-07-04 06:38:00 +00:00
|
|
|
case 17:
|
|
|
|
for (bptr = buffer; bptr < eptr; bptr++) {
|
|
|
|
sam_A = 2 * dpp->samples_A [0] - dpp->samples_A [1];
|
|
|
|
dpp->samples_A [1] = dpp->samples_A [0];
|
|
|
|
dpp->samples_A [0] = apply_weight (weight_A, sam_A) + bptr [0];
|
|
|
|
update_weight (weight_A, delta, sam_A, bptr [0]);
|
|
|
|
bptr [0] = dpp->samples_A [0];
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 18:
|
|
|
|
for (bptr = buffer; bptr < eptr; bptr++) {
|
|
|
|
sam_A = (3 * dpp->samples_A [0] - dpp->samples_A [1]) >> 1;
|
|
|
|
dpp->samples_A [1] = dpp->samples_A [0];
|
|
|
|
dpp->samples_A [0] = apply_weight (weight_A, sam_A) + bptr [0];
|
|
|
|
update_weight (weight_A, delta, sam_A, bptr [0]);
|
|
|
|
bptr [0] = dpp->samples_A [0];
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
for (m = 0, k = dpp->term & (MAX_TERM - 1), bptr = buffer; bptr < eptr; bptr++) {
|
|
|
|
sam_A = dpp->samples_A [m];
|
|
|
|
dpp->samples_A [k] = apply_weight (weight_A, sam_A) + bptr [0];
|
|
|
|
update_weight (weight_A, delta, sam_A, bptr [0]);
|
|
|
|
bptr [0] = dpp->samples_A [k];
|
|
|
|
m = (m + 1) & (MAX_TERM - 1);
|
|
|
|
k = (k + 1) & (MAX_TERM - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m) {
|
2006-03-26 22:54:15 +00:00
|
|
|
int32_t temp_samples [MAX_TERM];
|
2005-07-04 06:38:00 +00:00
|
|
|
|
|
|
|
memcpy (temp_samples, dpp->samples_A, sizeof (dpp->samples_A));
|
|
|
|
|
|
|
|
for (k = 0; k < MAX_TERM; k++, m++)
|
|
|
|
dpp->samples_A [k] = temp_samples [m & (MAX_TERM - 1)];
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2005-05-17 06:32:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dpp->weight_A = weight_A;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-25 17:05:30 +00:00
|
|
|
// This is a helper function for unpack_samples() that applies several final
|
|
|
|
// operations. First, if the data is 32-bit float data, then that conversion
|
|
|
|
// is done in the float.c module (whether lossy or lossless) and we return.
|
|
|
|
// Otherwise, if the extended integer data applies, then that operation is
|
|
|
|
// executed first. If the unpacked data is lossy (and not corrected) then
|
|
|
|
// 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).
|
|
|
|
|
2006-02-06 07:40:35 +00:00
|
|
|
// 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.
|
|
|
|
|
2006-03-26 22:54:15 +00:00
|
|
|
static void fixup_samples (WavpackStream *wps, int32_t *buffer, uint32_t sample_count)
|
2005-02-25 17:05:30 +00:00
|
|
|
{
|
2006-03-26 22:54:15 +00:00
|
|
|
uint32_t flags = wps->wphdr.flags;
|
2005-02-25 17:05:30 +00:00
|
|
|
int shift = (flags & SHIFT_MASK) >> SHIFT_LSB;
|
|
|
|
|
2006-03-26 22:54:15 +00:00
|
|
|
shift += 21 - (flags & BYTES_STORED) * 8; // this provides RockBox with 28-bit (+sign)
|
2006-02-06 07:40:35 +00:00
|
|
|
|
2005-02-25 17:05:30 +00:00
|
|
|
if (flags & FLOAT_DATA) {
|
2006-04-22 22:21:36 +00:00
|
|
|
float_values (wps, buffer, (flags & MONO_DATA) ? sample_count : sample_count * 2);
|
2005-07-04 06:38:00 +00:00
|
|
|
return;
|
2005-02-25 17:05:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & INT32_DATA) {
|
2006-04-22 22:21:36 +00:00
|
|
|
uint32_t count = (flags & MONO_DATA) ? sample_count : sample_count * 2;
|
2005-07-04 06:38:00 +00:00
|
|
|
int sent_bits = wps->int32_sent_bits, zeros = wps->int32_zeros;
|
|
|
|
int ones = wps->int32_ones, dups = wps->int32_dups;
|
2006-03-26 22:54:15 +00:00
|
|
|
int32_t *dptr = buffer;
|
2005-07-04 06:38:00 +00:00
|
|
|
|
|
|
|
if (!(flags & HYBRID_FLAG) && !sent_bits && (zeros + ones + dups))
|
|
|
|
while (count--) {
|
|
|
|
if (zeros)
|
|
|
|
*dptr <<= zeros;
|
|
|
|
else if (ones)
|
|
|
|
*dptr = ((*dptr + 1) << ones) - 1;
|
|
|
|
else if (dups)
|
|
|
|
*dptr = ((*dptr + (*dptr & 1)) << dups) - (*dptr & 1);
|
|
|
|
|
|
|
|
dptr++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
shift += zeros + sent_bits + ones + dups;
|
2005-02-25 17:05:30 +00:00
|
|
|
}
|
|
|
|
|
2006-02-06 07:40:35 +00:00
|
|
|
if (shift > 0) {
|
2006-04-22 22:21:36 +00:00
|
|
|
if (!(flags & MONO_DATA))
|
2005-07-04 06:38:00 +00:00
|
|
|
sample_count *= 2;
|
|
|
|
|
2006-02-06 07:40:35 +00:00
|
|
|
while (sample_count--)
|
|
|
|
*buffer++ <<= shift;
|
2005-02-25 17:05:30 +00:00
|
|
|
}
|
2006-02-06 07:40:35 +00:00
|
|
|
else if (shift < 0) {
|
|
|
|
shift = -shift;
|
|
|
|
|
2006-04-22 22:21:36 +00:00
|
|
|
if (!(flags & MONO_DATA))
|
2005-07-04 06:38:00 +00:00
|
|
|
sample_count *= 2;
|
2005-02-25 17:05:30 +00:00
|
|
|
|
2005-07-04 06:38:00 +00:00
|
|
|
while (sample_count--)
|
2006-02-06 07:40:35 +00:00
|
|
|
*buffer++ >>= shift;
|
2005-02-25 17:05:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This function checks the crc value(s) for an unpacked block, returning the
|
|
|
|
// number of actual crc errors detected for the block. The block must be
|
|
|
|
// completely unpacked before this test is valid. For losslessly unpacked
|
|
|
|
// blocks of float or extended integer data the extended crc is also checked.
|
|
|
|
// Note that WavPack's crc is not a CCITT approved polynomial algorithm, but
|
|
|
|
// is a much simpler method that is virtually as robust for real world data.
|
|
|
|
|
|
|
|
int check_crc_error (WavpackContext *wpc)
|
|
|
|
{
|
|
|
|
WavpackStream *wps = &wpc->stream;
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
if (wps->crc != wps->wphdr.crc)
|
2005-07-04 06:38:00 +00:00
|
|
|
++result;
|
2005-02-25 17:05:30 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|