equal
deleted
inserted
replaced
69 m_device = device; |
69 m_device = device; |
70 totalTimeValue = 0; |
70 totalTimeValue = 0; |
71 intervalTime = 1000; |
71 intervalTime = 1000; |
72 audioBuffer = 0; |
72 audioBuffer = 0; |
73 errorState = QAudio::NoError; |
73 errorState = QAudio::NoError; |
74 deviceState = QAudio::StopState; |
74 deviceState = QAudio::StoppedState; |
75 audioSource = 0; |
75 audioSource = 0; |
76 pullMode = true; |
76 pullMode = true; |
77 finished = false; |
77 finished = false; |
78 InitializeCriticalSection(&waveOutCriticalSection); |
78 InitializeCriticalSection(&waveOutCriticalSection); |
79 } |
79 } |
145 return blocks; |
145 return blocks; |
146 } |
146 } |
147 |
147 |
148 void QAudioOutputPrivate::freeBlocks(WAVEHDR* blockArray) |
148 void QAudioOutputPrivate::freeBlocks(WAVEHDR* blockArray) |
149 { |
149 { |
|
150 WAVEHDR* blocks = blockArray; |
|
151 |
|
152 int count = buffer_size/period_size; |
|
153 |
|
154 for(int i = 0; i < count; i++) { |
|
155 waveOutUnprepareHeader(hWaveOut,&blocks[i], sizeof(WAVEHDR)); |
|
156 blocks+=sizeof(WAVEHDR); |
|
157 } |
150 HeapFree(GetProcessHeap(), 0, blockArray); |
158 HeapFree(GetProcessHeap(), 0, blockArray); |
151 } |
159 } |
152 |
160 |
153 QAudioFormat QAudioOutputPrivate::format() const |
161 QAudioFormat QAudioOutputPrivate::format() const |
154 { |
162 { |
155 return settings; |
163 return settings; |
156 } |
164 } |
157 |
165 |
158 QIODevice* QAudioOutputPrivate::start(QIODevice* device) |
166 QIODevice* QAudioOutputPrivate::start(QIODevice* device) |
159 { |
167 { |
160 if(deviceState != QAudio::StopState) |
168 if(deviceState != QAudio::StoppedState) |
161 close(); |
169 close(); |
162 |
170 |
163 if(!pullMode && audioSource) { |
171 if(!pullMode && audioSource) { |
164 delete audioSource; |
172 delete audioSource; |
165 } |
173 } |
185 return audioSource; |
193 return audioSource; |
186 } |
194 } |
187 |
195 |
188 void QAudioOutputPrivate::stop() |
196 void QAudioOutputPrivate::stop() |
189 { |
197 { |
190 if(deviceState == QAudio::StopState) |
198 if(deviceState == QAudio::StoppedState) |
191 return; |
199 return; |
192 close(); |
200 close(); |
193 if(!pullMode && audioSource) { |
201 if(!pullMode && audioSource) { |
194 delete audioSource; |
202 delete audioSource; |
195 audioSource = 0; |
203 audioSource = 0; |
253 if(waveOutOpen(&hWaveOut, devId, &wfx, |
261 if(waveOutOpen(&hWaveOut, devId, &wfx, |
254 (DWORD_PTR)&waveOutProc, |
262 (DWORD_PTR)&waveOutProc, |
255 (DWORD_PTR) this, |
263 (DWORD_PTR) this, |
256 CALLBACK_FUNCTION) != MMSYSERR_NOERROR) { |
264 CALLBACK_FUNCTION) != MMSYSERR_NOERROR) { |
257 errorState = QAudio::OpenError; |
265 errorState = QAudio::OpenError; |
258 deviceState = QAudio::StopState; |
266 deviceState = QAudio::StoppedState; |
259 emit stateChanged(deviceState); |
267 emit stateChanged(deviceState); |
260 qWarning("QAudioOutput: open error"); |
268 qWarning("QAudioOutput: open error"); |
261 return false; |
269 return false; |
262 } |
270 } |
263 |
271 |
275 return true; |
283 return true; |
276 } |
284 } |
277 |
285 |
278 void QAudioOutputPrivate::close() |
286 void QAudioOutputPrivate::close() |
279 { |
287 { |
280 if(deviceState == QAudio::StopState) |
288 if(deviceState == QAudio::StoppedState) |
281 return; |
289 return; |
282 |
290 |
283 deviceState = QAudio::StopState; |
291 deviceState = QAudio::StoppedState; |
284 int delay = (buffer_size-bytesFree())*1000/(settings.frequency() |
292 int delay = (buffer_size-bytesFree())*1000/(settings.frequency() |
285 *settings.channels()*(settings.sampleSize()/8)); |
293 *settings.channels()*(settings.sampleSize()/8)); |
286 waveOutReset(hWaveOut); |
294 waveOutReset(hWaveOut); |
287 Sleep(delay+10); |
295 Sleep(delay+10); |
288 |
296 |
306 return period_size; |
314 return period_size; |
307 } |
315 } |
308 |
316 |
309 void QAudioOutputPrivate::setBufferSize(int value) |
317 void QAudioOutputPrivate::setBufferSize(int value) |
310 { |
318 { |
311 if(deviceState == QAudio::StopState) |
319 if(deviceState == QAudio::StoppedState) |
312 buffer_size = value; |
320 buffer_size = value; |
313 } |
321 } |
314 |
322 |
315 int QAudioOutputPrivate::bufferSize() const |
323 int QAudioOutputPrivate::bufferSize() const |
316 { |
324 { |
328 int QAudioOutputPrivate::notifyInterval() const |
336 int QAudioOutputPrivate::notifyInterval() const |
329 { |
337 { |
330 return intervalTime; |
338 return intervalTime; |
331 } |
339 } |
332 |
340 |
333 qint64 QAudioOutputPrivate::totalTime() const |
341 qint64 QAudioOutputPrivate::processedUSecs() const |
334 { |
342 { |
335 return totalTimeValue; |
343 return totalTimeValue; |
336 } |
344 } |
337 |
345 |
338 qint64 QAudioOutputPrivate::write( const char *data, qint64 len ) |
346 qint64 QAudioOutputPrivate::write( const char *data, qint64 len ) |
388 return (len-l); |
396 return (len-l); |
389 } |
397 } |
390 |
398 |
391 void QAudioOutputPrivate::resume() |
399 void QAudioOutputPrivate::resume() |
392 { |
400 { |
393 if(deviceState == QAudio::SuspendState) { |
401 if(deviceState == QAudio::SuspendedState) { |
394 deviceState = QAudio::ActiveState; |
402 deviceState = QAudio::ActiveState; |
395 errorState = QAudio::NoError; |
403 errorState = QAudio::NoError; |
396 waveOutRestart(hWaveOut); |
404 waveOutRestart(hWaveOut); |
397 QTimer::singleShot(10, this, SLOT(feedback())); |
405 QTimer::singleShot(10, this, SLOT(feedback())); |
398 emit stateChanged(deviceState); |
406 emit stateChanged(deviceState); |
401 |
409 |
402 void QAudioOutputPrivate::suspend() |
410 void QAudioOutputPrivate::suspend() |
403 { |
411 { |
404 if(deviceState == QAudio::ActiveState) { |
412 if(deviceState == QAudio::ActiveState) { |
405 waveOutPause(hWaveOut); |
413 waveOutPause(hWaveOut); |
406 deviceState = QAudio::SuspendState; |
414 deviceState = QAudio::SuspendedState; |
407 errorState = QAudio::NoError; |
415 errorState = QAudio::NoError; |
408 emit stateChanged(deviceState); |
416 emit stateChanged(deviceState); |
409 } |
417 } |
410 } |
418 } |
411 |
419 |
415 QTime now(QTime::currentTime()); |
423 QTime now(QTime::currentTime()); |
416 qDebug()<<now.second()<<"s "<<now.msec()<<"ms :feedback()"; |
424 qDebug()<<now.second()<<"s "<<now.msec()<<"ms :feedback()"; |
417 #endif |
425 #endif |
418 bytesAvailable = bytesFree(); |
426 bytesAvailable = bytesFree(); |
419 |
427 |
420 if(!(deviceState==QAudio::StopState||deviceState==QAudio::SuspendState)) { |
428 if(!(deviceState==QAudio::StoppedState||deviceState==QAudio::SuspendedState)) { |
421 if(bytesAvailable >= period_size) |
429 if(bytesAvailable >= period_size) |
422 QMetaObject::invokeMethod(this, "deviceReady", Qt::QueuedConnection); |
430 QMetaObject::invokeMethod(this, "deviceReady", Qt::QueuedConnection); |
423 } |
431 } |
424 } |
432 } |
425 |
433 |
489 } |
497 } |
490 |
498 |
491 return true; |
499 return true; |
492 } |
500 } |
493 |
501 |
494 qint64 QAudioOutputPrivate::clock() const |
502 qint64 QAudioOutputPrivate::elapsedUSecs() const |
495 { |
503 { |
496 if (deviceState == QAudio::StopState) |
504 if (deviceState == QAudio::StoppedState) |
497 return 0; |
505 return 0; |
498 |
506 |
499 return timeStampOpened.elapsed()*1000; |
507 return timeStampOpened.elapsed()*1000; |
500 } |
508 } |
501 |
509 |