~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to kmix/mixer_hpux.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *              KMix -- KDE's full featured mini mixer
 
3
 *
 
4
 *
 
5
 *              Copyright (C) 1996-2000 Christian Esken
 
6
 *                        esken@kde.org
 
7
 *
 
8
 * HP/UX-Port:  Copyright (C) 1999 by Helge Deller
 
9
 *                        deller@gmx.de
 
10
 *
 
11
 * This program is free software; you can redistribute it and/or
 
12
 * modify it under the terms of the GNU Library General Public
 
13
 * License as published by the Free Software Foundation; either
 
14
 * version 2 of the License, or (at your option) any later version.
 
15
 *
 
16
 * This program is distributed in the hope that it will be useful,
 
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
19
 * Library General Public License for more details.
 
20
 *
 
21
 * You should have received a copy of the GNU Library General Public
 
22
 * License along with this program; if not, write to the Free
 
23
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
24
 */
 
25
 
 
26
#include "mixer_hpux.h"
 
27
 
 
28
#warning "HP/UX mixer (maybe) doesn't work yet !"
 
29
 
 
30
#define HPUX_ERROR_OFFSET 1024
 
31
 
 
32
#define myGain  AUnityGain      /* AUnityGain or AZeroGain */
 
33
 
 
34
#define GAIN_OUT_DIFF   ((long) ((int)aMaxOutputGain(audio) - (int)aMinOutputGain(audio)))
 
35
#define GAIN_OUT_MIN    ((long) aMinOutputGain(audio))
 
36
#define GAIN_IN_DIFF    ((long) ((int)aMaxInputGain(audio)  - (int)aMinInputGain(audio)))
 
37
#define GAIN_IN_MIN     ((long) aMinOutputGain(audio))
 
38
 
 
39
/* standard */
 
40
#define ID_PCM                  4
 
41
 
 
42
/* AInputSrcType: */         /*OSS:*/
 
43
#define ID_IN_MICROPHONE        7       /* AISTMonoMicrophone */
 
44
#define ID_IN_AUX               6       /* AISTLeftAuxiliary, AISTRightAuxiliary */
 
45
 
 
46
/* AOutputDstType: */
 
47
#define ID_OUT_INT_SPEAKER      0       /* AODTMonoIntSpeaker */
 
48
 
 
49
/* not yet implemented:
 
50
    AODTLeftJack,    AODTRightJack,
 
51
    AODTLeftLineOut,  AODTRightLineOut,
 
52
    AODTLeftHeadphone, AODTRightHeadphone
 
53
 
 
54
const char* MixerDevNames[32]={"Volume"  , "Bass"    , "Treble"    , "Synth"   , "Pcm"  ,    \
 
55
                               "Speaker" , "Line"    , "Microphone", "CD"      , "Mix"  ,    \
 
56
                               "Pcm2"    , "RecMon"  , "IGain"     , "OGain"   , "Line1",    \
 
57
                               "Line2"   , "Line3"   , "Digital1"  , "Digital2", "Digital3", \
 
58
                               "PhoneIn" , "PhoneOut", "Video"     , "Radio"   , "Monitor",  \
 
59
                               "3D-depth", "3D-center", "unknown"  , "unknown" , "unknown",  \
 
60
                               "unknown" , "unused" };
 
61
*/
 
62
 
 
63
 
 
64
Mixer* HPUX_getMixer(int devnum, int SetNum)
 
65
{
 
66
  Mixer *l_mixer;
 
67
  l_mixer = new Mixer_HPUX( devnum, SetNum);
 
68
//  l_mixer->init(devnum, SetNum);
 
69
  return l_mixer;
 
70
}
 
71
 
 
72
 
 
73
Mixer_HPUX::Mixer_HPUX() : Mixer()
 
74
{
 
75
    Mixer_HPUX(0,-1);
 
76
}
 
77
 
 
78
Mixer_HPUX::Mixer_HPUX(int devnum, int SetNum) : Mixer(devnum, SetNum)
 
79
{
 
80
  char ServerName[10];
 
81
  ServerName[0] = 0;
 
82
  audio = AOpenAudio(ServerName,NULL);
 
83
}
 
84
 
 
85
Mixer_HPUX::~Mixer_HPUX()
 
86
{
 
87
  if (audio) {
 
88
      ACloseAudio(audio,0);
 
89
      audio = 0;
 
90
  }
 
91
}
 
92
 
 
93
 
 
94
int Mixer_HPUX::openMixer()
 
