shithub: sox

Download patch

ref: 9285511b84be6be47fda82500fb0c57c88282329
parent: c1e92600b65fc8d7671bbd2ce7ac8d9671371999
author: Mans Rullgard <mans@mansr.com>
date: Thu Aug 6 08:08:32 EDT 2020

wav: prettify startread() function

--- a/src/wav.c
+++ b/src/wav.c
@@ -740,12 +740,12 @@
  *      size and encoding of samples,
  *      mono/stereo/quad.
  */
-static int startread(sox_format_t * ft)
+static int startread(sox_format_t *ft)
 {
-    priv_t *       wav = (priv_t *) ft->priv;
-    char        magic[5] = { 0 };
-    uint32_t    clen;
-    int err;
+    priv_t  *wav = ft->priv;
+    char     magic[5] = { 0 };
+    uint32_t clen;
+    int      err;
 
     sox_bool isRF64 = sox_false;
     uint64_t ds64_riff_size;
@@ -753,8 +753,8 @@
     uint64_t ds64_sample_count;
 
     /* wave file characteristics */
-    uint64_t      qwRiffLength;
-    uint64_t      qwDataLength = 0;
+    uint64_t qwRiffLength;
+    uint64_t qwDataLength = 0;
     sox_bool have_fmt = sox_false;
 
     ft->sox_errno = SOX_SUCCESS;
@@ -771,7 +771,7 @@
         lsx_debug("Found RF64 header");
         isRF64 = sox_true;
     } else if (memcmp(magic, "RIFF", 4)) {
-        lsx_fail_errno(ft,SOX_EHDR,"WAVE: RIFF header not found");
+        lsx_fail_errno(ft, SOX_EHDR, "WAVE: RIFF header not found");
         return SOX_EOF;
     }
 
@@ -778,7 +778,7 @@
     qwRiffLength = clen;
 
     if (lsx_readbuf(ft, magic, 4) < 4 || memcmp(magic, "WAVE", 4)) {
-        lsx_fail_errno(ft,SOX_EHDR,"WAVE header not found");
+        lsx_fail_errno(ft, SOX_EHDR, "WAVE header not found");
         return SOX_EOF;
     }
 
@@ -899,14 +899,13 @@
         wav->ignoreSize = 1;
     }
 
-    switch (wav->formatTag)
-    {
-
+    switch (wav->formatTag) {
     case WAVE_FORMAT_ADPCM:
         wav->numSamples =
-            lsx_ms_adpcm_samples_in((size_t)qwDataLength, (size_t)ft->signal.channels,
-                           (size_t)wav->blockAlign, (size_t)wav->samplesPerBlock);
-        lsx_debug_more("datalen %ld, numSamples %lu",qwDataLength, (unsigned long)wav->numSamples);
+            lsx_ms_adpcm_samples_in(qwDataLength, ft->signal.channels,
+                                    wav->blockAlign, wav->samplesPerBlock);
+        lsx_debug_more("datalen %ld, numSamples %lu",
+                       qwDataLength, (unsigned long)wav->numSamples);
         wav->blockSamplesRemaining = 0;        /* Samples left in buffer */
         break;
 
@@ -914,15 +913,16 @@
         /* Compute easiest part of number of samples.  For every block, there
            are samplesPerBlock samples to read. */
         wav->numSamples =
-            lsx_ima_samples_in((size_t)qwDataLength, (size_t)ft->signal.channels,
-                         (size_t)wav->blockAlign, (size_t)wav->samplesPerBlock);
-        lsx_debug_more("datalen %ld, numSamples %lu",qwDataLength, (unsigned long)wav->numSamples);
+            lsx_ima_samples_in(qwDataLength, ft->signal.channels,
+                               wav->blockAlign, wav->samplesPerBlock);
+        lsx_debug_more("datalen %ld, numSamples %lu",
+                       qwDataLength, (unsigned long)wav->numSamples);
         wav->blockSamplesRemaining = 0;        /* Samples left in buffer */
         lsx_ima_init_table();
         break;
 
     case WAVE_FORMAT_GSM610:
-        wav->numSamples = ((qwDataLength / wav->blockAlign) * wav->samplesPerBlock);
+        wav->numSamples = qwDataLength / wav->blockAlign * wav->samplesPerBlock;
         wavgsminit(ft);
         break;
     }