mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-21 15:56:58 +02:00
API CHANGE: Add device callbacks to mal_device_config.
Rationale: 1) It allows the callbacks to be set at initialization time which feels a bit more intuitive to me. 2) It avoids the need to call mal_device_set_send_callback(), etc. 3) It's a bit more consistent with the onLog callback. Previously, onLog would be passed to mal_device_init(), whereas onSend, etc were set with mal_device_set_send_callback(), etc. which feels needlessly inconsistent.
This commit is contained in:
@@ -37,21 +37,17 @@ int main(int argc, char** argv)
|
||||
config.sampleRate = wav.sampleRate;
|
||||
config.bufferSizeInFrames = 0; // Use default.
|
||||
config.periods = 0; // Use default.
|
||||
config.onRecvCallback = NULL; // Not used for playback.
|
||||
config.onSendCallback = on_send_frames_to_device;
|
||||
config.onStopCallback = NULL;
|
||||
config.onLogCallback = NULL;
|
||||
|
||||
mal_device device;
|
||||
if (mal_device_init(&device, mal_device_type_playback, NULL, &config, NULL, NULL) != MAL_SUCCESS) {
|
||||
if (mal_device_init(&device, mal_device_type_playback, NULL, &config, &wav) != MAL_SUCCESS) {
|
||||
printf("Failed to open playback device.");
|
||||
drwav_uninit(&wav);
|
||||
return -3;
|
||||
}
|
||||
|
||||
// The pUserData member of mal_device is reserved for you.
|
||||
device.pUserData = &wav;
|
||||
|
||||
// This is the callback for sending data to a playback device when it needs more. Make sure
|
||||
// it's set before playing the device otherwise you'll end up with silence for the first
|
||||
// bunch of frames.
|
||||
mal_device_set_send_callback(&device, on_send_frames_to_device);
|
||||
mal_device_start(&device);
|
||||
|
||||
printf("Press Enter to quit...");
|
||||
|
||||
Reference in New Issue
Block a user