[MPlayer-dev-eng] [PATCH] enable ao_pcm to output s16be

Peter Fordham peter.fordham at gmail.com
Mon Jan 18 00:19:41 CET 2010


OK, how about this then? It allows a lot more PCM formats when not
writing the WAV header.

-Pete


Index: libao2/ao_pcm.c
===================================================================
--- libao2/ao_pcm.c	(revision 30357)
+++ libao2/ao_pcm.c	(working copy)
@@ -56,6 +56,7 @@
 static int fast = 0;

 #define WAV_ID_RIFF 0x46464952 /* "RIFF" */
+#define WAV_ID_RIFX 0x58464952 /* "RIFX" */
 #define WAV_ID_WAVE 0x45564157 /* "WAVE" */
 #define WAV_ID_FMT  0x20746d66 /* "fmt " */
 #define WAV_ID_DATA 0x61746164 /* "data" */
@@ -111,32 +112,47 @@
             strdup(ao_pcm_waveheader?"audiodump.wav":"audiodump.pcm");
     }

-    bits=8;
-    switch(format){
-    case AF_FORMAT_S32_BE:
-        format=AF_FORMAT_S32_LE;
-    case AF_FORMAT_S32_LE:
-        bits=32;
+    switch (format & AF_FORMAT_BITS_MASK)
+    {
+    default:
+    case AF_FORMAT_8BIT:
+        bits = 8;
         break;
-    case AF_FORMAT_FLOAT_BE:
-        format=AF_FORMAT_FLOAT_LE;
-    case AF_FORMAT_FLOAT_LE:
-        bits=32;
+    case AF_FORMAT_16BIT:
+        bits = 16;
         break;
-    case AF_FORMAT_S8:
-        format=AF_FORMAT_U8;
-    case AF_FORMAT_U8:
+    case AF_FORMAT_24BIT:
+        bits = 24;
         break;
-    case AF_FORMAT_AC3_BE:
-    case AF_FORMAT_AC3_LE:
-        bits=16;
+    case AF_FORMAT_32BIT:
+        bits = 32;
         break;
-    default:
-        format=AF_FORMAT_S16_LE;
-        bits=16;
+    case AF_FORMAT_40BIT:
+        bits = 40;
         break;
+    case AF_FORMAT_48BIT:
+        bits = 48;
+        break;
     }

+    if (ao_pcm_waveheader)
+    {
+        // Force LE for WAV files, shouldn't need to do this
+        // but mplayer doesn't understand RIFX WAV files.
+        format = (format &~ AF_FORMAT_END_MASK) | AF_FORMAT_LE;
+
+        switch(format){
+        case AF_FORMAT_S8:
+            // WAV files only allow unsigned 8-bit PCM
+            format = AF_FORMAT_U8;
+            break;
+        case AF_FORMAT_U16_LE:
+            // WAV files only allow signed 16-bit PCM
+            format = AF_FORMAT_S16_LE;
+            break;
+       }
+    }
+
     ao_data.outburst = 65536;
     ao_data.buffersize= 2*65536;
     ao_data.channels=channels;
@@ -144,11 +160,12 @@
     ao_data.format=format;
     ao_data.bps=channels*rate*(bits/8);

-    wavhdr.riff = le2me_32(WAV_ID_RIFF);
+    wavhdr.riff = le2me_32((format & AF_FORMAT_END_MASK) ==
AF_FORMAT_BE ? WAV_ID_RIFX : WAV_ID_RIFF);
     wavhdr.wave = le2me_32(WAV_ID_WAVE);
     wavhdr.fmt = le2me_32(WAV_ID_FMT);
     wavhdr.fmt_length = le2me_32(16);
-    wavhdr.fmt_tag = le2me_16(format == AF_FORMAT_FLOAT_LE ?
WAV_ID_FLOAT_PCM : WAV_ID_PCM);
+    wavhdr.fmt_tag = le2me_16((format == AF_FORMAT_FLOAT_LE || format
== AF_FORMAT_FLOAT_BE) ?
+                              WAV_ID_FLOAT_PCM : WAV_ID_PCM);
     wavhdr.channels = le2me_16(ao_data.channels);
     wavhdr.sample_rate = le2me_32(ao_data.samplerate);
     wavhdr.bytes_per_second = le2me_32(ao_data.bps);



More information about the MPlayer-dev-eng mailing list