mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-22 00:06:59 +02:00
Web Audio: Update to the new device info system.
This commit is contained in:
+5
-7
@@ -42910,6 +42910,7 @@ static void ma_context_uninit__webaudio(ma_context* pContext)
|
|||||||
static ma_device_enumeration_result ma_context_enumerate_device_from_type__webaudio(ma_context* pContext, ma_device_type deviceType, ma_enum_devices_callback_proc callback, void* pUserData)
|
static ma_device_enumeration_result ma_context_enumerate_device_from_type__webaudio(ma_context* pContext, ma_device_type deviceType, ma_enum_devices_callback_proc callback, void* pUserData)
|
||||||
{
|
{
|
||||||
ma_device_info deviceInfo;
|
ma_device_info deviceInfo;
|
||||||
|
ma_uint32 sampleRate;
|
||||||
|
|
||||||
(void)pContext;
|
(void)pContext;
|
||||||
|
|
||||||
@@ -42929,11 +42930,8 @@ static ma_device_enumeration_result ma_context_enumerate_device_from_type__webau
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Data Format. */
|
/* Data Format. */
|
||||||
/* Web Audio can support any number of channels. It only supports f32 formats, however. */
|
/* Web Audio can support any number of channels up to 32. It only supports f32 formats, however. The sample rate can be queried. */
|
||||||
deviceInfo.nativeDataFormats[0].flags = 0;
|
sampleRate = EM_ASM_INT({
|
||||||
deviceInfo.nativeDataFormats[0].format = ma_format_unknown;
|
|
||||||
deviceInfo.nativeDataFormats[0].channels = 0; /* All channels are supported. */
|
|
||||||
deviceInfo.nativeDataFormats[0].sampleRate = EM_ASM_INT({
|
|
||||||
try {
|
try {
|
||||||
var temp = new (window.AudioContext || window.webkitAudioContext)();
|
var temp = new (window.AudioContext || window.webkitAudioContext)();
|
||||||
var sampleRate = temp.sampleRate;
|
var sampleRate = temp.sampleRate;
|
||||||
@@ -42944,11 +42942,11 @@ static ma_device_enumeration_result ma_context_enumerate_device_from_type__webau
|
|||||||
}
|
}
|
||||||
}, 0); /* Must pass in a dummy argument for C99 compatibility. */
|
}, 0); /* Must pass in a dummy argument for C99 compatibility. */
|
||||||
|
|
||||||
if (deviceInfo.nativeDataFormats[0].sampleRate == 0) {
|
if (sampleRate == 0) {
|
||||||
return MA_DEVICE_ENUMERATION_CONTINUE;
|
return MA_DEVICE_ENUMERATION_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
deviceInfo.nativeDataFormatCount = 1;
|
ma_device_info_add_native_data_format_2(&deviceInfo, ma_format_f32, 1, 32, sampleRate, sampleRate);
|
||||||
|
|
||||||
return callback(deviceType, &deviceInfo, pUserData);
|
return callback(deviceType, &deviceInfo, pUserData);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,10 +142,69 @@ static EM_BOOL on_canvas_click(int eventType, const EmscriptenMouseEvent* pMouse
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void print_device_info(const ma_device_info* pDeviceInfo)
|
||||||
|
{
|
||||||
|
ma_uint32 iFormat;
|
||||||
|
|
||||||
|
printf("%s\n", pDeviceInfo->name);
|
||||||
|
printf(" Default: %s\n", (pDeviceInfo->isDefault) ? "Yes" : "No");
|
||||||
|
printf(" Format Count: %d\n", pDeviceInfo->nativeDataFormatCount);
|
||||||
|
for (iFormat = 0; iFormat < pDeviceInfo->nativeDataFormatCount; ++iFormat) {
|
||||||
|
printf(" %s, [%d, %d], [%d, %d]\n",
|
||||||
|
ma_get_format_name(pDeviceInfo->nativeDataFormats[iFormat].format),
|
||||||
|
pDeviceInfo->nativeDataFormats[iFormat].minChannels, pDeviceInfo->nativeDataFormats[iFormat].maxChannels,
|
||||||
|
pDeviceInfo->nativeDataFormats[iFormat].minSampleRate, pDeviceInfo->nativeDataFormats[iFormat].maxSampleRate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void enumerate_devices()
|
||||||
|
{
|
||||||
|
ma_result result;
|
||||||
|
ma_context context;
|
||||||
|
ma_device_backend_config backend;
|
||||||
|
ma_device_info* pPlaybackDevices;
|
||||||
|
ma_device_info* pCaptureDevices;
|
||||||
|
ma_uint32 playbackDeviceCount;
|
||||||
|
ma_uint32 captureDeviceCount;
|
||||||
|
ma_uint32 iDevice;
|
||||||
|
|
||||||
|
backend = ma_device_backend_config_init(DEVICE_BACKEND, NULL);
|
||||||
|
|
||||||
|
result = ma_context_init(&backend, 1, NULL, &context);
|
||||||
|
if (result != MA_SUCCESS) {
|
||||||
|
printf("Failed to create context for device enumeration.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = ma_context_get_devices(&context, &pPlaybackDevices, &playbackDeviceCount, &pCaptureDevices, &captureDeviceCount);
|
||||||
|
if (result != MA_SUCCESS) {
|
||||||
|
printf("Failed to enumerate devices.\n");
|
||||||
|
ma_context_uninit(&context);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Playback Devices\n");
|
||||||
|
printf("----------------\n");
|
||||||
|
for (iDevice = 0; iDevice < playbackDeviceCount; iDevice += 1) {
|
||||||
|
printf("%d: ", iDevice);
|
||||||
|
print_device_info(&pPlaybackDevices[iDevice]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
printf("Capture Devices\n");
|
||||||
|
printf("---------------\n");
|
||||||
|
for (iDevice = 0; iDevice < captureDeviceCount; iDevice += 1) {
|
||||||
|
printf("%d: ", iDevice);
|
||||||
|
print_device_info(&pCaptureDevices[iDevice]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
enumerate_devices();
|
||||||
|
|
||||||
printf("Click inside canvas to start playing:\n");
|
printf("Click inside canvas to start playing:\n");
|
||||||
printf(" Left click for playback\n");
|
printf(" Left click for playback\n");
|
||||||
printf(" Right click for duplex\n");
|
printf(" Right click for duplex\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user