Diffstat (limited to 'core/multimedia/opieplayer/audiodevice.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/audiodevice.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/core/multimedia/opieplayer/audiodevice.cpp b/core/multimedia/opieplayer/audiodevice.cpp index 9a10eb4..5fef792 100644 --- a/core/multimedia/opieplayer/audiodevice.cpp +++ b/core/multimedia/opieplayer/audiodevice.cpp | |||
@@ -142,107 +142,108 @@ void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, | |||
142 | WAVEFORMATEX formatData; | 142 | WAVEFORMATEX formatData; |
143 | formatData.cbSize = sizeof(WAVEFORMATEX); | 143 | formatData.cbSize = sizeof(WAVEFORMATEX); |
144 | formatData.wFormatTag = WAVE_FORMAT_PCM; | 144 | formatData.wFormatTag = WAVE_FORMAT_PCM; |
145 | formatData.nAvgBytesPerSec = 4 * 44000; | 145 | formatData.nAvgBytesPerSec = 4 * 44000; |
146 | formatData.nBlockAlign = 4; | 146 | formatData.nBlockAlign = 4; |
147 | formatData.nChannels = 2; | 147 | formatData.nChannels = 2; |
148 | formatData.nSamplesPerSec = 44000; | 148 | formatData.nSamplesPerSec = 44000; |
149 | formatData.wBitsPerSample = 16; | 149 | formatData.wBitsPerSample = 16; |
150 | waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); | 150 | waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); |
151 | unsigned int volume = (rightVolume << 16) | leftVolume; | 151 | unsigned int volume = (rightVolume << 16) | leftVolume; |
152 | if ( waveOutSetVolume( handle, volume ) ) | 152 | if ( waveOutSetVolume( handle, volume ) ) |
153 | // qDebug( "set volume of audio device failed" ); | 153 | // qDebug( "set volume of audio device failed" ); |
154 | waveOutClose( handle ); | 154 | waveOutClose( handle ); |
155 | #else | 155 | #else |
156 | // Volume can be from 0 to 100 which is 101 distinct values | 156 | // Volume can be from 0 to 100 which is 101 distinct values |
157 | unsigned int rV = (rightVolume * 101) >> 16; | 157 | unsigned int rV = (rightVolume * 101) >> 16; |
158 | 158 | ||
159 | # if 0 | 159 | # if 0 |
160 | unsigned int lV = (leftVolume * 101) >> 16; | 160 | unsigned int lV = (leftVolume * 101) >> 16; |
161 | unsigned int volume = ((rV << 8) & 0xFF00) | (lV & 0x00FF); | 161 | unsigned int volume = ((rV << 8) & 0xFF00) | (lV & 0x00FF); |
162 | int mixerHandle = 0; | 162 | int mixerHandle = 0; |
163 | if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { | 163 | if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { |
164 | if(ioctl( mixerHandle, MIXER_WRITE(0), &volume ) ==-1) | 164 | if(ioctl( mixerHandle, MIXER_WRITE(0), &volume ) ==-1) |
165 | perror("ioctl(\"MIXER_WRITE\")"); | 165 | perror("ioctl(\"MIXER_WRITE\")"); |
166 | close( mixerHandle ); | 166 | close( mixerHandle ); |
167 | } else | 167 | } else |
168 | perror("open(\"/dev/mixer\")"); | 168 | perror("open(\"/dev/mixer\")"); |
169 | 169 | ||
170 | # else | 170 | # else |
171 | // This is the way this has to be done now I guess, doesn't allow for | 171 | // This is the way this has to be done now I guess, doesn't allow for |
172 | // independant right and left channel setting, or setting for different outputs | 172 | // independant right and left channel setting, or setting for different outputs |
173 | Config cfg("Sound"); | 173 | Config cfg("Sound"); |
174 | cfg.setGroup("System"); | 174 | cfg.setGroup("System"); |
175 | cfg.writeEntry("Volume",(int)rV); | 175 | cfg.writeEntry("Volume",(int)rV); |
176 | # endif | 176 | # endif |
177 | 177 | ||
178 | #endif | 178 | #endif |
179 | // qDebug( "setting volume to: 0x%x", volume ); | 179 | // qDebug( "setting volume to: 0x%x", volume ); |
180 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) | 180 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) |
181 | // Send notification that the volume has changed | 181 | // Send notification that the volume has changed |
182 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted; | 182 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted; |
183 | #endif | 183 | #endif |
184 | } | 184 | } |
185 | 185 | ||
186 | 186 | ||
187 | 187 | ||
188 | 188 | ||
189 | AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { | 189 | AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { |
190 | d = new AudioDevicePrivate; | 190 | qDebug("creating new audio device"); |
191 | d = new AudioDevicePrivate; | ||
191 | d->frequency = f; | 192 | d->frequency = f; |
192 | d->channels = chs; | 193 | d->channels = chs; |
193 | d->bytesPerSample = bps; | 194 | d->bytesPerSample = bps; |
194 | // qDebug("%d",bps); | 195 | qDebug("%d",bps); |
195 | int format=0; | 196 | int format=0; |
196 | if( bps == 8) format = AFMT_U8; | 197 | if( bps == 8) format = AFMT_U8; |
197 | else if( bps <= 0) format = AFMT_S16_LE; | 198 | else if( bps <= 0) format = AFMT_S16_LE; |
198 | else format = AFMT_S16_LE; | 199 | else format = AFMT_S16_LE; |
199 | 200 | ||
200 | // qDebug("AD- freq %d, channels %d, b/sample %d, bitrate %d",f,chs,bps,format); | 201 | qDebug("AD- freq %d, channels %d, b/sample %d, bitrate %d",f,chs,bps,format); |
201 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); | 202 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); |
202 | 203 | ||
203 | 204 | ||
204 | int fragments = 0x10000 * 8 + sound_fragment_shift; | 205 | int fragments = 0x10000 * 8 + sound_fragment_shift; |
205 | int capabilities = 0; | 206 | int capabilities = 0; |
206 | 207 | ||
207 | #ifdef KEEP_DEVICE_OPEN | 208 | #ifdef KEEP_DEVICE_OPEN |
208 | if ( AudioDevicePrivate::dspFd == 0 ) { | 209 | if ( AudioDevicePrivate::dspFd == 0 ) { |
209 | #endif | 210 | #endif |
210 | if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) { | 211 | if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) { |
211 | perror("open(\"/dev/dsp\") sending to /dev/null instead"); | 212 | perror("open(\"/dev/dsp\") sending to /dev/null instead"); |
212 | d->handle = ::open( "/dev/null", O_WRONLY ); | 213 | d->handle = ::open( "/dev/null", O_WRONLY ); |
213 | } | 214 | } |
214 | #ifdef KEEP_DEVICE_OPEN | 215 | #ifdef KEEP_DEVICE_OPEN |
215 | AudioDevicePrivate::dspFd = d->handle; | 216 | AudioDevicePrivate::dspFd = d->handle; |
216 | } else { | 217 | } else { |
217 | d->handle = AudioDevicePrivate::dspFd; | 218 | d->handle = AudioDevicePrivate::dspFd; |
218 | } | 219 | } |
219 | #endif | 220 | #endif |
220 | 221 | ||
221 | if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1) | 222 | if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1) |
222 | perror("ioctl(\"SNDCTL_DSP_GETCAPS\")"); | 223 | perror("ioctl(\"SNDCTL_DSP_GETCAPS\")"); |
223 | if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1) | 224 | if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1) |
224 | perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); | 225 | perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); |
225 | if(ioctl( d->handle, SNDCTL_DSP_SETFMT, & format )==-1) | 226 | if(ioctl( d->handle, SNDCTL_DSP_SETFMT, & format )==-1) |
226 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | 227 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); |
227 | qDebug("freq %d", d->frequency); | 228 | qDebug("freq %d", d->frequency); |
228 | if(ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency )==-1) | 229 | if(ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency )==-1) |
229 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); | 230 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); |
230 | qDebug("channels %d",d->channels); | 231 | qDebug("channels %d",d->channels); |
231 | if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) { | 232 | if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) { |
232 | d->channels = ( d->channels == 1 ) ? 2 : d->channels; | 233 | d->channels = ( d->channels == 1 ) ? 2 : d->channels; |
233 | if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1) | 234 | if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1) |
234 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); | 235 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); |
235 | } | 236 | } |
236 | 237 | ||
237 | d->bufferSize = sound_fragment_bytes; | 238 | d->bufferSize = sound_fragment_bytes; |
238 | d->unwrittenBuffer = new char[d->bufferSize]; | 239 | d->unwrittenBuffer = new char[d->bufferSize]; |
239 | d->unwritten = 0; | 240 | d->unwritten = 0; |
240 | d->can_GETOSPACE = TRUE; // until we find otherwise | 241 | d->can_GETOSPACE = TRUE; // until we find otherwise |
241 | 242 | ||
242 | //if ( chs != d->channels ) qDebug( "Wanted %d, got %d channels", chs, d->channels ); | 243 | //if ( chs != d->channels ) qDebug( "Wanted %d, got %d channels", chs, d->channels ); |
243 | //if ( f != d->frequency ) qDebug( "wanted %dHz, got %dHz", f, d->frequency ); | 244 | //if ( f != d->frequency ) qDebug( "wanted %dHz, got %dHz", f, d->frequency ); |
244 | //if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" ); | 245 | //if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" ); |
245 | //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" ); | 246 | //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" ); |
246 | //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" ); | 247 | //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" ); |
247 | //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" ); | 248 | //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" ); |
248 | } | 249 | } |