| 5387 | //----------------------------------------------------------------------------- |
| 5388 | |
| 5389 | void RtApiWasapi::wasapiThread() |
| 5390 | { |
| 5391 | // as this is a new thread, we must CoInitialize it |
| 5392 | //CoInitialize( NULL ); modified by LabSound per issue 121 |
| 5393 | CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); |
| 5394 | |
| 5395 | HRESULT hr; |
| 5396 | |
| 5397 | IAudioClient * captureAudioClient = ((WasapiHandle *) stream_.apiHandle)->captureAudioClient; |
| 5398 | IAudioClient * renderAudioClient = ((WasapiHandle *) stream_.apiHandle)->renderAudioClient; |
| 5399 | IAudioCaptureClient * captureClient = ((WasapiHandle *) stream_.apiHandle)->captureClient; |
| 5400 | IAudioRenderClient * renderClient = ((WasapiHandle *) stream_.apiHandle)->renderClient; |
| 5401 | HANDLE captureEvent = ((WasapiHandle *) stream_.apiHandle)->captureEvent; |
| 5402 | HANDLE renderEvent = ((WasapiHandle *) stream_.apiHandle)->renderEvent; |
| 5403 | |
| 5404 | WAVEFORMATEX * captureFormat = NULL; |
| 5405 | WAVEFORMATEX * renderFormat = NULL; |
| 5406 | float captureSrRatio = 0.0f; |
| 5407 | float renderSrRatio = 0.0f; |
| 5408 | WasapiBuffer captureBuffer; |
| 5409 | WasapiBuffer renderBuffer; |
| 5410 | WasapiResampler * captureResampler = NULL; |
| 5411 | WasapiResampler * renderResampler = NULL; |
| 5412 | |
| 5413 | // declare local stream variables |
| 5414 | RtAudioCallback callback = (RtAudioCallback) stream_.callbackInfo.callback; |
| 5415 | BYTE * streamBuffer = NULL; |
| 5416 | unsigned long captureFlags = 0; |
| 5417 | unsigned int bufferFrameCount = 0; |
| 5418 | unsigned int numFramesPadding = 0; |
| 5419 | unsigned int convBufferSize = 0; |
| 5420 | bool loopbackEnabled = stream_.device[INPUT] == stream_.device[OUTPUT]; |
| 5421 | bool callbackPushed = true; |
| 5422 | bool callbackPulled = false; |
| 5423 | bool callbackStopped = false; |
| 5424 | int callbackResult = 0; |
| 5425 | |
| 5426 | // convBuffer is used to store converted buffers between WASAPI and the user |
| 5427 | char * convBuffer = NULL; |
| 5428 | unsigned int convBuffSize = 0; |
| 5429 | unsigned int deviceBuffSize = 0; |
| 5430 | |
| 5431 | std::string errorText; |
| 5432 | RtAudioError::Type errorType = RtAudioError::DRIVER_ERROR; |
| 5433 | |
| 5434 | // Attempt to assign "Pro Audio" characteristic to thread |
| 5435 | HMODULE AvrtDll = LoadLibrary((LPCTSTR) "AVRT.dll"); |
| 5436 | if (AvrtDll) |
| 5437 | { |
| 5438 | DWORD taskIndex = 0; |
| 5439 | TAvSetMmThreadCharacteristicsPtr AvSetMmThreadCharacteristicsPtr = (TAvSetMmThreadCharacteristicsPtr)(void (*)()) GetProcAddress(AvrtDll, "AvSetMmThreadCharacteristicsW"); |
| 5440 | AvSetMmThreadCharacteristicsPtr(L"Pro Audio", &taskIndex); |
| 5441 | FreeLibrary(AvrtDll); |
| 5442 | } |
| 5443 | |
| 5444 | // start capture stream if applicable |
| 5445 | if (captureAudioClient) |
| 5446 | { |
no test coverage detected