DirectSound: Remove ma_context_get_device_info__dsound().

This commit is contained in:
David Reid
2025-07-21 08:48:53 +10:00
parent ced8f9e091
commit b184d81a46
+1 -157
View File
@@ -25940,162 +25940,6 @@ static BOOL CALLBACK ma_context_get_device_info_callback__dsound(GUID* lpGuid, c
return TRUE;
}
static ma_result ma_context_get_device_info__dsound(ma_context* pContext, ma_device_type deviceType, const ma_device_id* pDeviceID, ma_device_info* pDeviceInfo)
{
ma_context_state_dsound* pContextStateDSound = ma_context_get_backend_state__dsound(pContext);
ma_result result;
HRESULT hr;
if (pDeviceID != NULL) {
ma_context_get_device_info_callback_data__dsound data;
/* ID. */
MA_COPY_MEMORY(pDeviceInfo->id.dsound, pDeviceID->dsound, 16);
/* Name / Description. This is retrieved by enumerating over each device until we find that one that matches the input ID. */
data.pDeviceID = pDeviceID;
data.pDeviceInfo = pDeviceInfo;
data.found = MA_FALSE;
if (deviceType == ma_device_type_playback) {
pContextStateDSound->DirectSoundEnumerateA(ma_context_get_device_info_callback__dsound, &data);
} else {
pContextStateDSound->DirectSoundCaptureEnumerateA(ma_context_get_device_info_callback__dsound, &data);
}
if (!data.found) {
return MA_NO_DEVICE;
}
} else {
/* I don't think there's a way to get the name of the default device with DirectSound. In this case we just need to use defaults. */
/* ID */
MA_ZERO_MEMORY(pDeviceInfo->id.dsound, 16);
/* Name / Description */
if (deviceType == ma_device_type_playback) {
ma_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), MA_DEFAULT_PLAYBACK_DEVICE_NAME, (size_t)-1);
} else {
ma_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), MA_DEFAULT_CAPTURE_DEVICE_NAME, (size_t)-1);
}
pDeviceInfo->isDefault = MA_TRUE;
}
/* Retrieving detailed information is slightly different depending on the device type. */
if (deviceType == ma_device_type_playback) {
/* Playback. */
ma_IDirectSound* pDirectSound;
MA_DSCAPS caps;
WORD channels;
result = ma_context_create_IDirectSound__dsound(pContext, ma_share_mode_shared, pDeviceID, &pDirectSound);
if (result != MA_SUCCESS) {
return result;
}
MA_ZERO_OBJECT(&caps);
caps.dwSize = sizeof(caps);
hr = ma_IDirectSound_GetCaps(pDirectSound, &caps);
if (FAILED(hr)) {
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[DirectSound] IDirectSound_GetCaps() failed for playback device.");
return ma_result_from_HRESULT(hr);
}
/* Channels. Only a single channel count is reported for DirectSound. */
if ((caps.dwFlags & MA_DSCAPS_PRIMARYSTEREO) != 0) {
/* It supports at least stereo, but could support more. */
DWORD speakerConfig;
channels = 2;
/* Look at the speaker configuration to get a better idea on the channel count. */
hr = ma_IDirectSound_GetSpeakerConfig(pDirectSound, &speakerConfig);
if (SUCCEEDED(hr)) {
ma_get_channels_from_speaker_config__dsound(speakerConfig, &channels, NULL);
}
} else {
/* It does not support stereo, which means we are stuck with mono. */
channels = 1;
}
/*
In DirectSound, our native formats are centered around sample rates. All formats are supported, and we're only reporting a single channel
count. However, DirectSound can report a range of supported sample rates. We're only going to include standard rates known by miniaudio
in order to keep the size of this within reason.
*/
if ((caps.dwFlags & MA_DSCAPS_CONTINUOUSRATE) != 0) {
/* Multiple sample rates are supported. We'll report in order of our preferred sample rates. */
size_t iStandardSampleRate;
for (iStandardSampleRate = 0; iStandardSampleRate < ma_countof(g_maStandardSampleRatePriorities); iStandardSampleRate += 1) {
ma_uint32 sampleRate = g_maStandardSampleRatePriorities[iStandardSampleRate];
if (sampleRate >= caps.dwMinSecondarySampleRate && sampleRate <= caps.dwMaxSecondarySampleRate) {
pDeviceInfo->nativeDataFormats[pDeviceInfo->nativeDataFormatCount].format = ma_format_unknown;
pDeviceInfo->nativeDataFormats[pDeviceInfo->nativeDataFormatCount].channels = channels;
pDeviceInfo->nativeDataFormats[pDeviceInfo->nativeDataFormatCount].sampleRate = sampleRate;
pDeviceInfo->nativeDataFormats[pDeviceInfo->nativeDataFormatCount].flags = 0;
pDeviceInfo->nativeDataFormatCount += 1;
}
}
} else {
/* Only a single sample rate is supported. */
pDeviceInfo->nativeDataFormats[pDeviceInfo->nativeDataFormatCount].format = ma_format_unknown;
pDeviceInfo->nativeDataFormats[pDeviceInfo->nativeDataFormatCount].channels = channels;
pDeviceInfo->nativeDataFormats[pDeviceInfo->nativeDataFormatCount].sampleRate = caps.dwMaxSecondarySampleRate;
pDeviceInfo->nativeDataFormats[pDeviceInfo->nativeDataFormatCount].flags = 0;
pDeviceInfo->nativeDataFormatCount += 1;
}
ma_IDirectSound_Release(pDirectSound);
} else {
/*
Capture. This is a little different to playback due to the way the supported formats are reported. Technically capture
devices can support a number of different formats, but for simplicity and consistency with ma_device_init() I'm just
reporting the best format.
*/
ma_IDirectSoundCapture* pDirectSoundCapture;
WORD channels;
WORD bitsPerSample;
DWORD sampleRate;
result = ma_context_create_IDirectSoundCapture__dsound(pContext, ma_share_mode_shared, pDeviceID, &pDirectSoundCapture);
if (result != MA_SUCCESS) {
return result;
}
result = ma_context_get_format_info_for_IDirectSoundCapture__dsound(pContext, pDirectSoundCapture, &channels, &bitsPerSample, &sampleRate);
if (result != MA_SUCCESS) {
ma_IDirectSoundCapture_Release(pDirectSoundCapture);
return result;
}
ma_IDirectSoundCapture_Release(pDirectSoundCapture);
/* The format is always an integer format and is based on the bits per sample. */
if (bitsPerSample == 8) {
pDeviceInfo->nativeDataFormats[0].format = ma_format_u8;
} else if (bitsPerSample == 16) {
pDeviceInfo->nativeDataFormats[0].format = ma_format_s16;
} else if (bitsPerSample == 24) {
pDeviceInfo->nativeDataFormats[0].format = ma_format_s24;
} else if (bitsPerSample == 32) {
pDeviceInfo->nativeDataFormats[0].format = ma_format_s32;
} else {
return MA_FORMAT_NOT_SUPPORTED;
}
pDeviceInfo->nativeDataFormats[0].channels = channels;
pDeviceInfo->nativeDataFormats[0].sampleRate = sampleRate;
pDeviceInfo->nativeDataFormats[0].flags = 0;
pDeviceInfo->nativeDataFormatCount = 1;
}
return MA_SUCCESS;
}
static ma_result ma_config_to_WAVEFORMATEXTENSIBLE(ma_format format, ma_uint32 channels, ma_uint32 sampleRate, const ma_channel* pChannelMap, MA_WAVEFORMATEXTENSIBLE* pWF)
{
GUID subformat;
@@ -27012,7 +26856,7 @@ static ma_device_backend_vtable ma_gDeviceBackendVTable_DSound =
ma_context_init__dsound,
ma_context_uninit__dsound,
ma_context_enumerate_devices__dsound,
ma_context_get_device_info__dsound,
NULL,
ma_device_init__dsound,
ma_device_uninit__dsound,
NULL, /* onDeviceStart. Started in onDeviceLoop. */