Mercurial > mplayer.hg
annotate libaf/af_center.c @ 30674:553f53cffabf
Reset output color after each line.
author | zuxy |
---|---|
date | Tue, 23 Feb 2010 06:42:51 +0000 |
parents | 0f1b5b68af32 |
children | 8fa2f43cb760 |
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 |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
32 #include "af.h" |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
33 |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
34 // 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
|
35 typedef struct af_center_s |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
36 { |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
37 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
|
38 }af_center_t; |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
39 |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
40 // Initialization and runtime control |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
41 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
|
42 { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
43 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
|
44 |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
45 switch(cmd){ |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
46 case AF_CONTROL_REINIT:{ |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
47 // Sanity check |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
48 if(!arg) return AF_ERROR; |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
49 |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
50 af->data->rate = ((af_data_t*)arg)->rate; |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
51 af->data->nch = max(s->ch+1,((af_data_t*)arg)->nch); |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
52 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
|
53 af->data->bps = 4; |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
54 |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
55 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
|
56 } |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
57 case AF_CONTROL_COMMAND_LINE:{ |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
58 int ch=1; |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
59 sscanf(arg,"%i", &ch); |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
60 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
|
61 } |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
62 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
|
63 // Sanity check |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
64 if((*(int*)arg >= AF_NCH) || (*(int*)arg < 0)){ |
29049 | 65 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
|
66 " 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
|
67 return AF_ERROR; |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
68 } |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
69 s->ch = *(int*)arg; |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
70 return AF_OK; |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
71 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
|
72 *(int*)arg = s->ch; |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
73 return AF_OK; |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
74 } |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
75 return AF_UNKNOWN; |
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 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29049
diff
changeset
|
78 // Deallocate memory |
14749
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
79 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
|
80 { |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
81 if(af->data) |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
82 free(af->data); |
ab617c2e24d3
filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff
changeset
|
83 if(af->setup) |
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 }; |