]> git.vomp.tv Git - vompclient.git/blob - audiomvp.cc
Remove manual sync buttons
[vompclient.git] / audiomvp.cc
1 /*
2     Copyright 2004-2005 Chris Tallon
3
4     This file is part of VOMP.
5
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.
10
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.
15
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
19 */
20
21 #include "audiomvp.h"
22
23 AudioMVP::AudioMVP()
24 {
25   if (instance) return;
26   initted = 0;
27   fdAudio = 0;
28   streamType = 0;
29   volume = 20;
30   muted = 0;
31   userMute = 0;
32   systemMute = 0;
33 }
34
35 AudioMVP::~AudioMVP()
36 {
37 }
38
39 int AudioMVP::init(UCHAR tstreamType)
40 {
41   if (initted) return 0;
42   initted = 1;
43
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;
46
47   streamType = tstreamType;
48
49   if (!initAllParams())
50   {
51     shutdown();
52     return 0;
53   }
54
55   unMute();
56
57   // Set the volume variable to what the hardware is set at now
58   int hwvol = -1;
59   int hwvolFail = ioctl(fdAudio, AV_GET_AUD_VOLUME, &hwvol);
60   if (!hwvolFail)
61   {
62     volume = 20 - ((hwvol >> 16) & 0xFF);
63     if ((volume < 0) || (volume > 20)) volume = 20;
64   }
65
66   return 1;
67 }
68
69 int AudioMVP::initAllParams()
70 {
71   return (setStreamType(streamType) && setChannel() && setSource());
72 }
73
74 int AudioMVP::shutdown()
75 {
76   if (!initted) return 0;
77   initted = 0;
78   close(fdAudio);
79   return 1;
80 }
81
82 int AudioMVP::getFD()
83 {
84   if (!initted) return 0;
85
86   return fdAudio;
87 }
88
89 int AudioMVP::write(char *buf, int len)
90 {
91   return 0; //write(fdAudio, buf, len);
92 }
93
94 int AudioMVP::setStreamType(UCHAR type)
95 {
96   if (!initted) return 0;
97
98   if (ioctl(fdAudio, AV_SET_AUD_STREAMTYPE, type) != 0) return 0;
99   return 1;
100 }
101
102 int AudioMVP::setChannel()
103 {
104   if (!initted) return 0;
105
106   if (ioctl(fdAudio, AV_SET_AUD_CHANNEL, 0) != 0) return 0;
107   return 1;
108 }
109
110 int AudioMVP::setSource()
111 {
112   if (!initted) return 0;
113
114   if (ioctl(fdAudio, AV_SET_AUD_SRC, 1) != 0) return 0;
115   return 1;
116 }
117
118 int AudioMVP::sync()
119 {
120   if (!initted) return 0;
121
122   if (ioctl(fdAudio, AV_SET_AUD_SYNC, 2) != 0) return 0;
123   return 1;
124 }
125
126 int AudioMVP::play()
127 {
128   if (!initted) return 0;
129
130   if (ioctl(fdAudio, AV_SET_AUD_PLAY, 0) != 0) return 0;
131   return 1;
132 }
133
134 int AudioMVP::stop()
135 {
136   if (!initted) return 0;
137
138   if (ioctl(fdAudio, AV_SET_AUD_RESET, 0x11) != 0) return 0;
139   return 1;
140 }
141
142 int AudioMVP::mute()
143 {
144   if (!initted) return 0;
145
146   if (ioctl(fdAudio, AV_SET_AUD_MUTE, 1) != 0) return 0;
147   Log::getInstance()->log("Audio", Log::DEBUG, "MUTE MUTE MUTE");
148
149   muted = 1;
150   return 1;
151 }
152
153 int AudioMVP::unMute()
154 {
155   if (!initted) return 0;
156
157   if (ioctl(fdAudio, AV_SET_AUD_MUTE, 0) != 0) return 0;
158   Log::getInstance()->log("Audio", Log::DEBUG, "MUTE OFF OFF OFF");
159
160   muted = 0;
161   return 1;
162 }
163
164 int AudioMVP::pause()
165 {
166   if (!initted) return 0;
167
168   if (ioctl(fdAudio, AV_SET_AUD_PAUSE, 1) != 0) return 0;
169   return 1;
170 }
171
172 int AudioMVP::unPause()
173 {
174   if (!initted) return 0;
175
176   if (ioctl(fdAudio, AV_SET_AUD_UNPAUSE, 1) != 0) return 0;
177   return 1;
178 }
179
180 int AudioMVP::reset()
181 {
182   if (!initted) return 0;
183 //test();
184   if (ioctl(fdAudio, AV_SET_AUD_RESET, 0x11) != 0) return 0;
185   if (ioctl(fdAudio, AV_SET_AUD_PLAY, 0) != 0) return 0;
186
187   doMuting();
188   return 1;
189 }
190
191 int AudioMVP::setVolume(int tvolume)
192 {
193   // parameter: 0 for silence, 20 for full
194   if ((tvolume < 0) || (tvolume > 20)) return 0;
195
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
200
201   tvolume = 20 - tvolume;
202
203   audio_volume Avolume;
204   Avolume.frontleft = tvolume + Aoffset.frontleft;
205   Avolume.frontright = tvolume + Aoffset.frontright;
206   Avolume.rearleft = tvolume + Aoffset.rearleft;
207   Avolume.rearright = tvolume + Aoffset.rearright;
208   Avolume.center = tvolume + Aoffset.center;
209   Avolume.lfe = tvolume + Aoffset.lfe;
210
211   if (ioctl(fdAudio, AV_SET_AUD_VOLUME, &Avolume) != 0) return 0;
212
213 //  unsigned long vol = (tvolume << 24) | (tvolume << 16);
214 //
215 //  Log::getInstance()->log("Audio", Log::DEBUG, "%lx", vol);
216 //  Log::getInstance()->log("Audio", Log::DEBUG, "%i", tvolume);
217
218 //  if (ioctl(fdAudio, AV_SET_AUD_VOLUME, &vol) != 0) return 0;
219   return 1;
220 }
221
222 #ifdef DEV
223 int AudioMVP::test()
224 {
225 //  ULLONG stc = 0;
226 //  return ioctl(fdAudio, AV_SET_AUD_STC, &stc);
227
228   aud_sync_parms_t a;
229   a.parm1 = 0;
230   a.parm2 = 0;
231
232   int b = ioctl(fdAudio, AV_SET_AUD_DISABLE_SYNC, &a);
233
234
235   printf("Audio sync disable = %i\n", b); // is in a DEV block
236
237   return 1;
238
239
240 }
241 #endif
242
243
244 // unused
245 UINT AudioMVP::DeliverMediaSample(MediaPacket packet, UCHAR* buffer, UINT *samplepos)
246 {
247   return 0;
248 }