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
37 int AudioMVP::init(UCHAR tstreamType)
39 if (initted) return 0;
42 // if ((fdAudio = open("/dev/adec_mpg", O_RDWR | O_NONBLOCK)) < 0) return 0;
43 if ((fdAudio = open("/dev/adec_mpg", O_WRONLY)) < 0) return 0;
45 streamType = tstreamType;
55 // Set the volume variable to what the hardware is set at now
57 int hwvolFail = ioctl(fdAudio, AV_GET_AUD_VOLUME, &hwvol);
60 volume = 20 - ((hwvol >> 16) & 0xFF);
61 if ((volume < 0) || (volume > 20)) volume = 20;
67 int AudioMVP::initAllParams()
69 return (setStreamType(streamType) && setChannel() && setSource());
72 int AudioMVP::shutdown()
74 if (!initted) return 0;
80 int AudioMVP::setStreamType(UCHAR type)
82 if (!initted) return 0;
84 if (ioctl(fdAudio, AV_SET_AUD_STREAMTYPE, type) != 0) return 0;
88 int AudioMVP::setChannel()
90 if (!initted) return 0;
92 if (ioctl(fdAudio, AV_SET_AUD_CHANNEL, 0) != 0) return 0;
96 int AudioMVP::setSource()
98 if (!initted) return 0;
100 if (ioctl(fdAudio, AV_SET_AUD_SRC, 1) != 0) return 0;
106 if (!initted) return 0;
108 if (ioctl(fdAudio, AV_SET_AUD_SYNC, 2) != 0) return 0;
114 if (!initted) return 0;
116 if (ioctl(fdAudio, AV_SET_AUD_PLAY, 0) != 0) return 0;
122 if (!initted) return 0;
124 if (ioctl(fdAudio, AV_SET_AUD_RESET, 0x11) != 0) return 0;
130 if (!initted) return 0;
132 if (ioctl(fdAudio, AV_SET_AUD_MUTE, 1) != 0) return 0;
133 Log::getInstance()->log("Audio", Log::DEBUG, "MUTE MUTE MUTE");
139 int AudioMVP::unMute()
141 if (!initted) return 0;
143 if (ioctl(fdAudio, AV_SET_AUD_MUTE, 0) != 0) return 0;
144 Log::getInstance()->log("Audio", Log::DEBUG, "MUTE OFF OFF OFF");
150 int AudioMVP::pause()
152 if (!initted) return 0;
154 if (ioctl(fdAudio, AV_SET_AUD_PAUSE, 1) != 0) return 0;
158 int AudioMVP::unPause()
160 if (!initted) return 0;
162 if (ioctl(fdAudio, AV_SET_AUD_UNPAUSE, 1) != 0) return 0;
166 int AudioMVP::reset()
168 if (!initted) return 0;
170 if (ioctl(fdAudio, AV_SET_AUD_RESET, 0x11) != 0) return 0;
171 if (ioctl(fdAudio, AV_SET_AUD_PLAY, 0) != 0) return 0;
177 int AudioMVP::setVolume(int tvolume)
179 // parameter: 0 for silence, 20 for full
180 if ((tvolume < 0) || (tvolume > 20)) return 0;
182 // volume = 2 * (20 - volume);
183 // Right, that one was rubbish... 0-10 were almost
184 // inaudible, 11-20 did what should have been done
185 // over the whole 0-20 range
187 tvolume = 20 - tvolume;
189 audio_volume Avolume;
190 Avolume.frontleft = tvolume + Aoffset.frontleft;
191 Avolume.frontright = tvolume + Aoffset.frontright;
192 Avolume.rearleft = tvolume + Aoffset.rearleft;
193 Avolume.rearright = tvolume + Aoffset.rearright;
194 Avolume.center = tvolume + Aoffset.center;
195 Avolume.lfe = tvolume + Aoffset.lfe;
197 if (ioctl(fdAudio, AV_SET_AUD_VOLUME, &Avolume) != 0) return 0;
199 // unsigned long vol = (tvolume << 24) | (tvolume << 16);
201 // Log::getInstance()->log("Audio", Log::DEBUG, "%lx", vol);
202 // Log::getInstance()->log("Audio", Log::DEBUG, "%i", tvolume);
204 // if (ioctl(fdAudio, AV_SET_AUD_VOLUME, &vol) != 0) return 0;
212 // return ioctl(fdAudio, AV_SET_AUD_STC, &stc);
218 int b = ioctl(fdAudio, AV_SET_AUD_DISABLE_SYNC, &a);
221 /*OK*/ printf("Audio sync disable = %i\n", b);
229 void AudioMVP::PrepareMediaSample(const MediaPacketList& mplist,UINT samplepos)
231 packet = mplist.front();
234 UINT AudioMVP::DeliverMediaSample(const UCHAR* buffer, UINT* samplepos)
236 int written = ::write(fdAudio, buffer + packet.pos_buffer + *samplepos,
237 packet.length - *samplepos);
238 if (written == (int)(packet.length - *samplepos)) {*samplepos = 0; return 1;}
239 if (written > 0) *samplepos += written;
243 void AudioMVP::ResetTimeOffsets()