summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/audiodevice.cpp
Side-by-side diff
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 @@
/**********************************************************************
-** Copyright (C) 2000 Trolltech AS. All rights reserved.
+** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
-** This file is part of Qtopia Environment.
+** This file is part of the Qtopia Environment.
**
@@ -19,7 +19,4 @@
**********************************************************************/
-// L.J.Potter added better error code Fri 02-15-2002 14:37:47
-
#include <stdlib.h>
-#include <stdio.h>
#include <qpe/qpeapplication.h>
@@ -111,3 +108,3 @@ void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume
if ( waveOutGetVolume( handle, (LPDWORD)&volume ) )
-// qDebug( "get volume of audio device failed" );
+ qDebug( "get volume of audio device failed" );
waveOutClose( handle );
@@ -118,7 +115,6 @@ void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume
if ( mixerHandle >= 0 ) {
- if(ioctl( mixerHandle, MIXER_READ(0), &volume )==-1)
- perror("ioctl(\"MIXER_READ\")");
+ ioctl( mixerHandle, MIXER_READ(0), &volume );
close( mixerHandle );
} else
- perror("open(\"/dev/mixer\")");
+ qDebug( "get volume of audio device failed" );
leftVolume = ((volume & 0x00FF) << 16) / 101;
@@ -153,3 +149,3 @@ void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume,
if ( waveOutSetVolume( handle, volume ) )
-// qDebug( "set volume of audio device failed" );
+ qDebug( "set volume of audio device failed" );
waveOutClose( handle );
@@ -164,8 +160,6 @@ void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume,
if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
- if(ioctl( mixerHandle, MIXER_WRITE(0), &volume ) ==-1)
- perror("ioctl(\"MIXER_WRITE\")");
+ ioctl( mixerHandle, MIXER_WRITE(0), &volume );
close( mixerHandle );
} else
- perror("open(\"/dev/mixer\")");
-
+ qDebug( "set volume of audio device failed" );
# else
@@ -194,13 +188,41 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) {
d->bytesPerSample = bps;
-// qDebug("%d",bps);
- int format=0;
- if( bps == 8) format = AFMT_U8;
- else if( bps <= 0) format = AFMT_S16_LE;
- else format = AFMT_S16_LE;
-// qDebug("AD- freq %d, channels %d, b/sample %d, bitrate %d",f,chs,bps,format);
connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) );
+#ifdef Q_OS_WIN32
+ UINT result;
+ WAVEFORMATEX formatData;
+ formatData.cbSize = sizeof(WAVEFORMATEX);
+/*
+ // Other possible formats windows supports
+ formatData.wFormatTag = WAVE_FORMAT_MPEG;
+ formatData.wFormatTag = WAVE_FORMAT_MPEGLAYER3;
+ formatData.wFormatTag = WAVE_FORMAT_ADPCM;
+*/
+ formatData.wFormatTag = WAVE_FORMAT_PCM;
+ formatData.nAvgBytesPerSec = bps * chs * f;
+ formatData.nBlockAlign = bps * chs;
+ formatData.nChannels = chs;
+ formatData.nSamplesPerSec = f;
+ formatData.wBitsPerSample = bps * 8;
+ // Open a waveform device for output
+ if (result = waveOutOpen((LPHWAVEOUT)&d->handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL)) {
+ QString errorMsg = "error opening audio device.\nReason: %i - ";
+ switch (result) {
+ case MMSYSERR_ALLOCATED: errorMsg += "Specified resource is already allocated."; break;
+ case MMSYSERR_BADDEVICEID: errorMsg += "Specified device identifier is out of range."; break;
+ case MMSYSERR_NODRIVER: errorMsg += "No device driver is present."; break;
+ case MMSYSERR_NOMEM: errorMsg += "Unable to allocate or lock memory."; break;
+ case WAVERR_BADFORMAT: errorMsg += "Attempted to open with an unsupported waveform-audio format."; break;
+ case WAVERR_SYNC: errorMsg += "The device is synchronous but waveOutOpen was called without using the WAVE_ALLOWSYNC flag."; break;
+ default: errorMsg += "Undefined error"; break;
+ }
+ qDebug( errorMsg, result );
+ }
+
+ d->bufferSize = sound_fragment_bytes;
+#else
int fragments = 0x10000 * 8 + sound_fragment_shift;
+ int format = AFMT_S16_LE;
int capabilities = 0;
@@ -211,3 +233,3 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) {
if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) {
- perror("open(\"/dev/dsp\") sending to /dev/null instead");
+ qDebug( "error opening audio device /dev/dsp, sending data to /dev/null instead" );
d->handle = ::open( "/dev/null", O_WRONLY );
@@ -221,16 +243,9 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) {
- if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1)
- perror("ioctl(\"SNDCTL_DSP_GETCAPS\")");
- if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1)
- perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")");
- if(ioctl( d->handle, SNDCTL_DSP_SETFMT, & format )==-1)
- perror("ioctl(\"SNDCTL_DSP_SETFMT\")");
- qDebug("freq %d", d->frequency);
- if(ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency )==-1)
- perror("ioctl(\"SNDCTL_DSP_SPEED\")");
- qDebug("channels %d",d->channels);
+ ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities );
+ ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments );
+ ioctl( d->handle, SNDCTL_DSP_SETFMT, &format );
+ ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency );
if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) {
d->channels = ( d->channels == 1 ) ? 2 : d->channels;
- if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1)
- perror("ioctl(\"SNDCTL_DSP_CHANNELS\")");
+ ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels );
}
@@ -248,2 +263,3 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) {
//if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" );
+#endif
}