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 @@ | |||
26 | #include <qpe/config.h> | 26 | #include <qpe/config.h> |
27 | #include <qmessagebox.h> | 27 | #include <qmessagebox.h> |
28 | 28 | ||
29 | #include "audiodevice.h" | 29 | #include "audiodevice.h" |
30 | 30 | ||
31 | 31 | ||
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); |
64 | //#endif | 54 | //#endif |
65 | 55 | ||
66 | 56 | ||
67 | class AudioDevicePrivate { | 57 | class AudioDevicePrivate { |
68 | public: | 58 | public: |
69 | int handle; | 59 | int handle; |
@@ -92,81 +82,47 @@ public: | |||
92 | #endif | 82 | #endif |
93 | 83 | ||
94 | 84 | ||
95 | int AudioDevicePrivate::dspFd = 0; | 85 | int AudioDevicePrivate::dspFd = 0; |
96 | bool AudioDevicePrivate::muted = FALSE; | 86 | bool AudioDevicePrivate::muted = FALSE; |
97 | unsigned int AudioDevicePrivate::leftVolume = 0; | 87 | 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 ) { |
137 | AudioDevicePrivate::leftVolume = leftVolume; | 109 | AudioDevicePrivate::leftVolume = leftVolume; |
138 | AudioDevicePrivate::rightVolume = rightVolume; | 110 | AudioDevicePrivate::rightVolume = 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); |
167 | int mixerHandle = 0; | 123 | int mixerHandle = 0; |
168 | if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { | 124 | if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { |
169 | if(ioctl( mixerHandle, MIXER_WRITE(0), &volume ) ==-1) | 125 | if(ioctl( mixerHandle, MIXER_WRITE(0), &volume ) ==-1) |
170 | perror("ioctl(\"MIXER_WRITE\")"); | 126 | perror("ioctl(\"MIXER_WRITE\")"); |
171 | close( mixerHandle ); | 127 | close( mixerHandle ); |
172 | } else | 128 | } else |
@@ -181,25 +137,24 @@ void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, | |||
181 | # endif | 137 | # endif |
182 | 138 | ||
183 | //#endif | 139 | //#endif |
184 | // qDebug( "setting volume to: 0x%x", volume ); | 140 | // qDebug( "setting volume to: 0x%x", volume ); |
185 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) | 141 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) |
186 | // Send notification that the volume has changed | 142 | // Send notification that the volume has changed |
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; |
200 | d->bytesPerSample = bps; | 155 | d->bytesPerSample = bps; |
201 | qDebug("%d",bps); | 156 | qDebug("%d",bps); |
202 | int format=0; | 157 | int format=0; |
203 | if( bps == 8) format = AFMT_U8; | 158 | if( bps == 8) format = AFMT_U8; |
204 | else if( bps <= 0) format = AFMT_S16_LE; | 159 | else if( bps <= 0) format = AFMT_S16_LE; |
205 | else format = AFMT_S16_LE; | 160 | else format = AFMT_S16_LE; |
@@ -257,60 +212,42 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { | |||
257 | //if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" ); | 212 | //if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" ); |
258 | //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" ); | 213 | //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" ); |
259 | //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" ); | 214 | //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" ); |
260 | //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" ); | 215 | //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" ); |
261 | 216 | ||
262 | } | 217 | } |
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 ) |
284 | { | 235 | { |
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; |
311 | } | 248 | } |
312 | //#endif | 249 | //#endif |
313 | } | 250 | } |
314 | 251 | ||
315 | 252 | ||
316 | unsigned int AudioDevice::channels() const | 253 | unsigned int AudioDevice::channels() const |
@@ -329,61 +266,48 @@ unsigned int AudioDevice::bytesPerSample() const | |||
329 | { | 266 | { |
330 | return d->bytesPerSample; | 267 | return d->bytesPerSample; |
331 | } | 268 | } |
332 | 269 | ||
333 | 270 | ||
334 | unsigned int AudioDevice::bufferSize() const | 271 | 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 ) { |
350 | int t = info.fragments * sound_fragment_bytes; | 284 | int t = info.fragments * sound_fragment_bytes; |
351 | return QMIN(t,(int)bufferSize()); | 285 | return QMIN(t,(int)bufferSize()); |
352 | } else { | 286 | } else { |
353 | if ( d->unwritten ) { | 287 | if ( d->unwritten ) { |
354 | int t = ::write( d->handle, d->unwrittenBuffer, d->unwritten ); | 288 | int t = ::write( d->handle, d->unwrittenBuffer, d->unwritten ); |
355 | if ( t<0 ) t = 0; | 289 | if ( t<0 ) t = 0; |
356 | if ( (unsigned)t!=d->unwritten ) { | 290 | if ( (unsigned)t!=d->unwritten ) { |
357 | memcpy(d->unwrittenBuffer,d->unwrittenBuffer+t,d->unwritten-t); | 291 | memcpy(d->unwrittenBuffer,d->unwrittenBuffer+t,d->unwritten-t); |
358 | d->unwritten -= t; | 292 | d->unwritten -= t; |
359 | } else { | 293 | } else { |
360 | d->unwritten = 0; | 294 | d->unwritten = 0; |
361 | } | 295 | } |
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 | ||