7#include <mmdeviceapi.h>
8#include <audioclient.h>
11using namespace Microsoft::WRL;
56 void DoPlay(
const uint8_t* buf,
size_t len)
override;
81 virtual ULONG STDMETHODCALLTYPE
AddRef();
84 virtual ULONG STDMETHODCALLTYPE
Release();
87 virtual HRESULT STDMETHODCALLTYPE
QueryInterface(REFIID riid, VOID** ppvInterface);
102 ComPtr<IMMDeviceEnumerator> mDeviceEnumerator;
103 ComPtr<IMMDevice> mDevice;
104 ComPtr<IAudioClient> mClient;
105 ComPtr<IAudioRenderClient> mRenderClient;
107 UINT32 mBufferFrameCount = 0;
108 bool mInitialized =
false;
109 bool mStarted =
false;
110 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, unregisters device notifications, and releases 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.
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