summaryrefslogtreecommitdiff
path: root/apps/plugins/wav2wv.c
diff options
context:
space:
mode:
authorDave Bryant <bryant@rockbox.org>2005-07-09 23:14:41 +0000
committerDave Bryant <bryant@rockbox.org>2005-07-09 23:14:41 +0000
commit85e03767f7f59eabfdb2e6aaffdebb63e48a0d00 (patch)
treed2553b044d4a88d2ee49a3e358b74759e9d16f14 /apps/plugins/wav2wv.c
parentd1af08f9cb347009f57b282b734ae5f5abd878da (diff)
Reorganized encoder to allow compressing blocks in smaller chunks and
improved efficiency somewhat by looping through data in tighter passes. Code is basically ready for an attempt at direct recording. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7088 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/wav2wv.c')
-rw-r--r--apps/plugins/wav2wv.c74
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,
#endif
}
+#define TEMP_SAMPLES 4096
+
+static long temp_buffer [TEMP_SAMPLES] IDATA_ATTR;
+
static int wav2wv (char *filename)
{
int in_fd, out_fd, num_chans, error = false, last_buttons;
@@ -144,7 +148,6 @@ static int wav2wv (char *filename)
}
wpc = WavpackOpenFileOutput ();
- WavpackSetOutputBuffer (wpc, output_buffer, output_buffer + 0x100000);
rb->memset (&config, 0, sizeof (config));
config.bits_per_sample = 16;
@@ -153,6 +156,8 @@ static int wav2wv (char *filename)
num_chans = config.num_channels = native_header.NumChannels;
total_samples = native_header.data_ckSize / native_header.BlockAlign;
+// config.flags |= CONFIG_HIGH_FLAG;
+
if (!WavpackSetConfiguration (wpc, &config, total_samples)) {
rb->splash(HZ*2, true, "internal error!");
rb->close (in_fd);
@@ -178,7 +183,7 @@ static int wav2wv (char *filename)
wvupdate (start_tick, native_header.SampleRate, total_samples, 0, 0, 0);
for (samples_remaining = total_samples; samples_remaining;) {
- unsigned long samples_count, bytes_count;
+ unsigned long samples_count, samples_to_pack, bytes_count;
int cnt, buttons;
long value, *lp;
char *cp;
@@ -197,33 +202,48 @@ static int wav2wv (char *filename)
}
total_bytes_read += bytes_count;
- cp = (char *) input_buffer + bytes_count;
- lp = input_buffer + samples_count * num_chans;
- cnt = samples_count;
-
- if (num_chans == 2)
- while (cnt--) {
- value = *--cp << 8;
- value += *--cp & 0xff;
- *--lp = value;
- value = *--cp << 8;
- value += *--cp & 0xff;
- *--lp = value;
- }
- else
- while (cnt--) {
- value = *--cp << 8;
- value += *--cp & 0xff;
- *--lp = value;
- }
-
- bytes_count = WavpackPackSamples (wpc, input_buffer, samples_count);
+ WavpackStartBlock (wpc, output_buffer, output_buffer + 0x100000);
+ samples_to_pack = samples_count;
+ cp = (char *) input_buffer;
+
+ while (samples_to_pack) {
+ unsigned long samples_this_pass = TEMP_SAMPLES / num_chans;
+
+ if (samples_this_pass > samples_to_pack)
+ samples_this_pass = samples_to_pack;
+
+ lp = temp_buffer;
+ cnt = samples_this_pass;
+
+ if (num_chans == 2)
+ while (cnt--) {
+ value = *cp++ & 0xff;
+ value += *cp++ << 8;
+ *lp++ = value;
+ value = *cp++ & 0xff;
+ value += *cp++ << 8;
+ *lp++ = value;
+ }
+ else
+ while (cnt--) {
+ value = *cp++ & 0xff;
+ value += *cp++ << 8;
+ *lp++ = value;
+ }
+
+ if (!WavpackPackSamples (wpc, temp_buffer, samples_this_pass)) {
+ rb->splash(HZ*2, true, "internal error!");
+ error = true;
+ break;
+ }
+
+ samples_to_pack -= samples_this_pass;
+ }
- if (!bytes_count) {
- rb->splash(HZ*2, true, "internal error!");
- error = true;
+ if (error)
break;
- }
+
+ bytes_count = WavpackFinishBlock (wpc);
if (rb->write (out_fd, output_buffer, bytes_count) != (long) bytes_count) {
rb->splash(HZ*2, true, "could not write file!");