[MPlayer-dev-eng] [PATCH] Proof of concept extrasurround plugin
Kis Gergely
kisg at lme.linux.hu
Thu Apr 4 22:03:40 CEST 2002
Hi,
I made the thing work.
WHAT'S NEW:
-> Every previously known bugs fixed.
-> The plugin now respects the -channels switch of mplayer and acts
accordingly. (The sochans switch has been removed.)
4 and 6 channel output is supported.
-> Included "quick workaround" for ao_plugin.c bug that prevented 6 channel
output in many cases. This is not a true fix, it may cause problems for
you.
-> Debug output enabled. Note the word "experimental".
TODO:
-> Use the same lowpass filter as in the original surround part of the plugin.
I couldn't figure the firfilter thingie out, so I stole^H^H^H^H^H reused
the simple RC lowpass filter from sox.
-> Discover and fix the bugs
KNOWN BUGS:
-> Quick workaround for ao_plugin.c may cause problems.
Patch is attached, or can be downloaded from
http://www.inf.bme.hu/~kisg/mplayer.
Please Anders look at the bug in ao_plugin.c
Thanks,
kisg
-------------- next part --------------
? cfg-mplayer.h.kisg4
? libao2/audio_plugin.h.kisg4
? libao2/pl_surround.c.kisg1
? libao2/pl_surround.c.kisg2
Index: libao2/ao_plugin.c
===================================================================
RCS file: /cvsroot/mplayer/main/libao2/ao_plugin.c,v
retrieving revision 1.15
diff -u -r1.15 ao_plugin.c
--- libao2/ao_plugin.c 12 Mar 2002 06:32:02 -0000 1.15
+++ libao2/ao_plugin.c 4 Apr 2002 20:06:18 -0000
@@ -229,9 +229,17 @@
int tmp = get_space();
int ret_len =(tmp<len)?tmp:len;
if(ret_len){
+
+ if (ret_len%2 != 0) {
+ ret_len += 1;
+ }
+
// Filter data
ao_plugin_data.len=ret_len;
ao_plugin_data.data=data;
+
+ fprintf(stderr,"ao_plugin: I send ao_plugin_data.len = %d data to the plugins\n",ao_plugin_data.len);
+
while(plugin(i))
plugin(i++)->play();
// Copy data to output buffer
Index: libao2/pl_surround.c
===================================================================
RCS file: /cvsroot/mplayer/main/libao2/pl_surround.c,v
retrieving revision 1.9
diff -u -r1.9 pl_surround.c
--- libao2/pl_surround.c 24 Dec 2001 18:54:58 -0000 1.9
+++ libao2/pl_surround.c 4 Apr 2002 20:06:18 -0000
@@ -64,6 +64,7 @@
int passthrough; // Just be a "NO-OP"
int msecs; // Rear channel delay in milliseconds
int16_t* databuf; // Output audio buffer
+ int databuf_len; // Output audio buffer length in samples
int16_t* Ls_delaybuf; // circular buffer to be used for delaying Ls audio
int16_t* Rs_delaybuf; // circular buffer to be used for delaying Rs audio
int delaybuf_len; // delaybuf buffer length in samples
@@ -72,10 +73,16 @@
int rate; // input data rate
int format; // input format
int input_channels; // input channels
+ int output_channels; // output channels
+ float lowp_cutoff; // cutoff freq for the lowpass filter
+ double lowp_A, lowp_B; // parameters for lowpass filter
+ double lowp_outm1; // output for lowpass filter (??)
} pl_surround_t;
-static pl_surround_t pl_surround={0,20,NULL,NULL,NULL,0,0,NULL,0,0,0};
+static pl_surround_t pl_surround={0,20,NULL,0,NULL,NULL,0,0,NULL,0,0,0,0,0,0,0,0};
+
+extern int audio_output_channels;
// to set/get/query special features/parameters
static int control(int cmd,int arg){
@@ -89,9 +96,20 @@
free(pl_surround.databuf); pl_surround.databuf = NULL;
}
// Allocate output buffer
- pl_surround.databuf = calloc(ao_plugin_data.len, 1);
+
+ fprintf(stderr, "pl_surround: We can produce: audio_plugin_data.len = %d\n",ao_plugin_data.len);
+
+ pl_surround.databuf_len = ao_plugin_data.len / sizeof(int16_t) / pl_surround.output_channels;
+
+ fprintf(stderr, "pl_surround: This means pl_surround.databuf_len = %d\n",pl_surround.databuf_len);
+
+ pl_surround.databuf = calloc(pl_surround.databuf_len*pl_surround.output_channels, sizeof(int16_t));
// Return back smaller len so we don't get overflowed...
- ao_plugin_data.len /= 2;
+ // ao_plugin_data.len /= 2;
+ ao_plugin_data.len = pl_surround.databuf_len * sizeof(int16_t) * pl_surround.input_channels;
+
+ fprintf(stderr, "pl_surround: We can receive: audio_plugin_data.len = %d\n",ao_plugin_data.len);
+
return CONTROL_OK;
}
return -1;
@@ -113,6 +131,12 @@
return 1;
}
+ if (audio_output_channels != 4 && audio_output_channels != 6) {
+ fprintf(stderr, "pl_surround: I'm dumb and can only output 4 or 6 channel sound, using passtrough mode\n");
+ pl_surround.passthrough = 1;
+ return 1;
+ }
+
pl_surround.passthrough = 0;
/* Store info on input format to expect */
@@ -120,9 +144,16 @@
pl_surround.format=ao_plugin_data.format;
pl_surround.input_channels=ao_plugin_data.channels;
+ /* Store info on output channel number */
+ pl_surround.output_channels = audio_output_channels;
+
+
// Input 2 channels, output will be 4 - tell ao_plugin
- ao_plugin_data.channels = 4;
- ao_plugin_data.sz_mult /= 2;
+// ao_plugin_data.channels = 4;
+// ao_plugin_data.sz_mult /= 2;
+
+ ao_plugin_data.channels = pl_surround.output_channels;
+ ao_plugin_data.sz_mult /= pl_surround.output_channels / pl_surround.input_channels;
// Figure out buffer space (in int16_ts) needed for the 15msec delay
// Extra 31 samples allow for lowpass filter delay (taps-1)
@@ -137,6 +168,16 @@
pl_surround.filter_coefs_surround = calc_coefficients_7kHz_lowpass(pl_surround.rate);
//dump_filter_coefficients(pl_surround.filter_coefs_surround);
//testfilter(pl_surround.filter_coefs_surround, 32, pl_surround.rate);
+
+ pl_surround.lowp_cutoff = 7000;
+ if (pl_surround.lowp_cutoff > pl_surround.rate / 2) {
+ // Cutoff rate must be < sample rate / 2 (Nyquist rate)
+ pl_surround.lowp_cutoff = pl_surround.rate / 2 - 1;
+ }
+ pl_surround.lowp_B = exp ((-2.0 * M_PI * (pl_surround.lowp_cutoff / pl_surround.rate)));
+ pl_surround.lowp_A = 1 - pl_surround.lowp_B;
+ pl_surround.lowp_outm1 = 0.0;
+
return 1;
}
@@ -161,6 +202,7 @@
pl_surround.delaybuf_pos = 0;
memset(pl_surround.Ls_delaybuf, 0, sizeof(int16_t)*pl_surround.delaybuf_len);
memset(pl_surround.Rs_delaybuf, 0, sizeof(int16_t)*pl_surround.delaybuf_len);
+ pl_surround.lowp_outm1 = 0;
}
// The beginnings of an active matrix...
@@ -181,11 +223,11 @@
if (pl_surround.passthrough) return 1;
- // fprintf(stderr, "pl_surround: play %d bytes, %d samples\n", ao_plugin_data.len, samples);
samples = ao_plugin_data.len / sizeof(int16_t) / pl_surround.input_channels;
out = pl_surround.databuf; in = (int16_t *)ao_plugin_data.data;
+ fprintf(stderr, "pl_surround: play %d bytes, %d samples\n", ao_plugin_data.len, samples);
// Testing - place a 1kHz tone on Lt and Rt in anti-phase: should decode in S
//sinewave(in, samples, pl_surround.input_channels, 1000, 0.0, pl_surround.rate);
//sinewave(&in[1], samples, pl_surround.input_channels, 1000, PI, pl_surround.rate);
@@ -222,6 +264,26 @@
#else
out[3] = -out[2];
#endif
+ if (pl_surround.output_channels == 6) {
+
+ int32_t avg;
+ double d;
+ avg = (out[0] + out[1]) / 2;
+
+ d = pl_surround.lowp_A * avg + pl_surround.lowp_B * pl_surround.lowp_outm1;
+
+ if (d > 32767L) {
+ d = 32767L;
+ }
+ if (d < -32768L) {
+ d = -32768L;
+ }
+ pl_surround.lowp_outm1 = d;
+ out[5] = d;
+ // Only 4.1 output, center speaker remains silent
+ out[4] = 0;
+ }
+
// calculate and save surround for 20msecs time
#ifdef SPLITREAR
pl_surround.Ls_delaybuf[pl_surround.delaybuf_pos] =
@@ -235,7 +297,7 @@
pl_surround.delaybuf_pos %= pl_surround.delaybuf_len;
// next samples...
- in = &in[pl_surround.input_channels]; out = &out[4];
+ in = &in[pl_surround.input_channels]; out = &out[pl_surround.output_channels];
}
// Show some state
@@ -243,6 +305,6 @@
// Set output block/len
ao_plugin_data.data=pl_surround.databuf;
- ao_plugin_data.len=samples*sizeof(int16_t)*4;
+ ao_plugin_data.len=samples*sizeof(int16_t)*pl_surround.output_channels;
return 1;
}
? libavcodec/.depend
? libavcodec/README.MPlayer
More information about the MPlayer-dev-eng
mailing list