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
)
91 // Filter data through filter
92 static af_data_t
* play_s16(struct af_instance_s
* af
, af_data_t
* data
)
94 af_extrastereo_t
*s
= af
->setup
;
96 int16_t *a
= (int16_t*)data
->audio
; // Audio data
97 int len
= data
->len
/2; // Number of samples
100 for (i
= 0; i
< len
; i
+=2)
102 avg
= (a
[i
] + a
[i
+ 1]) / 2;
104 l
= avg
+ (int)(s
->mul
* (a
[i
] - avg
));
105 r
= avg
+ (int)(s
->mul
* (a
[i
+ 1] - avg
));
107 a
[i
] = clamp(l
, SHRT_MIN
, SHRT_MAX
);
108 a
[i
+ 1] = clamp(r
, SHRT_MIN
, SHRT_MAX
);
114 static af_data_t
* play_float(struct af_instance_s
* af
, af_data_t
* data
)
116 af_extrastereo_t
*s
= af
->setup
;
118 float *a
= (float*)data
->audio
; // Audio data
119 int len
= data
->len
/4; // Number of samples
122 for (i
= 0; i
< len
; i
+=2)
124 avg
= (a
[i
] + a
[i
+ 1]) / 2;
126 l
= avg
+ (s
->mul
* (a
[i
] - avg
));
127 r
= avg
+ (s
->mul
* (a
[i
+ 1] - avg
));
129 a
[i
] = af_softclip(l
);
130 a
[i
+ 1] = af_softclip(r
);
136 // Allocate memory and set function pointers
137 static int af_open(af_instance_t
* af
){
142 af
->data
=calloc(1,sizeof(af_data_t
));
143 af
->setup
=calloc(1,sizeof(af_extrastereo_t
));
144 if(af
->data
== NULL
|| af
->setup
== NULL
)
147 ((af_extrastereo_t
*)af
->setup
)->mul
= 2.5;
151 // Description of this filter
152 af_info_t af_info_extrastereo
= {
155 "Alex Beregszaszi & Pierre Lombard",
157 AF_FLAGS_NOT_REENTRANT
,