Diffstat (limited to 'core/multimedia/opieplayer/audiodevice.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/audiodevice.cpp | 81 |
1 files changed, 32 insertions, 49 deletions
diff --git a/core/multimedia/opieplayer/audiodevice.cpp b/core/multimedia/opieplayer/audiodevice.cpp index 7b3700a..9a10eb4 100644 --- a/core/multimedia/opieplayer/audiodevice.cpp +++ b/core/multimedia/opieplayer/audiodevice.cpp | |||
@@ -1,7 +1,7 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
@@ -17,8 +17,10 @@ | |||
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | // L.J.Potter added better error code Fri 02-15-2002 14:37:47 | ||
20 | 21 | ||
21 | #include <stdlib.h> | 22 | #include <stdlib.h> |
23 | #include <stdio.h> | ||
22 | #include <qpe/qpeapplication.h> | 24 | #include <qpe/qpeapplication.h> |
23 | #include <qpe/config.h> | 25 | #include <qpe/config.h> |
24 | #include "audiodevice.h" | 26 | #include "audiodevice.h" |
@@ -106,17 +108,18 @@ void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume | |||
106 | formatData.wBitsPerSample = 16; | 108 | formatData.wBitsPerSample = 16; |
107 | waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); | 109 | waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); |
108 | if ( waveOutGetVolume( handle, (LPDWORD)&volume ) ) | 110 | if ( waveOutGetVolume( handle, (LPDWORD)&volume ) ) |
109 | qDebug( "get volume of audio device failed" ); | 111 | // qDebug( "get volume of audio device failed" ); |
110 | waveOutClose( handle ); | 112 | waveOutClose( handle ); |
111 | leftVolume = volume & 0xFFFF; | 113 | leftVolume = volume & 0xFFFF; |
112 | rightVolume = volume >> 16; | 114 | rightVolume = volume >> 16; |
113 | #else | 115 | #else |
114 | int mixerHandle = open( "/dev/mixer", O_RDWR ); | 116 | int mixerHandle = open( "/dev/mixer", O_RDWR ); |
115 | if ( mixerHandle >= 0 ) { | 117 | if ( mixerHandle >= 0 ) { |
116 | ioctl( mixerHandle, MIXER_READ(0), &volume ); | 118 | if(ioctl( mixerHandle, MIXER_READ(0), &volume )==-1) |
119 | perror("ioctl(\"MIXER_READ\")"); | ||
117 | close( mixerHandle ); | 120 | close( mixerHandle ); |
118 | } else | 121 | } else |
119 | qDebug( "get volume of audio device failed" ); | 122 | perror("open(\"/dev/mixer\")"); |
120 | leftVolume = ((volume & 0x00FF) << 16) / 101; | 123 | leftVolume = ((volume & 0x00FF) << 16) / 101; |
121 | rightVolume = ((volume & 0xFF00) << 8) / 101; | 124 | rightVolume = ((volume & 0xFF00) << 8) / 101; |
122 | #endif | 125 | #endif |
@@ -147,7 +150,7 @@ void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, | |||
147 | waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); | 150 | waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); |
148 | unsigned int volume = (rightVolume << 16) | leftVolume; | 151 | unsigned int volume = (rightVolume << 16) | leftVolume; |
149 | if ( waveOutSetVolume( handle, volume ) ) | 152 | if ( waveOutSetVolume( handle, volume ) ) |
150 | qDebug( "set volume of audio device failed" ); | 153 | // qDebug( "set volume of audio device failed" ); |
151 | waveOutClose( handle ); | 154 | waveOutClose( handle ); |
152 | #else | 155 | #else |
153 | // 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 |
@@ -158,10 +161,12 @@ void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, | |||
158 | unsigned int volume = ((rV << 8) & 0xFF00) | (lV & 0x00FF); | 161 | unsigned int volume = ((rV << 8) & 0xFF00) | (lV & 0x00FF); |
159 | int mixerHandle = 0; | 162 | int mixerHandle = 0; |
160 | if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { | 163 | if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { |
161 | ioctl( mixerHandle, MIXER_WRITE(0), &volume ); | 164 | if(ioctl( mixerHandle, MIXER_WRITE(0), &volume ) ==-1) |
165 | perror("ioctl(\"MIXER_WRITE\")"); | ||
162 | close( mixerHandle ); | 166 | close( mixerHandle ); |
163 | } else | 167 | } else |
164 | qDebug( "set volume of audio device failed" ); | 168 | perror("open(\"/dev/mixer\")"); |
169 | |||
165 | # else | 170 | # else |
166 | // 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 |
167 | // independant right and left channel setting, or setting for different outputs | 172 | // independant right and left channel setting, or setting for different outputs |
@@ -186,52 +191,24 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { | |||
186 | d->frequency = f; | 191 | d->frequency = f; |
187 | d->channels = chs; | 192 | d->channels = chs; |
188 | d->bytesPerSample = bps; | 193 | d->bytesPerSample = bps; |
194 | // qDebug("%d",bps); | ||
195 | int format=0; | ||
196 | if( bps == 8) format = AFMT_U8; | ||
197 | else if( bps <= 0) format = AFMT_S16_LE; | ||
198 | else format = AFMT_S16_LE; | ||
189 | 199 | ||
200 | // qDebug("AD- freq %d, channels %d, b/sample %d, bitrate %d",f,chs,bps,format); | ||
190 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); | 201 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); |
191 | 202 | ||
192 | #ifdef Q_OS_WIN32 | ||
193 | UINT result; | ||
194 | WAVEFORMATEX formatData; | ||
195 | formatData.cbSize = sizeof(WAVEFORMATEX); | ||
196 | /* | ||
197 | // Other possible formats windows supports | ||
198 | formatData.wFormatTag = WAVE_FORMAT_MPEG; | ||
199 | formatData.wFormatTag = WAVE_FORMAT_MPEGLAYER3; | ||
200 | formatData.wFormatTag = WAVE_FORMAT_ADPCM; | ||
201 | */ | ||
202 | formatData.wFormatTag = WAVE_FORMAT_PCM; | ||
203 | formatData.nAvgBytesPerSec = bps * chs * f; | ||
204 | formatData.nBlockAlign = bps * chs; | ||
205 | formatData.nChannels = chs; | ||
206 | formatData.nSamplesPerSec = f; | ||
207 | formatData.wBitsPerSample = bps * 8; | ||
208 | // Open a waveform device for output | ||
209 | if (result = waveOutOpen((LPHWAVEOUT)&d->handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL)) { | ||
210 | QString errorMsg = "error opening audio device.\nReason: %i - "; | ||
211 | switch (result) { | ||
212 | case MMSYSERR_ALLOCATED:errorMsg += "Specified resource is already allocated."; break; | ||
213 | case MMSYSERR_BADDEVICEID:errorMsg += "Specified device identifier is out of range."; break; | ||
214 | case MMSYSERR_NODRIVER:errorMsg += "No device driver is present."; break; | ||
215 | case MMSYSERR_NOMEM:errorMsg += "Unable to allocate or lock memory."; break; | ||
216 | case WAVERR_BADFORMAT:errorMsg += "Attempted to open with an unsupported waveform-audio format."; break; | ||
217 | case WAVERR_SYNC: errorMsg += "The device is synchronous but waveOutOpen was called without using the WAVE_ALLOWSYNC flag."; break; | ||
218 | default: errorMsg += "Undefined error"; break; | ||
219 | } | ||
220 | qDebug( errorMsg, result ); | ||
221 | } | ||
222 | |||
223 | d->bufferSize = sound_fragment_bytes; | ||
224 | #else | ||
225 | 203 | ||
226 | int fragments = 0x10000 * 8 + sound_fragment_shift; | 204 | int fragments = 0x10000 * 8 + sound_fragment_shift; |
227 | int format = AFMT_S16_LE; | ||
228 | int capabilities = 0; | 205 | int capabilities = 0; |
229 | 206 | ||
230 | #ifdef KEEP_DEVICE_OPEN | 207 | #ifdef KEEP_DEVICE_OPEN |
231 | if ( AudioDevicePrivate::dspFd == 0 ) { | 208 | if ( AudioDevicePrivate::dspFd == 0 ) { |
232 | #endif | 209 | #endif |
233 | if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) { | 210 | if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) { |
234 | qDebug( "error opening audio device /dev/dsp, sending data to /dev/null instead" ); | 211 | perror("open(\"/dev/dsp\") sending to /dev/null instead"); |
235 | d->handle = ::open( "/dev/null", O_WRONLY ); | 212 | d->handle = ::open( "/dev/null", O_WRONLY ); |
236 | } | 213 | } |
237 | #ifdef KEEP_DEVICE_OPEN | 214 | #ifdef KEEP_DEVICE_OPEN |
@@ -241,13 +218,20 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { | |||
241 | } | 218 | } |
242 | #endif | 219 | #endif |
243 | 220 | ||
244 | ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities ); | 221 | if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1) |
245 | ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments ); | 222 | perror("ioctl(\"SNDCTL_DSP_GETCAPS\")"); |
246 | ioctl( d->handle, SNDCTL_DSP_SETFMT, &format ); | 223 | if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1) |
247 | ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency ); | 224 | perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); |
225 | if(ioctl( d->handle, SNDCTL_DSP_SETFMT, & format )==-1) | ||
226 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | ||
227 | qDebug("freq %d", d->frequency); | ||
228 | if(ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency )==-1) | ||
229 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); | ||
230 | qDebug("channels %d",d->channels); | ||
248 | if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) { | 231 | if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) { |
249 | d->channels = ( d->channels == 1 ) ? 2 : d->channels; | 232 | d->channels = ( d->channels == 1 ) ? 2 : d->channels; |
250 | ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ); | 233 | if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1) |
234 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); | ||
251 | } | 235 | } |
252 | 236 | ||
253 | d->bufferSize = sound_fragment_bytes; | 237 | d->bufferSize = sound_fragment_bytes; |
@@ -261,7 +245,6 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { | |||
261 | //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" ); | 245 | //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" ); |
262 | //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" ); | 246 | //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" ); |
263 | //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" ); | 247 | //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" ); |
264 | #endif | ||
265 | } | 248 | } |
266 | 249 | ||
267 | 250 | ||