summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <waker@users.sourceforge.net>2014-06-21 13:54:46 +0200
committerGravatar Alexey Yakovenko <waker@users.sourceforge.net>2014-06-21 13:55:43 +0200
commitdd563895851aca5e7a6504f1fc0264a341ab9eab (patch)
tree855b876dcf263c6cc5c9110596ca48a3e6753395 /plugins
parentab64fa187f7df94a3242982722d1cd05242446c7 (diff)
converter: write correct data size into wav files, clip to 0xffffffff if doesn't fit in 32 bit
Diffstat (limited to 'plugins')
-rw-r--r--plugins/converter/converter.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/plugins/converter/converter.c b/plugins/converter/converter.c
index 18b68d68..46307116 100644
--- a/plugins/converter/converter.c
+++ b/plugins/converter/converter.c
@@ -970,10 +970,10 @@ convert (DB_playItem_t *it, const char *out, int output_bps, int output_is_float
// write wave header
char wavehdr_int[] = {
- 0x52, 0x49, 0x46, 0x46, 0x24, 0x70, 0x0d, 0x00, 0x57, 0x41, 0x56, 0x45, 0x66, 0x6d, 0x74, 0x20, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x44, 0xac, 0x00, 0x00, 0x10, 0xb1, 0x02, 0x00, 0x04, 0x00, 0x10, 0x00, 0x64, 0x61, 0x74, 0x61
+ 0x52, 0x49, 0x46, 0x46, 0x00, 0x00, 0x00, 0x00, 0x57, 0x41, 0x56, 0x45, 0x66, 0x6d, 0x74, 0x20, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x44, 0xac, 0x00, 0x00, 0x10, 0xb1, 0x02, 0x00, 0x04, 0x00, 0x10, 0x00, 0x64, 0x61, 0x74, 0x61
};
char wavehdr_float[] = {
- 0x52, 0x49, 0x46, 0x46, 0x2a, 0xdf, 0x02, 0x00, 0x57, 0x41, 0x56, 0x45, 0x66, 0x6d, 0x74, 0x20, 0x28, 0x00, 0x00, 0x00, 0xfe, 0xff, 0x02, 0x00, 0x40, 0x1f, 0x00, 0x00, 0x00, 0xfa, 0x00, 0x00, 0x08, 0x00, 0x20, 0x00, 0x16, 0x00, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71, 0x66, 0x61, 0x63, 0x74, 0x04, 0x00, 0x00, 0x00, 0xc5, 0x5b, 0x00, 0x00, 0x64, 0x61, 0x74, 0x61
+ 0x52, 0x49, 0x46, 0x46, 0x00, 0x00, 0x00, 0x00, 0x57, 0x41, 0x56, 0x45, 0x66, 0x6d, 0x74, 0x20, 0x28, 0x00, 0x00, 0x00, 0xfe, 0xff, 0x02, 0x00, 0x40, 0x1f, 0x00, 0x00, 0x00, 0xfa, 0x00, 0x00, 0x08, 0x00, 0x20, 0x00, 0x16, 0x00, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71, 0x66, 0x61, 0x63, 0x74, 0x04, 0x00, 0x00, 0x00, 0xc5, 0x5b, 0x00, 0x00, 0x64, 0x61, 0x74, 0x61
};
char *wavehdr = output_is_float ? wavehdr_float : wavehdr_int;
int wavehdr_size = output_is_float ? sizeof (wavehdr_float) : sizeof (wavehdr_int);
@@ -1054,9 +1054,9 @@ convert (DB_playItem_t *it, const char *out, int output_bps, int output_is_float
outsize += sz;
if (!header_written) {
- uint32_t size = (it->endsample-it->startsample) * outch * output_bps / 8;
+ uint64_t size = (int64_t)(it->endsample-it->startsample) * outch * output_bps / 8;
if (!size) {
- size = deadbeef->pl_get_item_duration (it) * fileinfo->fmt.samplerate * outch * output_bps / 8;
+ size = (double)deadbeef->pl_get_item_duration (it) * fileinfo->fmt.samplerate * outch * output_bps / 8;
}
@@ -1067,20 +1067,38 @@ convert (DB_playItem_t *it, const char *out, int output_bps, int output_is_float
size = temp;
}
+ uint64_t chunksize;
+ chunksize = size + 36;
+
+ // for float, add 36 more
+ if (output_is_float) {
+ chunksize += 36;
+ }
+
+ uint32_t size32 = 0xffffffff;
+ if (chunksize <= 0xffffffff) {
+ size32 = chunksize;
+ }
+ memcpy (&wavehdr[4], &size32, 4);
memcpy (&wavehdr[22], &outch, 2);
memcpy (&wavehdr[24], &outsr, 4);
uint16_t blockalign = outch * output_bps / 8;
memcpy (&wavehdr[32], &blockalign, 2);
memcpy (&wavehdr[34], &output_bps, 2);
+ size32 = 0xffffffff;
+ if (size <= 0xffffffff) {
+ size32 = size;
+ }
+
if (wavehdr_size != write (temp_file, wavehdr, wavehdr_size)) {
fprintf (stderr, "converter: wave header write error\n");
goto error;
}
if (encoder_preset->method == DDB_ENCODER_METHOD_PIPE) {
- size = 0;
+ size32 = 0;
}
- if (write (temp_file, &size, sizeof (size)) != sizeof (size)) {
+ if (write (temp_file, &size32, sizeof (size32)) != sizeof (size32)) {
fprintf (stderr, "converter: wave header size write error\n");
goto error;
}