Commit cba66e9b authored by David Reid's avatar David Reid

API CHANGE: Pass config properties to mal_device_init() via a structure.

Rationale:
1) The number of parameters is just getting too much.
2) It makes it a bit easier to add new configuration properties in the
   future. In particular, there's a chance there will be support added
   for backend-specific properties.
parent 2fad2359
......@@ -47,9 +47,16 @@ mal_uint32 on_send_frames(mal_device* pDevice, mal_uint32 frameCount, void* pSam
int main()
{
mal_device_config config;
config.format = mal_format_f32;
config.channels = 2;
config.sampleRate = 48000;
config.bufferSizeInFrames = 0; // Use default.
config.periods = 0; // Use default.
printf("Recording...\n");
mal_device captureDevice;
if (mal_device_init(&captureDevice, mal_device_type_capture, NULL, mal_format_f32, 2, 48000, 0, 0, NULL)) {
if (mal_device_init(&captureDevice, mal_device_type_capture, NULL, &config, NULL, NULL)) {
printf("Failed to initialize capture device.\n");
return -2;
}
......@@ -64,7 +71,7 @@ int main()
printf("Playing...\n");
mal_device playbackDevice;
if (mal_device_init(&playbackDevice, mal_device_type_playback, NULL, mal_format_f32, 2, 48000, 0, 0, NULL)) {
if (mal_device_init(&playbackDevice, mal_device_type_playback, NULL, &config, NULL, NULL)) {
printf("Failed to initialize playback device.\n");
return -3;
}
......
......@@ -31,8 +31,15 @@ int main(int argc, char** argv)
}
// In this example we use the default playback device with a default buffer size and period count.
mal_device_config config;
config.format = mal_format_f32;
config.channels = wav.channels;
config.sampleRate = wav.sampleRate;
config.bufferSizeInFrames = 0; // Use default.
config.periods = 0; // Use default.
mal_device device;
if (mal_device_init(&device, mal_device_type_playback, NULL, mal_format_f32, wav.channels, wav.sampleRate, 0, 0, NULL) != MAL_SUCCESS) {
if (mal_device_init(&device, mal_device_type_playback, NULL, &config, NULL, NULL) != MAL_SUCCESS) {
printf("Failed to open playback device.");
drwav_uninit(&wav);
return -3;
......
This diff is collapsed.
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