react-native-tiny-wavpack-decoder 0.1.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/lib/module/tiny-wavpack/lib/bits.c +140 -140
- package/lib/module/tiny-wavpack/lib/float.c +50 -50
- package/lib/module/tiny-wavpack/lib/license.txt +25 -25
- package/lib/module/tiny-wavpack/lib/metadata.c +105 -105
- package/lib/module/tiny-wavpack/lib/readme.txt +68 -68
- package/lib/module/tiny-wavpack/lib/unpack.c +785 -785
- package/lib/module/tiny-wavpack/lib/wavpack.h +384 -384
- package/lib/module/tiny-wavpack/lib/words.c +560 -560
- package/lib/module/tiny-wavpack/lib/wputils.c +351 -351
- package/package.json +14 -2
- package/src/tiny-wavpack/lib/bits.c +140 -140
- package/src/tiny-wavpack/lib/float.c +50 -50
- package/src/tiny-wavpack/lib/license.txt +25 -25
- package/src/tiny-wavpack/lib/metadata.c +105 -105
- package/src/tiny-wavpack/lib/readme.txt +68 -68
- package/src/tiny-wavpack/lib/unpack.c +785 -785
- package/src/tiny-wavpack/lib/wavpack.h +384 -384
- package/src/tiny-wavpack/lib/words.c +560 -560
- package/src/tiny-wavpack/lib/wputils.c +351 -351
- package/lib/module/tiny-wavpack/common/test.c +0 -45
- package/lib/module/tiny-wavpack/common/wv2wav +0 -0
- package/src/tiny-wavpack/common/test.c +0 -45
- package/src/tiny-wavpack/common/wv2wav +0 -0
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
A lightweight React Native Turbo Module for decoding WavPack audio files to WAV format on iOS and Android. Built with the New Architecture for optimal performance, this module supports progress updates during decoding and is designed for seamless integration into React Native apps.
|
|
4
4
|
|
|
5
|
+
[](https://badge.fury.io/js/react-native-tiny-wavpack-decoder) [](https://github.com/JairajJangle/react-native-tiny-wavpack-decoder/blob/main/LICENSE) [](https://github.com/JairajJangle/react-native-tiny-wavpack-decoder/actions/workflows/ci.yml)   [](https://github.com/JairajJangle/react-native-tiny-wavpack-decoder/issues?q=is%3Aopen+is%3Aissue)  [](https://snyk.io/test/github/jairajjangle/react-native-tiny-wavpack-decoder) 
|
|
6
|
+
|
|
5
7
|
## Features
|
|
6
8
|
- Decode WavPack (.wv) files to WAV format.
|
|
7
9
|
- Cross-platform support for iOS (13.0+) and Android (API 21+).
|
|
@@ -1,140 +1,140 @@
|
|
|
1
|
-
////////////////////////////////////////////////////////////////////////////
|
|
2
|
-
// **** WAVPACK **** //
|
|
3
|
-
// Hybrid Lossless Wavefile Compressor //
|
|
4
|
-
// Copyright (c) 1998 - 2006 Conifer Software. //
|
|
5
|
-
// All Rights Reserved. //
|
|
6
|
-
// Distributed under the BSD Software License (see license.txt) //
|
|
7
|
-
////////////////////////////////////////////////////////////////////////////
|
|
8
|
-
|
|
9
|
-
// bits.c
|
|
10
|
-
|
|
11
|
-
// This module provides utilities to support the BitStream structure which is
|
|
12
|
-
// used to read and write all WavPack audio data streams. It also contains a
|
|
13
|
-
// wrapper for the stream I/O functions and a set of functions dealing with
|
|
14
|
-
// endian-ness, both for enhancing portability. Finally, a debug wrapper for
|
|
15
|
-
// the malloc() system is provided.
|
|
16
|
-
|
|
17
|
-
#include "wavpack.h"
|
|
18
|
-
|
|
19
|
-
#include <string.h>
|
|
20
|
-
#include <ctype.h>
|
|
21
|
-
|
|
22
|
-
////////////////////////// Bitstream functions ////////////////////////////////
|
|
23
|
-
|
|
24
|
-
// Open the specified BitStream and associate with the specified buffer.
|
|
25
|
-
|
|
26
|
-
static void bs_read (Bitstream *bs);
|
|
27
|
-
|
|
28
|
-
void bs_open_read (Bitstream *bs, uchar *buffer_start, uchar *buffer_end, read_stream file, uint32_t file_bytes)
|
|
29
|
-
{
|
|
30
|
-
CLEAR (*bs);
|
|
31
|
-
bs->buf = buffer_start;
|
|
32
|
-
bs->end = buffer_end;
|
|
33
|
-
|
|
34
|
-
if (file) {
|
|
35
|
-
bs->ptr = bs->end - 1;
|
|
36
|
-
bs->file_bytes = file_bytes;
|
|
37
|
-
bs->file = file;
|
|
38
|
-
}
|
|
39
|
-
else
|
|
40
|
-
bs->ptr = bs->buf - 1;
|
|
41
|
-
|
|
42
|
-
bs->wrap = bs_read;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// This function is only called from the getbit() and getbits() macros when
|
|
46
|
-
// the BitStream has been exhausted and more data is required. Sinve these
|
|
47
|
-
// bistreams no longer access files, this function simple sets an error and
|
|
48
|
-
// resets the buffer.
|
|
49
|
-
|
|
50
|
-
static void bs_read (Bitstream *bs)
|
|
51
|
-
{
|
|
52
|
-
if (bs->file && bs->file_bytes) {
|
|
53
|
-
uint32_t bytes_read, bytes_to_read = bs->end - bs->buf;
|
|
54
|
-
|
|
55
|
-
if (bytes_to_read > bs->file_bytes)
|
|
56
|
-
bytes_to_read = bs->file_bytes;
|
|
57
|
-
|
|
58
|
-
bytes_read = bs->file (bs->buf, bytes_to_read);
|
|
59
|
-
|
|
60
|
-
if (bytes_read) {
|
|
61
|
-
bs->end = bs->buf + bytes_read;
|
|
62
|
-
bs->file_bytes -= bytes_read;
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
memset (bs->buf, -1, bs->end - bs->buf);
|
|
66
|
-
bs->error = 1;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
else
|
|
70
|
-
bs->error = 1;
|
|
71
|
-
|
|
72
|
-
if (bs->error)
|
|
73
|
-
memset (bs->buf, -1, bs->end - bs->buf);
|
|
74
|
-
|
|
75
|
-
bs->ptr = bs->buf;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/////////////////////// Endian Correction Routines ////////////////////////////
|
|
79
|
-
|
|
80
|
-
void little_endian_to_native (void *data, char *format)
|
|
81
|
-
{
|
|
82
|
-
uchar *cp = (uchar *) data;
|
|
83
|
-
int32_t temp;
|
|
84
|
-
|
|
85
|
-
while (*format) {
|
|
86
|
-
switch (*format) {
|
|
87
|
-
case 'L':
|
|
88
|
-
temp = cp [0] + ((int32_t) cp [1] << 8) + ((int32_t) cp [2] << 16) + ((int32_t) cp [3] << 24);
|
|
89
|
-
* (int32_t *) cp = temp;
|
|
90
|
-
cp += 4;
|
|
91
|
-
break;
|
|
92
|
-
|
|
93
|
-
case 'S':
|
|
94
|
-
temp = cp [0] + (cp [1] << 8);
|
|
95
|
-
* (short *) cp = (short) temp;
|
|
96
|
-
cp += 2;
|
|
97
|
-
break;
|
|
98
|
-
|
|
99
|
-
default:
|
|
100
|
-
if (isdigit (*format))
|
|
101
|
-
cp += *format - '0';
|
|
102
|
-
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
format++;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
void native_to_little_endian (void *data, char *format)
|
|
111
|
-
{
|
|
112
|
-
uchar *cp = (uchar *) data;
|
|
113
|
-
int32_t temp;
|
|
114
|
-
|
|
115
|
-
while (*format) {
|
|
116
|
-
switch (*format) {
|
|
117
|
-
case 'L':
|
|
118
|
-
temp = * (int32_t *) cp;
|
|
119
|
-
*cp++ = (uchar) temp;
|
|
120
|
-
*cp++ = (uchar) (temp >> 8);
|
|
121
|
-
*cp++ = (uchar) (temp >> 16);
|
|
122
|
-
*cp++ = (uchar) (temp >> 24);
|
|
123
|
-
break;
|
|
124
|
-
|
|
125
|
-
case 'S':
|
|
126
|
-
temp = * (short *) cp;
|
|
127
|
-
*cp++ = (uchar) temp;
|
|
128
|
-
*cp++ = (uchar) (temp >> 8);
|
|
129
|
-
break;
|
|
130
|
-
|
|
131
|
-
default:
|
|
132
|
-
if (isdigit (*format))
|
|
133
|
-
cp += *format - '0';
|
|
134
|
-
|
|
135
|
-
break;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
format++;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
1
|
+
////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// **** WAVPACK **** //
|
|
3
|
+
// Hybrid Lossless Wavefile Compressor //
|
|
4
|
+
// Copyright (c) 1998 - 2006 Conifer Software. //
|
|
5
|
+
// All Rights Reserved. //
|
|
6
|
+
// Distributed under the BSD Software License (see license.txt) //
|
|
7
|
+
////////////////////////////////////////////////////////////////////////////
|
|
8
|
+
|
|
9
|
+
// bits.c
|
|
10
|
+
|
|
11
|
+
// This module provides utilities to support the BitStream structure which is
|
|
12
|
+
// used to read and write all WavPack audio data streams. It also contains a
|
|
13
|
+
// wrapper for the stream I/O functions and a set of functions dealing with
|
|
14
|
+
// endian-ness, both for enhancing portability. Finally, a debug wrapper for
|
|
15
|
+
// the malloc() system is provided.
|
|
16
|
+
|
|
17
|
+
#include "wavpack.h"
|
|
18
|
+
|
|
19
|
+
#include <string.h>
|
|
20
|
+
#include <ctype.h>
|
|
21
|
+
|
|
22
|
+
////////////////////////// Bitstream functions ////////////////////////////////
|
|
23
|
+
|
|
24
|
+
// Open the specified BitStream and associate with the specified buffer.
|
|
25
|
+
|
|
26
|
+
static void bs_read (Bitstream *bs);
|
|
27
|
+
|
|
28
|
+
void bs_open_read (Bitstream *bs, uchar *buffer_start, uchar *buffer_end, read_stream file, uint32_t file_bytes)
|
|
29
|
+
{
|
|
30
|
+
CLEAR (*bs);
|
|
31
|
+
bs->buf = buffer_start;
|
|
32
|
+
bs->end = buffer_end;
|
|
33
|
+
|
|
34
|
+
if (file) {
|
|
35
|
+
bs->ptr = bs->end - 1;
|
|
36
|
+
bs->file_bytes = file_bytes;
|
|
37
|
+
bs->file = file;
|
|
38
|
+
}
|
|
39
|
+
else
|
|
40
|
+
bs->ptr = bs->buf - 1;
|
|
41
|
+
|
|
42
|
+
bs->wrap = bs_read;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// This function is only called from the getbit() and getbits() macros when
|
|
46
|
+
// the BitStream has been exhausted and more data is required. Sinve these
|
|
47
|
+
// bistreams no longer access files, this function simple sets an error and
|
|
48
|
+
// resets the buffer.
|
|
49
|
+
|
|
50
|
+
static void bs_read (Bitstream *bs)
|
|
51
|
+
{
|
|
52
|
+
if (bs->file && bs->file_bytes) {
|
|
53
|
+
uint32_t bytes_read, bytes_to_read = bs->end - bs->buf;
|
|
54
|
+
|
|
55
|
+
if (bytes_to_read > bs->file_bytes)
|
|
56
|
+
bytes_to_read = bs->file_bytes;
|
|
57
|
+
|
|
58
|
+
bytes_read = bs->file (bs->buf, bytes_to_read);
|
|
59
|
+
|
|
60
|
+
if (bytes_read) {
|
|
61
|
+
bs->end = bs->buf + bytes_read;
|
|
62
|
+
bs->file_bytes -= bytes_read;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
memset (bs->buf, -1, bs->end - bs->buf);
|
|
66
|
+
bs->error = 1;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else
|
|
70
|
+
bs->error = 1;
|
|
71
|
+
|
|
72
|
+
if (bs->error)
|
|
73
|
+
memset (bs->buf, -1, bs->end - bs->buf);
|
|
74
|
+
|
|
75
|
+
bs->ptr = bs->buf;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/////////////////////// Endian Correction Routines ////////////////////////////
|
|
79
|
+
|
|
80
|
+
void little_endian_to_native (void *data, char *format)
|
|
81
|
+
{
|
|
82
|
+
uchar *cp = (uchar *) data;
|
|
83
|
+
int32_t temp;
|
|
84
|
+
|
|
85
|
+
while (*format) {
|
|
86
|
+
switch (*format) {
|
|
87
|
+
case 'L':
|
|
88
|
+
temp = cp [0] + ((int32_t) cp [1] << 8) + ((int32_t) cp [2] << 16) + ((int32_t) cp [3] << 24);
|
|
89
|
+
* (int32_t *) cp = temp;
|
|
90
|
+
cp += 4;
|
|
91
|
+
break;
|
|
92
|
+
|
|
93
|
+
case 'S':
|
|
94
|
+
temp = cp [0] + (cp [1] << 8);
|
|
95
|
+
* (short *) cp = (short) temp;
|
|
96
|
+
cp += 2;
|
|
97
|
+
break;
|
|
98
|
+
|
|
99
|
+
default:
|
|
100
|
+
if (isdigit (*format))
|
|
101
|
+
cp += *format - '0';
|
|
102
|
+
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
format++;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
void native_to_little_endian (void *data, char *format)
|
|
111
|
+
{
|
|
112
|
+
uchar *cp = (uchar *) data;
|
|
113
|
+
int32_t temp;
|
|
114
|
+
|
|
115
|
+
while (*format) {
|
|
116
|
+
switch (*format) {
|
|
117
|
+
case 'L':
|
|
118
|
+
temp = * (int32_t *) cp;
|
|
119
|
+
*cp++ = (uchar) temp;
|
|
120
|
+
*cp++ = (uchar) (temp >> 8);
|
|
121
|
+
*cp++ = (uchar) (temp >> 16);
|
|
122
|
+
*cp++ = (uchar) (temp >> 24);
|
|
123
|
+
break;
|
|
124
|
+
|
|
125
|
+
case 'S':
|
|
126
|
+
temp = * (short *) cp;
|
|
127
|
+
*cp++ = (uchar) temp;
|
|
128
|
+
*cp++ = (uchar) (temp >> 8);
|
|
129
|
+
break;
|
|
130
|
+
|
|
131
|
+
default:
|
|
132
|
+
if (isdigit (*format))
|
|
133
|
+
cp += *format - '0';
|
|
134
|
+
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
format++;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
////////////////////////////////////////////////////////////////////////////
|
|
2
|
-
// **** WAVPACK **** //
|
|
3
|
-
// Hybrid Lossless Wavefile Compressor //
|
|
4
|
-
// Copyright (c) 1998 - 2006 Conifer Software. //
|
|
5
|
-
// All Rights Reserved. //
|
|
6
|
-
// Distributed under the BSD Software License (see license.txt) //
|
|
7
|
-
////////////////////////////////////////////////////////////////////////////
|
|
8
|
-
|
|
9
|
-
// float.c
|
|
10
|
-
|
|
11
|
-
#include "wavpack.h"
|
|
12
|
-
|
|
13
|
-
int read_float_info (WavpackStream *wps, WavpackMetadata *wpmd)
|
|
14
|
-
{
|
|
15
|
-
int bytecnt = wpmd->byte_length;
|
|
16
|
-
char *byteptr = wpmd->data;
|
|
17
|
-
|
|
18
|
-
if (bytecnt != 4)
|
|
19
|
-
return FALSE;
|
|
20
|
-
|
|
21
|
-
wps->float_flags = *byteptr++;
|
|
22
|
-
wps->float_shift = *byteptr++;
|
|
23
|
-
wps->float_max_exp = *byteptr++;
|
|
24
|
-
wps->float_norm_exp = *byteptr;
|
|
25
|
-
return TRUE;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
void float_values (WavpackStream *wps, int32_t *values, int32_t num_values)
|
|
29
|
-
{
|
|
30
|
-
int shift = wps->float_max_exp - wps->float_norm_exp + wps->float_shift;
|
|
31
|
-
|
|
32
|
-
if (shift > 32)
|
|
33
|
-
shift = 32;
|
|
34
|
-
else if (shift < -32)
|
|
35
|
-
shift = -32;
|
|
36
|
-
|
|
37
|
-
while (num_values--) {
|
|
38
|
-
if (shift > 0)
|
|
39
|
-
*values <<= shift;
|
|
40
|
-
else if (shift < 0)
|
|
41
|
-
*values >>= -shift;
|
|
42
|
-
|
|
43
|
-
if (*values > 8388607L)
|
|
44
|
-
*values = 8388607L;
|
|
45
|
-
else if (*values < -8388608L)
|
|
46
|
-
*values = -8388608L;
|
|
47
|
-
|
|
48
|
-
values++;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
1
|
+
////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// **** WAVPACK **** //
|
|
3
|
+
// Hybrid Lossless Wavefile Compressor //
|
|
4
|
+
// Copyright (c) 1998 - 2006 Conifer Software. //
|
|
5
|
+
// All Rights Reserved. //
|
|
6
|
+
// Distributed under the BSD Software License (see license.txt) //
|
|
7
|
+
////////////////////////////////////////////////////////////////////////////
|
|
8
|
+
|
|
9
|
+
// float.c
|
|
10
|
+
|
|
11
|
+
#include "wavpack.h"
|
|
12
|
+
|
|
13
|
+
int read_float_info (WavpackStream *wps, WavpackMetadata *wpmd)
|
|
14
|
+
{
|
|
15
|
+
int bytecnt = wpmd->byte_length;
|
|
16
|
+
char *byteptr = wpmd->data;
|
|
17
|
+
|
|
18
|
+
if (bytecnt != 4)
|
|
19
|
+
return FALSE;
|
|
20
|
+
|
|
21
|
+
wps->float_flags = *byteptr++;
|
|
22
|
+
wps->float_shift = *byteptr++;
|
|
23
|
+
wps->float_max_exp = *byteptr++;
|
|
24
|
+
wps->float_norm_exp = *byteptr;
|
|
25
|
+
return TRUE;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
void float_values (WavpackStream *wps, int32_t *values, int32_t num_values)
|
|
29
|
+
{
|
|
30
|
+
int shift = wps->float_max_exp - wps->float_norm_exp + wps->float_shift;
|
|
31
|
+
|
|
32
|
+
if (shift > 32)
|
|
33
|
+
shift = 32;
|
|
34
|
+
else if (shift < -32)
|
|
35
|
+
shift = -32;
|
|
36
|
+
|
|
37
|
+
while (num_values--) {
|
|
38
|
+
if (shift > 0)
|
|
39
|
+
*values <<= shift;
|
|
40
|
+
else if (shift < 0)
|
|
41
|
+
*values >>= -shift;
|
|
42
|
+
|
|
43
|
+
if (*values > 8388607L)
|
|
44
|
+
*values = 8388607L;
|
|
45
|
+
else if (*values < -8388608L)
|
|
46
|
+
*values = -8388608L;
|
|
47
|
+
|
|
48
|
+
values++;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
Copyright (c) 1998 - 2006 Conifer Software
|
|
2
|
-
All rights reserved.
|
|
3
|
-
|
|
4
|
-
Redistribution and use in source and binary forms, with or without
|
|
5
|
-
modification, are permitted provided that the following conditions are met:
|
|
6
|
-
|
|
7
|
-
* Redistributions of source code must retain the above copyright notice,
|
|
8
|
-
this list of conditions and the following disclaimer.
|
|
9
|
-
* Redistributions in binary form must reproduce the above copyright notice,
|
|
10
|
-
this list of conditions and the following disclaimer in the
|
|
11
|
-
documentation and/or other materials provided with the distribution.
|
|
12
|
-
* Neither the name of Conifer Software nor the names of its contributors
|
|
13
|
-
may be used to endorse or promote products derived from this software
|
|
14
|
-
without specific prior written permission.
|
|
15
|
-
|
|
16
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
17
|
-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
18
|
-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
19
|
-
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
|
|
20
|
-
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
21
|
-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
22
|
-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
23
|
-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
24
|
-
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
25
|
-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1
|
+
Copyright (c) 1998 - 2006 Conifer Software
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
|
6
|
+
|
|
7
|
+
* Redistributions of source code must retain the above copyright notice,
|
|
8
|
+
this list of conditions and the following disclaimer.
|
|
9
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
|
10
|
+
this list of conditions and the following disclaimer in the
|
|
11
|
+
documentation and/or other materials provided with the distribution.
|
|
12
|
+
* Neither the name of Conifer Software nor the names of its contributors
|
|
13
|
+
may be used to endorse or promote products derived from this software
|
|
14
|
+
without specific prior written permission.
|
|
15
|
+
|
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
17
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
18
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
19
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
|
|
20
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
21
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
22
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
23
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
24
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
25
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -1,105 +1,105 @@
|
|
|
1
|
-
////////////////////////////////////////////////////////////////////////////
|
|
2
|
-
// **** WAVPACK **** //
|
|
3
|
-
// Hybrid Lossless Wavefile Compressor //
|
|
4
|
-
// Copyright (c) 1998 - 2006 Conifer Software. //
|
|
5
|
-
// All Rights Reserved. //
|
|
6
|
-
// Distributed under the BSD Software License (see license.txt) //
|
|
7
|
-
////////////////////////////////////////////////////////////////////////////
|
|
8
|
-
|
|
9
|
-
// metadata.c
|
|
10
|
-
|
|
11
|
-
// This module handles the metadata structure introduced in WavPack 4.0
|
|
12
|
-
|
|
13
|
-
#include "wavpack.h"
|
|
14
|
-
|
|
15
|
-
int read_metadata_buff (WavpackContext *wpc, WavpackMetadata *wpmd)
|
|
16
|
-
{
|
|
17
|
-
uchar tchar;
|
|
18
|
-
|
|
19
|
-
if (!wpc->infile (&wpmd->id, 1) || !wpc->infile (&tchar, 1))
|
|
20
|
-
return FALSE;
|
|
21
|
-
|
|
22
|
-
wpmd->byte_length = tchar << 1;
|
|
23
|
-
|
|
24
|
-
if (wpmd->id & ID_LARGE) {
|
|
25
|
-
wpmd->id &= ~ID_LARGE;
|
|
26
|
-
|
|
27
|
-
if (!wpc->infile (&tchar, 1))
|
|
28
|
-
return FALSE;
|
|
29
|
-
|
|
30
|
-
wpmd->byte_length += (int32_t) tchar << 9;
|
|
31
|
-
|
|
32
|
-
if (!wpc->infile (&tchar, 1))
|
|
33
|
-
return FALSE;
|
|
34
|
-
|
|
35
|
-
wpmd->byte_length += (int32_t) tchar << 17;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (wpmd->id & ID_ODD_SIZE) {
|
|
39
|
-
wpmd->id &= ~ID_ODD_SIZE;
|
|
40
|
-
wpmd->byte_length--;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (wpmd->byte_length && wpmd->byte_length <= sizeof (wpc->read_buffer)) {
|
|
44
|
-
uint32_t bytes_to_read = wpmd->byte_length + (wpmd->byte_length & 1);
|
|
45
|
-
|
|
46
|
-
if (wpc->infile (wpc->read_buffer, bytes_to_read) != (int32_t) bytes_to_read) {
|
|
47
|
-
wpmd->data = NULL;
|
|
48
|
-
return FALSE;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
wpmd->data = wpc->read_buffer;
|
|
52
|
-
}
|
|
53
|
-
else
|
|
54
|
-
wpmd->data = NULL;
|
|
55
|
-
|
|
56
|
-
return TRUE;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
int process_metadata (WavpackContext *wpc, WavpackMetadata *wpmd)
|
|
60
|
-
{
|
|
61
|
-
WavpackStream *wps = &wpc->stream;
|
|
62
|
-
|
|
63
|
-
switch (wpmd->id) {
|
|
64
|
-
case ID_DUMMY:
|
|
65
|
-
return TRUE;
|
|
66
|
-
|
|
67
|
-
case ID_DECORR_TERMS:
|
|
68
|
-
return read_decorr_terms (wps, wpmd);
|
|
69
|
-
|
|
70
|
-
case ID_DECORR_WEIGHTS:
|
|
71
|
-
return read_decorr_weights (wps, wpmd);
|
|
72
|
-
|
|
73
|
-
case ID_DECORR_SAMPLES:
|
|
74
|
-
return read_decorr_samples (wps, wpmd);
|
|
75
|
-
|
|
76
|
-
case ID_ENTROPY_VARS:
|
|
77
|
-
return read_entropy_vars (wps, wpmd);
|
|
78
|
-
|
|
79
|
-
case ID_HYBRID_PROFILE:
|
|
80
|
-
return read_hybrid_profile (wps, wpmd);
|
|
81
|
-
|
|
82
|
-
case ID_FLOAT_INFO:
|
|
83
|
-
return read_float_info (wps, wpmd);
|
|
84
|
-
|
|
85
|
-
case ID_INT32_INFO:
|
|
86
|
-
return read_int32_info (wps, wpmd);
|
|
87
|
-
|
|
88
|
-
case ID_CHANNEL_INFO:
|
|
89
|
-
return read_channel_info (wpc, wpmd);
|
|
90
|
-
|
|
91
|
-
case ID_CONFIG_BLOCK:
|
|
92
|
-
return read_config_info (wpc, wpmd);
|
|
93
|
-
|
|
94
|
-
case ID_WV_BITSTREAM:
|
|
95
|
-
return init_wv_bitstream (wpc, wpmd);
|
|
96
|
-
|
|
97
|
-
case ID_SHAPING_WEIGHTS:
|
|
98
|
-
case ID_WVC_BITSTREAM:
|
|
99
|
-
case ID_WVX_BITSTREAM:
|
|
100
|
-
return TRUE;
|
|
101
|
-
|
|
102
|
-
default:
|
|
103
|
-
return (wpmd->id & ID_OPTIONAL_DATA) ? TRUE : FALSE;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
1
|
+
////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// **** WAVPACK **** //
|
|
3
|
+
// Hybrid Lossless Wavefile Compressor //
|
|
4
|
+
// Copyright (c) 1998 - 2006 Conifer Software. //
|
|
5
|
+
// All Rights Reserved. //
|
|
6
|
+
// Distributed under the BSD Software License (see license.txt) //
|
|
7
|
+
////////////////////////////////////////////////////////////////////////////
|
|
8
|
+
|
|
9
|
+
// metadata.c
|
|
10
|
+
|
|
11
|
+
// This module handles the metadata structure introduced in WavPack 4.0
|
|
12
|
+
|
|
13
|
+
#include "wavpack.h"
|
|
14
|
+
|
|
15
|
+
int read_metadata_buff (WavpackContext *wpc, WavpackMetadata *wpmd)
|
|
16
|
+
{
|
|
17
|
+
uchar tchar;
|
|
18
|
+
|
|
19
|
+
if (!wpc->infile (&wpmd->id, 1) || !wpc->infile (&tchar, 1))
|
|
20
|
+
return FALSE;
|
|
21
|
+
|
|
22
|
+
wpmd->byte_length = tchar << 1;
|
|
23
|
+
|
|
24
|
+
if (wpmd->id & ID_LARGE) {
|
|
25
|
+
wpmd->id &= ~ID_LARGE;
|
|
26
|
+
|
|
27
|
+
if (!wpc->infile (&tchar, 1))
|
|
28
|
+
return FALSE;
|
|
29
|
+
|
|
30
|
+
wpmd->byte_length += (int32_t) tchar << 9;
|
|
31
|
+
|
|
32
|
+
if (!wpc->infile (&tchar, 1))
|
|
33
|
+
return FALSE;
|
|
34
|
+
|
|
35
|
+
wpmd->byte_length += (int32_t) tchar << 17;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (wpmd->id & ID_ODD_SIZE) {
|
|
39
|
+
wpmd->id &= ~ID_ODD_SIZE;
|
|
40
|
+
wpmd->byte_length--;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (wpmd->byte_length && wpmd->byte_length <= sizeof (wpc->read_buffer)) {
|
|
44
|
+
uint32_t bytes_to_read = wpmd->byte_length + (wpmd->byte_length & 1);
|
|
45
|
+
|
|
46
|
+
if (wpc->infile (wpc->read_buffer, bytes_to_read) != (int32_t) bytes_to_read) {
|
|
47
|
+
wpmd->data = NULL;
|
|
48
|
+
return FALSE;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
wpmd->data = wpc->read_buffer;
|
|
52
|
+
}
|
|
53
|
+
else
|
|
54
|
+
wpmd->data = NULL;
|
|
55
|
+
|
|
56
|
+
return TRUE;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
int process_metadata (WavpackContext *wpc, WavpackMetadata *wpmd)
|
|
60
|
+
{
|
|
61
|
+
WavpackStream *wps = &wpc->stream;
|
|
62
|
+
|
|
63
|
+
switch (wpmd->id) {
|
|
64
|
+
case ID_DUMMY:
|
|
65
|
+
return TRUE;
|
|
66
|
+
|
|
67
|
+
case ID_DECORR_TERMS:
|
|
68
|
+
return read_decorr_terms (wps, wpmd);
|
|
69
|
+
|
|
70
|
+
case ID_DECORR_WEIGHTS:
|
|
71
|
+
return read_decorr_weights (wps, wpmd);
|
|
72
|
+
|
|
73
|
+
case ID_DECORR_SAMPLES:
|
|
74
|
+
return read_decorr_samples (wps, wpmd);
|
|
75
|
+
|
|
76
|
+
case ID_ENTROPY_VARS:
|
|
77
|
+
return read_entropy_vars (wps, wpmd);
|
|
78
|
+
|
|
79
|
+
case ID_HYBRID_PROFILE:
|
|
80
|
+
return read_hybrid_profile (wps, wpmd);
|
|
81
|
+
|
|
82
|
+
case ID_FLOAT_INFO:
|
|
83
|
+
return read_float_info (wps, wpmd);
|
|
84
|
+
|
|
85
|
+
case ID_INT32_INFO:
|
|
86
|
+
return read_int32_info (wps, wpmd);
|
|
87
|
+
|
|
88
|
+
case ID_CHANNEL_INFO:
|
|
89
|
+
return read_channel_info (wpc, wpmd);
|
|
90
|
+
|
|
91
|
+
case ID_CONFIG_BLOCK:
|
|
92
|
+
return read_config_info (wpc, wpmd);
|
|
93
|
+
|
|
94
|
+
case ID_WV_BITSTREAM:
|
|
95
|
+
return init_wv_bitstream (wpc, wpmd);
|
|
96
|
+
|
|
97
|
+
case ID_SHAPING_WEIGHTS:
|
|
98
|
+
case ID_WVC_BITSTREAM:
|
|
99
|
+
case ID_WVX_BITSTREAM:
|
|
100
|
+
return TRUE;
|
|
101
|
+
|
|
102
|
+
default:
|
|
103
|
+
return (wpmd->id & ID_OPTIONAL_DATA) ? TRUE : FALSE;
|
|
104
|
+
}
|
|
105
|
+
}
|