Commit 5d0705b3 authored by David Reid's avatar David Reid

Check the return value of mal_device_start() in examples.

parent 8727d3d8
...@@ -62,7 +62,7 @@ Simple Playback Example ...@@ -62,7 +62,7 @@ Simple Playback Example
#include "../mini_al.h" #include "../mini_al.h"
#define DR_WAV_IMPLEMENTATION #define DR_WAV_IMPLEMENTATION
#include "dr_wav.h" #include "../extras/dr_wav.h"
#include <stdio.h> #include <stdio.h>
...@@ -80,20 +80,20 @@ mal_uint32 on_send_frames_to_device(mal_device* pDevice, mal_uint32 frameCount, ...@@ -80,20 +80,20 @@ mal_uint32 on_send_frames_to_device(mal_device* pDevice, mal_uint32 frameCount,
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
if (argc < 2) { if (argc < 2) {
printf("No input file."); printf("No input file.\n");
return -1; return -1;
} }
drwav wav; drwav wav;
if (!drwav_init_file(&wav, argv[1])) { if (!drwav_init_file(&wav, argv[1])) {
printf("Not a valid WAV file."); printf("Not a valid WAV file.\n");
return -2; return -2;
} }
mal_context context; mal_context context;
if (mal_context_init(NULL, 0, NULL, &context) != MAL_SUCCESS) { if (mal_context_init(NULL, 0, NULL, &context) != MAL_SUCCESS) {
printf("Failed to initialize context."); printf("Failed to initialize context.\n");
drwav_uninit(&wav); drwav_uninit(&wav);
return -3; return -3;
} }
...@@ -101,13 +101,19 @@ int main(int argc, char** argv) ...@@ -101,13 +101,19 @@ int main(int argc, char** argv)
mal_device device; mal_device device;
if (mal_device_init(&context, mal_device_type_playback, NULL, &config, &wav, &device) != MAL_SUCCESS) { 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); mal_context_uninit(&context);
drwav_uninit(&wav); drwav_uninit(&wav);
return -4; 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..."); printf("Press Enter to quit...");
getchar(); getchar();
......
...@@ -155,12 +155,17 @@ int main(int argc, char** argv) ...@@ -155,12 +155,17 @@ int main(int argc, char** argv)
mal_device playbackDevice; mal_device playbackDevice;
if (mal_device_init(&context, mal_device_type_playback, NULL, &deviceConfig, NULL, &playbackDevice) != MAL_SUCCESS) { 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); mal_context_uninit(&context);
return -7; 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..."); printf("Press Enter to quit...");
getchar(); getchar();
......
...@@ -92,7 +92,7 @@ int main(int argc, char** argv) ...@@ -92,7 +92,7 @@ int main(int argc, char** argv)
drwav* wav = NULL; drwav* wav = NULL;
stb_vorbis* vorbis = NULL; stb_vorbis* vorbis = NULL;
if ( type == UNK && (flac = drflac_open_file(argv[1])) != NULL) type = FLAC; 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 && (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_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; if ( type == UNK && (jar_mod_load_file(&mod, argv[1]) != 0) ) type = MOD;
...@@ -148,7 +148,13 @@ int main(int argc, char** argv) ...@@ -148,7 +148,13 @@ int main(int argc, char** argv)
goto end; 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..."); printf("Press Enter to quit...");
getchar(); getchar();
......
...@@ -63,10 +63,16 @@ int main() ...@@ -63,10 +63,16 @@ int main()
return -2; 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"); printf("Press Enter to stop recording...\n");
getchar(); getchar();
mal_device_uninit(&captureDevice); mal_device_uninit(&captureDevice);
...@@ -76,12 +82,19 @@ int main() ...@@ -76,12 +82,19 @@ int main()
if (mal_device_init(&context, mal_device_type_playback, NULL, &config, NULL, &playbackDevice) != MAL_SUCCESS) { if (mal_device_init(&context, mal_device_type_playback, NULL, &config, NULL, &playbackDevice) != MAL_SUCCESS) {
mal_context_uninit(&context); mal_context_uninit(&context);
printf("Failed to initialize playback device.\n"); 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"); printf("Press Enter to quit...\n");
getchar(); getchar();
mal_device_uninit(&playbackDevice); mal_device_uninit(&playbackDevice);
mal_context_uninit(&context); mal_context_uninit(&context);
......
...@@ -20,19 +20,19 @@ mal_uint32 on_send_frames_to_device(mal_device* pDevice, mal_uint32 frameCount, ...@@ -20,19 +20,19 @@ mal_uint32 on_send_frames_to_device(mal_device* pDevice, mal_uint32 frameCount,
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
if (argc < 2) { if (argc < 2) {
printf("No input file."); printf("No input file.\n");
return -1; return -1;
} }
drwav wav; drwav wav;
if (!drwav_init_file(&wav, argv[1])) { if (!drwav_init_file(&wav, argv[1])) {
printf("Not a valid WAV file."); printf("Not a valid WAV file.\n");
return -2; return -2;
} }
mal_context context; mal_context context;
if (mal_context_init(NULL, 0, NULL, &context) != MAL_SUCCESS) { if (mal_context_init(NULL, 0, NULL, &context) != MAL_SUCCESS) {
printf("Failed to initialize context."); printf("Failed to initialize context.\n");
drwav_uninit(&wav); drwav_uninit(&wav);
return -3; return -3;
} }
...@@ -41,13 +41,19 @@ int main(int argc, char** argv) ...@@ -41,13 +41,19 @@ int main(int argc, char** argv)
mal_device device; mal_device device;
if (mal_device_init(&context, mal_device_type_playback, NULL, &config, &wav, &device) != MAL_SUCCESS) { 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); mal_context_uninit(&context);
drwav_uninit(&wav); drwav_uninit(&wav);
return -4; 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..."); printf("Press Enter to quit...");
getchar(); getchar();
......
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