mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-22 00:06:59 +02:00
Check the return value of mal_device_start() in examples.
This commit is contained in:
@@ -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 <stdio.h>
|
||||
|
||||
@@ -80,19 +80,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;
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user