shithub: sox

Download patch

ref: f77f0f732eb11153e182443204211a7216d50cd4
parent: f05b764b4f4d4a035b357af42a2ee3af3927a101
author: cbagwell <cbagwell>
date: Sat Oct 1 16:02:03 EDT 2005

Moving ft->length back to total samples instead of frames

--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -69,7 +69,8 @@
 ALSAOBJ_1   = alsa.o
 EXTRAOBJS   = $(OSSOBJ_$(NEED_OSS)) $(SUNAUOBJ_$(NEED_SUNAU)) $(ALSAOBJ_$(NEED_ALSA)) $(GSMOBJ_$(GSM_SUPPORT))
 
-LIBOBJS = $(FOBJ) $(EOBJ) handlers.o stio.o misc.o util.o getopt.o $(EXTRAOBJS)
+LIBOBJS = $(FOBJ) $(EOBJ) getopt.o handlers.o misc.o stio.o \
+	  util.o $(EXTRAOBJS)
 
 # Building libgsm.a is kinda a hack.  It switches to a different
 # makefile with hardcoded options.  We really want the object files
--- a/src/aiff.c
+++ b/src/aiff.c
@@ -91,8 +91,7 @@
     ft->st_errno = st_seeki(ft, new_offset, SEEK_SET);
 
     if (ft->st_errno == ST_SUCCESS)
-        aiff->nsamples = ft->length - 
-                          (new_offset / ft->info.size / ft->info.channels);
+        aiff->nsamples = ft->length - (new_offset / ft->info.size);
 
     return(ft->st_errno);
 }
@@ -424,12 +423,12 @@
 
         }
 
-        aiff->nsamples = ssndsize / ft->info.size / ft->info.channels;
+        aiff->nsamples = ssndsize / ft->info.size;
 
         /* Cope with 'sowt' CD tracks as read on Macs */
         if (is_sowt)
         {
-                aiff->nsamples -= (4 / ft->info.channels);
+                aiff->nsamples -= 4;
                 ft->swap = ft->swap ? 0 : 1;
         }
         
@@ -620,12 +619,12 @@
 
         if (len < 0)
             return ST_EOF;
-        else if ((st_size_t)len > aiff->nsamples*ft->info.channels)
-                len = (aiff->nsamples*ft->info.channels);
+        else if ((st_size_t)len > aiff->nsamples)
+                len = aiff->nsamples;
         done = st_rawread(ft, buf, len);
         if (done == 0 && aiff->nsamples != 0)
                 st_warn("Premature EOF on AIFF input file");
-        aiff->nsamples -= (done / ft->info.channels);
+        aiff->nsamples -= done;
         return done;
 }
 
@@ -713,7 +712,7 @@
 st_ssize_t st_aiffwrite(ft_t ft, st_sample_t *buf, st_ssize_t len)
 {
         aiff_t aiff = (aiff_t ) ft->priv;
-        aiff->nsamples += (len / ft->info.channels);
+        aiff->nsamples += len;
         st_rawwrite(ft, buf, len);
         return(len);
 }
@@ -740,7 +739,7 @@
                 st_fail_errno(ft,errno,"can't rewind output file to rewrite AIFF header");
                 return(ST_EOF);
         }
-        return(aiffwriteheader(ft, aiff->nsamples));
+        return(aiffwriteheader(ft, aiff->nsamples / ft->info.channels));
 }
 
 static int aiffwriteheader(ft_t ft, st_size_t nframes)
--- a/src/cdr.c
+++ b/src/cdr.c
@@ -63,7 +63,7 @@
 
 /* Need length for seeking */
         if(ft->seekable){
-                ft->length = st_filelength(ft)/2/2;
+                ft->length = st_filelength(ft)/ST_SIZE_WORD;
         } else {
                 ft->length = 0;
         }
--- a/src/prc.c
+++ b/src/prc.c
@@ -113,7 +113,7 @@
         ft->info.channels = 1;
 
         p->dataStart = st_tell(ft);
-        ft->length = p->length/ft->info.size/ft->info.channels;
+        ft->length = p->length/ft->info.size;
 
         return (ST_SUCCESS);
 }
--- a/src/sf.c
+++ b/src/sf.c
@@ -154,7 +154,7 @@
 
 /* Need length for seeking */
         if(ft->seekable){
-                ft->length = st_filelength(ft)/samplesize/ft->info.channels;
+                ft->length = st_filelength(ft)/samplesize;
                 sf->dataStart = st_tell(ft);
         } else {
                 ft->length = 0;
--- a/src/smp.c
+++ b/src/smp.c
@@ -191,8 +191,7 @@
     ft->st_errno = st_seeki(ft, new_offset, SEEK_SET);
 
     if( ft->st_errno == ST_SUCCESS )
-        smp->NoOfSamps = (ft->length*ft->info.channels) - 
-                         (new_offset / ft->info.size);
+        smp->NoOfSamps = ft->length - (new_offset / ft->info.size);
 
     return(ft->st_errno);
 }
