ref: e02d1db8faca48ce7a21dbe406cb7a7aa8754116
parent: 6d4e9fa315c331603e517361130a8368b1f65392
author: Ulrich Klauer <ulrich@chirlu.de>
date: Fri Mar 16 21:20:20 EDT 2012
Fix input length calculation Calculating the total length of the input wasn't done correctly for parallel combine methods when input files had different numbers of channels, or when merging. For the sequence combine method, it is not possible to determine the total length, so use SOX_UNKNOWN_LEN in that case.
--- a/ChangeLog
+++ b/ChangeLog
@@ -11,6 +11,11 @@
o Fix pipe file-type detection regression. (robs)
+Other bug fixes:
+
+ o Fix input length calculation for combine methods other than
+ concatenate. (Ulrich Klauer)
+
sox-14.4.0 2012-03-04
----------
--- a/src/sox.c
+++ b/src/sox.c
@@ -1617,6 +1617,7 @@
/* Report all input files; do this only the 1st time process() is called: */
if (!current_input) for (i = 0; i < input_count; i++)
report_file_info(files[i]);
+ combiner_signal.length = SOX_UNKNOWN_LEN;
} else {
size_t total_channels = 0;
size_t min_channels = SOX_SIZE_MAX;
@@ -1623,7 +1624,7 @@
size_t max_channels = 0;
size_t min_rate = SOX_SIZE_MAX;
size_t max_rate = 0;
- uint64_t total_length = 0, max_length = 0;
+ uint64_t total_length = 0, max_length_ws = 0;
/* Report all input files and gather info on differing rates & numbers of
* channels, and on the resulting output audio length: */
@@ -1634,7 +1635,9 @@
max_channels = max(max_channels, files[i]->ft->signal.channels);
min_rate = min(min_rate , files[i]->ft->signal.rate);
max_rate = max(max_rate , files[i]->ft->signal.rate);
- max_length = max(max_length , files[i]->ft->signal.length);
+ max_length_ws = files[i]->ft->signal.length ?
+ max(max_length_ws, files[i]->ft->signal.length / files[i]->ft->signal.channels) :
+ SOX_UNKNOWN_LEN;
if (total_length != SOX_UNKNOWN_LEN && files[i]->ft->signal.length)
total_length += files[i]->ft->signal.length;
else
@@ -1655,14 +1658,15 @@
if (min_rate != max_rate)
exit(1);
- if (combine_method == sox_concatenate)
- combiner_signal.length = total_length;
- else if (is_parallel(combine_method))
- combiner_signal.length = max_length;
-
/* Store the calculated # of combined channels: */
combiner_signal.channels =
combine_method == sox_merge? total_channels : max_channels;
+
+ if (combine_method == sox_concatenate)
+ combiner_signal.length = total_length;
+ else if (is_parallel(combine_method))
+ combiner_signal.length = max_length_ws != SOX_UNKNOWN_LEN ?
+ max_length_ws * combiner_signal.channels : SOX_UNKNOWN_LEN;
}
} /* calculate_combiner_signal_parameters */