Commit e00fe077 authored by David Reid's avatar David Reid

"mal_" to "ma_".

parent f1bf58d0
...@@ -74,14 +74,14 @@ Simple Playback Example ...@@ -74,14 +74,14 @@ Simple Playback Example
#include <stdio.h> #include <stdio.h>
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) { if (pDecoder == NULL) {
return; return;
} }
mal_decoder_read_pcm_frames(pDecoder, pOutput, frameCount); ma_decoder_read_pcm_frames(pDecoder, pOutput, frameCount);
(void)pInput; (void)pInput;
} }
...@@ -93,38 +93,38 @@ int main(int argc, char** argv) ...@@ -93,38 +93,38 @@ int main(int argc, char** argv)
return -1; return -1;
} }
mal_decoder decoder; ma_decoder decoder;
mal_result result = mal_decoder_init_file(argv[1], NULL, &decoder); ma_result result = ma_decoder_init_file(argv[1], NULL, &decoder);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
return -2; 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.format = decoder.outputFormat;
config.playback.channels = decoder.outputChannels; config.playback.channels = decoder.outputChannels;
config.sampleRate = decoder.outputSampleRate; config.sampleRate = decoder.outputSampleRate;
config.dataCallback = data_callback; config.dataCallback = data_callback;
config.pUserData = &decoder; config.pUserData = &decoder;
mal_device device; ma_device device;
if (mal_device_init(NULL, &config, &device) != MA_SUCCESS) { if (ma_device_init(NULL, &config, &device) != MA_SUCCESS) {
printf("Failed to open playback device.\n"); printf("Failed to open playback device.\n");
mal_decoder_uninit(&decoder); ma_decoder_uninit(&decoder);
return -3; return -3;
} }
if (mal_device_start(&device) != MA_SUCCESS) { if (ma_device_start(&device) != MA_SUCCESS) {
printf("Failed to start playback device.\n"); printf("Failed to start playback device.\n");
mal_device_uninit(&device); ma_device_uninit(&device);
mal_decoder_uninit(&decoder); ma_decoder_uninit(&decoder);
return -4; return -4;
} }
printf("Press Enter to quit..."); printf("Press Enter to quit...");
getchar(); getchar();
mal_device_uninit(&device); ma_device_uninit(&device);
mal_decoder_uninit(&decoder); ma_decoder_uninit(&decoder);
return 0; return 0;
} }
...@@ -158,28 +158,28 @@ relevant backend library before the implementation of miniaudio, like so: ...@@ -158,28 +158,28 @@ relevant backend library before the implementation of miniaudio, like so:
#include "miniaudio.h" #include "miniaudio.h"
``` ```
A decoder can be initialized from a file with `mal_decoder_init_file()`, a block of memory with A decoder can be initialized from a file with `ma_decoder_init_file()`, a block of memory with
`mal_decoder_init_memory()`, or from data delivered via callbacks with `mal_decoder_init()`. Here `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: is an example for loading a decoder from a file:
``` ```
mal_decoder decoder; ma_decoder decoder;
mal_result result = mal_decoder_init_file("MySong.mp3", NULL, &decoder); ma_result result = ma_decoder_init_file("MySong.mp3", NULL, &decoder);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
return false; // An error occurred. 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 (the `NULL` argument in the example above) which allows you to configure the output format, channel
count, sample rate and channel map: 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 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. ...@@ -188,13 +188,13 @@ decoding backend.
Data is read from the decoder as PCM frames: 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: 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) { if (result != MA_SUCCESS) {
return false; // An error occurred. return false; // An error occurred.
} }
...@@ -205,14 +205,14 @@ backend. This can be unnecessarily inefficient if the type is already known. In ...@@ -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: use the `_wav`, `_mp3`, etc. varients of the aforementioned initialization APIs:
``` ```
mal_decoder_init_wav() ma_decoder_init_wav()
mal_decoder_init_mp3() ma_decoder_init_mp3()
mal_decoder_init_memory_wav() ma_decoder_init_memory_wav()
mal_decoder_init_memory_mp3() ma_decoder_init_memory_mp3()
mal_decoder_init_file_wav() ma_decoder_init_file_wav()
mal_decoder_init_file_mp3() ma_decoder_init_file_mp3()
etc. 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. backend to prefer.
...@@ -2,7 +2,7 @@ To compile these examples, cd into the "build" directory and run the applicable ...@@ -2,7 +2,7 @@ To compile these examples, cd into the "build" directory and run the applicable
will be placed in the "bin" directory. will be placed in the "bin" directory.
cd build cd build
./mal_build_examples_linux ./ma_build_examples_linux
Then you can run executables like this: Then you can run executables like this:
......
...@@ -3,14 +3,14 @@ ...@@ -3,14 +3,14 @@
#include <stdio.h> #include <stdio.h>
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)pContext;
(void)pDevice; (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)pDevice;
(void)pOutput; (void)pOutput;
...@@ -19,7 +19,7 @@ void data_callback(mal_device* pDevice, void* pOutput, const void* pInput, mal_u ...@@ -19,7 +19,7 @@ void data_callback(mal_device* pDevice, void* pOutput, const void* pInput, mal_u
return; // Just output silence for this example. return; // Just output silence for this example.
} }
void stop_callback(mal_device* pDevice) void stop_callback(ma_device* pDevice)
{ {
(void)pDevice; (void)pDevice;
printf("Device stopped\n"); printf("Device stopped\n");
...@@ -31,14 +31,14 @@ int main(int argc, char** argv) ...@@ -31,14 +31,14 @@ int main(int argc, char** argv)
(void)argv; (void)argv;
// When initializing a context, you can pass in an optional configuration object that allows you to control // 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. // 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; contextConfig.logCallback = log_callback;
// The priority of the worker thread can be set with the following. The default priority is // The priority of the worker thread can be set with the following. The default priority is
// mal_thread_priority_highest. // ma_thread_priority_highest.
contextConfig.threadPriority = mal_thread_priority_normal; contextConfig.threadPriority = ma_thread_priority_normal;
// PulseAudio // PulseAudio
...@@ -80,52 +80,52 @@ int main(int argc, char** argv) ...@@ -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 // 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. // will fail.
mal_backend backends[] = { ma_backend backends[] = {
mal_backend_wasapi, // Higest priority. ma_backend_wasapi, // Higest priority.
mal_backend_dsound, ma_backend_dsound,
mal_backend_winmm, ma_backend_winmm,
mal_backend_coreaudio, ma_backend_coreaudio,
mal_backend_sndio, ma_backend_sndio,
mal_backend_audio4, ma_backend_audio4,
mal_backend_oss, ma_backend_oss,
mal_backend_pulseaudio, ma_backend_pulseaudio,
mal_backend_alsa, ma_backend_alsa,
mal_backend_jack, ma_backend_jack,
mal_backend_aaudio, ma_backend_aaudio,
mal_backend_opensl, ma_backend_opensl,
mal_backend_webaudio, ma_backend_webaudio,
mal_backend_null // Lowest priority. ma_backend_null // Lowest priority.
}; };
mal_context context; ma_context context;
if (mal_context_init(backends, sizeof(backends)/sizeof(backends[0]), &contextConfig, &context) != MA_SUCCESS) { if (ma_context_init(backends, sizeof(backends)/sizeof(backends[0]), &contextConfig, &context) != MA_SUCCESS) {
printf("Failed to initialize context."); printf("Failed to initialize context.");
return -2; return -2;
} }
// Enumerate devices. // Enumerate devices.
mal_device_info* pPlaybackDeviceInfos; ma_device_info* pPlaybackDeviceInfos;
mal_uint32 playbackDeviceCount; ma_uint32 playbackDeviceCount;
mal_device_info* pCaptureDeviceInfos; ma_device_info* pCaptureDeviceInfos;
mal_uint32 captureDeviceCount; ma_uint32 captureDeviceCount;
mal_result result = mal_context_get_devices(&context, &pPlaybackDeviceInfos, &playbackDeviceCount, &pCaptureDeviceInfos, &captureDeviceCount); ma_result result = ma_context_get_devices(&context, &pPlaybackDeviceInfos, &playbackDeviceCount, &pCaptureDeviceInfos, &captureDeviceCount);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
printf("Failed to retrieve device information.\n"); printf("Failed to retrieve device information.\n");
return -3; return -3;
} }
printf("Playback Devices (%d)\n", playbackDeviceCount); 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(" %u: %s\n", iDevice, pPlaybackDeviceInfos[iDevice].name);
} }
printf("\n"); printf("\n");
printf("Capture Devices (%d)\n", captureDeviceCount); 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); printf(" %u: %s\n", iDevice, pCaptureDeviceInfos[iDevice].name);
} }
...@@ -133,12 +133,12 @@ int main(int argc, char** argv) ...@@ -133,12 +133,12 @@ int main(int argc, char** argv)
// Open the device. // Open the device.
// //
// Unlike context configs, device configs are required. Similar to context configs, an API exists to help you // 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 // 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. // 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); ma_device_config deviceConfig = ma_device_config_init(ma_device_type_playback);
deviceConfig.playback.format = mal_format_s16; deviceConfig.playback.format = ma_format_s16;
deviceConfig.playback.channels = 2; deviceConfig.playback.channels = 2;
deviceConfig.sampleRate = 48000; deviceConfig.sampleRate = 48000;
deviceConfig.dataCallback = data_callback; deviceConfig.dataCallback = data_callback;
...@@ -149,7 +149,7 @@ int main(int argc, char** argv) ...@@ -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 // 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. // 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 // 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 // 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) ...@@ -165,12 +165,12 @@ int main(int argc, char** argv)
deviceConfig.alsa.noMMap = MA_TRUE; 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 // 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 // for device selection by ma_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 // 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. // audio glitches or whatnot with specific devices.
#ifdef MA_SUPPORT_ALSA #ifdef MA_SUPPORT_ALSA
mal_device_id customDeviceID; ma_device_id customDeviceID;
if (context.backend == mal_backend_alsa) { if (context.backend == ma_backend_alsa) {
strcpy(customDeviceID.alsa, "hw:0,0"); strcpy(customDeviceID.alsa, "hw:0,0");
// The ALSA backend also supports a miniaudio-specific format which looks like this: ":0,0". In this case, // 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) ...@@ -181,26 +181,26 @@ int main(int argc, char** argv)
} }
#endif #endif
mal_device playbackDevice; ma_device playbackDevice;
if (mal_device_init(&context, &deviceConfig, &playbackDevice) != MA_SUCCESS) { if (ma_device_init(&context, &deviceConfig, &playbackDevice) != MA_SUCCESS) {
printf("Failed to initialize playback device.\n"); printf("Failed to initialize playback device.\n");
mal_context_uninit(&context); ma_context_uninit(&context);
return -7; return -7;
} }
if (mal_device_start(&playbackDevice) != MA_SUCCESS) { if (ma_device_start(&playbackDevice) != MA_SUCCESS) {
printf("Failed to start playback device.\n"); printf("Failed to start playback device.\n");
mal_device_uninit(&playbackDevice); ma_device_uninit(&playbackDevice);
mal_context_uninit(&context); ma_context_uninit(&context);
return -8; return -8;
} }
printf("Press Enter to quit..."); printf("Press Enter to quit...");
getchar(); getchar();
mal_device_uninit(&playbackDevice); ma_device_uninit(&playbackDevice);
mal_context_uninit(&context); ma_context_uninit(&context);
return 0; return 0;
} }
...@@ -9,12 +9,12 @@ ...@@ -9,12 +9,12 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
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; (void)pOutput;
drwav* pWav = (drwav*)pDevice->pUserData; drwav* pWav = (drwav*)pDevice->pUserData;
mal_assert(pWav != NULL); ma_assert(pWav != NULL);
drwav_write_pcm_frames(pWav, frameCount, pInput); drwav_write_pcm_frames(pWav, frameCount, pInput);
} }
...@@ -26,7 +26,7 @@ int main(int argc, char** argv) ...@@ -26,7 +26,7 @@ int main(int argc, char** argv)
return -1; return -1;
} }
mal_result result; ma_result result;
drwav_data_format wavFormat; drwav_data_format wavFormat;
wavFormat.container = drwav_container_riff; wavFormat.container = drwav_container_riff;
...@@ -41,23 +41,23 @@ int main(int argc, char** argv) ...@@ -41,23 +41,23 @@ int main(int argc, char** argv)
return -1; return -1;
} }
mal_device_config config = mal_device_config_init(mal_device_type_capture); ma_device_config config = ma_device_config_init(ma_device_type_capture);
config.capture.format = mal_format_f32; config.capture.format = ma_format_f32;
config.capture.channels = wavFormat.channels; config.capture.channels = wavFormat.channels;
config.sampleRate = wavFormat.sampleRate; config.sampleRate = wavFormat.sampleRate;
config.dataCallback = data_callback; config.dataCallback = data_callback;
config.pUserData = &wav; config.pUserData = &wav;
mal_device device; ma_device device;
result = mal_device_init(NULL, &config, &device); result = ma_device_init(NULL, &config, &device);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
printf("Failed to initialize capture device.\n"); printf("Failed to initialize capture device.\n");
return -2; return -2;
} }
result = mal_device_start(&device); result = ma_device_start(&device);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
mal_device_uninit(&device); ma_device_uninit(&device);
printf("Failed to start device.\n"); printf("Failed to start device.\n");
return -3; return -3;
} }
...@@ -65,7 +65,7 @@ int main(int argc, char** argv) ...@@ -65,7 +65,7 @@ int main(int argc, char** argv)
printf("Press Enter to stop recording...\n"); printf("Press Enter to stop recording...\n");
getchar(); getchar();
mal_device_uninit(&device); ma_device_uninit(&device);
drwav_uninit(&wav); drwav_uninit(&wav);
return 0; return 0;
......
...@@ -8,35 +8,35 @@ int main(int argc, char** argv) ...@@ -8,35 +8,35 @@ int main(int argc, char** argv)
(void)argc; (void)argc;
(void)argv; (void)argv;
mal_context context; ma_context context;
if (mal_context_init(NULL, 0, NULL, &context) != MA_SUCCESS) { if (ma_context_init(NULL, 0, NULL, &context) != MA_SUCCESS) {
printf("Failed to initialize context.\n"); printf("Failed to initialize context.\n");
return -2; return -2;
} }
mal_device_info* pPlaybackDeviceInfos; ma_device_info* pPlaybackDeviceInfos;
mal_uint32 playbackDeviceCount; ma_uint32 playbackDeviceCount;
mal_device_info* pCaptureDeviceInfos; ma_device_info* pCaptureDeviceInfos;
mal_uint32 captureDeviceCount; ma_uint32 captureDeviceCount;
mal_result result = mal_context_get_devices(&context, &pPlaybackDeviceInfos, &playbackDeviceCount, &pCaptureDeviceInfos, &captureDeviceCount); ma_result result = ma_context_get_devices(&context, &pPlaybackDeviceInfos, &playbackDeviceCount, &pCaptureDeviceInfos, &captureDeviceCount);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
printf("Failed to retrieve device information.\n"); printf("Failed to retrieve device information.\n");
return -3; return -3;
} }
printf("Playback Devices\n"); 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(" %u: %s\n", iDevice, pPlaybackDeviceInfos[iDevice].name);
} }
printf("\n"); printf("\n");
printf("Capture Devices\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); printf(" %u: %s\n", iDevice, pCaptureDeviceInfos[iDevice].name);
} }
mal_context_uninit(&context); ma_context_uninit(&context);
return 0; return 0;
} }
...@@ -10,14 +10,14 @@ ...@@ -10,14 +10,14 @@
#include <stdio.h> #include <stdio.h>
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) { if (pDecoder == NULL) {
return; return;
} }
mal_decoder_read_pcm_frames(pDecoder, pOutput, frameCount); ma_decoder_read_pcm_frames(pDecoder, pOutput, frameCount);
(void)pInput; (void)pInput;
} }
...@@ -29,38 +29,38 @@ int main(int argc, char** argv) ...@@ -29,38 +29,38 @@ int main(int argc, char** argv)
return -1; return -1;
} }
mal_decoder decoder; ma_decoder decoder;
mal_result result = mal_decoder_init_file(argv[1], NULL, &decoder); ma_result result = ma_decoder_init_file(argv[1], NULL, &decoder);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
return -2; 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.format = decoder.outputFormat;
config.playback.channels = decoder.outputChannels; config.playback.channels = decoder.outputChannels;
config.sampleRate = decoder.outputSampleRate; config.sampleRate = decoder.outputSampleRate;
config.dataCallback = data_callback; config.dataCallback = data_callback;
config.pUserData = &decoder; config.pUserData = &decoder;
mal_device device; ma_device device;
if (mal_device_init(NULL, &config, &device) != MA_SUCCESS) { if (ma_device_init(NULL, &config, &device) != MA_SUCCESS) {
printf("Failed to open playback device.\n"); printf("Failed to open playback device.\n");
mal_decoder_uninit(&decoder); ma_decoder_uninit(&decoder);
return -3; return -3;
} }
if (mal_device_start(&device) != MA_SUCCESS) { if (ma_device_start(&device) != MA_SUCCESS) {
printf("Failed to start playback device.\n"); printf("Failed to start playback device.\n");
mal_device_uninit(&device); ma_device_uninit(&device);
mal_decoder_uninit(&decoder); ma_decoder_uninit(&decoder);
return -4; return -4;
} }
printf("Press Enter to quit..."); printf("Press Enter to quit...");
getchar(); getchar();
mal_device_uninit(&device); ma_device_uninit(&device);
mal_decoder_uninit(&decoder); ma_decoder_uninit(&decoder);
return 0; return 0;
} }
...@@ -11,19 +11,19 @@ void main_loop__em() ...@@ -11,19 +11,19 @@ void main_loop__em()
} }
#endif #endif
#define DEVICE_FORMAT mal_format_f32 #define DEVICE_FORMAT ma_format_f32
#define DEVICE_CHANNELS 1 #define DEVICE_CHANNELS 1
#define DEVICE_SAMPLE_RATE 48000 #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. */ (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; ma_sine_wave* pSineWave = (ma_sine_wave*)pDevice->pUserData;
mal_assert(pSineWave != NULL); 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) int main(int argc, char** argv)
...@@ -31,27 +31,27 @@ int main(int argc, char** argv) ...@@ -31,27 +31,27 @@ int main(int argc, char** argv)
(void)argc; (void)argc;
(void)argv; (void)argv;
mal_sine_wave sineWave; ma_sine_wave sineWave;
mal_sine_wave_init(0.2, 400, DEVICE_SAMPLE_RATE, &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.format = DEVICE_FORMAT;
config.playback.channels = DEVICE_CHANNELS; config.playback.channels = DEVICE_CHANNELS;
config.sampleRate = DEVICE_SAMPLE_RATE; config.sampleRate = DEVICE_SAMPLE_RATE;
config.dataCallback = data_callback; config.dataCallback = data_callback;
config.pUserData = &sineWave; config.pUserData = &sineWave;
mal_device device; ma_device device;
if (mal_device_init(NULL, &config, &device) != MA_SUCCESS) { if (ma_device_init(NULL, &config, &device) != MA_SUCCESS) {
printf("Failed to open playback device.\n"); printf("Failed to open playback device.\n");
return -4; return -4;
} }
printf("Device Name: %s\n", device.playback.name); 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"); printf("Failed to start playback device.\n");
mal_device_uninit(&device); ma_device_uninit(&device);
return -5; return -5;
} }
...@@ -62,7 +62,7 @@ int main(int argc, char** argv) ...@@ -62,7 +62,7 @@ int main(int argc, char** argv)
getchar(); getchar();
#endif #endif
mal_device_uninit(&device); ma_device_uninit(&device);
return 0; return 0;
} }
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -8,12 +8,12 @@ Requirements: ...@@ -8,12 +8,12 @@ Requirements:
- Linear with optional filtering - Linear with optional filtering
- Sinc - Sinc
- Floating point pipeline for f32 and fixed point integer pipeline for s16 - 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 - 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 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 - 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() - 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 - 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 returned value must be fractional. Likewise, must be able to query the number of cached input PCM frames and must
also be fractional. also be fractional.
...@@ -26,13 +26,13 @@ Requirements: ...@@ -26,13 +26,13 @@ Requirements:
the last input samples to be cached in the internal structure for the windowing algorithm. Other situations require 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. 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. - 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. result code. inputFrameCount and outputFrameCount are both input and output.
- Need to support using a ring buffer as the backing data. - 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? how to handle underruns - should it stop processing or should it pad with zeroes?
- Need to support reading from a callback. - 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: Other Notes:
...@@ -44,13 +44,13 @@ Other Notes: ...@@ -44,13 +44,13 @@ Other Notes:
Random Notes: Random Notes:
- You cannot change the algorithm after initialization. - 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 - 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 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. extreme ratios then you will need to chain resamplers together.
*/ */
#ifndef mal_resampler_h #ifndef ma_resampler_h
#define mal_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_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. */ #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: ...@@ -59,89 +59,89 @@ Random Notes:
#define MA_RESAMPLER_CACHE_SIZE_IN_BYTES 4096 #define MA_RESAMPLER_CACHE_SIZE_IN_BYTES 4096
#endif #endif
typedef struct mal_resampler mal_resampler; typedef struct ma_resampler ma_resampler;
/* Client callbacks. */ /* 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. */ /* Backend functions. */
typedef mal_result (* mal_resampler_init_proc) (mal_resampler* pResampler); typedef ma_result (* ma_resampler_init_proc) (ma_resampler* pResampler);
typedef mal_uint64 (* mal_resampler_read_f32_proc)(mal_resampler* pResampler, mal_uint64 frameCount, float** ppFrames); typedef ma_uint64 (* ma_resampler_read_f32_proc)(ma_resampler* pResampler, ma_uint64 frameCount, float** ppFrames);
typedef mal_uint64 (* mal_resampler_read_s16_proc)(mal_resampler* pResampler, mal_uint64 frameCount, mal_int16** ppFrames); typedef ma_uint64 (* ma_resampler_read_s16_proc)(ma_resampler* pResampler, ma_uint64 frameCount, ma_int16** ppFrames);
typedef mal_uint64 (* mal_resampler_seek_proc) (mal_resampler* pResampler, mal_uint64 frameCount, mal_uint32 options); typedef ma_uint64 (* ma_resampler_seek_proc) (ma_resampler* pResampler, ma_uint64 frameCount, ma_uint32 options);
typedef enum typedef enum
{ {
mal_resampler_algorithm_sinc = 0, /* Default. */ ma_resampler_algorithm_sinc = 0, /* Default. */
mal_resampler_algorithm_linear, /* Fastest. */ ma_resampler_algorithm_linear, /* Fastest. */
} mal_resampler_algorithm; } ma_resampler_algorithm;
typedef enum 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. */ 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. */
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. */ 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. */
} mal_resampler_end_of_input_mode; } ma_resampler_end_of_input_mode;
typedef struct typedef struct
{ {
mal_format format; ma_format format;
mal_uint32 channels; ma_uint32 channels;
mal_uint32 sampleRateIn; ma_uint32 sampleRateIn;
mal_uint32 sampleRateOut; ma_uint32 sampleRateOut;
double ratio; /* ratio = in/out */ double ratio; /* ratio = in/out */
mal_resampler_algorithm algorithm; ma_resampler_algorithm algorithm;
mal_resampler_end_of_input_mode endOfInputMode; ma_resampler_end_of_input_mode endOfInputMode;
mal_stream_layout layout; /* Interleaved or deinterleaved. */ ma_stream_layout layout; /* Interleaved or deinterleaved. */
mal_resampler_read_from_client_proc onRead; ma_resampler_read_from_client_proc onRead;
void* pUserData; void* pUserData;
} mal_resampler_config; } ma_resampler_config;
struct mal_resampler struct ma_resampler
{ {
union union
{ {
float f32[MA_RESAMPLER_CACHE_SIZE_IN_BYTES/sizeof(float)]; 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. */ } 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. */ 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. */
mal_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 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_uint16 windowLength;
double windowTime; /* By input rate. Relative to the start of the cache. */ double windowTime; /* By input rate. Relative to the start of the cache. */
mal_resampler_config config; ma_resampler_config config;
mal_resampler_init_proc init; ma_resampler_init_proc init;
mal_resampler_read_f32_proc readF32; ma_resampler_read_f32_proc readF32;
mal_resampler_read_s16_proc readS16; ma_resampler_read_s16_proc readS16;
mal_resampler_seek_proc seek; ma_resampler_seek_proc seek;
}; };
/* /*
Initializes a new resampler object from a config. 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. Uninitializes the given resampler.
*/ */
void mal_resampler_uninit(mal_resampler* pResampler); void ma_resampler_uninit(ma_resampler* pResampler);
/* /*
Dynamically adjusts the sample rate. 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. Dynamically adjusts the sample rate by a ratio.
The ratio is in/out. 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. 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. Seeks forward by the specified number of PCM frames.
...@@ -152,45 +152,45 @@ 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 MA_RESAMPLER_SEEK_INPUT_RATE
Treats "frameCount" as input samples instead of output samples. 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. 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. 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. 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. 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 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 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. 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. 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. 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 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. ...@@ -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 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. 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. 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 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. 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 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 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. 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. 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 #endif
#ifdef MINIAUDIO_IMPLEMENTATION #ifdef MINIAUDIO_IMPLEMENTATION
...@@ -229,64 +229,64 @@ mal_uint64 mal_resampler_get_expected_output_frame_count(mal_resampler* pResampl ...@@ -229,64 +229,64 @@ mal_uint64 mal_resampler_get_expected_output_frame_count(mal_resampler* pResampl
#define MA_RESAMPLER_MAX_RATIO 48.0 #define MA_RESAMPLER_MAX_RATIO 48.0
#endif #endif
mal_result mal_resampler_init__linear(mal_resampler* pResampler); ma_result ma_resampler_init__linear(ma_resampler* pResampler);
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_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_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_result mal_resampler_init__sinc(mal_resampler* pResampler); ma_result ma_resampler_init__sinc(ma_resampler* pResampler);
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_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_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);
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 #if 0
#define MA_ALIGN_INT(val, alignment) (((val) + ((alignment)-1)) & ~((alignment)-1)) #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: This macro declares a set of variables on the stack of a given size in bytes. The variables it creates are:
- mal_uint8 <name>Unaligned[size + MA_SIMD_ALIGNMENT]; - ma_uint8 <name>Unaligned[size + MA_SIMD_ALIGNMENT];
- <type>* <name>[MA_MAX_CHANNELS]; - <type>* <name>[MA_MAX_CHANNELS];
- size_t <name>FrameCount; <-- This is the number of samples contained within each sub-buffer of <name> - size_t <name>FrameCount; <-- This is the number of samples contained within each sub-buffer of <name>
This does not work for formats that do not have a clean mapping to a primitive C type. s24 will not work here. 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) \ #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]; \ type* name[MA_MAX_CHANNELS]; \
size_t name##FrameCount = ((size) & ~((MA_SIMD_ALIGNMENT)-1)) / sizeof(type); \ size_t name##FrameCount = ((size) & ~((MA_SIMD_ALIGNMENT)-1)) / sizeof(type); \
do { \ do { \
mal_uint32 iChannel; \ ma_uint32 iChannel; \
for (iChannel = 0; iChannel < channels; ++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) } while (0)
#endif #endif
#define mal_filter_window_length_left(length) ((length) >> 1) #define ma_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_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 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 ...@@ -294,8 +294,8 @@ static MA_INLINE double mal_resampler__calculate_cached_input_time_by_mode(mal_r
of the window. of the window.
*/ */
double cachedInputTime = pResampler->cacheLengthInFrames; double cachedInputTime = pResampler->cacheLengthInFrames;
if (mode == mal_resampler_end_of_input_mode_consume) { if (mode == ma_resampler_end_of_input_mode_consume) {
cachedInputTime -= (pResampler->windowTime + mal_resampler__window_length_left(pResampler)); cachedInputTime -= (pResampler->windowTime + ma_resampler__window_length_left(pResampler));
} else { } else {
cachedInputTime -= (pResampler->windowTime + pResampler->windowLength); cachedInputTime -= (pResampler->windowTime + pResampler->windowLength);
} }
...@@ -303,42 +303,42 @@ static MA_INLINE double mal_resampler__calculate_cached_input_time_by_mode(mal_r ...@@ -303,42 +303,42 @@ static MA_INLINE double mal_resampler__calculate_cached_input_time_by_mode(mal_r
return cachedInputTime; 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. */ /* 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; ma_uint16 framesToConsume;
framesToConsume = (mal_uint16)pResampler->windowTime; framesToConsume = (ma_uint16)pResampler->windowTime;
pResampler->windowTime -= framesToConsume; pResampler->windowTime -= framesToConsume;
pResampler->cacheLengthInFrames -= framesToConsume; pResampler->cacheLengthInFrames -= framesToConsume;
if (pResampler->config.format == mal_format_f32) { if (pResampler->config.format == ma_format_f32) {
for (mal_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { for (ma_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) {
for (mal_uint32 iFrame = 0; iFrame < pResampler->cacheLengthInFrames; ++iFrame) { for (ma_uint32 iFrame = 0; iFrame < pResampler->cacheLengthInFrames; ++iFrame) {
pResampler->cache.f32[pResampler->cacheStrideInFrames*iChannel + iFrame] = pResampler->cache.f32[pResampler->cacheStrideInFrames*iChannel + iFrame + framesToConsume]; pResampler->cache.f32[pResampler->cacheStrideInFrames*iChannel + iFrame] = pResampler->cache.f32[pResampler->cacheStrideInFrames*iChannel + iFrame + framesToConsume];
} }
} }
} else { } else {
for (mal_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { for (ma_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) {
for (mal_uint32 iFrame = 0; iFrame < pResampler->cacheLengthInFrames; ++iFrame) { for (ma_uint32 iFrame = 0; iFrame < pResampler->cacheLengthInFrames; ++iFrame) {
pResampler->cache.s16[pResampler->cacheStrideInFrames*iChannel + iFrame] = pResampler->cache.s16[pResampler->cacheStrideInFrames*iChannel + iFrame + framesToConsume]; 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 ...@@ -350,30 +350,30 @@ static MA_INLINE mal_result mal_resampler__slide_cache_down(mal_resampler* pResa
typedef union typedef union
{ {
float* f32[MA_MAX_CHANNELS]; float* f32[MA_MAX_CHANNELS];
mal_int16* s16[MA_MAX_CHANNELS]; ma_int16* s16[MA_MAX_CHANNELS];
} mal_resampler_deinterleaved_pointers; } ma_resampler_deinterleaved_pointers;
typedef union typedef union
{ {
float* f32; float* f32;
mal_int16* s16; ma_int16* s16;
} mal_resampler_interleaved_pointers; } 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 */ /* When reloading the buffer there's a specific rule to keep into consideration. When the client */
mal_result result; ma_result result;
mal_uint32 framesToReadFromClient; ma_uint32 framesToReadFromClient;
mal_uint32 framesReadFromClient; ma_uint32 framesReadFromClient;
mal_bool32 loadedEndOfInput = MA_FALSE; ma_bool32 loadedEndOfInput = MA_FALSE;
mal_assert(pLoadedEndOfInput != NULL); ma_assert(pLoadedEndOfInput != NULL);
mal_assert(pResampler->windowTime < 65536); ma_assert(pResampler->windowTime < 65536);
mal_assert(pResampler->windowTime <= pResampler->cacheLengthInFrames); ma_assert(pResampler->windowTime <= pResampler->cacheLengthInFrames);
/* Before loading anything from the client we need to move anything left in the cache down the front. */ /* 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) { if (result != MA_SUCCESS) {
return result; /* Should never actually happen. */ return result; /* Should never actually happen. */
} }
...@@ -383,67 +383,67 @@ mal_result mal_resampler__reload_cache(mal_resampler* pResampler, mal_bool32* pL ...@@ -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 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. to the size of the right side of the filter window.
*/ */
if (pResampler->config.format == mal_format_f32) { if (pResampler->config.format == ma_format_f32) {
framesToReadFromClient = pResampler->cacheStrideInFrames - mal_resampler__window_length_right(pResampler) - pResampler->cacheLengthInFrames; framesToReadFromClient = pResampler->cacheStrideInFrames - ma_resampler__window_length_right(pResampler) - pResampler->cacheLengthInFrames;
} else { } 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. */ /* 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; ma_resampler_deinterleaved_pointers clientDst;
if (pResampler->config.format == mal_format_f32) { if (pResampler->config.format == ma_format_f32) {
for (mal_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { for (ma_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) {
clientDst.f32[iChannel] = pResampler->cache.f32 + (pResampler->cacheStrideInFrames*iChannel + pResampler->cacheLengthInFrames); 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); framesReadFromClient = pResampler->config.onRead(pResampler, framesToReadFromClient, clientDst.f32);
} else { } else {
float buffer[mal_countof(pResampler->cache.f32)]; float buffer[ma_countof(pResampler->cache.f32)];
float* pInterleavedFrames = buffer; float* pInterleavedFrames = buffer;
framesReadFromClient = pResampler->config.onRead(pResampler, framesToReadFromClient, &pInterleavedFrames); 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 { } 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); 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); framesReadFromClient = pResampler->config.onRead(pResampler, framesToReadFromClient, clientDst.s16);
} else { } else {
mal_int16 buffer[mal_countof(pResampler->cache.s16)]; ma_int16 buffer[ma_countof(pResampler->cache.s16)];
mal_int16* pInterleavedFrames = buffer; ma_int16* pInterleavedFrames = buffer;
framesReadFromClient = pResampler->config.onRead(pResampler, framesToReadFromClient, &pInterleavedFrames); 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) { 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. */ /* 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; loadedEndOfInput = MA_TRUE;
*pLoadedEndOfInput = loadedEndOfInput; *pLoadedEndOfInput = loadedEndOfInput;
} }
mal_assert(framesReadFromClient <= 65535); ma_assert(framesReadFromClient <= 65535);
pResampler->cacheLengthInFrames += (mal_uint16)framesReadFromClient; 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 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 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. of the right side of the filter window.
*/ */
if (loadedEndOfInput && pResampler->config.endOfInputMode == mal_resampler_end_of_input_mode_consume) { if (loadedEndOfInput && pResampler->config.endOfInputMode == ma_resampler_end_of_input_mode_consume) {
mal_uint16 paddingLengthInFrames = mal_resampler__window_length_right(pResampler); ma_uint16 paddingLengthInFrames = ma_resampler__window_length_right(pResampler);
if (paddingLengthInFrames > 0) { if (paddingLengthInFrames > 0) {
if (pResampler->config.format == mal_format_f32) { if (pResampler->config.format == ma_format_f32) {
for (mal_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { for (ma_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) {
mal_zero_memory(pResampler->cache.f32 + (pResampler->cacheStrideInFrames*iChannel + pResampler->cacheLengthInFrames), paddingLengthInFrames*sizeof(float)); ma_zero_memory(pResampler->cache.f32 + (pResampler->cacheStrideInFrames*iChannel + pResampler->cacheLengthInFrames), paddingLengthInFrames*sizeof(float));
} }
} else { } else {
for (mal_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { for (ma_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) {
mal_zero_memory(pResampler->cache.s16 + (pResampler->cacheStrideInFrames*iChannel + pResampler->cacheLengthInFrames), paddingLengthInFrames*sizeof(mal_int16)); 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 ...@@ -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) { if (pResampler == NULL) {
return MA_INVALID_ARGS; return MA_INVALID_ARGS;
} }
mal_zero_object(pResampler); ma_zero_object(pResampler);
if (pConfig == NULL) { if (pConfig == NULL) {
return MA_INVALID_ARGS; return MA_INVALID_ARGS;
} }
pResampler->config = *pConfig; 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. */ return MA_INVALID_ARGS; /* Unsupported format. */
} }
if (pResampler->config.channels == 0) { if (pResampler->config.channels == 0) {
...@@ -484,31 +484,31 @@ mal_result mal_resampler_init(const mal_resampler_config* pConfig, mal_resampler ...@@ -484,31 +484,31 @@ mal_result mal_resampler_init(const mal_resampler_config* pConfig, mal_resampler
} }
switch (pResampler->config.algorithm) { switch (pResampler->config.algorithm) {
case mal_resampler_algorithm_linear: case ma_resampler_algorithm_linear:
{ {
pResampler->init = mal_resampler_init__linear; pResampler->init = ma_resampler_init__linear;
pResampler->readF32 = mal_resampler_read_f32__linear; pResampler->readF32 = ma_resampler_read_f32__linear;
pResampler->readS16 = mal_resampler_read_s16__linear; pResampler->readS16 = ma_resampler_read_s16__linear;
pResampler->seek = mal_resampler_seek__linear; pResampler->seek = ma_resampler_seek__linear;
} break; } break;
case mal_resampler_algorithm_sinc: case ma_resampler_algorithm_sinc:
{ {
pResampler->init = mal_resampler_init__sinc; pResampler->init = ma_resampler_init__sinc;
pResampler->readF32 = mal_resampler_read_f32__sinc; pResampler->readF32 = ma_resampler_read_f32__sinc;
pResampler->readS16 = mal_resampler_read_s16__sinc; pResampler->readS16 = ma_resampler_read_s16__sinc;
pResampler->seek = mal_resampler_seek__sinc; pResampler->seek = ma_resampler_seek__sinc;
} break; } break;
} }
if (pResampler->config.format == mal_format_f32) { if (pResampler->config.format == ma_format_f32) {
pResampler->cacheStrideInFrames = mal_countof(pResampler->cache.f32) / pResampler->config.channels; pResampler->cacheStrideInFrames = ma_countof(pResampler->cache.f32) / pResampler->config.channels;
} else { } 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) { if (pResampler->init != NULL) {
mal_result result = pResampler->init(pResampler); ma_result result = pResampler->init(pResampler);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
return result; return result;
} }
...@@ -516,19 +516,19 @@ mal_result mal_resampler_init(const mal_resampler_config* pConfig, mal_resampler ...@@ -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 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; return MA_SUCCESS;
} }
void mal_resampler_uninit(mal_resampler* pResampler) void ma_resampler_uninit(ma_resampler* pResampler)
{ {
(void)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) { if (pResampler == NULL) {
return MA_INVALID_ARGS; return MA_INVALID_ARGS;
...@@ -550,7 +550,7 @@ mal_result mal_resampler_set_rate(mal_resampler* pResampler, mal_uint32 sampleRa ...@@ -550,7 +550,7 @@ mal_result mal_resampler_set_rate(mal_resampler* pResampler, mal_uint32 sampleRa
return MA_SUCCESS; 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) { if (pResampler == NULL) {
return MA_INVALID_ARGS; return MA_INVALID_ARGS;
...@@ -565,13 +565,13 @@ mal_result mal_resampler_set_rate_ratio(mal_resampler* pResampler, double ratio) ...@@ -565,13 +565,13 @@ mal_result mal_resampler_set_rate_ratio(mal_resampler* pResampler, double ratio)
return MA_SUCCESS; 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; ma_result result;
mal_uint64 totalFramesRead; ma_uint64 totalFramesRead;
mal_resampler_deinterleaved_pointers runningFramesOutDeinterleaved; ma_resampler_deinterleaved_pointers runningFramesOutDeinterleaved;
mal_resampler_interleaved_pointers runningFramesOutInterleaved; ma_resampler_interleaved_pointers runningFramesOutInterleaved;
mal_bool32 loadedEndOfInput = MA_FALSE; ma_bool32 loadedEndOfInput = MA_FALSE;
if (pResampler == NULL) { if (pResampler == NULL) {
return 0; /* Invalid arguments. */ return 0; /* Invalid arguments. */
...@@ -583,20 +583,20 @@ mal_uint64 mal_resampler_read(mal_resampler* pResampler, mal_uint64 frameCount, ...@@ -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. */ /* When ppFrames is NULL, reading is equivalent to seeking with default options. */
if (ppFrames == NULL) { if (ppFrames == NULL) {
return mal_resampler_seek(pResampler, frameCount, 0); return ma_resampler_seek(pResampler, frameCount, 0);
} }
if (pResampler->config.format == mal_format_f32) { if (pResampler->config.format == ma_format_f32) {
mal_assert(pResampler->readF32 != NULL); ma_assert(pResampler->readF32 != NULL);
} else { } else {
mal_assert(pResampler->readS16 != NULL); ma_assert(pResampler->readS16 != NULL);
} }
/* Initialization of the running frame pointers. */ /* Initialization of the running frame pointers. */
if (pResampler->config.layout == mal_stream_layout_deinterleaved) { if (pResampler->config.layout == ma_stream_layout_deinterleaved) {
for (mal_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { for (ma_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) {
runningFramesOutDeinterleaved.f32[iChannel] = (float*)ppFrames[iChannel]; runningFramesOutDeinterleaved.f32[iChannel] = (float*)ppFrames[iChannel];
} }
runningFramesOutInterleaved.f32 = NULL; /* Silences a warning. */ runningFramesOutInterleaved.f32 = NULL; /* Silences a warning. */
...@@ -613,46 +613,46 @@ mal_uint64 mal_resampler_read(mal_resampler* pResampler, mal_uint64 frameCount, ...@@ -613,46 +613,46 @@ mal_uint64 mal_resampler_read(mal_resampler* pResampler, mal_uint64 frameCount,
totalFramesRead = 0; totalFramesRead = 0;
while (totalFramesRead < frameCount) { while (totalFramesRead < frameCount) {
double cachedOutputTime; double cachedOutputTime;
mal_uint64 framesRemaining = frameCount - totalFramesRead; ma_uint64 framesRemaining = frameCount - totalFramesRead;
mal_uint64 framesToReadRightNow = framesRemaining; ma_uint64 framesToReadRightNow = framesRemaining;
/* We need to make sure we don't read more than what's already in the buffer at a time. */ /* 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 (cachedOutputTime > 0) {
if (framesRemaining > cachedOutputTime) { 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 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. 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 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. the right side of the filter window.
*/ */
mal_uint16 iFirstSample = (mal_uint16)pResampler->windowTime + mal_resampler__window_length_left(pResampler); ma_uint16 iFirstSample = (ma_uint16)pResampler->windowTime + ma_resampler__window_length_left(pResampler);
if (pResampler->config.format == mal_format_f32) { if (pResampler->config.format == ma_format_f32) {
for (mal_uint16 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { for (ma_uint16 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) {
if (pResampler->config.layout == mal_stream_layout_deinterleaved) { if (pResampler->config.layout == ma_stream_layout_deinterleaved) {
for (mal_uint16 iFrame = 0; iFrame < framesToReadRightNow; ++iFrame) { for (ma_uint16 iFrame = 0; iFrame < framesToReadRightNow; ++iFrame) {
runningFramesOutDeinterleaved.f32[iChannel][iFrame] = pResampler->cache.f32[pResampler->cacheStrideInFrames*iChannel + iFirstSample + iFrame]; runningFramesOutDeinterleaved.f32[iChannel][iFrame] = pResampler->cache.f32[pResampler->cacheStrideInFrames*iChannel + iFirstSample + iFrame];
} }
} else { } 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]; runningFramesOutInterleaved.f32[iFrame*pResampler->config.channels + iChannel] = pResampler->cache.f32[pResampler->cacheStrideInFrames*iChannel + iFirstSample + iFrame];
} }
} }
} }
} else { } else {
for (mal_uint16 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { for (ma_uint16 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) {
if (pResampler->config.layout == mal_stream_layout_deinterleaved) { if (pResampler->config.layout == ma_stream_layout_deinterleaved) {
for (mal_uint16 iFrame = 0; iFrame < framesToReadRightNow; ++iFrame) { for (ma_uint16 iFrame = 0; iFrame < framesToReadRightNow; ++iFrame) {
runningFramesOutDeinterleaved.s16[iChannel][iFrame] = pResampler->cache.s16[pResampler->cacheStrideInFrames*iChannel + iFirstSample + iFrame]; runningFramesOutDeinterleaved.s16[iChannel][iFrame] = pResampler->cache.s16[pResampler->cacheStrideInFrames*iChannel + iFirstSample + iFrame];
} }
} else { } 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]; 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, ...@@ -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 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. is set to deinterleaved, we need to read into a temporary buffer and then interleave.
*/ */
mal_uint64 framesJustRead; ma_uint64 framesJustRead;
if (pResampler->config.format == mal_format_f32) { if (pResampler->config.format == ma_format_f32) {
if (pResampler->config.layout == mal_stream_layout_deinterleaved) { if (pResampler->config.layout == ma_stream_layout_deinterleaved) {
framesJustRead = pResampler->readF32(pResampler, framesToReadRightNow, runningFramesOutDeinterleaved.f32); framesJustRead = pResampler->readF32(pResampler, framesToReadRightNow, runningFramesOutDeinterleaved.f32);
} else { } else {
float buffer[mal_countof(pResampler->cache.f32)]; float buffer[ma_countof(pResampler->cache.f32)];
float* ppDeinterleavedFrames[MA_MAX_CHANNELS]; 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); ppDeinterleavedFrames[iChannel] = buffer + (pResampler->cacheStrideInFrames*iChannel);
} }
framesJustRead = pResampler->readF32(pResampler, framesToReadRightNow, ppDeinterleavedFrames); 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 { } else {
if (pResampler->config.layout == mal_stream_layout_interleaved) { if (pResampler->config.layout == ma_stream_layout_interleaved) {
framesJustRead = pResampler->readS16(pResampler, framesToReadRightNow, runningFramesOutDeinterleaved.s16); framesJustRead = pResampler->readS16(pResampler, framesToReadRightNow, runningFramesOutDeinterleaved.s16);
} else { } else {
mal_int16 buffer[mal_countof(pResampler->cache.s16)]; ma_int16 buffer[ma_countof(pResampler->cache.s16)];
mal_int16* ppDeinterleavedFrames[MA_MAX_CHANNELS]; ma_int16* 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); ppDeinterleavedFrames[iChannel] = buffer + (pResampler->cacheStrideInFrames*iChannel);
} }
framesJustRead = pResampler->readS16(pResampler, framesToReadRightNow, ppDeinterleavedFrames); 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) { if (framesJustRead != framesToReadRightNow) {
mal_assert(MA_FALSE); ma_assert(MA_FALSE);
break; /* Should never hit this. */ break; /* Should never hit this. */
} }
} }
...@@ -701,17 +701,17 @@ mal_uint64 mal_resampler_read(mal_resampler* pResampler, mal_uint64 frameCount, ...@@ -701,17 +701,17 @@ mal_uint64 mal_resampler_read(mal_resampler* pResampler, mal_uint64 frameCount,
/* Move time forward. */ /* Move time forward. */
pResampler->windowTime += (framesToReadRightNow * pResampler->config.ratio); pResampler->windowTime += (framesToReadRightNow * pResampler->config.ratio);
if (pResampler->config.format == mal_format_f32) { if (pResampler->config.format == ma_format_f32) {
if (pResampler->config.layout == mal_stream_layout_deinterleaved) { if (pResampler->config.layout == ma_stream_layout_deinterleaved) {
for (mal_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { for (ma_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) {
runningFramesOutDeinterleaved.f32[iChannel] += framesToReadRightNow; runningFramesOutDeinterleaved.f32[iChannel] += framesToReadRightNow;
} }
} else { } else {
runningFramesOutInterleaved.f32 += framesToReadRightNow * pResampler->config.channels; runningFramesOutInterleaved.f32 += framesToReadRightNow * pResampler->config.channels;
} }
} else { } else {
if (pResampler->config.layout == mal_stream_layout_deinterleaved) { if (pResampler->config.layout == ma_stream_layout_deinterleaved) {
for (mal_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) { for (ma_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) {
runningFramesOutDeinterleaved.s16[iChannel] += framesToReadRightNow; runningFramesOutDeinterleaved.s16[iChannel] += framesToReadRightNow;
} }
} else { } else {
...@@ -739,7 +739,7 @@ mal_uint64 mal_resampler_read(mal_resampler* pResampler, mal_uint64 frameCount, ...@@ -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 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. 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) { 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. */ 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, ...@@ -748,9 +748,9 @@ mal_uint64 mal_resampler_read(mal_resampler* pResampler, mal_uint64 frameCount,
return totalFramesRead; 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) { if (pResampler == NULL) {
return 0; /* Invalid args. */ return 0; /* Invalid args. */
...@@ -770,7 +770,7 @@ mal_uint64 mal_resampler_seek(mal_resampler* pResampler, mal_uint64 frameCount, ...@@ -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 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. 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; totalFramesSeeked = frameCount;
} else { } else {
/* We need to read from the client which means we need to loop. */ /* 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, ...@@ -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) { if (pResampler == NULL) {
return 0; /* Invalid args. */ 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) { if (pResampler == NULL) {
return 0; /* Invalid args. */ 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) { if (pResampler == NULL) {
return 0; /* Invalid args. */ return 0; /* Invalid args. */
...@@ -832,7 +832,7 @@ mal_uint64 mal_resampler_get_required_input_frame_count(mal_resampler* pResample ...@@ -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. */ /* 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) { if (cachedOutputTime >= outputFrameCount) {
return 0; /* All of the necessary input data is cached. No additional data is required from the client. */ 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 ...@@ -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. The return value must always be larger than 0 after this point. If it's not we have an error.
*/ */
double nonCachedOutputTime = outputFrameCount - cachedOutputTime; double nonCachedOutputTime = outputFrameCount - cachedOutputTime;
mal_assert(nonCachedOutputTime > 0); ma_assert(nonCachedOutputTime > 0);
mal_uint64 requiredInputFrames = (mal_uint64)ceil(nonCachedOutputTime * pResampler->config.ratio); ma_uint64 requiredInputFrames = (ma_uint64)ceil(nonCachedOutputTime * pResampler->config.ratio);
mal_assert(requiredInputFrames > 0); ma_assert(requiredInputFrames > 0);
return requiredInputFrames; 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) { if (pResampler == NULL) {
return 0; /* Invalid args. */ return 0; /* Invalid args. */
...@@ -865,17 +865,17 @@ mal_uint64 mal_resampler_get_expected_output_frame_count(mal_resampler* pResampl ...@@ -865,17 +865,17 @@ mal_uint64 mal_resampler_get_expected_output_frame_count(mal_resampler* pResampl
return 0; 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(). */ /* 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 (mal_uint64)floor((mal_resampler__calculate_cached_input_time(pResampler) + inputFrameCount) / pResampler->config.ratio); return (ma_uint64)floor((ma_resampler__calculate_cached_input_time(pResampler) + inputFrameCount) / pResampler->config.ratio);
} }
/* /*
Linear 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. */ /* The linear implementation always has a window length of 2. */
pResampler->windowLength = 2; pResampler->windowLength = 2;
...@@ -883,12 +883,12 @@ mal_result mal_resampler_init__linear(mal_resampler* pResampler) ...@@ -883,12 +883,12 @@ mal_result mal_resampler_init__linear(mal_resampler* pResampler)
return MA_SUCCESS; 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); ma_assert(pResampler != NULL);
mal_assert(pResampler->config.onRead != NULL); ma_assert(pResampler->config.onRead != NULL);
mal_assert(frameCount > 0); ma_assert(frameCount > 0);
mal_assert(ppFrames != NULL); ma_assert(ppFrames != NULL);
/* TODO: Implement me. */ /* TODO: Implement me. */
(void)pResampler; (void)pResampler;
...@@ -897,36 +897,36 @@ mal_uint64 mal_resampler_read_f32__linear(mal_resampler* pResampler, mal_uint64 ...@@ -897,36 +897,36 @@ mal_uint64 mal_resampler_read_f32__linear(mal_resampler* pResampler, mal_uint64
return 0; 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); ma_assert(pResampler != NULL);
mal_assert(pResampler->config.onRead != NULL); ma_assert(pResampler->config.onRead != NULL);
mal_assert(frameCount > 0); ma_assert(frameCount > 0);
mal_assert(ppFrames != NULL); ma_assert(ppFrames != NULL);
/* TODO: Implement an s16 optimized implementation. */ /* 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. */ /* 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]; 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); 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) { for (ma_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. */ ma_pcm_f32_to_s16(ppFrames[iChannel], ppFramesF32[iChannel], frameCount, ma_dither_mode_none); /* No dithering - keep it fast for linear. */
} }
return framesRead; 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); ma_assert(pResampler != NULL);
mal_assert(pResampler->config.onRead != NULL); ma_assert(pResampler->config.onRead != NULL);
mal_assert(frameCount > 0); ma_assert(frameCount > 0);
/* TODO: Implement me. */ /* TODO: Implement me. */
(void)pResampler; (void)pResampler;
...@@ -939,20 +939,20 @@ mal_uint64 mal_resampler_seek__linear(mal_resampler* pResampler, mal_uint64 fram ...@@ -939,20 +939,20 @@ mal_uint64 mal_resampler_seek__linear(mal_resampler* pResampler, mal_uint64 fram
/* /*
Sinc 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. */ /* TODO: Implement me. Need to initialize the sinc table. */
return MA_SUCCESS; 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); ma_assert(pResampler != NULL);
mal_assert(pResampler->config.onRead != NULL); ma_assert(pResampler->config.onRead != NULL);
mal_assert(frameCount > 0); ma_assert(frameCount > 0);
mal_assert(ppFrames != NULL); ma_assert(ppFrames != NULL);
/* TODO: Implement me. */ /* TODO: Implement me. */
(void)pResampler; (void)pResampler;
...@@ -961,36 +961,36 @@ mal_uint64 mal_resampler_read_f32__sinc(mal_resampler* pResampler, mal_uint64 fr ...@@ -961,36 +961,36 @@ mal_uint64 mal_resampler_read_f32__sinc(mal_resampler* pResampler, mal_uint64 fr
return 0; 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); ma_assert(pResampler != NULL);
mal_assert(pResampler->config.onRead != NULL); ma_assert(pResampler->config.onRead != NULL);
mal_assert(frameCount > 0); ma_assert(frameCount > 0);
mal_assert(ppFrames != NULL); ma_assert(ppFrames != NULL);
/* TODO: Implement an s16 optimized implementation. */ /* 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. */ /* 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]; 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); 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) { for (ma_uint32 iChannel = 0; iChannel < pResampler->config.channels; ++iChannel) {
mal_pcm_f32_to_s16(ppFrames[iChannel], ppFramesF32[iChannel], frameCount, mal_dither_mode_triangle); ma_pcm_f32_to_s16(ppFrames[iChannel], ppFramesF32[iChannel], frameCount, ma_dither_mode_triangle);
} }
return framesRead; 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); ma_assert(pResampler != NULL);
mal_assert(pResampler->config.onRead != NULL); ma_assert(pResampler->config.onRead != NULL);
mal_assert(frameCount > 0); ma_assert(frameCount > 0);
/* TODO: Implement me. */ /* TODO: Implement me. */
(void)pResampler; (void)pResampler;
......
...@@ -8,28 +8,28 @@ ...@@ -8,28 +8,28 @@
// USAGE // USAGE
// //
// - Call mal_rb_init() to initialize a simple buffer, with an optional pre-allocated buffer. If you pass in NULL // - 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 mal_rb_uninit(). If you pass in // 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. // 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 // - 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 mal_rb_get_subbuffer_stride(), mal_rb_get_subbuffer_offset() and // other based on the stride. Use ma_rb_get_subbuffer_stride(), ma_rb_get_subbuffer_offset() and
// mal_rb_get_subbuffer_ptr() to manage your sub-buffers. // 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 // 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 // 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 // clamped to the end of the buffer. Therefore, the number of bytes you're given may be less than the number
// you requested. // you requested.
// //
// - After calling mal_rb_acquire_read/write(), you do your work on the buffer and then "commit" it with // - After calling ma_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 // 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 mal_rb_acquire_read/write() and is only used // 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 mal_rb_commit_read/write() is what's used to increment the // for validation. The number of bytes passed to ma_rb_commit_read/write() is what's used to increment the
// pointers. // pointers.
// //
// - If you want to correct for drift between the write pointer and the read pointer you can use a combination // - 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 // 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 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. // pointer forward. If there is too little space between the pointers, move the write pointer forward.
...@@ -45,99 +45,99 @@ ...@@ -45,99 +45,99 @@
// - Operates on bytes. May end up adding to higher level helpers for doing everything per audio frame. // - 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. // - Maximum buffer size is 0x7FFFFFFF-(MA_SIMD_ALIGNMENT-1) because of reasons.
#ifndef mal_ring_buffer_h #ifndef ma_ring_buffer_h
#define mal_ring_buffer_h #define ma_ring_buffer_h
typedef struct typedef struct
{ {
void* pBuffer; void* pBuffer;
mal_uint32 subbufferSizeInBytes; ma_uint32 subbufferSizeInBytes;
mal_uint32 subbufferCount; ma_uint32 subbufferCount;
mal_uint32 subbufferStrideInBytes; ma_uint32 subbufferStrideInBytes;
volatile mal_uint32 encodedReadOffset; /* Most significant bit is the loop flag. Lower 31 bits contains the actual offset in bytes. */ volatile ma_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. */ volatile ma_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. */ ma_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(). */ ma_bool32 clearOnWriteAcquire : 1; /* When set, clears the acquired write buffer before returning from ma_rb_acquire_write(). */
} mal_rb; } ma_rb;
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);
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);
void mal_rb_uninit(mal_rb* pRB); void ma_rb_uninit(ma_rb* pRB);
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);
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);
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);
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);
mal_result mal_rb_seek_read(mal_rb* pRB, size_t offsetInBytes); ma_result ma_rb_seek_read(ma_rb* pRB, size_t offsetInBytes);
mal_result mal_rb_seek_write(mal_rb* pRB, size_t offsetInBytes); ma_result ma_rb_seek_write(ma_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. */ 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 mal_rb_get_subbuffer_stride(mal_rb* pRB); size_t ma_rb_get_subbuffer_stride(ma_rb* pRB);
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);
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);
typedef struct typedef struct
{ {
mal_rb rb; ma_rb rb;
mal_format format; ma_format format;
mal_uint32 channels; ma_uint32 channels;
} mal_pcm_rb; } 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); 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);
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);
void mal_pcm_rb_uninit(mal_pcm_rb* pRB); void ma_pcm_rb_uninit(ma_pcm_rb* pRB);
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);
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);
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);
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);
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);
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);
mal_int32 mal_pcm_rb_pointer_disance(mal_pcm_rb* pRB); /* Return value is in frames. */ ma_int32 ma_pcm_rb_pointer_disance(ma_pcm_rb* pRB); /* Return value is in frames. */
size_t mal_pcm_rb_get_subbuffer_stride(mal_pcm_rb* pRB); size_t ma_pcm_rb_get_subbuffer_stride(ma_pcm_rb* 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);
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);
#endif // mal_ring_buffer_h #endif // ma_ring_buffer_h
#ifdef MINIAUDIO_IMPLEMENTATION #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; 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; 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); ma_assert(pRB != NULL);
return mal_offset_ptr(pRB->pBuffer, mal_rb__extract_offset_in_bytes(pRB->encodedReadOffset)); 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); ma_assert(pRB != NULL);
return mal_offset_ptr(pRB->pBuffer, mal_rb__extract_offset_in_bytes(pRB->encodedWriteOffset)); 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; 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); ma_assert(pOffsetInBytes != NULL);
mal_assert(pOffsetLoopFlag != NULL); ma_assert(pOffsetLoopFlag != NULL);
*pOffsetInBytes = mal_rb__extract_offset_in_bytes(encodedOffset); *pOffsetInBytes = ma_rb__extract_offset_in_bytes(encodedOffset);
*pOffsetLoopFlag = mal_rb__extract_offset_loop_flag(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) { if (pRB == NULL) {
return MA_INVALID_ARGS; return MA_INVALID_ARGS;
...@@ -147,18 +147,18 @@ mal_result mal_rb_init_ex(size_t subbufferSizeInBytes, size_t subbufferCount, si ...@@ -147,18 +147,18 @@ mal_result mal_rb_init_ex(size_t subbufferSizeInBytes, size_t subbufferCount, si
return MA_INVALID_ARGS; 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) { if (subbufferSizeInBytes > maxSubBufferSize) {
return MA_INVALID_ARGS; // Maximum buffer size is ~2GB. The most significant bit is a flag for use internally. return MA_INVALID_ARGS; // Maximum buffer size is ~2GB. The most significant bit is a flag for use internally.
} }
mal_zero_object(pRB); ma_zero_object(pRB);
pRB->subbufferSizeInBytes = (mal_uint32)subbufferSizeInBytes; pRB->subbufferSizeInBytes = (ma_uint32)subbufferSizeInBytes;
pRB->subbufferCount = (mal_uint32)subbufferCount; pRB->subbufferCount = (ma_uint32)subbufferCount;
if (pOptionalPreallocatedBuffer != NULL) { if (pOptionalPreallocatedBuffer != NULL) {
pRB->subbufferStrideInBytes = (mal_uint32)subbufferStrideInBytes; pRB->subbufferStrideInBytes = (ma_uint32)subbufferStrideInBytes;
pRB->pBuffer = pOptionalPreallocatedBuffer; pRB->pBuffer = pOptionalPreallocatedBuffer;
} else { } 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 // 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 ...@@ -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; pRB->subbufferStrideInBytes = (pRB->subbufferSizeInBytes + (MA_SIMD_ALIGNMENT-1)) & ~MA_SIMD_ALIGNMENT;
size_t bufferSizeInBytes = (size_t)pRB->subbufferCount*pRB->subbufferStrideInBytes; 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) { if (pRB->pBuffer == NULL) {
return MA_OUT_OF_MEMORY; return MA_OUT_OF_MEMORY;
} }
mal_zero_memory(pRB->pBuffer, bufferSizeInBytes); ma_zero_memory(pRB->pBuffer, bufferSizeInBytes);
pRB->ownsBuffer = MA_TRUE; pRB->ownsBuffer = MA_TRUE;
} }
return MA_SUCCESS; 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) { if (pRB == NULL) {
return; return;
} }
if (pRB->ownsBuffer) { 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) { if (pRB == NULL || pSizeInBytes == NULL || ppBufferOut == NULL) {
return MA_INVALID_ARGS; return MA_INVALID_ARGS;
} }
// The returned buffer should never move ahead of the write pointer. // The returned buffer should never move ahead of the write pointer.
mal_uint32 writeOffset = pRB->encodedWriteOffset; ma_uint32 writeOffset = pRB->encodedWriteOffset;
mal_uint32 writeOffsetInBytes; ma_uint32 writeOffsetInBytes;
mal_uint32 writeOffsetLoopFlag; ma_uint32 writeOffsetLoopFlag;
mal_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag); ma_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag);
mal_uint32 readOffset = pRB->encodedReadOffset; ma_uint32 readOffset = pRB->encodedReadOffset;
mal_uint32 readOffsetInBytes; ma_uint32 readOffsetInBytes;
mal_uint32 readOffsetLoopFlag; ma_uint32 readOffsetLoopFlag;
mal_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &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 // 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. // 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 ...@@ -226,60 +226,60 @@ mal_result mal_rb_acquire_read(mal_rb* pRB, size_t* pSizeInBytes, void** ppBuffe
} }
*pSizeInBytes = bytesRequested; *pSizeInBytes = bytesRequested;
(*ppBufferOut) = mal_rb__get_read_ptr(pRB); (*ppBufferOut) = ma_rb__get_read_ptr(pRB);
return MA_SUCCESS; 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) { if (pRB == NULL) {
return MA_INVALID_ARGS; return MA_INVALID_ARGS;
} }
// Validate the buffer. // Validate the buffer.
if (pBufferOut != mal_rb__get_read_ptr(pRB)) { if (pBufferOut != ma_rb__get_read_ptr(pRB)) {
return MA_INVALID_ARGS; return MA_INVALID_ARGS;
} }
mal_uint32 readOffset = pRB->encodedReadOffset; ma_uint32 readOffset = pRB->encodedReadOffset;
mal_uint32 readOffsetInBytes; ma_uint32 readOffsetInBytes;
mal_uint32 readOffsetLoopFlag; ma_uint32 readOffsetLoopFlag;
mal_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag); ma_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag);
// Check that sizeInBytes is correct. It should never go beyond the end of the buffer. // 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) { if (newReadOffsetInBytes > pRB->subbufferSizeInBytes) {
return MA_INVALID_ARGS; // <-- sizeInBytes will cause the read offset to overflow. return MA_INVALID_ARGS; // <-- sizeInBytes will cause the read offset to overflow.
} }
// Move the read pointer back to the start if necessary. // Move the read pointer back to the start if necessary.
mal_uint32 newReadOffsetLoopFlag = readOffsetLoopFlag; ma_uint32 newReadOffsetLoopFlag = readOffsetLoopFlag;
if (newReadOffsetInBytes == pRB->subbufferSizeInBytes) { if (newReadOffsetInBytes == pRB->subbufferSizeInBytes) {
newReadOffsetInBytes = 0; newReadOffsetInBytes = 0;
newReadOffsetLoopFlag ^= 0x80000000; 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; 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) { if (pRB == NULL || pSizeInBytes == NULL || ppBufferOut == NULL) {
return MA_INVALID_ARGS; return MA_INVALID_ARGS;
} }
// The returned buffer should never overtake the read buffer. // The returned buffer should never overtake the read buffer.
mal_uint32 readOffset = pRB->encodedReadOffset; ma_uint32 readOffset = pRB->encodedReadOffset;
mal_uint32 readOffsetInBytes; ma_uint32 readOffsetInBytes;
mal_uint32 readOffsetLoopFlag; ma_uint32 readOffsetLoopFlag;
mal_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag); ma_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag);
mal_uint32 writeOffset = pRB->encodedWriteOffset; ma_uint32 writeOffset = pRB->encodedWriteOffset;
mal_uint32 writeOffsetInBytes; ma_uint32 writeOffsetInBytes;
mal_uint32 writeOffsetLoopFlag; ma_uint32 writeOffsetLoopFlag;
mal_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &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 // 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 // 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 ...@@ -297,144 +297,144 @@ mal_result mal_rb_acquire_write(mal_rb* pRB, size_t* pSizeInBytes, void** ppBuff
} }
*pSizeInBytes = bytesRequested; *pSizeInBytes = bytesRequested;
*ppBufferOut = mal_rb__get_write_ptr(pRB); *ppBufferOut = ma_rb__get_write_ptr(pRB);
// Clear the buffer if desired. // Clear the buffer if desired.
if (pRB->clearOnWriteAcquire) { if (pRB->clearOnWriteAcquire) {
mal_zero_memory(*ppBufferOut, *pSizeInBytes); ma_zero_memory(*ppBufferOut, *pSizeInBytes);
} }
return MA_SUCCESS; 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) { if (pRB == NULL) {
return MA_INVALID_ARGS; return MA_INVALID_ARGS;
} }
// Validate the buffer. // Validate the buffer.
if (pBufferOut != mal_rb__get_write_ptr(pRB)) { if (pBufferOut != ma_rb__get_write_ptr(pRB)) {
return MA_INVALID_ARGS; return MA_INVALID_ARGS;
} }
mal_uint32 writeOffset = pRB->encodedWriteOffset; ma_uint32 writeOffset = pRB->encodedWriteOffset;
mal_uint32 writeOffsetInBytes; ma_uint32 writeOffsetInBytes;
mal_uint32 writeOffsetLoopFlag; ma_uint32 writeOffsetLoopFlag;
mal_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag); ma_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag);
// Check that sizeInBytes is correct. It should never go beyond the end of the buffer. // 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) { if (newWriteOffsetInBytes > pRB->subbufferSizeInBytes) {
return MA_INVALID_ARGS; // <-- sizeInBytes will cause the read offset to overflow. return MA_INVALID_ARGS; // <-- sizeInBytes will cause the read offset to overflow.
} }
// Move the read pointer back to the start if necessary. // Move the read pointer back to the start if necessary.
mal_uint32 newWriteOffsetLoopFlag = writeOffsetLoopFlag; ma_uint32 newWriteOffsetLoopFlag = writeOffsetLoopFlag;
if (newWriteOffsetInBytes == pRB->subbufferSizeInBytes) { if (newWriteOffsetInBytes == pRB->subbufferSizeInBytes) {
newWriteOffsetInBytes = 0; newWriteOffsetInBytes = 0;
newWriteOffsetLoopFlag ^= 0x80000000; 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; 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) { if (pRB == NULL || offsetInBytes > pRB->subbufferSizeInBytes) {
return MA_INVALID_ARGS; return MA_INVALID_ARGS;
} }
mal_uint32 readOffset = pRB->encodedReadOffset; ma_uint32 readOffset = pRB->encodedReadOffset;
mal_uint32 readOffsetInBytes; ma_uint32 readOffsetInBytes;
mal_uint32 readOffsetLoopFlag; ma_uint32 readOffsetLoopFlag;
mal_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag); ma_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag);
mal_uint32 writeOffset = pRB->encodedWriteOffset; ma_uint32 writeOffset = pRB->encodedWriteOffset;
mal_uint32 writeOffsetInBytes; ma_uint32 writeOffsetInBytes;
mal_uint32 writeOffsetLoopFlag; ma_uint32 writeOffsetLoopFlag;
mal_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag); ma_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag);
mal_uint32 newReadOffsetInBytes = readOffsetInBytes; ma_uint32 newReadOffsetInBytes = readOffsetInBytes;
mal_uint32 newReadOffsetLoopFlag = readOffsetLoopFlag; ma_uint32 newReadOffsetLoopFlag = readOffsetLoopFlag;
// We cannot go past the write buffer. // We cannot go past the write buffer.
if (readOffsetLoopFlag == writeOffsetLoopFlag) { if (readOffsetLoopFlag == writeOffsetLoopFlag) {
if ((readOffsetInBytes + offsetInBytes) > writeOffsetInBytes) { if ((readOffsetInBytes + offsetInBytes) > writeOffsetInBytes) {
newReadOffsetInBytes = writeOffsetInBytes; newReadOffsetInBytes = writeOffsetInBytes;
} else { } else {
newReadOffsetInBytes = (mal_uint32)(readOffsetInBytes + offsetInBytes); newReadOffsetInBytes = (ma_uint32)(readOffsetInBytes + offsetInBytes);
} }
} else { } else {
// May end up looping. // May end up looping.
if ((readOffsetInBytes + offsetInBytes) >= pRB->subbufferSizeInBytes) { if ((readOffsetInBytes + offsetInBytes) >= pRB->subbufferSizeInBytes) {
newReadOffsetInBytes = (mal_uint32)(readOffsetInBytes + offsetInBytes) - pRB->subbufferSizeInBytes; newReadOffsetInBytes = (ma_uint32)(readOffsetInBytes + offsetInBytes) - pRB->subbufferSizeInBytes;
newReadOffsetLoopFlag ^= 0x80000000; /* <-- Looped. */ newReadOffsetLoopFlag ^= 0x80000000; /* <-- Looped. */
} else { } 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; 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) { if (pRB == NULL) {
return MA_INVALID_ARGS; return MA_INVALID_ARGS;
} }
mal_uint32 readOffset = pRB->encodedReadOffset; ma_uint32 readOffset = pRB->encodedReadOffset;
mal_uint32 readOffsetInBytes; ma_uint32 readOffsetInBytes;
mal_uint32 readOffsetLoopFlag; ma_uint32 readOffsetLoopFlag;
mal_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag); ma_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag);
mal_uint32 writeOffset = pRB->encodedWriteOffset; ma_uint32 writeOffset = pRB->encodedWriteOffset;
mal_uint32 writeOffsetInBytes; ma_uint32 writeOffsetInBytes;
mal_uint32 writeOffsetLoopFlag; ma_uint32 writeOffsetLoopFlag;
mal_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag); ma_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag);
mal_uint32 newWriteOffsetInBytes = writeOffsetInBytes; ma_uint32 newWriteOffsetInBytes = writeOffsetInBytes;
mal_uint32 newWriteOffsetLoopFlag = writeOffsetLoopFlag; ma_uint32 newWriteOffsetLoopFlag = writeOffsetLoopFlag;
// We cannot go past the write buffer. // We cannot go past the write buffer.
if (readOffsetLoopFlag == writeOffsetLoopFlag) { if (readOffsetLoopFlag == writeOffsetLoopFlag) {
// May end up looping. // May end up looping.
if ((writeOffsetInBytes + offsetInBytes) >= pRB->subbufferSizeInBytes) { if ((writeOffsetInBytes + offsetInBytes) >= pRB->subbufferSizeInBytes) {
newWriteOffsetInBytes = (mal_uint32)(writeOffsetInBytes + offsetInBytes) - pRB->subbufferSizeInBytes; newWriteOffsetInBytes = (ma_uint32)(writeOffsetInBytes + offsetInBytes) - pRB->subbufferSizeInBytes;
newWriteOffsetLoopFlag ^= 0x80000000; /* <-- Looped. */ newWriteOffsetLoopFlag ^= 0x80000000; /* <-- Looped. */
} else { } else {
newWriteOffsetInBytes = (mal_uint32)(writeOffsetInBytes + offsetInBytes); newWriteOffsetInBytes = (ma_uint32)(writeOffsetInBytes + offsetInBytes);
} }
} else { } else {
if ((writeOffsetInBytes + offsetInBytes) > readOffsetInBytes) { if ((writeOffsetInBytes + offsetInBytes) > readOffsetInBytes) {
newWriteOffsetInBytes = readOffsetInBytes; newWriteOffsetInBytes = readOffsetInBytes;
} else { } 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; return MA_SUCCESS;
} }
mal_int32 mal_rb_pointer_distance(mal_rb* pRB) ma_int32 ma_rb_pointer_distance(ma_rb* pRB)
{ {
if (pRB == NULL) { if (pRB == NULL) {
return 0; return 0;
} }
mal_uint32 readOffset = pRB->encodedReadOffset; ma_uint32 readOffset = pRB->encodedReadOffset;
mal_uint32 readOffsetInBytes; ma_uint32 readOffsetInBytes;
mal_uint32 readOffsetLoopFlag; ma_uint32 readOffsetLoopFlag;
mal_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag); ma_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag);
mal_uint32 writeOffset = pRB->encodedWriteOffset; ma_uint32 writeOffset = pRB->encodedWriteOffset;
mal_uint32 writeOffsetInBytes; ma_uint32 writeOffsetInBytes;
mal_uint32 writeOffsetLoopFlag; ma_uint32 writeOffsetLoopFlag;
mal_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag); ma_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag);
if (readOffsetLoopFlag == writeOffsetLoopFlag) { if (readOffsetLoopFlag == writeOffsetLoopFlag) {
return writeOffsetInBytes - readOffsetInBytes; return writeOffsetInBytes - readOffsetInBytes;
...@@ -443,7 +443,7 @@ mal_int32 mal_rb_pointer_distance(mal_rb* pRB) ...@@ -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) { if (pRB == NULL) {
return 0; return 0;
...@@ -456,48 +456,48 @@ size_t mal_rb_get_subbuffer_stride(mal_rb* pRB) ...@@ -456,48 +456,48 @@ size_t mal_rb_get_subbuffer_stride(mal_rb* pRB)
return (size_t)pRB->subbufferStrideInBytes; 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) { if (pRB == NULL) {
return 0; 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) { if (pRB == NULL) {
return 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) { if (pRB == NULL) {
return MA_INVALID_ARGS; 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) { if (bpf == 0) {
return MA_INVALID_ARGS; 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) { if (result != MA_SUCCESS) {
return result; return result;
} }
...@@ -508,130 +508,130 @@ mal_result mal_pcm_rb_init_ex(mal_format format, mal_uint32 channels, size_t sub ...@@ -508,130 +508,130 @@ mal_result mal_pcm_rb_init_ex(mal_format format, mal_uint32 channels, size_t sub
return MA_SUCCESS; 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) { if (pRB == NULL) {
return; 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; size_t sizeInBytes;
mal_result result; ma_result result;
if (pRB == NULL || pSizeInFrames == NULL) { if (pRB == NULL || pSizeInFrames == NULL) {
return MA_INVALID_ARGS; 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) { if (result != MA_SUCCESS) {
return result; return result;
} }
*pSizeInFrames = sizeInBytes / mal_pcm_rb_get_bpf(pRB); *pSizeInFrames = sizeInBytes / ma_pcm_rb_get_bpf(pRB);
return MA_SUCCESS; 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) { if (pRB == NULL) {
return MA_INVALID_ARGS; 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; size_t sizeInBytes;
mal_result result; ma_result result;
if (pRB == NULL) { if (pRB == NULL) {
return MA_INVALID_ARGS; 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) { if (result != MA_SUCCESS) {
return result; return result;
} }
*pSizeInFrames = sizeInBytes / mal_pcm_rb_get_bpf(pRB); *pSizeInFrames = sizeInBytes / ma_pcm_rb_get_bpf(pRB);
return MA_SUCCESS; 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) { if (pRB == NULL) {
return MA_INVALID_ARGS; 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) { if (pRB == NULL) {
return MA_INVALID_ARGS; 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) { if (pRB == NULL) {
return MA_INVALID_ARGS; 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) { if (pRB == NULL) {
return MA_INVALID_ARGS; 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) { if (pRB == NULL) {
return 0; 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) { if (pRB == NULL) {
return 0; 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) { if (pRB == NULL) {
return 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 #endif // MINIAUDIO_IMPLEMENTATION
...@@ -4,46 +4,46 @@ ...@@ -4,46 +4,46 @@
#define MA_DEBUG_OUTPUT #define MA_DEBUG_OUTPUT
#define MINIAUDIO_IMPLEMENTATION #define MINIAUDIO_IMPLEMENTATION
#include "../../miniaudio.h" #include "../../miniaudio.h"
#include "../mal_resampler.h" #include "../ma_resampler.h"
#define SAMPLE_RATE_IN 44100 #define SAMPLE_RATE_IN 44100
#define SAMPLE_RATE_OUT 44100 #define SAMPLE_RATE_OUT 44100
#define CHANNELS 1 #define CHANNELS 1
#define OUTPUT_FILE "output.wav" #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) int main(int argc, char** argv)
{ {
mal_result result; ma_result result;
mal_resampler_config resamplerConfig; ma_resampler_config resamplerConfig;
mal_resampler resampler; ma_resampler resampler;
mal_zero_object(&resamplerConfig); ma_zero_object(&resamplerConfig);
resamplerConfig.format = mal_format_f32; resamplerConfig.format = ma_format_f32;
resamplerConfig.channels = CHANNELS; resamplerConfig.channels = CHANNELS;
resamplerConfig.sampleRateIn = SAMPLE_RATE_IN; resamplerConfig.sampleRateIn = SAMPLE_RATE_IN;
resamplerConfig.sampleRateOut = SAMPLE_RATE_OUT; resamplerConfig.sampleRateOut = SAMPLE_RATE_OUT;
resamplerConfig.algorithm = mal_resampler_algorithm_linear; resamplerConfig.algorithm = ma_resampler_algorithm_linear;
resamplerConfig.endOfInputMode = mal_resampler_end_of_input_mode_consume; resamplerConfig.endOfInputMode = ma_resampler_end_of_input_mode_consume;
resamplerConfig.layout = mal_stream_layout_interleaved; resamplerConfig.layout = ma_stream_layout_interleaved;
resamplerConfig.onRead = on_read; resamplerConfig.onRead = on_read;
resamplerConfig.pUserData = NULL; resamplerConfig.pUserData = NULL;
result = mal_resampler_init(&resamplerConfig, &resampler); result = ma_resampler_init(&resamplerConfig, &resampler);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
printf("Failed to initialize resampler.\n"); printf("Failed to initialize resampler.\n");
return -1; 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. // 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) ...@@ -57,10 +57,10 @@ int main(int argc, char** argv)
float buffer[SAMPLE_RATE_IN*CHANNELS]; float buffer[SAMPLE_RATE_IN*CHANNELS];
float* pBuffer = buffer; float* pBuffer = buffer;
mal_uint32 iterations = 10; ma_uint32 iterations = 10;
mal_uint32 framesToReadPerIteration = mal_countof(buffer)/CHANNELS; ma_uint32 framesToReadPerIteration = ma_countof(buffer)/CHANNELS;
for (mal_uint32 i = 0; i < iterations; ++i) { for (ma_uint32 i = 0; i < iterations; ++i) {
mal_uint32 framesRead = (mal_uint32)mal_resampler_read(&resampler, framesToReadPerIteration, &pBuffer); ma_uint32 framesRead = (ma_uint32)ma_resampler_read(&resampler, framesToReadPerIteration, &pBuffer);
drwav_write(pWavWriter, framesRead*CHANNELS, buffer); drwav_write(pWavWriter, framesRead*CHANNELS, buffer);
} }
......
...@@ -2,7 +2,7 @@ Building ...@@ -2,7 +2,7 @@ Building
======== ========
Build and run these test from this folder. Example: 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 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 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 ...@@ -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 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: 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 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: running the web page locally. To test you can run with something like this:
emrun bin/mal_test_0_emscripten.html emrun bin/ma_test_0_emscripten.html
\ No newline at end of file \ No newline at end of file
cc mal_test_0.c -o ./bin/mal_test_0 -Wall -lpthread -lm cc ma_test_0.c -o ./bin/ma_test_0 -Wall -lpthread -lm
c++ mal_test_0.c -o ./bin/mal_test_0_cpp -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 cc ma_profiling.c -o ./bin/ma_profiling -Wall -lpthread -lm
c++ mal_profiling.c -o ./bin/mal_profiling_cpp -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 cc ma_dithering.c -o ./bin/ma_dithering -Wall -lpthread -lm
c++ mal_dithering.c -o ./bin/mal_dithering_cpp -Wall -lpthread -lm c++ ma_dithering.c -o ./bin/ma_dithering_cpp -Wall -lpthread -lm
emcc ./mal_test_0.c -o ./bin/mal_test_0_emscripten.html -s WASM=0 -std=c99 emcc ./ma_test_0.c -o ./bin/ma_test_0_emscripten.html -s WASM=0 -std=c99
emcc ./mal_duplex.c -o ./bin/mal_duplex.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 \ No newline at end of file
#!/bin/bash #!/bin/bash
cc mal_test_0.c -o ./bin/mal_test_0 -Wall -ldl -lpthread -lm cc ma_test_0.c -o ./bin/ma_test_0 -Wall -ldl -lpthread -lm
c++ mal_test_0.c -o ./bin/mal_test_0_cpp -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 cc ma_profiling.c -o ./bin/ma_profiling -Wall -ldl -lpthread -lm
c++ mal_profiling.c -o ./bin/mal_profiling_cpp -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 cc ma_dithering.c -o ./bin/ma_dithering -Wall -ldl -lpthread -lm
c++ mal_dithering.c -o ./bin/mal_dithering_cpp -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
cc mal_test_0.c -o ./bin/mal_test_0 -Wall -lpthread -lm cc ma_test_0.c -o ./bin/ma_test_0 -Wall -lpthread -lm
c++ mal_test_0.c -o ./bin/mal_test_0_cpp -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 cc ma_profiling.c -o ./bin/ma_profiling -Wall -lpthread -lm
c++ mal_profiling.c -o ./bin/mal_profiling_cpp -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 cc ma_dithering.c -o ./bin/ma_dithering -Wall -lpthread -lm
c++ mal_dithering.c -o ./bin/mal_dithering_cpp -Wall -lpthread -lm c++ ma_dithering.c -o ./bin/ma_dithering_cpp -Wall -lpthread -lm
#!/bin/bash #!/bin/bash
cc mal_test_0.c -o ./bin/mal_test_0 -Wall -ldl -lpthread -lm cc ma_test_0.c -o ./bin/ma_test_0 -Wall -ldl -lpthread -lm
c++ mal_test_0.c -o ./bin/mal_test_0_cpp -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 cc ma_profiling.c -o ./bin/ma_profiling -Wall -ldl -lpthread -lm -mfpu=neon -O2
c++ mal_profiling.c -o ./bin/mal_profiling_cpp -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 cc ma_dithering.c -o ./bin/ma_dithering -Wall -ldl -lpthread -lm
c++ mal_dithering.c -o ./bin/mal_dithering_cpp -Wall -ldl -lpthread -lm c++ ma_dithering.c -o ./bin/ma_dithering_cpp -Wall -ldl -lpthread -lm
\ No newline at end of file \ No newline at end of file
...@@ -4,11 +4,11 @@ SET cpp_compiler=g++ ...@@ -4,11 +4,11 @@ SET cpp_compiler=g++
SET options=-Wall SET options=-Wall
@echo on @echo on
%c_compiler% mal_test_0.c -o ./bin/mal_test_0.exe %options% %c_compiler% ma_test_0.c -o ./bin/ma_test_0.exe %options%
%cpp_compiler% mal_test_0.cpp -o ./bin/mal_test_0_cpp.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 %c_compiler% ma_profiling.c -o ./bin/ma_profiling.exe %options% -s -O2
%cpp_compiler% mal_profiling.c -o ./bin/mal_profiling_cpp.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% %c_compiler% ma_dithering.c -o ./bin/ma_dithering.exe %options%
%cpp_compiler% mal_dithering.c -o ./bin/mal_dithering_cpp.exe %options% %cpp_compiler% ma_dithering.c -o ./bin/ma_dithering_cpp.exe %options%
\ No newline at end of file \ No newline at end of file
...@@ -4,20 +4,20 @@ ...@@ -4,20 +4,20 @@
#define MINIAUDIO_IMPLEMENTATION #define MINIAUDIO_IMPLEMENTATION
#include "../miniaudio.h" #include "../miniaudio.h"
int print_context_info(mal_context* pContext) int print_context_info(ma_context* pContext)
{ {
mal_result result = MA_SUCCESS; ma_result result = MA_SUCCESS;
mal_device_info* pPlaybackDeviceInfos; ma_device_info* pPlaybackDeviceInfos;
mal_uint32 playbackDeviceCount; ma_uint32 playbackDeviceCount;
mal_device_info* pCaptureDeviceInfos; ma_device_info* pCaptureDeviceInfos;
mal_uint32 captureDeviceCount; ma_uint32 captureDeviceCount;
printf("BACKEND: %s\n", mal_get_backend_name(pContext->backend)); printf("BACKEND: %s\n", ma_get_backend_name(pContext->backend));
// Enumeration. // Enumeration.
printf(" Enumerating Devices... "); 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) { if (result == MA_SUCCESS) {
printf("Done\n"); printf("Done\n");
} else { } else {
...@@ -26,12 +26,12 @@ int print_context_info(mal_context* pContext) ...@@ -26,12 +26,12 @@ int print_context_info(mal_context* pContext)
} }
printf(" Playback Devices (%d)\n", playbackDeviceCount); 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(" %d: %s\n", iDevice, pPlaybackDeviceInfos[iDevice].name);
} }
printf(" Capture Devices (%d)\n", captureDeviceCount); 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); printf(" %d: %s\n", iDevice, pCaptureDeviceInfos[iDevice].name);
} }
} }
...@@ -40,10 +40,10 @@ int print_context_info(mal_context* pContext) ...@@ -40,10 +40,10 @@ int print_context_info(mal_context* pContext)
printf(" Getting Device Information...\n"); printf(" Getting Device Information...\n");
{ {
printf(" Playback Devices (%d)\n", playbackDeviceCount); 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(" %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) { if (result == MA_SUCCESS) {
printf(" Name: %s\n", pPlaybackDeviceInfos[iDevice].name); printf(" Name: %s\n", pPlaybackDeviceInfos[iDevice].name);
printf(" Min Channels: %d\n", pPlaybackDeviceInfos[iDevice].minChannels); printf(" Min Channels: %d\n", pPlaybackDeviceInfos[iDevice].minChannels);
...@@ -51,8 +51,8 @@ int print_context_info(mal_context* pContext) ...@@ -51,8 +51,8 @@ int print_context_info(mal_context* pContext)
printf(" Min Sample Rate: %d\n", pPlaybackDeviceInfos[iDevice].minSampleRate); printf(" Min Sample Rate: %d\n", pPlaybackDeviceInfos[iDevice].minSampleRate);
printf(" Max Sample Rate: %d\n", pPlaybackDeviceInfos[iDevice].maxSampleRate); printf(" Max Sample Rate: %d\n", pPlaybackDeviceInfos[iDevice].maxSampleRate);
printf(" Format Count: %d\n", pPlaybackDeviceInfos[iDevice].formatCount); printf(" Format Count: %d\n", pPlaybackDeviceInfos[iDevice].formatCount);
for (mal_uint32 iFormat = 0; iFormat < pPlaybackDeviceInfos[iDevice].formatCount; ++iFormat) { for (ma_uint32 iFormat = 0; iFormat < pPlaybackDeviceInfos[iDevice].formatCount; ++iFormat) {
printf(" %s\n", mal_get_format_name(pPlaybackDeviceInfos[iDevice].formats[iFormat])); printf(" %s\n", ma_get_format_name(pPlaybackDeviceInfos[iDevice].formats[iFormat]));
} }
} else { } else {
printf(" ERROR\n"); printf(" ERROR\n");
...@@ -60,10 +60,10 @@ int print_context_info(mal_context* pContext) ...@@ -60,10 +60,10 @@ int print_context_info(mal_context* pContext)
} }
printf(" Capture Devices (%d)\n", captureDeviceCount); 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); 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) { if (result == MA_SUCCESS) {
printf(" Name: %s\n", pCaptureDeviceInfos[iDevice].name); printf(" Name: %s\n", pCaptureDeviceInfos[iDevice].name);
printf(" Min Channels: %d\n", pCaptureDeviceInfos[iDevice].minChannels); printf(" Min Channels: %d\n", pCaptureDeviceInfos[iDevice].minChannels);
...@@ -71,8 +71,8 @@ int print_context_info(mal_context* pContext) ...@@ -71,8 +71,8 @@ int print_context_info(mal_context* pContext)
printf(" Min Sample Rate: %d\n", pCaptureDeviceInfos[iDevice].minSampleRate); printf(" Min Sample Rate: %d\n", pCaptureDeviceInfos[iDevice].minSampleRate);
printf(" Max Sample Rate: %d\n", pCaptureDeviceInfos[iDevice].maxSampleRate); printf(" Max Sample Rate: %d\n", pCaptureDeviceInfos[iDevice].maxSampleRate);
printf(" Format Count: %d\n", pCaptureDeviceInfos[iDevice].formatCount); printf(" Format Count: %d\n", pCaptureDeviceInfos[iDevice].formatCount);
for (mal_uint32 iFormat = 0; iFormat < pCaptureDeviceInfos[iDevice].formatCount; ++iFormat) { for (ma_uint32 iFormat = 0; iFormat < pCaptureDeviceInfos[iDevice].formatCount; ++iFormat) {
printf(" %s\n", mal_get_format_name(pCaptureDeviceInfos[iDevice].formats[iFormat])); printf(" %s\n", ma_get_format_name(pCaptureDeviceInfos[iDevice].formats[iFormat]));
} }
} else { } else {
printf(" ERROR\n"); printf(" ERROR\n");
...@@ -85,10 +85,10 @@ done: ...@@ -85,10 +85,10 @@ done:
return (result == MA_SUCCESS) ? 0 : -1; 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("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(" Channels: %d -> %d\n", pDevice->channels, pDevice->internalChannels);
printf(" Sample Rate: %d -> %d\n", pDevice->sampleRate, pDevice->internalSampleRate); printf(" Sample Rate: %d -> %d\n", pDevice->sampleRate, pDevice->internalSampleRate);
printf(" Buffer Size: %d\n", pDevice->bufferSizeInFrames); printf(" Buffer Size: %d\n", pDevice->bufferSizeInFrames);
...@@ -97,17 +97,17 @@ int print_device_info(mal_device* pDevice) ...@@ -97,17 +97,17 @@ int print_device_info(mal_device* pDevice)
return 0; 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; ma_sine_wave* pSineWave = (ma_sine_wave*)pDevice->pUserData;
mal_assert(pSineWave != NULL); ma_assert(pSineWave != NULL);
float* pFramesOutF32 = (float*)pFramesOut; float* pFramesOutF32 = (float*)pFramesOut;
for (mal_uint32 iFrame = 0; iFrame < frameCount; ++iFrame) { for (ma_uint32 iFrame = 0; iFrame < frameCount; ++iFrame) {
float sample; float sample;
mal_sine_wave_read(pSineWave, 1, &sample); ma_sine_wave_read(pSineWave, 1, &sample);
for (mal_uint32 iChannel = 0; iChannel < pDevice->channels; ++iChannel) { for (ma_uint32 iChannel = 0; iChannel < pDevice->channels; ++iChannel) {
pFramesOutF32[iChannel] = sample; pFramesOutF32[iChannel] = sample;
} }
...@@ -119,19 +119,19 @@ mal_uint32 on_send(mal_device* pDevice, mal_uint32 frameCount, void* pFramesOut) ...@@ -119,19 +119,19 @@ mal_uint32 on_send(mal_device* pDevice, mal_uint32 frameCount, void* pFramesOut)
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
mal_result result; ma_result result;
mal_sine_wave sineWave; ma_sine_wave sineWave;
result = mal_sine_wave_init(0.2, 400, 44100, &sineWave); result = ma_sine_wave_init(0.2, 400, 44100, &sineWave);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
printf("Failed to initialize sine wave.\n"); printf("Failed to initialize sine wave.\n");
return -1; return -1;
} }
// Separate context for this test. // 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. ma_context_config contextConfig = ma_context_config_init(NULL); // <-- Don't need a log callback because we're using debug output instead.
mal_context context; ma_context context;
result = mal_context_init(NULL, 0, &contextConfig, &context); result = ma_context_init(NULL, 0, &contextConfig, &context);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
printf("Failed to initialize context.\n"); printf("Failed to initialize context.\n");
return -1; return -1;
...@@ -141,13 +141,13 @@ int main(int argc, char** argv) ...@@ -141,13 +141,13 @@ int main(int argc, char** argv)
// Device. // 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; deviceConfig.bufferSizeInFrames = 32768;
mal_device device; ma_device device;
result = mal_device_init(&context, mal_device_type_playback, NULL, &deviceConfig, &sineWave, &device); result = ma_device_init(&context, ma_device_type_playback, NULL, &deviceConfig, &sineWave, &device);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
mal_context_uninit(&context); ma_context_uninit(&context);
printf("Failed to initialize device.\n"); printf("Failed to initialize device.\n");
return -1; return -1;
} }
...@@ -156,10 +156,10 @@ int main(int argc, char** argv) ...@@ -156,10 +156,10 @@ int main(int argc, char** argv)
// Start playback. // Start playback.
result = mal_device_start(&device); result = ma_device_start(&device);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
mal_device_uninit(&device); ma_device_uninit(&device);
mal_context_uninit(&context); ma_context_uninit(&context);
printf("Failed to start device.\n"); printf("Failed to start device.\n");
return -1; return -1;
} }
...@@ -169,7 +169,7 @@ int main(int argc, char** argv) ...@@ -169,7 +169,7 @@ int main(int argc, char** argv)
getchar(); getchar();
mal_device_uninit(&device); ma_device_uninit(&device);
mal_context_uninit(&context); ma_context_uninit(&context);
return 0; return 0;
} }
...@@ -5,109 +5,109 @@ ...@@ -5,109 +5,109 @@
// Two converters are needed here. One for converting f32 samples from the sine wave generator to the input format, // 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. // and another for converting the input format to the output format for device output.
mal_sine_wave sineWave; ma_sine_wave sineWave;
mal_format_converter converterIn; ma_format_converter converterIn;
mal_format_converter converterOut; 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; (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; ma_sine_wave* pSineWave = (ma_sine_wave*)pConverter->config.pUserData;
mal_assert(pSineWave); 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; (void)pUserData;
mal_format_converter* pConverterIn = (mal_format_converter*)pConverter->config.pUserData; ma_format_converter* pConverterIn = (ma_format_converter*)pConverter->config.pUserData;
mal_assert(pConverterIn != NULL); 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); ma_assert(pDevice->playback.format == ma_format_f32);
mal_assert(pDevice->playback.channels == 1); 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)pDevice;
(void)pInput; (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; ma_format_converter* pConverter = (ma_format_converter*)pDevice->pUserData;
mal_assert(pConverter != NULL); ma_assert(pConverter != NULL);
mal_assert(pDevice->playback.format == pConverter->config.formatOut); 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; (void)pInput;
} }
int do_dithering_test() int do_dithering_test()
{ {
mal_device_config config; ma_device_config config;
mal_device device; ma_device device;
mal_result result; ma_result result;
config = mal_device_config_init(mal_device_type_playback); config = ma_device_config_init(ma_device_type_playback);
config.playback.format = mal_format_f32; config.playback.format = ma_format_f32;
config.playback.channels = 1; config.playback.channels = 1;
config.sampleRate = 0; config.sampleRate = 0;
config.dataCallback = on_send_to_device__original; config.dataCallback = on_send_to_device__original;
// We first play the sound the way it's meant to be played. // 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) { if (result != MA_SUCCESS) {
return -1; 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) { if (result != MA_SUCCESS) {
return -2; return -2;
} }
printf("Press Enter to play enable dithering.\n"); printf("Press Enter to play enable dithering.\n");
getchar(); getchar();
mal_device_uninit(&device); ma_device_uninit(&device);
mal_format srcFormat = mal_format_s24; ma_format srcFormat = ma_format_s24;
mal_format dstFormat = mal_format_u8; ma_format dstFormat = ma_format_u8;
mal_dither_mode ditherMode = mal_dither_mode_triangle; ma_dither_mode ditherMode = ma_dither_mode_triangle;
mal_format_converter_config converterInConfig = mal_format_converter_config_init_new(); ma_format_converter_config converterInConfig = ma_format_converter_config_init_new();
converterInConfig.formatIn = mal_format_f32; // <-- From the sine wave generator. converterInConfig.formatIn = ma_format_f32; // <-- From the sine wave generator.
converterInConfig.formatOut = srcFormat; converterInConfig.formatOut = srcFormat;
converterInConfig.channels = config.playback.channels; converterInConfig.channels = config.playback.channels;
converterInConfig.ditherMode = mal_dither_mode_none; converterInConfig.ditherMode = ma_dither_mode_none;
converterInConfig.onRead = on_convert_samples_in; converterInConfig.onRead = on_convert_samples_in;
converterInConfig.pUserData = &sineWave; converterInConfig.pUserData = &sineWave;
result = mal_format_converter_init(&converterInConfig, &converterIn); result = ma_format_converter_init(&converterInConfig, &converterIn);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
return -3; 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.formatIn = srcFormat;
converterOutConfig.formatOut = dstFormat; converterOutConfig.formatOut = dstFormat;
converterOutConfig.channels = config.playback.channels; converterOutConfig.channels = config.playback.channels;
converterOutConfig.ditherMode = ditherMode; converterOutConfig.ditherMode = ditherMode;
converterOutConfig.onRead = on_convert_samples_out; converterOutConfig.onRead = on_convert_samples_out;
converterOutConfig.pUserData = &converterIn; converterOutConfig.pUserData = &converterIn;
result = mal_format_converter_init(&converterOutConfig, &converterOut); result = ma_format_converter_init(&converterOutConfig, &converterOut);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
return -3; return -3;
} }
...@@ -116,15 +116,15 @@ int do_dithering_test() ...@@ -116,15 +116,15 @@ int do_dithering_test()
config.dataCallback = on_send_to_device__dithered; config.dataCallback = on_send_to_device__dithered;
config.pUserData = &converterOut; config.pUserData = &converterOut;
result = mal_device_init(NULL, &config, &device); result = ma_device_init(NULL, &config, &device);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
return -1; return -1;
} }
// Now we play the sound after it's run through a dithered format converter. // 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) { if (result != MA_SUCCESS) {
return -2; return -2;
} }
......
...@@ -13,7 +13,7 @@ void main_loop__em() ...@@ -13,7 +13,7 @@ void main_loop__em()
} }
#endif #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)pContext;
(void)pDevice; (void)pDevice;
...@@ -21,21 +21,21 @@ void log_callback(mal_context* pContext, mal_device* pDevice, mal_uint32 logLeve ...@@ -21,21 +21,21 @@ void log_callback(mal_context* pContext, mal_device* pDevice, mal_uint32 logLeve
printf("%s\n", message); printf("%s\n", message);
} }
void stop_callback(mal_device* pDevice) void stop_callback(ma_device* pDevice)
{ {
(void)pDevice; (void)pDevice;
printf("STOPPED\n"); 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(). */ /* 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 #if 1
/* Also write to a wav file for debugging. */ /* Also write to a wav file for debugging. */
drwav* pWav = (drwav*)pDevice->pUserData; drwav* pWav = (drwav*)pDevice->pUserData;
mal_assert(pWav != NULL); ma_assert(pWav != NULL);
drwav_write_pcm_frames(pWav, frameCount, pInput); drwav_write_pcm_frames(pWav, frameCount, pInput);
#endif #endif
...@@ -43,7 +43,7 @@ void data_callback(mal_device* pDevice, void* pOutput, const void* pInput, mal_u ...@@ -43,7 +43,7 @@ void data_callback(mal_device* pDevice, void* pOutput, const void* pInput, mal_u
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
mal_result result; ma_result result;
#if 1 #if 1
drwav_data_format wavFormat; drwav_data_format wavFormat;
...@@ -61,26 +61,26 @@ int main(int argc, char** argv) ...@@ -61,26 +61,26 @@ int main(int argc, char** argv)
#endif #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; contextConfig.logCallback = log_callback;
mal_context context; ma_context context;
result = mal_context_init(&backend, 1, &contextConfig, &context); result = ma_context_init(&backend, 1, &contextConfig, &context);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
printf("Failed to initialize context.\n"); printf("Failed to initialize context.\n");
return result; 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.pDeviceID = NULL;
deviceConfig.capture.format = mal_format_s16; deviceConfig.capture.format = ma_format_s16;
deviceConfig.capture.channels = 2; deviceConfig.capture.channels = 2;
deviceConfig.playback.pDeviceID = NULL; deviceConfig.playback.pDeviceID = NULL;
deviceConfig.playback.format = mal_format_s16; deviceConfig.playback.format = ma_format_s16;
deviceConfig.playback.channels = 2; deviceConfig.playback.channels = 2;
deviceConfig.playback.shareMode = mal_share_mode_shared; deviceConfig.playback.shareMode = ma_share_mode_shared;
deviceConfig.sampleRate = 44100; deviceConfig.sampleRate = 44100;
//deviceConfig.bufferSizeInMilliseconds = 60; //deviceConfig.bufferSizeInMilliseconds = 60;
deviceConfig.bufferSizeInFrames = 4096; deviceConfig.bufferSizeInFrames = 4096;
...@@ -89,8 +89,8 @@ int main(int argc, char** argv) ...@@ -89,8 +89,8 @@ int main(int argc, char** argv)
deviceConfig.stopCallback = stop_callback; deviceConfig.stopCallback = stop_callback;
deviceConfig.pUserData = &wav; deviceConfig.pUserData = &wav;
mal_device device; ma_device device;
result = mal_device_init(&context, &deviceConfig, &device); result = ma_device_init(&context, &deviceConfig, &device);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
return result; return result;
} }
...@@ -99,7 +99,7 @@ int main(int argc, char** argv) ...@@ -99,7 +99,7 @@ int main(int argc, char** argv)
getchar(); getchar();
#endif #endif
mal_device_start(&device); ma_device_start(&device);
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
emscripten_set_main_loop(main_loop__em, 0, 1); emscripten_set_main_loop(main_loop__em, 0, 1);
...@@ -108,7 +108,7 @@ int main(int argc, char** argv) ...@@ -108,7 +108,7 @@ int main(int argc, char** argv)
getchar(); getchar();
#endif #endif
mal_device_uninit(&device); ma_device_uninit(&device);
drwav_uninit(&wav); drwav_uninit(&wav);
(void)argc; (void)argc;
......
...@@ -13,15 +13,15 @@ int main(int argc, char** argv) ...@@ -13,15 +13,15 @@ int main(int argc, char** argv)
(void)argc; (void)argc;
(void)argv; (void)argv;
mal_result result = MA_ERROR; ma_result result = MA_ERROR;
mal_pcm_converter_config dspConfig = mal_pcm_converter_config_init_new(); ma_pcm_converter_config dspConfig = ma_pcm_converter_config_init_new();
mal_pcm_converter converter; ma_pcm_converter converter;
result = mal_pcm_converter_init(&dspConfig, &converter); result = ma_pcm_converter_init(&dspConfig, &converter);
mal_decoder_config decoderConfig = mal_decoder_config_init(mal_format_unknown, 0, 0); ma_decoder_config decoderConfig = ma_decoder_config_init(ma_format_unknown, 0, 0);
mal_decoder decoder; ma_decoder decoder;
result = mal_decoder_init_file("res/sine_s16_mono_48000.wav", &decoderConfig, &decoder); result = ma_decoder_init_file("res/sine_s16_mono_48000.wav", &decoderConfig, &decoder);
return result; return result;
} }
......
...@@ -23,23 +23,23 @@ const char* simd_mode_to_string(simd_mode mode) ...@@ -23,23 +23,23 @@ const char* simd_mode_to_string(simd_mode mode)
return "Unknown"; 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) { switch (algorithm) {
case mal_src_algorithm_none: return "Passthrough"; case ma_src_algorithm_none: return "Passthrough";
case mal_src_algorithm_linear: return "Linear"; case ma_src_algorithm_linear: return "Linear";
case mal_src_algorithm_sinc: return "Sinc"; case ma_src_algorithm_sinc: return "Sinc";
} }
return "Unknown"; 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) { switch (ditherMode) {
case mal_dither_mode_none: return "None"; case ma_dither_mode_none: return "None";
case mal_dither_mode_rectangle: return "Rectangle"; case ma_dither_mode_rectangle: return "Rectangle";
case mal_dither_mode_triangle: return "Triangle"; case ma_dither_mode_triangle: return "Triangle";
} }
return "Unkown"; return "Unkown";
...@@ -56,70 +56,70 @@ const char* mal_dither_mode_to_string(mal_dither_mode ditherMode) ...@@ -56,70 +56,70 @@ const char* mal_dither_mode_to_string(mal_dither_mode ditherMode)
typedef struct typedef struct
{ {
void* pBaseData; void* pBaseData;
mal_uint64 sampleCount; ma_uint64 sampleCount;
mal_uint64 iNextSample; ma_uint64 iNextSample;
} format_conversion_data; } 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) switch (formatIn)
{ {
case mal_format_u8: case ma_format_u8:
{ {
switch (formatOut) switch (formatOut)
{ {
case mal_format_s16: mal_pcm_u8_to_s16__reference(pOut, pIn, sampleCount, ditherMode); return; case ma_format_s16: ma_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 ma_format_s24: ma_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 ma_format_s32: ma_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_f32: ma_pcm_u8_to_f32__reference(pOut, pIn, sampleCount, ditherMode); return;
default: break; default: break;
} }
} break; } break;
case mal_format_s16: case ma_format_s16:
{ {
switch (formatOut) switch (formatOut)
{ {
case mal_format_u8: mal_pcm_s16_to_u8__reference( pOut, pIn, sampleCount, ditherMode); return; case ma_format_u8: ma_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 ma_format_s24: ma_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 ma_format_s32: ma_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_f32: ma_pcm_s16_to_f32__reference(pOut, pIn, sampleCount, ditherMode); return;
default: break; default: break;
} }
} break; } break;
case mal_format_s24: case ma_format_s24:
{ {
switch (formatOut) switch (formatOut)
{ {
case mal_format_u8: mal_pcm_s24_to_u8__reference( pOut, pIn, sampleCount, ditherMode); return; case ma_format_u8: ma_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 ma_format_s16: ma_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 ma_format_s32: ma_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_f32: ma_pcm_s24_to_f32__reference(pOut, pIn, sampleCount, ditherMode); return;
default: break; default: break;
} }
} break; } break;
case mal_format_s32: case ma_format_s32:
{ {
switch (formatOut) switch (formatOut)
{ {
case mal_format_u8: mal_pcm_s32_to_u8__reference( pOut, pIn, sampleCount, ditherMode); return; case ma_format_u8: ma_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 ma_format_s16: ma_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 ma_format_s24: ma_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_f32: ma_pcm_s32_to_f32__reference(pOut, pIn, sampleCount, ditherMode); return;
default: break; default: break;
} }
} break; } break;
case mal_format_f32: case ma_format_f32:
{ {
switch (formatOut) switch (formatOut)
{ {
case mal_format_u8: mal_pcm_f32_to_u8__reference( pOut, pIn, sampleCount, ditherMode); return; case ma_format_u8: ma_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 ma_format_s16: ma_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 ma_format_s24: ma_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_s32: ma_pcm_f32_to_s32__reference(pOut, pIn, sampleCount, ditherMode); return;
default: break; default: break;
} }
} break; } break;
...@@ -128,66 +128,66 @@ void pcm_convert__reference(void* pOut, mal_format formatOut, const void* pIn, m ...@@ -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) switch (formatIn)
{ {
case mal_format_u8: case ma_format_u8:
{ {
switch (formatOut) switch (formatOut)
{ {
case mal_format_s16: mal_pcm_u8_to_s16__optimized(pOut, pIn, sampleCount, ditherMode); return; case ma_format_s16: ma_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 ma_format_s24: ma_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 ma_format_s32: ma_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_f32: ma_pcm_u8_to_f32__optimized(pOut, pIn, sampleCount, ditherMode); return;
default: break; default: break;
} }
} break; } break;
case mal_format_s16: case ma_format_s16:
{ {
switch (formatOut) switch (formatOut)
{ {
case mal_format_u8: mal_pcm_s16_to_u8__optimized( pOut, pIn, sampleCount, ditherMode); return; case ma_format_u8: ma_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 ma_format_s24: ma_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 ma_format_s32: ma_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_f32: ma_pcm_s16_to_f32__optimized(pOut, pIn, sampleCount, ditherMode); return;
default: break; default: break;
} }
} break; } break;
case mal_format_s24: case ma_format_s24:
{ {
switch (formatOut) switch (formatOut)
{ {
case mal_format_u8: mal_pcm_s24_to_u8__optimized( pOut, pIn, sampleCount, ditherMode); return; case ma_format_u8: ma_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 ma_format_s16: ma_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 ma_format_s32: ma_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_f32: ma_pcm_s24_to_f32__optimized(pOut, pIn, sampleCount, ditherMode); return;
default: break; default: break;
} }
} break; } break;
case mal_format_s32: case ma_format_s32:
{ {
switch (formatOut) switch (formatOut)
{ {
case mal_format_u8: mal_pcm_s32_to_u8__optimized( pOut, pIn, sampleCount, ditherMode); return; case ma_format_u8: ma_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 ma_format_s16: ma_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 ma_format_s24: ma_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_f32: ma_pcm_s32_to_f32__optimized(pOut, pIn, sampleCount, ditherMode); return;
default: break; default: break;
} }
} break; } break;
case mal_format_f32: case ma_format_f32:
{ {
switch (formatOut) switch (formatOut)
{ {
case mal_format_u8: mal_pcm_f32_to_u8__optimized( pOut, pIn, sampleCount, ditherMode); return; case ma_format_u8: ma_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 ma_format_s16: ma_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 ma_format_s24: ma_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_s32: ma_pcm_f32_to_s32__optimized(pOut, pIn, sampleCount, ditherMode); return;
default: break; default: break;
} }
} break; } break;
...@@ -197,66 +197,66 @@ void pcm_convert__optimized(void* pOut, mal_format formatOut, const void* pIn, m ...@@ -197,66 +197,66 @@ void pcm_convert__optimized(void* pOut, mal_format formatOut, const void* pIn, m
} }
#if defined(MA_SUPPORT_SSE2) #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) switch (formatIn)
{ {
case mal_format_u8: case ma_format_u8:
{ {
switch (formatOut) switch (formatOut)
{ {
case mal_format_s16: mal_pcm_u8_to_s16__sse2(pOut, pIn, sampleCount, ditherMode); return; case ma_format_s16: ma_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 ma_format_s24: ma_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 ma_format_s32: ma_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_f32: ma_pcm_u8_to_f32__sse2(pOut, pIn, sampleCount, ditherMode); return;
default: break; default: break;
} }
} break; } break;
case mal_format_s16: case ma_format_s16:
{ {
switch (formatOut) switch (formatOut)
{ {
case mal_format_u8: mal_pcm_s16_to_u8__sse2( pOut, pIn, sampleCount, ditherMode); return; case ma_format_u8: ma_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 ma_format_s24: ma_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 ma_format_s32: ma_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_f32: ma_pcm_s16_to_f32__sse2(pOut, pIn, sampleCount, ditherMode); return;
default: break; default: break;
} }
} break; } break;
case mal_format_s24: case ma_format_s24:
{ {
switch (formatOut) switch (formatOut)
{ {
case mal_format_u8: mal_pcm_s24_to_u8__sse2( pOut, pIn, sampleCount, ditherMode); return; case ma_format_u8: ma_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 ma_format_s16: ma_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 ma_format_s32: ma_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_f32: ma_pcm_s24_to_f32__sse2(pOut, pIn, sampleCount, ditherMode); return;
default: break; default: break;
} }
} break; } break;
case mal_format_s32: case ma_format_s32:
{ {
switch (formatOut) switch (formatOut)
{ {
case mal_format_u8: mal_pcm_s32_to_u8__sse2( pOut, pIn, sampleCount, ditherMode); return; case ma_format_u8: ma_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 ma_format_s16: ma_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 ma_format_s24: ma_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_f32: ma_pcm_s32_to_f32__sse2(pOut, pIn, sampleCount, ditherMode); return;
default: break; default: break;
} }
} break; } break;
case mal_format_f32: case ma_format_f32:
{ {
switch (formatOut) switch (formatOut)
{ {
case mal_format_u8: mal_pcm_f32_to_u8__sse2( pOut, pIn, sampleCount, ditherMode); return; case ma_format_u8: ma_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 ma_format_s16: ma_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 ma_format_s24: ma_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_s32: ma_pcm_f32_to_s32__sse2(pOut, pIn, sampleCount, ditherMode); return;
default: break; default: break;
} }
} break; } break;
...@@ -267,66 +267,66 @@ void pcm_convert__sse2(void* pOut, mal_format formatOut, const void* pIn, mal_fo ...@@ -267,66 +267,66 @@ void pcm_convert__sse2(void* pOut, mal_format formatOut, const void* pIn, mal_fo
#endif #endif
#if defined(MA_SUPPORT_AVX2) #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) switch (formatIn)
{ {
case mal_format_u8: case ma_format_u8:
{ {
switch (formatOut) switch (formatOut)
{ {
case mal_format_s16: mal_pcm_u8_to_s16__avx2(pOut, pIn, sampleCount, ditherMode); return; case ma_format_s16: ma_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 ma_format_s24: ma_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 ma_format_s32: ma_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_f32: ma_pcm_u8_to_f32__avx2(pOut, pIn, sampleCount, ditherMode); return;
default: break; default: break;
} }
} break; } break;
case mal_format_s16: case ma_format_s16:
{ {
switch (formatOut) switch (formatOut)
{ {
case mal_format_u8: mal_pcm_s16_to_u8__avx2( pOut, pIn, sampleCount, ditherMode); return; case ma_format_u8: ma_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 ma_format_s24: ma_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 ma_format_s32: ma_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_f32: ma_pcm_s16_to_f32__avx2(pOut, pIn, sampleCount, ditherMode); return;
default: break; default: break;
} }
} break; } break;
case mal_format_s24: case ma_format_s24:
{ {
switch (formatOut) switch (formatOut)
{ {
case mal_format_u8: mal_pcm_s24_to_u8__avx2( pOut, pIn, sampleCount, ditherMode); return; case ma_format_u8: ma_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 ma_format_s16: ma_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 ma_format_s32: ma_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_f32: ma_pcm_s24_to_f32__avx2(pOut, pIn, sampleCount, ditherMode); return;
default: break; default: break;
} }
} break; } break;
case mal_format_s32: case ma_format_s32:
{ {
switch (formatOut) switch (formatOut)
{ {
case mal_format_u8: mal_pcm_s32_to_u8__avx2( pOut, pIn, sampleCount, ditherMode); return; case ma_format_u8: ma_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 ma_format_s16: ma_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 ma_format_s24: ma_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_f32: ma_pcm_s32_to_f32__avx2(pOut, pIn, sampleCount, ditherMode); return;
default: break; default: break;
} }
} break; } break;
case mal_format_f32: case ma_format_f32:
{ {
switch (formatOut) switch (formatOut)
{ {
case mal_format_u8: mal_pcm_f32_to_u8__avx2( pOut, pIn, sampleCount, ditherMode); return; case ma_format_u8: ma_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 ma_format_s16: ma_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 ma_format_s24: ma_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_s32: ma_pcm_f32_to_s32__avx2(pOut, pIn, sampleCount, ditherMode); return;
default: break; default: break;
} }
} break; } break;
...@@ -337,66 +337,66 @@ void pcm_convert__avx(void* pOut, mal_format formatOut, const void* pIn, mal_for ...@@ -337,66 +337,66 @@ void pcm_convert__avx(void* pOut, mal_format formatOut, const void* pIn, mal_for
#endif #endif
#if defined(MA_SUPPORT_AVX512) #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) switch (formatIn)
{ {
case mal_format_u8: case ma_format_u8:
{ {
switch (formatOut) switch (formatOut)
{ {
case mal_format_s16: mal_pcm_u8_to_s16__avx512(pOut, pIn, sampleCount, ditherMode); return; case ma_format_s16: ma_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 ma_format_s24: ma_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 ma_format_s32: ma_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_f32: ma_pcm_u8_to_f32__avx512(pOut, pIn, sampleCount, ditherMode); return;
default: break; default: break;
} }
} break; } break;
case mal_format_s16: case ma_format_s16:
{ {
switch (formatOut) switch (formatOut)
{ {
case mal_format_u8: mal_pcm_s16_to_u8__avx512( pOut, pIn, sampleCount, ditherMode); return; case ma_format_u8: ma_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 ma_format_s24: ma_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 ma_format_s32: ma_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_f32: ma_pcm_s16_to_f32__avx512(pOut, pIn, sampleCount, ditherMode); return;
default: break; default: break;
} }
} break; } break;
case mal_format_s24: case ma_format_s24:
{ {
switch (formatOut) switch (formatOut)
{ {
case mal_format_u8: mal_pcm_s24_to_u8__avx512( pOut, pIn, sampleCount, ditherMode); return; case ma_format_u8: ma_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 ma_format_s16: ma_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 ma_format_s32: ma_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_f32: ma_pcm_s24_to_f32__avx512(pOut, pIn, sampleCount, ditherMode); return;
default: break; default: break;
} }
} break; } break;
case mal_format_s32: case ma_format_s32:
{ {
switch (formatOut) switch (formatOut)
{ {
case mal_format_u8: mal_pcm_s32_to_u8__avx512( pOut, pIn, sampleCount, ditherMode); return; case ma_format_u8: ma_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 ma_format_s16: ma_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 ma_format_s24: ma_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_f32: ma_pcm_s32_to_f32__avx512(pOut, pIn, sampleCount, ditherMode); return;
default: break; default: break;
} }
} break; } break;
case mal_format_f32: case ma_format_f32:
{ {
switch (formatOut) switch (formatOut)
{ {
case mal_format_u8: mal_pcm_f32_to_u8__avx512( pOut, pIn, sampleCount, ditherMode); return; case ma_format_u8: ma_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 ma_format_s16: ma_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 ma_format_s24: ma_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_s32: ma_pcm_f32_to_s32__avx512(pOut, pIn, sampleCount, ditherMode); return;
default: break; default: break;
} }
} break; } break;
...@@ -407,66 +407,66 @@ void pcm_convert__avx512(void* pOut, mal_format formatOut, const void* pIn, mal_ ...@@ -407,66 +407,66 @@ void pcm_convert__avx512(void* pOut, mal_format formatOut, const void* pIn, mal_
#endif #endif
#if defined(MA_SUPPORT_NEON) #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) switch (formatIn)
{ {
case mal_format_u8: case ma_format_u8:
{ {
switch (formatOut) switch (formatOut)
{ {
case mal_format_s16: mal_pcm_u8_to_s16__neon(pOut, pIn, sampleCount, ditherMode); return; case ma_format_s16: ma_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 ma_format_s24: ma_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 ma_format_s32: ma_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_f32: ma_pcm_u8_to_f32__neon(pOut, pIn, sampleCount, ditherMode); return;
default: break; default: break;
} }
} break; } break;
case mal_format_s16: case ma_format_s16:
{ {
switch (formatOut) switch (formatOut)
{ {
case mal_format_u8: mal_pcm_s16_to_u8__neon( pOut, pIn, sampleCount, ditherMode); return; case ma_format_u8: ma_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 ma_format_s24: ma_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 ma_format_s32: ma_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_f32: ma_pcm_s16_to_f32__neon(pOut, pIn, sampleCount, ditherMode); return;
default: break; default: break;
} }
} break; } break;
case mal_format_s24: case ma_format_s24:
{ {
switch (formatOut) switch (formatOut)
{ {
case mal_format_u8: mal_pcm_s24_to_u8__neon( pOut, pIn, sampleCount, ditherMode); return; case ma_format_u8: ma_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 ma_format_s16: ma_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 ma_format_s32: ma_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_f32: ma_pcm_s24_to_f32__neon(pOut, pIn, sampleCount, ditherMode); return;
default: break; default: break;
} }
} break; } break;
case mal_format_s32: case ma_format_s32:
{ {
switch (formatOut) switch (formatOut)
{ {
case mal_format_u8: mal_pcm_s32_to_u8__neon( pOut, pIn, sampleCount, ditherMode); return; case ma_format_u8: ma_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 ma_format_s16: ma_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 ma_format_s24: ma_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_f32: ma_pcm_s32_to_f32__neon(pOut, pIn, sampleCount, ditherMode); return;
default: break; default: break;
} }
} break; } break;
case mal_format_f32: case ma_format_f32:
{ {
switch (formatOut) switch (formatOut)
{ {
case mal_format_u8: mal_pcm_f32_to_u8__neon( pOut, pIn, sampleCount, ditherMode); return; case ma_format_u8: ma_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 ma_format_s16: ma_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 ma_format_s24: ma_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_s32: ma_pcm_f32_to_s32__neon(pOut, pIn, sampleCount, ditherMode); return;
default: break; default: break;
} }
} break; } break;
...@@ -476,10 +476,10 @@ void pcm_convert__neon(void* pOut, mal_format formatOut, const void* pIn, mal_fo ...@@ -476,10 +476,10 @@ void pcm_convert__neon(void* pOut, mal_format formatOut, const void* pIn, mal_fo
} }
#endif #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. // 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) switch (mode)
{ {
...@@ -521,35 +521,35 @@ void pcm_convert(void* pOut, mal_format formatOut, const void* pIn, mal_format f ...@@ -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) { if (pTestData == NULL) {
printf("Out of memory.\n"); printf("Out of memory.\n");
return -1; return -1;
} }
mal_timer timer; ma_timer timer;
mal_timer_init(&timer); ma_timer_init(&timer);
double timeTaken = mal_timer_get_time_in_seconds(&timer); double timeTaken = ma_timer_get_time_in_seconds(&timer);
{ {
pcm_convert(pTestData, formatOut, pBaseData, formatIn, sampleCount, ditherMode, mode); 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. // Compare with the reference for correctness.
mal_bool32 passed = MA_TRUE; ma_bool32 passed = MA_TRUE;
for (mal_uint64 iSample = 0; iSample < sampleCount; ++iSample) { for (ma_uint64 iSample = 0; iSample < sampleCount; ++iSample) {
mal_uint32 bps = mal_get_bytes_per_sample(formatOut); 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. // 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) switch (formatOut)
{ {
case mal_format_s16: case ma_format_s16:
{ {
mal_int16 a = ((const mal_int16*)pReferenceData)[iSample]; ma_int16 a = ((const ma_int16*)pReferenceData)[iSample];
mal_int16 b = ((const mal_int16*)pTestData)[iSample]; ma_int16 b = ((const ma_int16*)pTestData)[iSample];
if (abs(a-b) > 0) { if (abs(a-b) > 0) {
printf("Incorrect Sample: (%d) %d != %d\n", (int)iSample, a, b); printf("Incorrect Sample: (%d) %d != %d\n", (int)iSample, a, b);
passed = MA_FALSE; passed = MA_FALSE;
...@@ -558,7 +558,7 @@ int do_profiling__format_conversion__profile_individual(mal_format formatIn, mal ...@@ -558,7 +558,7 @@ int do_profiling__format_conversion__profile_individual(mal_format formatIn, mal
default: 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); printf("Incorrect Sample: (%d)\n", (int)iSample);
passed = MA_FALSE; passed = MA_FALSE;
} }
...@@ -571,63 +571,63 @@ int do_profiling__format_conversion__profile_individual(mal_format formatIn, mal ...@@ -571,63 +571,63 @@ int do_profiling__format_conversion__profile_individual(mal_format formatIn, mal
} else { } else {
printf(" [FAILED] "); 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; 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. // 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) { if (pSourceData == NULL) {
printf("Out of memory.\n"); printf("Out of memory.\n");
return -1; return -1;
} }
mal_sine_wave sineWave; ma_sine_wave sineWave;
mal_sine_wave_init(1.0, 400, 48000, &sineWave); ma_sine_wave_init(1.0, 400, 48000, &sineWave);
mal_sine_wave_read_f32(&sineWave, sampleCount, pSourceData); ma_sine_wave_read_f32(&sineWave, sampleCount, pSourceData);
void* pBaseData = mal_aligned_malloc(sampleCount * mal_get_bytes_per_sample(formatIn), MA_SIMD_ALIGNMENT); void* pBaseData = ma_aligned_malloc(sampleCount * ma_get_bytes_per_sample(formatIn), MA_SIMD_ALIGNMENT);
mal_pcm_convert(pBaseData, formatIn, pSourceData, mal_format_f32, sampleCount, mal_dither_mode_none); ma_pcm_convert(pBaseData, formatIn, pSourceData, ma_format_f32, sampleCount, ma_dither_mode_none);
// Reference first so we can get a benchmark. // Reference first so we can get a benchmark.
void* pReferenceData = mal_aligned_malloc(sampleCount * mal_get_bytes_per_sample(formatOut), MA_SIMD_ALIGNMENT); void* pReferenceData = ma_aligned_malloc(sampleCount * ma_get_bytes_per_sample(formatOut), MA_SIMD_ALIGNMENT);
mal_timer timer; ma_timer timer;
mal_timer_init(&timer); ma_timer_init(&timer);
double referenceTime = mal_timer_get_time_in_seconds(&timer); double referenceTime = ma_timer_get_time_in_seconds(&timer);
{ {
pcm_convert__reference(pReferenceData, formatOut, pBaseData, formatIn, sampleCount, ditherMode); 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. // Here is where each optimized implementation is profiled.
do_profiling__format_conversion__profile_individual(formatIn, formatOut, ditherMode, pBaseData, sampleCount, simd_mode_scalar, pReferenceData, referenceTime); 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); 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); 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); 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); do_profiling__format_conversion__profile_individual(formatIn, formatOut, ditherMode, pBaseData, sampleCount, simd_mode_neon, pReferenceData, referenceTime);
} }
mal_aligned_free(pReferenceData); ma_aligned_free(pReferenceData);
mal_aligned_free(pBaseData); ma_aligned_free(pBaseData);
mal_aligned_free(pSourceData); ma_aligned_free(pSourceData);
return 0; return 0;
} }
...@@ -636,7 +636,7 @@ int do_profiling__format_conversion() ...@@ -636,7 +636,7 @@ int do_profiling__format_conversion()
// First we need to generate our base data. // 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; return 0;
} }
...@@ -657,12 +657,12 @@ double g_ChannelRouterTime_AVX2 = 0; ...@@ -657,12 +657,12 @@ double g_ChannelRouterTime_AVX2 = 0;
double g_ChannelRouterTime_AVX512 = 0; double g_ChannelRouterTime_AVX512 = 0;
double g_ChannelRouterTime_NEON = 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 (ma_uint32 iChannel = 0; iChannel < channels; ++iChannel) {
for (mal_uint32 iFrame = 0; iFrame < frameCount; ++iFrame) { for (ma_uint32 iFrame = 0; iFrame < frameCount; ++iFrame) {
if (ppFramesA[iChannel][iFrame] != ppFramesB[iChannel][iFrame]) { if (ppFramesA[iChannel][iFrame] != ppFramesB[iChannel][iFrame]) {
return MA_FALSE; return MA_FALSE;
} }
...@@ -672,16 +672,16 @@ mal_bool32 channel_router_test(mal_uint32 channels, mal_uint64 frameCount, float ...@@ -672,16 +672,16 @@ mal_bool32 channel_router_test(mal_uint32 channels, mal_uint64 frameCount, float
return MA_TRUE; 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)pUserData;
(void)pRouter; (void)pRouter;
float** ppSamplesOutF = (float**)ppSamplesOut; float** ppSamplesOutF = (float**)ppSamplesOut;
for (mal_uint32 iChannel = 0; iChannel < pRouter->config.channelsIn; ++iChannel) { for (ma_uint32 iChannel = 0; iChannel < pRouter->config.channelsIn; ++iChannel) {
mal_sine_wave_init(1/(iChannel+1), 400, 48000, &g_sineWave); ma_sine_wave_init(1/(iChannel+1), 400, 48000, &g_sineWave);
mal_sine_wave_read_f32(&g_sineWave, frameCount, ppSamplesOutF[iChannel]); ma_sine_wave_read_f32(&g_sineWave, frameCount, ppSamplesOutF[iChannel]);
} }
return frameCount; return frameCount;
...@@ -689,20 +689,20 @@ mal_uint32 channel_router_on_read(mal_channel_router* pRouter, mal_uint32 frameC ...@@ -689,20 +689,20 @@ mal_uint32 channel_router_on_read(mal_channel_router* pRouter, mal_uint32 frameC
int do_profiling__channel_routing() 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 // 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. // use the reference implementation for our benchmark.
mal_uint32 channels = mal_countof(g_ChannelRouterProfilingOutputBenchmark); ma_uint32 channels = ma_countof(g_ChannelRouterProfilingOutputBenchmark);
mal_channel channelMapIn[MA_MAX_CHANNELS]; ma_channel channelMapIn[MA_MAX_CHANNELS];
mal_get_standard_channel_map(mal_standard_channel_map_default, channels, channelMapIn); ma_get_standard_channel_map(ma_standard_channel_map_default, channels, channelMapIn);
mal_channel channelMapOut[MA_MAX_CHANNELS]; ma_channel channelMapOut[MA_MAX_CHANNELS];
mal_get_standard_channel_map(mal_standard_channel_map_default, channels, channelMapOut); 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; ma_channel_router router;
result = mal_channel_router_init(&routerConfig, &router); result = ma_channel_router_init(&routerConfig, &router);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
return -1; return -1;
} }
...@@ -715,7 +715,7 @@ int do_profiling__channel_routing() ...@@ -715,7 +715,7 @@ int do_profiling__channel_routing()
router.useAVX512 = MA_FALSE; router.useAVX512 = MA_FALSE;
router.useNEON = MA_FALSE; router.useNEON = MA_FALSE;
mal_uint64 framesToRead = mal_countof(g_ChannelRouterProfilingOutputBenchmark[0]); ma_uint64 framesToRead = ma_countof(g_ChannelRouterProfilingOutputBenchmark[0]);
// Benchmark // Benchmark
void* ppOutBenchmark[8]; void* ppOutBenchmark[8];
...@@ -723,8 +723,8 @@ int do_profiling__channel_routing() ...@@ -723,8 +723,8 @@ int do_profiling__channel_routing()
ppOutBenchmark[i] = (void*)g_ChannelRouterProfilingOutputBenchmark[i]; ppOutBenchmark[i] = (void*)g_ChannelRouterProfilingOutputBenchmark[i];
} }
mal_sine_wave_init(1, 400, 48000, &g_sineWave); ma_sine_wave_init(1, 400, 48000, &g_sineWave);
mal_uint64 framesRead = mal_channel_router_read_deinterleaved(&router, framesToRead, ppOutBenchmark, NULL); ma_uint64 framesRead = ma_channel_router_read_deinterleaved(&router, framesToRead, ppOutBenchmark, NULL);
if (framesRead != framesToRead) { if (framesRead != framesToRead) {
printf("Channel Router: An error occurred while reading benchmark data.\n"); printf("Channel Router: An error occurred while reading benchmark data.\n");
} }
...@@ -740,11 +740,11 @@ int do_profiling__channel_routing() ...@@ -740,11 +740,11 @@ int do_profiling__channel_routing()
// Reference // Reference
{ {
mal_timer timer; ma_timer timer;
mal_timer_init(&timer); ma_timer_init(&timer);
double startTime = mal_timer_get_time_in_seconds(&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) { if (framesRead != framesToRead) {
printf("Channel Router: An error occurred while reading reference data.\n"); printf("Channel Router: An error occurred while reading reference data.\n");
} }
...@@ -755,23 +755,23 @@ int do_profiling__channel_routing() ...@@ -755,23 +755,23 @@ int do_profiling__channel_routing()
printf(" [PASSED] "); 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); printf("Reference: %.4fms (%.2f%%)\n", g_ChannelRouterTime_Reference*1000, g_ChannelRouterTime_Reference/g_ChannelRouterTime_Reference*100);
} }
// SSE2 // SSE2
if (mal_has_sse2()) { if (ma_has_sse2()) {
router.useSSE2 = MA_TRUE; router.useSSE2 = MA_TRUE;
mal_timer timer; ma_timer timer;
mal_timer_init(&timer); ma_timer_init(&timer);
double startTime = mal_timer_get_time_in_seconds(&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) { if (framesRead != framesToRead) {
printf("Channel Router: An error occurred while reading SSE2 data.\n"); 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; router.useSSE2 = MA_FALSE;
if (!channel_router_test(channels, framesRead, (float**)ppOutBenchmark, (float**)ppOut)) { if (!channel_router_test(channels, framesRead, (float**)ppOutBenchmark, (float**)ppOut)) {
...@@ -784,18 +784,18 @@ int do_profiling__channel_routing() ...@@ -784,18 +784,18 @@ int do_profiling__channel_routing()
} }
// AVX2 // AVX2
if (mal_has_avx2()) { if (ma_has_avx2()) {
router.useAVX2 = MA_TRUE; router.useAVX2 = MA_TRUE;
mal_timer timer; ma_timer timer;
mal_timer_init(&timer); ma_timer_init(&timer);
double startTime = mal_timer_get_time_in_seconds(&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) { if (framesRead != framesToRead) {
printf("Channel Router: An error occurred while reading AVX2 data.\n"); 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; router.useAVX2 = MA_FALSE;
if (!channel_router_test(channels, framesRead, (float**)ppOutBenchmark, (float**)ppOut)) { if (!channel_router_test(channels, framesRead, (float**)ppOutBenchmark, (float**)ppOut)) {
...@@ -808,18 +808,18 @@ int do_profiling__channel_routing() ...@@ -808,18 +808,18 @@ int do_profiling__channel_routing()
} }
// NEON // NEON
if (mal_has_neon()) { if (ma_has_neon()) {
router.useNEON = MA_TRUE; router.useNEON = MA_TRUE;
mal_timer timer; ma_timer timer;
mal_timer_init(&timer); ma_timer_init(&timer);
double startTime = mal_timer_get_time_in_seconds(&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) { if (framesRead != framesToRead) {
printf("Channel Router: An error occurred while reading NEON data.\n"); 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; router.useNEON = MA_FALSE;
if (!channel_router_test(channels, framesRead, (float**)ppOutBenchmark, (float**)ppOut)) { if (!channel_router_test(channels, framesRead, (float**)ppOutBenchmark, (float**)ppOut)) {
...@@ -844,48 +844,48 @@ int do_profiling__channel_routing() ...@@ -844,48 +844,48 @@ int do_profiling__channel_routing()
typedef struct typedef struct
{ {
float* pFrameData[MA_MAX_CHANNELS]; float* pFrameData[MA_MAX_CHANNELS];
mal_uint64 frameCount; ma_uint64 frameCount;
mal_uint32 channels; ma_uint32 channels;
double timeTaken; double timeTaken;
} src_reference_data; } src_reference_data;
typedef struct typedef struct
{ {
float* pFrameData[MA_MAX_CHANNELS]; float* pFrameData[MA_MAX_CHANNELS];
mal_uint64 frameCount; ma_uint64 frameCount;
mal_uint64 iNextFrame; ma_uint64 iNextFrame;
mal_uint32 channels; ma_uint32 channels;
} src_data; } 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; src_data* pBaseData = (src_data*)pUserData;
mal_assert(pBaseData != NULL); ma_assert(pBaseData != NULL);
mal_assert(pBaseData->iNextFrame <= pBaseData->frameCount); 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) { if (framesToRead > framesAvailable) {
framesToRead = framesAvailable; framesToRead = framesAvailable;
} }
if (framesToRead > 0) { if (framesToRead > 0) {
for (mal_uint32 iChannel = 0; iChannel < pSRC->config.channels; iChannel += 1) { for (ma_uint32 iChannel = 0; iChannel < pSRC->config.channels; iChannel += 1) {
mal_copy_memory(ppSamplesOut[iChannel], pBaseData->pFrameData[iChannel], (size_t)(framesToRead * sizeof(float))); ma_copy_memory(ppSamplesOut[iChannel], pBaseData->pFrameData[iChannel], (size_t)(framesToRead * sizeof(float)));
} }
} }
pBaseData->iNextFrame += framesToRead; 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); ma_assert(pBaseData != NULL);
mal_assert(pSRC != 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.sinc.windowWidth = 17; // <-- Make this an odd number to test unaligned section in the SIMD implementations.
srcConfig.algorithm = algorithm; srcConfig.algorithm = algorithm;
srcConfig.noSSE2 = MA_TRUE; srcConfig.noSSE2 = MA_TRUE;
...@@ -901,7 +901,7 @@ mal_result init_src(src_data* pBaseData, mal_uint32 sampleRateIn, mal_uint32 sam ...@@ -901,7 +901,7 @@ mal_result init_src(src_data* pBaseData, mal_uint32 sampleRateIn, mal_uint32 sam
default: break; default: break;
} }
mal_result result = mal_src_init(&srcConfig, pSRC); ma_result result = ma_src_init(&srcConfig, pSRC);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
printf("Failed to initialize sample rate converter.\n"); printf("Failed to initialize sample rate converter.\n");
return (int)result; return (int)result;
...@@ -910,17 +910,17 @@ mal_result init_src(src_data* pBaseData, mal_uint32 sampleRateIn, mal_uint32 sam ...@@ -910,17 +910,17 @@ mal_result init_src(src_data* pBaseData, mal_uint32 sampleRateIn, mal_uint32 sam
return result; 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); ma_assert(pBaseData != NULL);
mal_assert(pReferenceData != 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. // Make sure the base data is moved back to the start.
pBaseData->iNextFrame = 0; pBaseData->iNextFrame = 0;
mal_src src; ma_src src;
result = init_src(pBaseData, sampleRateIn, sampleRateOut, algorithm, mode, &src); result = init_src(pBaseData, sampleRateIn, sampleRateOut, algorithm, mode, &src);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
return (int)result; return (int)result;
...@@ -928,32 +928,32 @@ int do_profiling__src__profile_individual(src_data* pBaseData, mal_uint32 sample ...@@ -928,32 +928,32 @@ int do_profiling__src__profile_individual(src_data* pBaseData, mal_uint32 sample
// Profiling. // Profiling.
mal_uint64 sz = pReferenceData->frameCount * sizeof(float); ma_uint64 sz = pReferenceData->frameCount * sizeof(float);
mal_assert(sz <= SIZE_MAX); ma_assert(sz <= SIZE_MAX);
float* pFrameData[MA_MAX_CHANNELS]; float* pFrameData[MA_MAX_CHANNELS];
for (mal_uint32 iChannel = 0; iChannel < pBaseData->channels; iChannel += 1) { for (ma_uint32 iChannel = 0; iChannel < pBaseData->channels; iChannel += 1) {
pFrameData[iChannel] = (float*)mal_aligned_malloc((size_t)sz, MA_SIMD_ALIGNMENT); pFrameData[iChannel] = (float*)ma_aligned_malloc((size_t)sz, MA_SIMD_ALIGNMENT);
if (pFrameData[iChannel] == NULL) { if (pFrameData[iChannel] == NULL) {
printf("Out of memory.\n"); printf("Out of memory.\n");
return -2; return -2;
} }
mal_zero_memory(pFrameData[iChannel], (size_t)sz); ma_zero_memory(pFrameData[iChannel], (size_t)sz);
} }
mal_timer timer; ma_timer timer;
mal_timer_init(&timer); ma_timer_init(&timer);
double startTime = mal_timer_get_time_in_seconds(&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. // Correctness test.
mal_bool32 passed = MA_TRUE; ma_bool32 passed = MA_TRUE;
for (mal_uint32 iChannel = 0; iChannel < pReferenceData->channels; iChannel += 1) { for (ma_uint32 iChannel = 0; iChannel < pReferenceData->channels; iChannel += 1) {
for (mal_uint32 iFrame = 0; iFrame < pReferenceData->frameCount; iFrame += 1) { for (ma_uint32 iFrame = 0; iFrame < pReferenceData->frameCount; iFrame += 1) {
float s0 = pReferenceData->pFrameData[iChannel][iFrame]; float s0 = pReferenceData->pFrameData[iChannel][iFrame];
float s1 = pFrameData[iChannel][iFrame]; float s1 = pFrameData[iChannel][iFrame];
//if (s0 != s1) { //if (s0 != s1) {
...@@ -971,82 +971,82 @@ int do_profiling__src__profile_individual(src_data* pBaseData, mal_uint32 sample ...@@ -971,82 +971,82 @@ int do_profiling__src__profile_individual(src_data* pBaseData, mal_uint32 sample
} else { } else {
printf(" [FAILED] "); 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) { for (ma_uint32 iChannel = 0; iChannel < pBaseData->channels; iChannel += 1) {
mal_aligned_free(pFrameData[iChannel]); ma_aligned_free(pFrameData[iChannel]);
} }
return (int)result; 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. // Make sure the base data is back at the start.
pBaseData->iNextFrame = 0; pBaseData->iNextFrame = 0;
src_reference_data referenceData; src_reference_data referenceData;
mal_zero_object(&referenceData); ma_zero_object(&referenceData);
referenceData.channels = pBaseData->channels; 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 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. // 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) { if (referenceData.frameCount == 0) {
printf("Failed to calculate output frame count.\n"); printf("Failed to calculate output frame count.\n");
return -1; return -1;
} }
mal_uint64 sz = referenceData.frameCount * sizeof(float); ma_uint64 sz = referenceData.frameCount * sizeof(float);
mal_assert(sz <= SIZE_MAX); ma_assert(sz <= SIZE_MAX);
for (mal_uint32 iChannel = 0; iChannel < referenceData.channels; iChannel += 1) { for (ma_uint32 iChannel = 0; iChannel < referenceData.channels; iChannel += 1) {
referenceData.pFrameData[iChannel] = (float*)mal_aligned_malloc((size_t)sz, MA_SIMD_ALIGNMENT); referenceData.pFrameData[iChannel] = (float*)ma_aligned_malloc((size_t)sz, MA_SIMD_ALIGNMENT);
if (referenceData.pFrameData[iChannel] == NULL) { if (referenceData.pFrameData[iChannel] == NULL) {
printf("Out of memory.\n"); printf("Out of memory.\n");
return -2; return -2;
} }
mal_zero_memory(referenceData.pFrameData[iChannel], (size_t)sz); ma_zero_memory(referenceData.pFrameData[iChannel], (size_t)sz);
} }
// Generate the reference data. // Generate the reference data.
mal_src src; ma_src src;
mal_result result = init_src(pBaseData, sampleRateIn, sampleRateOut, algorithm, simd_mode_scalar, &src); ma_result result = init_src(pBaseData, sampleRateIn, sampleRateOut, algorithm, simd_mode_scalar, &src);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
return (int)result; return (int)result;
} }
mal_timer timer; ma_timer timer;
mal_timer_init(&timer); ma_timer_init(&timer);
double startTime = mal_timer_get_time_in_seconds(&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. // 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); 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); 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); 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); 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); do_profiling__src__profile_individual(pBaseData, sampleRateIn, sampleRateOut, algorithm, simd_mode_neon, &referenceData);
} }
for (mal_uint32 iChannel = 0; iChannel < referenceData.channels; iChannel += 1) { for (ma_uint32 iChannel = 0; iChannel < referenceData.channels; iChannel += 1) {
mal_aligned_free(referenceData.pFrameData[iChannel]); ma_aligned_free(referenceData.pFrameData[iChannel]);
} }
return 0; return 0;
...@@ -1059,31 +1059,31 @@ int do_profiling__src() ...@@ -1059,31 +1059,31 @@ int do_profiling__src()
// Set up base data. // Set up base data.
src_data baseData; src_data baseData;
mal_zero_object(&baseData); ma_zero_object(&baseData);
baseData.channels = 8; baseData.channels = 8;
baseData.frameCount = 100000; baseData.frameCount = 100000;
for (mal_uint32 iChannel = 0; iChannel < baseData.channels; ++iChannel) { for (ma_uint32 iChannel = 0; iChannel < baseData.channels; ++iChannel) {
baseData.pFrameData[iChannel] = (float*)mal_aligned_malloc((size_t)(baseData.frameCount * sizeof(float)), MA_SIMD_ALIGNMENT); baseData.pFrameData[iChannel] = (float*)ma_aligned_malloc((size_t)(baseData.frameCount * sizeof(float)), MA_SIMD_ALIGNMENT);
if (baseData.pFrameData[iChannel] == NULL) { if (baseData.pFrameData[iChannel] == NULL) {
printf("Out of memory.\n"); printf("Out of memory.\n");
return -1; return -1;
} }
mal_sine_wave sineWave; ma_sine_wave sineWave;
mal_sine_wave_init(1.0f, 400 + (iChannel*50), 48000, &sineWave); ma_sine_wave_init(1.0f, 400 + (iChannel*50), 48000, &sineWave);
mal_sine_wave_read_f32(&sineWave, baseData.frameCount, baseData.pFrameData[iChannel]); ma_sine_wave_read_f32(&sineWave, baseData.frameCount, baseData.pFrameData[iChannel]);
} }
// Upsampling. // 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. // 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) { for (ma_uint32 iChannel = 0; iChannel < baseData.channels; iChannel += 1) {
mal_aligned_free(baseData.pFrameData[iChannel]); ma_aligned_free(baseData.pFrameData[iChannel]);
} }
return 0; return 0;
...@@ -1128,22 +1128,22 @@ int main(int argc, char** argv) ...@@ -1128,22 +1128,22 @@ int main(int argc, char** argv)
// Summary. // Summary.
if (mal_has_sse2()) { if (ma_has_sse2()) {
printf("Has SSE2: YES\n"); printf("Has SSE2: YES\n");
} else { } else {
printf("Has SSE2: NO\n"); printf("Has SSE2: NO\n");
} }
if (mal_has_avx2()) { if (ma_has_avx2()) {
printf("Has AVX2: YES\n"); printf("Has AVX2: YES\n");
} else { } else {
printf("Has AVX2: NO\n"); printf("Has AVX2: NO\n");
} }
if (mal_has_avx512f()) { if (ma_has_avx512f()) {
printf("Has AVX-512F: YES\n"); printf("Has AVX-512F: YES\n");
} else { } else {
printf("Has AVX-512F: NO\n"); printf("Has AVX-512F: NO\n");
} }
if (mal_has_neon()) { if (ma_has_neon()) {
printf("Has NEON: YES\n"); printf("Has NEON: YES\n");
} else { } else {
printf("Has NEON: NO\n"); printf("Has NEON: NO\n");
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
#endif #endif
// There is a usage pattern for resampling that miniaudio does not properly support which is where the client continuously // 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 // 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 mal_src_read() (assuming the client // 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). // has re-filled the resampler's input data).
/* /*
...@@ -22,72 +22,72 @@ for (;;) { ...@@ -22,72 +22,72 @@ for (;;) {
fill_src_input_data(&src, someData); fill_src_input_data(&src, someData);
float buffer[4096] float buffer[4096]
while ((framesRead = mal_src_read(&src, ...) != 0) { while ((framesRead = ma_src_read(&src, ...) != 0) {
do_something_with_resampled_data(buffer); 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. // from in order to calculate the correct interpolation factor which in turn results in crackling.
mal_uint32 sampleRateIn = 0; ma_uint32 sampleRateIn = 0;
mal_uint32 sampleRateOut = 0; ma_uint32 sampleRateOut = 0;
mal_sine_wave sineWave; // <-- This is the source data. ma_sine_wave sineWave; // <-- This is the source data.
mal_src src; ma_src src;
float srcInput[1024]; float srcInput[1024];
mal_uint32 srcNextSampleIndex = mal_countof(srcInput); ma_uint32 srcNextSampleIndex = ma_countof(srcInput);
void reload_src_input() 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; 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); ma_assert(pSRC != NULL);
mal_assert(pSRC->config.channels == 1); ma_assert(pSRC->config.channels == 1);
(void)pUserData; (void)pUserData;
// Only read as much as is available in the input buffer. Do not reload the buffer here. // Only read as much as is available in the input buffer. Do not reload the buffer here.
mal_uint32 framesAvailable = mal_countof(srcInput) - srcNextSampleIndex; ma_uint32 framesAvailable = ma_countof(srcInput) - srcNextSampleIndex;
mal_uint32 framesToRead = frameCount; ma_uint32 framesToRead = frameCount;
if (framesToRead > framesAvailable) { if (framesToRead > framesAvailable) {
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; srcNextSampleIndex += framesToRead;
return 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)pDevice;
(void)pInput; (void)pInput;
mal_assert(pDevice->playback.format == mal_format_f32); ma_assert(pDevice->playback.format == ma_format_f32);
mal_assert(pDevice->playback.channels == 1); ma_assert(pDevice->playback.channels == 1);
float* pFramesF32 = (float*)pOutput; 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 // 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. // 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) { while (totalFramesRead < frameCount) {
mal_uint32 framesRemaining = frameCount - totalFramesRead; ma_uint32 framesRemaining = frameCount - totalFramesRead;
mal_uint32 maxFramesToRead = 128; ma_uint32 maxFramesToRead = 128;
mal_uint32 framesToRead = framesRemaining; ma_uint32 framesToRead = framesRemaining;
if (framesToRead > maxFramesToRead) { if (framesToRead > maxFramesToRead) {
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) { if (framesRead == 0) {
reload_src_input(); reload_src_input();
} }
...@@ -96,7 +96,7 @@ void on_send_to_device(mal_device* pDevice, void* pOutput, const void* pInput, m ...@@ -96,7 +96,7 @@ void on_send_to_device(mal_device* pDevice, void* pOutput, const void* pInput, m
pFramesF32 += framesRead; pFramesF32 += framesRead;
} }
mal_assert(totalFramesRead == frameCount); ma_assert(totalFramesRead == frameCount);
} }
int main(int argc, char** argv) int main(int argc, char** argv)
...@@ -105,18 +105,18 @@ int main(int argc, char** argv) ...@@ -105,18 +105,18 @@ int main(int argc, char** argv)
(void)argv; (void)argv;
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 = mal_format_f32; config.playback.format = ma_format_f32;
config.playback.channels = 1; config.playback.channels = 1;
config.dataCallback = on_send_to_device; config.dataCallback = on_send_to_device;
mal_device device; ma_device device;
mal_result result; ma_result result;
config.bufferSizeInFrames = 8192*1; config.bufferSizeInFrames = 8192*1;
// We first play the sound the way it's meant to be played. // 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) { if (result != MA_SUCCESS) {
return -1; return -1;
} }
...@@ -125,13 +125,13 @@ int main(int argc, char** argv) ...@@ -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. // For this test, we need the sine wave to be a different format to the device.
sampleRateOut = device.sampleRate; sampleRateOut = device.sampleRate;
sampleRateIn = (sampleRateOut == 44100) ? 48000 : 44100; 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); ma_src_config srcConfig = ma_src_config_init(sampleRateIn, sampleRateOut, 1, on_src, NULL);
srcConfig.algorithm = mal_src_algorithm_sinc; srcConfig.algorithm = ma_src_algorithm_sinc;
srcConfig.neverConsumeEndOfInput = MA_TRUE; srcConfig.neverConsumeEndOfInput = MA_TRUE;
result = mal_src_init(&srcConfig, &src); result = ma_src_init(&srcConfig, &src);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
printf("Failed to create SRC.\n"); printf("Failed to create SRC.\n");
return -1; return -1;
...@@ -158,7 +158,7 @@ int main(int argc, char** argv) ...@@ -158,7 +158,7 @@ int main(int argc, char** argv)
msigvis_channel channelSineWave; 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) { if (result != MA_SUCCESS) {
printf("Failed to initialize mini_sigvis channel.\n"); printf("Failed to initialize mini_sigvis channel.\n");
return -3; return -3;
...@@ -168,17 +168,17 @@ int main(int argc, char** argv) ...@@ -168,17 +168,17 @@ int main(int argc, char** argv)
float* pFramesF32 = testSamples; 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 // 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. // 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 < mal_countof(testSamples)) { while (totalFramesRead < ma_countof(testSamples)) {
mal_uint32 maxFramesToRead = 128; ma_uint32 maxFramesToRead = 128;
mal_uint32 framesToRead = mal_countof(testSamples); ma_uint32 framesToRead = ma_countof(testSamples);
if (framesToRead > maxFramesToRead) { if (framesToRead > maxFramesToRead) {
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) { if (framesRead == 0) {
reload_src_input(); reload_src_input();
} }
...@@ -187,7 +187,7 @@ int main(int argc, char** argv) ...@@ -187,7 +187,7 @@ int main(int argc, char** argv)
pFramesF32 += framesRead; 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); msigvis_screen_add_channel(&screen, &channelSineWave);
...@@ -197,14 +197,14 @@ int main(int argc, char** argv) ...@@ -197,14 +197,14 @@ int main(int argc, char** argv)
msigvis_uninit(&sigvis); msigvis_uninit(&sigvis);
#else #else
result = mal_device_start(&device); result = ma_device_start(&device);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
return -2; return -2;
} }
printf("Press Enter to quit...\n"); printf("Press Enter to quit...\n");
getchar(); getchar();
mal_device_uninit(&device); ma_device_uninit(&device);
#endif #endif
return 0; return 0;
......
...@@ -3,38 +3,38 @@ ...@@ -3,38 +3,38 @@
#define MINIAUDIO_IMPLEMENTATION #define MINIAUDIO_IMPLEMENTATION
#include "../miniaudio.h" #include "../miniaudio.h"
mal_sine_wave sineWave; ma_sine_wave sineWave;
mal_uint32 framesWritten; ma_uint32 framesWritten;
mal_event stopEvent; ma_event stopEvent;
mal_bool32 isInitialRun = MA_TRUE; ma_bool32 isInitialRun = MA_TRUE;
void on_stop(mal_device* pDevice) void on_stop(ma_device* pDevice)
{ {
(void)pDevice; (void)pDevice;
printf("STOPPED\n"); 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. */ (void)pInput; /* Not used yet. */
/* Output exactly one second of data. Pad the end with silence. */ /* Output exactly one second of data. Pad the end with silence. */
mal_uint32 framesRemaining = pDevice->sampleRate - framesWritten; ma_uint32 framesRemaining = pDevice->sampleRate - framesWritten;
mal_uint32 framesToProcess = frameCount; ma_uint32 framesToProcess = frameCount;
if (framesToProcess > framesRemaining && isInitialRun) { if (framesToProcess > framesRemaining && isInitialRun) {
framesToProcess = framesRemaining; 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) { if (isInitialRun) {
framesWritten += framesToProcess; framesWritten += framesToProcess;
} }
mal_assert(framesWritten <= pDevice->sampleRate); ma_assert(framesWritten <= pDevice->sampleRate);
if (framesWritten >= pDevice->sampleRate) { if (framesWritten >= pDevice->sampleRate) {
if (isInitialRun) { if (isInitialRun) {
printf("STOPPING [AUDIO THREAD]...\n"); printf("STOPPING [AUDIO THREAD]...\n");
mal_event_signal(&stopEvent); ma_event_signal(&stopEvent);
isInitialRun = MA_FALSE; isInitialRun = MA_FALSE;
} }
} }
...@@ -42,57 +42,57 @@ void on_data(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 ...@@ -42,57 +42,57 @@ void on_data(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
mal_result result; ma_result result;
(void)argc; (void)argc;
(void)argv; (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); ma_device_config config = ma_device_config_init(ma_device_type_playback);
config.playback.format = mal_format_f32; config.playback.format = ma_format_f32;
config.playback.channels = 2; config.playback.channels = 2;
config.sampleRate = 44100; config.sampleRate = 44100;
config.dataCallback = on_data; config.dataCallback = on_data;
config.stopCallback = on_stop; config.stopCallback = on_stop;
config.bufferSizeInFrames = 16384; config.bufferSizeInFrames = 16384;
mal_device device; ma_device device;
result = mal_device_init_ex(&backend, 1, NULL, &config, &device); result = ma_device_init_ex(&backend, 1, NULL, &config, &device);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
printf("Failed to initialize device.\n"); printf("Failed to initialize device.\n");
return result; return result;
} }
result = mal_event_init(device.pContext, &stopEvent); result = ma_event_init(device.pContext, &stopEvent);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
printf("Failed to initialize stop event.\n"); printf("Failed to initialize stop event.\n");
return result; 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. */ /* 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"); printf("STOPPING [MAIN THREAD]...\n");
mal_device_stop(&device); ma_device_stop(&device);
printf("Press Enter to restart...\n"); printf("Press Enter to restart...\n");
getchar(); getchar();
result = mal_device_start(&device); result = ma_device_start(&device);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
printf("Failed to restart the device.\n"); printf("Failed to restart the device.\n");
mal_device_uninit(&device); ma_device_uninit(&device);
return -1; return -1;
} }
printf("Press Enter to quit...\n"); printf("Press Enter to quit...\n");
getchar(); getchar();
mal_device_uninit(&device); ma_device_uninit(&device);
return 0; return 0;
} }
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
#include "mal_test_0.c" #include "ma_test_0.c"
\ No newline at end of file \ No newline at end of file
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">
<ProjectGuid>{3430EEA2-AC6E-4DC7-B684-1F698D01FAE8}</ProjectGuid> <ProjectGuid>{3430EEA2-AC6E-4DC7-B684-1F698D01FAE8}</ProjectGuid>
<Keyword>Win32Proj</Keyword> <Keyword>Win32Proj</Keyword>
<RootNamespace>mal_test_0</RootNamespace> <RootNamespace>ma_test_0</RootNamespace>
<WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion> <WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
...@@ -262,7 +262,7 @@ ...@@ -262,7 +262,7 @@
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\debugging\source\mal_router_1.c"> <ClCompile Include="..\debugging\source\ma_router_1.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
...@@ -302,7 +302,7 @@ ...@@ -302,7 +302,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClCompile Include="..\research\tests\mal_resampler_test_0.c"> <ClCompile Include="..\research\tests\ma_resampler_test_0.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
...@@ -310,7 +310,7 @@ ...@@ -310,7 +310,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClCompile Include="mal_dithering.c"> <ClCompile Include="ma_dithering.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
...@@ -318,7 +318,7 @@ ...@@ -318,7 +318,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClCompile Include="mal_duplex.c"> <ClCompile Include="ma_duplex.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
...@@ -326,7 +326,7 @@ ...@@ -326,7 +326,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClCompile Include="mal_no_device_io.c"> <ClCompile Include="ma_no_device_io.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
...@@ -334,7 +334,7 @@ ...@@ -334,7 +334,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClCompile Include="mal_profiling.c"> <ClCompile Include="ma_profiling.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
...@@ -342,7 +342,7 @@ ...@@ -342,7 +342,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClCompile Include="mal_resampling.c"> <ClCompile Include="ma_resampling.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
...@@ -350,7 +350,7 @@ ...@@ -350,7 +350,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClCompile Include="mal_stop.c"> <ClCompile Include="ma_stop.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
...@@ -358,7 +358,7 @@ ...@@ -358,7 +358,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClCompile Include="mal_test_0.c"> <ClCompile Include="ma_test_0.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
...@@ -366,7 +366,7 @@ ...@@ -366,7 +366,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClCompile Include="mal_test_0.cpp"> <ClCompile Include="ma_test_0.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">false</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild>
...@@ -377,7 +377,7 @@ ...@@ -377,7 +377,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\miniaudio.h" /> <ClInclude Include="..\miniaudio.h" />
<ClInclude Include="..\research\mal_resampler.h" /> <ClInclude Include="..\research\ma_resampler.h" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
......
...@@ -15,40 +15,40 @@ ...@@ -15,40 +15,40 @@
</Filter> </Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="mal_test_0.c"> <ClCompile Include="ma_test_0.c">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="mal_test_0.cpp"> <ClCompile Include="ma_test_0.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="mal_profiling.c"> <ClCompile Include="ma_profiling.c">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="mal_dithering.c"> <ClCompile Include="ma_dithering.c">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="mal_resampling.c"> <ClCompile Include="ma_resampling.c">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="mal_no_device_io.c"> <ClCompile Include="ma_no_device_io.c">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\research\tests\mal_resampler_test_0.c"> <ClCompile Include="..\research\tests\ma_resampler_test_0.c">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\examples\simple_playback.c"> <ClCompile Include="..\examples\simple_playback.c">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\debugging\source\mal_router_1.c"> <ClCompile Include="..\debugging\source\ma_router_1.c">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\examples\simple_enumeration.c"> <ClCompile Include="..\examples\simple_enumeration.c">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="mal_duplex.c"> <ClCompile Include="ma_duplex.c">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="mal_stop.c"> <ClCompile Include="ma_stop.c">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\examples\simple_capture.c"> <ClCompile Include="..\examples\simple_capture.c">
...@@ -62,7 +62,7 @@ ...@@ -62,7 +62,7 @@
<ClInclude Include="..\miniaudio.h"> <ClInclude Include="..\miniaudio.h">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\research\mal_resampler.h"> <ClInclude Include="..\research\ma_resampler.h">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClInclude> </ClInclude>
</ItemGroup> </ItemGroup>
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
<script> <script>
var runningTime = 0.0; var runningTime = 0.0;
function mal_enum_devices(deviceType) { function ma_enum_devices(deviceType) {
if (deviceType !== 'audiooutput' && deviceType !== 'audioinput') { if (deviceType !== 'audiooutput' && deviceType !== 'audioinput') {
alert("Invalid device type: " + deviceType); alert("Invalid device type: " + deviceType);
return null; return null;
...@@ -71,7 +71,7 @@ ...@@ -71,7 +71,7 @@
return promise; return promise;
} }
function mal_device_new(deviceType, deviceID) { function ma_device_new(deviceType, deviceID) {
if (typeof(mal) === 'undefined') { if (typeof(mal) === 'undefined') {
return null; // Context not initialized. return null; // Context not initialized.
} }
...@@ -202,11 +202,11 @@ ...@@ -202,11 +202,11 @@
return device; return device;
} }
function mal_device_delete(device) { function ma_device_delete(device) {
Module._free(device.intermediaryBuffer); Module._free(device.intermediaryBuffer);
} }
function mal_context_init() { function ma_context_init() {
if ((window.AudioContext || window.webkitAudioContext) === undefined) { if ((window.AudioContext || window.webkitAudioContext) === undefined) {
return 0; // Web Audio not supported. return 0; // Web Audio not supported.
} }
...@@ -235,7 +235,7 @@ ...@@ -235,7 +235,7 @@
}; };
mal.untrack_device_by_index = function(deviceIndex) { 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[iDevice] = null; mal.devices[iDevice] = null;
// Trim the array if possible. // Trim the array if possible.
...@@ -265,14 +265,14 @@ ...@@ -265,14 +265,14 @@
} }
window.onload = function() { window.onload = function() {
if (mal_context_init() != 1) { if (ma_context_init() != 1) {
alert("Failed to initialize context."); alert("Failed to initialize context.");
return; return;
} }
// Unfortunately this doesn't seem to work too well. See comment in mal_enum_devices(). // Unfortunately this doesn't seem to work too well. See comment in ma_enum_devices().
mal_enum_devices('audiooutput').then(function(outputDevices) { ma_enum_devices('audiooutput').then(function(outputDevices) {
for (var iDevice = 0; iDevice < outputDevices.length; ++iDevice) { for (var iDevice = 0; iDevice < outputDevices.length; ++iDevice) {
console.log("Output Device: ", JSON.stringify(outputDevices[iDevice])); console.log("Output Device: ", JSON.stringify(outputDevices[iDevice]));
} }
...@@ -280,7 +280,7 @@ ...@@ -280,7 +280,7 @@
console.log("Failed to retrieve output devices: ", error); console.log("Failed to retrieve output devices: ", error);
}); });
mal_enum_devices('audioinput').then(function(inputDevices) { ma_enum_devices('audioinput').then(function(inputDevices) {
for (var iDevice = 0; iDevice < inputDevices.length; ++iDevice) { for (var iDevice = 0; iDevice < inputDevices.length; ++iDevice) {
console.log("Input Device: ", JSON.stringify(inputDevices[iDevice])); console.log("Input Device: ", JSON.stringify(inputDevices[iDevice]));
} }
...@@ -289,8 +289,8 @@ ...@@ -289,8 +289,8 @@
}); });
var outputDevice = mal_device_new('audiooutput', null); var outputDevice = ma_device_new('audiooutput', null);
var inputDevice = mal_device_new('audioinput', null); var inputDevice = ma_device_new('audioinput', null);
var btnStartPlayback = document.getElementById("btnStartPlayback"); var btnStartPlayback = document.getElementById("btnStartPlayback");
btnStartPlayback.addEventListener('click', function() { btnStartPlayback.addEventListener('click', function() {
......
...@@ -36,37 +36,37 @@ struct msigvis_screen ...@@ -36,37 +36,37 @@ struct msigvis_screen
struct msigvis_channel struct msigvis_channel
{ {
mal_format format; ma_format format;
mal_uint32 sampleRate; ma_uint32 sampleRate;
dtk_color color; dtk_color color;
mal_uint32 sampleCount; ma_uint32 sampleCount;
mal_uint32 bufferCapInSamples; ma_uint32 bufferCapInSamples;
mal_uint8* pBuffer; // The buffer containing the sample to visualize. ma_uint8* pBuffer; // The buffer containing the sample to visualize.
}; };
// Context // Context
mal_result msigvis_init(msigvis_context* pContext); ma_result msigvis_init(msigvis_context* pContext);
void msigvis_uninit(msigvis_context* pContext); void msigvis_uninit(msigvis_context* pContext);
int msigvis_run(msigvis_context* pContext); int msigvis_run(msigvis_context* pContext);
// Screen // Screen
mal_result msigvis_screen_init(msigvis_context* pContext, mal_uint32 screenWidth, mal_uint32 screenHeight, msigvis_screen* pScreen); ma_result msigvis_screen_init(msigvis_context* pContext, ma_uint32 screenWidth, ma_uint32 screenHeight, msigvis_screen* pScreen);
void msigvis_screen_uninit(msigvis_screen* pScreen); void msigvis_screen_uninit(msigvis_screen* pScreen);
mal_result msigvis_screen_show(msigvis_screen* pScreen); ma_result msigvis_screen_show(msigvis_screen* pScreen);
mal_result msigvis_screen_hide(msigvis_screen* pScreen); ma_result msigvis_screen_hide(msigvis_screen* pScreen);
mal_result msigvis_screen_add_channel(msigvis_screen* pScreen, msigvis_channel* pChannel); ma_result msigvis_screen_add_channel(msigvis_screen* pScreen, msigvis_channel* pChannel);
mal_result msigvis_screen_remove_channel(msigvis_screen* pScreen, msigvis_channel* pChannel); ma_result msigvis_screen_remove_channel(msigvis_screen* pScreen, msigvis_channel* pChannel);
mal_result msigvis_screen_remove_channel_by_index(msigvis_screen* pScreen, mal_uint32 iChannel); ma_result msigvis_screen_remove_channel_by_index(msigvis_screen* pScreen, ma_uint32 iChannel);
mal_result msigvis_screen_find_channel_index(msigvis_screen* pScreen, msigvis_channel* pChannel, mal_uint32* pIndex); ma_result msigvis_screen_find_channel_index(msigvis_screen* pScreen, msigvis_channel* pChannel, ma_uint32* pIndex);
mal_result msigvis_screen_redraw(msigvis_screen* pScreen); ma_result msigvis_screen_redraw(msigvis_screen* pScreen);
// Channel // Channel
mal_result msigvis_channel_init(msigvis_context* pContext, mal_format format, mal_uint32 sampleRate, msigvis_channel* pChannel); ma_result msigvis_channel_init(msigvis_context* pContext, ma_format format, ma_uint32 sampleRate, msigvis_channel* pChannel);
void msigvis_channel_uninit(msigvis_channel* pChannel); void msigvis_channel_uninit(msigvis_channel* pChannel);
mal_result msigvis_channel_push_samples(msigvis_channel* pChannel, mal_uint32 sampleCount, const void* pSamples); ma_result msigvis_channel_push_samples(msigvis_channel* pChannel, ma_uint32 sampleCount, const void* pSamples);
mal_result msigvis_channel_pop_samples(msigvis_channel* pChannel, mal_uint32 sampleCount); ma_result msigvis_channel_pop_samples(msigvis_channel* pChannel, ma_uint32 sampleCount);
float msigvis_channel_get_sample_f32(msigvis_channel* pChannel, mal_uint32 iSample); float msigvis_channel_get_sample_f32(msigvis_channel* pChannel, ma_uint32 iSample);
#ifdef __cplusplus #ifdef __cplusplus
} }
...@@ -86,19 +86,19 @@ float msigvis_channel_get_sample_f32(msigvis_channel* pChannel, mal_uint32 iSamp ...@@ -86,19 +86,19 @@ float msigvis_channel_get_sample_f32(msigvis_channel* pChannel, mal_uint32 iSamp
#include "../../miniaudio.h" #include "../../miniaudio.h"
#include "../external/dred/source/dred/dtk/dtk.c" #include "../external/dred/source/dred/dtk/dtk.c"
mal_result msigvis_result_from_dtk(dtk_result resultDTK) ma_result msigvis_result_from_dtk(dtk_result resultDTK)
{ {
return (mal_result)resultDTK; return (ma_result)resultDTK;
} }
mal_result msigvis_init(msigvis_context* pContext) ma_result msigvis_init(msigvis_context* pContext)
{ {
if (pContext == NULL) { if (pContext == NULL) {
return MA_INVALID_ARGS; return MA_INVALID_ARGS;
} }
mal_zero_object(pContext); ma_zero_object(pContext);
// DTK context. // DTK context.
dtk_result resultDTK = dtk_init(&pContext->tk, NULL, pContext); dtk_result resultDTK = dtk_init(&pContext->tk, NULL, pContext);
...@@ -188,23 +188,23 @@ dtk_bool32 msigvis_window_event_handler(dtk_event* pEvent) ...@@ -188,23 +188,23 @@ dtk_bool32 msigvis_window_event_handler(dtk_event* pEvent)
float baseSampleSpacingX = (screenSizeX / (float)(pScreen->sampleRate/10)) * pScreen->zoomX; float baseSampleSpacingX = (screenSizeX / (float)(pScreen->sampleRate/10)) * pScreen->zoomX;
float baseSampleSpacingY = ((screenSizeY/1) / 2.0f) * pScreen->zoomY; float baseSampleSpacingY = ((screenSizeY/1) / 2.0f) * pScreen->zoomY;
for (mal_uint32 iChannel = 0; iChannel < pScreen->channelCount; ++iChannel) { for (ma_uint32 iChannel = 0; iChannel < pScreen->channelCount; ++iChannel) {
msigvis_channel* pChannel = pScreen->ppChannels[iChannel]; msigvis_channel* pChannel = pScreen->ppChannels[iChannel];
float spacingFactorX = pScreen->sampleRate / (float)pChannel->sampleRate; float spacingFactorX = pScreen->sampleRate / (float)pChannel->sampleRate;
float sampleSpacingX = baseSampleSpacingX * spacingFactorX; float sampleSpacingX = baseSampleSpacingX * spacingFactorX;
float sampleSpacingY = baseSampleSpacingY; float sampleSpacingY = baseSampleSpacingY;
mal_uint32 sampleInterval = 1; ma_uint32 sampleInterval = 1;
if (sampleSpacingX < 1) { if (sampleSpacingX < 1) {
sampleInterval = (mal_uint32)(1/sampleSpacingX); sampleInterval = (ma_uint32)(1/sampleSpacingX);
} }
if (sampleInterval == 0) { if (sampleInterval == 0) {
sampleInterval = 1; // Safety. sampleInterval = 1; // Safety.
} }
mal_uint32 iFirstSample = 0; ma_uint32 iFirstSample = 0;
for (mal_uint32 iSample = iFirstSample; iSample < pChannel->sampleCount; iSample += sampleInterval) { for (ma_uint32 iSample = iFirstSample; iSample < pChannel->sampleCount; iSample += sampleInterval) {
float samplePosX = iSample * sampleSpacingX; float samplePosX = iSample * sampleSpacingX;
float samplePosY = msigvis_channel_get_sample_f32(pChannel, iSample) * sampleSpacingY * -1; // Invert the Y axis for graphics output. float samplePosY = msigvis_channel_get_sample_f32(pChannel, iSample) * sampleSpacingY * -1; // Invert the Y axis for graphics output.
...@@ -226,13 +226,13 @@ dtk_bool32 msigvis_window_event_handler(dtk_event* pEvent) ...@@ -226,13 +226,13 @@ dtk_bool32 msigvis_window_event_handler(dtk_event* pEvent)
return dtk_window_default_event_handler(pEvent); return dtk_window_default_event_handler(pEvent);
} }
mal_result msigvis_screen_init(msigvis_context* pContext, mal_uint32 screenWidth, mal_uint32 screenHeight, msigvis_screen* pScreen) ma_result msigvis_screen_init(msigvis_context* pContext, ma_uint32 screenWidth, ma_uint32 screenHeight, msigvis_screen* pScreen)
{ {
if (pScreen == NULL) { if (pScreen == NULL) {
return DTK_INVALID_ARGS; return DTK_INVALID_ARGS;
} }
mal_zero_object(pScreen); ma_zero_object(pScreen);
dtk_result resultDTK = dtk_window_init(&pContext->tk, msigvis_window_event_handler, NULL, dtk_window_type_toplevel, "mini_sigvis", screenWidth, screenHeight, &pScreen->window); dtk_result resultDTK = dtk_window_init(&pContext->tk, msigvis_window_event_handler, NULL, dtk_window_type_toplevel, "mini_sigvis", screenWidth, screenHeight, &pScreen->window);
if (resultDTK != DTK_SUCCESS) { if (resultDTK != DTK_SUCCESS) {
...@@ -258,7 +258,7 @@ void msigvis_screen_uninit(msigvis_screen* pScreen) ...@@ -258,7 +258,7 @@ void msigvis_screen_uninit(msigvis_screen* pScreen)
dtk_window_uninit(&pScreen->window); dtk_window_uninit(&pScreen->window);
} }
mal_result msigvis_screen_show(msigvis_screen* pScreen) ma_result msigvis_screen_show(msigvis_screen* pScreen)
{ {
if (pScreen == NULL) { if (pScreen == NULL) {
return MA_INVALID_ARGS; return MA_INVALID_ARGS;
...@@ -267,7 +267,7 @@ mal_result msigvis_screen_show(msigvis_screen* pScreen) ...@@ -267,7 +267,7 @@ mal_result msigvis_screen_show(msigvis_screen* pScreen)
return msigvis_result_from_dtk(dtk_window_show(&pScreen->window, DTK_SHOW_NORMAL)); return msigvis_result_from_dtk(dtk_window_show(&pScreen->window, DTK_SHOW_NORMAL));
} }
mal_result msigvis_screen_hide(msigvis_screen* pScreen) ma_result msigvis_screen_hide(msigvis_screen* pScreen)
{ {
if (pScreen == NULL) { if (pScreen == NULL) {
return MA_INVALID_ARGS; return MA_INVALID_ARGS;
...@@ -276,7 +276,7 @@ mal_result msigvis_screen_hide(msigvis_screen* pScreen) ...@@ -276,7 +276,7 @@ mal_result msigvis_screen_hide(msigvis_screen* pScreen)
return msigvis_result_from_dtk(dtk_window_hide(&pScreen->window)); return msigvis_result_from_dtk(dtk_window_hide(&pScreen->window));
} }
mal_result msigvis_screen_add_channel(msigvis_screen* pScreen, msigvis_channel* pChannel) ma_result msigvis_screen_add_channel(msigvis_screen* pScreen, msigvis_channel* pChannel)
{ {
if (pScreen == NULL || pChannel == NULL) { if (pScreen == NULL || pChannel == NULL) {
return MA_INVALID_ARGS; return MA_INVALID_ARGS;
...@@ -284,12 +284,12 @@ mal_result msigvis_screen_add_channel(msigvis_screen* pScreen, msigvis_channel* ...@@ -284,12 +284,12 @@ mal_result msigvis_screen_add_channel(msigvis_screen* pScreen, msigvis_channel*
// Expand if necessary. // Expand if necessary.
if (pScreen->channelCap == pScreen->channelCount) { if (pScreen->channelCap == pScreen->channelCount) {
mal_uint32 newCap = pScreen->channelCap*2; ma_uint32 newCap = pScreen->channelCap*2;
if (newCap == 0) { if (newCap == 0) {
newCap = 1; newCap = 1;
} }
msigvis_channel** ppNewBuffer = (msigvis_channel**)mal_realloc(pScreen->ppChannels, sizeof(*pScreen->ppChannels)*newCap); msigvis_channel** ppNewBuffer = (msigvis_channel**)ma_realloc(pScreen->ppChannels, sizeof(*pScreen->ppChannels)*newCap);
if (ppNewBuffer == NULL) { if (ppNewBuffer == NULL) {
return MA_OUT_OF_MEMORY; return MA_OUT_OF_MEMORY;
} }
...@@ -305,14 +305,14 @@ mal_result msigvis_screen_add_channel(msigvis_screen* pScreen, msigvis_channel* ...@@ -305,14 +305,14 @@ mal_result msigvis_screen_add_channel(msigvis_screen* pScreen, msigvis_channel*
return MA_SUCCESS; return MA_SUCCESS;
} }
mal_result msigvis_screen_remove_channel(msigvis_screen* pScreen, msigvis_channel* pChannel) ma_result msigvis_screen_remove_channel(msigvis_screen* pScreen, msigvis_channel* pChannel)
{ {
if (pScreen == NULL || pChannel == NULL) { if (pScreen == NULL || pChannel == NULL) {
return MA_INVALID_ARGS; return MA_INVALID_ARGS;
} }
mal_uint32 iChannel; ma_uint32 iChannel;
mal_result result = msigvis_screen_find_channel_index(pScreen, pChannel, &iChannel); ma_result result = msigvis_screen_find_channel_index(pScreen, pChannel, &iChannel);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
return result; return result;
} }
...@@ -320,7 +320,7 @@ mal_result msigvis_screen_remove_channel(msigvis_screen* pScreen, msigvis_channe ...@@ -320,7 +320,7 @@ mal_result msigvis_screen_remove_channel(msigvis_screen* pScreen, msigvis_channe
return msigvis_screen_remove_channel_by_index(pScreen, iChannel); return msigvis_screen_remove_channel_by_index(pScreen, iChannel);
} }
mal_result msigvis_screen_remove_channel_by_index(msigvis_screen* pScreen, mal_uint32 iChannel) ma_result msigvis_screen_remove_channel_by_index(msigvis_screen* pScreen, ma_uint32 iChannel)
{ {
if (pScreen == NULL || iChannel > pScreen->channelCount) { if (pScreen == NULL || iChannel > pScreen->channelCount) {
return MA_INVALID_ARGS; return MA_INVALID_ARGS;
...@@ -340,13 +340,13 @@ mal_result msigvis_screen_remove_channel_by_index(msigvis_screen* pScreen, mal_u ...@@ -340,13 +340,13 @@ mal_result msigvis_screen_remove_channel_by_index(msigvis_screen* pScreen, mal_u
return MA_SUCCESS; return MA_SUCCESS;
} }
mal_result msigvis_screen_find_channel_index(msigvis_screen* pScreen, msigvis_channel* pChannel, mal_uint32* pIndex) ma_result msigvis_screen_find_channel_index(msigvis_screen* pScreen, msigvis_channel* pChannel, ma_uint32* pIndex)
{ {
if (pScreen == NULL || pChannel == NULL) { if (pScreen == NULL || pChannel == NULL) {
return MA_INVALID_ARGS; return MA_INVALID_ARGS;
} }
for (mal_uint32 iChannel = 0; iChannel < pScreen->channelCount; ++iChannel) { for (ma_uint32 iChannel = 0; iChannel < pScreen->channelCount; ++iChannel) {
if (pScreen->ppChannels[iChannel] == pChannel) { if (pScreen->ppChannels[iChannel] == pChannel) {
*pIndex = iChannel; *pIndex = iChannel;
return MA_SUCCESS; return MA_SUCCESS;
...@@ -356,7 +356,7 @@ mal_result msigvis_screen_find_channel_index(msigvis_screen* pScreen, msigvis_ch ...@@ -356,7 +356,7 @@ mal_result msigvis_screen_find_channel_index(msigvis_screen* pScreen, msigvis_ch
return MA_ERROR; return MA_ERROR;
} }
mal_result msigvis_screen_redraw(msigvis_screen* pScreen) ma_result msigvis_screen_redraw(msigvis_screen* pScreen)
{ {
if (pScreen == NULL) { if (pScreen == NULL) {
return MA_INVALID_ARGS; return MA_INVALID_ARGS;
...@@ -371,7 +371,7 @@ mal_result msigvis_screen_redraw(msigvis_screen* pScreen) ...@@ -371,7 +371,7 @@ mal_result msigvis_screen_redraw(msigvis_screen* pScreen)
// Channel // Channel
// //
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
mal_result msigvis_channel_init(msigvis_context* pContext, mal_format format, mal_uint32 sampleRate, msigvis_channel* pChannel) ma_result msigvis_channel_init(msigvis_context* pContext, ma_format format, ma_uint32 sampleRate, msigvis_channel* pChannel)
{ {
(void)pContext; (void)pContext;
...@@ -379,9 +379,9 @@ mal_result msigvis_channel_init(msigvis_context* pContext, mal_format format, ma ...@@ -379,9 +379,9 @@ mal_result msigvis_channel_init(msigvis_context* pContext, mal_format format, ma
return MA_INVALID_ARGS; return MA_INVALID_ARGS;
} }
mal_zero_object(pChannel); ma_zero_object(pChannel);
if (format == mal_format_unknown || sampleRate == 0) { if (format == ma_format_unknown || sampleRate == 0) {
return MA_INVALID_ARGS; return MA_INVALID_ARGS;
} }
...@@ -398,25 +398,25 @@ void msigvis_channel_uninit(msigvis_channel* pChannel) ...@@ -398,25 +398,25 @@ void msigvis_channel_uninit(msigvis_channel* pChannel)
return; return;
} }
mal_free(pChannel->pBuffer); ma_free(pChannel->pBuffer);
} }
mal_result msigvis_channel_push_samples(msigvis_channel* pChannel, mal_uint32 sampleCount, const void* pSamples) ma_result msigvis_channel_push_samples(msigvis_channel* pChannel, ma_uint32 sampleCount, const void* pSamples)
{ {
if (pChannel == NULL) { if (pChannel == NULL) {
return MA_INVALID_ARGS; return MA_INVALID_ARGS;
} }
mal_uint32 bps = mal_get_bytes_per_sample(pChannel->format); ma_uint32 bps = ma_get_bytes_per_sample(pChannel->format);
// Resize the buffer if necessary. // Resize the buffer if necessary.
if (pChannel->sampleCount + sampleCount >= pChannel->bufferCapInSamples) { if (pChannel->sampleCount + sampleCount >= pChannel->bufferCapInSamples) {
mal_uint32 newBufferCapInSamples = mal_max(pChannel->sampleCount + sampleCount, pChannel->bufferCapInSamples*2); ma_uint32 newBufferCapInSamples = ma_max(pChannel->sampleCount + sampleCount, pChannel->bufferCapInSamples*2);
if (newBufferCapInSamples == 0) { if (newBufferCapInSamples == 0) {
newBufferCapInSamples = 32; newBufferCapInSamples = 32;
} }
mal_uint8* pNewBuffer = (mal_uint8*)mal_realloc(pChannel->pBuffer, newBufferCapInSamples*bps); ma_uint8* pNewBuffer = (ma_uint8*)ma_realloc(pChannel->pBuffer, newBufferCapInSamples*bps);
if (pNewBuffer == NULL) { if (pNewBuffer == NULL) {
return MA_OUT_OF_MEMORY; return MA_OUT_OF_MEMORY;
} }
...@@ -425,13 +425,13 @@ mal_result msigvis_channel_push_samples(msigvis_channel* pChannel, mal_uint32 sa ...@@ -425,13 +425,13 @@ mal_result msigvis_channel_push_samples(msigvis_channel* pChannel, mal_uint32 sa
pChannel->bufferCapInSamples = newBufferCapInSamples; pChannel->bufferCapInSamples = newBufferCapInSamples;
} }
mal_copy_memory(pChannel->pBuffer + pChannel->sampleCount*bps, pSamples, sampleCount*bps); ma_copy_memory(pChannel->pBuffer + pChannel->sampleCount*bps, pSamples, sampleCount*bps);
pChannel->sampleCount += sampleCount; pChannel->sampleCount += sampleCount;
return MA_SUCCESS; return MA_SUCCESS;
} }
mal_result msigvis_channel_pop_samples(msigvis_channel* pChannel, mal_uint32 sampleCount) ma_result msigvis_channel_pop_samples(msigvis_channel* pChannel, ma_uint32 sampleCount)
{ {
if (pChannel == NULL) { if (pChannel == NULL) {
return MA_INVALID_ARGS; return MA_INVALID_ARGS;
...@@ -441,11 +441,11 @@ mal_result msigvis_channel_pop_samples(msigvis_channel* pChannel, mal_uint32 sam ...@@ -441,11 +441,11 @@ mal_result msigvis_channel_pop_samples(msigvis_channel* pChannel, mal_uint32 sam
sampleCount = pChannel->sampleCount; sampleCount = pChannel->sampleCount;
} }
mal_uint32 bps = mal_get_bytes_per_sample(pChannel->format); ma_uint32 bps = ma_get_bytes_per_sample(pChannel->format);
// This is just a dumb "move everything down" type of data movement. Need to change this to a circular buffer to make this more efficient. // This is just a dumb "move everything down" type of data movement. Need to change this to a circular buffer to make this more efficient.
mal_uint32 bytesToRemove = sampleCount*bps; ma_uint32 bytesToRemove = sampleCount*bps;
mal_assert(bytesToRemove > 0); ma_assert(bytesToRemove > 0);
memmove(pChannel->pBuffer, pChannel->pBuffer + bytesToRemove, pChannel->sampleCount*bps - bytesToRemove); memmove(pChannel->pBuffer, pChannel->pBuffer + bytesToRemove, pChannel->sampleCount*bps - bytesToRemove);
pChannel->sampleCount -= sampleCount; pChannel->sampleCount -= sampleCount;
...@@ -453,11 +453,11 @@ mal_result msigvis_channel_pop_samples(msigvis_channel* pChannel, mal_uint32 sam ...@@ -453,11 +453,11 @@ mal_result msigvis_channel_pop_samples(msigvis_channel* pChannel, mal_uint32 sam
return MA_SUCCESS; return MA_SUCCESS;
} }
float msigvis_channel_get_sample_f32(msigvis_channel* pChannel, mal_uint32 iSample) float msigvis_channel_get_sample_f32(msigvis_channel* pChannel, ma_uint32 iSample)
{ {
switch (pChannel->format) switch (pChannel->format)
{ {
case mal_format_f32: return *((float*)pChannel->pBuffer + iSample); case ma_format_f32: return *((float*)pChannel->pBuffer + iSample);
default: return 0; default: return 0;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment