comparison libaf/af.c @ 32272:fd4cd29b6121

Automatic downmix using the pan filter when the requested channel count is 2 and the codec does not support it natively. Patch by Clment Bsch, ubitux gmail com
author cigaes
date Sun, 26 Sep 2010 08:45:40 +0000
parents b8cd2b5c4d35
children 71a04d45357c
comparison
equal deleted inserted replaced
32271:563b35a003b8 32272:fd4cd29b6121
19 #include "config.h" 19 #include "config.h"
20 #include <stdio.h> 20 #include <stdio.h>
21 #include <stdlib.h> 21 #include <stdlib.h>
22 #include <string.h> 22 #include <string.h>
23 #include "osdep/strsep.h" 23 #include "osdep/strsep.h"
24 #include "libmpcodecs/dec_audio.h"
24 25
25 #include "af.h" 26 #include "af.h"
26 27
27 // Static list of filters 28 // Static list of filters
28 extern const af_info_t af_info_dummy; 29 extern const af_info_t af_info_dummy;
410 return AF_ERROR; 411 return AF_ERROR;
411 } 412 }
412 return AF_OK; 413 return AF_OK;
413 } 414 }
414 415
416 /**
417 * Automatic downmix to stereo in case the codec does not implement it.
418 */
419 static void af_downmix(af_stream_t* s)
420 {
421 static const char * const downmix_strs[AF_NCH + 1] = {
422 /* FL FR RL RR FC LF AL AR */
423 [3] = "pan=2:" "0.6:0:" "0:0.6:" "0.4:0.4",
424 [4] = "pan=2:" "0.6:0:" "0:0.6:" "0.4:0:" "0:0.4",
425 [5] = "pan=2:" "0.5:0:" "0:0.5:" "0.2:0:" "0:0.2:" "0.3:0.3",
426 [6] = "pan=2:" "0.4:0:" "0:0.4:" "0.2:0:" "0:0.2:" "0.3:0.3:" "0.1:0.1",
427 [7] = "pan=2:" "0.4:0:" "0:0.4:" "0.2:0:" "0:0.2:" "0.3:0.3:" "0.1:0:" "0:0.1",
428 [8] = "pan=2:" "0.4:0:" "0:0.4:" "0.15:0:" "0:0.15:" "0.25:0.25:" "0.1:0.1:" "0.1:0:" "0:0.1",
429 };
430 const char *af_pan_str = downmix_strs[s->input.nch];
431
432 if (af_pan_str)
433 af_append(s, s->first, af_pan_str);
434 }
435
415 /* Initialize the stream "s". This function creates a new filter list 436 /* Initialize the stream "s". This function creates a new filter list
416 if necessary according to the values set in input and output. Input 437 if necessary according to the values set in input and output. Input
417 and output should contain the format of the current movie and the 438 and output should contain the format of the current movie and the
418 formate of the preferred output respectively. The function is 439 formate of the preferred output respectively. The function is
419 reentrant i.e. if called with an already initialized stream the 440 reentrant i.e. if called with an already initialized stream the
436 if(AF_INIT_AUTO == (AF_INIT_TYPE_MASK & s->cfg.force)) 457 if(AF_INIT_AUTO == (AF_INIT_TYPE_MASK & s->cfg.force))
437 s->cfg.force = (s->cfg.force & ~AF_INIT_TYPE_MASK) | AF_INIT_TYPE; 458 s->cfg.force = (s->cfg.force & ~AF_INIT_TYPE_MASK) | AF_INIT_TYPE;
438 459
439 // Check if this is the first call 460 // Check if this is the first call
440 if(!s->first){ 461 if(!s->first){
462 // Append a downmix pan filter at the beginning of the chain if needed
463 if (s->input.nch != audio_output_channels && audio_output_channels == 2)
464 af_downmix(s);
441 // Add all filters in the list (if there are any) 465 // Add all filters in the list (if there are any)
442 if (s->cfg.list) { 466 if (s->cfg.list) {
443 while(s->cfg.list[i]){ 467 while(s->cfg.list[i]){
444 if(!af_append(s,s->last,s->cfg.list[i++])) 468 if(!af_append(s,s->last,s->cfg.list[i++]))
445 return -1; 469 return -1;