annotate libaf/af_channels.c @ 8208:ae5a2ae1c349

demuxer_control(), percent position and time length query implemented in asf, avi, mpeg demuxers. patch by Balatoni Denes <pnis@coder.hu>
author arpi
date Sat, 16 Nov 2002 03:42:14 +0000
parents e8832e66babd
children d6f40a06867b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
1 /* Audio filter that adds and removes channels, according to the
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
2 command line parameter channels. It is stupid and can only add
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
3 silence or copy channels not mix or filter.
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
4 */
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
5 #include <stdio.h>
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
6 #include <stdlib.h>
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
7 #include <string.h>
7570
a0bba1b6c458 FreeBSD fix
nexus
parents: 7568
diff changeset
8 #include <unistd.h>
7975
6e03baea602f Adding compile problem fix from Gabucino
anders
parents: 7615
diff changeset
9 #include <inttypes.h>
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
10
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
11 #include "af.h"
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
12
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
13 // Local function for copying data
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
14 void copy(void* in, void* out, int ins, int inos,int outs, int outos, int len, int bps)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
15 {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
16 switch(bps){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
17 case 1:{
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
18 int8_t* tin = (int8_t*)in;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
19 int8_t* tout = (int8_t*)out;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
20 tin += inos;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
21 tout += outos;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
22 len = len/ins;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
23 while(len--){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
24 *tout=*tin;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
25 tin +=ins;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
26 tout+=outs;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
27 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
28 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
29 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
30 case 2:{
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
31 int16_t* tin = (int16_t*)in;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
32 int16_t* tout = (int16_t*)out;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
33 tin += inos;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
34 tout += outos;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
35 len = len/(2*ins);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
36 while(len--){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
37 *tout=*tin;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
38 tin +=ins;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
39 tout+=outs;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
40 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
41 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
42 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
43 case 4:{
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
44 int32_t* tin = (int32_t*)in;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
45 int32_t* tout = (int32_t*)out;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
46 tin += inos;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
47 tout += outos;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
48 len = len/(4*ins);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
49 while(len--){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
50 *tout=*tin;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
51 tin +=ins;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
52 tout+=outs;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
53 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
54 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
55 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
56 case 8:{
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
57 int64_t* tin = (int64_t*)in;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
58 int64_t* tout = (int64_t*)out;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
59 tin += inos;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
60 tout += outos;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
61 len = len/(8*ins);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
62 while(len--){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
63 *tout=*tin;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
64 tin +=ins;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
65 tout+=outs;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
66 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
67 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
68 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
69 default:
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
70 af_msg(AF_MSG_ERROR,"[channels] Unsupported number of bytes/sample: %i please report this error on the MPlayer mailing list. \n",bps);
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
71 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
72 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
73
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
74 // Initialization and runtime control
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
75 static int control(struct af_instance_s* af, int cmd, void* arg)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
76 {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
77 switch(cmd){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
78 case AF_CONTROL_REINIT:
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
79 // Make sure this filter isn't redundant
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
80 if(af->data->nch == ((af_data_t*)arg)->nch)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
81 return AF_DETACH;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
82
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
83 af->data->rate = ((af_data_t*)arg)->rate;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
84 af->data->format = ((af_data_t*)arg)->format;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
85 af->data->bps = ((af_data_t*)arg)->bps;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
86 af->mul.n = af->data->nch;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
87 af->mul.d = ((af_data_t*)arg)->nch;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
88 return AF_OK;
7998
d48a06d07afb Adding commandline options for filters and fixing stupid bug in cfg
anders
parents: 7975
diff changeset
89 case AF_CONTROL_COMMAND_LINE:{
d48a06d07afb Adding commandline options for filters and fixing stupid bug in cfg
anders
parents: 7975
diff changeset
90 int nch = 0;
d48a06d07afb Adding commandline options for filters and fixing stupid bug in cfg
anders
parents: 7975
diff changeset
91 sscanf((char*)arg,"%i",&nch);
d48a06d07afb Adding commandline options for filters and fixing stupid bug in cfg
anders
parents: 7975
diff changeset
92 return af->control(af,AF_CONTROL_CHANNELS,&nch);
d48a06d07afb Adding commandline options for filters and fixing stupid bug in cfg
anders
parents: 7975
diff changeset
93 }
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
94 case AF_CONTROL_CHANNELS:
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
95 // Reinit must be called after this function has been called
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
96
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
97 // Sanity check
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
98 if(((int*)arg)[0] <= 0 || ((int*)arg)[0] > 6){
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
99 af_msg(AF_MSG_ERROR,"[channels] The number of output channels must be between 1 and 6. Current value is%i \n",((int*)arg)[0]);
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
100 return AF_ERROR;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
101 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
102
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
103 af->data->nch=((int*)arg)[0];
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
104 af_msg(AF_MSG_VERBOSE,"[channels] Changing number of channels to %i\n",af->data->nch);
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
105 return AF_OK;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
106 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
107 return AF_UNKNOWN;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
108 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
109
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
110 // Deallocate memory
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
111 static void uninit(struct af_instance_s* af)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
112 {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
113 if(af->data)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
114 free(af->data);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
115 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
116
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
117 // Filter data through filter
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
118 static af_data_t* play(struct af_instance_s* af, af_data_t* data)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
119 {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
120 af_data_t* c = data; // Current working data
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
121 af_data_t* l = af->data; // Local data
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
122
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
123 if(AF_OK != RESIZE_LOCAL_BUFFER(af,data))
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
124 return NULL;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
125
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
126 // Reset unused channels if nch in < nch out
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
127 if(af->mul.n > af->mul.d)
7590
0cba73469341 Fixing the fix buffer overrun should work now
anders
parents: 7589
diff changeset
128 memset(l->audio,0,(c->len*af->mul.n)/af->mul.d);
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
129
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
130 // Special case always output L & R
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
131 if(c->nch == 1){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
132 copy(c->audio,l->audio,1,0,l->nch,0,c->len,c->bps);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
133 copy(c->audio,l->audio,1,0,l->nch,1,c->len,c->bps);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
134 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
135 else{
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
136 int i;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
137 if(l->nch < c->nch){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
138 for(i=0;i<l->nch;i++) // Truncates R if l->nch == 1 not good need mixing
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
139 copy(c->audio,l->audio,c->nch,i,l->nch,i,c->len,c->bps);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
140 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
141 else{
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
142 for(i=0;i<c->nch;i++)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
143 copy(c->audio,l->audio,c->nch,i,l->nch,i,c->len,c->bps);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
144 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
145 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
146
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
147 // Set output data
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
148 c->audio = l->audio;
7590
0cba73469341 Fixing the fix buffer overrun should work now
anders
parents: 7589
diff changeset
149 c->len = (c->len*af->mul.n)/af->mul.d;
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
150 c->nch = l->nch;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
151
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
152 return c;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
153 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
154
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
155 // Allocate memory and set function pointers
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
156 static int open(af_instance_t* af){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
157 af->control=control;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
158 af->uninit=uninit;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
159 af->play=play;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
160 af->mul.n=1;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
161 af->mul.d=1;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
162 af->data=calloc(1,sizeof(af_data_t));
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
163 if(af->data == NULL)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
164 return AF_ERROR;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
165 return AF_OK;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
166 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
167
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
168 // Description of this filter
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
169 af_info_t af_info_channels = {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
170 "Insert or remove channels",
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
171 "channels",
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
172 "Anders",
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
173 "",
7615
c67328dd459a Adding Support for non-reentrant audio filters
anders
parents: 7590
diff changeset
174 AF_FLAGS_REENTRANT,
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
175 open
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
176 };