ref: eb95bc3cad50e412e00e9db850f56cbe44b77fcd
parent: eda8fca0d1211fac705d1ea39221e8c6f5a72b2f
author: robs <robs>
date: Sat Dec 23 08:32:34 EST 2006
Improved multi-channel file reading.
--- a/ChangeLog
+++ b/ChangeLog
@@ -78,6 +78,7 @@
o Added prompt to overwrite pre-existing output file (unless overridden
with --force). (robs)
o Added silence padding effect. (robs)
+ o Improved multi-channel file reading; fixes [1599990]. (robs)
sox-12.18.2
-----------
--- a/TODO
+++ b/TODO
@@ -2,11 +2,6 @@
sox-devel@lists.sourceforge.net, or post them on the patches tracker
at http://sf.net/projects/sox/.
- o Update all read routines to be like WAV handler and only
- return data in multiples of sample_size*channels. This
- will prevent corrupt files from causing sox to go into
- an infinite loop trying to read just a couple more bytes.
-
o Make "mix" an alias of "avg" since that's closer to what it
really is. For 2->2 mixes, make a 2 option L->L and R->R
shortcut. Similar 4 option for 4->4.
@@ -86,5 +81,3 @@
o Effects option-parsers should fail if extraneous characters or arguments
are present. e.g. vol 3mW, speed 2 3, etc. should all fail.
-
- o Fix the multi-channel bug in trim.
--- a/src/stio.c
+++ b/src/stio.c
@@ -171,7 +171,6 @@
int i;
bool no_filetype_given = filetype == NULL;
- fprintf(stderr, "%s %s\n", filetype, path);
ft->filename = xstrdup(path);
/* Let auto effect do the work if user is not overriding. */
@@ -282,7 +281,11 @@
st_size_t st_read(ft_t ft, st_sample_t *buf, st_size_t len)
{
- return (*ft->h->read)(ft, buf, len);
+ len -= len % ft->info.channels; /* We need a whole number of "wide" samples */
+ len = (*ft->h->read)(ft, buf, len);
+ if (len != ST_EOF)
+ len -= len % ft->info.channels; /* Belt & braces */
+ return len;
}
st_size_t st_write(ft_t ft, const st_sample_t *buf, st_size_t len)
--- a/src/tests.sh
+++ b/src/tests.sh
@@ -33,9 +33,9 @@
if [ "${format1_skip}x" = "x" -a "${from_skip}x" = "x" ] ; then
getFormat ${format1}; format1Text=$formatText; format1Flags=$formatFlags
getFormat $1; format2Text=$formatText; format2Flags=$formatFlags
- ./sox -c $channels -r $rate -n $format1Flags input.$format1 synth $samples's' sin 300-3300 noise
- ./sox $verbose -r $rate -c $channels $format1Flags input.$format1 $format2Flags intermediate.$1
- ./sox $verbose -r $rate -c $channels $format2Flags intermediate.$1 $format1Flags output.$format1
+ ./sox --force -c $channels -r $rate -n $format1Flags input.$format1 synth $samples's' sin 300-3300 noise trapezium
+ ./sox --force $verbose -r $rate -c $channels $format1Flags input.$format1 $format2Flags intermediate.$1
+ ./sox --force $verbose -r $rate -c $channels $format2Flags intermediate.$1 $format1Flags output.$format1
if cmp -s input.$format1 output.$format1
then
@@ -70,18 +70,23 @@
convertToAndFrom ul sw uw sl raw Raw dat
format1=Wav
- convertToAndFrom Wav aiff aifc au avr dat maud sf flac
- (samples=23492; convertToAndFrom 8svx) # Even number of samples only
- (rate=8000; convertToAndFrom voc) # Fixed rate
+ convertToAndFrom Wav aiff aifc au dat sf flac
}
+do_twochannel_formats () {
+ format1=Wav
+ convertToAndFrom avr maud
+ (rate=8000; convertToAndFrom voc) || exit 1 # Fixed rate
+ (samples=23492; convertToAndFrom 8svx) || exit 1 # Even number of samples only
+}
+
do_singlechannel_formats () {
format1=Wav
convertToAndFrom smp
- (rate=5512; convertToAndFrom hcom) # Fixed rate
+ (rate=5512; convertToAndFrom hcom) || exit 1 # Fixed rate
format1=wve
- (rate=8000; convertToAndFrom al sw uw sl raw Raw dat) # Fixed rate
+ (rate=8000; convertToAndFrom al sw uw sl raw Raw dat) || exit 1 # Fixed rate
}
grep -q "^#define HAVE_LIBFLAC" stconfig.h || skip="flac $skip"
@@ -88,10 +93,14 @@
rate=44100
samples=23493
+channels=3
+do_multichannel_formats
channels=2
do_multichannel_formats
+do_twochannel_formats
channels=1
do_multichannel_formats
+do_twochannel_formats
do_singlechannel_formats
./sox -c 1 -n output.ub synth .01 vol .5
--- a/src/trim.c
+++ b/src/trim.c
@@ -129,12 +129,6 @@
/* Compute the most samples we can process this time */
done = ((*isamp < *osamp) ? *isamp : *osamp);
- if (done % effp->ininfo.channels) {
- st_fail("FIXME: multi-channel not implemented properly.");
- *isamp = *osamp = 0;
- return ST_EOF;
- }
-
/* Quick check to see if we are trimming off the back side yet.
* If so then we can skip trimming from the front side.
*/