ref: 5e6b85c0cb2603b7f9933aecff53e343edf8c251
parent: 40e6fb44883611af7b01dbe537a392d1861d39b9
author: rrt <rrt>
date: Thu Apr 5 11:45:57 EDT 2007
Fix sphere reader not to swallow the first 4 bytes of every file by doing the shorten test (seek back after the test, and only do the test on seekable streams; we can't deal with shorten-compressed data anyway). Add sph to the tests. At the moment, sph <-> u3 and sph <-> alaw doesn't work. Why not?
--- a/src/sphere.c
+++ b/src/sphere.c
@@ -148,16 +148,19 @@
sphere->shorten_check[0] = 0;
- /* Check first four bytes of data to see if it's shorten
- * compressed or not.
- */
- sox_reads(ft, sphere->shorten_check, 4);
+ if (ft->seekable) {
+ /* Check first four bytes of data to see if it's shorten compressed. */
+ sox_size_t pos = sox_tell(ft);
+ sox_reads(ft, sphere->shorten_check, 4);
- if (!strcmp(sphere->shorten_check,"ajkg"))
- {
- sox_fail_errno(ft,SOX_EFMT,"File uses shorten compression, cannot handle this.");
+ if (!strcmp(sphere->shorten_check,"ajkg")) {
+ sox_fail_errno(ft, SOX_EFMT, "File uses shorten compression, cannot handle this.");
free(buf);
return(SOX_EOF);
+ }
+
+ /* Can't just seek -4, as sox_reads has read 1-4 bytes */
+ sox_seeki(ft, pos, SEEK_SET);
}
free(buf);
@@ -164,27 +167,6 @@
return (SOX_SUCCESS);
}
-/*
- * Read up to len samples from file.
- * Convert to signed longs.
- * Place in buf[].
- * Return number of samples read.
- */
-
-static sox_size_t sox_sphereread(ft_t ft, sox_sample_t *buf, sox_size_t len)
-{
- sphere_t sphere = (sphere_t) ft->priv;
-
- if (sphere->shorten_check[0])
- {
- /* TODO: put these 4 bytes into the buffer. Requires
- * knowing how to process ulaw and all version of PCM data size.
- */
- sphere->shorten_check[0] = 0;
- }
- return sox_rawread(ft, buf, len);
-}
-
static int sox_spherestartwrite(ft_t ft)
{
int rc;
@@ -292,7 +274,7 @@
NULL,
0,
sox_spherestartread,
- sox_sphereread,
+ sox_rawread,
sox_rawstopread,
sox_spherestartwrite,
sox_spherewrite,
--- a/src/tests.sh
+++ b/src/tests.sh
@@ -2,7 +2,7 @@
#
# SoX Regression Test script: Lossless file conversion
#
-# FIXME: Test sndt sph ogg
+# FIXME: Test sndt ogg ima
# Options:
#verbose=-V
@@ -33,7 +33,10 @@
fi
if [ "${format1_skip}x" = "x" -a "${from_skip}x" = "x" ] ; then
getFormat ${format1}; format1Text=$formatText; format1Flags=$formatFlags
- getFormat $1; format2Text=$formatText; format2Flags=$formatFlags
+ getFormat $1; format2Text=$formatText; format2Flags=$formatFlags
+ echo ./sox -c $channels -r $rate -n $format1Flags input.$format1 synth $samples's' sin 300-3300 noise trapezium
+ echo ./sox $verbose -r $rate -c $channels $format1Flags input.$format1 $format2Flags intermediate.$1
+ echo ./sox $verbose -r $rate -c $channels $format2Flags intermediate.$1 $format1Flags output.$format1
./sox -c $channels -r $rate -n $format1Flags input.$format1 synth $samples's' sin 300-3300 noise trapezium
./sox $verbose -r $rate -c $channels $format1Flags input.$format1 $format2Flags intermediate.$1
./sox $verbose -r $rate -c $channels $format2Flags intermediate.$1 $format1Flags output.$format1
@@ -53,25 +56,25 @@
do_multichannel_formats () {
format1=ub
- convertToAndFrom sb ub sw uw s3 u3 sl u4 raw Raw dat au wav aiff aifc flac caf
+ convertToAndFrom sb ub sw uw s3 u3 sl u4 raw Raw dat au wav aiff aifc flac caf sph
format1=sw
- convertToAndFrom sw uw s3 u3 sl u4 raw Raw dat au wav aiff aifc flac caf
+ convertToAndFrom sw uw s3 u3 sl u4 raw Raw dat au wav aiff aifc flac caf sph
format1=u3
convertToAndFrom s3 u3 sl u4 raw Raw wav aiff aifc flac
format1=sl
- convertToAndFrom sl u4 Raw wav aiff aifc caf
+ convertToAndFrom sl u4 Raw wav aiff aifc caf sph
format1=al
convertToAndFrom al sw uw sl raw Raw dat aiff aifc flac caf
format1=ul
- convertToAndFrom ul sw uw sl raw Raw dat aiff aifc flac caf
+ convertToAndFrom ul sw uw sl raw Raw dat aiff aifc flac caf sph
format1=Wav
- convertToAndFrom Wav aiff aifc au dat sf flac caf
+ convertToAndFrom Wav aiff aifc au dat sf flac caf sph
}
do_twochannel_formats () {