summaryrefslogtreecommitdiff
path: root/libopie2/opiemm
Unidiff
Diffstat (limited to 'libopie2/opiemm') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiemm/osoundsystem.cpp1
1 files changed, 0 insertions, 1 deletions
diff --git a/libopie2/opiemm/osoundsystem.cpp b/libopie2/opiemm/osoundsystem.cpp
index ca63389..51e088c 100644
--- a/libopie2/opiemm/osoundsystem.cpp
+++ b/libopie2/opiemm/osoundsystem.cpp
@@ -1,235 +1,234 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 3
4              (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 4              (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
5 =. 5 =.
6 .=l. 6 .=l.
7           .>+-= 7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can 8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under 9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License, 12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_. 14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of 17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22 :     =  ...= . :.=- 22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29 29
30*/ 30*/
31 31
32#include <opie2/osoundsystem.h> 32#include <opie2/osoundsystem.h>
33#include <opie2/odebug.h> 33#include <opie2/odebug.h>
34 34
35#include <errno.h> 35#include <errno.h>
36#include <fcntl.h> 36#include <fcntl.h>
37#include <string.h> 37#include <string.h>
38#include <sys/ioctl.h> 38#include <sys/ioctl.h>
39#include <sys/types.h> 39#include <sys/types.h>
40#include <sys/soundcard.h> 40#include <sys/soundcard.h>
41#include <sys/stat.h> 41#include <sys/stat.h>
42 42
43#include <qstringlist.h>
44 43
45/*====================================================================================== 44/*======================================================================================
46 * OSoundSystem 45 * OSoundSystem
47 *======================================================================================*/ 46 *======================================================================================*/
48 47
49OSoundSystem* OSoundSystem::_instance = 0; 48OSoundSystem* OSoundSystem::_instance = 0;
50 49
51OSoundSystem::OSoundSystem() 50OSoundSystem::OSoundSystem()
52{ 51{
53 odebug << "OSoundSystem::OSoundSystem()" << oendl; 52 odebug << "OSoundSystem::OSoundSystem()" << oendl;
54 synchronize(); 53 synchronize();
55} 54}
56 55
57void OSoundSystem::synchronize() 56void OSoundSystem::synchronize()
58{ 57{
59 // gather available interfaces by inspecting /dev 58 // gather available interfaces by inspecting /dev
60 //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices 59 //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices
61 //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices 60 //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices
62 61
63 _interfaces.clear(); 62 _interfaces.clear();
64 _interfaces.insert( "soundcard", new OSoundCard( this, "soundcard" ) ); 63 _interfaces.insert( "soundcard", new OSoundCard( this, "soundcard" ) );
65 64
66 65
67 /* 66 /*
68 67
69 QString str; 68 QString str;
70 QFile f( "/dev/sound" ); 69 QFile f( "/dev/sound" );
71 bool hasFile = f.open( IO_ReadOnly ); 70 bool hasFile = f.open( IO_ReadOnly );
72 if ( !hasFile ) 71 if ( !hasFile )
73 { 72 {
74 odebug << "OSoundSystem: /dev/sound not existing. No sound devices available" << oendl; 73 odebug << "OSoundSystem: /dev/sound not existing. No sound devices available" << oendl;
75 return; 74 return;
76 } 75 }
77 QTextStream s( &f ); 76 QTextStream s( &f );
78 s.readLine(); 77 s.readLine();
79 s.readLine(); 78 s.readLine();
80 while ( !s.atEnd() ) 79 while ( !s.atEnd() )
81 { 80 {
82 s >> str; 81 s >> str;
83 str.truncate( str.find( ':' ) ); 82 str.truncate( str.find( ':' ) );
84 qDebug( "OSoundSystem: found interface '%s'", (const char*) str ); 83 qDebug( "OSoundSystem: found interface '%s'", (const char*) str );
85 OAudioInterface* iface; 84 OAudioInterface* iface;
86 iface = new OAudioInterface( this, (const char*) str ); 85 iface = new OAudioInterface( this, (const char*) str );
87 86
88 _interfaces.insert( str, iface ); 87 _interfaces.insert( str, iface );
89 s.readLine(); 88 s.readLine();
90 } 89 }
91*/ 90*/
92} 91}
93 92
94 93
95int OSoundSystem::count() const 94int OSoundSystem::count() const
96{ 95{
97 return _interfaces.count(); 96 return _interfaces.count();
98} 97}
99 98
100 99
101OSoundCard* OSoundSystem::card( const QString& iface ) const 100OSoundCard* OSoundSystem::card( const QString& iface ) const
102{ 101{
103 return _interfaces[iface]; 102 return _interfaces[iface];
104} 103}
105 104
106 105
107OSoundSystem* OSoundSystem::instance() 106OSoundSystem* OSoundSystem::instance()
108{ 107{
109 if ( !_instance ) _instance = new OSoundSystem(); 108 if ( !_instance ) _instance = new OSoundSystem();
110 return _instance; 109 return _instance;
111} 110}
112 111
113 112
114OSoundSystem::CardIterator OSoundSystem::iterator() const 113OSoundSystem::CardIterator OSoundSystem::iterator() const
115{ 114{
116 return OSoundSystem::CardIterator( _interfaces ); 115 return OSoundSystem::CardIterator( _interfaces );
117} 116}
118 117
119 118
120/*====================================================================================== 119/*======================================================================================
121 * OSoundCard 120 * OSoundCard
122 *======================================================================================*/ 121 *======================================================================================*/
123 122
124OSoundCard::OSoundCard( QObject* parent, const char* name ) 123OSoundCard::OSoundCard( QObject* parent, const char* name )
125 :QObject( parent, name ), _audio( 0 ), _mixer( 0 ) 124 :QObject( parent, name ), _audio( 0 ), _mixer( 0 )
126{ 125{
127 odebug << "OSoundCard::OSoundCard()" << oendl; 126 odebug << "OSoundCard::OSoundCard()" << oendl;
128 init(); 127 init();
129} 128}
130 129
131 130
132OSoundCard::~OSoundCard() 131OSoundCard::~OSoundCard()
133{ 132{
134} 133}
135 134
136 135
137void OSoundCard::init() 136void OSoundCard::init()
138{ 137{
139 _audio = new OAudioInterface( this, "/dev/dsp" ); 138 _audio = new OAudioInterface( this, "/dev/dsp" );
140 _mixer = new OMixerInterface( this, "/dev/mixer" ); 139 _mixer = new OMixerInterface( this, "/dev/mixer" );
141} 140}
142 141
143 142
144/*====================================================================================== 143/*======================================================================================
145 * OAudioInterface 144 * OAudioInterface
146 *======================================================================================*/ 145 *======================================================================================*/
147 146
148OAudioInterface::OAudioInterface( QObject* parent, const char* name ) 147OAudioInterface::OAudioInterface( QObject* parent, const char* name )
149 :QObject( parent, name ) 148 :QObject( parent, name )
150{ 149{
151 odebug << "OAudioInterface::OAudioInterface()" << oendl; 150 odebug << "OAudioInterface::OAudioInterface()" << oendl;
152 init(); 151 init();
153} 152}
154 153
155 154
156OAudioInterface::~OAudioInterface() 155OAudioInterface::~OAudioInterface()
157{ 156{
158} 157}
159 158
160 159
161void OAudioInterface::init() 160void OAudioInterface::init()
162{ 161{
163 162
164 163
165} 164}
166 165
167 166
168/*====================================================================================== 167/*======================================================================================
169 * OMixerInterface 168 * OMixerInterface
170 *======================================================================================*/ 169 *======================================================================================*/
171 170
172OMixerInterface::OMixerInterface( QObject* parent, const char* name ) 171OMixerInterface::OMixerInterface( QObject* parent, const char* name )
173 :QObject( parent, name ) 172 :QObject( parent, name )
174{ 173{
175 odebug << "OMixerInterface::OMixerInterface()" << oendl; 174 odebug << "OMixerInterface::OMixerInterface()" << oendl;
176 init(); 175 init();
177} 176}
178 177
179 178
180OMixerInterface::~OMixerInterface() 179OMixerInterface::~OMixerInterface()
181{ 180{
182} 181}
183 182
184 183
185void OMixerInterface::init() 184void OMixerInterface::init()
186{ 185{
187 // open the device 186 // open the device
188 _fd = ::open( name(), O_RDWR ); 187 _fd = ::open( name(), O_RDWR );
189 if ( _fd == -1 ) 188 if ( _fd == -1 )
190 { 189 {
191 owarn << "OMixerInterface::init(): Can't open mixer." << oendl; 190 owarn << "OMixerInterface::init(): Can't open mixer." << oendl;
192 return; 191 return;
193 } 192 }
194 193
195 // construct the device capabilities 194 // construct the device capabilities
196 int devmask = 0; 195 int devmask = 0;
197 if ( ioctl( _fd, SOUND_MIXER_READ_DEVMASK, &devmask ) != -1 ) 196 if ( ioctl( _fd, SOUND_MIXER_READ_DEVMASK, &devmask ) != -1 )
198 { 197 {
199 if ( devmask & ( 1 << SOUND_MIXER_VOLUME ) ) _channels.insert( "PlayVolume", SOUND_MIXER_VOLUME ); 198 if ( devmask & ( 1 << SOUND_MIXER_VOLUME ) ) _channels.insert( "PlayVolume", SOUND_MIXER_VOLUME );
200 if ( devmask & ( 1 << SOUND_MIXER_BASS ) ) _channels.insert( "PlayBass", SOUND_MIXER_BASS ); 199 if ( devmask & ( 1 << SOUND_MIXER_BASS ) ) _channels.insert( "PlayBass", SOUND_MIXER_BASS );
201 if ( devmask & ( 1 << SOUND_MIXER_TREBLE ) ) _channels.insert( "PlayTreble", SOUND_MIXER_TREBLE ); 200 if ( devmask & ( 1 << SOUND_MIXER_TREBLE ) ) _channels.insert( "PlayTreble", SOUND_MIXER_TREBLE );
202 if ( devmask & ( 1 << SOUND_MIXER_SYNTH ) ) _channels.insert( "PlaySynth", SOUND_MIXER_SYNTH ); 201 if ( devmask & ( 1 << SOUND_MIXER_SYNTH ) ) _channels.insert( "PlaySynth", SOUND_MIXER_SYNTH );
203 if ( devmask & ( 1 << SOUND_MIXER_PCM ) ) _channels.insert( "PlayPCM", SOUND_MIXER_PCM ); 202 if ( devmask & ( 1 << SOUND_MIXER_PCM ) ) _channels.insert( "PlayPCM", SOUND_MIXER_PCM );
204 if ( devmask & ( 1 << SOUND_MIXER_SPEAKER ) ) _channels.insert( "PlaySpeaker", SOUND_MIXER_SPEAKER ); 203 if ( devmask & ( 1 << SOUND_MIXER_SPEAKER ) ) _channels.insert( "PlaySpeaker", SOUND_MIXER_SPEAKER );
205 if ( devmask & ( 1 << SOUND_MIXER_LINE ) ) _channels.insert( "PlayLine", SOUND_MIXER_LINE ); 204 if ( devmask & ( 1 << SOUND_MIXER_LINE ) ) _channels.insert( "PlayLine", SOUND_MIXER_LINE );
206 if ( devmask & ( 1 << SOUND_MIXER_MIC ) ) _channels.insert( "PlayMic", SOUND_MIXER_MIC ); 205 if ( devmask & ( 1 << SOUND_MIXER_MIC ) ) _channels.insert( "PlayMic", SOUND_MIXER_MIC );
207 if ( devmask & ( 1 << SOUND_MIXER_CD ) ) _channels.insert( "PlayCD", SOUND_MIXER_CD ); 206 if ( devmask & ( 1 << SOUND_MIXER_CD ) ) _channels.insert( "PlayCD", SOUND_MIXER_CD );
208 if ( devmask & ( 1 << SOUND_MIXER_IMIX ) ) _channels.insert( "PlayInputMix", SOUND_MIXER_IMIX ); 207 if ( devmask & ( 1 << SOUND_MIXER_IMIX ) ) _channels.insert( "PlayInputMix", SOUND_MIXER_IMIX );
209 if ( devmask & ( 1 << SOUND_MIXER_ALTPCM ) ) _channels.insert( "PlayAltPCM", SOUND_MIXER_ALTPCM ); 208 if ( devmask & ( 1 << SOUND_MIXER_ALTPCM ) ) _channels.insert( "PlayAltPCM", SOUND_MIXER_ALTPCM );
210 if ( devmask & ( 1 << SOUND_MIXER_RECLEV ) ) _channels.insert( "PlayRecord", SOUND_MIXER_RECLEV ); 209 if ( devmask & ( 1 << SOUND_MIXER_RECLEV ) ) _channels.insert( "PlayRecord", SOUND_MIXER_RECLEV );
211 if ( devmask & ( 1 << SOUND_MIXER_IGAIN ) ) _channels.insert( "PlayInputGain", SOUND_MIXER_IGAIN ); 210 if ( devmask & ( 1 << SOUND_MIXER_IGAIN ) ) _channels.insert( "PlayInputGain", SOUND_MIXER_IGAIN );
212 if ( devmask & ( 1 << SOUND_MIXER_OGAIN ) ) _channels.insert( "PlayOutputGain", SOUND_MIXER_OGAIN ); 211 if ( devmask & ( 1 << SOUND_MIXER_OGAIN ) ) _channels.insert( "PlayOutputGain", SOUND_MIXER_OGAIN );
213 //odebug << "devmask available and constructed." << oendl; 212 //odebug << "devmask available and constructed." << oendl;
214 } 213 }
215 214
216 devmask = 0; 215 devmask = 0;
217 if ( ioctl( _fd, SOUND_MIXER_READ_RECMASK, &devmask ) != -1 ) 216 if ( ioctl( _fd, SOUND_MIXER_READ_RECMASK, &devmask ) != -1 )
218 { 217 {
219 if ( devmask & ( 1 << SOUND_MIXER_VOLUME ) ) _channels.insert( "RecVolume", SOUND_MIXER_VOLUME ); 218 if ( devmask & ( 1 << SOUND_MIXER_VOLUME ) ) _channels.insert( "RecVolume", SOUND_MIXER_VOLUME );
220 if ( devmask & ( 1 << SOUND_MIXER_BASS ) ) _channels.insert( "RecBass", SOUND_MIXER_BASS ); 219 if ( devmask & ( 1 << SOUND_MIXER_BASS ) ) _channels.insert( "RecBass", SOUND_MIXER_BASS );
221 if ( devmask & ( 1 << SOUND_MIXER_TREBLE ) ) _channels.insert( "RecTreble", SOUND_MIXER_TREBLE ); 220 if ( devmask & ( 1 << SOUND_MIXER_TREBLE ) ) _channels.insert( "RecTreble", SOUND_MIXER_TREBLE );
222 if ( devmask & ( 1 << SOUND_MIXER_SYNTH ) ) _channels.insert( "RecSynth", SOUND_MIXER_SYNTH ); 221 if ( devmask & ( 1 << SOUND_MIXER_SYNTH ) ) _channels.insert( "RecSynth", SOUND_MIXER_SYNTH );
223 if ( devmask & ( 1 << SOUND_MIXER_PCM ) ) _channels.insert( "RecPCM", SOUND_MIXER_PCM ); 222 if ( devmask & ( 1 << SOUND_MIXER_PCM ) ) _channels.insert( "RecPCM", SOUND_MIXER_PCM );
224 if ( devmask & ( 1 << SOUND_MIXER_SPEAKER ) ) _channels.insert( "RecSpeaker", SOUND_MIXER_SPEAKER ); 223 if ( devmask & ( 1 << SOUND_MIXER_SPEAKER ) ) _channels.insert( "RecSpeaker", SOUND_MIXER_SPEAKER );
225 if ( devmask & ( 1 << SOUND_MIXER_LINE ) ) _channels.insert( "RecLine", SOUND_MIXER_LINE ); 224 if ( devmask & ( 1 << SOUND_MIXER_LINE ) ) _channels.insert( "RecLine", SOUND_MIXER_LINE );
226 if ( devmask & ( 1 << SOUND_MIXER_MIC ) ) _channels.insert( "RecMic", SOUND_MIXER_MIC ); 225 if ( devmask & ( 1 << SOUND_MIXER_MIC ) ) _channels.insert( "RecMic", SOUND_MIXER_MIC );
227 if ( devmask & ( 1 << SOUND_MIXER_CD ) ) _channels.insert( "RecCD", SOUND_MIXER_CD ); 226 if ( devmask & ( 1 << SOUND_MIXER_CD ) ) _channels.insert( "RecCD", SOUND_MIXER_CD );
228 if ( devmask & ( 1 << SOUND_MIXER_IMIX ) ) _channels.insert( "RecInputMix", SOUND_MIXER_IMIX ); 227 if ( devmask & ( 1 << SOUND_MIXER_IMIX ) ) _channels.insert( "RecInputMix", SOUND_MIXER_IMIX );
229 if ( devmask & ( 1 << SOUND_MIXER_ALTPCM ) ) _channels.insert( "RecAltPCM", SOUND_MIXER_ALTPCM ); 228 if ( devmask & ( 1 << SOUND_MIXER_ALTPCM ) ) _channels.insert( "RecAltPCM", SOUND_MIXER_ALTPCM );
230 if ( devmask & ( 1 << SOUND_MIXER_RECLEV ) ) _channels.insert( "RecRecord", SOUND_MIXER_RECLEV ); 229 if ( devmask & ( 1 << SOUND_MIXER_RECLEV ) ) _channels.insert( "RecRecord", SOUND_MIXER_RECLEV );
231 if ( devmask & ( 1 << SOUND_MIXER_IGAIN ) ) _channels.insert( "RecInputGain", SOUND_MIXER_IGAIN ); 230 if ( devmask & ( 1 << SOUND_MIXER_IGAIN ) ) _channels.insert( "RecInputGain", SOUND_MIXER_IGAIN );
232 if ( devmask & ( 1 << SOUND_MIXER_OGAIN ) ) _channels.insert( "RecOutputGain", SOUND_MIXER_OGAIN ); 231 if ( devmask & ( 1 << SOUND_MIXER_OGAIN ) ) _channels.insert( "RecOutputGain", SOUND_MIXER_OGAIN );
233 //odebug << "recmask available and constructed." << oendl; 232 //odebug << "recmask available and constructed." << oendl;
234 } 233 }
235 234