shithub: sox

Download patch

ref: 44dc2abe48eaded6e27f4a1ae92fa2666d38993b
parent: 792012d799daefaa777397987a221fed54b63ecb
author: robs <robs>
date: Sun Nov 19 15:43:02 EST 2006

Add support for 24-bit PCM raw, wav, & flac files.

--- a/src/flac.c
+++ b/src/flac.c
@@ -208,7 +208,14 @@
 
       for (channel = 0; channel < decoder->channels; ++channel)
       {
-        *sampleBuffer++ = decoder->decoded_wide_samples[channel][decoder->wide_sample_number] << (32 - decoder->bits_per_sample);
+        FLAC__int32 d = decoder->decoded_wide_samples[channel][decoder->wide_sample_number];
+        switch (decoder->bits_per_sample)
+        {
+          case  8: *sampleBuffer++ = ST_SIGNED_BYTE_TO_SAMPLE(d); break;
+          case 16: *sampleBuffer++ = ST_SIGNED_WORD_TO_SAMPLE(d); break;
+          case 24: *sampleBuffer++ = ST_SIGNED_24BIT_TO_SAMPLE(d); break;
+          case 32: *sampleBuffer++ = ST_SIGNED_DWORD_TO_SAMPLE(d); break;
+        }
         ++actual;
       }
       ++decoder->wide_sample_number;
@@ -336,7 +343,7 @@
 #undef SET_OPTION
   }
 
-  encoder->bits_per_sample = (format->info.size > 3 ? 3 : format->info.size) << 3;
+  encoder->bits_per_sample = (format->info.size > 4 ? 4 : format->info.size) << 3;
   st_report("FLAC encoding at %i bits per sample", encoder->bits_per_sample);
 
   FLAC__stream_encoder_set_channels(encoder->flac, format->info.channels);
@@ -354,7 +361,7 @@
     }
     if (!streamable)
     {
-      st_warn("FLAC: non-standard rate; output may not be streamable");
+      st_report("FLAC: non-standard rate; output may not be streamable");
       FLAC__stream_encoder_set_streamable_subset(encoder->flac, false);
     }
   }
@@ -435,7 +442,13 @@
 
   for (i = 0; i < len; ++i)
   {
-    encoder->decoded_samples[i] = sampleBuffer[i] >> (32 - encoder->bits_per_sample);
+    switch (encoder->bits_per_sample)
+    {
+      case  8: encoder->decoded_samples[i] = ST_SAMPLE_TO_SIGNED_BYTE(sampleBuffer[i]); break;
+      case 16: encoder->decoded_samples[i] = ST_SAMPLE_TO_SIGNED_WORD(sampleBuffer[i]); break;
+      case 24: encoder->decoded_samples[i] = ST_SAMPLE_TO_SIGNED_24BIT(sampleBuffer[i]); break;
+      case 32: encoder->decoded_samples[i] = ST_SAMPLE_TO_SIGNED_DWORD(sampleBuffer[i]); break;
+    }
   }
   FLAC__stream_encoder_process_interleaved(encoder->flac, encoder->decoded_samples, len / format->info.channels);
   return FLAC__stream_encoder_get_state(encoder->flac) == FLAC__STREAM_ENCODER_OK ? len : -1;
--- a/src/handlers.c
+++ b/src/handlers.c
@@ -47,6 +47,7 @@
 #endif
   st_prc_format_fn,
   st_raw_format_fn,
+  st_s3_format_fn,
   st_sb_format_fn,
   st_sf_format_fn,
   st_sl_format_fn,
@@ -59,6 +60,8 @@
   st_svx_format_fn,
   st_sw_format_fn,
   st_txw_format_fn,
+  st_u3_format_fn,
+  st_u4_format_fn,
   st_ub_format_fn,
   st_ul_format_fn,
   st_uw_format_fn,
--- a/src/st_i.h
+++ b/src/st_i.h
@@ -180,10 +180,13 @@
 extern const st_format_t *st_al_format_fn(void);
 extern const st_format_t *st_la_format_fn(void);
 extern const st_format_t *st_lu_format_fn(void);
+extern const st_format_t *st_s3_format_fn(void);
 extern const st_format_t *st_sb_format_fn(void);
 extern const st_format_t *st_sl_format_fn(void);
 extern const st_format_t *st_sw_format_fn(void);
+extern const st_format_t *st_u3_format_fn(void);
 extern const st_format_t *st_ub_format_fn(void);
+extern const st_format_t *st_u4_format_fn(void);
 extern const st_format_t *st_ul_format_fn(void);
 extern const st_format_t *st_uw_format_fn(void);
 extern const st_format_t *st_sf_format_fn(void);