Fix endian issues for intel

CQTexperiment
vspader 2006-04-21 20:43:47 +00:00
parent c63f495f33
commit e1eabaea4b
32 changed files with 16209 additions and 15017 deletions

View File

@ -1,6 +1,7 @@
0.05 alpha 4 0.05 alpha 4
------------ ------------
Volume slider now gravitates to 100%, in the middle. Volume slider now gravitates to 100%, in the middle.
Fixes endian issues for intel?
0.05 alpha 3 0.05 alpha 3
------------ ------------

View File

@ -157,7 +157,7 @@
29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; }; 29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
32CA4F630368D1EE00C91783 /* Cog_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Cog_Prefix.pch; sourceTree = "<group>"; }; 32CA4F630368D1EE00C91783 /* Cog_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Cog_Prefix.pch; sourceTree = "<group>"; };
8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; }; 8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
8D1107320486CEB800E47090 /* Cog.app */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.application; path = Cog.app; sourceTree = BUILT_PRODUCTS_DIR; }; 8D1107320486CEB800E47090 /* Cog.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Cog.app; sourceTree = BUILT_PRODUCTS_DIR; };
8E75751309F31D130080F1EE /* French */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = French; path = French.lproj/MainMenu.nib; sourceTree = "<group>"; }; 8E75751309F31D130080F1EE /* French */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = French; path = French.lproj/MainMenu.nib; sourceTree = "<group>"; };
8E75751809F31D5A0080F1EE /* AppController.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = AppController.h; sourceTree = "<group>"; }; 8E75751809F31D5A0080F1EE /* AppController.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = AppController.h; sourceTree = "<group>"; };
8E75751909F31D5A0080F1EE /* AppController.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = AppController.m; sourceTree = "<group>"; }; 8E75751909F31D5A0080F1EE /* AppController.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = AppController.m; sourceTree = "<group>"; };

Binary file not shown.

View File

@ -1,3 +1,107 @@
----------------------
Update - April 5, 2006
----------------------
WavPack Library Source Code - 4.32
-----------------------------------------
fixed: generating RIFF headers on big-endian machines caused crash
--------------------------
Update - December 10, 2005
--------------------------
wavpack.exe (command-line encoder) - 4.31
wvunpack.exe (command-line decoder) - 4.31
------------------------------------------
fixed: detect debug mode in all cases (win32 only)
improved: use latest service pack and SDK for building (win32 only)
improved: better directory choice for logging file (win32 only)
improved: allow shell to expand wildcards (*nix only)
added: option (-o) to specify output directory or path (*nix only)
added: option (-t) to copy timestamp (*nix only)
wvgain.exe (command-line ReplayGain scanner) - 4.31
---------------------------------------------------
new
WavPack Library Source Code - 4.31
----------------------------------
fixed: failing seek with some files that had been played to the end
fixed: small memory leak when opening hybrid lossless files
improved: signed characters no longer must be default
improved: APEv2 tags are read even if followed by ID3v1 tag
improved: limited APEv2 tag editing capability
------------------------------
Release 4.3 - November 1, 2005
------------------------------
wavpack.exe (command-line encoder) - 4.3
----------------------------------------
fixed: bug causing termination error with very wide screen widths
added: command-line option (-l) to use low priority for batch operation
added: command-line option (-r) to generate a fresh RIFF header
added: debug mode (rename to wavpack_debug.exe)
added: automatically detect lower resolution data even without -x1
added: src and dst dirs are searched also for tag source files (handy for EAC)
added: wildcard accepted for tag source files (handy for EAC)
added: handle non-standard sampling rates
improved: returns error status for any error
improved: use longer blocks in multichannel files (better "high" compression)
wvunpack.exe (command-line decoder) - 4.3
-----------------------------------------
fixed: very rare decoding bug causing overflow with hi-res files
fixed: bug causing termination error with very wide screen widths
fixed: formatting error in duration display
added: command-line option (-ss) to include tags in summary dump
added: command-line option (-l) to use low priority for batch operation
added: debug mode (rename to wvunpack_debug.exe)
improved: returns error status for any error
improved: more robust decoding of damaged (or invalid) files
in_wv.dll (winamp plugin) - 2.3
nxWavPack.dll (Nero plugin) - 1.2
WavPack_Apollo.dll (Apollo plugin) - 1.3
cool_wv4.flt (CoolEdit / Audition filter) - 2.6
-----------------------------------------------
fixed: very rare decoding bug causing overflow with hi-res files
improved: handle ID3v1.1 tags (now includes track number)
improved: more robust decoding of damaged (or invalid) files
added: handle non-standard sampling rates
foo_wavpack.dll (foobar plugin) - 2.3
-----------------------------------------------
fixed: any error during WavPack file open caused crash if wvc file present
fixed: very rare decoding bug causing overflow with hi-res files
improved: more robust decoding of damaged (or invalid) files
added: handle non-standard sampling rates
WavPack Library Source Code - 4.3
---------------------------------
fixed: very rare decoding bug causing overflow with hi-res files
added: automatic generation of RIFF wav header during encoding
added: new functions to access tags by index (instead of item name)
added: automatically detect lower resolution data during encoding
added: handle non-standard sampling rates
improved: more robust decoding of damaged (or invalid) files
improved: use longer blocks in multichannel files (better "high" compression)
improved: two structures renamed to avoid namespace conflict
removed: legacy code for Borland compiler
--------------------------
Update - September 1, 2005
--------------------------
wavpack.exe (command-line encoder) - 4.22
cool_wv4.flt (CoolEdit / Audition filter) - 2.5
-----------------------------------------------
fixed: possible corrupt files written (24 or 32-bit + "extra" mode)
--------------------------- ---------------------------
Release 4.2 - April 2, 2005 Release 4.2 - April 2, 2005
--------------------------- ---------------------------

View File

@ -1,27 +1,32 @@
AUTOMAKE_OPTIONS = foreign AUTOMAKE_OPTIONS = foreign
bin_PROGRAMS = wavpack wvunpack bin_PROGRAMS = wavpack wvunpack wvgain
lib_LTLIBRARIES = libwavpack.la lib_LTLIBRARIES = libwavpack.la
wpincludedir = $(prefix)/include/wavpack wpincludedir = $(prefix)/include/wavpack
wpinclude_HEADERS = md5.h wavpack.h wputils.h unpack3.h wpinclude_HEADERS = md5.h wavpack.h wputils.h unpack3.h
libwavpack_la_SOURCES = bits.c float.c metadata.c unpack.c unpack3.c utils.c \ libwavpack_la_SOURCES = bits.c float.c metadata.c unpack.c unpack3.c \
wputils.c words.c md5.c extra1.c extra2.c pack.c \ wputils.c words.c md5.c extra1.c extra2.c pack.c \
md5.h wavpack.h wputils.h unpack3.h md5.h wavpack.h wputils.h unpack3.h
libwavpack_la_CFLAGS = -DPACK -DUNPACK -DUSE_FSTREAMS -DTAGS -DSEEKING -DVER3 libwavpack_la_CFLAGS = -DPACK -DUNPACK -DUSE_FSTREAMS -DTAGS -DSEEKING -DVER3
libwavpack_la_LDFLAGS = -lm @ICONV_LIBS@ libwavpack_la_LDFLAGS = -lm @ICONV_LIBS@
wavpack_SOURCES = wavpack.c wavpack_SOURCES = wavpack.c utils.c
wavpack_CFLAGS = -DPACK wavpack_CFLAGS = -DPACK
wavpack_LDFLAGS = -lm -lcurses wavpack_LDFLAGS = -lm
wavpack_LDADD = libwavpack.la wavpack_LDADD = libwavpack.la
wvunpack_SOURCES = wvunpack.c wvunpack_SOURCES = wvunpack.c utils.c
wvunpack_CFLAGS = -DUNPACK -DUSE_FSTREAMS wvunpack_CFLAGS = -DUNPACK -DUSE_FSTREAMS
wvunpack_LDFLAGS = -lm -lcurses wvunpack_LDFLAGS = -lm
wvunpack_LDADD = libwavpack.la wvunpack_LDADD = libwavpack.la
pkgconfigdir = $(libdir)/pkgconfig wvgain_SOURCES = wvgain.c utils.c
pkgconfig_DATA = wavpack.pc wvgain_CFLAGS = -DUNPACK -DUSE_FSTREAMS
wvgain_LDFLAGS = -lm
wvgain_LDADD = libwavpack.la
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = wavpack.pc

View File

@ -13,10 +13,9 @@ of the plugin sources in the Windows source release.
To build everything, type: To build everything, type:
1. ./autogen.sh 1. ./configure
2. ./configure 2. make
3. make 3. make install (optionally, to install into /usr/local/bin)
4. make install (optionally, to install into /usr/local/bin)
Notes: Notes:
@ -31,10 +30,10 @@ Notes:
a "short" must be 16-bits a "short" must be 16-bits
an "int" must be at least 16-bits, but may be larger an "int" must be at least 16-bits, but may be larger
a "char" must default to signed (Watcom users take note!)
For version 4.2 references to "long" variables were eliminated to allow For version 4.2 references to "long" variables were eliminated to allow
compilation on 64-bit machines. compilation on 64-bit machines. For version 4.3 "char" types may default
to signed or unsigned.
2. For WavPack file decoding, a library interface in "wputils.c" provides all 2. For WavPack file decoding, a library interface in "wputils.c" provides all
the functionality required for both the winamp plugin and the "wvunpack" the functionality required for both the winamp plugin and the "wvunpack"

View File

@ -1,259 +1,259 @@
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// **** WAVPACK **** // // **** WAVPACK **** //
// Hybrid Lossless Wavefile Compressor // // Hybrid Lossless Wavefile Compressor //
// Copyright (c) 1998 - 2005 Conifer Software. // // Copyright (c) 1998 - 2005 Conifer Software. //
// All Rights Reserved. // // All Rights Reserved. //
// Distributed under the BSD Software License (see license.txt) // // Distributed under the BSD Software License (see license.txt) //
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// bits.c // bits.c
// This module provides utilities to support the BitStream structure which is // This module provides utilities to support the BitStream structure which is
// used to read and write all WavPack audio data streams. It also contains a // used to read and write all WavPack audio data streams. It also contains a
// wrapper for the stream I/O functions and a set of functions dealing with // wrapper for the stream I/O functions and a set of functions dealing with
// endian-ness, both for enhancing portability. Finally, a debug wrapper for // endian-ness, both for enhancing portability. Finally, a debug wrapper for
// the malloc() system is provided. // the malloc() system is provided.
#include "wavpack.h" #include "wavpack.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include <sys/stat.h> #include <sys/stat.h>
#if defined(WIN32) #if defined(WIN32)
#include <io.h> #include <io.h>
#else #else
#include <unistd.h> #include <unistd.h>
#endif #endif
////////////////////////// Bitstream functions //////////////////////////////// ////////////////////////// Bitstream functions ////////////////////////////////
#if defined(UNPACK) || defined(INFO_ONLY) #if defined(UNPACK) || defined(INFO_ONLY)
// Open the specified BitStream and associate with the specified buffer. // Open the specified BitStream and associate with the specified buffer.
static void bs_read (Bitstream *bs); static void bs_read (Bitstream *bs);
void bs_open_read (Bitstream *bs, uchar *buffer_start, uchar *buffer_end) void bs_open_read (Bitstream *bs, uchar *buffer_start, uchar *buffer_end)
{ {
bs->error = bs->sr = bs->bc = 0; bs->error = bs->sr = bs->bc = 0;
bs->ptr = (bs->buf = buffer_start) - 1; bs->ptr = (bs->buf = buffer_start) - 1;
bs->end = buffer_end; bs->end = buffer_end;
bs->wrap = bs_read; bs->wrap = bs_read;
} }
// This function is only called from the getbit() and getbits() macros when // This function is only called from the getbit() and getbits() macros when
// the BitStream has been exhausted and more data is required. Sinve these // the BitStream has been exhausted and more data is required. Sinve these
// bistreams no longer access files, this function simple sets an error and // bistreams no longer access files, this function simple sets an error and
// resets the buffer. // resets the buffer.
static void bs_read (Bitstream *bs) static void bs_read (Bitstream *bs)
{ {
bs->ptr = bs->buf - 1; bs->ptr = bs->buf - 1;
bs->error = 1; bs->error = 1;
} }
// This function is called to close the bitstream. It returns the number of // This function is called to close the bitstream. It returns the number of
// full bytes actually read as bits. // full bytes actually read as bits.
uint32_t bs_close_read (Bitstream *bs) uint32_t bs_close_read (Bitstream *bs)
{ {
uint32_t bytes_read; uint32_t bytes_read;
if (bs->bc < 8) if (bs->bc < 8)
bs->ptr++; bs->ptr++;
if ((bs->buf - bs->ptr) & 1) if ((bs->buf - bs->ptr) & 1)
bs->ptr++; bs->ptr++;
bytes_read = bs->ptr - bs->buf; bytes_read = bs->ptr - bs->buf;
CLEAR (*bs); CLEAR (*bs);
return bytes_read; return bytes_read;
} }
#endif #endif
#ifdef PACK #ifdef PACK
// Open the specified BitStream using the specified buffer pointers. It is // Open the specified BitStream using the specified buffer pointers. It is
// assumed that enough buffer space has been allocated for all data that will // assumed that enough buffer space has been allocated for all data that will
// be written, otherwise an error will be generated. // be written, otherwise an error will be generated.
static void bs_write (Bitstream *bs); static void bs_write (Bitstream *bs);
void bs_open_write (Bitstream *bs, uchar *buffer_start, uchar *buffer_end) void bs_open_write (Bitstream *bs, uchar *buffer_start, uchar *buffer_end)
{ {
bs->error = bs->sr = bs->bc = 0; bs->error = bs->sr = bs->bc = 0;
bs->ptr = bs->buf = buffer_start; bs->ptr = bs->buf = buffer_start;
bs->end = buffer_end; bs->end = buffer_end;
bs->wrap = bs_write; bs->wrap = bs_write;
} }
// This function is only called from the putbit() and putbits() macros when // This function is only called from the putbit() and putbits() macros when
// the buffer is full, which is now flagged as an error. // the buffer is full, which is now flagged as an error.
static void bs_write (Bitstream *bs) static void bs_write (Bitstream *bs)
{ {
bs->ptr = bs->buf; bs->ptr = bs->buf;
bs->error = 1; bs->error = 1;
} }
// This function forces a flushing write of the specified BitStream, and // This function forces a flushing write of the specified BitStream, and
// returns the total number of bytes written into the buffer. // returns the total number of bytes written into the buffer.
uint32_t bs_close_write (Bitstream *bs) uint32_t bs_close_write (Bitstream *bs)
{ {
uint32_t bytes_written; uint32_t bytes_written;
if (bs->error) if (bs->error)
return (uint32_t) -1; return (uint32_t) -1;
while (bs->bc || ((bs->ptr - bs->buf) & 1)) putbit_1 (bs); while (bs->bc || ((bs->ptr - bs->buf) & 1)) putbit_1 (bs);
bytes_written = bs->ptr - bs->buf; bytes_written = bs->ptr - bs->buf;
CLEAR (*bs); CLEAR (*bs);
return bytes_written; return bytes_written;
} }
#endif #endif
/////////////////////// Endian Correction Routines //////////////////////////// /////////////////////// Endian Correction Routines ////////////////////////////
void little_endian_to_native (void *data, char *format) void little_endian_to_native (void *data, char *format)
{ {
uchar *cp = (uchar *) data; uchar *cp = (uchar *) data;
int32_t temp; int32_t temp;
while (*format) { while (*format) {
switch (*format) { switch (*format) {
case 'L': case 'L':
temp = cp [0] + ((int32_t) cp [1] << 8) + ((int32_t) cp [2] << 16) + ((int32_t) cp [3] << 24); temp = cp [0] + ((int32_t) cp [1] << 8) + ((int32_t) cp [2] << 16) + ((int32_t) cp [3] << 24);
* (int32_t *) cp = temp; * (int32_t *) cp = temp;
cp += 4; cp += 4;
break; break;
case 'S': case 'S':
temp = cp [0] + (cp [1] << 8); temp = cp [0] + (cp [1] << 8);
* (short *) cp = (short) temp; * (short *) cp = (short) temp;
cp += 2; cp += 2;
break; break;
default: default:
if (isdigit (*format)) if (isdigit (*format))
cp += *format - '0'; cp += *format - '0';
break; break;
} }
format++; format++;
} }
} }
void native_to_little_endian (void *data, char *format) void native_to_little_endian (void *data, char *format)
{ {
uchar *cp = (uchar *) data; uchar *cp = (uchar *) data;
int32_t temp; int32_t temp;
while (*format) { while (*format) {
switch (*format) { switch (*format) {
case 'L': case 'L':
temp = * (int32_t *) cp; temp = * (int32_t *) cp;
*cp++ = (uchar) temp; *cp++ = (uchar) temp;
*cp++ = (uchar) (temp >> 8); *cp++ = (uchar) (temp >> 8);
*cp++ = (uchar) (temp >> 16); *cp++ = (uchar) (temp >> 16);
*cp++ = (uchar) (temp >> 24); *cp++ = (uchar) (temp >> 24);
break; break;
case 'S': case 'S':
temp = * (short *) cp; temp = * (short *) cp;
*cp++ = (uchar) temp; *cp++ = (uchar) temp;
*cp++ = (uchar) (temp >> 8); *cp++ = (uchar) (temp >> 8);
break; break;
default: default:
if (isdigit (*format)) if (isdigit (*format))
cp += *format - '0'; cp += *format - '0';
break; break;
} }
format++; format++;
} }
} }
////////////////////////// Debug Wrapper for Malloc /////////////////////////// ////////////////////////// Debug Wrapper for Malloc ///////////////////////////
#ifdef DEBUG_ALLOC #ifdef DEBUG_ALLOC
void *vptrs [512]; void *vptrs [512];
static void *add_ptr (void *ptr) static void *add_ptr (void *ptr)
{ {
int i; int i;
for (i = 0; i < 512; ++i) for (i = 0; i < 512; ++i)
if (!vptrs [i]) { if (!vptrs [i]) {
vptrs [i] = ptr; vptrs [i] = ptr;
break; break;
} }
if (i == 512) if (i == 512)
error_line ("too many mallocs!"); error_line ("too many mallocs!");
return ptr; return ptr;
} }
static void *del_ptr (void *ptr) static void *del_ptr (void *ptr)
{ {
int i; int i;
for (i = 0; i < 512; ++i) for (i = 0; i < 512; ++i)
if (vptrs [i] == ptr) { if (vptrs [i] == ptr) {
vptrs [i] = NULL; vptrs [i] = NULL;
break; break;
} }
if (i == 512) if (i == 512)
error_line ("free invalid ptr!"); error_line ("free invalid ptr!");
return ptr; return ptr;
} }
void *malloc_db (uint32_t size) void *malloc_db (uint32_t size)
{ {
if (size) if (size)
return add_ptr (malloc (size)); return add_ptr (malloc (size));
else else
return NULL; return NULL;
} }
void free_db (void *ptr) void free_db (void *ptr)
{ {
if (ptr) if (ptr)
free (del_ptr (ptr)); free (del_ptr (ptr));
} }
void *realloc_db (void *ptr, uint32_t size) void *realloc_db (void *ptr, uint32_t size)
{ {
if (ptr && size) if (ptr && size)
return add_ptr (realloc (del_ptr (ptr), size)); return add_ptr (realloc (del_ptr (ptr), size));
else if (size) else if (size)
return malloc_db (size); return malloc_db (size);
else else
free_db (ptr); free_db (ptr);
return NULL; return NULL;
} }
int32_t dump_alloc (void) int32_t dump_alloc (void)
{ {
int i, j; int i, j;
for (j = i = 0; i < 512; ++i) for (j = i = 0; i < 512; ++i)
if (vptrs [i]) if (vptrs [i])
j++; j++;
return j; return j;
} }
#endif #endif

View File

@ -1,7 +1,7 @@
# wavpack 4.2 configure.ac # wavpack 4.32 configure.ac
AC_INIT(wavpack, 4.2, bryant@wavpack.com) AC_INIT(wavpack, 4.32, bryant@wavpack.com)
AM_INIT_AUTOMAKE(wavpack, 4.2, bryant@wavpack.com) AM_INIT_AUTOMAKE(wavpack, 4.32, bryant@wavpack.com)
AC_CONFIG_SRCDIR([pack.c]) AC_CONFIG_SRCDIR([pack.c])
# Check for os version # Check for os version

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,371 +1,371 @@
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// **** WAVPACK **** // // **** WAVPACK **** //
// Hybrid Lossless Wavefile Compressor // // Hybrid Lossless Wavefile Compressor //
// Copyright (c) 1998 - 2005 Conifer Software. // // Copyright (c) 1998 - 2005 Conifer Software. //
// All Rights Reserved. // // All Rights Reserved. //
// Distributed under the BSD Software License (see license.txt) // // Distributed under the BSD Software License (see license.txt) //
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// float.c // float.c
#include "wavpack.h" #include "wavpack.h"
#include <stdlib.h> #include <stdlib.h>
#ifdef DEBUG_ALLOC #ifdef DEBUG_ALLOC
#define malloc malloc_db #define malloc malloc_db
#define realloc realloc_db #define realloc realloc_db
#define free free_db #define free free_db
void *malloc_db (uint32_t size); void *malloc_db (uint32_t size);
void *realloc_db (void *ptr, uint32_t size); void *realloc_db (void *ptr, uint32_t size);
void free_db (void *ptr); void free_db (void *ptr);
int32_t dump_alloc (void); int32_t dump_alloc (void);
#endif #endif
#ifdef PACK #ifdef PACK
void write_float_info (WavpackStream *wps, WavpackMetadata *wpmd) void write_float_info (WavpackStream *wps, WavpackMetadata *wpmd)
{ {
char *byteptr; char *byteptr;
byteptr = wpmd->data = malloc (4); byteptr = wpmd->data = malloc (4);
wpmd->id = ID_FLOAT_INFO; wpmd->id = ID_FLOAT_INFO;
*byteptr++ = wps->float_flags; *byteptr++ = wps->float_flags;
*byteptr++ = wps->float_shift; *byteptr++ = wps->float_shift;
*byteptr++ = wps->float_max_exp; *byteptr++ = wps->float_max_exp;
*byteptr++ = wps->float_norm_exp; *byteptr++ = wps->float_norm_exp;
wpmd->byte_length = byteptr - (char *) wpmd->data; wpmd->byte_length = byteptr - (char *) wpmd->data;
} }
int scan_float_data (WavpackStream *wps, f32 *values, int32_t num_values) int scan_float_data (WavpackStream *wps, f32 *values, int32_t num_values)
{ {
int32_t shifted_ones = 0, shifted_zeros = 0, shifted_both = 0; int32_t shifted_ones = 0, shifted_zeros = 0, shifted_both = 0;
int32_t false_zeros = 0, neg_zeros = 0; int32_t false_zeros = 0, neg_zeros = 0;
uint32_t ordata = 0, crc = 0xffffffff; uint32_t ordata = 0, crc = 0xffffffff;
int max_exp = 0, shift_count; int max_exp = 0, shift_count;
int32_t count, value; int32_t count, value;
f32 *dp; f32 *dp;
wps->float_shift = wps->float_flags = 0; wps->float_shift = wps->float_flags = 0;
for (dp = values, count = num_values; count--; dp++) { for (dp = values, count = num_values; count--; dp++) {
crc = crc * 27 + dp->mantissa * 9 + dp->exponent * 3 + dp->sign; crc = crc * 27 + dp->mantissa * 9 + dp->exponent * 3 + dp->sign;
if (dp->exponent > max_exp && dp->exponent < 255) if (dp->exponent > max_exp && dp->exponent < 255)
max_exp = dp->exponent; max_exp = dp->exponent;
} }
wps->crc_x = crc; wps->crc_x = crc;
for (dp = values, count = num_values; count--; dp++) { for (dp = values, count = num_values; count--; dp++) {
if (dp->exponent == 255) { if (dp->exponent == 255) {
wps->float_flags |= FLOAT_EXCEPTIONS; wps->float_flags |= FLOAT_EXCEPTIONS;
value = 0x1000000; value = 0x1000000;
shift_count = 0; shift_count = 0;
} }
else if (dp->exponent) { else if (dp->exponent) {
shift_count = max_exp - dp->exponent; shift_count = max_exp - dp->exponent;
value = 0x800000 + dp->mantissa; value = 0x800000 + dp->mantissa;
} }
else { else {
shift_count = max_exp ? max_exp - 1 : 0; shift_count = max_exp ? max_exp - 1 : 0;
value = dp->mantissa; value = dp->mantissa;
// if (dp->mantissa) // if (dp->mantissa)
// denormals++; // denormals++;
} }
if (shift_count < 25) if (shift_count < 25)
value >>= shift_count; value >>= shift_count;
else else
value = 0; value = 0;
if (!value) { if (!value) {
if (dp->exponent || dp->mantissa) if (dp->exponent || dp->mantissa)
++false_zeros; ++false_zeros;
else if (dp->sign) else if (dp->sign)
++neg_zeros; ++neg_zeros;
} }
else if (shift_count) { else if (shift_count) {
int32_t mask = (1 << shift_count) - 1; int32_t mask = (1 << shift_count) - 1;
if (!(dp->mantissa & mask)) if (!(dp->mantissa & mask))
shifted_zeros++; shifted_zeros++;
else if ((dp->mantissa & mask) == mask) else if ((dp->mantissa & mask) == mask)
shifted_ones++; shifted_ones++;
else else
shifted_both++; shifted_both++;
} }
ordata |= value; ordata |= value;
* (int32_t *) dp = (dp->sign) ? -value : value; * (int32_t *) dp = (dp->sign) ? -value : value;
} }
wps->float_max_exp = max_exp; wps->float_max_exp = max_exp;
if (shifted_both) if (shifted_both)
wps->float_flags |= FLOAT_SHIFT_SENT; wps->float_flags |= FLOAT_SHIFT_SENT;
else if (shifted_ones && !shifted_zeros) else if (shifted_ones && !shifted_zeros)
wps->float_flags |= FLOAT_SHIFT_ONES; wps->float_flags |= FLOAT_SHIFT_ONES;
else if (shifted_ones && shifted_zeros) else if (shifted_ones && shifted_zeros)
wps->float_flags |= FLOAT_SHIFT_SAME; wps->float_flags |= FLOAT_SHIFT_SAME;
else if (ordata && !(ordata & 1)) { else if (ordata && !(ordata & 1)) {
while (!(ordata & 1)) { while (!(ordata & 1)) {
wps->float_shift++; wps->float_shift++;
ordata >>= 1; ordata >>= 1;
} }
for (dp = values, count = num_values; count--; dp++) for (dp = values, count = num_values; count--; dp++)
* (int32_t *) dp >>= wps->float_shift; * (int32_t *) dp >>= wps->float_shift;
} }
wps->wphdr.flags &= ~MAG_MASK; wps->wphdr.flags &= ~MAG_MASK;
while (ordata) { while (ordata) {
wps->wphdr.flags += 1 << MAG_LSB; wps->wphdr.flags += 1 << MAG_LSB;
ordata >>= 1; ordata >>= 1;
} }
if (false_zeros || neg_zeros) if (false_zeros || neg_zeros)
wps->float_flags |= FLOAT_ZEROS_SENT; wps->float_flags |= FLOAT_ZEROS_SENT;
if (neg_zeros) if (neg_zeros)
wps->float_flags |= FLOAT_NEG_ZEROS; wps->float_flags |= FLOAT_NEG_ZEROS;
// error_line ("samples = %d, max exp = %d, pre-shift = %d, denormals = %d", // error_line ("samples = %d, max exp = %d, pre-shift = %d, denormals = %d",
// num_values, max_exp, wps->float_shift, denormals); // num_values, max_exp, wps->float_shift, denormals);
// if (wps->float_flags & FLOAT_EXCEPTIONS) // if (wps->float_flags & FLOAT_EXCEPTIONS)
// error_line ("exceptions!"); // error_line ("exceptions!");
// error_line ("shifted ones/zeros/both = %d/%d/%d, true/neg/false zeros = %d/%d/%d", // error_line ("shifted ones/zeros/both = %d/%d/%d, true/neg/false zeros = %d/%d/%d",
// shifted_ones, shifted_zeros, shifted_both, true_zeros, neg_zeros, false_zeros); // shifted_ones, shifted_zeros, shifted_both, true_zeros, neg_zeros, false_zeros);
return wps->float_flags & (FLOAT_EXCEPTIONS | FLOAT_ZEROS_SENT | FLOAT_SHIFT_SENT | FLOAT_SHIFT_SAME); return wps->float_flags & (FLOAT_EXCEPTIONS | FLOAT_ZEROS_SENT | FLOAT_SHIFT_SENT | FLOAT_SHIFT_SAME);
} }
void send_float_data (WavpackStream *wps, f32 *values, int32_t num_values) void send_float_data (WavpackStream *wps, f32 *values, int32_t num_values)
{ {
int max_exp = wps->float_max_exp; int max_exp = wps->float_max_exp;
int32_t count, value, shift_count; int32_t count, value, shift_count;
f32 *dp; f32 *dp;
for (dp = values, count = num_values; count--; dp++) { for (dp = values, count = num_values; count--; dp++) {
if (dp->exponent == 255) { if (dp->exponent == 255) {
if (dp->mantissa) { if (dp->mantissa) {
putbit_1 (&wps->wvxbits); putbit_1 (&wps->wvxbits);
putbits (dp->mantissa, 23, &wps->wvxbits); putbits (dp->mantissa, 23, &wps->wvxbits);
} }
else { else {
putbit_0 (&wps->wvxbits); putbit_0 (&wps->wvxbits);
} }
value = 0x1000000; value = 0x1000000;
shift_count = 0; shift_count = 0;
} }
else if (dp->exponent) { else if (dp->exponent) {
shift_count = max_exp - dp->exponent; shift_count = max_exp - dp->exponent;
value = 0x800000 + dp->mantissa; value = 0x800000 + dp->mantissa;
} }
else { else {
shift_count = max_exp ? max_exp - 1 : 0; shift_count = max_exp ? max_exp - 1 : 0;
value = dp->mantissa; value = dp->mantissa;
} }
if (shift_count < 25) if (shift_count < 25)
value >>= shift_count; value >>= shift_count;
else else
value = 0; value = 0;
if (!value) { if (!value) {
if (wps->float_flags & FLOAT_ZEROS_SENT) { if (wps->float_flags & FLOAT_ZEROS_SENT) {
if (dp->exponent || dp->mantissa) { if (dp->exponent || dp->mantissa) {
putbit_1 (&wps->wvxbits); putbit_1 (&wps->wvxbits);
putbits (dp->mantissa, 23, &wps->wvxbits); putbits (dp->mantissa, 23, &wps->wvxbits);
if (max_exp >= 25) { if (max_exp >= 25) {
putbits (dp->exponent, 8, &wps->wvxbits); putbits (dp->exponent, 8, &wps->wvxbits);
} }
putbit (dp->sign, &wps->wvxbits); putbit (dp->sign, &wps->wvxbits);
} }
else { else {
putbit_0 (&wps->wvxbits); putbit_0 (&wps->wvxbits);
if (wps->float_flags & FLOAT_NEG_ZEROS) if (wps->float_flags & FLOAT_NEG_ZEROS)
putbit (dp->sign, &wps->wvxbits); putbit (dp->sign, &wps->wvxbits);
} }
} }
} }
else if (shift_count) { else if (shift_count) {
if (wps->float_flags & FLOAT_SHIFT_SENT) { if (wps->float_flags & FLOAT_SHIFT_SENT) {
int32_t data = dp->mantissa & ((1 << shift_count) - 1); int32_t data = dp->mantissa & ((1 << shift_count) - 1);
putbits (data, shift_count, &wps->wvxbits); putbits (data, shift_count, &wps->wvxbits);
} }
else if (wps->float_flags & FLOAT_SHIFT_SAME) { else if (wps->float_flags & FLOAT_SHIFT_SAME) {
putbit (dp->mantissa & 1, &wps->wvxbits); putbit (dp->mantissa & 1, &wps->wvxbits);
} }
} }
} }
} }
#endif #endif
#if defined(UNPACK) || defined(INFO_ONLY) #if defined(UNPACK) || defined(INFO_ONLY)
int read_float_info (WavpackStream *wps, WavpackMetadata *wpmd) int read_float_info (WavpackStream *wps, WavpackMetadata *wpmd)
{ {
int bytecnt = wpmd->byte_length; int bytecnt = wpmd->byte_length;
char *byteptr = wpmd->data; char *byteptr = wpmd->data;
if (bytecnt != 4) if (bytecnt != 4)
return FALSE; return FALSE;
wps->float_flags = *byteptr++; wps->float_flags = *byteptr++;
wps->float_shift = *byteptr++; wps->float_shift = *byteptr++;
wps->float_max_exp = *byteptr++; wps->float_max_exp = *byteptr++;
wps->float_norm_exp = *byteptr; wps->float_norm_exp = *byteptr;
return TRUE; return TRUE;
} }
#endif #endif
#ifdef UNPACK #ifdef UNPACK
static void float_values_nowvx (WavpackStream *wps, int32_t *values, int32_t num_values); static void float_values_nowvx (WavpackStream *wps, int32_t *values, int32_t num_values);
void float_values (WavpackStream *wps, int32_t *values, int32_t num_values) void float_values (WavpackStream *wps, int32_t *values, int32_t num_values)
{ {
uint32_t crc = wps->crc_x; uint32_t crc = wps->crc_x;
if (!bs_is_open (&wps->wvxbits)) { if (!bs_is_open (&wps->wvxbits)) {
float_values_nowvx (wps, values, num_values); float_values_nowvx (wps, values, num_values);
return; return;
} }
while (num_values--) { while (num_values--) {
int shift_count = 0, exp = wps->float_max_exp; int shift_count = 0, exp = wps->float_max_exp;
f32 outval = { 0, 0, 0 }; f32 outval = { 0, 0, 0 };
uint32_t temp; uint32_t temp;
if (*values == 0) { if (*values == 0) {
if (wps->float_flags & FLOAT_ZEROS_SENT) { if (wps->float_flags & FLOAT_ZEROS_SENT) {
if (getbit (&wps->wvxbits)) { if (getbit (&wps->wvxbits)) {
getbits (&temp, 23, &wps->wvxbits); getbits (&temp, 23, &wps->wvxbits);
outval.mantissa = temp; outval.mantissa = temp;
if (exp >= 25) { if (exp >= 25) {
getbits (&temp, 8, &wps->wvxbits); getbits (&temp, 8, &wps->wvxbits);
outval.exponent = temp; outval.exponent = temp;
} }
outval.sign = getbit (&wps->wvxbits); outval.sign = getbit (&wps->wvxbits);
} }
else if (wps->float_flags & FLOAT_NEG_ZEROS) else if (wps->float_flags & FLOAT_NEG_ZEROS)
outval.sign = getbit (&wps->wvxbits); outval.sign = getbit (&wps->wvxbits);
} }
} }
else { else {
*values <<= wps->float_shift; *values <<= wps->float_shift;
if (*values < 0) { if (*values < 0) {
*values = -*values; *values = -*values;
outval.sign = 1; outval.sign = 1;
} }
if (*values == 0x1000000) { if (*values == 0x1000000) {
if (getbit (&wps->wvxbits)) { if (getbit (&wps->wvxbits)) {
getbits (&temp, 23, &wps->wvxbits); getbits (&temp, 23, &wps->wvxbits);
outval.mantissa = temp; outval.mantissa = temp;
} }
outval.exponent = 255; outval.exponent = 255;
} }
else { else {
if (exp) if (exp)
while (!(*values & 0x800000) && --exp) { while (!(*values & 0x800000) && --exp) {
shift_count++; shift_count++;
*values <<= 1; *values <<= 1;
} }
if (shift_count) { if (shift_count) {
if ((wps->float_flags & FLOAT_SHIFT_ONES) || if ((wps->float_flags & FLOAT_SHIFT_ONES) ||
((wps->float_flags & FLOAT_SHIFT_SAME) && getbit (&wps->wvxbits))) ((wps->float_flags & FLOAT_SHIFT_SAME) && getbit (&wps->wvxbits)))
*values |= ((1 << shift_count) - 1); *values |= ((1 << shift_count) - 1);
else if (wps->float_flags & FLOAT_SHIFT_SENT) { else if (wps->float_flags & FLOAT_SHIFT_SENT) {
getbits (&temp, shift_count, &wps->wvxbits); getbits (&temp, shift_count, &wps->wvxbits);
*values |= temp & ((1 << shift_count) - 1); *values |= temp & ((1 << shift_count) - 1);
} }
} }
outval.mantissa = *values; outval.mantissa = *values;
outval.exponent = exp; outval.exponent = exp;
} }
} }
crc = crc * 27 + outval.mantissa * 9 + outval.exponent * 3 + outval.sign; crc = crc * 27 + outval.mantissa * 9 + outval.exponent * 3 + outval.sign;
* (f32 *) values++ = outval; * (f32 *) values++ = outval;
} }
wps->crc_x = crc; wps->crc_x = crc;
} }
static void float_values_nowvx (WavpackStream *wps, int32_t *values, int32_t num_values) static void float_values_nowvx (WavpackStream *wps, int32_t *values, int32_t num_values)
{ {
while (num_values--) { while (num_values--) {
int shift_count = 0, exp = wps->float_max_exp; int shift_count = 0, exp = wps->float_max_exp;
f32 outval = { 0, 0, 0 }; f32 outval = { 0, 0, 0 };
if (*values) { if (*values) {
*values <<= wps->float_shift; *values <<= wps->float_shift;
if (*values < 0) { if (*values < 0) {
*values = -*values; *values = -*values;
outval.sign = 1; outval.sign = 1;
} }
if (*values >= 0x1000000) { if (*values >= 0x1000000) {
while (*values & 0xf000000) { while (*values & 0xf000000) {
*values >>= 1; *values >>= 1;
++exp; ++exp;
} }
} }
else if (exp) { else if (exp) {
while (!(*values & 0x800000) && --exp) { while (!(*values & 0x800000) && --exp) {
shift_count++; shift_count++;
*values <<= 1; *values <<= 1;
} }
if (shift_count && (wps->float_flags & FLOAT_SHIFT_ONES)) if (shift_count && (wps->float_flags & FLOAT_SHIFT_ONES))
*values |= ((1 << shift_count) - 1); *values |= ((1 << shift_count) - 1);
} }
outval.mantissa = *values; outval.mantissa = *values;
outval.exponent = exp; outval.exponent = exp;
} }
* (f32 *) values++ = outval; * (f32 *) values++ = outval;
} }
} }
void float_normalize (int32_t *values, int32_t num_values, int delta_exp) #endif
{
f32 *fvalues = (f32 *) values, fzero = { 0, 0, 0 }; void float_normalize (int32_t *values, int32_t num_values, int delta_exp)
int exp; {
f32 *fvalues = (f32 *) values, fzero = { 0, 0, 0 };
if (!delta_exp) int exp;
return;
if (!delta_exp)
while (num_values--) { return;
if ((exp = fvalues->exponent) == 0 || exp + delta_exp <= 0)
*fvalues = fzero; while (num_values--) {
else if (exp == 255 || (exp += delta_exp) >= 255) { if ((exp = fvalues->exponent) == 0 || exp + delta_exp <= 0)
fvalues->exponent = 255; *fvalues = fzero;
fvalues->mantissa = 0; else if (exp == 255 || (exp += delta_exp) >= 255) {
} fvalues->exponent = 255;
else fvalues->mantissa = 0;
fvalues->exponent = exp; }
else
fvalues++; fvalues->exponent = exp;
}
} fvalues++;
}
#endif }

View File

@ -1,263 +1,263 @@
/* /*
* This code implements the MD5 message-digest algorithm. * This code implements the MD5 message-digest algorithm.
* The algorithm is due to Ron Rivest. This code was * The algorithm is due to Ron Rivest. This code was
* written by Colin Plumb in 1993, no copyright is claimed. * written by Colin Plumb in 1993, no copyright is claimed.
* This code is in the public domain; do with it what you wish. * This code is in the public domain; do with it what you wish.
* *
* Equivalent code is available from RSA Data Security, Inc. * Equivalent code is available from RSA Data Security, Inc.
* This code has been tested against that, and is equivalent, * This code has been tested against that, and is equivalent,
* except that you don't need to include two pages of legalese * except that you don't need to include two pages of legalese
* with every copy. * with every copy.
* *
* To compute the message digest of a chunk of bytes, declare an * To compute the message digest of a chunk of bytes, declare an
* MD5Context structure, pass it to MD5Init, call MD5Update as * MD5Context structure, pass it to MD5Init, call MD5Update as
* needed on buffers full of bytes, and then call MD5Final, which * needed on buffers full of bytes, and then call MD5Final, which
* will fill a supplied 16-byte array with the digest. * will fill a supplied 16-byte array with the digest.
*/ */
/* Brutally hacked by John Walker back from ANSI C to K&R (no /* Brutally hacked by John Walker back from ANSI C to K&R (no
prototypes) to maintain the tradition that Netfone will compile prototypes) to maintain the tradition that Netfone will compile
with Sun's original "cc". */ with Sun's original "cc". */
#include <memory.h> /* for memcpy() */ #include <memory.h> /* for memcpy() */
#include "md5.h" #include "md5.h"
#ifdef sgi #ifdef sgi
#define HIGHFIRST #define HIGHFIRST
#endif #endif
#ifdef sun #ifdef sun
#define HIGHFIRST #define HIGHFIRST
#endif #endif
#ifndef HIGHFIRST #ifndef HIGHFIRST
#define byteReverse(buf, len) /* Nothing */ #define byteReverse(buf, len) /* Nothing */
#else #else
/* /*
* Note: this code is harmless on little-endian machines. * Note: this code is harmless on little-endian machines.
*/ */
void byteReverse(buf, longs) void byteReverse(buf, longs)
unsigned char *buf; unsigned longs; unsigned char *buf; unsigned longs;
{ {
uint32 t; uint32 t;
do { do {
t = (uint32) ((unsigned) buf[3] << 8 | buf[2]) << 16 | t = (uint32) ((unsigned) buf[3] << 8 | buf[2]) << 16 |
((unsigned) buf[1] << 8 | buf[0]); ((unsigned) buf[1] << 8 | buf[0]);
*(uint32 *) buf = t; *(uint32 *) buf = t;
buf += 4; buf += 4;
} while (--longs); } while (--longs);
} }
#endif #endif
/* /*
* Start MD5 accumulation. Set bit count to 0 and buffer to mysterious * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
* initialization constants. * initialization constants.
*/ */
void MD5Init(ctx) void MD5Init(ctx)
struct MD5Context *ctx; struct MD5Context *ctx;
{ {
ctx->buf[0] = 0x67452301; ctx->buf[0] = 0x67452301;
ctx->buf[1] = 0xefcdab89; ctx->buf[1] = 0xefcdab89;
ctx->buf[2] = 0x98badcfe; ctx->buf[2] = 0x98badcfe;
ctx->buf[3] = 0x10325476; ctx->buf[3] = 0x10325476;
ctx->bits[0] = 0; ctx->bits[0] = 0;
ctx->bits[1] = 0; ctx->bits[1] = 0;
} }
/* /*
* Update context to reflect the concatenation of another buffer full * Update context to reflect the concatenation of another buffer full
* of bytes. * of bytes.
*/ */
void MD5Update(ctx, buf, len) void MD5Update(ctx, buf, len)
struct MD5Context *ctx; unsigned char *buf; unsigned len; struct MD5Context *ctx; unsigned char *buf; unsigned len;
{ {
uint32 t; uint32 t;
/* Update bitcount */ /* Update bitcount */
t = ctx->bits[0]; t = ctx->bits[0];
if ((ctx->bits[0] = t + ((uint32) len << 3)) < t) if ((ctx->bits[0] = t + ((uint32) len << 3)) < t)
ctx->bits[1]++; /* Carry from low to high */ ctx->bits[1]++; /* Carry from low to high */
ctx->bits[1] += len >> 29; ctx->bits[1] += len >> 29;
t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */ t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */
/* Handle any leading odd-sized chunks */ /* Handle any leading odd-sized chunks */
if (t) { if (t) {
unsigned char *p = (unsigned char *) ctx->in + t; unsigned char *p = (unsigned char *) ctx->in + t;
t = 64 - t; t = 64 - t;
if (len < t) { if (len < t) {
memcpy(p, buf, len); memcpy(p, buf, len);
return; return;
} }
memcpy(p, buf, t); memcpy(p, buf, t);
byteReverse(ctx->in, 16); byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (uint32 *) ctx->in); MD5Transform(ctx->buf, (uint32 *) ctx->in);
buf += t; buf += t;
len -= t; len -= t;
} }
/* Process data in 64-byte chunks */ /* Process data in 64-byte chunks */
while (len >= 64) { while (len >= 64) {
memcpy(ctx->in, buf, 64); memcpy(ctx->in, buf, 64);
byteReverse(ctx->in, 16); byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (uint32 *) ctx->in); MD5Transform(ctx->buf, (uint32 *) ctx->in);
buf += 64; buf += 64;
len -= 64; len -= 64;
} }
/* Handle any remaining bytes of data. */ /* Handle any remaining bytes of data. */
memcpy(ctx->in, buf, len); memcpy(ctx->in, buf, len);
} }
/* /*
* Final wrapup - pad to 64-byte boundary with the bit pattern * Final wrapup - pad to 64-byte boundary with the bit pattern
* 1 0* (64-bit count of bits processed, MSB-first) * 1 0* (64-bit count of bits processed, MSB-first)
*/ */
void MD5Final(digest, ctx) void MD5Final(digest, ctx)
unsigned char digest[16]; struct MD5Context *ctx; unsigned char digest[16]; struct MD5Context *ctx;
{ {
unsigned count; unsigned count;
unsigned char *p; unsigned char *p;
/* Compute number of bytes mod 64 */ /* Compute number of bytes mod 64 */
count = (ctx->bits[0] >> 3) & 0x3F; count = (ctx->bits[0] >> 3) & 0x3F;
/* Set the first char of padding to 0x80. This is safe since there is /* Set the first char of padding to 0x80. This is safe since there is
always at least one byte free */ always at least one byte free */
p = ctx->in + count; p = ctx->in + count;
*p++ = 0x80; *p++ = 0x80;
/* Bytes of padding needed to make 64 bytes */ /* Bytes of padding needed to make 64 bytes */
count = 64 - 1 - count; count = 64 - 1 - count;
/* Pad out to 56 mod 64 */ /* Pad out to 56 mod 64 */
if (count < 8) { if (count < 8) {
/* Two lots of padding: Pad the first block to 64 bytes */ /* Two lots of padding: Pad the first block to 64 bytes */
memset(p, 0, count); memset(p, 0, count);
byteReverse(ctx->in, 16); byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (uint32 *) ctx->in); MD5Transform(ctx->buf, (uint32 *) ctx->in);
/* Now fill the next block with 56 bytes */ /* Now fill the next block with 56 bytes */
memset(ctx->in, 0, 56); memset(ctx->in, 0, 56);
} else { } else {
/* Pad block to 56 bytes */ /* Pad block to 56 bytes */
memset(p, 0, count - 8); memset(p, 0, count - 8);
} }
byteReverse(ctx->in, 14); byteReverse(ctx->in, 14);
/* Append length in bits and transform */ /* Append length in bits and transform */
((uint32 *) ctx->in)[14] = ctx->bits[0]; ((uint32 *) ctx->in)[14] = ctx->bits[0];
((uint32 *) ctx->in)[15] = ctx->bits[1]; ((uint32 *) ctx->in)[15] = ctx->bits[1];
MD5Transform(ctx->buf, (uint32 *) ctx->in); MD5Transform(ctx->buf, (uint32 *) ctx->in);
byteReverse((unsigned char *) ctx->buf, 4); byteReverse((unsigned char *) ctx->buf, 4);
memcpy(digest, ctx->buf, 16); memcpy(digest, ctx->buf, 16);
memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */ memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
} }
/* The four core functions - F1 is optimized somewhat */ /* The four core functions - F1 is optimized somewhat */
/* #define F1(x, y, z) (x & y | ~x & z) */ /* #define F1(x, y, z) (x & y | ~x & z) */
#define F1(x, y, z) (z ^ (x & (y ^ z))) #define F1(x, y, z) (z ^ (x & (y ^ z)))
#define F2(x, y, z) F1(z, x, y) #define F2(x, y, z) F1(z, x, y)
#define F3(x, y, z) (x ^ y ^ z) #define F3(x, y, z) (x ^ y ^ z)
#define F4(x, y, z) (y ^ (x | ~z)) #define F4(x, y, z) (y ^ (x | ~z))
/* This is the central step in the MD5 algorithm. */ /* This is the central step in the MD5 algorithm. */
#define MD5STEP(f, w, x, y, z, data, s) \ #define MD5STEP(f, w, x, y, z, data, s) \
( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x ) ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x )
/* /*
* The core of the MD5 algorithm, this alters an existing MD5 hash to * The core of the MD5 algorithm, this alters an existing MD5 hash to
* reflect the addition of 16 longwords of new data. MD5Update blocks * reflect the addition of 16 longwords of new data. MD5Update blocks
* the data and converts bytes into longwords for this routine. * the data and converts bytes into longwords for this routine.
*/ */
void MD5Transform(buf, in) void MD5Transform(buf, in)
uint32 buf[4]; uint32 in[16]; uint32 buf[4]; uint32 in[16];
{ {
register uint32 a, b, c, d; register uint32 a, b, c, d;
a = buf[0]; a = buf[0];
b = buf[1]; b = buf[1];
c = buf[2]; c = buf[2];
d = buf[3]; d = buf[3];
MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7); MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12); MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17); MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22); MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7); MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12); MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17); MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22); MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7); MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12); MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17); MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22); MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7); MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12); MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17); MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22); MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5); MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9); MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14); MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20); MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5); MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9); MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14); MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20); MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5); MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9); MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14); MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20); MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5); MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9); MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14); MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20); MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4); MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11); MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16); MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23); MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4); MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11); MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16); MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23); MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4); MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11); MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16); MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23); MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4); MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11); MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16); MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23); MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6); MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10); MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15); MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21); MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6); MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10); MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15); MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21); MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6); MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10); MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15); MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21); MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6); MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10); MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15); MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21); MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
buf[0] += a; buf[0] += a;
buf[1] += b; buf[1] += b;
buf[2] += c; buf[2] += c;
buf[3] += d; buf[3] += d;
} }

