Diffstat (limited to 'core/multimedia/opieplayer/audiodevice.cpp') (more/less context) (show 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 | |||
@@ -32,32 +32,22 @@ | |||
32 | #include <errno.h> | 32 | #include <errno.h> |
33 | 33 | ||
34 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) | 34 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) |
35 | #include "qpe/qcopenvelope_qws.h" | 35 | #include "qpe/qcopenvelope_qws.h" |
36 | #endif | 36 | #endif |
37 | 37 | ||
38 | // #ifdef Q_WS_WIN | ||
39 | // #include <windows.h> | ||
40 | // #include <mmsystem.h> | ||
41 | // #include <mmreg.h> | ||
42 | // #endif | ||
43 | #if defined(Q_WS_X11) || defined(Q_WS_QWS) | 38 | #if defined(Q_WS_X11) || defined(Q_WS_QWS) |
44 | #include <fcntl.h> | 39 | #include <fcntl.h> |
45 | #include <sys/ioctl.h> | 40 | #include <sys/ioctl.h> |
46 | #include <sys/soundcard.h> | 41 | #include <sys/soundcard.h> |
47 | #include <sys/stat.h> | 42 | #include <sys/stat.h> |
48 | #include <sys/time.h> | 43 | #include <sys/time.h> |
49 | #include <sys/types.h> | 44 | #include <sys/types.h> |
50 | #include <unistd.h> | 45 | #include <unistd.h> |
51 | #endif | 46 | #endif |
52 | 47 | ||
53 | // #if defined(Q_OS_WIN32) | ||
54 | // static const int expectedBytesPerMilliSecond = 2 * 2 * 44000 / 1000; | ||
55 | // static const int timerResolutionMilliSeconds = 30; | ||
56 | // static const int sound_fragment_bytes = timerResolutionMilliSeconds * expectedBytesPerMilliSecond; | ||
57 | // #else | ||
58 | # if defined(QT_QWS_IPAQ) | 48 | # if defined(QT_QWS_IPAQ) |
59 | static const int sound_fragment_shift = 14; | 49 | static const int sound_fragment_shift = 14; |
60 | # else | 50 | # else |
61 | static const int sound_fragment_shift = 16; | 51 | static const int sound_fragment_shift = 16; |
62 | # endif | 52 | # endif |
63 | static const int sound_fragment_bytes = (1<<sound_fragment_shift); | 53 | static const int sound_fragment_bytes = (1<<sound_fragment_shift); |
@@ -98,39 +88,21 @@ unsigned int AudioDevicePrivate::leftVolume = 0; | |||
98 | unsigned int AudioDevicePrivate::rightVolume = 0; | 88 | unsigned int AudioDevicePrivate::rightVolume = 0; |
99 | 89 | ||
100 | 90 | ||
101 | void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume, bool &muted ) { | 91 | void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume, bool &muted ) { |
102 | muted = AudioDevicePrivate::muted; | 92 | muted = AudioDevicePrivate::muted; |
103 | unsigned int volume; | 93 | unsigned int volume; |
104 | // #ifdef Q_OS_WIN32 | ||
105 | // HWAVEOUT handle; | ||
106 | // WAVEFORMATEX formatData; | ||
107 | // formatData.cbSize = sizeof(WAVEFORMATEX); | ||
108 | // formatData.wFormatTag = WAVE_FORMAT_PCM; | ||
109 | // formatData.nAvgBytesPerSec = 4 * 44000; | ||
110 | // formatData.nBlockAlign = 4; | ||
111 | // formatData.nChannels = 2; | ||
112 | // formatData.nSamplesPerSec = 44000; | ||
113 | // formatData.wBitsPerSample = 16; | ||
114 | // waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); | ||
115 | // if ( waveOutGetVolume( handle, (LPDWORD)&volume ) ) | ||
116 | // // qDebug( "get volume of audio device failed" ); | ||
117 | // waveOutClose( handle ); | ||
118 | // leftVolume = volume & 0xFFFF; | ||
119 | // rightVolume = volume >> 16; | ||
120 | // #else | ||
121 | int mixerHandle = open( "/dev/mixer", O_RDWR ); | 94 | int mixerHandle = open( "/dev/mixer", O_RDWR ); |
122 | if ( mixerHandle >= 0 ) { | 95 | if ( mixerHandle >= 0 ) { |
123 | if(ioctl( mixerHandle, MIXER_READ(0), &volume )==-1) | 96 | if(ioctl( mixerHandle, MIXER_READ(0), &volume )==-1) |
124 | perror("ioctl(\"MIXER_READ\")"); | 97 | perror("ioctl(\"MIXER_READ\")"); |
125 | close( mixerHandle ); | 98 | close( mixerHandle ); |
126 | } else | 99 | } else |
127 | perror("open(\"/dev/mixer\")"); | 100 | perror("open(\"/dev/mixer\")"); |
128 | leftVolume = ((volume & 0x00FF) << 16) / 101; | 101 | leftVolume = ((volume & 0x00FF) << 16) / 101; |
129 | rightVolume = ((volume & 0xFF00) << 8) / 101; | 102 | rightVolume = ((volume & 0xFF00) << 8) / 101; |
130 | //#endif | ||
131 | } | 103 | } |
132 | 104 | ||
133 | 105 | ||
134 | void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, bool muted ) { | 106 | void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, bool muted ) { |
135 | AudioDevicePrivate::muted = muted; | 107 | AudioDevicePrivate::muted = muted; |
136 | if ( muted ) { | 108 | if ( muted ) { |
@@ -139,28 +111,12 @@ void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, | |||
139 | leftVolume = 0; | 111 | leftVolume = 0; |
140 | rightVolume = 0; | 112 | rightVolume = 0; |
141 | } else { | 113 | } else { |
142 | leftVolume = ( (int) leftVolume < 0 ) ? 0 : (( leftVolume > 0xFFFF ) ? 0xFFFF : leftVolume ); | 114 | leftVolume = ( (int) leftVolume < 0 ) ? 0 : (( leftVolume > 0xFFFF ) ? 0xFFFF : leftVolume ); |
143 | rightVolume = ( (int)rightVolume < 0 ) ? 0 : (( rightVolume > 0xFFFF ) ? 0xFFFF : rightVolume ); | 115 | rightVolume = ( (int)rightVolume < 0 ) ? 0 : (( rightVolume > 0xFFFF ) ? 0xFFFF : rightVolume ); |
144 | } | 116 | } |
145 | // #ifdef Q_OS_WIN32 | ||
146 | // HWAVEOUT handle; | ||
147 | // WAVEFORMATEX formatData; | ||
148 | // formatData.cbSize = sizeof(WAVEFORMATEX); | ||
149 | // formatData.wFormatTag = WAVE_FORMAT_PCM; | ||
150 | // formatData.nAvgBytesPerSec = 4 * 44000; | ||
151 | // formatData.nBlockAlign = 4; | ||
152 | // formatData.nChannels = 2; | ||
153 | // formatData.nSamplesPerSec = 44000; | ||
154 | // formatData.wBitsPerSample = 16; | ||
155 | // waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); | ||
156 | // unsigned int volume = (rightVolume << 16) | leftVolume; | ||
157 | // if ( waveOutSetVolume( handle, volume ) ) | ||
158 | // // qDebug( "set volume of audio device failed" ); | ||
159 | // waveOutClose( handle ); | ||
160 | // #else | ||
161 | // Volume can be from 0 to 100 which is 101 distinct values | 117 | // Volume can be from 0 to 100 which is 101 distinct values |
162 | unsigned int rV = (rightVolume * 101) >> 16; | 118 | unsigned int rV = (rightVolume * 101) >> 16; |
163 | 119 | ||
164 | # if 0 | 120 | # if 0 |
165 | unsigned int lV = (leftVolume * 101) >> 16; | 121 | unsigned int lV = (leftVolume * 101) >> 16; |
166 | unsigned int volume = ((rV << 8) & 0xFF00) | (lV & 0x00FF); | 122 | unsigned int volume = ((rV << 8) & 0xFF00) | (lV & 0x00FF); |
@@ -187,13 +143,12 @@ void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, | |||
187 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted; | 143 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted; |
188 | #endif | 144 | #endif |
189 | } | 145 | } |
190 | 146 | ||
191 | 147 | ||
192 | 148 | ||
193 | |||
194 | AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { | 149 | AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { |
195 | qDebug("creating new audio device"); | 150 | qDebug("creating new audio device"); |
196 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; | 151 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; |
197 | d = new AudioDevicePrivate; | 152 | d = new AudioDevicePrivate; |
198 | d->frequency = f; | 153 | d->frequency = f; |
199 | d->channels = chs; | 154 | d->channels = chs; |
@@ -263,21 +218,17 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { | |||
263 | 218 | ||
264 | 219 | ||
265 | AudioDevice::~AudioDevice() { | 220 | AudioDevice::~AudioDevice() { |
266 | qDebug("destryo audiodevice"); | 221 | qDebug("destryo audiodevice"); |
267 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; | 222 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; |
268 | 223 | ||
269 | // #ifdef Q_OS_WIN32 | ||
270 | // waveOutClose( (HWAVEOUT)d->handle ); | ||
271 | // #else | ||
272 | # ifndef KEEP_DEVICE_OPEN | 224 | # ifndef KEEP_DEVICE_OPEN |
273 | close( d->handle ); // Now it should be safe to shut the handle | 225 | close( d->handle ); // Now it should be safe to shut the handle |
274 | # endif | 226 | # endif |
275 | delete d->unwrittenBuffer; | 227 | delete d->unwrittenBuffer; |
276 | delete d; | 228 | delete d; |
277 | //#endif | ||
278 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; | 229 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; |
279 | 230 | ||
280 | } | 231 | } |
281 | 232 | ||
282 | 233 | ||
283 | void AudioDevice::volumeChanged( bool muted ) | 234 | void AudioDevice::volumeChanged( bool muted ) |
@@ -285,26 +236,12 @@ void AudioDevice::volumeChanged( bool muted ) | |||
285 | AudioDevicePrivate::muted = muted; | 236 | AudioDevicePrivate::muted = muted; |
286 | } | 237 | } |
287 | 238 | ||
288 | 239 | ||
289 | void AudioDevice::write( char *buffer, unsigned int length ) | 240 | void AudioDevice::write( char *buffer, unsigned int length ) |
290 | { | 241 | { |
291 | // #ifdef Q_OS_WIN32 | ||
292 | // // returns immediately and (to be implemented) emits completedIO() when finished writing | ||
293 | // WAVEHDR *lpWaveHdr = (WAVEHDR *)malloc( sizeof(WAVEHDR) ); | ||
294 | // // maybe the buffer should be copied so that this fool proof, but its a performance hit | ||
295 | // lpWaveHdr->lpData = buffer; | ||
296 | // lpWaveHdr->dwBufferLength = length; | ||
297 | // lpWaveHdr->dwFlags = 0L; | ||
298 | // lpWaveHdr->dwLoops = 0L; | ||
299 | // waveOutPrepareHeader( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) ); | ||
300 | // // waveOutWrite returns immediately. the data is sent in the background. | ||
301 | // if ( waveOutWrite( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) ) ) | ||
302 | // qDebug( "failed to write block to audio device" ); | ||
303 | // // emit completedIO(); | ||
304 | // #else | ||
305 | int t = ::write( d->handle, buffer, length ); | 242 | int t = ::write( d->handle, buffer, length ); |
306 | if ( t<0 ) t = 0; | 243 | if ( t<0 ) t = 0; |
307 | if ( t != (int)length) { | 244 | if ( t != (int)length) { |
308 | qDebug("Ahhh!! memcpys 1"); | 245 | qDebug("Ahhh!! memcpys 1"); |
309 | memcpy(d->unwrittenBuffer,buffer+t,length-t); | 246 | memcpy(d->unwrittenBuffer,buffer+t,length-t); |
310 | d->unwritten = length-t; | 247 | d->unwritten = length-t; |
@@ -335,15 +272,12 @@ unsigned int AudioDevice::bufferSize() const | |||
335 | { | 272 | { |
336 | return d->bufferSize; | 273 | return d->bufferSize; |
337 | } | 274 | } |
338 | 275 | ||
339 | unsigned int AudioDevice::canWrite() const | 276 | unsigned int AudioDevice::canWrite() const |
340 | { | 277 | { |
341 | // #ifdef Q_OS_WIN32 | ||
342 | // return bufferSize(); // Any better? | ||
343 | // #else | ||
344 | audio_buf_info info; | 278 | audio_buf_info info; |
345 | if ( d->can_GETOSPACE && ioctl(d->handle,SNDCTL_DSP_GETOSPACE,&info) ) { | 279 | if ( d->can_GETOSPACE && ioctl(d->handle,SNDCTL_DSP_GETOSPACE,&info) ) { |
346 | d->can_GETOSPACE = FALSE; | 280 | d->can_GETOSPACE = FALSE; |
347 | fcntl( d->handle, F_SETFL, O_NONBLOCK ); | 281 | fcntl( d->handle, F_SETFL, O_NONBLOCK ); |
348 | } | 282 | } |
349 | if ( d->can_GETOSPACE ) { | 283 | if ( d->can_GETOSPACE ) { |
@@ -362,28 +296,18 @@ unsigned int AudioDevice::canWrite() const | |||
362 | } | 296 | } |
363 | if ( d->unwritten ) | 297 | if ( d->unwritten ) |
364 | return 0; | 298 | return 0; |
365 | else | 299 | else |
366 | return d->bufferSize; | 300 | return d->bufferSize; |
367 | } | 301 | } |
368 | //#endif | ||
369 | } | 302 | } |
370 | 303 | ||
371 | 304 | ||
372 | int AudioDevice::bytesWritten() { | 305 | int AudioDevice::bytesWritten() { |
373 | // #ifdef Q_OS_WIN32 | ||
374 | // MMTIME pmmt = { TIME_BYTES, 0 }; | ||
375 | // if ( ( waveOutGetPosition( (HWAVEOUT)d->handle, &pmmt, sizeof(MMTIME) ) != MMSYSERR_NOERROR ) || ( pmmt.wType != TIME_BYTES ) ) { | ||
376 | // qDebug( "failed to get audio device position" ); | ||
377 | // return -1; | ||
378 | // } | ||
379 | // return pmmt.u.cb; | ||
380 | // #else | ||
381 | int buffered = 0; | 306 | int buffered = 0; |
382 | if ( ioctl( d->handle, SNDCTL_DSP_GETODELAY, &buffered ) ) { | 307 | if ( ioctl( d->handle, SNDCTL_DSP_GETODELAY, &buffered ) ) { |
383 | qDebug( "failed to get audio device position" ); | 308 | qDebug( "failed to get audio device position" ); |
384 | return -1; | 309 | return -1; |
385 | } | 310 | } |
386 | return buffered; | 311 | return buffered; |
387 | //#endif | ||
388 | } | 312 | } |
389 | 313 | ||