From 6ba1241cfef6c3ddf4e50e82f67afde0abc02285 Mon Sep 17 00:00:00 2001 From: Grishka Date: Tue, 5 Jun 2018 20:41:50 +0300 Subject: [PATCH] Fixed audio on Windows XP --- os/windows/AudioInputWave.cpp | 44 ++++++++++++++++++---------------- os/windows/AudioOutputWave.cpp | 34 ++++++++++++++------------ 2 files changed, 43 insertions(+), 35 deletions(-) mode change 100644 => 100755 os/windows/AudioInputWave.cpp mode change 100644 => 100755 os/windows/AudioOutputWave.cpp diff --git a/os/windows/AudioInputWave.cpp b/os/windows/AudioInputWave.cpp old mode 100644 new mode 100755 index 61a8f0b..4b4a4ee --- a/os/windows/AudioInputWave.cpp +++ b/os/windows/AudioInputWave.cpp @@ -42,33 +42,37 @@ void AudioInputWave::Configure(uint32_t sampleRate, uint32_t bitsPerSample, uint } void AudioInputWave::Start(){ - isRecording=true; - - MMRESULT res; - for(int i=0;i<4;i++){ - res=waveInPrepareHeader(hWaveIn, &buffers[i], sizeof(WAVEHDR)); - CHECK_ERROR(res, "waveInPrepareHeader failed"); - res=waveInAddBuffer(hWaveIn, &buffers[i], sizeof(WAVEHDR)); - CHECK_ERROR(res, "waveInAddBuffer failed"); + if(!isRecording){ + isRecording=true; + + MMRESULT res; + for(int i=0;i<4;i++){ + res=waveInPrepareHeader(hWaveIn, &buffers[i], sizeof(WAVEHDR)); + CHECK_ERROR(res, "waveInPrepareHeader failed"); + res=waveInAddBuffer(hWaveIn, &buffers[i], sizeof(WAVEHDR)); + CHECK_ERROR(res, "waveInAddBuffer failed"); + } + res=waveInStart(hWaveIn); + CHECK_ERROR(res, "waveInStart failed"); } - res=waveInStart(hWaveIn); - CHECK_ERROR(res, "waveInStart failed"); } void AudioInputWave::Stop(){ - isRecording=false; - - MMRESULT res=waveInStop(hWaveIn); - CHECK_ERROR(res, "waveInStop failed"); - res=waveInReset(hWaveIn); - CHECK_ERROR(res, "waveInReset failed"); - for(int i=0;i<4;i++){ - res=waveInUnprepareHeader(hWaveIn, &buffers[i], sizeof(WAVEHDR)); - CHECK_ERROR(res, "waveInUnprepareHeader failed"); + if(isRecording){ + isRecording=false; + + MMRESULT res=waveInStop(hWaveIn); + CHECK_ERROR(res, "waveInStop failed"); + res=waveInReset(hWaveIn); + CHECK_ERROR(res, "waveInReset failed"); + for(int i=0;i<4;i++){ + res=waveInUnprepareHeader(hWaveIn, &buffers[i], sizeof(WAVEHDR)); + CHECK_ERROR(res, "waveInUnprepareHeader failed"); + } } } -void AudioInputWave::WaveInProc(HWAVEIN hwi, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2){ +void CALLBACK AudioInputWave::WaveInProc(HWAVEIN hwi, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2){ if(uMsg==WIM_DATA){ ((AudioInputWave*)dwInstance)->OnData((WAVEHDR*)dwParam1); } diff --git a/os/windows/AudioOutputWave.cpp b/os/windows/AudioOutputWave.cpp old mode 100644 new mode 100755 index 752aad8..8527cf3 --- a/os/windows/AudioOutputWave.cpp +++ b/os/windows/AudioOutputWave.cpp @@ -40,26 +40,30 @@ void AudioOutputWave::Configure(uint32_t sampleRate, uint32_t bitsPerSample, uin } void AudioOutputWave::Start(){ - isPlaying=true; - - for(int i=0;i<4;i++){ - MMRESULT res=waveOutPrepareHeader(hWaveOut, &buffers[i], sizeof(WAVEHDR)); - CHECK_ERROR(res, "waveOutPrepareHeader failed"); - //InvokeCallback((unsigned char*)buffers[i].lpData, buffers[i].dwBufferLength); - ZeroMemory(buffers[i].lpData, buffers[i].dwBufferLength); - res=waveOutWrite(hWaveOut, &buffers[i], sizeof(WAVEHDR)); - CHECK_ERROR(res, "waveOutWrite failed"); + if(!isPlaying){ + isPlaying=true; + + for(int i=0;i<4;i++){ + MMRESULT res=waveOutPrepareHeader(hWaveOut, &buffers[i], sizeof(WAVEHDR)); + CHECK_ERROR(res, "waveOutPrepareHeader failed"); + //InvokeCallback((unsigned char*)buffers[i].lpData, buffers[i].dwBufferLength); + ZeroMemory(buffers[i].lpData, buffers[i].dwBufferLength); + res=waveOutWrite(hWaveOut, &buffers[i], sizeof(WAVEHDR)); + CHECK_ERROR(res, "waveOutWrite failed"); + } } } void AudioOutputWave::Stop(){ - isPlaying=false; + if(isPlaying){ + isPlaying=false; - MMRESULT res=waveOutReset(hWaveOut); - CHECK_ERROR(res, "waveOutReset failed"); - for(int i=0;i<4;i++){ - res=waveOutUnprepareHeader(hWaveOut, &buffers[i], sizeof(WAVEHDR)); - CHECK_ERROR(res, "waveOutUnprepareHeader failed"); + MMRESULT res=waveOutReset(hWaveOut); + CHECK_ERROR(res, "waveOutReset failed"); + for(int i=0;i<4;i++){ + res=waveOutUnprepareHeader(hWaveOut, &buffers[i], sizeof(WAVEHDR)); + CHECK_ERROR(res, "waveOutUnprepareHeader failed"); + } } }