summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/audiodevice.cpp
Unidiff
Diffstat (limited to 'core/multimedia/opieplayer/audiodevice.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/audiodevice.cpp50
1 files changed, 27 insertions, 23 deletions
diff --git a/core/multimedia/opieplayer/audiodevice.cpp b/core/multimedia/opieplayer/audiodevice.cpp
index 355062b..9b64e07 100644
--- a/core/multimedia/opieplayer/audiodevice.cpp
+++ b/core/multimedia/opieplayer/audiodevice.cpp
@@ -11,39 +11,43 @@
11 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13 ** 13 **
14 ** See http://www.trolltech.com/gpl/ for GPL licensing information. 14 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
15 ** 15 **
16 ** Contact info@trolltech.com if any conditions of this licensing are 16 ** Contact info@trolltech.com if any conditions of this licensing are
17 ** not clear to you. 17 ** not clear to you.
18 ** 18 **
19 **********************************************************************/ 19 **********************************************************************/
20// L.J.Potter added better error code Fri 02-15-2002 14:37:47 20// L.J.Potter added better error code Fri 02-15-2002 14:37:47
21 21
22 22
23#include <stdlib.h>
24#include <stdio.h>
25#include <qpe/qpeapplication.h>
26#include <qpe/config.h>
27#include <qmessagebox.h>
28
29#include "audiodevice.h" 23#include "audiodevice.h"
30 24
31 25/* OPIE */
32#include <errno.h> 26#include <qpe/qpeapplication.h>
27#include <qpe/config.h>
28#include <opie2/odebug.h>
33 29
34#if !defined(QT_NO_COP) 30#if !defined(QT_NO_COP)
35#include <qpe/qcopenvelope_qws.h> 31#include <qpe/qcopenvelope_qws.h>
36#endif 32#endif
37 33
34/* QT */
35#include <qmessagebox.h>
36
37/* STD */
38#include <stdlib.h>
39#include <stdio.h>
40#include <errno.h>
41
38#if defined(Q_WS_X11) || defined(Q_WS_QWS) 42#if defined(Q_WS_X11) || defined(Q_WS_QWS)
39#include <fcntl.h> 43#include <fcntl.h>
40#include <sys/ioctl.h> 44#include <sys/ioctl.h>
41#include <sys/soundcard.h> 45#include <sys/soundcard.h>
42#include <sys/stat.h> 46#include <sys/stat.h>
43#include <sys/time.h> 47#include <sys/time.h>
44#include <sys/types.h> 48#include <sys/types.h>
45#include <unistd.h> 49#include <unistd.h>
46#endif 50#endif
47 51
48#ifdef OPIE_SOUND_FRAGMENT_SHIFT 52#ifdef OPIE_SOUND_FRAGMENT_SHIFT
49static const int sound_fragment_shift = OPIE_SOUND_FRAGMENT_SHIFT; 53static const int sound_fragment_shift = OPIE_SOUND_FRAGMENT_SHIFT;
@@ -136,46 +140,46 @@ void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume,
136 } else 140 } else
137 perror("open(\"/dev/mixer\")"); 141 perror("open(\"/dev/mixer\")");
138 142
139# else 143# else
140 // This is the way this has to be done now I guess, doesn't allow for 144 // This is the way this has to be done now I guess, doesn't allow for
141 // independant right and left channel setting, or setting for different outputs 145 // independant right and left channel setting, or setting for different outputs
142 Config cfg("qpe"); // qtopia is "Sound" 146 Config cfg("qpe"); // qtopia is "Sound"
143 cfg.setGroup("Volume"); // qtopia is "Settings" 147 cfg.setGroup("Volume"); // qtopia is "Settings"
144 cfg.writeEntry("VolumePercent",(int)rV); //qtopia is Volume 148 cfg.writeEntry("VolumePercent",(int)rV); //qtopia is Volume
145# endif 149# endif
146 150
147//#endif 151//#endif
148// qDebug( "setting volume to: 0x%x", volume ); 152// odebug << "setting volume to: 0x" << volume << "" << oendl;
149#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) 153#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
150 // Send notification that the volume has changed 154 // Send notification that the volume has changed
151 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted; 155 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted;
152#endif 156#endif
153} 157}
154 158
155 159
156 160
157AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { 161AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) {
158 // qDebug("creating new audio device"); 162 // odebug << "creating new audio device" << oendl;
159// QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; 163// QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE;
160 d = new AudioDevicePrivate; 164 d = new AudioDevicePrivate;
161 d->frequency = f; 165 d->frequency = f;
162 d->channels = chs; 166 d->channels = chs;
163 d->bytesPerSample = bps; 167 d->bytesPerSample = bps;
164 // qDebug("%d",bps); 168 // odebug << "" << bps << "" << oendl;
165 int format=0; 169 int format=0;
166 if( bps == 8) format = AFMT_U8; 170 if( bps == 8) format = AFMT_U8;
167 else if( bps <= 0) format = AFMT_S16_LE; 171 else if( bps <= 0) format = AFMT_S16_LE;
168 else format = AFMT_S16_LE; 172 else format = AFMT_S16_LE;
169 // qDebug("AD- freq %d, channels %d, b/sample %d, bitrate %d",f,chs,bps,format); 173 // odebug << "AD- freq " << f << ", channels " << chs << ", b/sample " << bps << ", bitrate " << format << "" << oendl;
170 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); 174 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) );
171 175
172 int fragments = 0x10000 * 8 + sound_fragment_shift; 176 int fragments = 0x10000 * 8 + sound_fragment_shift;
173 int capabilities = 0; 177 int capabilities = 0;
174 178
175 179
176#ifdef KEEP_DEVICE_OPEN 180#ifdef KEEP_DEVICE_OPEN
177 if ( AudioDevicePrivate::dspFd == 0 ) { 181 if ( AudioDevicePrivate::dspFd == 0 ) {
178#endif 182#endif
179#ifdef QT_QWS_DEVFS 183#ifdef QT_QWS_DEVFS
180 if ( ( d->handle = ::open( "/dev/sound/dsp", O_WRONLY ) ) < 0 ) { 184 if ( ( d->handle = ::open( "/dev/sound/dsp", O_WRONLY ) ) < 0 ) {
181#else 185#else
@@ -191,76 +195,76 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) {
191 AudioDevicePrivate::dspFd = d->handle; 195 AudioDevicePrivate::dspFd = d->handle;
192 } else { 196 } else {
193 d->handle = AudioDevicePrivate::dspFd; 197 d->handle = AudioDevicePrivate::dspFd;
194 } 198 }
195#endif 199#endif
196 200
197 if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1) 201 if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1)
198 perror("ioctl(\"SNDCTL_DSP_GETCAPS\")"); 202 perror("ioctl(\"SNDCTL_DSP_GETCAPS\")");
199 if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1) 203 if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1)
200 perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); 204 perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")");
201 if(ioctl( d->handle, SNDCTL_DSP_SETFMT, & format )==-1) 205 if(ioctl( d->handle, SNDCTL_DSP_SETFMT, & format )==-1)
202 perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); 206 perror("ioctl(\"SNDCTL_DSP_SETFMT\")");
203 // qDebug("freq %d", d->frequency); 207 // odebug << "freq " << d->frequency << "" << oendl;
204 if(ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency )==-1) 208 if(ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency )==-1)
205 perror("ioctl(\"SNDCTL_DSP_SPEED\")"); 209 perror("ioctl(\"SNDCTL_DSP_SPEED\")");
206 // qDebug("channels %d",d->channels); 210 // odebug << "channels " << d->channels << "" << oendl;
207 if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) { 211 if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) {
208 d->channels = ( d->channels == 1 ) ? 2 : d->channels; 212 d->channels = ( d->channels == 1 ) ? 2 : d->channels;
209 if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1) 213 if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1)
210 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); 214 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")");
211 } 215 }
212// QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; 216// QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE;
213 217
214 d->bufferSize = sound_fragment_bytes; 218 d->bufferSize = sound_fragment_bytes;
215 d->unwrittenBuffer = new char[d->bufferSize]; 219 d->unwrittenBuffer = new char[d->bufferSize];
216 d->unwritten = 0; 220 d->unwritten = 0;
217 d->can_GETOSPACE = TRUE; // until we find otherwise 221 d->can_GETOSPACE = TRUE; // until we find otherwise
218 222
219 //if ( chs != d->channels ) qDebug( "Wanted %d, got %d channels", chs, d->channels ); 223 //if ( chs != d->channels ) odebug << "Wanted " << chs << ", got " << d->channels << " channels" << oendl;
220 //if ( f != d->frequency ) qDebug( "wanted %dHz, got %dHz", f, d->frequency ); 224 //if ( f != d->frequency ) odebug << "wanted " << f << "Hz, got " << d->frequency << "Hz" << oendl;
221 //if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" ); 225 //if ( capabilities & DSP_CAP_BATCH ) odebug << "Sound card has local buffer" << oendl;
222 //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" ); 226 //if ( capabilities & DSP_CAP_REALTIME )odebug << "Sound card has realtime sync" << oendl;
223 //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" ); 227 //if ( capabilities & DSP_CAP_TRIGGER ) odebug << "Sound card has precise trigger" << oendl;
224 //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" ); 228 //if ( capabilities & DSP_CAP_MMAP ) odebug << "Sound card can mmap" << oendl;
225 229
226} 230}
227 231
228 232
229AudioDevice::~AudioDevice() { 233AudioDevice::~AudioDevice() {
230 // qDebug("destryo audiodevice"); 234 // odebug << "destryo audiodevice" << oendl;
231// QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; 235// QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE;
232 236
233# ifndef KEEP_DEVICE_OPEN 237# ifndef KEEP_DEVICE_OPEN
234 close( d->handle ); // Now it should be safe to shut the handle 238 close( d->handle ); // Now it should be safe to shut the handle
235# endif 239# endif
236 delete d->unwrittenBuffer; 240 delete d->unwrittenBuffer;
237 delete d; 241 delete d;
238// QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; 242// QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE;
239 243
240} 244}
241 245
242 246
243void AudioDevice::volumeChanged( bool muted ) 247void AudioDevice::volumeChanged( bool muted )
244{ 248{
245 AudioDevicePrivate::muted = muted; 249 AudioDevicePrivate::muted = muted;
246} 250}
247 251
248 252
249void AudioDevice::write( char *buffer, unsigned int length ) 253void AudioDevice::write( char *buffer, unsigned int length )
250{ 254{
251 int t = ::write( d->handle, buffer, length ); 255 int t = ::write( d->handle, buffer, length );
252 if ( t<0 ) t = 0; 256 if ( t<0 ) t = 0;
253 if ( t != (int)length) { 257 if ( t != (int)length) {
254 // qDebug("Ahhh!! memcpys 1"); 258 // odebug << "Ahhh!! memcpys 1" << oendl;
255 memcpy(d->unwrittenBuffer,buffer+t,length-t); 259 memcpy(d->unwrittenBuffer,buffer+t,length-t);
256 d->unwritten = length-t; 260 d->unwritten = length-t;
257 } 261 }
258//#endif 262//#endif
259} 263}
260 264
261 265
262unsigned int AudioDevice::channels() const 266unsigned int AudioDevice::channels() const
263{ 267{
264 return d->channels; 268 return d->channels;
265} 269}
266 270
@@ -305,18 +309,18 @@ unsigned int AudioDevice::canWrite() const
305 } 309 }
306 if ( d->unwritten ) 310 if ( d->unwritten )
307 return 0; 311 return 0;
308 else 312 else
309 return d->bufferSize; 313 return d->bufferSize;
310 } 314 }
311} 315}
312 316
313 317
314int AudioDevice::bytesWritten() { 318int AudioDevice::bytesWritten() {
315 int buffered = 0; 319 int buffered = 0;
316 if ( ioctl( d->handle, SNDCTL_DSP_GETODELAY, &buffered ) ) { 320 if ( ioctl( d->handle, SNDCTL_DSP_GETODELAY, &buffered ) ) {
317 // qDebug( "failed to get audio device position" ); 321 // odebug << "failed to get audio device position" << oendl;
318 return -1; 322 return -1;
319 } 323 }
320 return buffered; 324 return buffered;
321} 325}
322 326