summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/audiodevice.cpp
Unidiff
Diffstat (limited to 'core/multimedia/opieplayer/audiodevice.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/multimedia/opieplayer/audiodevice.cpp75
1 files changed, 30 insertions, 45 deletions
diff --git a/core/multimedia/opieplayer/audiodevice.cpp b/core/multimedia/opieplayer/audiodevice.cpp
index 8861015..59136af 100644
--- a/core/multimedia/opieplayer/audiodevice.cpp
+++ b/core/multimedia/opieplayer/audiodevice.cpp
@@ -19,3 +19,7 @@
19**********************************************************************/ 19**********************************************************************/
20// L.J.Potter added better error code Fri 02-15-2002 14:37:47
21
22
20#include <stdlib.h> 23#include <stdlib.h>
24#include <stdio.h>
21#include <qpe/qpeapplication.h> 25#include <qpe/qpeapplication.h>
@@ -114,6 +118,7 @@ void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume
114 if ( mixerHandle >= 0 ) { 118 if ( mixerHandle >= 0 ) {
115 ioctl( mixerHandle, MIXER_READ(0), &volume ); 119 if(ioctl( mixerHandle, MIXER_READ(0), &volume )==-1)
120 perror("ioctl(\"MIXER_READ\")");
116 close( mixerHandle ); 121 close( mixerHandle );
117 } else 122 } else
118 qDebug( "get volume of audio device failed" ); 123 perror("open(\"/dev/mixer\")");
119 leftVolume = ((volume & 0x00FF) << 16) / 101; 124 leftVolume = ((volume & 0x00FF) << 16) / 101;
@@ -159,6 +164,8 @@ void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume,
159 if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 164 if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
160 ioctl( mixerHandle, MIXER_WRITE(0), &volume ); 165 if(ioctl( mixerHandle, MIXER_WRITE(0), &volume ) ==-1)
166 perror("ioctl(\"MIXER_WRITE\")");
161 close( mixerHandle ); 167 close( mixerHandle );
162 } else 168 } else
163 qDebug( "set volume of audio device failed" ); 169 perror("open(\"/dev/mixer\")");
170
164# else 171# else
@@ -187,41 +194,13 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) {
187 d->bytesPerSample = bps; 194 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;
188 200
201 qDebug("AD- freq %d, channels %d, b/sample %d, bitrate %d",f,chs,bps,format);
189 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); 202 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) );
190 203
191#ifdef Q_OS_WIN32
192 UINT result;
193 WAVEFORMATEX formatData;
194 formatData.cbSize = sizeof(WAVEFORMATEX);
195/*
196 // Other possible formats windows supports
197 formatData.wFormatTag = WAVE_FORMAT_MPEG;
198 formatData.wFormatTag = WAVE_FORMAT_MPEGLAYER3;
199 formatData.wFormatTag = WAVE_FORMAT_ADPCM;
200*/
201 formatData.wFormatTag = WAVE_FORMAT_PCM;
202 formatData.nAvgBytesPerSec = bps * chs * f;
203 formatData.nBlockAlign = bps * chs;
204 formatData.nChannels = chs;
205 formatData.nSamplesPerSec = f;
206 formatData.wBitsPerSample = bps * 8;
207 // Open a waveform device for output
208 if (result = waveOutOpen((LPHWAVEOUT)&d->handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL)) {
209 QString errorMsg = "error opening audio device.\nReason: %i - ";
210 switch (result) {
211 case MMSYSERR_ALLOCATED:errorMsg += "Specified resource is already allocated."; break;
212 case MMSYSERR_BADDEVICEID:errorMsg += "Specified device identifier is out of range."; break;
213 case MMSYSERR_NODRIVER:errorMsg += "No device driver is present."; break;
214 case MMSYSERR_NOMEM:errorMsg += "Unable to allocate or lock memory."; break;
215 case WAVERR_BADFORMAT:errorMsg += "Attempted to open with an unsupported waveform-audio format."; break;
216 case WAVERR_SYNC: errorMsg += "The device is synchronous but waveOutOpen was called without using the WAVE_ALLOWSYNC flag."; break;
217 default: errorMsg += "Undefined error"; break;
218 }
219 qDebug( errorMsg, result );
220 }
221
222 d->bufferSize = sound_fragment_bytes;
223#else
224 204
225 int fragments = 0x10000 * 8 + sound_fragment_shift; 205 int fragments = 0x10000 * 8 + sound_fragment_shift;
226 int format = AFMT_S16_LE;
227 int capabilities = 0; 206 int capabilities = 0;
@@ -232,3 +211,3 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) {
232 if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) { 211 if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) {
233 qDebug( "error opening audio device /dev/dsp, sending data to /dev/null instead" ); 212 perror("open(\"/dev/dsp\") sending to /dev/null instead");
234 d->handle = ::open( "/dev/null", O_WRONLY ); 213 d->handle = ::open( "/dev/null", O_WRONLY );
@@ -242,9 +221,16 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) {
242 221
243 ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities ); 222 if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1)
244 ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments ); 223 perror("ioctl(\"SNDCTL_DSP_GETCAPS\")");
245 ioctl( d->handle, SNDCTL_DSP_SETFMT, &format ); 224 if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1)
246 ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency ); 225 perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")");
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);
247 if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) { 232 if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) {
248 d->channels = ( d->channels == 1 ) ? 2 : d->channels; 233 d->channels = ( d->channels == 1 ) ? 2 : d->channels;
249 ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ); 234 if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1)
235 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")");
250 } 236 }
@@ -262,3 +248,2 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) {
262 //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" ); 248 //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" );
263#endif
264} 249}