248248 < div style ="background-color:#fff; padding-bottom:0em; border-top:solid 1px #003800; background-color:#eee; ">
249249< table border ="0 " style ="margin:0 auto; width:100%; border-collapse:collapse; border:solid 0px #000; table-layout:fixed; "> < tr >
250250< td valign ="top " style ="width:20em; padding:0; margin:0; border-right:solid 0px #000; "> < div style ="position:relative; height:100%; width:100%; border:solid 0px #000; padding:0; margin:0; ">
251- < a href ="../index.html " class ="doc-navigation "> Documentation Home</ a > < a href ="../manual/index.html " class ="doc-navigation "> Programming Manual</ a > < a href ="index.html " class ="doc-navigation "> Examples</ a > < a href ="custom_backend.html " class ="doc-navigation doc-navigation-l1 doc-navigation-active "> Custom Backend</ a > < a href ="custom_decoder.html " class ="doc-navigation doc-navigation-l1 "> Custom Decoder</ a > < a href ="custom_decoder_engine.html " class ="doc-navigation doc-navigation-l1 "> Custom Decoder Engine</ a > < a href ="data_source_chaining.html " class ="doc-navigation doc-navigation-l1 "> Data Source Chaining</ a > < a href ="duplex_effect.html " class ="doc-navigation doc-navigation-l1 "> Duplex Effect</ a > < a href ="engine_advanced.html " class ="doc-navigation doc-navigation-l1 "> Engine Advanced</ a > < a href ="engine_effects.html " class ="doc-navigation doc-navigation-l1 "> Engine Effects</ a > < a href ="engine_hello_world.html " class ="doc-navigation doc-navigation-l1 "> Engine Hello World</ a > < a href ="engine_sdl.html " class ="doc-navigation doc-navigation-l1 "> Engine Sdl</ a > < a href ="engine_steamaudio.html " class ="doc-navigation doc-navigation-l1 "> Engine Steamaudio</ a > < a href ="hilo_interop.html " class ="doc-navigation doc-navigation-l1 "> Hilo Interop</ a > < a href ="node_graph.html " class ="doc-navigation doc-navigation-l1 "> Node Graph</ a > < a href ="resource_manager.html " class ="doc-navigation doc-navigation-l1 "> Resource Manager</ a > < a href ="resource_manager_advanced.html " class ="doc-navigation doc-navigation-l1 "> Resource Manager Advanced</ a > < a href ="simple_capture.html " class ="doc-navigation doc-navigation-l1 "> Simple Capture</ a > < a href ="simple_duplex.html " class ="doc-navigation doc-navigation-l1 "> Simple Duplex</ a > < a href ="simple_enumeration.html " class ="doc-navigation doc-navigation-l1 "> Simple Enumeration</ a > < a href ="simple_loopback.html " class ="doc-navigation doc-navigation-l1 "> Simple Loopback</ a > < a href ="simple_looping.html " class ="doc-navigation doc-navigation-l1 "> Simple Looping</ a > < a href ="simple_mixing.html " class ="doc-navigation doc-navigation-l1 "> Simple Mixing</ a > < a href ="simple_playback.html " class ="doc-navigation doc-navigation-l1 "> Simple Playback</ a > < a href ="simple_playback_sine.html " class ="doc-navigation doc-navigation-l1 "> Simple Playback Sine</ a > < a href ="simple_playback_sine.html " class ="doc-navigation doc-navigation-l1 "> Simple Playback Sine</ a > < a href ="../api/index.html " class ="doc-navigation " style ="border-bottom:none; "> API Reference</ a > </ div > </ td > < td valign ="top " style ="padding:1em; border-left:solid 1px #bbb; ">
251+ < a href ="../index.html " class ="doc-navigation "> Documentation Home</ a > < a href ="../manual/index.html " class ="doc-navigation "> Programming Manual</ a > < a href ="index.html " class ="doc-navigation "> Examples</ a > < a href ="custom_backend.html " class ="doc-navigation doc-navigation-l1 doc-navigation-active "> Custom Backend</ a > < a href ="custom_decoder.html " class ="doc-navigation doc-navigation-l1 "> Custom Decoder</ a > < a href ="custom_decoder_engine.html " class ="doc-navigation doc-navigation-l1 "> Custom Decoder Engine</ a > < a href ="data_source_chaining.html " class ="doc-navigation doc-navigation-l1 "> Data Source Chaining</ a > < a href ="duplex_effect.html " class ="doc-navigation doc-navigation-l1 "> Duplex Effect</ a > < a href ="engine_advanced.html " class ="doc-navigation doc-navigation-l1 "> Engine Advanced</ a > < a href ="engine_effects.html " class ="doc-navigation doc-navigation-l1 "> Engine Effects</ a > < a href ="engine_hello_world.html " class ="doc-navigation doc-navigation-l1 "> Engine Hello World</ a > < a href ="engine_sdl.html " class ="doc-navigation doc-navigation-l1 "> Engine Sdl</ a > < a href ="engine_steamaudio.html " class ="doc-navigation doc-navigation-l1 "> Engine Steamaudio</ a > < a href ="hilo_interop.html " class ="doc-navigation doc-navigation-l1 "> Hilo Interop</ a > < a href ="node_graph.html " class ="doc-navigation doc-navigation-l1 "> Node Graph</ a > < a href ="resource_manager.html " class ="doc-navigation doc-navigation-l1 "> Resource Manager</ a > < a href ="resource_manager_advanced.html " class ="doc-navigation doc-navigation-l1 "> Resource Manager Advanced</ a > < a href ="simple_capture.html " class ="doc-navigation doc-navigation-l1 "> Simple Capture</ a > < a href ="simple_duplex.html " class ="doc-navigation doc-navigation-l1 "> Simple Duplex</ a > < a href ="simple_enumeration.html " class ="doc-navigation doc-navigation-l1 "> Simple Enumeration</ a > < a href ="simple_loopback.html " class ="doc-navigation doc-navigation-l1 "> Simple Loopback</ a > < a href ="simple_looping.html " class ="doc-navigation doc-navigation-l1 "> Simple Looping</ a > < a href ="simple_mixing.html " class ="doc-navigation doc-navigation-l1 "> Simple Mixing</ a > < a href ="simple_playback.html " class ="doc-navigation doc-navigation-l1 "> Simple Playback</ a > < a href ="simple_playback_sine.html " class ="doc-navigation doc-navigation-l1 "> Simple Playback Sine</ a > < a href ="simple_playback_sine.html " class ="doc-navigation doc-navigation-l1 "> Simple Playback Sine</ a > < a href ="simple_spatialization.html " class ="doc-navigation doc-navigation-l1 "> Simple Spatialization</ a > < a href ="../api/index.html " class ="doc-navigation " style ="border-bottom:none; "> API Reference</ a > </ div > </ td > < td valign ="top " style ="padding:1em; border-left:solid 1px #bbb; ">
252252< h1 > Custom Backend</ h1 > < p >
253253This example show how a custom backend can be implemented.
254254</ p >
@@ -439,9 +439,6 @@ <h1>Custom Backend</h1><p>
439439 < span style ="color:#0099cc "> ma_bool32</ span > cbResult;
440440 < span style ="color:#0033ff "> int</ span > iDevice;
441441
442- MA_ASSERT(pContext != NULL);
443- MA_ASSERT(callback != NULL);
444-
445442 < span style ="color:#009900 "> /* Playback */</ span >
446443 < span style ="color:#0033ff "> if</ span > (!isTerminated) {
447444 < span style ="color:#0033ff "> int</ span > deviceCount = ((MA_PFN_SDL_GetNumAudioDevices)pContextEx->sdl.SDL_GetNumAudioDevices)(0);
@@ -500,8 +497,6 @@ <h1>Custom Backend</h1><p>
500497 < span style ="color:#0033ff "> const</ span > < span style ="color:#0033ff "> char</ span > * pDeviceName;
501498< span style ="color:#666666 "> #endif</ span >
502499
503- MA_ASSERT(pContext != NULL);
504-
505500 < span style ="color:#0033ff "> if</ span > (pDeviceID == NULL) {
506501 < span style ="color:#0033ff "> if</ span > (deviceType == ma_device_type_playback) {
507502 pDeviceInfo->id.custom.< span style ="color:#0033ff "> i</ span > = 0;
@@ -525,7 +520,7 @@ <h1>Custom Backend</h1><p>
525520 of the device's _actual_ ideal format.
526521
527522 Note: With Emscripten, it looks like non-zero values need to be specified for desiredSpec. Whatever is specified in
528- desiredSpec will be used by SDL since it uses it just does it's own format conversion internally. Therefore, from what
523+ desiredSpec will be used by SDL since it uses it just does its own format conversion internally. Therefore, from what
529524 I can tell, there's no real way to know the device's actual format which means I'm just going to fall back to the full
530525 range of channels and sample rates on Emscripten builds.
531526 */</ span >
@@ -581,17 +576,13 @@ <h1>Custom Backend</h1><p>
581576{
582577 ma_device_ex* pDeviceEx = (ma_device_ex*)pUserData;
583578
584- MA_ASSERT(pDeviceEx != NULL);
585-
586579 ma_device_handle_backend_data_callback((< span style ="color:#0099cc "> ma_device</ span > *)pDeviceEx, NULL, pBuffer, (< span style ="color:#0099cc "> ma_uint32</ span > )bufferSizeInBytes / ma_get_bytes_per_frame(pDeviceEx->device.capture.internalFormat, pDeviceEx->device.capture.internalChannels));
587580}
588581
589582< span style ="color:#0033ff "> void</ span > ma_audio_callback_playback__sdl(< span style ="color:#0033ff "> void</ span > * pUserData, < span style ="color:#0099cc "> ma_uint8</ span > * pBuffer, < span style ="color:#0033ff "> int</ span > bufferSizeInBytes)
590583{
591584 ma_device_ex* pDeviceEx = (ma_device_ex*)pUserData;
592585
593- MA_ASSERT(pDeviceEx != NULL);
594-
595586 ma_device_handle_backend_data_callback((< span style ="color:#0099cc "> ma_device</ span > *)pDeviceEx, pBuffer, NULL, (< span style ="color:#0099cc "> ma_uint32</ span > )bufferSizeInBytes / ma_get_bytes_per_frame(pDeviceEx->device.playback.internalFormat, pDeviceEx->device.playback.internalChannels));
596587}
597588
@@ -603,9 +594,6 @@ <h1>Custom Backend</h1><p>
603594 < span style ="color:#0033ff "> const</ span > < span style ="color:#0033ff "> char</ span > * pDeviceName;
604595 < span style ="color:#0033ff "> int</ span > deviceID;
605596
606- MA_ASSERT(pDeviceEx != NULL);
607- MA_ASSERT(pDescriptor != NULL);
608-
609597 < span style ="color:#009900 "> /*
610598 SDL is a little bit awkward with specifying the buffer size, You need to specify the size of the buffer in frames, but since we may
611599 have requested a period size in milliseconds we'll need to convert, which depends on the sample rate. But there's a possibility that
@@ -689,8 +677,6 @@ <h1>Custom Backend</h1><p>
689677 ma_context_ex* pContextEx = (ma_context_ex*)pDevice->pContext;
690678 < span style ="color:#0099cc "> ma_result</ span > result;
691679
692- MA_ASSERT(pDevice != NULL);
693-
694680 < span style ="color:#009900 "> /* SDL does not support loopback mode, so must return MA_DEVICE_TYPE_NOT_SUPPORTED if it's requested. */</ span >
695681 < span style ="color:#0033ff "> if</ span > (pConfig->deviceType == ma_device_type_loopback) {
696682 < span style ="color:#0033ff "> return</ span > MA_DEVICE_TYPE_NOT_SUPPORTED;
@@ -722,8 +708,6 @@ <h1>Custom Backend</h1><p>
722708 ma_device_ex* pDeviceEx = (ma_device_ex*)pDevice;
723709 ma_context_ex* pContextEx = (ma_context_ex*)pDevice->pContext;
724710
725- MA_ASSERT(pDevice != NULL);
726-
727711 < span style ="color:#0033ff "> if</ span > (pDevice->< span style ="color:#0033ff "> type</ span > == ma_device_type_capture || pDevice->< span style ="color:#0033ff "> type</ span > == ma_device_type_duplex) {
728712 ((MA_PFN_SDL_CloseAudioDevice)pContextEx->sdl.SDL_CloseAudioDevice)(pDeviceEx->sdl.deviceIDCapture);
729713 }
@@ -740,8 +724,6 @@ <h1>Custom Backend</h1><p>
740724 ma_device_ex* pDeviceEx = (ma_device_ex*)pDevice;
741725 ma_context_ex* pContextEx = (ma_context_ex*)pDevice->pContext;
742726
743- MA_ASSERT(pDevice != NULL);
744-
745727 < span style ="color:#0033ff "> if</ span > (pDevice->< span style ="color:#0033ff "> type</ span > == ma_device_type_capture || pDevice->< span style ="color:#0033ff "> type</ span > == ma_device_type_duplex) {
746728 ((MA_PFN_SDL_PauseAudioDevice)pContextEx->sdl.SDL_PauseAudioDevice)(pDeviceEx->sdl.deviceIDCapture, 0);
747729 }
@@ -758,8 +740,6 @@ <h1>Custom Backend</h1><p>
758740 ma_device_ex* pDeviceEx = (ma_device_ex*)pDevice;
759741 ma_context_ex* pContextEx = (ma_context_ex*)pDevice->pContext;
760742
761- MA_ASSERT(pDevice != NULL);
762-
763743 < span style ="color:#0033ff "> if</ span > (pDevice->< span style ="color:#0033ff "> type</ span > == ma_device_type_capture || pDevice->< span style ="color:#0033ff "> type</ span > == ma_device_type_duplex) {
764744 ((MA_PFN_SDL_PauseAudioDevice)pContextEx->sdl.SDL_PauseAudioDevice)(pDeviceEx->sdl.deviceIDCapture, 1);
765745 }
@@ -775,8 +755,6 @@ <h1>Custom Backend</h1><p>
775755{
776756 ma_context_ex* pContextEx = (ma_context_ex*)pContext;
777757
778- MA_ASSERT(pContext != NULL);
779-
780758 ((MA_PFN_SDL_QuitSubSystem)pContextEx->sdl.SDL_QuitSubSystem)(MA_SDL_INIT_AUDIO);
781759
782760 < span style ="color:#009900 "> /* Close the handle to the SDL shared object last. */</ span >
@@ -804,8 +782,6 @@ <h1>Custom Backend</h1><p>
804782< span style ="color:#666666 "> #endif</ span >
805783 };
806784
807- MA_ASSERT(pContext != NULL);
808-
809785 (< span style ="color:#0033ff "> void</ span > )pConfig;
810786
811787 < span style ="color:#009900 "> /* Check if we have SDL2 installed somewhere. If not it's not usable and we need to abort. */</ span >
@@ -900,15 +876,8 @@ <h1>Custom Backend</h1><p>
900876
901877< span style ="color:#0033ff "> void</ span > data_callback(< span style ="color:#0099cc "> ma_device</ span > * pDevice, < span style ="color:#0033ff "> void</ span > * pOutput, < span style ="color:#0033ff "> const</ span > < span style ="color:#0033ff "> void</ span > * pInput, < span style ="color:#0099cc "> ma_uint32</ span > frameCount)
902878{
903- MA_ASSERT(pDevice->playback.channels == DEVICE_CHANNELS);
904-
905879 < span style ="color:#0033ff "> if</ span > (pDevice->< span style ="color:#0033ff "> type</ span > == ma_device_type_playback) {
906- < span style ="color:#0099cc "> ma_waveform</ span > * pSineWave;
907-
908- pSineWave = (< span style ="color:#0099cc "> ma_waveform</ span > *)pDevice->pUserData;
909- MA_ASSERT(pSineWave != NULL);
910-
911- ma_waveform_read_pcm_frames(pSineWave, pOutput, frameCount, NULL);
880+ ma_waveform_read_pcm_frames((< span style ="color:#0099cc "> ma_waveform</ span > *)pDevice->pUserData, pOutput, frameCount, NULL);
912881 }
913882
914883 < span style ="color:#0033ff "> if</ span > (pDevice->< span style ="color:#0033ff "> type</ span > == ma_device_type_duplex) {
@@ -996,7 +965,8 @@ <h1>Custom Backend</h1><p>
996965 (< span style ="color:#0033ff "> void</ span > )argv;
997966
998967 < span style ="color:#0033ff "> return</ span > 0;
999- }</ pre > </ div > </ td >
968+ }
969+ </ pre > </ div > </ td >
1000970</ tr > </ table >
1001971 </ div >
1002972 < table style ="margin:0 auto; padding:1em 0px; text-align:center; ">
@@ -1009,7 +979,7 @@ <h1>Custom Backend</h1><p>
1009979 </ table >
1010980
1011981 < div style ="color:#e0d7cf; font-size:9pt; padding:2em 0px; text-align:center; ">
1012- Copyright © 2023 David Reid< br />
982+ Copyright © 2025 David Reid< br />
1013983 Developed by David Reid -
< a class ="
footer-link "
href ="
mailto:[email protected] "
> [email protected] </ a > 1014984 </ div >
1015985</ body >
0 commit comments