Skip to content

Commit

Permalink
Merge pull request #435 from lalitshankarchowdhury/master
Browse files Browse the repository at this point in the history
Fix no output on WASAPI (#433)
  • Loading branch information
garyscavone authored Sep 17, 2024
2 parents 0cee8ed + 632bbba commit ef77fe8
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions RtAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@
#include <locale>

#if defined(_WIN32)
#include <wrl/client.h>
using Microsoft::WRL::ComPtr;
#include <windows.h>
#endif

Expand Down Expand Up @@ -257,6 +255,8 @@ class RtApiDs: public RtApi
#endif

#if defined(__WINDOWS_WASAPI__)
#include <wrl/client.h>
using Microsoft::WRL::ComPtr;

struct IMMDeviceEnumerator;

Expand Down Expand Up @@ -4691,8 +4691,8 @@ class WasapiResampler
outputBufferSize = ( unsigned int ) ceilf( inputBufferSize * _sampleRatio ) + ( _bytesPerSample * _channelCount );
}

ComPtr<IMFMediaBuffer> rInBuffer;
ComPtr<IMFSample> rInSample;
ComPtr<IMFMediaBuffer> rInBuffer = NULL;
ComPtr<IMFSample> rInSample = NULL;
BYTE* rInByteBuffer = NULL;

// 5. Create Sample object from input data
Expand Down Expand Up @@ -4749,7 +4749,6 @@ class WasapiResampler
rOutBuffer->Lock( &rOutByteBuffer, NULL, NULL );
memcpy( outBuffer, rOutByteBuffer, rBytes );
rOutBuffer->Unlock();
rOutByteBuffer = NULL;

outSampleCount = rBytes / _bytesPerSample / _channelCount;
SAFE_RELEASE( rOutDataBuffer.pSample );
Expand Down Expand Up @@ -5090,6 +5089,8 @@ void RtApiWasapi::probeDevices( void )
}

Exit:
// Release all references

CoTaskMemFree( defaultCaptureId );
CoTaskMemFree( defaultRenderId );

Expand Down Expand Up @@ -5237,6 +5238,8 @@ void RtApiWasapi::closeStream( void )
MUTEX_LOCK( &stream_.mutex );
}

// clean up stream memory

if ( ( ( WasapiHandle* ) stream_.apiHandle )->captureEvent )
CloseHandle( ( ( WasapiHandle* ) stream_.apiHandle )->captureEvent );

Expand Down Expand Up @@ -5439,15 +5442,15 @@ bool RtApiWasapi::probeDeviceOpen( unsigned int deviceId, StreamMode mode, unsig
// If an output device and is configured for loopback (input mode)
if ( isInput == false && mode == INPUT ) {
// If renderAudioClient is not initialised, initialise it now
ComPtr<IAudioClient> renderAudioClient = ( ( WasapiHandle* ) stream_.apiHandle )->renderAudioClient;
ComPtr<IAudioClient>& renderAudioClient = ( ( WasapiHandle* ) stream_.apiHandle )->renderAudioClient;
if ( !renderAudioClient ) {
MUTEX_UNLOCK( &stream_.mutex );
probeDeviceOpen( deviceId, OUTPUT, channels, firstChannel, sampleRate, format, bufferSize, options );
MUTEX_LOCK( &stream_.mutex );
}

// Retrieve captureAudioClient from our stream handle.
ComPtr<IAudioClient> captureAudioClient = ( ( WasapiHandle* ) stream_.apiHandle )->captureAudioClient;
ComPtr<IAudioClient>& captureAudioClient = ( ( WasapiHandle* ) stream_.apiHandle )->captureAudioClient;

hr = devicePtr->Activate( __uuidof( IAudioClient ), CLSCTX_ALL,
NULL, ( void** ) &captureAudioClient );
Expand All @@ -5469,7 +5472,7 @@ bool RtApiWasapi::probeDeviceOpen( unsigned int deviceId, StreamMode mode, unsig
// If output device and is configured for output.
if ( isInput == false && mode == OUTPUT ) {
// If renderAudioClient is already initialised, don't initialise it again
ComPtr<IAudioClient> renderAudioClient = ( ( WasapiHandle* ) stream_.apiHandle )->renderAudioClient;
ComPtr<IAudioClient>& renderAudioClient = ( ( WasapiHandle* ) stream_.apiHandle )->renderAudioClient;
if ( renderAudioClient ) {
methodResult = SUCCESS;
goto Exit;
Expand Down

0 comments on commit ef77fe8

Please sign in to comment.