summaryrefslogtreecommitdiff
path: root/libopie2/opiemm
Unidiff
Diffstat (limited to 'libopie2/opiemm') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiemm/osoundsystem.cpp4
1 files changed, 0 insertions, 4 deletions
diff --git a/libopie2/opiemm/osoundsystem.cpp b/libopie2/opiemm/osoundsystem.cpp
index 6c03203..2956682 100644
--- a/libopie2/opiemm/osoundsystem.cpp
+++ b/libopie2/opiemm/osoundsystem.cpp
@@ -1,319 +1,315 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              (C) 2003-2005 Michael 'Mickey' Lauer <mickey@Vanille.de> 3              (C) 2003-2005 Michael 'Mickey' Lauer <mickey@Vanille.de>
4 =. 4 =.
5 .=l. 5 .=l.
6           .>+-= 6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can 7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License, 11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version. 12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that 14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details. 20++=   -.     .`     .: details.
21 :     =  ...= . :.=- 21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28 28
29*/ 29*/
30 30
31#include <opie2/osoundsystem.h> 31#include <opie2/osoundsystem.h>
32#include <opie2/odebug.h> 32#include <opie2/odebug.h>
33 33
34#include <errno.h> 34#include <errno.h>
35#include <fcntl.h> 35#include <fcntl.h>
36#include <string.h> 36#include <string.h>
37#include <sys/ioctl.h> 37#include <sys/ioctl.h>
38#include <sys/types.h> 38#include <sys/types.h>
39#include <sys/soundcard.h> 39#include <sys/soundcard.h>
40#include <sys/stat.h> 40#include <sys/stat.h>
41 41
42static const char* device_label[] = SOUND_DEVICE_LABELS; 42static const char* device_label[] = SOUND_DEVICE_LABELS;
43static int max_device_nr = sizeof device_label / sizeof (const char*); 43static int max_device_nr = sizeof device_label / sizeof (const char*);
44 44
45using namespace Opie::Core; 45using namespace Opie::Core;
46using namespace Opie::MM; 46using namespace Opie::MM;
47/*====================================================================================== 47/*======================================================================================
48 * OSoundSystem 48 * OSoundSystem
49 *======================================================================================*/ 49 *======================================================================================*/
50 50
51OSoundSystem* OSoundSystem::_instance = 0; 51OSoundSystem* OSoundSystem::_instance = 0;
52 52
53OSoundSystem::OSoundSystem() 53OSoundSystem::OSoundSystem()
54{ 54{
55 odebug << "OSoundSystem::OSoundSystem()" << oendl; 55 odebug << "OSoundSystem::OSoundSystem()" << oendl;
56 synchronize(); 56 synchronize();
57} 57}
58 58
59void OSoundSystem::synchronize() 59void OSoundSystem::synchronize()
60{ 60{
61 // gather available interfaces by inspecting /dev
62 //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices
63 //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices
64
65 _interfaces.clear(); 61 _interfaces.clear();
66 _interfaces.insert( "soundcard", new OSoundCard( this, "soundcard" ) ); 62 _interfaces.insert( "soundcard", new OSoundCard( this, "soundcard" ) );
67 63
68 /* 64 /*
69 65
70 QString str; 66 QString str;
71 QFile f( "/dev/sound" ); 67 QFile f( "/dev/sound" );
72 bool hasFile = f.open( IO_ReadOnly ); 68 bool hasFile = f.open( IO_ReadOnly );
73 if ( !hasFile ) 69 if ( !hasFile )
74 { 70 {
75 odebug << "OSoundSystem: /dev/sound not existing. No sound devices available" << oendl; 71 odebug << "OSoundSystem: /dev/sound not existing. No sound devices available" << oendl;
76 return; 72 return;
77 } 73 }
78 QTextStream s( &f ); 74 QTextStream s( &f );
79 s.readLine(); 75 s.readLine();
80 s.readLine(); 76 s.readLine();
81 while ( !s.atEnd() ) 77 while ( !s.atEnd() )
82 { 78 {
83 s >> str; 79 s >> str;
84 str.truncate( str.find( ':' ) ); 80 str.truncate( str.find( ':' ) );
85 odebug << "OSoundSystem: found interface '" << str << "'" << oendl; 81 odebug << "OSoundSystem: found interface '" << str << "'" << oendl;
86 OAudioInterface* iface; 82 OAudioInterface* iface;
87 iface = new OAudioInterface( this, (const char*) str ); 83 iface = new OAudioInterface( this, (const char*) str );
88 84
89 _interfaces.insert( str, iface ); 85 _interfaces.insert( str, iface );
90 s.readLine(); 86 s.readLine();
91 } 87 }
92*/ 88*/
93} 89}
94 90
95 91
96int OSoundSystem::count() const 92int OSoundSystem::count() const
97{ 93{
98 return _interfaces.count(); 94 return _interfaces.count();
99} 95}
100 96
101 97
102OSoundCard* OSoundSystem::card( const QString& iface ) const 98OSoundCard* OSoundSystem::card( const QString& iface ) const
103{ 99{
104 return _interfaces[iface]; 100 return _interfaces[iface];
105} 101}
106 102
107 103
108OSoundSystem* OSoundSystem::instance() 104OSoundSystem* OSoundSystem::instance()
109{ 105{
110 if ( !_instance ) _instance = new OSoundSystem(); 106 if ( !_instance ) _instance = new OSoundSystem();
111 return _instance; 107 return _instance;
112} 108}
113 109
114 110
115OSoundSystem::CardIterator OSoundSystem::iterator() const 111OSoundSystem::CardIterator OSoundSystem::iterator() const
116{ 112{
117 return OSoundSystem::CardIterator( _interfaces ); 113 return OSoundSystem::CardIterator( _interfaces );
118} 114}
119 115
120 116
121/*====================================================================================== 117/*======================================================================================
122 * OSoundCard 118 * OSoundCard
123 *======================================================================================*/ 119 *======================================================================================*/
124 120
125OSoundCard::OSoundCard( QObject* parent, const char* name ) 121OSoundCard::OSoundCard( QObject* parent, const char* name )
126 :QObject( parent, name ), _audio( 0 ), _mixer( 0 ) 122 :QObject( parent, name ), _audio( 0 ), _mixer( 0 )
127{ 123{
128 odebug << "OSoundCard::OSoundCard()" << oendl; 124 odebug << "OSoundCard::OSoundCard()" << oendl;
129 init(); 125 init();
130} 126}
131 127
132 128
133OSoundCard::~OSoundCard() 129OSoundCard::~OSoundCard()
134{ 130{
135} 131}
136 132
137 133
138void OSoundCard::init() 134void OSoundCard::init()
139{ 135{
140#ifdef QT_QWS_DEVFS 136#ifdef QT_QWS_DEVFS
141 _audio = new OAudioInterface( this, "/dev/sound/dsp" ); 137 _audio = new OAudioInterface( this, "/dev/sound/dsp" );
142 _mixer = new OMixerInterface( this, "/dev/sound/mixer" ); 138 _mixer = new OMixerInterface( this, "/dev/sound/mixer" );
143#else 139#else
144 _audio = new OAudioInterface( this, "/dev/dsp" ); 140 _audio = new OAudioInterface( this, "/dev/dsp" );
145 _mixer = new OMixerInterface( this, "/dev/mixer" ); 141 _mixer = new OMixerInterface( this, "/dev/mixer" );
146#endif 142#endif
147} 143}
148 144
149 145
150/*====================================================================================== 146/*======================================================================================
151 * OAudioInterface 147 * OAudioInterface
152 *======================================================================================*/ 148 *======================================================================================*/
153 149
154OAudioInterface::OAudioInterface( QObject* parent, const char* name ) 150OAudioInterface::OAudioInterface( QObject* parent, const char* name )
155 :QObject( parent, name ), _sfd(0) 151 :QObject( parent, name ), _sfd(0)
156{ 152{
157 odebug << "OAudioInterface::OAudioInterface()" << oendl; 153 odebug << "OAudioInterface::OAudioInterface()" << oendl;
158 init(); 154 init();
159} 155}
160 156
161 157
162OAudioInterface::~OAudioInterface() 158OAudioInterface::~OAudioInterface()
163{ 159{
164} 160}
165 161
166 162
167void OAudioInterface::init() 163void OAudioInterface::init()
168{ 164{
169 165
170 166
171} 167}
172 168
173 169
174/*====================================================================================== 170/*======================================================================================
175 * OMixerInterface 171 * OMixerInterface
176 *======================================================================================*/ 172 *======================================================================================*/
177 173
178OMixerInterface::OMixerInterface( QObject* parent, const char* name ) 174OMixerInterface::OMixerInterface( QObject* parent, const char* name )
179 :QObject( parent, name ), _devmask( 0 ), _recmask( 0 ), _stmask( 0 ) 175 :QObject( parent, name ), _devmask( 0 ), _recmask( 0 ), _stmask( 0 )
180{ 176{
181 odebug << "OMixerInterface::OMixerInterface()" << oendl; 177 odebug << "OMixerInterface::OMixerInterface()" << oendl;
182 init(); 178 init();
183} 179}
184 180
185 181
186OMixerInterface::~OMixerInterface() 182OMixerInterface::~OMixerInterface()
187{ 183{
188} 184}
189 185
190 186
191void OMixerInterface::init() 187void OMixerInterface::init()
192{ 188{
193 // open the device 189 // open the device
194 _fd = ::open( name(), O_RDWR ); 190 _fd = ::open( name(), O_RDWR );
195 if ( _fd == -1 ) 191 if ( _fd == -1 )
196 { 192 {
197 owarn << "OMixerInterface::init(): Can't open mixer " << name() << oendl; 193 owarn << "OMixerInterface::init(): Can't open mixer " << name() << oendl;
198 return; 194 return;
199 } 195 }
200 196
201 // construct the device capabilities 197 // construct the device capabilities
202 if ( ioctl( _fd, SOUND_MIXER_READ_CAPS, &_capmask ) != -1 ) 198 if ( ioctl( _fd, SOUND_MIXER_READ_CAPS, &_capmask ) != -1 )
203 { 199 {
204 odebug << "OMixerInterface::init() - capmask = " << _capmask << oendl; 200 odebug << "OMixerInterface::init() - capmask = " << _capmask << oendl;
205 } 201 }
206 if ( ioctl( _fd, SOUND_MIXER_READ_DEVMASK, &_devmask ) != -1 ) 202 if ( ioctl( _fd, SOUND_MIXER_READ_DEVMASK, &_devmask ) != -1 )
207 { 203 {
208 odebug << "OMixerInterface::init() - devmask = " << _devmask << oendl; 204 odebug << "OMixerInterface::init() - devmask = " << _devmask << oendl;
209 } 205 }
210 if ( ioctl( _fd, SOUND_MIXER_READ_RECMASK, &_recmask ) != -1 ) 206 if ( ioctl( _fd, SOUND_MIXER_READ_RECMASK, &_recmask ) != -1 )
211 { 207 {
212 odebug << "OMixerInterface::init() - recmask = " << _recmask << oendl; 208 odebug << "OMixerInterface::init() - recmask = " << _recmask << oendl;
213 } 209 }
214 if ( ioctl( _fd, SOUND_MIXER_READ_STEREODEVS, &_stmask ) != -1 ) 210 if ( ioctl( _fd, SOUND_MIXER_READ_STEREODEVS, &_stmask ) != -1 )
215 { 211 {
216 odebug << "OMixerInterface::init() - stereomask = " << _stmask << oendl; 212 odebug << "OMixerInterface::init() - stereomask = " << _stmask << oendl;
217 } 213 }
218 for ( int i = 0; i < max_device_nr; ++i ) 214 for ( int i = 0; i < max_device_nr; ++i )
219 { 215 {
220 if ( _devmask & ( 1 << i ) ) 216 if ( _devmask & ( 1 << i ) )
221 { 217 {
222 _channels.insert( QString( device_label[i] ).stripWhiteSpace(), i ); 218 _channels.insert( QString( device_label[i] ).stripWhiteSpace(), i );
223 odebug << "OMixerInterface::init() - channel '" << device_label[i] << "'" << oendl; 219 odebug << "OMixerInterface::init() - channel '" << device_label[i] << "'" << oendl;
224 } 220 }
225 } 221 }
226} 222}
227 223
228 224
229QStringList OMixerInterface::allChannels() const 225QStringList OMixerInterface::allChannels() const
230{ 226{
231 ChannelIterator it = _channels.begin(); 227 ChannelIterator it = _channels.begin();
232 QStringList channels; 228 QStringList channels;
233 while ( it != _channels.end() ) 229 while ( it != _channels.end() )
234 { 230 {
235 channels += it++.key(); 231 channels += it++.key();
236 } 232 }
237 return channels; 233 return channels;
238} 234}
239 235
240 236
241QStringList OMixerInterface::recChannels() const 237QStringList OMixerInterface::recChannels() const
242{ 238{
243 ChannelIterator it = _channels.begin(); 239 ChannelIterator it = _channels.begin();
244 QStringList channels; 240 QStringList channels;
245 while ( it != _channels.end() ) 241 while ( it != _channels.end() )
246 { 242 {
247 if ( _recmask & ( 1 << _channels[it.key()] ) ) channels += it++.key(); 243 if ( _recmask & ( 1 << _channels[it.key()] ) ) channels += it++.key();
248 } 244 }
249 return channels; 245 return channels;
250} 246}
251 247
252 248
253QStringList OMixerInterface::playChannels() const 249QStringList OMixerInterface::playChannels() const
254{ 250{
255 return allChannels(); 251 return allChannels();
256} 252}
257 253
258 254
259bool OMixerInterface::hasMultipleRecording() const 255bool OMixerInterface::hasMultipleRecording() const
260{ 256{
261 return !( _capmask & SOUND_CAP_EXCL_INPUT ); 257 return !( _capmask & SOUND_CAP_EXCL_INPUT );
262} 258}
263 259
264 260
265bool OMixerInterface::hasChannel( const QString& channel ) const 261bool OMixerInterface::hasChannel( const QString& channel ) const
266{ 262{
267 return _channels.contains( channel ); 263 return _channels.contains( channel );
268} 264}
269 265
270 266
271bool OMixerInterface::isStereo( const QString& channel ) const 267bool OMixerInterface::isStereo( const QString& channel ) const
272{ 268{
273 return _channels.contains( channel ) && ( _stmask & ( 1 << _channels[channel] ) ); 269 return _channels.contains( channel ) && ( _stmask & ( 1 << _channels[channel] ) );
274} 270}
275 271
276 272
277bool OMixerInterface::isRecordable( const QString& channel ) const 273bool OMixerInterface::isRecordable( const QString& channel ) const
278{ 274{
279 return _channels.contains( channel ) && ( _recmask & ( 1 << _channels[channel] ) ); 275 return _channels.contains( channel ) && ( _recmask & ( 1 << _channels[channel] ) );
280} 276}
281 277
282 278
283void OMixerInterface::setVolume( const QString& channel, int left, int right ) 279void OMixerInterface::setVolume( const QString& channel, int left, int right )
284{ 280{
285 int volume = left; 281 int volume = left;
286 volume |= ( right == -1 ) ? left << 8 : right << 8; 282 volume |= ( right == -1 ) ? left << 8 : right << 8;
287 283
288 if ( _channels.contains( channel ) ) 284 if ( _channels.contains( channel ) )
289 { 285 {
290 int result = ioctl( _fd, MIXER_WRITE( _channels[channel] ), &volume ); 286 int result = ioctl( _fd, MIXER_WRITE( _channels[channel] ), &volume );
291 if ( result == -1 ) 287 if ( result == -1 )
292 { 288 {
293 owarn << "Can't set volume: " << strerror( errno ) << oendl; 289 owarn << "Can't set volume: " << strerror( errno ) << oendl;
294 } 290 }
295 else 291 else
296 { 292 {
297 if ( result & 0xff != left ) 293 if ( result & 0xff != left )
298 { 294 {
299 owarn << "Device adjusted volume from " << left << " to " << (result & 0xff) << oendl; 295 owarn << "Device adjusted volume from " << left << " to " << (result & 0xff) << oendl;
300 } 296 }
301 } 297 }
302 } 298 }
303} 299}
304 300
305 301
306int OMixerInterface::volume( const QString& channel ) const 302int OMixerInterface::volume( const QString& channel ) const
307{ 303{
308 int volume; 304 int volume;
309 305
310 if ( _channels.contains( channel ) ) 306 if ( _channels.contains( channel ) )
311 { 307 {
312 if ( ioctl( _fd, MIXER_READ( _channels[channel] ), &volume ) == -1 ) 308 if ( ioctl( _fd, MIXER_READ( _channels[channel] ), &volume ) == -1 )
313 { 309 {
314 owarn << "Can't get volume: " << strerror( errno ) << oendl; 310 owarn << "Can't get volume: " << strerror( errno ) << oendl;
315 } 311 }
316 else return volume; 312 else return volume;
317 } 313 }
318 return -1; 314 return -1;
319} 315}