diff options
Diffstat (limited to 'apps/codecs/libwavpack/wavpack.h')
-rw-r--r-- | apps/codecs/libwavpack/wavpack.h | 317 |
1 files changed, 206 insertions, 111 deletions
diff --git a/apps/codecs/libwavpack/wavpack.h b/apps/codecs/libwavpack/wavpack.h index 3aee4718b1..12212bb0f8 100644 --- a/apps/codecs/libwavpack/wavpack.h +++ b/apps/codecs/libwavpack/wavpack.h | |||
@@ -14,11 +14,10 @@ | |||
14 | 14 | ||
15 | // This header file contains all the definitions required by WavPack. | 15 | // This header file contains all the definitions required by WavPack. |
16 | 16 | ||
17 | // not sure about them.. testing will bring more light into it.. | 17 | typedef unsigned char uchar; |
18 | typedef unsigned char uchar; | 18 | typedef unsigned short ushort; |
19 | typedef unsigned short ushort; | 19 | typedef unsigned long ulong; |
20 | typedef unsigned long ulong; | 20 | typedef unsigned int uint; |
21 | typedef unsigned int uint; | ||
22 | 21 | ||
23 | // This structure is used to access the individual fields of 32-bit ieee | 22 | // This structure is used to access the individual fields of 32-bit ieee |
24 | // floating point numbers. This will not be compatible with compilers that | 23 | // floating point numbers. This will not be compatible with compilers that |
@@ -54,70 +53,71 @@ typedef struct { | |||
54 | 53 | ||
55 | // or-values for "flags" | 54 | // or-values for "flags" |
56 | 55 | ||
57 | #define BYTES_STORED 3 // 1-4 bytes/sample | 56 | #define BYTES_STORED 3 // 1-4 bytes/sample |
58 | #define MONO_FLAG 4 // not stereo | 57 | #define MONO_FLAG 4 // not stereo |
59 | #define HYBRID_FLAG 8 // hybrid mode | 58 | #define HYBRID_FLAG 8 // hybrid mode |
60 | #define JOINT_STEREO 0x10 // joint stereo | 59 | #define JOINT_STEREO 0x10 // joint stereo |
61 | #define CROSS_DECORR 0x20 // no-delay cross decorrelation | 60 | #define CROSS_DECORR 0x20 // no-delay cross decorrelation |
62 | #define HYBRID_SHAPE 0x40 // noise shape (hybrid mode only) | 61 | #define HYBRID_SHAPE 0x40 // noise shape (hybrid mode only) |
63 | #define FLOAT_DATA 0x80 // ieee 32-bit floating point data | 62 | #define FLOAT_DATA 0x80 // ieee 32-bit floating point data |
64 | 63 | ||
65 | #define INT32_DATA 0x100 // special extended int handling | 64 | #define INT32_DATA 0x100 // special extended int handling |
66 | #define HYBRID_BITRATE 0x200 // bitrate noise (hybrid mode only) | 65 | #define HYBRID_BITRATE 0x200 // bitrate noise (hybrid mode only) |
67 | #define HYBRID_BALANCE 0x400 // balance noise (hybrid stereo mode only) | 66 | #define HYBRID_BALANCE 0x400 // balance noise (hybrid stereo mode only) |
68 | 67 | ||
69 | #define INITIAL_BLOCK 0x800 // initial block of multichannel segment | 68 | #define INITIAL_BLOCK 0x800 // initial block of multichannel segment |
70 | #define FINAL_BLOCK 0x1000 // final block of multichannel segment | 69 | #define FINAL_BLOCK 0x1000 // final block of multichannel segment |
71 | 70 | ||
72 | #define SHIFT_LSB 13 | 71 | #define SHIFT_LSB 13 |
73 | #define SHIFT_MASK (0x1fL << SHIFT_LSB) | 72 | #define SHIFT_MASK (0x1fL << SHIFT_LSB) |
74 | 73 | ||
75 | #define MAG_LSB 18 | 74 | #define MAG_LSB 18 |
76 | #define MAG_MASK (0x1fL << MAG_LSB) | 75 | #define MAG_MASK (0x1fL << MAG_LSB) |
77 | 76 | ||
78 | #define SRATE_LSB 23 | 77 | #define SRATE_LSB 23 |
79 | #define SRATE_MASK (0xfL << SRATE_LSB) | 78 | #define SRATE_MASK (0xfL << SRATE_LSB) |
80 | 79 | ||
81 | #define IGNORED_FLAGS 0x18000000 // reserved, but ignore if encountered | 80 | #define IGNORED_FLAGS 0x18000000 // reserved, but ignore if encountered |
82 | #define NEW_SHAPING 0x20000000 // use IIR filter for negative shaping | 81 | #define NEW_SHAPING 0x20000000 // use IIR filter for negative shaping |
83 | #define UNKNOWN_FLAGS 0xC0000000 // also reserved, but refuse decode if | 82 | #define UNKNOWN_FLAGS 0xC0000000 // also reserved, but refuse decode if |
84 | // encountered | 83 | // encountered |
85 | 84 | ||
86 | //////////////////////////// WavPack Metadata ///////////////////////////////// | 85 | //////////////////////////// WavPack Metadata ///////////////////////////////// |
87 | 86 | ||
88 | // This is an internal representation of metadata. | 87 | // This is an internal representation of metadata. |
89 | 88 | ||
90 | typedef struct { | 89 | typedef struct { |
90 | uchar temp_data [64]; | ||
91 | long byte_length; | 91 | long byte_length; |
92 | void *data; | 92 | void *data; |
93 | uchar id; | 93 | uchar id; |
94 | } WavpackMetadata; | 94 | } WavpackMetadata; |
95 | 95 | ||
96 | #define ID_OPTIONAL_DATA 0x20 | 96 | #define ID_OPTIONAL_DATA 0x20 |
97 | #define ID_ODD_SIZE 0x40 | 97 | #define ID_ODD_SIZE 0x40 |
98 | #define ID_LARGE 0x80 | 98 | #define ID_LARGE 0x80 |
99 | 99 | ||
100 | #define ID_DUMMY 0x0 | 100 | #define ID_DUMMY 0x0 |
101 | #define ID_ENCODER_INFO 0x1 | 101 | #define ID_ENCODER_INFO 0x1 |
102 | #define ID_DECORR_TERMS 0x2 | 102 | #define ID_DECORR_TERMS 0x2 |
103 | #define ID_DECORR_WEIGHTS 0x3 | 103 | #define ID_DECORR_WEIGHTS 0x3 |
104 | #define ID_DECORR_SAMPLES 0x4 | 104 | #define ID_DECORR_SAMPLES 0x4 |
105 | #define ID_ENTROPY_VARS 0x5 | 105 | #define ID_ENTROPY_VARS 0x5 |
106 | #define ID_HYBRID_PROFILE 0x6 | 106 | #define ID_HYBRID_PROFILE 0x6 |
107 | #define ID_SHAPING_WEIGHTS 0x7 | 107 | #define ID_SHAPING_WEIGHTS 0x7 |
108 | #define ID_FLOAT_INFO 0x8 | 108 | #define ID_FLOAT_INFO 0x8 |
109 | #define ID_INT32_INFO 0x9 | 109 | #define ID_INT32_INFO 0x9 |
110 | #define ID_WV_BITSTREAM 0xa | 110 | #define ID_WV_BITSTREAM 0xa |
111 | #define ID_WVC_BITSTREAM 0xb | 111 | #define ID_WVC_BITSTREAM 0xb |
112 | #define ID_WVX_BITSTREAM 0xc | 112 | #define ID_WVX_BITSTREAM 0xc |
113 | #define ID_CHANNEL_INFO 0xd | 113 | #define ID_CHANNEL_INFO 0xd |
114 | 114 | ||
115 | #define ID_RIFF_HEADER (ID_OPTIONAL_DATA | 0x1) | 115 | #define ID_RIFF_HEADER (ID_OPTIONAL_DATA | 0x1) |
116 | #define ID_RIFF_TRAILER (ID_OPTIONAL_DATA | 0x2) | 116 | #define ID_RIFF_TRAILER (ID_OPTIONAL_DATA | 0x2) |
117 | #define ID_REPLAY_GAIN (ID_OPTIONAL_DATA | 0x3) | 117 | #define ID_REPLAY_GAIN (ID_OPTIONAL_DATA | 0x3) |
118 | #define ID_CUESHEET (ID_OPTIONAL_DATA | 0x4) | 118 | #define ID_CUESHEET (ID_OPTIONAL_DATA | 0x4) |
119 | #define ID_CONFIG_BLOCK (ID_OPTIONAL_DATA | 0x5) | 119 | #define ID_CONFIG_BLOCK (ID_OPTIONAL_DATA | 0x5) |
120 | #define ID_MD5_CHECKSUM (ID_OPTIONAL_DATA | 0x6) | 120 | #define ID_MD5_CHECKSUM (ID_OPTIONAL_DATA | 0x6) |
121 | 121 | ||
122 | ///////////////////////// WavPack Configuration /////////////////////////////// | 122 | ///////////////////////// WavPack Configuration /////////////////////////////// |
123 | 123 | ||
@@ -127,39 +127,39 @@ typedef struct { | |||
127 | 127 | ||
128 | typedef struct { | 128 | typedef struct { |
129 | int bits_per_sample, bytes_per_sample; | 129 | int bits_per_sample, bytes_per_sample; |
130 | int qmode, flags, xmode, num_channels, float_norm_exp; | 130 | int flags, num_channels, float_norm_exp; |
131 | long block_samples, extra_flags, sample_rate, channel_mask; | 131 | ulong sample_rate, channel_mask; |
132 | } WavpackConfig; | 132 | } WavpackConfig; |
133 | 133 | ||
134 | #define CONFIG_BYTES_STORED 3 // 1-4 bytes/sample | 134 | #define CONFIG_BYTES_STORED 3 // 1-4 bytes/sample |
135 | #define CONFIG_MONO_FLAG 4 // not stereo | 135 | #define CONFIG_MONO_FLAG 4 // not stereo |
136 | #define CONFIG_HYBRID_FLAG 8 // hybrid mode | 136 | #define CONFIG_HYBRID_FLAG 8 // hybrid mode |
137 | #define CONFIG_JOINT_STEREO 0x10 // joint stereo | 137 | #define CONFIG_JOINT_STEREO 0x10 // joint stereo |
138 | #define CONFIG_CROSS_DECORR 0x20 // no-delay cross decorrelation | 138 | #define CONFIG_CROSS_DECORR 0x20 // no-delay cross decorrelation |
139 | #define CONFIG_HYBRID_SHAPE 0x40 // noise shape (hybrid mode only) | 139 | #define CONFIG_HYBRID_SHAPE 0x40 // noise shape (hybrid mode only) |
140 | #define CONFIG_FLOAT_DATA 0x80 // ieee 32-bit floating point data | 140 | #define CONFIG_FLOAT_DATA 0x80 // ieee 32-bit floating point data |
141 | 141 | ||
142 | #define CONFIG_ADOBE_MODE 0x100 // "adobe" mode for 32-bit floats | 142 | #define CONFIG_ADOBE_MODE 0x100 // "adobe" mode for 32-bit floats |
143 | #define CONFIG_FAST_FLAG 0x200 // fast mode | 143 | #define CONFIG_FAST_FLAG 0x200 // fast mode |
144 | #define CONFIG_VERY_FAST_FLAG 0x400 // double fast | 144 | #define CONFIG_VERY_FAST_FLAG 0x400 // double fast |
145 | #define CONFIG_HIGH_FLAG 0x800 // high quality mode | 145 | #define CONFIG_HIGH_FLAG 0x800 // high quality mode |
146 | #define CONFIG_VERY_HIGH_FLAG 0x1000 // double high (not used yet) | 146 | #define CONFIG_VERY_HIGH_FLAG 0x1000 // double high (not used yet) |
147 | #define CONFIG_BITRATE_KBPS 0x2000 // bitrate is kbps, not bits / sample | 147 | #define CONFIG_BITRATE_KBPS 0x2000 // bitrate is kbps, not bits / sample |
148 | #define CONFIG_AUTO_SHAPING 0x4000 // automatic noise shaping | 148 | #define CONFIG_AUTO_SHAPING 0x4000 // automatic noise shaping |
149 | #define CONFIG_SHAPE_OVERRIDE 0x8000 // shaping mode specified | 149 | #define CONFIG_SHAPE_OVERRIDE 0x8000 // shaping mode specified |
150 | #define CONFIG_JOINT_OVERRIDE 0x10000 // joint-stereo mode specified | 150 | #define CONFIG_JOINT_OVERRIDE 0x10000 // joint-stereo mode specified |
151 | #define CONFIG_COPY_TIME 0x20000 // copy file-time from source | 151 | #define CONFIG_COPY_TIME 0x20000 // copy file-time from source |
152 | #define CONFIG_CREATE_EXE 0x40000 // create executable (not yet) | 152 | #define CONFIG_CREATE_EXE 0x40000 // create executable (not yet) |
153 | #define CONFIG_CREATE_WVC 0x80000 // create correction file | 153 | #define CONFIG_CREATE_WVC 0x80000 // create correction file |
154 | #define CONFIG_OPTIMIZE_WVC 0x100000 // maximize bybrid compression | 154 | #define CONFIG_OPTIMIZE_WVC 0x100000 // maximize bybrid compression |
155 | #define CONFIG_QUALITY_MODE 0x200000 // psychoacoustic quality mode | 155 | #define CONFIG_QUALITY_MODE 0x200000 // psychoacoustic quality mode |
156 | #define CONFIG_RAW_FLAG 0x400000 // raw mode (not implemented yet) | 156 | #define CONFIG_RAW_FLAG 0x400000 // raw mode (not implemented yet) |
157 | #define CONFIG_CALC_NOISE 0x800000 // calc noise in hybrid mode | 157 | #define CONFIG_CALC_NOISE 0x800000 // calc noise in hybrid mode |
158 | #define CONFIG_LOSSY_MODE 0x1000000 // obsolete (for information) | 158 | #define CONFIG_LOSSY_MODE 0x1000000 // obsolete (for information) |
159 | #define CONFIG_EXTRA_MODE 0x2000000 // extra processing mode | 159 | #define CONFIG_EXTRA_MODE 0x2000000 // extra processing mode |
160 | #define CONFIG_SKIP_WVX 0x4000000 // no wvx stream w/ floats & big ints | 160 | #define CONFIG_SKIP_WVX 0x4000000 // no wvx stream w/ floats & big ints |
161 | #define CONFIG_MD5_CHECKSUM 0x8000000 // compute & store MD5 signature | 161 | #define CONFIG_MD5_CHECKSUM 0x8000000 // compute & store MD5 signature |
162 | #define CONFIG_QUIET_MODE 0x10000000 // don't report progress % | 162 | #define CONFIG_QUIET_MODE 0x10000000 // don't report progress % |
163 | 163 | ||
164 | //////////////////////////////// WavPack Stream /////////////////////////////// | 164 | //////////////////////////////// WavPack Stream /////////////////////////////// |
165 | 165 | ||
@@ -191,35 +191,38 @@ struct entropy_data { | |||
191 | ulong median [3], slow_level, error_limit; | 191 | ulong median [3], slow_level, error_limit; |
192 | }; | 192 | }; |
193 | 193 | ||
194 | struct words_data { | ||
195 | ulong bitrate_delta [2], bitrate_acc [2]; | ||
196 | ulong pend_data, holding_one, zeros_acc; | ||
197 | int holding_zero, pend_count; | ||
198 | struct entropy_data c [2]; | ||
199 | }; | ||
200 | |||
194 | typedef struct { | 201 | typedef struct { |
195 | WavpackHeader wphdr; | 202 | WavpackHeader wphdr; |
196 | Bitstream wvbits; | 203 | Bitstream wvbits; |
197 | 204 | ||
198 | struct { | 205 | struct words_data w; |
199 | ulong bitrate_delta [2], bitrate_acc [2]; | ||
200 | ulong pend_data, holding_one, zeros_acc; | ||
201 | int holding_zero, pend_count; | ||
202 | struct entropy_data c [2]; | ||
203 | } w; | ||
204 | 206 | ||
205 | int num_terms, mute_error; | 207 | int num_terms, mute_error; |
206 | ulong sample_index, crc; | 208 | ulong sample_index, crc; |
207 | 209 | ||
208 | uchar int32_sent_bits, int32_zeros, int32_ones, int32_dups; | 210 | uchar int32_sent_bits, int32_zeros, int32_ones, int32_dups; |
209 | uchar float_flags, float_shift, float_max_exp, float_norm_exp; | 211 | uchar float_flags, float_shift, float_max_exp, float_norm_exp; |
210 | 212 | uchar *blockbuff, *blockend; | |
213 | |||
211 | struct decorr_pass decorr_passes [MAX_NTERMS]; | 214 | struct decorr_pass decorr_passes [MAX_NTERMS]; |
212 | 215 | ||
213 | } WavpackStream; | 216 | } WavpackStream; |
214 | 217 | ||
215 | // flags for float_flags: | 218 | // flags for float_flags: |
216 | 219 | ||
217 | #define FLOAT_SHIFT_ONES 1 // bits left-shifted into float = '1' | 220 | #define FLOAT_SHIFT_ONES 1 // bits left-shifted into float = '1' |
218 | #define FLOAT_SHIFT_SAME 2 // bits left-shifted into float are the same | 221 | #define FLOAT_SHIFT_SAME 2 // bits left-shifted into float are the same |
219 | #define FLOAT_SHIFT_SENT 4 // bits shifted into float are sent literally | 222 | #define FLOAT_SHIFT_SENT 4 // bits shifted into float are sent literally |
220 | #define FLOAT_ZEROS_SENT 8 // "zeros" are not all real zeros | 223 | #define FLOAT_ZEROS_SENT 8 // "zeros" are not all real zeros |
221 | #define FLOAT_NEG_ZEROS 0x10 // contains negative zeros | 224 | #define FLOAT_NEG_ZEROS 0x10 // contains negative zeros |
222 | #define FLOAT_EXCEPTIONS 0x20 // contains exceptions (inf, nan, etc.) | 225 | #define FLOAT_EXCEPTIONS 0x20 // contains exceptions (inf, nan, etc.) |
223 | 226 | ||
224 | /////////////////////////////// WavPack Context /////////////////////////////// | 227 | /////////////////////////////// WavPack Context /////////////////////////////// |
225 | 228 | ||
@@ -231,6 +234,13 @@ typedef struct { | |||
231 | WavpackStream stream; | 234 | WavpackStream stream; |
232 | WavpackConfig config; | 235 | WavpackConfig config; |
233 | 236 | ||
237 | WavpackMetadata *metadata; | ||
238 | ulong metabytes; | ||
239 | int metacount; | ||
240 | |||
241 | uchar *wrapper_data; | ||
242 | int wrapper_bytes; | ||
243 | |||
234 | uchar read_buffer [1024]; | 244 | uchar read_buffer [1024]; |
235 | char error_message [80]; | 245 | char error_message [80]; |
236 | 246 | ||
@@ -247,32 +257,96 @@ typedef struct { | |||
247 | // bits.c | 257 | // bits.c |
248 | 258 | ||
249 | void bs_open_read (Bitstream *bs, uchar *buffer_start, uchar *buffer_end, read_stream file, ulong file_bytes); | 259 | void bs_open_read (Bitstream *bs, uchar *buffer_start, uchar *buffer_end, read_stream file, ulong file_bytes); |
260 | void bs_open_write (Bitstream *bs, uchar *buffer_start, uchar *buffer_end); | ||
261 | ulong bs_close_write (Bitstream *bs); | ||
250 | 262 | ||
251 | #define bs_is_open(bs) ((bs)->ptr != NULL) | 263 | #define bs_is_open(bs) ((bs)->ptr != NULL) |
252 | 264 | ||
253 | #define getbit(bs) ( \ | 265 | #define getbit(bs) ( \ |
254 | (((bs)->bc) ? \ | 266 | (((bs)->bc) ? \ |
255 | ((bs)->bc--, (bs)->sr & 1) : \ | 267 | ((bs)->bc--, (bs)->sr & 1) : \ |
256 | (((++((bs)->ptr) != (bs)->end) ? (void) 0 : (bs)->wrap (bs)), (bs)->bc = 7, ((bs)->sr = *((bs)->ptr)) & 1) \ | 268 | (((++((bs)->ptr) != (bs)->end) ? (void) 0 : (bs)->wrap (bs)), (bs)->bc = 7, ((bs)->sr = *((bs)->ptr)) & 1) \ |
257 | ) ? \ | 269 | ) ? \ |
258 | ((bs)->sr >>= 1, 1) : \ | 270 | ((bs)->sr >>= 1, 1) : \ |
259 | ((bs)->sr >>= 1, 0) \ | 271 | ((bs)->sr >>= 1, 0) \ |
260 | ) | 272 | ) |
261 | 273 | ||
262 | #define getbits(value, nbits, bs) { \ | 274 | #define getbits(value, nbits, bs) { \ |
263 | while ((nbits) > (bs)->bc) { \ | 275 | while ((nbits) > (bs)->bc) { \ |
264 | if (++((bs)->ptr) == (bs)->end) (bs)->wrap (bs); \ | 276 | if (++((bs)->ptr) == (bs)->end) (bs)->wrap (bs); \ |
265 | (bs)->sr |= (long)*((bs)->ptr) << (bs)->bc; \ | 277 | (bs)->sr |= (long)*((bs)->ptr) << (bs)->bc; \ |
266 | (bs)->bc += 8; \ | 278 | (bs)->bc += 8; \ |
267 | } \ | 279 | } \ |
268 | *(value) = (bs)->sr; \ | 280 | *(value) = (bs)->sr; \ |
269 | (bs)->sr >>= (nbits); \ | 281 | (bs)->sr >>= (nbits); \ |
270 | (bs)->bc -= (nbits); \ | 282 | (bs)->bc -= (nbits); \ |
271 | } | 283 | } |
272 | 284 | ||
285 | #define putbit(bit, bs) { if (bit) (bs)->sr |= (1 << (bs)->bc); \ | ||
286 | if (++((bs)->bc) == 8) { \ | ||
287 | *((bs)->ptr) = (bs)->sr; \ | ||
288 | (bs)->sr = (bs)->bc = 0; \ | ||
289 | if (++((bs)->ptr) == (bs)->end) (bs)->wrap (bs); \ | ||
290 | }} | ||
291 | |||
292 | #define putbit_0(bs) { \ | ||
293 | if (++((bs)->bc) == 8) { \ | ||
294 | *((bs)->ptr) = (bs)->sr; \ | ||
295 | (bs)->sr = (bs)->bc = 0; \ | ||
296 | if (++((bs)->ptr) == (bs)->end) (bs)->wrap (bs); \ | ||
297 | }} | ||
298 | |||
299 | #define putbit_1(bs) { (bs)->sr |= (1 << (bs)->bc); \ | ||
300 | if (++((bs)->bc) == 8) { \ | ||
301 | *((bs)->ptr) = (bs)->sr; \ | ||
302 | (bs)->sr = (bs)->bc = 0; \ | ||
303 | if (++((bs)->ptr) == (bs)->end) (bs)->wrap (bs); \ | ||
304 | }} | ||
305 | |||
306 | #define putbits(value, nbits, bs) { \ | ||
307 | (bs)->sr |= (long)(value) << (bs)->bc; \ | ||
308 | if (((bs)->bc += (nbits)) >= 8) \ | ||
309 | do { \ | ||
310 | *((bs)->ptr) = (bs)->sr; \ | ||
311 | (bs)->sr >>= 8; \ | ||
312 | if (++((bs)->ptr) == (bs)->end) (bs)->wrap (bs); \ | ||
313 | } while (((bs)->bc -= 8) >= 8); \ | ||
314 | } | ||
315 | |||
273 | void little_endian_to_native (void *data, char *format); | 316 | void little_endian_to_native (void *data, char *format); |
274 | void native_to_little_endian (void *data, char *format); | 317 | void native_to_little_endian (void *data, char *format); |
275 | 318 | ||
319 | // these macros implement the weight application and update operations | ||
320 | // that are at the heart of the decorrelation loops | ||
321 | |||
322 | #if 0 // PERFCOND | ||
323 | #define apply_weight_i(weight, sample) ((weight * sample + 512) >> 10) | ||
324 | #else | ||
325 | #define apply_weight_i(weight, sample) ((((weight * sample) >> 8) + 2) >> 2) | ||
326 | #endif | ||
327 | |||
328 | #define apply_weight_f(weight, sample) (((((sample & 0xffff) * weight) >> 9) + \ | ||
329 | (((sample & ~0xffff) >> 9) * weight) + 1) >> 1) | ||
330 | |||
331 | #if 1 // PERFCOND | ||
332 | #define apply_weight(weight, sample) (sample != (short) sample ? \ | ||
333 | apply_weight_f (weight, sample) : apply_weight_i (weight, sample)) | ||
334 | #else | ||
335 | #define apply_weight(weight, sample) ((int32_t)((weight * (int64_t) sample + 512) >> 10)) | ||
336 | #endif | ||
337 | |||
338 | #if 0 // PERFCOND | ||
339 | #define update_weight(weight, delta, source, result) \ | ||
340 | if (source && result) weight -= ((((source ^ result) >> 30) & 2) - 1) * delta; | ||
341 | #else | ||
342 | #define update_weight(weight, delta, source, result) \ | ||
343 | if (source && result) (source ^ result) < 0 ? (weight -= delta) : (weight += delta); | ||
344 | #endif | ||
345 | |||
346 | #define update_weight_clip(weight, delta, source, result) \ | ||
347 | if (source && result && ((source ^ result) < 0 ? (weight -= delta) < -1024 : (weight += delta) > 1024)) \ | ||
348 | weight = weight < 0 ? -1024 : 1024; | ||
349 | |||
276 | // unpack.c | 350 | // unpack.c |
277 | 351 | ||
278 | int unpack_init (WavpackContext *wpc); | 352 | int unpack_init (WavpackContext *wpc); |
@@ -287,17 +361,31 @@ int read_config_info (WavpackContext *wpc, WavpackMetadata *wpmd); | |||
287 | long unpack_samples (WavpackContext *wpc, long *buffer, ulong sample_count); | 361 | long unpack_samples (WavpackContext *wpc, long *buffer, ulong sample_count); |
288 | int check_crc_error (WavpackContext *wpc); | 362 | int check_crc_error (WavpackContext *wpc); |
289 | 363 | ||
364 | // pack.c | ||
365 | |||
366 | void pack_init (WavpackContext *wpc); | ||
367 | int pack_block (WavpackContext *wpc, long *buffer); | ||
368 | |||
290 | // metadata.c stuff | 369 | // metadata.c stuff |
291 | 370 | ||
292 | int read_metadata_buff (WavpackContext *wpc, WavpackMetadata *wpmd); | 371 | int read_metadata_buff (WavpackContext *wpc, WavpackMetadata *wpmd); |
293 | int process_metadata (WavpackContext *wpc, WavpackMetadata *wpmd); | 372 | int process_metadata (WavpackContext *wpc, WavpackMetadata *wpmd); |
373 | int copy_metadata (WavpackMetadata *wpmd, uchar *buffer_start, uchar *buffer_end); | ||
374 | void free_metadata (WavpackMetadata *wpmd); | ||
294 | 375 | ||
295 | // words.c stuff | 376 | // words.c stuff |
296 | 377 | ||
378 | void init_words (WavpackStream *wps); | ||
297 | int read_entropy_vars (WavpackStream *wps, WavpackMetadata *wpmd); | 379 | int read_entropy_vars (WavpackStream *wps, WavpackMetadata *wpmd); |
380 | void write_entropy_vars (WavpackStream *wps, WavpackMetadata *wpmd); | ||
298 | int read_hybrid_profile (WavpackStream *wps, WavpackMetadata *wpmd); | 381 | int read_hybrid_profile (WavpackStream *wps, WavpackMetadata *wpmd); |
299 | long get_words (WavpackStream *wps, int nchans, int nsamples, long *buffer); | 382 | long get_words (long *buffer, int nsamples, ulong flags, |
383 | struct words_data *w, Bitstream *bs); | ||
384 | void send_word_lossless (WavpackStream *wps, long value, int chan); | ||
385 | void flush_word (WavpackStream *wps); | ||
386 | int log2s (long value); | ||
300 | long exp2s (int log); | 387 | long exp2s (int log); |
388 | char store_weight (int weight); | ||
301 | int restore_weight (char weight); | 389 | int restore_weight (char weight); |
302 | 390 | ||
303 | #define WORD_EOF (1L << 31) | 391 | #define WORD_EOF (1L << 31) |
@@ -314,13 +402,13 @@ WavpackContext *WavpackOpenFileInput (read_stream infile, char *error); | |||
314 | 402 | ||
315 | int WavpackGetMode (WavpackContext *wpc); | 403 | int WavpackGetMode (WavpackContext *wpc); |
316 | 404 | ||
317 | #define MODE_WVC 0x1 | 405 | #define MODE_WVC 0x1 |
318 | #define MODE_LOSSLESS 0x2 | 406 | #define MODE_LOSSLESS 0x2 |
319 | #define MODE_HYBRID 0x4 | 407 | #define MODE_HYBRID 0x4 |
320 | #define MODE_FLOAT 0x8 | 408 | #define MODE_FLOAT 0x8 |
321 | #define MODE_VALID_TAG 0x10 | 409 | #define MODE_VALID_TAG 0x10 |
322 | #define MODE_HIGH 0x20 | 410 | #define MODE_HIGH 0x20 |
323 | #define MODE_FAST 0x40 | 411 | #define MODE_FAST 0x40 |
324 | 412 | ||
325 | ulong WavpackUnpackSamples (WavpackContext *wpc, long *buffer, ulong samples); | 413 | ulong WavpackUnpackSamples (WavpackContext *wpc, long *buffer, ulong samples); |
326 | ulong WavpackGetNumSamples (WavpackContext *wpc); | 414 | ulong WavpackGetNumSamples (WavpackContext *wpc); |
@@ -332,3 +420,10 @@ int WavpackGetBitsPerSample (WavpackContext *wpc); | |||
332 | int WavpackGetBytesPerSample (WavpackContext *wpc); | 420 | int WavpackGetBytesPerSample (WavpackContext *wpc); |
333 | int WavpackGetNumChannels (WavpackContext *wpc); | 421 | int WavpackGetNumChannels (WavpackContext *wpc); |
334 | int WavpackGetReducedChannels (WavpackContext *wpc); | 422 | int WavpackGetReducedChannels (WavpackContext *wpc); |
423 | WavpackContext *WavpackOpenFileOutput (void); | ||
424 | void WavpackSetOutputBuffer (WavpackContext *wpc, uchar *begin, uchar *end); | ||
425 | int WavpackSetConfiguration (WavpackContext *wpc, WavpackConfig *config, ulong total_samples); | ||
426 | void WavpackAddWrapper (WavpackContext *wpc, void *data, ulong bcount); | ||
427 | ulong WavpackPackSamples (WavpackContext *wpc, long *sample_buffer, ulong sample_count); | ||
428 | |||
429 | |||