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
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.
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.
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
21
#include "msosswrite.h"
26
MSFilterInfo oss_write_info={
35
static MSOssWriteClass *msosswriteclass=NULL;
37
MSFilter * ms_oss_write_new()
41
if (msosswriteclass==NULL)
43
msosswriteclass=g_new(MSOssWriteClass,1);
44
ms_oss_write_class_init( msosswriteclass );
46
w=g_new(MSOssWrite,1);
47
MS_FILTER(w)->klass=MS_FILTER_CLASS(msosswriteclass);
53
void ms_oss_write_init(MSOssWrite *w)
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...*/
66
gint ms_oss_write_set_property(MSOssWrite *f,MSFilterProperty prop, void *value)
69
case MS_FILTER_PROPERTY_FREQ:
70
f->freq=((gint*)value)[0];
72
case MS_FILTER_PROPERTY_CHANNELS:
73
f->channels=((gint*)value)[0];
79
void ms_oss_write_class_init(MSOssWriteClass *klass)
81
ms_sound_write_class_init(MS_SOUND_WRITE_CLASS(klass));
82
MS_FILTER_CLASS(klass)->max_finputs=1; /* one fifo input only */
83
MS_FILTER_CLASS(klass)->r_maxgran=MS_OSS_WRITE_DEF_GRAN;
84
MS_FILTER_CLASS(klass)->process= (MSFilterProcessFunc)ms_oss_write_process;
85
MS_FILTER_CLASS(klass)->destroy= (MSFilterDestroyFunc)ms_oss_write_destroy;
86
MS_FILTER_CLASS(klass)->setup= (MSFilterSetupFunc)ms_oss_write_setup;
87
MS_FILTER_CLASS(klass)->unsetup= (MSFilterSetupFunc)ms_oss_write_stop;
88
MS_FILTER_CLASS(klass)->set_property=(MSFilterPropertyFunc)ms_oss_write_set_property;
89
MS_FILTER_CLASS(klass)->info=&oss_write_info;
90
MS_SOUND_WRITE_CLASS(klass)->set_device=(gint (*)(MSSoundWrite*,gint))ms_oss_write_set_device;
91
MS_SOUND_WRITE_CLASS(klass)->start=(void (*)(MSSoundWrite*))ms_oss_write_start;
92
MS_SOUND_WRITE_CLASS(klass)->stop=(void (*)(MSSoundWrite*))ms_oss_write_stop;
93
MS_SOUND_WRITE_CLASS(klass)->set_level=(void (*)(MSSoundWrite*, gint))ms_oss_write_set_level;
94
ms_filter_class_set_name(MS_FILTER_CLASS(klass),"OssWrite");
97
void ms_oss_write_destroy( MSOssWrite *obj)
103
void ms_oss_write_process(MSOssWrite *f)
108
gint gran=ms_filter_get_mingran(MS_FILTER(f));
110
/* always consume something */
112
ms_fifo_get_read_ptr(fifo,gran,&p);
114
g_warning("Not enough data: gran=%i.",gran);
117
g_return_if_fail(f->sndcard!=NULL);
118
if (f->dtmf_time!=-1){
119
gint16 *buf=(gint16*)p;
121
for(i=0;i<gran/2;i++){
122
buf[i]=(gint16)(10000.0*sin(2*M_PI*(double)f->dtmf_time*f->lowfreq));
123
buf[i]+=(gint16)(10000.0*sin(2*M_PI*(double)f->dtmf_time*f->highfreq));
125
//printf("buf[%i]=%i\n",i,buf[i]);
127
if (f->dtmf_time>f->dtmf_duration) f->dtmf_time=-1; /*finished*/
129
snd_card_write(f->sndcard,p,gran);
132
void ms_oss_write_start(MSOssWrite *w)
135
g_return_if_fail(w->devid!=-1);
136
w->sndcard=snd_card_manager_get_card(snd_card_manager,w->devid);
137
g_return_if_fail(w->sndcard!=NULL);
138
/* open the device for an audio telephony signal with minimum latency */
139
snd_card_open_w(w->sndcard,16,w->channels==2,w->freq);
140
w->bsize=snd_card_get_bsize(w->sndcard);
141
//MS_FILTER(w)->r_mingran=w->bsize;
142
//ms_sync_set_samples_per_tick(MS_FILTER(w)->sync,bsize);
145
void ms_oss_write_stop(MSOssWrite *w)
147
g_return_if_fail(w->devid!=-1);
148
g_return_if_fail(w->sndcard!=NULL);
149
snd_card_close_w(w->sndcard);
153
void ms_oss_write_set_level(MSOssWrite *w,gint a)
158
gint ms_oss_write_set_device(MSOssWrite *w, gint devid)
164
void ms_oss_write_setup(MSOssWrite *r)
166
//g_message("starting MSOssWrite..");
167
ms_oss_write_start(r);
172
void ms_oss_write_play_dtmf(MSOssWrite *w, char dtmf){
174
w->dtmf_duration=0.1*w->freq;
241
g_warning("Not a dtmf key.");
244
w->lowfreq=w->lowfreq/w->freq;
245
w->highfreq=w->highfreq/w->freq;