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.
"backend" is one of the miniaudio backends:
wasapi
dsound
dsound or directsound
winmm
coreaudio
sndio
audio4
oss
pulseaudio
pulseaudio or pulse
alsa
jack
aaudio
......@@ -124,7 +124,7 @@ ma_bool32 try_parse_backend(const char* arg, ma_backend* pBackends, ma_uint32 ba
pBackends[backendCount++] = ma_backend_wasapi;
goto done;
}
if (strcmp(arg, "dsound") == 0) {
if (strcmp(arg, "dsound") == 0 || strcmp(arg, "directsound") == 0) {
pBackends[backendCount++] = ma_backend_dsound;
goto done;
}
......@@ -148,7 +148,7 @@ ma_bool32 try_parse_backend(const char* arg, ma_backend* pBackends, ma_uint32 ba
pBackends[backendCount++] = ma_backend_oss;
goto done;
}
if (strcmp(arg, "pulseaudio") == 0) {
if (strcmp(arg, "pulseaudio") == 0 || strcmp(arg, "pulse") == 0) {
pBackends[backendCount++] = ma_backend_pulseaudio;
goto done;
}
......@@ -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);
}
void on_stop(ma_device* pDevice)
void on_notification(const ma_device_notification* pNotification)
{
(void)pDevice;
MA_ASSERT(pNotification != NULL);
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)
......@@ -464,7 +493,7 @@ int main(int argc, char** argv)
deviceConfig.capture.channels = deviceChannels;
deviceConfig.sampleRate = deviceSampleRate;
deviceConfig.dataCallback = on_data;
deviceConfig.stopCallback = on_stop;
deviceConfig.notificationCallback = on_notification;
result = ma_device_init(&g_State.context, &deviceConfig, &g_State.device);
if (result != MA_SUCCESS) {
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