Commit dd7c706e authored by David Reid's avatar David Reid

Update example in readme.

parent 1d9ccdec
...@@ -21,6 +21,15 @@ Simple Playback Example ...@@ -21,6 +21,15 @@ Simple Playback Example
======================= =======================
```c ```c
#define MAL_IMPLEMENTATION
#include "../mini_al.h"
#define DR_WAV_IMPLEMENTATION
#include "dr_wav.h"
#include <stdio.h>
// This is the function that's used for sending more data to the device for playback.
mal_uint32 on_send_frames_to_device(mal_device* pDevice, mal_uint32 frameCount, void* pSamples) mal_uint32 on_send_frames_to_device(mal_device* pDevice, mal_uint32 frameCount, void* pSamples)
{ {
drwav* pWav = (drwav*)pDevice->pUserData; drwav* pWav = (drwav*)pDevice->pUserData;
...@@ -44,6 +53,12 @@ int main(int argc, char** argv) ...@@ -44,6 +53,12 @@ int main(int argc, char** argv)
return -2; return -2;
} }
mal_context context;
if (mal_context_init(NULL, 0, &context) != MAL_SUCCESS) {
printf("Failed to initialize context.");
return -3;
}
// In this example we use the default playback device with a default buffer size and period count. // In this example we use the default playback device with a default buffer size and period count.
mal_device_config config; mal_device_config config;
config.format = mal_format_f32; config.format = mal_format_f32;
...@@ -57,10 +72,11 @@ int main(int argc, char** argv) ...@@ -57,10 +72,11 @@ int main(int argc, char** argv)
config.onLogCallback = NULL; config.onLogCallback = NULL;
mal_device device; mal_device device;
if (mal_device_init(&device, mal_device_type_playback, NULL, &config, &wav) != 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.");
mal_context_uninit(&context);
drwav_uninit(&wav); drwav_uninit(&wav);
return -3; return -4;
} }
mal_device_start(&device); mal_device_start(&device);
...@@ -68,6 +84,7 @@ int main(int argc, char** argv) ...@@ -68,6 +84,7 @@ int main(int argc, char** argv)
getchar(); getchar();
mal_device_uninit(&device); mal_device_uninit(&device);
mal_context_uninit(&context);
drwav_uninit(&wav); drwav_uninit(&wav);
return 0; return 0;
......
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