Go to the documentation of this file.
26 #define MINIAUDIO_IMPLEMENTATION
27 #include "../miniaudio.h"
30 #include <emscripten.h>
38 #define MA_SUPPORT_SDL
44 #if defined(MA_SUPPORT_SDL) && !defined(MA_NO_SDL) && (!defined(MA_ENABLE_ONLY_SPECIFIC_BACKENDS) || defined(MA_ENABLE_SDL))
52 #if defined(MA_SUPPORT_SDL)
70 #if defined(MA_SUPPORT_SDL)
81 #if defined(MA_HAS_SDL)
83 #ifdef MA_NO_RUNTIME_LINKING
86 #if !__has_include(<SDL/SDL_audio.h>)
90 #if !__has_include(<SDL2/SDL_audio.h>)
99 #if defined(MA_HAS_SDL)
100 #define MA_SDL_INIT_AUDIO 0x00000010
101 #define MA_AUDIO_U8 0x0008
102 #define MA_AUDIO_S16 0x8010
103 #define MA_AUDIO_S32 0x8020
104 #define MA_AUDIO_F32 0x8120
105 #define MA_SDL_AUDIO_ALLOW_FREQUENCY_CHANGE 0x00000001
106 #define MA_SDL_AUDIO_ALLOW_FORMAT_CHANGE 0x00000002
107 #define MA_SDL_AUDIO_ALLOW_CHANNELS_CHANGE 0x00000004
108 #define MA_SDL_AUDIO_ALLOW_ANY_CHANGE (MA_SDL_AUDIO_ALLOW_FREQUENCY_CHANGE | MA_SDL_AUDIO_ALLOW_FORMAT_CHANGE | MA_SDL_AUDIO_ALLOW_CHANNELS_CHANGE)
111 #ifdef MA_NO_RUNTIME_LINKING
112 #define SDL_MAIN_HANDLED
116 #include <SDL2/SDL.h>
145 typedef const char* (* MA_PFN_SDL_GetAudioDeviceName)(
int index,
int iscapture);
189 for (iDevice = 0; iDevice < deviceCount; ++iDevice) {
211 for (iDevice = 0; iDevice < deviceCount; ++iDevice) {
237 #if !defined(__EMSCRIPTEN__)
241 const char* pDeviceName;
246 if (pDeviceID ==
NULL) {
273 #if defined(__EMSCRIPTEN__)
292 if (pDeviceID !=
NULL) {
297 if (tempDeviceID == 0) {
343 const char* pDeviceName;
386 desiredSpec.freq = (int)pDescriptor->
sampleRate;
391 desiredSpec.userdata = pDeviceEx;
394 if (desiredSpec.format == 0) {
416 pDescriptor->
channels = obtainedSpec.channels;
533 #ifndef MA_NO_RUNTIME_LINKING
536 const char* pSDLNames[] = {
539 #elif defined(__APPLE__)
540 "SDL2.framework/SDL2"
551 for (iName = 0; iName <
ma_countof(pSDLNames); iName += 1) {
581 if (resultSDL != 0) {
620 #if !defined(MA_NO_SDL)
636 #define DEVICE_FORMAT ma_format_f32
637 #define DEVICE_CHANNELS 2
638 #define DEVICE_SAMPLE_RATE 48000
724 #ifdef __EMSCRIPTEN__
725 emscripten_set_main_loop(main_loop__em, 0, 1);
727 printf(
"Press Enter to quit...\n");
static MA_INLINE ma_uint32 ma_get_bytes_per_frame(ma_format format, ma_uint32 channels)
const typedef char *(* MA_PFN_SDL_GetAudioDeviceName)(int index, int iscapture)
int main(int argc, char **argv)
@ ma_device_type_loopback
#define MA_DEVICE_TYPE_NOT_SUPPORTED
#define DEVICE_SAMPLE_RATE
void ma_device_uninit(ma_device *pDevice)
ma_result ma_device_start(ma_device *pDevice)
ma_uint32 internalChannels
int(* MA_PFN_SDL_InitSubSystem)(ma_uint32 flags)
#define MA_SDL_AUDIO_ALLOW_ANY_CHANGE
struct MA_SDL_AudioSpec MA_SDL_AudioSpec
ma_device_type deviceType
void(* MA_PFN_SDL_QuitSubSystem)(ma_uint32 flags)
union ma_device_id::@169 custom
#define MA_FAILED_TO_OPEN_BACKEND_DEVICE
MA_SDL_AudioCallback callback
ma_proc SDL_QuitSubSystem
ma_uint32 nativeDataFormatCount
ma_result(* onContextGetDeviceInfo)(ma_context *pContext, ma_device_type deviceType, const ma_device_id *pDeviceID, ma_device_info *pDeviceInfo)
@ ma_device_type_playback
ma_result(* onContextInit)(ma_context *pContext, const ma_context_config *pConfig, ma_backend_callbacks *pCallbacks)
ma_channel channelMap[MA_MAX_CHANNELS]
ma_uint16 MA_SDL_AudioFormat
void(* MA_PFN_SDL_CloseAudioDevice)(MA_SDL_AudioDeviceID dev)
ma_result(* onDeviceUninit)(ma_device *pDevice)
ma_device_callback_proc dataCallback
void ma_audio_callback_playback__sdl(void *pUserData, ma_uint8 *pBuffer, int bufferSizeInBytes)
static ma_result ma_context_uninit__sdl(ma_context *pContext)
ma_format ma_format_from_sdl(MA_SDL_AudioFormat format)
ma_bool32(* ma_enum_devices_callback_proc)(ma_context *pContext, ma_device_type deviceType, const ma_device_info *pInfo, void *pUserData)
void data_callback(ma_device *pDevice, void *pOutput, const void *pInput, ma_uint32 frameCount)
static ma_result ma_context_get_device_info__sdl(ma_context *pContext, ma_device_type deviceType, const ma_device_id *pDeviceID, ma_device_info *pDeviceInfo)
#define MA_SDL_INIT_AUDIO
struct ma_device_config::@98 capture
ma_performance_profile performanceProfile
static ma_result ma_device_init_internal__sdl(ma_device_ex *pDeviceEx, const ma_device_config *pConfig, ma_device_descriptor *pDescriptor)
ma_result ma_context_uninit(ma_context *pContext)
ma_context_config ma_context_config_init(void)
const ma_device_id * pDeviceID
void(* MA_PFN_SDL_PauseAudioDevice)(MA_SDL_AudioDeviceID dev, int pause_on)
ma_proc SDL_InitSubSystem
ma_uint32 periodSizeInFrames
struct ma_context_ex::@133 sdl
ma_result ma_waveform_init(const ma_waveform_config *pConfig, ma_waveform *pWaveform)
static ma_result ma_context_init__custom_loader(ma_context *pContext, const ma_context_config *pConfig, ma_backend_callbacks *pCallbacks)
MA_SDL_AudioFormat format
ma_result(* onContextUninit)(ma_context *pContext)
void ma_get_standard_channel_map(ma_standard_channel_map standardChannelMap, ma_uint32 channels, ma_channel channelMap[MA_MAX_CHANNELS])
ma_proc SDL_OpenAudioDevice
ma_waveform_config ma_waveform_config_init(ma_format format, ma_uint32 channels, ma_uint32 sampleRate, ma_waveform_type type, double amplitude, double frequency)
ma_result(* onContextEnumerateDevices)(ma_context *pContext, ma_enum_devices_callback_proc callback, void *pUserData)
static ma_result ma_device_start__sdl(ma_device *pDevice)
struct ma_device_info::@170 nativeDataFormats[/*ma_format_count *ma_standard_sample_rate_count *MA_MAX_CHANNELS */64]
struct ma_device_ex::@134 sdl
ma_device_config ma_device_config_init(ma_device_type deviceType)
static ma_result ma_device_init__sdl(ma_device *pDevice, const ma_device_config *pConfig, ma_device_descriptor *pDescriptorPlayback, ma_device_descriptor *pDescriptorCapture)
@ ma_standard_channel_map_default
#define MA_LOG_LEVEL_ERROR
ma_result(* onDeviceStart)(ma_device *pDevice)
int(* MA_PFN_SDL_GetNumAudioDevices)(int iscapture)
ma_uint64 ma_waveform_read_pcm_frames(ma_waveform *pWaveform, void *pFramesOut, ma_uint64 frameCount)
MA_SDL_AudioDeviceID(* MA_PFN_SDL_OpenAudioDevice)(const char *device, int iscapture, const MA_SDL_AudioSpec *desired, MA_SDL_AudioSpec *obtained, int allowed_changes)
static ma_result ma_device_stop__sdl(ma_device *pDevice)
ma_result(* onDeviceStop)(ma_device *pDevice)
ma_result ma_device_init(ma_context *pContext, const ma_device_config *pConfig, ma_device *pDevice)
struct ma_device::@116 capture
ma_result ma_context_init(const ma_backend backends[], ma_uint32 backendCount, const ma_context_config *pConfig, ma_context *pContext)
ma_uint32 MA_SDL_AudioDeviceID
ma_proc SDL_GetNumAudioDevices
MA_SDL_AudioFormat ma_format_to_sdl(ma_format format)
ma_proc SDL_CloseAudioDevice
ma_result(* onDeviceInit)(ma_device *pDevice, const ma_device_config *pConfig, ma_device_descriptor *pDescriptorPlayback, ma_device_descriptor *pDescriptorCapture)
static ma_result ma_device_uninit__sdl(ma_device *pDevice)
ma_proc SDL_PauseAudioDevice
ma_backend_callbacks custom
static ma_result ma_context_init__sdl(ma_context *pContext, const ma_context_config *pConfig, ma_backend_callbacks *pCallbacks)
ma_proc SDL_GetAudioDeviceName
void(* MA_SDL_AudioCallback)(void *userdata, ma_uint8 *stream, int len)
static ma_result ma_context_enumerate_devices__sdl(ma_context *pContext, ma_enum_devices_callback_proc callback, void *pUserData)
struct ma_device_config::@97 playback
void ma_audio_callback_capture__sdl(void *pUserData, ma_uint8 *pBuffer, int bufferSizeInBytes)
struct ma_device::@115 playback