Mercurial > mplayer.hg
annotate libaf/af_center.c @ 37080:0b0528ba3344
Add remove_vf().
(Currently unused, but we will need it soon.)
author | ib |
---|---|
date | Thu, 24 Apr 2014 13:51:20 +0000 |
parents | 2b9bc3c2933d |
children |
rev | line source |
---|---|
14749
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
1 /* |
28229
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
2 * This filter adds a center channel to the audio stream by |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
3 * averaging the left and right channel. |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
4 * There are two runtime controls one for setting which channel |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
5 * to insert the center-audio into called AF_CONTROL_SUB_CH. |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
6 * |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
7 * FIXME: implement a high-pass filter for better results. |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
8 * |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
9 * copyright (c) 2005 Alex Beregszaszi |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
10 * |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
11 * This file is part of MPlayer. |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
12 * |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
13 * MPlayer is free software; you can redistribute it and/or modify |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
14 * it under the terms of the GNU General Public License as published by |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
15 * the Free Software Foundation; either version 2 of the License, or |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
16 * (at your option) any later version. |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
17 * |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
18 * MPlayer is distributed in the hope that it will be useful, |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
21 * GNU General Public License for more details. |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
22 * |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
23 * You should have received a copy of the GNU General Public License along |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
24 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
24888
diff
changeset
|
26 */ |
14749
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
27 |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
28 #include <stdio.h> |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
29 #include <stdlib.h> |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
30 #include <string.h> |
14749
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
31 |
36395
2b9bc3c2933d
Remove some macros and switch to libavutil equivalents.
reimar
parents:
34174
diff
changeset
|
32 #include "libavutil/common.h" |
34174
a93891202051
Add missing mp_msg.h #includes, remove some unnecessary ones.
diego
parents:
32537
diff
changeset
|
33 #include "mp_msg.h" |
14749
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
34 #include "af.h" |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
35 |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
36 // Data for specific instances of this filter |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
37 typedef struct af_center_s |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
38 { |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
39 int ch; // Channel number which to insert the filtered data |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
40 }af_center_t; |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
41 |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
42 // Initialization and runtime control |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
43 static int control(struct af_instance_s* af, int cmd, void* arg) |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
44 { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
45 af_center_t* s = af->setup; |
14749
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
46 |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
47 switch(cmd){ |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
48 case AF_CONTROL_REINIT:{ |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
49 // Sanity check |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
50 if(!arg) return AF_ERROR; |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
51 |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
52 af->data->rate = ((af_data_t*)arg)->rate; |
36395
2b9bc3c2933d
Remove some macros and switch to libavutil equivalents.
reimar
parents:
34174
diff
changeset
|
53 af->data->nch = FFMAX(s->ch+1,((af_data_t*)arg)->nch); |
14749
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
54 af->data->format = AF_FORMAT_FLOAT_NE; |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
55 af->data->bps = 4; |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
56 |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
57 return af_test_output(af,(af_data_t*)arg); |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
58 } |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
59 case AF_CONTROL_COMMAND_LINE:{ |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
60 int ch=1; |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
61 sscanf(arg,"%i", &ch); |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
62 return control(af,AF_CONTROL_CENTER_CH | AF_CONTROL_SET, &ch); |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
63 } |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
64 case AF_CONTROL_CENTER_CH | AF_CONTROL_SET: // Requires reinit |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
65 // Sanity check |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
66 if((*(int*)arg >= AF_NCH) || (*(int*)arg < 0)){ |
29049 | 67 mp_msg(MSGT_AFILTER, MSGL_ERR, "[sub] Center channel number must be between " |
14749
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
68 " 0 and %i current value is %i\n", AF_NCH-1, *(int*)arg); |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
69 return AF_ERROR; |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
70 } |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
71 s->ch = *(int*)arg; |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
72 return AF_OK; |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
73 case AF_CONTROL_CENTER_CH | AF_CONTROL_GET: |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
74 *(int*)arg = s->ch; |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
75 return AF_OK; |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
76 } |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
77 return AF_UNKNOWN; |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
78 } |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
79 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
80 // Deallocate memory |
14749
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
81 static void uninit(struct af_instance_s* af) |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
82 { |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
83 free(af->data); |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
84 free(af->setup); |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
85 } |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
86 |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
87 // Filter data through filter |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
88 static af_data_t* play(struct af_instance_s* af, af_data_t* data) |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
89 { |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
90 af_data_t* c = data; // Current working data |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
91 af_center_t* s = af->setup; // Setup for this instance |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
92 float* a = c->audio; // Audio data |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
93 int len = c->len/4; // Number of samples in current audio block |
14749
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
94 int nch = c->nch; // Number of channels |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
95 int ch = s->ch; // Channel in which to insert the center audio |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
96 register int i; |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
97 |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
98 // Run filter |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
99 for(i=0;i<len;i+=nch){ |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
100 // Average left and right |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
101 a[i+ch] = (a[i]/2) + (a[i+1]/2); |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
102 } |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
103 |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
104 return c; |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
105 } |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
106 |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
107 // Allocate memory and set function pointers |
22746
fd6f824ef894
Rename open to af_open so as not to conflict with a previous header definition.
diego
parents:
14749
diff
changeset
|
108 static int af_open(af_instance_t* af){ |
14749
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
109 af_center_t* s; |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
110 af->control=control; |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
111 af->uninit=uninit; |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
112 af->play=play; |
24888 | 113 af->mul=1; |
14749
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
114 af->data=calloc(1,sizeof(af_data_t)); |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
115 af->setup=s=calloc(1,sizeof(af_center_t)); |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
116 if(af->data == NULL || af->setup == NULL) |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
117 return AF_ERROR; |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
118 // Set default values |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
119 s->ch = 1; // Channel nr 2 |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
120 return AF_OK; |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
121 } |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
122 |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
123 // Description of this filter |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
124 af_info_t af_info_center = { |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
125 "Audio filter for adding a center channel", |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
126 "center", |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
127 "Alex Beregszaszi", |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
128 "", |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
129 AF_FLAGS_NOT_REENTRANT, |
22746
fd6f824ef894
Rename open to af_open so as not to conflict with a previous header definition.
diego
parents:
14749
diff
changeset
|
130 af_open |
14749
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
131 }; |