From 1eaf97d06151b452171155ae1340c6d62d991c37 Mon Sep 17 00:00:00 2001 From: David Reid Date: Sat, 30 Jun 2018 20:47:48 +1000 Subject: [PATCH] Update test to show a message when a device is stopped. --- mini_al.h | 24 ++++++++++++++++++------ tests/mal_test_0.c | 7 +++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/mini_al.h b/mini_al.h index 29df143f..41295901 100644 --- a/mini_al.h +++ b/mini_al.h @@ -42,9 +42,7 @@ // // You can then #include this file in other parts of the program as you would with any other header file. // -// The implementation of this library will try #include-ing necessary headers for some backends. If you do not have -// the development packages for any particular backend you can disable it by #define-ing the appropriate MAL_NO_* -// option before the implementation. +// If you want to disable a specific backend, #define the appropriate MAL_NO_* option before the implementation. // // Note that GCC and Clang requires "-msse2", "-mavx2", etc. for SIMD optimizations. // @@ -56,6 +54,7 @@ // // Building for macOS // ------------------ +// The macOS build requires -framework CoreFoundation -framework CoreAudio -framework AudioToolbox. // // Building for Linux // ------------------ @@ -12499,6 +12498,12 @@ mal_result mal_device__stop_backend__jack(mal_device* pDevice) if (((mal_jack_deactivate_proc)pContext->jack.jack_deactivate)((mal_jack_client_t*)pDevice->jack.pClient) != 0) { return mal_post_error(pDevice, "[JACK] An error occurred when deactivating the JACK client.", MAL_ERROR); } + + mal_device__set_state(pDevice, MAL_STATE_STOPPED); + mal_stop_proc onStop = pDevice->onStop; + if (onStop) { + onStop(pDevice); + } return MAL_SUCCESS; } @@ -13847,7 +13852,7 @@ mal_result mal_device_init__coreaudio(mal_context* pContext, mal_device_type dev #endif // Backend tax. Need to fiddle with this. - float fBackend = 1.0; + float fBackend = 1.5f; // <-- mini_al's implementation is actually kind of bad at the moment. TODO: Revisit this after AudioUnit implementation. requestedBufferSizeInFrames = mal_calculate_default_buffer_size_in_frames(pConfig->performanceProfile, pConfig->sampleRate, fCPUSpeed*fType*fBackend); if (requestedBufferSizeInFrames == 0) { @@ -15202,8 +15207,9 @@ mal_result mal_device__stop_backend__opensl(mal_device* pDevice) // Make sure the client is aware that the device has stopped. There may be an OpenSL|ES callback for this, but I haven't found it. mal_device__set_state(pDevice, MAL_STATE_STOPPED); - if (pDevice->onStop) { - pDevice->onStop(pDevice); + mal_stop_proc onStop = pDevice->onStop; + if (onStop) { + onStop(pDevice); } return MAL_SUCCESS; @@ -16727,6 +16733,12 @@ mal_result mal_device__stop_backend__sdl(mal_device* pDevice) { ((MAL_PFN_SDL_PauseAudio)pDevice->pContext->sdl.SDL_PauseAudio)(1); } + + mal_device__set_state(pDevice, MAL_STATE_STOPPED); + mal_stop_proc onStop = pDevice->onStop; + if (onStop) { + onStop(pDevice); + } return MAL_SUCCESS; } diff --git a/tests/mal_test_0.c b/tests/mal_test_0.c index 87241b6c..b29b4448 100644 --- a/tests/mal_test_0.c +++ b/tests/mal_test_0.c @@ -43,6 +43,12 @@ void on_log(mal_context* pContext, mal_device* pDevice, const char* message) printf("%s\n", message); } +void on_stop(mal_device* pDevice) +{ + (void)pDevice; + printf("Device Stopped.\n"); +} + FILE* mal_fopen(const char* filePath, const char* openMode) { FILE* pFile; @@ -2272,6 +2278,7 @@ int do_playback_test(mal_backend backend) { mal_context_config contextConfig = mal_context_config_init(on_log); mal_device_config deviceConfig = mal_device_config_init_default_playback(on_send__playback_test); + deviceConfig.onStopCallback = on_stop; #if defined(__EMSCRIPTEN__) deviceConfig.format = mal_format_f32;