Mercurial > pidgin
annotate src/mediastreamer/msosswrite.c @ 12029:1c771536a032
[gaim-migrate @ 14322]
This _compiles_ for me now. Theres still a bunch of "dereferencing type-punned pointer will break strict-aliasing rules" warning and some redefinition warnings from the various config.h's. The deferencing warnings look like a BE<->LE hack but I left them untouched for the time being.
committer: Tailor Script <tailor@pidgin.im>
author | Gary Kramlich <grim@reaperworld.com> |
---|---|
date | Wed, 09 Nov 2005 09:57:33 +0000 |
parents | e67993da8a22 |
children |
rev | line source |
---|---|
12024 | 1 /* |
2 The mediastreamer library aims at providing modular media processing and I/O | |
3 for linphone, but also for any telephony application. | |
4 Copyright (C) 2001 Simon MORLAT simon.morlat@linphone.org | |
5 | |
6 This library is free software; you can redistribute it and/or | |
7 modify it under the terms of the GNU Lesser General Public | |
8 License as published by the Free Software Foundation; either | |
9 version 2.1 of the License, or (at your option) any later version. | |
10 | |
11 This library 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 GNU | |
14 Lesser General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU Lesser General Public | |
17 License along with this library; if not, write to the Free Software | |
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 */ | |
20 | |
21 #include "msosswrite.h" | |
22 #include "mssync.h" | |
23 #include <unistd.h> | |
24 #include <math.h> | |
25 | |
26 MSFilterInfo oss_write_info={ | |
27 "OSS write", | |
28 0, | |
29 MS_FILTER_OTHER, | |
30 ms_oss_write_new, | |
31 NULL | |
32 }; | |
33 | |
34 | |
35 static MSOssWriteClass *msosswriteclass=NULL; | |
36 | |
37 MSFilter * ms_oss_write_new() | |
38 { | |
39 MSOssWrite *w; | |
40 | |
41 if (msosswriteclass==NULL) | |
42 { | |
43 msosswriteclass=g_new(MSOssWriteClass,1); | |
44 ms_oss_write_class_init( msosswriteclass ); | |
45 } | |
46 w=g_new(MSOssWrite,1); | |
47 MS_FILTER(w)->klass=MS_FILTER_CLASS(msosswriteclass); | |
48 ms_oss_write_init(w); | |
49 return(MS_FILTER(w)); | |
50 } | |
51 | |
52 /* FOR INTERNAL USE*/ | |
53 void ms_oss_write_init(MSOssWrite *w) | |
54 { | |
55 ms_sound_write_init(MS_SOUND_WRITE(w)); | |
56 MS_FILTER(w)->infifos=w->f_inputs; | |
57 MS_FILTER(w)->infifos[0]=NULL; | |
58 MS_FILTER(w)->r_mingran=512; /* very few cards can do that...*/ | |
59 w->devid=0; | |
60 w->sndcard=NULL; | |
61 w->freq=8000; | |
62 w->channels=1; | |
63 w->dtmf_time=-1; | |
64 } | |
65 | |
66 gint ms_oss_write_set_property(MSOssWrite *f,MSFilterProperty prop, void *value) | |
67 { | |
68 switch(prop){ | |
69 case MS_FILTER_PROPERTY_FREQ: | |
70 f->freq=((gint*)value)[0]; | |
71 break; | |
72 case MS_FILTER_PROPERTY_CHANNELS: | |
73 f->channels=((gint*)value)[0]; | |
74 break; | |
12029
1c771536a032
[gaim-migrate @ 14322]
Gary Kramlich <grim@reaperworld.com>
parents:
12024
diff
changeset
|
75 case MS_FILTER_PROPERTY_BITRATE: |
1c771536a032
[gaim-migrate @ 14322]
Gary Kramlich <grim@reaperworld.com>
parents:
12024
diff
changeset
|
76 case MS_FILTER_PROPERTY_FMTP: |
1c771536a032
[gaim-migrate @ 14322]
Gary Kramlich <grim@reaperworld.com>
parents:
12024
diff
changeset
|
77 default: |
1c771536a032
[gaim-migrate @ 14322]
Gary Kramlich <grim@reaperworld.com>
parents:
12024
diff
changeset
|
78 break; |
12024 | 79 } |
80 return 0; | |
81 } | |
82 | |
83 void ms_oss_write_class_init(MSOssWriteClass *klass) | |
84 { | |
85 ms_sound_write_class_init(MS_SOUND_WRITE_CLASS(klass)); | |
86 MS_FILTER_CLASS(klass)->max_finputs=1; /* one fifo input only */ | |
87 MS_FILTER_CLASS(klass)->r_maxgran=MS_OSS_WRITE_DEF_GRAN; | |
88 MS_FILTER_CLASS(klass)->process= (MSFilterProcessFunc)ms_oss_write_process; | |
89 MS_FILTER_CLASS(klass)->destroy= (MSFilterDestroyFunc)ms_oss_write_destroy; | |
90 MS_FILTER_CLASS(klass)->setup= (MSFilterSetupFunc)ms_oss_write_setup; | |
91 MS_FILTER_CLASS(klass)->unsetup= (MSFilterSetupFunc)ms_oss_write_stop; | |
92 MS_FILTER_CLASS(klass)->set_property=(MSFilterPropertyFunc)ms_oss_write_set_property; | |
93 MS_FILTER_CLASS(klass)->info=&oss_write_info; | |
94 MS_SOUND_WRITE_CLASS(klass)->set_device=(gint (*)(MSSoundWrite*,gint))ms_oss_write_set_device; | |
95 MS_SOUND_WRITE_CLASS(klass)->start=(void (*)(MSSoundWrite*))ms_oss_write_start; | |
96 MS_SOUND_WRITE_CLASS(klass)->stop=(void (*)(MSSoundWrite*))ms_oss_write_stop; | |
97 MS_SOUND_WRITE_CLASS(klass)->set_level=(void (*)(MSSoundWrite*, gint))ms_oss_write_set_level; | |
98 ms_filter_class_set_name(MS_FILTER_CLASS(klass),"OssWrite"); | |
99 } | |
100 | |
101 void ms_oss_write_destroy( MSOssWrite *obj) | |
102 { | |
103 | |
104 g_free(obj); | |
105 } | |
106 | |
107 void ms_oss_write_process(MSOssWrite *f) | |
108 { | |
109 MSFifo *fifo; | |
110 void *p; | |
111 int i; | |
112 gint gran=ms_filter_get_mingran(MS_FILTER(f)); | |
113 | |
114 /* always consume something */ | |
115 fifo=f->f_inputs[0]; | |
116 ms_fifo_get_read_ptr(fifo,gran,&p); | |
117 if (p==NULL) { | |
118 g_warning("Not enough data: gran=%i.",gran); | |
119 return; | |
120 } | |
121 g_return_if_fail(f->sndcard!=NULL); | |
122 if (f->dtmf_time!=-1){ | |
123 gint16 *buf=(gint16*)p; | |
124 /* generate a DTMF*/ | |
125 for(i=0;i<gran/2;i++){ | |
126 buf[i]=(gint16)(10000.0*sin(2*M_PI*(double)f->dtmf_time*f->lowfreq)); | |
127 buf[i]+=(gint16)(10000.0*sin(2*M_PI*(double)f->dtmf_time*f->highfreq)); | |
128 f->dtmf_time++; | |
129 //printf("buf[%i]=%i\n",i,buf[i]); | |
130 } | |
131 if (f->dtmf_time>f->dtmf_duration) f->dtmf_time=-1; /*finished*/ | |
132 } | |
133 snd_card_write(f->sndcard,p,gran); | |
134 } | |
135 | |
136 void ms_oss_write_start(MSOssWrite *w) | |
137 { | |
12029
1c771536a032
[gaim-migrate @ 14322]
Gary Kramlich <grim@reaperworld.com>
parents:
12024
diff
changeset
|
138 /* gint bsize; */ |
12024 | 139 g_return_if_fail(w->devid!=-1); |
140 w->sndcard=snd_card_manager_get_card(snd_card_manager,w->devid); | |
141 g_return_if_fail(w->sndcard!=NULL); | |
142 /* open the device for an audio telephony signal with minimum latency */ | |
143 snd_card_open_w(w->sndcard,16,w->channels==2,w->freq); | |
144 w->bsize=snd_card_get_bsize(w->sndcard); | |
12029
1c771536a032
[gaim-migrate @ 14322]
Gary Kramlich <grim@reaperworld.com>
parents:
12024
diff
changeset
|
145 /* |
1c771536a032
[gaim-migrate @ 14322]
Gary Kramlich <grim@reaperworld.com>
parents:
12024
diff
changeset
|
146 MS_FILTER(w)->r_mingran=w->bsize; |
1c771536a032
[gaim-migrate @ 14322]
Gary Kramlich <grim@reaperworld.com>
parents:
12024
diff
changeset
|
147 ms_sync_set_samples_per_tick(MS_FILTER(w)->sync,bsize); |
1c771536a032
[gaim-migrate @ 14322]
Gary Kramlich <grim@reaperworld.com>
parents:
12024
diff
changeset
|
148 */ |
12024 | 149 } |
150 | |
151 void ms_oss_write_stop(MSOssWrite *w) | |
152 { | |
153 g_return_if_fail(w->devid!=-1); | |
154 g_return_if_fail(w->sndcard!=NULL); | |
155 snd_card_close_w(w->sndcard); | |
156 w->sndcard=NULL; | |
157 } | |
158 | |
159 void ms_oss_write_set_level(MSOssWrite *w,gint a) | |
160 { | |
161 | |
162 } | |
163 | |
164 gint ms_oss_write_set_device(MSOssWrite *w, gint devid) | |
165 { | |
166 w->devid=devid; | |
167 return 0; | |
168 } | |
169 | |
170 void ms_oss_write_setup(MSOssWrite *r) | |
171 { | |
172 //g_message("starting MSOssWrite.."); | |
173 ms_oss_write_start(r); | |
174 } | |
175 | |
176 | |
177 | |
178 void ms_oss_write_play_dtmf(MSOssWrite *w, char dtmf){ | |
179 | |
180 w->dtmf_duration=0.1*w->freq; | |
181 switch(dtmf){ | |
182 case '0': | |
183 w->lowfreq=941; | |
184 w->highfreq=1336; | |
185 break; | |
186 case '1': | |
187 w->lowfreq=697; | |
188 w->highfreq=1209; | |
189 break; | |
190 case '2': | |
191 w->lowfreq=697; | |
192 w->highfreq=1336; | |
193 break; | |
194 case '3': | |
195 w->lowfreq=697; | |
196 w->highfreq=1477; | |
197 break; | |
198 case '4': | |
199 w->lowfreq=770; | |
200 w->highfreq=1209; | |
201 break; | |
202 case '5': | |
203 w->lowfreq=770; | |
204 w->highfreq=1336; | |
205 break; | |
206 case '6': | |
207 w->lowfreq=770; | |
208 w->highfreq=1477; | |
209 break; | |
210 case '7': | |
211 w->lowfreq=852; | |
212 w->highfreq=1209; | |
213 break; | |
214 case '8': | |
215 w->lowfreq=852; | |
216 w->highfreq=1336; | |
217 break; | |
218 case '9': | |
219 w->lowfreq=852; | |
220 w->highfreq=1477; | |
221 break; | |
222 case '*': | |
223 w->lowfreq=941; | |
224 w->highfreq=1209; | |
225 break; | |
226 case '#': | |
227 w->lowfreq=941; | |
228 w->highfreq=1477; | |
229 break; | |
230 case 'A': | |
231 w->lowfreq=697; | |
232 w->highfreq=1633; | |
233 break; | |
234 case 'B': | |
235 w->lowfreq=770; | |
236 w->highfreq=1633; | |
237 break; | |
238 case 'C': | |
239 w->lowfreq=852; | |
240 w->highfreq=1633; | |
241 break; | |
242 case 'D': | |
243 w->lowfreq=941; | |
244 w->highfreq=1633; | |
245 break; | |
246 default: | |
247 g_warning("Not a dtmf key."); | |
248 return; | |
249 } | |
250 w->lowfreq=w->lowfreq/w->freq; | |
251 w->highfreq=w->highfreq/w->freq; | |
252 w->dtmf_time=0; | |
253 } |