summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2005-01-30 19:00:38 (UTC)
committer mickeyl <mickeyl>2005-01-30 19:00:38 (UTC)
commitc3b5d1ebb51848a679f96ac3bb1c8acb1b06138e (patch) (unidiff)
tree9ac1d1281b3bdd92d1975bdc7756e89ebe730f34
parent271dd6ba75ddfba5ac4345e9d74db4dbb2b7c971 (diff)
downloadopie-c3b5d1ebb51848a679f96ac3bb1c8acb1b06138e.zip
opie-c3b5d1ebb51848a679f96ac3bb1c8acb1b06138e.tar.gz
opie-c3b5d1ebb51848a679f96ac3bb1c8acb1b06138e.tar.bz2
improve mixer code
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--examples/opiemm/osoundsystemdemo/osoundsystemdemo.cpp14
-rw-r--r--libopie2/config.in12
-rw-r--r--libopie2/opiemm/osoundsystem.cpp112
-rw-r--r--libopie2/opiemm/osoundsystem.h19
4 files changed, 69 insertions, 88 deletions
diff --git a/examples/opiemm/osoundsystemdemo/osoundsystemdemo.cpp b/examples/opiemm/osoundsystemdemo/osoundsystemdemo.cpp
index f74a1b9..b18d719 100644
--- a/examples/opiemm/osoundsystemdemo/osoundsystemdemo.cpp
+++ b/examples/opiemm/osoundsystemdemo/osoundsystemdemo.cpp
@@ -1,66 +1,72 @@
1/* 1/*
2 =. This file is part of the Opie Project 2 =. This file is part of the Opie Project
3 .=l. Copyright (C) 2004 Opie Team <opie-devel@handhelds.org> 3 .=l. Copyright (C) 2004 Opie Team <opie-devel@handhelds.org>
4 .>+-= 4 .>+-=
5 _;:, .> :=|. This library is free software; you can 5 _;:, .> :=|. This library is free software; you can
6.> <`_, > . <= redistribute it and/or modify it under 6.> <`_, > . <= redistribute it and/or modify it under
7:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 7:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
8.="- .-=="i, .._ License as published by the Free Software 8.="- .-=="i, .._ License as published by the Free Software
9 - . .-<_> .<> Foundation; either version 2 of the License, 9 - . .-<_> .<> Foundation; either version 2 of the License,
10 ._= =} : or (at your option) any later version. 10 ._= =} : or (at your option) any later version.
11 .%`+i> _;_. 11 .%`+i> _;_.
12 .i_,=:_. -<s. This library is distributed in the hope that 12 .i_,=:_. -<s. This library is distributed in the hope that
13 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 13 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
14 : .. .:, . . . without even the implied warranty of 14 : .. .:, . . . without even the implied warranty of
15 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 15 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
16 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 16 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.= = ; Library General Public License for more 17..}^=.= = ; Library General Public License for more
18++= -. .` .: details. 18++= -. .` .: details.
19 : = ...= . :.=- 19 : = ...= . :.=-
20 -. .:....=;==+<; You should have received a copy of the GNU 20 -. .:....=;==+<; You should have received a copy of the GNU
21 -_. . . )=. = Library General Public License along with 21 -_. . . )=. = Library General Public License along with
22 -- :-=` this library; see the file COPYING.LIB. 22 -- :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation, 23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, 24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29/* OPIE */ 29/* OPIE */
30#include <opie2/osoundsystem.h> 30#include <opie2/osoundsystem.h>
31#include <opie2/odebug.h> 31#include <opie2/odebug.h>
32 32
33using namespace Opie::MM; 33using namespace Opie::MM;
34 34
35int main( int argc, char** argv ) 35int main( int argc, char** argv )
36{ 36{
37 odebug << "OPIE Sound System Demo" << oendl; 37 odebug << "OPIE Sound System Demo" << oendl;
38 38
39 OSoundSystem* sound = OSoundSystem::instance(); 39 OSoundSystem* sound = OSoundSystem::instance();
40 40
41 OSoundSystem::CardIterator it = sound->iterator(); 41 OSoundSystem::CardIterator it = sound->iterator();
42/* 42/*
43 while ( it.current() ) 43 while ( it.current() )
44 { 44 {
45 odebug << "DEMO: OSoundSystem contains Interface '" << it.current()->name() << "'" << oendl; 45 odebug << "DEMO: OSoundSystem contains Interface '" << it.current()->name() << "'" << oendl;
46 ++it; 46 ++it;
47 } 47 }
48 48
49*/ 49*/
50 OSoundCard* card = it.current(); 50 OSoundCard* card = it.current();
51
52 OMixerInterface* mixer = card->mixer(); 51 OMixerInterface* mixer = card->mixer();
52 odebug << "This device " << ( mixer->hasMultipleRecording() ? "does" : "does not" ) << " feature multiple recording sources." << oendl;
53 53
54 QStringList channels = mixer->allChannels(); 54 QStringList channels = mixer->allChannels();
55 55
56 for ( QStringList::Iterator it = channels.begin(); it != channels.end(); ++it ) 56 for ( QStringList::Iterator it = channels.begin(); it != channels.end(); ++it )
57 { 57 {
58 bool stereo = mixer->isStereo( *it ); 58 bool stereo = mixer->isStereo( *it );
59 odebug << "OSSDEMO: Mixer has channel " << *it << ( stereo ? "[stereo]" : "[mono]" ) << oendl; 59 bool recsrc = mixer->isRecordable( *it );
60 odebug << "OSSDEMO: +--- volume " << ( mixer->volume( *it ) & 0xff ) 60 QString line = "OSSDEMO: Mixer has channel " + *it + " ";
61 << " (left) | " << ( mixer->volume( *it ) >> 8 ) << " (right)" << oendl; 61 line = line.leftJustify( 50 ) + ( stereo ? "[stereo]" : "[mono]" );
62 line = line.leftJustify( 60 ) + ( recsrc ? "[recsrc]" : "[ ]" );
63 line = line.leftJustify( 70 );
64 line += " [ " + QString::number( mixer->volume( *it ) & 0xff ).rightJustify( 3 );
65 if ( stereo ) line += " | " + QString::number( mixer->volume( *it ) >> 8 ).rightJustify( 3 );
66 line += " ]";
67 odebug << line << oendl;
62 } 68 }
63 69
64 return 0; 70 return 0;
65 71
66} 72}
diff --git a/libopie2/config.in b/libopie2/config.in
deleted file mode 100644
index 5f1bed3..0000000
--- a/libopie2/config.in
+++ b/dev/null
@@ -1,12 +0,0 @@
1#menu "libopie2"
2 comment ""
3 source libopie2/opiecore/config.in
4 source libopie2/opiedb/config.in
5 source libopie2/opienet/config.in
6 source libopie2/opiepim/config.in
7 source libopie2/opieui/config.in
8 source libopie2/opiemm/config.in
9 source libopie2/opiesecurity/config.in
10 comment ""
11#endmenu
12
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,341 +1,319 @@
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;
17    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 20++=   -.     .`     .: details.
22 :     =  ...= . :.=- 21 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
29 28
30*/ 29*/
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
42static const char* device_label[] = SOUND_DEVICE_LABELS;
43static int max_device_nr = sizeof device_label / sizeof (const char*);
43 44
44using namespace Opie::Core; 45using namespace Opie::Core;
45using namespace Opie::MM; 46using namespace Opie::MM;
46/*====================================================================================== 47/*======================================================================================
47 * OSoundSystem 48 * OSoundSystem
48 *======================================================================================*/ 49 *======================================================================================*/
49 50
50OSoundSystem* OSoundSystem::_instance = 0; 51OSoundSystem* OSoundSystem::_instance = 0;
51 52
52OSoundSystem::OSoundSystem() 53OSoundSystem::OSoundSystem()
53{ 54{
54 odebug << "OSoundSystem::OSoundSystem()" << oendl; 55 odebug << "OSoundSystem::OSoundSystem()" << oendl;
55 synchronize(); 56 synchronize();
56} 57}
57 58
58void OSoundSystem::synchronize() 59void 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();
80 s.readLine(); 80 s.readLine();
81 while ( !s.atEnd() ) 81 while ( !s.atEnd() )
82 { 82 {
83 s >> str; 83 s >> str;
84 str.truncate( str.find( ':' ) ); 84 str.truncate( str.find( ':' ) );
85 odebug << "OSoundSystem: found interface '" << str << "'" << oendl; 85 odebug << "OSoundSystem: found interface '" << str << "'" << oendl;
86 OAudioInterface* iface; 86 OAudioInterface* iface;
87 iface = new OAudioInterface( this, (const char*) str ); 87 iface = new OAudioInterface( this, (const char*) str );
88 88
89 _interfaces.insert( str, iface ); 89 _interfaces.insert( str, iface );
90 s.readLine(); 90 s.readLine();
91 } 91 }
92*/ 92*/
93} 93}
94 94
95 95
96int OSoundSystem::count() const 96int OSoundSystem::count() const
97{ 97{
98 return _interfaces.count(); 98 return _interfaces.count();
99} 99}
100 100
101 101
102OSoundCard* OSoundSystem::card( const QString& iface ) const 102OSoundCard* OSoundSystem::card( const QString& iface ) const
103{ 103{
104 return _interfaces[iface]; 104 return _interfaces[iface];
105} 105}
106 106
107 107
108OSoundSystem* OSoundSystem::instance() 108OSoundSystem* OSoundSystem::instance()
109{ 109{
110 if ( !_instance ) _instance = new OSoundSystem(); 110 if ( !_instance ) _instance = new OSoundSystem();
111 return _instance; 111 return _instance;
112} 112}
113 113
114 114
115OSoundSystem::CardIterator OSoundSystem::iterator() const 115OSoundSystem::CardIterator OSoundSystem::iterator() const
116{ 116{
117 return OSoundSystem::CardIterator( _interfaces ); 117 return OSoundSystem::CardIterator( _interfaces );
118} 118}
119 119
120 120
121/*====================================================================================== 121/*======================================================================================
122 * OSoundCard 122 * OSoundCard
123 *======================================================================================*/ 123 *======================================================================================*/
124 124
125OSoundCard::OSoundCard( QObject* parent, const char* name ) 125OSoundCard::OSoundCard( QObject* parent, const char* name )
126 :QObject( parent, name ), _audio( 0 ), _mixer( 0 ) 126 :QObject( parent, name ), _audio( 0 ), _mixer( 0 )
127{ 127{
128 odebug << "OSoundCard::OSoundCard()" << oendl; 128 odebug << "OSoundCard::OSoundCard()" << oendl;
129 init(); 129 init();
130} 130}
131 131
132 132
133OSoundCard::~OSoundCard() 133OSoundCard::~OSoundCard()
134{ 134{
135} 135}
136 136
137 137
138void OSoundCard::init() 138void OSoundCard::init()
139{ 139{
140#ifdef QT_QWS_DEVFS 140#ifdef QT_QWS_DEVFS
141 _audio = new OAudioInterface( this, "/dev/sound/dsp" ); 141 _audio = new OAudioInterface( this, "/dev/sound/dsp" );
142 _mixer = new OMixerInterface( this, "/dev/sound/mixer" ); 142 _mixer = new OMixerInterface( this, "/dev/sound/mixer" );
143#else 143#else
144 _audio = new OAudioInterface( this, "/dev/dsp" ); 144 _audio = new OAudioInterface( this, "/dev/dsp" );
145 _mixer = new OMixerInterface( this, "/dev/mixer" ); 145 _mixer = new OMixerInterface( this, "/dev/mixer" );
146#endif 146#endif
147} 147}
148 148
149 149
150/*====================================================================================== 150/*======================================================================================
151 * OAudioInterface 151 * OAudioInterface
152 *======================================================================================*/ 152 *======================================================================================*/
153 153
154OAudioInterface::OAudioInterface( QObject* parent, const char* name ) 154OAudioInterface::OAudioInterface( QObject* parent, const char* name )
155 :QObject( parent, name ), _sfd(0) 155 :QObject( parent, name ), _sfd(0)
156{ 156{
157 odebug << "OAudioInterface::OAudioInterface()" << oendl; 157 odebug << "OAudioInterface::OAudioInterface()" << oendl;
158 init(); 158 init();
159} 159}
160 160
161 161
162OAudioInterface::~OAudioInterface() 162OAudioInterface::~OAudioInterface()
163{ 163{
164} 164}
165 165
166 166
167void OAudioInterface::init() 167void OAudioInterface::init()
168{ 168{
169 169
170 170
171} 171}
172 172
173 173
174/*====================================================================================== 174/*======================================================================================
175 * OMixerInterface 175 * OMixerInterface
176 *======================================================================================*/ 176 *======================================================================================*/
177 177
178OMixerInterface::OMixerInterface( QObject* parent, const char* name ) 178OMixerInterface::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
186OMixerInterface::~OMixerInterface() 186OMixerInterface::~OMixerInterface()
187{ 187{
188} 188}
189 189
190 190
191void OMixerInterface::init() 191void 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
257QStringList OMixerInterface::allChannels() const 229QStringList 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
270QStringList OMixerInterface::recChannels() const 241QStringList 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
277QStringList OMixerInterface::playChannels() const 253QStringList OMixerInterface::playChannels() const
278{ 254{
279 owarn << "NYI" << oendl; 255 return allChannels();
280 return QStringList(); 256}
257
258
259bool OMixerInterface::hasMultipleRecording() const
260{
261 return !( _capmask & SOUND_CAP_EXCL_INPUT );
281} 262}
282 263
283 264
284bool OMixerInterface::hasChannel( const QString& channel ) const 265bool OMixerInterface::hasChannel( const QString& channel ) const
285{ 266{
286 return _channels.contains( channel ); 267 return _channels.contains( channel );
287} 268}
288 269
289 270
290bool OMixerInterface::isStereo( const QString& channel ) const 271bool 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 ) 277bool 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
305void OMixerInterface::setVolume( const QString& channel, int left, int right ) 283void 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 )
314 { 292 {
315 owarn << "Can't set volume: " << strerror( errno ) << oendl; 293 owarn << "Can't set volume: " << strerror( errno ) << oendl;
316 } 294 }
317 else 295 else
318 { 296 {
319 if ( result & 0xff != left ) 297 if ( result & 0xff != left )
320 { 298 {
321 owarn << "Device adjusted volume from " << left << " to " << (result & 0xff) << oendl; 299 owarn << "Device adjusted volume from " << left << " to " << (result & 0xff) << oendl;
322 } 300 }
323 } 301 }
324 } 302 }
325} 303}
326 304
327 305
328int OMixerInterface::volume( const QString& channel ) const 306int OMixerInterface::volume( const QString& channel ) const
329{ 307{
330 int volume; 308 int volume;
331 309
332 if ( _channels.contains( channel ) ) 310 if ( _channels.contains( channel ) )
333 { 311 {
334 if ( ioctl( _fd, MIXER_READ( _channels[channel] ), &volume ) == -1 ) 312 if ( ioctl( _fd, MIXER_READ( _channels[channel] ), &volume ) == -1 )
335 { 313 {
336 owarn << "Can't get volume: " << strerror( errno ) << oendl; 314 owarn << "Can't get volume: " << strerror( errno ) << oendl;
337 } 315 }
338 else return volume; 316 else return volume;
339 } 317 }
340 return -1; 318 return -1;
341} 319}
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,100 +1,99 @@
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;
17    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 20++=   -.     .`     .: details.
22 :     =  ...= . :.=- 21 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
29 28
30*/ 29*/
31 30
32#ifndef OSOUNDSYSTEM_H 31#ifndef OSOUNDSYSTEM_H
33#define OSOUNDSYSTEM_H 32#define OSOUNDSYSTEM_H
34 33
35#include <qobject.h> 34#include <qobject.h>
36#include <qdict.h> 35#include <qdict.h>
37#include <qmap.h> 36#include <qmap.h>
38 37
39namespace Opie { 38namespace Opie {
40namespace MM { 39namespace MM {
41 40
42class OAudioInterface; 41class OAudioInterface;
43class OMixerInterface; 42class OMixerInterface;
44class OSoundCard; 43class OSoundCard;
45 44
46/*====================================================================================== 45/*======================================================================================
47 * OSoundSystem 46 * OSoundSystem
48 *======================================================================================*/ 47 *======================================================================================*/
49 48
50/** 49/**
51 * @brief A container class for all audio interfaces 50 * @brief A container class for all audio interfaces
52 * 51 *
53 * This class provides access to all available audio/midi/sequencer interfaces of your computer. 52 * This class provides access to all available audio/midi/sequencer interfaces of your computer.
54 * 53 *
55 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 54 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
56 */ 55 */
57class OSoundSystem : public QObject 56class OSoundSystem : public QObject
58{ 57{
59 Q_OBJECT 58 Q_OBJECT
60 59
61 public: 60 public:
62 typedef QDict<OSoundCard> CardMap; 61 typedef QDict<OSoundCard> CardMap;
63 typedef QDictIterator<OSoundCard> CardIterator; 62 typedef QDictIterator<OSoundCard> CardIterator;
64 63
65 public: 64 public:
66 /** 65 /**
67 * @returns the number of available interfaces 66 * @returns the number of available interfaces
68 */ 67 */
69 int count() const; 68 int count() const;
70 /** 69 /**
71 * @returns a pointer to the (one and only) @ref ONetwork instance. 70 * @returns a pointer to the (one and only) @ref ONetwork instance.
72 */ 71 */
73 static OSoundSystem* instance(); 72 static OSoundSystem* instance();
74 /** 73 /**
75 * @returns an iterator usable for iterating through all network interfaces. 74 * @returns an iterator usable for iterating through all network interfaces.
76 */ 75 */
77 CardIterator iterator() const; 76 CardIterator iterator() const;
78 /** 77 /**
79 * @returns a pointer to the @ref OAudioInterface object for the specified @a interface or 0, if not found 78 * @returns a pointer to the @ref OAudioInterface object for the specified @a interface or 0, if not found
80 * @see OAudioInterface 79 * @see OAudioInterface
81 */ 80 */
82 OSoundCard* card( const QString& interface ) const; 81 OSoundCard* card( const QString& interface ) const;
83 /** 82 /**
84 * @internal Rebuild the internal interface database 83 * @internal Rebuild the internal interface database
85 * @note Sometimes it might be useful to call this from client code, 84 * @note Sometimes it might be useful to call this from client code,
86 * e.g. after issuing a cardctl insert 85 * e.g. after issuing a cardctl insert
87 */ 86 */
88 void synchronize(); 87 void synchronize();
89 88
90 protected: 89 protected:
91 OSoundSystem(); 90 OSoundSystem();
92 91
93 private: 92 private:
94 static OSoundSystem* _instance; 93 static OSoundSystem* _instance;
95 CardMap _interfaces; 94 CardMap _interfaces;
96 class Private; 95 class Private;
97 Private *d; 96 Private *d;
98}; 97};
99 98
100 99
@@ -105,132 +104,142 @@ class OSoundSystem : public QObject
105class OSoundCard : public QObject 104class OSoundCard : public QObject
106{ 105{
107 Q_OBJECT 106 Q_OBJECT
108 107
109 public: 108 public:
110 /** 109 /**
111 * Constructor. Normally you don't create @ref OSoundCard objects yourself, 110 * Constructor. Normally you don't create @ref OSoundCard objects yourself,
112 * but access them via @ref OSoundSystem::card(). 111 * but access them via @ref OSoundSystem::card().
113 */ 112 */
114 OSoundCard( QObject* parent, const char* name ); 113 OSoundCard( QObject* parent, const char* name );
115 /** 114 /**
116 * Destructor. 115 * Destructor.
117 */ 116 */
118 virtual ~OSoundCard(); 117 virtual ~OSoundCard();
119 118
120 bool hasMixer() const { return _audio; }; 119 bool hasMixer() const { return _audio; };
121 bool hasAudio() const { return _mixer; }; 120 bool hasAudio() const { return _mixer; };
122 121
123 OAudioInterface* audio() const { return _audio; }; 122 OAudioInterface* audio() const { return _audio; };
124 OMixerInterface* mixer() const { return _mixer; }; 123 OMixerInterface* mixer() const { return _mixer; };
125 124
126 protected: 125 protected:
127 OAudioInterface* _audio; 126 OAudioInterface* _audio;
128 OMixerInterface* _mixer; 127 OMixerInterface* _mixer;
129 128
130 private: 129 private:
131 void init(); 130 void init();
132 private: 131 private:
133 class Private; 132 class Private;
134 Private *d; 133 Private *d;
135}; 134};
136 135
137/*====================================================================================== 136/*======================================================================================
138 * OAudioInterface 137 * OAudioInterface
139 *======================================================================================*/ 138 *======================================================================================*/
140 139
141class OAudioInterface : public QObject 140class OAudioInterface : public QObject
142{ 141{
143 Q_OBJECT 142 Q_OBJECT
144 143
145 public: 144 public:
146 /** 145 /**
147 * Constructor. Normally you don't create @ref OAudioInterface objects yourself, 146 * Constructor. Normally you don't create @ref OAudioInterface objects yourself,
148 * but access them via the @ref OSoundCard interface. 147 * but access them via the @ref OSoundCard interface.
149 */ 148 */
150 OAudioInterface( QObject* parent, const char* name ); 149 OAudioInterface( QObject* parent, const char* name );
151 /** 150 /**
152 * Destructor. 151 * Destructor.
153 */ 152 */
154 virtual ~OAudioInterface(); 153 virtual ~OAudioInterface();
155 154
156 protected: 155 protected:
157 const int _sfd; 156 const int _sfd;
158 157
159 private: 158 private:
160 void init(); 159 void init();
161 private: 160 private:
162 class Private; 161 class Private;
163 Private *d; 162 Private *d;
164}; 163};
165 164
166 165
167/*====================================================================================== 166/*======================================================================================
168 * OMixerInterface 167 * OMixerInterface
169 *======================================================================================*/ 168 *======================================================================================*/
170 169
171class OMixerInterface : public QObject 170class OMixerInterface : public QObject
172{ 171{
173 Q_OBJECT 172 Q_OBJECT
174 173
175 public: 174 public:
176 175
177 typedef QMap<QString,int>::ConstIterator ChannelIterator; 176 typedef QMap<QString,int>::ConstIterator ChannelIterator;
178 177
179 /** 178 /**
180 * Constructor. Normally you don't create @ref OMixerInterface objects yourself, 179 * Constructor. Normally you don't create @ref OMixerInterface objects yourself,
181 * but access them via the @ref OSoundCard interface. 180 * but access them via the @ref OSoundCard interface.
182 */ 181 */
183 OMixerInterface( QObject* parent, const char* name ); 182 OMixerInterface( QObject* parent, const char* name );
184 /** 183 /**
185 * Destructor. 184 * Destructor.
186 */ 185 */
187 virtual ~OMixerInterface(); 186 virtual ~OMixerInterface();
188 187
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