View File

@ -1,26 +1,26 @@
#ifndef MD5_H #ifndef MD5_H
#define MD5_H #define MD5_H
#if defined (__alpha__) || defined (__x86_64__) #if defined (__alpha__) || defined (__x86_64__)
typedef unsigned int uint32; typedef unsigned int uint32;
#else #else
typedef unsigned long uint32; typedef unsigned long uint32;
#endif #endif
struct MD5Context { struct MD5Context {
uint32 buf[4]; uint32 buf[4];
uint32 bits[2]; uint32 bits[2];
unsigned char in[64]; unsigned char in[64];
}; };
extern void MD5Init(); extern void MD5Init (struct MD5Context *ctx);
extern void MD5Update(); extern void MD5Update (struct MD5Context *ctx, unsigned char *buf, unsigned len);
extern void MD5Final(); extern void MD5Final (unsigned char digest[16], struct MD5Context *ctx);
extern void MD5Transform(); extern void MD5Transform (uint32 buf[4], uint32 in[16]);
/* /*
* This is needed to make RSAREF happy on some MS-DOS compilers. * This is needed to make RSAREF happy on some MS-DOS compilers.
*/ */
typedef struct MD5Context MD5_CTX; typedef struct MD5Context MD5_CTX;
#endif /* !MD5_H */ #endif /* !MD5_H */

