src/multimedia/audio/qaudiooutput_win32_p.cpp
branchRCL_3
changeset 13 c0432d11811c
parent 7 3f74d0d4af4c
equal deleted inserted replaced
12:cc75c76972ee 13:c0432d11811c
    53 #include "qaudiooutput_win32_p.h"
    53 #include "qaudiooutput_win32_p.h"
    54 
    54 
    55 //#define DEBUG_AUDIO 1
    55 //#define DEBUG_AUDIO 1
    56 
    56 
    57 QT_BEGIN_NAMESPACE
    57 QT_BEGIN_NAMESPACE
    58 
       
    59 static CRITICAL_SECTION waveOutCriticalSection;
       
    60 
    58 
    61 static const int minimumIntervalTime = 50;
    59 static const int minimumIntervalTime = 50;
    62 
    60 
    63 QAudioOutputPrivate::QAudioOutputPrivate(const QByteArray &device, const QAudioFormat& audioFormat):
    61 QAudioOutputPrivate::QAudioOutputPrivate(const QByteArray &device, const QAudioFormat& audioFormat):
    64     settings(audioFormat)
    62     settings(audioFormat)
   105             qAudio->feedback();
   103             qAudio->feedback();
   106             break;
   104             break;
   107         case WOM_CLOSE:
   105         case WOM_CLOSE:
   108             return;
   106             return;
   109         case WOM_DONE:
   107         case WOM_DONE:
   110             EnterCriticalSection(&waveOutCriticalSection);
   108             EnterCriticalSection(&qAudio->waveOutCriticalSection);
   111             if(qAudio->finished || qAudio->buffer_size == 0 || qAudio->period_size == 0) {
   109             if(qAudio->finished || qAudio->buffer_size == 0 || qAudio->period_size == 0) {
   112                 LeaveCriticalSection(&waveOutCriticalSection);
   110                 LeaveCriticalSection(&qAudio->waveOutCriticalSection);
   113                 return;
   111                 return;
   114 	    }
   112 	    }
   115             qAudio->waveFreeBlockCount++;
   113             qAudio->waveFreeBlockCount++;
   116             if(qAudio->waveFreeBlockCount >= qAudio->buffer_size/qAudio->period_size)
   114             if(qAudio->waveFreeBlockCount >= qAudio->buffer_size/qAudio->period_size)
   117                 qAudio->waveFreeBlockCount = qAudio->buffer_size/qAudio->period_size;
   115                 qAudio->waveFreeBlockCount = qAudio->buffer_size/qAudio->period_size;
   118             qAudio->feedback();
   116             qAudio->feedback();
   119             LeaveCriticalSection(&waveOutCriticalSection);
   117             LeaveCriticalSection(&qAudio->waveOutCriticalSection);
   120             break;
   118             break;
   121         default:
   119         default:
   122             return;
   120             return;
   123     }
   121     }
   124 }
   122 }
   150     WAVEHDR* blocks = blockArray;
   148     WAVEHDR* blocks = blockArray;
   151 
   149 
   152     int count = buffer_size/period_size;
   150     int count = buffer_size/period_size;
   153 
   151 
   154     for(int i = 0; i < count; i++) {
   152     for(int i = 0; i < count; i++) {
   155         waveOutUnprepareHeader(hWaveOut,&blocks[i], sizeof(WAVEHDR));
   153         if (blocks->dwFlags & WHDR_PREPARED)
       
   154             waveOutUnprepareHeader(hWaveOut,blocks, sizeof(WAVEHDR));
   156         blocks+=sizeof(WAVEHDR);
   155         blocks+=sizeof(WAVEHDR);
   157     }
   156     }
   158     HeapFree(GetProcessHeap(), 0, blockArray);
   157     HeapFree(GetProcessHeap(), 0, blockArray);
   159 }
   158 }
   160 
   159