-rw-r--r-- | libopie2/examples/opiemm/osoundsystemdemo/osoundsystemdemo.cpp | 3 | ||||
-rw-r--r-- | libopie2/opiemm/osoundsystem.cpp | 25 | ||||
-rw-r--r-- | libopie2/opiemm/osoundsystem.h | 6 |
3 files changed, 30 insertions, 4 deletions
diff --git a/libopie2/examples/opiemm/osoundsystemdemo/osoundsystemdemo.cpp b/libopie2/examples/opiemm/osoundsystemdemo/osoundsystemdemo.cpp index b522441..f74a1b9 100644 --- a/libopie2/examples/opiemm/osoundsystemdemo/osoundsystemdemo.cpp +++ b/libopie2/examples/opiemm/osoundsystemdemo/osoundsystemdemo.cpp | |||
@@ -1,65 +1,66 @@ | |||
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 | ||
33 | using namespace Opie::MM; | 33 | using namespace Opie::MM; |
34 | 34 | ||
35 | int main( int argc, char** argv ) | 35 | int 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 | 51 | ||
52 | OMixerInterface* mixer = card->mixer(); | 52 | OMixerInterface* mixer = card->mixer(); |
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 | odebug << "OSSDEMO: Mixer has channel " << *it << "" << oendl; | 58 | bool stereo = mixer->isStereo( *it ); |
59 | odebug << "OSSDEMO: Mixer has channel " << *it << ( stereo ? "[stereo]" : "[mono]" ) << oendl; | ||
59 | odebug << "OSSDEMO: +--- volume " << ( mixer->volume( *it ) & 0xff ) | 60 | odebug << "OSSDEMO: +--- volume " << ( mixer->volume( *it ) & 0xff ) |
60 | << " (left) | " << ( mixer->volume( *it ) >> 8 ) << " (right)" << oendl; | 61 | << " (left) | " << ( mixer->volume( *it ) >> 8 ) << " (right)" << oendl; |
61 | } | 62 | } |
62 | 63 | ||
63 | return 0; | 64 | return 0; |
64 | 65 | ||
65 | } | 66 | } |
diff --git a/libopie2/opiemm/osoundsystem.cpp b/libopie2/opiemm/osoundsystem.cpp index 13b26e6..09fd28f 100644 --- a/libopie2/opiemm/osoundsystem.cpp +++ b/libopie2/opiemm/osoundsystem.cpp | |||
@@ -69,252 +69,273 @@ void OSoundSystem::synchronize() | |||
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 | ||
96 | int OSoundSystem::count() const | 96 | int OSoundSystem::count() const |
97 | { | 97 | { |
98 | return _interfaces.count(); | 98 | return _interfaces.count(); |
99 | } | 99 | } |
100 | 100 | ||
101 | 101 | ||
102 | OSoundCard* OSoundSystem::card( const QString& iface ) const | 102 | OSoundCard* OSoundSystem::card( const QString& iface ) const |
103 | { | 103 | { |
104 | return _interfaces[iface]; | 104 | return _interfaces[iface]; |
105 | } | 105 | } |
106 | 106 | ||
107 | 107 | ||
108 | OSoundSystem* OSoundSystem::instance() | 108 | OSoundSystem* 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 | ||
115 | OSoundSystem::CardIterator OSoundSystem::iterator() const | 115 | OSoundSystem::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 | ||
125 | OSoundCard::OSoundCard( QObject* parent, const char* name ) | 125 | OSoundCard::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 | ||
133 | OSoundCard::~OSoundCard() | 133 | OSoundCard::~OSoundCard() |
134 | { | 134 | { |
135 | } | 135 | } |
136 | 136 | ||
137 | 137 | ||
138 | void OSoundCard::init() | 138 | void 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 | ||
154 | OAudioInterface::OAudioInterface( QObject* parent, const char* name ) | 154 | OAudioInterface::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 | ||
162 | OAudioInterface::~OAudioInterface() | 162 | OAudioInterface::~OAudioInterface() |
163 | { | 163 | { |
164 | } | 164 | } |
165 | 165 | ||
166 | 166 | ||
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 ) |
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." << 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 | int devmask = 0; |
203 | if ( ioctl( _fd, SOUND_MIXER_READ_DEVMASK, &devmask ) != -1 ) | 203 | if ( ioctl( _fd, SOUND_MIXER_READ_DEVMASK, &devmask ) != -1 ) |
204 | { | 204 | { |
205 | if ( devmask & ( 1 << SOUND_MIXER_VOLUME ) ) _channels.insert( "PlayVolume", SOUND_MIXER_VOLUME ); | 205 | if ( devmask & ( 1 << SOUND_MIXER_VOLUME ) ) _channels.insert( "PlayVolume", SOUND_MIXER_VOLUME ); |
206 | if ( devmask & ( 1 << SOUND_MIXER_BASS ) ) _channels.insert( "PlayBass", SOUND_MIXER_BASS ); | 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 ); | 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 ); | 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 ); | 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 ); | 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 ); | 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 ); | 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 ); | 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 ); | 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 ); | 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 ); | 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 ); | 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 ); | 218 | if ( devmask & ( 1 << SOUND_MIXER_OGAIN ) ) _channels.insert( "PlayOutputGain", SOUND_MIXER_OGAIN ); |
219 | //odebug << "devmask available and constructed." << oendl; | 219 | //odebug << "devmask available and constructed." << oendl; |
220 | } | 220 | } |
221 | 221 | ||
222 | devmask = 0; | 222 | devmask = 0; |
223 | if ( ioctl( _fd, SOUND_MIXER_READ_RECMASK, &devmask ) != -1 ) | 223 | if ( ioctl( _fd, SOUND_MIXER_READ_RECMASK, &devmask ) != -1 ) |
224 | { | 224 | { |
225 | if ( devmask & ( 1 << SOUND_MIXER_VOLUME ) ) _channels.insert( "RecVolume", SOUND_MIXER_VOLUME ); | 225 | if ( devmask & ( 1 << SOUND_MIXER_VOLUME ) ) _channels.insert( "RecVolume", SOUND_MIXER_VOLUME ); |
226 | if ( devmask & ( 1 << SOUND_MIXER_BASS ) ) _channels.insert( "RecBass", SOUND_MIXER_BASS ); | 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 ); | 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 ); | 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 ); | 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 ); | 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 ); | 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 ); | 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 ); | 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 ); | 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 ); | 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 ); | 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 ); | 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 ); | 238 | if ( devmask & ( 1 << SOUND_MIXER_OGAIN ) ) _channels.insert( "RecOutputGain", SOUND_MIXER_OGAIN ); |
239 | //odebug << "recmask available and constructed." << oendl; | 239 | //odebug << "recmask available and constructed." << oendl; |
240 | } | 240 | } |
241 | 241 | ||
242 | devmask = 0; | ||
243 | if ( ioctl( _fd, SOUND_MIXER_READ_STEREODEVS, &devmask ) != -1 ) | ||
244 | { | ||
245 | odebug << "stereomask = " << devmask << oendl; | ||
246 | } | ||
247 | |||
242 | /* ChannelIterator it; | 248 | /* ChannelIterator it; |
243 | for ( it = _channels.begin(); it != _channels.end(); ++it ) | 249 | for ( it = _channels.begin(); it != _channels.end(); ++it ) |
244 | { | 250 | { |
245 | odebug << "Channel " << it.key() << " available (bit " << it.data() << ")" << oendl; | 251 | odebug << "Channel " << it.key() << " available (bit " << it.data() << ")" << oendl; |
246 | odebug << " +--- Volume: " << volume( it.key() ) & 0xff << " | " << volume( it.key() ) >> 8 << "" << oendl; | 252 | odebug << " +--- Volume: " << volume( it.key() ) & 0xff << " | " << volume( it.key() ) >> 8 << "" << oendl; |
247 | } | 253 | } |
248 | */ | 254 | */ |
249 | } | 255 | } |
250 | 256 | ||
251 | QStringList OMixerInterface::allChannels() const | 257 | QStringList OMixerInterface::allChannels() const |
252 | { | 258 | { |
253 | ChannelIterator it = _channels.begin(); | 259 | ChannelIterator it = _channels.begin(); |
254 | QStringList channels; | 260 | QStringList channels; |
255 | while ( it != _channels.end() ) | 261 | while ( it != _channels.end() ) |
256 | { | 262 | { |
257 | channels += it.key(); | 263 | channels += it.key(); |
258 | it++; | 264 | it++; |
259 | } | 265 | } |
260 | return channels; | 266 | return channels; |
261 | } | 267 | } |
262 | 268 | ||
263 | 269 | ||
264 | QStringList OMixerInterface::recChannels() const | 270 | QStringList OMixerInterface::recChannels() const |
265 | { | 271 | { |
266 | owarn << "NYI" << oendl; | 272 | owarn << "NYI" << oendl; |
267 | return QStringList(); | 273 | return QStringList(); |
268 | } | 274 | } |
269 | 275 | ||
270 | 276 | ||
271 | QStringList OMixerInterface::playChannels() const | 277 | QStringList OMixerInterface::playChannels() const |
272 | { | 278 | { |
273 | owarn << "NYI" << oendl; | 279 | owarn << "NYI" << oendl; |
274 | return QStringList(); | 280 | return QStringList(); |
275 | } | 281 | } |
276 | 282 | ||
277 | 283 | ||
278 | bool OMixerInterface::hasChannel( const QString& channel ) | 284 | bool OMixerInterface::hasChannel( const QString& channel ) const |
279 | { | 285 | { |
280 | return _channels.contains( channel ); | 286 | return _channels.contains( channel ); |
281 | } | 287 | } |
282 | 288 | ||
283 | 289 | ||
290 | bool OMixerInterface::isStereo( const QString& channel ) const | ||
291 | { | ||
292 | bool result = false; | ||
293 | if ( _channels.contains( channel ) ) | ||
294 | { | ||
295 | int devmask = 0; | ||
296 | if ( ioctl( _fd, SOUND_MIXER_READ_STEREODEVS, &devmask ) != -1 ) | ||
297 | { | ||
298 | result = devmask & ( 1 << _channels[channel] ); | ||
299 | } | ||
300 | } | ||
301 | return result; | ||
302 | } | ||
303 | |||
304 | |||
284 | void OMixerInterface::setVolume( const QString& channel, int left, int right ) | 305 | void OMixerInterface::setVolume( const QString& channel, int left, int right ) |
285 | { | 306 | { |
286 | int volume = left; | 307 | int volume = left; |
287 | volume |= ( right == -1 ) ? left << 8 : right << 8; | 308 | volume |= ( right == -1 ) ? left << 8 : right << 8; |
288 | 309 | ||
289 | if ( _channels.contains( channel ) ) | 310 | if ( _channels.contains( channel ) ) |
290 | { | 311 | { |
291 | int result = ioctl( _fd, MIXER_WRITE( _channels[channel] ), &volume ); | 312 | int result = ioctl( _fd, MIXER_WRITE( _channels[channel] ), &volume ); |
292 | if ( result == -1 ) | 313 | if ( result == -1 ) |
293 | { | 314 | { |
294 | owarn << "Can't set volume: " << strerror( errno ) << oendl; | 315 | owarn << "Can't set volume: " << strerror( errno ) << oendl; |
295 | } | 316 | } |
296 | else | 317 | else |
297 | { | 318 | { |
298 | if ( result & 0xff != left ) | 319 | if ( result & 0xff != left ) |
299 | { | 320 | { |
300 | owarn << "Device adjusted volume from " << left << " to " << (result & 0xff) << oendl; | 321 | owarn << "Device adjusted volume from " << left << " to " << (result & 0xff) << oendl; |
301 | } | 322 | } |
302 | } | 323 | } |
303 | } | 324 | } |
304 | } | 325 | } |
305 | 326 | ||
306 | 327 | ||
307 | int OMixerInterface::volume( const QString& channel ) const | 328 | int OMixerInterface::volume( const QString& channel ) const |
308 | { | 329 | { |
309 | int volume; | 330 | int volume; |
310 | 331 | ||
311 | if ( _channels.contains( channel ) ) | 332 | if ( _channels.contains( channel ) ) |
312 | { | 333 | { |
313 | if ( ioctl( _fd, MIXER_READ( _channels[channel] ), &volume ) == -1 ) | 334 | if ( ioctl( _fd, MIXER_READ( _channels[channel] ), &volume ) == -1 ) |
314 | { | 335 | { |
315 | owarn << "Can't get volume: " << strerror( errno ) << oendl; | 336 | owarn << "Can't get volume: " << strerror( errno ) << oendl; |
316 | } | 337 | } |
317 | else return volume; | 338 | else return volume; |
318 | } | 339 | } |
319 | return -1; | 340 | return -1; |
320 | } | 341 | } |
diff --git a/libopie2/opiemm/osoundsystem.h b/libopie2/opiemm/osoundsystem.h index bd69114..ac7a5a7 100644 --- a/libopie2/opiemm/osoundsystem.h +++ b/libopie2/opiemm/osoundsystem.h | |||
@@ -77,156 +77,160 @@ class OSoundSystem : public QObject | |||
77 | CardIterator iterator() const; | 77 | CardIterator iterator() const; |
78 | /** | 78 | /** |
79 | * @returns a pointer to the @ref OAudioInterface object for the specified @a interface or 0, if not found | 79 | * @returns a pointer to the @ref OAudioInterface object for the specified @a interface or 0, if not found |
80 | * @see OAudioInterface | 80 | * @see OAudioInterface |
81 | */ | 81 | */ |
82 | OSoundCard* card( const QString& interface ) const; | 82 | OSoundCard* card( const QString& interface ) const; |
83 | /** | 83 | /** |
84 | * @internal Rebuild the internal interface database | 84 | * @internal Rebuild the internal interface database |
85 | * @note Sometimes it might be useful to call this from client code, | 85 | * @note Sometimes it might be useful to call this from client code, |
86 | * e.g. after issuing a cardctl insert | 86 | * e.g. after issuing a cardctl insert |
87 | */ | 87 | */ |
88 | void synchronize(); | 88 | void synchronize(); |
89 | 89 | ||
90 | protected: | 90 | protected: |
91 | OSoundSystem(); | 91 | OSoundSystem(); |
92 | 92 | ||
93 | private: | 93 | private: |
94 | static OSoundSystem* _instance; | 94 | static OSoundSystem* _instance; |
95 | CardMap _interfaces; | 95 | CardMap _interfaces; |
96 | class Private; | 96 | class Private; |
97 | Private *d; | 97 | Private *d; |
98 | }; | 98 | }; |
99 | 99 | ||
100 | 100 | ||
101 | /*====================================================================================== | 101 | /*====================================================================================== |
102 | * OSoundCard | 102 | * OSoundCard |
103 | *======================================================================================*/ | 103 | *======================================================================================*/ |
104 | 104 | ||
105 | class OSoundCard : public QObject | 105 | class OSoundCard : public QObject |
106 | { | 106 | { |
107 | Q_OBJECT | 107 | Q_OBJECT |
108 | 108 | ||
109 | public: | 109 | public: |
110 | /** | 110 | /** |
111 | * Constructor. Normally you don't create @ref OSoundCard objects yourself, | 111 | * Constructor. Normally you don't create @ref OSoundCard objects yourself, |
112 | * but access them via @ref OSoundSystem::card(). | 112 | * but access them via @ref OSoundSystem::card(). |
113 | */ | 113 | */ |
114 | OSoundCard( QObject* parent, const char* name ); | 114 | OSoundCard( QObject* parent, const char* name ); |
115 | /** | 115 | /** |
116 | * Destructor. | 116 | * Destructor. |
117 | */ | 117 | */ |
118 | virtual ~OSoundCard(); | 118 | virtual ~OSoundCard(); |
119 | 119 | ||
120 | bool hasMixer() const { return _audio; }; | 120 | bool hasMixer() const { return _audio; }; |
121 | bool hasAudio() const { return _mixer; }; | 121 | bool hasAudio() const { return _mixer; }; |
122 | 122 | ||
123 | OAudioInterface* audio() const { return _audio; }; | 123 | OAudioInterface* audio() const { return _audio; }; |
124 | OMixerInterface* mixer() const { return _mixer; }; | 124 | OMixerInterface* mixer() const { return _mixer; }; |
125 | 125 | ||
126 | protected: | 126 | protected: |
127 | OAudioInterface* _audio; | 127 | OAudioInterface* _audio; |
128 | OMixerInterface* _mixer; | 128 | OMixerInterface* _mixer; |
129 | 129 | ||
130 | private: | 130 | private: |
131 | void init(); | 131 | void init(); |
132 | private: | 132 | private: |
133 | class Private; | 133 | class Private; |
134 | Private *d; | 134 | Private *d; |
135 | }; | 135 | }; |
136 | 136 | ||
137 | /*====================================================================================== | 137 | /*====================================================================================== |
138 | * OAudioInterface | 138 | * OAudioInterface |
139 | *======================================================================================*/ | 139 | *======================================================================================*/ |
140 | 140 | ||
141 | class OAudioInterface : public QObject | 141 | class OAudioInterface : public QObject |
142 | { | 142 | { |
143 | Q_OBJECT | 143 | Q_OBJECT |
144 | 144 | ||
145 | public: | 145 | public: |
146 | /** | 146 | /** |
147 | * Constructor. Normally you don't create @ref OAudioInterface objects yourself, | 147 | * Constructor. Normally you don't create @ref OAudioInterface objects yourself, |
148 | * but access them via the @ref OSoundCard interface. | 148 | * but access them via the @ref OSoundCard interface. |
149 | */ | 149 | */ |
150 | OAudioInterface( QObject* parent, const char* name ); | 150 | OAudioInterface( QObject* parent, const char* name ); |
151 | /** | 151 | /** |
152 | * Destructor. | 152 | * Destructor. |
153 | */ | 153 | */ |
154 | virtual ~OAudioInterface(); | 154 | virtual ~OAudioInterface(); |
155 | 155 | ||
156 | protected: | 156 | protected: |
157 | const int _sfd; | 157 | const int _sfd; |
158 | 158 | ||
159 | private: | 159 | private: |
160 | void init(); | 160 | void init(); |
161 | private: | 161 | private: |
162 | class Private; | 162 | class Private; |
163 | Private *d; | 163 | Private *d; |
164 | }; | 164 | }; |
165 | 165 | ||
166 | 166 | ||
167 | /*====================================================================================== | 167 | /*====================================================================================== |
168 | * OMixerInterface | 168 | * OMixerInterface |
169 | *======================================================================================*/ | 169 | *======================================================================================*/ |
170 | 170 | ||
171 | class OMixerInterface : public QObject | 171 | class OMixerInterface : public QObject |
172 | { | 172 | { |
173 | Q_OBJECT | 173 | Q_OBJECT |
174 | 174 | ||
175 | public: | 175 | public: |
176 | 176 | ||
177 | typedef QMap<QString,int>::ConstIterator ChannelIterator; | 177 | typedef QMap<QString,int>::ConstIterator ChannelIterator; |
178 | 178 | ||
179 | /** | 179 | /** |
180 | * Constructor. Normally you don't create @ref OMixerInterface objects yourself, | 180 | * Constructor. Normally you don't create @ref OMixerInterface objects yourself, |
181 | * but access them via the @ref OSoundCard interface. | 181 | * but access them via the @ref OSoundCard interface. |
182 | */ | 182 | */ |
183 | OMixerInterface( QObject* parent, const char* name ); | 183 | OMixerInterface( QObject* parent, const char* name ); |
184 | /** | 184 | /** |
185 | * Destructor. | 185 | * Destructor. |
186 | */ | 186 | */ |
187 | virtual ~OMixerInterface(); | 187 | virtual ~OMixerInterface(); |
188 | 188 | ||
189 | /** | 189 | /** |
190 | * @returns all available channels. | 190 | * @returns all available channels. |
191 | */ | 191 | */ |
192 | QStringList allChannels() const; | 192 | QStringList allChannels() const; |
193 | /** | 193 | /** |
194 | * @returns recordable channels. | 194 | * @returns recordable channels. |
195 | */ | 195 | */ |
196 | QStringList recChannels() const; | 196 | QStringList recChannels() const; |
197 | /** | 197 | /** |
198 | * @returns playable channels. | 198 | * @returns playable channels. |
199 | */ | 199 | */ |
200 | QStringList playChannels() const; | 200 | QStringList playChannels() const; |
201 | 201 | ||
202 | /** | 202 | /** |
203 | * @returns true, if @a channel exists. | 203 | * @returns true, if @a channel exists. |
204 | */ | 204 | */ |
205 | bool hasChannel( const QString& channel ); | 205 | bool hasChannel( const QString& channel ) const; |
206 | /** | ||
207 | * @returns true, if @a channel is stereo. | ||
208 | */ | ||
209 | bool isStereo( const QString& channel ) const; | ||
206 | 210 | ||
207 | /** | 211 | /** |
208 | * Set the @a left and @a right volumes for @a channel. | 212 | * Set the @a left and @a right volumes for @a channel. |
209 | * If no value for right is given, the value for left is taken for that. | 213 | * If no value for right is given, the value for left is taken for that. |
210 | */ | 214 | */ |
211 | void setVolume( const QString& channel, int left, int right = -1 ); | 215 | void setVolume( const QString& channel, int left, int right = -1 ); |
212 | /** | 216 | /** |
213 | * @returns the volume of @a channel or -1, if the channel doesn't exist. | 217 | * @returns the volume of @a channel or -1, if the channel doesn't exist. |
214 | * @note You might want to use @ref hasChannel() to check if a channel exists. | 218 | * @note You might want to use @ref hasChannel() to check if a channel exists. |
215 | */ | 219 | */ |
216 | int volume( const QString& channel ) const; | 220 | int volume( const QString& channel ) const; |
217 | 221 | ||
218 | protected: | 222 | protected: |
219 | int _fd; | 223 | int _fd; |
220 | QMap<QString, int> _channels; | 224 | QMap<QString, int> _channels; |
221 | 225 | ||
222 | private: | 226 | private: |
223 | void init(); | 227 | void init(); |
224 | private: | 228 | private: |
225 | class Private; | 229 | class Private; |
226 | Private *d; | 230 | Private *d; |
227 | }; | 231 | }; |
228 | 232 | ||
229 | } | 233 | } |
230 | } | 234 | } |
231 | 235 | ||
232 | #endif // OSOUNDSYSTEM_H | 236 | #endif // OSOUNDSYSTEM_H |