src/multimedia/audio/qaudioinput_win32_p.cpp
branchRCL_3
changeset 13 c0432d11811c
parent 7 3f74d0d4af4c
equal deleted inserted replaced
12:cc75c76972ee 13:c0432d11811c
    54 #include "qaudioinput_win32_p.h"
    54 #include "qaudioinput_win32_p.h"
    55 
    55 
    56 QT_BEGIN_NAMESPACE
    56 QT_BEGIN_NAMESPACE
    57 
    57 
    58 //#define DEBUG_AUDIO 1
    58 //#define DEBUG_AUDIO 1
    59 
       
    60 static CRITICAL_SECTION waveInCriticalSection;
       
    61 
    59 
    62 static const int minimumIntervalTime = 50;
    60 static const int minimumIntervalTime = 50;
    63 
    61 
    64 QAudioInputPrivate::QAudioInputPrivate(const QByteArray &device, const QAudioFormat& audioFormat):
    62 QAudioInputPrivate::QAudioInputPrivate(const QByteArray &device, const QAudioFormat& audioFormat):
    65     settings(audioFormat)
    63     settings(audioFormat)
   102 
   100 
   103     switch(uMsg) {
   101     switch(uMsg) {
   104         case WIM_OPEN:
   102         case WIM_OPEN:
   105             break;
   103             break;
   106         case WIM_DATA:
   104         case WIM_DATA:
   107             EnterCriticalSection(&waveInCriticalSection);
   105             EnterCriticalSection(&qAudio->waveInCriticalSection);
   108             if(qAudio->waveFreeBlockCount > 0)
   106             if(qAudio->waveFreeBlockCount > 0)
   109                 qAudio->waveFreeBlockCount--;
   107                 qAudio->waveFreeBlockCount--;
   110             qAudio->feedback();
   108             qAudio->feedback();
   111             LeaveCriticalSection(&waveInCriticalSection);
   109             LeaveCriticalSection(&qAudio->waveInCriticalSection);
   112             break;
   110             break;
   113         case WIM_CLOSE:
   111         case WIM_CLOSE:
   114             EnterCriticalSection(&waveInCriticalSection);
   112             EnterCriticalSection(&qAudio->waveInCriticalSection);
   115             qAudio->finished = true;
   113             qAudio->finished = true;
   116             LeaveCriticalSection(&waveInCriticalSection);
   114             LeaveCriticalSection(&qAudio->waveInCriticalSection);
   117             break;
   115             break;
   118         default:
   116         default:
   119             return;
   117             return;
   120     }
   118     }
   121 }
   119 }
   156     WAVEHDR* blocks = blockArray;
   154     WAVEHDR* blocks = blockArray;
   157 
   155 
   158     int count = buffer_size/period_size;
   156     int count = buffer_size/period_size;
   159 
   157 
   160     for(int i = 0; i < count; i++) {
   158     for(int i = 0; i < count; i++) {
   161         waveInUnprepareHeader(hWaveIn,&blocks[i], sizeof(WAVEHDR));
   159         if (blocks->dwFlags & WHDR_PREPARED)
       
   160             waveInUnprepareHeader(hWaveIn,blocks, sizeof(WAVEHDR));
   162         blocks+=sizeof(WAVEHDR);
   161         blocks+=sizeof(WAVEHDR);
   163     }
   162     }
   164     HeapFree(GetProcessHeap(), 0, blockArray);
   163     HeapFree(GetProcessHeap(), 0, blockArray);
   165 }
   164 }
   166 
   165 
   224     QTime now(QTime::currentTime());
   223     QTime now(QTime::currentTime());
   225     qDebug()<<now.second()<<"s "<<now.msec()<<"ms :open()";
   224     qDebug()<<now.second()<<"s "<<now.msec()<<"ms :open()";
   226 #endif
   225 #endif
   227     header = 0;
   226     header = 0;
   228     if(buffer_size == 0) {
   227     if(buffer_size == 0) {
   229         // Default buffer size, 100ms, default period size is 20ms
   228         // Default buffer size, 200ms, default period size is 40ms
   230         buffer_size = settings.frequency()*settings.channels()*(settings.sampleSize()/8)*0.1;
   229         buffer_size = settings.frequency()*settings.channels()*(settings.sampleSize()/8)*0.2;
   231 	period_size = buffer_size/5;
   230 	period_size = buffer_size/5;
   232     } else {
   231     } else {
   233         period_size = buffer_size/5;
   232         period_size = buffer_size/5;
   234     }
   233     }
   235     timeStamp.restart();
   234     timeStamp.restart();