2
* KMix -- KDE's full featured mini mixer
5
* Copyright (C) 2008 Helio Chissini de Castro <helio@kde.org>
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Library General Public
9
* License as published by the Free Software Foundation; either
10
* version 2 of the License, or (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Library General Public License for more details.
17
* You should have received a copy of the GNU Library General Public
18
* License along with this program; if not, write to the Free
19
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24
#include "mixer_pulse.h"
27
static pa_context *context = NULL;
28
static pa_glib_mainloop *mainloop = NULL;
30
Mixer_Backend* PULSE_getMixer( Mixer *mixer, int devnum )
32
Mixer_Backend *l_mixer;
33
l_mixer = new Mixer_PULSE( mixer, devnum );
38
Mixer_PULSE::Mixer_PULSE(Mixer *mixer, int devnum) : Mixer_Backend(mixer, devnum)
44
Mixer_PULSE::~Mixer_PULSE()
49
int Mixer_PULSE::open()
51
kDebug(67100) << "Trying Pulse sink";
52
mainloop = pa_glib_mainloop_new(g_main_context_default());
54
pa_mainloop_api *api = pa_glib_mainloop_get_api(mainloop);
57
context = pa_context_new(api, "KMix KDE 4");
59
//return Mixer::ERR_OPEN;
63
// Mixer is open. Now define all of the mix devices.
66
for ( int idx = 0; idx < numDevs; idx++ )
68
Volume vol( 2, AUDIO_MAX_GAIN );
71
MixDevice* md = new MixDevice( _mixer, id,
72
QString(MixerDevNames[idx]), MixerChannelTypes[idx]);
73
md->addPlaybackVolume(vol);
74
md->setRecSource( isRecsrcHW( idx ) );
75
m_mixDevices.append( md );
79
m_mixerName = "PULSE Audio Mixer";
86
int Mixer_PULSE::close()
90
pa_context_unref(context);
95
pa_glib_mainloop_free(mainloop);
101
int Mixer_PULSE::readVolumeFromHW( const QString& id, MixDevice *md )
103
/* audio_info_t audioinfo;
104
uint_t devMask = MixerSunPortMasks[devnum];
106
Volume& volume = md->playbackVolume();
107
int devnum = id2num(id);
109
// Read the current audio information from the driver
111
if ( ioctl( fd, AUDIO_GETINFO, &audioinfo ) < 0 )
113
return( Mixer::ERR_READ );
118
// Extract the appropriate fields based on the requested device
122
case MIXERDEV_MASTER_VOLUME :
123
volume.setSwitchActivated( audioinfo.output_muted );
124
GainBalanceToVolume( audioinfo.play.gain,
125
audioinfo.play.balance,
129
case MIXERDEV_RECORD_MONITOR :
131
volume.setAllVolumes( audioinfo.monitor_gain );
134
case MIXERDEV_INTERNAL_SPEAKER :
135
case MIXERDEV_HEADPHONE :
136
case MIXERDEV_LINE_OUT :
137
md->setMuted( (audioinfo.play.port & devMask) ? false : true );
138
GainBalanceToVolume( audioinfo.play.gain,
139
audioinfo.play.balance,
143
case MIXERDEV_MICROPHONE :
144
case MIXERDEV_LINE_IN :
146
md->setMuted( (audioinfo.record.port & devMask) ? false : true );
147
GainBalanceToVolume( audioinfo.record.gain,
148
audioinfo.record.balance,
153
return Mixer::ERR_READ;
160
int Mixer_PULSE::writeVolumeToHW( const QString& id, MixDevice *md )
166
Volume& volume = md->playbackVolume();
167
int devnum = id2num(id);
169
// Convert the Volume(left vol, right vol) to the Gain/Balance Sun uses
171
VolumeToGainBalance( volume, gain, balance );
172
mute = md->isMuted() ? 1 : 0;
175
// Read the current audio settings from the hardware
177
audio_info_t audioinfo;
178
if ( ioctl( fd, AUDIO_GETINFO, &audioinfo ) < 0 )
180
return( Mixer::ERR_READ );
184
// Now, based on the devnum that we are writing to, update the appropriate
185
// volume field and twiddle the appropriate bitmask to enable/mute the
186
// device as necessary.
190
case MIXERDEV_MASTER_VOLUME :
191
audioinfo.play.gain = gain;
192
audioinfo.play.balance = balance;
193
audioinfo.output_muted = mute;
196
case MIXERDEV_RECORD_MONITOR :
197
audioinfo.monitor_gain = gain;
198
// no mute or balance for record monitor
201
case MIXERDEV_INTERNAL_SPEAKER :
202
case MIXERDEV_HEADPHONE :
203
case MIXERDEV_LINE_OUT :
204
audioinfo.play.gain = gain;
205
audioinfo.play.balance = balance;
207
audioinfo.play.port &= ~MixerSunPortMasks[devnum];
209
audioinfo.play.port |= MixerSunPortMasks[devnum];
212
case MIXERDEV_MICROPHONE :
213
case MIXERDEV_LINE_IN :
215
audioinfo.record.gain = gain;
216
audioinfo.record.balance = balance;
218
audioinfo.record.port &= ~MixerSunPortMasks[devnum];
220
audioinfo.record.port |= MixerSunPortMasks[devnum];
224
return Mixer::ERR_READ;
228
// Now that we've updated the audioinfo struct, write it back to the hardware
230
if ( ioctl( fd, AUDIO_SETINFO, &audioinfo ) < 0 )
232
return( Mixer::ERR_WRITE );
241
void Mixer_PULSE::setRecsrcHW( const QString& /*id*/, bool /* on */ )
246
bool Mixer_PULSE::isRecsrcHW( const QString& id )
248
/* int devnum = id2num(id);
251
case MIXERDEV_MICROPHONE :
252
case MIXERDEV_LINE_IN :
263
QString PULSE_getDriverName() {
267
QString Mixer_PULSE::getDriverName()