[MPlayer-users] Need help for proper downmixing

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Sun Apr 17 22:50:59 CEST 2005


Hi,
On Sun, Apr 17, 2005 at 02:12:35PM +0200, Nico Sabbi wrote:
> If I use
> -channels 6 -af hrtf=s -ao pcm:file=x.wav
> 
> sound is exactly how I like it, but the resulting audio stream still has 
> 6 channels,
> although I verified that if I play it with -channels 2 it still sounds 
> correctly.

This problem has two parts: First af_hrtf.c _outputs_ 6 channels. The
attached patch fixes this, as well as some other things I think that are
bugs. Please test...

> So, how should I insert filters?

There is still some other bug left :-(

Greetings,
Reimar Döffinger
-------------- next part --------------
Index: libaf/af_hrtf.c
===================================================================
RCS file: /cvsroot/mplayer/main/libaf/af_hrtf.c,v
retrieving revision 1.7
diff -u -r1.7 af_hrtf.c
--- libaf/af_hrtf.c	11 Apr 2005 14:01:29 -0000	1.7
+++ libaf/af_hrtf.c	17 Apr 2005 20:44:31 -0000
@@ -267,6 +267,7 @@
 static int control(struct af_instance_s *af, int cmd, void* arg)
 {
     af_hrtf_t *s = af->setup;
+    int test_output_res;
     char mode;
 
     switch(cmd) {
@@ -281,8 +282,6 @@
 	    return AF_ERROR;
 	}
 	af->data->nch    = ((af_data_t*)arg)->nch;
-	if(af->data->nch < 5) {
-	    af->data->nch = 5;
 	    if(af->data->nch == 2) {
  	       /* 2 channel input */
  	       if(s->decode_mode != HRTF_MIX_MATRIX2CH) {
@@ -290,11 +289,17 @@
  		  s->decode_mode = HRTF_MIX_STEREO;
 	       }
 	    }
-	}
+	    else if (af->data->nch < 5)
+	      af->data->nch = 5;
 	af->data->format = AF_FORMAT_S16_NE;
 	af->data->bps    = 2;
+	test_output_res = af_test_output(af, (af_data_t*)arg);
+	af->mul.n = 2;
+	af->mul.d = af->data->nch;
+	// after testing input set the real output format
+	af->data->nch = 2;
 	s->print_flag = 1;
-	return af_test_output(af, (af_data_t*)arg);
+	return test_output_res;
     case AF_CONTROL_COMMAND_LINE:
 	sscanf((char*)arg, "%c", &mode);
 	switch(mode) {
@@ -516,9 +521,9 @@
 	left  += (1 - BASSCROSS) * left_b  + BASSCROSS * right_b;
 	right += (1 - BASSCROSS) * right_b + BASSCROSS * left_b;
 	/* Also mix the LFE channel (if available) */
-	if(af->data->nch >= 6) {
-	    left  += out[5] * M3_01DB;
-	    right += out[5] * M3_01DB;
+	if(data->nch >= 6) {
+	    left  += in[5] * M3_01DB;
+	    right += in[5] * M3_01DB;
 	}
 
 	/* Amplitude renormalization. */
@@ -545,11 +550,6 @@
 	   break;
 	}
 
-	/* The remaining channels are not needed any more */
-	out[2] = out[3] = out[4] = 0;
-	if(af->data->nch >= 6)
-	    out[5] = 0;
-
 	/* Next sample... */
 	in = &in[data->nch];
 	out = &out[af->data->nch];
@@ -561,7 +561,7 @@
     /* Set output data */
     data->audio = af->data->audio;
     data->len   = (data->len * af->mul.n) / af->mul.d;
-    data->nch   = af->data->nch;
+    data->nch   = 2;
 
     return data;
 }


More information about the MPlayer-users mailing list