wmclockmon: update change-log
[dockapps.git] / wmradio / radio.c
blobce93ab40e6c84d5b75bd060621922b7cf8536b38
1 /*
2 * Copyright (C) 12 Jun 2003 Tomas Cermak
4 * This file is part of wmradio program.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program 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
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <string.h>
25 #include <errno.h>
26 #include <fcntl.h>
27 #include <sys/time.h>
28 #include <sys/ioctl.h>
30 #include <linux/videodev.h>
32 char *device = "/dev/radio";
34 int get_freq_fact(int fd)
36 struct video_tuner tuner;
38 tuner.tuner = 0;
39 if (ioctl (fd, VIDIOCGTUNER, &tuner) < 0)
40 return 16;
41 if ((tuner.flags & VIDEO_TUNER_LOW) == 0)
42 return 16;
43 return 16000;
46 int radio_setfreq(int fd, int freq)
48 int ifreq = (freq/100.0+1.0/32.0)*get_freq_fact(fd);
49 return ioctl(fd, VIDIOCSFREQ, &ifreq);
52 void radio_unmute(int fd)
54 struct video_audio vid_aud;
56 if (ioctl(fd, VIDIOCGAUDIO, &vid_aud))
57 perror("VIDIOCGAUDIO");
58 if (vid_aud.volume == 0)
59 vid_aud.volume = 65535;
60 vid_aud.flags &= ~VIDEO_AUDIO_MUTE;
61 if (ioctl(fd, VIDIOCSAUDIO, &vid_aud))
62 perror("VIDIOCSAUDIO");
65 void radio_mute(int fd)
67 struct video_audio vid_aud;
69 if (ioctl(fd, VIDIOCGAUDIO, &vid_aud))
70 perror("VIDIOCGAUDIO");
71 vid_aud.flags |= VIDEO_AUDIO_MUTE;
72 if (ioctl(fd, VIDIOCSAUDIO, &vid_aud))
73 perror("VIDIOCSAUDIO");
76 int radio_getstereo(int fd)
78 struct video_audio va;
79 va.mode=-1;
80 if(ioctl(fd, VIDIOCGAUDIO, &va) < 0) return 0;
81 return va.mode == VIDEO_SOUND_STEREO ? 1 : 0;
84 int radio_getsignal(int fd)
86 struct video_tuner vt;
87 int signal;
89 memset(&vt,0,sizeof(vt));
90 ioctl (fd, VIDIOCGTUNER, &vt);
91 signal=vt.signal>>13;
93 return signal;