Diffstat (limited to 'core/multimedia/opieplayer/audiodevice.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/audiodevice.cpp | 82 |
1 files changed, 49 insertions, 33 deletions
diff --git a/core/multimedia/opieplayer/audiodevice.cpp b/core/multimedia/opieplayer/audiodevice.cpp index 11fd9e8..7b3700a 100644 --- a/core/multimedia/opieplayer/audiodevice.cpp +++ b/core/multimedia/opieplayer/audiodevice.cpp | |||
@@ -1,6 +1,6 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of the 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 |
@@ -18,9 +18,6 @@ | |||
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | // L.J.Potter added better error code Fri 02-15-2002 14:37:47 | ||
21 | |||
22 | 20 | ||
23 | #include <stdlib.h> | 21 | #include <stdlib.h> |
24 | #include <stdio.h> | ||
25 | #include <qpe/qpeapplication.h> | 22 | #include <qpe/qpeapplication.h> |
26 | #include <qpe/config.h> | 23 | #include <qpe/config.h> |
@@ -110,5 +107,5 @@ void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume | |||
110 | waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); | 107 | waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); |
111 | if ( waveOutGetVolume( handle, (LPDWORD)&volume ) ) | 108 | if ( waveOutGetVolume( handle, (LPDWORD)&volume ) ) |
112 | // qDebug( "get volume of audio device failed" ); | 109 | qDebug( "get volume of audio device failed" ); |
113 | waveOutClose( handle ); | 110 | waveOutClose( handle ); |
114 | leftVolume = volume & 0xFFFF; | 111 | leftVolume = volume & 0xFFFF; |
@@ -117,9 +114,8 @@ void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume | |||
117 | int mixerHandle = open( "/dev/mixer", O_RDWR ); | 114 | int mixerHandle = open( "/dev/mixer", O_RDWR ); |
118 | if ( mixerHandle >= 0 ) { | 115 | if ( mixerHandle >= 0 ) { |
119 | if(ioctl( mixerHandle, MIXER_READ(0), &volume )==-1) | 116 | ioctl( mixerHandle, MIXER_READ(0), &volume ); |
120 | perror("ioctl(\"MIXER_READ\")"); | ||
121 | close( mixerHandle ); | 117 | close( mixerHandle ); |
122 | } else | 118 | } else |
123 | perror("open(\"/dev/mixer\")"); | 119 | qDebug( "get volume of audio device failed" ); |
124 | leftVolume = ((volume & 0x00FF) << 16) / 101; | 120 | leftVolume = ((volume & 0x00FF) << 16) / 101; |
125 | rightVolume = ((volume & 0xFF00) << 8) / 101; | 121 | rightVolume = ((volume & 0xFF00) << 8) / 101; |
@@ -152,5 +148,5 @@ void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, | |||
152 | unsigned int volume = (rightVolume << 16) | leftVolume; | 148 | unsigned int volume = (rightVolume << 16) | leftVolume; |
153 | if ( waveOutSetVolume( handle, volume ) ) | 149 | if ( waveOutSetVolume( handle, volume ) ) |
154 | // qDebug( "set volume of audio device failed" ); | 150 | qDebug( "set volume of audio device failed" ); |
155 | waveOutClose( handle ); | 151 | waveOutClose( handle ); |
156 | #else | 152 | #else |
@@ -163,10 +159,8 @@ void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, | |||
163 | int mixerHandle = 0; | 159 | int mixerHandle = 0; |
164 | if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { | 160 | if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { |
165 | if(ioctl( mixerHandle, MIXER_WRITE(0), &volume ) ==-1) | 161 | ioctl( mixerHandle, MIXER_WRITE(0), &volume ); |
166 | perror("ioctl(\"MIXER_WRITE\")"); | ||
167 | close( mixerHandle ); | 162 | close( mixerHandle ); |
168 | } else | 163 | } else |
169 | perror("open(\"/dev/mixer\")"); | 164 | qDebug( "set volume of audio device failed" ); |
170 | |||
171 | # else | 165 | # else |
172 | // This is the way this has to be done now I guess, doesn't allow for | 166 | // This is the way this has to be done now I guess, doesn't allow for |
@@ -193,15 +187,43 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { | |||
193 | d->channels = chs; | 187 | d->channels = chs; |
194 | d->bytesPerSample = bps; | 188 | d->bytesPerSample = bps; |
195 | // qDebug("%d",bps); | ||
196 | int format=0; | ||
197 | if( bps == 8) format = AFMT_U8; | ||
198 | else if( bps <= 0) format = AFMT_S16_LE; | ||
199 | else format = AFMT_S16_LE; | ||
200 | 189 | ||
201 | // qDebug("AD- freq %d, channels %d, b/sample %d, bitrate %d",f,chs,bps,format); | ||
202 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); | 190 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); |
203 | 191 | ||
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 | ||
204 | 225 | ||
205 | int fragments = 0x10000 * 8 + sound_fragment_shift; | 226 | int fragments = 0x10000 * 8 + sound_fragment_shift; |
227 | int format = AFMT_S16_LE; | ||
206 | int capabilities = 0; | 228 | int capabilities = 0; |
207 | 229 | ||
@@ -210,5 +232,5 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { | |||
210 | #endif | 232 | #endif |
211 | if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) { | 233 | if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) { |
212 | perror("open(\"/dev/dsp\") sending to /dev/null instead"); | 234 | qDebug( "error opening audio device /dev/dsp, sending data to /dev/null instead" ); |
213 | d->handle = ::open( "/dev/null", O_WRONLY ); | 235 | d->handle = ::open( "/dev/null", O_WRONLY ); |
214 | } | 236 | } |
@@ -220,18 +242,11 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { | |||
220 | #endif | 242 | #endif |
221 | 243 | ||
222 | if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1) | 244 | ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities ); |
223 | perror("ioctl(\"SNDCTL_DSP_GETCAPS\")"); | 245 | ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments ); |
224 | if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1) | 246 | ioctl( d->handle, SNDCTL_DSP_SETFMT, &format ); |
225 | perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); | 247 | ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency ); |
226 | if(ioctl( d->handle, SNDCTL_DSP_SETFMT, & format )==-1) | ||
227 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | ||
228 | qDebug("freq %d", d->frequency); | ||
229 | if(ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency )==-1) | ||
230 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); | ||
231 | qDebug("channels %d",d->channels); | ||
232 | if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) { | 248 | if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) { |
233 | d->channels = ( d->channels == 1 ) ? 2 : d->channels; | 249 | d->channels = ( d->channels == 1 ) ? 2 : d->channels; |
234 | if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1) | 250 | ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ); |
235 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); | ||
236 | } | 251 | } |
237 | 252 | ||
@@ -247,4 +262,5 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { | |||
247 | //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" ); | 262 | //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" ); |
248 | //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" ); | 263 | //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" ); |
264 | #endif | ||
249 | } | 265 | } |
250 | 266 | ||