@@ -263,8 +262,8 @@
         samplestart = st_tell(ft);
 
         /* seek from the current position (the start of sample data) by */
-        /* NoOfSamps * 2 */
-        if (st_seeki(ft, smp->NoOfSamps * 2L, 1) == -1)
+        /* NoOfSamps * sizeof(int16_t) */
+        if (st_seek(ft, smp->NoOfSamps * 2L, 1) == -1)
         {
                 st_fail_errno(ft,errno,"SMP unable to seek to trailer");
                 return(ST_EOF);
--- a/src/st_i.h
+++ b/src/st_i.h
@@ -1,7 +1,7 @@
 #ifndef ST_I_H
 #define ST_I_H
 /*
- * Sound Tools Interal - October 11, 2001
+ * Sound Tools Internal - October 11, 2001
  *
  *   This file is meant for libst internal use only
  *
--- a/src/vorbis.c
+++ b/src/vorbis.c
@@ -131,10 +131,11 @@
         ft->info.channels = vi->channels;
 
         /* ov_pcm_total doesn't work on non-seekable files so
-         * skip that step in that case.
+         * skip that step in that case.  Also, it reports
+         * "frame"-ish results so we must * channels.
          */
         if (ft->seekable)
-            ft->length = ov_pcm_total(vb->vf, -1);
+            ft->length = ov_pcm_total(vb->vf, -1) * ft->info.channels;
         
         /* Record comments */
         if (vc->comments == 0)
--- a/src/wav.c
+++ b/src/wav.c
@@ -878,7 +878,7 @@
                            wav->blockAlign, wav->samplesPerBlock);
         /*st_report("datalen %d, numSamples %d",dwDataLength, wav->numSamples);*/
         wav->blockSamplesRemaining = 0;        /* Samples left in buffer */
-        ft->length = wav->numSamples;
+        ft->length = wav->numSamples*ft->info.channels;
         break;
 
     case WAVE_FORMAT_IMA_ADPCM:
@@ -890,7 +890,7 @@
         /*st_report("datalen %d, numSamples %d",dwDataLength, wav->numSamples);*/
         wav->blockSamplesRemaining = 0;        /* Samples left in buffer */
         initImaTable();
-        ft->length = wav->numSamples;
+        ft->length = wav->numSamples*ft->info.channels;
         break;
 
 #ifdef ENABLE_GSM
@@ -897,13 +897,13 @@
     case WAVE_FORMAT_GSM610:
         wav->numSamples = ((dwDataLength / wav->blockAlign) * wav->samplesPerBlock);
         wavgsminit(ft);
-        ft->length = wav->numSamples;
+        ft->length = wav->numSamples*ft->info.channels;
         break;
 #endif
 
     default:
         wav->numSamples = dwDataLength/ft->info.size/ft->info.channels;
-        ft->length = wav->numSamples;
+        ft->length = wav->numSamples*ft->info.channels;
     }
 
     st_report("Reading Wave file: %s format, %d channel%s, %d samp/sec",
@@ -1488,7 +1488,6 @@
                 /* intentional case fallthrough! */
 #endif
             default:
-                dwSamplesWritten /= wChannels; /* because how rawwrite()'s work */
                 blocksWritten = (dwSamplesWritten+wSamplesPerBlock-1)/wSamplesPerBlock;
                 dwDataLength = blocksWritten * wBlockAlign;
         }
@@ -1766,8 +1765,8 @@
             ft->st_errno = st_seeki(ft, new_offset, SEEK_SET);
 
             if( ft->st_errno == ST_SUCCESS )
-                wav->numSamples = ft->length - (new_offset / ft->info.size /
-                                  ft->info.channels);
+                wav->numSamples = (ft->length / ft->info.channels) -
+                                  (new_offset / ft->info.size / ft->info.channels);
     }
 
     return(ft->st_errno);
--- a/src/wve.c
+++ b/src/wve.c
@@ -124,7 +124,7 @@
         ft->info.channels = 1;
 
         p->dataStart = st_tell(ft);
-        ft->length = p->length/ft->info.size/ft->info.channels;
+        ft->length = p->length/ft->info.size;
 
         return (ST_SUCCESS);
 }