diff options
Diffstat (limited to 'apps/plugins')
-rw-r--r-- | apps/plugins/wav2wv.c | 74 |
1 files changed, 47 insertions, 27 deletions
diff --git a/apps/plugins/wav2wv.c b/apps/plugins/wav2wv.c index 24a7f8be6d..4cb7b14f2a 100644 --- a/apps/plugins/wav2wv.c +++ b/apps/plugins/wav2wv.c | |||
@@ -92,6 +92,10 @@ static void wvupdate (long start_tick, | |||
92 | #endif | 92 | #endif |
93 | } | 93 | } |
94 | 94 | ||
95 | #define TEMP_SAMPLES 4096 | ||
96 | |||
97 | static long temp_buffer [TEMP_SAMPLES] IDATA_ATTR; | ||
98 | |||
95 | static int wav2wv (char *filename) | 99 | static int wav2wv (char *filename) |
96 | { | 100 | { |
97 | int in_fd, out_fd, num_chans, error = false, last_buttons; | 101 | int in_fd, out_fd, num_chans, error = false, last_buttons; |
@@ -144,7 +148,6 @@ static int wav2wv (char *filename) | |||
144 | } | 148 | } |
145 | 149 | ||
146 | wpc = WavpackOpenFileOutput (); | 150 | wpc = WavpackOpenFileOutput (); |
147 | WavpackSetOutputBuffer (wpc, output_buffer, output_buffer + 0x100000); | ||
148 | 151 | ||
149 | rb->memset (&config, 0, sizeof (config)); | 152 | rb->memset (&config, 0, sizeof (config)); |
150 | config.bits_per_sample = 16; | 153 | config.bits_per_sample = 16; |
@@ -153,6 +156,8 @@ static int wav2wv (char *filename) | |||
153 | num_chans = config.num_channels = native_header.NumChannels; | 156 | num_chans = config.num_channels = native_header.NumChannels; |
154 | total_samples = native_header.data_ckSize / native_header.BlockAlign; | 157 | total_samples = native_header.data_ckSize / native_header.BlockAlign; |
155 | 158 | ||
159 | // config.flags |= CONFIG_HIGH_FLAG; | ||
160 | |||
156 | if (!WavpackSetConfiguration (wpc, &config, total_samples)) { | 161 | if (!WavpackSetConfiguration (wpc, &config, total_samples)) { |
157 | rb->splash(HZ*2, true, "internal error!"); | 162 | rb->splash(HZ*2, true, "internal error!"); |
158 | rb->close (in_fd); | 163 | rb->close (in_fd); |
@@ -178,7 +183,7 @@ static int wav2wv (char *filename) | |||
178 | wvupdate (start_tick, native_header.SampleRate, total_samples, 0, 0, 0); | 183 | wvupdate (start_tick, native_header.SampleRate, total_samples, 0, 0, 0); |
179 | 184 | ||
180 | for (samples_remaining = total_samples; samples_remaining;) { | 185 | for (samples_remaining = total_samples; samples_remaining;) { |
181 | unsigned long samples_count, bytes_count; | 186 | unsigned long samples_count, samples_to_pack, bytes_count; |
182 | int cnt, buttons; | 187 | int cnt, buttons; |
183 | long value, *lp; | 188 | long value, *lp; |
184 | char *cp; | 189 | char *cp; |
@@ -197,33 +202,48 @@ static int wav2wv (char *filename) | |||
197 | } | 202 | } |
198 | 203 | ||
199 | total_bytes_read += bytes_count; | 204 | total_bytes_read += bytes_count; |
200 | cp = (char *) input_buffer + bytes_count; | 205 | WavpackStartBlock (wpc, output_buffer, output_buffer + 0x100000); |
201 | lp = input_buffer + samples_count * num_chans; | 206 | samples_to_pack = samples_count; |
202 | cnt = samples_count; | 207 | cp = (char *) input_buffer; |
203 | 208 | ||
204 | if (num_chans == 2) | 209 | while (samples_to_pack) { |
205 | while (cnt--) { | 210 | unsigned long samples_this_pass = TEMP_SAMPLES / num_chans; |
206 | value = *--cp << 8; | 211 | |
207 | value += *--cp & 0xff; | 212 | if (samples_this_pass > samples_to_pack) |
208 | *--lp = value; | 213 | samples_this_pass = samples_to_pack; |
209 | value = *--cp << 8; | 214 | |
210 | value += *--cp & 0xff; | 215 | lp = temp_buffer; |
211 | *--lp = value; | 216 | cnt = samples_this_pass; |
212 | } | 217 | |
213 | else | 218 | if (num_chans == 2) |
214 | while (cnt--) { | 219 | while (cnt--) { |
215 | value = *--cp << 8; | 220 | value = *cp++ & 0xff; |
216 | value += *--cp & 0xff; | 221 | value += *cp++ << 8; |
217 | *--lp = value; | 222 | *lp++ = value; |
218 | } | 223 | value = *cp++ & 0xff; |
219 | 224 | value += *cp++ << 8; | |
220 | bytes_count = WavpackPackSamples (wpc, input_buffer, samples_count); | 225 | *lp++ = value; |
226 | } | ||
227 | else | ||
228 | while (cnt--) { | ||
229 | value = *cp++ & 0xff; | ||
230 | value += *cp++ << 8; | ||
231 | *lp++ = value; | ||
232 | } | ||
233 | |||
234 | if (!WavpackPackSamples (wpc, temp_buffer, samples_this_pass)) { | ||
235 | rb->splash(HZ*2, true, "internal error!"); | ||
236 | error = true; | ||
237 | break; | ||
238 | } | ||
239 | |||
240 | samples_to_pack -= samples_this_pass; | ||
241 | } | ||
221 | 242 | ||
222 | if (!bytes_count) { | 243 | if (error) |
223 | rb->splash(HZ*2, true, "internal error!"); | ||
224 | error = true; | ||
225 | break; | 244 | break; |
226 | } | 245 | |
246 | bytes_count = WavpackFinishBlock (wpc); | ||
227 | 247 | ||
228 | if (rb->write (out_fd, output_buffer, bytes_count) != (long) bytes_count) { | 248 | if (rb->write (out_fd, output_buffer, bytes_count) != (long) bytes_count) { |
229 | rb->splash(HZ*2, true, "could not write file!"); | 249 | rb->splash(HZ*2, true, "could not write file!"); |