23
23
#include <sys/ioctl.h>
24
24
#include <assert.h>
26
#include <linux/videodev.h>
27
26
#include <sys/soundcard.h>
31
static int freq_fact, fd = -1, mixer_fd = -1, mixer_src = -1;
30
static int mixer_fd = -1, mixer_src = -1;
32
31
static char *devices[] = SOUND_DEVICE_NAMES;
175
* These functions handle the radio device
178
int radio_init(char *device)
180
struct video_tuner tuner;
182
if ((fd = open(device, O_RDONLY))< 0)
186
if (ioctl (fd, VIDIOCGTUNER, &tuner) < 0)
190
if ((tuner.flags & VIDEO_TUNER_LOW) == 0)
201
int radio_is_init(void)
206
void radio_stop(void)
214
int radio_setfreq(float freq)
216
int ifreq = (freq+1.0/32)*freq_fact;
221
printf("Setting to %i (= %.2f)\n", ifreq, freq);
224
if ((freq > 108) || (freq < 65))
227
assert ((freq <= 108) && (freq > 65));
229
return ioctl(fd, VIDIOCSFREQ, &ifreq);
232
int radio_check_station(float freq)
238
signal = radio_getsignal();
243
if ((a + b + signal > 8) && (fabsf(freq - last) > 0.25f)) {
254
void radio_unmute(void)
256
struct video_audio vid_aud;
261
if (ioctl(fd, VIDIOCGAUDIO, &vid_aud))
262
perror("VIDIOCGAUDIO");
263
/*if (vid_aud.volume == 0)*/
264
vid_aud.volume = 0xFFFF;
265
vid_aud.flags &= ~VIDEO_AUDIO_MUTE;
266
vid_aud.mode = VIDEO_SOUND_STEREO;
268
if (ioctl(fd, VIDIOCSAUDIO, &vid_aud))
269
perror("VIDIOCSAUDIO");
272
void radio_mute(void)
274
struct video_audio vid_aud;
279
if (ioctl(fd, VIDIOCGAUDIO, &vid_aud))
280
perror("VIDIOCGAUDIO");
281
vid_aud.flags |= VIDEO_AUDIO_MUTE;
282
if (ioctl(fd, VIDIOCSAUDIO, &vid_aud))
283
perror("VIDIOCSAUDIO");
286
int radio_getstereo()
288
struct video_audio va;
294
if (ioctl (fd, VIDIOCGAUDIO, &va) < 0)
296
if (va.mode == VIDEO_SOUND_STEREO)
302
int radio_getsignal()
304
struct video_tuner vt;
310
memset(&vt,0,sizeof(vt));
311
ioctl (fd, VIDIOCGTUNER, &vt);
312
signal=vt.signal>>13;