-rw-r--r-- | libopie2/opiemm/osoundsystem.cpp | 112 | ||||
-rw-r--r-- | libopie2/opiemm/osoundsystem.h | 19 |
2 files changed, 59 insertions, 72 deletions
diff --git a/libopie2/opiemm/osoundsystem.cpp b/libopie2/opiemm/osoundsystem.cpp index 09fd28f..6c03203 100644 --- a/libopie2/opiemm/osoundsystem.cpp +++ b/libopie2/opiemm/osoundsystem.cpp | |||
@@ -1,16 +1,15 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | (C) 2003-2005 Michael 'Mickey' Lauer <mickey@Vanille.de> | |
4 | (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | ||
5 | =. | 4 | =. |
6 | .=l. | 5 | .=l. |
7 | .>+-= | 6 | .>+-= |
8 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
9 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
11 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
12 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
13 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
14 | .%`+i> _;_. | 13 | .%`+i> _;_. |
15 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
@@ -31,49 +30,50 @@ | |||
31 | 30 | ||
32 | #include <opie2/osoundsystem.h> | 31 | #include <opie2/osoundsystem.h> |
33 | #include <opie2/odebug.h> | 32 | #include <opie2/odebug.h> |
34 | 33 | ||
35 | #include <errno.h> | 34 | #include <errno.h> |
36 | #include <fcntl.h> | 35 | #include <fcntl.h> |
37 | #include <string.h> | 36 | #include <string.h> |
38 | #include <sys/ioctl.h> | 37 | #include <sys/ioctl.h> |
39 | #include <sys/types.h> | 38 | #include <sys/types.h> |
40 | #include <sys/soundcard.h> | 39 | #include <sys/soundcard.h> |
41 | #include <sys/stat.h> | 40 | #include <sys/stat.h> |
42 | 41 | ||
42 | static const char* device_label[] = SOUND_DEVICE_LABELS; | ||
43 | static int max_device_nr = sizeof device_label / sizeof (const char*); | ||
43 | 44 | ||
44 | using namespace Opie::Core; | 45 | using namespace Opie::Core; |
45 | using namespace Opie::MM; | 46 | using namespace Opie::MM; |
46 | /*====================================================================================== | 47 | /*====================================================================================== |
47 | * OSoundSystem | 48 | * OSoundSystem |
48 | *======================================================================================*/ | 49 | *======================================================================================*/ |
49 | 50 | ||
50 | OSoundSystem* OSoundSystem::_instance = 0; | 51 | OSoundSystem* OSoundSystem::_instance = 0; |
51 | 52 | ||
52 | OSoundSystem::OSoundSystem() | 53 | OSoundSystem::OSoundSystem() |
53 | { | 54 | { |
54 | odebug << "OSoundSystem::OSoundSystem()" << oendl; | 55 | odebug << "OSoundSystem::OSoundSystem()" << oendl; |
55 | synchronize(); | 56 | synchronize(); |
56 | } | 57 | } |
57 | 58 | ||
58 | void OSoundSystem::synchronize() | 59 | void OSoundSystem::synchronize() |
59 | { | 60 | { |
60 | // gather available interfaces by inspecting /dev | 61 | // gather available interfaces by inspecting /dev |
61 | //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices | 62 | //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices |
62 | //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices | 63 | //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices |
63 | 64 | ||
64 | _interfaces.clear(); | 65 | _interfaces.clear(); |
65 | _interfaces.insert( "soundcard", new OSoundCard( this, "soundcard" ) ); | 66 | _interfaces.insert( "soundcard", new OSoundCard( this, "soundcard" ) ); |
66 | 67 | ||
67 | |||
68 | /* | 68 | /* |
69 | 69 | ||
70 | QString str; | 70 | QString str; |
71 | QFile f( "/dev/sound" ); | 71 | QFile f( "/dev/sound" ); |
72 | bool hasFile = f.open( IO_ReadOnly ); | 72 | bool hasFile = f.open( IO_ReadOnly ); |
73 | if ( !hasFile ) | 73 | if ( !hasFile ) |
74 | { | 74 | { |
75 | odebug << "OSoundSystem: /dev/sound not existing. No sound devices available" << oendl; | 75 | odebug << "OSoundSystem: /dev/sound not existing. No sound devices available" << oendl; |
76 | return; | 76 | return; |
77 | } | 77 | } |
78 | QTextStream s( &f ); | 78 | QTextStream s( &f ); |
79 | s.readLine(); | 79 | s.readLine(); |
@@ -167,147 +167,125 @@ OAudioInterface::~OAudioInterface() | |||
167 | void OAudioInterface::init() | 167 | void OAudioInterface::init() |
168 | { | 168 | { |
169 | 169 | ||
170 | 170 | ||
171 | } | 171 | } |
172 | 172 | ||
173 | 173 | ||
174 | /*====================================================================================== | 174 | /*====================================================================================== |
175 | * OMixerInterface | 175 | * OMixerInterface |
176 | *======================================================================================*/ | 176 | *======================================================================================*/ |
177 | 177 | ||
178 | OMixerInterface::OMixerInterface( QObject* parent, const char* name ) | 178 | OMixerInterface::OMixerInterface( QObject* parent, const char* name ) |
179 | :QObject( parent, name ) | 179 | :QObject( parent, name ), _devmask( 0 ), _recmask( 0 ), _stmask( 0 ) |
180 | { | 180 | { |
181 | odebug << "OMixerInterface::OMixerInterface()" << oendl; | 181 | odebug << "OMixerInterface::OMixerInterface()" << oendl; |
182 | init(); | 182 | init(); |
183 | } | 183 | } |
184 | 184 | ||
185 | 185 | ||
186 | OMixerInterface::~OMixerInterface() | 186 | OMixerInterface::~OMixerInterface() |
187 | { | 187 | { |
188 | } | 188 | } |
189 | 189 | ||
190 | 190 | ||
191 | void OMixerInterface::init() | 191 | void OMixerInterface::init() |
192 | { | 192 | { |
193 | // open the device | 193 | // open the device |
194 | _fd = ::open( name(), O_RDWR ); | 194 | _fd = ::open( name(), O_RDWR ); |
195 | if ( _fd == -1 ) | 195 | if ( _fd == -1 ) |
196 | { | 196 | { |
197 | owarn << "OMixerInterface::init(): Can't open mixer " << name() << oendl; | 197 | owarn << "OMixerInterface::init(): Can't open mixer " << name() << oendl; |
198 | return; | 198 | return; |
199 | } | 199 | } |
200 | 200 | ||
201 | // construct the device capabilities | 201 | // construct the device capabilities |
202 | int devmask = 0; | 202 | if ( ioctl( _fd, SOUND_MIXER_READ_CAPS, &_capmask ) != -1 ) |
203 | if ( ioctl( _fd, SOUND_MIXER_READ_DEVMASK, &devmask ) != -1 ) | ||
204 | { | 203 | { |
205 | if ( devmask & ( 1 << SOUND_MIXER_VOLUME ) ) _channels.insert( "PlayVolume", SOUND_MIXER_VOLUME ); | 204 | odebug << "OMixerInterface::init() - capmask = " << _capmask << oendl; |
206 | if ( devmask & ( 1 << SOUND_MIXER_BASS ) ) _channels.insert( "PlayBass", SOUND_MIXER_BASS ); | ||
207 | if ( devmask & ( 1 << SOUND_MIXER_TREBLE ) ) _channels.insert( "PlayTreble", SOUND_MIXER_TREBLE ); | ||
208 | if ( devmask & ( 1 << SOUND_MIXER_SYNTH ) ) _channels.insert( "PlaySynth", SOUND_MIXER_SYNTH ); | ||
209 | if ( devmask & ( 1 << SOUND_MIXER_PCM ) ) _channels.insert( "PlayPCM", SOUND_MIXER_PCM ); | ||
210 | if ( devmask & ( 1 << SOUND_MIXER_SPEAKER ) ) _channels.insert( "PlaySpeaker", SOUND_MIXER_SPEAKER ); | ||
211 | if ( devmask & ( 1 << SOUND_MIXER_LINE ) ) _channels.insert( "PlayLine", SOUND_MIXER_LINE ); | ||
212 | if ( devmask & ( 1 << SOUND_MIXER_MIC ) ) _channels.insert( "PlayMic", SOUND_MIXER_MIC ); | ||
213 | if ( devmask & ( 1 << SOUND_MIXER_CD ) ) _channels.insert( "PlayCD", SOUND_MIXER_CD ); | ||
214 | if ( devmask & ( 1 << SOUND_MIXER_IMIX ) ) _channels.insert( "PlayInputMix", SOUND_MIXER_IMIX ); | ||
215 | if ( devmask & ( 1 << SOUND_MIXER_ALTPCM ) ) _channels.insert( "PlayAltPCM", SOUND_MIXER_ALTPCM ); | ||
216 | if ( devmask & ( 1 << SOUND_MIXER_RECLEV ) ) _channels.insert( "PlayRecord", SOUND_MIXER_RECLEV ); | ||
217 | if ( devmask & ( 1 << SOUND_MIXER_IGAIN ) ) _channels.insert( "PlayInputGain", SOUND_MIXER_IGAIN ); | ||
218 | if ( devmask & ( 1 << SOUND_MIXER_OGAIN ) ) _channels.insert( "PlayOutputGain", SOUND_MIXER_OGAIN ); | ||
219 | //odebug << "devmask available and constructed." << oendl; | ||
220 | } | 205 | } |
221 | 206 | if ( ioctl( _fd, SOUND_MIXER_READ_DEVMASK, &_devmask ) != -1 ) | |
222 | devmask = 0; | ||
223 | if ( ioctl( _fd, SOUND_MIXER_READ_RECMASK, &devmask ) != -1 ) | ||
224 | { | 207 | { |
225 | if ( devmask & ( 1 << SOUND_MIXER_VOLUME ) ) _channels.insert( "RecVolume", SOUND_MIXER_VOLUME ); | 208 | odebug << "OMixerInterface::init() - devmask = " << _devmask << oendl; |
226 | if ( devmask & ( 1 << SOUND_MIXER_BASS ) ) _channels.insert( "RecBass", SOUND_MIXER_BASS ); | ||
227 | if ( devmask & ( 1 << SOUND_MIXER_TREBLE ) ) _channels.insert( "RecTreble", SOUND_MIXER_TREBLE ); | ||
228 | if ( devmask & ( 1 << SOUND_MIXER_SYNTH ) ) _channels.insert( "RecSynth", SOUND_MIXER_SYNTH ); | ||
229 | if ( devmask & ( 1 << SOUND_MIXER_PCM ) ) _channels.insert( "RecPCM", SOUND_MIXER_PCM ); | ||
230 | if ( devmask & ( 1 << SOUND_MIXER_SPEAKER ) ) _channels.insert( "RecSpeaker", SOUND_MIXER_SPEAKER ); | ||
231 | if ( devmask & ( 1 << SOUND_MIXER_LINE ) ) _channels.insert( "RecLine", SOUND_MIXER_LINE ); | ||
232 | if ( devmask & ( 1 << SOUND_MIXER_MIC ) ) _channels.insert( "RecMic", SOUND_MIXER_MIC ); | ||
233 | if ( devmask & ( 1 << SOUND_MIXER_CD ) ) _channels.insert( "RecCD", SOUND_MIXER_CD ); | ||
234 | if ( devmask & ( 1 << SOUND_MIXER_IMIX ) ) _channels.insert( "RecInputMix", SOUND_MIXER_IMIX ); | ||
235 | if ( devmask & ( 1 << SOUND_MIXER_ALTPCM ) ) _channels.insert( "RecAltPCM", SOUND_MIXER_ALTPCM ); | ||
236 | if ( devmask & ( 1 << SOUND_MIXER_RECLEV ) ) _channels.insert( "RecRecord", SOUND_MIXER_RECLEV ); | ||
237 | if ( devmask & ( 1 << SOUND_MIXER_IGAIN ) ) _channels.insert( "RecInputGain", SOUND_MIXER_IGAIN ); | ||
238 | if ( devmask & ( 1 << SOUND_MIXER_OGAIN ) ) _channels.insert( "RecOutputGain", SOUND_MIXER_OGAIN ); | ||
239 | //odebug << "recmask available and constructed." << oendl; | ||
240 | } | 209 | } |
241 | 210 | if ( ioctl( _fd, SOUND_MIXER_READ_RECMASK, &_recmask ) != -1 ) | |
242 | devmask = 0; | ||
243 | if ( ioctl( _fd, SOUND_MIXER_READ_STEREODEVS, &devmask ) != -1 ) | ||
244 | { | 211 | { |
245 | odebug << "stereomask = " << devmask << oendl; | 212 | odebug << "OMixerInterface::init() - recmask = " << _recmask << oendl; |
246 | } | 213 | } |
247 | 214 | if ( ioctl( _fd, SOUND_MIXER_READ_STEREODEVS, &_stmask ) != -1 ) | |
248 | /* ChannelIterator it; | ||
249 | for ( it = _channels.begin(); it != _channels.end(); ++it ) | ||
250 | { | 215 | { |
251 | odebug << "Channel " << it.key() << " available (bit " << it.data() << ")" << oendl; | 216 | odebug << "OMixerInterface::init() - stereomask = " << _stmask << oendl; |
252 | odebug << " +--- Volume: " << volume( it.key() ) & 0xff << " | " << volume( it.key() ) >> 8 << "" << oendl; | ||
253 | } | 217 | } |
254 | */ | 218 | for ( int i = 0; i < max_device_nr; ++i ) |
255 | } | 219 | { |
220 | if ( _devmask & ( 1 << i ) ) | ||
221 | { | ||
222 | _channels.insert( QString( device_label[i] ).stripWhiteSpace(), i ); | ||
223 | odebug << "OMixerInterface::init() - channel '" << device_label[i] << "'" << oendl; | ||
224 | } | ||
225 | } | ||
226 | } | ||
227 | |||
256 | 228 | ||
257 | QStringList OMixerInterface::allChannels() const | 229 | QStringList OMixerInterface::allChannels() const |
258 | { | 230 | { |
259 | ChannelIterator it = _channels.begin(); | 231 | ChannelIterator it = _channels.begin(); |
260 | QStringList channels; | 232 | QStringList channels; |
261 | while ( it != _channels.end() ) | 233 | while ( it != _channels.end() ) |
262 | { | 234 | { |
263 | channels += it.key(); | 235 | channels += it++.key(); |
264 | it++; | ||
265 | } | 236 | } |
266 | return channels; | 237 | return channels; |
267 | } | 238 | } |
268 | 239 | ||
269 | 240 | ||
270 | QStringList OMixerInterface::recChannels() const | 241 | QStringList OMixerInterface::recChannels() const |
271 | { | 242 | { |
272 | owarn << "NYI" << oendl; | 243 | ChannelIterator it = _channels.begin(); |
273 | return QStringList(); | 244 | QStringList channels; |
245 | while ( it != _channels.end() ) | ||
246 | { | ||
247 | if ( _recmask & ( 1 << _channels[it.key()] ) ) channels += it++.key(); | ||
248 | } | ||
249 | return channels; | ||
274 | } | 250 | } |
275 | 251 | ||
276 | 252 | ||
277 | QStringList OMixerInterface::playChannels() const | 253 | QStringList OMixerInterface::playChannels() const |
278 | { | 254 | { |
279 | owarn << "NYI" << oendl; | 255 | return allChannels(); |
280 | return QStringList(); | 256 | } |
257 | |||
258 | |||
259 | bool OMixerInterface::hasMultipleRecording() const | ||
260 | { | ||
261 | return !( _capmask & SOUND_CAP_EXCL_INPUT ); | ||
281 | } | 262 | } |
282 | 263 | ||
283 | 264 | ||
284 | bool OMixerInterface::hasChannel( const QString& channel ) const | 265 | bool OMixerInterface::hasChannel( const QString& channel ) const |
285 | { | 266 | { |
286 | return _channels.contains( channel ); | 267 | return _channels.contains( channel ); |
287 | } | 268 | } |
288 | 269 | ||
289 | 270 | ||
290 | bool OMixerInterface::isStereo( const QString& channel ) const | 271 | bool OMixerInterface::isStereo( const QString& channel ) const |
291 | { | 272 | { |
292 | bool result = false; | 273 | return _channels.contains( channel ) && ( _stmask & ( 1 << _channels[channel] ) ); |
293 | if ( _channels.contains( channel ) ) | 274 | } |
294 | { | 275 | |
295 | int devmask = 0; | 276 | |
296 | if ( ioctl( _fd, SOUND_MIXER_READ_STEREODEVS, &devmask ) != -1 ) | 277 | bool OMixerInterface::isRecordable( const QString& channel ) const |
297 | { | 278 | { |
298 | result = devmask & ( 1 << _channels[channel] ); | 279 | return _channels.contains( channel ) && ( _recmask & ( 1 << _channels[channel] ) ); |
299 | } | ||
300 | } | ||
301 | return result; | ||
302 | } | 280 | } |
303 | 281 | ||
304 | 282 | ||
305 | void OMixerInterface::setVolume( const QString& channel, int left, int right ) | 283 | void OMixerInterface::setVolume( const QString& channel, int left, int right ) |
306 | { | 284 | { |
307 | int volume = left; | 285 | int volume = left; |
308 | volume |= ( right == -1 ) ? left << 8 : right << 8; | 286 | volume |= ( right == -1 ) ? left << 8 : right << 8; |
309 | 287 | ||
310 | if ( _channels.contains( channel ) ) | 288 | if ( _channels.contains( channel ) ) |
311 | { | 289 | { |
312 | int result = ioctl( _fd, MIXER_WRITE( _channels[channel] ), &volume ); | 290 | int result = ioctl( _fd, MIXER_WRITE( _channels[channel] ), &volume ); |
313 | if ( result == -1 ) | 291 | if ( result == -1 ) |
diff --git a/libopie2/opiemm/osoundsystem.h b/libopie2/opiemm/osoundsystem.h index ac7a5a7..cce90c0 100644 --- a/libopie2/opiemm/osoundsystem.h +++ b/libopie2/opiemm/osoundsystem.h | |||
@@ -1,16 +1,15 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | (C) 2003-2005 Michael 'Mickey' Lauer <mickey@Vanille.de> | |
4 | (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | ||
5 | =. | 4 | =. |
6 | .=l. | 5 | .=l. |
7 | .>+-= | 6 | .>+-= |
8 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
9 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
11 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
12 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
13 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
14 | .%`+i> _;_. | 13 | .%`+i> _;_. |
15 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
@@ -189,48 +188,58 @@ class OMixerInterface : public QObject | |||
189 | /** | 188 | /** |
190 | * @returns all available channels. | 189 | * @returns all available channels. |
191 | */ | 190 | */ |
192 | QStringList allChannels() const; | 191 | QStringList allChannels() const; |
193 | /** | 192 | /** |
194 | * @returns recordable channels. | 193 | * @returns recordable channels. |
195 | */ | 194 | */ |
196 | QStringList recChannels() const; | 195 | QStringList recChannels() const; |
197 | /** | 196 | /** |
198 | * @returns playable channels. | 197 | * @returns playable channels. |
199 | */ | 198 | */ |
200 | QStringList playChannels() const; | 199 | QStringList playChannels() const; |
201 | 200 | /** | |
201 | * @returns true, if the device features multiple recording sources. | ||
202 | */ | ||
203 | bool hasMultipleRecording() const; | ||
202 | /** | 204 | /** |
203 | * @returns true, if @a channel exists. | 205 | * @returns true, if @a channel exists. |
204 | */ | 206 | */ |
205 | bool hasChannel( const QString& channel ) const; | 207 | bool hasChannel( const QString& channel ) const; |
206 | /** | 208 | /** |
207 | * @returns true, if @a channel is stereo. | 209 | * @returns true, if @a channel is stereo. |
208 | */ | 210 | */ |
209 | bool isStereo( const QString& channel ) const; | 211 | bool isStereo( const QString& channel ) const; |
210 | 212 | /** | |
213 | * @returns tru, if @a channel is a possible recording source. | ||
214 | */ | ||
215 | bool isRecordable( const QString& channel ) const; | ||
211 | /** | 216 | /** |
212 | * Set the @a left and @a right volumes for @a channel. | 217 | * Set the @a left and @a right volumes for @a channel. |
213 | * If no value for right is given, the value for left is taken for that. | 218 | * If no value for right is given, the value for left is taken for that. |
214 | */ | 219 | */ |
215 | void setVolume( const QString& channel, int left, int right = -1 ); | 220 | void setVolume( const QString& channel, int left, int right = -1 ); |
216 | /** | 221 | /** |
217 | * @returns the volume of @a channel or -1, if the channel doesn't exist. | 222 | * @returns the volume of @a channel or -1, if the channel doesn't exist. |
218 | * @note You might want to use @ref hasChannel() to check if a channel exists. | 223 | * @note You might want to use @ref hasChannel() to check if a channel exists. |
219 | */ | 224 | */ |
220 | int volume( const QString& channel ) const; | 225 | int volume( const QString& channel ) const; |
221 | 226 | ||
222 | protected: | 227 | protected: |
223 | int _fd; | 228 | int _fd; |
224 | QMap<QString, int> _channels; | 229 | int _capmask; |
230 | int _devmask; | ||
231 | int _recmask; | ||
232 | int _stmask; | ||
233 | QMap<QString,int> _channels; | ||
225 | 234 | ||
226 | private: | 235 | private: |
227 | void init(); | 236 | void init(); |
228 | private: | 237 | private: |
229 | class Private; | 238 | class Private; |
230 | Private *d; | 239 | Private *d; |
231 | }; | 240 | }; |
232 | 241 | ||
233 | } | 242 | } |
234 | } | 243 | } |
235 | 244 | ||
236 | #endif // OSOUNDSYSTEM_H | 245 | #endif // OSOUNDSYSTEM_H |