summaryrefslogtreecommitdiffstats
path: root/kmix/mixer_hpux.cpp
blob: 3a4dbe5bb1e99b95b99c6605acdd5f1e277f18d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/*
 *              KMix -- KDE's full featured mini mixer
 *
 *
 *              Copyright (C) 1996-2000 Christian Esken
 *                        esken@kde.org
 *
 * HP/UX-Port:	Copyright (C) 1999 by Helge Deller
 *			  deller@gmx.de
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this program; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include "mixer_hpux.h"

#warning "HP/UX mixer (maybe) doesn't work yet !"

#define HPUX_ERROR_OFFSET 1024

#define myGain 	AUnityGain	/* AUnityGain or AZeroGain */

#define GAIN_OUT_DIFF	((long) ((int)aMaxOutputGain(audio) - (int)aMinOutputGain(audio)))
#define GAIN_OUT_MIN	((long) aMinOutputGain(audio))
#define GAIN_IN_DIFF	((long) ((int)aMaxInputGain(audio)  - (int)aMinInputGain(audio)))
#define GAIN_IN_MIN	((long) aMinOutputGain(audio))

/* standard */
#define	ID_PCM			4

/* AInputSrcType: */	     /*OSS:*/
#define ID_IN_MICROPHONE 	7	/* AISTMonoMicrophone */
#define ID_IN_AUX		6	/* AISTLeftAuxiliary, AISTRightAuxiliary */

/* AOutputDstType: */
#define ID_OUT_INT_SPEAKER	0	/* AODTMonoIntSpeaker */

/* not yet implemented:
    AODTLeftJack,    AODTRightJack,
    AODTLeftLineOut,  AODTRightLineOut,
    AODTLeftHeadphone, AODTRightHeadphone

const char* MixerDevNames[32]={"Volume"  , "Bass"    , "Treble"    , "Synth"   , "Pcm"  ,    \
			       "Speaker" , "Line"    , "Microphone", "CD"      , "Mix"  ,    \
			       "Pcm2"    , "RecMon"  , "IGain"     , "OGain"   , "Line1",    \
			       "Line2"   , "Line3"   , "Digital1"  , "Digital2", "Digital3", \
			       "PhoneIn" , "PhoneOut", "Video"     , "Radio"   , "Monitor",  \
			       "3D-depth", "3D-center", "unknown"  , "unknown" , "unknown",  \
			       "unknown" , "unused" };
*/



Mixer_HPUX::Mixer_HPUX(int devnum) : Mixer_Backend(devnum)
{
  char ServerName[10];
  ServerName[0] = 0;
  audio = AOpenAudio(ServerName,NULL);
}

Mixer_HPUX::~Mixer_HPUX()
{
  if (audio) {
      ACloseAudio(audio,0);
      audio = 0;
  }
}


int Mixer_HPUX::open()
{
  if (audio==0) {
    return Mixer::ERR_OPEN;
  }
  else
  {
    /* Mixer is open. Now define properties */
    stereodevs = devmask = (1<<ID_PCM); /* activate pcm */
    recmask = 0;

    /* check Input devices... */
    if (AInputSources(audio) & AMonoMicrophoneMask) {
	    devmask	|= (1<<ID_IN_MICROPHONE);
	    recmask	|= (1<<ID_IN_MICROPHONE);
    }
    if (AInputSources(audio) & (ALeftAuxiliaryMask|ARightAuxiliaryMask)) {
	    devmask	|= (1<<ID_IN_AUX);
	    recmask	|= (1<<ID_IN_AUX);
	    stereodevs	|= (1<<ID_IN_AUX);
    }

    /* check Output devices... */
    if (AOutputDestinations(audio) & AMonoIntSpeakerMask) {
	    devmask	|= (1<<ID_OUT_INT_SPEAKER);
	    stereodevs	|= (1<<ID_OUT_INT_SPEAKER);
    }

/*  implement later:
    ----------------
    if (AOutputDestinations(audio) & AMonoLineOutMask)	devmask |= 64; // Line
    if (AOutputDestinations(audio) & AMonoJackMask)	devmask |= (1<<14); // Line1
    if (AOutputDestinations(audio) & AMonoHeadphoneMask)	devmask |= (1<<15); // Line2
*/

    MaxVolume = 255;

    long error = 0;
    ASetSystemPlayGain(audio, myGain, &error);
    if (error) errorText(error + HPUX_ERROR_OFFSET);
    ASetSystemRecordGain(audio, myGain, &error);
    if (error) errorText(error + HPUX_ERROR_OFFSET);

    i_recsrc = 0;
    m_isOpen = true;

    m_mixerName = "HP Mixer"; /* AAudioString(audio); */
    return 0;
  }
}

int Mixer_HPUX::close()
{
  m_isOpen = false;
  m_mixDevices.clear();
  return 0;
}


