MCPcopy Create free account
hub / github.com/cjcliffe/CubicSDR / wasapiThread

Method wasapiThread

external/rtaudio/RtAudio.cpp:4960–5570  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

runWasapiThreadMethod · 0.80

Calls 5

setBufferSizeMethod · 0.80
pullBufferMethod · 0.80
ConvertMethod · 0.80
pushBufferMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected