Diffstat (limited to 'core/multimedia/opieplayer/audiodevice.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/audiodevice.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/core/multimedia/opieplayer/audiodevice.cpp b/core/multimedia/opieplayer/audiodevice.cpp index 73e41dc..d01d2ba 100644 --- a/core/multimedia/opieplayer/audiodevice.cpp +++ b/core/multimedia/opieplayer/audiodevice.cpp | |||
@@ -126,144 +126,144 @@ void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, | |||
126 | perror("ioctl(\"MIXER_WRITE\")"); | 126 | perror("ioctl(\"MIXER_WRITE\")"); |
127 | close( mixerHandle ); | 127 | close( mixerHandle ); |
128 | } else | 128 | } else |
129 | perror("open(\"/dev/mixer\")"); | 129 | perror("open(\"/dev/mixer\")"); |
130 | 130 | ||
131 | # else | 131 | # else |
132 | // This is the way this has to be done now I guess, doesn't allow for | 132 | // This is the way this has to be done now I guess, doesn't allow for |
133 | // independant right and left channel setting, or setting for different outputs | 133 | // independant right and left channel setting, or setting for different outputs |
134 | Config cfg("qpe"); // qtopia is "Sound" | 134 | Config cfg("qpe"); // qtopia is "Sound" |
135 | cfg.setGroup("Volume"); // qtopia is "Settings" | 135 | cfg.setGroup("Volume"); // qtopia is "Settings" |
136 | cfg.writeEntry("VolumePercent",(int)rV); //qtopia is Volume | 136 | cfg.writeEntry("VolumePercent",(int)rV); //qtopia is Volume |
137 | # endif | 137 | # endif |
138 | 138 | ||
139 | //#endif | 139 | //#endif |
140 | // qDebug( "setting volume to: 0x%x", volume ); | 140 | // qDebug( "setting volume to: 0x%x", volume ); |
141 | #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) |
142 | // Send notification that the volume has changed | 142 | // Send notification that the volume has changed |
143 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted; | 143 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted; |
144 | #endif | 144 | #endif |
145 | } | 145 | } |
146 | 146 | ||
147 | 147 | ||
148 | 148 | ||
149 | AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { | 149 | AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { |
150 | qDebug("creating new audio device"); | 150 | // qDebug("creating new audio device"); |
151 | // QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; | 151 | // QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; |
152 | d = new AudioDevicePrivate; | 152 | d = new AudioDevicePrivate; |
153 | d->frequency = f; | 153 | d->frequency = f; |
154 | d->channels = chs; | 154 | d->channels = chs; |
155 | d->bytesPerSample = bps; | 155 | d->bytesPerSample = bps; |
156 | qDebug("%d",bps); | 156 | // qDebug("%d",bps); |
157 | int format=0; | 157 | int format=0; |
158 | if( bps == 8) format = AFMT_U8; | 158 | if( bps == 8) format = AFMT_U8; |
159 | else if( bps <= 0) format = AFMT_S16_LE; | 159 | else if( bps <= 0) format = AFMT_S16_LE; |
160 | else format = AFMT_S16_LE; | 160 | else format = AFMT_S16_LE; |
161 | qDebug("AD- freq %d, channels %d, b/sample %d, bitrate %d",f,chs,bps,format); | 161 | // qDebug("AD- freq %d, channels %d, b/sample %d, bitrate %d",f,chs,bps,format); |
162 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); | 162 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); |
163 | 163 | ||
164 | int fragments = 0x10000 * 8 + sound_fragment_shift; | 164 | int fragments = 0x10000 * 8 + sound_fragment_shift; |
165 | int capabilities = 0; | 165 | int capabilities = 0; |
166 | 166 | ||
167 | 167 | ||
168 | #ifdef KEEP_DEVICE_OPEN | 168 | #ifdef KEEP_DEVICE_OPEN |
169 | if ( AudioDevicePrivate::dspFd == 0 ) { | 169 | if ( AudioDevicePrivate::dspFd == 0 ) { |
170 | #endif | 170 | #endif |
171 | if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) { | 171 | if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) { |
172 | 172 | ||
173 | // perror("open(\"/dev/dsp\") sending to /dev/null instead"); | 173 | // perror("open(\"/dev/dsp\") sending to /dev/null instead"); |
174 | perror("open(\"/dev/dsp\")"); | 174 | perror("open(\"/dev/dsp\")"); |
175 | QString errorMsg=tr("Somethin's wrong with\nyour sound device.\nopen(\"/dev/dsp\")\n")+(QString)strerror(errno)+tr("\n\nClosing player now."); | 175 | QString errorMsg=tr("Somethin's wrong with\nyour sound device.\nopen(\"/dev/dsp\")\n")+(QString)strerror(errno)+tr("\n\nClosing player now."); |
176 | QMessageBox::critical(0, "Vmemo", errorMsg, tr("Abort")); | 176 | QMessageBox::critical(0, "Vmemo", errorMsg, tr("Abort")); |
177 | exit(-1); //harsh? | 177 | exit(-1); //harsh? |
178 | // d->handle = ::open( "/dev/null", O_WRONLY ); | 178 | // d->handle = ::open( "/dev/null", O_WRONLY ); |
179 | // WTF?!?! | 179 | // WTF?!?! |
180 | } | 180 | } |
181 | #ifdef KEEP_DEVICE_OPEN | 181 | #ifdef KEEP_DEVICE_OPEN |
182 | AudioDevicePrivate::dspFd = d->handle; | 182 | AudioDevicePrivate::dspFd = d->handle; |
183 | } else { | 183 | } else { |
184 | d->handle = AudioDevicePrivate::dspFd; | 184 | d->handle = AudioDevicePrivate::dspFd; |
185 | } | 185 | } |
186 | #endif | 186 | #endif |
187 | 187 | ||
188 | if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1) | 188 | if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1) |
189 | perror("ioctl(\"SNDCTL_DSP_GETCAPS\")"); | 189 | perror("ioctl(\"SNDCTL_DSP_GETCAPS\")"); |
190 | if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1) | 190 | if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1) |
191 | perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); | 191 | perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); |
192 | if(ioctl( d->handle, SNDCTL_DSP_SETFMT, & format )==-1) | 192 | if(ioctl( d->handle, SNDCTL_DSP_SETFMT, & format )==-1) |
193 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | 193 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); |
194 | qDebug("freq %d", d->frequency); | 194 | // qDebug("freq %d", d->frequency); |
195 | if(ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency )==-1) | 195 | if(ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency )==-1) |
196 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); | 196 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); |
197 | qDebug("channels %d",d->channels); | 197 | // qDebug("channels %d",d->channels); |
198 | if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) { | 198 | if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) { |
199 | d->channels = ( d->channels == 1 ) ? 2 : d->channels; | 199 | d->channels = ( d->channels == 1 ) ? 2 : d->channels; |
200 | if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1) | 200 | if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1) |
201 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); | 201 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); |
202 | } | 202 | } |
203 | // QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; | 203 | // QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; |
204 | 204 | ||
205 | d->bufferSize = sound_fragment_bytes; | 205 | d->bufferSize = sound_fragment_bytes; |
206 | d->unwrittenBuffer = new char[d->bufferSize]; | 206 | d->unwrittenBuffer = new char[d->bufferSize]; |
207 | d->unwritten = 0; | 207 | d->unwritten = 0; |
208 | d->can_GETOSPACE = TRUE; // until we find otherwise | 208 | d->can_GETOSPACE = TRUE; // until we find otherwise |
209 | 209 | ||
210 | //if ( chs != d->channels ) qDebug( "Wanted %d, got %d channels", chs, d->channels ); | 210 | //if ( chs != d->channels ) qDebug( "Wanted %d, got %d channels", chs, d->channels ); |
211 | //if ( f != d->frequency ) qDebug( "wanted %dHz, got %dHz", f, d->frequency ); | 211 | //if ( f != d->frequency ) qDebug( "wanted %dHz, got %dHz", f, d->frequency ); |
212 | //if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" ); | 212 | //if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" ); |
213 | //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" ); | 213 | //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" ); |
214 | //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" ); | 214 | //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" ); |
215 | //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" ); | 215 | //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" ); |
216 | 216 | ||
217 | } | 217 | } |
218 | 218 | ||
219 | 219 | ||
220 | AudioDevice::~AudioDevice() { | 220 | AudioDevice::~AudioDevice() { |
221 | qDebug("destryo audiodevice"); | 221 | // qDebug("destryo audiodevice"); |
222 | // QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; | 222 | // QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; |
223 | 223 | ||
224 | # ifndef KEEP_DEVICE_OPEN | 224 | # ifndef KEEP_DEVICE_OPEN |
225 | 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 |
226 | # endif | 226 | # endif |
227 | delete d->unwrittenBuffer; | 227 | delete d->unwrittenBuffer; |
228 | delete d; | 228 | delete d; |
229 | // QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; | 229 | // QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; |
230 | 230 | ||
231 | } | 231 | } |
232 | 232 | ||
233 | 233 | ||
234 | void AudioDevice::volumeChanged( bool muted ) | 234 | void AudioDevice::volumeChanged( bool muted ) |
235 | { | 235 | { |
236 | AudioDevicePrivate::muted = muted; | 236 | AudioDevicePrivate::muted = muted; |
237 | } | 237 | } |
238 | 238 | ||
239 | 239 | ||
240 | void AudioDevice::write( char *buffer, unsigned int length ) | 240 | void AudioDevice::write( char *buffer, unsigned int length ) |
241 | { | 241 | { |
242 | int t = ::write( d->handle, buffer, length ); | 242 | int t = ::write( d->handle, buffer, length ); |
243 | if ( t<0 ) t = 0; | 243 | if ( t<0 ) t = 0; |
244 | if ( t != (int)length) { | 244 | if ( t != (int)length) { |
245 | qDebug("Ahhh!! memcpys 1"); | 245 | // qDebug("Ahhh!! memcpys 1"); |
246 | memcpy(d->unwrittenBuffer,buffer+t,length-t); | 246 | memcpy(d->unwrittenBuffer,buffer+t,length-t); |
247 | d->unwritten = length-t; | 247 | d->unwritten = length-t; |
248 | } | 248 | } |
249 | //#endif | 249 | //#endif |
250 | } | 250 | } |
251 | 251 | ||
252 | 252 | ||
253 | unsigned int AudioDevice::channels() const | 253 | unsigned int AudioDevice::channels() const |
254 | { | 254 | { |
255 | return d->channels; | 255 | return d->channels; |
256 | } | 256 | } |
257 | 257 | ||
258 | 258 | ||
259 | unsigned int AudioDevice::frequency() const | 259 | unsigned int AudioDevice::frequency() const |
260 | { | 260 | { |
261 | return d->frequency; | 261 | return d->frequency; |
262 | } | 262 | } |
263 | 263 | ||
264 | 264 | ||
265 | unsigned int AudioDevice::bytesPerSample() const | 265 | unsigned int AudioDevice::bytesPerSample() const |
266 | { | 266 | { |
267 | return d->bytesPerSample; | 267 | return d->bytesPerSample; |
268 | } | 268 | } |
269 | 269 | ||
@@ -284,30 +284,30 @@ unsigned int AudioDevice::canWrite() const | |||
284 | int t = info.fragments * sound_fragment_bytes; | 284 | int t = info.fragments * sound_fragment_bytes; |
285 | return QMIN(t,(int)bufferSize()); | 285 | return QMIN(t,(int)bufferSize()); |
286 | } else { | 286 | } else { |
287 | if ( d->unwritten ) { | 287 | if ( d->unwritten ) { |
288 | int t = ::write( d->handle, d->unwrittenBuffer, d->unwritten ); | 288 | int t = ::write( d->handle, d->unwrittenBuffer, d->unwritten ); |
289 | if ( t<0 ) t = 0; | 289 | if ( t<0 ) t = 0; |
290 | if ( (unsigned)t!=d->unwritten ) { | 290 | if ( (unsigned)t!=d->unwritten ) { |
291 | memcpy(d->unwrittenBuffer,d->unwrittenBuffer+t,d->unwritten-t); | 291 | memcpy(d->unwrittenBuffer,d->unwrittenBuffer+t,d->unwritten-t); |
292 | d->unwritten -= t; | 292 | d->unwritten -= t; |
293 | } else { | 293 | } else { |
294 | d->unwritten = 0; | 294 | d->unwritten = 0; |
295 | } | 295 | } |
296 | } | 296 | } |
297 | if ( d->unwritten ) | 297 | if ( d->unwritten ) |
298 | return 0; | 298 | return 0; |
299 | else | 299 | else |
300 | return d->bufferSize; | 300 | return d->bufferSize; |
301 | } | 301 | } |
302 | } | 302 | } |
303 | 303 | ||
304 | 304 | ||
305 | int AudioDevice::bytesWritten() { | 305 | int AudioDevice::bytesWritten() { |
306 | int buffered = 0; | 306 | int buffered = 0; |
307 | if ( ioctl( d->handle, SNDCTL_DSP_GETODELAY, &buffered ) ) { | 307 | if ( ioctl( d->handle, SNDCTL_DSP_GETODELAY, &buffered ) ) { |
308 | qDebug( "failed to get audio device position" ); | 308 | // qDebug( "failed to get audio device position" ); |
309 | return -1; | 309 | return -1; |
310 | } | 310 | } |
311 | return buffered; | 311 | return buffered; |
312 | } | 312 | } |
313 | 313 | ||