2 * Copyright (C) 2004 Alex Beregszaszi & Pierre Lombard
4 * This file is part of MPlayer.
6 * MPlayer is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * MPlayer is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 // Data for specific instances of this filter
32 typedef struct af_extrastereo_s
37 static af_data_t
* play_s16(struct af_instance_s
* af
, af_data_t
* data
);
38 static af_data_t
* play_float(struct af_instance_s
* af
, af_data_t
* data
);
40 // Initialization and runtime control
41 static int control(struct af_instance_s
* af
, int cmd
, void* arg
)
43 af_extrastereo_t
* s
= (af_extrastereo_t
*)af
->setup
;
46 case AF_CONTROL_REINIT
:{
48 if(!arg
) return AF_ERROR
;
50 af
->data
->rate
= ((af_data_t
*)arg
)->rate
;
52 if (((af_data_t
*)arg
)->format
== AF_FORMAT_FLOAT_NE
)
54 af
->data
->format
= AF_FORMAT_FLOAT_NE
;
56 af
->play
= play_float
;
59 af
->data
->format
= AF_FORMAT_S16_NE
;
64 return af_test_output(af
,(af_data_t
*)arg
);
66 case AF_CONTROL_COMMAND_LINE
:{
68 sscanf((char*)arg
,"%f", &f
);
72 case AF_CONTROL_ES_MUL
| AF_CONTROL_SET
:
73 s
->mul
= *(float*)arg
;
75 case AF_CONTROL_ES_MUL
| AF_CONTROL_GET
:
76 *(float*)arg
= s
->mul
;
83 static void uninit(struct af_instance_s
* af
)
89 // Filter data through filter
90 static af_data_t
* play_s16(struct af_instance_s
* af
, af_data_t
* data
)
92 af_extrastereo_t
*s
= af
->setup
;
94 int16_t *a
= (int16_t*)data
->audio
; // Audio data
95 int len
= data
->len
/2; // Number of samples
98 for (i
= 0; i
< len
; i
+=2)
100 avg
= (a
[i
] + a
[i
+ 1]) / 2;
102 l
= avg
+ (int)(s
->mul
* (a
[i
] - avg
));
103 r
= avg
+ (int)(s
->mul
* (a
[i
+ 1] - avg
));
105 a
[i
] = clamp(l
, SHRT_MIN
, SHRT_MAX
);
106 a
[i
+ 1] = clamp(r
, SHRT_MIN
, SHRT_MAX
);
112 static af_data_t
* play_float(struct af_instance_s
* af
, af_data_t
* data
)
114 af_extrastereo_t
*s
= af
->setup
;
116 float *a
= (float*)data
->audio
; // Audio data
117 int len
= data
->len
/4; // Number of samples
120 for (i
= 0; i
< len
; i
+=2)
122 avg
= (a
[i
] + a
[i
+ 1]) / 2;
124 l
= avg
+ (s
->mul
* (a
[i
] - avg
));
125 r
= avg
+ (s
->mul
* (a
[i
+ 1] - avg
));
127 a
[i
] = af_softclip(l
);
128 a
[i
+ 1] = af_softclip(r
);
134 // Allocate memory and set function pointers
135 static int af_open(af_instance_t
* af
){
140 af
->data
=calloc(1,sizeof(af_data_t
));
141 af
->setup
=calloc(1,sizeof(af_extrastereo_t
));
142 if(af
->data
== NULL
|| af
->setup
== NULL
)
145 ((af_extrastereo_t
*)af
->setup
)->mul
= 2.5;
149 // Description of this filter
150 af_info_t af_info_extrastereo
= {
151 "Increase difference between audio channels",
153 "Alex Beregszaszi & Pierre Lombard",
155 AF_FLAGS_NOT_REENTRANT
,