/*
void Mixer_HPUX::setDevNumName_I(int devnum)
{
  devname = "HP Mixer";
}
*/
bool Mixer_HPUX::setRecsrcHW( int devnum, bool on )
{
    return FALSE;
}

bool Mixer_HPUX::isRecsrcHW( int devnum )
{
    return FALSE;
}

int Mixer_HPUX::readVolumeFromHW( int devnum, Volume &vol )
{
    long Gain;
    long error = 0;
    int  vl,vr;

    switch (devnum) {
    case ID_OUT_INT_SPEAKER:	/* AODTMonoIntSpeaker */
	AGetSystemChannelGain(audio, ASGTPlay, ACTMono, &Gain, &error );
	vl = vr = (Gain-GAIN_OUT_MIN)*255 / GAIN_OUT_DIFF;
	vol.setVolume( Volume::LEFT, vl);
	vol.setVolume( Volume::RIGHT, vr);
printf("READ - Devnum: %d, Left: %d, Right: %d\n", devnum, vl, vr );
	break;

    case ID_IN_AUX:		/* AISTLeftAuxiliary, AISTRightAuxiliary */
    case ID_IN_MICROPHONE:	/* AISTMonoMicrophone */
	AGetSystemChannelGain(audio, ASGTRecord, ACTMono, &Gain, &error );
	vl = vr = (Gain-GAIN_IN_MIN)*255 / GAIN_IN_DIFF;
	vol.setVolume( Volume::LEFT, vl);
	vol.setVolume( Volume::RIGHT, vr);
	break;

    default:
	error = Mixer::ERR_NODEV - HPUX_ERROR_OFFSET;
	break;
    };

  return (error ? (error+HPUX_ERROR_OFFSET) : 0);
}

/*
        ASystemGainType         =     ASGTPlay, ASGTRecord, ASGTMonitor
	AChType                	=     ACTMono, ACTLeft, ACTRight
*/

int Mixer_HPUX::writeVolumeToHW( int devnum, Volume& vol )
{
    long Gain;
    long error = 0;
    int vl = vol.getVolume(Volume::LEFT);
    int vr = vol.getVolume(Volume::RIGHT);

    switch (devnum) {
    case ID_OUT_INT_SPEAKER:	/* AODTMonoIntSpeaker */
printf("WRITE - Devnum: %d, Left: %d, Right: %d\n", devnum, vl, vr);
	Gain = vl;	// only left Volume
	Gain = (Gain*GAIN_OUT_DIFF) / 255 - GAIN_OUT_MIN;
	ASetSystemChannelGain(audio, ASGTPlay, ACTMono, (AGainDB) Gain, &error );
	break;

    case ID_IN_MICROPHONE:	/* AISTMonoMicrophone */
	Gain = vl;	// only left Volume
	Gain = (Gain*GAIN_IN_DIFF) / 255 - GAIN_IN_MIN;
	ASetSystemChannelGain(audio, ASGTRecord, ACTMono, (AGainDB) Gain, &error );
	break;

    case ID_IN_AUX:		/* AISTLeftAuxiliary, AISTRightAuxiliary */
	Gain = (vl*GAIN_IN_DIFF) / 255 - GAIN_IN_MIN;
	ASetSystemChannelGain(audio, ASGTRecord, ACTLeft, (AGainDB) Gain, &error );
	Gain = (vr*GAIN_IN_DIFF) / 255 - GAIN_IN_MIN;
	ASetSystemChannelGain(audio, ASGTRecord, ACTRight, (AGainDB) Gain, &error );
	break;

    default:
	error = Mixer::ERR_NODEV - HPUX_ERROR_OFFSET;
	break;
    };
  return (error ? (error+HPUX_ERROR_OFFSET) : 0);
}


QString Mixer_HPUX::errorText(int mixer_error)
{
  QString l_s_errmsg;
  if (mixer_error >= HPUX_ERROR_OFFSET) {
      char errorstr[200];
      AGetErrorText(audio, (AError) (mixer_error-HPUX_ERROR_OFFSET),
                	    errorstr, sizeof(errorstr));
      printf("kmix: %s: %s\n",mixerName().data(), errorstr);
      l_s_errmsg = errorstr;
  } else
  switch (mixer_error)
    {
    case Mixer::ERR_OPEN:
		// should use i18n...
      l_s_errmsg = "kmix: HP-UX Alib-Mixer cannot be found.\n" \
			"Please check that you have:\n" \
			"  1. Installed the libAlib package  and\n" \
			"  2. started the Aserver program from the /opt/audio/bin directory\n";
      break;
    default:
      l_s_errmsg = Mixer_Backend::errorText(mixer_error);
      break;
    }
  return l_s_errmsg;
}

QString HPUX_getDriverName() {
        return "HPUX";
}