95
{
 
96
  if (audio==0) {
 
97
    return Mixer::ERR_OPEN;
 
98
  }
 
99
  else
 
100
  {
 
101
    /* Mixer is open. Now define properties */
 
102
    stereodevs = devmask = (1<<ID_PCM); /* activate pcm */
 
103
    recmask = 0;
 
104
 
 
105
    /* check Input devices... */
 
106
    if (AInputSources(audio) & AMonoMicrophoneMask) {
 
107
            devmask     |= (1<<ID_IN_MICROPHONE);
 
108
            recmask     |= (1<<ID_IN_MICROPHONE);
 
109
    }
 
110
    if (AInputSources(audio) & (ALeftAuxiliaryMask|ARightAuxiliaryMask)) {
 
111
            devmask     |= (1<<ID_IN_AUX);
 
112
            recmask     |= (1<<ID_IN_AUX);
 
113
            stereodevs  |= (1<<ID_IN_AUX);
 
114
    }
 
115
 
 
116
    /* check Output devices... */
 
117
    if (AOutputDestinations(audio) & AMonoIntSpeakerMask) {
 
118
            devmask     |= (1<<ID_OUT_INT_SPEAKER);
 
119
            stereodevs  |= (1<<ID_OUT_INT_SPEAKER);
 
120
    }
 
121
 
 
122
/*  implement later:
 
123
    ----------------
 
124
    if (AOutputDestinations(audio) & AMonoLineOutMask)  devmask |= 64; // Line
 
125
    if (AOutputDestinations(audio) & AMonoJackMask)     devmask |= (1<<14); // Line1
 
126
    if (AOutputDestinations(audio) & AMonoHeadphoneMask)        devmask |= (1<<15); // Line2
 
127
*/
 
128
 
 
129
    MaxVolume = 255;
 
130
 
 
131
    long error = 0;
 
132
    ASetSystemPlayGain(audio, myGain, &error);
 
133
    if (error) errorText(error + HPUX_ERROR_OFFSET);
 
134
    ASetSystemRecordGain(audio, myGain, &error);
 
135
    if (error) errorText(error + HPUX_ERROR_OFFSET);
 
136
 
 
137
    i_recsrc = 0;
 
138
    m_isOpen = true;
 
139
 
 
140
    m_mixerName = "HP Mixer"; /* AAudioString(audio); */
 
141
    return 0;
 
142
  }
 
143
}
 
144
 
 
145
int Mixer_HPUX::releaseMixer()
 
146
{
 
147
  return 0;
 
148
}
 
149
 
 
150
 
 
151
/*
 
152
void Mixer_HPUX::setDevNumName_I(int devnum)
 
153
{
 
154
  devname = "HP Mixer";
 
155
}
 
156
*/
 
157
bool Mixer_HPUX::setRecsrcHW( int devnum, bool on )
 
158
{
 
159
    return FALSE;
 
160
}
 
161
 
 
162
bool Mixer_HPUX::isRecsrcHW( int devnum )
 
163
{
 
164
    return FALSE;
 
165
}
 
166
 
 
167
#if 0
 
168
void Mixer_HPUX::setRecsrc(unsigned int newRecsrc)
 
169
{
 
170
    long error = (long) AENoError;
 
171
    int  Source;
 
172
 
 
173
    i_recsrc = newRecsrc;
 
174
 
 
175
    Source = 0;
 
176
    if (newRecsrc & (1<<ID_IN_MICROPHONE))
 
177
        Source |= (1<<AISTMonoMicrophone);
 
178
    if (newRecsrc & (1<<ID_IN_AUX))
 
179
        Source |= (1<<AISTLeftAuxiliary) + (1<<AISTRightAuxiliary);
 
180
 
 
181
    ASetDefaultInput(audio, (AInputSrcType) Source, &error);
 
182
    if (error)
 
183
        errorText(error + HPUX_ERROR_OFFSET);
 
184
 
 
185
  /* Traverse through the mixer devices and set the record source flags
 
186
   * This is especially necessary for mixer devices that sometimes do
 
187
   * not obey blindly (because of hardware limitations)
 
188
   */
 
189
  unsigned int recsrcwork = i_recsrc;
 
190
  MixDevice *MixPtr;
 
191
  for ( unsigned int l_i_mixDevice = 1; l_i_mixDevice <= size(); l_i_mixDevice++) {
 
192
    MixPtr = operator[](l_i_mixDevice);
 
193
 
 
194
    if (recsrcwork & (1 << (MixPtr->num()) ) )
 
195
      MixPtr->setRecsrc(true);
 
196
    else
 
197
      MixPtr->setRecsrc(false);
 
198
  }
 
199
}
 
200
#endif
 
201
 
 
202
int Mixer_HPUX::readVolumeFromHW( int devnum, Volume &vol )
 
