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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
39 int AudioMVP::init(UCHAR tstreamType)
41 if (initted) return 0;
44 // if ((fdAudio = open("/dev/adec_mpg", O_RDWR | O_NONBLOCK)) < 0) return 0;
45 if ((fdAudio = open("/dev/adec_mpg", O_WRONLY)) < 0) return 0;
47 streamType = tstreamType;
57 // Set the volume variable to what the hardware is set at now
59 int hwvolFail = ioctl(fdAudio, AV_GET_AUD_VOLUME, &hwvol);
62 volume = 20 - ((hwvol >> 16) & 0xFF);
63 if ((volume < 0) || (volume > 20)) volume = 20;
69 int AudioMVP::initAllParams()
71 return (setStreamType(streamType) && setChannel() && setSource());
74 int AudioMVP::shutdown()
76 if (!initted) return 0;
82 int AudioMVP::setStreamType(UCHAR type)
84 if (!initted) return 0;
86 if (ioctl(fdAudio, AV_SET_AUD_STREAMTYPE, type) != 0) return 0;
90 int AudioMVP::setChannel()
92 if (!initted) return 0;
94 if (ioctl(fdAudio, AV_SET_AUD_CHANNEL, 0) != 0) return 0;
98 int AudioMVP::setSource()
100 if (!initted) return 0;
102 if (ioctl(fdAudio, AV_SET_AUD_SRC, 1) != 0) return 0;
108 if (!initted) return 0;
110 if (ioctl(fdAudio, AV_SET_AUD_SYNC, 2) != 0) return 0;
116 if (!initted) return 0;
118 if (ioctl(fdAudio, AV_SET_AUD_PLAY, 0) != 0) return 0;
124 if (!initted) return 0;
126 if (ioctl(fdAudio, AV_SET_AUD_RESET, 0x11) != 0) return 0;
132 if (!initted) return 0;
134 if (ioctl(fdAudio, AV_SET_AUD_MUTE, 1) != 0) return 0;
135 Log::getInstance()->log("Audio", Log::DEBUG, "MUTE MUTE MUTE");
141 int AudioMVP::unMute()
143 if (!initted) return 0;
145 if (ioctl(fdAudio, AV_SET_AUD_MUTE, 0) != 0) return 0;
146 Log::getInstance()->log("Audio", Log::DEBUG, "MUTE OFF OFF OFF");
152 int AudioMVP::pause()
154 if (!initted) return 0;
156 if (ioctl(fdAudio, AV_SET_AUD_PAUSE, 1) != 0) return 0;
160 int AudioMVP::unPause()
162 if (!initted) return 0;
164 if (ioctl(fdAudio, AV_SET_AUD_UNPAUSE, 1) != 0) return 0;
168 int AudioMVP::reset()
170 if (!initted) return 0;
172 Log::getInstance()->log("Audio", Log::DEBUG, "reset called");
173 if (ioctl(fdAudio, AV_SET_AUD_RESET, 0x11) != 0) return 0;
174 Log::getInstance()->log("Audio", Log::DEBUG, "reset back");
175 if (ioctl(fdAudio, AV_SET_AUD_PLAY, 0) != 0) return 0;
181 int AudioMVP::setVolume(int tvolume)
183 // parameter: 0 for silence, 20 for full
184 if ((tvolume < 0) || (tvolume > 20)) return 0;
186 // volume = 2 * (20 - volume);
187 // Right, that one was rubbish... 0-10 were almost
188 // inaudible, 11-20 did what should have been done
189 // over the whole 0-20 range
191 tvolume = 20 - tvolume;
193 audio_volume Avolume;
194 Avolume.frontleft = tvolume + Aoffset.frontleft;
195 Avolume.frontright = tvolume + Aoffset.frontright;
196 Avolume.rearleft = tvolume + Aoffset.rearleft;
197 Avolume.rearright = tvolume + Aoffset.rearright;
198 Avolume.center = tvolume + Aoffset.center;
199 Avolume.lfe = tvolume + Aoffset.lfe;
201 if (ioctl(fdAudio, AV_SET_AUD_VOLUME, &Avolume) != 0) return 0;
203 // unsigned long vol = (tvolume << 24) | (tvolume << 16);
205 // Log::getInstance()->log("Audio", Log::DEBUG, "%lx", vol);
206 // Log::getInstance()->log("Audio", Log::DEBUG, "%i", tvolume);
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 /*OK*/ printf("Audio sync disable = %i\n", b);
233 void AudioMVP::PrepareMediaSample(const MediaPacketList& mplist,UINT samplepos)
235 packet = mplist.front();
238 UINT AudioMVP::DeliverMediaSample(const UCHAR* buffer, UINT* samplepos)
240 int written = ::write(fdAudio, buffer + packet.pos_buffer + *samplepos,
241 packet.length - *samplepos);
242 if (written == (int)(packet.length - *samplepos)) {*samplepos = 0; return 1;}
243 if (written > 0) *samplepos += written;
247 void AudioMVP::ResetTimeOffsets()