config.playback.format = ma_format_f32; // Set to ma_format_unknown to use the device's native format.
config.playback.channels = MY_CHANNEL_COUNT;
config.playback.channels = 2; // Set to 0 to use the device's native channel count.
config.sampleRate = MY_SAMPLE_RATE;
config.sampleRate = 48000; // Set to 0 to use the device's native sample rate.
config.dataCallback = data_callback;
config.dataCallback = data_callback; // This function will be called when miniaudio needs more data.
config.pUserData = pMyCustomData; // Can be accessed from the device object (device.pUserData).
config.pUserData = pMyCustomData; // Can be accessed from the device object (device.pUserData).
ma_device device;
ma_device device;
if (ma_device_init(NULL, &config, &device) != MA_SUCCESS) {
if (ma_device_init(NULL, &config, &device) != MA_SUCCESS) {
... An error occurred ...
return -1; // Failed to initialize the device.
}
}
ma_device_start(&device); // The device is sleeping by default so you'll need to start it manually.
ma_device_start(&device); // The device is sleeping by default so you'll need to start it manually.
...
// Do something here. Probably your program's main loop.
ma_device_uninit(&device); // This will stop the device so no need to do that manually.
ma_device_uninit(&device); // This will stop the device so no need to do that manually.
return 0;
}
```
```
In the example above, `data_callback()` is where audio data is written and read from the device. The idea is in playback mode you cause sound to be emitted
In the example above, `data_callback()` is where audio data is written and read from the device. The idea is in playback mode you cause sound to be emitted