203
{
 
204
    long Gain;
 
205
    long error = 0;
 
206
    int  vl,vr;
 
207
 
 
208
    switch (devnum) {
 
209
    case ID_OUT_INT_SPEAKER:    /* AODTMonoIntSpeaker */
 
210
        AGetSystemChannelGain(audio, ASGTPlay, ACTMono, &Gain, &error );
 
211
        vl = vr = (Gain-GAIN_OUT_MIN)*255 / GAIN_OUT_DIFF;
 
212
        vol.setVolume( Volume::LEFT, vl);
 
213
        vol.setVolume( Volume::RIGHT, vr);
 
214
printf("READ - Devnum: %d, Left: %d, Right: %d\n", devnum, vl, vr );
 
215
        break;
 
216
 
 
217
    case ID_IN_AUX:             /* AISTLeftAuxiliary, AISTRightAuxiliary */
 
218
    case ID_IN_MICROPHONE:      /* AISTMonoMicrophone */
 
219
        AGetSystemChannelGain(audio, ASGTRecord, ACTMono, &Gain, &error );
 
220
        vl = vr = (Gain-GAIN_IN_MIN)*255 / GAIN_IN_DIFF;
 
221
        vol.setVolume( Volume::LEFT, vl);
 
222
        vol.setVolume( Volume::RIGHT, vr);
 
223
        break;
 
224
 
 
225
    default:
 
226
        error = ERR_NODEV - HPUX_ERROR_OFFSET;
 
227
        break;
 
228
    };
 
229
 
 
230
  return (error ? (error+HPUX_ERROR_OFFSET) : 0);
 
231
}
 
232
 
 
233
/*
 
234
        ASystemGainType         =     ASGTPlay, ASGTRecord, ASGTMonitor
 
235
        AChType                 =     ACTMono, ACTLeft, ACTRight
 
236
*/
 
237
 
 
238
int Mixer_HPUX::writeVolumeToHW( int devnum, Volume vol )
 
239
{
 
240
    long Gain;
 
241
    long error = 0;
 
242
    int vl = vol.getVolume(Volume::LEFT);
 
243
    int vr = vol.getVolume(Volume::RIGHT);
 
244
 
 
245
    switch (devnum) {
 
246
    case ID_OUT_INT_SPEAKER:    /* AODTMonoIntSpeaker */
 
247
printf("WRITE - Devnum: %d, Left: %d, Right: %d\n", devnum, vl, vr);
 
248
        Gain = vl;      // only left Volume
 
249
        Gain = (Gain*GAIN_OUT_DIFF) / 255 - GAIN_OUT_MIN;
 
250
        ASetSystemChannelGain(audio, ASGTPlay, ACTMono, (AGainDB) Gain, &error );
 
251
        break;
 
252
 
 
253
    case ID_IN_MICROPHONE:      /* AISTMonoMicrophone */
 
254
        Gain = vl;      // only left Volume
 
255
        Gain = (Gain*GAIN_IN_DIFF) / 255 - GAIN_IN_MIN;
 
256
        ASetSystemChannelGain(audio, ASGTRecord, ACTMono, (AGainDB) Gain, &error );
 
257
        break;
 
258
 
 
259
    case ID_IN_AUX:             /* AISTLeftAuxiliary, AISTRightAuxiliary */
 
260
        Gain = (vl*GAIN_IN_DIFF) / 255 - GAIN_IN_MIN;
 
261
        ASetSystemChannelGain(audio, ASGTRecord, ACTLeft, (AGainDB) Gain, &error );
 
262
        Gain = (vr*GAIN_IN_DIFF) / 255 - GAIN_IN_MIN;
 
263
        ASetSystemChannelGain(audio, ASGTRecord, ACTRight, (AGainDB) Gain, &error );
 
264
        break;
 
265
 
 
266
    default:
 
267
        error = ERR_NODEV - HPUX_ERROR_OFFSET;
 
268
        break;
 
269
    };
 
270
  return (error ? (error+HPUX_ERROR_OFFSET) : 0);
 
271
}
 
272
 
 
273
 
 
274
QString Mixer_HPUX::errorText(int mixer_error)
 
275
{
 
276
  QString l_s_errmsg;
 
277
  if (mixer_error >= HPUX_ERROR_OFFSET) {
 
278
      char errorstr[200];
 
279
      AGetErrorText(audio, (AError) (mixer_error-HPUX_ERROR_OFFSET),
 
280
                            errorstr, sizeof(errorstr));
 
281
      printf("kmix: %s: %s\n",mixerName().data(), errorstr);
 
282
      l_s_errmsg = errorstr;
 
283
  } else
 
284
  switch (mixer_error)
 
285
    {
 
286
    case ERR_OPEN:
 
287
                // should use i18n...
 
288
      l_s_errmsg = "kmix: HP-UX Alib-Mixer cannot be found.\n" \
 
289
                        "Please check that you have:\n" \
 
290
                        "  1. Installed the libAlib package  and\n" \
 
291
                        "  2. started the Aserver program from the /opt/audio/bin directory\n";
 
292
      break;
 
293
    default:
 
294
      l_s_errmsg = Mixer::errorText(mixer_error);
 
295
      break;
 
296
    }
 
297
  return l_s_errmsg;
 
298
}