Diffstat (limited to 'core/multimedia/opieplayer/audiodevice.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/audiodevice.cpp | 50 |
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 | |||
@@ -1,85 +1,89 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
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 |
49 | static const int sound_fragment_shift = OPIE_SOUND_FRAGMENT_SHIFT; | 53 | static const int sound_fragment_shift = OPIE_SOUND_FRAGMENT_SHIFT; |
50 | #else | 54 | #else |
51 | static const int sound_fragment_shift = 16; | 55 | static const int sound_fragment_shift = 16; |
52 | #endif | 56 | #endif |
53 | static const int sound_fragment_bytes = (1<<sound_fragment_shift); | 57 | static const int sound_fragment_bytes = (1<<sound_fragment_shift); |
54 | //#endif | 58 | //#endif |
55 | 59 | ||
56 | 60 | ||
57 | class AudioDevicePrivate { | 61 | class AudioDevicePrivate { |
58 | public: | 62 | public: |
59 | int handle; | 63 | int handle; |
60 | unsigned int frequency; | 64 | unsigned int frequency; |
61 | unsigned int channels; | 65 | unsigned int channels; |
62 | unsigned int bytesPerSample; | 66 | unsigned int bytesPerSample; |
63 | unsigned int bufferSize; | 67 | unsigned int bufferSize; |
64 | //#ifndef Q_OS_WIN32 | 68 | //#ifndef Q_OS_WIN32 |
65 | bool can_GETOSPACE; | 69 | bool can_GETOSPACE; |
66 | char* unwrittenBuffer; | 70 | char* unwrittenBuffer; |
67 | unsigned int unwritten; | 71 | unsigned int unwritten; |
68 | //#endif | 72 | //#endif |
69 | 73 | ||
70 | static int dspFd; | 74 | static int dspFd; |
71 | static bool muted; | 75 | static bool muted; |
72 | static unsigned int leftVolume; | 76 | static unsigned int leftVolume; |
73 | static unsigned int rightVolume; | 77 | static unsigned int rightVolume; |
74 | }; | 78 | }; |
75 | 79 | ||
76 | 80 | ||
77 | #ifdef Q_WS_QWS | 81 | #ifdef Q_WS_QWS |
78 | // This is for keeping the device open in-between playing files when | 82 | // This is for keeping the device open in-between playing files when |
79 | // the device makes clicks and it starts to drive you insane! :) | 83 | // the device makes clicks and it starts to drive you insane! :) |
80 | // Best to have the device not open when not using it though | 84 | // Best to have the device not open when not using it though |
81 | //#define KEEP_DEVICE_OPEN | 85 | //#define KEEP_DEVICE_OPEN |
82 | #endif | 86 | #endif |
83 | 87 | ||
84 | 88 | ||
85 | int AudioDevicePrivate::dspFd = 0; | 89 | int AudioDevicePrivate::dspFd = 0; |
@@ -100,223 +104,223 @@ void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume | |||
100 | if(ioctl( mixerHandle, MIXER_READ(0), &volume )==-1) | 104 | if(ioctl( mixerHandle, MIXER_READ(0), &volume )==-1) |
101 | perror("ioctl(\"MIXER_READ\")"); | 105 | perror("ioctl(\"MIXER_READ\")"); |
102 | close( mixerHandle ); | 106 | close( mixerHandle ); |
103 | } else | 107 | } else |
104 | perror("open(\"/dev/mixer\")"); | 108 | perror("open(\"/dev/mixer\")"); |
105 | leftVolume = ((volume & 0x00FF) << 16) / 101; | 109 | leftVolume = ((volume & 0x00FF) << 16) / 101; |
106 | rightVolume = ((volume & 0xFF00) << 8) / 101; | 110 | rightVolume = ((volume & 0xFF00) << 8) / 101; |
107 | } | 111 | } |
108 | 112 | ||
109 | 113 | ||
110 | void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, bool muted ) { | 114 | void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, bool muted ) { |
111 | AudioDevicePrivate::muted = muted; | 115 | AudioDevicePrivate::muted = muted; |
112 | if ( muted ) { | 116 | if ( muted ) { |
113 | AudioDevicePrivate::leftVolume = leftVolume; | 117 | AudioDevicePrivate::leftVolume = leftVolume; |
114 | AudioDevicePrivate::rightVolume = rightVolume; | 118 | AudioDevicePrivate::rightVolume = rightVolume; |
115 | leftVolume = 0; | 119 | leftVolume = 0; |
116 | rightVolume = 0; | 120 | rightVolume = 0; |
117 | } else { | 121 | } else { |
118 | leftVolume = ( (int) leftVolume < 0 ) ? 0 : (( leftVolume > 0xFFFF ) ? 0xFFFF : leftVolume ); | 122 | leftVolume = ( (int) leftVolume < 0 ) ? 0 : (( leftVolume > 0xFFFF ) ? 0xFFFF : leftVolume ); |
119 | rightVolume = ( (int)rightVolume < 0 ) ? 0 : (( rightVolume > 0xFFFF ) ? 0xFFFF : rightVolume ); | 123 | rightVolume = ( (int)rightVolume < 0 ) ? 0 : (( rightVolume > 0xFFFF ) ? 0xFFFF : rightVolume ); |
120 | } | 124 | } |
121 | // Volume can be from 0 to 100 which is 101 distinct values | 125 | // Volume can be from 0 to 100 which is 101 distinct values |
122 | unsigned int rV = (rightVolume * 101) >> 16; | 126 | unsigned int rV = (rightVolume * 101) >> 16; |
123 | 127 | ||
124 | # if 0 | 128 | # if 0 |
125 | unsigned int lV = (leftVolume * 101) >> 16; | 129 | unsigned int lV = (leftVolume * 101) >> 16; |
126 | unsigned int volume = ((rV << 8) & 0xFF00) | (lV & 0x00FF); | 130 | unsigned int volume = ((rV << 8) & 0xFF00) | (lV & 0x00FF); |
127 | int mixerHandle = 0; | 131 | int mixerHandle = 0; |
128 | #ifdef QT_QWS_DEVFS | 132 | #ifdef QT_QWS_DEVFS |
129 | if ( ( mixerHandle = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { | 133 | if ( ( mixerHandle = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { |
130 | #else | 134 | #else |
131 | if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { | 135 | if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { |
132 | #endif | 136 | #endif |
133 | if(ioctl( mixerHandle, MIXER_WRITE(0), &volume ) ==-1) | 137 | if(ioctl( mixerHandle, MIXER_WRITE(0), &volume ) ==-1) |
134 | perror("ioctl(\"MIXER_WRITE\")"); | 138 | perror("ioctl(\"MIXER_WRITE\")"); |
135 | close( mixerHandle ); | 139 | close( mixerHandle ); |
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 | ||
157 | AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { | 161 | AudioDevice::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 |
182 | if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) { | 186 | if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) { |
183 | #endif | 187 | #endif |
184 | 188 | ||
185 | perror("open(\"/dev/dsp\")"); | 189 | perror("open(\"/dev/dsp\")"); |
186 | QString errorMsg=tr("Somethin's wrong with\nyour sound device.\nopen(\"/dev/dsp\")\n")+(QString)strerror(errno)+tr("\n\nClosing player now."); | 190 | QString errorMsg=tr("Somethin's wrong with\nyour sound device.\nopen(\"/dev/dsp\")\n")+(QString)strerror(errno)+tr("\n\nClosing player now."); |
187 | QMessageBox::critical(0, "Vmemo", errorMsg, tr("Abort")); | 191 | QMessageBox::critical(0, "Vmemo", errorMsg, tr("Abort")); |
188 | exit(-1); //harsh? | 192 | exit(-1); //harsh? |
189 | } | 193 | } |
190 | #ifdef KEEP_DEVICE_OPEN | 194 | #ifdef KEEP_DEVICE_OPEN |
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 | ||
229 | AudioDevice::~AudioDevice() { | 233 | AudioDevice::~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 | ||
243 | void AudioDevice::volumeChanged( bool muted ) | 247 | void AudioDevice::volumeChanged( bool muted ) |
244 | { | 248 | { |
245 | AudioDevicePrivate::muted = muted; | 249 | AudioDevicePrivate::muted = muted; |
246 | } | 250 | } |
247 | 251 | ||
248 | 252 | ||
249 | void AudioDevice::write( char *buffer, unsigned int length ) | 253 | void 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 | ||
262 | unsigned int AudioDevice::channels() const | 266 | unsigned int AudioDevice::channels() const |
263 | { | 267 | { |
264 | return d->channels; | 268 | return d->channels; |
265 | } | 269 | } |
266 | 270 | ||
267 | 271 | ||
268 | unsigned int AudioDevice::frequency() const | 272 | unsigned int AudioDevice::frequency() const |
269 | { | 273 | { |
270 | return d->frequency; | 274 | return d->frequency; |
271 | } | 275 | } |
272 | 276 | ||
273 | 277 | ||
274 | unsigned int AudioDevice::bytesPerSample() const | 278 | unsigned int AudioDevice::bytesPerSample() const |
275 | { | 279 | { |
276 | return d->bytesPerSample; | 280 | return d->bytesPerSample; |
277 | } | 281 | } |
278 | 282 | ||
279 | 283 | ||
280 | unsigned int AudioDevice::bufferSize() const | 284 | unsigned int AudioDevice::bufferSize() const |
281 | { | 285 | { |
282 | return d->bufferSize; | 286 | return d->bufferSize; |
283 | } | 287 | } |
284 | 288 | ||
285 | unsigned int AudioDevice::canWrite() const | 289 | unsigned int AudioDevice::canWrite() const |
286 | { | 290 | { |
287 | audio_buf_info info; | 291 | audio_buf_info info; |
288 | if ( d->can_GETOSPACE && ioctl(d->handle,SNDCTL_DSP_GETOSPACE,&info) ) { | 292 | if ( d->can_GETOSPACE && ioctl(d->handle,SNDCTL_DSP_GETOSPACE,&info) ) { |
289 | d->can_GETOSPACE = FALSE; | 293 | d->can_GETOSPACE = FALSE; |
290 | fcntl( d->handle, F_SETFL, O_NONBLOCK ); | 294 | fcntl( d->handle, F_SETFL, O_NONBLOCK ); |
291 | } | 295 | } |
292 | if ( d->can_GETOSPACE ) { | 296 | if ( d->can_GETOSPACE ) { |
293 | int t = info.fragments * sound_fragment_bytes; | 297 | int t = info.fragments * sound_fragment_bytes; |
294 | return QMIN(t,(int)bufferSize()); | 298 | return QMIN(t,(int)bufferSize()); |
295 | } else { | 299 | } else { |
296 | if ( d->unwritten ) { | 300 | if ( d->unwritten ) { |
297 | int t = ::write( d->handle, d->unwrittenBuffer, d->unwritten ); | 301 | int t = ::write( d->handle, d->unwrittenBuffer, d->unwritten ); |
298 | if ( t<0 ) t = 0; | 302 | if ( t<0 ) t = 0; |
299 | if ( (unsigned)t!=d->unwritten ) { | 303 | if ( (unsigned)t!=d->unwritten ) { |
300 | memcpy(d->unwrittenBuffer,d->unwrittenBuffer+t,d->unwritten-t); | 304 | memcpy(d->unwrittenBuffer,d->unwrittenBuffer+t,d->unwritten-t); |
301 | d->unwritten -= t; | 305 | d->unwritten -= t; |
302 | } else { | 306 | } else { |
303 | d->unwritten = 0; | 307 | d->unwritten = 0; |
304 | } | 308 | } |
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 | ||
314 | int AudioDevice::bytesWritten() { | 318 | int 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 | ||