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.cpp81
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,5 +1,5 @@
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**
@@ -19,4 +19,6 @@
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>
@@ -108,3 +110,3 @@ void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume
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 );
@@ -115,6 +117,7 @@ void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume
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;
@@ -149,3 +152,3 @@ void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume,
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 );
@@ -160,6 +163,8 @@ void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume,
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
@@ -188,41 +193,13 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) {
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;
@@ -233,3 +210,3 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) {
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 );
@@ -243,9 +220,16 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) {
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 }
@@ -263,3 +247,2 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) {
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}