[MPlayer-dev-eng] Re: Audio filter problems: af_format.c

Juergen Keil jk at tools.de
Fri Oct 11 22:27:09 CEST 2002


I wrote

> How is the audio filtering system supposed to work on big endian cpus?

The appended patch should fix the problem on big endian cpus.

af_format.c swaps bytes only in case the input / output format is
different from the cpu's native endian format.

And af_resample.c requests 16-bit samples in native byte order for
it's input and output.


Now the next problem is A-V sync.  A-V sync is lost when the audio filters
are in use....   For example with:

  Building audio filter chain for 44100Hz/2ch/16bit -> 22050Hz/2ch/16bit...

plays the video at 1/2 the speed, while

  Building audio filter chain for 11025Hz/1ch/8bit -> 22050Hz/2ch/8bit...

plays the video stream at 4x the normal speed.



Index: libaf/af_format.c
===================================================================
RCS file: /cvsroot/mplayer/main/libaf/af_format.c,v
retrieving revision 1.4
diff -u -B -r1.4 af_format.c
--- libaf/af_format.c	11 Oct 2002 04:23:52 -0000	1.4
+++ libaf/af_format.c	11 Oct 2002 20:23:04 -0000
@@ -28,6 +28,12 @@
 #define LE 		(1<<2) // Little Endian
 #define END_MASK	(1<<2)
 
+#if WORDS_BIGENDIAN	       // native endian of cpu
+#define	NE	BE
+#else
+#define	NE	LE
+#endif
+
 // Signed
 #define US		(0<<3) // Un Signed
 #define SI		(1<<3) // SIgned
@@ -128,8 +134,8 @@
 
   la = l->audio;
 
-  // Change to little endian
-  if((cf&END_MASK)!=LE){
+  // Change to cpu native endian
+  if((cf&END_MASK)!=NE){
     switch(cf&NBITS_MASK){
     case(B16):{
       register uint16_t s;
@@ -234,8 +241,9 @@
       break;      
     }
   }
-  // Switch to the correct endainess (again the problem with sun?)
-  if((lf&END_MASK)!=LE){
+
+  // Switch from cpu native endian to the correct endianess 
+  if((lf&END_MASK)!=NE){
     switch(lf&NBITS_MASK){
     case(B16):{
       register uint16_t s;
Index: libaf/af_resample.c
===================================================================
RCS file: /cvsroot/mplayer/main/libaf/af_resample.c,v
retrieving revision 1.9
diff -u -B -r1.9 af_resample.c
--- libaf/af_resample.c	8 Oct 2002 10:20:36 -0000	1.9
+++ libaf/af_resample.c	11 Oct 2002 20:23:04 -0000
@@ -212,11 +212,11 @@
 
     // Set parameters
     af->data->nch    = n->nch;
-    af->data->format = AFMT_S16_LE;
+    af->data->format = AFMT_S16_NE;
     af->data->bps    = 2;
     if(af->data->format != n->format || af->data->bps != n->bps)
       rv = AF_FALSE;
-    n->format = AFMT_S16_LE;
+    n->format = AFMT_S16_NE;
     n->bps = 2;
 
     // Calculate up and down sampling factors
Index: libao2/afmt.h
===================================================================
RCS file: /cvsroot/mplayer/main/libao2/afmt.h,v
retrieving revision 1.2
diff -u -B -r1.2 afmt.h
--- libao2/afmt.h	27 Apr 2002 22:42:24 -0000	1.2
+++ libao2/afmt.h	11 Oct 2002 20:23:04 -0000
@@ -36,3 +36,14 @@
 # define AFMT_S32_BE              0x00002000
 #endif
 
+
+/* native endian formats */
+#ifndef	AFMT_S16_NE
+# if WORDS_BIGENDIAN
+#  define AFMT_S16_NE	AFMT_S16_BE
+#  define AFMT_S32_NE	AFMT_S32_BE
+# else
+#  define AFMT_S16_NE	AFMT_S16_LE
+#  define AFMT_S32_NE	AFMT_S32_LE
+# endif
+#endif





More information about the MPlayer-dev-eng mailing list