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.cpp82
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,5 +1,5 @@
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**
@@ -19,7 +19,4 @@
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>
@@ -111,3 +108,3 @@ void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume
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 );
@@ -118,7 +115,6 @@ void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume
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;
@@ -153,3 +149,3 @@ void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume,
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 );
@@ -164,8 +160,6 @@ void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume,
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
@@ -194,13 +188,41 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) {
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;
@@ -211,3 +233,3 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) {
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 );
@@ -221,16 +243,9 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) {
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 }
@@ -248,2 +263,3 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) {
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}