author | llornkcor <llornkcor> | 2002-06-17 12:54:54 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-06-17 12:54:54 (UTC) |
commit | 282007e58a8a038a0db042341528510e73ac80fc (patch) (side-by-side diff) | |
tree | f1a16c9a6a380bdc4217e9f92ac6ef6128d10717 /core/multimedia/opieplayer/audiodevice.cpp | |
parent | 2917d7481dc8c1b053e3212a699e64948a90ec4c (diff) | |
download | opie-282007e58a8a038a0db042341528510e73ac80fc.zip opie-282007e58a8a038a0db042341528510e73ac80fc.tar.gz opie-282007e58a8a038a0db042341528510e73ac80fc.tar.bz2 |
fixes for goofy crap going on
Diffstat (limited to 'core/multimedia/opieplayer/audiodevice.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/audiodevice.cpp | 292 |
1 files changed, 146 insertions, 146 deletions
diff --git a/core/multimedia/opieplayer/audiodevice.cpp b/core/multimedia/opieplayer/audiodevice.cpp index 3262e38..4c5f12d 100644 --- a/core/multimedia/opieplayer/audiodevice.cpp +++ b/core/multimedia/opieplayer/audiodevice.cpp @@ -1,20 +1,20 @@ /********************************************************************** -** Copyright (C) 2000 Trolltech AS. All rights reserved. -** -** This file is part of Qtopia Environment. -** -** This file may be distributed and/or modified under the terms of the -** GNU General Public License version 2 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. -** -** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -** See http://www.trolltech.com/gpl/ for GPL licensing information. -** -** Contact info@trolltech.com if any conditions of this licensing are -** not clear to you. -** -**********************************************************************/ + ** Copyright (C) 2000 Trolltech AS. All rights reserved. + ** + ** This file is part of Qtopia Environment. + ** + ** This file may be distributed and/or modified under the terms of the + ** GNU General Public License version 2 as published by the Free Software + ** Foundation and appearing in the file LICENSE.GPL included in the + ** packaging of this file. + ** + ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + ** + ** See http://www.trolltech.com/gpl/ for GPL licensing information. + ** + ** Contact info@trolltech.com if any conditions of this licensing are + ** not clear to you. + ** + **********************************************************************/ // L.J.Potter added better error code Fri 02-15-2002 14:37:47 @@ -32,8 +32,7 @@ -#ifdef Q_WS_WIN -#include <windows.h> -#include <mmsystem.h> -#include <mmreg.h> -#endif - +// #ifdef Q_WS_WIN +// #include <windows.h> +// #include <mmsystem.h> +// #include <mmreg.h> +// #endif #if defined(Q_WS_X11) || defined(Q_WS_QWS) @@ -48,7 +47,7 @@ -#if defined(Q_OS_WIN32) -static const int expectedBytesPerMilliSecond = 2 * 2 * 44000 / 1000; -static const int timerResolutionMilliSeconds = 30; -static const int sound_fragment_bytes = timerResolutionMilliSeconds * expectedBytesPerMilliSecond; -#else +// #if defined(Q_OS_WIN32) +// static const int expectedBytesPerMilliSecond = 2 * 2 * 44000 / 1000; +// static const int timerResolutionMilliSeconds = 30; +// static const int sound_fragment_bytes = timerResolutionMilliSeconds * expectedBytesPerMilliSecond; +// #else # if defined(QT_QWS_IPAQ) @@ -59,3 +58,3 @@ static const int sound_fragment_shift = 16; static const int sound_fragment_bytes = (1<<sound_fragment_shift); -#endif +//#endif @@ -69,3 +68,3 @@ public: unsigned int bufferSize; -#ifndef Q_OS_WIN32 +//#ifndef Q_OS_WIN32 bool can_GETOSPACE; @@ -73,3 +72,3 @@ public: unsigned int unwritten; -#endif +//#endif @@ -99,19 +98,19 @@ void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume unsigned int volume; -#ifdef Q_OS_WIN32 - HWAVEOUT handle; - WAVEFORMATEX formatData; - formatData.cbSize = sizeof(WAVEFORMATEX); - formatData.wFormatTag = WAVE_FORMAT_PCM; - formatData.nAvgBytesPerSec = 4 * 44000; - formatData.nBlockAlign = 4; - formatData.nChannels = 2; - formatData.nSamplesPerSec = 44000; - formatData.wBitsPerSample = 16; - waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); - if ( waveOutGetVolume( handle, (LPDWORD)&volume ) ) -// qDebug( "get volume of audio device failed" ); - waveOutClose( handle ); - leftVolume = volume & 0xFFFF; - rightVolume = volume >> 16; -#else +// #ifdef Q_OS_WIN32 +// HWAVEOUT handle; +// WAVEFORMATEX formatData; +// formatData.cbSize = sizeof(WAVEFORMATEX); +// formatData.wFormatTag = WAVE_FORMAT_PCM; +// formatData.nAvgBytesPerSec = 4 * 44000; +// formatData.nBlockAlign = 4; +// formatData.nChannels = 2; +// formatData.nSamplesPerSec = 44000; +// formatData.wBitsPerSample = 16; +// waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); +// if ( waveOutGetVolume( handle, (LPDWORD)&volume ) ) +// // qDebug( "get volume of audio device failed" ); +// waveOutClose( handle ); +// leftVolume = volume & 0xFFFF; +// rightVolume = volume >> 16; +// #else int mixerHandle = open( "/dev/mixer", O_RDWR ); @@ -119,3 +118,3 @@ void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume if(ioctl( mixerHandle, MIXER_READ(0), &volume )==-1) - perror("ioctl(\"MIXER_READ\")"); + perror("ioctl(\"MIXER_READ\")"); close( mixerHandle ); @@ -125,3 +124,3 @@ void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume rightVolume = ((volume & 0xFF00) << 8) / 101; -#endif +//#endif } @@ -132,27 +131,27 @@ void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, if ( muted ) { - AudioDevicePrivate::leftVolume = leftVolume; - AudioDevicePrivate::rightVolume = rightVolume; - leftVolume = 0; - rightVolume = 0; + AudioDevicePrivate::leftVolume = leftVolume; + AudioDevicePrivate::rightVolume = rightVolume; + leftVolume = 0; + rightVolume = 0; } else { leftVolume = ( (int) leftVolume < 0 ) ? 0 : (( leftVolume > 0xFFFF ) ? 0xFFFF : leftVolume ); - rightVolume = ( (int)rightVolume < 0 ) ? 0 : (( rightVolume > 0xFFFF ) ? 0xFFFF : rightVolume ); + rightVolume = ( (int)rightVolume < 0 ) ? 0 : (( rightVolume > 0xFFFF ) ? 0xFFFF : rightVolume ); } -#ifdef Q_OS_WIN32 - HWAVEOUT handle; - WAVEFORMATEX formatData; - formatData.cbSize = sizeof(WAVEFORMATEX); - formatData.wFormatTag = WAVE_FORMAT_PCM; - formatData.nAvgBytesPerSec = 4 * 44000; - formatData.nBlockAlign = 4; - formatData.nChannels = 2; - formatData.nSamplesPerSec = 44000; - formatData.wBitsPerSample = 16; - waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); - unsigned int volume = (rightVolume << 16) | leftVolume; - if ( waveOutSetVolume( handle, volume ) ) -// qDebug( "set volume of audio device failed" ); - waveOutClose( handle ); -#else - // Volume can be from 0 to 100 which is 101 distinct values +// #ifdef Q_OS_WIN32 +// HWAVEOUT handle; +// WAVEFORMATEX formatData; +// formatData.cbSize = sizeof(WAVEFORMATEX); +// formatData.wFormatTag = WAVE_FORMAT_PCM; +// formatData.nAvgBytesPerSec = 4 * 44000; +// formatData.nBlockAlign = 4; +// formatData.nChannels = 2; +// formatData.nSamplesPerSec = 44000; +// formatData.wBitsPerSample = 16; +// waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); +// unsigned int volume = (rightVolume << 16) | leftVolume; +// if ( waveOutSetVolume( handle, volume ) ) +// // qDebug( "set volume of audio device failed" ); +// waveOutClose( handle ); +// #else + // Volume can be from 0 to 100 which is 101 distinct values unsigned int rV = (rightVolume * 101) >> 16; @@ -171,4 +170,4 @@ void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, # else - // This is the way this has to be done now I guess, doesn't allow for - // independant right and left channel setting, or setting for different outputs + // This is the way this has to be done now I guess, doesn't allow for + // independant right and left channel setting, or setting for different outputs Config cfg("Sound"); @@ -178,6 +177,6 @@ void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, -#endif +//#endif // qDebug( "setting volume to: 0x%x", volume ); #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) - // Send notification that the volume has changed + // Send notification that the volume has changed QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted; @@ -190,5 +189,5 @@ void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { - qDebug("creating new audio device"); + qDebug("creating new audio device"); QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; - d = new AudioDevicePrivate; + d = new AudioDevicePrivate; d->frequency = f; @@ -211,8 +210,8 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { #endif - if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) { - perror("open(\"/dev/dsp\") sending to /dev/null instead"); - d->handle = ::open( "/dev/null", O_WRONLY ); - } + if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) { + perror("open(\"/dev/dsp\") sending to /dev/null instead"); + d->handle = ::open( "/dev/null", O_WRONLY ); + } #ifdef KEEP_DEVICE_OPEN - AudioDevicePrivate::dspFd = d->handle; + AudioDevicePrivate::dspFd = d->handle; } else { @@ -243,8 +242,8 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { - //if ( chs != d->channels ) qDebug( "Wanted %d, got %d channels", chs, d->channels ); - //if ( f != d->frequency ) qDebug( "wanted %dHz, got %dHz", f, d->frequency ); - //if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" ); - //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" ); - //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" ); - //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" ); + //if ( chs != d->channels ) qDebug( "Wanted %d, got %d channels", chs, d->channels ); + //if ( f != d->frequency ) qDebug( "wanted %dHz, got %dHz", f, d->frequency ); + //if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" ); + //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" ); + //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" ); + //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" ); QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; @@ -256,7 +255,7 @@ AudioDevice::~AudioDevice() { qDebug("destryo audiodevice"); - QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; + QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; -#ifdef Q_OS_WIN32 - waveOutClose( (HWAVEOUT)d->handle ); -#else +// #ifdef Q_OS_WIN32 +// waveOutClose( (HWAVEOUT)d->handle ); +// #else # ifndef KEEP_DEVICE_OPEN @@ -266,3 +265,4 @@ AudioDevice::~AudioDevice() { delete d; -#endif +//#endif + QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; @@ -279,16 +279,16 @@ void AudioDevice::write( char *buffer, unsigned int length ) { -#ifdef Q_OS_WIN32 - // returns immediately and (to be implemented) emits completedIO() when finished writing - WAVEHDR *lpWaveHdr = (WAVEHDR *)malloc( sizeof(WAVEHDR) ); - // maybe the buffer should be copied so that this fool proof, but its a performance hit - lpWaveHdr->lpData = buffer; - lpWaveHdr->dwBufferLength = length; - lpWaveHdr->dwFlags = 0L; - lpWaveHdr->dwLoops = 0L; - waveOutPrepareHeader( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) ); - // waveOutWrite returns immediately. the data is sent in the background. - if ( waveOutWrite( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) ) ) - qDebug( "failed to write block to audio device" ); - // emit completedIO(); -#else +// #ifdef Q_OS_WIN32 +// // returns immediately and (to be implemented) emits completedIO() when finished writing +// WAVEHDR *lpWaveHdr = (WAVEHDR *)malloc( sizeof(WAVEHDR) ); +// // maybe the buffer should be copied so that this fool proof, but its a performance hit +// lpWaveHdr->lpData = buffer; +// lpWaveHdr->dwBufferLength = length; +// lpWaveHdr->dwFlags = 0L; +// lpWaveHdr->dwLoops = 0L; +// waveOutPrepareHeader( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) ); +// // waveOutWrite returns immediately. the data is sent in the background. +// if ( waveOutWrite( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) ) ) +// qDebug( "failed to write block to audio device" ); +// // emit completedIO(); +// #else int t = ::write( d->handle, buffer, length ); @@ -296,7 +296,7 @@ void AudioDevice::write( char *buffer, unsigned int length ) if ( t != (int)length) { - qDebug("Ahhh!! memcpys 1"); - memcpy(d->unwrittenBuffer,buffer+t,length-t); - d->unwritten = length-t; + qDebug("Ahhh!! memcpys 1"); + memcpy(d->unwrittenBuffer,buffer+t,length-t); + d->unwritten = length-t; } -#endif +//#endif } @@ -329,30 +329,30 @@ unsigned int AudioDevice::canWrite() const { -#ifdef Q_OS_WIN32 - return bufferSize(); // Any better? -#else +// #ifdef Q_OS_WIN32 +// return bufferSize(); // Any better? +// #else audio_buf_info info; if ( d->can_GETOSPACE && ioctl(d->handle,SNDCTL_DSP_GETOSPACE,&info) ) { - d->can_GETOSPACE = FALSE; - fcntl( d->handle, F_SETFL, O_NONBLOCK ); + d->can_GETOSPACE = FALSE; + fcntl( d->handle, F_SETFL, O_NONBLOCK ); } if ( d->can_GETOSPACE ) { - int t = info.fragments * sound_fragment_bytes; - return QMIN(t,(int)bufferSize()); + int t = info.fragments * sound_fragment_bytes; + return QMIN(t,(int)bufferSize()); } else { - if ( d->unwritten ) { - int t = ::write( d->handle, d->unwrittenBuffer, d->unwritten ); - if ( t<0 ) t = 0; - if ( (unsigned)t!=d->unwritten ) { - memcpy(d->unwrittenBuffer,d->unwrittenBuffer+t,d->unwritten-t); - d->unwritten -= t; - } else { - d->unwritten = 0; - } - } - if ( d->unwritten ) - return 0; - else - return d->bufferSize; + if ( d->unwritten ) { + int t = ::write( d->handle, d->unwrittenBuffer, d->unwritten ); + if ( t<0 ) t = 0; + if ( (unsigned)t!=d->unwritten ) { + memcpy(d->unwrittenBuffer,d->unwrittenBuffer+t,d->unwritten-t); + d->unwritten -= t; + } else { + d->unwritten = 0; + } + } + if ( d->unwritten ) + return 0; + else + return d->bufferSize; } -#endif +//#endif } @@ -361,17 +361,17 @@ unsigned int AudioDevice::canWrite() const int AudioDevice::bytesWritten() { -#ifdef Q_OS_WIN32 - MMTIME pmmt = { TIME_BYTES, 0 }; - if ( ( waveOutGetPosition( (HWAVEOUT)d->handle, &pmmt, sizeof(MMTIME) ) != MMSYSERR_NOERROR ) || ( pmmt.wType != TIME_BYTES ) ) { - qDebug( "failed to get audio device position" ); - return -1; - } - return pmmt.u.cb; -#else +// #ifdef Q_OS_WIN32 +// MMTIME pmmt = { TIME_BYTES, 0 }; +// if ( ( waveOutGetPosition( (HWAVEOUT)d->handle, &pmmt, sizeof(MMTIME) ) != MMSYSERR_NOERROR ) || ( pmmt.wType != TIME_BYTES ) ) { +// qDebug( "failed to get audio device position" ); +// return -1; +// } +// return pmmt.u.cb; +// #else int buffered = 0; if ( ioctl( d->handle, SNDCTL_DSP_GETODELAY, &buffered ) ) { - qDebug( "failed to get audio device position" ); - return -1; + qDebug( "failed to get audio device position" ); + return -1; } return buffered; -#endif +//#endif } |