2 Copyright 2004-2005 Chris Tallon
4 This file is part of VOMP.
6 VOMP 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 VOMP 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 VOMP; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 Audio* Audio::instance = NULL;
43 Audio* Audio::getInstance()
48 int Audio::init(UCHAR tstreamType)
50 if (initted) return 0;
53 // if ((fdAudio = open("/dev/adec_mpg", O_RDWR | O_NONBLOCK)) < 0) return 0;
54 if ((fdAudio = open("/dev/adec_mpg", O_WRONLY)) < 0) return 0;
56 streamType = tstreamType;
66 // Set the volume variable to what the hardware is set at now
68 int hwvolFail = ioctl(fdAudio, AV_GET_AUD_VOLUME, &hwvol);
71 volume = 20 - ((hwvol >> 16) & 0xFF);
72 if ((volume < 0) || (volume > 20)) volume = 20;
78 int Audio::initAllParams()
80 return (setStreamType(streamType) && setChannel() && setSource());
85 if (!initted) return 0;
93 if (!initted) return 0;
98 int Audio::write(char *buf, int len)
100 return 0; //write(fdAudio, buf, len);
103 int Audio::setStreamType(UCHAR type)
105 if (!initted) return 0;
107 if (ioctl(fdAudio, AV_SET_AUD_STREAMTYPE, type) != 0) return 0;
111 int Audio::setChannel()
113 if (!initted) return 0;
115 if (ioctl(fdAudio, AV_SET_AUD_CHANNEL, 0) != 0) return 0;
119 int Audio::setSource()
121 if (!initted) return 0;
123 if (ioctl(fdAudio, AV_SET_AUD_SRC, 1) != 0) return 0;
129 if (!initted) return 0;
131 if (ioctl(fdAudio, AV_SET_AUD_SYNC, 2) != 0) return 0;
137 if (!initted) return 0;
139 if (ioctl(fdAudio, AV_SET_AUD_PLAY, 0) != 0) return 0;
145 if (!initted) return 0;
147 if (ioctl(fdAudio, AV_SET_AUD_RESET, 0x11) != 0) return 0;
153 if (!initted) return 0;
155 if (ioctl(fdAudio, AV_SET_AUD_MUTE, 1) != 0) return 0;
156 Log::getInstance()->log("Audio", Log::DEBUG, "MUTE MUTE MUTE");
164 if (!initted) return 0;
166 if (ioctl(fdAudio, AV_SET_AUD_MUTE, 0) != 0) return 0;
167 Log::getInstance()->log("Audio", Log::DEBUG, "MUTE OFF OFF OFF");
175 if (!initted) return 0;
177 if (ioctl(fdAudio, AV_SET_AUD_PAUSE, 1) != 0) return 0;
183 if (!initted) return 0;
185 if (ioctl(fdAudio, AV_SET_AUD_UNPAUSE, 1) != 0) return 0;
191 if (!initted) return 0;
193 if (ioctl(fdAudio, AV_SET_AUD_RESET, 0x11) != 0) return 0;
194 if (ioctl(fdAudio, AV_SET_AUD_PLAY, 0) != 0) return 0;
200 int Audio::setVolume(int tvolume)
202 // parameter: 0 for silence, 20 for full
203 if ((tvolume < 0) || (tvolume > 20)) return 0;
205 // volume = 2 * (20 - volume);
206 // Right, that one was rubbish... 0-10 were almost
207 // inaudible, 11-20 did what should have been done
208 // over the whole 0-20 range
210 tvolume = 20 - tvolume;
212 unsigned long vol = (tvolume << 24) | (tvolume << 16);
214 Log::getInstance()->log("Audio", Log::DEBUG, "%lx", vol);
215 Log::getInstance()->log("Audio", Log::DEBUG, "%i", tvolume);
217 if (ioctl(fdAudio, AV_SET_AUD_VOLUME, &vol) != 0) return 0;
225 // return ioctl(fdAudio, AV_SET_AUD_STC, &stc);
231 int b = ioctl(fdAudio, AV_SET_AUD_DISABLE_SYNC, &a);
234 printf("Audio sync disable = %i\n", b); // is in a DEV block
242 int Audio::volumeUp()
244 if (!initted) return 0;
245 if (userMute) toggleUserMute();
246 if (volume == 20) return volume;
252 int Audio::volumeDown()
254 if (!initted) return 0;
255 if (userMute) toggleUserMute();
256 if (volume == 0) return 0;
262 int Audio::getVolume()
264 if (!initted) return 0;
268 int Audio::toggleUserMute()
270 if (!initted) return 0;
286 int Audio::systemMuteOn()
292 int Audio::systemMuteOff()
298 int Audio::doMuting()
300 Log::getInstance()->log("Audio", Log::DEBUG, "doMuting: user=%i sys=%i", userMute, systemMute);
303 if (userMute || systemMute)