shithub: sox

Download patch

ref: cbdab0ba1bf3e009222e3038bcac0efc1de627f8
parent: c42b41dc0d8e3c120fbf950180def271ac15bb2e
author: cbagwell <cbagwell>
date: Wed Jan 3 13:33:51 EST 2007

Adding seek support for GSM WAV files

--- a/ChangeLog
+++ b/ChangeLog
@@ -85,6 +85,7 @@
   o Improved multi-channel file reading; fixes [1599990].  (robs)
   o New options for specifying endianness (and separate option for
     bit reversal) [FR# 1621702].  (robs)
+  o Add seek support for GSM data in WAV files. Rafal Maszkowski
 
 sox-12.18.2
 -----------
--- a/src/wav.c
+++ b/src/wav.c
@@ -1691,9 +1691,32 @@
     {
         case WAVE_FORMAT_IMA_ADPCM:
         case WAVE_FORMAT_ADPCM:
-        case WAVE_FORMAT_GSM610:
             st_fail_errno(ft,ST_ENOTSUP,"Only PCM Supported");
             break;
+
+        case WAVE_FORMAT_GSM610:
+            {   
+                st_size_t gsmoff;
+
+                /* rounding bytes to blockAlign so that we
+                 * don't have to decode partial block. */
+                gsmoff = offset * wav->blockAlign / wav->samplesPerBlock + 
+                         wav->blockAlign * ft->signal.channels / 2;
+                gsmoff -= gsmoff % (wav->blockAlign * ft->signal.channels);
+
+                ft->st_errno = st_seeki(ft, gsmoff + wav->dataStart, SEEK_SET);
+                if (ft->st_errno != ST_SUCCESS)
+                    return ST_EOF;
+
+                /* offset is in samples */
+                new_offset = offset;
+                alignment = offset % wav->samplesPerBlock;                
+                if (alignment != 0)
+                    new_offset += (wav->samplesPerBlock - alignment);
+                wav->numSamples = ft->length - (new_offset / ft->signal.channels);
+            }
+            break;
+
         default:
             new_offset = offset * ft->signal.size;
             /* Make sure request aligns to a channel block (ie left+right) */