Commit 922b5846 authored by David Reid's avatar David Reid

Introduce a new device notification system.

This replaces the stop callback. The new callback supports different
event types, not all of which are supported on all backends.

This commit also fixes a bug where the stop callback is not fired.

Public issue https://github.com/mackron/miniaudio/issues/351
parent 2bd5011b
This diff is collapsed.
...@@ -13,13 +13,13 @@ will receive the captured audio. ...@@ -13,13 +13,13 @@ will receive the captured audio.
"backend" is one of the miniaudio backends: "backend" is one of the miniaudio backends:
wasapi wasapi
dsound dsound or directsound
winmm winmm
coreaudio coreaudio
sndio sndio
audio4 audio4
oss oss
pulseaudio pulseaudio or pulse
alsa alsa
jack jack
aaudio aaudio
...@@ -124,7 +124,7 @@ ma_bool32 try_parse_backend(const char* arg, ma_backend* pBackends, ma_uint32 ba ...@@ -124,7 +124,7 @@ ma_bool32 try_parse_backend(const char* arg, ma_backend* pBackends, ma_uint32 ba
pBackends[backendCount++] = ma_backend_wasapi; pBackends[backendCount++] = ma_backend_wasapi;
goto done; goto done;
} }
if (strcmp(arg, "dsound") == 0) { if (strcmp(arg, "dsound") == 0 || strcmp(arg, "directsound") == 0) {
pBackends[backendCount++] = ma_backend_dsound; pBackends[backendCount++] = ma_backend_dsound;
goto done; goto done;
} }
...@@ -148,7 +148,7 @@ ma_bool32 try_parse_backend(const char* arg, ma_backend* pBackends, ma_uint32 ba ...@@ -148,7 +148,7 @@ ma_bool32 try_parse_backend(const char* arg, ma_backend* pBackends, ma_uint32 ba
pBackends[backendCount++] = ma_backend_oss; pBackends[backendCount++] = ma_backend_oss;
goto done; goto done;
} }
if (strcmp(arg, "pulseaudio") == 0) { if (strcmp(arg, "pulseaudio") == 0 || strcmp(arg, "pulse") == 0) {
pBackends[backendCount++] = ma_backend_pulseaudio; pBackends[backendCount++] = ma_backend_pulseaudio;
goto done; goto done;
} }
...@@ -304,10 +304,39 @@ void on_log(void* pUserData, ma_uint32 logLevel, const char* message) ...@@ -304,10 +304,39 @@ void on_log(void* pUserData, ma_uint32 logLevel, const char* message)
printf("%s: %s", ma_log_level_to_string(logLevel), message); printf("%s: %s", ma_log_level_to_string(logLevel), message);
} }
void on_stop(ma_device* pDevice) void on_notification(const ma_device_notification* pNotification)
{ {
(void)pDevice; MA_ASSERT(pNotification != NULL);
printf("Stopped\n");
switch (pNotification->type)
{
case ma_device_notification_type_started:
{
printf("Started\n");
} break;
case ma_device_notification_type_stopped:
{
printf("Stopped\n");
} break;
case ma_device_notification_type_rerouted:
{
printf("Rerouted\n");
} break;
case ma_device_notification_type_interruption_began:
{
printf("Interruption Began\n");
} break;
case ma_device_notification_type_interruption_ended:
{
printf("Interruption Ended\n");
} break;
default: break;
}
} }
void on_data(ma_device* pDevice, void* pFramesOut, const void* pFramesIn, ma_uint32 frameCount) void on_data(ma_device* pDevice, void* pFramesOut, const void* pFramesIn, ma_uint32 frameCount)
...@@ -458,13 +487,13 @@ int main(int argc, char** argv) ...@@ -458,13 +487,13 @@ int main(int argc, char** argv)
} }
deviceConfig = ma_device_config_init(deviceType); deviceConfig = ma_device_config_init(deviceType);
deviceConfig.playback.format = deviceFormat; deviceConfig.playback.format = deviceFormat;
deviceConfig.playback.channels = deviceChannels; deviceConfig.playback.channels = deviceChannels;
deviceConfig.capture.format = deviceFormat; deviceConfig.capture.format = deviceFormat;
deviceConfig.capture.channels = deviceChannels; deviceConfig.capture.channels = deviceChannels;
deviceConfig.sampleRate = deviceSampleRate; deviceConfig.sampleRate = deviceSampleRate;
deviceConfig.dataCallback = on_data; deviceConfig.dataCallback = on_data;
deviceConfig.stopCallback = on_stop; deviceConfig.notificationCallback = on_notification;
result = ma_device_init(&g_State.context, &deviceConfig, &g_State.device); result = ma_device_init(&g_State.context, &deviceConfig, &g_State.device);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
printf("Failed to initialize device.\n"); printf("Failed to initialize device.\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment