MCPcopy Create free account
hub / github.com/DISTRHO/DPF / wasapiThread

Method wasapiThread

distrho/src/jackbridge/rtaudio/RtAudio.cpp:4950–5510  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4948//-----------------------------------------------------------------------------
4949
4950void RtApiWasapi::wasapiThread()
4951{
4952 // as this is a new thread, we must CoInitialize it
4953 CoInitialize( NULL );
4954
4955 HRESULT hr;
4956
4957 IAudioClient* captureAudioClient = ( ( WasapiHandle* ) stream_.apiHandle )->captureAudioClient;
4958 IAudioClient* renderAudioClient = ( ( WasapiHandle* ) stream_.apiHandle )->renderAudioClient;
4959 IAudioCaptureClient* captureClient = ( ( WasapiHandle* ) stream_.apiHandle )->captureClient;
4960 IAudioRenderClient* renderClient = ( ( WasapiHandle* ) stream_.apiHandle )->renderClient;
4961 HANDLE captureEvent = ( ( WasapiHandle* ) stream_.apiHandle )->captureEvent;
4962 HANDLE renderEvent = ( ( WasapiHandle* ) stream_.apiHandle )->renderEvent;
4963
4964 WAVEFORMATEX* captureFormat = NULL;
4965 WAVEFORMATEX* renderFormat = NULL;
4966 float captureSrRatio = 0.0f;
4967 float renderSrRatio = 0.0f;
4968 WasapiBuffer captureBuffer;
4969 WasapiBuffer renderBuffer;
4970 WasapiResampler* captureResampler = NULL;
4971 WasapiResampler* renderResampler = NULL;
4972
4973 // declare local stream variables
4974 RtAudioCallback callback = ( RtAudioCallback ) stream_.callbackInfo.callback;
4975 BYTE* streamBuffer = NULL;
4976 DWORD captureFlags = 0;
4977 unsigned int bufferFrameCount = 0;
4978 unsigned int numFramesPadding = 0;
4979 unsigned int convBufferSize = 0;
4980 bool loopbackEnabled = stream_.device[INPUT] == stream_.device[OUTPUT];
4981 bool callbackPushed = true;
4982 bool callbackPulled = false;
4983 bool callbackStopped = false;
4984 int callbackResult = 0;
4985
4986 // convBuffer is used to store converted buffers between WASAPI and the user
4987 char* convBuffer = NULL;
4988 unsigned int convBuffSize = 0;
4989 unsigned int deviceBuffSize = 0;
4990
4991 std::string errorText;
4992 RtAudioError::Type errorType = RtAudioError::DRIVER_ERROR;
4993
4994 // Attempt to assign "Pro Audio" characteristic to thread
4995 HMODULE AvrtDll = LoadLibraryW( L"AVRT.dll" );
4996 if ( AvrtDll ) {
4997 DWORD taskIndex = 0;
4998 TAvSetMmThreadCharacteristicsPtr AvSetMmThreadCharacteristicsPtr =
4999 ( TAvSetMmThreadCharacteristicsPtr ) (void(*)()) GetProcAddress( AvrtDll, "AvSetMmThreadCharacteristicsW" );
5000 AvSetMmThreadCharacteristicsPtr( L"Pro Audio", &taskIndex );
5001 FreeLibrary( AvrtDll );
5002 }
5003
5004 // start capture stream if applicable
5005 if ( captureAudioClient ) {
5006 hr = captureAudioClient->GetMixFormat( &captureFormat );
5007 if ( FAILED( hr ) ) {

Callers 1

runWasapiThreadMethod · 0.80

Calls 6

GetProcAddressFunction · 0.85
FreeLibraryFunction · 0.85
setBufferSizeMethod · 0.80
pullBufferMethod · 0.80
ConvertMethod · 0.80
pushBufferMethod · 0.80

Tested by

no test coverage detected