annotate libaf/af_center.c @ 35060:c5c8d88d612e

directx: Support negative panscanrange (i.e. zooming) for noaccel. All that is necessary is to skip the code clipping the destination rectangle.
author reimar
date Fri, 07 Sep 2012 19:27:44 +0000
parents a93891202051
children 2b9bc3c2933d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
34174
a93891202051 Add missing mp_msg.h #includes, remove some unnecessary ones.
diego
parents: 32537
diff changeset
32 #include "mp_msg.h"
14749
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
33 #include "af.h"
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
34
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
35 // 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
36 typedef struct af_center_s
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
37 {
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
38 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
39 }af_center_t;
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
40
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
41 // Initialization and runtime control
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
42 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
43 {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
44 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
45
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
46 switch(cmd){
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
47 case AF_CONTROL_REINIT:{
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
48 // Sanity check
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
49 if(!arg) return AF_ERROR;
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
50
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
51 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
52 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
53 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
54 af->data->bps = 4;
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
55
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
56 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
57 }
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
58 case AF_CONTROL_COMMAND_LINE:{
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
59 int ch=1;
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
60 sscanf(arg,"%i", &ch);
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
61 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
62 }
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
63 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
64 // Sanity check
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
65 if((*(int*)arg >= AF_NCH) || (*(int*)arg < 0)){
29049
8c706ce21c6f Remove af_msg special-casing API in libaf.
bircoph
parents: 28229
diff changeset
66 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
67 " 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
68 return AF_ERROR;
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
69 }
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
70 s->ch = *(int*)arg;
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
71 return AF_OK;
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
72 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
73 *(int*)arg = s->ch;
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
74 return AF_OK;
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
75 }
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
76 return AF_UNKNOWN;
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
77 }
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
78
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
79 // Deallocate memory
14749
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
80 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
81 {
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 free(af->setup);
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
84 }
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 // Filter data through filter
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
87 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
88 {
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
89 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
90 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
91 float* a = c->audio; // Audio data
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
92 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
93 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
94 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
95 register int i;
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
96
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
97 // Run filter
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
98 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
99 // Average left and right
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
100 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
101 }
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 return c;
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
104 }
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 // 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
107 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
108 af_center_t* s;
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
109 af->control=control;
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
110 af->uninit=uninit;
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
111 af->play=play;
24888
b2402b4f0afa libaf: change filter input/output ratio calculations
uau
parents: 22746
diff changeset
112 af->mul=1;
14749
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
113 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
114 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
115 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
116 return AF_ERROR;
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
117 // Set default values
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
118 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
119 return AF_OK;
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
120 }
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 // Description of this filter
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
123 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
124 "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
125 "center",
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
126 "Alex Beregszaszi",
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
127 "",
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
128 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
129 af_open
14749
ab617c2e24d3 filter for adding a center channel, adding a high pass filter would be nice
alex
parents:
diff changeset
130 };