View File

@ -1,310 +1,313 @@
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// **** WAVPACK **** // // **** WAVPACK **** //
// Hybrid Lossless Wavefile Compressor // // Hybrid Lossless Wavefile Compressor //
// Copyright (c) 1998 - 2005 Conifer Software. // // Copyright (c) 1998 - 2005 Conifer Software. //
// All Rights Reserved. // // All Rights Reserved. //
// Distributed under the BSD Software License (see license.txt) // // Distributed under the BSD Software License (see license.txt) //
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// metadata.c // metadata.c
// This module handles the metadata structure introduced in WavPack 4.0 // This module handles the metadata structure introduced in WavPack 4.0
#include "wavpack.h" #include "wavpack.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifdef DEBUG_ALLOC #ifdef DEBUG_ALLOC
#define malloc malloc_db #define malloc malloc_db
#define realloc realloc_db #define realloc realloc_db
#define free free_db #define free free_db
void *malloc_db (uint32_t size); void *malloc_db (uint32_t size);
void *realloc_db (void *ptr, uint32_t size); void *realloc_db (void *ptr, uint32_t size);
void free_db (void *ptr); void free_db (void *ptr);
int32_t dump_alloc (void); int32_t dump_alloc (void);
#endif #endif
#if defined(UNPACK) || defined(INFO_ONLY) #if defined(UNPACK) || defined(INFO_ONLY)
int read_metadata_buff (WavpackMetadata *wpmd, uchar *blockbuff, uchar **buffptr) int read_metadata_buff (WavpackMetadata *wpmd, uchar *blockbuff, uchar **buffptr)
{ {
WavpackHeader *wphdr = (WavpackHeader *) blockbuff; WavpackHeader *wphdr = (WavpackHeader *) blockbuff;
uchar *buffend = blockbuff + wphdr->ckSize + 8; uchar *buffend = blockbuff + wphdr->ckSize + 8;
if (buffend - *buffptr < 2) if (buffend - *buffptr < 2)
return FALSE; return FALSE;
wpmd->id = *(*buffptr)++; wpmd->id = *(*buffptr)++;
wpmd->byte_length = *(*buffptr)++ << 1; wpmd->byte_length = *(*buffptr)++ << 1;
if (wpmd->id & ID_LARGE) { if (wpmd->id & ID_LARGE) {
wpmd->id &= ~ID_LARGE; wpmd->id &= ~ID_LARGE;
if (buffend - *buffptr < 2) if (buffend - *buffptr < 2)
return FALSE; return FALSE;
wpmd->byte_length += *(*buffptr)++ << 9; wpmd->byte_length += *(*buffptr)++ << 9;
wpmd->byte_length += *(*buffptr)++ << 17; wpmd->byte_length += *(*buffptr)++ << 17;
} }
if (wpmd->id & ID_ODD_SIZE) { if (wpmd->id & ID_ODD_SIZE) {
wpmd->id &= ~ID_ODD_SIZE; wpmd->id &= ~ID_ODD_SIZE;
wpmd->byte_length--; wpmd->byte_length--;
} }
if (wpmd->byte_length) { if (wpmd->byte_length) {
if (buffend - *buffptr < wpmd->byte_length + (wpmd->byte_length & 1)) { if (buffend - *buffptr < wpmd->byte_length + (wpmd->byte_length & 1)) {
wpmd->data = NULL; wpmd->data = NULL;
return FALSE; return FALSE;
} }
wpmd->data = *buffptr; wpmd->data = *buffptr;
(*buffptr) += wpmd->byte_length + (wpmd->byte_length & 1); (*buffptr) += wpmd->byte_length + (wpmd->byte_length & 1);
} }
else else
wpmd->data = NULL; wpmd->data = NULL;
return TRUE; return TRUE;
} }
int process_metadata (WavpackContext *wpc, WavpackMetadata *wpmd) int process_metadata (WavpackContext *wpc, WavpackMetadata *wpmd)
{ {
WavpackStream *wps = wpc->streams [wpc->current_stream]; WavpackStream *wps = wpc->streams [wpc->current_stream];
switch (wpmd->id) { switch (wpmd->id) {
case ID_DUMMY: case ID_DUMMY:
return TRUE; return TRUE;
case ID_DECORR_TERMS: case ID_DECORR_TERMS:
return read_decorr_terms (wps, wpmd); return read_decorr_terms (wps, wpmd);
case ID_DECORR_WEIGHTS: case ID_DECORR_WEIGHTS:
return read_decorr_weights (wps, wpmd); return read_decorr_weights (wps, wpmd);
case ID_DECORR_SAMPLES: case ID_DECORR_SAMPLES:
return read_decorr_samples (wps, wpmd); return read_decorr_samples (wps, wpmd);
case ID_ENTROPY_VARS: case ID_ENTROPY_VARS:
return read_entropy_vars (wps, wpmd); return read_entropy_vars (wps, wpmd);
case ID_HYBRID_PROFILE: case ID_HYBRID_PROFILE:
return read_hybrid_profile (wps, wpmd); return read_hybrid_profile (wps, wpmd);
case ID_SHAPING_WEIGHTS: case ID_SHAPING_WEIGHTS:
return read_shaping_info (wps, wpmd); return read_shaping_info (wps, wpmd);
case ID_FLOAT_INFO: case ID_FLOAT_INFO:
return read_float_info (wps, wpmd); return read_float_info (wps, wpmd);
case ID_INT32_INFO: case ID_INT32_INFO:
return read_int32_info (wps, wpmd); return read_int32_info (wps, wpmd);
case ID_CHANNEL_INFO: case ID_CHANNEL_INFO:
return read_channel_info (wpc, wpmd); return read_channel_info (wpc, wpmd);
case ID_CONFIG_BLOCK: case ID_CONFIG_BLOCK:
return read_config_info (wpc, wpmd); return read_config_info (wpc, wpmd);
case ID_WV_BITSTREAM: case ID_SAMPLE_RATE:
return init_wv_bitstream (wps, wpmd); return read_sample_rate (wpc, wpmd);
case ID_WVC_BITSTREAM: case ID_WV_BITSTREAM:
return init_wvc_bitstream (wps, wpmd); return init_wv_bitstream (wps, wpmd);
case ID_WVX_BITSTREAM: case ID_WVC_BITSTREAM:
return init_wvx_bitstream (wps, wpmd); return init_wvc_bitstream (wps, wpmd);
case ID_RIFF_HEADER: case ID_RIFF_TRAILER: case ID_WVX_BITSTREAM:
return read_wrapper_data (wpc, wpmd); return init_wvx_bitstream (wps, wpmd);
case ID_MD5_CHECKSUM: case ID_RIFF_HEADER: case ID_RIFF_TRAILER:
if (wpmd->byte_length == 16) { return read_wrapper_data (wpc, wpmd);
memcpy (wpc->config.md5_checksum, wpmd->data, 16);
wpc->config.flags |= CONFIG_MD5_CHECKSUM; case ID_MD5_CHECKSUM:
wpc->config.md5_read = 1; if (wpmd->byte_length == 16) {
} memcpy (wpc->config.md5_checksum, wpmd->data, 16);
wpc->config.flags |= CONFIG_MD5_CHECKSUM;
return TRUE; wpc->config.md5_read = 1;
}
default:
return (wpmd->id & ID_OPTIONAL_DATA) ? TRUE : FALSE; return TRUE;
}
} default:
return (wpmd->id & ID_OPTIONAL_DATA) ? TRUE : FALSE;
#endif }
}
#ifdef PACK
#endif
int copy_metadata (WavpackMetadata *wpmd, uchar *buffer_start, uchar *buffer_end)
{ #ifdef PACK
uint32_t mdsize = wpmd->byte_length + (wpmd->byte_length & 1);
WavpackHeader *wphdr = (WavpackHeader *) buffer_start; int copy_metadata (WavpackMetadata *wpmd, uchar *buffer_start, uchar *buffer_end)
{
if (wpmd->byte_length & 1) uint32_t mdsize = wpmd->byte_length + (wpmd->byte_length & 1);
((char *) wpmd->data) [wpmd->byte_length] = 0; WavpackHeader *wphdr = (WavpackHeader *) buffer_start;
mdsize += (wpmd->byte_length > 510) ? 4 : 2; if (wpmd->byte_length & 1)
buffer_start += wphdr->ckSize + 8; ((char *) wpmd->data) [wpmd->byte_length] = 0;
if (buffer_start + mdsize >= buffer_end) mdsize += (wpmd->byte_length > 510) ? 4 : 2;
return FALSE; buffer_start += wphdr->ckSize + 8;
buffer_start [0] = wpmd->id | (wpmd->byte_length & 1 ? ID_ODD_SIZE : 0); if (buffer_start + mdsize >= buffer_end)
buffer_start [1] = (wpmd->byte_length + 1) >> 1; return FALSE;
if (wpmd->byte_length > 510) { buffer_start [0] = wpmd->id | (wpmd->byte_length & 1 ? ID_ODD_SIZE : 0);
buffer_start [0] |= ID_LARGE; buffer_start [1] = (wpmd->byte_length + 1) >> 1;
buffer_start [2] = (wpmd->byte_length + 1) >> 9;
buffer_start [3] = (wpmd->byte_length + 1) >> 17; if (wpmd->byte_length > 510) {
} buffer_start [0] |= ID_LARGE;
buffer_start [2] = (wpmd->byte_length + 1) >> 9;
if (wpmd->data && wpmd->byte_length) { buffer_start [3] = (wpmd->byte_length + 1) >> 17;
if (wpmd->byte_length > 510) { }
buffer_start [0] |= ID_LARGE;
buffer_start [2] = (wpmd->byte_length + 1) >> 9; if (wpmd->data && wpmd->byte_length) {
buffer_start [3] = (wpmd->byte_length + 1) >> 17; if (wpmd->byte_length > 510) {
memcpy (buffer_start + 4, wpmd->data, mdsize - 4); buffer_start [0] |= ID_LARGE;
} buffer_start [2] = (wpmd->byte_length + 1) >> 9;
else buffer_start [3] = (wpmd->byte_length + 1) >> 17;
memcpy (buffer_start + 2, wpmd->data, mdsize - 2); memcpy (buffer_start + 4, wpmd->data, mdsize - 4);
} }
else
wphdr->ckSize += mdsize; memcpy (buffer_start + 2, wpmd->data, mdsize - 2);
return TRUE; }
}
wphdr->ckSize += mdsize;
int add_to_metadata (WavpackContext *wpc, void *data, uint32_t bcount, uchar id) return TRUE;
{ }
WavpackMetadata *mdp;
uchar *src = data; int add_to_metadata (WavpackContext *wpc, void *data, uint32_t bcount, uchar id)
{
while (bcount) { WavpackMetadata *mdp;
if (wpc->metacount) { uchar *src = data;
uint32_t bc = bcount;
while (bcount) {
mdp = wpc->metadata + wpc->metacount - 1; if (wpc->metacount) {
uint32_t bc = bcount;
if (mdp->id == id) {
if (wpc->metabytes + bcount > 1000000) mdp = wpc->metadata + wpc->metacount - 1;
bc = 1000000 - wpc->metabytes;
if (mdp->id == id) {
mdp->data = realloc (mdp->data, mdp->byte_length + bc); if (wpc->metabytes + bcount > 1000000)
memcpy ((char *) mdp->data + mdp->byte_length, src, bc); bc = 1000000 - wpc->metabytes;
mdp->byte_length += bc;
wpc->metabytes += bc; mdp->data = realloc (mdp->data, mdp->byte_length + bc);
bcount -= bc; memcpy ((char *) mdp->data + mdp->byte_length, src, bc);
src += bc; mdp->byte_length += bc;
wpc->metabytes += bc;
if (wpc->metabytes >= 1000000 && !write_metadata_block (wpc)) bcount -= bc;
return FALSE; src += bc;
}
} if (wpc->metabytes >= 1000000 && !write_metadata_block (wpc))
return FALSE;
if (bcount) { }
wpc->metadata = realloc (wpc->metadata, (wpc->metacount + 1) * sizeof (WavpackMetadata)); }
mdp = wpc->metadata + wpc->metacount++;
mdp->byte_length = 0; if (bcount) {
mdp->data = NULL; wpc->metadata = realloc (wpc->metadata, (wpc->metacount + 1) * sizeof (WavpackMetadata));
mdp->id = id; mdp = wpc->metadata + wpc->metacount++;
} mdp->byte_length = 0;
} mdp->data = NULL;
mdp->id = id;
return TRUE; }
} }
static char *write_metadata (WavpackMetadata *wpmd, char *outdata) return TRUE;
{ }
uchar id = wpmd->id, wordlen [3];
static char *write_metadata (WavpackMetadata *wpmd, char *outdata)
wordlen [0] = (wpmd->byte_length + 1) >> 1; {
wordlen [1] = (wpmd->byte_length + 1) >> 9; uchar id = wpmd->id, wordlen [3];
wordlen [2] = (wpmd->byte_length + 1) >> 17;
wordlen [0] = (wpmd->byte_length + 1) >> 1;
if (wpmd->byte_length & 1) { wordlen [1] = (wpmd->byte_length + 1) >> 9;
// ((char *) wpmd->data) [wpmd->byte_length] = 0; wordlen [2] = (wpmd->byte_length + 1) >> 17;
id |= ID_ODD_SIZE;
} if (wpmd->byte_length & 1) {
// ((char *) wpmd->data) [wpmd->byte_length] = 0;
if (wordlen [1] || wordlen [2]) id |= ID_ODD_SIZE;
id |= ID_LARGE; }
*outdata++ = id; if (wordlen [1] || wordlen [2])
*outdata++ = wordlen [0]; id |= ID_LARGE;
if (id & ID_LARGE) { *outdata++ = id;
*outdata++ = wordlen [1]; *outdata++ = wordlen [0];
*outdata++ = wordlen [2];
} if (id & ID_LARGE) {
*outdata++ = wordlen [1];
if (wpmd->data && wpmd->byte_length) { *outdata++ = wordlen [2];
memcpy (outdata, wpmd->data, wpmd->byte_length); }
outdata += wpmd->byte_length;
if (wpmd->data && wpmd->byte_length) {
if (wpmd->byte_length & 1) memcpy (outdata, wpmd->data, wpmd->byte_length);
*outdata++ = 0; outdata += wpmd->byte_length;
}
if (wpmd->byte_length & 1)
return outdata; *outdata++ = 0;
} }
int write_metadata_block (WavpackContext *wpc) return outdata;
{ }
char *block_buff, *block_ptr;
WavpackHeader *wphdr; int write_metadata_block (WavpackContext *wpc)
{
if (wpc->metacount) { char *block_buff, *block_ptr;
int metacount = wpc->metacount, block_size = sizeof (WavpackHeader); WavpackHeader *wphdr;
WavpackMetadata *wpmdp = wpc->metadata;
if (wpc->metacount) {
while (metacount--) { int metacount = wpc->metacount, block_size = sizeof (WavpackHeader);
block_size += wpmdp->byte_length + (wpmdp->byte_length & 1); WavpackMetadata *wpmdp = wpc->metadata;
block_size += (wpmdp->byte_length > 510) ? 4 : 2;
wpmdp++; while (metacount--) {
} block_size += wpmdp->byte_length + (wpmdp->byte_length & 1);
block_size += (wpmdp->byte_length > 510) ? 4 : 2;
wphdr = (WavpackHeader *) (block_buff = malloc (block_size)); wpmdp++;
}
CLEAR (*wphdr);
memcpy (wphdr->ckID, "wvpk", 4); wphdr = (WavpackHeader *) (block_buff = malloc (block_size));
wphdr->total_samples = wpc->total_samples;
wphdr->version = 0x403; CLEAR (*wphdr);
wphdr->ckSize = block_size - 8; memcpy (wphdr->ckID, "wvpk", 4);
wphdr->block_samples = 0; wphdr->total_samples = wpc->total_samples;
wphdr->version = wpc->stream_version;
block_ptr = (char *)(wphdr + 1); wphdr->ckSize = block_size - 8;
wphdr->block_samples = 0;
wpmdp = wpc->metadata;
block_ptr = (char *)(wphdr + 1);
while (wpc->metacount) {
block_ptr = write_metadata (wpmdp, block_ptr); wpmdp = wpc->metadata;
wpc->metabytes -= wpmdp->byte_length;
free_metadata (wpmdp++); while (wpc->metacount) {
wpc->metacount--; block_ptr = write_metadata (wpmdp, block_ptr);
} wpc->metabytes -= wpmdp->byte_length;
free_metadata (wpmdp++);
free (wpc->metadata); wpc->metacount--;
wpc->metadata = NULL; }
native_to_little_endian ((WavpackHeader *) block_buff, WavpackHeaderFormat);
free (wpc->metadata);
if (!wpc->blockout (wpc->wv_out, block_buff, block_size)) { wpc->metadata = NULL;
free (block_buff); native_to_little_endian ((WavpackHeader *) block_buff, WavpackHeaderFormat);
strcpy (wpc->error_message, "can't write WavPack data, disk probably full!");
return FALSE; if (!wpc->blockout (wpc->wv_out, block_buff, block_size)) {
} free (block_buff);
strcpy (wpc->error_message, "can't write WavPack data, disk probably full!");
free (block_buff); return FALSE;
} }
return TRUE; free (block_buff);
} }
#endif return TRUE;
}
void free_metadata (WavpackMetadata *wpmd)
{ #endif
if (wpmd->data) {
free (wpmd->data); void free_metadata (WavpackMetadata *wpmd)
wpmd->data = NULL; {
} if (wpmd->data) {
} free (wpmd->data);
wpmd->data = NULL;
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,113 +1,113 @@
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// **** WAVPACK **** // // **** WAVPACK **** //
// Hybrid Lossless Wavefile Compressor // // Hybrid Lossless Wavefile Compressor //
// Copyright (c) 1998 - 2005 Conifer Software. // // Copyright (c) 1998 - 2005 Conifer Software. //
// All Rights Reserved. // // All Rights Reserved. //
// Distributed under the BSD Software License (see license.txt) // // Distributed under the BSD Software License (see license.txt) //
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// wavpack3.h // wavpack3.h
// This header file contains all the additional definitions required for // This header file contains all the additional definitions required for
// decoding old (versions 1, 2 & 3) WavPack files. // decoding old (versions 1, 2 & 3) WavPack files.
typedef struct { typedef struct {
ushort FormatTag, NumChannels; ushort FormatTag, NumChannels;
uint32_t SampleRate, BytesPerSecond; uint32_t SampleRate, BytesPerSecond;
ushort BlockAlign, BitsPerSample; ushort BlockAlign, BitsPerSample;
} WaveHeader3; } WaveHeader3;
#define WaveHeader3Format "SSLLSS" #define WaveHeader3Format "SSLLSS"
typedef struct { typedef struct {
char ckID [4]; char ckID [4];
int32_t ckSize; int32_t ckSize;
short version; short version;
short bits; // added for version 2.00 short bits; // added for version 2.00
short flags, shift; // added for version 3.00 short flags, shift; // added for version 3.00
int32_t total_samples, crc, crc2; int32_t total_samples, crc, crc2;
char extension [4], extra_bc, extras [3]; char extension [4], extra_bc, extras [3];
} WavpackHeader3; } WavpackHeader3;
#define WavpackHeader3Format "4LSSSSLLL4L" #define WavpackHeader3Format "4LSSSSLLL4L"
// these flags added for version 3 // these flags added for version 3
#undef MONO_FLAG // these definitions changed for WavPack 4.0 #undef MONO_FLAG // these definitions changed for WavPack 4.0
#undef CROSS_DECORR #undef CROSS_DECORR
#undef JOINT_STEREO #undef JOINT_STEREO
#define MONO_FLAG 1 // not stereo #define MONO_FLAG 1 // not stereo
#define FAST_FLAG 2 // non-adaptive predictor and stereo mode #define FAST_FLAG 2 // non-adaptive predictor and stereo mode
#define RAW_FLAG 4 // raw mode (no .wav header) #define RAW_FLAG 4 // raw mode (no .wav header)
#define CALC_NOISE 8 // calc noise in lossy mode (no longer stored) #define CALC_NOISE 8 // calc noise in lossy mode (no longer stored)
#define HIGH_FLAG 0x10 // high quality mode (all modes) #define HIGH_FLAG 0x10 // high quality mode (all modes)
#define BYTES_3 0x20 // files have 3-byte samples #define BYTES_3 0x20 // files have 3-byte samples
#define OVER_20 0x40 // samples are over 20 bits #define OVER_20 0x40 // samples are over 20 bits
#define WVC_FLAG 0x80 // create/use .wvc (no longer stored) #define WVC_FLAG 0x80 // create/use .wvc (no longer stored)
#define LOSSY_SHAPE 0x100 // noise shape (lossy mode only) #define LOSSY_SHAPE 0x100 // noise shape (lossy mode only)
#define VERY_FAST_FLAG 0x200 // double fast (no longer stored) #define VERY_FAST_FLAG 0x200 // double fast (no longer stored)
#define NEW_HIGH_FLAG 0x400 // new high quality mode (lossless only) #define NEW_HIGH_FLAG 0x400 // new high quality mode (lossless only)
#define CANCEL_EXTREME 0x800 // cancel EXTREME_DECORR #define CANCEL_EXTREME 0x800 // cancel EXTREME_DECORR
#define CROSS_DECORR 0x1000 // decorrelate chans (with EXTREME_DECORR flag) #define CROSS_DECORR 0x1000 // decorrelate chans (with EXTREME_DECORR flag)
#define NEW_DECORR_FLAG 0x2000 // new high-mode decorrelator #define NEW_DECORR_FLAG 0x2000 // new high-mode decorrelator
#define JOINT_STEREO 0x4000 // joint stereo (lossy and high lossless) #define JOINT_STEREO 0x4000 // joint stereo (lossy and high lossless)
#define EXTREME_DECORR 0x8000 // extra decorrelation (+ enables other flags) #define EXTREME_DECORR 0x8000 // extra decorrelation (+ enables other flags)
#define STORED_FLAGS 0xfd77 // these are only flags that affect unpacking #define STORED_FLAGS 0xfd77 // these are only flags that affect unpacking
#define NOT_STORED_FLAGS (~STORED_FLAGS & 0xffff) #define NOT_STORED_FLAGS (~STORED_FLAGS & 0xffff)
// BitStream stuff (bits.c) // BitStream stuff (bits.c)
typedef struct bs3 { typedef struct bs3 {
void (*wrap)(struct bs3 *bs); void (*wrap)(struct bs3 *bs);
uchar *buf, *end, *ptr; uchar *buf, *end, *ptr;
uint32_t bufsiz, fpos, sr; uint32_t bufsiz, fpos, sr;
stream_reader *reader; WavpackStreamReader *reader;
int error, bc; int error, bc;
void *id; void *id;
} Bitstream3; } Bitstream3;
#define K_DEPTH 3 #define K_DEPTH 3
#define MAX_NTERMS3 18 #define MAX_NTERMS3 18
typedef struct { typedef struct {
WavpackHeader3 wphdr; WavpackHeader3 wphdr;
Bitstream3 wvbits, wvcbits; Bitstream3 wvbits, wvcbits;
uint32_t sample_index; uint32_t sample_index;
int num_terms; int num_terms;
#ifdef SEEKING #ifdef SEEKING
struct index_point { struct index_point {
char saved; char saved;
uint32_t sample_index; uint32_t sample_index;
} index_points [256]; } index_points [256];
uchar *unpack_data; uchar *unpack_data;
uint32_t unpack_size; uint32_t unpack_size;
#endif #endif
struct { struct {
int32_t sum_level, left_level, right_level, diff_level; int32_t sum_level, left_level, right_level, diff_level;
int last_extra_bits, extra_bits_count, m; int last_extra_bits, extra_bits_count, m;
int32_t error [2], crc; int32_t error [2], crc;
int32_t sample [2] [2]; int32_t sample [2] [2];
int weight [2] [1]; int weight [2] [1];
} dc; } dc;
struct decorr_pass decorr_passes [MAX_NTERMS3]; struct decorr_pass decorr_passes [MAX_NTERMS3];
struct { struct {
uint index [2], k_value [2], ave_k [2]; uint index [2], k_value [2], ave_k [2];
uint32_t zeros_acc, ave_level [K_DEPTH] [2]; uint32_t zeros_acc, ave_level [K_DEPTH] [2];
} w1; } w1;
struct { int last_dbits [2], last_delta_sign [2], bit_limit; } w2; struct { int last_dbits [2], last_delta_sign [2], bit_limit; } w2;
struct { int ave_dbits [2], bit_limit; } w3; struct { int ave_dbits [2], bit_limit; } w3;
struct { struct {
uint32_t fast_level [2], slow_level [2]; uint32_t fast_level [2], slow_level [2];
int bits_acc [2], bitrate; int bits_acc [2], bitrate;
} w4; } w4;
} WavpackStream3; } WavpackStream3;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,163 +1,172 @@
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// **** WAVPACK **** // // **** WAVPACK **** //
// Hybrid Lossless Wavefile Compressor // // Hybrid Lossless Wavefile Compressor //
// Copyright (c) 1998 - 2005 Conifer Software. // // Copyright (c) 1998 - 2005 Conifer Software. //
// All Rights Reserved. // // All Rights Reserved. //
// Distributed under the BSD Software License (see license.txt) // // Distributed under the BSD Software License (see license.txt) //
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// wputils.h // wputils.h
#ifndef WPUTILS_H #ifndef WPUTILS_H
#define WPUTILS_H #define WPUTILS_H
// This header file contains all the definitions required to use the // This header file contains all the definitions required to use the
// functions in "wputils.c" to read and write WavPack files and streams. // functions in "wputils.c" to read and write WavPack files and streams.
#include <sys/types.h> #include <sys/types.h>
#if defined(_WIN32) && !defined(__MINGW32__) #if defined(_WIN32) && !defined(__MINGW32__)
#include <stdlib.h> #include <stdlib.h>
typedef unsigned __int64 uint64_t; typedef unsigned __int64 uint64_t;
typedef unsigned __int32 uint32_t; typedef unsigned __int32 uint32_t;
typedef unsigned __int16 uint16_t; typedef unsigned __int16 uint16_t;
typedef unsigned __int8 uint8_t; typedef unsigned __int8 uint8_t;
typedef __int64 int64_t; typedef __int64 int64_t;
typedef __int32 int32_t; typedef __int32 int32_t;
typedef __int16 int16_t; typedef __int16 int16_t;
typedef __int8 int8_t; typedef __int8 int8_t;
typedef float float32_t; typedef float float32_t;
#else #else
#include <inttypes.h> #include <inttypes.h>
#endif #endif
typedef unsigned char uchar; typedef unsigned char uchar;
#if !defined(__GNUC__) || defined(WIN32) #if !defined(__GNUC__) || defined(WIN32)
typedef unsigned short ushort; typedef unsigned short ushort;
typedef unsigned int uint; typedef unsigned int uint;
#endif #endif
///////////////////////// WavPack Configuration /////////////////////////////// ///////////////////////// WavPack Configuration ///////////////////////////////
// This external structure is used during encode to provide configuration to // This external structure is used during encode to provide configuration to
// the encoding engine and during decoding to provide fle information back to // the encoding engine and during decoding to provide fle information back to
// the higher level functions. Not all fields are used in both modes. // the higher level functions. Not all fields are used in both modes.
typedef struct { typedef struct {
float bitrate, shaping_weight; float bitrate, shaping_weight;
int bits_per_sample, bytes_per_sample; int bits_per_sample, bytes_per_sample;
int qmode, flags, xmode, num_channels, float_norm_exp; int qmode, flags, xmode, num_channels, float_norm_exp;
int32_t block_samples, extra_flags, sample_rate, channel_mask; int32_t block_samples, extra_flags, sample_rate, channel_mask;
uchar md5_checksum [16], md5_read; uchar md5_checksum [16], md5_read;
int num_tag_strings; int num_tag_strings;
char **tag_strings; char **tag_strings;
} WavpackConfig; } WavpackConfig;
#define CONFIG_HYBRID_FLAG 8 // hybrid mode #define CONFIG_HYBRID_FLAG 8 // hybrid mode
#define CONFIG_JOINT_STEREO 0x10 // joint stereo #define CONFIG_JOINT_STEREO 0x10 // joint stereo
#define CONFIG_HYBRID_SHAPE 0x40 // noise shape (hybrid mode only) #define CONFIG_HYBRID_SHAPE 0x40 // noise shape (hybrid mode only)
#define CONFIG_FAST_FLAG 0x200 // fast mode #define CONFIG_FAST_FLAG 0x200 // fast mode
#define CONFIG_HIGH_FLAG 0x800 // high quality mode #define CONFIG_HIGH_FLAG 0x800 // high quality mode
#define CONFIG_BITRATE_KBPS 0x2000 // bitrate is kbps, not bits / sample #define CONFIG_BITRATE_KBPS 0x2000 // bitrate is kbps, not bits / sample
#define CONFIG_SHAPE_OVERRIDE 0x8000 // shaping mode specified #define CONFIG_SHAPE_OVERRIDE 0x8000 // shaping mode specified
#define CONFIG_JOINT_OVERRIDE 0x10000 // joint-stereo mode specified #define CONFIG_JOINT_OVERRIDE 0x10000 // joint-stereo mode specified
#define CONFIG_CREATE_WVC 0x80000 // create correction file #define CONFIG_CREATE_EXE 0x40000 // create executable
#define CONFIG_OPTIMIZE_WVC 0x100000 // maximize bybrid compression #define CONFIG_CREATE_WVC 0x80000 // create correction file
#define CONFIG_CALC_NOISE 0x800000 // calc noise in hybrid mode #define CONFIG_OPTIMIZE_WVC 0x100000 // maximize bybrid compression
#define CONFIG_EXTRA_MODE 0x2000000 // extra processing mode #define CONFIG_CALC_NOISE 0x800000 // calc noise in hybrid mode
#define CONFIG_SKIP_WVX 0x4000000 // no wvx stream w/ floats & big ints #define CONFIG_EXTRA_MODE 0x2000000 // extra processing mode
#define CONFIG_SKIP_WVX 0x4000000 // no wvx stream w/ floats & big ints
////////////// Callbacks used for reading & writing WavPack streams ////////// #define CONFIG_MD5_CHECKSUM 0x8000000 // store MD5 signature
typedef struct { ////////////// Callbacks used for reading & writing WavPack streams //////////
int32_t (*read_bytes)(void *id, void *data, int32_t bcount);
uint32_t (*get_pos)(void *id); typedef struct {
int (*set_pos_abs)(void *id, uint32_t pos); int32_t (*read_bytes)(void *id, void *data, int32_t bcount);
int (*set_pos_rel)(void *id, int32_t delta, int mode); uint32_t (*get_pos)(void *id);
int (*push_back_byte)(void *id, int c); int (*set_pos_abs)(void *id, uint32_t pos);
uint32_t (*get_length)(void *id); int (*set_pos_rel)(void *id, int32_t delta, int mode);
int (*can_seek)(void *id); int (*push_back_byte)(void *id, int c);
} stream_reader; uint32_t (*get_length)(void *id);
int (*can_seek)(void *id);
typedef int (*blockout)(void *id, void *data, int32_t bcount);
// this callback is for writing edited tags only
//////////////////////// function prototypes and macros ////////////////////// int32_t (*write_bytes)(void *id, void *data, int32_t bcount);
} WavpackStreamReader;
typedef void WavpackContext;
typedef int (*WavpackBlockOutput)(void *id, void *data, int32_t bcount);
#ifdef __cplusplus
extern "C" { //////////////////////// function prototypes and macros //////////////////////
#endif
typedef void WavpackContext;
WavpackContext *WavpackOpenFileInputEx (stream_reader *reader, void *wv_id, void *wvc_id, char *error, int flags, int norm_offset);
WavpackContext *WavpackOpenFileInput (const char *infilename, char *error, int flags, int norm_offset); #ifdef __cplusplus
extern "C" {
#define OPEN_WVC 0x1 // open/read "correction" file #endif
#define OPEN_TAGS 0x2 // read ID3v1 / APEv2 tags (seekable file)
#define OPEN_WRAPPER 0x4 // make audio wrapper available (i.e. RIFF) WavpackContext *WavpackOpenFileInputEx (WavpackStreamReader *reader, void *wv_id, void *wvc_id, char *error, int flags, int norm_offset);
#define OPEN_2CH_MAX 0x8 // open multichannel as stereo (no downmix) WavpackContext *WavpackOpenFileInput (const char *infilename, char *error, int flags, int norm_offset);
#define OPEN_NORMALIZE 0x10 // normalize floating point data to +/- 1.0
#define OPEN_STREAMING 0x20 // "streaming" mode blindly unpacks blocks #define OPEN_WVC 0x1 // open/read "correction" file
// w/o regard to header file position info #define OPEN_TAGS 0x2 // read ID3v1 / APEv2 tags (seekable file)
#define OPEN_WRAPPER 0x4 // make audio wrapper available (i.e. RIFF)
int WavpackGetMode (WavpackContext *wpc); #define OPEN_2CH_MAX 0x8 // open multichannel as stereo (no downmix)
#define OPEN_NORMALIZE 0x10 // normalize floating point data to +/- 1.0
#define MODE_WVC 0x1 #define OPEN_STREAMING 0x20 // "streaming" mode blindly unpacks blocks
#define MODE_LOSSLESS 0x2 // w/o regard to header file position info
#define MODE_HYBRID 0x4 #define OPEN_EDIT_TAGS 0x40 // allow editing of tags
#define MODE_FLOAT 0x8
#define MODE_VALID_TAG 0x10 int WavpackGetMode (WavpackContext *wpc);
#define MODE_HIGH 0x20
#define MODE_FAST 0x40 #define MODE_WVC 0x1
#define MODE_EXTRA 0x80 #define MODE_LOSSLESS 0x2
#define MODE_APETAG 0x100 #define MODE_HYBRID 0x4
#define MODE_SFX 0x200 #define MODE_FLOAT 0x8
#define MODE_VALID_TAG 0x10
int WavpackGetVersion (WavpackContext *wpc); #define MODE_HIGH 0x20
uint32_t WavpackUnpackSamples (WavpackContext *wpc, int32_t *buffer, uint32_t samples); #define MODE_FAST 0x40
uint32_t WavpackGetNumSamples (WavpackContext *wpc); #define MODE_EXTRA 0x80
uint32_t WavpackGetSampleIndex (WavpackContext *wpc); #define MODE_APETAG 0x100
int WavpackGetNumErrors (WavpackContext *wpc); #define MODE_SFX 0x200
int WavpackLossyBlocks (WavpackContext *wpc);
int WavpackSeekSample (WavpackContext *wpc, uint32_t sample); int WavpackGetVersion (WavpackContext *wpc);
WavpackContext *WavpackCloseFile (WavpackContext *wpc); uint32_t WavpackUnpackSamples (WavpackContext *wpc, int32_t *buffer, uint32_t samples);
uint32_t WavpackGetSampleRate (WavpackContext *wpc); uint32_t WavpackGetNumSamples (WavpackContext *wpc);
int WavpackGetBitsPerSample (WavpackContext *wpc); uint32_t WavpackGetSampleIndex (WavpackContext *wpc);
int WavpackGetBytesPerSample (WavpackContext *wpc); int WavpackGetNumErrors (WavpackContext *wpc);
int WavpackGetNumChannels (WavpackContext *wpc); int WavpackLossyBlocks (WavpackContext *wpc);
int WavpackGetReducedChannels (WavpackContext *wpc); int WavpackSeekSample (WavpackContext *wpc, uint32_t sample);
int WavpackGetFloatNormExp (WavpackContext *wpc); WavpackContext *WavpackCloseFile (WavpackContext *wpc);
int WavpackGetMD5Sum (WavpackContext *wpc, uchar data [16]); uint32_t WavpackGetSampleRate (WavpackContext *wpc);
uint32_t WavpackGetWrapperBytes (WavpackContext *wpc); int WavpackGetBitsPerSample (WavpackContext *wpc);
uchar *WavpackGetWrapperData (WavpackContext *wpc); int WavpackGetBytesPerSample (WavpackContext *wpc);
void WavpackFreeWrapper (WavpackContext *wpc); int WavpackGetNumChannels (WavpackContext *wpc);
double WavpackGetProgress (WavpackContext *wpc); int WavpackGetReducedChannels (WavpackContext *wpc);
uint32_t WavpackGetFileSize (WavpackContext *wpc); int WavpackGetFloatNormExp (WavpackContext *wpc);
double WavpackGetRatio (WavpackContext *wpc); int WavpackGetMD5Sum (WavpackContext *wpc, uchar data [16]);
double WavpackGetAverageBitrate (WavpackContext *wpc, int count_wvc); uint32_t WavpackGetWrapperBytes (WavpackContext *wpc);
double WavpackGetInstantBitrate (WavpackContext *wpc); uchar *WavpackGetWrapperData (WavpackContext *wpc);
int WavpackGetTagItem (WavpackContext *wpc, const char *item, char *value, int size); void WavpackFreeWrapper (WavpackContext *wpc);
int WavpackAppendTagItem (WavpackContext *wpc, const char *item, const char *value); double WavpackGetProgress (WavpackContext *wpc);
int WavpackWriteTag (WavpackContext *wpc); uint32_t WavpackGetFileSize (WavpackContext *wpc);
double WavpackGetRatio (WavpackContext *wpc);
double WavpackGetAverageBitrate (WavpackContext *wpc, int count_wvc);
WavpackContext *WavpackOpenFileOutput (blockout blockout, void *wv_id, void *wvc_id); double WavpackGetInstantBitrate (WavpackContext *wpc);
int WavpackSetConfiguration (WavpackContext *wpc, WavpackConfig *config, uint32_t total_samples); int WavpackGetNumTagItems (WavpackContext *wpc);
int WavpackAddWrapper (WavpackContext *wpc, void *data, uint32_t bcount); int WavpackGetTagItem (WavpackContext *wpc, const char *item, char *value, int size);
int WavpackStoreMD5Sum (WavpackContext *wpc, uchar data [16]); int WavpackGetTagItemIndexed (WavpackContext *wpc, int index, char *item, int size);
int WavpackPackInit (WavpackContext *wpc); int WavpackAppendTagItem (WavpackContext *wpc, const char *item, const char *value, int vsize);
int WavpackPackSamples (WavpackContext *wpc, int32_t *sample_buffer, uint32_t sample_count); int WavpackDeleteTagItem (WavpackContext *wpc, const char *item);
int WavpackFlushSamples (WavpackContext *wpc); int WavpackWriteTag (WavpackContext *wpc);
void WavpackUpdateNumSamples (WavpackContext *wpc, void *first_block);
void *WavpackGetWrapperLocation (void *first_block);
WavpackContext *WavpackOpenFileOutput (WavpackBlockOutput blockout, void *wv_id, void *wvc_id);
// this function is not actually in wputils.c, but is generally useful int WavpackSetConfiguration (WavpackContext *wpc, WavpackConfig *config, uint32_t total_samples);
int WavpackAddWrapper (WavpackContext *wpc, void *data, uint32_t bcount);
void float_normalize (int32_t *values, int32_t num_values, int delta_exp); int WavpackStoreMD5Sum (WavpackContext *wpc, uchar data [16]);
int WavpackPackInit (WavpackContext *wpc);
#ifdef __cplusplus int WavpackPackSamples (WavpackContext *wpc, int32_t *sample_buffer, uint32_t sample_count);
} int WavpackFlushSamples (WavpackContext *wpc);
#endif void WavpackUpdateNumSamples (WavpackContext *wpc, void *first_block);
void *WavpackGetWrapperLocation (void *first_block, uint32_t *size);
#endif
// this function is not actually in wputils.c, but is generally useful
void float_normalize (int32_t *values, int32_t num_values, int delta_exp);
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@ -86,11 +86,7 @@ void ErrorProc(const FLAC__FileDecoder *decoder, FLAC__StreamDecoderErrorStatus
FLAC__file_decoder_process_until_end_of_metadata(decoder); FLAC__file_decoder_process_until_end_of_metadata(decoder);
#ifdef __BIG_ENDIAN__ isBigEndian = hostIsBigEndian();
isBigEndian = YES;
#else
isBigEndian = NO;
#endif
return YES; return YES;
} }

View File

@ -36,11 +36,7 @@
channels = outputFormat.nChannels; channels = outputFormat.nChannels;
bitsPerSample = 16; bitsPerSample = 16;
#ifdef __BIG_ENDIAN__ isBigEndian = hostIsBigEndian();
isBigEndian = YES;
#else
isBigEndian = NO;
#endif
long duration; long duration;
DecMPA_GetDuration(decoder, &duration); DecMPA_GetDuration(decoder, &duration);

View File

@ -66,11 +66,7 @@ BOOL CanSeekProc(void *data)
} }
// DBLog(@"Ok to go..."); // DBLog(@"Ok to go...");
#ifdef __BIG_ENDIAN__ isBigEndian = hostIsBigEndian();
isBigEndian = YES;
#else
isBigEndian = NO;
#endif
return YES; return YES;
} }

