Diffstat (limited to 'core/multimedia/opieplayer/audiodevice.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/audiodevice.cpp | 76 |
1 files changed, 0 insertions, 76 deletions
diff --git a/core/multimedia/opieplayer/audiodevice.cpp b/core/multimedia/opieplayer/audiodevice.cpp index 020f6be..136e06c 100644 --- a/core/multimedia/opieplayer/audiodevice.cpp +++ b/core/multimedia/opieplayer/audiodevice.cpp @@ -26,44 +26,34 @@ #include <qpe/config.h> #include <qmessagebox.h> #include "audiodevice.h" #include <errno.h> #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) #include "qpe/qcopenvelope_qws.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) #include <fcntl.h> #include <sys/ioctl.h> #include <sys/soundcard.h> #include <sys/stat.h> #include <sys/time.h> #include <sys/types.h> #include <unistd.h> #endif -// #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) static const int sound_fragment_shift = 14; # else static const int sound_fragment_shift = 16; # endif static const int sound_fragment_bytes = (1<<sound_fragment_shift); //#endif class AudioDevicePrivate { public: int handle; @@ -92,81 +82,47 @@ public: #endif int AudioDevicePrivate::dspFd = 0; bool AudioDevicePrivate::muted = FALSE; unsigned int AudioDevicePrivate::leftVolume = 0; unsigned int AudioDevicePrivate::rightVolume = 0; void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume, bool &muted ) { muted = AudioDevicePrivate::muted; 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 int mixerHandle = open( "/dev/mixer", O_RDWR ); if ( mixerHandle >= 0 ) { if(ioctl( mixerHandle, MIXER_READ(0), &volume )==-1) perror("ioctl(\"MIXER_READ\")"); close( mixerHandle ); } else perror("open(\"/dev/mixer\")"); leftVolume = ((volume & 0x00FF) << 16) / 101; rightVolume = ((volume & 0xFF00) << 8) / 101; -//#endif } void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, bool muted ) { AudioDevicePrivate::muted = muted; if ( muted ) { 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 ); } -// #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; # if 0 unsigned int lV = (leftVolume * 101) >> 16; unsigned int volume = ((rV << 8) & 0xFF00) | (lV & 0x00FF); int mixerHandle = 0; if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { if(ioctl( mixerHandle, MIXER_WRITE(0), &volume ) ==-1) perror("ioctl(\"MIXER_WRITE\")"); close( mixerHandle ); } else @@ -181,25 +137,24 @@ 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 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted; #endif } - AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { qDebug("creating new audio device"); QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; d = new AudioDevicePrivate; d->frequency = f; d->channels = chs; 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; @@ -257,60 +212,42 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { //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" ); } AudioDevice::~AudioDevice() { qDebug("destryo audiodevice"); QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; -// #ifdef Q_OS_WIN32 -// waveOutClose( (HWAVEOUT)d->handle ); -// #else # ifndef KEEP_DEVICE_OPEN close( d->handle ); // Now it should be safe to shut the handle # endif delete d->unwrittenBuffer; delete d; -//#endif QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; } void AudioDevice::volumeChanged( bool muted ) { AudioDevicePrivate::muted = muted; } 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 int t = ::write( d->handle, buffer, length ); if ( t<0 ) t = 0; if ( t != (int)length) { qDebug("Ahhh!! memcpys 1"); memcpy(d->unwrittenBuffer,buffer+t,length-t); d->unwritten = length-t; } //#endif } unsigned int AudioDevice::channels() const @@ -329,61 +266,48 @@ unsigned int AudioDevice::bytesPerSample() const { return d->bytesPerSample; } unsigned int AudioDevice::bufferSize() const { return d->bufferSize; } unsigned int AudioDevice::canWrite() const { -// #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 ); } if ( d->can_GETOSPACE ) { 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; } -//#endif } 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 int buffered = 0; if ( ioctl( d->handle, SNDCTL_DSP_GETODELAY, &buffered ) ) { qDebug( "failed to get audio device position" ); return -1; } return buffered; -//#endif } |