Commit cdc49541 authored by David Reid's avatar David Reid

API CHANGE: Move pUserData from device_init() to device_config_init().

This change makes it consistent with mal_pcm_converter, mal_src, etc.
parent e762208c
......@@ -102,10 +102,11 @@ int main(int argc, char** argv)
decoder.outputFormat,
decoder.outputChannels,
decoder.outputSampleRate,
on_send_frames_to_device);
on_send_frames_to_device,
&decoder);
mal_device device;
if (mal_device_init(NULL, mal_device_type_playback, NULL, &config, &decoder, &device) != MAL_SUCCESS) {
if (mal_device_init(NULL, mal_device_type_playback, NULL, &config, &device) != MAL_SUCCESS) {
printf("Failed to open playback device.\n");
mal_decoder_uninit(&decoder);
return -3;
......
......@@ -91,9 +91,9 @@ int main(int argc, char** argv)
mal_backend_pulseaudio,
mal_backend_alsa,
mal_backend_jack,
mal_backend_aaudio
mal_backend_opensl,
mal_backend_openal,
mal_backend_sdl,
mal_backend_webaudio,
mal_backend_null // Lowest priority.
};
......@@ -134,7 +134,7 @@ int main(int argc, char** argv)
// initialize a config object called mal_device_config_init(). There are an additional two helper APIs to make
// it easy for you to initialize playback or capture configs specifically: mal_device_config_init_playback()
// and mal_device_config_init_capture().
mal_device_config deviceConfig = mal_device_config_init(mal_format_s16, 2, 48000, NULL, on_send_frames_to_device);
mal_device_config deviceConfig = mal_device_config_init(mal_format_s16, 2, 48000, NULL, on_send_frames_to_device, NULL);
// Applications can specify a callback for when a device is stopped.
deviceConfig.onStopCallback = on_device_stop;
......@@ -174,7 +174,7 @@ int main(int argc, char** argv)
#endif
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, &playbackDevice) != MAL_SUCCESS) {
printf("Failed to initialize playback device.\n");
mal_context_uninit(&context);
return -7;
......
......@@ -53,11 +53,11 @@ int main()
return -1;
}
mal_device_config config = mal_device_config_init(mal_format_s16, 2, 48000, on_recv_frames, on_send_frames);
mal_device_config config = mal_device_config_init(mal_format_s16, 2, 48000, on_recv_frames, on_send_frames, NULL);
printf("Recording...\n");
mal_device captureDevice;
if (mal_device_init(&context, mal_device_type_capture, NULL, &config, NULL, &captureDevice) != MAL_SUCCESS) {
if (mal_device_init(&context, mal_device_type_capture, NULL, &config, &captureDevice) != MAL_SUCCESS) {
mal_context_uninit(&context);
printf("Failed to initialize capture device.\n");
return -2;
......@@ -79,7 +79,7 @@ int main()
printf("Playing...\n");
mal_device playbackDevice;
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, &playbackDevice) != MAL_SUCCESS) {
mal_context_uninit(&context);
printf("Failed to initialize playback device.\n");
return -4;
......
......@@ -38,10 +38,11 @@ int main(int argc, char** argv)
decoder.outputFormat,
decoder.outputChannels,
decoder.outputSampleRate,
on_send_frames_to_device);
on_send_frames_to_device,
&decoder);
mal_device device;
if (mal_device_init(NULL, mal_device_type_playback, NULL, &config, &decoder, &device) != MAL_SUCCESS) {
if (mal_device_init(NULL, mal_device_type_playback, NULL, &config, &device) != MAL_SUCCESS) {
printf("Failed to open playback device.\n");
mal_decoder_uninit(&decoder);
return -3;
......
......@@ -34,9 +34,9 @@ int main(int argc, char** argv)
mal_sine_wave sineWave;
mal_sine_wave_init(0.2, 400, DEVICE_SAMPLE_RATE, &sineWave);
mal_device_config config = mal_device_config_init_playback(DEVICE_FORMAT, DEVICE_CHANNELS, DEVICE_SAMPLE_RATE, on_send_frames_to_device);
mal_device_config config = mal_device_config_init_playback(DEVICE_FORMAT, DEVICE_CHANNELS, DEVICE_SAMPLE_RATE, on_send_frames_to_device, &sineWave);
mal_device device;
if (mal_device_init(NULL, mal_device_type_playback, NULL, &config, &sineWave, &device) != MAL_SUCCESS) {
if (mal_device_init(NULL, mal_device_type_playback, NULL, &config, &device) != MAL_SUCCESS) {
printf("Failed to open playback device.\n");
return -4;
}
......
This diff is collapsed.
......@@ -52,12 +52,12 @@ mal_uint32 on_send_to_device__dithered(mal_device* pDevice, mal_uint32 frameCoun
int do_dithering_test()
{
mal_device_config config = mal_device_config_init_playback(mal_format_f32, 1, 0, on_send_to_device__original);
mal_device_config config = mal_device_config_init_playback(mal_format_f32, 1, 0, on_send_to_device__original, NULL);
mal_device device;
mal_result result;
// We first play the sound the way it's meant to be played.
result = mal_device_init(NULL, mal_device_type_playback, NULL, &config, NULL, &device);
result = mal_device_init(NULL, mal_device_type_playback, NULL, &config, &device);
if (result != MAL_SUCCESS) {
return -1;
}
......@@ -102,9 +102,9 @@ int do_dithering_test()
return -3;
}
config = mal_device_config_init_playback(converterOutConfig.formatOut, 1, 0, on_send_to_device__dithered);
config = mal_device_config_init_playback(converterOutConfig.formatOut, 1, 0, on_send_to_device__dithered, &converterOut);
result = mal_device_init(NULL, mal_device_type_playback, NULL, &config, &converterOut, &device);
result = mal_device_init(NULL, mal_device_type_playback, NULL, &config, &device);
if (result != MAL_SUCCESS) {
return -1;
}
......
......@@ -2289,14 +2289,14 @@ int do_playback_test(mal_backend backend)
printf(" Opening Device... ");
{
mal_context_config contextConfig = mal_context_config_init(on_log);
mal_device_config deviceConfig = mal_device_config_init_default_playback(on_send__playback_test);
mal_device_config deviceConfig = mal_device_config_init_default_playback(on_send__playback_test, &callbackData);
deviceConfig.onStopCallback = on_stop__playback_test;
#if defined(__EMSCRIPTEN__)
deviceConfig.format = mal_format_f32;
#endif
result = mal_device_init_ex(&backend, 1, &contextConfig, mal_device_type_playback, NULL, &deviceConfig, &callbackData, &device);
result = mal_device_init_ex(&backend, 1, &contextConfig, mal_device_type_playback, NULL, &deviceConfig, &device);
if (result == MAL_SUCCESS) {
printf("Done\n");
} else {
......
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