diff options
author | Dave Bryant <bryant@rockbox.org> | 2005-07-04 06:38:00 +0000 |
---|---|---|
committer | Dave Bryant <bryant@rockbox.org> | 2005-07-04 06:38:00 +0000 |
commit | dacbc16d5b2c2a113eab6b9295db12795d98e2cc (patch) | |
tree | 6040249a9776880f02d478532028f41065a65451 /apps/codecs/libwavpack/metadata.c | |
parent | 1d5f07b0a654ca0ee0b6f4785388801ed809af33 (diff) | |
download | rockbox-dacbc16d5b2c2a113eab6b9295db12795d98e2cc.tar.gz rockbox-dacbc16d5b2c2a113eab6b9295db12795d98e2cc.zip |
Added lossless encoding to WavPack library. Also made a few changes to
decoding stuff in preparation for future optimization and eliminated all tabs.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7009 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/libwavpack/metadata.c')
-rw-r--r-- | apps/codecs/libwavpack/metadata.c | 136 |
1 files changed, 91 insertions, 45 deletions
diff --git a/apps/codecs/libwavpack/metadata.c b/apps/codecs/libwavpack/metadata.c index 661b25edc8..ebc7dcf99d 100644 --- a/apps/codecs/libwavpack/metadata.c +++ b/apps/codecs/libwavpack/metadata.c | |||
@@ -12,46 +12,48 @@ | |||
12 | 12 | ||
13 | #include "wavpack.h" | 13 | #include "wavpack.h" |
14 | 14 | ||
15 | #include <string.h> | ||
16 | |||
15 | int read_metadata_buff (WavpackContext *wpc, WavpackMetadata *wpmd) | 17 | int read_metadata_buff (WavpackContext *wpc, WavpackMetadata *wpmd) |
16 | { | 18 | { |
17 | uchar tchar; | 19 | uchar tchar; |
18 | 20 | ||
19 | if (!wpc->infile (&wpmd->id, 1) || !wpc->infile (&tchar, 1)) | 21 | if (!wpc->infile (&wpmd->id, 1) || !wpc->infile (&tchar, 1)) |
20 | return FALSE; | 22 | return FALSE; |
21 | 23 | ||
22 | wpmd->byte_length = tchar << 1; | 24 | wpmd->byte_length = tchar << 1; |
23 | 25 | ||
24 | if (wpmd->id & ID_LARGE) { | 26 | if (wpmd->id & ID_LARGE) { |
25 | wpmd->id &= ~ID_LARGE; | 27 | wpmd->id &= ~ID_LARGE; |
26 | 28 | ||
27 | if (!wpc->infile (&tchar, 1)) | 29 | if (!wpc->infile (&tchar, 1)) |
28 | return FALSE; | 30 | return FALSE; |
29 | 31 | ||
30 | wpmd->byte_length += (long) tchar << 9; | 32 | wpmd->byte_length += (long) tchar << 9; |
31 | 33 | ||
32 | if (!wpc->infile (&tchar, 1)) | 34 | if (!wpc->infile (&tchar, 1)) |
33 | return FALSE; | 35 | return FALSE; |
34 | 36 | ||
35 | wpmd->byte_length += (long) tchar << 17; | 37 | wpmd->byte_length += (long) tchar << 17; |
36 | } | 38 | } |
37 | 39 | ||
38 | if (wpmd->id & ID_ODD_SIZE) { | 40 | if (wpmd->id & ID_ODD_SIZE) { |
39 | wpmd->id &= ~ID_ODD_SIZE; | 41 | wpmd->id &= ~ID_ODD_SIZE; |
40 | wpmd->byte_length--; | 42 | wpmd->byte_length--; |
41 | } | 43 | } |
42 | 44 | ||
43 | if (wpmd->byte_length && wpmd->byte_length <= (long)sizeof (wpc->read_buffer)) { | 45 | if (wpmd->byte_length && wpmd->byte_length <= (long)sizeof (wpc->read_buffer)) { |
44 | ulong bytes_to_read = wpmd->byte_length + (wpmd->byte_length & 1); | 46 | ulong bytes_to_read = wpmd->byte_length + (wpmd->byte_length & 1); |
45 | 47 | ||
46 | if (wpc->infile (wpc->read_buffer, bytes_to_read) != (long) bytes_to_read) { | 48 | if (wpc->infile (wpc->read_buffer, bytes_to_read) != (long) bytes_to_read) { |
47 | wpmd->data = NULL; | 49 | wpmd->data = NULL; |
48 | return FALSE; | 50 | return FALSE; |
49 | } | 51 | } |
50 | 52 | ||
51 | wpmd->data = wpc->read_buffer; | 53 | wpmd->data = wpc->read_buffer; |
52 | } | 54 | } |
53 | else | 55 | else |
54 | wpmd->data = NULL; | 56 | wpmd->data = NULL; |
55 | 57 | ||
56 | return TRUE; | 58 | return TRUE; |
57 | } | 59 | } |
@@ -61,45 +63,89 @@ int process_metadata (WavpackContext *wpc, WavpackMetadata *wpmd) | |||
61 | WavpackStream *wps = &wpc->stream; | 63 | WavpackStream *wps = &wpc->stream; |
62 | 64 | ||
63 | switch (wpmd->id) { | 65 | switch (wpmd->id) { |
64 | case ID_DUMMY: | 66 | case ID_DUMMY: |
65 | return TRUE; | 67 | return TRUE; |
68 | |||
69 | case ID_DECORR_TERMS: | ||
70 | return read_decorr_terms (wps, wpmd); | ||
71 | |||
72 | case ID_DECORR_WEIGHTS: | ||
73 | return read_decorr_weights (wps, wpmd); | ||
74 | |||
75 | case ID_DECORR_SAMPLES: | ||
76 | return read_decorr_samples (wps, wpmd); | ||
77 | |||
78 | case ID_ENTROPY_VARS: | ||
79 | return read_entropy_vars (wps, wpmd); | ||
66 | 80 | ||
67 | case ID_DECORR_TERMS: | 81 | case ID_HYBRID_PROFILE: |
68 | return read_decorr_terms (wps, wpmd); | 82 | return read_hybrid_profile (wps, wpmd); |
69 | 83 | ||
70 | case ID_DECORR_WEIGHTS: | 84 | case ID_FLOAT_INFO: |
71 | return read_decorr_weights (wps, wpmd); | 85 | return read_float_info (wps, wpmd); |
72 | 86 | ||
73 | case ID_DECORR_SAMPLES: | 87 | case ID_INT32_INFO: |
74 | return read_decorr_samples (wps, wpmd); | 88 | return read_int32_info (wps, wpmd); |
75 | 89 | ||
76 | case ID_ENTROPY_VARS: | 90 | case ID_CHANNEL_INFO: |
77 | return read_entropy_vars (wps, wpmd); | 91 | return read_channel_info (wpc, wpmd); |
78 | 92 | ||
79 | case ID_HYBRID_PROFILE: | 93 | case ID_CONFIG_BLOCK: |
80 | return read_hybrid_profile (wps, wpmd); | 94 | return read_config_info (wpc, wpmd); |
95 | |||
96 | case ID_WV_BITSTREAM: | ||
97 | return init_wv_bitstream (wpc, wpmd); | ||
98 | |||
99 | case ID_SHAPING_WEIGHTS: | ||
100 | case ID_WVC_BITSTREAM: | ||
101 | case ID_WVX_BITSTREAM: | ||
102 | return TRUE; | ||
103 | |||
104 | default: | ||
105 | return (wpmd->id & ID_OPTIONAL_DATA) ? TRUE : FALSE; | ||
106 | } | ||
107 | } | ||
81 | 108 | ||
82 | case ID_FLOAT_INFO: | 109 | int copy_metadata (WavpackMetadata *wpmd, uchar *buffer_start, uchar *buffer_end) |
83 | return read_float_info (wps, wpmd); | 110 | { |
111 | ulong mdsize = wpmd->byte_length + (wpmd->byte_length & 1); | ||
112 | WavpackHeader *wphdr = (WavpackHeader *) buffer_start; | ||
84 | 113 | ||
85 | case ID_INT32_INFO: | 114 | if (wpmd->byte_length & 1) |
86 | return read_int32_info (wps, wpmd); | 115 | ((char *) wpmd->data) [wpmd->byte_length] = 0; |
87 | 116 | ||
88 | case ID_CHANNEL_INFO: | 117 | mdsize += (wpmd->byte_length > 510) ? 4 : 2; |
89 | return read_channel_info (wpc, wpmd); | 118 | buffer_start += wphdr->ckSize + 8; |
90 | 119 | ||
91 | case ID_CONFIG_BLOCK: | 120 | if (buffer_start + mdsize >= buffer_end) |
92 | return read_config_info (wpc, wpmd); | 121 | return FALSE; |
93 | 122 | ||
94 | case ID_WV_BITSTREAM: | 123 | buffer_start [0] = wpmd->id | (wpmd->byte_length & 1 ? ID_ODD_SIZE : 0); |
95 | return init_wv_bitstream (wpc, wpmd); | 124 | buffer_start [1] = (wpmd->byte_length + 1) >> 1; |
96 | 125 | ||
97 | case ID_SHAPING_WEIGHTS: | 126 | if (wpmd->byte_length > 510) { |
98 | case ID_WVC_BITSTREAM: | 127 | buffer_start [0] |= ID_LARGE; |
99 | case ID_WVX_BITSTREAM: | 128 | buffer_start [2] = (wpmd->byte_length + 1) >> 9; |
100 | return TRUE; | 129 | buffer_start [3] = (wpmd->byte_length + 1) >> 17; |
130 | } | ||
101 | 131 | ||
102 | default: | 132 | if (wpmd->data && wpmd->byte_length) { |
103 | return (wpmd->id & ID_OPTIONAL_DATA) ? TRUE : FALSE; | 133 | if (wpmd->byte_length > 510) { |
134 | buffer_start [0] |= ID_LARGE; | ||
135 | buffer_start [2] = (wpmd->byte_length + 1) >> 9; | ||
136 | buffer_start [3] = (wpmd->byte_length + 1) >> 17; | ||
137 | memcpy (buffer_start + 4, wpmd->data, mdsize - 4); | ||
138 | } | ||
139 | else | ||
140 | memcpy (buffer_start + 2, wpmd->data, mdsize - 2); | ||
104 | } | 141 | } |
142 | |||
143 | wphdr->ckSize += mdsize; | ||
144 | return TRUE; | ||
105 | } | 145 | } |
146 | |||
147 | void free_metadata (WavpackMetadata *wpmd) | ||
148 | { | ||
149 | wpmd->data = NULL; | ||
150 | } | ||
151 | |||