diff --git a/README.md b/README.md index bf617495..dc6bcac8 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Features - A simple build system. - It should Just Work out of the box, without the need to download and install any dependencies. - A simple API. -- Supports both playback and capture on all backends. +- Supports playback, capture and full-duplex. - Data conversion. - Sample format conversion, with optional dithering. - Sample rate conversion. @@ -74,15 +74,16 @@ Simple Playback Example #include -// 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) +void data_callback(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 frameCount) { mal_decoder* pDecoder = (mal_decoder*)pDevice->pUserData; if (pDecoder == NULL) { - return 0; + return; } - return (mal_uint32)mal_decoder_read_pcm_frames(pDecoder, frameCount, pSamples); + mal_decoder_read_pcm_frames(pDecoder, frameCount, pOutput); + + (void)pInput; } int main(int argc, char** argv) @@ -98,15 +99,16 @@ int main(int argc, char** argv) return -2; } - mal_device_config config = mal_device_config_init_playback( - decoder.outputFormat, - decoder.outputChannels, - decoder.outputSampleRate, - on_send_frames_to_device, - &decoder); + mal_device_config config = mal_device_config_init(mal_device_type_playback); + config.playback.pDeviceID = NULL; + config.playback.format = decoder.outputFormat; + config.playback.channels = decoder.outputChannels; + config.sampleRate = decoder.outputSampleRate; + config.dataCallback = data_callback; + config.pUserData = &decoder; mal_device device; - if (mal_device_init(NULL, mal_device_type_playback, NULL, &config, &device) != MAL_SUCCESS) { + if (mal_device_init(NULL, &config, &device) != MAL_SUCCESS) { printf("Failed to open playback device.\n"); mal_decoder_uninit(&decoder); return -3; @@ -126,7 +128,7 @@ int main(int argc, char** argv) mal_decoder_uninit(&decoder); return 0; -} +}} ``` diff --git a/examples/simple_playback.c b/examples/simple_playback.c index e1d755ac..89d99801 100644 --- a/examples/simple_playback.c +++ b/examples/simple_playback.c @@ -10,7 +10,7 @@ #include -void on_send_frames_to_device(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 frameCount) +void data_callback(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 frameCount) { mal_decoder* pDecoder = (mal_decoder*)pDevice->pUserData; if (pDecoder == NULL) { @@ -37,11 +37,11 @@ int main(int argc, char** argv) mal_device_config config = mal_device_config_init(mal_device_type_playback); config.playback.pDeviceID = NULL; - config.playback.format = decoder.outputFormat; - config.playback.channels = decoder.outputChannels; - config.sampleRate = decoder.outputSampleRate; - config.dataCallback = on_send_frames_to_device; - config.pUserData = &decoder; + config.playback.format = decoder.outputFormat; + config.playback.channels = decoder.outputChannels; + config.sampleRate = decoder.outputSampleRate; + config.dataCallback = data_callback; + config.pUserData = &decoder; mal_device device; if (mal_device_init(NULL, &config, &device) != MAL_SUCCESS) { diff --git a/mini_al.h b/mini_al.h index d9ecd162..2c5f4069 100644 --- a/mini_al.h +++ b/mini_al.h @@ -50,24 +50,29 @@ of capture. Playback Example ---------------- - mal_uint32 on_send_samples(mal_device* pDevice, mal_uint32 frameCount, void* pSamples) + void data_callback(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 frameCount) { - // This callback is set at initialization time and will be called when a playback device needs more - // data. You need to write as many frames as you can to pSamples (but no more than frameCount) and - // then return the number of frames you wrote. - // - // The user data (pDevice->pUserData) is set by mal_device_init(). - return (mal_uint32)mal_decoder_read_pcm_frames((mal_decoder*)pDevice->pUserData, frameCount, pSamples); + mal_decoder* pDecoder = (mal_decoder*)pDevice->pUserData; + if (pDecoder == NULL) { + return; + } + + mal_decoder_read_pcm_frames(pDecoder, frameCount, pOutput); } ... - mal_device_config config = mal_device_config_init_playback(decoder.outputFormat, decoder.outputChannels, decoder.outputSampleRate, on_send_frames_to_device, &decoder); + mal_device_config config = mal_device_config_init(mal_device_type_playback); + config.playback.pDeviceID = NULL; + config.playback.format = decoder.outputFormat; + config.playback.channels = decoder.outputChannels; + config.sampleRate = decoder.outputSampleRate; + config.dataCallback = data_callback; + config.pUserData = &decoder; mal_device device; - mal_result result = mal_device_init(NULL, mal_device_type_playback, NULL, &config, &device); - if (result != MAL_SUCCESS) { - return -1; + if (mal_device_init(NULL, &config, &device) != MAL_SUCCESS) { + ... An error occurred ... } mal_device_start(&device); // The device is sleeping by default so you'll need to start it manually. diff --git a/tests/mal_test_0.vcxproj b/tests/mal_test_0.vcxproj index 891c4f9d..8c020342 100644 --- a/tests/mal_test_0.vcxproj +++ b/tests/mal_test_0.vcxproj @@ -287,12 +287,12 @@ true - true - true - true - true - true - true + false + false + false + false + false + false true @@ -359,12 +359,12 @@ true - false - false - false - false - false - false + true + true + true + true + true + true true