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 streamType)
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 this->streamType = streamType;
69 int Audio::initAllParams()
71 return (setStreamType(streamType) && setChannel() && setSource());
76 if (!initted) return 0;
84 if (!initted) return 0;
89 int Audio::write(char *buf, int len)
91 return 0; //write(fdAudio, buf, len);
94 int Audio::setStreamType(UCHAR type)
96 if (!initted) return 0;
98 if (ioctl(fdAudio, AV_SET_AUD_STREAMTYPE, type) != 0) return 0;
102 int Audio::setChannel()
104 if (!initted) return 0;
106 if (ioctl(fdAudio, AV_SET_AUD_CHANNEL, 0) != 0) return 0;
110 int Audio::setSource()
112 if (!initted) return 0;
114 if (ioctl(fdAudio, AV_SET_AUD_SRC, 1) != 0) return 0;
120 if (!initted) return 0;
122 if (ioctl(fdAudio, AV_SET_AUD_SYNC, 2) != 0) return 0;
128 if (!initted) return 0;
130 if (ioctl(fdAudio, AV_SET_AUD_PLAY, 0) != 0) return 0;
136 if (!initted) return 0;
138 if (ioctl(fdAudio, AV_SET_AUD_RESET, 0x11) != 0) return 0;
144 if (!initted) return 0;
146 if (ioctl(fdAudio, AV_SET_AUD_MUTE, 1) != 0) return 0;
147 Log::getInstance()->log("Audio", Log::DEBUG, "MUTE MUTE MUTE");
155 if (!initted) return 0;
157 if (ioctl(fdAudio, AV_SET_AUD_MUTE, 0) != 0) return 0;
158 Log::getInstance()->log("Audio", Log::DEBUG, "MUTE OFF OFF OFF");
166 if (!initted) return 0;
168 if (ioctl(fdAudio, AV_SET_AUD_PAUSE, 1) != 0) return 0;
174 if (!initted) return 0;
176 if (ioctl(fdAudio, AV_SET_AUD_UNPAUSE, 1) != 0) return 0;
182 if (!initted) return 0;
184 if (ioctl(fdAudio, AV_SET_AUD_RESET, 0x11) != 0) return 0;
185 if (ioctl(fdAudio, AV_SET_AUD_PLAY, 0) != 0) return 0;
191 int Audio::setVolume(int volume)
193 // parameter: 0 for silence, 20 for full
194 if ((volume < 0) || (volume > 20)) return 0;
196 // volume = 2 * (20 - volume);
197 // Right, that one was rubbish... 0-10 were almost
198 // inaudible, 11-20 did what should have been done
199 // over the whole 0-20 range
201 volume = 20 - volume;
203 unsigned long vol = (volume << 24) | (volume << 16);
205 Log::getInstance()->log("Audio", Log::DEBUG, "%lx", vol);
206 Log::getInstance()->log("Audio", Log::DEBUG, "%i", volume);
208 if (ioctl(fdAudio, AV_SET_AUD_VOLUME, &vol) != 0) return 0;
216 // return ioctl(fdAudio, AV_SET_AUD_STC, &stc);
222 int b = ioctl(fdAudio, AV_SET_AUD_DISABLE_SYNC, &a);
225 printf("Audio sync disable = %i\n", b);
233 int Audio::volumeUp()
235 if (!initted) return 0;
236 if (volume == 20) return volume;
242 int Audio::volumeDown()
244 if (!initted) return 0;
245 if (volume == 0) return 0;
251 int Audio::getVolume()
253 if (!initted) return 0;
257 int Audio::toggleUserMute()
259 if (!initted) return 0;
275 int Audio::systemMuteOn()
281 int Audio::systemMuteOff()
287 int Audio::doMuting()
289 Log::getInstance()->log("Audio", Log::DEBUG, "doMuting: user=%i sys=%i", userMute, systemMute);
292 if (userMute || systemMute)