From e00fe077f4b305aaea2f4bcd3d71d492fa9c0166 Mon Sep 17 00:00:00 2001 From: David Reid Date: Wed, 6 Mar 2019 20:55:51 +1000 Subject: [PATCH] "mal_" to "ma_". --- README.md | 60 +- examples/README.md | 2 +- examples/advanced_config.c | 98 +- examples/simple_capture.c | 20 +- examples/simple_enumeration.c | 20 +- examples/simple_playback.c | 28 +- examples/simple_playback_emscripten.c | 28 +- miniaudio.h | 17264 ++++++++++++------------ research/mal_resampler.h | 536 +- research/mal_ring_buffer.h | 398 +- research/tests/mal_resampler_test_0.c | 38 +- tests/README.md | 6 +- tests/mal_build_tests_bsd | 12 +- tests/mal_build_tests_emscripten.bat | 4 +- tests/mal_build_tests_linux | 14 +- tests/mal_build_tests_mac | 12 +- tests/mal_build_tests_rpi | 12 +- tests/mal_build_tests_win32.bat | 12 +- tests/mal_debug_playback.c | 82 +- tests/mal_dithering.c | 86 +- tests/mal_duplex.c | 36 +- tests/mal_no_device_io.c | 14 +- tests/mal_profiling.c | 644 +- tests/mal_resampling.c | 90 +- tests/mal_stop.c | 50 +- tests/mal_test_0.c | 1004 +- tests/mal_test_0.cpp | 2 +- tests/mal_test_0.vcxproj | 24 +- tests/mal_test_0.vcxproj.filters | 22 +- tests/mal_webaudio_test_0.html | 22 +- tools/mini_sigvis/mini_sigvis.h | 112 +- 31 files changed, 10376 insertions(+), 10376 deletions(-) diff --git a/README.md b/README.md index 21657bd3..aac5be29 100644 --- a/README.md +++ b/README.md @@ -74,14 +74,14 @@ Simple Playback Example #include -void data_callback(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 frameCount) +void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount) { - mal_decoder* pDecoder = (mal_decoder*)pDevice->pUserData; + ma_decoder* pDecoder = (ma_decoder*)pDevice->pUserData; if (pDecoder == NULL) { return; } - mal_decoder_read_pcm_frames(pDecoder, pOutput, frameCount); + ma_decoder_read_pcm_frames(pDecoder, pOutput, frameCount); (void)pInput; } @@ -93,38 +93,38 @@ int main(int argc, char** argv) return -1; } - mal_decoder decoder; - mal_result result = mal_decoder_init_file(argv[1], NULL, &decoder); + ma_decoder decoder; + ma_result result = ma_decoder_init_file(argv[1], NULL, &decoder); if (result != MA_SUCCESS) { return -2; } - mal_device_config config = mal_device_config_init(mal_device_type_playback); + ma_device_config config = ma_device_config_init(ma_device_type_playback); 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) != MA_SUCCESS) { + ma_device device; + if (ma_device_init(NULL, &config, &device) != MA_SUCCESS) { printf("Failed to open playback device.\n"); - mal_decoder_uninit(&decoder); + ma_decoder_uninit(&decoder); return -3; } - if (mal_device_start(&device) != MA_SUCCESS) { + if (ma_device_start(&device) != MA_SUCCESS) { printf("Failed to start playback device.\n"); - mal_device_uninit(&device); - mal_decoder_uninit(&decoder); + ma_device_uninit(&device); + ma_decoder_uninit(&decoder); return -4; } printf("Press Enter to quit..."); getchar(); - mal_device_uninit(&device); - mal_decoder_uninit(&decoder); + ma_device_uninit(&device); + ma_decoder_uninit(&decoder); return 0; } @@ -158,28 +158,28 @@ relevant backend library before the implementation of miniaudio, like so: #include "miniaudio.h" ``` -A decoder can be initialized from a file with `mal_decoder_init_file()`, a block of memory with -`mal_decoder_init_memory()`, or from data delivered via callbacks with `mal_decoder_init()`. Here +A decoder can be initialized from a file with `ma_decoder_init_file()`, a block of memory with +`ma_decoder_init_memory()`, or from data delivered via callbacks with `ma_decoder_init()`. Here is an example for loading a decoder from a file: ``` -mal_decoder decoder; -mal_result result = mal_decoder_init_file("MySong.mp3", NULL, &decoder); +ma_decoder decoder; +ma_result result = ma_decoder_init_file("MySong.mp3", NULL, &decoder); if (result != MA_SUCCESS) { return false; // An error occurred. } ... -mal_decoder_uninit(&decoder); +ma_decoder_uninit(&decoder); ``` -When initializing a decoder, you can optionally pass in a pointer to a `mal_decoder_config` object +When initializing a decoder, you can optionally pass in a pointer to a `ma_decoder_config` object (the `NULL` argument in the example above) which allows you to configure the output format, channel count, sample rate and channel map: ``` -mal_decoder_config config = mal_decoder_config_init(mal_format_f32, 2, 48000); +ma_decoder_config config = ma_decoder_config_init(ma_format_f32, 2, 48000); ``` When passing in NULL for this parameter, the output format will be the same as that defined by the @@ -188,13 +188,13 @@ decoding backend. Data is read from the decoder as PCM frames: ``` -mal_uint64 framesRead = mal_decoder_read_pcm_frames(pDecoder, pFrames, framesToRead); +ma_uint64 framesRead = ma_decoder_read_pcm_frames(pDecoder, pFrames, framesToRead); ``` You can also seek to a specific frame like so: ``` -mal_result result = mal_decoder_seek_to_pcm_frame(pDecoder, targetFrame); +ma_result result = ma_decoder_seek_to_pcm_frame(pDecoder, targetFrame); if (result != MA_SUCCESS) { return false; // An error occurred. } @@ -205,14 +205,14 @@ backend. This can be unnecessarily inefficient if the type is already known. In use the `_wav`, `_mp3`, etc. varients of the aforementioned initialization APIs: ``` -mal_decoder_init_wav() -mal_decoder_init_mp3() -mal_decoder_init_memory_wav() -mal_decoder_init_memory_mp3() -mal_decoder_init_file_wav() -mal_decoder_init_file_mp3() +ma_decoder_init_wav() +ma_decoder_init_mp3() +ma_decoder_init_memory_wav() +ma_decoder_init_memory_mp3() +ma_decoder_init_file_wav() +ma_decoder_init_file_mp3() etc. ``` -The `mal_decoder_init_file()` API will try using the file extension to determine which decoding +The `ma_decoder_init_file()` API will try using the file extension to determine which decoding backend to prefer. diff --git a/examples/README.md b/examples/README.md index 85bd1193..e29bad97 100644 --- a/examples/README.md +++ b/examples/README.md @@ -2,7 +2,7 @@ To compile these examples, cd into the "build" directory and run the applicable will be placed in the "bin" directory. cd build - ./mal_build_examples_linux + ./ma_build_examples_linux Then you can run executables like this: diff --git a/examples/advanced_config.c b/examples/advanced_config.c index 1d8ad577..51a59bca 100644 --- a/examples/advanced_config.c +++ b/examples/advanced_config.c @@ -3,14 +3,14 @@ #include -void log_callback(mal_context* pContext, mal_device* pDevice, mal_uint32 logLevel, const char* message) +void log_callback(ma_context* pContext, ma_device* pDevice, ma_uint32 logLevel, const char* message) { (void)pContext; (void)pDevice; - printf("miniaudio: [%s] %s\n", mal_log_level_to_string(logLevel), message); + printf("miniaudio: [%s] %s\n", ma_log_level_to_string(logLevel), message); } -void data_callback(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 frameCount) +void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount) { (void)pDevice; (void)pOutput; @@ -19,7 +19,7 @@ void data_callback(mal_device* pDevice, void* pOutput, const void* pInput, mal_u return; // Just output silence for this example. } -void stop_callback(mal_device* pDevice) +void stop_callback(ma_device* pDevice) { (void)pDevice; printf("Device stopped\n"); @@ -31,14 +31,14 @@ int main(int argc, char** argv) (void)argv; // When initializing a context, you can pass in an optional configuration object that allows you to control - // context-level configuration. The mal_context_config_init() function will initialize a config object with + // context-level configuration. The ma_context_config_init() function will initialize a config object with // common configuration settings, but you can set other members for more detailed control. - mal_context_config contextConfig = mal_context_config_init(); + ma_context_config contextConfig = ma_context_config_init(); contextConfig.logCallback = log_callback; // The priority of the worker thread can be set with the following. The default priority is - // mal_thread_priority_highest. - contextConfig.threadPriority = mal_thread_priority_normal; + // ma_thread_priority_highest. + contextConfig.threadPriority = ma_thread_priority_normal; // PulseAudio @@ -80,52 +80,52 @@ int main(int argc, char** argv) // The prioritization of backends can be controlled by the application. You need only specify the backends - // you care about. If the context cannot be initialized for any of the specified backends mal_context_init() + // you care about. If the context cannot be initialized for any of the specified backends ma_context_init() // will fail. - mal_backend backends[] = { - mal_backend_wasapi, // Higest priority. - mal_backend_dsound, - mal_backend_winmm, - mal_backend_coreaudio, - mal_backend_sndio, - mal_backend_audio4, - mal_backend_oss, - mal_backend_pulseaudio, - mal_backend_alsa, - mal_backend_jack, - mal_backend_aaudio, - mal_backend_opensl, - mal_backend_webaudio, - mal_backend_null // Lowest priority. + ma_backend backends[] = { + ma_backend_wasapi, // Higest priority. + ma_backend_dsound, + ma_backend_winmm, + ma_backend_coreaudio, + ma_backend_sndio, + ma_backend_audio4, + ma_backend_oss, + ma_backend_pulseaudio, + ma_backend_alsa, + ma_backend_jack, + ma_backend_aaudio, + ma_backend_opensl, + ma_backend_webaudio, + ma_backend_null // Lowest priority. }; - mal_context context; - if (mal_context_init(backends, sizeof(backends)/sizeof(backends[0]), &contextConfig, &context) != MA_SUCCESS) { + ma_context context; + if (ma_context_init(backends, sizeof(backends)/sizeof(backends[0]), &contextConfig, &context) != MA_SUCCESS) { printf("Failed to initialize context."); return -2; } // Enumerate devices. - mal_device_info* pPlaybackDeviceInfos; - mal_uint32 playbackDeviceCount; - mal_device_info* pCaptureDeviceInfos; - mal_uint32 captureDeviceCount; - mal_result result = mal_context_get_devices(&context, &pPlaybackDeviceInfos, &playbackDeviceCount, &pCaptureDeviceInfos, &captureDeviceCount); + ma_device_info* pPlaybackDeviceInfos; + ma_uint32 playbackDeviceCount; + ma_device_info* pCaptureDeviceInfos; + ma_uint32 captureDeviceCount; + ma_result result = ma_context_get_devices(&context, &pPlaybackDeviceInfos, &playbackDeviceCount, &pCaptureDeviceInfos, &captureDeviceCount); if (result != MA_SUCCESS) { printf("Failed to retrieve device information.\n"); return -3; } printf("Playback Devices (%d)\n", playbackDeviceCount); - for (mal_uint32 iDevice = 0; iDevice < playbackDeviceCount; ++iDevice) { + for (ma_uint32 iDevice = 0; iDevice < playbackDeviceCount; ++iDevice) { printf(" %u: %s\n", iDevice, pPlaybackDeviceInfos[iDevice].name); } printf("\n"); printf("Capture Devices (%d)\n", captureDeviceCount); - for (mal_uint32 iDevice = 0; iDevice < captureDeviceCount; ++iDevice) { + for (ma_uint32 iDevice = 0; iDevice < captureDeviceCount; ++iDevice) { printf(" %u: %s\n", iDevice, pCaptureDeviceInfos[iDevice].name); } @@ -133,12 +133,12 @@ int main(int argc, char** argv) // Open the device. // // Unlike context configs, device configs are required. Similar to context configs, an API exists to help you - // initialize a config object called mal_device_config_init(). + // initialize a config object called ma_device_config_init(). // // When using full-duplex you may want to use a different sample format, channel count and channel map. To // support this, the device configuration splits these into "playback" and "capture" as shown below. - mal_device_config deviceConfig = mal_device_config_init(mal_device_type_playback); - deviceConfig.playback.format = mal_format_s16; + ma_device_config deviceConfig = ma_device_config_init(ma_device_type_playback); + deviceConfig.playback.format = ma_format_s16; deviceConfig.playback.channels = 2; deviceConfig.sampleRate = 48000; deviceConfig.dataCallback = data_callback; @@ -149,7 +149,7 @@ int main(int argc, char** argv) // Applications can request exclusive control of the device using the config variable below. Note that not all // backends support this feature, so this is actually just a hint. - deviceConfig.playback.shareMode = mal_share_mode_exclusive; + deviceConfig.playback.shareMode = ma_share_mode_exclusive; // miniaudio allows applications to control the mapping of channels. The config below swaps the left and right // channels. Normally in an interleaved audio stream, the left channel comes first, but we can change that @@ -165,12 +165,12 @@ int main(int argc, char** argv) deviceConfig.alsa.noMMap = MA_TRUE; // This is not used in this example, but miniaudio allows you to directly control the device ID that's used - // for device selection by mal_device_init(). Below is an example for ALSA. In this example it forces - // mal_device_init() to try opening the "hw:0,0" device. This is useful for debugging in case you have + // for device selection by ma_device_init(). Below is an example for ALSA. In this example it forces + // ma_device_init() to try opening the "hw:0,0" device. This is useful for debugging in case you have // audio glitches or whatnot with specific devices. #ifdef MA_SUPPORT_ALSA - mal_device_id customDeviceID; - if (context.backend == mal_backend_alsa) { + ma_device_id customDeviceID; + if (context.backend == ma_backend_alsa) { strcpy(customDeviceID.alsa, "hw:0,0"); // The ALSA backend also supports a miniaudio-specific format which looks like this: ":0,0". In this case, @@ -181,26 +181,26 @@ int main(int argc, char** argv) } #endif - mal_device playbackDevice; - if (mal_device_init(&context, &deviceConfig, &playbackDevice) != MA_SUCCESS) { + ma_device playbackDevice; + if (ma_device_init(&context, &deviceConfig, &playbackDevice) != MA_SUCCESS) { printf("Failed to initialize playback device.\n"); - mal_context_uninit(&context); + ma_context_uninit(&context); return -7; } - if (mal_device_start(&playbackDevice) != MA_SUCCESS) { + if (ma_device_start(&playbackDevice) != MA_SUCCESS) { printf("Failed to start playback device.\n"); - mal_device_uninit(&playbackDevice); - mal_context_uninit(&context); + ma_device_uninit(&playbackDevice); + ma_context_uninit(&context); return -8; } printf("Press Enter to quit..."); getchar(); - mal_device_uninit(&playbackDevice); + ma_device_uninit(&playbackDevice); - mal_context_uninit(&context); + ma_context_uninit(&context); return 0; } diff --git a/examples/simple_capture.c b/examples/simple_capture.c index 631c546c..c253d573 100644 --- a/examples/simple_capture.c +++ b/examples/simple_capture.c @@ -9,12 +9,12 @@ #include #include -void data_callback(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 frameCount) +void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount) { (void)pOutput; drwav* pWav = (drwav*)pDevice->pUserData; - mal_assert(pWav != NULL); + ma_assert(pWav != NULL); drwav_write_pcm_frames(pWav, frameCount, pInput); } @@ -26,7 +26,7 @@ int main(int argc, char** argv) return -1; } - mal_result result; + ma_result result; drwav_data_format wavFormat; wavFormat.container = drwav_container_riff; @@ -41,23 +41,23 @@ int main(int argc, char** argv) return -1; } - mal_device_config config = mal_device_config_init(mal_device_type_capture); - config.capture.format = mal_format_f32; + ma_device_config config = ma_device_config_init(ma_device_type_capture); + config.capture.format = ma_format_f32; config.capture.channels = wavFormat.channels; config.sampleRate = wavFormat.sampleRate; config.dataCallback = data_callback; config.pUserData = &wav; - mal_device device; - result = mal_device_init(NULL, &config, &device); + ma_device device; + result = ma_device_init(NULL, &config, &device); if (result != MA_SUCCESS) { printf("Failed to initialize capture device.\n"); return -2; } - result = mal_device_start(&device); + result = ma_device_start(&device); if (result != MA_SUCCESS) { - mal_device_uninit(&device); + ma_device_uninit(&device); printf("Failed to start device.\n"); return -3; } @@ -65,7 +65,7 @@ int main(int argc, char** argv) printf("Press Enter to stop recording...\n"); getchar(); - mal_device_uninit(&device); + ma_device_uninit(&device); drwav_uninit(&wav); return 0; diff --git a/examples/simple_enumeration.c b/examples/simple_enumeration.c index 3d35df1f..96281f0a 100644 --- a/examples/simple_enumeration.c +++ b/examples/simple_enumeration.c @@ -8,35 +8,35 @@ int main(int argc, char** argv) (void)argc; (void)argv; - mal_context context; - if (mal_context_init(NULL, 0, NULL, &context) != MA_SUCCESS) { + ma_context context; + if (ma_context_init(NULL, 0, NULL, &context) != MA_SUCCESS) { printf("Failed to initialize context.\n"); return -2; } - mal_device_info* pPlaybackDeviceInfos; - mal_uint32 playbackDeviceCount; - mal_device_info* pCaptureDeviceInfos; - mal_uint32 captureDeviceCount; - mal_result result = mal_context_get_devices(&context, &pPlaybackDeviceInfos, &playbackDeviceCount, &pCaptureDeviceInfos, &captureDeviceCount); + ma_device_info* pPlaybackDeviceInfos; + ma_uint32 playbackDeviceCount; + ma_device_info* pCaptureDeviceInfos; + ma_uint32 captureDeviceCount; + ma_result result = ma_context_get_devices(&context, &pPlaybackDeviceInfos, &playbackDeviceCount, &pCaptureDeviceInfos, &captureDeviceCount); if (result != MA_SUCCESS) { printf("Failed to retrieve device information.\n"); return -3; } printf("Playback Devices\n"); - for (mal_uint32 iDevice = 0; iDevice < playbackDeviceCount; ++iDevice) { + for (ma_uint32 iDevice = 0; iDevice < playbackDeviceCount; ++iDevice) { printf(" %u: %s\n", iDevice, pPlaybackDeviceInfos[iDevice].name); } printf("\n"); printf("Capture Devices\n"); - for (mal_uint32 iDevice = 0; iDevice < captureDeviceCount; ++iDevice) { + for (ma_uint32 iDevice = 0; iDevice < captureDeviceCount; ++iDevice) { printf(" %u: %s\n", iDevice, pCaptureDeviceInfos[iDevice].name); } - mal_context_uninit(&context); + ma_context_uninit(&context); return 0; } diff --git a/examples/simple_playback.c b/examples/simple_playback.c index dd1c668d..6091ade9 100644 --- a/examples/simple_playback.c +++ b/examples/simple_playback.c @@ -10,14 +10,14 @@ #include -void data_callback(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 frameCount) +void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount) { - mal_decoder* pDecoder = (mal_decoder*)pDevice->pUserData; + ma_decoder* pDecoder = (ma_decoder*)pDevice->pUserData; if (pDecoder == NULL) { return; } - mal_decoder_read_pcm_frames(pDecoder, pOutput, frameCount); + ma_decoder_read_pcm_frames(pDecoder, pOutput, frameCount); (void)pInput; } @@ -29,38 +29,38 @@ int main(int argc, char** argv) return -1; } - mal_decoder decoder; - mal_result result = mal_decoder_init_file(argv[1], NULL, &decoder); + ma_decoder decoder; + ma_result result = ma_decoder_init_file(argv[1], NULL, &decoder); if (result != MA_SUCCESS) { return -2; } - mal_device_config config = mal_device_config_init(mal_device_type_playback); + ma_device_config config = ma_device_config_init(ma_device_type_playback); 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) != MA_SUCCESS) { + ma_device device; + if (ma_device_init(NULL, &config, &device) != MA_SUCCESS) { printf("Failed to open playback device.\n"); - mal_decoder_uninit(&decoder); + ma_decoder_uninit(&decoder); return -3; } - if (mal_device_start(&device) != MA_SUCCESS) { + if (ma_device_start(&device) != MA_SUCCESS) { printf("Failed to start playback device.\n"); - mal_device_uninit(&device); - mal_decoder_uninit(&decoder); + ma_device_uninit(&device); + ma_decoder_uninit(&decoder); return -4; } printf("Press Enter to quit..."); getchar(); - mal_device_uninit(&device); - mal_decoder_uninit(&decoder); + ma_device_uninit(&device); + ma_decoder_uninit(&decoder); return 0; } diff --git a/examples/simple_playback_emscripten.c b/examples/simple_playback_emscripten.c index a8b41003..f965df8c 100644 --- a/examples/simple_playback_emscripten.c +++ b/examples/simple_playback_emscripten.c @@ -11,19 +11,19 @@ void main_loop__em() } #endif -#define DEVICE_FORMAT mal_format_f32 +#define DEVICE_FORMAT ma_format_f32 #define DEVICE_CHANNELS 1 #define DEVICE_SAMPLE_RATE 48000 -void data_callback(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 frameCount) +void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount) { (void)pInput; /* Unused. */ - mal_assert(pDevice->playback.channels == DEVICE_CHANNELS); + ma_assert(pDevice->playback.channels == DEVICE_CHANNELS); - mal_sine_wave* pSineWave = (mal_sine_wave*)pDevice->pUserData; - mal_assert(pSineWave != NULL); + ma_sine_wave* pSineWave = (ma_sine_wave*)pDevice->pUserData; + ma_assert(pSineWave != NULL); - mal_sine_wave_read_f32(pSineWave, frameCount, (float*)pOutput); + ma_sine_wave_read_f32(pSineWave, frameCount, (float*)pOutput); } int main(int argc, char** argv) @@ -31,27 +31,27 @@ int main(int argc, char** argv) (void)argc; (void)argv; - mal_sine_wave sineWave; - mal_sine_wave_init(0.2, 400, DEVICE_SAMPLE_RATE, &sineWave); + ma_sine_wave sineWave; + ma_sine_wave_init(0.2, 400, DEVICE_SAMPLE_RATE, &sineWave); - mal_device_config config = mal_device_config_init(mal_device_type_playback); + ma_device_config config = ma_device_config_init(ma_device_type_playback); config.playback.format = DEVICE_FORMAT; config.playback.channels = DEVICE_CHANNELS; config.sampleRate = DEVICE_SAMPLE_RATE; config.dataCallback = data_callback; config.pUserData = &sineWave; - mal_device device; - if (mal_device_init(NULL, &config, &device) != MA_SUCCESS) { + ma_device device; + if (ma_device_init(NULL, &config, &device) != MA_SUCCESS) { printf("Failed to open playback device.\n"); return -4; } printf("Device Name: %s\n", device.playback.name); - if (mal_device_start(&device) != MA_SUCCESS) { + if (ma_device_start(&device) != MA_SUCCESS) { printf("Failed to start playback device.\n"); - mal_device_uninit(&device); + ma_device_uninit(&device); return -5; } @@ -62,7 +62,7 @@ int main(int argc, char** argv) getchar(); #endif - mal_device_uninit(&device); + ma_device_uninit(&device); return 0; } diff --git a/miniaudio.h b/miniaudio.h index b84e51a7..03a195a5 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -25,41 +25,41 @@ The major feature added to version 0.9 is full-duplex. This has necessitated a f there is just one callback which is the same for all three modes (playback, capture, duplex). The new callback looks like the following: - void data_callback(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 frameCount); + void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount); This callback allows you to move data straight out of the input buffer and into the output buffer in full-duplex mode. In playback-only mode, pInput will be null. Likewise, pOutput will be null in capture-only mode. The sample count is no longer returned from the callback since it's not necessary for miniaudio anymore. 2) The device config needed to change in order to support full-duplex. Full-duplex requires the ability to allow the client - to choose a different PCM format for the playback and capture sides. The old mal_device_config object simply did not allow + to choose a different PCM format for the playback and capture sides. The old ma_device_config object simply did not allow this and needed to change. With these changes you now specify the device ID, format, channels, channel map and share mode on a per-playback and per-capture basis (see example below). The sample rate must be the same for playback and capture. Since the device config API has changed I have also decided to take the opportunity to simplify device initialization. Now, - the device ID, device type and callback user data are set in the config. mal_device_init() is now simplified down to taking + the device ID, device type and callback user data are set in the config. ma_device_init() is now simplified down to taking just the context, device config and a pointer to the device object being initialized. The rationale for this change is that it just makes more sense to me that these are set as part of the config like everything else. Example device initialization: - mal_device_config config = mal_device_config_init(mal_device_type_duplex); // Or mal_device_type_playback or mal_device_type_capture. + ma_device_config config = ma_device_config_init(ma_device_type_duplex); // Or ma_device_type_playback or ma_device_type_capture. config.playback.pDeviceID = &myPlaybackDeviceID; // Or NULL for the default playback device. - config.playback.format = mal_format_f32; + config.playback.format = ma_format_f32; config.playback.channels = 2; config.capture.pDeviceID = &myCaptureDeviceID; // Or NULL for the default capture device. - config.capture.format = mal_format_s16; + config.capture.format = ma_format_s16; config.capture.channels = 1; config.sampleRate = 44100; config.dataCallback = data_callback; config.pUserData = &myUserData; - result = mal_device_init(&myContext, &config, &device); + result = ma_device_init(&myContext, &config, &device); if (result != MA_SUCCESS) { ... handle error ... } - Note that the "onDataCallback" member of mal_device_config has been renamed to "dataCallback". Also, "onStopCallback" has + Note that the "onDataCallback" member of ma_device_config has been renamed to "dataCallback". Also, "onStopCallback" has been renamed to "stopCallback". This is the first pass for full-duplex and there is a known bug. You will hear crackling on the following backends when sample @@ -79,27 +79,27 @@ Other API Changes ----------------- In addition to the above, the following API changes have been made: -- The log callback is no longer passed to mal_context_config_init(). Instead you need to set it manually after initialization. -- The onLogCallback member of mal_context_config has been renamed to "logCallback". -- The log callback now takes a logLevel parameter. The new callback looks like: void log_callback(mal_context* pContext, mal_device* pDevice, mal_uint32 logLevel, const char* message) - - You can use mal_log_level_to_string() to convert the logLevel to human readable text if you want to log it. +- The log callback is no longer passed to ma_context_config_init(). Instead you need to set it manually after initialization. +- The onLogCallback member of ma_context_config has been renamed to "logCallback". +- The log callback now takes a logLevel parameter. The new callback looks like: void log_callback(ma_context* pContext, ma_device* pDevice, ma_uint32 logLevel, const char* message) + - You can use ma_log_level_to_string() to convert the logLevel to human readable text if you want to log it. - Some APIs have been renamed: - - mal_decoder_read() -> mal_decoder_read_pcm_frames() - - mal_decoder_seek_to_frame() -> mal_decoder_seek_to_pcm_frame() - - mal_sine_wave_read() -> mal_sine_wave_read_f32() - - mal_sine_wave_read_ex() -> mal_sine_wave_read_f32_ex() + - ma_decoder_read() -> ma_decoder_read_pcm_frames() + - ma_decoder_seek_to_frame() -> ma_decoder_seek_to_pcm_frame() + - ma_sine_wave_read() -> ma_sine_wave_read_f32() + - ma_sine_wave_read_ex() -> ma_sine_wave_read_f32_ex() - Some APIs have been removed: - - mal_device_get_buffer_size_in_bytes() - - mal_device_set_recv_callback() - - mal_device_set_send_callback() - - mal_src_set_input_sample_rate() - - mal_src_set_output_sample_rate() + - ma_device_get_buffer_size_in_bytes() + - ma_device_set_recv_callback() + - ma_device_set_send_callback() + - ma_src_set_input_sample_rate() + - ma_src_set_output_sample_rate() - Error codes have been rearranged. If you're a binding maintainer you will need to update. -- The mal_backend enums have been rearranged to priority order. The rationale for this is to simplify automatic backend selection +- The ma_backend enums have been rearranged to priority order. The rationale for this is to simplify automatic backend selection and to make it easier to see the priority. If you're a binding maintainer you will need to update. -- mal_dsp has been renamed to mal_pcm_converter. The rationale for this change is that I'm expecting "mal_dsp" to conflict with +- ma_dsp has been renamed to ma_pcm_converter. The rationale for this change is that I'm expecting "ma_dsp" to conflict with some future planned high-level APIs. -- For functions that take a pointer/count combo, such as mal_decoder_read_pcm_frames(), the parameter order has changed so that +- For functions that take a pointer/count combo, such as ma_decoder_read_pcm_frames(), the parameter order has changed so that the pointer comes before the count. The rationale for this is to keep it consistent with things like memcpy(). @@ -115,7 +115,7 @@ The following miscellaneous changes have also been made. - Device initialization now fails if the requested share mode is not supported. If you ask for exclusive mode, you either get an exclusive mode device, or an error. The rationale for this change is to give the client more control over how to handle cases when the desired shared mode is unavailable. -- A lock-free ring buffer API has been added. There are two varients of this. "mal_rb" operates on bytes, whereas "mal_pcm_rb" +- A lock-free ring buffer API has been added. There are two varients of this. "ma_rb" operates on bytes, whereas "ma_pcm_rb" operates on PCM frames. - The library is now licensed as a choice of Public Domain (Unlicense) _or_ MIT-0 (No Attribution) which is the same as MIT, but removes the attribution requirement. The rationale for this is to support countries that don't recognize public domain. @@ -166,35 +166,35 @@ of capture. Playback Example ---------------- - void data_callback(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 frameCount) + void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount) { - mal_decoder* pDecoder = (mal_decoder*)pDevice->pUserData; + ma_decoder* pDecoder = (ma_decoder*)pDevice->pUserData; if (pDecoder == NULL) { return; } - mal_decoder_read_pcm_frames(pDecoder, frameCount, pOutput); + ma_decoder_read_pcm_frames(pDecoder, frameCount, pOutput); } ... - mal_device_config config = mal_device_config_init(mal_device_type_playback); + ma_device_config config = ma_device_config_init(ma_device_type_playback); 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) != MA_SUCCESS) { + ma_device device; + if (ma_device_init(NULL, &config, &device) != MA_SUCCESS) { ... An error occurred ... } - mal_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. ... - mal_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. BUILDING @@ -242,10 +242,10 @@ NOTES ===== - This library uses an asynchronous API for delivering and requesting audio data. Each device will have it's own worker thread which is managed by the library. -- If mal_device_init() is called with a device that's not aligned to the platform's natural alignment +- If ma_device_init() is called with a device that's not aligned to the platform's natural alignment boundary (4 bytes on 32-bit, 8 bytes on 64-bit), it will _not_ be thread-safe. The reason for this - is that it depends on members of mal_device being correctly aligned for atomic assignments. -- Sample data is always native-endian and interleaved. For example, mal_format_s16 means signed 16-bit + is that it depends on members of ma_device being correctly aligned for atomic assignments. +- Sample data is always native-endian and interleaved. For example, ma_format_s16 means signed 16-bit integer samples, interleaved. Let me know if you need non-interleaved and I'll look into it. - The sndio backend is currently only enabled on OpenBSD builds. - The audio(4) backend is supported on OpenBSD, but you may need to disable sndiod before you can use it. @@ -267,10 +267,10 @@ Android ------- - To capture audio on Android, remember to add the RECORD_AUDIO permission to your manifest: -- With OpenSL|ES, only a single mal_context can be active at any given time. This is due to a limitation with OpenSL|ES. +- With OpenSL|ES, only a single ma_context can be active at any given time. This is due to a limitation with OpenSL|ES. - With AAudio, only default devices are enumerated. This is due to AAudio not having an enumeration API (devices are enumerated through Java). You can however perform your own device enumeration through Java and then set the ID in the - mal_device_id structure (mal_device_id.aaudio) and pass it to mal_device_init(). + ma_device_id structure (ma_device_id.aaudio) and pass it to ma_device_init(). - The backend API will perform resampling where possible. The reason for this as opposed to using miniaudio's built-in resampler is to take advantage of any potential device-specific optimizations the driver may implement. @@ -353,7 +353,7 @@ OPTIONS Disables the decoding APIs. #define MA_NO_DEVICE_IO - Disables playback and recording. This will disable mal_context and mal_device APIs. This is useful if you only want to + Disables playback and recording. This will disable ma_context and ma_device APIs. This is useful if you only want to use miniaudio's data conversion and/or decoding APIs. #define MA_NO_STDIO @@ -478,61 +478,61 @@ extern "C" { #pragma GCC diagnostic ignored "-Wlanguage-extension-token" #pragma GCC diagnostic ignored "-Wc++11-long-long" #endif - typedef signed __int8 mal_int8; - typedef unsigned __int8 mal_uint8; - typedef signed __int16 mal_int16; - typedef unsigned __int16 mal_uint16; - typedef signed __int32 mal_int32; - typedef unsigned __int32 mal_uint32; - typedef signed __int64 mal_int64; - typedef unsigned __int64 mal_uint64; + typedef signed __int8 ma_int8; + typedef unsigned __int8 ma_uint8; + typedef signed __int16 ma_int16; + typedef unsigned __int16 ma_uint16; + typedef signed __int32 ma_int32; + typedef unsigned __int32 ma_uint32; + typedef signed __int64 ma_int64; + typedef unsigned __int64 ma_uint64; #if defined(__clang__) #pragma GCC diagnostic pop #endif #else #define MA_HAS_STDINT #include - typedef int8_t mal_int8; - typedef uint8_t mal_uint8; - typedef int16_t mal_int16; - typedef uint16_t mal_uint16; - typedef int32_t mal_int32; - typedef uint32_t mal_uint32; - typedef int64_t mal_int64; - typedef uint64_t mal_uint64; + typedef int8_t ma_int8; + typedef uint8_t ma_uint8; + typedef int16_t ma_int16; + typedef uint16_t ma_uint16; + typedef int32_t ma_int32; + typedef uint32_t ma_uint32; + typedef int64_t ma_int64; + typedef uint64_t ma_uint64; #endif #ifdef MA_HAS_STDINT - typedef uintptr_t mal_uintptr; + typedef uintptr_t ma_uintptr; #else #if defined(_WIN32) #if defined(_WIN64) - typedef mal_uint64 mal_uintptr; + typedef ma_uint64 ma_uintptr; #else - typedef mal_uint32 mal_uintptr; + typedef ma_uint32 ma_uintptr; #endif #elif defined(__GNUC__) #if defined(__LP64__) - typedef mal_uint64 mal_uintptr; + typedef ma_uint64 ma_uintptr; #else - typedef mal_uint32 mal_uintptr; + typedef ma_uint32 ma_uintptr; #endif #else - typedef mal_uint64 mal_uintptr; /* Fallback. */ + typedef ma_uint64 ma_uintptr; /* Fallback. */ #endif #endif -typedef mal_uint8 mal_bool8; -typedef mal_uint32 mal_bool32; +typedef ma_uint8 ma_bool8; +typedef ma_uint32 ma_bool32; #define MA_TRUE 1 #define MA_FALSE 0 -typedef void* mal_handle; -typedef void* mal_ptr; -typedef void (* mal_proc)(void); +typedef void* ma_handle; +typedef void* ma_ptr; +typedef void (* ma_proc)(void); #if defined(_MSC_VER) && !defined(_WCHAR_T_DEFINED) -typedef mal_uint16 wchar_t; +typedef ma_uint16 wchar_t; #endif // Define NULL for some compilers. @@ -585,10 +585,10 @@ typedef mal_uint16 wchar_t; #define MA_LOG_LEVEL MA_LOG_LEVEL_ERROR #endif -typedef struct mal_context mal_context; -typedef struct mal_device mal_device; +typedef struct ma_context ma_context; +typedef struct ma_device ma_device; -typedef mal_uint8 mal_channel; +typedef ma_uint8 ma_channel; #define MA_CHANNEL_NONE 0 #define MA_CHANNEL_MONO 1 #define MA_CHANNEL_FRONT_LEFT 2 @@ -646,7 +646,7 @@ typedef mal_uint8 mal_channel; #define MA_CHANNEL_POSITION_COUNT MA_CHANNEL_AUX_31 + 1 -typedef int mal_result; +typedef int ma_result; #define MA_SUCCESS 0 /* General errors. */ @@ -720,176 +720,176 @@ typedef int mal_result; typedef enum { - mal_stream_format_pcm = 0, -} mal_stream_format; + ma_stream_format_pcm = 0, +} ma_stream_format; typedef enum { - mal_stream_layout_interleaved = 0, - mal_stream_layout_deinterleaved -} mal_stream_layout; + ma_stream_layout_interleaved = 0, + ma_stream_layout_deinterleaved +} ma_stream_layout; typedef enum { - mal_dither_mode_none = 0, - mal_dither_mode_rectangle, - mal_dither_mode_triangle -} mal_dither_mode; + ma_dither_mode_none = 0, + ma_dither_mode_rectangle, + ma_dither_mode_triangle +} ma_dither_mode; typedef enum { // I like to keep these explicitly defined because they're used as a key into a lookup table. When items are - // added to this, make sure there are no gaps and that they're added to the lookup table in mal_get_bytes_per_sample(). - mal_format_unknown = 0, // Mainly used for indicating an error, but also used as the default for the output format for decoders. - mal_format_u8 = 1, - mal_format_s16 = 2, // Seems to be the most widely supported format. - mal_format_s24 = 3, // Tightly packed. 3 bytes per sample. - mal_format_s32 = 4, - mal_format_f32 = 5, - mal_format_count -} mal_format; + // added to this, make sure there are no gaps and that they're added to the lookup table in ma_get_bytes_per_sample(). + ma_format_unknown = 0, // Mainly used for indicating an error, but also used as the default for the output format for decoders. + ma_format_u8 = 1, + ma_format_s16 = 2, // Seems to be the most widely supported format. + ma_format_s24 = 3, // Tightly packed. 3 bytes per sample. + ma_format_s32 = 4, + ma_format_f32 = 5, + ma_format_count +} ma_format; typedef enum { - mal_channel_mix_mode_rectangular = 0, // Simple averaging based on the plane(s) the channel is sitting on. - mal_channel_mix_mode_simple, // Drop excess channels; zeroed out extra channels. - mal_channel_mix_mode_custom_weights, // Use custom weights specified in mal_channel_router_config. - mal_channel_mix_mode_planar_blend = mal_channel_mix_mode_rectangular, - mal_channel_mix_mode_default = mal_channel_mix_mode_planar_blend -} mal_channel_mix_mode; + ma_channel_mix_mode_rectangular = 0, // Simple averaging based on the plane(s) the channel is sitting on. + ma_channel_mix_mode_simple, // Drop excess channels; zeroed out extra channels. + ma_channel_mix_mode_custom_weights, // Use custom weights specified in ma_channel_router_config. + ma_channel_mix_mode_planar_blend = ma_channel_mix_mode_rectangular, + ma_channel_mix_mode_default = ma_channel_mix_mode_planar_blend +} ma_channel_mix_mode; typedef enum { - mal_standard_channel_map_microsoft, - mal_standard_channel_map_alsa, - mal_standard_channel_map_rfc3551, // Based off AIFF. - mal_standard_channel_map_flac, - mal_standard_channel_map_vorbis, - mal_standard_channel_map_sound4, // FreeBSD's sound(4). - mal_standard_channel_map_sndio, // www.sndio.org/tips.html - mal_standard_channel_map_webaudio = mal_standard_channel_map_flac, // https://webaudio.github.io/web-audio-api/#ChannelOrdering. Only 1, 2, 4 and 6 channels are defined, but can fill in the gaps with logical assumptions. - mal_standard_channel_map_default = mal_standard_channel_map_microsoft -} mal_standard_channel_map; + ma_standard_channel_map_microsoft, + ma_standard_channel_map_alsa, + ma_standard_channel_map_rfc3551, // Based off AIFF. + ma_standard_channel_map_flac, + ma_standard_channel_map_vorbis, + ma_standard_channel_map_sound4, // FreeBSD's sound(4). + ma_standard_channel_map_sndio, // www.sndio.org/tips.html + ma_standard_channel_map_webaudio = ma_standard_channel_map_flac, // https://webaudio.github.io/web-audio-api/#ChannelOrdering. Only 1, 2, 4 and 6 channels are defined, but can fill in the gaps with logical assumptions. + ma_standard_channel_map_default = ma_standard_channel_map_microsoft +} ma_standard_channel_map; typedef enum { - mal_performance_profile_low_latency = 0, - mal_performance_profile_conservative -} mal_performance_profile; + ma_performance_profile_low_latency = 0, + ma_performance_profile_conservative +} ma_performance_profile; -typedef struct mal_format_converter mal_format_converter; -typedef mal_uint32 (* mal_format_converter_read_proc) (mal_format_converter* pConverter, mal_uint32 frameCount, void* pFramesOut, void* pUserData); -typedef mal_uint32 (* mal_format_converter_read_deinterleaved_proc)(mal_format_converter* pConverter, mal_uint32 frameCount, void** ppSamplesOut, void* pUserData); +typedef struct ma_format_converter ma_format_converter; +typedef ma_uint32 (* ma_format_converter_read_proc) (ma_format_converter* pConverter, ma_uint32 frameCount, void* pFramesOut, void* pUserData); +typedef ma_uint32 (* ma_format_converter_read_deinterleaved_proc)(ma_format_converter* pConverter, ma_uint32 frameCount, void** ppSamplesOut, void* pUserData); typedef struct { - mal_format formatIn; - mal_format formatOut; - mal_uint32 channels; - mal_stream_format streamFormatIn; - mal_stream_format streamFormatOut; - mal_dither_mode ditherMode; - mal_bool32 noSSE2 : 1; - mal_bool32 noAVX2 : 1; - mal_bool32 noAVX512 : 1; - mal_bool32 noNEON : 1; - mal_format_converter_read_proc onRead; - mal_format_converter_read_deinterleaved_proc onReadDeinterleaved; + ma_format formatIn; + ma_format formatOut; + ma_uint32 channels; + ma_stream_format streamFormatIn; + ma_stream_format streamFormatOut; + ma_dither_mode ditherMode; + ma_bool32 noSSE2 : 1; + ma_bool32 noAVX2 : 1; + ma_bool32 noAVX512 : 1; + ma_bool32 noNEON : 1; + ma_format_converter_read_proc onRead; + ma_format_converter_read_deinterleaved_proc onReadDeinterleaved; void* pUserData; -} mal_format_converter_config; +} ma_format_converter_config; -struct mal_format_converter +struct ma_format_converter { - mal_format_converter_config config; - mal_bool32 useSSE2 : 1; - mal_bool32 useAVX2 : 1; - mal_bool32 useAVX512 : 1; - mal_bool32 useNEON : 1; - void (* onConvertPCM)(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode); - void (* onInterleavePCM)(void* dst, const void** src, mal_uint64 frameCount, mal_uint32 channels); - void (* onDeinterleavePCM)(void** dst, const void* src, mal_uint64 frameCount, mal_uint32 channels); + ma_format_converter_config config; + ma_bool32 useSSE2 : 1; + ma_bool32 useAVX2 : 1; + ma_bool32 useAVX512 : 1; + ma_bool32 useNEON : 1; + void (* onConvertPCM)(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode); + void (* onInterleavePCM)(void* dst, const void** src, ma_uint64 frameCount, ma_uint32 channels); + void (* onDeinterleavePCM)(void** dst, const void* src, ma_uint64 frameCount, ma_uint32 channels); }; -typedef struct mal_channel_router mal_channel_router; -typedef mal_uint32 (* mal_channel_router_read_deinterleaved_proc)(mal_channel_router* pRouter, mal_uint32 frameCount, void** ppSamplesOut, void* pUserData); +typedef struct ma_channel_router ma_channel_router; +typedef ma_uint32 (* ma_channel_router_read_deinterleaved_proc)(ma_channel_router* pRouter, ma_uint32 frameCount, void** ppSamplesOut, void* pUserData); typedef struct { - mal_uint32 channelsIn; - mal_uint32 channelsOut; - mal_channel channelMapIn[MA_MAX_CHANNELS]; - mal_channel channelMapOut[MA_MAX_CHANNELS]; - mal_channel_mix_mode mixingMode; - float weights[MA_MAX_CHANNELS][MA_MAX_CHANNELS]; // [in][out]. Only used when mixingMode is set to mal_channel_mix_mode_custom_weights. - mal_bool32 noSSE2 : 1; - mal_bool32 noAVX2 : 1; - mal_bool32 noAVX512 : 1; - mal_bool32 noNEON : 1; - mal_channel_router_read_deinterleaved_proc onReadDeinterleaved; + ma_uint32 channelsIn; + ma_uint32 channelsOut; + ma_channel channelMapIn[MA_MAX_CHANNELS]; + ma_channel channelMapOut[MA_MAX_CHANNELS]; + ma_channel_mix_mode mixingMode; + float weights[MA_MAX_CHANNELS][MA_MAX_CHANNELS]; // [in][out]. Only used when mixingMode is set to ma_channel_mix_mode_custom_weights. + ma_bool32 noSSE2 : 1; + ma_bool32 noAVX2 : 1; + ma_bool32 noAVX512 : 1; + ma_bool32 noNEON : 1; + ma_channel_router_read_deinterleaved_proc onReadDeinterleaved; void* pUserData; -} mal_channel_router_config; +} ma_channel_router_config; -struct mal_channel_router +struct ma_channel_router { - mal_channel_router_config config; - mal_bool32 isPassthrough : 1; - mal_bool32 isSimpleShuffle : 1; - mal_bool32 useSSE2 : 1; - mal_bool32 useAVX2 : 1; - mal_bool32 useAVX512 : 1; - mal_bool32 useNEON : 1; - mal_uint8 shuffleTable[MA_MAX_CHANNELS]; + ma_channel_router_config config; + ma_bool32 isPassthrough : 1; + ma_bool32 isSimpleShuffle : 1; + ma_bool32 useSSE2 : 1; + ma_bool32 useAVX2 : 1; + ma_bool32 useAVX512 : 1; + ma_bool32 useNEON : 1; + ma_uint8 shuffleTable[MA_MAX_CHANNELS]; }; -typedef struct mal_src mal_src; -typedef mal_uint32 (* mal_src_read_deinterleaved_proc)(mal_src* pSRC, mal_uint32 frameCount, void** ppSamplesOut, void* pUserData); // Returns the number of frames that were read. +typedef struct ma_src ma_src; +typedef ma_uint32 (* ma_src_read_deinterleaved_proc)(ma_src* pSRC, ma_uint32 frameCount, void** ppSamplesOut, void* pUserData); // Returns the number of frames that were read. typedef enum { - mal_src_algorithm_linear = 0, - mal_src_algorithm_sinc, - mal_src_algorithm_none, - mal_src_algorithm_default = mal_src_algorithm_linear -} mal_src_algorithm; + ma_src_algorithm_linear = 0, + ma_src_algorithm_sinc, + ma_src_algorithm_none, + ma_src_algorithm_default = ma_src_algorithm_linear +} ma_src_algorithm; typedef enum { - mal_src_sinc_window_function_hann = 0, - mal_src_sinc_window_function_rectangular, - mal_src_sinc_window_function_default = mal_src_sinc_window_function_hann -} mal_src_sinc_window_function; + ma_src_sinc_window_function_hann = 0, + ma_src_sinc_window_function_rectangular, + ma_src_sinc_window_function_default = ma_src_sinc_window_function_hann +} ma_src_sinc_window_function; typedef struct { - mal_src_sinc_window_function windowFunction; - mal_uint32 windowWidth; -} mal_src_config_sinc; + ma_src_sinc_window_function windowFunction; + ma_uint32 windowWidth; +} ma_src_config_sinc; typedef struct { - mal_uint32 sampleRateIn; - mal_uint32 sampleRateOut; - mal_uint32 channels; - mal_src_algorithm algorithm; - mal_bool32 neverConsumeEndOfInput : 1; - mal_bool32 noSSE2 : 1; - mal_bool32 noAVX2 : 1; - mal_bool32 noAVX512 : 1; - mal_bool32 noNEON : 1; - mal_src_read_deinterleaved_proc onReadDeinterleaved; + ma_uint32 sampleRateIn; + ma_uint32 sampleRateOut; + ma_uint32 channels; + ma_src_algorithm algorithm; + ma_bool32 neverConsumeEndOfInput : 1; + ma_bool32 noSSE2 : 1; + ma_bool32 noAVX2 : 1; + ma_bool32 noAVX512 : 1; + ma_bool32 noNEON : 1; + ma_src_read_deinterleaved_proc onReadDeinterleaved; void* pUserData; union { - mal_src_config_sinc sinc; + ma_src_config_sinc sinc; }; -} mal_src_config; +} ma_src_config; -MA_ALIGNED_STRUCT(MA_SIMD_ALIGNMENT) mal_src +MA_ALIGNED_STRUCT(MA_SIMD_ALIGNMENT) ma_src { union { @@ -897,72 +897,72 @@ MA_ALIGNED_STRUCT(MA_SIMD_ALIGNMENT) mal_src { MA_ALIGN(MA_SIMD_ALIGNMENT) float input[MA_MAX_CHANNELS][MA_SRC_INPUT_BUFFER_SIZE_IN_SAMPLES]; float timeIn; - mal_uint32 leftoverFrames; + ma_uint32 leftoverFrames; } linear; struct { MA_ALIGN(MA_SIMD_ALIGNMENT) float input[MA_MAX_CHANNELS][MA_SRC_SINC_MAX_WINDOW_WIDTH*2 + MA_SRC_INPUT_BUFFER_SIZE_IN_SAMPLES]; float timeIn; - mal_uint32 inputFrameCount; // The number of frames sitting in the input buffer, not including the first half of the window. - mal_uint32 windowPosInSamples; // An offset of . + ma_uint32 inputFrameCount; // The number of frames sitting in the input buffer, not including the first half of the window. + ma_uint32 windowPosInSamples; // An offset of . float table[MA_SRC_SINC_MAX_WINDOW_WIDTH*1 * MA_SRC_SINC_LOOKUP_TABLE_RESOLUTION]; // Precomputed lookup table. The +1 is used to avoid the need for an overflow check. } sinc; }; - mal_src_config config; - mal_bool32 isEndOfInputLoaded : 1; - mal_bool32 useSSE2 : 1; - mal_bool32 useAVX2 : 1; - mal_bool32 useAVX512 : 1; - mal_bool32 useNEON : 1; + ma_src_config config; + ma_bool32 isEndOfInputLoaded : 1; + ma_bool32 useSSE2 : 1; + ma_bool32 useAVX2 : 1; + ma_bool32 useAVX512 : 1; + ma_bool32 useNEON : 1; }; -typedef struct mal_pcm_converter mal_pcm_converter; -typedef mal_uint32 (* mal_pcm_converter_read_proc)(mal_pcm_converter* pDSP, void* pSamplesOut, mal_uint32 frameCount, void* pUserData); +typedef struct ma_pcm_converter ma_pcm_converter; +typedef ma_uint32 (* ma_pcm_converter_read_proc)(ma_pcm_converter* pDSP, void* pSamplesOut, ma_uint32 frameCount, void* pUserData); typedef struct { - mal_format formatIn; - mal_uint32 channelsIn; - mal_uint32 sampleRateIn; - mal_channel channelMapIn[MA_MAX_CHANNELS]; - mal_format formatOut; - mal_uint32 channelsOut; - mal_uint32 sampleRateOut; - mal_channel channelMapOut[MA_MAX_CHANNELS]; - mal_channel_mix_mode channelMixMode; - mal_dither_mode ditherMode; - mal_src_algorithm srcAlgorithm; - mal_bool32 allowDynamicSampleRate; - mal_bool32 neverConsumeEndOfInput : 1; // <-- For SRC. - mal_bool32 noSSE2 : 1; - mal_bool32 noAVX2 : 1; - mal_bool32 noAVX512 : 1; - mal_bool32 noNEON : 1; - mal_pcm_converter_read_proc onRead; + ma_format formatIn; + ma_uint32 channelsIn; + ma_uint32 sampleRateIn; + ma_channel channelMapIn[MA_MAX_CHANNELS]; + ma_format formatOut; + ma_uint32 channelsOut; + ma_uint32 sampleRateOut; + ma_channel channelMapOut[MA_MAX_CHANNELS]; + ma_channel_mix_mode channelMixMode; + ma_dither_mode ditherMode; + ma_src_algorithm srcAlgorithm; + ma_bool32 allowDynamicSampleRate; + ma_bool32 neverConsumeEndOfInput : 1; // <-- For SRC. + ma_bool32 noSSE2 : 1; + ma_bool32 noAVX2 : 1; + ma_bool32 noAVX512 : 1; + ma_bool32 noNEON : 1; + ma_pcm_converter_read_proc onRead; void* pUserData; union { - mal_src_config_sinc sinc; + ma_src_config_sinc sinc; }; -} mal_pcm_converter_config; +} ma_pcm_converter_config; -MA_ALIGNED_STRUCT(MA_SIMD_ALIGNMENT) mal_pcm_converter +MA_ALIGNED_STRUCT(MA_SIMD_ALIGNMENT) ma_pcm_converter { - mal_pcm_converter_read_proc onRead; + ma_pcm_converter_read_proc onRead; void* pUserData; - mal_format_converter formatConverterIn; // For converting data to f32 in preparation for further processing. - mal_format_converter formatConverterOut; // For converting data to the requested output format. Used as the final step in the processing pipeline. - mal_channel_router channelRouter; // For channel conversion. - mal_src src; // For sample rate conversion. - mal_bool32 isDynamicSampleRateAllowed : 1; // mal_pcm_converter_set_input_sample_rate() and mal_pcm_converter_set_output_sample_rate() will fail if this is set to false. - mal_bool32 isPreFormatConversionRequired : 1; - mal_bool32 isPostFormatConversionRequired : 1; - mal_bool32 isChannelRoutingRequired : 1; - mal_bool32 isSRCRequired : 1; - mal_bool32 isChannelRoutingAtStart : 1; - mal_bool32 isPassthrough : 1; // <-- Will be set to true when the DSP pipeline is an optimized passthrough. + ma_format_converter formatConverterIn; // For converting data to f32 in preparation for further processing. + ma_format_converter formatConverterOut; // For converting data to the requested output format. Used as the final step in the processing pipeline. + ma_channel_router channelRouter; // For channel conversion. + ma_src src; // For sample rate conversion. + ma_bool32 isDynamicSampleRateAllowed : 1; // ma_pcm_converter_set_input_sample_rate() and ma_pcm_converter_set_output_sample_rate() will fail if this is set to false. + ma_bool32 isPreFormatConversionRequired : 1; + ma_bool32 isPostFormatConversionRequired : 1; + ma_bool32 isChannelRoutingRequired : 1; + ma_bool32 isSRCRequired : 1; + ma_bool32 isChannelRoutingAtStart : 1; + ma_bool32 isPassthrough : 1; // <-- Will be set to true when the DSP pipeline is an optimized passthrough. }; @@ -982,7 +982,7 @@ MA_ALIGNED_STRUCT(MA_SIMD_ALIGNMENT) mal_pcm_converter // Channel Maps // ============ // -// Below is the channel map used by mal_standard_channel_map_default: +// Below is the channel map used by ma_standard_channel_map_default: // // |---------------|------------------------------| // | Channel Count | Mapping | @@ -1039,10 +1039,10 @@ MA_ALIGNED_STRUCT(MA_SIMD_ALIGNMENT) mal_pcm_converter ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Helper for retrieving a standard channel map. -void mal_get_standard_channel_map(mal_standard_channel_map standardChannelMap, mal_uint32 channels, mal_channel channelMap[MA_MAX_CHANNELS]); +void ma_get_standard_channel_map(ma_standard_channel_map standardChannelMap, ma_uint32 channels, ma_channel channelMap[MA_MAX_CHANNELS]); // Copies a channel map. -void mal_channel_map_copy(mal_channel* pOut, const mal_channel* pIn, mal_uint32 channels); +void ma_channel_map_copy(ma_channel* pOut, const ma_channel* pIn, ma_uint32 channels); // Determines whether or not a channel map is valid. @@ -1053,18 +1053,18 @@ void mal_channel_map_copy(mal_channel* pOut, const mal_channel* pIn, mal_uint32 // Invalid channel maps: // - A channel map with no channels // - A channel map with more than one channel and a mono channel -mal_bool32 mal_channel_map_valid(mal_uint32 channels, const mal_channel channelMap[MA_MAX_CHANNELS]); +ma_bool32 ma_channel_map_valid(ma_uint32 channels, const ma_channel channelMap[MA_MAX_CHANNELS]); // Helper for comparing two channel maps for equality. // // This assumes the channel count is the same between the two. -mal_bool32 mal_channel_map_equal(mal_uint32 channels, const mal_channel channelMapA[MA_MAX_CHANNELS], const mal_channel channelMapB[MA_MAX_CHANNELS]); +ma_bool32 ma_channel_map_equal(ma_uint32 channels, const ma_channel channelMapA[MA_MAX_CHANNELS], const ma_channel channelMapB[MA_MAX_CHANNELS]); // Helper for determining if a channel map is blank (all channels set to MA_CHANNEL_NONE). -mal_bool32 mal_channel_map_blank(mal_uint32 channels, const mal_channel channelMap[MA_MAX_CHANNELS]); +ma_bool32 ma_channel_map_blank(ma_uint32 channels, const ma_channel channelMap[MA_MAX_CHANNELS]); // Helper for determining whether or not a channel is present in the given channel map. -mal_bool32 mal_channel_map_contains_channel_position(mal_uint32 channels, const mal_channel channelMap[MA_MAX_CHANNELS], mal_channel channelPosition); +ma_bool32 ma_channel_map_contains_channel_position(ma_uint32 channels, const ma_channel channelMap[MA_MAX_CHANNELS], ma_channel channelPosition); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1079,20 +1079,20 @@ mal_bool32 mal_channel_map_contains_channel_position(mal_uint32 channels, const // interleaved input data (onRead) and another for deinterleaved input data (onReadDeinterleaved). You implement whichever is most convenient for you. You // can implement both, but it's not recommended as it just introduces unnecessary complexity. // -// To read data as interleaved samples, use mal_format_converter_read(). Otherwise use mal_format_converter_read_deinterleaved(). +// To read data as interleaved samples, use ma_format_converter_read(). Otherwise use ma_format_converter_read_deinterleaved(). // // Dithering // --------- // The format converter also supports dithering. Dithering can be set using ditherMode variable in the config, like so. // -// pConfig->ditherMode = mal_dither_mode_rectangle; +// pConfig->ditherMode = ma_dither_mode_rectangle; // // The different dithering modes include the following, in order of efficiency: -// - None: mal_dither_mode_none -// - Rectangle: mal_dither_mode_rectangle -// - Triangle: mal_dither_mode_triangle +// - None: ma_dither_mode_none +// - Rectangle: ma_dither_mode_rectangle +// - Triangle: ma_dither_mode_triangle // -// Note that even if the dither mode is set to something other than mal_dither_mode_none, it will be ignored for conversions where dithering is not needed. +// Note that even if the dither mode is set to something other than ma_dither_mode_none, it will be ignored for conversions where dithering is not needed. // Dithering is available for the following conversions: // - s16 -> u8 // - s24 -> u8 @@ -1102,24 +1102,24 @@ mal_bool32 mal_channel_map_contains_channel_position(mal_uint32 channels, const // - s32 -> s16 // - f32 -> s16 // -// Note that it is not an error to pass something other than mal_dither_mode_none for conversions where dither is not used. It will just be ignored. +// Note that it is not an error to pass something other than ma_dither_mode_none for conversions where dither is not used. It will just be ignored. // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Initializes a format converter. -mal_result mal_format_converter_init(const mal_format_converter_config* pConfig, mal_format_converter* pConverter); +ma_result ma_format_converter_init(const ma_format_converter_config* pConfig, ma_format_converter* pConverter); // Reads data from the format converter as interleaved channels. -mal_uint64 mal_format_converter_read(mal_format_converter* pConverter, mal_uint64 frameCount, void* pFramesOut, void* pUserData); +ma_uint64 ma_format_converter_read(ma_format_converter* pConverter, ma_uint64 frameCount, void* pFramesOut, void* pUserData); // Reads data from the format converter as deinterleaved channels. -mal_uint64 mal_format_converter_read_deinterleaved(mal_format_converter* pConverter, mal_uint64 frameCount, void** ppSamplesOut, void* pUserData); +ma_uint64 ma_format_converter_read_deinterleaved(ma_format_converter* pConverter, ma_uint64 frameCount, void** ppSamplesOut, void* pUserData); // Helper for initializing a format converter config. -mal_format_converter_config mal_format_converter_config_init_new(void); -mal_format_converter_config mal_format_converter_config_init(mal_format formatIn, mal_format formatOut, mal_uint32 channels, mal_format_converter_read_proc onRead, void* pUserData); -mal_format_converter_config mal_format_converter_config_init_deinterleaved(mal_format formatIn, mal_format formatOut, mal_uint32 channels, mal_format_converter_read_deinterleaved_proc onReadDeinterleaved, void* pUserData); +ma_format_converter_config ma_format_converter_config_init_new(void); +ma_format_converter_config ma_format_converter_config_init(ma_format formatIn, ma_format formatOut, ma_uint32 channels, ma_format_converter_read_proc onRead, void* pUserData); +ma_format_converter_config ma_format_converter_config_init_deinterleaved(ma_format formatIn, ma_format formatOut, ma_uint32 channels, ma_format_converter_read_deinterleaved_proc onReadDeinterleaved, void* pUserData); @@ -1180,22 +1180,22 @@ mal_format_converter_config mal_format_converter_config_init_deinterleaved(mal_f // // Note that input and output data is always deinterleaved 32-bit floating point. // -// Initialize the channel router with mal_channel_router_init(). You will need to pass in a config object which specifies the input and output configuration, +// Initialize the channel router with ma_channel_router_init(). You will need to pass in a config object which specifies the input and output configuration, // mixing mode and a callback for sending data to the router. This callback will be called when input data needs to be sent to the router for processing. Note // that the mixing mode is only used when a 1:1 mapping is unavailable. This includes the custom weights mode. // -// Read data from the channel router with mal_channel_router_read_deinterleaved(). Output data is always 32-bit floating point. +// Read data from the channel router with ma_channel_router_read_deinterleaved(). Output data is always 32-bit floating point. // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Initializes a channel router where it is assumed that the input data is non-interleaved. -mal_result mal_channel_router_init(const mal_channel_router_config* pConfig, mal_channel_router* pRouter); +ma_result ma_channel_router_init(const ma_channel_router_config* pConfig, ma_channel_router* pRouter); // Reads data from the channel router as deinterleaved channels. -mal_uint64 mal_channel_router_read_deinterleaved(mal_channel_router* pRouter, mal_uint64 frameCount, void** ppSamplesOut, void* pUserData); +ma_uint64 ma_channel_router_read_deinterleaved(ma_channel_router* pRouter, ma_uint64 frameCount, void** ppSamplesOut, void* pUserData); // Helper for initializing a channel router config. -mal_channel_router_config mal_channel_router_config_init(mal_uint32 channelsIn, const mal_channel channelMapIn[MA_MAX_CHANNELS], mal_uint32 channelsOut, const mal_channel channelMapOut[MA_MAX_CHANNELS], mal_channel_mix_mode mixingMode, mal_channel_router_read_deinterleaved_proc onRead, void* pUserData); +ma_channel_router_config ma_channel_router_config_init(ma_uint32 channelsIn, const ma_channel channelMapIn[MA_MAX_CHANNELS], ma_uint32 channelsOut, const ma_channel channelMapOut[MA_MAX_CHANNELS], ma_channel_mix_mode mixingMode, ma_channel_router_read_deinterleaved_proc onRead, void* pUserData); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1206,23 +1206,23 @@ mal_channel_router_config mal_channel_router_config_init(mal_uint32 channelsIn, ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Initializes a sample rate conversion object. -mal_result mal_src_init(const mal_src_config* pConfig, mal_src* pSRC); +ma_result ma_src_init(const ma_src_config* pConfig, ma_src* pSRC); // Dynamically adjusts the sample rate. // // This is useful for dynamically adjust pitch. Keep in mind, however, that this will speed up or slow down the sound. If this // is not acceptable you will need to use your own algorithm. -mal_result mal_src_set_sample_rate(mal_src* pSRC, mal_uint32 sampleRateIn, mal_uint32 sampleRateOut); +ma_result ma_src_set_sample_rate(ma_src* pSRC, ma_uint32 sampleRateIn, ma_uint32 sampleRateOut); // Reads a number of frames. // // Returns the number of frames actually read. -mal_uint64 mal_src_read_deinterleaved(mal_src* pSRC, mal_uint64 frameCount, void** ppSamplesOut, void* pUserData); +ma_uint64 ma_src_read_deinterleaved(ma_src* pSRC, ma_uint64 frameCount, void** ppSamplesOut, void* pUserData); // Helper for creating a sample rate conversion config. -mal_src_config mal_src_config_init_new(void); -mal_src_config mal_src_config_init(mal_uint32 sampleRateIn, mal_uint32 sampleRateOut, mal_uint32 channels, mal_src_read_deinterleaved_proc onReadDeinterleaved, void* pUserData); +ma_src_config ma_src_config_init_new(void); +ma_src_config ma_src_config_init(ma_uint32 sampleRateIn, ma_uint32 sampleRateOut, ma_uint32 channels, ma_src_read_deinterleaved_proc onReadDeinterleaved, void* pUserData); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1232,14 +1232,14 @@ mal_src_config mal_src_config_init(mal_uint32 sampleRateIn, mal_uint32 sampleRat ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Initializes a DSP object. -mal_result mal_pcm_converter_init(const mal_pcm_converter_config* pConfig, mal_pcm_converter* pDSP); +ma_result ma_pcm_converter_init(const ma_pcm_converter_config* pConfig, ma_pcm_converter* pDSP); // Dynamically adjusts the input sample rate. // // This will fail is the DSP was not initialized with allowDynamicSampleRate. // -// DEPRECATED. Use mal_pcm_converter_set_sample_rate() instead. -mal_result mal_pcm_converter_set_input_sample_rate(mal_pcm_converter* pDSP, mal_uint32 sampleRateOut); +// DEPRECATED. Use ma_pcm_converter_set_sample_rate() instead. +ma_result ma_pcm_converter_set_input_sample_rate(ma_pcm_converter* pDSP, ma_uint32 sampleRateOut); // Dynamically adjusts the output sample rate. // @@ -1248,8 +1248,8 @@ mal_result mal_pcm_converter_set_input_sample_rate(mal_pcm_converter* pDSP, mal_ // // This will fail is the DSP was not initialized with allowDynamicSampleRate. // -// DEPRECATED. Use mal_pcm_converter_set_sample_rate() instead. -mal_result mal_pcm_converter_set_output_sample_rate(mal_pcm_converter* pDSP, mal_uint32 sampleRateOut); +// DEPRECATED. Use ma_pcm_converter_set_sample_rate() instead. +ma_result ma_pcm_converter_set_output_sample_rate(ma_pcm_converter* pDSP, ma_uint32 sampleRateOut); // Dynamically adjusts the output sample rate. // @@ -1257,16 +1257,16 @@ mal_result mal_pcm_converter_set_output_sample_rate(mal_pcm_converter* pDSP, mal // is not acceptable you will need to use your own algorithm. // // This will fail is the DSP was not initialized with allowDynamicSampleRate. -mal_result mal_pcm_converter_set_sample_rate(mal_pcm_converter* pDSP, mal_uint32 sampleRateIn, mal_uint32 sampleRateOut); +ma_result ma_pcm_converter_set_sample_rate(ma_pcm_converter* pDSP, ma_uint32 sampleRateIn, ma_uint32 sampleRateOut); // Reads a number of frames and runs them through the DSP processor. -mal_uint64 mal_pcm_converter_read(mal_pcm_converter* pDSP, void* pFramesOut, mal_uint64 frameCount); +ma_uint64 ma_pcm_converter_read(ma_pcm_converter* pDSP, void* pFramesOut, ma_uint64 frameCount); -// Helper for initializing a mal_pcm_converter_config object. -mal_pcm_converter_config mal_pcm_converter_config_init_new(void); -mal_pcm_converter_config mal_pcm_converter_config_init(mal_format formatIn, mal_uint32 channelsIn, mal_uint32 sampleRateIn, mal_format formatOut, mal_uint32 channelsOut, mal_uint32 sampleRateOut, mal_pcm_converter_read_proc onRead, void* pUserData); -mal_pcm_converter_config mal_pcm_converter_config_init_ex(mal_format formatIn, mal_uint32 channelsIn, mal_uint32 sampleRateIn, mal_channel channelMapIn[MA_MAX_CHANNELS], mal_format formatOut, mal_uint32 channelsOut, mal_uint32 sampleRateOut, mal_channel channelMapOut[MA_MAX_CHANNELS], mal_pcm_converter_read_proc onRead, void* pUserData); +// Helper for initializing a ma_pcm_converter_config object. +ma_pcm_converter_config ma_pcm_converter_config_init_new(void); +ma_pcm_converter_config ma_pcm_converter_config_init(ma_format formatIn, ma_uint32 channelsIn, ma_uint32 sampleRateIn, ma_format formatOut, ma_uint32 channelsOut, ma_uint32 sampleRateOut, ma_pcm_converter_read_proc onRead, void* pUserData); +ma_pcm_converter_config ma_pcm_converter_config_init_ex(ma_format formatIn, ma_uint32 channelsIn, ma_uint32 sampleRateIn, ma_channel channelMapIn[MA_MAX_CHANNELS], ma_format formatOut, ma_uint32 channelsOut, ma_uint32 sampleRateOut, ma_channel channelMapOut[MA_MAX_CHANNELS], ma_pcm_converter_read_proc onRead, void* pUserData); // High-level helper for doing a full format conversion in one go. Returns the number of output frames. Call this with pOut set to NULL to @@ -1275,8 +1275,8 @@ mal_pcm_converter_config mal_pcm_converter_config_init_ex(mal_format formatIn, m // A return value of 0 indicates an error. // // This function is useful for one-off bulk conversions, but if you're streaming data you should use the DSP APIs instead. -mal_uint64 mal_convert_frames(void* pOut, mal_format formatOut, mal_uint32 channelsOut, mal_uint32 sampleRateOut, const void* pIn, mal_format formatIn, mal_uint32 channelsIn, mal_uint32 sampleRateIn, mal_uint64 frameCount); -mal_uint64 mal_convert_frames_ex(void* pOut, mal_format formatOut, mal_uint32 channelsOut, mal_uint32 sampleRateOut, mal_channel channelMapOut[MA_MAX_CHANNELS], const void* pIn, mal_format formatIn, mal_uint32 channelsIn, mal_uint32 sampleRateIn, mal_channel channelMapIn[MA_MAX_CHANNELS], mal_uint64 frameCount); +ma_uint64 ma_convert_frames(void* pOut, ma_format formatOut, ma_uint32 channelsOut, ma_uint32 sampleRateOut, const void* pIn, ma_format formatIn, ma_uint32 channelsIn, ma_uint32 sampleRateIn, ma_uint64 frameCount); +ma_uint64 ma_convert_frames_ex(void* pOut, ma_format formatOut, ma_uint32 channelsOut, ma_uint32 sampleRateOut, ma_channel channelMapOut[MA_MAX_CHANNELS], const void* pIn, ma_format formatIn, ma_uint32 channelsIn, ma_uint32 sampleRateIn, ma_channel channelMapIn[MA_MAX_CHANNELS], ma_uint64 frameCount); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1292,28 +1292,28 @@ mal_uint64 mal_convert_frames_ex(void* pOut, mal_format formatOut, mal_uint32 ch // // Usage // ----- -// - Call mal_rb_init() to initialize a simple buffer, with an optional pre-allocated buffer. If you pass in NULL -// for the pre-allocated buffer, it will be allocated for you and free()'d in mal_rb_uninit(). If you pass in +// - Call ma_rb_init() to initialize a simple buffer, with an optional pre-allocated buffer. If you pass in NULL +// for the pre-allocated buffer, it will be allocated for you and free()'d in ma_rb_uninit(). If you pass in // your own pre-allocated buffer, free()-ing is left to you. // -// - Call mal_rb_init_ex() if you need a deinterleaved buffer. The data for each sub-buffer is offset from each -// other based on the stride. Use mal_rb_get_subbuffer_stride(), mal_rb_get_subbuffer_offset() and -// mal_rb_get_subbuffer_ptr() to manage your sub-buffers. +// - Call ma_rb_init_ex() if you need a deinterleaved buffer. The data for each sub-buffer is offset from each +// other based on the stride. Use ma_rb_get_subbuffer_stride(), ma_rb_get_subbuffer_offset() and +// ma_rb_get_subbuffer_ptr() to manage your sub-buffers. // -// - Use mal_rb_acquire_read() and mal_rb_acquire_write() to retrieve a pointer to a section of the ring buffer. +// - Use ma_rb_acquire_read() and ma_rb_acquire_write() to retrieve a pointer to a section of the ring buffer. // You specify the number of bytes you need, and on output it will set to what was actually acquired. If the // read or write pointer is positioned such that the number of bytes requested will require a loop, it will be // clamped to the end of the buffer. Therefore, the number of bytes you're given may be less than the number // you requested. // -// - After calling mal_rb_acquire_read/write(), you do your work on the buffer and then "commit" it with -// mal_rb_commit_read/write(). This is where the read/write pointers are updated. When you commit you need to -// pass in the buffer that was returned by the earlier call to mal_rb_acquire_read/write() and is only used -// for validation. The number of bytes passed to mal_rb_commit_read/write() is what's used to increment the +// - After calling ma_rb_acquire_read/write(), you do your work on the buffer and then "commit" it with +// ma_rb_commit_read/write(). This is where the read/write pointers are updated. When you commit you need to +// pass in the buffer that was returned by the earlier call to ma_rb_acquire_read/write() and is only used +// for validation. The number of bytes passed to ma_rb_commit_read/write() is what's used to increment the // pointers. // // - If you want to correct for drift between the write pointer and the read pointer you can use a combination -// of mal_rb_pointer_distance(), mal_rb_seek_read() and mal_rb_seek_write(). Note that you can only move the +// of ma_rb_pointer_distance(), ma_rb_seek_read() and ma_rb_seek_write(). Note that you can only move the // pointers forward, and you should only move the read pointer forward via the consumer thread, and the write // pointer forward by the producer thread. If there is too much space between the pointers, move the read // pointer forward. If there is too little space between the pointers, move the write pointer forward. @@ -1324,7 +1324,7 @@ mal_uint64 mal_convert_frames_ex(void* pOut, mal_format formatOut, mal_uint32 ch // - Thread safety depends on a single producer, single consumer model. Only one thread is allowed to write, and // only one thread is allowed to read. The producer is the only one allowed to move the write pointer, and the // consumer is the only one allowed to move the read pointer. -// - Operates on bytes. Use mal_pcm_rb to operate in terms of PCM frames. +// - Operates on bytes. Use ma_pcm_rb to operate in terms of PCM frames. // - Maximum buffer size in bytes is 0x7FFFFFFF-(MA_SIMD_ALIGNMENT-1) because of reasons. // // @@ -1336,52 +1336,52 @@ mal_uint64 mal_convert_frames_ex(void* pOut, mal_format formatOut, mal_uint32 ch typedef struct { void* pBuffer; - mal_uint32 subbufferSizeInBytes; - mal_uint32 subbufferCount; - mal_uint32 subbufferStrideInBytes; - volatile mal_uint32 encodedReadOffset; /* Most significant bit is the loop flag. Lower 31 bits contains the actual offset in bytes. */ - volatile mal_uint32 encodedWriteOffset; /* Most significant bit is the loop flag. Lower 31 bits contains the actual offset in bytes. */ - mal_bool32 ownsBuffer : 1; /* Used to know whether or not miniaudio is responsible for free()-ing the buffer. */ - mal_bool32 clearOnWriteAcquire : 1; /* When set, clears the acquired write buffer before returning from mal_rb_acquire_write(). */ -} mal_rb; + ma_uint32 subbufferSizeInBytes; + ma_uint32 subbufferCount; + ma_uint32 subbufferStrideInBytes; + volatile ma_uint32 encodedReadOffset; /* Most significant bit is the loop flag. Lower 31 bits contains the actual offset in bytes. */ + volatile ma_uint32 encodedWriteOffset; /* Most significant bit is the loop flag. Lower 31 bits contains the actual offset in bytes. */ + ma_bool32 ownsBuffer : 1; /* Used to know whether or not miniaudio is responsible for free()-ing the buffer. */ + ma_bool32 clearOnWriteAcquire : 1; /* When set, clears the acquired write buffer before returning from ma_rb_acquire_write(). */ +} ma_rb; -mal_result mal_rb_init_ex(size_t subbufferSizeInBytes, size_t subbufferCount, size_t subbufferStrideInBytes, void* pOptionalPreallocatedBuffer, mal_rb* pRB); -mal_result mal_rb_init(size_t bufferSizeInBytes, void* pOptionalPreallocatedBuffer, mal_rb* pRB); -void mal_rb_uninit(mal_rb* pRB); -mal_result mal_rb_acquire_read(mal_rb* pRB, size_t* pSizeInBytes, void** ppBufferOut); -mal_result mal_rb_commit_read(mal_rb* pRB, size_t sizeInBytes, void* pBufferOut); -mal_result mal_rb_acquire_write(mal_rb* pRB, size_t* pSizeInBytes, void** ppBufferOut); -mal_result mal_rb_commit_write(mal_rb* pRB, size_t sizeInBytes, void* pBufferOut); -mal_result mal_rb_seek_read(mal_rb* pRB, size_t offsetInBytes); -mal_result mal_rb_seek_write(mal_rb* pRB, size_t offsetInBytes); -mal_int32 mal_rb_pointer_distance(mal_rb* pRB); /* Returns the distance between the write pointer and the read pointer. Should never be negative for a correct program. */ -size_t mal_rb_get_subbuffer_size(mal_rb* pRB); -size_t mal_rb_get_subbuffer_stride(mal_rb* pRB); -size_t mal_rb_get_subbuffer_offset(mal_rb* pRB, size_t subbufferIndex); -void* mal_rb_get_subbuffer_ptr(mal_rb* pRB, size_t subbufferIndex, void* pBuffer); +ma_result ma_rb_init_ex(size_t subbufferSizeInBytes, size_t subbufferCount, size_t subbufferStrideInBytes, void* pOptionalPreallocatedBuffer, ma_rb* pRB); +ma_result ma_rb_init(size_t bufferSizeInBytes, void* pOptionalPreallocatedBuffer, ma_rb* pRB); +void ma_rb_uninit(ma_rb* pRB); +ma_result ma_rb_acquire_read(ma_rb* pRB, size_t* pSizeInBytes, void** ppBufferOut); +ma_result ma_rb_commit_read(ma_rb* pRB, size_t sizeInBytes, void* pBufferOut); +ma_result ma_rb_acquire_write(ma_rb* pRB, size_t* pSizeInBytes, void** ppBufferOut); +ma_result ma_rb_commit_write(ma_rb* pRB, size_t sizeInBytes, void* pBufferOut); +ma_result ma_rb_seek_read(ma_rb* pRB, size_t offsetInBytes); +ma_result ma_rb_seek_write(ma_rb* pRB, size_t offsetInBytes); +ma_int32 ma_rb_pointer_distance(ma_rb* pRB); /* Returns the distance between the write pointer and the read pointer. Should never be negative for a correct program. */ +size_t ma_rb_get_subbuffer_size(ma_rb* pRB); +size_t ma_rb_get_subbuffer_stride(ma_rb* pRB); +size_t ma_rb_get_subbuffer_offset(ma_rb* pRB, size_t subbufferIndex); +void* ma_rb_get_subbuffer_ptr(ma_rb* pRB, size_t subbufferIndex, void* pBuffer); typedef struct { - mal_rb rb; - mal_format format; - mal_uint32 channels; -} mal_pcm_rb; + ma_rb rb; + ma_format format; + ma_uint32 channels; +} ma_pcm_rb; -mal_result mal_pcm_rb_init_ex(mal_format format, mal_uint32 channels, mal_uint32 subbufferSizeInFrames, mal_uint32 subbufferCount, mal_uint32 subbufferStrideInFrames, void* pOptionalPreallocatedBuffer, mal_pcm_rb* pRB); -mal_result mal_pcm_rb_init(mal_format format, mal_uint32 channels, mal_uint32 bufferSizeInFrames, void* pOptionalPreallocatedBuffer, mal_pcm_rb* pRB); -void mal_pcm_rb_uninit(mal_pcm_rb* pRB); -mal_result mal_pcm_rb_acquire_read(mal_pcm_rb* pRB, mal_uint32* pSizeInFrames, void** ppBufferOut); -mal_result mal_pcm_rb_commit_read(mal_pcm_rb* pRB, mal_uint32 sizeInFrames, void* pBufferOut); -mal_result mal_pcm_rb_acquire_write(mal_pcm_rb* pRB, mal_uint32* pSizeInFrames, void** ppBufferOut); -mal_result mal_pcm_rb_commit_write(mal_pcm_rb* pRB, mal_uint32 sizeInFrames, void* pBufferOut); -mal_result mal_pcm_rb_seek_read(mal_pcm_rb* pRB, mal_uint32 offsetInFrames); -mal_result mal_pcm_rb_seek_write(mal_pcm_rb* pRB, mal_uint32 offsetInFrames); -mal_int32 mal_pcm_rb_pointer_disance(mal_pcm_rb* pRB); /* Return value is in frames. */ -mal_uint32 mal_pcm_rb_get_subbuffer_size(mal_pcm_rb* pRB); -mal_uint32 mal_pcm_rb_get_subbuffer_stride(mal_pcm_rb* pRB); -mal_uint32 mal_pcm_rb_get_subbuffer_offset(mal_pcm_rb* pRB, mal_uint32 subbufferIndex); -void* mal_pcm_rb_get_subbuffer_ptr(mal_pcm_rb* pRB, mal_uint32 subbufferIndex, void* pBuffer); +ma_result ma_pcm_rb_init_ex(ma_format format, ma_uint32 channels, ma_uint32 subbufferSizeInFrames, ma_uint32 subbufferCount, ma_uint32 subbufferStrideInFrames, void* pOptionalPreallocatedBuffer, ma_pcm_rb* pRB); +ma_result ma_pcm_rb_init(ma_format format, ma_uint32 channels, ma_uint32 bufferSizeInFrames, void* pOptionalPreallocatedBuffer, ma_pcm_rb* pRB); +void ma_pcm_rb_uninit(ma_pcm_rb* pRB); +ma_result ma_pcm_rb_acquire_read(ma_pcm_rb* pRB, ma_uint32* pSizeInFrames, void** ppBufferOut); +ma_result ma_pcm_rb_commit_read(ma_pcm_rb* pRB, ma_uint32 sizeInFrames, void* pBufferOut); +ma_result ma_pcm_rb_acquire_write(ma_pcm_rb* pRB, ma_uint32* pSizeInFrames, void** ppBufferOut); +ma_result ma_pcm_rb_commit_write(ma_pcm_rb* pRB, ma_uint32 sizeInFrames, void* pBufferOut); +ma_result ma_pcm_rb_seek_read(ma_pcm_rb* pRB, ma_uint32 offsetInFrames); +ma_result ma_pcm_rb_seek_write(ma_pcm_rb* pRB, ma_uint32 offsetInFrames); +ma_int32 ma_pcm_rb_pointer_disance(ma_pcm_rb* pRB); /* Return value is in frames. */ +ma_uint32 ma_pcm_rb_get_subbuffer_size(ma_pcm_rb* pRB); +ma_uint32 ma_pcm_rb_get_subbuffer_stride(ma_pcm_rb* pRB); +ma_uint32 ma_pcm_rb_get_subbuffer_offset(ma_pcm_rb* pRB, ma_uint32 subbufferIndex); +void* ma_pcm_rb_get_subbuffer_ptr(ma_pcm_rb* pRB, ma_uint32 subbufferIndex, void* pBuffer); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1391,25 +1391,25 @@ void* mal_pcm_rb_get_subbuffer_ptr(mal_pcm_rb* pRB, mal_uint32 subbufferIndex, v ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // malloc(). Calls MA_MALLOC(). -void* mal_malloc(size_t sz); +void* ma_malloc(size_t sz); // realloc(). Calls MA_REALLOC(). -void* mal_realloc(void* p, size_t sz); +void* ma_realloc(void* p, size_t sz); // free(). Calls MA_FREE(). -void mal_free(void* p); +void ma_free(void* p); // Performs an aligned malloc, with the assumption that the alignment is a power of 2. -void* mal_aligned_malloc(size_t sz, size_t alignment); +void* ma_aligned_malloc(size_t sz, size_t alignment); // Free's an aligned malloc'd buffer. -void mal_aligned_free(void* p); +void ma_aligned_free(void* p); // Retrieves a friendly name for a format. -const char* mal_get_format_name(mal_format format); +const char* ma_get_format_name(ma_format format); // Blends two frames in floating point format. -void mal_blend_f32(float* pOut, float* pInA, float* pInB, float factor, mal_uint32 channels); +void ma_blend_f32(float* pOut, float* pInA, float* pInB, float factor, ma_uint32 channels); // Retrieves the size of a sample in bytes for the given format. // @@ -1417,8 +1417,8 @@ void mal_blend_f32(float* pOut, float* pInA, float* pInB, float factor, mal_uint // // Thread Safety: SAFE // This is API is pure. -mal_uint32 mal_get_bytes_per_sample(mal_format format); -static MA_INLINE mal_uint32 mal_get_bytes_per_frame(mal_format format, mal_uint32 channels) { return mal_get_bytes_per_sample(format) * channels; } +ma_uint32 ma_get_bytes_per_sample(ma_format format); +static MA_INLINE ma_uint32 ma_get_bytes_per_frame(ma_format format, ma_uint32 channels) { return ma_get_bytes_per_sample(format) * channels; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1426,33 +1426,33 @@ static MA_INLINE mal_uint32 mal_get_bytes_per_frame(mal_format format, mal_uint3 // Format Conversion // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -void mal_pcm_u8_to_s16(void* pOut, const void* pIn, mal_uint64 count, mal_dither_mode ditherMode); -void mal_pcm_u8_to_s24(void* pOut, const void* pIn, mal_uint64 count, mal_dither_mode ditherMode); -void mal_pcm_u8_to_s32(void* pOut, const void* pIn, mal_uint64 count, mal_dither_mode ditherMode); -void mal_pcm_u8_to_f32(void* pOut, const void* pIn, mal_uint64 count, mal_dither_mode ditherMode); -void mal_pcm_s16_to_u8(void* pOut, const void* pIn, mal_uint64 count, mal_dither_mode ditherMode); -void mal_pcm_s16_to_s24(void* pOut, const void* pIn, mal_uint64 count, mal_dither_mode ditherMode); -void mal_pcm_s16_to_s32(void* pOut, const void* pIn, mal_uint64 count, mal_dither_mode ditherMode); -void mal_pcm_s16_to_f32(void* pOut, const void* pIn, mal_uint64 count, mal_dither_mode ditherMode); -void mal_pcm_s24_to_u8(void* pOut, const void* pIn, mal_uint64 count, mal_dither_mode ditherMode); -void mal_pcm_s24_to_s16(void* pOut, const void* pIn, mal_uint64 count, mal_dither_mode ditherMode); -void mal_pcm_s24_to_s32(void* pOut, const void* pIn, mal_uint64 count, mal_dither_mode ditherMode); -void mal_pcm_s24_to_f32(void* pOut, const void* pIn, mal_uint64 count, mal_dither_mode ditherMode); -void mal_pcm_s32_to_u8(void* pOut, const void* pIn, mal_uint64 count, mal_dither_mode ditherMode); -void mal_pcm_s32_to_s16(void* pOut, const void* pIn, mal_uint64 count, mal_dither_mode ditherMode); -void mal_pcm_s32_to_s24(void* pOut, const void* pIn, mal_uint64 count, mal_dither_mode ditherMode); -void mal_pcm_s32_to_f32(void* pOut, const void* pIn, mal_uint64 count, mal_dither_mode ditherMode); -void mal_pcm_f32_to_u8(void* pOut, const void* pIn, mal_uint64 count, mal_dither_mode ditherMode); -void mal_pcm_f32_to_s16(void* pOut, const void* pIn, mal_uint64 count, mal_dither_mode ditherMode); -void mal_pcm_f32_to_s24(void* pOut, const void* pIn, mal_uint64 count, mal_dither_mode ditherMode); -void mal_pcm_f32_to_s32(void* pOut, const void* pIn, mal_uint64 count, mal_dither_mode ditherMode); -void mal_pcm_convert(void* pOut, mal_format formatOut, const void* pIn, mal_format formatIn, mal_uint64 sampleCount, mal_dither_mode ditherMode); +void ma_pcm_u8_to_s16(void* pOut, const void* pIn, ma_uint64 count, ma_dither_mode ditherMode); +void ma_pcm_u8_to_s24(void* pOut, const void* pIn, ma_uint64 count, ma_dither_mode ditherMode); +void ma_pcm_u8_to_s32(void* pOut, const void* pIn, ma_uint64 count, ma_dither_mode ditherMode); +void ma_pcm_u8_to_f32(void* pOut, const void* pIn, ma_uint64 count, ma_dither_mode ditherMode); +void ma_pcm_s16_to_u8(void* pOut, const void* pIn, ma_uint64 count, ma_dither_mode ditherMode); +void ma_pcm_s16_to_s24(void* pOut, const void* pIn, ma_uint64 count, ma_dither_mode ditherMode); +void ma_pcm_s16_to_s32(void* pOut, const void* pIn, ma_uint64 count, ma_dither_mode ditherMode); +void ma_pcm_s16_to_f32(void* pOut, const void* pIn, ma_uint64 count, ma_dither_mode ditherMode); +void ma_pcm_s24_to_u8(void* pOut, const void* pIn, ma_uint64 count, ma_dither_mode ditherMode); +void ma_pcm_s24_to_s16(void* pOut, const void* pIn, ma_uint64 count, ma_dither_mode ditherMode); +void ma_pcm_s24_to_s32(void* pOut, const void* pIn, ma_uint64 count, ma_dither_mode ditherMode); +void ma_pcm_s24_to_f32(void* pOut, const void* pIn, ma_uint64 count, ma_dither_mode ditherMode); +void ma_pcm_s32_to_u8(void* pOut, const void* pIn, ma_uint64 count, ma_dither_mode ditherMode); +void ma_pcm_s32_to_s16(void* pOut, const void* pIn, ma_uint64 count, ma_dither_mode ditherMode); +void ma_pcm_s32_to_s24(void* pOut, const void* pIn, ma_uint64 count, ma_dither_mode ditherMode); +void ma_pcm_s32_to_f32(void* pOut, const void* pIn, ma_uint64 count, ma_dither_mode ditherMode); +void ma_pcm_f32_to_u8(void* pOut, const void* pIn, ma_uint64 count, ma_dither_mode ditherMode); +void ma_pcm_f32_to_s16(void* pOut, const void* pIn, ma_uint64 count, ma_dither_mode ditherMode); +void ma_pcm_f32_to_s24(void* pOut, const void* pIn, ma_uint64 count, ma_dither_mode ditherMode); +void ma_pcm_f32_to_s32(void* pOut, const void* pIn, ma_uint64 count, ma_dither_mode ditherMode); +void ma_pcm_convert(void* pOut, ma_format formatOut, const void* pIn, ma_format formatIn, ma_uint64 sampleCount, ma_dither_mode ditherMode); // Deinterleaves an interleaved buffer. -void mal_deinterleave_pcm_frames(mal_format format, mal_uint32 channels, mal_uint64 frameCount, const void* pInterleavedPCMFrames, void** ppDeinterleavedPCMFrames); +void ma_deinterleave_pcm_frames(ma_format format, ma_uint32 channels, ma_uint64 frameCount, const void* pInterleavedPCMFrames, void** ppDeinterleavedPCMFrames); // Interleaves a group of deinterleaved buffers. -void mal_interleave_pcm_frames(mal_format format, mal_uint32 channels, mal_uint64 frameCount, const void** ppDeinterleavedPCMFrames, void* pInterleavedPCMFrames); +void ma_interleave_pcm_frames(ma_format format, ma_uint32 channels, ma_uint64 frameCount, const void** ppDeinterleavedPCMFrames, void* pInterleavedPCMFrames); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1461,7 +1461,7 @@ void mal_interleave_pcm_frames(mal_format format, mal_uint32 channels, mal_uint6 // DEVICE I/O // ========== // -// This section contains the APIs for device playback and capture. Here is where you'll find mal_device_init(), etc. +// This section contains the APIs for device playback and capture. Here is where you'll find ma_device_init(), etc. // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1560,53 +1560,53 @@ void mal_interleave_pcm_frames(mal_format format, mal_uint32 channels, mal_uint6 typedef struct { void* lpVtbl; - mal_uint32 counter; - mal_device* pDevice; -} mal_IMMNotificationClient; + ma_uint32 counter; + ma_device* pDevice; +} ma_IMMNotificationClient; #endif /* Backend enums must be in priority order. */ typedef enum { - mal_backend_wasapi, - mal_backend_dsound, - mal_backend_winmm, - mal_backend_coreaudio, - mal_backend_sndio, - mal_backend_audio4, - mal_backend_oss, - mal_backend_pulseaudio, - mal_backend_alsa, - mal_backend_jack, - mal_backend_aaudio, - mal_backend_opensl, - mal_backend_webaudio, - mal_backend_null /* <-- Must always be the last item. Lowest priority, and used as the terminator for backend enumeration. */ -} mal_backend; + ma_backend_wasapi, + ma_backend_dsound, + ma_backend_winmm, + ma_backend_coreaudio, + ma_backend_sndio, + ma_backend_audio4, + ma_backend_oss, + ma_backend_pulseaudio, + ma_backend_alsa, + ma_backend_jack, + ma_backend_aaudio, + ma_backend_opensl, + ma_backend_webaudio, + ma_backend_null /* <-- Must always be the last item. Lowest priority, and used as the terminator for backend enumeration. */ +} ma_backend; // Thread priorties should be ordered such that the default priority of the worker thread is 0. typedef enum { - mal_thread_priority_idle = -5, - mal_thread_priority_lowest = -4, - mal_thread_priority_low = -3, - mal_thread_priority_normal = -2, - mal_thread_priority_high = -1, - mal_thread_priority_highest = 0, - mal_thread_priority_realtime = 1, - mal_thread_priority_default = 0 -} mal_thread_priority; + ma_thread_priority_idle = -5, + ma_thread_priority_lowest = -4, + ma_thread_priority_low = -3, + ma_thread_priority_normal = -2, + ma_thread_priority_high = -1, + ma_thread_priority_highest = 0, + ma_thread_priority_realtime = 1, + ma_thread_priority_default = 0 +} ma_thread_priority; typedef struct { - mal_context* pContext; + ma_context* pContext; union { #ifdef MA_WIN32 struct { - /*HANDLE*/ mal_handle hThread; + /*HANDLE*/ ma_handle hThread; } win32; #endif #ifdef MA_POSIX @@ -1617,18 +1617,18 @@ typedef struct #endif int _unused; }; -} mal_thread; +} ma_thread; typedef struct { - mal_context* pContext; + ma_context* pContext; union { #ifdef MA_WIN32 struct { - /*HANDLE*/ mal_handle hMutex; + /*HANDLE*/ ma_handle hMutex; } win32; #endif #ifdef MA_POSIX @@ -1639,18 +1639,18 @@ typedef struct #endif int _unused; }; -} mal_mutex; +} ma_mutex; typedef struct { - mal_context* pContext; + ma_context* pContext; union { #ifdef MA_WIN32 struct { - /*HANDLE*/ mal_handle hEvent; + /*HANDLE*/ ma_handle hEvent; } win32; #endif #ifdef MA_POSIX @@ -1658,12 +1658,12 @@ typedef struct { pthread_mutex_t mutex; pthread_cond_t condition; - mal_uint32 value; + ma_uint32 value; } posix; #endif int _unused; }; -} mal_event; +} ma_event; /* @@ -1679,19 +1679,19 @@ frameCount is the number of PCM frames to process. If an output buffer is provid to the entire output buffer. Do _not_ call any miniaudio APIs from the callback. Attempting the stop the device can result in a deadlock. The proper way to stop the -device is to call mal_device_stop() from a different thread, normally the main application thread. +device is to call ma_device_stop() from a different thread, normally the main application thread. */ -typedef void (* mal_device_callback_proc)(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 frameCount); +typedef void (* ma_device_callback_proc)(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount); /* The callback for when the device has been stopped. -This will be called when the device is stopped explicitly with mal_device_stop() and also called implicitly when the device is stopped +This will be called when the device is stopped explicitly with ma_device_stop() and also called implicitly when the device is stopped through external forces such as being unplugged or an internal error occuring. Do not restart the device from the callback. */ -typedef void (* mal_stop_proc)(mal_device* pDevice); +typedef void (* ma_stop_proc)(ma_device* pDevice); /* The callback for handling log messages. @@ -1705,20 +1705,20 @@ logLevel is one of the following: MA_LOG_LEVEL_WARNING MA_LOG_LEVEL_ERROR */ -typedef void (* mal_log_proc)(mal_context* pContext, mal_device* pDevice, mal_uint32 logLevel, const char* message); +typedef void (* ma_log_proc)(ma_context* pContext, ma_device* pDevice, ma_uint32 logLevel, const char* message); typedef enum { - mal_device_type_playback = 1, - mal_device_type_capture = 2, - mal_device_type_duplex = mal_device_type_playback | mal_device_type_capture, -} mal_device_type; + ma_device_type_playback = 1, + ma_device_type_capture = 2, + ma_device_type_duplex = ma_device_type_playback | ma_device_type_capture, +} ma_device_type; typedef enum { - mal_share_mode_shared = 0, - mal_share_mode_exclusive, -} mal_share_mode; + ma_share_mode_shared = 0, + ma_share_mode_exclusive, +} ma_share_mode; typedef union { @@ -1726,10 +1726,10 @@ typedef union wchar_t wasapi[64]; // WASAPI uses a wchar_t string for identification. #endif #ifdef MA_SUPPORT_DSOUND - mal_uint8 dsound[16]; // DirectSound uses a GUID for identification. + ma_uint8 dsound[16]; // DirectSound uses a GUID for identification. #endif #ifdef MA_SUPPORT_WINMM - /*UINT_PTR*/ mal_uint32 winmm; // When creating a device, WinMM expects a Win32 UINT_PTR for device identification. In practice it's actually just a UINT. + /*UINT_PTR*/ ma_uint32 winmm; // When creating a device, WinMM expects a Win32 UINT_PTR for device identification. In practice it's actually just a UINT. #endif #ifdef MA_SUPPORT_ALSA char alsa[256]; // ALSA uses a name string for identification. @@ -1753,10 +1753,10 @@ typedef union char oss[64]; // "dev/dsp0", etc. "dev/dsp" for the default device. #endif #ifdef MA_SUPPORT_AAUDIO - mal_int32 aaudio; // AAudio uses a 32-bit integer for identification. + ma_int32 aaudio; // AAudio uses a 32-bit integer for identification. #endif #ifdef MA_SUPPORT_OPENSL - mal_uint32 opensl; // OpenSL|ES uses a 32-bit unsigned integer for identification. + ma_uint32 opensl; // OpenSL|ES uses a 32-bit unsigned integer for identification. #endif #ifdef MA_SUPPORT_WEBAUDIO char webaudio[32]; // Web Audio always uses default devices for now, but if this changes it'll be a GUID. @@ -1764,125 +1764,125 @@ typedef union #ifdef MA_SUPPORT_NULL int nullbackend; // The null backend uses an integer for device IDs. #endif -} mal_device_id; +} ma_device_id; typedef struct { // Basic info. This is the only information guaranteed to be filled in during device enumeration. - mal_device_id id; + ma_device_id id; char name[256]; - // Detailed info. As much of this is filled as possible with mal_context_get_device_info(). Note that you are allowed to initialize + // Detailed info. As much of this is filled as possible with ma_context_get_device_info(). Note that you are allowed to initialize // a device with settings outside of this range, but it just means the data will be converted using miniaudio's data conversion // pipeline before sending the data to/from the device. Most programs will need to not worry about these values, but it's provided // here mainly for informational purposes or in the rare case that someone might find it useful. // - // These will be set to 0 when returned by mal_context_enumerate_devices() or mal_context_get_devices(). - mal_uint32 formatCount; - mal_format formats[mal_format_count]; - mal_uint32 minChannels; - mal_uint32 maxChannels; - mal_uint32 minSampleRate; - mal_uint32 maxSampleRate; -} mal_device_info; + // These will be set to 0 when returned by ma_context_enumerate_devices() or ma_context_get_devices(). + ma_uint32 formatCount; + ma_format formats[ma_format_count]; + ma_uint32 minChannels; + ma_uint32 maxChannels; + ma_uint32 minSampleRate; + ma_uint32 maxSampleRate; +} ma_device_info; typedef struct { union { - mal_int64 counter; + ma_int64 counter; double counterD; }; -} mal_timer; +} ma_timer; typedef struct { - mal_device_type deviceType; - mal_uint32 sampleRate; - mal_uint32 bufferSizeInFrames; - mal_uint32 bufferSizeInMilliseconds; - mal_uint32 periods; - mal_performance_profile performanceProfile; - mal_device_callback_proc dataCallback; - mal_stop_proc stopCallback; + ma_device_type deviceType; + ma_uint32 sampleRate; + ma_uint32 bufferSizeInFrames; + ma_uint32 bufferSizeInMilliseconds; + ma_uint32 periods; + ma_performance_profile performanceProfile; + ma_device_callback_proc dataCallback; + ma_stop_proc stopCallback; void* pUserData; struct { - mal_device_id* pDeviceID; - mal_format format; - mal_uint32 channels; - mal_channel channelMap[MA_MAX_CHANNELS]; - mal_share_mode shareMode; + ma_device_id* pDeviceID; + ma_format format; + ma_uint32 channels; + ma_channel channelMap[MA_MAX_CHANNELS]; + ma_share_mode shareMode; } playback; struct { - mal_device_id* pDeviceID; - mal_format format; - mal_uint32 channels; - mal_channel channelMap[MA_MAX_CHANNELS]; - mal_share_mode shareMode; + ma_device_id* pDeviceID; + ma_format format; + ma_uint32 channels; + ma_channel channelMap[MA_MAX_CHANNELS]; + ma_share_mode shareMode; } capture; struct { - mal_bool32 noMMap; // Disables MMap mode. + ma_bool32 noMMap; // Disables MMap mode. } alsa; struct { const char* pStreamNamePlayback; const char* pStreamNameCapture; } pulse; -} mal_device_config; +} ma_device_config; typedef struct { - mal_log_proc logCallback; - mal_thread_priority threadPriority; + ma_log_proc logCallback; + ma_thread_priority threadPriority; struct { - mal_bool32 useVerboseDeviceEnumeration; + ma_bool32 useVerboseDeviceEnumeration; } alsa; struct { const char* pApplicationName; const char* pServerName; - mal_bool32 tryAutoSpawn; // Enables autospawning of the PulseAudio daemon if necessary. + ma_bool32 tryAutoSpawn; // Enables autospawning of the PulseAudio daemon if necessary. } pulse; struct { const char* pClientName; - mal_bool32 tryStartServer; + ma_bool32 tryStartServer; } jack; -} mal_context_config; +} ma_context_config; -typedef mal_bool32 (* mal_enum_devices_callback_proc)(mal_context* pContext, mal_device_type deviceType, const mal_device_info* pInfo, void* pUserData); +typedef ma_bool32 (* ma_enum_devices_callback_proc)(ma_context* pContext, ma_device_type deviceType, const ma_device_info* pInfo, void* pUserData); -struct mal_context +struct ma_context { - mal_backend backend; // DirectSound, ALSA, etc. - mal_context_config config; - mal_mutex deviceEnumLock; // Used to make mal_context_get_devices() thread safe. - mal_mutex deviceInfoLock; // Used to make mal_context_get_device_info() thread safe. - mal_uint32 deviceInfoCapacity; // Total capacity of pDeviceInfos. - mal_uint32 playbackDeviceInfoCount; - mal_uint32 captureDeviceInfoCount; - mal_device_info* pDeviceInfos; // Playback devices first, then capture. - mal_bool32 isBackendAsynchronous : 1; // Set when the context is initialized. Set to 1 for asynchronous backends such as Core Audio and JACK. Do not modify. + ma_backend backend; // DirectSound, ALSA, etc. + ma_context_config config; + ma_mutex deviceEnumLock; // Used to make ma_context_get_devices() thread safe. + ma_mutex deviceInfoLock; // Used to make ma_context_get_device_info() thread safe. + ma_uint32 deviceInfoCapacity; // Total capacity of pDeviceInfos. + ma_uint32 playbackDeviceInfoCount; + ma_uint32 captureDeviceInfoCount; + ma_device_info* pDeviceInfos; // Playback devices first, then capture. + ma_bool32 isBackendAsynchronous : 1; // Set when the context is initialized. Set to 1 for asynchronous backends such as Core Audio and JACK. Do not modify. - mal_result (* onUninit )(mal_context* pContext); - mal_bool32 (* onDeviceIDEqual )(mal_context* pContext, const mal_device_id* pID0, const mal_device_id* pID1); - mal_result (* onEnumDevices )(mal_context* pContext, mal_enum_devices_callback_proc callback, void* pUserData); // Return false from the callback to stop enumeration. - mal_result (* onGetDeviceInfo )(mal_context* pContext, mal_device_type deviceType, const mal_device_id* pDeviceID, mal_share_mode shareMode, mal_device_info* pDeviceInfo); - mal_result (* onDeviceInit )(mal_context* pContext, const mal_device_config* pConfig, mal_device* pDevice); - void (* onDeviceUninit )(mal_device* pDevice); - mal_result (* onDeviceStart )(mal_device* pDevice); - mal_result (* onDeviceStop )(mal_device* pDevice); - mal_result (* onDeviceWrite )(mal_device* pDevice, const void* pPCMFrames, mal_uint32 frameCount); /* Data is in internal device format. */ - mal_result (* onDeviceRead )(mal_device* pDevice, void* pPCMFrames, mal_uint32 frameCount); /* Data is in internal device format. */ - mal_result (* onDeviceMainLoop)(mal_device* pDevice); + ma_result (* onUninit )(ma_context* pContext); + ma_bool32 (* onDeviceIDEqual )(ma_context* pContext, const ma_device_id* pID0, const ma_device_id* pID1); + ma_result (* onEnumDevices )(ma_context* pContext, ma_enum_devices_callback_proc callback, void* pUserData); // Return false from the callback to stop enumeration. + ma_result (* onGetDeviceInfo )(ma_context* pContext, ma_device_type deviceType, const ma_device_id* pDeviceID, ma_share_mode shareMode, ma_device_info* pDeviceInfo); + ma_result (* onDeviceInit )(ma_context* pContext, const ma_device_config* pConfig, ma_device* pDevice); + void (* onDeviceUninit )(ma_device* pDevice); + ma_result (* onDeviceStart )(ma_device* pDevice); + ma_result (* onDeviceStop )(ma_device* pDevice); + ma_result (* onDeviceWrite )(ma_device* pDevice, const void* pPCMFrames, ma_uint32 frameCount); /* Data is in internal device format. */ + ma_result (* onDeviceRead )(ma_device* pDevice, void* pPCMFrames, ma_uint32 frameCount); /* Data is in internal device format. */ + ma_result (* onDeviceMainLoop)(ma_device* pDevice); union { @@ -1895,220 +1895,220 @@ struct mal_context #ifdef MA_SUPPORT_DSOUND struct { - mal_handle hDSoundDLL; - mal_proc DirectSoundCreate; - mal_proc DirectSoundEnumerateA; - mal_proc DirectSoundCaptureCreate; - mal_proc DirectSoundCaptureEnumerateA; + ma_handle hDSoundDLL; + ma_proc DirectSoundCreate; + ma_proc DirectSoundEnumerateA; + ma_proc DirectSoundCaptureCreate; + ma_proc DirectSoundCaptureEnumerateA; } dsound; #endif #ifdef MA_SUPPORT_WINMM struct { - mal_handle hWinMM; - mal_proc waveOutGetNumDevs; - mal_proc waveOutGetDevCapsA; - mal_proc waveOutOpen; - mal_proc waveOutClose; - mal_proc waveOutPrepareHeader; - mal_proc waveOutUnprepareHeader; - mal_proc waveOutWrite; - mal_proc waveOutReset; - mal_proc waveInGetNumDevs; - mal_proc waveInGetDevCapsA; - mal_proc waveInOpen; - mal_proc waveInClose; - mal_proc waveInPrepareHeader; - mal_proc waveInUnprepareHeader; - mal_proc waveInAddBuffer; - mal_proc waveInStart; - mal_proc waveInReset; + ma_handle hWinMM; + ma_proc waveOutGetNumDevs; + ma_proc waveOutGetDevCapsA; + ma_proc waveOutOpen; + ma_proc waveOutClose; + ma_proc waveOutPrepareHeader; + ma_proc waveOutUnprepareHeader; + ma_proc waveOutWrite; + ma_proc waveOutReset; + ma_proc waveInGetNumDevs; + ma_proc waveInGetDevCapsA; + ma_proc waveInOpen; + ma_proc waveInClose; + ma_proc waveInPrepareHeader; + ma_proc waveInUnprepareHeader; + ma_proc waveInAddBuffer; + ma_proc waveInStart; + ma_proc waveInReset; } winmm; #endif #ifdef MA_SUPPORT_ALSA struct { - mal_handle asoundSO; - mal_proc snd_pcm_open; - mal_proc snd_pcm_close; - mal_proc snd_pcm_hw_params_sizeof; - mal_proc snd_pcm_hw_params_any; - mal_proc snd_pcm_hw_params_set_format; - mal_proc snd_pcm_hw_params_set_format_first; - mal_proc snd_pcm_hw_params_get_format_mask; - mal_proc snd_pcm_hw_params_set_channels_near; - mal_proc snd_pcm_hw_params_set_rate_resample; - mal_proc snd_pcm_hw_params_set_rate_near; - mal_proc snd_pcm_hw_params_set_buffer_size_near; - mal_proc snd_pcm_hw_params_set_periods_near; - mal_proc snd_pcm_hw_params_set_access; - mal_proc snd_pcm_hw_params_get_format; - mal_proc snd_pcm_hw_params_get_channels; - mal_proc snd_pcm_hw_params_get_channels_min; - mal_proc snd_pcm_hw_params_get_channels_max; - mal_proc snd_pcm_hw_params_get_rate; - mal_proc snd_pcm_hw_params_get_rate_min; - mal_proc snd_pcm_hw_params_get_rate_max; - mal_proc snd_pcm_hw_params_get_buffer_size; - mal_proc snd_pcm_hw_params_get_periods; - mal_proc snd_pcm_hw_params_get_access; - mal_proc snd_pcm_hw_params; - mal_proc snd_pcm_sw_params_sizeof; - mal_proc snd_pcm_sw_params_current; - mal_proc snd_pcm_sw_params_get_boundary; - mal_proc snd_pcm_sw_params_set_avail_min; - mal_proc snd_pcm_sw_params_set_start_threshold; - mal_proc snd_pcm_sw_params_set_stop_threshold; - mal_proc snd_pcm_sw_params; - mal_proc snd_pcm_format_mask_sizeof; - mal_proc snd_pcm_format_mask_test; - mal_proc snd_pcm_get_chmap; - mal_proc snd_pcm_state; - mal_proc snd_pcm_prepare; - mal_proc snd_pcm_start; - mal_proc snd_pcm_drop; - mal_proc snd_pcm_drain; - mal_proc snd_device_name_hint; - mal_proc snd_device_name_get_hint; - mal_proc snd_card_get_index; - mal_proc snd_device_name_free_hint; - mal_proc snd_pcm_mmap_begin; - mal_proc snd_pcm_mmap_commit; - mal_proc snd_pcm_recover; - mal_proc snd_pcm_readi; - mal_proc snd_pcm_writei; - mal_proc snd_pcm_avail; - mal_proc snd_pcm_avail_update; - mal_proc snd_pcm_wait; - mal_proc snd_pcm_info; - mal_proc snd_pcm_info_sizeof; - mal_proc snd_pcm_info_get_name; - mal_proc snd_config_update_free_global; + ma_handle asoundSO; + ma_proc snd_pcm_open; + ma_proc snd_pcm_close; + ma_proc snd_pcm_hw_params_sizeof; + ma_proc snd_pcm_hw_params_any; + ma_proc snd_pcm_hw_params_set_format; + ma_proc snd_pcm_hw_params_set_format_first; + ma_proc snd_pcm_hw_params_get_format_mask; + ma_proc snd_pcm_hw_params_set_channels_near; + ma_proc snd_pcm_hw_params_set_rate_resample; + ma_proc snd_pcm_hw_params_set_rate_near; + ma_proc snd_pcm_hw_params_set_buffer_size_near; + ma_proc snd_pcm_hw_params_set_periods_near; + ma_proc snd_pcm_hw_params_set_access; + ma_proc snd_pcm_hw_params_get_format; + ma_proc snd_pcm_hw_params_get_channels; + ma_proc snd_pcm_hw_params_get_channels_min; + ma_proc snd_pcm_hw_params_get_channels_max; + ma_proc snd_pcm_hw_params_get_rate; + ma_proc snd_pcm_hw_params_get_rate_min; + ma_proc snd_pcm_hw_params_get_rate_max; + ma_proc snd_pcm_hw_params_get_buffer_size; + ma_proc snd_pcm_hw_params_get_periods; + ma_proc snd_pcm_hw_params_get_access; + ma_proc snd_pcm_hw_params; + ma_proc snd_pcm_sw_params_sizeof; + ma_proc snd_pcm_sw_params_current; + ma_proc snd_pcm_sw_params_get_boundary; + ma_proc snd_pcm_sw_params_set_avail_min; + ma_proc snd_pcm_sw_params_set_start_threshold; + ma_proc snd_pcm_sw_params_set_stop_threshold; + ma_proc snd_pcm_sw_params; + ma_proc snd_pcm_format_mask_sizeof; + ma_proc snd_pcm_format_mask_test; + ma_proc snd_pcm_get_chmap; + ma_proc snd_pcm_state; + ma_proc snd_pcm_prepare; + ma_proc snd_pcm_start; + ma_proc snd_pcm_drop; + ma_proc snd_pcm_drain; + ma_proc snd_device_name_hint; + ma_proc snd_device_name_get_hint; + ma_proc snd_card_get_index; + ma_proc snd_device_name_free_hint; + ma_proc snd_pcm_mmap_begin; + ma_proc snd_pcm_mmap_commit; + ma_proc snd_pcm_recover; + ma_proc snd_pcm_readi; + ma_proc snd_pcm_writei; + ma_proc snd_pcm_avail; + ma_proc snd_pcm_avail_update; + ma_proc snd_pcm_wait; + ma_proc snd_pcm_info; + ma_proc snd_pcm_info_sizeof; + ma_proc snd_pcm_info_get_name; + ma_proc snd_config_update_free_global; - mal_mutex internalDeviceEnumLock; + ma_mutex internalDeviceEnumLock; } alsa; #endif #ifdef MA_SUPPORT_PULSEAUDIO struct { - mal_handle pulseSO; - mal_proc pa_mainloop_new; - mal_proc pa_mainloop_free; - mal_proc pa_mainloop_get_api; - mal_proc pa_mainloop_iterate; - mal_proc pa_mainloop_wakeup; - mal_proc pa_context_new; - mal_proc pa_context_unref; - mal_proc pa_context_connect; - mal_proc pa_context_disconnect; - mal_proc pa_context_set_state_callback; - mal_proc pa_context_get_state; - mal_proc pa_context_get_sink_info_list; - mal_proc pa_context_get_source_info_list; - mal_proc pa_context_get_sink_info_by_name; - mal_proc pa_context_get_source_info_by_name; - mal_proc pa_operation_unref; - mal_proc pa_operation_get_state; - mal_proc pa_channel_map_init_extend; - mal_proc pa_channel_map_valid; - mal_proc pa_channel_map_compatible; - mal_proc pa_stream_new; - mal_proc pa_stream_unref; - mal_proc pa_stream_connect_playback; - mal_proc pa_stream_connect_record; - mal_proc pa_stream_disconnect; - mal_proc pa_stream_get_state; - mal_proc pa_stream_get_sample_spec; - mal_proc pa_stream_get_channel_map; - mal_proc pa_stream_get_buffer_attr; - mal_proc pa_stream_set_buffer_attr; - mal_proc pa_stream_get_device_name; - mal_proc pa_stream_set_write_callback; - mal_proc pa_stream_set_read_callback; - mal_proc pa_stream_flush; - mal_proc pa_stream_drain; - mal_proc pa_stream_is_corked; - mal_proc pa_stream_cork; - mal_proc pa_stream_trigger; - mal_proc pa_stream_begin_write; - mal_proc pa_stream_write; - mal_proc pa_stream_peek; - mal_proc pa_stream_drop; - mal_proc pa_stream_writable_size; - mal_proc pa_stream_readable_size; + ma_handle pulseSO; + ma_proc pa_mainloop_new; + ma_proc pa_mainloop_free; + ma_proc pa_mainloop_get_api; + ma_proc pa_mainloop_iterate; + ma_proc pa_mainloop_wakeup; + ma_proc pa_context_new; + ma_proc pa_context_unref; + ma_proc pa_context_connect; + ma_proc pa_context_disconnect; + ma_proc pa_context_set_state_callback; + ma_proc pa_context_get_state; + ma_proc pa_context_get_sink_info_list; + ma_proc pa_context_get_source_info_list; + ma_proc pa_context_get_sink_info_by_name; + ma_proc pa_context_get_source_info_by_name; + ma_proc pa_operation_unref; + ma_proc pa_operation_get_state; + ma_proc pa_channel_map_init_extend; + ma_proc pa_channel_map_valid; + ma_proc pa_channel_map_compatible; + ma_proc pa_stream_new; + ma_proc pa_stream_unref; + ma_proc pa_stream_connect_playback; + ma_proc pa_stream_connect_record; + ma_proc pa_stream_disconnect; + ma_proc pa_stream_get_state; + ma_proc pa_stream_get_sample_spec; + ma_proc pa_stream_get_channel_map; + ma_proc pa_stream_get_buffer_attr; + ma_proc pa_stream_set_buffer_attr; + ma_proc pa_stream_get_device_name; + ma_proc pa_stream_set_write_callback; + ma_proc pa_stream_set_read_callback; + ma_proc pa_stream_flush; + ma_proc pa_stream_drain; + ma_proc pa_stream_is_corked; + ma_proc pa_stream_cork; + ma_proc pa_stream_trigger; + ma_proc pa_stream_begin_write; + ma_proc pa_stream_write; + ma_proc pa_stream_peek; + ma_proc pa_stream_drop; + ma_proc pa_stream_writable_size; + ma_proc pa_stream_readable_size; } pulse; #endif #ifdef MA_SUPPORT_JACK struct { - mal_handle jackSO; - mal_proc jack_client_open; - mal_proc jack_client_close; - mal_proc jack_client_name_size; - mal_proc jack_set_process_callback; - mal_proc jack_set_buffer_size_callback; - mal_proc jack_on_shutdown; - mal_proc jack_get_sample_rate; - mal_proc jack_get_buffer_size; - mal_proc jack_get_ports; - mal_proc jack_activate; - mal_proc jack_deactivate; - mal_proc jack_connect; - mal_proc jack_port_register; - mal_proc jack_port_name; - mal_proc jack_port_get_buffer; - mal_proc jack_free; + ma_handle jackSO; + ma_proc jack_client_open; + ma_proc jack_client_close; + ma_proc jack_client_name_size; + ma_proc jack_set_process_callback; + ma_proc jack_set_buffer_size_callback; + ma_proc jack_on_shutdown; + ma_proc jack_get_sample_rate; + ma_proc jack_get_buffer_size; + ma_proc jack_get_ports; + ma_proc jack_activate; + ma_proc jack_deactivate; + ma_proc jack_connect; + ma_proc jack_port_register; + ma_proc jack_port_name; + ma_proc jack_port_get_buffer; + ma_proc jack_free; } jack; #endif #ifdef MA_SUPPORT_COREAUDIO struct { - mal_handle hCoreFoundation; - mal_proc CFStringGetCString; + ma_handle hCoreFoundation; + ma_proc CFStringGetCString; - mal_handle hCoreAudio; - mal_proc AudioObjectGetPropertyData; - mal_proc AudioObjectGetPropertyDataSize; - mal_proc AudioObjectSetPropertyData; - mal_proc AudioObjectAddPropertyListener; + ma_handle hCoreAudio; + ma_proc AudioObjectGetPropertyData; + ma_proc AudioObjectGetPropertyDataSize; + ma_proc AudioObjectSetPropertyData; + ma_proc AudioObjectAddPropertyListener; - mal_handle hAudioUnit; // Could possibly be set to AudioToolbox on later versions of macOS. - mal_proc AudioComponentFindNext; - mal_proc AudioComponentInstanceDispose; - mal_proc AudioComponentInstanceNew; - mal_proc AudioOutputUnitStart; - mal_proc AudioOutputUnitStop; - mal_proc AudioUnitAddPropertyListener; - mal_proc AudioUnitGetPropertyInfo; - mal_proc AudioUnitGetProperty; - mal_proc AudioUnitSetProperty; - mal_proc AudioUnitInitialize; - mal_proc AudioUnitRender; + ma_handle hAudioUnit; // Could possibly be set to AudioToolbox on later versions of macOS. + ma_proc AudioComponentFindNext; + ma_proc AudioComponentInstanceDispose; + ma_proc AudioComponentInstanceNew; + ma_proc AudioOutputUnitStart; + ma_proc AudioOutputUnitStop; + ma_proc AudioUnitAddPropertyListener; + ma_proc AudioUnitGetPropertyInfo; + ma_proc AudioUnitGetProperty; + ma_proc AudioUnitSetProperty; + ma_proc AudioUnitInitialize; + ma_proc AudioUnitRender; - /*AudioComponent*/ mal_ptr component; + /*AudioComponent*/ ma_ptr component; } coreaudio; #endif #ifdef MA_SUPPORT_SNDIO struct { - mal_handle sndioSO; - mal_proc sio_open; - mal_proc sio_close; - mal_proc sio_setpar; - mal_proc sio_getpar; - mal_proc sio_getcap; - mal_proc sio_start; - mal_proc sio_stop; - mal_proc sio_read; - mal_proc sio_write; - mal_proc sio_onmove; - mal_proc sio_nfds; - mal_proc sio_pollfd; - mal_proc sio_revents; - mal_proc sio_eof; - mal_proc sio_setvol; - mal_proc sio_onvol; - mal_proc sio_initpar; + ma_handle sndioSO; + ma_proc sio_open; + ma_proc sio_close; + ma_proc sio_setpar; + ma_proc sio_getpar; + ma_proc sio_getcap; + ma_proc sio_start; + ma_proc sio_stop; + ma_proc sio_read; + ma_proc sio_write; + ma_proc sio_onmove; + ma_proc sio_nfds; + ma_proc sio_pollfd; + ma_proc sio_revents; + ma_proc sio_eof; + ma_proc sio_setvol; + ma_proc sio_onvol; + ma_proc sio_initpar; } sndio; #endif #ifdef MA_SUPPORT_AUDIO4 @@ -2127,31 +2127,31 @@ struct mal_context #ifdef MA_SUPPORT_AAUDIO struct { - mal_handle hAAudio; /* libaaudio.so */ - mal_proc AAudio_createStreamBuilder; - mal_proc AAudioStreamBuilder_delete; - mal_proc AAudioStreamBuilder_setDeviceId; - mal_proc AAudioStreamBuilder_setDirection; - mal_proc AAudioStreamBuilder_setSharingMode; - mal_proc AAudioStreamBuilder_setFormat; - mal_proc AAudioStreamBuilder_setChannelCount; - mal_proc AAudioStreamBuilder_setSampleRate; - mal_proc AAudioStreamBuilder_setBufferCapacityInFrames; - mal_proc AAudioStreamBuilder_setFramesPerDataCallback; - mal_proc AAudioStreamBuilder_setDataCallback; - mal_proc AAudioStreamBuilder_setPerformanceMode; - mal_proc AAudioStreamBuilder_openStream; - mal_proc AAudioStream_close; - mal_proc AAudioStream_getState; - mal_proc AAudioStream_waitForStateChange; - mal_proc AAudioStream_getFormat; - mal_proc AAudioStream_getChannelCount; - mal_proc AAudioStream_getSampleRate; - mal_proc AAudioStream_getBufferCapacityInFrames; - mal_proc AAudioStream_getFramesPerDataCallback; - mal_proc AAudioStream_getFramesPerBurst; - mal_proc AAudioStream_requestStart; - mal_proc AAudioStream_requestStop; + ma_handle hAAudio; /* libaaudio.so */ + ma_proc AAudio_createStreamBuilder; + ma_proc AAudioStreamBuilder_delete; + ma_proc AAudioStreamBuilder_setDeviceId; + ma_proc AAudioStreamBuilder_setDirection; + ma_proc AAudioStreamBuilder_setSharingMode; + ma_proc AAudioStreamBuilder_setFormat; + ma_proc AAudioStreamBuilder_setChannelCount; + ma_proc AAudioStreamBuilder_setSampleRate; + ma_proc AAudioStreamBuilder_setBufferCapacityInFrames; + ma_proc AAudioStreamBuilder_setFramesPerDataCallback; + ma_proc AAudioStreamBuilder_setDataCallback; + ma_proc AAudioStreamBuilder_setPerformanceMode; + ma_proc AAudioStreamBuilder_openStream; + ma_proc AAudioStream_close; + ma_proc AAudioStream_getState; + ma_proc AAudioStream_waitForStateChange; + ma_proc AAudioStream_getFormat; + ma_proc AAudioStream_getChannelCount; + ma_proc AAudioStream_getSampleRate; + ma_proc AAudioStream_getBufferCapacityInFrames; + ma_proc AAudioStream_getFramesPerDataCallback; + ma_proc AAudioStream_getFramesPerBurst; + ma_proc AAudioStream_requestStart; + ma_proc AAudioStream_requestStop; } aaudio; #endif #ifdef MA_SUPPORT_OPENSL @@ -2179,107 +2179,107 @@ struct mal_context #ifdef MA_WIN32 struct { - /*HMODULE*/ mal_handle hOle32DLL; - mal_proc CoInitializeEx; - mal_proc CoUninitialize; - mal_proc CoCreateInstance; - mal_proc CoTaskMemFree; - mal_proc PropVariantClear; - mal_proc StringFromGUID2; + /*HMODULE*/ ma_handle hOle32DLL; + ma_proc CoInitializeEx; + ma_proc CoUninitialize; + ma_proc CoCreateInstance; + ma_proc CoTaskMemFree; + ma_proc PropVariantClear; + ma_proc StringFromGUID2; - /*HMODULE*/ mal_handle hUser32DLL; - mal_proc GetForegroundWindow; - mal_proc GetDesktopWindow; + /*HMODULE*/ ma_handle hUser32DLL; + ma_proc GetForegroundWindow; + ma_proc GetDesktopWindow; - /*HMODULE*/ mal_handle hAdvapi32DLL; - mal_proc RegOpenKeyExA; - mal_proc RegCloseKey; - mal_proc RegQueryValueExA; + /*HMODULE*/ ma_handle hAdvapi32DLL; + ma_proc RegOpenKeyExA; + ma_proc RegCloseKey; + ma_proc RegQueryValueExA; } win32; #endif #ifdef MA_POSIX struct { - mal_handle pthreadSO; - mal_proc pthread_create; - mal_proc pthread_join; - mal_proc pthread_mutex_init; - mal_proc pthread_mutex_destroy; - mal_proc pthread_mutex_lock; - mal_proc pthread_mutex_unlock; - mal_proc pthread_cond_init; - mal_proc pthread_cond_destroy; - mal_proc pthread_cond_wait; - mal_proc pthread_cond_signal; - mal_proc pthread_attr_init; - mal_proc pthread_attr_destroy; - mal_proc pthread_attr_setschedpolicy; - mal_proc pthread_attr_getschedparam; - mal_proc pthread_attr_setschedparam; + ma_handle pthreadSO; + ma_proc pthread_create; + ma_proc pthread_join; + ma_proc pthread_mutex_init; + ma_proc pthread_mutex_destroy; + ma_proc pthread_mutex_lock; + ma_proc pthread_mutex_unlock; + ma_proc pthread_cond_init; + ma_proc pthread_cond_destroy; + ma_proc pthread_cond_wait; + ma_proc pthread_cond_signal; + ma_proc pthread_attr_init; + ma_proc pthread_attr_destroy; + ma_proc pthread_attr_setschedpolicy; + ma_proc pthread_attr_getschedparam; + ma_proc pthread_attr_setschedparam; } posix; #endif int _unused; }; }; -MA_ALIGNED_STRUCT(MA_SIMD_ALIGNMENT) mal_device +MA_ALIGNED_STRUCT(MA_SIMD_ALIGNMENT) ma_device { - mal_context* pContext; - mal_device_type type; - mal_uint32 sampleRate; - mal_uint32 state; - mal_device_callback_proc onData; - mal_stop_proc onStop; + ma_context* pContext; + ma_device_type type; + ma_uint32 sampleRate; + ma_uint32 state; + ma_device_callback_proc onData; + ma_stop_proc onStop; void* pUserData; // Application defined data. - mal_mutex lock; - mal_event wakeupEvent; - mal_event startEvent; - mal_event stopEvent; - mal_thread thread; - mal_result workResult; // This is set by the worker thread after it's finished doing a job. - mal_bool32 usingDefaultSampleRate : 1; - mal_bool32 usingDefaultBufferSize : 1; - mal_bool32 usingDefaultPeriods : 1; - mal_bool32 isOwnerOfContext : 1; // When set to true, uninitializing the device will also uninitialize the context. Set to true when NULL is passed into mal_device_init(). + ma_mutex lock; + ma_event wakeupEvent; + ma_event startEvent; + ma_event stopEvent; + ma_thread thread; + ma_result workResult; // This is set by the worker thread after it's finished doing a job. + ma_bool32 usingDefaultSampleRate : 1; + ma_bool32 usingDefaultBufferSize : 1; + ma_bool32 usingDefaultPeriods : 1; + ma_bool32 isOwnerOfContext : 1; // When set to true, uninitializing the device will also uninitialize the context. Set to true when NULL is passed into ma_device_init(). struct { char name[256]; /* Maybe temporary. Likely to be replaced with a query API. */ - mal_share_mode shareMode; /* Set to whatever was passed in when the device was initialized. */ - mal_bool32 usingDefaultFormat : 1; - mal_bool32 usingDefaultChannels : 1; - mal_bool32 usingDefaultChannelMap : 1; - mal_format format; - mal_uint32 channels; - mal_channel channelMap[MA_MAX_CHANNELS]; - mal_format internalFormat; - mal_uint32 internalChannels; - mal_uint32 internalSampleRate; - mal_channel internalChannelMap[MA_MAX_CHANNELS]; - mal_uint32 internalBufferSizeInFrames; - mal_uint32 internalPeriods; - mal_pcm_converter converter; - mal_uint32 _dspFrameCount; // Internal use only. Used as the data source when reading from the device. - const mal_uint8* _dspFrames; // ^^^ AS ABOVE ^^^ + ma_share_mode shareMode; /* Set to whatever was passed in when the device was initialized. */ + ma_bool32 usingDefaultFormat : 1; + ma_bool32 usingDefaultChannels : 1; + ma_bool32 usingDefaultChannelMap : 1; + ma_format format; + ma_uint32 channels; + ma_channel channelMap[MA_MAX_CHANNELS]; + ma_format internalFormat; + ma_uint32 internalChannels; + ma_uint32 internalSampleRate; + ma_channel internalChannelMap[MA_MAX_CHANNELS]; + ma_uint32 internalBufferSizeInFrames; + ma_uint32 internalPeriods; + ma_pcm_converter converter; + ma_uint32 _dspFrameCount; // Internal use only. Used as the data source when reading from the device. + const ma_uint8* _dspFrames; // ^^^ AS ABOVE ^^^ } playback; struct { char name[256]; /* Maybe temporary. Likely to be replaced with a query API. */ - mal_share_mode shareMode; /* Set to whatever was passed in when the device was initialized. */ - mal_bool32 usingDefaultFormat : 1; - mal_bool32 usingDefaultChannels : 1; - mal_bool32 usingDefaultChannelMap : 1; - mal_format format; - mal_uint32 channels; - mal_channel channelMap[MA_MAX_CHANNELS]; - mal_format internalFormat; - mal_uint32 internalChannels; - mal_uint32 internalSampleRate; - mal_channel internalChannelMap[MA_MAX_CHANNELS]; - mal_uint32 internalBufferSizeInFrames; - mal_uint32 internalPeriods; - mal_pcm_converter converter; - mal_uint32 _dspFrameCount; // Internal use only. Used as the data source when reading from the device. - const mal_uint8* _dspFrames; // ^^^ AS ABOVE ^^^ + ma_share_mode shareMode; /* Set to whatever was passed in when the device was initialized. */ + ma_bool32 usingDefaultFormat : 1; + ma_bool32 usingDefaultChannels : 1; + ma_bool32 usingDefaultChannelMap : 1; + ma_format format; + ma_uint32 channels; + ma_channel channelMap[MA_MAX_CHANNELS]; + ma_format internalFormat; + ma_uint32 internalChannels; + ma_uint32 internalSampleRate; + ma_channel internalChannelMap[MA_MAX_CHANNELS]; + ma_uint32 internalBufferSizeInFrames; + ma_uint32 internalPeriods; + ma_pcm_converter converter; + ma_uint32 _dspFrameCount; // Internal use only. Used as the data source when reading from the device. + const ma_uint8* _dspFrames; // ^^^ AS ABOVE ^^^ } capture; union @@ -2287,122 +2287,122 @@ MA_ALIGNED_STRUCT(MA_SIMD_ALIGNMENT) mal_device #ifdef MA_SUPPORT_WASAPI struct { - /*IAudioClient**/ mal_ptr pAudioClientPlayback; - /*IAudioClient**/ mal_ptr pAudioClientCapture; - /*IAudioRenderClient**/ mal_ptr pRenderClient; - /*IAudioCaptureClient**/ mal_ptr pCaptureClient; - /*IMMDeviceEnumerator**/ mal_ptr pDeviceEnumerator; /* Used for IMMNotificationClient notifications. Required for detecting default device changes. */ - mal_IMMNotificationClient notificationClient; - /*HANDLE*/ mal_handle hEventPlayback; /* Auto reset. Initialized to signaled. */ - /*HANDLE*/ mal_handle hEventCapture; /* Auto reset. Initialized to unsignaled. */ - mal_uint32 actualBufferSizeInFramesPlayback; /* Value from GetBufferSize(). internalBufferSizeInFrames is not set to the _actual_ buffer size when low-latency shared mode is being used due to the way the IAudioClient3 API works. */ - mal_uint32 actualBufferSizeInFramesCapture; - mal_uint32 originalBufferSizeInFrames; - mal_uint32 originalBufferSizeInMilliseconds; - mal_uint32 originalPeriods; - mal_bool32 hasDefaultPlaybackDeviceChanged; /* <-- Make sure this is always a whole 32-bits because we use atomic assignments. */ - mal_bool32 hasDefaultCaptureDeviceChanged; /* <-- Make sure this is always a whole 32-bits because we use atomic assignments. */ - mal_uint32 periodSizeInFramesPlayback; - mal_uint32 periodSizeInFramesCapture; - mal_bool32 isStartedCapture; - mal_bool32 isStartedPlayback; + /*IAudioClient**/ ma_ptr pAudioClientPlayback; + /*IAudioClient**/ ma_ptr pAudioClientCapture; + /*IAudioRenderClient**/ ma_ptr pRenderClient; + /*IAudioCaptureClient**/ ma_ptr pCaptureClient; + /*IMMDeviceEnumerator**/ ma_ptr pDeviceEnumerator; /* Used for IMMNotificationClient notifications. Required for detecting default device changes. */ + ma_IMMNotificationClient notificationClient; + /*HANDLE*/ ma_handle hEventPlayback; /* Auto reset. Initialized to signaled. */ + /*HANDLE*/ ma_handle hEventCapture; /* Auto reset. Initialized to unsignaled. */ + ma_uint32 actualBufferSizeInFramesPlayback; /* Value from GetBufferSize(). internalBufferSizeInFrames is not set to the _actual_ buffer size when low-latency shared mode is being used due to the way the IAudioClient3 API works. */ + ma_uint32 actualBufferSizeInFramesCapture; + ma_uint32 originalBufferSizeInFrames; + ma_uint32 originalBufferSizeInMilliseconds; + ma_uint32 originalPeriods; + ma_bool32 hasDefaultPlaybackDeviceChanged; /* <-- Make sure this is always a whole 32-bits because we use atomic assignments. */ + ma_bool32 hasDefaultCaptureDeviceChanged; /* <-- Make sure this is always a whole 32-bits because we use atomic assignments. */ + ma_uint32 periodSizeInFramesPlayback; + ma_uint32 periodSizeInFramesCapture; + ma_bool32 isStartedCapture; + ma_bool32 isStartedPlayback; } wasapi; #endif #ifdef MA_SUPPORT_DSOUND struct { - /*LPDIRECTSOUND*/ mal_ptr pPlayback; - /*LPDIRECTSOUNDBUFFER*/ mal_ptr pPlaybackPrimaryBuffer; - /*LPDIRECTSOUNDBUFFER*/ mal_ptr pPlaybackBuffer; - /*LPDIRECTSOUNDCAPTURE*/ mal_ptr pCapture; - /*LPDIRECTSOUNDCAPTUREBUFFER*/ mal_ptr pCaptureBuffer; + /*LPDIRECTSOUND*/ ma_ptr pPlayback; + /*LPDIRECTSOUNDBUFFER*/ ma_ptr pPlaybackPrimaryBuffer; + /*LPDIRECTSOUNDBUFFER*/ ma_ptr pPlaybackBuffer; + /*LPDIRECTSOUNDCAPTURE*/ ma_ptr pCapture; + /*LPDIRECTSOUNDCAPTUREBUFFER*/ ma_ptr pCaptureBuffer; } dsound; #endif #ifdef MA_SUPPORT_WINMM struct { - /*HWAVEOUT*/ mal_handle hDevicePlayback; - /*HWAVEIN*/ mal_handle hDeviceCapture; - /*HANDLE*/ mal_handle hEventPlayback; - /*HANDLE*/ mal_handle hEventCapture; - mal_uint32 fragmentSizeInFrames; - mal_uint32 fragmentSizeInBytes; - mal_uint32 iNextHeaderPlayback; /* [0,periods). Used as an index into pWAVEHDRPlayback. */ - mal_uint32 iNextHeaderCapture; /* [0,periods). Used as an index into pWAVEHDRCapture. */ - mal_uint32 headerFramesConsumedPlayback; /* The number of PCM frames consumed in the buffer in pWAVEHEADER[iNextHeader]. */ - mal_uint32 headerFramesConsumedCapture; /* ^^^ */ - /*WAVEHDR**/ mal_uint8* pWAVEHDRPlayback; /* One instantiation for each period. */ - /*WAVEHDR**/ mal_uint8* pWAVEHDRCapture; /* One instantiation for each period. */ - mal_uint8* pIntermediaryBufferPlayback; - mal_uint8* pIntermediaryBufferCapture; - mal_uint8* _pHeapData; /* Used internally and is used for the heap allocated data for the intermediary buffer and the WAVEHDR structures. */ - mal_bool32 isStarted; + /*HWAVEOUT*/ ma_handle hDevicePlayback; + /*HWAVEIN*/ ma_handle hDeviceCapture; + /*HANDLE*/ ma_handle hEventPlayback; + /*HANDLE*/ ma_handle hEventCapture; + ma_uint32 fragmentSizeInFrames; + ma_uint32 fragmentSizeInBytes; + ma_uint32 iNextHeaderPlayback; /* [0,periods). Used as an index into pWAVEHDRPlayback. */ + ma_uint32 iNextHeaderCapture; /* [0,periods). Used as an index into pWAVEHDRCapture. */ + ma_uint32 headerFramesConsumedPlayback; /* The number of PCM frames consumed in the buffer in pWAVEHEADER[iNextHeader]. */ + ma_uint32 headerFramesConsumedCapture; /* ^^^ */ + /*WAVEHDR**/ ma_uint8* pWAVEHDRPlayback; /* One instantiation for each period. */ + /*WAVEHDR**/ ma_uint8* pWAVEHDRCapture; /* One instantiation for each period. */ + ma_uint8* pIntermediaryBufferPlayback; + ma_uint8* pIntermediaryBufferCapture; + ma_uint8* _pHeapData; /* Used internally and is used for the heap allocated data for the intermediary buffer and the WAVEHDR structures. */ + ma_bool32 isStarted; } winmm; #endif #ifdef MA_SUPPORT_ALSA struct { - /*snd_pcm_t**/ mal_ptr pPCMPlayback; - /*snd_pcm_t**/ mal_ptr pPCMCapture; - mal_bool32 isUsingMMapPlayback : 1; - mal_bool32 isUsingMMapCapture : 1; + /*snd_pcm_t**/ ma_ptr pPCMPlayback; + /*snd_pcm_t**/ ma_ptr pPCMCapture; + ma_bool32 isUsingMMapPlayback : 1; + ma_bool32 isUsingMMapCapture : 1; } alsa; #endif #ifdef MA_SUPPORT_PULSEAUDIO struct { - /*pa_mainloop**/ mal_ptr pMainLoop; - /*pa_mainloop_api**/ mal_ptr pAPI; - /*pa_context**/ mal_ptr pPulseContext; - /*pa_stream**/ mal_ptr pStreamPlayback; - /*pa_stream**/ mal_ptr pStreamCapture; - /*pa_context_state*/ mal_uint32 pulseContextState; + /*pa_mainloop**/ ma_ptr pMainLoop; + /*pa_mainloop_api**/ ma_ptr pAPI; + /*pa_context**/ ma_ptr pPulseContext; + /*pa_stream**/ ma_ptr pStreamPlayback; + /*pa_stream**/ ma_ptr pStreamCapture; + /*pa_context_state*/ ma_uint32 pulseContextState; void* pMappedBufferPlayback; const void* pMappedBufferCapture; - mal_uint32 mappedBufferFramesRemainingPlayback; - mal_uint32 mappedBufferFramesRemainingCapture; - mal_uint32 mappedBufferFramesCapacityPlayback; - mal_uint32 mappedBufferFramesCapacityCapture; - mal_bool32 breakFromMainLoop : 1; + ma_uint32 mappedBufferFramesRemainingPlayback; + ma_uint32 mappedBufferFramesRemainingCapture; + ma_uint32 mappedBufferFramesCapacityPlayback; + ma_uint32 mappedBufferFramesCapacityCapture; + ma_bool32 breakFromMainLoop : 1; } pulse; #endif #ifdef MA_SUPPORT_JACK struct { - /*jack_client_t**/ mal_ptr pClient; - /*jack_port_t**/ mal_ptr pPortsPlayback[MA_MAX_CHANNELS]; - /*jack_port_t**/ mal_ptr pPortsCapture[MA_MAX_CHANNELS]; + /*jack_client_t**/ ma_ptr pClient; + /*jack_port_t**/ ma_ptr pPortsPlayback[MA_MAX_CHANNELS]; + /*jack_port_t**/ ma_ptr pPortsCapture[MA_MAX_CHANNELS]; float* pIntermediaryBufferPlayback; // Typed as a float because JACK is always floating point. float* pIntermediaryBufferCapture; - mal_pcm_rb duplexRB; + ma_pcm_rb duplexRB; } jack; #endif #ifdef MA_SUPPORT_COREAUDIO struct { - mal_uint32 deviceObjectIDPlayback; - mal_uint32 deviceObjectIDCapture; - /*AudioUnit*/ mal_ptr audioUnitPlayback; - /*AudioUnit*/ mal_ptr audioUnitCapture; - /*AudioBufferList**/ mal_ptr pAudioBufferList; // Only used for input devices. - mal_event stopEvent; - mal_uint32 originalBufferSizeInFrames; - mal_uint32 originalBufferSizeInMilliseconds; - mal_uint32 originalPeriods; - mal_bool32 isDefaultPlaybackDevice; - mal_bool32 isDefaultCaptureDevice; - mal_bool32 isSwitchingPlaybackDevice; /* <-- Set to true when the default device has changed and miniaudio is in the process of switching. */ - mal_bool32 isSwitchingCaptureDevice; /* <-- Set to true when the default device has changed and miniaudio is in the process of switching. */ - mal_pcm_rb duplexRB; + ma_uint32 deviceObjectIDPlayback; + ma_uint32 deviceObjectIDCapture; + /*AudioUnit*/ ma_ptr audioUnitPlayback; + /*AudioUnit*/ ma_ptr audioUnitCapture; + /*AudioBufferList**/ ma_ptr pAudioBufferList; // Only used for input devices. + ma_event stopEvent; + ma_uint32 originalBufferSizeInFrames; + ma_uint32 originalBufferSizeInMilliseconds; + ma_uint32 originalPeriods; + ma_bool32 isDefaultPlaybackDevice; + ma_bool32 isDefaultCaptureDevice; + ma_bool32 isSwitchingPlaybackDevice; /* <-- Set to true when the default device has changed and miniaudio is in the process of switching. */ + ma_bool32 isSwitchingCaptureDevice; /* <-- Set to true when the default device has changed and miniaudio is in the process of switching. */ + ma_pcm_rb duplexRB; } coreaudio; #endif #ifdef MA_SUPPORT_SNDIO struct { - mal_ptr handlePlayback; - mal_ptr handleCapture; - mal_bool32 isStartedPlayback; - mal_bool32 isStartedCapture; + ma_ptr handlePlayback; + ma_ptr handleCapture; + ma_bool32 isStartedPlayback; + ma_bool32 isStartedCapture; } sndio; #endif #ifdef MA_SUPPORT_AUDIO4 @@ -2422,27 +2422,27 @@ MA_ALIGNED_STRUCT(MA_SIMD_ALIGNMENT) mal_device #ifdef MA_SUPPORT_AAUDIO struct { - /*AAudioStream**/ mal_ptr pStreamPlayback; - /*AAudioStream**/ mal_ptr pStreamCapture; - mal_pcm_rb duplexRB; + /*AAudioStream**/ ma_ptr pStreamPlayback; + /*AAudioStream**/ ma_ptr pStreamCapture; + ma_pcm_rb duplexRB; } aaudio; #endif #ifdef MA_SUPPORT_OPENSL struct { - /*SLObjectItf*/ mal_ptr pOutputMixObj; - /*SLOutputMixItf*/ mal_ptr pOutputMix; - /*SLObjectItf*/ mal_ptr pAudioPlayerObj; - /*SLPlayItf*/ mal_ptr pAudioPlayer; - /*SLObjectItf*/ mal_ptr pAudioRecorderObj; - /*SLRecordItf*/ mal_ptr pAudioRecorder; - /*SLAndroidSimpleBufferQueueItf*/ mal_ptr pBufferQueuePlayback; - /*SLAndroidSimpleBufferQueueItf*/ mal_ptr pBufferQueueCapture; - mal_uint32 currentBufferIndexPlayback; - mal_uint32 currentBufferIndexCapture; - mal_uint8* pBufferPlayback; // This is malloc()'d and is used for storing audio data. Typed as mal_uint8 for easy offsetting. - mal_uint8* pBufferCapture; - mal_pcm_rb duplexRB; + /*SLObjectItf*/ ma_ptr pOutputMixObj; + /*SLOutputMixItf*/ ma_ptr pOutputMix; + /*SLObjectItf*/ ma_ptr pAudioPlayerObj; + /*SLPlayItf*/ ma_ptr pAudioPlayer; + /*SLObjectItf*/ ma_ptr pAudioRecorderObj; + /*SLRecordItf*/ ma_ptr pAudioRecorder; + /*SLAndroidSimpleBufferQueueItf*/ ma_ptr pBufferQueuePlayback; + /*SLAndroidSimpleBufferQueueItf*/ ma_ptr pBufferQueueCapture; + ma_uint32 currentBufferIndexPlayback; + ma_uint32 currentBufferIndexCapture; + ma_uint8* pBufferPlayback; // This is malloc()'d and is used for storing audio data. Typed as ma_uint8 for easy offsetting. + ma_uint8* pBufferCapture; + ma_pcm_rb duplexRB; } opensl; #endif #ifdef MA_SUPPORT_WEBAUDIO @@ -2450,24 +2450,24 @@ MA_ALIGNED_STRUCT(MA_SIMD_ALIGNMENT) mal_device { int indexPlayback; /* We use a factory on the JavaScript side to manage devices and use an index for JS/C interop. */ int indexCapture; - mal_pcm_rb duplexRB; /* In external capture format. */ + ma_pcm_rb duplexRB; /* In external capture format. */ } webaudio; #endif #ifdef MA_SUPPORT_NULL struct { - mal_thread deviceThread; - mal_event operationEvent; - mal_event operationCompletionEvent; - mal_uint32 operation; - mal_result operationResult; - mal_timer timer; + ma_thread deviceThread; + ma_event operationEvent; + ma_event operationCompletionEvent; + ma_uint32 operation; + ma_result operationResult; + ma_timer timer; double priorRunTime; - mal_uint32 currentPeriodFramesRemainingPlayback; - mal_uint32 currentPeriodFramesRemainingCapture; - mal_uint64 lastProcessedFramePlayback; - mal_uint32 lastProcessedFrameCapture; - mal_bool32 isStarted; + ma_uint32 currentPeriodFramesRemainingPlayback; + ma_uint32 currentPeriodFramesRemainingCapture; + ma_uint64 lastProcessedFramePlayback; + ma_uint32 lastProcessedFrameCapture; + ma_bool32 isStarted; } null_device; #endif }; @@ -2481,8 +2481,8 @@ MA_ALIGNED_STRUCT(MA_SIMD_ALIGNMENT) mal_device // The context is used for selecting and initializing the relevant backends. // // Note that the location of the context cannot change throughout it's lifetime. Consider allocating -// the mal_context object with malloc() if this is an issue. The reason for this is that a pointer -// to the context is stored in the mal_device structure. +// the ma_context object with malloc() if this is an issue. The reason for this is that a pointer +// to the context is stored in the ma_device structure. // // is used to allow the application to prioritize backends depending on it's specific // requirements. This can be null in which case it uses the default priority, which is as follows: @@ -2511,7 +2511,7 @@ MA_ALIGNED_STRUCT(MA_SIMD_ALIGNMENT) mal_device // MA_SUCCESS if successful; any other error code otherwise. // // Thread Safety: UNSAFE -mal_result mal_context_init(const mal_backend backends[], mal_uint32 backendCount, const mal_context_config* pConfig, mal_context* pContext); +ma_result ma_context_init(const ma_backend backends[], ma_uint32 backendCount, const ma_context_config* pConfig, ma_context* pContext); // Uninitializes a context. // @@ -2521,12 +2521,12 @@ mal_result mal_context_init(const mal_backend backends[], mal_uint32 backendCoun // MA_SUCCESS if successful; any other error code otherwise. // // Thread Safety: UNSAFE -mal_result mal_context_uninit(mal_context* pContext); +ma_result ma_context_uninit(ma_context* pContext); // Enumerates over every device (both playback and capture). // -// This is a lower-level enumeration function to the easier to use mal_context_get_devices(). Use -// mal_context_enumerate_devices() if you would rather not incur an internal heap allocation, or +// This is a lower-level enumeration function to the easier to use ma_context_get_devices(). Use +// ma_context_enumerate_devices() if you would rather not incur an internal heap allocation, or // it simply suits your code better. // // Do _not_ assume the first enumerated device of a given type is the default device. @@ -2536,12 +2536,12 @@ mal_result mal_context_uninit(mal_context* pContext); // Note that this only retrieves the ID and name/description of the device. The reason for only // retrieving basic information is that it would otherwise require opening the backend device in // order to probe it for more detailed information which can be inefficient. Consider using -// mal_context_get_device_info() for this, but don't call it from within the enumeration callback. +// ma_context_get_device_info() for this, but don't call it from within the enumeration callback. // // In general, you should not do anything complicated from within the callback. In particular, do // not try initializing a device from within the callback. // -// Consider using mal_context_get_devices() for a simpler and safer API, albeit at the expense of +// Consider using ma_context_get_devices() for a simpler and safer API, albeit at the expense of // an internal heap allocation. // // Returning false from the callback will stop enumeration. Returning true will continue enumeration. @@ -2551,7 +2551,7 @@ mal_result mal_context_uninit(mal_context* pContext); // // Thread Safety: SAFE // This is guarded using a simple mutex lock. -mal_result mal_context_enumerate_devices(mal_context* pContext, mal_enum_devices_callback_proc callback, void* pUserData); +ma_result ma_context_enumerate_devices(ma_context* pContext, ma_enum_devices_callback_proc callback, void* pUserData); // Retrieves basic information about every active playback and/or capture device. // @@ -2562,8 +2562,8 @@ mal_result mal_context_enumerate_devices(mal_context* pContext, mal_enum_devices // The returned pointers will become invalid upon the next call this this function, or when the // context is uninitialized. Do not free the returned pointers. // -// This function follows the same enumeration rules as mal_context_enumerate_devices(). See -// documentation for mal_context_enumerate_devices() for more information. +// This function follows the same enumeration rules as ma_context_enumerate_devices(). See +// documentation for ma_context_enumerate_devices() for more information. // // Return Value: // MA_SUCCESS if successful; any other error code otherwise. @@ -2572,11 +2572,11 @@ mal_result mal_context_enumerate_devices(mal_context* pContext, mal_enum_devices // Since each call to this function invalidates the pointers from the previous call, you // should not be calling this simultaneously across multiple threads. Instead, you need to // make a copy of the returned data with your own higher level synchronization. -mal_result mal_context_get_devices(mal_context* pContext, mal_device_info** ppPlaybackDeviceInfos, mal_uint32* pPlaybackDeviceCount, mal_device_info** ppCaptureDeviceInfos, mal_uint32* pCaptureDeviceCount); +ma_result ma_context_get_devices(ma_context* pContext, ma_device_info** ppPlaybackDeviceInfos, ma_uint32* pPlaybackDeviceCount, ma_device_info** ppCaptureDeviceInfos, ma_uint32* pCaptureDeviceCount); // Retrieves information about a device with the given ID. // -// Do _not_ call this from within the mal_context_enumerate_devices() callback. +// Do _not_ call this from within the ma_context_enumerate_devices() callback. // // It's possible for a device to have different information and capabilities depending on wether or // not it's opened in shared or exclusive mode. For example, in shared mode, WASAPI always uses @@ -2592,22 +2592,22 @@ mal_result mal_context_get_devices(mal_context* pContext, mal_device_info** ppPl // // Thread Safety: SAFE // This is guarded using a simple mutex lock. -mal_result mal_context_get_device_info(mal_context* pContext, mal_device_type deviceType, const mal_device_id* pDeviceID, mal_share_mode shareMode, mal_device_info* pDeviceInfo); +ma_result ma_context_get_device_info(ma_context* pContext, ma_device_type deviceType, const ma_device_id* pDeviceID, ma_share_mode shareMode, ma_device_info* pDeviceInfo); // Initializes a device. // // The context can be null in which case it uses the default. This is equivalent to passing in a // context that was initialized like so: // -// mal_context_init(NULL, 0, NULL, &context); +// ma_context_init(NULL, 0, NULL, &context); // // Do not pass in null for the context if you are needing to open multiple devices. You can, // however, use null when initializing the first device, and then use device.pContext for the // initialization of other devices. // // The device's configuration is controlled with pConfig. This allows you to configure the sample -// format, channel count, sample rate, etc. Before calling mal_device_init(), you will need to -// initialize a mal_device_config object using mal_device_config_init(). You must set the callback in +// format, channel count, sample rate, etc. Before calling ma_device_init(), you will need to +// initialize a ma_device_config object using ma_device_config_init(). You must set the callback in // the device config. // // Passing in 0 to any property in pConfig will force the use of a default value. In the case of @@ -2616,7 +2616,7 @@ mal_result mal_context_get_device_info(mal_context* pContext, mal_device_type de // bufferSizeInMilliseconds (if both are set it will prioritize bufferSizeInFrames). If both are // set to zero, it will default to MA_BASE_BUFFER_SIZE_IN_MILLISECONDS_LOW_LATENCY or // MA_BASE_BUFFER_SIZE_IN_MILLISECONDS_CONSERVATIVE, depending on whether or not performanceProfile -// is set to mal_performance_profile_low_latency or mal_performance_profile_conservative. +// is set to ma_performance_profile_low_latency or ma_performance_profile_conservative. // // If you request exclusive mode and the backend does not support it an error will be returned. For // robustness, you may want to first try initializing the device in exclusive mode, and then fall back @@ -2654,18 +2654,18 @@ mal_result mal_context_get_device_info(mal_context* pContext, mal_device_type de // Thread Safety: UNSAFE // It is not safe to call this function simultaneously for different devices because some backends // depend on and mutate global state (such as OpenSL|ES). The same applies to calling this at the -// same time as mal_device_uninit(). -mal_result mal_device_init(mal_context* pContext, const mal_device_config* pConfig, mal_device* pDevice); +// same time as ma_device_uninit(). +ma_result ma_device_init(ma_context* pContext, const ma_device_config* pConfig, ma_device* pDevice); // Initializes a device without a context, with extra parameters for controlling the configuration // of the internal self-managed context. // -// See mal_device_init() and mal_context_init(). -mal_result mal_device_init_ex(const mal_backend backends[], mal_uint32 backendCount, const mal_context_config* pContextConfig, const mal_device_config* pConfig, mal_device* pDevice); +// See ma_device_init() and ma_context_init(). +ma_result ma_device_init_ex(const ma_backend backends[], ma_uint32 backendCount, const ma_context_config* pContextConfig, const ma_device_config* pConfig, ma_device* pDevice); // Uninitializes a device. // -// This will explicitly stop the device. You do not need to call mal_device_stop() beforehand, but it's +// This will explicitly stop the device. You do not need to call ma_device_stop() beforehand, but it's // harmless if you do. // // Return Value: @@ -2674,13 +2674,13 @@ mal_result mal_device_init_ex(const mal_backend backends[], mal_uint32 backendCo // Thread Safety: UNSAFE // As soon as this API is called the device should be considered undefined. All bets are off if you // try using the device at the same time as uninitializing it. -void mal_device_uninit(mal_device* pDevice); +void ma_device_uninit(ma_device* pDevice); // Sets the callback to use when the device has stopped, either explicitly or as a result of an error. // // Thread Safety: SAFE // This API is implemented as a simple atomic assignment. -void mal_device_set_stop_callback(mal_device* pDevice, mal_stop_proc proc); +void ma_device_set_stop_callback(ma_device* pDevice, ma_stop_proc proc); // Activates the device. For playback devices this begins playback. For capture devices it begins // recording. @@ -2696,9 +2696,9 @@ void mal_device_set_stop_callback(mal_device* pDevice, mal_stop_proc proc); // MA_SUCCESS if successful; any other error code otherwise. // // Thread Safety: SAFE -mal_result mal_device_start(mal_device* pDevice); +ma_result ma_device_start(ma_device* pDevice); -// Puts the device to sleep, but does not uninitialize it. Use mal_device_start() to start it up again. +// Puts the device to sleep, but does not uninitialize it. Use ma_device_start() to start it up again. // // This API needs to wait on the worker thread to stop the backend device properly before returning. It // also waits on a mutex for thread-safety. In addition, some backends need to wait for the device to @@ -2707,7 +2707,7 @@ mal_result mal_device_start(mal_device* pDevice); // // This should not drop unprocessed samples. Backends are required to either pause the stream in-place // or drain the buffer if pausing is not possible. The reason for this is that stopping the device and -// the resuming it with mal_device_start() (which you might do when your program loses focus) may result +// the resuming it with ma_device_start() (which you might do when your program loses focus) may result // in a situation where those samples are never output to the speakers or received from the microphone // which can in turn result in de-syncs. // @@ -2715,7 +2715,7 @@ mal_result mal_device_start(mal_device* pDevice); // MA_SUCCESS if successful; any other error code otherwise. // // Thread Safety: SAFE -mal_result mal_device_stop(mal_device* pDevice); +ma_result ma_device_stop(ma_device* pDevice); // Determines whether or not the device is started. // @@ -2725,13 +2725,13 @@ mal_result mal_device_stop(mal_device* pDevice); // True if the device is started, false otherwise. // // Thread Safety: SAFE -// If another thread calls mal_device_start() or mal_device_stop() at this same time as this function +// If another thread calls ma_device_start() or ma_device_stop() at this same time as this function // is called, there's a very small chance the return value will be out of sync. -mal_bool32 mal_device_is_started(mal_device* pDevice); +ma_bool32 ma_device_is_started(ma_device* pDevice); -// Helper function for initializing a mal_context_config object. -mal_context_config mal_context_config_init(void); +// Helper function for initializing a ma_context_config object. +ma_context_config ma_context_config_init(void); // Initializes a device config. // @@ -2740,36 +2740,36 @@ mal_context_config mal_context_config_init(void); // need to do all format conversions manually. Normally you would want to use a known format that your program can handle // natively, which you can do by specifying it after this function returns, like so: // -// mal_device_config config = mal_device_config_init(mal_device_type_playback); +// ma_device_config config = ma_device_config_init(ma_device_type_playback); // config.callback = my_data_callback; // config.pUserData = pMyUserData; -// config.format = mal_format_f32; +// config.format = ma_format_f32; // config.channels = 2; // config.sampleRate = 44100; // // In this case miniaudio will perform all of the necessary data conversion for you behind the scenes. // // Currently miniaudio only supports asynchronous, callback based data delivery which means you must specify callback. A -// pointer to user data can also be specified which is set in the pUserData member of the mal_device object. +// pointer to user data can also be specified which is set in the pUserData member of the ma_device object. // -// To specify a channel map you can use mal_get_standard_channel_map(): +// To specify a channel map you can use ma_get_standard_channel_map(): // -// mal_get_standard_channel_map(mal_standard_channel_map_default, config.channels, config.channelMap); +// ma_get_standard_channel_map(ma_standard_channel_map_default, config.channels, config.channelMap); // // Alternatively you can set the channel map manually if you need something specific or something that isn't one of miniaudio's // stock channel maps. // -// By default the system's default device will be used. Set the pDeviceID member to a pointer to a mal_device_id object to -// use a specific device. You can enumerate over the devices with mal_context_enumerate_devices() or mal_context_get_devices() +// By default the system's default device will be used. Set the pDeviceID member to a pointer to a ma_device_id object to +// use a specific device. You can enumerate over the devices with ma_context_enumerate_devices() or ma_context_get_devices() // which will give you access to the device ID. Set pDeviceID to NULL to use the default device. // -// The device type can be one of the mal_device_type's: -// mal_device_type_playback -// mal_device_type_capture -// mal_device_type_duplex +// The device type can be one of the ma_device_type's: +// ma_device_type_playback +// ma_device_type_capture +// ma_device_type_duplex // // Thread Safety: SAFE -mal_device_config mal_device_config_init(mal_device_type deviceType); +ma_device_config ma_device_config_init(ma_device_type deviceType); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -2781,41 +2781,41 @@ mal_device_config mal_device_config_init(mal_device_type deviceType); // Creates a mutex. // // A mutex must be created from a valid context. A mutex is initially unlocked. -mal_result mal_mutex_init(mal_context* pContext, mal_mutex* pMutex); +ma_result ma_mutex_init(ma_context* pContext, ma_mutex* pMutex); // Deletes a mutex. -void mal_mutex_uninit(mal_mutex* pMutex); +void ma_mutex_uninit(ma_mutex* pMutex); // Locks a mutex with an infinite timeout. -void mal_mutex_lock(mal_mutex* pMutex); +void ma_mutex_lock(ma_mutex* pMutex); // Unlocks a mutex. -void mal_mutex_unlock(mal_mutex* pMutex); +void ma_mutex_unlock(ma_mutex* pMutex); // Retrieves a friendly name for a backend. -const char* mal_get_backend_name(mal_backend backend); +const char* ma_get_backend_name(ma_backend backend); // Adjust buffer size based on a scaling factor. // // This just multiplies the base size by the scaling factor, making sure it's a size of at least 1. -mal_uint32 mal_scale_buffer_size(mal_uint32 baseBufferSize, float scale); +ma_uint32 ma_scale_buffer_size(ma_uint32 baseBufferSize, float scale); // Calculates a buffer size in milliseconds from the specified number of frames and sample rate. -mal_uint32 mal_calculate_buffer_size_in_milliseconds_from_frames(mal_uint32 bufferSizeInFrames, mal_uint32 sampleRate); +ma_uint32 ma_calculate_buffer_size_in_milliseconds_from_frames(ma_uint32 bufferSizeInFrames, ma_uint32 sampleRate); // Calculates a buffer size in frames from the specified number of milliseconds and sample rate. -mal_uint32 mal_calculate_buffer_size_in_frames_from_milliseconds(mal_uint32 bufferSizeInMilliseconds, mal_uint32 sampleRate); +ma_uint32 ma_calculate_buffer_size_in_frames_from_milliseconds(ma_uint32 bufferSizeInMilliseconds, ma_uint32 sampleRate); // Retrieves the default buffer size in milliseconds based on the specified performance profile. -mal_uint32 mal_get_default_buffer_size_in_milliseconds(mal_performance_profile performanceProfile); +ma_uint32 ma_get_default_buffer_size_in_milliseconds(ma_performance_profile performanceProfile); // Calculates a buffer size in frames for the specified performance profile and scale factor. -mal_uint32 mal_get_default_buffer_size_in_frames(mal_performance_profile performanceProfile, mal_uint32 sampleRate); +ma_uint32 ma_get_default_buffer_size_in_frames(ma_performance_profile performanceProfile, ma_uint32 sampleRate); // Copies silent frames into the given buffer. -void mal_zero_pcm_frames(void* p, mal_uint32 frameCount, mal_format format, mal_uint32 channels); +void ma_zero_pcm_frames(void* p, ma_uint32 frameCount, ma_format format, ma_uint32 channels); #endif // MA_NO_DEVICE_IO @@ -2829,92 +2829,92 @@ void mal_zero_pcm_frames(void* p, mal_uint32 frameCount, mal_format format, mal_ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #ifndef MA_NO_DECODING -typedef struct mal_decoder mal_decoder; +typedef struct ma_decoder ma_decoder; typedef enum { - mal_seek_origin_start, - mal_seek_origin_current -} mal_seek_origin; + ma_seek_origin_start, + ma_seek_origin_current +} ma_seek_origin; -typedef size_t (* mal_decoder_read_proc) (mal_decoder* pDecoder, void* pBufferOut, size_t bytesToRead); // Returns the number of bytes read. -typedef mal_bool32 (* mal_decoder_seek_proc) (mal_decoder* pDecoder, int byteOffset, mal_seek_origin origin); -typedef mal_result (* mal_decoder_seek_to_pcm_frame_proc)(mal_decoder* pDecoder, mal_uint64 frameIndex); -typedef mal_result (* mal_decoder_uninit_proc) (mal_decoder* pDecoder); +typedef size_t (* ma_decoder_read_proc) (ma_decoder* pDecoder, void* pBufferOut, size_t bytesToRead); // Returns the number of bytes read. +typedef ma_bool32 (* ma_decoder_seek_proc) (ma_decoder* pDecoder, int byteOffset, ma_seek_origin origin); +typedef ma_result (* ma_decoder_seek_to_pcm_frame_proc)(ma_decoder* pDecoder, ma_uint64 frameIndex); +typedef ma_result (* ma_decoder_uninit_proc) (ma_decoder* pDecoder); typedef struct { - mal_format format; // Set to 0 or mal_format_unknown to use the stream's internal format. - mal_uint32 channels; // Set to 0 to use the stream's internal channels. - mal_uint32 sampleRate; // Set to 0 to use the stream's internal sample rate. - mal_channel channelMap[MA_MAX_CHANNELS]; - mal_channel_mix_mode channelMixMode; - mal_dither_mode ditherMode; - mal_src_algorithm srcAlgorithm; + ma_format format; // Set to 0 or ma_format_unknown to use the stream's internal format. + ma_uint32 channels; // Set to 0 to use the stream's internal channels. + ma_uint32 sampleRate; // Set to 0 to use the stream's internal sample rate. + ma_channel channelMap[MA_MAX_CHANNELS]; + ma_channel_mix_mode channelMixMode; + ma_dither_mode ditherMode; + ma_src_algorithm srcAlgorithm; union { - mal_src_config_sinc sinc; + ma_src_config_sinc sinc; } src; -} mal_decoder_config; +} ma_decoder_config; -struct mal_decoder +struct ma_decoder { - mal_decoder_read_proc onRead; - mal_decoder_seek_proc onSeek; + ma_decoder_read_proc onRead; + ma_decoder_seek_proc onSeek; void* pUserData; - mal_format internalFormat; - mal_uint32 internalChannels; - mal_uint32 internalSampleRate; - mal_channel internalChannelMap[MA_MAX_CHANNELS]; - mal_format outputFormat; - mal_uint32 outputChannels; - mal_uint32 outputSampleRate; - mal_channel outputChannelMap[MA_MAX_CHANNELS]; - mal_pcm_converter dsp; // <-- Format conversion is achieved by running frames through this. - mal_decoder_seek_to_pcm_frame_proc onSeekToPCMFrame; - mal_decoder_uninit_proc onUninit; + ma_format internalFormat; + ma_uint32 internalChannels; + ma_uint32 internalSampleRate; + ma_channel internalChannelMap[MA_MAX_CHANNELS]; + ma_format outputFormat; + ma_uint32 outputChannels; + ma_uint32 outputSampleRate; + ma_channel outputChannelMap[MA_MAX_CHANNELS]; + ma_pcm_converter dsp; // <-- Format conversion is achieved by running frames through this. + ma_decoder_seek_to_pcm_frame_proc onSeekToPCMFrame; + ma_decoder_uninit_proc onUninit; void* pInternalDecoder; // <-- The drwav/drflac/stb_vorbis/etc. objects. struct { - const mal_uint8* pData; + const ma_uint8* pData; size_t dataSize; size_t currentReadPos; } memory; // Only used for decoders that were opened against a block of memory. }; -mal_decoder_config mal_decoder_config_init(mal_format outputFormat, mal_uint32 outputChannels, mal_uint32 outputSampleRate); +ma_decoder_config ma_decoder_config_init(ma_format outputFormat, ma_uint32 outputChannels, ma_uint32 outputSampleRate); -mal_result mal_decoder_init(mal_decoder_read_proc onRead, mal_decoder_seek_proc onSeek, void* pUserData, const mal_decoder_config* pConfig, mal_decoder* pDecoder); -mal_result mal_decoder_init_wav(mal_decoder_read_proc onRead, mal_decoder_seek_proc onSeek, void* pUserData, const mal_decoder_config* pConfig, mal_decoder* pDecoder); -mal_result mal_decoder_init_flac(mal_decoder_read_proc onRead, mal_decoder_seek_proc onSeek, void* pUserData, const mal_decoder_config* pConfig, mal_decoder* pDecoder); -mal_result mal_decoder_init_vorbis(mal_decoder_read_proc onRead, mal_decoder_seek_proc onSeek, void* pUserData, const mal_decoder_config* pConfig, mal_decoder* pDecoder); -mal_result mal_decoder_init_mp3(mal_decoder_read_proc onRead, mal_decoder_seek_proc onSeek, void* pUserData, const mal_decoder_config* pConfig, mal_decoder* pDecoder); -mal_result mal_decoder_init_raw(mal_decoder_read_proc onRead, mal_decoder_seek_proc onSeek, void* pUserData, const mal_decoder_config* pConfigIn, const mal_decoder_config* pConfigOut, mal_decoder* pDecoder); +ma_result ma_decoder_init(ma_decoder_read_proc onRead, ma_decoder_seek_proc onSeek, void* pUserData, const ma_decoder_config* pConfig, ma_decoder* pDecoder); +ma_result ma_decoder_init_wav(ma_decoder_read_proc onRead, ma_decoder_seek_proc onSeek, void* pUserData, const ma_decoder_config* pConfig, ma_decoder* pDecoder); +ma_result ma_decoder_init_flac(ma_decoder_read_proc onRead, ma_decoder_seek_proc onSeek, void* pUserData, const ma_decoder_config* pConfig, ma_decoder* pDecoder); +ma_result ma_decoder_init_vorbis(ma_decoder_read_proc onRead, ma_decoder_seek_proc onSeek, void* pUserData, const ma_decoder_config* pConfig, ma_decoder* pDecoder); +ma_result ma_decoder_init_mp3(ma_decoder_read_proc onRead, ma_decoder_seek_proc onSeek, void* pUserData, const ma_decoder_config* pConfig, ma_decoder* pDecoder); +ma_result ma_decoder_init_raw(ma_decoder_read_proc onRead, ma_decoder_seek_proc onSeek, void* pUserData, const ma_decoder_config* pConfigIn, const ma_decoder_config* pConfigOut, ma_decoder* pDecoder); -mal_result mal_decoder_init_memory(const void* pData, size_t dataSize, const mal_decoder_config* pConfig, mal_decoder* pDecoder); -mal_result mal_decoder_init_memory_wav(const void* pData, size_t dataSize, const mal_decoder_config* pConfig, mal_decoder* pDecoder); -mal_result mal_decoder_init_memory_flac(const void* pData, size_t dataSize, const mal_decoder_config* pConfig, mal_decoder* pDecoder); -mal_result mal_decoder_init_memory_vorbis(const void* pData, size_t dataSize, const mal_decoder_config* pConfig, mal_decoder* pDecoder); -mal_result mal_decoder_init_memory_mp3(const void* pData, size_t dataSize, const mal_decoder_config* pConfig, mal_decoder* pDecoder); -mal_result mal_decoder_init_memory_raw(const void* pData, size_t dataSize, const mal_decoder_config* pConfigIn, const mal_decoder_config* pConfigOut, mal_decoder* pDecoder); +ma_result ma_decoder_init_memory(const void* pData, size_t dataSize, const ma_decoder_config* pConfig, ma_decoder* pDecoder); +ma_result ma_decoder_init_memory_wav(const void* pData, size_t dataSize, const ma_decoder_config* pConfig, ma_decoder* pDecoder); +ma_result ma_decoder_init_memory_flac(const void* pData, size_t dataSize, const ma_decoder_config* pConfig, ma_decoder* pDecoder); +ma_result ma_decoder_init_memory_vorbis(const void* pData, size_t dataSize, const ma_decoder_config* pConfig, ma_decoder* pDecoder); +ma_result ma_decoder_init_memory_mp3(const void* pData, size_t dataSize, const ma_decoder_config* pConfig, ma_decoder* pDecoder); +ma_result ma_decoder_init_memory_raw(const void* pData, size_t dataSize, const ma_decoder_config* pConfigIn, const ma_decoder_config* pConfigOut, ma_decoder* pDecoder); #ifndef MA_NO_STDIO -mal_result mal_decoder_init_file(const char* pFilePath, const mal_decoder_config* pConfig, mal_decoder* pDecoder); -mal_result mal_decoder_init_file_wav(const char* pFilePath, const mal_decoder_config* pConfig, mal_decoder* pDecoder); +ma_result ma_decoder_init_file(const char* pFilePath, const ma_decoder_config* pConfig, ma_decoder* pDecoder); +ma_result ma_decoder_init_file_wav(const char* pFilePath, const ma_decoder_config* pConfig, ma_decoder* pDecoder); #endif -mal_result mal_decoder_uninit(mal_decoder* pDecoder); +ma_result ma_decoder_uninit(ma_decoder* pDecoder); -mal_uint64 mal_decoder_read_pcm_frames(mal_decoder* pDecoder, void* pFramesOut, mal_uint64 frameCount); -mal_result mal_decoder_seek_to_pcm_frame(mal_decoder* pDecoder, mal_uint64 frameIndex); +ma_uint64 ma_decoder_read_pcm_frames(ma_decoder* pDecoder, void* pFramesOut, ma_uint64 frameCount); +ma_result ma_decoder_seek_to_pcm_frame(ma_decoder* pDecoder, ma_uint64 frameIndex); -// Helper for opening and decoding a file into a heap allocated block of memory. Free the returned pointer with mal_free(). On input, +// Helper for opening and decoding a file into a heap allocated block of memory. Free the returned pointer with ma_free(). On input, // pConfig should be set to what you want. On output it will be set to what you got. #ifndef MA_NO_STDIO -mal_result mal_decode_file(const char* pFilePath, mal_decoder_config* pConfig, mal_uint64* pFrameCountOut, void** ppDataOut); +ma_result ma_decode_file(const char* pFilePath, ma_decoder_config* pConfig, ma_uint64* pFrameCountOut, void** ppDataOut); #endif -mal_result mal_decode_memory(const void* pData, size_t dataSize, mal_decoder_config* pConfig, mal_uint64* pFrameCountOut, void** ppDataOut); +ma_result ma_decode_memory(const void* pData, size_t dataSize, ma_decoder_config* pConfig, ma_uint64* pFrameCountOut, void** ppDataOut); #endif // MA_NO_DECODING @@ -2931,11 +2931,11 @@ typedef struct double periodsPerSecond; double delta; double time; -} mal_sine_wave; +} ma_sine_wave; -mal_result mal_sine_wave_init(double amplitude, double period, mal_uint32 sampleRate, mal_sine_wave* pSineWave); -mal_uint64 mal_sine_wave_read_f32(mal_sine_wave* pSineWave, mal_uint64 count, float* pSamples); -mal_uint64 mal_sine_wave_read_f32_ex(mal_sine_wave* pSineWave, mal_uint64 frameCount, mal_uint32 channels, mal_stream_layout layout, float** ppFrames); +ma_result ma_sine_wave_init(double amplitude, double period, ma_uint32 sampleRate, ma_sine_wave* pSineWave); +ma_uint64 ma_sine_wave_read_f32(ma_sine_wave* pSineWave, ma_uint64 count, float* pSamples); +ma_uint64 ma_sine_wave_read_f32_ex(ma_sine_wave* pSineWave, ma_uint64 frameCount, ma_uint32 channels, ma_stream_layout layout, float** ppFrames); #ifdef __cplusplus @@ -3109,7 +3109,7 @@ mal_uint64 mal_sine_wave_read_f32_ex(mal_sine_wave* pSineWave, mal_uint64 frameC #if defined(_MSC_VER) && !defined(__clang__) #if _MSC_VER >= 1400 #include - static MA_INLINE void mal_cpuid(int info[4], int fid) + static MA_INLINE void ma_cpuid(int info[4], int fid) { __cpuid(info, fid); } @@ -3118,7 +3118,7 @@ mal_uint64 mal_sine_wave_read_f32_ex(mal_sine_wave* pSineWave, mal_uint64 frameC #endif #if _MSC_VER >= 1600 - static MA_INLINE unsigned __int64 mal_xgetbv(int reg) + static MA_INLINE unsigned __int64 ma_xgetbv(int reg) { return _xgetbv(reg); } @@ -3126,7 +3126,7 @@ mal_uint64 mal_sine_wave_read_f32_ex(mal_sine_wave* pSineWave, mal_uint64 frameC #define MA_NO_XGETBV #endif #elif (defined(__GNUC__) || defined(__clang__)) && !defined(MA_ANDROID) - static MA_INLINE void mal_cpuid(int info[4], int fid) + static MA_INLINE void ma_cpuid(int info[4], int fid) { // It looks like the -fPIC option uses the ebx register which GCC complains about. We can work around this by just using a different register, the // specific register of which I'm letting the compiler decide on. The "k" prefix is used to specify a 32-bit register. The {...} syntax is for @@ -3147,7 +3147,7 @@ mal_uint64 mal_sine_wave_read_f32_ex(mal_sine_wave* pSineWave, mal_uint64 frameC #endif } - static MA_INLINE unsigned long long mal_xgetbv(int reg) + static MA_INLINE unsigned long long ma_xgetbv(int reg) { unsigned int hi; unsigned int lo; @@ -3167,7 +3167,7 @@ mal_uint64 mal_sine_wave_read_f32_ex(mal_sine_wave* pSineWave, mal_uint64 frameC #define MA_NO_XGETBV #endif -static MA_INLINE mal_bool32 mal_has_sse2() +static MA_INLINE ma_bool32 ma_has_sse2() { #if defined(MA_SUPPORT_SSE2) #if (defined(MA_X64) || defined(MA_X86)) && !defined(MA_NO_SSE2) @@ -3180,7 +3180,7 @@ static MA_INLINE mal_bool32 mal_has_sse2() return MA_FALSE; #else int info[4]; - mal_cpuid(info, 1); + ma_cpuid(info, 1); return (info[3] & (1 << 26)) != 0; #endif #endif @@ -3193,7 +3193,7 @@ static MA_INLINE mal_bool32 mal_has_sse2() } #if 0 -static MA_INLINE mal_bool32 mal_has_avx() +static MA_INLINE ma_bool32 ma_has_avx() { #if defined(MA_SUPPORT_AVX) #if (defined(MA_X64) || defined(MA_X86)) && !defined(MA_NO_AVX) @@ -3205,9 +3205,9 @@ static MA_INLINE mal_bool32 mal_has_avx() return MA_FALSE; #else int info[4]; - mal_cpuid(info, 1); + ma_cpuid(info, 1); if (((info[2] & (1 << 27)) != 0) && ((info[2] & (1 << 28)) != 0)) { - mal_uint64 xrc = mal_xgetbv(0); + ma_uint64 xrc = ma_xgetbv(0); if ((xrc & 0x06) == 0x06) { return MA_TRUE; } else { @@ -3227,7 +3227,7 @@ static MA_INLINE mal_bool32 mal_has_avx() } #endif -static MA_INLINE mal_bool32 mal_has_avx2() +static MA_INLINE ma_bool32 ma_has_avx2() { #if defined(MA_SUPPORT_AVX2) #if (defined(MA_X64) || defined(MA_X86)) && !defined(MA_NO_AVX2) @@ -3240,10 +3240,10 @@ static MA_INLINE mal_bool32 mal_has_avx2() #else int info1[4]; int info7[4]; - mal_cpuid(info1, 1); - mal_cpuid(info7, 7); + ma_cpuid(info1, 1); + ma_cpuid(info7, 7); if (((info1[2] & (1 << 27)) != 0) && ((info7[1] & (1 << 5)) != 0)) { - mal_uint64 xrc = mal_xgetbv(0); + ma_uint64 xrc = ma_xgetbv(0); if ((xrc & 0x06) == 0x06) { return MA_TRUE; } else { @@ -3262,7 +3262,7 @@ static MA_INLINE mal_bool32 mal_has_avx2() #endif } -static MA_INLINE mal_bool32 mal_has_avx512f() +static MA_INLINE ma_bool32 ma_has_avx512f() { #if defined(MA_SUPPORT_AVX512) #if (defined(MA_X64) || defined(MA_X86)) && !defined(MA_NO_AVX512) @@ -3275,10 +3275,10 @@ static MA_INLINE mal_bool32 mal_has_avx512f() #else int info1[4]; int info7[4]; - mal_cpuid(info1, 1); - mal_cpuid(info7, 7); + ma_cpuid(info1, 1); + ma_cpuid(info7, 7); if (((info1[2] & (1 << 27)) != 0) && ((info7[1] & (1 << 16)) != 0)) { - mal_uint64 xrc = mal_xgetbv(0); + ma_uint64 xrc = ma_xgetbv(0); if ((xrc & 0xE6) == 0xE6) { return MA_TRUE; } else { @@ -3297,7 +3297,7 @@ static MA_INLINE mal_bool32 mal_has_avx512f() #endif } -static MA_INLINE mal_bool32 mal_has_neon() +static MA_INLINE ma_bool32 ma_has_neon() { #if defined(MA_SUPPORT_NEON) #if defined(MA_ARM) && !defined(MA_NO_NEON) @@ -3316,7 +3316,7 @@ static MA_INLINE mal_bool32 mal_has_neon() } -static MA_INLINE mal_bool32 mal_is_little_endian() +static MA_INLINE ma_bool32 ma_is_little_endian() { #if defined(MA_X86) || defined(MA_X64) return MA_TRUE; @@ -3326,9 +3326,9 @@ static MA_INLINE mal_bool32 mal_is_little_endian() #endif } -static MA_INLINE mal_bool32 mal_is_big_endian() +static MA_INLINE ma_bool32 ma_is_big_endian() { - return !mal_is_little_endian(); + return !ma_is_little_endian(); } @@ -3352,9 +3352,9 @@ static MA_INLINE mal_bool32 mal_is_big_endian() #endif -// The default format when mal_format_unknown (0) is requested when initializing a device. +// The default format when ma_format_unknown (0) is requested when initializing a device. #ifndef MA_DEFAULT_FORMAT -#define MA_DEFAULT_FORMAT mal_format_f32 +#define MA_DEFAULT_FORMAT ma_format_f32 #endif // The default channel count to use when 0 is used when initializing a device. @@ -3367,7 +3367,7 @@ static MA_INLINE mal_bool32 mal_is_big_endian() #define MA_DEFAULT_SAMPLE_RATE 48000 #endif -// Default periods when none is specified in mal_device_init(). More periods means more work on the CPU. +// Default periods when none is specified in ma_device_init(). More periods means more work on the CPU. #ifndef MA_DEFAULT_PERIODS #define MA_DEFAULT_PERIODS 3 #endif @@ -3384,7 +3384,7 @@ static MA_INLINE mal_bool32 mal_is_big_endian() // Standard sample rates, in order of priority. -mal_uint32 g_malStandardSampleRatePriorities[] = { +ma_uint32 g_malStandardSampleRatePriorities[] = { MA_SAMPLE_RATE_48000, // Most common MA_SAMPLE_RATE_44100, @@ -3405,16 +3405,16 @@ mal_uint32 g_malStandardSampleRatePriorities[] = { MA_SAMPLE_RATE_384000 }; -mal_format g_malFormatPriorities[] = { - mal_format_s16, // Most common - mal_format_f32, +ma_format g_malFormatPriorities[] = { + ma_format_s16, // Most common + ma_format_f32, - //mal_format_s24_32, // Clean alignment - mal_format_s32, + //ma_format_s24_32, // Clean alignment + ma_format_s32, - mal_format_s24, // Unclean alignment + ma_format_s24, // Unclean alignment - mal_format_u8 // Low quality + ma_format_u8 // Low quality }; @@ -3472,18 +3472,18 @@ mal_format g_malFormatPriorities[] = { #endif #endif -#define mal_zero_memory MA_ZERO_MEMORY -#define mal_copy_memory MA_COPY_MEMORY -#define mal_assert MA_ASSERT +#define ma_zero_memory MA_ZERO_MEMORY +#define ma_copy_memory MA_COPY_MEMORY +#define ma_assert MA_ASSERT -#define mal_zero_object(p) mal_zero_memory((p), sizeof(*(p))) -#define mal_countof(x) (sizeof(x) / sizeof(x[0])) -#define mal_max(x, y) (((x) > (y)) ? (x) : (y)) -#define mal_min(x, y) (((x) < (y)) ? (x) : (y)) -#define mal_clamp(x, lo, hi) (mal_max(lo, mal_min(x, hi))) -#define mal_offset_ptr(p, offset) (((mal_uint8*)(p)) + (offset)) +#define ma_zero_object(p) ma_zero_memory((p), sizeof(*(p))) +#define ma_countof(x) (sizeof(x) / sizeof(x[0])) +#define ma_max(x, y) (((x) > (y)) ? (x) : (y)) +#define ma_min(x, y) (((x) < (y)) ? (x) : (y)) +#define ma_clamp(x, lo, hi) (ma_max(lo, ma_min(x, hi))) +#define ma_offset_ptr(p, offset) (((ma_uint8*)(p)) + (offset)) -#define mal_buffer_frame_capacity(buffer, channels, format) (sizeof(buffer) / mal_get_bytes_per_sample(format) / (channels)) +#define ma_buffer_frame_capacity(buffer, channels, format) (sizeof(buffer) / ma_get_bytes_per_sample(format) / (channels)) // Return Values: @@ -3492,7 +3492,7 @@ mal_format g_malFormatPriorities[] = { // 34: ERANGE // // Not using symbolic constants for errors because I want to avoid #including errno.h -int mal_strcpy_s(char* dst, size_t dstSizeInBytes, const char* src) +int ma_strcpy_s(char* dst, size_t dstSizeInBytes, const char* src) { if (dst == 0) { return 22; @@ -3519,7 +3519,7 @@ int mal_strcpy_s(char* dst, size_t dstSizeInBytes, const char* src) return 34; } -int mal_strncpy_s(char* dst, size_t dstSizeInBytes, const char* src, size_t count) +int ma_strncpy_s(char* dst, size_t dstSizeInBytes, const char* src, size_t count) { if (dst == 0) { return 22; @@ -3551,7 +3551,7 @@ int mal_strncpy_s(char* dst, size_t dstSizeInBytes, const char* src, size_t coun return 34; } -int mal_strcat_s(char* dst, size_t dstSizeInBytes, const char* src) +int ma_strcat_s(char* dst, size_t dstSizeInBytes, const char* src) { if (dst == 0) { return 22; @@ -3591,7 +3591,7 @@ int mal_strcat_s(char* dst, size_t dstSizeInBytes, const char* src) return 0; } -int mal_itoa_s(int value, char* dst, size_t dstSizeInBytes, int radix) +int ma_itoa_s(int value, char* dst, size_t dstSizeInBytes, int radix) { if (dst == NULL || dstSizeInBytes == 0) { return 22; @@ -3657,7 +3657,7 @@ int mal_itoa_s(int value, char* dst, size_t dstSizeInBytes, int radix) return 0; } -int mal_strcmp(const char* str1, const char* str2) +int ma_strcmp(const char* str1, const char* str2) { if (str1 == str2) return 0; @@ -3683,7 +3683,7 @@ int mal_strcmp(const char* str1, const char* str2) // Thanks to good old Bit Twiddling Hacks for this one: http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 -static MA_INLINE unsigned int mal_next_power_of_2(unsigned int x) +static MA_INLINE unsigned int ma_next_power_of_2(unsigned int x) { x--; x |= x >> 1; @@ -3696,15 +3696,15 @@ static MA_INLINE unsigned int mal_next_power_of_2(unsigned int x) return x; } -static MA_INLINE unsigned int mal_prev_power_of_2(unsigned int x) +static MA_INLINE unsigned int ma_prev_power_of_2(unsigned int x) { - return mal_next_power_of_2(x) >> 1; + return ma_next_power_of_2(x) >> 1; } -static MA_INLINE unsigned int mal_round_to_power_of_2(unsigned int x) +static MA_INLINE unsigned int ma_round_to_power_of_2(unsigned int x) { - unsigned int prev = mal_prev_power_of_2(x); - unsigned int next = mal_next_power_of_2(x); + unsigned int prev = ma_prev_power_of_2(x); + unsigned int next = ma_next_power_of_2(x); if ((next - x) > (x - prev)) { return prev; } else { @@ -3712,7 +3712,7 @@ static MA_INLINE unsigned int mal_round_to_power_of_2(unsigned int x) } } -static MA_INLINE unsigned int mal_count_set_bits(unsigned int x) +static MA_INLINE unsigned int ma_count_set_bits(unsigned int x) { unsigned int count = 0; while (x != 0) { @@ -3729,18 +3729,18 @@ static MA_INLINE unsigned int mal_count_set_bits(unsigned int x) // Clamps an f32 sample to -1..1 -static MA_INLINE float mal_clip_f32(float x) +static MA_INLINE float ma_clip_f32(float x) { if (x < -1) return -1; if (x > +1) return +1; return x; } -static MA_INLINE float mal_mix_f32(float x, float y, float a) +static MA_INLINE float ma_mix_f32(float x, float y, float a) { return x*(1-a) + y*a; } -static MA_INLINE float mal_mix_f32_fast(float x, float y, float a) +static MA_INLINE float ma_mix_f32_fast(float x, float y, float a) { float r0 = (y - x); float r1 = r0*a; @@ -3749,41 +3749,41 @@ static MA_INLINE float mal_mix_f32_fast(float x, float y, float a) } #if defined(MA_SUPPORT_SSE2) -static MA_INLINE __m128 mal_mix_f32_fast__sse2(__m128 x, __m128 y, __m128 a) +static MA_INLINE __m128 ma_mix_f32_fast__sse2(__m128 x, __m128 y, __m128 a) { return _mm_add_ps(x, _mm_mul_ps(_mm_sub_ps(y, x), a)); } #endif #if defined(MA_SUPPORT_AVX2) -static MA_INLINE __m256 mal_mix_f32_fast__avx2(__m256 x, __m256 y, __m256 a) +static MA_INLINE __m256 ma_mix_f32_fast__avx2(__m256 x, __m256 y, __m256 a) { return _mm256_add_ps(x, _mm256_mul_ps(_mm256_sub_ps(y, x), a)); } #endif #if defined(MA_SUPPORT_AVX512) -static MA_INLINE __m512 mal_mix_f32_fast__avx512(__m512 x, __m512 y, __m512 a) +static MA_INLINE __m512 ma_mix_f32_fast__avx512(__m512 x, __m512 y, __m512 a) { return _mm512_add_ps(x, _mm512_mul_ps(_mm512_sub_ps(y, x), a)); } #endif #if defined(MA_SUPPORT_NEON) -static MA_INLINE float32x4_t mal_mix_f32_fast__neon(float32x4_t x, float32x4_t y, float32x4_t a) +static MA_INLINE float32x4_t ma_mix_f32_fast__neon(float32x4_t x, float32x4_t y, float32x4_t a) { return vaddq_f32(x, vmulq_f32(vsubq_f32(y, x), a)); } #endif -static MA_INLINE double mal_mix_f64(double x, double y, double a) +static MA_INLINE double ma_mix_f64(double x, double y, double a) { return x*(1-a) + y*a; } -static MA_INLINE double mal_mix_f64_fast(double x, double y, double a) +static MA_INLINE double ma_mix_f64_fast(double x, double y, double a) { return x + (y - x)*a; } -static MA_INLINE float mal_scale_to_range_f32(float x, float lo, float hi) +static MA_INLINE float ma_scale_to_range_f32(float x, float lo, float hi) { return lo + x*(hi-lo); } @@ -3800,76 +3800,76 @@ static MA_INLINE float mal_scale_to_range_f32(float x, float lo, float hi) #define MA_LCG_M 4294967296 #define MA_LCG_A 1103515245 #define MA_LCG_C 12345 -static mal_int32 g_malLCG; +static ma_int32 g_malLCG; -void mal_seed(mal_int32 seed) +void ma_seed(ma_int32 seed) { g_malLCG = seed; } -mal_int32 mal_rand_s32() +ma_int32 ma_rand_s32() { - mal_int32 lcg = g_malLCG; - mal_int32 r = (MA_LCG_A * lcg + MA_LCG_C) % MA_LCG_M; + ma_int32 lcg = g_malLCG; + ma_int32 r = (MA_LCG_A * lcg + MA_LCG_C) % MA_LCG_M; g_malLCG = r; return r; } -double mal_rand_f64() +double ma_rand_f64() { - return (mal_rand_s32() + 0x80000000) / (double)0x7FFFFFFF; + return (ma_rand_s32() + 0x80000000) / (double)0x7FFFFFFF; } -float mal_rand_f32() +float ma_rand_f32() { - return (float)mal_rand_f64(); + return (float)ma_rand_f64(); } -static MA_INLINE float mal_rand_range_f32(float lo, float hi) +static MA_INLINE float ma_rand_range_f32(float lo, float hi) { - return mal_scale_to_range_f32(mal_rand_f32(), lo, hi); + return ma_scale_to_range_f32(ma_rand_f32(), lo, hi); } -static MA_INLINE mal_int32 mal_rand_range_s32(mal_int32 lo, mal_int32 hi) +static MA_INLINE ma_int32 ma_rand_range_s32(ma_int32 lo, ma_int32 hi) { - double x = mal_rand_f64(); - return lo + (mal_int32)(x*(hi-lo)); + double x = ma_rand_f64(); + return lo + (ma_int32)(x*(hi-lo)); } -static MA_INLINE float mal_dither_f32_rectangle(float ditherMin, float ditherMax) +static MA_INLINE float ma_dither_f32_rectangle(float ditherMin, float ditherMax) { - return mal_rand_range_f32(ditherMin, ditherMax); + return ma_rand_range_f32(ditherMin, ditherMax); } -static MA_INLINE float mal_dither_f32_triangle(float ditherMin, float ditherMax) +static MA_INLINE float ma_dither_f32_triangle(float ditherMin, float ditherMax) { - float a = mal_rand_range_f32(ditherMin, 0); - float b = mal_rand_range_f32(0, ditherMax); + float a = ma_rand_range_f32(ditherMin, 0); + float b = ma_rand_range_f32(0, ditherMax); return a + b; } -static MA_INLINE float mal_dither_f32(mal_dither_mode ditherMode, float ditherMin, float ditherMax) +static MA_INLINE float ma_dither_f32(ma_dither_mode ditherMode, float ditherMin, float ditherMax) { - if (ditherMode == mal_dither_mode_rectangle) { - return mal_dither_f32_rectangle(ditherMin, ditherMax); + if (ditherMode == ma_dither_mode_rectangle) { + return ma_dither_f32_rectangle(ditherMin, ditherMax); } - if (ditherMode == mal_dither_mode_triangle) { - return mal_dither_f32_triangle(ditherMin, ditherMax); + if (ditherMode == ma_dither_mode_triangle) { + return ma_dither_f32_triangle(ditherMin, ditherMax); } return 0; } -static MA_INLINE mal_int32 mal_dither_s32(mal_dither_mode ditherMode, mal_int32 ditherMin, mal_int32 ditherMax) +static MA_INLINE ma_int32 ma_dither_s32(ma_dither_mode ditherMode, ma_int32 ditherMin, ma_int32 ditherMax) { - if (ditherMode == mal_dither_mode_rectangle) { - mal_int32 a = mal_rand_range_s32(ditherMin, ditherMax); + if (ditherMode == ma_dither_mode_rectangle) { + ma_int32 a = ma_rand_range_s32(ditherMin, ditherMax); return a; } - if (ditherMode == mal_dither_mode_triangle) { - mal_int32 a = mal_rand_range_s32(ditherMin, 0); - mal_int32 b = mal_rand_range_s32(0, ditherMax); + if (ditherMode == ma_dither_mode_triangle) { + ma_int32 a = ma_rand_range_s32(ditherMin, 0); + ma_int32 b = ma_rand_range_s32(0, ditherMax); return a + b; } @@ -3879,7 +3879,7 @@ static MA_INLINE mal_int32 mal_dither_s32(mal_dither_mode ditherMode, mal_int32 // Splits a buffer into parts of equal length and of the given alignment. The returned size of the split buffers will be a // multiple of the alignment. The alignment must be a power of 2. -void mal_split_buffer(void* pBuffer, size_t bufferSize, size_t splitCount, size_t alignment, void** ppBuffersOut, size_t* pSplitSizeOut) +void ma_split_buffer(void* pBuffer, size_t bufferSize, size_t splitCount, size_t alignment, void** ppBuffersOut, size_t* pSplitSizeOut) { if (pSplitSizeOut) { *pSplitSizeOut = 0; @@ -3893,8 +3893,8 @@ void mal_split_buffer(void* pBuffer, size_t bufferSize, size_t splitCount, size_ alignment = 1; } - mal_uintptr pBufferUnaligned = (mal_uintptr)pBuffer; - mal_uintptr pBufferAligned = (pBufferUnaligned + (alignment-1)) & ~(alignment-1); + ma_uintptr pBufferUnaligned = (ma_uintptr)pBuffer; + ma_uintptr pBufferAligned = (pBufferUnaligned + (alignment-1)) & ~(alignment-1); size_t unalignedBytes = (size_t)(pBufferAligned - pBufferUnaligned); size_t splitSize = 0; @@ -3905,7 +3905,7 @@ void mal_split_buffer(void* pBuffer, size_t bufferSize, size_t splitCount, size_ if (ppBuffersOut != NULL) { for (size_t i = 0; i < splitCount; ++i) { - ppBuffersOut[i] = (mal_uint8*)(pBufferAligned + (splitSize*i)); + ppBuffersOut[i] = (ma_uint8*)(pBufferAligned + (splitSize*i)); } } @@ -3921,44 +3921,44 @@ void mal_split_buffer(void* pBuffer, size_t bufferSize, size_t splitCount, size_ // /////////////////////////////////////////////////////////////////////////////// #if defined(_WIN32) && !defined(__GNUC__) -#define mal_memory_barrier() MemoryBarrier() -#define mal_atomic_exchange_32(a, b) InterlockedExchange((LONG*)a, (LONG)b) -#define mal_atomic_exchange_64(a, b) InterlockedExchange64((LONGLONG*)a, (LONGLONG)b) -#define mal_atomic_increment_32(a) InterlockedIncrement((LONG*)a) -#define mal_atomic_decrement_32(a) InterlockedDecrement((LONG*)a) +#define ma_memory_barrier() MemoryBarrier() +#define ma_atomic_exchange_32(a, b) InterlockedExchange((LONG*)a, (LONG)b) +#define ma_atomic_exchange_64(a, b) InterlockedExchange64((LONGLONG*)a, (LONGLONG)b) +#define ma_atomic_increment_32(a) InterlockedIncrement((LONG*)a) +#define ma_atomic_decrement_32(a) InterlockedDecrement((LONG*)a) #else -#define mal_memory_barrier() __sync_synchronize() -#define mal_atomic_exchange_32(a, b) (void)__sync_lock_test_and_set(a, b); __sync_synchronize() -#define mal_atomic_exchange_64(a, b) (void)__sync_lock_test_and_set(a, b); __sync_synchronize() -#define mal_atomic_increment_32(a) __sync_add_and_fetch(a, 1) -#define mal_atomic_decrement_32(a) __sync_sub_and_fetch(a, 1) +#define ma_memory_barrier() __sync_synchronize() +#define ma_atomic_exchange_32(a, b) (void)__sync_lock_test_and_set(a, b); __sync_synchronize() +#define ma_atomic_exchange_64(a, b) (void)__sync_lock_test_and_set(a, b); __sync_synchronize() +#define ma_atomic_increment_32(a) __sync_add_and_fetch(a, 1) +#define ma_atomic_decrement_32(a) __sync_sub_and_fetch(a, 1) #endif #ifdef MA_64BIT -#define mal_atomic_exchange_ptr mal_atomic_exchange_64 +#define ma_atomic_exchange_ptr ma_atomic_exchange_64 #endif #ifdef MA_32BIT -#define mal_atomic_exchange_ptr mal_atomic_exchange_32 +#define ma_atomic_exchange_ptr ma_atomic_exchange_32 #endif -mal_uint32 mal_get_standard_sample_rate_priority_index(mal_uint32 sampleRate) // Lower = higher priority +ma_uint32 ma_get_standard_sample_rate_priority_index(ma_uint32 sampleRate) // Lower = higher priority { - for (mal_uint32 i = 0; i < mal_countof(g_malStandardSampleRatePriorities); ++i) { + for (ma_uint32 i = 0; i < ma_countof(g_malStandardSampleRatePriorities); ++i) { if (g_malStandardSampleRatePriorities[i] == sampleRate) { return i; } } - return (mal_uint32)-1; + return (ma_uint32)-1; } -mal_uint64 mal_calculate_frame_count_after_src(mal_uint32 sampleRateOut, mal_uint32 sampleRateIn, mal_uint64 frameCountIn) +ma_uint64 ma_calculate_frame_count_after_src(ma_uint32 sampleRateOut, ma_uint32 sampleRateIn, ma_uint64 frameCountIn) { double srcRatio = (double)sampleRateOut / sampleRateIn; double frameCountOutF = frameCountIn * srcRatio; - mal_uint64 frameCountOut = (mal_uint64)frameCountOutF; + ma_uint64 frameCountOut = (ma_uint64)frameCountOutF; // If the output frame count is fractional, make sure we add an extra frame to ensure there's enough room for that last sample. if ((frameCountOutF - frameCountOut) > 0.0) { @@ -4058,24 +4058,24 @@ mal_uint64 mal_calculate_frame_count_after_src(mal_uint32 sampleRateOut, mal_uin #define MA_HAS_NULL // Everything supports the null backend. #endif -const char* mal_get_backend_name(mal_backend backend) +const char* ma_get_backend_name(ma_backend backend) { switch (backend) { - case mal_backend_wasapi: return "WASAPI"; - case mal_backend_dsound: return "DirectSound"; - case mal_backend_winmm: return "WinMM"; - case mal_backend_coreaudio: return "Core Audio"; - case mal_backend_sndio: return "sndio"; - case mal_backend_audio4: return "audio(4)"; - case mal_backend_oss: return "OSS"; - case mal_backend_pulseaudio: return "PulseAudio"; - case mal_backend_alsa: return "ALSA"; - case mal_backend_jack: return "JACK"; - case mal_backend_aaudio: return "AAudio"; - case mal_backend_opensl: return "OpenSL|ES"; - case mal_backend_webaudio: return "Web Audio"; - case mal_backend_null: return "Null"; + case ma_backend_wasapi: return "WASAPI"; + case ma_backend_dsound: return "DirectSound"; + case ma_backend_winmm: return "WinMM"; + case ma_backend_coreaudio: return "Core Audio"; + case ma_backend_sndio: return "sndio"; + case ma_backend_audio4: return "audio(4)"; + case ma_backend_oss: return "OSS"; + case ma_backend_pulseaudio: return "PulseAudio"; + case ma_backend_alsa: return "ALSA"; + case ma_backend_jack: return "JACK"; + case ma_backend_aaudio: return "AAudio"; + case ma_backend_opensl: return "OpenSL|ES"; + case ma_backend_webaudio: return "Web Audio"; + case ma_backend_null: return "Null"; default: return "Unknown"; } } @@ -4084,12 +4084,12 @@ const char* mal_get_backend_name(mal_backend backend) #ifdef MA_WIN32 #define MA_THREADCALL WINAPI - typedef unsigned long mal_thread_result; + typedef unsigned long ma_thread_result; #else #define MA_THREADCALL - typedef void* mal_thread_result; + typedef void* ma_thread_result; #endif -typedef mal_thread_result (MA_THREADCALL * mal_thread_entry_proc)(void* pData); +typedef ma_thread_result (MA_THREADCALL * ma_thread_entry_proc)(void* pData); #ifdef MA_WIN32 typedef HRESULT (WINAPI * MA_PFN_CoInitializeEx)(LPVOID pvReserved, DWORD dwCoInit); @@ -4125,11 +4125,11 @@ typedef LONG (WINAPI * MA_PFN_RegQueryValueExA)(HKEY hKey, LPCSTR lpValueName, L // /////////////////////////////////////////////////////////////////////////////// #ifdef MA_WIN32 -LARGE_INTEGER g_mal_TimerFrequency = {{0}}; -void mal_timer_init(mal_timer* pTimer) +LARGE_INTEGER g_ma_TimerFrequency = {{0}}; +void ma_timer_init(ma_timer* pTimer) { - if (g_mal_TimerFrequency.QuadPart == 0) { - QueryPerformanceFrequency(&g_mal_TimerFrequency); + if (g_ma_TimerFrequency.QuadPart == 0) { + QueryPerformanceFrequency(&g_ma_TimerFrequency); } LARGE_INTEGER counter; @@ -4137,40 +4137,40 @@ void mal_timer_init(mal_timer* pTimer) pTimer->counter = counter.QuadPart; } -double mal_timer_get_time_in_seconds(mal_timer* pTimer) +double ma_timer_get_time_in_seconds(ma_timer* pTimer) { LARGE_INTEGER counter; if (!QueryPerformanceCounter(&counter)) { return 0; } - return (double)(counter.QuadPart - pTimer->counter) / g_mal_TimerFrequency.QuadPart; + return (double)(counter.QuadPart - pTimer->counter) / g_ma_TimerFrequency.QuadPart; } #elif defined(MA_APPLE) && (__MAC_OS_X_VERSION_MIN_REQUIRED < 101200) -mal_uint64 g_mal_TimerFrequency = 0; -void mal_timer_init(mal_timer* pTimer) +ma_uint64 g_ma_TimerFrequency = 0; +void ma_timer_init(ma_timer* pTimer) { mach_timebase_info_data_t baseTime; mach_timebase_info(&baseTime); - g_mal_TimerFrequency = (baseTime.denom * 1e9) / baseTime.numer; + g_ma_TimerFrequency = (baseTime.denom * 1e9) / baseTime.numer; pTimer->counter = mach_absolute_time(); } -double mal_timer_get_time_in_seconds(mal_timer* pTimer) +double ma_timer_get_time_in_seconds(ma_timer* pTimer) { - mal_uint64 newTimeCounter = mach_absolute_time(); - mal_uint64 oldTimeCounter = pTimer->counter; + ma_uint64 newTimeCounter = mach_absolute_time(); + ma_uint64 oldTimeCounter = pTimer->counter; - return (newTimeCounter - oldTimeCounter) / g_mal_TimerFrequency; + return (newTimeCounter - oldTimeCounter) / g_ma_TimerFrequency; } #elif defined(MA_EMSCRIPTEN) -void mal_timer_init(mal_timer* pTimer) +void ma_timer_init(ma_timer* pTimer) { pTimer->counterD = emscripten_get_now(); } -double mal_timer_get_time_in_seconds(mal_timer* pTimer) +double ma_timer_get_time_in_seconds(ma_timer* pTimer) { return (emscripten_get_now() - pTimer->counterD) / 1000; /* Emscripten is in milliseconds. */ } @@ -4181,7 +4181,7 @@ double mal_timer_get_time_in_seconds(mal_timer* pTimer) #define MA_CLOCK_ID CLOCK_REALTIME #endif -void mal_timer_init(mal_timer* pTimer) +void ma_timer_init(ma_timer* pTimer) { struct timespec newTime; clock_gettime(MA_CLOCK_ID, &newTime); @@ -4189,13 +4189,13 @@ void mal_timer_init(mal_timer* pTimer) pTimer->counter = (newTime.tv_sec * 1000000000) + newTime.tv_nsec; } -double mal_timer_get_time_in_seconds(mal_timer* pTimer) +double ma_timer_get_time_in_seconds(ma_timer* pTimer) { struct timespec newTime; clock_gettime(MA_CLOCK_ID, &newTime); - mal_uint64 newTimeCounter = (newTime.tv_sec * 1000000000) + newTime.tv_nsec; - mal_uint64 oldTimeCounter = pTimer->counter; + ma_uint64 newTimeCounter = (newTime.tv_sec * 1000000000) + newTime.tv_nsec; + ma_uint64 oldTimeCounter = pTimer->counter; return (newTimeCounter - oldTimeCounter) / 1000000000.0; } @@ -4207,11 +4207,11 @@ double mal_timer_get_time_in_seconds(mal_timer* pTimer) // Dynamic Linking // /////////////////////////////////////////////////////////////////////////////// -mal_handle mal_dlopen(const char* filename) +ma_handle ma_dlopen(const char* filename) { #ifdef _WIN32 #ifdef MA_WIN32_DESKTOP - return (mal_handle)LoadLibraryA(filename); + return (ma_handle)LoadLibraryA(filename); #else // *sigh* It appears there is no ANSI version of LoadPackagedLibrary()... WCHAR filenameW[4096]; @@ -4219,14 +4219,14 @@ mal_handle mal_dlopen(const char* filename) return NULL; } - return (mal_handle)LoadPackagedLibrary(filenameW, 0); + return (ma_handle)LoadPackagedLibrary(filenameW, 0); #endif #else - return (mal_handle)dlopen(filename, RTLD_NOW); + return (ma_handle)dlopen(filename, RTLD_NOW); #endif } -void mal_dlclose(mal_handle handle) +void ma_dlclose(ma_handle handle) { #ifdef _WIN32 FreeLibrary((HMODULE)handle); @@ -4235,12 +4235,12 @@ void mal_dlclose(mal_handle handle) #endif } -mal_proc mal_dlsym(mal_handle handle, const char* symbol) +ma_proc ma_dlsym(ma_handle handle, const char* symbol) { #ifdef _WIN32 - return (mal_proc)GetProcAddress((HMODULE)handle, symbol); + return (ma_proc)GetProcAddress((HMODULE)handle, symbol); #else - return (mal_proc)dlsym((void*)handle, symbol); + return (ma_proc)dlsym((void*)handle, symbol); #endif } @@ -4251,44 +4251,44 @@ mal_proc mal_dlsym(mal_handle handle, const char* symbol) // /////////////////////////////////////////////////////////////////////////////// #ifdef MA_WIN32 -int mal_thread_priority_to_win32(mal_thread_priority priority) +int ma_thread_priority_to_win32(ma_thread_priority priority) { switch (priority) { - case mal_thread_priority_idle: return THREAD_PRIORITY_IDLE; - case mal_thread_priority_lowest: return THREAD_PRIORITY_LOWEST; - case mal_thread_priority_low: return THREAD_PRIORITY_BELOW_NORMAL; - case mal_thread_priority_normal: return THREAD_PRIORITY_NORMAL; - case mal_thread_priority_high: return THREAD_PRIORITY_ABOVE_NORMAL; - case mal_thread_priority_highest: return THREAD_PRIORITY_HIGHEST; - case mal_thread_priority_realtime: return THREAD_PRIORITY_TIME_CRITICAL; - default: return mal_thread_priority_normal; + case ma_thread_priority_idle: return THREAD_PRIORITY_IDLE; + case ma_thread_priority_lowest: return THREAD_PRIORITY_LOWEST; + case ma_thread_priority_low: return THREAD_PRIORITY_BELOW_NORMAL; + case ma_thread_priority_normal: return THREAD_PRIORITY_NORMAL; + case ma_thread_priority_high: return THREAD_PRIORITY_ABOVE_NORMAL; + case ma_thread_priority_highest: return THREAD_PRIORITY_HIGHEST; + case ma_thread_priority_realtime: return THREAD_PRIORITY_TIME_CRITICAL; + default: return ma_thread_priority_normal; } } -mal_result mal_thread_create__win32(mal_context* pContext, mal_thread* pThread, mal_thread_entry_proc entryProc, void* pData) +ma_result ma_thread_create__win32(ma_context* pContext, ma_thread* pThread, ma_thread_entry_proc entryProc, void* pData) { pThread->win32.hThread = CreateThread(NULL, 0, entryProc, pData, 0, NULL); if (pThread->win32.hThread == NULL) { return MA_FAILED_TO_CREATE_THREAD; } - SetThreadPriority((HANDLE)pThread->win32.hThread, mal_thread_priority_to_win32(pContext->config.threadPriority)); + SetThreadPriority((HANDLE)pThread->win32.hThread, ma_thread_priority_to_win32(pContext->config.threadPriority)); return MA_SUCCESS; } -void mal_thread_wait__win32(mal_thread* pThread) +void ma_thread_wait__win32(ma_thread* pThread) { WaitForSingleObject(pThread->win32.hThread, INFINITE); } -void mal_sleep__win32(mal_uint32 milliseconds) +void ma_sleep__win32(ma_uint32 milliseconds) { Sleep((DWORD)milliseconds); } -mal_result mal_mutex_init__win32(mal_context* pContext, mal_mutex* pMutex) +ma_result ma_mutex_init__win32(ma_context* pContext, ma_mutex* pMutex) { (void)pContext; @@ -4300,23 +4300,23 @@ mal_result mal_mutex_init__win32(mal_context* pContext, mal_mutex* pMutex) return MA_SUCCESS; } -void mal_mutex_uninit__win32(mal_mutex* pMutex) +void ma_mutex_uninit__win32(ma_mutex* pMutex) { CloseHandle(pMutex->win32.hMutex); } -void mal_mutex_lock__win32(mal_mutex* pMutex) +void ma_mutex_lock__win32(ma_mutex* pMutex) { WaitForSingleObject(pMutex->win32.hMutex, INFINITE); } -void mal_mutex_unlock__win32(mal_mutex* pMutex) +void ma_mutex_unlock__win32(ma_mutex* pMutex) { SetEvent(pMutex->win32.hMutex); } -mal_result mal_event_init__win32(mal_context* pContext, mal_event* pEvent) +ma_result ma_event_init__win32(ma_context* pContext, ma_event* pEvent) { (void)pContext; @@ -4328,17 +4328,17 @@ mal_result mal_event_init__win32(mal_context* pContext, mal_event* pEvent) return MA_SUCCESS; } -void mal_event_uninit__win32(mal_event* pEvent) +void ma_event_uninit__win32(ma_event* pEvent) { CloseHandle(pEvent->win32.hEvent); } -mal_bool32 mal_event_wait__win32(mal_event* pEvent) +ma_bool32 ma_event_wait__win32(ma_event* pEvent) { return WaitForSingleObject(pEvent->win32.hEvent, INFINITE) == WAIT_OBJECT_0; } -mal_bool32 mal_event_signal__win32(mal_event* pEvent) +ma_bool32 ma_event_signal__win32(ma_event* pEvent) { return SetEvent(pEvent->win32.hEvent); } @@ -4348,40 +4348,40 @@ mal_bool32 mal_event_signal__win32(mal_event* pEvent) #ifdef MA_POSIX #include -typedef int (* mal_pthread_create_proc)(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg); -typedef int (* mal_pthread_join_proc)(pthread_t thread, void **retval); -typedef int (* mal_pthread_mutex_init_proc)(pthread_mutex_t *__mutex, const pthread_mutexattr_t *__mutexattr); -typedef int (* mal_pthread_mutex_destroy_proc)(pthread_mutex_t *__mutex); -typedef int (* mal_pthread_mutex_lock_proc)(pthread_mutex_t *__mutex); -typedef int (* mal_pthread_mutex_unlock_proc)(pthread_mutex_t *__mutex); -typedef int (* mal_pthread_cond_init_proc)(pthread_cond_t *__restrict __cond, const pthread_condattr_t *__restrict __cond_attr); -typedef int (* mal_pthread_cond_destroy_proc)(pthread_cond_t *__cond); -typedef int (* mal_pthread_cond_signal_proc)(pthread_cond_t *__cond); -typedef int (* mal_pthread_cond_wait_proc)(pthread_cond_t *__restrict __cond, pthread_mutex_t *__restrict __mutex); -typedef int (* mal_pthread_attr_init_proc)(pthread_attr_t *attr); -typedef int (* mal_pthread_attr_destroy_proc)(pthread_attr_t *attr); -typedef int (* mal_pthread_attr_setschedpolicy_proc)(pthread_attr_t *attr, int policy); -typedef int (* mal_pthread_attr_getschedparam_proc)(const pthread_attr_t *attr, struct sched_param *param); -typedef int (* mal_pthread_attr_setschedparam_proc)(pthread_attr_t *attr, const struct sched_param *param); +typedef int (* ma_pthread_create_proc)(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg); +typedef int (* ma_pthread_join_proc)(pthread_t thread, void **retval); +typedef int (* ma_pthread_mutex_init_proc)(pthread_mutex_t *__mutex, const pthread_mutexattr_t *__mutexattr); +typedef int (* ma_pthread_mutex_destroy_proc)(pthread_mutex_t *__mutex); +typedef int (* ma_pthread_mutex_lock_proc)(pthread_mutex_t *__mutex); +typedef int (* ma_pthread_mutex_unlock_proc)(pthread_mutex_t *__mutex); +typedef int (* ma_pthread_cond_init_proc)(pthread_cond_t *__restrict __cond, const pthread_condattr_t *__restrict __cond_attr); +typedef int (* ma_pthread_cond_destroy_proc)(pthread_cond_t *__cond); +typedef int (* ma_pthread_cond_signal_proc)(pthread_cond_t *__cond); +typedef int (* ma_pthread_cond_wait_proc)(pthread_cond_t *__restrict __cond, pthread_mutex_t *__restrict __mutex); +typedef int (* ma_pthread_attr_init_proc)(pthread_attr_t *attr); +typedef int (* ma_pthread_attr_destroy_proc)(pthread_attr_t *attr); +typedef int (* ma_pthread_attr_setschedpolicy_proc)(pthread_attr_t *attr, int policy); +typedef int (* ma_pthread_attr_getschedparam_proc)(const pthread_attr_t *attr, struct sched_param *param); +typedef int (* ma_pthread_attr_setschedparam_proc)(pthread_attr_t *attr, const struct sched_param *param); -mal_bool32 mal_thread_create__posix(mal_context* pContext, mal_thread* pThread, mal_thread_entry_proc entryProc, void* pData) +ma_bool32 ma_thread_create__posix(ma_context* pContext, ma_thread* pThread, ma_thread_entry_proc entryProc, void* pData) { pthread_attr_t* pAttr = NULL; #if !defined(__EMSCRIPTEN__) // Try setting the thread priority. It's not critical if anything fails here. pthread_attr_t attr; - if (((mal_pthread_attr_init_proc)pContext->posix.pthread_attr_init)(&attr) == 0) { + if (((ma_pthread_attr_init_proc)pContext->posix.pthread_attr_init)(&attr) == 0) { int scheduler = -1; - if (pContext->config.threadPriority == mal_thread_priority_idle) { + if (pContext->config.threadPriority == ma_thread_priority_idle) { #ifdef SCHED_IDLE - if (((mal_pthread_attr_setschedpolicy_proc)pContext->posix.pthread_attr_setschedpolicy)(&attr, SCHED_IDLE) == 0) { + if (((ma_pthread_attr_setschedpolicy_proc)pContext->posix.pthread_attr_setschedpolicy)(&attr, SCHED_IDLE) == 0) { scheduler = SCHED_IDLE; } #endif - } else if (pContext->config.threadPriority == mal_thread_priority_realtime) { + } else if (pContext->config.threadPriority == ma_thread_priority_realtime) { #ifdef SCHED_FIFO - if (((mal_pthread_attr_setschedpolicy_proc)pContext->posix.pthread_attr_setschedpolicy)(&attr, SCHED_FIFO) == 0) { + if (((ma_pthread_attr_setschedpolicy_proc)pContext->posix.pthread_attr_setschedpolicy)(&attr, SCHED_FIFO) == 0) { scheduler = SCHED_FIFO; } #endif @@ -4397,10 +4397,10 @@ mal_bool32 mal_thread_create__posix(mal_context* pContext, mal_thread* pThread, int priorityStep = (priorityMax - priorityMin) / 7; // 7 = number of priorities supported by miniaudio. struct sched_param sched; - if (((mal_pthread_attr_getschedparam_proc)pContext->posix.pthread_attr_getschedparam)(&attr, &sched) == 0) { - if (pContext->config.threadPriority == mal_thread_priority_idle) { + if (((ma_pthread_attr_getschedparam_proc)pContext->posix.pthread_attr_getschedparam)(&attr, &sched) == 0) { + if (pContext->config.threadPriority == ma_thread_priority_idle) { sched.sched_priority = priorityMin; - } else if (pContext->config.threadPriority == mal_thread_priority_realtime) { + } else if (pContext->config.threadPriority == ma_thread_priority_realtime) { sched.sched_priority = priorityMax; } else { sched.sched_priority += ((int)pContext->config.threadPriority + 5) * priorityStep; // +5 because the lowest priority is -5. @@ -4412,17 +4412,17 @@ mal_bool32 mal_thread_create__posix(mal_context* pContext, mal_thread* pThread, } } - if (((mal_pthread_attr_setschedparam_proc)pContext->posix.pthread_attr_setschedparam)(&attr, &sched) == 0) { + if (((ma_pthread_attr_setschedparam_proc)pContext->posix.pthread_attr_setschedparam)(&attr, &sched) == 0) { pAttr = &attr; } } } - ((mal_pthread_attr_destroy_proc)pContext->posix.pthread_attr_destroy)(&attr); + ((ma_pthread_attr_destroy_proc)pContext->posix.pthread_attr_destroy)(&attr); } #endif - int result = ((mal_pthread_create_proc)pContext->posix.pthread_create)(&pThread->posix.thread, pAttr, entryProc, pData); + int result = ((ma_pthread_create_proc)pContext->posix.pthread_create)(&pThread->posix.thread, pAttr, entryProc, pData); if (result != 0) { return MA_FAILED_TO_CREATE_THREAD; } @@ -4430,25 +4430,25 @@ mal_bool32 mal_thread_create__posix(mal_context* pContext, mal_thread* pThread, return MA_SUCCESS; } -void mal_thread_wait__posix(mal_thread* pThread) +void ma_thread_wait__posix(ma_thread* pThread) { - ((mal_pthread_join_proc)pThread->pContext->posix.pthread_join)(pThread->posix.thread, NULL); + ((ma_pthread_join_proc)pThread->pContext->posix.pthread_join)(pThread->posix.thread, NULL); } -void mal_sleep__posix(mal_uint32 milliseconds) +void ma_sleep__posix(ma_uint32 milliseconds) { #ifdef MA_EMSCRIPTEN (void)milliseconds; - mal_assert(MA_FALSE); /* The Emscripten build should never sleep. */ + ma_assert(MA_FALSE); /* The Emscripten build should never sleep. */ #else usleep(milliseconds * 1000); /* <-- usleep is in microseconds. */ #endif } -mal_result mal_mutex_init__posix(mal_context* pContext, mal_mutex* pMutex) +ma_result ma_mutex_init__posix(ma_context* pContext, ma_mutex* pMutex) { - int result = ((mal_pthread_mutex_init_proc)pContext->posix.pthread_mutex_init)(&pMutex->posix.mutex, NULL); + int result = ((ma_pthread_mutex_init_proc)pContext->posix.pthread_mutex_init)(&pMutex->posix.mutex, NULL); if (result != 0) { return MA_FAILED_TO_CREATE_MUTEX; } @@ -4456,29 +4456,29 @@ mal_result mal_mutex_init__posix(mal_context* pContext, mal_mutex* pMutex) return MA_SUCCESS; } -void mal_mutex_uninit__posix(mal_mutex* pMutex) +void ma_mutex_uninit__posix(ma_mutex* pMutex) { - ((mal_pthread_mutex_destroy_proc)pMutex->pContext->posix.pthread_mutex_destroy)(&pMutex->posix.mutex); + ((ma_pthread_mutex_destroy_proc)pMutex->pContext->posix.pthread_mutex_destroy)(&pMutex->posix.mutex); } -void mal_mutex_lock__posix(mal_mutex* pMutex) +void ma_mutex_lock__posix(ma_mutex* pMutex) { - ((mal_pthread_mutex_lock_proc)pMutex->pContext->posix.pthread_mutex_lock)(&pMutex->posix.mutex); + ((ma_pthread_mutex_lock_proc)pMutex->pContext->posix.pthread_mutex_lock)(&pMutex->posix.mutex); } -void mal_mutex_unlock__posix(mal_mutex* pMutex) +void ma_mutex_unlock__posix(ma_mutex* pMutex) { - ((mal_pthread_mutex_unlock_proc)pMutex->pContext->posix.pthread_mutex_unlock)(&pMutex->posix.mutex); + ((ma_pthread_mutex_unlock_proc)pMutex->pContext->posix.pthread_mutex_unlock)(&pMutex->posix.mutex); } -mal_result mal_event_init__posix(mal_context* pContext, mal_event* pEvent) +ma_result ma_event_init__posix(ma_context* pContext, ma_event* pEvent) { - if (((mal_pthread_mutex_init_proc)pContext->posix.pthread_mutex_init)(&pEvent->posix.mutex, NULL) != 0) { + if (((ma_pthread_mutex_init_proc)pContext->posix.pthread_mutex_init)(&pEvent->posix.mutex, NULL) != 0) { return MA_FAILED_TO_CREATE_MUTEX; } - if (((mal_pthread_cond_init_proc)pContext->posix.pthread_cond_init)(&pEvent->posix.condition, NULL) != 0) { + if (((ma_pthread_cond_init_proc)pContext->posix.pthread_cond_init)(&pEvent->posix.condition, NULL) != 0) { return MA_FAILED_TO_CREATE_EVENT; } @@ -4486,77 +4486,77 @@ mal_result mal_event_init__posix(mal_context* pContext, mal_event* pEvent) return MA_SUCCESS; } -void mal_event_uninit__posix(mal_event* pEvent) +void ma_event_uninit__posix(ma_event* pEvent) { - ((mal_pthread_cond_destroy_proc)pEvent->pContext->posix.pthread_cond_destroy)(&pEvent->posix.condition); - ((mal_pthread_mutex_destroy_proc)pEvent->pContext->posix.pthread_mutex_destroy)(&pEvent->posix.mutex); + ((ma_pthread_cond_destroy_proc)pEvent->pContext->posix.pthread_cond_destroy)(&pEvent->posix.condition); + ((ma_pthread_mutex_destroy_proc)pEvent->pContext->posix.pthread_mutex_destroy)(&pEvent->posix.mutex); } -mal_bool32 mal_event_wait__posix(mal_event* pEvent) +ma_bool32 ma_event_wait__posix(ma_event* pEvent) { - ((mal_pthread_mutex_lock_proc)pEvent->pContext->posix.pthread_mutex_lock)(&pEvent->posix.mutex); + ((ma_pthread_mutex_lock_proc)pEvent->pContext->posix.pthread_mutex_lock)(&pEvent->posix.mutex); { while (pEvent->posix.value == 0) { - ((mal_pthread_cond_wait_proc)pEvent->pContext->posix.pthread_cond_wait)(&pEvent->posix.condition, &pEvent->posix.mutex); + ((ma_pthread_cond_wait_proc)pEvent->pContext->posix.pthread_cond_wait)(&pEvent->posix.condition, &pEvent->posix.mutex); } pEvent->posix.value = 0; // Auto-reset. } - ((mal_pthread_mutex_unlock_proc)pEvent->pContext->posix.pthread_mutex_unlock)(&pEvent->posix.mutex); + ((ma_pthread_mutex_unlock_proc)pEvent->pContext->posix.pthread_mutex_unlock)(&pEvent->posix.mutex); return MA_TRUE; } -mal_bool32 mal_event_signal__posix(mal_event* pEvent) +ma_bool32 ma_event_signal__posix(ma_event* pEvent) { - ((mal_pthread_mutex_lock_proc)pEvent->pContext->posix.pthread_mutex_lock)(&pEvent->posix.mutex); + ((ma_pthread_mutex_lock_proc)pEvent->pContext->posix.pthread_mutex_lock)(&pEvent->posix.mutex); { pEvent->posix.value = 1; - ((mal_pthread_cond_signal_proc)pEvent->pContext->posix.pthread_cond_signal)(&pEvent->posix.condition); + ((ma_pthread_cond_signal_proc)pEvent->pContext->posix.pthread_cond_signal)(&pEvent->posix.condition); } - ((mal_pthread_mutex_unlock_proc)pEvent->pContext->posix.pthread_mutex_unlock)(&pEvent->posix.mutex); + ((ma_pthread_mutex_unlock_proc)pEvent->pContext->posix.pthread_mutex_unlock)(&pEvent->posix.mutex); return MA_TRUE; } #endif -mal_result mal_thread_create(mal_context* pContext, mal_thread* pThread, mal_thread_entry_proc entryProc, void* pData) +ma_result ma_thread_create(ma_context* pContext, ma_thread* pThread, ma_thread_entry_proc entryProc, void* pData) { if (pContext == NULL || pThread == NULL || entryProc == NULL) return MA_FALSE; pThread->pContext = pContext; #ifdef MA_WIN32 - return mal_thread_create__win32(pContext, pThread, entryProc, pData); + return ma_thread_create__win32(pContext, pThread, entryProc, pData); #endif #ifdef MA_POSIX - return mal_thread_create__posix(pContext, pThread, entryProc, pData); + return ma_thread_create__posix(pContext, pThread, entryProc, pData); #endif } -void mal_thread_wait(mal_thread* pThread) +void ma_thread_wait(ma_thread* pThread) { if (pThread == NULL) return; #ifdef MA_WIN32 - mal_thread_wait__win32(pThread); + ma_thread_wait__win32(pThread); #endif #ifdef MA_POSIX - mal_thread_wait__posix(pThread); + ma_thread_wait__posix(pThread); #endif } -void mal_sleep(mal_uint32 milliseconds) +void ma_sleep(ma_uint32 milliseconds) { #ifdef MA_WIN32 - mal_sleep__win32(milliseconds); + ma_sleep__win32(milliseconds); #endif #ifdef MA_POSIX - mal_sleep__posix(milliseconds); + ma_sleep__posix(milliseconds); #endif } -mal_result mal_mutex_init(mal_context* pContext, mal_mutex* pMutex) +ma_result ma_mutex_init(ma_context* pContext, ma_mutex* pMutex) { if (pContext == NULL || pMutex == NULL) { return MA_INVALID_ARGS; @@ -4565,102 +4565,102 @@ mal_result mal_mutex_init(mal_context* pContext, mal_mutex* pMutex) pMutex->pContext = pContext; #ifdef MA_WIN32 - return mal_mutex_init__win32(pContext, pMutex); + return ma_mutex_init__win32(pContext, pMutex); #endif #ifdef MA_POSIX - return mal_mutex_init__posix(pContext, pMutex); + return ma_mutex_init__posix(pContext, pMutex); #endif } -void mal_mutex_uninit(mal_mutex* pMutex) +void ma_mutex_uninit(ma_mutex* pMutex) { if (pMutex == NULL || pMutex->pContext == NULL) return; #ifdef MA_WIN32 - mal_mutex_uninit__win32(pMutex); + ma_mutex_uninit__win32(pMutex); #endif #ifdef MA_POSIX - mal_mutex_uninit__posix(pMutex); + ma_mutex_uninit__posix(pMutex); #endif } -void mal_mutex_lock(mal_mutex* pMutex) +void ma_mutex_lock(ma_mutex* pMutex) { if (pMutex == NULL || pMutex->pContext == NULL) return; #ifdef MA_WIN32 - mal_mutex_lock__win32(pMutex); + ma_mutex_lock__win32(pMutex); #endif #ifdef MA_POSIX - mal_mutex_lock__posix(pMutex); + ma_mutex_lock__posix(pMutex); #endif } -void mal_mutex_unlock(mal_mutex* pMutex) +void ma_mutex_unlock(ma_mutex* pMutex) { if (pMutex == NULL || pMutex->pContext == NULL) return; #ifdef MA_WIN32 - mal_mutex_unlock__win32(pMutex); + ma_mutex_unlock__win32(pMutex); #endif #ifdef MA_POSIX - mal_mutex_unlock__posix(pMutex); + ma_mutex_unlock__posix(pMutex); #endif } -mal_result mal_event_init(mal_context* pContext, mal_event* pEvent) +ma_result ma_event_init(ma_context* pContext, ma_event* pEvent) { if (pContext == NULL || pEvent == NULL) return MA_FALSE; pEvent->pContext = pContext; #ifdef MA_WIN32 - return mal_event_init__win32(pContext, pEvent); + return ma_event_init__win32(pContext, pEvent); #endif #ifdef MA_POSIX - return mal_event_init__posix(pContext, pEvent); + return ma_event_init__posix(pContext, pEvent); #endif } -void mal_event_uninit(mal_event* pEvent) +void ma_event_uninit(ma_event* pEvent) { if (pEvent == NULL || pEvent->pContext == NULL) return; #ifdef MA_WIN32 - mal_event_uninit__win32(pEvent); + ma_event_uninit__win32(pEvent); #endif #ifdef MA_POSIX - mal_event_uninit__posix(pEvent); + ma_event_uninit__posix(pEvent); #endif } -mal_bool32 mal_event_wait(mal_event* pEvent) +ma_bool32 ma_event_wait(ma_event* pEvent) { if (pEvent == NULL || pEvent->pContext == NULL) return MA_FALSE; #ifdef MA_WIN32 - return mal_event_wait__win32(pEvent); + return ma_event_wait__win32(pEvent); #endif #ifdef MA_POSIX - return mal_event_wait__posix(pEvent); + return ma_event_wait__posix(pEvent); #endif } -mal_bool32 mal_event_signal(mal_event* pEvent) +ma_bool32 ma_event_signal(ma_event* pEvent) { if (pEvent == NULL || pEvent->pContext == NULL) return MA_FALSE; #ifdef MA_WIN32 - return mal_event_signal__win32(pEvent); + return ma_event_signal__win32(pEvent); #endif #ifdef MA_POSIX - return mal_event_signal__posix(pEvent); + return ma_event_signal__posix(pEvent); #endif } -mal_uint32 mal_get_best_sample_rate_within_range(mal_uint32 sampleRateMin, mal_uint32 sampleRateMax) +ma_uint32 ma_get_best_sample_rate_within_range(ma_uint32 sampleRateMin, ma_uint32 sampleRateMax) { // Normalize the range in case we were given something stupid. if (sampleRateMin < MA_MIN_SAMPLE_RATE) { @@ -4676,8 +4676,8 @@ mal_uint32 mal_get_best_sample_rate_within_range(mal_uint32 sampleRateMin, mal_u if (sampleRateMin == sampleRateMax) { return sampleRateMax; } else { - for (size_t iStandardRate = 0; iStandardRate < mal_countof(g_malStandardSampleRatePriorities); ++iStandardRate) { - mal_uint32 standardRate = g_malStandardSampleRatePriorities[iStandardRate]; + for (size_t iStandardRate = 0; iStandardRate < ma_countof(g_malStandardSampleRatePriorities); ++iStandardRate) { + ma_uint32 standardRate = g_malStandardSampleRatePriorities[iStandardRate]; if (standardRate >= sampleRateMin && standardRate <= sampleRateMax) { return standardRate; } @@ -4685,19 +4685,19 @@ mal_uint32 mal_get_best_sample_rate_within_range(mal_uint32 sampleRateMin, mal_u } // Should never get here. - mal_assert(MA_FALSE); + ma_assert(MA_FALSE); return 0; } -mal_uint32 mal_get_closest_standard_sample_rate(mal_uint32 sampleRateIn) +ma_uint32 ma_get_closest_standard_sample_rate(ma_uint32 sampleRateIn) { - mal_uint32 closestRate = 0; - mal_uint32 closestDiff = 0xFFFFFFFF; + ma_uint32 closestRate = 0; + ma_uint32 closestDiff = 0xFFFFFFFF; - for (size_t iStandardRate = 0; iStandardRate < mal_countof(g_malStandardSampleRatePriorities); ++iStandardRate) { - mal_uint32 standardRate = g_malStandardSampleRatePriorities[iStandardRate]; + for (size_t iStandardRate = 0; iStandardRate < ma_countof(g_malStandardSampleRatePriorities); ++iStandardRate) { + ma_uint32 standardRate = g_malStandardSampleRatePriorities[iStandardRate]; - mal_uint32 diff; + ma_uint32 diff; if (sampleRateIn > standardRate) { diff = sampleRateIn - standardRate; } else { @@ -4718,38 +4718,38 @@ mal_uint32 mal_get_closest_standard_sample_rate(mal_uint32 sampleRateIn) } -mal_uint32 mal_scale_buffer_size(mal_uint32 baseBufferSize, float scale) +ma_uint32 ma_scale_buffer_size(ma_uint32 baseBufferSize, float scale) { - return mal_max(1, (mal_uint32)(baseBufferSize*scale)); + return ma_max(1, (ma_uint32)(baseBufferSize*scale)); } -mal_uint32 mal_calculate_buffer_size_in_milliseconds_from_frames(mal_uint32 bufferSizeInFrames, mal_uint32 sampleRate) +ma_uint32 ma_calculate_buffer_size_in_milliseconds_from_frames(ma_uint32 bufferSizeInFrames, ma_uint32 sampleRate) { return bufferSizeInFrames / (sampleRate/1000); } -mal_uint32 mal_calculate_buffer_size_in_frames_from_milliseconds(mal_uint32 bufferSizeInMilliseconds, mal_uint32 sampleRate) +ma_uint32 ma_calculate_buffer_size_in_frames_from_milliseconds(ma_uint32 bufferSizeInMilliseconds, ma_uint32 sampleRate) { return bufferSizeInMilliseconds * (sampleRate/1000); } -mal_uint32 mal_get_default_buffer_size_in_milliseconds(mal_performance_profile performanceProfile) +ma_uint32 ma_get_default_buffer_size_in_milliseconds(ma_performance_profile performanceProfile) { - if (performanceProfile == mal_performance_profile_low_latency) { + if (performanceProfile == ma_performance_profile_low_latency) { return MA_BASE_BUFFER_SIZE_IN_MILLISECONDS_LOW_LATENCY; } else { return MA_BASE_BUFFER_SIZE_IN_MILLISECONDS_CONSERVATIVE; } } -mal_uint32 mal_get_default_buffer_size_in_frames(mal_performance_profile performanceProfile, mal_uint32 sampleRate) +ma_uint32 ma_get_default_buffer_size_in_frames(ma_performance_profile performanceProfile, ma_uint32 sampleRate) { - mal_uint32 bufferSizeInMilliseconds = mal_get_default_buffer_size_in_milliseconds(performanceProfile); + ma_uint32 bufferSizeInMilliseconds = ma_get_default_buffer_size_in_milliseconds(performanceProfile); if (bufferSizeInMilliseconds == 0) { bufferSizeInMilliseconds = 1; } - mal_uint32 sampleRateMS = (sampleRate/1000); + ma_uint32 sampleRateMS = (sampleRate/1000); if (sampleRateMS == 0) { sampleRateMS = 1; } @@ -4757,19 +4757,19 @@ mal_uint32 mal_get_default_buffer_size_in_frames(mal_performance_profile perform return bufferSizeInMilliseconds * sampleRateMS; } -mal_uint32 mal_get_fragment_size_in_bytes(mal_uint32 bufferSizeInFrames, mal_uint32 periods, mal_format format, mal_uint32 channels) +ma_uint32 ma_get_fragment_size_in_bytes(ma_uint32 bufferSizeInFrames, ma_uint32 periods, ma_format format, ma_uint32 channels) { - mal_uint32 fragmentSizeInFrames = bufferSizeInFrames / periods; - return fragmentSizeInFrames * mal_get_bytes_per_frame(format, channels); + ma_uint32 fragmentSizeInFrames = bufferSizeInFrames / periods; + return fragmentSizeInFrames * ma_get_bytes_per_frame(format, channels); } -void mal_zero_pcm_frames(void* p, mal_uint32 frameCount, mal_format format, mal_uint32 channels) +void ma_zero_pcm_frames(void* p, ma_uint32 frameCount, ma_format format, ma_uint32 channels) { - mal_zero_memory(p, frameCount * mal_get_bytes_per_frame(format, channels)); + ma_zero_memory(p, frameCount * ma_get_bytes_per_frame(format, channels)); } -const char* mal_log_level_to_string(mal_uint32 logLevel) +const char* ma_log_level_to_string(ma_uint32 logLevel) { switch (logLevel) { @@ -4782,7 +4782,7 @@ const char* mal_log_level_to_string(mal_uint32 logLevel) } // Posts a log message. -void mal_log(mal_context* pContext, mal_device* pDevice, mal_uint32 logLevel, const char* message) +void ma_log(ma_context* pContext, ma_device* pDevice, ma_uint32 logLevel, const char* message) { if (pContext == NULL) return; @@ -4790,11 +4790,11 @@ void mal_log(mal_context* pContext, mal_device* pDevice, mal_uint32 logLevel, co if (logLevel <= MA_LOG_LEVEL) { #if defined(MA_DEBUG_OUTPUT) if (logLevel <= MA_LOG_LEVEL) { - printf("%s: %s\n", mal_log_level_to_string(logLevel), message); + printf("%s: %s\n", ma_log_level_to_string(logLevel), message); } #endif - mal_log_proc onLog = pContext->config.logCallback; + ma_log_proc onLog = pContext->config.logCallback; if (onLog) { onLog(pContext, pDevice, logLevel, message); } @@ -4803,7 +4803,7 @@ void mal_log(mal_context* pContext, mal_device* pDevice, mal_uint32 logLevel, co } // Posts an error. Throw a breakpoint in here if you're needing to debug. The return value is always "resultCode". -mal_result mal_context_post_error(mal_context* pContext, mal_device* pDevice, mal_uint32 logLevel, const char* message, mal_result resultCode) +ma_result ma_context_post_error(ma_context* pContext, ma_device* pDevice, ma_uint32 logLevel, const char* message, ma_result resultCode) { // Derive the context from the device if necessary. if (pContext == NULL) { @@ -4812,28 +4812,28 @@ mal_result mal_context_post_error(mal_context* pContext, mal_device* pDevice, ma } } - mal_log(pContext, pDevice, logLevel, message); + ma_log(pContext, pDevice, logLevel, message); return resultCode; } -mal_result mal_post_error(mal_device* pDevice, mal_uint32 logLevel, const char* message, mal_result resultCode) +ma_result ma_post_error(ma_device* pDevice, ma_uint32 logLevel, const char* message, ma_result resultCode) { - return mal_context_post_error(NULL, pDevice, logLevel, message, resultCode); + return ma_context_post_error(NULL, pDevice, logLevel, message, resultCode); } // The callback for reading from the client -> DSP -> device. -mal_uint32 mal_device__on_read_from_client(mal_pcm_converter* pDSP, void* pFramesOut, mal_uint32 frameCount, void* pUserData) +ma_uint32 ma_device__on_read_from_client(ma_pcm_converter* pDSP, void* pFramesOut, ma_uint32 frameCount, void* pUserData) { (void)pDSP; - mal_device* pDevice = (mal_device*)pUserData; - mal_assert(pDevice != NULL); + ma_device* pDevice = (ma_device*)pUserData; + ma_assert(pDevice != NULL); - mal_zero_pcm_frames(pFramesOut, frameCount, pDevice->playback.format, pDevice->playback.channels); + ma_zero_pcm_frames(pFramesOut, frameCount, pDevice->playback.format, pDevice->playback.channels); - mal_device_callback_proc onData = pDevice->onData; + ma_device_callback_proc onData = pDevice->onData; if (onData) { onData(pDevice, pFramesOut, NULL, frameCount); return frameCount; @@ -4843,44 +4843,44 @@ mal_uint32 mal_device__on_read_from_client(mal_pcm_converter* pDSP, void* pFrame } /* The PCM converter callback for reading from a buffer. */ -mal_uint32 mal_device__pcm_converter__on_read_from_buffer_capture(mal_pcm_converter* pConverter, void* pFramesOut, mal_uint32 frameCount, void* pUserData) +ma_uint32 ma_device__pcm_converter__on_read_from_buffer_capture(ma_pcm_converter* pConverter, void* pFramesOut, ma_uint32 frameCount, void* pUserData) { - mal_device* pDevice = (mal_device*)pUserData; - mal_assert(pDevice != NULL); + ma_device* pDevice = (ma_device*)pUserData; + ma_assert(pDevice != NULL); if (pDevice->capture._dspFrameCount == 0) { return 0; // Nothing left. } - mal_uint32 framesToRead = frameCount; + ma_uint32 framesToRead = frameCount; if (framesToRead > pDevice->capture._dspFrameCount) { framesToRead = pDevice->capture._dspFrameCount; } - mal_uint32 bytesToRead = framesToRead * mal_get_bytes_per_frame(pConverter->formatConverterIn.config.formatIn, pConverter->channelRouter.config.channelsIn); - mal_copy_memory(pFramesOut, pDevice->capture._dspFrames, bytesToRead); + ma_uint32 bytesToRead = framesToRead * ma_get_bytes_per_frame(pConverter->formatConverterIn.config.formatIn, pConverter->channelRouter.config.channelsIn); + ma_copy_memory(pFramesOut, pDevice->capture._dspFrames, bytesToRead); pDevice->capture._dspFrameCount -= framesToRead; pDevice->capture._dspFrames += bytesToRead; return framesToRead; } -mal_uint32 mal_device__pcm_converter__on_read_from_buffer_playback(mal_pcm_converter* pConverter, void* pFramesOut, mal_uint32 frameCount, void* pUserData) +ma_uint32 ma_device__pcm_converter__on_read_from_buffer_playback(ma_pcm_converter* pConverter, void* pFramesOut, ma_uint32 frameCount, void* pUserData) { - mal_device* pDevice = (mal_device*)pUserData; - mal_assert(pDevice != NULL); + ma_device* pDevice = (ma_device*)pUserData; + ma_assert(pDevice != NULL); if (pDevice->playback._dspFrameCount == 0) { return 0; // Nothing left. } - mal_uint32 framesToRead = frameCount; + ma_uint32 framesToRead = frameCount; if (framesToRead > pDevice->playback._dspFrameCount) { framesToRead = pDevice->playback._dspFrameCount; } - mal_uint32 bytesToRead = framesToRead * mal_get_bytes_per_frame(pConverter->formatConverterIn.config.formatIn, pConverter->channelRouter.config.channelsIn); - mal_copy_memory(pFramesOut, pDevice->playback._dspFrames, bytesToRead); + ma_uint32 bytesToRead = framesToRead * ma_get_bytes_per_frame(pConverter->formatConverterIn.config.formatIn, pConverter->channelRouter.config.channelsIn); + ma_copy_memory(pFramesOut, pDevice->playback._dspFrames, bytesToRead); pDevice->playback._dspFrameCount -= framesToRead; pDevice->playback._dspFrames += bytesToRead; @@ -4890,32 +4890,32 @@ mal_uint32 mal_device__pcm_converter__on_read_from_buffer_playback(mal_pcm_conve // A helper function for reading sample data from the client. -static MA_INLINE void mal_device__read_frames_from_client(mal_device* pDevice, mal_uint32 frameCount, void* pSamples) +static MA_INLINE void ma_device__read_frames_from_client(ma_device* pDevice, ma_uint32 frameCount, void* pSamples) { - mal_assert(pDevice != NULL); - mal_assert(frameCount > 0); - mal_assert(pSamples != NULL); + ma_assert(pDevice != NULL); + ma_assert(frameCount > 0); + ma_assert(pSamples != NULL); - mal_pcm_converter_read(&pDevice->playback.converter, pSamples, frameCount); + ma_pcm_converter_read(&pDevice->playback.converter, pSamples, frameCount); } // A helper for sending sample data to the client. -static MA_INLINE void mal_device__send_frames_to_client(mal_device* pDevice, mal_uint32 frameCount, const void* pSamples) +static MA_INLINE void ma_device__send_frames_to_client(ma_device* pDevice, ma_uint32 frameCount, const void* pSamples) { - mal_assert(pDevice != NULL); - mal_assert(frameCount > 0); - mal_assert(pSamples != NULL); + ma_assert(pDevice != NULL); + ma_assert(frameCount > 0); + ma_assert(pSamples != NULL); - mal_device_callback_proc onData = pDevice->onData; + ma_device_callback_proc onData = pDevice->onData; if (onData) { pDevice->capture._dspFrameCount = frameCount; - pDevice->capture._dspFrames = (const mal_uint8*)pSamples; + pDevice->capture._dspFrames = (const ma_uint8*)pSamples; - mal_uint8 chunkBuffer[4096]; - mal_uint32 chunkFrameCount = sizeof(chunkBuffer) / mal_get_bytes_per_frame(pDevice->capture.format, pDevice->capture.channels); + ma_uint8 chunkBuffer[4096]; + ma_uint32 chunkFrameCount = sizeof(chunkBuffer) / ma_get_bytes_per_frame(pDevice->capture.format, pDevice->capture.channels); for (;;) { - mal_uint32 framesJustRead = (mal_uint32)mal_pcm_converter_read(&pDevice->capture.converter, chunkBuffer, chunkFrameCount); + ma_uint32 framesJustRead = (ma_uint32)ma_pcm_converter_read(&pDevice->capture.converter, chunkBuffer, chunkFrameCount); if (framesJustRead == 0) { break; } @@ -4929,41 +4929,41 @@ static MA_INLINE void mal_device__send_frames_to_client(mal_device* pDevice, mal } } -static MA_INLINE mal_result mal_device__handle_duplex_callback_capture(mal_device* pDevice, mal_uint32 frameCount, const void* pFramesInInternalFormat, mal_pcm_rb* pRB) +static MA_INLINE ma_result ma_device__handle_duplex_callback_capture(ma_device* pDevice, ma_uint32 frameCount, const void* pFramesInInternalFormat, ma_pcm_rb* pRB) { - mal_assert(pDevice != NULL); - mal_assert(frameCount > 0); - mal_assert(pFramesInInternalFormat != NULL); - mal_assert(pRB != NULL); + ma_assert(pDevice != NULL); + ma_assert(frameCount > 0); + ma_assert(pFramesInInternalFormat != NULL); + ma_assert(pRB != NULL); - mal_result result; + ma_result result; - pDevice->capture._dspFrameCount = (mal_uint32)frameCount; - pDevice->capture._dspFrames = (const mal_uint8*)pFramesInInternalFormat; + pDevice->capture._dspFrameCount = (ma_uint32)frameCount; + pDevice->capture._dspFrames = (const ma_uint8*)pFramesInInternalFormat; /* Write to the ring buffer. The ring buffer is in the external format. */ for (;;) { - mal_uint32 framesProcessed; - mal_uint32 framesToProcess = 256; + ma_uint32 framesProcessed; + ma_uint32 framesToProcess = 256; void* pFramesInExternalFormat; - result = mal_pcm_rb_acquire_write(pRB, &framesToProcess, &pFramesInExternalFormat); + result = ma_pcm_rb_acquire_write(pRB, &framesToProcess, &pFramesInExternalFormat); if (result != MA_SUCCESS) { - mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "Failed to acquire capture PCM frames from ring buffer.", result); + ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "Failed to acquire capture PCM frames from ring buffer.", result); break; } if (framesToProcess == 0) { - if (mal_pcm_rb_pointer_disance(pRB) == (mal_int32)mal_pcm_rb_get_subbuffer_size(pRB)) { + if (ma_pcm_rb_pointer_disance(pRB) == (ma_int32)ma_pcm_rb_get_subbuffer_size(pRB)) { break; /* Overrun. Not enough room in the ring buffer for input frame. Excess frames are dropped. */ } } /* Convert. */ - framesProcessed = (mal_uint32)mal_pcm_converter_read(&pDevice->capture.converter, pFramesInExternalFormat, framesToProcess); + framesProcessed = (ma_uint32)ma_pcm_converter_read(&pDevice->capture.converter, pFramesInExternalFormat, framesToProcess); - result = mal_pcm_rb_commit_write(pRB, framesProcessed, pFramesInExternalFormat); + result = ma_pcm_rb_commit_write(pRB, framesProcessed, pFramesInExternalFormat); if (result != MA_SUCCESS) { - mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "Failed to commit capture PCM frames to ring buffer.", result); + ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "Failed to commit capture PCM frames to ring buffer.", result); break; } @@ -4975,56 +4975,56 @@ static MA_INLINE mal_result mal_device__handle_duplex_callback_capture(mal_devic return MA_SUCCESS; } -static MA_INLINE mal_result mal_device__handle_duplex_callback_playback(mal_device* pDevice, mal_uint32 frameCount, void* pFramesInInternalFormat, mal_pcm_rb* pRB) +static MA_INLINE ma_result ma_device__handle_duplex_callback_playback(ma_device* pDevice, ma_uint32 frameCount, void* pFramesInInternalFormat, ma_pcm_rb* pRB) { - mal_assert(pDevice != NULL); - mal_assert(frameCount > 0); - mal_assert(pFramesInInternalFormat != NULL); - mal_assert(pRB != NULL); + ma_assert(pDevice != NULL); + ma_assert(frameCount > 0); + ma_assert(pFramesInInternalFormat != NULL); + ma_assert(pRB != NULL); /* Sitting in the ring buffer should be captured data from the capture callback in external format. If there's not enough data in there for the whole frameCount frames we just use silence instead for the input data. */ - mal_result result; - mal_uint8 playbackFramesInExternalFormat[4096]; - mal_uint8 silentInputFrames[4096]; - mal_zero_memory(silentInputFrames, sizeof(silentInputFrames)); + ma_result result; + ma_uint8 playbackFramesInExternalFormat[4096]; + ma_uint8 silentInputFrames[4096]; + ma_zero_memory(silentInputFrames, sizeof(silentInputFrames)); /* We need to calculate how many output frames are required to be read from the client to completely fill frameCount internal frames. */ - mal_uint32 totalFramesToReadFromClient = (mal_uint32)mal_calculate_frame_count_after_src(pDevice->sampleRate, pDevice->playback.internalSampleRate, frameCount); // mal_pcm_converter_get_required_input_frame_count(&pDevice->playback.converter, (mal_uint32)frameCount); - mal_uint32 totalFramesReadFromClient = 0; - while (totalFramesReadFromClient < totalFramesToReadFromClient && mal_device_is_started(pDevice)) { - mal_uint32 framesRemainingFromClient = (totalFramesToReadFromClient - totalFramesReadFromClient); - mal_uint32 framesToProcessFromClient = sizeof(playbackFramesInExternalFormat) / mal_get_bytes_per_frame(pDevice->playback.format, pDevice->playback.channels); + ma_uint32 totalFramesToReadFromClient = (ma_uint32)ma_calculate_frame_count_after_src(pDevice->sampleRate, pDevice->playback.internalSampleRate, frameCount); // ma_pcm_converter_get_required_input_frame_count(&pDevice->playback.converter, (ma_uint32)frameCount); + ma_uint32 totalFramesReadFromClient = 0; + while (totalFramesReadFromClient < totalFramesToReadFromClient && ma_device_is_started(pDevice)) { + ma_uint32 framesRemainingFromClient = (totalFramesToReadFromClient - totalFramesReadFromClient); + ma_uint32 framesToProcessFromClient = sizeof(playbackFramesInExternalFormat) / ma_get_bytes_per_frame(pDevice->playback.format, pDevice->playback.channels); if (framesToProcessFromClient > framesRemainingFromClient) { framesToProcessFromClient = framesRemainingFromClient; } /* We need to grab captured samples before firing the callback. If there's not enough input samples we just pass silence. */ - mal_uint32 inputFrameCount = framesToProcessFromClient; + ma_uint32 inputFrameCount = framesToProcessFromClient; void* pInputFrames; - result = mal_pcm_rb_acquire_read(pRB, &inputFrameCount, &pInputFrames); + result = ma_pcm_rb_acquire_read(pRB, &inputFrameCount, &pInputFrames); if (result == MA_SUCCESS) { if (inputFrameCount > 0) { /* Use actual input frames. */ pDevice->onData(pDevice, playbackFramesInExternalFormat, pInputFrames, inputFrameCount); } else { - if (mal_pcm_rb_pointer_disance(pRB) == 0) { + if (ma_pcm_rb_pointer_disance(pRB) == 0) { break; /* Underrun. */ } } /* We're done with the captured samples. */ - result = mal_pcm_rb_commit_read(pRB, inputFrameCount, pInputFrames); + result = ma_pcm_rb_commit_read(pRB, inputFrameCount, pInputFrames); if (result != MA_SUCCESS) { break; /* Don't know what to do here... Just abandon ship. */ } } else { /* Use silent input frames. */ - inputFrameCount = mal_min( - sizeof(playbackFramesInExternalFormat) / mal_get_bytes_per_frame(pDevice->playback.format, pDevice->playback.channels), - sizeof(silentInputFrames) / mal_get_bytes_per_frame(pDevice->capture.format, pDevice->capture.channels) + inputFrameCount = ma_min( + sizeof(playbackFramesInExternalFormat) / ma_get_bytes_per_frame(pDevice->playback.format, pDevice->playback.channels), + sizeof(silentInputFrames) / ma_get_bytes_per_frame(pDevice->capture.format, pDevice->capture.channels) ); pDevice->onData(pDevice, playbackFramesInExternalFormat, silentInputFrames, inputFrameCount); @@ -5032,30 +5032,30 @@ static MA_INLINE mal_result mal_device__handle_duplex_callback_playback(mal_devi /* We have samples in external format so now we need to convert to internal format and output to the device. */ pDevice->playback._dspFrameCount = inputFrameCount; - pDevice->playback._dspFrames = (const mal_uint8*)playbackFramesInExternalFormat; - mal_pcm_converter_read(&pDevice->playback.converter, pFramesInInternalFormat, inputFrameCount); + pDevice->playback._dspFrames = (const ma_uint8*)playbackFramesInExternalFormat; + ma_pcm_converter_read(&pDevice->playback.converter, pFramesInInternalFormat, inputFrameCount); totalFramesReadFromClient += inputFrameCount; - pFramesInInternalFormat = mal_offset_ptr(pFramesInInternalFormat, inputFrameCount * mal_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels)); + pFramesInInternalFormat = ma_offset_ptr(pFramesInInternalFormat, inputFrameCount * ma_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels)); } return MA_SUCCESS; } // A helper for changing the state of the device. -static MA_INLINE void mal_device__set_state(mal_device* pDevice, mal_uint32 newState) +static MA_INLINE void ma_device__set_state(ma_device* pDevice, ma_uint32 newState) { - mal_atomic_exchange_32(&pDevice->state, newState); + ma_atomic_exchange_32(&pDevice->state, newState); } // A helper for getting the state of the device. -static MA_INLINE mal_uint32 mal_device__get_state(mal_device* pDevice) +static MA_INLINE ma_uint32 ma_device__get_state(ma_device* pDevice) { return pDevice->state; } /* A helper for determining whether or not the device is running in async mode. */ -static MA_INLINE mal_bool32 mal_device__is_async(mal_device* pDevice) +static MA_INLINE ma_bool32 ma_device__is_async(ma_device* pDevice) { return pDevice->onData != NULL; } @@ -5069,9 +5069,9 @@ static MA_INLINE mal_bool32 mal_device__is_async(mal_device* pDevice) #endif -mal_bool32 mal_context__device_id_equal(mal_context* pContext, const mal_device_id* pID0, const mal_device_id* pID1) +ma_bool32 ma_context__device_id_equal(ma_context* pContext, const ma_device_id* pID0, const ma_device_id* pID1) { - mal_assert(pContext != NULL); + ma_assert(pContext != NULL); if (pID0 == pID1) return MA_TRUE; @@ -5090,21 +5090,21 @@ mal_bool32 mal_context__device_id_equal(mal_context* pContext, const mal_device_ typedef struct { - mal_device_type deviceType; - const mal_device_id* pDeviceID; + ma_device_type deviceType; + const ma_device_id* pDeviceID; char* pName; size_t nameBufferSize; - mal_bool32 foundDevice; -} mal_context__try_get_device_name_by_id__enum_callback_data; + ma_bool32 foundDevice; +} ma_context__try_get_device_name_by_id__enum_callback_data; -mal_bool32 mal_context__try_get_device_name_by_id__enum_callback(mal_context* pContext, mal_device_type deviceType, const mal_device_info* pDeviceInfo, void* pUserData) +ma_bool32 ma_context__try_get_device_name_by_id__enum_callback(ma_context* pContext, ma_device_type deviceType, const ma_device_info* pDeviceInfo, void* pUserData) { - mal_context__try_get_device_name_by_id__enum_callback_data* pData = (mal_context__try_get_device_name_by_id__enum_callback_data*)pUserData; - mal_assert(pData != NULL); + ma_context__try_get_device_name_by_id__enum_callback_data* pData = (ma_context__try_get_device_name_by_id__enum_callback_data*)pUserData; + ma_assert(pData != NULL); if (pData->deviceType == deviceType) { if (pContext->onDeviceIDEqual(pContext, pData->pDeviceID, &pDeviceInfo->id)) { - mal_strncpy_s(pData->pName, pData->nameBufferSize, pDeviceInfo->name, (size_t)-1); + ma_strncpy_s(pData->pName, pData->nameBufferSize, pDeviceInfo->name, (size_t)-1); pData->foundDevice = MA_TRUE; } } @@ -5115,22 +5115,22 @@ mal_bool32 mal_context__try_get_device_name_by_id__enum_callback(mal_context* pC // Generic function for retrieving the name of a device by it's ID. // // This function simply enumerates every device and then retrieves the name of the first device that has the same ID. -mal_result mal_context__try_get_device_name_by_id(mal_context* pContext, mal_device_type deviceType, const mal_device_id* pDeviceID, char* pName, size_t nameBufferSize) +ma_result ma_context__try_get_device_name_by_id(ma_context* pContext, ma_device_type deviceType, const ma_device_id* pDeviceID, char* pName, size_t nameBufferSize) { - mal_assert(pContext != NULL); - mal_assert(pName != NULL); + ma_assert(pContext != NULL); + ma_assert(pName != NULL); if (pDeviceID == NULL) { return MA_NO_DEVICE; } - mal_context__try_get_device_name_by_id__enum_callback_data data; + ma_context__try_get_device_name_by_id__enum_callback_data data; data.deviceType = deviceType; data.pDeviceID = pDeviceID; data.pName = pName; data.nameBufferSize = nameBufferSize; data.foundDevice = MA_FALSE; - mal_result result = mal_context_enumerate_devices(pContext, mal_context__try_get_device_name_by_id__enum_callback, &data); + ma_result result = ma_context_enumerate_devices(pContext, ma_context__try_get_device_name_by_id__enum_callback, &data); if (result != MA_SUCCESS) { return result; } @@ -5143,19 +5143,19 @@ mal_result mal_context__try_get_device_name_by_id(mal_context* pContext, mal_dev } -mal_uint32 mal_get_format_priority_index(mal_format format) // Lower = better. +ma_uint32 ma_get_format_priority_index(ma_format format) // Lower = better. { - for (mal_uint32 i = 0; i < mal_countof(g_malFormatPriorities); ++i) { + for (ma_uint32 i = 0; i < ma_countof(g_malFormatPriorities); ++i) { if (g_malFormatPriorities[i] == format) { return i; } } - // Getting here means the format could not be found or is equal to mal_format_unknown. - return (mal_uint32)-1; + // Getting here means the format could not be found or is equal to ma_format_unknown. + return (ma_uint32)-1; } -void mal_device__post_init_setup(mal_device* pDevice, mal_device_type deviceType); +void ma_device__post_init_setup(ma_device* pDevice, ma_device_type deviceType); /////////////////////////////////////////////////////////////////////////////// // @@ -5169,135 +5169,135 @@ void mal_device__post_init_setup(mal_device* pDevice, mal_device_type deviceType #define MA_DEVICE_OP_SUSPEND__NULL 2 #define MA_DEVICE_OP_KILL__NULL 3 -mal_thread_result MA_THREADCALL mal_device_thread__null(void* pData) +ma_thread_result MA_THREADCALL ma_device_thread__null(void* pData) { - mal_device* pDevice = (mal_device*)pData; - mal_assert(pDevice != NULL); + ma_device* pDevice = (ma_device*)pData; + ma_assert(pDevice != NULL); for (;;) { /* Keep the thread alive until the device is uninitialized. */ /* Wait for an operation to be requested. */ - mal_event_wait(&pDevice->null_device.operationEvent); + ma_event_wait(&pDevice->null_device.operationEvent); /* At this point an event should have been triggered. */ /* Starting the device needs to put the thread into a loop. */ if (pDevice->null_device.operation == MA_DEVICE_OP_START__NULL) { - mal_atomic_exchange_32(&pDevice->null_device.operation, MA_DEVICE_OP_NONE__NULL); + ma_atomic_exchange_32(&pDevice->null_device.operation, MA_DEVICE_OP_NONE__NULL); /* Reset the timer just in case. */ - mal_timer_init(&pDevice->null_device.timer); + ma_timer_init(&pDevice->null_device.timer); /* Keep looping until an operation has been requested. */ while (pDevice->null_device.operation != MA_DEVICE_OP_NONE__NULL && pDevice->null_device.operation != MA_DEVICE_OP_START__NULL) { - mal_sleep(10); /* Don't hog the CPU. */ + ma_sleep(10); /* Don't hog the CPU. */ } /* Getting here means a suspend or kill operation has been requested. */ - mal_atomic_exchange_32(&pDevice->null_device.operationResult, MA_SUCCESS); - mal_event_signal(&pDevice->null_device.operationCompletionEvent); + ma_atomic_exchange_32(&pDevice->null_device.operationResult, MA_SUCCESS); + ma_event_signal(&pDevice->null_device.operationCompletionEvent); continue; } /* Suspending the device means we need to stop the timer and just continue the loop. */ if (pDevice->null_device.operation == MA_DEVICE_OP_SUSPEND__NULL) { - mal_atomic_exchange_32(&pDevice->null_device.operation, MA_DEVICE_OP_NONE__NULL); + ma_atomic_exchange_32(&pDevice->null_device.operation, MA_DEVICE_OP_NONE__NULL); /* We need to add the current run time to the prior run time, then reset the timer. */ - pDevice->null_device.priorRunTime += mal_timer_get_time_in_seconds(&pDevice->null_device.timer); - mal_timer_init(&pDevice->null_device.timer); + pDevice->null_device.priorRunTime += ma_timer_get_time_in_seconds(&pDevice->null_device.timer); + ma_timer_init(&pDevice->null_device.timer); /* We're done. */ - mal_atomic_exchange_32(&pDevice->null_device.operationResult, MA_SUCCESS); - mal_event_signal(&pDevice->null_device.operationCompletionEvent); + ma_atomic_exchange_32(&pDevice->null_device.operationResult, MA_SUCCESS); + ma_event_signal(&pDevice->null_device.operationCompletionEvent); continue; } /* Killing the device means we need to get out of this loop so that this thread can terminate. */ if (pDevice->null_device.operation == MA_DEVICE_OP_KILL__NULL) { - mal_atomic_exchange_32(&pDevice->null_device.operation, MA_DEVICE_OP_NONE__NULL); - mal_atomic_exchange_32(&pDevice->null_device.operationResult, MA_SUCCESS); - mal_event_signal(&pDevice->null_device.operationCompletionEvent); + ma_atomic_exchange_32(&pDevice->null_device.operation, MA_DEVICE_OP_NONE__NULL); + ma_atomic_exchange_32(&pDevice->null_device.operationResult, MA_SUCCESS); + ma_event_signal(&pDevice->null_device.operationCompletionEvent); break; } /* Getting a signal on a "none" operation probably means an error. Return invalid operation. */ if (pDevice->null_device.operation == MA_DEVICE_OP_NONE__NULL) { - mal_assert(MA_FALSE); /* <-- Trigger this in debug mode to ensure developers are aware they're doing something wrong (or there's a bug in a miniaudio). */ - mal_atomic_exchange_32(&pDevice->null_device.operationResult, MA_INVALID_OPERATION); - mal_event_signal(&pDevice->null_device.operationCompletionEvent); + ma_assert(MA_FALSE); /* <-- Trigger this in debug mode to ensure developers are aware they're doing something wrong (or there's a bug in a miniaudio). */ + ma_atomic_exchange_32(&pDevice->null_device.operationResult, MA_INVALID_OPERATION); + ma_event_signal(&pDevice->null_device.operationCompletionEvent); continue; /* Continue the loop. Don't terminate. */ } } - return (mal_thread_result)0; + return (ma_thread_result)0; } -mal_result mal_device_do_operation__null(mal_device* pDevice, mal_uint32 operation) +ma_result ma_device_do_operation__null(ma_device* pDevice, ma_uint32 operation) { - mal_atomic_exchange_32(&pDevice->null_device.operation, operation); - if (!mal_event_signal(&pDevice->null_device.operationEvent)) { + ma_atomic_exchange_32(&pDevice->null_device.operation, operation); + if (!ma_event_signal(&pDevice->null_device.operationEvent)) { return MA_ERROR; } - if (!mal_event_wait(&pDevice->null_device.operationCompletionEvent)) { + if (!ma_event_wait(&pDevice->null_device.operationCompletionEvent)) { return MA_ERROR; } return pDevice->null_device.operationResult; } -mal_uint64 mal_device_get_total_run_time_in_frames__null(mal_device* pDevice) +ma_uint64 ma_device_get_total_run_time_in_frames__null(ma_device* pDevice) { - mal_uint32 internalSampleRate; - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { + ma_uint32 internalSampleRate; + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { internalSampleRate = pDevice->capture.internalSampleRate; } else { internalSampleRate = pDevice->playback.internalSampleRate; } - return (mal_uint64)((pDevice->null_device.priorRunTime + mal_timer_get_time_in_seconds(&pDevice->null_device.timer)) * internalSampleRate); + return (ma_uint64)((pDevice->null_device.priorRunTime + ma_timer_get_time_in_seconds(&pDevice->null_device.timer)) * internalSampleRate); } -mal_bool32 mal_context_is_device_id_equal__null(mal_context* pContext, const mal_device_id* pID0, const mal_device_id* pID1) +ma_bool32 ma_context_is_device_id_equal__null(ma_context* pContext, const ma_device_id* pID0, const ma_device_id* pID1) { - mal_assert(pContext != NULL); - mal_assert(pID0 != NULL); - mal_assert(pID1 != NULL); + ma_assert(pContext != NULL); + ma_assert(pID0 != NULL); + ma_assert(pID1 != NULL); (void)pContext; return pID0->nullbackend == pID1->nullbackend; } -mal_result mal_context_enumerate_devices__null(mal_context* pContext, mal_enum_devices_callback_proc callback, void* pUserData) +ma_result ma_context_enumerate_devices__null(ma_context* pContext, ma_enum_devices_callback_proc callback, void* pUserData) { - mal_assert(pContext != NULL); - mal_assert(callback != NULL); + ma_assert(pContext != NULL); + ma_assert(callback != NULL); - mal_bool32 cbResult = MA_TRUE; + ma_bool32 cbResult = MA_TRUE; // Playback. if (cbResult) { - mal_device_info deviceInfo; - mal_zero_object(&deviceInfo); - mal_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), "NULL Playback Device", (size_t)-1); - cbResult = callback(pContext, mal_device_type_playback, &deviceInfo, pUserData); + ma_device_info deviceInfo; + ma_zero_object(&deviceInfo); + ma_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), "NULL Playback Device", (size_t)-1); + cbResult = callback(pContext, ma_device_type_playback, &deviceInfo, pUserData); } // Capture. if (cbResult) { - mal_device_info deviceInfo; - mal_zero_object(&deviceInfo); - mal_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), "NULL Capture Device", (size_t)-1); - cbResult = callback(pContext, mal_device_type_capture, &deviceInfo, pUserData); + ma_device_info deviceInfo; + ma_zero_object(&deviceInfo); + ma_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), "NULL Capture Device", (size_t)-1); + cbResult = callback(pContext, ma_device_type_capture, &deviceInfo, pUserData); } return MA_SUCCESS; } -mal_result mal_context_get_device_info__null(mal_context* pContext, mal_device_type deviceType, const mal_device_id* pDeviceID, mal_share_mode shareMode, mal_device_info* pDeviceInfo) +ma_result ma_context_get_device_info__null(ma_context* pContext, ma_device_type deviceType, const ma_device_id* pDeviceID, ma_share_mode shareMode, ma_device_info* pDeviceInfo) { - mal_assert(pContext != NULL); + ma_assert(pContext != NULL); (void)pContext; (void)shareMode; @@ -5307,16 +5307,16 @@ mal_result mal_context_get_device_info__null(mal_context* pContext, mal_device_t } // Name / Description - if (deviceType == mal_device_type_playback) { - mal_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), "NULL Playback Device", (size_t)-1); + if (deviceType == ma_device_type_playback) { + ma_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), "NULL Playback Device", (size_t)-1); } else { - mal_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), "NULL Capture Device", (size_t)-1); + ma_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), "NULL Capture Device", (size_t)-1); } // Support everything on the null backend. - pDeviceInfo->formatCount = mal_format_count - 1; // Minus one because we don't want to include mal_format_unknown. - for (mal_uint32 iFormat = 0; iFormat < pDeviceInfo->formatCount; ++iFormat) { - pDeviceInfo->formats[iFormat] = (mal_format)(iFormat + 1); // +1 to skip over mal_format_unknown. + pDeviceInfo->formatCount = ma_format_count - 1; // Minus one because we don't want to include ma_format_unknown. + for (ma_uint32 iFormat = 0; iFormat < pDeviceInfo->formatCount; ++iFormat) { + pDeviceInfo->formats[iFormat] = (ma_format)(iFormat + 1); // +1 to skip over ma_format_unknown. } pDeviceInfo->minChannels = 1; @@ -5328,66 +5328,66 @@ mal_result mal_context_get_device_info__null(mal_context* pContext, mal_device_t } -void mal_device_uninit__null(mal_device* pDevice) +void ma_device_uninit__null(ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); /* Keep it clean and wait for the device thread to finish before returning. */ - mal_device_do_operation__null(pDevice, MA_DEVICE_OP_KILL__NULL); + ma_device_do_operation__null(pDevice, MA_DEVICE_OP_KILL__NULL); /* At this point the loop in the device thread is as good as terminated so we can uninitialize our events. */ - mal_event_uninit(&pDevice->null_device.operationCompletionEvent); - mal_event_uninit(&pDevice->null_device.operationEvent); + ma_event_uninit(&pDevice->null_device.operationCompletionEvent); + ma_event_uninit(&pDevice->null_device.operationEvent); } -mal_result mal_device_init__null(mal_context* pContext, const mal_device_config* pConfig, mal_device* pDevice) +ma_result ma_device_init__null(ma_context* pContext, const ma_device_config* pConfig, ma_device* pDevice) { (void)pContext; (void)pConfig; - mal_result result; + ma_result result; - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); - mal_zero_object(&pDevice->null_device); + ma_zero_object(&pDevice->null_device); - mal_uint32 bufferSizeInFrames = pConfig->bufferSizeInFrames; + ma_uint32 bufferSizeInFrames = pConfig->bufferSizeInFrames; if (bufferSizeInFrames == 0) { - bufferSizeInFrames = mal_calculate_buffer_size_in_frames_from_milliseconds(pConfig->bufferSizeInMilliseconds, pConfig->sampleRate); + bufferSizeInFrames = ma_calculate_buffer_size_in_frames_from_milliseconds(pConfig->bufferSizeInMilliseconds, pConfig->sampleRate); } - if (pConfig->deviceType == mal_device_type_capture || pConfig->deviceType == mal_device_type_duplex) { - mal_strncpy_s(pDevice->capture.name, sizeof(pDevice->capture.name), "NULL Capture Device", (size_t)-1); + if (pConfig->deviceType == ma_device_type_capture || pConfig->deviceType == ma_device_type_duplex) { + ma_strncpy_s(pDevice->capture.name, sizeof(pDevice->capture.name), "NULL Capture Device", (size_t)-1); pDevice->capture.internalFormat = pConfig->capture.format; pDevice->capture.internalChannels = pConfig->capture.channels; - mal_channel_map_copy(pDevice->capture.internalChannelMap, pConfig->capture.channelMap, pConfig->capture.channels); + ma_channel_map_copy(pDevice->capture.internalChannelMap, pConfig->capture.channelMap, pConfig->capture.channels); pDevice->capture.internalBufferSizeInFrames = bufferSizeInFrames; pDevice->capture.internalPeriods = pConfig->periods; } - if (pConfig->deviceType == mal_device_type_playback || pConfig->deviceType == mal_device_type_duplex) { - mal_strncpy_s(pDevice->playback.name, sizeof(pDevice->playback.name), "NULL Playback Device", (size_t)-1); + if (pConfig->deviceType == ma_device_type_playback || pConfig->deviceType == ma_device_type_duplex) { + ma_strncpy_s(pDevice->playback.name, sizeof(pDevice->playback.name), "NULL Playback Device", (size_t)-1); pDevice->playback.internalFormat = pConfig->playback.format; pDevice->playback.internalChannels = pConfig->playback.channels; - mal_channel_map_copy(pDevice->playback.internalChannelMap, pConfig->playback.channelMap, pConfig->playback.channels); + ma_channel_map_copy(pDevice->playback.internalChannelMap, pConfig->playback.channelMap, pConfig->playback.channels); pDevice->playback.internalBufferSizeInFrames = bufferSizeInFrames; pDevice->playback.internalPeriods = pConfig->periods; } /* In order to get timing right, we need to create a thread that does nothing but keeps track of the timer. This timer is started when the - first period is "written" to it, and then stopped in mal_device_stop__null(). + first period is "written" to it, and then stopped in ma_device_stop__null(). */ - result = mal_event_init(pContext, &pDevice->null_device.operationEvent); + result = ma_event_init(pContext, &pDevice->null_device.operationEvent); if (result != MA_SUCCESS) { return result; } - result = mal_event_init(pContext, &pDevice->null_device.operationCompletionEvent); + result = ma_event_init(pContext, &pDevice->null_device.operationCompletionEvent); if (result != MA_SUCCESS) { return result; } - result = mal_thread_create(pContext, &pDevice->thread, mal_device_thread__null, pDevice); + result = ma_thread_create(pContext, &pDevice->thread, ma_device_thread__null, pDevice); if (result != MA_SUCCESS) { return result; } @@ -5395,31 +5395,31 @@ mal_result mal_device_init__null(mal_context* pContext, const mal_device_config* return MA_SUCCESS; } -mal_result mal_device_start__null(mal_device* pDevice) +ma_result ma_device_start__null(ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); - mal_device_do_operation__null(pDevice, MA_DEVICE_OP_START__NULL); + ma_device_do_operation__null(pDevice, MA_DEVICE_OP_START__NULL); - mal_atomic_exchange_32(&pDevice->null_device.isStarted, MA_TRUE); + ma_atomic_exchange_32(&pDevice->null_device.isStarted, MA_TRUE); return MA_SUCCESS; } -mal_result mal_device_stop__null(mal_device* pDevice) +ma_result ma_device_stop__null(ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); - mal_device_do_operation__null(pDevice, MA_DEVICE_OP_SUSPEND__NULL); + ma_device_do_operation__null(pDevice, MA_DEVICE_OP_SUSPEND__NULL); - mal_atomic_exchange_32(&pDevice->null_device.isStarted, MA_FALSE); + ma_atomic_exchange_32(&pDevice->null_device.isStarted, MA_FALSE); return MA_SUCCESS; } -mal_result mal_device_write__null(mal_device* pDevice, const void* pPCMFrames, mal_uint32 frameCount) +ma_result ma_device_write__null(ma_device* pDevice, const void* pPCMFrames, ma_uint32 frameCount) { - mal_result result = MA_SUCCESS; - mal_uint32 totalPCMFramesProcessed; - mal_bool32 wasStartedOnEntry; + ma_result result = MA_SUCCESS; + ma_uint32 totalPCMFramesProcessed; + ma_bool32 wasStartedOnEntry; wasStartedOnEntry = pDevice->null_device.isStarted; @@ -5428,8 +5428,8 @@ mal_result mal_device_write__null(mal_device* pDevice, const void* pPCMFrames, m while (totalPCMFramesProcessed < frameCount) { /* If there are any frames remaining in the current period, consume those first. */ if (pDevice->null_device.currentPeriodFramesRemainingPlayback > 0) { - mal_uint32 framesRemaining = (frameCount - totalPCMFramesProcessed); - mal_uint32 framesToProcess = pDevice->null_device.currentPeriodFramesRemainingPlayback; + ma_uint32 framesRemaining = (frameCount - totalPCMFramesProcessed); + ma_uint32 framesToProcess = pDevice->null_device.currentPeriodFramesRemainingPlayback; if (framesToProcess > framesRemaining) { framesToProcess = framesRemaining; } @@ -5446,7 +5446,7 @@ mal_result mal_device_write__null(mal_device* pDevice, const void* pPCMFrames, m pDevice->null_device.currentPeriodFramesRemainingPlayback = 0; if (!pDevice->null_device.isStarted && !wasStartedOnEntry) { - result = mal_device_start__null(pDevice); + result = ma_device_start__null(pDevice); if (result != MA_SUCCESS) { break; } @@ -5454,26 +5454,26 @@ mal_result mal_device_write__null(mal_device* pDevice, const void* pPCMFrames, m } /* If we've consumed the whole buffer we can return now. */ - mal_assert(totalPCMFramesProcessed <= frameCount); + ma_assert(totalPCMFramesProcessed <= frameCount); if (totalPCMFramesProcessed == frameCount) { break; } /* Getting here means we've still got more frames to consume, we but need to wait for it to become available. */ - mal_uint64 targetFrame = pDevice->null_device.lastProcessedFramePlayback; + ma_uint64 targetFrame = pDevice->null_device.lastProcessedFramePlayback; for (;;) { /* Stop waiting if the device has been stopped. */ if (!pDevice->null_device.isStarted) { break; } - mal_uint64 currentFrame = mal_device_get_total_run_time_in_frames__null(pDevice); + ma_uint64 currentFrame = ma_device_get_total_run_time_in_frames__null(pDevice); if (currentFrame >= targetFrame) { break; } /* Getting here means we haven't yet reached the target sample, so continue waiting. */ - mal_sleep(10); + ma_sleep(10); } pDevice->null_device.lastProcessedFramePlayback += pDevice->playback.internalBufferSizeInFrames / pDevice->playback.internalPeriods; @@ -5483,14 +5483,14 @@ mal_result mal_device_write__null(mal_device* pDevice, const void* pPCMFrames, m return result; } -mal_result mal_device_read__null(mal_device* pDevice, void* pPCMFrames, mal_uint32 frameCount) +ma_result ma_device_read__null(ma_device* pDevice, void* pPCMFrames, ma_uint32 frameCount) { - mal_result result = MA_SUCCESS; - mal_uint32 totalPCMFramesProcessed; + ma_result result = MA_SUCCESS; + ma_uint32 totalPCMFramesProcessed; /* The device needs to be started immediately. */ if (!pDevice->null_device.isStarted) { - result = mal_device_start__null(pDevice); + result = ma_device_start__null(pDevice); if (result != MA_SUCCESS) { return result; } @@ -5501,15 +5501,15 @@ mal_result mal_device_read__null(mal_device* pDevice, void* pPCMFrames, mal_uint while (totalPCMFramesProcessed < frameCount) { /* If there are any frames remaining in the current period, consume those first. */ if (pDevice->null_device.currentPeriodFramesRemainingCapture > 0) { - mal_uint32 bpf = mal_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels); - mal_uint32 framesRemaining = (frameCount - totalPCMFramesProcessed); - mal_uint32 framesToProcess = pDevice->null_device.currentPeriodFramesRemainingCapture; + ma_uint32 bpf = ma_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels); + ma_uint32 framesRemaining = (frameCount - totalPCMFramesProcessed); + ma_uint32 framesToProcess = pDevice->null_device.currentPeriodFramesRemainingCapture; if (framesToProcess > framesRemaining) { framesToProcess = framesRemaining; } /* We need to ensured the output buffer is zeroed. */ - mal_zero_memory(mal_offset_ptr(pPCMFrames, totalPCMFramesProcessed*bpf), framesToProcess*bpf); + ma_zero_memory(ma_offset_ptr(pPCMFrames, totalPCMFramesProcessed*bpf), framesToProcess*bpf); pDevice->null_device.currentPeriodFramesRemainingCapture -= framesToProcess; totalPCMFramesProcessed += framesToProcess; @@ -5521,26 +5521,26 @@ mal_result mal_device_read__null(mal_device* pDevice, void* pPCMFrames, mal_uint } /* If we've consumed the whole buffer we can return now. */ - mal_assert(totalPCMFramesProcessed <= frameCount); + ma_assert(totalPCMFramesProcessed <= frameCount); if (totalPCMFramesProcessed == frameCount) { break; } /* Getting here means we've still got more frames to consume, we but need to wait for it to become available. */ - mal_uint64 targetFrame = pDevice->null_device.lastProcessedFrameCapture + (pDevice->capture.internalBufferSizeInFrames / pDevice->capture.internalPeriods); + ma_uint64 targetFrame = pDevice->null_device.lastProcessedFrameCapture + (pDevice->capture.internalBufferSizeInFrames / pDevice->capture.internalPeriods); for (;;) { /* Stop waiting if the device has been stopped. */ if (!pDevice->null_device.isStarted) { break; } - mal_uint64 currentFrame = mal_device_get_total_run_time_in_frames__null(pDevice); + ma_uint64 currentFrame = ma_device_get_total_run_time_in_frames__null(pDevice); if (currentFrame >= targetFrame) { break; } /* Getting here means we haven't yet reached the target sample, so continue waiting. */ - mal_sleep(10); + ma_sleep(10); } pDevice->null_device.lastProcessedFrameCapture += pDevice->capture.internalBufferSizeInFrames / pDevice->capture.internalPeriods; @@ -5550,29 +5550,29 @@ mal_result mal_device_read__null(mal_device* pDevice, void* pPCMFrames, mal_uint return result; } -mal_result mal_context_uninit__null(mal_context* pContext) +ma_result ma_context_uninit__null(ma_context* pContext) { - mal_assert(pContext != NULL); - mal_assert(pContext->backend == mal_backend_null); + ma_assert(pContext != NULL); + ma_assert(pContext->backend == ma_backend_null); (void)pContext; return MA_SUCCESS; } -mal_result mal_context_init__null(mal_context* pContext) +ma_result ma_context_init__null(ma_context* pContext) { - mal_assert(pContext != NULL); + ma_assert(pContext != NULL); - pContext->onUninit = mal_context_uninit__null; - pContext->onDeviceIDEqual = mal_context_is_device_id_equal__null; - pContext->onEnumDevices = mal_context_enumerate_devices__null; - pContext->onGetDeviceInfo = mal_context_get_device_info__null; - pContext->onDeviceInit = mal_device_init__null; - pContext->onDeviceUninit = mal_device_uninit__null; - pContext->onDeviceStart = mal_device_start__null; - pContext->onDeviceStop = mal_device_stop__null; - pContext->onDeviceWrite = mal_device_write__null; - pContext->onDeviceRead = mal_device_read__null; + pContext->onUninit = ma_context_uninit__null; + pContext->onDeviceIDEqual = ma_context_is_device_id_equal__null; + pContext->onEnumDevices = ma_context_enumerate_devices__null; + pContext->onGetDeviceInfo = ma_context_get_device_info__null; + pContext->onDeviceInit = ma_device_init__null; + pContext->onDeviceUninit = ma_device_uninit__null; + pContext->onDeviceStart = ma_device_start__null; + pContext->onDeviceStop = ma_device_stop__null; + pContext->onDeviceWrite = ma_device_write__null; + pContext->onDeviceRead = ma_device_read__null; /* The null backend always works. */ return MA_SUCCESS; @@ -5587,17 +5587,17 @@ mal_result mal_context_init__null(mal_context* pContext) /////////////////////////////////////////////////////////////////////////////// #if defined(MA_WIN32) #if defined(MA_WIN32_DESKTOP) - #define mal_CoInitializeEx(pContext, pvReserved, dwCoInit) ((MA_PFN_CoInitializeEx)pContext->win32.CoInitializeEx)(pvReserved, dwCoInit) - #define mal_CoUninitialize(pContext) ((MA_PFN_CoUninitialize)pContext->win32.CoUninitialize)() - #define mal_CoCreateInstance(pContext, rclsid, pUnkOuter, dwClsContext, riid, ppv) ((MA_PFN_CoCreateInstance)pContext->win32.CoCreateInstance)(rclsid, pUnkOuter, dwClsContext, riid, ppv) - #define mal_CoTaskMemFree(pContext, pv) ((MA_PFN_CoTaskMemFree)pContext->win32.CoTaskMemFree)(pv) - #define mal_PropVariantClear(pContext, pvar) ((MA_PFN_PropVariantClear)pContext->win32.PropVariantClear)(pvar) + #define ma_CoInitializeEx(pContext, pvReserved, dwCoInit) ((MA_PFN_CoInitializeEx)pContext->win32.CoInitializeEx)(pvReserved, dwCoInit) + #define ma_CoUninitialize(pContext) ((MA_PFN_CoUninitialize)pContext->win32.CoUninitialize)() + #define ma_CoCreateInstance(pContext, rclsid, pUnkOuter, dwClsContext, riid, ppv) ((MA_PFN_CoCreateInstance)pContext->win32.CoCreateInstance)(rclsid, pUnkOuter, dwClsContext, riid, ppv) + #define ma_CoTaskMemFree(pContext, pv) ((MA_PFN_CoTaskMemFree)pContext->win32.CoTaskMemFree)(pv) + #define ma_PropVariantClear(pContext, pvar) ((MA_PFN_PropVariantClear)pContext->win32.PropVariantClear)(pvar) #else - #define mal_CoInitializeEx(pContext, pvReserved, dwCoInit) CoInitializeEx(pvReserved, dwCoInit) - #define mal_CoUninitialize(pContext) CoUninitialize() - #define mal_CoCreateInstance(pContext, rclsid, pUnkOuter, dwClsContext, riid, ppv) CoCreateInstance(rclsid, pUnkOuter, dwClsContext, riid, ppv) - #define mal_CoTaskMemFree(pContext, pv) CoTaskMemFree(pv) - #define mal_PropVariantClear(pContext, pvar) PropVariantClear(pvar) + #define ma_CoInitializeEx(pContext, pvReserved, dwCoInit) CoInitializeEx(pvReserved, dwCoInit) + #define ma_CoUninitialize(pContext) CoUninitialize() + #define ma_CoCreateInstance(pContext, rclsid, pUnkOuter, dwClsContext, riid, ppv) CoCreateInstance(rclsid, pUnkOuter, dwClsContext, riid, ppv) + #define ma_CoTaskMemFree(pContext, pv) CoTaskMemFree(pv) + #define ma_PropVariantClear(pContext, pvar) PropVariantClear(pvar) #endif #if !defined(MAXULONG_PTR) @@ -5668,7 +5668,7 @@ typedef struct GUID MA_GUID_NULL = {0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; // Converts an individual Win32-style channel identifier (SPEAKER_FRONT_LEFT, etc.) to miniaudio. -mal_uint8 mal_channel_id_to_mal__win32(DWORD id) +ma_uint8 ma_channel_id_to_ma__win32(DWORD id) { switch (id) { @@ -5695,7 +5695,7 @@ mal_uint8 mal_channel_id_to_mal__win32(DWORD id) } // Converts an individual miniaudio channel identifier (MA_CHANNEL_FRONT_LEFT, etc.) to Win32-style. -DWORD mal_channel_id_to_win32(DWORD id) +DWORD ma_channel_id_to_win32(DWORD id) { switch (id) { @@ -5723,18 +5723,18 @@ DWORD mal_channel_id_to_win32(DWORD id) } // Converts a channel mapping to a Win32-style channel mask. -DWORD mal_channel_map_to_channel_mask__win32(const mal_channel channelMap[MA_MAX_CHANNELS], mal_uint32 channels) +DWORD ma_channel_map_to_channel_mask__win32(const ma_channel channelMap[MA_MAX_CHANNELS], ma_uint32 channels) { DWORD dwChannelMask = 0; - for (mal_uint32 iChannel = 0; iChannel < channels; ++iChannel) { - dwChannelMask |= mal_channel_id_to_win32(channelMap[iChannel]); + for (ma_uint32 iChannel = 0; iChannel < channels; ++iChannel) { + dwChannelMask |= ma_channel_id_to_win32(channelMap[iChannel]); } return dwChannelMask; } // Converts a Win32-style channel mask to a miniaudio channel map. -void mal_channel_mask_to_channel_map__win32(DWORD dwChannelMask, mal_uint32 channels, mal_channel channelMap[MA_MAX_CHANNELS]) +void ma_channel_mask_to_channel_map__win32(DWORD dwChannelMask, ma_uint32 channels, ma_channel channelMap[MA_MAX_CHANNELS]) { if (channels == 1 && dwChannelMask == 0) { channelMap[0] = MA_CHANNEL_MONO; @@ -5746,12 +5746,12 @@ void mal_channel_mask_to_channel_map__win32(DWORD dwChannelMask, mal_uint32 chan channelMap[0] = MA_CHANNEL_MONO; } else { // Just iterate over each bit. - mal_uint32 iChannel = 0; - for (mal_uint32 iBit = 0; iBit < 32; ++iBit) { + ma_uint32 iChannel = 0; + for (ma_uint32 iBit = 0; iBit < 32; ++iBit) { DWORD bitValue = (dwChannelMask & (1UL << iBit)); if (bitValue != 0) { // The bit is set. - channelMap[iChannel] = mal_channel_id_to_mal__win32(bitValue); + channelMap[iChannel] = ma_channel_id_to_ma__win32(bitValue); iChannel += 1; } } @@ -5760,73 +5760,73 @@ void mal_channel_mask_to_channel_map__win32(DWORD dwChannelMask, mal_uint32 chan } #ifdef __cplusplus -mal_bool32 mal_is_guid_equal(const void* a, const void* b) +ma_bool32 ma_is_guid_equal(const void* a, const void* b) { return IsEqualGUID(*(const GUID*)a, *(const GUID*)b); } #else -#define mal_is_guid_equal(a, b) IsEqualGUID((const GUID*)a, (const GUID*)b) +#define ma_is_guid_equal(a, b) IsEqualGUID((const GUID*)a, (const GUID*)b) #endif -mal_format mal_format_from_WAVEFORMATEX(const WAVEFORMATEX* pWF) +ma_format ma_format_from_WAVEFORMATEX(const WAVEFORMATEX* pWF) { - mal_assert(pWF != NULL); + ma_assert(pWF != NULL); if (pWF->wFormatTag == WAVE_FORMAT_EXTENSIBLE) { const WAVEFORMATEXTENSIBLE* pWFEX = (const WAVEFORMATEXTENSIBLE*)pWF; - if (mal_is_guid_equal(&pWFEX->SubFormat, &MA_GUID_KSDATAFORMAT_SUBTYPE_PCM)) { + if (ma_is_guid_equal(&pWFEX->SubFormat, &MA_GUID_KSDATAFORMAT_SUBTYPE_PCM)) { if (pWFEX->Samples.wValidBitsPerSample == 32) { - return mal_format_s32; + return ma_format_s32; } if (pWFEX->Samples.wValidBitsPerSample == 24) { if (pWFEX->Format.wBitsPerSample == 32) { - //return mal_format_s24_32; + //return ma_format_s24_32; } if (pWFEX->Format.wBitsPerSample == 24) { - return mal_format_s24; + return ma_format_s24; } } if (pWFEX->Samples.wValidBitsPerSample == 16) { - return mal_format_s16; + return ma_format_s16; } if (pWFEX->Samples.wValidBitsPerSample == 8) { - return mal_format_u8; + return ma_format_u8; } } - if (mal_is_guid_equal(&pWFEX->SubFormat, &MA_GUID_KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)) { + if (ma_is_guid_equal(&pWFEX->SubFormat, &MA_GUID_KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)) { if (pWFEX->Samples.wValidBitsPerSample == 32) { - return mal_format_f32; + return ma_format_f32; } //if (pWFEX->Samples.wValidBitsPerSample == 64) { - // return mal_format_f64; + // return ma_format_f64; //} } } else { if (pWF->wFormatTag == WAVE_FORMAT_PCM) { if (pWF->wBitsPerSample == 32) { - return mal_format_s32; + return ma_format_s32; } if (pWF->wBitsPerSample == 24) { - return mal_format_s24; + return ma_format_s24; } if (pWF->wBitsPerSample == 16) { - return mal_format_s16; + return ma_format_s16; } if (pWF->wBitsPerSample == 8) { - return mal_format_u8; + return ma_format_u8; } } if (pWF->wFormatTag == WAVE_FORMAT_IEEE_FLOAT) { if (pWF->wBitsPerSample == 32) { - return mal_format_f32; + return ma_format_f32; } if (pWF->wBitsPerSample == 64) { - //return mal_format_f64; + //return ma_format_f64; } } } - return mal_format_unknown; + return ma_format_unknown; } #endif @@ -5868,12 +5868,12 @@ typedef struct { WORD wSuiteMask; BYTE wProductType; BYTE wReserved; -} mal_OSVERSIONINFOEXW; +} ma_OSVERSIONINFOEXW; -BOOL WINAPI VerifyVersionInfoW(mal_OSVERSIONINFOEXW* lpVersionInfo, DWORD dwTypeMask, DWORDLONG dwlConditionMask); +BOOL WINAPI VerifyVersionInfoW(ma_OSVERSIONINFOEXW* lpVersionInfo, DWORD dwTypeMask, DWORDLONG dwlConditionMask); ULONGLONG WINAPI VerSetConditionMask(ULONGLONG dwlConditionMask, DWORD dwTypeBitMask, BYTE dwConditionMask); #else -typedef OSVERSIONINFOEXW mal_OSVERSIONINFOEXW; +typedef OSVERSIONINFOEXW ma_OSVERSIONINFOEXW; #endif @@ -5887,9 +5887,9 @@ typedef struct #endif // Some compilers don't define PropVariantInit(). We just do this ourselves since it's just a memset(). -static MA_INLINE void mal_PropVariantInit(PROPVARIANT* pProp) +static MA_INLINE void ma_PropVariantInit(PROPVARIANT* pProp) { - mal_zero_object(pProp); + ma_zero_object(pProp); } @@ -5921,28 +5921,28 @@ const IID MA_IID_IMMDeviceEnumerator_Instance = {0xA95664D2, 0x9614, #define MA_IID_IMMDeviceEnumerator &MA_IID_IMMDeviceEnumerator_Instance #endif -typedef struct mal_IUnknown mal_IUnknown; +typedef struct ma_IUnknown ma_IUnknown; #ifdef MA_WIN32_DESKTOP #define MA_MM_DEVICE_STATE_ACTIVE 1 #define MA_MM_DEVICE_STATE_DISABLED 2 #define MA_MM_DEVICE_STATE_NOTPRESENT 4 #define MA_MM_DEVICE_STATE_UNPLUGGED 8 -typedef struct mal_IMMDeviceEnumerator mal_IMMDeviceEnumerator; -typedef struct mal_IMMDeviceCollection mal_IMMDeviceCollection; -typedef struct mal_IMMDevice mal_IMMDevice; +typedef struct ma_IMMDeviceEnumerator ma_IMMDeviceEnumerator; +typedef struct ma_IMMDeviceCollection ma_IMMDeviceCollection; +typedef struct ma_IMMDevice ma_IMMDevice; #else -typedef struct mal_IActivateAudioInterfaceCompletionHandler mal_IActivateAudioInterfaceCompletionHandler; -typedef struct mal_IActivateAudioInterfaceAsyncOperation mal_IActivateAudioInterfaceAsyncOperation; +typedef struct ma_IActivateAudioInterfaceCompletionHandler ma_IActivateAudioInterfaceCompletionHandler; +typedef struct ma_IActivateAudioInterfaceAsyncOperation ma_IActivateAudioInterfaceAsyncOperation; #endif -typedef struct mal_IPropertyStore mal_IPropertyStore; -typedef struct mal_IAudioClient mal_IAudioClient; -typedef struct mal_IAudioClient2 mal_IAudioClient2; -typedef struct mal_IAudioClient3 mal_IAudioClient3; -typedef struct mal_IAudioRenderClient mal_IAudioRenderClient; -typedef struct mal_IAudioCaptureClient mal_IAudioCaptureClient; +typedef struct ma_IPropertyStore ma_IPropertyStore; +typedef struct ma_IAudioClient ma_IAudioClient; +typedef struct ma_IAudioClient2 ma_IAudioClient2; +typedef struct ma_IAudioClient3 ma_IAudioClient3; +typedef struct ma_IAudioRenderClient ma_IAudioRenderClient; +typedef struct ma_IAudioCaptureClient ma_IAudioCaptureClient; -typedef mal_int64 MA_REFERENCE_TIME; +typedef ma_int64 MA_REFERENCE_TIME; #define MA_AUDCLNT_STREAMFLAGS_CROSSPROCESS 0x00010000 #define MA_AUDCLNT_STREAMFLAGS_LOOPBACK 0x00020000 @@ -5963,17 +5963,17 @@ typedef mal_int64 MA_REFERENCE_TIME; typedef enum { - mal_eRender = 0, - mal_eCapture = 1, - mal_eAll = 2 -} mal_EDataFlow; + ma_eRender = 0, + ma_eCapture = 1, + ma_eAll = 2 +} ma_EDataFlow; typedef enum { - mal_eConsole = 0, - mal_eMultimedia = 1, - mal_eCommunications = 2 -} mal_ERole; + ma_eConsole = 0, + ma_eMultimedia = 1, + ma_eCommunications = 2 +} ma_ERole; typedef enum { @@ -5991,412 +5991,412 @@ typedef struct UINT32 cbSize; BOOL bIsOffload; MA_AUDIO_STREAM_CATEGORY eCategory; -} mal_AudioClientProperties; +} ma_AudioClientProperties; // IUnknown typedef struct { // IUnknown - HRESULT (STDMETHODCALLTYPE * QueryInterface)(mal_IUnknown* pThis, const IID* const riid, void** ppObject); - ULONG (STDMETHODCALLTYPE * AddRef) (mal_IUnknown* pThis); - ULONG (STDMETHODCALLTYPE * Release) (mal_IUnknown* pThis); -} mal_IUnknownVtbl; -struct mal_IUnknown + HRESULT (STDMETHODCALLTYPE * QueryInterface)(ma_IUnknown* pThis, const IID* const riid, void** ppObject); + ULONG (STDMETHODCALLTYPE * AddRef) (ma_IUnknown* pThis); + ULONG (STDMETHODCALLTYPE * Release) (ma_IUnknown* pThis); +} ma_IUnknownVtbl; +struct ma_IUnknown { - mal_IUnknownVtbl* lpVtbl; + ma_IUnknownVtbl* lpVtbl; }; -HRESULT mal_IUnknown_QueryInterface(mal_IUnknown* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); } -ULONG mal_IUnknown_AddRef(mal_IUnknown* pThis) { return pThis->lpVtbl->AddRef(pThis); } -ULONG mal_IUnknown_Release(mal_IUnknown* pThis) { return pThis->lpVtbl->Release(pThis); } +HRESULT ma_IUnknown_QueryInterface(ma_IUnknown* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); } +ULONG ma_IUnknown_AddRef(ma_IUnknown* pThis) { return pThis->lpVtbl->AddRef(pThis); } +ULONG ma_IUnknown_Release(ma_IUnknown* pThis) { return pThis->lpVtbl->Release(pThis); } #ifdef MA_WIN32_DESKTOP // IMMNotificationClient typedef struct { // IUnknown - HRESULT (STDMETHODCALLTYPE * QueryInterface)(mal_IMMNotificationClient* pThis, const IID* const riid, void** ppObject); - ULONG (STDMETHODCALLTYPE * AddRef) (mal_IMMNotificationClient* pThis); - ULONG (STDMETHODCALLTYPE * Release) (mal_IMMNotificationClient* pThis); + HRESULT (STDMETHODCALLTYPE * QueryInterface)(ma_IMMNotificationClient* pThis, const IID* const riid, void** ppObject); + ULONG (STDMETHODCALLTYPE * AddRef) (ma_IMMNotificationClient* pThis); + ULONG (STDMETHODCALLTYPE * Release) (ma_IMMNotificationClient* pThis); // IMMNotificationClient - HRESULT (STDMETHODCALLTYPE * OnDeviceStateChanged) (mal_IMMNotificationClient* pThis, LPCWSTR pDeviceID, DWORD dwNewState); - HRESULT (STDMETHODCALLTYPE * OnDeviceAdded) (mal_IMMNotificationClient* pThis, LPCWSTR pDeviceID); - HRESULT (STDMETHODCALLTYPE * OnDeviceRemoved) (mal_IMMNotificationClient* pThis, LPCWSTR pDeviceID); - HRESULT (STDMETHODCALLTYPE * OnDefaultDeviceChanged)(mal_IMMNotificationClient* pThis, mal_EDataFlow dataFlow, mal_ERole role, LPCWSTR pDefaultDeviceID); - HRESULT (STDMETHODCALLTYPE * OnPropertyValueChanged)(mal_IMMNotificationClient* pThis, LPCWSTR pDeviceID, const PROPERTYKEY key); - } mal_IMMNotificationClientVtbl; + HRESULT (STDMETHODCALLTYPE * OnDeviceStateChanged) (ma_IMMNotificationClient* pThis, LPCWSTR pDeviceID, DWORD dwNewState); + HRESULT (STDMETHODCALLTYPE * OnDeviceAdded) (ma_IMMNotificationClient* pThis, LPCWSTR pDeviceID); + HRESULT (STDMETHODCALLTYPE * OnDeviceRemoved) (ma_IMMNotificationClient* pThis, LPCWSTR pDeviceID); + HRESULT (STDMETHODCALLTYPE * OnDefaultDeviceChanged)(ma_IMMNotificationClient* pThis, ma_EDataFlow dataFlow, ma_ERole role, LPCWSTR pDefaultDeviceID); + HRESULT (STDMETHODCALLTYPE * OnPropertyValueChanged)(ma_IMMNotificationClient* pThis, LPCWSTR pDeviceID, const PROPERTYKEY key); + } ma_IMMNotificationClientVtbl; // IMMDeviceEnumerator typedef struct { // IUnknown - HRESULT (STDMETHODCALLTYPE * QueryInterface)(mal_IMMDeviceEnumerator* pThis, const IID* const riid, void** ppObject); - ULONG (STDMETHODCALLTYPE * AddRef) (mal_IMMDeviceEnumerator* pThis); - ULONG (STDMETHODCALLTYPE * Release) (mal_IMMDeviceEnumerator* pThis); + HRESULT (STDMETHODCALLTYPE * QueryInterface)(ma_IMMDeviceEnumerator* pThis, const IID* const riid, void** ppObject); + ULONG (STDMETHODCALLTYPE * AddRef) (ma_IMMDeviceEnumerator* pThis); + ULONG (STDMETHODCALLTYPE * Release) (ma_IMMDeviceEnumerator* pThis); // IMMDeviceEnumerator - HRESULT (STDMETHODCALLTYPE * EnumAudioEndpoints) (mal_IMMDeviceEnumerator* pThis, mal_EDataFlow dataFlow, DWORD dwStateMask, mal_IMMDeviceCollection** ppDevices); - HRESULT (STDMETHODCALLTYPE * GetDefaultAudioEndpoint) (mal_IMMDeviceEnumerator* pThis, mal_EDataFlow dataFlow, mal_ERole role, mal_IMMDevice** ppEndpoint); - HRESULT (STDMETHODCALLTYPE * GetDevice) (mal_IMMDeviceEnumerator* pThis, LPCWSTR pID, mal_IMMDevice** ppDevice); - HRESULT (STDMETHODCALLTYPE * RegisterEndpointNotificationCallback) (mal_IMMDeviceEnumerator* pThis, mal_IMMNotificationClient* pClient); - HRESULT (STDMETHODCALLTYPE * UnregisterEndpointNotificationCallback)(mal_IMMDeviceEnumerator* pThis, mal_IMMNotificationClient* pClient); - } mal_IMMDeviceEnumeratorVtbl; - struct mal_IMMDeviceEnumerator + HRESULT (STDMETHODCALLTYPE * EnumAudioEndpoints) (ma_IMMDeviceEnumerator* pThis, ma_EDataFlow dataFlow, DWORD dwStateMask, ma_IMMDeviceCollection** ppDevices); + HRESULT (STDMETHODCALLTYPE * GetDefaultAudioEndpoint) (ma_IMMDeviceEnumerator* pThis, ma_EDataFlow dataFlow, ma_ERole role, ma_IMMDevice** ppEndpoint); + HRESULT (STDMETHODCALLTYPE * GetDevice) (ma_IMMDeviceEnumerator* pThis, LPCWSTR pID, ma_IMMDevice** ppDevice); + HRESULT (STDMETHODCALLTYPE * RegisterEndpointNotificationCallback) (ma_IMMDeviceEnumerator* pThis, ma_IMMNotificationClient* pClient); + HRESULT (STDMETHODCALLTYPE * UnregisterEndpointNotificationCallback)(ma_IMMDeviceEnumerator* pThis, ma_IMMNotificationClient* pClient); + } ma_IMMDeviceEnumeratorVtbl; + struct ma_IMMDeviceEnumerator { - mal_IMMDeviceEnumeratorVtbl* lpVtbl; + ma_IMMDeviceEnumeratorVtbl* lpVtbl; }; - HRESULT mal_IMMDeviceEnumerator_QueryInterface(mal_IMMDeviceEnumerator* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); } - ULONG mal_IMMDeviceEnumerator_AddRef(mal_IMMDeviceEnumerator* pThis) { return pThis->lpVtbl->AddRef(pThis); } - ULONG mal_IMMDeviceEnumerator_Release(mal_IMMDeviceEnumerator* pThis) { return pThis->lpVtbl->Release(pThis); } - HRESULT mal_IMMDeviceEnumerator_EnumAudioEndpoints(mal_IMMDeviceEnumerator* pThis, mal_EDataFlow dataFlow, DWORD dwStateMask, mal_IMMDeviceCollection** ppDevices) { return pThis->lpVtbl->EnumAudioEndpoints(pThis, dataFlow, dwStateMask, ppDevices); } - HRESULT mal_IMMDeviceEnumerator_GetDefaultAudioEndpoint(mal_IMMDeviceEnumerator* pThis, mal_EDataFlow dataFlow, mal_ERole role, mal_IMMDevice** ppEndpoint) { return pThis->lpVtbl->GetDefaultAudioEndpoint(pThis, dataFlow, role, ppEndpoint); } - HRESULT mal_IMMDeviceEnumerator_GetDevice(mal_IMMDeviceEnumerator* pThis, LPCWSTR pID, mal_IMMDevice** ppDevice) { return pThis->lpVtbl->GetDevice(pThis, pID, ppDevice); } - HRESULT mal_IMMDeviceEnumerator_RegisterEndpointNotificationCallback(mal_IMMDeviceEnumerator* pThis, mal_IMMNotificationClient* pClient) { return pThis->lpVtbl->RegisterEndpointNotificationCallback(pThis, pClient); } - HRESULT mal_IMMDeviceEnumerator_UnregisterEndpointNotificationCallback(mal_IMMDeviceEnumerator* pThis, mal_IMMNotificationClient* pClient) { return pThis->lpVtbl->UnregisterEndpointNotificationCallback(pThis, pClient); } + HRESULT ma_IMMDeviceEnumerator_QueryInterface(ma_IMMDeviceEnumerator* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); } + ULONG ma_IMMDeviceEnumerator_AddRef(ma_IMMDeviceEnumerator* pThis) { return pThis->lpVtbl->AddRef(pThis); } + ULONG ma_IMMDeviceEnumerator_Release(ma_IMMDeviceEnumerator* pThis) { return pThis->lpVtbl->Release(pThis); } + HRESULT ma_IMMDeviceEnumerator_EnumAudioEndpoints(ma_IMMDeviceEnumerator* pThis, ma_EDataFlow dataFlow, DWORD dwStateMask, ma_IMMDeviceCollection** ppDevices) { return pThis->lpVtbl->EnumAudioEndpoints(pThis, dataFlow, dwStateMask, ppDevices); } + HRESULT ma_IMMDeviceEnumerator_GetDefaultAudioEndpoint(ma_IMMDeviceEnumerator* pThis, ma_EDataFlow dataFlow, ma_ERole role, ma_IMMDevice** ppEndpoint) { return pThis->lpVtbl->GetDefaultAudioEndpoint(pThis, dataFlow, role, ppEndpoint); } + HRESULT ma_IMMDeviceEnumerator_GetDevice(ma_IMMDeviceEnumerator* pThis, LPCWSTR pID, ma_IMMDevice** ppDevice) { return pThis->lpVtbl->GetDevice(pThis, pID, ppDevice); } + HRESULT ma_IMMDeviceEnumerator_RegisterEndpointNotificationCallback(ma_IMMDeviceEnumerator* pThis, ma_IMMNotificationClient* pClient) { return pThis->lpVtbl->RegisterEndpointNotificationCallback(pThis, pClient); } + HRESULT ma_IMMDeviceEnumerator_UnregisterEndpointNotificationCallback(ma_IMMDeviceEnumerator* pThis, ma_IMMNotificationClient* pClient) { return pThis->lpVtbl->UnregisterEndpointNotificationCallback(pThis, pClient); } // IMMDeviceCollection typedef struct { // IUnknown - HRESULT (STDMETHODCALLTYPE * QueryInterface)(mal_IMMDeviceCollection* pThis, const IID* const riid, void** ppObject); - ULONG (STDMETHODCALLTYPE * AddRef) (mal_IMMDeviceCollection* pThis); - ULONG (STDMETHODCALLTYPE * Release) (mal_IMMDeviceCollection* pThis); + HRESULT (STDMETHODCALLTYPE * QueryInterface)(ma_IMMDeviceCollection* pThis, const IID* const riid, void** ppObject); + ULONG (STDMETHODCALLTYPE * AddRef) (ma_IMMDeviceCollection* pThis); + ULONG (STDMETHODCALLTYPE * Release) (ma_IMMDeviceCollection* pThis); // IMMDeviceCollection - HRESULT (STDMETHODCALLTYPE * GetCount)(mal_IMMDeviceCollection* pThis, UINT* pDevices); - HRESULT (STDMETHODCALLTYPE * Item) (mal_IMMDeviceCollection* pThis, UINT nDevice, mal_IMMDevice** ppDevice); - } mal_IMMDeviceCollectionVtbl; - struct mal_IMMDeviceCollection + HRESULT (STDMETHODCALLTYPE * GetCount)(ma_IMMDeviceCollection* pThis, UINT* pDevices); + HRESULT (STDMETHODCALLTYPE * Item) (ma_IMMDeviceCollection* pThis, UINT nDevice, ma_IMMDevice** ppDevice); + } ma_IMMDeviceCollectionVtbl; + struct ma_IMMDeviceCollection { - mal_IMMDeviceCollectionVtbl* lpVtbl; + ma_IMMDeviceCollectionVtbl* lpVtbl; }; - HRESULT mal_IMMDeviceCollection_QueryInterface(mal_IMMDeviceCollection* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); } - ULONG mal_IMMDeviceCollection_AddRef(mal_IMMDeviceCollection* pThis) { return pThis->lpVtbl->AddRef(pThis); } - ULONG mal_IMMDeviceCollection_Release(mal_IMMDeviceCollection* pThis) { return pThis->lpVtbl->Release(pThis); } - HRESULT mal_IMMDeviceCollection_GetCount(mal_IMMDeviceCollection* pThis, UINT* pDevices) { return pThis->lpVtbl->GetCount(pThis, pDevices); } - HRESULT mal_IMMDeviceCollection_Item(mal_IMMDeviceCollection* pThis, UINT nDevice, mal_IMMDevice** ppDevice) { return pThis->lpVtbl->Item(pThis, nDevice, ppDevice); } + HRESULT ma_IMMDeviceCollection_QueryInterface(ma_IMMDeviceCollection* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); } + ULONG ma_IMMDeviceCollection_AddRef(ma_IMMDeviceCollection* pThis) { return pThis->lpVtbl->AddRef(pThis); } + ULONG ma_IMMDeviceCollection_Release(ma_IMMDeviceCollection* pThis) { return pThis->lpVtbl->Release(pThis); } + HRESULT ma_IMMDeviceCollection_GetCount(ma_IMMDeviceCollection* pThis, UINT* pDevices) { return pThis->lpVtbl->GetCount(pThis, pDevices); } + HRESULT ma_IMMDeviceCollection_Item(ma_IMMDeviceCollection* pThis, UINT nDevice, ma_IMMDevice** ppDevice) { return pThis->lpVtbl->Item(pThis, nDevice, ppDevice); } // IMMDevice typedef struct { // IUnknown - HRESULT (STDMETHODCALLTYPE * QueryInterface)(mal_IMMDevice* pThis, const IID* const riid, void** ppObject); - ULONG (STDMETHODCALLTYPE * AddRef) (mal_IMMDevice* pThis); - ULONG (STDMETHODCALLTYPE * Release) (mal_IMMDevice* pThis); + HRESULT (STDMETHODCALLTYPE * QueryInterface)(ma_IMMDevice* pThis, const IID* const riid, void** ppObject); + ULONG (STDMETHODCALLTYPE * AddRef) (ma_IMMDevice* pThis); + ULONG (STDMETHODCALLTYPE * Release) (ma_IMMDevice* pThis); // IMMDevice - HRESULT (STDMETHODCALLTYPE * Activate) (mal_IMMDevice* pThis, const IID* const iid, DWORD dwClsCtx, PROPVARIANT* pActivationParams, void** ppInterface); - HRESULT (STDMETHODCALLTYPE * OpenPropertyStore)(mal_IMMDevice* pThis, DWORD stgmAccess, mal_IPropertyStore** ppProperties); - HRESULT (STDMETHODCALLTYPE * GetId) (mal_IMMDevice* pThis, LPWSTR *pID); - HRESULT (STDMETHODCALLTYPE * GetState) (mal_IMMDevice* pThis, DWORD *pState); - } mal_IMMDeviceVtbl; - struct mal_IMMDevice + HRESULT (STDMETHODCALLTYPE * Activate) (ma_IMMDevice* pThis, const IID* const iid, DWORD dwClsCtx, PROPVARIANT* pActivationParams, void** ppInterface); + HRESULT (STDMETHODCALLTYPE * OpenPropertyStore)(ma_IMMDevice* pThis, DWORD stgmAccess, ma_IPropertyStore** ppProperties); + HRESULT (STDMETHODCALLTYPE * GetId) (ma_IMMDevice* pThis, LPWSTR *pID); + HRESULT (STDMETHODCALLTYPE * GetState) (ma_IMMDevice* pThis, DWORD *pState); + } ma_IMMDeviceVtbl; + struct ma_IMMDevice { - mal_IMMDeviceVtbl* lpVtbl; + ma_IMMDeviceVtbl* lpVtbl; }; - HRESULT mal_IMMDevice_QueryInterface(mal_IMMDevice* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); } - ULONG mal_IMMDevice_AddRef(mal_IMMDevice* pThis) { return pThis->lpVtbl->AddRef(pThis); } - ULONG mal_IMMDevice_Release(mal_IMMDevice* pThis) { return pThis->lpVtbl->Release(pThis); } - HRESULT mal_IMMDevice_Activate(mal_IMMDevice* pThis, const IID* const iid, DWORD dwClsCtx, PROPVARIANT* pActivationParams, void** ppInterface) { return pThis->lpVtbl->Activate(pThis, iid, dwClsCtx, pActivationParams, ppInterface); } - HRESULT mal_IMMDevice_OpenPropertyStore(mal_IMMDevice* pThis, DWORD stgmAccess, mal_IPropertyStore** ppProperties) { return pThis->lpVtbl->OpenPropertyStore(pThis, stgmAccess, ppProperties); } - HRESULT mal_IMMDevice_GetId(mal_IMMDevice* pThis, LPWSTR *pID) { return pThis->lpVtbl->GetId(pThis, pID); } - HRESULT mal_IMMDevice_GetState(mal_IMMDevice* pThis, DWORD *pState) { return pThis->lpVtbl->GetState(pThis, pState); } + HRESULT ma_IMMDevice_QueryInterface(ma_IMMDevice* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); } + ULONG ma_IMMDevice_AddRef(ma_IMMDevice* pThis) { return pThis->lpVtbl->AddRef(pThis); } + ULONG ma_IMMDevice_Release(ma_IMMDevice* pThis) { return pThis->lpVtbl->Release(pThis); } + HRESULT ma_IMMDevice_Activate(ma_IMMDevice* pThis, const IID* const iid, DWORD dwClsCtx, PROPVARIANT* pActivationParams, void** ppInterface) { return pThis->lpVtbl->Activate(pThis, iid, dwClsCtx, pActivationParams, ppInterface); } + HRESULT ma_IMMDevice_OpenPropertyStore(ma_IMMDevice* pThis, DWORD stgmAccess, ma_IPropertyStore** ppProperties) { return pThis->lpVtbl->OpenPropertyStore(pThis, stgmAccess, ppProperties); } + HRESULT ma_IMMDevice_GetId(ma_IMMDevice* pThis, LPWSTR *pID) { return pThis->lpVtbl->GetId(pThis, pID); } + HRESULT ma_IMMDevice_GetState(ma_IMMDevice* pThis, DWORD *pState) { return pThis->lpVtbl->GetState(pThis, pState); } #else // IActivateAudioInterfaceAsyncOperation typedef struct { // IUnknown - HRESULT (STDMETHODCALLTYPE * QueryInterface)(mal_IActivateAudioInterfaceAsyncOperation* pThis, const IID* const riid, void** ppObject); - ULONG (STDMETHODCALLTYPE * AddRef) (mal_IActivateAudioInterfaceAsyncOperation* pThis); - ULONG (STDMETHODCALLTYPE * Release) (mal_IActivateAudioInterfaceAsyncOperation* pThis); + HRESULT (STDMETHODCALLTYPE * QueryInterface)(ma_IActivateAudioInterfaceAsyncOperation* pThis, const IID* const riid, void** ppObject); + ULONG (STDMETHODCALLTYPE * AddRef) (ma_IActivateAudioInterfaceAsyncOperation* pThis); + ULONG (STDMETHODCALLTYPE * Release) (ma_IActivateAudioInterfaceAsyncOperation* pThis); // IActivateAudioInterfaceAsyncOperation - HRESULT (STDMETHODCALLTYPE * GetActivateResult)(mal_IActivateAudioInterfaceAsyncOperation* pThis, HRESULT *pActivateResult, mal_IUnknown** ppActivatedInterface); - } mal_IActivateAudioInterfaceAsyncOperationVtbl; - struct mal_IActivateAudioInterfaceAsyncOperation + HRESULT (STDMETHODCALLTYPE * GetActivateResult)(ma_IActivateAudioInterfaceAsyncOperation* pThis, HRESULT *pActivateResult, ma_IUnknown** ppActivatedInterface); + } ma_IActivateAudioInterfaceAsyncOperationVtbl; + struct ma_IActivateAudioInterfaceAsyncOperation { - mal_IActivateAudioInterfaceAsyncOperationVtbl* lpVtbl; + ma_IActivateAudioInterfaceAsyncOperationVtbl* lpVtbl; }; - HRESULT mal_IActivateAudioInterfaceAsyncOperation_QueryInterface(mal_IActivateAudioInterfaceAsyncOperation* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); } - ULONG mal_IActivateAudioInterfaceAsyncOperation_AddRef(mal_IActivateAudioInterfaceAsyncOperation* pThis) { return pThis->lpVtbl->AddRef(pThis); } - ULONG mal_IActivateAudioInterfaceAsyncOperation_Release(mal_IActivateAudioInterfaceAsyncOperation* pThis) { return pThis->lpVtbl->Release(pThis); } - HRESULT mal_IActivateAudioInterfaceAsyncOperation_GetActivateResult(mal_IActivateAudioInterfaceAsyncOperation* pThis, HRESULT *pActivateResult, mal_IUnknown** ppActivatedInterface) { return pThis->lpVtbl->GetActivateResult(pThis, pActivateResult, ppActivatedInterface); } + HRESULT ma_IActivateAudioInterfaceAsyncOperation_QueryInterface(ma_IActivateAudioInterfaceAsyncOperation* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); } + ULONG ma_IActivateAudioInterfaceAsyncOperation_AddRef(ma_IActivateAudioInterfaceAsyncOperation* pThis) { return pThis->lpVtbl->AddRef(pThis); } + ULONG ma_IActivateAudioInterfaceAsyncOperation_Release(ma_IActivateAudioInterfaceAsyncOperation* pThis) { return pThis->lpVtbl->Release(pThis); } + HRESULT ma_IActivateAudioInterfaceAsyncOperation_GetActivateResult(ma_IActivateAudioInterfaceAsyncOperation* pThis, HRESULT *pActivateResult, ma_IUnknown** ppActivatedInterface) { return pThis->lpVtbl->GetActivateResult(pThis, pActivateResult, ppActivatedInterface); } #endif // IPropertyStore typedef struct { // IUnknown - HRESULT (STDMETHODCALLTYPE * QueryInterface)(mal_IPropertyStore* pThis, const IID* const riid, void** ppObject); - ULONG (STDMETHODCALLTYPE * AddRef) (mal_IPropertyStore* pThis); - ULONG (STDMETHODCALLTYPE * Release) (mal_IPropertyStore* pThis); + HRESULT (STDMETHODCALLTYPE * QueryInterface)(ma_IPropertyStore* pThis, const IID* const riid, void** ppObject); + ULONG (STDMETHODCALLTYPE * AddRef) (ma_IPropertyStore* pThis); + ULONG (STDMETHODCALLTYPE * Release) (ma_IPropertyStore* pThis); // IPropertyStore - HRESULT (STDMETHODCALLTYPE * GetCount)(mal_IPropertyStore* pThis, DWORD* pPropCount); - HRESULT (STDMETHODCALLTYPE * GetAt) (mal_IPropertyStore* pThis, DWORD propIndex, PROPERTYKEY* pPropKey); - HRESULT (STDMETHODCALLTYPE * GetValue)(mal_IPropertyStore* pThis, const PROPERTYKEY* const pKey, PROPVARIANT* pPropVar); - HRESULT (STDMETHODCALLTYPE * SetValue)(mal_IPropertyStore* pThis, const PROPERTYKEY* const pKey, const PROPVARIANT* const pPropVar); - HRESULT (STDMETHODCALLTYPE * Commit) (mal_IPropertyStore* pThis); -} mal_IPropertyStoreVtbl; -struct mal_IPropertyStore + HRESULT (STDMETHODCALLTYPE * GetCount)(ma_IPropertyStore* pThis, DWORD* pPropCount); + HRESULT (STDMETHODCALLTYPE * GetAt) (ma_IPropertyStore* pThis, DWORD propIndex, PROPERTYKEY* pPropKey); + HRESULT (STDMETHODCALLTYPE * GetValue)(ma_IPropertyStore* pThis, const PROPERTYKEY* const pKey, PROPVARIANT* pPropVar); + HRESULT (STDMETHODCALLTYPE * SetValue)(ma_IPropertyStore* pThis, const PROPERTYKEY* const pKey, const PROPVARIANT* const pPropVar); + HRESULT (STDMETHODCALLTYPE * Commit) (ma_IPropertyStore* pThis); +} ma_IPropertyStoreVtbl; +struct ma_IPropertyStore { - mal_IPropertyStoreVtbl* lpVtbl; + ma_IPropertyStoreVtbl* lpVtbl; }; -HRESULT mal_IPropertyStore_QueryInterface(mal_IPropertyStore* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); } -ULONG mal_IPropertyStore_AddRef(mal_IPropertyStore* pThis) { return pThis->lpVtbl->AddRef(pThis); } -ULONG mal_IPropertyStore_Release(mal_IPropertyStore* pThis) { return pThis->lpVtbl->Release(pThis); } -HRESULT mal_IPropertyStore_GetCount(mal_IPropertyStore* pThis, DWORD* pPropCount) { return pThis->lpVtbl->GetCount(pThis, pPropCount); } -HRESULT mal_IPropertyStore_GetAt(mal_IPropertyStore* pThis, DWORD propIndex, PROPERTYKEY* pPropKey) { return pThis->lpVtbl->GetAt(pThis, propIndex, pPropKey); } -HRESULT mal_IPropertyStore_GetValue(mal_IPropertyStore* pThis, const PROPERTYKEY* const pKey, PROPVARIANT* pPropVar) { return pThis->lpVtbl->GetValue(pThis, pKey, pPropVar); } -HRESULT mal_IPropertyStore_SetValue(mal_IPropertyStore* pThis, const PROPERTYKEY* const pKey, const PROPVARIANT* const pPropVar) { return pThis->lpVtbl->SetValue(pThis, pKey, pPropVar); } -HRESULT mal_IPropertyStore_Commit(mal_IPropertyStore* pThis) { return pThis->lpVtbl->Commit(pThis); } +HRESULT ma_IPropertyStore_QueryInterface(ma_IPropertyStore* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); } +ULONG ma_IPropertyStore_AddRef(ma_IPropertyStore* pThis) { return pThis->lpVtbl->AddRef(pThis); } +ULONG ma_IPropertyStore_Release(ma_IPropertyStore* pThis) { return pThis->lpVtbl->Release(pThis); } +HRESULT ma_IPropertyStore_GetCount(ma_IPropertyStore* pThis, DWORD* pPropCount) { return pThis->lpVtbl->GetCount(pThis, pPropCount); } +HRESULT ma_IPropertyStore_GetAt(ma_IPropertyStore* pThis, DWORD propIndex, PROPERTYKEY* pPropKey) { return pThis->lpVtbl->GetAt(pThis, propIndex, pPropKey); } +HRESULT ma_IPropertyStore_GetValue(ma_IPropertyStore* pThis, const PROPERTYKEY* const pKey, PROPVARIANT* pPropVar) { return pThis->lpVtbl->GetValue(pThis, pKey, pPropVar); } +HRESULT ma_IPropertyStore_SetValue(ma_IPropertyStore* pThis, const PROPERTYKEY* const pKey, const PROPVARIANT* const pPropVar) { return pThis->lpVtbl->SetValue(pThis, pKey, pPropVar); } +HRESULT ma_IPropertyStore_Commit(ma_IPropertyStore* pThis) { return pThis->lpVtbl->Commit(pThis); } // IAudioClient typedef struct { // IUnknown - HRESULT (STDMETHODCALLTYPE * QueryInterface)(mal_IAudioClient* pThis, const IID* const riid, void** ppObject); - ULONG (STDMETHODCALLTYPE * AddRef) (mal_IAudioClient* pThis); - ULONG (STDMETHODCALLTYPE * Release) (mal_IAudioClient* pThis); + HRESULT (STDMETHODCALLTYPE * QueryInterface)(ma_IAudioClient* pThis, const IID* const riid, void** ppObject); + ULONG (STDMETHODCALLTYPE * AddRef) (ma_IAudioClient* pThis); + ULONG (STDMETHODCALLTYPE * Release) (ma_IAudioClient* pThis); // IAudioClient - HRESULT (STDMETHODCALLTYPE * Initialize) (mal_IAudioClient* pThis, MA_AUDCLNT_SHAREMODE shareMode, DWORD streamFlags, MA_REFERENCE_TIME bufferDuration, MA_REFERENCE_TIME periodicity, const WAVEFORMATEX* pFormat, const GUID* pAudioSessionGuid); - HRESULT (STDMETHODCALLTYPE * GetBufferSize) (mal_IAudioClient* pThis, mal_uint32* pNumBufferFrames); - HRESULT (STDMETHODCALLTYPE * GetStreamLatency) (mal_IAudioClient* pThis, MA_REFERENCE_TIME* pLatency); - HRESULT (STDMETHODCALLTYPE * GetCurrentPadding)(mal_IAudioClient* pThis, mal_uint32* pNumPaddingFrames); - HRESULT (STDMETHODCALLTYPE * IsFormatSupported)(mal_IAudioClient* pThis, MA_AUDCLNT_SHAREMODE shareMode, const WAVEFORMATEX* pFormat, WAVEFORMATEX** ppClosestMatch); - HRESULT (STDMETHODCALLTYPE * GetMixFormat) (mal_IAudioClient* pThis, WAVEFORMATEX** ppDeviceFormat); - HRESULT (STDMETHODCALLTYPE * GetDevicePeriod) (mal_IAudioClient* pThis, MA_REFERENCE_TIME* pDefaultDevicePeriod, MA_REFERENCE_TIME* pMinimumDevicePeriod); - HRESULT (STDMETHODCALLTYPE * Start) (mal_IAudioClient* pThis); - HRESULT (STDMETHODCALLTYPE * Stop) (mal_IAudioClient* pThis); - HRESULT (STDMETHODCALLTYPE * Reset) (mal_IAudioClient* pThis); - HRESULT (STDMETHODCALLTYPE * SetEventHandle) (mal_IAudioClient* pThis, HANDLE eventHandle); - HRESULT (STDMETHODCALLTYPE * GetService) (mal_IAudioClient* pThis, const IID* const riid, void** pp); -} mal_IAudioClientVtbl; -struct mal_IAudioClient + HRESULT (STDMETHODCALLTYPE * Initialize) (ma_IAudioClient* pThis, MA_AUDCLNT_SHAREMODE shareMode, DWORD streamFlags, MA_REFERENCE_TIME bufferDuration, MA_REFERENCE_TIME periodicity, const WAVEFORMATEX* pFormat, const GUID* pAudioSessionGuid); + HRESULT (STDMETHODCALLTYPE * GetBufferSize) (ma_IAudioClient* pThis, ma_uint32* pNumBufferFrames); + HRESULT (STDMETHODCALLTYPE * GetStreamLatency) (ma_IAudioClient* pThis, MA_REFERENCE_TIME* pLatency); + HRESULT (STDMETHODCALLTYPE * GetCurrentPadding)(ma_IAudioClient* pThis, ma_uint32* pNumPaddingFrames); + HRESULT (STDMETHODCALLTYPE * IsFormatSupported)(ma_IAudioClient* pThis, MA_AUDCLNT_SHAREMODE shareMode, const WAVEFORMATEX* pFormat, WAVEFORMATEX** ppClosestMatch); + HRESULT (STDMETHODCALLTYPE * GetMixFormat) (ma_IAudioClient* pThis, WAVEFORMATEX** ppDeviceFormat); + HRESULT (STDMETHODCALLTYPE * GetDevicePeriod) (ma_IAudioClient* pThis, MA_REFERENCE_TIME* pDefaultDevicePeriod, MA_REFERENCE_TIME* pMinimumDevicePeriod); + HRESULT (STDMETHODCALLTYPE * Start) (ma_IAudioClient* pThis); + HRESULT (STDMETHODCALLTYPE * Stop) (ma_IAudioClient* pThis); + HRESULT (STDMETHODCALLTYPE * Reset) (ma_IAudioClient* pThis); + HRESULT (STDMETHODCALLTYPE * SetEventHandle) (ma_IAudioClient* pThis, HANDLE eventHandle); + HRESULT (STDMETHODCALLTYPE * GetService) (ma_IAudioClient* pThis, const IID* const riid, void** pp); +} ma_IAudioClientVtbl; +struct ma_IAudioClient { - mal_IAudioClientVtbl* lpVtbl; + ma_IAudioClientVtbl* lpVtbl; }; -HRESULT mal_IAudioClient_QueryInterface(mal_IAudioClient* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); } -ULONG mal_IAudioClient_AddRef(mal_IAudioClient* pThis) { return pThis->lpVtbl->AddRef(pThis); } -ULONG mal_IAudioClient_Release(mal_IAudioClient* pThis) { return pThis->lpVtbl->Release(pThis); } -HRESULT mal_IAudioClient_Initialize(mal_IAudioClient* pThis, MA_AUDCLNT_SHAREMODE shareMode, DWORD streamFlags, MA_REFERENCE_TIME bufferDuration, MA_REFERENCE_TIME periodicity, const WAVEFORMATEX* pFormat, const GUID* pAudioSessionGuid) { return pThis->lpVtbl->Initialize(pThis, shareMode, streamFlags, bufferDuration, periodicity, pFormat, pAudioSessionGuid); } -HRESULT mal_IAudioClient_GetBufferSize(mal_IAudioClient* pThis, mal_uint32* pNumBufferFrames) { return pThis->lpVtbl->GetBufferSize(pThis, pNumBufferFrames); } -HRESULT mal_IAudioClient_GetStreamLatency(mal_IAudioClient* pThis, MA_REFERENCE_TIME* pLatency) { return pThis->lpVtbl->GetStreamLatency(pThis, pLatency); } -HRESULT mal_IAudioClient_GetCurrentPadding(mal_IAudioClient* pThis, mal_uint32* pNumPaddingFrames) { return pThis->lpVtbl->GetCurrentPadding(pThis, pNumPaddingFrames); } -HRESULT mal_IAudioClient_IsFormatSupported(mal_IAudioClient* pThis, MA_AUDCLNT_SHAREMODE shareMode, const WAVEFORMATEX* pFormat, WAVEFORMATEX** ppClosestMatch) { return pThis->lpVtbl->IsFormatSupported(pThis, shareMode, pFormat, ppClosestMatch); } -HRESULT mal_IAudioClient_GetMixFormat(mal_IAudioClient* pThis, WAVEFORMATEX** ppDeviceFormat) { return pThis->lpVtbl->GetMixFormat(pThis, ppDeviceFormat); } -HRESULT mal_IAudioClient_GetDevicePeriod(mal_IAudioClient* pThis, MA_REFERENCE_TIME* pDefaultDevicePeriod, MA_REFERENCE_TIME* pMinimumDevicePeriod) { return pThis->lpVtbl->GetDevicePeriod(pThis, pDefaultDevicePeriod, pMinimumDevicePeriod); } -HRESULT mal_IAudioClient_Start(mal_IAudioClient* pThis) { return pThis->lpVtbl->Start(pThis); } -HRESULT mal_IAudioClient_Stop(mal_IAudioClient* pThis) { return pThis->lpVtbl->Stop(pThis); } -HRESULT mal_IAudioClient_Reset(mal_IAudioClient* pThis) { return pThis->lpVtbl->Reset(pThis); } -HRESULT mal_IAudioClient_SetEventHandle(mal_IAudioClient* pThis, HANDLE eventHandle) { return pThis->lpVtbl->SetEventHandle(pThis, eventHandle); } -HRESULT mal_IAudioClient_GetService(mal_IAudioClient* pThis, const IID* const riid, void** pp) { return pThis->lpVtbl->GetService(pThis, riid, pp); } +HRESULT ma_IAudioClient_QueryInterface(ma_IAudioClient* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); } +ULONG ma_IAudioClient_AddRef(ma_IAudioClient* pThis) { return pThis->lpVtbl->AddRef(pThis); } +ULONG ma_IAudioClient_Release(ma_IAudioClient* pThis) { return pThis->lpVtbl->Release(pThis); } +HRESULT ma_IAudioClient_Initialize(ma_IAudioClient* pThis, MA_AUDCLNT_SHAREMODE shareMode, DWORD streamFlags, MA_REFERENCE_TIME bufferDuration, MA_REFERENCE_TIME periodicity, const WAVEFORMATEX* pFormat, const GUID* pAudioSessionGuid) { return pThis->lpVtbl->Initialize(pThis, shareMode, streamFlags, bufferDuration, periodicity, pFormat, pAudioSessionGuid); } +HRESULT ma_IAudioClient_GetBufferSize(ma_IAudioClient* pThis, ma_uint32* pNumBufferFrames) { return pThis->lpVtbl->GetBufferSize(pThis, pNumBufferFrames); } +HRESULT ma_IAudioClient_GetStreamLatency(ma_IAudioClient* pThis, MA_REFERENCE_TIME* pLatency) { return pThis->lpVtbl->GetStreamLatency(pThis, pLatency); } +HRESULT ma_IAudioClient_GetCurrentPadding(ma_IAudioClient* pThis, ma_uint32* pNumPaddingFrames) { return pThis->lpVtbl->GetCurrentPadding(pThis, pNumPaddingFrames); } +HRESULT ma_IAudioClient_IsFormatSupported(ma_IAudioClient* pThis, MA_AUDCLNT_SHAREMODE shareMode, const WAVEFORMATEX* pFormat, WAVEFORMATEX** ppClosestMatch) { return pThis->lpVtbl->IsFormatSupported(pThis, shareMode, pFormat, ppClosestMatch); } +HRESULT ma_IAudioClient_GetMixFormat(ma_IAudioClient* pThis, WAVEFORMATEX** ppDeviceFormat) { return pThis->lpVtbl->GetMixFormat(pThis, ppDeviceFormat); } +HRESULT ma_IAudioClient_GetDevicePeriod(ma_IAudioClient* pThis, MA_REFERENCE_TIME* pDefaultDevicePeriod, MA_REFERENCE_TIME* pMinimumDevicePeriod) { return pThis->lpVtbl->GetDevicePeriod(pThis, pDefaultDevicePeriod, pMinimumDevicePeriod); } +HRESULT ma_IAudioClient_Start(ma_IAudioClient* pThis) { return pThis->lpVtbl->Start(pThis); } +HRESULT ma_IAudioClient_Stop(ma_IAudioClient* pThis) { return pThis->lpVtbl->Stop(pThis); } +HRESULT ma_IAudioClient_Reset(ma_IAudioClient* pThis) { return pThis->lpVtbl->Reset(pThis); } +HRESULT ma_IAudioClient_SetEventHandle(ma_IAudioClient* pThis, HANDLE eventHandle) { return pThis->lpVtbl->SetEventHandle(pThis, eventHandle); } +HRESULT ma_IAudioClient_GetService(ma_IAudioClient* pThis, const IID* const riid, void** pp) { return pThis->lpVtbl->GetService(pThis, riid, pp); } // IAudioClient2 typedef struct { // IUnknown - HRESULT (STDMETHODCALLTYPE * QueryInterface)(mal_IAudioClient2* pThis, const IID* const riid, void** ppObject); - ULONG (STDMETHODCALLTYPE * AddRef) (mal_IAudioClient2* pThis); - ULONG (STDMETHODCALLTYPE * Release) (mal_IAudioClient2* pThis); + HRESULT (STDMETHODCALLTYPE * QueryInterface)(ma_IAudioClient2* pThis, const IID* const riid, void** ppObject); + ULONG (STDMETHODCALLTYPE * AddRef) (ma_IAudioClient2* pThis); + ULONG (STDMETHODCALLTYPE * Release) (ma_IAudioClient2* pThis); // IAudioClient - HRESULT (STDMETHODCALLTYPE * Initialize) (mal_IAudioClient2* pThis, MA_AUDCLNT_SHAREMODE shareMode, DWORD streamFlags, MA_REFERENCE_TIME bufferDuration, MA_REFERENCE_TIME periodicity, const WAVEFORMATEX* pFormat, const GUID* pAudioSessionGuid); - HRESULT (STDMETHODCALLTYPE * GetBufferSize) (mal_IAudioClient2* pThis, mal_uint32* pNumBufferFrames); - HRESULT (STDMETHODCALLTYPE * GetStreamLatency) (mal_IAudioClient2* pThis, MA_REFERENCE_TIME* pLatency); - HRESULT (STDMETHODCALLTYPE * GetCurrentPadding)(mal_IAudioClient2* pThis, mal_uint32* pNumPaddingFrames); - HRESULT (STDMETHODCALLTYPE * IsFormatSupported)(mal_IAudioClient2* pThis, MA_AUDCLNT_SHAREMODE shareMode, const WAVEFORMATEX* pFormat, WAVEFORMATEX** ppClosestMatch); - HRESULT (STDMETHODCALLTYPE * GetMixFormat) (mal_IAudioClient2* pThis, WAVEFORMATEX** ppDeviceFormat); - HRESULT (STDMETHODCALLTYPE * GetDevicePeriod) (mal_IAudioClient2* pThis, MA_REFERENCE_TIME* pDefaultDevicePeriod, MA_REFERENCE_TIME* pMinimumDevicePeriod); - HRESULT (STDMETHODCALLTYPE * Start) (mal_IAudioClient2* pThis); - HRESULT (STDMETHODCALLTYPE * Stop) (mal_IAudioClient2* pThis); - HRESULT (STDMETHODCALLTYPE * Reset) (mal_IAudioClient2* pThis); - HRESULT (STDMETHODCALLTYPE * SetEventHandle) (mal_IAudioClient2* pThis, HANDLE eventHandle); - HRESULT (STDMETHODCALLTYPE * GetService) (mal_IAudioClient2* pThis, const IID* const riid, void** pp); + HRESULT (STDMETHODCALLTYPE * Initialize) (ma_IAudioClient2* pThis, MA_AUDCLNT_SHAREMODE shareMode, DWORD streamFlags, MA_REFERENCE_TIME bufferDuration, MA_REFERENCE_TIME periodicity, const WAVEFORMATEX* pFormat, const GUID* pAudioSessionGuid); + HRESULT (STDMETHODCALLTYPE * GetBufferSize) (ma_IAudioClient2* pThis, ma_uint32* pNumBufferFrames); + HRESULT (STDMETHODCALLTYPE * GetStreamLatency) (ma_IAudioClient2* pThis, MA_REFERENCE_TIME* pLatency); + HRESULT (STDMETHODCALLTYPE * GetCurrentPadding)(ma_IAudioClient2* pThis, ma_uint32* pNumPaddingFrames); + HRESULT (STDMETHODCALLTYPE * IsFormatSupported)(ma_IAudioClient2* pThis, MA_AUDCLNT_SHAREMODE shareMode, const WAVEFORMATEX* pFormat, WAVEFORMATEX** ppClosestMatch); + HRESULT (STDMETHODCALLTYPE * GetMixFormat) (ma_IAudioClient2* pThis, WAVEFORMATEX** ppDeviceFormat); + HRESULT (STDMETHODCALLTYPE * GetDevicePeriod) (ma_IAudioClient2* pThis, MA_REFERENCE_TIME* pDefaultDevicePeriod, MA_REFERENCE_TIME* pMinimumDevicePeriod); + HRESULT (STDMETHODCALLTYPE * Start) (ma_IAudioClient2* pThis); + HRESULT (STDMETHODCALLTYPE * Stop) (ma_IAudioClient2* pThis); + HRESULT (STDMETHODCALLTYPE * Reset) (ma_IAudioClient2* pThis); + HRESULT (STDMETHODCALLTYPE * SetEventHandle) (ma_IAudioClient2* pThis, HANDLE eventHandle); + HRESULT (STDMETHODCALLTYPE * GetService) (ma_IAudioClient2* pThis, const IID* const riid, void** pp); // IAudioClient2 - HRESULT (STDMETHODCALLTYPE * IsOffloadCapable) (mal_IAudioClient2* pThis, MA_AUDIO_STREAM_CATEGORY category, BOOL* pOffloadCapable); - HRESULT (STDMETHODCALLTYPE * SetClientProperties)(mal_IAudioClient2* pThis, const mal_AudioClientProperties* pProperties); - HRESULT (STDMETHODCALLTYPE * GetBufferSizeLimits)(mal_IAudioClient2* pThis, const WAVEFORMATEX* pFormat, BOOL eventDriven, MA_REFERENCE_TIME* pMinBufferDuration, MA_REFERENCE_TIME* pMaxBufferDuration); -} mal_IAudioClient2Vtbl; -struct mal_IAudioClient2 + HRESULT (STDMETHODCALLTYPE * IsOffloadCapable) (ma_IAudioClient2* pThis, MA_AUDIO_STREAM_CATEGORY category, BOOL* pOffloadCapable); + HRESULT (STDMETHODCALLTYPE * SetClientProperties)(ma_IAudioClient2* pThis, const ma_AudioClientProperties* pProperties); + HRESULT (STDMETHODCALLTYPE * GetBufferSizeLimits)(ma_IAudioClient2* pThis, const WAVEFORMATEX* pFormat, BOOL eventDriven, MA_REFERENCE_TIME* pMinBufferDuration, MA_REFERENCE_TIME* pMaxBufferDuration); +} ma_IAudioClient2Vtbl; +struct ma_IAudioClient2 { - mal_IAudioClient2Vtbl* lpVtbl; + ma_IAudioClient2Vtbl* lpVtbl; }; -HRESULT mal_IAudioClient2_QueryInterface(mal_IAudioClient2* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); } -ULONG mal_IAudioClient2_AddRef(mal_IAudioClient2* pThis) { return pThis->lpVtbl->AddRef(pThis); } -ULONG mal_IAudioClient2_Release(mal_IAudioClient2* pThis) { return pThis->lpVtbl->Release(pThis); } -HRESULT mal_IAudioClient2_Initialize(mal_IAudioClient2* pThis, MA_AUDCLNT_SHAREMODE shareMode, DWORD streamFlags, MA_REFERENCE_TIME bufferDuration, MA_REFERENCE_TIME periodicity, const WAVEFORMATEX* pFormat, const GUID* pAudioSessionGuid) { return pThis->lpVtbl->Initialize(pThis, shareMode, streamFlags, bufferDuration, periodicity, pFormat, pAudioSessionGuid); } -HRESULT mal_IAudioClient2_GetBufferSize(mal_IAudioClient2* pThis, mal_uint32* pNumBufferFrames) { return pThis->lpVtbl->GetBufferSize(pThis, pNumBufferFrames); } -HRESULT mal_IAudioClient2_GetStreamLatency(mal_IAudioClient2* pThis, MA_REFERENCE_TIME* pLatency) { return pThis->lpVtbl->GetStreamLatency(pThis, pLatency); } -HRESULT mal_IAudioClient2_GetCurrentPadding(mal_IAudioClient2* pThis, mal_uint32* pNumPaddingFrames) { return pThis->lpVtbl->GetCurrentPadding(pThis, pNumPaddingFrames); } -HRESULT mal_IAudioClient2_IsFormatSupported(mal_IAudioClient2* pThis, MA_AUDCLNT_SHAREMODE shareMode, const WAVEFORMATEX* pFormat, WAVEFORMATEX** ppClosestMatch) { return pThis->lpVtbl->IsFormatSupported(pThis, shareMode, pFormat, ppClosestMatch); } -HRESULT mal_IAudioClient2_GetMixFormat(mal_IAudioClient2* pThis, WAVEFORMATEX** ppDeviceFormat) { return pThis->lpVtbl->GetMixFormat(pThis, ppDeviceFormat); } -HRESULT mal_IAudioClient2_GetDevicePeriod(mal_IAudioClient2* pThis, MA_REFERENCE_TIME* pDefaultDevicePeriod, MA_REFERENCE_TIME* pMinimumDevicePeriod) { return pThis->lpVtbl->GetDevicePeriod(pThis, pDefaultDevicePeriod, pMinimumDevicePeriod); } -HRESULT mal_IAudioClient2_Start(mal_IAudioClient2* pThis) { return pThis->lpVtbl->Start(pThis); } -HRESULT mal_IAudioClient2_Stop(mal_IAudioClient2* pThis) { return pThis->lpVtbl->Stop(pThis); } -HRESULT mal_IAudioClient2_Reset(mal_IAudioClient2* pThis) { return pThis->lpVtbl->Reset(pThis); } -HRESULT mal_IAudioClient2_SetEventHandle(mal_IAudioClient2* pThis, HANDLE eventHandle) { return pThis->lpVtbl->SetEventHandle(pThis, eventHandle); } -HRESULT mal_IAudioClient2_GetService(mal_IAudioClient2* pThis, const IID* const riid, void** pp) { return pThis->lpVtbl->GetService(pThis, riid, pp); } -HRESULT mal_IAudioClient2_IsOffloadCapable(mal_IAudioClient2* pThis, MA_AUDIO_STREAM_CATEGORY category, BOOL* pOffloadCapable) { return pThis->lpVtbl->IsOffloadCapable(pThis, category, pOffloadCapable); } -HRESULT mal_IAudioClient2_SetClientProperties(mal_IAudioClient2* pThis, const mal_AudioClientProperties* pProperties) { return pThis->lpVtbl->SetClientProperties(pThis, pProperties); } -HRESULT mal_IAudioClient2_GetBufferSizeLimits(mal_IAudioClient2* pThis, const WAVEFORMATEX* pFormat, BOOL eventDriven, MA_REFERENCE_TIME* pMinBufferDuration, MA_REFERENCE_TIME* pMaxBufferDuration) { return pThis->lpVtbl->GetBufferSizeLimits(pThis, pFormat, eventDriven, pMinBufferDuration, pMaxBufferDuration); } +HRESULT ma_IAudioClient2_QueryInterface(ma_IAudioClient2* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); } +ULONG ma_IAudioClient2_AddRef(ma_IAudioClient2* pThis) { return pThis->lpVtbl->AddRef(pThis); } +ULONG ma_IAudioClient2_Release(ma_IAudioClient2* pThis) { return pThis->lpVtbl->Release(pThis); } +HRESULT ma_IAudioClient2_Initialize(ma_IAudioClient2* pThis, MA_AUDCLNT_SHAREMODE shareMode, DWORD streamFlags, MA_REFERENCE_TIME bufferDuration, MA_REFERENCE_TIME periodicity, const WAVEFORMATEX* pFormat, const GUID* pAudioSessionGuid) { return pThis->lpVtbl->Initialize(pThis, shareMode, streamFlags, bufferDuration, periodicity, pFormat, pAudioSessionGuid); } +HRESULT ma_IAudioClient2_GetBufferSize(ma_IAudioClient2* pThis, ma_uint32* pNumBufferFrames) { return pThis->lpVtbl->GetBufferSize(pThis, pNumBufferFrames); } +HRESULT ma_IAudioClient2_GetStreamLatency(ma_IAudioClient2* pThis, MA_REFERENCE_TIME* pLatency) { return pThis->lpVtbl->GetStreamLatency(pThis, pLatency); } +HRESULT ma_IAudioClient2_GetCurrentPadding(ma_IAudioClient2* pThis, ma_uint32* pNumPaddingFrames) { return pThis->lpVtbl->GetCurrentPadding(pThis, pNumPaddingFrames); } +HRESULT ma_IAudioClient2_IsFormatSupported(ma_IAudioClient2* pThis, MA_AUDCLNT_SHAREMODE shareMode, const WAVEFORMATEX* pFormat, WAVEFORMATEX** ppClosestMatch) { return pThis->lpVtbl->IsFormatSupported(pThis, shareMode, pFormat, ppClosestMatch); } +HRESULT ma_IAudioClient2_GetMixFormat(ma_IAudioClient2* pThis, WAVEFORMATEX** ppDeviceFormat) { return pThis->lpVtbl->GetMixFormat(pThis, ppDeviceFormat); } +HRESULT ma_IAudioClient2_GetDevicePeriod(ma_IAudioClient2* pThis, MA_REFERENCE_TIME* pDefaultDevicePeriod, MA_REFERENCE_TIME* pMinimumDevicePeriod) { return pThis->lpVtbl->GetDevicePeriod(pThis, pDefaultDevicePeriod, pMinimumDevicePeriod); } +HRESULT ma_IAudioClient2_Start(ma_IAudioClient2* pThis) { return pThis->lpVtbl->Start(pThis); } +HRESULT ma_IAudioClient2_Stop(ma_IAudioClient2* pThis) { return pThis->lpVtbl->Stop(pThis); } +HRESULT ma_IAudioClient2_Reset(ma_IAudioClient2* pThis) { return pThis->lpVtbl->Reset(pThis); } +HRESULT ma_IAudioClient2_SetEventHandle(ma_IAudioClient2* pThis, HANDLE eventHandle) { return pThis->lpVtbl->SetEventHandle(pThis, eventHandle); } +HRESULT ma_IAudioClient2_GetService(ma_IAudioClient2* pThis, const IID* const riid, void** pp) { return pThis->lpVtbl->GetService(pThis, riid, pp); } +HRESULT ma_IAudioClient2_IsOffloadCapable(ma_IAudioClient2* pThis, MA_AUDIO_STREAM_CATEGORY category, BOOL* pOffloadCapable) { return pThis->lpVtbl->IsOffloadCapable(pThis, category, pOffloadCapable); } +HRESULT ma_IAudioClient2_SetClientProperties(ma_IAudioClient2* pThis, const ma_AudioClientProperties* pProperties) { return pThis->lpVtbl->SetClientProperties(pThis, pProperties); } +HRESULT ma_IAudioClient2_GetBufferSizeLimits(ma_IAudioClient2* pThis, const WAVEFORMATEX* pFormat, BOOL eventDriven, MA_REFERENCE_TIME* pMinBufferDuration, MA_REFERENCE_TIME* pMaxBufferDuration) { return pThis->lpVtbl->GetBufferSizeLimits(pThis, pFormat, eventDriven, pMinBufferDuration, pMaxBufferDuration); } // IAudioClient3 typedef struct { // IUnknown - HRESULT (STDMETHODCALLTYPE * QueryInterface)(mal_IAudioClient3* pThis, const IID* const riid, void** ppObject); - ULONG (STDMETHODCALLTYPE * AddRef) (mal_IAudioClient3* pThis); - ULONG (STDMETHODCALLTYPE * Release) (mal_IAudioClient3* pThis); + HRESULT (STDMETHODCALLTYPE * QueryInterface)(ma_IAudioClient3* pThis, const IID* const riid, void** ppObject); + ULONG (STDMETHODCALLTYPE * AddRef) (ma_IAudioClient3* pThis); + ULONG (STDMETHODCALLTYPE * Release) (ma_IAudioClient3* pThis); // IAudioClient - HRESULT (STDMETHODCALLTYPE * Initialize) (mal_IAudioClient3* pThis, MA_AUDCLNT_SHAREMODE shareMode, DWORD streamFlags, MA_REFERENCE_TIME bufferDuration, MA_REFERENCE_TIME periodicity, const WAVEFORMATEX* pFormat, const GUID* pAudioSessionGuid); - HRESULT (STDMETHODCALLTYPE * GetBufferSize) (mal_IAudioClient3* pThis, mal_uint32* pNumBufferFrames); - HRESULT (STDMETHODCALLTYPE * GetStreamLatency) (mal_IAudioClient3* pThis, MA_REFERENCE_TIME* pLatency); - HRESULT (STDMETHODCALLTYPE * GetCurrentPadding)(mal_IAudioClient3* pThis, mal_uint32* pNumPaddingFrames); - HRESULT (STDMETHODCALLTYPE * IsFormatSupported)(mal_IAudioClient3* pThis, MA_AUDCLNT_SHAREMODE shareMode, const WAVEFORMATEX* pFormat, WAVEFORMATEX** ppClosestMatch); - HRESULT (STDMETHODCALLTYPE * GetMixFormat) (mal_IAudioClient3* pThis, WAVEFORMATEX** ppDeviceFormat); - HRESULT (STDMETHODCALLTYPE * GetDevicePeriod) (mal_IAudioClient3* pThis, MA_REFERENCE_TIME* pDefaultDevicePeriod, MA_REFERENCE_TIME* pMinimumDevicePeriod); - HRESULT (STDMETHODCALLTYPE * Start) (mal_IAudioClient3* pThis); - HRESULT (STDMETHODCALLTYPE * Stop) (mal_IAudioClient3* pThis); - HRESULT (STDMETHODCALLTYPE * Reset) (mal_IAudioClient3* pThis); - HRESULT (STDMETHODCALLTYPE * SetEventHandle) (mal_IAudioClient3* pThis, HANDLE eventHandle); - HRESULT (STDMETHODCALLTYPE * GetService) (mal_IAudioClient3* pThis, const IID* const riid, void** pp); + HRESULT (STDMETHODCALLTYPE * Initialize) (ma_IAudioClient3* pThis, MA_AUDCLNT_SHAREMODE shareMode, DWORD streamFlags, MA_REFERENCE_TIME bufferDuration, MA_REFERENCE_TIME periodicity, const WAVEFORMATEX* pFormat, const GUID* pAudioSessionGuid); + HRESULT (STDMETHODCALLTYPE * GetBufferSize) (ma_IAudioClient3* pThis, ma_uint32* pNumBufferFrames); + HRESULT (STDMETHODCALLTYPE * GetStreamLatency) (ma_IAudioClient3* pThis, MA_REFERENCE_TIME* pLatency); + HRESULT (STDMETHODCALLTYPE * GetCurrentPadding)(ma_IAudioClient3* pThis, ma_uint32* pNumPaddingFrames); + HRESULT (STDMETHODCALLTYPE * IsFormatSupported)(ma_IAudioClient3* pThis, MA_AUDCLNT_SHAREMODE shareMode, const WAVEFORMATEX* pFormat, WAVEFORMATEX** ppClosestMatch); + HRESULT (STDMETHODCALLTYPE * GetMixFormat) (ma_IAudioClient3* pThis, WAVEFORMATEX** ppDeviceFormat); + HRESULT (STDMETHODCALLTYPE * GetDevicePeriod) (ma_IAudioClient3* pThis, MA_REFERENCE_TIME* pDefaultDevicePeriod, MA_REFERENCE_TIME* pMinimumDevicePeriod); + HRESULT (STDMETHODCALLTYPE * Start) (ma_IAudioClient3* pThis); + HRESULT (STDMETHODCALLTYPE * Stop) (ma_IAudioClient3* pThis); + HRESULT (STDMETHODCALLTYPE * Reset) (ma_IAudioClient3* pThis); + HRESULT (STDMETHODCALLTYPE * SetEventHandle) (ma_IAudioClient3* pThis, HANDLE eventHandle); + HRESULT (STDMETHODCALLTYPE * GetService) (ma_IAudioClient3* pThis, const IID* const riid, void** pp); // IAudioClient2 - HRESULT (STDMETHODCALLTYPE * IsOffloadCapable) (mal_IAudioClient3* pThis, MA_AUDIO_STREAM_CATEGORY category, BOOL* pOffloadCapable); - HRESULT (STDMETHODCALLTYPE * SetClientProperties)(mal_IAudioClient3* pThis, const mal_AudioClientProperties* pProperties); - HRESULT (STDMETHODCALLTYPE * GetBufferSizeLimits)(mal_IAudioClient3* pThis, const WAVEFORMATEX* pFormat, BOOL eventDriven, MA_REFERENCE_TIME* pMinBufferDuration, MA_REFERENCE_TIME* pMaxBufferDuration); + HRESULT (STDMETHODCALLTYPE * IsOffloadCapable) (ma_IAudioClient3* pThis, MA_AUDIO_STREAM_CATEGORY category, BOOL* pOffloadCapable); + HRESULT (STDMETHODCALLTYPE * SetClientProperties)(ma_IAudioClient3* pThis, const ma_AudioClientProperties* pProperties); + HRESULT (STDMETHODCALLTYPE * GetBufferSizeLimits)(ma_IAudioClient3* pThis, const WAVEFORMATEX* pFormat, BOOL eventDriven, MA_REFERENCE_TIME* pMinBufferDuration, MA_REFERENCE_TIME* pMaxBufferDuration); // IAudioClient3 - HRESULT (STDMETHODCALLTYPE * GetSharedModeEnginePeriod) (mal_IAudioClient3* pThis, const WAVEFORMATEX* pFormat, UINT32* pDefaultPeriodInFrames, UINT32* pFundamentalPeriodInFrames, UINT32* pMinPeriodInFrames, UINT32* pMaxPeriodInFrames); - HRESULT (STDMETHODCALLTYPE * GetCurrentSharedModeEnginePeriod)(mal_IAudioClient3* pThis, WAVEFORMATEX** ppFormat, UINT32* pCurrentPeriodInFrames); - HRESULT (STDMETHODCALLTYPE * InitializeSharedAudioStream) (mal_IAudioClient3* pThis, DWORD streamFlags, UINT32 periodInFrames, const WAVEFORMATEX* pFormat, const GUID* pAudioSessionGuid); -} mal_IAudioClient3Vtbl; -struct mal_IAudioClient3 + HRESULT (STDMETHODCALLTYPE * GetSharedModeEnginePeriod) (ma_IAudioClient3* pThis, const WAVEFORMATEX* pFormat, UINT32* pDefaultPeriodInFrames, UINT32* pFundamentalPeriodInFrames, UINT32* pMinPeriodInFrames, UINT32* pMaxPeriodInFrames); + HRESULT (STDMETHODCALLTYPE * GetCurrentSharedModeEnginePeriod)(ma_IAudioClient3* pThis, WAVEFORMATEX** ppFormat, UINT32* pCurrentPeriodInFrames); + HRESULT (STDMETHODCALLTYPE * InitializeSharedAudioStream) (ma_IAudioClient3* pThis, DWORD streamFlags, UINT32 periodInFrames, const WAVEFORMATEX* pFormat, const GUID* pAudioSessionGuid); +} ma_IAudioClient3Vtbl; +struct ma_IAudioClient3 { - mal_IAudioClient3Vtbl* lpVtbl; + ma_IAudioClient3Vtbl* lpVtbl; }; -HRESULT mal_IAudioClient3_QueryInterface(mal_IAudioClient3* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); } -ULONG mal_IAudioClient3_AddRef(mal_IAudioClient3* pThis) { return pThis->lpVtbl->AddRef(pThis); } -ULONG mal_IAudioClient3_Release(mal_IAudioClient3* pThis) { return pThis->lpVtbl->Release(pThis); } -HRESULT mal_IAudioClient3_Initialize(mal_IAudioClient3* pThis, MA_AUDCLNT_SHAREMODE shareMode, DWORD streamFlags, MA_REFERENCE_TIME bufferDuration, MA_REFERENCE_TIME periodicity, const WAVEFORMATEX* pFormat, const GUID* pAudioSessionGuid) { return pThis->lpVtbl->Initialize(pThis, shareMode, streamFlags, bufferDuration, periodicity, pFormat, pAudioSessionGuid); } -HRESULT mal_IAudioClient3_GetBufferSize(mal_IAudioClient3* pThis, mal_uint32* pNumBufferFrames) { return pThis->lpVtbl->GetBufferSize(pThis, pNumBufferFrames); } -HRESULT mal_IAudioClient3_GetStreamLatency(mal_IAudioClient3* pThis, MA_REFERENCE_TIME* pLatency) { return pThis->lpVtbl->GetStreamLatency(pThis, pLatency); } -HRESULT mal_IAudioClient3_GetCurrentPadding(mal_IAudioClient3* pThis, mal_uint32* pNumPaddingFrames) { return pThis->lpVtbl->GetCurrentPadding(pThis, pNumPaddingFrames); } -HRESULT mal_IAudioClient3_IsFormatSupported(mal_IAudioClient3* pThis, MA_AUDCLNT_SHAREMODE shareMode, const WAVEFORMATEX* pFormat, WAVEFORMATEX** ppClosestMatch) { return pThis->lpVtbl->IsFormatSupported(pThis, shareMode, pFormat, ppClosestMatch); } -HRESULT mal_IAudioClient3_GetMixFormat(mal_IAudioClient3* pThis, WAVEFORMATEX** ppDeviceFormat) { return pThis->lpVtbl->GetMixFormat(pThis, ppDeviceFormat); } -HRESULT mal_IAudioClient3_GetDevicePeriod(mal_IAudioClient3* pThis, MA_REFERENCE_TIME* pDefaultDevicePeriod, MA_REFERENCE_TIME* pMinimumDevicePeriod) { return pThis->lpVtbl->GetDevicePeriod(pThis, pDefaultDevicePeriod, pMinimumDevicePeriod); } -HRESULT mal_IAudioClient3_Start(mal_IAudioClient3* pThis) { return pThis->lpVtbl->Start(pThis); } -HRESULT mal_IAudioClient3_Stop(mal_IAudioClient3* pThis) { return pThis->lpVtbl->Stop(pThis); } -HRESULT mal_IAudioClient3_Reset(mal_IAudioClient3* pThis) { return pThis->lpVtbl->Reset(pThis); } -HRESULT mal_IAudioClient3_SetEventHandle(mal_IAudioClient3* pThis, HANDLE eventHandle) { return pThis->lpVtbl->SetEventHandle(pThis, eventHandle); } -HRESULT mal_IAudioClient3_GetService(mal_IAudioClient3* pThis, const IID* const riid, void** pp) { return pThis->lpVtbl->GetService(pThis, riid, pp); } -HRESULT mal_IAudioClient3_IsOffloadCapable(mal_IAudioClient3* pThis, MA_AUDIO_STREAM_CATEGORY category, BOOL* pOffloadCapable) { return pThis->lpVtbl->IsOffloadCapable(pThis, category, pOffloadCapable); } -HRESULT mal_IAudioClient3_SetClientProperties(mal_IAudioClient3* pThis, const mal_AudioClientProperties* pProperties) { return pThis->lpVtbl->SetClientProperties(pThis, pProperties); } -HRESULT mal_IAudioClient3_GetBufferSizeLimits(mal_IAudioClient3* pThis, const WAVEFORMATEX* pFormat, BOOL eventDriven, MA_REFERENCE_TIME* pMinBufferDuration, MA_REFERENCE_TIME* pMaxBufferDuration) { return pThis->lpVtbl->GetBufferSizeLimits(pThis, pFormat, eventDriven, pMinBufferDuration, pMaxBufferDuration); } -HRESULT mal_IAudioClient3_GetSharedModeEnginePeriod(mal_IAudioClient3* pThis, const WAVEFORMATEX* pFormat, UINT32* pDefaultPeriodInFrames, UINT32* pFundamentalPeriodInFrames, UINT32* pMinPeriodInFrames, UINT32* pMaxPeriodInFrames) { return pThis->lpVtbl->GetSharedModeEnginePeriod(pThis, pFormat, pDefaultPeriodInFrames, pFundamentalPeriodInFrames, pMinPeriodInFrames, pMaxPeriodInFrames); } -HRESULT mal_IAudioClient3_GetCurrentSharedModeEnginePeriod(mal_IAudioClient3* pThis, WAVEFORMATEX** ppFormat, UINT32* pCurrentPeriodInFrames) { return pThis->lpVtbl->GetCurrentSharedModeEnginePeriod(pThis, ppFormat, pCurrentPeriodInFrames); } -HRESULT mal_IAudioClient3_InitializeSharedAudioStream(mal_IAudioClient3* pThis, DWORD streamFlags, UINT32 periodInFrames, const WAVEFORMATEX* pFormat, const GUID* pAudioSessionGUID) { return pThis->lpVtbl->InitializeSharedAudioStream(pThis, streamFlags, periodInFrames, pFormat, pAudioSessionGUID); } +HRESULT ma_IAudioClient3_QueryInterface(ma_IAudioClient3* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); } +ULONG ma_IAudioClient3_AddRef(ma_IAudioClient3* pThis) { return pThis->lpVtbl->AddRef(pThis); } +ULONG ma_IAudioClient3_Release(ma_IAudioClient3* pThis) { return pThis->lpVtbl->Release(pThis); } +HRESULT ma_IAudioClient3_Initialize(ma_IAudioClient3* pThis, MA_AUDCLNT_SHAREMODE shareMode, DWORD streamFlags, MA_REFERENCE_TIME bufferDuration, MA_REFERENCE_TIME periodicity, const WAVEFORMATEX* pFormat, const GUID* pAudioSessionGuid) { return pThis->lpVtbl->Initialize(pThis, shareMode, streamFlags, bufferDuration, periodicity, pFormat, pAudioSessionGuid); } +HRESULT ma_IAudioClient3_GetBufferSize(ma_IAudioClient3* pThis, ma_uint32* pNumBufferFrames) { return pThis->lpVtbl->GetBufferSize(pThis, pNumBufferFrames); } +HRESULT ma_IAudioClient3_GetStreamLatency(ma_IAudioClient3* pThis, MA_REFERENCE_TIME* pLatency) { return pThis->lpVtbl->GetStreamLatency(pThis, pLatency); } +HRESULT ma_IAudioClient3_GetCurrentPadding(ma_IAudioClient3* pThis, ma_uint32* pNumPaddingFrames) { return pThis->lpVtbl->GetCurrentPadding(pThis, pNumPaddingFrames); } +HRESULT ma_IAudioClient3_IsFormatSupported(ma_IAudioClient3* pThis, MA_AUDCLNT_SHAREMODE shareMode, const WAVEFORMATEX* pFormat, WAVEFORMATEX** ppClosestMatch) { return pThis->lpVtbl->IsFormatSupported(pThis, shareMode, pFormat, ppClosestMatch); } +HRESULT ma_IAudioClient3_GetMixFormat(ma_IAudioClient3* pThis, WAVEFORMATEX** ppDeviceFormat) { return pThis->lpVtbl->GetMixFormat(pThis, ppDeviceFormat); } +HRESULT ma_IAudioClient3_GetDevicePeriod(ma_IAudioClient3* pThis, MA_REFERENCE_TIME* pDefaultDevicePeriod, MA_REFERENCE_TIME* pMinimumDevicePeriod) { return pThis->lpVtbl->GetDevicePeriod(pThis, pDefaultDevicePeriod, pMinimumDevicePeriod); } +HRESULT ma_IAudioClient3_Start(ma_IAudioClient3* pThis) { return pThis->lpVtbl->Start(pThis); } +HRESULT ma_IAudioClient3_Stop(ma_IAudioClient3* pThis) { return pThis->lpVtbl->Stop(pThis); } +HRESULT ma_IAudioClient3_Reset(ma_IAudioClient3* pThis) { return pThis->lpVtbl->Reset(pThis); } +HRESULT ma_IAudioClient3_SetEventHandle(ma_IAudioClient3* pThis, HANDLE eventHandle) { return pThis->lpVtbl->SetEventHandle(pThis, eventHandle); } +HRESULT ma_IAudioClient3_GetService(ma_IAudioClient3* pThis, const IID* const riid, void** pp) { return pThis->lpVtbl->GetService(pThis, riid, pp); } +HRESULT ma_IAudioClient3_IsOffloadCapable(ma_IAudioClient3* pThis, MA_AUDIO_STREAM_CATEGORY category, BOOL* pOffloadCapable) { return pThis->lpVtbl->IsOffloadCapable(pThis, category, pOffloadCapable); } +HRESULT ma_IAudioClient3_SetClientProperties(ma_IAudioClient3* pThis, const ma_AudioClientProperties* pProperties) { return pThis->lpVtbl->SetClientProperties(pThis, pProperties); } +HRESULT ma_IAudioClient3_GetBufferSizeLimits(ma_IAudioClient3* pThis, const WAVEFORMATEX* pFormat, BOOL eventDriven, MA_REFERENCE_TIME* pMinBufferDuration, MA_REFERENCE_TIME* pMaxBufferDuration) { return pThis->lpVtbl->GetBufferSizeLimits(pThis, pFormat, eventDriven, pMinBufferDuration, pMaxBufferDuration); } +HRESULT ma_IAudioClient3_GetSharedModeEnginePeriod(ma_IAudioClient3* pThis, const WAVEFORMATEX* pFormat, UINT32* pDefaultPeriodInFrames, UINT32* pFundamentalPeriodInFrames, UINT32* pMinPeriodInFrames, UINT32* pMaxPeriodInFrames) { return pThis->lpVtbl->GetSharedModeEnginePeriod(pThis, pFormat, pDefaultPeriodInFrames, pFundamentalPeriodInFrames, pMinPeriodInFrames, pMaxPeriodInFrames); } +HRESULT ma_IAudioClient3_GetCurrentSharedModeEnginePeriod(ma_IAudioClient3* pThis, WAVEFORMATEX** ppFormat, UINT32* pCurrentPeriodInFrames) { return pThis->lpVtbl->GetCurrentSharedModeEnginePeriod(pThis, ppFormat, pCurrentPeriodInFrames); } +HRESULT ma_IAudioClient3_InitializeSharedAudioStream(ma_IAudioClient3* pThis, DWORD streamFlags, UINT32 periodInFrames, const WAVEFORMATEX* pFormat, const GUID* pAudioSessionGUID) { return pThis->lpVtbl->InitializeSharedAudioStream(pThis, streamFlags, periodInFrames, pFormat, pAudioSessionGUID); } // IAudioRenderClient typedef struct { // IUnknown - HRESULT (STDMETHODCALLTYPE * QueryInterface)(mal_IAudioRenderClient* pThis, const IID* const riid, void** ppObject); - ULONG (STDMETHODCALLTYPE * AddRef) (mal_IAudioRenderClient* pThis); - ULONG (STDMETHODCALLTYPE * Release) (mal_IAudioRenderClient* pThis); + HRESULT (STDMETHODCALLTYPE * QueryInterface)(ma_IAudioRenderClient* pThis, const IID* const riid, void** ppObject); + ULONG (STDMETHODCALLTYPE * AddRef) (ma_IAudioRenderClient* pThis); + ULONG (STDMETHODCALLTYPE * Release) (ma_IAudioRenderClient* pThis); // IAudioRenderClient - HRESULT (STDMETHODCALLTYPE * GetBuffer) (mal_IAudioRenderClient* pThis, mal_uint32 numFramesRequested, BYTE** ppData); - HRESULT (STDMETHODCALLTYPE * ReleaseBuffer)(mal_IAudioRenderClient* pThis, mal_uint32 numFramesWritten, DWORD dwFlags); -} mal_IAudioRenderClientVtbl; -struct mal_IAudioRenderClient + HRESULT (STDMETHODCALLTYPE * GetBuffer) (ma_IAudioRenderClient* pThis, ma_uint32 numFramesRequested, BYTE** ppData); + HRESULT (STDMETHODCALLTYPE * ReleaseBuffer)(ma_IAudioRenderClient* pThis, ma_uint32 numFramesWritten, DWORD dwFlags); +} ma_IAudioRenderClientVtbl; +struct ma_IAudioRenderClient { - mal_IAudioRenderClientVtbl* lpVtbl; + ma_IAudioRenderClientVtbl* lpVtbl; }; -HRESULT mal_IAudioRenderClient_QueryInterface(mal_IAudioRenderClient* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); } -ULONG mal_IAudioRenderClient_AddRef(mal_IAudioRenderClient* pThis) { return pThis->lpVtbl->AddRef(pThis); } -ULONG mal_IAudioRenderClient_Release(mal_IAudioRenderClient* pThis) { return pThis->lpVtbl->Release(pThis); } -HRESULT mal_IAudioRenderClient_GetBuffer(mal_IAudioRenderClient* pThis, mal_uint32 numFramesRequested, BYTE** ppData) { return pThis->lpVtbl->GetBuffer(pThis, numFramesRequested, ppData); } -HRESULT mal_IAudioRenderClient_ReleaseBuffer(mal_IAudioRenderClient* pThis, mal_uint32 numFramesWritten, DWORD dwFlags) { return pThis->lpVtbl->ReleaseBuffer(pThis, numFramesWritten, dwFlags); } +HRESULT ma_IAudioRenderClient_QueryInterface(ma_IAudioRenderClient* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); } +ULONG ma_IAudioRenderClient_AddRef(ma_IAudioRenderClient* pThis) { return pThis->lpVtbl->AddRef(pThis); } +ULONG ma_IAudioRenderClient_Release(ma_IAudioRenderClient* pThis) { return pThis->lpVtbl->Release(pThis); } +HRESULT ma_IAudioRenderClient_GetBuffer(ma_IAudioRenderClient* pThis, ma_uint32 numFramesRequested, BYTE** ppData) { return pThis->lpVtbl->GetBuffer(pThis, numFramesRequested, ppData); } +HRESULT ma_IAudioRenderClient_ReleaseBuffer(ma_IAudioRenderClient* pThis, ma_uint32 numFramesWritten, DWORD dwFlags) { return pThis->lpVtbl->ReleaseBuffer(pThis, numFramesWritten, dwFlags); } // IAudioCaptureClient typedef struct { // IUnknown - HRESULT (STDMETHODCALLTYPE * QueryInterface)(mal_IAudioCaptureClient* pThis, const IID* const riid, void** ppObject); - ULONG (STDMETHODCALLTYPE * AddRef) (mal_IAudioCaptureClient* pThis); - ULONG (STDMETHODCALLTYPE * Release) (mal_IAudioCaptureClient* pThis); + HRESULT (STDMETHODCALLTYPE * QueryInterface)(ma_IAudioCaptureClient* pThis, const IID* const riid, void** ppObject); + ULONG (STDMETHODCALLTYPE * AddRef) (ma_IAudioCaptureClient* pThis); + ULONG (STDMETHODCALLTYPE * Release) (ma_IAudioCaptureClient* pThis); // IAudioRenderClient - HRESULT (STDMETHODCALLTYPE * GetBuffer) (mal_IAudioCaptureClient* pThis, BYTE** ppData, mal_uint32* pNumFramesToRead, DWORD* pFlags, mal_uint64* pDevicePosition, mal_uint64* pQPCPosition); - HRESULT (STDMETHODCALLTYPE * ReleaseBuffer) (mal_IAudioCaptureClient* pThis, mal_uint32 numFramesRead); - HRESULT (STDMETHODCALLTYPE * GetNextPacketSize)(mal_IAudioCaptureClient* pThis, mal_uint32* pNumFramesInNextPacket); -} mal_IAudioCaptureClientVtbl; -struct mal_IAudioCaptureClient + HRESULT (STDMETHODCALLTYPE * GetBuffer) (ma_IAudioCaptureClient* pThis, BYTE** ppData, ma_uint32* pNumFramesToRead, DWORD* pFlags, ma_uint64* pDevicePosition, ma_uint64* pQPCPosition); + HRESULT (STDMETHODCALLTYPE * ReleaseBuffer) (ma_IAudioCaptureClient* pThis, ma_uint32 numFramesRead); + HRESULT (STDMETHODCALLTYPE * GetNextPacketSize)(ma_IAudioCaptureClient* pThis, ma_uint32* pNumFramesInNextPacket); +} ma_IAudioCaptureClientVtbl; +struct ma_IAudioCaptureClient { - mal_IAudioCaptureClientVtbl* lpVtbl; + ma_IAudioCaptureClientVtbl* lpVtbl; }; -HRESULT mal_IAudioCaptureClient_QueryInterface(mal_IAudioCaptureClient* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); } -ULONG mal_IAudioCaptureClient_AddRef(mal_IAudioCaptureClient* pThis) { return pThis->lpVtbl->AddRef(pThis); } -ULONG mal_IAudioCaptureClient_Release(mal_IAudioCaptureClient* pThis) { return pThis->lpVtbl->Release(pThis); } -HRESULT mal_IAudioCaptureClient_GetBuffer(mal_IAudioCaptureClient* pThis, BYTE** ppData, mal_uint32* pNumFramesToRead, DWORD* pFlags, mal_uint64* pDevicePosition, mal_uint64* pQPCPosition) { return pThis->lpVtbl->GetBuffer(pThis, ppData, pNumFramesToRead, pFlags, pDevicePosition, pQPCPosition); } -HRESULT mal_IAudioCaptureClient_ReleaseBuffer(mal_IAudioCaptureClient* pThis, mal_uint32 numFramesRead) { return pThis->lpVtbl->ReleaseBuffer(pThis, numFramesRead); } -HRESULT mal_IAudioCaptureClient_GetNextPacketSize(mal_IAudioCaptureClient* pThis, mal_uint32* pNumFramesInNextPacket) { return pThis->lpVtbl->GetNextPacketSize(pThis, pNumFramesInNextPacket); } +HRESULT ma_IAudioCaptureClient_QueryInterface(ma_IAudioCaptureClient* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); } +ULONG ma_IAudioCaptureClient_AddRef(ma_IAudioCaptureClient* pThis) { return pThis->lpVtbl->AddRef(pThis); } +ULONG ma_IAudioCaptureClient_Release(ma_IAudioCaptureClient* pThis) { return pThis->lpVtbl->Release(pThis); } +HRESULT ma_IAudioCaptureClient_GetBuffer(ma_IAudioCaptureClient* pThis, BYTE** ppData, ma_uint32* pNumFramesToRead, DWORD* pFlags, ma_uint64* pDevicePosition, ma_uint64* pQPCPosition) { return pThis->lpVtbl->GetBuffer(pThis, ppData, pNumFramesToRead, pFlags, pDevicePosition, pQPCPosition); } +HRESULT ma_IAudioCaptureClient_ReleaseBuffer(ma_IAudioCaptureClient* pThis, ma_uint32 numFramesRead) { return pThis->lpVtbl->ReleaseBuffer(pThis, numFramesRead); } +HRESULT ma_IAudioCaptureClient_GetNextPacketSize(ma_IAudioCaptureClient* pThis, ma_uint32* pNumFramesInNextPacket) { return pThis->lpVtbl->GetNextPacketSize(pThis, pNumFramesInNextPacket); } #ifndef MA_WIN32_DESKTOP #include -typedef struct mal_completion_handler_uwp mal_completion_handler_uwp; +typedef struct ma_completion_handler_uwp ma_completion_handler_uwp; typedef struct { // IUnknown - HRESULT (STDMETHODCALLTYPE * QueryInterface)(mal_completion_handler_uwp* pThis, const IID* const riid, void** ppObject); - ULONG (STDMETHODCALLTYPE * AddRef) (mal_completion_handler_uwp* pThis); - ULONG (STDMETHODCALLTYPE * Release) (mal_completion_handler_uwp* pThis); + HRESULT (STDMETHODCALLTYPE * QueryInterface)(ma_completion_handler_uwp* pThis, const IID* const riid, void** ppObject); + ULONG (STDMETHODCALLTYPE * AddRef) (ma_completion_handler_uwp* pThis); + ULONG (STDMETHODCALLTYPE * Release) (ma_completion_handler_uwp* pThis); // IActivateAudioInterfaceCompletionHandler - HRESULT (STDMETHODCALLTYPE * ActivateCompleted)(mal_completion_handler_uwp* pThis, mal_IActivateAudioInterfaceAsyncOperation* pActivateOperation); -} mal_completion_handler_uwp_vtbl; -struct mal_completion_handler_uwp + HRESULT (STDMETHODCALLTYPE * ActivateCompleted)(ma_completion_handler_uwp* pThis, ma_IActivateAudioInterfaceAsyncOperation* pActivateOperation); +} ma_completion_handler_uwp_vtbl; +struct ma_completion_handler_uwp { - mal_completion_handler_uwp_vtbl* lpVtbl; - mal_uint32 counter; + ma_completion_handler_uwp_vtbl* lpVtbl; + ma_uint32 counter; HANDLE hEvent; }; -HRESULT STDMETHODCALLTYPE mal_completion_handler_uwp_QueryInterface(mal_completion_handler_uwp* pThis, const IID* const riid, void** ppObject) +HRESULT STDMETHODCALLTYPE ma_completion_handler_uwp_QueryInterface(ma_completion_handler_uwp* pThis, const IID* const riid, void** ppObject) { // We need to "implement" IAgileObject which is just an indicator that's used internally by WASAPI for some multithreading management. To // "implement" this, we just make sure we return pThis when the IAgileObject is requested. - if (!mal_is_guid_equal(riid, &MA_IID_IUnknown) && !mal_is_guid_equal(riid, &MA_IID_IActivateAudioInterfaceCompletionHandler) && !mal_is_guid_equal(riid, &MA_IID_IAgileObject)) { + if (!ma_is_guid_equal(riid, &MA_IID_IUnknown) && !ma_is_guid_equal(riid, &MA_IID_IActivateAudioInterfaceCompletionHandler) && !ma_is_guid_equal(riid, &MA_IID_IAgileObject)) { *ppObject = NULL; return E_NOINTERFACE; } // Getting here means the IID is IUnknown or IMMNotificationClient. *ppObject = (void*)pThis; - ((mal_completion_handler_uwp_vtbl*)pThis->lpVtbl)->AddRef(pThis); + ((ma_completion_handler_uwp_vtbl*)pThis->lpVtbl)->AddRef(pThis); return S_OK; } -ULONG STDMETHODCALLTYPE mal_completion_handler_uwp_AddRef(mal_completion_handler_uwp* pThis) +ULONG STDMETHODCALLTYPE ma_completion_handler_uwp_AddRef(ma_completion_handler_uwp* pThis) { - return (ULONG)mal_atomic_increment_32(&pThis->counter); + return (ULONG)ma_atomic_increment_32(&pThis->counter); } -ULONG STDMETHODCALLTYPE mal_completion_handler_uwp_Release(mal_completion_handler_uwp* pThis) +ULONG STDMETHODCALLTYPE ma_completion_handler_uwp_Release(ma_completion_handler_uwp* pThis) { - mal_uint32 newRefCount = mal_atomic_decrement_32(&pThis->counter); + ma_uint32 newRefCount = ma_atomic_decrement_32(&pThis->counter); if (newRefCount == 0) { return 0; // We don't free anything here because we never allocate the object on the heap. } @@ -6404,7 +6404,7 @@ ULONG STDMETHODCALLTYPE mal_completion_handler_uwp_Release(mal_completion_handle return (ULONG)newRefCount; } -HRESULT STDMETHODCALLTYPE mal_completion_handler_uwp_ActivateCompleted(mal_completion_handler_uwp* pThis, mal_IActivateAudioInterfaceAsyncOperation* pActivateOperation) +HRESULT STDMETHODCALLTYPE ma_completion_handler_uwp_ActivateCompleted(ma_completion_handler_uwp* pThis, ma_IActivateAudioInterfaceAsyncOperation* pActivateOperation) { (void)pActivateOperation; SetEvent(pThis->hEvent); @@ -6412,17 +6412,17 @@ HRESULT STDMETHODCALLTYPE mal_completion_handler_uwp_ActivateCompleted(mal_compl } -static mal_completion_handler_uwp_vtbl g_malCompletionHandlerVtblInstance = { - mal_completion_handler_uwp_QueryInterface, - mal_completion_handler_uwp_AddRef, - mal_completion_handler_uwp_Release, - mal_completion_handler_uwp_ActivateCompleted +static ma_completion_handler_uwp_vtbl g_malCompletionHandlerVtblInstance = { + ma_completion_handler_uwp_QueryInterface, + ma_completion_handler_uwp_AddRef, + ma_completion_handler_uwp_Release, + ma_completion_handler_uwp_ActivateCompleted }; -mal_result mal_completion_handler_uwp_init(mal_completion_handler_uwp* pHandler) +ma_result ma_completion_handler_uwp_init(ma_completion_handler_uwp* pHandler) { - mal_assert(pHandler != NULL); - mal_zero_object(pHandler); + ma_assert(pHandler != NULL); + ma_zero_object(pHandler); pHandler->lpVtbl = &g_malCompletionHandlerVtblInstance; pHandler->counter = 1; @@ -6434,14 +6434,14 @@ mal_result mal_completion_handler_uwp_init(mal_completion_handler_uwp* pHandler) return MA_SUCCESS; } -void mal_completion_handler_uwp_uninit(mal_completion_handler_uwp* pHandler) +void ma_completion_handler_uwp_uninit(ma_completion_handler_uwp* pHandler) { if (pHandler->hEvent != NULL) { CloseHandle(pHandler->hEvent); } } -void mal_completion_handler_uwp_wait(mal_completion_handler_uwp* pHandler) +void ma_completion_handler_uwp_wait(ma_completion_handler_uwp* pHandler) { WaitForSingleObject(pHandler->hEvent, INFINITE); } @@ -6449,29 +6449,29 @@ void mal_completion_handler_uwp_wait(mal_completion_handler_uwp* pHandler) // We need a virtual table for our notification client object that's used for detecting changes to the default device. #ifdef MA_WIN32_DESKTOP -HRESULT STDMETHODCALLTYPE mal_IMMNotificationClient_QueryInterface(mal_IMMNotificationClient* pThis, const IID* const riid, void** ppObject) +HRESULT STDMETHODCALLTYPE ma_IMMNotificationClient_QueryInterface(ma_IMMNotificationClient* pThis, const IID* const riid, void** ppObject) { // We care about two interfaces - IUnknown and IMMNotificationClient. If the requested IID is something else // we just return E_NOINTERFACE. Otherwise we need to increment the reference counter and return S_OK. - if (!mal_is_guid_equal(riid, &MA_IID_IUnknown) && !mal_is_guid_equal(riid, &MA_IID_IMMNotificationClient)) { + if (!ma_is_guid_equal(riid, &MA_IID_IUnknown) && !ma_is_guid_equal(riid, &MA_IID_IMMNotificationClient)) { *ppObject = NULL; return E_NOINTERFACE; } // Getting here means the IID is IUnknown or IMMNotificationClient. *ppObject = (void*)pThis; - ((mal_IMMNotificationClientVtbl*)pThis->lpVtbl)->AddRef(pThis); + ((ma_IMMNotificationClientVtbl*)pThis->lpVtbl)->AddRef(pThis); return S_OK; } -ULONG STDMETHODCALLTYPE mal_IMMNotificationClient_AddRef(mal_IMMNotificationClient* pThis) +ULONG STDMETHODCALLTYPE ma_IMMNotificationClient_AddRef(ma_IMMNotificationClient* pThis) { - return (ULONG)mal_atomic_increment_32(&pThis->counter); + return (ULONG)ma_atomic_increment_32(&pThis->counter); } -ULONG STDMETHODCALLTYPE mal_IMMNotificationClient_Release(mal_IMMNotificationClient* pThis) +ULONG STDMETHODCALLTYPE ma_IMMNotificationClient_Release(ma_IMMNotificationClient* pThis) { - mal_uint32 newRefCount = mal_atomic_decrement_32(&pThis->counter); + ma_uint32 newRefCount = ma_atomic_decrement_32(&pThis->counter); if (newRefCount == 0) { return 0; // We don't free anything here because we never allocate the object on the heap. } @@ -6480,7 +6480,7 @@ ULONG STDMETHODCALLTYPE mal_IMMNotificationClient_Release(mal_IMMNotificationCli } -HRESULT STDMETHODCALLTYPE mal_IMMNotificationClient_OnDeviceStateChanged(mal_IMMNotificationClient* pThis, LPCWSTR pDeviceID, DWORD dwNewState) +HRESULT STDMETHODCALLTYPE ma_IMMNotificationClient_OnDeviceStateChanged(ma_IMMNotificationClient* pThis, LPCWSTR pDeviceID, DWORD dwNewState) { #ifdef MA_DEBUG_OUTPUT printf("IMMNotificationClient_OnDeviceStateChanged(pDeviceID=%S, dwNewState=%u)\n", (pDeviceID != NULL) ? pDeviceID : L"(NULL)", (unsigned int)dwNewState); @@ -6492,7 +6492,7 @@ HRESULT STDMETHODCALLTYPE mal_IMMNotificationClient_OnDeviceStateChanged(mal_IMM return S_OK; } -HRESULT STDMETHODCALLTYPE mal_IMMNotificationClient_OnDeviceAdded(mal_IMMNotificationClient* pThis, LPCWSTR pDeviceID) +HRESULT STDMETHODCALLTYPE ma_IMMNotificationClient_OnDeviceAdded(ma_IMMNotificationClient* pThis, LPCWSTR pDeviceID) { #ifdef MA_DEBUG_OUTPUT printf("IMMNotificationClient_OnDeviceAdded(pDeviceID=%S)\n", (pDeviceID != NULL) ? pDeviceID : L"(NULL)"); @@ -6504,7 +6504,7 @@ HRESULT STDMETHODCALLTYPE mal_IMMNotificationClient_OnDeviceAdded(mal_IMMNotific return S_OK; } -HRESULT STDMETHODCALLTYPE mal_IMMNotificationClient_OnDeviceRemoved(mal_IMMNotificationClient* pThis, LPCWSTR pDeviceID) +HRESULT STDMETHODCALLTYPE ma_IMMNotificationClient_OnDeviceRemoved(ma_IMMNotificationClient* pThis, LPCWSTR pDeviceID) { #ifdef MA_DEBUG_OUTPUT printf("IMMNotificationClient_OnDeviceRemoved(pDeviceID=%S)\n", (pDeviceID != NULL) ? pDeviceID : L"(NULL)"); @@ -6516,45 +6516,45 @@ HRESULT STDMETHODCALLTYPE mal_IMMNotificationClient_OnDeviceRemoved(mal_IMMNotif return S_OK; } -HRESULT STDMETHODCALLTYPE mal_IMMNotificationClient_OnDefaultDeviceChanged(mal_IMMNotificationClient* pThis, mal_EDataFlow dataFlow, mal_ERole role, LPCWSTR pDefaultDeviceID) +HRESULT STDMETHODCALLTYPE ma_IMMNotificationClient_OnDefaultDeviceChanged(ma_IMMNotificationClient* pThis, ma_EDataFlow dataFlow, ma_ERole role, LPCWSTR pDefaultDeviceID) { #ifdef MA_DEBUG_OUTPUT printf("IMMNotificationClient_OnDefaultDeviceChanged(dataFlow=%d, role=%d, pDefaultDeviceID=%S)\n", dataFlow, role, (pDefaultDeviceID != NULL) ? pDefaultDeviceID : L"(NULL)"); #endif // We only ever use the eConsole role in miniaudio. - if (role != mal_eConsole) { + if (role != ma_eConsole) { return S_OK; } // We only care about devices with the same data flow and role as the current device. - if (pThis->pDevice->type == mal_device_type_playback && dataFlow != mal_eRender || - pThis->pDevice->type == mal_device_type_capture && dataFlow != mal_eCapture) { + if (pThis->pDevice->type == ma_device_type_playback && dataFlow != ma_eRender || + pThis->pDevice->type == ma_device_type_capture && dataFlow != ma_eCapture) { return S_OK; } // Not currently supporting automatic stream routing in exclusive mode. This is not working correctly on my machine due to // AUDCLNT_E_DEVICE_IN_USE errors when reinitializing the device. If this is a bug in miniaudio, we can try re-enabling this once // it's fixed. - if (dataFlow == mal_eRender && pThis->pDevice->playback.shareMode == mal_share_mode_exclusive || - dataFlow == mal_eCapture && pThis->pDevice->capture.shareMode == mal_share_mode_exclusive) { + if (dataFlow == ma_eRender && pThis->pDevice->playback.shareMode == ma_share_mode_exclusive || + dataFlow == ma_eCapture && pThis->pDevice->capture.shareMode == ma_share_mode_exclusive) { return S_OK; } // We don't change the device here - we change it in the worker thread to keep synchronization simple. To do this I'm just setting a flag to // indicate that the default device has changed. - if (dataFlow == mal_eRender) { - mal_atomic_exchange_32(&pThis->pDevice->wasapi.hasDefaultPlaybackDeviceChanged, MA_TRUE); + if (dataFlow == ma_eRender) { + ma_atomic_exchange_32(&pThis->pDevice->wasapi.hasDefaultPlaybackDeviceChanged, MA_TRUE); } - if (dataFlow == mal_eCapture) { - mal_atomic_exchange_32(&pThis->pDevice->wasapi.hasDefaultCaptureDeviceChanged, MA_TRUE); + if (dataFlow == ma_eCapture) { + ma_atomic_exchange_32(&pThis->pDevice->wasapi.hasDefaultCaptureDeviceChanged, MA_TRUE); } (void)pDefaultDeviceID; return S_OK; } -HRESULT STDMETHODCALLTYPE mal_IMMNotificationClient_OnPropertyValueChanged(mal_IMMNotificationClient* pThis, LPCWSTR pDeviceID, const PROPERTYKEY key) +HRESULT STDMETHODCALLTYPE ma_IMMNotificationClient_OnPropertyValueChanged(ma_IMMNotificationClient* pThis, LPCWSTR pDeviceID, const PROPERTYKEY key) { #ifdef MA_DEBUG_OUTPUT printf("IMMNotificationClient_OnPropertyValueChanged(pDeviceID=%S)\n", (pDeviceID != NULL) ? pDeviceID : L"(NULL)"); @@ -6566,130 +6566,130 @@ HRESULT STDMETHODCALLTYPE mal_IMMNotificationClient_OnPropertyValueChanged(mal_I return S_OK; } -static mal_IMMNotificationClientVtbl g_malNotificationCientVtbl = { - mal_IMMNotificationClient_QueryInterface, - mal_IMMNotificationClient_AddRef, - mal_IMMNotificationClient_Release, - mal_IMMNotificationClient_OnDeviceStateChanged, - mal_IMMNotificationClient_OnDeviceAdded, - mal_IMMNotificationClient_OnDeviceRemoved, - mal_IMMNotificationClient_OnDefaultDeviceChanged, - mal_IMMNotificationClient_OnPropertyValueChanged +static ma_IMMNotificationClientVtbl g_malNotificationCientVtbl = { + ma_IMMNotificationClient_QueryInterface, + ma_IMMNotificationClient_AddRef, + ma_IMMNotificationClient_Release, + ma_IMMNotificationClient_OnDeviceStateChanged, + ma_IMMNotificationClient_OnDeviceAdded, + ma_IMMNotificationClient_OnDeviceRemoved, + ma_IMMNotificationClient_OnDefaultDeviceChanged, + ma_IMMNotificationClient_OnPropertyValueChanged }; #endif // MA_WIN32_DESKTOP #ifdef MA_WIN32_DESKTOP -typedef mal_IMMDevice mal_WASAPIDeviceInterface; +typedef ma_IMMDevice ma_WASAPIDeviceInterface; #else -typedef mal_IUnknown mal_WASAPIDeviceInterface; +typedef ma_IUnknown ma_WASAPIDeviceInterface; #endif -mal_bool32 mal_context_is_device_id_equal__wasapi(mal_context* pContext, const mal_device_id* pID0, const mal_device_id* pID1) +ma_bool32 ma_context_is_device_id_equal__wasapi(ma_context* pContext, const ma_device_id* pID0, const ma_device_id* pID1) { - mal_assert(pContext != NULL); - mal_assert(pID0 != NULL); - mal_assert(pID1 != NULL); + ma_assert(pContext != NULL); + ma_assert(pID0 != NULL); + ma_assert(pID1 != NULL); (void)pContext; return memcmp(pID0->wasapi, pID1->wasapi, sizeof(pID0->wasapi)) == 0; } -void mal_set_device_info_from_WAVEFORMATEX(const WAVEFORMATEX* pWF, mal_device_info* pInfo) +void ma_set_device_info_from_WAVEFORMATEX(const WAVEFORMATEX* pWF, ma_device_info* pInfo) { - mal_assert(pWF != NULL); - mal_assert(pInfo != NULL); + ma_assert(pWF != NULL); + ma_assert(pInfo != NULL); pInfo->formatCount = 1; - pInfo->formats[0] = mal_format_from_WAVEFORMATEX(pWF); + pInfo->formats[0] = ma_format_from_WAVEFORMATEX(pWF); pInfo->minChannels = pWF->nChannels; pInfo->maxChannels = pWF->nChannels; pInfo->minSampleRate = pWF->nSamplesPerSec; pInfo->maxSampleRate = pWF->nSamplesPerSec; } -mal_result mal_context_get_device_info_from_IAudioClient__wasapi(mal_context* pContext, /*mal_IMMDevice**/void* pMMDevice, mal_IAudioClient* pAudioClient, mal_share_mode shareMode, mal_device_info* pInfo) +ma_result ma_context_get_device_info_from_IAudioClient__wasapi(ma_context* pContext, /*ma_IMMDevice**/void* pMMDevice, ma_IAudioClient* pAudioClient, ma_share_mode shareMode, ma_device_info* pInfo) { - mal_assert(pAudioClient != NULL); - mal_assert(pInfo != NULL); + ma_assert(pAudioClient != NULL); + ma_assert(pInfo != NULL); // We use a different technique to retrieve the device information depending on whether or not we are using shared or exclusive mode. - if (shareMode == mal_share_mode_shared) { + if (shareMode == ma_share_mode_shared) { // Shared Mode. We use GetMixFormat() here. WAVEFORMATEX* pWF = NULL; - HRESULT hr = mal_IAudioClient_GetMixFormat((mal_IAudioClient*)pAudioClient, (WAVEFORMATEX**)&pWF); + HRESULT hr = ma_IAudioClient_GetMixFormat((ma_IAudioClient*)pAudioClient, (WAVEFORMATEX**)&pWF); if (SUCCEEDED(hr)) { - mal_set_device_info_from_WAVEFORMATEX(pWF, pInfo); + ma_set_device_info_from_WAVEFORMATEX(pWF, pInfo); return MA_SUCCESS; } else { - return mal_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to retrieve mix format for device info retrieval.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + return ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to retrieve mix format for device info retrieval.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } } else { // Exlcusive Mode. We repeatedly call IsFormatSupported() here. This is not currently support on UWP. #ifdef MA_WIN32_DESKTOP // The first thing to do is get the format from PKEY_AudioEngine_DeviceFormat. This should give us a channel count we assume is // correct which will simplify our searching. - mal_IPropertyStore *pProperties; - HRESULT hr = mal_IMMDevice_OpenPropertyStore((mal_IMMDevice*)pMMDevice, STGM_READ, &pProperties); + ma_IPropertyStore *pProperties; + HRESULT hr = ma_IMMDevice_OpenPropertyStore((ma_IMMDevice*)pMMDevice, STGM_READ, &pProperties); if (SUCCEEDED(hr)) { PROPVARIANT var; - mal_PropVariantInit(&var); + ma_PropVariantInit(&var); - hr = mal_IPropertyStore_GetValue(pProperties, &MA_PKEY_AudioEngine_DeviceFormat, &var); + hr = ma_IPropertyStore_GetValue(pProperties, &MA_PKEY_AudioEngine_DeviceFormat, &var); if (SUCCEEDED(hr)) { WAVEFORMATEX* pWF = (WAVEFORMATEX*)var.blob.pBlobData; - mal_set_device_info_from_WAVEFORMATEX(pWF, pInfo); + ma_set_device_info_from_WAVEFORMATEX(pWF, pInfo); // In my testing, the format returned by PKEY_AudioEngine_DeviceFormat is suitable for exclusive mode so we check this format // first. If this fails, fall back to a search. - hr = mal_IAudioClient_IsFormatSupported((mal_IAudioClient*)pAudioClient, MA_AUDCLNT_SHAREMODE_EXCLUSIVE, pWF, NULL); - mal_PropVariantClear(pContext, &var); + hr = ma_IAudioClient_IsFormatSupported((ma_IAudioClient*)pAudioClient, MA_AUDCLNT_SHAREMODE_EXCLUSIVE, pWF, NULL); + ma_PropVariantClear(pContext, &var); if (FAILED(hr)) { // The format returned by PKEY_AudioEngine_DeviceFormat is not supported, so fall back to a search. We assume the channel // count returned by MA_PKEY_AudioEngine_DeviceFormat is valid and correct. For simplicity we're only returning one format. - mal_uint32 channels = pInfo->minChannels; + ma_uint32 channels = pInfo->minChannels; - mal_format formatsToSearch[] = { - mal_format_s16, - mal_format_s24, - //mal_format_s24_32, - mal_format_f32, - mal_format_s32, - mal_format_u8 + ma_format formatsToSearch[] = { + ma_format_s16, + ma_format_s24, + //ma_format_s24_32, + ma_format_f32, + ma_format_s32, + ma_format_u8 }; - mal_channel defaultChannelMap[MA_MAX_CHANNELS]; - mal_get_standard_channel_map(mal_standard_channel_map_microsoft, channels, defaultChannelMap); + ma_channel defaultChannelMap[MA_MAX_CHANNELS]; + ma_get_standard_channel_map(ma_standard_channel_map_microsoft, channels, defaultChannelMap); WAVEFORMATEXTENSIBLE wf; - mal_zero_object(&wf); + ma_zero_object(&wf); wf.Format.cbSize = sizeof(wf); wf.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE; wf.Format.nChannels = (WORD)channels; - wf.dwChannelMask = mal_channel_map_to_channel_mask__win32(defaultChannelMap, channels); + wf.dwChannelMask = ma_channel_map_to_channel_mask__win32(defaultChannelMap, channels); - mal_bool32 found = MA_FALSE; - for (mal_uint32 iFormat = 0; iFormat < mal_countof(formatsToSearch); ++iFormat) { - mal_format format = formatsToSearch[iFormat]; + ma_bool32 found = MA_FALSE; + for (ma_uint32 iFormat = 0; iFormat < ma_countof(formatsToSearch); ++iFormat) { + ma_format format = formatsToSearch[iFormat]; - wf.Format.wBitsPerSample = (WORD)mal_get_bytes_per_sample(format)*8; + wf.Format.wBitsPerSample = (WORD)ma_get_bytes_per_sample(format)*8; wf.Format.nBlockAlign = (wf.Format.nChannels * wf.Format.wBitsPerSample) / 8; wf.Format.nAvgBytesPerSec = wf.Format.nBlockAlign * wf.Format.nSamplesPerSec; - wf.Samples.wValidBitsPerSample = /*(format == mal_format_s24_32) ? 24 :*/ wf.Format.wBitsPerSample; - if (format == mal_format_f32) { + wf.Samples.wValidBitsPerSample = /*(format == ma_format_s24_32) ? 24 :*/ wf.Format.wBitsPerSample; + if (format == ma_format_f32) { wf.SubFormat = MA_GUID_KSDATAFORMAT_SUBTYPE_IEEE_FLOAT; } else { wf.SubFormat = MA_GUID_KSDATAFORMAT_SUBTYPE_PCM; } - for (mal_uint32 iSampleRate = 0; iSampleRate < mal_countof(g_malStandardSampleRatePriorities); ++iSampleRate) { + for (ma_uint32 iSampleRate = 0; iSampleRate < ma_countof(g_malStandardSampleRatePriorities); ++iSampleRate) { wf.Format.nSamplesPerSec = g_malStandardSampleRatePriorities[iSampleRate]; - hr = mal_IAudioClient_IsFormatSupported((mal_IAudioClient*)pAudioClient, MA_AUDCLNT_SHAREMODE_EXCLUSIVE, (WAVEFORMATEX*)&wf, NULL); + hr = ma_IAudioClient_IsFormatSupported((ma_IAudioClient*)pAudioClient, MA_AUDCLNT_SHAREMODE_EXCLUSIVE, (WAVEFORMATEX*)&wf, NULL); if (SUCCEEDED(hr)) { - mal_set_device_info_from_WAVEFORMATEX((WAVEFORMATEX*)&wf, pInfo); + ma_set_device_info_from_WAVEFORMATEX((WAVEFORMATEX*)&wf, pInfo); found = MA_TRUE; break; } @@ -6701,16 +6701,16 @@ mal_result mal_context_get_device_info_from_IAudioClient__wasapi(mal_context* pC } if (!found) { - mal_IPropertyStore_Release(pProperties); - return mal_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to find suitable device format for device info retrieval.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + ma_IPropertyStore_Release(pProperties); + return ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to find suitable device format for device info retrieval.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } } } else { - mal_IPropertyStore_Release(pProperties); - return mal_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to retrieve device format for device info retrieval.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + ma_IPropertyStore_Release(pProperties); + return ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to retrieve device format for device info retrieval.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } } else { - return mal_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to open property store for device info retrieval.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + return ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to open property store for device info retrieval.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } return MA_SUCCESS; @@ -6722,112 +6722,112 @@ mal_result mal_context_get_device_info_from_IAudioClient__wasapi(mal_context* pC } #ifdef MA_WIN32_DESKTOP -mal_result mal_context_get_MMDevice__wasapi(mal_context* pContext, mal_device_type deviceType, const mal_device_id* pDeviceID, mal_IMMDevice** ppMMDevice) +ma_result ma_context_get_MMDevice__wasapi(ma_context* pContext, ma_device_type deviceType, const ma_device_id* pDeviceID, ma_IMMDevice** ppMMDevice) { - mal_assert(pContext != NULL); - mal_assert(ppMMDevice != NULL); + ma_assert(pContext != NULL); + ma_assert(ppMMDevice != NULL); - mal_IMMDeviceEnumerator* pDeviceEnumerator; - HRESULT hr = mal_CoCreateInstance(pContext, MA_CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, MA_IID_IMMDeviceEnumerator, (void**)&pDeviceEnumerator); + ma_IMMDeviceEnumerator* pDeviceEnumerator; + HRESULT hr = ma_CoCreateInstance(pContext, MA_CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, MA_IID_IMMDeviceEnumerator, (void**)&pDeviceEnumerator); if (FAILED(hr)) { - return mal_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to create IMMDeviceEnumerator.", MA_FAILED_TO_INIT_BACKEND); + return ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to create IMMDeviceEnumerator.", MA_FAILED_TO_INIT_BACKEND); } if (pDeviceID == NULL) { - hr = mal_IMMDeviceEnumerator_GetDefaultAudioEndpoint(pDeviceEnumerator, (deviceType == mal_device_type_playback) ? mal_eRender : mal_eCapture, mal_eConsole, ppMMDevice); + hr = ma_IMMDeviceEnumerator_GetDefaultAudioEndpoint(pDeviceEnumerator, (deviceType == ma_device_type_playback) ? ma_eRender : ma_eCapture, ma_eConsole, ppMMDevice); } else { - hr = mal_IMMDeviceEnumerator_GetDevice(pDeviceEnumerator, pDeviceID->wasapi, ppMMDevice); + hr = ma_IMMDeviceEnumerator_GetDevice(pDeviceEnumerator, pDeviceID->wasapi, ppMMDevice); } - mal_IMMDeviceEnumerator_Release(pDeviceEnumerator); + ma_IMMDeviceEnumerator_Release(pDeviceEnumerator); if (FAILED(hr)) { - return mal_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to retrieve IMMDevice.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + return ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to retrieve IMMDevice.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } return MA_SUCCESS; } -mal_result mal_context_get_device_info_from_MMDevice__wasapi(mal_context* pContext, mal_IMMDevice* pMMDevice, mal_share_mode shareMode, mal_bool32 onlySimpleInfo, mal_device_info* pInfo) +ma_result ma_context_get_device_info_from_MMDevice__wasapi(ma_context* pContext, ma_IMMDevice* pMMDevice, ma_share_mode shareMode, ma_bool32 onlySimpleInfo, ma_device_info* pInfo) { - mal_assert(pContext != NULL); - mal_assert(pMMDevice != NULL); - mal_assert(pInfo != NULL); + ma_assert(pContext != NULL); + ma_assert(pMMDevice != NULL); + ma_assert(pInfo != NULL); // ID. LPWSTR id; - HRESULT hr = mal_IMMDevice_GetId(pMMDevice, &id); + HRESULT hr = ma_IMMDevice_GetId(pMMDevice, &id); if (SUCCEEDED(hr)) { size_t idlen = wcslen(id); - if (idlen+1 > mal_countof(pInfo->id.wasapi)) { - mal_CoTaskMemFree(pContext, id); - mal_assert(MA_FALSE); // NOTE: If this is triggered, please report it. It means the format of the ID must haved change and is too long to fit in our fixed sized buffer. + if (idlen+1 > ma_countof(pInfo->id.wasapi)) { + ma_CoTaskMemFree(pContext, id); + ma_assert(MA_FALSE); // NOTE: If this is triggered, please report it. It means the format of the ID must haved change and is too long to fit in our fixed sized buffer. return MA_ERROR; } - mal_copy_memory(pInfo->id.wasapi, id, idlen * sizeof(wchar_t)); + ma_copy_memory(pInfo->id.wasapi, id, idlen * sizeof(wchar_t)); pInfo->id.wasapi[idlen] = '\0'; - mal_CoTaskMemFree(pContext, id); + ma_CoTaskMemFree(pContext, id); } { - mal_IPropertyStore *pProperties; - hr = mal_IMMDevice_OpenPropertyStore(pMMDevice, STGM_READ, &pProperties); + ma_IPropertyStore *pProperties; + hr = ma_IMMDevice_OpenPropertyStore(pMMDevice, STGM_READ, &pProperties); if (SUCCEEDED(hr)) { PROPVARIANT var; // Description / Friendly Name - mal_PropVariantInit(&var); - hr = mal_IPropertyStore_GetValue(pProperties, &MA_PKEY_Device_FriendlyName, &var); + ma_PropVariantInit(&var); + hr = ma_IPropertyStore_GetValue(pProperties, &MA_PKEY_Device_FriendlyName, &var); if (SUCCEEDED(hr)) { WideCharToMultiByte(CP_UTF8, 0, var.pwszVal, -1, pInfo->name, sizeof(pInfo->name), 0, FALSE); - mal_PropVariantClear(pContext, &var); + ma_PropVariantClear(pContext, &var); } - mal_IPropertyStore_Release(pProperties); + ma_IPropertyStore_Release(pProperties); } } // Format if (!onlySimpleInfo) { - mal_IAudioClient* pAudioClient; - hr = mal_IMMDevice_Activate(pMMDevice, &MA_IID_IAudioClient, CLSCTX_ALL, NULL, (void**)&pAudioClient); + ma_IAudioClient* pAudioClient; + hr = ma_IMMDevice_Activate(pMMDevice, &MA_IID_IAudioClient, CLSCTX_ALL, NULL, (void**)&pAudioClient); if (SUCCEEDED(hr)) { - mal_result result = mal_context_get_device_info_from_IAudioClient__wasapi(pContext, pMMDevice, pAudioClient, shareMode, pInfo); + ma_result result = ma_context_get_device_info_from_IAudioClient__wasapi(pContext, pMMDevice, pAudioClient, shareMode, pInfo); - mal_IAudioClient_Release(pAudioClient); + ma_IAudioClient_Release(pAudioClient); return result; } else { - return mal_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to activate audio client for device info retrieval.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + return ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to activate audio client for device info retrieval.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } } return MA_SUCCESS; } -mal_result mal_context_enumerate_device_collection__wasapi(mal_context* pContext, mal_IMMDeviceCollection* pDeviceCollection, mal_device_type deviceType, mal_enum_devices_callback_proc callback, void* pUserData) +ma_result ma_context_enumerate_device_collection__wasapi(ma_context* pContext, ma_IMMDeviceCollection* pDeviceCollection, ma_device_type deviceType, ma_enum_devices_callback_proc callback, void* pUserData) { - mal_assert(pContext != NULL); - mal_assert(callback != NULL); + ma_assert(pContext != NULL); + ma_assert(callback != NULL); UINT deviceCount; - HRESULT hr = mal_IMMDeviceCollection_GetCount(pDeviceCollection, &deviceCount); + HRESULT hr = ma_IMMDeviceCollection_GetCount(pDeviceCollection, &deviceCount); if (FAILED(hr)) { - return mal_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to get playback device count.", MA_NO_DEVICE); + return ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to get playback device count.", MA_NO_DEVICE); } - for (mal_uint32 iDevice = 0; iDevice < deviceCount; ++iDevice) { - mal_device_info deviceInfo; - mal_zero_object(&deviceInfo); + for (ma_uint32 iDevice = 0; iDevice < deviceCount; ++iDevice) { + ma_device_info deviceInfo; + ma_zero_object(&deviceInfo); - mal_IMMDevice* pMMDevice; - hr = mal_IMMDeviceCollection_Item(pDeviceCollection, iDevice, &pMMDevice); + ma_IMMDevice* pMMDevice; + hr = ma_IMMDeviceCollection_Item(pDeviceCollection, iDevice, &pMMDevice); if (SUCCEEDED(hr)) { - mal_result result = mal_context_get_device_info_from_MMDevice__wasapi(pContext, pMMDevice, mal_share_mode_shared, MA_TRUE, &deviceInfo); // MA_TRUE = onlySimpleInfo. + ma_result result = ma_context_get_device_info_from_MMDevice__wasapi(pContext, pMMDevice, ma_share_mode_shared, MA_TRUE, &deviceInfo); // MA_TRUE = onlySimpleInfo. - mal_IMMDevice_Release(pMMDevice); + ma_IMMDevice_Release(pMMDevice); if (result == MA_SUCCESS) { - mal_bool32 cbResult = callback(pContext, deviceType, &deviceInfo, pUserData); + ma_bool32 cbResult = callback(pContext, deviceType, &deviceInfo, pUserData); if (cbResult == MA_FALSE) { break; } @@ -6840,21 +6840,21 @@ mal_result mal_context_enumerate_device_collection__wasapi(mal_context* pContext #endif #ifdef MA_WIN32_DESKTOP -mal_result mal_context_get_IAudioClient_Desktop__wasapi(mal_context* pContext, mal_device_type deviceType, const mal_device_id* pDeviceID, mal_IAudioClient** ppAudioClient, mal_IMMDevice** ppMMDevice) +ma_result ma_context_get_IAudioClient_Desktop__wasapi(ma_context* pContext, ma_device_type deviceType, const ma_device_id* pDeviceID, ma_IAudioClient** ppAudioClient, ma_IMMDevice** ppMMDevice) { - mal_result result; + ma_result result; HRESULT hr; - mal_assert(pContext != NULL); - mal_assert(ppAudioClient != NULL); - mal_assert(ppMMDevice != NULL); + ma_assert(pContext != NULL); + ma_assert(ppAudioClient != NULL); + ma_assert(ppMMDevice != NULL); - result = mal_context_get_MMDevice__wasapi(pContext, deviceType, pDeviceID, ppMMDevice); + result = ma_context_get_MMDevice__wasapi(pContext, deviceType, pDeviceID, ppMMDevice); if (result != MA_SUCCESS) { return result; } - hr = mal_IMMDevice_Activate(*ppMMDevice, &MA_IID_IAudioClient, CLSCTX_ALL, NULL, (void**)ppAudioClient); + hr = ma_IMMDevice_Activate(*ppMMDevice, &MA_IID_IAudioClient, CLSCTX_ALL, NULL, (void**)ppAudioClient); if (FAILED(hr)) { return MA_FAILED_TO_OPEN_BACKEND_DEVICE; } @@ -6862,19 +6862,19 @@ mal_result mal_context_get_IAudioClient_Desktop__wasapi(mal_context* pContext, m return MA_SUCCESS; } #else -mal_result mal_context_get_IAudioClient_UWP__wasapi(mal_context* pContext, mal_device_type deviceType, const mal_device_id* pDeviceID, mal_IAudioClient** ppAudioClient, mal_IUnknown** ppActivatedInterface) +ma_result ma_context_get_IAudioClient_UWP__wasapi(ma_context* pContext, ma_device_type deviceType, const ma_device_id* pDeviceID, ma_IAudioClient** ppAudioClient, ma_IUnknown** ppActivatedInterface) { - mal_assert(pContext != NULL); - mal_assert(ppAudioClient != NULL); + ma_assert(pContext != NULL); + ma_assert(ppAudioClient != NULL); - mal_IActivateAudioInterfaceAsyncOperation *pAsyncOp = NULL; - mal_completion_handler_uwp completionHandler; + ma_IActivateAudioInterfaceAsyncOperation *pAsyncOp = NULL; + ma_completion_handler_uwp completionHandler; IID iid; if (pDeviceID != NULL) { - mal_copy_memory(&iid, pDeviceID->wasapi, sizeof(iid)); + ma_copy_memory(&iid, pDeviceID->wasapi, sizeof(iid)); } else { - if (deviceType == mal_device_type_playback) { + if (deviceType == ma_device_type_playback) { iid = MA_IID_DEVINTERFACE_AUDIO_RENDER; } else { iid = MA_IID_DEVINTERFACE_AUDIO_CAPTURE; @@ -6888,13 +6888,13 @@ mal_result mal_context_get_IAudioClient_UWP__wasapi(mal_context* pContext, mal_d HRESULT hr = StringFromIID(&iid, &iidStr); #endif if (FAILED(hr)) { - return mal_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to convert device IID to string for ActivateAudioInterfaceAsync(). Out of memory.", MA_OUT_OF_MEMORY); + return ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to convert device IID to string for ActivateAudioInterfaceAsync(). Out of memory.", MA_OUT_OF_MEMORY); } - mal_result result = mal_completion_handler_uwp_init(&completionHandler); + ma_result result = ma_completion_handler_uwp_init(&completionHandler); if (result != MA_SUCCESS) { - mal_CoTaskMemFree(pContext, iidStr); - return mal_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to create event for waiting for ActivateAudioInterfaceAsync().", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + ma_CoTaskMemFree(pContext, iidStr); + return ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to create event for waiting for ActivateAudioInterfaceAsync().", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } #if defined(__cplusplus) @@ -6903,83 +6903,83 @@ mal_result mal_context_get_IAudioClient_UWP__wasapi(mal_context* pContext, mal_d hr = ActivateAudioInterfaceAsync(iidStr, &MA_IID_IAudioClient, NULL, (IActivateAudioInterfaceCompletionHandler*)&completionHandler, (IActivateAudioInterfaceAsyncOperation**)&pAsyncOp); #endif if (FAILED(hr)) { - mal_completion_handler_uwp_uninit(&completionHandler); - mal_CoTaskMemFree(pContext, iidStr); - return mal_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[WASAPI] ActivateAudioInterfaceAsync() failed.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + ma_completion_handler_uwp_uninit(&completionHandler); + ma_CoTaskMemFree(pContext, iidStr); + return ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[WASAPI] ActivateAudioInterfaceAsync() failed.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } - mal_CoTaskMemFree(pContext, iidStr); + ma_CoTaskMemFree(pContext, iidStr); // Wait for the async operation for finish. - mal_completion_handler_uwp_wait(&completionHandler); - mal_completion_handler_uwp_uninit(&completionHandler); + ma_completion_handler_uwp_wait(&completionHandler); + ma_completion_handler_uwp_uninit(&completionHandler); HRESULT activateResult; - mal_IUnknown* pActivatedInterface; - hr = mal_IActivateAudioInterfaceAsyncOperation_GetActivateResult(pAsyncOp, &activateResult, &pActivatedInterface); - mal_IActivateAudioInterfaceAsyncOperation_Release(pAsyncOp); + ma_IUnknown* pActivatedInterface; + hr = ma_IActivateAudioInterfaceAsyncOperation_GetActivateResult(pAsyncOp, &activateResult, &pActivatedInterface); + ma_IActivateAudioInterfaceAsyncOperation_Release(pAsyncOp); if (FAILED(hr) || FAILED(activateResult)) { - return mal_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to activate device.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + return ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to activate device.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } // Here is where we grab the IAudioClient interface. - hr = mal_IUnknown_QueryInterface(pActivatedInterface, &MA_IID_IAudioClient, (void**)ppAudioClient); + hr = ma_IUnknown_QueryInterface(pActivatedInterface, &MA_IID_IAudioClient, (void**)ppAudioClient); if (FAILED(hr)) { - return mal_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to query IAudioClient interface.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + return ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to query IAudioClient interface.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } if (ppActivatedInterface) { *ppActivatedInterface = pActivatedInterface; } else { - mal_IUnknown_Release(pActivatedInterface); + ma_IUnknown_Release(pActivatedInterface); } return MA_SUCCESS; } #endif -mal_result mal_context_get_IAudioClient__wasapi(mal_context* pContext, mal_device_type deviceType, const mal_device_id* pDeviceID, mal_IAudioClient** ppAudioClient, mal_WASAPIDeviceInterface** ppDeviceInterface) +ma_result ma_context_get_IAudioClient__wasapi(ma_context* pContext, ma_device_type deviceType, const ma_device_id* pDeviceID, ma_IAudioClient** ppAudioClient, ma_WASAPIDeviceInterface** ppDeviceInterface) { #ifdef MA_WIN32_DESKTOP - return mal_context_get_IAudioClient_Desktop__wasapi(pContext, deviceType, pDeviceID, ppAudioClient, ppDeviceInterface); + return ma_context_get_IAudioClient_Desktop__wasapi(pContext, deviceType, pDeviceID, ppAudioClient, ppDeviceInterface); #else - return mal_context_get_IAudioClient_UWP__wasapi(pContext, deviceType, pDeviceID, ppAudioClient, ppDeviceInterface); + return ma_context_get_IAudioClient_UWP__wasapi(pContext, deviceType, pDeviceID, ppAudioClient, ppDeviceInterface); #endif } -mal_result mal_context_enumerate_devices__wasapi(mal_context* pContext, mal_enum_devices_callback_proc callback, void* pUserData) +ma_result ma_context_enumerate_devices__wasapi(ma_context* pContext, ma_enum_devices_callback_proc callback, void* pUserData) { - mal_assert(pContext != NULL); - mal_assert(callback != NULL); + ma_assert(pContext != NULL); + ma_assert(callback != NULL); // Different enumeration for desktop and UWP. #ifdef MA_WIN32_DESKTOP // Desktop - mal_IMMDeviceEnumerator* pDeviceEnumerator; - HRESULT hr = mal_CoCreateInstance(pContext, MA_CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, MA_IID_IMMDeviceEnumerator, (void**)&pDeviceEnumerator); + ma_IMMDeviceEnumerator* pDeviceEnumerator; + HRESULT hr = ma_CoCreateInstance(pContext, MA_CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, MA_IID_IMMDeviceEnumerator, (void**)&pDeviceEnumerator); if (FAILED(hr)) { - return mal_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to create device enumerator.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + return ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to create device enumerator.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } - mal_IMMDeviceCollection* pDeviceCollection; + ma_IMMDeviceCollection* pDeviceCollection; // Playback. - hr = mal_IMMDeviceEnumerator_EnumAudioEndpoints(pDeviceEnumerator, mal_eRender, MA_MM_DEVICE_STATE_ACTIVE, &pDeviceCollection); + hr = ma_IMMDeviceEnumerator_EnumAudioEndpoints(pDeviceEnumerator, ma_eRender, MA_MM_DEVICE_STATE_ACTIVE, &pDeviceCollection); if (SUCCEEDED(hr)) { - mal_context_enumerate_device_collection__wasapi(pContext, pDeviceCollection, mal_device_type_playback, callback, pUserData); - mal_IMMDeviceCollection_Release(pDeviceCollection); + ma_context_enumerate_device_collection__wasapi(pContext, pDeviceCollection, ma_device_type_playback, callback, pUserData); + ma_IMMDeviceCollection_Release(pDeviceCollection); } // Capture. - hr = mal_IMMDeviceEnumerator_EnumAudioEndpoints(pDeviceEnumerator, mal_eCapture, MA_MM_DEVICE_STATE_ACTIVE, &pDeviceCollection); + hr = ma_IMMDeviceEnumerator_EnumAudioEndpoints(pDeviceEnumerator, ma_eCapture, MA_MM_DEVICE_STATE_ACTIVE, &pDeviceCollection); if (SUCCEEDED(hr)) { - mal_context_enumerate_device_collection__wasapi(pContext, pDeviceCollection, mal_device_type_capture, callback, pUserData); - mal_IMMDeviceCollection_Release(pDeviceCollection); + ma_context_enumerate_device_collection__wasapi(pContext, pDeviceCollection, ma_device_type_capture, callback, pUserData); + ma_IMMDeviceCollection_Release(pDeviceCollection); } - mal_IMMDeviceEnumerator_Release(pDeviceEnumerator); + ma_IMMDeviceEnumerator_Release(pDeviceEnumerator); #else // UWP // @@ -6988,22 +6988,22 @@ mal_result mal_context_enumerate_devices__wasapi(mal_context* pContext, mal_enum // // Hint: DeviceInformation::FindAllAsync() with DeviceClass.AudioCapture/AudioRender. https://blogs.windows.com/buildingapps/2014/05/15/real-time-audio-in-windows-store-and-windows-phone-apps/ if (callback) { - mal_bool32 cbResult = MA_TRUE; + ma_bool32 cbResult = MA_TRUE; // Playback. if (cbResult) { - mal_device_info deviceInfo; - mal_zero_object(&deviceInfo); - mal_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), MA_DEFAULT_PLAYBACK_DEVICE_NAME, (size_t)-1); - cbResult = callback(pContext, mal_device_type_playback, &deviceInfo, pUserData); + ma_device_info deviceInfo; + ma_zero_object(&deviceInfo); + ma_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), MA_DEFAULT_PLAYBACK_DEVICE_NAME, (size_t)-1); + cbResult = callback(pContext, ma_device_type_playback, &deviceInfo, pUserData); } // Capture. if (cbResult) { - mal_device_info deviceInfo; - mal_zero_object(&deviceInfo); - mal_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), MA_DEFAULT_CAPTURE_DEVICE_NAME, (size_t)-1); - cbResult = callback(pContext, mal_device_type_capture, &deviceInfo, pUserData); + ma_device_info deviceInfo; + ma_zero_object(&deviceInfo); + ma_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), MA_DEFAULT_CAPTURE_DEVICE_NAME, (size_t)-1); + cbResult = callback(pContext, ma_device_type_capture, &deviceInfo, pUserData); } } #endif @@ -7011,68 +7011,68 @@ mal_result mal_context_enumerate_devices__wasapi(mal_context* pContext, mal_enum return MA_SUCCESS; } -mal_result mal_context_get_device_info__wasapi(mal_context* pContext, mal_device_type deviceType, const mal_device_id* pDeviceID, mal_share_mode shareMode, mal_device_info* pDeviceInfo) +ma_result ma_context_get_device_info__wasapi(ma_context* pContext, ma_device_type deviceType, const ma_device_id* pDeviceID, ma_share_mode shareMode, ma_device_info* pDeviceInfo) { #ifdef MA_WIN32_DESKTOP - mal_IMMDevice* pMMDevice = NULL; - mal_result result = mal_context_get_MMDevice__wasapi(pContext, deviceType, pDeviceID, &pMMDevice); + ma_IMMDevice* pMMDevice = NULL; + ma_result result = ma_context_get_MMDevice__wasapi(pContext, deviceType, pDeviceID, &pMMDevice); if (result != MA_SUCCESS) { return result; } - result = mal_context_get_device_info_from_MMDevice__wasapi(pContext, pMMDevice, shareMode, MA_FALSE, pDeviceInfo); // MA_FALSE = !onlySimpleInfo. + result = ma_context_get_device_info_from_MMDevice__wasapi(pContext, pMMDevice, shareMode, MA_FALSE, pDeviceInfo); // MA_FALSE = !onlySimpleInfo. - mal_IMMDevice_Release(pMMDevice); + ma_IMMDevice_Release(pMMDevice); return result; #else // UWP currently only uses default devices. - if (deviceType == mal_device_type_playback) { - mal_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), MA_DEFAULT_PLAYBACK_DEVICE_NAME, (size_t)-1); + if (deviceType == ma_device_type_playback) { + ma_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), MA_DEFAULT_PLAYBACK_DEVICE_NAME, (size_t)-1); } else { - mal_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), MA_DEFAULT_CAPTURE_DEVICE_NAME, (size_t)-1); + ma_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), MA_DEFAULT_CAPTURE_DEVICE_NAME, (size_t)-1); } // Not currently supporting exclusive mode on UWP. - if (shareMode == mal_share_mode_exclusive) { + if (shareMode == ma_share_mode_exclusive) { return MA_ERROR; } - mal_IAudioClient* pAudioClient; - mal_result result = mal_context_get_IAudioClient_UWP__wasapi(pContext, deviceType, pDeviceID, &pAudioClient, NULL); + ma_IAudioClient* pAudioClient; + ma_result result = ma_context_get_IAudioClient_UWP__wasapi(pContext, deviceType, pDeviceID, &pAudioClient, NULL); if (result != MA_SUCCESS) { return result; } - result = mal_context_get_device_info_from_IAudioClient__wasapi(pContext, NULL, pAudioClient, shareMode, pDeviceInfo); + result = ma_context_get_device_info_from_IAudioClient__wasapi(pContext, NULL, pAudioClient, shareMode, pDeviceInfo); - mal_IAudioClient_Release(pAudioClient); + ma_IAudioClient_Release(pAudioClient); return result; #endif } -void mal_device_uninit__wasapi(mal_device* pDevice) +void ma_device_uninit__wasapi(ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); #ifdef MA_WIN32_DESKTOP if (pDevice->wasapi.pDeviceEnumerator) { - ((mal_IMMDeviceEnumerator*)pDevice->wasapi.pDeviceEnumerator)->lpVtbl->UnregisterEndpointNotificationCallback((mal_IMMDeviceEnumerator*)pDevice->wasapi.pDeviceEnumerator, &pDevice->wasapi.notificationClient); - mal_IMMDeviceEnumerator_Release((mal_IMMDeviceEnumerator*)pDevice->wasapi.pDeviceEnumerator); + ((ma_IMMDeviceEnumerator*)pDevice->wasapi.pDeviceEnumerator)->lpVtbl->UnregisterEndpointNotificationCallback((ma_IMMDeviceEnumerator*)pDevice->wasapi.pDeviceEnumerator, &pDevice->wasapi.notificationClient); + ma_IMMDeviceEnumerator_Release((ma_IMMDeviceEnumerator*)pDevice->wasapi.pDeviceEnumerator); } #endif if (pDevice->wasapi.pRenderClient) { - mal_IAudioRenderClient_Release((mal_IAudioRenderClient*)pDevice->wasapi.pRenderClient); + ma_IAudioRenderClient_Release((ma_IAudioRenderClient*)pDevice->wasapi.pRenderClient); } if (pDevice->wasapi.pCaptureClient) { - mal_IAudioCaptureClient_Release((mal_IAudioCaptureClient*)pDevice->wasapi.pCaptureClient); + ma_IAudioCaptureClient_Release((ma_IAudioCaptureClient*)pDevice->wasapi.pCaptureClient); } if (pDevice->wasapi.pAudioClientPlayback) { - mal_IAudioClient_Release((mal_IAudioClient*)pDevice->wasapi.pAudioClientPlayback); + ma_IAudioClient_Release((ma_IAudioClient*)pDevice->wasapi.pAudioClientPlayback); } if (pDevice->wasapi.pAudioClientCapture) { - mal_IAudioClient_Release((mal_IAudioClient*)pDevice->wasapi.pAudioClientCapture); + ma_IAudioClient_Release((ma_IAudioClient*)pDevice->wasapi.pAudioClientCapture); } if (pDevice->wasapi.hEventPlayback) { @@ -7087,42 +7087,42 @@ void mal_device_uninit__wasapi(mal_device* pDevice) typedef struct { // Input. - mal_format formatIn; - mal_uint32 channelsIn; - mal_uint32 sampleRateIn; - mal_channel channelMapIn[MA_MAX_CHANNELS]; - mal_uint32 bufferSizeInFramesIn; - mal_uint32 bufferSizeInMillisecondsIn; - mal_uint32 periodsIn; - mal_bool32 usingDefaultFormat; - mal_bool32 usingDefaultChannels; - mal_bool32 usingDefaultSampleRate; - mal_bool32 usingDefaultChannelMap; - mal_share_mode shareMode; + ma_format formatIn; + ma_uint32 channelsIn; + ma_uint32 sampleRateIn; + ma_channel channelMapIn[MA_MAX_CHANNELS]; + ma_uint32 bufferSizeInFramesIn; + ma_uint32 bufferSizeInMillisecondsIn; + ma_uint32 periodsIn; + ma_bool32 usingDefaultFormat; + ma_bool32 usingDefaultChannels; + ma_bool32 usingDefaultSampleRate; + ma_bool32 usingDefaultChannelMap; + ma_share_mode shareMode; // Output. - mal_IAudioClient* pAudioClient; - mal_IAudioRenderClient* pRenderClient; - mal_IAudioCaptureClient* pCaptureClient; - mal_format formatOut; - mal_uint32 channelsOut; - mal_uint32 sampleRateOut; - mal_channel channelMapOut[MA_MAX_CHANNELS]; - mal_uint32 bufferSizeInFramesOut; - mal_uint32 periodSizeInFramesOut; - mal_uint32 periodsOut; + ma_IAudioClient* pAudioClient; + ma_IAudioRenderClient* pRenderClient; + ma_IAudioCaptureClient* pCaptureClient; + ma_format formatOut; + ma_uint32 channelsOut; + ma_uint32 sampleRateOut; + ma_channel channelMapOut[MA_MAX_CHANNELS]; + ma_uint32 bufferSizeInFramesOut; + ma_uint32 periodSizeInFramesOut; + ma_uint32 periodsOut; char deviceName[256]; -} mal_device_init_internal_data__wasapi; +} ma_device_init_internal_data__wasapi; -mal_result mal_device_init_internal__wasapi(mal_context* pContext, mal_device_type deviceType, const mal_device_id* pDeviceID, mal_device_init_internal_data__wasapi* pData) +ma_result ma_device_init_internal__wasapi(ma_context* pContext, ma_device_type deviceType, const ma_device_id* pDeviceID, ma_device_init_internal_data__wasapi* pData) { (void)pContext; - mal_assert(pContext != NULL); - mal_assert(pData != NULL); + ma_assert(pContext != NULL); + ma_assert(pData != NULL); /* This function is only used to initialize one device type: either playback or capture. Never full-duplex. */ - if (deviceType == mal_device_type_duplex) { + if (deviceType == ma_device_type_duplex) { return MA_INVALID_ARGS; } @@ -7132,59 +7132,59 @@ mal_result mal_device_init_internal__wasapi(mal_context* pContext, mal_device_ty HRESULT hr; - mal_result result = MA_SUCCESS; + ma_result result = MA_SUCCESS; const char* errorMsg = ""; MA_AUDCLNT_SHAREMODE shareMode = MA_AUDCLNT_SHAREMODE_SHARED; MA_REFERENCE_TIME bufferDurationInMicroseconds; - mal_bool32 wasInitializedUsingIAudioClient3 = MA_FALSE; + ma_bool32 wasInitializedUsingIAudioClient3 = MA_FALSE; WAVEFORMATEXTENSIBLE wf; - mal_WASAPIDeviceInterface* pDeviceInterface = NULL; + ma_WASAPIDeviceInterface* pDeviceInterface = NULL; - result = mal_context_get_IAudioClient__wasapi(pContext, deviceType, pDeviceID, &pData->pAudioClient, &pDeviceInterface); + result = ma_context_get_IAudioClient__wasapi(pContext, deviceType, pDeviceID, &pData->pAudioClient, &pDeviceInterface); if (result != MA_SUCCESS) { goto done; } // Try enabling hardware offloading. - mal_IAudioClient2* pAudioClient2; - hr = mal_IAudioClient_QueryInterface(pData->pAudioClient, &MA_IID_IAudioClient2, (void**)&pAudioClient2); + ma_IAudioClient2* pAudioClient2; + hr = ma_IAudioClient_QueryInterface(pData->pAudioClient, &MA_IID_IAudioClient2, (void**)&pAudioClient2); if (SUCCEEDED(hr)) { BOOL isHardwareOffloadingSupported = 0; - hr = mal_IAudioClient2_IsOffloadCapable(pAudioClient2, MA_AudioCategory_Other, &isHardwareOffloadingSupported); + hr = ma_IAudioClient2_IsOffloadCapable(pAudioClient2, MA_AudioCategory_Other, &isHardwareOffloadingSupported); if (SUCCEEDED(hr) && isHardwareOffloadingSupported) { - mal_AudioClientProperties clientProperties; - mal_zero_object(&clientProperties); + ma_AudioClientProperties clientProperties; + ma_zero_object(&clientProperties); clientProperties.cbSize = sizeof(clientProperties); clientProperties.bIsOffload = 1; clientProperties.eCategory = MA_AudioCategory_Other; - mal_IAudioClient2_SetClientProperties(pAudioClient2, &clientProperties); + ma_IAudioClient2_SetClientProperties(pAudioClient2, &clientProperties); } } // Here is where we try to determine the best format to use with the device. If the client if wanting exclusive mode, first try finding the best format for that. If this fails, fall back to shared mode. result = MA_FORMAT_NOT_SUPPORTED; - if (pData->shareMode == mal_share_mode_exclusive) { + if (pData->shareMode == ma_share_mode_exclusive) { #ifdef MA_WIN32_DESKTOP // In exclusive mode on desktop we always use the backend's native format. - mal_IPropertyStore* pStore = NULL; - hr = mal_IMMDevice_OpenPropertyStore(pDeviceInterface, STGM_READ, &pStore); + ma_IPropertyStore* pStore = NULL; + hr = ma_IMMDevice_OpenPropertyStore(pDeviceInterface, STGM_READ, &pStore); if (SUCCEEDED(hr)) { PROPVARIANT prop; - mal_PropVariantInit(&prop); - hr = mal_IPropertyStore_GetValue(pStore, &MA_PKEY_AudioEngine_DeviceFormat, &prop); + ma_PropVariantInit(&prop); + hr = ma_IPropertyStore_GetValue(pStore, &MA_PKEY_AudioEngine_DeviceFormat, &prop); if (SUCCEEDED(hr)) { WAVEFORMATEX* pActualFormat = (WAVEFORMATEX*)prop.blob.pBlobData; - hr = mal_IAudioClient_IsFormatSupported((mal_IAudioClient*)pData->pAudioClient, MA_AUDCLNT_SHAREMODE_EXCLUSIVE, pActualFormat, NULL); + hr = ma_IAudioClient_IsFormatSupported((ma_IAudioClient*)pData->pAudioClient, MA_AUDCLNT_SHAREMODE_EXCLUSIVE, pActualFormat, NULL); if (SUCCEEDED(hr)) { - mal_copy_memory(&wf, pActualFormat, sizeof(WAVEFORMATEXTENSIBLE)); + ma_copy_memory(&wf, pActualFormat, sizeof(WAVEFORMATEXTENSIBLE)); } - mal_PropVariantClear(pContext, &prop); + ma_PropVariantClear(pContext, &prop); } - mal_IPropertyStore_Release(pStore); + ma_IPropertyStore_Release(pStore); } #else // I do not know how to query the device's native format on UWP so for now I'm just disabling support for @@ -7204,15 +7204,15 @@ mal_result mal_device_init_internal__wasapi(mal_context* pContext, mal_device_ty } else { // In shared mode we are always using the format reported by the operating system. WAVEFORMATEXTENSIBLE* pNativeFormat = NULL; - hr = mal_IAudioClient_GetMixFormat((mal_IAudioClient*)pData->pAudioClient, (WAVEFORMATEX**)&pNativeFormat); + hr = ma_IAudioClient_GetMixFormat((ma_IAudioClient*)pData->pAudioClient, (WAVEFORMATEX**)&pNativeFormat); if (hr != S_OK) { result = MA_FORMAT_NOT_SUPPORTED; } else { - mal_copy_memory(&wf, pNativeFormat, sizeof(wf)); + ma_copy_memory(&wf, pNativeFormat, sizeof(wf)); result = MA_SUCCESS; } - mal_CoTaskMemFree(pContext, pNativeFormat); + ma_CoTaskMemFree(pContext, pNativeFormat); shareMode = MA_AUDCLNT_SHAREMODE_SHARED; } @@ -7223,21 +7223,21 @@ mal_result mal_device_init_internal__wasapi(mal_context* pContext, mal_device_ty goto done; } - pData->formatOut = mal_format_from_WAVEFORMATEX((WAVEFORMATEX*)&wf); + pData->formatOut = ma_format_from_WAVEFORMATEX((WAVEFORMATEX*)&wf); pData->channelsOut = wf.Format.nChannels; pData->sampleRateOut = wf.Format.nSamplesPerSec; // Get the internal channel map based on the channel mask. - mal_channel_mask_to_channel_map__win32(wf.dwChannelMask, pData->channelsOut, pData->channelMapOut); + ma_channel_mask_to_channel_map__win32(wf.dwChannelMask, pData->channelsOut, pData->channelMapOut); // If we're using a default buffer size we need to calculate it based on the efficiency of the system. pData->periodsOut = pData->periodsIn; pData->bufferSizeInFramesOut = pData->bufferSizeInFramesIn; if (pData->bufferSizeInFramesOut == 0) { - pData->bufferSizeInFramesOut = mal_calculate_buffer_size_in_frames_from_milliseconds(pData->bufferSizeInMillisecondsIn, pData->sampleRateOut); + pData->bufferSizeInFramesOut = ma_calculate_buffer_size_in_frames_from_milliseconds(pData->bufferSizeInMillisecondsIn, pData->sampleRateOut); } - bufferDurationInMicroseconds = ((mal_uint64)pData->bufferSizeInFramesOut * 1000 * 1000) / pData->sampleRateOut; + bufferDurationInMicroseconds = ((ma_uint64)pData->bufferSizeInFramesOut * 1000 * 1000) / pData->sampleRateOut; // Slightly different initialization for shared and exclusive modes. We try exclusive mode first, and if it fails, fall back to shared mode. @@ -7248,7 +7248,7 @@ mal_result mal_device_init_internal__wasapi(mal_context* pContext, mal_device_ty // it and trying it again. hr = E_FAIL; for (;;) { - hr = mal_IAudioClient_Initialize((mal_IAudioClient*)pData->pAudioClient, shareMode, MA_AUDCLNT_STREAMFLAGS_EVENTCALLBACK, bufferDuration, bufferDuration, (WAVEFORMATEX*)&wf, NULL); + hr = ma_IAudioClient_Initialize((ma_IAudioClient*)pData->pAudioClient, shareMode, MA_AUDCLNT_STREAMFLAGS_EVENTCALLBACK, bufferDuration, bufferDuration, (WAVEFORMATEX*)&wf, NULL); if (hr == MA_AUDCLNT_E_INVALID_DEVICE_PERIOD) { if (bufferDuration > 500*10000) { break; @@ -7267,21 +7267,21 @@ mal_result mal_device_init_internal__wasapi(mal_context* pContext, mal_device_ty if (hr == MA_AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED) { UINT bufferSizeInFrames; - hr = mal_IAudioClient_GetBufferSize((mal_IAudioClient*)pData->pAudioClient, &bufferSizeInFrames); + hr = ma_IAudioClient_GetBufferSize((ma_IAudioClient*)pData->pAudioClient, &bufferSizeInFrames); if (SUCCEEDED(hr)) { bufferDuration = (MA_REFERENCE_TIME)((10000.0 * 1000 / wf.Format.nSamplesPerSec * bufferSizeInFrames) + 0.5); // Unfortunately we need to release and re-acquire the audio client according to MSDN. Seems silly - why not just call IAudioClient_Initialize() again?! - mal_IAudioClient_Release((mal_IAudioClient*)pData->pAudioClient); + ma_IAudioClient_Release((ma_IAudioClient*)pData->pAudioClient); #ifdef MA_WIN32_DESKTOP - hr = mal_IMMDevice_Activate(pDeviceInterface, &MA_IID_IAudioClient, CLSCTX_ALL, NULL, (void**)&pData->pAudioClient); + hr = ma_IMMDevice_Activate(pDeviceInterface, &MA_IID_IAudioClient, CLSCTX_ALL, NULL, (void**)&pData->pAudioClient); #else - hr = mal_IUnknown_QueryInterface(pDeviceInterface, &MA_IID_IAudioClient, (void**)&pData->pAudioClient); + hr = ma_IUnknown_QueryInterface(pDeviceInterface, &MA_IID_IAudioClient, (void**)&pData->pAudioClient); #endif if (SUCCEEDED(hr)) { - hr = mal_IAudioClient_Initialize((mal_IAudioClient*)pData->pAudioClient, shareMode, MA_AUDCLNT_STREAMFLAGS_EVENTCALLBACK, bufferDuration, bufferDuration, (WAVEFORMATEX*)&wf, NULL); + hr = ma_IAudioClient_Initialize((ma_IAudioClient*)pData->pAudioClient, shareMode, MA_AUDCLNT_STREAMFLAGS_EVENTCALLBACK, bufferDuration, bufferDuration, (WAVEFORMATEX*)&wf, NULL); } } } @@ -7302,14 +7302,14 @@ mal_result mal_device_init_internal__wasapi(mal_context* pContext, mal_device_ty if (shareMode == MA_AUDCLNT_SHAREMODE_SHARED) { /* Low latency shared mode via IAudioClient3. */ #ifndef MA_WASAPI_NO_LOW_LATENCY_SHARED_MODE - mal_IAudioClient3* pAudioClient3 = NULL; - hr = mal_IAudioClient_QueryInterface(pData->pAudioClient, &MA_IID_IAudioClient3, (void**)&pAudioClient3); + ma_IAudioClient3* pAudioClient3 = NULL; + hr = ma_IAudioClient_QueryInterface(pData->pAudioClient, &MA_IID_IAudioClient3, (void**)&pAudioClient3); if (SUCCEEDED(hr)) { UINT32 defaultPeriodInFrames; UINT32 fundamentalPeriodInFrames; UINT32 minPeriodInFrames; UINT32 maxPeriodInFrames; - hr = mal_IAudioClient3_GetSharedModeEnginePeriod(pAudioClient3, (WAVEFORMATEX*)&wf, &defaultPeriodInFrames, &fundamentalPeriodInFrames, &minPeriodInFrames, &maxPeriodInFrames); + hr = ma_IAudioClient3_GetSharedModeEnginePeriod(pAudioClient3, (WAVEFORMATEX*)&wf, &defaultPeriodInFrames, &fundamentalPeriodInFrames, &minPeriodInFrames, &maxPeriodInFrames); if (SUCCEEDED(hr)) { UINT32 desiredPeriodInFrames = pData->bufferSizeInFramesOut / pData->periodsOut; UINT32 actualPeriodInFrames = desiredPeriodInFrames; @@ -7319,11 +7319,11 @@ mal_result mal_device_init_internal__wasapi(mal_context* pContext, mal_device_ty actualPeriodInFrames = actualPeriodInFrames * fundamentalPeriodInFrames; /* The period needs to be clamped between minPeriodInFrames and maxPeriodInFrames. */ - actualPeriodInFrames = mal_clamp(actualPeriodInFrames, minPeriodInFrames, maxPeriodInFrames); + actualPeriodInFrames = ma_clamp(actualPeriodInFrames, minPeriodInFrames, maxPeriodInFrames); /* If the client requested a largish buffer than we don't actually want to use low latency shared mode because it forces small buffers. */ if (actualPeriodInFrames >= desiredPeriodInFrames) { - hr = mal_IAudioClient3_InitializeSharedAudioStream(pAudioClient3, MA_AUDCLNT_STREAMFLAGS_EVENTCALLBACK, actualPeriodInFrames, (WAVEFORMATEX*)&wf, NULL); + hr = ma_IAudioClient3_InitializeSharedAudioStream(pAudioClient3, MA_AUDCLNT_STREAMFLAGS_EVENTCALLBACK, actualPeriodInFrames, (WAVEFORMATEX*)&wf, NULL); if (SUCCEEDED(hr)) { wasInitializedUsingIAudioClient3 = MA_TRUE; pData->periodSizeInFramesOut = actualPeriodInFrames; @@ -7332,7 +7332,7 @@ mal_result mal_device_init_internal__wasapi(mal_context* pContext, mal_device_ty } } - mal_IAudioClient3_Release(pAudioClient3); + ma_IAudioClient3_Release(pAudioClient3); pAudioClient3 = NULL; } #endif @@ -7340,7 +7340,7 @@ mal_result mal_device_init_internal__wasapi(mal_context* pContext, mal_device_ty // If we don't have an IAudioClient3 then we need to use the normal initialization routine. if (!wasInitializedUsingIAudioClient3) { MA_REFERENCE_TIME bufferDuration = bufferDurationInMicroseconds*10; - hr = mal_IAudioClient_Initialize((mal_IAudioClient*)pData->pAudioClient, shareMode, MA_AUDCLNT_STREAMFLAGS_EVENTCALLBACK, bufferDuration, 0, (WAVEFORMATEX*)&wf, NULL); + hr = ma_IAudioClient_Initialize((ma_IAudioClient*)pData->pAudioClient, shareMode, MA_AUDCLNT_STREAMFLAGS_EVENTCALLBACK, bufferDuration, 0, (WAVEFORMATEX*)&wf, NULL); if (FAILED(hr)) { if (hr == E_ACCESSDENIED) { errorMsg = "[WASAPI] Failed to initialize device. Access denied.", result = MA_ACCESS_DENIED; @@ -7356,7 +7356,7 @@ mal_result mal_device_init_internal__wasapi(mal_context* pContext, mal_device_ty } if (!wasInitializedUsingIAudioClient3) { - hr = mal_IAudioClient_GetBufferSize((mal_IAudioClient*)pData->pAudioClient, &pData->bufferSizeInFramesOut); + hr = ma_IAudioClient_GetBufferSize((ma_IAudioClient*)pData->pAudioClient, &pData->bufferSizeInFramesOut); if (FAILED(hr)) { errorMsg = "[WASAPI] Failed to get audio client's actual buffer size.", result = MA_FAILED_TO_OPEN_BACKEND_DEVICE; goto done; @@ -7365,10 +7365,10 @@ mal_result mal_device_init_internal__wasapi(mal_context* pContext, mal_device_ty pData->periodSizeInFramesOut = pData->bufferSizeInFramesOut / pData->periodsOut; } - if (deviceType == mal_device_type_playback) { - hr = mal_IAudioClient_GetService((mal_IAudioClient*)pData->pAudioClient, &MA_IID_IAudioRenderClient, (void**)&pData->pRenderClient); + if (deviceType == ma_device_type_playback) { + hr = ma_IAudioClient_GetService((ma_IAudioClient*)pData->pAudioClient, &MA_IID_IAudioRenderClient, (void**)&pData->pRenderClient); } else { - hr = mal_IAudioClient_GetService((mal_IAudioClient*)pData->pAudioClient, &MA_IID_IAudioCaptureClient, (void**)&pData->pCaptureClient); + hr = ma_IAudioClient_GetService((ma_IAudioClient*)pData->pAudioClient, &MA_IID_IAudioCaptureClient, (void**)&pData->pCaptureClient); } if (FAILED(hr)) { @@ -7379,18 +7379,18 @@ mal_result mal_device_init_internal__wasapi(mal_context* pContext, mal_device_ty // Grab the name of the device. #ifdef MA_WIN32_DESKTOP - mal_IPropertyStore *pProperties; - hr = mal_IMMDevice_OpenPropertyStore(pDeviceInterface, STGM_READ, &pProperties); + ma_IPropertyStore *pProperties; + hr = ma_IMMDevice_OpenPropertyStore(pDeviceInterface, STGM_READ, &pProperties); if (SUCCEEDED(hr)) { PROPVARIANT varName; - mal_PropVariantInit(&varName); - hr = mal_IPropertyStore_GetValue(pProperties, &MA_PKEY_Device_FriendlyName, &varName); + ma_PropVariantInit(&varName); + hr = ma_IPropertyStore_GetValue(pProperties, &MA_PKEY_Device_FriendlyName, &varName); if (SUCCEEDED(hr)) { WideCharToMultiByte(CP_UTF8, 0, varName.pwszVal, -1, pData->deviceName, sizeof(pData->deviceName), 0, FALSE); - mal_PropVariantClear(pContext, &varName); + ma_PropVariantClear(pContext, &varName); } - mal_IPropertyStore_Release(pProperties); + ma_IPropertyStore_Release(pProperties); } #endif @@ -7398,48 +7398,48 @@ done: // Clean up. #ifdef MA_WIN32_DESKTOP if (pDeviceInterface != NULL) { - mal_IMMDevice_Release(pDeviceInterface); + ma_IMMDevice_Release(pDeviceInterface); } #else if (pDeviceInterface != NULL) { - mal_IUnknown_Release(pDeviceInterface); + ma_IUnknown_Release(pDeviceInterface); } #endif if (result != MA_SUCCESS) { if (pData->pRenderClient) { - mal_IAudioRenderClient_Release((mal_IAudioRenderClient*)pData->pRenderClient); + ma_IAudioRenderClient_Release((ma_IAudioRenderClient*)pData->pRenderClient); pData->pRenderClient = NULL; } if (pData->pCaptureClient) { - mal_IAudioCaptureClient_Release((mal_IAudioCaptureClient*)pData->pCaptureClient); + ma_IAudioCaptureClient_Release((ma_IAudioCaptureClient*)pData->pCaptureClient); pData->pCaptureClient = NULL; } if (pData->pAudioClient) { - mal_IAudioClient_Release((mal_IAudioClient*)pData->pAudioClient); + ma_IAudioClient_Release((ma_IAudioClient*)pData->pAudioClient); pData->pAudioClient = NULL; } - return mal_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, errorMsg, result); + return ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, errorMsg, result); } else { return MA_SUCCESS; } } -mal_result mal_device_reinit__wasapi(mal_device* pDevice, mal_device_type deviceType) +ma_result ma_device_reinit__wasapi(ma_device* pDevice, ma_device_type deviceType) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); // We only re-initialize the playback or capture device. Never a full-duplex device. - if (deviceType == mal_device_type_duplex) { + if (deviceType == ma_device_type_duplex) { return MA_INVALID_ARGS; } - mal_device_init_internal_data__wasapi data; - if (deviceType == mal_device_type_capture) { + ma_device_init_internal_data__wasapi data; + if (deviceType == ma_device_type_capture) { data.formatIn = pDevice->capture.format; data.channelsIn = pDevice->capture.channels; - mal_copy_memory(data.channelMapIn, pDevice->capture.channelMap, sizeof(pDevice->capture.channelMap)); + ma_copy_memory(data.channelMapIn, pDevice->capture.channelMap, sizeof(pDevice->capture.channelMap)); data.shareMode = pDevice->capture.shareMode; data.usingDefaultFormat = pDevice->capture.usingDefaultFormat; data.usingDefaultChannels = pDevice->capture.usingDefaultChannels; @@ -7447,7 +7447,7 @@ mal_result mal_device_reinit__wasapi(mal_device* pDevice, mal_device_type device } else { data.formatIn = pDevice->playback.format; data.channelsIn = pDevice->playback.channels; - mal_copy_memory(data.channelMapIn, pDevice->playback.channelMap, sizeof(pDevice->playback.channelMap)); + ma_copy_memory(data.channelMapIn, pDevice->playback.channelMap, sizeof(pDevice->playback.channelMap)); data.shareMode = pDevice->playback.shareMode; data.usingDefaultFormat = pDevice->playback.usingDefaultFormat; data.usingDefaultChannels = pDevice->playback.usingDefaultChannels; @@ -7459,20 +7459,20 @@ mal_result mal_device_reinit__wasapi(mal_device* pDevice, mal_device_type device data.bufferSizeInFramesIn = pDevice->wasapi.originalBufferSizeInFrames; data.bufferSizeInMillisecondsIn = pDevice->wasapi.originalBufferSizeInMilliseconds; data.periodsIn = pDevice->wasapi.originalPeriods; - mal_result result = mal_device_init_internal__wasapi(pDevice->pContext, deviceType, NULL, &data); + ma_result result = ma_device_init_internal__wasapi(pDevice->pContext, deviceType, NULL, &data); if (result != MA_SUCCESS) { return result; } // At this point we have some new objects ready to go. We need to uninitialize the previous ones and then set the new ones. - if (deviceType == mal_device_type_capture) { + if (deviceType == ma_device_type_capture) { if (pDevice->wasapi.pCaptureClient) { - mal_IAudioCaptureClient_Release((mal_IAudioCaptureClient*)pDevice->wasapi.pCaptureClient); + ma_IAudioCaptureClient_Release((ma_IAudioCaptureClient*)pDevice->wasapi.pCaptureClient); pDevice->wasapi.pCaptureClient = NULL; } if (pDevice->wasapi.pAudioClientCapture) { - mal_IAudioClient_Release((mal_IAudioClient*)pDevice->wasapi.pAudioClientCapture); + ma_IAudioClient_Release((ma_IAudioClient*)pDevice->wasapi.pAudioClientCapture); pDevice->wasapi.pAudioClientCapture = NULL; } @@ -7482,33 +7482,33 @@ mal_result mal_device_reinit__wasapi(mal_device* pDevice, mal_device_type device pDevice->capture.internalFormat = data.formatOut; pDevice->capture.internalChannels = data.channelsOut; pDevice->capture.internalSampleRate = data.sampleRateOut; - mal_copy_memory(pDevice->capture.internalChannelMap, data.channelMapOut, sizeof(data.channelMapOut)); + ma_copy_memory(pDevice->capture.internalChannelMap, data.channelMapOut, sizeof(data.channelMapOut)); pDevice->capture.internalBufferSizeInFrames = data.bufferSizeInFramesOut; pDevice->capture.internalPeriods = data.periodsOut; - mal_strcpy_s(pDevice->capture.name, sizeof(pDevice->capture.name), data.deviceName); + ma_strcpy_s(pDevice->capture.name, sizeof(pDevice->capture.name), data.deviceName); - mal_IAudioClient_SetEventHandle((mal_IAudioClient*)pDevice->wasapi.pAudioClientCapture, pDevice->wasapi.hEventCapture); + ma_IAudioClient_SetEventHandle((ma_IAudioClient*)pDevice->wasapi.pAudioClientCapture, pDevice->wasapi.hEventCapture); pDevice->wasapi.periodSizeInFramesCapture = data.periodSizeInFramesOut; - mal_IAudioClient_GetBufferSize((mal_IAudioClient*)pDevice->wasapi.pAudioClientCapture, &pDevice->wasapi.actualBufferSizeInFramesCapture); + ma_IAudioClient_GetBufferSize((ma_IAudioClient*)pDevice->wasapi.pAudioClientCapture, &pDevice->wasapi.actualBufferSizeInFramesCapture); /* The device may be in a started state. If so we need to immediately restart it. */ if (pDevice->wasapi.isStartedCapture) { - HRESULT hr = mal_IAudioClient_Start((mal_IAudioClient*)pDevice->wasapi.pAudioClientCapture); + HRESULT hr = ma_IAudioClient_Start((ma_IAudioClient*)pDevice->wasapi.pAudioClientCapture); if (FAILED(hr)) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to start internal capture device after reinitialization.", MA_FAILED_TO_START_BACKEND_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to start internal capture device after reinitialization.", MA_FAILED_TO_START_BACKEND_DEVICE); } } } - if (deviceType == mal_device_type_playback) { + if (deviceType == ma_device_type_playback) { if (pDevice->wasapi.pRenderClient) { - mal_IAudioRenderClient_Release((mal_IAudioRenderClient*)pDevice->wasapi.pRenderClient); + ma_IAudioRenderClient_Release((ma_IAudioRenderClient*)pDevice->wasapi.pRenderClient); pDevice->wasapi.pRenderClient = NULL; } if (pDevice->wasapi.pAudioClientPlayback) { - mal_IAudioClient_Release((mal_IAudioClient*)pDevice->wasapi.pAudioClientPlayback); + ma_IAudioClient_Release((ma_IAudioClient*)pDevice->wasapi.pAudioClientPlayback); pDevice->wasapi.pAudioClientPlayback = NULL; } @@ -7518,21 +7518,21 @@ mal_result mal_device_reinit__wasapi(mal_device* pDevice, mal_device_type device pDevice->playback.internalFormat = data.formatOut; pDevice->playback.internalChannels = data.channelsOut; pDevice->playback.internalSampleRate = data.sampleRateOut; - mal_copy_memory(pDevice->playback.internalChannelMap, data.channelMapOut, sizeof(data.channelMapOut)); + ma_copy_memory(pDevice->playback.internalChannelMap, data.channelMapOut, sizeof(data.channelMapOut)); pDevice->playback.internalBufferSizeInFrames = data.bufferSizeInFramesOut; pDevice->playback.internalPeriods = data.periodsOut; - mal_strcpy_s(pDevice->playback.name, sizeof(pDevice->playback.name), data.deviceName); + ma_strcpy_s(pDevice->playback.name, sizeof(pDevice->playback.name), data.deviceName); - mal_IAudioClient_SetEventHandle((mal_IAudioClient*)pDevice->wasapi.pAudioClientPlayback, pDevice->wasapi.hEventPlayback); + ma_IAudioClient_SetEventHandle((ma_IAudioClient*)pDevice->wasapi.pAudioClientPlayback, pDevice->wasapi.hEventPlayback); pDevice->wasapi.periodSizeInFramesPlayback = data.periodSizeInFramesOut; - mal_IAudioClient_GetBufferSize((mal_IAudioClient*)pDevice->wasapi.pAudioClientPlayback, &pDevice->wasapi.actualBufferSizeInFramesPlayback); + ma_IAudioClient_GetBufferSize((ma_IAudioClient*)pDevice->wasapi.pAudioClientPlayback, &pDevice->wasapi.actualBufferSizeInFramesPlayback); /* The device may be in a started state. If so we need to immediately restart it. */ if (pDevice->wasapi.isStartedPlayback) { - HRESULT hr = mal_IAudioClient_Start((mal_IAudioClient*)pDevice->wasapi.pAudioClientPlayback); + HRESULT hr = ma_IAudioClient_Start((ma_IAudioClient*)pDevice->wasapi.pAudioClientPlayback); if (FAILED(hr)) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to start internal playback device after reinitialization.", MA_FAILED_TO_START_BACKEND_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to start internal playback device after reinitialization.", MA_FAILED_TO_START_BACKEND_DEVICE); } } } @@ -7540,27 +7540,27 @@ mal_result mal_device_reinit__wasapi(mal_device* pDevice, mal_device_type device return MA_SUCCESS; } -mal_result mal_device_init__wasapi(mal_context* pContext, const mal_device_config* pConfig, mal_device* pDevice) +ma_result ma_device_init__wasapi(ma_context* pContext, const ma_device_config* pConfig, ma_device* pDevice) { - mal_result result = MA_SUCCESS; + ma_result result = MA_SUCCESS; const char* errorMsg = ""; (void)pContext; - mal_assert(pContext != NULL); - mal_assert(pDevice != NULL); + ma_assert(pContext != NULL); + ma_assert(pDevice != NULL); - mal_zero_object(&pDevice->wasapi); + ma_zero_object(&pDevice->wasapi); pDevice->wasapi.originalBufferSizeInFrames = pConfig->bufferSizeInFrames; pDevice->wasapi.originalBufferSizeInMilliseconds = pConfig->bufferSizeInMilliseconds; pDevice->wasapi.originalPeriods = pConfig->periods; - if (pConfig->deviceType == mal_device_type_capture || pConfig->deviceType == mal_device_type_duplex) { - mal_device_init_internal_data__wasapi data; + if (pConfig->deviceType == ma_device_type_capture || pConfig->deviceType == ma_device_type_duplex) { + ma_device_init_internal_data__wasapi data; data.formatIn = pConfig->capture.format; data.channelsIn = pConfig->capture.channels; data.sampleRateIn = pConfig->sampleRate; - mal_copy_memory(data.channelMapIn, pConfig->capture.channelMap, sizeof(pConfig->capture.channelMap)); + ma_copy_memory(data.channelMapIn, pConfig->capture.channelMap, sizeof(pConfig->capture.channelMap)); data.usingDefaultFormat = pDevice->capture.usingDefaultFormat; data.usingDefaultChannels = pDevice->capture.usingDefaultChannels; data.usingDefaultSampleRate = pDevice->usingDefaultSampleRate; @@ -7570,7 +7570,7 @@ mal_result mal_device_init__wasapi(mal_context* pContext, const mal_device_confi data.bufferSizeInMillisecondsIn = pConfig->bufferSizeInMilliseconds; data.periodsIn = pConfig->periods; - result = mal_device_init_internal__wasapi(pDevice->pContext, mal_device_type_capture, pConfig->capture.pDeviceID, &data); + result = ma_device_init_internal__wasapi(pDevice->pContext, ma_device_type_capture, pConfig->capture.pDeviceID, &data); if (result != MA_SUCCESS) { return result; } @@ -7581,40 +7581,40 @@ mal_result mal_device_init__wasapi(mal_context* pContext, const mal_device_confi pDevice->capture.internalFormat = data.formatOut; pDevice->capture.internalChannels = data.channelsOut; pDevice->capture.internalSampleRate = data.sampleRateOut; - mal_copy_memory(pDevice->capture.internalChannelMap, data.channelMapOut, sizeof(data.channelMapOut)); + ma_copy_memory(pDevice->capture.internalChannelMap, data.channelMapOut, sizeof(data.channelMapOut)); pDevice->capture.internalBufferSizeInFrames = data.bufferSizeInFramesOut; pDevice->capture.internalPeriods = data.periodsOut; - mal_strcpy_s(pDevice->capture.name, sizeof(pDevice->capture.name), data.deviceName); + ma_strcpy_s(pDevice->capture.name, sizeof(pDevice->capture.name), data.deviceName); /* The event for capture needs to be manual reset for the same reason as playback. We keep the initial state set to unsignaled, - however, because we want to block until we actually have something for the first call to mal_device_read(). + however, because we want to block until we actually have something for the first call to ma_device_read(). */ pDevice->wasapi.hEventCapture = CreateEventA(NULL, FALSE, FALSE, NULL); /* Auto reset, unsignaled by default. */ if (pDevice->wasapi.hEventCapture == NULL) { if (pDevice->wasapi.pCaptureClient != NULL) { - mal_IAudioCaptureClient_Release((mal_IAudioCaptureClient*)pDevice->wasapi.pCaptureClient); + ma_IAudioCaptureClient_Release((ma_IAudioCaptureClient*)pDevice->wasapi.pCaptureClient); pDevice->wasapi.pCaptureClient = NULL; } if (pDevice->wasapi.pAudioClientCapture != NULL) { - mal_IAudioClient_Release((mal_IAudioClient*)pDevice->wasapi.pAudioClientCapture); + ma_IAudioClient_Release((ma_IAudioClient*)pDevice->wasapi.pAudioClientCapture); pDevice->wasapi.pAudioClientCapture = NULL; } - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to create event for capture.", MA_FAILED_TO_CREATE_EVENT); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to create event for capture.", MA_FAILED_TO_CREATE_EVENT); } - mal_IAudioClient_SetEventHandle((mal_IAudioClient*)pDevice->wasapi.pAudioClientCapture, pDevice->wasapi.hEventCapture); + ma_IAudioClient_SetEventHandle((ma_IAudioClient*)pDevice->wasapi.pAudioClientCapture, pDevice->wasapi.hEventCapture); pDevice->wasapi.periodSizeInFramesCapture = data.periodSizeInFramesOut; - mal_IAudioClient_GetBufferSize((mal_IAudioClient*)pDevice->wasapi.pAudioClientCapture, &pDevice->wasapi.actualBufferSizeInFramesCapture); + ma_IAudioClient_GetBufferSize((ma_IAudioClient*)pDevice->wasapi.pAudioClientCapture, &pDevice->wasapi.actualBufferSizeInFramesCapture); } - if (pConfig->deviceType == mal_device_type_playback || pConfig->deviceType == mal_device_type_duplex) { - mal_device_init_internal_data__wasapi data; + if (pConfig->deviceType == ma_device_type_playback || pConfig->deviceType == ma_device_type_duplex) { + ma_device_init_internal_data__wasapi data; data.formatIn = pConfig->playback.format; data.channelsIn = pConfig->playback.channels; data.sampleRateIn = pConfig->sampleRate; - mal_copy_memory(data.channelMapIn, pConfig->playback.channelMap, sizeof(pConfig->playback.channelMap)); + ma_copy_memory(data.channelMapIn, pConfig->playback.channelMap, sizeof(pConfig->playback.channelMap)); data.usingDefaultFormat = pDevice->playback.usingDefaultFormat; data.usingDefaultChannels = pDevice->playback.usingDefaultChannels; data.usingDefaultSampleRate = pDevice->usingDefaultSampleRate; @@ -7624,15 +7624,15 @@ mal_result mal_device_init__wasapi(mal_context* pContext, const mal_device_confi data.bufferSizeInMillisecondsIn = pConfig->bufferSizeInMilliseconds; data.periodsIn = pConfig->periods; - result = mal_device_init_internal__wasapi(pDevice->pContext, mal_device_type_playback, pConfig->playback.pDeviceID, &data); + result = ma_device_init_internal__wasapi(pDevice->pContext, ma_device_type_playback, pConfig->playback.pDeviceID, &data); if (result != MA_SUCCESS) { - if (pConfig->deviceType == mal_device_type_duplex) { + if (pConfig->deviceType == ma_device_type_duplex) { if (pDevice->wasapi.pCaptureClient != NULL) { - mal_IAudioCaptureClient_Release((mal_IAudioCaptureClient*)pDevice->wasapi.pCaptureClient); + ma_IAudioCaptureClient_Release((ma_IAudioCaptureClient*)pDevice->wasapi.pCaptureClient); pDevice->wasapi.pCaptureClient = NULL; } if (pDevice->wasapi.pAudioClientCapture != NULL) { - mal_IAudioClient_Release((mal_IAudioClient*)pDevice->wasapi.pAudioClientCapture); + ma_IAudioClient_Release((ma_IAudioClient*)pDevice->wasapi.pAudioClientCapture); pDevice->wasapi.pAudioClientCapture = NULL; } @@ -7648,27 +7648,27 @@ mal_result mal_device_init__wasapi(mal_context* pContext, const mal_device_confi pDevice->playback.internalFormat = data.formatOut; pDevice->playback.internalChannels = data.channelsOut; pDevice->playback.internalSampleRate = data.sampleRateOut; - mal_copy_memory(pDevice->playback.internalChannelMap, data.channelMapOut, sizeof(data.channelMapOut)); + ma_copy_memory(pDevice->playback.internalChannelMap, data.channelMapOut, sizeof(data.channelMapOut)); pDevice->playback.internalBufferSizeInFrames = data.bufferSizeInFramesOut; pDevice->playback.internalPeriods = data.periodsOut; - mal_strcpy_s(pDevice->playback.name, sizeof(pDevice->playback.name), data.deviceName); + ma_strcpy_s(pDevice->playback.name, sizeof(pDevice->playback.name), data.deviceName); /* The event for playback is needs to be manual reset because we want to explicitly control the fact that it becomes signalled only after the whole available space has been filled, never before. - The playback event also needs to be initially set to a signaled state so that the first call to mal_device_write() is able + The playback event also needs to be initially set to a signaled state so that the first call to ma_device_write() is able to get passed WaitForMultipleObjects(). */ pDevice->wasapi.hEventPlayback = CreateEventA(NULL, FALSE, TRUE, NULL); /* Auto reset, signaled by default. */ if (pDevice->wasapi.hEventPlayback == NULL) { - if (pConfig->deviceType == mal_device_type_duplex) { + if (pConfig->deviceType == ma_device_type_duplex) { if (pDevice->wasapi.pCaptureClient != NULL) { - mal_IAudioCaptureClient_Release((mal_IAudioCaptureClient*)pDevice->wasapi.pCaptureClient); + ma_IAudioCaptureClient_Release((ma_IAudioCaptureClient*)pDevice->wasapi.pCaptureClient); pDevice->wasapi.pCaptureClient = NULL; } if (pDevice->wasapi.pAudioClientCapture != NULL) { - mal_IAudioClient_Release((mal_IAudioClient*)pDevice->wasapi.pAudioClientCapture); + ma_IAudioClient_Release((ma_IAudioClient*)pDevice->wasapi.pAudioClientCapture); pDevice->wasapi.pAudioClientCapture = NULL; } @@ -7677,28 +7677,28 @@ mal_result mal_device_init__wasapi(mal_context* pContext, const mal_device_confi } if (pDevice->wasapi.pRenderClient != NULL) { - mal_IAudioRenderClient_Release((mal_IAudioRenderClient*)pDevice->wasapi.pRenderClient); + ma_IAudioRenderClient_Release((ma_IAudioRenderClient*)pDevice->wasapi.pRenderClient); pDevice->wasapi.pRenderClient = NULL; } if (pDevice->wasapi.pAudioClientPlayback != NULL) { - mal_IAudioClient_Release((mal_IAudioClient*)pDevice->wasapi.pAudioClientPlayback); + ma_IAudioClient_Release((ma_IAudioClient*)pDevice->wasapi.pAudioClientPlayback); pDevice->wasapi.pAudioClientPlayback = NULL; } - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to create event for playback.", MA_FAILED_TO_CREATE_EVENT); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to create event for playback.", MA_FAILED_TO_CREATE_EVENT); } - mal_IAudioClient_SetEventHandle((mal_IAudioClient*)pDevice->wasapi.pAudioClientPlayback, pDevice->wasapi.hEventPlayback); + ma_IAudioClient_SetEventHandle((ma_IAudioClient*)pDevice->wasapi.pAudioClientPlayback, pDevice->wasapi.hEventPlayback); pDevice->wasapi.periodSizeInFramesPlayback = data.periodSizeInFramesOut; - mal_IAudioClient_GetBufferSize((mal_IAudioClient*)pDevice->wasapi.pAudioClientPlayback, &pDevice->wasapi.actualBufferSizeInFramesPlayback); + ma_IAudioClient_GetBufferSize((ma_IAudioClient*)pDevice->wasapi.pAudioClientPlayback, &pDevice->wasapi.actualBufferSizeInFramesPlayback); } // We need to get notifications of when the default device changes. We do this through a device enumerator by // registering a IMMNotificationClient with it. We only care about this if it's the default device. #ifdef MA_WIN32_DESKTOP - mal_IMMDeviceEnumerator* pDeviceEnumerator; - HRESULT hr = mal_CoCreateInstance(pContext, MA_CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, MA_IID_IMMDeviceEnumerator, (void**)&pDeviceEnumerator); + ma_IMMDeviceEnumerator* pDeviceEnumerator; + HRESULT hr = ma_CoCreateInstance(pContext, MA_CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, MA_IID_IMMDeviceEnumerator, (void**)&pDeviceEnumerator); if (FAILED(hr)) { errorMsg = "[WASAPI] Failed to create device enumerator.", result = MA_FAILED_TO_OPEN_BACKEND_DEVICE; goto done; @@ -7710,51 +7710,51 @@ mal_result mal_device_init__wasapi(mal_context* pContext, const mal_device_confi hr = pDeviceEnumerator->lpVtbl->RegisterEndpointNotificationCallback(pDeviceEnumerator, &pDevice->wasapi.notificationClient); if (SUCCEEDED(hr)) { - pDevice->wasapi.pDeviceEnumerator = (mal_ptr)pDeviceEnumerator; + pDevice->wasapi.pDeviceEnumerator = (ma_ptr)pDeviceEnumerator; } else { // Not the end of the world if we fail to register the notification callback. We just won't support automatic stream routing. - mal_IMMDeviceEnumerator_Release(pDeviceEnumerator); + ma_IMMDeviceEnumerator_Release(pDeviceEnumerator); } #endif - mal_atomic_exchange_32(&pDevice->wasapi.isStartedCapture, MA_FALSE); - mal_atomic_exchange_32(&pDevice->wasapi.isStartedPlayback, MA_FALSE); + ma_atomic_exchange_32(&pDevice->wasapi.isStartedCapture, MA_FALSE); + ma_atomic_exchange_32(&pDevice->wasapi.isStartedPlayback, MA_FALSE); result = MA_SUCCESS; done: // Clean up. if (result != MA_SUCCESS) { - mal_device_uninit__wasapi(pDevice); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, errorMsg, result); + ma_device_uninit__wasapi(pDevice); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, errorMsg, result); } else { return MA_SUCCESS; } } -mal_result mal_device__get_available_frames__wasapi(mal_device* pDevice, mal_IAudioClient* pAudioClient, mal_uint32* pFrameCount) +ma_result ma_device__get_available_frames__wasapi(ma_device* pDevice, ma_IAudioClient* pAudioClient, ma_uint32* pFrameCount) { - mal_assert(pDevice != NULL); - mal_assert(pFrameCount != NULL); + ma_assert(pDevice != NULL); + ma_assert(pFrameCount != NULL); *pFrameCount = 0; - if ((mal_ptr)pAudioClient != pDevice->wasapi.pAudioClientPlayback && (mal_ptr)pAudioClient != pDevice->wasapi.pAudioClientCapture) { + if ((ma_ptr)pAudioClient != pDevice->wasapi.pAudioClientPlayback && (ma_ptr)pAudioClient != pDevice->wasapi.pAudioClientCapture) { return MA_INVALID_OPERATION; } - mal_uint32 paddingFramesCount; - HRESULT hr = mal_IAudioClient_GetCurrentPadding(pAudioClient, &paddingFramesCount); + ma_uint32 paddingFramesCount; + HRESULT hr = ma_IAudioClient_GetCurrentPadding(pAudioClient, &paddingFramesCount); if (FAILED(hr)) { return MA_DEVICE_UNAVAILABLE; } // Slightly different rules for exclusive and shared modes. - mal_share_mode shareMode = ((mal_ptr)pAudioClient == pDevice->wasapi.pAudioClientPlayback) ? pDevice->playback.shareMode : pDevice->capture.shareMode; - if (shareMode == mal_share_mode_exclusive) { + ma_share_mode shareMode = ((ma_ptr)pAudioClient == pDevice->wasapi.pAudioClientPlayback) ? pDevice->playback.shareMode : pDevice->capture.shareMode; + if (shareMode == ma_share_mode_exclusive) { *pFrameCount = paddingFramesCount; } else { - if ((mal_ptr)pAudioClient == pDevice->wasapi.pAudioClientPlayback) { + if ((ma_ptr)pAudioClient == pDevice->wasapi.pAudioClientPlayback) { *pFrameCount = pDevice->wasapi.actualBufferSizeInFramesPlayback - paddingFramesCount; } else { *pFrameCount = paddingFramesCount; @@ -7764,32 +7764,32 @@ mal_result mal_device__get_available_frames__wasapi(mal_device* pDevice, mal_IAu return MA_SUCCESS; } -mal_bool32 mal_device_is_reroute_required__wasapi(mal_device* pDevice, mal_device_type deviceType) +ma_bool32 ma_device_is_reroute_required__wasapi(ma_device* pDevice, ma_device_type deviceType) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); - if (deviceType == mal_device_type_playback) { + if (deviceType == ma_device_type_playback) { return pDevice->wasapi.hasDefaultPlaybackDeviceChanged; } - if (deviceType == mal_device_type_capture) { + if (deviceType == ma_device_type_capture) { return pDevice->wasapi.hasDefaultCaptureDeviceChanged; } return MA_FALSE; } -mal_result mal_device_reroute__wasapi(mal_device* pDevice, mal_device_type deviceType) +ma_result ma_device_reroute__wasapi(ma_device* pDevice, ma_device_type deviceType) { - if (deviceType == mal_device_type_duplex) { + if (deviceType == ma_device_type_duplex) { return MA_INVALID_ARGS; } - if (deviceType == mal_device_type_playback) { - mal_atomic_exchange_32(&pDevice->wasapi.hasDefaultPlaybackDeviceChanged, MA_FALSE); + if (deviceType == ma_device_type_playback) { + ma_atomic_exchange_32(&pDevice->wasapi.hasDefaultPlaybackDeviceChanged, MA_FALSE); } - if (deviceType == mal_device_type_capture) { - mal_atomic_exchange_32(&pDevice->wasapi.hasDefaultCaptureDeviceChanged, MA_FALSE); + if (deviceType == ma_device_type_capture) { + ma_atomic_exchange_32(&pDevice->wasapi.hasDefaultCaptureDeviceChanged, MA_FALSE); } @@ -7797,58 +7797,58 @@ mal_result mal_device_reroute__wasapi(mal_device* pDevice, mal_device_type devic printf("=== CHANGING DEVICE ===\n"); #endif - mal_result result = mal_device_reinit__wasapi(pDevice, deviceType); + ma_result result = ma_device_reinit__wasapi(pDevice, deviceType); if (result != MA_SUCCESS) { return result; } - mal_device__post_init_setup(pDevice, deviceType); + ma_device__post_init_setup(pDevice, deviceType); return MA_SUCCESS; } -mal_result mal_device_main_loop__wasapi(mal_device* pDevice) +ma_result ma_device_main_loop__wasapi(ma_device* pDevice) { - mal_result result; + ma_result result; HRESULT hr; - mal_bool32 exitLoop = MA_FALSE; - mal_uint32 framesWrittenToPlaybackDevice = 0; - mal_uint32 mappedBufferSizeInFramesCapture = 0; - mal_uint32 mappedBufferSizeInFramesPlayback = 0; - mal_uint32 mappedBufferFramesRemainingCapture = 0; - mal_uint32 mappedBufferFramesRemainingPlayback = 0; + ma_bool32 exitLoop = MA_FALSE; + ma_uint32 framesWrittenToPlaybackDevice = 0; + ma_uint32 mappedBufferSizeInFramesCapture = 0; + ma_uint32 mappedBufferSizeInFramesPlayback = 0; + ma_uint32 mappedBufferFramesRemainingCapture = 0; + ma_uint32 mappedBufferFramesRemainingPlayback = 0; BYTE* pMappedBufferCapture = NULL; BYTE* pMappedBufferPlayback = NULL; - mal_uint32 bpfCapture = mal_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels); - mal_uint32 bpfPlayback = mal_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels); - mal_uint8 inputDataInExternalFormat[4096]; - mal_uint32 inputDataInExternalFormatCap = sizeof(inputDataInExternalFormat) / bpfCapture; - mal_uint8 outputDataInExternalFormat[4096]; - mal_uint32 outputDataInExternalFormatCap = sizeof(outputDataInExternalFormat) / bpfPlayback; + ma_uint32 bpfCapture = ma_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels); + ma_uint32 bpfPlayback = ma_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels); + ma_uint8 inputDataInExternalFormat[4096]; + ma_uint32 inputDataInExternalFormatCap = sizeof(inputDataInExternalFormat) / bpfCapture; + ma_uint8 outputDataInExternalFormat[4096]; + ma_uint32 outputDataInExternalFormatCap = sizeof(outputDataInExternalFormat) / bpfPlayback; - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); /* The playback device needs to be started immediately. */ - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { - hr = mal_IAudioClient_Start((mal_IAudioClient*)pDevice->wasapi.pAudioClientCapture); + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { + hr = ma_IAudioClient_Start((ma_IAudioClient*)pDevice->wasapi.pAudioClientCapture); if (FAILED(hr)) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to start internal capture device.", MA_FAILED_TO_START_BACKEND_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to start internal capture device.", MA_FAILED_TO_START_BACKEND_DEVICE); } - mal_atomic_exchange_32(&pDevice->wasapi.isStartedCapture, MA_TRUE); + ma_atomic_exchange_32(&pDevice->wasapi.isStartedCapture, MA_TRUE); } - while (mal_device__get_state(pDevice) == MA_STATE_STARTED && !exitLoop) { + while (ma_device__get_state(pDevice) == MA_STATE_STARTED && !exitLoop) { /* We may need to reroute the device. */ - if (mal_device_is_reroute_required__wasapi(pDevice, mal_device_type_playback)) { - result = mal_device_reroute__wasapi(pDevice, mal_device_type_playback); + if (ma_device_is_reroute_required__wasapi(pDevice, ma_device_type_playback)) { + result = ma_device_reroute__wasapi(pDevice, ma_device_type_playback); if (result != MA_SUCCESS) { exitLoop = MA_TRUE; break; } } - if (mal_device_is_reroute_required__wasapi(pDevice, mal_device_type_capture)) { - result = mal_device_reroute__wasapi(pDevice, mal_device_type_capture); + if (ma_device_is_reroute_required__wasapi(pDevice, ma_device_type_capture)) { + result = ma_device_reroute__wasapi(pDevice, ma_device_type_capture); if (result != MA_SUCCESS) { exitLoop = MA_TRUE; break; @@ -7857,22 +7857,22 @@ mal_result mal_device_main_loop__wasapi(mal_device* pDevice) switch (pDevice->type) { - case mal_device_type_duplex: + case ma_device_type_duplex: { - mal_uint32 framesAvailableCapture; - mal_uint32 framesAvailablePlayback; + ma_uint32 framesAvailableCapture; + ma_uint32 framesAvailablePlayback; DWORD flagsCapture; /* Passed to IAudioCaptureClient_GetBuffer(). */ /* The process is to map the playback buffer and fill it as quickly as possible from input data. */ if (pMappedBufferPlayback == NULL) { /* WASAPI is weird with exclusive mode. You need to wait on the event _before_ querying the available frames. */ - if (pDevice->playback.shareMode == mal_share_mode_exclusive) { + if (pDevice->playback.shareMode == ma_share_mode_exclusive) { if (WaitForSingleObject(pDevice->wasapi.hEventPlayback, INFINITE) == WAIT_FAILED) { return MA_ERROR; /* Wait failed. */ } } - result = mal_device__get_available_frames__wasapi(pDevice, (mal_IAudioClient*)pDevice->wasapi.pAudioClientPlayback, &framesAvailablePlayback); + result = ma_device__get_available_frames__wasapi(pDevice, (ma_IAudioClient*)pDevice->wasapi.pAudioClientPlayback, &framesAvailablePlayback); if (result != MA_SUCCESS) { return result; } @@ -7881,7 +7881,7 @@ mal_result mal_device_main_loop__wasapi(mal_device* pDevice) /* In exclusive mode, the frame count needs to exactly match the value returned by GetCurrentPadding(). */ - if (pDevice->playback.shareMode != mal_share_mode_exclusive) { + if (pDevice->playback.shareMode != ma_share_mode_exclusive) { if (framesAvailablePlayback >= pDevice->wasapi.periodSizeInFramesPlayback) { framesAvailablePlayback = pDevice->wasapi.periodSizeInFramesPlayback; } @@ -7890,7 +7890,7 @@ mal_result mal_device_main_loop__wasapi(mal_device* pDevice) /* If there's no frames available in the playback device we need to wait for more. */ if (framesAvailablePlayback == 0) { /* In exclusive mode we waited at the top. */ - if (pDevice->playback.shareMode != mal_share_mode_exclusive) { + if (pDevice->playback.shareMode != ma_share_mode_exclusive) { if (WaitForSingleObject(pDevice->wasapi.hEventPlayback, INFINITE) == WAIT_FAILED) { return MA_ERROR; /* Wait failed. */ } @@ -7900,9 +7900,9 @@ mal_result mal_device_main_loop__wasapi(mal_device* pDevice) } /* We're ready to map the playback device's buffer. We don't release this until it's been entirely filled. */ - hr = mal_IAudioRenderClient_GetBuffer((mal_IAudioRenderClient*)pDevice->wasapi.pRenderClient, framesAvailablePlayback, &pMappedBufferPlayback); + hr = ma_IAudioRenderClient_GetBuffer((ma_IAudioRenderClient*)pDevice->wasapi.pRenderClient, framesAvailablePlayback, &pMappedBufferPlayback); if (FAILED(hr)) { - mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to retrieve internal buffer from playback device in preparation for writing to the device.", MA_FAILED_TO_MAP_DEVICE_BUFFER); + ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to retrieve internal buffer from playback device in preparation for writing to the device.", MA_FAILED_TO_MAP_DEVICE_BUFFER); exitLoop = MA_TRUE; break; } @@ -7915,13 +7915,13 @@ mal_result mal_device_main_loop__wasapi(mal_device* pDevice) for (;;) { /* Try grabbing some captured data if we haven't already got a mapped buffer. */ if (pMappedBufferCapture == NULL) { - if (pDevice->capture.shareMode == mal_share_mode_shared) { + if (pDevice->capture.shareMode == ma_share_mode_shared) { if (WaitForSingleObject(pDevice->wasapi.hEventCapture, INFINITE) == WAIT_FAILED) { return MA_ERROR; /* Wait failed. */ } } - result = mal_device__get_available_frames__wasapi(pDevice, (mal_IAudioClient*)pDevice->wasapi.pAudioClientCapture, &framesAvailableCapture); + result = ma_device__get_available_frames__wasapi(pDevice, (ma_IAudioClient*)pDevice->wasapi.pAudioClientCapture, &framesAvailableCapture); if (result != MA_SUCCESS) { exitLoop = MA_TRUE; break; @@ -7932,7 +7932,7 @@ mal_result mal_device_main_loop__wasapi(mal_device* pDevice) /* Wait for more if nothing is available. */ if (framesAvailableCapture == 0) { /* In exclusive mode we waited at the top. */ - if (pDevice->capture.shareMode != mal_share_mode_shared) { + if (pDevice->capture.shareMode != ma_share_mode_shared) { if (WaitForSingleObject(pDevice->wasapi.hEventCapture, INFINITE) == WAIT_FAILED) { return MA_ERROR; /* Wait failed. */ } @@ -7943,9 +7943,9 @@ mal_result mal_device_main_loop__wasapi(mal_device* pDevice) /* Getting here means there's data available for writing to the output device. */ mappedBufferSizeInFramesCapture = framesAvailableCapture; - hr = mal_IAudioCaptureClient_GetBuffer((mal_IAudioCaptureClient*)pDevice->wasapi.pCaptureClient, (BYTE**)&pMappedBufferCapture, &mappedBufferSizeInFramesCapture, &flagsCapture, NULL, NULL); + hr = ma_IAudioCaptureClient_GetBuffer((ma_IAudioCaptureClient*)pDevice->wasapi.pCaptureClient, (BYTE**)&pMappedBufferCapture, &mappedBufferSizeInFramesCapture, &flagsCapture, NULL, NULL); if (FAILED(hr)) { - mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to retrieve internal buffer from capture device in preparation for writing to the device.", MA_FAILED_TO_MAP_DEVICE_BUFFER); + ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to retrieve internal buffer from capture device in preparation for writing to the device.", MA_FAILED_TO_MAP_DEVICE_BUFFER); exitLoop = MA_TRUE; break; } @@ -7960,7 +7960,7 @@ mal_result mal_device_main_loop__wasapi(mal_device* pDevice) mappedBufferFramesRemainingCapture = mappedBufferSizeInFramesCapture; pDevice->capture._dspFrameCount = mappedBufferSizeInFramesCapture; - pDevice->capture._dspFrames = (const mal_uint8*)pMappedBufferCapture; + pDevice->capture._dspFrames = (const ma_uint8*)pMappedBufferCapture; } @@ -7968,15 +7968,15 @@ mal_result mal_device_main_loop__wasapi(mal_device* pDevice) for (;;) { BYTE* pRunningBufferCapture; BYTE* pRunningBufferPlayback; - mal_uint32 framesToProcess; - mal_uint32 framesProcessed; + ma_uint32 framesToProcess; + ma_uint32 framesProcessed; pRunningBufferCapture = pMappedBufferCapture + ((mappedBufferSizeInFramesCapture - mappedBufferFramesRemainingCapture ) * bpfPlayback); pRunningBufferPlayback = pMappedBufferPlayback + ((mappedBufferSizeInFramesPlayback - mappedBufferFramesRemainingPlayback) * bpfPlayback); /* There may be some data sitting in the converter that needs to be processed first. Once this is exhaused, run the data callback again. */ if (!pDevice->playback.converter.isPassthrough) { - framesProcessed = (mal_uint32)mal_pcm_converter_read(&pDevice->playback.converter, pRunningBufferPlayback, mappedBufferFramesRemainingPlayback); + framesProcessed = (ma_uint32)ma_pcm_converter_read(&pDevice->playback.converter, pRunningBufferPlayback, mappedBufferFramesRemainingPlayback); if (framesProcessed > 0) { mappedBufferFramesRemainingPlayback -= framesProcessed; if (mappedBufferFramesRemainingPlayback == 0) { @@ -7991,7 +7991,7 @@ mal_result mal_device_main_loop__wasapi(mal_device* pDevice) */ if (pDevice->capture.converter.isPassthrough && pDevice->playback.converter.isPassthrough) { /* Optimal path. We can pass mapped pointers directly to the callback. */ - framesToProcess = mal_min(mappedBufferFramesRemainingCapture, mappedBufferFramesRemainingPlayback); + framesToProcess = ma_min(mappedBufferFramesRemainingCapture, mappedBufferFramesRemainingPlayback); framesProcessed = framesToProcess; pDevice->onData(pDevice, pRunningBufferPlayback, pRunningBufferCapture, framesToProcess); @@ -8007,22 +8007,22 @@ mal_result mal_device_main_loop__wasapi(mal_device* pDevice) } } else if (pDevice->capture.converter.isPassthrough) { /* The input buffer is a passthrough, but the playback buffer requires a conversion. */ - framesToProcess = mal_min(mappedBufferFramesRemainingCapture, outputDataInExternalFormatCap); + framesToProcess = ma_min(mappedBufferFramesRemainingCapture, outputDataInExternalFormatCap); framesProcessed = framesToProcess; pDevice->onData(pDevice, outputDataInExternalFormat, pRunningBufferCapture, framesToProcess); mappedBufferFramesRemainingCapture -= framesProcessed; pDevice->playback._dspFrameCount = framesProcessed; - pDevice->playback._dspFrames = (const mal_uint8*)outputDataInExternalFormat; + pDevice->playback._dspFrames = (const ma_uint8*)outputDataInExternalFormat; if (mappedBufferFramesRemainingCapture == 0) { break; /* Exhausted input data. */ } } else if (pDevice->playback.converter.isPassthrough) { /* The input buffer requires conversion, the playback buffer is passthrough. */ - framesToProcess = mal_min(inputDataInExternalFormatCap, mappedBufferFramesRemainingPlayback); - framesProcessed = (mal_uint32)mal_pcm_converter_read(&pDevice->capture.converter, inputDataInExternalFormat, framesToProcess); + framesToProcess = ma_min(inputDataInExternalFormatCap, mappedBufferFramesRemainingPlayback); + framesProcessed = (ma_uint32)ma_pcm_converter_read(&pDevice->capture.converter, inputDataInExternalFormat, framesToProcess); if (framesProcessed == 0) { /* Getting here means we've run out of input data. */ mappedBufferFramesRemainingCapture = 0; @@ -8041,8 +8041,8 @@ mal_result mal_device_main_loop__wasapi(mal_device* pDevice) break; /* Exhausted output data. */ } } else { - framesToProcess = mal_min(inputDataInExternalFormatCap, outputDataInExternalFormatCap); - framesProcessed = (mal_uint32)mal_pcm_converter_read(&pDevice->capture.converter, inputDataInExternalFormat, framesToProcess); + framesToProcess = ma_min(inputDataInExternalFormatCap, outputDataInExternalFormatCap); + framesProcessed = (ma_uint32)ma_pcm_converter_read(&pDevice->capture.converter, inputDataInExternalFormat, framesToProcess); if (framesProcessed == 0) { /* Getting here means we've run out of input data. */ mappedBufferFramesRemainingCapture = 0; @@ -8052,7 +8052,7 @@ mal_result mal_device_main_loop__wasapi(mal_device* pDevice) pDevice->onData(pDevice, outputDataInExternalFormat, inputDataInExternalFormat, framesProcessed); pDevice->playback._dspFrameCount = framesProcessed; - pDevice->playback._dspFrames = (const mal_uint8*)outputDataInExternalFormat; + pDevice->playback._dspFrames = (const ma_uint8*)outputDataInExternalFormat; if (framesProcessed < framesToProcess) { /* Getting here means we've run out of input data. */ @@ -8065,9 +8065,9 @@ mal_result mal_device_main_loop__wasapi(mal_device* pDevice) /* If at this point we've run out of capture data we need to release the buffer. */ if (mappedBufferFramesRemainingCapture == 0 && pMappedBufferCapture != NULL) { - hr = mal_IAudioCaptureClient_ReleaseBuffer((mal_IAudioCaptureClient*)pDevice->wasapi.pCaptureClient, mappedBufferSizeInFramesCapture); + hr = ma_IAudioCaptureClient_ReleaseBuffer((ma_IAudioCaptureClient*)pDevice->wasapi.pCaptureClient, mappedBufferSizeInFramesCapture); if (FAILED(hr)) { - mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to release internal buffer from capture device after reading from the device.", MA_FAILED_TO_UNMAP_DEVICE_BUFFER); + ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to release internal buffer from capture device after reading from the device.", MA_FAILED_TO_UNMAP_DEVICE_BUFFER); exitLoop = MA_TRUE; break; } @@ -8088,9 +8088,9 @@ mal_result mal_device_main_loop__wasapi(mal_device* pDevice) /* If at this point we've run out of data we need to release the buffer. */ if (mappedBufferFramesRemainingPlayback == 0 && pMappedBufferPlayback != NULL) { - hr = mal_IAudioRenderClient_ReleaseBuffer((mal_IAudioRenderClient*)pDevice->wasapi.pRenderClient, mappedBufferSizeInFramesPlayback, 0); + hr = ma_IAudioRenderClient_ReleaseBuffer((ma_IAudioRenderClient*)pDevice->wasapi.pRenderClient, mappedBufferSizeInFramesPlayback, 0); if (FAILED(hr)) { - mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to release internal buffer from playback device after writing to the device.", MA_FAILED_TO_UNMAP_DEVICE_BUFFER); + ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to release internal buffer from playback device after writing to the device.", MA_FAILED_TO_UNMAP_DEVICE_BUFFER); exitLoop = MA_TRUE; break; } @@ -8104,23 +8104,23 @@ mal_result mal_device_main_loop__wasapi(mal_device* pDevice) } if (!pDevice->wasapi.isStartedPlayback) { - if (pDevice->playback.shareMode == mal_share_mode_exclusive || framesWrittenToPlaybackDevice >= (pDevice->playback.internalBufferSizeInFrames/pDevice->playback.internalPeriods)*2) { - hr = mal_IAudioClient_Start((mal_IAudioClient*)pDevice->wasapi.pAudioClientPlayback); + if (pDevice->playback.shareMode == ma_share_mode_exclusive || framesWrittenToPlaybackDevice >= (pDevice->playback.internalBufferSizeInFrames/pDevice->playback.internalPeriods)*2) { + hr = ma_IAudioClient_Start((ma_IAudioClient*)pDevice->wasapi.pAudioClientPlayback); if (FAILED(hr)) { - mal_IAudioClient_Stop((mal_IAudioClient*)pDevice->wasapi.pAudioClientCapture); - mal_IAudioClient_Reset((mal_IAudioClient*)pDevice->wasapi.pAudioClientCapture); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to start internal playback device.", MA_FAILED_TO_START_BACKEND_DEVICE); + ma_IAudioClient_Stop((ma_IAudioClient*)pDevice->wasapi.pAudioClientCapture); + ma_IAudioClient_Reset((ma_IAudioClient*)pDevice->wasapi.pAudioClientCapture); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to start internal playback device.", MA_FAILED_TO_START_BACKEND_DEVICE); } - mal_atomic_exchange_32(&pDevice->wasapi.isStartedPlayback, MA_TRUE); + ma_atomic_exchange_32(&pDevice->wasapi.isStartedPlayback, MA_TRUE); } } } break; - case mal_device_type_capture: + case ma_device_type_capture: { - mal_uint32 framesAvailableCapture; + ma_uint32 framesAvailableCapture; DWORD flagsCapture; /* Passed to IAudioCaptureClient_GetBuffer(). */ /* Wait for data to become available first. */ @@ -8130,7 +8130,7 @@ mal_result mal_device_main_loop__wasapi(mal_device* pDevice) } /* See how many frames are available. Since we waited at the top, I don't think this should ever return 0. I'm checking for this anyway. */ - result = mal_device__get_available_frames__wasapi(pDevice, (mal_IAudioClient*)pDevice->wasapi.pAudioClientCapture, &framesAvailableCapture); + result = ma_device__get_available_frames__wasapi(pDevice, (ma_IAudioClient*)pDevice->wasapi.pAudioClientCapture, &framesAvailableCapture); if (result != MA_SUCCESS) { exitLoop = MA_TRUE; break; @@ -8142,9 +8142,9 @@ mal_result mal_device_main_loop__wasapi(mal_device* pDevice) /* Map a the data buffer in preparation for sending to the client. */ mappedBufferSizeInFramesCapture = framesAvailableCapture; - hr = mal_IAudioCaptureClient_GetBuffer((mal_IAudioCaptureClient*)pDevice->wasapi.pCaptureClient, (BYTE**)&pMappedBufferCapture, &mappedBufferSizeInFramesCapture, &flagsCapture, NULL, NULL); + hr = ma_IAudioCaptureClient_GetBuffer((ma_IAudioCaptureClient*)pDevice->wasapi.pCaptureClient, (BYTE**)&pMappedBufferCapture, &mappedBufferSizeInFramesCapture, &flagsCapture, NULL, NULL); if (FAILED(hr)) { - mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to retrieve internal buffer from capture device in preparation for writing to the device.", MA_FAILED_TO_MAP_DEVICE_BUFFER); + ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to retrieve internal buffer from capture device in preparation for writing to the device.", MA_FAILED_TO_MAP_DEVICE_BUFFER); exitLoop = MA_TRUE; break; } @@ -8153,15 +8153,15 @@ mal_result mal_device_main_loop__wasapi(mal_device* pDevice) if (pDevice->capture.converter.isPassthrough) { pDevice->onData(pDevice, NULL, pMappedBufferCapture, mappedBufferSizeInFramesCapture); } else { - mal_device__send_frames_to_client(pDevice, mappedBufferSizeInFramesCapture, pMappedBufferCapture); + ma_device__send_frames_to_client(pDevice, mappedBufferSizeInFramesCapture, pMappedBufferCapture); } /* At this point we're done with the buffer. */ - hr = mal_IAudioCaptureClient_ReleaseBuffer((mal_IAudioCaptureClient*)pDevice->wasapi.pCaptureClient, mappedBufferSizeInFramesCapture); + hr = ma_IAudioCaptureClient_ReleaseBuffer((ma_IAudioCaptureClient*)pDevice->wasapi.pCaptureClient, mappedBufferSizeInFramesCapture); pMappedBufferCapture = NULL; /* <-- Important. Not doing this can result in an error once we leave this loop because it will use this to know whether or not a final ReleaseBuffer() needs to be called. */ mappedBufferSizeInFramesCapture = 0; if (FAILED(hr)) { - mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to release internal buffer from capture device after reading from the device.", MA_FAILED_TO_UNMAP_DEVICE_BUFFER); + ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to release internal buffer from capture device after reading from the device.", MA_FAILED_TO_UNMAP_DEVICE_BUFFER); exitLoop = MA_TRUE; break; } @@ -8169,9 +8169,9 @@ mal_result mal_device_main_loop__wasapi(mal_device* pDevice) - case mal_device_type_playback: + case ma_device_type_playback: { - mal_uint32 framesAvailablePlayback; + ma_uint32 framesAvailablePlayback; /* Wait for space to become available first. */ if (WaitForSingleObject(pDevice->wasapi.hEventPlayback, INFINITE) == WAIT_FAILED) { @@ -8180,7 +8180,7 @@ mal_result mal_device_main_loop__wasapi(mal_device* pDevice) } /* Check how much space is available. If this returns 0 we just keep waiting. */ - result = mal_device__get_available_frames__wasapi(pDevice, (mal_IAudioClient*)pDevice->wasapi.pAudioClientPlayback, &framesAvailablePlayback); + result = ma_device__get_available_frames__wasapi(pDevice, (ma_IAudioClient*)pDevice->wasapi.pAudioClientPlayback, &framesAvailablePlayback); if (result != MA_SUCCESS) { exitLoop = MA_TRUE; break; @@ -8191,9 +8191,9 @@ mal_result mal_device_main_loop__wasapi(mal_device* pDevice) } /* Map a the data buffer in preparation for the callback. */ - hr = mal_IAudioRenderClient_GetBuffer((mal_IAudioRenderClient*)pDevice->wasapi.pRenderClient, framesAvailablePlayback, &pMappedBufferPlayback); + hr = ma_IAudioRenderClient_GetBuffer((ma_IAudioRenderClient*)pDevice->wasapi.pRenderClient, framesAvailablePlayback, &pMappedBufferPlayback); if (FAILED(hr)) { - mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to retrieve internal buffer from playback device in preparation for writing to the device.", MA_FAILED_TO_MAP_DEVICE_BUFFER); + ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to retrieve internal buffer from playback device in preparation for writing to the device.", MA_FAILED_TO_MAP_DEVICE_BUFFER); exitLoop = MA_TRUE; break; } @@ -8201,30 +8201,30 @@ mal_result mal_device_main_loop__wasapi(mal_device* pDevice) if (pDevice->playback.converter.isPassthrough) { pDevice->onData(pDevice, pMappedBufferPlayback, NULL, framesAvailablePlayback); } else { - mal_device__read_frames_from_client(pDevice, framesAvailablePlayback, pMappedBufferPlayback); + ma_device__read_frames_from_client(pDevice, framesAvailablePlayback, pMappedBufferPlayback); } /* At this point we're done writing to the device and we just need to release the buffer. */ - hr = mal_IAudioRenderClient_ReleaseBuffer((mal_IAudioRenderClient*)pDevice->wasapi.pRenderClient, framesAvailablePlayback, 0); + hr = ma_IAudioRenderClient_ReleaseBuffer((ma_IAudioRenderClient*)pDevice->wasapi.pRenderClient, framesAvailablePlayback, 0); pMappedBufferPlayback = NULL; /* <-- Important. Not doing this can result in an error once we leave this loop because it will use this to know whether or not a final ReleaseBuffer() needs to be called. */ mappedBufferSizeInFramesPlayback = 0; if (FAILED(hr)) { - mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to release internal buffer from playback device after writing to the device.", MA_FAILED_TO_UNMAP_DEVICE_BUFFER); + ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to release internal buffer from playback device after writing to the device.", MA_FAILED_TO_UNMAP_DEVICE_BUFFER); exitLoop = MA_TRUE; break; } framesWrittenToPlaybackDevice += framesAvailablePlayback; if (!pDevice->wasapi.isStartedPlayback) { - if (pDevice->playback.shareMode == mal_share_mode_exclusive || framesWrittenToPlaybackDevice >= (pDevice->playback.internalBufferSizeInFrames/pDevice->playback.internalPeriods)*1) { - hr = mal_IAudioClient_Start((mal_IAudioClient*)pDevice->wasapi.pAudioClientPlayback); + if (pDevice->playback.shareMode == ma_share_mode_exclusive || framesWrittenToPlaybackDevice >= (pDevice->playback.internalBufferSizeInFrames/pDevice->playback.internalPeriods)*1) { + hr = ma_IAudioClient_Start((ma_IAudioClient*)pDevice->wasapi.pAudioClientPlayback); if (FAILED(hr)) { - mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to start internal playback device.", MA_FAILED_TO_START_BACKEND_DEVICE); + ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to start internal playback device.", MA_FAILED_TO_START_BACKEND_DEVICE); exitLoop = MA_TRUE; break; } - mal_atomic_exchange_32(&pDevice->wasapi.isStartedPlayback, MA_TRUE); + ma_atomic_exchange_32(&pDevice->wasapi.isStartedPlayback, MA_TRUE); } } } break; @@ -8234,30 +8234,30 @@ mal_result mal_device_main_loop__wasapi(mal_device* pDevice) } /* Here is where the device needs to be stopped. */ - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { /* Any mapped buffers need to be released. */ if (pMappedBufferCapture != NULL) { - hr = mal_IAudioCaptureClient_ReleaseBuffer((mal_IAudioCaptureClient*)pDevice->wasapi.pCaptureClient, mappedBufferSizeInFramesCapture); + hr = ma_IAudioCaptureClient_ReleaseBuffer((ma_IAudioCaptureClient*)pDevice->wasapi.pCaptureClient, mappedBufferSizeInFramesCapture); } - hr = mal_IAudioClient_Stop((mal_IAudioClient*)pDevice->wasapi.pAudioClientCapture); + hr = ma_IAudioClient_Stop((ma_IAudioClient*)pDevice->wasapi.pAudioClientCapture); if (FAILED(hr)) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to stop internal capture device.", MA_FAILED_TO_STOP_BACKEND_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to stop internal capture device.", MA_FAILED_TO_STOP_BACKEND_DEVICE); } /* The audio client needs to be reset otherwise restarting will fail. */ - hr = mal_IAudioClient_Reset((mal_IAudioClient*)pDevice->wasapi.pAudioClientCapture); + hr = ma_IAudioClient_Reset((ma_IAudioClient*)pDevice->wasapi.pAudioClientCapture); if (FAILED(hr)) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to reset internal capture device.", MA_FAILED_TO_STOP_BACKEND_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to reset internal capture device.", MA_FAILED_TO_STOP_BACKEND_DEVICE); } - mal_atomic_exchange_32(&pDevice->wasapi.isStartedCapture, MA_FALSE); + ma_atomic_exchange_32(&pDevice->wasapi.isStartedCapture, MA_FALSE); } - if (pDevice->type == mal_device_type_playback || pDevice->type == mal_device_type_duplex) { + if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) { /* Any mapped buffers need to be released. */ if (pMappedBufferPlayback != NULL) { - hr = mal_IAudioRenderClient_ReleaseBuffer((mal_IAudioRenderClient*)pDevice->wasapi.pRenderClient, mappedBufferSizeInFramesPlayback, 0); + hr = ma_IAudioRenderClient_ReleaseBuffer((ma_IAudioRenderClient*)pDevice->wasapi.pRenderClient, mappedBufferSizeInFramesPlayback, 0); } /* @@ -8265,13 +8265,13 @@ mal_result mal_device_main_loop__wasapi(mal_device* pDevice) the speakers. This is a problem for very short sounds because it'll result in a significant potion of it not getting played. */ if (pDevice->wasapi.isStartedPlayback) { - if (pDevice->playback.shareMode == mal_share_mode_exclusive) { + if (pDevice->playback.shareMode == ma_share_mode_exclusive) { WaitForSingleObject(pDevice->wasapi.hEventPlayback, INFINITE); } else { - mal_uint32 prevFramesAvaialablePlayback = (size_t)-1; - mal_uint32 framesAvailablePlayback; + ma_uint32 prevFramesAvaialablePlayback = (size_t)-1; + ma_uint32 framesAvailablePlayback; for (;;) { - result = mal_device__get_available_frames__wasapi(pDevice, (mal_IAudioClient*)pDevice->wasapi.pAudioClientPlayback, &framesAvailablePlayback); + result = ma_device__get_available_frames__wasapi(pDevice, (ma_IAudioClient*)pDevice->wasapi.pAudioClientPlayback, &framesAvailablePlayback); if (result != MA_SUCCESS) { break; } @@ -8295,44 +8295,44 @@ mal_result mal_device_main_loop__wasapi(mal_device* pDevice) } } - hr = mal_IAudioClient_Stop((mal_IAudioClient*)pDevice->wasapi.pAudioClientPlayback); + hr = ma_IAudioClient_Stop((ma_IAudioClient*)pDevice->wasapi.pAudioClientPlayback); if (FAILED(hr)) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to stop internal playback device.", MA_FAILED_TO_STOP_BACKEND_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to stop internal playback device.", MA_FAILED_TO_STOP_BACKEND_DEVICE); } /* The audio client needs to be reset otherwise restarting will fail. */ - hr = mal_IAudioClient_Reset((mal_IAudioClient*)pDevice->wasapi.pAudioClientPlayback); + hr = ma_IAudioClient_Reset((ma_IAudioClient*)pDevice->wasapi.pAudioClientPlayback); if (FAILED(hr)) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to reset internal playback device.", MA_FAILED_TO_STOP_BACKEND_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to reset internal playback device.", MA_FAILED_TO_STOP_BACKEND_DEVICE); } - mal_atomic_exchange_32(&pDevice->wasapi.isStartedPlayback, MA_FALSE); + ma_atomic_exchange_32(&pDevice->wasapi.isStartedPlayback, MA_FALSE); } return MA_SUCCESS; } -mal_result mal_context_uninit__wasapi(mal_context* pContext) +ma_result ma_context_uninit__wasapi(ma_context* pContext) { - mal_assert(pContext != NULL); - mal_assert(pContext->backend == mal_backend_wasapi); + ma_assert(pContext != NULL); + ma_assert(pContext->backend == ma_backend_wasapi); (void)pContext; return MA_SUCCESS; } -mal_result mal_context_init__wasapi(mal_context* pContext) +ma_result ma_context_init__wasapi(ma_context* pContext) { - mal_assert(pContext != NULL); + ma_assert(pContext != NULL); (void)pContext; - mal_result result = MA_SUCCESS; + ma_result result = MA_SUCCESS; #ifdef MA_WIN32_DESKTOP // WASAPI is only supported in Vista SP1 and newer. The reason for SP1 and not the base version of Vista is that event-driven // exclusive mode does not work until SP1. - mal_OSVERSIONINFOEXW osvi; - mal_zero_object(&osvi); + ma_OSVERSIONINFOEXW osvi; + ma_zero_object(&osvi); osvi.dwOSVersionInfoSize = sizeof(osvi); osvi.dwMajorVersion = HIBYTE(_WIN32_WINNT_VISTA); osvi.dwMinorVersion = LOBYTE(_WIN32_WINNT_VISTA); @@ -8348,17 +8348,17 @@ mal_result mal_context_init__wasapi(mal_context* pContext) return result; } - pContext->onUninit = mal_context_uninit__wasapi; - pContext->onDeviceIDEqual = mal_context_is_device_id_equal__wasapi; - pContext->onEnumDevices = mal_context_enumerate_devices__wasapi; - pContext->onGetDeviceInfo = mal_context_get_device_info__wasapi; - pContext->onDeviceInit = mal_device_init__wasapi; - pContext->onDeviceUninit = mal_device_uninit__wasapi; + pContext->onUninit = ma_context_uninit__wasapi; + pContext->onDeviceIDEqual = ma_context_is_device_id_equal__wasapi; + pContext->onEnumDevices = ma_context_enumerate_devices__wasapi; + pContext->onGetDeviceInfo = ma_context_get_device_info__wasapi; + pContext->onDeviceInit = ma_device_init__wasapi; + pContext->onDeviceUninit = ma_device_uninit__wasapi; pContext->onDeviceStart = NULL; /* Not used. Started in onDeviceMainLoop. */ pContext->onDeviceStop = NULL; /* Not used. Stopped in onDeviceMainLoop. */ pContext->onDeviceWrite = NULL; pContext->onDeviceRead = NULL; - pContext->onDeviceMainLoop = mal_device_main_loop__wasapi; + pContext->onDeviceMainLoop = ma_device_main_loop__wasapi; return result; } @@ -8498,11 +8498,11 @@ typedef struct HANDLE hEventNotify; } MA_DSBPOSITIONNOTIFY; -typedef struct mal_IDirectSound mal_IDirectSound; -typedef struct mal_IDirectSoundBuffer mal_IDirectSoundBuffer; -typedef struct mal_IDirectSoundCapture mal_IDirectSoundCapture; -typedef struct mal_IDirectSoundCaptureBuffer mal_IDirectSoundCaptureBuffer; -typedef struct mal_IDirectSoundNotify mal_IDirectSoundNotify; +typedef struct ma_IDirectSound ma_IDirectSound; +typedef struct ma_IDirectSoundBuffer ma_IDirectSoundBuffer; +typedef struct ma_IDirectSoundCapture ma_IDirectSoundCapture; +typedef struct ma_IDirectSoundCaptureBuffer ma_IDirectSoundCaptureBuffer; +typedef struct ma_IDirectSoundNotify ma_IDirectSoundNotify; // COM objects. The way these work is that you have a vtable (a list of function pointers, kind of @@ -8514,185 +8514,185 @@ typedef struct mal_IDirectSoundNotify mal_IDirectSoundNotify; typedef struct { // IUnknown - HRESULT (STDMETHODCALLTYPE * QueryInterface)(mal_IDirectSound* pThis, const IID* const riid, void** ppObject); - ULONG (STDMETHODCALLTYPE * AddRef) (mal_IDirectSound* pThis); - ULONG (STDMETHODCALLTYPE * Release) (mal_IDirectSound* pThis); + HRESULT (STDMETHODCALLTYPE * QueryInterface)(ma_IDirectSound* pThis, const IID* const riid, void** ppObject); + ULONG (STDMETHODCALLTYPE * AddRef) (ma_IDirectSound* pThis); + ULONG (STDMETHODCALLTYPE * Release) (ma_IDirectSound* pThis); // IDirectSound - HRESULT (STDMETHODCALLTYPE * CreateSoundBuffer) (mal_IDirectSound* pThis, const MA_DSBUFFERDESC* pDSBufferDesc, mal_IDirectSoundBuffer** ppDSBuffer, void* pUnkOuter); - HRESULT (STDMETHODCALLTYPE * GetCaps) (mal_IDirectSound* pThis, MA_DSCAPS* pDSCaps); - HRESULT (STDMETHODCALLTYPE * DuplicateSoundBuffer)(mal_IDirectSound* pThis, mal_IDirectSoundBuffer* pDSBufferOriginal, mal_IDirectSoundBuffer** ppDSBufferDuplicate); - HRESULT (STDMETHODCALLTYPE * SetCooperativeLevel) (mal_IDirectSound* pThis, HWND hwnd, DWORD dwLevel); - HRESULT (STDMETHODCALLTYPE * Compact) (mal_IDirectSound* pThis); - HRESULT (STDMETHODCALLTYPE * GetSpeakerConfig) (mal_IDirectSound* pThis, DWORD* pSpeakerConfig); - HRESULT (STDMETHODCALLTYPE * SetSpeakerConfig) (mal_IDirectSound* pThis, DWORD dwSpeakerConfig); - HRESULT (STDMETHODCALLTYPE * Initialize) (mal_IDirectSound* pThis, const GUID* pGuidDevice); -} mal_IDirectSoundVtbl; -struct mal_IDirectSound + HRESULT (STDMETHODCALLTYPE * CreateSoundBuffer) (ma_IDirectSound* pThis, const MA_DSBUFFERDESC* pDSBufferDesc, ma_IDirectSoundBuffer** ppDSBuffer, void* pUnkOuter); + HRESULT (STDMETHODCALLTYPE * GetCaps) (ma_IDirectSound* pThis, MA_DSCAPS* pDSCaps); + HRESULT (STDMETHODCALLTYPE * DuplicateSoundBuffer)(ma_IDirectSound* pThis, ma_IDirectSoundBuffer* pDSBufferOriginal, ma_IDirectSoundBuffer** ppDSBufferDuplicate); + HRESULT (STDMETHODCALLTYPE * SetCooperativeLevel) (ma_IDirectSound* pThis, HWND hwnd, DWORD dwLevel); + HRESULT (STDMETHODCALLTYPE * Compact) (ma_IDirectSound* pThis); + HRESULT (STDMETHODCALLTYPE * GetSpeakerConfig) (ma_IDirectSound* pThis, DWORD* pSpeakerConfig); + HRESULT (STDMETHODCALLTYPE * SetSpeakerConfig) (ma_IDirectSound* pThis, DWORD dwSpeakerConfig); + HRESULT (STDMETHODCALLTYPE * Initialize) (ma_IDirectSound* pThis, const GUID* pGuidDevice); +} ma_IDirectSoundVtbl; +struct ma_IDirectSound { - mal_IDirectSoundVtbl* lpVtbl; + ma_IDirectSoundVtbl* lpVtbl; }; -HRESULT mal_IDirectSound_QueryInterface(mal_IDirectSound* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); } -ULONG mal_IDirectSound_AddRef(mal_IDirectSound* pThis) { return pThis->lpVtbl->AddRef(pThis); } -ULONG mal_IDirectSound_Release(mal_IDirectSound* pThis) { return pThis->lpVtbl->Release(pThis); } -HRESULT mal_IDirectSound_CreateSoundBuffer(mal_IDirectSound* pThis, const MA_DSBUFFERDESC* pDSBufferDesc, mal_IDirectSoundBuffer** ppDSBuffer, void* pUnkOuter) { return pThis->lpVtbl->CreateSoundBuffer(pThis, pDSBufferDesc, ppDSBuffer, pUnkOuter); } -HRESULT mal_IDirectSound_GetCaps(mal_IDirectSound* pThis, MA_DSCAPS* pDSCaps) { return pThis->lpVtbl->GetCaps(pThis, pDSCaps); } -HRESULT mal_IDirectSound_DuplicateSoundBuffer(mal_IDirectSound* pThis, mal_IDirectSoundBuffer* pDSBufferOriginal, mal_IDirectSoundBuffer** ppDSBufferDuplicate) { return pThis->lpVtbl->DuplicateSoundBuffer(pThis, pDSBufferOriginal, ppDSBufferDuplicate); } -HRESULT mal_IDirectSound_SetCooperativeLevel(mal_IDirectSound* pThis, HWND hwnd, DWORD dwLevel) { return pThis->lpVtbl->SetCooperativeLevel(pThis, hwnd, dwLevel); } -HRESULT mal_IDirectSound_Compact(mal_IDirectSound* pThis) { return pThis->lpVtbl->Compact(pThis); } -HRESULT mal_IDirectSound_GetSpeakerConfig(mal_IDirectSound* pThis, DWORD* pSpeakerConfig) { return pThis->lpVtbl->GetSpeakerConfig(pThis, pSpeakerConfig); } -HRESULT mal_IDirectSound_SetSpeakerConfig(mal_IDirectSound* pThis, DWORD dwSpeakerConfig) { return pThis->lpVtbl->SetSpeakerConfig(pThis, dwSpeakerConfig); } -HRESULT mal_IDirectSound_Initialize(mal_IDirectSound* pThis, const GUID* pGuidDevice) { return pThis->lpVtbl->Initialize(pThis, pGuidDevice); } +HRESULT ma_IDirectSound_QueryInterface(ma_IDirectSound* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); } +ULONG ma_IDirectSound_AddRef(ma_IDirectSound* pThis) { return pThis->lpVtbl->AddRef(pThis); } +ULONG ma_IDirectSound_Release(ma_IDirectSound* pThis) { return pThis->lpVtbl->Release(pThis); } +HRESULT ma_IDirectSound_CreateSoundBuffer(ma_IDirectSound* pThis, const MA_DSBUFFERDESC* pDSBufferDesc, ma_IDirectSoundBuffer** ppDSBuffer, void* pUnkOuter) { return pThis->lpVtbl->CreateSoundBuffer(pThis, pDSBufferDesc, ppDSBuffer, pUnkOuter); } +HRESULT ma_IDirectSound_GetCaps(ma_IDirectSound* pThis, MA_DSCAPS* pDSCaps) { return pThis->lpVtbl->GetCaps(pThis, pDSCaps); } +HRESULT ma_IDirectSound_DuplicateSoundBuffer(ma_IDirectSound* pThis, ma_IDirectSoundBuffer* pDSBufferOriginal, ma_IDirectSoundBuffer** ppDSBufferDuplicate) { return pThis->lpVtbl->DuplicateSoundBuffer(pThis, pDSBufferOriginal, ppDSBufferDuplicate); } +HRESULT ma_IDirectSound_SetCooperativeLevel(ma_IDirectSound* pThis, HWND hwnd, DWORD dwLevel) { return pThis->lpVtbl->SetCooperativeLevel(pThis, hwnd, dwLevel); } +HRESULT ma_IDirectSound_Compact(ma_IDirectSound* pThis) { return pThis->lpVtbl->Compact(pThis); } +HRESULT ma_IDirectSound_GetSpeakerConfig(ma_IDirectSound* pThis, DWORD* pSpeakerConfig) { return pThis->lpVtbl->GetSpeakerConfig(pThis, pSpeakerConfig); } +HRESULT ma_IDirectSound_SetSpeakerConfig(ma_IDirectSound* pThis, DWORD dwSpeakerConfig) { return pThis->lpVtbl->SetSpeakerConfig(pThis, dwSpeakerConfig); } +HRESULT ma_IDirectSound_Initialize(ma_IDirectSound* pThis, const GUID* pGuidDevice) { return pThis->lpVtbl->Initialize(pThis, pGuidDevice); } // IDirectSoundBuffer typedef struct { // IUnknown - HRESULT (STDMETHODCALLTYPE * QueryInterface)(mal_IDirectSoundBuffer* pThis, const IID* const riid, void** ppObject); - ULONG (STDMETHODCALLTYPE * AddRef) (mal_IDirectSoundBuffer* pThis); - ULONG (STDMETHODCALLTYPE * Release) (mal_IDirectSoundBuffer* pThis); + HRESULT (STDMETHODCALLTYPE * QueryInterface)(ma_IDirectSoundBuffer* pThis, const IID* const riid, void** ppObject); + ULONG (STDMETHODCALLTYPE * AddRef) (ma_IDirectSoundBuffer* pThis); + ULONG (STDMETHODCALLTYPE * Release) (ma_IDirectSoundBuffer* pThis); // IDirectSoundBuffer - HRESULT (STDMETHODCALLTYPE * GetCaps) (mal_IDirectSoundBuffer* pThis, MA_DSBCAPS* pDSBufferCaps); - HRESULT (STDMETHODCALLTYPE * GetCurrentPosition)(mal_IDirectSoundBuffer* pThis, DWORD* pCurrentPlayCursor, DWORD* pCurrentWriteCursor); - HRESULT (STDMETHODCALLTYPE * GetFormat) (mal_IDirectSoundBuffer* pThis, WAVEFORMATEX* pFormat, DWORD dwSizeAllocated, DWORD* pSizeWritten); - HRESULT (STDMETHODCALLTYPE * GetVolume) (mal_IDirectSoundBuffer* pThis, LONG* pVolume); - HRESULT (STDMETHODCALLTYPE * GetPan) (mal_IDirectSoundBuffer* pThis, LONG* pPan); - HRESULT (STDMETHODCALLTYPE * GetFrequency) (mal_IDirectSoundBuffer* pThis, DWORD* pFrequency); - HRESULT (STDMETHODCALLTYPE * GetStatus) (mal_IDirectSoundBuffer* pThis, DWORD* pStatus); - HRESULT (STDMETHODCALLTYPE * Initialize) (mal_IDirectSoundBuffer* pThis, mal_IDirectSound* pDirectSound, const MA_DSBUFFERDESC* pDSBufferDesc); - HRESULT (STDMETHODCALLTYPE * Lock) (mal_IDirectSoundBuffer* pThis, DWORD dwOffset, DWORD dwBytes, void** ppAudioPtr1, DWORD* pAudioBytes1, void** ppAudioPtr2, DWORD* pAudioBytes2, DWORD dwFlags); - HRESULT (STDMETHODCALLTYPE * Play) (mal_IDirectSoundBuffer* pThis, DWORD dwReserved1, DWORD dwPriority, DWORD dwFlags); - HRESULT (STDMETHODCALLTYPE * SetCurrentPosition)(mal_IDirectSoundBuffer* pThis, DWORD dwNewPosition); - HRESULT (STDMETHODCALLTYPE * SetFormat) (mal_IDirectSoundBuffer* pThis, const WAVEFORMATEX* pFormat); - HRESULT (STDMETHODCALLTYPE * SetVolume) (mal_IDirectSoundBuffer* pThis, LONG volume); - HRESULT (STDMETHODCALLTYPE * SetPan) (mal_IDirectSoundBuffer* pThis, LONG pan); - HRESULT (STDMETHODCALLTYPE * SetFrequency) (mal_IDirectSoundBuffer* pThis, DWORD dwFrequency); - HRESULT (STDMETHODCALLTYPE * Stop) (mal_IDirectSoundBuffer* pThis); - HRESULT (STDMETHODCALLTYPE * Unlock) (mal_IDirectSoundBuffer* pThis, void* pAudioPtr1, DWORD dwAudioBytes1, void* pAudioPtr2, DWORD dwAudioBytes2); - HRESULT (STDMETHODCALLTYPE * Restore) (mal_IDirectSoundBuffer* pThis); -} mal_IDirectSoundBufferVtbl; -struct mal_IDirectSoundBuffer + HRESULT (STDMETHODCALLTYPE * GetCaps) (ma_IDirectSoundBuffer* pThis, MA_DSBCAPS* pDSBufferCaps); + HRESULT (STDMETHODCALLTYPE * GetCurrentPosition)(ma_IDirectSoundBuffer* pThis, DWORD* pCurrentPlayCursor, DWORD* pCurrentWriteCursor); + HRESULT (STDMETHODCALLTYPE * GetFormat) (ma_IDirectSoundBuffer* pThis, WAVEFORMATEX* pFormat, DWORD dwSizeAllocated, DWORD* pSizeWritten); + HRESULT (STDMETHODCALLTYPE * GetVolume) (ma_IDirectSoundBuffer* pThis, LONG* pVolume); + HRESULT (STDMETHODCALLTYPE * GetPan) (ma_IDirectSoundBuffer* pThis, LONG* pPan); + HRESULT (STDMETHODCALLTYPE * GetFrequency) (ma_IDirectSoundBuffer* pThis, DWORD* pFrequency); + HRESULT (STDMETHODCALLTYPE * GetStatus) (ma_IDirectSoundBuffer* pThis, DWORD* pStatus); + HRESULT (STDMETHODCALLTYPE * Initialize) (ma_IDirectSoundBuffer* pThis, ma_IDirectSound* pDirectSound, const MA_DSBUFFERDESC* pDSBufferDesc); + HRESULT (STDMETHODCALLTYPE * Lock) (ma_IDirectSoundBuffer* pThis, DWORD dwOffset, DWORD dwBytes, void** ppAudioPtr1, DWORD* pAudioBytes1, void** ppAudioPtr2, DWORD* pAudioBytes2, DWORD dwFlags); + HRESULT (STDMETHODCALLTYPE * Play) (ma_IDirectSoundBuffer* pThis, DWORD dwReserved1, DWORD dwPriority, DWORD dwFlags); + HRESULT (STDMETHODCALLTYPE * SetCurrentPosition)(ma_IDirectSoundBuffer* pThis, DWORD dwNewPosition); + HRESULT (STDMETHODCALLTYPE * SetFormat) (ma_IDirectSoundBuffer* pThis, const WAVEFORMATEX* pFormat); + HRESULT (STDMETHODCALLTYPE * SetVolume) (ma_IDirectSoundBuffer* pThis, LONG volume); + HRESULT (STDMETHODCALLTYPE * SetPan) (ma_IDirectSoundBuffer* pThis, LONG pan); + HRESULT (STDMETHODCALLTYPE * SetFrequency) (ma_IDirectSoundBuffer* pThis, DWORD dwFrequency); + HRESULT (STDMETHODCALLTYPE * Stop) (ma_IDirectSoundBuffer* pThis); + HRESULT (STDMETHODCALLTYPE * Unlock) (ma_IDirectSoundBuffer* pThis, void* pAudioPtr1, DWORD dwAudioBytes1, void* pAudioPtr2, DWORD dwAudioBytes2); + HRESULT (STDMETHODCALLTYPE * Restore) (ma_IDirectSoundBuffer* pThis); +} ma_IDirectSoundBufferVtbl; +struct ma_IDirectSoundBuffer { - mal_IDirectSoundBufferVtbl* lpVtbl; + ma_IDirectSoundBufferVtbl* lpVtbl; }; -HRESULT mal_IDirectSoundBuffer_QueryInterface(mal_IDirectSoundBuffer* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); } -ULONG mal_IDirectSoundBuffer_AddRef(mal_IDirectSoundBuffer* pThis) { return pThis->lpVtbl->AddRef(pThis); } -ULONG mal_IDirectSoundBuffer_Release(mal_IDirectSoundBuffer* pThis) { return pThis->lpVtbl->Release(pThis); } -HRESULT mal_IDirectSoundBuffer_GetCaps(mal_IDirectSoundBuffer* pThis, MA_DSBCAPS* pDSBufferCaps) { return pThis->lpVtbl->GetCaps(pThis, pDSBufferCaps); } -HRESULT mal_IDirectSoundBuffer_GetCurrentPosition(mal_IDirectSoundBuffer* pThis, DWORD* pCurrentPlayCursor, DWORD* pCurrentWriteCursor) { return pThis->lpVtbl->GetCurrentPosition(pThis, pCurrentPlayCursor, pCurrentWriteCursor); } -HRESULT mal_IDirectSoundBuffer_GetFormat(mal_IDirectSoundBuffer* pThis, WAVEFORMATEX* pFormat, DWORD dwSizeAllocated, DWORD* pSizeWritten) { return pThis->lpVtbl->GetFormat(pThis, pFormat, dwSizeAllocated, pSizeWritten); } -HRESULT mal_IDirectSoundBuffer_GetVolume(mal_IDirectSoundBuffer* pThis, LONG* pVolume) { return pThis->lpVtbl->GetVolume(pThis, pVolume); } -HRESULT mal_IDirectSoundBuffer_GetPan(mal_IDirectSoundBuffer* pThis, LONG* pPan) { return pThis->lpVtbl->GetPan(pThis, pPan); } -HRESULT mal_IDirectSoundBuffer_GetFrequency(mal_IDirectSoundBuffer* pThis, DWORD* pFrequency) { return pThis->lpVtbl->GetFrequency(pThis, pFrequency); } -HRESULT mal_IDirectSoundBuffer_GetStatus(mal_IDirectSoundBuffer* pThis, DWORD* pStatus) { return pThis->lpVtbl->GetStatus(pThis, pStatus); } -HRESULT mal_IDirectSoundBuffer_Initialize(mal_IDirectSoundBuffer* pThis, mal_IDirectSound* pDirectSound, const MA_DSBUFFERDESC* pDSBufferDesc) { return pThis->lpVtbl->Initialize(pThis, pDirectSound, pDSBufferDesc); } -HRESULT mal_IDirectSoundBuffer_Lock(mal_IDirectSoundBuffer* pThis, DWORD dwOffset, DWORD dwBytes, void** ppAudioPtr1, DWORD* pAudioBytes1, void** ppAudioPtr2, DWORD* pAudioBytes2, DWORD dwFlags) { return pThis->lpVtbl->Lock(pThis, dwOffset, dwBytes, ppAudioPtr1, pAudioBytes1, ppAudioPtr2, pAudioBytes2, dwFlags); } -HRESULT mal_IDirectSoundBuffer_Play(mal_IDirectSoundBuffer* pThis, DWORD dwReserved1, DWORD dwPriority, DWORD dwFlags) { return pThis->lpVtbl->Play(pThis, dwReserved1, dwPriority, dwFlags); } -HRESULT mal_IDirectSoundBuffer_SetCurrentPosition(mal_IDirectSoundBuffer* pThis, DWORD dwNewPosition) { return pThis->lpVtbl->SetCurrentPosition(pThis, dwNewPosition); } -HRESULT mal_IDirectSoundBuffer_SetFormat(mal_IDirectSoundBuffer* pThis, const WAVEFORMATEX* pFormat) { return pThis->lpVtbl->SetFormat(pThis, pFormat); } -HRESULT mal_IDirectSoundBuffer_SetVolume(mal_IDirectSoundBuffer* pThis, LONG volume) { return pThis->lpVtbl->SetVolume(pThis, volume); } -HRESULT mal_IDirectSoundBuffer_SetPan(mal_IDirectSoundBuffer* pThis, LONG pan) { return pThis->lpVtbl->SetPan(pThis, pan); } -HRESULT mal_IDirectSoundBuffer_SetFrequency(mal_IDirectSoundBuffer* pThis, DWORD dwFrequency) { return pThis->lpVtbl->SetFrequency(pThis, dwFrequency); } -HRESULT mal_IDirectSoundBuffer_Stop(mal_IDirectSoundBuffer* pThis) { return pThis->lpVtbl->Stop(pThis); } -HRESULT mal_IDirectSoundBuffer_Unlock(mal_IDirectSoundBuffer* pThis, void* pAudioPtr1, DWORD dwAudioBytes1, void* pAudioPtr2, DWORD dwAudioBytes2) { return pThis->lpVtbl->Unlock(pThis, pAudioPtr1, dwAudioBytes1, pAudioPtr2, dwAudioBytes2); } -HRESULT mal_IDirectSoundBuffer_Restore(mal_IDirectSoundBuffer* pThis) { return pThis->lpVtbl->Restore(pThis); } +HRESULT ma_IDirectSoundBuffer_QueryInterface(ma_IDirectSoundBuffer* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); } +ULONG ma_IDirectSoundBuffer_AddRef(ma_IDirectSoundBuffer* pThis) { return pThis->lpVtbl->AddRef(pThis); } +ULONG ma_IDirectSoundBuffer_Release(ma_IDirectSoundBuffer* pThis) { return pThis->lpVtbl->Release(pThis); } +HRESULT ma_IDirectSoundBuffer_GetCaps(ma_IDirectSoundBuffer* pThis, MA_DSBCAPS* pDSBufferCaps) { return pThis->lpVtbl->GetCaps(pThis, pDSBufferCaps); } +HRESULT ma_IDirectSoundBuffer_GetCurrentPosition(ma_IDirectSoundBuffer* pThis, DWORD* pCurrentPlayCursor, DWORD* pCurrentWriteCursor) { return pThis->lpVtbl->GetCurrentPosition(pThis, pCurrentPlayCursor, pCurrentWriteCursor); } +HRESULT ma_IDirectSoundBuffer_GetFormat(ma_IDirectSoundBuffer* pThis, WAVEFORMATEX* pFormat, DWORD dwSizeAllocated, DWORD* pSizeWritten) { return pThis->lpVtbl->GetFormat(pThis, pFormat, dwSizeAllocated, pSizeWritten); } +HRESULT ma_IDirectSoundBuffer_GetVolume(ma_IDirectSoundBuffer* pThis, LONG* pVolume) { return pThis->lpVtbl->GetVolume(pThis, pVolume); } +HRESULT ma_IDirectSoundBuffer_GetPan(ma_IDirectSoundBuffer* pThis, LONG* pPan) { return pThis->lpVtbl->GetPan(pThis, pPan); } +HRESULT ma_IDirectSoundBuffer_GetFrequency(ma_IDirectSoundBuffer* pThis, DWORD* pFrequency) { return pThis->lpVtbl->GetFrequency(pThis, pFrequency); } +HRESULT ma_IDirectSoundBuffer_GetStatus(ma_IDirectSoundBuffer* pThis, DWORD* pStatus) { return pThis->lpVtbl->GetStatus(pThis, pStatus); } +HRESULT ma_IDirectSoundBuffer_Initialize(ma_IDirectSoundBuffer* pThis, ma_IDirectSound* pDirectSound, const MA_DSBUFFERDESC* pDSBufferDesc) { return pThis->lpVtbl->Initialize(pThis, pDirectSound, pDSBufferDesc); } +HRESULT ma_IDirectSoundBuffer_Lock(ma_IDirectSoundBuffer* pThis, DWORD dwOffset, DWORD dwBytes, void** ppAudioPtr1, DWORD* pAudioBytes1, void** ppAudioPtr2, DWORD* pAudioBytes2, DWORD dwFlags) { return pThis->lpVtbl->Lock(pThis, dwOffset, dwBytes, ppAudioPtr1, pAudioBytes1, ppAudioPtr2, pAudioBytes2, dwFlags); } +HRESULT ma_IDirectSoundBuffer_Play(ma_IDirectSoundBuffer* pThis, DWORD dwReserved1, DWORD dwPriority, DWORD dwFlags) { return pThis->lpVtbl->Play(pThis, dwReserved1, dwPriority, dwFlags); } +HRESULT ma_IDirectSoundBuffer_SetCurrentPosition(ma_IDirectSoundBuffer* pThis, DWORD dwNewPosition) { return pThis->lpVtbl->SetCurrentPosition(pThis, dwNewPosition); } +HRESULT ma_IDirectSoundBuffer_SetFormat(ma_IDirectSoundBuffer* pThis, const WAVEFORMATEX* pFormat) { return pThis->lpVtbl->SetFormat(pThis, pFormat); } +HRESULT ma_IDirectSoundBuffer_SetVolume(ma_IDirectSoundBuffer* pThis, LONG volume) { return pThis->lpVtbl->SetVolume(pThis, volume); } +HRESULT ma_IDirectSoundBuffer_SetPan(ma_IDirectSoundBuffer* pThis, LONG pan) { return pThis->lpVtbl->SetPan(pThis, pan); } +HRESULT ma_IDirectSoundBuffer_SetFrequency(ma_IDirectSoundBuffer* pThis, DWORD dwFrequency) { return pThis->lpVtbl->SetFrequency(pThis, dwFrequency); } +HRESULT ma_IDirectSoundBuffer_Stop(ma_IDirectSoundBuffer* pThis) { return pThis->lpVtbl->Stop(pThis); } +HRESULT ma_IDirectSoundBuffer_Unlock(ma_IDirectSoundBuffer* pThis, void* pAudioPtr1, DWORD dwAudioBytes1, void* pAudioPtr2, DWORD dwAudioBytes2) { return pThis->lpVtbl->Unlock(pThis, pAudioPtr1, dwAudioBytes1, pAudioPtr2, dwAudioBytes2); } +HRESULT ma_IDirectSoundBuffer_Restore(ma_IDirectSoundBuffer* pThis) { return pThis->lpVtbl->Restore(pThis); } // IDirectSoundCapture typedef struct { // IUnknown - HRESULT (STDMETHODCALLTYPE * QueryInterface)(mal_IDirectSoundCapture* pThis, const IID* const riid, void** ppObject); - ULONG (STDMETHODCALLTYPE * AddRef) (mal_IDirectSoundCapture* pThis); - ULONG (STDMETHODCALLTYPE * Release) (mal_IDirectSoundCapture* pThis); + HRESULT (STDMETHODCALLTYPE * QueryInterface)(ma_IDirectSoundCapture* pThis, const IID* const riid, void** ppObject); + ULONG (STDMETHODCALLTYPE * AddRef) (ma_IDirectSoundCapture* pThis); + ULONG (STDMETHODCALLTYPE * Release) (ma_IDirectSoundCapture* pThis); // IDirectSoundCapture - HRESULT (STDMETHODCALLTYPE * CreateCaptureBuffer)(mal_IDirectSoundCapture* pThis, const MA_DSCBUFFERDESC* pDSCBufferDesc, mal_IDirectSoundCaptureBuffer** ppDSCBuffer, void* pUnkOuter); - HRESULT (STDMETHODCALLTYPE * GetCaps) (mal_IDirectSoundCapture* pThis, MA_DSCCAPS* pDSCCaps); - HRESULT (STDMETHODCALLTYPE * Initialize) (mal_IDirectSoundCapture* pThis, const GUID* pGuidDevice); -} mal_IDirectSoundCaptureVtbl; -struct mal_IDirectSoundCapture + HRESULT (STDMETHODCALLTYPE * CreateCaptureBuffer)(ma_IDirectSoundCapture* pThis, const MA_DSCBUFFERDESC* pDSCBufferDesc, ma_IDirectSoundCaptureBuffer** ppDSCBuffer, void* pUnkOuter); + HRESULT (STDMETHODCALLTYPE * GetCaps) (ma_IDirectSoundCapture* pThis, MA_DSCCAPS* pDSCCaps); + HRESULT (STDMETHODCALLTYPE * Initialize) (ma_IDirectSoundCapture* pThis, const GUID* pGuidDevice); +} ma_IDirectSoundCaptureVtbl; +struct ma_IDirectSoundCapture { - mal_IDirectSoundCaptureVtbl* lpVtbl; + ma_IDirectSoundCaptureVtbl* lpVtbl; }; -HRESULT mal_IDirectSoundCapture_QueryInterface(mal_IDirectSoundCapture* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); } -ULONG mal_IDirectSoundCapture_AddRef(mal_IDirectSoundCapture* pThis) { return pThis->lpVtbl->AddRef(pThis); } -ULONG mal_IDirectSoundCapture_Release(mal_IDirectSoundCapture* pThis) { return pThis->lpVtbl->Release(pThis); } -HRESULT mal_IDirectSoundCapture_CreateCaptureBuffer(mal_IDirectSoundCapture* pThis, const MA_DSCBUFFERDESC* pDSCBufferDesc, mal_IDirectSoundCaptureBuffer** ppDSCBuffer, void* pUnkOuter) { return pThis->lpVtbl->CreateCaptureBuffer(pThis, pDSCBufferDesc, ppDSCBuffer, pUnkOuter); } -HRESULT mal_IDirectSoundCapture_GetCaps (mal_IDirectSoundCapture* pThis, MA_DSCCAPS* pDSCCaps) { return pThis->lpVtbl->GetCaps(pThis, pDSCCaps); } -HRESULT mal_IDirectSoundCapture_Initialize (mal_IDirectSoundCapture* pThis, const GUID* pGuidDevice) { return pThis->lpVtbl->Initialize(pThis, pGuidDevice); } +HRESULT ma_IDirectSoundCapture_QueryInterface(ma_IDirectSoundCapture* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); } +ULONG ma_IDirectSoundCapture_AddRef(ma_IDirectSoundCapture* pThis) { return pThis->lpVtbl->AddRef(pThis); } +ULONG ma_IDirectSoundCapture_Release(ma_IDirectSoundCapture* pThis) { return pThis->lpVtbl->Release(pThis); } +HRESULT ma_IDirectSoundCapture_CreateCaptureBuffer(ma_IDirectSoundCapture* pThis, const MA_DSCBUFFERDESC* pDSCBufferDesc, ma_IDirectSoundCaptureBuffer** ppDSCBuffer, void* pUnkOuter) { return pThis->lpVtbl->CreateCaptureBuffer(pThis, pDSCBufferDesc, ppDSCBuffer, pUnkOuter); } +HRESULT ma_IDirectSoundCapture_GetCaps (ma_IDirectSoundCapture* pThis, MA_DSCCAPS* pDSCCaps) { return pThis->lpVtbl->GetCaps(pThis, pDSCCaps); } +HRESULT ma_IDirectSoundCapture_Initialize (ma_IDirectSoundCapture* pThis, const GUID* pGuidDevice) { return pThis->lpVtbl->Initialize(pThis, pGuidDevice); } // IDirectSoundCaptureBuffer typedef struct { // IUnknown - HRESULT (STDMETHODCALLTYPE * QueryInterface)(mal_IDirectSoundCaptureBuffer* pThis, const IID* const riid, void** ppObject); - ULONG (STDMETHODCALLTYPE * AddRef) (mal_IDirectSoundCaptureBuffer* pThis); - ULONG (STDMETHODCALLTYPE * Release) (mal_IDirectSoundCaptureBuffer* pThis); + HRESULT (STDMETHODCALLTYPE * QueryInterface)(ma_IDirectSoundCaptureBuffer* pThis, const IID* const riid, void** ppObject); + ULONG (STDMETHODCALLTYPE * AddRef) (ma_IDirectSoundCaptureBuffer* pThis); + ULONG (STDMETHODCALLTYPE * Release) (ma_IDirectSoundCaptureBuffer* pThis); // IDirectSoundCaptureBuffer - HRESULT (STDMETHODCALLTYPE * GetCaps) (mal_IDirectSoundCaptureBuffer* pThis, MA_DSCBCAPS* pDSCBCaps); - HRESULT (STDMETHODCALLTYPE * GetCurrentPosition)(mal_IDirectSoundCaptureBuffer* pThis, DWORD* pCapturePosition, DWORD* pReadPosition); - HRESULT (STDMETHODCALLTYPE * GetFormat) (mal_IDirectSoundCaptureBuffer* pThis, WAVEFORMATEX* pFormat, DWORD dwSizeAllocated, DWORD* pSizeWritten); - HRESULT (STDMETHODCALLTYPE * GetStatus) (mal_IDirectSoundCaptureBuffer* pThis, DWORD* pStatus); - HRESULT (STDMETHODCALLTYPE * Initialize) (mal_IDirectSoundCaptureBuffer* pThis, mal_IDirectSoundCapture* pDirectSoundCapture, const MA_DSCBUFFERDESC* pDSCBufferDesc); - HRESULT (STDMETHODCALLTYPE * Lock) (mal_IDirectSoundCaptureBuffer* pThis, DWORD dwOffset, DWORD dwBytes, void** ppAudioPtr1, DWORD* pAudioBytes1, void** ppAudioPtr2, DWORD* pAudioBytes2, DWORD dwFlags); - HRESULT (STDMETHODCALLTYPE * Start) (mal_IDirectSoundCaptureBuffer* pThis, DWORD dwFlags); - HRESULT (STDMETHODCALLTYPE * Stop) (mal_IDirectSoundCaptureBuffer* pThis); - HRESULT (STDMETHODCALLTYPE * Unlock) (mal_IDirectSoundCaptureBuffer* pThis, void* pAudioPtr1, DWORD dwAudioBytes1, void* pAudioPtr2, DWORD dwAudioBytes2); -} mal_IDirectSoundCaptureBufferVtbl; -struct mal_IDirectSoundCaptureBuffer + HRESULT (STDMETHODCALLTYPE * GetCaps) (ma_IDirectSoundCaptureBuffer* pThis, MA_DSCBCAPS* pDSCBCaps); + HRESULT (STDMETHODCALLTYPE * GetCurrentPosition)(ma_IDirectSoundCaptureBuffer* pThis, DWORD* pCapturePosition, DWORD* pReadPosition); + HRESULT (STDMETHODCALLTYPE * GetFormat) (ma_IDirectSoundCaptureBuffer* pThis, WAVEFORMATEX* pFormat, DWORD dwSizeAllocated, DWORD* pSizeWritten); + HRESULT (STDMETHODCALLTYPE * GetStatus) (ma_IDirectSoundCaptureBuffer* pThis, DWORD* pStatus); + HRESULT (STDMETHODCALLTYPE * Initialize) (ma_IDirectSoundCaptureBuffer* pThis, ma_IDirectSoundCapture* pDirectSoundCapture, const MA_DSCBUFFERDESC* pDSCBufferDesc); + HRESULT (STDMETHODCALLTYPE * Lock) (ma_IDirectSoundCaptureBuffer* pThis, DWORD dwOffset, DWORD dwBytes, void** ppAudioPtr1, DWORD* pAudioBytes1, void** ppAudioPtr2, DWORD* pAudioBytes2, DWORD dwFlags); + HRESULT (STDMETHODCALLTYPE * Start) (ma_IDirectSoundCaptureBuffer* pThis, DWORD dwFlags); + HRESULT (STDMETHODCALLTYPE * Stop) (ma_IDirectSoundCaptureBuffer* pThis); + HRESULT (STDMETHODCALLTYPE * Unlock) (ma_IDirectSoundCaptureBuffer* pThis, void* pAudioPtr1, DWORD dwAudioBytes1, void* pAudioPtr2, DWORD dwAudioBytes2); +} ma_IDirectSoundCaptureBufferVtbl; +struct ma_IDirectSoundCaptureBuffer { - mal_IDirectSoundCaptureBufferVtbl* lpVtbl; + ma_IDirectSoundCaptureBufferVtbl* lpVtbl; }; -HRESULT mal_IDirectSoundCaptureBuffer_QueryInterface(mal_IDirectSoundCaptureBuffer* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); } -ULONG mal_IDirectSoundCaptureBuffer_AddRef(mal_IDirectSoundCaptureBuffer* pThis) { return pThis->lpVtbl->AddRef(pThis); } -ULONG mal_IDirectSoundCaptureBuffer_Release(mal_IDirectSoundCaptureBuffer* pThis) { return pThis->lpVtbl->Release(pThis); } -HRESULT mal_IDirectSoundCaptureBuffer_GetCaps(mal_IDirectSoundCaptureBuffer* pThis, MA_DSCBCAPS* pDSCBCaps) { return pThis->lpVtbl->GetCaps(pThis, pDSCBCaps); } -HRESULT mal_IDirectSoundCaptureBuffer_GetCurrentPosition(mal_IDirectSoundCaptureBuffer* pThis, DWORD* pCapturePosition, DWORD* pReadPosition) { return pThis->lpVtbl->GetCurrentPosition(pThis, pCapturePosition, pReadPosition); } -HRESULT mal_IDirectSoundCaptureBuffer_GetFormat(mal_IDirectSoundCaptureBuffer* pThis, WAVEFORMATEX* pFormat, DWORD dwSizeAllocated, DWORD* pSizeWritten) { return pThis->lpVtbl->GetFormat(pThis, pFormat, dwSizeAllocated, pSizeWritten); } -HRESULT mal_IDirectSoundCaptureBuffer_GetStatus(mal_IDirectSoundCaptureBuffer* pThis, DWORD* pStatus) { return pThis->lpVtbl->GetStatus(pThis, pStatus); } -HRESULT mal_IDirectSoundCaptureBuffer_Initialize(mal_IDirectSoundCaptureBuffer* pThis, mal_IDirectSoundCapture* pDirectSoundCapture, const MA_DSCBUFFERDESC* pDSCBufferDesc) { return pThis->lpVtbl->Initialize(pThis, pDirectSoundCapture, pDSCBufferDesc); } -HRESULT mal_IDirectSoundCaptureBuffer_Lock(mal_IDirectSoundCaptureBuffer* pThis, DWORD dwOffset, DWORD dwBytes, void** ppAudioPtr1, DWORD* pAudioBytes1, void** ppAudioPtr2, DWORD* pAudioBytes2, DWORD dwFlags) { return pThis->lpVtbl->Lock(pThis, dwOffset, dwBytes, ppAudioPtr1, pAudioBytes1, ppAudioPtr2, pAudioBytes2, dwFlags); } -HRESULT mal_IDirectSoundCaptureBuffer_Start(mal_IDirectSoundCaptureBuffer* pThis, DWORD dwFlags) { return pThis->lpVtbl->Start(pThis, dwFlags); } -HRESULT mal_IDirectSoundCaptureBuffer_Stop(mal_IDirectSoundCaptureBuffer* pThis) { return pThis->lpVtbl->Stop(pThis); } -HRESULT mal_IDirectSoundCaptureBuffer_Unlock(mal_IDirectSoundCaptureBuffer* pThis, void* pAudioPtr1, DWORD dwAudioBytes1, void* pAudioPtr2, DWORD dwAudioBytes2) { return pThis->lpVtbl->Unlock(pThis, pAudioPtr1, dwAudioBytes1, pAudioPtr2, dwAudioBytes2); } +HRESULT ma_IDirectSoundCaptureBuffer_QueryInterface(ma_IDirectSoundCaptureBuffer* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); } +ULONG ma_IDirectSoundCaptureBuffer_AddRef(ma_IDirectSoundCaptureBuffer* pThis) { return pThis->lpVtbl->AddRef(pThis); } +ULONG ma_IDirectSoundCaptureBuffer_Release(ma_IDirectSoundCaptureBuffer* pThis) { return pThis->lpVtbl->Release(pThis); } +HRESULT ma_IDirectSoundCaptureBuffer_GetCaps(ma_IDirectSoundCaptureBuffer* pThis, MA_DSCBCAPS* pDSCBCaps) { return pThis->lpVtbl->GetCaps(pThis, pDSCBCaps); } +HRESULT ma_IDirectSoundCaptureBuffer_GetCurrentPosition(ma_IDirectSoundCaptureBuffer* pThis, DWORD* pCapturePosition, DWORD* pReadPosition) { return pThis->lpVtbl->GetCurrentPosition(pThis, pCapturePosition, pReadPosition); } +HRESULT ma_IDirectSoundCaptureBuffer_GetFormat(ma_IDirectSoundCaptureBuffer* pThis, WAVEFORMATEX* pFormat, DWORD dwSizeAllocated, DWORD* pSizeWritten) { return pThis->lpVtbl->GetFormat(pThis, pFormat, dwSizeAllocated, pSizeWritten); } +HRESULT ma_IDirectSoundCaptureBuffer_GetStatus(ma_IDirectSoundCaptureBuffer* pThis, DWORD* pStatus) { return pThis->lpVtbl->GetStatus(pThis, pStatus); } +HRESULT ma_IDirectSoundCaptureBuffer_Initialize(ma_IDirectSoundCaptureBuffer* pThis, ma_IDirectSoundCapture* pDirectSoundCapture, const MA_DSCBUFFERDESC* pDSCBufferDesc) { return pThis->lpVtbl->Initialize(pThis, pDirectSoundCapture, pDSCBufferDesc); } +HRESULT ma_IDirectSoundCaptureBuffer_Lock(ma_IDirectSoundCaptureBuffer* pThis, DWORD dwOffset, DWORD dwBytes, void** ppAudioPtr1, DWORD* pAudioBytes1, void** ppAudioPtr2, DWORD* pAudioBytes2, DWORD dwFlags) { return pThis->lpVtbl->Lock(pThis, dwOffset, dwBytes, ppAudioPtr1, pAudioBytes1, ppAudioPtr2, pAudioBytes2, dwFlags); } +HRESULT ma_IDirectSoundCaptureBuffer_Start(ma_IDirectSoundCaptureBuffer* pThis, DWORD dwFlags) { return pThis->lpVtbl->Start(pThis, dwFlags); } +HRESULT ma_IDirectSoundCaptureBuffer_Stop(ma_IDirectSoundCaptureBuffer* pThis) { return pThis->lpVtbl->Stop(pThis); } +HRESULT ma_IDirectSoundCaptureBuffer_Unlock(ma_IDirectSoundCaptureBuffer* pThis, void* pAudioPtr1, DWORD dwAudioBytes1, void* pAudioPtr2, DWORD dwAudioBytes2) { return pThis->lpVtbl->Unlock(pThis, pAudioPtr1, dwAudioBytes1, pAudioPtr2, dwAudioBytes2); } // IDirectSoundNotify typedef struct { // IUnknown - HRESULT (STDMETHODCALLTYPE * QueryInterface)(mal_IDirectSoundNotify* pThis, const IID* const riid, void** ppObject); - ULONG (STDMETHODCALLTYPE * AddRef) (mal_IDirectSoundNotify* pThis); - ULONG (STDMETHODCALLTYPE * Release) (mal_IDirectSoundNotify* pThis); + HRESULT (STDMETHODCALLTYPE * QueryInterface)(ma_IDirectSoundNotify* pThis, const IID* const riid, void** ppObject); + ULONG (STDMETHODCALLTYPE * AddRef) (ma_IDirectSoundNotify* pThis); + ULONG (STDMETHODCALLTYPE * Release) (ma_IDirectSoundNotify* pThis); // IDirectSoundNotify - HRESULT (STDMETHODCALLTYPE * SetNotificationPositions)(mal_IDirectSoundNotify* pThis, DWORD dwPositionNotifies, const MA_DSBPOSITIONNOTIFY* pPositionNotifies); -} mal_IDirectSoundNotifyVtbl; -struct mal_IDirectSoundNotify + HRESULT (STDMETHODCALLTYPE * SetNotificationPositions)(ma_IDirectSoundNotify* pThis, DWORD dwPositionNotifies, const MA_DSBPOSITIONNOTIFY* pPositionNotifies); +} ma_IDirectSoundNotifyVtbl; +struct ma_IDirectSoundNotify { - mal_IDirectSoundNotifyVtbl* lpVtbl; + ma_IDirectSoundNotifyVtbl* lpVtbl; }; -HRESULT mal_IDirectSoundNotify_QueryInterface(mal_IDirectSoundNotify* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); } -ULONG mal_IDirectSoundNotify_AddRef(mal_IDirectSoundNotify* pThis) { return pThis->lpVtbl->AddRef(pThis); } -ULONG mal_IDirectSoundNotify_Release(mal_IDirectSoundNotify* pThis) { return pThis->lpVtbl->Release(pThis); } -HRESULT mal_IDirectSoundNotify_SetNotificationPositions(mal_IDirectSoundNotify* pThis, DWORD dwPositionNotifies, const MA_DSBPOSITIONNOTIFY* pPositionNotifies) { return pThis->lpVtbl->SetNotificationPositions(pThis, dwPositionNotifies, pPositionNotifies); } +HRESULT ma_IDirectSoundNotify_QueryInterface(ma_IDirectSoundNotify* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); } +ULONG ma_IDirectSoundNotify_AddRef(ma_IDirectSoundNotify* pThis) { return pThis->lpVtbl->AddRef(pThis); } +ULONG ma_IDirectSoundNotify_Release(ma_IDirectSoundNotify* pThis) { return pThis->lpVtbl->Release(pThis); } +HRESULT ma_IDirectSoundNotify_SetNotificationPositions(ma_IDirectSoundNotify* pThis, DWORD dwPositionNotifies, const MA_DSBPOSITIONNOTIFY* pPositionNotifies) { return pThis->lpVtbl->SetNotificationPositions(pThis, dwPositionNotifies, pPositionNotifies); } -typedef BOOL (CALLBACK * mal_DSEnumCallbackAProc) (LPGUID pDeviceGUID, LPCSTR pDeviceDescription, LPCSTR pModule, LPVOID pContext); -typedef HRESULT (WINAPI * mal_DirectSoundCreateProc) (const GUID* pcGuidDevice, mal_IDirectSound** ppDS8, LPUNKNOWN pUnkOuter); -typedef HRESULT (WINAPI * mal_DirectSoundEnumerateAProc) (mal_DSEnumCallbackAProc pDSEnumCallback, LPVOID pContext); -typedef HRESULT (WINAPI * mal_DirectSoundCaptureCreateProc) (const GUID* pcGuidDevice, mal_IDirectSoundCapture** ppDSC8, LPUNKNOWN pUnkOuter); -typedef HRESULT (WINAPI * mal_DirectSoundCaptureEnumerateAProc)(mal_DSEnumCallbackAProc pDSEnumCallback, LPVOID pContext); +typedef BOOL (CALLBACK * ma_DSEnumCallbackAProc) (LPGUID pDeviceGUID, LPCSTR pDeviceDescription, LPCSTR pModule, LPVOID pContext); +typedef HRESULT (WINAPI * ma_DirectSoundCreateProc) (const GUID* pcGuidDevice, ma_IDirectSound** ppDS8, LPUNKNOWN pUnkOuter); +typedef HRESULT (WINAPI * ma_DirectSoundEnumerateAProc) (ma_DSEnumCallbackAProc pDSEnumCallback, LPVOID pContext); +typedef HRESULT (WINAPI * ma_DirectSoundCaptureCreateProc) (const GUID* pcGuidDevice, ma_IDirectSoundCapture** ppDSC8, LPUNKNOWN pUnkOuter); +typedef HRESULT (WINAPI * ma_DirectSoundCaptureEnumerateAProc)(ma_DSEnumCallbackAProc pDSEnumCallback, LPVOID pContext); // Retrieves the channel count and channel map for the given speaker configuration. If the speaker configuration is unknown, // the channel count and channel map will be left unmodified. -void mal_get_channels_from_speaker_config__dsound(DWORD speakerConfig, WORD* pChannelsOut, DWORD* pChannelMapOut) +void ma_get_channels_from_speaker_config__dsound(DWORD speakerConfig, WORD* pChannelsOut, DWORD* pChannelMapOut) { WORD channels = 0; if (pChannelsOut != NULL) { @@ -8729,16 +8729,16 @@ void mal_get_channels_from_speaker_config__dsound(DWORD speakerConfig, WORD* pCh } -mal_result mal_context_create_IDirectSound__dsound(mal_context* pContext, mal_share_mode shareMode, const mal_device_id* pDeviceID, mal_IDirectSound** ppDirectSound) +ma_result ma_context_create_IDirectSound__dsound(ma_context* pContext, ma_share_mode shareMode, const ma_device_id* pDeviceID, ma_IDirectSound** ppDirectSound) { - mal_assert(pContext != NULL); - mal_assert(ppDirectSound != NULL); + ma_assert(pContext != NULL); + ma_assert(ppDirectSound != NULL); *ppDirectSound = NULL; - mal_IDirectSound* pDirectSound = NULL; + ma_IDirectSound* pDirectSound = NULL; - if (FAILED(((mal_DirectSoundCreateProc)pContext->dsound.DirectSoundCreate)((pDeviceID == NULL) ? NULL : (const GUID*)pDeviceID->dsound, &pDirectSound, NULL))) { - return mal_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[DirectSound] DirectSoundCreate() failed for playback device.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + if (FAILED(((ma_DirectSoundCreateProc)pContext->dsound.DirectSoundCreate)((pDeviceID == NULL) ? NULL : (const GUID*)pDeviceID->dsound, &pDirectSound, NULL))) { + return ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[DirectSound] DirectSoundCreate() failed for playback device.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } // The cooperative level must be set before doing anything else. @@ -8746,39 +8746,39 @@ mal_result mal_context_create_IDirectSound__dsound(mal_context* pContext, mal_sh if (hWnd == NULL) { hWnd = ((MA_PFN_GetDesktopWindow)pContext->win32.GetDesktopWindow)(); } - if (FAILED(mal_IDirectSound_SetCooperativeLevel(pDirectSound, hWnd, (shareMode == mal_share_mode_exclusive) ? MA_DSSCL_EXCLUSIVE : MA_DSSCL_PRIORITY))) { - return mal_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[DirectSound] IDirectSound_SetCooperateiveLevel() failed for playback device.", MA_SHARE_MODE_NOT_SUPPORTED); + if (FAILED(ma_IDirectSound_SetCooperativeLevel(pDirectSound, hWnd, (shareMode == ma_share_mode_exclusive) ? MA_DSSCL_EXCLUSIVE : MA_DSSCL_PRIORITY))) { + return ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[DirectSound] IDirectSound_SetCooperateiveLevel() failed for playback device.", MA_SHARE_MODE_NOT_SUPPORTED); } *ppDirectSound = pDirectSound; return MA_SUCCESS; } -mal_result mal_context_create_IDirectSoundCapture__dsound(mal_context* pContext, mal_share_mode shareMode, const mal_device_id* pDeviceID, mal_IDirectSoundCapture** ppDirectSoundCapture) +ma_result ma_context_create_IDirectSoundCapture__dsound(ma_context* pContext, ma_share_mode shareMode, const ma_device_id* pDeviceID, ma_IDirectSoundCapture** ppDirectSoundCapture) { - mal_assert(pContext != NULL); - mal_assert(ppDirectSoundCapture != NULL); + ma_assert(pContext != NULL); + ma_assert(ppDirectSoundCapture != NULL); /* DirectSound does not support exclusive mode for capture. */ - if (shareMode == mal_share_mode_exclusive) { + if (shareMode == ma_share_mode_exclusive) { return MA_SHARE_MODE_NOT_SUPPORTED; } *ppDirectSoundCapture = NULL; - mal_IDirectSoundCapture* pDirectSoundCapture = NULL; + ma_IDirectSoundCapture* pDirectSoundCapture = NULL; - if (FAILED(((mal_DirectSoundCaptureCreateProc)pContext->dsound.DirectSoundCaptureCreate)((pDeviceID == NULL) ? NULL : (const GUID*)pDeviceID->dsound, &pDirectSoundCapture, NULL))) { - return mal_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[DirectSound] DirectSoundCaptureCreate() failed for capture device.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + if (FAILED(((ma_DirectSoundCaptureCreateProc)pContext->dsound.DirectSoundCaptureCreate)((pDeviceID == NULL) ? NULL : (const GUID*)pDeviceID->dsound, &pDirectSoundCapture, NULL))) { + return ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[DirectSound] DirectSoundCaptureCreate() failed for capture device.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } *ppDirectSoundCapture = pDirectSoundCapture; return MA_SUCCESS; } -mal_result mal_context_get_format_info_for_IDirectSoundCapture__dsound(mal_context* pContext, mal_IDirectSoundCapture* pDirectSoundCapture, WORD* pChannels, WORD* pBitsPerSample, DWORD* pSampleRate) +ma_result ma_context_get_format_info_for_IDirectSoundCapture__dsound(ma_context* pContext, ma_IDirectSoundCapture* pDirectSoundCapture, WORD* pChannels, WORD* pBitsPerSample, DWORD* pSampleRate) { - mal_assert(pContext != NULL); - mal_assert(pDirectSoundCapture != NULL); + ma_assert(pContext != NULL); + ma_assert(pDirectSoundCapture != NULL); if (pChannels) { *pChannels = 0; @@ -8791,10 +8791,10 @@ mal_result mal_context_get_format_info_for_IDirectSoundCapture__dsound(mal_conte } MA_DSCCAPS caps; - mal_zero_object(&caps); + ma_zero_object(&caps); caps.dwSize = sizeof(caps); - if (FAILED(mal_IDirectSoundCapture_GetCaps(pDirectSoundCapture, &caps))) { - return mal_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[DirectSound] IDirectSoundCapture_GetCaps() failed for capture device.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + if (FAILED(ma_IDirectSoundCapture_GetCaps(pDirectSoundCapture, &caps))) { + return ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[DirectSound] IDirectSoundCapture_GetCaps() failed for capture device.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } if (pChannels) { @@ -8872,11 +8872,11 @@ mal_result mal_context_get_format_info_for_IDirectSoundCapture__dsound(mal_conte return MA_SUCCESS; } -mal_bool32 mal_context_is_device_id_equal__dsound(mal_context* pContext, const mal_device_id* pID0, const mal_device_id* pID1) +ma_bool32 ma_context_is_device_id_equal__dsound(ma_context* pContext, const ma_device_id* pID0, const ma_device_id* pID1) { - mal_assert(pContext != NULL); - mal_assert(pID0 != NULL); - mal_assert(pID1 != NULL); + ma_assert(pContext != NULL); + ma_assert(pID0 != NULL); + ma_assert(pID1 != NULL); (void)pContext; return memcmp(pID0->dsound, pID1->dsound, sizeof(pID0->dsound)) == 0; @@ -8885,32 +8885,32 @@ mal_bool32 mal_context_is_device_id_equal__dsound(mal_context* pContext, const m typedef struct { - mal_context* pContext; - mal_device_type deviceType; - mal_enum_devices_callback_proc callback; + ma_context* pContext; + ma_device_type deviceType; + ma_enum_devices_callback_proc callback; void* pUserData; - mal_bool32 terminated; -} mal_context_enumerate_devices_callback_data__dsound; + ma_bool32 terminated; +} ma_context_enumerate_devices_callback_data__dsound; -BOOL CALLBACK mal_context_enumerate_devices_callback__dsound(LPGUID lpGuid, LPCSTR lpcstrDescription, LPCSTR lpcstrModule, LPVOID lpContext) +BOOL CALLBACK ma_context_enumerate_devices_callback__dsound(LPGUID lpGuid, LPCSTR lpcstrDescription, LPCSTR lpcstrModule, LPVOID lpContext) { (void)lpcstrModule; - mal_context_enumerate_devices_callback_data__dsound* pData = (mal_context_enumerate_devices_callback_data__dsound*)lpContext; - mal_assert(pData != NULL); + ma_context_enumerate_devices_callback_data__dsound* pData = (ma_context_enumerate_devices_callback_data__dsound*)lpContext; + ma_assert(pData != NULL); - mal_device_info deviceInfo; - mal_zero_object(&deviceInfo); + ma_device_info deviceInfo; + ma_zero_object(&deviceInfo); // ID. if (lpGuid != NULL) { - mal_copy_memory(deviceInfo.id.dsound, lpGuid, 16); + ma_copy_memory(deviceInfo.id.dsound, lpGuid, 16); } else { - mal_zero_memory(deviceInfo.id.dsound, 16); + ma_zero_memory(deviceInfo.id.dsound, 16); } // Name / Description - mal_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), lpcstrDescription, (size_t)-1); + ma_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), lpcstrDescription, (size_t)-1); // Call the callback function, but make sure we stop enumerating if the callee requested so. @@ -8922,12 +8922,12 @@ BOOL CALLBACK mal_context_enumerate_devices_callback__dsound(LPGUID lpGuid, LPCS } } -mal_result mal_context_enumerate_devices__dsound(mal_context* pContext, mal_enum_devices_callback_proc callback, void* pUserData) +ma_result ma_context_enumerate_devices__dsound(ma_context* pContext, ma_enum_devices_callback_proc callback, void* pUserData) { - mal_assert(pContext != NULL); - mal_assert(callback != NULL); + ma_assert(pContext != NULL); + ma_assert(callback != NULL); - mal_context_enumerate_devices_callback_data__dsound data; + ma_context_enumerate_devices_callback_data__dsound data; data.pContext = pContext; data.callback = callback; data.pUserData = pUserData; @@ -8935,14 +8935,14 @@ mal_result mal_context_enumerate_devices__dsound(mal_context* pContext, mal_enum // Playback. if (!data.terminated) { - data.deviceType = mal_device_type_playback; - ((mal_DirectSoundEnumerateAProc)pContext->dsound.DirectSoundEnumerateA)(mal_context_enumerate_devices_callback__dsound, &data); + data.deviceType = ma_device_type_playback; + ((ma_DirectSoundEnumerateAProc)pContext->dsound.DirectSoundEnumerateA)(ma_context_enumerate_devices_callback__dsound, &data); } // Capture. if (!data.terminated) { - data.deviceType = mal_device_type_capture; - ((mal_DirectSoundCaptureEnumerateAProc)pContext->dsound.DirectSoundCaptureEnumerateA)(mal_context_enumerate_devices_callback__dsound, &data); + data.deviceType = ma_device_type_capture; + ((ma_DirectSoundCaptureEnumerateAProc)pContext->dsound.DirectSoundCaptureEnumerateA)(ma_context_enumerate_devices_callback__dsound, &data); } return MA_SUCCESS; @@ -8951,28 +8951,28 @@ mal_result mal_context_enumerate_devices__dsound(mal_context* pContext, mal_enum typedef struct { - const mal_device_id* pDeviceID; - mal_device_info* pDeviceInfo; - mal_bool32 found; -} mal_context_get_device_info_callback_data__dsound; + const ma_device_id* pDeviceID; + ma_device_info* pDeviceInfo; + ma_bool32 found; +} ma_context_get_device_info_callback_data__dsound; -BOOL CALLBACK mal_context_get_device_info_callback__dsound(LPGUID lpGuid, LPCSTR lpcstrDescription, LPCSTR lpcstrModule, LPVOID lpContext) +BOOL CALLBACK ma_context_get_device_info_callback__dsound(LPGUID lpGuid, LPCSTR lpcstrDescription, LPCSTR lpcstrModule, LPVOID lpContext) { (void)lpcstrModule; - mal_context_get_device_info_callback_data__dsound* pData = (mal_context_get_device_info_callback_data__dsound*)lpContext; - mal_assert(pData != NULL); + ma_context_get_device_info_callback_data__dsound* pData = (ma_context_get_device_info_callback_data__dsound*)lpContext; + ma_assert(pData != NULL); - if ((pData->pDeviceID == NULL || mal_is_guid_equal(pData->pDeviceID->dsound, &MA_GUID_NULL)) && (lpGuid == NULL || mal_is_guid_equal(lpGuid, &MA_GUID_NULL))) { + if ((pData->pDeviceID == NULL || ma_is_guid_equal(pData->pDeviceID->dsound, &MA_GUID_NULL)) && (lpGuid == NULL || ma_is_guid_equal(lpGuid, &MA_GUID_NULL))) { // Default device. - mal_strncpy_s(pData->pDeviceInfo->name, sizeof(pData->pDeviceInfo->name), lpcstrDescription, (size_t)-1); + ma_strncpy_s(pData->pDeviceInfo->name, sizeof(pData->pDeviceInfo->name), lpcstrDescription, (size_t)-1); pData->found = MA_TRUE; return FALSE; // Stop enumeration. } else { // Not the default device. if (lpGuid != NULL) { if (memcmp(pData->pDeviceID->dsound, lpGuid, sizeof(pData->pDeviceID->dsound)) == 0) { - mal_strncpy_s(pData->pDeviceInfo->name, sizeof(pData->pDeviceInfo->name), lpcstrDescription, (size_t)-1); + ma_strncpy_s(pData->pDeviceInfo->name, sizeof(pData->pDeviceInfo->name), lpcstrDescription, (size_t)-1); pData->found = MA_TRUE; return FALSE; // Stop enumeration. } @@ -8982,26 +8982,26 @@ BOOL CALLBACK mal_context_get_device_info_callback__dsound(LPGUID lpGuid, LPCSTR return TRUE; } -mal_result mal_context_get_device_info__dsound(mal_context* pContext, mal_device_type deviceType, const mal_device_id* pDeviceID, mal_share_mode shareMode, mal_device_info* pDeviceInfo) +ma_result ma_context_get_device_info__dsound(ma_context* pContext, ma_device_type deviceType, const ma_device_id* pDeviceID, ma_share_mode shareMode, ma_device_info* pDeviceInfo) { /* Exclusive mode and capture not supported with DirectSound. */ - if (deviceType == mal_device_type_capture && shareMode == mal_share_mode_exclusive) { + if (deviceType == ma_device_type_capture && shareMode == ma_share_mode_exclusive) { return MA_SHARE_MODE_NOT_SUPPORTED; } if (pDeviceID != NULL) { // ID. - mal_copy_memory(pDeviceInfo->id.dsound, pDeviceID->dsound, 16); + ma_copy_memory(pDeviceInfo->id.dsound, pDeviceID->dsound, 16); // Name / Description. This is retrieved by enumerating over each device until we find that one that matches the input ID. - mal_context_get_device_info_callback_data__dsound data; + ma_context_get_device_info_callback_data__dsound data; data.pDeviceID = pDeviceID; data.pDeviceInfo = pDeviceInfo; data.found = MA_FALSE; - if (deviceType == mal_device_type_playback) { - ((mal_DirectSoundEnumerateAProc)pContext->dsound.DirectSoundEnumerateA)(mal_context_get_device_info_callback__dsound, &data); + if (deviceType == ma_device_type_playback) { + ((ma_DirectSoundEnumerateAProc)pContext->dsound.DirectSoundEnumerateA)(ma_context_get_device_info_callback__dsound, &data); } else { - ((mal_DirectSoundCaptureEnumerateAProc)pContext->dsound.DirectSoundCaptureEnumerateA)(mal_context_get_device_info_callback__dsound, &data); + ((ma_DirectSoundCaptureEnumerateAProc)pContext->dsound.DirectSoundCaptureEnumerateA)(ma_context_get_device_info_callback__dsound, &data); } if (!data.found) { @@ -9011,30 +9011,30 @@ mal_result mal_context_get_device_info__dsound(mal_context* pContext, mal_device // I don't think there's a way to get the name of the default device with DirectSound. In this case we just need to use defaults. // ID - mal_zero_memory(pDeviceInfo->id.dsound, 16); + ma_zero_memory(pDeviceInfo->id.dsound, 16); // Name / Description/ - if (deviceType == mal_device_type_playback) { - mal_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), MA_DEFAULT_PLAYBACK_DEVICE_NAME, (size_t)-1); + if (deviceType == ma_device_type_playback) { + ma_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), MA_DEFAULT_PLAYBACK_DEVICE_NAME, (size_t)-1); } else { - mal_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), MA_DEFAULT_CAPTURE_DEVICE_NAME, (size_t)-1); + ma_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), MA_DEFAULT_CAPTURE_DEVICE_NAME, (size_t)-1); } } // Retrieving detailed information is slightly different depending on the device type. - if (deviceType == mal_device_type_playback) { + if (deviceType == ma_device_type_playback) { // Playback. - mal_IDirectSound* pDirectSound; - mal_result result = mal_context_create_IDirectSound__dsound(pContext, shareMode, pDeviceID, &pDirectSound); + ma_IDirectSound* pDirectSound; + ma_result result = ma_context_create_IDirectSound__dsound(pContext, shareMode, pDeviceID, &pDirectSound); if (result != MA_SUCCESS) { return result; } MA_DSCAPS caps; - mal_zero_object(&caps); + ma_zero_object(&caps); caps.dwSize = sizeof(caps); - if (FAILED(mal_IDirectSound_GetCaps(pDirectSound, &caps))) { - return mal_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[DirectSound] IDirectSound_GetCaps() failed for playback device.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + if (FAILED(ma_IDirectSound_GetCaps(pDirectSound, &caps))) { + return ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[DirectSound] IDirectSound_GetCaps() failed for playback device.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } if ((caps.dwFlags & MA_DSCAPS_PRIMARYSTEREO) != 0) { @@ -9043,8 +9043,8 @@ mal_result mal_context_get_device_info__dsound(mal_context* pContext, mal_device // Look at the speaker configuration to get a better idea on the channel count. DWORD speakerConfig; - if (SUCCEEDED(mal_IDirectSound_GetSpeakerConfig(pDirectSound, &speakerConfig))) { - mal_get_channels_from_speaker_config__dsound(speakerConfig, &channels, NULL); + if (SUCCEEDED(ma_IDirectSound_GetSpeakerConfig(pDirectSound, &speakerConfig))) { + ma_get_channels_from_speaker_config__dsound(speakerConfig, &channels, NULL); } pDeviceInfo->minChannels = channels; @@ -9075,18 +9075,18 @@ mal_result mal_context_get_device_info__dsound(mal_context* pContext, mal_device } // DirectSound can support all formats. - pDeviceInfo->formatCount = mal_format_count - 1; // Minus one because we don't want to include mal_format_unknown. - for (mal_uint32 iFormat = 0; iFormat < pDeviceInfo->formatCount; ++iFormat) { - pDeviceInfo->formats[iFormat] = (mal_format)(iFormat + 1); // +1 to skip over mal_format_unknown. + pDeviceInfo->formatCount = ma_format_count - 1; // Minus one because we don't want to include ma_format_unknown. + for (ma_uint32 iFormat = 0; iFormat < pDeviceInfo->formatCount; ++iFormat) { + pDeviceInfo->formats[iFormat] = (ma_format)(iFormat + 1); // +1 to skip over ma_format_unknown. } - mal_IDirectSound_Release(pDirectSound); + ma_IDirectSound_Release(pDirectSound); } else { // Capture. This is a little different to playback due to the say the supported formats are reported. Technically capture - // devices can support a number of different formats, but for simplicity and consistency with mal_device_init() I'm just + // devices can support a number of different formats, but for simplicity and consistency with ma_device_init() I'm just // reporting the best format. - mal_IDirectSoundCapture* pDirectSoundCapture; - mal_result result = mal_context_create_IDirectSoundCapture__dsound(pContext, shareMode, pDeviceID, &pDirectSoundCapture); + ma_IDirectSoundCapture* pDirectSoundCapture; + ma_result result = ma_context_create_IDirectSoundCapture__dsound(pContext, shareMode, pDeviceID, &pDirectSoundCapture); if (result != MA_SUCCESS) { return result; } @@ -9094,9 +9094,9 @@ mal_result mal_context_get_device_info__dsound(mal_context* pContext, mal_device WORD channels; WORD bitsPerSample; DWORD sampleRate; - result = mal_context_get_format_info_for_IDirectSoundCapture__dsound(pContext, pDirectSoundCapture, &channels, &bitsPerSample, &sampleRate); + result = ma_context_get_format_info_for_IDirectSoundCapture__dsound(pContext, pDirectSoundCapture, &channels, &bitsPerSample, &sampleRate); if (result != MA_SUCCESS) { - mal_IDirectSoundCapture_Release(pDirectSoundCapture); + ma_IDirectSoundCapture_Release(pDirectSoundCapture); return result; } @@ -9106,19 +9106,19 @@ mal_result mal_context_get_device_info__dsound(mal_context* pContext, mal_device pDeviceInfo->maxSampleRate = sampleRate; pDeviceInfo->formatCount = 1; if (bitsPerSample == 8) { - pDeviceInfo->formats[0] = mal_format_u8; + pDeviceInfo->formats[0] = ma_format_u8; } else if (bitsPerSample == 16) { - pDeviceInfo->formats[0] = mal_format_s16; + pDeviceInfo->formats[0] = ma_format_s16; } else if (bitsPerSample == 24) { - pDeviceInfo->formats[0] = mal_format_s24; + pDeviceInfo->formats[0] = ma_format_s24; } else if (bitsPerSample == 32) { - pDeviceInfo->formats[0] = mal_format_s32; + pDeviceInfo->formats[0] = ma_format_s32; } else { - mal_IDirectSoundCapture_Release(pDirectSoundCapture); + ma_IDirectSoundCapture_Release(pDirectSoundCapture); return MA_FORMAT_NOT_SUPPORTED; } - mal_IDirectSoundCapture_Release(pDirectSoundCapture); + ma_IDirectSoundCapture_Release(pDirectSoundCapture); } return MA_SUCCESS; @@ -9127,27 +9127,27 @@ mal_result mal_context_get_device_info__dsound(mal_context* pContext, mal_device typedef struct { - mal_uint32 deviceCount; - mal_uint32 infoCount; - mal_device_info* pInfo; -} mal_device_enum_data__dsound; + ma_uint32 deviceCount; + ma_uint32 infoCount; + ma_device_info* pInfo; +} ma_device_enum_data__dsound; -BOOL CALLBACK mal_enum_devices_callback__dsound(LPGUID lpGuid, LPCSTR lpcstrDescription, LPCSTR lpcstrModule, LPVOID lpContext) +BOOL CALLBACK ma_enum_devices_callback__dsound(LPGUID lpGuid, LPCSTR lpcstrDescription, LPCSTR lpcstrModule, LPVOID lpContext) { (void)lpcstrModule; - mal_device_enum_data__dsound* pData = (mal_device_enum_data__dsound*)lpContext; - mal_assert(pData != NULL); + ma_device_enum_data__dsound* pData = (ma_device_enum_data__dsound*)lpContext; + ma_assert(pData != NULL); if (pData->pInfo != NULL) { if (pData->infoCount > 0) { - mal_zero_object(pData->pInfo); - mal_strncpy_s(pData->pInfo->name, sizeof(pData->pInfo->name), lpcstrDescription, (size_t)-1); + ma_zero_object(pData->pInfo); + ma_strncpy_s(pData->pInfo->name, sizeof(pData->pInfo->name), lpcstrDescription, (size_t)-1); if (lpGuid != NULL) { - mal_copy_memory(pData->pInfo->id.dsound, lpGuid, 16); + ma_copy_memory(pData->pInfo->id.dsound, lpGuid, 16); } else { - mal_zero_memory(pData->pInfo->id.dsound, 16); + ma_zero_memory(pData->pInfo->id.dsound, 16); } pData->pInfo += 1; @@ -9161,43 +9161,43 @@ BOOL CALLBACK mal_enum_devices_callback__dsound(LPGUID lpGuid, LPCSTR lpcstrDesc return TRUE; } -void mal_device_uninit__dsound(mal_device* pDevice) +void ma_device_uninit__dsound(ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); if (pDevice->dsound.pCaptureBuffer != NULL) { - mal_IDirectSoundCaptureBuffer_Release((mal_IDirectSoundCaptureBuffer*)pDevice->dsound.pCaptureBuffer); + ma_IDirectSoundCaptureBuffer_Release((ma_IDirectSoundCaptureBuffer*)pDevice->dsound.pCaptureBuffer); } if (pDevice->dsound.pCapture != NULL) { - mal_IDirectSoundCapture_Release((mal_IDirectSoundCapture*)pDevice->dsound.pCapture); + ma_IDirectSoundCapture_Release((ma_IDirectSoundCapture*)pDevice->dsound.pCapture); } if (pDevice->dsound.pPlaybackBuffer != NULL) { - mal_IDirectSoundBuffer_Release((mal_IDirectSoundBuffer*)pDevice->dsound.pPlaybackBuffer); + ma_IDirectSoundBuffer_Release((ma_IDirectSoundBuffer*)pDevice->dsound.pPlaybackBuffer); } if (pDevice->dsound.pPlaybackPrimaryBuffer != NULL) { - mal_IDirectSoundBuffer_Release((mal_IDirectSoundBuffer*)pDevice->dsound.pPlaybackPrimaryBuffer); + ma_IDirectSoundBuffer_Release((ma_IDirectSoundBuffer*)pDevice->dsound.pPlaybackPrimaryBuffer); } if (pDevice->dsound.pPlayback != NULL) { - mal_IDirectSound_Release((mal_IDirectSound*)pDevice->dsound.pPlayback); + ma_IDirectSound_Release((ma_IDirectSound*)pDevice->dsound.pPlayback); } } -mal_result mal_config_to_WAVEFORMATEXTENSIBLE(mal_format format, mal_uint32 channels, mal_uint32 sampleRate, const mal_channel* pChannelMap, WAVEFORMATEXTENSIBLE* pWF) +ma_result ma_config_to_WAVEFORMATEXTENSIBLE(ma_format format, ma_uint32 channels, ma_uint32 sampleRate, const ma_channel* pChannelMap, WAVEFORMATEXTENSIBLE* pWF) { GUID subformat; switch (format) { - case mal_format_u8: - case mal_format_s16: - case mal_format_s24: - //case mal_format_s24_32: - case mal_format_s32: + case ma_format_u8: + case ma_format_s16: + case ma_format_s24: + //case ma_format_s24_32: + case ma_format_s32: { subformat = MA_GUID_KSDATAFORMAT_SUBTYPE_PCM; } break; - case mal_format_f32: + case ma_format_f32: { subformat = MA_GUID_KSDATAFORMAT_SUBTYPE_IEEE_FLOAT; } break; @@ -9206,38 +9206,38 @@ mal_result mal_config_to_WAVEFORMATEXTENSIBLE(mal_format format, mal_uint32 chan return MA_FORMAT_NOT_SUPPORTED; } - mal_zero_object(pWF); + ma_zero_object(pWF); pWF->Format.cbSize = sizeof(*pWF); pWF->Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE; pWF->Format.nChannels = (WORD)channels; pWF->Format.nSamplesPerSec = (DWORD)sampleRate; - pWF->Format.wBitsPerSample = (WORD)mal_get_bytes_per_sample(format)*8; + pWF->Format.wBitsPerSample = (WORD)ma_get_bytes_per_sample(format)*8; pWF->Format.nBlockAlign = (pWF->Format.nChannels * pWF->Format.wBitsPerSample) / 8; pWF->Format.nAvgBytesPerSec = pWF->Format.nBlockAlign * pWF->Format.nSamplesPerSec; pWF->Samples.wValidBitsPerSample = pWF->Format.wBitsPerSample; - pWF->dwChannelMask = mal_channel_map_to_channel_mask__win32(pChannelMap, channels); + pWF->dwChannelMask = ma_channel_map_to_channel_mask__win32(pChannelMap, channels); pWF->SubFormat = subformat; return MA_SUCCESS; } -mal_result mal_device_init__dsound(mal_context* pContext, const mal_device_config* pConfig, mal_device* pDevice) +ma_result ma_device_init__dsound(ma_context* pContext, const ma_device_config* pConfig, ma_device* pDevice) { - mal_result result; + ma_result result; (void)pContext; - mal_assert(pDevice != NULL); - mal_zero_object(&pDevice->dsound); + ma_assert(pDevice != NULL); + ma_zero_object(&pDevice->dsound); - mal_uint32 bufferSizeInMilliseconds = pConfig->bufferSizeInMilliseconds; + ma_uint32 bufferSizeInMilliseconds = pConfig->bufferSizeInMilliseconds; if (bufferSizeInMilliseconds == 0) { - bufferSizeInMilliseconds = mal_calculate_buffer_size_in_milliseconds_from_frames(pConfig->bufferSizeInFrames, pConfig->sampleRate); + bufferSizeInMilliseconds = ma_calculate_buffer_size_in_milliseconds_from_frames(pConfig->bufferSizeInFrames, pConfig->sampleRate); } /* DirectSound should use a latency of about 20ms per period for low latency mode. */ if (pDevice->usingDefaultBufferSize) { - if (pConfig->performanceProfile == mal_performance_profile_low_latency) { + if (pConfig->performanceProfile == ma_performance_profile_low_latency) { bufferSizeInMilliseconds = 20 * pConfig->periods; } else { bufferSizeInMilliseconds = 200 * pConfig->periods; @@ -9252,22 +9252,22 @@ mal_result mal_device_init__dsound(mal_context* pContext, const mal_device_confi // Unfortunately DirectSound uses different APIs and data structures for playback and catpure devices. We need to initialize // the capture device first because we'll want to match it's buffer size and period count on the playback side if we're using // full-duplex mode. - if (pConfig->deviceType == mal_device_type_capture || pConfig->deviceType == mal_device_type_duplex) { + if (pConfig->deviceType == ma_device_type_capture || pConfig->deviceType == ma_device_type_duplex) { WAVEFORMATEXTENSIBLE wf; - result = mal_config_to_WAVEFORMATEXTENSIBLE(pConfig->capture.format, pConfig->capture.channels, pConfig->sampleRate, pConfig->capture.channelMap, &wf); + result = ma_config_to_WAVEFORMATEXTENSIBLE(pConfig->capture.format, pConfig->capture.channels, pConfig->sampleRate, pConfig->capture.channelMap, &wf); if (result != MA_SUCCESS) { return result; } - result = mal_context_create_IDirectSoundCapture__dsound(pContext, pConfig->capture.shareMode, pConfig->capture.pDeviceID, (mal_IDirectSoundCapture**)&pDevice->dsound.pCapture); + result = ma_context_create_IDirectSoundCapture__dsound(pContext, pConfig->capture.shareMode, pConfig->capture.pDeviceID, (ma_IDirectSoundCapture**)&pDevice->dsound.pCapture); if (result != MA_SUCCESS) { - mal_device_uninit__dsound(pDevice); + ma_device_uninit__dsound(pDevice); return result; } - result = mal_context_get_format_info_for_IDirectSoundCapture__dsound(pContext, (mal_IDirectSoundCapture*)pDevice->dsound.pCapture, &wf.Format.nChannels, &wf.Format.wBitsPerSample, &wf.Format.nSamplesPerSec); + result = ma_context_get_format_info_for_IDirectSoundCapture__dsound(pContext, (ma_IDirectSoundCapture*)pDevice->dsound.pCapture, &wf.Format.nChannels, &wf.Format.wBitsPerSample, &wf.Format.nSamplesPerSec); if (result != MA_SUCCESS) { - mal_device_uninit__dsound(pDevice); + ma_device_uninit__dsound(pDevice); return result; } @@ -9277,49 +9277,49 @@ mal_result mal_device_init__dsound(mal_context* pContext, const mal_device_confi wf.SubFormat = MA_GUID_KSDATAFORMAT_SUBTYPE_PCM; /* The size of the buffer must be a clean multiple of the period count. */ - mal_uint32 bufferSizeInFrames = (mal_calculate_buffer_size_in_frames_from_milliseconds(bufferSizeInMilliseconds, wf.Format.nSamplesPerSec) / pConfig->periods) * pConfig->periods; + ma_uint32 bufferSizeInFrames = (ma_calculate_buffer_size_in_frames_from_milliseconds(bufferSizeInMilliseconds, wf.Format.nSamplesPerSec) / pConfig->periods) * pConfig->periods; MA_DSCBUFFERDESC descDS; - mal_zero_object(&descDS); + ma_zero_object(&descDS); descDS.dwSize = sizeof(descDS); descDS.dwFlags = 0; - descDS.dwBufferBytes = bufferSizeInFrames * mal_get_bytes_per_frame(pDevice->capture.internalFormat, wf.Format.nChannels); + descDS.dwBufferBytes = bufferSizeInFrames * ma_get_bytes_per_frame(pDevice->capture.internalFormat, wf.Format.nChannels); descDS.lpwfxFormat = (WAVEFORMATEX*)&wf; - if (FAILED(mal_IDirectSoundCapture_CreateCaptureBuffer((mal_IDirectSoundCapture*)pDevice->dsound.pCapture, &descDS, (mal_IDirectSoundCaptureBuffer**)&pDevice->dsound.pCaptureBuffer, NULL))) { - mal_device_uninit__dsound(pDevice); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] IDirectSoundCapture_CreateCaptureBuffer() failed for capture device.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + if (FAILED(ma_IDirectSoundCapture_CreateCaptureBuffer((ma_IDirectSoundCapture*)pDevice->dsound.pCapture, &descDS, (ma_IDirectSoundCaptureBuffer**)&pDevice->dsound.pCaptureBuffer, NULL))) { + ma_device_uninit__dsound(pDevice); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] IDirectSoundCapture_CreateCaptureBuffer() failed for capture device.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } // Get the _actual_ properties of the buffer. char rawdata[1024]; WAVEFORMATEXTENSIBLE* pActualFormat = (WAVEFORMATEXTENSIBLE*)rawdata; - if (FAILED(mal_IDirectSoundCaptureBuffer_GetFormat((mal_IDirectSoundCaptureBuffer*)pDevice->dsound.pCaptureBuffer, (WAVEFORMATEX*)pActualFormat, sizeof(rawdata), NULL))) { - mal_device_uninit__dsound(pDevice); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] Failed to retrieve the actual format of the capture device's buffer.", MA_FORMAT_NOT_SUPPORTED); + if (FAILED(ma_IDirectSoundCaptureBuffer_GetFormat((ma_IDirectSoundCaptureBuffer*)pDevice->dsound.pCaptureBuffer, (WAVEFORMATEX*)pActualFormat, sizeof(rawdata), NULL))) { + ma_device_uninit__dsound(pDevice); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] Failed to retrieve the actual format of the capture device's buffer.", MA_FORMAT_NOT_SUPPORTED); } - pDevice->capture.internalFormat = mal_format_from_WAVEFORMATEX((WAVEFORMATEX*)pActualFormat); + pDevice->capture.internalFormat = ma_format_from_WAVEFORMATEX((WAVEFORMATEX*)pActualFormat); pDevice->capture.internalChannels = pActualFormat->Format.nChannels; pDevice->capture.internalSampleRate = pActualFormat->Format.nSamplesPerSec; // Get the internal channel map based on the channel mask. if (pActualFormat->Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE) { - mal_channel_mask_to_channel_map__win32(pActualFormat->dwChannelMask, pDevice->capture.internalChannels, pDevice->capture.internalChannelMap); + ma_channel_mask_to_channel_map__win32(pActualFormat->dwChannelMask, pDevice->capture.internalChannels, pDevice->capture.internalChannelMap); } else { - mal_channel_mask_to_channel_map__win32(wf.dwChannelMask, pDevice->capture.internalChannels, pDevice->capture.internalChannelMap); + ma_channel_mask_to_channel_map__win32(wf.dwChannelMask, pDevice->capture.internalChannels, pDevice->capture.internalChannelMap); } /* After getting the actual format the size of the buffer in frames may have actually changed. However, we want this to be as close to what the user has asked for as possible, so let's go ahead and release the old capture buffer and create a new one in this case. */ - if (bufferSizeInFrames != (descDS.dwBufferBytes / mal_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels))) { - descDS.dwBufferBytes = bufferSizeInFrames * mal_get_bytes_per_frame(pDevice->capture.internalFormat, wf.Format.nChannels); - mal_IDirectSoundCaptureBuffer_Release((mal_IDirectSoundCaptureBuffer*)pDevice->dsound.pCaptureBuffer); + if (bufferSizeInFrames != (descDS.dwBufferBytes / ma_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels))) { + descDS.dwBufferBytes = bufferSizeInFrames * ma_get_bytes_per_frame(pDevice->capture.internalFormat, wf.Format.nChannels); + ma_IDirectSoundCaptureBuffer_Release((ma_IDirectSoundCaptureBuffer*)pDevice->dsound.pCaptureBuffer); - if (FAILED(mal_IDirectSoundCapture_CreateCaptureBuffer((mal_IDirectSoundCapture*)pDevice->dsound.pCapture, &descDS, (mal_IDirectSoundCaptureBuffer**)&pDevice->dsound.pCaptureBuffer, NULL))) { - mal_device_uninit__dsound(pDevice); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] Second attempt at IDirectSoundCapture_CreateCaptureBuffer() failed for capture device.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + if (FAILED(ma_IDirectSoundCapture_CreateCaptureBuffer((ma_IDirectSoundCapture*)pDevice->dsound.pCapture, &descDS, (ma_IDirectSoundCaptureBuffer**)&pDevice->dsound.pCaptureBuffer, NULL))) { + ma_device_uninit__dsound(pDevice); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] Second attempt at IDirectSoundCapture_CreateCaptureBuffer() failed for capture device.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } } @@ -9328,36 +9328,36 @@ mal_result mal_device_init__dsound(mal_context* pContext, const mal_device_confi pDevice->capture.internalPeriods = pConfig->periods; } - if (pConfig->deviceType == mal_device_type_playback || pConfig->deviceType == mal_device_type_duplex) { + if (pConfig->deviceType == ma_device_type_playback || pConfig->deviceType == ma_device_type_duplex) { WAVEFORMATEXTENSIBLE wf; - result = mal_config_to_WAVEFORMATEXTENSIBLE(pConfig->playback.format, pConfig->playback.channels, pConfig->sampleRate, pConfig->playback.channelMap, &wf); + result = ma_config_to_WAVEFORMATEXTENSIBLE(pConfig->playback.format, pConfig->playback.channels, pConfig->sampleRate, pConfig->playback.channelMap, &wf); if (result != MA_SUCCESS) { return result; } - result = mal_context_create_IDirectSound__dsound(pContext, pConfig->playback.shareMode, pConfig->playback.pDeviceID, (mal_IDirectSound**)&pDevice->dsound.pPlayback); + result = ma_context_create_IDirectSound__dsound(pContext, pConfig->playback.shareMode, pConfig->playback.pDeviceID, (ma_IDirectSound**)&pDevice->dsound.pPlayback); if (result != MA_SUCCESS) { - mal_device_uninit__dsound(pDevice); + ma_device_uninit__dsound(pDevice); return result; } MA_DSBUFFERDESC descDSPrimary; - mal_zero_object(&descDSPrimary); + ma_zero_object(&descDSPrimary); descDSPrimary.dwSize = sizeof(MA_DSBUFFERDESC); descDSPrimary.dwFlags = MA_DSBCAPS_PRIMARYBUFFER | MA_DSBCAPS_CTRLVOLUME; - if (FAILED(mal_IDirectSound_CreateSoundBuffer((mal_IDirectSound*)pDevice->dsound.pPlayback, &descDSPrimary, (mal_IDirectSoundBuffer**)&pDevice->dsound.pPlaybackPrimaryBuffer, NULL))) { - mal_device_uninit__dsound(pDevice); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] IDirectSound_CreateSoundBuffer() failed for playback device's primary buffer.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + if (FAILED(ma_IDirectSound_CreateSoundBuffer((ma_IDirectSound*)pDevice->dsound.pPlayback, &descDSPrimary, (ma_IDirectSoundBuffer**)&pDevice->dsound.pPlaybackPrimaryBuffer, NULL))) { + ma_device_uninit__dsound(pDevice); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] IDirectSound_CreateSoundBuffer() failed for playback device's primary buffer.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } // We may want to make some adjustments to the format if we are using defaults. MA_DSCAPS caps; - mal_zero_object(&caps); + ma_zero_object(&caps); caps.dwSize = sizeof(caps); - if (FAILED(mal_IDirectSound_GetCaps((mal_IDirectSound*)pDevice->dsound.pPlayback, &caps))) { - mal_device_uninit__dsound(pDevice); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] IDirectSound_GetCaps() failed for playback device.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + if (FAILED(ma_IDirectSound_GetCaps((ma_IDirectSound*)pDevice->dsound.pPlayback, &caps))) { + ma_device_uninit__dsound(pDevice); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] IDirectSound_GetCaps() failed for playback device.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } if (pDevice->playback.usingDefaultChannels) { @@ -9367,8 +9367,8 @@ mal_result mal_device_init__dsound(mal_context* pContext, const mal_device_confi // Look at the speaker configuration to get a better idea on the channel count. DWORD speakerConfig; - if (SUCCEEDED(mal_IDirectSound_GetSpeakerConfig((mal_IDirectSound*)pDevice->dsound.pPlayback, &speakerConfig))) { - mal_get_channels_from_speaker_config__dsound(speakerConfig, &wf.Format.nChannels, &wf.dwChannelMask); + if (SUCCEEDED(ma_IDirectSound_GetSpeakerConfig((ma_IDirectSound*)pDevice->dsound.pPlayback, &speakerConfig))) { + ma_get_channels_from_speaker_config__dsound(speakerConfig, &wf.Format.nChannels, &wf.dwChannelMask); } } else { // It does not support stereo, which means we are stuck with mono. @@ -9379,7 +9379,7 @@ mal_result mal_device_init__dsound(mal_context* pContext, const mal_device_confi if (pDevice->usingDefaultSampleRate) { // We base the sample rate on the values returned by GetCaps(). if ((caps.dwFlags & MA_DSCAPS_CONTINUOUSRATE) != 0) { - wf.Format.nSamplesPerSec = mal_get_best_sample_rate_within_range(caps.dwMinSecondarySampleRate, caps.dwMaxSecondarySampleRate); + wf.Format.nSamplesPerSec = ma_get_best_sample_rate_within_range(caps.dwMinSecondarySampleRate, caps.dwMaxSecondarySampleRate); } else { wf.Format.nSamplesPerSec = caps.dwMaxSecondarySampleRate; } @@ -9393,32 +9393,32 @@ mal_result mal_device_init__dsound(mal_context* pContext, const mal_device_confi // The method succeeds even if the hardware does not support the requested format; DirectSound sets the buffer to the closest // supported format. To determine whether this has happened, an application can call the GetFormat method for the primary buffer // and compare the result with the format that was requested with the SetFormat method. - if (FAILED(mal_IDirectSoundBuffer_SetFormat((mal_IDirectSoundBuffer*)pDevice->dsound.pPlaybackPrimaryBuffer, (WAVEFORMATEX*)&wf))) { - mal_device_uninit__dsound(pDevice); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] Failed to set format of playback device's primary buffer.", MA_FORMAT_NOT_SUPPORTED); + if (FAILED(ma_IDirectSoundBuffer_SetFormat((ma_IDirectSoundBuffer*)pDevice->dsound.pPlaybackPrimaryBuffer, (WAVEFORMATEX*)&wf))) { + ma_device_uninit__dsound(pDevice); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] Failed to set format of playback device's primary buffer.", MA_FORMAT_NOT_SUPPORTED); } // Get the _actual_ properties of the buffer. char rawdata[1024]; WAVEFORMATEXTENSIBLE* pActualFormat = (WAVEFORMATEXTENSIBLE*)rawdata; - if (FAILED(mal_IDirectSoundBuffer_GetFormat((mal_IDirectSoundBuffer*)pDevice->dsound.pPlaybackPrimaryBuffer, (WAVEFORMATEX*)pActualFormat, sizeof(rawdata), NULL))) { - mal_device_uninit__dsound(pDevice); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] Failed to retrieve the actual format of the playback device's primary buffer.", MA_FORMAT_NOT_SUPPORTED); + if (FAILED(ma_IDirectSoundBuffer_GetFormat((ma_IDirectSoundBuffer*)pDevice->dsound.pPlaybackPrimaryBuffer, (WAVEFORMATEX*)pActualFormat, sizeof(rawdata), NULL))) { + ma_device_uninit__dsound(pDevice); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] Failed to retrieve the actual format of the playback device's primary buffer.", MA_FORMAT_NOT_SUPPORTED); } - pDevice->playback.internalFormat = mal_format_from_WAVEFORMATEX((WAVEFORMATEX*)pActualFormat); + pDevice->playback.internalFormat = ma_format_from_WAVEFORMATEX((WAVEFORMATEX*)pActualFormat); pDevice->playback.internalChannels = pActualFormat->Format.nChannels; pDevice->playback.internalSampleRate = pActualFormat->Format.nSamplesPerSec; // Get the internal channel map based on the channel mask. if (pActualFormat->Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE) { - mal_channel_mask_to_channel_map__win32(pActualFormat->dwChannelMask, pDevice->playback.internalChannels, pDevice->playback.internalChannelMap); + ma_channel_mask_to_channel_map__win32(pActualFormat->dwChannelMask, pDevice->playback.internalChannels, pDevice->playback.internalChannelMap); } else { - mal_channel_mask_to_channel_map__win32(wf.dwChannelMask, pDevice->playback.internalChannels, pDevice->playback.internalChannelMap); + ma_channel_mask_to_channel_map__win32(wf.dwChannelMask, pDevice->playback.internalChannels, pDevice->playback.internalChannelMap); } /* The size of the buffer must be a clean multiple of the period count. */ - mal_uint32 bufferSizeInFrames = (mal_calculate_buffer_size_in_frames_from_milliseconds(bufferSizeInMilliseconds, pDevice->playback.internalSampleRate) / pConfig->periods) * pConfig->periods; + ma_uint32 bufferSizeInFrames = (ma_calculate_buffer_size_in_frames_from_milliseconds(bufferSizeInMilliseconds, pDevice->playback.internalSampleRate) / pConfig->periods) * pConfig->periods; // Meaning of dwFlags (from MSDN): // @@ -9434,14 +9434,14 @@ mal_result mal_device_init__dsound(mal_context* pContext, const mal_device_confi // sound cards; it was directly behind the write cursor. Now, if the DSBCAPS_GETCURRENTPOSITION2 flag is specified, the // application can get a more accurate play cursor. MA_DSBUFFERDESC descDS; - mal_zero_object(&descDS); + ma_zero_object(&descDS); descDS.dwSize = sizeof(descDS); descDS.dwFlags = MA_DSBCAPS_CTRLPOSITIONNOTIFY | MA_DSBCAPS_GLOBALFOCUS | MA_DSBCAPS_GETCURRENTPOSITION2; - descDS.dwBufferBytes = bufferSizeInFrames * mal_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels); + descDS.dwBufferBytes = bufferSizeInFrames * ma_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels); descDS.lpwfxFormat = (WAVEFORMATEX*)&wf; - if (FAILED(mal_IDirectSound_CreateSoundBuffer((mal_IDirectSound*)pDevice->dsound.pPlayback, &descDS, (mal_IDirectSoundBuffer**)&pDevice->dsound.pPlaybackBuffer, NULL))) { - mal_device_uninit__dsound(pDevice); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] IDirectSound_CreateSoundBuffer() failed for playback device's secondary buffer.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + if (FAILED(ma_IDirectSound_CreateSoundBuffer((ma_IDirectSound*)pDevice->dsound.pPlayback, &descDS, (ma_IDirectSoundBuffer**)&pDevice->dsound.pPlaybackBuffer, NULL))) { + ma_device_uninit__dsound(pDevice); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] IDirectSound_CreateSoundBuffer() failed for playback device's secondary buffer.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } /* DirectSound should give us a buffer exactly the size we asked for. */ @@ -9453,11 +9453,11 @@ mal_result mal_device_init__dsound(mal_context* pContext, const mal_device_confi } -mal_result mal_device_main_loop__dsound(mal_device* pDevice) +ma_result ma_device_main_loop__dsound(ma_device* pDevice) { - mal_result result = MA_SUCCESS; - mal_uint32 bpfCapture = mal_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels); - mal_uint32 bpfPlayback = mal_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels); + ma_result result = MA_SUCCESS; + ma_uint32 bpfCapture = ma_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels); + ma_uint32 bpfPlayback = ma_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels); HRESULT hr; DWORD lockOffsetInBytesCapture; DWORD lockSizeInBytesCapture; @@ -9469,36 +9469,36 @@ mal_result mal_device_main_loop__dsound(mal_device* pDevice) void* pMappedBufferPlayback; DWORD prevReadCursorInBytesCapture = 0; DWORD prevPlayCursorInBytesPlayback = 0; - mal_bool32 physicalPlayCursorLoopFlagPlayback = 0; + ma_bool32 physicalPlayCursorLoopFlagPlayback = 0; DWORD virtualWriteCursorInBytesPlayback = 0; - mal_bool32 virtualWriteCursorLoopFlagPlayback = 0; - mal_bool32 isPlaybackDeviceStarted = MA_FALSE; - mal_uint32 framesWrittenToPlaybackDevice = 0; /* For knowing whether or not the playback device needs to be started. */ - mal_uint32 waitTimeInMilliseconds = 1; + ma_bool32 virtualWriteCursorLoopFlagPlayback = 0; + ma_bool32 isPlaybackDeviceStarted = MA_FALSE; + ma_uint32 framesWrittenToPlaybackDevice = 0; /* For knowing whether or not the playback device needs to be started. */ + ma_uint32 waitTimeInMilliseconds = 1; - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); /* The first thing to do is start the capture device. The playback device is only started after the first period is written. */ - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { - if (FAILED(mal_IDirectSoundCaptureBuffer_Start((mal_IDirectSoundCaptureBuffer*)pDevice->dsound.pCaptureBuffer, MA_DSCBSTART_LOOPING))) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] IDirectSoundCaptureBuffer_Start() failed.", MA_FAILED_TO_START_BACKEND_DEVICE); + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { + if (FAILED(ma_IDirectSoundCaptureBuffer_Start((ma_IDirectSoundCaptureBuffer*)pDevice->dsound.pCaptureBuffer, MA_DSCBSTART_LOOPING))) { + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] IDirectSoundCaptureBuffer_Start() failed.", MA_FAILED_TO_START_BACKEND_DEVICE); } } - while (mal_device__get_state(pDevice) == MA_STATE_STARTED) { + while (ma_device__get_state(pDevice) == MA_STATE_STARTED) { switch (pDevice->type) { - case mal_device_type_duplex: + case ma_device_type_duplex: { DWORD physicalCaptureCursorInBytes; DWORD physicalReadCursorInBytes; - if (FAILED(mal_IDirectSoundCaptureBuffer_GetCurrentPosition((mal_IDirectSoundCaptureBuffer*)pDevice->dsound.pCaptureBuffer, &physicalCaptureCursorInBytes, &physicalReadCursorInBytes))) { + if (FAILED(ma_IDirectSoundCaptureBuffer_GetCurrentPosition((ma_IDirectSoundCaptureBuffer*)pDevice->dsound.pCaptureBuffer, &physicalCaptureCursorInBytes, &physicalReadCursorInBytes))) { return MA_ERROR; } /* If nothing is available we just sleep for a bit and return from this iteration. */ if (physicalReadCursorInBytes == prevReadCursorInBytesCapture) { - mal_sleep(waitTimeInMilliseconds); + ma_sleep(waitTimeInMilliseconds); continue; /* Nothing is available in the capture buffer. */ } @@ -9527,27 +9527,27 @@ mal_result mal_device_main_loop__dsound(mal_device* pDevice) } if (lockSizeInBytesCapture == 0) { - mal_sleep(waitTimeInMilliseconds); + ma_sleep(waitTimeInMilliseconds); continue; /* Nothing is available in the capture buffer. */ } - hr = mal_IDirectSoundCaptureBuffer_Lock((mal_IDirectSoundCaptureBuffer*)pDevice->dsound.pCaptureBuffer, lockOffsetInBytesCapture, lockSizeInBytesCapture, &pMappedBufferCapture, &mappedSizeInBytesCapture, NULL, NULL, 0); + hr = ma_IDirectSoundCaptureBuffer_Lock((ma_IDirectSoundCaptureBuffer*)pDevice->dsound.pCaptureBuffer, lockOffsetInBytesCapture, lockSizeInBytesCapture, &pMappedBufferCapture, &mappedSizeInBytesCapture, NULL, NULL, 0); if (FAILED(hr)) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] Failed to map buffer from capture device in preparation for writing to the device.", MA_FAILED_TO_MAP_DEVICE_BUFFER); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] Failed to map buffer from capture device in preparation for writing to the device.", MA_FAILED_TO_MAP_DEVICE_BUFFER); } /* At this point we have some input data that we need to output. We do not return until every mapped frame of the input data is written to the playback device. */ pDevice->capture._dspFrameCount = mappedSizeInBytesCapture / bpfCapture; - pDevice->capture._dspFrames = (const mal_uint8*)pMappedBufferCapture; + pDevice->capture._dspFrames = (const ma_uint8*)pMappedBufferCapture; for (;;) { /* Keep writing to the playback device. */ - mal_uint8 inputFramesInExternalFormat[4096]; - mal_uint32 inputFramesInExternalFormatCap = sizeof(inputFramesInExternalFormat) / mal_get_bytes_per_frame(pDevice->capture.format, pDevice->capture.channels); - mal_uint32 inputFramesInExternalFormatCount; - mal_uint8 outputFramesInExternalFormat[4096]; - mal_uint32 outputFramesInExternalFormatCap = sizeof(outputFramesInExternalFormat) / mal_get_bytes_per_frame(pDevice->playback.format, pDevice->playback.channels); + ma_uint8 inputFramesInExternalFormat[4096]; + ma_uint32 inputFramesInExternalFormatCap = sizeof(inputFramesInExternalFormat) / ma_get_bytes_per_frame(pDevice->capture.format, pDevice->capture.channels); + ma_uint32 inputFramesInExternalFormatCount; + ma_uint8 outputFramesInExternalFormat[4096]; + ma_uint32 outputFramesInExternalFormatCap = sizeof(outputFramesInExternalFormat) / ma_get_bytes_per_frame(pDevice->playback.format, pDevice->playback.channels); - inputFramesInExternalFormatCount = (mal_uint32)mal_pcm_converter_read(&pDevice->capture.converter, inputFramesInExternalFormat, mal_min(inputFramesInExternalFormatCap, outputFramesInExternalFormatCap)); + inputFramesInExternalFormatCount = (ma_uint32)ma_pcm_converter_read(&pDevice->capture.converter, inputFramesInExternalFormat, ma_min(inputFramesInExternalFormatCap, outputFramesInExternalFormatCap)); if (inputFramesInExternalFormatCount == 0) { break; /* No more input data. */ } @@ -9556,16 +9556,16 @@ mal_result mal_device_main_loop__dsound(mal_device* pDevice) /* At this point we have input and output data in external format. All we need to do now is convert it to the output format. This may take a few passes. */ pDevice->playback._dspFrameCount = inputFramesInExternalFormatCount; - pDevice->playback._dspFrames = (const mal_uint8*)outputFramesInExternalFormat; + pDevice->playback._dspFrames = (const ma_uint8*)outputFramesInExternalFormat; for (;;) { - mal_uint32 framesWrittenThisIteration; + ma_uint32 framesWrittenThisIteration; DWORD physicalPlayCursorInBytes; DWORD physicalWriteCursorInBytes; DWORD availableBytesPlayback; DWORD silentPaddingInBytes = 0; /* <-- Must be initialized to 0. */ /* We need the physical play and write cursors. */ - if (FAILED(mal_IDirectSoundBuffer_GetCurrentPosition((mal_IDirectSoundBuffer*)pDevice->dsound.pPlaybackBuffer, &physicalPlayCursorInBytes, &physicalWriteCursorInBytes))) { + if (FAILED(ma_IDirectSoundBuffer_GetCurrentPosition((ma_IDirectSoundBuffer*)pDevice->dsound.pPlaybackBuffer, &physicalPlayCursorInBytes, &physicalWriteCursorInBytes))) { break; } @@ -9608,13 +9608,13 @@ mal_result mal_device_main_loop__dsound(mal_device* pDevice) if (availableBytesPlayback == 0) { /* If we haven't started the device yet, this will never get beyond 0. In this case we need to get the device started. */ if (!isPlaybackDeviceStarted) { - if (FAILED(mal_IDirectSoundBuffer_Play((mal_IDirectSoundBuffer*)pDevice->dsound.pPlaybackBuffer, 0, 0, MA_DSBPLAY_LOOPING))) { - mal_IDirectSoundCaptureBuffer_Stop((mal_IDirectSoundCaptureBuffer*)pDevice->dsound.pCaptureBuffer); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] IDirectSoundBuffer_Play() failed.", MA_FAILED_TO_START_BACKEND_DEVICE); + if (FAILED(ma_IDirectSoundBuffer_Play((ma_IDirectSoundBuffer*)pDevice->dsound.pPlaybackBuffer, 0, 0, MA_DSBPLAY_LOOPING))) { + ma_IDirectSoundCaptureBuffer_Stop((ma_IDirectSoundCaptureBuffer*)pDevice->dsound.pCaptureBuffer); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] IDirectSoundBuffer_Play() failed.", MA_FAILED_TO_START_BACKEND_DEVICE); } isPlaybackDeviceStarted = MA_TRUE; } else { - mal_sleep(waitTimeInMilliseconds); + ma_sleep(waitTimeInMilliseconds); continue; } } @@ -9630,9 +9630,9 @@ mal_result mal_device_main_loop__dsound(mal_device* pDevice) lockSizeInBytesPlayback = physicalPlayCursorInBytes - virtualWriteCursorInBytesPlayback; } - hr = mal_IDirectSoundBuffer_Lock((mal_IDirectSoundBuffer*)pDevice->dsound.pPlaybackBuffer, lockOffsetInBytesPlayback, lockSizeInBytesPlayback, &pMappedBufferPlayback, &mappedSizeInBytesPlayback, NULL, NULL, 0); + hr = ma_IDirectSoundBuffer_Lock((ma_IDirectSoundBuffer*)pDevice->dsound.pPlaybackBuffer, lockOffsetInBytesPlayback, lockSizeInBytesPlayback, &pMappedBufferPlayback, &mappedSizeInBytesPlayback, NULL, NULL, 0); if (FAILED(hr)) { - result = mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] Failed to map buffer from playback device in preparation for writing to the device.", MA_FAILED_TO_MAP_DEVICE_BUFFER); + result = ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] Failed to map buffer from playback device in preparation for writing to the device.", MA_FAILED_TO_MAP_DEVICE_BUFFER); break; } @@ -9656,16 +9656,16 @@ mal_result mal_device_main_loop__dsound(mal_device* pDevice) /* At this point we have a buffer for output. */ if (silentPaddingInBytes > 0) { - mal_zero_memory(pMappedBufferPlayback, silentPaddingInBytes); + ma_zero_memory(pMappedBufferPlayback, silentPaddingInBytes); framesWrittenThisIteration = silentPaddingInBytes/bpfPlayback; } else { - framesWrittenThisIteration = (mal_uint32)mal_pcm_converter_read(&pDevice->playback.converter, pMappedBufferPlayback, mappedSizeInBytesPlayback/bpfPlayback); + framesWrittenThisIteration = (ma_uint32)ma_pcm_converter_read(&pDevice->playback.converter, pMappedBufferPlayback, mappedSizeInBytesPlayback/bpfPlayback); } - hr = mal_IDirectSoundBuffer_Unlock((mal_IDirectSoundBuffer*)pDevice->dsound.pPlaybackBuffer, pMappedBufferPlayback, framesWrittenThisIteration*bpfPlayback, NULL, 0); + hr = ma_IDirectSoundBuffer_Unlock((ma_IDirectSoundBuffer*)pDevice->dsound.pPlaybackBuffer, pMappedBufferPlayback, framesWrittenThisIteration*bpfPlayback, NULL, 0); if (FAILED(hr)) { - result = mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] Failed to unlock internal buffer from playback device after writing to the device.", MA_FAILED_TO_UNMAP_DEVICE_BUFFER); + result = ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] Failed to unlock internal buffer from playback device after writing to the device.", MA_FAILED_TO_UNMAP_DEVICE_BUFFER); break; } @@ -9681,9 +9681,9 @@ mal_result mal_device_main_loop__dsound(mal_device* pDevice) */ framesWrittenToPlaybackDevice += framesWrittenThisIteration; if (!isPlaybackDeviceStarted && framesWrittenToPlaybackDevice >= ((pDevice->playback.internalBufferSizeInFrames/pDevice->playback.internalPeriods)*2)) { - if (FAILED(mal_IDirectSoundBuffer_Play((mal_IDirectSoundBuffer*)pDevice->dsound.pPlaybackBuffer, 0, 0, MA_DSBPLAY_LOOPING))) { - mal_IDirectSoundCaptureBuffer_Stop((mal_IDirectSoundCaptureBuffer*)pDevice->dsound.pCaptureBuffer); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] IDirectSoundBuffer_Play() failed.", MA_FAILED_TO_START_BACKEND_DEVICE); + if (FAILED(ma_IDirectSoundBuffer_Play((ma_IDirectSoundBuffer*)pDevice->dsound.pPlaybackBuffer, 0, 0, MA_DSBPLAY_LOOPING))) { + ma_IDirectSoundCaptureBuffer_Stop((ma_IDirectSoundCaptureBuffer*)pDevice->dsound.pCaptureBuffer); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] IDirectSoundBuffer_Play() failed.", MA_FAILED_TO_START_BACKEND_DEVICE); } isPlaybackDeviceStarted = MA_TRUE; } @@ -9700,26 +9700,26 @@ mal_result mal_device_main_loop__dsound(mal_device* pDevice) /* At this point we're done with the mapped portion of the capture buffer. */ - hr = mal_IDirectSoundCaptureBuffer_Unlock((mal_IDirectSoundCaptureBuffer*)pDevice->dsound.pCaptureBuffer, pMappedBufferCapture, mappedSizeInBytesCapture, NULL, 0); + hr = ma_IDirectSoundCaptureBuffer_Unlock((ma_IDirectSoundCaptureBuffer*)pDevice->dsound.pCaptureBuffer, pMappedBufferCapture, mappedSizeInBytesCapture, NULL, 0); if (FAILED(hr)) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] Failed to unlock internal buffer from capture device after reading from the device.", MA_FAILED_TO_UNMAP_DEVICE_BUFFER); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] Failed to unlock internal buffer from capture device after reading from the device.", MA_FAILED_TO_UNMAP_DEVICE_BUFFER); } prevReadCursorInBytesCapture = (lockOffsetInBytesCapture + mappedSizeInBytesCapture); } break; - case mal_device_type_capture: + case ma_device_type_capture: { DWORD physicalCaptureCursorInBytes; DWORD physicalReadCursorInBytes; - if (FAILED(mal_IDirectSoundCaptureBuffer_GetCurrentPosition((mal_IDirectSoundCaptureBuffer*)pDevice->dsound.pCaptureBuffer, &physicalCaptureCursorInBytes, &physicalReadCursorInBytes))) { + if (FAILED(ma_IDirectSoundCaptureBuffer_GetCurrentPosition((ma_IDirectSoundCaptureBuffer*)pDevice->dsound.pCaptureBuffer, &physicalCaptureCursorInBytes, &physicalReadCursorInBytes))) { return MA_ERROR; } /* If the previous capture position is the same as the current position we need to wait a bit longer. */ if (prevReadCursorInBytesCapture == physicalReadCursorInBytes) { - mal_sleep(waitTimeInMilliseconds); + ma_sleep(waitTimeInMilliseconds); continue; } @@ -9750,13 +9750,13 @@ mal_result mal_device_main_loop__dsound(mal_device* pDevice) #endif if (lockSizeInBytesCapture == 0) { - mal_sleep(waitTimeInMilliseconds); + ma_sleep(waitTimeInMilliseconds); continue; /* Nothing is available in the capture buffer. */ } - hr = mal_IDirectSoundCaptureBuffer_Lock((mal_IDirectSoundCaptureBuffer*)pDevice->dsound.pCaptureBuffer, lockOffsetInBytesCapture, lockSizeInBytesCapture, &pMappedBufferCapture, &mappedSizeInBytesCapture, NULL, NULL, 0); + hr = ma_IDirectSoundCaptureBuffer_Lock((ma_IDirectSoundCaptureBuffer*)pDevice->dsound.pCaptureBuffer, lockOffsetInBytesCapture, lockSizeInBytesCapture, &pMappedBufferCapture, &mappedSizeInBytesCapture, NULL, NULL, 0); if (FAILED(hr)) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] Failed to map buffer from capture device in preparation for writing to the device.", MA_FAILED_TO_MAP_DEVICE_BUFFER); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] Failed to map buffer from capture device in preparation for writing to the device.", MA_FAILED_TO_MAP_DEVICE_BUFFER); } #ifdef MA_DEBUG_OUTPUT @@ -9771,12 +9771,12 @@ mal_result mal_device_main_loop__dsound(mal_device* pDevice) pDevice->onData(pDevice, NULL, pMappedBufferCapture, mappedSizeInBytesCapture/bpfCapture); } else { /* Not a passthrough. */ - mal_device__send_frames_to_client(pDevice, mappedSizeInBytesCapture/bpfCapture, pMappedBufferCapture); + ma_device__send_frames_to_client(pDevice, mappedSizeInBytesCapture/bpfCapture, pMappedBufferCapture); } - hr = mal_IDirectSoundCaptureBuffer_Unlock((mal_IDirectSoundCaptureBuffer*)pDevice->dsound.pCaptureBuffer, pMappedBufferCapture, mappedSizeInBytesCapture, NULL, 0); + hr = ma_IDirectSoundCaptureBuffer_Unlock((ma_IDirectSoundCaptureBuffer*)pDevice->dsound.pCaptureBuffer, pMappedBufferCapture, mappedSizeInBytesCapture, NULL, 0); if (FAILED(hr)) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] Failed to unlock internal buffer from capture device after reading from the device.", MA_FAILED_TO_UNMAP_DEVICE_BUFFER); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] Failed to unlock internal buffer from capture device after reading from the device.", MA_FAILED_TO_UNMAP_DEVICE_BUFFER); } prevReadCursorInBytesCapture = lockOffsetInBytesCapture + mappedSizeInBytesCapture; @@ -9787,12 +9787,12 @@ mal_result mal_device_main_loop__dsound(mal_device* pDevice) - case mal_device_type_playback: + case ma_device_type_playback: { DWORD availableBytesPlayback; DWORD physicalPlayCursorInBytes; DWORD physicalWriteCursorInBytes; - if (FAILED(mal_IDirectSoundBuffer_GetCurrentPosition((mal_IDirectSoundBuffer*)pDevice->dsound.pPlaybackBuffer, &physicalPlayCursorInBytes, &physicalWriteCursorInBytes))) { + if (FAILED(ma_IDirectSoundBuffer_GetCurrentPosition((ma_IDirectSoundBuffer*)pDevice->dsound.pPlaybackBuffer, &physicalPlayCursorInBytes, &physicalWriteCursorInBytes))) { break; } @@ -9835,12 +9835,12 @@ mal_result mal_device_main_loop__dsound(mal_device* pDevice) if (availableBytesPlayback == 0) { /* If we haven't started the device yet, this will never get beyond 0. In this case we need to get the device started. */ if (!isPlaybackDeviceStarted) { - if (FAILED(mal_IDirectSoundBuffer_Play((mal_IDirectSoundBuffer*)pDevice->dsound.pPlaybackBuffer, 0, 0, MA_DSBPLAY_LOOPING))) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] IDirectSoundBuffer_Play() failed.", MA_FAILED_TO_START_BACKEND_DEVICE); + if (FAILED(ma_IDirectSoundBuffer_Play((ma_IDirectSoundBuffer*)pDevice->dsound.pPlaybackBuffer, 0, 0, MA_DSBPLAY_LOOPING))) { + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] IDirectSoundBuffer_Play() failed.", MA_FAILED_TO_START_BACKEND_DEVICE); } isPlaybackDeviceStarted = MA_TRUE; } else { - mal_sleep(waitTimeInMilliseconds); + ma_sleep(waitTimeInMilliseconds); continue; } } @@ -9855,9 +9855,9 @@ mal_result mal_device_main_loop__dsound(mal_device* pDevice) lockSizeInBytesPlayback = physicalPlayCursorInBytes - virtualWriteCursorInBytesPlayback; } - hr = mal_IDirectSoundBuffer_Lock((mal_IDirectSoundBuffer*)pDevice->dsound.pPlaybackBuffer, lockOffsetInBytesPlayback, lockSizeInBytesPlayback, &pMappedBufferPlayback, &mappedSizeInBytesPlayback, NULL, NULL, 0); + hr = ma_IDirectSoundBuffer_Lock((ma_IDirectSoundBuffer*)pDevice->dsound.pPlaybackBuffer, lockOffsetInBytesPlayback, lockSizeInBytesPlayback, &pMappedBufferPlayback, &mappedSizeInBytesPlayback, NULL, NULL, 0); if (FAILED(hr)) { - result = mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] Failed to map buffer from playback device in preparation for writing to the device.", MA_FAILED_TO_MAP_DEVICE_BUFFER); + result = ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] Failed to map buffer from playback device in preparation for writing to the device.", MA_FAILED_TO_MAP_DEVICE_BUFFER); break; } @@ -9870,12 +9870,12 @@ mal_result mal_device_main_loop__dsound(mal_device* pDevice) pDevice->onData(pDevice, pMappedBufferPlayback, NULL, (mappedSizeInBytesPlayback/bpfPlayback)); } else { /* Conversion. */ - mal_device__read_frames_from_client(pDevice, (mappedSizeInBytesPlayback/bpfPlayback), pMappedBufferPlayback); + ma_device__read_frames_from_client(pDevice, (mappedSizeInBytesPlayback/bpfPlayback), pMappedBufferPlayback); } - hr = mal_IDirectSoundBuffer_Unlock((mal_IDirectSoundBuffer*)pDevice->dsound.pPlaybackBuffer, pMappedBufferPlayback, mappedSizeInBytesPlayback, NULL, 0); + hr = ma_IDirectSoundBuffer_Unlock((ma_IDirectSoundBuffer*)pDevice->dsound.pPlaybackBuffer, pMappedBufferPlayback, mappedSizeInBytesPlayback, NULL, 0); if (FAILED(hr)) { - result = mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] Failed to unlock internal buffer from playback device after writing to the device.", MA_FAILED_TO_UNMAP_DEVICE_BUFFER); + result = ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] Failed to unlock internal buffer from playback device after writing to the device.", MA_FAILED_TO_UNMAP_DEVICE_BUFFER); break; } @@ -9891,8 +9891,8 @@ mal_result mal_device_main_loop__dsound(mal_device* pDevice) */ framesWrittenToPlaybackDevice += mappedSizeInBytesPlayback/bpfPlayback; if (!isPlaybackDeviceStarted && framesWrittenToPlaybackDevice >= (pDevice->playback.internalBufferSizeInFrames/pDevice->playback.internalPeriods)) { - if (FAILED(mal_IDirectSoundBuffer_Play((mal_IDirectSoundBuffer*)pDevice->dsound.pPlaybackBuffer, 0, 0, MA_DSBPLAY_LOOPING))) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] IDirectSoundBuffer_Play() failed.", MA_FAILED_TO_START_BACKEND_DEVICE); + if (FAILED(ma_IDirectSoundBuffer_Play((ma_IDirectSoundBuffer*)pDevice->dsound.pPlaybackBuffer, 0, 0, MA_DSBPLAY_LOOPING))) { + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] IDirectSoundBuffer_Play() failed.", MA_FAILED_TO_START_BACKEND_DEVICE); } isPlaybackDeviceStarted = MA_TRUE; } @@ -9908,20 +9908,20 @@ mal_result mal_device_main_loop__dsound(mal_device* pDevice) } /* Getting here means the device is being stopped. */ - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { - if (FAILED(mal_IDirectSoundCaptureBuffer_Stop((mal_IDirectSoundCaptureBuffer*)pDevice->dsound.pCaptureBuffer))) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] IDirectSoundCaptureBuffer_Stop() failed.", MA_FAILED_TO_STOP_BACKEND_DEVICE); + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { + if (FAILED(ma_IDirectSoundCaptureBuffer_Stop((ma_IDirectSoundCaptureBuffer*)pDevice->dsound.pCaptureBuffer))) { + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] IDirectSoundCaptureBuffer_Stop() failed.", MA_FAILED_TO_STOP_BACKEND_DEVICE); } } - if (pDevice->type == mal_device_type_playback || pDevice->type == mal_device_type_duplex) { + if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) { /* The playback device should be drained before stopping. All we do is wait until the available bytes is equal to the size of the buffer. */ if (isPlaybackDeviceStarted) { for (;;) { DWORD availableBytesPlayback = 0; DWORD physicalPlayCursorInBytes; DWORD physicalWriteCursorInBytes; - if (FAILED(mal_IDirectSoundBuffer_GetCurrentPosition((mal_IDirectSoundBuffer*)pDevice->dsound.pPlaybackBuffer, &physicalPlayCursorInBytes, &physicalWriteCursorInBytes))) { + if (FAILED(ma_IDirectSoundBuffer_GetCurrentPosition((ma_IDirectSoundBuffer*)pDevice->dsound.pPlaybackBuffer, &physicalPlayCursorInBytes, &physicalWriteCursorInBytes))) { break; } @@ -9951,55 +9951,55 @@ mal_result mal_device_main_loop__dsound(mal_device* pDevice) break; } - mal_sleep(waitTimeInMilliseconds); + ma_sleep(waitTimeInMilliseconds); } } - if (FAILED(mal_IDirectSoundBuffer_Stop((mal_IDirectSoundBuffer*)pDevice->dsound.pPlaybackBuffer))) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] IDirectSoundBuffer_Stop() failed.", MA_FAILED_TO_STOP_BACKEND_DEVICE); + if (FAILED(ma_IDirectSoundBuffer_Stop((ma_IDirectSoundBuffer*)pDevice->dsound.pPlaybackBuffer))) { + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[DirectSound] IDirectSoundBuffer_Stop() failed.", MA_FAILED_TO_STOP_BACKEND_DEVICE); } - mal_IDirectSoundBuffer_SetCurrentPosition((mal_IDirectSoundBuffer*)pDevice->dsound.pPlaybackBuffer, 0); + ma_IDirectSoundBuffer_SetCurrentPosition((ma_IDirectSoundBuffer*)pDevice->dsound.pPlaybackBuffer, 0); } return MA_SUCCESS; } -mal_result mal_context_uninit__dsound(mal_context* pContext) +ma_result ma_context_uninit__dsound(ma_context* pContext) { - mal_assert(pContext != NULL); - mal_assert(pContext->backend == mal_backend_dsound); + ma_assert(pContext != NULL); + ma_assert(pContext->backend == ma_backend_dsound); - mal_dlclose(pContext->dsound.hDSoundDLL); + ma_dlclose(pContext->dsound.hDSoundDLL); return MA_SUCCESS; } -mal_result mal_context_init__dsound(mal_context* pContext) +ma_result ma_context_init__dsound(ma_context* pContext) { - mal_assert(pContext != NULL); + ma_assert(pContext != NULL); - pContext->dsound.hDSoundDLL = mal_dlopen("dsound.dll"); + pContext->dsound.hDSoundDLL = ma_dlopen("dsound.dll"); if (pContext->dsound.hDSoundDLL == NULL) { return MA_API_NOT_FOUND; } - pContext->dsound.DirectSoundCreate = mal_dlsym(pContext->dsound.hDSoundDLL, "DirectSoundCreate"); - pContext->dsound.DirectSoundEnumerateA = mal_dlsym(pContext->dsound.hDSoundDLL, "DirectSoundEnumerateA"); - pContext->dsound.DirectSoundCaptureCreate = mal_dlsym(pContext->dsound.hDSoundDLL, "DirectSoundCaptureCreate"); - pContext->dsound.DirectSoundCaptureEnumerateA = mal_dlsym(pContext->dsound.hDSoundDLL, "DirectSoundCaptureEnumerateA"); + pContext->dsound.DirectSoundCreate = ma_dlsym(pContext->dsound.hDSoundDLL, "DirectSoundCreate"); + pContext->dsound.DirectSoundEnumerateA = ma_dlsym(pContext->dsound.hDSoundDLL, "DirectSoundEnumerateA"); + pContext->dsound.DirectSoundCaptureCreate = ma_dlsym(pContext->dsound.hDSoundDLL, "DirectSoundCaptureCreate"); + pContext->dsound.DirectSoundCaptureEnumerateA = ma_dlsym(pContext->dsound.hDSoundDLL, "DirectSoundCaptureEnumerateA"); - pContext->onUninit = mal_context_uninit__dsound; - pContext->onDeviceIDEqual = mal_context_is_device_id_equal__dsound; - pContext->onEnumDevices = mal_context_enumerate_devices__dsound; - pContext->onGetDeviceInfo = mal_context_get_device_info__dsound; - pContext->onDeviceInit = mal_device_init__dsound; - pContext->onDeviceUninit = mal_device_uninit__dsound; + pContext->onUninit = ma_context_uninit__dsound; + pContext->onDeviceIDEqual = ma_context_is_device_id_equal__dsound; + pContext->onEnumDevices = ma_context_enumerate_devices__dsound; + pContext->onGetDeviceInfo = ma_context_get_device_info__dsound; + pContext->onDeviceInit = ma_device_init__dsound; + pContext->onDeviceUninit = ma_device_uninit__dsound; pContext->onDeviceStart = NULL; /* Not used. Started in onDeviceMainLoop. */ pContext->onDeviceStop = NULL; /* Not used. Stopped in onDeviceMainLoop. */ pContext->onDeviceWrite = NULL; pContext->onDeviceRead = NULL; - pContext->onDeviceMainLoop = mal_device_main_loop__dsound; + pContext->onDeviceMainLoop = ma_device_main_loop__dsound; return MA_SUCCESS; } @@ -10046,7 +10046,7 @@ typedef struct } MA_WAVEINCAPS2A; typedef UINT (WINAPI * MA_PFN_waveOutGetNumDevs)(void); -typedef MMRESULT (WINAPI * MA_PFN_waveOutGetDevCapsA)(mal_uintptr uDeviceID, LPWAVEOUTCAPSA pwoc, UINT cbwoc); +typedef MMRESULT (WINAPI * MA_PFN_waveOutGetDevCapsA)(ma_uintptr uDeviceID, LPWAVEOUTCAPSA pwoc, UINT cbwoc); typedef MMRESULT (WINAPI * MA_PFN_waveOutOpen)(LPHWAVEOUT phwo, UINT uDeviceID, LPCWAVEFORMATEX pwfx, DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD fdwOpen); typedef MMRESULT (WINAPI * MA_PFN_waveOutClose)(HWAVEOUT hwo); typedef MMRESULT (WINAPI * MA_PFN_waveOutPrepareHeader)(HWAVEOUT hwo, LPWAVEHDR pwh, UINT cbwh); @@ -10054,7 +10054,7 @@ typedef MMRESULT (WINAPI * MA_PFN_waveOutUnprepareHeader)(HWAVEOUT hwo, LPWAVEHD typedef MMRESULT (WINAPI * MA_PFN_waveOutWrite)(HWAVEOUT hwo, LPWAVEHDR pwh, UINT cbwh); typedef MMRESULT (WINAPI * MA_PFN_waveOutReset)(HWAVEOUT hwo); typedef UINT (WINAPI * MA_PFN_waveInGetNumDevs)(void); -typedef MMRESULT (WINAPI * MA_PFN_waveInGetDevCapsA)(mal_uintptr uDeviceID, LPWAVEINCAPSA pwic, UINT cbwic); +typedef MMRESULT (WINAPI * MA_PFN_waveInGetDevCapsA)(ma_uintptr uDeviceID, LPWAVEINCAPSA pwic, UINT cbwic); typedef MMRESULT (WINAPI * MA_PFN_waveInOpen)(LPHWAVEIN phwi, UINT uDeviceID, LPCWAVEFORMATEX pwfx, DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD fdwOpen); typedef MMRESULT (WINAPI * MA_PFN_waveInClose)(HWAVEIN hwi); typedef MMRESULT (WINAPI * MA_PFN_waveInPrepareHeader)(HWAVEIN hwi, LPWAVEHDR pwh, UINT cbwh); @@ -10063,7 +10063,7 @@ typedef MMRESULT (WINAPI * MA_PFN_waveInAddBuffer)(HWAVEIN hwi, LPWAVEHDR pwh, U typedef MMRESULT (WINAPI * MA_PFN_waveInStart)(HWAVEIN hwi); typedef MMRESULT (WINAPI * MA_PFN_waveInReset)(HWAVEIN hwi); -mal_result mal_result_from_MMRESULT(MMRESULT resultMM) +ma_result ma_result_from_MMRESULT(MMRESULT resultMM) { switch (resultMM) { case MMSYSERR_NOERROR: return MA_SUCCESS; @@ -10078,7 +10078,7 @@ mal_result mal_result_from_MMRESULT(MMRESULT resultMM) } } -char* mal_find_last_character(char* str, char ch) +char* ma_find_last_character(char* str, char ch) { if (str == NULL) { return NULL; @@ -10107,7 +10107,7 @@ typedef struct GUID NameGuid; } MA_WAVECAPSA; -mal_result mal_get_best_info_from_formats_flags__winmm(DWORD dwFormats, WORD channels, WORD* pBitsPerSample, DWORD* pSampleRate) +ma_result ma_get_best_info_from_formats_flags__winmm(DWORD dwFormats, WORD channels, WORD* pBitsPerSample, DWORD* pSampleRate) { if (pBitsPerSample) { *pBitsPerSample = 0; @@ -10187,11 +10187,11 @@ mal_result mal_get_best_info_from_formats_flags__winmm(DWORD dwFormats, WORD cha return MA_SUCCESS; } -mal_result mal_formats_flags_to_WAVEFORMATEX__winmm(DWORD dwFormats, WORD channels, WAVEFORMATEX* pWF) +ma_result ma_formats_flags_to_WAVEFORMATEX__winmm(DWORD dwFormats, WORD channels, WAVEFORMATEX* pWF) { - mal_assert(pWF != NULL); + ma_assert(pWF != NULL); - mal_zero_object(pWF); + ma_zero_object(pWF); pWF->cbSize = sizeof(*pWF); pWF->wFormatTag = WAVE_FORMAT_PCM; pWF->nChannels = (WORD)channels; @@ -10263,11 +10263,11 @@ mal_result mal_formats_flags_to_WAVEFORMATEX__winmm(DWORD dwFormats, WORD channe return MA_SUCCESS; } -mal_result mal_context_get_device_info_from_WAVECAPS(mal_context* pContext, MA_WAVECAPSA* pCaps, mal_device_info* pDeviceInfo) +ma_result ma_context_get_device_info_from_WAVECAPS(ma_context* pContext, MA_WAVECAPSA* pCaps, ma_device_info* pDeviceInfo) { - mal_assert(pContext != NULL); - mal_assert(pCaps != NULL); - mal_assert(pDeviceInfo != NULL); + ma_assert(pContext != NULL); + ma_assert(pCaps != NULL); + ma_assert(pDeviceInfo != NULL); // Name / Description // @@ -10276,7 +10276,7 @@ mal_result mal_context_get_device_info_from_WAVECAPS(mal_context* pContext, MA_W // looking in the registry for the full name. If we can't find it there, we need to just fall back to the default name. // Set the default to begin with. - mal_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), pCaps->szPname, (size_t)-1); + ma_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), pCaps->szPname, (size_t)-1); // Now try the registry. There's a few things to consider here: // - The name GUID can be null, in which we case we just need to stick to the original 31 characters. @@ -10286,15 +10286,15 @@ mal_result mal_context_get_device_info_from_WAVECAPS(mal_context* pContext, MA_W // but WinMM does not specificy the component name. From my admittedly limited testing, I've notice the component name seems to // usually fit within the 31 characters of the fixed sized buffer, so what I'm going to do is parse that string for the component // name, and then concatenate the name from the registry. - if (!mal_is_guid_equal(&pCaps->NameGuid, &MA_GUID_NULL)) { + if (!ma_is_guid_equal(&pCaps->NameGuid, &MA_GUID_NULL)) { wchar_t guidStrW[256]; - if (((MA_PFN_StringFromGUID2)pContext->win32.StringFromGUID2)(&pCaps->NameGuid, guidStrW, mal_countof(guidStrW)) > 0) { + if (((MA_PFN_StringFromGUID2)pContext->win32.StringFromGUID2)(&pCaps->NameGuid, guidStrW, ma_countof(guidStrW)) > 0) { char guidStr[256]; WideCharToMultiByte(CP_UTF8, 0, guidStrW, -1, guidStr, sizeof(guidStr), 0, FALSE); char keyStr[1024]; - mal_strcpy_s(keyStr, sizeof(keyStr), "SYSTEM\\CurrentControlSet\\Control\\MediaCategories\\"); - mal_strcat_s(keyStr, sizeof(keyStr), guidStr); + ma_strcpy_s(keyStr, sizeof(keyStr), "SYSTEM\\CurrentControlSet\\Control\\MediaCategories\\"); + ma_strcat_s(keyStr, sizeof(keyStr), guidStr); HKEY hKey; LONG result = ((MA_PFN_RegOpenKeyExA)pContext->win32.RegOpenKeyExA)(HKEY_LOCAL_MACHINE, keyStr, 0, KEY_READ, &hKey); @@ -10307,18 +10307,18 @@ mal_result mal_context_get_device_info_from_WAVECAPS(mal_context* pContext, MA_W if (result == ERROR_SUCCESS) { // We have the value from the registry, so now we need to construct the name string. char name[1024]; - if (mal_strcpy_s(name, sizeof(name), pDeviceInfo->name) == 0) { - char* nameBeg = mal_find_last_character(name, '('); + if (ma_strcpy_s(name, sizeof(name), pDeviceInfo->name) == 0) { + char* nameBeg = ma_find_last_character(name, '('); if (nameBeg != NULL) { size_t leadingLen = (nameBeg - name); - mal_strncpy_s(nameBeg + 1, sizeof(name) - leadingLen, (const char*)nameFromReg, (size_t)-1); + ma_strncpy_s(nameBeg + 1, sizeof(name) - leadingLen, (const char*)nameFromReg, (size_t)-1); // The closing ")", if it can fit. if (leadingLen + nameFromRegSize < sizeof(name)-1) { - mal_strcat_s(name, sizeof(name), ")"); + ma_strcat_s(name, sizeof(name), ")"); } - mal_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), name, (size_t)-1); + ma_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), name, (size_t)-1); } } } @@ -10329,7 +10329,7 @@ mal_result mal_context_get_device_info_from_WAVECAPS(mal_context* pContext, MA_W WORD bitsPerSample; DWORD sampleRate; - mal_result result = mal_get_best_info_from_formats_flags__winmm(pCaps->dwFormats, pCaps->wChannels, &bitsPerSample, &sampleRate); + ma_result result = ma_get_best_info_from_formats_flags__winmm(pCaps->dwFormats, pCaps->wChannels, &bitsPerSample, &sampleRate); if (result != MA_SUCCESS) { return result; } @@ -10340,13 +10340,13 @@ mal_result mal_context_get_device_info_from_WAVECAPS(mal_context* pContext, MA_W pDeviceInfo->maxSampleRate = sampleRate; pDeviceInfo->formatCount = 1; if (bitsPerSample == 8) { - pDeviceInfo->formats[0] = mal_format_u8; + pDeviceInfo->formats[0] = ma_format_u8; } else if (bitsPerSample == 16) { - pDeviceInfo->formats[0] = mal_format_s16; + pDeviceInfo->formats[0] = ma_format_s16; } else if (bitsPerSample == 24) { - pDeviceInfo->formats[0] = mal_format_s24; + pDeviceInfo->formats[0] = ma_format_s24; } else if (bitsPerSample == 32) { - pDeviceInfo->formats[0] = mal_format_s32; + pDeviceInfo->formats[0] = ma_format_s32; } else { return MA_FORMAT_NOT_SUPPORTED; } @@ -10354,63 +10354,63 @@ mal_result mal_context_get_device_info_from_WAVECAPS(mal_context* pContext, MA_W return MA_SUCCESS; } -mal_result mal_context_get_device_info_from_WAVEOUTCAPS2(mal_context* pContext, MA_WAVEOUTCAPS2A* pCaps, mal_device_info* pDeviceInfo) +ma_result ma_context_get_device_info_from_WAVEOUTCAPS2(ma_context* pContext, MA_WAVEOUTCAPS2A* pCaps, ma_device_info* pDeviceInfo) { - mal_assert(pContext != NULL); - mal_assert(pCaps != NULL); - mal_assert(pDeviceInfo != NULL); + ma_assert(pContext != NULL); + ma_assert(pCaps != NULL); + ma_assert(pDeviceInfo != NULL); MA_WAVECAPSA caps; - mal_copy_memory(caps.szPname, pCaps->szPname, sizeof(caps.szPname)); + ma_copy_memory(caps.szPname, pCaps->szPname, sizeof(caps.szPname)); caps.dwFormats = pCaps->dwFormats; caps.wChannels = pCaps->wChannels; caps.NameGuid = pCaps->NameGuid; - return mal_context_get_device_info_from_WAVECAPS(pContext, &caps, pDeviceInfo); + return ma_context_get_device_info_from_WAVECAPS(pContext, &caps, pDeviceInfo); } -mal_result mal_context_get_device_info_from_WAVEINCAPS2(mal_context* pContext, MA_WAVEINCAPS2A* pCaps, mal_device_info* pDeviceInfo) +ma_result ma_context_get_device_info_from_WAVEINCAPS2(ma_context* pContext, MA_WAVEINCAPS2A* pCaps, ma_device_info* pDeviceInfo) { - mal_assert(pContext != NULL); - mal_assert(pCaps != NULL); - mal_assert(pDeviceInfo != NULL); + ma_assert(pContext != NULL); + ma_assert(pCaps != NULL); + ma_assert(pDeviceInfo != NULL); MA_WAVECAPSA caps; - mal_copy_memory(caps.szPname, pCaps->szPname, sizeof(caps.szPname)); + ma_copy_memory(caps.szPname, pCaps->szPname, sizeof(caps.szPname)); caps.dwFormats = pCaps->dwFormats; caps.wChannels = pCaps->wChannels; caps.NameGuid = pCaps->NameGuid; - return mal_context_get_device_info_from_WAVECAPS(pContext, &caps, pDeviceInfo); + return ma_context_get_device_info_from_WAVECAPS(pContext, &caps, pDeviceInfo); } -mal_bool32 mal_context_is_device_id_equal__winmm(mal_context* pContext, const mal_device_id* pID0, const mal_device_id* pID1) +ma_bool32 ma_context_is_device_id_equal__winmm(ma_context* pContext, const ma_device_id* pID0, const ma_device_id* pID1) { - mal_assert(pContext != NULL); - mal_assert(pID0 != NULL); - mal_assert(pID1 != NULL); + ma_assert(pContext != NULL); + ma_assert(pID0 != NULL); + ma_assert(pID1 != NULL); (void)pContext; return pID0->winmm == pID1->winmm; } -mal_result mal_context_enumerate_devices__winmm(mal_context* pContext, mal_enum_devices_callback_proc callback, void* pUserData) +ma_result ma_context_enumerate_devices__winmm(ma_context* pContext, ma_enum_devices_callback_proc callback, void* pUserData) { - mal_assert(pContext != NULL); - mal_assert(callback != NULL); + ma_assert(pContext != NULL); + ma_assert(callback != NULL); // Playback. UINT playbackDeviceCount = ((MA_PFN_waveOutGetNumDevs)pContext->winmm.waveOutGetNumDevs)(); for (UINT iPlaybackDevice = 0; iPlaybackDevice < playbackDeviceCount; ++iPlaybackDevice) { MA_WAVEOUTCAPS2A caps; - mal_zero_object(&caps); + ma_zero_object(&caps); MMRESULT result = ((MA_PFN_waveOutGetDevCapsA)pContext->winmm.waveOutGetDevCapsA)(iPlaybackDevice, (WAVEOUTCAPSA*)&caps, sizeof(caps)); if (result == MMSYSERR_NOERROR) { - mal_device_info deviceInfo; - mal_zero_object(&deviceInfo); + ma_device_info deviceInfo; + ma_zero_object(&deviceInfo); deviceInfo.id.winmm = iPlaybackDevice; - if (mal_context_get_device_info_from_WAVEOUTCAPS2(pContext, &caps, &deviceInfo) == MA_SUCCESS) { - mal_bool32 cbResult = callback(pContext, mal_device_type_playback, &deviceInfo, pUserData); + if (ma_context_get_device_info_from_WAVEOUTCAPS2(pContext, &caps, &deviceInfo) == MA_SUCCESS) { + ma_bool32 cbResult = callback(pContext, ma_device_type_playback, &deviceInfo, pUserData); if (cbResult == MA_FALSE) { return MA_SUCCESS; // Enumeration was stopped. } @@ -10422,15 +10422,15 @@ mal_result mal_context_enumerate_devices__winmm(mal_context* pContext, mal_enum_ UINT captureDeviceCount = ((MA_PFN_waveInGetNumDevs)pContext->winmm.waveInGetNumDevs)(); for (UINT iCaptureDevice = 0; iCaptureDevice < captureDeviceCount; ++iCaptureDevice) { MA_WAVEINCAPS2A caps; - mal_zero_object(&caps); + ma_zero_object(&caps); MMRESULT result = ((MA_PFN_waveInGetDevCapsA)pContext->winmm.waveInGetDevCapsA)(iCaptureDevice, (WAVEINCAPSA*)&caps, sizeof(caps)); if (result == MMSYSERR_NOERROR) { - mal_device_info deviceInfo; - mal_zero_object(&deviceInfo); + ma_device_info deviceInfo; + ma_zero_object(&deviceInfo); deviceInfo.id.winmm = iCaptureDevice; - if (mal_context_get_device_info_from_WAVEINCAPS2(pContext, &caps, &deviceInfo) == MA_SUCCESS) { - mal_bool32 cbResult = callback(pContext, mal_device_type_capture, &deviceInfo, pUserData); + if (ma_context_get_device_info_from_WAVEINCAPS2(pContext, &caps, &deviceInfo) == MA_SUCCESS) { + ma_bool32 cbResult = callback(pContext, ma_device_type_capture, &deviceInfo, pUserData); if (cbResult == MA_FALSE) { return MA_SUCCESS; // Enumeration was stopped. } @@ -10441,11 +10441,11 @@ mal_result mal_context_enumerate_devices__winmm(mal_context* pContext, mal_enum_ return MA_SUCCESS; } -mal_result mal_context_get_device_info__winmm(mal_context* pContext, mal_device_type deviceType, const mal_device_id* pDeviceID, mal_share_mode shareMode, mal_device_info* pDeviceInfo) +ma_result ma_context_get_device_info__winmm(ma_context* pContext, ma_device_type deviceType, const ma_device_id* pDeviceID, ma_share_mode shareMode, ma_device_info* pDeviceInfo) { - mal_assert(pContext != NULL); + ma_assert(pContext != NULL); - if (shareMode == mal_share_mode_exclusive) { + if (shareMode == ma_share_mode_exclusive) { return MA_SHARE_MODE_NOT_SUPPORTED; } @@ -10456,19 +10456,19 @@ mal_result mal_context_get_device_info__winmm(mal_context* pContext, mal_device_ pDeviceInfo->id.winmm = winMMDeviceID; - if (deviceType == mal_device_type_playback) { + if (deviceType == ma_device_type_playback) { MA_WAVEOUTCAPS2A caps; - mal_zero_object(&caps); + ma_zero_object(&caps); MMRESULT result = ((MA_PFN_waveOutGetDevCapsA)pContext->winmm.waveOutGetDevCapsA)(winMMDeviceID, (WAVEOUTCAPSA*)&caps, sizeof(caps)); if (result == MMSYSERR_NOERROR) { - return mal_context_get_device_info_from_WAVEOUTCAPS2(pContext, &caps, pDeviceInfo); + return ma_context_get_device_info_from_WAVEOUTCAPS2(pContext, &caps, pDeviceInfo); } } else { MA_WAVEINCAPS2A caps; - mal_zero_object(&caps); + ma_zero_object(&caps); MMRESULT result = ((MA_PFN_waveInGetDevCapsA)pContext->winmm.waveInGetDevCapsA)(winMMDeviceID, (WAVEINCAPSA*)&caps, sizeof(caps)); if (result == MMSYSERR_NOERROR) { - return mal_context_get_device_info_from_WAVEINCAPS2(pContext, &caps, pDeviceInfo); + return ma_context_get_device_info_from_WAVEINCAPS2(pContext, &caps, pDeviceInfo); } } @@ -10476,53 +10476,53 @@ mal_result mal_context_get_device_info__winmm(mal_context* pContext, mal_device_ } -void mal_device_uninit__winmm(mal_device* pDevice) +void ma_device_uninit__winmm(ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); ((MA_PFN_waveOutReset)pDevice->pContext->winmm.waveOutReset); - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { ((MA_PFN_waveInClose)pDevice->pContext->winmm.waveInClose)((HWAVEIN)pDevice->winmm.hDeviceCapture); CloseHandle((HANDLE)pDevice->winmm.hEventCapture); } - if (pDevice->type == mal_device_type_playback) { + if (pDevice->type == ma_device_type_playback) { ((MA_PFN_waveOutClose)pDevice->pContext->winmm.waveOutClose)((HWAVEOUT)pDevice->winmm.hDevicePlayback); CloseHandle((HANDLE)pDevice->winmm.hEventPlayback); } - mal_free(pDevice->winmm._pHeapData); + ma_free(pDevice->winmm._pHeapData); - mal_zero_object(&pDevice->winmm); // Safety. + ma_zero_object(&pDevice->winmm); // Safety. } -mal_result mal_device_init__winmm(mal_context* pContext, const mal_device_config* pConfig, mal_device* pDevice) +ma_result ma_device_init__winmm(ma_context* pContext, const ma_device_config* pConfig, ma_device* pDevice) { const char* errorMsg = ""; - mal_result errorCode = MA_ERROR; - mal_result result = MA_SUCCESS; - mal_uint32 heapSize; + ma_result errorCode = MA_ERROR; + ma_result result = MA_SUCCESS; + ma_uint32 heapSize; UINT winMMDeviceIDPlayback = 0; UINT winMMDeviceIDCapture = 0; - mal_assert(pDevice != NULL); - mal_zero_object(&pDevice->winmm); + ma_assert(pDevice != NULL); + ma_zero_object(&pDevice->winmm); /* No exlusive mode with WinMM. */ - if (((pConfig->deviceType == mal_device_type_playback || pConfig->deviceType == mal_device_type_duplex) && pConfig->playback.shareMode == mal_share_mode_exclusive) || - ((pConfig->deviceType == mal_device_type_capture || pConfig->deviceType == mal_device_type_duplex) && pConfig->capture.shareMode == mal_share_mode_exclusive)) { + if (((pConfig->deviceType == ma_device_type_playback || pConfig->deviceType == ma_device_type_duplex) && pConfig->playback.shareMode == ma_share_mode_exclusive) || + ((pConfig->deviceType == ma_device_type_capture || pConfig->deviceType == ma_device_type_duplex) && pConfig->capture.shareMode == ma_share_mode_exclusive)) { return MA_SHARE_MODE_NOT_SUPPORTED; } - mal_uint32 bufferSizeInMilliseconds = pConfig->bufferSizeInMilliseconds; + ma_uint32 bufferSizeInMilliseconds = pConfig->bufferSizeInMilliseconds; if (bufferSizeInMilliseconds == 0) { - bufferSizeInMilliseconds = mal_calculate_buffer_size_in_milliseconds_from_frames(pConfig->bufferSizeInFrames, pConfig->sampleRate); + bufferSizeInMilliseconds = ma_calculate_buffer_size_in_milliseconds_from_frames(pConfig->bufferSizeInFrames, pConfig->sampleRate); } /* WinMM has horrible latency. */ if (pDevice->usingDefaultBufferSize) { - if (pConfig->performanceProfile == mal_performance_profile_low_latency) { + if (pConfig->performanceProfile == ma_performance_profile_low_latency) { bufferSizeInMilliseconds = 40 * pConfig->periods; } else { bufferSizeInMilliseconds = 400 * pConfig->periods; @@ -10538,13 +10538,13 @@ mal_result mal_device_init__winmm(mal_context* pContext, const mal_device_config } // The capture device needs to be initialized first. - if (pConfig->deviceType == mal_device_type_capture || pConfig->deviceType == mal_device_type_duplex) { + if (pConfig->deviceType == ma_device_type_capture || pConfig->deviceType == ma_device_type_duplex) { WAVEINCAPSA caps; WAVEFORMATEX wf; MMRESULT resultMM; // We use an event to know when a new fragment needs to be enqueued. - pDevice->winmm.hEventCapture = (mal_handle)CreateEvent(NULL, TRUE, TRUE, NULL); + pDevice->winmm.hEventCapture = (ma_handle)CreateEvent(NULL, TRUE, TRUE, NULL); if (pDevice->winmm.hEventCapture == NULL) { errorMsg = "[WinMM] Failed to create event for fragment enqueing for the capture device.", errorCode = MA_FAILED_TO_CREATE_EVENT; goto on_error; @@ -10556,7 +10556,7 @@ mal_result mal_device_init__winmm(mal_context* pContext, const mal_device_config goto on_error; } - result = mal_formats_flags_to_WAVEFORMATEX__winmm(caps.dwFormats, caps.wChannels, &wf); + result = ma_formats_flags_to_WAVEFORMATEX__winmm(caps.dwFormats, caps.wChannels, &wf); if (result != MA_SUCCESS) { errorMsg = "[WinMM] Could not find appropriate format for internal device.", errorCode = result; goto on_error; @@ -10568,21 +10568,21 @@ mal_result mal_device_init__winmm(mal_context* pContext, const mal_device_config goto on_error; } - pDevice->capture.internalFormat = mal_format_from_WAVEFORMATEX(&wf); + pDevice->capture.internalFormat = ma_format_from_WAVEFORMATEX(&wf); pDevice->capture.internalChannels = wf.nChannels; pDevice->capture.internalSampleRate = wf.nSamplesPerSec; - mal_get_standard_channel_map(mal_standard_channel_map_microsoft, pDevice->capture.internalChannels, pDevice->capture.internalChannelMap); + ma_get_standard_channel_map(ma_standard_channel_map_microsoft, pDevice->capture.internalChannels, pDevice->capture.internalChannelMap); pDevice->capture.internalPeriods = pConfig->periods; - pDevice->capture.internalBufferSizeInFrames = mal_calculate_buffer_size_in_frames_from_milliseconds(bufferSizeInMilliseconds, pDevice->capture.internalSampleRate); + pDevice->capture.internalBufferSizeInFrames = ma_calculate_buffer_size_in_frames_from_milliseconds(bufferSizeInMilliseconds, pDevice->capture.internalSampleRate); } - if (pConfig->deviceType == mal_device_type_playback || pConfig->deviceType == mal_device_type_duplex) { + if (pConfig->deviceType == ma_device_type_playback || pConfig->deviceType == ma_device_type_duplex) { WAVEOUTCAPSA caps; WAVEFORMATEX wf; MMRESULT resultMM; // We use an event to know when a new fragment needs to be enqueued. - pDevice->winmm.hEventPlayback = (mal_handle)CreateEvent(NULL, TRUE, TRUE, NULL); + pDevice->winmm.hEventPlayback = (ma_handle)CreateEvent(NULL, TRUE, TRUE, NULL); if (pDevice->winmm.hEventPlayback == NULL) { errorMsg = "[WinMM] Failed to create event for fragment enqueing for the playback device.", errorCode = MA_FAILED_TO_CREATE_EVENT; goto on_error; @@ -10594,7 +10594,7 @@ mal_result mal_device_init__winmm(mal_context* pContext, const mal_device_config goto on_error; } - result = mal_formats_flags_to_WAVEFORMATEX__winmm(caps.dwFormats, caps.wChannels, &wf); + result = ma_formats_flags_to_WAVEFORMATEX__winmm(caps.dwFormats, caps.wChannels, &wf); if (result != MA_SUCCESS) { errorMsg = "[WinMM] Could not find appropriate format for internal device.", errorCode = result; goto on_error; @@ -10606,35 +10606,35 @@ mal_result mal_device_init__winmm(mal_context* pContext, const mal_device_config goto on_error; } - pDevice->playback.internalFormat = mal_format_from_WAVEFORMATEX(&wf); + pDevice->playback.internalFormat = ma_format_from_WAVEFORMATEX(&wf); pDevice->playback.internalChannels = wf.nChannels; pDevice->playback.internalSampleRate = wf.nSamplesPerSec; - mal_get_standard_channel_map(mal_standard_channel_map_microsoft, pDevice->playback.internalChannels, pDevice->playback.internalChannelMap); + ma_get_standard_channel_map(ma_standard_channel_map_microsoft, pDevice->playback.internalChannels, pDevice->playback.internalChannelMap); pDevice->playback.internalPeriods = pConfig->periods; - pDevice->playback.internalBufferSizeInFrames = mal_calculate_buffer_size_in_frames_from_milliseconds(bufferSizeInMilliseconds, pDevice->playback.internalSampleRate); + pDevice->playback.internalBufferSizeInFrames = ma_calculate_buffer_size_in_frames_from_milliseconds(bufferSizeInMilliseconds, pDevice->playback.internalSampleRate); } // The heap allocated data is allocated like so: // // [Capture WAVEHDRs][Playback WAVEHDRs][Capture Intermediary Buffer][Playback Intermediary Buffer] heapSize = 0; - if (pConfig->deviceType == mal_device_type_capture || pConfig->deviceType == mal_device_type_duplex) { - heapSize += sizeof(WAVEHDR)*pDevice->capture.internalPeriods + (pDevice->capture.internalBufferSizeInFrames*mal_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels)); + if (pConfig->deviceType == ma_device_type_capture || pConfig->deviceType == ma_device_type_duplex) { + heapSize += sizeof(WAVEHDR)*pDevice->capture.internalPeriods + (pDevice->capture.internalBufferSizeInFrames*ma_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels)); } - if (pConfig->deviceType == mal_device_type_playback || pConfig->deviceType == mal_device_type_duplex) { - heapSize += sizeof(WAVEHDR)*pDevice->playback.internalPeriods + (pDevice->playback.internalBufferSizeInFrames*mal_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels)); + if (pConfig->deviceType == ma_device_type_playback || pConfig->deviceType == ma_device_type_duplex) { + heapSize += sizeof(WAVEHDR)*pDevice->playback.internalPeriods + (pDevice->playback.internalBufferSizeInFrames*ma_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels)); } - pDevice->winmm._pHeapData = (mal_uint8*)mal_malloc(heapSize); + pDevice->winmm._pHeapData = (ma_uint8*)ma_malloc(heapSize); if (pDevice->winmm._pHeapData == NULL) { errorMsg = "[WinMM] Failed to allocate memory for the intermediary buffer.", errorCode = MA_OUT_OF_MEMORY; goto on_error; } - mal_zero_memory(pDevice->winmm._pHeapData, heapSize); + ma_zero_memory(pDevice->winmm._pHeapData, heapSize); - if (pConfig->deviceType == mal_device_type_capture || pConfig->deviceType == mal_device_type_duplex) { - if (pConfig->deviceType == mal_device_type_capture) { + if (pConfig->deviceType == ma_device_type_capture || pConfig->deviceType == ma_device_type_duplex) { + if (pConfig->deviceType == ma_device_type_capture) { pDevice->winmm.pWAVEHDRCapture = pDevice->winmm._pHeapData; pDevice->winmm.pIntermediaryBufferCapture = pDevice->winmm._pHeapData + (sizeof(WAVEHDR)*(pDevice->capture.internalPeriods)); } else { @@ -10643,8 +10643,8 @@ mal_result mal_device_init__winmm(mal_context* pContext, const mal_device_config } /* Prepare headers. */ - for (mal_uint32 iPeriod = 0; iPeriod < pDevice->capture.internalPeriods; ++iPeriod) { - mal_uint32 fragmentSizeInBytes = mal_get_fragment_size_in_bytes(pDevice->capture.internalBufferSizeInFrames, pDevice->capture.internalPeriods, pDevice->capture.internalFormat, pDevice->capture.internalChannels); + for (ma_uint32 iPeriod = 0; iPeriod < pDevice->capture.internalPeriods; ++iPeriod) { + ma_uint32 fragmentSizeInBytes = ma_get_fragment_size_in_bytes(pDevice->capture.internalBufferSizeInFrames, pDevice->capture.internalPeriods, pDevice->capture.internalFormat, pDevice->capture.internalChannels); ((WAVEHDR*)pDevice->winmm.pWAVEHDRCapture)[iPeriod].lpData = (LPSTR)(pDevice->winmm.pIntermediaryBufferCapture + (fragmentSizeInBytes*iPeriod)); ((WAVEHDR*)pDevice->winmm.pWAVEHDRCapture)[iPeriod].dwBufferLength = fragmentSizeInBytes; @@ -10659,18 +10659,18 @@ mal_result mal_device_init__winmm(mal_context* pContext, const mal_device_config ((WAVEHDR*)pDevice->winmm.pWAVEHDRCapture)[iPeriod].dwUser = 0; } } - if (pConfig->deviceType == mal_device_type_playback || pConfig->deviceType == mal_device_type_duplex) { - if (pConfig->deviceType == mal_device_type_playback) { + if (pConfig->deviceType == ma_device_type_playback || pConfig->deviceType == ma_device_type_duplex) { + if (pConfig->deviceType == ma_device_type_playback) { pDevice->winmm.pWAVEHDRPlayback = pDevice->winmm._pHeapData; pDevice->winmm.pIntermediaryBufferPlayback = pDevice->winmm._pHeapData + (sizeof(WAVEHDR)*pDevice->playback.internalPeriods); } else { pDevice->winmm.pWAVEHDRPlayback = pDevice->winmm._pHeapData + (sizeof(WAVEHDR)*(pDevice->capture.internalPeriods)); - pDevice->winmm.pIntermediaryBufferPlayback = pDevice->winmm._pHeapData + (sizeof(WAVEHDR)*(pDevice->capture.internalPeriods + pDevice->playback.internalPeriods)) + (pDevice->playback.internalBufferSizeInFrames*mal_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels)); + pDevice->winmm.pIntermediaryBufferPlayback = pDevice->winmm._pHeapData + (sizeof(WAVEHDR)*(pDevice->capture.internalPeriods + pDevice->playback.internalPeriods)) + (pDevice->playback.internalBufferSizeInFrames*ma_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels)); } /* Prepare headers. */ - for (mal_uint32 iPeriod = 0; iPeriod < pDevice->playback.internalPeriods; ++iPeriod) { - mal_uint32 fragmentSizeInBytes = mal_get_fragment_size_in_bytes(pDevice->playback.internalBufferSizeInFrames, pDevice->playback.internalPeriods, pDevice->playback.internalFormat, pDevice->playback.internalChannels); + for (ma_uint32 iPeriod = 0; iPeriod < pDevice->playback.internalPeriods; ++iPeriod) { + ma_uint32 fragmentSizeInBytes = ma_get_fragment_size_in_bytes(pDevice->playback.internalBufferSizeInFrames, pDevice->playback.internalPeriods, pDevice->playback.internalFormat, pDevice->playback.internalChannels); ((WAVEHDR*)pDevice->winmm.pWAVEHDRPlayback)[iPeriod].lpData = (LPSTR)(pDevice->winmm.pIntermediaryBufferPlayback + (fragmentSizeInBytes*iPeriod)); ((WAVEHDR*)pDevice->winmm.pWAVEHDRPlayback)[iPeriod].dwBufferLength = fragmentSizeInBytes; @@ -10689,9 +10689,9 @@ mal_result mal_device_init__winmm(mal_context* pContext, const mal_device_config return MA_SUCCESS; on_error: - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { if (pDevice->winmm.pWAVEHDRCapture != NULL) { - for (mal_uint32 iPeriod = 0; iPeriod < pDevice->capture.internalPeriods; ++iPeriod) { + for (ma_uint32 iPeriod = 0; iPeriod < pDevice->capture.internalPeriods; ++iPeriod) { ((MA_PFN_waveInUnprepareHeader)pContext->winmm.waveInUnprepareHeader)((HWAVEIN)pDevice->winmm.hDeviceCapture, &((WAVEHDR*)pDevice->winmm.pWAVEHDRCapture)[iPeriod], sizeof(WAVEHDR)); } } @@ -10699,9 +10699,9 @@ on_error: ((MA_PFN_waveInClose)pContext->winmm.waveInClose)((HWAVEIN)pDevice->winmm.hDeviceCapture); } - if (pDevice->type == mal_device_type_playback || pDevice->type == mal_device_type_duplex) { + if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) { if (pDevice->winmm.pWAVEHDRCapture != NULL) { - for (mal_uint32 iPeriod = 0; iPeriod < pDevice->playback.internalPeriods; ++iPeriod) { + for (ma_uint32 iPeriod = 0; iPeriod < pDevice->playback.internalPeriods; ++iPeriod) { ((MA_PFN_waveOutUnprepareHeader)pContext->winmm.waveOutUnprepareHeader)((HWAVEOUT)pDevice->winmm.hDevicePlayback, &((WAVEHDR*)pDevice->winmm.pWAVEHDRPlayback)[iPeriod], sizeof(WAVEHDR)); } } @@ -10709,49 +10709,49 @@ on_error: ((MA_PFN_waveOutClose)pContext->winmm.waveOutClose)((HWAVEOUT)pDevice->winmm.hDevicePlayback); } - mal_free(pDevice->winmm._pHeapData); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, errorMsg, errorCode); + ma_free(pDevice->winmm._pHeapData); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, errorMsg, errorCode); } -mal_result mal_device_stop__winmm(mal_device* pDevice) +ma_result ma_device_stop__winmm(ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { if (pDevice->winmm.hDeviceCapture == NULL) { return MA_INVALID_ARGS; } MMRESULT resultMM = ((MA_PFN_waveInReset)pDevice->pContext->winmm.waveInReset)((HWAVEIN)pDevice->winmm.hDeviceCapture); if (resultMM != MMSYSERR_NOERROR) { - mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WinMM] WARNING: Failed to reset capture device.", mal_result_from_MMRESULT(resultMM)); + ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WinMM] WARNING: Failed to reset capture device.", ma_result_from_MMRESULT(resultMM)); } } - if (pDevice->type == mal_device_type_playback || pDevice->type == mal_device_type_duplex) { + if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) { if (pDevice->winmm.hDevicePlayback == NULL) { return MA_INVALID_ARGS; } MMRESULT resultMM = ((MA_PFN_waveOutReset)pDevice->pContext->winmm.waveOutReset)((HWAVEOUT)pDevice->winmm.hDevicePlayback); if (resultMM != MMSYSERR_NOERROR) { - mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WinMM] WARNING: Failed to reset playback device.", mal_result_from_MMRESULT(resultMM)); + ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WinMM] WARNING: Failed to reset playback device.", ma_result_from_MMRESULT(resultMM)); } } - mal_atomic_exchange_32(&pDevice->winmm.isStarted, MA_FALSE); + ma_atomic_exchange_32(&pDevice->winmm.isStarted, MA_FALSE); return MA_SUCCESS; } -mal_result mal_device_write__winmm(mal_device* pDevice, const void* pPCMFrames, mal_uint32 frameCount) +ma_result ma_device_write__winmm(ma_device* pDevice, const void* pPCMFrames, ma_uint32 frameCount) { - mal_result result = MA_SUCCESS; + ma_result result = MA_SUCCESS; MMRESULT resultMM; - mal_uint32 totalFramesWritten; + ma_uint32 totalFramesWritten; WAVEHDR* pWAVEHDR = (WAVEHDR*)pDevice->winmm.pWAVEHDRPlayback; - mal_assert(pDevice != NULL); - mal_assert(pPCMFrames != NULL); + ma_assert(pDevice != NULL); + ma_assert(pPCMFrames != NULL); /* Keep processing as much data as possible. */ totalFramesWritten = 0; @@ -10762,13 +10762,13 @@ mal_result mal_device_write__winmm(mal_device* pDevice, const void* pPCMFrames, This header has room in it. We copy as much of it as we can. If we end up fully consuming the buffer we need to write it out and move on to the next iteration. */ - mal_uint32 bpf = mal_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels); - mal_uint32 framesRemainingInHeader = (pWAVEHDR[pDevice->winmm.iNextHeaderPlayback].dwBufferLength/bpf) - pDevice->winmm.headerFramesConsumedPlayback; + ma_uint32 bpf = ma_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels); + ma_uint32 framesRemainingInHeader = (pWAVEHDR[pDevice->winmm.iNextHeaderPlayback].dwBufferLength/bpf) - pDevice->winmm.headerFramesConsumedPlayback; - mal_uint32 framesToCopy = mal_min(framesRemainingInHeader, (frameCount - totalFramesWritten)); - const void* pSrc = mal_offset_ptr(pPCMFrames, totalFramesWritten*bpf); - void* pDst = mal_offset_ptr(pWAVEHDR[pDevice->winmm.iNextHeaderPlayback].lpData, pDevice->winmm.headerFramesConsumedPlayback*bpf); - mal_copy_memory(pDst, pSrc, framesToCopy*bpf); + ma_uint32 framesToCopy = ma_min(framesRemainingInHeader, (frameCount - totalFramesWritten)); + const void* pSrc = ma_offset_ptr(pPCMFrames, totalFramesWritten*bpf); + void* pDst = ma_offset_ptr(pWAVEHDR[pDevice->winmm.iNextHeaderPlayback].lpData, pDevice->winmm.headerFramesConsumedPlayback*bpf); + ma_copy_memory(pDst, pSrc, framesToCopy*bpf); pDevice->winmm.headerFramesConsumedPlayback += framesToCopy; totalFramesWritten += framesToCopy; @@ -10784,11 +10784,11 @@ mal_result mal_device_write__winmm(mal_device* pDevice, const void* pPCMFrames, /* The device will be started here. */ resultMM = ((MA_PFN_waveOutWrite)pDevice->pContext->winmm.waveOutWrite)((HWAVEOUT)pDevice->winmm.hDevicePlayback, &pWAVEHDR[pDevice->winmm.iNextHeaderPlayback], sizeof(WAVEHDR)); if (resultMM != MMSYSERR_NOERROR) { - result = mal_result_from_MMRESULT(resultMM); - mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WinMM] waveOutWrite() failed.", result); + result = ma_result_from_MMRESULT(resultMM); + ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WinMM] waveOutWrite() failed.", result); break; } - mal_atomic_exchange_32(&pDevice->winmm.isStarted, MA_TRUE); + ma_atomic_exchange_32(&pDevice->winmm.isStarted, MA_TRUE); /* Make sure we move to the next header. */ pDevice->winmm.iNextHeaderPlayback = (pDevice->winmm.iNextHeaderPlayback + 1) % pDevice->playback.internalPeriods; @@ -10796,7 +10796,7 @@ mal_result mal_device_write__winmm(mal_device* pDevice, const void* pPCMFrames, } /* If at this point we have consumed the entire input buffer we can return. */ - mal_assert(totalFramesWritten <= frameCount); + ma_assert(totalFramesWritten <= frameCount); if (totalFramesWritten == frameCount) { break; } @@ -10826,14 +10826,14 @@ mal_result mal_device_write__winmm(mal_device* pDevice, const void* pPCMFrames, return result; } -mal_result mal_device_read__winmm(mal_device* pDevice, void* pPCMFrames, mal_uint32 frameCount) +ma_result ma_device_read__winmm(ma_device* pDevice, void* pPCMFrames, ma_uint32 frameCount) { - mal_assert(pDevice != NULL); - mal_assert(pPCMFrames != NULL); + ma_assert(pDevice != NULL); + ma_assert(pPCMFrames != NULL); - mal_result result = MA_SUCCESS; + ma_result result = MA_SUCCESS; MMRESULT resultMM; - mal_uint32 totalFramesRead; + ma_uint32 totalFramesRead; WAVEHDR* pWAVEHDR = (WAVEHDR*)pDevice->winmm.pWAVEHDRCapture; /* We want to start the device immediately. */ @@ -10842,10 +10842,10 @@ mal_result mal_device_read__winmm(mal_device* pDevice, void* pPCMFrames, mal_uin ResetEvent((HANDLE)pDevice->winmm.hEventCapture); /* To start the device we attach all of the buffers and then start it. As the buffers are filled with data we will get notifications. */ - for (mal_uint32 iPeriod = 0; iPeriod < pDevice->capture.internalPeriods; ++iPeriod) { + for (ma_uint32 iPeriod = 0; iPeriod < pDevice->capture.internalPeriods; ++iPeriod) { resultMM = ((MA_PFN_waveInAddBuffer)pDevice->pContext->winmm.waveInAddBuffer)((HWAVEIN)pDevice->winmm.hDeviceCapture, &((LPWAVEHDR)pDevice->winmm.pWAVEHDRCapture)[iPeriod], sizeof(WAVEHDR)); if (resultMM != MMSYSERR_NOERROR) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WinMM] Failed to attach input buffers to capture device in preparation for capture.", mal_result_from_MMRESULT(resultMM)); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WinMM] Failed to attach input buffers to capture device in preparation for capture.", ma_result_from_MMRESULT(resultMM)); } /* Make sure all of the buffers start out locked. We don't want to access them until the backend tells us we can. */ @@ -10855,10 +10855,10 @@ mal_result mal_device_read__winmm(mal_device* pDevice, void* pPCMFrames, mal_uin /* Capture devices need to be explicitly started, unlike playback devices. */ resultMM = ((MA_PFN_waveInStart)pDevice->pContext->winmm.waveInStart)((HWAVEIN)pDevice->winmm.hDeviceCapture); if (resultMM != MMSYSERR_NOERROR) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WinMM] Failed to start backend device.", mal_result_from_MMRESULT(resultMM)); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WinMM] Failed to start backend device.", ma_result_from_MMRESULT(resultMM)); } - mal_atomic_exchange_32(&pDevice->winmm.isStarted, MA_TRUE); + ma_atomic_exchange_32(&pDevice->winmm.isStarted, MA_TRUE); } /* Keep processing as much data as possible. */ @@ -10867,13 +10867,13 @@ mal_result mal_device_read__winmm(mal_device* pDevice, void* pPCMFrames, mal_uin /* If the current header has some space available we need to write part of it. */ if (pWAVEHDR[pDevice->winmm.iNextHeaderCapture].dwUser == 0) { /* 0 = unlocked. */ /* The buffer is available for reading. If we fully consume it we need to add it back to the buffer. */ - mal_uint32 bpf = mal_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels); - mal_uint32 framesRemainingInHeader = (pWAVEHDR[pDevice->winmm.iNextHeaderCapture].dwBufferLength/bpf) - pDevice->winmm.headerFramesConsumedCapture; + ma_uint32 bpf = ma_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels); + ma_uint32 framesRemainingInHeader = (pWAVEHDR[pDevice->winmm.iNextHeaderCapture].dwBufferLength/bpf) - pDevice->winmm.headerFramesConsumedCapture; - mal_uint32 framesToCopy = mal_min(framesRemainingInHeader, (frameCount - totalFramesRead)); - const void* pSrc = mal_offset_ptr(pWAVEHDR[pDevice->winmm.iNextHeaderCapture].lpData, pDevice->winmm.headerFramesConsumedCapture*bpf); - void* pDst = mal_offset_ptr(pPCMFrames, totalFramesRead*bpf); - mal_copy_memory(pDst, pSrc, framesToCopy*bpf); + ma_uint32 framesToCopy = ma_min(framesRemainingInHeader, (frameCount - totalFramesRead)); + const void* pSrc = ma_offset_ptr(pWAVEHDR[pDevice->winmm.iNextHeaderCapture].lpData, pDevice->winmm.headerFramesConsumedCapture*bpf); + void* pDst = ma_offset_ptr(pPCMFrames, totalFramesRead*bpf); + ma_copy_memory(pDst, pSrc, framesToCopy*bpf); pDevice->winmm.headerFramesConsumedCapture += framesToCopy; totalFramesRead += framesToCopy; @@ -10889,8 +10889,8 @@ mal_result mal_device_read__winmm(mal_device* pDevice, void* pPCMFrames, mal_uin /* The device will be started here. */ resultMM = ((MA_PFN_waveInAddBuffer)pDevice->pContext->winmm.waveInAddBuffer)((HWAVEIN)pDevice->winmm.hDeviceCapture, &((LPWAVEHDR)pDevice->winmm.pWAVEHDRCapture)[pDevice->winmm.iNextHeaderCapture], sizeof(WAVEHDR)); if (resultMM != MMSYSERR_NOERROR) { - result = mal_result_from_MMRESULT(resultMM); - mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WinMM] waveInAddBuffer() failed.", result); + result = ma_result_from_MMRESULT(resultMM); + ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WinMM] waveInAddBuffer() failed.", result); break; } @@ -10900,7 +10900,7 @@ mal_result mal_device_read__winmm(mal_device* pDevice, void* pPCMFrames, mal_uin } /* If at this point we have filled the entire input buffer we can return. */ - mal_assert(totalFramesRead <= frameCount); + ma_assert(totalFramesRead <= frameCount); if (totalFramesRead == frameCount) { break; } @@ -10930,52 +10930,52 @@ mal_result mal_device_read__winmm(mal_device* pDevice, void* pPCMFrames, mal_uin return result; } -mal_result mal_context_uninit__winmm(mal_context* pContext) +ma_result ma_context_uninit__winmm(ma_context* pContext) { - mal_assert(pContext != NULL); - mal_assert(pContext->backend == mal_backend_winmm); + ma_assert(pContext != NULL); + ma_assert(pContext->backend == ma_backend_winmm); - mal_dlclose(pContext->winmm.hWinMM); + ma_dlclose(pContext->winmm.hWinMM); return MA_SUCCESS; } -mal_result mal_context_init__winmm(mal_context* pContext) +ma_result ma_context_init__winmm(ma_context* pContext) { - mal_assert(pContext != NULL); + ma_assert(pContext != NULL); - pContext->winmm.hWinMM = mal_dlopen("winmm.dll"); + pContext->winmm.hWinMM = ma_dlopen("winmm.dll"); if (pContext->winmm.hWinMM == NULL) { return MA_NO_BACKEND; } - pContext->winmm.waveOutGetNumDevs = mal_dlsym(pContext->winmm.hWinMM, "waveOutGetNumDevs"); - pContext->winmm.waveOutGetDevCapsA = mal_dlsym(pContext->winmm.hWinMM, "waveOutGetDevCapsA"); - pContext->winmm.waveOutOpen = mal_dlsym(pContext->winmm.hWinMM, "waveOutOpen"); - pContext->winmm.waveOutClose = mal_dlsym(pContext->winmm.hWinMM, "waveOutClose"); - pContext->winmm.waveOutPrepareHeader = mal_dlsym(pContext->winmm.hWinMM, "waveOutPrepareHeader"); - pContext->winmm.waveOutUnprepareHeader = mal_dlsym(pContext->winmm.hWinMM, "waveOutUnprepareHeader"); - pContext->winmm.waveOutWrite = mal_dlsym(pContext->winmm.hWinMM, "waveOutWrite"); - pContext->winmm.waveOutReset = mal_dlsym(pContext->winmm.hWinMM, "waveOutReset"); - pContext->winmm.waveInGetNumDevs = mal_dlsym(pContext->winmm.hWinMM, "waveInGetNumDevs"); - pContext->winmm.waveInGetDevCapsA = mal_dlsym(pContext->winmm.hWinMM, "waveInGetDevCapsA"); - pContext->winmm.waveInOpen = mal_dlsym(pContext->winmm.hWinMM, "waveInOpen"); - pContext->winmm.waveInClose = mal_dlsym(pContext->winmm.hWinMM, "waveInClose"); - pContext->winmm.waveInPrepareHeader = mal_dlsym(pContext->winmm.hWinMM, "waveInPrepareHeader"); - pContext->winmm.waveInUnprepareHeader = mal_dlsym(pContext->winmm.hWinMM, "waveInUnprepareHeader"); - pContext->winmm.waveInAddBuffer = mal_dlsym(pContext->winmm.hWinMM, "waveInAddBuffer"); - pContext->winmm.waveInStart = mal_dlsym(pContext->winmm.hWinMM, "waveInStart"); - pContext->winmm.waveInReset = mal_dlsym(pContext->winmm.hWinMM, "waveInReset"); + pContext->winmm.waveOutGetNumDevs = ma_dlsym(pContext->winmm.hWinMM, "waveOutGetNumDevs"); + pContext->winmm.waveOutGetDevCapsA = ma_dlsym(pContext->winmm.hWinMM, "waveOutGetDevCapsA"); + pContext->winmm.waveOutOpen = ma_dlsym(pContext->winmm.hWinMM, "waveOutOpen"); + pContext->winmm.waveOutClose = ma_dlsym(pContext->winmm.hWinMM, "waveOutClose"); + pContext->winmm.waveOutPrepareHeader = ma_dlsym(pContext->winmm.hWinMM, "waveOutPrepareHeader"); + pContext->winmm.waveOutUnprepareHeader = ma_dlsym(pContext->winmm.hWinMM, "waveOutUnprepareHeader"); + pContext->winmm.waveOutWrite = ma_dlsym(pContext->winmm.hWinMM, "waveOutWrite"); + pContext->winmm.waveOutReset = ma_dlsym(pContext->winmm.hWinMM, "waveOutReset"); + pContext->winmm.waveInGetNumDevs = ma_dlsym(pContext->winmm.hWinMM, "waveInGetNumDevs"); + pContext->winmm.waveInGetDevCapsA = ma_dlsym(pContext->winmm.hWinMM, "waveInGetDevCapsA"); + pContext->winmm.waveInOpen = ma_dlsym(pContext->winmm.hWinMM, "waveInOpen"); + pContext->winmm.waveInClose = ma_dlsym(pContext->winmm.hWinMM, "waveInClose"); + pContext->winmm.waveInPrepareHeader = ma_dlsym(pContext->winmm.hWinMM, "waveInPrepareHeader"); + pContext->winmm.waveInUnprepareHeader = ma_dlsym(pContext->winmm.hWinMM, "waveInUnprepareHeader"); + pContext->winmm.waveInAddBuffer = ma_dlsym(pContext->winmm.hWinMM, "waveInAddBuffer"); + pContext->winmm.waveInStart = ma_dlsym(pContext->winmm.hWinMM, "waveInStart"); + pContext->winmm.waveInReset = ma_dlsym(pContext->winmm.hWinMM, "waveInReset"); - pContext->onUninit = mal_context_uninit__winmm; - pContext->onDeviceIDEqual = mal_context_is_device_id_equal__winmm; - pContext->onEnumDevices = mal_context_enumerate_devices__winmm; - pContext->onGetDeviceInfo = mal_context_get_device_info__winmm; - pContext->onDeviceInit = mal_device_init__winmm; - pContext->onDeviceUninit = mal_device_uninit__winmm; + pContext->onUninit = ma_context_uninit__winmm; + pContext->onDeviceIDEqual = ma_context_is_device_id_equal__winmm; + pContext->onEnumDevices = ma_context_enumerate_devices__winmm; + pContext->onGetDeviceInfo = ma_context_get_device_info__winmm; + pContext->onDeviceInit = ma_device_init__winmm; + pContext->onDeviceUninit = ma_device_uninit__winmm; pContext->onDeviceStart = NULL; /* Not used. Started in onDeviceWrite/onDeviceRead. */ - pContext->onDeviceStop = mal_device_stop__winmm; - pContext->onDeviceWrite = mal_device_write__winmm; - pContext->onDeviceRead = mal_device_read__winmm; + pContext->onDeviceStop = ma_device_stop__winmm; + pContext->onDeviceWrite = ma_device_write__winmm; + pContext->onDeviceRead = ma_device_read__winmm; return MA_SUCCESS; } @@ -10993,18 +10993,18 @@ mal_result mal_context_init__winmm(mal_context* pContext) #ifdef MA_NO_RUNTIME_LINKING #include -typedef snd_pcm_uframes_t mal_snd_pcm_uframes_t; -typedef snd_pcm_sframes_t mal_snd_pcm_sframes_t; -typedef snd_pcm_stream_t mal_snd_pcm_stream_t; -typedef snd_pcm_format_t mal_snd_pcm_format_t; -typedef snd_pcm_access_t mal_snd_pcm_access_t; -typedef snd_pcm_t mal_snd_pcm_t; -typedef snd_pcm_hw_params_t mal_snd_pcm_hw_params_t; -typedef snd_pcm_sw_params_t mal_snd_pcm_sw_params_t; -typedef snd_pcm_format_mask_t mal_snd_pcm_format_mask_t; -typedef snd_pcm_info_t mal_snd_pcm_info_t; -typedef snd_pcm_channel_area_t mal_snd_pcm_channel_area_t; -typedef snd_pcm_chmap_t mal_snd_pcm_chmap_t; +typedef snd_pcm_uframes_t ma_snd_pcm_uframes_t; +typedef snd_pcm_sframes_t ma_snd_pcm_sframes_t; +typedef snd_pcm_stream_t ma_snd_pcm_stream_t; +typedef snd_pcm_format_t ma_snd_pcm_format_t; +typedef snd_pcm_access_t ma_snd_pcm_access_t; +typedef snd_pcm_t ma_snd_pcm_t; +typedef snd_pcm_hw_params_t ma_snd_pcm_hw_params_t; +typedef snd_pcm_sw_params_t ma_snd_pcm_sw_params_t; +typedef snd_pcm_format_mask_t ma_snd_pcm_format_mask_t; +typedef snd_pcm_info_t ma_snd_pcm_info_t; +typedef snd_pcm_channel_area_t ma_snd_pcm_channel_area_t; +typedef snd_pcm_chmap_t ma_snd_pcm_chmap_t; // snd_pcm_stream_t #define MA_SND_PCM_STREAM_PLAYBACK SND_PCM_STREAM_PLAYBACK @@ -11028,7 +11028,7 @@ typedef snd_pcm_chmap_t mal_snd_pcm_chmap_t; #define MA_SND_PCM_FORMAT_S24_3LE SND_PCM_FORMAT_S24_3LE #define MA_SND_PCM_FORMAT_S24_3BE SND_PCM_FORMAT_S24_3BE -// mal_snd_pcm_access_t +// ma_snd_pcm_access_t #define MA_SND_PCM_ACCESS_MMAP_INTERLEAVED SND_PCM_ACCESS_MMAP_INTERLEAVED #define MA_SND_PCM_ACCESS_MMAP_NONINTERLEAVED SND_PCM_ACCESS_MMAP_NONINTERLEAVED #define MA_SND_PCM_ACCESS_MMAP_COMPLEX SND_PCM_ACCESS_MMAP_COMPLEX @@ -11080,27 +11080,27 @@ typedef snd_pcm_chmap_t mal_snd_pcm_chmap_t; #define MA_SND_PCM_NO_AUTO_FORMAT SND_PCM_NO_AUTO_FORMAT #else #include // For EPIPE, etc. -typedef unsigned long mal_snd_pcm_uframes_t; -typedef long mal_snd_pcm_sframes_t; -typedef int mal_snd_pcm_stream_t; -typedef int mal_snd_pcm_format_t; -typedef int mal_snd_pcm_access_t; -typedef struct mal_snd_pcm_t mal_snd_pcm_t; -typedef struct mal_snd_pcm_hw_params_t mal_snd_pcm_hw_params_t; -typedef struct mal_snd_pcm_sw_params_t mal_snd_pcm_sw_params_t; -typedef struct mal_snd_pcm_format_mask_t mal_snd_pcm_format_mask_t; -typedef struct mal_snd_pcm_info_t mal_snd_pcm_info_t; +typedef unsigned long ma_snd_pcm_uframes_t; +typedef long ma_snd_pcm_sframes_t; +typedef int ma_snd_pcm_stream_t; +typedef int ma_snd_pcm_format_t; +typedef int ma_snd_pcm_access_t; +typedef struct ma_snd_pcm_t ma_snd_pcm_t; +typedef struct ma_snd_pcm_hw_params_t ma_snd_pcm_hw_params_t; +typedef struct ma_snd_pcm_sw_params_t ma_snd_pcm_sw_params_t; +typedef struct ma_snd_pcm_format_mask_t ma_snd_pcm_format_mask_t; +typedef struct ma_snd_pcm_info_t ma_snd_pcm_info_t; typedef struct { void* addr; unsigned int first; unsigned int step; -} mal_snd_pcm_channel_area_t; +} ma_snd_pcm_channel_area_t; typedef struct { unsigned int channels; unsigned int pos[0]; -} mal_snd_pcm_chmap_t; +} ma_snd_pcm_chmap_t; // snd_pcm_state_t #define MA_SND_PCM_STATE_OPEN 0 @@ -11187,61 +11187,61 @@ typedef struct #define MA_SND_PCM_NO_AUTO_FORMAT 0x00040000 #endif -typedef int (* mal_snd_pcm_open_proc) (mal_snd_pcm_t **pcm, const char *name, mal_snd_pcm_stream_t stream, int mode); -typedef int (* mal_snd_pcm_close_proc) (mal_snd_pcm_t *pcm); -typedef size_t (* mal_snd_pcm_hw_params_sizeof_proc) (void); -typedef int (* mal_snd_pcm_hw_params_any_proc) (mal_snd_pcm_t *pcm, mal_snd_pcm_hw_params_t *params); -typedef int (* mal_snd_pcm_hw_params_set_format_proc) (mal_snd_pcm_t *pcm, mal_snd_pcm_hw_params_t *params, mal_snd_pcm_format_t val); -typedef int (* mal_snd_pcm_hw_params_set_format_first_proc) (mal_snd_pcm_t *pcm, mal_snd_pcm_hw_params_t *params, mal_snd_pcm_format_t *format); -typedef void (* mal_snd_pcm_hw_params_get_format_mask_proc) (mal_snd_pcm_hw_params_t *params, mal_snd_pcm_format_mask_t *mask); -typedef int (* mal_snd_pcm_hw_params_set_channels_near_proc) (mal_snd_pcm_t *pcm, mal_snd_pcm_hw_params_t *params, unsigned int *val); -typedef int (* mal_snd_pcm_hw_params_set_rate_resample_proc) (mal_snd_pcm_t *pcm, mal_snd_pcm_hw_params_t *params, unsigned int val); -typedef int (* mal_snd_pcm_hw_params_set_rate_near_proc) (mal_snd_pcm_t *pcm, mal_snd_pcm_hw_params_t *params, unsigned int *val, int *dir); -typedef int (* mal_snd_pcm_hw_params_set_buffer_size_near_proc)(mal_snd_pcm_t *pcm, mal_snd_pcm_hw_params_t *params, mal_snd_pcm_uframes_t *val); -typedef int (* mal_snd_pcm_hw_params_set_periods_near_proc) (mal_snd_pcm_t *pcm, mal_snd_pcm_hw_params_t *params, unsigned int *val, int *dir); -typedef int (* mal_snd_pcm_hw_params_set_access_proc) (mal_snd_pcm_t *pcm, mal_snd_pcm_hw_params_t *params, mal_snd_pcm_access_t _access); -typedef int (* mal_snd_pcm_hw_params_get_format_proc) (const mal_snd_pcm_hw_params_t *params, mal_snd_pcm_format_t *format); -typedef int (* mal_snd_pcm_hw_params_get_channels_proc) (const mal_snd_pcm_hw_params_t *params, unsigned int *val); -typedef int (* mal_snd_pcm_hw_params_get_channels_min_proc) (const mal_snd_pcm_hw_params_t *params, unsigned int *val); -typedef int (* mal_snd_pcm_hw_params_get_channels_max_proc) (const mal_snd_pcm_hw_params_t *params, unsigned int *val); -typedef int (* mal_snd_pcm_hw_params_get_rate_proc) (const mal_snd_pcm_hw_params_t *params, unsigned int *rate, int *dir); -typedef int (* mal_snd_pcm_hw_params_get_rate_min_proc) (const mal_snd_pcm_hw_params_t *params, unsigned int *rate, int *dir); -typedef int (* mal_snd_pcm_hw_params_get_rate_max_proc) (const mal_snd_pcm_hw_params_t *params, unsigned int *rate, int *dir); -typedef int (* mal_snd_pcm_hw_params_get_buffer_size_proc) (const mal_snd_pcm_hw_params_t *params, mal_snd_pcm_uframes_t *val); -typedef int (* mal_snd_pcm_hw_params_get_periods_proc) (const mal_snd_pcm_hw_params_t *params, unsigned int *val, int *dir); -typedef int (* mal_snd_pcm_hw_params_get_access_proc) (const mal_snd_pcm_hw_params_t *params, mal_snd_pcm_access_t *_access); -typedef int (* mal_snd_pcm_hw_params_proc) (mal_snd_pcm_t *pcm, mal_snd_pcm_hw_params_t *params); -typedef size_t (* mal_snd_pcm_sw_params_sizeof_proc) (void); -typedef int (* mal_snd_pcm_sw_params_current_proc) (mal_snd_pcm_t *pcm, mal_snd_pcm_sw_params_t *params); -typedef int (* mal_snd_pcm_sw_params_get_boundary_proc) (mal_snd_pcm_sw_params_t *params, mal_snd_pcm_uframes_t* val); -typedef int (* mal_snd_pcm_sw_params_set_avail_min_proc) (mal_snd_pcm_t *pcm, mal_snd_pcm_sw_params_t *params, mal_snd_pcm_uframes_t val); -typedef int (* mal_snd_pcm_sw_params_set_start_threshold_proc) (mal_snd_pcm_t *pcm, mal_snd_pcm_sw_params_t *params, mal_snd_pcm_uframes_t val); -typedef int (* mal_snd_pcm_sw_params_set_stop_threshold_proc) (mal_snd_pcm_t *pcm, mal_snd_pcm_sw_params_t *params, mal_snd_pcm_uframes_t val); -typedef int (* mal_snd_pcm_sw_params_proc) (mal_snd_pcm_t *pcm, mal_snd_pcm_sw_params_t *params); -typedef size_t (* mal_snd_pcm_format_mask_sizeof_proc) (void); -typedef int (* mal_snd_pcm_format_mask_test_proc) (const mal_snd_pcm_format_mask_t *mask, mal_snd_pcm_format_t val); -typedef mal_snd_pcm_chmap_t * (* mal_snd_pcm_get_chmap_proc) (mal_snd_pcm_t *pcm); -typedef int (* mal_snd_pcm_state_proc) (mal_snd_pcm_t *pcm); -typedef int (* mal_snd_pcm_prepare_proc) (mal_snd_pcm_t *pcm); -typedef int (* mal_snd_pcm_start_proc) (mal_snd_pcm_t *pcm); -typedef int (* mal_snd_pcm_drop_proc) (mal_snd_pcm_t *pcm); -typedef int (* mal_snd_pcm_drain_proc) (mal_snd_pcm_t *pcm); -typedef int (* mal_snd_device_name_hint_proc) (int card, const char *iface, void ***hints); -typedef char * (* mal_snd_device_name_get_hint_proc) (const void *hint, const char *id); -typedef int (* mal_snd_card_get_index_proc) (const char *name); -typedef int (* mal_snd_device_name_free_hint_proc) (void **hints); -typedef int (* mal_snd_pcm_mmap_begin_proc) (mal_snd_pcm_t *pcm, const mal_snd_pcm_channel_area_t **areas, mal_snd_pcm_uframes_t *offset, mal_snd_pcm_uframes_t *frames); -typedef mal_snd_pcm_sframes_t (* mal_snd_pcm_mmap_commit_proc) (mal_snd_pcm_t *pcm, mal_snd_pcm_uframes_t offset, mal_snd_pcm_uframes_t frames); -typedef int (* mal_snd_pcm_recover_proc) (mal_snd_pcm_t *pcm, int err, int silent); -typedef mal_snd_pcm_sframes_t (* mal_snd_pcm_readi_proc) (mal_snd_pcm_t *pcm, void *buffer, mal_snd_pcm_uframes_t size); -typedef mal_snd_pcm_sframes_t (* mal_snd_pcm_writei_proc) (mal_snd_pcm_t *pcm, const void *buffer, mal_snd_pcm_uframes_t size); -typedef mal_snd_pcm_sframes_t (* mal_snd_pcm_avail_proc) (mal_snd_pcm_t *pcm); -typedef mal_snd_pcm_sframes_t (* mal_snd_pcm_avail_update_proc) (mal_snd_pcm_t *pcm); -typedef int (* mal_snd_pcm_wait_proc) (mal_snd_pcm_t *pcm, int timeout); -typedef int (* mal_snd_pcm_info_proc) (mal_snd_pcm_t *pcm, mal_snd_pcm_info_t* info); -typedef size_t (* mal_snd_pcm_info_sizeof_proc) (); -typedef const char* (* mal_snd_pcm_info_get_name_proc) (const mal_snd_pcm_info_t* info); -typedef int (* mal_snd_config_update_free_global_proc) (); +typedef int (* ma_snd_pcm_open_proc) (ma_snd_pcm_t **pcm, const char *name, ma_snd_pcm_stream_t stream, int mode); +typedef int (* ma_snd_pcm_close_proc) (ma_snd_pcm_t *pcm); +typedef size_t (* ma_snd_pcm_hw_params_sizeof_proc) (void); +typedef int (* ma_snd_pcm_hw_params_any_proc) (ma_snd_pcm_t *pcm, ma_snd_pcm_hw_params_t *params); +typedef int (* ma_snd_pcm_hw_params_set_format_proc) (ma_snd_pcm_t *pcm, ma_snd_pcm_hw_params_t *params, ma_snd_pcm_format_t val); +typedef int (* ma_snd_pcm_hw_params_set_format_first_proc) (ma_snd_pcm_t *pcm, ma_snd_pcm_hw_params_t *params, ma_snd_pcm_format_t *format); +typedef void (* ma_snd_pcm_hw_params_get_format_mask_proc) (ma_snd_pcm_hw_params_t *params, ma_snd_pcm_format_mask_t *mask); +typedef int (* ma_snd_pcm_hw_params_set_channels_near_proc) (ma_snd_pcm_t *pcm, ma_snd_pcm_hw_params_t *params, unsigned int *val); +typedef int (* ma_snd_pcm_hw_params_set_rate_resample_proc) (ma_snd_pcm_t *pcm, ma_snd_pcm_hw_params_t *params, unsigned int val); +typedef int (* ma_snd_pcm_hw_params_set_rate_near_proc) (ma_snd_pcm_t *pcm, ma_snd_pcm_hw_params_t *params, unsigned int *val, int *dir); +typedef int (* ma_snd_pcm_hw_params_set_buffer_size_near_proc)(ma_snd_pcm_t *pcm, ma_snd_pcm_hw_params_t *params, ma_snd_pcm_uframes_t *val); +typedef int (* ma_snd_pcm_hw_params_set_periods_near_proc) (ma_snd_pcm_t *pcm, ma_snd_pcm_hw_params_t *params, unsigned int *val, int *dir); +typedef int (* ma_snd_pcm_hw_params_set_access_proc) (ma_snd_pcm_t *pcm, ma_snd_pcm_hw_params_t *params, ma_snd_pcm_access_t _access); +typedef int (* ma_snd_pcm_hw_params_get_format_proc) (const ma_snd_pcm_hw_params_t *params, ma_snd_pcm_format_t *format); +typedef int (* ma_snd_pcm_hw_params_get_channels_proc) (const ma_snd_pcm_hw_params_t *params, unsigned int *val); +typedef int (* ma_snd_pcm_hw_params_get_channels_min_proc) (const ma_snd_pcm_hw_params_t *params, unsigned int *val); +typedef int (* ma_snd_pcm_hw_params_get_channels_max_proc) (const ma_snd_pcm_hw_params_t *params, unsigned int *val); +typedef int (* ma_snd_pcm_hw_params_get_rate_proc) (const ma_snd_pcm_hw_params_t *params, unsigned int *rate, int *dir); +typedef int (* ma_snd_pcm_hw_params_get_rate_min_proc) (const ma_snd_pcm_hw_params_t *params, unsigned int *rate, int *dir); +typedef int (* ma_snd_pcm_hw_params_get_rate_max_proc) (const ma_snd_pcm_hw_params_t *params, unsigned int *rate, int *dir); +typedef int (* ma_snd_pcm_hw_params_get_buffer_size_proc) (const ma_snd_pcm_hw_params_t *params, ma_snd_pcm_uframes_t *val); +typedef int (* ma_snd_pcm_hw_params_get_periods_proc) (const ma_snd_pcm_hw_params_t *params, unsigned int *val, int *dir); +typedef int (* ma_snd_pcm_hw_params_get_access_proc) (const ma_snd_pcm_hw_params_t *params, ma_snd_pcm_access_t *_access); +typedef int (* ma_snd_pcm_hw_params_proc) (ma_snd_pcm_t *pcm, ma_snd_pcm_hw_params_t *params); +typedef size_t (* ma_snd_pcm_sw_params_sizeof_proc) (void); +typedef int (* ma_snd_pcm_sw_params_current_proc) (ma_snd_pcm_t *pcm, ma_snd_pcm_sw_params_t *params); +typedef int (* ma_snd_pcm_sw_params_get_boundary_proc) (ma_snd_pcm_sw_params_t *params, ma_snd_pcm_uframes_t* val); +typedef int (* ma_snd_pcm_sw_params_set_avail_min_proc) (ma_snd_pcm_t *pcm, ma_snd_pcm_sw_params_t *params, ma_snd_pcm_uframes_t val); +typedef int (* ma_snd_pcm_sw_params_set_start_threshold_proc) (ma_snd_pcm_t *pcm, ma_snd_pcm_sw_params_t *params, ma_snd_pcm_uframes_t val); +typedef int (* ma_snd_pcm_sw_params_set_stop_threshold_proc) (ma_snd_pcm_t *pcm, ma_snd_pcm_sw_params_t *params, ma_snd_pcm_uframes_t val); +typedef int (* ma_snd_pcm_sw_params_proc) (ma_snd_pcm_t *pcm, ma_snd_pcm_sw_params_t *params); +typedef size_t (* ma_snd_pcm_format_mask_sizeof_proc) (void); +typedef int (* ma_snd_pcm_format_mask_test_proc) (const ma_snd_pcm_format_mask_t *mask, ma_snd_pcm_format_t val); +typedef ma_snd_pcm_chmap_t * (* ma_snd_pcm_get_chmap_proc) (ma_snd_pcm_t *pcm); +typedef int (* ma_snd_pcm_state_proc) (ma_snd_pcm_t *pcm); +typedef int (* ma_snd_pcm_prepare_proc) (ma_snd_pcm_t *pcm); +typedef int (* ma_snd_pcm_start_proc) (ma_snd_pcm_t *pcm); +typedef int (* ma_snd_pcm_drop_proc) (ma_snd_pcm_t *pcm); +typedef int (* ma_snd_pcm_drain_proc) (ma_snd_pcm_t *pcm); +typedef int (* ma_snd_device_name_hint_proc) (int card, const char *iface, void ***hints); +typedef char * (* ma_snd_device_name_get_hint_proc) (const void *hint, const char *id); +typedef int (* ma_snd_card_get_index_proc) (const char *name); +typedef int (* ma_snd_device_name_free_hint_proc) (void **hints); +typedef int (* ma_snd_pcm_mmap_begin_proc) (ma_snd_pcm_t *pcm, const ma_snd_pcm_channel_area_t **areas, ma_snd_pcm_uframes_t *offset, ma_snd_pcm_uframes_t *frames); +typedef ma_snd_pcm_sframes_t (* ma_snd_pcm_mmap_commit_proc) (ma_snd_pcm_t *pcm, ma_snd_pcm_uframes_t offset, ma_snd_pcm_uframes_t frames); +typedef int (* ma_snd_pcm_recover_proc) (ma_snd_pcm_t *pcm, int err, int silent); +typedef ma_snd_pcm_sframes_t (* ma_snd_pcm_readi_proc) (ma_snd_pcm_t *pcm, void *buffer, ma_snd_pcm_uframes_t size); +typedef ma_snd_pcm_sframes_t (* ma_snd_pcm_writei_proc) (ma_snd_pcm_t *pcm, const void *buffer, ma_snd_pcm_uframes_t size); +typedef ma_snd_pcm_sframes_t (* ma_snd_pcm_avail_proc) (ma_snd_pcm_t *pcm); +typedef ma_snd_pcm_sframes_t (* ma_snd_pcm_avail_update_proc) (ma_snd_pcm_t *pcm); +typedef int (* ma_snd_pcm_wait_proc) (ma_snd_pcm_t *pcm, int timeout); +typedef int (* ma_snd_pcm_info_proc) (ma_snd_pcm_t *pcm, ma_snd_pcm_info_t* info); +typedef size_t (* ma_snd_pcm_info_sizeof_proc) (); +typedef const char* (* ma_snd_pcm_info_get_name_proc) (const ma_snd_pcm_info_t* info); +typedef int (* ma_snd_config_update_free_global_proc) (); // This array specifies each of the common devices that can be used for both playback and capture. const char* g_malCommonDeviceNamesALSA[] = { @@ -11273,13 +11273,13 @@ static struct {"bcm2835 ALSA", 2.0f} }; -float mal_find_default_buffer_size_scale__alsa(const char* deviceName) +float ma_find_default_buffer_size_scale__alsa(const char* deviceName) { if (deviceName == NULL) { return 1; } - for (size_t i = 0; i < mal_countof(g_malDefaultBufferSizeScalesALSA); ++i) { + for (size_t i = 0; i < ma_countof(g_malDefaultBufferSizeScalesALSA); ++i) { if (strstr(g_malDefaultBufferSizeScalesALSA[i].name, deviceName) != NULL) { return g_malDefaultBufferSizeScalesALSA[i].scale; } @@ -11288,18 +11288,18 @@ float mal_find_default_buffer_size_scale__alsa(const char* deviceName) return 1; } -mal_snd_pcm_format_t mal_convert_mal_format_to_alsa_format(mal_format format) +ma_snd_pcm_format_t ma_convert_ma_format_to_alsa_format(ma_format format) { - mal_snd_pcm_format_t ALSAFormats[] = { - MA_SND_PCM_FORMAT_UNKNOWN, // mal_format_unknown - MA_SND_PCM_FORMAT_U8, // mal_format_u8 - MA_SND_PCM_FORMAT_S16_LE, // mal_format_s16 - MA_SND_PCM_FORMAT_S24_3LE, // mal_format_s24 - MA_SND_PCM_FORMAT_S32_LE, // mal_format_s32 - MA_SND_PCM_FORMAT_FLOAT_LE // mal_format_f32 + ma_snd_pcm_format_t ALSAFormats[] = { + MA_SND_PCM_FORMAT_UNKNOWN, // ma_format_unknown + MA_SND_PCM_FORMAT_U8, // ma_format_u8 + MA_SND_PCM_FORMAT_S16_LE, // ma_format_s16 + MA_SND_PCM_FORMAT_S24_3LE, // ma_format_s24 + MA_SND_PCM_FORMAT_S32_LE, // ma_format_s32 + MA_SND_PCM_FORMAT_FLOAT_LE // ma_format_f32 }; - if (mal_is_big_endian()) { + if (ma_is_big_endian()) { ALSAFormats[0] = MA_SND_PCM_FORMAT_UNKNOWN; ALSAFormats[1] = MA_SND_PCM_FORMAT_U8; ALSAFormats[2] = MA_SND_PCM_FORMAT_S16_BE; @@ -11312,34 +11312,34 @@ mal_snd_pcm_format_t mal_convert_mal_format_to_alsa_format(mal_format format) return ALSAFormats[format]; } -mal_format mal_convert_alsa_format_to_mal_format(mal_snd_pcm_format_t formatALSA) +ma_format ma_convert_alsa_format_to_ma_format(ma_snd_pcm_format_t formatALSA) { - if (mal_is_little_endian()) { + if (ma_is_little_endian()) { switch (formatALSA) { - case MA_SND_PCM_FORMAT_S16_LE: return mal_format_s16; - case MA_SND_PCM_FORMAT_S24_3LE: return mal_format_s24; - case MA_SND_PCM_FORMAT_S32_LE: return mal_format_s32; - case MA_SND_PCM_FORMAT_FLOAT_LE: return mal_format_f32; + case MA_SND_PCM_FORMAT_S16_LE: return ma_format_s16; + case MA_SND_PCM_FORMAT_S24_3LE: return ma_format_s24; + case MA_SND_PCM_FORMAT_S32_LE: return ma_format_s32; + case MA_SND_PCM_FORMAT_FLOAT_LE: return ma_format_f32; default: break; } } else { switch (formatALSA) { - case MA_SND_PCM_FORMAT_S16_BE: return mal_format_s16; - case MA_SND_PCM_FORMAT_S24_3BE: return mal_format_s24; - case MA_SND_PCM_FORMAT_S32_BE: return mal_format_s32; - case MA_SND_PCM_FORMAT_FLOAT_BE: return mal_format_f32; + case MA_SND_PCM_FORMAT_S16_BE: return ma_format_s16; + case MA_SND_PCM_FORMAT_S24_3BE: return ma_format_s24; + case MA_SND_PCM_FORMAT_S32_BE: return ma_format_s32; + case MA_SND_PCM_FORMAT_FLOAT_BE: return ma_format_f32; default: break; } } // Endian agnostic. switch (formatALSA) { - case MA_SND_PCM_FORMAT_U8: return mal_format_u8; - default: return mal_format_unknown; + case MA_SND_PCM_FORMAT_U8: return ma_format_u8; + default: return ma_format_unknown; } } -mal_channel mal_convert_alsa_channel_position_to_mal_channel(unsigned int alsaChannelPos) +ma_channel ma_convert_alsa_channel_position_to_ma_channel(unsigned int alsaChannelPos) { switch (alsaChannelPos) { @@ -11375,10 +11375,10 @@ mal_channel mal_convert_alsa_channel_position_to_mal_channel(unsigned int alsaCh return 0; } -mal_bool32 mal_is_common_device_name__alsa(const char* name) +ma_bool32 ma_is_common_device_name__alsa(const char* name) { - for (size_t iName = 0; iName < mal_countof(g_malCommonDeviceNamesALSA); ++iName) { - if (mal_strcmp(name, g_malCommonDeviceNamesALSA[iName]) == 0) { + for (size_t iName = 0; iName < ma_countof(g_malCommonDeviceNamesALSA); ++iName) { + if (ma_strcmp(name, g_malCommonDeviceNamesALSA[iName]) == 0) { return MA_TRUE; } } @@ -11387,10 +11387,10 @@ mal_bool32 mal_is_common_device_name__alsa(const char* name) } -mal_bool32 mal_is_playback_device_blacklisted__alsa(const char* name) +ma_bool32 ma_is_playback_device_blacklisted__alsa(const char* name) { - for (size_t iName = 0; iName < mal_countof(g_malBlacklistedPlaybackDeviceNamesALSA); ++iName) { - if (mal_strcmp(name, g_malBlacklistedPlaybackDeviceNamesALSA[iName]) == 0) { + for (size_t iName = 0; iName < ma_countof(g_malBlacklistedPlaybackDeviceNamesALSA); ++iName) { + if (ma_strcmp(name, g_malBlacklistedPlaybackDeviceNamesALSA[iName]) == 0) { return MA_TRUE; } } @@ -11398,10 +11398,10 @@ mal_bool32 mal_is_playback_device_blacklisted__alsa(const char* name) return MA_FALSE; } -mal_bool32 mal_is_capture_device_blacklisted__alsa(const char* name) +ma_bool32 ma_is_capture_device_blacklisted__alsa(const char* name) { - for (size_t iName = 0; iName < mal_countof(g_malBlacklistedCaptureDeviceNamesALSA); ++iName) { - if (mal_strcmp(name, g_malBlacklistedCaptureDeviceNamesALSA[iName]) == 0) { + for (size_t iName = 0; iName < ma_countof(g_malBlacklistedCaptureDeviceNamesALSA); ++iName) { + if (ma_strcmp(name, g_malBlacklistedCaptureDeviceNamesALSA[iName]) == 0) { return MA_TRUE; } } @@ -11409,17 +11409,17 @@ mal_bool32 mal_is_capture_device_blacklisted__alsa(const char* name) return MA_FALSE; } -mal_bool32 mal_is_device_blacklisted__alsa(mal_device_type deviceType, const char* name) +ma_bool32 ma_is_device_blacklisted__alsa(ma_device_type deviceType, const char* name) { - if (deviceType == mal_device_type_playback) { - return mal_is_playback_device_blacklisted__alsa(name); + if (deviceType == ma_device_type_playback) { + return ma_is_playback_device_blacklisted__alsa(name); } else { - return mal_is_capture_device_blacklisted__alsa(name); + return ma_is_capture_device_blacklisted__alsa(name); } } -const char* mal_find_char(const char* str, char c, int* index) +const char* ma_find_char(const char* str, char c, int* index) { int i = 0; for (;;) { @@ -11442,7 +11442,7 @@ const char* mal_find_char(const char* str, char c, int* index) return NULL; } -mal_bool32 mal_is_device_name_in_hw_format__alsa(const char* hwid) +ma_bool32 ma_is_device_name_in_hw_format__alsa(const char* hwid) { // This function is just checking whether or not hwid is in "hw:%d,%d" format. @@ -11457,7 +11457,7 @@ mal_bool32 mal_is_device_name_in_hw_format__alsa(const char* hwid) hwid += 3; int commaPos; - const char* dev = mal_find_char(hwid, ',', &commaPos); + const char* dev = ma_find_char(hwid, ',', &commaPos); if (dev == NULL) { return MA_FALSE; } else { @@ -11483,7 +11483,7 @@ mal_bool32 mal_is_device_name_in_hw_format__alsa(const char* hwid) return MA_TRUE; } -int mal_convert_device_name_to_hw_format__alsa(mal_context* pContext, char* dst, size_t dstSize, const char* src) // Returns 0 on success, non-0 on error. +int ma_convert_device_name_to_hw_format__alsa(ma_context* pContext, char* dst, size_t dstSize, const char* src) // Returns 0 on success, non-0 on error. { // src should look something like this: "hw:CARD=I82801AAICH,DEV=0" @@ -11494,13 +11494,13 @@ int mal_convert_device_name_to_hw_format__alsa(mal_context* pContext, char* dst, if (src == NULL) return -1; // If the input name is already in "hw:%d,%d" format, just return that verbatim. - if (mal_is_device_name_in_hw_format__alsa(src)) { - return mal_strcpy_s(dst, dstSize, src); + if (ma_is_device_name_in_hw_format__alsa(src)) { + return ma_strcpy_s(dst, dstSize, src); } int colonPos; - src = mal_find_char(src, ':', &colonPos); + src = ma_find_char(src, ':', &colonPos); if (src == NULL) { return -1; // Couldn't find a colon } @@ -11508,16 +11508,16 @@ int mal_convert_device_name_to_hw_format__alsa(mal_context* pContext, char* dst, char card[256]; int commaPos; - const char* dev = mal_find_char(src, ',', &commaPos); + const char* dev = ma_find_char(src, ',', &commaPos); if (dev == NULL) { dev = "0"; - mal_strncpy_s(card, sizeof(card), src+6, (size_t)-1); // +6 = ":CARD=" + ma_strncpy_s(card, sizeof(card), src+6, (size_t)-1); // +6 = ":CARD=" } else { dev = dev + 5; // +5 = ",DEV=" - mal_strncpy_s(card, sizeof(card), src+6, commaPos-6); // +6 = ":CARD=" + ma_strncpy_s(card, sizeof(card), src+6, commaPos-6); // +6 = ":CARD=" } - int cardIndex = ((mal_snd_card_get_index_proc)pContext->alsa.snd_card_get_index)(card); + int cardIndex = ((ma_snd_card_get_index_proc)pContext->alsa.snd_card_get_index)(card); if (cardIndex < 0) { return -2; // Failed to retrieve the card index. } @@ -11527,25 +11527,25 @@ int mal_convert_device_name_to_hw_format__alsa(mal_context* pContext, char* dst, // Construction. dst[0] = 'h'; dst[1] = 'w'; dst[2] = ':'; - if (mal_itoa_s(cardIndex, dst+3, dstSize-3, 10) != 0) { + if (ma_itoa_s(cardIndex, dst+3, dstSize-3, 10) != 0) { return -3; } - if (mal_strcat_s(dst, dstSize, ",") != 0) { + if (ma_strcat_s(dst, dstSize, ",") != 0) { return -3; } - if (mal_strcat_s(dst, dstSize, dev) != 0) { + if (ma_strcat_s(dst, dstSize, dev) != 0) { return -3; } return 0; } -mal_bool32 mal_does_id_exist_in_list__alsa(mal_device_id* pUniqueIDs, mal_uint32 count, const char* pHWID) +ma_bool32 ma_does_id_exist_in_list__alsa(ma_device_id* pUniqueIDs, ma_uint32 count, const char* pHWID) { - mal_assert(pHWID != NULL); + ma_assert(pHWID != NULL); - for (mal_uint32 i = 0; i < count; ++i) { - if (mal_strcmp(pUniqueIDs[i].alsa, pHWID) == 0) { + for (ma_uint32 i = 0; i < count; ++i) { + if (ma_strcmp(pUniqueIDs[i].alsa, pHWID) == 0) { return MA_TRUE; } } @@ -11554,16 +11554,16 @@ mal_bool32 mal_does_id_exist_in_list__alsa(mal_device_id* pUniqueIDs, mal_uint32 } -mal_result mal_context_open_pcm__alsa(mal_context* pContext, mal_share_mode shareMode, mal_device_type deviceType, const mal_device_id* pDeviceID, mal_snd_pcm_t** ppPCM) +ma_result ma_context_open_pcm__alsa(ma_context* pContext, ma_share_mode shareMode, ma_device_type deviceType, const ma_device_id* pDeviceID, ma_snd_pcm_t** ppPCM) { - mal_assert(pContext != NULL); - mal_assert(ppPCM != NULL); + ma_assert(pContext != NULL); + ma_assert(ppPCM != NULL); *ppPCM = NULL; - mal_snd_pcm_t* pPCM = NULL; + ma_snd_pcm_t* pPCM = NULL; - mal_snd_pcm_stream_t stream = (deviceType == mal_device_type_playback) ? MA_SND_PCM_STREAM_PLAYBACK : MA_SND_PCM_STREAM_CAPTURE; + ma_snd_pcm_stream_t stream = (deviceType == ma_device_type_playback) ? MA_SND_PCM_STREAM_PLAYBACK : MA_SND_PCM_STREAM_CAPTURE; int openMode = MA_SND_PCM_NO_AUTO_RESAMPLE | MA_SND_PCM_NO_AUTO_CHANNELS | MA_SND_PCM_NO_AUTO_FORMAT; if (pDeviceID == NULL) { @@ -11579,12 +11579,12 @@ mal_result mal_context_open_pcm__alsa(mal_context* pContext, mal_share_mode shar NULL }; - if (shareMode == mal_share_mode_exclusive) { + if (shareMode == ma_share_mode_exclusive) { defaultDeviceNames[1] = "hw"; defaultDeviceNames[2] = "hw:0"; defaultDeviceNames[3] = "hw:0,0"; } else { - if (deviceType == mal_device_type_playback) { + if (deviceType == ma_device_type_playback) { defaultDeviceNames[1] = "dmix"; defaultDeviceNames[2] = "dmix:0"; defaultDeviceNames[3] = "dmix:0,0"; @@ -11598,10 +11598,10 @@ mal_result mal_context_open_pcm__alsa(mal_context* pContext, mal_share_mode shar defaultDeviceNames[6] = "hw:0,0"; } - mal_bool32 isDeviceOpen = MA_FALSE; - for (size_t i = 0; i < mal_countof(defaultDeviceNames); ++i) { // TODO: i = 1 is temporary for testing purposes. Needs to be i = 0. + ma_bool32 isDeviceOpen = MA_FALSE; + for (size_t i = 0; i < ma_countof(defaultDeviceNames); ++i) { // TODO: i = 1 is temporary for testing purposes. Needs to be i = 0. if (defaultDeviceNames[i] != NULL && defaultDeviceNames[i][0] != '\0') { - if (((mal_snd_pcm_open_proc)pContext->alsa.snd_pcm_open)(&pPCM, defaultDeviceNames[i], stream, openMode) == 0) { + if (((ma_snd_pcm_open_proc)pContext->alsa.snd_pcm_open)(&pPCM, defaultDeviceNames[i], stream, openMode) == 0) { isDeviceOpen = MA_TRUE; break; } @@ -11609,7 +11609,7 @@ mal_result mal_context_open_pcm__alsa(mal_context* pContext, mal_share_mode shar } if (!isDeviceOpen) { - return mal_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[ALSA] snd_pcm_open() failed when trying to open an appropriate default device.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + return ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[ALSA] snd_pcm_open() failed when trying to open an appropriate default device.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } } else { // We're trying to open a specific device. There's a few things to consider here: @@ -11619,12 +11619,12 @@ mal_result mal_context_open_pcm__alsa(mal_context* pContext, mal_share_mode shar // finds an appropriate one that works. This comes in very handy when trying to open a device in shared mode ("dmix"), vs exclusive mode ("hw"). // May end up needing to make small adjustments to the ID, so make a copy. - mal_device_id deviceID = *pDeviceID; + ma_device_id deviceID = *pDeviceID; - mal_bool32 isDeviceOpen = MA_FALSE; + ma_bool32 isDeviceOpen = MA_FALSE; if (deviceID.alsa[0] != ':') { // The ID is not in ":0,0" format. Use the ID exactly as-is. - if (((mal_snd_pcm_open_proc)pContext->alsa.snd_pcm_open)(&pPCM, deviceID.alsa, stream, openMode) == 0) { + if (((ma_snd_pcm_open_proc)pContext->alsa.snd_pcm_open)(&pPCM, deviceID.alsa, stream, openMode) == 0) { isDeviceOpen = MA_TRUE; } } else { @@ -11634,15 +11634,15 @@ mal_result mal_context_open_pcm__alsa(mal_context* pContext, mal_share_mode shar } char hwid[256]; - if (shareMode == mal_share_mode_shared) { - if (deviceType == mal_device_type_playback) { - mal_strcpy_s(hwid, sizeof(hwid), "dmix"); + if (shareMode == ma_share_mode_shared) { + if (deviceType == ma_device_type_playback) { + ma_strcpy_s(hwid, sizeof(hwid), "dmix"); } else { - mal_strcpy_s(hwid, sizeof(hwid), "dsnoop"); + ma_strcpy_s(hwid, sizeof(hwid), "dsnoop"); } - if (mal_strcat_s(hwid, sizeof(hwid), deviceID.alsa) == 0) { - if (((mal_snd_pcm_open_proc)pContext->alsa.snd_pcm_open)(&pPCM, hwid, stream, openMode) == 0) { + if (ma_strcat_s(hwid, sizeof(hwid), deviceID.alsa) == 0) { + if (((ma_snd_pcm_open_proc)pContext->alsa.snd_pcm_open)(&pPCM, hwid, stream, openMode) == 0) { isDeviceOpen = MA_TRUE; } } @@ -11650,9 +11650,9 @@ mal_result mal_context_open_pcm__alsa(mal_context* pContext, mal_share_mode shar // If at this point we still don't have an open device it means we're either preferencing exclusive mode or opening with "dmix"/"dsnoop" failed. if (!isDeviceOpen) { - mal_strcpy_s(hwid, sizeof(hwid), "hw"); - if (mal_strcat_s(hwid, sizeof(hwid), deviceID.alsa) == 0) { - if (((mal_snd_pcm_open_proc)pContext->alsa.snd_pcm_open)(&pPCM, hwid, stream, openMode) == 0) { + ma_strcpy_s(hwid, sizeof(hwid), "hw"); + if (ma_strcat_s(hwid, sizeof(hwid), deviceID.alsa) == 0) { + if (((ma_snd_pcm_open_proc)pContext->alsa.snd_pcm_open)(&pPCM, hwid, stream, openMode) == 0) { isDeviceOpen = MA_TRUE; } } @@ -11660,7 +11660,7 @@ mal_result mal_context_open_pcm__alsa(mal_context* pContext, mal_share_mode shar } if (!isDeviceOpen) { - return mal_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[ALSA] snd_pcm_open() failed.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + return ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[ALSA] snd_pcm_open() failed.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } } @@ -11669,56 +11669,56 @@ mal_result mal_context_open_pcm__alsa(mal_context* pContext, mal_share_mode shar } -mal_bool32 mal_context_is_device_id_equal__alsa(mal_context* pContext, const mal_device_id* pID0, const mal_device_id* pID1) +ma_bool32 ma_context_is_device_id_equal__alsa(ma_context* pContext, const ma_device_id* pID0, const ma_device_id* pID1) { - mal_assert(pContext != NULL); - mal_assert(pID0 != NULL); - mal_assert(pID1 != NULL); + ma_assert(pContext != NULL); + ma_assert(pID0 != NULL); + ma_assert(pID1 != NULL); (void)pContext; - return mal_strcmp(pID0->alsa, pID1->alsa) == 0; + return ma_strcmp(pID0->alsa, pID1->alsa) == 0; } -mal_result mal_context_enumerate_devices__alsa(mal_context* pContext, mal_enum_devices_callback_proc callback, void* pUserData) +ma_result ma_context_enumerate_devices__alsa(ma_context* pContext, ma_enum_devices_callback_proc callback, void* pUserData) { - mal_assert(pContext != NULL); - mal_assert(callback != NULL); + ma_assert(pContext != NULL); + ma_assert(callback != NULL); - mal_bool32 cbResult = MA_TRUE; + ma_bool32 cbResult = MA_TRUE; - mal_mutex_lock(&pContext->alsa.internalDeviceEnumLock); + ma_mutex_lock(&pContext->alsa.internalDeviceEnumLock); char** ppDeviceHints; - if (((mal_snd_device_name_hint_proc)pContext->alsa.snd_device_name_hint)(-1, "pcm", (void***)&ppDeviceHints) < 0) { - mal_mutex_unlock(&pContext->alsa.internalDeviceEnumLock); + if (((ma_snd_device_name_hint_proc)pContext->alsa.snd_device_name_hint)(-1, "pcm", (void***)&ppDeviceHints) < 0) { + ma_mutex_unlock(&pContext->alsa.internalDeviceEnumLock); return MA_NO_BACKEND; } - mal_device_id* pUniqueIDs = NULL; - mal_uint32 uniqueIDCount = 0; + ma_device_id* pUniqueIDs = NULL; + ma_uint32 uniqueIDCount = 0; char** ppNextDeviceHint = ppDeviceHints; while (*ppNextDeviceHint != NULL) { - char* NAME = ((mal_snd_device_name_get_hint_proc)pContext->alsa.snd_device_name_get_hint)(*ppNextDeviceHint, "NAME"); - char* DESC = ((mal_snd_device_name_get_hint_proc)pContext->alsa.snd_device_name_get_hint)(*ppNextDeviceHint, "DESC"); - char* IOID = ((mal_snd_device_name_get_hint_proc)pContext->alsa.snd_device_name_get_hint)(*ppNextDeviceHint, "IOID"); + char* NAME = ((ma_snd_device_name_get_hint_proc)pContext->alsa.snd_device_name_get_hint)(*ppNextDeviceHint, "NAME"); + char* DESC = ((ma_snd_device_name_get_hint_proc)pContext->alsa.snd_device_name_get_hint)(*ppNextDeviceHint, "DESC"); + char* IOID = ((ma_snd_device_name_get_hint_proc)pContext->alsa.snd_device_name_get_hint)(*ppNextDeviceHint, "IOID"); - mal_device_type deviceType = mal_device_type_playback; - if ((IOID == NULL || mal_strcmp(IOID, "Output") == 0)) { - deviceType = mal_device_type_playback; + ma_device_type deviceType = ma_device_type_playback; + if ((IOID == NULL || ma_strcmp(IOID, "Output") == 0)) { + deviceType = ma_device_type_playback; } - if ((IOID != NULL && mal_strcmp(IOID, "Input" ) == 0)) { - deviceType = mal_device_type_capture; + if ((IOID != NULL && ma_strcmp(IOID, "Input" ) == 0)) { + deviceType = ma_device_type_capture; } - mal_bool32 stopEnumeration = MA_FALSE; + ma_bool32 stopEnumeration = MA_FALSE; #if 0 printf("NAME: %s\n", NAME); printf("DESC: %s\n", DESC); printf("IOID: %s\n", IOID); char hwid2[256]; - mal_convert_device_name_to_hw_format__alsa(pContext, hwid2, sizeof(hwid2), NAME); + ma_convert_device_name_to_hw_format__alsa(pContext, hwid2, sizeof(hwid2), NAME); printf("DEVICE ID: %s\n\n", hwid2); #endif @@ -11726,10 +11726,10 @@ mal_result mal_context_enumerate_devices__alsa(mal_context* pContext, mal_enum_d if (NAME != NULL) { if (pContext->config.alsa.useVerboseDeviceEnumeration) { // Verbose mode. Use the name exactly as-is. - mal_strncpy_s(hwid, sizeof(hwid), NAME, (size_t)-1); + ma_strncpy_s(hwid, sizeof(hwid), NAME, (size_t)-1); } else { // Simplified mode. Use ":%d,%d" format. - if (mal_convert_device_name_to_hw_format__alsa(pContext, hwid, sizeof(hwid), NAME) == 0) { + if (ma_convert_device_name_to_hw_format__alsa(pContext, hwid, sizeof(hwid), NAME) == 0) { // At this point, hwid looks like "hw:0,0". In simplified enumeration mode, we actually want to strip off the // plugin name so it looks like ":0,0". The reason for this is that this special format is detected at device // initialization time and is used as an indicator to try and use the most appropriate plugin depending on the @@ -11739,30 +11739,30 @@ mal_result mal_context_enumerate_devices__alsa(mal_context* pContext, mal_enum_d while ((*dst++ = *src++)); } else { // Conversion to "hw:%d,%d" failed. Just use the name as-is. - mal_strncpy_s(hwid, sizeof(hwid), NAME, (size_t)-1); + ma_strncpy_s(hwid, sizeof(hwid), NAME, (size_t)-1); } - if (mal_does_id_exist_in_list__alsa(pUniqueIDs, uniqueIDCount, hwid)) { + if (ma_does_id_exist_in_list__alsa(pUniqueIDs, uniqueIDCount, hwid)) { goto next_device; // The device has already been enumerated. Move on to the next one. } else { // The device has not yet been enumerated. Make sure it's added to our list so that it's not enumerated again. - mal_device_id* pNewUniqueIDs = (mal_device_id*)mal_realloc(pUniqueIDs, sizeof(*pUniqueIDs) * (uniqueIDCount + 1)); + ma_device_id* pNewUniqueIDs = (ma_device_id*)ma_realloc(pUniqueIDs, sizeof(*pUniqueIDs) * (uniqueIDCount + 1)); if (pNewUniqueIDs == NULL) { goto next_device; // Failed to allocate memory. } pUniqueIDs = pNewUniqueIDs; - mal_copy_memory(pUniqueIDs[uniqueIDCount].alsa, hwid, sizeof(hwid)); + ma_copy_memory(pUniqueIDs[uniqueIDCount].alsa, hwid, sizeof(hwid)); uniqueIDCount += 1; } } } else { - mal_zero_memory(hwid, sizeof(hwid)); + ma_zero_memory(hwid, sizeof(hwid)); } - mal_device_info deviceInfo; - mal_zero_object(&deviceInfo); - mal_strncpy_s(deviceInfo.id.alsa, sizeof(deviceInfo.id.alsa), hwid, (size_t)-1); + ma_device_info deviceInfo; + ma_zero_object(&deviceInfo); + ma_strncpy_s(deviceInfo.id.alsa, sizeof(deviceInfo.id.alsa), hwid, (size_t)-1); // DESC is the friendly name. We treat this slightly differently depending on whether or not we are using verbose // device enumeration. In verbose mode we want to take the entire description so that the end-user can distinguish @@ -11775,41 +11775,41 @@ mal_result mal_context_enumerate_devices__alsa(mal_context* pContext, mal_enum_d // being put into parentheses. In simplified mode I'm just stripping the second line entirely. if (DESC != NULL) { int lfPos; - const char* line2 = mal_find_char(DESC, '\n', &lfPos); + const char* line2 = ma_find_char(DESC, '\n', &lfPos); if (line2 != NULL) { line2 += 1; // Skip past the new-line character. if (pContext->config.alsa.useVerboseDeviceEnumeration) { // Verbose mode. Put the second line in brackets. - mal_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), DESC, lfPos); - mal_strcat_s (deviceInfo.name, sizeof(deviceInfo.name), " ("); - mal_strcat_s (deviceInfo.name, sizeof(deviceInfo.name), line2); - mal_strcat_s (deviceInfo.name, sizeof(deviceInfo.name), ")"); + ma_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), DESC, lfPos); + ma_strcat_s (deviceInfo.name, sizeof(deviceInfo.name), " ("); + ma_strcat_s (deviceInfo.name, sizeof(deviceInfo.name), line2); + ma_strcat_s (deviceInfo.name, sizeof(deviceInfo.name), ")"); } else { // Simplified mode. Strip the second line entirely. - mal_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), DESC, lfPos); + ma_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), DESC, lfPos); } } else { // There's no second line. Just copy the whole description. - mal_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), DESC, (size_t)-1); + ma_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), DESC, (size_t)-1); } } - if (!mal_is_device_blacklisted__alsa(deviceType, NAME)) { + if (!ma_is_device_blacklisted__alsa(deviceType, NAME)) { cbResult = callback(pContext, deviceType, &deviceInfo, pUserData); } // Some devices are both playback and capture, but they are only enumerated by ALSA once. We need to fire the callback // again for the other device type in this case. We do this for known devices. if (cbResult) { - if (mal_is_common_device_name__alsa(NAME)) { - if (deviceType == mal_device_type_playback) { - if (!mal_is_capture_device_blacklisted__alsa(NAME)) { - cbResult = callback(pContext, mal_device_type_capture, &deviceInfo, pUserData); + if (ma_is_common_device_name__alsa(NAME)) { + if (deviceType == ma_device_type_playback) { + if (!ma_is_capture_device_blacklisted__alsa(NAME)) { + cbResult = callback(pContext, ma_device_type_capture, &deviceInfo, pUserData); } } else { - if (!mal_is_playback_device_blacklisted__alsa(NAME)) { - cbResult = callback(pContext, mal_device_type_playback, &deviceInfo, pUserData); + if (!ma_is_playback_device_blacklisted__alsa(NAME)) { + cbResult = callback(pContext, ma_device_type_playback, &deviceInfo, pUserData); } } } @@ -11831,10 +11831,10 @@ mal_result mal_context_enumerate_devices__alsa(mal_context* pContext, mal_enum_d } } - mal_free(pUniqueIDs); - ((mal_snd_device_name_free_hint_proc)pContext->alsa.snd_device_name_free_hint)((void**)ppDeviceHints); + ma_free(pUniqueIDs); + ((ma_snd_device_name_free_hint_proc)pContext->alsa.snd_device_name_free_hint)((void**)ppDeviceHints); - mal_mutex_unlock(&pContext->alsa.internalDeviceEnumLock); + ma_mutex_unlock(&pContext->alsa.internalDeviceEnumLock); return MA_SUCCESS; } @@ -11842,24 +11842,24 @@ mal_result mal_context_enumerate_devices__alsa(mal_context* pContext, mal_enum_d typedef struct { - mal_device_type deviceType; - const mal_device_id* pDeviceID; - mal_share_mode shareMode; - mal_device_info* pDeviceInfo; - mal_bool32 foundDevice; -} mal_context_get_device_info_enum_callback_data__alsa; + ma_device_type deviceType; + const ma_device_id* pDeviceID; + ma_share_mode shareMode; + ma_device_info* pDeviceInfo; + ma_bool32 foundDevice; +} ma_context_get_device_info_enum_callback_data__alsa; -mal_bool32 mal_context_get_device_info_enum_callback__alsa(mal_context* pContext, mal_device_type deviceType, const mal_device_info* pDeviceInfo, void* pUserData) +ma_bool32 ma_context_get_device_info_enum_callback__alsa(ma_context* pContext, ma_device_type deviceType, const ma_device_info* pDeviceInfo, void* pUserData) { - mal_context_get_device_info_enum_callback_data__alsa* pData = (mal_context_get_device_info_enum_callback_data__alsa*)pUserData; - mal_assert(pData != NULL); + ma_context_get_device_info_enum_callback_data__alsa* pData = (ma_context_get_device_info_enum_callback_data__alsa*)pUserData; + ma_assert(pData != NULL); - if (pData->pDeviceID == NULL && mal_strcmp(pDeviceInfo->id.alsa, "default") == 0) { - mal_strncpy_s(pData->pDeviceInfo->name, sizeof(pData->pDeviceInfo->name), pDeviceInfo->name, (size_t)-1); + if (pData->pDeviceID == NULL && ma_strcmp(pDeviceInfo->id.alsa, "default") == 0) { + ma_strncpy_s(pData->pDeviceInfo->name, sizeof(pData->pDeviceInfo->name), pDeviceInfo->name, (size_t)-1); pData->foundDevice = MA_TRUE; } else { - if (pData->deviceType == deviceType && mal_context_is_device_id_equal__alsa(pContext, pData->pDeviceID, &pDeviceInfo->id)) { - mal_strncpy_s(pData->pDeviceInfo->name, sizeof(pData->pDeviceInfo->name), pDeviceInfo->name, (size_t)-1); + if (pData->deviceType == deviceType && ma_context_is_device_id_equal__alsa(pContext, pData->pDeviceID, &pDeviceInfo->id)) { + ma_strncpy_s(pData->pDeviceInfo->name, sizeof(pData->pDeviceInfo->name), pDeviceInfo->name, (size_t)-1); pData->foundDevice = MA_TRUE; } } @@ -11868,18 +11868,18 @@ mal_bool32 mal_context_get_device_info_enum_callback__alsa(mal_context* pContext return !pData->foundDevice; } -mal_result mal_context_get_device_info__alsa(mal_context* pContext, mal_device_type deviceType, const mal_device_id* pDeviceID, mal_share_mode shareMode, mal_device_info* pDeviceInfo) +ma_result ma_context_get_device_info__alsa(ma_context* pContext, ma_device_type deviceType, const ma_device_id* pDeviceID, ma_share_mode shareMode, ma_device_info* pDeviceInfo) { - mal_assert(pContext != NULL); + ma_assert(pContext != NULL); // We just enumerate to find basic information about the device. - mal_context_get_device_info_enum_callback_data__alsa data; + ma_context_get_device_info_enum_callback_data__alsa data; data.deviceType = deviceType; data.pDeviceID = pDeviceID; data.shareMode = shareMode; data.pDeviceInfo = pDeviceInfo; data.foundDevice = MA_FALSE; - mal_result result = mal_context_enumerate_devices__alsa(pContext, mal_context_get_device_info_enum_callback__alsa, &data); + ma_result result = ma_context_enumerate_devices__alsa(pContext, ma_context_get_device_info_enum_callback__alsa, &data); if (result != MA_SUCCESS) { return result; } @@ -11890,50 +11890,50 @@ mal_result mal_context_get_device_info__alsa(mal_context* pContext, mal_device_t // For detailed info we need to open the device. - mal_snd_pcm_t* pPCM; - result = mal_context_open_pcm__alsa(pContext, shareMode, deviceType, pDeviceID, &pPCM); + ma_snd_pcm_t* pPCM; + result = ma_context_open_pcm__alsa(pContext, shareMode, deviceType, pDeviceID, &pPCM); if (result != MA_SUCCESS) { return result; } // We need to initialize a HW parameters object in order to know what formats are supported. - mal_snd_pcm_hw_params_t* pHWParams = (mal_snd_pcm_hw_params_t*)alloca(((mal_snd_pcm_hw_params_sizeof_proc)pContext->alsa.snd_pcm_hw_params_sizeof)()); - mal_zero_memory(pHWParams, ((mal_snd_pcm_hw_params_sizeof_proc)pContext->alsa.snd_pcm_hw_params_sizeof)()); + ma_snd_pcm_hw_params_t* pHWParams = (ma_snd_pcm_hw_params_t*)alloca(((ma_snd_pcm_hw_params_sizeof_proc)pContext->alsa.snd_pcm_hw_params_sizeof)()); + ma_zero_memory(pHWParams, ((ma_snd_pcm_hw_params_sizeof_proc)pContext->alsa.snd_pcm_hw_params_sizeof)()); - if (((mal_snd_pcm_hw_params_any_proc)pContext->alsa.snd_pcm_hw_params_any)(pPCM, pHWParams) < 0) { - return mal_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to initialize hardware parameters. snd_pcm_hw_params_any() failed.", MA_FAILED_TO_CONFIGURE_BACKEND_DEVICE); + if (((ma_snd_pcm_hw_params_any_proc)pContext->alsa.snd_pcm_hw_params_any)(pPCM, pHWParams) < 0) { + return ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to initialize hardware parameters. snd_pcm_hw_params_any() failed.", MA_FAILED_TO_CONFIGURE_BACKEND_DEVICE); } int sampleRateDir = 0; - ((mal_snd_pcm_hw_params_get_channels_min_proc)pContext->alsa.snd_pcm_hw_params_get_channels_min)(pHWParams, &pDeviceInfo->minChannels); - ((mal_snd_pcm_hw_params_get_channels_max_proc)pContext->alsa.snd_pcm_hw_params_get_channels_max)(pHWParams, &pDeviceInfo->maxChannels); - ((mal_snd_pcm_hw_params_get_rate_min_proc)pContext->alsa.snd_pcm_hw_params_get_rate_min)(pHWParams, &pDeviceInfo->minSampleRate, &sampleRateDir); - ((mal_snd_pcm_hw_params_get_rate_max_proc)pContext->alsa.snd_pcm_hw_params_get_rate_max)(pHWParams, &pDeviceInfo->maxSampleRate, &sampleRateDir); + ((ma_snd_pcm_hw_params_get_channels_min_proc)pContext->alsa.snd_pcm_hw_params_get_channels_min)(pHWParams, &pDeviceInfo->minChannels); + ((ma_snd_pcm_hw_params_get_channels_max_proc)pContext->alsa.snd_pcm_hw_params_get_channels_max)(pHWParams, &pDeviceInfo->maxChannels); + ((ma_snd_pcm_hw_params_get_rate_min_proc)pContext->alsa.snd_pcm_hw_params_get_rate_min)(pHWParams, &pDeviceInfo->minSampleRate, &sampleRateDir); + ((ma_snd_pcm_hw_params_get_rate_max_proc)pContext->alsa.snd_pcm_hw_params_get_rate_max)(pHWParams, &pDeviceInfo->maxSampleRate, &sampleRateDir); // Formats. - mal_snd_pcm_format_mask_t* pFormatMask = (mal_snd_pcm_format_mask_t*)alloca(((mal_snd_pcm_format_mask_sizeof_proc)pContext->alsa.snd_pcm_format_mask_sizeof)()); - mal_zero_memory(pFormatMask, ((mal_snd_pcm_format_mask_sizeof_proc)pContext->alsa.snd_pcm_format_mask_sizeof)()); - ((mal_snd_pcm_hw_params_get_format_mask_proc)pContext->alsa.snd_pcm_hw_params_get_format_mask)(pHWParams, pFormatMask); + ma_snd_pcm_format_mask_t* pFormatMask = (ma_snd_pcm_format_mask_t*)alloca(((ma_snd_pcm_format_mask_sizeof_proc)pContext->alsa.snd_pcm_format_mask_sizeof)()); + ma_zero_memory(pFormatMask, ((ma_snd_pcm_format_mask_sizeof_proc)pContext->alsa.snd_pcm_format_mask_sizeof)()); + ((ma_snd_pcm_hw_params_get_format_mask_proc)pContext->alsa.snd_pcm_hw_params_get_format_mask)(pHWParams, pFormatMask); pDeviceInfo->formatCount = 0; - if (((mal_snd_pcm_format_mask_test_proc)pContext->alsa.snd_pcm_format_mask_test)(pFormatMask, MA_SND_PCM_FORMAT_U8)) { - pDeviceInfo->formats[pDeviceInfo->formatCount++] = mal_format_u8; + if (((ma_snd_pcm_format_mask_test_proc)pContext->alsa.snd_pcm_format_mask_test)(pFormatMask, MA_SND_PCM_FORMAT_U8)) { + pDeviceInfo->formats[pDeviceInfo->formatCount++] = ma_format_u8; } - if (((mal_snd_pcm_format_mask_test_proc)pContext->alsa.snd_pcm_format_mask_test)(pFormatMask, MA_SND_PCM_FORMAT_S16_LE)) { - pDeviceInfo->formats[pDeviceInfo->formatCount++] = mal_format_s16; + if (((ma_snd_pcm_format_mask_test_proc)pContext->alsa.snd_pcm_format_mask_test)(pFormatMask, MA_SND_PCM_FORMAT_S16_LE)) { + pDeviceInfo->formats[pDeviceInfo->formatCount++] = ma_format_s16; } - if (((mal_snd_pcm_format_mask_test_proc)pContext->alsa.snd_pcm_format_mask_test)(pFormatMask, MA_SND_PCM_FORMAT_S24_3LE)) { - pDeviceInfo->formats[pDeviceInfo->formatCount++] = mal_format_s24; + if (((ma_snd_pcm_format_mask_test_proc)pContext->alsa.snd_pcm_format_mask_test)(pFormatMask, MA_SND_PCM_FORMAT_S24_3LE)) { + pDeviceInfo->formats[pDeviceInfo->formatCount++] = ma_format_s24; } - if (((mal_snd_pcm_format_mask_test_proc)pContext->alsa.snd_pcm_format_mask_test)(pFormatMask, MA_SND_PCM_FORMAT_S32_LE)) { - pDeviceInfo->formats[pDeviceInfo->formatCount++] = mal_format_s32; + if (((ma_snd_pcm_format_mask_test_proc)pContext->alsa.snd_pcm_format_mask_test)(pFormatMask, MA_SND_PCM_FORMAT_S32_LE)) { + pDeviceInfo->formats[pDeviceInfo->formatCount++] = ma_format_s32; } - if (((mal_snd_pcm_format_mask_test_proc)pContext->alsa.snd_pcm_format_mask_test)(pFormatMask, MA_SND_PCM_FORMAT_FLOAT_LE)) { - pDeviceInfo->formats[pDeviceInfo->formatCount++] = mal_format_f32; + if (((ma_snd_pcm_format_mask_test_proc)pContext->alsa.snd_pcm_format_mask_test)(pFormatMask, MA_SND_PCM_FORMAT_FLOAT_LE)) { + pDeviceInfo->formats[pDeviceInfo->formatCount++] = ma_format_f32; } - ((mal_snd_pcm_close_proc)pContext->alsa.snd_pcm_close)(pPCM); + ((ma_snd_pcm_close_proc)pContext->alsa.snd_pcm_close)(pPCM); return MA_SUCCESS; } @@ -11942,20 +11942,20 @@ mal_result mal_context_get_device_info__alsa(mal_context* pContext, mal_device_t // Waits for a number of frames to become available for either capture or playback. The return // value is the number of frames available. // -// This will return early if the main loop is broken with mal_device__break_main_loop(). -mal_uint32 mal_device__wait_for_frames__alsa(mal_device* pDevice, mal_bool32* pRequiresRestart) +// This will return early if the main loop is broken with ma_device__break_main_loop(). +ma_uint32 ma_device__wait_for_frames__alsa(ma_device* pDevice, ma_bool32* pRequiresRestart) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); if (pRequiresRestart) *pRequiresRestart = MA_FALSE; // I want it so that this function returns the period size in frames. We just wait until that number of frames are available and then return. - mal_uint32 periodSizeInFrames = pDevice->bufferSizeInFrames / pDevice->periods; + ma_uint32 periodSizeInFrames = pDevice->bufferSizeInFrames / pDevice->periods; while (!pDevice->alsa.breakFromMainLoop) { - mal_snd_pcm_sframes_t framesAvailable = ((mal_snd_pcm_avail_update_proc)pDevice->pContext->alsa.snd_pcm_avail_update)((mal_snd_pcm_t*)pDevice->alsa.pPCM); + ma_snd_pcm_sframes_t framesAvailable = ((ma_snd_pcm_avail_update_proc)pDevice->pContext->alsa.snd_pcm_avail_update)((ma_snd_pcm_t*)pDevice->alsa.pPCM); if (framesAvailable < 0) { if (framesAvailable == -EPIPE) { - if (((mal_snd_pcm_recover_proc)pDevice->pContext->alsa.snd_pcm_recover)((mal_snd_pcm_t*)pDevice->alsa.pPCM, framesAvailable, MA_TRUE) < 0) { + if (((ma_snd_pcm_recover_proc)pDevice->pContext->alsa.snd_pcm_recover)((ma_snd_pcm_t*)pDevice->alsa.pPCM, framesAvailable, MA_TRUE) < 0) { return 0; } @@ -11965,7 +11965,7 @@ mal_uint32 mal_device__wait_for_frames__alsa(mal_device* pDevice, mal_bool32* pR } // Try again, but if it fails this time just return an error. - framesAvailable = ((mal_snd_pcm_avail_update_proc)pDevice->pContext->alsa.snd_pcm_avail_update)((mal_snd_pcm_t*)pDevice->alsa.pPCM); + framesAvailable = ((ma_snd_pcm_avail_update_proc)pDevice->pContext->alsa.snd_pcm_avail_update)((ma_snd_pcm_t*)pDevice->alsa.pPCM); if (framesAvailable < 0) { return 0; } @@ -11978,10 +11978,10 @@ mal_uint32 mal_device__wait_for_frames__alsa(mal_device* pDevice, mal_bool32* pR if (framesAvailable < periodSizeInFrames) { // Less than a whole period is available so keep waiting. - int waitResult = ((mal_snd_pcm_wait_proc)pDevice->pContext->alsa.snd_pcm_wait)((mal_snd_pcm_t*)pDevice->alsa.pPCM, -1); + int waitResult = ((ma_snd_pcm_wait_proc)pDevice->pContext->alsa.snd_pcm_wait)((ma_snd_pcm_t*)pDevice->alsa.pPCM, -1); if (waitResult < 0) { if (waitResult == -EPIPE) { - if (((mal_snd_pcm_recover_proc)pDevice->pContext->alsa.snd_pcm_recover)((mal_snd_pcm_t*)pDevice->alsa.pPCM, waitResult, MA_TRUE) < 0) { + if (((ma_snd_pcm_recover_proc)pDevice->pContext->alsa.snd_pcm_recover)((ma_snd_pcm_t*)pDevice->alsa.pPCM, waitResult, MA_TRUE) < 0) { return 0; } @@ -11995,7 +11995,7 @@ mal_uint32 mal_device__wait_for_frames__alsa(mal_device* pDevice, mal_bool32* pR } // We'll get here if the loop was terminated. Just return whatever's available. - mal_snd_pcm_sframes_t framesAvailable = ((mal_snd_pcm_avail_update_proc)pDevice->pContext->alsa.snd_pcm_avail_update)((mal_snd_pcm_t*)pDevice->alsa.pPCM); + ma_snd_pcm_sframes_t framesAvailable = ((ma_snd_pcm_avail_update_proc)pDevice->pContext->alsa.snd_pcm_avail_update)((ma_snd_pcm_t*)pDevice->alsa.pPCM); if (framesAvailable < 0) { return 0; } @@ -12003,10 +12003,10 @@ mal_uint32 mal_device__wait_for_frames__alsa(mal_device* pDevice, mal_bool32* pR return framesAvailable; } -mal_bool32 mal_device_read_from_client_and_write__alsa(mal_device* pDevice) +ma_bool32 ma_device_read_from_client_and_write__alsa(ma_device* pDevice) { - mal_assert(pDevice != NULL); - if (!mal_device_is_started(pDevice) && mal_device__get_state(pDevice) != MA_STATE_STARTING) { + ma_assert(pDevice != NULL); + if (!ma_device_is_started(pDevice) && ma_device__get_state(pDevice) != MA_STATE_STARTING) { return MA_FALSE; } if (pDevice->alsa.breakFromMainLoop) { @@ -12015,8 +12015,8 @@ mal_bool32 mal_device_read_from_client_and_write__alsa(mal_device* pDevice) if (pDevice->alsa.isUsingMMap) { // mmap. - mal_bool32 requiresRestart; - mal_uint32 framesAvailable = mal_device__wait_for_frames__alsa(pDevice, &requiresRestart); + ma_bool32 requiresRestart; + ma_uint32 framesAvailable = ma_device__wait_for_frames__alsa(pDevice, &requiresRestart); if (framesAvailable == 0) { return MA_FALSE; } @@ -12026,28 +12026,28 @@ mal_bool32 mal_device_read_from_client_and_write__alsa(mal_device* pDevice) return MA_FALSE; } - const mal_snd_pcm_channel_area_t* pAreas; - mal_snd_pcm_uframes_t mappedOffset; - mal_snd_pcm_uframes_t mappedFrames = framesAvailable; + const ma_snd_pcm_channel_area_t* pAreas; + ma_snd_pcm_uframes_t mappedOffset; + ma_snd_pcm_uframes_t mappedFrames = framesAvailable; while (framesAvailable > 0) { - int result = ((mal_snd_pcm_mmap_begin_proc)pDevice->pContext->alsa.snd_pcm_mmap_begin)((mal_snd_pcm_t*)pDevice->alsa.pPCM, &pAreas, &mappedOffset, &mappedFrames); + int result = ((ma_snd_pcm_mmap_begin_proc)pDevice->pContext->alsa.snd_pcm_mmap_begin)((ma_snd_pcm_t*)pDevice->alsa.pPCM, &pAreas, &mappedOffset, &mappedFrames); if (result < 0) { return MA_FALSE; } if (mappedFrames > 0) { - void* pBuffer = (mal_uint8*)pAreas[0].addr + ((pAreas[0].first + (mappedOffset * pAreas[0].step)) / 8); - mal_device__read_frames_from_client(pDevice, mappedFrames, pBuffer); + void* pBuffer = (ma_uint8*)pAreas[0].addr + ((pAreas[0].first + (mappedOffset * pAreas[0].step)) / 8); + ma_device__read_frames_from_client(pDevice, mappedFrames, pBuffer); } - result = ((mal_snd_pcm_mmap_commit_proc)pDevice->pContext->alsa.snd_pcm_mmap_commit)((mal_snd_pcm_t*)pDevice->alsa.pPCM, mappedOffset, mappedFrames); - if (result < 0 || (mal_snd_pcm_uframes_t)result != mappedFrames) { - ((mal_snd_pcm_recover_proc)pDevice->pContext->alsa.snd_pcm_recover)((mal_snd_pcm_t*)pDevice->alsa.pPCM, result, MA_TRUE); + result = ((ma_snd_pcm_mmap_commit_proc)pDevice->pContext->alsa.snd_pcm_mmap_commit)((ma_snd_pcm_t*)pDevice->alsa.pPCM, mappedOffset, mappedFrames); + if (result < 0 || (ma_snd_pcm_uframes_t)result != mappedFrames) { + ((ma_snd_pcm_recover_proc)pDevice->pContext->alsa.snd_pcm_recover)((ma_snd_pcm_t*)pDevice->alsa.pPCM, result, MA_TRUE); return MA_FALSE; } if (requiresRestart) { - if (((mal_snd_pcm_start_proc)pDevice->pContext->alsa.snd_pcm_start)((mal_snd_pcm_t*)pDevice->alsa.pPCM) < 0) { + if (((ma_snd_pcm_start_proc)pDevice->pContext->alsa.snd_pcm_start)((ma_snd_pcm_t*)pDevice->alsa.pPCM) < 0) { return MA_FALSE; } } @@ -12061,7 +12061,7 @@ mal_bool32 mal_device_read_from_client_and_write__alsa(mal_device* pDevice) } else { // readi/writei. while (!pDevice->alsa.breakFromMainLoop) { - mal_uint32 framesAvailable = mal_device__wait_for_frames__alsa(pDevice, NULL); + ma_uint32 framesAvailable = ma_device__wait_for_frames__alsa(pDevice, NULL); if (framesAvailable == 0) { continue; } @@ -12071,28 +12071,28 @@ mal_bool32 mal_device_read_from_client_and_write__alsa(mal_device* pDevice) return MA_FALSE; } - mal_device__read_frames_from_client(pDevice, framesAvailable, pDevice->alsa.pIntermediaryBuffer); + ma_device__read_frames_from_client(pDevice, framesAvailable, pDevice->alsa.pIntermediaryBuffer); - mal_snd_pcm_sframes_t framesWritten = ((mal_snd_pcm_writei_proc)pDevice->pContext->alsa.snd_pcm_writei)((mal_snd_pcm_t*)pDevice->alsa.pPCM, pDevice->alsa.pIntermediaryBuffer, framesAvailable); + ma_snd_pcm_sframes_t framesWritten = ((ma_snd_pcm_writei_proc)pDevice->pContext->alsa.snd_pcm_writei)((ma_snd_pcm_t*)pDevice->alsa.pPCM, pDevice->alsa.pIntermediaryBuffer, framesAvailable); if (framesWritten < 0) { if (framesWritten == -EAGAIN) { continue; // Just keep trying... } else if (framesWritten == -EPIPE) { // Underrun. Just recover and try writing again. - if (((mal_snd_pcm_recover_proc)pDevice->pContext->alsa.snd_pcm_recover)((mal_snd_pcm_t*)pDevice->alsa.pPCM, framesWritten, MA_TRUE) < 0) { - mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to recover device after underrun.", MA_FAILED_TO_START_BACKEND_DEVICE); + if (((ma_snd_pcm_recover_proc)pDevice->pContext->alsa.snd_pcm_recover)((ma_snd_pcm_t*)pDevice->alsa.pPCM, framesWritten, MA_TRUE) < 0) { + ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to recover device after underrun.", MA_FAILED_TO_START_BACKEND_DEVICE); return MA_FALSE; } - framesWritten = ((mal_snd_pcm_writei_proc)pDevice->pContext->alsa.snd_pcm_writei)((mal_snd_pcm_t*)pDevice->alsa.pPCM, pDevice->alsa.pIntermediaryBuffer, framesAvailable); + framesWritten = ((ma_snd_pcm_writei_proc)pDevice->pContext->alsa.snd_pcm_writei)((ma_snd_pcm_t*)pDevice->alsa.pPCM, pDevice->alsa.pIntermediaryBuffer, framesAvailable); if (framesWritten < 0) { - mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to write data to the internal device.", MA_FAILED_TO_SEND_DATA_TO_DEVICE); + ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to write data to the internal device.", MA_FAILED_TO_SEND_DATA_TO_DEVICE); return MA_FALSE; } break; // Success. } else { - mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] snd_pcm_writei() failed when writing initial data.", MA_FAILED_TO_SEND_DATA_TO_DEVICE); + ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] snd_pcm_writei() failed when writing initial data.", MA_FAILED_TO_SEND_DATA_TO_DEVICE); return MA_FALSE; } } else { @@ -12104,48 +12104,48 @@ mal_bool32 mal_device_read_from_client_and_write__alsa(mal_device* pDevice) return MA_TRUE; } -mal_bool32 mal_device_read_and_send_to_client__alsa(mal_device* pDevice) +ma_bool32 ma_device_read_and_send_to_client__alsa(ma_device* pDevice) { - mal_assert(pDevice != NULL); - if (!mal_device_is_started(pDevice)) { + ma_assert(pDevice != NULL); + if (!ma_device_is_started(pDevice)) { return MA_FALSE; } if (pDevice->alsa.breakFromMainLoop) { return MA_FALSE; } - mal_uint32 framesToSend = 0; + ma_uint32 framesToSend = 0; void* pBuffer = NULL; if (pDevice->alsa.pIntermediaryBuffer == NULL) { // mmap. - mal_bool32 requiresRestart; - mal_uint32 framesAvailable = mal_device__wait_for_frames__alsa(pDevice, &requiresRestart); + ma_bool32 requiresRestart; + ma_uint32 framesAvailable = ma_device__wait_for_frames__alsa(pDevice, &requiresRestart); if (framesAvailable == 0) { return MA_FALSE; } - const mal_snd_pcm_channel_area_t* pAreas; - mal_snd_pcm_uframes_t mappedOffset; - mal_snd_pcm_uframes_t mappedFrames = framesAvailable; + const ma_snd_pcm_channel_area_t* pAreas; + ma_snd_pcm_uframes_t mappedOffset; + ma_snd_pcm_uframes_t mappedFrames = framesAvailable; while (framesAvailable > 0) { - int result = ((mal_snd_pcm_mmap_begin_proc)pDevice->pContext->alsa.snd_pcm_mmap_begin)((mal_snd_pcm_t*)pDevice->alsa.pPCM, &pAreas, &mappedOffset, &mappedFrames); + int result = ((ma_snd_pcm_mmap_begin_proc)pDevice->pContext->alsa.snd_pcm_mmap_begin)((ma_snd_pcm_t*)pDevice->alsa.pPCM, &pAreas, &mappedOffset, &mappedFrames); if (result < 0) { return MA_FALSE; } if (mappedFrames > 0) { - void* pBuffer = (mal_uint8*)pAreas[0].addr + ((pAreas[0].first + (mappedOffset * pAreas[0].step)) / 8); - mal_device__send_frames_to_client(pDevice, mappedFrames, pBuffer); + void* pBuffer = (ma_uint8*)pAreas[0].addr + ((pAreas[0].first + (mappedOffset * pAreas[0].step)) / 8); + ma_device__send_frames_to_client(pDevice, mappedFrames, pBuffer); } - result = ((mal_snd_pcm_mmap_commit_proc)pDevice->pContext->alsa.snd_pcm_mmap_commit)((mal_snd_pcm_t*)pDevice->alsa.pPCM, mappedOffset, mappedFrames); - if (result < 0 || (mal_snd_pcm_uframes_t)result != mappedFrames) { - ((mal_snd_pcm_recover_proc)pDevice->pContext->alsa.snd_pcm_recover)((mal_snd_pcm_t*)pDevice->alsa.pPCM, result, MA_TRUE); + result = ((ma_snd_pcm_mmap_commit_proc)pDevice->pContext->alsa.snd_pcm_mmap_commit)((ma_snd_pcm_t*)pDevice->alsa.pPCM, mappedOffset, mappedFrames); + if (result < 0 || (ma_snd_pcm_uframes_t)result != mappedFrames) { + ((ma_snd_pcm_recover_proc)pDevice->pContext->alsa.snd_pcm_recover)((ma_snd_pcm_t*)pDevice->alsa.pPCM, result, MA_TRUE); return MA_FALSE; } if (requiresRestart) { - if (((mal_snd_pcm_start_proc)pDevice->pContext->alsa.snd_pcm_start)((mal_snd_pcm_t*)pDevice->alsa.pPCM) < 0) { + if (((ma_snd_pcm_start_proc)pDevice->pContext->alsa.snd_pcm_start)((ma_snd_pcm_t*)pDevice->alsa.pPCM) < 0) { return MA_FALSE; } } @@ -12158,27 +12158,27 @@ mal_bool32 mal_device_read_and_send_to_client__alsa(mal_device* pDevice) } } else { // readi/writei. - mal_snd_pcm_sframes_t framesRead = 0; + ma_snd_pcm_sframes_t framesRead = 0; while (!pDevice->alsa.breakFromMainLoop) { - mal_uint32 framesAvailable = mal_device__wait_for_frames__alsa(pDevice, NULL); + ma_uint32 framesAvailable = ma_device__wait_for_frames__alsa(pDevice, NULL); if (framesAvailable == 0) { continue; } - framesRead = ((mal_snd_pcm_readi_proc)pDevice->pContext->alsa.snd_pcm_readi)((mal_snd_pcm_t*)pDevice->alsa.pPCM, pDevice->alsa.pIntermediaryBuffer, framesAvailable); + framesRead = ((ma_snd_pcm_readi_proc)pDevice->pContext->alsa.snd_pcm_readi)((ma_snd_pcm_t*)pDevice->alsa.pPCM, pDevice->alsa.pIntermediaryBuffer, framesAvailable); if (framesRead < 0) { if (framesRead == -EAGAIN) { continue; // Just keep trying... } else if (framesRead == -EPIPE) { // Overrun. Just recover and try reading again. - if (((mal_snd_pcm_recover_proc)pDevice->pContext->alsa.snd_pcm_recover)((mal_snd_pcm_t*)pDevice->alsa.pPCM, framesRead, MA_TRUE) < 0) { - mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to recover device after overrun.", MA_FAILED_TO_START_BACKEND_DEVICE); + if (((ma_snd_pcm_recover_proc)pDevice->pContext->alsa.snd_pcm_recover)((ma_snd_pcm_t*)pDevice->alsa.pPCM, framesRead, MA_TRUE) < 0) { + ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to recover device after overrun.", MA_FAILED_TO_START_BACKEND_DEVICE); return MA_FALSE; } - framesRead = ((mal_snd_pcm_readi_proc)pDevice->pContext->alsa.snd_pcm_readi)((mal_snd_pcm_t*)pDevice->alsa.pPCM, pDevice->alsa.pIntermediaryBuffer, framesAvailable); + framesRead = ((ma_snd_pcm_readi_proc)pDevice->pContext->alsa.snd_pcm_readi)((ma_snd_pcm_t*)pDevice->alsa.pPCM, pDevice->alsa.pIntermediaryBuffer, framesAvailable); if (framesRead < 0) { - mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to read data from the internal device.", MA_FAILED_TO_READ_DATA_FROM_DEVICE); + ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to read data from the internal device.", MA_FAILED_TO_READ_DATA_FROM_DEVICE); return MA_FALSE; } @@ -12196,54 +12196,54 @@ mal_bool32 mal_device_read_and_send_to_client__alsa(mal_device* pDevice) } if (framesToSend > 0) { - mal_device__send_frames_to_client(pDevice, framesToSend, pBuffer); + ma_device__send_frames_to_client(pDevice, framesToSend, pBuffer); } return MA_TRUE; } #endif -void mal_device_uninit__alsa(mal_device* pDevice) +void ma_device_uninit__alsa(ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); - if ((mal_snd_pcm_t*)pDevice->alsa.pPCMCapture) { - ((mal_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)((mal_snd_pcm_t*)pDevice->alsa.pPCMCapture); + if ((ma_snd_pcm_t*)pDevice->alsa.pPCMCapture) { + ((ma_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)((ma_snd_pcm_t*)pDevice->alsa.pPCMCapture); } - if ((mal_snd_pcm_t*)pDevice->alsa.pPCMPlayback) { - ((mal_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)((mal_snd_pcm_t*)pDevice->alsa.pPCMPlayback); + if ((ma_snd_pcm_t*)pDevice->alsa.pPCMPlayback) { + ((ma_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)((ma_snd_pcm_t*)pDevice->alsa.pPCMPlayback); } } -mal_result mal_device_init_by_type__alsa(mal_context* pContext, const mal_device_config* pConfig, mal_device_type deviceType, mal_device* pDevice) +ma_result ma_device_init_by_type__alsa(ma_context* pContext, const ma_device_config* pConfig, ma_device_type deviceType, ma_device* pDevice) { - mal_result result; - mal_snd_pcm_t* pPCM; - mal_bool32 isUsingMMap; - mal_snd_pcm_format_t formatALSA; - mal_share_mode shareMode; - mal_device_id* pDeviceID; - mal_format internalFormat; - mal_uint32 internalChannels; - mal_uint32 internalSampleRate; - mal_channel internalChannelMap[MA_MAX_CHANNELS]; - mal_uint32 internalBufferSizeInFrames; - mal_uint32 internalPeriods; - mal_snd_pcm_hw_params_t* pHWParams; - mal_snd_pcm_sw_params_t* pSWParams; - mal_snd_pcm_uframes_t bufferBoundary; + ma_result result; + ma_snd_pcm_t* pPCM; + ma_bool32 isUsingMMap; + ma_snd_pcm_format_t formatALSA; + ma_share_mode shareMode; + ma_device_id* pDeviceID; + ma_format internalFormat; + ma_uint32 internalChannels; + ma_uint32 internalSampleRate; + ma_channel internalChannelMap[MA_MAX_CHANNELS]; + ma_uint32 internalBufferSizeInFrames; + ma_uint32 internalPeriods; + ma_snd_pcm_hw_params_t* pHWParams; + ma_snd_pcm_sw_params_t* pSWParams; + ma_snd_pcm_uframes_t bufferBoundary; - mal_assert(pContext != NULL); - mal_assert(pConfig != NULL); - mal_assert(deviceType != mal_device_type_duplex); /* This function should only be called for playback _or_ capture, never duplex. */ - mal_assert(pDevice != NULL); + ma_assert(pContext != NULL); + ma_assert(pConfig != NULL); + ma_assert(deviceType != ma_device_type_duplex); /* This function should only be called for playback _or_ capture, never duplex. */ + ma_assert(pDevice != NULL); - formatALSA = mal_convert_mal_format_to_alsa_format((deviceType == mal_device_type_capture) ? pConfig->capture.format : pConfig->playback.format); - shareMode = (deviceType == mal_device_type_capture) ? pConfig->capture.shareMode : pConfig->playback.shareMode; - pDeviceID = (deviceType == mal_device_type_capture) ? pConfig->capture.pDeviceID : pConfig->playback.pDeviceID; + formatALSA = ma_convert_ma_format_to_alsa_format((deviceType == ma_device_type_capture) ? pConfig->capture.format : pConfig->playback.format); + shareMode = (deviceType == ma_device_type_capture) ? pConfig->capture.shareMode : pConfig->playback.shareMode; + pDeviceID = (deviceType == ma_device_type_capture) ? pConfig->capture.pDeviceID : pConfig->playback.pDeviceID; - result = mal_context_open_pcm__alsa(pContext, shareMode, deviceType, pDeviceID, &pPCM); + result = ma_context_open_pcm__alsa(pContext, shareMode, deviceType, pDeviceID, &pPCM); if (result != MA_SUCCESS) { return result; } @@ -12251,33 +12251,33 @@ mal_result mal_device_init_by_type__alsa(mal_context* pContext, const mal_device /* If using the default buffer size we may want to apply some device-specific scaling for known devices that have peculiar latency characteristics */ float bufferSizeScaleFactor = 1; if (pDevice->usingDefaultBufferSize) { - mal_snd_pcm_info_t* pInfo = (mal_snd_pcm_info_t*)alloca(((mal_snd_pcm_info_sizeof_proc)pContext->alsa.snd_pcm_info_sizeof)()); - mal_zero_memory(pInfo, ((mal_snd_pcm_info_sizeof_proc)pContext->alsa.snd_pcm_info_sizeof)()); + ma_snd_pcm_info_t* pInfo = (ma_snd_pcm_info_t*)alloca(((ma_snd_pcm_info_sizeof_proc)pContext->alsa.snd_pcm_info_sizeof)()); + ma_zero_memory(pInfo, ((ma_snd_pcm_info_sizeof_proc)pContext->alsa.snd_pcm_info_sizeof)()); /* We may need to scale the size of the buffer depending on the device. */ - if (((mal_snd_pcm_info_proc)pContext->alsa.snd_pcm_info)(pPCM, pInfo) == 0) { - const char* deviceName = ((mal_snd_pcm_info_get_name_proc)pContext->alsa.snd_pcm_info_get_name)(pInfo); + if (((ma_snd_pcm_info_proc)pContext->alsa.snd_pcm_info)(pPCM, pInfo) == 0) { + const char* deviceName = ((ma_snd_pcm_info_get_name_proc)pContext->alsa.snd_pcm_info_get_name)(pInfo); if (deviceName != NULL) { - if (mal_strcmp(deviceName, "default") == 0) { + if (ma_strcmp(deviceName, "default") == 0) { char** ppDeviceHints; char** ppNextDeviceHint; /* It's the default device. We need to use DESC from snd_device_name_hint(). */ - if (((mal_snd_device_name_hint_proc)pContext->alsa.snd_device_name_hint)(-1, "pcm", (void***)&ppDeviceHints) < 0) { + if (((ma_snd_device_name_hint_proc)pContext->alsa.snd_device_name_hint)(-1, "pcm", (void***)&ppDeviceHints) < 0) { return MA_NO_BACKEND; } ppNextDeviceHint = ppDeviceHints; while (*ppNextDeviceHint != NULL) { - char* NAME = ((mal_snd_device_name_get_hint_proc)pContext->alsa.snd_device_name_get_hint)(*ppNextDeviceHint, "NAME"); - char* DESC = ((mal_snd_device_name_get_hint_proc)pContext->alsa.snd_device_name_get_hint)(*ppNextDeviceHint, "DESC"); - char* IOID = ((mal_snd_device_name_get_hint_proc)pContext->alsa.snd_device_name_get_hint)(*ppNextDeviceHint, "IOID"); + char* NAME = ((ma_snd_device_name_get_hint_proc)pContext->alsa.snd_device_name_get_hint)(*ppNextDeviceHint, "NAME"); + char* DESC = ((ma_snd_device_name_get_hint_proc)pContext->alsa.snd_device_name_get_hint)(*ppNextDeviceHint, "DESC"); + char* IOID = ((ma_snd_device_name_get_hint_proc)pContext->alsa.snd_device_name_get_hint)(*ppNextDeviceHint, "IOID"); - mal_bool32 foundDevice = MA_FALSE; - if ((deviceType == mal_device_type_playback && (IOID == NULL || mal_strcmp(IOID, "Output") == 0)) || - (deviceType == mal_device_type_capture && (IOID != NULL && mal_strcmp(IOID, "Input" ) == 0))) { - if (mal_strcmp(NAME, deviceName) == 0) { - bufferSizeScaleFactor = mal_find_default_buffer_size_scale__alsa(DESC); + ma_bool32 foundDevice = MA_FALSE; + if ((deviceType == ma_device_type_playback && (IOID == NULL || ma_strcmp(IOID, "Output") == 0)) || + (deviceType == ma_device_type_capture && (IOID != NULL && ma_strcmp(IOID, "Input" ) == 0))) { + if (ma_strcmp(NAME, deviceName) == 0) { + bufferSizeScaleFactor = ma_find_default_buffer_size_scale__alsa(DESC); foundDevice = MA_TRUE; } } @@ -12292,9 +12292,9 @@ mal_result mal_device_init_by_type__alsa(mal_context* pContext, const mal_device } } - ((mal_snd_device_name_free_hint_proc)pContext->alsa.snd_device_name_free_hint)((void**)ppDeviceHints); + ((ma_snd_device_name_free_hint_proc)pContext->alsa.snd_device_name_free_hint)((void**)ppDeviceHints); } else { - bufferSizeScaleFactor = mal_find_default_buffer_size_scale__alsa(deviceName); + bufferSizeScaleFactor = ma_find_default_buffer_size_scale__alsa(deviceName); } } } @@ -12302,20 +12302,20 @@ mal_result mal_device_init_by_type__alsa(mal_context* pContext, const mal_device /* Hardware parameters. */ - pHWParams = (mal_snd_pcm_hw_params_t*)alloca(((mal_snd_pcm_hw_params_sizeof_proc)pContext->alsa.snd_pcm_hw_params_sizeof)()); - mal_zero_memory(pHWParams, ((mal_snd_pcm_hw_params_sizeof_proc)pContext->alsa.snd_pcm_hw_params_sizeof)()); + pHWParams = (ma_snd_pcm_hw_params_t*)alloca(((ma_snd_pcm_hw_params_sizeof_proc)pContext->alsa.snd_pcm_hw_params_sizeof)()); + ma_zero_memory(pHWParams, ((ma_snd_pcm_hw_params_sizeof_proc)pContext->alsa.snd_pcm_hw_params_sizeof)()); - if (((mal_snd_pcm_hw_params_any_proc)pContext->alsa.snd_pcm_hw_params_any)(pPCM, pHWParams) < 0) { - ((mal_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)(pPCM); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to initialize hardware parameters. snd_pcm_hw_params_any() failed.", MA_FAILED_TO_CONFIGURE_BACKEND_DEVICE); + if (((ma_snd_pcm_hw_params_any_proc)pContext->alsa.snd_pcm_hw_params_any)(pPCM, pHWParams) < 0) { + ((ma_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)(pPCM); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to initialize hardware parameters. snd_pcm_hw_params_any() failed.", MA_FAILED_TO_CONFIGURE_BACKEND_DEVICE); } /* MMAP Mode. Try using interleaved MMAP access. If this fails, fall back to standard readi/writei. */ isUsingMMap = MA_FALSE; #if 0 /* NOTE: MMAP mode temporarily disabled. */ - if (deviceType != mal_device_type_capture) { /* <-- Disabling MMAP mode for capture devices because I apparently do not have a device that supports it which means I can't test it... Contributions welcome. */ - if (!pConfig->alsa.noMMap && mal_device__is_async(pDevice)) { - if (((mal_snd_pcm_hw_params_set_access_proc)pContext->alsa.snd_pcm_hw_params_set_access)(pPCM, pHWParams, MA_SND_PCM_ACCESS_MMAP_INTERLEAVED) == 0) { + if (deviceType != ma_device_type_capture) { /* <-- Disabling MMAP mode for capture devices because I apparently do not have a device that supports it which means I can't test it... Contributions welcome. */ + if (!pConfig->alsa.noMMap && ma_device__is_async(pDevice)) { + if (((ma_snd_pcm_hw_params_set_access_proc)pContext->alsa.snd_pcm_hw_params_set_access)(pPCM, pHWParams, MA_SND_PCM_ACCESS_MMAP_INTERLEAVED) == 0) { pDevice->alsa.isUsingMMap = MA_TRUE; } } @@ -12323,9 +12323,9 @@ mal_result mal_device_init_by_type__alsa(mal_context* pContext, const mal_device #endif if (!isUsingMMap) { - if (((mal_snd_pcm_hw_params_set_access_proc)pContext->alsa.snd_pcm_hw_params_set_access)(pPCM, pHWParams, MA_SND_PCM_ACCESS_RW_INTERLEAVED) < 0) {; - ((mal_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)(pPCM); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to set access mode to neither SND_PCM_ACCESS_MMAP_INTERLEAVED nor SND_PCM_ACCESS_RW_INTERLEAVED. snd_pcm_hw_params_set_access() failed.", MA_FORMAT_NOT_SUPPORTED); + if (((ma_snd_pcm_hw_params_set_access_proc)pContext->alsa.snd_pcm_hw_params_set_access)(pPCM, pHWParams, MA_SND_PCM_ACCESS_RW_INTERLEAVED) < 0) {; + ((ma_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)(pPCM); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to set access mode to neither SND_PCM_ACCESS_MMAP_INTERLEAVED nor SND_PCM_ACCESS_RW_INTERLEAVED. snd_pcm_hw_params_set_access() failed.", MA_FORMAT_NOT_SUPPORTED); } } @@ -12336,29 +12336,29 @@ mal_result mal_device_init_by_type__alsa(mal_context* pContext, const mal_device /* Format. */ { - mal_snd_pcm_format_mask_t* pFormatMask; + ma_snd_pcm_format_mask_t* pFormatMask; /* Try getting every supported format first. */ - pFormatMask = (mal_snd_pcm_format_mask_t*)alloca(((mal_snd_pcm_format_mask_sizeof_proc)pContext->alsa.snd_pcm_format_mask_sizeof)()); - mal_zero_memory(pFormatMask, ((mal_snd_pcm_format_mask_sizeof_proc)pContext->alsa.snd_pcm_format_mask_sizeof)()); + pFormatMask = (ma_snd_pcm_format_mask_t*)alloca(((ma_snd_pcm_format_mask_sizeof_proc)pContext->alsa.snd_pcm_format_mask_sizeof)()); + ma_zero_memory(pFormatMask, ((ma_snd_pcm_format_mask_sizeof_proc)pContext->alsa.snd_pcm_format_mask_sizeof)()); - ((mal_snd_pcm_hw_params_get_format_mask_proc)pContext->alsa.snd_pcm_hw_params_get_format_mask)(pHWParams, pFormatMask); + ((ma_snd_pcm_hw_params_get_format_mask_proc)pContext->alsa.snd_pcm_hw_params_get_format_mask)(pHWParams, pFormatMask); /* At this point we should have a list of supported formats, so now we need to find the best one. We first check if the requested format is supported, and if so, use that one. If it's not supported, we just run though a list of formats and try to find the best one. */ - if (!((mal_snd_pcm_format_mask_test_proc)pContext->alsa.snd_pcm_format_mask_test)(pFormatMask, formatALSA)) { + if (!((ma_snd_pcm_format_mask_test_proc)pContext->alsa.snd_pcm_format_mask_test)(pFormatMask, formatALSA)) { /* The requested format is not supported so now try running through the list of formats and return the best one. */ - mal_snd_pcm_format_t preferredFormatsALSA[] = { - MA_SND_PCM_FORMAT_S16_LE, /* mal_format_s16 */ - MA_SND_PCM_FORMAT_FLOAT_LE, /* mal_format_f32 */ - MA_SND_PCM_FORMAT_S32_LE, /* mal_format_s32 */ - MA_SND_PCM_FORMAT_S24_3LE, /* mal_format_s24 */ - MA_SND_PCM_FORMAT_U8 /* mal_format_u8 */ + ma_snd_pcm_format_t preferredFormatsALSA[] = { + MA_SND_PCM_FORMAT_S16_LE, /* ma_format_s16 */ + MA_SND_PCM_FORMAT_FLOAT_LE, /* ma_format_f32 */ + MA_SND_PCM_FORMAT_S32_LE, /* ma_format_s32 */ + MA_SND_PCM_FORMAT_S24_3LE, /* ma_format_s24 */ + MA_SND_PCM_FORMAT_U8 /* ma_format_u8 */ }; - if (mal_is_big_endian()) { + if (ma_is_big_endian()) { preferredFormatsALSA[0] = MA_SND_PCM_FORMAT_S16_BE; preferredFormatsALSA[1] = MA_SND_PCM_FORMAT_FLOAT_BE; preferredFormatsALSA[2] = MA_SND_PCM_FORMAT_S32_BE; @@ -12368,38 +12368,38 @@ mal_result mal_device_init_by_type__alsa(mal_context* pContext, const mal_device formatALSA = MA_SND_PCM_FORMAT_UNKNOWN; for (size_t i = 0; i < (sizeof(preferredFormatsALSA) / sizeof(preferredFormatsALSA[0])); ++i) { - if (((mal_snd_pcm_format_mask_test_proc)pContext->alsa.snd_pcm_format_mask_test)(pFormatMask, preferredFormatsALSA[i])) { + if (((ma_snd_pcm_format_mask_test_proc)pContext->alsa.snd_pcm_format_mask_test)(pFormatMask, preferredFormatsALSA[i])) { formatALSA = preferredFormatsALSA[i]; break; } } if (formatALSA == MA_SND_PCM_FORMAT_UNKNOWN) { - ((mal_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)(pPCM); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Format not supported. The device does not support any miniaudio formats.", MA_FORMAT_NOT_SUPPORTED); + ((ma_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)(pPCM); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Format not supported. The device does not support any miniaudio formats.", MA_FORMAT_NOT_SUPPORTED); } } - if (((mal_snd_pcm_hw_params_set_format_proc)pContext->alsa.snd_pcm_hw_params_set_format)(pPCM, pHWParams, formatALSA) < 0) { - ((mal_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)(pPCM); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Format not supported. snd_pcm_hw_params_set_format() failed.", MA_FORMAT_NOT_SUPPORTED); + if (((ma_snd_pcm_hw_params_set_format_proc)pContext->alsa.snd_pcm_hw_params_set_format)(pPCM, pHWParams, formatALSA) < 0) { + ((ma_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)(pPCM); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Format not supported. snd_pcm_hw_params_set_format() failed.", MA_FORMAT_NOT_SUPPORTED); } - internalFormat = mal_convert_alsa_format_to_mal_format(formatALSA); - if (internalFormat == mal_format_unknown) { - ((mal_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)(pPCM); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] The chosen format is not supported by miniaudio.", MA_FORMAT_NOT_SUPPORTED); + internalFormat = ma_convert_alsa_format_to_ma_format(formatALSA); + if (internalFormat == ma_format_unknown) { + ((ma_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)(pPCM); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] The chosen format is not supported by miniaudio.", MA_FORMAT_NOT_SUPPORTED); } } /* Channels. */ { - unsigned int channels = (deviceType == mal_device_type_capture) ? pConfig->capture.channels : pConfig->playback.channels; - if (((mal_snd_pcm_hw_params_set_channels_near_proc)pContext->alsa.snd_pcm_hw_params_set_channels_near)(pPCM, pHWParams, &channels) < 0) { - ((mal_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)(pPCM); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to set channel count. snd_pcm_hw_params_set_channels_near() failed.", MA_FORMAT_NOT_SUPPORTED); + unsigned int channels = (deviceType == ma_device_type_capture) ? pConfig->capture.channels : pConfig->playback.channels; + if (((ma_snd_pcm_hw_params_set_channels_near_proc)pContext->alsa.snd_pcm_hw_params_set_channels_near)(pPCM, pHWParams, &channels) < 0) { + ((ma_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)(pPCM); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to set channel count. snd_pcm_hw_params_set_channels_near() failed.", MA_FORMAT_NOT_SUPPORTED); } - internalChannels = (mal_uint32)channels; + internalChannels = (ma_uint32)channels; } /* Sample Rate */ @@ -12423,124 +12423,124 @@ mal_result mal_device_init_by_type__alsa(mal_context* pContext, const mal_device I don't currently know if the dmix plugin is the only one with this error. Indeed, this is the only one I've been able to reproduce this error with. In the future, we may want to restrict the disabling of resampling to only known bad plugins. */ - ((mal_snd_pcm_hw_params_set_rate_resample_proc)pContext->alsa.snd_pcm_hw_params_set_rate_resample)(pPCM, pHWParams, 0); + ((ma_snd_pcm_hw_params_set_rate_resample_proc)pContext->alsa.snd_pcm_hw_params_set_rate_resample)(pPCM, pHWParams, 0); sampleRate = pConfig->sampleRate; - if (((mal_snd_pcm_hw_params_set_rate_near_proc)pContext->alsa.snd_pcm_hw_params_set_rate_near)(pPCM, pHWParams, &sampleRate, 0) < 0) { - ((mal_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)(pPCM); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Sample rate not supported. snd_pcm_hw_params_set_rate_near() failed.", MA_FORMAT_NOT_SUPPORTED); + if (((ma_snd_pcm_hw_params_set_rate_near_proc)pContext->alsa.snd_pcm_hw_params_set_rate_near)(pPCM, pHWParams, &sampleRate, 0) < 0) { + ((ma_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)(pPCM); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Sample rate not supported. snd_pcm_hw_params_set_rate_near() failed.", MA_FORMAT_NOT_SUPPORTED); } - internalSampleRate = (mal_uint32)sampleRate; + internalSampleRate = (ma_uint32)sampleRate; } /* Buffer Size */ { - mal_snd_pcm_uframes_t actualBufferSizeInFrames = pConfig->bufferSizeInFrames; + ma_snd_pcm_uframes_t actualBufferSizeInFrames = pConfig->bufferSizeInFrames; if (actualBufferSizeInFrames == 0) { - actualBufferSizeInFrames = mal_scale_buffer_size(mal_calculate_buffer_size_in_frames_from_milliseconds(pConfig->bufferSizeInMilliseconds, internalSampleRate), bufferSizeScaleFactor); + actualBufferSizeInFrames = ma_scale_buffer_size(ma_calculate_buffer_size_in_frames_from_milliseconds(pConfig->bufferSizeInMilliseconds, internalSampleRate), bufferSizeScaleFactor); } - if (((mal_snd_pcm_hw_params_set_buffer_size_near_proc)pContext->alsa.snd_pcm_hw_params_set_buffer_size_near)(pPCM, pHWParams, &actualBufferSizeInFrames) < 0) { - ((mal_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)(pPCM); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to set buffer size for device. snd_pcm_hw_params_set_buffer_size() failed.", MA_FORMAT_NOT_SUPPORTED); + if (((ma_snd_pcm_hw_params_set_buffer_size_near_proc)pContext->alsa.snd_pcm_hw_params_set_buffer_size_near)(pPCM, pHWParams, &actualBufferSizeInFrames) < 0) { + ((ma_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)(pPCM); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to set buffer size for device. snd_pcm_hw_params_set_buffer_size() failed.", MA_FORMAT_NOT_SUPPORTED); } internalBufferSizeInFrames = actualBufferSizeInFrames; } /* Periods. */ { - mal_uint32 periods = pConfig->periods; - if (((mal_snd_pcm_hw_params_set_periods_near_proc)pContext->alsa.snd_pcm_hw_params_set_periods_near)(pPCM, pHWParams, &periods, NULL) < 0) { - ((mal_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)(pPCM); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to set period count. snd_pcm_hw_params_set_periods_near() failed.", MA_FORMAT_NOT_SUPPORTED); + ma_uint32 periods = pConfig->periods; + if (((ma_snd_pcm_hw_params_set_periods_near_proc)pContext->alsa.snd_pcm_hw_params_set_periods_near)(pPCM, pHWParams, &periods, NULL) < 0) { + ((ma_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)(pPCM); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to set period count. snd_pcm_hw_params_set_periods_near() failed.", MA_FORMAT_NOT_SUPPORTED); } internalPeriods = periods; } /* Apply hardware parameters. */ - if (((mal_snd_pcm_hw_params_proc)pContext->alsa.snd_pcm_hw_params)(pPCM, pHWParams) < 0) { - ((mal_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)(pPCM); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to set hardware parameters. snd_pcm_hw_params() failed.", MA_FAILED_TO_CONFIGURE_BACKEND_DEVICE); + if (((ma_snd_pcm_hw_params_proc)pContext->alsa.snd_pcm_hw_params)(pPCM, pHWParams) < 0) { + ((ma_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)(pPCM); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to set hardware parameters. snd_pcm_hw_params() failed.", MA_FAILED_TO_CONFIGURE_BACKEND_DEVICE); } /* Software parameters. */ - pSWParams = (mal_snd_pcm_sw_params_t*)alloca(((mal_snd_pcm_sw_params_sizeof_proc)pContext->alsa.snd_pcm_sw_params_sizeof)()); - mal_zero_memory(pSWParams, ((mal_snd_pcm_sw_params_sizeof_proc)pContext->alsa.snd_pcm_sw_params_sizeof)()); + pSWParams = (ma_snd_pcm_sw_params_t*)alloca(((ma_snd_pcm_sw_params_sizeof_proc)pContext->alsa.snd_pcm_sw_params_sizeof)()); + ma_zero_memory(pSWParams, ((ma_snd_pcm_sw_params_sizeof_proc)pContext->alsa.snd_pcm_sw_params_sizeof)()); - if (((mal_snd_pcm_sw_params_current_proc)pContext->alsa.snd_pcm_sw_params_current)(pPCM, pSWParams) != 0) { - ((mal_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)(pPCM); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to initialize software parameters. snd_pcm_sw_params_current() failed.", MA_FAILED_TO_CONFIGURE_BACKEND_DEVICE); + if (((ma_snd_pcm_sw_params_current_proc)pContext->alsa.snd_pcm_sw_params_current)(pPCM, pSWParams) != 0) { + ((ma_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)(pPCM); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to initialize software parameters. snd_pcm_sw_params_current() failed.", MA_FAILED_TO_CONFIGURE_BACKEND_DEVICE); } - if (deviceType == mal_device_type_capture) { - if (((mal_snd_pcm_sw_params_set_avail_min_proc)pContext->alsa.snd_pcm_sw_params_set_avail_min)(pPCM, pSWParams, 1) != 0) { - ((mal_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)(pPCM); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] snd_pcm_sw_params_set_avail_min() failed.", MA_FORMAT_NOT_SUPPORTED); + if (deviceType == ma_device_type_capture) { + if (((ma_snd_pcm_sw_params_set_avail_min_proc)pContext->alsa.snd_pcm_sw_params_set_avail_min)(pPCM, pSWParams, 1) != 0) { + ((ma_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)(pPCM); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] snd_pcm_sw_params_set_avail_min() failed.", MA_FORMAT_NOT_SUPPORTED); } } else { - if (((mal_snd_pcm_sw_params_set_avail_min_proc)pContext->alsa.snd_pcm_sw_params_set_avail_min)(pPCM, pSWParams, 1) != 0) { - ((mal_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)(pPCM); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] snd_pcm_sw_params_set_avail_min() failed.", MA_FORMAT_NOT_SUPPORTED); + if (((ma_snd_pcm_sw_params_set_avail_min_proc)pContext->alsa.snd_pcm_sw_params_set_avail_min)(pPCM, pSWParams, 1) != 0) { + ((ma_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)(pPCM); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] snd_pcm_sw_params_set_avail_min() failed.", MA_FORMAT_NOT_SUPPORTED); } } - if (((mal_snd_pcm_sw_params_get_boundary_proc)pContext->alsa.snd_pcm_sw_params_get_boundary)(pSWParams, &bufferBoundary) < 0) { + if (((ma_snd_pcm_sw_params_get_boundary_proc)pContext->alsa.snd_pcm_sw_params_get_boundary)(pSWParams, &bufferBoundary) < 0) { bufferBoundary = internalBufferSizeInFrames; } //printf("TRACE: bufferBoundary=%ld\n", bufferBoundary); - if (deviceType == mal_device_type_playback && !isUsingMMap) { /* Only playback devices in writei/readi mode need a start threshold. */ + if (deviceType == ma_device_type_playback && !isUsingMMap) { /* Only playback devices in writei/readi mode need a start threshold. */ /* Subtle detail here with the start threshold. When in playback-only mode (no full-duplex) we can set the start threshold to the size of a period. But for full-duplex we need to set it such that it is at least two periods. */ - if (((mal_snd_pcm_sw_params_set_start_threshold_proc)pContext->alsa.snd_pcm_sw_params_set_start_threshold)(pPCM, pSWParams, internalBufferSizeInFrames) != 0) { - ((mal_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)(pPCM); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to set start threshold for playback device. snd_pcm_sw_params_set_start_threshold() failed.", MA_FAILED_TO_CONFIGURE_BACKEND_DEVICE); + if (((ma_snd_pcm_sw_params_set_start_threshold_proc)pContext->alsa.snd_pcm_sw_params_set_start_threshold)(pPCM, pSWParams, internalBufferSizeInFrames) != 0) { + ((ma_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)(pPCM); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to set start threshold for playback device. snd_pcm_sw_params_set_start_threshold() failed.", MA_FAILED_TO_CONFIGURE_BACKEND_DEVICE); } - if (((mal_snd_pcm_sw_params_set_stop_threshold_proc)pContext->alsa.snd_pcm_sw_params_set_stop_threshold)(pPCM, pSWParams, bufferBoundary) != 0) { /* Set to boundary to loop instead of stop in the event of an xrun. */ - ((mal_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)(pPCM); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to set stop threshold for playback device. snd_pcm_sw_params_set_stop_threshold() failed.", MA_FAILED_TO_CONFIGURE_BACKEND_DEVICE); + if (((ma_snd_pcm_sw_params_set_stop_threshold_proc)pContext->alsa.snd_pcm_sw_params_set_stop_threshold)(pPCM, pSWParams, bufferBoundary) != 0) { /* Set to boundary to loop instead of stop in the event of an xrun. */ + ((ma_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)(pPCM); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to set stop threshold for playback device. snd_pcm_sw_params_set_stop_threshold() failed.", MA_FAILED_TO_CONFIGURE_BACKEND_DEVICE); } } - if (((mal_snd_pcm_sw_params_proc)pContext->alsa.snd_pcm_sw_params)(pPCM, pSWParams) != 0) { - ((mal_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)(pPCM); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to set software parameters. snd_pcm_sw_params() failed.", MA_FAILED_TO_CONFIGURE_BACKEND_DEVICE); + if (((ma_snd_pcm_sw_params_proc)pContext->alsa.snd_pcm_sw_params)(pPCM, pSWParams) != 0) { + ((ma_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)(pPCM); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to set software parameters. snd_pcm_sw_params() failed.", MA_FAILED_TO_CONFIGURE_BACKEND_DEVICE); } /* Grab the internal channel map. For now we're not going to bother trying to change the channel map and instead just do it ourselves. */ { - mal_snd_pcm_chmap_t* pChmap = ((mal_snd_pcm_get_chmap_proc)pContext->alsa.snd_pcm_get_chmap)(pPCM); + ma_snd_pcm_chmap_t* pChmap = ((ma_snd_pcm_get_chmap_proc)pContext->alsa.snd_pcm_get_chmap)(pPCM); if (pChmap != NULL) { /* There are cases where the returned channel map can have a different channel count than was returned by snd_pcm_hw_params_set_channels_near(). */ if (pChmap->channels >= internalChannels) { /* Drop excess channels. */ - for (mal_uint32 iChannel = 0; iChannel < internalChannels; ++iChannel) { - internalChannelMap[iChannel] = mal_convert_alsa_channel_position_to_mal_channel(pChmap->pos[iChannel]); + for (ma_uint32 iChannel = 0; iChannel < internalChannels; ++iChannel) { + internalChannelMap[iChannel] = ma_convert_alsa_channel_position_to_ma_channel(pChmap->pos[iChannel]); } } else { /* Excess channels use defaults. Do an initial fill with defaults, overwrite the first pChmap->channels, validate to ensure there are no duplicate channels. If validation fails, fall back to defaults. */ - mal_bool32 isValid = MA_TRUE; + ma_bool32 isValid = MA_TRUE; /* Fill with defaults. */ - mal_get_standard_channel_map(mal_standard_channel_map_alsa, internalChannels, internalChannelMap); + ma_get_standard_channel_map(ma_standard_channel_map_alsa, internalChannels, internalChannelMap); /* Overwrite first pChmap->channels channels. */ - for (mal_uint32 iChannel = 0; iChannel < pChmap->channels; ++iChannel) { - internalChannelMap[iChannel] = mal_convert_alsa_channel_position_to_mal_channel(pChmap->pos[iChannel]); + for (ma_uint32 iChannel = 0; iChannel < pChmap->channels; ++iChannel) { + internalChannelMap[iChannel] = ma_convert_alsa_channel_position_to_ma_channel(pChmap->pos[iChannel]); } /* Validate. */ - for (mal_uint32 i = 0; i < internalChannels && isValid; ++i) { - for (mal_uint32 j = i+1; j < internalChannels; ++j) { + for (ma_uint32 i = 0; i < internalChannels && isValid; ++i) { + for (ma_uint32 j = i+1; j < internalChannels; ++j) { if (internalChannelMap[i] == internalChannelMap[j]) { isValid = MA_FALSE; break; @@ -12550,7 +12550,7 @@ mal_result mal_device_init_by_type__alsa(mal_context* pContext, const mal_device /* If our channel map is invalid, fall back to defaults. */ if (!isValid) { - mal_get_standard_channel_map(mal_standard_channel_map_alsa, internalChannels, internalChannelMap); + ma_get_standard_channel_map(ma_standard_channel_map_alsa, internalChannels, internalChannelMap); } } @@ -12558,34 +12558,34 @@ mal_result mal_device_init_by_type__alsa(mal_context* pContext, const mal_device pChmap = NULL; } else { /* Could not retrieve the channel map. Fall back to a hard-coded assumption. */ - mal_get_standard_channel_map(mal_standard_channel_map_alsa, internalChannels, internalChannelMap); + ma_get_standard_channel_map(ma_standard_channel_map_alsa, internalChannels, internalChannelMap); } } /* We're done. Prepare the device. */ - if (((mal_snd_pcm_prepare_proc)pDevice->pContext->alsa.snd_pcm_prepare)(pPCM) < 0) { - ((mal_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)(pPCM); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to prepare device.", MA_FAILED_TO_START_BACKEND_DEVICE); + if (((ma_snd_pcm_prepare_proc)pDevice->pContext->alsa.snd_pcm_prepare)(pPCM) < 0) { + ((ma_snd_pcm_close_proc)pDevice->pContext->alsa.snd_pcm_close)(pPCM); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to prepare device.", MA_FAILED_TO_START_BACKEND_DEVICE); } - if (deviceType == mal_device_type_capture) { - pDevice->alsa.pPCMCapture = (mal_ptr)pPCM; + if (deviceType == ma_device_type_capture) { + pDevice->alsa.pPCMCapture = (ma_ptr)pPCM; pDevice->alsa.isUsingMMapCapture = isUsingMMap; pDevice->capture.internalFormat = internalFormat; pDevice->capture.internalChannels = internalChannels; pDevice->capture.internalSampleRate = internalSampleRate; - mal_channel_map_copy(pDevice->capture.internalChannelMap, internalChannelMap, internalChannels); + ma_channel_map_copy(pDevice->capture.internalChannelMap, internalChannelMap, internalChannels); pDevice->capture.internalBufferSizeInFrames = internalBufferSizeInFrames; pDevice->capture.internalPeriods = internalPeriods; } else { - pDevice->alsa.pPCMPlayback = (mal_ptr)pPCM; + pDevice->alsa.pPCMPlayback = (ma_ptr)pPCM; pDevice->alsa.isUsingMMapPlayback = isUsingMMap; pDevice->playback.internalFormat = internalFormat; pDevice->playback.internalChannels = internalChannels; pDevice->playback.internalSampleRate = internalSampleRate; - mal_channel_map_copy(pDevice->playback.internalChannelMap, internalChannelMap, internalChannels); + ma_channel_map_copy(pDevice->playback.internalChannelMap, internalChannelMap, internalChannels); pDevice->playback.internalBufferSizeInFrames = internalBufferSizeInFrames; pDevice->playback.internalPeriods = internalPeriods; } @@ -12593,21 +12593,21 @@ mal_result mal_device_init_by_type__alsa(mal_context* pContext, const mal_device return MA_SUCCESS; } -mal_result mal_device_init__alsa(mal_context* pContext, const mal_device_config* pConfig, mal_device* pDevice) +ma_result ma_device_init__alsa(ma_context* pContext, const ma_device_config* pConfig, ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); - mal_zero_object(&pDevice->alsa); + ma_zero_object(&pDevice->alsa); - if (pConfig->deviceType == mal_device_type_capture || pConfig->deviceType == mal_device_type_duplex) { - mal_result result = mal_device_init_by_type__alsa(pContext, pConfig, mal_device_type_capture, pDevice); + if (pConfig->deviceType == ma_device_type_capture || pConfig->deviceType == ma_device_type_duplex) { + ma_result result = ma_device_init_by_type__alsa(pContext, pConfig, ma_device_type_capture, pDevice); if (result != MA_SUCCESS) { return result; } } - if (pConfig->deviceType == mal_device_type_playback || pConfig->deviceType == mal_device_type_duplex) { - mal_result result = mal_device_init_by_type__alsa(pContext, pConfig, mal_device_type_playback, pDevice); + if (pConfig->deviceType == ma_device_type_playback || pConfig->deviceType == ma_device_type_duplex) { + ma_result result = ma_device_init_by_type__alsa(pContext, pConfig, ma_device_type_playback, pDevice); if (result != MA_SUCCESS) { return result; } @@ -12617,31 +12617,31 @@ mal_result mal_device_init__alsa(mal_context* pContext, const mal_device_config* } #if 0 -mal_result mal_device_start__alsa(mal_device* pDevice) +ma_result ma_device_start__alsa(ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); // Prepare the device first... - if (((mal_snd_pcm_prepare_proc)pDevice->pContext->alsa.snd_pcm_prepare)((mal_snd_pcm_t*)pDevice->alsa.pPCM) < 0) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to prepare device.", MA_FAILED_TO_START_BACKEND_DEVICE); + if (((ma_snd_pcm_prepare_proc)pDevice->pContext->alsa.snd_pcm_prepare)((ma_snd_pcm_t*)pDevice->alsa.pPCM) < 0) { + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to prepare device.", MA_FAILED_TO_START_BACKEND_DEVICE); } // ... and then grab an initial chunk from the client. After this is done, the device should // automatically start playing, since that's how we configured the software parameters. - if (pDevice->type == mal_device_type_playback) { - if (!mal_device_read_from_client_and_write__alsa(pDevice)) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to write initial chunk of data to the playback device.", MA_FAILED_TO_SEND_DATA_TO_DEVICE); + if (pDevice->type == ma_device_type_playback) { + if (!ma_device_read_from_client_and_write__alsa(pDevice)) { + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to write initial chunk of data to the playback device.", MA_FAILED_TO_SEND_DATA_TO_DEVICE); } // mmap mode requires an explicit start. if (pDevice->alsa.isUsingMMap) { - if (((mal_snd_pcm_start_proc)pDevice->pContext->alsa.snd_pcm_start)((mal_snd_pcm_t*)pDevice->alsa.pPCM) < 0) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to start capture device.", MA_FAILED_TO_START_BACKEND_DEVICE); + if (((ma_snd_pcm_start_proc)pDevice->pContext->alsa.snd_pcm_start)((ma_snd_pcm_t*)pDevice->alsa.pPCM) < 0) { + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to start capture device.", MA_FAILED_TO_START_BACKEND_DEVICE); } } } else { - if (((mal_snd_pcm_start_proc)pDevice->pContext->alsa.snd_pcm_start)((mal_snd_pcm_t*)pDevice->alsa.pPCM) < 0) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to start capture device.", MA_FAILED_TO_START_BACKEND_DEVICE); + if (((ma_snd_pcm_start_proc)pDevice->pContext->alsa.snd_pcm_start)((ma_snd_pcm_t*)pDevice->alsa.pPCM) < 0) { + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to start capture device.", MA_FAILED_TO_START_BACKEND_DEVICE); } } @@ -12649,41 +12649,41 @@ mal_result mal_device_start__alsa(mal_device* pDevice) } #endif -mal_result mal_device_stop__alsa(mal_device* pDevice) +ma_result ma_device_stop__alsa(ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { - ((mal_snd_pcm_drain_proc)pDevice->pContext->alsa.snd_pcm_drain)((mal_snd_pcm_t*)pDevice->alsa.pPCMCapture); + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { + ((ma_snd_pcm_drain_proc)pDevice->pContext->alsa.snd_pcm_drain)((ma_snd_pcm_t*)pDevice->alsa.pPCMCapture); } - if (pDevice->type == mal_device_type_playback || pDevice->type == mal_device_type_duplex) { - /* Using drain instead of drop because mal_device_stop() is defined such that pending frames are processed before returning. */ - ((mal_snd_pcm_drain_proc)pDevice->pContext->alsa.snd_pcm_drain)((mal_snd_pcm_t*)pDevice->alsa.pPCMPlayback); + if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) { + /* Using drain instead of drop because ma_device_stop() is defined such that pending frames are processed before returning. */ + ((ma_snd_pcm_drain_proc)pDevice->pContext->alsa.snd_pcm_drain)((ma_snd_pcm_t*)pDevice->alsa.pPCMPlayback); } return MA_SUCCESS; } -mal_result mal_device_write__alsa(mal_device* pDevice, const void* pPCMFrames, mal_uint32 frameCount) +ma_result ma_device_write__alsa(ma_device* pDevice, const void* pPCMFrames, ma_uint32 frameCount) { - mal_snd_pcm_sframes_t resultALSA; - mal_uint32 totalPCMFramesProcessed; + ma_snd_pcm_sframes_t resultALSA; + ma_uint32 totalPCMFramesProcessed; - mal_assert(pDevice != NULL); - mal_assert(pPCMFrames != NULL); + ma_assert(pDevice != NULL); + ma_assert(pPCMFrames != NULL); //printf("TRACE: Enter write()\n"); totalPCMFramesProcessed = 0; while (totalPCMFramesProcessed < frameCount) { - const void* pSrc = mal_offset_ptr(pPCMFrames, totalPCMFramesProcessed * mal_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels)); - mal_uint32 framesRemaining = (frameCount - totalPCMFramesProcessed); + const void* pSrc = ma_offset_ptr(pPCMFrames, totalPCMFramesProcessed * ma_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels)); + ma_uint32 framesRemaining = (frameCount - totalPCMFramesProcessed); //printf("TRACE: Writing %d frames (frameCount=%d)\n", framesRemaining, frameCount); - resultALSA = ((mal_snd_pcm_writei_proc)pDevice->pContext->alsa.snd_pcm_writei)((mal_snd_pcm_t*)pDevice->alsa.pPCMPlayback, pSrc, framesRemaining); + resultALSA = ((ma_snd_pcm_writei_proc)pDevice->pContext->alsa.snd_pcm_writei)((ma_snd_pcm_t*)pDevice->alsa.pPCMPlayback, pSrc, framesRemaining); if (resultALSA < 0) { if (resultALSA == -EAGAIN) { //printf("TRACE: EGAIN (write)\n"); @@ -12692,8 +12692,8 @@ mal_result mal_device_write__alsa(mal_device* pDevice, const void* pPCMFrames, m //printf("TRACE: EPIPE (write)\n"); /* Underrun. Recover and try again. If this fails we need to return an error. */ - if (((mal_snd_pcm_recover_proc)pDevice->pContext->alsa.snd_pcm_recover)((mal_snd_pcm_t*)pDevice->alsa.pPCMPlayback, resultALSA, MA_TRUE) < 0) { /* MA_TRUE=silent (don't print anything on error). */ - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to recover device after underrun.", MA_FAILED_TO_START_BACKEND_DEVICE); + if (((ma_snd_pcm_recover_proc)pDevice->pContext->alsa.snd_pcm_recover)((ma_snd_pcm_t*)pDevice->alsa.pPCMPlayback, resultALSA, MA_TRUE) < 0) { /* MA_TRUE=silent (don't print anything on error). */ + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to recover device after underrun.", MA_FAILED_TO_START_BACKEND_DEVICE); } /* @@ -12703,13 +12703,13 @@ mal_result mal_device_write__alsa(mal_device* pDevice, const void* pPCMFrames, m if this is me just being stupid and not recovering the device properly, but this definitely feels like something isn't quite right here. */ - if (((mal_snd_pcm_start_proc)pDevice->pContext->alsa.snd_pcm_start)((mal_snd_pcm_t*)pDevice->alsa.pPCMPlayback) < 0) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to start device after underrun.", MA_FAILED_TO_START_BACKEND_DEVICE); + if (((ma_snd_pcm_start_proc)pDevice->pContext->alsa.snd_pcm_start)((ma_snd_pcm_t*)pDevice->alsa.pPCMPlayback) < 0) { + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to start device after underrun.", MA_FAILED_TO_START_BACKEND_DEVICE); } - resultALSA = ((mal_snd_pcm_writei_proc)pDevice->pContext->alsa.snd_pcm_writei)((mal_snd_pcm_t*)pDevice->alsa.pPCMPlayback, pSrc, framesRemaining); + resultALSA = ((ma_snd_pcm_writei_proc)pDevice->pContext->alsa.snd_pcm_writei)((ma_snd_pcm_t*)pDevice->alsa.pPCMPlayback, pSrc, framesRemaining); if (resultALSA < 0) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to write data to device after underrun.", MA_FAILED_TO_START_BACKEND_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to write data to device after underrun.", MA_FAILED_TO_START_BACKEND_DEVICE); } } } @@ -12720,29 +12720,29 @@ mal_result mal_device_write__alsa(mal_device* pDevice, const void* pPCMFrames, m return MA_SUCCESS; } -mal_result mal_device_read__alsa(mal_device* pDevice, void* pPCMFrames, mal_uint32 frameCount) +ma_result ma_device_read__alsa(ma_device* pDevice, void* pPCMFrames, ma_uint32 frameCount) { - mal_snd_pcm_sframes_t resultALSA; - mal_uint32 totalPCMFramesProcessed; + ma_snd_pcm_sframes_t resultALSA; + ma_uint32 totalPCMFramesProcessed; - mal_assert(pDevice != NULL); - mal_assert(pPCMFrames != NULL); + ma_assert(pDevice != NULL); + ma_assert(pPCMFrames != NULL); /* We need to explicitly start the device if it isn't already. */ - if (((mal_snd_pcm_state_proc)pDevice->pContext->alsa.snd_pcm_state)((mal_snd_pcm_t*)pDevice->alsa.pPCMCapture) != MA_SND_PCM_STATE_RUNNING) { - if (((mal_snd_pcm_start_proc)pDevice->pContext->alsa.snd_pcm_start)((mal_snd_pcm_t*)pDevice->alsa.pPCMCapture) < 0) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to start device in preparation for reading.", MA_FAILED_TO_START_BACKEND_DEVICE); + if (((ma_snd_pcm_state_proc)pDevice->pContext->alsa.snd_pcm_state)((ma_snd_pcm_t*)pDevice->alsa.pPCMCapture) != MA_SND_PCM_STATE_RUNNING) { + if (((ma_snd_pcm_start_proc)pDevice->pContext->alsa.snd_pcm_start)((ma_snd_pcm_t*)pDevice->alsa.pPCMCapture) < 0) { + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to start device in preparation for reading.", MA_FAILED_TO_START_BACKEND_DEVICE); } } totalPCMFramesProcessed = 0; while (totalPCMFramesProcessed < frameCount) { - void* pDst = mal_offset_ptr(pPCMFrames, totalPCMFramesProcessed * mal_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels)); - mal_uint32 framesRemaining = (frameCount - totalPCMFramesProcessed); + void* pDst = ma_offset_ptr(pPCMFrames, totalPCMFramesProcessed * ma_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels)); + ma_uint32 framesRemaining = (frameCount - totalPCMFramesProcessed); //printf("TRACE: snd_pcm_readi(framesRemaining=%d)\n", framesRemaining); - resultALSA = ((mal_snd_pcm_readi_proc)pDevice->pContext->alsa.snd_pcm_readi)((mal_snd_pcm_t*)pDevice->alsa.pPCMCapture, pDst, framesRemaining); + resultALSA = ((ma_snd_pcm_readi_proc)pDevice->pContext->alsa.snd_pcm_readi)((ma_snd_pcm_t*)pDevice->alsa.pPCMCapture, pDst, framesRemaining); if (resultALSA < 0) { if (resultALSA == -EAGAIN) { //printf("TRACE: EGAIN (read)\n"); @@ -12751,17 +12751,17 @@ mal_result mal_device_read__alsa(mal_device* pDevice, void* pPCMFrames, mal_uint //printf("TRACE: EPIPE (read)\n"); /* Overrun. Recover and try again. If this fails we need to return an error. */ - if (((mal_snd_pcm_recover_proc)pDevice->pContext->alsa.snd_pcm_recover)((mal_snd_pcm_t*)pDevice->alsa.pPCMCapture, resultALSA, MA_TRUE) < 0) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to recover device after overrun.", MA_FAILED_TO_START_BACKEND_DEVICE); + if (((ma_snd_pcm_recover_proc)pDevice->pContext->alsa.snd_pcm_recover)((ma_snd_pcm_t*)pDevice->alsa.pPCMCapture, resultALSA, MA_TRUE) < 0) { + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to recover device after overrun.", MA_FAILED_TO_START_BACKEND_DEVICE); } - if (((mal_snd_pcm_start_proc)pDevice->pContext->alsa.snd_pcm_start)((mal_snd_pcm_t*)pDevice->alsa.pPCMCapture) < 0) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to start device after underrun.", MA_FAILED_TO_START_BACKEND_DEVICE); + if (((ma_snd_pcm_start_proc)pDevice->pContext->alsa.snd_pcm_start)((ma_snd_pcm_t*)pDevice->alsa.pPCMCapture) < 0) { + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to start device after underrun.", MA_FAILED_TO_START_BACKEND_DEVICE); } - resultALSA = ((mal_snd_pcm_readi_proc)pDevice->pContext->alsa.snd_pcm_readi)((mal_snd_pcm_t*)pDevice->alsa.pPCMCapture, pDst, framesRemaining); + resultALSA = ((ma_snd_pcm_readi_proc)pDevice->pContext->alsa.snd_pcm_readi)((ma_snd_pcm_t*)pDevice->alsa.pPCMCapture, pDst, framesRemaining); if (resultALSA < 0) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to read data from the internal device.", MA_FAILED_TO_READ_DATA_FROM_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[ALSA] Failed to read data from the internal device.", MA_FAILED_TO_READ_DATA_FROM_DEVICE); } } } @@ -12773,26 +12773,26 @@ mal_result mal_device_read__alsa(mal_device* pDevice, void* pPCMFrames, mal_uint } #if 0 -mal_result mal_device_break_main_loop__alsa(mal_device* pDevice) +ma_result ma_device_break_main_loop__alsa(ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); pDevice->alsa.breakFromMainLoop = MA_TRUE; return MA_SUCCESS; } -mal_result mal_device_main_loop__alsa(mal_device* pDevice) +ma_result ma_device_main_loop__alsa(ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); pDevice->alsa.breakFromMainLoop = MA_FALSE; - if (pDevice->type == mal_device_type_playback) { + if (pDevice->type == ma_device_type_playback) { // Playback. Read from client, write to device. - while (!pDevice->alsa.breakFromMainLoop && mal_device_read_from_client_and_write__alsa(pDevice)) { + while (!pDevice->alsa.breakFromMainLoop && ma_device_read_from_client_and_write__alsa(pDevice)) { } } else { // Capture. Read from device, write to client. - while (!pDevice->alsa.breakFromMainLoop && mal_device_read_and_send_to_client__alsa(pDevice)) { + while (!pDevice->alsa.breakFromMainLoop && ma_device_read_and_send_to_client__alsa(pDevice)) { } } @@ -12800,26 +12800,26 @@ mal_result mal_device_main_loop__alsa(mal_device* pDevice) } #endif -mal_result mal_context_uninit__alsa(mal_context* pContext) +ma_result ma_context_uninit__alsa(ma_context* pContext) { - mal_assert(pContext != NULL); - mal_assert(pContext->backend == mal_backend_alsa); + ma_assert(pContext != NULL); + ma_assert(pContext->backend == ma_backend_alsa); // Clean up memory for memory leak checkers. - ((mal_snd_config_update_free_global_proc)pContext->alsa.snd_config_update_free_global)(); + ((ma_snd_config_update_free_global_proc)pContext->alsa.snd_config_update_free_global)(); #ifndef MA_NO_RUNTIME_LINKING - mal_dlclose(pContext->alsa.asoundSO); + ma_dlclose(pContext->alsa.asoundSO); #endif - mal_mutex_uninit(&pContext->alsa.internalDeviceEnumLock); + ma_mutex_uninit(&pContext->alsa.internalDeviceEnumLock); return MA_SUCCESS; } -mal_result mal_context_init__alsa(mal_context* pContext) +ma_result ma_context_init__alsa(ma_context* pContext) { - mal_assert(pContext != NULL); + ma_assert(pContext != NULL); #ifndef MA_NO_RUNTIME_LINKING const char* libasoundNames[] = { @@ -12827,8 +12827,8 @@ mal_result mal_context_init__alsa(mal_context* pContext) "libasound.so" }; - for (size_t i = 0; i < mal_countof(libasoundNames); ++i) { - pContext->alsa.asoundSO = mal_dlopen(libasoundNames[i]); + for (size_t i = 0; i < ma_countof(libasoundNames); ++i) { + pContext->alsa.asoundSO = ma_dlopen(libasoundNames[i]); if (pContext->alsa.asoundSO != NULL) { break; } @@ -12841,188 +12841,188 @@ mal_result mal_context_init__alsa(mal_context* pContext) return MA_NO_BACKEND; } - pContext->alsa.snd_pcm_open = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_open"); - pContext->alsa.snd_pcm_close = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_close"); - pContext->alsa.snd_pcm_hw_params_sizeof = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_sizeof"); - pContext->alsa.snd_pcm_hw_params_any = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_any"); - pContext->alsa.snd_pcm_hw_params_set_format = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_set_format"); - pContext->alsa.snd_pcm_hw_params_set_format_first = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_set_format_first"); - pContext->alsa.snd_pcm_hw_params_get_format_mask = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_get_format_mask"); - pContext->alsa.snd_pcm_hw_params_set_channels_near = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_set_channels_near"); - pContext->alsa.snd_pcm_hw_params_set_rate_resample = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_set_rate_resample"); - pContext->alsa.snd_pcm_hw_params_set_rate_near = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_set_rate_near"); - pContext->alsa.snd_pcm_hw_params_set_buffer_size_near = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_set_buffer_size_near"); - pContext->alsa.snd_pcm_hw_params_set_periods_near = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_set_periods_near"); - pContext->alsa.snd_pcm_hw_params_set_access = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_set_access"); - pContext->alsa.snd_pcm_hw_params_get_format = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_get_format"); - pContext->alsa.snd_pcm_hw_params_get_channels = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_get_channels"); - pContext->alsa.snd_pcm_hw_params_get_channels_min = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_get_channels_min"); - pContext->alsa.snd_pcm_hw_params_get_channels_max = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_get_channels_max"); - pContext->alsa.snd_pcm_hw_params_get_rate = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_get_rate"); - pContext->alsa.snd_pcm_hw_params_get_rate_min = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_get_rate_min"); - pContext->alsa.snd_pcm_hw_params_get_rate_max = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_get_rate_max"); - pContext->alsa.snd_pcm_hw_params_get_buffer_size = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_get_buffer_size"); - pContext->alsa.snd_pcm_hw_params_get_periods = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_get_periods"); - pContext->alsa.snd_pcm_hw_params_get_access = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_get_access"); - pContext->alsa.snd_pcm_hw_params = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params"); - pContext->alsa.snd_pcm_sw_params_sizeof = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_sw_params_sizeof"); - pContext->alsa.snd_pcm_sw_params_current = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_sw_params_current"); - pContext->alsa.snd_pcm_sw_params_get_boundary = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_sw_params_get_boundary"); - pContext->alsa.snd_pcm_sw_params_set_avail_min = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_sw_params_set_avail_min"); - pContext->alsa.snd_pcm_sw_params_set_start_threshold = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_sw_params_set_start_threshold"); - pContext->alsa.snd_pcm_sw_params_set_stop_threshold = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_sw_params_set_stop_threshold"); - pContext->alsa.snd_pcm_sw_params = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_sw_params"); - pContext->alsa.snd_pcm_format_mask_sizeof = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_format_mask_sizeof"); - pContext->alsa.snd_pcm_format_mask_test = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_format_mask_test"); - pContext->alsa.snd_pcm_get_chmap = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_get_chmap"); - pContext->alsa.snd_pcm_state = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_state"); - pContext->alsa.snd_pcm_prepare = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_prepare"); - pContext->alsa.snd_pcm_start = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_start"); - pContext->alsa.snd_pcm_drop = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_drop"); - pContext->alsa.snd_pcm_drain = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_drain"); - pContext->alsa.snd_device_name_hint = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_device_name_hint"); - pContext->alsa.snd_device_name_get_hint = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_device_name_get_hint"); - pContext->alsa.snd_card_get_index = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_card_get_index"); - pContext->alsa.snd_device_name_free_hint = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_device_name_free_hint"); - pContext->alsa.snd_pcm_mmap_begin = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_mmap_begin"); - pContext->alsa.snd_pcm_mmap_commit = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_mmap_commit"); - pContext->alsa.snd_pcm_recover = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_recover"); - pContext->alsa.snd_pcm_readi = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_readi"); - pContext->alsa.snd_pcm_writei = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_writei"); - pContext->alsa.snd_pcm_avail = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_avail"); - pContext->alsa.snd_pcm_avail_update = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_avail_update"); - pContext->alsa.snd_pcm_wait = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_wait"); - pContext->alsa.snd_pcm_info = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_info"); - pContext->alsa.snd_pcm_info_sizeof = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_info_sizeof"); - pContext->alsa.snd_pcm_info_get_name = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_pcm_info_get_name"); - pContext->alsa.snd_config_update_free_global = (mal_proc)mal_dlsym(pContext->alsa.asoundSO, "snd_config_update_free_global"); + pContext->alsa.snd_pcm_open = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_open"); + pContext->alsa.snd_pcm_close = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_close"); + pContext->alsa.snd_pcm_hw_params_sizeof = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_sizeof"); + pContext->alsa.snd_pcm_hw_params_any = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_any"); + pContext->alsa.snd_pcm_hw_params_set_format = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_set_format"); + pContext->alsa.snd_pcm_hw_params_set_format_first = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_set_format_first"); + pContext->alsa.snd_pcm_hw_params_get_format_mask = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_get_format_mask"); + pContext->alsa.snd_pcm_hw_params_set_channels_near = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_set_channels_near"); + pContext->alsa.snd_pcm_hw_params_set_rate_resample = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_set_rate_resample"); + pContext->alsa.snd_pcm_hw_params_set_rate_near = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_set_rate_near"); + pContext->alsa.snd_pcm_hw_params_set_buffer_size_near = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_set_buffer_size_near"); + pContext->alsa.snd_pcm_hw_params_set_periods_near = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_set_periods_near"); + pContext->alsa.snd_pcm_hw_params_set_access = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_set_access"); + pContext->alsa.snd_pcm_hw_params_get_format = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_get_format"); + pContext->alsa.snd_pcm_hw_params_get_channels = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_get_channels"); + pContext->alsa.snd_pcm_hw_params_get_channels_min = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_get_channels_min"); + pContext->alsa.snd_pcm_hw_params_get_channels_max = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_get_channels_max"); + pContext->alsa.snd_pcm_hw_params_get_rate = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_get_rate"); + pContext->alsa.snd_pcm_hw_params_get_rate_min = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_get_rate_min"); + pContext->alsa.snd_pcm_hw_params_get_rate_max = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_get_rate_max"); + pContext->alsa.snd_pcm_hw_params_get_buffer_size = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_get_buffer_size"); + pContext->alsa.snd_pcm_hw_params_get_periods = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_get_periods"); + pContext->alsa.snd_pcm_hw_params_get_access = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params_get_access"); + pContext->alsa.snd_pcm_hw_params = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_hw_params"); + pContext->alsa.snd_pcm_sw_params_sizeof = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_sw_params_sizeof"); + pContext->alsa.snd_pcm_sw_params_current = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_sw_params_current"); + pContext->alsa.snd_pcm_sw_params_get_boundary = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_sw_params_get_boundary"); + pContext->alsa.snd_pcm_sw_params_set_avail_min = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_sw_params_set_avail_min"); + pContext->alsa.snd_pcm_sw_params_set_start_threshold = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_sw_params_set_start_threshold"); + pContext->alsa.snd_pcm_sw_params_set_stop_threshold = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_sw_params_set_stop_threshold"); + pContext->alsa.snd_pcm_sw_params = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_sw_params"); + pContext->alsa.snd_pcm_format_mask_sizeof = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_format_mask_sizeof"); + pContext->alsa.snd_pcm_format_mask_test = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_format_mask_test"); + pContext->alsa.snd_pcm_get_chmap = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_get_chmap"); + pContext->alsa.snd_pcm_state = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_state"); + pContext->alsa.snd_pcm_prepare = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_prepare"); + pContext->alsa.snd_pcm_start = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_start"); + pContext->alsa.snd_pcm_drop = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_drop"); + pContext->alsa.snd_pcm_drain = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_drain"); + pContext->alsa.snd_device_name_hint = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_device_name_hint"); + pContext->alsa.snd_device_name_get_hint = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_device_name_get_hint"); + pContext->alsa.snd_card_get_index = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_card_get_index"); + pContext->alsa.snd_device_name_free_hint = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_device_name_free_hint"); + pContext->alsa.snd_pcm_mmap_begin = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_mmap_begin"); + pContext->alsa.snd_pcm_mmap_commit = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_mmap_commit"); + pContext->alsa.snd_pcm_recover = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_recover"); + pContext->alsa.snd_pcm_readi = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_readi"); + pContext->alsa.snd_pcm_writei = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_writei"); + pContext->alsa.snd_pcm_avail = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_avail"); + pContext->alsa.snd_pcm_avail_update = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_avail_update"); + pContext->alsa.snd_pcm_wait = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_wait"); + pContext->alsa.snd_pcm_info = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_info"); + pContext->alsa.snd_pcm_info_sizeof = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_info_sizeof"); + pContext->alsa.snd_pcm_info_get_name = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_pcm_info_get_name"); + pContext->alsa.snd_config_update_free_global = (ma_proc)ma_dlsym(pContext->alsa.asoundSO, "snd_config_update_free_global"); #else // The system below is just for type safety. - mal_snd_pcm_open_proc _snd_pcm_open = snd_pcm_open; - mal_snd_pcm_close_proc _snd_pcm_close = snd_pcm_close; - mal_snd_pcm_hw_params_sizeof_proc _snd_pcm_hw_params_sizeof = snd_pcm_hw_params_sizeof; - mal_snd_pcm_hw_params_any_proc _snd_pcm_hw_params_any = snd_pcm_hw_params_any; - mal_snd_pcm_hw_params_set_format_proc _snd_pcm_hw_params_set_format = snd_pcm_hw_params_set_format; - mal_snd_pcm_hw_params_set_format_first_proc _snd_pcm_hw_params_set_format_first = snd_pcm_hw_params_set_format_first; - mal_snd_pcm_hw_params_get_format_mask_proc _snd_pcm_hw_params_get_format_mask = snd_pcm_hw_params_get_format_mask; - mal_snd_pcm_hw_params_set_channels_near_proc _snd_pcm_hw_params_set_channels_near = snd_pcm_hw_params_set_channels_near; - mal_snd_pcm_hw_params_set_rate_resample_proc _snd_pcm_hw_params_set_rate_resample = snd_pcm_hw_params_set_rate_resample; - mal_snd_pcm_hw_params_set_rate_near_proc _snd_pcm_hw_params_set_rate_near = snd_pcm_hw_params_set_rate_near; - mal_snd_pcm_hw_params_set_buffer_size_near_proc _snd_pcm_hw_params_set_buffer_size_near = snd_pcm_hw_params_set_buffer_size_near; - mal_snd_pcm_hw_params_set_periods_near_proc _snd_pcm_hw_params_set_periods_near = snd_pcm_hw_params_set_periods_near; - mal_snd_pcm_hw_params_set_access_proc _snd_pcm_hw_params_set_access = snd_pcm_hw_params_set_access; - mal_snd_pcm_hw_params_get_format_proc _snd_pcm_hw_params_get_format = snd_pcm_hw_params_get_format; - mal_snd_pcm_hw_params_get_channels_proc _snd_pcm_hw_params_get_channels = snd_pcm_hw_params_get_channels; - mal_snd_pcm_hw_params_get_channels_min_proc _snd_pcm_hw_params_get_channels_min = snd_pcm_hw_params_get_channels_min; - mal_snd_pcm_hw_params_get_channels_max_proc _snd_pcm_hw_params_get_channels_max = snd_pcm_hw_params_get_channels_max; - mal_snd_pcm_hw_params_get_rate_proc _snd_pcm_hw_params_get_rate = snd_pcm_hw_params_get_rate; - mal_snd_pcm_hw_params_get_rate_min_proc _snd_pcm_hw_params_get_rate_min = snd_pcm_hw_params_get_rate_min; - mal_snd_pcm_hw_params_get_rate_max_proc _snd_pcm_hw_params_get_rate_max = snd_pcm_hw_params_get_rate_max; - mal_snd_pcm_hw_params_get_buffer_size_proc _snd_pcm_hw_params_get_buffer_size = snd_pcm_hw_params_get_buffer_size; - mal_snd_pcm_hw_params_get_periods_proc _snd_pcm_hw_params_get_periods = snd_pcm_hw_params_get_periods; - mal_snd_pcm_hw_params_get_access_proc _snd_pcm_hw_params_get_access = snd_pcm_hw_params_get_access; - mal_snd_pcm_hw_params_proc _snd_pcm_hw_params = snd_pcm_hw_params; - mal_snd_pcm_sw_params_sizeof_proc _snd_pcm_sw_params_sizeof = snd_pcm_sw_params_sizeof; - mal_snd_pcm_sw_params_current_proc _snd_pcm_sw_params_current = snd_pcm_sw_params_current; - mal_snd_pcm_sw_params_get_boundary_proc _snd_pcm_sw_params_get_boundary = snd_pcm_sw_params_get_boundary; - mal_snd_pcm_sw_params_set_avail_min_proc _snd_pcm_sw_params_set_avail_min = snd_pcm_sw_params_set_avail_min; - mal_snd_pcm_sw_params_set_start_threshold_proc _snd_pcm_sw_params_set_start_threshold = snd_pcm_sw_params_set_start_threshold; - mal_snd_pcm_sw_params_set_stop_threshold_proc _snd_pcm_sw_params_set_stop_threshold = snd_pcm_sw_params_set_stop_threshold; - mal_snd_pcm_sw_params_proc _snd_pcm_sw_params = snd_pcm_sw_params; - mal_snd_pcm_format_mask_sizeof_proc _snd_pcm_format_mask_sizeof = snd_pcm_format_mask_sizeof; - mal_snd_pcm_format_mask_test_proc _snd_pcm_format_mask_test = snd_pcm_format_mask_test; - mal_snd_pcm_get_chmap_proc _snd_pcm_get_chmap = snd_pcm_get_chmap; - mal_snd_pcm_state_proc _snd_pcm_state = snd_pcm_state; - mal_snd_pcm_prepare_proc _snd_pcm_prepare = snd_pcm_prepare; - mal_snd_pcm_start_proc _snd_pcm_start = snd_pcm_start; - mal_snd_pcm_drop_proc _snd_pcm_drop = snd_pcm_drop; - mal_snd_pcm_drain_proc _snd_pcm_drain = snd_pcm_drain; - mal_snd_device_name_hint_proc _snd_device_name_hint = snd_device_name_hint; - mal_snd_device_name_get_hint_proc _snd_device_name_get_hint = snd_device_name_get_hint; - mal_snd_card_get_index_proc _snd_card_get_index = snd_card_get_index; - mal_snd_device_name_free_hint_proc _snd_device_name_free_hint = snd_device_name_free_hint; - mal_snd_pcm_mmap_begin_proc _snd_pcm_mmap_begin = snd_pcm_mmap_begin; - mal_snd_pcm_mmap_commit_proc _snd_pcm_mmap_commit = snd_pcm_mmap_commit; - mal_snd_pcm_recover_proc _snd_pcm_recover = snd_pcm_recover; - mal_snd_pcm_readi_proc _snd_pcm_readi = snd_pcm_readi; - mal_snd_pcm_writei_proc _snd_pcm_writei = snd_pcm_writei; - mal_snd_pcm_avail_proc _snd_pcm_avail = snd_pcm_avail; - mal_snd_pcm_avail_update_proc _snd_pcm_avail_update = snd_pcm_avail_update; - mal_snd_pcm_wait_proc _snd_pcm_wait = snd_pcm_wait; - mal_snd_pcm_info_proc _snd_pcm_info = snd_pcm_info; - mal_snd_pcm_info_sizeof_proc _snd_pcm_info_sizeof = snd_pcm_info_sizeof; - mal_snd_pcm_info_get_name_proc _snd_pcm_info_get_name = snd_pcm_info_get_name; - mal_snd_config_update_free_global_proc _snd_config_update_free_global = snd_config_update_free_global; + ma_snd_pcm_open_proc _snd_pcm_open = snd_pcm_open; + ma_snd_pcm_close_proc _snd_pcm_close = snd_pcm_close; + ma_snd_pcm_hw_params_sizeof_proc _snd_pcm_hw_params_sizeof = snd_pcm_hw_params_sizeof; + ma_snd_pcm_hw_params_any_proc _snd_pcm_hw_params_any = snd_pcm_hw_params_any; + ma_snd_pcm_hw_params_set_format_proc _snd_pcm_hw_params_set_format = snd_pcm_hw_params_set_format; + ma_snd_pcm_hw_params_set_format_first_proc _snd_pcm_hw_params_set_format_first = snd_pcm_hw_params_set_format_first; + ma_snd_pcm_hw_params_get_format_mask_proc _snd_pcm_hw_params_get_format_mask = snd_pcm_hw_params_get_format_mask; + ma_snd_pcm_hw_params_set_channels_near_proc _snd_pcm_hw_params_set_channels_near = snd_pcm_hw_params_set_channels_near; + ma_snd_pcm_hw_params_set_rate_resample_proc _snd_pcm_hw_params_set_rate_resample = snd_pcm_hw_params_set_rate_resample; + ma_snd_pcm_hw_params_set_rate_near_proc _snd_pcm_hw_params_set_rate_near = snd_pcm_hw_params_set_rate_near; + ma_snd_pcm_hw_params_set_buffer_size_near_proc _snd_pcm_hw_params_set_buffer_size_near = snd_pcm_hw_params_set_buffer_size_near; + ma_snd_pcm_hw_params_set_periods_near_proc _snd_pcm_hw_params_set_periods_near = snd_pcm_hw_params_set_periods_near; + ma_snd_pcm_hw_params_set_access_proc _snd_pcm_hw_params_set_access = snd_pcm_hw_params_set_access; + ma_snd_pcm_hw_params_get_format_proc _snd_pcm_hw_params_get_format = snd_pcm_hw_params_get_format; + ma_snd_pcm_hw_params_get_channels_proc _snd_pcm_hw_params_get_channels = snd_pcm_hw_params_get_channels; + ma_snd_pcm_hw_params_get_channels_min_proc _snd_pcm_hw_params_get_channels_min = snd_pcm_hw_params_get_channels_min; + ma_snd_pcm_hw_params_get_channels_max_proc _snd_pcm_hw_params_get_channels_max = snd_pcm_hw_params_get_channels_max; + ma_snd_pcm_hw_params_get_rate_proc _snd_pcm_hw_params_get_rate = snd_pcm_hw_params_get_rate; + ma_snd_pcm_hw_params_get_rate_min_proc _snd_pcm_hw_params_get_rate_min = snd_pcm_hw_params_get_rate_min; + ma_snd_pcm_hw_params_get_rate_max_proc _snd_pcm_hw_params_get_rate_max = snd_pcm_hw_params_get_rate_max; + ma_snd_pcm_hw_params_get_buffer_size_proc _snd_pcm_hw_params_get_buffer_size = snd_pcm_hw_params_get_buffer_size; + ma_snd_pcm_hw_params_get_periods_proc _snd_pcm_hw_params_get_periods = snd_pcm_hw_params_get_periods; + ma_snd_pcm_hw_params_get_access_proc _snd_pcm_hw_params_get_access = snd_pcm_hw_params_get_access; + ma_snd_pcm_hw_params_proc _snd_pcm_hw_params = snd_pcm_hw_params; + ma_snd_pcm_sw_params_sizeof_proc _snd_pcm_sw_params_sizeof = snd_pcm_sw_params_sizeof; + ma_snd_pcm_sw_params_current_proc _snd_pcm_sw_params_current = snd_pcm_sw_params_current; + ma_snd_pcm_sw_params_get_boundary_proc _snd_pcm_sw_params_get_boundary = snd_pcm_sw_params_get_boundary; + ma_snd_pcm_sw_params_set_avail_min_proc _snd_pcm_sw_params_set_avail_min = snd_pcm_sw_params_set_avail_min; + ma_snd_pcm_sw_params_set_start_threshold_proc _snd_pcm_sw_params_set_start_threshold = snd_pcm_sw_params_set_start_threshold; + ma_snd_pcm_sw_params_set_stop_threshold_proc _snd_pcm_sw_params_set_stop_threshold = snd_pcm_sw_params_set_stop_threshold; + ma_snd_pcm_sw_params_proc _snd_pcm_sw_params = snd_pcm_sw_params; + ma_snd_pcm_format_mask_sizeof_proc _snd_pcm_format_mask_sizeof = snd_pcm_format_mask_sizeof; + ma_snd_pcm_format_mask_test_proc _snd_pcm_format_mask_test = snd_pcm_format_mask_test; + ma_snd_pcm_get_chmap_proc _snd_pcm_get_chmap = snd_pcm_get_chmap; + ma_snd_pcm_state_proc _snd_pcm_state = snd_pcm_state; + ma_snd_pcm_prepare_proc _snd_pcm_prepare = snd_pcm_prepare; + ma_snd_pcm_start_proc _snd_pcm_start = snd_pcm_start; + ma_snd_pcm_drop_proc _snd_pcm_drop = snd_pcm_drop; + ma_snd_pcm_drain_proc _snd_pcm_drain = snd_pcm_drain; + ma_snd_device_name_hint_proc _snd_device_name_hint = snd_device_name_hint; + ma_snd_device_name_get_hint_proc _snd_device_name_get_hint = snd_device_name_get_hint; + ma_snd_card_get_index_proc _snd_card_get_index = snd_card_get_index; + ma_snd_device_name_free_hint_proc _snd_device_name_free_hint = snd_device_name_free_hint; + ma_snd_pcm_mmap_begin_proc _snd_pcm_mmap_begin = snd_pcm_mmap_begin; + ma_snd_pcm_mmap_commit_proc _snd_pcm_mmap_commit = snd_pcm_mmap_commit; + ma_snd_pcm_recover_proc _snd_pcm_recover = snd_pcm_recover; + ma_snd_pcm_readi_proc _snd_pcm_readi = snd_pcm_readi; + ma_snd_pcm_writei_proc _snd_pcm_writei = snd_pcm_writei; + ma_snd_pcm_avail_proc _snd_pcm_avail = snd_pcm_avail; + ma_snd_pcm_avail_update_proc _snd_pcm_avail_update = snd_pcm_avail_update; + ma_snd_pcm_wait_proc _snd_pcm_wait = snd_pcm_wait; + ma_snd_pcm_info_proc _snd_pcm_info = snd_pcm_info; + ma_snd_pcm_info_sizeof_proc _snd_pcm_info_sizeof = snd_pcm_info_sizeof; + ma_snd_pcm_info_get_name_proc _snd_pcm_info_get_name = snd_pcm_info_get_name; + ma_snd_config_update_free_global_proc _snd_config_update_free_global = snd_config_update_free_global; - pContext->alsa.snd_pcm_open = (mal_proc)_snd_pcm_open; - pContext->alsa.snd_pcm_close = (mal_proc)_snd_pcm_close; - pContext->alsa.snd_pcm_hw_params_sizeof = (mal_proc)_snd_pcm_hw_params_sizeof; - pContext->alsa.snd_pcm_hw_params_any = (mal_proc)_snd_pcm_hw_params_any; - pContext->alsa.snd_pcm_hw_params_set_format = (mal_proc)_snd_pcm_hw_params_set_format; - pContext->alsa.snd_pcm_hw_params_set_format_first = (mal_proc)_snd_pcm_hw_params_set_format_first; - pContext->alsa.snd_pcm_hw_params_get_format_mask = (mal_proc)_snd_pcm_hw_params_get_format_mask; - pContext->alsa.snd_pcm_hw_params_set_channels_near = (mal_proc)_snd_pcm_hw_params_set_channels_near; - pContext->alsa.snd_pcm_hw_params_set_rate_resample = (mal_proc)_snd_pcm_hw_params_set_rate_resample; - pContext->alsa.snd_pcm_hw_params_set_rate_near = (mal_proc)_snd_pcm_hw_params_set_rate_near; - pContext->alsa.snd_pcm_hw_params_set_buffer_size_near = (mal_proc)_snd_pcm_hw_params_set_buffer_size_near; - pContext->alsa.snd_pcm_hw_params_set_periods_near = (mal_proc)_snd_pcm_hw_params_set_periods_near; - pContext->alsa.snd_pcm_hw_params_set_access = (mal_proc)_snd_pcm_hw_params_set_access; - pContext->alsa.snd_pcm_hw_params_get_format = (mal_proc)_snd_pcm_hw_params_get_format; - pContext->alsa.snd_pcm_hw_params_get_channels = (mal_proc)_snd_pcm_hw_params_get_channels; - pContext->alsa.snd_pcm_hw_params_get_channels_min = (mal_proc)_snd_pcm_hw_params_get_channels_min; - pContext->alsa.snd_pcm_hw_params_get_channels_max = (mal_proc)_snd_pcm_hw_params_get_channels_max; - pContext->alsa.snd_pcm_hw_params_get_rate = (mal_proc)_snd_pcm_hw_params_get_rate; - pContext->alsa.snd_pcm_hw_params_get_buffer_size = (mal_proc)_snd_pcm_hw_params_get_buffer_size; - pContext->alsa.snd_pcm_hw_params_get_periods = (mal_proc)_snd_pcm_hw_params_get_periods; - pContext->alsa.snd_pcm_hw_params_get_access = (mal_proc)_snd_pcm_hw_params_get_access; - pContext->alsa.snd_pcm_hw_params = (mal_proc)_snd_pcm_hw_params; - pContext->alsa.snd_pcm_sw_params_sizeof = (mal_proc)_snd_pcm_sw_params_sizeof; - pContext->alsa.snd_pcm_sw_params_current = (mal_proc)_snd_pcm_sw_params_current; - pContext->alsa.snd_pcm_sw_params_get_boundary = (mal_proc)_snd_pcm_sw_params_get_boundary; - pContext->alsa.snd_pcm_sw_params_set_avail_min = (mal_proc)_snd_pcm_sw_params_set_avail_min; - pContext->alsa.snd_pcm_sw_params_set_start_threshold = (mal_proc)_snd_pcm_sw_params_set_start_threshold; - pContext->alsa.snd_pcm_sw_params_set_stop_threshold = (mal_proc)_snd_pcm_sw_params_set_stop_threshold; - pContext->alsa.snd_pcm_sw_params = (mal_proc)_snd_pcm_sw_params; - pContext->alsa.snd_pcm_format_mask_sizeof = (mal_proc)_snd_pcm_format_mask_sizeof; - pContext->alsa.snd_pcm_format_mask_test = (mal_proc)_snd_pcm_format_mask_test; - pContext->alsa.snd_pcm_get_chmap = (mal_proc)_snd_pcm_get_chmap; - pContext->alsa.snd_pcm_state = (mal_proc)_snd_pcm_state; - pContext->alsa.snd_pcm_prepare = (mal_proc)_snd_pcm_prepare; - pContext->alsa.snd_pcm_start = (mal_proc)_snd_pcm_start; - pContext->alsa.snd_pcm_drop = (mal_proc)_snd_pcm_drop; - pContext->alsa.snd_pcm_drain = (mal_proc)_snd_pcm_drain; - pContext->alsa.snd_device_name_hint = (mal_proc)_snd_device_name_hint; - pContext->alsa.snd_device_name_get_hint = (mal_proc)_snd_device_name_get_hint; - pContext->alsa.snd_card_get_index = (mal_proc)_snd_card_get_index; - pContext->alsa.snd_device_name_free_hint = (mal_proc)_snd_device_name_free_hint; - pContext->alsa.snd_pcm_mmap_begin = (mal_proc)_snd_pcm_mmap_begin; - pContext->alsa.snd_pcm_mmap_commit = (mal_proc)_snd_pcm_mmap_commit; - pContext->alsa.snd_pcm_recover = (mal_proc)_snd_pcm_recover; - pContext->alsa.snd_pcm_readi = (mal_proc)_snd_pcm_readi; - pContext->alsa.snd_pcm_writei = (mal_proc)_snd_pcm_writei; - pContext->alsa.snd_pcm_avail = (mal_proc)_snd_pcm_avail; - pContext->alsa.snd_pcm_avail_update = (mal_proc)_snd_pcm_avail_update; - pContext->alsa.snd_pcm_wait = (mal_proc)_snd_pcm_wait; - pContext->alsa.snd_pcm_info = (mal_proc)_snd_pcm_info; - pContext->alsa.snd_pcm_info_sizeof = (mal_proc)_snd_pcm_info_sizeof; - pContext->alsa.snd_pcm_info_get_name = (mal_proc)_snd_pcm_info_get_name; - pContext->alsa.snd_config_update_free_global = (mal_proc)_snd_config_update_free_global; + pContext->alsa.snd_pcm_open = (ma_proc)_snd_pcm_open; + pContext->alsa.snd_pcm_close = (ma_proc)_snd_pcm_close; + pContext->alsa.snd_pcm_hw_params_sizeof = (ma_proc)_snd_pcm_hw_params_sizeof; + pContext->alsa.snd_pcm_hw_params_any = (ma_proc)_snd_pcm_hw_params_any; + pContext->alsa.snd_pcm_hw_params_set_format = (ma_proc)_snd_pcm_hw_params_set_format; + pContext->alsa.snd_pcm_hw_params_set_format_first = (ma_proc)_snd_pcm_hw_params_set_format_first; + pContext->alsa.snd_pcm_hw_params_get_format_mask = (ma_proc)_snd_pcm_hw_params_get_format_mask; + pContext->alsa.snd_pcm_hw_params_set_channels_near = (ma_proc)_snd_pcm_hw_params_set_channels_near; + pContext->alsa.snd_pcm_hw_params_set_rate_resample = (ma_proc)_snd_pcm_hw_params_set_rate_resample; + pContext->alsa.snd_pcm_hw_params_set_rate_near = (ma_proc)_snd_pcm_hw_params_set_rate_near; + pContext->alsa.snd_pcm_hw_params_set_buffer_size_near = (ma_proc)_snd_pcm_hw_params_set_buffer_size_near; + pContext->alsa.snd_pcm_hw_params_set_periods_near = (ma_proc)_snd_pcm_hw_params_set_periods_near; + pContext->alsa.snd_pcm_hw_params_set_access = (ma_proc)_snd_pcm_hw_params_set_access; + pContext->alsa.snd_pcm_hw_params_get_format = (ma_proc)_snd_pcm_hw_params_get_format; + pContext->alsa.snd_pcm_hw_params_get_channels = (ma_proc)_snd_pcm_hw_params_get_channels; + pContext->alsa.snd_pcm_hw_params_get_channels_min = (ma_proc)_snd_pcm_hw_params_get_channels_min; + pContext->alsa.snd_pcm_hw_params_get_channels_max = (ma_proc)_snd_pcm_hw_params_get_channels_max; + pContext->alsa.snd_pcm_hw_params_get_rate = (ma_proc)_snd_pcm_hw_params_get_rate; + pContext->alsa.snd_pcm_hw_params_get_buffer_size = (ma_proc)_snd_pcm_hw_params_get_buffer_size; + pContext->alsa.snd_pcm_hw_params_get_periods = (ma_proc)_snd_pcm_hw_params_get_periods; + pContext->alsa.snd_pcm_hw_params_get_access = (ma_proc)_snd_pcm_hw_params_get_access; + pContext->alsa.snd_pcm_hw_params = (ma_proc)_snd_pcm_hw_params; + pContext->alsa.snd_pcm_sw_params_sizeof = (ma_proc)_snd_pcm_sw_params_sizeof; + pContext->alsa.snd_pcm_sw_params_current = (ma_proc)_snd_pcm_sw_params_current; + pContext->alsa.snd_pcm_sw_params_get_boundary = (ma_proc)_snd_pcm_sw_params_get_boundary; + pContext->alsa.snd_pcm_sw_params_set_avail_min = (ma_proc)_snd_pcm_sw_params_set_avail_min; + pContext->alsa.snd_pcm_sw_params_set_start_threshold = (ma_proc)_snd_pcm_sw_params_set_start_threshold; + pContext->alsa.snd_pcm_sw_params_set_stop_threshold = (ma_proc)_snd_pcm_sw_params_set_stop_threshold; + pContext->alsa.snd_pcm_sw_params = (ma_proc)_snd_pcm_sw_params; + pContext->alsa.snd_pcm_format_mask_sizeof = (ma_proc)_snd_pcm_format_mask_sizeof; + pContext->alsa.snd_pcm_format_mask_test = (ma_proc)_snd_pcm_format_mask_test; + pContext->alsa.snd_pcm_get_chmap = (ma_proc)_snd_pcm_get_chmap; + pContext->alsa.snd_pcm_state = (ma_proc)_snd_pcm_state; + pContext->alsa.snd_pcm_prepare = (ma_proc)_snd_pcm_prepare; + pContext->alsa.snd_pcm_start = (ma_proc)_snd_pcm_start; + pContext->alsa.snd_pcm_drop = (ma_proc)_snd_pcm_drop; + pContext->alsa.snd_pcm_drain = (ma_proc)_snd_pcm_drain; + pContext->alsa.snd_device_name_hint = (ma_proc)_snd_device_name_hint; + pContext->alsa.snd_device_name_get_hint = (ma_proc)_snd_device_name_get_hint; + pContext->alsa.snd_card_get_index = (ma_proc)_snd_card_get_index; + pContext->alsa.snd_device_name_free_hint = (ma_proc)_snd_device_name_free_hint; + pContext->alsa.snd_pcm_mmap_begin = (ma_proc)_snd_pcm_mmap_begin; + pContext->alsa.snd_pcm_mmap_commit = (ma_proc)_snd_pcm_mmap_commit; + pContext->alsa.snd_pcm_recover = (ma_proc)_snd_pcm_recover; + pContext->alsa.snd_pcm_readi = (ma_proc)_snd_pcm_readi; + pContext->alsa.snd_pcm_writei = (ma_proc)_snd_pcm_writei; + pContext->alsa.snd_pcm_avail = (ma_proc)_snd_pcm_avail; + pContext->alsa.snd_pcm_avail_update = (ma_proc)_snd_pcm_avail_update; + pContext->alsa.snd_pcm_wait = (ma_proc)_snd_pcm_wait; + pContext->alsa.snd_pcm_info = (ma_proc)_snd_pcm_info; + pContext->alsa.snd_pcm_info_sizeof = (ma_proc)_snd_pcm_info_sizeof; + pContext->alsa.snd_pcm_info_get_name = (ma_proc)_snd_pcm_info_get_name; + pContext->alsa.snd_config_update_free_global = (ma_proc)_snd_config_update_free_global; #endif - if (mal_mutex_init(pContext, &pContext->alsa.internalDeviceEnumLock) != MA_SUCCESS) { - mal_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[ALSA] WARNING: Failed to initialize mutex for internal device enumeration.", MA_ERROR); + if (ma_mutex_init(pContext, &pContext->alsa.internalDeviceEnumLock) != MA_SUCCESS) { + ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[ALSA] WARNING: Failed to initialize mutex for internal device enumeration.", MA_ERROR); } - pContext->onUninit = mal_context_uninit__alsa; - pContext->onDeviceIDEqual = mal_context_is_device_id_equal__alsa; - pContext->onEnumDevices = mal_context_enumerate_devices__alsa; - pContext->onGetDeviceInfo = mal_context_get_device_info__alsa; - pContext->onDeviceInit = mal_device_init__alsa; - pContext->onDeviceUninit = mal_device_uninit__alsa; - pContext->onDeviceStart = NULL; /*mal_device_start__alsa;*/ - pContext->onDeviceStop = mal_device_stop__alsa; - pContext->onDeviceWrite = mal_device_write__alsa; - pContext->onDeviceRead = mal_device_read__alsa; + pContext->onUninit = ma_context_uninit__alsa; + pContext->onDeviceIDEqual = ma_context_is_device_id_equal__alsa; + pContext->onEnumDevices = ma_context_enumerate_devices__alsa; + pContext->onGetDeviceInfo = ma_context_get_device_info__alsa; + pContext->onDeviceInit = ma_device_init__alsa; + pContext->onDeviceUninit = ma_device_uninit__alsa; + pContext->onDeviceStart = NULL; /*ma_device_start__alsa;*/ + pContext->onDeviceStop = ma_device_stop__alsa; + pContext->onDeviceWrite = ma_device_write__alsa; + pContext->onDeviceRead = ma_device_read__alsa; return MA_SUCCESS; } @@ -13040,7 +13040,7 @@ mal_result mal_context_init__alsa(mal_context* pContext) // It is assumed pulseaudio.h is available when compile-time linking is being used. We use this for type safety when using // compile time linking (we don't have this luxury when using runtime linking without headers). // -// When using compile time linking, each of our mal_* equivalents should use the sames types as defined by the header. The +// When using compile time linking, each of our ma_* equivalents should use the sames types as defined by the header. The // reason for this is that it allow us to take advantage of proper type safety. #ifdef MA_NO_RUNTIME_LINKING #include @@ -13053,12 +13053,12 @@ mal_result mal_context_init__alsa(mal_context* pContext) #define MA_PA_CHANNELS_MAX PA_CHANNELS_MAX #define MA_PA_RATE_MAX PA_RATE_MAX -typedef pa_context_flags_t mal_pa_context_flags_t; +typedef pa_context_flags_t ma_pa_context_flags_t; #define MA_PA_CONTEXT_NOFLAGS PA_CONTEXT_NOFLAGS #define MA_PA_CONTEXT_NOAUTOSPAWN PA_CONTEXT_NOAUTOSPAWN #define MA_PA_CONTEXT_NOFAIL PA_CONTEXT_NOFAIL -typedef pa_stream_flags_t mal_pa_stream_flags_t; +typedef pa_stream_flags_t ma_pa_stream_flags_t; #define MA_PA_STREAM_NOFLAGS PA_STREAM_NOFLAGS #define MA_PA_STREAM_START_CORKED PA_STREAM_START_CORKED #define MA_PA_STREAM_INTERPOLATE_TIMING PA_STREAM_INTERPOLATE_TIMING @@ -13081,7 +13081,7 @@ typedef pa_stream_flags_t mal_pa_stream_flags_t; #define MA_PA_STREAM_RELATIVE_VOLUME PA_STREAM_RELATIVE_VOLUME #define MA_PA_STREAM_PASSTHROUGH PA_STREAM_PASSTHROUGH -typedef pa_sink_flags_t mal_pa_sink_flags_t; +typedef pa_sink_flags_t ma_pa_sink_flags_t; #define MA_PA_SINK_NOFLAGS PA_SINK_NOFLAGS #define MA_PA_SINK_HW_VOLUME_CTRL PA_SINK_HW_VOLUME_CTRL #define MA_PA_SINK_LATENCY PA_SINK_LATENCY @@ -13093,7 +13093,7 @@ typedef pa_sink_flags_t mal_pa_sink_flags_t; #define MA_PA_SINK_DYNAMIC_LATENCY PA_SINK_DYNAMIC_LATENCY #define MA_PA_SINK_SET_FORMATS PA_SINK_SET_FORMATS -typedef pa_source_flags_t mal_pa_source_flags_t; +typedef pa_source_flags_t ma_pa_source_flags_t; #define MA_PA_SOURCE_NOFLAGS PA_SOURCE_NOFLAGS #define MA_PA_SOURCE_HW_VOLUME_CTRL PA_SOURCE_HW_VOLUME_CTRL #define MA_PA_SOURCE_LATENCY PA_SOURCE_LATENCY @@ -13104,7 +13104,7 @@ typedef pa_source_flags_t mal_pa_source_flags_t; #define MA_PA_SOURCE_DYNAMIC_LATENCY PA_SOURCE_DYNAMIC_LATENCY #define MA_PA_SOURCE_FLAT_VOLUME PA_SOURCE_FLAT_VOLUME -typedef pa_context_state_t mal_pa_context_state_t; +typedef pa_context_state_t ma_pa_context_state_t; #define MA_PA_CONTEXT_UNCONNECTED PA_CONTEXT_UNCONNECTED #define MA_PA_CONTEXT_CONNECTING PA_CONTEXT_CONNECTING #define MA_PA_CONTEXT_AUTHORIZING PA_CONTEXT_AUTHORIZING @@ -13113,37 +13113,37 @@ typedef pa_context_state_t mal_pa_context_state_t; #define MA_PA_CONTEXT_FAILED PA_CONTEXT_FAILED #define MA_PA_CONTEXT_TERMINATED PA_CONTEXT_TERMINATED -typedef pa_stream_state_t mal_pa_stream_state_t; +typedef pa_stream_state_t ma_pa_stream_state_t; #define MA_PA_STREAM_UNCONNECTED PA_STREAM_UNCONNECTED #define MA_PA_STREAM_CREATING PA_STREAM_CREATING #define MA_PA_STREAM_READY PA_STREAM_READY #define MA_PA_STREAM_FAILED PA_STREAM_FAILED #define MA_PA_STREAM_TERMINATED PA_STREAM_TERMINATED -typedef pa_operation_state_t mal_pa_operation_state_t; +typedef pa_operation_state_t ma_pa_operation_state_t; #define MA_PA_OPERATION_RUNNING PA_OPERATION_RUNNING #define MA_PA_OPERATION_DONE PA_OPERATION_DONE #define MA_PA_OPERATION_CANCELLED PA_OPERATION_CANCELLED -typedef pa_sink_state_t mal_pa_sink_state_t; +typedef pa_sink_state_t ma_pa_sink_state_t; #define MA_PA_SINK_INVALID_STATE PA_SINK_INVALID_STATE #define MA_PA_SINK_RUNNING PA_SINK_RUNNING #define MA_PA_SINK_IDLE PA_SINK_IDLE #define MA_PA_SINK_SUSPENDED PA_SINK_SUSPENDED -typedef pa_source_state_t mal_pa_source_state_t; +typedef pa_source_state_t ma_pa_source_state_t; #define MA_PA_SOURCE_INVALID_STATE PA_SOURCE_INVALID_STATE #define MA_PA_SOURCE_RUNNING PA_SOURCE_RUNNING #define MA_PA_SOURCE_IDLE PA_SOURCE_IDLE #define MA_PA_SOURCE_SUSPENDED PA_SOURCE_SUSPENDED -typedef pa_seek_mode_t mal_pa_seek_mode_t; +typedef pa_seek_mode_t ma_pa_seek_mode_t; #define MA_PA_SEEK_RELATIVE PA_SEEK_RELATIVE #define MA_PA_SEEK_ABSOLUTE PA_SEEK_ABSOLUTE #define MA_PA_SEEK_RELATIVE_ON_READ PA_SEEK_RELATIVE_ON_READ #define MA_PA_SEEK_RELATIVE_END PA_SEEK_RELATIVE_END -typedef pa_channel_position_t mal_pa_channel_position_t; +typedef pa_channel_position_t ma_pa_channel_position_t; #define MA_PA_CHANNEL_POSITION_INVALID PA_CHANNEL_POSITION_INVALID #define MA_PA_CHANNEL_POSITION_MONO PA_CHANNEL_POSITION_MONO #define MA_PA_CHANNEL_POSITION_FRONT_LEFT PA_CHANNEL_POSITION_FRONT_LEFT @@ -13201,7 +13201,7 @@ typedef pa_channel_position_t mal_pa_channel_position_t; #define MA_PA_CHANNEL_POSITION_CENTER PA_CHANNEL_POSITION_CENTER #define MA_PA_CHANNEL_POSITION_SUBWOOFER PA_CHANNEL_POSITION_SUBWOOFER -typedef pa_channel_map_def_t mal_pa_channel_map_def_t; +typedef pa_channel_map_def_t ma_pa_channel_map_def_t; #define MA_PA_CHANNEL_MAP_AIFF PA_CHANNEL_MAP_AIFF #define MA_PA_CHANNEL_MAP_ALSA PA_CHANNEL_MAP_ALSA #define MA_PA_CHANNEL_MAP_AUX PA_CHANNEL_MAP_AUX @@ -13209,7 +13209,7 @@ typedef pa_channel_map_def_t mal_pa_channel_map_def_t; #define MA_PA_CHANNEL_MAP_OSS PA_CHANNEL_MAP_OSS #define MA_PA_CHANNEL_MAP_DEFAULT PA_CHANNEL_MAP_DEFAULT -typedef pa_sample_format_t mal_pa_sample_format_t; +typedef pa_sample_format_t ma_pa_sample_format_t; #define MA_PA_SAMPLE_INVALID PA_SAMPLE_INVALID #define MA_PA_SAMPLE_U8 PA_SAMPLE_U8 #define MA_PA_SAMPLE_ALAW PA_SAMPLE_ALAW @@ -13225,25 +13225,25 @@ typedef pa_sample_format_t mal_pa_sample_format_t; #define MA_PA_SAMPLE_S24_32LE PA_SAMPLE_S24_32LE #define MA_PA_SAMPLE_S24_32BE PA_SAMPLE_S24_32BE -typedef pa_mainloop mal_pa_mainloop; -typedef pa_mainloop_api mal_pa_mainloop_api; -typedef pa_context mal_pa_context; -typedef pa_operation mal_pa_operation; -typedef pa_stream mal_pa_stream; -typedef pa_spawn_api mal_pa_spawn_api; -typedef pa_buffer_attr mal_pa_buffer_attr; -typedef pa_channel_map mal_pa_channel_map; -typedef pa_cvolume mal_pa_cvolume; -typedef pa_sample_spec mal_pa_sample_spec; -typedef pa_sink_info mal_pa_sink_info; -typedef pa_source_info mal_pa_source_info; +typedef pa_mainloop ma_pa_mainloop; +typedef pa_mainloop_api ma_pa_mainloop_api; +typedef pa_context ma_pa_context; +typedef pa_operation ma_pa_operation; +typedef pa_stream ma_pa_stream; +typedef pa_spawn_api ma_pa_spawn_api; +typedef pa_buffer_attr ma_pa_buffer_attr; +typedef pa_channel_map ma_pa_channel_map; +typedef pa_cvolume ma_pa_cvolume; +typedef pa_sample_spec ma_pa_sample_spec; +typedef pa_sink_info ma_pa_sink_info; +typedef pa_source_info ma_pa_source_info; -typedef pa_context_notify_cb_t mal_pa_context_notify_cb_t; -typedef pa_sink_info_cb_t mal_pa_sink_info_cb_t; -typedef pa_source_info_cb_t mal_pa_source_info_cb_t; -typedef pa_stream_success_cb_t mal_pa_stream_success_cb_t; -typedef pa_stream_request_cb_t mal_pa_stream_request_cb_t; -typedef pa_free_cb_t mal_pa_free_cb_t; +typedef pa_context_notify_cb_t ma_pa_context_notify_cb_t; +typedef pa_sink_info_cb_t ma_pa_sink_info_cb_t; +typedef pa_source_info_cb_t ma_pa_source_info_cb_t; +typedef pa_stream_success_cb_t ma_pa_stream_success_cb_t; +typedef pa_stream_request_cb_t ma_pa_stream_request_cb_t; +typedef pa_free_cb_t ma_pa_free_cb_t; #else #define MA_PA_OK 0 #define MA_PA_ERR_ACCESS 1 @@ -13253,12 +13253,12 @@ typedef pa_free_cb_t mal_pa_free_cb_t; #define MA_PA_CHANNELS_MAX 32 #define MA_PA_RATE_MAX 384000 -typedef int mal_pa_context_flags_t; +typedef int ma_pa_context_flags_t; #define MA_PA_CONTEXT_NOFLAGS 0x00000000 #define MA_PA_CONTEXT_NOAUTOSPAWN 0x00000001 #define MA_PA_CONTEXT_NOFAIL 0x00000002 -typedef int mal_pa_stream_flags_t; +typedef int ma_pa_stream_flags_t; #define MA_PA_STREAM_NOFLAGS 0x00000000 #define MA_PA_STREAM_START_CORKED 0x00000001 #define MA_PA_STREAM_INTERPOLATE_TIMING 0x00000002 @@ -13281,7 +13281,7 @@ typedef int mal_pa_stream_flags_t; #define MA_PA_STREAM_RELATIVE_VOLUME 0x00040000 #define MA_PA_STREAM_PASSTHROUGH 0x00080000 -typedef int mal_pa_sink_flags_t; +typedef int ma_pa_sink_flags_t; #define MA_PA_SINK_NOFLAGS 0x00000000 #define MA_PA_SINK_HW_VOLUME_CTRL 0x00000001 #define MA_PA_SINK_LATENCY 0x00000002 @@ -13293,7 +13293,7 @@ typedef int mal_pa_sink_flags_t; #define MA_PA_SINK_DYNAMIC_LATENCY 0x00000080 #define MA_PA_SINK_SET_FORMATS 0x00000100 -typedef int mal_pa_source_flags_t; +typedef int ma_pa_source_flags_t; #define MA_PA_SOURCE_NOFLAGS 0x00000000 #define MA_PA_SOURCE_HW_VOLUME_CTRL 0x00000001 #define MA_PA_SOURCE_LATENCY 0x00000002 @@ -13304,7 +13304,7 @@ typedef int mal_pa_source_flags_t; #define MA_PA_SOURCE_DYNAMIC_LATENCY 0x00000040 #define MA_PA_SOURCE_FLAT_VOLUME 0x00000080 -typedef int mal_pa_context_state_t; +typedef int ma_pa_context_state_t; #define MA_PA_CONTEXT_UNCONNECTED 0 #define MA_PA_CONTEXT_CONNECTING 1 #define MA_PA_CONTEXT_AUTHORIZING 2 @@ -13313,37 +13313,37 @@ typedef int mal_pa_context_state_t; #define MA_PA_CONTEXT_FAILED 5 #define MA_PA_CONTEXT_TERMINATED 6 -typedef int mal_pa_stream_state_t; +typedef int ma_pa_stream_state_t; #define MA_PA_STREAM_UNCONNECTED 0 #define MA_PA_STREAM_CREATING 1 #define MA_PA_STREAM_READY 2 #define MA_PA_STREAM_FAILED 3 #define MA_PA_STREAM_TERMINATED 4 -typedef int mal_pa_operation_state_t; +typedef int ma_pa_operation_state_t; #define MA_PA_OPERATION_RUNNING 0 #define MA_PA_OPERATION_DONE 1 #define MA_PA_OPERATION_CANCELLED 2 -typedef int mal_pa_sink_state_t; +typedef int ma_pa_sink_state_t; #define MA_PA_SINK_INVALID_STATE -1 #define MA_PA_SINK_RUNNING 0 #define MA_PA_SINK_IDLE 1 #define MA_PA_SINK_SUSPENDED 2 -typedef int mal_pa_source_state_t; +typedef int ma_pa_source_state_t; #define MA_PA_SOURCE_INVALID_STATE -1 #define MA_PA_SOURCE_RUNNING 0 #define MA_PA_SOURCE_IDLE 1 #define MA_PA_SOURCE_SUSPENDED 2 -typedef int mal_pa_seek_mode_t; +typedef int ma_pa_seek_mode_t; #define MA_PA_SEEK_RELATIVE 0 #define MA_PA_SEEK_ABSOLUTE 1 #define MA_PA_SEEK_RELATIVE_ON_READ 2 #define MA_PA_SEEK_RELATIVE_END 3 -typedef int mal_pa_channel_position_t; +typedef int ma_pa_channel_position_t; #define MA_PA_CHANNEL_POSITION_INVALID -1 #define MA_PA_CHANNEL_POSITION_MONO 0 #define MA_PA_CHANNEL_POSITION_FRONT_LEFT 1 @@ -13401,7 +13401,7 @@ typedef int mal_pa_channel_position_t; #define MA_PA_CHANNEL_POSITION_CENTER MA_PA_CHANNEL_POSITION_FRONT_CENTER #define MA_PA_CHANNEL_POSITION_SUBWOOFER MA_PA_CHANNEL_POSITION_LFE -typedef int mal_pa_channel_map_def_t; +typedef int ma_pa_channel_map_def_t; #define MA_PA_CHANNEL_MAP_AIFF 0 #define MA_PA_CHANNEL_MAP_ALSA 1 #define MA_PA_CHANNEL_MAP_AUX 2 @@ -13409,7 +13409,7 @@ typedef int mal_pa_channel_map_def_t; #define MA_PA_CHANNEL_MAP_OSS 4 #define MA_PA_CHANNEL_MAP_DEFAULT MA_PA_CHANNEL_MAP_AIFF -typedef int mal_pa_sample_format_t; +typedef int ma_pa_sample_format_t; #define MA_PA_SAMPLE_INVALID -1 #define MA_PA_SAMPLE_U8 0 #define MA_PA_SAMPLE_ALAW 1 @@ -13425,159 +13425,159 @@ typedef int mal_pa_sample_format_t; #define MA_PA_SAMPLE_S24_32LE 11 #define MA_PA_SAMPLE_S24_32BE 12 -typedef struct mal_pa_mainloop mal_pa_mainloop; -typedef struct mal_pa_mainloop_api mal_pa_mainloop_api; -typedef struct mal_pa_context mal_pa_context; -typedef struct mal_pa_operation mal_pa_operation; -typedef struct mal_pa_stream mal_pa_stream; -typedef struct mal_pa_spawn_api mal_pa_spawn_api; +typedef struct ma_pa_mainloop ma_pa_mainloop; +typedef struct ma_pa_mainloop_api ma_pa_mainloop_api; +typedef struct ma_pa_context ma_pa_context; +typedef struct ma_pa_operation ma_pa_operation; +typedef struct ma_pa_stream ma_pa_stream; +typedef struct ma_pa_spawn_api ma_pa_spawn_api; typedef struct { - mal_uint32 maxlength; - mal_uint32 tlength; - mal_uint32 prebuf; - mal_uint32 minreq; - mal_uint32 fragsize; -} mal_pa_buffer_attr; + ma_uint32 maxlength; + ma_uint32 tlength; + ma_uint32 prebuf; + ma_uint32 minreq; + ma_uint32 fragsize; +} ma_pa_buffer_attr; typedef struct { - mal_uint8 channels; - mal_pa_channel_position_t map[MA_PA_CHANNELS_MAX]; -} mal_pa_channel_map; + ma_uint8 channels; + ma_pa_channel_position_t map[MA_PA_CHANNELS_MAX]; +} ma_pa_channel_map; typedef struct { - mal_uint8 channels; - mal_uint32 values[MA_PA_CHANNELS_MAX]; -} mal_pa_cvolume; + ma_uint8 channels; + ma_uint32 values[MA_PA_CHANNELS_MAX]; +} ma_pa_cvolume; typedef struct { - mal_pa_sample_format_t format; - mal_uint32 rate; - mal_uint8 channels; -} mal_pa_sample_spec; + ma_pa_sample_format_t format; + ma_uint32 rate; + ma_uint8 channels; +} ma_pa_sample_spec; typedef struct { const char* name; - mal_uint32 index; + ma_uint32 index; const char* description; - mal_pa_sample_spec sample_spec; - mal_pa_channel_map channel_map; - mal_uint32 owner_module; - mal_pa_cvolume volume; + ma_pa_sample_spec sample_spec; + ma_pa_channel_map channel_map; + ma_uint32 owner_module; + ma_pa_cvolume volume; int mute; - mal_uint32 monitor_source; + ma_uint32 monitor_source; const char* monitor_source_name; - mal_uint64 latency; + ma_uint64 latency; const char* driver; - mal_pa_sink_flags_t flags; + ma_pa_sink_flags_t flags; void* proplist; - mal_uint64 configured_latency; - mal_uint32 base_volume; - mal_pa_sink_state_t state; - mal_uint32 n_volume_steps; - mal_uint32 card; - mal_uint32 n_ports; + ma_uint64 configured_latency; + ma_uint32 base_volume; + ma_pa_sink_state_t state; + ma_uint32 n_volume_steps; + ma_uint32 card; + ma_uint32 n_ports; void** ports; void* active_port; - mal_uint8 n_formats; + ma_uint8 n_formats; void** formats; -} mal_pa_sink_info; +} ma_pa_sink_info; typedef struct { const char *name; - mal_uint32 index; + ma_uint32 index; const char *description; - mal_pa_sample_spec sample_spec; - mal_pa_channel_map channel_map; - mal_uint32 owner_module; - mal_pa_cvolume volume; + ma_pa_sample_spec sample_spec; + ma_pa_channel_map channel_map; + ma_uint32 owner_module; + ma_pa_cvolume volume; int mute; - mal_uint32 monitor_of_sink; + ma_uint32 monitor_of_sink; const char *monitor_of_sink_name; - mal_uint64 latency; + ma_uint64 latency; const char *driver; - mal_pa_source_flags_t flags; + ma_pa_source_flags_t flags; void* proplist; - mal_uint64 configured_latency; - mal_uint32 base_volume; - mal_pa_source_state_t state; - mal_uint32 n_volume_steps; - mal_uint32 card; - mal_uint32 n_ports; + ma_uint64 configured_latency; + ma_uint32 base_volume; + ma_pa_source_state_t state; + ma_uint32 n_volume_steps; + ma_uint32 card; + ma_uint32 n_ports; void** ports; void* active_port; - mal_uint8 n_formats; + ma_uint8 n_formats; void** formats; -} mal_pa_source_info; +} ma_pa_source_info; -typedef void (* mal_pa_context_notify_cb_t)(mal_pa_context* c, void* userdata); -typedef void (* mal_pa_sink_info_cb_t) (mal_pa_context* c, const mal_pa_sink_info* i, int eol, void* userdata); -typedef void (* mal_pa_source_info_cb_t) (mal_pa_context* c, const mal_pa_source_info* i, int eol, void* userdata); -typedef void (* mal_pa_stream_success_cb_t)(mal_pa_stream* s, int success, void* userdata); -typedef void (* mal_pa_stream_request_cb_t)(mal_pa_stream* s, size_t nbytes, void* userdata); -typedef void (* mal_pa_free_cb_t) (void* p); +typedef void (* ma_pa_context_notify_cb_t)(ma_pa_context* c, void* userdata); +typedef void (* ma_pa_sink_info_cb_t) (ma_pa_context* c, const ma_pa_sink_info* i, int eol, void* userdata); +typedef void (* ma_pa_source_info_cb_t) (ma_pa_context* c, const ma_pa_source_info* i, int eol, void* userdata); +typedef void (* ma_pa_stream_success_cb_t)(ma_pa_stream* s, int success, void* userdata); +typedef void (* ma_pa_stream_request_cb_t)(ma_pa_stream* s, size_t nbytes, void* userdata); +typedef void (* ma_pa_free_cb_t) (void* p); #endif -typedef mal_pa_mainloop* (* mal_pa_mainloop_new_proc) (); -typedef void (* mal_pa_mainloop_free_proc) (mal_pa_mainloop* m); -typedef mal_pa_mainloop_api* (* mal_pa_mainloop_get_api_proc) (mal_pa_mainloop* m); -typedef int (* mal_pa_mainloop_iterate_proc) (mal_pa_mainloop* m, int block, int* retval); -typedef void (* mal_pa_mainloop_wakeup_proc) (mal_pa_mainloop* m); -typedef mal_pa_context* (* mal_pa_context_new_proc) (mal_pa_mainloop_api* mainloop, const char* name); -typedef void (* mal_pa_context_unref_proc) (mal_pa_context* c); -typedef int (* mal_pa_context_connect_proc) (mal_pa_context* c, const char* server, mal_pa_context_flags_t flags, const mal_pa_spawn_api* api); -typedef void (* mal_pa_context_disconnect_proc) (mal_pa_context* c); -typedef void (* mal_pa_context_set_state_callback_proc) (mal_pa_context* c, mal_pa_context_notify_cb_t cb, void* userdata); -typedef mal_pa_context_state_t (* mal_pa_context_get_state_proc) (mal_pa_context* c); -typedef mal_pa_operation* (* mal_pa_context_get_sink_info_list_proc) (mal_pa_context* c, mal_pa_sink_info_cb_t cb, void* userdata); -typedef mal_pa_operation* (* mal_pa_context_get_source_info_list_proc) (mal_pa_context* c, mal_pa_source_info_cb_t cb, void* userdata); -typedef mal_pa_operation* (* mal_pa_context_get_sink_info_by_name_proc) (mal_pa_context* c, const char* name, mal_pa_sink_info_cb_t cb, void* userdata); -typedef mal_pa_operation* (* mal_pa_context_get_source_info_by_name_proc)(mal_pa_context* c, const char* name, mal_pa_source_info_cb_t cb, void* userdata); -typedef void (* mal_pa_operation_unref_proc) (mal_pa_operation* o); -typedef mal_pa_operation_state_t (* mal_pa_operation_get_state_proc) (mal_pa_operation* o); -typedef mal_pa_channel_map* (* mal_pa_channel_map_init_extend_proc) (mal_pa_channel_map* m, unsigned channels, mal_pa_channel_map_def_t def); -typedef int (* mal_pa_channel_map_valid_proc) (const mal_pa_channel_map* m); -typedef int (* mal_pa_channel_map_compatible_proc) (const mal_pa_channel_map* m, const mal_pa_sample_spec* ss); -typedef mal_pa_stream* (* mal_pa_stream_new_proc) (mal_pa_context* c, const char* name, const mal_pa_sample_spec* ss, const mal_pa_channel_map* map); -typedef void (* mal_pa_stream_unref_proc) (mal_pa_stream* s); -typedef int (* mal_pa_stream_connect_playback_proc) (mal_pa_stream* s, const char* dev, const mal_pa_buffer_attr* attr, mal_pa_stream_flags_t flags, const mal_pa_cvolume* volume, mal_pa_stream* sync_stream); -typedef int (* mal_pa_stream_connect_record_proc) (mal_pa_stream* s, const char* dev, const mal_pa_buffer_attr* attr, mal_pa_stream_flags_t flags); -typedef int (* mal_pa_stream_disconnect_proc) (mal_pa_stream* s); -typedef mal_pa_stream_state_t (* mal_pa_stream_get_state_proc) (mal_pa_stream* s); -typedef const mal_pa_sample_spec* (* mal_pa_stream_get_sample_spec_proc) (mal_pa_stream* s); -typedef const mal_pa_channel_map* (* mal_pa_stream_get_channel_map_proc) (mal_pa_stream* s); -typedef const mal_pa_buffer_attr* (* mal_pa_stream_get_buffer_attr_proc) (mal_pa_stream* s); -typedef mal_pa_operation* (* mal_pa_stream_set_buffer_attr_proc) (mal_pa_stream* s, const mal_pa_buffer_attr* attr, mal_pa_stream_success_cb_t cb, void* userdata); -typedef const char* (* mal_pa_stream_get_device_name_proc) (mal_pa_stream* s); -typedef void (* mal_pa_stream_set_write_callback_proc) (mal_pa_stream* s, mal_pa_stream_request_cb_t cb, void* userdata); -typedef void (* mal_pa_stream_set_read_callback_proc) (mal_pa_stream* s, mal_pa_stream_request_cb_t cb, void* userdata); -typedef mal_pa_operation* (* mal_pa_stream_flush_proc) (mal_pa_stream* s, mal_pa_stream_success_cb_t cb, void* userdata); -typedef mal_pa_operation* (* mal_pa_stream_drain_proc) (mal_pa_stream* s, mal_pa_stream_success_cb_t cb, void* userdata); -typedef int (* mal_pa_stream_is_corked_proc) (mal_pa_stream* s); -typedef mal_pa_operation* (* mal_pa_stream_cork_proc) (mal_pa_stream* s, int b, mal_pa_stream_success_cb_t cb, void* userdata); -typedef mal_pa_operation* (* mal_pa_stream_trigger_proc) (mal_pa_stream* s, mal_pa_stream_success_cb_t cb, void* userdata); -typedef int (* mal_pa_stream_begin_write_proc) (mal_pa_stream* s, void** data, size_t* nbytes); -typedef int (* mal_pa_stream_write_proc) (mal_pa_stream* s, const void* data, size_t nbytes, mal_pa_free_cb_t free_cb, int64_t offset, mal_pa_seek_mode_t seek); -typedef int (* mal_pa_stream_peek_proc) (mal_pa_stream* s, const void** data, size_t* nbytes); -typedef int (* mal_pa_stream_drop_proc) (mal_pa_stream* s); -typedef size_t (* mal_pa_stream_writable_size_proc) (mal_pa_stream* s); -typedef size_t (* mal_pa_stream_readable_size_proc) (mal_pa_stream* s); +typedef ma_pa_mainloop* (* ma_pa_mainloop_new_proc) (); +typedef void (* ma_pa_mainloop_free_proc) (ma_pa_mainloop* m); +typedef ma_pa_mainloop_api* (* ma_pa_mainloop_get_api_proc) (ma_pa_mainloop* m); +typedef int (* ma_pa_mainloop_iterate_proc) (ma_pa_mainloop* m, int block, int* retval); +typedef void (* ma_pa_mainloop_wakeup_proc) (ma_pa_mainloop* m); +typedef ma_pa_context* (* ma_pa_context_new_proc) (ma_pa_mainloop_api* mainloop, const char* name); +typedef void (* ma_pa_context_unref_proc) (ma_pa_context* c); +typedef int (* ma_pa_context_connect_proc) (ma_pa_context* c, const char* server, ma_pa_context_flags_t flags, const ma_pa_spawn_api* api); +typedef void (* ma_pa_context_disconnect_proc) (ma_pa_context* c); +typedef void (* ma_pa_context_set_state_callback_proc) (ma_pa_context* c, ma_pa_context_notify_cb_t cb, void* userdata); +typedef ma_pa_context_state_t (* ma_pa_context_get_state_proc) (ma_pa_context* c); +typedef ma_pa_operation* (* ma_pa_context_get_sink_info_list_proc) (ma_pa_context* c, ma_pa_sink_info_cb_t cb, void* userdata); +typedef ma_pa_operation* (* ma_pa_context_get_source_info_list_proc) (ma_pa_context* c, ma_pa_source_info_cb_t cb, void* userdata); +typedef ma_pa_operation* (* ma_pa_context_get_sink_info_by_name_proc) (ma_pa_context* c, const char* name, ma_pa_sink_info_cb_t cb, void* userdata); +typedef ma_pa_operation* (* ma_pa_context_get_source_info_by_name_proc)(ma_pa_context* c, const char* name, ma_pa_source_info_cb_t cb, void* userdata); +typedef void (* ma_pa_operation_unref_proc) (ma_pa_operation* o); +typedef ma_pa_operation_state_t (* ma_pa_operation_get_state_proc) (ma_pa_operation* o); +typedef ma_pa_channel_map* (* ma_pa_channel_map_init_extend_proc) (ma_pa_channel_map* m, unsigned channels, ma_pa_channel_map_def_t def); +typedef int (* ma_pa_channel_map_valid_proc) (const ma_pa_channel_map* m); +typedef int (* ma_pa_channel_map_compatible_proc) (const ma_pa_channel_map* m, const ma_pa_sample_spec* ss); +typedef ma_pa_stream* (* ma_pa_stream_new_proc) (ma_pa_context* c, const char* name, const ma_pa_sample_spec* ss, const ma_pa_channel_map* map); +typedef void (* ma_pa_stream_unref_proc) (ma_pa_stream* s); +typedef int (* ma_pa_stream_connect_playback_proc) (ma_pa_stream* s, const char* dev, const ma_pa_buffer_attr* attr, ma_pa_stream_flags_t flags, const ma_pa_cvolume* volume, ma_pa_stream* sync_stream); +typedef int (* ma_pa_stream_connect_record_proc) (ma_pa_stream* s, const char* dev, const ma_pa_buffer_attr* attr, ma_pa_stream_flags_t flags); +typedef int (* ma_pa_stream_disconnect_proc) (ma_pa_stream* s); +typedef ma_pa_stream_state_t (* ma_pa_stream_get_state_proc) (ma_pa_stream* s); +typedef const ma_pa_sample_spec* (* ma_pa_stream_get_sample_spec_proc) (ma_pa_stream* s); +typedef const ma_pa_channel_map* (* ma_pa_stream_get_channel_map_proc) (ma_pa_stream* s); +typedef const ma_pa_buffer_attr* (* ma_pa_stream_get_buffer_attr_proc) (ma_pa_stream* s); +typedef ma_pa_operation* (* ma_pa_stream_set_buffer_attr_proc) (ma_pa_stream* s, const ma_pa_buffer_attr* attr, ma_pa_stream_success_cb_t cb, void* userdata); +typedef const char* (* ma_pa_stream_get_device_name_proc) (ma_pa_stream* s); +typedef void (* ma_pa_stream_set_write_callback_proc) (ma_pa_stream* s, ma_pa_stream_request_cb_t cb, void* userdata); +typedef void (* ma_pa_stream_set_read_callback_proc) (ma_pa_stream* s, ma_pa_stream_request_cb_t cb, void* userdata); +typedef ma_pa_operation* (* ma_pa_stream_flush_proc) (ma_pa_stream* s, ma_pa_stream_success_cb_t cb, void* userdata); +typedef ma_pa_operation* (* ma_pa_stream_drain_proc) (ma_pa_stream* s, ma_pa_stream_success_cb_t cb, void* userdata); +typedef int (* ma_pa_stream_is_corked_proc) (ma_pa_stream* s); +typedef ma_pa_operation* (* ma_pa_stream_cork_proc) (ma_pa_stream* s, int b, ma_pa_stream_success_cb_t cb, void* userdata); +typedef ma_pa_operation* (* ma_pa_stream_trigger_proc) (ma_pa_stream* s, ma_pa_stream_success_cb_t cb, void* userdata); +typedef int (* ma_pa_stream_begin_write_proc) (ma_pa_stream* s, void** data, size_t* nbytes); +typedef int (* ma_pa_stream_write_proc) (ma_pa_stream* s, const void* data, size_t nbytes, ma_pa_free_cb_t free_cb, int64_t offset, ma_pa_seek_mode_t seek); +typedef int (* ma_pa_stream_peek_proc) (ma_pa_stream* s, const void** data, size_t* nbytes); +typedef int (* ma_pa_stream_drop_proc) (ma_pa_stream* s); +typedef size_t (* ma_pa_stream_writable_size_proc) (ma_pa_stream* s); +typedef size_t (* ma_pa_stream_readable_size_proc) (ma_pa_stream* s); typedef struct { - mal_uint32 count; - mal_uint32 capacity; - mal_device_info* pInfo; -} mal_pulse_device_enum_data; + ma_uint32 count; + ma_uint32 capacity; + ma_device_info* pInfo; +} ma_pulse_device_enum_data; -mal_result mal_result_from_pulse(int result) +ma_result ma_result_from_pulse(int result) { switch (result) { case MA_PA_OK: return MA_SUCCESS; @@ -13589,62 +13589,62 @@ mal_result mal_result_from_pulse(int result) } #if 0 -mal_pa_sample_format_t mal_format_to_pulse(mal_format format) +ma_pa_sample_format_t ma_format_to_pulse(ma_format format) { - if (mal_is_little_endian()) { + if (ma_is_little_endian()) { switch (format) { - case mal_format_s16: return MA_PA_SAMPLE_S16LE; - case mal_format_s24: return MA_PA_SAMPLE_S24LE; - case mal_format_s32: return MA_PA_SAMPLE_S32LE; - case mal_format_f32: return MA_PA_SAMPLE_FLOAT32LE; + case ma_format_s16: return MA_PA_SAMPLE_S16LE; + case ma_format_s24: return MA_PA_SAMPLE_S24LE; + case ma_format_s32: return MA_PA_SAMPLE_S32LE; + case ma_format_f32: return MA_PA_SAMPLE_FLOAT32LE; default: break; } } else { switch (format) { - case mal_format_s16: return MA_PA_SAMPLE_S16BE; - case mal_format_s24: return MA_PA_SAMPLE_S24BE; - case mal_format_s32: return MA_PA_SAMPLE_S32BE; - case mal_format_f32: return MA_PA_SAMPLE_FLOAT32BE; + case ma_format_s16: return MA_PA_SAMPLE_S16BE; + case ma_format_s24: return MA_PA_SAMPLE_S24BE; + case ma_format_s32: return MA_PA_SAMPLE_S32BE; + case ma_format_f32: return MA_PA_SAMPLE_FLOAT32BE; default: break; } } // Endian agnostic. switch (format) { - case mal_format_u8: return MA_PA_SAMPLE_U8; + case ma_format_u8: return MA_PA_SAMPLE_U8; default: return MA_PA_SAMPLE_INVALID; } } #endif -mal_format mal_format_from_pulse(mal_pa_sample_format_t format) +ma_format ma_format_from_pulse(ma_pa_sample_format_t format) { - if (mal_is_little_endian()) { + if (ma_is_little_endian()) { switch (format) { - case MA_PA_SAMPLE_S16LE: return mal_format_s16; - case MA_PA_SAMPLE_S24LE: return mal_format_s24; - case MA_PA_SAMPLE_S32LE: return mal_format_s32; - case MA_PA_SAMPLE_FLOAT32LE: return mal_format_f32; + case MA_PA_SAMPLE_S16LE: return ma_format_s16; + case MA_PA_SAMPLE_S24LE: return ma_format_s24; + case MA_PA_SAMPLE_S32LE: return ma_format_s32; + case MA_PA_SAMPLE_FLOAT32LE: return ma_format_f32; default: break; } } else { switch (format) { - case MA_PA_SAMPLE_S16BE: return mal_format_s16; - case MA_PA_SAMPLE_S24BE: return mal_format_s24; - case MA_PA_SAMPLE_S32BE: return mal_format_s32; - case MA_PA_SAMPLE_FLOAT32BE: return mal_format_f32; + case MA_PA_SAMPLE_S16BE: return ma_format_s16; + case MA_PA_SAMPLE_S24BE: return ma_format_s24; + case MA_PA_SAMPLE_S32BE: return ma_format_s32; + case MA_PA_SAMPLE_FLOAT32BE: return ma_format_f32; default: break; } } // Endian agnostic. switch (format) { - case MA_PA_SAMPLE_U8: return mal_format_u8; - default: return mal_format_unknown; + case MA_PA_SAMPLE_U8: return ma_format_u8; + default: return ma_format_unknown; } } -mal_channel mal_channel_position_from_pulse(mal_pa_channel_position_t position) +ma_channel ma_channel_position_from_pulse(ma_pa_channel_position_t position) { switch (position) { @@ -13705,7 +13705,7 @@ mal_channel mal_channel_position_from_pulse(mal_pa_channel_position_t position) } #if 0 -mal_pa_channel_position_t mal_channel_position_to_pulse(mal_channel position) +ma_pa_channel_position_t ma_channel_position_to_pulse(ma_channel position) { switch (position) { @@ -13742,148 +13742,148 @@ mal_pa_channel_position_t mal_channel_position_to_pulse(mal_channel position) case MA_CHANNEL_30: return MA_PA_CHANNEL_POSITION_AUX29; case MA_CHANNEL_31: return MA_PA_CHANNEL_POSITION_AUX30; case MA_CHANNEL_32: return MA_PA_CHANNEL_POSITION_AUX31; - default: return (mal_pa_channel_position_t)position; + default: return (ma_pa_channel_position_t)position; } } #endif -mal_result mal_wait_for_operation__pulse(mal_context* pContext, mal_pa_mainloop* pMainLoop, mal_pa_operation* pOP) +ma_result ma_wait_for_operation__pulse(ma_context* pContext, ma_pa_mainloop* pMainLoop, ma_pa_operation* pOP) { - mal_assert(pContext != NULL); - mal_assert(pMainLoop != NULL); - mal_assert(pOP != NULL); + ma_assert(pContext != NULL); + ma_assert(pMainLoop != NULL); + ma_assert(pOP != NULL); - while (((mal_pa_operation_get_state_proc)pContext->pulse.pa_operation_get_state)(pOP) == MA_PA_OPERATION_RUNNING) { - int error = ((mal_pa_mainloop_iterate_proc)pContext->pulse.pa_mainloop_iterate)(pMainLoop, 1, NULL); + while (((ma_pa_operation_get_state_proc)pContext->pulse.pa_operation_get_state)(pOP) == MA_PA_OPERATION_RUNNING) { + int error = ((ma_pa_mainloop_iterate_proc)pContext->pulse.pa_mainloop_iterate)(pMainLoop, 1, NULL); if (error < 0) { - return mal_result_from_pulse(error); + return ma_result_from_pulse(error); } } return MA_SUCCESS; } -mal_result mal_device__wait_for_operation__pulse(mal_device* pDevice, mal_pa_operation* pOP) +ma_result ma_device__wait_for_operation__pulse(ma_device* pDevice, ma_pa_operation* pOP) { - mal_assert(pDevice != NULL); - mal_assert(pOP != NULL); + ma_assert(pDevice != NULL); + ma_assert(pOP != NULL); - return mal_wait_for_operation__pulse(pDevice->pContext, (mal_pa_mainloop*)pDevice->pulse.pMainLoop, pOP); + return ma_wait_for_operation__pulse(pDevice->pContext, (ma_pa_mainloop*)pDevice->pulse.pMainLoop, pOP); } -mal_bool32 mal_context_is_device_id_equal__pulse(mal_context* pContext, const mal_device_id* pID0, const mal_device_id* pID1) +ma_bool32 ma_context_is_device_id_equal__pulse(ma_context* pContext, const ma_device_id* pID0, const ma_device_id* pID1) { - mal_assert(pContext != NULL); - mal_assert(pID0 != NULL); - mal_assert(pID1 != NULL); + ma_assert(pContext != NULL); + ma_assert(pID0 != NULL); + ma_assert(pID1 != NULL); (void)pContext; - return mal_strcmp(pID0->pulse, pID1->pulse) == 0; + return ma_strcmp(pID0->pulse, pID1->pulse) == 0; } typedef struct { - mal_context* pContext; - mal_enum_devices_callback_proc callback; + ma_context* pContext; + ma_enum_devices_callback_proc callback; void* pUserData; - mal_bool32 isTerminated; -} mal_context_enumerate_devices_callback_data__pulse; + ma_bool32 isTerminated; +} ma_context_enumerate_devices_callback_data__pulse; -void mal_context_enumerate_devices_sink_callback__pulse(mal_pa_context* pPulseContext, const mal_pa_sink_info* pSinkInfo, int endOfList, void* pUserData) +void ma_context_enumerate_devices_sink_callback__pulse(ma_pa_context* pPulseContext, const ma_pa_sink_info* pSinkInfo, int endOfList, void* pUserData) { - mal_context_enumerate_devices_callback_data__pulse* pData = (mal_context_enumerate_devices_callback_data__pulse*)pUserData; - mal_assert(pData != NULL); + ma_context_enumerate_devices_callback_data__pulse* pData = (ma_context_enumerate_devices_callback_data__pulse*)pUserData; + ma_assert(pData != NULL); if (endOfList || pData->isTerminated) { return; } - mal_device_info deviceInfo; - mal_zero_object(&deviceInfo); + ma_device_info deviceInfo; + ma_zero_object(&deviceInfo); // The name from PulseAudio is the ID for miniaudio. if (pSinkInfo->name != NULL) { - mal_strncpy_s(deviceInfo.id.pulse, sizeof(deviceInfo.id.pulse), pSinkInfo->name, (size_t)-1); + ma_strncpy_s(deviceInfo.id.pulse, sizeof(deviceInfo.id.pulse), pSinkInfo->name, (size_t)-1); } // The description from PulseAudio is the name for miniaudio. if (pSinkInfo->description != NULL) { - mal_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), pSinkInfo->description, (size_t)-1); + ma_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), pSinkInfo->description, (size_t)-1); } - pData->isTerminated = !pData->callback(pData->pContext, mal_device_type_playback, &deviceInfo, pData->pUserData); + pData->isTerminated = !pData->callback(pData->pContext, ma_device_type_playback, &deviceInfo, pData->pUserData); } -void mal_context_enumerate_devices_source_callback__pulse(mal_pa_context* pPulseContext, const mal_pa_source_info* pSinkInfo, int endOfList, void* pUserData) +void ma_context_enumerate_devices_source_callback__pulse(ma_pa_context* pPulseContext, const ma_pa_source_info* pSinkInfo, int endOfList, void* pUserData) { - mal_context_enumerate_devices_callback_data__pulse* pData = (mal_context_enumerate_devices_callback_data__pulse*)pUserData; - mal_assert(pData != NULL); + ma_context_enumerate_devices_callback_data__pulse* pData = (ma_context_enumerate_devices_callback_data__pulse*)pUserData; + ma_assert(pData != NULL); if (endOfList || pData->isTerminated) { return; } - mal_device_info deviceInfo; - mal_zero_object(&deviceInfo); + ma_device_info deviceInfo; + ma_zero_object(&deviceInfo); // The name from PulseAudio is the ID for miniaudio. if (pSinkInfo->name != NULL) { - mal_strncpy_s(deviceInfo.id.pulse, sizeof(deviceInfo.id.pulse), pSinkInfo->name, (size_t)-1); + ma_strncpy_s(deviceInfo.id.pulse, sizeof(deviceInfo.id.pulse), pSinkInfo->name, (size_t)-1); } // The description from PulseAudio is the name for miniaudio. if (pSinkInfo->description != NULL) { - mal_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), pSinkInfo->description, (size_t)-1); + ma_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), pSinkInfo->description, (size_t)-1); } - pData->isTerminated = !pData->callback(pData->pContext, mal_device_type_capture, &deviceInfo, pData->pUserData); + pData->isTerminated = !pData->callback(pData->pContext, ma_device_type_capture, &deviceInfo, pData->pUserData); } -mal_result mal_context_enumerate_devices__pulse(mal_context* pContext, mal_enum_devices_callback_proc callback, void* pUserData) +ma_result ma_context_enumerate_devices__pulse(ma_context* pContext, ma_enum_devices_callback_proc callback, void* pUserData) { - mal_assert(pContext != NULL); - mal_assert(callback != NULL); + ma_assert(pContext != NULL); + ma_assert(callback != NULL); - mal_result result = MA_SUCCESS; + ma_result result = MA_SUCCESS; - mal_context_enumerate_devices_callback_data__pulse callbackData; + ma_context_enumerate_devices_callback_data__pulse callbackData; callbackData.pContext = pContext; callbackData.callback = callback; callbackData.pUserData = pUserData; callbackData.isTerminated = MA_FALSE; - mal_pa_operation* pOP = NULL; + ma_pa_operation* pOP = NULL; - mal_pa_mainloop* pMainLoop = ((mal_pa_mainloop_new_proc)pContext->pulse.pa_mainloop_new)(); + ma_pa_mainloop* pMainLoop = ((ma_pa_mainloop_new_proc)pContext->pulse.pa_mainloop_new)(); if (pMainLoop == NULL) { return MA_FAILED_TO_INIT_BACKEND; } - mal_pa_mainloop_api* pAPI = ((mal_pa_mainloop_get_api_proc)pContext->pulse.pa_mainloop_get_api)(pMainLoop); + ma_pa_mainloop_api* pAPI = ((ma_pa_mainloop_get_api_proc)pContext->pulse.pa_mainloop_get_api)(pMainLoop); if (pAPI == NULL) { - ((mal_pa_mainloop_free_proc)pContext->pulse.pa_mainloop_free)(pMainLoop); + ((ma_pa_mainloop_free_proc)pContext->pulse.pa_mainloop_free)(pMainLoop); return MA_FAILED_TO_INIT_BACKEND; } - mal_pa_context* pPulseContext = ((mal_pa_context_new_proc)pContext->pulse.pa_context_new)(pAPI, pContext->config.pulse.pApplicationName); + ma_pa_context* pPulseContext = ((ma_pa_context_new_proc)pContext->pulse.pa_context_new)(pAPI, pContext->config.pulse.pApplicationName); if (pPulseContext == NULL) { - ((mal_pa_mainloop_free_proc)pContext->pulse.pa_mainloop_free)(pMainLoop); + ((ma_pa_mainloop_free_proc)pContext->pulse.pa_mainloop_free)(pMainLoop); return MA_FAILED_TO_INIT_BACKEND; } - int error = ((mal_pa_context_connect_proc)pContext->pulse.pa_context_connect)(pPulseContext, pContext->config.pulse.pServerName, 0, NULL); + int error = ((ma_pa_context_connect_proc)pContext->pulse.pa_context_connect)(pPulseContext, pContext->config.pulse.pServerName, 0, NULL); if (error != MA_PA_OK) { - ((mal_pa_context_unref_proc)pContext->pulse.pa_context_unref)(pPulseContext); - ((mal_pa_mainloop_free_proc)pContext->pulse.pa_mainloop_free)(pMainLoop); - return mal_result_from_pulse(error); + ((ma_pa_context_unref_proc)pContext->pulse.pa_context_unref)(pPulseContext); + ((ma_pa_mainloop_free_proc)pContext->pulse.pa_mainloop_free)(pMainLoop); + return ma_result_from_pulse(error); } - while (((mal_pa_context_get_state_proc)pContext->pulse.pa_context_get_state)(pPulseContext) != MA_PA_CONTEXT_READY) { - error = ((mal_pa_mainloop_iterate_proc)pContext->pulse.pa_mainloop_iterate)(pMainLoop, 1, NULL); + while (((ma_pa_context_get_state_proc)pContext->pulse.pa_context_get_state)(pPulseContext) != MA_PA_CONTEXT_READY) { + error = ((ma_pa_mainloop_iterate_proc)pContext->pulse.pa_mainloop_iterate)(pMainLoop, 1, NULL); if (error < 0) { - result = mal_result_from_pulse(error); + result = ma_result_from_pulse(error); goto done; } } @@ -13891,14 +13891,14 @@ mal_result mal_context_enumerate_devices__pulse(mal_context* pContext, mal_enum_ // Playback. if (!callbackData.isTerminated) { - pOP = ((mal_pa_context_get_sink_info_list_proc)pContext->pulse.pa_context_get_sink_info_list)(pPulseContext, mal_context_enumerate_devices_sink_callback__pulse, &callbackData); + pOP = ((ma_pa_context_get_sink_info_list_proc)pContext->pulse.pa_context_get_sink_info_list)(pPulseContext, ma_context_enumerate_devices_sink_callback__pulse, &callbackData); if (pOP == NULL) { result = MA_ERROR; goto done; } - result = mal_wait_for_operation__pulse(pContext, pMainLoop, pOP); - ((mal_pa_operation_unref_proc)pContext->pulse.pa_operation_unref)(pOP); + result = ma_wait_for_operation__pulse(pContext, pMainLoop, pOP); + ((ma_pa_operation_unref_proc)pContext->pulse.pa_operation_unref)(pOP); if (result != MA_SUCCESS) { goto done; } @@ -13907,49 +13907,49 @@ mal_result mal_context_enumerate_devices__pulse(mal_context* pContext, mal_enum_ // Capture. if (!callbackData.isTerminated) { - pOP = ((mal_pa_context_get_source_info_list_proc)pContext->pulse.pa_context_get_source_info_list)(pPulseContext, mal_context_enumerate_devices_source_callback__pulse, &callbackData); + pOP = ((ma_pa_context_get_source_info_list_proc)pContext->pulse.pa_context_get_source_info_list)(pPulseContext, ma_context_enumerate_devices_source_callback__pulse, &callbackData); if (pOP == NULL) { result = MA_ERROR; goto done; } - result = mal_wait_for_operation__pulse(pContext, pMainLoop, pOP); - ((mal_pa_operation_unref_proc)pContext->pulse.pa_operation_unref)(pOP); + result = ma_wait_for_operation__pulse(pContext, pMainLoop, pOP); + ((ma_pa_operation_unref_proc)pContext->pulse.pa_operation_unref)(pOP); if (result != MA_SUCCESS) { goto done; } } done: - ((mal_pa_context_disconnect_proc)pContext->pulse.pa_context_disconnect)(pPulseContext); - ((mal_pa_context_unref_proc)pContext->pulse.pa_context_unref)(pPulseContext); - ((mal_pa_mainloop_free_proc)pContext->pulse.pa_mainloop_free)(pMainLoop); + ((ma_pa_context_disconnect_proc)pContext->pulse.pa_context_disconnect)(pPulseContext); + ((ma_pa_context_unref_proc)pContext->pulse.pa_context_unref)(pPulseContext); + ((ma_pa_mainloop_free_proc)pContext->pulse.pa_mainloop_free)(pMainLoop); return result; } typedef struct { - mal_device_info* pDeviceInfo; - mal_bool32 foundDevice; -} mal_context_get_device_info_callback_data__pulse; + ma_device_info* pDeviceInfo; + ma_bool32 foundDevice; +} ma_context_get_device_info_callback_data__pulse; -void mal_context_get_device_info_sink_callback__pulse(mal_pa_context* pPulseContext, const mal_pa_sink_info* pInfo, int endOfList, void* pUserData) +void ma_context_get_device_info_sink_callback__pulse(ma_pa_context* pPulseContext, const ma_pa_sink_info* pInfo, int endOfList, void* pUserData) { if (endOfList > 0) { return; } - mal_context_get_device_info_callback_data__pulse* pData = (mal_context_get_device_info_callback_data__pulse*)pUserData; - mal_assert(pData != NULL); + ma_context_get_device_info_callback_data__pulse* pData = (ma_context_get_device_info_callback_data__pulse*)pUserData; + ma_assert(pData != NULL); pData->foundDevice = MA_TRUE; if (pInfo->name != NULL) { - mal_strncpy_s(pData->pDeviceInfo->id.pulse, sizeof(pData->pDeviceInfo->id.pulse), pInfo->name, (size_t)-1); + ma_strncpy_s(pData->pDeviceInfo->id.pulse, sizeof(pData->pDeviceInfo->id.pulse), pInfo->name, (size_t)-1); } if (pInfo->description != NULL) { - mal_strncpy_s(pData->pDeviceInfo->name, sizeof(pData->pDeviceInfo->name), pInfo->description, (size_t)-1); + ma_strncpy_s(pData->pDeviceInfo->name, sizeof(pData->pDeviceInfo->name), pInfo->description, (size_t)-1); } pData->pDeviceInfo->minChannels = pInfo->sample_spec.channels; @@ -13957,25 +13957,25 @@ void mal_context_get_device_info_sink_callback__pulse(mal_pa_context* pPulseCont pData->pDeviceInfo->minSampleRate = pInfo->sample_spec.rate; pData->pDeviceInfo->maxSampleRate = pInfo->sample_spec.rate; pData->pDeviceInfo->formatCount = 1; - pData->pDeviceInfo->formats[0] = mal_format_from_pulse(pInfo->sample_spec.format); + pData->pDeviceInfo->formats[0] = ma_format_from_pulse(pInfo->sample_spec.format); } -void mal_context_get_device_info_source_callback__pulse(mal_pa_context* pPulseContext, const mal_pa_source_info* pInfo, int endOfList, void* pUserData) +void ma_context_get_device_info_source_callback__pulse(ma_pa_context* pPulseContext, const ma_pa_source_info* pInfo, int endOfList, void* pUserData) { if (endOfList > 0) { return; } - mal_context_get_device_info_callback_data__pulse* pData = (mal_context_get_device_info_callback_data__pulse*)pUserData; - mal_assert(pData != NULL); + ma_context_get_device_info_callback_data__pulse* pData = (ma_context_get_device_info_callback_data__pulse*)pUserData; + ma_assert(pData != NULL); pData->foundDevice = MA_TRUE; if (pInfo->name != NULL) { - mal_strncpy_s(pData->pDeviceInfo->id.pulse, sizeof(pData->pDeviceInfo->id.pulse), pInfo->name, (size_t)-1); + ma_strncpy_s(pData->pDeviceInfo->id.pulse, sizeof(pData->pDeviceInfo->id.pulse), pInfo->name, (size_t)-1); } if (pInfo->description != NULL) { - mal_strncpy_s(pData->pDeviceInfo->name, sizeof(pData->pDeviceInfo->name), pInfo->description, (size_t)-1); + ma_strncpy_s(pData->pDeviceInfo->name, sizeof(pData->pDeviceInfo->name), pInfo->description, (size_t)-1); } pData->pDeviceInfo->minChannels = pInfo->sample_spec.channels; @@ -13983,67 +13983,67 @@ void mal_context_get_device_info_source_callback__pulse(mal_pa_context* pPulseCo pData->pDeviceInfo->minSampleRate = pInfo->sample_spec.rate; pData->pDeviceInfo->maxSampleRate = pInfo->sample_spec.rate; pData->pDeviceInfo->formatCount = 1; - pData->pDeviceInfo->formats[0] = mal_format_from_pulse(pInfo->sample_spec.format); + pData->pDeviceInfo->formats[0] = ma_format_from_pulse(pInfo->sample_spec.format); } -mal_result mal_context_get_device_info__pulse(mal_context* pContext, mal_device_type deviceType, const mal_device_id* pDeviceID, mal_share_mode shareMode, mal_device_info* pDeviceInfo) +ma_result ma_context_get_device_info__pulse(ma_context* pContext, ma_device_type deviceType, const ma_device_id* pDeviceID, ma_share_mode shareMode, ma_device_info* pDeviceInfo) { - mal_assert(pContext != NULL); + ma_assert(pContext != NULL); /* No exclusive mode with the PulseAudio backend. */ - if (shareMode == mal_share_mode_exclusive) { + if (shareMode == ma_share_mode_exclusive) { return MA_SHARE_MODE_NOT_SUPPORTED; } - mal_result result = MA_SUCCESS; + ma_result result = MA_SUCCESS; - mal_context_get_device_info_callback_data__pulse callbackData; + ma_context_get_device_info_callback_data__pulse callbackData; callbackData.pDeviceInfo = pDeviceInfo; callbackData.foundDevice = MA_FALSE; - mal_pa_operation* pOP = NULL; + ma_pa_operation* pOP = NULL; - mal_pa_mainloop* pMainLoop = ((mal_pa_mainloop_new_proc)pContext->pulse.pa_mainloop_new)(); + ma_pa_mainloop* pMainLoop = ((ma_pa_mainloop_new_proc)pContext->pulse.pa_mainloop_new)(); if (pMainLoop == NULL) { return MA_FAILED_TO_INIT_BACKEND; } - mal_pa_mainloop_api* pAPI = ((mal_pa_mainloop_get_api_proc)pContext->pulse.pa_mainloop_get_api)(pMainLoop); + ma_pa_mainloop_api* pAPI = ((ma_pa_mainloop_get_api_proc)pContext->pulse.pa_mainloop_get_api)(pMainLoop); if (pAPI == NULL) { - ((mal_pa_mainloop_free_proc)pContext->pulse.pa_mainloop_free)(pMainLoop); + ((ma_pa_mainloop_free_proc)pContext->pulse.pa_mainloop_free)(pMainLoop); return MA_FAILED_TO_INIT_BACKEND; } - mal_pa_context* pPulseContext = ((mal_pa_context_new_proc)pContext->pulse.pa_context_new)(pAPI, pContext->config.pulse.pApplicationName); + ma_pa_context* pPulseContext = ((ma_pa_context_new_proc)pContext->pulse.pa_context_new)(pAPI, pContext->config.pulse.pApplicationName); if (pPulseContext == NULL) { - ((mal_pa_mainloop_free_proc)pContext->pulse.pa_mainloop_free)(pMainLoop); + ((ma_pa_mainloop_free_proc)pContext->pulse.pa_mainloop_free)(pMainLoop); return MA_FAILED_TO_INIT_BACKEND; } - int error = ((mal_pa_context_connect_proc)pContext->pulse.pa_context_connect)(pPulseContext, pContext->config.pulse.pServerName, 0, NULL); + int error = ((ma_pa_context_connect_proc)pContext->pulse.pa_context_connect)(pPulseContext, pContext->config.pulse.pServerName, 0, NULL); if (error != MA_PA_OK) { - ((mal_pa_context_unref_proc)pContext->pulse.pa_context_unref)(pPulseContext); - ((mal_pa_mainloop_free_proc)pContext->pulse.pa_mainloop_free)(pMainLoop); - return mal_result_from_pulse(error); + ((ma_pa_context_unref_proc)pContext->pulse.pa_context_unref)(pPulseContext); + ((ma_pa_mainloop_free_proc)pContext->pulse.pa_mainloop_free)(pMainLoop); + return ma_result_from_pulse(error); } - while (((mal_pa_context_get_state_proc)pContext->pulse.pa_context_get_state)(pPulseContext) != MA_PA_CONTEXT_READY) { - error = ((mal_pa_mainloop_iterate_proc)pContext->pulse.pa_mainloop_iterate)(pMainLoop, 1, NULL); + while (((ma_pa_context_get_state_proc)pContext->pulse.pa_context_get_state)(pPulseContext) != MA_PA_CONTEXT_READY) { + error = ((ma_pa_mainloop_iterate_proc)pContext->pulse.pa_mainloop_iterate)(pMainLoop, 1, NULL); if (error < 0) { - result = mal_result_from_pulse(error); + result = ma_result_from_pulse(error); goto done; } } - if (deviceType == mal_device_type_playback) { - pOP = ((mal_pa_context_get_sink_info_by_name_proc)pContext->pulse.pa_context_get_sink_info_by_name)(pPulseContext, pDeviceID->pulse, mal_context_get_device_info_sink_callback__pulse, &callbackData); + if (deviceType == ma_device_type_playback) { + pOP = ((ma_pa_context_get_sink_info_by_name_proc)pContext->pulse.pa_context_get_sink_info_by_name)(pPulseContext, pDeviceID->pulse, ma_context_get_device_info_sink_callback__pulse, &callbackData); } else { - pOP = ((mal_pa_context_get_source_info_by_name_proc)pContext->pulse.pa_context_get_source_info_by_name)(pPulseContext, pDeviceID->pulse, mal_context_get_device_info_source_callback__pulse, &callbackData); + pOP = ((ma_pa_context_get_source_info_by_name_proc)pContext->pulse.pa_context_get_source_info_by_name)(pPulseContext, pDeviceID->pulse, ma_context_get_device_info_source_callback__pulse, &callbackData); } if (pOP != NULL) { - mal_wait_for_operation__pulse(pContext, pMainLoop, pOP); - ((mal_pa_operation_unref_proc)pContext->pulse.pa_operation_unref)(pOP); + ma_wait_for_operation__pulse(pContext, pMainLoop, pOP); + ((ma_pa_operation_unref_proc)pContext->pulse.pa_operation_unref)(pOP); } else { result = MA_ERROR; goto done; @@ -14056,201 +14056,201 @@ mal_result mal_context_get_device_info__pulse(mal_context* pContext, mal_device_ done: - ((mal_pa_context_disconnect_proc)pContext->pulse.pa_context_disconnect)(pPulseContext); - ((mal_pa_context_unref_proc)pContext->pulse.pa_context_unref)(pPulseContext); - ((mal_pa_mainloop_free_proc)pContext->pulse.pa_mainloop_free)(pMainLoop); + ((ma_pa_context_disconnect_proc)pContext->pulse.pa_context_disconnect)(pPulseContext); + ((ma_pa_context_unref_proc)pContext->pulse.pa_context_unref)(pPulseContext); + ((ma_pa_mainloop_free_proc)pContext->pulse.pa_mainloop_free)(pMainLoop); return result; } -void mal_pulse_device_state_callback(mal_pa_context* pPulseContext, void* pUserData) +void ma_pulse_device_state_callback(ma_pa_context* pPulseContext, void* pUserData) { - mal_device* pDevice = (mal_device*)pUserData; - mal_assert(pDevice != NULL); + ma_device* pDevice = (ma_device*)pUserData; + ma_assert(pDevice != NULL); - mal_context* pContext = pDevice->pContext; - mal_assert(pContext != NULL); + ma_context* pContext = pDevice->pContext; + ma_assert(pContext != NULL); - pDevice->pulse.pulseContextState = ((mal_pa_context_get_state_proc)pContext->pulse.pa_context_get_state)(pPulseContext); + pDevice->pulse.pulseContextState = ((ma_pa_context_get_state_proc)pContext->pulse.pa_context_get_state)(pPulseContext); } -void mal_device_sink_info_callback(mal_pa_context* pPulseContext, const mal_pa_sink_info* pInfo, int endOfList, void* pUserData) +void ma_device_sink_info_callback(ma_pa_context* pPulseContext, const ma_pa_sink_info* pInfo, int endOfList, void* pUserData) { if (endOfList > 0) { return; } - mal_pa_sink_info* pInfoOut = (mal_pa_sink_info*)pUserData; - mal_assert(pInfoOut != NULL); + ma_pa_sink_info* pInfoOut = (ma_pa_sink_info*)pUserData; + ma_assert(pInfoOut != NULL); *pInfoOut = *pInfo; } -void mal_device_source_info_callback(mal_pa_context* pPulseContext, const mal_pa_source_info* pInfo, int endOfList, void* pUserData) +void ma_device_source_info_callback(ma_pa_context* pPulseContext, const ma_pa_source_info* pInfo, int endOfList, void* pUserData) { if (endOfList > 0) { return; } - mal_pa_source_info* pInfoOut = (mal_pa_source_info*)pUserData; - mal_assert(pInfoOut != NULL); + ma_pa_source_info* pInfoOut = (ma_pa_source_info*)pUserData; + ma_assert(pInfoOut != NULL); *pInfoOut = *pInfo; } -void mal_device_sink_name_callback(mal_pa_context* pPulseContext, const mal_pa_sink_info* pInfo, int endOfList, void* pUserData) +void ma_device_sink_name_callback(ma_pa_context* pPulseContext, const ma_pa_sink_info* pInfo, int endOfList, void* pUserData) { if (endOfList > 0) { return; } - mal_device* pDevice = (mal_device*)pUserData; - mal_assert(pDevice != NULL); + ma_device* pDevice = (ma_device*)pUserData; + ma_assert(pDevice != NULL); - mal_strncpy_s(pDevice->playback.name, sizeof(pDevice->playback.name), pInfo->description, (size_t)-1); + ma_strncpy_s(pDevice->playback.name, sizeof(pDevice->playback.name), pInfo->description, (size_t)-1); } -void mal_device_source_name_callback(mal_pa_context* pPulseContext, const mal_pa_source_info* pInfo, int endOfList, void* pUserData) +void ma_device_source_name_callback(ma_pa_context* pPulseContext, const ma_pa_source_info* pInfo, int endOfList, void* pUserData) { if (endOfList > 0) { return; } - mal_device* pDevice = (mal_device*)pUserData; - mal_assert(pDevice != NULL); + ma_device* pDevice = (ma_device*)pUserData; + ma_assert(pDevice != NULL); - mal_strncpy_s(pDevice->capture.name, sizeof(pDevice->capture.name), pInfo->description, (size_t)-1); + ma_strncpy_s(pDevice->capture.name, sizeof(pDevice->capture.name), pInfo->description, (size_t)-1); } -void mal_device_uninit__pulse(mal_device* pDevice) +void ma_device_uninit__pulse(ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); - mal_context* pContext = pDevice->pContext; - mal_assert(pContext != NULL); + ma_context* pContext = pDevice->pContext; + ma_assert(pContext != NULL); - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { - ((mal_pa_stream_disconnect_proc)pContext->pulse.pa_stream_disconnect)((mal_pa_stream*)pDevice->pulse.pStreamCapture); - ((mal_pa_stream_unref_proc)pContext->pulse.pa_stream_unref)((mal_pa_stream*)pDevice->pulse.pStreamCapture); + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { + ((ma_pa_stream_disconnect_proc)pContext->pulse.pa_stream_disconnect)((ma_pa_stream*)pDevice->pulse.pStreamCapture); + ((ma_pa_stream_unref_proc)pContext->pulse.pa_stream_unref)((ma_pa_stream*)pDevice->pulse.pStreamCapture); } - if (pDevice->type == mal_device_type_playback || pDevice->type == mal_device_type_duplex) { - ((mal_pa_stream_disconnect_proc)pContext->pulse.pa_stream_disconnect)((mal_pa_stream*)pDevice->pulse.pStreamPlayback); - ((mal_pa_stream_unref_proc)pContext->pulse.pa_stream_unref)((mal_pa_stream*)pDevice->pulse.pStreamPlayback); + if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) { + ((ma_pa_stream_disconnect_proc)pContext->pulse.pa_stream_disconnect)((ma_pa_stream*)pDevice->pulse.pStreamPlayback); + ((ma_pa_stream_unref_proc)pContext->pulse.pa_stream_unref)((ma_pa_stream*)pDevice->pulse.pStreamPlayback); } - ((mal_pa_context_disconnect_proc)pContext->pulse.pa_context_disconnect)((mal_pa_context*)pDevice->pulse.pPulseContext); - ((mal_pa_context_unref_proc)pContext->pulse.pa_context_unref)((mal_pa_context*)pDevice->pulse.pPulseContext); - ((mal_pa_mainloop_free_proc)pContext->pulse.pa_mainloop_free)((mal_pa_mainloop*)pDevice->pulse.pMainLoop); + ((ma_pa_context_disconnect_proc)pContext->pulse.pa_context_disconnect)((ma_pa_context*)pDevice->pulse.pPulseContext); + ((ma_pa_context_unref_proc)pContext->pulse.pa_context_unref)((ma_pa_context*)pDevice->pulse.pPulseContext); + ((ma_pa_mainloop_free_proc)pContext->pulse.pa_mainloop_free)((ma_pa_mainloop*)pDevice->pulse.pMainLoop); } -mal_pa_buffer_attr mal_device__pa_buffer_attr_new(mal_uint32 bufferSizeInFrames, mal_uint32 periods, const mal_pa_sample_spec* ss) +ma_pa_buffer_attr ma_device__pa_buffer_attr_new(ma_uint32 bufferSizeInFrames, ma_uint32 periods, const ma_pa_sample_spec* ss) { - mal_pa_buffer_attr attr; - attr.maxlength = bufferSizeInFrames * mal_get_bytes_per_sample(mal_format_from_pulse(ss->format)) * ss->channels; + ma_pa_buffer_attr attr; + attr.maxlength = bufferSizeInFrames * ma_get_bytes_per_sample(ma_format_from_pulse(ss->format)) * ss->channels; attr.tlength = attr.maxlength / periods; - attr.prebuf = (mal_uint32)-1; + attr.prebuf = (ma_uint32)-1; attr.minreq = attr.maxlength / periods; attr.fragsize = attr.maxlength / periods; return attr; } -mal_pa_stream* mal_device__pa_stream_new__pulse(mal_device* pDevice, const char* pStreamName, const mal_pa_sample_spec* ss, const mal_pa_channel_map* cmap) +ma_pa_stream* ma_device__pa_stream_new__pulse(ma_device* pDevice, const char* pStreamName, const ma_pa_sample_spec* ss, const ma_pa_channel_map* cmap) { static int g_StreamCounter = 0; char actualStreamName[256]; if (pStreamName != NULL) { - mal_strncpy_s(actualStreamName, sizeof(actualStreamName), pStreamName, (size_t)-1); + ma_strncpy_s(actualStreamName, sizeof(actualStreamName), pStreamName, (size_t)-1); } else { - mal_strcpy_s(actualStreamName, sizeof(actualStreamName), "miniaudio:"); - mal_itoa_s(g_StreamCounter, actualStreamName + 8, sizeof(actualStreamName)-8, 10); // 8 = strlen("miniaudio:") + ma_strcpy_s(actualStreamName, sizeof(actualStreamName), "miniaudio:"); + ma_itoa_s(g_StreamCounter, actualStreamName + 8, sizeof(actualStreamName)-8, 10); // 8 = strlen("miniaudio:") } g_StreamCounter += 1; - return ((mal_pa_stream_new_proc)pDevice->pContext->pulse.pa_stream_new)((mal_pa_context*)pDevice->pulse.pPulseContext, actualStreamName, ss, cmap); + return ((ma_pa_stream_new_proc)pDevice->pContext->pulse.pa_stream_new)((ma_pa_context*)pDevice->pulse.pPulseContext, actualStreamName, ss, cmap); } -mal_result mal_device_init__pulse(mal_context* pContext, const mal_device_config* pConfig, mal_device* pDevice) +ma_result ma_device_init__pulse(ma_context* pContext, const ma_device_config* pConfig, ma_device* pDevice) { (void)pContext; - mal_assert(pDevice != NULL); - mal_zero_object(&pDevice->pulse); + ma_assert(pDevice != NULL); + ma_zero_object(&pDevice->pulse); - mal_result result = MA_SUCCESS; + ma_result result = MA_SUCCESS; int error = 0; const char* devPlayback = NULL; const char* devCapture = NULL; /* No exclusive mode with the PulseAudio backend. */ - if (((pConfig->deviceType == mal_device_type_playback || pConfig->deviceType == mal_device_type_duplex) && pConfig->playback.shareMode == mal_share_mode_exclusive) || - ((pConfig->deviceType == mal_device_type_capture || pConfig->deviceType == mal_device_type_duplex) && pConfig->capture.shareMode == mal_share_mode_exclusive)) { + if (((pConfig->deviceType == ma_device_type_playback || pConfig->deviceType == ma_device_type_duplex) && pConfig->playback.shareMode == ma_share_mode_exclusive) || + ((pConfig->deviceType == ma_device_type_capture || pConfig->deviceType == ma_device_type_duplex) && pConfig->capture.shareMode == ma_share_mode_exclusive)) { return MA_SHARE_MODE_NOT_SUPPORTED; } - if ((pConfig->deviceType == mal_device_type_playback || pConfig->deviceType == mal_device_type_duplex) && pConfig->playback.pDeviceID != NULL) { + if ((pConfig->deviceType == ma_device_type_playback || pConfig->deviceType == ma_device_type_duplex) && pConfig->playback.pDeviceID != NULL) { devPlayback = pConfig->playback.pDeviceID->pulse; } - if ((pConfig->deviceType == mal_device_type_capture || pConfig->deviceType == mal_device_type_duplex) && pConfig->capture.pDeviceID != NULL) { + if ((pConfig->deviceType == ma_device_type_capture || pConfig->deviceType == ma_device_type_duplex) && pConfig->capture.pDeviceID != NULL) { devCapture = pConfig->capture.pDeviceID->pulse; } - mal_uint32 bufferSizeInMilliseconds = pConfig->bufferSizeInMilliseconds; + ma_uint32 bufferSizeInMilliseconds = pConfig->bufferSizeInMilliseconds; if (bufferSizeInMilliseconds == 0) { - bufferSizeInMilliseconds = mal_calculate_buffer_size_in_milliseconds_from_frames(pConfig->bufferSizeInFrames, pConfig->sampleRate); + bufferSizeInMilliseconds = ma_calculate_buffer_size_in_milliseconds_from_frames(pConfig->bufferSizeInFrames, pConfig->sampleRate); } - mal_pa_sink_info sinkInfo; - mal_pa_source_info sourceInfo; - mal_pa_operation* pOP = NULL; + ma_pa_sink_info sinkInfo; + ma_pa_source_info sourceInfo; + ma_pa_operation* pOP = NULL; - mal_pa_sample_spec ss; - mal_pa_channel_map cmap; - mal_pa_buffer_attr attr; + ma_pa_sample_spec ss; + ma_pa_channel_map cmap; + ma_pa_buffer_attr attr; - const mal_pa_sample_spec* pActualSS = NULL; - const mal_pa_channel_map* pActualCMap = NULL; - const mal_pa_buffer_attr* pActualAttr = NULL; + const ma_pa_sample_spec* pActualSS = NULL; + const ma_pa_channel_map* pActualCMap = NULL; + const ma_pa_buffer_attr* pActualAttr = NULL; - pDevice->pulse.pMainLoop = ((mal_pa_mainloop_new_proc)pContext->pulse.pa_mainloop_new)(); + pDevice->pulse.pMainLoop = ((ma_pa_mainloop_new_proc)pContext->pulse.pa_mainloop_new)(); if (pDevice->pulse.pMainLoop == NULL) { - result = mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to create main loop for device.", MA_FAILED_TO_INIT_BACKEND); + result = ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to create main loop for device.", MA_FAILED_TO_INIT_BACKEND); goto on_error0; } - pDevice->pulse.pAPI = ((mal_pa_mainloop_get_api_proc)pContext->pulse.pa_mainloop_get_api)((mal_pa_mainloop*)pDevice->pulse.pMainLoop); + pDevice->pulse.pAPI = ((ma_pa_mainloop_get_api_proc)pContext->pulse.pa_mainloop_get_api)((ma_pa_mainloop*)pDevice->pulse.pMainLoop); if (pDevice->pulse.pAPI == NULL) { - result = mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to retrieve PulseAudio main loop.", MA_FAILED_TO_INIT_BACKEND); + result = ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to retrieve PulseAudio main loop.", MA_FAILED_TO_INIT_BACKEND); goto on_error1; } - pDevice->pulse.pPulseContext = ((mal_pa_context_new_proc)pContext->pulse.pa_context_new)((mal_pa_mainloop_api*)pDevice->pulse.pAPI, pContext->config.pulse.pApplicationName); + pDevice->pulse.pPulseContext = ((ma_pa_context_new_proc)pContext->pulse.pa_context_new)((ma_pa_mainloop_api*)pDevice->pulse.pAPI, pContext->config.pulse.pApplicationName); if (pDevice->pulse.pPulseContext == NULL) { - result = mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to create PulseAudio context for device.", MA_FAILED_TO_INIT_BACKEND); + result = ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to create PulseAudio context for device.", MA_FAILED_TO_INIT_BACKEND); goto on_error1; } - error = ((mal_pa_context_connect_proc)pContext->pulse.pa_context_connect)((mal_pa_context*)pDevice->pulse.pPulseContext, pContext->config.pulse.pServerName, (pContext->config.pulse.tryAutoSpawn) ? 0 : MA_PA_CONTEXT_NOAUTOSPAWN, NULL); + error = ((ma_pa_context_connect_proc)pContext->pulse.pa_context_connect)((ma_pa_context*)pDevice->pulse.pPulseContext, pContext->config.pulse.pServerName, (pContext->config.pulse.tryAutoSpawn) ? 0 : MA_PA_CONTEXT_NOAUTOSPAWN, NULL); if (error != MA_PA_OK) { - result = mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to connect PulseAudio context.", mal_result_from_pulse(error)); + result = ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to connect PulseAudio context.", ma_result_from_pulse(error)); goto on_error2; } pDevice->pulse.pulseContextState = MA_PA_CONTEXT_UNCONNECTED; - ((mal_pa_context_set_state_callback_proc)pContext->pulse.pa_context_set_state_callback)((mal_pa_context*)pDevice->pulse.pPulseContext, mal_pulse_device_state_callback, pDevice); + ((ma_pa_context_set_state_callback_proc)pContext->pulse.pa_context_set_state_callback)((ma_pa_context*)pDevice->pulse.pPulseContext, ma_pulse_device_state_callback, pDevice); // Wait for PulseAudio to get itself ready before returning. for (;;) { if (pDevice->pulse.pulseContextState == MA_PA_CONTEXT_READY) { break; } else { - error = ((mal_pa_mainloop_iterate_proc)pContext->pulse.pa_mainloop_iterate)((mal_pa_mainloop*)pDevice->pulse.pMainLoop, 1, NULL); // 1 = block. + error = ((ma_pa_mainloop_iterate_proc)pContext->pulse.pa_mainloop_iterate)((ma_pa_mainloop*)pDevice->pulse.pMainLoop, 1, NULL); // 1 = block. if (error < 0) { - result = mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] The PulseAudio main loop returned an error while connecting the PulseAudio context.", mal_result_from_pulse(error)); + result = ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] The PulseAudio main loop returned an error while connecting the PulseAudio context.", ma_result_from_pulse(error)); goto on_error3; } continue; @@ -14258,209 +14258,209 @@ mal_result mal_device_init__pulse(mal_context* pContext, const mal_device_config // An error may have occurred. if (pDevice->pulse.pulseContextState == MA_PA_CONTEXT_FAILED || pDevice->pulse.pulseContextState == MA_PA_CONTEXT_TERMINATED) { - result = mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] An error occurred while connecting the PulseAudio context.", MA_ERROR); + result = ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] An error occurred while connecting the PulseAudio context.", MA_ERROR); goto on_error3; } - error = ((mal_pa_mainloop_iterate_proc)pContext->pulse.pa_mainloop_iterate)((mal_pa_mainloop*)pDevice->pulse.pMainLoop, 1, NULL); + error = ((ma_pa_mainloop_iterate_proc)pContext->pulse.pa_mainloop_iterate)((ma_pa_mainloop*)pDevice->pulse.pMainLoop, 1, NULL); if (error < 0) { - result = mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] The PulseAudio main loop returned an error while connecting the PulseAudio context.", mal_result_from_pulse(error)); + result = ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] The PulseAudio main loop returned an error while connecting the PulseAudio context.", ma_result_from_pulse(error)); goto on_error3; } } - if (pConfig->deviceType == mal_device_type_capture || pConfig->deviceType == mal_device_type_duplex) { - pOP = ((mal_pa_context_get_source_info_by_name_proc)pContext->pulse.pa_context_get_source_info_by_name)((mal_pa_context*)pDevice->pulse.pPulseContext, devCapture, mal_device_source_info_callback, &sourceInfo); + if (pConfig->deviceType == ma_device_type_capture || pConfig->deviceType == ma_device_type_duplex) { + pOP = ((ma_pa_context_get_source_info_by_name_proc)pContext->pulse.pa_context_get_source_info_by_name)((ma_pa_context*)pDevice->pulse.pPulseContext, devCapture, ma_device_source_info_callback, &sourceInfo); if (pOP != NULL) { - mal_device__wait_for_operation__pulse(pDevice, pOP); - ((mal_pa_operation_unref_proc)pContext->pulse.pa_operation_unref)(pOP); + ma_device__wait_for_operation__pulse(pDevice, pOP); + ((ma_pa_operation_unref_proc)pContext->pulse.pa_operation_unref)(pOP); } else { - result = mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to retrieve source info for capture device.", mal_result_from_pulse(error)); + result = ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to retrieve source info for capture device.", ma_result_from_pulse(error)); goto on_error3; } ss = sourceInfo.sample_spec; cmap = sourceInfo.channel_map; - pDevice->capture.internalBufferSizeInFrames = mal_calculate_buffer_size_in_frames_from_milliseconds(bufferSizeInMilliseconds, ss.rate); + pDevice->capture.internalBufferSizeInFrames = ma_calculate_buffer_size_in_frames_from_milliseconds(bufferSizeInMilliseconds, ss.rate); pDevice->capture.internalPeriods = pConfig->periods; - attr = mal_device__pa_buffer_attr_new(pDevice->capture.internalBufferSizeInFrames, pConfig->periods, &ss); + attr = ma_device__pa_buffer_attr_new(pDevice->capture.internalBufferSizeInFrames, pConfig->periods, &ss); #ifdef MA_DEBUG_OUTPUT printf("[PulseAudio] Capture attr: maxlength=%d, tlength=%d, prebuf=%d, minreq=%d, fragsize=%d; internalBufferSizeInFrames=%d\n", attr.maxlength, attr.tlength, attr.prebuf, attr.minreq, attr.fragsize, pDevice->capture.internalBufferSizeInFrames); #endif - pDevice->pulse.pStreamCapture = mal_device__pa_stream_new__pulse(pDevice, pConfig->pulse.pStreamNameCapture, &ss, &cmap); + pDevice->pulse.pStreamCapture = ma_device__pa_stream_new__pulse(pDevice, pConfig->pulse.pStreamNameCapture, &ss, &cmap); if (pDevice->pulse.pStreamCapture == NULL) { - result = mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to create PulseAudio capture stream.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + result = ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to create PulseAudio capture stream.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); goto on_error3; } - mal_pa_stream_flags_t streamFlags = MA_PA_STREAM_START_CORKED | MA_PA_STREAM_FIX_FORMAT | MA_PA_STREAM_FIX_RATE | MA_PA_STREAM_FIX_CHANNELS; + ma_pa_stream_flags_t streamFlags = MA_PA_STREAM_START_CORKED | MA_PA_STREAM_FIX_FORMAT | MA_PA_STREAM_FIX_RATE | MA_PA_STREAM_FIX_CHANNELS; if (devCapture != NULL) { streamFlags |= MA_PA_STREAM_DONT_MOVE; } - error = ((mal_pa_stream_connect_record_proc)pContext->pulse.pa_stream_connect_record)((mal_pa_stream*)pDevice->pulse.pStreamCapture, devCapture, &attr, streamFlags); + error = ((ma_pa_stream_connect_record_proc)pContext->pulse.pa_stream_connect_record)((ma_pa_stream*)pDevice->pulse.pStreamCapture, devCapture, &attr, streamFlags); if (error != MA_PA_OK) { - result = mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to connect PulseAudio capture stream.", mal_result_from_pulse(error)); + result = ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to connect PulseAudio capture stream.", ma_result_from_pulse(error)); goto on_error4; } - while (((mal_pa_stream_get_state_proc)pContext->pulse.pa_stream_get_state)((mal_pa_stream*)pDevice->pulse.pStreamCapture) != MA_PA_STREAM_READY) { - error = ((mal_pa_mainloop_iterate_proc)pContext->pulse.pa_mainloop_iterate)((mal_pa_mainloop*)pDevice->pulse.pMainLoop, 1, NULL); + while (((ma_pa_stream_get_state_proc)pContext->pulse.pa_stream_get_state)((ma_pa_stream*)pDevice->pulse.pStreamCapture) != MA_PA_STREAM_READY) { + error = ((ma_pa_mainloop_iterate_proc)pContext->pulse.pa_mainloop_iterate)((ma_pa_mainloop*)pDevice->pulse.pMainLoop, 1, NULL); if (error < 0) { - result = mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] The PulseAudio main loop returned an error while connecting the PulseAudio capture stream.", mal_result_from_pulse(error)); + result = ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] The PulseAudio main loop returned an error while connecting the PulseAudio capture stream.", ma_result_from_pulse(error)); goto on_error5; } } /* Internal format. */ - pActualSS = ((mal_pa_stream_get_sample_spec_proc)pContext->pulse.pa_stream_get_sample_spec)((mal_pa_stream*)pDevice->pulse.pStreamCapture); + pActualSS = ((ma_pa_stream_get_sample_spec_proc)pContext->pulse.pa_stream_get_sample_spec)((ma_pa_stream*)pDevice->pulse.pStreamCapture); if (pActualSS != NULL) { /* If anything has changed between the requested and the actual sample spec, we need to update the buffer. */ if (ss.format != pActualSS->format || ss.channels != pActualSS->channels || ss.rate != pActualSS->rate) { - attr = mal_device__pa_buffer_attr_new(pDevice->capture.internalBufferSizeInFrames, pConfig->periods, pActualSS); + attr = ma_device__pa_buffer_attr_new(pDevice->capture.internalBufferSizeInFrames, pConfig->periods, pActualSS); - pOP = ((mal_pa_stream_set_buffer_attr_proc)pContext->pulse.pa_stream_set_buffer_attr)((mal_pa_stream*)pDevice->pulse.pStreamCapture, &attr, NULL, NULL); + pOP = ((ma_pa_stream_set_buffer_attr_proc)pContext->pulse.pa_stream_set_buffer_attr)((ma_pa_stream*)pDevice->pulse.pStreamCapture, &attr, NULL, NULL); if (pOP != NULL) { - mal_device__wait_for_operation__pulse(pDevice, pOP); - ((mal_pa_operation_unref_proc)pContext->pulse.pa_operation_unref)(pOP); + ma_device__wait_for_operation__pulse(pDevice, pOP); + ((ma_pa_operation_unref_proc)pContext->pulse.pa_operation_unref)(pOP); } } ss = *pActualSS; } - pDevice->capture.internalFormat = mal_format_from_pulse(ss.format); + pDevice->capture.internalFormat = ma_format_from_pulse(ss.format); pDevice->capture.internalChannels = ss.channels; pDevice->capture.internalSampleRate = ss.rate; /* Internal channel map. */ - pActualCMap = ((mal_pa_stream_get_channel_map_proc)pContext->pulse.pa_stream_get_channel_map)((mal_pa_stream*)pDevice->pulse.pStreamCapture); + pActualCMap = ((ma_pa_stream_get_channel_map_proc)pContext->pulse.pa_stream_get_channel_map)((ma_pa_stream*)pDevice->pulse.pStreamCapture); if (pActualCMap != NULL) { cmap = *pActualCMap; } - for (mal_uint32 iChannel = 0; iChannel < pDevice->capture.internalChannels; ++iChannel) { - pDevice->capture.internalChannelMap[iChannel] = mal_channel_position_from_pulse(cmap.map[iChannel]); + for (ma_uint32 iChannel = 0; iChannel < pDevice->capture.internalChannels; ++iChannel) { + pDevice->capture.internalChannelMap[iChannel] = ma_channel_position_from_pulse(cmap.map[iChannel]); } /* Buffer. */ - pActualAttr = ((mal_pa_stream_get_buffer_attr_proc)pContext->pulse.pa_stream_get_buffer_attr)((mal_pa_stream*)pDevice->pulse.pStreamCapture); + pActualAttr = ((ma_pa_stream_get_buffer_attr_proc)pContext->pulse.pa_stream_get_buffer_attr)((ma_pa_stream*)pDevice->pulse.pStreamCapture); if (pActualAttr != NULL) { attr = *pActualAttr; } - pDevice->capture.internalBufferSizeInFrames = attr.maxlength / (mal_get_bytes_per_sample(pDevice->capture.internalFormat) * pDevice->capture.internalChannels); + pDevice->capture.internalBufferSizeInFrames = attr.maxlength / (ma_get_bytes_per_sample(pDevice->capture.internalFormat) * pDevice->capture.internalChannels); pDevice->capture.internalPeriods = attr.maxlength / attr.fragsize; #ifdef MA_DEBUG_OUTPUT printf("[PulseAudio] Capture actual attr: maxlength=%d, tlength=%d, prebuf=%d, minreq=%d, fragsize=%d; internalBufferSizeInFrames=%d\n", attr.maxlength, attr.tlength, attr.prebuf, attr.minreq, attr.fragsize, pDevice->capture.internalBufferSizeInFrames); #endif /* Name. */ - devCapture = ((mal_pa_stream_get_device_name_proc)pContext->pulse.pa_stream_get_device_name)((mal_pa_stream*)pDevice->pulse.pStreamCapture); + devCapture = ((ma_pa_stream_get_device_name_proc)pContext->pulse.pa_stream_get_device_name)((ma_pa_stream*)pDevice->pulse.pStreamCapture); if (devCapture != NULL) { - mal_pa_operation* pOP = ((mal_pa_context_get_source_info_by_name_proc)pContext->pulse.pa_context_get_source_info_by_name)((mal_pa_context*)pDevice->pulse.pPulseContext, devCapture, mal_device_source_name_callback, pDevice); + ma_pa_operation* pOP = ((ma_pa_context_get_source_info_by_name_proc)pContext->pulse.pa_context_get_source_info_by_name)((ma_pa_context*)pDevice->pulse.pPulseContext, devCapture, ma_device_source_name_callback, pDevice); if (pOP != NULL) { - mal_device__wait_for_operation__pulse(pDevice, pOP); - ((mal_pa_operation_unref_proc)pContext->pulse.pa_operation_unref)(pOP); + ma_device__wait_for_operation__pulse(pDevice, pOP); + ((ma_pa_operation_unref_proc)pContext->pulse.pa_operation_unref)(pOP); } } } - if (pConfig->deviceType == mal_device_type_playback || pConfig->deviceType == mal_device_type_duplex) { - pOP = ((mal_pa_context_get_sink_info_by_name_proc)pContext->pulse.pa_context_get_sink_info_by_name)((mal_pa_context*)pDevice->pulse.pPulseContext, devPlayback, mal_device_sink_info_callback, &sinkInfo); + if (pConfig->deviceType == ma_device_type_playback || pConfig->deviceType == ma_device_type_duplex) { + pOP = ((ma_pa_context_get_sink_info_by_name_proc)pContext->pulse.pa_context_get_sink_info_by_name)((ma_pa_context*)pDevice->pulse.pPulseContext, devPlayback, ma_device_sink_info_callback, &sinkInfo); if (pOP != NULL) { - mal_device__wait_for_operation__pulse(pDevice, pOP); - ((mal_pa_operation_unref_proc)pContext->pulse.pa_operation_unref)(pOP); + ma_device__wait_for_operation__pulse(pDevice, pOP); + ((ma_pa_operation_unref_proc)pContext->pulse.pa_operation_unref)(pOP); } else { - result = mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to retrieve sink info for playback device.", mal_result_from_pulse(error)); + result = ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to retrieve sink info for playback device.", ma_result_from_pulse(error)); goto on_error3; } ss = sinkInfo.sample_spec; cmap = sinkInfo.channel_map; - pDevice->playback.internalBufferSizeInFrames = mal_calculate_buffer_size_in_frames_from_milliseconds(bufferSizeInMilliseconds, ss.rate); + pDevice->playback.internalBufferSizeInFrames = ma_calculate_buffer_size_in_frames_from_milliseconds(bufferSizeInMilliseconds, ss.rate); pDevice->playback.internalPeriods = pConfig->periods; - attr = mal_device__pa_buffer_attr_new(pDevice->playback.internalBufferSizeInFrames, pConfig->periods, &ss); + attr = ma_device__pa_buffer_attr_new(pDevice->playback.internalBufferSizeInFrames, pConfig->periods, &ss); #ifdef MA_DEBUG_OUTPUT printf("[PulseAudio] Playback attr: maxlength=%d, tlength=%d, prebuf=%d, minreq=%d, fragsize=%d; internalBufferSizeInFrames=%d\n", attr.maxlength, attr.tlength, attr.prebuf, attr.minreq, attr.fragsize, pDevice->playback.internalBufferSizeInFrames); #endif - pDevice->pulse.pStreamPlayback = mal_device__pa_stream_new__pulse(pDevice, pConfig->pulse.pStreamNamePlayback, &ss, &cmap); + pDevice->pulse.pStreamPlayback = ma_device__pa_stream_new__pulse(pDevice, pConfig->pulse.pStreamNamePlayback, &ss, &cmap); if (pDevice->pulse.pStreamPlayback == NULL) { - result = mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to create PulseAudio playback stream.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + result = ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to create PulseAudio playback stream.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); goto on_error3; } - mal_pa_stream_flags_t streamFlags = MA_PA_STREAM_START_CORKED | MA_PA_STREAM_FIX_FORMAT | MA_PA_STREAM_FIX_RATE | MA_PA_STREAM_FIX_CHANNELS; + ma_pa_stream_flags_t streamFlags = MA_PA_STREAM_START_CORKED | MA_PA_STREAM_FIX_FORMAT | MA_PA_STREAM_FIX_RATE | MA_PA_STREAM_FIX_CHANNELS; if (devPlayback != NULL) { streamFlags |= MA_PA_STREAM_DONT_MOVE; } - error = ((mal_pa_stream_connect_playback_proc)pContext->pulse.pa_stream_connect_playback)((mal_pa_stream*)pDevice->pulse.pStreamPlayback, devPlayback, &attr, streamFlags, NULL, NULL); + error = ((ma_pa_stream_connect_playback_proc)pContext->pulse.pa_stream_connect_playback)((ma_pa_stream*)pDevice->pulse.pStreamPlayback, devPlayback, &attr, streamFlags, NULL, NULL); if (error != MA_PA_OK) { - result = mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to connect PulseAudio playback stream.", mal_result_from_pulse(error)); + result = ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to connect PulseAudio playback stream.", ma_result_from_pulse(error)); goto on_error6; } - while (((mal_pa_stream_get_state_proc)pContext->pulse.pa_stream_get_state)((mal_pa_stream*)pDevice->pulse.pStreamPlayback) != MA_PA_STREAM_READY) { - error = ((mal_pa_mainloop_iterate_proc)pContext->pulse.pa_mainloop_iterate)((mal_pa_mainloop*)pDevice->pulse.pMainLoop, 1, NULL); + while (((ma_pa_stream_get_state_proc)pContext->pulse.pa_stream_get_state)((ma_pa_stream*)pDevice->pulse.pStreamPlayback) != MA_PA_STREAM_READY) { + error = ((ma_pa_mainloop_iterate_proc)pContext->pulse.pa_mainloop_iterate)((ma_pa_mainloop*)pDevice->pulse.pMainLoop, 1, NULL); if (error < 0) { - result = mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] The PulseAudio main loop returned an error while connecting the PulseAudio playback stream.", mal_result_from_pulse(error)); + result = ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] The PulseAudio main loop returned an error while connecting the PulseAudio playback stream.", ma_result_from_pulse(error)); goto on_error7; } } /* Internal format. */ - pActualSS = ((mal_pa_stream_get_sample_spec_proc)pContext->pulse.pa_stream_get_sample_spec)((mal_pa_stream*)pDevice->pulse.pStreamPlayback); + pActualSS = ((ma_pa_stream_get_sample_spec_proc)pContext->pulse.pa_stream_get_sample_spec)((ma_pa_stream*)pDevice->pulse.pStreamPlayback); if (pActualSS != NULL) { /* If anything has changed between the requested and the actual sample spec, we need to update the buffer. */ if (ss.format != pActualSS->format || ss.channels != pActualSS->channels || ss.rate != pActualSS->rate) { - attr = mal_device__pa_buffer_attr_new(pDevice->playback.internalBufferSizeInFrames, pConfig->periods, pActualSS); + attr = ma_device__pa_buffer_attr_new(pDevice->playback.internalBufferSizeInFrames, pConfig->periods, pActualSS); - pOP = ((mal_pa_stream_set_buffer_attr_proc)pContext->pulse.pa_stream_set_buffer_attr)((mal_pa_stream*)pDevice->pulse.pStreamPlayback, &attr, NULL, NULL); + pOP = ((ma_pa_stream_set_buffer_attr_proc)pContext->pulse.pa_stream_set_buffer_attr)((ma_pa_stream*)pDevice->pulse.pStreamPlayback, &attr, NULL, NULL); if (pOP != NULL) { - mal_device__wait_for_operation__pulse(pDevice, pOP); - ((mal_pa_operation_unref_proc)pContext->pulse.pa_operation_unref)(pOP); + ma_device__wait_for_operation__pulse(pDevice, pOP); + ((ma_pa_operation_unref_proc)pContext->pulse.pa_operation_unref)(pOP); } } ss = *pActualSS; } - pDevice->playback.internalFormat = mal_format_from_pulse(ss.format); + pDevice->playback.internalFormat = ma_format_from_pulse(ss.format); pDevice->playback.internalChannels = ss.channels; pDevice->playback.internalSampleRate = ss.rate; /* Internal channel map. */ - pActualCMap = ((mal_pa_stream_get_channel_map_proc)pContext->pulse.pa_stream_get_channel_map)((mal_pa_stream*)pDevice->pulse.pStreamPlayback); + pActualCMap = ((ma_pa_stream_get_channel_map_proc)pContext->pulse.pa_stream_get_channel_map)((ma_pa_stream*)pDevice->pulse.pStreamPlayback); if (pActualCMap != NULL) { cmap = *pActualCMap; } - for (mal_uint32 iChannel = 0; iChannel < pDevice->playback.internalChannels; ++iChannel) { - pDevice->playback.internalChannelMap[iChannel] = mal_channel_position_from_pulse(cmap.map[iChannel]); + for (ma_uint32 iChannel = 0; iChannel < pDevice->playback.internalChannels; ++iChannel) { + pDevice->playback.internalChannelMap[iChannel] = ma_channel_position_from_pulse(cmap.map[iChannel]); } /* Buffer. */ - pActualAttr = ((mal_pa_stream_get_buffer_attr_proc)pContext->pulse.pa_stream_get_buffer_attr)((mal_pa_stream*)pDevice->pulse.pStreamPlayback); + pActualAttr = ((ma_pa_stream_get_buffer_attr_proc)pContext->pulse.pa_stream_get_buffer_attr)((ma_pa_stream*)pDevice->pulse.pStreamPlayback); if (pActualAttr != NULL) { attr = *pActualAttr; } - pDevice->playback.internalBufferSizeInFrames = attr.maxlength / (mal_get_bytes_per_sample(pDevice->playback.internalFormat) * pDevice->playback.internalChannels); + pDevice->playback.internalBufferSizeInFrames = attr.maxlength / (ma_get_bytes_per_sample(pDevice->playback.internalFormat) * pDevice->playback.internalChannels); pDevice->playback.internalPeriods = /*pConfig->periods;*/attr.maxlength / attr.tlength; #ifdef MA_DEBUG_OUTPUT printf("[PulseAudio] Playback actual attr: maxlength=%d, tlength=%d, prebuf=%d, minreq=%d, fragsize=%d; internalBufferSizeInFrames=%d\n", attr.maxlength, attr.tlength, attr.prebuf, attr.minreq, attr.fragsize, pDevice->playback.internalBufferSizeInFrames); #endif /* Name. */ - devPlayback = ((mal_pa_stream_get_device_name_proc)pContext->pulse.pa_stream_get_device_name)((mal_pa_stream*)pDevice->pulse.pStreamPlayback); + devPlayback = ((ma_pa_stream_get_device_name_proc)pContext->pulse.pa_stream_get_device_name)((ma_pa_stream*)pDevice->pulse.pStreamPlayback); if (devPlayback != NULL) { - mal_pa_operation* pOP = ((mal_pa_context_get_sink_info_by_name_proc)pContext->pulse.pa_context_get_sink_info_by_name)((mal_pa_context*)pDevice->pulse.pPulseContext, devPlayback, mal_device_sink_name_callback, pDevice); + ma_pa_operation* pOP = ((ma_pa_context_get_sink_info_by_name_proc)pContext->pulse.pa_context_get_sink_info_by_name)((ma_pa_context*)pDevice->pulse.pPulseContext, devPlayback, ma_device_sink_name_callback, pDevice); if (pOP != NULL) { - mal_device__wait_for_operation__pulse(pDevice, pOP); - ((mal_pa_operation_unref_proc)pContext->pulse.pa_operation_unref)(pOP); + ma_device__wait_for_operation__pulse(pDevice, pOP); + ((ma_pa_operation_unref_proc)pContext->pulse.pa_operation_unref)(pOP); } } } @@ -14469,99 +14469,99 @@ mal_result mal_device_init__pulse(mal_context* pContext, const mal_device_config on_error7: - if (pConfig->deviceType == mal_device_type_playback || pConfig->deviceType == mal_device_type_duplex) { - ((mal_pa_stream_disconnect_proc)pContext->pulse.pa_stream_disconnect)((mal_pa_stream*)pDevice->pulse.pStreamPlayback); + if (pConfig->deviceType == ma_device_type_playback || pConfig->deviceType == ma_device_type_duplex) { + ((ma_pa_stream_disconnect_proc)pContext->pulse.pa_stream_disconnect)((ma_pa_stream*)pDevice->pulse.pStreamPlayback); } on_error6: - if (pConfig->deviceType == mal_device_type_playback || pConfig->deviceType == mal_device_type_duplex) { - ((mal_pa_stream_unref_proc)pContext->pulse.pa_stream_unref)((mal_pa_stream*)pDevice->pulse.pStreamPlayback); + if (pConfig->deviceType == ma_device_type_playback || pConfig->deviceType == ma_device_type_duplex) { + ((ma_pa_stream_unref_proc)pContext->pulse.pa_stream_unref)((ma_pa_stream*)pDevice->pulse.pStreamPlayback); } on_error5: - if (pConfig->deviceType == mal_device_type_capture || pConfig->deviceType == mal_device_type_duplex) { - ((mal_pa_stream_disconnect_proc)pContext->pulse.pa_stream_disconnect)((mal_pa_stream*)pDevice->pulse.pStreamCapture); + if (pConfig->deviceType == ma_device_type_capture || pConfig->deviceType == ma_device_type_duplex) { + ((ma_pa_stream_disconnect_proc)pContext->pulse.pa_stream_disconnect)((ma_pa_stream*)pDevice->pulse.pStreamCapture); } on_error4: - if (pConfig->deviceType == mal_device_type_capture || pConfig->deviceType == mal_device_type_duplex) { - ((mal_pa_stream_unref_proc)pContext->pulse.pa_stream_unref)((mal_pa_stream*)pDevice->pulse.pStreamCapture); + if (pConfig->deviceType == ma_device_type_capture || pConfig->deviceType == ma_device_type_duplex) { + ((ma_pa_stream_unref_proc)pContext->pulse.pa_stream_unref)((ma_pa_stream*)pDevice->pulse.pStreamCapture); } -on_error3: ((mal_pa_context_disconnect_proc)pContext->pulse.pa_context_disconnect)((mal_pa_context*)pDevice->pulse.pPulseContext); -on_error2: ((mal_pa_context_unref_proc)pContext->pulse.pa_context_unref)((mal_pa_context*)pDevice->pulse.pPulseContext); -on_error1: ((mal_pa_mainloop_free_proc)pContext->pulse.pa_mainloop_free)((mal_pa_mainloop*)pDevice->pulse.pMainLoop); +on_error3: ((ma_pa_context_disconnect_proc)pContext->pulse.pa_context_disconnect)((ma_pa_context*)pDevice->pulse.pPulseContext); +on_error2: ((ma_pa_context_unref_proc)pContext->pulse.pa_context_unref)((ma_pa_context*)pDevice->pulse.pPulseContext); +on_error1: ((ma_pa_mainloop_free_proc)pContext->pulse.pa_mainloop_free)((ma_pa_mainloop*)pDevice->pulse.pMainLoop); on_error0: return result; } -void mal_pulse_operation_complete_callback(mal_pa_stream* pStream, int success, void* pUserData) +void ma_pulse_operation_complete_callback(ma_pa_stream* pStream, int success, void* pUserData) { - mal_bool32* pIsSuccessful = (mal_bool32*)pUserData; - mal_assert(pIsSuccessful != NULL); + ma_bool32* pIsSuccessful = (ma_bool32*)pUserData; + ma_assert(pIsSuccessful != NULL); - *pIsSuccessful = (mal_bool32)success; + *pIsSuccessful = (ma_bool32)success; } -mal_result mal_device__cork_stream__pulse(mal_device* pDevice, mal_device_type deviceType, int cork) +ma_result ma_device__cork_stream__pulse(ma_device* pDevice, ma_device_type deviceType, int cork) { - mal_context* pContext = pDevice->pContext; - mal_assert(pContext != NULL); + ma_context* pContext = pDevice->pContext; + ma_assert(pContext != NULL); /* This should not be called with a duplex device type. */ - if (deviceType == mal_device_type_duplex) { + if (deviceType == ma_device_type_duplex) { return MA_INVALID_ARGS; } - mal_bool32 wasSuccessful = MA_FALSE; + ma_bool32 wasSuccessful = MA_FALSE; - mal_pa_stream* pStream = (mal_pa_stream*)((deviceType == mal_device_type_capture) ? pDevice->pulse.pStreamCapture : pDevice->pulse.pStreamPlayback); - mal_assert(pStream != NULL); + ma_pa_stream* pStream = (ma_pa_stream*)((deviceType == ma_device_type_capture) ? pDevice->pulse.pStreamCapture : pDevice->pulse.pStreamPlayback); + ma_assert(pStream != NULL); - mal_pa_operation* pOP = ((mal_pa_stream_cork_proc)pContext->pulse.pa_stream_cork)(pStream, cork, mal_pulse_operation_complete_callback, &wasSuccessful); + ma_pa_operation* pOP = ((ma_pa_stream_cork_proc)pContext->pulse.pa_stream_cork)(pStream, cork, ma_pulse_operation_complete_callback, &wasSuccessful); if (pOP == NULL) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to cork PulseAudio stream.", (cork == 0) ? MA_FAILED_TO_START_BACKEND_DEVICE : MA_FAILED_TO_STOP_BACKEND_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to cork PulseAudio stream.", (cork == 0) ? MA_FAILED_TO_START_BACKEND_DEVICE : MA_FAILED_TO_STOP_BACKEND_DEVICE); } - mal_result result = mal_device__wait_for_operation__pulse(pDevice, pOP); - ((mal_pa_operation_unref_proc)pContext->pulse.pa_operation_unref)(pOP); + ma_result result = ma_device__wait_for_operation__pulse(pDevice, pOP); + ((ma_pa_operation_unref_proc)pContext->pulse.pa_operation_unref)(pOP); if (result != MA_SUCCESS) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] An error occurred while waiting for the PulseAudio stream to cork.", result); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] An error occurred while waiting for the PulseAudio stream to cork.", result); } if (!wasSuccessful) { if (cork) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to stop PulseAudio stream.", MA_FAILED_TO_STOP_BACKEND_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to stop PulseAudio stream.", MA_FAILED_TO_STOP_BACKEND_DEVICE); } else { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to start PulseAudio stream.", MA_FAILED_TO_START_BACKEND_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to start PulseAudio stream.", MA_FAILED_TO_START_BACKEND_DEVICE); } } return MA_SUCCESS; } -mal_result mal_device_stop__pulse(mal_device* pDevice) +ma_result ma_device_stop__pulse(ma_device* pDevice) { - mal_result result; - mal_bool32 wasSuccessful; - mal_pa_operation* pOP; + ma_result result; + ma_bool32 wasSuccessful; + ma_pa_operation* pOP; - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { - result = mal_device__cork_stream__pulse(pDevice, mal_device_type_capture, 1); + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { + result = ma_device__cork_stream__pulse(pDevice, ma_device_type_capture, 1); if (result != MA_SUCCESS) { return result; } } - if (pDevice->type == mal_device_type_playback || pDevice->type == mal_device_type_duplex) { + if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) { /* The stream needs to be drained if it's a playback device. */ - pOP = ((mal_pa_stream_drain_proc)pDevice->pContext->pulse.pa_stream_drain)((mal_pa_stream*)pDevice->pulse.pStreamPlayback, mal_pulse_operation_complete_callback, &wasSuccessful); + pOP = ((ma_pa_stream_drain_proc)pDevice->pContext->pulse.pa_stream_drain)((ma_pa_stream*)pDevice->pulse.pStreamPlayback, ma_pulse_operation_complete_callback, &wasSuccessful); if (pOP != NULL) { - mal_device__wait_for_operation__pulse(pDevice, pOP); - ((mal_pa_operation_unref_proc)pDevice->pContext->pulse.pa_operation_unref)(pOP); + ma_device__wait_for_operation__pulse(pDevice, pOP); + ((ma_pa_operation_unref_proc)pDevice->pContext->pulse.pa_operation_unref)(pOP); } - result = mal_device__cork_stream__pulse(pDevice, mal_device_type_playback, 1); + result = ma_device__cork_stream__pulse(pDevice, ma_device_type_playback, 1); if (result != MA_SUCCESS) { return result; } @@ -14570,21 +14570,21 @@ mal_result mal_device_stop__pulse(mal_device* pDevice) return MA_SUCCESS; } -mal_result mal_device_write__pulse(mal_device* pDevice, const void* pPCMFrames, mal_uint32 frameCount) +ma_result ma_device_write__pulse(ma_device* pDevice, const void* pPCMFrames, ma_uint32 frameCount) { - mal_assert(pDevice != NULL); - mal_assert(pPCMFrames != NULL); - mal_assert(frameCount > 0); + ma_assert(pDevice != NULL); + ma_assert(pPCMFrames != NULL); + ma_assert(frameCount > 0); /* The stream needs to be uncorked first. */ - if (((mal_pa_stream_is_corked_proc)pDevice->pContext->pulse.pa_stream_is_corked)(pDevice->pulse.pStreamPlayback)) { - mal_result result = mal_device__cork_stream__pulse(pDevice, mal_device_type_playback, 0); + if (((ma_pa_stream_is_corked_proc)pDevice->pContext->pulse.pa_stream_is_corked)(pDevice->pulse.pStreamPlayback)) { + ma_result result = ma_device__cork_stream__pulse(pDevice, ma_device_type_playback, 0); if (result != MA_SUCCESS) { return result; } } - mal_uint32 totalFramesWritten = 0; + ma_uint32 totalFramesWritten = 0; while (totalFramesWritten < frameCount) { //printf("TRACE: Outer loop.\n"); @@ -14592,13 +14592,13 @@ mal_result mal_device_write__pulse(mal_device* pDevice, const void* pPCMFrames, if (pDevice->pulse.pMappedBufferPlayback != NULL && pDevice->pulse.mappedBufferFramesRemainingPlayback > 0) { //printf("TRACE: Copying data.\n"); - mal_uint32 bpf = mal_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels); - mal_uint32 mappedBufferFramesConsumed = pDevice->pulse.mappedBufferFramesCapacityPlayback - pDevice->pulse.mappedBufferFramesRemainingPlayback; + ma_uint32 bpf = ma_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels); + ma_uint32 mappedBufferFramesConsumed = pDevice->pulse.mappedBufferFramesCapacityPlayback - pDevice->pulse.mappedBufferFramesRemainingPlayback; - void* pDst = (mal_uint8*)pDevice->pulse.pMappedBufferPlayback + (mappedBufferFramesConsumed * bpf); - const void* pSrc = (const mal_uint8*)pPCMFrames + (totalFramesWritten * bpf); - mal_uint32 framesToCopy = mal_min(pDevice->pulse.mappedBufferFramesRemainingPlayback, (frameCount - totalFramesWritten)); - mal_copy_memory(pDst, pSrc, framesToCopy * bpf); + void* pDst = (ma_uint8*)pDevice->pulse.pMappedBufferPlayback + (mappedBufferFramesConsumed * bpf); + const void* pSrc = (const ma_uint8*)pPCMFrames + (totalFramesWritten * bpf); + ma_uint32 framesToCopy = ma_min(pDevice->pulse.mappedBufferFramesRemainingPlayback, (frameCount - totalFramesWritten)); + ma_copy_memory(pDst, pSrc, framesToCopy * bpf); pDevice->pulse.mappedBufferFramesRemainingPlayback -= framesToCopy; totalFramesWritten += framesToCopy; @@ -14609,12 +14609,12 @@ mal_result mal_device_write__pulse(mal_device* pDevice, const void* pPCMFrames, mapping another chunk. If this fails we need to wait for space to become available. */ if (pDevice->pulse.mappedBufferFramesCapacityPlayback > 0 && pDevice->pulse.mappedBufferFramesRemainingPlayback == 0) { - size_t nbytes = pDevice->pulse.mappedBufferFramesCapacityPlayback * mal_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels); + size_t nbytes = pDevice->pulse.mappedBufferFramesCapacityPlayback * ma_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels); //printf("TRACE: Submitting data. %d\n", nbytes); - int error = ((mal_pa_stream_write_proc)pDevice->pContext->pulse.pa_stream_write)((mal_pa_stream*)pDevice->pulse.pStreamPlayback, pDevice->pulse.pMappedBufferPlayback, nbytes, NULL, 0, MA_PA_SEEK_RELATIVE); + int error = ((ma_pa_stream_write_proc)pDevice->pContext->pulse.pa_stream_write)((ma_pa_stream*)pDevice->pulse.pStreamPlayback, pDevice->pulse.pMappedBufferPlayback, nbytes, NULL, 0, MA_PA_SEEK_RELATIVE); if (error < 0) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to write data to the PulseAudio stream.", mal_result_from_pulse(error)); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to write data to the PulseAudio stream.", ma_result_from_pulse(error)); } pDevice->pulse.pMappedBufferPlayback = NULL; @@ -14622,7 +14622,7 @@ mal_result mal_device_write__pulse(mal_device* pDevice, const void* pPCMFrames, pDevice->pulse.mappedBufferFramesCapacityPlayback = 0; } - mal_assert(totalFramesWritten <= frameCount); + ma_assert(totalFramesWritten <= frameCount); if (totalFramesWritten == frameCount) { break; } @@ -14632,24 +14632,24 @@ mal_result mal_device_write__pulse(mal_device* pDevice, const void* pPCMFrames, //printf("TRACE: Inner loop.\n"); /* If the device has been corked, don't try to continue. */ - if (((mal_pa_stream_is_corked_proc)pDevice->pContext->pulse.pa_stream_is_corked)(pDevice->pulse.pStreamPlayback)) { + if (((ma_pa_stream_is_corked_proc)pDevice->pContext->pulse.pa_stream_is_corked)(pDevice->pulse.pStreamPlayback)) { break; } - size_t writableSizeInBytes = ((mal_pa_stream_writable_size_proc)pDevice->pContext->pulse.pa_stream_writable_size)((mal_pa_stream*)pDevice->pulse.pStreamPlayback); + size_t writableSizeInBytes = ((ma_pa_stream_writable_size_proc)pDevice->pContext->pulse.pa_stream_writable_size)((ma_pa_stream*)pDevice->pulse.pStreamPlayback); if (writableSizeInBytes != (size_t)-1) { - size_t periodSizeInBytes = (pDevice->playback.internalBufferSizeInFrames / pDevice->playback.internalPeriods) * mal_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels); + size_t periodSizeInBytes = (pDevice->playback.internalBufferSizeInFrames / pDevice->playback.internalPeriods) * ma_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels); if (writableSizeInBytes >= periodSizeInBytes) { //printf("TRACE: Data available.\n"); /* Data is avaialable. */ size_t bytesToMap = periodSizeInBytes; - int error = ((mal_pa_stream_begin_write_proc)pDevice->pContext->pulse.pa_stream_begin_write)((mal_pa_stream*)pDevice->pulse.pStreamPlayback, &pDevice->pulse.pMappedBufferPlayback, &bytesToMap); + int error = ((ma_pa_stream_begin_write_proc)pDevice->pContext->pulse.pa_stream_begin_write)((ma_pa_stream*)pDevice->pulse.pStreamPlayback, &pDevice->pulse.pMappedBufferPlayback, &bytesToMap); if (error < 0) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to map write buffer.", mal_result_from_pulse(error)); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to map write buffer.", ma_result_from_pulse(error)); } - pDevice->pulse.mappedBufferFramesCapacityPlayback = bytesToMap / mal_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels); + pDevice->pulse.mappedBufferFramesCapacityPlayback = bytesToMap / ma_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels); pDevice->pulse.mappedBufferFramesRemainingPlayback = pDevice->pulse.mappedBufferFramesCapacityPlayback; break; @@ -14657,15 +14657,15 @@ mal_result mal_device_write__pulse(mal_device* pDevice, const void* pPCMFrames, /* No data available. Need to wait for more. */ //printf("TRACE: Playback: pa_mainloop_iterate(). writableSizeInBytes=%d, periodSizeInBytes=%d\n", writableSizeInBytes, periodSizeInBytes); - int error = ((mal_pa_mainloop_iterate_proc)pDevice->pContext->pulse.pa_mainloop_iterate)(pDevice->pulse.pMainLoop, 1, NULL); + int error = ((ma_pa_mainloop_iterate_proc)pDevice->pContext->pulse.pa_mainloop_iterate)(pDevice->pulse.pMainLoop, 1, NULL); if (error < 0) { - return mal_result_from_pulse(error); + return ma_result_from_pulse(error); } continue; } } else { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to query the stream's writable size.", MA_ERROR); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to query the stream's writable size.", MA_ERROR); } } } @@ -14673,39 +14673,39 @@ mal_result mal_device_write__pulse(mal_device* pDevice, const void* pPCMFrames, return MA_SUCCESS; } -mal_result mal_device_read__pulse(mal_device* pDevice, void* pPCMFrames, mal_uint32 frameCount) +ma_result ma_device_read__pulse(ma_device* pDevice, void* pPCMFrames, ma_uint32 frameCount) { - mal_assert(pDevice != NULL); - mal_assert(pPCMFrames != NULL); - mal_assert(frameCount > 0); + ma_assert(pDevice != NULL); + ma_assert(pPCMFrames != NULL); + ma_assert(frameCount > 0); /* The stream needs to be uncorked first. */ - if (((mal_pa_stream_is_corked_proc)pDevice->pContext->pulse.pa_stream_is_corked)(pDevice->pulse.pStreamCapture)) { - mal_result result = mal_device__cork_stream__pulse(pDevice, mal_device_type_capture, 0); + if (((ma_pa_stream_is_corked_proc)pDevice->pContext->pulse.pa_stream_is_corked)(pDevice->pulse.pStreamCapture)) { + ma_result result = ma_device__cork_stream__pulse(pDevice, ma_device_type_capture, 0); if (result != MA_SUCCESS) { return result; } } - mal_uint32 totalFramesRead = 0; + ma_uint32 totalFramesRead = 0; while (totalFramesRead < frameCount) { /* If a buffer is mapped we need to write to that first. Once it's consumed we reset the event and unmap it. */ if (pDevice->pulse.pMappedBufferCapture != NULL && pDevice->pulse.mappedBufferFramesRemainingCapture > 0) { - mal_uint32 bpf = mal_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels); - mal_uint32 mappedBufferFramesConsumed = pDevice->pulse.mappedBufferFramesCapacityCapture - pDevice->pulse.mappedBufferFramesRemainingCapture; + ma_uint32 bpf = ma_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels); + ma_uint32 mappedBufferFramesConsumed = pDevice->pulse.mappedBufferFramesCapacityCapture - pDevice->pulse.mappedBufferFramesRemainingCapture; - mal_uint32 framesToCopy = mal_min(pDevice->pulse.mappedBufferFramesRemainingCapture, (frameCount - totalFramesRead)); - void* pDst = (mal_uint8*)pPCMFrames + (totalFramesRead * bpf); + ma_uint32 framesToCopy = ma_min(pDevice->pulse.mappedBufferFramesRemainingCapture, (frameCount - totalFramesRead)); + void* pDst = (ma_uint8*)pPCMFrames + (totalFramesRead * bpf); /* This little bit of logic here is specifically for PulseAudio and it's hole management. The buffer pointer will be set to NULL when the current fragment is a hole. For a hole we just output silence. */ if (pDevice->pulse.pMappedBufferCapture != NULL) { - const void* pSrc = (const mal_uint8*)pDevice->pulse.pMappedBufferCapture + (mappedBufferFramesConsumed * bpf); - mal_copy_memory(pDst, pSrc, framesToCopy * bpf); + const void* pSrc = (const ma_uint8*)pDevice->pulse.pMappedBufferCapture + (mappedBufferFramesConsumed * bpf); + ma_copy_memory(pDst, pSrc, framesToCopy * bpf); } else { - mal_zero_memory(pDst, framesToCopy * bpf); + ma_zero_memory(pDst, framesToCopy * bpf); } pDevice->pulse.mappedBufferFramesRemainingCapture -= framesToCopy; @@ -14719,9 +14719,9 @@ mal_result mal_device_read__pulse(mal_device* pDevice, void* pPCMFrames, mal_uin if (pDevice->pulse.mappedBufferFramesCapacityCapture > 0 && pDevice->pulse.mappedBufferFramesRemainingCapture == 0) { //printf("TRACE: Dropping fragment. %d\n", nbytes); - int error = ((mal_pa_stream_drop_proc)pDevice->pContext->pulse.pa_stream_drop)((mal_pa_stream*)pDevice->pulse.pStreamCapture); + int error = ((ma_pa_stream_drop_proc)pDevice->pContext->pulse.pa_stream_drop)((ma_pa_stream*)pDevice->pulse.pStreamCapture); if (error != 0) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to drop fragment.", mal_result_from_pulse(error)); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to drop fragment.", ma_result_from_pulse(error)); } pDevice->pulse.pMappedBufferCapture = NULL; @@ -14729,7 +14729,7 @@ mal_result mal_device_read__pulse(mal_device* pDevice, void* pPCMFrames, mal_uin pDevice->pulse.mappedBufferFramesCapacityCapture = 0; } - mal_assert(totalFramesRead <= frameCount); + ma_assert(totalFramesRead <= frameCount); if (totalFramesRead == frameCount) { break; } @@ -14739,29 +14739,29 @@ mal_result mal_device_read__pulse(mal_device* pDevice, void* pPCMFrames, mal_uin //printf("TRACE: Inner loop.\n"); /* If the device has been corked, don't try to continue. */ - if (((mal_pa_stream_is_corked_proc)pDevice->pContext->pulse.pa_stream_is_corked)(pDevice->pulse.pStreamCapture)) { + if (((ma_pa_stream_is_corked_proc)pDevice->pContext->pulse.pa_stream_is_corked)(pDevice->pulse.pStreamCapture)) { break; } - size_t readableSizeInBytes = ((mal_pa_stream_readable_size_proc)pDevice->pContext->pulse.pa_stream_readable_size)((mal_pa_stream*)pDevice->pulse.pStreamCapture); + size_t readableSizeInBytes = ((ma_pa_stream_readable_size_proc)pDevice->pContext->pulse.pa_stream_readable_size)((ma_pa_stream*)pDevice->pulse.pStreamCapture); if (readableSizeInBytes != (size_t)-1) { - size_t periodSizeInBytes = (pDevice->capture.internalBufferSizeInFrames / pDevice->capture.internalPeriods) * mal_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels); + size_t periodSizeInBytes = (pDevice->capture.internalBufferSizeInFrames / pDevice->capture.internalPeriods) * ma_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels); if (readableSizeInBytes >= periodSizeInBytes) { /* Data is avaialable. */ size_t bytesMapped = (size_t)-1; - int error = ((mal_pa_stream_peek_proc)pDevice->pContext->pulse.pa_stream_peek)((mal_pa_stream*)pDevice->pulse.pStreamCapture, &pDevice->pulse.pMappedBufferCapture, &bytesMapped); + int error = ((ma_pa_stream_peek_proc)pDevice->pContext->pulse.pa_stream_peek)((ma_pa_stream*)pDevice->pulse.pStreamCapture, &pDevice->pulse.pMappedBufferCapture, &bytesMapped); if (error < 0) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to peek capture buffer.", mal_result_from_pulse(error)); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to peek capture buffer.", ma_result_from_pulse(error)); } //printf("TRACE: Data available: bytesMapped=%d, readableSizeInBytes=%d, periodSizeInBytes=%d.\n", bytesMapped, readableSizeInBytes, periodSizeInBytes); if (pDevice->pulse.pMappedBufferCapture == NULL && bytesMapped == 0) { /* Nothing available. This shouldn't happen because we checked earlier with pa_stream_readable_size(). I'm going to throw an error in this case. */ - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Nothing available after peeking capture buffer.", MA_ERROR); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Nothing available after peeking capture buffer.", MA_ERROR); } - pDevice->pulse.mappedBufferFramesCapacityCapture = bytesMapped / mal_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels); + pDevice->pulse.mappedBufferFramesCapacityCapture = bytesMapped / ma_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels); pDevice->pulse.mappedBufferFramesRemainingCapture = pDevice->pulse.mappedBufferFramesCapacityCapture; break; @@ -14769,15 +14769,15 @@ mal_result mal_device_read__pulse(mal_device* pDevice, void* pPCMFrames, mal_uin /* No data available. Need to wait for more. */ //printf("TRACE: Capture: pa_mainloop_iterate(). readableSizeInBytes=%d, periodSizeInBytes=%d\n", readableSizeInBytes, periodSizeInBytes); - int error = ((mal_pa_mainloop_iterate_proc)pDevice->pContext->pulse.pa_mainloop_iterate)(pDevice->pulse.pMainLoop, 1, NULL); + int error = ((ma_pa_mainloop_iterate_proc)pDevice->pContext->pulse.pa_mainloop_iterate)(pDevice->pulse.pMainLoop, 1, NULL); if (error < 0) { - return mal_result_from_pulse(error); + return ma_result_from_pulse(error); } continue; } } else { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to query the stream's readable size.", MA_ERROR); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[PulseAudio] Failed to query the stream's readable size.", MA_ERROR); } } } @@ -14786,21 +14786,21 @@ mal_result mal_device_read__pulse(mal_device* pDevice, void* pPCMFrames, mal_uin } -mal_result mal_context_uninit__pulse(mal_context* pContext) +ma_result ma_context_uninit__pulse(ma_context* pContext) { - mal_assert(pContext != NULL); - mal_assert(pContext->backend == mal_backend_pulseaudio); + ma_assert(pContext != NULL); + ma_assert(pContext->backend == ma_backend_pulseaudio); #ifndef MA_NO_RUNTIME_LINKING - mal_dlclose(pContext->pulse.pulseSO); + ma_dlclose(pContext->pulse.pulseSO); #endif return MA_SUCCESS; } -mal_result mal_context_init__pulse(mal_context* pContext) +ma_result ma_context_init__pulse(ma_context* pContext) { - mal_assert(pContext != NULL); + ma_assert(pContext != NULL); #ifndef MA_NO_RUNTIME_LINKING // libpulse.so @@ -14809,8 +14809,8 @@ mal_result mal_context_init__pulse(mal_context* pContext) "libpulse.so.0" }; - for (size_t i = 0; i < mal_countof(libpulseNames); ++i) { - pContext->pulse.pulseSO = mal_dlopen(libpulseNames[i]); + for (size_t i = 0; i < ma_countof(libpulseNames); ++i) { + pContext->pulse.pulseSO = ma_dlopen(libpulseNames[i]); if (pContext->pulse.pulseSO != NULL) { break; } @@ -14820,184 +14820,184 @@ mal_result mal_context_init__pulse(mal_context* pContext) return MA_NO_BACKEND; } - pContext->pulse.pa_mainloop_new = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_mainloop_new"); - pContext->pulse.pa_mainloop_free = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_mainloop_free"); - pContext->pulse.pa_mainloop_get_api = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_mainloop_get_api"); - pContext->pulse.pa_mainloop_iterate = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_mainloop_iterate"); - pContext->pulse.pa_mainloop_wakeup = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_mainloop_wakeup"); - pContext->pulse.pa_context_new = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_context_new"); - pContext->pulse.pa_context_unref = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_context_unref"); - pContext->pulse.pa_context_connect = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_context_connect"); - pContext->pulse.pa_context_disconnect = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_context_disconnect"); - pContext->pulse.pa_context_set_state_callback = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_context_set_state_callback"); - pContext->pulse.pa_context_get_state = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_context_get_state"); - pContext->pulse.pa_context_get_sink_info_list = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_context_get_sink_info_list"); - pContext->pulse.pa_context_get_source_info_list = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_context_get_source_info_list"); - pContext->pulse.pa_context_get_sink_info_by_name = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_context_get_sink_info_by_name"); - pContext->pulse.pa_context_get_source_info_by_name = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_context_get_source_info_by_name"); - pContext->pulse.pa_operation_unref = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_operation_unref"); - pContext->pulse.pa_operation_get_state = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_operation_get_state"); - pContext->pulse.pa_channel_map_init_extend = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_channel_map_init_extend"); - pContext->pulse.pa_channel_map_valid = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_channel_map_valid"); - pContext->pulse.pa_channel_map_compatible = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_channel_map_compatible"); - pContext->pulse.pa_stream_new = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_stream_new"); - pContext->pulse.pa_stream_unref = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_stream_unref"); - pContext->pulse.pa_stream_connect_playback = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_stream_connect_playback"); - pContext->pulse.pa_stream_connect_record = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_stream_connect_record"); - pContext->pulse.pa_stream_disconnect = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_stream_disconnect"); - pContext->pulse.pa_stream_get_state = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_stream_get_state"); - pContext->pulse.pa_stream_get_sample_spec = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_stream_get_sample_spec"); - pContext->pulse.pa_stream_get_channel_map = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_stream_get_channel_map"); - pContext->pulse.pa_stream_get_buffer_attr = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_stream_get_buffer_attr"); - pContext->pulse.pa_stream_set_buffer_attr = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_stream_set_buffer_attr"); - pContext->pulse.pa_stream_get_device_name = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_stream_get_device_name"); - pContext->pulse.pa_stream_set_write_callback = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_stream_set_write_callback"); - pContext->pulse.pa_stream_set_read_callback = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_stream_set_read_callback"); - pContext->pulse.pa_stream_flush = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_stream_flush"); - pContext->pulse.pa_stream_drain = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_stream_drain"); - pContext->pulse.pa_stream_is_corked = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_stream_is_corked"); - pContext->pulse.pa_stream_cork = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_stream_cork"); - pContext->pulse.pa_stream_trigger = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_stream_trigger"); - pContext->pulse.pa_stream_begin_write = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_stream_begin_write"); - pContext->pulse.pa_stream_write = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_stream_write"); - pContext->pulse.pa_stream_peek = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_stream_peek"); - pContext->pulse.pa_stream_drop = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_stream_drop"); - pContext->pulse.pa_stream_writable_size = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_stream_writable_size"); - pContext->pulse.pa_stream_readable_size = (mal_proc)mal_dlsym(pContext->pulse.pulseSO, "pa_stream_readable_size"); + pContext->pulse.pa_mainloop_new = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_mainloop_new"); + pContext->pulse.pa_mainloop_free = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_mainloop_free"); + pContext->pulse.pa_mainloop_get_api = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_mainloop_get_api"); + pContext->pulse.pa_mainloop_iterate = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_mainloop_iterate"); + pContext->pulse.pa_mainloop_wakeup = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_mainloop_wakeup"); + pContext->pulse.pa_context_new = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_context_new"); + pContext->pulse.pa_context_unref = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_context_unref"); + pContext->pulse.pa_context_connect = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_context_connect"); + pContext->pulse.pa_context_disconnect = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_context_disconnect"); + pContext->pulse.pa_context_set_state_callback = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_context_set_state_callback"); + pContext->pulse.pa_context_get_state = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_context_get_state"); + pContext->pulse.pa_context_get_sink_info_list = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_context_get_sink_info_list"); + pContext->pulse.pa_context_get_source_info_list = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_context_get_source_info_list"); + pContext->pulse.pa_context_get_sink_info_by_name = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_context_get_sink_info_by_name"); + pContext->pulse.pa_context_get_source_info_by_name = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_context_get_source_info_by_name"); + pContext->pulse.pa_operation_unref = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_operation_unref"); + pContext->pulse.pa_operation_get_state = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_operation_get_state"); + pContext->pulse.pa_channel_map_init_extend = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_channel_map_init_extend"); + pContext->pulse.pa_channel_map_valid = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_channel_map_valid"); + pContext->pulse.pa_channel_map_compatible = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_channel_map_compatible"); + pContext->pulse.pa_stream_new = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_stream_new"); + pContext->pulse.pa_stream_unref = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_stream_unref"); + pContext->pulse.pa_stream_connect_playback = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_stream_connect_playback"); + pContext->pulse.pa_stream_connect_record = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_stream_connect_record"); + pContext->pulse.pa_stream_disconnect = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_stream_disconnect"); + pContext->pulse.pa_stream_get_state = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_stream_get_state"); + pContext->pulse.pa_stream_get_sample_spec = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_stream_get_sample_spec"); + pContext->pulse.pa_stream_get_channel_map = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_stream_get_channel_map"); + pContext->pulse.pa_stream_get_buffer_attr = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_stream_get_buffer_attr"); + pContext->pulse.pa_stream_set_buffer_attr = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_stream_set_buffer_attr"); + pContext->pulse.pa_stream_get_device_name = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_stream_get_device_name"); + pContext->pulse.pa_stream_set_write_callback = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_stream_set_write_callback"); + pContext->pulse.pa_stream_set_read_callback = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_stream_set_read_callback"); + pContext->pulse.pa_stream_flush = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_stream_flush"); + pContext->pulse.pa_stream_drain = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_stream_drain"); + pContext->pulse.pa_stream_is_corked = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_stream_is_corked"); + pContext->pulse.pa_stream_cork = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_stream_cork"); + pContext->pulse.pa_stream_trigger = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_stream_trigger"); + pContext->pulse.pa_stream_begin_write = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_stream_begin_write"); + pContext->pulse.pa_stream_write = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_stream_write"); + pContext->pulse.pa_stream_peek = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_stream_peek"); + pContext->pulse.pa_stream_drop = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_stream_drop"); + pContext->pulse.pa_stream_writable_size = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_stream_writable_size"); + pContext->pulse.pa_stream_readable_size = (ma_proc)ma_dlsym(pContext->pulse.pulseSO, "pa_stream_readable_size"); #else // This strange assignment system is just for type safety. - mal_pa_mainloop_new_proc _pa_mainloop_new = pa_mainloop_new; - mal_pa_mainloop_free_proc _pa_mainloop_free = pa_mainloop_free; - mal_pa_mainloop_get_api_proc _pa_mainloop_get_api = pa_mainloop_get_api; - mal_pa_mainloop_iterate_proc _pa_mainloop_iterate = pa_mainloop_iterate; - mal_pa_mainloop_wakeup_proc _pa_mainloop_wakeup = pa_mainloop_wakeup; - mal_pa_context_new_proc _pa_context_new = pa_context_new; - mal_pa_context_unref_proc _pa_context_unref = pa_context_unref; - mal_pa_context_connect_proc _pa_context_connect = pa_context_connect; - mal_pa_context_disconnect_proc _pa_context_disconnect = pa_context_disconnect; - mal_pa_context_set_state_callback_proc _pa_context_set_state_callback = pa_context_set_state_callback; - mal_pa_context_get_state_proc _pa_context_get_state = pa_context_get_state; - mal_pa_context_get_sink_info_list_proc _pa_context_get_sink_info_list = pa_context_get_sink_info_list; - mal_pa_context_get_source_info_list_proc _pa_context_get_source_info_list = pa_context_get_source_info_list; - mal_pa_context_get_sink_info_by_name_proc _pa_context_get_sink_info_by_name = pa_context_get_sink_info_by_name; - mal_pa_context_get_source_info_by_name_proc _pa_context_get_source_info_by_name= pa_context_get_source_info_by_name; - mal_pa_operation_unref_proc _pa_operation_unref = pa_operation_unref; - mal_pa_operation_get_state_proc _pa_operation_get_state = pa_operation_get_state; - mal_pa_channel_map_init_extend_proc _pa_channel_map_init_extend = pa_channel_map_init_extend; - mal_pa_channel_map_valid_proc _pa_channel_map_valid = pa_channel_map_valid; - mal_pa_channel_map_compatible_proc _pa_channel_map_compatible = pa_channel_map_compatible; - mal_pa_stream_new_proc _pa_stream_new = pa_stream_new; - mal_pa_stream_unref_proc _pa_stream_unref = pa_stream_unref; - mal_pa_stream_connect_playback_proc _pa_stream_connect_playback = pa_stream_connect_playback; - mal_pa_stream_connect_record_proc _pa_stream_connect_record = pa_stream_connect_record; - mal_pa_stream_disconnect_proc _pa_stream_disconnect = pa_stream_disconnect; - mal_pa_stream_get_state_proc _pa_stream_get_state = pa_stream_get_state; - mal_pa_stream_get_sample_spec_proc _pa_stream_get_sample_spec = pa_stream_get_sample_spec; - mal_pa_stream_get_channel_map_proc _pa_stream_get_channel_map = pa_stream_get_channel_map; - mal_pa_stream_get_buffer_attr_proc _pa_stream_get_buffer_attr = pa_stream_get_buffer_attr; - mal_pa_stream_set_buffer_attr_proc _pa_stream_set_buffer_attr = pa_stream_set_buffer_attr; - mal_pa_stream_get_device_name_proc _pa_stream_get_device_name = pa_stream_get_device_name; - mal_pa_stream_set_write_callback_proc _pa_stream_set_write_callback = pa_stream_set_write_callback; - mal_pa_stream_set_read_callback_proc _pa_stream_set_read_callback = pa_stream_set_read_callback; - mal_pa_stream_flush_proc _pa_stream_flush = pa_stream_flush; - mal_pa_stream_drain_proc _pa_stream_drain = pa_stream_drain; - mal_pa_stream_ic_corked_proc _pa_stream_is_corked = pa_stream_is_corked; - mal_pa_stream_cork_proc _pa_stream_cork = pa_stream_cork; - mal_pa_stream_trigger_proc _pa_stream_trigger = pa_stream_trigger; - mal_pa_stream_begin_write_proc _pa_stream_begin_write = pa_stream_begin_write; - mal_pa_stream_write_proc _pa_stream_write = pa_stream_write; - mal_pa_stream_peek_proc _pa_stream_peek = pa_stream_peek; - mal_pa_stream_drop_proc _pa_stream_drop = pa_stream_drop; - mal_pa_stream_writable_size_proc _pa_stream_writable_size = pa_stream_writable_size; - mal_pa_stream_readable_size_proc _pa_stream_readable_size = pa_stream_readable_size; + ma_pa_mainloop_new_proc _pa_mainloop_new = pa_mainloop_new; + ma_pa_mainloop_free_proc _pa_mainloop_free = pa_mainloop_free; + ma_pa_mainloop_get_api_proc _pa_mainloop_get_api = pa_mainloop_get_api; + ma_pa_mainloop_iterate_proc _pa_mainloop_iterate = pa_mainloop_iterate; + ma_pa_mainloop_wakeup_proc _pa_mainloop_wakeup = pa_mainloop_wakeup; + ma_pa_context_new_proc _pa_context_new = pa_context_new; + ma_pa_context_unref_proc _pa_context_unref = pa_context_unref; + ma_pa_context_connect_proc _pa_context_connect = pa_context_connect; + ma_pa_context_disconnect_proc _pa_context_disconnect = pa_context_disconnect; + ma_pa_context_set_state_callback_proc _pa_context_set_state_callback = pa_context_set_state_callback; + ma_pa_context_get_state_proc _pa_context_get_state = pa_context_get_state; + ma_pa_context_get_sink_info_list_proc _pa_context_get_sink_info_list = pa_context_get_sink_info_list; + ma_pa_context_get_source_info_list_proc _pa_context_get_source_info_list = pa_context_get_source_info_list; + ma_pa_context_get_sink_info_by_name_proc _pa_context_get_sink_info_by_name = pa_context_get_sink_info_by_name; + ma_pa_context_get_source_info_by_name_proc _pa_context_get_source_info_by_name= pa_context_get_source_info_by_name; + ma_pa_operation_unref_proc _pa_operation_unref = pa_operation_unref; + ma_pa_operation_get_state_proc _pa_operation_get_state = pa_operation_get_state; + ma_pa_channel_map_init_extend_proc _pa_channel_map_init_extend = pa_channel_map_init_extend; + ma_pa_channel_map_valid_proc _pa_channel_map_valid = pa_channel_map_valid; + ma_pa_channel_map_compatible_proc _pa_channel_map_compatible = pa_channel_map_compatible; + ma_pa_stream_new_proc _pa_stream_new = pa_stream_new; + ma_pa_stream_unref_proc _pa_stream_unref = pa_stream_unref; + ma_pa_stream_connect_playback_proc _pa_stream_connect_playback = pa_stream_connect_playback; + ma_pa_stream_connect_record_proc _pa_stream_connect_record = pa_stream_connect_record; + ma_pa_stream_disconnect_proc _pa_stream_disconnect = pa_stream_disconnect; + ma_pa_stream_get_state_proc _pa_stream_get_state = pa_stream_get_state; + ma_pa_stream_get_sample_spec_proc _pa_stream_get_sample_spec = pa_stream_get_sample_spec; + ma_pa_stream_get_channel_map_proc _pa_stream_get_channel_map = pa_stream_get_channel_map; + ma_pa_stream_get_buffer_attr_proc _pa_stream_get_buffer_attr = pa_stream_get_buffer_attr; + ma_pa_stream_set_buffer_attr_proc _pa_stream_set_buffer_attr = pa_stream_set_buffer_attr; + ma_pa_stream_get_device_name_proc _pa_stream_get_device_name = pa_stream_get_device_name; + ma_pa_stream_set_write_callback_proc _pa_stream_set_write_callback = pa_stream_set_write_callback; + ma_pa_stream_set_read_callback_proc _pa_stream_set_read_callback = pa_stream_set_read_callback; + ma_pa_stream_flush_proc _pa_stream_flush = pa_stream_flush; + ma_pa_stream_drain_proc _pa_stream_drain = pa_stream_drain; + ma_pa_stream_ic_corked_proc _pa_stream_is_corked = pa_stream_is_corked; + ma_pa_stream_cork_proc _pa_stream_cork = pa_stream_cork; + ma_pa_stream_trigger_proc _pa_stream_trigger = pa_stream_trigger; + ma_pa_stream_begin_write_proc _pa_stream_begin_write = pa_stream_begin_write; + ma_pa_stream_write_proc _pa_stream_write = pa_stream_write; + ma_pa_stream_peek_proc _pa_stream_peek = pa_stream_peek; + ma_pa_stream_drop_proc _pa_stream_drop = pa_stream_drop; + ma_pa_stream_writable_size_proc _pa_stream_writable_size = pa_stream_writable_size; + ma_pa_stream_readable_size_proc _pa_stream_readable_size = pa_stream_readable_size; - pContext->pulse.pa_mainloop_new = (mal_proc)_pa_mainloop_new; - pContext->pulse.pa_mainloop_free = (mal_proc)_pa_mainloop_free; - pContext->pulse.pa_mainloop_get_api = (mal_proc)_pa_mainloop_get_api; - pContext->pulse.pa_mainloop_iterate = (mal_proc)_pa_mainloop_iterate; - pContext->pulse.pa_mainloop_wakeup = (mal_proc)_pa_mainloop_wakeup; - pContext->pulse.pa_context_new = (mal_proc)_pa_context_new; - pContext->pulse.pa_context_unref = (mal_proc)_pa_context_unref; - pContext->pulse.pa_context_connect = (mal_proc)_pa_context_connect; - pContext->pulse.pa_context_disconnect = (mal_proc)_pa_context_disconnect; - pContext->pulse.pa_context_set_state_callback = (mal_proc)_pa_context_set_state_callback; - pContext->pulse.pa_context_get_state = (mal_proc)_pa_context_get_state; - pContext->pulse.pa_context_get_sink_info_list = (mal_proc)_pa_context_get_sink_info_list; - pContext->pulse.pa_context_get_source_info_list = (mal_proc)_pa_context_get_source_info_list; - pContext->pulse.pa_context_get_sink_info_by_name = (mal_proc)_pa_context_get_sink_info_by_name; - pContext->pulse.pa_context_get_source_info_by_name = (mal_proc)_pa_context_get_source_info_by_name; - pContext->pulse.pa_operation_unref = (mal_proc)_pa_operation_unref; - pContext->pulse.pa_operation_get_state = (mal_proc)_pa_operation_get_state; - pContext->pulse.pa_channel_map_init_extend = (mal_proc)_pa_channel_map_init_extend; - pContext->pulse.pa_channel_map_valid = (mal_proc)_pa_channel_map_valid; - pContext->pulse.pa_channel_map_compatible = (mal_proc)_pa_channel_map_compatible; - pContext->pulse.pa_stream_new = (mal_proc)_pa_stream_new; - pContext->pulse.pa_stream_unref = (mal_proc)_pa_stream_unref; - pContext->pulse.pa_stream_connect_playback = (mal_proc)_pa_stream_connect_playback; - pContext->pulse.pa_stream_connect_record = (mal_proc)_pa_stream_connect_record; - pContext->pulse.pa_stream_disconnect = (mal_proc)_pa_stream_disconnect; - pContext->pulse.pa_stream_get_state = (mal_proc)_pa_stream_get_state; - pContext->pulse.pa_stream_get_sample_spec = (mal_proc)_pa_stream_get_sample_spec; - pContext->pulse.pa_stream_get_channel_map = (mal_proc)_pa_stream_get_channel_map; - pContext->pulse.pa_stream_get_buffer_attr = (mal_proc)_pa_stream_get_buffer_attr; - pContext->pulse.pa_stream_set_buffer_attr = (mal_proc)_pa_stream_set_buffer_attr; - pContext->pulse.pa_stream_get_device_name = (mal_proc)_pa_stream_get_device_name; - pContext->pulse.pa_stream_set_write_callback = (mal_proc)_pa_stream_set_write_callback; - pContext->pulse.pa_stream_set_read_callback = (mal_proc)_pa_stream_set_read_callback; - pContext->pulse.pa_stream_flush = (mal_proc)_pa_stream_flush; - pContext->pulse.pa_stream_drain = (mal_proc)_pa_stream_drain; - pContext->pulse.pa_stream_is_corked = (mal_proc)_pa_stream_is_corked; - pContext->pulse.pa_stream_cork = (mal_proc)_pa_stream_cork; - pContext->pulse.pa_stream_trigger = (mal_proc)_pa_stream_trigger; - pContext->pulse.pa_stream_begin_write = (mal_proc)_pa_stream_begin_write; - pContext->pulse.pa_stream_write = (mal_proc)_pa_stream_write; - pContext->pulse.pa_stream_peek = (mal_proc)_pa_stream_peek; - pContext->pulse.pa_stream_drop = (mal_proc)_pa_stream_drop; - pContext->pulse.pa_stream_writable_size = (mal_proc)_pa_stream_writable_size; - pContext->pulse.pa_stream_readable_size = (mal_proc)_pa_stream_readable_size; + pContext->pulse.pa_mainloop_new = (ma_proc)_pa_mainloop_new; + pContext->pulse.pa_mainloop_free = (ma_proc)_pa_mainloop_free; + pContext->pulse.pa_mainloop_get_api = (ma_proc)_pa_mainloop_get_api; + pContext->pulse.pa_mainloop_iterate = (ma_proc)_pa_mainloop_iterate; + pContext->pulse.pa_mainloop_wakeup = (ma_proc)_pa_mainloop_wakeup; + pContext->pulse.pa_context_new = (ma_proc)_pa_context_new; + pContext->pulse.pa_context_unref = (ma_proc)_pa_context_unref; + pContext->pulse.pa_context_connect = (ma_proc)_pa_context_connect; + pContext->pulse.pa_context_disconnect = (ma_proc)_pa_context_disconnect; + pContext->pulse.pa_context_set_state_callback = (ma_proc)_pa_context_set_state_callback; + pContext->pulse.pa_context_get_state = (ma_proc)_pa_context_get_state; + pContext->pulse.pa_context_get_sink_info_list = (ma_proc)_pa_context_get_sink_info_list; + pContext->pulse.pa_context_get_source_info_list = (ma_proc)_pa_context_get_source_info_list; + pContext->pulse.pa_context_get_sink_info_by_name = (ma_proc)_pa_context_get_sink_info_by_name; + pContext->pulse.pa_context_get_source_info_by_name = (ma_proc)_pa_context_get_source_info_by_name; + pContext->pulse.pa_operation_unref = (ma_proc)_pa_operation_unref; + pContext->pulse.pa_operation_get_state = (ma_proc)_pa_operation_get_state; + pContext->pulse.pa_channel_map_init_extend = (ma_proc)_pa_channel_map_init_extend; + pContext->pulse.pa_channel_map_valid = (ma_proc)_pa_channel_map_valid; + pContext->pulse.pa_channel_map_compatible = (ma_proc)_pa_channel_map_compatible; + pContext->pulse.pa_stream_new = (ma_proc)_pa_stream_new; + pContext->pulse.pa_stream_unref = (ma_proc)_pa_stream_unref; + pContext->pulse.pa_stream_connect_playback = (ma_proc)_pa_stream_connect_playback; + pContext->pulse.pa_stream_connect_record = (ma_proc)_pa_stream_connect_record; + pContext->pulse.pa_stream_disconnect = (ma_proc)_pa_stream_disconnect; + pContext->pulse.pa_stream_get_state = (ma_proc)_pa_stream_get_state; + pContext->pulse.pa_stream_get_sample_spec = (ma_proc)_pa_stream_get_sample_spec; + pContext->pulse.pa_stream_get_channel_map = (ma_proc)_pa_stream_get_channel_map; + pContext->pulse.pa_stream_get_buffer_attr = (ma_proc)_pa_stream_get_buffer_attr; + pContext->pulse.pa_stream_set_buffer_attr = (ma_proc)_pa_stream_set_buffer_attr; + pContext->pulse.pa_stream_get_device_name = (ma_proc)_pa_stream_get_device_name; + pContext->pulse.pa_stream_set_write_callback = (ma_proc)_pa_stream_set_write_callback; + pContext->pulse.pa_stream_set_read_callback = (ma_proc)_pa_stream_set_read_callback; + pContext->pulse.pa_stream_flush = (ma_proc)_pa_stream_flush; + pContext->pulse.pa_stream_drain = (ma_proc)_pa_stream_drain; + pContext->pulse.pa_stream_is_corked = (ma_proc)_pa_stream_is_corked; + pContext->pulse.pa_stream_cork = (ma_proc)_pa_stream_cork; + pContext->pulse.pa_stream_trigger = (ma_proc)_pa_stream_trigger; + pContext->pulse.pa_stream_begin_write = (ma_proc)_pa_stream_begin_write; + pContext->pulse.pa_stream_write = (ma_proc)_pa_stream_write; + pContext->pulse.pa_stream_peek = (ma_proc)_pa_stream_peek; + pContext->pulse.pa_stream_drop = (ma_proc)_pa_stream_drop; + pContext->pulse.pa_stream_writable_size = (ma_proc)_pa_stream_writable_size; + pContext->pulse.pa_stream_readable_size = (ma_proc)_pa_stream_readable_size; #endif - pContext->onUninit = mal_context_uninit__pulse; - pContext->onDeviceIDEqual = mal_context_is_device_id_equal__pulse; - pContext->onEnumDevices = mal_context_enumerate_devices__pulse; - pContext->onGetDeviceInfo = mal_context_get_device_info__pulse; - pContext->onDeviceInit = mal_device_init__pulse; - pContext->onDeviceUninit = mal_device_uninit__pulse; + pContext->onUninit = ma_context_uninit__pulse; + pContext->onDeviceIDEqual = ma_context_is_device_id_equal__pulse; + pContext->onEnumDevices = ma_context_enumerate_devices__pulse; + pContext->onGetDeviceInfo = ma_context_get_device_info__pulse; + pContext->onDeviceInit = ma_device_init__pulse; + pContext->onDeviceUninit = ma_device_uninit__pulse; pContext->onDeviceStart = NULL; - pContext->onDeviceStop = mal_device_stop__pulse; - pContext->onDeviceWrite = mal_device_write__pulse; - pContext->onDeviceRead = mal_device_read__pulse; + pContext->onDeviceStop = ma_device_stop__pulse; + pContext->onDeviceWrite = ma_device_write__pulse; + pContext->onDeviceRead = ma_device_read__pulse; // Although we have found the libpulse library, it doesn't necessarily mean PulseAudio is useable. We need to initialize // and connect a dummy PulseAudio context to test PulseAudio's usability. - mal_pa_mainloop* pMainLoop = ((mal_pa_mainloop_new_proc)pContext->pulse.pa_mainloop_new)(); + ma_pa_mainloop* pMainLoop = ((ma_pa_mainloop_new_proc)pContext->pulse.pa_mainloop_new)(); if (pMainLoop == NULL) { return MA_NO_BACKEND; } - mal_pa_mainloop_api* pAPI = ((mal_pa_mainloop_get_api_proc)pContext->pulse.pa_mainloop_get_api)(pMainLoop); + ma_pa_mainloop_api* pAPI = ((ma_pa_mainloop_get_api_proc)pContext->pulse.pa_mainloop_get_api)(pMainLoop); if (pAPI == NULL) { - ((mal_pa_mainloop_free_proc)pContext->pulse.pa_mainloop_free)(pMainLoop); + ((ma_pa_mainloop_free_proc)pContext->pulse.pa_mainloop_free)(pMainLoop); return MA_NO_BACKEND; } - mal_pa_context* pPulseContext = ((mal_pa_context_new_proc)pContext->pulse.pa_context_new)(pAPI, pContext->config.pulse.pApplicationName); + ma_pa_context* pPulseContext = ((ma_pa_context_new_proc)pContext->pulse.pa_context_new)(pAPI, pContext->config.pulse.pApplicationName); if (pPulseContext == NULL) { - ((mal_pa_mainloop_free_proc)pContext->pulse.pa_mainloop_free)(pMainLoop); + ((ma_pa_mainloop_free_proc)pContext->pulse.pa_mainloop_free)(pMainLoop); return MA_NO_BACKEND; } - int error = ((mal_pa_context_connect_proc)pContext->pulse.pa_context_connect)(pPulseContext, pContext->config.pulse.pServerName, 0, NULL); + int error = ((ma_pa_context_connect_proc)pContext->pulse.pa_context_connect)(pPulseContext, pContext->config.pulse.pServerName, 0, NULL); if (error != MA_PA_OK) { - ((mal_pa_context_unref_proc)pContext->pulse.pa_context_unref)(pPulseContext); - ((mal_pa_mainloop_free_proc)pContext->pulse.pa_mainloop_free)(pMainLoop); + ((ma_pa_context_unref_proc)pContext->pulse.pa_context_unref)(pPulseContext); + ((ma_pa_mainloop_free_proc)pContext->pulse.pa_mainloop_free)(pMainLoop); return MA_NO_BACKEND; } - ((mal_pa_context_disconnect_proc)pContext->pulse.pa_context_disconnect)(pPulseContext); - ((mal_pa_context_unref_proc)pContext->pulse.pa_context_unref)(pPulseContext); - ((mal_pa_mainloop_free_proc)pContext->pulse.pa_mainloop_free)(pMainLoop); + ((ma_pa_context_disconnect_proc)pContext->pulse.pa_context_disconnect)(pPulseContext); + ((ma_pa_context_unref_proc)pContext->pulse.pa_context_unref)(pPulseContext); + ((ma_pa_mainloop_free_proc)pContext->pulse.pa_mainloop_free)(pMainLoop); return MA_SUCCESS; } #endif @@ -15014,68 +15014,68 @@ mal_result mal_context_init__pulse(mal_context* pContext) #ifdef MA_NO_RUNTIME_LINKING #include -typedef jack_nframes_t mal_jack_nframes_t; -typedef jack_options_t mal_jack_options_t; -typedef jack_status_t mal_jack_status_t; -typedef jack_client_t mal_jack_client_t; -typedef jack_port_t mal_jack_port_t; -typedef JackProcessCallback mal_JackProcessCallback; -typedef JackBufferSizeCallback mal_JackBufferSizeCallback; -typedef JackShutdownCallback mal_JackShutdownCallback; +typedef jack_nframes_t ma_jack_nframes_t; +typedef jack_options_t ma_jack_options_t; +typedef jack_status_t ma_jack_status_t; +typedef jack_client_t ma_jack_client_t; +typedef jack_port_t ma_jack_port_t; +typedef JackProcessCallback ma_JackProcessCallback; +typedef JackBufferSizeCallback ma_JackBufferSizeCallback; +typedef JackShutdownCallback ma_JackShutdownCallback; #define MA_JACK_DEFAULT_AUDIO_TYPE JACK_DEFAULT_AUDIO_TYPE -#define mal_JackNoStartServer JackNoStartServer -#define mal_JackPortIsInput JackPortIsInput -#define mal_JackPortIsOutput JackPortIsOutput -#define mal_JackPortIsPhysical JackPortIsPhysical +#define ma_JackNoStartServer JackNoStartServer +#define ma_JackPortIsInput JackPortIsInput +#define ma_JackPortIsOutput JackPortIsOutput +#define ma_JackPortIsPhysical JackPortIsPhysical #else -typedef mal_uint32 mal_jack_nframes_t; -typedef int mal_jack_options_t; -typedef int mal_jack_status_t; -typedef struct mal_jack_client_t mal_jack_client_t; -typedef struct mal_jack_port_t mal_jack_port_t; -typedef int (* mal_JackProcessCallback) (mal_jack_nframes_t nframes, void* arg); -typedef int (* mal_JackBufferSizeCallback)(mal_jack_nframes_t nframes, void* arg); -typedef void (* mal_JackShutdownCallback) (void* arg); +typedef ma_uint32 ma_jack_nframes_t; +typedef int ma_jack_options_t; +typedef int ma_jack_status_t; +typedef struct ma_jack_client_t ma_jack_client_t; +typedef struct ma_jack_port_t ma_jack_port_t; +typedef int (* ma_JackProcessCallback) (ma_jack_nframes_t nframes, void* arg); +typedef int (* ma_JackBufferSizeCallback)(ma_jack_nframes_t nframes, void* arg); +typedef void (* ma_JackShutdownCallback) (void* arg); #define MA_JACK_DEFAULT_AUDIO_TYPE "32 bit float mono audio" -#define mal_JackNoStartServer 1 -#define mal_JackPortIsInput 1 -#define mal_JackPortIsOutput 2 -#define mal_JackPortIsPhysical 4 +#define ma_JackNoStartServer 1 +#define ma_JackPortIsInput 1 +#define ma_JackPortIsOutput 2 +#define ma_JackPortIsPhysical 4 #endif -typedef mal_jack_client_t* (* mal_jack_client_open_proc) (const char* client_name, mal_jack_options_t options, mal_jack_status_t* status, ...); -typedef int (* mal_jack_client_close_proc) (mal_jack_client_t* client); -typedef int (* mal_jack_client_name_size_proc) (); -typedef int (* mal_jack_set_process_callback_proc) (mal_jack_client_t* client, mal_JackProcessCallback process_callback, void* arg); -typedef int (* mal_jack_set_buffer_size_callback_proc)(mal_jack_client_t* client, mal_JackBufferSizeCallback bufsize_callback, void* arg); -typedef void (* mal_jack_on_shutdown_proc) (mal_jack_client_t* client, mal_JackShutdownCallback function, void* arg); -typedef mal_jack_nframes_t (* mal_jack_get_sample_rate_proc) (mal_jack_client_t* client); -typedef mal_jack_nframes_t (* mal_jack_get_buffer_size_proc) (mal_jack_client_t* client); -typedef const char** (* mal_jack_get_ports_proc) (mal_jack_client_t* client, const char* port_name_pattern, const char* type_name_pattern, unsigned long flags); -typedef int (* mal_jack_activate_proc) (mal_jack_client_t* client); -typedef int (* mal_jack_deactivate_proc) (mal_jack_client_t* client); -typedef int (* mal_jack_connect_proc) (mal_jack_client_t* client, const char* source_port, const char* destination_port); -typedef mal_jack_port_t* (* mal_jack_port_register_proc) (mal_jack_client_t* client, const char* port_name, const char* port_type, unsigned long flags, unsigned long buffer_size); -typedef const char* (* mal_jack_port_name_proc) (const mal_jack_port_t* port); -typedef void* (* mal_jack_port_get_buffer_proc) (mal_jack_port_t* port, mal_jack_nframes_t nframes); -typedef void (* mal_jack_free_proc) (void* ptr); +typedef ma_jack_client_t* (* ma_jack_client_open_proc) (const char* client_name, ma_jack_options_t options, ma_jack_status_t* status, ...); +typedef int (* ma_jack_client_close_proc) (ma_jack_client_t* client); +typedef int (* ma_jack_client_name_size_proc) (); +typedef int (* ma_jack_set_process_callback_proc) (ma_jack_client_t* client, ma_JackProcessCallback process_callback, void* arg); +typedef int (* ma_jack_set_buffer_size_callback_proc)(ma_jack_client_t* client, ma_JackBufferSizeCallback bufsize_callback, void* arg); +typedef void (* ma_jack_on_shutdown_proc) (ma_jack_client_t* client, ma_JackShutdownCallback function, void* arg); +typedef ma_jack_nframes_t (* ma_jack_get_sample_rate_proc) (ma_jack_client_t* client); +typedef ma_jack_nframes_t (* ma_jack_get_buffer_size_proc) (ma_jack_client_t* client); +typedef const char** (* ma_jack_get_ports_proc) (ma_jack_client_t* client, const char* port_name_pattern, const char* type_name_pattern, unsigned long flags); +typedef int (* ma_jack_activate_proc) (ma_jack_client_t* client); +typedef int (* ma_jack_deactivate_proc) (ma_jack_client_t* client); +typedef int (* ma_jack_connect_proc) (ma_jack_client_t* client, const char* source_port, const char* destination_port); +typedef ma_jack_port_t* (* ma_jack_port_register_proc) (ma_jack_client_t* client, const char* port_name, const char* port_type, unsigned long flags, unsigned long buffer_size); +typedef const char* (* ma_jack_port_name_proc) (const ma_jack_port_t* port); +typedef void* (* ma_jack_port_get_buffer_proc) (ma_jack_port_t* port, ma_jack_nframes_t nframes); +typedef void (* ma_jack_free_proc) (void* ptr); -mal_result mal_context_open_client__jack(mal_context* pContext, mal_jack_client_t** ppClient) +ma_result ma_context_open_client__jack(ma_context* pContext, ma_jack_client_t** ppClient) { - mal_assert(pContext != NULL); - mal_assert(ppClient != NULL); + ma_assert(pContext != NULL); + ma_assert(ppClient != NULL); if (ppClient) { *ppClient = NULL; } - size_t maxClientNameSize = ((mal_jack_client_name_size_proc)pContext->jack.jack_client_name_size)(); // Includes null terminator. + size_t maxClientNameSize = ((ma_jack_client_name_size_proc)pContext->jack.jack_client_name_size)(); // Includes null terminator. char clientName[256]; - mal_strncpy_s(clientName, mal_min(sizeof(clientName), maxClientNameSize), (pContext->config.jack.pClientName != NULL) ? pContext->config.jack.pClientName : "miniaudio", (size_t)-1); + ma_strncpy_s(clientName, ma_min(sizeof(clientName), maxClientNameSize), (pContext->config.jack.pClientName != NULL) ? pContext->config.jack.pClientName : "miniaudio", (size_t)-1); - mal_jack_status_t status; - mal_jack_client_t* pClient = ((mal_jack_client_open_proc)pContext->jack.jack_client_open)(clientName, (pContext->config.jack.tryStartServer) ? 0 : mal_JackNoStartServer, &status, NULL); + ma_jack_status_t status; + ma_jack_client_t* pClient = ((ma_jack_client_open_proc)pContext->jack.jack_client_open)(clientName, (pContext->config.jack.tryStartServer) ? 0 : ma_JackNoStartServer, &status, NULL); if (pClient == NULL) { return MA_FAILED_TO_OPEN_BACKEND_DEVICE; } @@ -15087,50 +15087,50 @@ mal_result mal_context_open_client__jack(mal_context* pContext, mal_jack_client_ return MA_SUCCESS; } -mal_bool32 mal_context_is_device_id_equal__jack(mal_context* pContext, const mal_device_id* pID0, const mal_device_id* pID1) +ma_bool32 ma_context_is_device_id_equal__jack(ma_context* pContext, const ma_device_id* pID0, const ma_device_id* pID1) { - mal_assert(pContext != NULL); - mal_assert(pID0 != NULL); - mal_assert(pID1 != NULL); + ma_assert(pContext != NULL); + ma_assert(pID0 != NULL); + ma_assert(pID1 != NULL); (void)pContext; return pID0->jack == pID1->jack; } -mal_result mal_context_enumerate_devices__jack(mal_context* pContext, mal_enum_devices_callback_proc callback, void* pUserData) +ma_result ma_context_enumerate_devices__jack(ma_context* pContext, ma_enum_devices_callback_proc callback, void* pUserData) { - mal_assert(pContext != NULL); - mal_assert(callback != NULL); + ma_assert(pContext != NULL); + ma_assert(callback != NULL); - mal_bool32 cbResult = MA_TRUE; + ma_bool32 cbResult = MA_TRUE; // Playback. if (cbResult) { - mal_device_info deviceInfo; - mal_zero_object(&deviceInfo); - mal_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), MA_DEFAULT_PLAYBACK_DEVICE_NAME, (size_t)-1); - cbResult = callback(pContext, mal_device_type_playback, &deviceInfo, pUserData); + ma_device_info deviceInfo; + ma_zero_object(&deviceInfo); + ma_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), MA_DEFAULT_PLAYBACK_DEVICE_NAME, (size_t)-1); + cbResult = callback(pContext, ma_device_type_playback, &deviceInfo, pUserData); } // Capture. if (cbResult) { - mal_device_info deviceInfo; - mal_zero_object(&deviceInfo); - mal_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), MA_DEFAULT_CAPTURE_DEVICE_NAME, (size_t)-1); - cbResult = callback(pContext, mal_device_type_capture, &deviceInfo, pUserData); + ma_device_info deviceInfo; + ma_zero_object(&deviceInfo); + ma_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), MA_DEFAULT_CAPTURE_DEVICE_NAME, (size_t)-1); + cbResult = callback(pContext, ma_device_type_capture, &deviceInfo, pUserData); } return MA_SUCCESS; } -mal_result mal_context_get_device_info__jack(mal_context* pContext, mal_device_type deviceType, const mal_device_id* pDeviceID, mal_share_mode shareMode, mal_device_info* pDeviceInfo) +ma_result ma_context_get_device_info__jack(ma_context* pContext, ma_device_type deviceType, const ma_device_id* pDeviceID, ma_share_mode shareMode, ma_device_info* pDeviceInfo) { - mal_assert(pContext != NULL); + ma_assert(pContext != NULL); (void)pContext; /* No exclusive mode with the JACK backend. */ - if (shareMode == mal_share_mode_exclusive) { + if (shareMode == ma_share_mode_exclusive) { return MA_SHARE_MODE_NOT_SUPPORTED; } @@ -15139,33 +15139,33 @@ mal_result mal_context_get_device_info__jack(mal_context* pContext, mal_device_t } // Name / Description - if (deviceType == mal_device_type_playback) { - mal_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), MA_DEFAULT_PLAYBACK_DEVICE_NAME, (size_t)-1); + if (deviceType == ma_device_type_playback) { + ma_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), MA_DEFAULT_PLAYBACK_DEVICE_NAME, (size_t)-1); } else { - mal_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), MA_DEFAULT_CAPTURE_DEVICE_NAME, (size_t)-1); + ma_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), MA_DEFAULT_CAPTURE_DEVICE_NAME, (size_t)-1); } // Jack only supports f32 and has a specific channel count and sample rate. pDeviceInfo->formatCount = 1; - pDeviceInfo->formats[0] = mal_format_f32; + pDeviceInfo->formats[0] = ma_format_f32; // The channel count and sample rate can only be determined by opening the device. - mal_jack_client_t* pClient; - mal_result result = mal_context_open_client__jack(pContext, &pClient); + ma_jack_client_t* pClient; + ma_result result = ma_context_open_client__jack(pContext, &pClient); if (result != MA_SUCCESS) { - return mal_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[JACK] Failed to open client.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + return ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[JACK] Failed to open client.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } - pDeviceInfo->minSampleRate = ((mal_jack_get_sample_rate_proc)pContext->jack.jack_get_sample_rate)((mal_jack_client_t*)pClient); + pDeviceInfo->minSampleRate = ((ma_jack_get_sample_rate_proc)pContext->jack.jack_get_sample_rate)((ma_jack_client_t*)pClient); pDeviceInfo->maxSampleRate = pDeviceInfo->minSampleRate; pDeviceInfo->minChannels = 0; pDeviceInfo->maxChannels = 0; - const char** ppPorts = ((mal_jack_get_ports_proc)pContext->jack.jack_get_ports)((mal_jack_client_t*)pClient, NULL, NULL, mal_JackPortIsPhysical | ((deviceType == mal_device_type_playback) ? mal_JackPortIsInput : mal_JackPortIsOutput)); + const char** ppPorts = ((ma_jack_get_ports_proc)pContext->jack.jack_get_ports)((ma_jack_client_t*)pClient, NULL, NULL, ma_JackPortIsPhysical | ((deviceType == ma_device_type_playback) ? ma_JackPortIsInput : ma_JackPortIsOutput)); if (ppPorts == NULL) { - ((mal_jack_client_close_proc)pContext->jack.jack_client_close)((mal_jack_client_t*)pClient); - return mal_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[JACK] Failed to query physical ports.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + ((ma_jack_client_close_proc)pContext->jack.jack_client_close)((ma_jack_client_t*)pClient); + return ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[JACK] Failed to query physical ports.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } while (ppPorts[pDeviceInfo->minChannels] != NULL) { @@ -15173,53 +15173,53 @@ mal_result mal_context_get_device_info__jack(mal_context* pContext, mal_device_t pDeviceInfo->maxChannels += 1; } - ((mal_jack_free_proc)pContext->jack.jack_free)((void*)ppPorts); - ((mal_jack_client_close_proc)pContext->jack.jack_client_close)((mal_jack_client_t*)pClient); + ((ma_jack_free_proc)pContext->jack.jack_free)((void*)ppPorts); + ((ma_jack_client_close_proc)pContext->jack.jack_client_close)((ma_jack_client_t*)pClient); return MA_SUCCESS; } -void mal_device_uninit__jack(mal_device* pDevice) +void ma_device_uninit__jack(ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); - mal_context* pContext = pDevice->pContext; - mal_assert(pContext != NULL); + ma_context* pContext = pDevice->pContext; + ma_assert(pContext != NULL); if (pDevice->jack.pClient != NULL) { - ((mal_jack_client_close_proc)pContext->jack.jack_client_close)((mal_jack_client_t*)pDevice->jack.pClient); + ((ma_jack_client_close_proc)pContext->jack.jack_client_close)((ma_jack_client_t*)pDevice->jack.pClient); } - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { - mal_free(pDevice->jack.pIntermediaryBufferCapture); + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { + ma_free(pDevice->jack.pIntermediaryBufferCapture); } - if (pDevice->type == mal_device_type_playback || pDevice->type == mal_device_type_duplex) { - mal_free(pDevice->jack.pIntermediaryBufferPlayback); + if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) { + ma_free(pDevice->jack.pIntermediaryBufferPlayback); } - if (pDevice->type == mal_device_type_duplex) { - mal_pcm_rb_uninit(&pDevice->jack.duplexRB); + if (pDevice->type == ma_device_type_duplex) { + ma_pcm_rb_uninit(&pDevice->jack.duplexRB); } } -void mal_device__jack_shutdown_callback(void* pUserData) +void ma_device__jack_shutdown_callback(void* pUserData) { // JACK died. Stop the device. - mal_device* pDevice = (mal_device*)pUserData; - mal_assert(pDevice != NULL); + ma_device* pDevice = (ma_device*)pUserData; + ma_assert(pDevice != NULL); - mal_device_stop(pDevice); + ma_device_stop(pDevice); } -int mal_device__jack_buffer_size_callback(mal_jack_nframes_t frameCount, void* pUserData) +int ma_device__jack_buffer_size_callback(ma_jack_nframes_t frameCount, void* pUserData) { - mal_device* pDevice = (mal_device*)pUserData; - mal_assert(pDevice != NULL); + ma_device* pDevice = (ma_device*)pUserData; + ma_assert(pDevice != NULL); - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { - float* pNewBuffer = (float*)mal_realloc(pDevice->jack.pIntermediaryBufferCapture, frameCount * (pDevice->capture.internalChannels * mal_get_bytes_per_sample(pDevice->capture.internalFormat))); + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { + float* pNewBuffer = (float*)ma_realloc(pDevice->jack.pIntermediaryBufferCapture, frameCount * (pDevice->capture.internalChannels * ma_get_bytes_per_sample(pDevice->capture.internalFormat))); if (pNewBuffer == NULL) { return MA_OUT_OF_MEMORY; } @@ -15228,8 +15228,8 @@ int mal_device__jack_buffer_size_callback(mal_jack_nframes_t frameCount, void* p pDevice->playback.internalBufferSizeInFrames = frameCount * pDevice->capture.internalPeriods; } - if (pDevice->type == mal_device_type_playback || pDevice->type == mal_device_type_duplex) { - float* pNewBuffer = (float*)mal_realloc(pDevice->jack.pIntermediaryBufferPlayback, frameCount * (pDevice->playback.internalChannels * mal_get_bytes_per_sample(pDevice->playback.internalFormat))); + if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) { + float* pNewBuffer = (float*)ma_realloc(pDevice->jack.pIntermediaryBufferPlayback, frameCount * (pDevice->playback.internalChannels * ma_get_bytes_per_sample(pDevice->playback.internalFormat))); if (pNewBuffer == NULL) { return MA_OUT_OF_MEMORY; } @@ -15241,21 +15241,21 @@ int mal_device__jack_buffer_size_callback(mal_jack_nframes_t frameCount, void* p return 0; } -int mal_device__jack_process_callback(mal_jack_nframes_t frameCount, void* pUserData) +int ma_device__jack_process_callback(ma_jack_nframes_t frameCount, void* pUserData) { - mal_device* pDevice = (mal_device*)pUserData; - mal_assert(pDevice != NULL); + ma_device* pDevice = (ma_device*)pUserData; + ma_assert(pDevice != NULL); - mal_context* pContext = pDevice->pContext; - mal_assert(pContext != NULL); + ma_context* pContext = pDevice->pContext; + ma_assert(pContext != NULL); - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { // Channels need to be interleaved. - for (mal_uint32 iChannel = 0; iChannel < pDevice->capture.internalChannels; ++iChannel) { - const float* pSrc = (const float*)((mal_jack_port_get_buffer_proc)pContext->jack.jack_port_get_buffer)((mal_jack_port_t*)pDevice->jack.pPortsCapture[iChannel], frameCount); + for (ma_uint32 iChannel = 0; iChannel < pDevice->capture.internalChannels; ++iChannel) { + const float* pSrc = (const float*)((ma_jack_port_get_buffer_proc)pContext->jack.jack_port_get_buffer)((ma_jack_port_t*)pDevice->jack.pPortsCapture[iChannel], frameCount); if (pSrc != NULL) { float* pDst = pDevice->jack.pIntermediaryBufferCapture + iChannel; - for (mal_jack_nframes_t iFrame = 0; iFrame < frameCount; ++iFrame) { + for (ma_jack_nframes_t iFrame = 0; iFrame < frameCount; ++iFrame) { *pDst = *pSrc; pDst += pDevice->capture.internalChannels; @@ -15264,26 +15264,26 @@ int mal_device__jack_process_callback(mal_jack_nframes_t frameCount, void* pUser } } - if (pDevice->type == mal_device_type_duplex) { - mal_device__handle_duplex_callback_capture(pDevice, frameCount, pDevice->jack.pIntermediaryBufferCapture, &pDevice->jack.duplexRB); + if (pDevice->type == ma_device_type_duplex) { + ma_device__handle_duplex_callback_capture(pDevice, frameCount, pDevice->jack.pIntermediaryBufferCapture, &pDevice->jack.duplexRB); } else { - mal_device__send_frames_to_client(pDevice, frameCount, pDevice->jack.pIntermediaryBufferCapture); + ma_device__send_frames_to_client(pDevice, frameCount, pDevice->jack.pIntermediaryBufferCapture); } } - if (pDevice->type == mal_device_type_playback || pDevice->type == mal_device_type_duplex) { - if (pDevice->type == mal_device_type_duplex) { - mal_device__handle_duplex_callback_playback(pDevice, frameCount, pDevice->jack.pIntermediaryBufferPlayback, &pDevice->jack.duplexRB); + if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) { + if (pDevice->type == ma_device_type_duplex) { + ma_device__handle_duplex_callback_playback(pDevice, frameCount, pDevice->jack.pIntermediaryBufferPlayback, &pDevice->jack.duplexRB); } else { - mal_device__read_frames_from_client(pDevice, frameCount, pDevice->jack.pIntermediaryBufferPlayback); + ma_device__read_frames_from_client(pDevice, frameCount, pDevice->jack.pIntermediaryBufferPlayback); } // Channels need to be deinterleaved. - for (mal_uint32 iChannel = 0; iChannel < pDevice->playback.internalChannels; ++iChannel) { - float* pDst = (float*)((mal_jack_port_get_buffer_proc)pContext->jack.jack_port_get_buffer)((mal_jack_port_t*)pDevice->jack.pPortsPlayback[iChannel], frameCount); + for (ma_uint32 iChannel = 0; iChannel < pDevice->playback.internalChannels; ++iChannel) { + float* pDst = (float*)((ma_jack_port_get_buffer_proc)pContext->jack.jack_port_get_buffer)((ma_jack_port_t*)pDevice->jack.pPortsPlayback[iChannel], frameCount); if (pDst != NULL) { const float* pSrc = pDevice->jack.pIntermediaryBufferPlayback + iChannel; - for (mal_jack_nframes_t iFrame = 0; iFrame < frameCount; ++iFrame) { + for (ma_jack_nframes_t iFrame = 0; iFrame < frameCount; ++iFrame) { *pDst = *pSrc; pDst += 1; @@ -15296,133 +15296,133 @@ int mal_device__jack_process_callback(mal_jack_nframes_t frameCount, void* pUser return 0; } -mal_result mal_device_init__jack(mal_context* pContext, const mal_device_config* pConfig, mal_device* pDevice) +ma_result ma_device_init__jack(ma_context* pContext, const ma_device_config* pConfig, ma_device* pDevice) { - mal_assert(pContext != NULL); - mal_assert(pConfig != NULL); - mal_assert(pDevice != NULL); + ma_assert(pContext != NULL); + ma_assert(pConfig != NULL); + ma_assert(pDevice != NULL); (void)pContext; /* Only supporting default devices with JACK. */ - if (((pConfig->deviceType == mal_device_type_playback || pConfig->deviceType == mal_device_type_duplex) && pConfig->playback.pDeviceID != NULL && pConfig->playback.pDeviceID->jack != 0) || - ((pConfig->deviceType == mal_device_type_capture || pConfig->deviceType == mal_device_type_duplex) && pConfig->capture.pDeviceID != NULL && pConfig->capture.pDeviceID->jack != 0)) { + if (((pConfig->deviceType == ma_device_type_playback || pConfig->deviceType == ma_device_type_duplex) && pConfig->playback.pDeviceID != NULL && pConfig->playback.pDeviceID->jack != 0) || + ((pConfig->deviceType == ma_device_type_capture || pConfig->deviceType == ma_device_type_duplex) && pConfig->capture.pDeviceID != NULL && pConfig->capture.pDeviceID->jack != 0)) { return MA_NO_DEVICE; } /* No exclusive mode with the JACK backend. */ - if (((pConfig->deviceType == mal_device_type_playback || pConfig->deviceType == mal_device_type_duplex) && pConfig->playback.shareMode == mal_share_mode_exclusive) || - ((pConfig->deviceType == mal_device_type_capture || pConfig->deviceType == mal_device_type_duplex) && pConfig->capture.shareMode == mal_share_mode_exclusive)) { + if (((pConfig->deviceType == ma_device_type_playback || pConfig->deviceType == ma_device_type_duplex) && pConfig->playback.shareMode == ma_share_mode_exclusive) || + ((pConfig->deviceType == ma_device_type_capture || pConfig->deviceType == ma_device_type_duplex) && pConfig->capture.shareMode == ma_share_mode_exclusive)) { return MA_SHARE_MODE_NOT_SUPPORTED; } /* Open the client. */ - mal_result result = mal_context_open_client__jack(pContext, (mal_jack_client_t**)&pDevice->jack.pClient); + ma_result result = ma_context_open_client__jack(pContext, (ma_jack_client_t**)&pDevice->jack.pClient); if (result != MA_SUCCESS) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[JACK] Failed to open client.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[JACK] Failed to open client.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } /* Callbacks. */ - if (((mal_jack_set_process_callback_proc)pContext->jack.jack_set_process_callback)((mal_jack_client_t*)pDevice->jack.pClient, mal_device__jack_process_callback, pDevice) != 0) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[JACK] Failed to set process callback.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + if (((ma_jack_set_process_callback_proc)pContext->jack.jack_set_process_callback)((ma_jack_client_t*)pDevice->jack.pClient, ma_device__jack_process_callback, pDevice) != 0) { + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[JACK] Failed to set process callback.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } - if (((mal_jack_set_buffer_size_callback_proc)pContext->jack.jack_set_buffer_size_callback)((mal_jack_client_t*)pDevice->jack.pClient, mal_device__jack_buffer_size_callback, pDevice) != 0) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[JACK] Failed to set buffer size callback.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + if (((ma_jack_set_buffer_size_callback_proc)pContext->jack.jack_set_buffer_size_callback)((ma_jack_client_t*)pDevice->jack.pClient, ma_device__jack_buffer_size_callback, pDevice) != 0) { + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[JACK] Failed to set buffer size callback.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } - ((mal_jack_on_shutdown_proc)pContext->jack.jack_on_shutdown)((mal_jack_client_t*)pDevice->jack.pClient, mal_device__jack_shutdown_callback, pDevice); + ((ma_jack_on_shutdown_proc)pContext->jack.jack_on_shutdown)((ma_jack_client_t*)pDevice->jack.pClient, ma_device__jack_shutdown_callback, pDevice); /* The buffer size in frames can change. */ - mal_uint32 periods = 2; - mal_uint32 bufferSizeInFrames = ((mal_jack_get_buffer_size_proc)pContext->jack.jack_get_buffer_size)((mal_jack_client_t*)pDevice->jack.pClient) * periods; + ma_uint32 periods = 2; + ma_uint32 bufferSizeInFrames = ((ma_jack_get_buffer_size_proc)pContext->jack.jack_get_buffer_size)((ma_jack_client_t*)pDevice->jack.pClient) * periods; - if (pConfig->deviceType == mal_device_type_capture || pConfig->deviceType == mal_device_type_duplex) { + if (pConfig->deviceType == ma_device_type_capture || pConfig->deviceType == ma_device_type_duplex) { const char** ppPorts; - pDevice->capture.internalFormat = mal_format_f32; + pDevice->capture.internalFormat = ma_format_f32; pDevice->capture.internalChannels = 0; - pDevice->capture.internalSampleRate = ((mal_jack_get_sample_rate_proc)pContext->jack.jack_get_sample_rate)((mal_jack_client_t*)pDevice->jack.pClient); - mal_get_standard_channel_map(mal_standard_channel_map_alsa, pDevice->capture.internalChannels, pDevice->capture.internalChannelMap); + pDevice->capture.internalSampleRate = ((ma_jack_get_sample_rate_proc)pContext->jack.jack_get_sample_rate)((ma_jack_client_t*)pDevice->jack.pClient); + ma_get_standard_channel_map(ma_standard_channel_map_alsa, pDevice->capture.internalChannels, pDevice->capture.internalChannelMap); - ppPorts = ((mal_jack_get_ports_proc)pContext->jack.jack_get_ports)((mal_jack_client_t*)pDevice->jack.pClient, NULL, NULL, mal_JackPortIsPhysical | mal_JackPortIsOutput); + ppPorts = ((ma_jack_get_ports_proc)pContext->jack.jack_get_ports)((ma_jack_client_t*)pDevice->jack.pClient, NULL, NULL, ma_JackPortIsPhysical | ma_JackPortIsOutput); if (ppPorts == NULL) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[JACK] Failed to query physical ports.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[JACK] Failed to query physical ports.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } while (ppPorts[pDevice->capture.internalChannels] != NULL) { char name[64]; - mal_strcpy_s(name, sizeof(name), "capture"); - mal_itoa_s((int)pDevice->capture.internalChannels, name+7, sizeof(name)-7, 10); // 7 = length of "capture" + ma_strcpy_s(name, sizeof(name), "capture"); + ma_itoa_s((int)pDevice->capture.internalChannels, name+7, sizeof(name)-7, 10); // 7 = length of "capture" - pDevice->jack.pPortsCapture[pDevice->capture.internalChannels] = ((mal_jack_port_register_proc)pContext->jack.jack_port_register)((mal_jack_client_t*)pDevice->jack.pClient, name, MA_JACK_DEFAULT_AUDIO_TYPE, mal_JackPortIsInput, 0); + pDevice->jack.pPortsCapture[pDevice->capture.internalChannels] = ((ma_jack_port_register_proc)pContext->jack.jack_port_register)((ma_jack_client_t*)pDevice->jack.pClient, name, MA_JACK_DEFAULT_AUDIO_TYPE, ma_JackPortIsInput, 0); if (pDevice->jack.pPortsCapture[pDevice->capture.internalChannels] == NULL) { - ((mal_jack_free_proc)pContext->jack.jack_free)((void*)ppPorts); - mal_device_uninit__jack(pDevice); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[JACK] Failed to register ports.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + ((ma_jack_free_proc)pContext->jack.jack_free)((void*)ppPorts); + ma_device_uninit__jack(pDevice); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[JACK] Failed to register ports.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } pDevice->capture.internalChannels += 1; } - ((mal_jack_free_proc)pContext->jack.jack_free)((void*)ppPorts); + ((ma_jack_free_proc)pContext->jack.jack_free)((void*)ppPorts); pDevice->capture.internalBufferSizeInFrames = bufferSizeInFrames; pDevice->capture.internalPeriods = periods; - pDevice->jack.pIntermediaryBufferCapture = (float*)mal_malloc((pDevice->capture.internalBufferSizeInFrames/pDevice->capture.internalPeriods) * (pDevice->capture.internalChannels * mal_get_bytes_per_sample(pDevice->capture.internalFormat))); + pDevice->jack.pIntermediaryBufferCapture = (float*)ma_malloc((pDevice->capture.internalBufferSizeInFrames/pDevice->capture.internalPeriods) * (pDevice->capture.internalChannels * ma_get_bytes_per_sample(pDevice->capture.internalFormat))); if (pDevice->jack.pIntermediaryBufferCapture == NULL) { - mal_device_uninit__jack(pDevice); + ma_device_uninit__jack(pDevice); return MA_OUT_OF_MEMORY; } } - if (pConfig->deviceType == mal_device_type_playback || pConfig->deviceType == mal_device_type_duplex) { + if (pConfig->deviceType == ma_device_type_playback || pConfig->deviceType == ma_device_type_duplex) { const char** ppPorts; - pDevice->playback.internalFormat = mal_format_f32; + pDevice->playback.internalFormat = ma_format_f32; pDevice->playback.internalChannels = 0; - pDevice->playback.internalSampleRate = ((mal_jack_get_sample_rate_proc)pContext->jack.jack_get_sample_rate)((mal_jack_client_t*)pDevice->jack.pClient); - mal_get_standard_channel_map(mal_standard_channel_map_alsa, pDevice->playback.internalChannels, pDevice->playback.internalChannelMap); + pDevice->playback.internalSampleRate = ((ma_jack_get_sample_rate_proc)pContext->jack.jack_get_sample_rate)((ma_jack_client_t*)pDevice->jack.pClient); + ma_get_standard_channel_map(ma_standard_channel_map_alsa, pDevice->playback.internalChannels, pDevice->playback.internalChannelMap); - ppPorts = ((mal_jack_get_ports_proc)pContext->jack.jack_get_ports)((mal_jack_client_t*)pDevice->jack.pClient, NULL, NULL, mal_JackPortIsPhysical | mal_JackPortIsInput); + ppPorts = ((ma_jack_get_ports_proc)pContext->jack.jack_get_ports)((ma_jack_client_t*)pDevice->jack.pClient, NULL, NULL, ma_JackPortIsPhysical | ma_JackPortIsInput); if (ppPorts == NULL) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[JACK] Failed to query physical ports.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[JACK] Failed to query physical ports.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } while (ppPorts[pDevice->playback.internalChannels] != NULL) { char name[64]; - mal_strcpy_s(name, sizeof(name), "playback"); - mal_itoa_s((int)pDevice->playback.internalChannels, name+8, sizeof(name)-8, 10); // 8 = length of "playback" + ma_strcpy_s(name, sizeof(name), "playback"); + ma_itoa_s((int)pDevice->playback.internalChannels, name+8, sizeof(name)-8, 10); // 8 = length of "playback" - pDevice->jack.pPortsPlayback[pDevice->playback.internalChannels] = ((mal_jack_port_register_proc)pContext->jack.jack_port_register)((mal_jack_client_t*)pDevice->jack.pClient, name, MA_JACK_DEFAULT_AUDIO_TYPE, mal_JackPortIsOutput, 0); + pDevice->jack.pPortsPlayback[pDevice->playback.internalChannels] = ((ma_jack_port_register_proc)pContext->jack.jack_port_register)((ma_jack_client_t*)pDevice->jack.pClient, name, MA_JACK_DEFAULT_AUDIO_TYPE, ma_JackPortIsOutput, 0); if (pDevice->jack.pPortsPlayback[pDevice->playback.internalChannels] == NULL) { - ((mal_jack_free_proc)pContext->jack.jack_free)((void*)ppPorts); - mal_device_uninit__jack(pDevice); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[JACK] Failed to register ports.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + ((ma_jack_free_proc)pContext->jack.jack_free)((void*)ppPorts); + ma_device_uninit__jack(pDevice); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[JACK] Failed to register ports.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } pDevice->playback.internalChannels += 1; } - ((mal_jack_free_proc)pContext->jack.jack_free)((void*)ppPorts); + ((ma_jack_free_proc)pContext->jack.jack_free)((void*)ppPorts); pDevice->playback.internalBufferSizeInFrames = bufferSizeInFrames; pDevice->playback.internalPeriods = periods; - pDevice->jack.pIntermediaryBufferPlayback = (float*)mal_malloc((pDevice->playback.internalBufferSizeInFrames/pDevice->playback.internalPeriods) * (pDevice->playback.internalChannels * mal_get_bytes_per_sample(pDevice->playback.internalFormat))); + pDevice->jack.pIntermediaryBufferPlayback = (float*)ma_malloc((pDevice->playback.internalBufferSizeInFrames/pDevice->playback.internalPeriods) * (pDevice->playback.internalChannels * ma_get_bytes_per_sample(pDevice->playback.internalFormat))); if (pDevice->jack.pIntermediaryBufferPlayback == NULL) { - mal_device_uninit__jack(pDevice); + ma_device_uninit__jack(pDevice); return MA_OUT_OF_MEMORY; } } - if (pDevice->type == mal_device_type_duplex) { - mal_uint32 rbSizeInFrames = (mal_uint32)mal_calculate_frame_count_after_src(pDevice->sampleRate, pDevice->capture.internalSampleRate, pDevice->capture.internalBufferSizeInFrames); - result = mal_pcm_rb_init(pDevice->capture.format, pDevice->capture.channels, rbSizeInFrames, NULL, &pDevice->jack.duplexRB); + if (pDevice->type == ma_device_type_duplex) { + ma_uint32 rbSizeInFrames = (ma_uint32)ma_calculate_frame_count_after_src(pDevice->sampleRate, pDevice->capture.internalSampleRate, pDevice->capture.internalBufferSizeInFrames); + result = ma_pcm_rb_init(pDevice->capture.format, pDevice->capture.channels, rbSizeInFrames, NULL, &pDevice->jack.duplexRB); if (result != MA_SUCCESS) { - mal_device_uninit__jack(pDevice); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[JACK] Failed to initialize ring buffer.", result); + ma_device_uninit__jack(pDevice); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[JACK] Failed to initialize ring buffer.", result); } } @@ -15430,77 +15430,77 @@ mal_result mal_device_init__jack(mal_context* pContext, const mal_device_config* } -mal_result mal_device_start__jack(mal_device* pDevice) +ma_result ma_device_start__jack(ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); - mal_context* pContext = pDevice->pContext; - mal_assert(pContext != NULL); + ma_context* pContext = pDevice->pContext; + ma_assert(pContext != NULL); - int resultJACK = ((mal_jack_activate_proc)pContext->jack.jack_activate)((mal_jack_client_t*)pDevice->jack.pClient); + int resultJACK = ((ma_jack_activate_proc)pContext->jack.jack_activate)((ma_jack_client_t*)pDevice->jack.pClient); if (resultJACK != 0) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[JACK] Failed to activate the JACK client.", MA_FAILED_TO_START_BACKEND_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[JACK] Failed to activate the JACK client.", MA_FAILED_TO_START_BACKEND_DEVICE); } - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { - const char** ppServerPorts = ((mal_jack_get_ports_proc)pContext->jack.jack_get_ports)((mal_jack_client_t*)pDevice->jack.pClient, NULL, NULL, mal_JackPortIsPhysical | mal_JackPortIsOutput); + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { + const char** ppServerPorts = ((ma_jack_get_ports_proc)pContext->jack.jack_get_ports)((ma_jack_client_t*)pDevice->jack.pClient, NULL, NULL, ma_JackPortIsPhysical | ma_JackPortIsOutput); if (ppServerPorts == NULL) { - ((mal_jack_deactivate_proc)pContext->jack.jack_deactivate)((mal_jack_client_t*)pDevice->jack.pClient); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[JACK] Failed to retrieve physical ports.", MA_ERROR); + ((ma_jack_deactivate_proc)pContext->jack.jack_deactivate)((ma_jack_client_t*)pDevice->jack.pClient); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[JACK] Failed to retrieve physical ports.", MA_ERROR); } for (size_t i = 0; ppServerPorts[i] != NULL; ++i) { const char* pServerPort = ppServerPorts[i]; - const char* pClientPort = ((mal_jack_port_name_proc)pContext->jack.jack_port_name)((mal_jack_port_t*)pDevice->jack.pPortsCapture[i]); + const char* pClientPort = ((ma_jack_port_name_proc)pContext->jack.jack_port_name)((ma_jack_port_t*)pDevice->jack.pPortsCapture[i]); - resultJACK = ((mal_jack_connect_proc)pContext->jack.jack_connect)((mal_jack_client_t*)pDevice->jack.pClient, pServerPort, pClientPort); + resultJACK = ((ma_jack_connect_proc)pContext->jack.jack_connect)((ma_jack_client_t*)pDevice->jack.pClient, pServerPort, pClientPort); if (resultJACK != 0) { - ((mal_jack_free_proc)pContext->jack.jack_free)((void*)ppServerPorts); - ((mal_jack_deactivate_proc)pContext->jack.jack_deactivate)((mal_jack_client_t*)pDevice->jack.pClient); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[JACK] Failed to connect ports.", MA_ERROR); + ((ma_jack_free_proc)pContext->jack.jack_free)((void*)ppServerPorts); + ((ma_jack_deactivate_proc)pContext->jack.jack_deactivate)((ma_jack_client_t*)pDevice->jack.pClient); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[JACK] Failed to connect ports.", MA_ERROR); } } - ((mal_jack_free_proc)pContext->jack.jack_free)((void*)ppServerPorts); + ((ma_jack_free_proc)pContext->jack.jack_free)((void*)ppServerPorts); } - if (pDevice->type == mal_device_type_playback || pDevice->type == mal_device_type_duplex) { - const char** ppServerPorts = ((mal_jack_get_ports_proc)pContext->jack.jack_get_ports)((mal_jack_client_t*)pDevice->jack.pClient, NULL, NULL, mal_JackPortIsPhysical | mal_JackPortIsInput); + if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) { + const char** ppServerPorts = ((ma_jack_get_ports_proc)pContext->jack.jack_get_ports)((ma_jack_client_t*)pDevice->jack.pClient, NULL, NULL, ma_JackPortIsPhysical | ma_JackPortIsInput); if (ppServerPorts == NULL) { - ((mal_jack_deactivate_proc)pContext->jack.jack_deactivate)((mal_jack_client_t*)pDevice->jack.pClient); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[JACK] Failed to retrieve physical ports.", MA_ERROR); + ((ma_jack_deactivate_proc)pContext->jack.jack_deactivate)((ma_jack_client_t*)pDevice->jack.pClient); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[JACK] Failed to retrieve physical ports.", MA_ERROR); } for (size_t i = 0; ppServerPorts[i] != NULL; ++i) { const char* pServerPort = ppServerPorts[i]; - const char* pClientPort = ((mal_jack_port_name_proc)pContext->jack.jack_port_name)((mal_jack_port_t*)pDevice->jack.pPortsPlayback[i]); + const char* pClientPort = ((ma_jack_port_name_proc)pContext->jack.jack_port_name)((ma_jack_port_t*)pDevice->jack.pPortsPlayback[i]); - resultJACK = ((mal_jack_connect_proc)pContext->jack.jack_connect)((mal_jack_client_t*)pDevice->jack.pClient, pClientPort, pServerPort); + resultJACK = ((ma_jack_connect_proc)pContext->jack.jack_connect)((ma_jack_client_t*)pDevice->jack.pClient, pClientPort, pServerPort); if (resultJACK != 0) { - ((mal_jack_free_proc)pContext->jack.jack_free)((void*)ppServerPorts); - ((mal_jack_deactivate_proc)pContext->jack.jack_deactivate)((mal_jack_client_t*)pDevice->jack.pClient); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[JACK] Failed to connect ports.", MA_ERROR); + ((ma_jack_free_proc)pContext->jack.jack_free)((void*)ppServerPorts); + ((ma_jack_deactivate_proc)pContext->jack.jack_deactivate)((ma_jack_client_t*)pDevice->jack.pClient); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[JACK] Failed to connect ports.", MA_ERROR); } } - ((mal_jack_free_proc)pContext->jack.jack_free)((void*)ppServerPorts); + ((ma_jack_free_proc)pContext->jack.jack_free)((void*)ppServerPorts); } return MA_SUCCESS; } -mal_result mal_device_stop__jack(mal_device* pDevice) +ma_result ma_device_stop__jack(ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); - mal_context* pContext = pDevice->pContext; - mal_assert(pContext != NULL); + ma_context* pContext = pDevice->pContext; + ma_assert(pContext != NULL); - if (((mal_jack_deactivate_proc)pContext->jack.jack_deactivate)((mal_jack_client_t*)pDevice->jack.pClient) != 0) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[JACK] An error occurred when deactivating the JACK client.", MA_ERROR); + if (((ma_jack_deactivate_proc)pContext->jack.jack_deactivate)((ma_jack_client_t*)pDevice->jack.pClient) != 0) { + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[JACK] An error occurred when deactivating the JACK client.", MA_ERROR); } - mal_stop_proc onStop = pDevice->onStop; + ma_stop_proc onStop = pDevice->onStop; if (onStop) { onStop(pDevice); } @@ -15509,21 +15509,21 @@ mal_result mal_device_stop__jack(mal_device* pDevice) } -mal_result mal_context_uninit__jack(mal_context* pContext) +ma_result ma_context_uninit__jack(ma_context* pContext) { - mal_assert(pContext != NULL); - mal_assert(pContext->backend == mal_backend_jack); + ma_assert(pContext != NULL); + ma_assert(pContext->backend == ma_backend_jack); #ifndef MA_NO_RUNTIME_LINKING - mal_dlclose(pContext->jack.jackSO); + ma_dlclose(pContext->jack.jackSO); #endif return MA_SUCCESS; } -mal_result mal_context_init__jack(mal_context* pContext) +ma_result ma_context_init__jack(ma_context* pContext) { - mal_assert(pContext != NULL); + ma_assert(pContext != NULL); #ifndef MA_NO_RUNTIME_LINKING // libjack.so @@ -15536,8 +15536,8 @@ mal_result mal_context_init__jack(mal_context* pContext) #endif }; - for (size_t i = 0; i < mal_countof(libjackNames); ++i) { - pContext->jack.jackSO = mal_dlopen(libjackNames[i]); + for (size_t i = 0; i < ma_countof(libjackNames); ++i) { + pContext->jack.jackSO = ma_dlopen(libjackNames[i]); if (pContext->jack.jackSO != NULL) { break; } @@ -15547,81 +15547,81 @@ mal_result mal_context_init__jack(mal_context* pContext) return MA_NO_BACKEND; } - pContext->jack.jack_client_open = (mal_proc)mal_dlsym(pContext->jack.jackSO, "jack_client_open"); - pContext->jack.jack_client_close = (mal_proc)mal_dlsym(pContext->jack.jackSO, "jack_client_close"); - pContext->jack.jack_client_name_size = (mal_proc)mal_dlsym(pContext->jack.jackSO, "jack_client_name_size"); - pContext->jack.jack_set_process_callback = (mal_proc)mal_dlsym(pContext->jack.jackSO, "jack_set_process_callback"); - pContext->jack.jack_set_buffer_size_callback = (mal_proc)mal_dlsym(pContext->jack.jackSO, "jack_set_buffer_size_callback"); - pContext->jack.jack_on_shutdown = (mal_proc)mal_dlsym(pContext->jack.jackSO, "jack_on_shutdown"); - pContext->jack.jack_get_sample_rate = (mal_proc)mal_dlsym(pContext->jack.jackSO, "jack_get_sample_rate"); - pContext->jack.jack_get_buffer_size = (mal_proc)mal_dlsym(pContext->jack.jackSO, "jack_get_buffer_size"); - pContext->jack.jack_get_ports = (mal_proc)mal_dlsym(pContext->jack.jackSO, "jack_get_ports"); - pContext->jack.jack_activate = (mal_proc)mal_dlsym(pContext->jack.jackSO, "jack_activate"); - pContext->jack.jack_deactivate = (mal_proc)mal_dlsym(pContext->jack.jackSO, "jack_deactivate"); - pContext->jack.jack_connect = (mal_proc)mal_dlsym(pContext->jack.jackSO, "jack_connect"); - pContext->jack.jack_port_register = (mal_proc)mal_dlsym(pContext->jack.jackSO, "jack_port_register"); - pContext->jack.jack_port_name = (mal_proc)mal_dlsym(pContext->jack.jackSO, "jack_port_name"); - pContext->jack.jack_port_get_buffer = (mal_proc)mal_dlsym(pContext->jack.jackSO, "jack_port_get_buffer"); - pContext->jack.jack_free = (mal_proc)mal_dlsym(pContext->jack.jackSO, "jack_free"); + pContext->jack.jack_client_open = (ma_proc)ma_dlsym(pContext->jack.jackSO, "jack_client_open"); + pContext->jack.jack_client_close = (ma_proc)ma_dlsym(pContext->jack.jackSO, "jack_client_close"); + pContext->jack.jack_client_name_size = (ma_proc)ma_dlsym(pContext->jack.jackSO, "jack_client_name_size"); + pContext->jack.jack_set_process_callback = (ma_proc)ma_dlsym(pContext->jack.jackSO, "jack_set_process_callback"); + pContext->jack.jack_set_buffer_size_callback = (ma_proc)ma_dlsym(pContext->jack.jackSO, "jack_set_buffer_size_callback"); + pContext->jack.jack_on_shutdown = (ma_proc)ma_dlsym(pContext->jack.jackSO, "jack_on_shutdown"); + pContext->jack.jack_get_sample_rate = (ma_proc)ma_dlsym(pContext->jack.jackSO, "jack_get_sample_rate"); + pContext->jack.jack_get_buffer_size = (ma_proc)ma_dlsym(pContext->jack.jackSO, "jack_get_buffer_size"); + pContext->jack.jack_get_ports = (ma_proc)ma_dlsym(pContext->jack.jackSO, "jack_get_ports"); + pContext->jack.jack_activate = (ma_proc)ma_dlsym(pContext->jack.jackSO, "jack_activate"); + pContext->jack.jack_deactivate = (ma_proc)ma_dlsym(pContext->jack.jackSO, "jack_deactivate"); + pContext->jack.jack_connect = (ma_proc)ma_dlsym(pContext->jack.jackSO, "jack_connect"); + pContext->jack.jack_port_register = (ma_proc)ma_dlsym(pContext->jack.jackSO, "jack_port_register"); + pContext->jack.jack_port_name = (ma_proc)ma_dlsym(pContext->jack.jackSO, "jack_port_name"); + pContext->jack.jack_port_get_buffer = (ma_proc)ma_dlsym(pContext->jack.jackSO, "jack_port_get_buffer"); + pContext->jack.jack_free = (ma_proc)ma_dlsym(pContext->jack.jackSO, "jack_free"); #else // This strange assignment system is here just to ensure type safety of miniaudio's function pointer // types. If anything differs slightly the compiler should throw a warning. - mal_jack_client_open_proc _jack_client_open = jack_client_open; - mal_jack_client_close_proc _jack_client_close = jack_client_close; - mal_jack_client_name_size_proc _jack_client_name_size = jack_client_name_size; - mal_jack_set_process_callback_proc _jack_set_process_callback = jack_set_process_callback; - mal_jack_set_buffer_size_callback_proc _jack_set_buffer_size_callback = jack_set_buffer_size_callback; - mal_jack_on_shutdown_proc _jack_on_shutdown = jack_on_shutdown; - mal_jack_get_sample_rate_proc _jack_get_sample_rate = jack_get_sample_rate; - mal_jack_get_buffer_size_proc _jack_get_buffer_size = jack_get_buffer_size; - mal_jack_get_ports_proc _jack_get_ports = jack_get_ports; - mal_jack_activate_proc _jack_activate = jack_activate; - mal_jack_deactivate_proc _jack_deactivate = jack_deactivate; - mal_jack_connect_proc _jack_connect = jack_connect; - mal_jack_port_register_proc _jack_port_register = jack_port_register; - mal_jack_port_name_proc _jack_port_name = jack_port_name; - mal_jack_port_get_buffer_proc _jack_port_get_buffer = jack_port_get_buffer; - mal_jack_free_proc _jack_free = jack_free; + ma_jack_client_open_proc _jack_client_open = jack_client_open; + ma_jack_client_close_proc _jack_client_close = jack_client_close; + ma_jack_client_name_size_proc _jack_client_name_size = jack_client_name_size; + ma_jack_set_process_callback_proc _jack_set_process_callback = jack_set_process_callback; + ma_jack_set_buffer_size_callback_proc _jack_set_buffer_size_callback = jack_set_buffer_size_callback; + ma_jack_on_shutdown_proc _jack_on_shutdown = jack_on_shutdown; + ma_jack_get_sample_rate_proc _jack_get_sample_rate = jack_get_sample_rate; + ma_jack_get_buffer_size_proc _jack_get_buffer_size = jack_get_buffer_size; + ma_jack_get_ports_proc _jack_get_ports = jack_get_ports; + ma_jack_activate_proc _jack_activate = jack_activate; + ma_jack_deactivate_proc _jack_deactivate = jack_deactivate; + ma_jack_connect_proc _jack_connect = jack_connect; + ma_jack_port_register_proc _jack_port_register = jack_port_register; + ma_jack_port_name_proc _jack_port_name = jack_port_name; + ma_jack_port_get_buffer_proc _jack_port_get_buffer = jack_port_get_buffer; + ma_jack_free_proc _jack_free = jack_free; - pContext->jack.jack_client_open = (mal_proc)_jack_client_open; - pContext->jack.jack_client_close = (mal_proc)_jack_client_close; - pContext->jack.jack_client_name_size = (mal_proc)_jack_client_name_size; - pContext->jack.jack_set_process_callback = (mal_proc)_jack_set_process_callback; - pContext->jack.jack_set_buffer_size_callback = (mal_proc)_jack_set_buffer_size_callback; - pContext->jack.jack_on_shutdown = (mal_proc)_jack_on_shutdown; - pContext->jack.jack_get_sample_rate = (mal_proc)_jack_get_sample_rate; - pContext->jack.jack_get_buffer_size = (mal_proc)_jack_get_buffer_size; - pContext->jack.jack_get_ports = (mal_proc)_jack_get_ports; - pContext->jack.jack_activate = (mal_proc)_jack_activate; - pContext->jack.jack_deactivate = (mal_proc)_jack_deactivate; - pContext->jack.jack_connect = (mal_proc)_jack_connect; - pContext->jack.jack_port_register = (mal_proc)_jack_port_register; - pContext->jack.jack_port_name = (mal_proc)_jack_port_name; - pContext->jack.jack_port_get_buffer = (mal_proc)_jack_port_get_buffer; - pContext->jack.jack_free = (mal_proc)_jack_free; + pContext->jack.jack_client_open = (ma_proc)_jack_client_open; + pContext->jack.jack_client_close = (ma_proc)_jack_client_close; + pContext->jack.jack_client_name_size = (ma_proc)_jack_client_name_size; + pContext->jack.jack_set_process_callback = (ma_proc)_jack_set_process_callback; + pContext->jack.jack_set_buffer_size_callback = (ma_proc)_jack_set_buffer_size_callback; + pContext->jack.jack_on_shutdown = (ma_proc)_jack_on_shutdown; + pContext->jack.jack_get_sample_rate = (ma_proc)_jack_get_sample_rate; + pContext->jack.jack_get_buffer_size = (ma_proc)_jack_get_buffer_size; + pContext->jack.jack_get_ports = (ma_proc)_jack_get_ports; + pContext->jack.jack_activate = (ma_proc)_jack_activate; + pContext->jack.jack_deactivate = (ma_proc)_jack_deactivate; + pContext->jack.jack_connect = (ma_proc)_jack_connect; + pContext->jack.jack_port_register = (ma_proc)_jack_port_register; + pContext->jack.jack_port_name = (ma_proc)_jack_port_name; + pContext->jack.jack_port_get_buffer = (ma_proc)_jack_port_get_buffer; + pContext->jack.jack_free = (ma_proc)_jack_free; #endif pContext->isBackendAsynchronous = MA_TRUE; - pContext->onUninit = mal_context_uninit__jack; - pContext->onDeviceIDEqual = mal_context_is_device_id_equal__jack; - pContext->onEnumDevices = mal_context_enumerate_devices__jack; - pContext->onGetDeviceInfo = mal_context_get_device_info__jack; - pContext->onDeviceInit = mal_device_init__jack; - pContext->onDeviceUninit = mal_device_uninit__jack; - pContext->onDeviceStart = mal_device_start__jack; - pContext->onDeviceStop = mal_device_stop__jack; + pContext->onUninit = ma_context_uninit__jack; + pContext->onDeviceIDEqual = ma_context_is_device_id_equal__jack; + pContext->onEnumDevices = ma_context_enumerate_devices__jack; + pContext->onGetDeviceInfo = ma_context_get_device_info__jack; + pContext->onDeviceInit = ma_device_init__jack; + pContext->onDeviceUninit = ma_device_uninit__jack; + pContext->onDeviceStart = ma_device_start__jack; + pContext->onDeviceStop = ma_device_stop__jack; // Getting here means the JACK library is installed, but it doesn't necessarily mean it's usable. We need to quickly test this by connecting // a temporary client. - mal_jack_client_t* pDummyClient; - mal_result result = mal_context_open_client__jack(pContext, &pDummyClient); + ma_jack_client_t* pDummyClient; + ma_result result = ma_context_open_client__jack(pContext, &pDummyClient); if (result != MA_SUCCESS) { return MA_NO_BACKEND; } - ((mal_jack_client_close_proc)pContext->jack.jack_client_close)((mal_jack_client_t*)pDummyClient); + ((ma_jack_client_close_proc)pContext->jack.jack_client_close)((ma_jack_client_t*)pDummyClient); return MA_SUCCESS; } #endif // JACK @@ -15651,34 +15651,34 @@ mal_result mal_context_init__jack(mal_context* pContext) #include // CoreFoundation -typedef Boolean (* mal_CFStringGetCString_proc)(CFStringRef theString, char* buffer, CFIndex bufferSize, CFStringEncoding encoding); +typedef Boolean (* ma_CFStringGetCString_proc)(CFStringRef theString, char* buffer, CFIndex bufferSize, CFStringEncoding encoding); // CoreAudio #if defined(MA_APPLE_DESKTOP) -typedef OSStatus (* mal_AudioObjectGetPropertyData_proc)(AudioObjectID inObjectID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32* ioDataSize, void* outData); -typedef OSStatus (* mal_AudioObjectGetPropertyDataSize_proc)(AudioObjectID inObjectID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32* outDataSize); -typedef OSStatus (* mal_AudioObjectSetPropertyData_proc)(AudioObjectID inObjectID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, const void* inData); -typedef OSStatus (* mal_AudioObjectAddPropertyListener_proc)(AudioObjectID inObjectID, const AudioObjectPropertyAddress* inAddress, AudioObjectPropertyListenerProc inListener, void* inClientData); +typedef OSStatus (* ma_AudioObjectGetPropertyData_proc)(AudioObjectID inObjectID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32* ioDataSize, void* outData); +typedef OSStatus (* ma_AudioObjectGetPropertyDataSize_proc)(AudioObjectID inObjectID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32* outDataSize); +typedef OSStatus (* ma_AudioObjectSetPropertyData_proc)(AudioObjectID inObjectID, const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, const void* inData); +typedef OSStatus (* ma_AudioObjectAddPropertyListener_proc)(AudioObjectID inObjectID, const AudioObjectPropertyAddress* inAddress, AudioObjectPropertyListenerProc inListener, void* inClientData); #endif // AudioToolbox -typedef AudioComponent (* mal_AudioComponentFindNext_proc)(AudioComponent inComponent, const AudioComponentDescription* inDesc); -typedef OSStatus (* mal_AudioComponentInstanceDispose_proc)(AudioComponentInstance inInstance); -typedef OSStatus (* mal_AudioComponentInstanceNew_proc)(AudioComponent inComponent, AudioComponentInstance* outInstance); -typedef OSStatus (* mal_AudioOutputUnitStart_proc)(AudioUnit inUnit); -typedef OSStatus (* mal_AudioOutputUnitStop_proc)(AudioUnit inUnit); -typedef OSStatus (* mal_AudioUnitAddPropertyListener_proc)(AudioUnit inUnit, AudioUnitPropertyID inID, AudioUnitPropertyListenerProc inProc, void* inProcUserData); -typedef OSStatus (* mal_AudioUnitGetPropertyInfo_proc)(AudioUnit inUnit, AudioUnitPropertyID inID, AudioUnitScope inScope, AudioUnitElement inElement, UInt32* outDataSize, Boolean* outWriteable); -typedef OSStatus (* mal_AudioUnitGetProperty_proc)(AudioUnit inUnit, AudioUnitPropertyID inID, AudioUnitScope inScope, AudioUnitElement inElement, void* outData, UInt32* ioDataSize); -typedef OSStatus (* mal_AudioUnitSetProperty_proc)(AudioUnit inUnit, AudioUnitPropertyID inID, AudioUnitScope inScope, AudioUnitElement inElement, const void* inData, UInt32 inDataSize); -typedef OSStatus (* mal_AudioUnitInitialize_proc)(AudioUnit inUnit); -typedef OSStatus (* mal_AudioUnitRender_proc)(AudioUnit inUnit, AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp, UInt32 inOutputBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData); +typedef AudioComponent (* ma_AudioComponentFindNext_proc)(AudioComponent inComponent, const AudioComponentDescription* inDesc); +typedef OSStatus (* ma_AudioComponentInstanceDispose_proc)(AudioComponentInstance inInstance); +typedef OSStatus (* ma_AudioComponentInstanceNew_proc)(AudioComponent inComponent, AudioComponentInstance* outInstance); +typedef OSStatus (* ma_AudioOutputUnitStart_proc)(AudioUnit inUnit); +typedef OSStatus (* ma_AudioOutputUnitStop_proc)(AudioUnit inUnit); +typedef OSStatus (* ma_AudioUnitAddPropertyListener_proc)(AudioUnit inUnit, AudioUnitPropertyID inID, AudioUnitPropertyListenerProc inProc, void* inProcUserData); +typedef OSStatus (* ma_AudioUnitGetPropertyInfo_proc)(AudioUnit inUnit, AudioUnitPropertyID inID, AudioUnitScope inScope, AudioUnitElement inElement, UInt32* outDataSize, Boolean* outWriteable); +typedef OSStatus (* ma_AudioUnitGetProperty_proc)(AudioUnit inUnit, AudioUnitPropertyID inID, AudioUnitScope inScope, AudioUnitElement inElement, void* outData, UInt32* ioDataSize); +typedef OSStatus (* ma_AudioUnitSetProperty_proc)(AudioUnit inUnit, AudioUnitPropertyID inID, AudioUnitScope inScope, AudioUnitElement inElement, const void* inData, UInt32 inDataSize); +typedef OSStatus (* ma_AudioUnitInitialize_proc)(AudioUnit inUnit); +typedef OSStatus (* ma_AudioUnitRender_proc)(AudioUnit inUnit, AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp, UInt32 inOutputBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData); #define MA_COREAUDIO_OUTPUT_BUS 0 #define MA_COREAUDIO_INPUT_BUS 1 -mal_result mal_device_reinit_internal__coreaudio(mal_device* pDevice, mal_device_type deviceType, mal_bool32 disposePreviousAudioUnit); +ma_result ma_device_reinit_internal__coreaudio(ma_device* pDevice, ma_device_type deviceType, ma_bool32 disposePreviousAudioUnit); // Core Audio @@ -15712,7 +15712,7 @@ mal_result mal_device_reinit_internal__coreaudio(mal_device* pDevice, mal_device // size, allocate a block of memory of that size and then call AudioObjectGetPropertyData(). The data is just a list of // AudioDeviceID's so just do "dataSize/sizeof(AudioDeviceID)" to know the device count. -mal_result mal_result_from_OSStatus(OSStatus status) +ma_result ma_result_from_OSStatus(OSStatus status) { switch (status) { @@ -15735,7 +15735,7 @@ mal_result mal_result_from_OSStatus(OSStatus status) } #if 0 -mal_channel mal_channel_from_AudioChannelBitmap(AudioChannelBitmap bit) +ma_channel ma_channel_from_AudioChannelBitmap(AudioChannelBitmap bit) { switch (bit) { @@ -15762,7 +15762,7 @@ mal_channel mal_channel_from_AudioChannelBitmap(AudioChannelBitmap bit) } #endif -mal_channel mal_channel_from_AudioChannelLabel(AudioChannelLabel label) +ma_channel ma_channel_from_AudioChannelLabel(AudioChannelLabel label) { switch (label) { @@ -15856,12 +15856,12 @@ mal_channel mal_channel_from_AudioChannelLabel(AudioChannelLabel label) } } -mal_result mal_format_from_AudioStreamBasicDescription(const AudioStreamBasicDescription* pDescription, mal_format* pFormatOut) +ma_result ma_format_from_AudioStreamBasicDescription(const AudioStreamBasicDescription* pDescription, ma_format* pFormatOut) { - mal_assert(pDescription != NULL); - mal_assert(pFormatOut != NULL); + ma_assert(pDescription != NULL); + ma_assert(pFormatOut != NULL); - *pFormatOut = mal_format_unknown; // Safety. + *pFormatOut = ma_format_unknown; // Safety. // There's a few things miniaudio doesn't support. if (pDescription->mFormatID != kAudioFormatLinearPCM) { @@ -15874,7 +15874,7 @@ mal_result mal_format_from_AudioStreamBasicDescription(const AudioStreamBasicDes } // Only supporting native-endian. - if ((mal_is_little_endian() && (pDescription->mFormatFlags & kAudioFormatFlagIsBigEndian) != 0) || (mal_is_big_endian() && (pDescription->mFormatFlags & kAudioFormatFlagIsBigEndian) == 0)) { + if ((ma_is_little_endian() && (pDescription->mFormatFlags & kAudioFormatFlagIsBigEndian) != 0) || (ma_is_big_endian() && (pDescription->mFormatFlags & kAudioFormatFlagIsBigEndian) == 0)) { return MA_FORMAT_NOT_SUPPORTED; } @@ -15885,33 +15885,33 @@ mal_result mal_format_from_AudioStreamBasicDescription(const AudioStreamBasicDes if ((pDescription->mFormatFlags & kLinearPCMFormatFlagIsFloat) != 0) { if (pDescription->mBitsPerChannel == 32) { - *pFormatOut = mal_format_f32; + *pFormatOut = ma_format_f32; return MA_SUCCESS; } } else { if ((pDescription->mFormatFlags & kLinearPCMFormatFlagIsSignedInteger) != 0) { if (pDescription->mBitsPerChannel == 16) { - *pFormatOut = mal_format_s16; + *pFormatOut = ma_format_s16; return MA_SUCCESS; } else if (pDescription->mBitsPerChannel == 24) { if (pDescription->mBytesPerFrame == (pDescription->mBitsPerChannel/8 * pDescription->mChannelsPerFrame)) { - *pFormatOut = mal_format_s24; + *pFormatOut = ma_format_s24; return MA_SUCCESS; } else { - if (pDescription->mBytesPerFrame/pDescription->mChannelsPerFrame == sizeof(mal_int32)) { - // TODO: Implement mal_format_s24_32. - //*pFormatOut = mal_format_s24_32; + if (pDescription->mBytesPerFrame/pDescription->mChannelsPerFrame == sizeof(ma_int32)) { + // TODO: Implement ma_format_s24_32. + //*pFormatOut = ma_format_s24_32; //return MA_SUCCESS; return MA_FORMAT_NOT_SUPPORTED; } } } else if (pDescription->mBitsPerChannel == 32) { - *pFormatOut = mal_format_s32; + *pFormatOut = ma_format_s32; return MA_SUCCESS; } } else { if (pDescription->mBitsPerChannel == 8) { - *pFormatOut = mal_format_u8; + *pFormatOut = ma_format_u8; return MA_SUCCESS; } } @@ -15921,13 +15921,13 @@ mal_result mal_format_from_AudioStreamBasicDescription(const AudioStreamBasicDes return MA_FORMAT_NOT_SUPPORTED; } -mal_result mal_get_channel_map_from_AudioChannelLayout(AudioChannelLayout* pChannelLayout, mal_channel channelMap[MA_MAX_CHANNELS]) +ma_result ma_get_channel_map_from_AudioChannelLayout(AudioChannelLayout* pChannelLayout, ma_channel channelMap[MA_MAX_CHANNELS]) { - mal_assert(pChannelLayout != NULL); + ma_assert(pChannelLayout != NULL); if (pChannelLayout->mChannelLayoutTag == kAudioChannelLayoutTag_UseChannelDescriptions) { for (UInt32 iChannel = 0; iChannel < pChannelLayout->mNumberChannelDescriptions; ++iChannel) { - channelMap[iChannel] = mal_channel_from_AudioChannelLabel(pChannelLayout->mChannelDescriptions[iChannel].mChannelLabel); + channelMap[iChannel] = ma_channel_from_AudioChannelLabel(pChannelLayout->mChannelDescriptions[iChannel].mChannelLabel); } } else #if 0 @@ -15938,7 +15938,7 @@ mal_result mal_get_channel_map_from_AudioChannelLayout(AudioChannelLayout* pChan for (UInt32 iBit = 0; iBit < 32; ++iBit) { AudioChannelBitmap bit = bitmap & (1 << iBit); if (bit != 0) { - channelMap[iChannel++] = mal_channel_from_AudioChannelBit(bit); + channelMap[iChannel++] = ma_channel_from_AudioChannelBit(bit); } } } else @@ -15958,7 +15958,7 @@ mal_result mal_get_channel_map_from_AudioChannelLayout(AudioChannelLayout* pChan case kAudioChannelLayoutTag_Binaural: case kAudioChannelLayoutTag_Ambisonic_B_Format: { - mal_get_standard_channel_map(mal_standard_channel_map_default, channelCount, channelMap); + ma_get_standard_channel_map(ma_standard_channel_map_default, channelCount, channelMap); } break; case kAudioChannelLayoutTag_Octagonal: @@ -15986,7 +15986,7 @@ mal_result mal_get_channel_map_from_AudioChannelLayout(AudioChannelLayout* pChan default: { - mal_get_standard_channel_map(mal_standard_channel_map_default, channelCount, channelMap); + ma_get_standard_channel_map(ma_standard_channel_map_default, channelCount, channelMap); } break; } } @@ -15996,11 +15996,11 @@ mal_result mal_get_channel_map_from_AudioChannelLayout(AudioChannelLayout* pChan #if defined(MA_APPLE_DESKTOP) -mal_result mal_get_device_object_ids__coreaudio(mal_context* pContext, UInt32* pDeviceCount, AudioObjectID** ppDeviceObjectIDs) // NOTE: Free the returned buffer with mal_free(). +ma_result ma_get_device_object_ids__coreaudio(ma_context* pContext, UInt32* pDeviceCount, AudioObjectID** ppDeviceObjectIDs) // NOTE: Free the returned buffer with ma_free(). { - mal_assert(pContext != NULL); - mal_assert(pDeviceCount != NULL); - mal_assert(ppDeviceObjectIDs != NULL); + ma_assert(pContext != NULL); + ma_assert(pDeviceCount != NULL); + ma_assert(ppDeviceObjectIDs != NULL); (void)pContext; // Safety. @@ -16013,20 +16013,20 @@ mal_result mal_get_device_object_ids__coreaudio(mal_context* pContext, UInt32* p propAddressDevices.mElement = kAudioObjectPropertyElementMaster; UInt32 deviceObjectsDataSize; - OSStatus status = ((mal_AudioObjectGetPropertyDataSize_proc)pContext->coreaudio.AudioObjectGetPropertyDataSize)(kAudioObjectSystemObject, &propAddressDevices, 0, NULL, &deviceObjectsDataSize); + OSStatus status = ((ma_AudioObjectGetPropertyDataSize_proc)pContext->coreaudio.AudioObjectGetPropertyDataSize)(kAudioObjectSystemObject, &propAddressDevices, 0, NULL, &deviceObjectsDataSize); if (status != noErr) { - return mal_result_from_OSStatus(status); + return ma_result_from_OSStatus(status); } - AudioObjectID* pDeviceObjectIDs = (AudioObjectID*)mal_malloc(deviceObjectsDataSize); + AudioObjectID* pDeviceObjectIDs = (AudioObjectID*)ma_malloc(deviceObjectsDataSize); if (pDeviceObjectIDs == NULL) { return MA_OUT_OF_MEMORY; } - status = ((mal_AudioObjectGetPropertyData_proc)pContext->coreaudio.AudioObjectGetPropertyData)(kAudioObjectSystemObject, &propAddressDevices, 0, NULL, &deviceObjectsDataSize, pDeviceObjectIDs); + status = ((ma_AudioObjectGetPropertyData_proc)pContext->coreaudio.AudioObjectGetPropertyData)(kAudioObjectSystemObject, &propAddressDevices, 0, NULL, &deviceObjectsDataSize, pDeviceObjectIDs); if (status != noErr) { - mal_free(pDeviceObjectIDs); - return mal_result_from_OSStatus(status); + ma_free(pDeviceObjectIDs); + return ma_result_from_OSStatus(status); } *pDeviceCount = deviceObjectsDataSize / sizeof(AudioObjectID); @@ -16034,9 +16034,9 @@ mal_result mal_get_device_object_ids__coreaudio(mal_context* pContext, UInt32* p return MA_SUCCESS; } -mal_result mal_get_AudioObject_uid_as_CFStringRef(mal_context* pContext, AudioObjectID objectID, CFStringRef* pUID) +ma_result ma_get_AudioObject_uid_as_CFStringRef(ma_context* pContext, AudioObjectID objectID, CFStringRef* pUID) { - mal_assert(pContext != NULL); + ma_assert(pContext != NULL); AudioObjectPropertyAddress propAddress; propAddress.mSelector = kAudioDevicePropertyDeviceUID; @@ -16044,34 +16044,34 @@ mal_result mal_get_AudioObject_uid_as_CFStringRef(mal_context* pContext, AudioOb propAddress.mElement = kAudioObjectPropertyElementMaster; UInt32 dataSize = sizeof(*pUID); - OSStatus status = ((mal_AudioObjectGetPropertyData_proc)pContext->coreaudio.AudioObjectGetPropertyData)(objectID, &propAddress, 0, NULL, &dataSize, pUID); + OSStatus status = ((ma_AudioObjectGetPropertyData_proc)pContext->coreaudio.AudioObjectGetPropertyData)(objectID, &propAddress, 0, NULL, &dataSize, pUID); if (status != noErr) { - return mal_result_from_OSStatus(status); + return ma_result_from_OSStatus(status); } return MA_SUCCESS; } -mal_result mal_get_AudioObject_uid(mal_context* pContext, AudioObjectID objectID, size_t bufferSize, char* bufferOut) +ma_result ma_get_AudioObject_uid(ma_context* pContext, AudioObjectID objectID, size_t bufferSize, char* bufferOut) { - mal_assert(pContext != NULL); + ma_assert(pContext != NULL); CFStringRef uid; - mal_result result = mal_get_AudioObject_uid_as_CFStringRef(pContext, objectID, &uid); + ma_result result = ma_get_AudioObject_uid_as_CFStringRef(pContext, objectID, &uid); if (result != MA_SUCCESS) { return result; } - if (!((mal_CFStringGetCString_proc)pContext->coreaudio.CFStringGetCString)(uid, bufferOut, bufferSize, kCFStringEncodingUTF8)) { + if (!((ma_CFStringGetCString_proc)pContext->coreaudio.CFStringGetCString)(uid, bufferOut, bufferSize, kCFStringEncodingUTF8)) { return MA_ERROR; } return MA_SUCCESS; } -mal_result mal_get_AudioObject_name(mal_context* pContext, AudioObjectID objectID, size_t bufferSize, char* bufferOut) +ma_result ma_get_AudioObject_name(ma_context* pContext, AudioObjectID objectID, size_t bufferSize, char* bufferOut) { - mal_assert(pContext != NULL); + ma_assert(pContext != NULL); AudioObjectPropertyAddress propAddress; propAddress.mSelector = kAudioDevicePropertyDeviceNameCFString; @@ -16080,21 +16080,21 @@ mal_result mal_get_AudioObject_name(mal_context* pContext, AudioObjectID objectI CFStringRef deviceName = NULL; UInt32 dataSize = sizeof(deviceName); - OSStatus status = ((mal_AudioObjectGetPropertyData_proc)pContext->coreaudio.AudioObjectGetPropertyData)(objectID, &propAddress, 0, NULL, &dataSize, &deviceName); + OSStatus status = ((ma_AudioObjectGetPropertyData_proc)pContext->coreaudio.AudioObjectGetPropertyData)(objectID, &propAddress, 0, NULL, &dataSize, &deviceName); if (status != noErr) { - return mal_result_from_OSStatus(status); + return ma_result_from_OSStatus(status); } - if (!((mal_CFStringGetCString_proc)pContext->coreaudio.CFStringGetCString)(deviceName, bufferOut, bufferSize, kCFStringEncodingUTF8)) { + if (!((ma_CFStringGetCString_proc)pContext->coreaudio.CFStringGetCString)(deviceName, bufferOut, bufferSize, kCFStringEncodingUTF8)) { return MA_ERROR; } return MA_SUCCESS; } -mal_bool32 mal_does_AudioObject_support_scope(mal_context* pContext, AudioObjectID deviceObjectID, AudioObjectPropertyScope scope) +ma_bool32 ma_does_AudioObject_support_scope(ma_context* pContext, AudioObjectID deviceObjectID, AudioObjectPropertyScope scope) { - mal_assert(pContext != NULL); + ma_assert(pContext != NULL); // To know whether or not a device is an input device we need ot look at the stream configuration. If it has an output channel it's a // playback device. @@ -16104,70 +16104,70 @@ mal_bool32 mal_does_AudioObject_support_scope(mal_context* pContext, AudioObject propAddress.mElement = kAudioObjectPropertyElementMaster; UInt32 dataSize; - OSStatus status = ((mal_AudioObjectGetPropertyDataSize_proc)pContext->coreaudio.AudioObjectGetPropertyDataSize)(deviceObjectID, &propAddress, 0, NULL, &dataSize); + OSStatus status = ((ma_AudioObjectGetPropertyDataSize_proc)pContext->coreaudio.AudioObjectGetPropertyDataSize)(deviceObjectID, &propAddress, 0, NULL, &dataSize); if (status != noErr) { return MA_FALSE; } - AudioBufferList* pBufferList = (AudioBufferList*)mal_malloc(dataSize); + AudioBufferList* pBufferList = (AudioBufferList*)ma_malloc(dataSize); if (pBufferList == NULL) { return MA_FALSE; // Out of memory. } - status = ((mal_AudioObjectGetPropertyData_proc)pContext->coreaudio.AudioObjectGetPropertyData)(deviceObjectID, &propAddress, 0, NULL, &dataSize, pBufferList); + status = ((ma_AudioObjectGetPropertyData_proc)pContext->coreaudio.AudioObjectGetPropertyData)(deviceObjectID, &propAddress, 0, NULL, &dataSize, pBufferList); if (status != noErr) { - mal_free(pBufferList); + ma_free(pBufferList); return MA_FALSE; } - mal_bool32 isSupported = MA_FALSE; + ma_bool32 isSupported = MA_FALSE; if (pBufferList->mNumberBuffers > 0) { isSupported = MA_TRUE; } - mal_free(pBufferList); + ma_free(pBufferList); return isSupported; } -mal_bool32 mal_does_AudioObject_support_playback(mal_context* pContext, AudioObjectID deviceObjectID) +ma_bool32 ma_does_AudioObject_support_playback(ma_context* pContext, AudioObjectID deviceObjectID) { - return mal_does_AudioObject_support_scope(pContext, deviceObjectID, kAudioObjectPropertyScopeOutput); + return ma_does_AudioObject_support_scope(pContext, deviceObjectID, kAudioObjectPropertyScopeOutput); } -mal_bool32 mal_does_AudioObject_support_capture(mal_context* pContext, AudioObjectID deviceObjectID) +ma_bool32 ma_does_AudioObject_support_capture(ma_context* pContext, AudioObjectID deviceObjectID) { - return mal_does_AudioObject_support_scope(pContext, deviceObjectID, kAudioObjectPropertyScopeInput); + return ma_does_AudioObject_support_scope(pContext, deviceObjectID, kAudioObjectPropertyScopeInput); } -mal_result mal_get_AudioObject_stream_descriptions(mal_context* pContext, AudioObjectID deviceObjectID, mal_device_type deviceType, UInt32* pDescriptionCount, AudioStreamRangedDescription** ppDescriptions) // NOTE: Free the returned pointer with mal_free(). +ma_result ma_get_AudioObject_stream_descriptions(ma_context* pContext, AudioObjectID deviceObjectID, ma_device_type deviceType, UInt32* pDescriptionCount, AudioStreamRangedDescription** ppDescriptions) // NOTE: Free the returned pointer with ma_free(). { - mal_assert(pContext != NULL); - mal_assert(pDescriptionCount != NULL); - mal_assert(ppDescriptions != NULL); + ma_assert(pContext != NULL); + ma_assert(pDescriptionCount != NULL); + ma_assert(ppDescriptions != NULL); // TODO: Experiment with kAudioStreamPropertyAvailablePhysicalFormats instead of (or in addition to) kAudioStreamPropertyAvailableVirtualFormats. My // MacBook Pro uses s24/32 format, however, which miniaudio does not currently support. AudioObjectPropertyAddress propAddress; propAddress.mSelector = kAudioStreamPropertyAvailableVirtualFormats; //kAudioStreamPropertyAvailablePhysicalFormats; - propAddress.mScope = (deviceType == mal_device_type_playback) ? kAudioObjectPropertyScopeOutput : kAudioObjectPropertyScopeInput; + propAddress.mScope = (deviceType == ma_device_type_playback) ? kAudioObjectPropertyScopeOutput : kAudioObjectPropertyScopeInput; propAddress.mElement = kAudioObjectPropertyElementMaster; UInt32 dataSize; - OSStatus status = ((mal_AudioObjectGetPropertyDataSize_proc)pContext->coreaudio.AudioObjectGetPropertyDataSize)(deviceObjectID, &propAddress, 0, NULL, &dataSize); + OSStatus status = ((ma_AudioObjectGetPropertyDataSize_proc)pContext->coreaudio.AudioObjectGetPropertyDataSize)(deviceObjectID, &propAddress, 0, NULL, &dataSize); if (status != noErr) { - return mal_result_from_OSStatus(status); + return ma_result_from_OSStatus(status); } - AudioStreamRangedDescription* pDescriptions = (AudioStreamRangedDescription*)mal_malloc(dataSize); + AudioStreamRangedDescription* pDescriptions = (AudioStreamRangedDescription*)ma_malloc(dataSize); if (pDescriptions == NULL) { return MA_OUT_OF_MEMORY; } - status = ((mal_AudioObjectGetPropertyData_proc)pContext->coreaudio.AudioObjectGetPropertyData)(deviceObjectID, &propAddress, 0, NULL, &dataSize, pDescriptions); + status = ((ma_AudioObjectGetPropertyData_proc)pContext->coreaudio.AudioObjectGetPropertyData)(deviceObjectID, &propAddress, 0, NULL, &dataSize, pDescriptions); if (status != noErr) { - mal_free(pDescriptions); - return mal_result_from_OSStatus(status); + ma_free(pDescriptions); + return ma_result_from_OSStatus(status); } *pDescriptionCount = dataSize / sizeof(*pDescriptions); @@ -16176,48 +16176,48 @@ mal_result mal_get_AudioObject_stream_descriptions(mal_context* pContext, AudioO } -mal_result mal_get_AudioObject_channel_layout(mal_context* pContext, AudioObjectID deviceObjectID, mal_device_type deviceType, AudioChannelLayout** ppChannelLayout) // NOTE: Free the returned pointer with mal_free(). +ma_result ma_get_AudioObject_channel_layout(ma_context* pContext, AudioObjectID deviceObjectID, ma_device_type deviceType, AudioChannelLayout** ppChannelLayout) // NOTE: Free the returned pointer with ma_free(). { - mal_assert(pContext != NULL); - mal_assert(ppChannelLayout != NULL); + ma_assert(pContext != NULL); + ma_assert(ppChannelLayout != NULL); *ppChannelLayout = NULL; // Safety. AudioObjectPropertyAddress propAddress; propAddress.mSelector = kAudioDevicePropertyPreferredChannelLayout; - propAddress.mScope = (deviceType == mal_device_type_playback) ? kAudioObjectPropertyScopeOutput : kAudioObjectPropertyScopeInput; + propAddress.mScope = (deviceType == ma_device_type_playback) ? kAudioObjectPropertyScopeOutput : kAudioObjectPropertyScopeInput; propAddress.mElement = kAudioObjectPropertyElementMaster; UInt32 dataSize; - OSStatus status = ((mal_AudioObjectGetPropertyDataSize_proc)pContext->coreaudio.AudioObjectGetPropertyDataSize)(deviceObjectID, &propAddress, 0, NULL, &dataSize); + OSStatus status = ((ma_AudioObjectGetPropertyDataSize_proc)pContext->coreaudio.AudioObjectGetPropertyDataSize)(deviceObjectID, &propAddress, 0, NULL, &dataSize); if (status != noErr) { - return mal_result_from_OSStatus(status); + return ma_result_from_OSStatus(status); } - AudioChannelLayout* pChannelLayout = (AudioChannelLayout*)mal_malloc(dataSize); + AudioChannelLayout* pChannelLayout = (AudioChannelLayout*)ma_malloc(dataSize); if (pChannelLayout == NULL) { return MA_OUT_OF_MEMORY; } - status = ((mal_AudioObjectGetPropertyData_proc)pContext->coreaudio.AudioObjectGetPropertyData)(deviceObjectID, &propAddress, 0, NULL, &dataSize, pChannelLayout); + status = ((ma_AudioObjectGetPropertyData_proc)pContext->coreaudio.AudioObjectGetPropertyData)(deviceObjectID, &propAddress, 0, NULL, &dataSize, pChannelLayout); if (status != noErr) { - mal_free(pChannelLayout); - return mal_result_from_OSStatus(status); + ma_free(pChannelLayout); + return ma_result_from_OSStatus(status); } *ppChannelLayout = pChannelLayout; return MA_SUCCESS; } -mal_result mal_get_AudioObject_channel_count(mal_context* pContext, AudioObjectID deviceObjectID, mal_device_type deviceType, mal_uint32* pChannelCount) +ma_result ma_get_AudioObject_channel_count(ma_context* pContext, AudioObjectID deviceObjectID, ma_device_type deviceType, ma_uint32* pChannelCount) { - mal_assert(pContext != NULL); - mal_assert(pChannelCount != NULL); + ma_assert(pContext != NULL); + ma_assert(pChannelCount != NULL); *pChannelCount = 0; // Safety. AudioChannelLayout* pChannelLayout; - mal_result result = mal_get_AudioObject_channel_layout(pContext, deviceObjectID, deviceType, &pChannelLayout); + ma_result result = ma_get_AudioObject_channel_layout(pContext, deviceObjectID, deviceType, &pChannelLayout); if (result != MA_SUCCESS) { return result; } @@ -16225,40 +16225,40 @@ mal_result mal_get_AudioObject_channel_count(mal_context* pContext, AudioObjectI if (pChannelLayout->mChannelLayoutTag == kAudioChannelLayoutTag_UseChannelDescriptions) { *pChannelCount = pChannelLayout->mNumberChannelDescriptions; } else if (pChannelLayout->mChannelLayoutTag == kAudioChannelLayoutTag_UseChannelBitmap) { - *pChannelCount = mal_count_set_bits(pChannelLayout->mChannelBitmap); + *pChannelCount = ma_count_set_bits(pChannelLayout->mChannelBitmap); } else { *pChannelCount = AudioChannelLayoutTag_GetNumberOfChannels(pChannelLayout->mChannelLayoutTag); } - mal_free(pChannelLayout); + ma_free(pChannelLayout); return MA_SUCCESS; } -mal_result mal_get_AudioObject_channel_map(mal_context* pContext, AudioObjectID deviceObjectID, mal_device_type deviceType, mal_channel channelMap[MA_MAX_CHANNELS]) +ma_result ma_get_AudioObject_channel_map(ma_context* pContext, AudioObjectID deviceObjectID, ma_device_type deviceType, ma_channel channelMap[MA_MAX_CHANNELS]) { - mal_assert(pContext != NULL); + ma_assert(pContext != NULL); AudioChannelLayout* pChannelLayout; - mal_result result = mal_get_AudioObject_channel_layout(pContext, deviceObjectID, deviceType, &pChannelLayout); + ma_result result = ma_get_AudioObject_channel_layout(pContext, deviceObjectID, deviceType, &pChannelLayout); if (result != MA_SUCCESS) { return result; // Rather than always failing here, would it be more robust to simply assume a default? } - result = mal_get_channel_map_from_AudioChannelLayout(pChannelLayout, channelMap); + result = ma_get_channel_map_from_AudioChannelLayout(pChannelLayout, channelMap); if (result != MA_SUCCESS) { - mal_free(pChannelLayout); + ma_free(pChannelLayout); return result; } - mal_free(pChannelLayout); + ma_free(pChannelLayout); return result; } -mal_result mal_get_AudioObject_sample_rates(mal_context* pContext, AudioObjectID deviceObjectID, mal_device_type deviceType, UInt32* pSampleRateRangesCount, AudioValueRange** ppSampleRateRanges) // NOTE: Free the returned pointer with mal_free(). +ma_result ma_get_AudioObject_sample_rates(ma_context* pContext, AudioObjectID deviceObjectID, ma_device_type deviceType, UInt32* pSampleRateRangesCount, AudioValueRange** ppSampleRateRanges) // NOTE: Free the returned pointer with ma_free(). { - mal_assert(pContext != NULL); - mal_assert(pSampleRateRangesCount != NULL); - mal_assert(ppSampleRateRanges != NULL); + ma_assert(pContext != NULL); + ma_assert(pSampleRateRangesCount != NULL); + ma_assert(ppSampleRateRanges != NULL); // Safety. *pSampleRateRangesCount = 0; @@ -16266,24 +16266,24 @@ mal_result mal_get_AudioObject_sample_rates(mal_context* pContext, AudioObjectID AudioObjectPropertyAddress propAddress; propAddress.mSelector = kAudioDevicePropertyAvailableNominalSampleRates; - propAddress.mScope = (deviceType == mal_device_type_playback) ? kAudioObjectPropertyScopeOutput : kAudioObjectPropertyScopeInput; + propAddress.mScope = (deviceType == ma_device_type_playback) ? kAudioObjectPropertyScopeOutput : kAudioObjectPropertyScopeInput; propAddress.mElement = kAudioObjectPropertyElementMaster; UInt32 dataSize; - OSStatus status = ((mal_AudioObjectGetPropertyDataSize_proc)pContext->coreaudio.AudioObjectGetPropertyDataSize)(deviceObjectID, &propAddress, 0, NULL, &dataSize); + OSStatus status = ((ma_AudioObjectGetPropertyDataSize_proc)pContext->coreaudio.AudioObjectGetPropertyDataSize)(deviceObjectID, &propAddress, 0, NULL, &dataSize); if (status != noErr) { - return mal_result_from_OSStatus(status); + return ma_result_from_OSStatus(status); } - AudioValueRange* pSampleRateRanges = (AudioValueRange*)mal_malloc(dataSize); + AudioValueRange* pSampleRateRanges = (AudioValueRange*)ma_malloc(dataSize); if (pSampleRateRanges == NULL) { return MA_OUT_OF_MEMORY; } - status = ((mal_AudioObjectGetPropertyData_proc)pContext->coreaudio.AudioObjectGetPropertyData)(deviceObjectID, &propAddress, 0, NULL, &dataSize, pSampleRateRanges); + status = ((ma_AudioObjectGetPropertyData_proc)pContext->coreaudio.AudioObjectGetPropertyData)(deviceObjectID, &propAddress, 0, NULL, &dataSize, pSampleRateRanges); if (status != noErr) { - mal_free(pSampleRateRanges); - return mal_result_from_OSStatus(status); + ma_free(pSampleRateRanges); + return ma_result_from_OSStatus(status); } *pSampleRateRangesCount = dataSize / sizeof(*pSampleRateRanges); @@ -16291,34 +16291,34 @@ mal_result mal_get_AudioObject_sample_rates(mal_context* pContext, AudioObjectID return MA_SUCCESS; } -mal_result mal_get_AudioObject_get_closest_sample_rate(mal_context* pContext, AudioObjectID deviceObjectID, mal_device_type deviceType, mal_uint32 sampleRateIn, mal_uint32* pSampleRateOut) +ma_result ma_get_AudioObject_get_closest_sample_rate(ma_context* pContext, AudioObjectID deviceObjectID, ma_device_type deviceType, ma_uint32 sampleRateIn, ma_uint32* pSampleRateOut) { - mal_assert(pContext != NULL); - mal_assert(pSampleRateOut != NULL); + ma_assert(pContext != NULL); + ma_assert(pSampleRateOut != NULL); *pSampleRateOut = 0; // Safety. UInt32 sampleRateRangeCount; AudioValueRange* pSampleRateRanges; - mal_result result = mal_get_AudioObject_sample_rates(pContext, deviceObjectID, deviceType, &sampleRateRangeCount, &pSampleRateRanges); + ma_result result = ma_get_AudioObject_sample_rates(pContext, deviceObjectID, deviceType, &sampleRateRangeCount, &pSampleRateRanges); if (result != MA_SUCCESS) { return result; } if (sampleRateRangeCount == 0) { - mal_free(pSampleRateRanges); + ma_free(pSampleRateRanges); return MA_ERROR; // Should never hit this case should we? } if (sampleRateIn == 0) { // Search in order of miniaudio's preferred priority. - for (UInt32 iMALSampleRate = 0; iMALSampleRate < mal_countof(g_malStandardSampleRatePriorities); ++iMALSampleRate) { - mal_uint32 malSampleRate = g_malStandardSampleRatePriorities[iMALSampleRate]; + for (UInt32 iMALSampleRate = 0; iMALSampleRate < ma_countof(g_malStandardSampleRatePriorities); ++iMALSampleRate) { + ma_uint32 malSampleRate = g_malStandardSampleRatePriorities[iMALSampleRate]; for (UInt32 iCASampleRate = 0; iCASampleRate < sampleRateRangeCount; ++iCASampleRate) { AudioValueRange caSampleRate = pSampleRateRanges[iCASampleRate]; if (caSampleRate.mMinimum <= malSampleRate && caSampleRate.mMaximum >= malSampleRate) { *pSampleRateOut = malSampleRate; - mal_free(pSampleRateRanges); + ma_free(pSampleRateRanges); return MA_SUCCESS; } } @@ -16326,10 +16326,10 @@ mal_result mal_get_AudioObject_get_closest_sample_rate(mal_context* pContext, Au // If we get here it means none of miniaudio's standard sample rates matched any of the supported sample rates from the device. In this // case we just fall back to the first one reported by Core Audio. - mal_assert(sampleRateRangeCount > 0); + ma_assert(sampleRateRangeCount > 0); *pSampleRateOut = pSampleRateRanges[0].mMinimum; - mal_free(pSampleRateRanges); + ma_free(pSampleRateRanges); return MA_SUCCESS; } else { // Find the closest match to this sample rate. @@ -16338,7 +16338,7 @@ mal_result mal_get_AudioObject_get_closest_sample_rate(mal_context* pContext, Au for (UInt32 iRange = 0; iRange < sampleRateRangeCount; ++iRange) { if (pSampleRateRanges[iRange].mMinimum <= sampleRateIn && pSampleRateRanges[iRange].mMaximum >= sampleRateIn) { *pSampleRateOut = sampleRateIn; - mal_free(pSampleRateRanges); + ma_free(pSampleRateRanges); return MA_SUCCESS; } else { UInt32 absoluteDifference; @@ -16355,43 +16355,43 @@ mal_result mal_get_AudioObject_get_closest_sample_rate(mal_context* pContext, Au } } - mal_assert(iCurrentClosestRange != (UInt32)-1); + ma_assert(iCurrentClosestRange != (UInt32)-1); *pSampleRateOut = pSampleRateRanges[iCurrentClosestRange].mMinimum; - mal_free(pSampleRateRanges); + ma_free(pSampleRateRanges); return MA_SUCCESS; } // Should never get here, but it would mean we weren't able to find any suitable sample rates. - //mal_free(pSampleRateRanges); + //ma_free(pSampleRateRanges); //return MA_ERROR; } -mal_result mal_get_AudioObject_closest_buffer_size_in_frames(mal_context* pContext, AudioObjectID deviceObjectID, mal_device_type deviceType, mal_uint32 bufferSizeInFramesIn, mal_uint32* pBufferSizeInFramesOut) +ma_result ma_get_AudioObject_closest_buffer_size_in_frames(ma_context* pContext, AudioObjectID deviceObjectID, ma_device_type deviceType, ma_uint32 bufferSizeInFramesIn, ma_uint32* pBufferSizeInFramesOut) { - mal_assert(pContext != NULL); - mal_assert(pBufferSizeInFramesOut != NULL); + ma_assert(pContext != NULL); + ma_assert(pBufferSizeInFramesOut != NULL); *pBufferSizeInFramesOut = 0; // Safety. AudioObjectPropertyAddress propAddress; propAddress.mSelector = kAudioDevicePropertyBufferFrameSizeRange; - propAddress.mScope = (deviceType == mal_device_type_playback) ? kAudioObjectPropertyScopeOutput : kAudioObjectPropertyScopeInput; + propAddress.mScope = (deviceType == ma_device_type_playback) ? kAudioObjectPropertyScopeOutput : kAudioObjectPropertyScopeInput; propAddress.mElement = kAudioObjectPropertyElementMaster; AudioValueRange bufferSizeRange; UInt32 dataSize = sizeof(bufferSizeRange); - OSStatus status = ((mal_AudioObjectGetPropertyData_proc)pContext->coreaudio.AudioObjectGetPropertyData)(deviceObjectID, &propAddress, 0, NULL, &dataSize, &bufferSizeRange); + OSStatus status = ((ma_AudioObjectGetPropertyData_proc)pContext->coreaudio.AudioObjectGetPropertyData)(deviceObjectID, &propAddress, 0, NULL, &dataSize, &bufferSizeRange); if (status != noErr) { - return mal_result_from_OSStatus(status); + return ma_result_from_OSStatus(status); } // This is just a clamp. if (bufferSizeInFramesIn < bufferSizeRange.mMinimum) { - *pBufferSizeInFramesOut = (mal_uint32)bufferSizeRange.mMinimum; + *pBufferSizeInFramesOut = (ma_uint32)bufferSizeRange.mMinimum; } else if (bufferSizeInFramesIn > bufferSizeRange.mMaximum) { - *pBufferSizeInFramesOut = (mal_uint32)bufferSizeRange.mMaximum; + *pBufferSizeInFramesOut = (ma_uint32)bufferSizeRange.mMaximum; } else { *pBufferSizeInFramesOut = bufferSizeInFramesIn; } @@ -16399,12 +16399,12 @@ mal_result mal_get_AudioObject_closest_buffer_size_in_frames(mal_context* pConte return MA_SUCCESS; } -mal_result mal_set_AudioObject_buffer_size_in_frames(mal_context* pContext, AudioObjectID deviceObjectID, mal_device_type deviceType, mal_uint32* pBufferSizeInOut) +ma_result ma_set_AudioObject_buffer_size_in_frames(ma_context* pContext, AudioObjectID deviceObjectID, ma_device_type deviceType, ma_uint32* pBufferSizeInOut) { - mal_assert(pContext != NULL); + ma_assert(pContext != NULL); - mal_uint32 chosenBufferSizeInFrames; - mal_result result = mal_get_AudioObject_closest_buffer_size_in_frames(pContext, deviceObjectID, deviceType, *pBufferSizeInOut, &chosenBufferSizeInFrames); + ma_uint32 chosenBufferSizeInFrames; + ma_result result = ma_get_AudioObject_closest_buffer_size_in_frames(pContext, deviceObjectID, deviceType, *pBufferSizeInOut, &chosenBufferSizeInFrames); if (result != MA_SUCCESS) { return result; } @@ -16412,16 +16412,16 @@ mal_result mal_set_AudioObject_buffer_size_in_frames(mal_context* pContext, Audi // Try setting the size of the buffer... If this fails we just use whatever is currently set. AudioObjectPropertyAddress propAddress; propAddress.mSelector = kAudioDevicePropertyBufferFrameSize; - propAddress.mScope = (deviceType == mal_device_type_playback) ? kAudioObjectPropertyScopeOutput : kAudioObjectPropertyScopeInput; + propAddress.mScope = (deviceType == ma_device_type_playback) ? kAudioObjectPropertyScopeOutput : kAudioObjectPropertyScopeInput; propAddress.mElement = kAudioObjectPropertyElementMaster; - ((mal_AudioObjectSetPropertyData_proc)pContext->coreaudio.AudioObjectSetPropertyData)(deviceObjectID, &propAddress, 0, NULL, sizeof(chosenBufferSizeInFrames), &chosenBufferSizeInFrames); + ((ma_AudioObjectSetPropertyData_proc)pContext->coreaudio.AudioObjectSetPropertyData)(deviceObjectID, &propAddress, 0, NULL, sizeof(chosenBufferSizeInFrames), &chosenBufferSizeInFrames); // Get the actual size of the buffer. UInt32 dataSize = sizeof(*pBufferSizeInOut); - OSStatus status = ((mal_AudioObjectGetPropertyData_proc)pContext->coreaudio.AudioObjectGetPropertyData)(deviceObjectID, &propAddress, 0, NULL, &dataSize, &chosenBufferSizeInFrames); + OSStatus status = ((ma_AudioObjectGetPropertyData_proc)pContext->coreaudio.AudioObjectGetPropertyData)(deviceObjectID, &propAddress, 0, NULL, &dataSize, &chosenBufferSizeInFrames); if (status != noErr) { - return mal_result_from_OSStatus(status); + return ma_result_from_OSStatus(status); } *pBufferSizeInOut = chosenBufferSizeInFrames; @@ -16429,10 +16429,10 @@ mal_result mal_set_AudioObject_buffer_size_in_frames(mal_context* pContext, Audi } -mal_result mal_find_AudioObjectID(mal_context* pContext, mal_device_type deviceType, const mal_device_id* pDeviceID, AudioObjectID* pDeviceObjectID) +ma_result ma_find_AudioObjectID(ma_context* pContext, ma_device_type deviceType, const ma_device_id* pDeviceID, AudioObjectID* pDeviceObjectID) { - mal_assert(pContext != NULL); - mal_assert(pDeviceObjectID != NULL); + ma_assert(pContext != NULL); + ma_assert(pDeviceObjectID != NULL); // Safety. *pDeviceObjectID = 0; @@ -16442,7 +16442,7 @@ mal_result mal_find_AudioObjectID(mal_context* pContext, mal_device_type deviceT AudioObjectPropertyAddress propAddressDefaultDevice; propAddressDefaultDevice.mScope = kAudioObjectPropertyScopeGlobal; propAddressDefaultDevice.mElement = kAudioObjectPropertyElementMaster; - if (deviceType == mal_device_type_playback) { + if (deviceType == ma_device_type_playback) { propAddressDefaultDevice.mSelector = kAudioHardwarePropertyDefaultOutputDevice; } else { propAddressDefaultDevice.mSelector = kAudioHardwarePropertyDefaultInputDevice; @@ -16450,7 +16450,7 @@ mal_result mal_find_AudioObjectID(mal_context* pContext, mal_device_type deviceT UInt32 defaultDeviceObjectIDSize = sizeof(AudioObjectID); AudioObjectID defaultDeviceObjectID; - OSStatus status = ((mal_AudioObjectGetPropertyData_proc)pContext->coreaudio.AudioObjectGetPropertyData)(kAudioObjectSystemObject, &propAddressDefaultDevice, 0, NULL, &defaultDeviceObjectIDSize, &defaultDeviceObjectID); + OSStatus status = ((ma_AudioObjectGetPropertyData_proc)pContext->coreaudio.AudioObjectGetPropertyData)(kAudioObjectSystemObject, &propAddressDefaultDevice, 0, NULL, &defaultDeviceObjectIDSize, &defaultDeviceObjectID); if (status == noErr) { *pDeviceObjectID = defaultDeviceObjectID; return MA_SUCCESS; @@ -16459,7 +16459,7 @@ mal_result mal_find_AudioObjectID(mal_context* pContext, mal_device_type deviceT // Explicit device. UInt32 deviceCount; AudioObjectID* pDeviceObjectIDs; - mal_result result = mal_get_device_object_ids__coreaudio(pContext, &deviceCount, &pDeviceObjectIDs); + ma_result result = ma_get_device_object_ids__coreaudio(pContext, &deviceCount, &pDeviceObjectIDs); if (result != MA_SUCCESS) { return result; } @@ -16468,19 +16468,19 @@ mal_result mal_find_AudioObjectID(mal_context* pContext, mal_device_type deviceT AudioObjectID deviceObjectID = pDeviceObjectIDs[iDevice]; char uid[256]; - if (mal_get_AudioObject_uid(pContext, deviceObjectID, sizeof(uid), uid) != MA_SUCCESS) { + if (ma_get_AudioObject_uid(pContext, deviceObjectID, sizeof(uid), uid) != MA_SUCCESS) { continue; } - if (deviceType == mal_device_type_playback) { - if (mal_does_AudioObject_support_playback(pContext, deviceObjectID)) { + if (deviceType == ma_device_type_playback) { + if (ma_does_AudioObject_support_playback(pContext, deviceObjectID)) { if (strcmp(uid, pDeviceID->coreaudio) == 0) { *pDeviceObjectID = deviceObjectID; return MA_SUCCESS; } } } else { - if (mal_does_AudioObject_support_capture(pContext, deviceObjectID)) { + if (ma_does_AudioObject_support_capture(pContext, deviceObjectID)) { if (strcmp(uid, pDeviceID->coreaudio) == 0) { *pDeviceObjectID = deviceObjectID; return MA_SUCCESS; @@ -16495,25 +16495,25 @@ mal_result mal_find_AudioObjectID(mal_context* pContext, mal_device_type deviceT } -mal_result mal_find_best_format__coreaudio(mal_context* pContext, AudioObjectID deviceObjectID, mal_device_type deviceType, mal_format format, mal_uint32 channels, mal_uint32 sampleRate, mal_bool32 usingDefaultFormat, mal_bool32 usingDefaultChannels, mal_bool32 usingDefaultSampleRate, AudioStreamBasicDescription* pFormat) +ma_result ma_find_best_format__coreaudio(ma_context* pContext, AudioObjectID deviceObjectID, ma_device_type deviceType, ma_format format, ma_uint32 channels, ma_uint32 sampleRate, ma_bool32 usingDefaultFormat, ma_bool32 usingDefaultChannels, ma_bool32 usingDefaultSampleRate, AudioStreamBasicDescription* pFormat) { UInt32 deviceFormatDescriptionCount; AudioStreamRangedDescription* pDeviceFormatDescriptions; - mal_result result = mal_get_AudioObject_stream_descriptions(pContext, deviceObjectID, deviceType, &deviceFormatDescriptionCount, &pDeviceFormatDescriptions); + ma_result result = ma_get_AudioObject_stream_descriptions(pContext, deviceObjectID, deviceType, &deviceFormatDescriptionCount, &pDeviceFormatDescriptions); if (result != MA_SUCCESS) { return result; } - mal_uint32 desiredSampleRate = sampleRate; + ma_uint32 desiredSampleRate = sampleRate; if (usingDefaultSampleRate) { // When using the device's default sample rate, we get the highest priority standard rate supported by the device. Otherwise // we just use the pre-set rate. - for (mal_uint32 iStandardRate = 0; iStandardRate < mal_countof(g_malStandardSampleRatePriorities); ++iStandardRate) { - mal_uint32 standardRate = g_malStandardSampleRatePriorities[iStandardRate]; + for (ma_uint32 iStandardRate = 0; iStandardRate < ma_countof(g_malStandardSampleRatePriorities); ++iStandardRate) { + ma_uint32 standardRate = g_malStandardSampleRatePriorities[iStandardRate]; - mal_bool32 foundRate = MA_FALSE; + ma_bool32 foundRate = MA_FALSE; for (UInt32 iDeviceRate = 0; iDeviceRate < deviceFormatDescriptionCount; ++iDeviceRate) { - mal_uint32 deviceRate = (mal_uint32)pDeviceFormatDescriptions[iDeviceRate].mFormat.mSampleRate; + ma_uint32 deviceRate = (ma_uint32)pDeviceFormatDescriptions[iDeviceRate].mFormat.mSampleRate; if (deviceRate == standardRate) { desiredSampleRate = standardRate; @@ -16528,12 +16528,12 @@ mal_result mal_find_best_format__coreaudio(mal_context* pContext, AudioObjectID } } - mal_uint32 desiredChannelCount = channels; + ma_uint32 desiredChannelCount = channels; if (usingDefaultChannels) { - mal_get_AudioObject_channel_count(pContext, deviceObjectID, deviceType, &desiredChannelCount); // <-- Not critical if this fails. + ma_get_AudioObject_channel_count(pContext, deviceObjectID, deviceType, &desiredChannelCount); // <-- Not critical if this fails. } - mal_format desiredFormat = format; + ma_format desiredFormat = format; if (usingDefaultFormat) { desiredFormat = g_malFormatPriorities[0]; } @@ -16541,13 +16541,13 @@ mal_result mal_find_best_format__coreaudio(mal_context* pContext, AudioObjectID // If we get here it means we don't have an exact match to what the client is asking for. We'll need to find the closest one. The next // loop will check for formats that have the same sample rate to what we're asking for. If there is, we prefer that one in all cases. AudioStreamBasicDescription bestDeviceFormatSoFar; - mal_zero_object(&bestDeviceFormatSoFar); + ma_zero_object(&bestDeviceFormatSoFar); - mal_bool32 hasSupportedFormat = MA_FALSE; + ma_bool32 hasSupportedFormat = MA_FALSE; for (UInt32 iFormat = 0; iFormat < deviceFormatDescriptionCount; ++iFormat) { - mal_format format; - mal_result formatResult = mal_format_from_AudioStreamBasicDescription(&pDeviceFormatDescriptions[iFormat].mFormat, &format); - if (formatResult == MA_SUCCESS && format != mal_format_unknown) { + ma_format format; + ma_result formatResult = ma_format_from_AudioStreamBasicDescription(&pDeviceFormatDescriptions[iFormat].mFormat, &format); + if (formatResult == MA_SUCCESS && format != ma_format_unknown) { hasSupportedFormat = MA_TRUE; bestDeviceFormatSoFar = pDeviceFormatDescriptions[iFormat].mFormat; break; @@ -16563,14 +16563,14 @@ mal_result mal_find_best_format__coreaudio(mal_context* pContext, AudioObjectID AudioStreamBasicDescription thisDeviceFormat = pDeviceFormatDescriptions[iFormat].mFormat; // If the format is not supported by miniaudio we need to skip this one entirely. - mal_format thisSampleFormat; - mal_result formatResult = mal_format_from_AudioStreamBasicDescription(&pDeviceFormatDescriptions[iFormat].mFormat, &thisSampleFormat); - if (formatResult != MA_SUCCESS || thisSampleFormat == mal_format_unknown) { + ma_format thisSampleFormat; + ma_result formatResult = ma_format_from_AudioStreamBasicDescription(&pDeviceFormatDescriptions[iFormat].mFormat, &thisSampleFormat); + if (formatResult != MA_SUCCESS || thisSampleFormat == ma_format_unknown) { continue; // The format is not supported by miniaudio. Skip. } - mal_format bestSampleFormatSoFar; - mal_format_from_AudioStreamBasicDescription(&bestDeviceFormatSoFar, &bestSampleFormatSoFar); + ma_format bestSampleFormatSoFar; + ma_format_from_AudioStreamBasicDescription(&bestDeviceFormatSoFar, &bestSampleFormatSoFar); // Getting here means the format is supported by miniaudio which makes this format a candidate. @@ -16588,7 +16588,7 @@ mal_result mal_find_best_format__coreaudio(mal_context* pContext, AudioObjectID } else { // Both this format and the best so far have different sample rates and different channel counts. Whichever has the // best format is the new best. - if (mal_get_format_priority_index(thisSampleFormat) < mal_get_format_priority_index(bestSampleFormatSoFar)) { + if (ma_get_format_priority_index(thisSampleFormat) < ma_get_format_priority_index(bestSampleFormatSoFar)) { bestDeviceFormatSoFar = thisDeviceFormat; continue; } else { @@ -16599,7 +16599,7 @@ mal_result mal_find_best_format__coreaudio(mal_context* pContext, AudioObjectID // This format has a different sample rate but the desired channel count. if (bestDeviceFormatSoFar.mChannelsPerFrame == desiredChannelCount) { // Both this format and the best so far have the desired channel count. Whichever has the best format is the new best. - if (mal_get_format_priority_index(thisSampleFormat) < mal_get_format_priority_index(bestSampleFormatSoFar)) { + if (ma_get_format_priority_index(thisSampleFormat) < ma_get_format_priority_index(bestSampleFormatSoFar)) { bestDeviceFormatSoFar = thisDeviceFormat; continue; } else { @@ -16633,7 +16633,7 @@ mal_result mal_find_best_format__coreaudio(mal_context* pContext, AudioObjectID break; // Found the exact match. } else { // The formats are different. The new best format is the one with the highest priority format according to miniaudio. - if (mal_get_format_priority_index(thisSampleFormat) < mal_get_format_priority_index(bestSampleFormatSoFar)) { + if (ma_get_format_priority_index(thisSampleFormat) < ma_get_format_priority_index(bestSampleFormatSoFar)) { bestDeviceFormatSoFar = thisDeviceFormat; continue; } else { @@ -16650,7 +16650,7 @@ mal_result mal_find_best_format__coreaudio(mal_context* pContext, AudioObjectID // This is the case where both have the same sample rate (good) but different channel counts. Right now both have about // the same priority, but we need to compare the format now. if (thisSampleFormat == bestSampleFormatSoFar) { - if (mal_get_format_priority_index(thisSampleFormat) < mal_get_format_priority_index(bestSampleFormatSoFar)) { + if (ma_get_format_priority_index(thisSampleFormat) < ma_get_format_priority_index(bestSampleFormatSoFar)) { bestDeviceFormatSoFar = thisDeviceFormat; continue; } else { @@ -16668,13 +16668,13 @@ mal_result mal_find_best_format__coreaudio(mal_context* pContext, AudioObjectID } #endif -mal_result mal_get_AudioUnit_channel_map(mal_context* pContext, AudioUnit audioUnit, mal_device_type deviceType, mal_channel channelMap[MA_MAX_CHANNELS]) +ma_result ma_get_AudioUnit_channel_map(ma_context* pContext, AudioUnit audioUnit, ma_device_type deviceType, ma_channel channelMap[MA_MAX_CHANNELS]) { - mal_assert(pContext != NULL); + ma_assert(pContext != NULL); AudioUnitScope deviceScope; AudioUnitElement deviceBus; - if (deviceType == mal_device_type_playback) { + if (deviceType == ma_device_type_playback) { deviceScope = kAudioUnitScope_Output; deviceBus = MA_COREAUDIO_OUTPUT_BUS; } else { @@ -16683,51 +16683,51 @@ mal_result mal_get_AudioUnit_channel_map(mal_context* pContext, AudioUnit audioU } UInt32 channelLayoutSize; - OSStatus status = ((mal_AudioUnitGetPropertyInfo_proc)pContext->coreaudio.AudioUnitGetPropertyInfo)(audioUnit, kAudioUnitProperty_AudioChannelLayout, deviceScope, deviceBus, &channelLayoutSize, NULL); + OSStatus status = ((ma_AudioUnitGetPropertyInfo_proc)pContext->coreaudio.AudioUnitGetPropertyInfo)(audioUnit, kAudioUnitProperty_AudioChannelLayout, deviceScope, deviceBus, &channelLayoutSize, NULL); if (status != noErr) { - return mal_result_from_OSStatus(status); + return ma_result_from_OSStatus(status); } - AudioChannelLayout* pChannelLayout = (AudioChannelLayout*)mal_malloc(channelLayoutSize); + AudioChannelLayout* pChannelLayout = (AudioChannelLayout*)ma_malloc(channelLayoutSize); if (pChannelLayout == NULL) { return MA_OUT_OF_MEMORY; } - status = ((mal_AudioUnitGetProperty_proc)pContext->coreaudio.AudioUnitGetProperty)(audioUnit, kAudioUnitProperty_AudioChannelLayout, deviceScope, deviceBus, pChannelLayout, &channelLayoutSize); + status = ((ma_AudioUnitGetProperty_proc)pContext->coreaudio.AudioUnitGetProperty)(audioUnit, kAudioUnitProperty_AudioChannelLayout, deviceScope, deviceBus, pChannelLayout, &channelLayoutSize); if (status != noErr) { - mal_free(pChannelLayout); - return mal_result_from_OSStatus(status); + ma_free(pChannelLayout); + return ma_result_from_OSStatus(status); } - mal_result result = mal_get_channel_map_from_AudioChannelLayout(pChannelLayout, channelMap); + ma_result result = ma_get_channel_map_from_AudioChannelLayout(pChannelLayout, channelMap); if (result != MA_SUCCESS) { - mal_free(pChannelLayout); + ma_free(pChannelLayout); return result; } - mal_free(pChannelLayout); + ma_free(pChannelLayout); return MA_SUCCESS; } -mal_bool32 mal_context_is_device_id_equal__coreaudio(mal_context* pContext, const mal_device_id* pID0, const mal_device_id* pID1) +ma_bool32 ma_context_is_device_id_equal__coreaudio(ma_context* pContext, const ma_device_id* pID0, const ma_device_id* pID1) { - mal_assert(pContext != NULL); - mal_assert(pID0 != NULL); - mal_assert(pID1 != NULL); + ma_assert(pContext != NULL); + ma_assert(pID0 != NULL); + ma_assert(pID1 != NULL); (void)pContext; return strcmp(pID0->coreaudio, pID1->coreaudio) == 0; } -mal_result mal_context_enumerate_devices__coreaudio(mal_context* pContext, mal_enum_devices_callback_proc callback, void* pUserData) +ma_result ma_context_enumerate_devices__coreaudio(ma_context* pContext, ma_enum_devices_callback_proc callback, void* pUserData) { - mal_assert(pContext != NULL); - mal_assert(callback != NULL); + ma_assert(pContext != NULL); + ma_assert(callback != NULL); #if defined(MA_APPLE_DESKTOP) UInt32 deviceCount; AudioObjectID* pDeviceObjectIDs; - mal_result result = mal_get_device_object_ids__coreaudio(pContext, &deviceCount, &pDeviceObjectIDs); + ma_result result = ma_get_device_object_ids__coreaudio(pContext, &deviceCount, &pDeviceObjectIDs); if (result != MA_SUCCESS) { return result; } @@ -16735,41 +16735,41 @@ mal_result mal_context_enumerate_devices__coreaudio(mal_context* pContext, mal_e for (UInt32 iDevice = 0; iDevice < deviceCount; ++iDevice) { AudioObjectID deviceObjectID = pDeviceObjectIDs[iDevice]; - mal_device_info info; - mal_zero_object(&info); - if (mal_get_AudioObject_uid(pContext, deviceObjectID, sizeof(info.id.coreaudio), info.id.coreaudio) != MA_SUCCESS) { + ma_device_info info; + ma_zero_object(&info); + if (ma_get_AudioObject_uid(pContext, deviceObjectID, sizeof(info.id.coreaudio), info.id.coreaudio) != MA_SUCCESS) { continue; } - if (mal_get_AudioObject_name(pContext, deviceObjectID, sizeof(info.name), info.name) != MA_SUCCESS) { + if (ma_get_AudioObject_name(pContext, deviceObjectID, sizeof(info.name), info.name) != MA_SUCCESS) { continue; } - if (mal_does_AudioObject_support_playback(pContext, deviceObjectID)) { - if (!callback(pContext, mal_device_type_playback, &info, pUserData)) { + if (ma_does_AudioObject_support_playback(pContext, deviceObjectID)) { + if (!callback(pContext, ma_device_type_playback, &info, pUserData)) { break; } } - if (mal_does_AudioObject_support_capture(pContext, deviceObjectID)) { - if (!callback(pContext, mal_device_type_capture, &info, pUserData)) { + if (ma_does_AudioObject_support_capture(pContext, deviceObjectID)) { + if (!callback(pContext, ma_device_type_capture, &info, pUserData)) { break; } } } - mal_free(pDeviceObjectIDs); + ma_free(pDeviceObjectIDs); #else // Only supporting default devices on non-Desktop platforms. - mal_device_info info; + ma_device_info info; - mal_zero_object(&info); - mal_strncpy_s(info.name, sizeof(info.name), MA_DEFAULT_PLAYBACK_DEVICE_NAME, (size_t)-1); - if (!callback(pContext, mal_device_type_playback, &info, pUserData)) { + ma_zero_object(&info); + ma_strncpy_s(info.name, sizeof(info.name), MA_DEFAULT_PLAYBACK_DEVICE_NAME, (size_t)-1); + if (!callback(pContext, ma_device_type_playback, &info, pUserData)) { return MA_SUCCESS; } - mal_zero_object(&info); - mal_strncpy_s(info.name, sizeof(info.name), MA_DEFAULT_CAPTURE_DEVICE_NAME, (size_t)-1); - if (!callback(pContext, mal_device_type_capture, &info, pUserData)) { + ma_zero_object(&info); + ma_strncpy_s(info.name, sizeof(info.name), MA_DEFAULT_CAPTURE_DEVICE_NAME, (size_t)-1); + if (!callback(pContext, ma_device_type_capture, &info, pUserData)) { return MA_SUCCESS; } #endif @@ -16777,13 +16777,13 @@ mal_result mal_context_enumerate_devices__coreaudio(mal_context* pContext, mal_e return MA_SUCCESS; } -mal_result mal_context_get_device_info__coreaudio(mal_context* pContext, mal_device_type deviceType, const mal_device_id* pDeviceID, mal_share_mode shareMode, mal_device_info* pDeviceInfo) +ma_result ma_context_get_device_info__coreaudio(ma_context* pContext, ma_device_type deviceType, const ma_device_id* pDeviceID, ma_share_mode shareMode, ma_device_info* pDeviceInfo) { - mal_assert(pContext != NULL); + ma_assert(pContext != NULL); (void)pDeviceInfo; /* No exclusive mode with the Core Audio backend for now. */ - if (shareMode == mal_share_mode_exclusive) { + if (shareMode == ma_share_mode_exclusive) { return MA_SHARE_MODE_NOT_SUPPORTED; } @@ -16791,17 +16791,17 @@ mal_result mal_context_get_device_info__coreaudio(mal_context* pContext, mal_dev // Desktop // ======= AudioObjectID deviceObjectID; - mal_result result = mal_find_AudioObjectID(pContext, deviceType, pDeviceID, &deviceObjectID); + ma_result result = ma_find_AudioObjectID(pContext, deviceType, pDeviceID, &deviceObjectID); if (result != MA_SUCCESS) { return result; } - result = mal_get_AudioObject_uid(pContext, deviceObjectID, sizeof(pDeviceInfo->id.coreaudio), pDeviceInfo->id.coreaudio); + result = ma_get_AudioObject_uid(pContext, deviceObjectID, sizeof(pDeviceInfo->id.coreaudio), pDeviceInfo->id.coreaudio); if (result != MA_SUCCESS) { return result; } - result = mal_get_AudioObject_name(pContext, deviceObjectID, sizeof(pDeviceInfo->name), pDeviceInfo->name); + result = ma_get_AudioObject_name(pContext, deviceObjectID, sizeof(pDeviceInfo->name), pDeviceInfo->name); if (result != MA_SUCCESS) { return result; } @@ -16809,23 +16809,23 @@ mal_result mal_context_get_device_info__coreaudio(mal_context* pContext, mal_dev // Formats. UInt32 streamDescriptionCount; AudioStreamRangedDescription* pStreamDescriptions; - result = mal_get_AudioObject_stream_descriptions(pContext, deviceObjectID, deviceType, &streamDescriptionCount, &pStreamDescriptions); + result = ma_get_AudioObject_stream_descriptions(pContext, deviceObjectID, deviceType, &streamDescriptionCount, &pStreamDescriptions); if (result != MA_SUCCESS) { return result; } for (UInt32 iStreamDescription = 0; iStreamDescription < streamDescriptionCount; ++iStreamDescription) { - mal_format format; - result = mal_format_from_AudioStreamBasicDescription(&pStreamDescriptions[iStreamDescription].mFormat, &format); + ma_format format; + result = ma_format_from_AudioStreamBasicDescription(&pStreamDescriptions[iStreamDescription].mFormat, &format); if (result != MA_SUCCESS) { continue; } - mal_assert(format != mal_format_unknown); + ma_assert(format != ma_format_unknown); // Make sure the format isn't already in the output list. - mal_bool32 exists = MA_FALSE; - for (mal_uint32 iOutputFormat = 0; iOutputFormat < pDeviceInfo->formatCount; ++iOutputFormat) { + ma_bool32 exists = MA_FALSE; + for (ma_uint32 iOutputFormat = 0; iOutputFormat < pDeviceInfo->formatCount; ++iOutputFormat) { if (pDeviceInfo->formats[iOutputFormat] == format) { exists = MA_TRUE; break; @@ -16837,11 +16837,11 @@ mal_result mal_context_get_device_info__coreaudio(mal_context* pContext, mal_dev } } - mal_free(pStreamDescriptions); + ma_free(pStreamDescriptions); // Channels. - result = mal_get_AudioObject_channel_count(pContext, deviceObjectID, deviceType, &pDeviceInfo->minChannels); + result = ma_get_AudioObject_channel_count(pContext, deviceObjectID, deviceType, &pDeviceInfo->minChannels); if (result != MA_SUCCESS) { return result; } @@ -16851,7 +16851,7 @@ mal_result mal_context_get_device_info__coreaudio(mal_context* pContext, mal_dev // Sample rates. UInt32 sampleRateRangeCount; AudioValueRange* pSampleRateRanges; - result = mal_get_AudioObject_sample_rates(pContext, deviceObjectID, deviceType, &sampleRateRangeCount, &pSampleRateRanges); + result = ma_get_AudioObject_sample_rates(pContext, deviceObjectID, deviceType, &sampleRateRangeCount, &pSampleRateRanges); if (result != MA_SUCCESS) { return result; } @@ -16871,10 +16871,10 @@ mal_result mal_context_get_device_info__coreaudio(mal_context* pContext, mal_dev #else // Mobile // ====== - if (deviceType == mal_device_type_playback) { - mal_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), MA_DEFAULT_PLAYBACK_DEVICE_NAME, (size_t)-1); + if (deviceType == ma_device_type_playback) { + ma_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), MA_DEFAULT_PLAYBACK_DEVICE_NAME, (size_t)-1); } else { - mal_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), MA_DEFAULT_CAPTURE_DEVICE_NAME, (size_t)-1); + ma_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), MA_DEFAULT_CAPTURE_DEVICE_NAME, (size_t)-1); } // Retrieving device information is more annoying on mobile than desktop. For simplicity I'm locking this down to whatever format is @@ -16887,29 +16887,29 @@ mal_result mal_context_get_device_info__coreaudio(mal_context* pContext, mal_dev desc.componentFlags = 0; desc.componentFlagsMask = 0; - AudioComponent component = ((mal_AudioComponentFindNext_proc)pContext->coreaudio.AudioComponentFindNext)(NULL, &desc); + AudioComponent component = ((ma_AudioComponentFindNext_proc)pContext->coreaudio.AudioComponentFindNext)(NULL, &desc); if (component == NULL) { return MA_FAILED_TO_INIT_BACKEND; } AudioUnit audioUnit; - OSStatus status = ((mal_AudioComponentInstanceNew_proc)pContext->coreaudio.AudioComponentInstanceNew)(component, &audioUnit); + OSStatus status = ((ma_AudioComponentInstanceNew_proc)pContext->coreaudio.AudioComponentInstanceNew)(component, &audioUnit); if (status != noErr) { - return mal_result_from_OSStatus(status); + return ma_result_from_OSStatus(status); } - AudioUnitScope formatScope = (deviceType == mal_device_type_playback) ? kAudioUnitScope_Input : kAudioUnitScope_Output; - AudioUnitElement formatElement = (deviceType == mal_device_type_playback) ? MA_COREAUDIO_OUTPUT_BUS : MA_COREAUDIO_INPUT_BUS; + AudioUnitScope formatScope = (deviceType == ma_device_type_playback) ? kAudioUnitScope_Input : kAudioUnitScope_Output; + AudioUnitElement formatElement = (deviceType == ma_device_type_playback) ? MA_COREAUDIO_OUTPUT_BUS : MA_COREAUDIO_INPUT_BUS; AudioStreamBasicDescription bestFormat; UInt32 propSize = sizeof(bestFormat); - status = ((mal_AudioUnitGetProperty_proc)pContext->coreaudio.AudioUnitGetProperty)(audioUnit, kAudioUnitProperty_StreamFormat, formatScope, formatElement, &bestFormat, &propSize); + status = ((ma_AudioUnitGetProperty_proc)pContext->coreaudio.AudioUnitGetProperty)(audioUnit, kAudioUnitProperty_StreamFormat, formatScope, formatElement, &bestFormat, &propSize); if (status != noErr) { - ((mal_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(audioUnit); - return mal_result_from_OSStatus(status); + ((ma_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(audioUnit); + return ma_result_from_OSStatus(status); } - ((mal_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(audioUnit); + ((ma_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(audioUnit); audioUnit = NULL; @@ -16917,7 +16917,7 @@ mal_result mal_context_get_device_info__coreaudio(mal_context* pContext, mal_dev pDeviceInfo->maxChannels = bestFormat.mChannelsPerFrame; pDeviceInfo->formatCount = 1; - mal_result result = mal_format_from_AudioStreamBasicDescription(&bestFormat, &pDeviceInfo->formats[0]); + ma_result result = ma_format_from_AudioStreamBasicDescription(&bestFormat, &pDeviceInfo->formats[0]); if (result != MA_SUCCESS) { return result; } @@ -16926,9 +16926,9 @@ mal_result mal_context_get_device_info__coreaudio(mal_context* pContext, mal_dev // this we just get the shared instance and inspect. @autoreleasepool { AVAudioSession* pAudioSession = [AVAudioSession sharedInstance]; - mal_assert(pAudioSession != NULL); + ma_assert(pAudioSession != NULL); - pDeviceInfo->minSampleRate = (mal_uint32)pAudioSession.sampleRate; + pDeviceInfo->minSampleRate = (ma_uint32)pAudioSession.sampleRate; pDeviceInfo->maxSampleRate = pDeviceInfo->minSampleRate; } #endif @@ -16937,36 +16937,36 @@ mal_result mal_context_get_device_info__coreaudio(mal_context* pContext, mal_dev } -void mal_device_uninit__coreaudio(mal_device* pDevice) +void ma_device_uninit__coreaudio(ma_device* pDevice) { - mal_assert(pDevice != NULL); - mal_assert(mal_device__get_state(pDevice) == MA_STATE_UNINITIALIZED); + ma_assert(pDevice != NULL); + ma_assert(ma_device__get_state(pDevice) == MA_STATE_UNINITIALIZED); if (pDevice->coreaudio.audioUnitCapture != NULL) { - ((mal_AudioComponentInstanceDispose_proc)pDevice->pContext->coreaudio.AudioComponentInstanceDispose)((AudioUnit)pDevice->coreaudio.audioUnitCapture); + ((ma_AudioComponentInstanceDispose_proc)pDevice->pContext->coreaudio.AudioComponentInstanceDispose)((AudioUnit)pDevice->coreaudio.audioUnitCapture); } if (pDevice->coreaudio.audioUnitPlayback != NULL) { - ((mal_AudioComponentInstanceDispose_proc)pDevice->pContext->coreaudio.AudioComponentInstanceDispose)((AudioUnit)pDevice->coreaudio.audioUnitPlayback); + ((ma_AudioComponentInstanceDispose_proc)pDevice->pContext->coreaudio.AudioComponentInstanceDispose)((AudioUnit)pDevice->coreaudio.audioUnitPlayback); } if (pDevice->coreaudio.pAudioBufferList) { - mal_free(pDevice->coreaudio.pAudioBufferList); + ma_free(pDevice->coreaudio.pAudioBufferList); } - if (pDevice->type == mal_device_type_duplex) { - mal_pcm_rb_uninit(&pDevice->coreaudio.duplexRB); + if (pDevice->type == ma_device_type_duplex) { + ma_pcm_rb_uninit(&pDevice->coreaudio.duplexRB); } } -OSStatus mal_on_output__coreaudio(void* pUserData, AudioUnitRenderActionFlags* pActionFlags, const AudioTimeStamp* pTimeStamp, UInt32 busNumber, UInt32 frameCount, AudioBufferList* pBufferList) +OSStatus ma_on_output__coreaudio(void* pUserData, AudioUnitRenderActionFlags* pActionFlags, const AudioTimeStamp* pTimeStamp, UInt32 busNumber, UInt32 frameCount, AudioBufferList* pBufferList) { (void)pActionFlags; (void)pTimeStamp; (void)busNumber; - mal_device* pDevice = (mal_device*)pUserData; - mal_assert(pDevice != NULL); + ma_device* pDevice = (ma_device*)pUserData; + ma_assert(pDevice != NULL); #if defined(MA_DEBUG_OUTPUT) printf("INFO: Output Callback: busNumber=%d, frameCount=%d, mNumberBuffers=%d\n", busNumber, frameCount, pBufferList->mNumberBuffers); @@ -16974,21 +16974,21 @@ OSStatus mal_on_output__coreaudio(void* pUserData, AudioUnitRenderActionFlags* p // We need to check whether or not we are outputting interleaved or non-interleaved samples. The // way we do this is slightly different for each type. - mal_stream_layout layout = mal_stream_layout_interleaved; + ma_stream_layout layout = ma_stream_layout_interleaved; if (pBufferList->mBuffers[0].mNumberChannels != pDevice->playback.internalChannels) { - layout = mal_stream_layout_deinterleaved; + layout = ma_stream_layout_deinterleaved; } - if (layout == mal_stream_layout_interleaved) { + if (layout == ma_stream_layout_interleaved) { // For now we can assume everything is interleaved. for (UInt32 iBuffer = 0; iBuffer < pBufferList->mNumberBuffers; ++iBuffer) { if (pBufferList->mBuffers[iBuffer].mNumberChannels == pDevice->playback.internalChannels) { - mal_uint32 frameCountForThisBuffer = pBufferList->mBuffers[iBuffer].mDataByteSize / mal_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels); + ma_uint32 frameCountForThisBuffer = pBufferList->mBuffers[iBuffer].mDataByteSize / ma_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels); if (frameCountForThisBuffer > 0) { - if (pDevice->type == mal_device_type_duplex) { - mal_device__handle_duplex_callback_playback(pDevice, frameCountForThisBuffer, pBufferList->mBuffers[iBuffer].mData, &pDevice->coreaudio.duplexRB); + if (pDevice->type == ma_device_type_duplex) { + ma_device__handle_duplex_callback_playback(pDevice, frameCountForThisBuffer, pBufferList->mBuffers[iBuffer].mData, &pDevice->coreaudio.duplexRB); } else { - mal_device__read_frames_from_client(pDevice, frameCountForThisBuffer, pBufferList->mBuffers[iBuffer].mData); + ma_device__read_frames_from_client(pDevice, frameCountForThisBuffer, pBufferList->mBuffers[iBuffer].mData); } } @@ -16999,7 +16999,7 @@ OSStatus mal_on_output__coreaudio(void* pUserData, AudioUnitRenderActionFlags* p // This case is where the number of channels in the output buffer do not match our internal channels. It could mean that it's // not interleaved, in which case we can't handle right now since miniaudio does not yet support non-interleaved streams. We just // output silence here. - mal_zero_memory(pBufferList->mBuffers[iBuffer].mData, pBufferList->mBuffers[iBuffer].mDataByteSize); + ma_zero_memory(pBufferList->mBuffers[iBuffer].mData, pBufferList->mBuffers[iBuffer].mDataByteSize); #if defined(MA_DEBUG_OUTPUT) printf(" WARNING: Outputting silence. frameCount=%d, mNumberChannels=%d, mDataByteSize=%d\n", frameCount, pBufferList->mBuffers[iBuffer].mNumberChannels, pBufferList->mBuffers[iBuffer].mDataByteSize); @@ -17009,29 +17009,29 @@ OSStatus mal_on_output__coreaudio(void* pUserData, AudioUnitRenderActionFlags* p } else { // This is the deinterleaved case. We need to update each buffer in groups of internalChannels. This // assumes each buffer is the same size. - mal_uint8 tempBuffer[4096]; + ma_uint8 tempBuffer[4096]; for (UInt32 iBuffer = 0; iBuffer < pBufferList->mNumberBuffers; iBuffer += pDevice->playback.internalChannels) { - mal_uint32 frameCountPerBuffer = pBufferList->mBuffers[iBuffer].mDataByteSize / mal_get_bytes_per_sample(pDevice->playback.internalFormat); + ma_uint32 frameCountPerBuffer = pBufferList->mBuffers[iBuffer].mDataByteSize / ma_get_bytes_per_sample(pDevice->playback.internalFormat); - mal_uint32 framesRemaining = frameCountPerBuffer; + ma_uint32 framesRemaining = frameCountPerBuffer; while (framesRemaining > 0) { - mal_uint32 framesToRead = sizeof(tempBuffer) / mal_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels); + ma_uint32 framesToRead = sizeof(tempBuffer) / ma_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels); if (framesToRead > framesRemaining) { framesToRead = framesRemaining; } - if (pDevice->type == mal_device_type_duplex) { - mal_device__handle_duplex_callback_playback(pDevice, framesToRead, tempBuffer, &pDevice->coreaudio.duplexRB); + if (pDevice->type == ma_device_type_duplex) { + ma_device__handle_duplex_callback_playback(pDevice, framesToRead, tempBuffer, &pDevice->coreaudio.duplexRB); } else { - mal_device__read_frames_from_client(pDevice, framesToRead, tempBuffer); + ma_device__read_frames_from_client(pDevice, framesToRead, tempBuffer); } void* ppDeinterleavedBuffers[MA_MAX_CHANNELS]; - for (mal_uint32 iChannel = 0; iChannel < pDevice->playback.internalChannels; ++iChannel) { - ppDeinterleavedBuffers[iChannel] = (void*)mal_offset_ptr(pBufferList->mBuffers[iBuffer].mData, (frameCountPerBuffer - framesRemaining) * mal_get_bytes_per_sample(pDevice->playback.internalFormat)); + for (ma_uint32 iChannel = 0; iChannel < pDevice->playback.internalChannels; ++iChannel) { + ppDeinterleavedBuffers[iChannel] = (void*)ma_offset_ptr(pBufferList->mBuffers[iBuffer].mData, (frameCountPerBuffer - framesRemaining) * ma_get_bytes_per_sample(pDevice->playback.internalFormat)); } - mal_deinterleave_pcm_frames(pDevice->playback.internalFormat, pDevice->playback.internalChannels, framesToRead, tempBuffer, ppDeinterleavedBuffers); + ma_deinterleave_pcm_frames(pDevice->playback.internalFormat, pDevice->playback.internalChannels, framesToRead, tempBuffer, ppDeinterleavedBuffers); framesRemaining -= framesToRead; } @@ -17041,7 +17041,7 @@ OSStatus mal_on_output__coreaudio(void* pUserData, AudioUnitRenderActionFlags* p return noErr; } -OSStatus mal_on_input__coreaudio(void* pUserData, AudioUnitRenderActionFlags* pActionFlags, const AudioTimeStamp* pTimeStamp, UInt32 busNumber, UInt32 frameCount, AudioBufferList* pUnusedBufferList) +OSStatus ma_on_input__coreaudio(void* pUserData, AudioUnitRenderActionFlags* pActionFlags, const AudioTimeStamp* pTimeStamp, UInt32 busNumber, UInt32 frameCount, AudioBufferList* pUnusedBufferList) { (void)pActionFlags; (void)pTimeStamp; @@ -17049,24 +17049,24 @@ OSStatus mal_on_input__coreaudio(void* pUserData, AudioUnitRenderActionFlags* pA (void)frameCount; (void)pUnusedBufferList; - mal_device* pDevice = (mal_device*)pUserData; - mal_assert(pDevice != NULL); + ma_device* pDevice = (ma_device*)pUserData; + ma_assert(pDevice != NULL); AudioBufferList* pRenderedBufferList = (AudioBufferList*)pDevice->coreaudio.pAudioBufferList; - mal_assert(pRenderedBufferList); + ma_assert(pRenderedBufferList); // We need to check whether or not we are outputting interleaved or non-interleaved samples. The // way we do this is slightly different for each type. - mal_stream_layout layout = mal_stream_layout_interleaved; + ma_stream_layout layout = ma_stream_layout_interleaved; if (pRenderedBufferList->mBuffers[0].mNumberChannels != pDevice->capture.internalChannels) { - layout = mal_stream_layout_deinterleaved; + layout = ma_stream_layout_deinterleaved; } #if defined(MA_DEBUG_OUTPUT) printf("INFO: Input Callback: busNumber=%d, frameCount=%d, mNumberBuffers=%d\n", busNumber, frameCount, pRenderedBufferList->mNumberBuffers); #endif - OSStatus status = ((mal_AudioUnitRender_proc)pDevice->pContext->coreaudio.AudioUnitRender)((AudioUnit)pDevice->coreaudio.audioUnitCapture, pActionFlags, pTimeStamp, busNumber, frameCount, pRenderedBufferList); + OSStatus status = ((ma_AudioUnitRender_proc)pDevice->pContext->coreaudio.AudioUnitRender)((AudioUnit)pDevice->coreaudio.audioUnitCapture, pActionFlags, pTimeStamp, busNumber, frameCount, pRenderedBufferList); if (status != noErr) { #if defined(MA_DEBUG_OUTPUT) printf(" ERROR: AudioUnitRender() failed with %d\n", status); @@ -17074,13 +17074,13 @@ OSStatus mal_on_input__coreaudio(void* pUserData, AudioUnitRenderActionFlags* pA return status; } - if (layout == mal_stream_layout_interleaved) { + if (layout == ma_stream_layout_interleaved) { for (UInt32 iBuffer = 0; iBuffer < pRenderedBufferList->mNumberBuffers; ++iBuffer) { if (pRenderedBufferList->mBuffers[iBuffer].mNumberChannels == pDevice->capture.internalChannels) { - if (pDevice->type == mal_device_type_duplex) { - mal_device__handle_duplex_callback_capture(pDevice, frameCount, pRenderedBufferList->mBuffers[iBuffer].mData, &pDevice->coreaudio.duplexRB); + if (pDevice->type == ma_device_type_duplex) { + ma_device__handle_duplex_callback_capture(pDevice, frameCount, pRenderedBufferList->mBuffers[iBuffer].mData, &pDevice->coreaudio.duplexRB); } else { - mal_device__send_frames_to_client(pDevice, frameCount, pRenderedBufferList->mBuffers[iBuffer].mData); + ma_device__send_frames_to_client(pDevice, frameCount, pRenderedBufferList->mBuffers[iBuffer].mData); } #if defined(MA_DEBUG_OUTPUT) printf(" mDataByteSize=%d\n", pRenderedBufferList->mBuffers[iBuffer].mDataByteSize); @@ -17089,20 +17089,20 @@ OSStatus mal_on_input__coreaudio(void* pUserData, AudioUnitRenderActionFlags* pA // This case is where the number of channels in the output buffer do not match our internal channels. It could mean that it's // not interleaved, in which case we can't handle right now since miniaudio does not yet support non-interleaved streams. - mal_uint8 silentBuffer[4096]; - mal_zero_memory(silentBuffer, sizeof(silentBuffer)); + ma_uint8 silentBuffer[4096]; + ma_zero_memory(silentBuffer, sizeof(silentBuffer)); - mal_uint32 framesRemaining = frameCount; + ma_uint32 framesRemaining = frameCount; while (framesRemaining > 0) { - mal_uint32 framesToSend = sizeof(silentBuffer) / mal_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels); + ma_uint32 framesToSend = sizeof(silentBuffer) / ma_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels); if (framesToSend > framesRemaining) { framesToSend = framesRemaining; } - if (pDevice->type == mal_device_type_duplex) { - mal_device__handle_duplex_callback_capture(pDevice, framesToSend, silentBuffer, &pDevice->coreaudio.duplexRB); + if (pDevice->type == ma_device_type_duplex) { + ma_device__handle_duplex_callback_capture(pDevice, framesToSend, silentBuffer, &pDevice->coreaudio.duplexRB); } else { - mal_device__send_frames_to_client(pDevice, framesToSend, silentBuffer); + ma_device__send_frames_to_client(pDevice, framesToSend, silentBuffer); } framesRemaining -= framesToSend; @@ -17116,26 +17116,26 @@ OSStatus mal_on_input__coreaudio(void* pUserData, AudioUnitRenderActionFlags* pA } else { // This is the deinterleaved case. We need to interleave the audio data before sending it to the client. This // assumes each buffer is the same size. - mal_uint8 tempBuffer[4096]; + ma_uint8 tempBuffer[4096]; for (UInt32 iBuffer = 0; iBuffer < pRenderedBufferList->mNumberBuffers; iBuffer += pDevice->capture.internalChannels) { - mal_uint32 framesRemaining = frameCount; + ma_uint32 framesRemaining = frameCount; while (framesRemaining > 0) { - mal_uint32 framesToSend = sizeof(tempBuffer) / mal_get_bytes_per_sample(pDevice->capture.internalFormat); + ma_uint32 framesToSend = sizeof(tempBuffer) / ma_get_bytes_per_sample(pDevice->capture.internalFormat); if (framesToSend > framesRemaining) { framesToSend = framesRemaining; } void* ppDeinterleavedBuffers[MA_MAX_CHANNELS]; - for (mal_uint32 iChannel = 0; iChannel < pDevice->capture.internalChannels; ++iChannel) { - ppDeinterleavedBuffers[iChannel] = (void*)mal_offset_ptr(pRenderedBufferList->mBuffers[iBuffer].mData, (frameCount - framesRemaining) * mal_get_bytes_per_sample(pDevice->capture.internalFormat)); + for (ma_uint32 iChannel = 0; iChannel < pDevice->capture.internalChannels; ++iChannel) { + ppDeinterleavedBuffers[iChannel] = (void*)ma_offset_ptr(pRenderedBufferList->mBuffers[iBuffer].mData, (frameCount - framesRemaining) * ma_get_bytes_per_sample(pDevice->capture.internalFormat)); } - mal_interleave_pcm_frames(pDevice->capture.internalFormat, pDevice->capture.internalChannels, framesToSend, (const void**)ppDeinterleavedBuffers, tempBuffer); + ma_interleave_pcm_frames(pDevice->capture.internalFormat, pDevice->capture.internalChannels, framesToSend, (const void**)ppDeinterleavedBuffers, tempBuffer); - if (pDevice->type == mal_device_type_duplex) { - mal_device__handle_duplex_callback_capture(pDevice, framesToSend, tempBuffer, &pDevice->coreaudio.duplexRB); + if (pDevice->type == ma_device_type_duplex) { + ma_device__handle_duplex_callback_capture(pDevice, framesToSend, tempBuffer, &pDevice->coreaudio.duplexRB); } else { - mal_device__send_frames_to_client(pDevice, framesToSend, tempBuffer); + ma_device__send_frames_to_client(pDevice, framesToSend, tempBuffer); } framesRemaining -= framesToSend; @@ -17150,24 +17150,24 @@ void on_start_stop__coreaudio(void* pUserData, AudioUnit audioUnit, AudioUnitPro { (void)propertyID; - mal_device* pDevice = (mal_device*)pUserData; - mal_assert(pDevice != NULL); + ma_device* pDevice = (ma_device*)pUserData; + ma_assert(pDevice != NULL); - // There's been a report of a deadlock here when triggered by mal_device_uninit(). It looks like - // AudioUnitGetProprty (called below) and AudioComponentInstanceDispose (called in mal_device_uninit) + // There's been a report of a deadlock here when triggered by ma_device_uninit(). It looks like + // AudioUnitGetProprty (called below) and AudioComponentInstanceDispose (called in ma_device_uninit) // can try waiting on the same lock. I'm going to try working around this by not calling any Core // Audio APIs in the callback when the device has been stopped or uninitialized. - if (mal_device__get_state(pDevice) == MA_STATE_UNINITIALIZED || mal_device__get_state(pDevice) == MA_STATE_STOPPING || mal_device__get_state(pDevice) == MA_STATE_STOPPED) { - mal_stop_proc onStop = pDevice->onStop; + if (ma_device__get_state(pDevice) == MA_STATE_UNINITIALIZED || ma_device__get_state(pDevice) == MA_STATE_STOPPING || ma_device__get_state(pDevice) == MA_STATE_STOPPED) { + ma_stop_proc onStop = pDevice->onStop; if (onStop) { onStop(pDevice); } - mal_event_signal(&pDevice->coreaudio.stopEvent); + ma_event_signal(&pDevice->coreaudio.stopEvent); } else { UInt32 isRunning; UInt32 isRunningSize = sizeof(isRunning); - OSStatus status = ((mal_AudioUnitGetProperty_proc)pDevice->pContext->coreaudio.AudioUnitGetProperty)(audioUnit, kAudioOutputUnitProperty_IsRunning, scope, element, &isRunning, &isRunningSize); + OSStatus status = ((ma_AudioUnitGetProperty_proc)pDevice->pContext->coreaudio.AudioUnitGetProperty)(audioUnit, kAudioOutputUnitProperty_IsRunning, scope, element, &isRunning, &isRunningSize); if (status != noErr) { return; // Don't really know what to do in this case... just ignore it, I suppose... } @@ -17199,7 +17199,7 @@ void on_start_stop__coreaudio(void* pUserData, AudioUnit audioUnit, AudioUnitPro } // Getting here means we need to stop the device. - mal_stop_proc onStop = pDevice->onStop; + ma_stop_proc onStop = pDevice->onStop; if (onStop) { onStop(pDevice); } @@ -17208,12 +17208,12 @@ void on_start_stop__coreaudio(void* pUserData, AudioUnit audioUnit, AudioUnitPro } #if defined(MA_APPLE_DESKTOP) -OSStatus mal_default_device_changed__coreaudio(AudioObjectID objectID, UInt32 addressCount, const AudioObjectPropertyAddress* pAddresses, void* pUserData) +OSStatus ma_default_device_changed__coreaudio(AudioObjectID objectID, UInt32 addressCount, const AudioObjectPropertyAddress* pAddresses, void* pUserData) { (void)objectID; - mal_device* pDevice = (mal_device*)pUserData; - mal_assert(pDevice != NULL); + ma_device* pDevice = (ma_device*)pUserData; + ma_assert(pDevice != NULL); // Not sure if I really need to check this, but it makes me feel better. if (addressCount == 0) { @@ -17222,20 +17222,20 @@ OSStatus mal_default_device_changed__coreaudio(AudioObjectID objectID, UInt32 ad if (pAddresses[0].mSelector == kAudioHardwarePropertyDefaultOutputDevice) { pDevice->coreaudio.isSwitchingPlaybackDevice = MA_TRUE; - mal_result reinitResult = mal_device_reinit_internal__coreaudio(pDevice, mal_device_type_playback, MA_TRUE); + ma_result reinitResult = ma_device_reinit_internal__coreaudio(pDevice, ma_device_type_playback, MA_TRUE); pDevice->coreaudio.isSwitchingPlaybackDevice = MA_FALSE; if (reinitResult == MA_SUCCESS) { - mal_device__post_init_setup(pDevice, mal_device_type_playback); + ma_device__post_init_setup(pDevice, ma_device_type_playback); // Restart the device if required. If this fails we need to stop the device entirely. - if (mal_device__get_state(pDevice) == MA_STATE_STARTED) { - OSStatus status = ((mal_AudioOutputUnitStart_proc)pDevice->pContext->coreaudio.AudioOutputUnitStart)((AudioUnit)pDevice->coreaudio.audioUnitPlayback); + if (ma_device__get_state(pDevice) == MA_STATE_STARTED) { + OSStatus status = ((ma_AudioOutputUnitStart_proc)pDevice->pContext->coreaudio.AudioOutputUnitStart)((AudioUnit)pDevice->coreaudio.audioUnitPlayback); if (status != noErr) { - if (pDevice->type == mal_device_type_duplex) { - ((mal_AudioOutputUnitStop_proc)pDevice->pContext->coreaudio.AudioOutputUnitStop)((AudioUnit)pDevice->coreaudio.audioUnitCapture); + if (pDevice->type == ma_device_type_duplex) { + ((ma_AudioOutputUnitStop_proc)pDevice->pContext->coreaudio.AudioOutputUnitStop)((AudioUnit)pDevice->coreaudio.audioUnitCapture); } - mal_device__set_state(pDevice, MA_STATE_STOPPED); + ma_device__set_state(pDevice, MA_STATE_STOPPED); } } } @@ -17243,20 +17243,20 @@ OSStatus mal_default_device_changed__coreaudio(AudioObjectID objectID, UInt32 ad if (pAddresses[0].mSelector == kAudioHardwarePropertyDefaultInputDevice) { pDevice->coreaudio.isSwitchingPlaybackDevice = MA_TRUE; - mal_result reinitResult = mal_device_reinit_internal__coreaudio(pDevice, mal_device_type_capture, MA_TRUE); + ma_result reinitResult = ma_device_reinit_internal__coreaudio(pDevice, ma_device_type_capture, MA_TRUE); pDevice->coreaudio.isSwitchingPlaybackDevice = MA_FALSE; if (reinitResult == MA_SUCCESS) { - mal_device__post_init_setup(pDevice, mal_device_type_capture); + ma_device__post_init_setup(pDevice, ma_device_type_capture); // Restart the device if required. If this fails we need to stop the device entirely. - if (mal_device__get_state(pDevice) == MA_STATE_STARTED) { - OSStatus status = ((mal_AudioOutputUnitStart_proc)pDevice->pContext->coreaudio.AudioOutputUnitStart)((AudioUnit)pDevice->coreaudio.audioUnitCapture); + if (ma_device__get_state(pDevice) == MA_STATE_STARTED) { + OSStatus status = ((ma_AudioOutputUnitStart_proc)pDevice->pContext->coreaudio.AudioOutputUnitStart)((AudioUnit)pDevice->coreaudio.audioUnitCapture); if (status != noErr) { - if (pDevice->type == mal_device_type_duplex) { - ((mal_AudioOutputUnitStop_proc)pDevice->pContext->coreaudio.AudioOutputUnitStop)((AudioUnit)pDevice->coreaudio.audioUnitPlayback); + if (pDevice->type == ma_device_type_duplex) { + ((ma_AudioOutputUnitStop_proc)pDevice->pContext->coreaudio.AudioOutputUnitStop)((AudioUnit)pDevice->coreaudio.audioUnitPlayback); } - mal_device__set_state(pDevice, MA_STATE_STOPPED); + ma_device__set_state(pDevice, MA_STATE_STOPPED); } } } @@ -17269,19 +17269,19 @@ OSStatus mal_default_device_changed__coreaudio(AudioObjectID objectID, UInt32 ad typedef struct { // Input. - mal_format formatIn; - mal_uint32 channelsIn; - mal_uint32 sampleRateIn; - mal_channel channelMapIn[MA_MAX_CHANNELS]; - mal_uint32 bufferSizeInFramesIn; - mal_uint32 bufferSizeInMillisecondsIn; - mal_uint32 periodsIn; - mal_bool32 usingDefaultFormat; - mal_bool32 usingDefaultChannels; - mal_bool32 usingDefaultSampleRate; - mal_bool32 usingDefaultChannelMap; - mal_share_mode shareMode; - mal_bool32 registerStopEvent; + ma_format formatIn; + ma_uint32 channelsIn; + ma_uint32 sampleRateIn; + ma_channel channelMapIn[MA_MAX_CHANNELS]; + ma_uint32 bufferSizeInFramesIn; + ma_uint32 bufferSizeInMillisecondsIn; + ma_uint32 periodsIn; + ma_bool32 usingDefaultFormat; + ma_bool32 usingDefaultChannels; + ma_bool32 usingDefaultSampleRate; + ma_bool32 usingDefaultChannelMap; + ma_share_mode shareMode; + ma_bool32 registerStopEvent; // Output. #if defined(MA_APPLE_DESKTOP) @@ -17290,24 +17290,24 @@ typedef struct AudioComponent component; AudioUnit audioUnit; AudioBufferList* pAudioBufferList; // Only used for input devices. - mal_format formatOut; - mal_uint32 channelsOut; - mal_uint32 sampleRateOut; - mal_channel channelMapOut[MA_MAX_CHANNELS]; - mal_uint32 bufferSizeInFramesOut; - mal_uint32 periodsOut; + ma_format formatOut; + ma_uint32 channelsOut; + ma_uint32 sampleRateOut; + ma_channel channelMapOut[MA_MAX_CHANNELS]; + ma_uint32 bufferSizeInFramesOut; + ma_uint32 periodsOut; char deviceName[256]; -} mal_device_init_internal_data__coreaudio; +} ma_device_init_internal_data__coreaudio; -mal_result mal_device_init_internal__coreaudio(mal_context* pContext, mal_device_type deviceType, const mal_device_id* pDeviceID, mal_device_init_internal_data__coreaudio* pData, void* pDevice_DoNotReference) /* <-- pDevice is typed as void* intentionally so as to avoid accidentally referencing it. */ +ma_result ma_device_init_internal__coreaudio(ma_context* pContext, ma_device_type deviceType, const ma_device_id* pDeviceID, ma_device_init_internal_data__coreaudio* pData, void* pDevice_DoNotReference) /* <-- pDevice is typed as void* intentionally so as to avoid accidentally referencing it. */ { /* This API should only be used for a single device type: playback or capture. No full-duplex mode. */ - if (deviceType == mal_device_type_duplex) { + if (deviceType == ma_device_type_duplex) { return MA_INVALID_ARGS; } - mal_assert(pContext != NULL); - mal_assert(deviceType == mal_device_type_playback || deviceType == mal_device_type_capture); + ma_assert(pContext != NULL); + ma_assert(deviceType == ma_device_type_playback || deviceType == ma_device_type_capture); #if defined(MA_APPLE_DESKTOP) pData->deviceObjectID = 0; @@ -17316,11 +17316,11 @@ mal_result mal_device_init_internal__coreaudio(mal_context* pContext, mal_device pData->audioUnit = NULL; pData->pAudioBufferList = NULL; - mal_result result; + ma_result result; #if defined(MA_APPLE_DESKTOP) AudioObjectID deviceObjectID; - result = mal_find_AudioObjectID(pContext, deviceType, pDeviceID, &deviceObjectID); + result = ma_find_AudioObjectID(pContext, deviceType, pDeviceID, &deviceObjectID); if (result != MA_SUCCESS) { return result; } @@ -17339,38 +17339,38 @@ mal_result mal_device_init_internal__coreaudio(mal_context* pContext, mal_device // Audio unit. - OSStatus status = ((mal_AudioComponentInstanceNew_proc)pContext->coreaudio.AudioComponentInstanceNew)(pContext->coreaudio.component, (AudioUnit*)&pData->audioUnit); + OSStatus status = ((ma_AudioComponentInstanceNew_proc)pContext->coreaudio.AudioComponentInstanceNew)(pContext->coreaudio.component, (AudioUnit*)&pData->audioUnit); if (status != noErr) { - return mal_result_from_OSStatus(status); + return ma_result_from_OSStatus(status); } // The input/output buses need to be explicitly enabled and disabled. We set the flag based on the output unit first, then we just swap it for input. UInt32 enableIOFlag = 1; - if (deviceType == mal_device_type_capture) { + if (deviceType == ma_device_type_capture) { enableIOFlag = 0; } - status = ((mal_AudioUnitSetProperty_proc)pContext->coreaudio.AudioUnitSetProperty)(pData->audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Output, MA_COREAUDIO_OUTPUT_BUS, &enableIOFlag, sizeof(enableIOFlag)); + status = ((ma_AudioUnitSetProperty_proc)pContext->coreaudio.AudioUnitSetProperty)(pData->audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Output, MA_COREAUDIO_OUTPUT_BUS, &enableIOFlag, sizeof(enableIOFlag)); if (status != noErr) { - ((mal_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(pData->audioUnit); - return mal_result_from_OSStatus(status); + ((ma_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(pData->audioUnit); + return ma_result_from_OSStatus(status); } enableIOFlag = (enableIOFlag == 0) ? 1 : 0; - status = ((mal_AudioUnitSetProperty_proc)pContext->coreaudio.AudioUnitSetProperty)(pData->audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, MA_COREAUDIO_INPUT_BUS, &enableIOFlag, sizeof(enableIOFlag)); + status = ((ma_AudioUnitSetProperty_proc)pContext->coreaudio.AudioUnitSetProperty)(pData->audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, MA_COREAUDIO_INPUT_BUS, &enableIOFlag, sizeof(enableIOFlag)); if (status != noErr) { - ((mal_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(pData->audioUnit); - return mal_result_from_OSStatus(status); + ((ma_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(pData->audioUnit); + return ma_result_from_OSStatus(status); } // Set the device to use with this audio unit. This is only used on desktop since we are using defaults on mobile. #if defined(MA_APPLE_DESKTOP) - status = ((mal_AudioUnitSetProperty_proc)pContext->coreaudio.AudioUnitSetProperty)(pData->audioUnit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, (deviceType == mal_device_type_playback) ? MA_COREAUDIO_OUTPUT_BUS : MA_COREAUDIO_INPUT_BUS, &deviceObjectID, sizeof(AudioDeviceID)); + status = ((ma_AudioUnitSetProperty_proc)pContext->coreaudio.AudioUnitSetProperty)(pData->audioUnit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, (deviceType == ma_device_type_playback) ? MA_COREAUDIO_OUTPUT_BUS : MA_COREAUDIO_INPUT_BUS, &deviceObjectID, sizeof(AudioDeviceID)); if (status != noErr) { - ((mal_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(pData->audioUnit); - return mal_result_from_OSStatus(result); + ((ma_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(pData->audioUnit); + return ma_result_from_OSStatus(result); } #endif @@ -17386,43 +17386,43 @@ mal_result mal_device_init_internal__coreaudio(mal_context* pContext, mal_device // On mobile platforms this is a bit different. We just force the use of whatever the audio unit's current format is set to. AudioStreamBasicDescription bestFormat; { - AudioUnitScope formatScope = (deviceType == mal_device_type_playback) ? kAudioUnitScope_Input : kAudioUnitScope_Output; - AudioUnitElement formatElement = (deviceType == mal_device_type_playback) ? MA_COREAUDIO_OUTPUT_BUS : MA_COREAUDIO_INPUT_BUS; + AudioUnitScope formatScope = (deviceType == ma_device_type_playback) ? kAudioUnitScope_Input : kAudioUnitScope_Output; + AudioUnitElement formatElement = (deviceType == ma_device_type_playback) ? MA_COREAUDIO_OUTPUT_BUS : MA_COREAUDIO_INPUT_BUS; #if defined(MA_APPLE_DESKTOP) - result = mal_find_best_format__coreaudio(pContext, deviceObjectID, deviceType, pData->formatIn, pData->channelsIn, pData->sampleRateIn, pData->usingDefaultFormat, pData->usingDefaultChannels, pData->usingDefaultSampleRate, &bestFormat); + result = ma_find_best_format__coreaudio(pContext, deviceObjectID, deviceType, pData->formatIn, pData->channelsIn, pData->sampleRateIn, pData->usingDefaultFormat, pData->usingDefaultChannels, pData->usingDefaultSampleRate, &bestFormat); if (result != MA_SUCCESS) { - ((mal_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(pData->audioUnit); + ((ma_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(pData->audioUnit); return result; } // From what I can see, Apple's documentation implies that we should keep the sample rate consistent. AudioStreamBasicDescription origFormat; UInt32 origFormatSize = sizeof(origFormat); - if (deviceType == mal_device_type_playback) { - status = ((mal_AudioUnitGetProperty_proc)pContext->coreaudio.AudioUnitGetProperty)(pData->audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, MA_COREAUDIO_OUTPUT_BUS, &origFormat, &origFormatSize); + if (deviceType == ma_device_type_playback) { + status = ((ma_AudioUnitGetProperty_proc)pContext->coreaudio.AudioUnitGetProperty)(pData->audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, MA_COREAUDIO_OUTPUT_BUS, &origFormat, &origFormatSize); } else { - status = ((mal_AudioUnitGetProperty_proc)pContext->coreaudio.AudioUnitGetProperty)(pData->audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, MA_COREAUDIO_INPUT_BUS, &origFormat, &origFormatSize); + status = ((ma_AudioUnitGetProperty_proc)pContext->coreaudio.AudioUnitGetProperty)(pData->audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, MA_COREAUDIO_INPUT_BUS, &origFormat, &origFormatSize); } if (status != noErr) { - ((mal_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(pData->audioUnit); + ((ma_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(pData->audioUnit); return result; } bestFormat.mSampleRate = origFormat.mSampleRate; - status = ((mal_AudioUnitSetProperty_proc)pContext->coreaudio.AudioUnitSetProperty)(pData->audioUnit, kAudioUnitProperty_StreamFormat, formatScope, formatElement, &bestFormat, sizeof(bestFormat)); + status = ((ma_AudioUnitSetProperty_proc)pContext->coreaudio.AudioUnitSetProperty)(pData->audioUnit, kAudioUnitProperty_StreamFormat, formatScope, formatElement, &bestFormat, sizeof(bestFormat)); if (status != noErr) { // We failed to set the format, so fall back to the current format of the audio unit. bestFormat = origFormat; } #else UInt32 propSize = sizeof(bestFormat); - status = ((mal_AudioUnitGetProperty_proc)pContext->coreaudio.AudioUnitGetProperty)(pData->audioUnit, kAudioUnitProperty_StreamFormat, formatScope, formatElement, &bestFormat, &propSize); + status = ((ma_AudioUnitGetProperty_proc)pContext->coreaudio.AudioUnitGetProperty)(pData->audioUnit, kAudioUnitProperty_StreamFormat, formatScope, formatElement, &bestFormat, &propSize); if (status != noErr) { - ((mal_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(pData->audioUnit); - return mal_result_from_OSStatus(status); + ((ma_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(pData->audioUnit); + return ma_result_from_OSStatus(status); } // Sample rate is a little different here because for some reason kAudioUnitProperty_StreamFormat returns 0... Oh well. We need to instead try @@ -17431,27 +17431,27 @@ mal_result mal_device_init_internal__coreaudio(mal_context* pContext, mal_device // can tell, it looks like the sample rate is shared between playback and capture for everything. @autoreleasepool { AVAudioSession* pAudioSession = [AVAudioSession sharedInstance]; - mal_assert(pAudioSession != NULL); + ma_assert(pAudioSession != NULL); [pAudioSession setPreferredSampleRate:(double)pData->sampleRateIn error:nil]; bestFormat.mSampleRate = pAudioSession.sampleRate; } - status = ((mal_AudioUnitSetProperty_proc)pContext->coreaudio.AudioUnitSetProperty)(pData->audioUnit, kAudioUnitProperty_StreamFormat, formatScope, formatElement, &bestFormat, sizeof(bestFormat)); + status = ((ma_AudioUnitSetProperty_proc)pContext->coreaudio.AudioUnitSetProperty)(pData->audioUnit, kAudioUnitProperty_StreamFormat, formatScope, formatElement, &bestFormat, sizeof(bestFormat)); if (status != noErr) { - ((mal_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(pData->audioUnit); - return mal_result_from_OSStatus(status); + ((ma_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(pData->audioUnit); + return ma_result_from_OSStatus(status); } #endif - result = mal_format_from_AudioStreamBasicDescription(&bestFormat, &pData->formatOut); + result = ma_format_from_AudioStreamBasicDescription(&bestFormat, &pData->formatOut); if (result != MA_SUCCESS) { - ((mal_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(pData->audioUnit); + ((ma_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(pData->audioUnit); return result; } - if (pData->formatOut == mal_format_unknown) { - ((mal_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(pData->audioUnit); + if (pData->formatOut == ma_format_unknown) { + ((ma_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(pData->audioUnit); return MA_FORMAT_NOT_SUPPORTED; } @@ -17466,35 +17466,35 @@ mal_result mal_device_init_internal__coreaudio(mal_context* pContext, mal_device // it gets weird, it doesn't seem to work with capture devices, nor at all on iOS... Therefore // I'm going to fall back to a default assumption in these cases. #if defined(MA_APPLE_DESKTOP) - result = mal_get_AudioUnit_channel_map(pContext, pData->audioUnit, deviceType, pData->channelMapOut); + result = ma_get_AudioUnit_channel_map(pContext, pData->audioUnit, deviceType, pData->channelMapOut); if (result != MA_SUCCESS) { #if 0 // Try falling back to the channel map from the AudioObject. - result = mal_get_AudioObject_channel_map(pContext, deviceObjectID, deviceType, pData->channelMapOut); + result = ma_get_AudioObject_channel_map(pContext, deviceObjectID, deviceType, pData->channelMapOut); if (result != MA_SUCCESS) { return result; } #else // Fall back to default assumptions. - mal_get_standard_channel_map(mal_standard_channel_map_default, pData->channelsOut, pData->channelMapOut); + ma_get_standard_channel_map(ma_standard_channel_map_default, pData->channelsOut, pData->channelMapOut); #endif } #else // TODO: Figure out how to get the channel map using AVAudioSession. - mal_get_standard_channel_map(mal_standard_channel_map_default, pData->channelsOut, pData->channelMapOut); + ma_get_standard_channel_map(ma_standard_channel_map_default, pData->channelsOut, pData->channelMapOut); #endif // Buffer size. Not allowing this to be configurable on iOS. - mal_uint32 actualBufferSizeInFrames = pData->bufferSizeInFramesIn; + ma_uint32 actualBufferSizeInFrames = pData->bufferSizeInFramesIn; #if defined(MA_APPLE_DESKTOP) if (actualBufferSizeInFrames == 0) { - actualBufferSizeInFrames = mal_calculate_buffer_size_in_frames_from_milliseconds(pData->bufferSizeInMillisecondsIn, pData->sampleRateOut); + actualBufferSizeInFrames = ma_calculate_buffer_size_in_frames_from_milliseconds(pData->bufferSizeInMillisecondsIn, pData->sampleRateOut); } actualBufferSizeInFrames = actualBufferSizeInFrames / pData->periodsOut; - result = mal_set_AudioObject_buffer_size_in_frames(pContext, deviceObjectID, deviceType, &actualBufferSizeInFrames); + result = ma_set_AudioObject_buffer_size_in_frames(pContext, deviceObjectID, deviceType, &actualBufferSizeInFrames); if (result != MA_SUCCESS) { return result; } @@ -17514,54 +17514,54 @@ mal_result mal_device_init_internal__coreaudio(mal_context* pContext, mal_device // Note how inFramesToProcess is smaller than mMaxFramesPerSlice. To fix, we need to set kAudioUnitProperty_MaximumFramesPerSlice to that // of the size of our buffer, or do it the other way around and set our buffer size to the kAudioUnitProperty_MaximumFramesPerSlice. { - /*AudioUnitScope propScope = (deviceType == mal_device_type_playback) ? kAudioUnitScope_Input : kAudioUnitScope_Output; - AudioUnitElement propBus = (deviceType == mal_device_type_playback) ? MA_COREAUDIO_OUTPUT_BUS : MA_COREAUDIO_INPUT_BUS; + /*AudioUnitScope propScope = (deviceType == ma_device_type_playback) ? kAudioUnitScope_Input : kAudioUnitScope_Output; + AudioUnitElement propBus = (deviceType == ma_device_type_playback) ? MA_COREAUDIO_OUTPUT_BUS : MA_COREAUDIO_INPUT_BUS; - status = ((mal_AudioUnitSetProperty_proc)pContext->coreaudio.AudioUnitSetProperty)(pData->audioUnit, kAudioUnitProperty_MaximumFramesPerSlice, propScope, propBus, &actualBufferSizeInFrames, sizeof(actualBufferSizeInFrames)); + status = ((ma_AudioUnitSetProperty_proc)pContext->coreaudio.AudioUnitSetProperty)(pData->audioUnit, kAudioUnitProperty_MaximumFramesPerSlice, propScope, propBus, &actualBufferSizeInFrames, sizeof(actualBufferSizeInFrames)); if (status != noErr) { - ((mal_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(pData->audioUnit); - return mal_result_from_OSStatus(status); + ((ma_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(pData->audioUnit); + return ma_result_from_OSStatus(status); }*/ - status = ((mal_AudioUnitSetProperty_proc)pContext->coreaudio.AudioUnitSetProperty)(pData->audioUnit, kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Global, 0, &actualBufferSizeInFrames, sizeof(actualBufferSizeInFrames)); + status = ((ma_AudioUnitSetProperty_proc)pContext->coreaudio.AudioUnitSetProperty)(pData->audioUnit, kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Global, 0, &actualBufferSizeInFrames, sizeof(actualBufferSizeInFrames)); if (status != noErr) { - ((mal_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(pData->audioUnit); - return mal_result_from_OSStatus(status); + ((ma_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(pData->audioUnit); + return ma_result_from_OSStatus(status); } } // We need a buffer list if this is an input device. We render into this in the input callback. - if (deviceType == mal_device_type_capture) { - mal_bool32 isInterleaved = (bestFormat.mFormatFlags & kAudioFormatFlagIsNonInterleaved) == 0; + if (deviceType == ma_device_type_capture) { + ma_bool32 isInterleaved = (bestFormat.mFormatFlags & kAudioFormatFlagIsNonInterleaved) == 0; size_t allocationSize = sizeof(AudioBufferList) - sizeof(AudioBuffer); // Subtract sizeof(AudioBuffer) because that part is dynamically sized. if (isInterleaved) { // Interleaved case. This is the simple case because we just have one buffer. allocationSize += sizeof(AudioBuffer) * 1; - allocationSize += actualBufferSizeInFrames * mal_get_bytes_per_frame(pData->formatOut, pData->channelsOut); + allocationSize += actualBufferSizeInFrames * ma_get_bytes_per_frame(pData->formatOut, pData->channelsOut); } else { // Non-interleaved case. This is the more complex case because there's more than one buffer. allocationSize += sizeof(AudioBuffer) * pData->channelsOut; - allocationSize += actualBufferSizeInFrames * mal_get_bytes_per_sample(pData->formatOut) * pData->channelsOut; + allocationSize += actualBufferSizeInFrames * ma_get_bytes_per_sample(pData->formatOut) * pData->channelsOut; } - AudioBufferList* pBufferList = (AudioBufferList*)mal_malloc(allocationSize); + AudioBufferList* pBufferList = (AudioBufferList*)ma_malloc(allocationSize); if (pBufferList == NULL) { - ((mal_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(pData->audioUnit); + ((ma_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(pData->audioUnit); return MA_OUT_OF_MEMORY; } if (isInterleaved) { pBufferList->mNumberBuffers = 1; pBufferList->mBuffers[0].mNumberChannels = pData->channelsOut; - pBufferList->mBuffers[0].mDataByteSize = actualBufferSizeInFrames * mal_get_bytes_per_frame(pData->formatOut, pData->channelsOut); - pBufferList->mBuffers[0].mData = (mal_uint8*)pBufferList + sizeof(AudioBufferList); + pBufferList->mBuffers[0].mDataByteSize = actualBufferSizeInFrames * ma_get_bytes_per_frame(pData->formatOut, pData->channelsOut); + pBufferList->mBuffers[0].mData = (ma_uint8*)pBufferList + sizeof(AudioBufferList); } else { pBufferList->mNumberBuffers = pData->channelsOut; - for (mal_uint32 iBuffer = 0; iBuffer < pBufferList->mNumberBuffers; ++iBuffer) { + for (ma_uint32 iBuffer = 0; iBuffer < pBufferList->mNumberBuffers; ++iBuffer) { pBufferList->mBuffers[iBuffer].mNumberChannels = 1; - pBufferList->mBuffers[iBuffer].mDataByteSize = actualBufferSizeInFrames * mal_get_bytes_per_sample(pData->formatOut); - pBufferList->mBuffers[iBuffer].mData = (mal_uint8*)pBufferList + ((sizeof(AudioBufferList) - sizeof(AudioBuffer)) + (sizeof(AudioBuffer) * pData->channelsOut)) + (actualBufferSizeInFrames * mal_get_bytes_per_sample(pData->formatOut) * iBuffer); + pBufferList->mBuffers[iBuffer].mDataByteSize = actualBufferSizeInFrames * ma_get_bytes_per_sample(pData->formatOut); + pBufferList->mBuffers[iBuffer].mData = (ma_uint8*)pBufferList + ((sizeof(AudioBufferList) - sizeof(AudioBuffer)) + (sizeof(AudioBuffer) * pData->channelsOut)) + (actualBufferSizeInFrames * ma_get_bytes_per_sample(pData->formatOut) * iBuffer); } } @@ -17571,67 +17571,67 @@ mal_result mal_device_init_internal__coreaudio(mal_context* pContext, mal_device // Callbacks. AURenderCallbackStruct callbackInfo; callbackInfo.inputProcRefCon = pDevice_DoNotReference; - if (deviceType == mal_device_type_playback) { - callbackInfo.inputProc = mal_on_output__coreaudio; - status = ((mal_AudioUnitSetProperty_proc)pContext->coreaudio.AudioUnitSetProperty)(pData->audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Global, MA_COREAUDIO_OUTPUT_BUS, &callbackInfo, sizeof(callbackInfo)); + if (deviceType == ma_device_type_playback) { + callbackInfo.inputProc = ma_on_output__coreaudio; + status = ((ma_AudioUnitSetProperty_proc)pContext->coreaudio.AudioUnitSetProperty)(pData->audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Global, MA_COREAUDIO_OUTPUT_BUS, &callbackInfo, sizeof(callbackInfo)); if (status != noErr) { - ((mal_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(pData->audioUnit); - return mal_result_from_OSStatus(status); + ((ma_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(pData->audioUnit); + return ma_result_from_OSStatus(status); } } else { - callbackInfo.inputProc = mal_on_input__coreaudio; - status = ((mal_AudioUnitSetProperty_proc)pContext->coreaudio.AudioUnitSetProperty)(pData->audioUnit, kAudioOutputUnitProperty_SetInputCallback, kAudioUnitScope_Global, MA_COREAUDIO_INPUT_BUS, &callbackInfo, sizeof(callbackInfo)); + callbackInfo.inputProc = ma_on_input__coreaudio; + status = ((ma_AudioUnitSetProperty_proc)pContext->coreaudio.AudioUnitSetProperty)(pData->audioUnit, kAudioOutputUnitProperty_SetInputCallback, kAudioUnitScope_Global, MA_COREAUDIO_INPUT_BUS, &callbackInfo, sizeof(callbackInfo)); if (status != noErr) { - ((mal_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(pData->audioUnit); - return mal_result_from_OSStatus(status); + ((ma_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(pData->audioUnit); + return ma_result_from_OSStatus(status); } } // We need to listen for stop events. if (pData->registerStopEvent) { - status = ((mal_AudioUnitAddPropertyListener_proc)pContext->coreaudio.AudioUnitAddPropertyListener)(pData->audioUnit, kAudioOutputUnitProperty_IsRunning, on_start_stop__coreaudio, pDevice_DoNotReference); + status = ((ma_AudioUnitAddPropertyListener_proc)pContext->coreaudio.AudioUnitAddPropertyListener)(pData->audioUnit, kAudioOutputUnitProperty_IsRunning, on_start_stop__coreaudio, pDevice_DoNotReference); if (status != noErr) { - ((mal_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(pData->audioUnit); - return mal_result_from_OSStatus(status); + ((ma_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(pData->audioUnit); + return ma_result_from_OSStatus(status); } } // Initialize the audio unit. - status = ((mal_AudioUnitInitialize_proc)pContext->coreaudio.AudioUnitInitialize)(pData->audioUnit); + status = ((ma_AudioUnitInitialize_proc)pContext->coreaudio.AudioUnitInitialize)(pData->audioUnit); if (status != noErr) { - mal_free(pData->pAudioBufferList); + ma_free(pData->pAudioBufferList); pData->pAudioBufferList = NULL; - ((mal_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(pData->audioUnit); - return mal_result_from_OSStatus(status); + ((ma_AudioComponentInstanceDispose_proc)pContext->coreaudio.AudioComponentInstanceDispose)(pData->audioUnit); + return ma_result_from_OSStatus(status); } // Grab the name. #if defined(MA_APPLE_DESKTOP) - mal_get_AudioObject_name(pContext, deviceObjectID, sizeof(pData->deviceName), pData->deviceName); + ma_get_AudioObject_name(pContext, deviceObjectID, sizeof(pData->deviceName), pData->deviceName); #else - if (deviceType == mal_device_type_playback) { - mal_strcpy_s(pData->deviceName, sizeof(pData->deviceName), MA_DEFAULT_PLAYBACK_DEVICE_NAME); + if (deviceType == ma_device_type_playback) { + ma_strcpy_s(pData->deviceName, sizeof(pData->deviceName), MA_DEFAULT_PLAYBACK_DEVICE_NAME); } else { - mal_strcpy_s(pData->deviceName, sizeof(pData->deviceName), MA_DEFAULT_CAPTURE_DEVICE_NAME); + ma_strcpy_s(pData->deviceName, sizeof(pData->deviceName), MA_DEFAULT_CAPTURE_DEVICE_NAME); } #endif return result; } -mal_result mal_device_reinit_internal__coreaudio(mal_device* pDevice, mal_device_type deviceType, mal_bool32 disposePreviousAudioUnit) +ma_result ma_device_reinit_internal__coreaudio(ma_device* pDevice, ma_device_type deviceType, ma_bool32 disposePreviousAudioUnit) { /* This should only be called for playback or capture, not duplex. */ - if (deviceType == mal_device_type_duplex) { + if (deviceType == ma_device_type_duplex) { return MA_INVALID_ARGS; } - mal_device_init_internal_data__coreaudio data; - if (deviceType == mal_device_type_capture) { + ma_device_init_internal_data__coreaudio data; + if (deviceType == ma_device_type_capture) { data.formatIn = pDevice->capture.format; data.channelsIn = pDevice->capture.channels; data.sampleRateIn = pDevice->sampleRate; - mal_copy_memory(data.channelMapIn, pDevice->capture.channelMap, sizeof(pDevice->capture.channelMap)); + ma_copy_memory(data.channelMapIn, pDevice->capture.channelMap, sizeof(pDevice->capture.channelMap)); data.usingDefaultFormat = pDevice->capture.usingDefaultFormat; data.usingDefaultChannels = pDevice->capture.usingDefaultChannels; data.usingDefaultSampleRate = pDevice->usingDefaultSampleRate; @@ -17640,46 +17640,46 @@ mal_result mal_device_reinit_internal__coreaudio(mal_device* pDevice, mal_device data.registerStopEvent = MA_TRUE; if (disposePreviousAudioUnit) { - ((mal_AudioOutputUnitStop_proc)pDevice->pContext->coreaudio.AudioOutputUnitStop)((AudioUnit)pDevice->coreaudio.audioUnitCapture); - ((mal_AudioComponentInstanceDispose_proc)pDevice->pContext->coreaudio.AudioComponentInstanceDispose)((AudioUnit)pDevice->coreaudio.audioUnitCapture); + ((ma_AudioOutputUnitStop_proc)pDevice->pContext->coreaudio.AudioOutputUnitStop)((AudioUnit)pDevice->coreaudio.audioUnitCapture); + ((ma_AudioComponentInstanceDispose_proc)pDevice->pContext->coreaudio.AudioComponentInstanceDispose)((AudioUnit)pDevice->coreaudio.audioUnitCapture); } if (pDevice->coreaudio.pAudioBufferList) { - mal_free(pDevice->coreaudio.pAudioBufferList); + ma_free(pDevice->coreaudio.pAudioBufferList); } #if defined(MA_APPLE_DESKTOP) - pDevice->coreaudio.deviceObjectIDCapture = (mal_uint32)data.deviceObjectID; + pDevice->coreaudio.deviceObjectIDCapture = (ma_uint32)data.deviceObjectID; #endif - pDevice->coreaudio.audioUnitCapture = (mal_ptr)data.audioUnit; - pDevice->coreaudio.pAudioBufferList = (mal_ptr)data.pAudioBufferList; + pDevice->coreaudio.audioUnitCapture = (ma_ptr)data.audioUnit; + pDevice->coreaudio.pAudioBufferList = (ma_ptr)data.pAudioBufferList; } - if (deviceType == mal_device_type_playback) { + if (deviceType == ma_device_type_playback) { data.formatIn = pDevice->playback.format; data.channelsIn = pDevice->playback.channels; data.sampleRateIn = pDevice->sampleRate; - mal_copy_memory(data.channelMapIn, pDevice->playback.channelMap, sizeof(pDevice->playback.channelMap)); + ma_copy_memory(data.channelMapIn, pDevice->playback.channelMap, sizeof(pDevice->playback.channelMap)); data.usingDefaultFormat = pDevice->playback.usingDefaultFormat; data.usingDefaultChannels = pDevice->playback.usingDefaultChannels; data.usingDefaultSampleRate = pDevice->usingDefaultSampleRate; data.usingDefaultChannelMap = pDevice->playback.usingDefaultChannelMap; data.shareMode = pDevice->playback.shareMode; - data.registerStopEvent = (pDevice->type != mal_device_type_duplex); + data.registerStopEvent = (pDevice->type != ma_device_type_duplex); if (disposePreviousAudioUnit) { - ((mal_AudioOutputUnitStop_proc)pDevice->pContext->coreaudio.AudioOutputUnitStop)((AudioUnit)pDevice->coreaudio.audioUnitPlayback); - ((mal_AudioComponentInstanceDispose_proc)pDevice->pContext->coreaudio.AudioComponentInstanceDispose)((AudioUnit)pDevice->coreaudio.audioUnitPlayback); + ((ma_AudioOutputUnitStop_proc)pDevice->pContext->coreaudio.AudioOutputUnitStop)((AudioUnit)pDevice->coreaudio.audioUnitPlayback); + ((ma_AudioComponentInstanceDispose_proc)pDevice->pContext->coreaudio.AudioComponentInstanceDispose)((AudioUnit)pDevice->coreaudio.audioUnitPlayback); } #if defined(MA_APPLE_DESKTOP) - pDevice->coreaudio.deviceObjectIDPlayback = (mal_uint32)data.deviceObjectID; + pDevice->coreaudio.deviceObjectIDPlayback = (ma_uint32)data.deviceObjectID; #endif - pDevice->coreaudio.audioUnitPlayback = (mal_ptr)data.audioUnit; + pDevice->coreaudio.audioUnitPlayback = (ma_ptr)data.audioUnit; } data.bufferSizeInFramesIn = pDevice->coreaudio.originalBufferSizeInFrames; data.bufferSizeInMillisecondsIn = pDevice->coreaudio.originalBufferSizeInMilliseconds; data.periodsIn = pDevice->coreaudio.originalPeriods; - mal_result result = mal_device_init_internal__coreaudio(pDevice->pContext, deviceType, NULL, &data, (void*)pDevice); + ma_result result = ma_device_init_internal__coreaudio(pDevice->pContext, deviceType, NULL, &data, (void*)pDevice); if (result != MA_SUCCESS) { return result; } @@ -17688,27 +17688,27 @@ mal_result mal_device_reinit_internal__coreaudio(mal_device* pDevice, mal_device } -mal_result mal_device_init__coreaudio(mal_context* pContext, const mal_device_config* pConfig, mal_device* pDevice) +ma_result ma_device_init__coreaudio(ma_context* pContext, const ma_device_config* pConfig, ma_device* pDevice) { (void)pConfig; - mal_assert(pContext != NULL); - mal_assert(pConfig != NULL); - mal_assert(pDevice != NULL); + ma_assert(pContext != NULL); + ma_assert(pConfig != NULL); + ma_assert(pDevice != NULL); /* No exclusive mode with the Core Audio backend for now. */ - if (((pConfig->deviceType == mal_device_type_capture || pConfig->deviceType == mal_device_type_duplex) && pConfig->capture.shareMode == mal_share_mode_exclusive) || - ((pConfig->deviceType == mal_device_type_playback || pConfig->deviceType == mal_device_type_duplex) && pConfig->playback.shareMode == mal_share_mode_exclusive)) { + if (((pConfig->deviceType == ma_device_type_capture || pConfig->deviceType == ma_device_type_duplex) && pConfig->capture.shareMode == ma_share_mode_exclusive) || + ((pConfig->deviceType == ma_device_type_playback || pConfig->deviceType == ma_device_type_duplex) && pConfig->playback.shareMode == ma_share_mode_exclusive)) { return MA_SHARE_MODE_NOT_SUPPORTED; } /* Capture needs to be initialized first. */ - if (pConfig->deviceType == mal_device_type_capture || pConfig->deviceType == mal_device_type_duplex) { - mal_device_init_internal_data__coreaudio data; + if (pConfig->deviceType == ma_device_type_capture || pConfig->deviceType == ma_device_type_duplex) { + ma_device_init_internal_data__coreaudio data; data.formatIn = pConfig->capture.format; data.channelsIn = pConfig->capture.channels; data.sampleRateIn = pConfig->sampleRate; - mal_copy_memory(data.channelMapIn, pConfig->capture.channelMap, sizeof(pConfig->capture.channelMap)); + ma_copy_memory(data.channelMapIn, pConfig->capture.channelMap, sizeof(pConfig->capture.channelMap)); data.usingDefaultFormat = pDevice->capture.usingDefaultFormat; data.usingDefaultChannels = pDevice->capture.usingDefaultChannels; data.usingDefaultSampleRate = pDevice->usingDefaultSampleRate; @@ -17718,22 +17718,22 @@ mal_result mal_device_init__coreaudio(mal_context* pContext, const mal_device_co data.bufferSizeInMillisecondsIn = pConfig->bufferSizeInMilliseconds; data.registerStopEvent = MA_TRUE; - mal_result result = mal_device_init_internal__coreaudio(pDevice->pContext, mal_device_type_capture, pConfig->capture.pDeviceID, &data, (void*)pDevice); + ma_result result = ma_device_init_internal__coreaudio(pDevice->pContext, ma_device_type_capture, pConfig->capture.pDeviceID, &data, (void*)pDevice); if (result != MA_SUCCESS) { return result; } pDevice->coreaudio.isDefaultCaptureDevice = (pConfig->capture.pDeviceID == NULL); #if defined(MA_APPLE_DESKTOP) - pDevice->coreaudio.deviceObjectIDCapture = (mal_uint32)data.deviceObjectID; + pDevice->coreaudio.deviceObjectIDCapture = (ma_uint32)data.deviceObjectID; #endif - pDevice->coreaudio.audioUnitCapture = (mal_ptr)data.audioUnit; - pDevice->coreaudio.pAudioBufferList = (mal_ptr)data.pAudioBufferList; + pDevice->coreaudio.audioUnitCapture = (ma_ptr)data.audioUnit; + pDevice->coreaudio.pAudioBufferList = (ma_ptr)data.pAudioBufferList; pDevice->capture.internalFormat = data.formatOut; pDevice->capture.internalChannels = data.channelsOut; pDevice->capture.internalSampleRate = data.sampleRateOut; - mal_copy_memory(pDevice->capture.internalChannelMap, data.channelMapOut, sizeof(data.channelMapOut)); + ma_copy_memory(pDevice->capture.internalChannelMap, data.channelMapOut, sizeof(data.channelMapOut)); pDevice->capture.internalBufferSizeInFrames = data.bufferSizeInFramesOut; pDevice->capture.internalPeriods = data.periodsOut; @@ -17746,18 +17746,18 @@ mal_result mal_device_init__coreaudio(mal_context* pContext, const mal_device_co propAddress.mSelector = kAudioHardwarePropertyDefaultInputDevice; propAddress.mScope = kAudioObjectPropertyScopeGlobal; propAddress.mElement = kAudioObjectPropertyElementMaster; - ((mal_AudioObjectAddPropertyListener_proc)pDevice->pContext->coreaudio.AudioObjectAddPropertyListener)(kAudioObjectSystemObject, &propAddress, &mal_default_device_changed__coreaudio, pDevice); + ((ma_AudioObjectAddPropertyListener_proc)pDevice->pContext->coreaudio.AudioObjectAddPropertyListener)(kAudioObjectSystemObject, &propAddress, &ma_default_device_changed__coreaudio, pDevice); } #endif } /* Playback. */ - if (pConfig->deviceType == mal_device_type_playback || pConfig->deviceType == mal_device_type_duplex) { - mal_device_init_internal_data__coreaudio data; + if (pConfig->deviceType == ma_device_type_playback || pConfig->deviceType == ma_device_type_duplex) { + ma_device_init_internal_data__coreaudio data; data.formatIn = pConfig->playback.format; data.channelsIn = pConfig->playback.channels; data.sampleRateIn = pConfig->sampleRate; - mal_copy_memory(data.channelMapIn, pConfig->playback.channelMap, sizeof(pConfig->playback.channelMap)); + ma_copy_memory(data.channelMapIn, pConfig->playback.channelMap, sizeof(pConfig->playback.channelMap)); data.usingDefaultFormat = pDevice->playback.usingDefaultFormat; data.usingDefaultChannels = pDevice->playback.usingDefaultChannels; data.usingDefaultSampleRate = pDevice->usingDefaultSampleRate; @@ -17765,7 +17765,7 @@ mal_result mal_device_init__coreaudio(mal_context* pContext, const mal_device_co data.shareMode = pConfig->playback.shareMode; /* In full-duplex mode we want the playback buffer to be the same size as the capture buffer. */ - if (pConfig->deviceType == mal_device_type_duplex) { + if (pConfig->deviceType == ma_device_type_duplex) { data.bufferSizeInFramesIn = pDevice->capture.internalBufferSizeInFrames; data.periodsIn = pDevice->capture.internalPeriods; data.registerStopEvent = MA_FALSE; @@ -17776,12 +17776,12 @@ mal_result mal_device_init__coreaudio(mal_context* pContext, const mal_device_co data.registerStopEvent = MA_TRUE; } - mal_result result = mal_device_init_internal__coreaudio(pDevice->pContext, mal_device_type_playback, pConfig->playback.pDeviceID, &data, (void*)pDevice); + ma_result result = ma_device_init_internal__coreaudio(pDevice->pContext, ma_device_type_playback, pConfig->playback.pDeviceID, &data, (void*)pDevice); if (result != MA_SUCCESS) { - if (pConfig->deviceType == mal_device_type_duplex) { - ((mal_AudioComponentInstanceDispose_proc)pDevice->pContext->coreaudio.AudioComponentInstanceDispose)((AudioUnit)pDevice->coreaudio.audioUnitCapture); + if (pConfig->deviceType == ma_device_type_duplex) { + ((ma_AudioComponentInstanceDispose_proc)pDevice->pContext->coreaudio.AudioComponentInstanceDispose)((AudioUnit)pDevice->coreaudio.audioUnitCapture); if (pDevice->coreaudio.pAudioBufferList) { - mal_free(pDevice->coreaudio.pAudioBufferList); + ma_free(pDevice->coreaudio.pAudioBufferList); } } return result; @@ -17789,14 +17789,14 @@ mal_result mal_device_init__coreaudio(mal_context* pContext, const mal_device_co pDevice->coreaudio.isDefaultPlaybackDevice = (pConfig->playback.pDeviceID == NULL); #if defined(MA_APPLE_DESKTOP) - pDevice->coreaudio.deviceObjectIDPlayback = (mal_uint32)data.deviceObjectID; + pDevice->coreaudio.deviceObjectIDPlayback = (ma_uint32)data.deviceObjectID; #endif - pDevice->coreaudio.audioUnitPlayback = (mal_ptr)data.audioUnit; + pDevice->coreaudio.audioUnitPlayback = (ma_ptr)data.audioUnit; pDevice->playback.internalFormat = data.formatOut; pDevice->playback.internalChannels = data.channelsOut; pDevice->playback.internalSampleRate = data.sampleRateOut; - mal_copy_memory(pDevice->playback.internalChannelMap, data.channelMapOut, sizeof(data.channelMapOut)); + ma_copy_memory(pDevice->playback.internalChannelMap, data.channelMapOut, sizeof(data.channelMapOut)); pDevice->playback.internalBufferSizeInFrames = data.bufferSizeInFramesOut; pDevice->playback.internalPeriods = data.periodsOut; @@ -17809,7 +17809,7 @@ mal_result mal_device_init__coreaudio(mal_context* pContext, const mal_device_co propAddress.mSelector = kAudioHardwarePropertyDefaultOutputDevice; propAddress.mScope = kAudioObjectPropertyScopeGlobal; propAddress.mElement = kAudioObjectPropertyElementMaster; - ((mal_AudioObjectAddPropertyListener_proc)pDevice->pContext->coreaudio.AudioObjectAddPropertyListener)(kAudioObjectSystemObject, &propAddress, &mal_default_device_changed__coreaudio, pDevice); + ((ma_AudioObjectAddPropertyListener_proc)pDevice->pContext->coreaudio.AudioObjectAddPropertyListener)(kAudioObjectSystemObject, &propAddress, &ma_default_device_changed__coreaudio, pDevice); } #endif } @@ -17820,16 +17820,16 @@ mal_result mal_device_init__coreaudio(mal_context* pContext, const mal_device_co /* When stopping the device, a callback is called on another thread. We need to wait for this callback - before returning from mal_device_stop(). This event is used for this. + before returning from ma_device_stop(). This event is used for this. */ - mal_event_init(pContext, &pDevice->coreaudio.stopEvent); + ma_event_init(pContext, &pDevice->coreaudio.stopEvent); /* Need a ring buffer for duplex mode. */ - if (pConfig->deviceType == mal_device_type_duplex) { - mal_uint32 rbSizeInFrames = (mal_uint32)mal_calculate_frame_count_after_src(pDevice->sampleRate, pDevice->capture.internalSampleRate, pDevice->capture.internalBufferSizeInFrames); - mal_result result = mal_pcm_rb_init(pDevice->capture.format, pDevice->capture.channels, rbSizeInFrames, NULL, &pDevice->coreaudio.duplexRB); + if (pConfig->deviceType == ma_device_type_duplex) { + ma_uint32 rbSizeInFrames = (ma_uint32)ma_calculate_frame_count_after_src(pDevice->sampleRate, pDevice->capture.internalSampleRate, pDevice->capture.internalBufferSizeInFrames); + ma_result result = ma_pcm_rb_init(pDevice->capture.format, pDevice->capture.channels, rbSizeInFrames, NULL, &pDevice->coreaudio.duplexRB); if (result != MA_SUCCESS) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[Core Audio] Failed to initialize ring buffer.", result); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[Core Audio] Failed to initialize ring buffer.", result); } } @@ -17837,83 +17837,83 @@ mal_result mal_device_init__coreaudio(mal_context* pContext, const mal_device_co } -mal_result mal_device_start__coreaudio(mal_device* pDevice) +ma_result ma_device_start__coreaudio(ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { - OSStatus status = ((mal_AudioOutputUnitStart_proc)pDevice->pContext->coreaudio.AudioOutputUnitStart)((AudioUnit)pDevice->coreaudio.audioUnitCapture); + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { + OSStatus status = ((ma_AudioOutputUnitStart_proc)pDevice->pContext->coreaudio.AudioOutputUnitStart)((AudioUnit)pDevice->coreaudio.audioUnitCapture); if (status != noErr) { - return mal_result_from_OSStatus(status); + return ma_result_from_OSStatus(status); } } - if (pDevice->type == mal_device_type_playback || pDevice->type == mal_device_type_duplex) { - OSStatus status = ((mal_AudioOutputUnitStart_proc)pDevice->pContext->coreaudio.AudioOutputUnitStart)((AudioUnit)pDevice->coreaudio.audioUnitPlayback); + if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) { + OSStatus status = ((ma_AudioOutputUnitStart_proc)pDevice->pContext->coreaudio.AudioOutputUnitStart)((AudioUnit)pDevice->coreaudio.audioUnitPlayback); if (status != noErr) { - if (pDevice->type == mal_device_type_duplex) { - ((mal_AudioOutputUnitStop_proc)pDevice->pContext->coreaudio.AudioOutputUnitStop)((AudioUnit)pDevice->coreaudio.audioUnitCapture); + if (pDevice->type == ma_device_type_duplex) { + ((ma_AudioOutputUnitStop_proc)pDevice->pContext->coreaudio.AudioOutputUnitStop)((AudioUnit)pDevice->coreaudio.audioUnitCapture); } - return mal_result_from_OSStatus(status); + return ma_result_from_OSStatus(status); } } return MA_SUCCESS; } -mal_result mal_device_stop__coreaudio(mal_device* pDevice) +ma_result ma_device_stop__coreaudio(ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { - OSStatus status = ((mal_AudioOutputUnitStop_proc)pDevice->pContext->coreaudio.AudioOutputUnitStop)((AudioUnit)pDevice->coreaudio.audioUnitCapture); + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { + OSStatus status = ((ma_AudioOutputUnitStop_proc)pDevice->pContext->coreaudio.AudioOutputUnitStop)((AudioUnit)pDevice->coreaudio.audioUnitCapture); if (status != noErr) { - return mal_result_from_OSStatus(status); + return ma_result_from_OSStatus(status); } } - if (pDevice->type == mal_device_type_playback || pDevice->type == mal_device_type_duplex) { - OSStatus status = ((mal_AudioOutputUnitStop_proc)pDevice->pContext->coreaudio.AudioOutputUnitStop)((AudioUnit)pDevice->coreaudio.audioUnitPlayback); + if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) { + OSStatus status = ((ma_AudioOutputUnitStop_proc)pDevice->pContext->coreaudio.AudioOutputUnitStop)((AudioUnit)pDevice->coreaudio.audioUnitPlayback); if (status != noErr) { - return mal_result_from_OSStatus(status); + return ma_result_from_OSStatus(status); } } /* We need to wait for the callback to finish before returning. */ - mal_event_wait(&pDevice->coreaudio.stopEvent); + ma_event_wait(&pDevice->coreaudio.stopEvent); return MA_SUCCESS; } -mal_result mal_context_uninit__coreaudio(mal_context* pContext) +ma_result ma_context_uninit__coreaudio(ma_context* pContext) { - mal_assert(pContext != NULL); - mal_assert(pContext->backend == mal_backend_coreaudio); + ma_assert(pContext != NULL); + ma_assert(pContext->backend == ma_backend_coreaudio); #if !defined(MA_NO_RUNTIME_LINKING) && !defined(MA_APPLE_MOBILE) - mal_dlclose(pContext->coreaudio.hAudioUnit); - mal_dlclose(pContext->coreaudio.hCoreAudio); - mal_dlclose(pContext->coreaudio.hCoreFoundation); + ma_dlclose(pContext->coreaudio.hAudioUnit); + ma_dlclose(pContext->coreaudio.hCoreAudio); + ma_dlclose(pContext->coreaudio.hCoreFoundation); #endif (void)pContext; return MA_SUCCESS; } -mal_result mal_context_init__coreaudio(mal_context* pContext) +ma_result ma_context_init__coreaudio(ma_context* pContext) { - mal_assert(pContext != NULL); + ma_assert(pContext != NULL); #if defined(MA_APPLE_MOBILE) @autoreleasepool { AVAudioSession* pAudioSession = [AVAudioSession sharedInstance]; - mal_assert(pAudioSession != NULL); + ma_assert(pAudioSession != NULL); [pAudioSession setCategory: AVAudioSessionCategoryPlayAndRecord error:nil]; // By default we want miniaudio to use the speakers instead of the receiver. In the future this may // be customizable. - mal_bool32 useSpeakers = MA_TRUE; + ma_bool32 useSpeakers = MA_TRUE; if (useSpeakers) { [pAudioSession overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:nil]; } @@ -17921,92 +17921,92 @@ mal_result mal_context_init__coreaudio(mal_context* pContext) #endif #if !defined(MA_NO_RUNTIME_LINKING) && !defined(MA_APPLE_MOBILE) - pContext->coreaudio.hCoreFoundation = mal_dlopen("CoreFoundation.framework/CoreFoundation"); + pContext->coreaudio.hCoreFoundation = ma_dlopen("CoreFoundation.framework/CoreFoundation"); if (pContext->coreaudio.hCoreFoundation == NULL) { return MA_API_NOT_FOUND; } - pContext->coreaudio.CFStringGetCString = mal_dlsym(pContext->coreaudio.hCoreFoundation, "CFStringGetCString"); + pContext->coreaudio.CFStringGetCString = ma_dlsym(pContext->coreaudio.hCoreFoundation, "CFStringGetCString"); - pContext->coreaudio.hCoreAudio = mal_dlopen("CoreAudio.framework/CoreAudio"); + pContext->coreaudio.hCoreAudio = ma_dlopen("CoreAudio.framework/CoreAudio"); if (pContext->coreaudio.hCoreAudio == NULL) { - mal_dlclose(pContext->coreaudio.hCoreFoundation); + ma_dlclose(pContext->coreaudio.hCoreFoundation); return MA_API_NOT_FOUND; } - pContext->coreaudio.AudioObjectGetPropertyData = mal_dlsym(pContext->coreaudio.hCoreAudio, "AudioObjectGetPropertyData"); - pContext->coreaudio.AudioObjectGetPropertyDataSize = mal_dlsym(pContext->coreaudio.hCoreAudio, "AudioObjectGetPropertyDataSize"); - pContext->coreaudio.AudioObjectSetPropertyData = mal_dlsym(pContext->coreaudio.hCoreAudio, "AudioObjectSetPropertyData"); - pContext->coreaudio.AudioObjectAddPropertyListener = mal_dlsym(pContext->coreaudio.hCoreAudio, "AudioObjectAddPropertyListener"); + pContext->coreaudio.AudioObjectGetPropertyData = ma_dlsym(pContext->coreaudio.hCoreAudio, "AudioObjectGetPropertyData"); + pContext->coreaudio.AudioObjectGetPropertyDataSize = ma_dlsym(pContext->coreaudio.hCoreAudio, "AudioObjectGetPropertyDataSize"); + pContext->coreaudio.AudioObjectSetPropertyData = ma_dlsym(pContext->coreaudio.hCoreAudio, "AudioObjectSetPropertyData"); + pContext->coreaudio.AudioObjectAddPropertyListener = ma_dlsym(pContext->coreaudio.hCoreAudio, "AudioObjectAddPropertyListener"); // It looks like Apple has moved some APIs from AudioUnit into AudioToolbox on more recent versions of macOS. They are still // defined in AudioUnit, but just in case they decide to remove them from there entirely I'm going to implement a fallback. // The way it'll work is that it'll first try AudioUnit, and if the required symbols are not present there we'll fall back to // AudioToolbox. - pContext->coreaudio.hAudioUnit = mal_dlopen("AudioUnit.framework/AudioUnit"); + pContext->coreaudio.hAudioUnit = ma_dlopen("AudioUnit.framework/AudioUnit"); if (pContext->coreaudio.hAudioUnit == NULL) { - mal_dlclose(pContext->coreaudio.hCoreAudio); - mal_dlclose(pContext->coreaudio.hCoreFoundation); + ma_dlclose(pContext->coreaudio.hCoreAudio); + ma_dlclose(pContext->coreaudio.hCoreFoundation); return MA_API_NOT_FOUND; } - if (mal_dlsym(pContext->coreaudio.hAudioUnit, "AudioComponentFindNext") == NULL) { + if (ma_dlsym(pContext->coreaudio.hAudioUnit, "AudioComponentFindNext") == NULL) { // Couldn't find the required symbols in AudioUnit, so fall back to AudioToolbox. - mal_dlclose(pContext->coreaudio.hAudioUnit); - pContext->coreaudio.hAudioUnit = mal_dlopen("AudioToolbox.framework/AudioToolbox"); + ma_dlclose(pContext->coreaudio.hAudioUnit); + pContext->coreaudio.hAudioUnit = ma_dlopen("AudioToolbox.framework/AudioToolbox"); if (pContext->coreaudio.hAudioUnit == NULL) { - mal_dlclose(pContext->coreaudio.hCoreAudio); - mal_dlclose(pContext->coreaudio.hCoreFoundation); + ma_dlclose(pContext->coreaudio.hCoreAudio); + ma_dlclose(pContext->coreaudio.hCoreFoundation); return MA_API_NOT_FOUND; } } - pContext->coreaudio.AudioComponentFindNext = mal_dlsym(pContext->coreaudio.hAudioUnit, "AudioComponentFindNext"); - pContext->coreaudio.AudioComponentInstanceDispose = mal_dlsym(pContext->coreaudio.hAudioUnit, "AudioComponentInstanceDispose"); - pContext->coreaudio.AudioComponentInstanceNew = mal_dlsym(pContext->coreaudio.hAudioUnit, "AudioComponentInstanceNew"); - pContext->coreaudio.AudioOutputUnitStart = mal_dlsym(pContext->coreaudio.hAudioUnit, "AudioOutputUnitStart"); - pContext->coreaudio.AudioOutputUnitStop = mal_dlsym(pContext->coreaudio.hAudioUnit, "AudioOutputUnitStop"); - pContext->coreaudio.AudioUnitAddPropertyListener = mal_dlsym(pContext->coreaudio.hAudioUnit, "AudioUnitAddPropertyListener"); - pContext->coreaudio.AudioUnitGetPropertyInfo = mal_dlsym(pContext->coreaudio.hAudioUnit, "AudioUnitGetPropertyInfo"); - pContext->coreaudio.AudioUnitGetProperty = mal_dlsym(pContext->coreaudio.hAudioUnit, "AudioUnitGetProperty"); - pContext->coreaudio.AudioUnitSetProperty = mal_dlsym(pContext->coreaudio.hAudioUnit, "AudioUnitSetProperty"); - pContext->coreaudio.AudioUnitInitialize = mal_dlsym(pContext->coreaudio.hAudioUnit, "AudioUnitInitialize"); - pContext->coreaudio.AudioUnitRender = mal_dlsym(pContext->coreaudio.hAudioUnit, "AudioUnitRender"); + pContext->coreaudio.AudioComponentFindNext = ma_dlsym(pContext->coreaudio.hAudioUnit, "AudioComponentFindNext"); + pContext->coreaudio.AudioComponentInstanceDispose = ma_dlsym(pContext->coreaudio.hAudioUnit, "AudioComponentInstanceDispose"); + pContext->coreaudio.AudioComponentInstanceNew = ma_dlsym(pContext->coreaudio.hAudioUnit, "AudioComponentInstanceNew"); + pContext->coreaudio.AudioOutputUnitStart = ma_dlsym(pContext->coreaudio.hAudioUnit, "AudioOutputUnitStart"); + pContext->coreaudio.AudioOutputUnitStop = ma_dlsym(pContext->coreaudio.hAudioUnit, "AudioOutputUnitStop"); + pContext->coreaudio.AudioUnitAddPropertyListener = ma_dlsym(pContext->coreaudio.hAudioUnit, "AudioUnitAddPropertyListener"); + pContext->coreaudio.AudioUnitGetPropertyInfo = ma_dlsym(pContext->coreaudio.hAudioUnit, "AudioUnitGetPropertyInfo"); + pContext->coreaudio.AudioUnitGetProperty = ma_dlsym(pContext->coreaudio.hAudioUnit, "AudioUnitGetProperty"); + pContext->coreaudio.AudioUnitSetProperty = ma_dlsym(pContext->coreaudio.hAudioUnit, "AudioUnitSetProperty"); + pContext->coreaudio.AudioUnitInitialize = ma_dlsym(pContext->coreaudio.hAudioUnit, "AudioUnitInitialize"); + pContext->coreaudio.AudioUnitRender = ma_dlsym(pContext->coreaudio.hAudioUnit, "AudioUnitRender"); #else - pContext->coreaudio.CFStringGetCString = (mal_proc)CFStringGetCString; + pContext->coreaudio.CFStringGetCString = (ma_proc)CFStringGetCString; #if defined(MA_APPLE_DESKTOP) - pContext->coreaudio.AudioObjectGetPropertyData = (mal_proc)AudioObjectGetPropertyData; - pContext->coreaudio.AudioObjectGetPropertyDataSize = (mal_proc)AudioObjectGetPropertyDataSize; - pContext->coreaudio.AudioObjectSetPropertyData = (mal_proc)AudioObjectSetPropertyData; - pContext->coreaudio.AudioObjectAddPropertyListener = (mal_proc)AudioObjectAddPropertyListener; + pContext->coreaudio.AudioObjectGetPropertyData = (ma_proc)AudioObjectGetPropertyData; + pContext->coreaudio.AudioObjectGetPropertyDataSize = (ma_proc)AudioObjectGetPropertyDataSize; + pContext->coreaudio.AudioObjectSetPropertyData = (ma_proc)AudioObjectSetPropertyData; + pContext->coreaudio.AudioObjectAddPropertyListener = (ma_proc)AudioObjectAddPropertyListener; #endif - pContext->coreaudio.AudioComponentFindNext = (mal_proc)AudioComponentFindNext; - pContext->coreaudio.AudioComponentInstanceDispose = (mal_proc)AudioComponentInstanceDispose; - pContext->coreaudio.AudioComponentInstanceNew = (mal_proc)AudioComponentInstanceNew; - pContext->coreaudio.AudioOutputUnitStart = (mal_proc)AudioOutputUnitStart; - pContext->coreaudio.AudioOutputUnitStop = (mal_proc)AudioOutputUnitStop; - pContext->coreaudio.AudioUnitAddPropertyListener = (mal_proc)AudioUnitAddPropertyListener; - pContext->coreaudio.AudioUnitGetPropertyInfo = (mal_proc)AudioUnitGetPropertyInfo; - pContext->coreaudio.AudioUnitGetProperty = (mal_proc)AudioUnitGetProperty; - pContext->coreaudio.AudioUnitSetProperty = (mal_proc)AudioUnitSetProperty; - pContext->coreaudio.AudioUnitInitialize = (mal_proc)AudioUnitInitialize; - pContext->coreaudio.AudioUnitRender = (mal_proc)AudioUnitRender; + pContext->coreaudio.AudioComponentFindNext = (ma_proc)AudioComponentFindNext; + pContext->coreaudio.AudioComponentInstanceDispose = (ma_proc)AudioComponentInstanceDispose; + pContext->coreaudio.AudioComponentInstanceNew = (ma_proc)AudioComponentInstanceNew; + pContext->coreaudio.AudioOutputUnitStart = (ma_proc)AudioOutputUnitStart; + pContext->coreaudio.AudioOutputUnitStop = (ma_proc)AudioOutputUnitStop; + pContext->coreaudio.AudioUnitAddPropertyListener = (ma_proc)AudioUnitAddPropertyListener; + pContext->coreaudio.AudioUnitGetPropertyInfo = (ma_proc)AudioUnitGetPropertyInfo; + pContext->coreaudio.AudioUnitGetProperty = (ma_proc)AudioUnitGetProperty; + pContext->coreaudio.AudioUnitSetProperty = (ma_proc)AudioUnitSetProperty; + pContext->coreaudio.AudioUnitInitialize = (ma_proc)AudioUnitInitialize; + pContext->coreaudio.AudioUnitRender = (ma_proc)AudioUnitRender; #endif pContext->isBackendAsynchronous = MA_TRUE; - pContext->onUninit = mal_context_uninit__coreaudio; - pContext->onDeviceIDEqual = mal_context_is_device_id_equal__coreaudio; - pContext->onEnumDevices = mal_context_enumerate_devices__coreaudio; - pContext->onGetDeviceInfo = mal_context_get_device_info__coreaudio; - pContext->onDeviceInit = mal_device_init__coreaudio; - pContext->onDeviceUninit = mal_device_uninit__coreaudio; - pContext->onDeviceStart = mal_device_start__coreaudio; - pContext->onDeviceStop = mal_device_stop__coreaudio; + pContext->onUninit = ma_context_uninit__coreaudio; + pContext->onDeviceIDEqual = ma_context_is_device_id_equal__coreaudio; + pContext->onEnumDevices = ma_context_enumerate_devices__coreaudio; + pContext->onGetDeviceInfo = ma_context_get_device_info__coreaudio; + pContext->onDeviceInit = ma_device_init__coreaudio; + pContext->onDeviceUninit = ma_device_uninit__coreaudio; + pContext->onDeviceStart = ma_device_start__coreaudio; + pContext->onDeviceStop = ma_device_stop__coreaudio; // Audio component. AudioComponentDescription desc; @@ -18020,12 +18020,12 @@ mal_result mal_context_init__coreaudio(mal_context* pContext) desc.componentFlags = 0; desc.componentFlagsMask = 0; - pContext->coreaudio.component = ((mal_AudioComponentFindNext_proc)pContext->coreaudio.AudioComponentFindNext)(NULL, &desc); + pContext->coreaudio.component = ((ma_AudioComponentFindNext_proc)pContext->coreaudio.AudioComponentFindNext)(NULL, &desc); if (pContext->coreaudio.component == NULL) { #if !defined(MA_NO_RUNTIME_LINKING) && !defined(MA_APPLE_MOBILE) - mal_dlclose(pContext->coreaudio.hAudioUnit); - mal_dlclose(pContext->coreaudio.hCoreAudio); - mal_dlclose(pContext->coreaudio.hCoreFoundation); + ma_dlclose(pContext->coreaudio.hAudioUnit); + ma_dlclose(pContext->coreaudio.hCoreAudio); + ma_dlclose(pContext->coreaudio.hCoreFoundation); #endif return MA_FAILED_TO_INIT_BACKEND; } @@ -18065,9 +18065,9 @@ mal_result mal_context_init__coreaudio(mal_context* pContext) #define MA_SIO_NRATE 16 #define MA_SIO_NCONF 4 -struct mal_sio_hdl; // <-- Opaque +struct ma_sio_hdl; // <-- Opaque -struct mal_sio_par +struct ma_sio_par { unsigned int bits; unsigned int bps; @@ -18085,7 +18085,7 @@ struct mal_sio_par unsigned int __magic; }; -struct mal_sio_enc +struct ma_sio_enc { unsigned int bits; unsigned int bps; @@ -18094,7 +18094,7 @@ struct mal_sio_enc unsigned int msb; }; -struct mal_sio_conf +struct ma_sio_conf { unsigned int enc; unsigned int rchan; @@ -18102,59 +18102,59 @@ struct mal_sio_conf unsigned int rate; }; -struct mal_sio_cap +struct ma_sio_cap { - struct mal_sio_enc enc[MA_SIO_NENC]; + struct ma_sio_enc enc[MA_SIO_NENC]; unsigned int rchan[MA_SIO_NCHAN]; unsigned int pchan[MA_SIO_NCHAN]; unsigned int rate[MA_SIO_NRATE]; int __pad[7]; unsigned int nconf; - struct mal_sio_conf confs[MA_SIO_NCONF]; + struct ma_sio_conf confs[MA_SIO_NCONF]; }; -typedef struct mal_sio_hdl* (* mal_sio_open_proc) (const char*, unsigned int, int); -typedef void (* mal_sio_close_proc) (struct mal_sio_hdl*); -typedef int (* mal_sio_setpar_proc) (struct mal_sio_hdl*, struct mal_sio_par*); -typedef int (* mal_sio_getpar_proc) (struct mal_sio_hdl*, struct mal_sio_par*); -typedef int (* mal_sio_getcap_proc) (struct mal_sio_hdl*, struct mal_sio_cap*); -typedef size_t (* mal_sio_write_proc) (struct mal_sio_hdl*, const void*, size_t); -typedef size_t (* mal_sio_read_proc) (struct mal_sio_hdl*, void*, size_t); -typedef int (* mal_sio_start_proc) (struct mal_sio_hdl*); -typedef int (* mal_sio_stop_proc) (struct mal_sio_hdl*); -typedef int (* mal_sio_initpar_proc)(struct mal_sio_par*); +typedef struct ma_sio_hdl* (* ma_sio_open_proc) (const char*, unsigned int, int); +typedef void (* ma_sio_close_proc) (struct ma_sio_hdl*); +typedef int (* ma_sio_setpar_proc) (struct ma_sio_hdl*, struct ma_sio_par*); +typedef int (* ma_sio_getpar_proc) (struct ma_sio_hdl*, struct ma_sio_par*); +typedef int (* ma_sio_getcap_proc) (struct ma_sio_hdl*, struct ma_sio_cap*); +typedef size_t (* ma_sio_write_proc) (struct ma_sio_hdl*, const void*, size_t); +typedef size_t (* ma_sio_read_proc) (struct ma_sio_hdl*, void*, size_t); +typedef int (* ma_sio_start_proc) (struct ma_sio_hdl*); +typedef int (* ma_sio_stop_proc) (struct ma_sio_hdl*); +typedef int (* ma_sio_initpar_proc)(struct ma_sio_par*); -mal_format mal_format_from_sio_enc__sndio(unsigned int bits, unsigned int bps, unsigned int sig, unsigned int le, unsigned int msb) +ma_format ma_format_from_sio_enc__sndio(unsigned int bits, unsigned int bps, unsigned int sig, unsigned int le, unsigned int msb) { // We only support native-endian right now. - if ((mal_is_little_endian() && le == 0) || (mal_is_big_endian() && le == 1)) { - return mal_format_unknown; + if ((ma_is_little_endian() && le == 0) || (ma_is_big_endian() && le == 1)) { + return ma_format_unknown; } if (bits == 8 && bps == 1 && sig == 0) { - return mal_format_u8; + return ma_format_u8; } if (bits == 16 && bps == 2 && sig == 1) { - return mal_format_s16; + return ma_format_s16; } if (bits == 24 && bps == 3 && sig == 1) { - return mal_format_s24; + return ma_format_s24; } if (bits == 24 && bps == 4 && sig == 1 && msb == 0) { - //return mal_format_s24_32; + //return ma_format_s24_32; } if (bits == 32 && bps == 4 && sig == 1) { - return mal_format_s32; + return ma_format_s32; } - return mal_format_unknown; + return ma_format_unknown; } -mal_format mal_find_best_format_from_sio_cap__sndio(struct mal_sio_cap* caps) +ma_format ma_find_best_format_from_sio_cap__sndio(struct ma_sio_cap* caps) { - mal_assert(caps != NULL); + ma_assert(caps != NULL); - mal_format bestFormat = mal_format_unknown; + ma_format bestFormat = ma_format_unknown; for (unsigned int iConfig = 0; iConfig < caps->nconf; iConfig += 1) { for (unsigned int iEncoding = 0; iEncoding < MA_SIO_NENC; iEncoding += 1) { if ((caps->confs[iConfig].enc & (1UL << iEncoding)) == 0) { @@ -18166,31 +18166,31 @@ mal_format mal_find_best_format_from_sio_cap__sndio(struct mal_sio_cap* caps) unsigned int sig = caps->enc[iEncoding].sig; unsigned int le = caps->enc[iEncoding].le; unsigned int msb = caps->enc[iEncoding].msb; - mal_format format = mal_format_from_sio_enc__sndio(bits, bps, sig, le, msb); - if (format == mal_format_unknown) { + ma_format format = ma_format_from_sio_enc__sndio(bits, bps, sig, le, msb); + if (format == ma_format_unknown) { continue; // Format not supported. } - if (bestFormat == mal_format_unknown) { + if (bestFormat == ma_format_unknown) { bestFormat = format; } else { - if (mal_get_format_priority_index(bestFormat) > mal_get_format_priority_index(format)) { // <-- Lower = better. + if (ma_get_format_priority_index(bestFormat) > ma_get_format_priority_index(format)) { // <-- Lower = better. bestFormat = format; } } } } - return mal_format_unknown; + return ma_format_unknown; } -mal_uint32 mal_find_best_channels_from_sio_cap__sndio(struct mal_sio_cap* caps, mal_device_type deviceType, mal_format requiredFormat) +ma_uint32 ma_find_best_channels_from_sio_cap__sndio(struct ma_sio_cap* caps, ma_device_type deviceType, ma_format requiredFormat) { - mal_assert(caps != NULL); - mal_assert(requiredFormat != mal_format_unknown); + ma_assert(caps != NULL); + ma_assert(requiredFormat != ma_format_unknown); // Just pick whatever configuration has the most channels. - mal_uint32 maxChannels = 0; + ma_uint32 maxChannels = 0; for (unsigned int iConfig = 0; iConfig < caps->nconf; iConfig += 1) { // The encoding should be of requiredFormat. for (unsigned int iEncoding = 0; iEncoding < MA_SIO_NENC; iEncoding += 1) { @@ -18203,7 +18203,7 @@ mal_uint32 mal_find_best_channels_from_sio_cap__sndio(struct mal_sio_cap* caps, unsigned int sig = caps->enc[iEncoding].sig; unsigned int le = caps->enc[iEncoding].le; unsigned int msb = caps->enc[iEncoding].msb; - mal_format format = mal_format_from_sio_enc__sndio(bits, bps, sig, le, msb); + ma_format format = ma_format_from_sio_enc__sndio(bits, bps, sig, le, msb); if (format != requiredFormat) { continue; } @@ -18211,7 +18211,7 @@ mal_uint32 mal_find_best_channels_from_sio_cap__sndio(struct mal_sio_cap* caps, // Getting here means the format is supported. Iterate over each channel count and grab the biggest one. for (unsigned int iChannel = 0; iChannel < MA_SIO_NCHAN; iChannel += 1) { unsigned int chan = 0; - if (deviceType == mal_device_type_playback) { + if (deviceType == ma_device_type_playback) { chan = caps->confs[iConfig].pchan; } else { chan = caps->confs[iConfig].rchan; @@ -18222,7 +18222,7 @@ mal_uint32 mal_find_best_channels_from_sio_cap__sndio(struct mal_sio_cap* caps, } unsigned int channels; - if (deviceType == mal_device_type_playback) { + if (deviceType == ma_device_type_playback) { channels = caps->pchan[iChannel]; } else { channels = caps->rchan[iChannel]; @@ -18238,16 +18238,16 @@ mal_uint32 mal_find_best_channels_from_sio_cap__sndio(struct mal_sio_cap* caps, return maxChannels; } -mal_uint32 mal_find_best_sample_rate_from_sio_cap__sndio(struct mal_sio_cap* caps, mal_device_type deviceType, mal_format requiredFormat, mal_uint32 requiredChannels) +ma_uint32 ma_find_best_sample_rate_from_sio_cap__sndio(struct ma_sio_cap* caps, ma_device_type deviceType, ma_format requiredFormat, ma_uint32 requiredChannels) { - mal_assert(caps != NULL); - mal_assert(requiredFormat != mal_format_unknown); - mal_assert(requiredChannels > 0); - mal_assert(requiredChannels <= MA_MAX_CHANNELS); + ma_assert(caps != NULL); + ma_assert(requiredFormat != ma_format_unknown); + ma_assert(requiredChannels > 0); + ma_assert(requiredChannels <= MA_MAX_CHANNELS); - mal_uint32 firstSampleRate = 0; // <-- If the device does not support a standard rate we'll fall back to the first one that's found. + ma_uint32 firstSampleRate = 0; // <-- If the device does not support a standard rate we'll fall back to the first one that's found. - mal_uint32 bestSampleRate = 0; + ma_uint32 bestSampleRate = 0; for (unsigned int iConfig = 0; iConfig < caps->nconf; iConfig += 1) { // The encoding should be of requiredFormat. for (unsigned int iEncoding = 0; iEncoding < MA_SIO_NENC; iEncoding += 1) { @@ -18260,7 +18260,7 @@ mal_uint32 mal_find_best_sample_rate_from_sio_cap__sndio(struct mal_sio_cap* cap unsigned int sig = caps->enc[iEncoding].sig; unsigned int le = caps->enc[iEncoding].le; unsigned int msb = caps->enc[iEncoding].msb; - mal_format format = mal_format_from_sio_enc__sndio(bits, bps, sig, le, msb); + ma_format format = ma_format_from_sio_enc__sndio(bits, bps, sig, le, msb); if (format != requiredFormat) { continue; } @@ -18268,7 +18268,7 @@ mal_uint32 mal_find_best_sample_rate_from_sio_cap__sndio(struct mal_sio_cap* cap // Getting here means the format is supported. Iterate over each channel count and grab the biggest one. for (unsigned int iChannel = 0; iChannel < MA_SIO_NCHAN; iChannel += 1) { unsigned int chan = 0; - if (deviceType == mal_device_type_playback) { + if (deviceType == ma_device_type_playback) { chan = caps->confs[iConfig].pchan; } else { chan = caps->confs[iConfig].rchan; @@ -18279,7 +18279,7 @@ mal_uint32 mal_find_best_sample_rate_from_sio_cap__sndio(struct mal_sio_cap* cap } unsigned int channels; - if (deviceType == mal_device_type_playback) { + if (deviceType == ma_device_type_playback) { channels = caps->pchan[iChannel]; } else { channels = caps->rchan[iChannel]; @@ -18291,19 +18291,19 @@ mal_uint32 mal_find_best_sample_rate_from_sio_cap__sndio(struct mal_sio_cap* cap // Getting here means we have found a compatible encoding/channel pair. for (unsigned int iRate = 0; iRate < MA_SIO_NRATE; iRate += 1) { - mal_uint32 rate = (mal_uint32)caps->rate[iRate]; + ma_uint32 rate = (ma_uint32)caps->rate[iRate]; if (firstSampleRate == 0) { firstSampleRate = rate; } // Disregard this rate if it's not a standard one. - mal_uint32 ratePriority = mal_get_standard_sample_rate_priority_index(rate); - if (ratePriority == (mal_uint32)-1) { + ma_uint32 ratePriority = ma_get_standard_sample_rate_priority_index(rate); + if (ratePriority == (ma_uint32)-1) { continue; } - if (mal_get_standard_sample_rate_priority_index(bestSampleRate) > ratePriority) { // Lower = better. + if (ma_get_standard_sample_rate_priority_index(bestSampleRate) > ratePriority) { // Lower = better. bestSampleRate = rate; } } @@ -18320,83 +18320,83 @@ mal_uint32 mal_find_best_sample_rate_from_sio_cap__sndio(struct mal_sio_cap* cap } -mal_bool32 mal_context_is_device_id_equal__sndio(mal_context* pContext, const mal_device_id* pID0, const mal_device_id* pID1) +ma_bool32 ma_context_is_device_id_equal__sndio(ma_context* pContext, const ma_device_id* pID0, const ma_device_id* pID1) { - mal_assert(pContext != NULL); - mal_assert(pID0 != NULL); - mal_assert(pID1 != NULL); + ma_assert(pContext != NULL); + ma_assert(pID0 != NULL); + ma_assert(pID1 != NULL); (void)pContext; - return mal_strcmp(pID0->sndio, pID1->sndio) == 0; + return ma_strcmp(pID0->sndio, pID1->sndio) == 0; } -mal_result mal_context_enumerate_devices__sndio(mal_context* pContext, mal_enum_devices_callback_proc callback, void* pUserData) +ma_result ma_context_enumerate_devices__sndio(ma_context* pContext, ma_enum_devices_callback_proc callback, void* pUserData) { - mal_assert(pContext != NULL); - mal_assert(callback != NULL); + ma_assert(pContext != NULL); + ma_assert(callback != NULL); // sndio doesn't seem to have a good device enumeration API, so I'm therefore only enumerating // over default devices for now. - mal_bool32 isTerminating = MA_FALSE; - struct mal_sio_hdl* handle; + ma_bool32 isTerminating = MA_FALSE; + struct ma_sio_hdl* handle; // Playback. if (!isTerminating) { - handle = ((mal_sio_open_proc)pContext->sndio.sio_open)(MA_SIO_DEVANY, MA_SIO_PLAY, 0); + handle = ((ma_sio_open_proc)pContext->sndio.sio_open)(MA_SIO_DEVANY, MA_SIO_PLAY, 0); if (handle != NULL) { // Supports playback. - mal_device_info deviceInfo; - mal_zero_object(&deviceInfo); - mal_strcpy_s(deviceInfo.id.sndio, sizeof(deviceInfo.id.sndio), MA_SIO_DEVANY); - mal_strcpy_s(deviceInfo.name, sizeof(deviceInfo.name), MA_DEFAULT_PLAYBACK_DEVICE_NAME); + ma_device_info deviceInfo; + ma_zero_object(&deviceInfo); + ma_strcpy_s(deviceInfo.id.sndio, sizeof(deviceInfo.id.sndio), MA_SIO_DEVANY); + ma_strcpy_s(deviceInfo.name, sizeof(deviceInfo.name), MA_DEFAULT_PLAYBACK_DEVICE_NAME); - isTerminating = !callback(pContext, mal_device_type_playback, &deviceInfo, pUserData); + isTerminating = !callback(pContext, ma_device_type_playback, &deviceInfo, pUserData); - ((mal_sio_close_proc)pContext->sndio.sio_close)(handle); + ((ma_sio_close_proc)pContext->sndio.sio_close)(handle); } } // Capture. if (!isTerminating) { - handle = ((mal_sio_open_proc)pContext->sndio.sio_open)(MA_SIO_DEVANY, MA_SIO_REC, 0); + handle = ((ma_sio_open_proc)pContext->sndio.sio_open)(MA_SIO_DEVANY, MA_SIO_REC, 0); if (handle != NULL) { // Supports capture. - mal_device_info deviceInfo; - mal_zero_object(&deviceInfo); - mal_strcpy_s(deviceInfo.id.sndio, sizeof(deviceInfo.id.sndio), "default"); - mal_strcpy_s(deviceInfo.name, sizeof(deviceInfo.name), MA_DEFAULT_CAPTURE_DEVICE_NAME); + ma_device_info deviceInfo; + ma_zero_object(&deviceInfo); + ma_strcpy_s(deviceInfo.id.sndio, sizeof(deviceInfo.id.sndio), "default"); + ma_strcpy_s(deviceInfo.name, sizeof(deviceInfo.name), MA_DEFAULT_CAPTURE_DEVICE_NAME); - isTerminating = !callback(pContext, mal_device_type_capture, &deviceInfo, pUserData); + isTerminating = !callback(pContext, ma_device_type_capture, &deviceInfo, pUserData); - ((mal_sio_close_proc)pContext->sndio.sio_close)(handle); + ((ma_sio_close_proc)pContext->sndio.sio_close)(handle); } } return MA_SUCCESS; } -mal_result mal_context_get_device_info__sndio(mal_context* pContext, mal_device_type deviceType, const mal_device_id* pDeviceID, mal_share_mode shareMode, mal_device_info* pDeviceInfo) +ma_result ma_context_get_device_info__sndio(ma_context* pContext, ma_device_type deviceType, const ma_device_id* pDeviceID, ma_share_mode shareMode, ma_device_info* pDeviceInfo) { - mal_assert(pContext != NULL); + ma_assert(pContext != NULL); (void)shareMode; // We need to open the device before we can get information about it. char devid[256]; if (pDeviceID == NULL) { - mal_strcpy_s(devid, sizeof(devid), MA_SIO_DEVANY); - mal_strcpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), (deviceType == mal_device_type_playback) ? MA_DEFAULT_PLAYBACK_DEVICE_NAME : MA_DEFAULT_CAPTURE_DEVICE_NAME); + ma_strcpy_s(devid, sizeof(devid), MA_SIO_DEVANY); + ma_strcpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), (deviceType == ma_device_type_playback) ? MA_DEFAULT_PLAYBACK_DEVICE_NAME : MA_DEFAULT_CAPTURE_DEVICE_NAME); } else { - mal_strcpy_s(devid, sizeof(devid), pDeviceID->sndio); - mal_strcpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), devid); + ma_strcpy_s(devid, sizeof(devid), pDeviceID->sndio); + ma_strcpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), devid); } - struct mal_sio_hdl* handle = ((mal_sio_open_proc)pContext->sndio.sio_open)(devid, (deviceType == mal_device_type_playback) ? MA_SIO_PLAY : MA_SIO_REC, 0); + struct ma_sio_hdl* handle = ((ma_sio_open_proc)pContext->sndio.sio_open)(devid, (deviceType == ma_device_type_playback) ? MA_SIO_PLAY : MA_SIO_REC, 0); if (handle == NULL) { return MA_NO_DEVICE; } - struct mal_sio_cap caps; - if (((mal_sio_getcap_proc)pContext->sndio.sio_getcap)(handle, &caps) == 0) { + struct ma_sio_cap caps; + if (((ma_sio_getcap_proc)pContext->sndio.sio_getcap)(handle, &caps) == 0) { return MA_ERROR; } @@ -18413,14 +18413,14 @@ mal_result mal_context_get_device_info__sndio(mal_context* pContext, mal_device_ unsigned int sig = caps.enc[iEncoding].sig; unsigned int le = caps.enc[iEncoding].le; unsigned int msb = caps.enc[iEncoding].msb; - mal_format format = mal_format_from_sio_enc__sndio(bits, bps, sig, le, msb); - if (format == mal_format_unknown) { + ma_format format = ma_format_from_sio_enc__sndio(bits, bps, sig, le, msb); + if (format == ma_format_unknown) { continue; // Format not supported. } // Add this format if it doesn't already exist. - mal_bool32 formatExists = MA_FALSE; - for (mal_uint32 iExistingFormat = 0; iExistingFormat < pDeviceInfo->formatCount; iExistingFormat += 1) { + ma_bool32 formatExists = MA_FALSE; + for (ma_uint32 iExistingFormat = 0; iExistingFormat < pDeviceInfo->formatCount; iExistingFormat += 1) { if (pDeviceInfo->formats[iExistingFormat] == format) { formatExists = MA_TRUE; break; @@ -18435,7 +18435,7 @@ mal_result mal_context_get_device_info__sndio(mal_context* pContext, mal_device_ // Channels. for (unsigned int iChannel = 0; iChannel < MA_SIO_NCHAN; iChannel += 1) { unsigned int chan = 0; - if (deviceType == mal_device_type_playback) { + if (deviceType == ma_device_type_playback) { chan = caps.confs[iConfig].pchan; } else { chan = caps.confs[iConfig].rchan; @@ -18446,7 +18446,7 @@ mal_result mal_context_get_device_info__sndio(mal_context* pContext, mal_device_ } unsigned int channels; - if (deviceType == mal_device_type_playback) { + if (deviceType == ma_device_type_playback) { channels = caps.pchan[iChannel]; } else { channels = caps.rchan[iChannel]; @@ -18474,47 +18474,47 @@ mal_result mal_context_get_device_info__sndio(mal_context* pContext, mal_device_ } } - ((mal_sio_close_proc)pContext->sndio.sio_close)(handle); + ((ma_sio_close_proc)pContext->sndio.sio_close)(handle); return MA_SUCCESS; } -void mal_device_uninit__sndio(mal_device* pDevice) +void ma_device_uninit__sndio(ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { - ((mal_sio_close_proc)pDevice->pContext->sndio.sio_close)((struct mal_sio_hdl*)pDevice->sndio.handleCapture); + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { + ((ma_sio_close_proc)pDevice->pContext->sndio.sio_close)((struct ma_sio_hdl*)pDevice->sndio.handleCapture); } - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { - ((mal_sio_close_proc)pDevice->pContext->sndio.sio_close)((struct mal_sio_hdl*)pDevice->sndio.handlePlayback); + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { + ((ma_sio_close_proc)pDevice->pContext->sndio.sio_close)((struct ma_sio_hdl*)pDevice->sndio.handlePlayback); } } -mal_result mal_device_init_handle__sndio(mal_context* pContext, const mal_device_config* pConfig, mal_device_type deviceType, mal_device* pDevice) +ma_result ma_device_init_handle__sndio(ma_context* pContext, const ma_device_config* pConfig, ma_device_type deviceType, ma_device* pDevice) { - mal_result result; + ma_result result; const char* pDeviceName; - mal_ptr handle; + ma_ptr handle; int openFlags = 0; - struct mal_sio_cap caps; - struct mal_sio_par par; - mal_device_id* pDeviceID; - mal_format format; - mal_uint32 channels; - mal_uint32 sampleRate; - mal_format internalFormat; - mal_uint32 internalChannels; - mal_uint32 internalSampleRate; - mal_uint32 internalBufferSizeInFrames; - mal_uint32 internalPeriods; + struct ma_sio_cap caps; + struct ma_sio_par par; + ma_device_id* pDeviceID; + ma_format format; + ma_uint32 channels; + ma_uint32 sampleRate; + ma_format internalFormat; + ma_uint32 internalChannels; + ma_uint32 internalSampleRate; + ma_uint32 internalBufferSizeInFrames; + ma_uint32 internalPeriods; - mal_assert(pContext != NULL); - mal_assert(pConfig != NULL); - mal_assert(deviceType != mal_device_type_duplex); - mal_assert(pDevice != NULL); + ma_assert(pContext != NULL); + ma_assert(pConfig != NULL); + ma_assert(deviceType != ma_device_type_duplex); + ma_assert(pDevice != NULL); - if (deviceType == mal_device_type_capture) { + if (deviceType == ma_device_type_capture) { openFlags = MA_SIO_REC; pDeviceID = pConfig->capture.pDeviceID; format = pConfig->capture.format; @@ -18533,15 +18533,15 @@ mal_result mal_device_init_handle__sndio(mal_context* pContext, const mal_device pDeviceName = pDeviceID->sndio; } - handle = (mal_ptr)((mal_sio_open_proc)pContext->sndio.sio_open)(pDeviceName, openFlags, 0); + handle = (ma_ptr)((ma_sio_open_proc)pContext->sndio.sio_open)(pDeviceName, openFlags, 0); if (handle == NULL) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[sndio] Failed to open device.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[sndio] Failed to open device.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } /* We need to retrieve the device caps to determine the most appropriate format to use. */ - if (((mal_sio_getcap_proc)pContext->sndio.sio_getcap)((struct mal_sio_hdl*)handle, &caps) == 0) { - ((mal_sio_close_proc)pContext->sndio.sio_close)((struct mal_sio_hdl*)handle); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[sndio] Failed to retrieve device caps.", MA_ERROR); + if (((ma_sio_getcap_proc)pContext->sndio.sio_getcap)((struct ma_sio_hdl*)handle, &caps) == 0) { + ((ma_sio_close_proc)pContext->sndio.sio_close)((struct ma_sio_hdl*)handle); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[sndio] Failed to retrieve device caps.", MA_ERROR); } /* @@ -18550,61 +18550,61 @@ mal_result mal_device_init_handle__sndio(mal_context* pContext, const mal_device to the requested channels, regardless of whether or not the default channel count is requested. For hardware devices, I'm suspecting only a single channel count will be reported and we can safely use the - value returned by mal_find_best_channels_from_sio_cap__sndio(). + value returned by ma_find_best_channels_from_sio_cap__sndio(). */ - if (deviceType == mal_device_type_capture) { + if (deviceType == ma_device_type_capture) { if (pDevice->capture.usingDefaultFormat) { - format = mal_find_best_format_from_sio_cap__sndio(&caps); + format = ma_find_best_format_from_sio_cap__sndio(&caps); } if (pDevice->capture.usingDefaultChannels) { if (strlen(pDeviceName) > strlen("rsnd/") && strncmp(pDeviceName, "rsnd/", strlen("rsnd/")) == 0) { - channels = mal_find_best_channels_from_sio_cap__sndio(&caps, deviceType, format); + channels = ma_find_best_channels_from_sio_cap__sndio(&caps, deviceType, format); } } } else { if (pDevice->playback.usingDefaultFormat) { - format = mal_find_best_format_from_sio_cap__sndio(&caps); + format = ma_find_best_format_from_sio_cap__sndio(&caps); } if (pDevice->playback.usingDefaultChannels) { if (strlen(pDeviceName) > strlen("rsnd/") && strncmp(pDeviceName, "rsnd/", strlen("rsnd/")) == 0) { - channels = mal_find_best_channels_from_sio_cap__sndio(&caps, deviceType, format); + channels = ma_find_best_channels_from_sio_cap__sndio(&caps, deviceType, format); } } } if (pDevice->usingDefaultSampleRate) { - sampleRate = mal_find_best_sample_rate_from_sio_cap__sndio(&caps, pConfig->deviceType, format, channels); + sampleRate = ma_find_best_sample_rate_from_sio_cap__sndio(&caps, pConfig->deviceType, format, channels); } - ((mal_sio_initpar_proc)pDevice->pContext->sndio.sio_initpar)(&par); + ((ma_sio_initpar_proc)pDevice->pContext->sndio.sio_initpar)(&par); par.msb = 0; - par.le = mal_is_little_endian(); + par.le = ma_is_little_endian(); switch (format) { - case mal_format_u8: + case ma_format_u8: { par.bits = 8; par.bps = 1; par.sig = 0; } break; - case mal_format_s24: + case ma_format_s24: { par.bits = 24; par.bps = 3; par.sig = 1; } break; - case mal_format_s32: + case ma_format_s32: { par.bits = 32; par.bps = 4; par.sig = 1; } break; - case mal_format_s16: - case mal_format_f32: + case ma_format_s16: + case ma_format_f32: default: { par.bits = 16; @@ -18613,7 +18613,7 @@ mal_result mal_device_init_handle__sndio(mal_context* pContext, const mal_device } break; } - if (deviceType == mal_device_type_capture) { + if (deviceType == ma_device_type_capture) { par.rchan = channels; } else { par.pchan = channels; @@ -18623,33 +18623,33 @@ mal_result mal_device_init_handle__sndio(mal_context* pContext, const mal_device internalBufferSizeInFrames = pConfig->bufferSizeInFrames; if (internalBufferSizeInFrames == 0) { - internalBufferSizeInFrames = mal_calculate_buffer_size_in_frames_from_milliseconds(pConfig->bufferSizeInMilliseconds, par.rate); + internalBufferSizeInFrames = ma_calculate_buffer_size_in_frames_from_milliseconds(pConfig->bufferSizeInMilliseconds, par.rate); } par.round = internalBufferSizeInFrames / pConfig->periods; par.appbufsz = par.round * pConfig->periods; - if (((mal_sio_setpar_proc)pContext->sndio.sio_setpar)((struct mal_sio_hdl*)handle, &par) == 0) { - ((mal_sio_close_proc)pContext->sndio.sio_close)((struct mal_sio_hdl*)handle); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[sndio] Failed to set buffer size.", MA_FORMAT_NOT_SUPPORTED); + if (((ma_sio_setpar_proc)pContext->sndio.sio_setpar)((struct ma_sio_hdl*)handle, &par) == 0) { + ((ma_sio_close_proc)pContext->sndio.sio_close)((struct ma_sio_hdl*)handle); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[sndio] Failed to set buffer size.", MA_FORMAT_NOT_SUPPORTED); } - if (((mal_sio_getpar_proc)pContext->sndio.sio_getpar)((struct mal_sio_hdl*)handle, &par) == 0) { - ((mal_sio_close_proc)pContext->sndio.sio_close)((struct mal_sio_hdl*)handle); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[sndio] Failed to retrieve buffer size.", MA_FORMAT_NOT_SUPPORTED); + if (((ma_sio_getpar_proc)pContext->sndio.sio_getpar)((struct ma_sio_hdl*)handle, &par) == 0) { + ((ma_sio_close_proc)pContext->sndio.sio_close)((struct ma_sio_hdl*)handle); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[sndio] Failed to retrieve buffer size.", MA_FORMAT_NOT_SUPPORTED); } - internalFormat = mal_format_from_sio_enc__sndio(par.bits, par.bps, par.sig, par.le, par.msb); - internalChannels = (deviceType == mal_device_type_capture) ? par.rchan : par.pchan; + internalFormat = ma_format_from_sio_enc__sndio(par.bits, par.bps, par.sig, par.le, par.msb); + internalChannels = (deviceType == ma_device_type_capture) ? par.rchan : par.pchan; internalSampleRate = par.rate; internalPeriods = par.appbufsz / par.round; internalBufferSizeInFrames = par.appbufsz; - if (deviceType == mal_device_type_capture) { + if (deviceType == ma_device_type_capture) { pDevice->sndio.handleCapture = handle; pDevice->capture.internalFormat = internalFormat; pDevice->capture.internalChannels = internalChannels; pDevice->capture.internalSampleRate = internalSampleRate; - mal_get_standard_channel_map(mal_standard_channel_map_sndio, pDevice->capture.internalChannels, pDevice->capture.internalChannelMap); + ma_get_standard_channel_map(ma_standard_channel_map_sndio, pDevice->capture.internalChannels, pDevice->capture.internalChannelMap); pDevice->capture.internalBufferSizeInFrames = internalBufferSizeInFrames; pDevice->capture.internalPeriods = internalPeriods; } else { @@ -18657,14 +18657,14 @@ mal_result mal_device_init_handle__sndio(mal_context* pContext, const mal_device pDevice->playback.internalFormat = internalFormat; pDevice->playback.internalChannels = internalChannels; pDevice->playback.internalSampleRate = internalSampleRate; - mal_get_standard_channel_map(mal_standard_channel_map_sndio, pDevice->playback.internalChannels, pDevice->playback.internalChannelMap); + ma_get_standard_channel_map(ma_standard_channel_map_sndio, pDevice->playback.internalChannels, pDevice->playback.internalChannelMap); pDevice->playback.internalBufferSizeInFrames = internalBufferSizeInFrames; pDevice->playback.internalPeriods = internalPeriods; } #ifdef MA_DEBUG_OUTPUT printf("DEVICE INFO\n"); - printf(" Format: %s\n", mal_get_format_name(internalFormat)); + printf(" Format: %s\n", ma_get_format_name(internalFormat)); printf(" Channels: %d\n", internalChannels); printf(" Sample Rate: %d\n", internalSampleRate); printf(" Buffer Size: %d\n", internalBufferSizeInFrames); @@ -18676,21 +18676,21 @@ mal_result mal_device_init_handle__sndio(mal_context* pContext, const mal_device return MA_SUCCESS; } -mal_result mal_device_init__sndio(mal_context* pContext, const mal_device_config* pConfig, mal_device* pDevice) +ma_result ma_device_init__sndio(ma_context* pContext, const ma_device_config* pConfig, ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); - mal_zero_object(&pDevice->sndio); + ma_zero_object(&pDevice->sndio); - if (pConfig->deviceType == mal_device_type_capture || pConfig->deviceType == mal_device_type_duplex) { - mal_result result = mal_device_init_handle__sndio(pContext, pConfig, mal_device_type_capture, pDevice); + if (pConfig->deviceType == ma_device_type_capture || pConfig->deviceType == ma_device_type_duplex) { + ma_result result = ma_device_init_handle__sndio(pContext, pConfig, ma_device_type_capture, pDevice); if (result != MA_SUCCESS) { return result; } } - if (pConfig->deviceType == mal_device_type_playback || pConfig->deviceType == mal_device_type_duplex) { - mal_result result = mal_device_init_handle__sndio(pContext, pConfig, mal_device_type_playback, pDevice); + if (pConfig->deviceType == ma_device_type_playback || pConfig->deviceType == ma_device_type_duplex) { + ma_result result = ma_device_init_handle__sndio(pContext, pConfig, ma_device_type_playback, pDevice); if (result != MA_SUCCESS) { return result; } @@ -18699,69 +18699,69 @@ mal_result mal_device_init__sndio(mal_context* pContext, const mal_device_config return MA_SUCCESS; } -mal_result mal_device_stop__sndio(mal_device* pDevice) +ma_result ma_device_stop__sndio(ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { - ((mal_sio_stop_proc)pDevice->pContext->sndio.sio_stop)((struct mal_sio_hdl*)pDevice->sndio.handleCapture); - mal_atomic_exchange_32(&pDevice->sndio.isStartedCapture, MA_FALSE); + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { + ((ma_sio_stop_proc)pDevice->pContext->sndio.sio_stop)((struct ma_sio_hdl*)pDevice->sndio.handleCapture); + ma_atomic_exchange_32(&pDevice->sndio.isStartedCapture, MA_FALSE); } - if (pDevice->type == mal_device_type_playback || pDevice->type == mal_device_type_duplex) { - ((mal_sio_stop_proc)pDevice->pContext->sndio.sio_stop)((struct mal_sio_hdl*)pDevice->sndio.handlePlayback); - mal_atomic_exchange_32(&pDevice->sndio.isStartedPlayback, MA_FALSE); + if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) { + ((ma_sio_stop_proc)pDevice->pContext->sndio.sio_stop)((struct ma_sio_hdl*)pDevice->sndio.handlePlayback); + ma_atomic_exchange_32(&pDevice->sndio.isStartedPlayback, MA_FALSE); } return MA_SUCCESS; } -mal_result mal_device_write__sndio(mal_device* pDevice, const void* pPCMFrames, mal_uint32 frameCount) +ma_result ma_device_write__sndio(ma_device* pDevice, const void* pPCMFrames, ma_uint32 frameCount) { int result; if (!pDevice->sndio.isStartedPlayback) { - ((mal_sio_start_proc)pDevice->pContext->sndio.sio_start)((struct mal_sio_hdl*)pDevice->sndio.handlePlayback); /* <-- Doesn't actually playback until data is written. */ - mal_atomic_exchange_32(&pDevice->sndio.isStartedPlayback, MA_TRUE); + ((ma_sio_start_proc)pDevice->pContext->sndio.sio_start)((struct ma_sio_hdl*)pDevice->sndio.handlePlayback); /* <-- Doesn't actually playback until data is written. */ + ma_atomic_exchange_32(&pDevice->sndio.isStartedPlayback, MA_TRUE); } - result = ((mal_sio_write_proc)pDevice->pContext->sndio.sio_write)((struct mal_sio_hdl*)pDevice->sndio.handlePlayback, pPCMFrames, frameCount * mal_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels)); + result = ((ma_sio_write_proc)pDevice->pContext->sndio.sio_write)((struct ma_sio_hdl*)pDevice->sndio.handlePlayback, pPCMFrames, frameCount * ma_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels)); if (result == 0) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[sndio] Failed to send data from the client to the device.", MA_FAILED_TO_SEND_DATA_TO_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[sndio] Failed to send data from the client to the device.", MA_FAILED_TO_SEND_DATA_TO_DEVICE); } return MA_SUCCESS; } -mal_result mal_device_read__sndio(mal_device* pDevice, void* pPCMFrames, mal_uint32 frameCount) +ma_result ma_device_read__sndio(ma_device* pDevice, void* pPCMFrames, ma_uint32 frameCount) { int result; if (!pDevice->sndio.isStartedCapture) { - ((mal_sio_start_proc)pDevice->pContext->sndio.sio_start)((struct mal_sio_hdl*)pDevice->sndio.handleCapture); /* <-- Doesn't actually playback until data is written. */ - mal_atomic_exchange_32(&pDevice->sndio.isStartedCapture, MA_TRUE); + ((ma_sio_start_proc)pDevice->pContext->sndio.sio_start)((struct ma_sio_hdl*)pDevice->sndio.handleCapture); /* <-- Doesn't actually playback until data is written. */ + ma_atomic_exchange_32(&pDevice->sndio.isStartedCapture, MA_TRUE); } - result = ((mal_sio_read_proc)pDevice->pContext->sndio.sio_read)((struct mal_sio_hdl*)pDevice->sndio.handleCapture, pPCMFrames, frameCount * mal_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels)); + result = ((ma_sio_read_proc)pDevice->pContext->sndio.sio_read)((struct ma_sio_hdl*)pDevice->sndio.handleCapture, pPCMFrames, frameCount * ma_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels)); if (result == 0) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[sndio] Failed to read data from the device to be sent to the device.", MA_FAILED_TO_SEND_DATA_TO_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[sndio] Failed to read data from the device to be sent to the device.", MA_FAILED_TO_SEND_DATA_TO_DEVICE); } return MA_SUCCESS; } -mal_result mal_context_uninit__sndio(mal_context* pContext) +ma_result ma_context_uninit__sndio(ma_context* pContext) { - mal_assert(pContext != NULL); - mal_assert(pContext->backend == mal_backend_sndio); + ma_assert(pContext != NULL); + ma_assert(pContext->backend == ma_backend_sndio); (void)pContext; return MA_SUCCESS; } -mal_result mal_context_init__sndio(mal_context* pContext) +ma_result ma_context_init__sndio(ma_context* pContext) { - mal_assert(pContext != NULL); + ma_assert(pContext != NULL); #ifndef MA_NO_RUNTIME_LINKING // libpulse.so @@ -18769,8 +18769,8 @@ mal_result mal_context_init__sndio(mal_context* pContext) "libsndio.so" }; - for (size_t i = 0; i < mal_countof(libsndioNames); ++i) { - pContext->sndio.sndioSO = mal_dlopen(libsndioNames[i]); + for (size_t i = 0; i < ma_countof(libsndioNames); ++i) { + pContext->sndio.sndioSO = ma_dlopen(libsndioNames[i]); if (pContext->sndio.sndioSO != NULL) { break; } @@ -18780,16 +18780,16 @@ mal_result mal_context_init__sndio(mal_context* pContext) return MA_NO_BACKEND; } - pContext->sndio.sio_open = (mal_proc)mal_dlsym(pContext->sndio.sndioSO, "sio_open"); - pContext->sndio.sio_close = (mal_proc)mal_dlsym(pContext->sndio.sndioSO, "sio_close"); - pContext->sndio.sio_setpar = (mal_proc)mal_dlsym(pContext->sndio.sndioSO, "sio_setpar"); - pContext->sndio.sio_getpar = (mal_proc)mal_dlsym(pContext->sndio.sndioSO, "sio_getpar"); - pContext->sndio.sio_getcap = (mal_proc)mal_dlsym(pContext->sndio.sndioSO, "sio_getcap"); - pContext->sndio.sio_write = (mal_proc)mal_dlsym(pContext->sndio.sndioSO, "sio_write"); - pContext->sndio.sio_read = (mal_proc)mal_dlsym(pContext->sndio.sndioSO, "sio_read"); - pContext->sndio.sio_start = (mal_proc)mal_dlsym(pContext->sndio.sndioSO, "sio_start"); - pContext->sndio.sio_stop = (mal_proc)mal_dlsym(pContext->sndio.sndioSO, "sio_stop"); - pContext->sndio.sio_initpar = (mal_proc)mal_dlsym(pContext->sndio.sndioSO, "sio_initpar"); + pContext->sndio.sio_open = (ma_proc)ma_dlsym(pContext->sndio.sndioSO, "sio_open"); + pContext->sndio.sio_close = (ma_proc)ma_dlsym(pContext->sndio.sndioSO, "sio_close"); + pContext->sndio.sio_setpar = (ma_proc)ma_dlsym(pContext->sndio.sndioSO, "sio_setpar"); + pContext->sndio.sio_getpar = (ma_proc)ma_dlsym(pContext->sndio.sndioSO, "sio_getpar"); + pContext->sndio.sio_getcap = (ma_proc)ma_dlsym(pContext->sndio.sndioSO, "sio_getcap"); + pContext->sndio.sio_write = (ma_proc)ma_dlsym(pContext->sndio.sndioSO, "sio_write"); + pContext->sndio.sio_read = (ma_proc)ma_dlsym(pContext->sndio.sndioSO, "sio_read"); + pContext->sndio.sio_start = (ma_proc)ma_dlsym(pContext->sndio.sndioSO, "sio_start"); + pContext->sndio.sio_stop = (ma_proc)ma_dlsym(pContext->sndio.sndioSO, "sio_stop"); + pContext->sndio.sio_initpar = (ma_proc)ma_dlsym(pContext->sndio.sndioSO, "sio_initpar"); #else pContext->sndio.sio_open = sio_open; pContext->sndio.sio_close = sio_close; @@ -18803,16 +18803,16 @@ mal_result mal_context_init__sndio(mal_context* pContext) pContext->sndio.sio_initpar = sio_initpar; #endif - pContext->onUninit = mal_context_uninit__sndio; - pContext->onDeviceIDEqual = mal_context_is_device_id_equal__sndio; - pContext->onEnumDevices = mal_context_enumerate_devices__sndio; - pContext->onGetDeviceInfo = mal_context_get_device_info__sndio; - pContext->onDeviceInit = mal_device_init__sndio; - pContext->onDeviceUninit = mal_device_uninit__sndio; + pContext->onUninit = ma_context_uninit__sndio; + pContext->onDeviceIDEqual = ma_context_is_device_id_equal__sndio; + pContext->onEnumDevices = ma_context_enumerate_devices__sndio; + pContext->onGetDeviceInfo = ma_context_get_device_info__sndio; + pContext->onDeviceInit = ma_device_init__sndio; + pContext->onDeviceUninit = ma_device_uninit__sndio; pContext->onDeviceStart = NULL; /* Not required for synchronous backends. */ - pContext->onDeviceStop = mal_device_stop__sndio; - pContext->onDeviceWrite = mal_device_write__sndio; - pContext->onDeviceRead = mal_device_read__sndio; + pContext->onDeviceStop = ma_device_stop__sndio; + pContext->onDeviceWrite = ma_device_write__sndio; + pContext->onDeviceRead = ma_device_read__sndio; return MA_SUCCESS; } @@ -18841,24 +18841,24 @@ mal_result mal_context_init__sndio(mal_context* pContext) #endif #endif -void mal_construct_device_id__audio4(char* id, size_t idSize, const char* base, int deviceIndex) +void ma_construct_device_id__audio4(char* id, size_t idSize, const char* base, int deviceIndex) { - mal_assert(id != NULL); - mal_assert(idSize > 0); - mal_assert(deviceIndex >= 0); + ma_assert(id != NULL); + ma_assert(idSize > 0); + ma_assert(deviceIndex >= 0); size_t baseLen = strlen(base); - mal_assert(idSize > baseLen); + ma_assert(idSize > baseLen); - mal_strcpy_s(id, idSize, base); - mal_itoa_s(deviceIndex, id+baseLen, idSize-baseLen, 10); + ma_strcpy_s(id, idSize, base); + ma_itoa_s(deviceIndex, id+baseLen, idSize-baseLen, 10); } -mal_result mal_extract_device_index_from_id__audio4(const char* id, const char* base, int* pIndexOut) +ma_result ma_extract_device_index_from_id__audio4(const char* id, const char* base, int* pIndexOut) { - mal_assert(id != NULL); - mal_assert(base != NULL); - mal_assert(pIndexOut != NULL); + ma_assert(id != NULL); + ma_assert(base != NULL); + ma_assert(pIndexOut != NULL); size_t idLen = strlen(id); size_t baseLen = strlen(base); @@ -18882,110 +18882,110 @@ mal_result mal_extract_device_index_from_id__audio4(const char* id, const char* return MA_SUCCESS; } -mal_bool32 mal_context_is_device_id_equal__audio4(mal_context* pContext, const mal_device_id* pID0, const mal_device_id* pID1) +ma_bool32 ma_context_is_device_id_equal__audio4(ma_context* pContext, const ma_device_id* pID0, const ma_device_id* pID1) { - mal_assert(pContext != NULL); - mal_assert(pID0 != NULL); - mal_assert(pID1 != NULL); + ma_assert(pContext != NULL); + ma_assert(pID0 != NULL); + ma_assert(pID1 != NULL); (void)pContext; - return mal_strcmp(pID0->audio4, pID1->audio4) == 0; + return ma_strcmp(pID0->audio4, pID1->audio4) == 0; } #if !defined(MA_AUDIO4_USE_NEW_API) /* Old API */ -mal_format mal_format_from_encoding__audio4(unsigned int encoding, unsigned int precision) +ma_format ma_format_from_encoding__audio4(unsigned int encoding, unsigned int precision) { if (precision == 8 && (encoding == AUDIO_ENCODING_ULINEAR || encoding == AUDIO_ENCODING_ULINEAR || encoding == AUDIO_ENCODING_ULINEAR_LE || encoding == AUDIO_ENCODING_ULINEAR_BE)) { - return mal_format_u8; + return ma_format_u8; } else { - if (mal_is_little_endian() && encoding == AUDIO_ENCODING_SLINEAR_LE) { + if (ma_is_little_endian() && encoding == AUDIO_ENCODING_SLINEAR_LE) { if (precision == 16) { - return mal_format_s16; + return ma_format_s16; } else if (precision == 24) { - return mal_format_s24; + return ma_format_s24; } else if (precision == 32) { - return mal_format_s32; + return ma_format_s32; } - } else if (mal_is_big_endian() && encoding == AUDIO_ENCODING_SLINEAR_BE) { + } else if (ma_is_big_endian() && encoding == AUDIO_ENCODING_SLINEAR_BE) { if (precision == 16) { - return mal_format_s16; + return ma_format_s16; } else if (precision == 24) { - return mal_format_s24; + return ma_format_s24; } else if (precision == 32) { - return mal_format_s32; + return ma_format_s32; } } } - return mal_format_unknown; // Encoding not supported. + return ma_format_unknown; // Encoding not supported. } -void mal_encoding_from_format__audio4(mal_format format, unsigned int* pEncoding, unsigned int* pPrecision) +void ma_encoding_from_format__audio4(ma_format format, unsigned int* pEncoding, unsigned int* pPrecision) { - mal_assert(format != mal_format_unknown); - mal_assert(pEncoding != NULL); - mal_assert(pPrecision != NULL); + ma_assert(format != ma_format_unknown); + ma_assert(pEncoding != NULL); + ma_assert(pPrecision != NULL); switch (format) { - case mal_format_u8: + case ma_format_u8: { *pEncoding = AUDIO_ENCODING_ULINEAR; *pPrecision = 8; } break; - case mal_format_s24: + case ma_format_s24: { - *pEncoding = (mal_is_little_endian()) ? AUDIO_ENCODING_SLINEAR_LE : AUDIO_ENCODING_SLINEAR_BE; + *pEncoding = (ma_is_little_endian()) ? AUDIO_ENCODING_SLINEAR_LE : AUDIO_ENCODING_SLINEAR_BE; *pPrecision = 24; } break; - case mal_format_s32: + case ma_format_s32: { - *pEncoding = (mal_is_little_endian()) ? AUDIO_ENCODING_SLINEAR_LE : AUDIO_ENCODING_SLINEAR_BE; + *pEncoding = (ma_is_little_endian()) ? AUDIO_ENCODING_SLINEAR_LE : AUDIO_ENCODING_SLINEAR_BE; *pPrecision = 32; } break; - case mal_format_s16: - case mal_format_f32: + case ma_format_s16: + case ma_format_f32: default: { - *pEncoding = (mal_is_little_endian()) ? AUDIO_ENCODING_SLINEAR_LE : AUDIO_ENCODING_SLINEAR_BE; + *pEncoding = (ma_is_little_endian()) ? AUDIO_ENCODING_SLINEAR_LE : AUDIO_ENCODING_SLINEAR_BE; *pPrecision = 16; } break; } } -mal_format mal_format_from_prinfo__audio4(struct audio_prinfo* prinfo) +ma_format ma_format_from_prinfo__audio4(struct audio_prinfo* prinfo) { - return mal_format_from_encoding__audio4(prinfo->encoding, prinfo->precision); + return ma_format_from_encoding__audio4(prinfo->encoding, prinfo->precision); } #else -mal_format mal_format_from_swpar__audio4(struct audio_swpar* par) +ma_format ma_format_from_swpar__audio4(struct audio_swpar* par) { if (par->bits == 8 && par->bps == 1 && par->sig == 0) { - return mal_format_u8; + return ma_format_u8; } - if (par->bits == 16 && par->bps == 2 && par->sig == 1 && par->le == mal_is_little_endian()) { - return mal_format_s16; + if (par->bits == 16 && par->bps == 2 && par->sig == 1 && par->le == ma_is_little_endian()) { + return ma_format_s16; } - if (par->bits == 24 && par->bps == 3 && par->sig == 1 && par->le == mal_is_little_endian()) { - return mal_format_s24; + if (par->bits == 24 && par->bps == 3 && par->sig == 1 && par->le == ma_is_little_endian()) { + return ma_format_s24; } - if (par->bits == 32 && par->bps == 4 && par->sig == 1 && par->le == mal_is_little_endian()) { - return mal_format_f32; + if (par->bits == 32 && par->bps == 4 && par->sig == 1 && par->le == ma_is_little_endian()) { + return ma_format_f32; } // Format not supported. - return mal_format_unknown; + return ma_format_unknown; } #endif -mal_result mal_context_get_device_info_from_fd__audio4(mal_context* pContext, mal_device_type deviceType, int fd, mal_device_info* pInfoOut) +ma_result ma_context_get_device_info_from_fd__audio4(ma_context* pContext, ma_device_type deviceType, int fd, ma_device_info* pInfoOut) { - mal_assert(pContext != NULL); - mal_assert(fd >= 0); - mal_assert(pInfoOut != NULL); + ma_assert(pContext != NULL); + ma_assert(fd >= 0); + ma_assert(pInfoOut != NULL); (void)pContext; (void)deviceType; @@ -18996,21 +18996,21 @@ mal_result mal_context_get_device_info_from_fd__audio4(mal_context* pContext, ma } // Name. - mal_strcpy_s(pInfoOut->name, sizeof(pInfoOut->name), fdDevice.name); + ma_strcpy_s(pInfoOut->name, sizeof(pInfoOut->name), fdDevice.name); #if !defined(MA_AUDIO4_USE_NEW_API) // Supported formats. We get this by looking at the encodings. int counter = 0; for (;;) { audio_encoding_t encoding; - mal_zero_object(&encoding); + ma_zero_object(&encoding); encoding.index = counter; if (ioctl(fd, AUDIO_GETENC, &encoding) < 0) { break; } - mal_format format = mal_format_from_encoding__audio4(encoding.encoding, encoding.precision); - if (format != mal_format_unknown) { + ma_format format = ma_format_from_encoding__audio4(encoding.encoding, encoding.precision); + if (format != ma_format_unknown) { pInfoOut->formats[pInfoOut->formatCount++] = format; } @@ -19022,7 +19022,7 @@ mal_result mal_context_get_device_info_from_fd__audio4(mal_context* pContext, ma return MA_ERROR; } - if (deviceType == mal_device_type_playback) { + if (deviceType == ma_device_type_playback) { pInfoOut->minChannels = fdInfo.play.channels; pInfoOut->maxChannels = fdInfo.play.channels; pInfoOut->minSampleRate = fdInfo.play.sample_rate; @@ -19039,13 +19039,13 @@ mal_result mal_context_get_device_info_from_fd__audio4(mal_context* pContext, ma return MA_ERROR; } - mal_format format = mal_format_from_swpar__audio4(&fdPar); - if (format == mal_format_unknown) { + ma_format format = ma_format_from_swpar__audio4(&fdPar); + if (format == ma_format_unknown) { return MA_FORMAT_NOT_SUPPORTED; } pInfoOut->formats[pInfoOut->formatCount++] = format; - if (deviceType == mal_device_type_playback) { + if (deviceType == ma_device_type_playback) { pInfoOut->minChannels = fdPar.pchan; pInfoOut->maxChannels = fdPar.pchan; } else { @@ -19060,10 +19060,10 @@ mal_result mal_context_get_device_info_from_fd__audio4(mal_context* pContext, ma return MA_SUCCESS; } -mal_result mal_context_enumerate_devices__audio4(mal_context* pContext, mal_enum_devices_callback_proc callback, void* pUserData) +ma_result ma_context_enumerate_devices__audio4(ma_context* pContext, ma_enum_devices_callback_proc callback, void* pUserData) { - mal_assert(pContext != NULL); - mal_assert(callback != NULL); + ma_assert(pContext != NULL); + ma_assert(callback != NULL); const int maxDevices = 64; @@ -19071,8 +19071,8 @@ mal_result mal_context_enumerate_devices__audio4(mal_context* pContext, mal_enum // version here since we can open it even when another process has control of the "/dev/audioN" device. char devpath[256]; for (int iDevice = 0; iDevice < maxDevices; ++iDevice) { - mal_strcpy_s(devpath, sizeof(devpath), "/dev/audioctl"); - mal_itoa_s(iDevice, devpath+strlen(devpath), sizeof(devpath)-strlen(devpath), 10); + ma_strcpy_s(devpath, sizeof(devpath), "/dev/audioctl"); + ma_itoa_s(iDevice, devpath+strlen(devpath), sizeof(devpath)-strlen(devpath), 10); struct stat st; if (stat(devpath, &st) < 0) { @@ -19081,18 +19081,18 @@ mal_result mal_context_enumerate_devices__audio4(mal_context* pContext, mal_enum // The device exists, but we need to check if it's usable as playback and/or capture. int fd; - mal_bool32 isTerminating = MA_FALSE; + ma_bool32 isTerminating = MA_FALSE; // Playback. if (!isTerminating) { fd = open(devpath, O_RDONLY, 0); if (fd >= 0) { // Supports playback. - mal_device_info deviceInfo; - mal_zero_object(&deviceInfo); - mal_construct_device_id__audio4(deviceInfo.id.audio4, sizeof(deviceInfo.id.audio4), "/dev/audio", iDevice); - if (mal_context_get_device_info_from_fd__audio4(pContext, mal_device_type_playback, fd, &deviceInfo) == MA_SUCCESS) { - isTerminating = !callback(pContext, mal_device_type_playback, &deviceInfo, pUserData); + ma_device_info deviceInfo; + ma_zero_object(&deviceInfo); + ma_construct_device_id__audio4(deviceInfo.id.audio4, sizeof(deviceInfo.id.audio4), "/dev/audio", iDevice); + if (ma_context_get_device_info_from_fd__audio4(pContext, ma_device_type_playback, fd, &deviceInfo) == MA_SUCCESS) { + isTerminating = !callback(pContext, ma_device_type_playback, &deviceInfo, pUserData); } close(fd); @@ -19104,11 +19104,11 @@ mal_result mal_context_enumerate_devices__audio4(mal_context* pContext, mal_enum fd = open(devpath, O_WRONLY, 0); if (fd >= 0) { // Supports capture. - mal_device_info deviceInfo; - mal_zero_object(&deviceInfo); - mal_construct_device_id__audio4(deviceInfo.id.audio4, sizeof(deviceInfo.id.audio4), "/dev/audio", iDevice); - if (mal_context_get_device_info_from_fd__audio4(pContext, mal_device_type_capture, fd, &deviceInfo) == MA_SUCCESS) { - isTerminating = !callback(pContext, mal_device_type_capture, &deviceInfo, pUserData); + ma_device_info deviceInfo; + ma_zero_object(&deviceInfo); + ma_construct_device_id__audio4(deviceInfo.id.audio4, sizeof(deviceInfo.id.audio4), "/dev/audio", iDevice); + if (ma_context_get_device_info_from_fd__audio4(pContext, ma_device_type_capture, fd, &deviceInfo) == MA_SUCCESS) { + isTerminating = !callback(pContext, ma_device_type_capture, &deviceInfo, pUserData); } close(fd); @@ -19123,9 +19123,9 @@ mal_result mal_context_enumerate_devices__audio4(mal_context* pContext, mal_enum return MA_SUCCESS; } -mal_result mal_context_get_device_info__audio4(mal_context* pContext, mal_device_type deviceType, const mal_device_id* pDeviceID, mal_share_mode shareMode, mal_device_info* pDeviceInfo) +ma_result ma_context_get_device_info__audio4(ma_context* pContext, ma_device_type deviceType, const ma_device_id* pDeviceID, ma_share_mode shareMode, ma_device_info* pDeviceInfo) { - mal_assert(pContext != NULL); + ma_assert(pContext != NULL); (void)shareMode; // We need to open the "/dev/audioctlN" device to get the info. To do this we need to extract the number @@ -19135,48 +19135,48 @@ mal_result mal_context_get_device_info__audio4(mal_context* pContext, mal_device char ctlid[256]; if (pDeviceID == NULL) { // Default device. - mal_strcpy_s(ctlid, sizeof(ctlid), "/dev/audioctl"); + ma_strcpy_s(ctlid, sizeof(ctlid), "/dev/audioctl"); } else { // Specific device. We need to convert from "/dev/audioN" to "/dev/audioctlN". - mal_result result = mal_extract_device_index_from_id__audio4(pDeviceID->audio4, "/dev/audio", &deviceIndex); + ma_result result = ma_extract_device_index_from_id__audio4(pDeviceID->audio4, "/dev/audio", &deviceIndex); if (result != MA_SUCCESS) { return result; } - mal_construct_device_id__audio4(ctlid, sizeof(ctlid), "/dev/audioctl", deviceIndex); + ma_construct_device_id__audio4(ctlid, sizeof(ctlid), "/dev/audioctl", deviceIndex); } - fd = open(ctlid, (deviceType == mal_device_type_playback) ? O_WRONLY : O_RDONLY, 0); + fd = open(ctlid, (deviceType == ma_device_type_playback) ? O_WRONLY : O_RDONLY, 0); if (fd == -1) { return MA_NO_DEVICE; } if (deviceIndex == -1) { - mal_strcpy_s(pDeviceInfo->id.audio4, sizeof(pDeviceInfo->id.audio4), "/dev/audio"); + ma_strcpy_s(pDeviceInfo->id.audio4, sizeof(pDeviceInfo->id.audio4), "/dev/audio"); } else { - mal_construct_device_id__audio4(pDeviceInfo->id.audio4, sizeof(pDeviceInfo->id.audio4), "/dev/audio", deviceIndex); + ma_construct_device_id__audio4(pDeviceInfo->id.audio4, sizeof(pDeviceInfo->id.audio4), "/dev/audio", deviceIndex); } - mal_result result = mal_context_get_device_info_from_fd__audio4(pContext, deviceType, fd, pDeviceInfo); + ma_result result = ma_context_get_device_info_from_fd__audio4(pContext, deviceType, fd, pDeviceInfo); close(fd); return result; } -void mal_device_uninit__audio4(mal_device* pDevice) +void ma_device_uninit__audio4(ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { close(pDevice->audio4.fdCapture); } - if (pDevice->type == mal_device_type_playback || pDevice->type == mal_device_type_duplex) { + if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) { close(pDevice->audio4.fdPlayback); } } -mal_result mal_device_init_fd__audio4(mal_context* pContext, const mal_device_config* pConfig, mal_device_type deviceType, mal_device* pDevice) +ma_result ma_device_init_fd__audio4(ma_context* pContext, const ma_device_config* pConfig, ma_device_type deviceType, ma_device* pDevice) { const char* pDefaultDeviceNames[] = { "/dev/audio", @@ -19189,30 +19189,30 @@ mal_result mal_device_init_fd__audio4(mal_context* pContext, const mal_device_co #else struct audio_swpar fdPar; #endif - mal_format internalFormat; - mal_uint32 internalChannels; - mal_uint32 internalSampleRate; - mal_uint32 internalBufferSizeInFrames; - mal_uint32 internalPeriods; + ma_format internalFormat; + ma_uint32 internalChannels; + ma_uint32 internalSampleRate; + ma_uint32 internalBufferSizeInFrames; + ma_uint32 internalPeriods; - mal_assert(pContext != NULL); - mal_assert(pConfig != NULL); - mal_assert(deviceType != mal_device_type_duplex); - mal_assert(pDevice != NULL); + ma_assert(pContext != NULL); + ma_assert(pConfig != NULL); + ma_assert(deviceType != ma_device_type_duplex); + ma_assert(pDevice != NULL); (void)pContext; /* The first thing to do is open the file. */ - if (deviceType == mal_device_type_capture) { + if (deviceType == ma_device_type_capture) { fdFlags = O_RDONLY; } else { fdFlags = O_WRONLY; } fdFlags |= O_NONBLOCK; - if ((deviceType == mal_device_type_capture && pConfig->capture.pDeviceID == NULL) || (deviceType == mal_device_type_playback && pConfig->playback.pDeviceID == NULL)) { + if ((deviceType == ma_device_type_capture && pConfig->capture.pDeviceID == NULL) || (deviceType == ma_device_type_playback && pConfig->playback.pDeviceID == NULL)) { /* Default device. */ - for (size_t iDevice = 0; iDevice < mal_countof(pDefaultDeviceNames); ++iDevice) { + for (size_t iDevice = 0; iDevice < ma_countof(pDefaultDeviceNames); ++iDevice) { fd = open(pDefaultDeviceNames[iDevice], fdFlags, 0); if (fd != -1) { break; @@ -19220,64 +19220,64 @@ mal_result mal_device_init_fd__audio4(mal_context* pContext, const mal_device_co } } else { /* Specific device. */ - fd = open((deviceType == mal_device_type_capture) ? pConfig->capture.pDeviceID->audio4 : pConfig->playback.pDeviceID->audio4, fdFlags, 0); + fd = open((deviceType == ma_device_type_capture) ? pConfig->capture.pDeviceID->audio4 : pConfig->playback.pDeviceID->audio4, fdFlags, 0); } if (fd == -1) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[audio4] Failed to open device.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[audio4] Failed to open device.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } #if !defined(MA_AUDIO4_USE_NEW_API) /* Old API */ AUDIO_INITINFO(&fdInfo); /* We get the driver to do as much of the data conversion as possible. */ - if (deviceType == mal_device_type_capture) { + if (deviceType == ma_device_type_capture) { fdInfo.mode = AUMODE_RECORD; - mal_encoding_from_format__audio4(pConfig->capture.format, &fdInfo.record.encoding, &fdInfo.record.precision); + ma_encoding_from_format__audio4(pConfig->capture.format, &fdInfo.record.encoding, &fdInfo.record.precision); fdInfo.record.channels = pConfig->capture.channels; fdInfo.record.sample_rate = pConfig->sampleRate; } else { fdInfo.mode = AUMODE_PLAY; - mal_encoding_from_format__audio4(pConfig->playback.format, &fdInfo.play.encoding, &fdInfo.play.precision); + ma_encoding_from_format__audio4(pConfig->playback.format, &fdInfo.play.encoding, &fdInfo.play.precision); fdInfo.play.channels = pConfig->playback.channels; fdInfo.play.sample_rate = pConfig->sampleRate; } if (ioctl(fd, AUDIO_SETINFO, &fdInfo) < 0) { close(fd); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[audio4] Failed to set device format. AUDIO_SETINFO failed.", MA_FORMAT_NOT_SUPPORTED); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[audio4] Failed to set device format. AUDIO_SETINFO failed.", MA_FORMAT_NOT_SUPPORTED); } if (ioctl(fd, AUDIO_GETINFO, &fdInfo) < 0) { close(fd); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[audio4] AUDIO_GETINFO failed.", MA_FORMAT_NOT_SUPPORTED); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[audio4] AUDIO_GETINFO failed.", MA_FORMAT_NOT_SUPPORTED); } - if (deviceType == mal_device_type_capture) { - internalFormat = mal_format_from_prinfo__audio4(&fdInfo.record); + if (deviceType == ma_device_type_capture) { + internalFormat = ma_format_from_prinfo__audio4(&fdInfo.record); internalChannels = fdInfo.record.channels; internalSampleRate = fdInfo.record.sample_rate; } else { - internalFormat = mal_format_from_prinfo__audio4(&fdInfo.play); + internalFormat = ma_format_from_prinfo__audio4(&fdInfo.play); internalChannels = fdInfo.play.channels; internalSampleRate = fdInfo.play.sample_rate; } - if (internalFormat == mal_format_unknown) { + if (internalFormat == ma_format_unknown) { close(fd); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[audio4] The device's internal device format is not supported by miniaudio. The device is unusable.", MA_FORMAT_NOT_SUPPORTED); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[audio4] The device's internal device format is not supported by miniaudio. The device is unusable.", MA_FORMAT_NOT_SUPPORTED); } /* Buffer. */ { - mal_uint32 internalBufferSizeInBytes; + ma_uint32 internalBufferSizeInBytes; internalBufferSizeInFrames = pConfig->bufferSizeInFrames; if (internalBufferSizeInFrames == 0) { - internalBufferSizeInFrames = mal_calculate_buffer_size_in_frames_from_milliseconds(pConfig->bufferSizeInMilliseconds, internalSampleRate); + internalBufferSizeInFrames = ma_calculate_buffer_size_in_frames_from_milliseconds(pConfig->bufferSizeInMilliseconds, internalSampleRate); } - internalBufferSizeInBytes = internalBufferSizeInFrames * mal_get_bytes_per_frame(internalFormat, internalChannels); + internalBufferSizeInBytes = internalBufferSizeInFrames * ma_get_bytes_per_frame(internalFormat, internalChannels); if (internalBufferSizeInBytes < 16) { internalBufferSizeInBytes = 16; } @@ -19294,39 +19294,39 @@ mal_result mal_device_init_fd__audio4(mal_context* pContext, const mal_device_co fdInfo.blocksize = internalBufferSizeInBytes / internalPeriods; if (ioctl(fd, AUDIO_SETINFO, &fdInfo) < 0) { close(fd); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[audio4] Failed to set internal buffer size. AUDIO_SETINFO failed.", MA_FORMAT_NOT_SUPPORTED); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[audio4] Failed to set internal buffer size. AUDIO_SETINFO failed.", MA_FORMAT_NOT_SUPPORTED); } internalPeriods = fdInfo.hiwat; - internalBufferSizeInFrames = (fdInfo.blocksize * fdInfo.hiwat) / mal_get_bytes_per_frame(internalFormat, internalChannels); + internalBufferSizeInFrames = (fdInfo.blocksize * fdInfo.hiwat) / ma_get_bytes_per_frame(internalFormat, internalChannels); } #else /* We need to retrieve the format of the device so we can know the channel count and sample rate. Then we can calculate the buffer size. */ if (ioctl(fd, AUDIO_GETPAR, &fdPar) < 0) { close(fd); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[audio4] Failed to retrieve initial device parameters.", MA_FORMAT_NOT_SUPPORTED); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[audio4] Failed to retrieve initial device parameters.", MA_FORMAT_NOT_SUPPORTED); } - internalFormat = mal_format_from_swpar__audio4(&fdPar); - internalChannels = (deviceType == mal_device_type_capture) ? fdPar.rchan : fdPar.pchan; + internalFormat = ma_format_from_swpar__audio4(&fdPar); + internalChannels = (deviceType == ma_device_type_capture) ? fdPar.rchan : fdPar.pchan; internalSampleRate = fdPar.rate; - if (internalFormat == mal_format_unknown) { + if (internalFormat == ma_format_unknown) { close(fd); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[audio4] The device's internal device format is not supported by miniaudio. The device is unusable.", MA_FORMAT_NOT_SUPPORTED); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[audio4] The device's internal device format is not supported by miniaudio. The device is unusable.", MA_FORMAT_NOT_SUPPORTED); } /* Buffer. */ { - mal_uint32 internalBufferSizeInBytes; + ma_uint32 internalBufferSizeInBytes; internalBufferSizeInFrames = pConfig->bufferSizeInFrames; if (internalBufferSizeInFrames == 0) { - internalBufferSizeInFrames = mal_calculate_buffer_size_in_frames_from_milliseconds(pConfig->bufferSizeInMilliseconds, internalSampleRate); + internalBufferSizeInFrames = ma_calculate_buffer_size_in_frames_from_milliseconds(pConfig->bufferSizeInMilliseconds, internalSampleRate); } /* What miniaudio calls a fragment, audio4 calls a block. */ - internalBufferSizeInBytes = internalBufferSizeInFrames * mal_get_bytes_per_frame(internalFormat, internalChannels); + internalBufferSizeInBytes = internalBufferSizeInFrames * ma_get_bytes_per_frame(internalFormat, internalChannels); if (internalBufferSizeInBytes < 16) { internalBufferSizeInBytes = 16; } @@ -19336,33 +19336,33 @@ mal_result mal_device_init_fd__audio4(mal_context* pContext, const mal_device_co if (ioctl(fd, AUDIO_SETPAR, &fdPar) < 0) { close(fd); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[audio4] Failed to set device parameters.", MA_FORMAT_NOT_SUPPORTED); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[audio4] Failed to set device parameters.", MA_FORMAT_NOT_SUPPORTED); } if (ioctl(fd, AUDIO_GETPAR, &fdPar) < 0) { close(fd); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[audio4] Failed to retrieve actual device parameters.", MA_FORMAT_NOT_SUPPORTED); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[audio4] Failed to retrieve actual device parameters.", MA_FORMAT_NOT_SUPPORTED); } } - internalFormat = mal_format_from_swpar__audio4(&fdPar); - internalChannels = (deviceType == mal_device_type_capture) ? fdPar.rchan : fdPar.pchan; + internalFormat = ma_format_from_swpar__audio4(&fdPar); + internalChannels = (deviceType == ma_device_type_capture) ? fdPar.rchan : fdPar.pchan; internalSampleRate = fdPar.rate; internalPeriods = fdPar.nblks; - internalBufferSizeInFrames = (fdPar.nblks * fdPar.round) / mal_get_bytes_per_frame(internalFormat, internalChannels); + internalBufferSizeInFrames = (fdPar.nblks * fdPar.round) / ma_get_bytes_per_frame(internalFormat, internalChannels); #endif - if (internalFormat == mal_format_unknown) { + if (internalFormat == ma_format_unknown) { close(fd); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[audio4] The device's internal device format is not supported by miniaudio. The device is unusable.", MA_FORMAT_NOT_SUPPORTED); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[audio4] The device's internal device format is not supported by miniaudio. The device is unusable.", MA_FORMAT_NOT_SUPPORTED); } - if (deviceType == mal_device_type_capture) { + if (deviceType == ma_device_type_capture) { pDevice->audio4.fdCapture = fd; pDevice->capture.internalFormat = internalFormat; pDevice->capture.internalChannels = internalChannels; pDevice->capture.internalSampleRate = internalSampleRate; - mal_get_standard_channel_map(mal_standard_channel_map_sound4, internalChannels, pDevice->capture.internalChannelMap); + ma_get_standard_channel_map(ma_standard_channel_map_sound4, internalChannels, pDevice->capture.internalChannelMap); pDevice->capture.internalBufferSizeInFrames = internalBufferSizeInFrames; pDevice->capture.internalPeriods = internalPeriods; } else { @@ -19370,7 +19370,7 @@ mal_result mal_device_init_fd__audio4(mal_context* pContext, const mal_device_co pDevice->playback.internalFormat = internalFormat; pDevice->playback.internalChannels = internalChannels; pDevice->playback.internalSampleRate = internalSampleRate; - mal_get_standard_channel_map(mal_standard_channel_map_sound4, internalChannels, pDevice->playback.internalChannelMap); + ma_get_standard_channel_map(ma_standard_channel_map_sound4, internalChannels, pDevice->playback.internalChannelMap); pDevice->playback.internalBufferSizeInFrames = internalBufferSizeInFrames; pDevice->playback.internalPeriods = internalPeriods; } @@ -19378,11 +19378,11 @@ mal_result mal_device_init_fd__audio4(mal_context* pContext, const mal_device_co return MA_SUCCESS; } -mal_result mal_device_init__audio4(mal_context* pContext, const mal_device_config* pConfig, mal_device* pDevice) +ma_result ma_device_init__audio4(ma_context* pContext, const ma_device_config* pConfig, ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); - mal_zero_object(&pDevice->audio4); + ma_zero_object(&pDevice->audio4); pDevice->audio4.fdCapture = -1; pDevice->audio4.fdPlayback = -1; @@ -19392,25 +19392,25 @@ mal_result mal_device_init__audio4(mal_context* pContext, const mal_device_confi // I'm aware. #if defined(__NetBSD_Version__) && __NetBSD_Version__ >= 800000000 /* NetBSD 8.0+ */ - if (((pConfig->deviceType == mal_device_type_playback || pConfig->deviceType == mal_device_type_duplex) && pConfig->playback.shareMode == mal_share_mode_exclusive) || - ((pConfig->deviceType == mal_device_type_capture || pConfig->deviceType == mal_device_type_duplex) && pConfig->capture.shareMode == mal_share_mode_exclusive)) { + if (((pConfig->deviceType == ma_device_type_playback || pConfig->deviceType == ma_device_type_duplex) && pConfig->playback.shareMode == ma_share_mode_exclusive) || + ((pConfig->deviceType == ma_device_type_capture || pConfig->deviceType == ma_device_type_duplex) && pConfig->capture.shareMode == ma_share_mode_exclusive)) { return MA_SHARE_MODE_NOT_SUPPORTED; } #else /* All other flavors. */ #endif - if (pConfig->deviceType == mal_device_type_capture || pConfig->deviceType == mal_device_type_duplex) { - mal_result result = mal_device_init_fd__audio4(pContext, pConfig, mal_device_type_capture, pDevice); + if (pConfig->deviceType == ma_device_type_capture || pConfig->deviceType == ma_device_type_duplex) { + ma_result result = ma_device_init_fd__audio4(pContext, pConfig, ma_device_type_capture, pDevice); if (result != MA_SUCCESS) { return result; } } - if (pConfig->deviceType == mal_device_type_playback || pConfig->deviceType == mal_device_type_duplex) { - mal_result result = mal_device_init_fd__audio4(pContext, pConfig, mal_device_type_playback, pDevice); + if (pConfig->deviceType == ma_device_type_playback || pConfig->deviceType == ma_device_type_duplex) { + ma_result result = ma_device_init_fd__audio4(pContext, pConfig, ma_device_type_playback, pDevice); if (result != MA_SUCCESS) { - if (pConfig->deviceType == mal_device_type_duplex) { + if (pConfig->deviceType == ma_device_type_duplex) { close(pDevice->audio4.fdCapture); } return result; @@ -19421,17 +19421,17 @@ mal_result mal_device_init__audio4(mal_context* pContext, const mal_device_confi } #if 0 -mal_result mal_device_start__audio4(mal_device* pDevice) +ma_result ma_device_start__audio4(ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { if (pDevice->audio4.fdCapture == -1) { return MA_INVALID_ARGS; } } - if (pDevice->type == mal_device_type_playback || pDevice->type == mal_device_type_duplex) { + if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) { if (pDevice->audio4.fdPlayback == -1) { return MA_INVALID_ARGS; } @@ -19441,7 +19441,7 @@ mal_result mal_device_start__audio4(mal_device* pDevice) } #endif -mal_result mal_device_stop_fd__audio4(mal_device* pDevice, int fd) +ma_result ma_device_stop_fd__audio4(ma_device* pDevice, int fd) { if (fd == -1) { return MA_INVALID_ARGS; @@ -19449,30 +19449,30 @@ mal_result mal_device_stop_fd__audio4(mal_device* pDevice, int fd) #if !defined(MA_AUDIO4_USE_NEW_API) if (ioctl(fd, AUDIO_FLUSH, 0) < 0) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[audio4] Failed to stop device. AUDIO_FLUSH failed.", MA_FAILED_TO_STOP_BACKEND_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[audio4] Failed to stop device. AUDIO_FLUSH failed.", MA_FAILED_TO_STOP_BACKEND_DEVICE); } #else if (ioctl(fd, AUDIO_STOP, 0) < 0) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[audio4] Failed to stop device. AUDIO_STOP failed.", MA_FAILED_TO_STOP_BACKEND_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[audio4] Failed to stop device. AUDIO_STOP failed.", MA_FAILED_TO_STOP_BACKEND_DEVICE); } #endif return MA_SUCCESS; } -mal_result mal_device_stop__audio4(mal_device* pDevice) +ma_result ma_device_stop__audio4(ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { - mal_result result = mal_device_stop_fd__audio4(pDevice, pDevice->audio4.fdCapture); + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { + ma_result result = ma_device_stop_fd__audio4(pDevice, pDevice->audio4.fdCapture); if (result != MA_SUCCESS) { return result; } } - if (pDevice->type == mal_device_type_playback || pDevice->type == mal_device_type_duplex) { - mal_result result = mal_device_stop_fd__audio4(pDevice, pDevice->audio4.fdPlayback); + if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) { + ma_result result = ma_device_stop_fd__audio4(pDevice, pDevice->audio4.fdPlayback); if (result != MA_SUCCESS) { return result; } @@ -19481,49 +19481,49 @@ mal_result mal_device_stop__audio4(mal_device* pDevice) return MA_SUCCESS; } -mal_result mal_device_write__audio4(mal_device* pDevice, const void* pPCMFrames, mal_uint32 frameCount) +ma_result ma_device_write__audio4(ma_device* pDevice, const void* pPCMFrames, ma_uint32 frameCount) { - int result = write(pDevice->audio4.fdPlayback, pPCMFrames, frameCount * mal_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels)); + int result = write(pDevice->audio4.fdPlayback, pPCMFrames, frameCount * ma_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels)); if (result < 0) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[audio4] Failed to write data to the device.", MA_FAILED_TO_SEND_DATA_TO_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[audio4] Failed to write data to the device.", MA_FAILED_TO_SEND_DATA_TO_DEVICE); } return MA_SUCCESS; } -mal_result mal_device_read__audio4(mal_device* pDevice, void* pPCMFrames, mal_uint32 frameCount) +ma_result ma_device_read__audio4(ma_device* pDevice, void* pPCMFrames, ma_uint32 frameCount) { - int result = read(pDevice->audio4.fdCapture, pPCMFrames, frameCount * mal_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels)); + int result = read(pDevice->audio4.fdCapture, pPCMFrames, frameCount * ma_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels)); if (result < 0) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[audio4] Failed to read data from the device.", MA_FAILED_TO_READ_DATA_FROM_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[audio4] Failed to read data from the device.", MA_FAILED_TO_READ_DATA_FROM_DEVICE); } return MA_SUCCESS; } -mal_result mal_context_uninit__audio4(mal_context* pContext) +ma_result ma_context_uninit__audio4(ma_context* pContext) { - mal_assert(pContext != NULL); - mal_assert(pContext->backend == mal_backend_audio4); + ma_assert(pContext != NULL); + ma_assert(pContext->backend == ma_backend_audio4); (void)pContext; return MA_SUCCESS; } -mal_result mal_context_init__audio4(mal_context* pContext) +ma_result ma_context_init__audio4(ma_context* pContext) { - mal_assert(pContext != NULL); + ma_assert(pContext != NULL); - pContext->onUninit = mal_context_uninit__audio4; - pContext->onDeviceIDEqual = mal_context_is_device_id_equal__audio4; - pContext->onEnumDevices = mal_context_enumerate_devices__audio4; - pContext->onGetDeviceInfo = mal_context_get_device_info__audio4; - pContext->onDeviceInit = mal_device_init__audio4; - pContext->onDeviceUninit = mal_device_uninit__audio4; + pContext->onUninit = ma_context_uninit__audio4; + pContext->onDeviceIDEqual = ma_context_is_device_id_equal__audio4; + pContext->onEnumDevices = ma_context_enumerate_devices__audio4; + pContext->onGetDeviceInfo = ma_context_get_device_info__audio4; + pContext->onDeviceInit = ma_device_init__audio4; + pContext->onDeviceUninit = ma_device_uninit__audio4; pContext->onDeviceStart = NULL; - pContext->onDeviceStop = mal_device_stop__audio4; - pContext->onDeviceWrite = mal_device_write__audio4; - pContext->onDeviceRead = mal_device_read__audio4; + pContext->onDeviceStop = ma_device_stop__audio4; + pContext->onDeviceWrite = ma_device_write__audio4; + pContext->onDeviceRead = ma_device_read__audio4; return MA_SUCCESS; } @@ -19545,7 +19545,7 @@ mal_result mal_context_init__audio4(mal_context* pContext) #define SNDCTL_DSP_HALT SNDCTL_DSP_RESET #endif -int mal_open_temp_device__oss() +int ma_open_temp_device__oss() { // The OSS sample code uses "/dev/mixer" as the device for getting system properties so I'm going to do the same. int fd = open("/dev/mixer", O_RDONLY, 0); @@ -19556,16 +19556,16 @@ int mal_open_temp_device__oss() return -1; } -mal_result mal_context_open_device__oss(mal_context* pContext, mal_device_type deviceType, const mal_device_id* pDeviceID, mal_share_mode shareMode, int* pfd) +ma_result ma_context_open_device__oss(ma_context* pContext, ma_device_type deviceType, const ma_device_id* pDeviceID, ma_share_mode shareMode, int* pfd) { - mal_assert(pContext != NULL); - mal_assert(pfd != NULL); + ma_assert(pContext != NULL); + ma_assert(pfd != NULL); (void)pContext; *pfd = -1; /* This function should only be called for playback or capture, not duplex. */ - if (deviceType == mal_device_type_duplex) { + if (deviceType == ma_device_type_duplex) { return MA_INVALID_ARGS; } @@ -19574,8 +19574,8 @@ mal_result mal_context_open_device__oss(mal_context* pContext, mal_device_type d deviceName = pDeviceID->oss; } - int flags = (deviceType == mal_device_type_playback) ? O_WRONLY : O_RDONLY; - if (shareMode == mal_share_mode_exclusive) { + int flags = (deviceType == ma_device_type_playback) ? O_WRONLY : O_RDONLY; + if (shareMode == ma_share_mode_exclusive) { flags |= O_EXCL; } @@ -19587,24 +19587,24 @@ mal_result mal_context_open_device__oss(mal_context* pContext, mal_device_type d return MA_SUCCESS; } -mal_bool32 mal_context_is_device_id_equal__oss(mal_context* pContext, const mal_device_id* pID0, const mal_device_id* pID1) +ma_bool32 ma_context_is_device_id_equal__oss(ma_context* pContext, const ma_device_id* pID0, const ma_device_id* pID1) { - mal_assert(pContext != NULL); - mal_assert(pID0 != NULL); - mal_assert(pID1 != NULL); + ma_assert(pContext != NULL); + ma_assert(pID0 != NULL); + ma_assert(pID1 != NULL); (void)pContext; - return mal_strcmp(pID0->oss, pID1->oss) == 0; + return ma_strcmp(pID0->oss, pID1->oss) == 0; } -mal_result mal_context_enumerate_devices__oss(mal_context* pContext, mal_enum_devices_callback_proc callback, void* pUserData) +ma_result ma_context_enumerate_devices__oss(ma_context* pContext, ma_enum_devices_callback_proc callback, void* pUserData) { - mal_assert(pContext != NULL); - mal_assert(callback != NULL); + ma_assert(pContext != NULL); + ma_assert(callback != NULL); - int fd = mal_open_temp_device__oss(); + int fd = ma_open_temp_device__oss(); if (fd == -1) { - return mal_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[OSS] Failed to open a temporary device for retrieving system information used for device enumeration.", MA_NO_BACKEND); + return ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[OSS] Failed to open a temporary device for retrieving system information used for device enumeration.", MA_NO_BACKEND); } oss_sysinfo si; @@ -19616,28 +19616,28 @@ mal_result mal_context_enumerate_devices__oss(mal_context* pContext, mal_enum_de result = ioctl(fd, SNDCTL_AUDIOINFO, &ai); if (result != -1) { if (ai.devnode[0] != '\0') { // <-- Can be blank, according to documentation. - mal_device_info deviceInfo; - mal_zero_object(&deviceInfo); + ma_device_info deviceInfo; + ma_zero_object(&deviceInfo); // ID - mal_strncpy_s(deviceInfo.id.oss, sizeof(deviceInfo.id.oss), ai.devnode, (size_t)-1); + ma_strncpy_s(deviceInfo.id.oss, sizeof(deviceInfo.id.oss), ai.devnode, (size_t)-1); // The human readable device name should be in the "ai.handle" variable, but it can // sometimes be empty in which case we just fall back to "ai.name" which is less user // friendly, but usually has a value. if (ai.handle[0] != '\0') { - mal_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), ai.handle, (size_t)-1); + ma_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), ai.handle, (size_t)-1); } else { - mal_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), ai.name, (size_t)-1); + ma_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), ai.name, (size_t)-1); } // The device can be both playback and capture. - mal_bool32 isTerminating = MA_FALSE; + ma_bool32 isTerminating = MA_FALSE; if (!isTerminating && (ai.caps & PCM_CAP_OUTPUT) != 0) { - isTerminating = !callback(pContext, mal_device_type_playback, &deviceInfo, pUserData); + isTerminating = !callback(pContext, ma_device_type_playback, &deviceInfo, pUserData); } if (!isTerminating && (ai.caps & PCM_CAP_INPUT) != 0) { - isTerminating = !callback(pContext, mal_device_type_capture, &deviceInfo, pUserData); + isTerminating = !callback(pContext, ma_device_type_capture, &deviceInfo, pUserData); } if (isTerminating) { @@ -19648,24 +19648,24 @@ mal_result mal_context_enumerate_devices__oss(mal_context* pContext, mal_enum_de } } else { close(fd); - return mal_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[OSS] Failed to retrieve system information for device enumeration.", MA_NO_BACKEND); + return ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[OSS] Failed to retrieve system information for device enumeration.", MA_NO_BACKEND); } close(fd); return MA_SUCCESS; } -mal_result mal_context_get_device_info__oss(mal_context* pContext, mal_device_type deviceType, const mal_device_id* pDeviceID, mal_share_mode shareMode, mal_device_info* pDeviceInfo) +ma_result ma_context_get_device_info__oss(ma_context* pContext, ma_device_type deviceType, const ma_device_id* pDeviceID, ma_share_mode shareMode, ma_device_info* pDeviceInfo) { - mal_assert(pContext != NULL); + ma_assert(pContext != NULL); (void)shareMode; // Handle the default device a little differently. if (pDeviceID == NULL) { - if (deviceType == mal_device_type_playback) { - mal_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), MA_DEFAULT_PLAYBACK_DEVICE_NAME, (size_t)-1); + if (deviceType == ma_device_type_playback) { + ma_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), MA_DEFAULT_PLAYBACK_DEVICE_NAME, (size_t)-1); } else { - mal_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), MA_DEFAULT_CAPTURE_DEVICE_NAME, (size_t)-1); + ma_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), MA_DEFAULT_CAPTURE_DEVICE_NAME, (size_t)-1); } return MA_SUCCESS; @@ -19673,11 +19673,11 @@ mal_result mal_context_get_device_info__oss(mal_context* pContext, mal_device_ty // If we get here it means we are _not_ using the default device. - mal_bool32 foundDevice = MA_FALSE; + ma_bool32 foundDevice = MA_FALSE; - int fdTemp = mal_open_temp_device__oss(); + int fdTemp = ma_open_temp_device__oss(); if (fdTemp == -1) { - return mal_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[OSS] Failed to open a temporary device for retrieving system information used for device enumeration.", MA_NO_BACKEND); + return ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[OSS] Failed to open a temporary device for retrieving system information used for device enumeration.", MA_NO_BACKEND); } oss_sysinfo si; @@ -19688,20 +19688,20 @@ mal_result mal_context_get_device_info__oss(mal_context* pContext, mal_device_ty ai.dev = iAudioDevice; result = ioctl(fdTemp, SNDCTL_AUDIOINFO, &ai); if (result != -1) { - if (mal_strcmp(ai.devnode, pDeviceID->oss) == 0) { + if (ma_strcmp(ai.devnode, pDeviceID->oss) == 0) { // It has the same name, so now just confirm the type. - if ((deviceType == mal_device_type_playback && ((ai.caps & PCM_CAP_OUTPUT) != 0)) || - (deviceType == mal_device_type_capture && ((ai.caps & PCM_CAP_INPUT) != 0))) { + if ((deviceType == ma_device_type_playback && ((ai.caps & PCM_CAP_OUTPUT) != 0)) || + (deviceType == ma_device_type_capture && ((ai.caps & PCM_CAP_INPUT) != 0))) { // ID - mal_strncpy_s(pDeviceInfo->id.oss, sizeof(pDeviceInfo->id.oss), ai.devnode, (size_t)-1); + ma_strncpy_s(pDeviceInfo->id.oss, sizeof(pDeviceInfo->id.oss), ai.devnode, (size_t)-1); // The human readable device name should be in the "ai.handle" variable, but it can // sometimes be empty in which case we just fall back to "ai.name" which is less user // friendly, but usually has a value. if (ai.handle[0] != '\0') { - mal_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), ai.handle, (size_t)-1); + ma_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), ai.handle, (size_t)-1); } else { - mal_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), ai.name, (size_t)-1); + ma_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), ai.name, (size_t)-1); } pDeviceInfo->minChannels = ai.min_channels; @@ -19711,20 +19711,20 @@ mal_result mal_context_get_device_info__oss(mal_context* pContext, mal_device_ty pDeviceInfo->formatCount = 0; unsigned int formatMask; - if (deviceType == mal_device_type_playback) { + if (deviceType == ma_device_type_playback) { formatMask = ai.oformats; } else { formatMask = ai.iformats; } if ((formatMask & AFMT_U8) != 0) { - pDeviceInfo->formats[pDeviceInfo->formatCount++] = mal_format_u8; + pDeviceInfo->formats[pDeviceInfo->formatCount++] = ma_format_u8; } - if (((formatMask & AFMT_S16_LE) != 0 && mal_is_little_endian()) || (AFMT_S16_BE && mal_is_big_endian())) { - pDeviceInfo->formats[pDeviceInfo->formatCount++] = mal_format_s16; + if (((formatMask & AFMT_S16_LE) != 0 && ma_is_little_endian()) || (AFMT_S16_BE && ma_is_big_endian())) { + pDeviceInfo->formats[pDeviceInfo->formatCount++] = ma_format_s16; } - if (((formatMask & AFMT_S32_LE) != 0 && mal_is_little_endian()) || (AFMT_S32_BE && mal_is_big_endian())) { - pDeviceInfo->formats[pDeviceInfo->formatCount++] = mal_format_s32; + if (((formatMask & AFMT_S32_LE) != 0 && ma_is_little_endian()) || (AFMT_S32_BE && ma_is_big_endian())) { + pDeviceInfo->formats[pDeviceInfo->formatCount++] = ma_format_s32; } foundDevice = MA_TRUE; @@ -19735,7 +19735,7 @@ mal_result mal_context_get_device_info__oss(mal_context* pContext, mal_device_ty } } else { close(fdTemp); - return mal_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[OSS] Failed to retrieve system information for device enumeration.", MA_NO_BACKEND); + return ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[OSS] Failed to retrieve system information for device enumeration.", MA_NO_BACKEND); } @@ -19749,93 +19749,93 @@ mal_result mal_context_get_device_info__oss(mal_context* pContext, mal_device_ty return MA_SUCCESS; } -void mal_device_uninit__oss(mal_device* pDevice) +void ma_device_uninit__oss(ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { close(pDevice->oss.fdCapture); } - if (pDevice->type == mal_device_type_playback || pDevice->type == mal_device_type_duplex) { + if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) { close(pDevice->oss.fdPlayback); } } -int mal_format_to_oss(mal_format format) +int ma_format_to_oss(ma_format format) { int ossFormat = AFMT_U8; switch (format) { - case mal_format_s16: ossFormat = (mal_is_little_endian()) ? AFMT_S16_LE : AFMT_S16_BE; break; - case mal_format_s24: ossFormat = (mal_is_little_endian()) ? AFMT_S32_LE : AFMT_S32_BE; break; - case mal_format_s32: ossFormat = (mal_is_little_endian()) ? AFMT_S32_LE : AFMT_S32_BE; break; - case mal_format_f32: ossFormat = (mal_is_little_endian()) ? AFMT_S16_LE : AFMT_S16_BE; break; - case mal_format_u8: + case ma_format_s16: ossFormat = (ma_is_little_endian()) ? AFMT_S16_LE : AFMT_S16_BE; break; + case ma_format_s24: ossFormat = (ma_is_little_endian()) ? AFMT_S32_LE : AFMT_S32_BE; break; + case ma_format_s32: ossFormat = (ma_is_little_endian()) ? AFMT_S32_LE : AFMT_S32_BE; break; + case ma_format_f32: ossFormat = (ma_is_little_endian()) ? AFMT_S16_LE : AFMT_S16_BE; break; + case ma_format_u8: default: ossFormat = AFMT_U8; break; } return ossFormat; } -mal_format mal_format_from_oss(int ossFormat) +ma_format ma_format_from_oss(int ossFormat) { if (ossFormat == AFMT_U8) { - return mal_format_u8; + return ma_format_u8; } else { - if (mal_is_little_endian()) { + if (ma_is_little_endian()) { switch (ossFormat) { - case AFMT_S16_LE: return mal_format_s16; - case AFMT_S32_LE: return mal_format_s32; - default: return mal_format_unknown; + case AFMT_S16_LE: return ma_format_s16; + case AFMT_S32_LE: return ma_format_s32; + default: return ma_format_unknown; } } else { switch (ossFormat) { - case AFMT_S16_BE: return mal_format_s16; - case AFMT_S32_BE: return mal_format_s32; - default: return mal_format_unknown; + case AFMT_S16_BE: return ma_format_s16; + case AFMT_S32_BE: return ma_format_s32; + default: return ma_format_unknown; } } } - return mal_format_unknown; + return ma_format_unknown; } -mal_result mal_device_init_fd__oss(mal_context* pContext, const mal_device_config* pConfig, mal_device_type deviceType, mal_device* pDevice) +ma_result ma_device_init_fd__oss(ma_context* pContext, const ma_device_config* pConfig, ma_device_type deviceType, ma_device* pDevice) { - mal_result result; + ma_result result; int ossResult; int fd; - const mal_device_id* pDeviceID = NULL; - mal_share_mode shareMode; + const ma_device_id* pDeviceID = NULL; + ma_share_mode shareMode; int ossFormat; int ossChannels; int ossSampleRate; int ossFragment; - mal_assert(pContext != NULL); - mal_assert(pConfig != NULL); - mal_assert(deviceType != mal_device_type_duplex); - mal_assert(pDevice != NULL); + ma_assert(pContext != NULL); + ma_assert(pConfig != NULL); + ma_assert(deviceType != ma_device_type_duplex); + ma_assert(pDevice != NULL); (void)pContext; - if (deviceType == mal_device_type_capture) { + if (deviceType == ma_device_type_capture) { pDeviceID = pConfig->capture.pDeviceID; shareMode = pConfig->capture.shareMode; - ossFormat = mal_format_to_oss(pConfig->capture.format); + ossFormat = ma_format_to_oss(pConfig->capture.format); ossChannels = (int)pConfig->capture.channels; ossSampleRate = (int)pConfig->sampleRate; } else { pDeviceID = pConfig->playback.pDeviceID; shareMode = pConfig->playback.shareMode; - ossFormat = mal_format_to_oss(pConfig->playback.format); + ossFormat = ma_format_to_oss(pConfig->playback.format); ossChannels = (int)pConfig->playback.channels; ossSampleRate = (int)pConfig->sampleRate; } - result = mal_context_open_device__oss(pContext, deviceType, pDeviceID, shareMode, &fd); + result = ma_context_open_device__oss(pContext, deviceType, pDeviceID, shareMode, &fd); if (result != MA_SUCCESS) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OSS] Failed to open device.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OSS] Failed to open device.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } /* @@ -19849,21 +19849,21 @@ mal_result mal_device_init_fd__oss(mal_context* pContext, const mal_device_confi ossResult = ioctl(fd, SNDCTL_DSP_SETFMT, &ossFormat); if (ossResult == -1) { close(fd); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OSS] Failed to set format.", MA_FORMAT_NOT_SUPPORTED); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OSS] Failed to set format.", MA_FORMAT_NOT_SUPPORTED); } /* Channels. */ ossResult = ioctl(fd, SNDCTL_DSP_CHANNELS, &ossChannels); if (ossResult == -1) { close(fd); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OSS] Failed to set channel count.", MA_FORMAT_NOT_SUPPORTED); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OSS] Failed to set channel count.", MA_FORMAT_NOT_SUPPORTED); } /* Sample Rate. */ ossResult = ioctl(fd, SNDCTL_DSP_SPEED, &ossSampleRate); if (ossResult == -1) { close(fd); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OSS] Failed to set sample rate.", MA_FORMAT_NOT_SUPPORTED); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OSS] Failed to set sample rate.", MA_FORMAT_NOT_SUPPORTED); } /* @@ -19876,16 +19876,16 @@ mal_result mal_device_init_fd__oss(mal_context* pContext, const mal_device_confi value. */ { - mal_uint32 fragmentSizeInBytes; - mal_uint32 bufferSizeInFrames; - mal_uint32 ossFragmentSizePower; + ma_uint32 fragmentSizeInBytes; + ma_uint32 bufferSizeInFrames; + ma_uint32 ossFragmentSizePower; bufferSizeInFrames = pConfig->bufferSizeInFrames; if (bufferSizeInFrames == 0) { - bufferSizeInFrames = mal_calculate_buffer_size_in_frames_from_milliseconds(pConfig->bufferSizeInMilliseconds, (mal_uint32)ossSampleRate); + bufferSizeInFrames = ma_calculate_buffer_size_in_frames_from_milliseconds(pConfig->bufferSizeInMilliseconds, (ma_uint32)ossSampleRate); } - fragmentSizeInBytes = mal_round_to_power_of_2((bufferSizeInFrames / pConfig->periods) * mal_get_bytes_per_frame(mal_format_from_oss(ossFormat), ossChannels)); + fragmentSizeInBytes = ma_round_to_power_of_2((bufferSizeInFrames / pConfig->periods) * ma_get_bytes_per_frame(ma_format_from_oss(ossFormat), ossChannels)); if (fragmentSizeInBytes < 16) { fragmentSizeInBytes = 16; } @@ -19900,68 +19900,68 @@ mal_result mal_device_init_fd__oss(mal_context* pContext, const mal_device_confi ossResult = ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &ossFragment); if (ossResult == -1) { close(fd); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OSS] Failed to set fragment size and period count.", MA_FORMAT_NOT_SUPPORTED); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OSS] Failed to set fragment size and period count.", MA_FORMAT_NOT_SUPPORTED); } } /* Internal settings. */ - if (deviceType == mal_device_type_capture) { + if (deviceType == ma_device_type_capture) { pDevice->oss.fdCapture = fd; - pDevice->capture.internalFormat = mal_format_from_oss(ossFormat); + pDevice->capture.internalFormat = ma_format_from_oss(ossFormat); pDevice->capture.internalChannels = ossChannels; pDevice->capture.internalSampleRate = ossSampleRate; - mal_get_standard_channel_map(mal_standard_channel_map_sound4, pDevice->capture.internalChannels, pDevice->capture.internalChannelMap); - pDevice->capture.internalPeriods = (mal_uint32)(ossFragment >> 16); - pDevice->capture.internalBufferSizeInFrames = (((mal_uint32)(1 << (ossFragment & 0xFFFF))) * pDevice->capture.internalPeriods) / mal_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels); + ma_get_standard_channel_map(ma_standard_channel_map_sound4, pDevice->capture.internalChannels, pDevice->capture.internalChannelMap); + pDevice->capture.internalPeriods = (ma_uint32)(ossFragment >> 16); + pDevice->capture.internalBufferSizeInFrames = (((ma_uint32)(1 << (ossFragment & 0xFFFF))) * pDevice->capture.internalPeriods) / ma_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels); - if (pDevice->capture.internalFormat == mal_format_unknown) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OSS] The device's internal format is not supported by miniaudio.", MA_FORMAT_NOT_SUPPORTED); + if (pDevice->capture.internalFormat == ma_format_unknown) { + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OSS] The device's internal format is not supported by miniaudio.", MA_FORMAT_NOT_SUPPORTED); } } else { pDevice->oss.fdPlayback = fd; - pDevice->playback.internalFormat = mal_format_from_oss(ossFormat); + pDevice->playback.internalFormat = ma_format_from_oss(ossFormat); pDevice->playback.internalChannels = ossChannels; pDevice->playback.internalSampleRate = ossSampleRate; - mal_get_standard_channel_map(mal_standard_channel_map_sound4, pDevice->playback.internalChannels, pDevice->playback.internalChannelMap); - pDevice->playback.internalPeriods = (mal_uint32)(ossFragment >> 16); - pDevice->playback.internalBufferSizeInFrames = (((mal_uint32)(1 << (ossFragment & 0xFFFF))) * pDevice->playback.internalPeriods) / mal_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels); + ma_get_standard_channel_map(ma_standard_channel_map_sound4, pDevice->playback.internalChannels, pDevice->playback.internalChannelMap); + pDevice->playback.internalPeriods = (ma_uint32)(ossFragment >> 16); + pDevice->playback.internalBufferSizeInFrames = (((ma_uint32)(1 << (ossFragment & 0xFFFF))) * pDevice->playback.internalPeriods) / ma_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels); - if (pDevice->playback.internalFormat == mal_format_unknown) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OSS] The device's internal format is not supported by miniaudio.", MA_FORMAT_NOT_SUPPORTED); + if (pDevice->playback.internalFormat == ma_format_unknown) { + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OSS] The device's internal format is not supported by miniaudio.", MA_FORMAT_NOT_SUPPORTED); } } return MA_SUCCESS; } -mal_result mal_device_init__oss(mal_context* pContext, const mal_device_config* pConfig, mal_device* pDevice) +ma_result ma_device_init__oss(ma_context* pContext, const ma_device_config* pConfig, ma_device* pDevice) { - mal_assert(pContext != NULL); - mal_assert(pConfig != NULL); - mal_assert(pDevice != NULL); + ma_assert(pContext != NULL); + ma_assert(pConfig != NULL); + ma_assert(pDevice != NULL); - mal_zero_object(&pDevice->oss); + ma_zero_object(&pDevice->oss); - if (pConfig->deviceType == mal_device_type_capture || pConfig->deviceType == mal_device_type_duplex) { - mal_result result = mal_device_init_fd__oss(pContext, pConfig, mal_device_type_capture, pDevice); + if (pConfig->deviceType == ma_device_type_capture || pConfig->deviceType == ma_device_type_duplex) { + ma_result result = ma_device_init_fd__oss(pContext, pConfig, ma_device_type_capture, pDevice); if (result != MA_SUCCESS) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OSS] Failed to open device.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OSS] Failed to open device.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } } - if (pConfig->deviceType == mal_device_type_playback || pConfig->deviceType == mal_device_type_duplex) { - mal_result result = mal_device_init_fd__oss(pContext, pConfig, mal_device_type_playback, pDevice); + if (pConfig->deviceType == ma_device_type_playback || pConfig->deviceType == ma_device_type_duplex) { + ma_result result = ma_device_init_fd__oss(pContext, pConfig, ma_device_type_playback, pDevice); if (result != MA_SUCCESS) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OSS] Failed to open device.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OSS] Failed to open device.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } } return MA_SUCCESS; } -mal_result mal_device_stop__oss(mal_device* pDevice) +ma_result ma_device_stop__oss(ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); /* We want to use SNDCTL_DSP_HALT. From the documentation: @@ -19976,60 +19976,60 @@ mal_result mal_device_stop__oss(mal_device* pDevice) thread anyway. Just keep this in mind, though... */ - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { int result = ioctl(pDevice->oss.fdCapture, SNDCTL_DSP_HALT, 0); if (result == -1) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OSS] Failed to stop device. SNDCTL_DSP_HALT failed.", MA_FAILED_TO_STOP_BACKEND_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OSS] Failed to stop device. SNDCTL_DSP_HALT failed.", MA_FAILED_TO_STOP_BACKEND_DEVICE); } } - if (pDevice->type == mal_device_type_playback || pDevice->type == mal_device_type_duplex) { + if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) { int result = ioctl(pDevice->oss.fdPlayback, SNDCTL_DSP_HALT, 0); if (result == -1) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OSS] Failed to stop device. SNDCTL_DSP_HALT failed.", MA_FAILED_TO_STOP_BACKEND_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OSS] Failed to stop device. SNDCTL_DSP_HALT failed.", MA_FAILED_TO_STOP_BACKEND_DEVICE); } } return MA_SUCCESS; } -mal_result mal_device_write__oss(mal_device* pDevice, const void* pPCMFrames, mal_uint32 frameCount) +ma_result ma_device_write__oss(ma_device* pDevice, const void* pPCMFrames, ma_uint32 frameCount) { - int resultOSS = write(pDevice->oss.fdPlayback, pPCMFrames, frameCount * mal_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels)); + int resultOSS = write(pDevice->oss.fdPlayback, pPCMFrames, frameCount * ma_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels)); if (resultOSS < 0) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OSS] Failed to send data from the client to the device.", MA_FAILED_TO_SEND_DATA_TO_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OSS] Failed to send data from the client to the device.", MA_FAILED_TO_SEND_DATA_TO_DEVICE); } return MA_SUCCESS; } -mal_result mal_device_read__oss(mal_device* pDevice, void* pPCMFrames, mal_uint32 frameCount) +ma_result ma_device_read__oss(ma_device* pDevice, void* pPCMFrames, ma_uint32 frameCount) { - int resultOSS = read(pDevice->oss.fdCapture, pPCMFrames, frameCount * mal_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels)); + int resultOSS = read(pDevice->oss.fdCapture, pPCMFrames, frameCount * ma_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels)); if (resultOSS < 0) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OSS] Failed to read data from the device to be sent to the client.", MA_FAILED_TO_READ_DATA_FROM_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OSS] Failed to read data from the device to be sent to the client.", MA_FAILED_TO_READ_DATA_FROM_DEVICE); } return MA_SUCCESS; } -mal_result mal_context_uninit__oss(mal_context* pContext) +ma_result ma_context_uninit__oss(ma_context* pContext) { - mal_assert(pContext != NULL); - mal_assert(pContext->backend == mal_backend_oss); + ma_assert(pContext != NULL); + ma_assert(pContext->backend == ma_backend_oss); (void)pContext; return MA_SUCCESS; } -mal_result mal_context_init__oss(mal_context* pContext) +ma_result ma_context_init__oss(ma_context* pContext) { - mal_assert(pContext != NULL); + ma_assert(pContext != NULL); /* Try opening a temporary device first so we can get version information. This is closed at the end. */ - int fd = mal_open_temp_device__oss(); + int fd = ma_open_temp_device__oss(); if (fd == -1) { - return mal_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[OSS] Failed to open temporary device for retrieving system properties.", MA_NO_BACKEND); /* Looks liks OSS isn't installed, or there are no available devices. */ + return ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[OSS] Failed to open temporary device for retrieving system properties.", MA_NO_BACKEND); /* Looks liks OSS isn't installed, or there are no available devices. */ } /* Grab the OSS version. */ @@ -20037,22 +20037,22 @@ mal_result mal_context_init__oss(mal_context* pContext) int result = ioctl(fd, OSS_GETVERSION, &ossVersion); if (result == -1) { close(fd); - return mal_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[OSS] Failed to retrieve OSS version.", MA_NO_BACKEND); + return ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_ERROR, "[OSS] Failed to retrieve OSS version.", MA_NO_BACKEND); } pContext->oss.versionMajor = ((ossVersion & 0xFF0000) >> 16); pContext->oss.versionMinor = ((ossVersion & 0x00FF00) >> 8); - pContext->onUninit = mal_context_uninit__oss; - pContext->onDeviceIDEqual = mal_context_is_device_id_equal__oss; - pContext->onEnumDevices = mal_context_enumerate_devices__oss; - pContext->onGetDeviceInfo = mal_context_get_device_info__oss; - pContext->onDeviceInit = mal_device_init__oss; - pContext->onDeviceUninit = mal_device_uninit__oss; + pContext->onUninit = ma_context_uninit__oss; + pContext->onDeviceIDEqual = ma_context_is_device_id_equal__oss; + pContext->onEnumDevices = ma_context_enumerate_devices__oss; + pContext->onGetDeviceInfo = ma_context_get_device_info__oss; + pContext->onDeviceInit = ma_device_init__oss; + pContext->onDeviceUninit = ma_device_uninit__oss; pContext->onDeviceStart = NULL; /* Not required for synchronous backends. */ - pContext->onDeviceStop = mal_device_stop__oss; - pContext->onDeviceWrite = mal_device_write__oss; - pContext->onDeviceRead = mal_device_read__oss; + pContext->onDeviceStop = ma_device_stop__oss; + pContext->onDeviceWrite = ma_device_write__oss; + pContext->onDeviceRead = ma_device_read__oss; close(fd); return MA_SUCCESS; @@ -20070,13 +20070,13 @@ mal_result mal_context_init__oss(mal_context* pContext) #define MA_AAUDIO_UNSPECIFIED 0 -typedef int32_t mal_aaudio_result_t; -typedef int32_t mal_aaudio_direction_t; -typedef int32_t mal_aaudio_sharing_mode_t; -typedef int32_t mal_aaudio_format_t; -typedef int32_t mal_aaudio_stream_state_t; -typedef int32_t mal_aaudio_performance_mode_t; -typedef int32_t mal_aaudio_data_callback_result_t; +typedef int32_t ma_aaudio_result_t; +typedef int32_t ma_aaudio_direction_t; +typedef int32_t ma_aaudio_sharing_mode_t; +typedef int32_t ma_aaudio_format_t; +typedef int32_t ma_aaudio_stream_state_t; +typedef int32_t ma_aaudio_performance_mode_t; +typedef int32_t ma_aaudio_data_callback_result_t; /* Result codes. miniaudio only cares about the success code. */ #define MA_AAUDIO_OK 0 @@ -20119,37 +20119,37 @@ typedef int32_t mal_aaudio_data_callback_result_t; #define MA_AAUDIO_CALLBACK_RESULT_STOP 1 /* Objects. */ -typedef struct mal_AAudioStreamBuilder_t* mal_AAudioStreamBuilder; -typedef struct mal_AAudioStream_t* mal_AAudioStream; +typedef struct ma_AAudioStreamBuilder_t* ma_AAudioStreamBuilder; +typedef struct ma_AAudioStream_t* ma_AAudioStream; -typedef mal_aaudio_data_callback_result_t (*mal_AAudioStream_dataCallback)(mal_AAudioStream* pStream, void* pUserData, void* pAudioData, int32_t numFrames); +typedef ma_aaudio_data_callback_result_t (*ma_AAudioStream_dataCallback)(ma_AAudioStream* pStream, void* pUserData, void* pAudioData, int32_t numFrames); -typedef mal_aaudio_result_t (* MA_PFN_AAudio_createStreamBuilder) (mal_AAudioStreamBuilder** ppBuilder); -typedef mal_aaudio_result_t (* MA_PFN_AAudioStreamBuilder_delete) (mal_AAudioStreamBuilder* pBuilder); -typedef void (* MA_PFN_AAudioStreamBuilder_setDeviceId) (mal_AAudioStreamBuilder* pBuilder, int32_t deviceId); -typedef void (* MA_PFN_AAudioStreamBuilder_setDirection) (mal_AAudioStreamBuilder* pBuilder, mal_aaudio_direction_t direction); -typedef void (* MA_PFN_AAudioStreamBuilder_setSharingMode) (mal_AAudioStreamBuilder* pBuilder, mal_aaudio_sharing_mode_t sharingMode); -typedef void (* MA_PFN_AAudioStreamBuilder_setFormat) (mal_AAudioStreamBuilder* pBuilder, mal_aaudio_format_t format); -typedef void (* MA_PFN_AAudioStreamBuilder_setChannelCount) (mal_AAudioStreamBuilder* pBuilder, int32_t channelCount); -typedef void (* MA_PFN_AAudioStreamBuilder_setSampleRate) (mal_AAudioStreamBuilder* pBuilder, int32_t sampleRate); -typedef void (* MA_PFN_AAudioStreamBuilder_setBufferCapacityInFrames)(mal_AAudioStreamBuilder* pBuilder, int32_t numFrames); -typedef void (* MA_PFN_AAudioStreamBuilder_setFramesPerDataCallback) (mal_AAudioStreamBuilder* pBuilder, int32_t numFrames); -typedef void (* MA_PFN_AAudioStreamBuilder_setDataCallback) (mal_AAudioStreamBuilder* pBuilder, mal_AAudioStream_dataCallback callback, void* pUserData); -typedef void (* MA_PFN_AAudioStreamBuilder_setPerformanceMode) (mal_AAudioStreamBuilder* pBuilder, mal_aaudio_performance_mode_t mode); -typedef mal_aaudio_result_t (* MA_PFN_AAudioStreamBuilder_openStream) (mal_AAudioStreamBuilder* pBuilder, mal_AAudioStream** ppStream); -typedef mal_aaudio_result_t (* MA_PFN_AAudioStream_close) (mal_AAudioStream* pStream); -typedef mal_aaudio_stream_state_t (* MA_PFN_AAudioStream_getState) (mal_AAudioStream* pStream); -typedef mal_aaudio_result_t (* MA_PFN_AAudioStream_waitForStateChange) (mal_AAudioStream* pStream, mal_aaudio_stream_state_t inputState, mal_aaudio_stream_state_t* pNextState, int64_t timeoutInNanoseconds); -typedef mal_aaudio_format_t (* MA_PFN_AAudioStream_getFormat) (mal_AAudioStream* pStream); -typedef int32_t (* MA_PFN_AAudioStream_getChannelCount) (mal_AAudioStream* pStream); -typedef int32_t (* MA_PFN_AAudioStream_getSampleRate) (mal_AAudioStream* pStream); -typedef int32_t (* MA_PFN_AAudioStream_getBufferCapacityInFrames) (mal_AAudioStream* pStream); -typedef int32_t (* MA_PFN_AAudioStream_getFramesPerDataCallback) (mal_AAudioStream* pStream); -typedef int32_t (* MA_PFN_AAudioStream_getFramesPerBurst) (mal_AAudioStream* pStream); -typedef mal_aaudio_result_t (* MA_PFN_AAudioStream_requestStart) (mal_AAudioStream* pStream); -typedef mal_aaudio_result_t (* MA_PFN_AAudioStream_requestStop) (mal_AAudioStream* pStream); +typedef ma_aaudio_result_t (* MA_PFN_AAudio_createStreamBuilder) (ma_AAudioStreamBuilder** ppBuilder); +typedef ma_aaudio_result_t (* MA_PFN_AAudioStreamBuilder_delete) (ma_AAudioStreamBuilder* pBuilder); +typedef void (* MA_PFN_AAudioStreamBuilder_setDeviceId) (ma_AAudioStreamBuilder* pBuilder, int32_t deviceId); +typedef void (* MA_PFN_AAudioStreamBuilder_setDirection) (ma_AAudioStreamBuilder* pBuilder, ma_aaudio_direction_t direction); +typedef void (* MA_PFN_AAudioStreamBuilder_setSharingMode) (ma_AAudioStreamBuilder* pBuilder, ma_aaudio_sharing_mode_t sharingMode); +typedef void (* MA_PFN_AAudioStreamBuilder_setFormat) (ma_AAudioStreamBuilder* pBuilder, ma_aaudio_format_t format); +typedef void (* MA_PFN_AAudioStreamBuilder_setChannelCount) (ma_AAudioStreamBuilder* pBuilder, int32_t channelCount); +typedef void (* MA_PFN_AAudioStreamBuilder_setSampleRate) (ma_AAudioStreamBuilder* pBuilder, int32_t sampleRate); +typedef void (* MA_PFN_AAudioStreamBuilder_setBufferCapacityInFrames)(ma_AAudioStreamBuilder* pBuilder, int32_t numFrames); +typedef void (* MA_PFN_AAudioStreamBuilder_setFramesPerDataCallback) (ma_AAudioStreamBuilder* pBuilder, int32_t numFrames); +typedef void (* MA_PFN_AAudioStreamBuilder_setDataCallback) (ma_AAudioStreamBuilder* pBuilder, ma_AAudioStream_dataCallback callback, void* pUserData); +typedef void (* MA_PFN_AAudioStreamBuilder_setPerformanceMode) (ma_AAudioStreamBuilder* pBuilder, ma_aaudio_performance_mode_t mode); +typedef ma_aaudio_result_t (* MA_PFN_AAudioStreamBuilder_openStream) (ma_AAudioStreamBuilder* pBuilder, ma_AAudioStream** ppStream); +typedef ma_aaudio_result_t (* MA_PFN_AAudioStream_close) (ma_AAudioStream* pStream); +typedef ma_aaudio_stream_state_t (* MA_PFN_AAudioStream_getState) (ma_AAudioStream* pStream); +typedef ma_aaudio_result_t (* MA_PFN_AAudioStream_waitForStateChange) (ma_AAudioStream* pStream, ma_aaudio_stream_state_t inputState, ma_aaudio_stream_state_t* pNextState, int64_t timeoutInNanoseconds); +typedef ma_aaudio_format_t (* MA_PFN_AAudioStream_getFormat) (ma_AAudioStream* pStream); +typedef int32_t (* MA_PFN_AAudioStream_getChannelCount) (ma_AAudioStream* pStream); +typedef int32_t (* MA_PFN_AAudioStream_getSampleRate) (ma_AAudioStream* pStream); +typedef int32_t (* MA_PFN_AAudioStream_getBufferCapacityInFrames) (ma_AAudioStream* pStream); +typedef int32_t (* MA_PFN_AAudioStream_getFramesPerDataCallback) (ma_AAudioStream* pStream); +typedef int32_t (* MA_PFN_AAudioStream_getFramesPerBurst) (ma_AAudioStream* pStream); +typedef ma_aaudio_result_t (* MA_PFN_AAudioStream_requestStart) (ma_AAudioStream* pStream); +typedef ma_aaudio_result_t (* MA_PFN_AAudioStream_requestStop) (ma_AAudioStream* pStream); -mal_result mal_result_from_aaudio(mal_aaudio_result_t resultAA) +ma_result ma_result_from_aaudio(ma_aaudio_result_t resultAA) { switch (resultAA) { @@ -20160,131 +20160,131 @@ mal_result mal_result_from_aaudio(mal_aaudio_result_t resultAA) return MA_ERROR; } -mal_aaudio_data_callback_result_t mal_stream_data_callback_capture__aaudio(mal_AAudioStream* pStream, void* pUserData, void* pAudioData, int32_t frameCount) +ma_aaudio_data_callback_result_t ma_stream_data_callback_capture__aaudio(ma_AAudioStream* pStream, void* pUserData, void* pAudioData, int32_t frameCount) { - mal_device* pDevice = (mal_device*)pUserData; - mal_assert(pDevice != NULL); + ma_device* pDevice = (ma_device*)pUserData; + ma_assert(pDevice != NULL); - if (pDevice->type == mal_device_type_duplex) { - mal_device__handle_duplex_callback_capture(pDevice, frameCount, pAudioData, &pDevice->aaudio.duplexRB); + if (pDevice->type == ma_device_type_duplex) { + ma_device__handle_duplex_callback_capture(pDevice, frameCount, pAudioData, &pDevice->aaudio.duplexRB); } else { - mal_device__send_frames_to_client(pDevice, frameCount, pAudioData); /* Send directly to the client. */ + ma_device__send_frames_to_client(pDevice, frameCount, pAudioData); /* Send directly to the client. */ } (void)pStream; return MA_AAUDIO_CALLBACK_RESULT_CONTINUE; } -mal_aaudio_data_callback_result_t mal_stream_data_callback_playback__aaudio(mal_AAudioStream* pStream, void* pUserData, void* pAudioData, int32_t frameCount) +ma_aaudio_data_callback_result_t ma_stream_data_callback_playback__aaudio(ma_AAudioStream* pStream, void* pUserData, void* pAudioData, int32_t frameCount) { - mal_device* pDevice = (mal_device*)pUserData; - mal_assert(pDevice != NULL); + ma_device* pDevice = (ma_device*)pUserData; + ma_assert(pDevice != NULL); - if (pDevice->type == mal_device_type_duplex) { - mal_device__handle_duplex_callback_playback(pDevice, frameCount, pAudioData, &pDevice->aaudio.duplexRB); + if (pDevice->type == ma_device_type_duplex) { + ma_device__handle_duplex_callback_playback(pDevice, frameCount, pAudioData, &pDevice->aaudio.duplexRB); } else { - mal_device__read_frames_from_client(pDevice, frameCount, pAudioData); /* Read directly from the client. */ + ma_device__read_frames_from_client(pDevice, frameCount, pAudioData); /* Read directly from the client. */ } (void)pStream; return MA_AAUDIO_CALLBACK_RESULT_CONTINUE; } -mal_result mal_open_stream__aaudio(mal_context* pContext, mal_device_type deviceType, const mal_device_id* pDeviceID, mal_share_mode shareMode, const mal_device_config* pConfig, const mal_device* pDevice, mal_AAudioStream** ppStream) +ma_result ma_open_stream__aaudio(ma_context* pContext, ma_device_type deviceType, const ma_device_id* pDeviceID, ma_share_mode shareMode, const ma_device_config* pConfig, const ma_device* pDevice, ma_AAudioStream** ppStream) { - mal_AAudioStreamBuilder* pBuilder; - mal_aaudio_result_t resultAA; + ma_AAudioStreamBuilder* pBuilder; + ma_aaudio_result_t resultAA; - mal_assert(deviceType != mal_device_type_duplex); /* This function should not be called for a full-duplex device type. */ + ma_assert(deviceType != ma_device_type_duplex); /* This function should not be called for a full-duplex device type. */ *ppStream = NULL; resultAA = ((MA_PFN_AAudio_createStreamBuilder)pContext->aaudio.AAudio_createStreamBuilder)(&pBuilder); if (resultAA != MA_AAUDIO_OK) { - return mal_result_from_aaudio(resultAA); + return ma_result_from_aaudio(resultAA); } if (pDeviceID != NULL) { ((MA_PFN_AAudioStreamBuilder_setDeviceId)pContext->aaudio.AAudioStreamBuilder_setDeviceId)(pBuilder, pDeviceID->aaudio); } - ((MA_PFN_AAudioStreamBuilder_setDirection)pContext->aaudio.AAudioStreamBuilder_setDirection)(pBuilder, (deviceType == mal_device_type_playback) ? MA_AAUDIO_DIRECTION_OUTPUT : MA_AAUDIO_DIRECTION_INPUT); - ((MA_PFN_AAudioStreamBuilder_setSharingMode)pContext->aaudio.AAudioStreamBuilder_setSharingMode)(pBuilder, (shareMode == mal_share_mode_shared) ? MA_AAUDIO_SHARING_MODE_SHARED : MA_AAUDIO_SHARING_MODE_EXCLUSIVE); + ((MA_PFN_AAudioStreamBuilder_setDirection)pContext->aaudio.AAudioStreamBuilder_setDirection)(pBuilder, (deviceType == ma_device_type_playback) ? MA_AAUDIO_DIRECTION_OUTPUT : MA_AAUDIO_DIRECTION_INPUT); + ((MA_PFN_AAudioStreamBuilder_setSharingMode)pContext->aaudio.AAudioStreamBuilder_setSharingMode)(pBuilder, (shareMode == ma_share_mode_shared) ? MA_AAUDIO_SHARING_MODE_SHARED : MA_AAUDIO_SHARING_MODE_EXCLUSIVE); if (pConfig != NULL) { if (pDevice == NULL || !pDevice->usingDefaultSampleRate) { ((MA_PFN_AAudioStreamBuilder_setSampleRate)pContext->aaudio.AAudioStreamBuilder_setSampleRate)(pBuilder, pConfig->sampleRate); } - if (deviceType == mal_device_type_capture) { + if (deviceType == ma_device_type_capture) { if (pDevice == NULL || !pDevice->capture.usingDefaultChannels) { ((MA_PFN_AAudioStreamBuilder_setChannelCount)pContext->aaudio.AAudioStreamBuilder_setChannelCount)(pBuilder, pConfig->capture.channels); } if (pDevice == NULL || !pDevice->capture.usingDefaultFormat) { - ((MA_PFN_AAudioStreamBuilder_setFormat)pContext->aaudio.AAudioStreamBuilder_setFormat)(pBuilder, (pConfig->capture.format == mal_format_s16) ? MA_AAUDIO_FORMAT_PCM_I16 : MA_AAUDIO_FORMAT_PCM_FLOAT); + ((MA_PFN_AAudioStreamBuilder_setFormat)pContext->aaudio.AAudioStreamBuilder_setFormat)(pBuilder, (pConfig->capture.format == ma_format_s16) ? MA_AAUDIO_FORMAT_PCM_I16 : MA_AAUDIO_FORMAT_PCM_FLOAT); } } else { if (pDevice == NULL || !pDevice->playback.usingDefaultChannels) { ((MA_PFN_AAudioStreamBuilder_setChannelCount)pContext->aaudio.AAudioStreamBuilder_setChannelCount)(pBuilder, pConfig->playback.channels); } if (pDevice == NULL || !pDevice->playback.usingDefaultFormat) { - ((MA_PFN_AAudioStreamBuilder_setFormat)pContext->aaudio.AAudioStreamBuilder_setFormat)(pBuilder, (pConfig->playback.format == mal_format_s16) ? MA_AAUDIO_FORMAT_PCM_I16 : MA_AAUDIO_FORMAT_PCM_FLOAT); + ((MA_PFN_AAudioStreamBuilder_setFormat)pContext->aaudio.AAudioStreamBuilder_setFormat)(pBuilder, (pConfig->playback.format == ma_format_s16) ? MA_AAUDIO_FORMAT_PCM_I16 : MA_AAUDIO_FORMAT_PCM_FLOAT); } } - mal_uint32 bufferCapacityInFrames = pConfig->bufferSizeInFrames; + ma_uint32 bufferCapacityInFrames = pConfig->bufferSizeInFrames; if (bufferCapacityInFrames == 0) { - bufferCapacityInFrames = mal_calculate_buffer_size_in_frames_from_milliseconds(pConfig->bufferSizeInMilliseconds, pConfig->sampleRate); + bufferCapacityInFrames = ma_calculate_buffer_size_in_frames_from_milliseconds(pConfig->bufferSizeInMilliseconds, pConfig->sampleRate); } ((MA_PFN_AAudioStreamBuilder_setBufferCapacityInFrames)pContext->aaudio.AAudioStreamBuilder_setBufferCapacityInFrames)(pBuilder, bufferCapacityInFrames); ((MA_PFN_AAudioStreamBuilder_setFramesPerDataCallback)pContext->aaudio.AAudioStreamBuilder_setFramesPerDataCallback)(pBuilder, bufferCapacityInFrames / pConfig->periods); - if (deviceType == mal_device_type_capture) { - ((MA_PFN_AAudioStreamBuilder_setDataCallback)pContext->aaudio.AAudioStreamBuilder_setDataCallback)(pBuilder, mal_stream_data_callback_capture__aaudio, (void*)pDevice); + if (deviceType == ma_device_type_capture) { + ((MA_PFN_AAudioStreamBuilder_setDataCallback)pContext->aaudio.AAudioStreamBuilder_setDataCallback)(pBuilder, ma_stream_data_callback_capture__aaudio, (void*)pDevice); } else { - ((MA_PFN_AAudioStreamBuilder_setDataCallback)pContext->aaudio.AAudioStreamBuilder_setDataCallback)(pBuilder, mal_stream_data_callback_playback__aaudio, (void*)pDevice); + ((MA_PFN_AAudioStreamBuilder_setDataCallback)pContext->aaudio.AAudioStreamBuilder_setDataCallback)(pBuilder, ma_stream_data_callback_playback__aaudio, (void*)pDevice); } /* Not sure how this affects things, but since there's a mapping between miniaudio's performance profiles and AAudio's performance modes, let go ahead and set it. */ - ((MA_PFN_AAudioStreamBuilder_setPerformanceMode)pContext->aaudio.AAudioStreamBuilder_setPerformanceMode)(pBuilder, (pConfig->performanceProfile == mal_performance_profile_low_latency) ? MA_AAUDIO_PERFORMANCE_MODE_LOW_LATENCY : MA_AAUDIO_PERFORMANCE_MODE_NONE); + ((MA_PFN_AAudioStreamBuilder_setPerformanceMode)pContext->aaudio.AAudioStreamBuilder_setPerformanceMode)(pBuilder, (pConfig->performanceProfile == ma_performance_profile_low_latency) ? MA_AAUDIO_PERFORMANCE_MODE_LOW_LATENCY : MA_AAUDIO_PERFORMANCE_MODE_NONE); } resultAA = ((MA_PFN_AAudioStreamBuilder_openStream)pContext->aaudio.AAudioStreamBuilder_openStream)(pBuilder, ppStream); if (resultAA != MA_AAUDIO_OK) { *ppStream = NULL; ((MA_PFN_AAudioStreamBuilder_delete)pContext->aaudio.AAudioStreamBuilder_delete)(pBuilder); - return mal_result_from_aaudio(resultAA); + return ma_result_from_aaudio(resultAA); } ((MA_PFN_AAudioStreamBuilder_delete)pContext->aaudio.AAudioStreamBuilder_delete)(pBuilder); return MA_SUCCESS; } -mal_result mal_close_stream__aaudio(mal_context* pContext, mal_AAudioStream* pStream) +ma_result ma_close_stream__aaudio(ma_context* pContext, ma_AAudioStream* pStream) { - return mal_result_from_aaudio(((MA_PFN_AAudioStream_close)pContext->aaudio.AAudioStream_close)(pStream)); + return ma_result_from_aaudio(((MA_PFN_AAudioStream_close)pContext->aaudio.AAudioStream_close)(pStream)); } -mal_bool32 mal_has_default_device__aaudio(mal_context* pContext, mal_device_type deviceType) +ma_bool32 ma_has_default_device__aaudio(ma_context* pContext, ma_device_type deviceType) { /* The only way to know this is to try creating a stream. */ - mal_AAudioStream* pStream; - mal_result result = mal_open_stream__aaudio(pContext, deviceType, NULL, mal_share_mode_shared, NULL, NULL, &pStream); + ma_AAudioStream* pStream; + ma_result result = ma_open_stream__aaudio(pContext, deviceType, NULL, ma_share_mode_shared, NULL, NULL, &pStream); if (result != MA_SUCCESS) { return MA_FALSE; } - mal_close_stream__aaudio(pContext, pStream); + ma_close_stream__aaudio(pContext, pStream); return MA_TRUE; } -mal_result mal_wait_for_simple_state_transition__aaudio(mal_context* pContext, mal_AAudioStream* pStream, mal_aaudio_stream_state_t oldState, mal_aaudio_stream_state_t newState) +ma_result ma_wait_for_simple_state_transition__aaudio(ma_context* pContext, ma_AAudioStream* pStream, ma_aaudio_stream_state_t oldState, ma_aaudio_stream_state_t newState) { - mal_aaudio_stream_state_t actualNewState; - mal_aaudio_result_t resultAA = ((MA_PFN_AAudioStream_waitForStateChange)pContext->aaudio.AAudioStream_waitForStateChange)(pStream, oldState, &actualNewState, 5000000000); /* 5 second timeout. */ + ma_aaudio_stream_state_t actualNewState; + ma_aaudio_result_t resultAA = ((MA_PFN_AAudioStream_waitForStateChange)pContext->aaudio.AAudioStream_waitForStateChange)(pStream, oldState, &actualNewState, 5000000000); /* 5 second timeout. */ if (resultAA != MA_AAUDIO_OK) { - return mal_result_from_aaudio(resultAA); + return ma_result_from_aaudio(resultAA); } if (newState != actualNewState) { @@ -20295,61 +20295,61 @@ mal_result mal_wait_for_simple_state_transition__aaudio(mal_context* pContext, m } -mal_bool32 mal_context_is_device_id_equal__aaudio(mal_context* pContext, const mal_device_id* pID0, const mal_device_id* pID1) +ma_bool32 ma_context_is_device_id_equal__aaudio(ma_context* pContext, const ma_device_id* pID0, const ma_device_id* pID1) { - mal_assert(pContext != NULL); - mal_assert(pID0 != NULL); - mal_assert(pID1 != NULL); + ma_assert(pContext != NULL); + ma_assert(pID0 != NULL); + ma_assert(pID1 != NULL); (void)pContext; return pID0->aaudio == pID1->aaudio; } -mal_result mal_context_enumerate_devices__aaudio(mal_context* pContext, mal_enum_devices_callback_proc callback, void* pUserData) +ma_result ma_context_enumerate_devices__aaudio(ma_context* pContext, ma_enum_devices_callback_proc callback, void* pUserData) { - mal_bool32 cbResult = MA_TRUE; + ma_bool32 cbResult = MA_TRUE; - mal_assert(pContext != NULL); - mal_assert(callback != NULL); + ma_assert(pContext != NULL); + ma_assert(callback != NULL); /* Unfortunately AAudio does not have an enumeration API. Therefore I'm only going to report default devices, but only if it can instantiate a stream. */ /* Playback. */ if (cbResult) { - mal_device_info deviceInfo; - mal_zero_object(&deviceInfo); + ma_device_info deviceInfo; + ma_zero_object(&deviceInfo); deviceInfo.id.aaudio = MA_AAUDIO_UNSPECIFIED; - mal_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), MA_DEFAULT_PLAYBACK_DEVICE_NAME, (size_t)-1); + ma_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), MA_DEFAULT_PLAYBACK_DEVICE_NAME, (size_t)-1); - if (mal_has_default_device__aaudio(pContext, mal_device_type_playback)) { - cbResult = callback(pContext, mal_device_type_playback, &deviceInfo, pUserData); + if (ma_has_default_device__aaudio(pContext, ma_device_type_playback)) { + cbResult = callback(pContext, ma_device_type_playback, &deviceInfo, pUserData); } } /* Capture. */ if (cbResult) { - mal_device_info deviceInfo; - mal_zero_object(&deviceInfo); + ma_device_info deviceInfo; + ma_zero_object(&deviceInfo); deviceInfo.id.aaudio = MA_AAUDIO_UNSPECIFIED; - mal_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), MA_DEFAULT_CAPTURE_DEVICE_NAME, (size_t)-1); + ma_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), MA_DEFAULT_CAPTURE_DEVICE_NAME, (size_t)-1); - if (mal_has_default_device__aaudio(pContext, mal_device_type_capture)) { - cbResult = callback(pContext, mal_device_type_capture, &deviceInfo, pUserData); + if (ma_has_default_device__aaudio(pContext, ma_device_type_capture)) { + cbResult = callback(pContext, ma_device_type_capture, &deviceInfo, pUserData); } } return MA_SUCCESS; } -mal_result mal_context_get_device_info__aaudio(mal_context* pContext, mal_device_type deviceType, const mal_device_id* pDeviceID, mal_share_mode shareMode, mal_device_info* pDeviceInfo) +ma_result ma_context_get_device_info__aaudio(ma_context* pContext, ma_device_type deviceType, const ma_device_id* pDeviceID, ma_share_mode shareMode, ma_device_info* pDeviceInfo) { - mal_AAudioStream* pStream; - mal_result result; + ma_AAudioStream* pStream; + ma_result result; - mal_assert(pContext != NULL); + ma_assert(pContext != NULL); /* No exclusive mode with AAudio. */ - if (shareMode == mal_share_mode_exclusive) { + if (shareMode == ma_share_mode_exclusive) { return MA_SHARE_MODE_NOT_SUPPORTED; } @@ -20361,15 +20361,15 @@ mal_result mal_context_get_device_info__aaudio(mal_context* pContext, mal_device } /* Name */ - if (deviceType == mal_device_type_playback) { - mal_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), MA_DEFAULT_PLAYBACK_DEVICE_NAME, (size_t)-1); + if (deviceType == ma_device_type_playback) { + ma_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), MA_DEFAULT_PLAYBACK_DEVICE_NAME, (size_t)-1); } else { - mal_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), MA_DEFAULT_CAPTURE_DEVICE_NAME, (size_t)-1); + ma_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), MA_DEFAULT_CAPTURE_DEVICE_NAME, (size_t)-1); } /* We'll need to open the device to get accurate sample rate and channel count information. */ - result = mal_open_stream__aaudio(pContext, deviceType, pDeviceID, shareMode, NULL, NULL, &pStream); + result = ma_open_stream__aaudio(pContext, deviceType, pDeviceID, shareMode, NULL, NULL, &pStream); if (result != MA_SUCCESS) { return result; } @@ -20379,66 +20379,66 @@ mal_result mal_context_get_device_info__aaudio(mal_context* pContext, mal_device pDeviceInfo->minSampleRate = ((MA_PFN_AAudioStream_getSampleRate)pContext->aaudio.AAudioStream_getSampleRate)(pStream); pDeviceInfo->maxSampleRate = pDeviceInfo->minSampleRate; - mal_close_stream__aaudio(pContext, pStream); + ma_close_stream__aaudio(pContext, pStream); pStream = NULL; /* AAudio supports s16 and f32. */ pDeviceInfo->formatCount = 2; - pDeviceInfo->formats[0] = mal_format_s16; - pDeviceInfo->formats[1] = mal_format_f32; + pDeviceInfo->formats[0] = ma_format_s16; + pDeviceInfo->formats[1] = ma_format_f32; return MA_SUCCESS; } -void mal_device_uninit__aaudio(mal_device* pDevice) +void ma_device_uninit__aaudio(ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { - mal_close_stream__aaudio(pDevice->pContext, (mal_AAudioStream*)pDevice->aaudio.pStreamCapture); + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { + ma_close_stream__aaudio(pDevice->pContext, (ma_AAudioStream*)pDevice->aaudio.pStreamCapture); pDevice->aaudio.pStreamCapture = NULL; } - if (pDevice->type == mal_device_type_playback || pDevice->type == mal_device_type_duplex) { - mal_close_stream__aaudio(pDevice->pContext, (mal_AAudioStream*)pDevice->aaudio.pStreamPlayback); + if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) { + ma_close_stream__aaudio(pDevice->pContext, (ma_AAudioStream*)pDevice->aaudio.pStreamPlayback); pDevice->aaudio.pStreamPlayback = NULL; } - if (pDevice->type == mal_device_type_duplex) { - mal_pcm_rb_uninit(&pDevice->aaudio.duplexRB); + if (pDevice->type == ma_device_type_duplex) { + ma_pcm_rb_uninit(&pDevice->aaudio.duplexRB); } } -mal_result mal_device_init__aaudio(mal_context* pContext, const mal_device_config* pConfig, mal_device* pDevice) +ma_result ma_device_init__aaudio(ma_context* pContext, const ma_device_config* pConfig, ma_device* pDevice) { - mal_result result; + ma_result result; - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); /* No exclusive mode with AAudio. */ - if (((pConfig->deviceType == mal_device_type_playback || pConfig->deviceType == mal_device_type_duplex) && pConfig->playback.shareMode == mal_share_mode_exclusive) || - ((pConfig->deviceType == mal_device_type_capture || pConfig->deviceType == mal_device_type_duplex) && pConfig->capture.shareMode == mal_share_mode_exclusive)) { + if (((pConfig->deviceType == ma_device_type_playback || pConfig->deviceType == ma_device_type_duplex) && pConfig->playback.shareMode == ma_share_mode_exclusive) || + ((pConfig->deviceType == ma_device_type_capture || pConfig->deviceType == ma_device_type_duplex) && pConfig->capture.shareMode == ma_share_mode_exclusive)) { return MA_SHARE_MODE_NOT_SUPPORTED; } /* We first need to try opening the stream. */ - if (pConfig->deviceType == mal_device_type_capture || pConfig->deviceType == mal_device_type_duplex) { - result = mal_open_stream__aaudio(pContext, mal_device_type_capture, pConfig->capture.pDeviceID, pConfig->capture.shareMode, pConfig, pDevice, (mal_AAudioStream**)&pDevice->aaudio.pStreamCapture); + if (pConfig->deviceType == ma_device_type_capture || pConfig->deviceType == ma_device_type_duplex) { + result = ma_open_stream__aaudio(pContext, ma_device_type_capture, pConfig->capture.pDeviceID, pConfig->capture.shareMode, pConfig, pDevice, (ma_AAudioStream**)&pDevice->aaudio.pStreamCapture); if (result != MA_SUCCESS) { return result; /* Failed to open the AAudio stream. */ } - pDevice->capture.internalFormat = (((MA_PFN_AAudioStream_getFormat)pContext->aaudio.AAudioStream_getFormat)((mal_AAudioStream*)pDevice->aaudio.pStreamCapture) == MA_AAUDIO_FORMAT_PCM_I16) ? mal_format_s16 : mal_format_f32; - pDevice->capture.internalChannels = ((MA_PFN_AAudioStream_getChannelCount)pContext->aaudio.AAudioStream_getChannelCount)((mal_AAudioStream*)pDevice->aaudio.pStreamCapture); - pDevice->capture.internalSampleRate = ((MA_PFN_AAudioStream_getSampleRate)pContext->aaudio.AAudioStream_getSampleRate)((mal_AAudioStream*)pDevice->aaudio.pStreamCapture); - mal_get_standard_channel_map(mal_standard_channel_map_default, pDevice->capture.internalChannels, pDevice->capture.internalChannelMap); /* <-- Cannot find info on channel order, so assuming a default. */ - pDevice->capture.internalBufferSizeInFrames = ((MA_PFN_AAudioStream_getBufferCapacityInFrames)pContext->aaudio.AAudioStream_getBufferCapacityInFrames)((mal_AAudioStream*)pDevice->aaudio.pStreamCapture); + pDevice->capture.internalFormat = (((MA_PFN_AAudioStream_getFormat)pContext->aaudio.AAudioStream_getFormat)((ma_AAudioStream*)pDevice->aaudio.pStreamCapture) == MA_AAUDIO_FORMAT_PCM_I16) ? ma_format_s16 : ma_format_f32; + pDevice->capture.internalChannels = ((MA_PFN_AAudioStream_getChannelCount)pContext->aaudio.AAudioStream_getChannelCount)((ma_AAudioStream*)pDevice->aaudio.pStreamCapture); + pDevice->capture.internalSampleRate = ((MA_PFN_AAudioStream_getSampleRate)pContext->aaudio.AAudioStream_getSampleRate)((ma_AAudioStream*)pDevice->aaudio.pStreamCapture); + ma_get_standard_channel_map(ma_standard_channel_map_default, pDevice->capture.internalChannels, pDevice->capture.internalChannelMap); /* <-- Cannot find info on channel order, so assuming a default. */ + pDevice->capture.internalBufferSizeInFrames = ((MA_PFN_AAudioStream_getBufferCapacityInFrames)pContext->aaudio.AAudioStream_getBufferCapacityInFrames)((ma_AAudioStream*)pDevice->aaudio.pStreamCapture); /* TODO: When synchronous reading and writing is supported, use AAudioStream_getFramesPerBurst() instead of AAudioStream_getFramesPerDataCallback(). Keep * using AAudioStream_getFramesPerDataCallback() for asynchronous mode, though. */ - int32_t framesPerPeriod = ((MA_PFN_AAudioStream_getFramesPerDataCallback)pContext->aaudio.AAudioStream_getFramesPerDataCallback)((mal_AAudioStream*)pDevice->aaudio.pStreamCapture); + int32_t framesPerPeriod = ((MA_PFN_AAudioStream_getFramesPerDataCallback)pContext->aaudio.AAudioStream_getFramesPerDataCallback)((ma_AAudioStream*)pDevice->aaudio.pStreamCapture); if (framesPerPeriod > 0) { pDevice->capture.internalPeriods = 1; } else { @@ -20446,19 +20446,19 @@ mal_result mal_device_init__aaudio(mal_context* pContext, const mal_device_confi } } - if (pConfig->deviceType == mal_device_type_playback || pConfig->deviceType == mal_device_type_duplex) { - result = mal_open_stream__aaudio(pContext, mal_device_type_playback, pConfig->playback.pDeviceID, pConfig->playback.shareMode, pConfig, pDevice, (mal_AAudioStream**)&pDevice->aaudio.pStreamPlayback); + if (pConfig->deviceType == ma_device_type_playback || pConfig->deviceType == ma_device_type_duplex) { + result = ma_open_stream__aaudio(pContext, ma_device_type_playback, pConfig->playback.pDeviceID, pConfig->playback.shareMode, pConfig, pDevice, (ma_AAudioStream**)&pDevice->aaudio.pStreamPlayback); if (result != MA_SUCCESS) { return result; /* Failed to open the AAudio stream. */ } - pDevice->playback.internalFormat = (((MA_PFN_AAudioStream_getFormat)pContext->aaudio.AAudioStream_getFormat)((mal_AAudioStream*)pDevice->aaudio.pStreamPlayback) == MA_AAUDIO_FORMAT_PCM_I16) ? mal_format_s16 : mal_format_f32; - pDevice->playback.internalChannels = ((MA_PFN_AAudioStream_getChannelCount)pContext->aaudio.AAudioStream_getChannelCount)((mal_AAudioStream*)pDevice->aaudio.pStreamPlayback); - pDevice->playback.internalSampleRate = ((MA_PFN_AAudioStream_getSampleRate)pContext->aaudio.AAudioStream_getSampleRate)((mal_AAudioStream*)pDevice->aaudio.pStreamPlayback); - mal_get_standard_channel_map(mal_standard_channel_map_default, pDevice->playback.internalChannels, pDevice->playback.internalChannelMap); /* <-- Cannot find info on channel order, so assuming a default. */ - pDevice->playback.internalBufferSizeInFrames = ((MA_PFN_AAudioStream_getBufferCapacityInFrames)pContext->aaudio.AAudioStream_getBufferCapacityInFrames)((mal_AAudioStream*)pDevice->aaudio.pStreamPlayback); + pDevice->playback.internalFormat = (((MA_PFN_AAudioStream_getFormat)pContext->aaudio.AAudioStream_getFormat)((ma_AAudioStream*)pDevice->aaudio.pStreamPlayback) == MA_AAUDIO_FORMAT_PCM_I16) ? ma_format_s16 : ma_format_f32; + pDevice->playback.internalChannels = ((MA_PFN_AAudioStream_getChannelCount)pContext->aaudio.AAudioStream_getChannelCount)((ma_AAudioStream*)pDevice->aaudio.pStreamPlayback); + pDevice->playback.internalSampleRate = ((MA_PFN_AAudioStream_getSampleRate)pContext->aaudio.AAudioStream_getSampleRate)((ma_AAudioStream*)pDevice->aaudio.pStreamPlayback); + ma_get_standard_channel_map(ma_standard_channel_map_default, pDevice->playback.internalChannels, pDevice->playback.internalChannelMap); /* <-- Cannot find info on channel order, so assuming a default. */ + pDevice->playback.internalBufferSizeInFrames = ((MA_PFN_AAudioStream_getBufferCapacityInFrames)pContext->aaudio.AAudioStream_getBufferCapacityInFrames)((ma_AAudioStream*)pDevice->aaudio.pStreamPlayback); - int32_t framesPerPeriod = ((MA_PFN_AAudioStream_getFramesPerDataCallback)pContext->aaudio.AAudioStream_getFramesPerDataCallback)((mal_AAudioStream*)pDevice->aaudio.pStreamPlayback); + int32_t framesPerPeriod = ((MA_PFN_AAudioStream_getFramesPerDataCallback)pContext->aaudio.AAudioStream_getFramesPerDataCallback)((ma_AAudioStream*)pDevice->aaudio.pStreamPlayback); if (framesPerPeriod > 0) { pDevice->playback.internalPeriods = 1; } else { @@ -20466,46 +20466,46 @@ mal_result mal_device_init__aaudio(mal_context* pContext, const mal_device_confi } } - if (pConfig->deviceType == mal_device_type_duplex) { - mal_uint32 rbSizeInFrames = (mal_uint32)mal_calculate_frame_count_after_src(pDevice->sampleRate, pDevice->capture.internalSampleRate, pDevice->capture.internalBufferSizeInFrames); - mal_result result = mal_pcm_rb_init(pDevice->capture.format, pDevice->capture.channels, rbSizeInFrames, NULL, &pDevice->aaudio.duplexRB); + if (pConfig->deviceType == ma_device_type_duplex) { + ma_uint32 rbSizeInFrames = (ma_uint32)ma_calculate_frame_count_after_src(pDevice->sampleRate, pDevice->capture.internalSampleRate, pDevice->capture.internalBufferSizeInFrames); + ma_result result = ma_pcm_rb_init(pDevice->capture.format, pDevice->capture.channels, rbSizeInFrames, NULL, &pDevice->aaudio.duplexRB); if (result != MA_SUCCESS) { - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { - mal_close_stream__aaudio(pDevice->pContext, (mal_AAudioStream*)pDevice->aaudio.pStreamCapture); + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { + ma_close_stream__aaudio(pDevice->pContext, (ma_AAudioStream*)pDevice->aaudio.pStreamCapture); } - if (pDevice->type == mal_device_type_playback || pDevice->type == mal_device_type_duplex) { - mal_close_stream__aaudio(pDevice->pContext, (mal_AAudioStream*)pDevice->aaudio.pStreamPlayback); + if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) { + ma_close_stream__aaudio(pDevice->pContext, (ma_AAudioStream*)pDevice->aaudio.pStreamPlayback); } - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[AAudio] Failed to initialize ring buffer.", result); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[AAudio] Failed to initialize ring buffer.", result); } } return MA_SUCCESS; } -mal_result mal_device_start_stream__aaudio(mal_device* pDevice, mal_AAudioStream* pStream) +ma_result ma_device_start_stream__aaudio(ma_device* pDevice, ma_AAudioStream* pStream) { - mal_aaudio_result_t resultAA; + ma_aaudio_result_t resultAA; - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); resultAA = ((MA_PFN_AAudioStream_requestStart)pDevice->pContext->aaudio.AAudioStream_requestStart)(pStream); if (resultAA != MA_AAUDIO_OK) { - return mal_result_from_aaudio(resultAA); + return ma_result_from_aaudio(resultAA); } /* Do we actually need to wait for the device to transition into it's started state? */ /* The device should be in either a starting or started state. If it's not set to started we need to wait for it to transition. It should go from starting to started. */ - mal_aaudio_stream_state_t currentState = ((MA_PFN_AAudioStream_getState)pDevice->pContext->aaudio.AAudioStream_getState)(pStream); + ma_aaudio_stream_state_t currentState = ((MA_PFN_AAudioStream_getState)pDevice->pContext->aaudio.AAudioStream_getState)(pStream); if (currentState != MA_AAUDIO_STREAM_STATE_STARTED) { - mal_result result; + ma_result result; if (currentState != MA_AAUDIO_STREAM_STATE_STARTING) { return MA_ERROR; /* Expecting the stream to be a starting or started state. */ } - result = mal_wait_for_simple_state_transition__aaudio(pDevice->pContext, pStream, currentState, MA_AAUDIO_STREAM_STATE_STARTED); + result = ma_wait_for_simple_state_transition__aaudio(pDevice->pContext, pStream, currentState, MA_AAUDIO_STREAM_STATE_STARTED); if (result != MA_SUCCESS) { return result; } @@ -20514,27 +20514,27 @@ mal_result mal_device_start_stream__aaudio(mal_device* pDevice, mal_AAudioStream return MA_SUCCESS; } -mal_result mal_device_stop_stream__aaudio(mal_device* pDevice, mal_AAudioStream* pStream) +ma_result ma_device_stop_stream__aaudio(ma_device* pDevice, ma_AAudioStream* pStream) { - mal_aaudio_result_t resultAA; + ma_aaudio_result_t resultAA; - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); resultAA = ((MA_PFN_AAudioStream_requestStop)pDevice->pContext->aaudio.AAudioStream_requestStop)(pStream); if (resultAA != MA_AAUDIO_OK) { - return mal_result_from_aaudio(resultAA); + return ma_result_from_aaudio(resultAA); } /* The device should be in either a stopping or stopped state. If it's not set to started we need to wait for it to transition. It should go from stopping to stopped. */ - mal_aaudio_stream_state_t currentState = ((MA_PFN_AAudioStream_getState)pDevice->pContext->aaudio.AAudioStream_getState)(pStream); + ma_aaudio_stream_state_t currentState = ((MA_PFN_AAudioStream_getState)pDevice->pContext->aaudio.AAudioStream_getState)(pStream); if (currentState != MA_AAUDIO_STREAM_STATE_STOPPED) { - mal_result result; + ma_result result; if (currentState != MA_AAUDIO_STREAM_STATE_STOPPING) { return MA_ERROR; /* Expecting the stream to be a stopping or stopped state. */ } - result = mal_wait_for_simple_state_transition__aaudio(pDevice->pContext, pStream, currentState, MA_AAUDIO_STREAM_STATE_STOPPED); + result = ma_wait_for_simple_state_transition__aaudio(pDevice->pContext, pStream, currentState, MA_AAUDIO_STREAM_STATE_STOPPED); if (result != MA_SUCCESS) { return result; } @@ -20543,22 +20543,22 @@ mal_result mal_device_stop_stream__aaudio(mal_device* pDevice, mal_AAudioStream* return MA_SUCCESS; } -mal_result mal_device_start__aaudio(mal_device* pDevice) +ma_result ma_device_start__aaudio(ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { - mal_result result = mal_device_start_stream__aaudio(pDevice, (mal_AAudioStream*)pDevice->aaudio.pStreamCapture); + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { + ma_result result = ma_device_start_stream__aaudio(pDevice, (ma_AAudioStream*)pDevice->aaudio.pStreamCapture); if (result != MA_SUCCESS) { return result; } } - if (pDevice->type == mal_device_type_playback || pDevice->type == mal_device_type_duplex) { - mal_result result = mal_device_start_stream__aaudio(pDevice, (mal_AAudioStream*)pDevice->aaudio.pStreamPlayback); + if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) { + ma_result result = ma_device_start_stream__aaudio(pDevice, (ma_AAudioStream*)pDevice->aaudio.pStreamPlayback); if (result != MA_SUCCESS) { - if (pDevice->type == mal_device_type_duplex) { - mal_device_stop_stream__aaudio(pDevice, (mal_AAudioStream*)pDevice->aaudio.pStreamCapture); + if (pDevice->type == ma_device_type_duplex) { + ma_device_stop_stream__aaudio(pDevice, (ma_AAudioStream*)pDevice->aaudio.pStreamCapture); } return result; } @@ -20567,25 +20567,25 @@ mal_result mal_device_start__aaudio(mal_device* pDevice) return MA_SUCCESS; } -mal_result mal_device_stop__aaudio(mal_device* pDevice) +ma_result ma_device_stop__aaudio(ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { - mal_result result = mal_device_stop_stream__aaudio(pDevice, (mal_AAudioStream*)pDevice->aaudio.pStreamCapture); + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { + ma_result result = ma_device_stop_stream__aaudio(pDevice, (ma_AAudioStream*)pDevice->aaudio.pStreamCapture); if (result != MA_SUCCESS) { return result; } } - if (pDevice->type == mal_device_type_playback || pDevice->type == mal_device_type_duplex) { - mal_result result = mal_device_stop_stream__aaudio(pDevice, (mal_AAudioStream*)pDevice->aaudio.pStreamPlayback); + if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) { + ma_result result = ma_device_stop_stream__aaudio(pDevice, (ma_AAudioStream*)pDevice->aaudio.pStreamPlayback); if (result != MA_SUCCESS) { return result; } } - mal_stop_proc onStop = pDevice->onStop; + ma_stop_proc onStop = pDevice->onStop; if (onStop) { onStop(pDevice); } @@ -20594,28 +20594,28 @@ mal_result mal_device_stop__aaudio(mal_device* pDevice) } -mal_result mal_context_uninit__aaudio(mal_context* pContext) +ma_result ma_context_uninit__aaudio(ma_context* pContext) { - mal_assert(pContext != NULL); - mal_assert(pContext->backend == mal_backend_aaudio); + ma_assert(pContext != NULL); + ma_assert(pContext->backend == ma_backend_aaudio); - mal_dlclose(pContext->aaudio.hAAudio); + ma_dlclose(pContext->aaudio.hAAudio); pContext->aaudio.hAAudio = NULL; return MA_SUCCESS; } -mal_result mal_context_init__aaudio(mal_context* pContext) +ma_result ma_context_init__aaudio(ma_context* pContext) { - mal_assert(pContext != NULL); + ma_assert(pContext != NULL); (void)pContext; const char* libNames[] = { "libaaudio.so" }; - for (size_t i = 0; i < mal_countof(libNames); ++i) { - pContext->aaudio.hAAudio = mal_dlopen(libNames[i]); + for (size_t i = 0; i < ma_countof(libNames); ++i) { + pContext->aaudio.hAAudio = ma_dlopen(libNames[i]); if (pContext->aaudio.hAAudio != NULL) { break; } @@ -20625,41 +20625,41 @@ mal_result mal_context_init__aaudio(mal_context* pContext) return MA_FAILED_TO_INIT_BACKEND; } - pContext->aaudio.AAudio_createStreamBuilder = (mal_proc)mal_dlsym(pContext->aaudio.hAAudio, "AAudio_createStreamBuilder"); - pContext->aaudio.AAudioStreamBuilder_delete = (mal_proc)mal_dlsym(pContext->aaudio.hAAudio, "AAudioStreamBuilder_delete"); - pContext->aaudio.AAudioStreamBuilder_setDeviceId = (mal_proc)mal_dlsym(pContext->aaudio.hAAudio, "AAudioStreamBuilder_setDeviceId"); - pContext->aaudio.AAudioStreamBuilder_setDirection = (mal_proc)mal_dlsym(pContext->aaudio.hAAudio, "AAudioStreamBuilder_setDirection"); - pContext->aaudio.AAudioStreamBuilder_setSharingMode = (mal_proc)mal_dlsym(pContext->aaudio.hAAudio, "AAudioStreamBuilder_setSharingMode"); - pContext->aaudio.AAudioStreamBuilder_setFormat = (mal_proc)mal_dlsym(pContext->aaudio.hAAudio, "AAudioStreamBuilder_setFormat"); - pContext->aaudio.AAudioStreamBuilder_setChannelCount = (mal_proc)mal_dlsym(pContext->aaudio.hAAudio, "AAudioStreamBuilder_setChannelCount"); - pContext->aaudio.AAudioStreamBuilder_setSampleRate = (mal_proc)mal_dlsym(pContext->aaudio.hAAudio, "AAudioStreamBuilder_setSampleRate"); - pContext->aaudio.AAudioStreamBuilder_setBufferCapacityInFrames = (mal_proc)mal_dlsym(pContext->aaudio.hAAudio, "AAudioStreamBuilder_setBufferCapacityInFrames"); - pContext->aaudio.AAudioStreamBuilder_setFramesPerDataCallback = (mal_proc)mal_dlsym(pContext->aaudio.hAAudio, "AAudioStreamBuilder_setFramesPerDataCallback"); - pContext->aaudio.AAudioStreamBuilder_setDataCallback = (mal_proc)mal_dlsym(pContext->aaudio.hAAudio, "AAudioStreamBuilder_setDataCallback"); - pContext->aaudio.AAudioStreamBuilder_setPerformanceMode = (mal_proc)mal_dlsym(pContext->aaudio.hAAudio, "AAudioStreamBuilder_setPerformanceMode"); - pContext->aaudio.AAudioStreamBuilder_openStream = (mal_proc)mal_dlsym(pContext->aaudio.hAAudio, "AAudioStreamBuilder_openStream"); - pContext->aaudio.AAudioStream_close = (mal_proc)mal_dlsym(pContext->aaudio.hAAudio, "AAudioStream_close"); - pContext->aaudio.AAudioStream_getState = (mal_proc)mal_dlsym(pContext->aaudio.hAAudio, "AAudioStream_getState"); - pContext->aaudio.AAudioStream_waitForStateChange = (mal_proc)mal_dlsym(pContext->aaudio.hAAudio, "AAudioStream_waitForStateChange"); - pContext->aaudio.AAudioStream_getFormat = (mal_proc)mal_dlsym(pContext->aaudio.hAAudio, "AAudioStream_getFormat"); - pContext->aaudio.AAudioStream_getChannelCount = (mal_proc)mal_dlsym(pContext->aaudio.hAAudio, "AAudioStream_getChannelCount"); - pContext->aaudio.AAudioStream_getSampleRate = (mal_proc)mal_dlsym(pContext->aaudio.hAAudio, "AAudioStream_getSampleRate"); - pContext->aaudio.AAudioStream_getBufferCapacityInFrames = (mal_proc)mal_dlsym(pContext->aaudio.hAAudio, "AAudioStream_getBufferCapacityInFrames"); - pContext->aaudio.AAudioStream_getFramesPerDataCallback = (mal_proc)mal_dlsym(pContext->aaudio.hAAudio, "AAudioStream_getFramesPerDataCallback"); - pContext->aaudio.AAudioStream_getFramesPerBurst = (mal_proc)mal_dlsym(pContext->aaudio.hAAudio, "AAudioStream_getFramesPerBurst"); - pContext->aaudio.AAudioStream_requestStart = (mal_proc)mal_dlsym(pContext->aaudio.hAAudio, "AAudioStream_requestStart"); - pContext->aaudio.AAudioStream_requestStop = (mal_proc)mal_dlsym(pContext->aaudio.hAAudio, "AAudioStream_requestStop"); + pContext->aaudio.AAudio_createStreamBuilder = (ma_proc)ma_dlsym(pContext->aaudio.hAAudio, "AAudio_createStreamBuilder"); + pContext->aaudio.AAudioStreamBuilder_delete = (ma_proc)ma_dlsym(pContext->aaudio.hAAudio, "AAudioStreamBuilder_delete"); + pContext->aaudio.AAudioStreamBuilder_setDeviceId = (ma_proc)ma_dlsym(pContext->aaudio.hAAudio, "AAudioStreamBuilder_setDeviceId"); + pContext->aaudio.AAudioStreamBuilder_setDirection = (ma_proc)ma_dlsym(pContext->aaudio.hAAudio, "AAudioStreamBuilder_setDirection"); + pContext->aaudio.AAudioStreamBuilder_setSharingMode = (ma_proc)ma_dlsym(pContext->aaudio.hAAudio, "AAudioStreamBuilder_setSharingMode"); + pContext->aaudio.AAudioStreamBuilder_setFormat = (ma_proc)ma_dlsym(pContext->aaudio.hAAudio, "AAudioStreamBuilder_setFormat"); + pContext->aaudio.AAudioStreamBuilder_setChannelCount = (ma_proc)ma_dlsym(pContext->aaudio.hAAudio, "AAudioStreamBuilder_setChannelCount"); + pContext->aaudio.AAudioStreamBuilder_setSampleRate = (ma_proc)ma_dlsym(pContext->aaudio.hAAudio, "AAudioStreamBuilder_setSampleRate"); + pContext->aaudio.AAudioStreamBuilder_setBufferCapacityInFrames = (ma_proc)ma_dlsym(pContext->aaudio.hAAudio, "AAudioStreamBuilder_setBufferCapacityInFrames"); + pContext->aaudio.AAudioStreamBuilder_setFramesPerDataCallback = (ma_proc)ma_dlsym(pContext->aaudio.hAAudio, "AAudioStreamBuilder_setFramesPerDataCallback"); + pContext->aaudio.AAudioStreamBuilder_setDataCallback = (ma_proc)ma_dlsym(pContext->aaudio.hAAudio, "AAudioStreamBuilder_setDataCallback"); + pContext->aaudio.AAudioStreamBuilder_setPerformanceMode = (ma_proc)ma_dlsym(pContext->aaudio.hAAudio, "AAudioStreamBuilder_setPerformanceMode"); + pContext->aaudio.AAudioStreamBuilder_openStream = (ma_proc)ma_dlsym(pContext->aaudio.hAAudio, "AAudioStreamBuilder_openStream"); + pContext->aaudio.AAudioStream_close = (ma_proc)ma_dlsym(pContext->aaudio.hAAudio, "AAudioStream_close"); + pContext->aaudio.AAudioStream_getState = (ma_proc)ma_dlsym(pContext->aaudio.hAAudio, "AAudioStream_getState"); + pContext->aaudio.AAudioStream_waitForStateChange = (ma_proc)ma_dlsym(pContext->aaudio.hAAudio, "AAudioStream_waitForStateChange"); + pContext->aaudio.AAudioStream_getFormat = (ma_proc)ma_dlsym(pContext->aaudio.hAAudio, "AAudioStream_getFormat"); + pContext->aaudio.AAudioStream_getChannelCount = (ma_proc)ma_dlsym(pContext->aaudio.hAAudio, "AAudioStream_getChannelCount"); + pContext->aaudio.AAudioStream_getSampleRate = (ma_proc)ma_dlsym(pContext->aaudio.hAAudio, "AAudioStream_getSampleRate"); + pContext->aaudio.AAudioStream_getBufferCapacityInFrames = (ma_proc)ma_dlsym(pContext->aaudio.hAAudio, "AAudioStream_getBufferCapacityInFrames"); + pContext->aaudio.AAudioStream_getFramesPerDataCallback = (ma_proc)ma_dlsym(pContext->aaudio.hAAudio, "AAudioStream_getFramesPerDataCallback"); + pContext->aaudio.AAudioStream_getFramesPerBurst = (ma_proc)ma_dlsym(pContext->aaudio.hAAudio, "AAudioStream_getFramesPerBurst"); + pContext->aaudio.AAudioStream_requestStart = (ma_proc)ma_dlsym(pContext->aaudio.hAAudio, "AAudioStream_requestStart"); + pContext->aaudio.AAudioStream_requestStop = (ma_proc)ma_dlsym(pContext->aaudio.hAAudio, "AAudioStream_requestStop"); pContext->isBackendAsynchronous = MA_TRUE; - pContext->onUninit = mal_context_uninit__aaudio; - pContext->onDeviceIDEqual = mal_context_is_device_id_equal__aaudio; - pContext->onEnumDevices = mal_context_enumerate_devices__aaudio; - pContext->onGetDeviceInfo = mal_context_get_device_info__aaudio; - pContext->onDeviceInit = mal_device_init__aaudio; - pContext->onDeviceUninit = mal_device_uninit__aaudio; - pContext->onDeviceStart = mal_device_start__aaudio; - pContext->onDeviceStop = mal_device_stop__aaudio; + pContext->onUninit = ma_context_uninit__aaudio; + pContext->onDeviceIDEqual = ma_context_is_device_id_equal__aaudio; + pContext->onEnumDevices = ma_context_enumerate_devices__aaudio; + pContext->onGetDeviceInfo = ma_context_get_device_info__aaudio; + pContext->onDeviceInit = ma_device_init__aaudio; + pContext->onDeviceUninit = ma_device_uninit__aaudio; + pContext->onDeviceStart = ma_device_start__aaudio; + pContext->onDeviceStop = ma_device_stop__aaudio; return MA_SUCCESS; } @@ -20680,7 +20680,7 @@ mal_result mal_context_init__aaudio(mal_context* pContext) // OpenSL|ES has one-per-application objects :( SLObjectItf g_malEngineObjectSL = NULL; SLEngineItf g_malEngineSL = NULL; -mal_uint32 g_malOpenSLInitCounter = 0; +ma_uint32 g_malOpenSLInitCounter = 0; #define MA_OPENSL_OBJ(p) (*((SLObjectItf)(p))) #define MA_OPENSL_OUTPUTMIX(p) (*((SLOutputMixItf)(p))) @@ -20694,7 +20694,7 @@ mal_uint32 g_malOpenSLInitCounter = 0; #endif // Converts an individual OpenSL-style channel identifier (SL_SPEAKER_FRONT_LEFT, etc.) to miniaudio. -mal_uint8 mal_channel_id_to_mal__opensl(SLuint32 id) +ma_uint8 ma_channel_id_to_ma__opensl(SLuint32 id) { switch (id) { @@ -20721,7 +20721,7 @@ mal_uint8 mal_channel_id_to_mal__opensl(SLuint32 id) } // Converts an individual miniaudio channel identifier (MA_CHANNEL_FRONT_LEFT, etc.) to OpenSL-style. -SLuint32 mal_channel_id_to_opensl(mal_uint8 id) +SLuint32 ma_channel_id_to_opensl(ma_uint8 id) { switch (id) { @@ -20749,18 +20749,18 @@ SLuint32 mal_channel_id_to_opensl(mal_uint8 id) } // Converts a channel mapping to an OpenSL-style channel mask. -SLuint32 mal_channel_map_to_channel_mask__opensl(const mal_channel channelMap[MA_MAX_CHANNELS], mal_uint32 channels) +SLuint32 ma_channel_map_to_channel_mask__opensl(const ma_channel channelMap[MA_MAX_CHANNELS], ma_uint32 channels) { SLuint32 channelMask = 0; - for (mal_uint32 iChannel = 0; iChannel < channels; ++iChannel) { - channelMask |= mal_channel_id_to_opensl(channelMap[iChannel]); + for (ma_uint32 iChannel = 0; iChannel < channels; ++iChannel) { + channelMask |= ma_channel_id_to_opensl(channelMap[iChannel]); } return channelMask; } // Converts an OpenSL-style channel mask to a miniaudio channel map. -void mal_channel_mask_to_channel_map__opensl(SLuint32 channelMask, mal_uint32 channels, mal_channel channelMap[MA_MAX_CHANNELS]) +void ma_channel_mask_to_channel_map__opensl(SLuint32 channelMask, ma_uint32 channels, ma_channel channelMap[MA_MAX_CHANNELS]) { if (channels == 1 && channelMask == 0) { channelMap[0] = MA_CHANNEL_MONO; @@ -20772,12 +20772,12 @@ void mal_channel_mask_to_channel_map__opensl(SLuint32 channelMask, mal_uint32 ch channelMap[0] = MA_CHANNEL_MONO; } else { // Just iterate over each bit. - mal_uint32 iChannel = 0; - for (mal_uint32 iBit = 0; iBit < 32; ++iBit) { + ma_uint32 iChannel = 0; + for (ma_uint32 iBit = 0; iBit < 32; ++iBit) { SLuint32 bitValue = (channelMask & (1UL << iBit)); if (bitValue != 0) { // The bit is set. - channelMap[iChannel] = mal_channel_id_to_mal__opensl(bitValue); + channelMap[iChannel] = ma_channel_id_to_ma__opensl(bitValue); iChannel += 1; } } @@ -20785,7 +20785,7 @@ void mal_channel_mask_to_channel_map__opensl(SLuint32 channelMask, mal_uint32 ch } } -SLuint32 mal_round_to_standard_sample_rate__opensl(SLuint32 samplesPerSec) +SLuint32 ma_round_to_standard_sample_rate__opensl(SLuint32 samplesPerSec) { if (samplesPerSec <= SL_SAMPLINGRATE_8) { return SL_SAMPLINGRATE_8; @@ -20835,22 +20835,22 @@ SLuint32 mal_round_to_standard_sample_rate__opensl(SLuint32 samplesPerSec) } -mal_bool32 mal_context_is_device_id_equal__opensl(mal_context* pContext, const mal_device_id* pID0, const mal_device_id* pID1) +ma_bool32 ma_context_is_device_id_equal__opensl(ma_context* pContext, const ma_device_id* pID0, const ma_device_id* pID1) { - mal_assert(pContext != NULL); - mal_assert(pID0 != NULL); - mal_assert(pID1 != NULL); + ma_assert(pContext != NULL); + ma_assert(pID0 != NULL); + ma_assert(pID1 != NULL); (void)pContext; return pID0->opensl == pID1->opensl; } -mal_result mal_context_enumerate_devices__opensl(mal_context* pContext, mal_enum_devices_callback_proc callback, void* pUserData) +ma_result ma_context_enumerate_devices__opensl(ma_context* pContext, ma_enum_devices_callback_proc callback, void* pUserData) { - mal_assert(pContext != NULL); - mal_assert(callback != NULL); + ma_assert(pContext != NULL); + ma_assert(callback != NULL); - mal_assert(g_malOpenSLInitCounter > 0); /* <-- If you trigger this it means you've either not initialized the context, or you've uninitialized it and then attempted to enumerate devices. */ + ma_assert(g_malOpenSLInitCounter > 0); /* <-- If you trigger this it means you've either not initialized the context, or you've uninitialized it and then attempted to enumerate devices. */ if (g_malOpenSLInitCounter == 0) { return MA_INVALID_OPERATION; } @@ -20859,7 +20859,7 @@ mal_result mal_context_enumerate_devices__opensl(mal_context* pContext, mal_enum // // This is currently untested, so for now we are just returning default devices. #if 0 && !defined(MA_ANDROID) - mal_bool32 isTerminated = MA_FALSE; + ma_bool32 isTerminated = MA_FALSE; SLuint32 pDeviceIDs[128]; SLint32 deviceCount = sizeof(pDeviceIDs) / sizeof(pDeviceIDs[0]); @@ -20879,16 +20879,16 @@ mal_result mal_context_enumerate_devices__opensl(mal_context* pContext, mal_enum } for (SLint32 iDevice = 0; iDevice < deviceCount; ++iDevice) { - mal_device_info deviceInfo; - mal_zero_object(&deviceInfo); + ma_device_info deviceInfo; + ma_zero_object(&deviceInfo); deviceInfo.id.opensl = pDeviceIDs[iDevice]; SLAudioOutputDescriptor desc; resultSL = (*deviceCaps)->QueryAudioOutputCapabilities(deviceCaps, deviceInfo.id.opensl, &desc); if (resultSL == SL_RESULT_SUCCESS) { - mal_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), (const char*)desc.pDeviceName, (size_t)-1); + ma_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), (const char*)desc.pDeviceName, (size_t)-1); - mal_bool32 cbResult = callback(pContext, mal_device_type_playback, &deviceInfo, pUserData); + ma_bool32 cbResult = callback(pContext, ma_device_type_playback, &deviceInfo, pUserData); if (cbResult == MA_FALSE) { isTerminated = MA_TRUE; break; @@ -20905,16 +20905,16 @@ mal_result mal_context_enumerate_devices__opensl(mal_context* pContext, mal_enum } for (SLint32 iDevice = 0; iDevice < deviceCount; ++iDevice) { - mal_device_info deviceInfo; - mal_zero_object(&deviceInfo); + ma_device_info deviceInfo; + ma_zero_object(&deviceInfo); deviceInfo.id.opensl = pDeviceIDs[iDevice]; SLAudioInputDescriptor desc; resultSL = (*deviceCaps)->QueryAudioInputCapabilities(deviceCaps, deviceInfo.id.opensl, &desc); if (resultSL == SL_RESULT_SUCCESS) { - mal_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), (const char*)desc.deviceName, (size_t)-1); + ma_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), (const char*)desc.deviceName, (size_t)-1); - mal_bool32 cbResult = callback(pContext, mal_device_type_capture, &deviceInfo, pUserData); + ma_bool32 cbResult = callback(pContext, ma_device_type_capture, &deviceInfo, pUserData); if (cbResult == MA_FALSE) { isTerminated = MA_TRUE; break; @@ -20929,38 +20929,38 @@ mal_result mal_context_enumerate_devices__opensl(mal_context* pContext, mal_enum #endif return_default_device:; - mal_bool32 cbResult = MA_TRUE; + ma_bool32 cbResult = MA_TRUE; // Playback. if (cbResult) { - mal_device_info deviceInfo; - mal_zero_object(&deviceInfo); - mal_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), MA_DEFAULT_PLAYBACK_DEVICE_NAME, (size_t)-1); - cbResult = callback(pContext, mal_device_type_playback, &deviceInfo, pUserData); + ma_device_info deviceInfo; + ma_zero_object(&deviceInfo); + ma_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), MA_DEFAULT_PLAYBACK_DEVICE_NAME, (size_t)-1); + cbResult = callback(pContext, ma_device_type_playback, &deviceInfo, pUserData); } // Capture. if (cbResult) { - mal_device_info deviceInfo; - mal_zero_object(&deviceInfo); - mal_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), MA_DEFAULT_CAPTURE_DEVICE_NAME, (size_t)-1); - cbResult = callback(pContext, mal_device_type_capture, &deviceInfo, pUserData); + ma_device_info deviceInfo; + ma_zero_object(&deviceInfo); + ma_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), MA_DEFAULT_CAPTURE_DEVICE_NAME, (size_t)-1); + cbResult = callback(pContext, ma_device_type_capture, &deviceInfo, pUserData); } return MA_SUCCESS; } -mal_result mal_context_get_device_info__opensl(mal_context* pContext, mal_device_type deviceType, const mal_device_id* pDeviceID, mal_share_mode shareMode, mal_device_info* pDeviceInfo) +ma_result ma_context_get_device_info__opensl(ma_context* pContext, ma_device_type deviceType, const ma_device_id* pDeviceID, ma_share_mode shareMode, ma_device_info* pDeviceInfo) { - mal_assert(pContext != NULL); + ma_assert(pContext != NULL); - mal_assert(g_malOpenSLInitCounter > 0); /* <-- If you trigger this it means you've either not initialized the context, or you've uninitialized it and then attempted to get device info. */ + ma_assert(g_malOpenSLInitCounter > 0); /* <-- If you trigger this it means you've either not initialized the context, or you've uninitialized it and then attempted to get device info. */ if (g_malOpenSLInitCounter == 0) { return MA_INVALID_OPERATION; } /* No exclusive mode with OpenSL|ES. */ - if (shareMode == mal_share_mode_exclusive) { + if (shareMode == ma_share_mode_exclusive) { return MA_SHARE_MODE_NOT_SUPPORTED; } @@ -20975,14 +20975,14 @@ mal_result mal_context_get_device_info__opensl(mal_context* pContext, mal_device goto return_default_device; } - if (deviceType == mal_device_type_playback) { + if (deviceType == ma_device_type_playback) { SLAudioOutputDescriptor desc; resultSL = (*deviceCaps)->QueryAudioOutputCapabilities(deviceCaps, pDeviceID->opensl, &desc); if (resultSL != SL_RESULT_SUCCESS) { return MA_NO_DEVICE; } - mal_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), (const char*)desc.pDeviceName, (size_t)-1); + ma_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), (const char*)desc.pDeviceName, (size_t)-1); } else { SLAudioInputDescriptor desc; resultSL = (*deviceCaps)->QueryAudioInputCapabilities(deviceCaps, pDeviceID->opensl, &desc); @@ -20990,7 +20990,7 @@ mal_result mal_context_get_device_info__opensl(mal_context* pContext, mal_device return MA_NO_DEVICE; } - mal_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), (const char*)desc.deviceName, (size_t)-1); + ma_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), (const char*)desc.deviceName, (size_t)-1); } goto return_detailed_info; @@ -21000,17 +21000,17 @@ mal_result mal_context_get_device_info__opensl(mal_context* pContext, mal_device return_default_device: if (pDeviceID != NULL) { - if ((deviceType == mal_device_type_playback && pDeviceID->opensl != SL_DEFAULTDEVICEID_AUDIOOUTPUT) || - (deviceType == mal_device_type_capture && pDeviceID->opensl != SL_DEFAULTDEVICEID_AUDIOINPUT)) { + if ((deviceType == ma_device_type_playback && pDeviceID->opensl != SL_DEFAULTDEVICEID_AUDIOOUTPUT) || + (deviceType == ma_device_type_capture && pDeviceID->opensl != SL_DEFAULTDEVICEID_AUDIOINPUT)) { return MA_NO_DEVICE; // Don't know the device. } } // Name / Description - if (deviceType == mal_device_type_playback) { - mal_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), MA_DEFAULT_PLAYBACK_DEVICE_NAME, (size_t)-1); + if (deviceType == ma_device_type_playback) { + ma_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), MA_DEFAULT_PLAYBACK_DEVICE_NAME, (size_t)-1); } else { - mal_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), MA_DEFAULT_CAPTURE_DEVICE_NAME, (size_t)-1); + ma_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), MA_DEFAULT_CAPTURE_DEVICE_NAME, (size_t)-1); } goto return_detailed_info; @@ -21026,10 +21026,10 @@ return_detailed_info: pDeviceInfo->minSampleRate = 8000; pDeviceInfo->maxSampleRate = 48000; pDeviceInfo->formatCount = 2; - pDeviceInfo->formats[0] = mal_format_u8; - pDeviceInfo->formats[1] = mal_format_s16; + pDeviceInfo->formats[0] = ma_format_u8; + pDeviceInfo->formats[1] = ma_format_s16; #if defined(MA_ANDROID) && __ANDROID_API__ >= 21 - pDeviceInfo->formats[pDeviceInfo->formatCount] = mal_format_f32; + pDeviceInfo->formats[pDeviceInfo->formatCount] = ma_format_f32; pDeviceInfo->formatCount += 1; #endif @@ -21038,11 +21038,11 @@ return_detailed_info: #ifdef MA_ANDROID -//void mal_buffer_queue_callback_capture__opensl_android(SLAndroidSimpleBufferQueueItf pBufferQueue, SLuint32 eventFlags, const void* pBuffer, SLuint32 bufferSize, SLuint32 dataUsed, void* pContext) -void mal_buffer_queue_callback_capture__opensl_android(SLAndroidSimpleBufferQueueItf pBufferQueue, void* pUserData) +//void ma_buffer_queue_callback_capture__opensl_android(SLAndroidSimpleBufferQueueItf pBufferQueue, SLuint32 eventFlags, const void* pBuffer, SLuint32 bufferSize, SLuint32 dataUsed, void* pContext) +void ma_buffer_queue_callback_capture__opensl_android(SLAndroidSimpleBufferQueueItf pBufferQueue, void* pUserData) { - mal_device* pDevice = (mal_device*)pUserData; - mal_assert(pDevice != NULL); + ma_device* pDevice = (ma_device*)pUserData; + ma_assert(pDevice != NULL); (void)pBufferQueue; @@ -21055,13 +21055,13 @@ void mal_buffer_queue_callback_capture__opensl_android(SLAndroidSimpleBufferQueu return; } - size_t periodSizeInBytes = (pDevice->capture.internalBufferSizeInFrames / pDevice->capture.internalPeriods) * mal_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels); - mal_uint8* pBuffer = pDevice->opensl.pBufferCapture + (pDevice->opensl.currentBufferIndexCapture * periodSizeInBytes); + size_t periodSizeInBytes = (pDevice->capture.internalBufferSizeInFrames / pDevice->capture.internalPeriods) * ma_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels); + ma_uint8* pBuffer = pDevice->opensl.pBufferCapture + (pDevice->opensl.currentBufferIndexCapture * periodSizeInBytes); - if (pDevice->type == mal_device_type_duplex) { - mal_device__handle_duplex_callback_capture(pDevice, (pDevice->capture.internalBufferSizeInFrames / pDevice->capture.internalPeriods), pBuffer, &pDevice->opensl.duplexRB); + if (pDevice->type == ma_device_type_duplex) { + ma_device__handle_duplex_callback_capture(pDevice, (pDevice->capture.internalBufferSizeInFrames / pDevice->capture.internalPeriods), pBuffer, &pDevice->opensl.duplexRB); } else { - mal_device__send_frames_to_client(pDevice, (pDevice->capture.internalBufferSizeInFrames / pDevice->capture.internalPeriods), pBuffer); + ma_device__send_frames_to_client(pDevice, (pDevice->capture.internalBufferSizeInFrames / pDevice->capture.internalPeriods), pBuffer); } SLresult resultSL = MA_OPENSL_BUFFERQUEUE(pDevice->opensl.pBufferQueueCapture)->Enqueue((SLAndroidSimpleBufferQueueItf)pDevice->opensl.pBufferQueueCapture, pBuffer, periodSizeInBytes); @@ -21072,10 +21072,10 @@ void mal_buffer_queue_callback_capture__opensl_android(SLAndroidSimpleBufferQueu pDevice->opensl.currentBufferIndexCapture = (pDevice->opensl.currentBufferIndexCapture + 1) % pDevice->capture.internalPeriods; } -void mal_buffer_queue_callback_playback__opensl_android(SLAndroidSimpleBufferQueueItf pBufferQueue, void* pUserData) +void ma_buffer_queue_callback_playback__opensl_android(SLAndroidSimpleBufferQueueItf pBufferQueue, void* pUserData) { - mal_device* pDevice = (mal_device*)pUserData; - mal_assert(pDevice != NULL); + ma_device* pDevice = (ma_device*)pUserData; + ma_assert(pDevice != NULL); (void)pBufferQueue; @@ -21084,13 +21084,13 @@ void mal_buffer_queue_callback_playback__opensl_android(SLAndroidSimpleBufferQue return; } - size_t periodSizeInBytes = (pDevice->playback.internalBufferSizeInFrames / pDevice->playback.internalPeriods) * mal_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels); - mal_uint8* pBuffer = pDevice->opensl.pBufferPlayback + (pDevice->opensl.currentBufferIndexPlayback * periodSizeInBytes); + size_t periodSizeInBytes = (pDevice->playback.internalBufferSizeInFrames / pDevice->playback.internalPeriods) * ma_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels); + ma_uint8* pBuffer = pDevice->opensl.pBufferPlayback + (pDevice->opensl.currentBufferIndexPlayback * periodSizeInBytes); - if (pDevice->type == mal_device_type_duplex) { - mal_device__handle_duplex_callback_playback(pDevice, (pDevice->playback.internalBufferSizeInFrames / pDevice->playback.internalPeriods), pBuffer, &pDevice->opensl.duplexRB); + if (pDevice->type == ma_device_type_duplex) { + ma_device__handle_duplex_callback_playback(pDevice, (pDevice->playback.internalBufferSizeInFrames / pDevice->playback.internalPeriods), pBuffer, &pDevice->opensl.duplexRB); } else { - mal_device__read_frames_from_client(pDevice, (pDevice->playback.internalBufferSizeInFrames / pDevice->playback.internalPeriods), pBuffer); + ma_device__read_frames_from_client(pDevice, (pDevice->playback.internalBufferSizeInFrames / pDevice->playback.internalPeriods), pBuffer); } SLresult resultSL = MA_OPENSL_BUFFERQUEUE(pDevice->opensl.pBufferQueuePlayback)->Enqueue((SLAndroidSimpleBufferQueueItf)pDevice->opensl.pBufferQueuePlayback, pBuffer, periodSizeInBytes); @@ -21102,24 +21102,24 @@ void mal_buffer_queue_callback_playback__opensl_android(SLAndroidSimpleBufferQue } #endif -void mal_device_uninit__opensl(mal_device* pDevice) +void ma_device_uninit__opensl(ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); - mal_assert(g_malOpenSLInitCounter > 0); /* <-- If you trigger this it means you've either not initialized the context, or you've uninitialized it before uninitializing the device. */ + ma_assert(g_malOpenSLInitCounter > 0); /* <-- If you trigger this it means you've either not initialized the context, or you've uninitialized it before uninitializing the device. */ if (g_malOpenSLInitCounter == 0) { return; } - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { if (pDevice->opensl.pAudioRecorderObj) { MA_OPENSL_OBJ(pDevice->opensl.pAudioRecorderObj)->Destroy((SLObjectItf)pDevice->opensl.pAudioRecorderObj); } - mal_free(pDevice->opensl.pBufferCapture); + ma_free(pDevice->opensl.pBufferCapture); } - if (pDevice->type == mal_device_type_playback || pDevice->type == mal_device_type_duplex) { + if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) { if (pDevice->opensl.pAudioPlayerObj) { MA_OPENSL_OBJ(pDevice->opensl.pAudioPlayerObj)->Destroy((SLObjectItf)pDevice->opensl.pAudioPlayerObj); } @@ -21127,24 +21127,24 @@ void mal_device_uninit__opensl(mal_device* pDevice) MA_OPENSL_OBJ(pDevice->opensl.pOutputMixObj)->Destroy((SLObjectItf)pDevice->opensl.pOutputMixObj); } - mal_free(pDevice->opensl.pBufferPlayback); + ma_free(pDevice->opensl.pBufferPlayback); } - if (pDevice->type == mal_device_type_duplex) { - mal_pcm_rb_uninit(&pDevice->opensl.duplexRB); + if (pDevice->type == ma_device_type_duplex) { + ma_pcm_rb_uninit(&pDevice->opensl.duplexRB); } } #if defined(MA_ANDROID) && __ANDROID_API__ >= 21 -typedef SLAndroidDataFormat_PCM_EX mal_SLDataFormat_PCM; +typedef SLAndroidDataFormat_PCM_EX ma_SLDataFormat_PCM; #else -typedef SLDataFormat_PCM mal_SLDataFormat_PCM; +typedef SLDataFormat_PCM ma_SLDataFormat_PCM; #endif -mal_result mal_SLDataFormat_PCM_init__opensl(mal_format format, mal_uint32 channels, mal_uint32 sampleRate, const mal_channel* channelMap, mal_SLDataFormat_PCM* pDataFormat) +ma_result ma_SLDataFormat_PCM_init__opensl(ma_format format, ma_uint32 channels, ma_uint32 sampleRate, const ma_channel* channelMap, ma_SLDataFormat_PCM* pDataFormat) { #if defined(MA_ANDROID) && __ANDROID_API__ >= 21 - if (format == mal_format_f32) { + if (format == ma_format_f32) { pDataFormat->formatType = SL_ANDROID_DATAFORMAT_PCM_EX; pDataFormat->representation = SL_ANDROID_PCM_REPRESENTATION_FLOAT; } else { @@ -21155,10 +21155,10 @@ mal_result mal_SLDataFormat_PCM_init__opensl(mal_format format, mal_uint32 chann #endif pDataFormat->numChannels = channels; - ((SLDataFormat_PCM*)pDataFormat)->samplesPerSec = mal_round_to_standard_sample_rate__opensl(sampleRate * 1000); /* In millihertz. Annoyingly, the sample rate variable is named differently between SLAndroidDataFormat_PCM_EX and SLDataFormat_PCM */ - pDataFormat->bitsPerSample = mal_get_bytes_per_sample(format)*8; - pDataFormat->channelMask = mal_channel_map_to_channel_mask__opensl(channelMap, channels); - pDataFormat->endianness = (mal_is_little_endian()) ? SL_BYTEORDER_LITTLEENDIAN : SL_BYTEORDER_BIGENDIAN; + ((SLDataFormat_PCM*)pDataFormat)->samplesPerSec = ma_round_to_standard_sample_rate__opensl(sampleRate * 1000); /* In millihertz. Annoyingly, the sample rate variable is named differently between SLAndroidDataFormat_PCM_EX and SLDataFormat_PCM */ + pDataFormat->bitsPerSample = ma_get_bytes_per_sample(format)*8; + pDataFormat->channelMask = ma_channel_map_to_channel_mask__opensl(channelMap, channels); + pDataFormat->endianness = (ma_is_little_endian()) ? SL_BYTEORDER_LITTLEENDIAN : SL_BYTEORDER_BIGENDIAN; /* Android has a few restrictions on the format as documented here: https://developer.android.com/ndk/guides/audio/opensl-for-android.html @@ -21173,7 +21173,7 @@ mal_result mal_SLDataFormat_PCM_init__opensl(mal_format format, mal_uint32 chann #if __ANDROID_API__ >= 21 if (pDataFormat->formatType == SL_ANDROID_DATAFORMAT_PCM_EX) { /* It's floating point. */ - mal_assert(pDataFormat->representation == SL_ANDROID_PCM_REPRESENTATION_FLOAT); + ma_assert(pDataFormat->representation == SL_ANDROID_PCM_REPRESENTATION_FLOAT); if (pDataFormat->bitsPerSample > 32) { pDataFormat->bitsPerSample = 32; } @@ -21197,43 +21197,43 @@ mal_result mal_SLDataFormat_PCM_init__opensl(mal_format format, mal_uint32 chann return MA_SUCCESS; } -mal_result mal_deconstruct_SLDataFormat_PCM__opensl(mal_SLDataFormat_PCM* pDataFormat, mal_format* pFormat, mal_uint32* pChannels, mal_uint32* pSampleRate, mal_channel* pChannelMap) +ma_result ma_deconstruct_SLDataFormat_PCM__opensl(ma_SLDataFormat_PCM* pDataFormat, ma_format* pFormat, ma_uint32* pChannels, ma_uint32* pSampleRate, ma_channel* pChannelMap) { - mal_bool32 isFloatingPoint = MA_FALSE; + ma_bool32 isFloatingPoint = MA_FALSE; #if defined(MA_ANDROID) && __ANDROID_API__ >= 21 if (pDataFormat->formatType == SL_ANDROID_DATAFORMAT_PCM_EX) { - mal_assert(pDataFormat->representation == SL_ANDROID_PCM_REPRESENTATION_FLOAT); + ma_assert(pDataFormat->representation == SL_ANDROID_PCM_REPRESENTATION_FLOAT); isFloatingPoint = MA_TRUE; } #endif if (isFloatingPoint) { if (pDataFormat->bitsPerSample == 32) { - *pFormat = mal_format_f32; + *pFormat = ma_format_f32; } } else { if (pDataFormat->bitsPerSample == 8) { - *pFormat = mal_format_u8; + *pFormat = ma_format_u8; } else if (pDataFormat->bitsPerSample == 16) { - *pFormat = mal_format_s16; + *pFormat = ma_format_s16; } else if (pDataFormat->bitsPerSample == 24) { - *pFormat = mal_format_s24; + *pFormat = ma_format_s24; } else if (pDataFormat->bitsPerSample == 32) { - *pFormat = mal_format_s32; + *pFormat = ma_format_s32; } } *pChannels = pDataFormat->numChannels; *pSampleRate = ((SLDataFormat_PCM*)pDataFormat)->samplesPerSec / 1000; - mal_channel_mask_to_channel_map__opensl(pDataFormat->channelMask, pDataFormat->numChannels, pChannelMap); + ma_channel_mask_to_channel_map__opensl(pDataFormat->channelMask, pDataFormat->numChannels, pChannelMap); return MA_SUCCESS; } -mal_result mal_device_init__opensl(mal_context* pContext, const mal_device_config* pConfig, mal_device* pDevice) +ma_result ma_device_init__opensl(ma_context* pContext, const ma_device_config* pConfig, ma_device* pDevice) { (void)pContext; - mal_assert(g_malOpenSLInitCounter > 0); /* <-- If you trigger this it means you've either not initialized the context, or you've uninitialized it and then attempted to initialize a new device. */ + ma_assert(g_malOpenSLInitCounter > 0); /* <-- If you trigger this it means you've either not initialized the context, or you've uninitialized it and then attempted to initialize a new device. */ if (g_malOpenSLInitCounter == 0) { return MA_INVALID_OPERATION; } @@ -21248,23 +21248,23 @@ mal_result mal_device_init__opensl(mal_context* pContext, const mal_device_confi #endif /* No exclusive mode with OpenSL|ES. */ - if (((pConfig->deviceType == mal_device_type_playback || pConfig->deviceType == mal_device_type_duplex) && pConfig->playback.shareMode == mal_share_mode_exclusive) || - ((pConfig->deviceType == mal_device_type_capture || pConfig->deviceType == mal_device_type_duplex) && pConfig->capture.shareMode == mal_share_mode_exclusive)) { + if (((pConfig->deviceType == ma_device_type_playback || pConfig->deviceType == ma_device_type_duplex) && pConfig->playback.shareMode == ma_share_mode_exclusive) || + ((pConfig->deviceType == ma_device_type_capture || pConfig->deviceType == ma_device_type_duplex) && pConfig->capture.shareMode == ma_share_mode_exclusive)) { return MA_SHARE_MODE_NOT_SUPPORTED; } /* Now we can start initializing the device properly. */ - mal_assert(pDevice != NULL); - mal_zero_object(&pDevice->opensl); + ma_assert(pDevice != NULL); + ma_zero_object(&pDevice->opensl); SLDataLocator_AndroidSimpleBufferQueue queue; queue.locatorType = SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE; queue.numBuffers = pConfig->periods; - if (pConfig->deviceType == mal_device_type_capture || pConfig->deviceType == mal_device_type_duplex) { - mal_SLDataFormat_PCM pcm; - mal_SLDataFormat_PCM_init__opensl(pConfig->capture.format, pConfig->capture.channels, pConfig->sampleRate, pConfig->capture.channelMap, &pcm); + if (pConfig->deviceType == ma_device_type_capture || pConfig->deviceType == ma_device_type_duplex) { + ma_SLDataFormat_PCM pcm; + ma_SLDataFormat_PCM_init__opensl(pConfig->capture.format, pConfig->capture.channels, pConfig->sampleRate, pConfig->capture.channelMap, &pcm); SLDataLocator_IODevice locatorDevice; locatorDevice.locatorType = SL_DATALOCATOR_IODEVICE; @@ -21295,69 +21295,69 @@ mal_result mal_device_init__opensl(mal_context* pContext, const mal_device_confi } if (resultSL != SL_RESULT_SUCCESS) { - mal_device_uninit__opensl(pDevice); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to create audio recorder.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + ma_device_uninit__opensl(pDevice); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to create audio recorder.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } if (MA_OPENSL_OBJ(pDevice->opensl.pAudioRecorderObj)->Realize((SLObjectItf)pDevice->opensl.pAudioRecorderObj, SL_BOOLEAN_FALSE) != SL_RESULT_SUCCESS) { - mal_device_uninit__opensl(pDevice); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to realize audio recorder.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + ma_device_uninit__opensl(pDevice); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to realize audio recorder.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } if (MA_OPENSL_OBJ(pDevice->opensl.pAudioRecorderObj)->GetInterface((SLObjectItf)pDevice->opensl.pAudioRecorderObj, SL_IID_RECORD, &pDevice->opensl.pAudioRecorder) != SL_RESULT_SUCCESS) { - mal_device_uninit__opensl(pDevice); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to retrieve SL_IID_RECORD interface.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + ma_device_uninit__opensl(pDevice); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to retrieve SL_IID_RECORD interface.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } if (MA_OPENSL_OBJ(pDevice->opensl.pAudioRecorderObj)->GetInterface((SLObjectItf)pDevice->opensl.pAudioRecorderObj, SL_IID_ANDROIDSIMPLEBUFFERQUEUE, &pDevice->opensl.pBufferQueueCapture) != SL_RESULT_SUCCESS) { - mal_device_uninit__opensl(pDevice); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to retrieve SL_IID_ANDROIDSIMPLEBUFFERQUEUE interface.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + ma_device_uninit__opensl(pDevice); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to retrieve SL_IID_ANDROIDSIMPLEBUFFERQUEUE interface.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } - if (MA_OPENSL_BUFFERQUEUE(pDevice->opensl.pBufferQueueCapture)->RegisterCallback((SLAndroidSimpleBufferQueueItf)pDevice->opensl.pBufferQueueCapture, mal_buffer_queue_callback_capture__opensl_android, pDevice) != SL_RESULT_SUCCESS) { - mal_device_uninit__opensl(pDevice); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to register buffer queue callback.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + if (MA_OPENSL_BUFFERQUEUE(pDevice->opensl.pBufferQueueCapture)->RegisterCallback((SLAndroidSimpleBufferQueueItf)pDevice->opensl.pBufferQueueCapture, ma_buffer_queue_callback_capture__opensl_android, pDevice) != SL_RESULT_SUCCESS) { + ma_device_uninit__opensl(pDevice); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to register buffer queue callback.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } /* The internal format is determined by the "pcm" object. */ - mal_deconstruct_SLDataFormat_PCM__opensl(&pcm, &pDevice->capture.internalFormat, &pDevice->capture.internalChannels, &pDevice->capture.internalSampleRate, pDevice->capture.internalChannelMap); + ma_deconstruct_SLDataFormat_PCM__opensl(&pcm, &pDevice->capture.internalFormat, &pDevice->capture.internalChannels, &pDevice->capture.internalSampleRate, pDevice->capture.internalChannelMap); /* Buffer. */ - mal_uint32 bufferSizeInFrames = pConfig->bufferSizeInFrames; + ma_uint32 bufferSizeInFrames = pConfig->bufferSizeInFrames; if (bufferSizeInFrames == 0) { - bufferSizeInFrames = mal_calculate_buffer_size_in_frames_from_milliseconds(pConfig->bufferSizeInMilliseconds, pDevice->capture.internalSampleRate); + bufferSizeInFrames = ma_calculate_buffer_size_in_frames_from_milliseconds(pConfig->bufferSizeInMilliseconds, pDevice->capture.internalSampleRate); } pDevice->capture.internalPeriods = pConfig->periods; pDevice->capture.internalBufferSizeInFrames = (bufferSizeInFrames / pDevice->capture.internalPeriods) * pDevice->capture.internalPeriods; pDevice->opensl.currentBufferIndexCapture = 0; - size_t bufferSizeInBytes = pDevice->capture.internalBufferSizeInFrames * mal_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels); - pDevice->opensl.pBufferCapture = (mal_uint8*)mal_malloc(bufferSizeInBytes); + size_t bufferSizeInBytes = pDevice->capture.internalBufferSizeInFrames * ma_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels); + pDevice->opensl.pBufferCapture = (ma_uint8*)ma_malloc(bufferSizeInBytes); if (pDevice->opensl.pBufferCapture == NULL) { - mal_device_uninit__opensl(pDevice); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to allocate memory for data buffer.", MA_OUT_OF_MEMORY); + ma_device_uninit__opensl(pDevice); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to allocate memory for data buffer.", MA_OUT_OF_MEMORY); } MA_ZERO_MEMORY(pDevice->opensl.pBufferCapture, bufferSizeInBytes); } - if (pConfig->deviceType == mal_device_type_playback || pConfig->deviceType == mal_device_type_duplex) { - mal_SLDataFormat_PCM pcm; - mal_SLDataFormat_PCM_init__opensl(pConfig->playback.format, pConfig->playback.channels, pConfig->sampleRate, pConfig->playback.channelMap, &pcm); + if (pConfig->deviceType == ma_device_type_playback || pConfig->deviceType == ma_device_type_duplex) { + ma_SLDataFormat_PCM pcm; + ma_SLDataFormat_PCM_init__opensl(pConfig->playback.format, pConfig->playback.channels, pConfig->sampleRate, pConfig->playback.channelMap, &pcm); SLresult resultSL = (*g_malEngineSL)->CreateOutputMix(g_malEngineSL, (SLObjectItf*)&pDevice->opensl.pOutputMixObj, 0, NULL, NULL); if (resultSL != SL_RESULT_SUCCESS) { - mal_device_uninit__opensl(pDevice); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to create output mix.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + ma_device_uninit__opensl(pDevice); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to create output mix.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } if (MA_OPENSL_OBJ(pDevice->opensl.pOutputMixObj)->Realize((SLObjectItf)pDevice->opensl.pOutputMixObj, SL_BOOLEAN_FALSE)) { - mal_device_uninit__opensl(pDevice); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to realize output mix object.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + ma_device_uninit__opensl(pDevice); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to realize output mix object.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } if (MA_OPENSL_OBJ(pDevice->opensl.pOutputMixObj)->GetInterface((SLObjectItf)pDevice->opensl.pOutputMixObj, SL_IID_OUTPUTMIX, &pDevice->opensl.pOutputMix) != SL_RESULT_SUCCESS) { - mal_device_uninit__opensl(pDevice); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to retrieve SL_IID_OUTPUTMIX interface.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + ma_device_uninit__opensl(pDevice); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to retrieve SL_IID_OUTPUTMIX interface.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } /* Set the output device. */ @@ -21393,107 +21393,107 @@ mal_result mal_device_init__opensl(mal_context* pContext, const mal_device_confi } if (resultSL != SL_RESULT_SUCCESS) { - mal_device_uninit__opensl(pDevice); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to create audio player.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + ma_device_uninit__opensl(pDevice); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to create audio player.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } if (MA_OPENSL_OBJ(pDevice->opensl.pAudioPlayerObj)->Realize((SLObjectItf)pDevice->opensl.pAudioPlayerObj, SL_BOOLEAN_FALSE) != SL_RESULT_SUCCESS) { - mal_device_uninit__opensl(pDevice); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to realize audio player.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + ma_device_uninit__opensl(pDevice); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to realize audio player.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } if (MA_OPENSL_OBJ(pDevice->opensl.pAudioPlayerObj)->GetInterface((SLObjectItf)pDevice->opensl.pAudioPlayerObj, SL_IID_PLAY, &pDevice->opensl.pAudioPlayer) != SL_RESULT_SUCCESS) { - mal_device_uninit__opensl(pDevice); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to retrieve SL_IID_PLAY interface.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + ma_device_uninit__opensl(pDevice); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to retrieve SL_IID_PLAY interface.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } if (MA_OPENSL_OBJ(pDevice->opensl.pAudioPlayerObj)->GetInterface((SLObjectItf)pDevice->opensl.pAudioPlayerObj, SL_IID_ANDROIDSIMPLEBUFFERQUEUE, &pDevice->opensl.pBufferQueuePlayback) != SL_RESULT_SUCCESS) { - mal_device_uninit__opensl(pDevice); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to retrieve SL_IID_ANDROIDSIMPLEBUFFERQUEUE interface.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + ma_device_uninit__opensl(pDevice); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to retrieve SL_IID_ANDROIDSIMPLEBUFFERQUEUE interface.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } - if (MA_OPENSL_BUFFERQUEUE(pDevice->opensl.pBufferQueuePlayback)->RegisterCallback((SLAndroidSimpleBufferQueueItf)pDevice->opensl.pBufferQueuePlayback, mal_buffer_queue_callback_playback__opensl_android, pDevice) != SL_RESULT_SUCCESS) { - mal_device_uninit__opensl(pDevice); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to register buffer queue callback.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); + if (MA_OPENSL_BUFFERQUEUE(pDevice->opensl.pBufferQueuePlayback)->RegisterCallback((SLAndroidSimpleBufferQueueItf)pDevice->opensl.pBufferQueuePlayback, ma_buffer_queue_callback_playback__opensl_android, pDevice) != SL_RESULT_SUCCESS) { + ma_device_uninit__opensl(pDevice); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to register buffer queue callback.", MA_FAILED_TO_OPEN_BACKEND_DEVICE); } /* The internal format is determined by the "pcm" object. */ - mal_deconstruct_SLDataFormat_PCM__opensl(&pcm, &pDevice->playback.internalFormat, &pDevice->playback.internalChannels, &pDevice->playback.internalSampleRate, pDevice->playback.internalChannelMap); + ma_deconstruct_SLDataFormat_PCM__opensl(&pcm, &pDevice->playback.internalFormat, &pDevice->playback.internalChannels, &pDevice->playback.internalSampleRate, pDevice->playback.internalChannelMap); /* Buffer. */ - mal_uint32 bufferSizeInFrames = pConfig->bufferSizeInFrames; + ma_uint32 bufferSizeInFrames = pConfig->bufferSizeInFrames; if (bufferSizeInFrames == 0) { - bufferSizeInFrames = mal_calculate_buffer_size_in_frames_from_milliseconds(pConfig->bufferSizeInMilliseconds, pDevice->playback.internalSampleRate); + bufferSizeInFrames = ma_calculate_buffer_size_in_frames_from_milliseconds(pConfig->bufferSizeInMilliseconds, pDevice->playback.internalSampleRate); } pDevice->playback.internalPeriods = pConfig->periods; pDevice->playback.internalBufferSizeInFrames = (bufferSizeInFrames / pDevice->playback.internalPeriods) * pDevice->playback.internalPeriods; pDevice->opensl.currentBufferIndexPlayback = 0; - size_t bufferSizeInBytes = pDevice->playback.internalBufferSizeInFrames * mal_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels); - pDevice->opensl.pBufferPlayback = (mal_uint8*)mal_malloc(bufferSizeInBytes); + size_t bufferSizeInBytes = pDevice->playback.internalBufferSizeInFrames * ma_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels); + pDevice->opensl.pBufferPlayback = (ma_uint8*)ma_malloc(bufferSizeInBytes); if (pDevice->opensl.pBufferPlayback == NULL) { - mal_device_uninit__opensl(pDevice); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to allocate memory for data buffer.", MA_OUT_OF_MEMORY); + ma_device_uninit__opensl(pDevice); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to allocate memory for data buffer.", MA_OUT_OF_MEMORY); } MA_ZERO_MEMORY(pDevice->opensl.pBufferPlayback, bufferSizeInBytes); } - if (pConfig->deviceType == mal_device_type_duplex) { - mal_uint32 rbSizeInFrames = (mal_uint32)mal_calculate_frame_count_after_src(pDevice->sampleRate, pDevice->capture.internalSampleRate, pDevice->capture.internalBufferSizeInFrames); - mal_result result = mal_pcm_rb_init(pDevice->capture.format, pDevice->capture.channels, rbSizeInFrames, NULL, &pDevice->opensl.duplexRB); + if (pConfig->deviceType == ma_device_type_duplex) { + ma_uint32 rbSizeInFrames = (ma_uint32)ma_calculate_frame_count_after_src(pDevice->sampleRate, pDevice->capture.internalSampleRate, pDevice->capture.internalBufferSizeInFrames); + ma_result result = ma_pcm_rb_init(pDevice->capture.format, pDevice->capture.channels, rbSizeInFrames, NULL, &pDevice->opensl.duplexRB); if (result != MA_SUCCESS) { - mal_device_uninit__opensl(pDevice); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to initialize ring buffer.", result); + ma_device_uninit__opensl(pDevice); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to initialize ring buffer.", result); } } return MA_SUCCESS; } -mal_result mal_device_start__opensl(mal_device* pDevice) +ma_result ma_device_start__opensl(ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); - mal_assert(g_malOpenSLInitCounter > 0); /* <-- If you trigger this it means you've either not initialized the context, or you've uninitialized it and then attempted to start the device. */ + ma_assert(g_malOpenSLInitCounter > 0); /* <-- If you trigger this it means you've either not initialized the context, or you've uninitialized it and then attempted to start the device. */ if (g_malOpenSLInitCounter == 0) { return MA_INVALID_OPERATION; } - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { SLresult resultSL = MA_OPENSL_RECORD(pDevice->opensl.pAudioRecorder)->SetRecordState((SLRecordItf)pDevice->opensl.pAudioRecorder, SL_RECORDSTATE_RECORDING); if (resultSL != SL_RESULT_SUCCESS) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to start internal capture device.", MA_FAILED_TO_START_BACKEND_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to start internal capture device.", MA_FAILED_TO_START_BACKEND_DEVICE); } - size_t periodSizeInBytes = (pDevice->capture.internalBufferSizeInFrames / pDevice->capture.internalPeriods) * mal_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels); - for (mal_uint32 iPeriod = 0; iPeriod < pDevice->capture.internalPeriods; ++iPeriod) { + size_t periodSizeInBytes = (pDevice->capture.internalBufferSizeInFrames / pDevice->capture.internalPeriods) * ma_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels); + for (ma_uint32 iPeriod = 0; iPeriod < pDevice->capture.internalPeriods; ++iPeriod) { resultSL = MA_OPENSL_BUFFERQUEUE(pDevice->opensl.pBufferQueuePlayback)->Enqueue((SLAndroidSimpleBufferQueueItf)pDevice->opensl.pBufferQueueCapture, pDevice->opensl.pBufferCapture + (periodSizeInBytes * iPeriod), periodSizeInBytes); if (resultSL != SL_RESULT_SUCCESS) { MA_OPENSL_RECORD(pDevice->opensl.pAudioRecorder)->SetRecordState((SLRecordItf)pDevice->opensl.pAudioRecorder, SL_RECORDSTATE_STOPPED); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to enqueue buffer for capture device.", MA_FAILED_TO_START_BACKEND_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to enqueue buffer for capture device.", MA_FAILED_TO_START_BACKEND_DEVICE); } } } - if (pDevice->type == mal_device_type_playback || pDevice->type == mal_device_type_duplex) { + if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) { SLresult resultSL = MA_OPENSL_PLAY(pDevice->opensl.pAudioPlayer)->SetPlayState((SLPlayItf)pDevice->opensl.pAudioPlayer, SL_PLAYSTATE_PLAYING); if (resultSL != SL_RESULT_SUCCESS) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to start internal playback device.", MA_FAILED_TO_START_BACKEND_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to start internal playback device.", MA_FAILED_TO_START_BACKEND_DEVICE); } /* In playback mode (no duplex) we need to load some initial buffers. In duplex mode we need to enqueu silent buffers. */ - if (pDevice->type == mal_device_type_duplex) { - MA_ZERO_MEMORY(pDevice->opensl.pBufferPlayback, pDevice->playback.internalBufferSizeInFrames * mal_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels)); + if (pDevice->type == ma_device_type_duplex) { + MA_ZERO_MEMORY(pDevice->opensl.pBufferPlayback, pDevice->playback.internalBufferSizeInFrames * ma_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels)); } else { - mal_device__read_frames_from_client(pDevice, pDevice->playback.internalBufferSizeInFrames, pDevice->opensl.pBufferPlayback); + ma_device__read_frames_from_client(pDevice, pDevice->playback.internalBufferSizeInFrames, pDevice->opensl.pBufferPlayback); } - size_t periodSizeInBytes = (pDevice->playback.internalBufferSizeInFrames / pDevice->playback.internalPeriods) * mal_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels); - for (mal_uint32 iPeriod = 0; iPeriod < pDevice->playback.internalPeriods; ++iPeriod) { + size_t periodSizeInBytes = (pDevice->playback.internalBufferSizeInFrames / pDevice->playback.internalPeriods) * ma_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels); + for (ma_uint32 iPeriod = 0; iPeriod < pDevice->playback.internalPeriods; ++iPeriod) { resultSL = MA_OPENSL_BUFFERQUEUE(pDevice->opensl.pBufferQueuePlayback)->Enqueue((SLAndroidSimpleBufferQueueItf)pDevice->opensl.pBufferQueuePlayback, pDevice->opensl.pBufferPlayback + (periodSizeInBytes * iPeriod), periodSizeInBytes); if (resultSL != SL_RESULT_SUCCESS) { MA_OPENSL_PLAY(pDevice->opensl.pAudioPlayer)->SetPlayState((SLPlayItf)pDevice->opensl.pAudioPlayer, SL_PLAYSTATE_STOPPED); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to enqueue buffer for playback device.", MA_FAILED_TO_START_BACKEND_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to enqueue buffer for playback device.", MA_FAILED_TO_START_BACKEND_DEVICE); } } } @@ -21501,37 +21501,37 @@ mal_result mal_device_start__opensl(mal_device* pDevice) return MA_SUCCESS; } -mal_result mal_device_stop__opensl(mal_device* pDevice) +ma_result ma_device_stop__opensl(ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); - mal_assert(g_malOpenSLInitCounter > 0); /* <-- If you trigger this it means you've either not initialized the context, or you've uninitialized it before stopping/uninitializing the device. */ + ma_assert(g_malOpenSLInitCounter > 0); /* <-- If you trigger this it means you've either not initialized the context, or you've uninitialized it before stopping/uninitializing the device. */ if (g_malOpenSLInitCounter == 0) { return MA_INVALID_OPERATION; } /* TODO: Wait until all buffers have been processed. Hint: Maybe SLAndroidSimpleBufferQueue::GetState() could be used in a loop? */ - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { SLresult resultSL = MA_OPENSL_RECORD(pDevice->opensl.pAudioRecorder)->SetRecordState((SLRecordItf)pDevice->opensl.pAudioRecorder, SL_RECORDSTATE_STOPPED); if (resultSL != SL_RESULT_SUCCESS) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to stop internal capture device.", MA_FAILED_TO_STOP_BACKEND_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to stop internal capture device.", MA_FAILED_TO_STOP_BACKEND_DEVICE); } MA_OPENSL_BUFFERQUEUE(pDevice->opensl.pBufferQueueCapture)->Clear((SLAndroidSimpleBufferQueueItf)pDevice->opensl.pBufferQueueCapture); } - if (pDevice->type == mal_device_type_playback || pDevice->type == mal_device_type_duplex) { + if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) { SLresult resultSL = MA_OPENSL_PLAY(pDevice->opensl.pAudioPlayer)->SetPlayState((SLPlayItf)pDevice->opensl.pAudioPlayer, SL_PLAYSTATE_STOPPED); if (resultSL != SL_RESULT_SUCCESS) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to stop internal playback device.", MA_FAILED_TO_STOP_BACKEND_DEVICE); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[OpenSL] Failed to stop internal playback device.", MA_FAILED_TO_STOP_BACKEND_DEVICE); } MA_OPENSL_BUFFERQUEUE(pDevice->opensl.pBufferQueuePlayback)->Clear((SLAndroidSimpleBufferQueueItf)pDevice->opensl.pBufferQueuePlayback); } /* Make sure the client is aware that the device has stopped. There may be an OpenSL|ES callback for this, but I haven't found it. */ - mal_stop_proc onStop = pDevice->onStop; + ma_stop_proc onStop = pDevice->onStop; if (onStop) { onStop(pDevice); } @@ -21540,15 +21540,15 @@ mal_result mal_device_stop__opensl(mal_device* pDevice) } -mal_result mal_context_uninit__opensl(mal_context* pContext) +ma_result ma_context_uninit__opensl(ma_context* pContext) { - mal_assert(pContext != NULL); - mal_assert(pContext->backend == mal_backend_opensl); + ma_assert(pContext != NULL); + ma_assert(pContext->backend == ma_backend_opensl); (void)pContext; /* Uninit global data. */ if (g_malOpenSLInitCounter > 0) { - if (mal_atomic_decrement_32(&g_malOpenSLInitCounter) == 0) { + if (ma_atomic_decrement_32(&g_malOpenSLInitCounter) == 0) { (*g_malEngineObjectSL)->Destroy(g_malEngineObjectSL); } } @@ -21556,16 +21556,16 @@ mal_result mal_context_uninit__opensl(mal_context* pContext) return MA_SUCCESS; } -mal_result mal_context_init__opensl(mal_context* pContext) +ma_result ma_context_init__opensl(ma_context* pContext) { - mal_assert(pContext != NULL); + ma_assert(pContext != NULL); (void)pContext; /* Initialize global data first if applicable. */ - if (mal_atomic_increment_32(&g_malOpenSLInitCounter) == 1) { + if (ma_atomic_increment_32(&g_malOpenSLInitCounter) == 1) { SLresult resultSL = slCreateEngine(&g_malEngineObjectSL, 0, NULL, 0, NULL, NULL); if (resultSL != SL_RESULT_SUCCESS) { - mal_atomic_decrement_32(&g_malOpenSLInitCounter); + ma_atomic_decrement_32(&g_malOpenSLInitCounter); return MA_NO_BACKEND; } @@ -21574,21 +21574,21 @@ mal_result mal_context_init__opensl(mal_context* pContext) resultSL = (*g_malEngineObjectSL)->GetInterface(g_malEngineObjectSL, SL_IID_ENGINE, &g_malEngineSL); if (resultSL != SL_RESULT_SUCCESS) { (*g_malEngineObjectSL)->Destroy(g_malEngineObjectSL); - mal_atomic_decrement_32(&g_malOpenSLInitCounter); + ma_atomic_decrement_32(&g_malOpenSLInitCounter); return MA_NO_BACKEND; } } pContext->isBackendAsynchronous = MA_TRUE; - pContext->onUninit = mal_context_uninit__opensl; - pContext->onDeviceIDEqual = mal_context_is_device_id_equal__opensl; - pContext->onEnumDevices = mal_context_enumerate_devices__opensl; - pContext->onGetDeviceInfo = mal_context_get_device_info__opensl; - pContext->onDeviceInit = mal_device_init__opensl; - pContext->onDeviceUninit = mal_device_uninit__opensl; - pContext->onDeviceStart = mal_device_start__opensl; - pContext->onDeviceStop = mal_device_stop__opensl; + pContext->onUninit = ma_context_uninit__opensl; + pContext->onDeviceIDEqual = ma_context_is_device_id_equal__opensl; + pContext->onEnumDevices = ma_context_enumerate_devices__opensl; + pContext->onGetDeviceInfo = ma_context_get_device_info__opensl; + pContext->onDeviceInit = ma_device_init__opensl; + pContext->onDeviceUninit = ma_device_uninit__opensl; + pContext->onDeviceStart = ma_device_start__opensl; + pContext->onDeviceStop = ma_device_stop__opensl; return MA_SUCCESS; } @@ -21603,7 +21603,7 @@ mal_result mal_context_init__opensl(mal_context* pContext) #ifdef MA_HAS_WEBAUDIO #include -mal_bool32 mal_is_capture_supported__webaudio() +ma_bool32 ma_is_capture_supported__webaudio() { return EM_ASM_INT({ return (navigator.mediaDevices !== undefined && navigator.mediaDevices.getUserMedia !== undefined); @@ -21613,89 +21613,89 @@ mal_bool32 mal_is_capture_supported__webaudio() #ifdef __cplusplus extern "C" { #endif -EMSCRIPTEN_KEEPALIVE void mal_device_process_pcm_frames_capture__webaudio(mal_device* pDevice, int frameCount, float* pFrames) +EMSCRIPTEN_KEEPALIVE void ma_device_process_pcm_frames_capture__webaudio(ma_device* pDevice, int frameCount, float* pFrames) { - mal_result result; + ma_result result; - if (pDevice->type == mal_device_type_duplex) { - mal_device__handle_duplex_callback_capture(pDevice, (mal_uint32)frameCount, pFrames, &pDevice->webaudio.duplexRB); + if (pDevice->type == ma_device_type_duplex) { + ma_device__handle_duplex_callback_capture(pDevice, (ma_uint32)frameCount, pFrames, &pDevice->webaudio.duplexRB); } else { - mal_device__send_frames_to_client(pDevice, (mal_uint32)frameCount, pFrames); /* Send directly to the client. */ + ma_device__send_frames_to_client(pDevice, (ma_uint32)frameCount, pFrames); /* Send directly to the client. */ } } -EMSCRIPTEN_KEEPALIVE void mal_device_process_pcm_frames_playback__webaudio(mal_device* pDevice, int frameCount, float* pFrames) +EMSCRIPTEN_KEEPALIVE void ma_device_process_pcm_frames_playback__webaudio(ma_device* pDevice, int frameCount, float* pFrames) { - if (pDevice->type == mal_device_type_duplex) { - mal_device__handle_duplex_callback_playback(pDevice, (mal_uint32)frameCount, pFrames, &pDevice->webaudio.duplexRB); + if (pDevice->type == ma_device_type_duplex) { + ma_device__handle_duplex_callback_playback(pDevice, (ma_uint32)frameCount, pFrames, &pDevice->webaudio.duplexRB); } else { - mal_device__read_frames_from_client(pDevice, (mal_uint32)frameCount, pFrames); /* Read directly from the device. */ + ma_device__read_frames_from_client(pDevice, (ma_uint32)frameCount, pFrames); /* Read directly from the device. */ } } #ifdef __cplusplus } #endif -mal_bool32 mal_context_is_device_id_equal__webaudio(mal_context* pContext, const mal_device_id* pID0, const mal_device_id* pID1) +ma_bool32 ma_context_is_device_id_equal__webaudio(ma_context* pContext, const ma_device_id* pID0, const ma_device_id* pID1) { - mal_assert(pContext != NULL); - mal_assert(pID0 != NULL); - mal_assert(pID1 != NULL); + ma_assert(pContext != NULL); + ma_assert(pID0 != NULL); + ma_assert(pID1 != NULL); (void)pContext; - return mal_strcmp(pID0->webaudio, pID1->webaudio) == 0; + return ma_strcmp(pID0->webaudio, pID1->webaudio) == 0; } -mal_result mal_context_enumerate_devices__webaudio(mal_context* pContext, mal_enum_devices_callback_proc callback, void* pUserData) +ma_result ma_context_enumerate_devices__webaudio(ma_context* pContext, ma_enum_devices_callback_proc callback, void* pUserData) { - mal_assert(pContext != NULL); - mal_assert(callback != NULL); + ma_assert(pContext != NULL); + ma_assert(callback != NULL); // Only supporting default devices for now. - mal_bool32 cbResult = MA_TRUE; + ma_bool32 cbResult = MA_TRUE; // Playback. if (cbResult) { - mal_device_info deviceInfo; - mal_zero_object(&deviceInfo); - mal_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), MA_DEFAULT_PLAYBACK_DEVICE_NAME, (size_t)-1); - cbResult = callback(pContext, mal_device_type_playback, &deviceInfo, pUserData); + ma_device_info deviceInfo; + ma_zero_object(&deviceInfo); + ma_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), MA_DEFAULT_PLAYBACK_DEVICE_NAME, (size_t)-1); + cbResult = callback(pContext, ma_device_type_playback, &deviceInfo, pUserData); } // Capture. if (cbResult) { - if (mal_is_capture_supported__webaudio()) { - mal_device_info deviceInfo; - mal_zero_object(&deviceInfo); - mal_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), MA_DEFAULT_CAPTURE_DEVICE_NAME, (size_t)-1); - cbResult = callback(pContext, mal_device_type_capture, &deviceInfo, pUserData); + if (ma_is_capture_supported__webaudio()) { + ma_device_info deviceInfo; + ma_zero_object(&deviceInfo); + ma_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), MA_DEFAULT_CAPTURE_DEVICE_NAME, (size_t)-1); + cbResult = callback(pContext, ma_device_type_capture, &deviceInfo, pUserData); } } return MA_SUCCESS; } -mal_result mal_context_get_device_info__webaudio(mal_context* pContext, mal_device_type deviceType, const mal_device_id* pDeviceID, mal_share_mode shareMode, mal_device_info* pDeviceInfo) +ma_result ma_context_get_device_info__webaudio(ma_context* pContext, ma_device_type deviceType, const ma_device_id* pDeviceID, ma_share_mode shareMode, ma_device_info* pDeviceInfo) { - mal_assert(pContext != NULL); + ma_assert(pContext != NULL); /* No exclusive mode with Web Audio. */ - if (shareMode == mal_share_mode_exclusive) { + if (shareMode == ma_share_mode_exclusive) { return MA_SHARE_MODE_NOT_SUPPORTED; } - if (deviceType == mal_device_type_capture && !mal_is_capture_supported__webaudio()) { + if (deviceType == ma_device_type_capture && !ma_is_capture_supported__webaudio()) { return MA_NO_DEVICE; } - mal_zero_memory(pDeviceInfo->id.webaudio, sizeof(pDeviceInfo->id.webaudio)); + ma_zero_memory(pDeviceInfo->id.webaudio, sizeof(pDeviceInfo->id.webaudio)); /* Only supporting default devices for now. */ - if (deviceType == mal_device_type_playback) { - mal_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), MA_DEFAULT_PLAYBACK_DEVICE_NAME, (size_t)-1); + if (deviceType == ma_device_type_playback) { + ma_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), MA_DEFAULT_PLAYBACK_DEVICE_NAME, (size_t)-1); } else { - mal_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), MA_DEFAULT_CAPTURE_DEVICE_NAME, (size_t)-1); + ma_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), MA_DEFAULT_CAPTURE_DEVICE_NAME, (size_t)-1); } /* Web Audio can support any number of channels and sample rates. It only supports f32 formats, however. */ @@ -21723,15 +21723,15 @@ mal_result mal_context_get_device_info__webaudio(mal_context* pContext, mal_devi /* Web Audio only supports f32. */ pDeviceInfo->formatCount = 1; - pDeviceInfo->formats[0] = mal_format_f32; + pDeviceInfo->formats[0] = ma_format_f32; return MA_SUCCESS; } -void mal_device_uninit_by_index__webaudio(mal_device* pDevice, mal_device_type deviceType, int deviceIndex) +void ma_device_uninit_by_index__webaudio(ma_device* pDevice, ma_device_type deviceType, int deviceIndex) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); EM_ASM({ var device = mal.get_device_by_index($0); @@ -21767,41 +21767,41 @@ void mal_device_uninit_by_index__webaudio(mal_device* pDevice, mal_device_type d }, deviceIndex, deviceType); } -void mal_device_uninit__webaudio(mal_device* pDevice) +void ma_device_uninit__webaudio(ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { - mal_device_uninit_by_index__webaudio(pDevice, mal_device_type_capture, pDevice->webaudio.indexCapture); + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { + ma_device_uninit_by_index__webaudio(pDevice, ma_device_type_capture, pDevice->webaudio.indexCapture); } - if (pDevice->type == mal_device_type_playback || pDevice->type == mal_device_type_duplex) { - mal_device_uninit_by_index__webaudio(pDevice, mal_device_type_playback, pDevice->webaudio.indexPlayback); + if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) { + ma_device_uninit_by_index__webaudio(pDevice, ma_device_type_playback, pDevice->webaudio.indexPlayback); } - if (pDevice->type == mal_device_type_duplex) { - mal_pcm_rb_uninit(&pDevice->webaudio.duplexRB); + if (pDevice->type == ma_device_type_duplex) { + ma_pcm_rb_uninit(&pDevice->webaudio.duplexRB); } } -mal_result mal_device_init_by_type__webaudio(mal_context* pContext, const mal_device_config* pConfig, mal_device_type deviceType, mal_device* pDevice) +ma_result ma_device_init_by_type__webaudio(ma_context* pContext, const ma_device_config* pConfig, ma_device_type deviceType, ma_device* pDevice) { int deviceIndex; - mal_uint32 internalBufferSizeInFrames; + ma_uint32 internalBufferSizeInFrames; - mal_assert(pContext != NULL); - mal_assert(pConfig != NULL); - mal_assert(deviceType != mal_device_type_duplex); - mal_assert(pDevice != NULL); + ma_assert(pContext != NULL); + ma_assert(pConfig != NULL); + ma_assert(deviceType != ma_device_type_duplex); + ma_assert(pDevice != NULL); - if (deviceType == mal_device_type_capture && !mal_is_capture_supported__webaudio()) { + if (deviceType == ma_device_type_capture && !ma_is_capture_supported__webaudio()) { return MA_NO_DEVICE; } /* Try calculating an appropriate buffer size. */ internalBufferSizeInFrames = pConfig->bufferSizeInFrames; if (internalBufferSizeInFrames == 0) { - internalBufferSizeInFrames = mal_calculate_buffer_size_in_frames_from_milliseconds(pConfig->bufferSizeInMilliseconds, pConfig->sampleRate); + internalBufferSizeInFrames = ma_calculate_buffer_size_in_frames_from_milliseconds(pConfig->bufferSizeInMilliseconds, pConfig->sampleRate); } /* The size of the buffer must be a power of 2 and between 256 and 16384. */ @@ -21810,7 +21810,7 @@ mal_result mal_device_init_by_type__webaudio(mal_context* pContext, const mal_de } else if (internalBufferSizeInFrames > 16384) { internalBufferSizeInFrames = 16384; } else { - internalBufferSizeInFrames = mal_next_power_of_2(internalBufferSizeInFrames); + internalBufferSizeInFrames = ma_next_power_of_2(internalBufferSizeInFrames); } /* We create the device on the JavaScript side and reference it using an index. We use this to make it possible to reference the device between JavaScript and C. */ @@ -21901,7 +21901,7 @@ mal_result mal_device_init_by_type__webaudio(mal_context* pContext, const mal_de } /* Send data to the client from our intermediary buffer. */ - ccall("mal_device_process_pcm_frames_capture__webaudio", "undefined", ["number", "number", "number"], [pDevice, framesToProcess, device.intermediaryBuffer]); + ccall("ma_device_process_pcm_frames_capture__webaudio", "undefined", ["number", "number", "number"], [pDevice, framesToProcess, device.intermediaryBuffer]); totalFramesProcessed += framesToProcess; } @@ -21942,7 +21942,7 @@ mal_result mal_device_init_by_type__webaudio(mal_context* pContext, const mal_de } /* Read data from the client into our intermediary buffer. */ - ccall("mal_device_process_pcm_frames_playback__webaudio", "undefined", ["number", "number", "number"], [pDevice, framesToProcess, device.intermediaryBuffer]); + ccall("ma_device_process_pcm_frames_playback__webaudio", "undefined", ["number", "number", "number"], [pDevice, framesToProcess, device.intermediaryBuffer]); /* At this point we'll have data in our intermediary buffer which we now need to deinterleave and copy over to the output buffers. */ if (outputSilence) { @@ -21965,25 +21965,25 @@ mal_result mal_device_init_by_type__webaudio(mal_context* pContext, const mal_de } return mal.track_device(device); - }, (deviceType == mal_device_type_capture) ? pConfig->capture.channels : pConfig->playback.channels, pConfig->sampleRate, internalBufferSizeInFrames, deviceType == mal_device_type_capture, pDevice); + }, (deviceType == ma_device_type_capture) ? pConfig->capture.channels : pConfig->playback.channels, pConfig->sampleRate, internalBufferSizeInFrames, deviceType == ma_device_type_capture, pDevice); if (deviceIndex < 0) { return MA_FAILED_TO_OPEN_BACKEND_DEVICE; } - if (deviceType == mal_device_type_capture) { + if (deviceType == ma_device_type_capture) { pDevice->webaudio.indexCapture = deviceIndex; - pDevice->capture.internalFormat = mal_format_f32; + pDevice->capture.internalFormat = ma_format_f32; pDevice->capture.internalChannels = pConfig->capture.channels; - mal_get_standard_channel_map(mal_standard_channel_map_webaudio, pDevice->capture.internalChannels, pDevice->capture.internalChannelMap); + ma_get_standard_channel_map(ma_standard_channel_map_webaudio, pDevice->capture.internalChannels, pDevice->capture.internalChannelMap); pDevice->capture.internalSampleRate = EM_ASM_INT({ return mal.get_device_by_index($0).webaudio.sampleRate; }, deviceIndex); pDevice->capture.internalBufferSizeInFrames = internalBufferSizeInFrames; pDevice->capture.internalPeriods = 1; } else { pDevice->webaudio.indexPlayback = deviceIndex; - pDevice->playback.internalFormat = mal_format_f32; + pDevice->playback.internalFormat = ma_format_f32; pDevice->playback.internalChannels = pConfig->playback.channels; - mal_get_standard_channel_map(mal_standard_channel_map_webaudio, pDevice->playback.internalChannels, pDevice->playback.internalChannelMap); + ma_get_standard_channel_map(ma_standard_channel_map_webaudio, pDevice->playback.internalChannels, pDevice->playback.internalChannelMap); pDevice->playback.internalSampleRate = EM_ASM_INT({ return mal.get_device_by_index($0).webaudio.sampleRate; }, deviceIndex); pDevice->playback.internalBufferSizeInFrames = internalBufferSizeInFrames; pDevice->playback.internalPeriods = 1; @@ -21992,28 +21992,28 @@ mal_result mal_device_init_by_type__webaudio(mal_context* pContext, const mal_de return MA_SUCCESS; } -mal_result mal_device_init__webaudio(mal_context* pContext, const mal_device_config* pConfig, mal_device* pDevice) +ma_result ma_device_init__webaudio(ma_context* pContext, const ma_device_config* pConfig, ma_device* pDevice) { - mal_result result; + ma_result result; /* No exclusive mode with Web Audio. */ - if (((pConfig->deviceType == mal_device_type_playback || pConfig->deviceType == mal_device_type_duplex) && pConfig->playback.shareMode == mal_share_mode_exclusive) || - ((pConfig->deviceType == mal_device_type_capture || pConfig->deviceType == mal_device_type_duplex) && pConfig->capture.shareMode == mal_share_mode_exclusive)) { + if (((pConfig->deviceType == ma_device_type_playback || pConfig->deviceType == ma_device_type_duplex) && pConfig->playback.shareMode == ma_share_mode_exclusive) || + ((pConfig->deviceType == ma_device_type_capture || pConfig->deviceType == ma_device_type_duplex) && pConfig->capture.shareMode == ma_share_mode_exclusive)) { return MA_SHARE_MODE_NOT_SUPPORTED; } - if (pConfig->deviceType == mal_device_type_capture || pConfig->deviceType == mal_device_type_duplex) { - result = mal_device_init_by_type__webaudio(pContext, pConfig, mal_device_type_capture, pDevice); + if (pConfig->deviceType == ma_device_type_capture || pConfig->deviceType == ma_device_type_duplex) { + result = ma_device_init_by_type__webaudio(pContext, pConfig, ma_device_type_capture, pDevice); if (result != MA_SUCCESS) { return result; } } - if (pConfig->deviceType == mal_device_type_playback || pConfig->deviceType == mal_device_type_duplex) { - result = mal_device_init_by_type__webaudio(pContext, pConfig, mal_device_type_playback, pDevice); + if (pConfig->deviceType == ma_device_type_playback || pConfig->deviceType == ma_device_type_duplex) { + result = ma_device_init_by_type__webaudio(pContext, pConfig, ma_device_type_playback, pDevice); if (result != MA_SUCCESS) { - if (pConfig->deviceType == mal_device_type_duplex) { - mal_device_uninit_by_index__webaudio(pDevice, mal_device_type_capture, pDevice->webaudio.indexCapture); + if (pConfig->deviceType == ma_device_type_duplex) { + ma_device_uninit_by_index__webaudio(pDevice, ma_device_type_capture, pDevice->webaudio.indexCapture); } return result; } @@ -22024,15 +22024,15 @@ mal_result mal_device_init__webaudio(mal_context* pContext, const mal_device_con and the playback callback is the consumer. The buffer needs to be large enough to hold internalBufferSizeInFrames based on the external sample rate. */ - if (pConfig->deviceType == mal_device_type_duplex) { - mal_uint32 rbSizeInFrames = (mal_uint32)mal_calculate_frame_count_after_src(pDevice->sampleRate, pDevice->capture.internalSampleRate, pDevice->capture.internalBufferSizeInFrames) * 2; - result = mal_pcm_rb_init(pDevice->capture.format, pDevice->capture.channels, rbSizeInFrames, NULL, &pDevice->webaudio.duplexRB); + if (pConfig->deviceType == ma_device_type_duplex) { + ma_uint32 rbSizeInFrames = (ma_uint32)ma_calculate_frame_count_after_src(pDevice->sampleRate, pDevice->capture.internalSampleRate, pDevice->capture.internalBufferSizeInFrames) * 2; + result = ma_pcm_rb_init(pDevice->capture.format, pDevice->capture.channels, rbSizeInFrames, NULL, &pDevice->webaudio.duplexRB); if (result != MA_SUCCESS) { - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { - mal_device_uninit_by_index__webaudio(pDevice, mal_device_type_capture, pDevice->webaudio.indexCapture); + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { + ma_device_uninit_by_index__webaudio(pDevice, ma_device_type_capture, pDevice->webaudio.indexCapture); } - if (pDevice->type == mal_device_type_playback || pDevice->type == mal_device_type_duplex) { - mal_device_uninit_by_index__webaudio(pDevice, mal_device_type_playback, pDevice->webaudio.indexPlayback); + if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) { + ma_device_uninit_by_index__webaudio(pDevice, ma_device_type_playback, pDevice->webaudio.indexPlayback); } return result; } @@ -22041,17 +22041,17 @@ mal_result mal_device_init__webaudio(mal_context* pContext, const mal_device_con return MA_SUCCESS; } -mal_result mal_device_start__webaudio(mal_device* pDevice) +ma_result ma_device_start__webaudio(ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { EM_ASM({ mal.get_device_by_index($0).webaudio.resume(); }, pDevice->webaudio.indexCapture); } - if (pDevice->type == mal_device_type_playback || pDevice->type == mal_device_type_duplex) { + if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) { EM_ASM({ mal.get_device_by_index($0).webaudio.resume(); }, pDevice->webaudio.indexPlayback); @@ -22060,23 +22060,23 @@ mal_result mal_device_start__webaudio(mal_device* pDevice) return MA_SUCCESS; } -mal_result mal_device_stop__webaudio(mal_device* pDevice) +ma_result ma_device_stop__webaudio(ma_device* pDevice) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { EM_ASM({ mal.get_device_by_index($0).webaudio.suspend(); }, pDevice->webaudio.indexCapture); } - if (pDevice->type == mal_device_type_playback || pDevice->type == mal_device_type_duplex) { + if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) { EM_ASM({ mal.get_device_by_index($0).webaudio.suspend(); }, pDevice->webaudio.indexPlayback); } - mal_stop_proc onStop = pDevice->onStop; + ma_stop_proc onStop = pDevice->onStop; if (onStop) { onStop(pDevice); } @@ -22084,10 +22084,10 @@ mal_result mal_device_stop__webaudio(mal_device* pDevice) return MA_SUCCESS; } -mal_result mal_context_uninit__webaudio(mal_context* pContext) +ma_result ma_context_uninit__webaudio(ma_context* pContext) { - mal_assert(pContext != NULL); - mal_assert(pContext->backend == mal_backend_webaudio); + ma_assert(pContext != NULL); + ma_assert(pContext->backend == ma_backend_webaudio); /* Nothing needs to be done here. */ (void)pContext; @@ -22095,9 +22095,9 @@ mal_result mal_context_uninit__webaudio(mal_context* pContext) return MA_SUCCESS; } -mal_result mal_context_init__webaudio(mal_context* pContext) +ma_result ma_context_init__webaudio(ma_context* pContext) { - mal_assert(pContext != NULL); + ma_assert(pContext != NULL); /* Here is where our global JavaScript object is initialized. */ int resultFromJS = EM_ASM_INT({ @@ -22124,7 +22124,7 @@ mal_result mal_context_init__webaudio(mal_context* pContext) }; mal.untrack_device_by_index = function(deviceIndex) { - /* We just set the device's slot to null. The slot will get reused in the next call to mal_track_device. */ + /* We just set the device's slot to null. The slot will get reused in the next call to ma_track_device. */ mal.devices[deviceIndex] = null; /* Trim the array if possible. */ @@ -22160,14 +22160,14 @@ mal_result mal_context_init__webaudio(mal_context* pContext) pContext->isBackendAsynchronous = MA_TRUE; - pContext->onUninit = mal_context_uninit__webaudio; - pContext->onDeviceIDEqual = mal_context_is_device_id_equal__webaudio; - pContext->onEnumDevices = mal_context_enumerate_devices__webaudio; - pContext->onGetDeviceInfo = mal_context_get_device_info__webaudio; - pContext->onDeviceInit = mal_device_init__webaudio; - pContext->onDeviceUninit = mal_device_uninit__webaudio; - pContext->onDeviceStart = mal_device_start__webaudio; - pContext->onDeviceStop = mal_device_stop__webaudio; + pContext->onUninit = ma_context_uninit__webaudio; + pContext->onDeviceIDEqual = ma_context_is_device_id_equal__webaudio; + pContext->onEnumDevices = ma_context_enumerate_devices__webaudio; + pContext->onGetDeviceInfo = ma_context_get_device_info__webaudio; + pContext->onDeviceInit = ma_device_init__webaudio; + pContext->onDeviceUninit = ma_device_uninit__webaudio; + pContext->onDeviceStart = ma_device_start__webaudio; + pContext->onDeviceStop = ma_device_stop__webaudio; return MA_SUCCESS; } @@ -22175,7 +22175,7 @@ mal_result mal_context_init__webaudio(mal_context* pContext) -mal_bool32 mal__is_channel_map_valid(const mal_channel* channelMap, mal_uint32 channels) +ma_bool32 ma__is_channel_map_valid(const ma_channel* channelMap, ma_uint32 channels) { // A blank channel map should be allowed, in which case it should use an appropriate default which will depend on context. if (channelMap[0] != MA_CHANNEL_NONE) { @@ -22184,8 +22184,8 @@ mal_bool32 mal__is_channel_map_valid(const mal_channel* channelMap, mal_uint32 c } // A channel cannot be present in the channel map more than once. - for (mal_uint32 iChannel = 0; iChannel < channels; ++iChannel) { - for (mal_uint32 jChannel = iChannel + 1; jChannel < channels; ++jChannel) { + for (ma_uint32 iChannel = 0; iChannel < channels; ++iChannel) { + for (ma_uint32 jChannel = iChannel + 1; jChannel < channels; ++jChannel) { if (channelMap[iChannel] == channelMap[jChannel]) { return MA_FALSE; } @@ -22197,11 +22197,11 @@ mal_bool32 mal__is_channel_map_valid(const mal_channel* channelMap, mal_uint32 c } -void mal_device__post_init_setup(mal_device* pDevice, mal_device_type deviceType) +void ma_device__post_init_setup(ma_device* pDevice, ma_device_type deviceType) { - mal_assert(pDevice != NULL); + ma_assert(pDevice != NULL); - if (deviceType == mal_device_type_capture || deviceType == mal_device_type_duplex) { + if (deviceType == ma_device_type_capture || deviceType == ma_device_type_duplex) { if (pDevice->capture.usingDefaultFormat) { pDevice->capture.format = pDevice->capture.internalFormat; } @@ -22210,14 +22210,14 @@ void mal_device__post_init_setup(mal_device* pDevice, mal_device_type deviceType } if (pDevice->capture.usingDefaultChannelMap) { if (pDevice->capture.internalChannels == pDevice->capture.channels) { - mal_channel_map_copy(pDevice->capture.channelMap, pDevice->capture.internalChannelMap, pDevice->capture.channels); + ma_channel_map_copy(pDevice->capture.channelMap, pDevice->capture.internalChannelMap, pDevice->capture.channels); } else { - mal_get_standard_channel_map(mal_standard_channel_map_default, pDevice->capture.channels, pDevice->capture.channelMap); + ma_get_standard_channel_map(ma_standard_channel_map_default, pDevice->capture.channels, pDevice->capture.channelMap); } } } - if (deviceType == mal_device_type_playback || deviceType == mal_device_type_duplex) { + if (deviceType == ma_device_type_playback || deviceType == ma_device_type_duplex) { if (pDevice->playback.usingDefaultFormat) { pDevice->playback.format = pDevice->playback.internalFormat; } @@ -22226,15 +22226,15 @@ void mal_device__post_init_setup(mal_device* pDevice, mal_device_type deviceType } if (pDevice->playback.usingDefaultChannelMap) { if (pDevice->playback.internalChannels == pDevice->playback.channels) { - mal_channel_map_copy(pDevice->playback.channelMap, pDevice->playback.internalChannelMap, pDevice->playback.channels); + ma_channel_map_copy(pDevice->playback.channelMap, pDevice->playback.internalChannelMap, pDevice->playback.channels); } else { - mal_get_standard_channel_map(mal_standard_channel_map_default, pDevice->playback.channels, pDevice->playback.channelMap); + ma_get_standard_channel_map(ma_standard_channel_map_default, pDevice->playback.channels, pDevice->playback.channelMap); } } } if (pDevice->usingDefaultSampleRate) { - if (deviceType == mal_device_type_capture || deviceType == mal_device_type_duplex) { + if (deviceType == ma_device_type_capture || deviceType == ma_device_type_duplex) { pDevice->sampleRate = pDevice->capture.internalSampleRate; } else { pDevice->sampleRate = pDevice->playback.internalSampleRate; @@ -22242,108 +22242,108 @@ void mal_device__post_init_setup(mal_device* pDevice, mal_device_type deviceType } /* PCM converters. */ - if (deviceType == mal_device_type_capture || deviceType == mal_device_type_duplex) { + if (deviceType == ma_device_type_capture || deviceType == ma_device_type_duplex) { /* Converting from internal device format to public format. */ - mal_pcm_converter_config converterConfig = mal_pcm_converter_config_init_new(); + ma_pcm_converter_config converterConfig = ma_pcm_converter_config_init_new(); converterConfig.neverConsumeEndOfInput = MA_TRUE; converterConfig.pUserData = pDevice; converterConfig.formatIn = pDevice->capture.internalFormat; converterConfig.channelsIn = pDevice->capture.internalChannels; converterConfig.sampleRateIn = pDevice->capture.internalSampleRate; - mal_channel_map_copy(converterConfig.channelMapIn, pDevice->capture.internalChannelMap, pDevice->capture.internalChannels); + ma_channel_map_copy(converterConfig.channelMapIn, pDevice->capture.internalChannelMap, pDevice->capture.internalChannels); converterConfig.formatOut = pDevice->capture.format; converterConfig.channelsOut = pDevice->capture.channels; converterConfig.sampleRateOut = pDevice->sampleRate; - mal_channel_map_copy(converterConfig.channelMapOut, pDevice->capture.channelMap, pDevice->capture.channels); - converterConfig.onRead = mal_device__pcm_converter__on_read_from_buffer_capture; - mal_pcm_converter_init(&converterConfig, &pDevice->capture.converter); + ma_channel_map_copy(converterConfig.channelMapOut, pDevice->capture.channelMap, pDevice->capture.channels); + converterConfig.onRead = ma_device__pcm_converter__on_read_from_buffer_capture; + ma_pcm_converter_init(&converterConfig, &pDevice->capture.converter); } - if (deviceType == mal_device_type_playback || deviceType == mal_device_type_duplex) { + if (deviceType == ma_device_type_playback || deviceType == ma_device_type_duplex) { /* Converting from public format to device format. */ - mal_pcm_converter_config converterConfig = mal_pcm_converter_config_init_new(); + ma_pcm_converter_config converterConfig = ma_pcm_converter_config_init_new(); converterConfig.neverConsumeEndOfInput = MA_TRUE; converterConfig.pUserData = pDevice; converterConfig.formatIn = pDevice->playback.format; converterConfig.channelsIn = pDevice->playback.channels; converterConfig.sampleRateIn = pDevice->sampleRate; - mal_channel_map_copy(converterConfig.channelMapIn, pDevice->playback.channelMap, pDevice->playback.channels); + ma_channel_map_copy(converterConfig.channelMapIn, pDevice->playback.channelMap, pDevice->playback.channels); converterConfig.formatOut = pDevice->playback.internalFormat; converterConfig.channelsOut = pDevice->playback.internalChannels; converterConfig.sampleRateOut = pDevice->playback.internalSampleRate; - mal_channel_map_copy(converterConfig.channelMapOut, pDevice->playback.internalChannelMap, pDevice->playback.internalChannels); - if (deviceType == mal_device_type_playback) { - if (pDevice->type == mal_device_type_playback) { - converterConfig.onRead = mal_device__on_read_from_client; + ma_channel_map_copy(converterConfig.channelMapOut, pDevice->playback.internalChannelMap, pDevice->playback.internalChannels); + if (deviceType == ma_device_type_playback) { + if (pDevice->type == ma_device_type_playback) { + converterConfig.onRead = ma_device__on_read_from_client; } else { - converterConfig.onRead = mal_device__pcm_converter__on_read_from_buffer_playback; + converterConfig.onRead = ma_device__pcm_converter__on_read_from_buffer_playback; } } else { - converterConfig.onRead = mal_device__pcm_converter__on_read_from_buffer_playback; + converterConfig.onRead = ma_device__pcm_converter__on_read_from_buffer_playback; } - mal_pcm_converter_init(&converterConfig, &pDevice->playback.converter); + ma_pcm_converter_init(&converterConfig, &pDevice->playback.converter); } } -mal_thread_result MA_THREADCALL mal_worker_thread(void* pData) +ma_thread_result MA_THREADCALL ma_worker_thread(void* pData) { - mal_device* pDevice = (mal_device*)pData; - mal_assert(pDevice != NULL); + ma_device* pDevice = (ma_device*)pData; + ma_assert(pDevice != NULL); #ifdef MA_WIN32 - mal_CoInitializeEx(pDevice->pContext, NULL, MA_COINIT_VALUE); + ma_CoInitializeEx(pDevice->pContext, NULL, MA_COINIT_VALUE); #endif // When the device is being initialized it's initial state is set to MA_STATE_UNINITIALIZED. Before returning from - // mal_device_init(), the state needs to be set to something valid. In miniaudio the device's default state immediately + // ma_device_init(), the state needs to be set to something valid. In miniaudio the device's default state immediately // after initialization is stopped, so therefore we need to mark the device as such. miniaudio will wait on the worker // thread to signal an event to know when the worker thread is ready for action. - mal_device__set_state(pDevice, MA_STATE_STOPPED); - mal_event_signal(&pDevice->stopEvent); + ma_device__set_state(pDevice, MA_STATE_STOPPED); + ma_event_signal(&pDevice->stopEvent); for (;;) { /* <-- This loop just keeps the thread alive. The main audio loop is inside. */ // We wait on an event to know when something has requested that the device be started and the main loop entered. - mal_event_wait(&pDevice->wakeupEvent); + ma_event_wait(&pDevice->wakeupEvent); // Default result code. pDevice->workResult = MA_SUCCESS; // If the reason for the wake up is that we are terminating, just break from the loop. - if (mal_device__get_state(pDevice) == MA_STATE_UNINITIALIZED) { + if (ma_device__get_state(pDevice) == MA_STATE_UNINITIALIZED) { break; } // Getting to this point means the device is wanting to get started. The function that has requested that the device // be started will be waiting on an event (pDevice->startEvent) which means we need to make sure we signal the event // in both the success and error case. It's important that the state of the device is set _before_ signaling the event. - mal_assert(mal_device__get_state(pDevice) == MA_STATE_STARTING); + ma_assert(ma_device__get_state(pDevice) == MA_STATE_STARTING); /* Make sure the state is set appropriately. */ - mal_device__set_state(pDevice, MA_STATE_STARTED); - mal_event_signal(&pDevice->startEvent); + ma_device__set_state(pDevice, MA_STATE_STARTED); + ma_event_signal(&pDevice->startEvent); if (pDevice->pContext->onDeviceMainLoop != NULL) { pDevice->pContext->onDeviceMainLoop(pDevice); } else { /* When a device is using miniaudio's generic worker thread they must implement onDeviceRead or onDeviceWrite, depending on the device type. */ - mal_assert( - (pDevice->type == mal_device_type_playback && pDevice->pContext->onDeviceWrite != NULL) || - (pDevice->type == mal_device_type_capture && pDevice->pContext->onDeviceRead != NULL) || - (pDevice->type == mal_device_type_duplex && pDevice->pContext->onDeviceWrite != NULL && pDevice->pContext->onDeviceRead != NULL) + ma_assert( + (pDevice->type == ma_device_type_playback && pDevice->pContext->onDeviceWrite != NULL) || + (pDevice->type == ma_device_type_capture && pDevice->pContext->onDeviceRead != NULL) || + (pDevice->type == ma_device_type_duplex && pDevice->pContext->onDeviceWrite != NULL && pDevice->pContext->onDeviceRead != NULL) ); - mal_uint32 periodSizeInFrames; - if (pDevice->type == mal_device_type_capture) { - mal_assert(pDevice->capture.internalBufferSizeInFrames >= pDevice->capture.internalPeriods); + ma_uint32 periodSizeInFrames; + if (pDevice->type == ma_device_type_capture) { + ma_assert(pDevice->capture.internalBufferSizeInFrames >= pDevice->capture.internalPeriods); periodSizeInFrames = pDevice->capture.internalBufferSizeInFrames / pDevice->capture.internalPeriods; - } else if (pDevice->type == mal_device_type_playback) { - mal_assert(pDevice->playback.internalBufferSizeInFrames >= pDevice->playback.internalPeriods); + } else if (pDevice->type == ma_device_type_playback) { + ma_assert(pDevice->playback.internalBufferSizeInFrames >= pDevice->playback.internalPeriods); periodSizeInFrames = pDevice->playback.internalBufferSizeInFrames / pDevice->playback.internalPeriods; } else { - mal_assert(pDevice->capture.internalBufferSizeInFrames >= pDevice->capture.internalPeriods); - mal_assert(pDevice->playback.internalBufferSizeInFrames >= pDevice->playback.internalPeriods); - periodSizeInFrames = mal_min( + ma_assert(pDevice->capture.internalBufferSizeInFrames >= pDevice->capture.internalPeriods); + ma_assert(pDevice->playback.internalBufferSizeInFrames >= pDevice->playback.internalPeriods); + periodSizeInFrames = ma_min( pDevice->capture.internalBufferSizeInFrames / pDevice->capture.internalPeriods, pDevice->playback.internalBufferSizeInFrames / pDevice->playback.internalPeriods ); @@ -22355,19 +22355,19 @@ mal_thread_result MA_THREADCALL mal_worker_thread(void* pData) */ /* Main Loop */ - mal_assert(periodSizeInFrames >= 1); - while (mal_device__get_state(pDevice) == MA_STATE_STARTED) { - mal_result result = MA_SUCCESS; - mal_uint32 totalFramesProcessed = 0; + ma_assert(periodSizeInFrames >= 1); + while (ma_device__get_state(pDevice) == MA_STATE_STARTED) { + ma_result result = MA_SUCCESS; + ma_uint32 totalFramesProcessed = 0; - if (pDevice->type == mal_device_type_duplex) { + if (pDevice->type == ma_device_type_duplex) { /* The process is device_read -> convert -> callback -> convert -> device_write. */ - mal_uint8 captureDeviceData[4096]; - mal_uint32 captureDeviceDataCapInFrames = sizeof(captureDeviceData) / mal_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels); + ma_uint8 captureDeviceData[4096]; + ma_uint32 captureDeviceDataCapInFrames = sizeof(captureDeviceData) / ma_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels); while (totalFramesProcessed < periodSizeInFrames) { - mal_uint32 framesRemaining = periodSizeInFrames - totalFramesProcessed; - mal_uint32 framesToProcess = framesRemaining; + ma_uint32 framesRemaining = periodSizeInFrames - totalFramesProcessed; + ma_uint32 framesToProcess = framesRemaining; if (framesToProcess > captureDeviceDataCapInFrames) { framesToProcess = captureDeviceDataCapInFrames; } @@ -22377,21 +22377,21 @@ mal_thread_result MA_THREADCALL mal_worker_thread(void* pData) break; } - mal_device_callback_proc onData = pDevice->onData; + ma_device_callback_proc onData = pDevice->onData; if (onData != NULL) { pDevice->capture._dspFrameCount = framesToProcess; pDevice->capture._dspFrames = captureDeviceData; /* We need to process every input frame. */ for (;;) { - mal_uint8 capturedData[4096]; // In capture.format/channels format - mal_uint8 playbackData[4096]; // In playback.format/channels format + ma_uint8 capturedData[4096]; // In capture.format/channels format + ma_uint8 playbackData[4096]; // In playback.format/channels format - mal_uint32 capturedDataCapInFrames = sizeof(capturedData) / mal_get_bytes_per_frame(pDevice->capture.format, pDevice->capture.channels); - mal_uint32 playbackDataCapInFrames = sizeof(playbackData) / mal_get_bytes_per_frame(pDevice->playback.format, pDevice->playback.channels); + ma_uint32 capturedDataCapInFrames = sizeof(capturedData) / ma_get_bytes_per_frame(pDevice->capture.format, pDevice->capture.channels); + ma_uint32 playbackDataCapInFrames = sizeof(playbackData) / ma_get_bytes_per_frame(pDevice->playback.format, pDevice->playback.channels); - mal_uint32 capturedFramesToTryProcessing = mal_min(capturedDataCapInFrames, playbackDataCapInFrames); - mal_uint32 capturedFramesToProcess = (mal_uint32)mal_pcm_converter_read(&pDevice->capture.converter, capturedData, capturedFramesToTryProcessing); + ma_uint32 capturedFramesToTryProcessing = ma_min(capturedDataCapInFrames, playbackDataCapInFrames); + ma_uint32 capturedFramesToProcess = (ma_uint32)ma_pcm_converter_read(&pDevice->capture.converter, capturedData, capturedFramesToTryProcessing); if (capturedFramesToProcess == 0) { break; /* Don't fire the data callback with zero frames. */ } @@ -22402,10 +22402,10 @@ mal_thread_result MA_THREADCALL mal_worker_thread(void* pData) pDevice->playback._dspFrameCount = capturedFramesToProcess; pDevice->playback._dspFrames = playbackData; for (;;) { - mal_uint8 playbackDeviceData[4096]; + ma_uint8 playbackDeviceData[4096]; - mal_uint32 playbackDeviceDataCapInFrames = sizeof(playbackDeviceData) / mal_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels); - mal_uint32 playbackDeviceFramesCount = (mal_uint32)mal_pcm_converter_read(&pDevice->playback.converter, playbackDeviceData, playbackDeviceDataCapInFrames); + ma_uint32 playbackDeviceDataCapInFrames = sizeof(playbackDeviceData) / ma_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels); + ma_uint32 playbackDeviceFramesCount = (ma_uint32)ma_pcm_converter_read(&pDevice->playback.converter, playbackDeviceData, playbackDeviceDataCapInFrames); if (playbackDeviceFramesCount == 0) { break; } @@ -22434,27 +22434,27 @@ mal_thread_result MA_THREADCALL mal_worker_thread(void* pData) totalFramesProcessed += framesToProcess; } } else { - mal_uint8 buffer[4096]; - mal_uint32 bufferSizeInFrames; - if (pDevice->type == mal_device_type_capture) { - bufferSizeInFrames = sizeof(buffer) / mal_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels); + ma_uint8 buffer[4096]; + ma_uint32 bufferSizeInFrames; + if (pDevice->type == ma_device_type_capture) { + bufferSizeInFrames = sizeof(buffer) / ma_get_bytes_per_frame(pDevice->capture.internalFormat, pDevice->capture.internalChannels); } else { - bufferSizeInFrames = sizeof(buffer) / mal_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels); + bufferSizeInFrames = sizeof(buffer) / ma_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels); } while (totalFramesProcessed < periodSizeInFrames) { - mal_uint32 framesRemaining = periodSizeInFrames - totalFramesProcessed; - mal_uint32 framesToProcess = framesRemaining; + ma_uint32 framesRemaining = periodSizeInFrames - totalFramesProcessed; + ma_uint32 framesToProcess = framesRemaining; if (framesToProcess > bufferSizeInFrames) { framesToProcess = bufferSizeInFrames; } - if (pDevice->type == mal_device_type_playback) { - mal_device__read_frames_from_client(pDevice, framesToProcess, buffer); + if (pDevice->type == ma_device_type_playback) { + ma_device__read_frames_from_client(pDevice, framesToProcess, buffer); result = pDevice->pContext->onDeviceWrite(pDevice, buffer, framesToProcess); } else { result = pDevice->pContext->onDeviceRead(pDevice, buffer, framesToProcess); - mal_device__send_frames_to_client(pDevice, framesToProcess, buffer); + ma_device__send_frames_to_client(pDevice, framesToProcess, buffer); } totalFramesProcessed += framesToProcess; @@ -22472,14 +22472,14 @@ mal_thread_result MA_THREADCALL mal_worker_thread(void* pData) // Getting here means we have broken from the main loop which happens the application has requested that device be stopped. Note that this // may have actually already happened above if the device was lost and miniaudio has attempted to re-initialize the device. In this case we // don't want to be doing this a second time. - if (mal_device__get_state(pDevice) != MA_STATE_UNINITIALIZED) { + if (ma_device__get_state(pDevice) != MA_STATE_UNINITIALIZED) { if (pDevice->pContext->onDeviceStop) { pDevice->pContext->onDeviceStop(pDevice); } } // After the device has stopped, make sure an event is posted. - mal_stop_proc onStop = pDevice->onStop; + ma_stop_proc onStop = pDevice->onStop; if (onStop) { onStop(pDevice); } @@ -22487,88 +22487,88 @@ mal_thread_result MA_THREADCALL mal_worker_thread(void* pData) // A function somewhere is waiting for the device to have stopped for real so we need to signal an event to allow it to continue. Note that // it's possible that the device has been uninitialized which means we need to _not_ change the status to stopped. We cannot go from an // uninitialized state to stopped state. - if (mal_device__get_state(pDevice) != MA_STATE_UNINITIALIZED) { - mal_device__set_state(pDevice, MA_STATE_STOPPED); - mal_event_signal(&pDevice->stopEvent); + if (ma_device__get_state(pDevice) != MA_STATE_UNINITIALIZED) { + ma_device__set_state(pDevice, MA_STATE_STOPPED); + ma_event_signal(&pDevice->stopEvent); } } // Make sure we aren't continuously waiting on a stop event. - mal_event_signal(&pDevice->stopEvent); // <-- Is this still needed? + ma_event_signal(&pDevice->stopEvent); // <-- Is this still needed? #ifdef MA_WIN32 - mal_CoUninitialize(pDevice->pContext); + ma_CoUninitialize(pDevice->pContext); #endif - return (mal_thread_result)0; + return (ma_thread_result)0; } // Helper for determining whether or not the given device is initialized. -mal_bool32 mal_device__is_initialized(mal_device* pDevice) +ma_bool32 ma_device__is_initialized(ma_device* pDevice) { if (pDevice == NULL) return MA_FALSE; - return mal_device__get_state(pDevice) != MA_STATE_UNINITIALIZED; + return ma_device__get_state(pDevice) != MA_STATE_UNINITIALIZED; } #ifdef MA_WIN32 -mal_result mal_context_uninit_backend_apis__win32(mal_context* pContext) +ma_result ma_context_uninit_backend_apis__win32(ma_context* pContext) { - mal_CoUninitialize(pContext); - mal_dlclose(pContext->win32.hUser32DLL); - mal_dlclose(pContext->win32.hOle32DLL); - mal_dlclose(pContext->win32.hAdvapi32DLL); + ma_CoUninitialize(pContext); + ma_dlclose(pContext->win32.hUser32DLL); + ma_dlclose(pContext->win32.hOle32DLL); + ma_dlclose(pContext->win32.hAdvapi32DLL); return MA_SUCCESS; } -mal_result mal_context_init_backend_apis__win32(mal_context* pContext) +ma_result ma_context_init_backend_apis__win32(ma_context* pContext) { #ifdef MA_WIN32_DESKTOP // Ole32.dll - pContext->win32.hOle32DLL = mal_dlopen("ole32.dll"); + pContext->win32.hOle32DLL = ma_dlopen("ole32.dll"); if (pContext->win32.hOle32DLL == NULL) { return MA_FAILED_TO_INIT_BACKEND; } - pContext->win32.CoInitializeEx = (mal_proc)mal_dlsym(pContext->win32.hOle32DLL, "CoInitializeEx"); - pContext->win32.CoUninitialize = (mal_proc)mal_dlsym(pContext->win32.hOle32DLL, "CoUninitialize"); - pContext->win32.CoCreateInstance = (mal_proc)mal_dlsym(pContext->win32.hOle32DLL, "CoCreateInstance"); - pContext->win32.CoTaskMemFree = (mal_proc)mal_dlsym(pContext->win32.hOle32DLL, "CoTaskMemFree"); - pContext->win32.PropVariantClear = (mal_proc)mal_dlsym(pContext->win32.hOle32DLL, "PropVariantClear"); - pContext->win32.StringFromGUID2 = (mal_proc)mal_dlsym(pContext->win32.hOle32DLL, "StringFromGUID2"); + pContext->win32.CoInitializeEx = (ma_proc)ma_dlsym(pContext->win32.hOle32DLL, "CoInitializeEx"); + pContext->win32.CoUninitialize = (ma_proc)ma_dlsym(pContext->win32.hOle32DLL, "CoUninitialize"); + pContext->win32.CoCreateInstance = (ma_proc)ma_dlsym(pContext->win32.hOle32DLL, "CoCreateInstance"); + pContext->win32.CoTaskMemFree = (ma_proc)ma_dlsym(pContext->win32.hOle32DLL, "CoTaskMemFree"); + pContext->win32.PropVariantClear = (ma_proc)ma_dlsym(pContext->win32.hOle32DLL, "PropVariantClear"); + pContext->win32.StringFromGUID2 = (ma_proc)ma_dlsym(pContext->win32.hOle32DLL, "StringFromGUID2"); // User32.dll - pContext->win32.hUser32DLL = mal_dlopen("user32.dll"); + pContext->win32.hUser32DLL = ma_dlopen("user32.dll"); if (pContext->win32.hUser32DLL == NULL) { return MA_FAILED_TO_INIT_BACKEND; } - pContext->win32.GetForegroundWindow = (mal_proc)mal_dlsym(pContext->win32.hUser32DLL, "GetForegroundWindow"); - pContext->win32.GetDesktopWindow = (mal_proc)mal_dlsym(pContext->win32.hUser32DLL, "GetDesktopWindow"); + pContext->win32.GetForegroundWindow = (ma_proc)ma_dlsym(pContext->win32.hUser32DLL, "GetForegroundWindow"); + pContext->win32.GetDesktopWindow = (ma_proc)ma_dlsym(pContext->win32.hUser32DLL, "GetDesktopWindow"); // Advapi32.dll - pContext->win32.hAdvapi32DLL = mal_dlopen("advapi32.dll"); + pContext->win32.hAdvapi32DLL = ma_dlopen("advapi32.dll"); if (pContext->win32.hAdvapi32DLL == NULL) { return MA_FAILED_TO_INIT_BACKEND; } - pContext->win32.RegOpenKeyExA = (mal_proc)mal_dlsym(pContext->win32.hAdvapi32DLL, "RegOpenKeyExA"); - pContext->win32.RegCloseKey = (mal_proc)mal_dlsym(pContext->win32.hAdvapi32DLL, "RegCloseKey"); - pContext->win32.RegQueryValueExA = (mal_proc)mal_dlsym(pContext->win32.hAdvapi32DLL, "RegQueryValueExA"); + pContext->win32.RegOpenKeyExA = (ma_proc)ma_dlsym(pContext->win32.hAdvapi32DLL, "RegOpenKeyExA"); + pContext->win32.RegCloseKey = (ma_proc)ma_dlsym(pContext->win32.hAdvapi32DLL, "RegCloseKey"); + pContext->win32.RegQueryValueExA = (ma_proc)ma_dlsym(pContext->win32.hAdvapi32DLL, "RegQueryValueExA"); #endif - mal_CoInitializeEx(pContext, NULL, MA_COINIT_VALUE); + ma_CoInitializeEx(pContext, NULL, MA_COINIT_VALUE); return MA_SUCCESS; } #else -mal_result mal_context_uninit_backend_apis__nix(mal_context* pContext) +ma_result ma_context_uninit_backend_apis__nix(ma_context* pContext) { #if defined(MA_USE_RUNTIME_LINKING_FOR_PTHREAD) && !defined(MA_NO_RUNTIME_LINKING) - mal_dlclose(pContext->posix.pthreadSO); + ma_dlclose(pContext->posix.pthreadSO); #else (void)pContext; #endif @@ -22576,7 +22576,7 @@ mal_result mal_context_uninit_backend_apis__nix(mal_context* pContext) return MA_SUCCESS; } -mal_result mal_context_init_backend_apis__nix(mal_context* pContext) +ma_result ma_context_init_backend_apis__nix(ma_context* pContext) { // pthread #if defined(MA_USE_RUNTIME_LINKING_FOR_PTHREAD) && !defined(MA_NO_RUNTIME_LINKING) @@ -22587,7 +22587,7 @@ mal_result mal_context_init_backend_apis__nix(mal_context* pContext) }; for (size_t i = 0; i < sizeof(libpthreadFileNames) / sizeof(libpthreadFileNames[0]); ++i) { - pContext->posix.pthreadSO = mal_dlopen(libpthreadFileNames[i]); + pContext->posix.pthreadSO = ma_dlopen(libpthreadFileNames[i]); if (pContext->posix.pthreadSO != NULL) { break; } @@ -22597,38 +22597,38 @@ mal_result mal_context_init_backend_apis__nix(mal_context* pContext) return MA_FAILED_TO_INIT_BACKEND; } - pContext->posix.pthread_create = (mal_proc)mal_dlsym(pContext->posix.pthreadSO, "pthread_create"); - pContext->posix.pthread_join = (mal_proc)mal_dlsym(pContext->posix.pthreadSO, "pthread_join"); - pContext->posix.pthread_mutex_init = (mal_proc)mal_dlsym(pContext->posix.pthreadSO, "pthread_mutex_init"); - pContext->posix.pthread_mutex_destroy = (mal_proc)mal_dlsym(pContext->posix.pthreadSO, "pthread_mutex_destroy"); - pContext->posix.pthread_mutex_lock = (mal_proc)mal_dlsym(pContext->posix.pthreadSO, "pthread_mutex_lock"); - pContext->posix.pthread_mutex_unlock = (mal_proc)mal_dlsym(pContext->posix.pthreadSO, "pthread_mutex_unlock"); - pContext->posix.pthread_cond_init = (mal_proc)mal_dlsym(pContext->posix.pthreadSO, "pthread_cond_init"); - pContext->posix.pthread_cond_destroy = (mal_proc)mal_dlsym(pContext->posix.pthreadSO, "pthread_cond_destroy"); - pContext->posix.pthread_cond_wait = (mal_proc)mal_dlsym(pContext->posix.pthreadSO, "pthread_cond_wait"); - pContext->posix.pthread_cond_signal = (mal_proc)mal_dlsym(pContext->posix.pthreadSO, "pthread_cond_signal"); - pContext->posix.pthread_attr_init = (mal_proc)mal_dlsym(pContext->posix.pthreadSO, "pthread_attr_init"); - pContext->posix.pthread_attr_destroy = (mal_proc)mal_dlsym(pContext->posix.pthreadSO, "pthread_attr_destroy"); - pContext->posix.pthread_attr_setschedpolicy = (mal_proc)mal_dlsym(pContext->posix.pthreadSO, "pthread_attr_setschedpolicy"); - pContext->posix.pthread_attr_getschedparam = (mal_proc)mal_dlsym(pContext->posix.pthreadSO, "pthread_attr_getschedparam"); - pContext->posix.pthread_attr_setschedparam = (mal_proc)mal_dlsym(pContext->posix.pthreadSO, "pthread_attr_setschedparam"); + pContext->posix.pthread_create = (ma_proc)ma_dlsym(pContext->posix.pthreadSO, "pthread_create"); + pContext->posix.pthread_join = (ma_proc)ma_dlsym(pContext->posix.pthreadSO, "pthread_join"); + pContext->posix.pthread_mutex_init = (ma_proc)ma_dlsym(pContext->posix.pthreadSO, "pthread_mutex_init"); + pContext->posix.pthread_mutex_destroy = (ma_proc)ma_dlsym(pContext->posix.pthreadSO, "pthread_mutex_destroy"); + pContext->posix.pthread_mutex_lock = (ma_proc)ma_dlsym(pContext->posix.pthreadSO, "pthread_mutex_lock"); + pContext->posix.pthread_mutex_unlock = (ma_proc)ma_dlsym(pContext->posix.pthreadSO, "pthread_mutex_unlock"); + pContext->posix.pthread_cond_init = (ma_proc)ma_dlsym(pContext->posix.pthreadSO, "pthread_cond_init"); + pContext->posix.pthread_cond_destroy = (ma_proc)ma_dlsym(pContext->posix.pthreadSO, "pthread_cond_destroy"); + pContext->posix.pthread_cond_wait = (ma_proc)ma_dlsym(pContext->posix.pthreadSO, "pthread_cond_wait"); + pContext->posix.pthread_cond_signal = (ma_proc)ma_dlsym(pContext->posix.pthreadSO, "pthread_cond_signal"); + pContext->posix.pthread_attr_init = (ma_proc)ma_dlsym(pContext->posix.pthreadSO, "pthread_attr_init"); + pContext->posix.pthread_attr_destroy = (ma_proc)ma_dlsym(pContext->posix.pthreadSO, "pthread_attr_destroy"); + pContext->posix.pthread_attr_setschedpolicy = (ma_proc)ma_dlsym(pContext->posix.pthreadSO, "pthread_attr_setschedpolicy"); + pContext->posix.pthread_attr_getschedparam = (ma_proc)ma_dlsym(pContext->posix.pthreadSO, "pthread_attr_getschedparam"); + pContext->posix.pthread_attr_setschedparam = (ma_proc)ma_dlsym(pContext->posix.pthreadSO, "pthread_attr_setschedparam"); #else - pContext->posix.pthread_create = (mal_proc)pthread_create; - pContext->posix.pthread_join = (mal_proc)pthread_join; - pContext->posix.pthread_mutex_init = (mal_proc)pthread_mutex_init; - pContext->posix.pthread_mutex_destroy = (mal_proc)pthread_mutex_destroy; - pContext->posix.pthread_mutex_lock = (mal_proc)pthread_mutex_lock; - pContext->posix.pthread_mutex_unlock = (mal_proc)pthread_mutex_unlock; - pContext->posix.pthread_cond_init = (mal_proc)pthread_cond_init; - pContext->posix.pthread_cond_destroy = (mal_proc)pthread_cond_destroy; - pContext->posix.pthread_cond_wait = (mal_proc)pthread_cond_wait; - pContext->posix.pthread_cond_signal = (mal_proc)pthread_cond_signal; - pContext->posix.pthread_attr_init = (mal_proc)pthread_attr_init; - pContext->posix.pthread_attr_destroy = (mal_proc)pthread_attr_destroy; + pContext->posix.pthread_create = (ma_proc)pthread_create; + pContext->posix.pthread_join = (ma_proc)pthread_join; + pContext->posix.pthread_mutex_init = (ma_proc)pthread_mutex_init; + pContext->posix.pthread_mutex_destroy = (ma_proc)pthread_mutex_destroy; + pContext->posix.pthread_mutex_lock = (ma_proc)pthread_mutex_lock; + pContext->posix.pthread_mutex_unlock = (ma_proc)pthread_mutex_unlock; + pContext->posix.pthread_cond_init = (ma_proc)pthread_cond_init; + pContext->posix.pthread_cond_destroy = (ma_proc)pthread_cond_destroy; + pContext->posix.pthread_cond_wait = (ma_proc)pthread_cond_wait; + pContext->posix.pthread_cond_signal = (ma_proc)pthread_cond_signal; + pContext->posix.pthread_attr_init = (ma_proc)pthread_attr_init; + pContext->posix.pthread_attr_destroy = (ma_proc)pthread_attr_destroy; #if !defined(__EMSCRIPTEN__) - pContext->posix.pthread_attr_setschedpolicy = (mal_proc)pthread_attr_setschedpolicy; - pContext->posix.pthread_attr_getschedparam = (mal_proc)pthread_attr_getschedparam; - pContext->posix.pthread_attr_setschedparam = (mal_proc)pthread_attr_setschedparam; + pContext->posix.pthread_attr_setschedpolicy = (ma_proc)pthread_attr_setschedpolicy; + pContext->posix.pthread_attr_getschedparam = (ma_proc)pthread_attr_getschedparam; + pContext->posix.pthread_attr_setschedparam = (ma_proc)pthread_attr_setschedparam; #endif #endif @@ -22636,158 +22636,158 @@ mal_result mal_context_init_backend_apis__nix(mal_context* pContext) } #endif -mal_result mal_context_init_backend_apis(mal_context* pContext) +ma_result ma_context_init_backend_apis(ma_context* pContext) { - mal_result result; + ma_result result; #ifdef MA_WIN32 - result = mal_context_init_backend_apis__win32(pContext); + result = ma_context_init_backend_apis__win32(pContext); #else - result = mal_context_init_backend_apis__nix(pContext); + result = ma_context_init_backend_apis__nix(pContext); #endif return result; } -mal_result mal_context_uninit_backend_apis(mal_context* pContext) +ma_result ma_context_uninit_backend_apis(ma_context* pContext) { - mal_result result; + ma_result result; #ifdef MA_WIN32 - result = mal_context_uninit_backend_apis__win32(pContext); + result = ma_context_uninit_backend_apis__win32(pContext); #else - result = mal_context_uninit_backend_apis__nix(pContext); + result = ma_context_uninit_backend_apis__nix(pContext); #endif return result; } -mal_bool32 mal_context_is_backend_asynchronous(mal_context* pContext) +ma_bool32 ma_context_is_backend_asynchronous(ma_context* pContext) { return pContext->isBackendAsynchronous; } -mal_result mal_context_init(const mal_backend backends[], mal_uint32 backendCount, const mal_context_config* pConfig, mal_context* pContext) +ma_result ma_context_init(const ma_backend backends[], ma_uint32 backendCount, const ma_context_config* pConfig, ma_context* pContext) { if (pContext == NULL) { return MA_INVALID_ARGS; } - mal_zero_object(pContext); + ma_zero_object(pContext); // Always make sure the config is set first to ensure properties are available as soon as possible. if (pConfig != NULL) { pContext->config = *pConfig; } else { - pContext->config = mal_context_config_init(); + pContext->config = ma_context_config_init(); } // Backend APIs need to be initialized first. This is where external libraries will be loaded and linked. - mal_result result = mal_context_init_backend_apis(pContext); + ma_result result = ma_context_init_backend_apis(pContext); if (result != MA_SUCCESS) { return result; } - mal_backend defaultBackends[mal_backend_null+1]; - for (int i = 0; i <= mal_backend_null; ++i) { - defaultBackends[i] = (mal_backend)i; + ma_backend defaultBackends[ma_backend_null+1]; + for (int i = 0; i <= ma_backend_null; ++i) { + defaultBackends[i] = (ma_backend)i; } - mal_backend* pBackendsToIterate = (mal_backend*)backends; - mal_uint32 backendsToIterateCount = backendCount; + ma_backend* pBackendsToIterate = (ma_backend*)backends; + ma_uint32 backendsToIterateCount = backendCount; if (pBackendsToIterate == NULL) { - pBackendsToIterate = (mal_backend*)defaultBackends; - backendsToIterateCount = mal_countof(defaultBackends); + pBackendsToIterate = (ma_backend*)defaultBackends; + backendsToIterateCount = ma_countof(defaultBackends); } - mal_assert(pBackendsToIterate != NULL); + ma_assert(pBackendsToIterate != NULL); - for (mal_uint32 iBackend = 0; iBackend < backendsToIterateCount; ++iBackend) { - mal_backend backend = pBackendsToIterate[iBackend]; + for (ma_uint32 iBackend = 0; iBackend < backendsToIterateCount; ++iBackend) { + ma_backend backend = pBackendsToIterate[iBackend]; result = MA_NO_BACKEND; switch (backend) { #ifdef MA_HAS_WASAPI - case mal_backend_wasapi: + case ma_backend_wasapi: { - result = mal_context_init__wasapi(pContext); + result = ma_context_init__wasapi(pContext); } break; #endif #ifdef MA_HAS_DSOUND - case mal_backend_dsound: + case ma_backend_dsound: { - result = mal_context_init__dsound(pContext); + result = ma_context_init__dsound(pContext); } break; #endif #ifdef MA_HAS_WINMM - case mal_backend_winmm: + case ma_backend_winmm: { - result = mal_context_init__winmm(pContext); + result = ma_context_init__winmm(pContext); } break; #endif #ifdef MA_HAS_ALSA - case mal_backend_alsa: + case ma_backend_alsa: { - result = mal_context_init__alsa(pContext); + result = ma_context_init__alsa(pContext); } break; #endif #ifdef MA_HAS_PULSEAUDIO - case mal_backend_pulseaudio: + case ma_backend_pulseaudio: { - result = mal_context_init__pulse(pContext); + result = ma_context_init__pulse(pContext); } break; #endif #ifdef MA_HAS_JACK - case mal_backend_jack: + case ma_backend_jack: { - result = mal_context_init__jack(pContext); + result = ma_context_init__jack(pContext); } break; #endif #ifdef MA_HAS_COREAUDIO - case mal_backend_coreaudio: + case ma_backend_coreaudio: { - result = mal_context_init__coreaudio(pContext); + result = ma_context_init__coreaudio(pContext); } break; #endif #ifdef MA_HAS_SNDIO - case mal_backend_sndio: + case ma_backend_sndio: { - result = mal_context_init__sndio(pContext); + result = ma_context_init__sndio(pContext); } break; #endif #ifdef MA_HAS_AUDIO4 - case mal_backend_audio4: + case ma_backend_audio4: { - result = mal_context_init__audio4(pContext); + result = ma_context_init__audio4(pContext); } break; #endif #ifdef MA_HAS_OSS - case mal_backend_oss: + case ma_backend_oss: { - result = mal_context_init__oss(pContext); + result = ma_context_init__oss(pContext); } break; #endif #ifdef MA_HAS_AAUDIO - case mal_backend_aaudio: + case ma_backend_aaudio: { - result = mal_context_init__aaudio(pContext); + result = ma_context_init__aaudio(pContext); } break; #endif #ifdef MA_HAS_OPENSL - case mal_backend_opensl: + case ma_backend_opensl: { - result = mal_context_init__opensl(pContext); + result = ma_context_init__opensl(pContext); } break; #endif #ifdef MA_HAS_WEBAUDIO - case mal_backend_webaudio: + case ma_backend_webaudio: { - result = mal_context_init__webaudio(pContext); + result = ma_context_init__webaudio(pContext); } break; #endif #ifdef MA_HAS_NULL - case mal_backend_null: + case ma_backend_null: { - result = mal_context_init__null(pContext); + result = ma_context_init__null(pContext); } break; #endif @@ -22796,21 +22796,21 @@ mal_result mal_context_init(const mal_backend backends[], mal_uint32 backendCoun // If this iteration was successful, return. if (result == MA_SUCCESS) { - result = mal_mutex_init(pContext, &pContext->deviceEnumLock); + result = ma_mutex_init(pContext, &pContext->deviceEnumLock); if (result != MA_SUCCESS) { - mal_context_post_error(pContext, NULL, MA_LOG_LEVEL_WARNING, "Failed to initialize mutex for device enumeration. mal_context_get_devices() is not thread safe.", MA_FAILED_TO_CREATE_MUTEX); + ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_WARNING, "Failed to initialize mutex for device enumeration. ma_context_get_devices() is not thread safe.", MA_FAILED_TO_CREATE_MUTEX); } - result = mal_mutex_init(pContext, &pContext->deviceInfoLock); + result = ma_mutex_init(pContext, &pContext->deviceInfoLock); if (result != MA_SUCCESS) { - mal_context_post_error(pContext, NULL, MA_LOG_LEVEL_WARNING, "Failed to initialize mutex for device info retrieval. mal_context_get_device_info() is not thread safe.", MA_FAILED_TO_CREATE_MUTEX); + ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_WARNING, "Failed to initialize mutex for device info retrieval. ma_context_get_device_info() is not thread safe.", MA_FAILED_TO_CREATE_MUTEX); } #ifdef MA_DEBUG_OUTPUT - printf("[miniaudio] Endian: %s\n", mal_is_little_endian() ? "LE" : "BE"); - printf("[miniaudio] SSE2: %s\n", mal_has_sse2() ? "YES" : "NO"); - printf("[miniaudio] AVX2: %s\n", mal_has_avx2() ? "YES" : "NO"); - printf("[miniaudio] AVX512F: %s\n", mal_has_avx512f() ? "YES" : "NO"); - printf("[miniaudio] NEON: %s\n", mal_has_neon() ? "YES" : "NO"); + printf("[miniaudio] Endian: %s\n", ma_is_little_endian() ? "LE" : "BE"); + printf("[miniaudio] SSE2: %s\n", ma_has_sse2() ? "YES" : "NO"); + printf("[miniaudio] AVX2: %s\n", ma_has_avx2() ? "YES" : "NO"); + printf("[miniaudio] AVX512F: %s\n", ma_has_avx512f() ? "YES" : "NO"); + printf("[miniaudio] NEON: %s\n", ma_has_neon() ? "YES" : "NO"); #endif pContext->backend = backend; @@ -22819,11 +22819,11 @@ mal_result mal_context_init(const mal_backend backends[], mal_uint32 backendCoun } // If we get here it means an error occurred. - mal_zero_object(pContext); // Safety. + ma_zero_object(pContext); // Safety. return MA_NO_BACKEND; } -mal_result mal_context_uninit(mal_context* pContext) +ma_result ma_context_uninit(ma_context* pContext) { if (pContext == NULL) { return MA_INVALID_ARGS; @@ -22831,33 +22831,33 @@ mal_result mal_context_uninit(mal_context* pContext) pContext->onUninit(pContext); - mal_context_uninit_backend_apis(pContext); - mal_mutex_uninit(&pContext->deviceEnumLock); - mal_mutex_uninit(&pContext->deviceInfoLock); - mal_free(pContext->pDeviceInfos); + ma_context_uninit_backend_apis(pContext); + ma_mutex_uninit(&pContext->deviceEnumLock); + ma_mutex_uninit(&pContext->deviceInfoLock); + ma_free(pContext->pDeviceInfos); return MA_SUCCESS; } -mal_result mal_context_enumerate_devices(mal_context* pContext, mal_enum_devices_callback_proc callback, void* pUserData) +ma_result ma_context_enumerate_devices(ma_context* pContext, ma_enum_devices_callback_proc callback, void* pUserData) { if (pContext == NULL || pContext->onEnumDevices == NULL || callback == NULL) { return MA_INVALID_ARGS; } - mal_result result; - mal_mutex_lock(&pContext->deviceEnumLock); + ma_result result; + ma_mutex_lock(&pContext->deviceEnumLock); { result = pContext->onEnumDevices(pContext, callback, pUserData); } - mal_mutex_unlock(&pContext->deviceEnumLock); + ma_mutex_unlock(&pContext->deviceEnumLock); return result; } -mal_bool32 mal_context_get_devices__enum_callback(mal_context* pContext, mal_device_type deviceType, const mal_device_info* pInfo, void* pUserData) +ma_bool32 ma_context_get_devices__enum_callback(ma_context* pContext, ma_device_type deviceType, const ma_device_info* pInfo, void* pUserData) { (void)pUserData; @@ -22866,12 +22866,12 @@ mal_bool32 mal_context_get_devices__enum_callback(mal_context* pContext, mal_dev // First make sure we have room. Since the number of devices we add to the list is usually relatively small I've decided to use a // simple fixed size increment for buffer expansion. - const mal_uint32 bufferExpansionCount = 2; - const mal_uint32 totalDeviceInfoCount = pContext->playbackDeviceInfoCount + pContext->captureDeviceInfoCount; + const ma_uint32 bufferExpansionCount = 2; + const ma_uint32 totalDeviceInfoCount = pContext->playbackDeviceInfoCount + pContext->captureDeviceInfoCount; if (pContext->deviceInfoCapacity >= totalDeviceInfoCount) { - mal_uint32 newCapacity = totalDeviceInfoCount + bufferExpansionCount; - mal_device_info* pNewInfos = (mal_device_info*)mal_realloc(pContext->pDeviceInfos, sizeof(*pContext->pDeviceInfos)*newCapacity); + ma_uint32 newCapacity = totalDeviceInfoCount + bufferExpansionCount; + ma_device_info* pNewInfos = (ma_device_info*)ma_realloc(pContext->pDeviceInfos, sizeof(*pContext->pDeviceInfos)*newCapacity); if (pNewInfos == NULL) { return MA_FALSE; // Out of memory. } @@ -22880,11 +22880,11 @@ mal_bool32 mal_context_get_devices__enum_callback(mal_context* pContext, mal_dev pContext->deviceInfoCapacity = newCapacity; } - if (deviceType == mal_device_type_playback) { + if (deviceType == ma_device_type_playback) { // Playback. Insert just before the first capture device. // The first thing to do is move all of the capture devices down a slot. - mal_uint32 iFirstCaptureDevice = pContext->playbackDeviceInfoCount; + ma_uint32 iFirstCaptureDevice = pContext->playbackDeviceInfoCount; for (size_t iCaptureDevice = totalDeviceInfoCount; iCaptureDevice > iFirstCaptureDevice; --iCaptureDevice) { pContext->pDeviceInfos[iCaptureDevice] = pContext->pDeviceInfos[iCaptureDevice-1]; } @@ -22901,7 +22901,7 @@ mal_bool32 mal_context_get_devices__enum_callback(mal_context* pContext, mal_dev return MA_TRUE; } -mal_result mal_context_get_devices(mal_context* pContext, mal_device_info** ppPlaybackDeviceInfos, mal_uint32* pPlaybackDeviceCount, mal_device_info** ppCaptureDeviceInfos, mal_uint32* pCaptureDeviceCount) +ma_result ma_context_get_devices(ma_context* pContext, ma_device_info** ppPlaybackDeviceInfos, ma_uint32* pPlaybackDeviceCount, ma_device_info** ppCaptureDeviceInfos, ma_uint32* pCaptureDeviceCount) { // Safety. if (ppPlaybackDeviceInfos != NULL) *ppPlaybackDeviceInfos = NULL; @@ -22913,16 +22913,16 @@ mal_result mal_context_get_devices(mal_context* pContext, mal_device_info** ppPl return MA_INVALID_ARGS; } - // Note that we don't use mal_context_enumerate_devices() here because we want to do locking at a higher level. - mal_result result; - mal_mutex_lock(&pContext->deviceEnumLock); + // Note that we don't use ma_context_enumerate_devices() here because we want to do locking at a higher level. + ma_result result; + ma_mutex_lock(&pContext->deviceEnumLock); { // Reset everything first. pContext->playbackDeviceInfoCount = 0; pContext->captureDeviceInfoCount = 0; // Now enumerate over available devices. - result = pContext->onEnumDevices(pContext, mal_context_get_devices__enum_callback, NULL); + result = pContext->onEnumDevices(pContext, ma_context_get_devices__enum_callback, NULL); if (result == MA_SUCCESS) { // Playback devices. if (ppPlaybackDeviceInfos != NULL) { @@ -22941,40 +22941,40 @@ mal_result mal_context_get_devices(mal_context* pContext, mal_device_info** ppPl } } } - mal_mutex_unlock(&pContext->deviceEnumLock); + ma_mutex_unlock(&pContext->deviceEnumLock); return result; } -mal_result mal_context_get_device_info(mal_context* pContext, mal_device_type deviceType, const mal_device_id* pDeviceID, mal_share_mode shareMode, mal_device_info* pDeviceInfo) +ma_result ma_context_get_device_info(ma_context* pContext, ma_device_type deviceType, const ma_device_id* pDeviceID, ma_share_mode shareMode, ma_device_info* pDeviceInfo) { // NOTE: Do not clear pDeviceInfo on entry. The reason is the pDeviceID may actually point to pDeviceInfo->id which will break things. if (pContext == NULL || pDeviceInfo == NULL) { return MA_INVALID_ARGS; } - mal_device_info deviceInfo; - mal_zero_object(&deviceInfo); + ma_device_info deviceInfo; + ma_zero_object(&deviceInfo); // Help the backend out by copying over the device ID if we have one. if (pDeviceID != NULL) { - mal_copy_memory(&deviceInfo.id, pDeviceID, sizeof(*pDeviceID)); + ma_copy_memory(&deviceInfo.id, pDeviceID, sizeof(*pDeviceID)); } // The backend may have an optimized device info retrieval function. If so, try that first. if (pContext->onGetDeviceInfo != NULL) { - mal_result result; - mal_mutex_lock(&pContext->deviceInfoLock); + ma_result result; + ma_mutex_lock(&pContext->deviceInfoLock); { result = pContext->onGetDeviceInfo(pContext, deviceType, pDeviceID, shareMode, &deviceInfo); } - mal_mutex_unlock(&pContext->deviceInfoLock); + ma_mutex_unlock(&pContext->deviceInfoLock); // Clamp ranges. - deviceInfo.minChannels = mal_max(deviceInfo.minChannels, MA_MIN_CHANNELS); - deviceInfo.maxChannels = mal_min(deviceInfo.maxChannels, MA_MAX_CHANNELS); - deviceInfo.minSampleRate = mal_max(deviceInfo.minSampleRate, MA_MIN_SAMPLE_RATE); - deviceInfo.maxSampleRate = mal_min(deviceInfo.maxSampleRate, MA_MAX_SAMPLE_RATE); + deviceInfo.minChannels = ma_max(deviceInfo.minChannels, MA_MIN_CHANNELS); + deviceInfo.maxChannels = ma_min(deviceInfo.maxChannels, MA_MAX_CHANNELS); + deviceInfo.minSampleRate = ma_max(deviceInfo.minSampleRate, MA_MIN_SAMPLE_RATE); + deviceInfo.maxSampleRate = ma_min(deviceInfo.maxSampleRate, MA_MAX_SAMPLE_RATE); *pDeviceInfo = deviceInfo; return result; @@ -22985,46 +22985,46 @@ mal_result mal_context_get_device_info(mal_context* pContext, mal_device_type de } -mal_result mal_device_init(mal_context* pContext, const mal_device_config* pConfig, mal_device* pDevice) +ma_result ma_device_init(ma_context* pContext, const ma_device_config* pConfig, ma_device* pDevice) { if (pContext == NULL) { - return mal_device_init_ex(NULL, 0, NULL, pConfig, pDevice); + return ma_device_init_ex(NULL, 0, NULL, pConfig, pDevice); } if (pDevice == NULL) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "mal_device_init() called with invalid arguments (pDevice == NULL).", MA_INVALID_ARGS); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "ma_device_init() called with invalid arguments (pDevice == NULL).", MA_INVALID_ARGS); } if (pConfig == NULL) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "mal_device_init() called with invalid arguments (pConfig == NULL).", MA_INVALID_ARGS); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "ma_device_init() called with invalid arguments (pConfig == NULL).", MA_INVALID_ARGS); } /* We need to make a copy of the config so we can set default values if they were left unset in the input config. */ - mal_device_config config = *pConfig; + ma_device_config config = *pConfig; /* Basic config validation. */ - if (config.deviceType != mal_device_type_playback && config.deviceType != mal_device_type_capture && config.deviceType != mal_device_type_duplex) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "mal_device_init() called with an invalid config. Device type is invalid. Make sure the device type has been set in the config.", MA_INVALID_DEVICE_CONFIG); + if (config.deviceType != ma_device_type_playback && config.deviceType != ma_device_type_capture && config.deviceType != ma_device_type_duplex) { + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "ma_device_init() called with an invalid config. Device type is invalid. Make sure the device type has been set in the config.", MA_INVALID_DEVICE_CONFIG); } - if (config.deviceType == mal_device_type_capture || config.deviceType == mal_device_type_duplex) { + if (config.deviceType == ma_device_type_capture || config.deviceType == ma_device_type_duplex) { if (config.capture.channels > MA_MAX_CHANNELS) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "mal_device_init() called with an invalid config. Capture channel count cannot exceed 32.", MA_INVALID_DEVICE_CONFIG); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "ma_device_init() called with an invalid config. Capture channel count cannot exceed 32.", MA_INVALID_DEVICE_CONFIG); } - if (!mal__is_channel_map_valid(config.capture.channelMap, config.capture.channels)) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "mal_device_init() called with invalid config. Capture channel map is invalid.", MA_INVALID_DEVICE_CONFIG); + if (!ma__is_channel_map_valid(config.capture.channelMap, config.capture.channels)) { + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "ma_device_init() called with invalid config. Capture channel map is invalid.", MA_INVALID_DEVICE_CONFIG); } } - if (config.deviceType == mal_device_type_playback || config.deviceType == mal_device_type_duplex) { + if (config.deviceType == ma_device_type_playback || config.deviceType == ma_device_type_duplex) { if (config.playback.channels > MA_MAX_CHANNELS) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "mal_device_init() called with an invalid config. Playback channel count cannot exceed 32.", MA_INVALID_DEVICE_CONFIG); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "ma_device_init() called with an invalid config. Playback channel count cannot exceed 32.", MA_INVALID_DEVICE_CONFIG); } - if (!mal__is_channel_map_valid(config.playback.channelMap, config.playback.channels)) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "mal_device_init() called with invalid config. Playback channel map is invalid.", MA_INVALID_DEVICE_CONFIG); + if (!ma__is_channel_map_valid(config.playback.channelMap, config.playback.channels)) { + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "ma_device_init() called with invalid config. Playback channel map is invalid.", MA_INVALID_DEVICE_CONFIG); } } - mal_zero_object(pDevice); + ma_zero_object(pDevice); pDevice->pContext = pContext; // Set the user data and log callback ASAP to ensure it is available for the entire initialization process. @@ -23032,9 +23032,9 @@ mal_result mal_device_init(mal_context* pContext, const mal_device_config* pConf pDevice->onData = config.dataCallback; pDevice->onStop = config.stopCallback; - if (((mal_uintptr)pDevice % sizeof(pDevice)) != 0) { + if (((ma_uintptr)pDevice % sizeof(pDevice)) != 0) { if (pContext->config.logCallback) { - pContext->config.logCallback(pContext, pDevice, MA_LOG_LEVEL_WARNING, "WARNING: mal_device_init() called for a device that is not properly aligned. Thread safety is not supported."); + pContext->config.logCallback(pContext, pDevice, MA_LOG_LEVEL_WARNING, "WARNING: ma_device_init() called for a device that is not properly aligned. Thread safety is not supported."); } } @@ -23045,7 +23045,7 @@ mal_result mal_device_init(mal_context* pContext, const mal_device_config* pConf pDevice->usingDefaultSampleRate = MA_TRUE; } - if (config.capture.format == mal_format_unknown) { + if (config.capture.format == ma_format_unknown) { config.capture.format = MA_DEFAULT_FORMAT; pDevice->capture.usingDefaultFormat = MA_TRUE; } @@ -23057,7 +23057,7 @@ mal_result mal_device_init(mal_context* pContext, const mal_device_config* pConf pDevice->capture.usingDefaultChannelMap = MA_TRUE; } - if (config.playback.format == mal_format_unknown) { + if (config.playback.format == ma_format_unknown) { config.playback.format = MA_DEFAULT_FORMAT; pDevice->playback.usingDefaultFormat = MA_TRUE; } @@ -23072,7 +23072,7 @@ mal_result mal_device_init(mal_context* pContext, const mal_device_config* pConf // Default buffer size. if (config.bufferSizeInMilliseconds == 0 && config.bufferSizeInFrames == 0) { - config.bufferSizeInMilliseconds = (config.performanceProfile == mal_performance_profile_low_latency) ? MA_BASE_BUFFER_SIZE_IN_MILLISECONDS_LOW_LATENCY : MA_BASE_BUFFER_SIZE_IN_MILLISECONDS_CONSERVATIVE; + config.bufferSizeInMilliseconds = (config.performanceProfile == ma_performance_profile_low_latency) ? MA_BASE_BUFFER_SIZE_IN_MILLISECONDS_LOW_LATENCY : MA_BASE_BUFFER_SIZE_IN_MILLISECONDS_CONSERVATIVE; pDevice->usingDefaultBufferSize = MA_TRUE; } @@ -23086,7 +23086,7 @@ mal_result mal_device_init(mal_context* pContext, const mal_device_config* pConf Must have at least 3 periods for full-duplex mode. The idea is that the playback and capture positions hang out in the middle period, with the surrounding periods acting as a buffer in case the capture and playback devices get's slightly out of sync. */ - if (config.deviceType == mal_device_type_duplex && config.periods < 3) { + if (config.deviceType == ma_device_type_duplex && config.periods < 3) { config.periods = 3; } @@ -23097,28 +23097,28 @@ mal_result mal_device_init(mal_context* pContext, const mal_device_config* pConf pDevice->capture.shareMode = config.capture.shareMode; pDevice->capture.format = config.capture.format; pDevice->capture.channels = config.capture.channels; - mal_channel_map_copy(pDevice->capture.channelMap, config.capture.channelMap, config.capture.channels); + ma_channel_map_copy(pDevice->capture.channelMap, config.capture.channelMap, config.capture.channels); pDevice->playback.shareMode = config.playback.shareMode; pDevice->playback.format = config.playback.format; pDevice->playback.channels = config.playback.channels; - mal_channel_map_copy(pDevice->playback.channelMap, config.playback.channelMap, config.playback.channels); + ma_channel_map_copy(pDevice->playback.channelMap, config.playback.channelMap, config.playback.channels); // The internal format, channel count and sample rate can be modified by the backend. pDevice->capture.internalFormat = pDevice->capture.format; pDevice->capture.internalChannels = pDevice->capture.channels; pDevice->capture.internalSampleRate = pDevice->sampleRate; - mal_channel_map_copy(pDevice->capture.internalChannelMap, pDevice->capture.channelMap, pDevice->capture.channels); + ma_channel_map_copy(pDevice->capture.internalChannelMap, pDevice->capture.channelMap, pDevice->capture.channels); pDevice->playback.internalFormat = pDevice->playback.format; pDevice->playback.internalChannels = pDevice->playback.channels; pDevice->playback.internalSampleRate = pDevice->sampleRate; - mal_channel_map_copy(pDevice->playback.internalChannelMap, pDevice->playback.channelMap, pDevice->playback.channels); + ma_channel_map_copy(pDevice->playback.internalChannelMap, pDevice->playback.channelMap, pDevice->playback.channels); - if (mal_mutex_init(pContext, &pDevice->lock) != MA_SUCCESS) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "Failed to create mutex.", MA_FAILED_TO_CREATE_MUTEX); + if (ma_mutex_init(pContext, &pDevice->lock) != MA_SUCCESS) { + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "Failed to create mutex.", MA_FAILED_TO_CREATE_MUTEX); } // When the device is started, the worker thread is the one that does the actual startup of the backend device. We @@ -23126,68 +23126,68 @@ mal_result mal_device_init(mal_context* pContext, const mal_device_config* pConf // // Each of these semaphores is released internally by the worker thread when the work is completed. The start // semaphore is also used to wake up the worker thread. - if (mal_event_init(pContext, &pDevice->wakeupEvent) != MA_SUCCESS) { - mal_mutex_uninit(&pDevice->lock); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "Failed to create worker thread wakeup event.", MA_FAILED_TO_CREATE_EVENT); + if (ma_event_init(pContext, &pDevice->wakeupEvent) != MA_SUCCESS) { + ma_mutex_uninit(&pDevice->lock); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "Failed to create worker thread wakeup event.", MA_FAILED_TO_CREATE_EVENT); } - if (mal_event_init(pContext, &pDevice->startEvent) != MA_SUCCESS) { - mal_event_uninit(&pDevice->wakeupEvent); - mal_mutex_uninit(&pDevice->lock); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "Failed to create worker thread start event.", MA_FAILED_TO_CREATE_EVENT); + if (ma_event_init(pContext, &pDevice->startEvent) != MA_SUCCESS) { + ma_event_uninit(&pDevice->wakeupEvent); + ma_mutex_uninit(&pDevice->lock); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "Failed to create worker thread start event.", MA_FAILED_TO_CREATE_EVENT); } - if (mal_event_init(pContext, &pDevice->stopEvent) != MA_SUCCESS) { - mal_event_uninit(&pDevice->startEvent); - mal_event_uninit(&pDevice->wakeupEvent); - mal_mutex_uninit(&pDevice->lock); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "Failed to create worker thread stop event.", MA_FAILED_TO_CREATE_EVENT); + if (ma_event_init(pContext, &pDevice->stopEvent) != MA_SUCCESS) { + ma_event_uninit(&pDevice->startEvent); + ma_event_uninit(&pDevice->wakeupEvent); + ma_mutex_uninit(&pDevice->lock); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "Failed to create worker thread stop event.", MA_FAILED_TO_CREATE_EVENT); } - mal_result result = pContext->onDeviceInit(pContext, &config, pDevice); + ma_result result = pContext->onDeviceInit(pContext, &config, pDevice); if (result != MA_SUCCESS) { - return MA_NO_BACKEND; // The error message will have been posted with mal_post_error() by the source of the error so don't bother calling it here. + return MA_NO_BACKEND; // The error message will have been posted with ma_post_error() by the source of the error so don't bother calling it here. } - mal_device__post_init_setup(pDevice, pConfig->deviceType); + ma_device__post_init_setup(pDevice, pConfig->deviceType); // If the backend did not fill out a name for the device, try a generic method. - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { if (pDevice->capture.name[0] == '\0') { - if (mal_context__try_get_device_name_by_id(pContext, mal_device_type_capture, config.capture.pDeviceID, pDevice->capture.name, sizeof(pDevice->capture.name)) != MA_SUCCESS) { - mal_strncpy_s(pDevice->capture.name, sizeof(pDevice->capture.name), (config.capture.pDeviceID == NULL) ? MA_DEFAULT_CAPTURE_DEVICE_NAME : "Capture Device", (size_t)-1); + if (ma_context__try_get_device_name_by_id(pContext, ma_device_type_capture, config.capture.pDeviceID, pDevice->capture.name, sizeof(pDevice->capture.name)) != MA_SUCCESS) { + ma_strncpy_s(pDevice->capture.name, sizeof(pDevice->capture.name), (config.capture.pDeviceID == NULL) ? MA_DEFAULT_CAPTURE_DEVICE_NAME : "Capture Device", (size_t)-1); } } } - if (pDevice->type == mal_device_type_playback || pDevice->type == mal_device_type_duplex) { + if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) { if (pDevice->playback.name[0] == '\0') { - if (mal_context__try_get_device_name_by_id(pContext, mal_device_type_playback, config.playback.pDeviceID, pDevice->playback.name, sizeof(pDevice->playback.name)) != MA_SUCCESS) { - mal_strncpy_s(pDevice->playback.name, sizeof(pDevice->playback.name), (config.playback.pDeviceID == NULL) ? MA_DEFAULT_PLAYBACK_DEVICE_NAME : "Playback Device", (size_t)-1); + if (ma_context__try_get_device_name_by_id(pContext, ma_device_type_playback, config.playback.pDeviceID, pDevice->playback.name, sizeof(pDevice->playback.name)) != MA_SUCCESS) { + ma_strncpy_s(pDevice->playback.name, sizeof(pDevice->playback.name), (config.playback.pDeviceID == NULL) ? MA_DEFAULT_PLAYBACK_DEVICE_NAME : "Playback Device", (size_t)-1); } } } // Some backends don't require the worker thread. - if (!mal_context_is_backend_asynchronous(pContext)) { + if (!ma_context_is_backend_asynchronous(pContext)) { // The worker thread. - if (mal_thread_create(pContext, &pDevice->thread, mal_worker_thread, pDevice) != MA_SUCCESS) { - mal_device_uninit(pDevice); - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "Failed to create worker thread.", MA_FAILED_TO_CREATE_THREAD); + if (ma_thread_create(pContext, &pDevice->thread, ma_worker_thread, pDevice) != MA_SUCCESS) { + ma_device_uninit(pDevice); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "Failed to create worker thread.", MA_FAILED_TO_CREATE_THREAD); } // Wait for the worker thread to put the device into it's stopped state for real. - mal_event_wait(&pDevice->stopEvent); + ma_event_wait(&pDevice->stopEvent); } else { - mal_device__set_state(pDevice, MA_STATE_STOPPED); + ma_device__set_state(pDevice, MA_STATE_STOPPED); } #ifdef MA_DEBUG_OUTPUT - printf("[%s]\n", mal_get_backend_name(pDevice->pContext->backend)); - if (pDevice->type == mal_device_type_capture || pDevice->type == mal_device_type_duplex) { + printf("[%s]\n", ma_get_backend_name(pDevice->pContext->backend)); + if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) { printf(" %s (%s)\n", pDevice->capture.name, "Capture"); - printf(" Format: %s -> %s\n", mal_get_format_name(pDevice->capture.format), mal_get_format_name(pDevice->capture.internalFormat)); + printf(" Format: %s -> %s\n", ma_get_format_name(pDevice->capture.format), ma_get_format_name(pDevice->capture.internalFormat)); printf(" Channels: %d -> %d\n", pDevice->capture.channels, pDevice->capture.internalChannels); printf(" Sample Rate: %d -> %d\n", pDevice->sampleRate, pDevice->capture.internalSampleRate); printf(" Buffer Size: %d/%d (%d)\n", pDevice->capture.internalBufferSizeInFrames, pDevice->capture.internalPeriods, (pDevice->capture.internalBufferSizeInFrames / pDevice->capture.internalPeriods)); @@ -23199,9 +23199,9 @@ mal_result mal_device_init(mal_context* pContext, const mal_device_config* pConf printf(" Channel Routing at Start: %s\n", pDevice->capture.converter.isChannelRoutingAtStart ? "YES" : "NO"); printf(" Passthrough: %s\n", pDevice->capture.converter.isPassthrough ? "YES" : "NO"); } - if (pDevice->type == mal_device_type_playback || pDevice->type == mal_device_type_duplex) { + if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) { printf(" %s (%s)\n", pDevice->playback.name, "Playback"); - printf(" Format: %s -> %s\n", mal_get_format_name(pDevice->playback.format), mal_get_format_name(pDevice->playback.internalFormat)); + printf(" Format: %s -> %s\n", ma_get_format_name(pDevice->playback.format), ma_get_format_name(pDevice->playback.internalFormat)); printf(" Channels: %d -> %d\n", pDevice->playback.channels, pDevice->playback.internalChannels); printf(" Sample Rate: %d -> %d\n", pDevice->sampleRate, pDevice->playback.internalSampleRate); printf(" Buffer Size: %d/%d (%d)\n", pDevice->playback.internalBufferSizeInFrames, pDevice->playback.internalPeriods, (pDevice->playback.internalBufferSizeInFrames / pDevice->playback.internalPeriods)); @@ -23216,49 +23216,49 @@ mal_result mal_device_init(mal_context* pContext, const mal_device_config* pConf #endif - mal_assert(mal_device__get_state(pDevice) == MA_STATE_STOPPED); + ma_assert(ma_device__get_state(pDevice) == MA_STATE_STOPPED); return MA_SUCCESS; } -mal_result mal_device_init_ex(const mal_backend backends[], mal_uint32 backendCount, const mal_context_config* pContextConfig, const mal_device_config* pConfig, mal_device* pDevice) +ma_result ma_device_init_ex(const ma_backend backends[], ma_uint32 backendCount, const ma_context_config* pContextConfig, const ma_device_config* pConfig, ma_device* pDevice) { if (pConfig == NULL) { return MA_INVALID_ARGS; } - mal_context* pContext = (mal_context*)mal_malloc(sizeof(*pContext)); + ma_context* pContext = (ma_context*)ma_malloc(sizeof(*pContext)); if (pContext == NULL) { return MA_OUT_OF_MEMORY; } - mal_backend defaultBackends[mal_backend_null+1]; - for (int i = 0; i <= mal_backend_null; ++i) { - defaultBackends[i] = (mal_backend)i; + ma_backend defaultBackends[ma_backend_null+1]; + for (int i = 0; i <= ma_backend_null; ++i) { + defaultBackends[i] = (ma_backend)i; } - mal_backend* pBackendsToIterate = (mal_backend*)backends; - mal_uint32 backendsToIterateCount = backendCount; + ma_backend* pBackendsToIterate = (ma_backend*)backends; + ma_uint32 backendsToIterateCount = backendCount; if (pBackendsToIterate == NULL) { - pBackendsToIterate = (mal_backend*)defaultBackends; - backendsToIterateCount = mal_countof(defaultBackends); + pBackendsToIterate = (ma_backend*)defaultBackends; + backendsToIterateCount = ma_countof(defaultBackends); } - mal_result result = MA_NO_BACKEND; + ma_result result = MA_NO_BACKEND; - for (mal_uint32 iBackend = 0; iBackend < backendsToIterateCount; ++iBackend) { - result = mal_context_init(&pBackendsToIterate[iBackend], 1, pContextConfig, pContext); + for (ma_uint32 iBackend = 0; iBackend < backendsToIterateCount; ++iBackend) { + result = ma_context_init(&pBackendsToIterate[iBackend], 1, pContextConfig, pContext); if (result == MA_SUCCESS) { - result = mal_device_init(pContext, pConfig, pDevice); + result = ma_device_init(pContext, pConfig, pDevice); if (result == MA_SUCCESS) { break; // Success. } else { - mal_context_uninit(pContext); // Failure. + ma_context_uninit(pContext); // Failure. } } } if (result != MA_SUCCESS) { - mal_free(pContext); + ma_free(pContext); return result; } @@ -23266,169 +23266,169 @@ mal_result mal_device_init_ex(const mal_backend backends[], mal_uint32 backendCo return result; } -void mal_device_uninit(mal_device* pDevice) +void ma_device_uninit(ma_device* pDevice) { - if (!mal_device__is_initialized(pDevice)) { + if (!ma_device__is_initialized(pDevice)) { return; } // Make sure the device is stopped first. The backends will probably handle this naturally, // but I like to do it explicitly for my own sanity. - if (mal_device_is_started(pDevice)) { - mal_device_stop(pDevice); + if (ma_device_is_started(pDevice)) { + ma_device_stop(pDevice); } // Putting the device into an uninitialized state will make the worker thread return. - mal_device__set_state(pDevice, MA_STATE_UNINITIALIZED); + ma_device__set_state(pDevice, MA_STATE_UNINITIALIZED); // Wake up the worker thread and wait for it to properly terminate. - if (!mal_context_is_backend_asynchronous(pDevice->pContext)) { - mal_event_signal(&pDevice->wakeupEvent); - mal_thread_wait(&pDevice->thread); + if (!ma_context_is_backend_asynchronous(pDevice->pContext)) { + ma_event_signal(&pDevice->wakeupEvent); + ma_thread_wait(&pDevice->thread); } pDevice->pContext->onDeviceUninit(pDevice); - mal_event_uninit(&pDevice->stopEvent); - mal_event_uninit(&pDevice->startEvent); - mal_event_uninit(&pDevice->wakeupEvent); - mal_mutex_uninit(&pDevice->lock); + ma_event_uninit(&pDevice->stopEvent); + ma_event_uninit(&pDevice->startEvent); + ma_event_uninit(&pDevice->wakeupEvent); + ma_mutex_uninit(&pDevice->lock); if (pDevice->isOwnerOfContext) { - mal_context_uninit(pDevice->pContext); - mal_free(pDevice->pContext); + ma_context_uninit(pDevice->pContext); + ma_free(pDevice->pContext); } - mal_zero_object(pDevice); + ma_zero_object(pDevice); } -void mal_device_set_stop_callback(mal_device* pDevice, mal_stop_proc proc) +void ma_device_set_stop_callback(ma_device* pDevice, ma_stop_proc proc) { if (pDevice == NULL) return; - mal_atomic_exchange_ptr(&pDevice->onStop, proc); + ma_atomic_exchange_ptr(&pDevice->onStop, proc); } -mal_result mal_device_start(mal_device* pDevice) +ma_result ma_device_start(ma_device* pDevice) { if (pDevice == NULL) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "mal_device_start() called with invalid arguments (pDevice == NULL).", MA_INVALID_ARGS); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "ma_device_start() called with invalid arguments (pDevice == NULL).", MA_INVALID_ARGS); } - if (mal_device__get_state(pDevice) == MA_STATE_UNINITIALIZED) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "mal_device_start() called for an uninitialized device.", MA_DEVICE_NOT_INITIALIZED); + if (ma_device__get_state(pDevice) == MA_STATE_UNINITIALIZED) { + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "ma_device_start() called for an uninitialized device.", MA_DEVICE_NOT_INITIALIZED); } /* Starting the device doesn't do anything in synchronous mode because in that case it's started automatically with - mal_device_write() and mal_device_read(). It's best to return an error so that the application can be aware that + ma_device_write() and ma_device_read(). It's best to return an error so that the application can be aware that it's not doing it right. */ - if (!mal_device__is_async(pDevice)) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "mal_device_start() called in synchronous mode. This should only be used in asynchronous/callback mode.", MA_DEVICE_NOT_INITIALIZED); + if (!ma_device__is_async(pDevice)) { + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "ma_device_start() called in synchronous mode. This should only be used in asynchronous/callback mode.", MA_DEVICE_NOT_INITIALIZED); } - mal_result result = MA_ERROR; - mal_mutex_lock(&pDevice->lock); + ma_result result = MA_ERROR; + ma_mutex_lock(&pDevice->lock); { // Starting and stopping are wrapped in a mutex which means we can assert that the device is in a stopped or paused state. - mal_assert(mal_device__get_state(pDevice) == MA_STATE_STOPPED); + ma_assert(ma_device__get_state(pDevice) == MA_STATE_STOPPED); - mal_device__set_state(pDevice, MA_STATE_STARTING); + ma_device__set_state(pDevice, MA_STATE_STARTING); // Asynchronous backends need to be handled differently. - if (mal_context_is_backend_asynchronous(pDevice->pContext)) { + if (ma_context_is_backend_asynchronous(pDevice->pContext)) { result = pDevice->pContext->onDeviceStart(pDevice); if (result == MA_SUCCESS) { - mal_device__set_state(pDevice, MA_STATE_STARTED); + ma_device__set_state(pDevice, MA_STATE_STARTED); } } else { // Synchronous backends are started by signaling an event that's being waited on in the worker thread. We first wake up the // thread and then wait for the start event. - mal_event_signal(&pDevice->wakeupEvent); + ma_event_signal(&pDevice->wakeupEvent); // Wait for the worker thread to finish starting the device. Note that the worker thread will be the one - // who puts the device into the started state. Don't call mal_device__set_state() here. - mal_event_wait(&pDevice->startEvent); + // who puts the device into the started state. Don't call ma_device__set_state() here. + ma_event_wait(&pDevice->startEvent); result = pDevice->workResult; } } - mal_mutex_unlock(&pDevice->lock); + ma_mutex_unlock(&pDevice->lock); return result; } -mal_result mal_device_stop(mal_device* pDevice) +ma_result ma_device_stop(ma_device* pDevice) { if (pDevice == NULL) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "mal_device_stop() called with invalid arguments (pDevice == NULL).", MA_INVALID_ARGS); + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "ma_device_stop() called with invalid arguments (pDevice == NULL).", MA_INVALID_ARGS); } - if (mal_device__get_state(pDevice) == MA_STATE_UNINITIALIZED) { - return mal_post_error(pDevice, MA_LOG_LEVEL_ERROR, "mal_device_stop() called for an uninitialized device.", MA_DEVICE_NOT_INITIALIZED); + if (ma_device__get_state(pDevice) == MA_STATE_UNINITIALIZED) { + return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "ma_device_stop() called for an uninitialized device.", MA_DEVICE_NOT_INITIALIZED); } /* Stopping is slightly different for synchronous mode. In this case it just tells the driver to stop the internal processing of the device. Also, stopping in synchronous mode does not require state checking. */ - if (!mal_device__is_async(pDevice)) { + if (!ma_device__is_async(pDevice)) { if (pDevice->pContext->onDeviceStop) { return pDevice->pContext->onDeviceStop(pDevice); } } - mal_result result = MA_ERROR; - mal_mutex_lock(&pDevice->lock); + ma_result result = MA_ERROR; + ma_mutex_lock(&pDevice->lock); { // Starting and stopping are wrapped in a mutex which means we can assert that the device is in a started or paused state. - mal_assert(mal_device__get_state(pDevice) == MA_STATE_STARTED); + ma_assert(ma_device__get_state(pDevice) == MA_STATE_STARTED); - mal_device__set_state(pDevice, MA_STATE_STOPPING); + ma_device__set_state(pDevice, MA_STATE_STOPPING); // There's no need to wake up the thread like we do when starting. // Asynchronous backends need to be handled differently. - if (mal_context_is_backend_asynchronous(pDevice->pContext)) { + if (ma_context_is_backend_asynchronous(pDevice->pContext)) { if (pDevice->pContext->onDeviceStop) { result = pDevice->pContext->onDeviceStop(pDevice); } else { result = MA_SUCCESS; } - mal_device__set_state(pDevice, MA_STATE_STOPPED); + ma_device__set_state(pDevice, MA_STATE_STOPPED); } else { // Synchronous backends. // We need to wait for the worker thread to become available for work before returning. Note that the worker thread will be - // the one who puts the device into the stopped state. Don't call mal_device__set_state() here. - mal_event_wait(&pDevice->stopEvent); + // the one who puts the device into the stopped state. Don't call ma_device__set_state() here. + ma_event_wait(&pDevice->stopEvent); result = MA_SUCCESS; } } - mal_mutex_unlock(&pDevice->lock); + ma_mutex_unlock(&pDevice->lock); return result; } -mal_bool32 mal_device_is_started(mal_device* pDevice) +ma_bool32 ma_device_is_started(ma_device* pDevice) { if (pDevice == NULL) return MA_FALSE; - return mal_device__get_state(pDevice) == MA_STATE_STARTED; + return ma_device__get_state(pDevice) == MA_STATE_STARTED; } -mal_context_config mal_context_config_init() +ma_context_config ma_context_config_init() { - mal_context_config config; - mal_zero_object(&config); + ma_context_config config; + ma_zero_object(&config); return config; } -mal_device_config mal_device_config_init(mal_device_type deviceType) +ma_device_config ma_device_config_init(ma_device_type deviceType) { - mal_device_config config; - mal_zero_object(&config); + ma_device_config config; + ma_zero_object(&config); config.deviceType = deviceType; return config; @@ -23436,7 +23436,7 @@ mal_device_config mal_device_config_init(mal_device_type deviceType) #endif // MA_NO_DEVICE_IO -void mal_get_standard_channel_map_microsoft(mal_uint32 channels, mal_channel channelMap[MA_MAX_CHANNELS]) +void ma_get_standard_channel_map_microsoft(ma_uint32 channels, ma_channel channelMap[MA_MAX_CHANNELS]) { // Based off the speaker configurations mentioned here: https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/ksmedia/ns-ksmedia-ksaudio_channel_config switch (channels) @@ -23523,13 +23523,13 @@ void mal_get_standard_channel_map_microsoft(mal_uint32 channels, mal_channel cha // Remainder. if (channels > 8) { - for (mal_uint32 iChannel = 8; iChannel < MA_MAX_CHANNELS; ++iChannel) { - channelMap[iChannel] = (mal_channel)(MA_CHANNEL_AUX_0 + (iChannel-8)); + for (ma_uint32 iChannel = 8; iChannel < MA_MAX_CHANNELS; ++iChannel) { + channelMap[iChannel] = (ma_channel)(MA_CHANNEL_AUX_0 + (iChannel-8)); } } } -void mal_get_standard_channel_map_alsa(mal_uint32 channels, mal_channel channelMap[MA_MAX_CHANNELS]) +void ma_get_standard_channel_map_alsa(ma_uint32 channels, ma_channel channelMap[MA_MAX_CHANNELS]) { switch (channels) { @@ -23605,13 +23605,13 @@ void mal_get_standard_channel_map_alsa(mal_uint32 channels, mal_channel channelM // Remainder. if (channels > 8) { - for (mal_uint32 iChannel = 8; iChannel < MA_MAX_CHANNELS; ++iChannel) { - channelMap[iChannel] = (mal_channel)(MA_CHANNEL_AUX_0 + (iChannel-8)); + for (ma_uint32 iChannel = 8; iChannel < MA_MAX_CHANNELS; ++iChannel) { + channelMap[iChannel] = (ma_channel)(MA_CHANNEL_AUX_0 + (iChannel-8)); } } } -void mal_get_standard_channel_map_rfc3551(mal_uint32 channels, mal_channel channelMap[MA_MAX_CHANNELS]) +void ma_get_standard_channel_map_rfc3551(ma_uint32 channels, ma_channel channelMap[MA_MAX_CHANNELS]) { switch (channels) { @@ -23663,13 +23663,13 @@ void mal_get_standard_channel_map_rfc3551(mal_uint32 channels, mal_channel chann // Remainder. if (channels > 8) { - for (mal_uint32 iChannel = 6; iChannel < MA_MAX_CHANNELS; ++iChannel) { - channelMap[iChannel] = (mal_channel)(MA_CHANNEL_AUX_0 + (iChannel-6)); + for (ma_uint32 iChannel = 6; iChannel < MA_MAX_CHANNELS; ++iChannel) { + channelMap[iChannel] = (ma_channel)(MA_CHANNEL_AUX_0 + (iChannel-6)); } } } -void mal_get_standard_channel_map_flac(mal_uint32 channels, mal_channel channelMap[MA_MAX_CHANNELS]) +void ma_get_standard_channel_map_flac(ma_uint32 channels, ma_channel channelMap[MA_MAX_CHANNELS]) { switch (channels) { @@ -23745,13 +23745,13 @@ void mal_get_standard_channel_map_flac(mal_uint32 channels, mal_channel channelM // Remainder. if (channels > 8) { - for (mal_uint32 iChannel = 8; iChannel < MA_MAX_CHANNELS; ++iChannel) { - channelMap[iChannel] = (mal_channel)(MA_CHANNEL_AUX_0 + (iChannel-8)); + for (ma_uint32 iChannel = 8; iChannel < MA_MAX_CHANNELS; ++iChannel) { + channelMap[iChannel] = (ma_channel)(MA_CHANNEL_AUX_0 + (iChannel-8)); } } } -void mal_get_standard_channel_map_vorbis(mal_uint32 channels, mal_channel channelMap[MA_MAX_CHANNELS]) +void ma_get_standard_channel_map_vorbis(ma_uint32 channels, ma_channel channelMap[MA_MAX_CHANNELS]) { // In Vorbis' type 0 channel mapping, the first two channels are not always the standard left/right - it // will have the center speaker where the right usually goes. Why?! @@ -23829,13 +23829,13 @@ void mal_get_standard_channel_map_vorbis(mal_uint32 channels, mal_channel channe // Remainder. if (channels > 8) { - for (mal_uint32 iChannel = 8; iChannel < MA_MAX_CHANNELS; ++iChannel) { - channelMap[iChannel] = (mal_channel)(MA_CHANNEL_AUX_0 + (iChannel-8)); + for (ma_uint32 iChannel = 8; iChannel < MA_MAX_CHANNELS; ++iChannel) { + channelMap[iChannel] = (ma_channel)(MA_CHANNEL_AUX_0 + (iChannel-8)); } } } -void mal_get_standard_channel_map_sound4(mal_uint32 channels, mal_channel channelMap[MA_MAX_CHANNELS]) +void ma_get_standard_channel_map_sound4(ma_uint32 channels, ma_channel channelMap[MA_MAX_CHANNELS]) { switch (channels) { @@ -23911,13 +23911,13 @@ void mal_get_standard_channel_map_sound4(mal_uint32 channels, mal_channel channe // Remainder. if (channels > 8) { - for (mal_uint32 iChannel = 8; iChannel < MA_MAX_CHANNELS; ++iChannel) { - channelMap[iChannel] = (mal_channel)(MA_CHANNEL_AUX_0 + (iChannel-8)); + for (ma_uint32 iChannel = 8; iChannel < MA_MAX_CHANNELS; ++iChannel) { + channelMap[iChannel] = (ma_channel)(MA_CHANNEL_AUX_0 + (iChannel-8)); } } } -void mal_get_standard_channel_map_sndio(mal_uint32 channels, mal_channel channelMap[MA_MAX_CHANNELS]) +void ma_get_standard_channel_map_sndio(ma_uint32 channels, ma_channel channelMap[MA_MAX_CHANNELS]) { switch (channels) { @@ -23970,62 +23970,62 @@ void mal_get_standard_channel_map_sndio(mal_uint32 channels, mal_channel channel // Remainder. if (channels > 6) { - for (mal_uint32 iChannel = 6; iChannel < MA_MAX_CHANNELS; ++iChannel) { - channelMap[iChannel] = (mal_channel)(MA_CHANNEL_AUX_0 + (iChannel-6)); + for (ma_uint32 iChannel = 6; iChannel < MA_MAX_CHANNELS; ++iChannel) { + channelMap[iChannel] = (ma_channel)(MA_CHANNEL_AUX_0 + (iChannel-6)); } } } -void mal_get_standard_channel_map(mal_standard_channel_map standardChannelMap, mal_uint32 channels, mal_channel channelMap[MA_MAX_CHANNELS]) +void ma_get_standard_channel_map(ma_standard_channel_map standardChannelMap, ma_uint32 channels, ma_channel channelMap[MA_MAX_CHANNELS]) { switch (standardChannelMap) { - case mal_standard_channel_map_alsa: + case ma_standard_channel_map_alsa: { - mal_get_standard_channel_map_alsa(channels, channelMap); + ma_get_standard_channel_map_alsa(channels, channelMap); } break; - case mal_standard_channel_map_rfc3551: + case ma_standard_channel_map_rfc3551: { - mal_get_standard_channel_map_rfc3551(channels, channelMap); + ma_get_standard_channel_map_rfc3551(channels, channelMap); } break; - case mal_standard_channel_map_flac: + case ma_standard_channel_map_flac: { - mal_get_standard_channel_map_flac(channels, channelMap); + ma_get_standard_channel_map_flac(channels, channelMap); } break; - case mal_standard_channel_map_vorbis: + case ma_standard_channel_map_vorbis: { - mal_get_standard_channel_map_vorbis(channels, channelMap); + ma_get_standard_channel_map_vorbis(channels, channelMap); } break; - case mal_standard_channel_map_sound4: + case ma_standard_channel_map_sound4: { - mal_get_standard_channel_map_sound4(channels, channelMap); + ma_get_standard_channel_map_sound4(channels, channelMap); } break; - case mal_standard_channel_map_sndio: + case ma_standard_channel_map_sndio: { - mal_get_standard_channel_map_sndio(channels, channelMap); + ma_get_standard_channel_map_sndio(channels, channelMap); } break; - case mal_standard_channel_map_microsoft: + case ma_standard_channel_map_microsoft: default: { - mal_get_standard_channel_map_microsoft(channels, channelMap); + ma_get_standard_channel_map_microsoft(channels, channelMap); } break; } } -void mal_channel_map_copy(mal_channel* pOut, const mal_channel* pIn, mal_uint32 channels) +void ma_channel_map_copy(ma_channel* pOut, const ma_channel* pIn, ma_uint32 channels) { if (pOut != NULL && pIn != NULL && channels > 0) { - mal_copy_memory(pOut, pIn, sizeof(*pOut) * channels); + ma_copy_memory(pOut, pIn, sizeof(*pOut) * channels); } } -mal_bool32 mal_channel_map_valid(mal_uint32 channels, const mal_channel channelMap[MA_MAX_CHANNELS]) +ma_bool32 ma_channel_map_valid(ma_uint32 channels, const ma_channel channelMap[MA_MAX_CHANNELS]) { if (channelMap == NULL) { return MA_FALSE; @@ -24038,7 +24038,7 @@ mal_bool32 mal_channel_map_valid(mal_uint32 channels, const mal_channel channelM // It does not make sense to have a mono channel when there is more than 1 channel. if (channels > 1) { - for (mal_uint32 iChannel = 0; iChannel < channels; ++iChannel) { + for (ma_uint32 iChannel = 0; iChannel < channels; ++iChannel) { if (channelMap[iChannel] == MA_CHANNEL_MONO) { return MA_FALSE; } @@ -24048,7 +24048,7 @@ mal_bool32 mal_channel_map_valid(mal_uint32 channels, const mal_channel channelM return MA_TRUE; } -mal_bool32 mal_channel_map_equal(mal_uint32 channels, const mal_channel channelMapA[MA_MAX_CHANNELS], const mal_channel channelMapB[MA_MAX_CHANNELS]) +ma_bool32 ma_channel_map_equal(ma_uint32 channels, const ma_channel channelMapA[MA_MAX_CHANNELS], const ma_channel channelMapB[MA_MAX_CHANNELS]) { if (channelMapA == channelMapB) { return MA_FALSE; @@ -24058,7 +24058,7 @@ mal_bool32 mal_channel_map_equal(mal_uint32 channels, const mal_channel channelM return MA_FALSE; } - for (mal_uint32 iChannel = 0; iChannel < channels; ++iChannel) { + for (ma_uint32 iChannel = 0; iChannel < channels; ++iChannel) { if (channelMapA[iChannel] != channelMapB[iChannel]) { return MA_FALSE; } @@ -24067,9 +24067,9 @@ mal_bool32 mal_channel_map_equal(mal_uint32 channels, const mal_channel channelM return MA_TRUE; } -mal_bool32 mal_channel_map_blank(mal_uint32 channels, const mal_channel channelMap[MA_MAX_CHANNELS]) +ma_bool32 ma_channel_map_blank(ma_uint32 channels, const ma_channel channelMap[MA_MAX_CHANNELS]) { - for (mal_uint32 iChannel = 0; iChannel < channels; ++iChannel) { + for (ma_uint32 iChannel = 0; iChannel < channels; ++iChannel) { if (channelMap[iChannel] != MA_CHANNEL_NONE) { return MA_FALSE; } @@ -24078,9 +24078,9 @@ mal_bool32 mal_channel_map_blank(mal_uint32 channels, const mal_channel channelM return MA_TRUE; } -mal_bool32 mal_channel_map_contains_channel_position(mal_uint32 channels, const mal_channel channelMap[MA_MAX_CHANNELS], mal_channel channelPosition) +ma_bool32 ma_channel_map_contains_channel_position(ma_uint32 channels, const ma_channel channelMap[MA_MAX_CHANNELS], ma_channel channelPosition) { - for (mal_uint32 iChannel = 0; iChannel < channels; ++iChannel) { + for (ma_uint32 iChannel = 0; iChannel < channels; ++iChannel) { if (channelMap[iChannel] == channelPosition) { return MA_TRUE; } @@ -24101,232 +24101,232 @@ mal_bool32 mal_channel_map_contains_channel_position(mal_uint32 channels, const //#define MA_USE_REFERENCE_CONVERSION_APIS 1 //#define MA_USE_SSE -void mal_copy_memory_64(void* dst, const void* src, mal_uint64 sizeInBytes) +void ma_copy_memory_64(void* dst, const void* src, ma_uint64 sizeInBytes) { #if 0xFFFFFFFFFFFFFFFF <= MA_SIZE_MAX - mal_copy_memory(dst, src, (size_t)sizeInBytes); + ma_copy_memory(dst, src, (size_t)sizeInBytes); #else while (sizeInBytes > 0) { - mal_uint64 bytesToCopyNow = sizeInBytes; + ma_uint64 bytesToCopyNow = sizeInBytes; if (bytesToCopyNow > MA_SIZE_MAX) { bytesToCopyNow = MA_SIZE_MAX; } - mal_copy_memory(dst, src, (size_t)bytesToCopyNow); // Safe cast to size_t. + ma_copy_memory(dst, src, (size_t)bytesToCopyNow); // Safe cast to size_t. sizeInBytes -= bytesToCopyNow; - dst = ( void*)(( mal_uint8*)dst + bytesToCopyNow); - src = (const void*)((const mal_uint8*)src + bytesToCopyNow); + dst = ( void*)(( ma_uint8*)dst + bytesToCopyNow); + src = (const void*)((const ma_uint8*)src + bytesToCopyNow); } #endif } -void mal_zero_memory_64(void* dst, mal_uint64 sizeInBytes) +void ma_zero_memory_64(void* dst, ma_uint64 sizeInBytes) { #if 0xFFFFFFFFFFFFFFFF <= MA_SIZE_MAX - mal_zero_memory(dst, (size_t)sizeInBytes); + ma_zero_memory(dst, (size_t)sizeInBytes); #else while (sizeInBytes > 0) { - mal_uint64 bytesToZeroNow = sizeInBytes; + ma_uint64 bytesToZeroNow = sizeInBytes; if (bytesToZeroNow > MA_SIZE_MAX) { bytesToZeroNow = MA_SIZE_MAX; } - mal_zero_memory(dst, (size_t)bytesToZeroNow); // Safe cast to size_t. + ma_zero_memory(dst, (size_t)bytesToZeroNow); // Safe cast to size_t. sizeInBytes -= bytesToZeroNow; - dst = (void*)((mal_uint8*)dst + bytesToZeroNow); + dst = (void*)((ma_uint8*)dst + bytesToZeroNow); } #endif } // u8 -void mal_pcm_u8_to_u8(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_u8_to_u8(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { (void)ditherMode; - mal_copy_memory_64(dst, src, count * sizeof(mal_uint8)); + ma_copy_memory_64(dst, src, count * sizeof(ma_uint8)); } -void mal_pcm_u8_to_s16__reference(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_u8_to_s16__reference(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { (void)ditherMode; - mal_int16* dst_s16 = (mal_int16*)dst; - const mal_uint8* src_u8 = (const mal_uint8*)src; + ma_int16* dst_s16 = (ma_int16*)dst; + const ma_uint8* src_u8 = (const ma_uint8*)src; - mal_uint64 i; + ma_uint64 i; for (i = 0; i < count; i += 1) { - mal_int16 x = src_u8[i]; + ma_int16 x = src_u8[i]; x = x - 128; x = x << 8; dst_s16[i] = x; } } -void mal_pcm_u8_to_s16__optimized(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_u8_to_s16__optimized(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_u8_to_s16__reference(dst, src, count, ditherMode); + ma_pcm_u8_to_s16__reference(dst, src, count, ditherMode); } #if defined(MA_SUPPORT_SSE2) -void mal_pcm_u8_to_s16__sse2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_u8_to_s16__sse2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_u8_to_s16__optimized(dst, src, count, ditherMode); + ma_pcm_u8_to_s16__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX2) -void mal_pcm_u8_to_s16__avx2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_u8_to_s16__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_u8_to_s16__optimized(dst, src, count, ditherMode); + ma_pcm_u8_to_s16__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX512) -void mal_pcm_u8_to_s16__avx512(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_u8_to_s16__avx512(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_u8_to_s16__avx2(dst, src, count, ditherMode); + ma_pcm_u8_to_s16__avx2(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_NEON) -void mal_pcm_u8_to_s16__neon(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_u8_to_s16__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_u8_to_s16__optimized(dst, src, count, ditherMode); + ma_pcm_u8_to_s16__optimized(dst, src, count, ditherMode); } #endif -void mal_pcm_u8_to_s16(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_u8_to_s16(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { #ifdef MA_USE_REFERENCE_CONVERSION_APIS - mal_pcm_u8_to_s16__reference(dst, src, count, ditherMode); + ma_pcm_u8_to_s16__reference(dst, src, count, ditherMode); #else - mal_pcm_u8_to_s16__optimized(dst, src, count, ditherMode); + ma_pcm_u8_to_s16__optimized(dst, src, count, ditherMode); #endif } -void mal_pcm_u8_to_s24__reference(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_u8_to_s24__reference(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { (void)ditherMode; - mal_uint8* dst_s24 = (mal_uint8*)dst; - const mal_uint8* src_u8 = (const mal_uint8*)src; + ma_uint8* dst_s24 = (ma_uint8*)dst; + const ma_uint8* src_u8 = (const ma_uint8*)src; - mal_uint64 i; + ma_uint64 i; for (i = 0; i < count; i += 1) { - mal_int16 x = src_u8[i]; + ma_int16 x = src_u8[i]; x = x - 128; dst_s24[i*3+0] = 0; dst_s24[i*3+1] = 0; - dst_s24[i*3+2] = (mal_uint8)((mal_int8)x); + dst_s24[i*3+2] = (ma_uint8)((ma_int8)x); } } -void mal_pcm_u8_to_s24__optimized(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_u8_to_s24__optimized(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_u8_to_s24__reference(dst, src, count, ditherMode); + ma_pcm_u8_to_s24__reference(dst, src, count, ditherMode); } #if defined(MA_SUPPORT_SSE2) -void mal_pcm_u8_to_s24__sse2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_u8_to_s24__sse2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_u8_to_s24__optimized(dst, src, count, ditherMode); + ma_pcm_u8_to_s24__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX2) -void mal_pcm_u8_to_s24__avx2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_u8_to_s24__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_u8_to_s24__optimized(dst, src, count, ditherMode); + ma_pcm_u8_to_s24__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX512) -void mal_pcm_u8_to_s24__avx512(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_u8_to_s24__avx512(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_u8_to_s24__avx2(dst, src, count, ditherMode); + ma_pcm_u8_to_s24__avx2(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_NEON) -void mal_pcm_u8_to_s24__neon(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_u8_to_s24__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_u8_to_s24__optimized(dst, src, count, ditherMode); + ma_pcm_u8_to_s24__optimized(dst, src, count, ditherMode); } #endif -void mal_pcm_u8_to_s24(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_u8_to_s24(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { #ifdef MA_USE_REFERENCE_CONVERSION_APIS - mal_pcm_u8_to_s24__reference(dst, src, count, ditherMode); + ma_pcm_u8_to_s24__reference(dst, src, count, ditherMode); #else - mal_pcm_u8_to_s24__optimized(dst, src, count, ditherMode); + ma_pcm_u8_to_s24__optimized(dst, src, count, ditherMode); #endif } -void mal_pcm_u8_to_s32__reference(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_u8_to_s32__reference(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { (void)ditherMode; - mal_int32* dst_s32 = (mal_int32*)dst; - const mal_uint8* src_u8 = (const mal_uint8*)src; + ma_int32* dst_s32 = (ma_int32*)dst; + const ma_uint8* src_u8 = (const ma_uint8*)src; - mal_uint64 i; + ma_uint64 i; for (i = 0; i < count; i += 1) { - mal_int32 x = src_u8[i]; + ma_int32 x = src_u8[i]; x = x - 128; x = x << 24; dst_s32[i] = x; } } -void mal_pcm_u8_to_s32__optimized(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_u8_to_s32__optimized(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_u8_to_s32__reference(dst, src, count, ditherMode); + ma_pcm_u8_to_s32__reference(dst, src, count, ditherMode); } #if defined(MA_SUPPORT_SSE2) -void mal_pcm_u8_to_s32__sse2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_u8_to_s32__sse2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_u8_to_s32__optimized(dst, src, count, ditherMode); + ma_pcm_u8_to_s32__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX2) -void mal_pcm_u8_to_s32__avx2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_u8_to_s32__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_u8_to_s32__optimized(dst, src, count, ditherMode); + ma_pcm_u8_to_s32__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX512) -void mal_pcm_u8_to_s32__avx512(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_u8_to_s32__avx512(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_u8_to_s32__avx2(dst, src, count, ditherMode); + ma_pcm_u8_to_s32__avx2(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_NEON) -void mal_pcm_u8_to_s32__neon(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_u8_to_s32__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_u8_to_s32__optimized(dst, src, count, ditherMode); + ma_pcm_u8_to_s32__optimized(dst, src, count, ditherMode); } #endif -void mal_pcm_u8_to_s32(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_u8_to_s32(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { #ifdef MA_USE_REFERENCE_CONVERSION_APIS - mal_pcm_u8_to_s32__reference(dst, src, count, ditherMode); + ma_pcm_u8_to_s32__reference(dst, src, count, ditherMode); #else - mal_pcm_u8_to_s32__optimized(dst, src, count, ditherMode); + ma_pcm_u8_to_s32__optimized(dst, src, count, ditherMode); #endif } -void mal_pcm_u8_to_f32__reference(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_u8_to_f32__reference(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { (void)ditherMode; float* dst_f32 = (float*)dst; - const mal_uint8* src_u8 = (const mal_uint8*)src; + const ma_uint8* src_u8 = (const ma_uint8*)src; - mal_uint64 i; + ma_uint64 i; for (i = 0; i < count; i += 1) { float x = (float)src_u8[i]; x = x * 0.00784313725490196078f; // 0..255 to 0..2 @@ -24336,78 +24336,78 @@ void mal_pcm_u8_to_f32__reference(void* dst, const void* src, mal_uint64 count, } } -void mal_pcm_u8_to_f32__optimized(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_u8_to_f32__optimized(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_u8_to_f32__reference(dst, src, count, ditherMode); + ma_pcm_u8_to_f32__reference(dst, src, count, ditherMode); } #if defined(MA_SUPPORT_SSE2) -void mal_pcm_u8_to_f32__sse2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_u8_to_f32__sse2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_u8_to_f32__optimized(dst, src, count, ditherMode); + ma_pcm_u8_to_f32__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX2) -void mal_pcm_u8_to_f32__avx2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_u8_to_f32__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_u8_to_f32__optimized(dst, src, count, ditherMode); + ma_pcm_u8_to_f32__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX512) -void mal_pcm_u8_to_f32__avx512(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_u8_to_f32__avx512(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_u8_to_f32__avx2(dst, src, count, ditherMode); + ma_pcm_u8_to_f32__avx2(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_NEON) -void mal_pcm_u8_to_f32__neon(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_u8_to_f32__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_u8_to_f32__optimized(dst, src, count, ditherMode); + ma_pcm_u8_to_f32__optimized(dst, src, count, ditherMode); } #endif -void mal_pcm_u8_to_f32(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_u8_to_f32(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { #ifdef MA_USE_REFERENCE_CONVERSION_APIS - mal_pcm_u8_to_f32__reference(dst, src, count, ditherMode); + ma_pcm_u8_to_f32__reference(dst, src, count, ditherMode); #else - mal_pcm_u8_to_f32__optimized(dst, src, count, ditherMode); + ma_pcm_u8_to_f32__optimized(dst, src, count, ditherMode); #endif } -void mal_pcm_interleave_u8__reference(void* dst, const void** src, mal_uint64 frameCount, mal_uint32 channels) +void ma_pcm_interleave_u8__reference(void* dst, const void** src, ma_uint64 frameCount, ma_uint32 channels) { - mal_uint8* dst_u8 = (mal_uint8*)dst; - const mal_uint8** src_u8 = (const mal_uint8**)src; + ma_uint8* dst_u8 = (ma_uint8*)dst; + const ma_uint8** src_u8 = (const ma_uint8**)src; - mal_uint64 iFrame; + ma_uint64 iFrame; for (iFrame = 0; iFrame < frameCount; iFrame += 1) { - mal_uint32 iChannel; + ma_uint32 iChannel; for (iChannel = 0; iChannel < channels; iChannel += 1) { dst_u8[iFrame*channels + iChannel] = src_u8[iChannel][iFrame]; } } } -void mal_pcm_interleave_u8__optimized(void* dst, const void** src, mal_uint64 frameCount, mal_uint32 channels) +void ma_pcm_interleave_u8__optimized(void* dst, const void** src, ma_uint64 frameCount, ma_uint32 channels) { - mal_uint8* dst_u8 = (mal_uint8*)dst; - const mal_uint8** src_u8 = (const mal_uint8**)src; + ma_uint8* dst_u8 = (ma_uint8*)dst; + const ma_uint8** src_u8 = (const ma_uint8**)src; if (channels == 1) { - mal_copy_memory_64(dst, src[0], frameCount * sizeof(mal_uint8)); + ma_copy_memory_64(dst, src[0], frameCount * sizeof(ma_uint8)); } else if (channels == 2) { - mal_uint64 iFrame; + ma_uint64 iFrame; for (iFrame = 0; iFrame < frameCount; iFrame += 1) { dst_u8[iFrame*2 + 0] = src_u8[0][iFrame]; dst_u8[iFrame*2 + 1] = src_u8[1][iFrame]; } } else { - mal_uint64 iFrame; + ma_uint64 iFrame; for (iFrame = 0; iFrame < frameCount; iFrame += 1) { - mal_uint32 iChannel; + ma_uint32 iChannel; for (iChannel = 0; iChannel < channels; iChannel += 1) { dst_u8[iFrame*channels + iChannel] = src_u8[iChannel][iFrame]; } @@ -24415,242 +24415,242 @@ void mal_pcm_interleave_u8__optimized(void* dst, const void** src, mal_uint64 fr } } -void mal_pcm_interleave_u8(void* dst, const void** src, mal_uint64 frameCount, mal_uint32 channels) +void ma_pcm_interleave_u8(void* dst, const void** src, ma_uint64 frameCount, ma_uint32 channels) { #ifdef MA_USE_REFERENCE_CONVERSION_APIS - mal_pcm_interleave_u8__reference(dst, src, frameCount, channels); + ma_pcm_interleave_u8__reference(dst, src, frameCount, channels); #else - mal_pcm_interleave_u8__optimized(dst, src, frameCount, channels); + ma_pcm_interleave_u8__optimized(dst, src, frameCount, channels); #endif } -void mal_pcm_deinterleave_u8__reference(void** dst, const void* src, mal_uint64 frameCount, mal_uint32 channels) +void ma_pcm_deinterleave_u8__reference(void** dst, const void* src, ma_uint64 frameCount, ma_uint32 channels) { - mal_uint8** dst_u8 = (mal_uint8**)dst; - const mal_uint8* src_u8 = (const mal_uint8*)src; + ma_uint8** dst_u8 = (ma_uint8**)dst; + const ma_uint8* src_u8 = (const ma_uint8*)src; - mal_uint64 iFrame; + ma_uint64 iFrame; for (iFrame = 0; iFrame < frameCount; iFrame += 1) { - mal_uint32 iChannel; + ma_uint32 iChannel; for (iChannel = 0; iChannel < channels; iChannel += 1) { dst_u8[iChannel][iFrame] = src_u8[iFrame*channels + iChannel]; } } } -void mal_pcm_deinterleave_u8__optimized(void** dst, const void* src, mal_uint64 frameCount, mal_uint32 channels) +void ma_pcm_deinterleave_u8__optimized(void** dst, const void* src, ma_uint64 frameCount, ma_uint32 channels) { - mal_pcm_deinterleave_u8__reference(dst, src, frameCount, channels); + ma_pcm_deinterleave_u8__reference(dst, src, frameCount, channels); } -void mal_pcm_deinterleave_u8(void** dst, const void* src, mal_uint64 frameCount, mal_uint32 channels) +void ma_pcm_deinterleave_u8(void** dst, const void* src, ma_uint64 frameCount, ma_uint32 channels) { #ifdef MA_USE_REFERENCE_CONVERSION_APIS - mal_pcm_deinterleave_u8__reference(dst, src, frameCount, channels); + ma_pcm_deinterleave_u8__reference(dst, src, frameCount, channels); #else - mal_pcm_deinterleave_u8__optimized(dst, src, frameCount, channels); + ma_pcm_deinterleave_u8__optimized(dst, src, frameCount, channels); #endif } // s16 -void mal_pcm_s16_to_u8__reference(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s16_to_u8__reference(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_uint8* dst_u8 = (mal_uint8*)dst; - const mal_int16* src_s16 = (const mal_int16*)src; + ma_uint8* dst_u8 = (ma_uint8*)dst; + const ma_int16* src_s16 = (const ma_int16*)src; - if (ditherMode == mal_dither_mode_none) { - mal_uint64 i; + if (ditherMode == ma_dither_mode_none) { + ma_uint64 i; for (i = 0; i < count; i += 1) { - mal_int16 x = src_s16[i]; + ma_int16 x = src_s16[i]; x = x >> 8; x = x + 128; - dst_u8[i] = (mal_uint8)x; + dst_u8[i] = (ma_uint8)x; } } else { - mal_uint64 i; + ma_uint64 i; for (i = 0; i < count; i += 1) { - mal_int16 x = src_s16[i]; + ma_int16 x = src_s16[i]; // Dither. Don't overflow. - mal_int32 dither = mal_dither_s32(ditherMode, -0x80, 0x7F); + ma_int32 dither = ma_dither_s32(ditherMode, -0x80, 0x7F); if ((x + dither) <= 0x7FFF) { - x = (mal_int16)(x + dither); + x = (ma_int16)(x + dither); } else { x = 0x7FFF; } x = x >> 8; x = x + 128; - dst_u8[i] = (mal_uint8)x; + dst_u8[i] = (ma_uint8)x; } } } -void mal_pcm_s16_to_u8__optimized(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s16_to_u8__optimized(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s16_to_u8__reference(dst, src, count, ditherMode); + ma_pcm_s16_to_u8__reference(dst, src, count, ditherMode); } #if defined(MA_SUPPORT_SSE2) -void mal_pcm_s16_to_u8__sse2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s16_to_u8__sse2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s16_to_u8__optimized(dst, src, count, ditherMode); + ma_pcm_s16_to_u8__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX2) -void mal_pcm_s16_to_u8__avx2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s16_to_u8__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s16_to_u8__optimized(dst, src, count, ditherMode); + ma_pcm_s16_to_u8__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX512) -void mal_pcm_s16_to_u8__avx512(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s16_to_u8__avx512(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s16_to_u8__avx2(dst, src, count, ditherMode); + ma_pcm_s16_to_u8__avx2(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_NEON) -void mal_pcm_s16_to_u8__neon(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s16_to_u8__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s16_to_u8__optimized(dst, src, count, ditherMode); + ma_pcm_s16_to_u8__optimized(dst, src, count, ditherMode); } #endif -void mal_pcm_s16_to_u8(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s16_to_u8(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { #ifdef MA_USE_REFERENCE_CONVERSION_APIS - mal_pcm_s16_to_u8__reference(dst, src, count, ditherMode); + ma_pcm_s16_to_u8__reference(dst, src, count, ditherMode); #else - mal_pcm_s16_to_u8__optimized(dst, src, count, ditherMode); + ma_pcm_s16_to_u8__optimized(dst, src, count, ditherMode); #endif } -void mal_pcm_s16_to_s16(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s16_to_s16(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { (void)ditherMode; - mal_copy_memory_64(dst, src, count * sizeof(mal_int16)); + ma_copy_memory_64(dst, src, count * sizeof(ma_int16)); } -void mal_pcm_s16_to_s24__reference(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s16_to_s24__reference(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { (void)ditherMode; - mal_uint8* dst_s24 = (mal_uint8*)dst; - const mal_int16* src_s16 = (const mal_int16*)src; + ma_uint8* dst_s24 = (ma_uint8*)dst; + const ma_int16* src_s16 = (const ma_int16*)src; - mal_uint64 i; + ma_uint64 i; for (i = 0; i < count; i += 1) { dst_s24[i*3+0] = 0; - dst_s24[i*3+1] = (mal_uint8)(src_s16[i] & 0xFF); - dst_s24[i*3+2] = (mal_uint8)(src_s16[i] >> 8); + dst_s24[i*3+1] = (ma_uint8)(src_s16[i] & 0xFF); + dst_s24[i*3+2] = (ma_uint8)(src_s16[i] >> 8); } } -void mal_pcm_s16_to_s24__optimized(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s16_to_s24__optimized(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s16_to_s24__reference(dst, src, count, ditherMode); + ma_pcm_s16_to_s24__reference(dst, src, count, ditherMode); } #if defined(MA_SUPPORT_SSE2) -void mal_pcm_s16_to_s24__sse2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s16_to_s24__sse2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s16_to_s24__optimized(dst, src, count, ditherMode); + ma_pcm_s16_to_s24__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX2) -void mal_pcm_s16_to_s24__avx2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s16_to_s24__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s16_to_s24__optimized(dst, src, count, ditherMode); + ma_pcm_s16_to_s24__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX512) -void mal_pcm_s16_to_s24__avx512(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s16_to_s24__avx512(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s16_to_s24__avx2(dst, src, count, ditherMode); + ma_pcm_s16_to_s24__avx2(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_NEON) -void mal_pcm_s16_to_s24__neon(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s16_to_s24__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s16_to_s24__optimized(dst, src, count, ditherMode); + ma_pcm_s16_to_s24__optimized(dst, src, count, ditherMode); } #endif -void mal_pcm_s16_to_s24(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s16_to_s24(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { #ifdef MA_USE_REFERENCE_CONVERSION_APIS - mal_pcm_s16_to_s24__reference(dst, src, count, ditherMode); + ma_pcm_s16_to_s24__reference(dst, src, count, ditherMode); #else - mal_pcm_s16_to_s24__optimized(dst, src, count, ditherMode); + ma_pcm_s16_to_s24__optimized(dst, src, count, ditherMode); #endif } -void mal_pcm_s16_to_s32__reference(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s16_to_s32__reference(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { (void)ditherMode; - mal_int32* dst_s32 = (mal_int32*)dst; - const mal_int16* src_s16 = (const mal_int16*)src; + ma_int32* dst_s32 = (ma_int32*)dst; + const ma_int16* src_s16 = (const ma_int16*)src; - mal_uint64 i; + ma_uint64 i; for (i = 0; i < count; i += 1) { dst_s32[i] = src_s16[i] << 16; } } -void mal_pcm_s16_to_s32__optimized(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s16_to_s32__optimized(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s16_to_s32__reference(dst, src, count, ditherMode); + ma_pcm_s16_to_s32__reference(dst, src, count, ditherMode); } #if defined(MA_SUPPORT_SSE2) -void mal_pcm_s16_to_s32__sse2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s16_to_s32__sse2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s16_to_s32__optimized(dst, src, count, ditherMode); + ma_pcm_s16_to_s32__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX2) -void mal_pcm_s16_to_s32__avx2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s16_to_s32__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s16_to_s32__optimized(dst, src, count, ditherMode); + ma_pcm_s16_to_s32__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX512) -void mal_pcm_s16_to_s32__avx512(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s16_to_s32__avx512(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s16_to_s32__avx2(dst, src, count, ditherMode); + ma_pcm_s16_to_s32__avx2(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_NEON) -void mal_pcm_s16_to_s32__neon(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s16_to_s32__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s16_to_s32__optimized(dst, src, count, ditherMode); + ma_pcm_s16_to_s32__optimized(dst, src, count, ditherMode); } #endif -void mal_pcm_s16_to_s32(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s16_to_s32(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { #ifdef MA_USE_REFERENCE_CONVERSION_APIS - mal_pcm_s16_to_s32__reference(dst, src, count, ditherMode); + ma_pcm_s16_to_s32__reference(dst, src, count, ditherMode); #else - mal_pcm_s16_to_s32__optimized(dst, src, count, ditherMode); + ma_pcm_s16_to_s32__optimized(dst, src, count, ditherMode); #endif } -void mal_pcm_s16_to_f32__reference(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s16_to_f32__reference(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { (void)ditherMode; float* dst_f32 = (float*)dst; - const mal_int16* src_s16 = (const mal_int16*)src; + const ma_int16* src_s16 = (const ma_int16*)src; - mal_uint64 i; + ma_uint64 i; for (i = 0; i < count; i += 1) { float x = (float)src_s16[i]; @@ -24668,124 +24668,124 @@ void mal_pcm_s16_to_f32__reference(void* dst, const void* src, mal_uint64 count, } } -void mal_pcm_s16_to_f32__optimized(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s16_to_f32__optimized(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s16_to_f32__reference(dst, src, count, ditherMode); + ma_pcm_s16_to_f32__reference(dst, src, count, ditherMode); } #if defined(MA_SUPPORT_SSE2) -void mal_pcm_s16_to_f32__sse2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s16_to_f32__sse2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s16_to_f32__optimized(dst, src, count, ditherMode); + ma_pcm_s16_to_f32__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX2) -void mal_pcm_s16_to_f32__avx2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s16_to_f32__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s16_to_f32__optimized(dst, src, count, ditherMode); + ma_pcm_s16_to_f32__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX512) -void mal_pcm_s16_to_f32__avx512(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s16_to_f32__avx512(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s16_to_f32__avx2(dst, src, count, ditherMode); + ma_pcm_s16_to_f32__avx2(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_NEON) -void mal_pcm_s16_to_f32__neon(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s16_to_f32__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s16_to_f32__optimized(dst, src, count, ditherMode); + ma_pcm_s16_to_f32__optimized(dst, src, count, ditherMode); } #endif -void mal_pcm_s16_to_f32(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s16_to_f32(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { #ifdef MA_USE_REFERENCE_CONVERSION_APIS - mal_pcm_s16_to_f32__reference(dst, src, count, ditherMode); + ma_pcm_s16_to_f32__reference(dst, src, count, ditherMode); #else - mal_pcm_s16_to_f32__optimized(dst, src, count, ditherMode); + ma_pcm_s16_to_f32__optimized(dst, src, count, ditherMode); #endif } -void mal_pcm_interleave_s16__reference(void* dst, const void** src, mal_uint64 frameCount, mal_uint32 channels) +void ma_pcm_interleave_s16__reference(void* dst, const void** src, ma_uint64 frameCount, ma_uint32 channels) { - mal_int16* dst_s16 = (mal_int16*)dst; - const mal_int16** src_s16 = (const mal_int16**)src; + ma_int16* dst_s16 = (ma_int16*)dst; + const ma_int16** src_s16 = (const ma_int16**)src; - mal_uint64 iFrame; + ma_uint64 iFrame; for (iFrame = 0; iFrame < frameCount; iFrame += 1) { - mal_uint32 iChannel; + ma_uint32 iChannel; for (iChannel = 0; iChannel < channels; iChannel += 1) { dst_s16[iFrame*channels + iChannel] = src_s16[iChannel][iFrame]; } } } -void mal_pcm_interleave_s16__optimized(void* dst, const void** src, mal_uint64 frameCount, mal_uint32 channels) +void ma_pcm_interleave_s16__optimized(void* dst, const void** src, ma_uint64 frameCount, ma_uint32 channels) { - mal_pcm_interleave_s16__reference(dst, src, frameCount, channels); + ma_pcm_interleave_s16__reference(dst, src, frameCount, channels); } -void mal_pcm_interleave_s16(void* dst, const void** src, mal_uint64 frameCount, mal_uint32 channels) +void ma_pcm_interleave_s16(void* dst, const void** src, ma_uint64 frameCount, ma_uint32 channels) { #ifdef MA_USE_REFERENCE_CONVERSION_APIS - mal_pcm_interleave_s16__reference(dst, src, frameCount, channels); + ma_pcm_interleave_s16__reference(dst, src, frameCount, channels); #else - mal_pcm_interleave_s16__optimized(dst, src, frameCount, channels); + ma_pcm_interleave_s16__optimized(dst, src, frameCount, channels); #endif } -void mal_pcm_deinterleave_s16__reference(void** dst, const void* src, mal_uint64 frameCount, mal_uint32 channels) +void ma_pcm_deinterleave_s16__reference(void** dst, const void* src, ma_uint64 frameCount, ma_uint32 channels) { - mal_int16** dst_s16 = (mal_int16**)dst; - const mal_int16* src_s16 = (const mal_int16*)src; + ma_int16** dst_s16 = (ma_int16**)dst; + const ma_int16* src_s16 = (const ma_int16*)src; - mal_uint64 iFrame; + ma_uint64 iFrame; for (iFrame = 0; iFrame < frameCount; iFrame += 1) { - mal_uint32 iChannel; + ma_uint32 iChannel; for (iChannel = 0; iChannel < channels; iChannel += 1) { dst_s16[iChannel][iFrame] = src_s16[iFrame*channels + iChannel]; } } } -void mal_pcm_deinterleave_s16__optimized(void** dst, const void* src, mal_uint64 frameCount, mal_uint32 channels) +void ma_pcm_deinterleave_s16__optimized(void** dst, const void* src, ma_uint64 frameCount, ma_uint32 channels) { - mal_pcm_deinterleave_s16__reference(dst, src, frameCount, channels); + ma_pcm_deinterleave_s16__reference(dst, src, frameCount, channels); } -void mal_pcm_deinterleave_s16(void** dst, const void* src, mal_uint64 frameCount, mal_uint32 channels) +void ma_pcm_deinterleave_s16(void** dst, const void* src, ma_uint64 frameCount, ma_uint32 channels) { #ifdef MA_USE_REFERENCE_CONVERSION_APIS - mal_pcm_deinterleave_s16__reference(dst, src, frameCount, channels); + ma_pcm_deinterleave_s16__reference(dst, src, frameCount, channels); #else - mal_pcm_deinterleave_s16__optimized(dst, src, frameCount, channels); + ma_pcm_deinterleave_s16__optimized(dst, src, frameCount, channels); #endif } // s24 -void mal_pcm_s24_to_u8__reference(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s24_to_u8__reference(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_uint8* dst_u8 = (mal_uint8*)dst; - const mal_uint8* src_s24 = (const mal_uint8*)src; + ma_uint8* dst_u8 = (ma_uint8*)dst; + const ma_uint8* src_s24 = (const ma_uint8*)src; - if (ditherMode == mal_dither_mode_none) { - mal_uint64 i; + if (ditherMode == ma_dither_mode_none) { + ma_uint64 i; for (i = 0; i < count; i += 1) { - mal_int8 x = (mal_int8)src_s24[i*3 + 2] + 128; - dst_u8[i] = (mal_uint8)x; + ma_int8 x = (ma_int8)src_s24[i*3 + 2] + 128; + dst_u8[i] = (ma_uint8)x; } } else { - mal_uint64 i; + ma_uint64 i; for (i = 0; i < count; i += 1) { - mal_int32 x = (mal_int32)(((mal_uint32)(src_s24[i*3+0]) << 8) | ((mal_uint32)(src_s24[i*3+1]) << 16) | ((mal_uint32)(src_s24[i*3+2])) << 24); + ma_int32 x = (ma_int32)(((ma_uint32)(src_s24[i*3+0]) << 8) | ((ma_uint32)(src_s24[i*3+1]) << 16) | ((ma_uint32)(src_s24[i*3+2])) << 24); // Dither. Don't overflow. - mal_int32 dither = mal_dither_s32(ditherMode, -0x800000, 0x7FFFFF); - if ((mal_int64)x + dither <= 0x7FFFFFFF) { + ma_int32 dither = ma_dither_s32(ditherMode, -0x800000, 0x7FFFFF); + if ((ma_int64)x + dither <= 0x7FFFFFFF) { x = x + dither; } else { x = 0x7FFFFFFF; @@ -24793,193 +24793,193 @@ void mal_pcm_s24_to_u8__reference(void* dst, const void* src, mal_uint64 count, x = x >> 24; x = x + 128; - dst_u8[i] = (mal_uint8)x; + dst_u8[i] = (ma_uint8)x; } } } -void mal_pcm_s24_to_u8__optimized(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s24_to_u8__optimized(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s24_to_u8__reference(dst, src, count, ditherMode); + ma_pcm_s24_to_u8__reference(dst, src, count, ditherMode); } #if defined(MA_SUPPORT_SSE2) -void mal_pcm_s24_to_u8__sse2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s24_to_u8__sse2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s24_to_u8__optimized(dst, src, count, ditherMode); + ma_pcm_s24_to_u8__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX2) -void mal_pcm_s24_to_u8__avx2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s24_to_u8__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s24_to_u8__optimized(dst, src, count, ditherMode); + ma_pcm_s24_to_u8__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX512) -void mal_pcm_s24_to_u8__avx512(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s24_to_u8__avx512(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s24_to_u8__avx2(dst, src, count, ditherMode); + ma_pcm_s24_to_u8__avx2(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_NEON) -void mal_pcm_s24_to_u8__neon(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s24_to_u8__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s24_to_u8__optimized(dst, src, count, ditherMode); + ma_pcm_s24_to_u8__optimized(dst, src, count, ditherMode); } #endif -void mal_pcm_s24_to_u8(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s24_to_u8(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { #ifdef MA_USE_REFERENCE_CONVERSION_APIS - mal_pcm_s24_to_u8__reference(dst, src, count, ditherMode); + ma_pcm_s24_to_u8__reference(dst, src, count, ditherMode); #else - mal_pcm_s24_to_u8__optimized(dst, src, count, ditherMode); + ma_pcm_s24_to_u8__optimized(dst, src, count, ditherMode); #endif } -void mal_pcm_s24_to_s16__reference(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s24_to_s16__reference(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_int16* dst_s16 = (mal_int16*)dst; - const mal_uint8* src_s24 = (const mal_uint8*)src; + ma_int16* dst_s16 = (ma_int16*)dst; + const ma_uint8* src_s24 = (const ma_uint8*)src; - if (ditherMode == mal_dither_mode_none) { - mal_uint64 i; + if (ditherMode == ma_dither_mode_none) { + ma_uint64 i; for (i = 0; i < count; i += 1) { - mal_uint16 dst_lo = ((mal_uint16)src_s24[i*3 + 1]); - mal_uint16 dst_hi = ((mal_uint16)src_s24[i*3 + 2]) << 8; - dst_s16[i] = (mal_int16)dst_lo | dst_hi; + ma_uint16 dst_lo = ((ma_uint16)src_s24[i*3 + 1]); + ma_uint16 dst_hi = ((ma_uint16)src_s24[i*3 + 2]) << 8; + dst_s16[i] = (ma_int16)dst_lo | dst_hi; } } else { - mal_uint64 i; + ma_uint64 i; for (i = 0; i < count; i += 1) { - mal_int32 x = (mal_int32)(((mal_uint32)(src_s24[i*3+0]) << 8) | ((mal_uint32)(src_s24[i*3+1]) << 16) | ((mal_uint32)(src_s24[i*3+2])) << 24); + ma_int32 x = (ma_int32)(((ma_uint32)(src_s24[i*3+0]) << 8) | ((ma_uint32)(src_s24[i*3+1]) << 16) | ((ma_uint32)(src_s24[i*3+2])) << 24); // Dither. Don't overflow. - mal_int32 dither = mal_dither_s32(ditherMode, -0x8000, 0x7FFF); - if ((mal_int64)x + dither <= 0x7FFFFFFF) { + ma_int32 dither = ma_dither_s32(ditherMode, -0x8000, 0x7FFF); + if ((ma_int64)x + dither <= 0x7FFFFFFF) { x = x + dither; } else { x = 0x7FFFFFFF; } x = x >> 16; - dst_s16[i] = (mal_int16)x; + dst_s16[i] = (ma_int16)x; } } } -void mal_pcm_s24_to_s16__optimized(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s24_to_s16__optimized(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s24_to_s16__reference(dst, src, count, ditherMode); + ma_pcm_s24_to_s16__reference(dst, src, count, ditherMode); } #if defined(MA_SUPPORT_SSE2) -void mal_pcm_s24_to_s16__sse2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s24_to_s16__sse2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s24_to_s16__optimized(dst, src, count, ditherMode); + ma_pcm_s24_to_s16__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX2) -void mal_pcm_s24_to_s16__avx2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s24_to_s16__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s24_to_s16__optimized(dst, src, count, ditherMode); + ma_pcm_s24_to_s16__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX512) -void mal_pcm_s24_to_s16__avx512(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s24_to_s16__avx512(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s24_to_s16__avx2(dst, src, count, ditherMode); + ma_pcm_s24_to_s16__avx2(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_NEON) -void mal_pcm_s24_to_s16__neon(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s24_to_s16__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s24_to_s16__optimized(dst, src, count, ditherMode); + ma_pcm_s24_to_s16__optimized(dst, src, count, ditherMode); } #endif -void mal_pcm_s24_to_s16(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s24_to_s16(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { #ifdef MA_USE_REFERENCE_CONVERSION_APIS - mal_pcm_s24_to_s16__reference(dst, src, count, ditherMode); + ma_pcm_s24_to_s16__reference(dst, src, count, ditherMode); #else - mal_pcm_s24_to_s16__optimized(dst, src, count, ditherMode); + ma_pcm_s24_to_s16__optimized(dst, src, count, ditherMode); #endif } -void mal_pcm_s24_to_s24(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s24_to_s24(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { (void)ditherMode; - mal_copy_memory_64(dst, src, count * 3); + ma_copy_memory_64(dst, src, count * 3); } -void mal_pcm_s24_to_s32__reference(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s24_to_s32__reference(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { (void)ditherMode; - mal_int32* dst_s32 = (mal_int32*)dst; - const mal_uint8* src_s24 = (const mal_uint8*)src; + ma_int32* dst_s32 = (ma_int32*)dst; + const ma_uint8* src_s24 = (const ma_uint8*)src; - mal_uint64 i; + ma_uint64 i; for (i = 0; i < count; i += 1) { - dst_s32[i] = (mal_int32)(((mal_uint32)(src_s24[i*3+0]) << 8) | ((mal_uint32)(src_s24[i*3+1]) << 16) | ((mal_uint32)(src_s24[i*3+2])) << 24); + dst_s32[i] = (ma_int32)(((ma_uint32)(src_s24[i*3+0]) << 8) | ((ma_uint32)(src_s24[i*3+1]) << 16) | ((ma_uint32)(src_s24[i*3+2])) << 24); } } -void mal_pcm_s24_to_s32__optimized(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s24_to_s32__optimized(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s24_to_s32__reference(dst, src, count, ditherMode); + ma_pcm_s24_to_s32__reference(dst, src, count, ditherMode); } #if defined(MA_SUPPORT_SSE2) -void mal_pcm_s24_to_s32__sse2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s24_to_s32__sse2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s24_to_s32__optimized(dst, src, count, ditherMode); + ma_pcm_s24_to_s32__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX2) -void mal_pcm_s24_to_s32__avx2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s24_to_s32__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s24_to_s32__optimized(dst, src, count, ditherMode); + ma_pcm_s24_to_s32__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX512) -void mal_pcm_s24_to_s32__avx512(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s24_to_s32__avx512(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s24_to_s32__avx2(dst, src, count, ditherMode); + ma_pcm_s24_to_s32__avx2(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_NEON) -void mal_pcm_s24_to_s32__neon(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s24_to_s32__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s24_to_s32__optimized(dst, src, count, ditherMode); + ma_pcm_s24_to_s32__optimized(dst, src, count, ditherMode); } #endif -void mal_pcm_s24_to_s32(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s24_to_s32(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { #ifdef MA_USE_REFERENCE_CONVERSION_APIS - mal_pcm_s24_to_s32__reference(dst, src, count, ditherMode); + ma_pcm_s24_to_s32__reference(dst, src, count, ditherMode); #else - mal_pcm_s24_to_s32__optimized(dst, src, count, ditherMode); + ma_pcm_s24_to_s32__optimized(dst, src, count, ditherMode); #endif } -void mal_pcm_s24_to_f32__reference(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s24_to_f32__reference(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { (void)ditherMode; float* dst_f32 = (float*)dst; - const mal_uint8* src_s24 = (const mal_uint8*)src; + const ma_uint8* src_s24 = (const ma_uint8*)src; - mal_uint64 i; + ma_uint64 i; for (i = 0; i < count; i += 1) { - float x = (float)(((mal_int32)(((mal_uint32)(src_s24[i*3+0]) << 8) | ((mal_uint32)(src_s24[i*3+1]) << 16) | ((mal_uint32)(src_s24[i*3+2])) << 24)) >> 8); + float x = (float)(((ma_int32)(((ma_uint32)(src_s24[i*3+0]) << 8) | ((ma_uint32)(src_s24[i*3+1]) << 16) | ((ma_uint32)(src_s24[i*3+2])) << 24)) >> 8); #if 0 // The accurate way. @@ -24995,54 +24995,54 @@ void mal_pcm_s24_to_f32__reference(void* dst, const void* src, mal_uint64 count, } } -void mal_pcm_s24_to_f32__optimized(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s24_to_f32__optimized(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s24_to_f32__reference(dst, src, count, ditherMode); + ma_pcm_s24_to_f32__reference(dst, src, count, ditherMode); } #if defined(MA_SUPPORT_SSE2) -void mal_pcm_s24_to_f32__sse2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s24_to_f32__sse2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s24_to_f32__optimized(dst, src, count, ditherMode); + ma_pcm_s24_to_f32__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX2) -void mal_pcm_s24_to_f32__avx2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s24_to_f32__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s24_to_f32__optimized(dst, src, count, ditherMode); + ma_pcm_s24_to_f32__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX512) -void mal_pcm_s24_to_f32__avx512(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s24_to_f32__avx512(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s24_to_f32__avx2(dst, src, count, ditherMode); + ma_pcm_s24_to_f32__avx2(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_NEON) -void mal_pcm_s24_to_f32__neon(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s24_to_f32__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s24_to_f32__optimized(dst, src, count, ditherMode); + ma_pcm_s24_to_f32__optimized(dst, src, count, ditherMode); } #endif -void mal_pcm_s24_to_f32(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s24_to_f32(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { #ifdef MA_USE_REFERENCE_CONVERSION_APIS - mal_pcm_s24_to_f32__reference(dst, src, count, ditherMode); + ma_pcm_s24_to_f32__reference(dst, src, count, ditherMode); #else - mal_pcm_s24_to_f32__optimized(dst, src, count, ditherMode); + ma_pcm_s24_to_f32__optimized(dst, src, count, ditherMode); #endif } -void mal_pcm_interleave_s24__reference(void* dst, const void** src, mal_uint64 frameCount, mal_uint32 channels) +void ma_pcm_interleave_s24__reference(void* dst, const void** src, ma_uint64 frameCount, ma_uint32 channels) { - mal_uint8* dst8 = (mal_uint8*)dst; - const mal_uint8** src8 = (const mal_uint8**)src; + ma_uint8* dst8 = (ma_uint8*)dst; + const ma_uint8** src8 = (const ma_uint8**)src; - mal_uint64 iFrame; + ma_uint64 iFrame; for (iFrame = 0; iFrame < frameCount; iFrame += 1) { - mal_uint32 iChannel; + ma_uint32 iChannel; for (iChannel = 0; iChannel < channels; iChannel += 1) { dst8[iFrame*3*channels + iChannel*3 + 0] = src8[iChannel][iFrame*3 + 0]; dst8[iFrame*3*channels + iChannel*3 + 1] = src8[iChannel][iFrame*3 + 1]; @@ -25051,29 +25051,29 @@ void mal_pcm_interleave_s24__reference(void* dst, const void** src, mal_uint64 f } } -void mal_pcm_interleave_s24__optimized(void* dst, const void** src, mal_uint64 frameCount, mal_uint32 channels) +void ma_pcm_interleave_s24__optimized(void* dst, const void** src, ma_uint64 frameCount, ma_uint32 channels) { - mal_pcm_interleave_s24__reference(dst, src, frameCount, channels); + ma_pcm_interleave_s24__reference(dst, src, frameCount, channels); } -void mal_pcm_interleave_s24(void* dst, const void** src, mal_uint64 frameCount, mal_uint32 channels) +void ma_pcm_interleave_s24(void* dst, const void** src, ma_uint64 frameCount, ma_uint32 channels) { #ifdef MA_USE_REFERENCE_CONVERSION_APIS - mal_pcm_interleave_s24__reference(dst, src, frameCount, channels); + ma_pcm_interleave_s24__reference(dst, src, frameCount, channels); #else - mal_pcm_interleave_s24__optimized(dst, src, frameCount, channels); + ma_pcm_interleave_s24__optimized(dst, src, frameCount, channels); #endif } -void mal_pcm_deinterleave_s24__reference(void** dst, const void* src, mal_uint64 frameCount, mal_uint32 channels) +void ma_pcm_deinterleave_s24__reference(void** dst, const void* src, ma_uint64 frameCount, ma_uint32 channels) { - mal_uint8** dst8 = (mal_uint8**)dst; - const mal_uint8* src8 = (const mal_uint8*)src; + ma_uint8** dst8 = (ma_uint8**)dst; + const ma_uint8* src8 = (const ma_uint8*)src; - mal_uint32 iFrame; + ma_uint32 iFrame; for (iFrame = 0; iFrame < frameCount; iFrame += 1) { - mal_uint32 iChannel; + ma_uint32 iChannel; for (iChannel = 0; iChannel < channels; iChannel += 1) { dst8[iChannel][iFrame*3 + 0] = src8[iFrame*3*channels + iChannel*3 + 0]; dst8[iChannel][iFrame*3 + 1] = src8[iFrame*3*channels + iChannel*3 + 1]; @@ -25082,44 +25082,44 @@ void mal_pcm_deinterleave_s24__reference(void** dst, const void* src, mal_uint64 } } -void mal_pcm_deinterleave_s24__optimized(void** dst, const void* src, mal_uint64 frameCount, mal_uint32 channels) +void ma_pcm_deinterleave_s24__optimized(void** dst, const void* src, ma_uint64 frameCount, ma_uint32 channels) { - mal_pcm_deinterleave_s24__reference(dst, src, frameCount, channels); + ma_pcm_deinterleave_s24__reference(dst, src, frameCount, channels); } -void mal_pcm_deinterleave_s24(void** dst, const void* src, mal_uint64 frameCount, mal_uint32 channels) +void ma_pcm_deinterleave_s24(void** dst, const void* src, ma_uint64 frameCount, ma_uint32 channels) { #ifdef MA_USE_REFERENCE_CONVERSION_APIS - mal_pcm_deinterleave_s24__reference(dst, src, frameCount, channels); + ma_pcm_deinterleave_s24__reference(dst, src, frameCount, channels); #else - mal_pcm_deinterleave_s24__optimized(dst, src, frameCount, channels); + ma_pcm_deinterleave_s24__optimized(dst, src, frameCount, channels); #endif } // s32 -void mal_pcm_s32_to_u8__reference(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s32_to_u8__reference(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_uint8* dst_u8 = (mal_uint8*)dst; - const mal_int32* src_s32 = (const mal_int32*)src; + ma_uint8* dst_u8 = (ma_uint8*)dst; + const ma_int32* src_s32 = (const ma_int32*)src; - if (ditherMode == mal_dither_mode_none) { - mal_uint64 i; + if (ditherMode == ma_dither_mode_none) { + ma_uint64 i; for (i = 0; i < count; i += 1) { - mal_int32 x = src_s32[i]; + ma_int32 x = src_s32[i]; x = x >> 24; x = x + 128; - dst_u8[i] = (mal_uint8)x; + dst_u8[i] = (ma_uint8)x; } } else { - mal_uint64 i; + ma_uint64 i; for (i = 0; i < count; i += 1) { - mal_int32 x = src_s32[i]; + ma_int32 x = src_s32[i]; // Dither. Don't overflow. - mal_int32 dither = mal_dither_s32(ditherMode, -0x800000, 0x7FFFFF); - if ((mal_int64)x + dither <= 0x7FFFFFFF) { + ma_int32 dither = ma_dither_s32(ditherMode, -0x800000, 0x7FFFFF); + if ((ma_int64)x + dither <= 0x7FFFFFFF) { x = x + dither; } else { x = 0x7FFFFFFF; @@ -25127,194 +25127,194 @@ void mal_pcm_s32_to_u8__reference(void* dst, const void* src, mal_uint64 count, x = x >> 24; x = x + 128; - dst_u8[i] = (mal_uint8)x; + dst_u8[i] = (ma_uint8)x; } } } -void mal_pcm_s32_to_u8__optimized(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s32_to_u8__optimized(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s32_to_u8__reference(dst, src, count, ditherMode); + ma_pcm_s32_to_u8__reference(dst, src, count, ditherMode); } #if defined(MA_SUPPORT_SSE2) -void mal_pcm_s32_to_u8__sse2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s32_to_u8__sse2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s32_to_u8__optimized(dst, src, count, ditherMode); + ma_pcm_s32_to_u8__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX2) -void mal_pcm_s32_to_u8__avx2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s32_to_u8__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s32_to_u8__optimized(dst, src, count, ditherMode); + ma_pcm_s32_to_u8__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX512) -void mal_pcm_s32_to_u8__avx512(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s32_to_u8__avx512(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s32_to_u8__avx2(dst, src, count, ditherMode); + ma_pcm_s32_to_u8__avx2(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_NEON) -void mal_pcm_s32_to_u8__neon(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s32_to_u8__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s32_to_u8__optimized(dst, src, count, ditherMode); + ma_pcm_s32_to_u8__optimized(dst, src, count, ditherMode); } #endif -void mal_pcm_s32_to_u8(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s32_to_u8(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { #ifdef MA_USE_REFERENCE_CONVERSION_APIS - mal_pcm_s32_to_u8__reference(dst, src, count, ditherMode); + ma_pcm_s32_to_u8__reference(dst, src, count, ditherMode); #else - mal_pcm_s32_to_u8__optimized(dst, src, count, ditherMode); + ma_pcm_s32_to_u8__optimized(dst, src, count, ditherMode); #endif } -void mal_pcm_s32_to_s16__reference(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s32_to_s16__reference(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_int16* dst_s16 = (mal_int16*)dst; - const mal_int32* src_s32 = (const mal_int32*)src; + ma_int16* dst_s16 = (ma_int16*)dst; + const ma_int32* src_s32 = (const ma_int32*)src; - if (ditherMode == mal_dither_mode_none) { - mal_uint64 i; + if (ditherMode == ma_dither_mode_none) { + ma_uint64 i; for (i = 0; i < count; i += 1) { - mal_int32 x = src_s32[i]; + ma_int32 x = src_s32[i]; x = x >> 16; - dst_s16[i] = (mal_int16)x; + dst_s16[i] = (ma_int16)x; } } else { - mal_uint64 i; + ma_uint64 i; for (i = 0; i < count; i += 1) { - mal_int32 x = src_s32[i]; + ma_int32 x = src_s32[i]; // Dither. Don't overflow. - mal_int32 dither = mal_dither_s32(ditherMode, -0x8000, 0x7FFF); - if ((mal_int64)x + dither <= 0x7FFFFFFF) { + ma_int32 dither = ma_dither_s32(ditherMode, -0x8000, 0x7FFF); + if ((ma_int64)x + dither <= 0x7FFFFFFF) { x = x + dither; } else { x = 0x7FFFFFFF; } x = x >> 16; - dst_s16[i] = (mal_int16)x; + dst_s16[i] = (ma_int16)x; } } } -void mal_pcm_s32_to_s16__optimized(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s32_to_s16__optimized(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s32_to_s16__reference(dst, src, count, ditherMode); + ma_pcm_s32_to_s16__reference(dst, src, count, ditherMode); } #if defined(MA_SUPPORT_SSE2) -void mal_pcm_s32_to_s16__sse2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s32_to_s16__sse2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s32_to_s16__optimized(dst, src, count, ditherMode); + ma_pcm_s32_to_s16__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX2) -void mal_pcm_s32_to_s16__avx2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s32_to_s16__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s32_to_s16__optimized(dst, src, count, ditherMode); + ma_pcm_s32_to_s16__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX512) -void mal_pcm_s32_to_s16__avx512(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s32_to_s16__avx512(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s32_to_s16__avx2(dst, src, count, ditherMode); + ma_pcm_s32_to_s16__avx2(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_NEON) -void mal_pcm_s32_to_s16__neon(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s32_to_s16__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s32_to_s16__optimized(dst, src, count, ditherMode); + ma_pcm_s32_to_s16__optimized(dst, src, count, ditherMode); } #endif -void mal_pcm_s32_to_s16(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s32_to_s16(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { #ifdef MA_USE_REFERENCE_CONVERSION_APIS - mal_pcm_s32_to_s16__reference(dst, src, count, ditherMode); + ma_pcm_s32_to_s16__reference(dst, src, count, ditherMode); #else - mal_pcm_s32_to_s16__optimized(dst, src, count, ditherMode); + ma_pcm_s32_to_s16__optimized(dst, src, count, ditherMode); #endif } -void mal_pcm_s32_to_s24__reference(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s32_to_s24__reference(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { (void)ditherMode; // No dithering for s32 -> s24. - mal_uint8* dst_s24 = (mal_uint8*)dst; - const mal_int32* src_s32 = (const mal_int32*)src; + ma_uint8* dst_s24 = (ma_uint8*)dst; + const ma_int32* src_s32 = (const ma_int32*)src; - mal_uint64 i; + ma_uint64 i; for (i = 0; i < count; i += 1) { - mal_uint32 x = (mal_uint32)src_s32[i]; - dst_s24[i*3+0] = (mal_uint8)((x & 0x0000FF00) >> 8); - dst_s24[i*3+1] = (mal_uint8)((x & 0x00FF0000) >> 16); - dst_s24[i*3+2] = (mal_uint8)((x & 0xFF000000) >> 24); + ma_uint32 x = (ma_uint32)src_s32[i]; + dst_s24[i*3+0] = (ma_uint8)((x & 0x0000FF00) >> 8); + dst_s24[i*3+1] = (ma_uint8)((x & 0x00FF0000) >> 16); + dst_s24[i*3+2] = (ma_uint8)((x & 0xFF000000) >> 24); } } -void mal_pcm_s32_to_s24__optimized(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s32_to_s24__optimized(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s32_to_s24__reference(dst, src, count, ditherMode); + ma_pcm_s32_to_s24__reference(dst, src, count, ditherMode); } #if defined(MA_SUPPORT_SSE2) -void mal_pcm_s32_to_s24__sse2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s32_to_s24__sse2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s32_to_s24__optimized(dst, src, count, ditherMode); + ma_pcm_s32_to_s24__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX2) -void mal_pcm_s32_to_s24__avx2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s32_to_s24__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s32_to_s24__optimized(dst, src, count, ditherMode); + ma_pcm_s32_to_s24__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX512) -void mal_pcm_s32_to_s24__avx512(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s32_to_s24__avx512(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s32_to_s24__avx2(dst, src, count, ditherMode); + ma_pcm_s32_to_s24__avx2(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_NEON) -void mal_pcm_s32_to_s24__neon(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s32_to_s24__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s32_to_s24__optimized(dst, src, count, ditherMode); + ma_pcm_s32_to_s24__optimized(dst, src, count, ditherMode); } #endif -void mal_pcm_s32_to_s24(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s32_to_s24(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { #ifdef MA_USE_REFERENCE_CONVERSION_APIS - mal_pcm_s32_to_s24__reference(dst, src, count, ditherMode); + ma_pcm_s32_to_s24__reference(dst, src, count, ditherMode); #else - mal_pcm_s32_to_s24__optimized(dst, src, count, ditherMode); + ma_pcm_s32_to_s24__optimized(dst, src, count, ditherMode); #endif } -void mal_pcm_s32_to_s32(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s32_to_s32(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { (void)ditherMode; - mal_copy_memory_64(dst, src, count * sizeof(mal_int32)); + ma_copy_memory_64(dst, src, count * sizeof(ma_int32)); } -void mal_pcm_s32_to_f32__reference(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s32_to_f32__reference(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { (void)ditherMode; // No dithering for s32 -> f32. float* dst_f32 = (float*)dst; - const mal_int32* src_s32 = (const mal_int32*)src; + const ma_int32* src_s32 = (const ma_int32*)src; - mal_uint64 i; + ma_uint64 i; for (i = 0; i < count; i += 1) { double x = src_s32[i]; @@ -25330,185 +25330,185 @@ void mal_pcm_s32_to_f32__reference(void* dst, const void* src, mal_uint64 count, } } -void mal_pcm_s32_to_f32__optimized(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s32_to_f32__optimized(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s32_to_f32__reference(dst, src, count, ditherMode); + ma_pcm_s32_to_f32__reference(dst, src, count, ditherMode); } #if defined(MA_SUPPORT_SSE2) -void mal_pcm_s32_to_f32__sse2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s32_to_f32__sse2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s32_to_f32__optimized(dst, src, count, ditherMode); + ma_pcm_s32_to_f32__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX2) -void mal_pcm_s32_to_f32__avx2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s32_to_f32__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s32_to_f32__optimized(dst, src, count, ditherMode); + ma_pcm_s32_to_f32__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX512) -void mal_pcm_s32_to_f32__avx512(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s32_to_f32__avx512(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s32_to_f32__avx2(dst, src, count, ditherMode); + ma_pcm_s32_to_f32__avx2(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_NEON) -void mal_pcm_s32_to_f32__neon(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s32_to_f32__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_s32_to_f32__optimized(dst, src, count, ditherMode); + ma_pcm_s32_to_f32__optimized(dst, src, count, ditherMode); } #endif -void mal_pcm_s32_to_f32(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_s32_to_f32(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { #ifdef MA_USE_REFERENCE_CONVERSION_APIS - mal_pcm_s32_to_f32__reference(dst, src, count, ditherMode); + ma_pcm_s32_to_f32__reference(dst, src, count, ditherMode); #else - mal_pcm_s32_to_f32__optimized(dst, src, count, ditherMode); + ma_pcm_s32_to_f32__optimized(dst, src, count, ditherMode); #endif } -void mal_pcm_interleave_s32__reference(void* dst, const void** src, mal_uint64 frameCount, mal_uint32 channels) +void ma_pcm_interleave_s32__reference(void* dst, const void** src, ma_uint64 frameCount, ma_uint32 channels) { - mal_int32* dst_s32 = (mal_int32*)dst; - const mal_int32** src_s32 = (const mal_int32**)src; + ma_int32* dst_s32 = (ma_int32*)dst; + const ma_int32** src_s32 = (const ma_int32**)src; - mal_uint64 iFrame; + ma_uint64 iFrame; for (iFrame = 0; iFrame < frameCount; iFrame += 1) { - mal_uint32 iChannel; + ma_uint32 iChannel; for (iChannel = 0; iChannel < channels; iChannel += 1) { dst_s32[iFrame*channels + iChannel] = src_s32[iChannel][iFrame]; } } } -void mal_pcm_interleave_s32__optimized(void* dst, const void** src, mal_uint64 frameCount, mal_uint32 channels) +void ma_pcm_interleave_s32__optimized(void* dst, const void** src, ma_uint64 frameCount, ma_uint32 channels) { - mal_pcm_interleave_s32__reference(dst, src, frameCount, channels); + ma_pcm_interleave_s32__reference(dst, src, frameCount, channels); } -void mal_pcm_interleave_s32(void* dst, const void** src, mal_uint64 frameCount, mal_uint32 channels) +void ma_pcm_interleave_s32(void* dst, const void** src, ma_uint64 frameCount, ma_uint32 channels) { #ifdef MA_USE_REFERENCE_CONVERSION_APIS - mal_pcm_interleave_s32__reference(dst, src, frameCount, channels); + ma_pcm_interleave_s32__reference(dst, src, frameCount, channels); #else - mal_pcm_interleave_s32__optimized(dst, src, frameCount, channels); + ma_pcm_interleave_s32__optimized(dst, src, frameCount, channels); #endif } -void mal_pcm_deinterleave_s32__reference(void** dst, const void* src, mal_uint64 frameCount, mal_uint32 channels) +void ma_pcm_deinterleave_s32__reference(void** dst, const void* src, ma_uint64 frameCount, ma_uint32 channels) { - mal_int32** dst_s32 = (mal_int32**)dst; - const mal_int32* src_s32 = (const mal_int32*)src; + ma_int32** dst_s32 = (ma_int32**)dst; + const ma_int32* src_s32 = (const ma_int32*)src; - mal_uint64 iFrame; + ma_uint64 iFrame; for (iFrame = 0; iFrame < frameCount; iFrame += 1) { - mal_uint32 iChannel; + ma_uint32 iChannel; for (iChannel = 0; iChannel < channels; iChannel += 1) { dst_s32[iChannel][iFrame] = src_s32[iFrame*channels + iChannel]; } } } -void mal_pcm_deinterleave_s32__optimized(void** dst, const void* src, mal_uint64 frameCount, mal_uint32 channels) +void ma_pcm_deinterleave_s32__optimized(void** dst, const void* src, ma_uint64 frameCount, ma_uint32 channels) { - mal_pcm_deinterleave_s32__reference(dst, src, frameCount, channels); + ma_pcm_deinterleave_s32__reference(dst, src, frameCount, channels); } -void mal_pcm_deinterleave_s32(void** dst, const void* src, mal_uint64 frameCount, mal_uint32 channels) +void ma_pcm_deinterleave_s32(void** dst, const void* src, ma_uint64 frameCount, ma_uint32 channels) { #ifdef MA_USE_REFERENCE_CONVERSION_APIS - mal_pcm_deinterleave_s32__reference(dst, src, frameCount, channels); + ma_pcm_deinterleave_s32__reference(dst, src, frameCount, channels); #else - mal_pcm_deinterleave_s32__optimized(dst, src, frameCount, channels); + ma_pcm_deinterleave_s32__optimized(dst, src, frameCount, channels); #endif } // f32 -void mal_pcm_f32_to_u8__reference(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_f32_to_u8__reference(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_uint8* dst_u8 = (mal_uint8*)dst; + ma_uint8* dst_u8 = (ma_uint8*)dst; const float* src_f32 = (const float*)src; float ditherMin = 0; float ditherMax = 0; - if (ditherMode != mal_dither_mode_none) { + if (ditherMode != ma_dither_mode_none) { ditherMin = 1.0f / -128; ditherMax = 1.0f / 127; } - mal_uint64 i; + ma_uint64 i; for (i = 0; i < count; i += 1) { float x = src_f32[i]; - x = x + mal_dither_f32(ditherMode, ditherMin, ditherMax); + x = x + ma_dither_f32(ditherMode, ditherMin, ditherMax); x = ((x < -1) ? -1 : ((x > 1) ? 1 : x)); // clip x = x + 1; // -1..1 to 0..2 x = x * 127.5f; // 0..2 to 0..255 - dst_u8[i] = (mal_uint8)x; + dst_u8[i] = (ma_uint8)x; } } -void mal_pcm_f32_to_u8__optimized(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_f32_to_u8__optimized(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_f32_to_u8__reference(dst, src, count, ditherMode); + ma_pcm_f32_to_u8__reference(dst, src, count, ditherMode); } #if defined(MA_SUPPORT_SSE2) -void mal_pcm_f32_to_u8__sse2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_f32_to_u8__sse2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_f32_to_u8__optimized(dst, src, count, ditherMode); + ma_pcm_f32_to_u8__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX2) -void mal_pcm_f32_to_u8__avx2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_f32_to_u8__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_f32_to_u8__optimized(dst, src, count, ditherMode); + ma_pcm_f32_to_u8__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX512) -void mal_pcm_f32_to_u8__avx512(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_f32_to_u8__avx512(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_f32_to_u8__avx2(dst, src, count, ditherMode); + ma_pcm_f32_to_u8__avx2(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_NEON) -void mal_pcm_f32_to_u8__neon(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_f32_to_u8__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_f32_to_u8__optimized(dst, src, count, ditherMode); + ma_pcm_f32_to_u8__optimized(dst, src, count, ditherMode); } #endif -void mal_pcm_f32_to_u8(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_f32_to_u8(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { #ifdef MA_USE_REFERENCE_CONVERSION_APIS - mal_pcm_f32_to_u8__reference(dst, src, count, ditherMode); + ma_pcm_f32_to_u8__reference(dst, src, count, ditherMode); #else - mal_pcm_f32_to_u8__optimized(dst, src, count, ditherMode); + ma_pcm_f32_to_u8__optimized(dst, src, count, ditherMode); #endif } -void mal_pcm_f32_to_s16__reference(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_f32_to_s16__reference(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_int16* dst_s16 = (mal_int16*)dst; + ma_int16* dst_s16 = (ma_int16*)dst; const float* src_f32 = (const float*)src; float ditherMin = 0; float ditherMax = 0; - if (ditherMode != mal_dither_mode_none) { + if (ditherMode != ma_dither_mode_none) { ditherMin = 1.0f / -32768; ditherMax = 1.0f / 32767; } - mal_uint64 i; + ma_uint64 i; for (i = 0; i < count; i += 1) { float x = src_f32[i]; - x = x + mal_dither_f32(ditherMode, ditherMin, ditherMax); + x = x + ma_dither_f32(ditherMode, ditherMin, ditherMax); x = ((x < -1) ? -1 : ((x > 1) ? 1 : x)); // clip #if 0 @@ -25521,31 +25521,31 @@ void mal_pcm_f32_to_s16__reference(void* dst, const void* src, mal_uint64 count, x = x * 32767.0f; // -1..1 to -32767..32767 #endif - dst_s16[i] = (mal_int16)x; + dst_s16[i] = (ma_int16)x; } } -void mal_pcm_f32_to_s16__optimized(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_f32_to_s16__optimized(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_int16* dst_s16 = (mal_int16*)dst; + ma_int16* dst_s16 = (ma_int16*)dst; const float* src_f32 = (const float*)src; float ditherMin = 0; float ditherMax = 0; - if (ditherMode != mal_dither_mode_none) { + if (ditherMode != ma_dither_mode_none) { ditherMin = 1.0f / -32768; ditherMax = 1.0f / 32767; } - mal_uint64 i = 0; + ma_uint64 i = 0; // Unrolled. - mal_uint64 count4 = count >> 2; - for (mal_uint64 i4 = 0; i4 < count4; i4 += 1) { - float d0 = mal_dither_f32(ditherMode, ditherMin, ditherMax); - float d1 = mal_dither_f32(ditherMode, ditherMin, ditherMax); - float d2 = mal_dither_f32(ditherMode, ditherMin, ditherMax); - float d3 = mal_dither_f32(ditherMode, ditherMin, ditherMax); + ma_uint64 count4 = count >> 2; + for (ma_uint64 i4 = 0; i4 < count4; i4 += 1) { + float d0 = ma_dither_f32(ditherMode, ditherMin, ditherMax); + float d1 = ma_dither_f32(ditherMode, ditherMin, ditherMax); + float d2 = ma_dither_f32(ditherMode, ditherMin, ditherMax); + float d3 = ma_dither_f32(ditherMode, ditherMin, ditherMax); float x0 = src_f32[i+0]; float x1 = src_f32[i+1]; @@ -25567,10 +25567,10 @@ void mal_pcm_f32_to_s16__optimized(void* dst, const void* src, mal_uint64 count, x2 = x2 * 32767.0f; x3 = x3 * 32767.0f; - dst_s16[i+0] = (mal_int16)x0; - dst_s16[i+1] = (mal_int16)x1; - dst_s16[i+2] = (mal_int16)x2; - dst_s16[i+3] = (mal_int16)x3; + dst_s16[i+0] = (ma_int16)x0; + dst_s16[i+1] = (ma_int16)x1; + dst_s16[i+2] = (ma_int16)x2; + dst_s16[i+3] = (ma_int16)x3; i += 4; } @@ -25578,68 +25578,68 @@ void mal_pcm_f32_to_s16__optimized(void* dst, const void* src, mal_uint64 count, // Leftover. for (; i < count; i += 1) { float x = src_f32[i]; - x = x + mal_dither_f32(ditherMode, ditherMin, ditherMax); + x = x + ma_dither_f32(ditherMode, ditherMin, ditherMax); x = ((x < -1) ? -1 : ((x > 1) ? 1 : x)); // clip x = x * 32767.0f; // -1..1 to -32767..32767 - dst_s16[i] = (mal_int16)x; + dst_s16[i] = (ma_int16)x; } } #if defined(MA_SUPPORT_SSE2) -void mal_pcm_f32_to_s16__sse2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_f32_to_s16__sse2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { // Both the input and output buffers need to be aligned to 16 bytes. - if ((((mal_uintptr)dst & 15) != 0) || (((mal_uintptr)src & 15) != 0)) { - mal_pcm_f32_to_s16__optimized(dst, src, count, ditherMode); + if ((((ma_uintptr)dst & 15) != 0) || (((ma_uintptr)src & 15) != 0)) { + ma_pcm_f32_to_s16__optimized(dst, src, count, ditherMode); return; } - mal_int16* dst_s16 = (mal_int16*)dst; + ma_int16* dst_s16 = (ma_int16*)dst; const float* src_f32 = (const float*)src; float ditherMin = 0; float ditherMax = 0; - if (ditherMode != mal_dither_mode_none) { + if (ditherMode != ma_dither_mode_none) { ditherMin = 1.0f / -32768; ditherMax = 1.0f / 32767; } - mal_uint64 i = 0; + ma_uint64 i = 0; // SSE2. SSE allows us to output 8 s16's at a time which means our loop is unrolled 8 times. - mal_uint64 count8 = count >> 3; - for (mal_uint64 i8 = 0; i8 < count8; i8 += 1) { + ma_uint64 count8 = count >> 3; + for (ma_uint64 i8 = 0; i8 < count8; i8 += 1) { __m128 d0; __m128 d1; - if (ditherMode == mal_dither_mode_none) { + if (ditherMode == ma_dither_mode_none) { d0 = _mm_set1_ps(0); d1 = _mm_set1_ps(0); - } else if (ditherMode == mal_dither_mode_rectangle) { + } else if (ditherMode == ma_dither_mode_rectangle) { d0 = _mm_set_ps( - mal_dither_f32_rectangle(ditherMin, ditherMax), - mal_dither_f32_rectangle(ditherMin, ditherMax), - mal_dither_f32_rectangle(ditherMin, ditherMax), - mal_dither_f32_rectangle(ditherMin, ditherMax) + ma_dither_f32_rectangle(ditherMin, ditherMax), + ma_dither_f32_rectangle(ditherMin, ditherMax), + ma_dither_f32_rectangle(ditherMin, ditherMax), + ma_dither_f32_rectangle(ditherMin, ditherMax) ); d1 = _mm_set_ps( - mal_dither_f32_rectangle(ditherMin, ditherMax), - mal_dither_f32_rectangle(ditherMin, ditherMax), - mal_dither_f32_rectangle(ditherMin, ditherMax), - mal_dither_f32_rectangle(ditherMin, ditherMax) + ma_dither_f32_rectangle(ditherMin, ditherMax), + ma_dither_f32_rectangle(ditherMin, ditherMax), + ma_dither_f32_rectangle(ditherMin, ditherMax), + ma_dither_f32_rectangle(ditherMin, ditherMax) ); } else { d0 = _mm_set_ps( - mal_dither_f32_triangle(ditherMin, ditherMax), - mal_dither_f32_triangle(ditherMin, ditherMax), - mal_dither_f32_triangle(ditherMin, ditherMax), - mal_dither_f32_triangle(ditherMin, ditherMax) + ma_dither_f32_triangle(ditherMin, ditherMax), + ma_dither_f32_triangle(ditherMin, ditherMax), + ma_dither_f32_triangle(ditherMin, ditherMax), + ma_dither_f32_triangle(ditherMin, ditherMax) ); d1 = _mm_set_ps( - mal_dither_f32_triangle(ditherMin, ditherMax), - mal_dither_f32_triangle(ditherMin, ditherMax), - mal_dither_f32_triangle(ditherMin, ditherMax), - mal_dither_f32_triangle(ditherMin, ditherMax) + ma_dither_f32_triangle(ditherMin, ditherMax), + ma_dither_f32_triangle(ditherMin, ditherMax), + ma_dither_f32_triangle(ditherMin, ditherMax), + ma_dither_f32_triangle(ditherMin, ditherMax) ); } @@ -25661,84 +25661,84 @@ void mal_pcm_f32_to_s16__sse2(void* dst, const void* src, mal_uint64 count, mal_ // Leftover. for (; i < count; i += 1) { float x = src_f32[i]; - x = x + mal_dither_f32(ditherMode, ditherMin, ditherMax); + x = x + ma_dither_f32(ditherMode, ditherMin, ditherMax); x = ((x < -1) ? -1 : ((x > 1) ? 1 : x)); // clip x = x * 32767.0f; // -1..1 to -32767..32767 - dst_s16[i] = (mal_int16)x; + dst_s16[i] = (ma_int16)x; } } #endif #if defined(MA_SUPPORT_AVX2) -void mal_pcm_f32_to_s16__avx2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_f32_to_s16__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { // Both the input and output buffers need to be aligned to 32 bytes. - if ((((mal_uintptr)dst & 31) != 0) || (((mal_uintptr)src & 31) != 0)) { - mal_pcm_f32_to_s16__optimized(dst, src, count, ditherMode); + if ((((ma_uintptr)dst & 31) != 0) || (((ma_uintptr)src & 31) != 0)) { + ma_pcm_f32_to_s16__optimized(dst, src, count, ditherMode); return; } - mal_int16* dst_s16 = (mal_int16*)dst; + ma_int16* dst_s16 = (ma_int16*)dst; const float* src_f32 = (const float*)src; float ditherMin = 0; float ditherMax = 0; - if (ditherMode != mal_dither_mode_none) { + if (ditherMode != ma_dither_mode_none) { ditherMin = 1.0f / -32768; ditherMax = 1.0f / 32767; } - mal_uint64 i = 0; + ma_uint64 i = 0; // AVX2. AVX2 allows us to output 16 s16's at a time which means our loop is unrolled 16 times. - mal_uint64 count16 = count >> 4; - for (mal_uint64 i16 = 0; i16 < count16; i16 += 1) { + ma_uint64 count16 = count >> 4; + for (ma_uint64 i16 = 0; i16 < count16; i16 += 1) { __m256 d0; __m256 d1; - if (ditherMode == mal_dither_mode_none) { + if (ditherMode == ma_dither_mode_none) { d0 = _mm256_set1_ps(0); d1 = _mm256_set1_ps(0); - } else if (ditherMode == mal_dither_mode_rectangle) { + } else if (ditherMode == ma_dither_mode_rectangle) { d0 = _mm256_set_ps( - mal_dither_f32_rectangle(ditherMin, ditherMax), - mal_dither_f32_rectangle(ditherMin, ditherMax), - mal_dither_f32_rectangle(ditherMin, ditherMax), - mal_dither_f32_rectangle(ditherMin, ditherMax), - mal_dither_f32_rectangle(ditherMin, ditherMax), - mal_dither_f32_rectangle(ditherMin, ditherMax), - mal_dither_f32_rectangle(ditherMin, ditherMax), - mal_dither_f32_rectangle(ditherMin, ditherMax) + ma_dither_f32_rectangle(ditherMin, ditherMax), + ma_dither_f32_rectangle(ditherMin, ditherMax), + ma_dither_f32_rectangle(ditherMin, ditherMax), + ma_dither_f32_rectangle(ditherMin, ditherMax), + ma_dither_f32_rectangle(ditherMin, ditherMax), + ma_dither_f32_rectangle(ditherMin, ditherMax), + ma_dither_f32_rectangle(ditherMin, ditherMax), + ma_dither_f32_rectangle(ditherMin, ditherMax) ); d1 = _mm256_set_ps( - mal_dither_f32_rectangle(ditherMin, ditherMax), - mal_dither_f32_rectangle(ditherMin, ditherMax), - mal_dither_f32_rectangle(ditherMin, ditherMax), - mal_dither_f32_rectangle(ditherMin, ditherMax), - mal_dither_f32_rectangle(ditherMin, ditherMax), - mal_dither_f32_rectangle(ditherMin, ditherMax), - mal_dither_f32_rectangle(ditherMin, ditherMax), - mal_dither_f32_rectangle(ditherMin, ditherMax) + ma_dither_f32_rectangle(ditherMin, ditherMax), + ma_dither_f32_rectangle(ditherMin, ditherMax), + ma_dither_f32_rectangle(ditherMin, ditherMax), + ma_dither_f32_rectangle(ditherMin, ditherMax), + ma_dither_f32_rectangle(ditherMin, ditherMax), + ma_dither_f32_rectangle(ditherMin, ditherMax), + ma_dither_f32_rectangle(ditherMin, ditherMax), + ma_dither_f32_rectangle(ditherMin, ditherMax) ); } else { d0 = _mm256_set_ps( - mal_dither_f32_triangle(ditherMin, ditherMax), - mal_dither_f32_triangle(ditherMin, ditherMax), - mal_dither_f32_triangle(ditherMin, ditherMax), - mal_dither_f32_triangle(ditherMin, ditherMax), - mal_dither_f32_triangle(ditherMin, ditherMax), - mal_dither_f32_triangle(ditherMin, ditherMax), - mal_dither_f32_triangle(ditherMin, ditherMax), - mal_dither_f32_triangle(ditherMin, ditherMax) + ma_dither_f32_triangle(ditherMin, ditherMax), + ma_dither_f32_triangle(ditherMin, ditherMax), + ma_dither_f32_triangle(ditherMin, ditherMax), + ma_dither_f32_triangle(ditherMin, ditherMax), + ma_dither_f32_triangle(ditherMin, ditherMax), + ma_dither_f32_triangle(ditherMin, ditherMax), + ma_dither_f32_triangle(ditherMin, ditherMax), + ma_dither_f32_triangle(ditherMin, ditherMax) ); d1 = _mm256_set_ps( - mal_dither_f32_triangle(ditherMin, ditherMax), - mal_dither_f32_triangle(ditherMin, ditherMax), - mal_dither_f32_triangle(ditherMin, ditherMax), - mal_dither_f32_triangle(ditherMin, ditherMax), - mal_dither_f32_triangle(ditherMin, ditherMax), - mal_dither_f32_triangle(ditherMin, ditherMax), - mal_dither_f32_triangle(ditherMin, ditherMax), - mal_dither_f32_triangle(ditherMin, ditherMax) + ma_dither_f32_triangle(ditherMin, ditherMax), + ma_dither_f32_triangle(ditherMin, ditherMax), + ma_dither_f32_triangle(ditherMin, ditherMax), + ma_dither_f32_triangle(ditherMin, ditherMax), + ma_dither_f32_triangle(ditherMin, ditherMax), + ma_dither_f32_triangle(ditherMin, ditherMax), + ma_dither_f32_triangle(ditherMin, ditherMax), + ma_dither_f32_triangle(ditherMin, ditherMax) ); } @@ -25767,77 +25767,77 @@ void mal_pcm_f32_to_s16__avx2(void* dst, const void* src, mal_uint64 count, mal_ // Leftover. for (; i < count; i += 1) { float x = src_f32[i]; - x = x + mal_dither_f32(ditherMode, ditherMin, ditherMax); + x = x + ma_dither_f32(ditherMode, ditherMin, ditherMax); x = ((x < -1) ? -1 : ((x > 1) ? 1 : x)); // clip x = x * 32767.0f; // -1..1 to -32767..32767 - dst_s16[i] = (mal_int16)x; + dst_s16[i] = (ma_int16)x; } } #endif #if defined(MA_SUPPORT_AVX512) -void mal_pcm_f32_to_s16__avx512(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_f32_to_s16__avx512(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { // TODO: Convert this from AVX to AVX-512. - mal_pcm_f32_to_s16__avx2(dst, src, count, ditherMode); + ma_pcm_f32_to_s16__avx2(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_NEON) -void mal_pcm_f32_to_s16__neon(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_f32_to_s16__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { // Both the input and output buffers need to be aligned to 16 bytes. - if ((((mal_uintptr)dst & 15) != 0) || (((mal_uintptr)src & 15) != 0)) { - mal_pcm_f32_to_s16__optimized(dst, src, count, ditherMode); + if ((((ma_uintptr)dst & 15) != 0) || (((ma_uintptr)src & 15) != 0)) { + ma_pcm_f32_to_s16__optimized(dst, src, count, ditherMode); return; } - mal_int16* dst_s16 = (mal_int16*)dst; + ma_int16* dst_s16 = (ma_int16*)dst; const float* src_f32 = (const float*)src; float ditherMin = 0; float ditherMax = 0; - if (ditherMode != mal_dither_mode_none) { + if (ditherMode != ma_dither_mode_none) { ditherMin = 1.0f / -32768; ditherMax = 1.0f / 32767; } - mal_uint64 i = 0; + ma_uint64 i = 0; // NEON. NEON allows us to output 8 s16's at a time which means our loop is unrolled 8 times. - mal_uint64 count8 = count >> 3; - for (mal_uint64 i8 = 0; i8 < count8; i8 += 1) { + ma_uint64 count8 = count >> 3; + for (ma_uint64 i8 = 0; i8 < count8; i8 += 1) { float32x4_t d0; float32x4_t d1; - if (ditherMode == mal_dither_mode_none) { + if (ditherMode == ma_dither_mode_none) { d0 = vmovq_n_f32(0); d1 = vmovq_n_f32(0); - } else if (ditherMode == mal_dither_mode_rectangle) { + } else if (ditherMode == ma_dither_mode_rectangle) { float d0v[4]; - d0v[0] = mal_dither_f32_rectangle(ditherMin, ditherMax); - d0v[1] = mal_dither_f32_rectangle(ditherMin, ditherMax); - d0v[2] = mal_dither_f32_rectangle(ditherMin, ditherMax); - d0v[3] = mal_dither_f32_rectangle(ditherMin, ditherMax); + d0v[0] = ma_dither_f32_rectangle(ditherMin, ditherMax); + d0v[1] = ma_dither_f32_rectangle(ditherMin, ditherMax); + d0v[2] = ma_dither_f32_rectangle(ditherMin, ditherMax); + d0v[3] = ma_dither_f32_rectangle(ditherMin, ditherMax); d0 = vld1q_f32(d0v); float d1v[4]; - d1v[0] = mal_dither_f32_rectangle(ditherMin, ditherMax); - d1v[1] = mal_dither_f32_rectangle(ditherMin, ditherMax); - d1v[2] = mal_dither_f32_rectangle(ditherMin, ditherMax); - d1v[3] = mal_dither_f32_rectangle(ditherMin, ditherMax); + d1v[0] = ma_dither_f32_rectangle(ditherMin, ditherMax); + d1v[1] = ma_dither_f32_rectangle(ditherMin, ditherMax); + d1v[2] = ma_dither_f32_rectangle(ditherMin, ditherMax); + d1v[3] = ma_dither_f32_rectangle(ditherMin, ditherMax); d1 = vld1q_f32(d1v); } else { float d0v[4]; - d0v[0] = mal_dither_f32_triangle(ditherMin, ditherMax); - d0v[1] = mal_dither_f32_triangle(ditherMin, ditherMax); - d0v[2] = mal_dither_f32_triangle(ditherMin, ditherMax); - d0v[3] = mal_dither_f32_triangle(ditherMin, ditherMax); + d0v[0] = ma_dither_f32_triangle(ditherMin, ditherMax); + d0v[1] = ma_dither_f32_triangle(ditherMin, ditherMax); + d0v[2] = ma_dither_f32_triangle(ditherMin, ditherMax); + d0v[3] = ma_dither_f32_triangle(ditherMin, ditherMax); d0 = vld1q_f32(d0v); float d1v[4]; - d1v[0] = mal_dither_f32_triangle(ditherMin, ditherMax); - d1v[1] = mal_dither_f32_triangle(ditherMin, ditherMax); - d1v[2] = mal_dither_f32_triangle(ditherMin, ditherMax); - d1v[3] = mal_dither_f32_triangle(ditherMin, ditherMax); + d1v[0] = ma_dither_f32_triangle(ditherMin, ditherMax); + d1v[1] = ma_dither_f32_triangle(ditherMin, ditherMax); + d1v[2] = ma_dither_f32_triangle(ditherMin, ditherMax); + d1v[3] = ma_dither_f32_triangle(ditherMin, ditherMax); d1 = vld1q_f32(d1v); } @@ -25861,33 +25861,33 @@ void mal_pcm_f32_to_s16__neon(void* dst, const void* src, mal_uint64 count, mal_ // Leftover. for (; i < count; i += 1) { float x = src_f32[i]; - x = x + mal_dither_f32(ditherMode, ditherMin, ditherMax); + x = x + ma_dither_f32(ditherMode, ditherMin, ditherMax); x = ((x < -1) ? -1 : ((x > 1) ? 1 : x)); // clip x = x * 32767.0f; // -1..1 to -32767..32767 - dst_s16[i] = (mal_int16)x; + dst_s16[i] = (ma_int16)x; } } #endif -void mal_pcm_f32_to_s16(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_f32_to_s16(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { #ifdef MA_USE_REFERENCE_CONVERSION_APIS - mal_pcm_f32_to_s16__reference(dst, src, count, ditherMode); + ma_pcm_f32_to_s16__reference(dst, src, count, ditherMode); #else - mal_pcm_f32_to_s16__optimized(dst, src, count, ditherMode); + ma_pcm_f32_to_s16__optimized(dst, src, count, ditherMode); #endif } -void mal_pcm_f32_to_s24__reference(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_f32_to_s24__reference(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { (void)ditherMode; // No dithering for f32 -> s24. - mal_uint8* dst_s24 = (mal_uint8*)dst; + ma_uint8* dst_s24 = (ma_uint8*)dst; const float* src_f32 = (const float*)src; - mal_uint64 i; + ma_uint64 i; for (i = 0; i < count; i += 1) { float x = src_f32[i]; x = ((x < -1) ? -1 : ((x > 1) ? 1 : x)); // clip @@ -25902,61 +25902,61 @@ void mal_pcm_f32_to_s24__reference(void* dst, const void* src, mal_uint64 count, x = x * 8388607.0f; // -1..1 to -8388607..8388607 #endif - mal_int32 r = (mal_int32)x; - dst_s24[(i*3)+0] = (mal_uint8)((r & 0x0000FF) >> 0); - dst_s24[(i*3)+1] = (mal_uint8)((r & 0x00FF00) >> 8); - dst_s24[(i*3)+2] = (mal_uint8)((r & 0xFF0000) >> 16); + ma_int32 r = (ma_int32)x; + dst_s24[(i*3)+0] = (ma_uint8)((r & 0x0000FF) >> 0); + dst_s24[(i*3)+1] = (ma_uint8)((r & 0x00FF00) >> 8); + dst_s24[(i*3)+2] = (ma_uint8)((r & 0xFF0000) >> 16); } } -void mal_pcm_f32_to_s24__optimized(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_f32_to_s24__optimized(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_f32_to_s24__reference(dst, src, count, ditherMode); + ma_pcm_f32_to_s24__reference(dst, src, count, ditherMode); } #if defined(MA_SUPPORT_SSE2) -void mal_pcm_f32_to_s24__sse2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_f32_to_s24__sse2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_f32_to_s24__optimized(dst, src, count, ditherMode); + ma_pcm_f32_to_s24__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX2) -void mal_pcm_f32_to_s24__avx2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_f32_to_s24__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_f32_to_s24__optimized(dst, src, count, ditherMode); + ma_pcm_f32_to_s24__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX512) -void mal_pcm_f32_to_s24__avx512(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_f32_to_s24__avx512(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_f32_to_s24__avx2(dst, src, count, ditherMode); + ma_pcm_f32_to_s24__avx2(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_NEON) -void mal_pcm_f32_to_s24__neon(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_f32_to_s24__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_f32_to_s24__optimized(dst, src, count, ditherMode); + ma_pcm_f32_to_s24__optimized(dst, src, count, ditherMode); } #endif -void mal_pcm_f32_to_s24(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_f32_to_s24(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { #ifdef MA_USE_REFERENCE_CONVERSION_APIS - mal_pcm_f32_to_s24__reference(dst, src, count, ditherMode); + ma_pcm_f32_to_s24__reference(dst, src, count, ditherMode); #else - mal_pcm_f32_to_s24__optimized(dst, src, count, ditherMode); + ma_pcm_f32_to_s24__optimized(dst, src, count, ditherMode); #endif } -void mal_pcm_f32_to_s32__reference(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_f32_to_s32__reference(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { (void)ditherMode; // No dithering for f32 -> s32. - mal_int32* dst_s32 = (mal_int32*)dst; + ma_int32* dst_s32 = (ma_int32*)dst; const float* src_f32 = (const float*)src; - mal_uint32 i; + ma_uint32 i; for (i = 0; i < count; i += 1) { double x = src_f32[i]; x = ((x < -1) ? -1 : ((x > 1) ? 1 : x)); // clip @@ -25971,280 +25971,280 @@ void mal_pcm_f32_to_s32__reference(void* dst, const void* src, mal_uint64 count, x = x * 2147483647.0; // -1..1 to -2147483647..2147483647 #endif - dst_s32[i] = (mal_int32)x; + dst_s32[i] = (ma_int32)x; } } -void mal_pcm_f32_to_s32__optimized(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_f32_to_s32__optimized(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_f32_to_s32__reference(dst, src, count, ditherMode); + ma_pcm_f32_to_s32__reference(dst, src, count, ditherMode); } #if defined(MA_SUPPORT_SSE2) -void mal_pcm_f32_to_s32__sse2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_f32_to_s32__sse2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_f32_to_s32__optimized(dst, src, count, ditherMode); + ma_pcm_f32_to_s32__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX2) -void mal_pcm_f32_to_s32__avx2(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_f32_to_s32__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_f32_to_s32__optimized(dst, src, count, ditherMode); + ma_pcm_f32_to_s32__optimized(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_AVX512) -void mal_pcm_f32_to_s32__avx512(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_f32_to_s32__avx512(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_f32_to_s32__avx2(dst, src, count, ditherMode); + ma_pcm_f32_to_s32__avx2(dst, src, count, ditherMode); } #endif #if defined(MA_SUPPORT_NEON) -void mal_pcm_f32_to_s32__neon(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_f32_to_s32__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { - mal_pcm_f32_to_s32__optimized(dst, src, count, ditherMode); + ma_pcm_f32_to_s32__optimized(dst, src, count, ditherMode); } #endif -void mal_pcm_f32_to_s32(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_f32_to_s32(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { #ifdef MA_USE_REFERENCE_CONVERSION_APIS - mal_pcm_f32_to_s32__reference(dst, src, count, ditherMode); + ma_pcm_f32_to_s32__reference(dst, src, count, ditherMode); #else - mal_pcm_f32_to_s32__optimized(dst, src, count, ditherMode); + ma_pcm_f32_to_s32__optimized(dst, src, count, ditherMode); #endif } -void mal_pcm_f32_to_f32(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) +void ma_pcm_f32_to_f32(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) { (void)ditherMode; - mal_copy_memory_64(dst, src, count * sizeof(float)); + ma_copy_memory_64(dst, src, count * sizeof(float)); } -void mal_pcm_interleave_f32__reference(void* dst, const void** src, mal_uint64 frameCount, mal_uint32 channels) +void ma_pcm_interleave_f32__reference(void* dst, const void** src, ma_uint64 frameCount, ma_uint32 channels) { float* dst_f32 = (float*)dst; const float** src_f32 = (const float**)src; - mal_uint64 iFrame; + ma_uint64 iFrame; for (iFrame = 0; iFrame < frameCount; iFrame += 1) { - mal_uint32 iChannel; + ma_uint32 iChannel; for (iChannel = 0; iChannel < channels; iChannel += 1) { dst_f32[iFrame*channels + iChannel] = src_f32[iChannel][iFrame]; } } } -void mal_pcm_interleave_f32__optimized(void* dst, const void** src, mal_uint64 frameCount, mal_uint32 channels) +void ma_pcm_interleave_f32__optimized(void* dst, const void** src, ma_uint64 frameCount, ma_uint32 channels) { - mal_pcm_interleave_f32__reference(dst, src, frameCount, channels); + ma_pcm_interleave_f32__reference(dst, src, frameCount, channels); } -void mal_pcm_interleave_f32(void* dst, const void** src, mal_uint64 frameCount, mal_uint32 channels) +void ma_pcm_interleave_f32(void* dst, const void** src, ma_uint64 frameCount, ma_uint32 channels) { #ifdef MA_USE_REFERENCE_CONVERSION_APIS - mal_pcm_interleave_f32__reference(dst, src, frameCount, channels); + ma_pcm_interleave_f32__reference(dst, src, frameCount, channels); #else - mal_pcm_interleave_f32__optimized(dst, src, frameCount, channels); + ma_pcm_interleave_f32__optimized(dst, src, frameCount, channels); #endif } -void mal_pcm_deinterleave_f32__reference(void** dst, const void* src, mal_uint64 frameCount, mal_uint32 channels) +void ma_pcm_deinterleave_f32__reference(void** dst, const void* src, ma_uint64 frameCount, ma_uint32 channels) { float** dst_f32 = (float**)dst; const float* src_f32 = (const float*)src; - mal_uint64 iFrame; + ma_uint64 iFrame; for (iFrame = 0; iFrame < frameCount; iFrame += 1) { - mal_uint32 iChannel; + ma_uint32 iChannel; for (iChannel = 0; iChannel < channels; iChannel += 1) { dst_f32[iChannel][iFrame] = src_f32[iFrame*channels + iChannel]; } } } -void mal_pcm_deinterleave_f32__optimized(void** dst, const void* src, mal_uint64 frameCount, mal_uint32 channels) +void ma_pcm_deinterleave_f32__optimized(void** dst, const void* src, ma_uint64 frameCount, ma_uint32 channels) { - mal_pcm_deinterleave_f32__reference(dst, src, frameCount, channels); + ma_pcm_deinterleave_f32__reference(dst, src, frameCount, channels); } -void mal_pcm_deinterleave_f32(void** dst, const void* src, mal_uint64 frameCount, mal_uint32 channels) +void ma_pcm_deinterleave_f32(void** dst, const void* src, ma_uint64 frameCount, ma_uint32 channels) { #ifdef MA_USE_REFERENCE_CONVERSION_APIS - mal_pcm_deinterleave_f32__reference(dst, src, frameCount, channels); + ma_pcm_deinterleave_f32__reference(dst, src, frameCount, channels); #else - mal_pcm_deinterleave_f32__optimized(dst, src, frameCount, channels); + ma_pcm_deinterleave_f32__optimized(dst, src, frameCount, channels); #endif } -void mal_format_converter_init_callbacks__default(mal_format_converter* pConverter) +void ma_format_converter_init_callbacks__default(ma_format_converter* pConverter) { - mal_assert(pConverter != NULL); + ma_assert(pConverter != NULL); switch (pConverter->config.formatIn) { - case mal_format_u8: + case ma_format_u8: { - if (pConverter->config.formatOut == mal_format_u8) { - pConverter->onConvertPCM = mal_pcm_u8_to_u8; - } else if (pConverter->config.formatOut == mal_format_s16) { - pConverter->onConvertPCM = mal_pcm_u8_to_s16; - } else if (pConverter->config.formatOut == mal_format_s24) { - pConverter->onConvertPCM = mal_pcm_u8_to_s24; - } else if (pConverter->config.formatOut == mal_format_s32) { - pConverter->onConvertPCM = mal_pcm_u8_to_s32; - } else if (pConverter->config.formatOut == mal_format_f32) { - pConverter->onConvertPCM = mal_pcm_u8_to_f32; + if (pConverter->config.formatOut == ma_format_u8) { + pConverter->onConvertPCM = ma_pcm_u8_to_u8; + } else if (pConverter->config.formatOut == ma_format_s16) { + pConverter->onConvertPCM = ma_pcm_u8_to_s16; + } else if (pConverter->config.formatOut == ma_format_s24) { + pConverter->onConvertPCM = ma_pcm_u8_to_s24; + } else if (pConverter->config.formatOut == ma_format_s32) { + pConverter->onConvertPCM = ma_pcm_u8_to_s32; + } else if (pConverter->config.formatOut == ma_format_f32) { + pConverter->onConvertPCM = ma_pcm_u8_to_f32; } } break; - case mal_format_s16: + case ma_format_s16: { - if (pConverter->config.formatOut == mal_format_u8) { - pConverter->onConvertPCM = mal_pcm_s16_to_u8; - } else if (pConverter->config.formatOut == mal_format_s16) { - pConverter->onConvertPCM = mal_pcm_s16_to_s16; - } else if (pConverter->config.formatOut == mal_format_s24) { - pConverter->onConvertPCM = mal_pcm_s16_to_s24; - } else if (pConverter->config.formatOut == mal_format_s32) { - pConverter->onConvertPCM = mal_pcm_s16_to_s32; - } else if (pConverter->config.formatOut == mal_format_f32) { - pConverter->onConvertPCM = mal_pcm_s16_to_f32; + if (pConverter->config.formatOut == ma_format_u8) { + pConverter->onConvertPCM = ma_pcm_s16_to_u8; + } else if (pConverter->config.formatOut == ma_format_s16) { + pConverter->onConvertPCM = ma_pcm_s16_to_s16; + } else if (pConverter->config.formatOut == ma_format_s24) { + pConverter->onConvertPCM = ma_pcm_s16_to_s24; + } else if (pConverter->config.formatOut == ma_format_s32) { + pConverter->onConvertPCM = ma_pcm_s16_to_s32; + } else if (pConverter->config.formatOut == ma_format_f32) { + pConverter->onConvertPCM = ma_pcm_s16_to_f32; } } break; - case mal_format_s24: + case ma_format_s24: { - if (pConverter->config.formatOut == mal_format_u8) { - pConverter->onConvertPCM = mal_pcm_s24_to_u8; - } else if (pConverter->config.formatOut == mal_format_s16) { - pConverter->onConvertPCM = mal_pcm_s24_to_s16; - } else if (pConverter->config.formatOut == mal_format_s24) { - pConverter->onConvertPCM = mal_pcm_s24_to_s24; - } else if (pConverter->config.formatOut == mal_format_s32) { - pConverter->onConvertPCM = mal_pcm_s24_to_s32; - } else if (pConverter->config.formatOut == mal_format_f32) { - pConverter->onConvertPCM = mal_pcm_s24_to_f32; + if (pConverter->config.formatOut == ma_format_u8) { + pConverter->onConvertPCM = ma_pcm_s24_to_u8; + } else if (pConverter->config.formatOut == ma_format_s16) { + pConverter->onConvertPCM = ma_pcm_s24_to_s16; + } else if (pConverter->config.formatOut == ma_format_s24) { + pConverter->onConvertPCM = ma_pcm_s24_to_s24; + } else if (pConverter->config.formatOut == ma_format_s32) { + pConverter->onConvertPCM = ma_pcm_s24_to_s32; + } else if (pConverter->config.formatOut == ma_format_f32) { + pConverter->onConvertPCM = ma_pcm_s24_to_f32; } } break; - case mal_format_s32: + case ma_format_s32: { - if (pConverter->config.formatOut == mal_format_u8) { - pConverter->onConvertPCM = mal_pcm_s32_to_u8; - } else if (pConverter->config.formatOut == mal_format_s16) { - pConverter->onConvertPCM = mal_pcm_s32_to_s16; - } else if (pConverter->config.formatOut == mal_format_s24) { - pConverter->onConvertPCM = mal_pcm_s32_to_s24; - } else if (pConverter->config.formatOut == mal_format_s32) { - pConverter->onConvertPCM = mal_pcm_s32_to_s32; - } else if (pConverter->config.formatOut == mal_format_f32) { - pConverter->onConvertPCM = mal_pcm_s32_to_f32; + if (pConverter->config.formatOut == ma_format_u8) { + pConverter->onConvertPCM = ma_pcm_s32_to_u8; + } else if (pConverter->config.formatOut == ma_format_s16) { + pConverter->onConvertPCM = ma_pcm_s32_to_s16; + } else if (pConverter->config.formatOut == ma_format_s24) { + pConverter->onConvertPCM = ma_pcm_s32_to_s24; + } else if (pConverter->config.formatOut == ma_format_s32) { + pConverter->onConvertPCM = ma_pcm_s32_to_s32; + } else if (pConverter->config.formatOut == ma_format_f32) { + pConverter->onConvertPCM = ma_pcm_s32_to_f32; } } break; - case mal_format_f32: + case ma_format_f32: default: { - if (pConverter->config.formatOut == mal_format_u8) { - pConverter->onConvertPCM = mal_pcm_f32_to_u8; - } else if (pConverter->config.formatOut == mal_format_s16) { - pConverter->onConvertPCM = mal_pcm_f32_to_s16; - } else if (pConverter->config.formatOut == mal_format_s24) { - pConverter->onConvertPCM = mal_pcm_f32_to_s24; - } else if (pConverter->config.formatOut == mal_format_s32) { - pConverter->onConvertPCM = mal_pcm_f32_to_s32; - } else if (pConverter->config.formatOut == mal_format_f32) { - pConverter->onConvertPCM = mal_pcm_f32_to_f32; + if (pConverter->config.formatOut == ma_format_u8) { + pConverter->onConvertPCM = ma_pcm_f32_to_u8; + } else if (pConverter->config.formatOut == ma_format_s16) { + pConverter->onConvertPCM = ma_pcm_f32_to_s16; + } else if (pConverter->config.formatOut == ma_format_s24) { + pConverter->onConvertPCM = ma_pcm_f32_to_s24; + } else if (pConverter->config.formatOut == ma_format_s32) { + pConverter->onConvertPCM = ma_pcm_f32_to_s32; + } else if (pConverter->config.formatOut == ma_format_f32) { + pConverter->onConvertPCM = ma_pcm_f32_to_f32; } } break; } } #if defined(MA_SUPPORT_SSE2) -void mal_format_converter_init_callbacks__sse2(mal_format_converter* pConverter) +void ma_format_converter_init_callbacks__sse2(ma_format_converter* pConverter) { - mal_assert(pConverter != NULL); + ma_assert(pConverter != NULL); switch (pConverter->config.formatIn) { - case mal_format_u8: + case ma_format_u8: { - if (pConverter->config.formatOut == mal_format_u8) { - pConverter->onConvertPCM = mal_pcm_u8_to_u8; - } else if (pConverter->config.formatOut == mal_format_s16) { - pConverter->onConvertPCM = mal_pcm_u8_to_s16__sse2; - } else if (pConverter->config.formatOut == mal_format_s24) { - pConverter->onConvertPCM = mal_pcm_u8_to_s24__sse2; - } else if (pConverter->config.formatOut == mal_format_s32) { - pConverter->onConvertPCM = mal_pcm_u8_to_s32__sse2; - } else if (pConverter->config.formatOut == mal_format_f32) { - pConverter->onConvertPCM = mal_pcm_u8_to_f32__sse2; + if (pConverter->config.formatOut == ma_format_u8) { + pConverter->onConvertPCM = ma_pcm_u8_to_u8; + } else if (pConverter->config.formatOut == ma_format_s16) { + pConverter->onConvertPCM = ma_pcm_u8_to_s16__sse2; + } else if (pConverter->config.formatOut == ma_format_s24) { + pConverter->onConvertPCM = ma_pcm_u8_to_s24__sse2; + } else if (pConverter->config.formatOut == ma_format_s32) { + pConverter->onConvertPCM = ma_pcm_u8_to_s32__sse2; + } else if (pConverter->config.formatOut == ma_format_f32) { + pConverter->onConvertPCM = ma_pcm_u8_to_f32__sse2; } } break; - case mal_format_s16: + case ma_format_s16: { - if (pConverter->config.formatOut == mal_format_u8) { - pConverter->onConvertPCM = mal_pcm_s16_to_u8__sse2; - } else if (pConverter->config.formatOut == mal_format_s16) { - pConverter->onConvertPCM = mal_pcm_s16_to_s16; - } else if (pConverter->config.formatOut == mal_format_s24) { - pConverter->onConvertPCM = mal_pcm_s16_to_s24__sse2; - } else if (pConverter->config.formatOut == mal_format_s32) { - pConverter->onConvertPCM = mal_pcm_s16_to_s32__sse2; - } else if (pConverter->config.formatOut == mal_format_f32) { - pConverter->onConvertPCM = mal_pcm_s16_to_f32__sse2; + if (pConverter->config.formatOut == ma_format_u8) { + pConverter->onConvertPCM = ma_pcm_s16_to_u8__sse2; + } else if (pConverter->config.formatOut == ma_format_s16) { + pConverter->onConvertPCM = ma_pcm_s16_to_s16; + } else if (pConverter->config.formatOut == ma_format_s24) { + pConverter->onConvertPCM = ma_pcm_s16_to_s24__sse2; + } else if (pConverter->config.formatOut == ma_format_s32) { + pConverter->onConvertPCM = ma_pcm_s16_to_s32__sse2; + } else if (pConverter->config.formatOut == ma_format_f32) { + pConverter->onConvertPCM = ma_pcm_s16_to_f32__sse2; } } break; - case mal_format_s24: + case ma_format_s24: { - if (pConverter->config.formatOut == mal_format_u8) { - pConverter->onConvertPCM = mal_pcm_s24_to_u8__sse2; - } else if (pConverter->config.formatOut == mal_format_s16) { - pConverter->onConvertPCM = mal_pcm_s24_to_s16__sse2; - } else if (pConverter->config.formatOut == mal_format_s24) { - pConverter->onConvertPCM = mal_pcm_s24_to_s24; - } else if (pConverter->config.formatOut == mal_format_s32) { - pConverter->onConvertPCM = mal_pcm_s24_to_s32__sse2; - } else if (pConverter->config.formatOut == mal_format_f32) { - pConverter->onConvertPCM = mal_pcm_s24_to_f32__sse2; + if (pConverter->config.formatOut == ma_format_u8) { + pConverter->onConvertPCM = ma_pcm_s24_to_u8__sse2; + } else if (pConverter->config.formatOut == ma_format_s16) { + pConverter->onConvertPCM = ma_pcm_s24_to_s16__sse2; + } else if (pConverter->config.formatOut == ma_format_s24) { + pConverter->onConvertPCM = ma_pcm_s24_to_s24; + } else if (pConverter->config.formatOut == ma_format_s32) { + pConverter->onConvertPCM = ma_pcm_s24_to_s32__sse2; + } else if (pConverter->config.formatOut == ma_format_f32) { + pConverter->onConvertPCM = ma_pcm_s24_to_f32__sse2; } } break; - case mal_format_s32: + case ma_format_s32: { - if (pConverter->config.formatOut == mal_format_u8) { - pConverter->onConvertPCM = mal_pcm_s32_to_u8__sse2; - } else if (pConverter->config.formatOut == mal_format_s16) { - pConverter->onConvertPCM = mal_pcm_s32_to_s16__sse2; - } else if (pConverter->config.formatOut == mal_format_s24) { - pConverter->onConvertPCM = mal_pcm_s32_to_s24__sse2; - } else if (pConverter->config.formatOut == mal_format_s32) { - pConverter->onConvertPCM = mal_pcm_s32_to_s32; - } else if (pConverter->config.formatOut == mal_format_f32) { - pConverter->onConvertPCM = mal_pcm_s32_to_f32__sse2; + if (pConverter->config.formatOut == ma_format_u8) { + pConverter->onConvertPCM = ma_pcm_s32_to_u8__sse2; + } else if (pConverter->config.formatOut == ma_format_s16) { + pConverter->onConvertPCM = ma_pcm_s32_to_s16__sse2; + } else if (pConverter->config.formatOut == ma_format_s24) { + pConverter->onConvertPCM = ma_pcm_s32_to_s24__sse2; + } else if (pConverter->config.formatOut == ma_format_s32) { + pConverter->onConvertPCM = ma_pcm_s32_to_s32; + } else if (pConverter->config.formatOut == ma_format_f32) { + pConverter->onConvertPCM = ma_pcm_s32_to_f32__sse2; } } break; - case mal_format_f32: + case ma_format_f32: default: { - if (pConverter->config.formatOut == mal_format_u8) { - pConverter->onConvertPCM = mal_pcm_f32_to_u8__sse2; - } else if (pConverter->config.formatOut == mal_format_s16) { - pConverter->onConvertPCM = mal_pcm_f32_to_s16__sse2; - } else if (pConverter->config.formatOut == mal_format_s24) { - pConverter->onConvertPCM = mal_pcm_f32_to_s24__sse2; - } else if (pConverter->config.formatOut == mal_format_s32) { - pConverter->onConvertPCM = mal_pcm_f32_to_s32__sse2; - } else if (pConverter->config.formatOut == mal_format_f32) { - pConverter->onConvertPCM = mal_pcm_f32_to_f32; + if (pConverter->config.formatOut == ma_format_u8) { + pConverter->onConvertPCM = ma_pcm_f32_to_u8__sse2; + } else if (pConverter->config.formatOut == ma_format_s16) { + pConverter->onConvertPCM = ma_pcm_f32_to_s16__sse2; + } else if (pConverter->config.formatOut == ma_format_s24) { + pConverter->onConvertPCM = ma_pcm_f32_to_s24__sse2; + } else if (pConverter->config.formatOut == ma_format_s32) { + pConverter->onConvertPCM = ma_pcm_f32_to_s32__sse2; + } else if (pConverter->config.formatOut == ma_format_f32) { + pConverter->onConvertPCM = ma_pcm_f32_to_f32; } } break; } @@ -26252,85 +26252,85 @@ void mal_format_converter_init_callbacks__sse2(mal_format_converter* pConverter) #endif #if defined(MA_SUPPORT_AVX2) -void mal_format_converter_init_callbacks__avx2(mal_format_converter* pConverter) +void ma_format_converter_init_callbacks__avx2(ma_format_converter* pConverter) { - mal_assert(pConverter != NULL); + ma_assert(pConverter != NULL); switch (pConverter->config.formatIn) { - case mal_format_u8: + case ma_format_u8: { - if (pConverter->config.formatOut == mal_format_u8) { - pConverter->onConvertPCM = mal_pcm_u8_to_u8; - } else if (pConverter->config.formatOut == mal_format_s16) { - pConverter->onConvertPCM = mal_pcm_u8_to_s16__avx2; - } else if (pConverter->config.formatOut == mal_format_s24) { - pConverter->onConvertPCM = mal_pcm_u8_to_s24__avx2; - } else if (pConverter->config.formatOut == mal_format_s32) { - pConverter->onConvertPCM = mal_pcm_u8_to_s32__avx2; - } else if (pConverter->config.formatOut == mal_format_f32) { - pConverter->onConvertPCM = mal_pcm_u8_to_f32__avx2; + if (pConverter->config.formatOut == ma_format_u8) { + pConverter->onConvertPCM = ma_pcm_u8_to_u8; + } else if (pConverter->config.formatOut == ma_format_s16) { + pConverter->onConvertPCM = ma_pcm_u8_to_s16__avx2; + } else if (pConverter->config.formatOut == ma_format_s24) { + pConverter->onConvertPCM = ma_pcm_u8_to_s24__avx2; + } else if (pConverter->config.formatOut == ma_format_s32) { + pConverter->onConvertPCM = ma_pcm_u8_to_s32__avx2; + } else if (pConverter->config.formatOut == ma_format_f32) { + pConverter->onConvertPCM = ma_pcm_u8_to_f32__avx2; } } break; - case mal_format_s16: + case ma_format_s16: { - if (pConverter->config.formatOut == mal_format_u8) { - pConverter->onConvertPCM = mal_pcm_s16_to_u8__avx2; - } else if (pConverter->config.formatOut == mal_format_s16) { - pConverter->onConvertPCM = mal_pcm_s16_to_s16; - } else if (pConverter->config.formatOut == mal_format_s24) { - pConverter->onConvertPCM = mal_pcm_s16_to_s24__avx2; - } else if (pConverter->config.formatOut == mal_format_s32) { - pConverter->onConvertPCM = mal_pcm_s16_to_s32__avx2; - } else if (pConverter->config.formatOut == mal_format_f32) { - pConverter->onConvertPCM = mal_pcm_s16_to_f32__avx2; + if (pConverter->config.formatOut == ma_format_u8) { + pConverter->onConvertPCM = ma_pcm_s16_to_u8__avx2; + } else if (pConverter->config.formatOut == ma_format_s16) { + pConverter->onConvertPCM = ma_pcm_s16_to_s16; + } else if (pConverter->config.formatOut == ma_format_s24) { + pConverter->onConvertPCM = ma_pcm_s16_to_s24__avx2; + } else if (pConverter->config.formatOut == ma_format_s32) { + pConverter->onConvertPCM = ma_pcm_s16_to_s32__avx2; + } else if (pConverter->config.formatOut == ma_format_f32) { + pConverter->onConvertPCM = ma_pcm_s16_to_f32__avx2; } } break; - case mal_format_s24: + case ma_format_s24: { - if (pConverter->config.formatOut == mal_format_u8) { - pConverter->onConvertPCM = mal_pcm_s24_to_u8__avx2; - } else if (pConverter->config.formatOut == mal_format_s16) { - pConverter->onConvertPCM = mal_pcm_s24_to_s16__avx2; - } else if (pConverter->config.formatOut == mal_format_s24) { - pConverter->onConvertPCM = mal_pcm_s24_to_s24; - } else if (pConverter->config.formatOut == mal_format_s32) { - pConverter->onConvertPCM = mal_pcm_s24_to_s32__avx2; - } else if (pConverter->config.formatOut == mal_format_f32) { - pConverter->onConvertPCM = mal_pcm_s24_to_f32__avx2; + if (pConverter->config.formatOut == ma_format_u8) { + pConverter->onConvertPCM = ma_pcm_s24_to_u8__avx2; + } else if (pConverter->config.formatOut == ma_format_s16) { + pConverter->onConvertPCM = ma_pcm_s24_to_s16__avx2; + } else if (pConverter->config.formatOut == ma_format_s24) { + pConverter->onConvertPCM = ma_pcm_s24_to_s24; + } else if (pConverter->config.formatOut == ma_format_s32) { + pConverter->onConvertPCM = ma_pcm_s24_to_s32__avx2; + } else if (pConverter->config.formatOut == ma_format_f32) { + pConverter->onConvertPCM = ma_pcm_s24_to_f32__avx2; } } break; - case mal_format_s32: + case ma_format_s32: { - if (pConverter->config.formatOut == mal_format_u8) { - pConverter->onConvertPCM = mal_pcm_s32_to_u8__avx2; - } else if (pConverter->config.formatOut == mal_format_s16) { - pConverter->onConvertPCM = mal_pcm_s32_to_s16__avx2; - } else if (pConverter->config.formatOut == mal_format_s24) { - pConverter->onConvertPCM = mal_pcm_s32_to_s24__avx2; - } else if (pConverter->config.formatOut == mal_format_s32) { - pConverter->onConvertPCM = mal_pcm_s32_to_s32; - } else if (pConverter->config.formatOut == mal_format_f32) { - pConverter->onConvertPCM = mal_pcm_s32_to_f32__avx2; + if (pConverter->config.formatOut == ma_format_u8) { + pConverter->onConvertPCM = ma_pcm_s32_to_u8__avx2; + } else if (pConverter->config.formatOut == ma_format_s16) { + pConverter->onConvertPCM = ma_pcm_s32_to_s16__avx2; + } else if (pConverter->config.formatOut == ma_format_s24) { + pConverter->onConvertPCM = ma_pcm_s32_to_s24__avx2; + } else if (pConverter->config.formatOut == ma_format_s32) { + pConverter->onConvertPCM = ma_pcm_s32_to_s32; + } else if (pConverter->config.formatOut == ma_format_f32) { + pConverter->onConvertPCM = ma_pcm_s32_to_f32__avx2; } } break; - case mal_format_f32: + case ma_format_f32: default: { - if (pConverter->config.formatOut == mal_format_u8) { - pConverter->onConvertPCM = mal_pcm_f32_to_u8__avx2; - } else if (pConverter->config.formatOut == mal_format_s16) { - pConverter->onConvertPCM = mal_pcm_f32_to_s16__avx2; - } else if (pConverter->config.formatOut == mal_format_s24) { - pConverter->onConvertPCM = mal_pcm_f32_to_s24__avx2; - } else if (pConverter->config.formatOut == mal_format_s32) { - pConverter->onConvertPCM = mal_pcm_f32_to_s32__avx2; - } else if (pConverter->config.formatOut == mal_format_f32) { - pConverter->onConvertPCM = mal_pcm_f32_to_f32; + if (pConverter->config.formatOut == ma_format_u8) { + pConverter->onConvertPCM = ma_pcm_f32_to_u8__avx2; + } else if (pConverter->config.formatOut == ma_format_s16) { + pConverter->onConvertPCM = ma_pcm_f32_to_s16__avx2; + } else if (pConverter->config.formatOut == ma_format_s24) { + pConverter->onConvertPCM = ma_pcm_f32_to_s24__avx2; + } else if (pConverter->config.formatOut == ma_format_s32) { + pConverter->onConvertPCM = ma_pcm_f32_to_s32__avx2; + } else if (pConverter->config.formatOut == ma_format_f32) { + pConverter->onConvertPCM = ma_pcm_f32_to_f32; } } break; } @@ -26338,85 +26338,85 @@ void mal_format_converter_init_callbacks__avx2(mal_format_converter* pConverter) #endif #if defined(MA_SUPPORT_AVX512) -void mal_format_converter_init_callbacks__avx512(mal_format_converter* pConverter) +void ma_format_converter_init_callbacks__avx512(ma_format_converter* pConverter) { - mal_assert(pConverter != NULL); + ma_assert(pConverter != NULL); switch (pConverter->config.formatIn) { - case mal_format_u8: + case ma_format_u8: { - if (pConverter->config.formatOut == mal_format_u8) { - pConverter->onConvertPCM = mal_pcm_u8_to_u8; - } else if (pConverter->config.formatOut == mal_format_s16) { - pConverter->onConvertPCM = mal_pcm_u8_to_s16__avx512; - } else if (pConverter->config.formatOut == mal_format_s24) { - pConverter->onConvertPCM = mal_pcm_u8_to_s24__avx512; - } else if (pConverter->config.formatOut == mal_format_s32) { - pConverter->onConvertPCM = mal_pcm_u8_to_s32__avx512; - } else if (pConverter->config.formatOut == mal_format_f32) { - pConverter->onConvertPCM = mal_pcm_u8_to_f32__avx512; + if (pConverter->config.formatOut == ma_format_u8) { + pConverter->onConvertPCM = ma_pcm_u8_to_u8; + } else if (pConverter->config.formatOut == ma_format_s16) { + pConverter->onConvertPCM = ma_pcm_u8_to_s16__avx512; + } else if (pConverter->config.formatOut == ma_format_s24) { + pConverter->onConvertPCM = ma_pcm_u8_to_s24__avx512; + } else if (pConverter->config.formatOut == ma_format_s32) { + pConverter->onConvertPCM = ma_pcm_u8_to_s32__avx512; + } else if (pConverter->config.formatOut == ma_format_f32) { + pConverter->onConvertPCM = ma_pcm_u8_to_f32__avx512; } } break; - case mal_format_s16: + case ma_format_s16: { - if (pConverter->config.formatOut == mal_format_u8) { - pConverter->onConvertPCM = mal_pcm_s16_to_u8__avx512; - } else if (pConverter->config.formatOut == mal_format_s16) { - pConverter->onConvertPCM = mal_pcm_s16_to_s16; - } else if (pConverter->config.formatOut == mal_format_s24) { - pConverter->onConvertPCM = mal_pcm_s16_to_s24__avx512; - } else if (pConverter->config.formatOut == mal_format_s32) { - pConverter->onConvertPCM = mal_pcm_s16_to_s32__avx512; - } else if (pConverter->config.formatOut == mal_format_f32) { - pConverter->onConvertPCM = mal_pcm_s16_to_f32__avx512; + if (pConverter->config.formatOut == ma_format_u8) { + pConverter->onConvertPCM = ma_pcm_s16_to_u8__avx512; + } else if (pConverter->config.formatOut == ma_format_s16) { + pConverter->onConvertPCM = ma_pcm_s16_to_s16; + } else if (pConverter->config.formatOut == ma_format_s24) { + pConverter->onConvertPCM = ma_pcm_s16_to_s24__avx512; + } else if (pConverter->config.formatOut == ma_format_s32) { + pConverter->onConvertPCM = ma_pcm_s16_to_s32__avx512; + } else if (pConverter->config.formatOut == ma_format_f32) { + pConverter->onConvertPCM = ma_pcm_s16_to_f32__avx512; } } break; - case mal_format_s24: + case ma_format_s24: { - if (pConverter->config.formatOut == mal_format_u8) { - pConverter->onConvertPCM = mal_pcm_s24_to_u8__avx512; - } else if (pConverter->config.formatOut == mal_format_s16) { - pConverter->onConvertPCM = mal_pcm_s24_to_s16__avx512; - } else if (pConverter->config.formatOut == mal_format_s24) { - pConverter->onConvertPCM = mal_pcm_s24_to_s24; - } else if (pConverter->config.formatOut == mal_format_s32) { - pConverter->onConvertPCM = mal_pcm_s24_to_s32__avx512; - } else if (pConverter->config.formatOut == mal_format_f32) { - pConverter->onConvertPCM = mal_pcm_s24_to_f32__avx512; + if (pConverter->config.formatOut == ma_format_u8) { + pConverter->onConvertPCM = ma_pcm_s24_to_u8__avx512; + } else if (pConverter->config.formatOut == ma_format_s16) { + pConverter->onConvertPCM = ma_pcm_s24_to_s16__avx512; + } else if (pConverter->config.formatOut == ma_format_s24) { + pConverter->onConvertPCM = ma_pcm_s24_to_s24; + } else if (pConverter->config.formatOut == ma_format_s32) { + pConverter->onConvertPCM = ma_pcm_s24_to_s32__avx512; + } else if (pConverter->config.formatOut == ma_format_f32) { + pConverter->onConvertPCM = ma_pcm_s24_to_f32__avx512; } } break; - case mal_format_s32: + case ma_format_s32: { - if (pConverter->config.formatOut == mal_format_u8) { - pConverter->onConvertPCM = mal_pcm_s32_to_u8__avx512; - } else if (pConverter->config.formatOut == mal_format_s16) { - pConverter->onConvertPCM = mal_pcm_s32_to_s16__avx512; - } else if (pConverter->config.formatOut == mal_format_s24) { - pConverter->onConvertPCM = mal_pcm_s32_to_s24__avx512; - } else if (pConverter->config.formatOut == mal_format_s32) { - pConverter->onConvertPCM = mal_pcm_s32_to_s32; - } else if (pConverter->config.formatOut == mal_format_f32) { - pConverter->onConvertPCM = mal_pcm_s32_to_f32__avx512; + if (pConverter->config.formatOut == ma_format_u8) { + pConverter->onConvertPCM = ma_pcm_s32_to_u8__avx512; + } else if (pConverter->config.formatOut == ma_format_s16) { + pConverter->onConvertPCM = ma_pcm_s32_to_s16__avx512; + } else if (pConverter->config.formatOut == ma_format_s24) { + pConverter->onConvertPCM = ma_pcm_s32_to_s24__avx512; + } else if (pConverter->config.formatOut == ma_format_s32) { + pConverter->onConvertPCM = ma_pcm_s32_to_s32; + } else if (pConverter->config.formatOut == ma_format_f32) { + pConverter->onConvertPCM = ma_pcm_s32_to_f32__avx512; } } break; - case mal_format_f32: + case ma_format_f32: default: { - if (pConverter->config.formatOut == mal_format_u8) { - pConverter->onConvertPCM = mal_pcm_f32_to_u8__avx512; - } else if (pConverter->config.formatOut == mal_format_s16) { - pConverter->onConvertPCM = mal_pcm_f32_to_s16__avx512; - } else if (pConverter->config.formatOut == mal_format_s24) { - pConverter->onConvertPCM = mal_pcm_f32_to_s24__avx512; - } else if (pConverter->config.formatOut == mal_format_s32) { - pConverter->onConvertPCM = mal_pcm_f32_to_s32__avx512; - } else if (pConverter->config.formatOut == mal_format_f32) { - pConverter->onConvertPCM = mal_pcm_f32_to_f32; + if (pConverter->config.formatOut == ma_format_u8) { + pConverter->onConvertPCM = ma_pcm_f32_to_u8__avx512; + } else if (pConverter->config.formatOut == ma_format_s16) { + pConverter->onConvertPCM = ma_pcm_f32_to_s16__avx512; + } else if (pConverter->config.formatOut == ma_format_s24) { + pConverter->onConvertPCM = ma_pcm_f32_to_s24__avx512; + } else if (pConverter->config.formatOut == ma_format_s32) { + pConverter->onConvertPCM = ma_pcm_f32_to_s32__avx512; + } else if (pConverter->config.formatOut == ma_format_f32) { + pConverter->onConvertPCM = ma_pcm_f32_to_f32; } } break; } @@ -26424,97 +26424,97 @@ void mal_format_converter_init_callbacks__avx512(mal_format_converter* pConverte #endif #if defined(MA_SUPPORT_NEON) -void mal_format_converter_init_callbacks__neon(mal_format_converter* pConverter) +void ma_format_converter_init_callbacks__neon(ma_format_converter* pConverter) { - mal_assert(pConverter != NULL); + ma_assert(pConverter != NULL); switch (pConverter->config.formatIn) { - case mal_format_u8: + case ma_format_u8: { - if (pConverter->config.formatOut == mal_format_u8) { - pConverter->onConvertPCM = mal_pcm_u8_to_u8; - } else if (pConverter->config.formatOut == mal_format_s16) { - pConverter->onConvertPCM = mal_pcm_u8_to_s16__neon; - } else if (pConverter->config.formatOut == mal_format_s24) { - pConverter->onConvertPCM = mal_pcm_u8_to_s24__neon; - } else if (pConverter->config.formatOut == mal_format_s32) { - pConverter->onConvertPCM = mal_pcm_u8_to_s32__neon; - } else if (pConverter->config.formatOut == mal_format_f32) { - pConverter->onConvertPCM = mal_pcm_u8_to_f32__neon; + if (pConverter->config.formatOut == ma_format_u8) { + pConverter->onConvertPCM = ma_pcm_u8_to_u8; + } else if (pConverter->config.formatOut == ma_format_s16) { + pConverter->onConvertPCM = ma_pcm_u8_to_s16__neon; + } else if (pConverter->config.formatOut == ma_format_s24) { + pConverter->onConvertPCM = ma_pcm_u8_to_s24__neon; + } else if (pConverter->config.formatOut == ma_format_s32) { + pConverter->onConvertPCM = ma_pcm_u8_to_s32__neon; + } else if (pConverter->config.formatOut == ma_format_f32) { + pConverter->onConvertPCM = ma_pcm_u8_to_f32__neon; } } break; - case mal_format_s16: + case ma_format_s16: { - if (pConverter->config.formatOut == mal_format_u8) { - pConverter->onConvertPCM = mal_pcm_s16_to_u8__neon; - } else if (pConverter->config.formatOut == mal_format_s16) { - pConverter->onConvertPCM = mal_pcm_s16_to_s16; - } else if (pConverter->config.formatOut == mal_format_s24) { - pConverter->onConvertPCM = mal_pcm_s16_to_s24__neon; - } else if (pConverter->config.formatOut == mal_format_s32) { - pConverter->onConvertPCM = mal_pcm_s16_to_s32__neon; - } else if (pConverter->config.formatOut == mal_format_f32) { - pConverter->onConvertPCM = mal_pcm_s16_to_f32__neon; + if (pConverter->config.formatOut == ma_format_u8) { + pConverter->onConvertPCM = ma_pcm_s16_to_u8__neon; + } else if (pConverter->config.formatOut == ma_format_s16) { + pConverter->onConvertPCM = ma_pcm_s16_to_s16; + } else if (pConverter->config.formatOut == ma_format_s24) { + pConverter->onConvertPCM = ma_pcm_s16_to_s24__neon; + } else if (pConverter->config.formatOut == ma_format_s32) { + pConverter->onConvertPCM = ma_pcm_s16_to_s32__neon; + } else if (pConverter->config.formatOut == ma_format_f32) { + pConverter->onConvertPCM = ma_pcm_s16_to_f32__neon; } } break; - case mal_format_s24: + case ma_format_s24: { - if (pConverter->config.formatOut == mal_format_u8) { - pConverter->onConvertPCM = mal_pcm_s24_to_u8__neon; - } else if (pConverter->config.formatOut == mal_format_s16) { - pConverter->onConvertPCM = mal_pcm_s24_to_s16__neon; - } else if (pConverter->config.formatOut == mal_format_s24) { - pConverter->onConvertPCM = mal_pcm_s24_to_s24; - } else if (pConverter->config.formatOut == mal_format_s32) { - pConverter->onConvertPCM = mal_pcm_s24_to_s32__neon; - } else if (pConverter->config.formatOut == mal_format_f32) { - pConverter->onConvertPCM = mal_pcm_s24_to_f32__neon; + if (pConverter->config.formatOut == ma_format_u8) { + pConverter->onConvertPCM = ma_pcm_s24_to_u8__neon; + } else if (pConverter->config.formatOut == ma_format_s16) { + pConverter->onConvertPCM = ma_pcm_s24_to_s16__neon; + } else if (pConverter->config.formatOut == ma_format_s24) { + pConverter->onConvertPCM = ma_pcm_s24_to_s24; + } else if (pConverter->config.formatOut == ma_format_s32) { + pConverter->onConvertPCM = ma_pcm_s24_to_s32__neon; + } else if (pConverter->config.formatOut == ma_format_f32) { + pConverter->onConvertPCM = ma_pcm_s24_to_f32__neon; } } break; - case mal_format_s32: + case ma_format_s32: { - if (pConverter->config.formatOut == mal_format_u8) { - pConverter->onConvertPCM = mal_pcm_s32_to_u8__neon; - } else if (pConverter->config.formatOut == mal_format_s16) { - pConverter->onConvertPCM = mal_pcm_s32_to_s16__neon; - } else if (pConverter->config.formatOut == mal_format_s24) { - pConverter->onConvertPCM = mal_pcm_s32_to_s24__neon; - } else if (pConverter->config.formatOut == mal_format_s32) { - pConverter->onConvertPCM = mal_pcm_s32_to_s32; - } else if (pConverter->config.formatOut == mal_format_f32) { - pConverter->onConvertPCM = mal_pcm_s32_to_f32__neon; + if (pConverter->config.formatOut == ma_format_u8) { + pConverter->onConvertPCM = ma_pcm_s32_to_u8__neon; + } else if (pConverter->config.formatOut == ma_format_s16) { + pConverter->onConvertPCM = ma_pcm_s32_to_s16__neon; + } else if (pConverter->config.formatOut == ma_format_s24) { + pConverter->onConvertPCM = ma_pcm_s32_to_s24__neon; + } else if (pConverter->config.formatOut == ma_format_s32) { + pConverter->onConvertPCM = ma_pcm_s32_to_s32; + } else if (pConverter->config.formatOut == ma_format_f32) { + pConverter->onConvertPCM = ma_pcm_s32_to_f32__neon; } } break; - case mal_format_f32: + case ma_format_f32: default: { - if (pConverter->config.formatOut == mal_format_u8) { - pConverter->onConvertPCM = mal_pcm_f32_to_u8__neon; - } else if (pConverter->config.formatOut == mal_format_s16) { - pConverter->onConvertPCM = mal_pcm_f32_to_s16__neon; - } else if (pConverter->config.formatOut == mal_format_s24) { - pConverter->onConvertPCM = mal_pcm_f32_to_s24__neon; - } else if (pConverter->config.formatOut == mal_format_s32) { - pConverter->onConvertPCM = mal_pcm_f32_to_s32__neon; - } else if (pConverter->config.formatOut == mal_format_f32) { - pConverter->onConvertPCM = mal_pcm_f32_to_f32; + if (pConverter->config.formatOut == ma_format_u8) { + pConverter->onConvertPCM = ma_pcm_f32_to_u8__neon; + } else if (pConverter->config.formatOut == ma_format_s16) { + pConverter->onConvertPCM = ma_pcm_f32_to_s16__neon; + } else if (pConverter->config.formatOut == ma_format_s24) { + pConverter->onConvertPCM = ma_pcm_f32_to_s24__neon; + } else if (pConverter->config.formatOut == ma_format_s32) { + pConverter->onConvertPCM = ma_pcm_f32_to_s32__neon; + } else if (pConverter->config.formatOut == ma_format_f32) { + pConverter->onConvertPCM = ma_pcm_f32_to_f32; } } break; } } #endif -mal_result mal_format_converter_init(const mal_format_converter_config* pConfig, mal_format_converter* pConverter) +ma_result ma_format_converter_init(const ma_format_converter_config* pConfig, ma_format_converter* pConverter) { if (pConverter == NULL) { return MA_INVALID_ARGS; } - mal_zero_object(pConverter); + ma_zero_object(pConverter); if (pConfig == NULL) { return MA_INVALID_ARGS; @@ -26523,93 +26523,93 @@ mal_result mal_format_converter_init(const mal_format_converter_config* pConfig, pConverter->config = *pConfig; // SIMD - pConverter->useSSE2 = mal_has_sse2() && !pConfig->noSSE2; - pConverter->useAVX2 = mal_has_avx2() && !pConfig->noAVX2; - pConverter->useAVX512 = mal_has_avx512f() && !pConfig->noAVX512; - pConverter->useNEON = mal_has_neon() && !pConfig->noNEON; + pConverter->useSSE2 = ma_has_sse2() && !pConfig->noSSE2; + pConverter->useAVX2 = ma_has_avx2() && !pConfig->noAVX2; + pConverter->useAVX512 = ma_has_avx512f() && !pConfig->noAVX512; + pConverter->useNEON = ma_has_neon() && !pConfig->noNEON; #if defined(MA_SUPPORT_AVX512) if (pConverter->useAVX512) { - mal_format_converter_init_callbacks__avx512(pConverter); + ma_format_converter_init_callbacks__avx512(pConverter); } else #endif #if defined(MA_SUPPORT_AVX2) if (pConverter->useAVX2) { - mal_format_converter_init_callbacks__avx2(pConverter); + ma_format_converter_init_callbacks__avx2(pConverter); } else #endif #if defined(MA_SUPPORT_SSE2) if (pConverter->useSSE2) { - mal_format_converter_init_callbacks__sse2(pConverter); + ma_format_converter_init_callbacks__sse2(pConverter); } else #endif #if defined(MA_SUPPORT_NEON) if (pConverter->useNEON) { - mal_format_converter_init_callbacks__neon(pConverter); + ma_format_converter_init_callbacks__neon(pConverter); } else #endif { - mal_format_converter_init_callbacks__default(pConverter); + ma_format_converter_init_callbacks__default(pConverter); } switch (pConfig->formatOut) { - case mal_format_u8: + case ma_format_u8: { - pConverter->onInterleavePCM = mal_pcm_interleave_u8; - pConverter->onDeinterleavePCM = mal_pcm_deinterleave_u8; + pConverter->onInterleavePCM = ma_pcm_interleave_u8; + pConverter->onDeinterleavePCM = ma_pcm_deinterleave_u8; } break; - case mal_format_s16: + case ma_format_s16: { - pConverter->onInterleavePCM = mal_pcm_interleave_s16; - pConverter->onDeinterleavePCM = mal_pcm_deinterleave_s16; + pConverter->onInterleavePCM = ma_pcm_interleave_s16; + pConverter->onDeinterleavePCM = ma_pcm_deinterleave_s16; } break; - case mal_format_s24: + case ma_format_s24: { - pConverter->onInterleavePCM = mal_pcm_interleave_s24; - pConverter->onDeinterleavePCM = mal_pcm_deinterleave_s24; + pConverter->onInterleavePCM = ma_pcm_interleave_s24; + pConverter->onDeinterleavePCM = ma_pcm_deinterleave_s24; } break; - case mal_format_s32: + case ma_format_s32: { - pConverter->onInterleavePCM = mal_pcm_interleave_s32; - pConverter->onDeinterleavePCM = mal_pcm_deinterleave_s32; + pConverter->onInterleavePCM = ma_pcm_interleave_s32; + pConverter->onDeinterleavePCM = ma_pcm_deinterleave_s32; } break; - case mal_format_f32: + case ma_format_f32: default: { - pConverter->onInterleavePCM = mal_pcm_interleave_f32; - pConverter->onDeinterleavePCM = mal_pcm_deinterleave_f32; + pConverter->onInterleavePCM = ma_pcm_interleave_f32; + pConverter->onDeinterleavePCM = ma_pcm_deinterleave_f32; } break; } return MA_SUCCESS; } -mal_uint64 mal_format_converter_read(mal_format_converter* pConverter, mal_uint64 frameCount, void* pFramesOut, void* pUserData) +ma_uint64 ma_format_converter_read(ma_format_converter* pConverter, ma_uint64 frameCount, void* pFramesOut, void* pUserData) { if (pConverter == NULL || pFramesOut == NULL) { return 0; } - mal_uint64 totalFramesRead = 0; - mal_uint32 sampleSizeIn = mal_get_bytes_per_sample(pConverter->config.formatIn); - mal_uint32 sampleSizeOut = mal_get_bytes_per_sample(pConverter->config.formatOut); - //mal_uint32 frameSizeIn = sampleSizeIn * pConverter->config.channels; - mal_uint32 frameSizeOut = sampleSizeOut * pConverter->config.channels; - mal_uint8* pNextFramesOut = (mal_uint8*)pFramesOut; + ma_uint64 totalFramesRead = 0; + ma_uint32 sampleSizeIn = ma_get_bytes_per_sample(pConverter->config.formatIn); + ma_uint32 sampleSizeOut = ma_get_bytes_per_sample(pConverter->config.formatOut); + //ma_uint32 frameSizeIn = sampleSizeIn * pConverter->config.channels; + ma_uint32 frameSizeOut = sampleSizeOut * pConverter->config.channels; + ma_uint8* pNextFramesOut = (ma_uint8*)pFramesOut; if (pConverter->config.onRead != NULL) { // Input data is interleaved. if (pConverter->config.formatIn == pConverter->config.formatOut) { // Pass through. while (totalFramesRead < frameCount) { - mal_uint64 framesRemaining = (frameCount - totalFramesRead); - mal_uint64 framesToReadRightNow = framesRemaining; + ma_uint64 framesRemaining = (frameCount - totalFramesRead); + ma_uint64 framesToReadRightNow = framesRemaining; if (framesToReadRightNow > 0xFFFFFFFF) { framesToReadRightNow = 0xFFFFFFFF; } - mal_uint32 framesJustRead = (mal_uint32)pConverter->config.onRead(pConverter, (mal_uint32)framesToReadRightNow, pNextFramesOut, pUserData); + ma_uint32 framesJustRead = (ma_uint32)pConverter->config.onRead(pConverter, (ma_uint32)framesToReadRightNow, pNextFramesOut, pUserData); if (framesJustRead == 0) { break; } @@ -26623,19 +26623,19 @@ mal_uint64 mal_format_converter_read(mal_format_converter* pConverter, mal_uint6 } } else { // Conversion required. - MA_ALIGN(MA_SIMD_ALIGNMENT) mal_uint8 temp[MA_MAX_CHANNELS * MA_MAX_PCM_SAMPLE_SIZE_IN_BYTES * 128]; - mal_assert(sizeof(temp) <= 0xFFFFFFFF); + MA_ALIGN(MA_SIMD_ALIGNMENT) ma_uint8 temp[MA_MAX_CHANNELS * MA_MAX_PCM_SAMPLE_SIZE_IN_BYTES * 128]; + ma_assert(sizeof(temp) <= 0xFFFFFFFF); - mal_uint32 maxFramesToReadAtATime = sizeof(temp) / sampleSizeIn / pConverter->config.channels; + ma_uint32 maxFramesToReadAtATime = sizeof(temp) / sampleSizeIn / pConverter->config.channels; while (totalFramesRead < frameCount) { - mal_uint64 framesRemaining = (frameCount - totalFramesRead); - mal_uint64 framesToReadRightNow = framesRemaining; + ma_uint64 framesRemaining = (frameCount - totalFramesRead); + ma_uint64 framesToReadRightNow = framesRemaining; if (framesToReadRightNow > maxFramesToReadAtATime) { framesToReadRightNow = maxFramesToReadAtATime; } - mal_uint32 framesJustRead = (mal_uint32)pConverter->config.onRead(pConverter, (mal_uint32)framesToReadRightNow, temp, pUserData); + ma_uint32 framesJustRead = (ma_uint32)pConverter->config.onRead(pConverter, (ma_uint32)framesToReadRightNow, temp, pUserData); if (framesJustRead == 0) { break; } @@ -26652,48 +26652,48 @@ mal_uint64 mal_format_converter_read(mal_format_converter* pConverter, mal_uint6 } } else { // Input data is deinterleaved. If a conversion is required we need to do an intermediary step. - MA_ALIGN(MA_SIMD_ALIGNMENT) mal_uint8 tempSamplesOfOutFormat[MA_MAX_CHANNELS * MA_MAX_PCM_SAMPLE_SIZE_IN_BYTES * 128]; - mal_assert(sizeof(tempSamplesOfOutFormat) <= 0xFFFFFFFFF); + MA_ALIGN(MA_SIMD_ALIGNMENT) ma_uint8 tempSamplesOfOutFormat[MA_MAX_CHANNELS * MA_MAX_PCM_SAMPLE_SIZE_IN_BYTES * 128]; + ma_assert(sizeof(tempSamplesOfOutFormat) <= 0xFFFFFFFFF); void* ppTempSamplesOfOutFormat[MA_MAX_CHANNELS]; size_t splitBufferSizeOut; - mal_split_buffer(tempSamplesOfOutFormat, sizeof(tempSamplesOfOutFormat), pConverter->config.channels, MA_SIMD_ALIGNMENT, (void**)&ppTempSamplesOfOutFormat, &splitBufferSizeOut); + ma_split_buffer(tempSamplesOfOutFormat, sizeof(tempSamplesOfOutFormat), pConverter->config.channels, MA_SIMD_ALIGNMENT, (void**)&ppTempSamplesOfOutFormat, &splitBufferSizeOut); - mal_uint32 maxFramesToReadAtATime = (mal_uint32)(splitBufferSizeOut / sampleSizeIn); + ma_uint32 maxFramesToReadAtATime = (ma_uint32)(splitBufferSizeOut / sampleSizeIn); while (totalFramesRead < frameCount) { - mal_uint64 framesRemaining = (frameCount - totalFramesRead); - mal_uint64 framesToReadRightNow = framesRemaining; + ma_uint64 framesRemaining = (frameCount - totalFramesRead); + ma_uint64 framesToReadRightNow = framesRemaining; if (framesToReadRightNow > maxFramesToReadAtATime) { framesToReadRightNow = maxFramesToReadAtATime; } - mal_uint32 framesJustRead = 0; + ma_uint32 framesJustRead = 0; if (pConverter->config.formatIn == pConverter->config.formatOut) { // Only interleaving. - framesJustRead = (mal_uint32)pConverter->config.onReadDeinterleaved(pConverter, (mal_uint32)framesToReadRightNow, ppTempSamplesOfOutFormat, pUserData); + framesJustRead = (ma_uint32)pConverter->config.onReadDeinterleaved(pConverter, (ma_uint32)framesToReadRightNow, ppTempSamplesOfOutFormat, pUserData); if (framesJustRead == 0) { break; } } else { // Interleaving + Conversion. Convert first, then interleave. - MA_ALIGN(MA_SIMD_ALIGNMENT) mal_uint8 tempSamplesOfInFormat[MA_MAX_CHANNELS * MA_MAX_PCM_SAMPLE_SIZE_IN_BYTES * 128]; + MA_ALIGN(MA_SIMD_ALIGNMENT) ma_uint8 tempSamplesOfInFormat[MA_MAX_CHANNELS * MA_MAX_PCM_SAMPLE_SIZE_IN_BYTES * 128]; void* ppTempSamplesOfInFormat[MA_MAX_CHANNELS]; size_t splitBufferSizeIn; - mal_split_buffer(tempSamplesOfInFormat, sizeof(tempSamplesOfInFormat), pConverter->config.channels, MA_SIMD_ALIGNMENT, (void**)&ppTempSamplesOfInFormat, &splitBufferSizeIn); + ma_split_buffer(tempSamplesOfInFormat, sizeof(tempSamplesOfInFormat), pConverter->config.channels, MA_SIMD_ALIGNMENT, (void**)&ppTempSamplesOfInFormat, &splitBufferSizeIn); if (framesToReadRightNow > (splitBufferSizeIn / sampleSizeIn)) { framesToReadRightNow = (splitBufferSizeIn / sampleSizeIn); } - framesJustRead = (mal_uint32)pConverter->config.onReadDeinterleaved(pConverter, (mal_uint32)framesToReadRightNow, ppTempSamplesOfInFormat, pUserData); + framesJustRead = (ma_uint32)pConverter->config.onReadDeinterleaved(pConverter, (ma_uint32)framesToReadRightNow, ppTempSamplesOfInFormat, pUserData); if (framesJustRead == 0) { break; } - for (mal_uint32 iChannel = 0; iChannel < pConverter->config.channels; iChannel += 1) { + for (ma_uint32 iChannel = 0; iChannel < pConverter->config.channels; iChannel += 1) { pConverter->onConvertPCM(ppTempSamplesOfOutFormat[iChannel], ppTempSamplesOfInFormat[iChannel], framesJustRead, pConverter->config.ditherMode); } } @@ -26712,46 +26712,46 @@ mal_uint64 mal_format_converter_read(mal_format_converter* pConverter, mal_uint6 return totalFramesRead; } -mal_uint64 mal_format_converter_read_deinterleaved(mal_format_converter* pConverter, mal_uint64 frameCount, void** ppSamplesOut, void* pUserData) +ma_uint64 ma_format_converter_read_deinterleaved(ma_format_converter* pConverter, ma_uint64 frameCount, void** ppSamplesOut, void* pUserData) { if (pConverter == NULL || ppSamplesOut == NULL) { return 0; } - mal_uint64 totalFramesRead = 0; - mal_uint32 sampleSizeIn = mal_get_bytes_per_sample(pConverter->config.formatIn); - mal_uint32 sampleSizeOut = mal_get_bytes_per_sample(pConverter->config.formatOut); + ma_uint64 totalFramesRead = 0; + ma_uint32 sampleSizeIn = ma_get_bytes_per_sample(pConverter->config.formatIn); + ma_uint32 sampleSizeOut = ma_get_bytes_per_sample(pConverter->config.formatOut); - mal_uint8* ppNextSamplesOut[MA_MAX_CHANNELS]; - mal_copy_memory(ppNextSamplesOut, ppSamplesOut, sizeof(void*) * pConverter->config.channels); + ma_uint8* ppNextSamplesOut[MA_MAX_CHANNELS]; + ma_copy_memory(ppNextSamplesOut, ppSamplesOut, sizeof(void*) * pConverter->config.channels); if (pConverter->config.onRead != NULL) { // Input data is interleaved. - MA_ALIGN(MA_SIMD_ALIGNMENT) mal_uint8 tempSamplesOfOutFormat[MA_MAX_CHANNELS * MA_MAX_PCM_SAMPLE_SIZE_IN_BYTES * 128]; - mal_assert(sizeof(tempSamplesOfOutFormat) <= 0xFFFFFFFF); + MA_ALIGN(MA_SIMD_ALIGNMENT) ma_uint8 tempSamplesOfOutFormat[MA_MAX_CHANNELS * MA_MAX_PCM_SAMPLE_SIZE_IN_BYTES * 128]; + ma_assert(sizeof(tempSamplesOfOutFormat) <= 0xFFFFFFFF); - mal_uint32 maxFramesToReadAtATime = sizeof(tempSamplesOfOutFormat) / sampleSizeIn / pConverter->config.channels; + ma_uint32 maxFramesToReadAtATime = sizeof(tempSamplesOfOutFormat) / sampleSizeIn / pConverter->config.channels; while (totalFramesRead < frameCount) { - mal_uint64 framesRemaining = (frameCount - totalFramesRead); - mal_uint64 framesToReadRightNow = framesRemaining; + ma_uint64 framesRemaining = (frameCount - totalFramesRead); + ma_uint64 framesToReadRightNow = framesRemaining; if (framesToReadRightNow > maxFramesToReadAtATime) { framesToReadRightNow = maxFramesToReadAtATime; } - mal_uint32 framesJustRead = 0; + ma_uint32 framesJustRead = 0; if (pConverter->config.formatIn == pConverter->config.formatOut) { // Only de-interleaving. - framesJustRead = (mal_uint32)pConverter->config.onRead(pConverter, (mal_uint32)framesToReadRightNow, tempSamplesOfOutFormat, pUserData); + framesJustRead = (ma_uint32)pConverter->config.onRead(pConverter, (ma_uint32)framesToReadRightNow, tempSamplesOfOutFormat, pUserData); if (framesJustRead == 0) { break; } } else { // De-interleaving + Conversion. Convert first, then de-interleave. - MA_ALIGN(MA_SIMD_ALIGNMENT) mal_uint8 tempSamplesOfInFormat[sizeof(tempSamplesOfOutFormat)]; + MA_ALIGN(MA_SIMD_ALIGNMENT) ma_uint8 tempSamplesOfInFormat[sizeof(tempSamplesOfOutFormat)]; - framesJustRead = (mal_uint32)pConverter->config.onRead(pConverter, (mal_uint32)framesToReadRightNow, tempSamplesOfInFormat, pUserData); + framesJustRead = (ma_uint32)pConverter->config.onRead(pConverter, (ma_uint32)framesToReadRightNow, tempSamplesOfInFormat, pUserData); if (framesJustRead == 0) { break; } @@ -26762,7 +26762,7 @@ mal_uint64 mal_format_converter_read_deinterleaved(mal_format_converter* pConver pConverter->onDeinterleavePCM((void**)ppNextSamplesOut, tempSamplesOfOutFormat, framesJustRead, pConverter->config.channels); totalFramesRead += framesJustRead; - for (mal_uint32 iChannel = 0; iChannel < pConverter->config.channels; ++iChannel) { + for (ma_uint32 iChannel = 0; iChannel < pConverter->config.channels; ++iChannel) { ppNextSamplesOut[iChannel] += framesJustRead * sampleSizeOut; } @@ -26775,19 +26775,19 @@ mal_uint64 mal_format_converter_read_deinterleaved(mal_format_converter* pConver if (pConverter->config.formatIn == pConverter->config.formatOut) { // Pass through. while (totalFramesRead < frameCount) { - mal_uint64 framesRemaining = (frameCount - totalFramesRead); - mal_uint64 framesToReadRightNow = framesRemaining; + ma_uint64 framesRemaining = (frameCount - totalFramesRead); + ma_uint64 framesToReadRightNow = framesRemaining; if (framesToReadRightNow > 0xFFFFFFFF) { framesToReadRightNow = 0xFFFFFFFF; } - mal_uint32 framesJustRead = (mal_uint32)pConverter->config.onReadDeinterleaved(pConverter, (mal_uint32)framesToReadRightNow, (void**)ppNextSamplesOut, pUserData); + ma_uint32 framesJustRead = (ma_uint32)pConverter->config.onReadDeinterleaved(pConverter, (ma_uint32)framesToReadRightNow, (void**)ppNextSamplesOut, pUserData); if (framesJustRead == 0) { break; } totalFramesRead += framesJustRead; - for (mal_uint32 iChannel = 0; iChannel < pConverter->config.channels; ++iChannel) { + for (ma_uint32 iChannel = 0; iChannel < pConverter->config.channels; ++iChannel) { ppNextSamplesOut[iChannel] += framesJustRead * sampleSizeOut; } @@ -26797,28 +26797,28 @@ mal_uint64 mal_format_converter_read_deinterleaved(mal_format_converter* pConver } } else { // Conversion required. - MA_ALIGN(MA_SIMD_ALIGNMENT) mal_uint8 temp[MA_MAX_CHANNELS][MA_MAX_PCM_SAMPLE_SIZE_IN_BYTES * 128]; - mal_assert(sizeof(temp) <= 0xFFFFFFFF); + MA_ALIGN(MA_SIMD_ALIGNMENT) ma_uint8 temp[MA_MAX_CHANNELS][MA_MAX_PCM_SAMPLE_SIZE_IN_BYTES * 128]; + ma_assert(sizeof(temp) <= 0xFFFFFFFF); void* ppTemp[MA_MAX_CHANNELS]; size_t splitBufferSize; - mal_split_buffer(temp, sizeof(temp), pConverter->config.channels, MA_SIMD_ALIGNMENT, (void**)&ppTemp, &splitBufferSize); + ma_split_buffer(temp, sizeof(temp), pConverter->config.channels, MA_SIMD_ALIGNMENT, (void**)&ppTemp, &splitBufferSize); - mal_uint32 maxFramesToReadAtATime = (mal_uint32)(splitBufferSize / sampleSizeIn); + ma_uint32 maxFramesToReadAtATime = (ma_uint32)(splitBufferSize / sampleSizeIn); while (totalFramesRead < frameCount) { - mal_uint64 framesRemaining = (frameCount - totalFramesRead); - mal_uint64 framesToReadRightNow = framesRemaining; + ma_uint64 framesRemaining = (frameCount - totalFramesRead); + ma_uint64 framesToReadRightNow = framesRemaining; if (framesToReadRightNow > maxFramesToReadAtATime) { framesToReadRightNow = maxFramesToReadAtATime; } - mal_uint32 framesJustRead = (mal_uint32)pConverter->config.onReadDeinterleaved(pConverter, (mal_uint32)framesToReadRightNow, ppTemp, pUserData); + ma_uint32 framesJustRead = (ma_uint32)pConverter->config.onReadDeinterleaved(pConverter, (ma_uint32)framesToReadRightNow, ppTemp, pUserData); if (framesJustRead == 0) { break; } - for (mal_uint32 iChannel = 0; iChannel < pConverter->config.channels; iChannel += 1) { + for (ma_uint32 iChannel = 0; iChannel < pConverter->config.channels; iChannel += 1) { pConverter->onConvertPCM(ppNextSamplesOut[iChannel], ppTemp[iChannel], framesJustRead, pConverter->config.ditherMode); ppNextSamplesOut[iChannel] += framesJustRead * sampleSizeOut; } @@ -26836,17 +26836,17 @@ mal_uint64 mal_format_converter_read_deinterleaved(mal_format_converter* pConver } -mal_format_converter_config mal_format_converter_config_init_new() +ma_format_converter_config ma_format_converter_config_init_new() { - mal_format_converter_config config; - mal_zero_object(&config); + ma_format_converter_config config; + ma_zero_object(&config); return config; } -mal_format_converter_config mal_format_converter_config_init(mal_format formatIn, mal_format formatOut, mal_uint32 channels, mal_format_converter_read_proc onRead, void* pUserData) +ma_format_converter_config ma_format_converter_config_init(ma_format formatIn, ma_format formatOut, ma_uint32 channels, ma_format_converter_read_proc onRead, void* pUserData) { - mal_format_converter_config config = mal_format_converter_config_init_new(); + ma_format_converter_config config = ma_format_converter_config_init_new(); config.formatIn = formatIn; config.formatOut = formatOut; config.channels = channels; @@ -26857,9 +26857,9 @@ mal_format_converter_config mal_format_converter_config_init(mal_format formatIn return config; } -mal_format_converter_config mal_format_converter_config_init_deinterleaved(mal_format formatIn, mal_format formatOut, mal_uint32 channels, mal_format_converter_read_deinterleaved_proc onReadDeinterleaved, void* pUserData) +ma_format_converter_config ma_format_converter_config_init_deinterleaved(ma_format formatIn, ma_format formatOut, ma_uint32 channels, ma_format_converter_read_deinterleaved_proc onReadDeinterleaved, void* pUserData) { - mal_format_converter_config config = mal_format_converter_config_init(formatIn, formatOut, channels, NULL, pUserData); + ma_format_converter_config config = ma_format_converter_config_init(formatIn, formatOut, channels, NULL, pUserData); config.onReadDeinterleaved = onReadDeinterleaved; return config; @@ -26881,11 +26881,11 @@ typedef struct float x; float y; float z; -} mal_vec3; +} ma_vec3; -static MA_INLINE mal_vec3 mal_vec3f(float x, float y, float z) +static MA_INLINE ma_vec3 ma_vec3f(float x, float y, float z) { - mal_vec3 r; + ma_vec3 r; r.x = x; r.y = y; r.z = z; @@ -26893,62 +26893,62 @@ static MA_INLINE mal_vec3 mal_vec3f(float x, float y, float z) return r; } -static MA_INLINE mal_vec3 mal_vec3_add(mal_vec3 a, mal_vec3 b) +static MA_INLINE ma_vec3 ma_vec3_add(ma_vec3 a, ma_vec3 b) { - return mal_vec3f( + return ma_vec3f( a.x + b.x, a.y + b.y, a.z + b.z ); } -static MA_INLINE mal_vec3 mal_vec3_sub(mal_vec3 a, mal_vec3 b) +static MA_INLINE ma_vec3 ma_vec3_sub(ma_vec3 a, ma_vec3 b) { - return mal_vec3f( + return ma_vec3f( a.x - b.x, a.y - b.y, a.z - b.z ); } -static MA_INLINE mal_vec3 mal_vec3_mul(mal_vec3 a, mal_vec3 b) +static MA_INLINE ma_vec3 ma_vec3_mul(ma_vec3 a, ma_vec3 b) { - return mal_vec3f( + return ma_vec3f( a.x * b.x, a.y * b.y, a.z * b.z ); } -static MA_INLINE mal_vec3 mal_vec3_div(mal_vec3 a, mal_vec3 b) +static MA_INLINE ma_vec3 ma_vec3_div(ma_vec3 a, ma_vec3 b) { - return mal_vec3f( + return ma_vec3f( a.x / b.x, a.y / b.y, a.z / b.z ); } -static MA_INLINE float mal_vec3_dot(mal_vec3 a, mal_vec3 b) +static MA_INLINE float ma_vec3_dot(ma_vec3 a, ma_vec3 b) { return a.x*b.x + a.y*b.y + a.z*b.z; } -static MA_INLINE float mal_vec3_length2(mal_vec3 a) +static MA_INLINE float ma_vec3_length2(ma_vec3 a) { - return mal_vec3_dot(a, a); + return ma_vec3_dot(a, a); } -static MA_INLINE float mal_vec3_length(mal_vec3 a) +static MA_INLINE float ma_vec3_length(ma_vec3 a) { - return (float)sqrt(mal_vec3_length2(a)); + return (float)sqrt(ma_vec3_length2(a)); } -static MA_INLINE mal_vec3 mal_vec3_normalize(mal_vec3 a) +static MA_INLINE ma_vec3 ma_vec3_normalize(ma_vec3 a) { - float len = 1 / mal_vec3_length(a); + float len = 1 / ma_vec3_length(a); - mal_vec3 r; + ma_vec3 r; r.x = a.x * len; r.y = a.y * len; r.z = a.z * len; @@ -26956,9 +26956,9 @@ static MA_INLINE mal_vec3 mal_vec3_normalize(mal_vec3 a) return r; } -static MA_INLINE float mal_vec3_distance(mal_vec3 a, mal_vec3 b) +static MA_INLINE float ma_vec3_distance(ma_vec3 a, ma_vec3 b) { - return mal_vec3_length(mal_vec3_sub(a, b)); + return ma_vec3_length(ma_vec3_sub(a, b)); } @@ -27024,7 +27024,7 @@ float g_malChannelPlaneRatios[MA_CHANNEL_POSITION_COUNT][6] = { { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // MA_CHANNEL_AUX_31 }; -float mal_calculate_channel_position_planar_weight(mal_channel channelPositionA, mal_channel channelPositionB) +float ma_calculate_channel_position_planar_weight(ma_channel channelPositionA, ma_channel channelPositionB) { // Imagine the following simplified example: You have a single input speaker which is the front/left speaker which you want to convert to // the following output configuration: @@ -27065,17 +27065,17 @@ float mal_calculate_channel_position_planar_weight(mal_channel channelPositionA, return contribution; } -float mal_channel_router__calculate_input_channel_planar_weight(const mal_channel_router* pRouter, mal_channel channelPositionIn, mal_channel channelPositionOut) +float ma_channel_router__calculate_input_channel_planar_weight(const ma_channel_router* pRouter, ma_channel channelPositionIn, ma_channel channelPositionOut) { - mal_assert(pRouter != NULL); + ma_assert(pRouter != NULL); (void)pRouter; - return mal_calculate_channel_position_planar_weight(channelPositionIn, channelPositionOut); + return ma_calculate_channel_position_planar_weight(channelPositionIn, channelPositionOut); } -mal_bool32 mal_channel_router__is_spatial_channel_position(const mal_channel_router* pRouter, mal_channel channelPosition) +ma_bool32 ma_channel_router__is_spatial_channel_position(const ma_channel_router* pRouter, ma_channel channelPosition) { - mal_assert(pRouter != NULL); + ma_assert(pRouter != NULL); (void)pRouter; if (channelPosition == MA_CHANNEL_NONE || channelPosition == MA_CHANNEL_MONO || channelPosition == MA_CHANNEL_LFE) { @@ -27091,13 +27091,13 @@ mal_bool32 mal_channel_router__is_spatial_channel_position(const mal_channel_rou return MA_FALSE; } -mal_result mal_channel_router_init(const mal_channel_router_config* pConfig, mal_channel_router* pRouter) +ma_result ma_channel_router_init(const ma_channel_router_config* pConfig, ma_channel_router* pRouter) { if (pRouter == NULL) { return MA_INVALID_ARGS; } - mal_zero_object(pRouter); + ma_zero_object(pRouter); if (pConfig == NULL) { return MA_INVALID_ARGS; @@ -27106,27 +27106,27 @@ mal_result mal_channel_router_init(const mal_channel_router_config* pConfig, mal return MA_INVALID_ARGS; } - if (!mal_channel_map_valid(pConfig->channelsIn, pConfig->channelMapIn)) { + if (!ma_channel_map_valid(pConfig->channelsIn, pConfig->channelMapIn)) { return MA_INVALID_ARGS; // Invalid input channel map. } - if (!mal_channel_map_valid(pConfig->channelsOut, pConfig->channelMapOut)) { + if (!ma_channel_map_valid(pConfig->channelsOut, pConfig->channelMapOut)) { return MA_INVALID_ARGS; // Invalid output channel map. } pRouter->config = *pConfig; // SIMD - pRouter->useSSE2 = mal_has_sse2() && !pConfig->noSSE2; - pRouter->useAVX2 = mal_has_avx2() && !pConfig->noAVX2; - pRouter->useAVX512 = mal_has_avx512f() && !pConfig->noAVX512; - pRouter->useNEON = mal_has_neon() && !pConfig->noNEON; + pRouter->useSSE2 = ma_has_sse2() && !pConfig->noSSE2; + pRouter->useAVX2 = ma_has_avx2() && !pConfig->noAVX2; + pRouter->useAVX512 = ma_has_avx512f() && !pConfig->noAVX512; + pRouter->useNEON = ma_has_neon() && !pConfig->noNEON; // If the input and output channels and channel maps are the same we should use a passthrough. if (pRouter->config.channelsIn == pRouter->config.channelsOut) { - if (mal_channel_map_equal(pRouter->config.channelsIn, pRouter->config.channelMapIn, pRouter->config.channelMapOut)) { + if (ma_channel_map_equal(pRouter->config.channelsIn, pRouter->config.channelMapIn, pRouter->config.channelMapOut)) { pRouter->isPassthrough = MA_TRUE; } - if (mal_channel_map_blank(pRouter->config.channelsIn, pRouter->config.channelMapIn) || mal_channel_map_blank(pRouter->config.channelsOut, pRouter->config.channelMapOut)) { + if (ma_channel_map_blank(pRouter->config.channelsIn, pRouter->config.channelMapIn) || ma_channel_map_blank(pRouter->config.channelsOut, pRouter->config.channelMapOut)) { pRouter->isPassthrough = MA_TRUE; } } @@ -27139,10 +27139,10 @@ mal_result mal_channel_router_init(const mal_channel_router_config* pConfig, mal // 3) Otherwise channels are blended based on spatial locality. if (!pRouter->isPassthrough) { if (pRouter->config.channelsIn == pRouter->config.channelsOut) { - mal_bool32 areAllChannelPositionsPresent = MA_TRUE; - for (mal_uint32 iChannelIn = 0; iChannelIn < pRouter->config.channelsIn; ++iChannelIn) { - mal_bool32 isInputChannelPositionInOutput = MA_FALSE; - for (mal_uint32 iChannelOut = 0; iChannelOut < pRouter->config.channelsOut; ++iChannelOut) { + ma_bool32 areAllChannelPositionsPresent = MA_TRUE; + for (ma_uint32 iChannelIn = 0; iChannelIn < pRouter->config.channelsIn; ++iChannelIn) { + ma_bool32 isInputChannelPositionInOutput = MA_FALSE; + for (ma_uint32 iChannelOut = 0; iChannelOut < pRouter->config.channelsOut; ++iChannelOut) { if (pRouter->config.channelMapIn[iChannelIn] == pRouter->config.channelMapOut[iChannelOut]) { isInputChannelPositionInOutput = MA_TRUE; break; @@ -27160,10 +27160,10 @@ mal_result mal_channel_router_init(const mal_channel_router_config* pConfig, mal // All the router will be doing is rearranging channels which means all we need to do is use a shuffling table which is just // a mapping between the index of the input channel to the index of the output channel. - for (mal_uint32 iChannelIn = 0; iChannelIn < pRouter->config.channelsIn; ++iChannelIn) { - for (mal_uint32 iChannelOut = 0; iChannelOut < pRouter->config.channelsOut; ++iChannelOut) { + for (ma_uint32 iChannelIn = 0; iChannelIn < pRouter->config.channelsIn; ++iChannelIn) { + for (ma_uint32 iChannelOut = 0; iChannelOut < pRouter->config.channelsOut; ++iChannelOut) { if (pRouter->config.channelMapIn[iChannelIn] == pRouter->config.channelMapOut[iChannelOut]) { - pRouter->shuffleTable[iChannelIn] = (mal_uint8)iChannelOut; + pRouter->shuffleTable[iChannelIn] = (ma_uint8)iChannelOut; break; } } @@ -27181,11 +27181,11 @@ mal_result mal_channel_router_init(const mal_channel_router_config* pConfig, mal // map, nothing will be heard! // In all cases we need to make sure all channels that are present in both channel maps have a 1:1 mapping. - for (mal_uint32 iChannelIn = 0; iChannelIn < pRouter->config.channelsIn; ++iChannelIn) { - mal_channel channelPosIn = pRouter->config.channelMapIn[iChannelIn]; + for (ma_uint32 iChannelIn = 0; iChannelIn < pRouter->config.channelsIn; ++iChannelIn) { + ma_channel channelPosIn = pRouter->config.channelMapIn[iChannelIn]; - for (mal_uint32 iChannelOut = 0; iChannelOut < pRouter->config.channelsOut; ++iChannelOut) { - mal_channel channelPosOut = pRouter->config.channelMapOut[iChannelOut]; + for (ma_uint32 iChannelOut = 0; iChannelOut < pRouter->config.channelsOut; ++iChannelOut) { + ma_channel channelPosOut = pRouter->config.channelMapOut[iChannelOut]; if (channelPosIn == channelPosOut) { pRouter->config.weights[iChannelIn][iChannelOut] = 1; @@ -27195,12 +27195,12 @@ mal_result mal_channel_router_init(const mal_channel_router_config* pConfig, mal // The mono channel is accumulated on all other channels, except LFE. Make sure in this loop we exclude output mono channels since // they were handled in the pass above. - for (mal_uint32 iChannelIn = 0; iChannelIn < pRouter->config.channelsIn; ++iChannelIn) { - mal_channel channelPosIn = pRouter->config.channelMapIn[iChannelIn]; + for (ma_uint32 iChannelIn = 0; iChannelIn < pRouter->config.channelsIn; ++iChannelIn) { + ma_channel channelPosIn = pRouter->config.channelMapIn[iChannelIn]; if (channelPosIn == MA_CHANNEL_MONO) { - for (mal_uint32 iChannelOut = 0; iChannelOut < pRouter->config.channelsOut; ++iChannelOut) { - mal_channel channelPosOut = pRouter->config.channelMapOut[iChannelOut]; + for (ma_uint32 iChannelOut = 0; iChannelOut < pRouter->config.channelsOut; ++iChannelOut) { + ma_channel channelPosOut = pRouter->config.channelMapOut[iChannelOut]; if (channelPosOut != MA_CHANNEL_NONE && channelPosOut != MA_CHANNEL_MONO && channelPosOut != MA_CHANNEL_LFE) { pRouter->config.weights[iChannelIn][iChannelOut] = 1; @@ -27211,9 +27211,9 @@ mal_result mal_channel_router_init(const mal_channel_router_config* pConfig, mal // The output mono channel is the average of all non-none, non-mono and non-lfe input channels. { - mal_uint32 len = 0; - for (mal_uint32 iChannelIn = 0; iChannelIn < pRouter->config.channelsIn; ++iChannelIn) { - mal_channel channelPosIn = pRouter->config.channelMapIn[iChannelIn]; + ma_uint32 len = 0; + for (ma_uint32 iChannelIn = 0; iChannelIn < pRouter->config.channelsIn; ++iChannelIn) { + ma_channel channelPosIn = pRouter->config.channelMapIn[iChannelIn]; if (channelPosIn != MA_CHANNEL_NONE && channelPosIn != MA_CHANNEL_MONO && channelPosIn != MA_CHANNEL_LFE) { len += 1; @@ -27223,12 +27223,12 @@ mal_result mal_channel_router_init(const mal_channel_router_config* pConfig, mal if (len > 0) { float monoWeight = 1.0f / len; - for (mal_uint32 iChannelOut = 0; iChannelOut < pRouter->config.channelsOut; ++iChannelOut) { - mal_channel channelPosOut = pRouter->config.channelMapOut[iChannelOut]; + for (ma_uint32 iChannelOut = 0; iChannelOut < pRouter->config.channelsOut; ++iChannelOut) { + ma_channel channelPosOut = pRouter->config.channelMapOut[iChannelOut]; if (channelPosOut == MA_CHANNEL_MONO) { - for (mal_uint32 iChannelIn = 0; iChannelIn < pRouter->config.channelsIn; ++iChannelIn) { - mal_channel channelPosIn = pRouter->config.channelMapIn[iChannelIn]; + for (ma_uint32 iChannelIn = 0; iChannelIn < pRouter->config.channelsIn; ++iChannelIn) { + ma_channel channelPosIn = pRouter->config.channelMapIn[iChannelIn]; if (channelPosIn != MA_CHANNEL_NONE && channelPosIn != MA_CHANNEL_MONO && channelPosIn != MA_CHANNEL_LFE) { pRouter->config.weights[iChannelIn][iChannelOut] += monoWeight; @@ -27243,21 +27243,21 @@ mal_result mal_channel_router_init(const mal_channel_router_config* pConfig, mal // Input and output channels that are not present on the other side need to be blended in based on spatial locality. switch (pRouter->config.mixingMode) { - case mal_channel_mix_mode_rectangular: + case ma_channel_mix_mode_rectangular: { // Unmapped input channels. - for (mal_uint32 iChannelIn = 0; iChannelIn < pRouter->config.channelsIn; ++iChannelIn) { - mal_channel channelPosIn = pRouter->config.channelMapIn[iChannelIn]; + for (ma_uint32 iChannelIn = 0; iChannelIn < pRouter->config.channelsIn; ++iChannelIn) { + ma_channel channelPosIn = pRouter->config.channelMapIn[iChannelIn]; - if (mal_channel_router__is_spatial_channel_position(pRouter, channelPosIn)) { - if (!mal_channel_map_contains_channel_position(pRouter->config.channelsOut, pRouter->config.channelMapOut, channelPosIn)) { - for (mal_uint32 iChannelOut = 0; iChannelOut < pRouter->config.channelsOut; ++iChannelOut) { - mal_channel channelPosOut = pRouter->config.channelMapOut[iChannelOut]; + if (ma_channel_router__is_spatial_channel_position(pRouter, channelPosIn)) { + if (!ma_channel_map_contains_channel_position(pRouter->config.channelsOut, pRouter->config.channelMapOut, channelPosIn)) { + for (ma_uint32 iChannelOut = 0; iChannelOut < pRouter->config.channelsOut; ++iChannelOut) { + ma_channel channelPosOut = pRouter->config.channelMapOut[iChannelOut]; - if (mal_channel_router__is_spatial_channel_position(pRouter, channelPosOut)) { + if (ma_channel_router__is_spatial_channel_position(pRouter, channelPosOut)) { float weight = 0; - if (pRouter->config.mixingMode == mal_channel_mix_mode_planar_blend) { - weight = mal_channel_router__calculate_input_channel_planar_weight(pRouter, channelPosIn, channelPosOut); + if (pRouter->config.mixingMode == ma_channel_mix_mode_planar_blend) { + weight = ma_channel_router__calculate_input_channel_planar_weight(pRouter, channelPosIn, channelPosOut); } // Only apply the weight if we haven't already got some contribution from the respective channels. @@ -27271,18 +27271,18 @@ mal_result mal_channel_router_init(const mal_channel_router_config* pConfig, mal } // Unmapped output channels. - for (mal_uint32 iChannelOut = 0; iChannelOut < pRouter->config.channelsOut; ++iChannelOut) { - mal_channel channelPosOut = pRouter->config.channelMapOut[iChannelOut]; + for (ma_uint32 iChannelOut = 0; iChannelOut < pRouter->config.channelsOut; ++iChannelOut) { + ma_channel channelPosOut = pRouter->config.channelMapOut[iChannelOut]; - if (mal_channel_router__is_spatial_channel_position(pRouter, channelPosOut)) { - if (!mal_channel_map_contains_channel_position(pRouter->config.channelsIn, pRouter->config.channelMapIn, channelPosOut)) { - for (mal_uint32 iChannelIn = 0; iChannelIn < pRouter->config.channelsIn; ++iChannelIn) { - mal_channel channelPosIn = pRouter->config.channelMapIn[iChannelIn]; + if (ma_channel_router__is_spatial_channel_position(pRouter, channelPosOut)) { + if (!ma_channel_map_contains_channel_position(pRouter->config.channelsIn, pRouter->config.channelMapIn, channelPosOut)) { + for (ma_uint32 iChannelIn = 0; iChannelIn < pRouter->config.channelsIn; ++iChannelIn) { + ma_channel channelPosIn = pRouter->config.channelMapIn[iChannelIn]; - if (mal_channel_router__is_spatial_channel_position(pRouter, channelPosIn)) { + if (ma_channel_router__is_spatial_channel_position(pRouter, channelPosIn)) { float weight = 0; - if (pRouter->config.mixingMode == mal_channel_mix_mode_planar_blend) { - weight = mal_channel_router__calculate_input_channel_planar_weight(pRouter, channelPosIn, channelPosOut); + if (pRouter->config.mixingMode == ma_channel_mix_mode_planar_blend) { + weight = ma_channel_router__calculate_input_channel_planar_weight(pRouter, channelPosIn, channelPosOut); } // Only apply the weight if we haven't already got some contribution from the respective channels. @@ -27296,8 +27296,8 @@ mal_result mal_channel_router_init(const mal_channel_router_config* pConfig, mal } } break; - case mal_channel_mix_mode_custom_weights: - case mal_channel_mix_mode_simple: + case ma_channel_mix_mode_custom_weights: + case ma_channel_mix_mode_simple: default: { /* Fallthrough. */ @@ -27307,56 +27307,56 @@ mal_result mal_channel_router_init(const mal_channel_router_config* pConfig, mal return MA_SUCCESS; } -static MA_INLINE mal_bool32 mal_channel_router__can_use_sse2(mal_channel_router* pRouter, const float* pSamplesOut, const float* pSamplesIn) +static MA_INLINE ma_bool32 ma_channel_router__can_use_sse2(ma_channel_router* pRouter, const float* pSamplesOut, const float* pSamplesIn) { - return pRouter->useSSE2 && (((mal_uintptr)pSamplesOut & 15) == 0) && (((mal_uintptr)pSamplesIn & 15) == 0); + return pRouter->useSSE2 && (((ma_uintptr)pSamplesOut & 15) == 0) && (((ma_uintptr)pSamplesIn & 15) == 0); } -static MA_INLINE mal_bool32 mal_channel_router__can_use_avx2(mal_channel_router* pRouter, const float* pSamplesOut, const float* pSamplesIn) +static MA_INLINE ma_bool32 ma_channel_router__can_use_avx2(ma_channel_router* pRouter, const float* pSamplesOut, const float* pSamplesIn) { - return pRouter->useAVX2 && (((mal_uintptr)pSamplesOut & 31) == 0) && (((mal_uintptr)pSamplesIn & 31) == 0); + return pRouter->useAVX2 && (((ma_uintptr)pSamplesOut & 31) == 0) && (((ma_uintptr)pSamplesIn & 31) == 0); } -static MA_INLINE mal_bool32 mal_channel_router__can_use_avx512(mal_channel_router* pRouter, const float* pSamplesOut, const float* pSamplesIn) +static MA_INLINE ma_bool32 ma_channel_router__can_use_avx512(ma_channel_router* pRouter, const float* pSamplesOut, const float* pSamplesIn) { - return pRouter->useAVX512 && (((mal_uintptr)pSamplesOut & 63) == 0) && (((mal_uintptr)pSamplesIn & 63) == 0); + return pRouter->useAVX512 && (((ma_uintptr)pSamplesOut & 63) == 0) && (((ma_uintptr)pSamplesIn & 63) == 0); } -static MA_INLINE mal_bool32 mal_channel_router__can_use_neon(mal_channel_router* pRouter, const float* pSamplesOut, const float* pSamplesIn) +static MA_INLINE ma_bool32 ma_channel_router__can_use_neon(ma_channel_router* pRouter, const float* pSamplesOut, const float* pSamplesIn) { - return pRouter->useNEON && (((mal_uintptr)pSamplesOut & 15) == 0) && (((mal_uintptr)pSamplesIn & 15) == 0); + return pRouter->useNEON && (((ma_uintptr)pSamplesOut & 15) == 0) && (((ma_uintptr)pSamplesIn & 15) == 0); } -void mal_channel_router__do_routing(mal_channel_router* pRouter, mal_uint64 frameCount, float** ppSamplesOut, const float** ppSamplesIn) +void ma_channel_router__do_routing(ma_channel_router* pRouter, ma_uint64 frameCount, float** ppSamplesOut, const float** ppSamplesIn) { - mal_assert(pRouter != NULL); - mal_assert(pRouter->isPassthrough == MA_FALSE); + ma_assert(pRouter != NULL); + ma_assert(pRouter->isPassthrough == MA_FALSE); if (pRouter->isSimpleShuffle) { // A shuffle is just a re-arrangement of channels and does not require any arithmetic. - mal_assert(pRouter->config.channelsIn == pRouter->config.channelsOut); - for (mal_uint32 iChannelIn = 0; iChannelIn < pRouter->config.channelsIn; ++iChannelIn) { - mal_uint32 iChannelOut = pRouter->shuffleTable[iChannelIn]; - mal_copy_memory_64(ppSamplesOut[iChannelOut], ppSamplesIn[iChannelIn], frameCount * sizeof(float)); + ma_assert(pRouter->config.channelsIn == pRouter->config.channelsOut); + for (ma_uint32 iChannelIn = 0; iChannelIn < pRouter->config.channelsIn; ++iChannelIn) { + ma_uint32 iChannelOut = pRouter->shuffleTable[iChannelIn]; + ma_copy_memory_64(ppSamplesOut[iChannelOut], ppSamplesIn[iChannelIn], frameCount * sizeof(float)); } } else { // This is the more complicated case. Each of the output channels is accumulated with 0 or more input channels. // Clear. - for (mal_uint32 iChannelOut = 0; iChannelOut < pRouter->config.channelsOut; ++iChannelOut) { - mal_zero_memory_64(ppSamplesOut[iChannelOut], frameCount * sizeof(float)); + for (ma_uint32 iChannelOut = 0; iChannelOut < pRouter->config.channelsOut; ++iChannelOut) { + ma_zero_memory_64(ppSamplesOut[iChannelOut], frameCount * sizeof(float)); } // Accumulate. - for (mal_uint32 iChannelIn = 0; iChannelIn < pRouter->config.channelsIn; ++iChannelIn) { - for (mal_uint32 iChannelOut = 0; iChannelOut < pRouter->config.channelsOut; ++iChannelOut) { - mal_uint64 iFrame = 0; + for (ma_uint32 iChannelIn = 0; iChannelIn < pRouter->config.channelsIn; ++iChannelIn) { + for (ma_uint32 iChannelOut = 0; iChannelOut < pRouter->config.channelsOut; ++iChannelOut) { + ma_uint64 iFrame = 0; #if defined(MA_SUPPORT_NEON) - if (mal_channel_router__can_use_neon(pRouter, ppSamplesOut[iChannelOut], ppSamplesIn[iChannelIn])) { + if (ma_channel_router__can_use_neon(pRouter, ppSamplesOut[iChannelOut], ppSamplesIn[iChannelIn])) { float32x4_t weight = vmovq_n_f32(pRouter->config.weights[iChannelIn][iChannelOut]); - mal_uint64 frameCount4 = frameCount/4; - for (mal_uint64 iFrame4 = 0; iFrame4 < frameCount4; iFrame4 += 1) { + ma_uint64 frameCount4 = frameCount/4; + for (ma_uint64 iFrame4 = 0; iFrame4 < frameCount4; iFrame4 += 1) { float32x4_t* pO = (float32x4_t*)ppSamplesOut[iChannelOut] + iFrame4; float32x4_t* pI = (float32x4_t*)ppSamplesIn [iChannelIn ] + iFrame4; *pO = vaddq_f32(*pO, vmulq_f32(*pI, weight)); @@ -27367,11 +27367,11 @@ void mal_channel_router__do_routing(mal_channel_router* pRouter, mal_uint64 fram else #endif #if defined(MA_SUPPORT_AVX512) - if (mal_channel_router__can_use_avx512(pRouter, ppSamplesOut[iChannelOut], ppSamplesIn[iChannelIn])) { + if (ma_channel_router__can_use_avx512(pRouter, ppSamplesOut[iChannelOut], ppSamplesIn[iChannelIn])) { __m512 weight = _mm512_set1_ps(pRouter->config.weights[iChannelIn][iChannelOut]); - mal_uint64 frameCount16 = frameCount/16; - for (mal_uint64 iFrame16 = 0; iFrame16 < frameCount16; iFrame16 += 1) { + ma_uint64 frameCount16 = frameCount/16; + for (ma_uint64 iFrame16 = 0; iFrame16 < frameCount16; iFrame16 += 1) { __m512* pO = (__m512*)ppSamplesOut[iChannelOut] + iFrame16; __m512* pI = (__m512*)ppSamplesIn [iChannelIn ] + iFrame16; *pO = _mm512_add_ps(*pO, _mm512_mul_ps(*pI, weight)); @@ -27382,11 +27382,11 @@ void mal_channel_router__do_routing(mal_channel_router* pRouter, mal_uint64 fram else #endif #if defined(MA_SUPPORT_AVX2) - if (mal_channel_router__can_use_avx2(pRouter, ppSamplesOut[iChannelOut], ppSamplesIn[iChannelIn])) { + if (ma_channel_router__can_use_avx2(pRouter, ppSamplesOut[iChannelOut], ppSamplesIn[iChannelIn])) { __m256 weight = _mm256_set1_ps(pRouter->config.weights[iChannelIn][iChannelOut]); - mal_uint64 frameCount8 = frameCount/8; - for (mal_uint64 iFrame8 = 0; iFrame8 < frameCount8; iFrame8 += 1) { + ma_uint64 frameCount8 = frameCount/8; + for (ma_uint64 iFrame8 = 0; iFrame8 < frameCount8; iFrame8 += 1) { __m256* pO = (__m256*)ppSamplesOut[iChannelOut] + iFrame8; __m256* pI = (__m256*)ppSamplesIn [iChannelIn ] + iFrame8; *pO = _mm256_add_ps(*pO, _mm256_mul_ps(*pI, weight)); @@ -27397,11 +27397,11 @@ void mal_channel_router__do_routing(mal_channel_router* pRouter, mal_uint64 fram else #endif #if defined(MA_SUPPORT_SSE2) - if (mal_channel_router__can_use_sse2(pRouter, ppSamplesOut[iChannelOut], ppSamplesIn[iChannelIn])) { + if (ma_channel_router__can_use_sse2(pRouter, ppSamplesOut[iChannelOut], ppSamplesIn[iChannelIn])) { __m128 weight = _mm_set1_ps(pRouter->config.weights[iChannelIn][iChannelOut]); - mal_uint64 frameCount4 = frameCount/4; - for (mal_uint64 iFrame4 = 0; iFrame4 < frameCount4; iFrame4 += 1) { + ma_uint64 frameCount4 = frameCount/4; + for (ma_uint64 iFrame4 = 0; iFrame4 < frameCount4; iFrame4 += 1) { __m128* pO = (__m128*)ppSamplesOut[iChannelOut] + iFrame4; __m128* pI = (__m128*)ppSamplesIn [iChannelIn ] + iFrame4; *pO = _mm_add_ps(*pO, _mm_mul_ps(*pI, weight)); @@ -27416,8 +27416,8 @@ void mal_channel_router__do_routing(mal_channel_router* pRouter, mal_uint64 fram float weight2 = pRouter->config.weights[iChannelIn][iChannelOut]; float weight3 = pRouter->config.weights[iChannelIn][iChannelOut]; - mal_uint64 frameCount4 = frameCount/4; - for (mal_uint64 iFrame4 = 0; iFrame4 < frameCount4; iFrame4 += 1) { + ma_uint64 frameCount4 = frameCount/4; + for (ma_uint64 iFrame4 = 0; iFrame4 < frameCount4; iFrame4 += 1) { ppSamplesOut[iChannelOut][iFrame+0] += ppSamplesIn[iChannelIn][iFrame+0] * weight0; ppSamplesOut[iChannelOut][iFrame+1] += ppSamplesIn[iChannelIn][iFrame+1] * weight1; ppSamplesOut[iChannelOut][iFrame+2] += ppSamplesIn[iChannelIn][iFrame+2] * weight2; @@ -27435,7 +27435,7 @@ void mal_channel_router__do_routing(mal_channel_router* pRouter, mal_uint64 fram } } -mal_uint64 mal_channel_router_read_deinterleaved(mal_channel_router* pRouter, mal_uint64 frameCount, void** ppSamplesOut, void* pUserData) +ma_uint64 ma_channel_router_read_deinterleaved(ma_channel_router* pRouter, ma_uint64 frameCount, void** ppSamplesOut, void* pUserData) { if (pRouter == NULL || ppSamplesOut == NULL) { return 0; @@ -27444,26 +27444,26 @@ mal_uint64 mal_channel_router_read_deinterleaved(mal_channel_router* pRouter, ma // Fast path for a passthrough. if (pRouter->isPassthrough) { if (frameCount <= 0xFFFFFFFF) { - return (mal_uint32)pRouter->config.onReadDeinterleaved(pRouter, (mal_uint32)frameCount, ppSamplesOut, pUserData); + return (ma_uint32)pRouter->config.onReadDeinterleaved(pRouter, (ma_uint32)frameCount, ppSamplesOut, pUserData); } else { float* ppNextSamplesOut[MA_MAX_CHANNELS]; - mal_copy_memory(ppNextSamplesOut, ppSamplesOut, sizeof(float*) * pRouter->config.channelsOut); + ma_copy_memory(ppNextSamplesOut, ppSamplesOut, sizeof(float*) * pRouter->config.channelsOut); - mal_uint64 totalFramesRead = 0; + ma_uint64 totalFramesRead = 0; while (totalFramesRead < frameCount) { - mal_uint64 framesRemaining = (frameCount - totalFramesRead); - mal_uint64 framesToReadRightNow = framesRemaining; + ma_uint64 framesRemaining = (frameCount - totalFramesRead); + ma_uint64 framesToReadRightNow = framesRemaining; if (framesToReadRightNow > 0xFFFFFFFF) { framesToReadRightNow = 0xFFFFFFFF; } - mal_uint32 framesJustRead = (mal_uint32)pRouter->config.onReadDeinterleaved(pRouter, (mal_uint32)framesToReadRightNow, (void**)ppNextSamplesOut, pUserData); + ma_uint32 framesJustRead = (ma_uint32)pRouter->config.onReadDeinterleaved(pRouter, (ma_uint32)framesToReadRightNow, (void**)ppNextSamplesOut, pUserData); if (framesJustRead == 0) { break; } totalFramesRead += framesJustRead; - for (mal_uint32 iChannel = 0; iChannel < pRouter->config.channelsOut; ++iChannel) { + for (ma_uint32 iChannel = 0; iChannel < pRouter->config.channelsOut; ++iChannel) { ppNextSamplesOut[iChannel] += framesJustRead; } @@ -27476,35 +27476,35 @@ mal_uint64 mal_channel_router_read_deinterleaved(mal_channel_router* pRouter, ma // Slower path for a non-passthrough. float* ppNextSamplesOut[MA_MAX_CHANNELS]; - mal_copy_memory(ppNextSamplesOut, ppSamplesOut, sizeof(float*) * pRouter->config.channelsOut); + ma_copy_memory(ppNextSamplesOut, ppSamplesOut, sizeof(float*) * pRouter->config.channelsOut); MA_ALIGN(MA_SIMD_ALIGNMENT) float temp[MA_MAX_CHANNELS * 256]; - mal_assert(sizeof(temp) <= 0xFFFFFFFF); + ma_assert(sizeof(temp) <= 0xFFFFFFFF); float* ppTemp[MA_MAX_CHANNELS]; size_t maxBytesToReadPerFrameEachIteration; - mal_split_buffer(temp, sizeof(temp), pRouter->config.channelsIn, MA_SIMD_ALIGNMENT, (void**)&ppTemp, &maxBytesToReadPerFrameEachIteration); + ma_split_buffer(temp, sizeof(temp), pRouter->config.channelsIn, MA_SIMD_ALIGNMENT, (void**)&ppTemp, &maxBytesToReadPerFrameEachIteration); size_t maxFramesToReadEachIteration = maxBytesToReadPerFrameEachIteration/sizeof(float); - mal_uint64 totalFramesRead = 0; + ma_uint64 totalFramesRead = 0; while (totalFramesRead < frameCount) { - mal_uint64 framesRemaining = (frameCount - totalFramesRead); - mal_uint64 framesToReadRightNow = framesRemaining; + ma_uint64 framesRemaining = (frameCount - totalFramesRead); + ma_uint64 framesToReadRightNow = framesRemaining; if (framesToReadRightNow > maxFramesToReadEachIteration) { framesToReadRightNow = maxFramesToReadEachIteration; } - mal_uint32 framesJustRead = pRouter->config.onReadDeinterleaved(pRouter, (mal_uint32)framesToReadRightNow, (void**)ppTemp, pUserData); + ma_uint32 framesJustRead = pRouter->config.onReadDeinterleaved(pRouter, (ma_uint32)framesToReadRightNow, (void**)ppTemp, pUserData); if (framesJustRead == 0) { break; } - mal_channel_router__do_routing(pRouter, framesJustRead, (float**)ppNextSamplesOut, (const float**)ppTemp); // <-- Real work is done here. + ma_channel_router__do_routing(pRouter, framesJustRead, (float**)ppNextSamplesOut, (const float**)ppTemp); // <-- Real work is done here. totalFramesRead += framesJustRead; if (totalFramesRead < frameCount) { - for (mal_uint32 iChannel = 0; iChannel < pRouter->config.channelsIn; iChannel += 1) { + for (ma_uint32 iChannel = 0; iChannel < pRouter->config.channelsIn; iChannel += 1) { ppNextSamplesOut[iChannel] += framesJustRead; } } @@ -27517,18 +27517,18 @@ mal_uint64 mal_channel_router_read_deinterleaved(mal_channel_router* pRouter, ma return totalFramesRead; } -mal_channel_router_config mal_channel_router_config_init(mal_uint32 channelsIn, const mal_channel channelMapIn[MA_MAX_CHANNELS], mal_uint32 channelsOut, const mal_channel channelMapOut[MA_MAX_CHANNELS], mal_channel_mix_mode mixingMode, mal_channel_router_read_deinterleaved_proc onRead, void* pUserData) +ma_channel_router_config ma_channel_router_config_init(ma_uint32 channelsIn, const ma_channel channelMapIn[MA_MAX_CHANNELS], ma_uint32 channelsOut, const ma_channel channelMapOut[MA_MAX_CHANNELS], ma_channel_mix_mode mixingMode, ma_channel_router_read_deinterleaved_proc onRead, void* pUserData) { - mal_channel_router_config config; - mal_zero_object(&config); + ma_channel_router_config config; + ma_zero_object(&config); config.channelsIn = channelsIn; - for (mal_uint32 iChannel = 0; iChannel < channelsIn; ++iChannel) { + for (ma_uint32 iChannel = 0; iChannel < channelsIn; ++iChannel) { config.channelMapIn[iChannel] = channelMapIn[iChannel]; } config.channelsOut = channelsOut; - for (mal_uint32 iChannel = 0; iChannel < channelsOut; ++iChannel) { + for (ma_uint32 iChannel = 0; iChannel < channelsOut; ++iChannel) { config.channelMapOut[iChannel] = channelMapOut[iChannel]; } @@ -27547,11 +27547,11 @@ mal_channel_router_config mal_channel_router_config_init(mal_uint32 channelsIn, // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -#define mal_floorf(x) ((float)floor((double)(x))) -#define mal_sinf(x) ((float)sin((double)(x))) -#define mal_cosf(x) ((float)cos((double)(x))) +#define ma_floorf(x) ((float)floor((double)(x))) +#define ma_sinf(x) ((float)sin((double)(x))) +#define ma_cosf(x) ((float)cos((double)(x))) -static MA_INLINE double mal_sinc(double x) +static MA_INLINE double ma_sinc(double x) { if (x != 0) { return sin(MA_PI_D*x) / (MA_PI_D*x); @@ -27560,35 +27560,35 @@ static MA_INLINE double mal_sinc(double x) } } -#define mal_sincf(x) ((float)mal_sinc((double)(x))) +#define ma_sincf(x) ((float)ma_sinc((double)(x))) -mal_uint64 mal_src_read_deinterleaved__passthrough(mal_src* pSRC, mal_uint64 frameCount, void** ppSamplesOut, void* pUserData); -mal_uint64 mal_src_read_deinterleaved__linear(mal_src* pSRC, mal_uint64 frameCount, void** ppSamplesOut, void* pUserData); -mal_uint64 mal_src_read_deinterleaved__sinc(mal_src* pSRC, mal_uint64 frameCount, void** ppSamplesOut, void* pUserData); +ma_uint64 ma_src_read_deinterleaved__passthrough(ma_src* pSRC, ma_uint64 frameCount, void** ppSamplesOut, void* pUserData); +ma_uint64 ma_src_read_deinterleaved__linear(ma_src* pSRC, ma_uint64 frameCount, void** ppSamplesOut, void* pUserData); +ma_uint64 ma_src_read_deinterleaved__sinc(ma_src* pSRC, ma_uint64 frameCount, void** ppSamplesOut, void* pUserData); -void mal_src__build_sinc_table__sinc(mal_src* pSRC) +void ma_src__build_sinc_table__sinc(ma_src* pSRC) { - mal_assert(pSRC != NULL); + ma_assert(pSRC != NULL); pSRC->sinc.table[0] = 1.0f; - for (mal_uint32 i = 1; i < mal_countof(pSRC->sinc.table); i += 1) { + for (ma_uint32 i = 1; i < ma_countof(pSRC->sinc.table); i += 1) { double x = i*MA_PI_D / MA_SRC_SINC_LOOKUP_TABLE_RESOLUTION; pSRC->sinc.table[i] = (float)(sin(x)/x); } } -void mal_src__build_sinc_table__rectangular(mal_src* pSRC) +void ma_src__build_sinc_table__rectangular(ma_src* pSRC) { // This is the same as the base sinc table. - mal_src__build_sinc_table__sinc(pSRC); + ma_src__build_sinc_table__sinc(pSRC); } -void mal_src__build_sinc_table__hann(mal_src* pSRC) +void ma_src__build_sinc_table__hann(ma_src* pSRC) { - mal_src__build_sinc_table__sinc(pSRC); + ma_src__build_sinc_table__sinc(pSRC); - for (mal_uint32 i = 0; i < mal_countof(pSRC->sinc.table); i += 1) { + for (ma_uint32 i = 0; i < ma_countof(pSRC->sinc.table); i += 1) { double x = pSRC->sinc.table[i]; double N = MA_SRC_SINC_MAX_WINDOW_WIDTH*2; double n = ((double)(i) / MA_SRC_SINC_LOOKUP_TABLE_RESOLUTION) + MA_SRC_SINC_MAX_WINDOW_WIDTH; @@ -27598,13 +27598,13 @@ void mal_src__build_sinc_table__hann(mal_src* pSRC) } } -mal_result mal_src_init(const mal_src_config* pConfig, mal_src* pSRC) +ma_result ma_src_init(const ma_src_config* pConfig, ma_src* pSRC) { if (pSRC == NULL) { return MA_INVALID_ARGS; } - mal_zero_object(pSRC); + ma_zero_object(pSRC); if (pConfig == NULL || pConfig->onReadDeinterleaved == NULL) { return MA_INVALID_ARGS; @@ -27616,12 +27616,12 @@ mal_result mal_src_init(const mal_src_config* pConfig, mal_src* pSRC) pSRC->config = *pConfig; // SIMD - pSRC->useSSE2 = mal_has_sse2() && !pConfig->noSSE2; - pSRC->useAVX2 = mal_has_avx2() && !pConfig->noAVX2; - pSRC->useAVX512 = mal_has_avx512f() && !pConfig->noAVX512; - pSRC->useNEON = mal_has_neon() && !pConfig->noNEON; + pSRC->useSSE2 = ma_has_sse2() && !pConfig->noSSE2; + pSRC->useAVX2 = ma_has_avx2() && !pConfig->noAVX2; + pSRC->useAVX512 = ma_has_avx512f() && !pConfig->noAVX512; + pSRC->useNEON = ma_has_neon() && !pConfig->noNEON; - if (pSRC->config.algorithm == mal_src_algorithm_sinc) { + if (pSRC->config.algorithm == ma_src_algorithm_sinc) { // Make sure the window width within bounds. if (pSRC->config.sinc.windowWidth == 0) { pSRC->config.sinc.windowWidth = MA_SRC_SINC_DEFAULT_WINDOW_WIDTH; @@ -27635,8 +27635,8 @@ mal_result mal_src_init(const mal_src_config* pConfig, mal_src* pSRC) // Set up the lookup table. switch (pSRC->config.sinc.windowFunction) { - case mal_src_sinc_window_function_hann: mal_src__build_sinc_table__hann(pSRC); break; - case mal_src_sinc_window_function_rectangular: mal_src__build_sinc_table__rectangular(pSRC); break; + case ma_src_sinc_window_function_hann: ma_src__build_sinc_table__hann(pSRC); break; + case ma_src_sinc_window_function_rectangular: ma_src__build_sinc_table__rectangular(pSRC); break; default: return MA_INVALID_ARGS; // <-- Hitting this means the window function is unknown to miniaudio. } } @@ -27644,7 +27644,7 @@ mal_result mal_src_init(const mal_src_config* pConfig, mal_src* pSRC) return MA_SUCCESS; } -mal_result mal_src_set_sample_rate(mal_src* pSRC, mal_uint32 sampleRateIn, mal_uint32 sampleRateOut) +ma_result ma_src_set_sample_rate(ma_src* pSRC, ma_uint32 sampleRateIn, ma_uint32 sampleRateOut) { if (pSRC == NULL) { return MA_INVALID_ARGS; @@ -27655,25 +27655,25 @@ mal_result mal_src_set_sample_rate(mal_src* pSRC, mal_uint32 sampleRateIn, mal_u return MA_INVALID_ARGS; } - mal_atomic_exchange_32(&pSRC->config.sampleRateIn, sampleRateIn); - mal_atomic_exchange_32(&pSRC->config.sampleRateOut, sampleRateOut); + ma_atomic_exchange_32(&pSRC->config.sampleRateIn, sampleRateIn); + ma_atomic_exchange_32(&pSRC->config.sampleRateOut, sampleRateOut); return MA_SUCCESS; } -mal_uint64 mal_src_read_deinterleaved(mal_src* pSRC, mal_uint64 frameCount, void** ppSamplesOut, void* pUserData) +ma_uint64 ma_src_read_deinterleaved(ma_src* pSRC, ma_uint64 frameCount, void** ppSamplesOut, void* pUserData) { if (pSRC == NULL || frameCount == 0 || ppSamplesOut == NULL) { return 0; } - mal_src_algorithm algorithm = pSRC->config.algorithm; + ma_src_algorithm algorithm = pSRC->config.algorithm; // Can use a function pointer for this. switch (algorithm) { - case mal_src_algorithm_none: return mal_src_read_deinterleaved__passthrough(pSRC, frameCount, ppSamplesOut, pUserData); - case mal_src_algorithm_linear: return mal_src_read_deinterleaved__linear( pSRC, frameCount, ppSamplesOut, pUserData); - case mal_src_algorithm_sinc: return mal_src_read_deinterleaved__sinc( pSRC, frameCount, ppSamplesOut, pUserData); + case ma_src_algorithm_none: return ma_src_read_deinterleaved__passthrough(pSRC, frameCount, ppSamplesOut, pUserData); + case ma_src_algorithm_linear: return ma_src_read_deinterleaved__linear( pSRC, frameCount, ppSamplesOut, pUserData); + case ma_src_algorithm_sinc: return ma_src_read_deinterleaved__sinc( pSRC, frameCount, ppSamplesOut, pUserData); default: break; } @@ -27681,31 +27681,31 @@ mal_uint64 mal_src_read_deinterleaved(mal_src* pSRC, mal_uint64 frameCount, void return 0; } -mal_uint64 mal_src_read_deinterleaved__passthrough(mal_src* pSRC, mal_uint64 frameCount, void** ppSamplesOut, void* pUserData) +ma_uint64 ma_src_read_deinterleaved__passthrough(ma_src* pSRC, ma_uint64 frameCount, void** ppSamplesOut, void* pUserData) { if (frameCount <= 0xFFFFFFFF) { - return pSRC->config.onReadDeinterleaved(pSRC, (mal_uint32)frameCount, ppSamplesOut, pUserData); + return pSRC->config.onReadDeinterleaved(pSRC, (ma_uint32)frameCount, ppSamplesOut, pUserData); } else { float* ppNextSamplesOut[MA_MAX_CHANNELS]; - for (mal_uint32 iChannel = 0; iChannel < pSRC->config.channels; ++iChannel) { + for (ma_uint32 iChannel = 0; iChannel < pSRC->config.channels; ++iChannel) { ppNextSamplesOut[iChannel] = (float*)ppSamplesOut[iChannel]; } - mal_uint64 totalFramesRead = 0; + ma_uint64 totalFramesRead = 0; while (totalFramesRead < frameCount) { - mal_uint64 framesRemaining = frameCount - totalFramesRead; - mal_uint64 framesToReadRightNow = framesRemaining; + ma_uint64 framesRemaining = frameCount - totalFramesRead; + ma_uint64 framesToReadRightNow = framesRemaining; if (framesToReadRightNow > 0xFFFFFFFF) { framesToReadRightNow = 0xFFFFFFFF; } - mal_uint32 framesJustRead = (mal_uint32)pSRC->config.onReadDeinterleaved(pSRC, (mal_uint32)framesToReadRightNow, (void**)ppNextSamplesOut, pUserData); + ma_uint32 framesJustRead = (ma_uint32)pSRC->config.onReadDeinterleaved(pSRC, (ma_uint32)framesToReadRightNow, (void**)ppNextSamplesOut, pUserData); if (framesJustRead == 0) { break; } totalFramesRead += framesJustRead; - for (mal_uint32 iChannel = 0; iChannel < pSRC->config.channels; ++iChannel) { + for (ma_uint32 iChannel = 0; iChannel < pSRC->config.channels; ++iChannel) { ppNextSamplesOut[iChannel] += framesJustRead; } @@ -27718,24 +27718,24 @@ mal_uint64 mal_src_read_deinterleaved__passthrough(mal_src* pSRC, mal_uint64 fra } } -mal_uint64 mal_src_read_deinterleaved__linear(mal_src* pSRC, mal_uint64 frameCount, void** ppSamplesOut, void* pUserData) +ma_uint64 ma_src_read_deinterleaved__linear(ma_src* pSRC, ma_uint64 frameCount, void** ppSamplesOut, void* pUserData) { - mal_assert(pSRC != NULL); - mal_assert(frameCount > 0); - mal_assert(ppSamplesOut != NULL); + ma_assert(pSRC != NULL); + ma_assert(frameCount > 0); + ma_assert(ppSamplesOut != NULL); float* ppNextSamplesOut[MA_MAX_CHANNELS]; - mal_copy_memory(ppNextSamplesOut, ppSamplesOut, sizeof(void*) * pSRC->config.channels); + ma_copy_memory(ppNextSamplesOut, ppSamplesOut, sizeof(void*) * pSRC->config.channels); float factor = (float)pSRC->config.sampleRateIn / pSRC->config.sampleRateOut; - mal_uint32 maxFrameCountPerChunkIn = mal_countof(pSRC->linear.input[0]); + ma_uint32 maxFrameCountPerChunkIn = ma_countof(pSRC->linear.input[0]); - mal_uint64 totalFramesRead = 0; + ma_uint64 totalFramesRead = 0; while (totalFramesRead < frameCount) { - mal_uint64 framesRemaining = frameCount - totalFramesRead; - mal_uint64 framesToRead = framesRemaining; + ma_uint64 framesRemaining = frameCount - totalFramesRead; + ma_uint64 framesToRead = framesRemaining; if (framesToRead > 16384) { framesToRead = 16384; // <-- Keep this small because we're using 32-bit floats for calculating sample positions and I don't want to run out of precision with huge sample counts. } @@ -27746,19 +27746,19 @@ mal_uint64 mal_src_read_deinterleaved__linear(mal_src* pSRC, mal_uint64 frameCou float tBeg = pSRC->linear.timeIn; float tEnd = tBeg + (framesToRead*factor); - mal_uint32 framesToReadFromClient = (mal_uint32)(tEnd) + 1 + 1; // +1 to make tEnd 1-based and +1 because we always need to an extra sample for interpolation. + ma_uint32 framesToReadFromClient = (ma_uint32)(tEnd) + 1 + 1; // +1 to make tEnd 1-based and +1 because we always need to an extra sample for interpolation. if (framesToReadFromClient >= maxFrameCountPerChunkIn) { framesToReadFromClient = maxFrameCountPerChunkIn; } float* ppSamplesFromClient[MA_MAX_CHANNELS]; - for (mal_uint32 iChannel = 0; iChannel < pSRC->config.channels; ++iChannel) { + for (ma_uint32 iChannel = 0; iChannel < pSRC->config.channels; ++iChannel) { ppSamplesFromClient[iChannel] = pSRC->linear.input[iChannel] + pSRC->linear.leftoverFrames; } - mal_uint32 framesReadFromClient = 0; + ma_uint32 framesReadFromClient = 0; if (framesToReadFromClient > pSRC->linear.leftoverFrames) { - framesReadFromClient = (mal_uint32)pSRC->config.onReadDeinterleaved(pSRC, (mal_uint32)framesToReadFromClient - pSRC->linear.leftoverFrames, (void**)ppSamplesFromClient, pUserData); + framesReadFromClient = (ma_uint32)pSRC->config.onReadDeinterleaved(pSRC, (ma_uint32)framesToReadFromClient - pSRC->linear.leftoverFrames, (void**)ppSamplesFromClient, pUserData); } framesReadFromClient += pSRC->linear.leftoverFrames; // <-- You can sort of think of it as though we've re-read the leftover samples from the client. @@ -27766,7 +27766,7 @@ mal_uint64 mal_src_read_deinterleaved__linear(mal_src* pSRC, mal_uint64 frameCou break; } - for (mal_uint32 iChannel = 0; iChannel < pSRC->config.channels; ++iChannel) { + for (ma_uint32 iChannel = 0; iChannel < pSRC->config.channels; ++iChannel) { ppSamplesFromClient[iChannel] = pSRC->linear.input[iChannel]; } @@ -27778,23 +27778,23 @@ mal_uint64 mal_src_read_deinterleaved__linear(mal_src* pSRC, mal_uint64 frameCou // that can be processed from this input. We want to output as many samples as possible from our input data. float tAvailable = framesReadFromClient - tBeg - 1; // Subtract 1 because the last input sample is needed for interpolation and cannot be included in the output sample count calculation. - mal_uint32 maxOutputFramesToRead = (mal_uint32)(tAvailable / factor); + ma_uint32 maxOutputFramesToRead = (ma_uint32)(tAvailable / factor); if (maxOutputFramesToRead == 0) { maxOutputFramesToRead = 1; } if (maxOutputFramesToRead > framesToRead) { - maxOutputFramesToRead = (mal_uint32)framesToRead; + maxOutputFramesToRead = (ma_uint32)framesToRead; } // Output frames are always read in groups of 4 because I'm planning on using this as a reference for some SIMD-y stuff later. - mal_uint32 maxOutputFramesToRead4 = maxOutputFramesToRead/4; - for (mal_uint32 iChannel = 0; iChannel < pSRC->config.channels; ++iChannel) { + ma_uint32 maxOutputFramesToRead4 = maxOutputFramesToRead/4; + for (ma_uint32 iChannel = 0; iChannel < pSRC->config.channels; ++iChannel) { float t0 = pSRC->linear.timeIn + factor*0; float t1 = pSRC->linear.timeIn + factor*1; float t2 = pSRC->linear.timeIn + factor*2; float t3 = pSRC->linear.timeIn + factor*3; - for (mal_uint32 iFrameOut = 0; iFrameOut < maxOutputFramesToRead4; iFrameOut += 1) { + for (ma_uint32 iFrameOut = 0; iFrameOut < maxOutputFramesToRead4; iFrameOut += 1) { float iPrevSample0 = (float)floor(t0); float iPrevSample1 = (float)floor(t1); float iPrevSample2 = (float)floor(t2); @@ -27810,20 +27810,20 @@ mal_uint64 mal_src_read_deinterleaved__linear(mal_src* pSRC, mal_uint64 frameCou float alpha2 = t2 - iPrevSample2; float alpha3 = t3 - iPrevSample3; - float prevSample0 = ppSamplesFromClient[iChannel][(mal_uint32)iPrevSample0]; - float prevSample1 = ppSamplesFromClient[iChannel][(mal_uint32)iPrevSample1]; - float prevSample2 = ppSamplesFromClient[iChannel][(mal_uint32)iPrevSample2]; - float prevSample3 = ppSamplesFromClient[iChannel][(mal_uint32)iPrevSample3]; + float prevSample0 = ppSamplesFromClient[iChannel][(ma_uint32)iPrevSample0]; + float prevSample1 = ppSamplesFromClient[iChannel][(ma_uint32)iPrevSample1]; + float prevSample2 = ppSamplesFromClient[iChannel][(ma_uint32)iPrevSample2]; + float prevSample3 = ppSamplesFromClient[iChannel][(ma_uint32)iPrevSample3]; - float nextSample0 = ppSamplesFromClient[iChannel][(mal_uint32)iNextSample0]; - float nextSample1 = ppSamplesFromClient[iChannel][(mal_uint32)iNextSample1]; - float nextSample2 = ppSamplesFromClient[iChannel][(mal_uint32)iNextSample2]; - float nextSample3 = ppSamplesFromClient[iChannel][(mal_uint32)iNextSample3]; + float nextSample0 = ppSamplesFromClient[iChannel][(ma_uint32)iNextSample0]; + float nextSample1 = ppSamplesFromClient[iChannel][(ma_uint32)iNextSample1]; + float nextSample2 = ppSamplesFromClient[iChannel][(ma_uint32)iNextSample2]; + float nextSample3 = ppSamplesFromClient[iChannel][(ma_uint32)iNextSample3]; - ppNextSamplesOut[iChannel][iFrameOut*4 + 0] = mal_mix_f32_fast(prevSample0, nextSample0, alpha0); - ppNextSamplesOut[iChannel][iFrameOut*4 + 1] = mal_mix_f32_fast(prevSample1, nextSample1, alpha1); - ppNextSamplesOut[iChannel][iFrameOut*4 + 2] = mal_mix_f32_fast(prevSample2, nextSample2, alpha2); - ppNextSamplesOut[iChannel][iFrameOut*4 + 3] = mal_mix_f32_fast(prevSample3, nextSample3, alpha3); + ppNextSamplesOut[iChannel][iFrameOut*4 + 0] = ma_mix_f32_fast(prevSample0, nextSample0, alpha0); + ppNextSamplesOut[iChannel][iFrameOut*4 + 1] = ma_mix_f32_fast(prevSample1, nextSample1, alpha1); + ppNextSamplesOut[iChannel][iFrameOut*4 + 2] = ma_mix_f32_fast(prevSample2, nextSample2, alpha2); + ppNextSamplesOut[iChannel][iFrameOut*4 + 3] = ma_mix_f32_fast(prevSample3, nextSample3, alpha3); t0 += factor*4; t1 += factor*4; @@ -27832,18 +27832,18 @@ mal_uint64 mal_src_read_deinterleaved__linear(mal_src* pSRC, mal_uint64 frameCou } float t = pSRC->linear.timeIn + (factor*maxOutputFramesToRead4*4); - for (mal_uint32 iFrameOut = (maxOutputFramesToRead4*4); iFrameOut < maxOutputFramesToRead; iFrameOut += 1) { + for (ma_uint32 iFrameOut = (maxOutputFramesToRead4*4); iFrameOut < maxOutputFramesToRead; iFrameOut += 1) { float iPrevSample = (float)floor(t); float iNextSample = iPrevSample + 1; float alpha = t - iPrevSample; - mal_assert(iPrevSample < mal_countof(pSRC->linear.input[iChannel])); - mal_assert(iNextSample < mal_countof(pSRC->linear.input[iChannel])); + ma_assert(iPrevSample < ma_countof(pSRC->linear.input[iChannel])); + ma_assert(iNextSample < ma_countof(pSRC->linear.input[iChannel])); - float prevSample = ppSamplesFromClient[iChannel][(mal_uint32)iPrevSample]; - float nextSample = ppSamplesFromClient[iChannel][(mal_uint32)iNextSample]; + float prevSample = ppSamplesFromClient[iChannel][(ma_uint32)iPrevSample]; + float nextSample = ppSamplesFromClient[iChannel][(ma_uint32)iNextSample]; - ppNextSamplesOut[iChannel][iFrameOut] = mal_mix_f32_fast(prevSample, nextSample, alpha); + ppNextSamplesOut[iChannel][iFrameOut] = ma_mix_f32_fast(prevSample, nextSample, alpha); t += factor; } @@ -27859,14 +27859,14 @@ mal_uint64 mal_src_read_deinterleaved__linear(mal_src* pSRC, mal_uint64 frameCou float tNext = pSRC->linear.timeIn + (maxOutputFramesToRead*factor); pSRC->linear.timeIn = tNext; - mal_assert(tNext <= framesReadFromClient+1); + ma_assert(tNext <= framesReadFromClient+1); - mal_uint32 iNextFrame = (mal_uint32)floor(tNext); + ma_uint32 iNextFrame = (ma_uint32)floor(tNext); pSRC->linear.leftoverFrames = framesReadFromClient - iNextFrame; pSRC->linear.timeIn = tNext - iNextFrame; - for (mal_uint32 iChannel = 0; iChannel < pSRC->config.channels; ++iChannel) { - for (mal_uint32 iFrame = 0; iFrame < pSRC->linear.leftoverFrames; ++iFrame) { + for (ma_uint32 iChannel = 0; iChannel < pSRC->config.channels; ++iChannel) { + for (ma_uint32 iFrame = 0; iFrame < pSRC->linear.leftoverFrames; ++iFrame) { float sample = ppSamplesFromClient[iChannel][framesReadFromClient-pSRC->linear.leftoverFrames + iFrame]; ppSamplesFromClient[iChannel][iFrame] = sample; } @@ -27883,17 +27883,17 @@ mal_uint64 mal_src_read_deinterleaved__linear(mal_src* pSRC, mal_uint64 frameCou } -mal_src_config mal_src_config_init_new() +ma_src_config ma_src_config_init_new() { - mal_src_config config; - mal_zero_object(&config); + ma_src_config config; + ma_zero_object(&config); return config; } -mal_src_config mal_src_config_init(mal_uint32 sampleRateIn, mal_uint32 sampleRateOut, mal_uint32 channels, mal_src_read_deinterleaved_proc onReadDeinterleaved, void* pUserData) +ma_src_config ma_src_config_init(ma_uint32 sampleRateIn, ma_uint32 sampleRateOut, ma_uint32 channels, ma_src_read_deinterleaved_proc onReadDeinterleaved, void* pUserData) { - mal_src_config config = mal_src_config_init_new(); + ma_src_config config = ma_src_config_init_new(); config.sampleRateIn = sampleRateIn; config.sampleRateOut = sampleRateOut; config.channels = channels; @@ -27935,22 +27935,22 @@ mal_src_config mal_src_config_init(mal_uint32 sampleRateIn, mal_uint32 sampleRat #define MA_USE_SINC_TABLE_INTERPOLATION // Retrieves a sample from the input buffer's window. Values >= 0 retrieve future samples. Negative values return past samples. -static MA_INLINE float mal_src_sinc__get_input_sample_from_window(const mal_src* pSRC, mal_uint32 channel, mal_uint32 windowPosInSamples, mal_int32 sampleIndex) +static MA_INLINE float ma_src_sinc__get_input_sample_from_window(const ma_src* pSRC, ma_uint32 channel, ma_uint32 windowPosInSamples, ma_int32 sampleIndex) { - mal_assert(pSRC != NULL); - mal_assert(channel < pSRC->config.channels); - mal_assert(sampleIndex >= -(mal_int32)pSRC->config.sinc.windowWidth); - mal_assert(sampleIndex < (mal_int32)pSRC->config.sinc.windowWidth); + ma_assert(pSRC != NULL); + ma_assert(channel < pSRC->config.channels); + ma_assert(sampleIndex >= -(ma_int32)pSRC->config.sinc.windowWidth); + ma_assert(sampleIndex < (ma_int32)pSRC->config.sinc.windowWidth); // The window should always be contained within the input cache. - mal_assert(windowPosInSamples < mal_countof(pSRC->sinc.input[0]) - pSRC->config.sinc.windowWidth); + ma_assert(windowPosInSamples < ma_countof(pSRC->sinc.input[0]) - pSRC->config.sinc.windowWidth); return pSRC->sinc.input[channel][windowPosInSamples + pSRC->config.sinc.windowWidth + sampleIndex]; } -static MA_INLINE float mal_src_sinc__interpolation_factor(const mal_src* pSRC, float x) +static MA_INLINE float ma_src_sinc__interpolation_factor(const ma_src* pSRC, float x) { - mal_assert(pSRC != NULL); + ma_assert(pSRC != NULL); float xabs = (float)fabs(x); //if (xabs >= MA_SRC_SINC_MAX_WINDOW_WIDTH /*pSRC->config.sinc.windowWidth*/) { @@ -27958,34 +27958,34 @@ static MA_INLINE float mal_src_sinc__interpolation_factor(const mal_src* pSRC, f //} xabs = xabs * MA_SRC_SINC_LOOKUP_TABLE_RESOLUTION; - mal_int32 ixabs = (mal_int32)xabs; + ma_int32 ixabs = (ma_int32)xabs; #if defined(MA_USE_SINC_TABLE_INTERPOLATION) float a = xabs - ixabs; - return mal_mix_f32_fast(pSRC->sinc.table[ixabs], pSRC->sinc.table[ixabs+1], a); + return ma_mix_f32_fast(pSRC->sinc.table[ixabs], pSRC->sinc.table[ixabs+1], a); #else return pSRC->sinc.table[ixabs]; #endif } #if defined(MA_SUPPORT_SSE2) -static MA_INLINE __m128 mal_fabsf_sse2(__m128 x) +static MA_INLINE __m128 ma_fabsf_sse2(__m128 x) { return _mm_and_ps(_mm_castsi128_ps(_mm_set1_epi32(0x7FFFFFFF)), x); } -static MA_INLINE __m128 mal_truncf_sse2(__m128 x) +static MA_INLINE __m128 ma_truncf_sse2(__m128 x) { return _mm_cvtepi32_ps(_mm_cvttps_epi32(x)); } -static MA_INLINE __m128 mal_src_sinc__interpolation_factor__sse2(const mal_src* pSRC, __m128 x) +static MA_INLINE __m128 ma_src_sinc__interpolation_factor__sse2(const ma_src* pSRC, __m128 x) { //__m128 windowWidth128 = _mm_set1_ps(MA_SRC_SINC_MAX_WINDOW_WIDTH); __m128 resolution128 = _mm_set1_ps(MA_SRC_SINC_LOOKUP_TABLE_RESOLUTION); //__m128 one = _mm_set1_ps(1); - __m128 xabs = mal_fabsf_sse2(x); + __m128 xabs = ma_fabsf_sse2(x); // if (MA_SRC_SINC_MAX_WINDOW_WIDTH <= xabs) xabs = 1 else xabs = xabs; //__m128 xcmp = _mm_cmp_ps(windowWidth128, xabs, 2); // 2 = Less than or equal = _mm_cmple_ps. @@ -28011,26 +28011,26 @@ static MA_INLINE __m128 mal_src_sinc__interpolation_factor__sse2(const mal_src* ); __m128 a = _mm_sub_ps(xabs, _mm_cvtepi32_ps(ixabs)); - __m128 r = mal_mix_f32_fast__sse2(lo, hi, a); + __m128 r = ma_mix_f32_fast__sse2(lo, hi, a); return r; } #endif #if defined(MA_SUPPORT_AVX2) -static MA_INLINE __m256 mal_fabsf_avx2(__m256 x) +static MA_INLINE __m256 ma_fabsf_avx2(__m256 x) { return _mm256_and_ps(_mm256_castsi256_ps(_mm256_set1_epi32(0x7FFFFFFF)), x); } #if 0 -static MA_INLINE __m256 mal_src_sinc__interpolation_factor__avx2(const mal_src* pSRC, __m256 x) +static MA_INLINE __m256 ma_src_sinc__interpolation_factor__avx2(const ma_src* pSRC, __m256 x) { //__m256 windowWidth256 = _mm256_set1_ps(MA_SRC_SINC_MAX_WINDOW_WIDTH); __m256 resolution256 = _mm256_set1_ps(MA_SRC_SINC_LOOKUP_TABLE_RESOLUTION); //__m256 one = _mm256_set1_ps(1); - __m256 xabs = mal_fabsf_avx2(x); + __m256 xabs = ma_fabsf_avx2(x); // if (MA_SRC_SINC_MAX_WINDOW_WIDTH <= xabs) xabs = 1 else xabs = xabs; //__m256 xcmp = _mm256_cmp_ps(windowWidth256, xabs, 2); // 2 = Less than or equal = _mm_cmple_ps. @@ -28066,7 +28066,7 @@ static MA_INLINE __m256 mal_src_sinc__interpolation_factor__avx2(const mal_src* pSRC->sinc.table[ixabsv[0]+1] ); - __m256 r = mal_mix_f32_fast__avx2(lo, hi, a); + __m256 r = ma_mix_f32_fast__avx2(lo, hi, a); return r; } @@ -28075,14 +28075,14 @@ static MA_INLINE __m256 mal_src_sinc__interpolation_factor__avx2(const mal_src* #endif #if defined(MA_SUPPORT_NEON) -static MA_INLINE float32x4_t mal_fabsf_neon(float32x4_t x) +static MA_INLINE float32x4_t ma_fabsf_neon(float32x4_t x) { return vabdq_f32(vmovq_n_f32(0), x); } -static MA_INLINE float32x4_t mal_src_sinc__interpolation_factor__neon(const mal_src* pSRC, float32x4_t x) +static MA_INLINE float32x4_t ma_src_sinc__interpolation_factor__neon(const ma_src* pSRC, float32x4_t x) { - float32x4_t xabs = mal_fabsf_neon(x); + float32x4_t xabs = ma_fabsf_neon(x); xabs = vmulq_n_f32(xabs, MA_SRC_SINC_LOOKUP_TABLE_RESOLUTION); int32x4_t ixabs = vcvtq_s32_f32(xabs); @@ -28102,27 +28102,27 @@ static MA_INLINE float32x4_t mal_src_sinc__interpolation_factor__neon(const mal_ hi[3] = pSRC->sinc.table[ixabsv[3]+1]; float32x4_t a = vsubq_f32(xabs, vcvtq_f32_s32(ixabs)); - float32x4_t r = mal_mix_f32_fast__neon(vld1q_f32(lo), vld1q_f32(hi), a); + float32x4_t r = ma_mix_f32_fast__neon(vld1q_f32(lo), vld1q_f32(hi), a); return r; } #endif -mal_uint64 mal_src_read_deinterleaved__sinc(mal_src* pSRC, mal_uint64 frameCount, void** ppSamplesOut, void* pUserData) +ma_uint64 ma_src_read_deinterleaved__sinc(ma_src* pSRC, ma_uint64 frameCount, void** ppSamplesOut, void* pUserData) { - mal_assert(pSRC != NULL); - mal_assert(frameCount > 0); - mal_assert(ppSamplesOut != NULL); + ma_assert(pSRC != NULL); + ma_assert(frameCount > 0); + ma_assert(ppSamplesOut != NULL); float factor = (float)pSRC->config.sampleRateIn / pSRC->config.sampleRateOut; float inverseFactor = 1/factor; - mal_int32 windowWidth = (mal_int32)pSRC->config.sinc.windowWidth; - mal_int32 windowWidth2 = windowWidth*2; + ma_int32 windowWidth = (ma_int32)pSRC->config.sinc.windowWidth; + ma_int32 windowWidth2 = windowWidth*2; // There are cases where it's actually more efficient to increase the window width so that it's aligned with the respective // SIMD pipeline being used. - mal_int32 windowWidthSIMD = windowWidth; + ma_int32 windowWidthSIMD = windowWidth; if (pSRC->useNEON) { windowWidthSIMD = (windowWidthSIMD + 1) & ~(1); } else if (pSRC->useAVX512) { @@ -28133,28 +28133,28 @@ mal_uint64 mal_src_read_deinterleaved__sinc(mal_src* pSRC, mal_uint64 frameCount windowWidthSIMD = (windowWidthSIMD + 1) & ~(1); } - mal_int32 windowWidthSIMD2 = windowWidthSIMD*2; + ma_int32 windowWidthSIMD2 = windowWidthSIMD*2; (void)windowWidthSIMD2; // <-- Silence a warning when SIMD is disabled. float* ppNextSamplesOut[MA_MAX_CHANNELS]; - mal_copy_memory(ppNextSamplesOut, ppSamplesOut, sizeof(void*) * pSRC->config.channels); + ma_copy_memory(ppNextSamplesOut, ppSamplesOut, sizeof(void*) * pSRC->config.channels); float _windowSamplesUnaligned[MA_SRC_SINC_MAX_WINDOW_WIDTH*2 + MA_SIMD_ALIGNMENT]; - float* windowSamples = (float*)(((mal_uintptr)_windowSamplesUnaligned + MA_SIMD_ALIGNMENT-1) & ~(MA_SIMD_ALIGNMENT-1)); - mal_zero_memory(windowSamples, MA_SRC_SINC_MAX_WINDOW_WIDTH*2 * sizeof(float)); + float* windowSamples = (float*)(((ma_uintptr)_windowSamplesUnaligned + MA_SIMD_ALIGNMENT-1) & ~(MA_SIMD_ALIGNMENT-1)); + ma_zero_memory(windowSamples, MA_SRC_SINC_MAX_WINDOW_WIDTH*2 * sizeof(float)); float _iWindowFUnaligned[MA_SRC_SINC_MAX_WINDOW_WIDTH*2 + MA_SIMD_ALIGNMENT]; - float* iWindowF = (float*)(((mal_uintptr)_iWindowFUnaligned + MA_SIMD_ALIGNMENT-1) & ~(MA_SIMD_ALIGNMENT-1)); - mal_zero_memory(iWindowF, MA_SRC_SINC_MAX_WINDOW_WIDTH*2 * sizeof(float)); - for (mal_int32 i = 0; i < windowWidth2; ++i) { + float* iWindowF = (float*)(((ma_uintptr)_iWindowFUnaligned + MA_SIMD_ALIGNMENT-1) & ~(MA_SIMD_ALIGNMENT-1)); + ma_zero_memory(iWindowF, MA_SRC_SINC_MAX_WINDOW_WIDTH*2 * sizeof(float)); + for (ma_int32 i = 0; i < windowWidth2; ++i) { iWindowF[i] = (float)(i - windowWidth); } - mal_uint64 totalOutputFramesRead = 0; + ma_uint64 totalOutputFramesRead = 0; while (totalOutputFramesRead < frameCount) { // The maximum number of frames we can read this iteration depends on how many input samples we have available to us. This is the number // of input samples between the end of the window and the end of the cache. - mal_uint32 maxInputSamplesAvailableInCache = mal_countof(pSRC->sinc.input[0]) - (pSRC->config.sinc.windowWidth*2) - pSRC->sinc.windowPosInSamples; + ma_uint32 maxInputSamplesAvailableInCache = ma_countof(pSRC->sinc.input[0]) - (pSRC->config.sinc.windowWidth*2) - pSRC->sinc.windowPosInSamples; if (maxInputSamplesAvailableInCache > pSRC->sinc.inputFrameCount) { maxInputSamplesAvailableInCache = pSRC->sinc.inputFrameCount; } @@ -28171,30 +28171,30 @@ mal_uint64 mal_src_read_deinterleaved__sinc(mal_src* pSRC, mal_uint64 frameCount float timeInBeg = pSRC->sinc.timeIn; float timeInEnd = (float)(pSRC->sinc.windowPosInSamples + maxInputSamplesAvailableInCache); - mal_assert(timeInBeg >= 0); - mal_assert(timeInBeg <= timeInEnd); + ma_assert(timeInBeg >= 0); + ma_assert(timeInBeg <= timeInEnd); - mal_uint64 maxOutputFramesToRead = (mal_uint64)(((timeInEnd - timeInBeg) * inverseFactor)); + ma_uint64 maxOutputFramesToRead = (ma_uint64)(((timeInEnd - timeInBeg) * inverseFactor)); - mal_uint64 outputFramesRemaining = frameCount - totalOutputFramesRead; - mal_uint64 outputFramesToRead = outputFramesRemaining; + ma_uint64 outputFramesRemaining = frameCount - totalOutputFramesRead; + ma_uint64 outputFramesToRead = outputFramesRemaining; if (outputFramesToRead > maxOutputFramesToRead) { outputFramesToRead = maxOutputFramesToRead; } - for (mal_uint32 iChannel = 0; iChannel < pSRC->config.channels; iChannel += 1) { + for (ma_uint32 iChannel = 0; iChannel < pSRC->config.channels; iChannel += 1) { // Do SRC. float timeIn = timeInBeg; - for (mal_uint32 iSample = 0; iSample < outputFramesToRead; iSample += 1) { + for (ma_uint32 iSample = 0; iSample < outputFramesToRead; iSample += 1) { float sampleOut = 0; - float iTimeInF = mal_floorf(timeIn); - mal_uint32 iTimeIn = (mal_uint32)iTimeInF; + float iTimeInF = ma_floorf(timeIn); + ma_uint32 iTimeIn = (ma_uint32)iTimeInF; - mal_int32 iWindow = 0; + ma_int32 iWindow = 0; // Pre-load the window samples into an aligned buffer to begin with. Need to put these into an aligned buffer to make SIMD easier. windowSamples[0] = 0; // <-- The first sample is always zero. - for (mal_int32 i = 1; i < windowWidth2; ++i) { + for (ma_int32 i = 1; i < windowWidth2; ++i) { windowSamples[i] = pSRC->sinc.input[iChannel][iTimeIn + i]; } @@ -28207,19 +28207,19 @@ mal_uint64 mal_src_read_deinterleaved__sinc(mal_src* pSRC, mal_uint64 frameCount __m256 t = _mm256_set1_ps((timeIn - iTimeInF)); __m256 r = _mm256_set1_ps(0); - mal_int32 windowWidth8 = windowWidthSIMD2 >> 3; - for (mal_int32 iWindow8 = 0; iWindow8 < windowWidth8; iWindow8 += 1) { + ma_int32 windowWidth8 = windowWidthSIMD2 >> 3; + for (ma_int32 iWindow8 = 0; iWindow8 < windowWidth8; iWindow8 += 1) { __m256 w = *((__m256*)iWindowF + iWindow8); __m256 xabs = _mm256_sub_ps(t, w); - xabs = mal_fabsf_avx2(xabs); + xabs = ma_fabsf_avx2(xabs); xabs = _mm256_mul_ps(xabs, resolution256); ixabs[iWindow8] = _mm256_cvttps_epi32(xabs); a[iWindow8] = _mm256_sub_ps(xabs, _mm256_cvtepi32_ps(ixabs[iWindow8])); } - for (mal_int32 iWindow8 = 0; iWindow8 < windowWidth8; iWindow8 += 1) { + for (ma_int32 iWindow8 = 0; iWindow8 < windowWidth8; iWindow8 += 1) { int* ixabsv = (int*)&ixabs[iWindow8]; __m256 lo = _mm256_set_ps( @@ -28245,7 +28245,7 @@ mal_uint64 mal_src_read_deinterleaved__sinc(mal_src* pSRC, mal_uint64 frameCount ); __m256 s = *((__m256*)windowSamples + iWindow8); - r = _mm256_add_ps(r, _mm256_mul_ps(s, mal_mix_f32_fast__avx2(lo, hi, a[iWindow8]))); + r = _mm256_add_ps(r, _mm256_mul_ps(s, ma_mix_f32_fast__avx2(lo, hi, a[iWindow8]))); } // Horizontal add. @@ -28263,12 +28263,12 @@ mal_uint64 mal_src_read_deinterleaved__sinc(mal_src* pSRC, mal_uint64 frameCount __m128 t = _mm_set1_ps((timeIn - iTimeInF)); __m128 r = _mm_set1_ps(0); - mal_int32 windowWidth4 = windowWidthSIMD2 >> 2; - for (mal_int32 iWindow4 = 0; iWindow4 < windowWidth4; iWindow4 += 1) { + ma_int32 windowWidth4 = windowWidthSIMD2 >> 2; + for (ma_int32 iWindow4 = 0; iWindow4 < windowWidth4; iWindow4 += 1) { __m128* s = (__m128*)windowSamples + iWindow4; __m128* w = (__m128*)iWindowF + iWindow4; - __m128 a = mal_src_sinc__interpolation_factor__sse2(pSRC, _mm_sub_ps(t, *w)); + __m128 a = ma_src_sinc__interpolation_factor__sse2(pSRC, _mm_sub_ps(t, *w)); r = _mm_add_ps(r, _mm_mul_ps(*s, a)); } @@ -28286,12 +28286,12 @@ mal_uint64 mal_src_read_deinterleaved__sinc(mal_src* pSRC, mal_uint64 frameCount float32x4_t t = vmovq_n_f32((timeIn - iTimeInF)); float32x4_t r = vmovq_n_f32(0); - mal_int32 windowWidth4 = windowWidthSIMD2 >> 2; - for (mal_int32 iWindow4 = 0; iWindow4 < windowWidth4; iWindow4 += 1) { + ma_int32 windowWidth4 = windowWidthSIMD2 >> 2; + for (ma_int32 iWindow4 = 0; iWindow4 < windowWidth4; iWindow4 += 1) { float32x4_t* s = (float32x4_t*)windowSamples + iWindow4; float32x4_t* w = (float32x4_t*)iWindowF + iWindow4; - float32x4_t a = mal_src_sinc__interpolation_factor__neon(pSRC, vsubq_f32(t, *w)); + float32x4_t a = ma_src_sinc__interpolation_factor__neon(pSRC, vsubq_f32(t, *w)); r = vaddq_f32(r, vmulq_f32(*s, a)); } @@ -28314,7 +28314,7 @@ mal_uint64 mal_src_read_deinterleaved__sinc(mal_src* pSRC, mal_uint64 frameCount float s = windowSamples[iWindow]; float w = iWindowF[iWindow]; - float a = mal_src_sinc__interpolation_factor(pSRC, (t - w)); + float a = ma_src_sinc__interpolation_factor(pSRC, (t - w)); float r = s * a; sampleOut += r; @@ -28330,24 +28330,24 @@ mal_uint64 mal_src_read_deinterleaved__sinc(mal_src* pSRC, mal_uint64 frameCount totalOutputFramesRead += outputFramesToRead; - mal_uint32 prevWindowPosInSamples = pSRC->sinc.windowPosInSamples; + ma_uint32 prevWindowPosInSamples = pSRC->sinc.windowPosInSamples; pSRC->sinc.timeIn += (outputFramesToRead * factor); - pSRC->sinc.windowPosInSamples = (mal_uint32)pSRC->sinc.timeIn; + pSRC->sinc.windowPosInSamples = (ma_uint32)pSRC->sinc.timeIn; pSRC->sinc.inputFrameCount -= pSRC->sinc.windowPosInSamples - prevWindowPosInSamples; // If the window has reached a point where we cannot read a whole output sample it needs to be moved back to the start. - mal_uint32 availableOutputFrames = (mal_uint32)((timeInEnd - pSRC->sinc.timeIn) * inverseFactor); + ma_uint32 availableOutputFrames = (ma_uint32)((timeInEnd - pSRC->sinc.timeIn) * inverseFactor); if (availableOutputFrames == 0) { - size_t samplesToMove = mal_countof(pSRC->sinc.input[0]) - pSRC->sinc.windowPosInSamples; + size_t samplesToMove = ma_countof(pSRC->sinc.input[0]) - pSRC->sinc.windowPosInSamples; - pSRC->sinc.timeIn -= mal_floorf(pSRC->sinc.timeIn); + pSRC->sinc.timeIn -= ma_floorf(pSRC->sinc.timeIn); pSRC->sinc.windowPosInSamples = 0; // Move everything from the end of the cache up to the front. - for (mal_uint32 iChannel = 0; iChannel < pSRC->config.channels; iChannel += 1) { - memmove(pSRC->sinc.input[iChannel], pSRC->sinc.input[iChannel] + mal_countof(pSRC->sinc.input[iChannel]) - samplesToMove, samplesToMove * sizeof(*pSRC->sinc.input[iChannel])); + for (ma_uint32 iChannel = 0; iChannel < pSRC->config.channels; iChannel += 1) { + memmove(pSRC->sinc.input[iChannel], pSRC->sinc.input[iChannel] + ma_countof(pSRC->sinc.input[iChannel]) - samplesToMove, samplesToMove * sizeof(*pSRC->sinc.input[iChannel])); } } @@ -28359,18 +28359,18 @@ mal_uint64 mal_src_read_deinterleaved__sinc(mal_src* pSRC, mal_uint64 frameCount // Everything beyond this point is reloading. If we're at the end of the input data we do _not_ want to try reading any more in this function call. If the // caller wants to keep trying, they can reload their internal data sources and call this function again. We should never be - mal_assert(pSRC->isEndOfInputLoaded == MA_FALSE); + ma_assert(pSRC->isEndOfInputLoaded == MA_FALSE); if (pSRC->sinc.inputFrameCount <= pSRC->config.sinc.windowWidth || availableOutputFrames == 0) { float* ppInputDst[MA_MAX_CHANNELS] = {0}; - for (mal_uint32 iChannel = 0; iChannel < pSRC->config.channels; iChannel += 1) { + for (ma_uint32 iChannel = 0; iChannel < pSRC->config.channels; iChannel += 1) { ppInputDst[iChannel] = pSRC->sinc.input[iChannel] + pSRC->config.sinc.windowWidth + pSRC->sinc.inputFrameCount; } // Now read data from the client. - mal_uint32 framesToReadFromClient = mal_countof(pSRC->sinc.input[0]) - (pSRC->config.sinc.windowWidth + pSRC->sinc.inputFrameCount); + ma_uint32 framesToReadFromClient = ma_countof(pSRC->sinc.input[0]) - (pSRC->config.sinc.windowWidth + pSRC->sinc.inputFrameCount); - mal_uint32 framesReadFromClient = 0; + ma_uint32 framesReadFromClient = 0; if (framesToReadFromClient > 0) { framesReadFromClient = pSRC->config.onReadDeinterleaved(pSRC, framesToReadFromClient, (void**)ppInputDst, pUserData); } @@ -28398,10 +28398,10 @@ mal_uint64 mal_src_read_deinterleaved__sinc(mal_src* pSRC, mal_uint64 frameCount } // Anything left over in the cache must be set to zero. - mal_uint32 leftoverFrames = mal_countof(pSRC->sinc.input[0]) - (pSRC->config.sinc.windowWidth + pSRC->sinc.inputFrameCount); + ma_uint32 leftoverFrames = ma_countof(pSRC->sinc.input[0]) - (pSRC->config.sinc.windowWidth + pSRC->sinc.inputFrameCount); if (leftoverFrames > 0) { - for (mal_uint32 iChannel = 0; iChannel < pSRC->config.channels; iChannel += 1) { - mal_zero_memory(pSRC->sinc.input[iChannel] + pSRC->config.sinc.windowWidth + pSRC->sinc.inputFrameCount, leftoverFrames * sizeof(float)); + for (ma_uint32 iChannel = 0; iChannel < pSRC->config.channels; iChannel += 1) { + ma_zero_memory(pSRC->sinc.input[iChannel] + pSRC->config.sinc.windowWidth + pSRC->sinc.inputFrameCount, leftoverFrames * sizeof(float)); } } } @@ -28419,71 +28419,71 @@ mal_uint64 mal_src_read_deinterleaved__sinc(mal_src* pSRC, mal_uint64 frameCount // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -void mal_pcm_convert(void* pOut, mal_format formatOut, const void* pIn, mal_format formatIn, mal_uint64 sampleCount, mal_dither_mode ditherMode) +void ma_pcm_convert(void* pOut, ma_format formatOut, const void* pIn, ma_format formatIn, ma_uint64 sampleCount, ma_dither_mode ditherMode) { if (formatOut == formatIn) { - mal_copy_memory_64(pOut, pIn, sampleCount * mal_get_bytes_per_sample(formatOut)); + ma_copy_memory_64(pOut, pIn, sampleCount * ma_get_bytes_per_sample(formatOut)); return; } switch (formatIn) { - case mal_format_u8: + case ma_format_u8: { switch (formatOut) { - case mal_format_s16: mal_pcm_u8_to_s16(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s24: mal_pcm_u8_to_s24(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s32: mal_pcm_u8_to_s32(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_f32: mal_pcm_u8_to_f32(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s16: ma_pcm_u8_to_s16(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s24: ma_pcm_u8_to_s24(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s32: ma_pcm_u8_to_s32(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_f32: ma_pcm_u8_to_f32(pOut, pIn, sampleCount, ditherMode); return; default: break; } } break; - case mal_format_s16: + case ma_format_s16: { switch (formatOut) { - case mal_format_u8: mal_pcm_s16_to_u8( pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s24: mal_pcm_s16_to_s24(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s32: mal_pcm_s16_to_s32(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_f32: mal_pcm_s16_to_f32(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_u8: ma_pcm_s16_to_u8( pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s24: ma_pcm_s16_to_s24(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s32: ma_pcm_s16_to_s32(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_f32: ma_pcm_s16_to_f32(pOut, pIn, sampleCount, ditherMode); return; default: break; } } break; - case mal_format_s24: + case ma_format_s24: { switch (formatOut) { - case mal_format_u8: mal_pcm_s24_to_u8( pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s16: mal_pcm_s24_to_s16(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s32: mal_pcm_s24_to_s32(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_f32: mal_pcm_s24_to_f32(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_u8: ma_pcm_s24_to_u8( pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s16: ma_pcm_s24_to_s16(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s32: ma_pcm_s24_to_s32(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_f32: ma_pcm_s24_to_f32(pOut, pIn, sampleCount, ditherMode); return; default: break; } } break; - case mal_format_s32: + case ma_format_s32: { switch (formatOut) { - case mal_format_u8: mal_pcm_s32_to_u8( pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s16: mal_pcm_s32_to_s16(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s24: mal_pcm_s32_to_s24(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_f32: mal_pcm_s32_to_f32(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_u8: ma_pcm_s32_to_u8( pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s16: ma_pcm_s32_to_s16(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s24: ma_pcm_s32_to_s24(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_f32: ma_pcm_s32_to_f32(pOut, pIn, sampleCount, ditherMode); return; default: break; } } break; - case mal_format_f32: + case ma_format_f32: { switch (formatOut) { - case mal_format_u8: mal_pcm_f32_to_u8( pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s16: mal_pcm_f32_to_s16(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s24: mal_pcm_f32_to_s24(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s32: mal_pcm_f32_to_s32(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_u8: ma_pcm_f32_to_u8( pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s16: ma_pcm_f32_to_s16(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s24: ma_pcm_f32_to_s24(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s32: ma_pcm_f32_to_s32(pOut, pIn, sampleCount, ditherMode); return; default: break; } } break; @@ -28492,7 +28492,7 @@ void mal_pcm_convert(void* pOut, mal_format formatOut, const void* pIn, mal_form } } -void mal_deinterleave_pcm_frames(mal_format format, mal_uint32 channels, mal_uint64 frameCount, const void* pInterleavedPCMFrames, void** ppDeinterleavedPCMFrames) +void ma_deinterleave_pcm_frames(ma_format format, ma_uint32 channels, ma_uint64 frameCount, const void* pInterleavedPCMFrames, void** ppDeinterleavedPCMFrames) { if (pInterleavedPCMFrames == NULL || ppDeinterleavedPCMFrames == NULL) { return; // Invalid args. @@ -28500,22 +28500,22 @@ void mal_deinterleave_pcm_frames(mal_format format, mal_uint32 channels, mal_uin // For efficiency we do this per format. switch (format) { - case mal_format_s16: + case ma_format_s16: { - const mal_int16* pSrcS16 = (const mal_int16*)pInterleavedPCMFrames; - for (mal_uint64 iPCMFrame = 0; iPCMFrame < frameCount; ++iPCMFrame) { - for (mal_uint32 iChannel = 0; iChannel < channels; ++iChannel) { - mal_int16* pDstS16 = (mal_int16*)ppDeinterleavedPCMFrames[iChannel]; + const ma_int16* pSrcS16 = (const ma_int16*)pInterleavedPCMFrames; + for (ma_uint64 iPCMFrame = 0; iPCMFrame < frameCount; ++iPCMFrame) { + for (ma_uint32 iChannel = 0; iChannel < channels; ++iChannel) { + ma_int16* pDstS16 = (ma_int16*)ppDeinterleavedPCMFrames[iChannel]; pDstS16[iPCMFrame] = pSrcS16[iPCMFrame*channels+iChannel]; } } } break; - case mal_format_f32: + case ma_format_f32: { const float* pSrcF32 = (const float*)pInterleavedPCMFrames; - for (mal_uint64 iPCMFrame = 0; iPCMFrame < frameCount; ++iPCMFrame) { - for (mal_uint32 iChannel = 0; iChannel < channels; ++iChannel) { + for (ma_uint64 iPCMFrame = 0; iPCMFrame < frameCount; ++iPCMFrame) { + for (ma_uint32 iChannel = 0; iChannel < channels; ++iChannel) { float* pDstF32 = (float*)ppDeinterleavedPCMFrames[iChannel]; pDstF32[iPCMFrame] = pSrcF32[iPCMFrame*channels+iChannel]; } @@ -28524,12 +28524,12 @@ void mal_deinterleave_pcm_frames(mal_format format, mal_uint32 channels, mal_uin default: { - mal_uint32 sampleSizeInBytes = mal_get_bytes_per_sample(format); + ma_uint32 sampleSizeInBytes = ma_get_bytes_per_sample(format); - for (mal_uint64 iPCMFrame = 0; iPCMFrame < frameCount; ++iPCMFrame) { - for (mal_uint32 iChannel = 0; iChannel < channels; ++iChannel) { - void* pDst = mal_offset_ptr(ppDeinterleavedPCMFrames[iChannel], iPCMFrame*sampleSizeInBytes); - const void* pSrc = mal_offset_ptr(pInterleavedPCMFrames, (iPCMFrame*channels+iChannel)*sampleSizeInBytes); + for (ma_uint64 iPCMFrame = 0; iPCMFrame < frameCount; ++iPCMFrame) { + for (ma_uint32 iChannel = 0; iChannel < channels; ++iChannel) { + void* pDst = ma_offset_ptr(ppDeinterleavedPCMFrames[iChannel], iPCMFrame*sampleSizeInBytes); + const void* pSrc = ma_offset_ptr(pInterleavedPCMFrames, (iPCMFrame*channels+iChannel)*sampleSizeInBytes); memcpy(pDst, pSrc, sampleSizeInBytes); } } @@ -28537,26 +28537,26 @@ void mal_deinterleave_pcm_frames(mal_format format, mal_uint32 channels, mal_uin } } -void mal_interleave_pcm_frames(mal_format format, mal_uint32 channels, mal_uint64 frameCount, const void** ppDeinterleavedPCMFrames, void* pInterleavedPCMFrames) +void ma_interleave_pcm_frames(ma_format format, ma_uint32 channels, ma_uint64 frameCount, const void** ppDeinterleavedPCMFrames, void* pInterleavedPCMFrames) { switch (format) { - case mal_format_s16: + case ma_format_s16: { - mal_int16* pDstS16 = (mal_int16*)pInterleavedPCMFrames; - for (mal_uint64 iPCMFrame = 0; iPCMFrame < frameCount; ++iPCMFrame) { - for (mal_uint32 iChannel = 0; iChannel < channels; ++iChannel) { - const mal_int16* pSrcS16 = (const mal_int16*)ppDeinterleavedPCMFrames[iChannel]; + ma_int16* pDstS16 = (ma_int16*)pInterleavedPCMFrames; + for (ma_uint64 iPCMFrame = 0; iPCMFrame < frameCount; ++iPCMFrame) { + for (ma_uint32 iChannel = 0; iChannel < channels; ++iChannel) { + const ma_int16* pSrcS16 = (const ma_int16*)ppDeinterleavedPCMFrames[iChannel]; pDstS16[iPCMFrame*channels+iChannel] = pSrcS16[iPCMFrame]; } } } break; - case mal_format_f32: + case ma_format_f32: { float* pDstF32 = (float*)pInterleavedPCMFrames; - for (mal_uint64 iPCMFrame = 0; iPCMFrame < frameCount; ++iPCMFrame) { - for (mal_uint32 iChannel = 0; iChannel < channels; ++iChannel) { + for (ma_uint64 iPCMFrame = 0; iPCMFrame < frameCount; ++iPCMFrame) { + for (ma_uint32 iChannel = 0; iChannel < channels; ++iChannel) { const float* pSrcF32 = (const float*)ppDeinterleavedPCMFrames[iChannel]; pDstF32[iPCMFrame*channels+iChannel] = pSrcF32[iPCMFrame]; } @@ -28565,12 +28565,12 @@ void mal_interleave_pcm_frames(mal_format format, mal_uint32 channels, mal_uint6 default: { - mal_uint32 sampleSizeInBytes = mal_get_bytes_per_sample(format); + ma_uint32 sampleSizeInBytes = ma_get_bytes_per_sample(format); - for (mal_uint64 iPCMFrame = 0; iPCMFrame < frameCount; ++iPCMFrame) { - for (mal_uint32 iChannel = 0; iChannel < channels; ++iChannel) { - void* pDst = mal_offset_ptr(pInterleavedPCMFrames, (iPCMFrame*channels+iChannel)*sampleSizeInBytes); - const void* pSrc = mal_offset_ptr(ppDeinterleavedPCMFrames[iChannel], iPCMFrame*sampleSizeInBytes); + for (ma_uint64 iPCMFrame = 0; iPCMFrame < frameCount; ++iPCMFrame) { + for (ma_uint32 iChannel = 0; iChannel < channels; ++iChannel) { + void* pDst = ma_offset_ptr(pInterleavedPCMFrames, (iPCMFrame*channels+iChannel)*sampleSizeInBytes); + const void* pSrc = ma_offset_ptr(ppDeinterleavedPCMFrames[iChannel], iPCMFrame*sampleSizeInBytes); memcpy(pDst, pSrc, sampleSizeInBytes); } } @@ -28582,109 +28582,109 @@ void mal_interleave_pcm_frames(mal_format format, mal_uint32 channels, mal_uint6 typedef struct { - mal_pcm_converter* pDSP; + ma_pcm_converter* pDSP; void* pUserDataForClient; -} mal_pcm_converter_callback_data; +} ma_pcm_converter_callback_data; -mal_uint32 mal_pcm_converter__pre_format_converter_on_read(mal_format_converter* pConverter, mal_uint32 frameCount, void* pFramesOut, void* pUserData) +ma_uint32 ma_pcm_converter__pre_format_converter_on_read(ma_format_converter* pConverter, ma_uint32 frameCount, void* pFramesOut, void* pUserData) { (void)pConverter; - mal_pcm_converter_callback_data* pData = (mal_pcm_converter_callback_data*)pUserData; - mal_assert(pData != NULL); + ma_pcm_converter_callback_data* pData = (ma_pcm_converter_callback_data*)pUserData; + ma_assert(pData != NULL); - mal_pcm_converter* pDSP = pData->pDSP; - mal_assert(pDSP != NULL); + ma_pcm_converter* pDSP = pData->pDSP; + ma_assert(pDSP != NULL); return pDSP->onRead(pDSP, pFramesOut, frameCount, pData->pUserDataForClient); } -mal_uint32 mal_pcm_converter__post_format_converter_on_read(mal_format_converter* pConverter, mal_uint32 frameCount, void* pFramesOut, void* pUserData) +ma_uint32 ma_pcm_converter__post_format_converter_on_read(ma_format_converter* pConverter, ma_uint32 frameCount, void* pFramesOut, void* pUserData) { (void)pConverter; - mal_pcm_converter_callback_data* pData = (mal_pcm_converter_callback_data*)pUserData; - mal_assert(pData != NULL); + ma_pcm_converter_callback_data* pData = (ma_pcm_converter_callback_data*)pUserData; + ma_assert(pData != NULL); - mal_pcm_converter* pDSP = pData->pDSP; - mal_assert(pDSP != NULL); + ma_pcm_converter* pDSP = pData->pDSP; + ma_assert(pDSP != NULL); // When this version of this callback is used it means we're reading directly from the client. - mal_assert(pDSP->isPreFormatConversionRequired == MA_FALSE); - mal_assert(pDSP->isChannelRoutingRequired == MA_FALSE); - mal_assert(pDSP->isSRCRequired == MA_FALSE); + ma_assert(pDSP->isPreFormatConversionRequired == MA_FALSE); + ma_assert(pDSP->isChannelRoutingRequired == MA_FALSE); + ma_assert(pDSP->isSRCRequired == MA_FALSE); return pDSP->onRead(pDSP, pFramesOut, frameCount, pData->pUserDataForClient); } -mal_uint32 mal_pcm_converter__post_format_converter_on_read_deinterleaved(mal_format_converter* pConverter, mal_uint32 frameCount, void** ppSamplesOut, void* pUserData) +ma_uint32 ma_pcm_converter__post_format_converter_on_read_deinterleaved(ma_format_converter* pConverter, ma_uint32 frameCount, void** ppSamplesOut, void* pUserData) { (void)pConverter; - mal_pcm_converter_callback_data* pData = (mal_pcm_converter_callback_data*)pUserData; - mal_assert(pData != NULL); + ma_pcm_converter_callback_data* pData = (ma_pcm_converter_callback_data*)pUserData; + ma_assert(pData != NULL); - mal_pcm_converter* pDSP = pData->pDSP; - mal_assert(pDSP != NULL); + ma_pcm_converter* pDSP = pData->pDSP; + ma_assert(pDSP != NULL); if (!pDSP->isChannelRoutingAtStart) { - return (mal_uint32)mal_channel_router_read_deinterleaved(&pDSP->channelRouter, frameCount, ppSamplesOut, pUserData); + return (ma_uint32)ma_channel_router_read_deinterleaved(&pDSP->channelRouter, frameCount, ppSamplesOut, pUserData); } else { if (pDSP->isSRCRequired) { - return (mal_uint32)mal_src_read_deinterleaved(&pDSP->src, frameCount, ppSamplesOut, pUserData); + return (ma_uint32)ma_src_read_deinterleaved(&pDSP->src, frameCount, ppSamplesOut, pUserData); } else { - return (mal_uint32)mal_channel_router_read_deinterleaved(&pDSP->channelRouter, frameCount, ppSamplesOut, pUserData); + return (ma_uint32)ma_channel_router_read_deinterleaved(&pDSP->channelRouter, frameCount, ppSamplesOut, pUserData); } } } -mal_uint32 mal_pcm_converter__src_on_read_deinterleaved(mal_src* pSRC, mal_uint32 frameCount, void** ppSamplesOut, void* pUserData) +ma_uint32 ma_pcm_converter__src_on_read_deinterleaved(ma_src* pSRC, ma_uint32 frameCount, void** ppSamplesOut, void* pUserData) { (void)pSRC; - mal_pcm_converter_callback_data* pData = (mal_pcm_converter_callback_data*)pUserData; - mal_assert(pData != NULL); + ma_pcm_converter_callback_data* pData = (ma_pcm_converter_callback_data*)pUserData; + ma_assert(pData != NULL); - mal_pcm_converter* pDSP = pData->pDSP; - mal_assert(pDSP != NULL); + ma_pcm_converter* pDSP = pData->pDSP; + ma_assert(pDSP != NULL); // If the channel routing stage is at the front we need to read from that. Otherwise we read from the pre format converter. if (pDSP->isChannelRoutingAtStart) { - return (mal_uint32)mal_channel_router_read_deinterleaved(&pDSP->channelRouter, frameCount, ppSamplesOut, pUserData); + return (ma_uint32)ma_channel_router_read_deinterleaved(&pDSP->channelRouter, frameCount, ppSamplesOut, pUserData); } else { - return (mal_uint32)mal_format_converter_read_deinterleaved(&pDSP->formatConverterIn, frameCount, ppSamplesOut, pUserData); + return (ma_uint32)ma_format_converter_read_deinterleaved(&pDSP->formatConverterIn, frameCount, ppSamplesOut, pUserData); } } -mal_uint32 mal_pcm_converter__channel_router_on_read_deinterleaved(mal_channel_router* pRouter, mal_uint32 frameCount, void** ppSamplesOut, void* pUserData) +ma_uint32 ma_pcm_converter__channel_router_on_read_deinterleaved(ma_channel_router* pRouter, ma_uint32 frameCount, void** ppSamplesOut, void* pUserData) { (void)pRouter; - mal_pcm_converter_callback_data* pData = (mal_pcm_converter_callback_data*)pUserData; - mal_assert(pData != NULL); + ma_pcm_converter_callback_data* pData = (ma_pcm_converter_callback_data*)pUserData; + ma_assert(pData != NULL); - mal_pcm_converter* pDSP = pData->pDSP; - mal_assert(pDSP != NULL); + ma_pcm_converter* pDSP = pData->pDSP; + ma_assert(pDSP != NULL); // If the channel routing stage is at the front of the pipeline we read from the pre format converter. Otherwise we read from the sample rate converter. if (pDSP->isChannelRoutingAtStart) { - return (mal_uint32)mal_format_converter_read_deinterleaved(&pDSP->formatConverterIn, frameCount, ppSamplesOut, pUserData); + return (ma_uint32)ma_format_converter_read_deinterleaved(&pDSP->formatConverterIn, frameCount, ppSamplesOut, pUserData); } else { if (pDSP->isSRCRequired) { - return (mal_uint32)mal_src_read_deinterleaved(&pDSP->src, frameCount, ppSamplesOut, pUserData); + return (ma_uint32)ma_src_read_deinterleaved(&pDSP->src, frameCount, ppSamplesOut, pUserData); } else { - return (mal_uint32)mal_format_converter_read_deinterleaved(&pDSP->formatConverterIn, frameCount, ppSamplesOut, pUserData); + return (ma_uint32)ma_format_converter_read_deinterleaved(&pDSP->formatConverterIn, frameCount, ppSamplesOut, pUserData); } } } -mal_result mal_pcm_converter_init(const mal_pcm_converter_config* pConfig, mal_pcm_converter* pDSP) +ma_result ma_pcm_converter_init(const ma_pcm_converter_config* pConfig, ma_pcm_converter* pDSP) { if (pDSP == NULL) { return MA_INVALID_ARGS; } - mal_zero_object(pDSP); + ma_zero_object(pDSP); pDSP->onRead = pConfig->onRead; pDSP->pUserData = pConfig->pUserData; pDSP->isDynamicSampleRateAllowed = pConfig->allowDynamicSampleRate; @@ -28746,7 +28746,7 @@ mal_result mal_pcm_converter_init(const mal_pcm_converter_config* pConfig, mal_p if (pConfig->sampleRateIn != pConfig->sampleRateOut || pConfig->allowDynamicSampleRate) { pDSP->isSRCRequired = MA_TRUE; } - if (pConfig->channelsIn != pConfig->channelsOut || !mal_channel_map_equal(pConfig->channelsIn, pConfig->channelMapIn, pConfig->channelMapOut)) { + if (pConfig->channelsIn != pConfig->channelsOut || !ma_channel_map_equal(pConfig->channelsIn, pConfig->channelMapIn, pConfig->channelMapOut)) { pDSP->isChannelRoutingRequired = MA_TRUE; } @@ -28774,15 +28774,15 @@ mal_result mal_pcm_converter_init(const mal_pcm_converter_config* pConfig, mal_p // We always initialize every stage of the pipeline regardless of whether or not the stage is used because it simplifies // a few things when it comes to dynamically changing properties post-initialization. - mal_result result = MA_SUCCESS; + ma_result result = MA_SUCCESS; // Pre format conversion. { - mal_format_converter_config preFormatConverterConfig = mal_format_converter_config_init( + ma_format_converter_config preFormatConverterConfig = ma_format_converter_config_init( pConfig->formatIn, - mal_format_f32, + ma_format_f32, pConfig->channelsIn, - mal_pcm_converter__pre_format_converter_on_read, + ma_pcm_converter__pre_format_converter_on_read, pDSP ); preFormatConverterConfig.ditherMode = pConfig->ditherMode; @@ -28791,7 +28791,7 @@ mal_result mal_pcm_converter_init(const mal_pcm_converter_config* pConfig, mal_p preFormatConverterConfig.noAVX512 = pConfig->noAVX512; preFormatConverterConfig.noNEON = pConfig->noNEON; - result = mal_format_converter_init(&preFormatConverterConfig, &pDSP->formatConverterIn); + result = ma_format_converter_init(&preFormatConverterConfig, &pDSP->formatConverterIn); if (result != MA_SUCCESS) { return result; } @@ -28800,7 +28800,7 @@ mal_result mal_pcm_converter_init(const mal_pcm_converter_config* pConfig, mal_p // Post format conversion. The exact configuration for this depends on whether or not we are reading data directly from the client // or from an earlier stage in the pipeline. { - mal_format_converter_config postFormatConverterConfig = mal_format_converter_config_init_new(); + ma_format_converter_config postFormatConverterConfig = ma_format_converter_config_init_new(); postFormatConverterConfig.formatIn = pConfig->formatIn; postFormatConverterConfig.formatOut = pConfig->formatOut; postFormatConverterConfig.channels = pConfig->channelsOut; @@ -28810,13 +28810,13 @@ mal_result mal_pcm_converter_init(const mal_pcm_converter_config* pConfig, mal_p postFormatConverterConfig.noAVX512 = pConfig->noAVX512; postFormatConverterConfig.noNEON = pConfig->noNEON; if (pDSP->isPreFormatConversionRequired) { - postFormatConverterConfig.onReadDeinterleaved = mal_pcm_converter__post_format_converter_on_read_deinterleaved; - postFormatConverterConfig.formatIn = mal_format_f32; + postFormatConverterConfig.onReadDeinterleaved = ma_pcm_converter__post_format_converter_on_read_deinterleaved; + postFormatConverterConfig.formatIn = ma_format_f32; } else { - postFormatConverterConfig.onRead = mal_pcm_converter__post_format_converter_on_read; + postFormatConverterConfig.onRead = ma_pcm_converter__post_format_converter_on_read; } - result = mal_format_converter_init(&postFormatConverterConfig, &pDSP->formatConverterOut); + result = ma_format_converter_init(&postFormatConverterConfig, &pDSP->formatConverterOut); if (result != MA_SUCCESS) { return result; } @@ -28824,11 +28824,11 @@ mal_result mal_pcm_converter_init(const mal_pcm_converter_config* pConfig, mal_p // SRC { - mal_src_config srcConfig = mal_src_config_init( + ma_src_config srcConfig = ma_src_config_init( pConfig->sampleRateIn, pConfig->sampleRateOut, ((pConfig->channelsIn < pConfig->channelsOut) ? pConfig->channelsIn : pConfig->channelsOut), - mal_pcm_converter__src_on_read_deinterleaved, + ma_pcm_converter__src_on_read_deinterleaved, pDSP ); srcConfig.algorithm = pConfig->srcAlgorithm; @@ -28837,9 +28837,9 @@ mal_result mal_pcm_converter_init(const mal_pcm_converter_config* pConfig, mal_p srcConfig.noAVX2 = pConfig->noAVX2; srcConfig.noAVX512 = pConfig->noAVX512; srcConfig.noNEON = pConfig->noNEON; - mal_copy_memory(&srcConfig.sinc, &pConfig->sinc, sizeof(pConfig->sinc)); + ma_copy_memory(&srcConfig.sinc, &pConfig->sinc, sizeof(pConfig->sinc)); - result = mal_src_init(&srcConfig, &pDSP->src); + result = ma_src_init(&srcConfig, &pDSP->src); if (result != MA_SUCCESS) { return result; } @@ -28847,20 +28847,20 @@ mal_result mal_pcm_converter_init(const mal_pcm_converter_config* pConfig, mal_p // Channel conversion { - mal_channel_router_config routerConfig = mal_channel_router_config_init( + ma_channel_router_config routerConfig = ma_channel_router_config_init( pConfig->channelsIn, pConfig->channelMapIn, pConfig->channelsOut, pConfig->channelMapOut, pConfig->channelMixMode, - mal_pcm_converter__channel_router_on_read_deinterleaved, + ma_pcm_converter__channel_router_on_read_deinterleaved, pDSP); routerConfig.noSSE2 = pConfig->noSSE2; routerConfig.noAVX2 = pConfig->noAVX2; routerConfig.noAVX512 = pConfig->noAVX512; routerConfig.noNEON = pConfig->noNEON; - result = mal_channel_router_init(&routerConfig, &pDSP->channelRouter); + result = ma_channel_router_init(&routerConfig, &pDSP->channelRouter); if (result != MA_SUCCESS) { return result; } @@ -28870,14 +28870,14 @@ mal_result mal_pcm_converter_init(const mal_pcm_converter_config* pConfig, mal_p } -mal_result mal_pcm_converter_refresh_sample_rate(mal_pcm_converter* pDSP) +ma_result ma_pcm_converter_refresh_sample_rate(ma_pcm_converter* pDSP) { // The SRC stage will already have been initialized so we can just set it there. - mal_src_set_sample_rate(&pDSP->src, pDSP->src.config.sampleRateIn, pDSP->src.config.sampleRateOut); + ma_src_set_sample_rate(&pDSP->src, pDSP->src.config.sampleRateIn, pDSP->src.config.sampleRateOut); return MA_SUCCESS; } -mal_result mal_pcm_converter_set_input_sample_rate(mal_pcm_converter* pDSP, mal_uint32 sampleRateIn) +ma_result ma_pcm_converter_set_input_sample_rate(ma_pcm_converter* pDSP, ma_uint32 sampleRateIn) { if (pDSP == NULL) { return MA_INVALID_ARGS; @@ -28893,11 +28893,11 @@ mal_result mal_pcm_converter_set_input_sample_rate(mal_pcm_converter* pDSP, mal_ return MA_INVALID_OPERATION; } - mal_atomic_exchange_32(&pDSP->src.config.sampleRateIn, sampleRateIn); - return mal_pcm_converter_refresh_sample_rate(pDSP); + ma_atomic_exchange_32(&pDSP->src.config.sampleRateIn, sampleRateIn); + return ma_pcm_converter_refresh_sample_rate(pDSP); } -mal_result mal_pcm_converter_set_output_sample_rate(mal_pcm_converter* pDSP, mal_uint32 sampleRateOut) +ma_result ma_pcm_converter_set_output_sample_rate(ma_pcm_converter* pDSP, ma_uint32 sampleRateOut) { if (pDSP == NULL) { return MA_INVALID_ARGS; @@ -28913,11 +28913,11 @@ mal_result mal_pcm_converter_set_output_sample_rate(mal_pcm_converter* pDSP, mal return MA_INVALID_OPERATION; } - mal_atomic_exchange_32(&pDSP->src.config.sampleRateOut, sampleRateOut); - return mal_pcm_converter_refresh_sample_rate(pDSP); + ma_atomic_exchange_32(&pDSP->src.config.sampleRateOut, sampleRateOut); + return ma_pcm_converter_refresh_sample_rate(pDSP); } -mal_result mal_pcm_converter_set_sample_rate(mal_pcm_converter* pDSP, mal_uint32 sampleRateIn, mal_uint32 sampleRateOut) +ma_result ma_pcm_converter_set_sample_rate(ma_pcm_converter* pDSP, ma_uint32 sampleRateIn, ma_uint32 sampleRateOut) { if (pDSP == NULL) { return MA_INVALID_ARGS; @@ -28933,13 +28933,13 @@ mal_result mal_pcm_converter_set_sample_rate(mal_pcm_converter* pDSP, mal_uint32 return MA_INVALID_OPERATION; } - mal_atomic_exchange_32(&pDSP->src.config.sampleRateIn, sampleRateIn); - mal_atomic_exchange_32(&pDSP->src.config.sampleRateOut, sampleRateOut); + ma_atomic_exchange_32(&pDSP->src.config.sampleRateIn, sampleRateIn); + ma_atomic_exchange_32(&pDSP->src.config.sampleRateOut, sampleRateOut); - return mal_pcm_converter_refresh_sample_rate(pDSP); + return ma_pcm_converter_refresh_sample_rate(pDSP); } -mal_uint64 mal_pcm_converter_read(mal_pcm_converter* pDSP, void* pFramesOut, mal_uint64 frameCount) +ma_uint64 ma_pcm_converter_read(ma_pcm_converter* pDSP, void* pFramesOut, ma_uint64 frameCount) { if (pDSP == NULL || pFramesOut == NULL) { return 0; @@ -28948,24 +28948,24 @@ mal_uint64 mal_pcm_converter_read(mal_pcm_converter* pDSP, void* pFramesOut, mal // Fast path. if (pDSP->isPassthrough) { if (frameCount <= 0xFFFFFFFF) { - return (mal_uint32)pDSP->onRead(pDSP, pFramesOut, (mal_uint32)frameCount, pDSP->pUserData); + return (ma_uint32)pDSP->onRead(pDSP, pFramesOut, (ma_uint32)frameCount, pDSP->pUserData); } else { - mal_uint8* pNextFramesOut = (mal_uint8*)pFramesOut; + ma_uint8* pNextFramesOut = (ma_uint8*)pFramesOut; - mal_uint64 totalFramesRead = 0; + ma_uint64 totalFramesRead = 0; while (totalFramesRead < frameCount) { - mal_uint64 framesRemaining = (frameCount - totalFramesRead); - mal_uint64 framesToReadRightNow = framesRemaining; + ma_uint64 framesRemaining = (frameCount - totalFramesRead); + ma_uint64 framesToReadRightNow = framesRemaining; if (framesToReadRightNow > 0xFFFFFFFF) { framesToReadRightNow = 0xFFFFFFFF; } - mal_uint32 framesRead = pDSP->onRead(pDSP, pNextFramesOut, (mal_uint32)framesToReadRightNow, pDSP->pUserData); + ma_uint32 framesRead = pDSP->onRead(pDSP, pNextFramesOut, (ma_uint32)framesToReadRightNow, pDSP->pUserData); if (framesRead == 0) { break; } - pNextFramesOut += framesRead * pDSP->channelRouter.config.channelsOut * mal_get_bytes_per_sample(pDSP->formatConverterOut.config.formatOut); + pNextFramesOut += framesRead * pDSP->channelRouter.config.channelsOut * ma_get_bytes_per_sample(pDSP->formatConverterOut.config.formatOut); totalFramesRead += framesRead; } @@ -28974,68 +28974,68 @@ mal_uint64 mal_pcm_converter_read(mal_pcm_converter* pDSP, void* pFramesOut, mal } // Slower path. The real work is done here. To do this all we need to do is read from the last stage in the pipeline. - mal_assert(pDSP->isPostFormatConversionRequired == MA_TRUE); + ma_assert(pDSP->isPostFormatConversionRequired == MA_TRUE); - mal_pcm_converter_callback_data data; + ma_pcm_converter_callback_data data; data.pDSP = pDSP; data.pUserDataForClient = pDSP->pUserData; - return mal_format_converter_read(&pDSP->formatConverterOut, frameCount, pFramesOut, &data); + return ma_format_converter_read(&pDSP->formatConverterOut, frameCount, pFramesOut, &data); } typedef struct { const void* pDataIn; - mal_format formatIn; - mal_uint32 channelsIn; - mal_uint64 totalFrameCount; - mal_uint64 iNextFrame; - mal_bool32 isFeedingZeros; // When set to true, feeds the DSP zero samples. -} mal_convert_frames__data; + ma_format formatIn; + ma_uint32 channelsIn; + ma_uint64 totalFrameCount; + ma_uint64 iNextFrame; + ma_bool32 isFeedingZeros; // When set to true, feeds the DSP zero samples. +} ma_convert_frames__data; -mal_uint32 mal_convert_frames__on_read(mal_pcm_converter* pDSP, void* pFramesOut, mal_uint32 frameCount, void* pUserData) +ma_uint32 ma_convert_frames__on_read(ma_pcm_converter* pDSP, void* pFramesOut, ma_uint32 frameCount, void* pUserData) { (void)pDSP; - mal_convert_frames__data* pData = (mal_convert_frames__data*)pUserData; - mal_assert(pData != NULL); - mal_assert(pData->totalFrameCount >= pData->iNextFrame); + ma_convert_frames__data* pData = (ma_convert_frames__data*)pUserData; + ma_assert(pData != NULL); + ma_assert(pData->totalFrameCount >= pData->iNextFrame); - mal_uint32 framesToRead = frameCount; - mal_uint64 framesRemaining = (pData->totalFrameCount - pData->iNextFrame); + ma_uint32 framesToRead = frameCount; + ma_uint64 framesRemaining = (pData->totalFrameCount - pData->iNextFrame); if (framesToRead > framesRemaining) { - framesToRead = (mal_uint32)framesRemaining; + framesToRead = (ma_uint32)framesRemaining; } - mal_uint32 frameSizeInBytes = mal_get_bytes_per_frame(pData->formatIn, pData->channelsIn); + ma_uint32 frameSizeInBytes = ma_get_bytes_per_frame(pData->formatIn, pData->channelsIn); if (!pData->isFeedingZeros) { - mal_copy_memory(pFramesOut, (const mal_uint8*)pData->pDataIn + (frameSizeInBytes * pData->iNextFrame), frameSizeInBytes * framesToRead); + ma_copy_memory(pFramesOut, (const ma_uint8*)pData->pDataIn + (frameSizeInBytes * pData->iNextFrame), frameSizeInBytes * framesToRead); } else { - mal_zero_memory(pFramesOut, frameSizeInBytes * framesToRead); + ma_zero_memory(pFramesOut, frameSizeInBytes * framesToRead); } pData->iNextFrame += framesToRead; return framesToRead; } -mal_pcm_converter_config mal_pcm_converter_config_init_new() +ma_pcm_converter_config ma_pcm_converter_config_init_new() { - mal_pcm_converter_config config; - mal_zero_object(&config); + ma_pcm_converter_config config; + ma_zero_object(&config); return config; } -mal_pcm_converter_config mal_pcm_converter_config_init(mal_format formatIn, mal_uint32 channelsIn, mal_uint32 sampleRateIn, mal_format formatOut, mal_uint32 channelsOut, mal_uint32 sampleRateOut, mal_pcm_converter_read_proc onRead, void* pUserData) +ma_pcm_converter_config ma_pcm_converter_config_init(ma_format formatIn, ma_uint32 channelsIn, ma_uint32 sampleRateIn, ma_format formatOut, ma_uint32 channelsOut, ma_uint32 sampleRateOut, ma_pcm_converter_read_proc onRead, void* pUserData) { - return mal_pcm_converter_config_init_ex(formatIn, channelsIn, sampleRateIn, NULL, formatOut, channelsOut, sampleRateOut, NULL, onRead, pUserData); + return ma_pcm_converter_config_init_ex(formatIn, channelsIn, sampleRateIn, NULL, formatOut, channelsOut, sampleRateOut, NULL, onRead, pUserData); } -mal_pcm_converter_config mal_pcm_converter_config_init_ex(mal_format formatIn, mal_uint32 channelsIn, mal_uint32 sampleRateIn, mal_channel channelMapIn[MA_MAX_CHANNELS], mal_format formatOut, mal_uint32 channelsOut, mal_uint32 sampleRateOut, mal_channel channelMapOut[MA_MAX_CHANNELS], mal_pcm_converter_read_proc onRead, void* pUserData) +ma_pcm_converter_config ma_pcm_converter_config_init_ex(ma_format formatIn, ma_uint32 channelsIn, ma_uint32 sampleRateIn, ma_channel channelMapIn[MA_MAX_CHANNELS], ma_format formatOut, ma_uint32 channelsOut, ma_uint32 sampleRateOut, ma_channel channelMapOut[MA_MAX_CHANNELS], ma_pcm_converter_read_proc onRead, void* pUserData) { - mal_pcm_converter_config config; - mal_zero_object(&config); + ma_pcm_converter_config config; + ma_zero_object(&config); config.formatIn = formatIn; config.channelsIn = channelsIn; config.sampleRateIn = sampleRateIn; @@ -29043,10 +29043,10 @@ mal_pcm_converter_config mal_pcm_converter_config_init_ex(mal_format formatIn, m config.channelsOut = channelsOut; config.sampleRateOut = sampleRateOut; if (channelMapIn != NULL) { - mal_copy_memory(config.channelMapIn, channelMapIn, sizeof(config.channelMapIn)); + ma_copy_memory(config.channelMapIn, channelMapIn, sizeof(config.channelMapIn)); } if (channelMapOut != NULL) { - mal_copy_memory(config.channelMapOut, channelMapOut, sizeof(config.channelMapOut)); + ma_copy_memory(config.channelMapOut, channelMapOut, sizeof(config.channelMapOut)); } config.onRead = onRead; config.pUserData = pUserData; @@ -29056,29 +29056,29 @@ mal_pcm_converter_config mal_pcm_converter_config_init_ex(mal_format formatIn, m -mal_uint64 mal_convert_frames(void* pOut, mal_format formatOut, mal_uint32 channelsOut, mal_uint32 sampleRateOut, const void* pIn, mal_format formatIn, mal_uint32 channelsIn, mal_uint32 sampleRateIn, mal_uint64 frameCount) +ma_uint64 ma_convert_frames(void* pOut, ma_format formatOut, ma_uint32 channelsOut, ma_uint32 sampleRateOut, const void* pIn, ma_format formatIn, ma_uint32 channelsIn, ma_uint32 sampleRateIn, ma_uint64 frameCount) { - mal_channel channelMapOut[MA_MAX_CHANNELS]; - mal_get_standard_channel_map(mal_standard_channel_map_default, channelsOut, channelMapOut); + ma_channel channelMapOut[MA_MAX_CHANNELS]; + ma_get_standard_channel_map(ma_standard_channel_map_default, channelsOut, channelMapOut); - mal_channel channelMapIn[MA_MAX_CHANNELS]; - mal_get_standard_channel_map(mal_standard_channel_map_default, channelsIn, channelMapIn); + ma_channel channelMapIn[MA_MAX_CHANNELS]; + ma_get_standard_channel_map(ma_standard_channel_map_default, channelsIn, channelMapIn); - return mal_convert_frames_ex(pOut, formatOut, channelsOut, sampleRateOut, channelMapOut, pIn, formatIn, channelsIn, sampleRateIn, channelMapIn, frameCount); + return ma_convert_frames_ex(pOut, formatOut, channelsOut, sampleRateOut, channelMapOut, pIn, formatIn, channelsIn, sampleRateIn, channelMapIn, frameCount); } -mal_uint64 mal_convert_frames_ex(void* pOut, mal_format formatOut, mal_uint32 channelsOut, mal_uint32 sampleRateOut, mal_channel channelMapOut[MA_MAX_CHANNELS], const void* pIn, mal_format formatIn, mal_uint32 channelsIn, mal_uint32 sampleRateIn, mal_channel channelMapIn[MA_MAX_CHANNELS], mal_uint64 frameCount) +ma_uint64 ma_convert_frames_ex(void* pOut, ma_format formatOut, ma_uint32 channelsOut, ma_uint32 sampleRateOut, ma_channel channelMapOut[MA_MAX_CHANNELS], const void* pIn, ma_format formatIn, ma_uint32 channelsIn, ma_uint32 sampleRateIn, ma_channel channelMapIn[MA_MAX_CHANNELS], ma_uint64 frameCount) { if (frameCount == 0) { return 0; } - mal_uint64 frameCountOut = mal_calculate_frame_count_after_src(sampleRateOut, sampleRateIn, frameCount); + ma_uint64 frameCountOut = ma_calculate_frame_count_after_src(sampleRateOut, sampleRateIn, frameCount); if (pOut == NULL) { return frameCountOut; } - mal_convert_frames__data data; + ma_convert_frames__data data; data.pDataIn = pIn; data.formatIn = formatIn; data.channelsIn = channelsIn; @@ -29086,51 +29086,51 @@ mal_uint64 mal_convert_frames_ex(void* pOut, mal_format formatOut, mal_uint32 ch data.iNextFrame = 0; data.isFeedingZeros = MA_FALSE; - mal_pcm_converter_config config; - mal_zero_object(&config); + ma_pcm_converter_config config; + ma_zero_object(&config); config.formatIn = formatIn; config.channelsIn = channelsIn; config.sampleRateIn = sampleRateIn; if (channelMapIn != NULL) { - mal_channel_map_copy(config.channelMapIn, channelMapIn, channelsIn); + ma_channel_map_copy(config.channelMapIn, channelMapIn, channelsIn); } else { - mal_get_standard_channel_map(mal_standard_channel_map_default, config.channelsIn, config.channelMapIn); + ma_get_standard_channel_map(ma_standard_channel_map_default, config.channelsIn, config.channelMapIn); } config.formatOut = formatOut; config.channelsOut = channelsOut; config.sampleRateOut = sampleRateOut; if (channelMapOut != NULL) { - mal_channel_map_copy(config.channelMapOut, channelMapOut, channelsOut); + ma_channel_map_copy(config.channelMapOut, channelMapOut, channelsOut); } else { - mal_get_standard_channel_map(mal_standard_channel_map_default, config.channelsOut, config.channelMapOut); + ma_get_standard_channel_map(ma_standard_channel_map_default, config.channelsOut, config.channelMapOut); } - config.onRead = mal_convert_frames__on_read; + config.onRead = ma_convert_frames__on_read; config.pUserData = &data; - mal_pcm_converter dsp; - if (mal_pcm_converter_init(&config, &dsp) != MA_SUCCESS) { + ma_pcm_converter dsp; + if (ma_pcm_converter_init(&config, &dsp) != MA_SUCCESS) { return 0; } // Always output our computed frame count. There is a chance the sample rate conversion routine may not output the last sample // due to precision issues with 32-bit floats, in which case we should feed the DSP zero samples so it can generate that last // frame. - mal_uint64 totalFramesRead = mal_pcm_converter_read(&dsp, pOut, frameCountOut); + ma_uint64 totalFramesRead = ma_pcm_converter_read(&dsp, pOut, frameCountOut); if (totalFramesRead < frameCountOut) { - mal_uint32 bpf = mal_get_bytes_per_frame(formatIn, channelsIn); + ma_uint32 bpf = ma_get_bytes_per_frame(formatIn, channelsIn); data.isFeedingZeros = MA_TRUE; data.totalFrameCount = 0xFFFFFFFFFFFFFFFF; data.pDataIn = NULL; while (totalFramesRead < frameCountOut) { - mal_uint64 framesToRead = (frameCountOut - totalFramesRead); - mal_assert(framesToRead > 0); + ma_uint64 framesToRead = (frameCountOut - totalFramesRead); + ma_assert(framesToRead > 0); - mal_uint64 framesJustRead = mal_pcm_converter_read(&dsp, mal_offset_ptr(pOut, totalFramesRead * bpf), framesToRead); + ma_uint64 framesJustRead = ma_pcm_converter_read(&dsp, ma_offset_ptr(pOut, totalFramesRead * bpf), framesToRead); totalFramesRead += framesJustRead; if (framesJustRead < framesToRead) { @@ -29140,12 +29140,12 @@ mal_uint64 mal_convert_frames_ex(void* pOut, mal_format formatOut, mal_uint32 ch // At this point we should have output every sample, but just to be super duper sure, just fill the rest with zeros. if (totalFramesRead < frameCountOut) { - mal_zero_memory_64(mal_offset_ptr(pOut, totalFramesRead * bpf), ((frameCountOut - totalFramesRead) * bpf)); + ma_zero_memory_64(ma_offset_ptr(pOut, totalFramesRead * bpf), ((frameCountOut - totalFramesRead) * bpf)); totalFramesRead = frameCountOut; } } - mal_assert(totalFramesRead == frameCountOut); + ma_assert(totalFramesRead == frameCountOut); return totalFramesRead; } @@ -29157,44 +29157,44 @@ mal_uint64 mal_convert_frames_ex(void* pOut, mal_format formatOut, mal_uint32 ch // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -MA_INLINE mal_uint32 mal_rb__extract_offset_in_bytes(mal_uint32 encodedOffset) +MA_INLINE ma_uint32 ma_rb__extract_offset_in_bytes(ma_uint32 encodedOffset) { return encodedOffset & 0x7FFFFFFF; } -MA_INLINE mal_uint32 mal_rb__extract_offset_loop_flag(mal_uint32 encodedOffset) +MA_INLINE ma_uint32 ma_rb__extract_offset_loop_flag(ma_uint32 encodedOffset) { return encodedOffset & 0x80000000; } -MA_INLINE void* mal_rb__get_read_ptr(mal_rb* pRB) +MA_INLINE void* ma_rb__get_read_ptr(ma_rb* pRB) { - mal_assert(pRB != NULL); - return mal_offset_ptr(pRB->pBuffer, mal_rb__extract_offset_in_bytes(pRB->encodedReadOffset)); + ma_assert(pRB != NULL); + return ma_offset_ptr(pRB->pBuffer, ma_rb__extract_offset_in_bytes(pRB->encodedReadOffset)); } -MA_INLINE void* mal_rb__get_write_ptr(mal_rb* pRB) +MA_INLINE void* ma_rb__get_write_ptr(ma_rb* pRB) { - mal_assert(pRB != NULL); - return mal_offset_ptr(pRB->pBuffer, mal_rb__extract_offset_in_bytes(pRB->encodedWriteOffset)); + ma_assert(pRB != NULL); + return ma_offset_ptr(pRB->pBuffer, ma_rb__extract_offset_in_bytes(pRB->encodedWriteOffset)); } -MA_INLINE mal_uint32 mal_rb__construct_offset(mal_uint32 offsetInBytes, mal_uint32 offsetLoopFlag) +MA_INLINE ma_uint32 ma_rb__construct_offset(ma_uint32 offsetInBytes, ma_uint32 offsetLoopFlag) { return offsetLoopFlag | offsetInBytes; } -MA_INLINE void mal_rb__deconstruct_offset(mal_uint32 encodedOffset, mal_uint32* pOffsetInBytes, mal_uint32* pOffsetLoopFlag) +MA_INLINE void ma_rb__deconstruct_offset(ma_uint32 encodedOffset, ma_uint32* pOffsetInBytes, ma_uint32* pOffsetLoopFlag) { - mal_assert(pOffsetInBytes != NULL); - mal_assert(pOffsetLoopFlag != NULL); + ma_assert(pOffsetInBytes != NULL); + ma_assert(pOffsetLoopFlag != NULL); - *pOffsetInBytes = mal_rb__extract_offset_in_bytes(encodedOffset); - *pOffsetLoopFlag = mal_rb__extract_offset_loop_flag(encodedOffset); + *pOffsetInBytes = ma_rb__extract_offset_in_bytes(encodedOffset); + *pOffsetLoopFlag = ma_rb__extract_offset_loop_flag(encodedOffset); } -mal_result mal_rb_init_ex(size_t subbufferSizeInBytes, size_t subbufferCount, size_t subbufferStrideInBytes, void* pOptionalPreallocatedBuffer, mal_rb* pRB) +ma_result ma_rb_init_ex(size_t subbufferSizeInBytes, size_t subbufferCount, size_t subbufferStrideInBytes, void* pOptionalPreallocatedBuffer, ma_rb* pRB) { if (pRB == NULL) { return MA_INVALID_ARGS; @@ -29204,18 +29204,18 @@ mal_result mal_rb_init_ex(size_t subbufferSizeInBytes, size_t subbufferCount, si return MA_INVALID_ARGS; } - const mal_uint32 maxSubBufferSize = 0x7FFFFFFF - (MA_SIMD_ALIGNMENT-1); + const ma_uint32 maxSubBufferSize = 0x7FFFFFFF - (MA_SIMD_ALIGNMENT-1); if (subbufferSizeInBytes > maxSubBufferSize) { return MA_INVALID_ARGS; // Maximum buffer size is ~2GB. The most significant bit is a flag for use internally. } - mal_zero_object(pRB); - pRB->subbufferSizeInBytes = (mal_uint32)subbufferSizeInBytes; - pRB->subbufferCount = (mal_uint32)subbufferCount; + ma_zero_object(pRB); + pRB->subbufferSizeInBytes = (ma_uint32)subbufferSizeInBytes; + pRB->subbufferCount = (ma_uint32)subbufferCount; if (pOptionalPreallocatedBuffer != NULL) { - pRB->subbufferStrideInBytes = (mal_uint32)subbufferStrideInBytes; + pRB->subbufferStrideInBytes = (ma_uint32)subbufferStrideInBytes; pRB->pBuffer = pOptionalPreallocatedBuffer; } else { // Here is where we allocate our own buffer. We always want to align this to MA_SIMD_ALIGNMENT for future SIMD optimization opportunity. To do this @@ -29223,50 +29223,50 @@ mal_result mal_rb_init_ex(size_t subbufferSizeInBytes, size_t subbufferCount, si pRB->subbufferStrideInBytes = (pRB->subbufferSizeInBytes + (MA_SIMD_ALIGNMENT-1)) & ~MA_SIMD_ALIGNMENT; size_t bufferSizeInBytes = (size_t)pRB->subbufferCount*pRB->subbufferStrideInBytes; - pRB->pBuffer = mal_aligned_malloc(bufferSizeInBytes, MA_SIMD_ALIGNMENT); + pRB->pBuffer = ma_aligned_malloc(bufferSizeInBytes, MA_SIMD_ALIGNMENT); if (pRB->pBuffer == NULL) { return MA_OUT_OF_MEMORY; } - mal_zero_memory(pRB->pBuffer, bufferSizeInBytes); + ma_zero_memory(pRB->pBuffer, bufferSizeInBytes); pRB->ownsBuffer = MA_TRUE; } return MA_SUCCESS; } -mal_result mal_rb_init(size_t bufferSizeInBytes, void* pOptionalPreallocatedBuffer, mal_rb* pRB) +ma_result ma_rb_init(size_t bufferSizeInBytes, void* pOptionalPreallocatedBuffer, ma_rb* pRB) { - return mal_rb_init_ex(bufferSizeInBytes, 1, 0, pOptionalPreallocatedBuffer, pRB); + return ma_rb_init_ex(bufferSizeInBytes, 1, 0, pOptionalPreallocatedBuffer, pRB); } -void mal_rb_uninit(mal_rb* pRB) +void ma_rb_uninit(ma_rb* pRB) { if (pRB == NULL) { return; } if (pRB->ownsBuffer) { - mal_aligned_free(pRB->pBuffer); + ma_aligned_free(pRB->pBuffer); } } -mal_result mal_rb_acquire_read(mal_rb* pRB, size_t* pSizeInBytes, void** ppBufferOut) +ma_result ma_rb_acquire_read(ma_rb* pRB, size_t* pSizeInBytes, void** ppBufferOut) { if (pRB == NULL || pSizeInBytes == NULL || ppBufferOut == NULL) { return MA_INVALID_ARGS; } // The returned buffer should never move ahead of the write pointer. - mal_uint32 writeOffset = pRB->encodedWriteOffset; - mal_uint32 writeOffsetInBytes; - mal_uint32 writeOffsetLoopFlag; - mal_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag); + ma_uint32 writeOffset = pRB->encodedWriteOffset; + ma_uint32 writeOffsetInBytes; + ma_uint32 writeOffsetLoopFlag; + ma_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag); - mal_uint32 readOffset = pRB->encodedReadOffset; - mal_uint32 readOffsetInBytes; - mal_uint32 readOffsetLoopFlag; - mal_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag); + ma_uint32 readOffset = pRB->encodedReadOffset; + ma_uint32 readOffsetInBytes; + ma_uint32 readOffsetLoopFlag; + ma_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag); // The number of bytes available depends on whether or not the read and write pointers are on the same loop iteration. If so, we // can only read up to the write pointer. If not, we can only read up to the end of the buffer. @@ -29283,60 +29283,60 @@ mal_result mal_rb_acquire_read(mal_rb* pRB, size_t* pSizeInBytes, void** ppBuffe } *pSizeInBytes = bytesRequested; - (*ppBufferOut) = mal_rb__get_read_ptr(pRB); + (*ppBufferOut) = ma_rb__get_read_ptr(pRB); return MA_SUCCESS; } -mal_result mal_rb_commit_read(mal_rb* pRB, size_t sizeInBytes, void* pBufferOut) +ma_result ma_rb_commit_read(ma_rb* pRB, size_t sizeInBytes, void* pBufferOut) { if (pRB == NULL) { return MA_INVALID_ARGS; } // Validate the buffer. - if (pBufferOut != mal_rb__get_read_ptr(pRB)) { + if (pBufferOut != ma_rb__get_read_ptr(pRB)) { return MA_INVALID_ARGS; } - mal_uint32 readOffset = pRB->encodedReadOffset; - mal_uint32 readOffsetInBytes; - mal_uint32 readOffsetLoopFlag; - mal_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag); + ma_uint32 readOffset = pRB->encodedReadOffset; + ma_uint32 readOffsetInBytes; + ma_uint32 readOffsetLoopFlag; + ma_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag); // Check that sizeInBytes is correct. It should never go beyond the end of the buffer. - mal_uint32 newReadOffsetInBytes = (mal_uint32)(readOffsetInBytes + sizeInBytes); + ma_uint32 newReadOffsetInBytes = (ma_uint32)(readOffsetInBytes + sizeInBytes); if (newReadOffsetInBytes > pRB->subbufferSizeInBytes) { return MA_INVALID_ARGS; // <-- sizeInBytes will cause the read offset to overflow. } // Move the read pointer back to the start if necessary. - mal_uint32 newReadOffsetLoopFlag = readOffsetLoopFlag; + ma_uint32 newReadOffsetLoopFlag = readOffsetLoopFlag; if (newReadOffsetInBytes == pRB->subbufferSizeInBytes) { newReadOffsetInBytes = 0; newReadOffsetLoopFlag ^= 0x80000000; } - mal_atomic_exchange_32(&pRB->encodedReadOffset, mal_rb__construct_offset(newReadOffsetLoopFlag, newReadOffsetInBytes)); + ma_atomic_exchange_32(&pRB->encodedReadOffset, ma_rb__construct_offset(newReadOffsetLoopFlag, newReadOffsetInBytes)); return MA_SUCCESS; } -mal_result mal_rb_acquire_write(mal_rb* pRB, size_t* pSizeInBytes, void** ppBufferOut) +ma_result ma_rb_acquire_write(ma_rb* pRB, size_t* pSizeInBytes, void** ppBufferOut) { if (pRB == NULL || pSizeInBytes == NULL || ppBufferOut == NULL) { return MA_INVALID_ARGS; } // The returned buffer should never overtake the read buffer. - mal_uint32 readOffset = pRB->encodedReadOffset; - mal_uint32 readOffsetInBytes; - mal_uint32 readOffsetLoopFlag; - mal_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag); + ma_uint32 readOffset = pRB->encodedReadOffset; + ma_uint32 readOffsetInBytes; + ma_uint32 readOffsetLoopFlag; + ma_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag); - mal_uint32 writeOffset = pRB->encodedWriteOffset; - mal_uint32 writeOffsetInBytes; - mal_uint32 writeOffsetLoopFlag; - mal_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag); + ma_uint32 writeOffset = pRB->encodedWriteOffset; + ma_uint32 writeOffsetInBytes; + ma_uint32 writeOffsetLoopFlag; + ma_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag); // In the case of writing, if the write pointer and the read pointer are on the same loop iteration we can only // write up to the end of the buffer. Otherwise we can only write up to the read pointer. The write pointer should @@ -29354,144 +29354,144 @@ mal_result mal_rb_acquire_write(mal_rb* pRB, size_t* pSizeInBytes, void** ppBuff } *pSizeInBytes = bytesRequested; - *ppBufferOut = mal_rb__get_write_ptr(pRB); + *ppBufferOut = ma_rb__get_write_ptr(pRB); // Clear the buffer if desired. if (pRB->clearOnWriteAcquire) { - mal_zero_memory(*ppBufferOut, *pSizeInBytes); + ma_zero_memory(*ppBufferOut, *pSizeInBytes); } return MA_SUCCESS; } -mal_result mal_rb_commit_write(mal_rb* pRB, size_t sizeInBytes, void* pBufferOut) +ma_result ma_rb_commit_write(ma_rb* pRB, size_t sizeInBytes, void* pBufferOut) { if (pRB == NULL) { return MA_INVALID_ARGS; } // Validate the buffer. - if (pBufferOut != mal_rb__get_write_ptr(pRB)) { + if (pBufferOut != ma_rb__get_write_ptr(pRB)) { return MA_INVALID_ARGS; } - mal_uint32 writeOffset = pRB->encodedWriteOffset; - mal_uint32 writeOffsetInBytes; - mal_uint32 writeOffsetLoopFlag; - mal_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag); + ma_uint32 writeOffset = pRB->encodedWriteOffset; + ma_uint32 writeOffsetInBytes; + ma_uint32 writeOffsetLoopFlag; + ma_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag); // Check that sizeInBytes is correct. It should never go beyond the end of the buffer. - mal_uint32 newWriteOffsetInBytes = (mal_uint32)(writeOffsetInBytes + sizeInBytes); + ma_uint32 newWriteOffsetInBytes = (ma_uint32)(writeOffsetInBytes + sizeInBytes); if (newWriteOffsetInBytes > pRB->subbufferSizeInBytes) { return MA_INVALID_ARGS; // <-- sizeInBytes will cause the read offset to overflow. } // Move the read pointer back to the start if necessary. - mal_uint32 newWriteOffsetLoopFlag = writeOffsetLoopFlag; + ma_uint32 newWriteOffsetLoopFlag = writeOffsetLoopFlag; if (newWriteOffsetInBytes == pRB->subbufferSizeInBytes) { newWriteOffsetInBytes = 0; newWriteOffsetLoopFlag ^= 0x80000000; } - mal_atomic_exchange_32(&pRB->encodedWriteOffset, mal_rb__construct_offset(newWriteOffsetLoopFlag, newWriteOffsetInBytes)); + ma_atomic_exchange_32(&pRB->encodedWriteOffset, ma_rb__construct_offset(newWriteOffsetLoopFlag, newWriteOffsetInBytes)); return MA_SUCCESS; } -mal_result mal_rb_seek_read(mal_rb* pRB, size_t offsetInBytes) +ma_result ma_rb_seek_read(ma_rb* pRB, size_t offsetInBytes) { if (pRB == NULL || offsetInBytes > pRB->subbufferSizeInBytes) { return MA_INVALID_ARGS; } - mal_uint32 readOffset = pRB->encodedReadOffset; - mal_uint32 readOffsetInBytes; - mal_uint32 readOffsetLoopFlag; - mal_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag); + ma_uint32 readOffset = pRB->encodedReadOffset; + ma_uint32 readOffsetInBytes; + ma_uint32 readOffsetLoopFlag; + ma_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag); - mal_uint32 writeOffset = pRB->encodedWriteOffset; - mal_uint32 writeOffsetInBytes; - mal_uint32 writeOffsetLoopFlag; - mal_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag); + ma_uint32 writeOffset = pRB->encodedWriteOffset; + ma_uint32 writeOffsetInBytes; + ma_uint32 writeOffsetLoopFlag; + ma_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag); - mal_uint32 newReadOffsetInBytes = readOffsetInBytes; - mal_uint32 newReadOffsetLoopFlag = readOffsetLoopFlag; + ma_uint32 newReadOffsetInBytes = readOffsetInBytes; + ma_uint32 newReadOffsetLoopFlag = readOffsetLoopFlag; // We cannot go past the write buffer. if (readOffsetLoopFlag == writeOffsetLoopFlag) { if ((readOffsetInBytes + offsetInBytes) > writeOffsetInBytes) { newReadOffsetInBytes = writeOffsetInBytes; } else { - newReadOffsetInBytes = (mal_uint32)(readOffsetInBytes + offsetInBytes); + newReadOffsetInBytes = (ma_uint32)(readOffsetInBytes + offsetInBytes); } } else { // May end up looping. if ((readOffsetInBytes + offsetInBytes) >= pRB->subbufferSizeInBytes) { - newReadOffsetInBytes = (mal_uint32)(readOffsetInBytes + offsetInBytes) - pRB->subbufferSizeInBytes; + newReadOffsetInBytes = (ma_uint32)(readOffsetInBytes + offsetInBytes) - pRB->subbufferSizeInBytes; newReadOffsetLoopFlag ^= 0x80000000; /* <-- Looped. */ } else { - newReadOffsetInBytes = (mal_uint32)(readOffsetInBytes + offsetInBytes); + newReadOffsetInBytes = (ma_uint32)(readOffsetInBytes + offsetInBytes); } } - mal_atomic_exchange_32(&pRB->encodedReadOffset, mal_rb__construct_offset(newReadOffsetInBytes, newReadOffsetLoopFlag)); + ma_atomic_exchange_32(&pRB->encodedReadOffset, ma_rb__construct_offset(newReadOffsetInBytes, newReadOffsetLoopFlag)); return MA_SUCCESS; } -mal_result mal_rb_seek_write(mal_rb* pRB, size_t offsetInBytes) +ma_result ma_rb_seek_write(ma_rb* pRB, size_t offsetInBytes) { if (pRB == NULL) { return MA_INVALID_ARGS; } - mal_uint32 readOffset = pRB->encodedReadOffset; - mal_uint32 readOffsetInBytes; - mal_uint32 readOffsetLoopFlag; - mal_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag); + ma_uint32 readOffset = pRB->encodedReadOffset; + ma_uint32 readOffsetInBytes; + ma_uint32 readOffsetLoopFlag; + ma_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag); - mal_uint32 writeOffset = pRB->encodedWriteOffset; - mal_uint32 writeOffsetInBytes; - mal_uint32 writeOffsetLoopFlag; - mal_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag); + ma_uint32 writeOffset = pRB->encodedWriteOffset; + ma_uint32 writeOffsetInBytes; + ma_uint32 writeOffsetLoopFlag; + ma_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag); - mal_uint32 newWriteOffsetInBytes = writeOffsetInBytes; - mal_uint32 newWriteOffsetLoopFlag = writeOffsetLoopFlag; + ma_uint32 newWriteOffsetInBytes = writeOffsetInBytes; + ma_uint32 newWriteOffsetLoopFlag = writeOffsetLoopFlag; // We cannot go past the write buffer. if (readOffsetLoopFlag == writeOffsetLoopFlag) { // May end up looping. if ((writeOffsetInBytes + offsetInBytes) >= pRB->subbufferSizeInBytes) { - newWriteOffsetInBytes = (mal_uint32)(writeOffsetInBytes + offsetInBytes) - pRB->subbufferSizeInBytes; + newWriteOffsetInBytes = (ma_uint32)(writeOffsetInBytes + offsetInBytes) - pRB->subbufferSizeInBytes; newWriteOffsetLoopFlag ^= 0x80000000; /* <-- Looped. */ } else { - newWriteOffsetInBytes = (mal_uint32)(writeOffsetInBytes + offsetInBytes); + newWriteOffsetInBytes = (ma_uint32)(writeOffsetInBytes + offsetInBytes); } } else { if ((writeOffsetInBytes + offsetInBytes) > readOffsetInBytes) { newWriteOffsetInBytes = readOffsetInBytes; } else { - newWriteOffsetInBytes = (mal_uint32)(writeOffsetInBytes + offsetInBytes); + newWriteOffsetInBytes = (ma_uint32)(writeOffsetInBytes + offsetInBytes); } } - mal_atomic_exchange_32(&pRB->encodedWriteOffset, mal_rb__construct_offset(newWriteOffsetInBytes, newWriteOffsetLoopFlag)); + ma_atomic_exchange_32(&pRB->encodedWriteOffset, ma_rb__construct_offset(newWriteOffsetInBytes, newWriteOffsetLoopFlag)); return MA_SUCCESS; } -mal_int32 mal_rb_pointer_distance(mal_rb* pRB) +ma_int32 ma_rb_pointer_distance(ma_rb* pRB) { if (pRB == NULL) { return 0; } - mal_uint32 readOffset = pRB->encodedReadOffset; - mal_uint32 readOffsetInBytes; - mal_uint32 readOffsetLoopFlag; - mal_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag); + ma_uint32 readOffset = pRB->encodedReadOffset; + ma_uint32 readOffsetInBytes; + ma_uint32 readOffsetLoopFlag; + ma_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag); - mal_uint32 writeOffset = pRB->encodedWriteOffset; - mal_uint32 writeOffsetInBytes; - mal_uint32 writeOffsetLoopFlag; - mal_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag); + ma_uint32 writeOffset = pRB->encodedWriteOffset; + ma_uint32 writeOffsetInBytes; + ma_uint32 writeOffsetLoopFlag; + ma_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag); if (readOffsetLoopFlag == writeOffsetLoopFlag) { return writeOffsetInBytes - readOffsetInBytes; @@ -29500,7 +29500,7 @@ mal_int32 mal_rb_pointer_distance(mal_rb* pRB) } } -size_t mal_rb_get_subbuffer_size(mal_rb* pRB) +size_t ma_rb_get_subbuffer_size(ma_rb* pRB) { if (pRB == NULL) { return 0; @@ -29509,7 +29509,7 @@ size_t mal_rb_get_subbuffer_size(mal_rb* pRB) return pRB->subbufferSizeInBytes; } -size_t mal_rb_get_subbuffer_stride(mal_rb* pRB) +size_t ma_rb_get_subbuffer_stride(ma_rb* pRB) { if (pRB == NULL) { return 0; @@ -29522,46 +29522,46 @@ size_t mal_rb_get_subbuffer_stride(mal_rb* pRB) return (size_t)pRB->subbufferStrideInBytes; } -size_t mal_rb_get_subbuffer_offset(mal_rb* pRB, size_t subbufferIndex) +size_t ma_rb_get_subbuffer_offset(ma_rb* pRB, size_t subbufferIndex) { if (pRB == NULL) { return 0; } - return subbufferIndex * mal_rb_get_subbuffer_stride(pRB); + return subbufferIndex * ma_rb_get_subbuffer_stride(pRB); } -void* mal_rb_get_subbuffer_ptr(mal_rb* pRB, size_t subbufferIndex, void* pBuffer) +void* ma_rb_get_subbuffer_ptr(ma_rb* pRB, size_t subbufferIndex, void* pBuffer) { if (pRB == NULL) { return NULL; } - return mal_offset_ptr(pBuffer, mal_rb_get_subbuffer_offset(pRB, subbufferIndex)); + return ma_offset_ptr(pBuffer, ma_rb_get_subbuffer_offset(pRB, subbufferIndex)); } -static MA_INLINE mal_uint32 mal_pcm_rb_get_bpf(mal_pcm_rb* pRB) +static MA_INLINE ma_uint32 ma_pcm_rb_get_bpf(ma_pcm_rb* pRB) { - mal_assert(pRB != NULL); + ma_assert(pRB != NULL); - return mal_get_bytes_per_frame(pRB->format, pRB->channels); + return ma_get_bytes_per_frame(pRB->format, pRB->channels); } -mal_result mal_pcm_rb_init_ex(mal_format format, mal_uint32 channels, mal_uint32 subbufferSizeInFrames, mal_uint32 subbufferCount, mal_uint32 subbufferStrideInFrames, void* pOptionalPreallocatedBuffer, mal_pcm_rb* pRB) +ma_result ma_pcm_rb_init_ex(ma_format format, ma_uint32 channels, ma_uint32 subbufferSizeInFrames, ma_uint32 subbufferCount, ma_uint32 subbufferStrideInFrames, void* pOptionalPreallocatedBuffer, ma_pcm_rb* pRB) { if (pRB == NULL) { return MA_INVALID_ARGS; } - mal_zero_object(pRB); + ma_zero_object(pRB); - mal_uint32 bpf = mal_get_bytes_per_frame(format, channels); + ma_uint32 bpf = ma_get_bytes_per_frame(format, channels); if (bpf == 0) { return MA_INVALID_ARGS; } - mal_result result = mal_rb_init_ex(subbufferSizeInFrames*bpf, subbufferCount, subbufferStrideInFrames*bpf, pOptionalPreallocatedBuffer, &pRB->rb); + ma_result result = ma_rb_init_ex(subbufferSizeInFrames*bpf, subbufferCount, subbufferStrideInFrames*bpf, pOptionalPreallocatedBuffer, &pRB->rb); if (result != MA_SUCCESS) { return result; } @@ -29572,139 +29572,139 @@ mal_result mal_pcm_rb_init_ex(mal_format format, mal_uint32 channels, mal_uint32 return MA_SUCCESS; } -mal_result mal_pcm_rb_init(mal_format format, mal_uint32 channels, mal_uint32 bufferSizeInFrames, void* pOptionalPreallocatedBuffer, mal_pcm_rb* pRB) +ma_result ma_pcm_rb_init(ma_format format, ma_uint32 channels, ma_uint32 bufferSizeInFrames, void* pOptionalPreallocatedBuffer, ma_pcm_rb* pRB) { - return mal_pcm_rb_init_ex(format, channels, bufferSizeInFrames, 1, 0, pOptionalPreallocatedBuffer, pRB); + return ma_pcm_rb_init_ex(format, channels, bufferSizeInFrames, 1, 0, pOptionalPreallocatedBuffer, pRB); } -void mal_pcm_rb_uninit(mal_pcm_rb* pRB) +void ma_pcm_rb_uninit(ma_pcm_rb* pRB) { if (pRB == NULL) { return; } - mal_rb_uninit(&pRB->rb); + ma_rb_uninit(&pRB->rb); } -mal_result mal_pcm_rb_acquire_read(mal_pcm_rb* pRB, mal_uint32* pSizeInFrames, void** ppBufferOut) +ma_result ma_pcm_rb_acquire_read(ma_pcm_rb* pRB, ma_uint32* pSizeInFrames, void** ppBufferOut) { size_t sizeInBytes; - mal_result result; + ma_result result; if (pRB == NULL || pSizeInFrames == NULL) { return MA_INVALID_ARGS; } - sizeInBytes = *pSizeInFrames * mal_pcm_rb_get_bpf(pRB); + sizeInBytes = *pSizeInFrames * ma_pcm_rb_get_bpf(pRB); - result = mal_rb_acquire_read(&pRB->rb, &sizeInBytes, ppBufferOut); + result = ma_rb_acquire_read(&pRB->rb, &sizeInBytes, ppBufferOut); if (result != MA_SUCCESS) { return result; } - *pSizeInFrames = (mal_uint32)(sizeInBytes / (size_t)mal_pcm_rb_get_bpf(pRB)); + *pSizeInFrames = (ma_uint32)(sizeInBytes / (size_t)ma_pcm_rb_get_bpf(pRB)); return MA_SUCCESS; } -mal_result mal_pcm_rb_commit_read(mal_pcm_rb* pRB, mal_uint32 sizeInFrames, void* pBufferOut) +ma_result ma_pcm_rb_commit_read(ma_pcm_rb* pRB, ma_uint32 sizeInFrames, void* pBufferOut) { if (pRB == NULL) { return MA_INVALID_ARGS; } - return mal_rb_commit_read(&pRB->rb, sizeInFrames * mal_pcm_rb_get_bpf(pRB), pBufferOut); + return ma_rb_commit_read(&pRB->rb, sizeInFrames * ma_pcm_rb_get_bpf(pRB), pBufferOut); } -mal_result mal_pcm_rb_acquire_write(mal_pcm_rb* pRB, mal_uint32* pSizeInFrames, void** ppBufferOut) +ma_result ma_pcm_rb_acquire_write(ma_pcm_rb* pRB, ma_uint32* pSizeInFrames, void** ppBufferOut) { size_t sizeInBytes; - mal_result result; + ma_result result; if (pRB == NULL) { return MA_INVALID_ARGS; } - sizeInBytes = *pSizeInFrames * mal_pcm_rb_get_bpf(pRB); + sizeInBytes = *pSizeInFrames * ma_pcm_rb_get_bpf(pRB); - result = mal_rb_acquire_write(&pRB->rb, &sizeInBytes, ppBufferOut); + result = ma_rb_acquire_write(&pRB->rb, &sizeInBytes, ppBufferOut); if (result != MA_SUCCESS) { return result; } - *pSizeInFrames = (mal_uint32)(sizeInBytes / mal_pcm_rb_get_bpf(pRB)); + *pSizeInFrames = (ma_uint32)(sizeInBytes / ma_pcm_rb_get_bpf(pRB)); return MA_SUCCESS; } -mal_result mal_pcm_rb_commit_write(mal_pcm_rb* pRB, mal_uint32 sizeInFrames, void* pBufferOut) +ma_result ma_pcm_rb_commit_write(ma_pcm_rb* pRB, ma_uint32 sizeInFrames, void* pBufferOut) { if (pRB == NULL) { return MA_INVALID_ARGS; } - return mal_rb_commit_write(&pRB->rb, sizeInFrames * mal_pcm_rb_get_bpf(pRB), pBufferOut); + return ma_rb_commit_write(&pRB->rb, sizeInFrames * ma_pcm_rb_get_bpf(pRB), pBufferOut); } -mal_result mal_pcm_rb_seek_read(mal_pcm_rb* pRB, mal_uint32 offsetInFrames) +ma_result ma_pcm_rb_seek_read(ma_pcm_rb* pRB, ma_uint32 offsetInFrames) { if (pRB == NULL) { return MA_INVALID_ARGS; } - return mal_rb_seek_read(&pRB->rb, offsetInFrames * mal_pcm_rb_get_bpf(pRB)); + return ma_rb_seek_read(&pRB->rb, offsetInFrames * ma_pcm_rb_get_bpf(pRB)); } -mal_result mal_pcm_rb_seek_write(mal_pcm_rb* pRB, mal_uint32 offsetInFrames) +ma_result ma_pcm_rb_seek_write(ma_pcm_rb* pRB, ma_uint32 offsetInFrames) { if (pRB == NULL) { return MA_INVALID_ARGS; } - return mal_rb_seek_write(&pRB->rb, offsetInFrames * mal_pcm_rb_get_bpf(pRB)); + return ma_rb_seek_write(&pRB->rb, offsetInFrames * ma_pcm_rb_get_bpf(pRB)); } -mal_int32 mal_pcm_rb_pointer_disance(mal_pcm_rb* pRB) +ma_int32 ma_pcm_rb_pointer_disance(ma_pcm_rb* pRB) { if (pRB == NULL) { return MA_INVALID_ARGS; } - return mal_rb_pointer_distance(&pRB->rb) / mal_pcm_rb_get_bpf(pRB); + return ma_rb_pointer_distance(&pRB->rb) / ma_pcm_rb_get_bpf(pRB); } -mal_uint32 mal_pcm_rb_get_subbuffer_size(mal_pcm_rb* pRB) +ma_uint32 ma_pcm_rb_get_subbuffer_size(ma_pcm_rb* pRB) { if (pRB == NULL) { return 0; } - return (mal_uint32)(mal_rb_get_subbuffer_size(&pRB->rb) / mal_pcm_rb_get_bpf(pRB)); + return (ma_uint32)(ma_rb_get_subbuffer_size(&pRB->rb) / ma_pcm_rb_get_bpf(pRB)); } -mal_uint32 mal_pcm_rb_get_subbuffer_stride(mal_pcm_rb* pRB) +ma_uint32 ma_pcm_rb_get_subbuffer_stride(ma_pcm_rb* pRB) { if (pRB == NULL) { return 0; } - return (mal_uint32)(mal_rb_get_subbuffer_stride(&pRB->rb) / mal_pcm_rb_get_bpf(pRB)); + return (ma_uint32)(ma_rb_get_subbuffer_stride(&pRB->rb) / ma_pcm_rb_get_bpf(pRB)); } -mal_uint32 mal_pcm_rb_get_subbuffer_offset(mal_pcm_rb* pRB, mal_uint32 subbufferIndex) +ma_uint32 ma_pcm_rb_get_subbuffer_offset(ma_pcm_rb* pRB, ma_uint32 subbufferIndex) { if (pRB == NULL) { return 0; } - return (mal_uint32)(mal_rb_get_subbuffer_offset(&pRB->rb, subbufferIndex) / mal_pcm_rb_get_bpf(pRB)); + return (ma_uint32)(ma_rb_get_subbuffer_offset(&pRB->rb, subbufferIndex) / ma_pcm_rb_get_bpf(pRB)); } -void* mal_pcm_rb_get_subbuffer_ptr(mal_pcm_rb* pRB, mal_uint32 subbufferIndex, void* pBuffer) +void* ma_pcm_rb_get_subbuffer_ptr(ma_pcm_rb* pRB, ma_uint32 subbufferIndex, void* pBuffer) { if (pRB == NULL) { return NULL; } - return mal_rb_get_subbuffer_ptr(&pRB->rb, subbufferIndex, pBuffer); + return ma_rb_get_subbuffer_ptr(&pRB->rb, subbufferIndex, pBuffer); } @@ -29717,22 +29717,22 @@ void* mal_pcm_rb_get_subbuffer_ptr(mal_pcm_rb* pRB, mal_uint32 subbufferIndex, v ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -void* mal_malloc(size_t sz) +void* ma_malloc(size_t sz) { return MA_MALLOC(sz); } -void* mal_realloc(void* p, size_t sz) +void* ma_realloc(void* p, size_t sz) { return MA_REALLOC(p, sz); } -void mal_free(void* p) +void ma_free(void* p) { MA_FREE(p); } -void* mal_aligned_malloc(size_t sz, size_t alignment) +void* ma_aligned_malloc(size_t sz, size_t alignment) { if (alignment == 0) { return 0; @@ -29740,47 +29740,47 @@ void* mal_aligned_malloc(size_t sz, size_t alignment) size_t extraBytes = alignment-1 + sizeof(void*); - void* pUnaligned = mal_malloc(sz + extraBytes); + void* pUnaligned = ma_malloc(sz + extraBytes); if (pUnaligned == NULL) { return NULL; } - void* pAligned = (void*)(((mal_uintptr)pUnaligned + extraBytes) & ~((mal_uintptr)(alignment-1))); + void* pAligned = (void*)(((ma_uintptr)pUnaligned + extraBytes) & ~((ma_uintptr)(alignment-1))); ((void**)pAligned)[-1] = pUnaligned; return pAligned; } -void mal_aligned_free(void* p) +void ma_aligned_free(void* p) { - mal_free(((void**)p)[-1]); + ma_free(((void**)p)[-1]); } -const char* mal_get_format_name(mal_format format) +const char* ma_get_format_name(ma_format format) { switch (format) { - case mal_format_unknown: return "Unknown"; - case mal_format_u8: return "8-bit Unsigned Integer"; - case mal_format_s16: return "16-bit Signed Integer"; - case mal_format_s24: return "24-bit Signed Integer (Tightly Packed)"; - case mal_format_s32: return "32-bit Signed Integer"; - case mal_format_f32: return "32-bit IEEE Floating Point"; + case ma_format_unknown: return "Unknown"; + case ma_format_u8: return "8-bit Unsigned Integer"; + case ma_format_s16: return "16-bit Signed Integer"; + case ma_format_s24: return "24-bit Signed Integer (Tightly Packed)"; + case ma_format_s32: return "32-bit Signed Integer"; + case ma_format_f32: return "32-bit IEEE Floating Point"; default: return "Invalid"; } } -void mal_blend_f32(float* pOut, float* pInA, float* pInB, float factor, mal_uint32 channels) +void ma_blend_f32(float* pOut, float* pInA, float* pInB, float factor, ma_uint32 channels) { - for (mal_uint32 i = 0; i < channels; ++i) { - pOut[i] = mal_mix_f32(pInA[i], pInB[i], factor); + for (ma_uint32 i = 0; i < channels; ++i) { + pOut[i] = ma_mix_f32(pInA[i], pInB[i], factor); } } -mal_uint32 mal_get_bytes_per_sample(mal_format format) +ma_uint32 ma_get_bytes_per_sample(ma_format format) { - mal_uint32 sizes[] = { + ma_uint32 sizes[] = { 0, // unknown 1, // u8 2, // s16 @@ -29801,36 +29801,36 @@ mal_uint32 mal_get_bytes_per_sample(mal_format format) ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #ifndef MA_NO_DECODING -mal_decoder_config mal_decoder_config_init(mal_format outputFormat, mal_uint32 outputChannels, mal_uint32 outputSampleRate) +ma_decoder_config ma_decoder_config_init(ma_format outputFormat, ma_uint32 outputChannels, ma_uint32 outputSampleRate) { - mal_decoder_config config; - mal_zero_object(&config); + ma_decoder_config config; + ma_zero_object(&config); config.format = outputFormat; config.channels = outputChannels; config.sampleRate = outputSampleRate; - mal_get_standard_channel_map(mal_standard_channel_map_default, config.channels, config.channelMap); + ma_get_standard_channel_map(ma_standard_channel_map_default, config.channels, config.channelMap); return config; } -mal_decoder_config mal_decoder_config_init_copy(const mal_decoder_config* pConfig) +ma_decoder_config ma_decoder_config_init_copy(const ma_decoder_config* pConfig) { - mal_decoder_config config; + ma_decoder_config config; if (pConfig != NULL) { config = *pConfig; } else { - mal_zero_object(&config); + ma_zero_object(&config); } return config; } -mal_result mal_decoder__init_dsp(mal_decoder* pDecoder, const mal_decoder_config* pConfig, mal_pcm_converter_read_proc onRead) +ma_result ma_decoder__init_dsp(ma_decoder* pDecoder, const ma_decoder_config* pConfig, ma_pcm_converter_read_proc onRead) { - mal_assert(pDecoder != NULL); + ma_assert(pDecoder != NULL); // Output format. - if (pConfig->format == mal_format_unknown) { + if (pConfig->format == ma_format_unknown) { pDecoder->outputFormat = pDecoder->internalFormat; } else { pDecoder->outputFormat = pConfig->format; @@ -29848,15 +29848,15 @@ mal_result mal_decoder__init_dsp(mal_decoder* pDecoder, const mal_decoder_config pDecoder->outputSampleRate = pConfig->sampleRate; } - if (mal_channel_map_blank(pDecoder->outputChannels, pConfig->channelMap)) { - mal_get_standard_channel_map(mal_standard_channel_map_default, pDecoder->outputChannels, pDecoder->outputChannelMap); + if (ma_channel_map_blank(pDecoder->outputChannels, pConfig->channelMap)) { + ma_get_standard_channel_map(ma_standard_channel_map_default, pDecoder->outputChannels, pDecoder->outputChannelMap); } else { - mal_copy_memory(pDecoder->outputChannelMap, pConfig->channelMap, sizeof(pConfig->channelMap)); + ma_copy_memory(pDecoder->outputChannelMap, pConfig->channelMap, sizeof(pConfig->channelMap)); } // DSP. - mal_pcm_converter_config dspConfig = mal_pcm_converter_config_init_ex( + ma_pcm_converter_config dspConfig = ma_pcm_converter_config_init_ex( pDecoder->internalFormat, pDecoder->internalChannels, pDecoder->internalSampleRate, pDecoder->internalChannelMap, pDecoder->outputFormat, pDecoder->outputChannels, pDecoder->outputSampleRate, pDecoder->outputChannelMap, onRead, pDecoder); @@ -29865,57 +29865,57 @@ mal_result mal_decoder__init_dsp(mal_decoder* pDecoder, const mal_decoder_config dspConfig.srcAlgorithm = pConfig->srcAlgorithm; dspConfig.sinc = pConfig->src.sinc; - return mal_pcm_converter_init(&dspConfig, &pDecoder->dsp); + return ma_pcm_converter_init(&dspConfig, &pDecoder->dsp); } // WAV #ifdef dr_wav_h #define MA_HAS_WAV -size_t mal_decoder_internal_on_read__wav(void* pUserData, void* pBufferOut, size_t bytesToRead) +size_t ma_decoder_internal_on_read__wav(void* pUserData, void* pBufferOut, size_t bytesToRead) { - mal_decoder* pDecoder = (mal_decoder*)pUserData; - mal_assert(pDecoder != NULL); - mal_assert(pDecoder->onRead != NULL); + ma_decoder* pDecoder = (ma_decoder*)pUserData; + ma_assert(pDecoder != NULL); + ma_assert(pDecoder->onRead != NULL); return pDecoder->onRead(pDecoder, pBufferOut, bytesToRead); } -drwav_bool32 mal_decoder_internal_on_seek__wav(void* pUserData, int offset, drwav_seek_origin origin) +drwav_bool32 ma_decoder_internal_on_seek__wav(void* pUserData, int offset, drwav_seek_origin origin) { - mal_decoder* pDecoder = (mal_decoder*)pUserData; - mal_assert(pDecoder != NULL); - mal_assert(pDecoder->onSeek != NULL); + ma_decoder* pDecoder = (ma_decoder*)pUserData; + ma_assert(pDecoder != NULL); + ma_assert(pDecoder->onSeek != NULL); - return pDecoder->onSeek(pDecoder, offset, (origin == drwav_seek_origin_start) ? mal_seek_origin_start : mal_seek_origin_current); + return pDecoder->onSeek(pDecoder, offset, (origin == drwav_seek_origin_start) ? ma_seek_origin_start : ma_seek_origin_current); } -mal_uint32 mal_decoder_internal_on_read_pcm_frames__wav(mal_pcm_converter* pDSP, void* pSamplesOut, mal_uint32 frameCount, void* pUserData) +ma_uint32 ma_decoder_internal_on_read_pcm_frames__wav(ma_pcm_converter* pDSP, void* pSamplesOut, ma_uint32 frameCount, void* pUserData) { (void)pDSP; - mal_decoder* pDecoder = (mal_decoder*)pUserData; - mal_assert(pDecoder != NULL); + ma_decoder* pDecoder = (ma_decoder*)pUserData; + ma_assert(pDecoder != NULL); drwav* pWav = (drwav*)pDecoder->pInternalDecoder; - mal_assert(pWav != NULL); + ma_assert(pWav != NULL); switch (pDecoder->internalFormat) { - case mal_format_s16: return (mal_uint32)drwav_read_pcm_frames_s16(pWav, frameCount, (drwav_int16*)pSamplesOut); - case mal_format_s32: return (mal_uint32)drwav_read_pcm_frames_s32(pWav, frameCount, (drwav_int32*)pSamplesOut); - case mal_format_f32: return (mal_uint32)drwav_read_pcm_frames_f32(pWav, frameCount, (float*)pSamplesOut); + case ma_format_s16: return (ma_uint32)drwav_read_pcm_frames_s16(pWav, frameCount, (drwav_int16*)pSamplesOut); + case ma_format_s32: return (ma_uint32)drwav_read_pcm_frames_s32(pWav, frameCount, (drwav_int32*)pSamplesOut); + case ma_format_f32: return (ma_uint32)drwav_read_pcm_frames_f32(pWav, frameCount, (float*)pSamplesOut); default: break; } // Should never get here. If we do, it means the internal format was not set correctly at initialization time. - mal_assert(MA_FALSE); + ma_assert(MA_FALSE); return 0; } -mal_result mal_decoder_internal_on_seek_to_pcm_frame__wav(mal_decoder* pDecoder, mal_uint64 frameIndex) +ma_result ma_decoder_internal_on_seek_to_pcm_frame__wav(ma_decoder* pDecoder, ma_uint64 frameIndex) { drwav* pWav = (drwav*)pDecoder->pInternalDecoder; - mal_assert(pWav != NULL); + ma_assert(pWav != NULL); drwav_bool32 result = drwav_seek_to_pcm_frame(pWav, frameIndex); if (result) { @@ -29925,46 +29925,46 @@ mal_result mal_decoder_internal_on_seek_to_pcm_frame__wav(mal_decoder* pDecoder, } } -mal_result mal_decoder_internal_on_uninit__wav(mal_decoder* pDecoder) +ma_result ma_decoder_internal_on_uninit__wav(ma_decoder* pDecoder) { drwav_close((drwav*)pDecoder->pInternalDecoder); return MA_SUCCESS; } -mal_result mal_decoder_init_wav__internal(const mal_decoder_config* pConfig, mal_decoder* pDecoder) +ma_result ma_decoder_init_wav__internal(const ma_decoder_config* pConfig, ma_decoder* pDecoder) { - mal_assert(pConfig != NULL); - mal_assert(pDecoder != NULL); + ma_assert(pConfig != NULL); + ma_assert(pDecoder != NULL); // Try opening the decoder first. - drwav* pWav = drwav_open(mal_decoder_internal_on_read__wav, mal_decoder_internal_on_seek__wav, pDecoder); + drwav* pWav = drwav_open(ma_decoder_internal_on_read__wav, ma_decoder_internal_on_seek__wav, pDecoder); if (pWav == NULL) { return MA_ERROR; } - // If we get here it means we successfully initialized the WAV decoder. We can now initialize the rest of the mal_decoder. - pDecoder->onSeekToPCMFrame = mal_decoder_internal_on_seek_to_pcm_frame__wav; - pDecoder->onUninit = mal_decoder_internal_on_uninit__wav; + // If we get here it means we successfully initialized the WAV decoder. We can now initialize the rest of the ma_decoder. + pDecoder->onSeekToPCMFrame = ma_decoder_internal_on_seek_to_pcm_frame__wav; + pDecoder->onUninit = ma_decoder_internal_on_uninit__wav; pDecoder->pInternalDecoder = pWav; // Try to be as optimal as possible for the internal format. If miniaudio does not support a format we will fall back to f32. - pDecoder->internalFormat = mal_format_unknown; + pDecoder->internalFormat = ma_format_unknown; switch (pWav->translatedFormatTag) { case DR_WAVE_FORMAT_PCM: { if (pWav->bitsPerSample == 8) { - pDecoder->internalFormat = mal_format_s16; + pDecoder->internalFormat = ma_format_s16; } else if (pWav->bitsPerSample == 16) { - pDecoder->internalFormat = mal_format_s16; + pDecoder->internalFormat = ma_format_s16; } else if (pWav->bitsPerSample == 32) { - pDecoder->internalFormat = mal_format_s32; + pDecoder->internalFormat = ma_format_s32; } } break; case DR_WAVE_FORMAT_IEEE_FLOAT: { if (pWav->bitsPerSample == 32) { - pDecoder->internalFormat = mal_format_f32; + pDecoder->internalFormat = ma_format_f32; } } break; @@ -29973,19 +29973,19 @@ mal_result mal_decoder_init_wav__internal(const mal_decoder_config* pConfig, mal case DR_WAVE_FORMAT_ADPCM: case DR_WAVE_FORMAT_DVI_ADPCM: { - pDecoder->internalFormat = mal_format_s16; + pDecoder->internalFormat = ma_format_s16; } break; } - if (pDecoder->internalFormat == mal_format_unknown) { - pDecoder->internalFormat = mal_format_f32; + if (pDecoder->internalFormat == ma_format_unknown) { + pDecoder->internalFormat = ma_format_f32; } pDecoder->internalChannels = pWav->channels; pDecoder->internalSampleRate = pWav->sampleRate; - mal_get_standard_channel_map(mal_standard_channel_map_microsoft, pDecoder->internalChannels, pDecoder->internalChannelMap); + ma_get_standard_channel_map(ma_standard_channel_map_microsoft, pDecoder->internalChannels, pDecoder->internalChannelMap); - mal_result result = mal_decoder__init_dsp(pDecoder, pConfig, mal_decoder_internal_on_read_pcm_frames__wav); + ma_result result = ma_decoder__init_dsp(pDecoder, pConfig, ma_decoder_internal_on_read_pcm_frames__wav); if (result != MA_SUCCESS) { drwav_close(pWav); return result; @@ -29999,50 +29999,50 @@ mal_result mal_decoder_init_wav__internal(const mal_decoder_config* pConfig, mal #ifdef dr_flac_h #define MA_HAS_FLAC -size_t mal_decoder_internal_on_read__flac(void* pUserData, void* pBufferOut, size_t bytesToRead) +size_t ma_decoder_internal_on_read__flac(void* pUserData, void* pBufferOut, size_t bytesToRead) { - mal_decoder* pDecoder = (mal_decoder*)pUserData; - mal_assert(pDecoder != NULL); - mal_assert(pDecoder->onRead != NULL); + ma_decoder* pDecoder = (ma_decoder*)pUserData; + ma_assert(pDecoder != NULL); + ma_assert(pDecoder->onRead != NULL); return pDecoder->onRead(pDecoder, pBufferOut, bytesToRead); } -drflac_bool32 mal_decoder_internal_on_seek__flac(void* pUserData, int offset, drflac_seek_origin origin) +drflac_bool32 ma_decoder_internal_on_seek__flac(void* pUserData, int offset, drflac_seek_origin origin) { - mal_decoder* pDecoder = (mal_decoder*)pUserData; - mal_assert(pDecoder != NULL); - mal_assert(pDecoder->onSeek != NULL); + ma_decoder* pDecoder = (ma_decoder*)pUserData; + ma_assert(pDecoder != NULL); + ma_assert(pDecoder->onSeek != NULL); - return pDecoder->onSeek(pDecoder, offset, (origin == drflac_seek_origin_start) ? mal_seek_origin_start : mal_seek_origin_current); + return pDecoder->onSeek(pDecoder, offset, (origin == drflac_seek_origin_start) ? ma_seek_origin_start : ma_seek_origin_current); } -mal_uint32 mal_decoder_internal_on_read_pcm_frames__flac(mal_pcm_converter* pDSP, void* pSamplesOut, mal_uint32 frameCount, void* pUserData) +ma_uint32 ma_decoder_internal_on_read_pcm_frames__flac(ma_pcm_converter* pDSP, void* pSamplesOut, ma_uint32 frameCount, void* pUserData) { (void)pDSP; - mal_decoder* pDecoder = (mal_decoder*)pUserData; - mal_assert(pDecoder != NULL); + ma_decoder* pDecoder = (ma_decoder*)pUserData; + ma_assert(pDecoder != NULL); drflac* pFlac = (drflac*)pDecoder->pInternalDecoder; - mal_assert(pFlac != NULL); + ma_assert(pFlac != NULL); switch (pDecoder->internalFormat) { - case mal_format_s16: return (mal_uint32)drflac_read_pcm_frames_s16(pFlac, frameCount, (drflac_int16*)pSamplesOut); - case mal_format_s32: return (mal_uint32)drflac_read_pcm_frames_s32(pFlac, frameCount, (drflac_int32*)pSamplesOut); - case mal_format_f32: return (mal_uint32)drflac_read_pcm_frames_f32(pFlac, frameCount, (float*)pSamplesOut); + case ma_format_s16: return (ma_uint32)drflac_read_pcm_frames_s16(pFlac, frameCount, (drflac_int16*)pSamplesOut); + case ma_format_s32: return (ma_uint32)drflac_read_pcm_frames_s32(pFlac, frameCount, (drflac_int32*)pSamplesOut); + case ma_format_f32: return (ma_uint32)drflac_read_pcm_frames_f32(pFlac, frameCount, (float*)pSamplesOut); default: break; } // Should never get here. If we do, it means the internal format was not set correctly at initialization time. - mal_assert(MA_FALSE); + ma_assert(MA_FALSE); return 0; } -mal_result mal_decoder_internal_on_seek_to_pcm_frame__flac(mal_decoder* pDecoder, mal_uint64 frameIndex) +ma_result ma_decoder_internal_on_seek_to_pcm_frame__flac(ma_decoder* pDecoder, ma_uint64 frameIndex) { drflac* pFlac = (drflac*)pDecoder->pInternalDecoder; - mal_assert(pFlac != NULL); + ma_assert(pFlac != NULL); drflac_bool32 result = drflac_seek_to_pcm_frame(pFlac, frameIndex); if (result) { @@ -30052,42 +30052,42 @@ mal_result mal_decoder_internal_on_seek_to_pcm_frame__flac(mal_decoder* pDecoder } } -mal_result mal_decoder_internal_on_uninit__flac(mal_decoder* pDecoder) +ma_result ma_decoder_internal_on_uninit__flac(ma_decoder* pDecoder) { drflac_close((drflac*)pDecoder->pInternalDecoder); return MA_SUCCESS; } -mal_result mal_decoder_init_flac__internal(const mal_decoder_config* pConfig, mal_decoder* pDecoder) +ma_result ma_decoder_init_flac__internal(const ma_decoder_config* pConfig, ma_decoder* pDecoder) { - mal_assert(pConfig != NULL); - mal_assert(pDecoder != NULL); + ma_assert(pConfig != NULL); + ma_assert(pDecoder != NULL); // Try opening the decoder first. - drflac* pFlac = drflac_open(mal_decoder_internal_on_read__flac, mal_decoder_internal_on_seek__flac, pDecoder); + drflac* pFlac = drflac_open(ma_decoder_internal_on_read__flac, ma_decoder_internal_on_seek__flac, pDecoder); if (pFlac == NULL) { return MA_ERROR; } - // If we get here it means we successfully initialized the FLAC decoder. We can now initialize the rest of the mal_decoder. - pDecoder->onSeekToPCMFrame = mal_decoder_internal_on_seek_to_pcm_frame__flac; - pDecoder->onUninit = mal_decoder_internal_on_uninit__flac; + // If we get here it means we successfully initialized the FLAC decoder. We can now initialize the rest of the ma_decoder. + pDecoder->onSeekToPCMFrame = ma_decoder_internal_on_seek_to_pcm_frame__flac; + pDecoder->onUninit = ma_decoder_internal_on_uninit__flac; pDecoder->pInternalDecoder = pFlac; // dr_flac supports reading as s32, s16 and f32. Try to do a one-to-one mapping if possible, but fall back to s32 if not. s32 is the "native" FLAC format // since it's the only one that's truly lossless. - pDecoder->internalFormat = mal_format_s32; - if (pConfig->format == mal_format_s16) { - pDecoder->internalFormat = mal_format_s16; - } else if (pConfig->format == mal_format_f32) { - pDecoder->internalFormat = mal_format_f32; + pDecoder->internalFormat = ma_format_s32; + if (pConfig->format == ma_format_s16) { + pDecoder->internalFormat = ma_format_s16; + } else if (pConfig->format == ma_format_f32) { + pDecoder->internalFormat = ma_format_f32; } pDecoder->internalChannels = pFlac->channels; pDecoder->internalSampleRate = pFlac->sampleRate; - mal_get_standard_channel_map(mal_standard_channel_map_flac, pDecoder->internalChannels, pDecoder->internalChannelMap); + ma_get_standard_channel_map(ma_standard_channel_map_flac, pDecoder->internalChannels, pDecoder->internalChannelMap); - mal_result result = mal_decoder__init_dsp(pDecoder, pConfig, mal_decoder_internal_on_read_pcm_frames__flac); + ma_result result = ma_decoder__init_dsp(pDecoder, pConfig, ma_decoder_internal_on_read_pcm_frames__flac); if (result != MA_SUCCESS) { drflac_close(pFlac); return result; @@ -30107,28 +30107,28 @@ mal_result mal_decoder_init_flac__internal(const mal_decoder_config* pConfig, ma typedef struct { stb_vorbis* pInternalVorbis; - mal_uint8* pData; + ma_uint8* pData; size_t dataSize; size_t dataCapacity; - mal_uint32 framesConsumed; // The number of frames consumed in ppPacketData. - mal_uint32 framesRemaining; // The number of frames remaining in ppPacketData. + ma_uint32 framesConsumed; // The number of frames consumed in ppPacketData. + ma_uint32 framesRemaining; // The number of frames remaining in ppPacketData. float** ppPacketData; -} mal_vorbis_decoder; +} ma_vorbis_decoder; -mal_uint32 mal_vorbis_decoder_read_pcm_frames(mal_vorbis_decoder* pVorbis, mal_decoder* pDecoder, void* pSamplesOut, mal_uint32 frameCount) +ma_uint32 ma_vorbis_decoder_read_pcm_frames(ma_vorbis_decoder* pVorbis, ma_decoder* pDecoder, void* pSamplesOut, ma_uint32 frameCount) { - mal_assert(pVorbis != NULL); - mal_assert(pDecoder != NULL); - mal_assert(pDecoder->onRead != NULL); - mal_assert(pDecoder->onSeek != NULL); + ma_assert(pVorbis != NULL); + ma_assert(pDecoder != NULL); + ma_assert(pDecoder->onRead != NULL); + ma_assert(pDecoder->onSeek != NULL); float* pSamplesOutF = (float*)pSamplesOut; - mal_uint32 totalFramesRead = 0; + ma_uint32 totalFramesRead = 0; while (frameCount > 0) { // Read from the in-memory buffer first. while (pVorbis->framesRemaining > 0 && frameCount > 0) { - for (mal_uint32 iChannel = 0; iChannel < pDecoder->internalChannels; ++iChannel) { + for (ma_uint32 iChannel = 0; iChannel < pDecoder->internalChannels; ++iChannel) { pSamplesOutF[0] = pVorbis->ppPacketData[iChannel][pVorbis->framesConsumed]; pSamplesOutF += 1; } @@ -30143,7 +30143,7 @@ mal_uint32 mal_vorbis_decoder_read_pcm_frames(mal_vorbis_decoder* pVorbis, mal_d break; } - mal_assert(pVorbis->framesRemaining == 0); + ma_assert(pVorbis->framesRemaining == 0); // We've run out of cached frames, so decode the next packet and continue iteration. do @@ -30169,7 +30169,7 @@ mal_uint32 mal_vorbis_decoder_read_pcm_frames(mal_vorbis_decoder* pVorbis, mal_d if (pVorbis->dataCapacity == pVorbis->dataSize) { // No room. Expand. pVorbis->dataCapacity += MA_VORBIS_DATA_CHUNK_SIZE; - mal_uint8* pNewData = (mal_uint8*)mal_realloc(pVorbis->pData, pVorbis->dataCapacity); + ma_uint8* pNewData = (ma_uint8*)ma_realloc(pVorbis->pData, pVorbis->dataCapacity); if (pNewData == NULL) { return totalFramesRead; // Out of memory. } @@ -30191,17 +30191,17 @@ mal_uint32 mal_vorbis_decoder_read_pcm_frames(mal_vorbis_decoder* pVorbis, mal_d return totalFramesRead; } -mal_result mal_vorbis_decoder_seek_to_pcm_frame(mal_vorbis_decoder* pVorbis, mal_decoder* pDecoder, mal_uint64 frameIndex) +ma_result ma_vorbis_decoder_seek_to_pcm_frame(ma_vorbis_decoder* pVorbis, ma_decoder* pDecoder, ma_uint64 frameIndex) { - mal_assert(pVorbis != NULL); - mal_assert(pDecoder != NULL); - mal_assert(pDecoder->onRead != NULL); - mal_assert(pDecoder->onSeek != NULL); + ma_assert(pVorbis != NULL); + ma_assert(pDecoder != NULL); + ma_assert(pDecoder->onRead != NULL); + ma_assert(pDecoder->onSeek != NULL); // This is terribly inefficient because stb_vorbis does not have a good seeking solution with it's push API. Currently this just performs // a full decode right from the start of the stream. Later on I'll need to write a layer that goes through all of the Ogg pages until we // find the one containing the sample we need. Then we know exactly where to seek for stb_vorbis. - if (!pDecoder->onSeek(pDecoder, 0, mal_seek_origin_start)) { + if (!pDecoder->onSeek(pDecoder, 0, ma_seek_origin_start)) { return MA_ERROR; } @@ -30212,12 +30212,12 @@ mal_result mal_vorbis_decoder_seek_to_pcm_frame(mal_vorbis_decoder* pVorbis, mal float buffer[4096]; while (frameIndex > 0) { - mal_uint32 framesToRead = mal_countof(buffer)/pDecoder->internalChannels; + ma_uint32 framesToRead = ma_countof(buffer)/pDecoder->internalChannels; if (framesToRead > frameIndex) { - framesToRead = (mal_uint32)frameIndex; + framesToRead = (ma_uint32)frameIndex; } - mal_uint32 framesRead = mal_vorbis_decoder_read_pcm_frames(pVorbis, pDecoder, buffer, framesToRead); + ma_uint32 framesRead = ma_vorbis_decoder_read_pcm_frames(pVorbis, pDecoder, buffer, framesToRead); if (framesRead == 0) { return MA_ERROR; } @@ -30229,66 +30229,66 @@ mal_result mal_vorbis_decoder_seek_to_pcm_frame(mal_vorbis_decoder* pVorbis, mal } -mal_result mal_decoder_internal_on_seek_to_pcm_frame__vorbis(mal_decoder* pDecoder, mal_uint64 frameIndex) +ma_result ma_decoder_internal_on_seek_to_pcm_frame__vorbis(ma_decoder* pDecoder, ma_uint64 frameIndex) { - mal_assert(pDecoder != NULL); - mal_assert(pDecoder->onRead != NULL); - mal_assert(pDecoder->onSeek != NULL); + ma_assert(pDecoder != NULL); + ma_assert(pDecoder->onRead != NULL); + ma_assert(pDecoder->onSeek != NULL); - mal_vorbis_decoder* pVorbis = (mal_vorbis_decoder*)pDecoder->pInternalDecoder; - mal_assert(pVorbis != NULL); + ma_vorbis_decoder* pVorbis = (ma_vorbis_decoder*)pDecoder->pInternalDecoder; + ma_assert(pVorbis != NULL); - return mal_vorbis_decoder_seek_to_pcm_frame(pVorbis, pDecoder, frameIndex); + return ma_vorbis_decoder_seek_to_pcm_frame(pVorbis, pDecoder, frameIndex); } -mal_result mal_decoder_internal_on_uninit__vorbis(mal_decoder* pDecoder) +ma_result ma_decoder_internal_on_uninit__vorbis(ma_decoder* pDecoder) { - mal_vorbis_decoder* pVorbis = (mal_vorbis_decoder*)pDecoder->pInternalDecoder; - mal_assert(pVorbis != NULL); + ma_vorbis_decoder* pVorbis = (ma_vorbis_decoder*)pDecoder->pInternalDecoder; + ma_assert(pVorbis != NULL); stb_vorbis_close(pVorbis->pInternalVorbis); - mal_free(pVorbis->pData); - mal_free(pVorbis); + ma_free(pVorbis->pData); + ma_free(pVorbis); return MA_SUCCESS; } -mal_uint32 mal_decoder_internal_on_read_pcm_frames__vorbis(mal_pcm_converter* pDSP, void* pSamplesOut, mal_uint32 frameCount, void* pUserData) +ma_uint32 ma_decoder_internal_on_read_pcm_frames__vorbis(ma_pcm_converter* pDSP, void* pSamplesOut, ma_uint32 frameCount, void* pUserData) { (void)pDSP; - mal_decoder* pDecoder = (mal_decoder*)pUserData; - mal_assert(pDecoder != NULL); - mal_assert(pDecoder->internalFormat == mal_format_f32); - mal_assert(pDecoder->onRead != NULL); - mal_assert(pDecoder->onSeek != NULL); + ma_decoder* pDecoder = (ma_decoder*)pUserData; + ma_assert(pDecoder != NULL); + ma_assert(pDecoder->internalFormat == ma_format_f32); + ma_assert(pDecoder->onRead != NULL); + ma_assert(pDecoder->onSeek != NULL); - mal_vorbis_decoder* pVorbis = (mal_vorbis_decoder*)pDecoder->pInternalDecoder; - mal_assert(pVorbis != NULL); + ma_vorbis_decoder* pVorbis = (ma_vorbis_decoder*)pDecoder->pInternalDecoder; + ma_assert(pVorbis != NULL); - return mal_vorbis_decoder_read_pcm_frames(pVorbis, pDecoder, pSamplesOut, frameCount); + return ma_vorbis_decoder_read_pcm_frames(pVorbis, pDecoder, pSamplesOut, frameCount); } -mal_result mal_decoder_init_vorbis__internal(const mal_decoder_config* pConfig, mal_decoder* pDecoder) +ma_result ma_decoder_init_vorbis__internal(const ma_decoder_config* pConfig, ma_decoder* pDecoder) { - mal_assert(pConfig != NULL); - mal_assert(pDecoder != NULL); - mal_assert(pDecoder->onRead != NULL); - mal_assert(pDecoder->onSeek != NULL); + ma_assert(pConfig != NULL); + ma_assert(pDecoder != NULL); + ma_assert(pDecoder->onRead != NULL); + ma_assert(pDecoder->onSeek != NULL); stb_vorbis* pInternalVorbis = NULL; // We grow the buffer in chunks. size_t dataSize = 0; size_t dataCapacity = 0; - mal_uint8* pData = NULL; + ma_uint8* pData = NULL; do { // Allocate memory for a new chunk. dataCapacity += MA_VORBIS_DATA_CHUNK_SIZE; - mal_uint8* pNewData = (mal_uint8*)mal_realloc(pData, dataCapacity); + ma_uint8* pNewData = (ma_uint8*)ma_realloc(pData, dataCapacity); if (pNewData == NULL) { - mal_free(pData); + ma_free(pData); return MA_OUT_OF_MEMORY; } @@ -30334,39 +30334,39 @@ mal_result mal_decoder_init_vorbis__internal(const mal_decoder_config* pConfig, // Don't allow more than MA_MAX_CHANNELS channels. if (vorbisInfo.channels > MA_MAX_CHANNELS) { stb_vorbis_close(pInternalVorbis); - mal_free(pData); + ma_free(pData); return MA_ERROR; // Too many channels. } - size_t vorbisDataSize = sizeof(mal_vorbis_decoder) + sizeof(float)*vorbisInfo.max_frame_size; - mal_vorbis_decoder* pVorbis = (mal_vorbis_decoder*)mal_malloc(vorbisDataSize); + size_t vorbisDataSize = sizeof(ma_vorbis_decoder) + sizeof(float)*vorbisInfo.max_frame_size; + ma_vorbis_decoder* pVorbis = (ma_vorbis_decoder*)ma_malloc(vorbisDataSize); if (pVorbis == NULL) { stb_vorbis_close(pInternalVorbis); - mal_free(pData); + ma_free(pData); return MA_OUT_OF_MEMORY; } - mal_zero_memory(pVorbis, vorbisDataSize); + ma_zero_memory(pVorbis, vorbisDataSize); pVorbis->pInternalVorbis = pInternalVorbis; pVorbis->pData = pData; pVorbis->dataSize = dataSize; pVorbis->dataCapacity = dataCapacity; - pDecoder->onSeekToPCMFrame = mal_decoder_internal_on_seek_to_pcm_frame__vorbis; - pDecoder->onUninit = mal_decoder_internal_on_uninit__vorbis; + pDecoder->onSeekToPCMFrame = ma_decoder_internal_on_seek_to_pcm_frame__vorbis; + pDecoder->onUninit = ma_decoder_internal_on_uninit__vorbis; pDecoder->pInternalDecoder = pVorbis; // The internal format is always f32. - pDecoder->internalFormat = mal_format_f32; + pDecoder->internalFormat = ma_format_f32; pDecoder->internalChannels = vorbisInfo.channels; pDecoder->internalSampleRate = vorbisInfo.sample_rate; - mal_get_standard_channel_map(mal_standard_channel_map_vorbis, pDecoder->internalChannels, pDecoder->internalChannelMap); + ma_get_standard_channel_map(ma_standard_channel_map_vorbis, pDecoder->internalChannels, pDecoder->internalChannelMap); - mal_result result = mal_decoder__init_dsp(pDecoder, pConfig, mal_decoder_internal_on_read_pcm_frames__vorbis); + ma_result result = ma_decoder__init_dsp(pDecoder, pConfig, ma_decoder_internal_on_read_pcm_frames__vorbis); if (result != MA_SUCCESS) { stb_vorbis_close(pVorbis->pInternalVorbis); - mal_free(pVorbis->pData); - mal_free(pVorbis); + ma_free(pVorbis->pData); + ma_free(pVorbis); return result; } @@ -30378,42 +30378,42 @@ mal_result mal_decoder_init_vorbis__internal(const mal_decoder_config* pConfig, #ifdef dr_mp3_h #define MA_HAS_MP3 -size_t mal_decoder_internal_on_read__mp3(void* pUserData, void* pBufferOut, size_t bytesToRead) +size_t ma_decoder_internal_on_read__mp3(void* pUserData, void* pBufferOut, size_t bytesToRead) { - mal_decoder* pDecoder = (mal_decoder*)pUserData; - mal_assert(pDecoder != NULL); - mal_assert(pDecoder->onRead != NULL); + ma_decoder* pDecoder = (ma_decoder*)pUserData; + ma_assert(pDecoder != NULL); + ma_assert(pDecoder->onRead != NULL); return pDecoder->onRead(pDecoder, pBufferOut, bytesToRead); } -drmp3_bool32 mal_decoder_internal_on_seek__mp3(void* pUserData, int offset, drmp3_seek_origin origin) +drmp3_bool32 ma_decoder_internal_on_seek__mp3(void* pUserData, int offset, drmp3_seek_origin origin) { - mal_decoder* pDecoder = (mal_decoder*)pUserData; - mal_assert(pDecoder != NULL); - mal_assert(pDecoder->onSeek != NULL); + ma_decoder* pDecoder = (ma_decoder*)pUserData; + ma_assert(pDecoder != NULL); + ma_assert(pDecoder->onSeek != NULL); - return pDecoder->onSeek(pDecoder, offset, (origin == drmp3_seek_origin_start) ? mal_seek_origin_start : mal_seek_origin_current); + return pDecoder->onSeek(pDecoder, offset, (origin == drmp3_seek_origin_start) ? ma_seek_origin_start : ma_seek_origin_current); } -mal_uint32 mal_decoder_internal_on_read_pcm_frames__mp3(mal_pcm_converter* pDSP, void* pSamplesOut, mal_uint32 frameCount, void* pUserData) +ma_uint32 ma_decoder_internal_on_read_pcm_frames__mp3(ma_pcm_converter* pDSP, void* pSamplesOut, ma_uint32 frameCount, void* pUserData) { (void)pDSP; - mal_decoder* pDecoder = (mal_decoder*)pUserData; - mal_assert(pDecoder != NULL); - mal_assert(pDecoder->internalFormat == mal_format_f32); + ma_decoder* pDecoder = (ma_decoder*)pUserData; + ma_assert(pDecoder != NULL); + ma_assert(pDecoder->internalFormat == ma_format_f32); drmp3* pMP3 = (drmp3*)pDecoder->pInternalDecoder; - mal_assert(pMP3 != NULL); + ma_assert(pMP3 != NULL); - return (mal_uint32)drmp3_read_pcm_frames_f32(pMP3, frameCount, (float*)pSamplesOut); + return (ma_uint32)drmp3_read_pcm_frames_f32(pMP3, frameCount, (float*)pSamplesOut); } -mal_result mal_decoder_internal_on_seek_to_pcm_frame__mp3(mal_decoder* pDecoder, mal_uint64 frameIndex) +ma_result ma_decoder_internal_on_seek_to_pcm_frame__mp3(ma_decoder* pDecoder, ma_uint64 frameIndex) { drmp3* pMP3 = (drmp3*)pDecoder->pInternalDecoder; - mal_assert(pMP3 != NULL); + ma_assert(pMP3 != NULL); drmp3_bool32 result = drmp3_seek_to_pcm_frame(pMP3, frameIndex); if (result) { @@ -30423,19 +30423,19 @@ mal_result mal_decoder_internal_on_seek_to_pcm_frame__mp3(mal_decoder* pDecoder, } } -mal_result mal_decoder_internal_on_uninit__mp3(mal_decoder* pDecoder) +ma_result ma_decoder_internal_on_uninit__mp3(ma_decoder* pDecoder) { drmp3_uninit((drmp3*)pDecoder->pInternalDecoder); - mal_free(pDecoder->pInternalDecoder); + ma_free(pDecoder->pInternalDecoder); return MA_SUCCESS; } -mal_result mal_decoder_init_mp3__internal(const mal_decoder_config* pConfig, mal_decoder* pDecoder) +ma_result ma_decoder_init_mp3__internal(const ma_decoder_config* pConfig, ma_decoder* pDecoder) { - mal_assert(pConfig != NULL); - mal_assert(pDecoder != NULL); + ma_assert(pConfig != NULL); + ma_assert(pDecoder != NULL); - drmp3* pMP3 = (drmp3*)mal_malloc(sizeof(*pMP3)); + drmp3* pMP3 = (drmp3*)ma_malloc(sizeof(*pMP3)); if (pMP3 == NULL) { return MA_OUT_OF_MEMORY; } @@ -30450,27 +30450,27 @@ mal_result mal_decoder_init_mp3__internal(const mal_decoder_config* pConfig, mal // // The internal channel count is always stereo, and the internal format is always f32. drmp3_config mp3Config; - mal_zero_object(&mp3Config); + ma_zero_object(&mp3Config); mp3Config.outputChannels = 2; mp3Config.outputSampleRate = (pConfig->sampleRate != 0) ? pConfig->sampleRate : 44100; - if (!drmp3_init(pMP3, mal_decoder_internal_on_read__mp3, mal_decoder_internal_on_seek__mp3, pDecoder, &mp3Config)) { + if (!drmp3_init(pMP3, ma_decoder_internal_on_read__mp3, ma_decoder_internal_on_seek__mp3, pDecoder, &mp3Config)) { return MA_ERROR; } - // If we get here it means we successfully initialized the MP3 decoder. We can now initialize the rest of the mal_decoder. - pDecoder->onSeekToPCMFrame = mal_decoder_internal_on_seek_to_pcm_frame__mp3; - pDecoder->onUninit = mal_decoder_internal_on_uninit__mp3; + // If we get here it means we successfully initialized the MP3 decoder. We can now initialize the rest of the ma_decoder. + pDecoder->onSeekToPCMFrame = ma_decoder_internal_on_seek_to_pcm_frame__mp3; + pDecoder->onUninit = ma_decoder_internal_on_uninit__mp3; pDecoder->pInternalDecoder = pMP3; // Internal format. - pDecoder->internalFormat = mal_format_f32; + pDecoder->internalFormat = ma_format_f32; pDecoder->internalChannels = pMP3->channels; pDecoder->internalSampleRate = pMP3->sampleRate; - mal_get_standard_channel_map(mal_standard_channel_map_default, pDecoder->internalChannels, pDecoder->internalChannelMap); + ma_get_standard_channel_map(ma_standard_channel_map_default, pDecoder->internalChannels, pDecoder->internalChannelMap); - mal_result result = mal_decoder__init_dsp(pDecoder, pConfig, mal_decoder_internal_on_read_pcm_frames__mp3); + ma_result result = ma_decoder__init_dsp(pDecoder, pConfig, ma_decoder_internal_on_read_pcm_frames__mp3); if (result != MA_SUCCESS) { - mal_free(pMP3); + ma_free(pMP3); return result; } @@ -30479,46 +30479,46 @@ mal_result mal_decoder_init_mp3__internal(const mal_decoder_config* pConfig, mal #endif // Raw -mal_uint32 mal_decoder_internal_on_read_pcm_frames__raw(mal_pcm_converter* pDSP, void* pSamplesOut, mal_uint32 frameCount, void* pUserData) +ma_uint32 ma_decoder_internal_on_read_pcm_frames__raw(ma_pcm_converter* pDSP, void* pSamplesOut, ma_uint32 frameCount, void* pUserData) { (void)pDSP; - mal_decoder* pDecoder = (mal_decoder*)pUserData; - mal_assert(pDecoder != NULL); + ma_decoder* pDecoder = (ma_decoder*)pUserData; + ma_assert(pDecoder != NULL); // For raw decoding we just read directly from the decoder's callbacks. - mal_uint32 bpf = mal_get_bytes_per_frame(pDecoder->internalFormat, pDecoder->internalChannels); - return (mal_uint32)pDecoder->onRead(pDecoder, pSamplesOut, frameCount * bpf) / bpf; + ma_uint32 bpf = ma_get_bytes_per_frame(pDecoder->internalFormat, pDecoder->internalChannels); + return (ma_uint32)pDecoder->onRead(pDecoder, pSamplesOut, frameCount * bpf) / bpf; } -mal_result mal_decoder_internal_on_seek_to_pcm_frame__raw(mal_decoder* pDecoder, mal_uint64 frameIndex) +ma_result ma_decoder_internal_on_seek_to_pcm_frame__raw(ma_decoder* pDecoder, ma_uint64 frameIndex) { - mal_assert(pDecoder != NULL); + ma_assert(pDecoder != NULL); if (pDecoder->onSeek == NULL) { return MA_ERROR; } - mal_bool32 result = MA_FALSE; + ma_bool32 result = MA_FALSE; // The callback uses a 32 bit integer whereas we use a 64 bit unsigned integer. We just need to continuously seek until we're at the correct position. - mal_uint64 totalBytesToSeek = frameIndex * mal_get_bytes_per_frame(pDecoder->internalFormat, pDecoder->internalChannels); + ma_uint64 totalBytesToSeek = frameIndex * ma_get_bytes_per_frame(pDecoder->internalFormat, pDecoder->internalChannels); if (totalBytesToSeek < 0x7FFFFFFF) { // Simple case. - result = pDecoder->onSeek(pDecoder, (int)(frameIndex * mal_get_bytes_per_frame(pDecoder->internalFormat, pDecoder->internalChannels)), mal_seek_origin_start); + result = pDecoder->onSeek(pDecoder, (int)(frameIndex * ma_get_bytes_per_frame(pDecoder->internalFormat, pDecoder->internalChannels)), ma_seek_origin_start); } else { // Complex case. Start by doing a seek relative to the start. Then keep looping using offset seeking. - result = pDecoder->onSeek(pDecoder, 0x7FFFFFFF, mal_seek_origin_start); + result = pDecoder->onSeek(pDecoder, 0x7FFFFFFF, ma_seek_origin_start); if (result == MA_TRUE) { totalBytesToSeek -= 0x7FFFFFFF; while (totalBytesToSeek > 0) { - mal_uint64 bytesToSeekThisIteration = totalBytesToSeek; + ma_uint64 bytesToSeekThisIteration = totalBytesToSeek; if (bytesToSeekThisIteration > 0x7FFFFFFF) { bytesToSeekThisIteration = 0x7FFFFFFF; } - result = pDecoder->onSeek(pDecoder, (int)bytesToSeekThisIteration, mal_seek_origin_current); + result = pDecoder->onSeek(pDecoder, (int)bytesToSeekThisIteration, ma_seek_origin_current); if (result != MA_TRUE) { break; } @@ -30535,28 +30535,28 @@ mal_result mal_decoder_internal_on_seek_to_pcm_frame__raw(mal_decoder* pDecoder, } } -mal_result mal_decoder_internal_on_uninit__raw(mal_decoder* pDecoder) +ma_result ma_decoder_internal_on_uninit__raw(ma_decoder* pDecoder) { (void)pDecoder; return MA_SUCCESS; } -mal_result mal_decoder_init_raw__internal(const mal_decoder_config* pConfigIn, const mal_decoder_config* pConfigOut, mal_decoder* pDecoder) +ma_result ma_decoder_init_raw__internal(const ma_decoder_config* pConfigIn, const ma_decoder_config* pConfigOut, ma_decoder* pDecoder) { - mal_assert(pConfigIn != NULL); - mal_assert(pConfigOut != NULL); - mal_assert(pDecoder != NULL); + ma_assert(pConfigIn != NULL); + ma_assert(pConfigOut != NULL); + ma_assert(pDecoder != NULL); - pDecoder->onSeekToPCMFrame = mal_decoder_internal_on_seek_to_pcm_frame__raw; - pDecoder->onUninit = mal_decoder_internal_on_uninit__raw; + pDecoder->onSeekToPCMFrame = ma_decoder_internal_on_seek_to_pcm_frame__raw; + pDecoder->onUninit = ma_decoder_internal_on_uninit__raw; // Internal format. pDecoder->internalFormat = pConfigIn->format; pDecoder->internalChannels = pConfigIn->channels; pDecoder->internalSampleRate = pConfigIn->sampleRate; - mal_channel_map_copy(pDecoder->internalChannelMap, pConfigIn->channelMap, pConfigIn->channels); + ma_channel_map_copy(pDecoder->internalChannelMap, pConfigIn->channelMap, pConfigIn->channels); - mal_result result = mal_decoder__init_dsp(pDecoder, pConfigOut, mal_decoder_internal_on_read_pcm_frames__raw); + ma_result result = ma_decoder__init_dsp(pDecoder, pConfigOut, ma_decoder_internal_on_read_pcm_frames__raw); if (result != MA_SUCCESS) { return result; } @@ -30564,15 +30564,15 @@ mal_result mal_decoder_init_raw__internal(const mal_decoder_config* pConfigIn, c return MA_SUCCESS; } -mal_result mal_decoder__preinit(mal_decoder_read_proc onRead, mal_decoder_seek_proc onSeek, void* pUserData, const mal_decoder_config* pConfig, mal_decoder* pDecoder) +ma_result ma_decoder__preinit(ma_decoder_read_proc onRead, ma_decoder_seek_proc onSeek, void* pUserData, const ma_decoder_config* pConfig, ma_decoder* pDecoder) { - mal_assert(pConfig != NULL); + ma_assert(pConfig != NULL); if (pDecoder == NULL) { return MA_INVALID_ARGS; } - mal_zero_object(pDecoder); + ma_zero_object(pDecoder); if (onRead == NULL || onSeek == NULL) { return MA_INVALID_ARGS; @@ -30586,86 +30586,86 @@ mal_result mal_decoder__preinit(mal_decoder_read_proc onRead, mal_decoder_seek_p return MA_SUCCESS; } -mal_result mal_decoder_init_wav(mal_decoder_read_proc onRead, mal_decoder_seek_proc onSeek, void* pUserData, const mal_decoder_config* pConfig, mal_decoder* pDecoder) +ma_result ma_decoder_init_wav(ma_decoder_read_proc onRead, ma_decoder_seek_proc onSeek, void* pUserData, const ma_decoder_config* pConfig, ma_decoder* pDecoder) { - mal_decoder_config config = mal_decoder_config_init_copy(pConfig); + ma_decoder_config config = ma_decoder_config_init_copy(pConfig); - mal_result result = mal_decoder__preinit(onRead, onSeek, pUserData, &config, pDecoder); + ma_result result = ma_decoder__preinit(onRead, onSeek, pUserData, &config, pDecoder); if (result != MA_SUCCESS) { return result; } #ifdef MA_HAS_WAV - return mal_decoder_init_wav__internal(&config, pDecoder); + return ma_decoder_init_wav__internal(&config, pDecoder); #else return MA_NO_BACKEND; #endif } -mal_result mal_decoder_init_flac(mal_decoder_read_proc onRead, mal_decoder_seek_proc onSeek, void* pUserData, const mal_decoder_config* pConfig, mal_decoder* pDecoder) +ma_result ma_decoder_init_flac(ma_decoder_read_proc onRead, ma_decoder_seek_proc onSeek, void* pUserData, const ma_decoder_config* pConfig, ma_decoder* pDecoder) { - mal_decoder_config config = mal_decoder_config_init_copy(pConfig); + ma_decoder_config config = ma_decoder_config_init_copy(pConfig); - mal_result result = mal_decoder__preinit(onRead, onSeek, pUserData, &config, pDecoder); + ma_result result = ma_decoder__preinit(onRead, onSeek, pUserData, &config, pDecoder); if (result != MA_SUCCESS) { return result; } #ifdef MA_HAS_FLAC - return mal_decoder_init_flac__internal(&config, pDecoder); + return ma_decoder_init_flac__internal(&config, pDecoder); #else return MA_NO_BACKEND; #endif } -mal_result mal_decoder_init_vorbis(mal_decoder_read_proc onRead, mal_decoder_seek_proc onSeek, void* pUserData, const mal_decoder_config* pConfig, mal_decoder* pDecoder) +ma_result ma_decoder_init_vorbis(ma_decoder_read_proc onRead, ma_decoder_seek_proc onSeek, void* pUserData, const ma_decoder_config* pConfig, ma_decoder* pDecoder) { - mal_decoder_config config = mal_decoder_config_init_copy(pConfig); + ma_decoder_config config = ma_decoder_config_init_copy(pConfig); - mal_result result = mal_decoder__preinit(onRead, onSeek, pUserData, &config, pDecoder); + ma_result result = ma_decoder__preinit(onRead, onSeek, pUserData, &config, pDecoder); if (result != MA_SUCCESS) { return result; } #ifdef MA_HAS_VORBIS - return mal_decoder_init_vorbis__internal(&config, pDecoder); + return ma_decoder_init_vorbis__internal(&config, pDecoder); #else return MA_NO_BACKEND; #endif } -mal_result mal_decoder_init_mp3(mal_decoder_read_proc onRead, mal_decoder_seek_proc onSeek, void* pUserData, const mal_decoder_config* pConfig, mal_decoder* pDecoder) +ma_result ma_decoder_init_mp3(ma_decoder_read_proc onRead, ma_decoder_seek_proc onSeek, void* pUserData, const ma_decoder_config* pConfig, ma_decoder* pDecoder) { - mal_decoder_config config = mal_decoder_config_init_copy(pConfig); + ma_decoder_config config = ma_decoder_config_init_copy(pConfig); - mal_result result = mal_decoder__preinit(onRead, onSeek, pUserData, &config, pDecoder); + ma_result result = ma_decoder__preinit(onRead, onSeek, pUserData, &config, pDecoder); if (result != MA_SUCCESS) { return result; } #ifdef MA_HAS_MP3 - return mal_decoder_init_mp3__internal(&config, pDecoder); + return ma_decoder_init_mp3__internal(&config, pDecoder); #else return MA_NO_BACKEND; #endif } -mal_result mal_decoder_init_raw(mal_decoder_read_proc onRead, mal_decoder_seek_proc onSeek, void* pUserData, const mal_decoder_config* pConfigIn, const mal_decoder_config* pConfigOut, mal_decoder* pDecoder) +ma_result ma_decoder_init_raw(ma_decoder_read_proc onRead, ma_decoder_seek_proc onSeek, void* pUserData, const ma_decoder_config* pConfigIn, const ma_decoder_config* pConfigOut, ma_decoder* pDecoder) { - mal_decoder_config config = mal_decoder_config_init_copy(pConfigOut); + ma_decoder_config config = ma_decoder_config_init_copy(pConfigOut); - mal_result result = mal_decoder__preinit(onRead, onSeek, pUserData, &config, pDecoder); + ma_result result = ma_decoder__preinit(onRead, onSeek, pUserData, &config, pDecoder); if (result != MA_SUCCESS) { return result; } - return mal_decoder_init_raw__internal(pConfigIn, &config, pDecoder); + return ma_decoder_init_raw__internal(pConfigIn, &config, pDecoder); } -mal_result mal_decoder_init__internal(mal_decoder_read_proc onRead, mal_decoder_seek_proc onSeek, void* pUserData, const mal_decoder_config* pConfig, mal_decoder* pDecoder) +ma_result ma_decoder_init__internal(ma_decoder_read_proc onRead, ma_decoder_seek_proc onSeek, void* pUserData, const ma_decoder_config* pConfig, ma_decoder* pDecoder) { - mal_assert(pConfig != NULL); - mal_assert(pDecoder != NULL); + ma_assert(pConfig != NULL); + ma_assert(pDecoder != NULL); // Silence some warnings in the case that we don't have any decoder backends enabled. (void)onRead; @@ -30675,37 +30675,37 @@ mal_result mal_decoder_init__internal(mal_decoder_read_proc onRead, mal_decoder_ (void)pDecoder; // We use trial and error to open a decoder. - mal_result result = MA_NO_BACKEND; + ma_result result = MA_NO_BACKEND; #ifdef MA_HAS_WAV if (result != MA_SUCCESS) { - result = mal_decoder_init_wav__internal(pConfig, pDecoder); + result = ma_decoder_init_wav__internal(pConfig, pDecoder); if (result != MA_SUCCESS) { - onSeek(pDecoder, 0, mal_seek_origin_start); + onSeek(pDecoder, 0, ma_seek_origin_start); } } #endif #ifdef MA_HAS_FLAC if (result != MA_SUCCESS) { - result = mal_decoder_init_flac__internal(pConfig, pDecoder); + result = ma_decoder_init_flac__internal(pConfig, pDecoder); if (result != MA_SUCCESS) { - onSeek(pDecoder, 0, mal_seek_origin_start); + onSeek(pDecoder, 0, ma_seek_origin_start); } } #endif #ifdef MA_HAS_VORBIS if (result != MA_SUCCESS) { - result = mal_decoder_init_vorbis__internal(pConfig, pDecoder); + result = ma_decoder_init_vorbis__internal(pConfig, pDecoder); if (result != MA_SUCCESS) { - onSeek(pDecoder, 0, mal_seek_origin_start); + onSeek(pDecoder, 0, ma_seek_origin_start); } } #endif #ifdef MA_HAS_MP3 if (result != MA_SUCCESS) { - result = mal_decoder_init_mp3__internal(pConfig, pDecoder); + result = ma_decoder_init_mp3__internal(pConfig, pDecoder); if (result != MA_SUCCESS) { - onSeek(pDecoder, 0, mal_seek_origin_start); + onSeek(pDecoder, 0, ma_seek_origin_start); } } #endif @@ -30717,22 +30717,22 @@ mal_result mal_decoder_init__internal(mal_decoder_read_proc onRead, mal_decoder_ return result; } -mal_result mal_decoder_init(mal_decoder_read_proc onRead, mal_decoder_seek_proc onSeek, void* pUserData, const mal_decoder_config* pConfig, mal_decoder* pDecoder) +ma_result ma_decoder_init(ma_decoder_read_proc onRead, ma_decoder_seek_proc onSeek, void* pUserData, const ma_decoder_config* pConfig, ma_decoder* pDecoder) { - mal_decoder_config config = mal_decoder_config_init_copy(pConfig); + ma_decoder_config config = ma_decoder_config_init_copy(pConfig); - mal_result result = mal_decoder__preinit(onRead, onSeek, pUserData, &config, pDecoder); + ma_result result = ma_decoder__preinit(onRead, onSeek, pUserData, &config, pDecoder); if (result != MA_SUCCESS) { return result; } - return mal_decoder_init__internal(onRead, onSeek, pUserData, &config, pDecoder); + return ma_decoder_init__internal(onRead, onSeek, pUserData, &config, pDecoder); } -size_t mal_decoder__on_read_memory(mal_decoder* pDecoder, void* pBufferOut, size_t bytesToRead) +size_t ma_decoder__on_read_memory(ma_decoder* pDecoder, void* pBufferOut, size_t bytesToRead) { - mal_assert(pDecoder->memory.dataSize >= pDecoder->memory.currentReadPos); + ma_assert(pDecoder->memory.dataSize >= pDecoder->memory.currentReadPos); size_t bytesRemaining = pDecoder->memory.dataSize - pDecoder->memory.currentReadPos; if (bytesToRead > bytesRemaining) { @@ -30740,16 +30740,16 @@ size_t mal_decoder__on_read_memory(mal_decoder* pDecoder, void* pBufferOut, size } if (bytesToRead > 0) { - mal_copy_memory(pBufferOut, pDecoder->memory.pData + pDecoder->memory.currentReadPos, bytesToRead); + ma_copy_memory(pBufferOut, pDecoder->memory.pData + pDecoder->memory.currentReadPos, bytesToRead); pDecoder->memory.currentReadPos += bytesToRead; } return bytesToRead; } -mal_bool32 mal_decoder__on_seek_memory(mal_decoder* pDecoder, int byteOffset, mal_seek_origin origin) +ma_bool32 ma_decoder__on_seek_memory(ma_decoder* pDecoder, int byteOffset, ma_seek_origin origin) { - if (origin == mal_seek_origin_current) { + if (origin == ma_seek_origin_current) { if (byteOffset > 0) { if (pDecoder->memory.currentReadPos + byteOffset > pDecoder->memory.dataSize) { byteOffset = (int)(pDecoder->memory.dataSize - pDecoder->memory.currentReadPos); // Trying to seek too far forward. @@ -30763,7 +30763,7 @@ mal_bool32 mal_decoder__on_seek_memory(mal_decoder* pDecoder, int byteOffset, ma // This will never underflow thanks to the clamps above. pDecoder->memory.currentReadPos += byteOffset; } else { - if ((mal_uint32)byteOffset <= pDecoder->memory.dataSize) { + if ((ma_uint32)byteOffset <= pDecoder->memory.dataSize) { pDecoder->memory.currentReadPos = byteOffset; } else { pDecoder->memory.currentReadPos = pDecoder->memory.dataSize; // Trying to seek too far forward. @@ -30773,9 +30773,9 @@ mal_bool32 mal_decoder__on_seek_memory(mal_decoder* pDecoder, int byteOffset, ma return MA_TRUE; } -mal_result mal_decoder__preinit_memory(const void* pData, size_t dataSize, const mal_decoder_config* pConfig, mal_decoder* pDecoder) +ma_result ma_decoder__preinit_memory(const void* pData, size_t dataSize, const ma_decoder_config* pConfig, ma_decoder* pDecoder) { - mal_result result = mal_decoder__preinit(mal_decoder__on_read_memory, mal_decoder__on_seek_memory, NULL, pConfig, pDecoder); + ma_result result = ma_decoder__preinit(ma_decoder__on_read_memory, ma_decoder__on_seek_memory, NULL, pConfig, pDecoder); if (result != MA_SUCCESS) { return result; } @@ -30784,7 +30784,7 @@ mal_result mal_decoder__preinit_memory(const void* pData, size_t dataSize, const return MA_INVALID_ARGS; } - pDecoder->memory.pData = (const mal_uint8*)pData; + pDecoder->memory.pData = (const ma_uint8*)pData; pDecoder->memory.dataSize = dataSize; pDecoder->memory.currentReadPos = 0; @@ -30792,92 +30792,92 @@ mal_result mal_decoder__preinit_memory(const void* pData, size_t dataSize, const return MA_SUCCESS; } -mal_result mal_decoder_init_memory(const void* pData, size_t dataSize, const mal_decoder_config* pConfig, mal_decoder* pDecoder) +ma_result ma_decoder_init_memory(const void* pData, size_t dataSize, const ma_decoder_config* pConfig, ma_decoder* pDecoder) { - mal_decoder_config config = mal_decoder_config_init_copy(pConfig); // Make sure the config is not NULL. + ma_decoder_config config = ma_decoder_config_init_copy(pConfig); // Make sure the config is not NULL. - mal_result result = mal_decoder__preinit_memory(pData, dataSize, &config, pDecoder); + ma_result result = ma_decoder__preinit_memory(pData, dataSize, &config, pDecoder); if (result != MA_SUCCESS) { return result; } - return mal_decoder_init__internal(mal_decoder__on_read_memory, mal_decoder__on_seek_memory, NULL, &config, pDecoder); + return ma_decoder_init__internal(ma_decoder__on_read_memory, ma_decoder__on_seek_memory, NULL, &config, pDecoder); } -mal_result mal_decoder_init_memory_wav(const void* pData, size_t dataSize, const mal_decoder_config* pConfig, mal_decoder* pDecoder) +ma_result ma_decoder_init_memory_wav(const void* pData, size_t dataSize, const ma_decoder_config* pConfig, ma_decoder* pDecoder) { - mal_decoder_config config = mal_decoder_config_init_copy(pConfig); // Make sure the config is not NULL. + ma_decoder_config config = ma_decoder_config_init_copy(pConfig); // Make sure the config is not NULL. - mal_result result = mal_decoder__preinit_memory(pData, dataSize, &config, pDecoder); + ma_result result = ma_decoder__preinit_memory(pData, dataSize, &config, pDecoder); if (result != MA_SUCCESS) { return result; } #ifdef MA_HAS_WAV - return mal_decoder_init_wav__internal(&config, pDecoder); + return ma_decoder_init_wav__internal(&config, pDecoder); #else return MA_NO_BACKEND; #endif } -mal_result mal_decoder_init_memory_flac(const void* pData, size_t dataSize, const mal_decoder_config* pConfig, mal_decoder* pDecoder) +ma_result ma_decoder_init_memory_flac(const void* pData, size_t dataSize, const ma_decoder_config* pConfig, ma_decoder* pDecoder) { - mal_decoder_config config = mal_decoder_config_init_copy(pConfig); // Make sure the config is not NULL. + ma_decoder_config config = ma_decoder_config_init_copy(pConfig); // Make sure the config is not NULL. - mal_result result = mal_decoder__preinit_memory(pData, dataSize, &config, pDecoder); + ma_result result = ma_decoder__preinit_memory(pData, dataSize, &config, pDecoder); if (result != MA_SUCCESS) { return result; } #ifdef MA_HAS_FLAC - return mal_decoder_init_flac__internal(&config, pDecoder); + return ma_decoder_init_flac__internal(&config, pDecoder); #else return MA_NO_BACKEND; #endif } -mal_result mal_decoder_init_memory_vorbis(const void* pData, size_t dataSize, const mal_decoder_config* pConfig, mal_decoder* pDecoder) +ma_result ma_decoder_init_memory_vorbis(const void* pData, size_t dataSize, const ma_decoder_config* pConfig, ma_decoder* pDecoder) { - mal_decoder_config config = mal_decoder_config_init_copy(pConfig); // Make sure the config is not NULL. + ma_decoder_config config = ma_decoder_config_init_copy(pConfig); // Make sure the config is not NULL. - mal_result result = mal_decoder__preinit_memory(pData, dataSize, &config, pDecoder); + ma_result result = ma_decoder__preinit_memory(pData, dataSize, &config, pDecoder); if (result != MA_SUCCESS) { return result; } #ifdef MA_HAS_VORBIS - return mal_decoder_init_vorbis__internal(&config, pDecoder); + return ma_decoder_init_vorbis__internal(&config, pDecoder); #else return MA_NO_BACKEND; #endif } -mal_result mal_decoder_init_memory_mp3(const void* pData, size_t dataSize, const mal_decoder_config* pConfig, mal_decoder* pDecoder) +ma_result ma_decoder_init_memory_mp3(const void* pData, size_t dataSize, const ma_decoder_config* pConfig, ma_decoder* pDecoder) { - mal_decoder_config config = mal_decoder_config_init_copy(pConfig); // Make sure the config is not NULL. + ma_decoder_config config = ma_decoder_config_init_copy(pConfig); // Make sure the config is not NULL. - mal_result result = mal_decoder__preinit_memory(pData, dataSize, &config, pDecoder); + ma_result result = ma_decoder__preinit_memory(pData, dataSize, &config, pDecoder); if (result != MA_SUCCESS) { return result; } #ifdef MA_HAS_MP3 - return mal_decoder_init_mp3__internal(&config, pDecoder); + return ma_decoder_init_mp3__internal(&config, pDecoder); #else return MA_NO_BACKEND; #endif } -mal_result mal_decoder_init_memory_raw(const void* pData, size_t dataSize, const mal_decoder_config* pConfigIn, const mal_decoder_config* pConfigOut, mal_decoder* pDecoder) +ma_result ma_decoder_init_memory_raw(const void* pData, size_t dataSize, const ma_decoder_config* pConfigIn, const ma_decoder_config* pConfigOut, ma_decoder* pDecoder) { - mal_decoder_config config = mal_decoder_config_init_copy(pConfigOut); // Make sure the config is not NULL. + ma_decoder_config config = ma_decoder_config_init_copy(pConfigOut); // Make sure the config is not NULL. - mal_result result = mal_decoder__preinit_memory(pData, dataSize, &config, pDecoder); + ma_result result = ma_decoder__preinit_memory(pData, dataSize, &config, pDecoder); if (result != MA_SUCCESS) { return result; } - return mal_decoder_init_raw__internal(pConfigIn, &config, pDecoder); + return ma_decoder_init_raw__internal(pConfigIn, &config, pDecoder); } #ifndef MA_NO_STDIO @@ -30886,7 +30886,7 @@ mal_result mal_decoder_init_memory_raw(const void* pData, size_t dataSize, const #include // For strcasecmp(). #endif -const char* mal_path_file_name(const char* path) +const char* ma_path_file_name(const char* path) { if (path == NULL) { return NULL; @@ -30911,13 +30911,13 @@ const char* mal_path_file_name(const char* path) return fileName; } -const char* mal_path_extension(const char* path) +const char* ma_path_extension(const char* path) { if (path == NULL) { path = ""; } - const char* extension = mal_path_file_name(path); + const char* extension = ma_path_file_name(path); const char* lastOccurance = NULL; // Just find the last '.' and return. @@ -30933,14 +30933,14 @@ const char* mal_path_extension(const char* path) return (lastOccurance != NULL) ? lastOccurance : extension; } -mal_bool32 mal_path_extension_equal(const char* path, const char* extension) +ma_bool32 ma_path_extension_equal(const char* path, const char* extension) { if (path == NULL || extension == NULL) { return MA_FALSE; } const char* ext1 = extension; - const char* ext2 = mal_path_extension(path); + const char* ext2 = ma_path_extension(path); #if defined(_MSC_VER) || defined(__DMC__) return _stricmp(ext1, ext2) == 0; @@ -30949,23 +30949,23 @@ mal_bool32 mal_path_extension_equal(const char* path, const char* extension) #endif } -size_t mal_decoder__on_read_stdio(mal_decoder* pDecoder, void* pBufferOut, size_t bytesToRead) +size_t ma_decoder__on_read_stdio(ma_decoder* pDecoder, void* pBufferOut, size_t bytesToRead) { return fread(pBufferOut, 1, bytesToRead, (FILE*)pDecoder->pUserData); } -mal_bool32 mal_decoder__on_seek_stdio(mal_decoder* pDecoder, int byteOffset, mal_seek_origin origin) +ma_bool32 ma_decoder__on_seek_stdio(ma_decoder* pDecoder, int byteOffset, ma_seek_origin origin) { - return fseek((FILE*)pDecoder->pUserData, byteOffset, (origin == mal_seek_origin_current) ? SEEK_CUR : SEEK_SET) == 0; + return fseek((FILE*)pDecoder->pUserData, byteOffset, (origin == ma_seek_origin_current) ? SEEK_CUR : SEEK_SET) == 0; } -mal_result mal_decoder__preinit_file(const char* pFilePath, const mal_decoder_config* pConfig, mal_decoder* pDecoder) +ma_result ma_decoder__preinit_file(const char* pFilePath, const ma_decoder_config* pConfig, ma_decoder* pDecoder) { if (pDecoder == NULL) { return MA_INVALID_ARGS; } - mal_zero_object(pDecoder); + ma_zero_object(pDecoder); if (pFilePath == NULL || pFilePath[0] == '\0') { return MA_INVALID_ARGS; @@ -30983,96 +30983,96 @@ mal_result mal_decoder__preinit_file(const char* pFilePath, const mal_decoder_co } #endif - // We need to manually set the user data so the calls to mal_decoder__on_seek_stdio() succeed. + // We need to manually set the user data so the calls to ma_decoder__on_seek_stdio() succeed. pDecoder->pUserData = pFile; (void)pConfig; return MA_SUCCESS; } -mal_result mal_decoder_init_file(const char* pFilePath, const mal_decoder_config* pConfig, mal_decoder* pDecoder) +ma_result ma_decoder_init_file(const char* pFilePath, const ma_decoder_config* pConfig, ma_decoder* pDecoder) { - mal_result result = mal_decoder__preinit_file(pFilePath, pConfig, pDecoder); // This sets pDecoder->pUserData to a FILE*. + ma_result result = ma_decoder__preinit_file(pFilePath, pConfig, pDecoder); // This sets pDecoder->pUserData to a FILE*. if (result != MA_SUCCESS) { return result; } // WAV - if (mal_path_extension_equal(pFilePath, "wav")) { - result = mal_decoder_init_wav(mal_decoder__on_read_stdio, mal_decoder__on_seek_stdio, pDecoder->pUserData, pConfig, pDecoder); + if (ma_path_extension_equal(pFilePath, "wav")) { + result = ma_decoder_init_wav(ma_decoder__on_read_stdio, ma_decoder__on_seek_stdio, pDecoder->pUserData, pConfig, pDecoder); if (result == MA_SUCCESS) { return MA_SUCCESS; } - mal_decoder__on_seek_stdio(pDecoder, 0, mal_seek_origin_start); + ma_decoder__on_seek_stdio(pDecoder, 0, ma_seek_origin_start); } // FLAC - if (mal_path_extension_equal(pFilePath, "flac")) { - result = mal_decoder_init_flac(mal_decoder__on_read_stdio, mal_decoder__on_seek_stdio, pDecoder->pUserData, pConfig, pDecoder); + if (ma_path_extension_equal(pFilePath, "flac")) { + result = ma_decoder_init_flac(ma_decoder__on_read_stdio, ma_decoder__on_seek_stdio, pDecoder->pUserData, pConfig, pDecoder); if (result == MA_SUCCESS) { return MA_SUCCESS; } - mal_decoder__on_seek_stdio(pDecoder, 0, mal_seek_origin_start); + ma_decoder__on_seek_stdio(pDecoder, 0, ma_seek_origin_start); } // MP3 - if (mal_path_extension_equal(pFilePath, "mp3")) { - result = mal_decoder_init_mp3(mal_decoder__on_read_stdio, mal_decoder__on_seek_stdio, pDecoder->pUserData, pConfig, pDecoder); + if (ma_path_extension_equal(pFilePath, "mp3")) { + result = ma_decoder_init_mp3(ma_decoder__on_read_stdio, ma_decoder__on_seek_stdio, pDecoder->pUserData, pConfig, pDecoder); if (result == MA_SUCCESS) { return MA_SUCCESS; } - mal_decoder__on_seek_stdio(pDecoder, 0, mal_seek_origin_start); + ma_decoder__on_seek_stdio(pDecoder, 0, ma_seek_origin_start); } // Trial and error. - return mal_decoder_init(mal_decoder__on_read_stdio, mal_decoder__on_seek_stdio, pDecoder->pUserData, pConfig, pDecoder); + return ma_decoder_init(ma_decoder__on_read_stdio, ma_decoder__on_seek_stdio, pDecoder->pUserData, pConfig, pDecoder); } -mal_result mal_decoder_init_file_wav(const char* pFilePath, const mal_decoder_config* pConfig, mal_decoder* pDecoder) +ma_result ma_decoder_init_file_wav(const char* pFilePath, const ma_decoder_config* pConfig, ma_decoder* pDecoder) { - mal_result result = mal_decoder__preinit_file(pFilePath, pConfig, pDecoder); + ma_result result = ma_decoder__preinit_file(pFilePath, pConfig, pDecoder); if (result != MA_SUCCESS) { return result; } - return mal_decoder_init_wav(mal_decoder__on_read_stdio, mal_decoder__on_seek_stdio, pDecoder->pUserData, pConfig, pDecoder); + return ma_decoder_init_wav(ma_decoder__on_read_stdio, ma_decoder__on_seek_stdio, pDecoder->pUserData, pConfig, pDecoder); } -mal_result mal_decoder_init_file_flac(const char* pFilePath, const mal_decoder_config* pConfig, mal_decoder* pDecoder) +ma_result ma_decoder_init_file_flac(const char* pFilePath, const ma_decoder_config* pConfig, ma_decoder* pDecoder) { - mal_result result = mal_decoder__preinit_file(pFilePath, pConfig, pDecoder); + ma_result result = ma_decoder__preinit_file(pFilePath, pConfig, pDecoder); if (result != MA_SUCCESS) { return result; } - return mal_decoder_init_flac(mal_decoder__on_read_stdio, mal_decoder__on_seek_stdio, pDecoder->pUserData, pConfig, pDecoder); + return ma_decoder_init_flac(ma_decoder__on_read_stdio, ma_decoder__on_seek_stdio, pDecoder->pUserData, pConfig, pDecoder); } -mal_result mal_decoder_init_file_vorbis(const char* pFilePath, const mal_decoder_config* pConfig, mal_decoder* pDecoder) +ma_result ma_decoder_init_file_vorbis(const char* pFilePath, const ma_decoder_config* pConfig, ma_decoder* pDecoder) { - mal_result result = mal_decoder__preinit_file(pFilePath, pConfig, pDecoder); + ma_result result = ma_decoder__preinit_file(pFilePath, pConfig, pDecoder); if (result != MA_SUCCESS) { return result; } - return mal_decoder_init_vorbis(mal_decoder__on_read_stdio, mal_decoder__on_seek_stdio, pDecoder->pUserData, pConfig, pDecoder); + return ma_decoder_init_vorbis(ma_decoder__on_read_stdio, ma_decoder__on_seek_stdio, pDecoder->pUserData, pConfig, pDecoder); } -mal_result mal_decoder_init_file_mp3(const char* pFilePath, const mal_decoder_config* pConfig, mal_decoder* pDecoder) +ma_result ma_decoder_init_file_mp3(const char* pFilePath, const ma_decoder_config* pConfig, ma_decoder* pDecoder) { - mal_result result = mal_decoder__preinit_file(pFilePath, pConfig, pDecoder); + ma_result result = ma_decoder__preinit_file(pFilePath, pConfig, pDecoder); if (result != MA_SUCCESS) { return result; } - return mal_decoder_init_mp3(mal_decoder__on_read_stdio, mal_decoder__on_seek_stdio, pDecoder->pUserData, pConfig, pDecoder); + return ma_decoder_init_mp3(ma_decoder__on_read_stdio, ma_decoder__on_seek_stdio, pDecoder->pUserData, pConfig, pDecoder); } #endif -mal_result mal_decoder_uninit(mal_decoder* pDecoder) +ma_result ma_decoder_uninit(ma_decoder* pDecoder) { if (pDecoder == NULL) { return MA_INVALID_ARGS; @@ -31084,7 +31084,7 @@ mal_result mal_decoder_uninit(mal_decoder* pDecoder) #ifndef MA_NO_STDIO // If we have a file handle, close it. - if (pDecoder->onRead == mal_decoder__on_read_stdio) { + if (pDecoder->onRead == ma_decoder__on_read_stdio) { fclose((FILE*)pDecoder->pUserData); } #endif @@ -31092,14 +31092,14 @@ mal_result mal_decoder_uninit(mal_decoder* pDecoder) return MA_SUCCESS; } -mal_uint64 mal_decoder_read_pcm_frames(mal_decoder* pDecoder, void* pFramesOut, mal_uint64 frameCount) +ma_uint64 ma_decoder_read_pcm_frames(ma_decoder* pDecoder, void* pFramesOut, ma_uint64 frameCount) { if (pDecoder == NULL) return 0; - return mal_pcm_converter_read(&pDecoder->dsp, pFramesOut, frameCount); + return ma_pcm_converter_read(&pDecoder->dsp, pFramesOut, frameCount); } -mal_result mal_decoder_seek_to_pcm_frame(mal_decoder* pDecoder, mal_uint64 frameIndex) +ma_result ma_decoder_seek_to_pcm_frame(ma_decoder* pDecoder, ma_uint64 frameIndex) { if (pDecoder == NULL) return 0; @@ -31112,33 +31112,33 @@ mal_result mal_decoder_seek_to_pcm_frame(mal_decoder* pDecoder, mal_uint64 frame } -mal_result mal_decoder__full_decode_and_uninit(mal_decoder* pDecoder, mal_decoder_config* pConfigOut, mal_uint64* pFrameCountOut, void** ppPCMFramesOut) +ma_result ma_decoder__full_decode_and_uninit(ma_decoder* pDecoder, ma_decoder_config* pConfigOut, ma_uint64* pFrameCountOut, void** ppPCMFramesOut) { - mal_assert(pDecoder != NULL); + ma_assert(pDecoder != NULL); - mal_uint64 totalFrameCount = 0; - mal_uint64 bpf = mal_get_bytes_per_frame(pDecoder->outputFormat, pDecoder->outputChannels); + ma_uint64 totalFrameCount = 0; + ma_uint64 bpf = ma_get_bytes_per_frame(pDecoder->outputFormat, pDecoder->outputChannels); // The frame count is unknown until we try reading. Thus, we just run in a loop. - mal_uint64 dataCapInFrames = 0; + ma_uint64 dataCapInFrames = 0; void* pPCMFramesOut = NULL; for (;;) { // Make room if there's not enough. if (totalFrameCount == dataCapInFrames) { - mal_uint64 newDataCapInFrames = dataCapInFrames*2; + ma_uint64 newDataCapInFrames = dataCapInFrames*2; if (newDataCapInFrames == 0) { newDataCapInFrames = 4096; } if ((newDataCapInFrames * bpf) > MA_SIZE_MAX) { - mal_free(pPCMFramesOut); + ma_free(pPCMFramesOut); return MA_TOO_LARGE; } - void* pNewPCMFramesOut = (void*)mal_realloc(pPCMFramesOut, (size_t)(newDataCapInFrames * bpf)); + void* pNewPCMFramesOut = (void*)ma_realloc(pPCMFramesOut, (size_t)(newDataCapInFrames * bpf)); if (pNewPCMFramesOut == NULL) { - mal_free(pPCMFramesOut); + ma_free(pPCMFramesOut); return MA_OUT_OF_MEMORY; } @@ -31146,10 +31146,10 @@ mal_result mal_decoder__full_decode_and_uninit(mal_decoder* pDecoder, mal_decode pPCMFramesOut = pNewPCMFramesOut; } - mal_uint64 frameCountToTryReading = dataCapInFrames - totalFrameCount; - mal_assert(frameCountToTryReading > 0); + ma_uint64 frameCountToTryReading = dataCapInFrames - totalFrameCount; + ma_assert(frameCountToTryReading > 0); - mal_uint64 framesJustRead = mal_decoder_read_pcm_frames(pDecoder, (mal_uint8*)pPCMFramesOut + (totalFrameCount * bpf), frameCountToTryReading); + ma_uint64 framesJustRead = ma_decoder_read_pcm_frames(pDecoder, (ma_uint8*)pPCMFramesOut + (totalFrameCount * bpf), frameCountToTryReading); totalFrameCount += framesJustRead; if (framesJustRead < frameCountToTryReading) { @@ -31162,25 +31162,25 @@ mal_result mal_decoder__full_decode_and_uninit(mal_decoder* pDecoder, mal_decode pConfigOut->format = pDecoder->outputFormat; pConfigOut->channels = pDecoder->outputChannels; pConfigOut->sampleRate = pDecoder->outputSampleRate; - mal_channel_map_copy(pConfigOut->channelMap, pDecoder->outputChannelMap, pDecoder->outputChannels); + ma_channel_map_copy(pConfigOut->channelMap, pDecoder->outputChannelMap, pDecoder->outputChannels); } if (ppPCMFramesOut != NULL) { *ppPCMFramesOut = pPCMFramesOut; } else { - mal_free(pPCMFramesOut); + ma_free(pPCMFramesOut); } if (pFrameCountOut != NULL) { *pFrameCountOut = totalFrameCount; } - mal_decoder_uninit(pDecoder); + ma_decoder_uninit(pDecoder); return MA_SUCCESS; } #ifndef MA_NO_STDIO -mal_result mal_decode_file(const char* pFilePath, mal_decoder_config* pConfig, mal_uint64* pFrameCountOut, void** ppPCMFramesOut) +ma_result ma_decode_file(const char* pFilePath, ma_decoder_config* pConfig, ma_uint64* pFrameCountOut, void** ppPCMFramesOut) { if (pFrameCountOut != NULL) { *pFrameCountOut = 0; @@ -31193,19 +31193,19 @@ mal_result mal_decode_file(const char* pFilePath, mal_decoder_config* pConfig, m return MA_INVALID_ARGS; } - mal_decoder_config config = mal_decoder_config_init_copy(pConfig); + ma_decoder_config config = ma_decoder_config_init_copy(pConfig); - mal_decoder decoder; - mal_result result = mal_decoder_init_file(pFilePath, &config, &decoder); + ma_decoder decoder; + ma_result result = ma_decoder_init_file(pFilePath, &config, &decoder); if (result != MA_SUCCESS) { return result; } - return mal_decoder__full_decode_and_uninit(&decoder, pConfig, pFrameCountOut, ppPCMFramesOut); + return ma_decoder__full_decode_and_uninit(&decoder, pConfig, pFrameCountOut, ppPCMFramesOut); } #endif -mal_result mal_decode_memory(const void* pData, size_t dataSize, mal_decoder_config* pConfig, mal_uint64* pFrameCountOut, void** ppPCMFramesOut) +ma_result ma_decode_memory(const void* pData, size_t dataSize, ma_decoder_config* pConfig, ma_uint64* pFrameCountOut, void** ppPCMFramesOut) { if (pFrameCountOut != NULL) { *pFrameCountOut = 0; @@ -31218,15 +31218,15 @@ mal_result mal_decode_memory(const void* pData, size_t dataSize, mal_decoder_con return MA_INVALID_ARGS; } - mal_decoder_config config = mal_decoder_config_init_copy(pConfig); + ma_decoder_config config = ma_decoder_config_init_copy(pConfig); - mal_decoder decoder; - mal_result result = mal_decoder_init_memory(pData, dataSize, &config, &decoder); + ma_decoder decoder; + ma_result result = ma_decoder_init_memory(pData, dataSize, &config, &decoder); if (result != MA_SUCCESS) { return result; } - return mal_decoder__full_decode_and_uninit(&decoder, pConfig, pFrameCountOut, ppPCMFramesOut); + return ma_decoder__full_decode_and_uninit(&decoder, pConfig, pFrameCountOut, ppPCMFramesOut); } #endif // MA_NO_DECODING @@ -31242,12 +31242,12 @@ mal_result mal_decode_memory(const void* pData, size_t dataSize, mal_decoder_con ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -mal_result mal_sine_wave_init(double amplitude, double periodsPerSecond, mal_uint32 sampleRate, mal_sine_wave* pSineWave) +ma_result ma_sine_wave_init(double amplitude, double periodsPerSecond, ma_uint32 sampleRate, ma_sine_wave* pSineWave) { if (pSineWave == NULL) { return MA_INVALID_ARGS; } - mal_zero_object(pSineWave); + ma_zero_object(pSineWave); if (amplitude == 0 || periodsPerSecond == 0) { return MA_INVALID_ARGS; @@ -31268,28 +31268,28 @@ mal_result mal_sine_wave_init(double amplitude, double periodsPerSecond, mal_uin return MA_SUCCESS; } -mal_uint64 mal_sine_wave_read_f32(mal_sine_wave* pSineWave, mal_uint64 count, float* pSamples) +ma_uint64 ma_sine_wave_read_f32(ma_sine_wave* pSineWave, ma_uint64 count, float* pSamples) { - return mal_sine_wave_read_f32_ex(pSineWave, count, 1, mal_stream_layout_interleaved, &pSamples); + return ma_sine_wave_read_f32_ex(pSineWave, count, 1, ma_stream_layout_interleaved, &pSamples); } -mal_uint64 mal_sine_wave_read_f32_ex(mal_sine_wave* pSineWave, mal_uint64 frameCount, mal_uint32 channels, mal_stream_layout layout, float** ppFrames) +ma_uint64 ma_sine_wave_read_f32_ex(ma_sine_wave* pSineWave, ma_uint64 frameCount, ma_uint32 channels, ma_stream_layout layout, float** ppFrames) { if (pSineWave == NULL) { return 0; } if (ppFrames != NULL) { - for (mal_uint64 iFrame = 0; iFrame < frameCount; iFrame += 1) { + for (ma_uint64 iFrame = 0; iFrame < frameCount; iFrame += 1) { float s = (float)(sin(pSineWave->time * pSineWave->periodsPerSecond) * pSineWave->amplitude); pSineWave->time += pSineWave->delta; - if (layout == mal_stream_layout_interleaved) { - for (mal_uint32 iChannel = 0; iChannel < channels; iChannel += 1) { + if (layout == ma_stream_layout_interleaved) { + for (ma_uint32 iChannel = 0; iChannel < channels; iChannel += 1) { ppFrames[0][iFrame*channels + iChannel] = s; } } else { - for (mal_uint32 iChannel = 0; iChannel < channels; iChannel += 1) { + for (ma_uint32 iChannel = 0; iChannel < channels; iChannel += 1) { ppFrames[iChannel][iFrame] = s; } } @@ -31317,7 +31317,7 @@ Context Device ------ -- If a full-duplex device is requested and the backend does not support full duplex devices, have mal_device_init__[backend]() +- If a full-duplex device is requested and the backend does not support full duplex devices, have ma_device_init__[backend]() return MA_DEVICE_TYPE_NOT_SUPPORTED. - If exclusive mode is requested, but the backend does not support it, return MA_SHARE_MODE_NOT_SUPPORTED. If practical, try not to fall back to a different share mode - give the client exactly what they asked for. Some backends, such as ALSA, may @@ -31326,7 +31326,7 @@ Device value from the config. - If the configs buffer size in frames is 0, set it based on the buffer size in milliseconds, keeping in mind to handle the case when the default sample rate is being used where practical. -- Backends must set the following members of pDevice before returning successfully from mal_device_init__[backend](): +- Backends must set the following members of pDevice before returning successfully from ma_device_init__[backend](): - internalFormat - internalChannels - internalSampleRate @@ -31340,12 +31340,12 @@ REVISION HISTORY ================ v0.9 - 2019-03-xx - - API CHANGE: mal_device_init() and mal_device_config_init() have changed significantly: - - The device type, device ID and user data pointer have moved from mal_device_init() to the config. - - All variations of mal_device_config_init_*() have been removed in favor of just mal_device_config_init(). - - mal_device_config_init() now takes only one parameter which is the device type. All other properties need + - API CHANGE: ma_device_init() and ma_device_config_init() have changed significantly: + - The device type, device ID and user data pointer have moved from ma_device_init() to the config. + - All variations of ma_device_config_init_*() have been removed in favor of just ma_device_config_init(). + - ma_device_config_init() now takes only one parameter which is the device type. All other properties need to be set on the returned object directly. - - The onDataCallback and onStopCallback members of mal_device_config have been renamed to "dataCallback" + - The onDataCallback and onStopCallback members of ma_device_config have been renamed to "dataCallback" and "stopCallback". - The ID of the physical device is now split into two: one for the playback device and the other for the capture device. This is required for full-duplex. These are named "pPlaybackDeviceID" and "pCaptureDeviceID". @@ -31353,40 +31353,40 @@ v0.9 - 2019-03-xx being separate for each. It now takes two pointers - one containing input data and the other output data. This design in required for full-duplex. The return value is now void instead of the number of frames written. The new callback looks like the following: - void data_callback(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 frameCount); - - API CHANGE: Remove the log callback parameter from mal_context_config_init(). With this change, - mal_context_config_init() now takes no parameters and the log callback is set via the structure directly. The + void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount); + - API CHANGE: Remove the log callback parameter from ma_context_config_init(). With this change, + ma_context_config_init() now takes no parameters and the log callback is set via the structure directly. The new policy for config initialization is that only mandatory settings are passed in to *_config_init(). The - "onLog" member of mal_context_config has been renamed to "logCallback". - - API CHANGE: Remove mal_device_get_buffer_size_in_bytes(). + "onLog" member of ma_context_config has been renamed to "logCallback". + - API CHANGE: Remove ma_device_get_buffer_size_in_bytes(). - API CHANGE: Rename decoding APIs to "pcm_frames" convention. - - mal_decoder_read() -> mal_decoder_read_pcm_frames() - - mal_decoder_seek_to_frame() -> mal_decoder_seek_to_pcm_frame() + - ma_decoder_read() -> ma_decoder_read_pcm_frames() + - ma_decoder_seek_to_frame() -> ma_decoder_seek_to_pcm_frame() - API CHANGE: Rename sine wave reading APIs to f32 convention. - - mal_sine_wave_read() -> mal_sine_wave_read_f32() - - mal_sine_wave_read_ex() -> mal_sine_wave_read_f32_ex() + - ma_sine_wave_read() -> ma_sine_wave_read_f32() + - ma_sine_wave_read_ex() -> ma_sine_wave_read_f32_ex() - API CHANGE: Remove some deprecated APIs - - mal_device_set_recv_callback() - - mal_device_set_send_callback() - - mal_src_set_input_sample_rate() - - mal_src_set_output_sample_rate() + - ma_device_set_recv_callback() + - ma_device_set_send_callback() + - ma_src_set_input_sample_rate() + - ma_src_set_output_sample_rate() - API CHANGE: Add log level to the log callback. New signature: - - void on_log(mal_context* pContext, mal_device* pDevice, mal_uint32 logLevel, const char* message) + - void on_log(ma_context* pContext, ma_device* pDevice, ma_uint32 logLevel, const char* message) - API CHANGE: Changes to result codes. Constants have changed and unused codes have been removed. If you're a binding mainainer you will need to update your result code constants. - - API CHANGE: Change the order of the mal_backend enums to priority order. If you are a binding maintainer, you + - API CHANGE: Change the order of the ma_backend enums to priority order. If you are a binding maintainer, you will need to update. - - API CHANGE: Rename mal_dsp to mal_pcm_converter. All functions have been renamed from mal_dsp_*() to - mal_pcm_converter_*(). All structures have been renamed from mal_dsp* to mal_pcm_converter*. - - API CHANGE: Reorder parameters of mal_decoder_read_pcm_frames() to be consistent with the new parameter order scheme. + - API CHANGE: Rename ma_dsp to ma_pcm_converter. All functions have been renamed from ma_dsp_*() to + ma_pcm_converter_*(). All structures have been renamed from ma_dsp* to ma_pcm_converter*. + - API CHANGE: Reorder parameters of ma_decoder_read_pcm_frames() to be consistent with the new parameter order scheme. - The resampling algorithm has been changed from sinc to linear. The rationale for this is that the sinc implementation is too inefficient right now. This will hopefully be improved at a later date. - Device initialization will no longer fall back to shared mode if exclusive mode is requested but is unusable. With this change, if you request an device in exclusive mode, but exclusive mode is not supported, it will not automatically fall back to shared mode. The client will need to reinitialize the device in shared mode if that's what they want. - - Add ring buffer API. This is mal_rb and mal_pcm_rb, the difference being that mal_rb operates on bytes and - mal_pcm_rb operates on PCM frames. + - Add ring buffer API. This is ma_rb and ma_pcm_rb, the difference being that ma_rb operates on bytes and + ma_pcm_rb operates on PCM frames. - Add Web Audio backend. This is used when compiling with Emscripten. The SDL backend, which was previously used for web support, will be removed in a future version. - Add AAudio backend (Android Audio). This is the new priority backend for Android. Support for AAudio starts @@ -31416,7 +31416,7 @@ v0.8.11 - 2018-11-21 v0.8.10 - 2018-10-21 - Core Audio: Fix a hang when uninitializing a device. - - Fix a bug where an incorrect value is returned from mal_device_stop(). + - Fix a bug where an incorrect value is returned from ma_device_stop(). v0.8.9 - 2018-09-28 - Fix a bug with the SDL backend where device initialization fails. @@ -31439,8 +31439,8 @@ v0.8.6 - 2018-08-26 - WASAPI: Add support for hardware offloading via IAudioClient2. Only supported on Windows 8 and newer. - WASAPI: Add support for low-latency shared mode via IAudioClient3. Only supported on Windows 10 and newer. - Add support for compiling the UWP build as C. - - mal_device_set_recv_callback() and mal_device_set_send_callback() have been deprecated. You must now set this - when the device is initialized with mal_device_init*(). These will be removed in version 0.9.0. + - ma_device_set_recv_callback() and ma_device_set_send_callback() have been deprecated. You must now set this + when the device is initialized with ma_device_init*(). These will be removed in version 0.9.0. v0.8.5 - 2018-08-12 - Add support for specifying the size of a device's buffer in milliseconds. You can still set the buffer size in @@ -31459,8 +31459,8 @@ v0.8.4 - 2018-08-06 - Drop support for the OSS backend on everything except FreeBSD and DragonFly BSD. - Formats are now native-endian (were previously little-endian). - Mark some APIs as deprecated: - - mal_src_set_input_sample_rate() and mal_src_set_output_sample_rate() are replaced with mal_src_set_sample_rate(). - - mal_dsp_set_input_sample_rate() and mal_dsp_set_output_sample_rate() are replaced with mal_dsp_set_sample_rate(). + - ma_src_set_input_sample_rate() and ma_src_set_output_sample_rate() are replaced with ma_src_set_sample_rate(). + - ma_dsp_set_input_sample_rate() and ma_dsp_set_output_sample_rate() are replaced with ma_dsp_set_sample_rate(). - Fix a bug when capturing using the WASAPI backend. - Fix some aliasing issues with resampling, specifically when increasing the sample rate. - Fix warnings. @@ -31469,8 +31469,8 @@ v0.8.3 - 2018-07-15 - Fix a crackling bug when resampling in capture mode. - Core Audio: Fix a bug where capture does not work. - ALSA: Fix a bug where the worker thread can get stuck in an infinite loop. - - PulseAudio: Fix a bug where mal_context_init() succeeds when PulseAudio is unusable. - - JACK: Fix a bug where mal_context_init() succeeds when JACK is unusable. + - PulseAudio: Fix a bug where ma_context_init() succeeds when PulseAudio is unusable. + - JACK: Fix a bug where ma_context_init() succeeds when JACK is unusable. v0.8.2 - 2018-07-07 - Fix a bug on macOS with Core Audio where the internal callback is not called. @@ -31481,18 +31481,18 @@ v0.8.1 - 2018-07-06 v0.8 - 2018-07-05 - Changed MA_IMPLEMENTATION to MINI_AL_IMPLEMENTATION for consistency with other libraries. The old way is still supported for now, but you should update as it may be removed in the future. - - API CHANGE: Replace device enumeration APIs. mal_enumerate_devices() has been replaced with - mal_context_get_devices(). An additional low-level device enumration API has been introduced called - mal_context_enumerate_devices() which uses a callback to report devices. - - API CHANGE: Rename mal_get_sample_size_in_bytes() to mal_get_bytes_per_sample() and add - mal_get_bytes_per_frame(). - - API CHANGE: Replace mal_device_config.preferExclusiveMode with mal_device_config.shareMode. - - This new config can be set to mal_share_mode_shared (default) or mal_share_mode_exclusive. - - API CHANGE: Remove excludeNullDevice from mal_context_config.alsa. + - API CHANGE: Replace device enumeration APIs. ma_enumerate_devices() has been replaced with + ma_context_get_devices(). An additional low-level device enumration API has been introduced called + ma_context_enumerate_devices() which uses a callback to report devices. + - API CHANGE: Rename ma_get_sample_size_in_bytes() to ma_get_bytes_per_sample() and add + ma_get_bytes_per_frame(). + - API CHANGE: Replace ma_device_config.preferExclusiveMode with ma_device_config.shareMode. + - This new config can be set to ma_share_mode_shared (default) or ma_share_mode_exclusive. + - API CHANGE: Remove excludeNullDevice from ma_context_config.alsa. - API CHANGE: Rename MA_MAX_SAMPLE_SIZE_IN_BYTES to MA_MAX_PCM_SAMPLE_SIZE_IN_BYTES. - API CHANGE: Change the default channel mapping to the standard Microsoft mapping. - API CHANGE: Remove backend-specific result codes. - - API CHANGE: Changes to the format conversion APIs (mal_pcm_f32_to_s16(), etc.) + - API CHANGE: Changes to the format conversion APIs (ma_pcm_f32_to_s16(), etc.) - Add support for Core Audio (Apple). - Add support for PulseAudio. - This is the highest priority backend on Linux (higher priority than ALSA) since it is commonly @@ -31511,13 +31511,13 @@ v0.8 - 2018-07-05 - Add support for configuring the priority of the worker thread. - Add a sine wave generator. - Improve efficiency of sample rate conversion. - - Introduce the notion of standard channel maps. Use mal_get_standard_channel_map(). + - Introduce the notion of standard channel maps. Use ma_get_standard_channel_map(). - Introduce the notion of default device configurations. A default config uses the same configuration as the backend's internal device, and as such results in a pass-through data transmission pipeline. - - Add support for passing in NULL for the device config in mal_device_init(), which uses a default - config. This requires manually calling mal_device_set_send/recv_callback(). - - Add support for decoding from raw PCM data (mal_decoder_init_raw(), etc.) - - Make mal_device_init_ex() more robust. + - Add support for passing in NULL for the device config in ma_device_init(), which uses a default + config. This requires manually calling ma_device_set_send/recv_callback(). + - Add support for decoding from raw PCM data (ma_decoder_init_raw(), etc.) + - Make ma_device_init_ex() more robust. - Make some APIs more const-correct. - Fix errors with SDL detection on Apple platforms. - Fix errors with OpenAL detection. @@ -31528,7 +31528,7 @@ v0.8 - 2018-07-05 - Documentation updates. v0.7 - 2018-02-25 - - API CHANGE: Change mal_src_read_frames() and mal_dsp_read_frames() to use 64-bit sample counts. + - API CHANGE: Change ma_src_read_frames() and ma_dsp_read_frames() to use 64-bit sample counts. - Add decoder APIs for loading WAV, FLAC, Vorbis and MP3 files. - Allow opening of devices without a context. - In this case the context is created and managed internally by the device. @@ -31549,22 +31549,22 @@ v0.6a - 2018-01-26 v0.6 - 2017-12-08 - API CHANGE: Expose and improve mutex APIs. If you were using the mutex APIs before this version you'll need to update. - - API CHANGE: SRC and DSP callbacks now take a pointer to a mal_src and mal_dsp object respectively. + - API CHANGE: SRC and DSP callbacks now take a pointer to a ma_src and ma_dsp object respectively. - API CHANGE: Improvements to event and thread APIs. These changes make these APIs more consistent. - Add support for SDL and Emscripten. - Simplify the build system further for when development packages for various backends are not installed. With this change, when the compiler supports __has_include, backends without the relevant development packages installed will be ignored. This fixes the build for old versions of MinGW. - Fixes to the Android build. - - Add mal_convert_frames(). This is a high-level helper API for performing a one-time, bulk conversion of + - Add ma_convert_frames(). This is a high-level helper API for performing a one-time, bulk conversion of audio data to a different format. - Improvements to f32 -> u8/s16/s24/s32 conversion routines. - - Fix a bug where the wrong value is returned from mal_device_start() for the OpenSL backend. + - Fix a bug where the wrong value is returned from ma_device_start() for the OpenSL backend. - Fixes and improvements for Raspberry Pi. - Warning fixes. v0.5 - 2017-11-11 - - API CHANGE: The mal_context_init() function now takes a pointer to a mal_context_config object for + - API CHANGE: The ma_context_init() function now takes a pointer to a ma_context_config object for configuring the context. The works in the same kind of way as the device config. The rationale for this change is to give applications better control over context-level properties, add support for backend- specific configurations, and support extensibility without breaking the API. @@ -31584,9 +31584,9 @@ v0.5 - 2017-11-11 v0.4 - 2017-11-05 - API CHANGE: The log callback is now per-context rather than per-device and as is thus now passed to - mal_context_init(). The rationale for this change is that it allows applications to capture diagnostic + ma_context_init(). The rationale for this change is that it allows applications to capture diagnostic messages at the context level. Previously this was only available at the device level. - - API CHANGE: The device config passed to mal_device_init() is now const. + - API CHANGE: The device config passed to ma_device_init() is now const. - Added support for OSS which enables support on BSD platforms. - Added support for WinMM (waveOut/waveIn). - Added support for UWP (Universal Windows Platform) applications. Currently C++ only. @@ -31610,7 +31610,7 @@ v0.3 - 2017-06-19 tied to the same backend. In addition, some backends are better suited to this design. - API CHANGE: Removed the rewinding APIs because they're too inconsistent across the different backends, hard to test and maintain, and just generally unreliable. - - Added helper APIs for initializing mal_device_config objects. + - Added helper APIs for initializing ma_device_config objects. - Null Backend: Fixed a crash when recording. - Fixed build for UWP. - Added support for f32 formats to the OpenSL|ES backend. @@ -31620,9 +31620,9 @@ v0.3 - 2017-06-19 - Added early support for basic channel mapping. v0.2 - 2016-10-28 - - API CHANGE: Add user data pointer as the last parameter to mal_device_init(). The rationale for this + - API CHANGE: Add user data pointer as the last parameter to ma_device_init(). The rationale for this change is to ensure the logging callback has access to the user data during initialization. - - API CHANGE: Have device configuration properties be passed to mal_device_init() via a structure. Rationale: + - API CHANGE: Have device configuration properties be passed to ma_device_init() via a structure. Rationale: 1) The number of parameters is just getting too much. 2) It makes it a bit easier to add new configuration properties in the future. In particular, there's a chance there will be support added for backend-specific properties. diff --git a/research/mal_resampler.h b/research/mal_resampler.h index 7342484e..fe8ad50a 100644 --- a/research/mal_resampler.h +++ b/research/mal_resampler.h @@ -8,12 +8,12 @@ Requirements: - Linear with optional filtering - Sinc - Floating point pipeline for f32 and fixed point integer pipeline for s16 - - Specify a mal_format enum as a config at initialization time, but fail if it's anything other than f32 or s16 + - Specify a ma_format enum as a config at initialization time, but fail if it's anything other than f32 or s16 - Need ability to move time forward without processing any samples - Needs an option to handle the cache as if silent samples of 0 have been passed as input - Needs option to move time forward by output sample rate _or_ input sample rate - Need to be able to do the equivalent to a seek by passing in NULL to the read API() - - mal_resampler_read(pResampler, frameCount, NULL) = mal_resampler_seek(pResampler, frameCount, 0) + - ma_resampler_read(pResampler, frameCount, NULL) = ma_resampler_seek(pResampler, frameCount, 0) - Need to be able to query the number of output PCM frames that can be generated from the currently cached input. The returned value must be fractional. Likewise, must be able to query the number of cached input PCM frames and must also be fractional. @@ -26,13 +26,13 @@ Requirements: the last input samples to be cached in the internal structure for the windowing algorithm. Other situations require all of the input samples to be consumed in order to output the correct total sample count. - Need to support converting input samples directly passed in as parameters without using a callback. - - mal_resampler_read(pResampler, &inputFrameCount, pInputFrames, &outputFrameCount, pOutputFrames). Returns a + - ma_resampler_read(pResampler, &inputFrameCount, pInputFrames, &outputFrameCount, pOutputFrames). Returns a result code. inputFrameCount and outputFrameCount are both input and output. - Need to support using a ring buffer as the backing data. - - mal_resampler_read_from_pcm_rb(pResampler, frameCount, pFramesOut, &ringBuffer). May need an option to control + - ma_resampler_read_from_pcm_rb(pResampler, frameCount, pFramesOut, &ringBuffer). May need an option to control how to handle underruns - should it stop processing or should it pad with zeroes? - Need to support reading from a callback. - - mal_resampler_read_from_callback(pResampler, frameCount, pFramesOut, resampler_callback, pUserData) + - ma_resampler_read_from_callback(pResampler, frameCount, pFramesOut, resampler_callback, pUserData) Other Notes: @@ -44,13 +44,13 @@ Other Notes: Random Notes: - You cannot change the algorithm after initialization. -- It is recommended to keep the mal_resampler object aligned to MA_SIMD_ALIGNMENT, though it is not necessary. +- It is recommended to keep the ma_resampler object aligned to MA_SIMD_ALIGNMENT, though it is not necessary. - Ratios need to be in the range of MA_RESAMPLER_MIN_RATIO and MA_RESAMPLER_MAX_RATIO. This is enough to convert to and from 8000 and 384000, which is the smallest and largest standard rates supported by miniaudio. If you need extreme ratios then you will need to chain resamplers together. */ -#ifndef mal_resampler_h -#define mal_resampler_h +#ifndef ma_resampler_h +#define ma_resampler_h #define MA_RESAMPLER_SEEK_NO_CLIENT_READ (1 << 0) /* When set, does not read anything from the client when seeking. This does _not_ call onRead(). */ #define MA_RESAMPLER_SEEK_INPUT_RATE (1 << 1) /* When set, treats the specified frame count based on the input sample rate rather than the output sample rate. */ @@ -59,89 +59,89 @@ Random Notes: #define MA_RESAMPLER_CACHE_SIZE_IN_BYTES 4096 #endif -typedef struct mal_resampler mal_resampler; +typedef struct ma_resampler ma_resampler; /* Client callbacks. */ -typedef mal_uint32 (* mal_resampler_read_from_client_proc)(mal_resampler* pResampler, mal_uint32 frameCount, void** ppFrames); +typedef ma_uint32 (* ma_resampler_read_from_client_proc)(ma_resampler* pResampler, ma_uint32 frameCount, void** ppFrames); /* Backend functions. */ -typedef mal_result (* mal_resampler_init_proc) (mal_resampler* pResampler); -typedef mal_uint64 (* mal_resampler_read_f32_proc)(mal_resampler* pResampler, mal_uint64 frameCount, float** ppFrames); -typedef mal_uint64 (* mal_resampler_read_s16_proc)(mal_resampler* pResampler, mal_uint64 frameCount, mal_int16** ppFrames); -typedef mal_uint64 (* mal_resampler_seek_proc) (mal_resampler* pResampler, mal_uint64 frameCount, mal_uint32 options); +typedef ma_result (* ma_resampler_init_proc) (ma_resampler* pResampler); +typedef ma_uint64 (* ma_resampler_read_f32_proc)(ma_resampler* pResampler, ma_uint64 frameCount, float** ppFrames); +typedef ma_uint64 (* ma_resampler_read_s16_proc)(ma_resampler* pResampler, ma_uint64 frameCount, ma_int16** ppFrames); +typedef ma_uint64 (* ma_resampler_seek_proc) (ma_resampler* pResampler, ma_uint64 frameCount, ma_uint32 options); typedef enum { - mal_resampler_algorithm_sinc = 0, /* Default. */ - mal_resampler_algorithm_linear, /* Fastest. */ -} mal_resampler_algorithm; + ma_resampler_algorithm_sinc = 0, /* Default. */ + ma_resampler_algorithm_linear, /* Fastest. */ +} ma_resampler_algorithm; typedef enum { - mal_resampler_end_of_input_mode_consume = 0, /* When the end of the input stream is reached, consume the last input PCM frames (do not leave them in the internal cache). Default. */ - mal_resampler_end_of_input_mode_no_consume /* When the end of the input stream is reached, do _not_ consume the last input PCM frames (leave them in the internal cache). Use this in streaming situations. */ -} mal_resampler_end_of_input_mode; + ma_resampler_end_of_input_mode_consume = 0, /* When the end of the input stream is reached, consume the last input PCM frames (do not leave them in the internal cache). Default. */ + ma_resampler_end_of_input_mode_no_consume /* When the end of the input stream is reached, do _not_ consume the last input PCM frames (leave them in the internal cache). Use this in streaming situations. */ +} ma_resampler_end_of_input_mode; typedef struct { - mal_format format; - mal_uint32 channels; - mal_uint32 sampleRateIn; - mal_uint32 sampleRateOut; + ma_format format; + ma_uint32 channels; + ma_uint32 sampleRateIn; + ma_uint32 sampleRateOut; double ratio; /* ratio = in/out */ - mal_resampler_algorithm algorithm; - mal_resampler_end_of_input_mode endOfInputMode; - mal_stream_layout layout; /* Interleaved or deinterleaved. */ - mal_resampler_read_from_client_proc onRead; + ma_resampler_algorithm algorithm; + ma_resampler_end_of_input_mode endOfInputMode; + ma_stream_layout layout; /* Interleaved or deinterleaved. */ + ma_resampler_read_from_client_proc onRead; void* pUserData; -} mal_resampler_config; +} ma_resampler_config; -struct mal_resampler +struct ma_resampler { union { float f32[MA_RESAMPLER_CACHE_SIZE_IN_BYTES/sizeof(float)]; - mal_int16 s16[MA_RESAMPLER_CACHE_SIZE_IN_BYTES/sizeof(mal_int16)]; + ma_int16 s16[MA_RESAMPLER_CACHE_SIZE_IN_BYTES/sizeof(ma_int16)]; } cache; /* Keep this as the first member of this structure for SIMD alignment purposes. */ - mal_uint32 cacheStrideInFrames; /* The number of the samples between channels in the cache. The first sample for channel 0 is cacheStrideInFrames*0. The first sample for channel 1 is cacheStrideInFrames*1, etc. */ - mal_uint16 cacheLengthInFrames; /* The number of valid frames sitting in the cache, including the filter window. May be less than the cache's capacity. */ - mal_uint16 windowLength; + ma_uint32 cacheStrideInFrames; /* The number of the samples between channels in the cache. The first sample for channel 0 is cacheStrideInFrames*0. The first sample for channel 1 is cacheStrideInFrames*1, etc. */ + ma_uint16 cacheLengthInFrames; /* The number of valid frames sitting in the cache, including the filter window. May be less than the cache's capacity. */ + ma_uint16 windowLength; double windowTime; /* By input rate. Relative to the start of the cache. */ - mal_resampler_config config; - mal_resampler_init_proc init; - mal_resampler_read_f32_proc readF32; - mal_resampler_read_s16_proc readS16; - mal_resampler_seek_proc seek; + ma_resampler_config config; + ma_resampler_init_proc init; + ma_resampler_read_f32_proc readF32; + ma_resampler_read_s16_proc readS16; + ma_resampler_seek_proc seek; }; /* Initializes a new resampler object from a config. */ -mal_result mal_resampler_init(const mal_resampler_config* pConfig, mal_resampler* pResampler); +ma_result ma_resampler_init(const ma_resampler_config* pConfig, ma_resampler* pResampler); /* Uninitializes the given resampler. */ -void mal_resampler_uninit(mal_resampler* pResampler); +void ma_resampler_uninit(ma_resampler* pResampler); /* Dynamically adjusts the sample rate. */ -mal_result mal_resampler_set_rate(mal_resampler* pResampler, mal_uint32 sampleRateIn, mal_uint32 sampleRateOut); +ma_result ma_resampler_set_rate(ma_resampler* pResampler, ma_uint32 sampleRateIn, ma_uint32 sampleRateOut); /* Dynamically adjusts the sample rate by a ratio. The ratio is in/out. */ -mal_result mal_resampler_set_rate_ratio(mal_resampler* pResampler, double ratio); +ma_result ma_resampler_set_rate_ratio(ma_resampler* pResampler, double ratio); /* Reads a number of PCM frames from the resampler. -Passing in NULL for ppFrames is equivalent to calling mal_resampler_seek(pResampler, frameCount, 0). +Passing in NULL for ppFrames is equivalent to calling ma_resampler_seek(pResampler, frameCount, 0). */ -mal_uint64 mal_resampler_read(mal_resampler* pResampler, mal_uint64 frameCount, void** ppFrames); +ma_uint64 ma_resampler_read(ma_resampler* pResampler, ma_uint64 frameCount, void** ppFrames); /* Seeks forward by the specified number of PCM frames. @@ -152,45 +152,45 @@ Seeks forward by the specified number of PCM frames. MA_RESAMPLER_SEEK_INPUT_RATE Treats "frameCount" as input samples instead of output samples. */ -mal_uint64 mal_resampler_seek(mal_resampler* pResampler, mal_uint64 frameCount, mal_uint32 options); +ma_uint64 ma_resampler_seek(ma_resampler* pResampler, ma_uint64 frameCount, ma_uint32 options); /* Retrieves the number of cached input frames. -This is equivalent to: (mal_uint64)ceil(mal_resampler_get_cached_input_time(pResampler)); +This is equivalent to: (ma_uint64)ceil(ma_resampler_get_cached_input_time(pResampler)); */ -mal_uint64 mal_resampler_get_cached_input_frame_count(mal_resampler* pResampler); +ma_uint64 ma_resampler_get_cached_input_frame_count(ma_resampler* pResampler); /* Retrieves the number of whole output frames that can be calculated from the currently cached input frames. -This is equivalent to: (mal_uint64)floor(mal_resampler_get_cached_output_time(pResampler)); +This is equivalent to: (ma_uint64)floor(ma_resampler_get_cached_output_time(pResampler)); */ -mal_uint64 mal_resampler_get_cached_output_frame_count(mal_resampler* pResampler); +ma_uint64 ma_resampler_get_cached_output_frame_count(ma_resampler* pResampler); /* -The same as mal_resampler_get_cached_input_frame_count(), except returns a fractional value representing the exact amount +The same as ma_resampler_get_cached_input_frame_count(), except returns a fractional value representing the exact amount of time in input rate making up the cached input. -When the end of input mode is set to mal_resampler_end_of_input_mode_no_consume, the input frames currently sitting in the +When the end of input mode is set to ma_resampler_end_of_input_mode_no_consume, the input frames currently sitting in the window are not included in the calculation. This can return a negative value if nothing has yet been loaded into the internal cache. This will happen if this is called immediately after initialization, before the first read has been performed. It may also happen if only a few samples have been read from the client. */ -double mal_resampler_get_cached_input_time(mal_resampler* pResampler); +double ma_resampler_get_cached_input_time(ma_resampler* pResampler); /* -The same as mal_resampler_get_cached_output_frame_count(), except returns a fractional value representing the exact amount +The same as ma_resampler_get_cached_output_frame_count(), except returns a fractional value representing the exact amount of time in output rate making up the cached output. -When the end of input mode is set to mal_resampler_end_of_input_mode_no_consume, the input frames currently sitting in the +When the end of input mode is set to ma_resampler_end_of_input_mode_no_consume, the input frames currently sitting in the window are not included in the calculation. -This can return a negative value. See mal_resampler_get_cached_input_time() for details. +This can return a negative value. See ma_resampler_get_cached_input_time() for details. */ -double mal_resampler_get_cached_output_time(mal_resampler* pResampler); +double ma_resampler_get_cached_output_time(ma_resampler* pResampler); /* Calculates the number of whole input frames that would need to be read from the client in order to output the specified @@ -199,25 +199,25 @@ number of output frames. The returned value does not include cached input frames. It only returns the number of extra frames that would need to be read from the client in order to output the specified number of output frames. -When the end of input mode is set to mal_resampler_end_of_input_mode_no_consume, the input frames sitting in the filter +When the end of input mode is set to ma_resampler_end_of_input_mode_no_consume, the input frames sitting in the filter window are not included in the calculation. */ -mal_uint64 mal_resampler_get_required_input_frame_count(mal_resampler* pResampler, mal_uint64 outputFrameCount); +ma_uint64 ma_resampler_get_required_input_frame_count(ma_resampler* pResampler, ma_uint64 outputFrameCount); /* Calculates the number of whole output frames that would be output after fully reading and consuming the specified number of input frames from the client. A detail to keep in mind is how cached input frames are handled. This function calculates the output frame count based on -inputFrameCount + mal_resampler_get_cached_input_time(). It essentially calcualtes how many output frames will be returned +inputFrameCount + ma_resampler_get_cached_input_time(). It essentially calcualtes how many output frames will be returned if an additional inputFrameCount frames were read from the client and consumed by the resampler. You can adjust the return -value by mal_resampler_get_cached_output_frame_count() which calculates the number of output frames that can be output from +value by ma_resampler_get_cached_output_frame_count() which calculates the number of output frames that can be output from the currently cached input. -When the end of input mode is set to mal_resampler_end_of_input_mode_no_consume, the input frames sitting in the filter +When the end of input mode is set to ma_resampler_end_of_input_mode_no_consume, the input frames sitting in the filter window are not included in the calculation. */ -mal_uint64 mal_resampler_get_expected_output_frame_count(mal_resampler* pResampler, mal_uint64 inputFrameCount); +ma_uint64 ma_resampler_get_expected_output_frame_count(ma_resampler* pResampler, ma_uint64 inputFrameCount); #endif #ifdef MINIAUDIO_IMPLEMENTATION @@ -229,64 +229,64 @@ mal_uint64 mal_resampler_get_expected_output_frame_count(mal_resampler* pResampl #define MA_RESAMPLER_MAX_RATIO 48.0 #endif -mal_result mal_resampler_init__linear(mal_resampler* pResampler); -mal_uint64 mal_resampler_read_f32__linear(mal_resampler* pResampler, mal_uint64 frameCount, float** ppFrames); -mal_uint64 mal_resampler_read_s16__linear(mal_resampler* pResampler, mal_uint64 frameCount, mal_int16** ppFrames); -mal_uint64 mal_resampler_seek__linear(mal_resampler* pResampler, mal_uint64 frameCount, mal_uint32 options); +ma_result ma_resampler_init__linear(ma_resampler* pResampler); +ma_uint64 ma_resampler_read_f32__linear(ma_resampler* pResampler, ma_uint64 frameCount, float** ppFrames); +ma_uint64 ma_resampler_read_s16__linear(ma_resampler* pResampler, ma_uint64 frameCount, ma_int16** ppFrames); +ma_uint64 ma_resampler_seek__linear(ma_resampler* pResampler, ma_uint64 frameCount, ma_uint32 options); -mal_result mal_resampler_init__sinc(mal_resampler* pResampler); -mal_uint64 mal_resampler_read_f32__sinc(mal_resampler* pResampler, mal_uint64 frameCount, float** ppFrames); -mal_uint64 mal_resampler_read_s16__sinc(mal_resampler* pResampler, mal_uint64 frameCount, mal_int16** ppFrames); -mal_uint64 mal_resampler_seek__sinc(mal_resampler* pResampler, mal_uint64 frameCount, mal_uint32 options); +ma_result ma_resampler_init__sinc(ma_resampler* pResampler); +ma_uint64 ma_resampler_read_f32__sinc(ma_resampler* pResampler, ma_uint64 frameCount, float** ppFrames); +ma_uint64 ma_resampler_read_s16__sinc(ma_resampler* pResampler, ma_uint64 frameCount, ma_int16** ppFrames); +ma_uint64 ma_resampler_seek__sinc(ma_resampler* pResampler, ma_uint64 frameCount, ma_uint32 options); -static MA_INLINE float mal_fractional_part_f32(float x) +static MA_INLINE float ma_fractional_part_f32(float x) { - return x - ((mal_int32)x); + return x - ((ma_int32)x); } -static MA_INLINE double mal_fractional_part_f64(double x) +static MA_INLINE double ma_fractional_part_f64(double x) { - return x - ((mal_int64)x); + return x - ((ma_int64)x); } #if 0 #define MA_ALIGN_INT(val, alignment) (((val) + ((alignment)-1)) & ~((alignment)-1)) -#define MA_ALIGN_PTR(ptr, alignment) (void*)MA_ALIGN_INT(((mal_uintptr)(ptr)), (alignment)) +#define MA_ALIGN_PTR(ptr, alignment) (void*)MA_ALIGN_INT(((ma_uintptr)(ptr)), (alignment)) /* This macro declares a set of variables on the stack of a given size in bytes. The variables it creates are: - - mal_uint8 Unaligned[size + MA_SIMD_ALIGNMENT]; + - ma_uint8 Unaligned[size + MA_SIMD_ALIGNMENT]; - * [MA_MAX_CHANNELS]; - size_t FrameCount; <-- This is the number of samples contained within each sub-buffer of This does not work for formats that do not have a clean mapping to a primitive C type. s24 will not work here. */ #define MA_DECLARE_ALIGNED_STACK_BUFFER(type, name, size, channels) \ - mal_uint8 name##Unaligned[(size) + MA_SIMD_ALIGNMENT]; \ + ma_uint8 name##Unaligned[(size) + MA_SIMD_ALIGNMENT]; \ type* name[MA_MAX_CHANNELS]; \ size_t name##FrameCount = ((size) & ~((MA_SIMD_ALIGNMENT)-1)) / sizeof(type); \ do { \ - mal_uint32 iChannel; \ + ma_uint32 iChannel; \ for (iChannel = 0; iChannel < channels; ++iChannel) { \ - name[iChannel] = (type*)((mal_uint8*)MA_ALIGN_PTR(name##Unaligned, MA_SIMD_ALIGNMENT) + (iChannel*((size) & ~((MA_SIMD_ALIGNMENT)-1)))); \ + name[iChannel] = (type*)((ma_uint8*)MA_ALIGN_PTR(name##Unaligned, MA_SIMD_ALIGNMENT) + (iChannel*((size) & ~((MA_SIMD_ALIGNMENT)-1)))); \ } \ } while (0) #endif -#define mal_filter_window_length_left(length) ((length) >> 1) -#define mal_filter_window_length_right(length) ((length) - mal_filter_window_length_left(length)) +#define ma_filter_window_length_left(length) ((length) >> 1) +#define ma_filter_window_length_right(length) ((length) - ma_filter_window_length_left(length)) -static MA_INLINE mal_uint16 mal_resampler__window_length_left(const mal_resampler* pResampler) +static MA_INLINE ma_uint16 ma_resampler__window_length_left(const ma_resampler* pResampler) { - return mal_filter_window_length_left(pResampler->windowLength); + return ma_filter_window_length_left(pResampler->windowLength); } -static MA_INLINE mal_uint16 mal_resampler__window_length_right(const mal_resampler* pResampler) +static MA_INLINE ma_uint16 ma_resampler__window_length_right(const ma_resampler* pResampler) { - return mal_filter_window_length_right(pResampler->windowLength); + return ma_filter_window_length_right(pResampler->windowLength); } -static MA_INLINE double mal_resampler__calculate_cached_input_time_by_mode(mal_resampler* pResampler, mal_resampler_end_of_input_mode mode) +static MA_INLINE double ma_resampler__calculate_cached_input_time_by_mode(ma_resampler* pResampler, ma_resampler_end_of_input_mode mode) { /* The cached input time depends on whether or not the end of the input is being consumed. If so, it's the difference between the @@ -294,8 +294,8 @@ static MA_INLINE double mal_resampler__calculate_cached_input_time_by_mode(mal_r of the window. */ double cachedInputTime = pResampler->cacheLengthInFrames; - if (mode == mal_resampler_end_of_input_mode_consume) { - cachedInputTime -= (pResampler->windowTime + mal_resampler__window_length_left(pResampler)); + if (mode == ma_resampler_end_of_input_mode_consume) { + cachedInputTime -= (pResampler->windowTime + ma_resampler__window_length_left(pResampler)); } else { cachedInputTime -= (pResampler->windowTime + pResampler->windowLength); } @@ -303,42 +303,42 @@ static MA_INLINE double mal_resampler__calculate_cached_input_time_by_mode(mal_r return cachedInputTime; } -static MA_INLINE double mal_resampler__calculate_cached_input_time(mal_resampler* pResampler) +static MA_INLINE double ma_resampler__calculate_cached_input_time(ma_resampler* pResampler) { - return mal_resampler__calculate_cached_input_time_by_mode(pResampler, pResampler->config.endOfInputMode); + return ma_resampler__calculate_cached_input_time_by_mode(pResampler, pResampler->config.endOfInputMode); } -static MA_INLINE double mal_resampler__calculate_cached_output_time_by_mode(mal_resampler* pResampler, mal_resampler_end_of_input_mode mode) +static MA_INLINE double ma_resampler__calculate_cached_output_time_by_mode(ma_resampler* pResampler, ma_resampler_end_of_input_mode mode) { - return mal_resampler__calculate_cached_input_time_by_mode(pResampler, mode) / pResampler->config.ratio; + return ma_resampler__calculate_cached_input_time_by_mode(pResampler, mode) / pResampler->config.ratio; } -static MA_INLINE double mal_resampler__calculate_cached_output_time(mal_resampler* pResampler) +static MA_INLINE double ma_resampler__calculate_cached_output_time(ma_resampler* pResampler) { - return mal_resampler__calculate_cached_output_time_by_mode(pResampler, pResampler->config.endOfInputMode); + return ma_resampler__calculate_cached_output_time_by_mode(pResampler, pResampler->config.endOfInputMode); } -static MA_INLINE mal_result mal_resampler__slide_cache_down(mal_resampler* pResampler) +static MA_INLINE ma_result ma_resampler__slide_cache_down(ma_resampler* pResampler) { /* This function moves everything from the start of the window to the last loaded frame in the cache down to the front. */ - mal_uint16 framesToConsume; - framesToConsume = (mal_uint16)pResampler->windowTime; + ma_uint16 framesToConsume; + framesToConsume = (ma_uint16)pResampler->windowTime; pResampler->windowTime -= framesToConsume; pResampler->cacheLengthInFrames -= framesToConsume; - if (pResampler->config.format == mal_format_f32) { - for (mal_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { - for (mal_uint32 iFrame = 0; iFrame < pResampler->cacheLengthInFrames; ++iFrame) { + if (pResampler->config.format == ma_format_f32) { + for (ma_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { + for (ma_uint32 iFrame = 0; iFrame < pResampler->cacheLengthInFrames; ++iFrame) { pResampler->cache.f32[pResampler->cacheStrideInFrames*iChannel + iFrame] = pResampler->cache.f32[pResampler->cacheStrideInFrames*iChannel + iFrame + framesToConsume]; } } } else { - for (mal_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { - for (mal_uint32 iFrame = 0; iFrame < pResampler->cacheLengthInFrames; ++iFrame) { + for (ma_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { + for (ma_uint32 iFrame = 0; iFrame < pResampler->cacheLengthInFrames; ++iFrame) { pResampler->cache.s16[pResampler->cacheStrideInFrames*iChannel + iFrame] = pResampler->cache.s16[pResampler->cacheStrideInFrames*iChannel + iFrame + framesToConsume]; } } @@ -350,30 +350,30 @@ static MA_INLINE mal_result mal_resampler__slide_cache_down(mal_resampler* pResa typedef union { float* f32[MA_MAX_CHANNELS]; - mal_int16* s16[MA_MAX_CHANNELS]; -} mal_resampler_deinterleaved_pointers; + ma_int16* s16[MA_MAX_CHANNELS]; +} ma_resampler_deinterleaved_pointers; typedef union { float* f32; - mal_int16* s16; -} mal_resampler_interleaved_pointers; + ma_int16* s16; +} ma_resampler_interleaved_pointers; -mal_result mal_resampler__reload_cache(mal_resampler* pResampler, mal_bool32* pLoadedEndOfInput) +ma_result ma_resampler__reload_cache(ma_resampler* pResampler, ma_bool32* pLoadedEndOfInput) { /* When reloading the buffer there's a specific rule to keep into consideration. When the client */ - mal_result result; - mal_uint32 framesToReadFromClient; - mal_uint32 framesReadFromClient; - mal_bool32 loadedEndOfInput = MA_FALSE; + ma_result result; + ma_uint32 framesToReadFromClient; + ma_uint32 framesReadFromClient; + ma_bool32 loadedEndOfInput = MA_FALSE; - mal_assert(pLoadedEndOfInput != NULL); - mal_assert(pResampler->windowTime < 65536); - mal_assert(pResampler->windowTime <= pResampler->cacheLengthInFrames); + ma_assert(pLoadedEndOfInput != NULL); + ma_assert(pResampler->windowTime < 65536); + ma_assert(pResampler->windowTime <= pResampler->cacheLengthInFrames); /* Before loading anything from the client we need to move anything left in the cache down the front. */ - result = mal_resampler__slide_cache_down(pResampler); + result = ma_resampler__slide_cache_down(pResampler); if (result != MA_SUCCESS) { return result; /* Should never actually happen. */ } @@ -383,67 +383,67 @@ mal_result mal_resampler__reload_cache(mal_resampler* pResampler, mal_bool32* pL cache. The reason is that the little bit is filled with zero-padding when the end of input is reached. The amount of padding is equal to the size of the right side of the filter window. */ - if (pResampler->config.format == mal_format_f32) { - framesToReadFromClient = pResampler->cacheStrideInFrames - mal_resampler__window_length_right(pResampler) - pResampler->cacheLengthInFrames; + if (pResampler->config.format == ma_format_f32) { + framesToReadFromClient = pResampler->cacheStrideInFrames - ma_resampler__window_length_right(pResampler) - pResampler->cacheLengthInFrames; } else { - framesToReadFromClient = pResampler->cacheStrideInFrames - mal_resampler__window_length_right(pResampler) - pResampler->cacheLengthInFrames; + framesToReadFromClient = pResampler->cacheStrideInFrames - ma_resampler__window_length_right(pResampler) - pResampler->cacheLengthInFrames; } /* Here is where we need to read more data from the client. We need to construct some deinterleaved buffers first, though. */ - mal_resampler_deinterleaved_pointers clientDst; - if (pResampler->config.format == mal_format_f32) { - for (mal_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { + ma_resampler_deinterleaved_pointers clientDst; + if (pResampler->config.format == ma_format_f32) { + for (ma_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { clientDst.f32[iChannel] = pResampler->cache.f32 + (pResampler->cacheStrideInFrames*iChannel + pResampler->cacheLengthInFrames); } - if (pResampler->config.layout == mal_stream_layout_deinterleaved) { + if (pResampler->config.layout == ma_stream_layout_deinterleaved) { framesReadFromClient = pResampler->config.onRead(pResampler, framesToReadFromClient, clientDst.f32); } else { - float buffer[mal_countof(pResampler->cache.f32)]; + float buffer[ma_countof(pResampler->cache.f32)]; float* pInterleavedFrames = buffer; framesReadFromClient = pResampler->config.onRead(pResampler, framesToReadFromClient, &pInterleavedFrames); - mal_deinterleave_pcm_frames(pResampler->config.format, pResampler->config.channels, framesReadFromClient, pInterleavedFrames, clientDst.f32); + ma_deinterleave_pcm_frames(pResampler->config.format, pResampler->config.channels, framesReadFromClient, pInterleavedFrames, clientDst.f32); } } else { - for (mal_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { + for (ma_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { clientDst.s16[iChannel] = pResampler->cache.s16 + (pResampler->cacheStrideInFrames*iChannel + pResampler->cacheLengthInFrames); } - if (pResampler->config.layout == mal_stream_layout_deinterleaved) { + if (pResampler->config.layout == ma_stream_layout_deinterleaved) { framesReadFromClient = pResampler->config.onRead(pResampler, framesToReadFromClient, clientDst.s16); } else { - mal_int16 buffer[mal_countof(pResampler->cache.s16)]; - mal_int16* pInterleavedFrames = buffer; + ma_int16 buffer[ma_countof(pResampler->cache.s16)]; + ma_int16* pInterleavedFrames = buffer; framesReadFromClient = pResampler->config.onRead(pResampler, framesToReadFromClient, &pInterleavedFrames); - mal_deinterleave_pcm_frames(pResampler->config.format, pResampler->config.channels, framesReadFromClient, pInterleavedFrames, clientDst.s16); + ma_deinterleave_pcm_frames(pResampler->config.format, pResampler->config.channels, framesReadFromClient, pInterleavedFrames, clientDst.s16); } } - mal_assert(framesReadFromClient <= framesToReadFromClient); + ma_assert(framesReadFromClient <= framesToReadFromClient); if (framesReadFromClient < framesToReadFromClient) { /* We have reached the end of the input buffer. We do _not_ want to attempt to read any more data from the client in this case. */ loadedEndOfInput = MA_TRUE; *pLoadedEndOfInput = loadedEndOfInput; } - mal_assert(framesReadFromClient <= 65535); - pResampler->cacheLengthInFrames += (mal_uint16)framesReadFromClient; + ma_assert(framesReadFromClient <= 65535); + pResampler->cacheLengthInFrames += (ma_uint16)framesReadFromClient; /* If we just loaded the end of the input and the resampler is configured to consume it, we need to pad the end of the cache with silence. This system ensures the last input samples are processed by the resampler. The amount of padding is equal to the length of the right side of the filter window. */ - if (loadedEndOfInput && pResampler->config.endOfInputMode == mal_resampler_end_of_input_mode_consume) { - mal_uint16 paddingLengthInFrames = mal_resampler__window_length_right(pResampler); + if (loadedEndOfInput && pResampler->config.endOfInputMode == ma_resampler_end_of_input_mode_consume) { + ma_uint16 paddingLengthInFrames = ma_resampler__window_length_right(pResampler); if (paddingLengthInFrames > 0) { - if (pResampler->config.format == mal_format_f32) { - for (mal_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { - mal_zero_memory(pResampler->cache.f32 + (pResampler->cacheStrideInFrames*iChannel + pResampler->cacheLengthInFrames), paddingLengthInFrames*sizeof(float)); + if (pResampler->config.format == ma_format_f32) { + for (ma_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { + ma_zero_memory(pResampler->cache.f32 + (pResampler->cacheStrideInFrames*iChannel + pResampler->cacheLengthInFrames), paddingLengthInFrames*sizeof(float)); } } else { - for (mal_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { - mal_zero_memory(pResampler->cache.s16 + (pResampler->cacheStrideInFrames*iChannel + pResampler->cacheLengthInFrames), paddingLengthInFrames*sizeof(mal_int16)); + for (ma_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { + ma_zero_memory(pResampler->cache.s16 + (pResampler->cacheStrideInFrames*iChannel + pResampler->cacheLengthInFrames), paddingLengthInFrames*sizeof(ma_int16)); } } @@ -455,19 +455,19 @@ mal_result mal_resampler__reload_cache(mal_resampler* pResampler, mal_bool32* pL } -mal_result mal_resampler_init(const mal_resampler_config* pConfig, mal_resampler* pResampler) +ma_result ma_resampler_init(const ma_resampler_config* pConfig, ma_resampler* pResampler) { if (pResampler == NULL) { return MA_INVALID_ARGS; } - mal_zero_object(pResampler); + ma_zero_object(pResampler); if (pConfig == NULL) { return MA_INVALID_ARGS; } pResampler->config = *pConfig; - if (pResampler->config.format != mal_format_f32 && pResampler->config.format != mal_format_s16) { + if (pResampler->config.format != ma_format_f32 && pResampler->config.format != ma_format_s16) { return MA_INVALID_ARGS; /* Unsupported format. */ } if (pResampler->config.channels == 0) { @@ -484,31 +484,31 @@ mal_result mal_resampler_init(const mal_resampler_config* pConfig, mal_resampler } switch (pResampler->config.algorithm) { - case mal_resampler_algorithm_linear: + case ma_resampler_algorithm_linear: { - pResampler->init = mal_resampler_init__linear; - pResampler->readF32 = mal_resampler_read_f32__linear; - pResampler->readS16 = mal_resampler_read_s16__linear; - pResampler->seek = mal_resampler_seek__linear; + pResampler->init = ma_resampler_init__linear; + pResampler->readF32 = ma_resampler_read_f32__linear; + pResampler->readS16 = ma_resampler_read_s16__linear; + pResampler->seek = ma_resampler_seek__linear; } break; - case mal_resampler_algorithm_sinc: + case ma_resampler_algorithm_sinc: { - pResampler->init = mal_resampler_init__sinc; - pResampler->readF32 = mal_resampler_read_f32__sinc; - pResampler->readS16 = mal_resampler_read_s16__sinc; - pResampler->seek = mal_resampler_seek__sinc; + pResampler->init = ma_resampler_init__sinc; + pResampler->readF32 = ma_resampler_read_f32__sinc; + pResampler->readS16 = ma_resampler_read_s16__sinc; + pResampler->seek = ma_resampler_seek__sinc; } break; } - if (pResampler->config.format == mal_format_f32) { - pResampler->cacheStrideInFrames = mal_countof(pResampler->cache.f32) / pResampler->config.channels; + if (pResampler->config.format == ma_format_f32) { + pResampler->cacheStrideInFrames = ma_countof(pResampler->cache.f32) / pResampler->config.channels; } else { - pResampler->cacheStrideInFrames = mal_countof(pResampler->cache.s16) / pResampler->config.channels; + pResampler->cacheStrideInFrames = ma_countof(pResampler->cache.s16) / pResampler->config.channels; } if (pResampler->init != NULL) { - mal_result result = pResampler->init(pResampler); + ma_result result = pResampler->init(pResampler); if (result != MA_SUCCESS) { return result; } @@ -516,19 +516,19 @@ mal_result mal_resampler_init(const mal_resampler_config* pConfig, mal_resampler /* After initializing the backend, we'll need to pre-fill the filter with zeroes. This has already been half done via - the call to mal_zero_object() at the top of this function, but we need to increment the frame counter to complete it. + the call to ma_zero_object() at the top of this function, but we need to increment the frame counter to complete it. */ - pResampler->cacheLengthInFrames = mal_resampler__window_length_left(pResampler); + pResampler->cacheLengthInFrames = ma_resampler__window_length_left(pResampler); return MA_SUCCESS; } -void mal_resampler_uninit(mal_resampler* pResampler) +void ma_resampler_uninit(ma_resampler* pResampler) { (void)pResampler; } -mal_result mal_resampler_set_rate(mal_resampler* pResampler, mal_uint32 sampleRateIn, mal_uint32 sampleRateOut) +ma_result ma_resampler_set_rate(ma_resampler* pResampler, ma_uint32 sampleRateIn, ma_uint32 sampleRateOut) { if (pResampler == NULL) { return MA_INVALID_ARGS; @@ -550,7 +550,7 @@ mal_result mal_resampler_set_rate(mal_resampler* pResampler, mal_uint32 sampleRa return MA_SUCCESS; } -mal_result mal_resampler_set_rate_ratio(mal_resampler* pResampler, double ratio) +ma_result ma_resampler_set_rate_ratio(ma_resampler* pResampler, double ratio) { if (pResampler == NULL) { return MA_INVALID_ARGS; @@ -565,13 +565,13 @@ mal_result mal_resampler_set_rate_ratio(mal_resampler* pResampler, double ratio) return MA_SUCCESS; } -mal_uint64 mal_resampler_read(mal_resampler* pResampler, mal_uint64 frameCount, void** ppFrames) +ma_uint64 ma_resampler_read(ma_resampler* pResampler, ma_uint64 frameCount, void** ppFrames) { - mal_result result; - mal_uint64 totalFramesRead; - mal_resampler_deinterleaved_pointers runningFramesOutDeinterleaved; - mal_resampler_interleaved_pointers runningFramesOutInterleaved; - mal_bool32 loadedEndOfInput = MA_FALSE; + ma_result result; + ma_uint64 totalFramesRead; + ma_resampler_deinterleaved_pointers runningFramesOutDeinterleaved; + ma_resampler_interleaved_pointers runningFramesOutInterleaved; + ma_bool32 loadedEndOfInput = MA_FALSE; if (pResampler == NULL) { return 0; /* Invalid arguments. */ @@ -583,20 +583,20 @@ mal_uint64 mal_resampler_read(mal_resampler* pResampler, mal_uint64 frameCount, /* When ppFrames is NULL, reading is equivalent to seeking with default options. */ if (ppFrames == NULL) { - return mal_resampler_seek(pResampler, frameCount, 0); + return ma_resampler_seek(pResampler, frameCount, 0); } - if (pResampler->config.format == mal_format_f32) { - mal_assert(pResampler->readF32 != NULL); + if (pResampler->config.format == ma_format_f32) { + ma_assert(pResampler->readF32 != NULL); } else { - mal_assert(pResampler->readS16 != NULL); + ma_assert(pResampler->readS16 != NULL); } /* Initialization of the running frame pointers. */ - if (pResampler->config.layout == mal_stream_layout_deinterleaved) { - for (mal_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { + if (pResampler->config.layout == ma_stream_layout_deinterleaved) { + for (ma_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { runningFramesOutDeinterleaved.f32[iChannel] = (float*)ppFrames[iChannel]; } runningFramesOutInterleaved.f32 = NULL; /* Silences a warning. */ @@ -613,46 +613,46 @@ mal_uint64 mal_resampler_read(mal_resampler* pResampler, mal_uint64 frameCount, totalFramesRead = 0; while (totalFramesRead < frameCount) { double cachedOutputTime; - mal_uint64 framesRemaining = frameCount - totalFramesRead; - mal_uint64 framesToReadRightNow = framesRemaining; + ma_uint64 framesRemaining = frameCount - totalFramesRead; + ma_uint64 framesToReadRightNow = framesRemaining; /* We need to make sure we don't read more than what's already in the buffer at a time. */ - cachedOutputTime = mal_resampler__calculate_cached_output_time_by_mode(pResampler, mal_resampler_end_of_input_mode_no_consume); + cachedOutputTime = ma_resampler__calculate_cached_output_time_by_mode(pResampler, ma_resampler_end_of_input_mode_no_consume); if (cachedOutputTime > 0) { if (framesRemaining > cachedOutputTime) { - framesToReadRightNow = (mal_uint64)floor(cachedOutputTime); + framesToReadRightNow = (ma_uint64)floor(cachedOutputTime); } /* At this point we should know how many frames can be read this iteration. We need an optimization for when the ratio=1 and the current time is a whole number. In this case we need to do a direct copy without any processing. */ - if (pResampler->config.ratio == 1 && mal_fractional_part_f64(pResampler->windowTime) == 0) { + if (pResampler->config.ratio == 1 && ma_fractional_part_f64(pResampler->windowTime) == 0) { /* No need to read from the backend - just copy the input straight over without any processing. We start reading from the right side of the filter window. */ - mal_uint16 iFirstSample = (mal_uint16)pResampler->windowTime + mal_resampler__window_length_left(pResampler); - if (pResampler->config.format == mal_format_f32) { - for (mal_uint16 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { - if (pResampler->config.layout == mal_stream_layout_deinterleaved) { - for (mal_uint16 iFrame = 0; iFrame < framesToReadRightNow; ++iFrame) { + ma_uint16 iFirstSample = (ma_uint16)pResampler->windowTime + ma_resampler__window_length_left(pResampler); + if (pResampler->config.format == ma_format_f32) { + for (ma_uint16 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { + if (pResampler->config.layout == ma_stream_layout_deinterleaved) { + for (ma_uint16 iFrame = 0; iFrame < framesToReadRightNow; ++iFrame) { runningFramesOutDeinterleaved.f32[iChannel][iFrame] = pResampler->cache.f32[pResampler->cacheStrideInFrames*iChannel + iFirstSample + iFrame]; } } else { - for (mal_uint16 iFrame = 0; iFrame < framesToReadRightNow; ++iFrame) { + for (ma_uint16 iFrame = 0; iFrame < framesToReadRightNow; ++iFrame) { runningFramesOutInterleaved.f32[iFrame*pResampler->config.channels + iChannel] = pResampler->cache.f32[pResampler->cacheStrideInFrames*iChannel + iFirstSample + iFrame]; } } } } else { - for (mal_uint16 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { - if (pResampler->config.layout == mal_stream_layout_deinterleaved) { - for (mal_uint16 iFrame = 0; iFrame < framesToReadRightNow; ++iFrame) { + for (ma_uint16 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { + if (pResampler->config.layout == ma_stream_layout_deinterleaved) { + for (ma_uint16 iFrame = 0; iFrame < framesToReadRightNow; ++iFrame) { runningFramesOutDeinterleaved.s16[iChannel][iFrame] = pResampler->cache.s16[pResampler->cacheStrideInFrames*iChannel + iFirstSample + iFrame]; } } else { - for (mal_uint16 iFrame = 0; iFrame < framesToReadRightNow; ++iFrame) { + for (ma_uint16 iFrame = 0; iFrame < framesToReadRightNow; ++iFrame) { runningFramesOutInterleaved.s16[iFrame*pResampler->config.channels + iChannel] = pResampler->cache.s16[pResampler->cacheStrideInFrames*iChannel + iFirstSample + iFrame]; } } @@ -663,37 +663,37 @@ mal_uint64 mal_resampler_read(mal_resampler* pResampler, mal_uint64 frameCount, Need to read from the backend. Input data is always from the cache. Output data is always to a deinterleaved buffer. When the stream layout is set to deinterleaved, we need to read into a temporary buffer and then interleave. */ - mal_uint64 framesJustRead; - if (pResampler->config.format == mal_format_f32) { - if (pResampler->config.layout == mal_stream_layout_deinterleaved) { + ma_uint64 framesJustRead; + if (pResampler->config.format == ma_format_f32) { + if (pResampler->config.layout == ma_stream_layout_deinterleaved) { framesJustRead = pResampler->readF32(pResampler, framesToReadRightNow, runningFramesOutDeinterleaved.f32); } else { - float buffer[mal_countof(pResampler->cache.f32)]; + float buffer[ma_countof(pResampler->cache.f32)]; float* ppDeinterleavedFrames[MA_MAX_CHANNELS]; - for (mal_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { + for (ma_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { ppDeinterleavedFrames[iChannel] = buffer + (pResampler->cacheStrideInFrames*iChannel); } framesJustRead = pResampler->readF32(pResampler, framesToReadRightNow, ppDeinterleavedFrames); - mal_interleave_pcm_frames(pResampler->config.format, pResampler->config.channels, framesJustRead, ppDeinterleavedFrames, runningFramesOutInterleaved.f32); + ma_interleave_pcm_frames(pResampler->config.format, pResampler->config.channels, framesJustRead, ppDeinterleavedFrames, runningFramesOutInterleaved.f32); } } else { - if (pResampler->config.layout == mal_stream_layout_interleaved) { + if (pResampler->config.layout == ma_stream_layout_interleaved) { framesJustRead = pResampler->readS16(pResampler, framesToReadRightNow, runningFramesOutDeinterleaved.s16); } else { - mal_int16 buffer[mal_countof(pResampler->cache.s16)]; - mal_int16* ppDeinterleavedFrames[MA_MAX_CHANNELS]; - for (mal_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { + ma_int16 buffer[ma_countof(pResampler->cache.s16)]; + ma_int16* ppDeinterleavedFrames[MA_MAX_CHANNELS]; + for (ma_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { ppDeinterleavedFrames[iChannel] = buffer + (pResampler->cacheStrideInFrames*iChannel); } framesJustRead = pResampler->readS16(pResampler, framesToReadRightNow, ppDeinterleavedFrames); - mal_interleave_pcm_frames(pResampler->config.format, pResampler->config.channels, framesJustRead, ppDeinterleavedFrames, runningFramesOutInterleaved.s16); + ma_interleave_pcm_frames(pResampler->config.format, pResampler->config.channels, framesJustRead, ppDeinterleavedFrames, runningFramesOutInterleaved.s16); } } if (framesJustRead != framesToReadRightNow) { - mal_assert(MA_FALSE); + ma_assert(MA_FALSE); break; /* Should never hit this. */ } } @@ -701,17 +701,17 @@ mal_uint64 mal_resampler_read(mal_resampler* pResampler, mal_uint64 frameCount, /* Move time forward. */ pResampler->windowTime += (framesToReadRightNow * pResampler->config.ratio); - if (pResampler->config.format == mal_format_f32) { - if (pResampler->config.layout == mal_stream_layout_deinterleaved) { - for (mal_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { + if (pResampler->config.format == ma_format_f32) { + if (pResampler->config.layout == ma_stream_layout_deinterleaved) { + for (ma_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { runningFramesOutDeinterleaved.f32[iChannel] += framesToReadRightNow; } } else { runningFramesOutInterleaved.f32 += framesToReadRightNow * pResampler->config.channels; } } else { - if (pResampler->config.layout == mal_stream_layout_deinterleaved) { - for (mal_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { + if (pResampler->config.layout == ma_stream_layout_deinterleaved) { + for (ma_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { runningFramesOutDeinterleaved.s16[iChannel] += framesToReadRightNow; } } else { @@ -739,7 +739,7 @@ mal_uint64 mal_resampler_read(mal_resampler* pResampler, mal_uint64 frameCount, need to move the remaining data down to the front of the buffer, adjust the window time, then read more from the client. If we have already reached the end of the client's data, we don't want to attempt to read more. */ - result = mal_resampler__reload_cache(pResampler, &loadedEndOfInput); + result = ma_resampler__reload_cache(pResampler, &loadedEndOfInput); if (result != MA_SUCCESS) { break; /* An error occurred when trying to reload the cache from the client. This does _not_ indicate that the end of the input has been reached. */ } @@ -748,9 +748,9 @@ mal_uint64 mal_resampler_read(mal_resampler* pResampler, mal_uint64 frameCount, return totalFramesRead; } -mal_uint64 mal_resampler_seek(mal_resampler* pResampler, mal_uint64 frameCount, mal_uint32 options) +ma_uint64 ma_resampler_seek(ma_resampler* pResampler, ma_uint64 frameCount, ma_uint32 options) { - mal_uint64 totalFramesSeeked = 0; + ma_uint64 totalFramesSeeked = 0; if (pResampler == NULL) { return 0; /* Invalid args. */ @@ -770,7 +770,7 @@ mal_uint64 mal_resampler_seek(mal_resampler* pResampler, mal_uint64 frameCount, by input rate instead of output rate), all we need to do is change the loaded sample count to the start of the right side of the filter window so that a reload is forced in the next read. */ - pResampler->cacheLengthInFrames = (mal_uint16)ceil(pResampler->windowTime + mal_resampler__window_length_left(pResampler)); + pResampler->cacheLengthInFrames = (ma_uint16)ceil(pResampler->windowTime + ma_resampler__window_length_left(pResampler)); totalFramesSeeked = frameCount; } else { /* We need to read from the client which means we need to loop. */ @@ -791,37 +791,37 @@ mal_uint64 mal_resampler_seek(mal_resampler* pResampler, mal_uint64 frameCount, } -mal_uint64 mal_resampler_get_cached_input_frame_count(mal_resampler* pResampler) +ma_uint64 ma_resampler_get_cached_input_frame_count(ma_resampler* pResampler) { - return (mal_uint64)ceil(mal_resampler_get_cached_input_time(pResampler)); + return (ma_uint64)ceil(ma_resampler_get_cached_input_time(pResampler)); } -mal_uint64 mal_resampler_get_cached_output_frame_count(mal_resampler* pResampler) +ma_uint64 ma_resampler_get_cached_output_frame_count(ma_resampler* pResampler) { - return (mal_uint64)floor(mal_resampler_get_cached_output_time(pResampler)); + return (ma_uint64)floor(ma_resampler_get_cached_output_time(pResampler)); } -double mal_resampler_get_cached_input_time(mal_resampler* pResampler) +double ma_resampler_get_cached_input_time(ma_resampler* pResampler) { if (pResampler == NULL) { return 0; /* Invalid args. */ } - return mal_resampler__calculate_cached_input_time(pResampler); + return ma_resampler__calculate_cached_input_time(pResampler); } -double mal_resampler_get_cached_output_time(mal_resampler* pResampler) +double ma_resampler_get_cached_output_time(ma_resampler* pResampler) { if (pResampler == NULL) { return 0; /* Invalid args. */ } - return mal_resampler__calculate_cached_output_time(pResampler); + return ma_resampler__calculate_cached_output_time(pResampler); } -mal_uint64 mal_resampler_get_required_input_frame_count(mal_resampler* pResampler, mal_uint64 outputFrameCount) +ma_uint64 ma_resampler_get_required_input_frame_count(ma_resampler* pResampler, ma_uint64 outputFrameCount) { if (pResampler == NULL) { return 0; /* Invalid args. */ @@ -832,7 +832,7 @@ mal_uint64 mal_resampler_get_required_input_frame_count(mal_resampler* pResample } /* First grab the amount of output time sitting in the cache. */ - double cachedOutputTime = mal_resampler__calculate_cached_output_time(pResampler); + double cachedOutputTime = ma_resampler__calculate_cached_output_time(pResampler); if (cachedOutputTime >= outputFrameCount) { return 0; /* All of the necessary input data is cached. No additional data is required from the client. */ } @@ -847,15 +847,15 @@ mal_uint64 mal_resampler_get_required_input_frame_count(mal_resampler* pResample The return value must always be larger than 0 after this point. If it's not we have an error. */ double nonCachedOutputTime = outputFrameCount - cachedOutputTime; - mal_assert(nonCachedOutputTime > 0); + ma_assert(nonCachedOutputTime > 0); - mal_uint64 requiredInputFrames = (mal_uint64)ceil(nonCachedOutputTime * pResampler->config.ratio); - mal_assert(requiredInputFrames > 0); + ma_uint64 requiredInputFrames = (ma_uint64)ceil(nonCachedOutputTime * pResampler->config.ratio); + ma_assert(requiredInputFrames > 0); return requiredInputFrames; } -mal_uint64 mal_resampler_get_expected_output_frame_count(mal_resampler* pResampler, mal_uint64 inputFrameCount) +ma_uint64 ma_resampler_get_expected_output_frame_count(ma_resampler* pResampler, ma_uint64 inputFrameCount) { if (pResampler == NULL) { return 0; /* Invalid args. */ @@ -865,17 +865,17 @@ mal_uint64 mal_resampler_get_expected_output_frame_count(mal_resampler* pResampl return 0; } - /* What we're actually calculating here is how many whole output frames will be calculated after consuming inputFrameCount + mal_resampler_get_cached_input_time(). */ - return (mal_uint64)floor((mal_resampler__calculate_cached_input_time(pResampler) + inputFrameCount) / pResampler->config.ratio); + /* What we're actually calculating here is how many whole output frames will be calculated after consuming inputFrameCount + ma_resampler_get_cached_input_time(). */ + return (ma_uint64)floor((ma_resampler__calculate_cached_input_time(pResampler) + inputFrameCount) / pResampler->config.ratio); } /* Linear */ -mal_result mal_resampler_init__linear(mal_resampler* pResampler) +ma_result ma_resampler_init__linear(ma_resampler* pResampler) { - mal_assert(pResampler != NULL); + ma_assert(pResampler != NULL); /* The linear implementation always has a window length of 2. */ pResampler->windowLength = 2; @@ -883,12 +883,12 @@ mal_result mal_resampler_init__linear(mal_resampler* pResampler) return MA_SUCCESS; } -mal_uint64 mal_resampler_read_f32__linear(mal_resampler* pResampler, mal_uint64 frameCount, float** ppFrames) +ma_uint64 ma_resampler_read_f32__linear(ma_resampler* pResampler, ma_uint64 frameCount, float** ppFrames) { - mal_assert(pResampler != NULL); - mal_assert(pResampler->config.onRead != NULL); - mal_assert(frameCount > 0); - mal_assert(ppFrames != NULL); + ma_assert(pResampler != NULL); + ma_assert(pResampler->config.onRead != NULL); + ma_assert(frameCount > 0); + ma_assert(ppFrames != NULL); /* TODO: Implement me. */ (void)pResampler; @@ -897,36 +897,36 @@ mal_uint64 mal_resampler_read_f32__linear(mal_resampler* pResampler, mal_uint64 return 0; } -mal_uint64 mal_resampler_read_s16__linear(mal_resampler* pResampler, mal_uint64 frameCount, mal_int16** ppFrames) +ma_uint64 ma_resampler_read_s16__linear(ma_resampler* pResampler, ma_uint64 frameCount, ma_int16** ppFrames) { - mal_assert(pResampler != NULL); - mal_assert(pResampler->config.onRead != NULL); - mal_assert(frameCount > 0); - mal_assert(ppFrames != NULL); + ma_assert(pResampler != NULL); + ma_assert(pResampler->config.onRead != NULL); + ma_assert(frameCount > 0); + ma_assert(ppFrames != NULL); /* TODO: Implement an s16 optimized implementation. */ /* I'm cheating here and just using the f32 implementation and converting to s16. This will be changed later - for now just focusing on getting it working. */ - float bufferF32[mal_countof(pResampler->cache.s16)]; + float bufferF32[ma_countof(pResampler->cache.s16)]; float* ppFramesF32[MA_MAX_CHANNELS]; - for (mal_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { + for (ma_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { ppFramesF32[iChannel] = bufferF32 + (pResampler->cacheStrideInFrames*iChannel); } - mal_uint64 framesRead = mal_resampler_read_f32__linear(pResampler, frameCount, ppFramesF32); + ma_uint64 framesRead = ma_resampler_read_f32__linear(pResampler, frameCount, ppFramesF32); - for (mal_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { - mal_pcm_f32_to_s16(ppFrames[iChannel], ppFramesF32[iChannel], frameCount, mal_dither_mode_none); /* No dithering - keep it fast for linear. */ + for (ma_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { + ma_pcm_f32_to_s16(ppFrames[iChannel], ppFramesF32[iChannel], frameCount, ma_dither_mode_none); /* No dithering - keep it fast for linear. */ } return framesRead; } -mal_uint64 mal_resampler_seek__linear(mal_resampler* pResampler, mal_uint64 frameCount, mal_uint32 options) +ma_uint64 ma_resampler_seek__linear(ma_resampler* pResampler, ma_uint64 frameCount, ma_uint32 options) { - mal_assert(pResampler != NULL); - mal_assert(pResampler->config.onRead != NULL); - mal_assert(frameCount > 0); + ma_assert(pResampler != NULL); + ma_assert(pResampler->config.onRead != NULL); + ma_assert(frameCount > 0); /* TODO: Implement me. */ (void)pResampler; @@ -939,20 +939,20 @@ mal_uint64 mal_resampler_seek__linear(mal_resampler* pResampler, mal_uint64 fram /* Sinc */ -mal_result mal_resampler_init__sinc(mal_resampler* pResampler) +ma_result ma_resampler_init__sinc(ma_resampler* pResampler) { - mal_assert(pResampler != NULL); + ma_assert(pResampler != NULL); /* TODO: Implement me. Need to initialize the sinc table. */ return MA_SUCCESS; } -mal_uint64 mal_resampler_read_f32__sinc(mal_resampler* pResampler, mal_uint64 frameCount, float** ppFrames) +ma_uint64 ma_resampler_read_f32__sinc(ma_resampler* pResampler, ma_uint64 frameCount, float** ppFrames) { - mal_assert(pResampler != NULL); - mal_assert(pResampler->config.onRead != NULL); - mal_assert(frameCount > 0); - mal_assert(ppFrames != NULL); + ma_assert(pResampler != NULL); + ma_assert(pResampler->config.onRead != NULL); + ma_assert(frameCount > 0); + ma_assert(ppFrames != NULL); /* TODO: Implement me. */ (void)pResampler; @@ -961,36 +961,36 @@ mal_uint64 mal_resampler_read_f32__sinc(mal_resampler* pResampler, mal_uint64 fr return 0; } -mal_uint64 mal_resampler_read_s16__sinc(mal_resampler* pResampler, mal_uint64 frameCount, mal_int16** ppFrames) +ma_uint64 ma_resampler_read_s16__sinc(ma_resampler* pResampler, ma_uint64 frameCount, ma_int16** ppFrames) { - mal_assert(pResampler != NULL); - mal_assert(pResampler->config.onRead != NULL); - mal_assert(frameCount > 0); - mal_assert(ppFrames != NULL); + ma_assert(pResampler != NULL); + ma_assert(pResampler->config.onRead != NULL); + ma_assert(frameCount > 0); + ma_assert(ppFrames != NULL); /* TODO: Implement an s16 optimized implementation. */ /* I'm cheating here and just using the f32 implementation and converting to s16. This will be changed later - for now just focusing on getting it working. */ - float bufferF32[mal_countof(pResampler->cache.s16)]; + float bufferF32[ma_countof(pResampler->cache.s16)]; float* ppFramesF32[MA_MAX_CHANNELS]; - for (mal_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { + for (ma_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { ppFramesF32[iChannel] = bufferF32 + (pResampler->cacheStrideInFrames*iChannel); } - mal_uint64 framesRead = mal_resampler_read_f32__sinc(pResampler, frameCount, ppFramesF32); + ma_uint64 framesRead = ma_resampler_read_f32__sinc(pResampler, frameCount, ppFramesF32); - for (mal_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { - mal_pcm_f32_to_s16(ppFrames[iChannel], ppFramesF32[iChannel], frameCount, mal_dither_mode_triangle); + for (ma_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { + ma_pcm_f32_to_s16(ppFrames[iChannel], ppFramesF32[iChannel], frameCount, ma_dither_mode_triangle); } return framesRead; } -mal_uint64 mal_resampler_seek__sinc(mal_resampler* pResampler, mal_uint64 frameCount, mal_uint32 options) +ma_uint64 ma_resampler_seek__sinc(ma_resampler* pResampler, ma_uint64 frameCount, ma_uint32 options) { - mal_assert(pResampler != NULL); - mal_assert(pResampler->config.onRead != NULL); - mal_assert(frameCount > 0); + ma_assert(pResampler != NULL); + ma_assert(pResampler->config.onRead != NULL); + ma_assert(frameCount > 0); /* TODO: Implement me. */ (void)pResampler; diff --git a/research/mal_ring_buffer.h b/research/mal_ring_buffer.h index 98b62a53..0945bb20 100644 --- a/research/mal_ring_buffer.h +++ b/research/mal_ring_buffer.h @@ -8,28 +8,28 @@ // USAGE // -// - Call mal_rb_init() to initialize a simple buffer, with an optional pre-allocated buffer. If you pass in NULL -// for the pre-allocated buffer, it will be allocated for you and free()'d in mal_rb_uninit(). If you pass in +// - Call ma_rb_init() to initialize a simple buffer, with an optional pre-allocated buffer. If you pass in NULL +// for the pre-allocated buffer, it will be allocated for you and free()'d in ma_rb_uninit(). If you pass in // your own pre-allocated buffer, free()-ing is left to you. // -// - Call mal_rb_init_ex() if you need a deinterleaved buffer. The data for each sub-buffer is offset from each -// other based on the stride. Use mal_rb_get_subbuffer_stride(), mal_rb_get_subbuffer_offset() and -// mal_rb_get_subbuffer_ptr() to manage your sub-buffers. +// - Call ma_rb_init_ex() if you need a deinterleaved buffer. The data for each sub-buffer is offset from each +// other based on the stride. Use ma_rb_get_subbuffer_stride(), ma_rb_get_subbuffer_offset() and +// ma_rb_get_subbuffer_ptr() to manage your sub-buffers. // -// - Use mal_rb_acquire_read() and mal_rb_acquire_write() to retrieve a pointer to a section of the ring buffer. +// - Use ma_rb_acquire_read() and ma_rb_acquire_write() to retrieve a pointer to a section of the ring buffer. // You specify the number of bytes you need, and on output it will set to what was actually acquired. If the // read or write pointer is positioned such that the number of bytes requested will require a loop, it will be // clamped to the end of the buffer. Therefore, the number of bytes you're given may be less than the number // you requested. // -// - After calling mal_rb_acquire_read/write(), you do your work on the buffer and then "commit" it with -// mal_rb_commit_read/write(). This is where the read/write pointers are updated. When you commit you need to -// pass in the buffer that was returned by the earlier call to mal_rb_acquire_read/write() and is only used -// for validation. The number of bytes passed to mal_rb_commit_read/write() is what's used to increment the +// - After calling ma_rb_acquire_read/write(), you do your work on the buffer and then "commit" it with +// ma_rb_commit_read/write(). This is where the read/write pointers are updated. When you commit you need to +// pass in the buffer that was returned by the earlier call to ma_rb_acquire_read/write() and is only used +// for validation. The number of bytes passed to ma_rb_commit_read/write() is what's used to increment the // pointers. // // - If you want to correct for drift between the write pointer and the read pointer you can use a combination -// of mal_rb_pointer_distance(), mal_rb_seek_read() and mal_rb_seek_write(). Note that you can only move the +// of ma_rb_pointer_distance(), ma_rb_seek_read() and ma_rb_seek_write(). Note that you can only move the // pointers forward, and you should only move the read pointer forward via the consumer thread, and the write // pointer forward by the producer thread. If there is too much space between the pointers, move the read // pointer forward. If there is too little space between the pointers, move the write pointer forward. @@ -45,99 +45,99 @@ // - Operates on bytes. May end up adding to higher level helpers for doing everything per audio frame. // - Maximum buffer size is 0x7FFFFFFF-(MA_SIMD_ALIGNMENT-1) because of reasons. -#ifndef mal_ring_buffer_h -#define mal_ring_buffer_h +#ifndef ma_ring_buffer_h +#define ma_ring_buffer_h typedef struct { void* pBuffer; - mal_uint32 subbufferSizeInBytes; - mal_uint32 subbufferCount; - mal_uint32 subbufferStrideInBytes; - volatile mal_uint32 encodedReadOffset; /* Most significant bit is the loop flag. Lower 31 bits contains the actual offset in bytes. */ - volatile mal_uint32 encodedWriteOffset; /* Most significant bit is the loop flag. Lower 31 bits contains the actual offset in bytes. */ - mal_bool32 ownsBuffer : 1; /* Used to know whether or not miniaudio is responsible for free()-ing the buffer. */ - mal_bool32 clearOnWriteAcquire : 1; /* When set, clears the acquired write buffer before returning from mal_rb_acquire_write(). */ -} mal_rb; + ma_uint32 subbufferSizeInBytes; + ma_uint32 subbufferCount; + ma_uint32 subbufferStrideInBytes; + volatile ma_uint32 encodedReadOffset; /* Most significant bit is the loop flag. Lower 31 bits contains the actual offset in bytes. */ + volatile ma_uint32 encodedWriteOffset; /* Most significant bit is the loop flag. Lower 31 bits contains the actual offset in bytes. */ + ma_bool32 ownsBuffer : 1; /* Used to know whether or not miniaudio is responsible for free()-ing the buffer. */ + ma_bool32 clearOnWriteAcquire : 1; /* When set, clears the acquired write buffer before returning from ma_rb_acquire_write(). */ +} ma_rb; -mal_result mal_rb_init_ex(size_t subbufferSizeInBytes, size_t subbufferCount, size_t subbufferStrideInBytes, void* pOptionalPreallocatedBuffer, mal_rb* pRB); -mal_result mal_rb_init(size_t bufferSizeInBytes, void* pOptionalPreallocatedBuffer, mal_rb* pRB); -void mal_rb_uninit(mal_rb* pRB); -mal_result mal_rb_acquire_read(mal_rb* pRB, size_t* pSizeInBytes, void** ppBufferOut); -mal_result mal_rb_commit_read(mal_rb* pRB, size_t sizeInBytes, void* pBufferOut); -mal_result mal_rb_acquire_write(mal_rb* pRB, size_t* pSizeInBytes, void** ppBufferOut); -mal_result mal_rb_commit_write(mal_rb* pRB, size_t sizeInBytes, void* pBufferOut); -mal_result mal_rb_seek_read(mal_rb* pRB, size_t offsetInBytes); -mal_result mal_rb_seek_write(mal_rb* pRB, size_t offsetInBytes); -mal_int32 mal_rb_pointer_distance(mal_rb* pRB); /* Returns the distance between the write pointer and the read pointer. Should never be negative for a correct program. */ -size_t mal_rb_get_subbuffer_stride(mal_rb* pRB); -size_t mal_rb_get_subbuffer_offset(mal_rb* pRB, size_t subbufferIndex); -void* mal_rb_get_subbuffer_ptr(mal_rb* pRB, size_t subbufferIndex, void* pBuffer); +ma_result ma_rb_init_ex(size_t subbufferSizeInBytes, size_t subbufferCount, size_t subbufferStrideInBytes, void* pOptionalPreallocatedBuffer, ma_rb* pRB); +ma_result ma_rb_init(size_t bufferSizeInBytes, void* pOptionalPreallocatedBuffer, ma_rb* pRB); +void ma_rb_uninit(ma_rb* pRB); +ma_result ma_rb_acquire_read(ma_rb* pRB, size_t* pSizeInBytes, void** ppBufferOut); +ma_result ma_rb_commit_read(ma_rb* pRB, size_t sizeInBytes, void* pBufferOut); +ma_result ma_rb_acquire_write(ma_rb* pRB, size_t* pSizeInBytes, void** ppBufferOut); +ma_result ma_rb_commit_write(ma_rb* pRB, size_t sizeInBytes, void* pBufferOut); +ma_result ma_rb_seek_read(ma_rb* pRB, size_t offsetInBytes); +ma_result ma_rb_seek_write(ma_rb* pRB, size_t offsetInBytes); +ma_int32 ma_rb_pointer_distance(ma_rb* pRB); /* Returns the distance between the write pointer and the read pointer. Should never be negative for a correct program. */ +size_t ma_rb_get_subbuffer_stride(ma_rb* pRB); +size_t ma_rb_get_subbuffer_offset(ma_rb* pRB, size_t subbufferIndex); +void* ma_rb_get_subbuffer_ptr(ma_rb* pRB, size_t subbufferIndex, void* pBuffer); typedef struct { - mal_rb rb; - mal_format format; - mal_uint32 channels; -} mal_pcm_rb; + ma_rb rb; + ma_format format; + ma_uint32 channels; +} ma_pcm_rb; -mal_result mal_pcm_rb_init_ex(mal_format format, mal_uint32 channels, size_t subbufferSizeInFrames, size_t subbufferCount, size_t subbufferStrideInFrames, void* pOptionalPreallocatedBuffer, mal_pcm_rb* pRB); -mal_result mal_pcm_rb_init(mal_format format, mal_uint32 channels, size_t bufferSizeInFrames, void* pOptionalPreallocatedBuffer, mal_pcm_rb* pRB); -void mal_pcm_rb_uninit(mal_pcm_rb* pRB); -mal_result mal_pcm_rb_acquire_read(mal_pcm_rb* pRB, size_t* pSizeInFrames, void** ppBufferOut); -mal_result mal_pcm_rb_commit_read(mal_pcm_rb* pRB, size_t sizeInFrames, void* pBufferOut); -mal_result mal_pcm_rb_acquire_write(mal_pcm_rb* pRB, size_t* pSizeInFrames, void** ppBufferOut); -mal_result mal_pcm_rb_commit_write(mal_pcm_rb* pRB, size_t sizeInFrames, void* pBufferOut); -mal_result mal_pcm_rb_seek_read(mal_pcm_rb* pRB, size_t offsetInFrames); -mal_result mal_pcm_rb_seek_write(mal_pcm_rb* pRB, size_t offsetInFrames); -mal_int32 mal_pcm_rb_pointer_disance(mal_pcm_rb* pRB); /* Return value is in frames. */ -size_t mal_pcm_rb_get_subbuffer_stride(mal_pcm_rb* pRB); -size_t mal_pcm_rb_get_subbuffer_offset(mal_pcm_rb* pRB, size_t subbufferIndex); -void* mal_pcm_rb_get_subbuffer_ptr(mal_pcm_rb* pRB, size_t subbufferIndex, void* pBuffer); +ma_result ma_pcm_rb_init_ex(ma_format format, ma_uint32 channels, size_t subbufferSizeInFrames, size_t subbufferCount, size_t subbufferStrideInFrames, void* pOptionalPreallocatedBuffer, ma_pcm_rb* pRB); +ma_result ma_pcm_rb_init(ma_format format, ma_uint32 channels, size_t bufferSizeInFrames, void* pOptionalPreallocatedBuffer, ma_pcm_rb* pRB); +void ma_pcm_rb_uninit(ma_pcm_rb* pRB); +ma_result ma_pcm_rb_acquire_read(ma_pcm_rb* pRB, size_t* pSizeInFrames, void** ppBufferOut); +ma_result ma_pcm_rb_commit_read(ma_pcm_rb* pRB, size_t sizeInFrames, void* pBufferOut); +ma_result ma_pcm_rb_acquire_write(ma_pcm_rb* pRB, size_t* pSizeInFrames, void** ppBufferOut); +ma_result ma_pcm_rb_commit_write(ma_pcm_rb* pRB, size_t sizeInFrames, void* pBufferOut); +ma_result ma_pcm_rb_seek_read(ma_pcm_rb* pRB, size_t offsetInFrames); +ma_result ma_pcm_rb_seek_write(ma_pcm_rb* pRB, size_t offsetInFrames); +ma_int32 ma_pcm_rb_pointer_disance(ma_pcm_rb* pRB); /* Return value is in frames. */ +size_t ma_pcm_rb_get_subbuffer_stride(ma_pcm_rb* pRB); +size_t ma_pcm_rb_get_subbuffer_offset(ma_pcm_rb* pRB, size_t subbufferIndex); +void* ma_pcm_rb_get_subbuffer_ptr(ma_pcm_rb* pRB, size_t subbufferIndex, void* pBuffer); -#endif // mal_ring_buffer_h +#endif // ma_ring_buffer_h #ifdef MINIAUDIO_IMPLEMENTATION -MA_INLINE mal_uint32 mal_rb__extract_offset_in_bytes(mal_uint32 encodedOffset) +MA_INLINE ma_uint32 ma_rb__extract_offset_in_bytes(ma_uint32 encodedOffset) { return encodedOffset & 0x7FFFFFFF; } -MA_INLINE mal_uint32 mal_rb__extract_offset_loop_flag(mal_uint32 encodedOffset) +MA_INLINE ma_uint32 ma_rb__extract_offset_loop_flag(ma_uint32 encodedOffset) { return encodedOffset & 0x80000000; } -MA_INLINE void* mal_rb__get_read_ptr(mal_rb* pRB) +MA_INLINE void* ma_rb__get_read_ptr(ma_rb* pRB) { - mal_assert(pRB != NULL); - return mal_offset_ptr(pRB->pBuffer, mal_rb__extract_offset_in_bytes(pRB->encodedReadOffset)); + ma_assert(pRB != NULL); + return ma_offset_ptr(pRB->pBuffer, ma_rb__extract_offset_in_bytes(pRB->encodedReadOffset)); } -MA_INLINE void* mal_rb__get_write_ptr(mal_rb* pRB) +MA_INLINE void* ma_rb__get_write_ptr(ma_rb* pRB) { - mal_assert(pRB != NULL); - return mal_offset_ptr(pRB->pBuffer, mal_rb__extract_offset_in_bytes(pRB->encodedWriteOffset)); + ma_assert(pRB != NULL); + return ma_offset_ptr(pRB->pBuffer, ma_rb__extract_offset_in_bytes(pRB->encodedWriteOffset)); } -MA_INLINE mal_uint32 mal_rb__construct_offset(mal_uint32 offsetInBytes, mal_uint32 offsetLoopFlag) +MA_INLINE ma_uint32 ma_rb__construct_offset(ma_uint32 offsetInBytes, ma_uint32 offsetLoopFlag) { return offsetLoopFlag | offsetInBytes; } -MA_INLINE void mal_rb__deconstruct_offset(mal_uint32 encodedOffset, mal_uint32* pOffsetInBytes, mal_uint32* pOffsetLoopFlag) +MA_INLINE void ma_rb__deconstruct_offset(ma_uint32 encodedOffset, ma_uint32* pOffsetInBytes, ma_uint32* pOffsetLoopFlag) { - mal_assert(pOffsetInBytes != NULL); - mal_assert(pOffsetLoopFlag != NULL); + ma_assert(pOffsetInBytes != NULL); + ma_assert(pOffsetLoopFlag != NULL); - *pOffsetInBytes = mal_rb__extract_offset_in_bytes(encodedOffset); - *pOffsetLoopFlag = mal_rb__extract_offset_loop_flag(encodedOffset); + *pOffsetInBytes = ma_rb__extract_offset_in_bytes(encodedOffset); + *pOffsetLoopFlag = ma_rb__extract_offset_loop_flag(encodedOffset); } -mal_result mal_rb_init_ex(size_t subbufferSizeInBytes, size_t subbufferCount, size_t subbufferStrideInBytes, void* pOptionalPreallocatedBuffer, mal_rb* pRB) +ma_result ma_rb_init_ex(size_t subbufferSizeInBytes, size_t subbufferCount, size_t subbufferStrideInBytes, void* pOptionalPreallocatedBuffer, ma_rb* pRB) { if (pRB == NULL) { return MA_INVALID_ARGS; @@ -147,18 +147,18 @@ mal_result mal_rb_init_ex(size_t subbufferSizeInBytes, size_t subbufferCount, si return MA_INVALID_ARGS; } - const mal_uint32 maxSubBufferSize = 0x7FFFFFFF - (MA_SIMD_ALIGNMENT-1); + const ma_uint32 maxSubBufferSize = 0x7FFFFFFF - (MA_SIMD_ALIGNMENT-1); if (subbufferSizeInBytes > maxSubBufferSize) { return MA_INVALID_ARGS; // Maximum buffer size is ~2GB. The most significant bit is a flag for use internally. } - mal_zero_object(pRB); - pRB->subbufferSizeInBytes = (mal_uint32)subbufferSizeInBytes; - pRB->subbufferCount = (mal_uint32)subbufferCount; + ma_zero_object(pRB); + pRB->subbufferSizeInBytes = (ma_uint32)subbufferSizeInBytes; + pRB->subbufferCount = (ma_uint32)subbufferCount; if (pOptionalPreallocatedBuffer != NULL) { - pRB->subbufferStrideInBytes = (mal_uint32)subbufferStrideInBytes; + pRB->subbufferStrideInBytes = (ma_uint32)subbufferStrideInBytes; pRB->pBuffer = pOptionalPreallocatedBuffer; } else { // Here is where we allocate our own buffer. We always want to align this to MA_SIMD_ALIGNMENT for future SIMD optimization opportunity. To do this @@ -166,50 +166,50 @@ mal_result mal_rb_init_ex(size_t subbufferSizeInBytes, size_t subbufferCount, si pRB->subbufferStrideInBytes = (pRB->subbufferSizeInBytes + (MA_SIMD_ALIGNMENT-1)) & ~MA_SIMD_ALIGNMENT; size_t bufferSizeInBytes = (size_t)pRB->subbufferCount*pRB->subbufferStrideInBytes; - pRB->pBuffer = mal_aligned_malloc(bufferSizeInBytes, MA_SIMD_ALIGNMENT); + pRB->pBuffer = ma_aligned_malloc(bufferSizeInBytes, MA_SIMD_ALIGNMENT); if (pRB->pBuffer == NULL) { return MA_OUT_OF_MEMORY; } - mal_zero_memory(pRB->pBuffer, bufferSizeInBytes); + ma_zero_memory(pRB->pBuffer, bufferSizeInBytes); pRB->ownsBuffer = MA_TRUE; } return MA_SUCCESS; } -mal_result mal_rb_init(size_t bufferSizeInBytes, void* pOptionalPreallocatedBuffer, mal_rb* pRB) +ma_result ma_rb_init(size_t bufferSizeInBytes, void* pOptionalPreallocatedBuffer, ma_rb* pRB) { - return mal_rb_init_ex(bufferSizeInBytes, 1, 0, pOptionalPreallocatedBuffer, pRB); + return ma_rb_init_ex(bufferSizeInBytes, 1, 0, pOptionalPreallocatedBuffer, pRB); } -void mal_rb_uninit(mal_rb* pRB) +void ma_rb_uninit(ma_rb* pRB) { if (pRB == NULL) { return; } if (pRB->ownsBuffer) { - mal_free(pRB->pBuffer); + ma_free(pRB->pBuffer); } } -mal_result mal_rb_acquire_read(mal_rb* pRB, size_t* pSizeInBytes, void** ppBufferOut) +ma_result ma_rb_acquire_read(ma_rb* pRB, size_t* pSizeInBytes, void** ppBufferOut) { if (pRB == NULL || pSizeInBytes == NULL || ppBufferOut == NULL) { return MA_INVALID_ARGS; } // The returned buffer should never move ahead of the write pointer. - mal_uint32 writeOffset = pRB->encodedWriteOffset; - mal_uint32 writeOffsetInBytes; - mal_uint32 writeOffsetLoopFlag; - mal_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag); + ma_uint32 writeOffset = pRB->encodedWriteOffset; + ma_uint32 writeOffsetInBytes; + ma_uint32 writeOffsetLoopFlag; + ma_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag); - mal_uint32 readOffset = pRB->encodedReadOffset; - mal_uint32 readOffsetInBytes; - mal_uint32 readOffsetLoopFlag; - mal_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag); + ma_uint32 readOffset = pRB->encodedReadOffset; + ma_uint32 readOffsetInBytes; + ma_uint32 readOffsetLoopFlag; + ma_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag); // The number of bytes available depends on whether or not the read and write pointers are on the same loop iteration. If so, we // can only read up to the write pointer. If not, we can only read up to the end of the buffer. @@ -226,60 +226,60 @@ mal_result mal_rb_acquire_read(mal_rb* pRB, size_t* pSizeInBytes, void** ppBuffe } *pSizeInBytes = bytesRequested; - (*ppBufferOut) = mal_rb__get_read_ptr(pRB); + (*ppBufferOut) = ma_rb__get_read_ptr(pRB); return MA_SUCCESS; } -mal_result mal_rb_commit_read(mal_rb* pRB, size_t sizeInBytes, void* pBufferOut) +ma_result ma_rb_commit_read(ma_rb* pRB, size_t sizeInBytes, void* pBufferOut) { if (pRB == NULL) { return MA_INVALID_ARGS; } // Validate the buffer. - if (pBufferOut != mal_rb__get_read_ptr(pRB)) { + if (pBufferOut != ma_rb__get_read_ptr(pRB)) { return MA_INVALID_ARGS; } - mal_uint32 readOffset = pRB->encodedReadOffset; - mal_uint32 readOffsetInBytes; - mal_uint32 readOffsetLoopFlag; - mal_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag); + ma_uint32 readOffset = pRB->encodedReadOffset; + ma_uint32 readOffsetInBytes; + ma_uint32 readOffsetLoopFlag; + ma_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag); // Check that sizeInBytes is correct. It should never go beyond the end of the buffer. - mal_uint32 newReadOffsetInBytes = (mal_uint32)(readOffsetInBytes + sizeInBytes); + ma_uint32 newReadOffsetInBytes = (ma_uint32)(readOffsetInBytes + sizeInBytes); if (newReadOffsetInBytes > pRB->subbufferSizeInBytes) { return MA_INVALID_ARGS; // <-- sizeInBytes will cause the read offset to overflow. } // Move the read pointer back to the start if necessary. - mal_uint32 newReadOffsetLoopFlag = readOffsetLoopFlag; + ma_uint32 newReadOffsetLoopFlag = readOffsetLoopFlag; if (newReadOffsetInBytes == pRB->subbufferSizeInBytes) { newReadOffsetInBytes = 0; newReadOffsetLoopFlag ^= 0x80000000; } - mal_atomic_exchange_32(&pRB->encodedReadOffset, mal_rb__construct_offset(newReadOffsetLoopFlag, newReadOffsetInBytes)); + ma_atomic_exchange_32(&pRB->encodedReadOffset, ma_rb__construct_offset(newReadOffsetLoopFlag, newReadOffsetInBytes)); return MA_SUCCESS; } -mal_result mal_rb_acquire_write(mal_rb* pRB, size_t* pSizeInBytes, void** ppBufferOut) +ma_result ma_rb_acquire_write(ma_rb* pRB, size_t* pSizeInBytes, void** ppBufferOut) { if (pRB == NULL || pSizeInBytes == NULL || ppBufferOut == NULL) { return MA_INVALID_ARGS; } // The returned buffer should never overtake the read buffer. - mal_uint32 readOffset = pRB->encodedReadOffset; - mal_uint32 readOffsetInBytes; - mal_uint32 readOffsetLoopFlag; - mal_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag); + ma_uint32 readOffset = pRB->encodedReadOffset; + ma_uint32 readOffsetInBytes; + ma_uint32 readOffsetLoopFlag; + ma_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag); - mal_uint32 writeOffset = pRB->encodedWriteOffset; - mal_uint32 writeOffsetInBytes; - mal_uint32 writeOffsetLoopFlag; - mal_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag); + ma_uint32 writeOffset = pRB->encodedWriteOffset; + ma_uint32 writeOffsetInBytes; + ma_uint32 writeOffsetLoopFlag; + ma_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag); // In the case of writing, if the write pointer and the read pointer are on the same loop iteration we can only // write up to the end of the buffer. Otherwise we can only write up to the read pointer. The write pointer should @@ -297,144 +297,144 @@ mal_result mal_rb_acquire_write(mal_rb* pRB, size_t* pSizeInBytes, void** ppBuff } *pSizeInBytes = bytesRequested; - *ppBufferOut = mal_rb__get_write_ptr(pRB); + *ppBufferOut = ma_rb__get_write_ptr(pRB); // Clear the buffer if desired. if (pRB->clearOnWriteAcquire) { - mal_zero_memory(*ppBufferOut, *pSizeInBytes); + ma_zero_memory(*ppBufferOut, *pSizeInBytes); } return MA_SUCCESS; } -mal_result mal_rb_commit_write(mal_rb* pRB, size_t sizeInBytes, void* pBufferOut) +ma_result ma_rb_commit_write(ma_rb* pRB, size_t sizeInBytes, void* pBufferOut) { if (pRB == NULL) { return MA_INVALID_ARGS; } // Validate the buffer. - if (pBufferOut != mal_rb__get_write_ptr(pRB)) { + if (pBufferOut != ma_rb__get_write_ptr(pRB)) { return MA_INVALID_ARGS; } - mal_uint32 writeOffset = pRB->encodedWriteOffset; - mal_uint32 writeOffsetInBytes; - mal_uint32 writeOffsetLoopFlag; - mal_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag); + ma_uint32 writeOffset = pRB->encodedWriteOffset; + ma_uint32 writeOffsetInBytes; + ma_uint32 writeOffsetLoopFlag; + ma_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag); // Check that sizeInBytes is correct. It should never go beyond the end of the buffer. - mal_uint32 newWriteOffsetInBytes = (mal_uint32)(writeOffsetInBytes + sizeInBytes); + ma_uint32 newWriteOffsetInBytes = (ma_uint32)(writeOffsetInBytes + sizeInBytes); if (newWriteOffsetInBytes > pRB->subbufferSizeInBytes) { return MA_INVALID_ARGS; // <-- sizeInBytes will cause the read offset to overflow. } // Move the read pointer back to the start if necessary. - mal_uint32 newWriteOffsetLoopFlag = writeOffsetLoopFlag; + ma_uint32 newWriteOffsetLoopFlag = writeOffsetLoopFlag; if (newWriteOffsetInBytes == pRB->subbufferSizeInBytes) { newWriteOffsetInBytes = 0; newWriteOffsetLoopFlag ^= 0x80000000; } - mal_atomic_exchange_32(&pRB->encodedWriteOffset, mal_rb__construct_offset(newWriteOffsetLoopFlag, newWriteOffsetInBytes)); + ma_atomic_exchange_32(&pRB->encodedWriteOffset, ma_rb__construct_offset(newWriteOffsetLoopFlag, newWriteOffsetInBytes)); return MA_SUCCESS; } -mal_result mal_rb_seek_read(mal_rb* pRB, size_t offsetInBytes) +ma_result ma_rb_seek_read(ma_rb* pRB, size_t offsetInBytes) { if (pRB == NULL || offsetInBytes > pRB->subbufferSizeInBytes) { return MA_INVALID_ARGS; } - mal_uint32 readOffset = pRB->encodedReadOffset; - mal_uint32 readOffsetInBytes; - mal_uint32 readOffsetLoopFlag; - mal_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag); + ma_uint32 readOffset = pRB->encodedReadOffset; + ma_uint32 readOffsetInBytes; + ma_uint32 readOffsetLoopFlag; + ma_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag); - mal_uint32 writeOffset = pRB->encodedWriteOffset; - mal_uint32 writeOffsetInBytes; - mal_uint32 writeOffsetLoopFlag; - mal_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag); + ma_uint32 writeOffset = pRB->encodedWriteOffset; + ma_uint32 writeOffsetInBytes; + ma_uint32 writeOffsetLoopFlag; + ma_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag); - mal_uint32 newReadOffsetInBytes = readOffsetInBytes; - mal_uint32 newReadOffsetLoopFlag = readOffsetLoopFlag; + ma_uint32 newReadOffsetInBytes = readOffsetInBytes; + ma_uint32 newReadOffsetLoopFlag = readOffsetLoopFlag; // We cannot go past the write buffer. if (readOffsetLoopFlag == writeOffsetLoopFlag) { if ((readOffsetInBytes + offsetInBytes) > writeOffsetInBytes) { newReadOffsetInBytes = writeOffsetInBytes; } else { - newReadOffsetInBytes = (mal_uint32)(readOffsetInBytes + offsetInBytes); + newReadOffsetInBytes = (ma_uint32)(readOffsetInBytes + offsetInBytes); } } else { // May end up looping. if ((readOffsetInBytes + offsetInBytes) >= pRB->subbufferSizeInBytes) { - newReadOffsetInBytes = (mal_uint32)(readOffsetInBytes + offsetInBytes) - pRB->subbufferSizeInBytes; + newReadOffsetInBytes = (ma_uint32)(readOffsetInBytes + offsetInBytes) - pRB->subbufferSizeInBytes; newReadOffsetLoopFlag ^= 0x80000000; /* <-- Looped. */ } else { - newReadOffsetInBytes = (mal_uint32)(readOffsetInBytes + offsetInBytes); + newReadOffsetInBytes = (ma_uint32)(readOffsetInBytes + offsetInBytes); } } - mal_atomic_exchange_32(&pRB->encodedReadOffset, mal_rb__construct_offset(newReadOffsetInBytes, newReadOffsetLoopFlag)); + ma_atomic_exchange_32(&pRB->encodedReadOffset, ma_rb__construct_offset(newReadOffsetInBytes, newReadOffsetLoopFlag)); return MA_SUCCESS; } -mal_result mal_rb_seek_write(mal_rb* pRB, size_t offsetInBytes) +ma_result ma_rb_seek_write(ma_rb* pRB, size_t offsetInBytes) { if (pRB == NULL) { return MA_INVALID_ARGS; } - mal_uint32 readOffset = pRB->encodedReadOffset; - mal_uint32 readOffsetInBytes; - mal_uint32 readOffsetLoopFlag; - mal_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag); + ma_uint32 readOffset = pRB->encodedReadOffset; + ma_uint32 readOffsetInBytes; + ma_uint32 readOffsetLoopFlag; + ma_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag); - mal_uint32 writeOffset = pRB->encodedWriteOffset; - mal_uint32 writeOffsetInBytes; - mal_uint32 writeOffsetLoopFlag; - mal_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag); + ma_uint32 writeOffset = pRB->encodedWriteOffset; + ma_uint32 writeOffsetInBytes; + ma_uint32 writeOffsetLoopFlag; + ma_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag); - mal_uint32 newWriteOffsetInBytes = writeOffsetInBytes; - mal_uint32 newWriteOffsetLoopFlag = writeOffsetLoopFlag; + ma_uint32 newWriteOffsetInBytes = writeOffsetInBytes; + ma_uint32 newWriteOffsetLoopFlag = writeOffsetLoopFlag; // We cannot go past the write buffer. if (readOffsetLoopFlag == writeOffsetLoopFlag) { // May end up looping. if ((writeOffsetInBytes + offsetInBytes) >= pRB->subbufferSizeInBytes) { - newWriteOffsetInBytes = (mal_uint32)(writeOffsetInBytes + offsetInBytes) - pRB->subbufferSizeInBytes; + newWriteOffsetInBytes = (ma_uint32)(writeOffsetInBytes + offsetInBytes) - pRB->subbufferSizeInBytes; newWriteOffsetLoopFlag ^= 0x80000000; /* <-- Looped. */ } else { - newWriteOffsetInBytes = (mal_uint32)(writeOffsetInBytes + offsetInBytes); + newWriteOffsetInBytes = (ma_uint32)(writeOffsetInBytes + offsetInBytes); } } else { if ((writeOffsetInBytes + offsetInBytes) > readOffsetInBytes) { newWriteOffsetInBytes = readOffsetInBytes; } else { - newWriteOffsetInBytes = (mal_uint32)(writeOffsetInBytes + offsetInBytes); + newWriteOffsetInBytes = (ma_uint32)(writeOffsetInBytes + offsetInBytes); } } - mal_atomic_exchange_32(&pRB->encodedWriteOffset, mal_rb__construct_offset(newWriteOffsetInBytes, newWriteOffsetLoopFlag)); + ma_atomic_exchange_32(&pRB->encodedWriteOffset, ma_rb__construct_offset(newWriteOffsetInBytes, newWriteOffsetLoopFlag)); return MA_SUCCESS; } -mal_int32 mal_rb_pointer_distance(mal_rb* pRB) +ma_int32 ma_rb_pointer_distance(ma_rb* pRB) { if (pRB == NULL) { return 0; } - mal_uint32 readOffset = pRB->encodedReadOffset; - mal_uint32 readOffsetInBytes; - mal_uint32 readOffsetLoopFlag; - mal_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag); + ma_uint32 readOffset = pRB->encodedReadOffset; + ma_uint32 readOffsetInBytes; + ma_uint32 readOffsetLoopFlag; + ma_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag); - mal_uint32 writeOffset = pRB->encodedWriteOffset; - mal_uint32 writeOffsetInBytes; - mal_uint32 writeOffsetLoopFlag; - mal_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag); + ma_uint32 writeOffset = pRB->encodedWriteOffset; + ma_uint32 writeOffsetInBytes; + ma_uint32 writeOffsetLoopFlag; + ma_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag); if (readOffsetLoopFlag == writeOffsetLoopFlag) { return writeOffsetInBytes - readOffsetInBytes; @@ -443,7 +443,7 @@ mal_int32 mal_rb_pointer_distance(mal_rb* pRB) } } -size_t mal_rb_get_subbuffer_stride(mal_rb* pRB) +size_t ma_rb_get_subbuffer_stride(ma_rb* pRB) { if (pRB == NULL) { return 0; @@ -456,48 +456,48 @@ size_t mal_rb_get_subbuffer_stride(mal_rb* pRB) return (size_t)pRB->subbufferStrideInBytes; } -size_t mal_rb_get_subbuffer_offset(mal_rb* pRB, size_t subbufferIndex) +size_t ma_rb_get_subbuffer_offset(ma_rb* pRB, size_t subbufferIndex) { if (pRB == NULL) { return 0; } - return subbufferIndex * mal_rb_get_subbuffer_stride(pRB); + return subbufferIndex * ma_rb_get_subbuffer_stride(pRB); } -void* mal_rb_get_subbuffer_ptr(mal_rb* pRB, size_t subbufferIndex, void* pBuffer) +void* ma_rb_get_subbuffer_ptr(ma_rb* pRB, size_t subbufferIndex, void* pBuffer) { if (pRB == NULL) { return NULL; } - return mal_offset_ptr(pBuffer, mal_rb_get_subbuffer_offset(pRB, subbufferIndex)); + return ma_offset_ptr(pBuffer, ma_rb_get_subbuffer_offset(pRB, subbufferIndex)); } -/* mal_pcm_rb */ +/* ma_pcm_rb */ -mal_uint32 mal_pcm_rb_get_bpf(mal_pcm_rb* pRB) +ma_uint32 ma_pcm_rb_get_bpf(ma_pcm_rb* pRB) { - mal_assert(pRB != NULL); + ma_assert(pRB != NULL); - return mal_get_bytes_per_frame(pRB->format, pRB->channels); + return ma_get_bytes_per_frame(pRB->format, pRB->channels); } -mal_result mal_pcm_rb_init_ex(mal_format format, mal_uint32 channels, size_t subbufferSizeInFrames, size_t subbufferCount, size_t subbufferStrideInFrames, void* pOptionalPreallocatedBuffer, mal_pcm_rb* pRB) +ma_result ma_pcm_rb_init_ex(ma_format format, ma_uint32 channels, size_t subbufferSizeInFrames, size_t subbufferCount, size_t subbufferStrideInFrames, void* pOptionalPreallocatedBuffer, ma_pcm_rb* pRB) { if (pRB == NULL) { return MA_INVALID_ARGS; } - mal_zero_object(pRB); + ma_zero_object(pRB); - mal_uint32 bpf = mal_get_bytes_per_frame(format, channels); + ma_uint32 bpf = ma_get_bytes_per_frame(format, channels); if (bpf == 0) { return MA_INVALID_ARGS; } - mal_result result = mal_rb_init_ex(subbufferSizeInFrames*bpf, subbufferCount, subbufferStrideInFrames*bpf, pOptionalPreallocatedBuffer, &pRB->rb); + ma_result result = ma_rb_init_ex(subbufferSizeInFrames*bpf, subbufferCount, subbufferStrideInFrames*bpf, pOptionalPreallocatedBuffer, &pRB->rb); if (result != MA_SUCCESS) { return result; } @@ -508,130 +508,130 @@ mal_result mal_pcm_rb_init_ex(mal_format format, mal_uint32 channels, size_t sub return MA_SUCCESS; } -mal_result mal_pcm_rb_init(mal_format format, mal_uint32 channels, size_t bufferSizeInFrames, void* pOptionalPreallocatedBuffer, mal_pcm_rb* pRB) +ma_result ma_pcm_rb_init(ma_format format, ma_uint32 channels, size_t bufferSizeInFrames, void* pOptionalPreallocatedBuffer, ma_pcm_rb* pRB) { - return mal_pcm_rb_init_ex(format, channels, bufferSizeInFrames, 1, 0, pOptionalPreallocatedBuffer, pRB); + return ma_pcm_rb_init_ex(format, channels, bufferSizeInFrames, 1, 0, pOptionalPreallocatedBuffer, pRB); } -void mal_pcm_rb_uninit(mal_pcm_rb* pRB) +void ma_pcm_rb_uninit(ma_pcm_rb* pRB) { if (pRB == NULL) { return; } - mal_rb_uninit(&pRB->rb); + ma_rb_uninit(&pRB->rb); } -mal_result mal_pcm_rb_acquire_read(mal_pcm_rb* pRB, size_t* pSizeInFrames, void** ppBufferOut) +ma_result ma_pcm_rb_acquire_read(ma_pcm_rb* pRB, size_t* pSizeInFrames, void** ppBufferOut) { size_t sizeInBytes; - mal_result result; + ma_result result; if (pRB == NULL || pSizeInFrames == NULL) { return MA_INVALID_ARGS; } - sizeInBytes = *pSizeInFrames * mal_pcm_rb_get_bpf(pRB); + sizeInBytes = *pSizeInFrames * ma_pcm_rb_get_bpf(pRB); - result = mal_rb_acquire_read(&pRB->rb, &sizeInBytes, ppBufferOut); + result = ma_rb_acquire_read(&pRB->rb, &sizeInBytes, ppBufferOut); if (result != MA_SUCCESS) { return result; } - *pSizeInFrames = sizeInBytes / mal_pcm_rb_get_bpf(pRB); + *pSizeInFrames = sizeInBytes / ma_pcm_rb_get_bpf(pRB); return MA_SUCCESS; } -mal_result mal_pcm_rb_commit_read(mal_pcm_rb* pRB, size_t sizeInFrames, void* pBufferOut) +ma_result ma_pcm_rb_commit_read(ma_pcm_rb* pRB, size_t sizeInFrames, void* pBufferOut) { if (pRB == NULL) { return MA_INVALID_ARGS; } - return mal_rb_commit_read(&pRB->rb, sizeInFrames * mal_pcm_rb_get_bpf(pRB), pBufferOut); + return ma_rb_commit_read(&pRB->rb, sizeInFrames * ma_pcm_rb_get_bpf(pRB), pBufferOut); } -mal_result mal_pcm_rb_acquire_write(mal_pcm_rb* pRB, size_t* pSizeInFrames, void** ppBufferOut) +ma_result ma_pcm_rb_acquire_write(ma_pcm_rb* pRB, size_t* pSizeInFrames, void** ppBufferOut) { size_t sizeInBytes; - mal_result result; + ma_result result; if (pRB == NULL) { return MA_INVALID_ARGS; } - sizeInBytes = *pSizeInFrames * mal_pcm_rb_get_bpf(pRB); + sizeInBytes = *pSizeInFrames * ma_pcm_rb_get_bpf(pRB); - result = mal_rb_acquire_write(&pRB->rb, &sizeInBytes, ppBufferOut); + result = ma_rb_acquire_write(&pRB->rb, &sizeInBytes, ppBufferOut); if (result != MA_SUCCESS) { return result; } - *pSizeInFrames = sizeInBytes / mal_pcm_rb_get_bpf(pRB); + *pSizeInFrames = sizeInBytes / ma_pcm_rb_get_bpf(pRB); return MA_SUCCESS; } -mal_result mal_pcm_rb_commit_write(mal_pcm_rb* pRB, size_t sizeInFrames, void* pBufferOut) +ma_result ma_pcm_rb_commit_write(ma_pcm_rb* pRB, size_t sizeInFrames, void* pBufferOut) { if (pRB == NULL) { return MA_INVALID_ARGS; } - return mal_rb_commit_write(&pRB->rb, sizeInFrames * mal_pcm_rb_get_bpf(pRB), pBufferOut); + return ma_rb_commit_write(&pRB->rb, sizeInFrames * ma_pcm_rb_get_bpf(pRB), pBufferOut); } -mal_result mal_pcm_rb_seek_read(mal_pcm_rb* pRB, size_t offsetInFrames) +ma_result ma_pcm_rb_seek_read(ma_pcm_rb* pRB, size_t offsetInFrames) { if (pRB == NULL) { return MA_INVALID_ARGS; } - return mal_rb_seek_read(&pRB->rb, offsetInFrames * mal_pcm_rb_get_bpf(pRB)); + return ma_rb_seek_read(&pRB->rb, offsetInFrames * ma_pcm_rb_get_bpf(pRB)); } -mal_result mal_pcm_rb_seek_write(mal_pcm_rb* pRB, size_t offsetInFrames) +ma_result ma_pcm_rb_seek_write(ma_pcm_rb* pRB, size_t offsetInFrames) { if (pRB == NULL) { return MA_INVALID_ARGS; } - return mal_rb_seek_write(&pRB->rb, offsetInFrames * mal_pcm_rb_get_bpf(pRB)); + return ma_rb_seek_write(&pRB->rb, offsetInFrames * ma_pcm_rb_get_bpf(pRB)); } -mal_int32 mal_pcm_rb_pointer_disance(mal_pcm_rb* pRB) +ma_int32 ma_pcm_rb_pointer_disance(ma_pcm_rb* pRB) { if (pRB == NULL) { return MA_INVALID_ARGS; } - return mal_rb_pointer_distance(&pRB->rb) / mal_pcm_rb_get_bpf(pRB); + return ma_rb_pointer_distance(&pRB->rb) / ma_pcm_rb_get_bpf(pRB); } -size_t mal_pcm_rb_get_subbuffer_stride(mal_pcm_rb* pRB) +size_t ma_pcm_rb_get_subbuffer_stride(ma_pcm_rb* pRB) { if (pRB == NULL) { return 0; } - return mal_rb_get_subbuffer_stride(&pRB->rb) / mal_pcm_rb_get_bpf(pRB); + return ma_rb_get_subbuffer_stride(&pRB->rb) / ma_pcm_rb_get_bpf(pRB); } -size_t mal_pcm_rb_get_subbuffer_offset(mal_pcm_rb* pRB, size_t subbufferIndex) +size_t ma_pcm_rb_get_subbuffer_offset(ma_pcm_rb* pRB, size_t subbufferIndex) { if (pRB == NULL) { return 0; } - return mal_rb_get_subbuffer_offset(&pRB->rb, subbufferIndex) / mal_pcm_rb_get_bpf(pRB); + return ma_rb_get_subbuffer_offset(&pRB->rb, subbufferIndex) / ma_pcm_rb_get_bpf(pRB); } -void* mal_pcm_rb_get_subbuffer_ptr(mal_pcm_rb* pRB, size_t subbufferIndex, void* pBuffer) +void* ma_pcm_rb_get_subbuffer_ptr(ma_pcm_rb* pRB, size_t subbufferIndex, void* pBuffer) { if (pRB == NULL) { return NULL; } - return mal_rb_get_subbuffer_ptr(&pRB->rb, subbufferIndex, pBuffer); + return ma_rb_get_subbuffer_ptr(&pRB->rb, subbufferIndex, pBuffer); } #endif // MINIAUDIO_IMPLEMENTATION diff --git a/research/tests/mal_resampler_test_0.c b/research/tests/mal_resampler_test_0.c index 637d6322..d775dc48 100644 --- a/research/tests/mal_resampler_test_0.c +++ b/research/tests/mal_resampler_test_0.c @@ -4,46 +4,46 @@ #define MA_DEBUG_OUTPUT #define MINIAUDIO_IMPLEMENTATION #include "../../miniaudio.h" -#include "../mal_resampler.h" +#include "../ma_resampler.h" #define SAMPLE_RATE_IN 44100 #define SAMPLE_RATE_OUT 44100 #define CHANNELS 1 #define OUTPUT_FILE "output.wav" -mal_sine_wave sineWave; +ma_sine_wave sineWave; -mal_uint32 on_read(mal_resampler* pResampler, mal_uint32 frameCount, void** ppFramesOut) +ma_uint32 on_read(ma_resampler* pResampler, ma_uint32 frameCount, void** ppFramesOut) { - mal_assert(pResampler->config.format == mal_format_f32); + ma_assert(pResampler->config.format == ma_format_f32); - return (mal_uint32)mal_sine_wave_read_f32_ex(&sineWave, frameCount, pResampler->config.channels, pResampler->config.layout, (float**)ppFramesOut); + return (ma_uint32)ma_sine_wave_read_f32_ex(&sineWave, frameCount, pResampler->config.channels, pResampler->config.layout, (float**)ppFramesOut); } int main(int argc, char** argv) { - mal_result result; - mal_resampler_config resamplerConfig; - mal_resampler resampler; + ma_result result; + ma_resampler_config resamplerConfig; + ma_resampler resampler; - mal_zero_object(&resamplerConfig); - resamplerConfig.format = mal_format_f32; + ma_zero_object(&resamplerConfig); + resamplerConfig.format = ma_format_f32; resamplerConfig.channels = CHANNELS; resamplerConfig.sampleRateIn = SAMPLE_RATE_IN; resamplerConfig.sampleRateOut = SAMPLE_RATE_OUT; - resamplerConfig.algorithm = mal_resampler_algorithm_linear; - resamplerConfig.endOfInputMode = mal_resampler_end_of_input_mode_consume; - resamplerConfig.layout = mal_stream_layout_interleaved; + resamplerConfig.algorithm = ma_resampler_algorithm_linear; + resamplerConfig.endOfInputMode = ma_resampler_end_of_input_mode_consume; + resamplerConfig.layout = ma_stream_layout_interleaved; resamplerConfig.onRead = on_read; resamplerConfig.pUserData = NULL; - result = mal_resampler_init(&resamplerConfig, &resampler); + result = ma_resampler_init(&resamplerConfig, &resampler); if (result != MA_SUCCESS) { printf("Failed to initialize resampler.\n"); return -1; } - mal_sine_wave_init(0.5, 400, resamplerConfig.sampleRateIn, &sineWave); + ma_sine_wave_init(0.5, 400, resamplerConfig.sampleRateIn, &sineWave); // Write to a WAV file. We'll do about 10 seconds worth, making sure we read in chunks to make sure everything is seamless. @@ -57,10 +57,10 @@ int main(int argc, char** argv) float buffer[SAMPLE_RATE_IN*CHANNELS]; float* pBuffer = buffer; - mal_uint32 iterations = 10; - mal_uint32 framesToReadPerIteration = mal_countof(buffer)/CHANNELS; - for (mal_uint32 i = 0; i < iterations; ++i) { - mal_uint32 framesRead = (mal_uint32)mal_resampler_read(&resampler, framesToReadPerIteration, &pBuffer); + ma_uint32 iterations = 10; + ma_uint32 framesToReadPerIteration = ma_countof(buffer)/CHANNELS; + for (ma_uint32 i = 0; i < iterations; ++i) { + ma_uint32 framesRead = (ma_uint32)ma_resampler_read(&resampler, framesToReadPerIteration, &pBuffer); drwav_write(pWavWriter, framesRead*CHANNELS, buffer); } diff --git a/tests/README.md b/tests/README.md index edb0f530..803f6036 100644 --- a/tests/README.md +++ b/tests/README.md @@ -2,7 +2,7 @@ Building ======== Build and run these test from this folder. Example: - clear && ./mal_build_tests_linux && ./bin/mal_test_0 + clear && ./ma_build_tests_linux && ./bin/ma_test_0 These tests load resources from hard coded paths which point to the "res" folder. These paths are based on the assumption that the current directory is where the build files @@ -14,9 +14,9 @@ On Windows, you need to move into this directory and run emsdk_env.bat from a co prompt using an absolute path like "C:\emsdk\emsdk_env.bat". Note that PowerShell doesn't work for me for some reason. Then, run the relevant batch file: - mal_build_tests_emscripten.bat + ma_build_tests_emscripten.bat The output will be placed in the bin folder. If you have output WASM it may not work when running the web page locally. To test you can run with something like this: - emrun bin/mal_test_0_emscripten.html \ No newline at end of file + emrun bin/ma_test_0_emscripten.html \ No newline at end of file diff --git a/tests/mal_build_tests_bsd b/tests/mal_build_tests_bsd index 12d970f2..bc6fff0e 100755 --- a/tests/mal_build_tests_bsd +++ b/tests/mal_build_tests_bsd @@ -1,8 +1,8 @@ -cc mal_test_0.c -o ./bin/mal_test_0 -Wall -lpthread -lm -c++ mal_test_0.c -o ./bin/mal_test_0_cpp -Wall -lpthread -lm +cc ma_test_0.c -o ./bin/ma_test_0 -Wall -lpthread -lm +c++ ma_test_0.c -o ./bin/ma_test_0_cpp -Wall -lpthread -lm -cc mal_profiling.c -o ./bin/mal_profiling -Wall -lpthread -lm -c++ mal_profiling.c -o ./bin/mal_profiling_cpp -Wall -lpthread -lm +cc ma_profiling.c -o ./bin/ma_profiling -Wall -lpthread -lm +c++ ma_profiling.c -o ./bin/ma_profiling_cpp -Wall -lpthread -lm -cc mal_dithering.c -o ./bin/mal_dithering -Wall -lpthread -lm -c++ mal_dithering.c -o ./bin/mal_dithering_cpp -Wall -lpthread -lm +cc ma_dithering.c -o ./bin/ma_dithering -Wall -lpthread -lm +c++ ma_dithering.c -o ./bin/ma_dithering_cpp -Wall -lpthread -lm diff --git a/tests/mal_build_tests_emscripten.bat b/tests/mal_build_tests_emscripten.bat index 082d8cbf..5fedabbc 100644 --- a/tests/mal_build_tests_emscripten.bat +++ b/tests/mal_build_tests_emscripten.bat @@ -1,2 +1,2 @@ -emcc ./mal_test_0.c -o ./bin/mal_test_0_emscripten.html -s WASM=0 -std=c99 -emcc ./mal_duplex.c -o ./bin/mal_duplex.html -s WASM=0 -std=c99 \ No newline at end of file +emcc ./ma_test_0.c -o ./bin/ma_test_0_emscripten.html -s WASM=0 -std=c99 +emcc ./ma_duplex.c -o ./bin/ma_duplex.html -s WASM=0 -std=c99 \ No newline at end of file diff --git a/tests/mal_build_tests_linux b/tests/mal_build_tests_linux index 183226b7..587b0c8e 100644 --- a/tests/mal_build_tests_linux +++ b/tests/mal_build_tests_linux @@ -1,11 +1,11 @@ #!/bin/bash -cc mal_test_0.c -o ./bin/mal_test_0 -Wall -ldl -lpthread -lm -c++ mal_test_0.c -o ./bin/mal_test_0_cpp -Wall -ldl -lpthread -lm +cc ma_test_0.c -o ./bin/ma_test_0 -Wall -ldl -lpthread -lm +c++ ma_test_0.c -o ./bin/ma_test_0_cpp -Wall -ldl -lpthread -lm -cc mal_profiling.c -o ./bin/mal_profiling -Wall -ldl -lpthread -lm -c++ mal_profiling.c -o ./bin/mal_profiling_cpp -Wall -ldl -lpthread -lm +cc ma_profiling.c -o ./bin/ma_profiling -Wall -ldl -lpthread -lm +c++ ma_profiling.c -o ./bin/ma_profiling_cpp -Wall -ldl -lpthread -lm -cc mal_dithering.c -o ./bin/mal_dithering -Wall -ldl -lpthread -lm -c++ mal_dithering.c -o ./bin/mal_dithering_cpp -Wall -ldl -lpthread -lm +cc ma_dithering.c -o ./bin/ma_dithering -Wall -ldl -lpthread -lm +c++ ma_dithering.c -o ./bin/ma_dithering_cpp -Wall -ldl -lpthread -lm -cc mal_duplex.c -o ./bin/mal_duplex -Wall -ldl -lpthread -lm +cc ma_duplex.c -o ./bin/ma_duplex -Wall -ldl -lpthread -lm diff --git a/tests/mal_build_tests_mac b/tests/mal_build_tests_mac index 7b010677..6dd91343 100755 --- a/tests/mal_build_tests_mac +++ b/tests/mal_build_tests_mac @@ -1,9 +1,9 @@ -cc mal_test_0.c -o ./bin/mal_test_0 -Wall -lpthread -lm -c++ mal_test_0.c -o ./bin/mal_test_0_cpp -Wall -lpthread -lm +cc ma_test_0.c -o ./bin/ma_test_0 -Wall -lpthread -lm +c++ ma_test_0.c -o ./bin/ma_test_0_cpp -Wall -lpthread -lm -cc mal_profiling.c -o ./bin/mal_profiling -Wall -lpthread -lm -c++ mal_profiling.c -o ./bin/mal_profiling_cpp -Wall -lpthread -lm +cc ma_profiling.c -o ./bin/ma_profiling -Wall -lpthread -lm +c++ ma_profiling.c -o ./bin/ma_profiling_cpp -Wall -lpthread -lm -cc mal_dithering.c -o ./bin/mal_dithering -Wall -lpthread -lm -c++ mal_dithering.c -o ./bin/mal_dithering_cpp -Wall -lpthread -lm +cc ma_dithering.c -o ./bin/ma_dithering -Wall -lpthread -lm +c++ ma_dithering.c -o ./bin/ma_dithering_cpp -Wall -lpthread -lm diff --git a/tests/mal_build_tests_rpi b/tests/mal_build_tests_rpi index 4193d738..f848a39d 100755 --- a/tests/mal_build_tests_rpi +++ b/tests/mal_build_tests_rpi @@ -1,9 +1,9 @@ #!/bin/bash -cc mal_test_0.c -o ./bin/mal_test_0 -Wall -ldl -lpthread -lm -c++ mal_test_0.c -o ./bin/mal_test_0_cpp -Wall -ldl -lpthread -lm +cc ma_test_0.c -o ./bin/ma_test_0 -Wall -ldl -lpthread -lm +c++ ma_test_0.c -o ./bin/ma_test_0_cpp -Wall -ldl -lpthread -lm -cc mal_profiling.c -o ./bin/mal_profiling -Wall -ldl -lpthread -lm -mfpu=neon -O2 -c++ mal_profiling.c -o ./bin/mal_profiling_cpp -Wall -ldl -lpthread -lm -mfpu=neon -O2 +cc ma_profiling.c -o ./bin/ma_profiling -Wall -ldl -lpthread -lm -mfpu=neon -O2 +c++ ma_profiling.c -o ./bin/ma_profiling_cpp -Wall -ldl -lpthread -lm -mfpu=neon -O2 -cc mal_dithering.c -o ./bin/mal_dithering -Wall -ldl -lpthread -lm -c++ mal_dithering.c -o ./bin/mal_dithering_cpp -Wall -ldl -lpthread -lm \ No newline at end of file +cc ma_dithering.c -o ./bin/ma_dithering -Wall -ldl -lpthread -lm +c++ ma_dithering.c -o ./bin/ma_dithering_cpp -Wall -ldl -lpthread -lm \ No newline at end of file diff --git a/tests/mal_build_tests_win32.bat b/tests/mal_build_tests_win32.bat index c649c6f0..d905053e 100644 --- a/tests/mal_build_tests_win32.bat +++ b/tests/mal_build_tests_win32.bat @@ -4,11 +4,11 @@ SET cpp_compiler=g++ SET options=-Wall @echo on -%c_compiler% mal_test_0.c -o ./bin/mal_test_0.exe %options% -%cpp_compiler% mal_test_0.cpp -o ./bin/mal_test_0_cpp.exe %options% +%c_compiler% ma_test_0.c -o ./bin/ma_test_0.exe %options% +%cpp_compiler% ma_test_0.cpp -o ./bin/ma_test_0_cpp.exe %options% -%c_compiler% mal_profiling.c -o ./bin/mal_profiling.exe %options% -s -O2 -%cpp_compiler% mal_profiling.c -o ./bin/mal_profiling_cpp.exe %options% -s -O2 +%c_compiler% ma_profiling.c -o ./bin/ma_profiling.exe %options% -s -O2 +%cpp_compiler% ma_profiling.c -o ./bin/ma_profiling_cpp.exe %options% -s -O2 -%c_compiler% mal_dithering.c -o ./bin/mal_dithering.exe %options% -%cpp_compiler% mal_dithering.c -o ./bin/mal_dithering_cpp.exe %options% \ No newline at end of file +%c_compiler% ma_dithering.c -o ./bin/ma_dithering.exe %options% +%cpp_compiler% ma_dithering.c -o ./bin/ma_dithering_cpp.exe %options% \ No newline at end of file diff --git a/tests/mal_debug_playback.c b/tests/mal_debug_playback.c index d42ad70e..fccb0312 100644 --- a/tests/mal_debug_playback.c +++ b/tests/mal_debug_playback.c @@ -4,20 +4,20 @@ #define MINIAUDIO_IMPLEMENTATION #include "../miniaudio.h" -int print_context_info(mal_context* pContext) +int print_context_info(ma_context* pContext) { - mal_result result = MA_SUCCESS; - mal_device_info* pPlaybackDeviceInfos; - mal_uint32 playbackDeviceCount; - mal_device_info* pCaptureDeviceInfos; - mal_uint32 captureDeviceCount; + ma_result result = MA_SUCCESS; + ma_device_info* pPlaybackDeviceInfos; + ma_uint32 playbackDeviceCount; + ma_device_info* pCaptureDeviceInfos; + ma_uint32 captureDeviceCount; - printf("BACKEND: %s\n", mal_get_backend_name(pContext->backend)); + printf("BACKEND: %s\n", ma_get_backend_name(pContext->backend)); // Enumeration. printf(" Enumerating Devices... "); { - result = mal_context_get_devices(pContext, &pPlaybackDeviceInfos, &playbackDeviceCount, &pCaptureDeviceInfos, &captureDeviceCount); + result = ma_context_get_devices(pContext, &pPlaybackDeviceInfos, &playbackDeviceCount, &pCaptureDeviceInfos, &captureDeviceCount); if (result == MA_SUCCESS) { printf("Done\n"); } else { @@ -26,12 +26,12 @@ int print_context_info(mal_context* pContext) } printf(" Playback Devices (%d)\n", playbackDeviceCount); - for (mal_uint32 iDevice = 0; iDevice < playbackDeviceCount; ++iDevice) { + for (ma_uint32 iDevice = 0; iDevice < playbackDeviceCount; ++iDevice) { printf(" %d: %s\n", iDevice, pPlaybackDeviceInfos[iDevice].name); } printf(" Capture Devices (%d)\n", captureDeviceCount); - for (mal_uint32 iDevice = 0; iDevice < captureDeviceCount; ++iDevice) { + for (ma_uint32 iDevice = 0; iDevice < captureDeviceCount; ++iDevice) { printf(" %d: %s\n", iDevice, pCaptureDeviceInfos[iDevice].name); } } @@ -40,10 +40,10 @@ int print_context_info(mal_context* pContext) printf(" Getting Device Information...\n"); { printf(" Playback Devices (%d)\n", playbackDeviceCount); - for (mal_uint32 iDevice = 0; iDevice < playbackDeviceCount; ++iDevice) { + for (ma_uint32 iDevice = 0; iDevice < playbackDeviceCount; ++iDevice) { printf(" %d: %s\n", iDevice, pPlaybackDeviceInfos[iDevice].name); - result = mal_context_get_device_info(pContext, mal_device_type_playback, &pPlaybackDeviceInfos[iDevice].id, mal_share_mode_shared, &pPlaybackDeviceInfos[iDevice]); + result = ma_context_get_device_info(pContext, ma_device_type_playback, &pPlaybackDeviceInfos[iDevice].id, ma_share_mode_shared, &pPlaybackDeviceInfos[iDevice]); if (result == MA_SUCCESS) { printf(" Name: %s\n", pPlaybackDeviceInfos[iDevice].name); printf(" Min Channels: %d\n", pPlaybackDeviceInfos[iDevice].minChannels); @@ -51,8 +51,8 @@ int print_context_info(mal_context* pContext) printf(" Min Sample Rate: %d\n", pPlaybackDeviceInfos[iDevice].minSampleRate); printf(" Max Sample Rate: %d\n", pPlaybackDeviceInfos[iDevice].maxSampleRate); printf(" Format Count: %d\n", pPlaybackDeviceInfos[iDevice].formatCount); - for (mal_uint32 iFormat = 0; iFormat < pPlaybackDeviceInfos[iDevice].formatCount; ++iFormat) { - printf(" %s\n", mal_get_format_name(pPlaybackDeviceInfos[iDevice].formats[iFormat])); + for (ma_uint32 iFormat = 0; iFormat < pPlaybackDeviceInfos[iDevice].formatCount; ++iFormat) { + printf(" %s\n", ma_get_format_name(pPlaybackDeviceInfos[iDevice].formats[iFormat])); } } else { printf(" ERROR\n"); @@ -60,10 +60,10 @@ int print_context_info(mal_context* pContext) } printf(" Capture Devices (%d)\n", captureDeviceCount); - for (mal_uint32 iDevice = 0; iDevice < captureDeviceCount; ++iDevice) { + for (ma_uint32 iDevice = 0; iDevice < captureDeviceCount; ++iDevice) { printf(" %d: %s\n", iDevice, pCaptureDeviceInfos[iDevice].name); - result = mal_context_get_device_info(pContext, mal_device_type_capture, &pCaptureDeviceInfos[iDevice].id, mal_share_mode_shared, &pCaptureDeviceInfos[iDevice]); + result = ma_context_get_device_info(pContext, ma_device_type_capture, &pCaptureDeviceInfos[iDevice].id, ma_share_mode_shared, &pCaptureDeviceInfos[iDevice]); if (result == MA_SUCCESS) { printf(" Name: %s\n", pCaptureDeviceInfos[iDevice].name); printf(" Min Channels: %d\n", pCaptureDeviceInfos[iDevice].minChannels); @@ -71,8 +71,8 @@ int print_context_info(mal_context* pContext) printf(" Min Sample Rate: %d\n", pCaptureDeviceInfos[iDevice].minSampleRate); printf(" Max Sample Rate: %d\n", pCaptureDeviceInfos[iDevice].maxSampleRate); printf(" Format Count: %d\n", pCaptureDeviceInfos[iDevice].formatCount); - for (mal_uint32 iFormat = 0; iFormat < pCaptureDeviceInfos[iDevice].formatCount; ++iFormat) { - printf(" %s\n", mal_get_format_name(pCaptureDeviceInfos[iDevice].formats[iFormat])); + for (ma_uint32 iFormat = 0; iFormat < pCaptureDeviceInfos[iDevice].formatCount; ++iFormat) { + printf(" %s\n", ma_get_format_name(pCaptureDeviceInfos[iDevice].formats[iFormat])); } } else { printf(" ERROR\n"); @@ -85,10 +85,10 @@ done: return (result == MA_SUCCESS) ? 0 : -1; } -int print_device_info(mal_device* pDevice) +int print_device_info(ma_device* pDevice) { printf("DEVICE NAME: %s\n", pDevice->name); - printf(" Format: %s -> %s\n", mal_get_format_name(pDevice->format), mal_get_format_name(pDevice->internalFormat)); + printf(" Format: %s -> %s\n", ma_get_format_name(pDevice->format), ma_get_format_name(pDevice->internalFormat)); printf(" Channels: %d -> %d\n", pDevice->channels, pDevice->internalChannels); printf(" Sample Rate: %d -> %d\n", pDevice->sampleRate, pDevice->internalSampleRate); printf(" Buffer Size: %d\n", pDevice->bufferSizeInFrames); @@ -97,17 +97,17 @@ int print_device_info(mal_device* pDevice) return 0; } -mal_uint32 on_send(mal_device* pDevice, mal_uint32 frameCount, void* pFramesOut) +ma_uint32 on_send(ma_device* pDevice, ma_uint32 frameCount, void* pFramesOut) { - mal_sine_wave* pSineWave = (mal_sine_wave*)pDevice->pUserData; - mal_assert(pSineWave != NULL); + ma_sine_wave* pSineWave = (ma_sine_wave*)pDevice->pUserData; + ma_assert(pSineWave != NULL); float* pFramesOutF32 = (float*)pFramesOut; - for (mal_uint32 iFrame = 0; iFrame < frameCount; ++iFrame) { + for (ma_uint32 iFrame = 0; iFrame < frameCount; ++iFrame) { float sample; - mal_sine_wave_read(pSineWave, 1, &sample); - for (mal_uint32 iChannel = 0; iChannel < pDevice->channels; ++iChannel) { + ma_sine_wave_read(pSineWave, 1, &sample); + for (ma_uint32 iChannel = 0; iChannel < pDevice->channels; ++iChannel) { pFramesOutF32[iChannel] = sample; } @@ -119,19 +119,19 @@ mal_uint32 on_send(mal_device* pDevice, mal_uint32 frameCount, void* pFramesOut) int main(int argc, char** argv) { - mal_result result; + ma_result result; - mal_sine_wave sineWave; - result = mal_sine_wave_init(0.2, 400, 44100, &sineWave); + ma_sine_wave sineWave; + result = ma_sine_wave_init(0.2, 400, 44100, &sineWave); if (result != MA_SUCCESS) { printf("Failed to initialize sine wave.\n"); return -1; } // Separate context for this test. - mal_context_config contextConfig = mal_context_config_init(NULL); // <-- Don't need a log callback because we're using debug output instead. - mal_context context; - result = mal_context_init(NULL, 0, &contextConfig, &context); + ma_context_config contextConfig = ma_context_config_init(NULL); // <-- Don't need a log callback because we're using debug output instead. + ma_context context; + result = ma_context_init(NULL, 0, &contextConfig, &context); if (result != MA_SUCCESS) { printf("Failed to initialize context.\n"); return -1; @@ -141,13 +141,13 @@ int main(int argc, char** argv) // Device. - mal_device_config deviceConfig = mal_device_config_init_playback(mal_format_f32, 2, 44100, on_send); + ma_device_config deviceConfig = ma_device_config_init_playback(ma_format_f32, 2, 44100, on_send); deviceConfig.bufferSizeInFrames = 32768; - mal_device device; - result = mal_device_init(&context, mal_device_type_playback, NULL, &deviceConfig, &sineWave, &device); + ma_device device; + result = ma_device_init(&context, ma_device_type_playback, NULL, &deviceConfig, &sineWave, &device); if (result != MA_SUCCESS) { - mal_context_uninit(&context); + ma_context_uninit(&context); printf("Failed to initialize device.\n"); return -1; } @@ -156,10 +156,10 @@ int main(int argc, char** argv) // Start playback. - result = mal_device_start(&device); + result = ma_device_start(&device); if (result != MA_SUCCESS) { - mal_device_uninit(&device); - mal_context_uninit(&context); + ma_device_uninit(&device); + ma_context_uninit(&context); printf("Failed to start device.\n"); return -1; } @@ -169,7 +169,7 @@ int main(int argc, char** argv) getchar(); - mal_device_uninit(&device); - mal_context_uninit(&context); + ma_device_uninit(&device); + ma_context_uninit(&context); return 0; } diff --git a/tests/mal_dithering.c b/tests/mal_dithering.c index 78aa8a70..9ef36f6d 100644 --- a/tests/mal_dithering.c +++ b/tests/mal_dithering.c @@ -5,109 +5,109 @@ // Two converters are needed here. One for converting f32 samples from the sine wave generator to the input format, // and another for converting the input format to the output format for device output. -mal_sine_wave sineWave; -mal_format_converter converterIn; -mal_format_converter converterOut; +ma_sine_wave sineWave; +ma_format_converter converterIn; +ma_format_converter converterOut; -mal_uint32 on_convert_samples_in(mal_format_converter* pConverter, mal_uint32 frameCount, void* pFrames, void* pUserData) +ma_uint32 on_convert_samples_in(ma_format_converter* pConverter, ma_uint32 frameCount, void* pFrames, void* pUserData) { (void)pUserData; - mal_assert(pConverter->config.formatIn == mal_format_f32); + ma_assert(pConverter->config.formatIn == ma_format_f32); - mal_sine_wave* pSineWave = (mal_sine_wave*)pConverter->config.pUserData; - mal_assert(pSineWave); + ma_sine_wave* pSineWave = (ma_sine_wave*)pConverter->config.pUserData; + ma_assert(pSineWave); - return (mal_uint32)mal_sine_wave_read_f32(pSineWave, frameCount, (float*)pFrames); + return (ma_uint32)ma_sine_wave_read_f32(pSineWave, frameCount, (float*)pFrames); } -mal_uint32 on_convert_samples_out(mal_format_converter* pConverter, mal_uint32 frameCount, void* pFrames, void* pUserData) +ma_uint32 on_convert_samples_out(ma_format_converter* pConverter, ma_uint32 frameCount, void* pFrames, void* pUserData) { (void)pUserData; - mal_format_converter* pConverterIn = (mal_format_converter*)pConverter->config.pUserData; - mal_assert(pConverterIn != NULL); + ma_format_converter* pConverterIn = (ma_format_converter*)pConverter->config.pUserData; + ma_assert(pConverterIn != NULL); - return (mal_uint32)mal_format_converter_read(pConverterIn, frameCount, pFrames, NULL); + return (ma_uint32)ma_format_converter_read(pConverterIn, frameCount, pFrames, NULL); } -void on_send_to_device__original(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 frameCount) +void on_send_to_device__original(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount) { - mal_assert(pDevice->playback.format == mal_format_f32); - mal_assert(pDevice->playback.channels == 1); + ma_assert(pDevice->playback.format == ma_format_f32); + ma_assert(pDevice->playback.channels == 1); - mal_sine_wave_read_f32(&sineWave, frameCount, (float*)pOutput); + ma_sine_wave_read_f32(&sineWave, frameCount, (float*)pOutput); (void)pDevice; (void)pInput; } -void on_send_to_device__dithered(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 frameCount) +void on_send_to_device__dithered(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount) { - mal_assert(pDevice->playback.channels == 1); + ma_assert(pDevice->playback.channels == 1); - mal_format_converter* pConverter = (mal_format_converter*)pDevice->pUserData; - mal_assert(pConverter != NULL); - mal_assert(pDevice->playback.format == pConverter->config.formatOut); + ma_format_converter* pConverter = (ma_format_converter*)pDevice->pUserData; + ma_assert(pConverter != NULL); + ma_assert(pDevice->playback.format == pConverter->config.formatOut); - mal_format_converter_read(pConverter, frameCount, pOutput, NULL); + ma_format_converter_read(pConverter, frameCount, pOutput, NULL); (void)pInput; } int do_dithering_test() { - mal_device_config config; - mal_device device; - mal_result result; + ma_device_config config; + ma_device device; + ma_result result; - config = mal_device_config_init(mal_device_type_playback); - config.playback.format = mal_format_f32; + config = ma_device_config_init(ma_device_type_playback); + config.playback.format = ma_format_f32; config.playback.channels = 1; config.sampleRate = 0; config.dataCallback = on_send_to_device__original; // We first play the sound the way it's meant to be played. - result = mal_device_init(NULL, &config, &device); + result = ma_device_init(NULL, &config, &device); if (result != MA_SUCCESS) { return -1; } - mal_sine_wave_init(0.5, 400, device.sampleRate, &sineWave); + ma_sine_wave_init(0.5, 400, device.sampleRate, &sineWave); - result = mal_device_start(&device); + result = ma_device_start(&device); if (result != MA_SUCCESS) { return -2; } printf("Press Enter to play enable dithering.\n"); getchar(); - mal_device_uninit(&device); + ma_device_uninit(&device); - mal_format srcFormat = mal_format_s24; - mal_format dstFormat = mal_format_u8; - mal_dither_mode ditherMode = mal_dither_mode_triangle; + ma_format srcFormat = ma_format_s24; + ma_format dstFormat = ma_format_u8; + ma_dither_mode ditherMode = ma_dither_mode_triangle; - mal_format_converter_config converterInConfig = mal_format_converter_config_init_new(); - converterInConfig.formatIn = mal_format_f32; // <-- From the sine wave generator. + ma_format_converter_config converterInConfig = ma_format_converter_config_init_new(); + converterInConfig.formatIn = ma_format_f32; // <-- From the sine wave generator. converterInConfig.formatOut = srcFormat; converterInConfig.channels = config.playback.channels; - converterInConfig.ditherMode = mal_dither_mode_none; + converterInConfig.ditherMode = ma_dither_mode_none; converterInConfig.onRead = on_convert_samples_in; converterInConfig.pUserData = &sineWave; - result = mal_format_converter_init(&converterInConfig, &converterIn); + result = ma_format_converter_init(&converterInConfig, &converterIn); if (result != MA_SUCCESS) { return -3; } - mal_format_converter_config converterOutConfig = mal_format_converter_config_init_new(); + ma_format_converter_config converterOutConfig = ma_format_converter_config_init_new(); converterOutConfig.formatIn = srcFormat; converterOutConfig.formatOut = dstFormat; converterOutConfig.channels = config.playback.channels; converterOutConfig.ditherMode = ditherMode; converterOutConfig.onRead = on_convert_samples_out; converterOutConfig.pUserData = &converterIn; - result = mal_format_converter_init(&converterOutConfig, &converterOut); + result = ma_format_converter_init(&converterOutConfig, &converterOut); if (result != MA_SUCCESS) { return -3; } @@ -116,15 +116,15 @@ int do_dithering_test() config.dataCallback = on_send_to_device__dithered; config.pUserData = &converterOut; - result = mal_device_init(NULL, &config, &device); + result = ma_device_init(NULL, &config, &device); if (result != MA_SUCCESS) { return -1; } // Now we play the sound after it's run through a dithered format converter. - mal_sine_wave_init(0.5, 400, device.sampleRate, &sineWave); + ma_sine_wave_init(0.5, 400, device.sampleRate, &sineWave); - result = mal_device_start(&device); + result = ma_device_start(&device); if (result != MA_SUCCESS) { return -2; } diff --git a/tests/mal_duplex.c b/tests/mal_duplex.c index 2f99daa5..f76e9aa5 100644 --- a/tests/mal_duplex.c +++ b/tests/mal_duplex.c @@ -13,7 +13,7 @@ void main_loop__em() } #endif -void log_callback(mal_context* pContext, mal_device* pDevice, mal_uint32 logLevel, const char* message) +void log_callback(ma_context* pContext, ma_device* pDevice, ma_uint32 logLevel, const char* message) { (void)pContext; (void)pDevice; @@ -21,21 +21,21 @@ void log_callback(mal_context* pContext, mal_device* pDevice, mal_uint32 logLeve printf("%s\n", message); } -void stop_callback(mal_device* pDevice) +void stop_callback(ma_device* pDevice) { (void)pDevice; printf("STOPPED\n"); } -void data_callback(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 frameCount) +void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount) { /* In this test the format and channel count are the same for both input and output which means we can just memcpy(). */ - mal_copy_memory(pOutput, pInput, frameCount * mal_get_bytes_per_frame(pDevice->capture.format, pDevice->capture.channels)); + ma_copy_memory(pOutput, pInput, frameCount * ma_get_bytes_per_frame(pDevice->capture.format, pDevice->capture.channels)); #if 1 /* Also write to a wav file for debugging. */ drwav* pWav = (drwav*)pDevice->pUserData; - mal_assert(pWav != NULL); + ma_assert(pWav != NULL); drwav_write_pcm_frames(pWav, frameCount, pInput); #endif @@ -43,7 +43,7 @@ void data_callback(mal_device* pDevice, void* pOutput, const void* pInput, mal_u int main(int argc, char** argv) { - mal_result result; + ma_result result; #if 1 drwav_data_format wavFormat; @@ -61,26 +61,26 @@ int main(int argc, char** argv) #endif - mal_backend backend = mal_backend_wasapi; + ma_backend backend = ma_backend_wasapi; - mal_context_config contextConfig = mal_context_config_init(); + ma_context_config contextConfig = ma_context_config_init(); contextConfig.logCallback = log_callback; - mal_context context; - result = mal_context_init(&backend, 1, &contextConfig, &context); + ma_context context; + result = ma_context_init(&backend, 1, &contextConfig, &context); if (result != MA_SUCCESS) { printf("Failed to initialize context.\n"); return result; } - mal_device_config deviceConfig = mal_device_config_init(mal_device_type_duplex); + ma_device_config deviceConfig = ma_device_config_init(ma_device_type_duplex); deviceConfig.capture.pDeviceID = NULL; - deviceConfig.capture.format = mal_format_s16; + deviceConfig.capture.format = ma_format_s16; deviceConfig.capture.channels = 2; deviceConfig.playback.pDeviceID = NULL; - deviceConfig.playback.format = mal_format_s16; + deviceConfig.playback.format = ma_format_s16; deviceConfig.playback.channels = 2; - deviceConfig.playback.shareMode = mal_share_mode_shared; + deviceConfig.playback.shareMode = ma_share_mode_shared; deviceConfig.sampleRate = 44100; //deviceConfig.bufferSizeInMilliseconds = 60; deviceConfig.bufferSizeInFrames = 4096; @@ -89,8 +89,8 @@ int main(int argc, char** argv) deviceConfig.stopCallback = stop_callback; deviceConfig.pUserData = &wav; - mal_device device; - result = mal_device_init(&context, &deviceConfig, &device); + ma_device device; + result = ma_device_init(&context, &deviceConfig, &device); if (result != MA_SUCCESS) { return result; } @@ -99,7 +99,7 @@ int main(int argc, char** argv) getchar(); #endif - mal_device_start(&device); + ma_device_start(&device); #ifdef __EMSCRIPTEN__ emscripten_set_main_loop(main_loop__em, 0, 1); @@ -108,7 +108,7 @@ int main(int argc, char** argv) getchar(); #endif - mal_device_uninit(&device); + ma_device_uninit(&device); drwav_uninit(&wav); (void)argc; diff --git a/tests/mal_no_device_io.c b/tests/mal_no_device_io.c index f23f0446..a40270c6 100644 --- a/tests/mal_no_device_io.c +++ b/tests/mal_no_device_io.c @@ -13,15 +13,15 @@ int main(int argc, char** argv) (void)argc; (void)argv; - mal_result result = MA_ERROR; + ma_result result = MA_ERROR; - mal_pcm_converter_config dspConfig = mal_pcm_converter_config_init_new(); - mal_pcm_converter converter; - result = mal_pcm_converter_init(&dspConfig, &converter); + ma_pcm_converter_config dspConfig = ma_pcm_converter_config_init_new(); + ma_pcm_converter converter; + result = ma_pcm_converter_init(&dspConfig, &converter); - mal_decoder_config decoderConfig = mal_decoder_config_init(mal_format_unknown, 0, 0); - mal_decoder decoder; - result = mal_decoder_init_file("res/sine_s16_mono_48000.wav", &decoderConfig, &decoder); + ma_decoder_config decoderConfig = ma_decoder_config_init(ma_format_unknown, 0, 0); + ma_decoder decoder; + result = ma_decoder_init_file("res/sine_s16_mono_48000.wav", &decoderConfig, &decoder); return result; } diff --git a/tests/mal_profiling.c b/tests/mal_profiling.c index a0b49302..ad814ba3 100644 --- a/tests/mal_profiling.c +++ b/tests/mal_profiling.c @@ -23,23 +23,23 @@ const char* simd_mode_to_string(simd_mode mode) return "Unknown"; } -const char* mal_src_algorithm_to_string(mal_src_algorithm algorithm) +const char* ma_src_algorithm_to_string(ma_src_algorithm algorithm) { switch (algorithm) { - case mal_src_algorithm_none: return "Passthrough"; - case mal_src_algorithm_linear: return "Linear"; - case mal_src_algorithm_sinc: return "Sinc"; + case ma_src_algorithm_none: return "Passthrough"; + case ma_src_algorithm_linear: return "Linear"; + case ma_src_algorithm_sinc: return "Sinc"; } return "Unknown"; } -const char* mal_dither_mode_to_string(mal_dither_mode ditherMode) +const char* ma_dither_mode_to_string(ma_dither_mode ditherMode) { switch (ditherMode) { - case mal_dither_mode_none: return "None"; - case mal_dither_mode_rectangle: return "Rectangle"; - case mal_dither_mode_triangle: return "Triangle"; + case ma_dither_mode_none: return "None"; + case ma_dither_mode_rectangle: return "Rectangle"; + case ma_dither_mode_triangle: return "Triangle"; } return "Unkown"; @@ -56,70 +56,70 @@ const char* mal_dither_mode_to_string(mal_dither_mode ditherMode) typedef struct { void* pBaseData; - mal_uint64 sampleCount; - mal_uint64 iNextSample; + ma_uint64 sampleCount; + ma_uint64 iNextSample; } format_conversion_data; -void pcm_convert__reference(void* pOut, mal_format formatOut, const void* pIn, mal_format formatIn, mal_uint64 sampleCount, mal_dither_mode ditherMode) +void pcm_convert__reference(void* pOut, ma_format formatOut, const void* pIn, ma_format formatIn, ma_uint64 sampleCount, ma_dither_mode ditherMode) { switch (formatIn) { - case mal_format_u8: + case ma_format_u8: { switch (formatOut) { - case mal_format_s16: mal_pcm_u8_to_s16__reference(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s24: mal_pcm_u8_to_s24__reference(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s32: mal_pcm_u8_to_s32__reference(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_f32: mal_pcm_u8_to_f32__reference(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s16: ma_pcm_u8_to_s16__reference(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s24: ma_pcm_u8_to_s24__reference(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s32: ma_pcm_u8_to_s32__reference(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_f32: ma_pcm_u8_to_f32__reference(pOut, pIn, sampleCount, ditherMode); return; default: break; } } break; - case mal_format_s16: + case ma_format_s16: { switch (formatOut) { - case mal_format_u8: mal_pcm_s16_to_u8__reference( pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s24: mal_pcm_s16_to_s24__reference(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s32: mal_pcm_s16_to_s32__reference(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_f32: mal_pcm_s16_to_f32__reference(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_u8: ma_pcm_s16_to_u8__reference( pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s24: ma_pcm_s16_to_s24__reference(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s32: ma_pcm_s16_to_s32__reference(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_f32: ma_pcm_s16_to_f32__reference(pOut, pIn, sampleCount, ditherMode); return; default: break; } } break; - case mal_format_s24: + case ma_format_s24: { switch (formatOut) { - case mal_format_u8: mal_pcm_s24_to_u8__reference( pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s16: mal_pcm_s24_to_s16__reference(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s32: mal_pcm_s24_to_s32__reference(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_f32: mal_pcm_s24_to_f32__reference(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_u8: ma_pcm_s24_to_u8__reference( pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s16: ma_pcm_s24_to_s16__reference(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s32: ma_pcm_s24_to_s32__reference(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_f32: ma_pcm_s24_to_f32__reference(pOut, pIn, sampleCount, ditherMode); return; default: break; } } break; - case mal_format_s32: + case ma_format_s32: { switch (formatOut) { - case mal_format_u8: mal_pcm_s32_to_u8__reference( pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s16: mal_pcm_s32_to_s16__reference(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s24: mal_pcm_s32_to_s24__reference(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_f32: mal_pcm_s32_to_f32__reference(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_u8: ma_pcm_s32_to_u8__reference( pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s16: ma_pcm_s32_to_s16__reference(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s24: ma_pcm_s32_to_s24__reference(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_f32: ma_pcm_s32_to_f32__reference(pOut, pIn, sampleCount, ditherMode); return; default: break; } } break; - case mal_format_f32: + case ma_format_f32: { switch (formatOut) { - case mal_format_u8: mal_pcm_f32_to_u8__reference( pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s16: mal_pcm_f32_to_s16__reference(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s24: mal_pcm_f32_to_s24__reference(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s32: mal_pcm_f32_to_s32__reference(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_u8: ma_pcm_f32_to_u8__reference( pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s16: ma_pcm_f32_to_s16__reference(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s24: ma_pcm_f32_to_s24__reference(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s32: ma_pcm_f32_to_s32__reference(pOut, pIn, sampleCount, ditherMode); return; default: break; } } break; @@ -128,66 +128,66 @@ void pcm_convert__reference(void* pOut, mal_format formatOut, const void* pIn, m } } -void pcm_convert__optimized(void* pOut, mal_format formatOut, const void* pIn, mal_format formatIn, mal_uint64 sampleCount, mal_dither_mode ditherMode) +void pcm_convert__optimized(void* pOut, ma_format formatOut, const void* pIn, ma_format formatIn, ma_uint64 sampleCount, ma_dither_mode ditherMode) { switch (formatIn) { - case mal_format_u8: + case ma_format_u8: { switch (formatOut) { - case mal_format_s16: mal_pcm_u8_to_s16__optimized(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s24: mal_pcm_u8_to_s24__optimized(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s32: mal_pcm_u8_to_s32__optimized(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_f32: mal_pcm_u8_to_f32__optimized(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s16: ma_pcm_u8_to_s16__optimized(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s24: ma_pcm_u8_to_s24__optimized(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s32: ma_pcm_u8_to_s32__optimized(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_f32: ma_pcm_u8_to_f32__optimized(pOut, pIn, sampleCount, ditherMode); return; default: break; } } break; - case mal_format_s16: + case ma_format_s16: { switch (formatOut) { - case mal_format_u8: mal_pcm_s16_to_u8__optimized( pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s24: mal_pcm_s16_to_s24__optimized(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s32: mal_pcm_s16_to_s32__optimized(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_f32: mal_pcm_s16_to_f32__optimized(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_u8: ma_pcm_s16_to_u8__optimized( pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s24: ma_pcm_s16_to_s24__optimized(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s32: ma_pcm_s16_to_s32__optimized(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_f32: ma_pcm_s16_to_f32__optimized(pOut, pIn, sampleCount, ditherMode); return; default: break; } } break; - case mal_format_s24: + case ma_format_s24: { switch (formatOut) { - case mal_format_u8: mal_pcm_s24_to_u8__optimized( pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s16: mal_pcm_s24_to_s16__optimized(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s32: mal_pcm_s24_to_s32__optimized(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_f32: mal_pcm_s24_to_f32__optimized(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_u8: ma_pcm_s24_to_u8__optimized( pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s16: ma_pcm_s24_to_s16__optimized(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s32: ma_pcm_s24_to_s32__optimized(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_f32: ma_pcm_s24_to_f32__optimized(pOut, pIn, sampleCount, ditherMode); return; default: break; } } break; - case mal_format_s32: + case ma_format_s32: { switch (formatOut) { - case mal_format_u8: mal_pcm_s32_to_u8__optimized( pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s16: mal_pcm_s32_to_s16__optimized(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s24: mal_pcm_s32_to_s24__optimized(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_f32: mal_pcm_s32_to_f32__optimized(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_u8: ma_pcm_s32_to_u8__optimized( pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s16: ma_pcm_s32_to_s16__optimized(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s24: ma_pcm_s32_to_s24__optimized(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_f32: ma_pcm_s32_to_f32__optimized(pOut, pIn, sampleCount, ditherMode); return; default: break; } } break; - case mal_format_f32: + case ma_format_f32: { switch (formatOut) { - case mal_format_u8: mal_pcm_f32_to_u8__optimized( pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s16: mal_pcm_f32_to_s16__optimized(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s24: mal_pcm_f32_to_s24__optimized(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s32: mal_pcm_f32_to_s32__optimized(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_u8: ma_pcm_f32_to_u8__optimized( pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s16: ma_pcm_f32_to_s16__optimized(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s24: ma_pcm_f32_to_s24__optimized(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s32: ma_pcm_f32_to_s32__optimized(pOut, pIn, sampleCount, ditherMode); return; default: break; } } break; @@ -197,66 +197,66 @@ void pcm_convert__optimized(void* pOut, mal_format formatOut, const void* pIn, m } #if defined(MA_SUPPORT_SSE2) -void pcm_convert__sse2(void* pOut, mal_format formatOut, const void* pIn, mal_format formatIn, mal_uint64 sampleCount, mal_dither_mode ditherMode) +void pcm_convert__sse2(void* pOut, ma_format formatOut, const void* pIn, ma_format formatIn, ma_uint64 sampleCount, ma_dither_mode ditherMode) { switch (formatIn) { - case mal_format_u8: + case ma_format_u8: { switch (formatOut) { - case mal_format_s16: mal_pcm_u8_to_s16__sse2(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s24: mal_pcm_u8_to_s24__sse2(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s32: mal_pcm_u8_to_s32__sse2(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_f32: mal_pcm_u8_to_f32__sse2(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s16: ma_pcm_u8_to_s16__sse2(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s24: ma_pcm_u8_to_s24__sse2(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s32: ma_pcm_u8_to_s32__sse2(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_f32: ma_pcm_u8_to_f32__sse2(pOut, pIn, sampleCount, ditherMode); return; default: break; } } break; - case mal_format_s16: + case ma_format_s16: { switch (formatOut) { - case mal_format_u8: mal_pcm_s16_to_u8__sse2( pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s24: mal_pcm_s16_to_s24__sse2(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s32: mal_pcm_s16_to_s32__sse2(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_f32: mal_pcm_s16_to_f32__sse2(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_u8: ma_pcm_s16_to_u8__sse2( pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s24: ma_pcm_s16_to_s24__sse2(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s32: ma_pcm_s16_to_s32__sse2(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_f32: ma_pcm_s16_to_f32__sse2(pOut, pIn, sampleCount, ditherMode); return; default: break; } } break; - case mal_format_s24: + case ma_format_s24: { switch (formatOut) { - case mal_format_u8: mal_pcm_s24_to_u8__sse2( pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s16: mal_pcm_s24_to_s16__sse2(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s32: mal_pcm_s24_to_s32__sse2(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_f32: mal_pcm_s24_to_f32__sse2(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_u8: ma_pcm_s24_to_u8__sse2( pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s16: ma_pcm_s24_to_s16__sse2(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s32: ma_pcm_s24_to_s32__sse2(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_f32: ma_pcm_s24_to_f32__sse2(pOut, pIn, sampleCount, ditherMode); return; default: break; } } break; - case mal_format_s32: + case ma_format_s32: { switch (formatOut) { - case mal_format_u8: mal_pcm_s32_to_u8__sse2( pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s16: mal_pcm_s32_to_s16__sse2(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s24: mal_pcm_s32_to_s24__sse2(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_f32: mal_pcm_s32_to_f32__sse2(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_u8: ma_pcm_s32_to_u8__sse2( pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s16: ma_pcm_s32_to_s16__sse2(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s24: ma_pcm_s32_to_s24__sse2(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_f32: ma_pcm_s32_to_f32__sse2(pOut, pIn, sampleCount, ditherMode); return; default: break; } } break; - case mal_format_f32: + case ma_format_f32: { switch (formatOut) { - case mal_format_u8: mal_pcm_f32_to_u8__sse2( pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s16: mal_pcm_f32_to_s16__sse2(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s24: mal_pcm_f32_to_s24__sse2(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s32: mal_pcm_f32_to_s32__sse2(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_u8: ma_pcm_f32_to_u8__sse2( pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s16: ma_pcm_f32_to_s16__sse2(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s24: ma_pcm_f32_to_s24__sse2(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s32: ma_pcm_f32_to_s32__sse2(pOut, pIn, sampleCount, ditherMode); return; default: break; } } break; @@ -267,66 +267,66 @@ void pcm_convert__sse2(void* pOut, mal_format formatOut, const void* pIn, mal_fo #endif #if defined(MA_SUPPORT_AVX2) -void pcm_convert__avx(void* pOut, mal_format formatOut, const void* pIn, mal_format formatIn, mal_uint64 sampleCount, mal_dither_mode ditherMode) +void pcm_convert__avx(void* pOut, ma_format formatOut, const void* pIn, ma_format formatIn, ma_uint64 sampleCount, ma_dither_mode ditherMode) { switch (formatIn) { - case mal_format_u8: + case ma_format_u8: { switch (formatOut) { - case mal_format_s16: mal_pcm_u8_to_s16__avx2(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s24: mal_pcm_u8_to_s24__avx2(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s32: mal_pcm_u8_to_s32__avx2(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_f32: mal_pcm_u8_to_f32__avx2(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s16: ma_pcm_u8_to_s16__avx2(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s24: ma_pcm_u8_to_s24__avx2(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s32: ma_pcm_u8_to_s32__avx2(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_f32: ma_pcm_u8_to_f32__avx2(pOut, pIn, sampleCount, ditherMode); return; default: break; } } break; - case mal_format_s16: + case ma_format_s16: { switch (formatOut) { - case mal_format_u8: mal_pcm_s16_to_u8__avx2( pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s24: mal_pcm_s16_to_s24__avx2(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s32: mal_pcm_s16_to_s32__avx2(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_f32: mal_pcm_s16_to_f32__avx2(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_u8: ma_pcm_s16_to_u8__avx2( pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s24: ma_pcm_s16_to_s24__avx2(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s32: ma_pcm_s16_to_s32__avx2(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_f32: ma_pcm_s16_to_f32__avx2(pOut, pIn, sampleCount, ditherMode); return; default: break; } } break; - case mal_format_s24: + case ma_format_s24: { switch (formatOut) { - case mal_format_u8: mal_pcm_s24_to_u8__avx2( pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s16: mal_pcm_s24_to_s16__avx2(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s32: mal_pcm_s24_to_s32__avx2(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_f32: mal_pcm_s24_to_f32__avx2(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_u8: ma_pcm_s24_to_u8__avx2( pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s16: ma_pcm_s24_to_s16__avx2(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s32: ma_pcm_s24_to_s32__avx2(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_f32: ma_pcm_s24_to_f32__avx2(pOut, pIn, sampleCount, ditherMode); return; default: break; } } break; - case mal_format_s32: + case ma_format_s32: { switch (formatOut) { - case mal_format_u8: mal_pcm_s32_to_u8__avx2( pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s16: mal_pcm_s32_to_s16__avx2(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s24: mal_pcm_s32_to_s24__avx2(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_f32: mal_pcm_s32_to_f32__avx2(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_u8: ma_pcm_s32_to_u8__avx2( pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s16: ma_pcm_s32_to_s16__avx2(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s24: ma_pcm_s32_to_s24__avx2(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_f32: ma_pcm_s32_to_f32__avx2(pOut, pIn, sampleCount, ditherMode); return; default: break; } } break; - case mal_format_f32: + case ma_format_f32: { switch (formatOut) { - case mal_format_u8: mal_pcm_f32_to_u8__avx2( pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s16: mal_pcm_f32_to_s16__avx2(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s24: mal_pcm_f32_to_s24__avx2(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s32: mal_pcm_f32_to_s32__avx2(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_u8: ma_pcm_f32_to_u8__avx2( pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s16: ma_pcm_f32_to_s16__avx2(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s24: ma_pcm_f32_to_s24__avx2(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s32: ma_pcm_f32_to_s32__avx2(pOut, pIn, sampleCount, ditherMode); return; default: break; } } break; @@ -337,66 +337,66 @@ void pcm_convert__avx(void* pOut, mal_format formatOut, const void* pIn, mal_for #endif #if defined(MA_SUPPORT_AVX512) -void pcm_convert__avx512(void* pOut, mal_format formatOut, const void* pIn, mal_format formatIn, mal_uint64 sampleCount, mal_dither_mode ditherMode) +void pcm_convert__avx512(void* pOut, ma_format formatOut, const void* pIn, ma_format formatIn, ma_uint64 sampleCount, ma_dither_mode ditherMode) { switch (formatIn) { - case mal_format_u8: + case ma_format_u8: { switch (formatOut) { - case mal_format_s16: mal_pcm_u8_to_s16__avx512(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s24: mal_pcm_u8_to_s24__avx512(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s32: mal_pcm_u8_to_s32__avx512(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_f32: mal_pcm_u8_to_f32__avx512(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s16: ma_pcm_u8_to_s16__avx512(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s24: ma_pcm_u8_to_s24__avx512(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s32: ma_pcm_u8_to_s32__avx512(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_f32: ma_pcm_u8_to_f32__avx512(pOut, pIn, sampleCount, ditherMode); return; default: break; } } break; - case mal_format_s16: + case ma_format_s16: { switch (formatOut) { - case mal_format_u8: mal_pcm_s16_to_u8__avx512( pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s24: mal_pcm_s16_to_s24__avx512(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s32: mal_pcm_s16_to_s32__avx512(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_f32: mal_pcm_s16_to_f32__avx512(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_u8: ma_pcm_s16_to_u8__avx512( pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s24: ma_pcm_s16_to_s24__avx512(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s32: ma_pcm_s16_to_s32__avx512(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_f32: ma_pcm_s16_to_f32__avx512(pOut, pIn, sampleCount, ditherMode); return; default: break; } } break; - case mal_format_s24: + case ma_format_s24: { switch (formatOut) { - case mal_format_u8: mal_pcm_s24_to_u8__avx512( pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s16: mal_pcm_s24_to_s16__avx512(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s32: mal_pcm_s24_to_s32__avx512(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_f32: mal_pcm_s24_to_f32__avx512(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_u8: ma_pcm_s24_to_u8__avx512( pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s16: ma_pcm_s24_to_s16__avx512(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s32: ma_pcm_s24_to_s32__avx512(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_f32: ma_pcm_s24_to_f32__avx512(pOut, pIn, sampleCount, ditherMode); return; default: break; } } break; - case mal_format_s32: + case ma_format_s32: { switch (formatOut) { - case mal_format_u8: mal_pcm_s32_to_u8__avx512( pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s16: mal_pcm_s32_to_s16__avx512(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s24: mal_pcm_s32_to_s24__avx512(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_f32: mal_pcm_s32_to_f32__avx512(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_u8: ma_pcm_s32_to_u8__avx512( pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s16: ma_pcm_s32_to_s16__avx512(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s24: ma_pcm_s32_to_s24__avx512(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_f32: ma_pcm_s32_to_f32__avx512(pOut, pIn, sampleCount, ditherMode); return; default: break; } } break; - case mal_format_f32: + case ma_format_f32: { switch (formatOut) { - case mal_format_u8: mal_pcm_f32_to_u8__avx512( pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s16: mal_pcm_f32_to_s16__avx512(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s24: mal_pcm_f32_to_s24__avx512(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s32: mal_pcm_f32_to_s32__avx512(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_u8: ma_pcm_f32_to_u8__avx512( pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s16: ma_pcm_f32_to_s16__avx512(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s24: ma_pcm_f32_to_s24__avx512(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s32: ma_pcm_f32_to_s32__avx512(pOut, pIn, sampleCount, ditherMode); return; default: break; } } break; @@ -407,66 +407,66 @@ void pcm_convert__avx512(void* pOut, mal_format formatOut, const void* pIn, mal_ #endif #if defined(MA_SUPPORT_NEON) -void pcm_convert__neon(void* pOut, mal_format formatOut, const void* pIn, mal_format formatIn, mal_uint64 sampleCount, mal_dither_mode ditherMode) +void pcm_convert__neon(void* pOut, ma_format formatOut, const void* pIn, ma_format formatIn, ma_uint64 sampleCount, ma_dither_mode ditherMode) { switch (formatIn) { - case mal_format_u8: + case ma_format_u8: { switch (formatOut) { - case mal_format_s16: mal_pcm_u8_to_s16__neon(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s24: mal_pcm_u8_to_s24__neon(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s32: mal_pcm_u8_to_s32__neon(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_f32: mal_pcm_u8_to_f32__neon(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s16: ma_pcm_u8_to_s16__neon(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s24: ma_pcm_u8_to_s24__neon(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s32: ma_pcm_u8_to_s32__neon(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_f32: ma_pcm_u8_to_f32__neon(pOut, pIn, sampleCount, ditherMode); return; default: break; } } break; - case mal_format_s16: + case ma_format_s16: { switch (formatOut) { - case mal_format_u8: mal_pcm_s16_to_u8__neon( pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s24: mal_pcm_s16_to_s24__neon(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s32: mal_pcm_s16_to_s32__neon(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_f32: mal_pcm_s16_to_f32__neon(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_u8: ma_pcm_s16_to_u8__neon( pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s24: ma_pcm_s16_to_s24__neon(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s32: ma_pcm_s16_to_s32__neon(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_f32: ma_pcm_s16_to_f32__neon(pOut, pIn, sampleCount, ditherMode); return; default: break; } } break; - case mal_format_s24: + case ma_format_s24: { switch (formatOut) { - case mal_format_u8: mal_pcm_s24_to_u8__neon( pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s16: mal_pcm_s24_to_s16__neon(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s32: mal_pcm_s24_to_s32__neon(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_f32: mal_pcm_s24_to_f32__neon(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_u8: ma_pcm_s24_to_u8__neon( pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s16: ma_pcm_s24_to_s16__neon(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s32: ma_pcm_s24_to_s32__neon(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_f32: ma_pcm_s24_to_f32__neon(pOut, pIn, sampleCount, ditherMode); return; default: break; } } break; - case mal_format_s32: + case ma_format_s32: { switch (formatOut) { - case mal_format_u8: mal_pcm_s32_to_u8__neon( pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s16: mal_pcm_s32_to_s16__neon(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s24: mal_pcm_s32_to_s24__neon(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_f32: mal_pcm_s32_to_f32__neon(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_u8: ma_pcm_s32_to_u8__neon( pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s16: ma_pcm_s32_to_s16__neon(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s24: ma_pcm_s32_to_s24__neon(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_f32: ma_pcm_s32_to_f32__neon(pOut, pIn, sampleCount, ditherMode); return; default: break; } } break; - case mal_format_f32: + case ma_format_f32: { switch (formatOut) { - case mal_format_u8: mal_pcm_f32_to_u8__neon( pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s16: mal_pcm_f32_to_s16__neon(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s24: mal_pcm_f32_to_s24__neon(pOut, pIn, sampleCount, ditherMode); return; - case mal_format_s32: mal_pcm_f32_to_s32__neon(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_u8: ma_pcm_f32_to_u8__neon( pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s16: ma_pcm_f32_to_s16__neon(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s24: ma_pcm_f32_to_s24__neon(pOut, pIn, sampleCount, ditherMode); return; + case ma_format_s32: ma_pcm_f32_to_s32__neon(pOut, pIn, sampleCount, ditherMode); return; default: break; } } break; @@ -476,10 +476,10 @@ void pcm_convert__neon(void* pOut, mal_format formatOut, const void* pIn, mal_fo } #endif -void pcm_convert(void* pOut, mal_format formatOut, const void* pIn, mal_format formatIn, mal_uint64 sampleCount, mal_dither_mode ditherMode, simd_mode mode) +void pcm_convert(void* pOut, ma_format formatOut, const void* pIn, ma_format formatIn, ma_uint64 sampleCount, ma_dither_mode ditherMode, simd_mode mode) { // For testing, we always reset the seed for dithering so we can get consistent results for comparisons. - mal_seed(1234); + ma_seed(1234); switch (mode) { @@ -521,35 +521,35 @@ void pcm_convert(void* pOut, mal_format formatOut, const void* pIn, mal_format f } -int do_profiling__format_conversion__profile_individual(mal_format formatIn, mal_format formatOut, mal_dither_mode ditherMode, const void* pBaseData, mal_uint64 sampleCount, simd_mode mode, const void* pReferenceData, double referenceTime) +int do_profiling__format_conversion__profile_individual(ma_format formatIn, ma_format formatOut, ma_dither_mode ditherMode, const void* pBaseData, ma_uint64 sampleCount, simd_mode mode, const void* pReferenceData, double referenceTime) { - void* pTestData = mal_aligned_malloc((size_t)(sampleCount * mal_get_bytes_per_sample(formatOut)), MA_SIMD_ALIGNMENT); + void* pTestData = ma_aligned_malloc((size_t)(sampleCount * ma_get_bytes_per_sample(formatOut)), MA_SIMD_ALIGNMENT); if (pTestData == NULL) { printf("Out of memory.\n"); return -1; } - mal_timer timer; - mal_timer_init(&timer); - double timeTaken = mal_timer_get_time_in_seconds(&timer); + ma_timer timer; + ma_timer_init(&timer); + double timeTaken = ma_timer_get_time_in_seconds(&timer); { pcm_convert(pTestData, formatOut, pBaseData, formatIn, sampleCount, ditherMode, mode); } - timeTaken = mal_timer_get_time_in_seconds(&timer) - timeTaken; + timeTaken = ma_timer_get_time_in_seconds(&timer) - timeTaken; // Compare with the reference for correctness. - mal_bool32 passed = MA_TRUE; - for (mal_uint64 iSample = 0; iSample < sampleCount; ++iSample) { - mal_uint32 bps = mal_get_bytes_per_sample(formatOut); + ma_bool32 passed = MA_TRUE; + for (ma_uint64 iSample = 0; iSample < sampleCount; ++iSample) { + ma_uint32 bps = ma_get_bytes_per_sample(formatOut); // We need to compare on a format by format basis because we allow for very slight deviations in results depending on the output format. switch (formatOut) { - case mal_format_s16: + case ma_format_s16: { - mal_int16 a = ((const mal_int16*)pReferenceData)[iSample]; - mal_int16 b = ((const mal_int16*)pTestData)[iSample]; + ma_int16 a = ((const ma_int16*)pReferenceData)[iSample]; + ma_int16 b = ((const ma_int16*)pTestData)[iSample]; if (abs(a-b) > 0) { printf("Incorrect Sample: (%d) %d != %d\n", (int)iSample, a, b); passed = MA_FALSE; @@ -558,7 +558,7 @@ int do_profiling__format_conversion__profile_individual(mal_format formatIn, mal default: { - if (memcmp(mal_offset_ptr(pReferenceData, iSample*bps), mal_offset_ptr(pTestData, iSample*bps), bps) != 0) { + if (memcmp(ma_offset_ptr(pReferenceData, iSample*bps), ma_offset_ptr(pTestData, iSample*bps), bps) != 0) { printf("Incorrect Sample: (%d)\n", (int)iSample); passed = MA_FALSE; } @@ -571,63 +571,63 @@ int do_profiling__format_conversion__profile_individual(mal_format formatIn, mal } else { printf(" [FAILED] "); } - printf("(Dither = %s) %s -> %s (%s): %.4fms (%.2f%%)\n", mal_dither_mode_to_string(ditherMode), mal_get_format_name(formatIn), mal_get_format_name(formatOut), simd_mode_to_string(mode), timeTaken*1000, referenceTime/timeTaken*100); + printf("(Dither = %s) %s -> %s (%s): %.4fms (%.2f%%)\n", ma_dither_mode_to_string(ditherMode), ma_get_format_name(formatIn), ma_get_format_name(formatOut), simd_mode_to_string(mode), timeTaken*1000, referenceTime/timeTaken*100); - mal_aligned_free(pTestData); + ma_aligned_free(pTestData); return 0; } -int do_profiling__format_conversion__profile_set(mal_format formatIn, mal_format formatOut, mal_dither_mode ditherMode) +int do_profiling__format_conversion__profile_set(ma_format formatIn, ma_format formatOut, ma_dither_mode ditherMode) { // Generate our base data to begin with. This is generated from an f32 sine wave which is converted to formatIn. That then becomes our base data. - mal_uint32 sampleCount = 10000000; + ma_uint32 sampleCount = 10000000; - float* pSourceData = (float*)mal_aligned_malloc(sampleCount*sizeof(*pSourceData), MA_SIMD_ALIGNMENT); + float* pSourceData = (float*)ma_aligned_malloc(sampleCount*sizeof(*pSourceData), MA_SIMD_ALIGNMENT); if (pSourceData == NULL) { printf("Out of memory.\n"); return -1; } - mal_sine_wave sineWave; - mal_sine_wave_init(1.0, 400, 48000, &sineWave); - mal_sine_wave_read_f32(&sineWave, sampleCount, pSourceData); + ma_sine_wave sineWave; + ma_sine_wave_init(1.0, 400, 48000, &sineWave); + ma_sine_wave_read_f32(&sineWave, sampleCount, pSourceData); - void* pBaseData = mal_aligned_malloc(sampleCount * mal_get_bytes_per_sample(formatIn), MA_SIMD_ALIGNMENT); - mal_pcm_convert(pBaseData, formatIn, pSourceData, mal_format_f32, sampleCount, mal_dither_mode_none); + void* pBaseData = ma_aligned_malloc(sampleCount * ma_get_bytes_per_sample(formatIn), MA_SIMD_ALIGNMENT); + ma_pcm_convert(pBaseData, formatIn, pSourceData, ma_format_f32, sampleCount, ma_dither_mode_none); // Reference first so we can get a benchmark. - void* pReferenceData = mal_aligned_malloc(sampleCount * mal_get_bytes_per_sample(formatOut), MA_SIMD_ALIGNMENT); - mal_timer timer; - mal_timer_init(&timer); - double referenceTime = mal_timer_get_time_in_seconds(&timer); + void* pReferenceData = ma_aligned_malloc(sampleCount * ma_get_bytes_per_sample(formatOut), MA_SIMD_ALIGNMENT); + ma_timer timer; + ma_timer_init(&timer); + double referenceTime = ma_timer_get_time_in_seconds(&timer); { pcm_convert__reference(pReferenceData, formatOut, pBaseData, formatIn, sampleCount, ditherMode); } - referenceTime = mal_timer_get_time_in_seconds(&timer) - referenceTime; + referenceTime = ma_timer_get_time_in_seconds(&timer) - referenceTime; // Here is where each optimized implementation is profiled. do_profiling__format_conversion__profile_individual(formatIn, formatOut, ditherMode, pBaseData, sampleCount, simd_mode_scalar, pReferenceData, referenceTime); - if (mal_has_sse2()) { + if (ma_has_sse2()) { do_profiling__format_conversion__profile_individual(formatIn, formatOut, ditherMode, pBaseData, sampleCount, simd_mode_sse2, pReferenceData, referenceTime); } - if (mal_has_avx2()) { + if (ma_has_avx2()) { do_profiling__format_conversion__profile_individual(formatIn, formatOut, ditherMode, pBaseData, sampleCount, simd_mode_avx2, pReferenceData, referenceTime); } - if (mal_has_avx512f()) { + if (ma_has_avx512f()) { do_profiling__format_conversion__profile_individual(formatIn, formatOut, ditherMode, pBaseData, sampleCount, simd_mode_avx512, pReferenceData, referenceTime); } - if (mal_has_neon()) { + if (ma_has_neon()) { do_profiling__format_conversion__profile_individual(formatIn, formatOut, ditherMode, pBaseData, sampleCount, simd_mode_neon, pReferenceData, referenceTime); } - mal_aligned_free(pReferenceData); - mal_aligned_free(pBaseData); - mal_aligned_free(pSourceData); + ma_aligned_free(pReferenceData); + ma_aligned_free(pBaseData); + ma_aligned_free(pSourceData); return 0; } @@ -636,7 +636,7 @@ int do_profiling__format_conversion() // First we need to generate our base data. - do_profiling__format_conversion__profile_set(mal_format_f32, mal_format_s16, mal_dither_mode_none); + do_profiling__format_conversion__profile_set(ma_format_f32, ma_format_s16, ma_dither_mode_none); return 0; } @@ -657,12 +657,12 @@ double g_ChannelRouterTime_AVX2 = 0; double g_ChannelRouterTime_AVX512 = 0; double g_ChannelRouterTime_NEON = 0; -mal_sine_wave g_sineWave; +ma_sine_wave g_sineWave; -mal_bool32 channel_router_test(mal_uint32 channels, mal_uint64 frameCount, float** ppFramesA, float** ppFramesB) +ma_bool32 channel_router_test(ma_uint32 channels, ma_uint64 frameCount, float** ppFramesA, float** ppFramesB) { - for (mal_uint32 iChannel = 0; iChannel < channels; ++iChannel) { - for (mal_uint32 iFrame = 0; iFrame < frameCount; ++iFrame) { + for (ma_uint32 iChannel = 0; iChannel < channels; ++iChannel) { + for (ma_uint32 iFrame = 0; iFrame < frameCount; ++iFrame) { if (ppFramesA[iChannel][iFrame] != ppFramesB[iChannel][iFrame]) { return MA_FALSE; } @@ -672,16 +672,16 @@ mal_bool32 channel_router_test(mal_uint32 channels, mal_uint64 frameCount, float return MA_TRUE; } -mal_uint32 channel_router_on_read(mal_channel_router* pRouter, mal_uint32 frameCount, void** ppSamplesOut, void* pUserData) +ma_uint32 channel_router_on_read(ma_channel_router* pRouter, ma_uint32 frameCount, void** ppSamplesOut, void* pUserData) { (void)pUserData; (void)pRouter; float** ppSamplesOutF = (float**)ppSamplesOut; - for (mal_uint32 iChannel = 0; iChannel < pRouter->config.channelsIn; ++iChannel) { - mal_sine_wave_init(1/(iChannel+1), 400, 48000, &g_sineWave); - mal_sine_wave_read_f32(&g_sineWave, frameCount, ppSamplesOutF[iChannel]); + for (ma_uint32 iChannel = 0; iChannel < pRouter->config.channelsIn; ++iChannel) { + ma_sine_wave_init(1/(iChannel+1), 400, 48000, &g_sineWave); + ma_sine_wave_read_f32(&g_sineWave, frameCount, ppSamplesOutF[iChannel]); } return frameCount; @@ -689,20 +689,20 @@ mal_uint32 channel_router_on_read(mal_channel_router* pRouter, mal_uint32 frameC int do_profiling__channel_routing() { - mal_result result; + ma_result result; // When profiling we need to compare against a benchmark to ensure the optimization is implemented correctly. We always // use the reference implementation for our benchmark. - mal_uint32 channels = mal_countof(g_ChannelRouterProfilingOutputBenchmark); - mal_channel channelMapIn[MA_MAX_CHANNELS]; - mal_get_standard_channel_map(mal_standard_channel_map_default, channels, channelMapIn); - mal_channel channelMapOut[MA_MAX_CHANNELS]; - mal_get_standard_channel_map(mal_standard_channel_map_default, channels, channelMapOut); + ma_uint32 channels = ma_countof(g_ChannelRouterProfilingOutputBenchmark); + ma_channel channelMapIn[MA_MAX_CHANNELS]; + ma_get_standard_channel_map(ma_standard_channel_map_default, channels, channelMapIn); + ma_channel channelMapOut[MA_MAX_CHANNELS]; + ma_get_standard_channel_map(ma_standard_channel_map_default, channels, channelMapOut); - mal_channel_router_config routerConfig = mal_channel_router_config_init(channels, channelMapIn, channels, channelMapOut, mal_channel_mix_mode_planar_blend, channel_router_on_read, NULL); + ma_channel_router_config routerConfig = ma_channel_router_config_init(channels, channelMapIn, channels, channelMapOut, ma_channel_mix_mode_planar_blend, channel_router_on_read, NULL); - mal_channel_router router; - result = mal_channel_router_init(&routerConfig, &router); + ma_channel_router router; + result = ma_channel_router_init(&routerConfig, &router); if (result != MA_SUCCESS) { return -1; } @@ -715,7 +715,7 @@ int do_profiling__channel_routing() router.useAVX512 = MA_FALSE; router.useNEON = MA_FALSE; - mal_uint64 framesToRead = mal_countof(g_ChannelRouterProfilingOutputBenchmark[0]); + ma_uint64 framesToRead = ma_countof(g_ChannelRouterProfilingOutputBenchmark[0]); // Benchmark void* ppOutBenchmark[8]; @@ -723,8 +723,8 @@ int do_profiling__channel_routing() ppOutBenchmark[i] = (void*)g_ChannelRouterProfilingOutputBenchmark[i]; } - mal_sine_wave_init(1, 400, 48000, &g_sineWave); - mal_uint64 framesRead = mal_channel_router_read_deinterleaved(&router, framesToRead, ppOutBenchmark, NULL); + ma_sine_wave_init(1, 400, 48000, &g_sineWave); + ma_uint64 framesRead = ma_channel_router_read_deinterleaved(&router, framesToRead, ppOutBenchmark, NULL); if (framesRead != framesToRead) { printf("Channel Router: An error occurred while reading benchmark data.\n"); } @@ -740,11 +740,11 @@ int do_profiling__channel_routing() // Reference { - mal_timer timer; - mal_timer_init(&timer); - double startTime = mal_timer_get_time_in_seconds(&timer); + ma_timer timer; + ma_timer_init(&timer); + double startTime = ma_timer_get_time_in_seconds(&timer); - framesRead = mal_channel_router_read_deinterleaved(&router, framesToRead, ppOut, NULL); + framesRead = ma_channel_router_read_deinterleaved(&router, framesToRead, ppOut, NULL); if (framesRead != framesToRead) { printf("Channel Router: An error occurred while reading reference data.\n"); } @@ -755,23 +755,23 @@ int do_profiling__channel_routing() printf(" [PASSED] "); } - g_ChannelRouterTime_Reference = mal_timer_get_time_in_seconds(&timer) - startTime; + g_ChannelRouterTime_Reference = ma_timer_get_time_in_seconds(&timer) - startTime; printf("Reference: %.4fms (%.2f%%)\n", g_ChannelRouterTime_Reference*1000, g_ChannelRouterTime_Reference/g_ChannelRouterTime_Reference*100); } // SSE2 - if (mal_has_sse2()) { + if (ma_has_sse2()) { router.useSSE2 = MA_TRUE; - mal_timer timer; - mal_timer_init(&timer); - double startTime = mal_timer_get_time_in_seconds(&timer); + ma_timer timer; + ma_timer_init(&timer); + double startTime = ma_timer_get_time_in_seconds(&timer); - framesRead = mal_channel_router_read_deinterleaved(&router, framesToRead, ppOut, NULL); + framesRead = ma_channel_router_read_deinterleaved(&router, framesToRead, ppOut, NULL); if (framesRead != framesToRead) { printf("Channel Router: An error occurred while reading SSE2 data.\n"); } - g_ChannelRouterTime_SSE2 = mal_timer_get_time_in_seconds(&timer) - startTime; + g_ChannelRouterTime_SSE2 = ma_timer_get_time_in_seconds(&timer) - startTime; router.useSSE2 = MA_FALSE; if (!channel_router_test(channels, framesRead, (float**)ppOutBenchmark, (float**)ppOut)) { @@ -784,18 +784,18 @@ int do_profiling__channel_routing() } // AVX2 - if (mal_has_avx2()) { + if (ma_has_avx2()) { router.useAVX2 = MA_TRUE; - mal_timer timer; - mal_timer_init(&timer); - double startTime = mal_timer_get_time_in_seconds(&timer); + ma_timer timer; + ma_timer_init(&timer); + double startTime = ma_timer_get_time_in_seconds(&timer); - framesRead = mal_channel_router_read_deinterleaved(&router, framesToRead, ppOut, NULL); + framesRead = ma_channel_router_read_deinterleaved(&router, framesToRead, ppOut, NULL); if (framesRead != framesToRead) { printf("Channel Router: An error occurred while reading AVX2 data.\n"); } - g_ChannelRouterTime_AVX2 = mal_timer_get_time_in_seconds(&timer) - startTime; + g_ChannelRouterTime_AVX2 = ma_timer_get_time_in_seconds(&timer) - startTime; router.useAVX2 = MA_FALSE; if (!channel_router_test(channels, framesRead, (float**)ppOutBenchmark, (float**)ppOut)) { @@ -808,18 +808,18 @@ int do_profiling__channel_routing() } // NEON - if (mal_has_neon()) { + if (ma_has_neon()) { router.useNEON = MA_TRUE; - mal_timer timer; - mal_timer_init(&timer); - double startTime = mal_timer_get_time_in_seconds(&timer); + ma_timer timer; + ma_timer_init(&timer); + double startTime = ma_timer_get_time_in_seconds(&timer); - framesRead = mal_channel_router_read_deinterleaved(&router, framesToRead, ppOut, NULL); + framesRead = ma_channel_router_read_deinterleaved(&router, framesToRead, ppOut, NULL); if (framesRead != framesToRead) { printf("Channel Router: An error occurred while reading NEON data.\n"); } - g_ChannelRouterTime_NEON = mal_timer_get_time_in_seconds(&timer) - startTime; + g_ChannelRouterTime_NEON = ma_timer_get_time_in_seconds(&timer) - startTime; router.useNEON = MA_FALSE; if (!channel_router_test(channels, framesRead, (float**)ppOutBenchmark, (float**)ppOut)) { @@ -844,48 +844,48 @@ int do_profiling__channel_routing() typedef struct { float* pFrameData[MA_MAX_CHANNELS]; - mal_uint64 frameCount; - mal_uint32 channels; + ma_uint64 frameCount; + ma_uint32 channels; double timeTaken; } src_reference_data; typedef struct { float* pFrameData[MA_MAX_CHANNELS]; - mal_uint64 frameCount; - mal_uint64 iNextFrame; - mal_uint32 channels; + ma_uint64 frameCount; + ma_uint64 iNextFrame; + ma_uint32 channels; } src_data; -mal_uint32 do_profiling__src__on_read(mal_src* pSRC, mal_uint32 frameCount, void** ppSamplesOut, void* pUserData) +ma_uint32 do_profiling__src__on_read(ma_src* pSRC, ma_uint32 frameCount, void** ppSamplesOut, void* pUserData) { src_data* pBaseData = (src_data*)pUserData; - mal_assert(pBaseData != NULL); - mal_assert(pBaseData->iNextFrame <= pBaseData->frameCount); + ma_assert(pBaseData != NULL); + ma_assert(pBaseData->iNextFrame <= pBaseData->frameCount); - mal_uint64 framesToRead = frameCount; + ma_uint64 framesToRead = frameCount; - mal_uint64 framesAvailable = pBaseData->frameCount - pBaseData->iNextFrame; + ma_uint64 framesAvailable = pBaseData->frameCount - pBaseData->iNextFrame; if (framesToRead > framesAvailable) { framesToRead = framesAvailable; } if (framesToRead > 0) { - for (mal_uint32 iChannel = 0; iChannel < pSRC->config.channels; iChannel += 1) { - mal_copy_memory(ppSamplesOut[iChannel], pBaseData->pFrameData[iChannel], (size_t)(framesToRead * sizeof(float))); + for (ma_uint32 iChannel = 0; iChannel < pSRC->config.channels; iChannel += 1) { + ma_copy_memory(ppSamplesOut[iChannel], pBaseData->pFrameData[iChannel], (size_t)(framesToRead * sizeof(float))); } } pBaseData->iNextFrame += framesToRead; - return (mal_uint32)framesToRead; + return (ma_uint32)framesToRead; } -mal_result init_src(src_data* pBaseData, mal_uint32 sampleRateIn, mal_uint32 sampleRateOut, mal_src_algorithm algorithm, simd_mode mode, mal_src* pSRC) +ma_result init_src(src_data* pBaseData, ma_uint32 sampleRateIn, ma_uint32 sampleRateOut, ma_src_algorithm algorithm, simd_mode mode, ma_src* pSRC) { - mal_assert(pBaseData != NULL); - mal_assert(pSRC != NULL); + ma_assert(pBaseData != NULL); + ma_assert(pSRC != NULL); - mal_src_config srcConfig = mal_src_config_init(sampleRateIn, sampleRateOut, pBaseData->channels, do_profiling__src__on_read, pBaseData); + ma_src_config srcConfig = ma_src_config_init(sampleRateIn, sampleRateOut, pBaseData->channels, do_profiling__src__on_read, pBaseData); srcConfig.sinc.windowWidth = 17; // <-- Make this an odd number to test unaligned section in the SIMD implementations. srcConfig.algorithm = algorithm; srcConfig.noSSE2 = MA_TRUE; @@ -901,7 +901,7 @@ mal_result init_src(src_data* pBaseData, mal_uint32 sampleRateIn, mal_uint32 sam default: break; } - mal_result result = mal_src_init(&srcConfig, pSRC); + ma_result result = ma_src_init(&srcConfig, pSRC); if (result != MA_SUCCESS) { printf("Failed to initialize sample rate converter.\n"); return (int)result; @@ -910,17 +910,17 @@ mal_result init_src(src_data* pBaseData, mal_uint32 sampleRateIn, mal_uint32 sam return result; } -int do_profiling__src__profile_individual(src_data* pBaseData, mal_uint32 sampleRateIn, mal_uint32 sampleRateOut, mal_src_algorithm algorithm, simd_mode mode, src_reference_data* pReferenceData) +int do_profiling__src__profile_individual(src_data* pBaseData, ma_uint32 sampleRateIn, ma_uint32 sampleRateOut, ma_src_algorithm algorithm, simd_mode mode, src_reference_data* pReferenceData) { - mal_assert(pBaseData != NULL); - mal_assert(pReferenceData != NULL); + ma_assert(pBaseData != NULL); + ma_assert(pReferenceData != NULL); - mal_result result = MA_ERROR; + ma_result result = MA_ERROR; // Make sure the base data is moved back to the start. pBaseData->iNextFrame = 0; - mal_src src; + ma_src src; result = init_src(pBaseData, sampleRateIn, sampleRateOut, algorithm, mode, &src); if (result != MA_SUCCESS) { return (int)result; @@ -928,32 +928,32 @@ int do_profiling__src__profile_individual(src_data* pBaseData, mal_uint32 sample // Profiling. - mal_uint64 sz = pReferenceData->frameCount * sizeof(float); - mal_assert(sz <= SIZE_MAX); + ma_uint64 sz = pReferenceData->frameCount * sizeof(float); + ma_assert(sz <= SIZE_MAX); float* pFrameData[MA_MAX_CHANNELS]; - for (mal_uint32 iChannel = 0; iChannel < pBaseData->channels; iChannel += 1) { - pFrameData[iChannel] = (float*)mal_aligned_malloc((size_t)sz, MA_SIMD_ALIGNMENT); + for (ma_uint32 iChannel = 0; iChannel < pBaseData->channels; iChannel += 1) { + pFrameData[iChannel] = (float*)ma_aligned_malloc((size_t)sz, MA_SIMD_ALIGNMENT); if (pFrameData[iChannel] == NULL) { printf("Out of memory.\n"); return -2; } - mal_zero_memory(pFrameData[iChannel], (size_t)sz); + ma_zero_memory(pFrameData[iChannel], (size_t)sz); } - mal_timer timer; - mal_timer_init(&timer); - double startTime = mal_timer_get_time_in_seconds(&timer); + ma_timer timer; + ma_timer_init(&timer); + double startTime = ma_timer_get_time_in_seconds(&timer); { - mal_src_read_deinterleaved(&src, pReferenceData->frameCount, (void**)pFrameData, pBaseData); + ma_src_read_deinterleaved(&src, pReferenceData->frameCount, (void**)pFrameData, pBaseData); } - double timeTaken = mal_timer_get_time_in_seconds(&timer) - startTime; + double timeTaken = ma_timer_get_time_in_seconds(&timer) - startTime; // Correctness test. - mal_bool32 passed = MA_TRUE; - for (mal_uint32 iChannel = 0; iChannel < pReferenceData->channels; iChannel += 1) { - for (mal_uint32 iFrame = 0; iFrame < pReferenceData->frameCount; iFrame += 1) { + ma_bool32 passed = MA_TRUE; + for (ma_uint32 iChannel = 0; iChannel < pReferenceData->channels; iChannel += 1) { + for (ma_uint32 iFrame = 0; iFrame < pReferenceData->frameCount; iFrame += 1) { float s0 = pReferenceData->pFrameData[iChannel][iFrame]; float s1 = pFrameData[iChannel][iFrame]; //if (s0 != s1) { @@ -971,82 +971,82 @@ int do_profiling__src__profile_individual(src_data* pBaseData, mal_uint32 sample } else { printf(" [FAILED] "); } - printf("%s %d -> %d (%s): %.4fms (%.2f%%)\n", mal_src_algorithm_to_string(algorithm), sampleRateIn, sampleRateOut, simd_mode_to_string(mode), timeTaken*1000, pReferenceData->timeTaken/timeTaken*100); + printf("%s %d -> %d (%s): %.4fms (%.2f%%)\n", ma_src_algorithm_to_string(algorithm), sampleRateIn, sampleRateOut, simd_mode_to_string(mode), timeTaken*1000, pReferenceData->timeTaken/timeTaken*100); - for (mal_uint32 iChannel = 0; iChannel < pBaseData->channels; iChannel += 1) { - mal_aligned_free(pFrameData[iChannel]); + for (ma_uint32 iChannel = 0; iChannel < pBaseData->channels; iChannel += 1) { + ma_aligned_free(pFrameData[iChannel]); } return (int)result; } -int do_profiling__src__profile_set(src_data* pBaseData, mal_uint32 sampleRateIn, mal_uint32 sampleRateOut, mal_src_algorithm algorithm) +int do_profiling__src__profile_set(src_data* pBaseData, ma_uint32 sampleRateIn, ma_uint32 sampleRateOut, ma_src_algorithm algorithm) { - mal_assert(pBaseData != NULL); + ma_assert(pBaseData != NULL); // Make sure the base data is back at the start. pBaseData->iNextFrame = 0; src_reference_data referenceData; - mal_zero_object(&referenceData); + ma_zero_object(&referenceData); referenceData.channels = pBaseData->channels; // The first thing to do is to perform a sample rate conversion using the scalar/reference implementation. This reference is used to compare // the results of the optimized implementation. - referenceData.frameCount = mal_calculate_frame_count_after_src(sampleRateOut, sampleRateIn, pBaseData->frameCount); + referenceData.frameCount = ma_calculate_frame_count_after_src(sampleRateOut, sampleRateIn, pBaseData->frameCount); if (referenceData.frameCount == 0) { printf("Failed to calculate output frame count.\n"); return -1; } - mal_uint64 sz = referenceData.frameCount * sizeof(float); - mal_assert(sz <= SIZE_MAX); + ma_uint64 sz = referenceData.frameCount * sizeof(float); + ma_assert(sz <= SIZE_MAX); - for (mal_uint32 iChannel = 0; iChannel < referenceData.channels; iChannel += 1) { - referenceData.pFrameData[iChannel] = (float*)mal_aligned_malloc((size_t)sz, MA_SIMD_ALIGNMENT); + for (ma_uint32 iChannel = 0; iChannel < referenceData.channels; iChannel += 1) { + referenceData.pFrameData[iChannel] = (float*)ma_aligned_malloc((size_t)sz, MA_SIMD_ALIGNMENT); if (referenceData.pFrameData[iChannel] == NULL) { printf("Out of memory.\n"); return -2; } - mal_zero_memory(referenceData.pFrameData[iChannel], (size_t)sz); + ma_zero_memory(referenceData.pFrameData[iChannel], (size_t)sz); } // Generate the reference data. - mal_src src; - mal_result result = init_src(pBaseData, sampleRateIn, sampleRateOut, algorithm, simd_mode_scalar, &src); + ma_src src; + ma_result result = init_src(pBaseData, sampleRateIn, sampleRateOut, algorithm, simd_mode_scalar, &src); if (result != MA_SUCCESS) { return (int)result; } - mal_timer timer; - mal_timer_init(&timer); - double startTime = mal_timer_get_time_in_seconds(&timer); + ma_timer timer; + ma_timer_init(&timer); + double startTime = ma_timer_get_time_in_seconds(&timer); { - mal_src_read_deinterleaved(&src, referenceData.frameCount, (void**)referenceData.pFrameData, pBaseData); + ma_src_read_deinterleaved(&src, referenceData.frameCount, (void**)referenceData.pFrameData, pBaseData); } - referenceData.timeTaken = mal_timer_get_time_in_seconds(&timer) - startTime; + referenceData.timeTaken = ma_timer_get_time_in_seconds(&timer) - startTime; // Now that we have the reference data to compare against we can go ahead and measure the SIMD optimizations. do_profiling__src__profile_individual(pBaseData, sampleRateIn, sampleRateOut, algorithm, simd_mode_scalar, &referenceData); - if (mal_has_sse2()) { + if (ma_has_sse2()) { do_profiling__src__profile_individual(pBaseData, sampleRateIn, sampleRateOut, algorithm, simd_mode_sse2, &referenceData); } - if (mal_has_avx2()) { + if (ma_has_avx2()) { do_profiling__src__profile_individual(pBaseData, sampleRateIn, sampleRateOut, algorithm, simd_mode_avx2, &referenceData); } - if (mal_has_avx512f()) { + if (ma_has_avx512f()) { do_profiling__src__profile_individual(pBaseData, sampleRateIn, sampleRateOut, algorithm, simd_mode_avx512, &referenceData); } - if (mal_has_neon()) { + if (ma_has_neon()) { do_profiling__src__profile_individual(pBaseData, sampleRateIn, sampleRateOut, algorithm, simd_mode_neon, &referenceData); } - for (mal_uint32 iChannel = 0; iChannel < referenceData.channels; iChannel += 1) { - mal_aligned_free(referenceData.pFrameData[iChannel]); + for (ma_uint32 iChannel = 0; iChannel < referenceData.channels; iChannel += 1) { + ma_aligned_free(referenceData.pFrameData[iChannel]); } return 0; @@ -1059,31 +1059,31 @@ int do_profiling__src() // Set up base data. src_data baseData; - mal_zero_object(&baseData); + ma_zero_object(&baseData); baseData.channels = 8; baseData.frameCount = 100000; - for (mal_uint32 iChannel = 0; iChannel < baseData.channels; ++iChannel) { - baseData.pFrameData[iChannel] = (float*)mal_aligned_malloc((size_t)(baseData.frameCount * sizeof(float)), MA_SIMD_ALIGNMENT); + for (ma_uint32 iChannel = 0; iChannel < baseData.channels; ++iChannel) { + baseData.pFrameData[iChannel] = (float*)ma_aligned_malloc((size_t)(baseData.frameCount * sizeof(float)), MA_SIMD_ALIGNMENT); if (baseData.pFrameData[iChannel] == NULL) { printf("Out of memory.\n"); return -1; } - mal_sine_wave sineWave; - mal_sine_wave_init(1.0f, 400 + (iChannel*50), 48000, &sineWave); - mal_sine_wave_read_f32(&sineWave, baseData.frameCount, baseData.pFrameData[iChannel]); + ma_sine_wave sineWave; + ma_sine_wave_init(1.0f, 400 + (iChannel*50), 48000, &sineWave); + ma_sine_wave_read_f32(&sineWave, baseData.frameCount, baseData.pFrameData[iChannel]); } // Upsampling. - do_profiling__src__profile_set(&baseData, 44100, 48000, mal_src_algorithm_sinc); + do_profiling__src__profile_set(&baseData, 44100, 48000, ma_src_algorithm_sinc); // Downsampling. - do_profiling__src__profile_set(&baseData, 48000, 44100, mal_src_algorithm_sinc); + do_profiling__src__profile_set(&baseData, 48000, 44100, ma_src_algorithm_sinc); - for (mal_uint32 iChannel = 0; iChannel < baseData.channels; iChannel += 1) { - mal_aligned_free(baseData.pFrameData[iChannel]); + for (ma_uint32 iChannel = 0; iChannel < baseData.channels; iChannel += 1) { + ma_aligned_free(baseData.pFrameData[iChannel]); } return 0; @@ -1128,22 +1128,22 @@ int main(int argc, char** argv) // Summary. - if (mal_has_sse2()) { + if (ma_has_sse2()) { printf("Has SSE2: YES\n"); } else { printf("Has SSE2: NO\n"); } - if (mal_has_avx2()) { + if (ma_has_avx2()) { printf("Has AVX2: YES\n"); } else { printf("Has AVX2: NO\n"); } - if (mal_has_avx512f()) { + if (ma_has_avx512f()) { printf("Has AVX-512F: YES\n"); } else { printf("Has AVX-512F: NO\n"); } - if (mal_has_neon()) { + if (ma_has_neon()) { printf("Has NEON: YES\n"); } else { printf("Has NEON: NO\n"); diff --git a/tests/mal_resampling.c b/tests/mal_resampling.c index abb4d8c0..1fd924dc 100644 --- a/tests/mal_resampling.c +++ b/tests/mal_resampling.c @@ -13,8 +13,8 @@ #endif // There is a usage pattern for resampling that miniaudio does not properly support which is where the client continuously -// reads samples until mal_src_read() returns 0. The problem with this pattern is that is consumes the samples sitting -// in the window which are needed to compute the next samples in future calls to mal_src_read() (assuming the client +// reads samples until ma_src_read() returns 0. The problem with this pattern is that is consumes the samples sitting +// in the window which are needed to compute the next samples in future calls to ma_src_read() (assuming the client // has re-filled the resampler's input data). /* @@ -22,72 +22,72 @@ for (;;) { fill_src_input_data(&src, someData); float buffer[4096] - while ((framesRead = mal_src_read(&src, ...) != 0) { + while ((framesRead = ma_src_read(&src, ...) != 0) { do_something_with_resampled_data(buffer); } } */ -// In the use case above, the very last samples that are read from mal_src_read() will not have future samples to draw +// In the use case above, the very last samples that are read from ma_src_read() will not have future samples to draw // from in order to calculate the correct interpolation factor which in turn results in crackling. -mal_uint32 sampleRateIn = 0; -mal_uint32 sampleRateOut = 0; -mal_sine_wave sineWave; // <-- This is the source data. -mal_src src; +ma_uint32 sampleRateIn = 0; +ma_uint32 sampleRateOut = 0; +ma_sine_wave sineWave; // <-- This is the source data. +ma_src src; float srcInput[1024]; -mal_uint32 srcNextSampleIndex = mal_countof(srcInput); +ma_uint32 srcNextSampleIndex = ma_countof(srcInput); void reload_src_input() { - mal_sine_wave_read_f32(&sineWave, mal_countof(srcInput), srcInput); + ma_sine_wave_read_f32(&sineWave, ma_countof(srcInput), srcInput); srcNextSampleIndex = 0; } -mal_uint32 on_src(mal_src* pSRC, mal_uint32 frameCount, void** ppSamplesOut, void* pUserData) +ma_uint32 on_src(ma_src* pSRC, ma_uint32 frameCount, void** ppSamplesOut, void* pUserData) { - mal_assert(pSRC != NULL); - mal_assert(pSRC->config.channels == 1); + ma_assert(pSRC != NULL); + ma_assert(pSRC->config.channels == 1); (void)pUserData; // Only read as much as is available in the input buffer. Do not reload the buffer here. - mal_uint32 framesAvailable = mal_countof(srcInput) - srcNextSampleIndex; - mal_uint32 framesToRead = frameCount; + ma_uint32 framesAvailable = ma_countof(srcInput) - srcNextSampleIndex; + ma_uint32 framesToRead = frameCount; if (framesToRead > framesAvailable) { framesToRead = framesAvailable; } - mal_copy_memory(ppSamplesOut[0], srcInput + srcNextSampleIndex, sizeof(float)*framesToRead); + ma_copy_memory(ppSamplesOut[0], srcInput + srcNextSampleIndex, sizeof(float)*framesToRead); srcNextSampleIndex += framesToRead; return framesToRead; } -void on_send_to_device(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 frameCount) +void on_send_to_device(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount) { (void)pDevice; (void)pInput; - mal_assert(pDevice->playback.format == mal_format_f32); - mal_assert(pDevice->playback.channels == 1); + ma_assert(pDevice->playback.format == ma_format_f32); + ma_assert(pDevice->playback.channels == 1); float* pFramesF32 = (float*)pOutput; // To reproduce the case we are needing to test, we need to read from the SRC in a very specific way. We keep looping - // until we've read the requested frame count, however we have an inner loop that keeps running until mal_src_read() + // until we've read the requested frame count, however we have an inner loop that keeps running until ma_src_read() // returns 0, in which case we need to reload the SRC's input data and keep going. - mal_uint32 totalFramesRead = 0; + ma_uint32 totalFramesRead = 0; while (totalFramesRead < frameCount) { - mal_uint32 framesRemaining = frameCount - totalFramesRead; + ma_uint32 framesRemaining = frameCount - totalFramesRead; - mal_uint32 maxFramesToRead = 128; - mal_uint32 framesToRead = framesRemaining; + ma_uint32 maxFramesToRead = 128; + ma_uint32 framesToRead = framesRemaining; if (framesToRead > maxFramesToRead) { framesToRead = maxFramesToRead; } - mal_uint32 framesRead = (mal_uint32)mal_src_read_deinterleaved(&src, framesToRead, (void**)&pFramesF32, NULL); + ma_uint32 framesRead = (ma_uint32)ma_src_read_deinterleaved(&src, framesToRead, (void**)&pFramesF32, NULL); if (framesRead == 0) { reload_src_input(); } @@ -96,7 +96,7 @@ void on_send_to_device(mal_device* pDevice, void* pOutput, const void* pInput, m pFramesF32 += framesRead; } - mal_assert(totalFramesRead == frameCount); + ma_assert(totalFramesRead == frameCount); } int main(int argc, char** argv) @@ -105,18 +105,18 @@ int main(int argc, char** argv) (void)argv; - mal_device_config config = mal_device_config_init(mal_device_type_playback); - config.playback.format = mal_format_f32; + ma_device_config config = ma_device_config_init(ma_device_type_playback); + config.playback.format = ma_format_f32; config.playback.channels = 1; config.dataCallback = on_send_to_device; - mal_device device; - mal_result result; + ma_device device; + ma_result result; config.bufferSizeInFrames = 8192*1; // We first play the sound the way it's meant to be played. - result = mal_device_init(NULL, &config, &device); + result = ma_device_init(NULL, &config, &device); if (result != MA_SUCCESS) { return -1; } @@ -125,13 +125,13 @@ int main(int argc, char** argv) // For this test, we need the sine wave to be a different format to the device. sampleRateOut = device.sampleRate; sampleRateIn = (sampleRateOut == 44100) ? 48000 : 44100; - mal_sine_wave_init(0.2, 400, sampleRateIn, &sineWave); + ma_sine_wave_init(0.2, 400, sampleRateIn, &sineWave); - mal_src_config srcConfig = mal_src_config_init(sampleRateIn, sampleRateOut, 1, on_src, NULL); - srcConfig.algorithm = mal_src_algorithm_sinc; + ma_src_config srcConfig = ma_src_config_init(sampleRateIn, sampleRateOut, 1, on_src, NULL); + srcConfig.algorithm = ma_src_algorithm_sinc; srcConfig.neverConsumeEndOfInput = MA_TRUE; - result = mal_src_init(&srcConfig, &src); + result = ma_src_init(&srcConfig, &src); if (result != MA_SUCCESS) { printf("Failed to create SRC.\n"); return -1; @@ -158,7 +158,7 @@ int main(int argc, char** argv) msigvis_channel channelSineWave; - result = msigvis_channel_init(&sigvis, mal_format_f32, sampleRateOut, &channelSineWave); + result = msigvis_channel_init(&sigvis, ma_format_f32, sampleRateOut, &channelSineWave); if (result != MA_SUCCESS) { printf("Failed to initialize mini_sigvis channel.\n"); return -3; @@ -168,17 +168,17 @@ int main(int argc, char** argv) float* pFramesF32 = testSamples; // To reproduce the case we are needing to test, we need to read from the SRC in a very specific way. We keep looping - // until we've read the requested frame count, however we have an inner loop that keeps running until mal_src_read() + // until we've read the requested frame count, however we have an inner loop that keeps running until ma_src_read() // returns 0, in which case we need to reload the SRC's input data and keep going. - mal_uint32 totalFramesRead = 0; - while (totalFramesRead < mal_countof(testSamples)) { - mal_uint32 maxFramesToRead = 128; - mal_uint32 framesToRead = mal_countof(testSamples); + ma_uint32 totalFramesRead = 0; + while (totalFramesRead < ma_countof(testSamples)) { + ma_uint32 maxFramesToRead = 128; + ma_uint32 framesToRead = ma_countof(testSamples); if (framesToRead > maxFramesToRead) { framesToRead = maxFramesToRead; } - mal_uint32 framesRead = (mal_uint32)mal_src_read_deinterleaved(&src, framesToRead, (void**)&pFramesF32, NULL); + ma_uint32 framesRead = (ma_uint32)ma_src_read_deinterleaved(&src, framesToRead, (void**)&pFramesF32, NULL); if (framesRead == 0) { reload_src_input(); } @@ -187,7 +187,7 @@ int main(int argc, char** argv) pFramesF32 += framesRead; } - msigvis_channel_push_samples(&channelSineWave, mal_countof(testSamples), testSamples); + msigvis_channel_push_samples(&channelSineWave, ma_countof(testSamples), testSamples); msigvis_screen_add_channel(&screen, &channelSineWave); @@ -197,14 +197,14 @@ int main(int argc, char** argv) msigvis_uninit(&sigvis); #else - result = mal_device_start(&device); + result = ma_device_start(&device); if (result != MA_SUCCESS) { return -2; } printf("Press Enter to quit...\n"); getchar(); - mal_device_uninit(&device); + ma_device_uninit(&device); #endif return 0; diff --git a/tests/mal_stop.c b/tests/mal_stop.c index 83e514fc..e32f28a8 100644 --- a/tests/mal_stop.c +++ b/tests/mal_stop.c @@ -3,38 +3,38 @@ #define MINIAUDIO_IMPLEMENTATION #include "../miniaudio.h" -mal_sine_wave sineWave; -mal_uint32 framesWritten; -mal_event stopEvent; -mal_bool32 isInitialRun = MA_TRUE; +ma_sine_wave sineWave; +ma_uint32 framesWritten; +ma_event stopEvent; +ma_bool32 isInitialRun = MA_TRUE; -void on_stop(mal_device* pDevice) +void on_stop(ma_device* pDevice) { (void)pDevice; printf("STOPPED\n"); } -void on_data(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 frameCount) +void on_data(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount) { (void)pInput; /* Not used yet. */ /* Output exactly one second of data. Pad the end with silence. */ - mal_uint32 framesRemaining = pDevice->sampleRate - framesWritten; - mal_uint32 framesToProcess = frameCount; + ma_uint32 framesRemaining = pDevice->sampleRate - framesWritten; + ma_uint32 framesToProcess = frameCount; if (framesToProcess > framesRemaining && isInitialRun) { framesToProcess = framesRemaining; } - mal_sine_wave_read_f32_ex(&sineWave, framesToProcess, pDevice->playback.channels, mal_stream_layout_interleaved, (float**)&pOutput); + ma_sine_wave_read_f32_ex(&sineWave, framesToProcess, pDevice->playback.channels, ma_stream_layout_interleaved, (float**)&pOutput); if (isInitialRun) { framesWritten += framesToProcess; } - mal_assert(framesWritten <= pDevice->sampleRate); + ma_assert(framesWritten <= pDevice->sampleRate); if (framesWritten >= pDevice->sampleRate) { if (isInitialRun) { printf("STOPPING [AUDIO THREAD]...\n"); - mal_event_signal(&stopEvent); + ma_event_signal(&stopEvent); isInitialRun = MA_FALSE; } } @@ -42,57 +42,57 @@ void on_data(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 int main(int argc, char** argv) { - mal_result result; + ma_result result; (void)argc; (void)argv; - mal_backend backend = mal_backend_wasapi; + ma_backend backend = ma_backend_wasapi; - mal_sine_wave_init(0.25, 400, 44100, &sineWave); + ma_sine_wave_init(0.25, 400, 44100, &sineWave); - mal_device_config config = mal_device_config_init(mal_device_type_playback); - config.playback.format = mal_format_f32; + ma_device_config config = ma_device_config_init(ma_device_type_playback); + config.playback.format = ma_format_f32; config.playback.channels = 2; config.sampleRate = 44100; config.dataCallback = on_data; config.stopCallback = on_stop; config.bufferSizeInFrames = 16384; - mal_device device; - result = mal_device_init_ex(&backend, 1, NULL, &config, &device); + ma_device device; + result = ma_device_init_ex(&backend, 1, NULL, &config, &device); if (result != MA_SUCCESS) { printf("Failed to initialize device.\n"); return result; } - result = mal_event_init(device.pContext, &stopEvent); + result = ma_event_init(device.pContext, &stopEvent); if (result != MA_SUCCESS) { printf("Failed to initialize stop event.\n"); return result; } - mal_device_start(&device); + ma_device_start(&device); /* We wait for the stop event, stop the device, then ask the user to press any key to restart. This checks that the device can restart after stopping. */ - mal_event_wait(&stopEvent); + ma_event_wait(&stopEvent); printf("STOPPING [MAIN THREAD]...\n"); - mal_device_stop(&device); + ma_device_stop(&device); printf("Press Enter to restart...\n"); getchar(); - result = mal_device_start(&device); + result = ma_device_start(&device); if (result != MA_SUCCESS) { printf("Failed to restart the device.\n"); - mal_device_uninit(&device); + ma_device_uninit(&device); return -1; } printf("Press Enter to quit...\n"); getchar(); - mal_device_uninit(&device); + ma_device_uninit(&device); return 0; } \ No newline at end of file diff --git a/tests/mal_test_0.c b/tests/mal_test_0.c index 2ca4fbe2..b975953c 100644 --- a/tests/mal_test_0.c +++ b/tests/mal_test_0.c @@ -22,24 +22,24 @@ void main_loop__em() #endif -mal_backend g_Backends[] = { - mal_backend_wasapi, - mal_backend_dsound, - mal_backend_winmm, - mal_backend_coreaudio, - mal_backend_sndio, - mal_backend_audio4, - mal_backend_oss, - mal_backend_pulseaudio, - mal_backend_alsa, - mal_backend_jack, - mal_backend_aaudio, - mal_backend_opensl, - mal_backend_webaudio, - mal_backend_null +ma_backend g_Backends[] = { + ma_backend_wasapi, + ma_backend_dsound, + ma_backend_winmm, + ma_backend_coreaudio, + ma_backend_sndio, + ma_backend_audio4, + ma_backend_oss, + ma_backend_pulseaudio, + ma_backend_alsa, + ma_backend_jack, + ma_backend_aaudio, + ma_backend_opensl, + ma_backend_webaudio, + ma_backend_null }; -void on_log(mal_context* pContext, mal_device* pDevice, mal_uint32 logLevel, const char* message) +void on_log(ma_context* pContext, ma_device* pDevice, ma_uint32 logLevel, const char* message) { (void)pContext; (void)pDevice; @@ -47,13 +47,13 @@ void on_log(mal_context* pContext, mal_device* pDevice, mal_uint32 logLevel, con printf("%s\n", message); } -void on_stop(mal_device* pDevice) +void on_stop(ma_device* pDevice) { (void)pDevice; printf("Device Stopped.\n"); } -FILE* mal_fopen(const char* filePath, const char* openMode) +FILE* ma_fopen(const char* filePath, const char* openMode) { FILE* pFile; #if _MSC_VER @@ -79,13 +79,13 @@ void* open_and_read_file_data(const char* filePath, size_t* pSizeOut) return NULL; } - FILE* pFile = mal_fopen(filePath, "rb"); + FILE* pFile = ma_fopen(filePath, "rb"); if (pFile == NULL) { return NULL; } fseek(pFile, 0, SEEK_END); - mal_uint64 fileSize = ftell(pFile); + ma_uint64 fileSize = ftell(pFile); fseek(pFile, 0, SEEK_SET); if (fileSize > MA_SIZE_MAX) { @@ -93,7 +93,7 @@ void* open_and_read_file_data(const char* filePath, size_t* pSizeOut) return NULL; } - void* pFileData = mal_malloc((size_t)fileSize); // <-- Safe cast due to the check above. + void* pFileData = ma_malloc((size_t)fileSize); // <-- Safe cast due to the check above. if (pFileData == NULL) { fclose(pFile); return NULL; @@ -101,7 +101,7 @@ void* open_and_read_file_data(const char* filePath, size_t* pSizeOut) size_t bytesRead = fread(pFileData, 1, (size_t)fileSize, pFile); if (bytesRead != fileSize) { - mal_free(pFileData); + ma_free(pFileData); fclose(pFile); return NULL; } @@ -120,26 +120,26 @@ int do_types_tests() { int result = 0; - int sizeof_int8 = sizeof(mal_int8); - int sizeof_uint8 = sizeof(mal_uint8); - int sizeof_int16 = sizeof(mal_int16); - int sizeof_uint16 = sizeof(mal_uint16); - int sizeof_int32 = sizeof(mal_int32); - int sizeof_uint32 = sizeof(mal_uint32); - int sizeof_int64 = sizeof(mal_int64); - int sizeof_uint64 = sizeof(mal_uint64); + int sizeof_int8 = sizeof(ma_int8); + int sizeof_uint8 = sizeof(ma_uint8); + int sizeof_int16 = sizeof(ma_int16); + int sizeof_uint16 = sizeof(ma_uint16); + int sizeof_int32 = sizeof(ma_int32); + int sizeof_uint32 = sizeof(ma_uint32); + int sizeof_int64 = sizeof(ma_int64); + int sizeof_uint64 = sizeof(ma_uint64); int sizeof_float32 = sizeof(float); int sizeof_float64 = sizeof(double); - int sizeof_uintptr = sizeof(mal_uintptr); + int sizeof_uintptr = sizeof(ma_uintptr); - printf("sizeof(mal_int8) 1 = %d", sizeof_int8); + printf("sizeof(ma_int8) 1 = %d", sizeof_int8); if (sizeof_int8 != 1) { printf(" - FAILED\n"); result = -1; } else { printf(" - PASSED\n"); } - printf("sizeof(mal_uint8) 1 = %d", sizeof_uint8); + printf("sizeof(ma_uint8) 1 = %d", sizeof_uint8); if (sizeof_uint8 != 1) { printf(" - FAILED\n"); result = -1; @@ -147,14 +147,14 @@ int do_types_tests() printf(" - PASSED\n"); } - printf("sizeof(mal_int16) 2 = %d", sizeof_int16); + printf("sizeof(ma_int16) 2 = %d", sizeof_int16); if (sizeof_int16 != 2) { printf(" - FAILED\n"); result = -1; } else { printf(" - PASSED\n"); } - printf("sizeof(mal_uint16) 2 = %d", sizeof_uint16); + printf("sizeof(ma_uint16) 2 = %d", sizeof_uint16); if (sizeof_uint16 != 2) { printf(" - FAILED\n"); result = -1; @@ -162,14 +162,14 @@ int do_types_tests() printf(" - PASSED\n"); } - printf("sizeof(mal_int32) 4 = %d", sizeof_int32); + printf("sizeof(ma_int32) 4 = %d", sizeof_int32); if (sizeof_int32 != 4) { printf(" - FAILED\n"); result = -1; } else { printf(" - PASSED\n"); } - printf("sizeof(mal_uint32) 4 = %d", sizeof_uint32); + printf("sizeof(ma_uint32) 4 = %d", sizeof_uint32); if (sizeof_uint32 != 4) { printf(" - FAILED\n"); result = -1; @@ -177,14 +177,14 @@ int do_types_tests() printf(" - PASSED\n"); } - printf("sizeof(mal_int64) 8 = %d", sizeof_int64); + printf("sizeof(ma_int64) 8 = %d", sizeof_int64); if (sizeof_int64 != 8) { printf(" - FAILED\n"); result = -1; } else { printf(" - PASSED\n"); } - printf("sizeof(mal_uint64) 8 = %d", sizeof_uint64); + printf("sizeof(ma_uint64) 8 = %d", sizeof_uint64); if (sizeof_uint64 != 8) { printf(" - FAILED\n"); result = -1; @@ -207,7 +207,7 @@ int do_types_tests() printf(" - PASSED\n"); } - printf("sizeof(mal_uintptr) %d = %d", (int)sizeof(void*), sizeof_uintptr); + printf("sizeof(ma_uintptr) %d = %d", (int)sizeof(void*), sizeof_uintptr); if (sizeof_uintptr != sizeof(void*)) { printf(" - FAILED\n"); result = -1; @@ -224,19 +224,19 @@ int do_aligned_malloc_tests() // We just do a whole bunch of malloc's and check them. This can probably be made more exhaustive. void* p[1024]; - for (mal_uint32 i = 0; i < mal_countof(p); ++i) { - mal_uintptr alignment = MA_SIMD_ALIGNMENT; + for (ma_uint32 i = 0; i < ma_countof(p); ++i) { + ma_uintptr alignment = MA_SIMD_ALIGNMENT; - p[i] = mal_aligned_malloc(1024, alignment); - if (((mal_uintptr)p[i] & (alignment-1)) != 0) { + p[i] = ma_aligned_malloc(1024, alignment); + if (((ma_uintptr)p[i] & (alignment-1)) != 0) { printf("FAILED\n"); result = -1; } } // Free. - for (mal_uint32 i = 0; i < mal_countof(p); ++i) { - mal_aligned_free(p[i]); + for (ma_uint32 i = 0; i < ma_countof(p); ++i) { + ma_aligned_free(p[i]); } if (result == 0) { @@ -267,9 +267,9 @@ int do_core_tests() } -void* load_raw_audio_data(const char* filePath, mal_format format, mal_uint64* pBenchmarkFrameCount) +void* load_raw_audio_data(const char* filePath, ma_format format, ma_uint64* pBenchmarkFrameCount) { - mal_assert(pBenchmarkFrameCount != NULL); + ma_assert(pBenchmarkFrameCount != NULL); *pBenchmarkFrameCount = 0; size_t fileSize; @@ -279,15 +279,15 @@ void* load_raw_audio_data(const char* filePath, mal_format format, mal_uint64* p return NULL; } - *pBenchmarkFrameCount = fileSize / mal_get_bytes_per_sample(format); + *pBenchmarkFrameCount = fileSize / ma_get_bytes_per_sample(format); return pFileData; } -void* load_benchmark_base_data(mal_format format, mal_uint32* pChannelsOut, mal_uint32* pSampleRateOut, mal_uint64* pBenchmarkFrameCount) +void* load_benchmark_base_data(ma_format format, ma_uint32* pChannelsOut, ma_uint32* pSampleRateOut, ma_uint64* pBenchmarkFrameCount) { - mal_assert(pChannelsOut != NULL); - mal_assert(pSampleRateOut != NULL); - mal_assert(pBenchmarkFrameCount != NULL); + ma_assert(pChannelsOut != NULL); + ma_assert(pSampleRateOut != NULL); + ma_assert(pBenchmarkFrameCount != NULL); *pChannelsOut = 1; *pSampleRateOut = 8000; @@ -295,81 +295,81 @@ void* load_benchmark_base_data(mal_format format, mal_uint32* pChannelsOut, mal_ const char* filePath = NULL; switch (format) { - case mal_format_u8: filePath = "res/benchmarks/pcm_u8_to_u8__mono_8000.raw"; break; - case mal_format_s16: filePath = "res/benchmarks/pcm_s16_to_s16__mono_8000.raw"; break; - case mal_format_s24: filePath = "res/benchmarks/pcm_s24_to_s24__mono_8000.raw"; break; - case mal_format_s32: filePath = "res/benchmarks/pcm_s32_to_s32__mono_8000.raw"; break; - case mal_format_f32: filePath = "res/benchmarks/pcm_f32_to_f32__mono_8000.raw"; break; + case ma_format_u8: filePath = "res/benchmarks/pcm_u8_to_u8__mono_8000.raw"; break; + case ma_format_s16: filePath = "res/benchmarks/pcm_s16_to_s16__mono_8000.raw"; break; + case ma_format_s24: filePath = "res/benchmarks/pcm_s24_to_s24__mono_8000.raw"; break; + case ma_format_s32: filePath = "res/benchmarks/pcm_s32_to_s32__mono_8000.raw"; break; + case ma_format_f32: filePath = "res/benchmarks/pcm_f32_to_f32__mono_8000.raw"; break; default: return NULL; } return load_raw_audio_data(filePath, format, pBenchmarkFrameCount); } -int mal_pcm_compare(const void* a, const void* b, mal_uint64 count, mal_format format, float allowedDifference) +int ma_pcm_compare(const void* a, const void* b, ma_uint64 count, ma_format format, float allowedDifference) { int result = 0; - const mal_uint8* a_u8 = (const mal_uint8*)a; - const mal_uint8* b_u8 = (const mal_uint8*)b; - const mal_int16* a_s16 = (const mal_int16*)a; - const mal_int16* b_s16 = (const mal_int16*)b; - const mal_int32* a_s32 = (const mal_int32*)a; - const mal_int32* b_s32 = (const mal_int32*)b; + const ma_uint8* a_u8 = (const ma_uint8*)a; + const ma_uint8* b_u8 = (const ma_uint8*)b; + const ma_int16* a_s16 = (const ma_int16*)a; + const ma_int16* b_s16 = (const ma_int16*)b; + const ma_int32* a_s32 = (const ma_int32*)a; + const ma_int32* b_s32 = (const ma_int32*)b; const float* a_f32 = (const float* )a; const float* b_f32 = (const float* )b; - for (mal_uint64 i = 0; i < count; ++i) { + for (ma_uint64 i = 0; i < count; ++i) { switch (format) { - case mal_format_u8: + case ma_format_u8: { - mal_uint8 sampleA = a_u8[i]; - mal_uint8 sampleB = b_u8[i]; + ma_uint8 sampleA = a_u8[i]; + ma_uint8 sampleB = b_u8[i]; if (sampleA != sampleB) { if (abs(sampleA - sampleB) > allowedDifference) { // Allow a difference of 1. - printf("Sample %u not equal. %d != %d (diff: %d)\n", (mal_int32)i, sampleA, sampleB, sampleA - sampleB); + printf("Sample %u not equal. %d != %d (diff: %d)\n", (ma_int32)i, sampleA, sampleB, sampleA - sampleB); result = -1; } } } break; - case mal_format_s16: + case ma_format_s16: { - mal_int16 sampleA = a_s16[i]; - mal_int16 sampleB = b_s16[i]; + ma_int16 sampleA = a_s16[i]; + ma_int16 sampleB = b_s16[i]; if (sampleA != sampleB) { if (abs(sampleA - sampleB) > allowedDifference) { // Allow a difference of 1. - printf("Sample %u not equal. %d != %d (diff: %d)\n", (mal_int32)i, sampleA, sampleB, sampleA - sampleB); + printf("Sample %u not equal. %d != %d (diff: %d)\n", (ma_int32)i, sampleA, sampleB, sampleA - sampleB); result = -1; } } } break; - case mal_format_s24: + case ma_format_s24: { - mal_int32 sampleA = ((mal_int32)(((mal_uint32)(a_u8[i*3+0]) << 8) | ((mal_uint32)(a_u8[i*3+1]) << 16) | ((mal_uint32)(a_u8[i*3+2])) << 24)) >> 8; - mal_int32 sampleB = ((mal_int32)(((mal_uint32)(b_u8[i*3+0]) << 8) | ((mal_uint32)(b_u8[i*3+1]) << 16) | ((mal_uint32)(b_u8[i*3+2])) << 24)) >> 8; + ma_int32 sampleA = ((ma_int32)(((ma_uint32)(a_u8[i*3+0]) << 8) | ((ma_uint32)(a_u8[i*3+1]) << 16) | ((ma_uint32)(a_u8[i*3+2])) << 24)) >> 8; + ma_int32 sampleB = ((ma_int32)(((ma_uint32)(b_u8[i*3+0]) << 8) | ((ma_uint32)(b_u8[i*3+1]) << 16) | ((ma_uint32)(b_u8[i*3+2])) << 24)) >> 8; if (sampleA != sampleB) { if (abs(sampleA - sampleB) > allowedDifference) { // Allow a difference of 1. - printf("Sample %u not equal. %d != %d (diff: %d)\n", (mal_int32)i, sampleA, sampleB, sampleA - sampleB); + printf("Sample %u not equal. %d != %d (diff: %d)\n", (ma_int32)i, sampleA, sampleB, sampleA - sampleB); result = -1; } } } break; - case mal_format_s32: + case ma_format_s32: { - mal_int32 sampleA = a_s32[i]; - mal_int32 sampleB = b_s32[i]; + ma_int32 sampleA = a_s32[i]; + ma_int32 sampleB = b_s32[i]; if (sampleA != sampleB) { if (abs(sampleA - sampleB) > allowedDifference) { // Allow a difference of 1. - printf("Sample %u not equal. %d != %d (diff: %d)\n", (mal_int32)i, sampleA, sampleB, sampleA - sampleB); + printf("Sample %u not equal. %d != %d (diff: %d)\n", (ma_int32)i, sampleA, sampleB, sampleA - sampleB); result = -1; } } } break; - case mal_format_f32: + case ma_format_f32: { float sampleA = a_f32[i]; float sampleB = b_f32[i]; @@ -378,7 +378,7 @@ int mal_pcm_compare(const void* a, const void* b, mal_uint64 count, mal_format f difference = (difference < 0) ? -difference : difference; if (difference > allowedDifference) { - printf("Sample %u not equal. %.8f != %.8f (diff: %.8f)\n", (mal_int32)i, sampleA, sampleB, sampleA - sampleB); + printf("Sample %u not equal. %.8f != %.8f (diff: %.8f)\n", (ma_int32)i, sampleA, sampleB, sampleA - sampleB); result = -1; } } @@ -391,48 +391,48 @@ int mal_pcm_compare(const void* a, const void* b, mal_uint64 count, mal_format f return result; } -int do_format_conversion_test(mal_format formatIn, mal_format formatOut) +int do_format_conversion_test(ma_format formatIn, ma_format formatOut) { int result = 0; - mal_uint32 channels; - mal_uint32 sampleRate; - mal_uint64 baseFrameCount; - mal_int16* pBaseData = (mal_int16*)load_benchmark_base_data(formatIn, &channels, &sampleRate, &baseFrameCount); + ma_uint32 channels; + ma_uint32 sampleRate; + ma_uint64 baseFrameCount; + ma_int16* pBaseData = (ma_int16*)load_benchmark_base_data(formatIn, &channels, &sampleRate, &baseFrameCount); if (pBaseData == NULL) { return -1; // Failed to load file. } - void (* onConvertPCM)(void* dst, const void* src, mal_uint64 count, mal_dither_mode ditherMode) = NULL; + void (* onConvertPCM)(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode) = NULL; const char* pBenchmarkFilePath = NULL; switch (formatIn) { - case mal_format_u8: + case ma_format_u8: { switch (formatOut) { - case mal_format_u8: + case ma_format_u8: { - onConvertPCM = mal_pcm_u8_to_u8; + onConvertPCM = ma_pcm_u8_to_u8; pBenchmarkFilePath = "res/benchmarks/pcm_u8_to_u8__mono_8000.raw"; } break; - case mal_format_s16: + case ma_format_s16: { - onConvertPCM = mal_pcm_u8_to_s16__reference; + onConvertPCM = ma_pcm_u8_to_s16__reference; pBenchmarkFilePath = "res/benchmarks/pcm_u8_to_s16__mono_8000.raw"; } break; - case mal_format_s24: + case ma_format_s24: { - onConvertPCM = mal_pcm_u8_to_s24__reference; + onConvertPCM = ma_pcm_u8_to_s24__reference; pBenchmarkFilePath = "res/benchmarks/pcm_u8_to_s24__mono_8000.raw"; } break; - case mal_format_s32: + case ma_format_s32: { - onConvertPCM = mal_pcm_u8_to_s32__reference; + onConvertPCM = ma_pcm_u8_to_s32__reference; pBenchmarkFilePath = "res/benchmarks/pcm_u8_to_s32__mono_8000.raw"; } break; - case mal_format_f32: + case ma_format_f32: { - onConvertPCM = mal_pcm_u8_to_f32__reference; + onConvertPCM = ma_pcm_u8_to_f32__reference; pBenchmarkFilePath = "res/benchmarks/pcm_u8_to_f32__mono_8000.raw"; } break; default: @@ -442,32 +442,32 @@ int do_format_conversion_test(mal_format formatIn, mal_format formatOut) } } break; - case mal_format_s16: + case ma_format_s16: { switch (formatOut) { - case mal_format_u8: + case ma_format_u8: { - onConvertPCM = mal_pcm_s16_to_u8__reference; + onConvertPCM = ma_pcm_s16_to_u8__reference; pBenchmarkFilePath = "res/benchmarks/pcm_s16_to_u8__mono_8000.raw"; } break; - case mal_format_s16: + case ma_format_s16: { - onConvertPCM = mal_pcm_s16_to_s16; + onConvertPCM = ma_pcm_s16_to_s16; pBenchmarkFilePath = "res/benchmarks/pcm_s16_to_s16__mono_8000.raw"; } break; - case mal_format_s24: + case ma_format_s24: { - onConvertPCM = mal_pcm_s16_to_s24__reference; + onConvertPCM = ma_pcm_s16_to_s24__reference; pBenchmarkFilePath = "res/benchmarks/pcm_s16_to_s24__mono_8000.raw"; } break; - case mal_format_s32: + case ma_format_s32: { - onConvertPCM = mal_pcm_s16_to_s32__reference; + onConvertPCM = ma_pcm_s16_to_s32__reference; pBenchmarkFilePath = "res/benchmarks/pcm_s16_to_s32__mono_8000.raw"; } break; - case mal_format_f32: + case ma_format_f32: { - onConvertPCM = mal_pcm_s16_to_f32__reference; + onConvertPCM = ma_pcm_s16_to_f32__reference; pBenchmarkFilePath = "res/benchmarks/pcm_s16_to_f32__mono_8000.raw"; } break; default: @@ -477,32 +477,32 @@ int do_format_conversion_test(mal_format formatIn, mal_format formatOut) } } break; - case mal_format_s24: + case ma_format_s24: { switch (formatOut) { - case mal_format_u8: + case ma_format_u8: { - onConvertPCM = mal_pcm_s24_to_u8__reference; + onConvertPCM = ma_pcm_s24_to_u8__reference; pBenchmarkFilePath = "res/benchmarks/pcm_s24_to_u8__mono_8000.raw"; } break; - case mal_format_s16: + case ma_format_s16: { - onConvertPCM = mal_pcm_s24_to_s16__reference; + onConvertPCM = ma_pcm_s24_to_s16__reference; pBenchmarkFilePath = "res/benchmarks/pcm_s24_to_s16__mono_8000.raw"; } break; - case mal_format_s24: + case ma_format_s24: { - onConvertPCM = mal_pcm_s24_to_s24; + onConvertPCM = ma_pcm_s24_to_s24; pBenchmarkFilePath = "res/benchmarks/pcm_s24_to_s24__mono_8000.raw"; } break; - case mal_format_s32: + case ma_format_s32: { - onConvertPCM = mal_pcm_s24_to_s32__reference; + onConvertPCM = ma_pcm_s24_to_s32__reference; pBenchmarkFilePath = "res/benchmarks/pcm_s24_to_s32__mono_8000.raw"; } break; - case mal_format_f32: + case ma_format_f32: { - onConvertPCM = mal_pcm_s24_to_f32__reference; + onConvertPCM = ma_pcm_s24_to_f32__reference; pBenchmarkFilePath = "res/benchmarks/pcm_s24_to_f32__mono_8000.raw"; } break; default: @@ -512,32 +512,32 @@ int do_format_conversion_test(mal_format formatIn, mal_format formatOut) } } break; - case mal_format_s32: + case ma_format_s32: { switch (formatOut) { - case mal_format_u8: + case ma_format_u8: { - onConvertPCM = mal_pcm_s32_to_u8__reference; + onConvertPCM = ma_pcm_s32_to_u8__reference; pBenchmarkFilePath = "res/benchmarks/pcm_s32_to_u8__mono_8000.raw"; } break; - case mal_format_s16: + case ma_format_s16: { - onConvertPCM = mal_pcm_s32_to_s16__reference; + onConvertPCM = ma_pcm_s32_to_s16__reference; pBenchmarkFilePath = "res/benchmarks/pcm_s32_to_s16__mono_8000.raw"; } break; - case mal_format_s24: + case ma_format_s24: { - onConvertPCM = mal_pcm_s32_to_s24__reference; + onConvertPCM = ma_pcm_s32_to_s24__reference; pBenchmarkFilePath = "res/benchmarks/pcm_s32_to_s24__mono_8000.raw"; } break; - case mal_format_s32: + case ma_format_s32: { - onConvertPCM = mal_pcm_s32_to_s32; + onConvertPCM = ma_pcm_s32_to_s32; pBenchmarkFilePath = "res/benchmarks/pcm_s32_to_s32__mono_8000.raw"; } break; - case mal_format_f32: + case ma_format_f32: { - onConvertPCM = mal_pcm_s32_to_f32__reference; + onConvertPCM = ma_pcm_s32_to_f32__reference; pBenchmarkFilePath = "res/benchmarks/pcm_s32_to_f32__mono_8000.raw"; } break; default: @@ -547,32 +547,32 @@ int do_format_conversion_test(mal_format formatIn, mal_format formatOut) } } break; - case mal_format_f32: + case ma_format_f32: { switch (formatOut) { - case mal_format_u8: + case ma_format_u8: { - onConvertPCM = mal_pcm_f32_to_u8__reference; + onConvertPCM = ma_pcm_f32_to_u8__reference; pBenchmarkFilePath = "res/benchmarks/pcm_f32_to_u8__mono_8000.raw"; } break; - case mal_format_s16: + case ma_format_s16: { - onConvertPCM = mal_pcm_f32_to_s16__reference; + onConvertPCM = ma_pcm_f32_to_s16__reference; pBenchmarkFilePath = "res/benchmarks/pcm_f32_to_s16__mono_8000.raw"; } break; - case mal_format_s24: + case ma_format_s24: { - onConvertPCM = mal_pcm_f32_to_s24__reference; + onConvertPCM = ma_pcm_f32_to_s24__reference; pBenchmarkFilePath = "res/benchmarks/pcm_f32_to_s24__mono_8000.raw"; } break; - case mal_format_s32: + case ma_format_s32: { - onConvertPCM = mal_pcm_f32_to_s32__reference; + onConvertPCM = ma_pcm_f32_to_s32__reference; pBenchmarkFilePath = "res/benchmarks/pcm_f32_to_s32__mono_8000.raw"; } break; - case mal_format_f32: + case ma_format_f32: { - onConvertPCM = mal_pcm_f32_to_f32; + onConvertPCM = ma_pcm_f32_to_f32; pBenchmarkFilePath = "res/benchmarks/pcm_f32_to_f32__mono_8000.raw"; } break; default: @@ -590,23 +590,23 @@ int do_format_conversion_test(mal_format formatIn, mal_format formatOut) if (result != 0) { - mal_free(pBaseData); + ma_free(pBaseData); return result; } // We need to allow a very small amount of difference to each sample because the software that generated our testing benchmarks can use slightly // different (but still correct) algorithms which produce slightly different results. I'm allowing for this variability in my basic comparison // tests, but testing things like dithering will require more detailed testing which I'll probably do separate to this test project. - mal_bool32 allowSmallDifference = MA_TRUE; + ma_bool32 allowSmallDifference = MA_TRUE; float allowedDifference = 0; if (allowSmallDifference) { - if (formatOut == mal_format_f32) { + if (formatOut == ma_format_f32) { switch (formatIn) { - case mal_format_u8: allowedDifference = 1.0f / 255 * 2; break; - case mal_format_s16: allowedDifference = 1.0f / 32767 * 2; break; - case mal_format_s24: allowedDifference = 1.0f / 8388608 * 2; break; - case mal_format_s32: allowedDifference = 1.0f / 2147483647 * 2; break; - case mal_format_f32: allowedDifference = 0; break; + case ma_format_u8: allowedDifference = 1.0f / 255 * 2; break; + case ma_format_s16: allowedDifference = 1.0f / 32767 * 2; break; + case ma_format_s24: allowedDifference = 1.0f / 8388608 * 2; break; + case ma_format_s32: allowedDifference = 1.0f / 2147483647 * 2; break; + case ma_format_f32: allowedDifference = 0; break; default: break; } } else { @@ -614,14 +614,14 @@ int do_format_conversion_test(mal_format formatIn, mal_format formatOut) } } - mal_uint64 benchmarkFrameCount; + ma_uint64 benchmarkFrameCount; void* pBenchmarkData = load_raw_audio_data(pBenchmarkFilePath, formatOut, &benchmarkFrameCount); if (pBenchmarkData != NULL) { if (benchmarkFrameCount == baseFrameCount) { - void* pConvertedData = (void*)mal_malloc((size_t)benchmarkFrameCount * mal_get_bytes_per_sample(formatOut)); + void* pConvertedData = (void*)ma_malloc((size_t)benchmarkFrameCount * ma_get_bytes_per_sample(formatOut)); if (pConvertedData != NULL) { - onConvertPCM(pConvertedData, pBaseData, (mal_uint32)benchmarkFrameCount, mal_dither_mode_none); - result = mal_pcm_compare(pBenchmarkData, pConvertedData, benchmarkFrameCount, formatOut, allowedDifference); + onConvertPCM(pConvertedData, pBaseData, (ma_uint32)benchmarkFrameCount, ma_dither_mode_none); + result = ma_pcm_compare(pBenchmarkData, pConvertedData, benchmarkFrameCount, formatOut, allowedDifference); if (result == 0) { printf("PASSED\n"); } @@ -639,8 +639,8 @@ int do_format_conversion_test(mal_format formatIn, mal_format formatOut) } - mal_free(pBaseData); - mal_free(pBenchmarkData); + ma_free(pBaseData); + ma_free(pBenchmarkData); return result; } @@ -649,27 +649,27 @@ int do_format_conversion_tests_u8() int result = 0; printf("PCM u8 -> u8... "); - if (do_format_conversion_test(mal_format_u8, mal_format_u8) != 0) { + if (do_format_conversion_test(ma_format_u8, ma_format_u8) != 0) { result = -1; } printf("PCM u8 -> s16... "); - if (do_format_conversion_test(mal_format_u8, mal_format_s16) != 0) { + if (do_format_conversion_test(ma_format_u8, ma_format_s16) != 0) { result = -1; } printf("PCM u8 -> s24... "); - if (do_format_conversion_test(mal_format_u8, mal_format_s24) != 0) { + if (do_format_conversion_test(ma_format_u8, ma_format_s24) != 0) { result = -1; } printf("PCM u8 -> s32... "); - if (do_format_conversion_test(mal_format_u8, mal_format_s32) != 0) { + if (do_format_conversion_test(ma_format_u8, ma_format_s32) != 0) { result = -1; } printf("PCM u8 -> f32... "); - if (do_format_conversion_test(mal_format_u8, mal_format_f32) != 0) { + if (do_format_conversion_test(ma_format_u8, ma_format_f32) != 0) { result = -1; } @@ -681,27 +681,27 @@ int do_format_conversion_tests_s16() int result = 0; printf("PCM s16 -> u8... "); - if (do_format_conversion_test(mal_format_s16, mal_format_u8) != 0) { + if (do_format_conversion_test(ma_format_s16, ma_format_u8) != 0) { result = -1; } printf("PCM s16 -> s16... "); - if (do_format_conversion_test(mal_format_s16, mal_format_s16) != 0) { + if (do_format_conversion_test(ma_format_s16, ma_format_s16) != 0) { result = -1; } printf("PCM s16 -> s24... "); - if (do_format_conversion_test(mal_format_s16, mal_format_s24) != 0) { + if (do_format_conversion_test(ma_format_s16, ma_format_s24) != 0) { result = -1; } printf("PCM s16 -> s32... "); - if (do_format_conversion_test(mal_format_s16, mal_format_s32) != 0) { + if (do_format_conversion_test(ma_format_s16, ma_format_s32) != 0) { result = -1; } printf("PCM s16 -> f32... "); - if (do_format_conversion_test(mal_format_s16, mal_format_f32) != 0) { + if (do_format_conversion_test(ma_format_s16, ma_format_f32) != 0) { result = -1; } @@ -713,27 +713,27 @@ int do_format_conversion_tests_s24() int result = 0; printf("PCM s24 -> u8... "); - if (do_format_conversion_test(mal_format_s24, mal_format_u8) != 0) { + if (do_format_conversion_test(ma_format_s24, ma_format_u8) != 0) { result = -1; } printf("PCM s24 -> s16... "); - if (do_format_conversion_test(mal_format_s24, mal_format_s16) != 0) { + if (do_format_conversion_test(ma_format_s24, ma_format_s16) != 0) { result = -1; } printf("PCM s24 -> s24... "); - if (do_format_conversion_test(mal_format_s24, mal_format_s24) != 0) { + if (do_format_conversion_test(ma_format_s24, ma_format_s24) != 0) { result = -1; } printf("PCM s24 -> s32... "); - if (do_format_conversion_test(mal_format_s24, mal_format_s32) != 0) { + if (do_format_conversion_test(ma_format_s24, ma_format_s32) != 0) { result = -1; } printf("PCM s24 -> f32... "); - if (do_format_conversion_test(mal_format_s24, mal_format_f32) != 0) { + if (do_format_conversion_test(ma_format_s24, ma_format_f32) != 0) { result = -1; } @@ -745,27 +745,27 @@ int do_format_conversion_tests_s32() int result = 0; printf("PCM s32 -> u8... "); - if (do_format_conversion_test(mal_format_s32, mal_format_u8) != 0) { + if (do_format_conversion_test(ma_format_s32, ma_format_u8) != 0) { result = -1; } printf("PCM s32 -> s16... "); - if (do_format_conversion_test(mal_format_s32, mal_format_s16) != 0) { + if (do_format_conversion_test(ma_format_s32, ma_format_s16) != 0) { result = -1; } printf("PCM s32 -> s24... "); - if (do_format_conversion_test(mal_format_s32, mal_format_s24) != 0) { + if (do_format_conversion_test(ma_format_s32, ma_format_s24) != 0) { result = -1; } printf("PCM s32 -> s32... "); - if (do_format_conversion_test(mal_format_s32, mal_format_s32) != 0) { + if (do_format_conversion_test(ma_format_s32, ma_format_s32) != 0) { result = -1; } printf("PCM s32 -> f32... "); - if (do_format_conversion_test(mal_format_s32, mal_format_f32) != 0) { + if (do_format_conversion_test(ma_format_s32, ma_format_f32) != 0) { result = -1; } @@ -777,27 +777,27 @@ int do_format_conversion_tests_f32() int result = 0; printf("PCM f32 -> u8... "); - if (do_format_conversion_test(mal_format_f32, mal_format_u8) != 0) { + if (do_format_conversion_test(ma_format_f32, ma_format_u8) != 0) { result = -1; } printf("PCM f32 -> s16... "); - if (do_format_conversion_test(mal_format_f32, mal_format_s16) != 0) { + if (do_format_conversion_test(ma_format_f32, ma_format_s16) != 0) { result = -1; } printf("PCM f32 -> s24... "); - if (do_format_conversion_test(mal_format_f32, mal_format_s24) != 0) { + if (do_format_conversion_test(ma_format_f32, ma_format_s24) != 0) { result = -1; } printf("PCM f32 -> s32... "); - if (do_format_conversion_test(mal_format_f32, mal_format_s32) != 0) { + if (do_format_conversion_test(ma_format_f32, ma_format_s32) != 0) { result = -1; } printf("PCM f32 -> f32... "); - if (do_format_conversion_test(mal_format_f32, mal_format_f32) != 0) { + if (do_format_conversion_test(ma_format_f32, ma_format_f32) != 0) { result = -1; } @@ -828,18 +828,18 @@ int do_format_conversion_tests() } -int compare_interleaved_and_deinterleaved_buffers(const void* interleaved, const void** deinterleaved, mal_uint32 frameCount, mal_uint32 channels, mal_format format) +int compare_interleaved_and_deinterleaved_buffers(const void* interleaved, const void** deinterleaved, ma_uint32 frameCount, ma_uint32 channels, ma_format format) { - mal_uint32 bytesPerSample = mal_get_bytes_per_sample(format); + ma_uint32 bytesPerSample = ma_get_bytes_per_sample(format); - const mal_uint8* interleaved8 = (const mal_uint8*)interleaved; - const mal_uint8** deinterleaved8 = (const mal_uint8**)deinterleaved; + const ma_uint8* interleaved8 = (const ma_uint8*)interleaved; + const ma_uint8** deinterleaved8 = (const ma_uint8**)deinterleaved; - for (mal_uint32 iFrame = 0; iFrame < frameCount; iFrame += 1) { - const mal_uint8* interleavedFrame = interleaved8 + iFrame*channels*bytesPerSample; + for (ma_uint32 iFrame = 0; iFrame < frameCount; iFrame += 1) { + const ma_uint8* interleavedFrame = interleaved8 + iFrame*channels*bytesPerSample; - for (mal_uint32 iChannel = 0; iChannel < channels; iChannel += 1) { - const mal_uint8* deinterleavedFrame = deinterleaved8[iChannel] + iFrame*bytesPerSample; + for (ma_uint32 iChannel = 0; iChannel < channels; iChannel += 1) { + const ma_uint8* deinterleavedFrame = deinterleaved8[iChannel] + iFrame*bytesPerSample; int result = memcmp(interleavedFrame + iChannel*bytesPerSample, deinterleavedFrame, bytesPerSample); if (result != 0) { @@ -852,7 +852,7 @@ int compare_interleaved_and_deinterleaved_buffers(const void* interleaved, const return 0; } -int do_interleaving_test(mal_format format) +int do_interleaving_test(ma_format format) { // This test is simple. We start with a deinterleaved buffer. We then test interleaving. Then we deinterleave the interleaved buffer // and compare that the original. It should be bit-perfect. We do this for all channel counts. @@ -861,19 +861,19 @@ int do_interleaving_test(mal_format format) switch (format) { - case mal_format_u8: + case ma_format_u8: { - mal_uint8 src [MA_MAX_CHANNELS][64]; - mal_uint8 dst [MA_MAX_CHANNELS][64]; - mal_uint8 dsti[MA_MAX_CHANNELS*64]; + ma_uint8 src [MA_MAX_CHANNELS][64]; + ma_uint8 dst [MA_MAX_CHANNELS][64]; + ma_uint8 dsti[MA_MAX_CHANNELS*64]; void* ppSrc[MA_MAX_CHANNELS]; void* ppDst[MA_MAX_CHANNELS]; - mal_uint32 frameCount = mal_countof(src[0]); - mal_uint32 channelCount = mal_countof(src); - for (mal_uint32 iChannel = 0; iChannel < channelCount; iChannel += 1) { - for (mal_uint32 iFrame = 0; iFrame < frameCount; iFrame += 1) { - src[iChannel][iFrame] = (mal_uint8)iChannel; + ma_uint32 frameCount = ma_countof(src[0]); + ma_uint32 channelCount = ma_countof(src); + for (ma_uint32 iChannel = 0; iChannel < channelCount; iChannel += 1) { + for (ma_uint32 iFrame = 0; iFrame < frameCount; iFrame += 1) { + src[iChannel][iFrame] = (ma_uint8)iChannel; } ppSrc[iChannel] = &src[iChannel]; @@ -881,11 +881,11 @@ int do_interleaving_test(mal_format format) } // Now test every channel count. - for (mal_uint32 i = 0; i < channelCount; ++i) { - mal_uint32 channelCountForThisIteration = i + 1; + for (ma_uint32 i = 0; i < channelCount; ++i) { + ma_uint32 channelCountForThisIteration = i + 1; // Interleave. - mal_pcm_interleave_u8__reference(dsti, (const void**)ppSrc, frameCount, channelCountForThisIteration); + ma_pcm_interleave_u8__reference(dsti, (const void**)ppSrc, frameCount, channelCountForThisIteration); if (compare_interleaved_and_deinterleaved_buffers(dsti, (const void**)ppSrc, frameCount, channelCountForThisIteration, format) != 0) { printf("FAILED. Deinterleaved to Interleaved (Channels = %u)\n", i); result = -1; @@ -893,7 +893,7 @@ int do_interleaving_test(mal_format format) } // Deinterleave. - mal_pcm_deinterleave_u8__reference((void**)ppDst, dsti, frameCount, channelCountForThisIteration); + ma_pcm_deinterleave_u8__reference((void**)ppDst, dsti, frameCount, channelCountForThisIteration); if (compare_interleaved_and_deinterleaved_buffers(dsti, (const void**)ppDst, frameCount, channelCountForThisIteration, format) != 0) { printf("FAILED. Interleaved to Deinterleaved (Channels = %u)\n", i); result = -1; @@ -902,19 +902,19 @@ int do_interleaving_test(mal_format format) } } break; - case mal_format_s16: + case ma_format_s16: { - mal_int16 src [MA_MAX_CHANNELS][64]; - mal_int16 dst [MA_MAX_CHANNELS][64]; - mal_int16 dsti[MA_MAX_CHANNELS*64]; + ma_int16 src [MA_MAX_CHANNELS][64]; + ma_int16 dst [MA_MAX_CHANNELS][64]; + ma_int16 dsti[MA_MAX_CHANNELS*64]; void* ppSrc[MA_MAX_CHANNELS]; void* ppDst[MA_MAX_CHANNELS]; - mal_uint32 frameCount = mal_countof(src[0]); - mal_uint32 channelCount = mal_countof(src); - for (mal_uint32 iChannel = 0; iChannel < channelCount; iChannel += 1) { - for (mal_uint32 iFrame = 0; iFrame < frameCount; iFrame += 1) { - src[iChannel][iFrame] = (mal_int16)iChannel; + ma_uint32 frameCount = ma_countof(src[0]); + ma_uint32 channelCount = ma_countof(src); + for (ma_uint32 iChannel = 0; iChannel < channelCount; iChannel += 1) { + for (ma_uint32 iFrame = 0; iFrame < frameCount; iFrame += 1) { + src[iChannel][iFrame] = (ma_int16)iChannel; } ppSrc[iChannel] = &src[iChannel]; @@ -922,11 +922,11 @@ int do_interleaving_test(mal_format format) } // Now test every channel count. - for (mal_uint32 i = 0; i < channelCount; ++i) { - mal_uint32 channelCountForThisIteration = i + 1; + for (ma_uint32 i = 0; i < channelCount; ++i) { + ma_uint32 channelCountForThisIteration = i + 1; // Interleave. - mal_pcm_interleave_s16__reference(dsti, (const void**)ppSrc, frameCount, channelCountForThisIteration); + ma_pcm_interleave_s16__reference(dsti, (const void**)ppSrc, frameCount, channelCountForThisIteration); if (compare_interleaved_and_deinterleaved_buffers(dsti, (const void**)ppSrc, frameCount, channelCountForThisIteration, format) != 0) { printf("FAILED. Deinterleaved to Interleaved (Channels = %u)\n", i); result = -1; @@ -934,7 +934,7 @@ int do_interleaving_test(mal_format format) } // Deinterleave. - mal_pcm_deinterleave_s16__reference((void**)ppDst, dsti, frameCount, channelCountForThisIteration); + ma_pcm_deinterleave_s16__reference((void**)ppDst, dsti, frameCount, channelCountForThisIteration); if (compare_interleaved_and_deinterleaved_buffers(dsti, (const void**)ppDst, frameCount, channelCountForThisIteration, format) != 0) { printf("FAILED. Interleaved to Deinterleaved (Channels = %u)\n", i); result = -1; @@ -943,21 +943,21 @@ int do_interleaving_test(mal_format format) } } break; - case mal_format_s24: + case ma_format_s24: { - mal_uint8 src [MA_MAX_CHANNELS][64*3]; - mal_uint8 dst [MA_MAX_CHANNELS][64*3]; - mal_uint8 dsti[MA_MAX_CHANNELS*64*3]; + ma_uint8 src [MA_MAX_CHANNELS][64*3]; + ma_uint8 dst [MA_MAX_CHANNELS][64*3]; + ma_uint8 dsti[MA_MAX_CHANNELS*64*3]; void* ppSrc[MA_MAX_CHANNELS]; void* ppDst[MA_MAX_CHANNELS]; - mal_uint32 frameCount = mal_countof(src[0])/3; - mal_uint32 channelCount = mal_countof(src); - for (mal_uint32 iChannel = 0; iChannel < channelCount; iChannel += 1) { - for (mal_uint32 iFrame = 0; iFrame < frameCount; iFrame += 1) { - src[iChannel][iFrame*3 + 0] = (mal_uint8)iChannel; - src[iChannel][iFrame*3 + 1] = (mal_uint8)iChannel; - src[iChannel][iFrame*3 + 2] = (mal_uint8)iChannel; + ma_uint32 frameCount = ma_countof(src[0])/3; + ma_uint32 channelCount = ma_countof(src); + for (ma_uint32 iChannel = 0; iChannel < channelCount; iChannel += 1) { + for (ma_uint32 iFrame = 0; iFrame < frameCount; iFrame += 1) { + src[iChannel][iFrame*3 + 0] = (ma_uint8)iChannel; + src[iChannel][iFrame*3 + 1] = (ma_uint8)iChannel; + src[iChannel][iFrame*3 + 2] = (ma_uint8)iChannel; } ppSrc[iChannel] = &src[iChannel]; @@ -965,11 +965,11 @@ int do_interleaving_test(mal_format format) } // Now test every channel count. - for (mal_uint32 i = 0; i < channelCount; ++i) { - mal_uint32 channelCountForThisIteration = i + 1; + for (ma_uint32 i = 0; i < channelCount; ++i) { + ma_uint32 channelCountForThisIteration = i + 1; // Interleave. - mal_pcm_interleave_s24__reference(dsti, (const void**)ppSrc, frameCount, channelCountForThisIteration); + ma_pcm_interleave_s24__reference(dsti, (const void**)ppSrc, frameCount, channelCountForThisIteration); if (compare_interleaved_and_deinterleaved_buffers(dsti, (const void**)ppSrc, frameCount, channelCountForThisIteration, format) != 0) { printf("FAILED. Deinterleaved to Interleaved (Channels = %u)\n", channelCountForThisIteration); result = -1; @@ -977,7 +977,7 @@ int do_interleaving_test(mal_format format) } // Deinterleave. - mal_pcm_deinterleave_s24__reference((void**)ppDst, dsti, frameCount, channelCountForThisIteration); + ma_pcm_deinterleave_s24__reference((void**)ppDst, dsti, frameCount, channelCountForThisIteration); if (compare_interleaved_and_deinterleaved_buffers(dsti, (const void**)ppDst, frameCount, channelCountForThisIteration, format) != 0) { printf("FAILED. Interleaved to Deinterleaved (Channels = %u)\n", channelCountForThisIteration); result = -1; @@ -986,19 +986,19 @@ int do_interleaving_test(mal_format format) } } break; - case mal_format_s32: + case ma_format_s32: { - mal_int32 src [MA_MAX_CHANNELS][64]; - mal_int32 dst [MA_MAX_CHANNELS][64]; - mal_int32 dsti[MA_MAX_CHANNELS*64]; + ma_int32 src [MA_MAX_CHANNELS][64]; + ma_int32 dst [MA_MAX_CHANNELS][64]; + ma_int32 dsti[MA_MAX_CHANNELS*64]; void* ppSrc[MA_MAX_CHANNELS]; void* ppDst[MA_MAX_CHANNELS]; - mal_uint32 frameCount = mal_countof(src[0]); - mal_uint32 channelCount = mal_countof(src); - for (mal_uint32 iChannel = 0; iChannel < channelCount; iChannel += 1) { - for (mal_uint32 iFrame = 0; iFrame < frameCount; iFrame += 1) { - src[iChannel][iFrame] = (mal_int32)iChannel; + ma_uint32 frameCount = ma_countof(src[0]); + ma_uint32 channelCount = ma_countof(src); + for (ma_uint32 iChannel = 0; iChannel < channelCount; iChannel += 1) { + for (ma_uint32 iFrame = 0; iFrame < frameCount; iFrame += 1) { + src[iChannel][iFrame] = (ma_int32)iChannel; } ppSrc[iChannel] = &src[iChannel]; @@ -1006,11 +1006,11 @@ int do_interleaving_test(mal_format format) } // Now test every channel count. - for (mal_uint32 i = 0; i < channelCount; ++i) { - mal_uint32 channelCountForThisIteration = i + 1; + for (ma_uint32 i = 0; i < channelCount; ++i) { + ma_uint32 channelCountForThisIteration = i + 1; // Interleave. - mal_pcm_interleave_s32__reference(dsti, (const void**)ppSrc, frameCount, channelCountForThisIteration); + ma_pcm_interleave_s32__reference(dsti, (const void**)ppSrc, frameCount, channelCountForThisIteration); if (compare_interleaved_and_deinterleaved_buffers(dsti, (const void**)ppSrc, frameCount, channelCountForThisIteration, format) != 0) { printf("FAILED. Deinterleaved to Interleaved (Channels = %u)\n", i); result = -1; @@ -1018,7 +1018,7 @@ int do_interleaving_test(mal_format format) } // Deinterleave. - mal_pcm_deinterleave_s32__reference((void**)ppDst, dsti, frameCount, channelCountForThisIteration); + ma_pcm_deinterleave_s32__reference((void**)ppDst, dsti, frameCount, channelCountForThisIteration); if (compare_interleaved_and_deinterleaved_buffers(dsti, (const void**)ppDst, frameCount, channelCountForThisIteration, format) != 0) { printf("FAILED. Interleaved to Deinterleaved (Channels = %u)\n", i); result = -1; @@ -1027,7 +1027,7 @@ int do_interleaving_test(mal_format format) } } break; - case mal_format_f32: + case ma_format_f32: { float src [MA_MAX_CHANNELS][64]; float dst [MA_MAX_CHANNELS][64]; @@ -1035,10 +1035,10 @@ int do_interleaving_test(mal_format format) void* ppSrc[MA_MAX_CHANNELS]; void* ppDst[MA_MAX_CHANNELS]; - mal_uint32 frameCount = mal_countof(src[0]); - mal_uint32 channelCount = mal_countof(src); - for (mal_uint32 iChannel = 0; iChannel < channelCount; iChannel += 1) { - for (mal_uint32 iFrame = 0; iFrame < frameCount; iFrame += 1) { + ma_uint32 frameCount = ma_countof(src[0]); + ma_uint32 channelCount = ma_countof(src); + for (ma_uint32 iChannel = 0; iChannel < channelCount; iChannel += 1) { + for (ma_uint32 iFrame = 0; iFrame < frameCount; iFrame += 1) { src[iChannel][iFrame] = (float)iChannel; } @@ -1047,11 +1047,11 @@ int do_interleaving_test(mal_format format) } // Now test every channel count. - for (mal_uint32 i = 0; i < channelCount; ++i) { - mal_uint32 channelCountForThisIteration = i + 1; + for (ma_uint32 i = 0; i < channelCount; ++i) { + ma_uint32 channelCountForThisIteration = i + 1; // Interleave. - mal_pcm_interleave_f32__reference(dsti, (const void**)ppSrc, frameCount, channelCountForThisIteration); + ma_pcm_interleave_f32__reference(dsti, (const void**)ppSrc, frameCount, channelCountForThisIteration); if (compare_interleaved_and_deinterleaved_buffers(dsti, (const void**)ppSrc, frameCount, channelCountForThisIteration, format) != 0) { printf("FAILED. Deinterleaved to Interleaved (Channels = %u)\n", i); result = -1; @@ -1059,7 +1059,7 @@ int do_interleaving_test(mal_format format) } // Deinterleave. - mal_pcm_deinterleave_f32__reference((void**)ppDst, dsti, frameCount, channelCountForThisIteration); + ma_pcm_deinterleave_f32__reference((void**)ppDst, dsti, frameCount, channelCountForThisIteration); if (compare_interleaved_and_deinterleaved_buffers(dsti, (const void**)ppDst, frameCount, channelCountForThisIteration, format) != 0) { printf("FAILED. Interleaved to Deinterleaved (Channels = %u)\n", i); result = -1; @@ -1088,27 +1088,27 @@ int do_interleaving_tests() int result = 0; printf("u8... "); - if (do_interleaving_test(mal_format_u8) != 0) { + if (do_interleaving_test(ma_format_u8) != 0) { result = -1; } printf("s16... "); - if (do_interleaving_test(mal_format_s16) != 0) { + if (do_interleaving_test(ma_format_s16) != 0) { result = -1; } printf("s24... "); - if (do_interleaving_test(mal_format_s24) != 0) { + if (do_interleaving_test(ma_format_s24) != 0) { result = -1; } printf("s32... "); - if (do_interleaving_test(mal_format_s32) != 0) { + if (do_interleaving_test(ma_format_s32) != 0) { result = -1; } printf("f32... "); - if (do_interleaving_test(mal_format_f32) != 0) { + if (do_interleaving_test(ma_format_f32) != 0) { result = -1; } @@ -1116,18 +1116,18 @@ int do_interleaving_tests() } -mal_uint32 converter_test_interleaved_callback(mal_format_converter* pConverter, mal_uint32 frameCount, void* pFramesOut, void* pUserData) +ma_uint32 converter_test_interleaved_callback(ma_format_converter* pConverter, ma_uint32 frameCount, void* pFramesOut, void* pUserData) { - mal_sine_wave* pSineWave = (mal_sine_wave*)pUserData; - mal_assert(pSineWave != NULL); + ma_sine_wave* pSineWave = (ma_sine_wave*)pUserData; + ma_assert(pSineWave != NULL); float* pFramesOutF32 = (float*)pFramesOut; - for (mal_uint32 iFrame = 0; iFrame < frameCount; iFrame += 1) { + for (ma_uint32 iFrame = 0; iFrame < frameCount; iFrame += 1) { float sample; - mal_sine_wave_read_f32(pSineWave, 1, &sample); + ma_sine_wave_read_f32(pSineWave, 1, &sample); - for (mal_uint32 iChannel = 0; iChannel < pConverter->config.channels; iChannel += 1) { + for (ma_uint32 iChannel = 0; iChannel < pConverter->config.channels; iChannel += 1) { pFramesOutF32[iFrame*pConverter->config.channels + iChannel] = sample; } } @@ -1135,16 +1135,16 @@ mal_uint32 converter_test_interleaved_callback(mal_format_converter* pConverter, return frameCount; } -mal_uint32 converter_test_deinterleaved_callback(mal_format_converter* pConverter, mal_uint32 frameCount, void** ppSamplesOut, void* pUserData) +ma_uint32 converter_test_deinterleaved_callback(ma_format_converter* pConverter, ma_uint32 frameCount, void** ppSamplesOut, void* pUserData) { - mal_sine_wave* pSineWave = (mal_sine_wave*)pUserData; - mal_assert(pSineWave != NULL); + ma_sine_wave* pSineWave = (ma_sine_wave*)pUserData; + ma_assert(pSineWave != NULL); - mal_sine_wave_read_f32(pSineWave, frameCount, (float*)ppSamplesOut[0]); + ma_sine_wave_read_f32(pSineWave, frameCount, (float*)ppSamplesOut[0]); // Copy everything from the first channel over the others. - for (mal_uint32 iChannel = 1; iChannel < pConverter->config.channels; iChannel += 1) { - mal_copy_memory(ppSamplesOut[iChannel], ppSamplesOut[0], frameCount * sizeof(float)); + for (ma_uint32 iChannel = 1; iChannel < pConverter->config.channels; iChannel += 1) { + ma_copy_memory(ppSamplesOut[iChannel], ppSamplesOut[0], frameCount * sizeof(float)); } return frameCount; @@ -1154,21 +1154,21 @@ int do_format_converter_tests() { double amplitude = 1; double periodsPerSecond = 400; - mal_uint32 sampleRate = 48000; + ma_uint32 sampleRate = 48000; - mal_result result = MA_SUCCESS; + ma_result result = MA_SUCCESS; - mal_sine_wave sineWave; - mal_format_converter converter; + ma_sine_wave sineWave; + ma_format_converter converter; - mal_format_converter_config config; - mal_zero_object(&config); - config.formatIn = mal_format_f32; - config.formatOut = mal_format_s16; + ma_format_converter_config config; + ma_zero_object(&config); + config.formatIn = ma_format_f32; + config.formatOut = ma_format_s16; config.channels = 2; - config.streamFormatIn = mal_stream_format_pcm; - config.streamFormatOut = mal_stream_format_pcm; - config.ditherMode = mal_dither_mode_none; + config.streamFormatIn = ma_stream_format_pcm; + config.streamFormatOut = ma_stream_format_pcm; + config.ditherMode = ma_dither_mode_none; config.pUserData = &sineWave; @@ -1177,63 +1177,63 @@ int do_format_converter_tests() // Interleaved/Interleaved f32 to s16. { - mal_sine_wave_init(amplitude, periodsPerSecond, sampleRate, &sineWave); - result = mal_format_converter_init(&config, &converter); + ma_sine_wave_init(amplitude, periodsPerSecond, sampleRate, &sineWave); + result = ma_format_converter_init(&config, &converter); if (result != MA_SUCCESS) { printf("Failed to initialize converter.\n"); return -1; } - mal_int16 interleavedFrames[MA_MAX_CHANNELS * 1024]; - mal_uint64 framesRead = mal_format_converter_read(&converter, 1024, interleavedFrames, converter.config.pUserData); + ma_int16 interleavedFrames[MA_MAX_CHANNELS * 1024]; + ma_uint64 framesRead = ma_format_converter_read(&converter, 1024, interleavedFrames, converter.config.pUserData); if (framesRead != 1024) { printf("Failed to read interleaved data from converter.\n"); return -1; } - FILE* pFile = mal_fopen("res/output/converter_f32_to_s16_interleaved_interleaved__stereo_48000.raw", "wb"); + FILE* pFile = ma_fopen("res/output/converter_f32_to_s16_interleaved_interleaved__stereo_48000.raw", "wb"); if (pFile == NULL) { printf("Failed to open output file.\n"); return -1; } - fwrite(interleavedFrames, sizeof(mal_int16), (size_t)framesRead * converter.config.channels, pFile); + fwrite(interleavedFrames, sizeof(ma_int16), (size_t)framesRead * converter.config.channels, pFile); fclose(pFile); } // Interleaved/Deinterleaved f32 to s16. { - mal_sine_wave_init(amplitude, periodsPerSecond, sampleRate, &sineWave); - result = mal_format_converter_init(&config, &converter); + ma_sine_wave_init(amplitude, periodsPerSecond, sampleRate, &sineWave); + result = ma_format_converter_init(&config, &converter); if (result != MA_SUCCESS) { printf("Failed to initialize converter.\n"); return -1; } - mal_int16 deinterleavedFrames[MA_MAX_CHANNELS][1024]; + ma_int16 deinterleavedFrames[MA_MAX_CHANNELS][1024]; void* ppDeinterleavedFrames[MA_MAX_CHANNELS]; - for (mal_uint32 iChannel = 0; iChannel < converter.config.channels; iChannel += 1) { + for (ma_uint32 iChannel = 0; iChannel < converter.config.channels; iChannel += 1) { ppDeinterleavedFrames[iChannel] = &deinterleavedFrames[iChannel]; } - mal_uint64 framesRead = mal_format_converter_read_deinterleaved(&converter, 1024, ppDeinterleavedFrames, converter.config.pUserData); + ma_uint64 framesRead = ma_format_converter_read_deinterleaved(&converter, 1024, ppDeinterleavedFrames, converter.config.pUserData); if (framesRead != 1024) { printf("Failed to read interleaved data from converter.\n"); return -1; } // Write a separate file for each channel. - for (mal_uint32 iChannel = 0; iChannel < converter.config.channels; iChannel += 1) { + for (ma_uint32 iChannel = 0; iChannel < converter.config.channels; iChannel += 1) { char filePath[256]; snprintf(filePath, sizeof(filePath), "res/output/converter_f32_to_s16_interleaved_deinterleaved__stereo_48000.raw.%d", iChannel); - FILE* pFile = mal_fopen(filePath, "wb"); + FILE* pFile = ma_fopen(filePath, "wb"); if (pFile == NULL) { printf("Failed to open output file.\n"); return -1; } - fwrite(ppDeinterleavedFrames[iChannel], sizeof(mal_int16), (size_t)framesRead, pFile); + fwrite(ppDeinterleavedFrames[iChannel], sizeof(ma_int16), (size_t)framesRead, pFile); fclose(pFile); } } @@ -1244,63 +1244,63 @@ int do_format_converter_tests() // Deinterleaved/Interleaved f32 to s16. { - mal_sine_wave_init(amplitude, periodsPerSecond, sampleRate, &sineWave); - result = mal_format_converter_init(&config, &converter); + ma_sine_wave_init(amplitude, periodsPerSecond, sampleRate, &sineWave); + result = ma_format_converter_init(&config, &converter); if (result != MA_SUCCESS) { printf("Failed to initialize converter.\n"); return -1; } - mal_int16 interleavedFrames[MA_MAX_CHANNELS * 1024]; - mal_uint64 framesRead = mal_format_converter_read(&converter, 1024, interleavedFrames, converter.config.pUserData); + ma_int16 interleavedFrames[MA_MAX_CHANNELS * 1024]; + ma_uint64 framesRead = ma_format_converter_read(&converter, 1024, interleavedFrames, converter.config.pUserData); if (framesRead != 1024) { printf("Failed to read interleaved data from converter.\n"); return -1; } - FILE* pFile = mal_fopen("res/output/converter_f32_to_s16_deinterleaved_interleaved__stereo_48000.raw", "wb"); + FILE* pFile = ma_fopen("res/output/converter_f32_to_s16_deinterleaved_interleaved__stereo_48000.raw", "wb"); if (pFile == NULL) { printf("Failed to open output file.\n"); return -1; } - fwrite(interleavedFrames, sizeof(mal_int16), (size_t)framesRead * converter.config.channels, pFile); + fwrite(interleavedFrames, sizeof(ma_int16), (size_t)framesRead * converter.config.channels, pFile); fclose(pFile); } // Deinterleaved/Deinterleaved f32 to s16. { - mal_sine_wave_init(amplitude, periodsPerSecond, sampleRate, &sineWave); - result = mal_format_converter_init(&config, &converter); + ma_sine_wave_init(amplitude, periodsPerSecond, sampleRate, &sineWave); + result = ma_format_converter_init(&config, &converter); if (result != MA_SUCCESS) { printf("Failed to initialize converter.\n"); return -1; } - mal_int16 deinterleavedFrames[MA_MAX_CHANNELS][1024]; + ma_int16 deinterleavedFrames[MA_MAX_CHANNELS][1024]; void* ppDeinterleavedFrames[MA_MAX_CHANNELS]; - for (mal_uint32 iChannel = 0; iChannel < converter.config.channels; iChannel += 1) { + for (ma_uint32 iChannel = 0; iChannel < converter.config.channels; iChannel += 1) { ppDeinterleavedFrames[iChannel] = &deinterleavedFrames[iChannel]; } - mal_uint64 framesRead = mal_format_converter_read_deinterleaved(&converter, 1024, ppDeinterleavedFrames, converter.config.pUserData); + ma_uint64 framesRead = ma_format_converter_read_deinterleaved(&converter, 1024, ppDeinterleavedFrames, converter.config.pUserData); if (framesRead != 1024) { printf("Failed to read interleaved data from converter.\n"); return -1; } // Write a separate file for each channel. - for (mal_uint32 iChannel = 0; iChannel < converter.config.channels; iChannel += 1) { + for (ma_uint32 iChannel = 0; iChannel < converter.config.channels; iChannel += 1) { char filePath[256]; snprintf(filePath, sizeof(filePath), "res/output/converter_f32_to_s16_deinterleaved_deinterleaved__stereo_48000.raw.%d", iChannel); - FILE* pFile = mal_fopen(filePath, "wb"); + FILE* pFile = ma_fopen(filePath, "wb"); if (pFile == NULL) { printf("Failed to open output file.\n"); return -1; } - fwrite(ppDeinterleavedFrames[iChannel], sizeof(mal_int16), (size_t)framesRead, pFile); + fwrite(ppDeinterleavedFrames[iChannel], sizeof(ma_int16), (size_t)framesRead, pFile); fclose(pFile); } } @@ -1308,25 +1308,25 @@ int do_format_converter_tests() config.onRead = converter_test_interleaved_callback; config.onReadDeinterleaved = NULL; - config.formatOut = mal_format_f32; + config.formatOut = ma_format_f32; // Interleaved/Interleaved f32 to f32. { - mal_sine_wave_init(amplitude, periodsPerSecond, sampleRate, &sineWave); - result = mal_format_converter_init(&config, &converter); + ma_sine_wave_init(amplitude, periodsPerSecond, sampleRate, &sineWave); + result = ma_format_converter_init(&config, &converter); if (result != MA_SUCCESS) { printf("Failed to initialize converter.\n"); return -1; } float interleavedFrames[MA_MAX_CHANNELS * 1024]; - mal_uint64 framesRead = mal_format_converter_read(&converter, 1024, interleavedFrames, converter.config.pUserData); + ma_uint64 framesRead = ma_format_converter_read(&converter, 1024, interleavedFrames, converter.config.pUserData); if (framesRead != 1024) { printf("Failed to read interleaved data from converter.\n"); return -1; } - FILE* pFile = mal_fopen("res/output/converter_f32_to_f32_interleaved_interleaved__stereo_48000.raw", "wb"); + FILE* pFile = ma_fopen("res/output/converter_f32_to_f32_interleaved_interleaved__stereo_48000.raw", "wb"); if (pFile == NULL) { printf("Failed to open output file.\n"); return -1; @@ -1338,8 +1338,8 @@ int do_format_converter_tests() // Interleaved/Deinterleaved f32 to f32. { - mal_sine_wave_init(amplitude, periodsPerSecond, sampleRate, &sineWave); - result = mal_format_converter_init(&config, &converter); + ma_sine_wave_init(amplitude, periodsPerSecond, sampleRate, &sineWave); + result = ma_format_converter_init(&config, &converter); if (result != MA_SUCCESS) { printf("Failed to initialize converter.\n"); return -1; @@ -1347,22 +1347,22 @@ int do_format_converter_tests() float deinterleavedFrames[MA_MAX_CHANNELS][1024]; void* ppDeinterleavedFrames[MA_MAX_CHANNELS]; - for (mal_uint32 iChannel = 0; iChannel < converter.config.channels; iChannel += 1) { + for (ma_uint32 iChannel = 0; iChannel < converter.config.channels; iChannel += 1) { ppDeinterleavedFrames[iChannel] = &deinterleavedFrames[iChannel]; } - mal_uint64 framesRead = mal_format_converter_read_deinterleaved(&converter, 1024, ppDeinterleavedFrames, converter.config.pUserData); + ma_uint64 framesRead = ma_format_converter_read_deinterleaved(&converter, 1024, ppDeinterleavedFrames, converter.config.pUserData); if (framesRead != 1024) { printf("Failed to read interleaved data from converter.\n"); return -1; } // Write a separate file for each channel. - for (mal_uint32 iChannel = 0; iChannel < converter.config.channels; iChannel += 1) { + for (ma_uint32 iChannel = 0; iChannel < converter.config.channels; iChannel += 1) { char filePath[256]; snprintf(filePath, sizeof(filePath), "res/output/converter_f32_to_f32_interleaved_deinterleaved__stereo_48000.raw.%d", iChannel); - FILE* pFile = mal_fopen(filePath, "wb"); + FILE* pFile = ma_fopen(filePath, "wb"); if (pFile == NULL) { printf("Failed to open output file.\n"); return -1; @@ -1379,21 +1379,21 @@ int do_format_converter_tests() // Deinterleaved/Interleaved f32 to f32. { - mal_sine_wave_init(amplitude, periodsPerSecond, sampleRate, &sineWave); - result = mal_format_converter_init(&config, &converter); + ma_sine_wave_init(amplitude, periodsPerSecond, sampleRate, &sineWave); + result = ma_format_converter_init(&config, &converter); if (result != MA_SUCCESS) { printf("Failed to initialize converter.\n"); return -1; } float interleavedFrames[MA_MAX_CHANNELS * 1024]; - mal_uint64 framesRead = mal_format_converter_read(&converter, 1024, interleavedFrames, converter.config.pUserData); + ma_uint64 framesRead = ma_format_converter_read(&converter, 1024, interleavedFrames, converter.config.pUserData); if (framesRead != 1024) { printf("Failed to read interleaved data from converter.\n"); return -1; } - FILE* pFile = mal_fopen("res/output/converter_f32_to_f32_deinterleaved_interleaved__stereo_48000.raw", "wb"); + FILE* pFile = ma_fopen("res/output/converter_f32_to_f32_deinterleaved_interleaved__stereo_48000.raw", "wb"); if (pFile == NULL) { printf("Failed to open output file.\n"); return -1; @@ -1405,8 +1405,8 @@ int do_format_converter_tests() // Deinterleaved/Deinterleaved f32 to f32. { - mal_sine_wave_init(amplitude, periodsPerSecond, sampleRate, &sineWave); - result = mal_format_converter_init(&config, &converter); + ma_sine_wave_init(amplitude, periodsPerSecond, sampleRate, &sineWave); + result = ma_format_converter_init(&config, &converter); if (result != MA_SUCCESS) { printf("Failed to initialize converter.\n"); return -1; @@ -1414,22 +1414,22 @@ int do_format_converter_tests() float deinterleavedFrames[MA_MAX_CHANNELS][1024]; void* ppDeinterleavedFrames[MA_MAX_CHANNELS]; - for (mal_uint32 iChannel = 0; iChannel < converter.config.channels; iChannel += 1) { + for (ma_uint32 iChannel = 0; iChannel < converter.config.channels; iChannel += 1) { ppDeinterleavedFrames[iChannel] = &deinterleavedFrames[iChannel]; } - mal_uint64 framesRead = mal_format_converter_read_deinterleaved(&converter, 1024, ppDeinterleavedFrames, converter.config.pUserData); + ma_uint64 framesRead = ma_format_converter_read_deinterleaved(&converter, 1024, ppDeinterleavedFrames, converter.config.pUserData); if (framesRead != 1024) { printf("Failed to read interleaved data from converter.\n"); return -1; } // Write a separate file for each channel. - for (mal_uint32 iChannel = 0; iChannel < converter.config.channels; iChannel += 1) { + for (ma_uint32 iChannel = 0; iChannel < converter.config.channels; iChannel += 1) { char filePath[256]; snprintf(filePath, sizeof(filePath), "res/output/converter_f32_to_f32_deinterleaved_deinterleaved__stereo_48000.raw.%d", iChannel); - FILE* pFile = mal_fopen(filePath, "wb"); + FILE* pFile = ma_fopen(filePath, "wb"); if (pFile == NULL) { printf("Failed to open output file.\n"); return -1; @@ -1447,12 +1447,12 @@ int do_format_converter_tests() -mal_uint32 channel_router_callback__passthrough_test(mal_channel_router* pRouter, mal_uint32 frameCount, void** ppSamplesOut, void* pUserData) +ma_uint32 channel_router_callback__passthrough_test(ma_channel_router* pRouter, ma_uint32 frameCount, void** ppSamplesOut, void* pUserData) { float** ppSamplesIn = (float**)pUserData; - for (mal_uint32 iChannel = 0; iChannel < pRouter->config.channelsIn; ++iChannel) { - mal_copy_memory(ppSamplesOut[iChannel], ppSamplesIn[iChannel], frameCount*sizeof(float)); + for (ma_uint32 iChannel = 0; iChannel < pRouter->config.channelsIn; ++iChannel) { + ma_copy_memory(ppSamplesOut[iChannel], ppSamplesIn[iChannel], frameCount*sizeof(float)); } return frameCount; @@ -1460,26 +1460,26 @@ mal_uint32 channel_router_callback__passthrough_test(mal_channel_router* pRouter int do_channel_routing_tests() { - mal_bool32 hasError = MA_FALSE; + ma_bool32 hasError = MA_FALSE; printf("Passthrough... "); { - mal_channel_router_config routerConfig; - mal_zero_object(&routerConfig); + ma_channel_router_config routerConfig; + ma_zero_object(&routerConfig); routerConfig.onReadDeinterleaved = channel_router_callback__passthrough_test; routerConfig.pUserData = NULL; - routerConfig.mixingMode = mal_channel_mix_mode_planar_blend; + routerConfig.mixingMode = ma_channel_mix_mode_planar_blend; routerConfig.channelsIn = 6; routerConfig.channelsOut = routerConfig.channelsIn; routerConfig.noSSE2 = MA_TRUE; routerConfig.noAVX2 = MA_TRUE; routerConfig.noAVX512 = MA_TRUE; routerConfig.noNEON = MA_TRUE; - mal_get_standard_channel_map(mal_standard_channel_map_microsoft, routerConfig.channelsIn, routerConfig.channelMapIn); - mal_get_standard_channel_map(mal_standard_channel_map_microsoft, routerConfig.channelsOut, routerConfig.channelMapOut); + ma_get_standard_channel_map(ma_standard_channel_map_microsoft, routerConfig.channelsIn, routerConfig.channelMapIn); + ma_get_standard_channel_map(ma_standard_channel_map_microsoft, routerConfig.channelsOut, routerConfig.channelMapOut); - mal_channel_router router; - mal_result result = mal_channel_router_init(&routerConfig, &router); + ma_channel_router router; + ma_result result = ma_channel_router_init(&routerConfig, &router); if (result == MA_SUCCESS) { if (!router.isPassthrough) { printf("Failed to init router as passthrough.\n"); @@ -1487,8 +1487,8 @@ int do_channel_routing_tests() } // Expecting the weights to all be equal to 1 for each channel. - for (mal_uint32 iChannelIn = 0; iChannelIn < routerConfig.channelsIn; ++iChannelIn) { - for (mal_uint32 iChannelOut = 0; iChannelOut < routerConfig.channelsOut; ++iChannelOut) { + for (ma_uint32 iChannelIn = 0; iChannelIn < routerConfig.channelsIn; ++iChannelIn) { + for (ma_uint32 iChannelOut = 0; iChannelOut < routerConfig.channelsOut; ++iChannelOut) { float expectedWeight = 0; if (iChannelIn == iChannelOut) { expectedWeight = 1; @@ -1511,28 +1511,28 @@ int do_channel_routing_tests() // us to check results. Each channel is given a value equal to it's index, plus 1. float testData[MA_MAX_CHANNELS][MA_SIMD_ALIGNMENT * 2]; float* ppTestData[MA_MAX_CHANNELS]; - for (mal_uint32 iChannel = 0; iChannel < routerConfig.channelsIn; ++iChannel) { + for (ma_uint32 iChannel = 0; iChannel < routerConfig.channelsIn; ++iChannel) { ppTestData[iChannel] = testData[iChannel]; - for (mal_uint32 iFrame = 0; iFrame < mal_countof(testData[0]); ++iFrame) { + for (ma_uint32 iFrame = 0; iFrame < ma_countof(testData[0]); ++iFrame) { ppTestData[iChannel][iFrame] = (float)(iChannel + 1); } } routerConfig.pUserData = ppTestData; - mal_channel_router_init(&routerConfig, &router); + ma_channel_router_init(&routerConfig, &router); MA_ALIGN(MA_SIMD_ALIGNMENT) float outputA[MA_MAX_CHANNELS][MA_SIMD_ALIGNMENT * 2]; MA_ALIGN(MA_SIMD_ALIGNMENT) float outputB[MA_MAX_CHANNELS][MA_SIMD_ALIGNMENT * 2]; float* ppOutputA[MA_MAX_CHANNELS]; float* ppOutputB[MA_MAX_CHANNELS]; - for (mal_uint32 iChannel = 0; iChannel < routerConfig.channelsOut; ++iChannel) { + for (ma_uint32 iChannel = 0; iChannel < routerConfig.channelsOut; ++iChannel) { ppOutputA[iChannel] = outputA[iChannel]; ppOutputB[iChannel] = outputB[iChannel]; } // With optimizations. - mal_uint64 framesRead = mal_channel_router_read_deinterleaved(&router, mal_countof(outputA[0]), (void**)ppOutputA, router.config.pUserData); - if (framesRead != mal_countof(outputA[0])) { + ma_uint64 framesRead = ma_channel_router_read_deinterleaved(&router, ma_countof(outputA[0]), (void**)ppOutputA, router.config.pUserData); + if (framesRead != ma_countof(outputA[0])) { printf("Returned frame count for optimized incorrect."); hasError = MA_TRUE; } @@ -1540,15 +1540,15 @@ int do_channel_routing_tests() // Without optimizations. router.isPassthrough = MA_FALSE; router.isSimpleShuffle = MA_FALSE; - framesRead = mal_channel_router_read_deinterleaved(&router, mal_countof(outputA[0]), (void**)ppOutputB, router.config.pUserData); - if (framesRead != mal_countof(outputA[0])) { + framesRead = ma_channel_router_read_deinterleaved(&router, ma_countof(outputA[0]), (void**)ppOutputB, router.config.pUserData); + if (framesRead != ma_countof(outputA[0])) { printf("Returned frame count for unoptimized path incorrect."); hasError = MA_TRUE; } // Compare. - for (mal_uint32 iChannel = 0; iChannel < routerConfig.channelsOut; ++iChannel) { - for (mal_uint32 iFrame = 0; iFrame < mal_countof(outputA[0]); ++iFrame) { + for (ma_uint32 iChannel = 0; iChannel < routerConfig.channelsOut; ++iChannel) { + for (ma_uint32 iFrame = 0; iFrame < ma_countof(outputA[0]); ++iFrame) { if (ppOutputA[iChannel][iFrame] != ppOutputB[iChannel][iFrame]) { printf("Sample incorrect [%d][%d]\n", iChannel, iFrame); hasError = MA_TRUE; @@ -1567,24 +1567,24 @@ int do_channel_routing_tests() // The shuffle is tested by simply reversing the order of the channels. Doing a reversal just makes it easier to // check that everything is working. - mal_channel_router_config routerConfig; - mal_zero_object(&routerConfig); + ma_channel_router_config routerConfig; + ma_zero_object(&routerConfig); routerConfig.onReadDeinterleaved = channel_router_callback__passthrough_test; routerConfig.pUserData = NULL; - routerConfig.mixingMode = mal_channel_mix_mode_planar_blend; + routerConfig.mixingMode = ma_channel_mix_mode_planar_blend; routerConfig.channelsIn = 6; routerConfig.channelsOut = routerConfig.channelsIn; routerConfig.noSSE2 = MA_TRUE; routerConfig.noAVX2 = MA_TRUE; routerConfig.noAVX512 = MA_TRUE; routerConfig.noNEON = MA_TRUE; - mal_get_standard_channel_map(mal_standard_channel_map_microsoft, routerConfig.channelsIn, routerConfig.channelMapIn); - for (mal_uint32 iChannel = 0; iChannel < routerConfig.channelsIn; ++iChannel) { + ma_get_standard_channel_map(ma_standard_channel_map_microsoft, routerConfig.channelsIn, routerConfig.channelMapIn); + for (ma_uint32 iChannel = 0; iChannel < routerConfig.channelsIn; ++iChannel) { routerConfig.channelMapOut[iChannel] = routerConfig.channelMapIn[routerConfig.channelsIn - iChannel - 1]; } - mal_channel_router router; - mal_result result = mal_channel_router_init(&routerConfig, &router); + ma_channel_router router; + ma_result result = ma_channel_router_init(&routerConfig, &router); if (result == MA_SUCCESS) { if (router.isPassthrough) { printf("Router incorrectly configured as a passthrough.\n"); @@ -1596,8 +1596,8 @@ int do_channel_routing_tests() } // Expecting the weights to all be equal to 1 for each channel. - for (mal_uint32 iChannelIn = 0; iChannelIn < routerConfig.channelsIn; ++iChannelIn) { - for (mal_uint32 iChannelOut = 0; iChannelOut < routerConfig.channelsOut; ++iChannelOut) { + for (ma_uint32 iChannelIn = 0; iChannelIn < routerConfig.channelsIn; ++iChannelIn) { + for (ma_uint32 iChannelOut = 0; iChannelOut < routerConfig.channelsOut; ++iChannelOut) { float expectedWeight = 0; if (iChannelIn == (routerConfig.channelsOut - iChannelOut - 1)) { expectedWeight = 1; @@ -1620,27 +1620,27 @@ int do_channel_routing_tests() // for us to check results. Each channel is given a value equal to it's index, plus 1. float testData[MA_MAX_CHANNELS][100]; float* ppTestData[MA_MAX_CHANNELS]; - for (mal_uint32 iChannel = 0; iChannel < routerConfig.channelsIn; ++iChannel) { + for (ma_uint32 iChannel = 0; iChannel < routerConfig.channelsIn; ++iChannel) { ppTestData[iChannel] = testData[iChannel]; - for (mal_uint32 iFrame = 0; iFrame < 100; ++iFrame) { + for (ma_uint32 iFrame = 0; iFrame < 100; ++iFrame) { ppTestData[iChannel][iFrame] = (float)(iChannel + 1); } } routerConfig.pUserData = ppTestData; - mal_channel_router_init(&routerConfig, &router); + ma_channel_router_init(&routerConfig, &router); float outputA[MA_MAX_CHANNELS][100]; float outputB[MA_MAX_CHANNELS][100]; float* ppOutputA[MA_MAX_CHANNELS]; float* ppOutputB[MA_MAX_CHANNELS]; - for (mal_uint32 iChannel = 0; iChannel < routerConfig.channelsOut; ++iChannel) { + for (ma_uint32 iChannel = 0; iChannel < routerConfig.channelsOut; ++iChannel) { ppOutputA[iChannel] = outputA[iChannel]; ppOutputB[iChannel] = outputB[iChannel]; } // With optimizations. - mal_uint64 framesRead = mal_channel_router_read_deinterleaved(&router, 100, (void**)ppOutputA, router.config.pUserData); + ma_uint64 framesRead = ma_channel_router_read_deinterleaved(&router, 100, (void**)ppOutputA, router.config.pUserData); if (framesRead != 100) { printf("Returned frame count for optimized incorrect."); hasError = MA_TRUE; @@ -1649,15 +1649,15 @@ int do_channel_routing_tests() // Without optimizations. router.isPassthrough = MA_FALSE; router.isSimpleShuffle = MA_FALSE; - framesRead = mal_channel_router_read_deinterleaved(&router, 100, (void**)ppOutputB, router.config.pUserData); + framesRead = ma_channel_router_read_deinterleaved(&router, 100, (void**)ppOutputB, router.config.pUserData); if (framesRead != 100) { printf("Returned frame count for unoptimized path incorrect."); hasError = MA_TRUE; } // Compare. - for (mal_uint32 iChannel = 0; iChannel < routerConfig.channelsOut; ++iChannel) { - for (mal_uint32 iFrame = 0; iFrame < 100; ++iFrame) { + for (ma_uint32 iChannel = 0; iChannel < routerConfig.channelsOut; ++iChannel) { + for (ma_uint32 iFrame = 0; iFrame < 100; ++iFrame) { if (ppOutputA[iChannel][iFrame] != ppOutputB[iChannel][iFrame]) { printf("Sample incorrect [%d][%d]\n", iChannel, iFrame); hasError = MA_TRUE; @@ -1676,22 +1676,22 @@ int do_channel_routing_tests() // This tests takes a Stereo to 5.1 conversion using the simple mixing mode. We should expect 0 and 1 (front/left, front/right) to have // weights of 1, and the others to have a weight of 0. - mal_channel_router_config routerConfig; - mal_zero_object(&routerConfig); + ma_channel_router_config routerConfig; + ma_zero_object(&routerConfig); routerConfig.onReadDeinterleaved = channel_router_callback__passthrough_test; routerConfig.pUserData = NULL; - routerConfig.mixingMode = mal_channel_mix_mode_simple; + routerConfig.mixingMode = ma_channel_mix_mode_simple; routerConfig.channelsIn = 2; routerConfig.channelsOut = 6; routerConfig.noSSE2 = MA_TRUE; routerConfig.noAVX2 = MA_TRUE; routerConfig.noAVX512 = MA_TRUE; routerConfig.noNEON = MA_TRUE; - mal_get_standard_channel_map(mal_standard_channel_map_microsoft, routerConfig.channelsIn, routerConfig.channelMapIn); - mal_get_standard_channel_map(mal_standard_channel_map_microsoft, routerConfig.channelsOut, routerConfig.channelMapOut); + ma_get_standard_channel_map(ma_standard_channel_map_microsoft, routerConfig.channelsIn, routerConfig.channelMapIn); + ma_get_standard_channel_map(ma_standard_channel_map_microsoft, routerConfig.channelsOut, routerConfig.channelMapOut); - mal_channel_router router; - mal_result result = mal_channel_router_init(&routerConfig, &router); + ma_channel_router router; + ma_result result = ma_channel_router_init(&routerConfig, &router); if (result == MA_SUCCESS) { if (router.isPassthrough) { printf("Router incorrectly configured as a passthrough.\n"); @@ -1703,8 +1703,8 @@ int do_channel_routing_tests() } // Expecting the weights to all be equal to 1 for each channel. - for (mal_uint32 iChannelIn = 0; iChannelIn < routerConfig.channelsIn; ++iChannelIn) { - for (mal_uint32 iChannelOut = 0; iChannelOut < routerConfig.channelsOut; ++iChannelOut) { + for (ma_uint32 iChannelIn = 0; iChannelIn < routerConfig.channelsIn; ++iChannelIn) { + for (ma_uint32 iChannelOut = 0; iChannelOut < routerConfig.channelsOut; ++iChannelOut) { float expectedWeight = 0; if (routerConfig.channelMapIn[iChannelIn] == routerConfig.channelMapOut[iChannelOut]) { expectedWeight = 1; @@ -1728,22 +1728,22 @@ int do_channel_routing_tests() printf("Simple Conversion (5.1 -> Stereo)... "); { - mal_channel_router_config routerConfig; - mal_zero_object(&routerConfig); + ma_channel_router_config routerConfig; + ma_zero_object(&routerConfig); routerConfig.onReadDeinterleaved = channel_router_callback__passthrough_test; routerConfig.pUserData = NULL; - routerConfig.mixingMode = mal_channel_mix_mode_simple; + routerConfig.mixingMode = ma_channel_mix_mode_simple; routerConfig.channelsIn = 6; routerConfig.channelsOut = 2; routerConfig.noSSE2 = MA_TRUE; routerConfig.noAVX2 = MA_TRUE; routerConfig.noAVX512 = MA_TRUE; routerConfig.noNEON = MA_TRUE; - mal_get_standard_channel_map(mal_standard_channel_map_microsoft, routerConfig.channelsIn, routerConfig.channelMapIn); - mal_get_standard_channel_map(mal_standard_channel_map_microsoft, routerConfig.channelsOut, routerConfig.channelMapOut); + ma_get_standard_channel_map(ma_standard_channel_map_microsoft, routerConfig.channelsIn, routerConfig.channelMapIn); + ma_get_standard_channel_map(ma_standard_channel_map_microsoft, routerConfig.channelsOut, routerConfig.channelMapOut); - mal_channel_router router; - mal_result result = mal_channel_router_init(&routerConfig, &router); + ma_channel_router router; + ma_result result = ma_channel_router_init(&routerConfig, &router); if (result == MA_SUCCESS) { if (router.isPassthrough) { printf("Router incorrectly configured as a passthrough.\n"); @@ -1755,8 +1755,8 @@ int do_channel_routing_tests() } // Expecting the weights to all be equal to 1 for each channel. - for (mal_uint32 iChannelIn = 0; iChannelIn < routerConfig.channelsIn; ++iChannelIn) { - for (mal_uint32 iChannelOut = 0; iChannelOut < routerConfig.channelsOut; ++iChannelOut) { + for (ma_uint32 iChannelIn = 0; iChannelIn < routerConfig.channelsIn; ++iChannelIn) { + for (ma_uint32 iChannelOut = 0; iChannelOut < routerConfig.channelsOut; ++iChannelOut) { float expectedWeight = 0; if (routerConfig.channelMapIn[iChannelIn] == routerConfig.channelMapOut[iChannelOut]) { expectedWeight = 1; @@ -1780,11 +1780,11 @@ int do_channel_routing_tests() printf("Planar Blend Conversion (Stereo -> 5.1)... "); { - mal_channel_router_config routerConfig; - mal_zero_object(&routerConfig); + ma_channel_router_config routerConfig; + ma_zero_object(&routerConfig); routerConfig.onReadDeinterleaved = channel_router_callback__passthrough_test; routerConfig.pUserData = NULL; - routerConfig.mixingMode = mal_channel_mix_mode_planar_blend; + routerConfig.mixingMode = ma_channel_mix_mode_planar_blend; routerConfig.noSSE2 = MA_TRUE; routerConfig.noAVX2 = MA_TRUE; routerConfig.noAVX512 = MA_TRUE; @@ -1805,8 +1805,8 @@ int do_channel_routing_tests() routerConfig.channelMapOut[6] = MA_CHANNEL_SIDE_LEFT; routerConfig.channelMapOut[7] = MA_CHANNEL_SIDE_RIGHT; - mal_channel_router router; - mal_result result = mal_channel_router_init(&routerConfig, &router); + ma_channel_router router; + ma_result result = ma_channel_router_init(&routerConfig, &router); if (result == MA_SUCCESS) { if (router.isPassthrough) { printf("Router incorrectly configured as a passthrough.\n"); @@ -1818,7 +1818,7 @@ int do_channel_routing_tests() } float expectedWeights[MA_MAX_CHANNELS][MA_MAX_CHANNELS]; - mal_zero_memory(expectedWeights, sizeof(expectedWeights)); + ma_zero_memory(expectedWeights, sizeof(expectedWeights)); expectedWeights[0][0] = 1.0f; // FRONT_LEFT -> FRONT_LEFT expectedWeights[0][1] = 0.0f; // FRONT_LEFT -> FRONT_RIGHT expectedWeights[0][2] = 0.5f; // FRONT_LEFT -> FRONT_CENTER @@ -1836,8 +1836,8 @@ int do_channel_routing_tests() expectedWeights[1][6] = 0.0f; // FRONT_RIGHT -> SIDE_LEFT expectedWeights[1][7] = 0.5f; // FRONT_RIGHT -> SIDE_RIGHT - for (mal_uint32 iChannelIn = 0; iChannelIn < routerConfig.channelsIn; ++iChannelIn) { - for (mal_uint32 iChannelOut = 0; iChannelOut < routerConfig.channelsOut; ++iChannelOut) { + for (ma_uint32 iChannelIn = 0; iChannelIn < routerConfig.channelsIn; ++iChannelIn) { + for (ma_uint32 iChannelOut = 0; iChannelOut < routerConfig.channelsOut; ++iChannelOut) { if (router.config.weights[iChannelIn][iChannelOut] != expectedWeights[iChannelIn][iChannelOut]) { printf("Failed. Channel weight incorrect for [%d][%d]. Expected %f, got %f\n", iChannelIn, iChannelOut, expectedWeights[iChannelIn][iChannelOut], router.config.weights[iChannelIn][iChannelOut]); hasError = MA_TRUE; @@ -1853,25 +1853,25 @@ int do_channel_routing_tests() // Test the actual conversion. The test data is set to +1 for the left channel, and -1 for the right channel. float testData[MA_MAX_CHANNELS][100]; float* ppTestData[MA_MAX_CHANNELS]; - for (mal_uint32 iChannel = 0; iChannel < routerConfig.channelsIn; ++iChannel) { + for (ma_uint32 iChannel = 0; iChannel < routerConfig.channelsIn; ++iChannel) { ppTestData[iChannel] = testData[iChannel]; } - for (mal_uint32 iFrame = 0; iFrame < 100; ++iFrame) { + for (ma_uint32 iFrame = 0; iFrame < 100; ++iFrame) { ppTestData[0][iFrame] = -1; ppTestData[1][iFrame] = +1; } routerConfig.pUserData = ppTestData; - mal_channel_router_init(&routerConfig, &router); + ma_channel_router_init(&routerConfig, &router); float output[MA_MAX_CHANNELS][100]; float* ppOutput[MA_MAX_CHANNELS]; - for (mal_uint32 iChannel = 0; iChannel < routerConfig.channelsOut; ++iChannel) { + for (ma_uint32 iChannel = 0; iChannel < routerConfig.channelsOut; ++iChannel) { ppOutput[iChannel] = output[iChannel]; } - mal_uint64 framesRead = mal_channel_router_read_deinterleaved(&router, 100, (void**)ppOutput, router.config.pUserData); + ma_uint64 framesRead = ma_channel_router_read_deinterleaved(&router, 100, (void**)ppOutput, router.config.pUserData); if (framesRead != 100) { printf("Returned frame count for optimized incorrect.\n"); hasError = MA_TRUE; @@ -1886,8 +1886,8 @@ int do_channel_routing_tests() expectedOutput[5] = +0.25f; // BACK_RIGHT expectedOutput[6] = -0.5f; // SIDE_LEFT expectedOutput[7] = +0.5f; // SIDE_RIGHT - for (mal_uint32 iChannel = 0; iChannel < routerConfig.channelsOut; ++iChannel) { - for (mal_uint32 iFrame = 0; iFrame < framesRead; ++iFrame) { + for (ma_uint32 iChannel = 0; iChannel < routerConfig.channelsOut; ++iChannel) { + for (ma_uint32 iFrame = 0; iFrame < framesRead; ++iFrame) { if (output[iChannel][iFrame] != expectedOutput[iChannel]) { printf("Incorrect sample [%d][%d]. Expecting %f, got %f\n", iChannel, iFrame, expectedOutput[iChannel], output[iChannel][iFrame]); hasError = MA_TRUE; @@ -1902,11 +1902,11 @@ int do_channel_routing_tests() printf("Planar Blend Conversion (5.1 -> Stereo)... "); { - mal_channel_router_config routerConfig; - mal_zero_object(&routerConfig); + ma_channel_router_config routerConfig; + ma_zero_object(&routerConfig); routerConfig.onReadDeinterleaved = channel_router_callback__passthrough_test; routerConfig.pUserData = NULL; - routerConfig.mixingMode = mal_channel_mix_mode_planar_blend; + routerConfig.mixingMode = ma_channel_mix_mode_planar_blend; routerConfig.noSSE2 = MA_TRUE; routerConfig.noAVX2 = MA_TRUE; routerConfig.noAVX512 = MA_TRUE; @@ -1927,8 +1927,8 @@ int do_channel_routing_tests() routerConfig.channelMapOut[0] = MA_CHANNEL_FRONT_LEFT; routerConfig.channelMapOut[1] = MA_CHANNEL_FRONT_RIGHT; - mal_channel_router router; - mal_result result = mal_channel_router_init(&routerConfig, &router); + ma_channel_router router; + ma_result result = ma_channel_router_init(&routerConfig, &router); if (result == MA_SUCCESS) { if (router.isPassthrough) { printf("Router incorrectly configured as a passthrough.\n"); @@ -1940,7 +1940,7 @@ int do_channel_routing_tests() } float expectedWeights[MA_MAX_CHANNELS][MA_MAX_CHANNELS]; - mal_zero_memory(expectedWeights, sizeof(expectedWeights)); + ma_zero_memory(expectedWeights, sizeof(expectedWeights)); expectedWeights[0][0] = 1.0f; // FRONT_LEFT -> FRONT_LEFT expectedWeights[1][0] = 0.0f; // FRONT_RIGHT -> FRONT_LEFT expectedWeights[2][0] = 0.5f; // FRONT_CENTER -> FRONT_LEFT @@ -1958,8 +1958,8 @@ int do_channel_routing_tests() expectedWeights[6][1] = 0.0f; // SIDE_LEFT -> FRONT_RIGHT expectedWeights[7][1] = 0.5f; // SIDE_RIGHT -> FRONT_RIGHT - for (mal_uint32 iChannelIn = 0; iChannelIn < routerConfig.channelsIn; ++iChannelIn) { - for (mal_uint32 iChannelOut = 0; iChannelOut < routerConfig.channelsOut; ++iChannelOut) { + for (ma_uint32 iChannelIn = 0; iChannelIn < routerConfig.channelsIn; ++iChannelIn) { + for (ma_uint32 iChannelOut = 0; iChannelOut < routerConfig.channelsOut; ++iChannelOut) { if (router.config.weights[iChannelIn][iChannelOut] != expectedWeights[iChannelIn][iChannelOut]) { printf("Failed. Channel weight incorrect for [%d][%d]. Expected %f, got %f\n", iChannelIn, iChannelOut, expectedWeights[iChannelIn][iChannelOut], router.config.weights[iChannelIn][iChannelOut]); hasError = MA_TRUE; @@ -1978,11 +1978,11 @@ int do_channel_routing_tests() printf("Mono -> 2.1 + None... "); { - mal_channel_router_config routerConfig; - mal_zero_object(&routerConfig); + ma_channel_router_config routerConfig; + ma_zero_object(&routerConfig); routerConfig.onReadDeinterleaved = channel_router_callback__passthrough_test; routerConfig.pUserData = NULL; - routerConfig.mixingMode = mal_channel_mix_mode_planar_blend; + routerConfig.mixingMode = ma_channel_mix_mode_planar_blend; routerConfig.noSSE2 = MA_TRUE; routerConfig.noAVX2 = MA_TRUE; routerConfig.noAVX512 = MA_TRUE; @@ -1998,8 +1998,8 @@ int do_channel_routing_tests() routerConfig.channelMapOut[2] = MA_CHANNEL_NONE; routerConfig.channelMapOut[3] = MA_CHANNEL_LFE; - mal_channel_router router; - mal_result result = mal_channel_router_init(&routerConfig, &router); + ma_channel_router router; + ma_result result = ma_channel_router_init(&routerConfig, &router); if (result == MA_SUCCESS) { if (router.isPassthrough) { printf("Router incorrectly configured as a passthrough.\n"); @@ -2011,14 +2011,14 @@ int do_channel_routing_tests() } float expectedWeights[MA_MAX_CHANNELS][MA_MAX_CHANNELS]; - mal_zero_memory(expectedWeights, sizeof(expectedWeights)); + ma_zero_memory(expectedWeights, sizeof(expectedWeights)); expectedWeights[0][0] = 1.0f; // MONO -> FRONT_LEFT expectedWeights[0][1] = 1.0f; // MONO -> FRONT_RIGHT expectedWeights[0][2] = 0.0f; // MONO -> NONE expectedWeights[0][3] = 0.0f; // MONO -> LFE - for (mal_uint32 iChannelIn = 0; iChannelIn < routerConfig.channelsIn; ++iChannelIn) { - for (mal_uint32 iChannelOut = 0; iChannelOut < routerConfig.channelsOut; ++iChannelOut) { + for (ma_uint32 iChannelIn = 0; iChannelIn < routerConfig.channelsIn; ++iChannelIn) { + for (ma_uint32 iChannelOut = 0; iChannelOut < routerConfig.channelsOut; ++iChannelOut) { if (router.config.weights[iChannelIn][iChannelOut] != expectedWeights[iChannelIn][iChannelOut]) { printf("Failed. Channel weight incorrect for [%d][%d]. Expected %f, got %f\n", iChannelIn, iChannelOut, expectedWeights[iChannelIn][iChannelOut], router.config.weights[iChannelIn][iChannelOut]); hasError = MA_TRUE; @@ -2037,11 +2037,11 @@ int do_channel_routing_tests() printf("2.1 + None -> Mono... "); { - mal_channel_router_config routerConfig; - mal_zero_object(&routerConfig); + ma_channel_router_config routerConfig; + ma_zero_object(&routerConfig); routerConfig.onReadDeinterleaved = channel_router_callback__passthrough_test; routerConfig.pUserData = NULL; - routerConfig.mixingMode = mal_channel_mix_mode_planar_blend; + routerConfig.mixingMode = ma_channel_mix_mode_planar_blend; routerConfig.noSSE2 = MA_TRUE; routerConfig.noAVX2 = MA_TRUE; routerConfig.noAVX512 = MA_TRUE; @@ -2057,8 +2057,8 @@ int do_channel_routing_tests() routerConfig.channelsOut = 1; routerConfig.channelMapOut[0] = MA_CHANNEL_MONO; - mal_channel_router router; - mal_result result = mal_channel_router_init(&routerConfig, &router); + ma_channel_router router; + ma_result result = ma_channel_router_init(&routerConfig, &router); if (result == MA_SUCCESS) { if (router.isPassthrough) { printf("Router incorrectly configured as a passthrough.\n"); @@ -2070,14 +2070,14 @@ int do_channel_routing_tests() } float expectedWeights[MA_MAX_CHANNELS][MA_MAX_CHANNELS]; - mal_zero_memory(expectedWeights, sizeof(expectedWeights)); + ma_zero_memory(expectedWeights, sizeof(expectedWeights)); expectedWeights[0][0] = 0.5f; // FRONT_LEFT -> MONO expectedWeights[1][0] = 0.5f; // FRONT_RIGHT -> MONO expectedWeights[2][0] = 0.0f; // NONE -> MONO expectedWeights[3][0] = 0.0f; // LFE -> MONO - for (mal_uint32 iChannelIn = 0; iChannelIn < routerConfig.channelsIn; ++iChannelIn) { - for (mal_uint32 iChannelOut = 0; iChannelOut < routerConfig.channelsOut; ++iChannelOut) { + for (ma_uint32 iChannelIn = 0; iChannelIn < routerConfig.channelsIn; ++iChannelIn) { + for (ma_uint32 iChannelOut = 0; iChannelOut < routerConfig.channelsOut; ++iChannelOut) { if (router.config.weights[iChannelIn][iChannelOut] != expectedWeights[iChannelIn][iChannelOut]) { printf("Failed. Channel weight incorrect for [%d][%d]. Expected %f, got %f\n", iChannelIn, iChannelOut, expectedWeights[iChannelIn][iChannelOut], router.config.weights[iChannelIn][iChannelOut]); hasError = MA_TRUE; @@ -2103,30 +2103,30 @@ int do_channel_routing_tests() } -int do_backend_test(mal_backend backend) +int do_backend_test(ma_backend backend) { - mal_result result = MA_SUCCESS; - mal_context context; - mal_device_info* pPlaybackDeviceInfos; - mal_uint32 playbackDeviceCount; - mal_device_info* pCaptureDeviceInfos; - mal_uint32 captureDeviceCount; + ma_result result = MA_SUCCESS; + ma_context context; + ma_device_info* pPlaybackDeviceInfos; + ma_uint32 playbackDeviceCount; + ma_device_info* pCaptureDeviceInfos; + ma_uint32 captureDeviceCount; - printf("--- %s ---\n", mal_get_backend_name(backend)); + printf("--- %s ---\n", ma_get_backend_name(backend)); // Context. printf(" Creating Context... "); { - mal_context_config contextConfig = mal_context_config_init(); + ma_context_config contextConfig = ma_context_config_init(); contextConfig.logCallback = on_log; - result = mal_context_init(&backend, 1, &contextConfig, &context); + result = ma_context_init(&backend, 1, &contextConfig, &context); if (result == MA_SUCCESS) { printf(" Done\n"); } else { if (result == MA_NO_BACKEND) { printf(" Not supported\n"); - printf("--- End %s ---\n", mal_get_backend_name(backend)); + printf("--- End %s ---\n", ma_get_backend_name(backend)); printf("\n"); return 0; } else { @@ -2139,7 +2139,7 @@ int do_backend_test(mal_backend backend) // Enumeration. printf(" Enumerating Devices... "); { - result = mal_context_get_devices(&context, &pPlaybackDeviceInfos, &playbackDeviceCount, &pCaptureDeviceInfos, &captureDeviceCount); + result = ma_context_get_devices(&context, &pPlaybackDeviceInfos, &playbackDeviceCount, &pCaptureDeviceInfos, &captureDeviceCount); if (result == MA_SUCCESS) { printf("Done\n"); } else { @@ -2148,12 +2148,12 @@ int do_backend_test(mal_backend backend) } printf(" Playback Devices (%d)\n", playbackDeviceCount); - for (mal_uint32 iDevice = 0; iDevice < playbackDeviceCount; ++iDevice) { + for (ma_uint32 iDevice = 0; iDevice < playbackDeviceCount; ++iDevice) { printf(" %d: %s\n", iDevice, pPlaybackDeviceInfos[iDevice].name); } printf(" Capture Devices (%d)\n", captureDeviceCount); - for (mal_uint32 iDevice = 0; iDevice < captureDeviceCount; ++iDevice) { + for (ma_uint32 iDevice = 0; iDevice < captureDeviceCount; ++iDevice) { printf(" %d: %s\n", iDevice, pCaptureDeviceInfos[iDevice].name); } } @@ -2162,10 +2162,10 @@ int do_backend_test(mal_backend backend) printf(" Getting Device Information...\n"); { printf(" Playback Devices (%d)\n", playbackDeviceCount); - for (mal_uint32 iDevice = 0; iDevice < playbackDeviceCount; ++iDevice) { + for (ma_uint32 iDevice = 0; iDevice < playbackDeviceCount; ++iDevice) { printf(" %d: %s\n", iDevice, pPlaybackDeviceInfos[iDevice].name); - result = mal_context_get_device_info(&context, mal_device_type_playback, &pPlaybackDeviceInfos[iDevice].id, mal_share_mode_shared, &pPlaybackDeviceInfos[iDevice]); + result = ma_context_get_device_info(&context, ma_device_type_playback, &pPlaybackDeviceInfos[iDevice].id, ma_share_mode_shared, &pPlaybackDeviceInfos[iDevice]); if (result == MA_SUCCESS) { printf(" Name: %s\n", pPlaybackDeviceInfos[iDevice].name); printf(" Min Channels: %d\n", pPlaybackDeviceInfos[iDevice].minChannels); @@ -2173,8 +2173,8 @@ int do_backend_test(mal_backend backend) printf(" Min Sample Rate: %d\n", pPlaybackDeviceInfos[iDevice].minSampleRate); printf(" Max Sample Rate: %d\n", pPlaybackDeviceInfos[iDevice].maxSampleRate); printf(" Format Count: %d\n", pPlaybackDeviceInfos[iDevice].formatCount); - for (mal_uint32 iFormat = 0; iFormat < pPlaybackDeviceInfos[iDevice].formatCount; ++iFormat) { - printf(" %s\n", mal_get_format_name(pPlaybackDeviceInfos[iDevice].formats[iFormat])); + for (ma_uint32 iFormat = 0; iFormat < pPlaybackDeviceInfos[iDevice].formatCount; ++iFormat) { + printf(" %s\n", ma_get_format_name(pPlaybackDeviceInfos[iDevice].formats[iFormat])); } } else { printf(" ERROR\n"); @@ -2182,10 +2182,10 @@ int do_backend_test(mal_backend backend) } printf(" Capture Devices (%d)\n", captureDeviceCount); - for (mal_uint32 iDevice = 0; iDevice < captureDeviceCount; ++iDevice) { + for (ma_uint32 iDevice = 0; iDevice < captureDeviceCount; ++iDevice) { printf(" %d: %s\n", iDevice, pCaptureDeviceInfos[iDevice].name); - result = mal_context_get_device_info(&context, mal_device_type_capture, &pCaptureDeviceInfos[iDevice].id, mal_share_mode_shared, &pCaptureDeviceInfos[iDevice]); + result = ma_context_get_device_info(&context, ma_device_type_capture, &pCaptureDeviceInfos[iDevice].id, ma_share_mode_shared, &pCaptureDeviceInfos[iDevice]); if (result == MA_SUCCESS) { printf(" Name: %s\n", pCaptureDeviceInfos[iDevice].name); printf(" Min Channels: %d\n", pCaptureDeviceInfos[iDevice].minChannels); @@ -2193,8 +2193,8 @@ int do_backend_test(mal_backend backend) printf(" Min Sample Rate: %d\n", pCaptureDeviceInfos[iDevice].minSampleRate); printf(" Max Sample Rate: %d\n", pCaptureDeviceInfos[iDevice].maxSampleRate); printf(" Format Count: %d\n", pCaptureDeviceInfos[iDevice].formatCount); - for (mal_uint32 iFormat = 0; iFormat < pCaptureDeviceInfos[iDevice].formatCount; ++iFormat) { - printf(" %s\n", mal_get_format_name(pCaptureDeviceInfos[iDevice].formats[iFormat])); + for (ma_uint32 iFormat = 0; iFormat < pCaptureDeviceInfos[iDevice].formatCount; ++iFormat) { + printf(" %s\n", ma_get_format_name(pCaptureDeviceInfos[iDevice].formats[iFormat])); } } else { printf(" ERROR\n"); @@ -2203,19 +2203,19 @@ int do_backend_test(mal_backend backend) } done: - printf("--- End %s ---\n", mal_get_backend_name(backend)); + printf("--- End %s ---\n", ma_get_backend_name(backend)); printf("\n"); - mal_context_uninit(&context); + ma_context_uninit(&context); return (result == MA_SUCCESS) ? 0 : -1; } int do_backend_tests() { - mal_bool32 hasErrorOccurred = MA_FALSE; + ma_bool32 hasErrorOccurred = MA_FALSE; // Tests are performed on a per-backend basis. - for (size_t iBackend = 0; iBackend < mal_countof(g_Backends); ++iBackend) { + for (size_t iBackend = 0; iBackend < ma_countof(g_Backends); ++iBackend) { int result = do_backend_test(g_Backends[iBackend]); if (result < 0) { hasErrorOccurred = MA_TRUE; @@ -2228,28 +2228,28 @@ int do_backend_tests() typedef struct { - mal_decoder* pDecoder; - mal_sine_wave* pSineWave; - mal_event endOfPlaybackEvent; + ma_decoder* pDecoder; + ma_sine_wave* pSineWave; + ma_event endOfPlaybackEvent; } playback_test_callback_data; -void on_send__playback_test(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 frameCount) +void on_send__playback_test(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount) { playback_test_callback_data* pData = (playback_test_callback_data*)pDevice->pUserData; - mal_assert(pData != NULL); + ma_assert(pData != NULL); #if !defined(__EMSCRIPTEN__) - mal_uint64 framesRead = mal_decoder_read_pcm_frames(pData->pDecoder, pOutput, frameCount); + ma_uint64 framesRead = ma_decoder_read_pcm_frames(pData->pDecoder, pOutput, frameCount); if (framesRead == 0) { - mal_event_signal(&pData->endOfPlaybackEvent); + ma_event_signal(&pData->endOfPlaybackEvent); } #else - if (pDevice->playback.format == mal_format_f32) { - for (mal_uint32 iFrame = 0; iFrame < frameCount; ++iFrame) { + if (pDevice->playback.format == ma_format_f32) { + for (ma_uint32 iFrame = 0; iFrame < frameCount; ++iFrame) { float sample; - mal_sine_wave_read_f32(pData->pSineWave, 1, &sample); + ma_sine_wave_read_f32(pData->pSineWave, 1, &sample); - for (mal_uint32 iChannel = 0; iChannel < pDevice->playback.channels; ++iChannel) { + for (ma_uint32 iChannel = 0; iChannel < pDevice->playback.channels; ++iChannel) { ((float*)pOutput)[iFrame*pDevice->playback.channels + iChannel] = sample; } } @@ -2259,53 +2259,53 @@ void on_send__playback_test(mal_device* pDevice, void* pOutput, const void* pInp (void)pInput; } -void on_stop__playback_test(mal_device* pDevice) +void on_stop__playback_test(ma_device* pDevice) { playback_test_callback_data* pData = (playback_test_callback_data*)pDevice->pUserData; - mal_assert(pData != NULL); + ma_assert(pData != NULL); printf("Device Stopped.\n"); - mal_event_signal(&pData->endOfPlaybackEvent); + ma_event_signal(&pData->endOfPlaybackEvent); } -int do_playback_test(mal_backend backend) +int do_playback_test(ma_backend backend) { - mal_result result = MA_SUCCESS; - mal_device device; - mal_decoder decoder; - mal_sine_wave sineWave; - mal_bool32 haveDevice = MA_FALSE; - mal_bool32 haveDecoder = MA_FALSE; + ma_result result = MA_SUCCESS; + ma_device device; + ma_decoder decoder; + ma_sine_wave sineWave; + ma_bool32 haveDevice = MA_FALSE; + ma_bool32 haveDecoder = MA_FALSE; playback_test_callback_data callbackData; callbackData.pDecoder = &decoder; callbackData.pSineWave = &sineWave; - printf("--- %s ---\n", mal_get_backend_name(backend)); + printf("--- %s ---\n", ma_get_backend_name(backend)); // Device. printf(" Opening Device... "); { - mal_context_config contextConfig = mal_context_config_init(); + ma_context_config contextConfig = ma_context_config_init(); contextConfig.logCallback = on_log; - mal_device_config deviceConfig = mal_device_config_init(mal_device_type_playback); + ma_device_config deviceConfig = ma_device_config_init(ma_device_type_playback); deviceConfig.pUserData = &callbackData; deviceConfig.dataCallback = on_send__playback_test; deviceConfig.stopCallback = on_stop__playback_test; #if defined(__EMSCRIPTEN__) - deviceConfig.playback.format = mal_format_f32; + deviceConfig.playback.format = ma_format_f32; #endif - result = mal_device_init_ex(&backend, 1, &contextConfig, &deviceConfig, &device); + result = ma_device_init_ex(&backend, 1, &contextConfig, &deviceConfig, &device); if (result == MA_SUCCESS) { printf("Done\n"); } else { if (result == MA_NO_BACKEND) { printf(" Not supported\n"); - printf("--- End %s ---\n", mal_get_backend_name(backend)); + printf("--- End %s ---\n", ma_get_backend_name(backend)); printf("\n"); return 0; } else { @@ -2321,15 +2321,15 @@ int do_playback_test(mal_backend backend) printf(" Opening Decoder... "); { - result = mal_event_init(device.pContext, &callbackData.endOfPlaybackEvent); + result = ma_event_init(device.pContext, &callbackData.endOfPlaybackEvent); if (result != MA_SUCCESS) { printf("Failed to init event.\n"); goto done; } #if !defined(__EMSCRIPTEN__) - mal_decoder_config decoderConfig = mal_decoder_config_init(device.playback.format, device.playback.channels, device.sampleRate); - result = mal_decoder_init_file("res/sine_s16_mono_48000.wav", &decoderConfig, &decoder); + ma_decoder_config decoderConfig = ma_decoder_config_init(device.playback.format, device.playback.channels, device.sampleRate); + result = ma_decoder_init_file("res/sine_s16_mono_48000.wav", &decoderConfig, &decoder); if (result == MA_SUCCESS) { printf("Done\n"); } else { @@ -2338,7 +2338,7 @@ int do_playback_test(mal_backend backend) } haveDecoder = MA_TRUE; #else - result = mal_sine_wave_init(0.5f, 400, device.sampleRate, &sineWave); + result = ma_sine_wave_init(0.5f, 400, device.sampleRate, &sineWave); if (result == MA_SUCCESS) { printf("Done\n"); } else { @@ -2353,7 +2353,7 @@ int do_playback_test(mal_backend backend) printf(" Press Enter to start playback... "); getchar(); { - result = mal_device_start(&device); + result = ma_device_start(&device); if (result != MA_SUCCESS) { printf("Failed to start device.\n"); goto done; @@ -2364,31 +2364,31 @@ int do_playback_test(mal_backend backend) #endif // Test rapid stopping and restarting. - //mal_device_stop(&device); - //mal_device_start(&device); + //ma_device_stop(&device); + //ma_device_start(&device); - mal_event_wait(&callbackData.endOfPlaybackEvent); // Wait for the sound to finish. + ma_event_wait(&callbackData.endOfPlaybackEvent); // Wait for the sound to finish. printf("Done\n"); } done: - printf("--- End %s ---\n", mal_get_backend_name(backend)); + printf("--- End %s ---\n", ma_get_backend_name(backend)); printf("\n"); if (haveDevice) { - mal_device_uninit(&device); + ma_device_uninit(&device); } if (haveDecoder) { - mal_decoder_uninit(&decoder); + ma_decoder_uninit(&decoder); } return (result == MA_SUCCESS) ? 0 : -1; } int do_playback_tests() { - mal_bool32 hasErrorOccurred = MA_FALSE; + ma_bool32 hasErrorOccurred = MA_FALSE; - for (size_t iBackend = 0; iBackend < mal_countof(g_Backends); ++iBackend) { + for (size_t iBackend = 0; iBackend < ma_countof(g_Backends); ++iBackend) { int result = do_playback_test(g_Backends[iBackend]); if (result < 0) { hasErrorOccurred = MA_TRUE; @@ -2403,7 +2403,7 @@ int main(int argc, char** argv) (void)argc; (void)argv; - mal_bool32 hasErrorOccurred = MA_FALSE; + ma_bool32 hasErrorOccurred = MA_FALSE; int result = 0; // Print the compiler. @@ -2424,22 +2424,22 @@ int main(int argc, char** argv) #endif // Print CPU features. - if (mal_has_sse2()) { + if (ma_has_sse2()) { printf("Has SSE: YES\n"); } else { printf("Has SSE: NO\n"); } - if (mal_has_avx2()) { + if (ma_has_avx2()) { printf("Has AVX2: YES\n"); } else { printf("Has AVX2: NO\n"); } - if (mal_has_avx512f()) { + if (ma_has_avx512f()) { printf("Has AVX-512F: YES\n"); } else { printf("Has AVX-512F: NO\n"); } - if (mal_has_neon()) { + if (ma_has_neon()) { printf("Has NEON: YES\n"); } else { printf("Has NEON: NO\n"); @@ -2476,7 +2476,7 @@ int main(int argc, char** argv) printf("\n"); - // mal_format_converter + // ma_format_converter printf("=== TESTING FORMAT CONVERTER ===\n"); result = do_format_converter_tests(); if (result < 0) { diff --git a/tests/mal_test_0.cpp b/tests/mal_test_0.cpp index 5a18a33d..dbfef5d5 100644 --- a/tests/mal_test_0.cpp +++ b/tests/mal_test_0.cpp @@ -1 +1 @@ -#include "mal_test_0.c" \ No newline at end of file +#include "ma_test_0.c" \ No newline at end of file diff --git a/tests/mal_test_0.vcxproj b/tests/mal_test_0.vcxproj index a28d3b69..3a3aac56 100644 --- a/tests/mal_test_0.vcxproj +++ b/tests/mal_test_0.vcxproj @@ -29,7 +29,7 @@ {3430EEA2-AC6E-4DC7-B684-1F698D01FAE8} Win32Proj - mal_test_0 + ma_test_0 10.0.15063.0 @@ -262,7 +262,7 @@ - + true true true @@ -302,7 +302,7 @@ true true - + true true true @@ -310,7 +310,7 @@ true true - + true true true @@ -318,7 +318,7 @@ true true - + true true true @@ -326,7 +326,7 @@ true true - + true true true @@ -334,7 +334,7 @@ true true - + true true true @@ -342,7 +342,7 @@ true true - + true true true @@ -350,7 +350,7 @@ true true - + true true true @@ -358,7 +358,7 @@ true true - + true true true @@ -366,7 +366,7 @@ true true - + false false false @@ -377,7 +377,7 @@ - + diff --git a/tests/mal_test_0.vcxproj.filters b/tests/mal_test_0.vcxproj.filters index f8640083..2a6605c3 100644 --- a/tests/mal_test_0.vcxproj.filters +++ b/tests/mal_test_0.vcxproj.filters @@ -15,40 +15,40 @@ - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files Source Files - + Source Files Source Files - + Source Files - + Source Files @@ -62,7 +62,7 @@ Source Files - + Source Files diff --git a/tests/mal_webaudio_test_0.html b/tests/mal_webaudio_test_0.html index 5aac7f2e..3d03d8d3 100644 --- a/tests/mal_webaudio_test_0.html +++ b/tests/mal_webaudio_test_0.html @@ -42,7 +42,7 @@