7#include <mmdeviceapi.h>
8#include <audioclient.h>
11using namespace Microsoft::WRL;
62 void DoPlay(
const uint8_t* buf,
size_t len)
override;
87 virtual ULONG STDMETHODCALLTYPE
AddRef();
90 virtual ULONG STDMETHODCALLTYPE
Release();
93 virtual HRESULT STDMETHODCALLTYPE
QueryInterface(REFIID riid, VOID** ppvInterface);
108 ComPtr<IMMDeviceEnumerator> mDeviceEnumerator;
109 ComPtr<IMMDevice> mDevice;
110 ComPtr<IAudioClient> mClient;
111 ComPtr<IAudioRenderClient> mRenderClient;
113 UINT32 mBufferFrameCount = 0;
114 bool mInitialized =
false;
115 bool mStarted =
false;
116 int32_t mNumChannels = 2;
Abstract base class for platform-specific audio output backends.
Definition AudioPlayer.h:32
AudioPlayer implementation backed by the Windows Audio Session API (WASAPI).
Definition WasapiAudioPlayer.h:23
virtual ULONG STDMETHODCALLTYPE AddRef()
Increments the IUnknown reference count.
WasapiAudioPlayer(AudioSettings settings)
Constructs a WasapiAudioPlayer with the given audio settings.
Definition WasapiAudioPlayer.h:29
void DoClose() override
Stops playback and releases the stream's COM objects.
void ThrowIfFailed(HRESULT res)
Throws a Ship::HResultException if res is a failed HRESULT.
virtual HRESULT STDMETHODCALLTYPE OnDeviceStateChanged(LPCWSTR pwstrDeviceId, DWORD dwNewState)
Called when the state of an audio endpoint device changes.
bool DoInit() override
Opens the WASAPI shared-mode audio client and registers device notifications.
virtual HRESULT STDMETHODCALLTYPE OnDefaultDeviceChanged(EDataFlow flow, ERole role, LPCWSTR pwstrDefaultDeviceId)
Called when the default audio endpoint for a given data-flow or role changes.
~WasapiAudioPlayer()
Closes the stream and unregisters the endpoint notification callback.
bool SetupStream()
(Re-)opens the WASAPI audio stream on the current default device.
int Buffered() override
Returns the number of frames currently queued in the WASAPI render buffer.
virtual HRESULT STDMETHODCALLTYPE OnDeviceAdded(LPCWSTR pwstrDeviceId)
Called when a new audio endpoint device is added to the system.
virtual ULONG STDMETHODCALLTYPE Release()
Decrements the IUnknown reference count.
virtual HRESULT STDMETHODCALLTYPE OnDeviceRemoved(LPCWSTR pwstrDeviceId)
Called when an audio endpoint device is removed from the system.
virtual HRESULT STDMETHODCALLTYPE OnPropertyValueChanged(LPCWSTR pwstrDeviceId, const PROPERTYKEY key)
Called when a property value of an audio endpoint device changes.
void DoPlay(const uint8_t *buf, size_t len) override
Writes interleaved PCM samples to the WASAPI render buffer.
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, VOID **ppvInterface)
Returns the requested interface if supported; otherwise E_NOINTERFACE.
Core namespace for the libultraship engine framework.
Definition gfx_direct3d_common.h:14
Configuration parameters shared by all AudioPlayer backends.
Definition AudioPlayer.h:14