View File

@ -14,6 +14,14 @@
#import "DBLog.h" #import "DBLog.h"
#ifdef __cplusplus
extern "C" {
#endif
BOOL hostIsBigEndian();
#ifdef __cplusplus
}
#endif
@interface SoundFile : NSObject { @interface SoundFile : NSObject {
UInt16 bitsPerSample; UInt16 bitsPerSample;
UInt16 channels; UInt16 channels;

View File

@ -18,6 +18,17 @@
#import "WavPackFile.h" #import "WavPackFile.h"
#import "ShnFile.h" #import "ShnFile.h"
extern "C" {
BOOL hostIsBigEndian()
{
#ifdef __BIG_ENDIAN__
return YES;
#else
return NO;
#endif
}
};
@implementation SoundFile @implementation SoundFile
/*- (void)seek:(unsigned long)position /*- (void)seek:(unsigned long)position

View File

@ -21,8 +21,10 @@
return NO; return NO;
channels = WavpackGetNumChannels(wpc); channels = WavpackGetNumChannels(wpc);
// bitsPerSample = WavpackGetBitsPerSample(wpc); bitsPerSample = WavpackGetBitsPerSample(wpc);
bitsPerSample = 32; // bitsPerSample = 32;
NSLog(@"BYTES PER SAMPLE: %i", WavpackGetBitsPerSample(wpc));
NSLog(@"BYTES PER SAMPLE: %i", WavpackGetBytesPerSample(wpc));
frequency = WavpackGetSampleRate(wpc); frequency = WavpackGetSampleRate(wpc);
@ -32,7 +34,7 @@
bitRate = (int)(WavpackGetAverageBitrate(wpc, TRUE)/1000.0); bitRate = (int)(WavpackGetAverageBitrate(wpc, TRUE)/1000.0);
//isBigEndian = YES; isBigEndian = hostIsBigEndian();
return YES; return YES;
} }
@ -48,19 +50,18 @@
{ {
int numsamples; int numsamples;
int n; int n;
void *sampleBuf = malloc(size*2);
numsamples = size/4/channels; numsamples = size/(bitsPerSample/8)/channels;
// DBLog(@"NUM SAMPLES: %i %i", numsamples, size); // DBLog(@"NUM SAMPLES: %i %i", numsamples, size);
n = WavpackUnpackSamples(wpc, buf, numsamples); n = WavpackUnpackSamples(wpc, sampleBuf, numsamples);
n *= 4*channels;
int i; int i;
for (i = 0; i < n/2; i++) for (i = 0; i < n*channels; i++)
{ {
// ((UInt32 *)buf)[i] = CFSwapInt32LittleToHost(((UInt32 *)buf)[i]); ((UInt16 *)buf)[i] = ((UInt32 *)sampleBuf)[i];
((UInt16 *)buf)[i] = CFSwapInt16LittleToHost(((UInt16 *)buf)[i]);
} }
n *= (bitsPerSample/8)*channels;
return n; return n;
} }

View File

@ -37,11 +37,7 @@
break; break;
case SF_ENDIAN_CPU: case SF_ENDIAN_CPU:
#ifdef __BIG_ENDIAN__ isBigEndian = hostIsBigEndian();
isBigEndian = YES;
#else
isBigEndian = NO;
#endif
//DBLog(@"&CPU ENDIAN"); //DBLog(@"&CPU ENDIAN");
break; break;
case SF_ENDIAN_LITTLE: case SF_ENDIAN_LITTLE: