From 5d0705b34e1df513318f2071392fccddf303bfb4 Mon Sep 17 00:00:00 2001 From: David Reid Date: Sun, 3 Dec 2017 17:02:30 +1000 Subject: [PATCH] Check the return value of mal_device_start() in examples. --- README.md | 22 ++++++++++++++-------- examples/advanced_config.c | 9 +++++++-- examples/multi_playback.c | 10 ++++++++-- examples/simple_capture.c | 19 ++++++++++++++++--- examples/simple_playback.c | 16 +++++++++++----- 5 files changed, 56 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 739af3ac..41f4767d 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ Simple Playback Example #include "../mini_al.h" #define DR_WAV_IMPLEMENTATION -#include "dr_wav.h" +#include "../extras/dr_wav.h" #include @@ -80,20 +80,20 @@ mal_uint32 on_send_frames_to_device(mal_device* pDevice, mal_uint32 frameCount, int main(int argc, char** argv) { if (argc < 2) { - printf("No input file."); + printf("No input file.\n"); return -1; } drwav wav; if (!drwav_init_file(&wav, argv[1])) { - printf("Not a valid WAV file."); + printf("Not a valid WAV file.\n"); return -2; } mal_context context; if (mal_context_init(NULL, 0, NULL, &context) != MAL_SUCCESS) { - printf("Failed to initialize context."); - drwav_uninit(&wav); + printf("Failed to initialize context.\n"); + drwav_uninit(&wav); return -3; } @@ -101,13 +101,19 @@ int main(int argc, char** argv) mal_device device; if (mal_device_init(&context, mal_device_type_playback, NULL, &config, &wav, &device) != MAL_SUCCESS) { - printf("Failed to open playback device."); + printf("Failed to open playback device.\n"); mal_context_uninit(&context); drwav_uninit(&wav); return -4; } - - mal_device_start(&device); + + if (mal_device_start(&device) != MAL_SUCCESS) { + printf("Failed to start playback device.\n"); + mal_device_uninit(&device); + mal_context_uninit(&context); + drwav_uninit(&wav); + return -5; + } printf("Press Enter to quit..."); getchar(); diff --git a/examples/advanced_config.c b/examples/advanced_config.c index 18520fe3..c62df9db 100644 --- a/examples/advanced_config.c +++ b/examples/advanced_config.c @@ -155,12 +155,17 @@ int main(int argc, char** argv) mal_device playbackDevice; if (mal_device_init(&context, mal_device_type_playback, NULL, &deviceConfig, NULL, &playbackDevice) != MAL_SUCCESS) { - printf("Failed to initialize playback device."); + printf("Failed to initialize playback device.\n"); mal_context_uninit(&context); return -7; } - mal_device_start(&playbackDevice); + if (mal_device_start(&playbackDevice) != MAL_SUCCESS) { + printf("Failed to start playback device.\n"); + mal_device_uninit(&playbackDevice); + mal_context_uninit(&context); + return -8; + } printf("Press Enter to quit..."); getchar(); diff --git a/examples/multi_playback.c b/examples/multi_playback.c index 51f6abd0..61df3f5b 100644 --- a/examples/multi_playback.c +++ b/examples/multi_playback.c @@ -92,7 +92,7 @@ int main(int argc, char** argv) drwav* wav = NULL; stb_vorbis* vorbis = NULL; if ( type == UNK && (flac = drflac_open_file(argv[1])) != NULL) type = FLAC; - if ( type == UNK && (wav = drwav_open_file(&wav, argv[1])) != NULL) type = WAV; + if ( type == UNK && (wav = drwav_open_file(argv[1])) != NULL) type = WAV; if ( type == UNK && (vorbis = stb_vorbis_open_filename(argv[1], NULL, NULL)) != NULL) type = VORBIS; if ( type == UNK && (jar_xm_create_context_from_file(&xm, 48000, argv[1]) == 0)) type = XM; if ( type == UNK && (jar_mod_load_file(&mod, argv[1]) != 0) ) type = MOD; @@ -148,7 +148,13 @@ int main(int argc, char** argv) goto end; } - mal_device_start(&device); + if (mal_device_start(&device) != MAL_SUCCESS) { + printf("Failed to start playback device.\n"); + mal_device_uninit(&device); + mal_context_uninit(&context); + exitcode = -4; + goto end; + } printf("Press Enter to quit..."); getchar(); diff --git a/examples/simple_capture.c b/examples/simple_capture.c index 9ad5302f..de79c73f 100644 --- a/examples/simple_capture.c +++ b/examples/simple_capture.c @@ -63,10 +63,16 @@ int main() return -2; } - mal_device_start(&captureDevice); + if (mal_device_start(&captureDevice) != MAL_SUCCESS) { + mal_device_uninit(&captureDevice); + mal_context_uninit(&context); + printf("Failed to start capture device.\n"); + return -3; + } printf("Press Enter to stop recording...\n"); getchar(); + mal_device_uninit(&captureDevice); @@ -76,12 +82,19 @@ int main() if (mal_device_init(&context, mal_device_type_playback, NULL, &config, NULL, &playbackDevice) != MAL_SUCCESS) { mal_context_uninit(&context); printf("Failed to initialize playback device.\n"); - return -3; + return -4; + } + + if (mal_device_start(&playbackDevice) != MAL_SUCCESS) { + mal_device_uninit(&playbackDevice); + mal_context_uninit(&context); + printf("Failed to start playback device.\n"); + return -5; } - mal_device_start(&playbackDevice); printf("Press Enter to quit...\n"); getchar(); + mal_device_uninit(&playbackDevice); mal_context_uninit(&context); diff --git a/examples/simple_playback.c b/examples/simple_playback.c index 4c39e588..8f4be8fe 100644 --- a/examples/simple_playback.c +++ b/examples/simple_playback.c @@ -20,19 +20,19 @@ mal_uint32 on_send_frames_to_device(mal_device* pDevice, mal_uint32 frameCount, int main(int argc, char** argv) { if (argc < 2) { - printf("No input file."); + printf("No input file.\n"); return -1; } drwav wav; if (!drwav_init_file(&wav, argv[1])) { - printf("Not a valid WAV file."); + printf("Not a valid WAV file.\n"); return -2; } mal_context context; if (mal_context_init(NULL, 0, NULL, &context) != MAL_SUCCESS) { - printf("Failed to initialize context."); + printf("Failed to initialize context.\n"); drwav_uninit(&wav); return -3; } @@ -41,13 +41,19 @@ int main(int argc, char** argv) mal_device device; if (mal_device_init(&context, mal_device_type_playback, NULL, &config, &wav, &device) != MAL_SUCCESS) { - printf("Failed to open playback device."); + printf("Failed to open playback device.\n"); mal_context_uninit(&context); drwav_uninit(&wav); return -4; } - mal_device_start(&device); + if (mal_device_start(&device) != MAL_SUCCESS) { + printf("Failed to start playback device.\n"); + mal_device_uninit(&device); + mal_context_uninit(&context); + drwav_uninit(&wav); + return -5; + } printf("Press Enter to quit..."); getchar();