2
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License as published by
4
* the Free Software Foundation; either version 2 of the License, or
5
* (at your option) any later version.
7
* This program is distributed in the hope that it will be useful,
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* GNU Library General Public License for more details.
12
* You should have received a copy of the GNU General Public License
13
* along with this program; if not, write to the Free Software
14
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
static int freq_fact, fd = -1, mixer_fd = -1, mixer_src = -1;
20
static char *devices[] = SOUND_DEVICE_NAMES;
23
* These functions handle the mixer device
26
int mixer_init(char *mixer_device, char *mixer_source)
32
for (i=0;i<SOUND_MIXER_NRDEVICES;i++)
33
if (strcmp(mixer_source, devices[i]) == 0)
36
mixer_fd = open(mixer_device, O_RDWR);
46
char* mixer_get_sndcard_name(void)
51
if (ioctl(mixer_fd, SOUND_MIXER_INFO, &info) == -1)
54
result = strdup(info.name);
59
char** mixer_get_rec_devices(void)
61
int i, o, devmask, res;
64
if ((ioctl(mixer_fd, SOUND_MIXER_READ_RECMASK, &devmask)) == -1)
68
result = malloc(sizeof(char*)*SOUND_MIXER_NRDEVICES);
70
for (i=0;i<SOUND_MIXER_NRDEVICES;i++)
72
res = (devmask >> i)%2;
75
result[o] = malloc(strlen(devices[i])+1);
76
sprintf(result[o], "%s", devices[i]);
85
int mixer_set_rec_device(void)
95
if ((ioctl(mixer_fd, SOUND_MIXER_READ_RECMASK, &devmask)) == -1)
98
recmask = 1 << mixer_src;
99
if (!(recmask & devmask))
102
if ((ioctl(mixer_fd, SOUND_MIXER_WRITE_RECSRC, &recmask)) == -1)
108
int mixer_close(void)
116
int mixer_set_volume(int volume)
122
assert(volume <= 100);
130
i_vol += volume << 8;
132
//printf("Setting %s to vol %i\n", devices[mixer_src], volume);
133
if ((ioctl(mixer_fd, MIXER_WRITE(mixer_src), &i_vol)) < 0)
139
int mixer_get_volume(void)
141
int i_vol = 0, r, l, volume;
149
if ((ioctl(mixer_fd, MIXER_READ(mixer_src), &i_vol)) < 0)
153
l = i_vol % (1 << 8);
155
//printf("%d %d %d %d\n", r, l, volume, i_vol);
157
assert((volume >= 0) && (volume <= 100));
163
* These functions handle the radio device
166
int radio_init(char *device)
168
struct video_tuner tuner;
170
if ((fd = open(device, O_RDONLY))< 0)
174
if (ioctl (fd, VIDIOCGTUNER, &tuner) < 0)
178
if ((tuner.flags & VIDEO_TUNER_LOW) == 0)
191
void radio_stop(void)
199
int radio_setfreq(float freq)
201
int ifreq = (freq+1.0/32)*freq_fact;
206
printf("Setting to %i (= %.2f)\n", ifreq, freq);
209
if ((freq > 108) || (freq < 65))
212
assert ((freq <= 108) && (freq > 65));
214
return ioctl(fd, VIDIOCSFREQ, &ifreq);
217
void radio_unmute(void)
219
struct video_audio vid_aud;
224
if (ioctl(fd, VIDIOCGAUDIO, &vid_aud))
225
perror("VIDIOCGAUDIO");
226
//if (vid_aud.volume == 0)
227
vid_aud.volume = 0xFFFF;
228
vid_aud.flags &= ~VIDEO_AUDIO_MUTE;
229
vid_aud.mode = VIDEO_SOUND_STEREO;
231
if (ioctl(fd, VIDIOCSAUDIO, &vid_aud))
232
perror("VIDIOCSAUDIO");
235
void radio_mute(void)
237
struct video_audio vid_aud;
242
if (ioctl(fd, VIDIOCGAUDIO, &vid_aud))
243
perror("VIDIOCGAUDIO");
244
vid_aud.flags |= VIDEO_AUDIO_MUTE;
245
if (ioctl(fd, VIDIOCSAUDIO, &vid_aud))
246
perror("VIDIOCSAUDIO");
249
int radio_getstereo()
251
struct video_audio va;
257
if (ioctl (fd, VIDIOCGAUDIO, &va) < 0)
259
if (va.mode == VIDEO_SOUND_STEREO)
265
int radio_getsignal()
267
struct video_tuner vt;
273
memset(&vt,0,sizeof(vt));
274
ioctl (fd, VIDIOCGTUNER, &vt);
275
signal=vt.signal>>13;