mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-21 15:56:58 +02:00
"mal_" to "ma_".
This commit is contained in:
@@ -74,14 +74,14 @@ Simple Playback Example
|
||||
|
||||
#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) {
|
||||
return;
|
||||
}
|
||||
|
||||
mal_decoder_read_pcm_frames(pDecoder, pOutput, frameCount);
|
||||
ma_decoder_read_pcm_frames(pDecoder, pOutput, frameCount);
|
||||
|
||||
(void)pInput;
|
||||
}
|
||||
@@ -93,38 +93,38 @@ int main(int argc, char** argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
mal_decoder decoder;
|
||||
mal_result result = mal_decoder_init_file(argv[1], NULL, &decoder);
|
||||
ma_decoder decoder;
|
||||
ma_result result = ma_decoder_init_file(argv[1], NULL, &decoder);
|
||||
if (result != MA_SUCCESS) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
mal_device_config config = mal_device_config_init(mal_device_type_playback);
|
||||
ma_device_config config = ma_device_config_init(ma_device_type_playback);
|
||||
config.playback.format = decoder.outputFormat;
|
||||
config.playback.channels = decoder.outputChannels;
|
||||
config.sampleRate = decoder.outputSampleRate;
|
||||
config.dataCallback = data_callback;
|
||||
config.pUserData = &decoder;
|
||||
|
||||
mal_device device;
|
||||
if (mal_device_init(NULL, &config, &device) != MA_SUCCESS) {
|
||||
ma_device device;
|
||||
if (ma_device_init(NULL, &config, &device) != MA_SUCCESS) {
|
||||
printf("Failed to open playback device.\n");
|
||||
mal_decoder_uninit(&decoder);
|
||||
ma_decoder_uninit(&decoder);
|
||||
return -3;
|
||||
}
|
||||
|
||||
if (mal_device_start(&device) != MA_SUCCESS) {
|
||||
if (ma_device_start(&device) != MA_SUCCESS) {
|
||||
printf("Failed to start playback device.\n");
|
||||
mal_device_uninit(&device);
|
||||
mal_decoder_uninit(&decoder);
|
||||
ma_device_uninit(&device);
|
||||
ma_decoder_uninit(&decoder);
|
||||
return -4;
|
||||
}
|
||||
|
||||
printf("Press Enter to quit...");
|
||||
getchar();
|
||||
|
||||
mal_device_uninit(&device);
|
||||
mal_decoder_uninit(&decoder);
|
||||
ma_device_uninit(&device);
|
||||
ma_decoder_uninit(&decoder);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -158,28 +158,28 @@ relevant backend library before the implementation of miniaudio, like so:
|
||||
#include "miniaudio.h"
|
||||
```
|
||||
|
||||
A decoder can be initialized from a file with `mal_decoder_init_file()`, a block of memory with
|
||||
`mal_decoder_init_memory()`, or from data delivered via callbacks with `mal_decoder_init()`. Here
|
||||
A decoder can be initialized from a file with `ma_decoder_init_file()`, a block of memory with
|
||||
`ma_decoder_init_memory()`, or from data delivered via callbacks with `ma_decoder_init()`. Here
|
||||
is an example for loading a decoder from a file:
|
||||
|
||||
```
|
||||
mal_decoder decoder;
|
||||
mal_result result = mal_decoder_init_file("MySong.mp3", NULL, &decoder);
|
||||
ma_decoder decoder;
|
||||
ma_result result = ma_decoder_init_file("MySong.mp3", NULL, &decoder);
|
||||
if (result != MA_SUCCESS) {
|
||||
return false; // An error occurred.
|
||||
}
|
||||
|
||||
...
|
||||
|
||||
mal_decoder_uninit(&decoder);
|
||||
ma_decoder_uninit(&decoder);
|
||||
```
|
||||
|
||||
When initializing a decoder, you can optionally pass in a pointer to a `mal_decoder_config` object
|
||||
When initializing a decoder, you can optionally pass in a pointer to a `ma_decoder_config` object
|
||||
(the `NULL` argument in the example above) which allows you to configure the output format, channel
|
||||
count, sample rate and channel map:
|
||||
|
||||
```
|
||||
mal_decoder_config config = mal_decoder_config_init(mal_format_f32, 2, 48000);
|
||||
ma_decoder_config config = ma_decoder_config_init(ma_format_f32, 2, 48000);
|
||||
```
|
||||
|
||||
When passing in NULL for this parameter, the output format will be the same as that defined by the
|
||||
@@ -188,13 +188,13 @@ decoding backend.
|
||||
Data is read from the decoder as PCM frames:
|
||||
|
||||
```
|
||||
mal_uint64 framesRead = mal_decoder_read_pcm_frames(pDecoder, pFrames, framesToRead);
|
||||
ma_uint64 framesRead = ma_decoder_read_pcm_frames(pDecoder, pFrames, framesToRead);
|
||||
```
|
||||
|
||||
You can also seek to a specific frame like so:
|
||||
|
||||
```
|
||||
mal_result result = mal_decoder_seek_to_pcm_frame(pDecoder, targetFrame);
|
||||
ma_result result = ma_decoder_seek_to_pcm_frame(pDecoder, targetFrame);
|
||||
if (result != MA_SUCCESS) {
|
||||
return false; // An error occurred.
|
||||
}
|
||||
@@ -205,14 +205,14 @@ backend. This can be unnecessarily inefficient if the type is already known. In
|
||||
use the `_wav`, `_mp3`, etc. varients of the aforementioned initialization APIs:
|
||||
|
||||
```
|
||||
mal_decoder_init_wav()
|
||||
mal_decoder_init_mp3()
|
||||
mal_decoder_init_memory_wav()
|
||||
mal_decoder_init_memory_mp3()
|
||||
mal_decoder_init_file_wav()
|
||||
mal_decoder_init_file_mp3()
|
||||
ma_decoder_init_wav()
|
||||
ma_decoder_init_mp3()
|
||||
ma_decoder_init_memory_wav()
|
||||
ma_decoder_init_memory_mp3()
|
||||
ma_decoder_init_file_wav()
|
||||
ma_decoder_init_file_mp3()
|
||||
etc.
|
||||
```
|
||||
|
||||
The `mal_decoder_init_file()` API will try using the file extension to determine which decoding
|
||||
The `ma_decoder_init_file()` API will try using the file extension to determine which decoding
|
||||
backend to prefer.
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ To compile these examples, cd into the "build" directory and run the applicable
|
||||
will be placed in the "bin" directory.
|
||||
|
||||
cd build
|
||||
./mal_build_examples_linux
|
||||
./ma_build_examples_linux
|
||||
|
||||
Then you can run executables like this:
|
||||
|
||||
|
||||
+49
-49
@@ -3,14 +3,14 @@
|
||||
|
||||
#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)pDevice;
|
||||
printf("miniaudio: [%s] %s\n", mal_log_level_to_string(logLevel), message);
|
||||
printf("miniaudio: [%s] %s\n", ma_log_level_to_string(logLevel), message);
|
||||
}
|
||||
|
||||
void data_callback(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 frameCount)
|
||||
void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount)
|
||||
{
|
||||
(void)pDevice;
|
||||
(void)pOutput;
|
||||
@@ -19,7 +19,7 @@ void data_callback(mal_device* pDevice, void* pOutput, const void* pInput, mal_u
|
||||
return; // Just output silence for this example.
|
||||
}
|
||||
|
||||
void stop_callback(mal_device* pDevice)
|
||||
void stop_callback(ma_device* pDevice)
|
||||
{
|
||||
(void)pDevice;
|
||||
printf("Device stopped\n");
|
||||
@@ -31,14 +31,14 @@ int main(int argc, char** argv)
|
||||
(void)argv;
|
||||
|
||||
// When initializing a context, you can pass in an optional configuration object that allows you to control
|
||||
// context-level configuration. The mal_context_config_init() function will initialize a config object with
|
||||
// context-level configuration. The ma_context_config_init() function will initialize a config object with
|
||||
// common configuration settings, but you can set other members for more detailed control.
|
||||
mal_context_config contextConfig = mal_context_config_init();
|
||||
ma_context_config contextConfig = ma_context_config_init();
|
||||
contextConfig.logCallback = log_callback;
|
||||
|
||||
// The priority of the worker thread can be set with the following. The default priority is
|
||||
// mal_thread_priority_highest.
|
||||
contextConfig.threadPriority = mal_thread_priority_normal;
|
||||
// ma_thread_priority_highest.
|
||||
contextConfig.threadPriority = ma_thread_priority_normal;
|
||||
|
||||
|
||||
// PulseAudio
|
||||
@@ -80,52 +80,52 @@ int main(int argc, char** argv)
|
||||
|
||||
|
||||
// The prioritization of backends can be controlled by the application. You need only specify the backends
|
||||
// you care about. If the context cannot be initialized for any of the specified backends mal_context_init()
|
||||
// you care about. If the context cannot be initialized for any of the specified backends ma_context_init()
|
||||
// will fail.
|
||||
mal_backend backends[] = {
|
||||
mal_backend_wasapi, // Higest priority.
|
||||
mal_backend_dsound,
|
||||
mal_backend_winmm,
|
||||
mal_backend_coreaudio,
|
||||
mal_backend_sndio,
|
||||
mal_backend_audio4,
|
||||
mal_backend_oss,
|
||||
mal_backend_pulseaudio,
|
||||
mal_backend_alsa,
|
||||
mal_backend_jack,
|
||||
mal_backend_aaudio,
|
||||
mal_backend_opensl,
|
||||
mal_backend_webaudio,
|
||||
mal_backend_null // Lowest priority.
|
||||
ma_backend backends[] = {
|
||||
ma_backend_wasapi, // Higest priority.
|
||||
ma_backend_dsound,
|
||||
ma_backend_winmm,
|
||||
ma_backend_coreaudio,
|
||||
ma_backend_sndio,
|
||||
ma_backend_audio4,
|
||||
ma_backend_oss,
|
||||
ma_backend_pulseaudio,
|
||||
ma_backend_alsa,
|
||||
ma_backend_jack,
|
||||
ma_backend_aaudio,
|
||||
ma_backend_opensl,
|
||||
ma_backend_webaudio,
|
||||
ma_backend_null // Lowest priority.
|
||||
};
|
||||
|
||||
mal_context context;
|
||||
if (mal_context_init(backends, sizeof(backends)/sizeof(backends[0]), &contextConfig, &context) != MA_SUCCESS) {
|
||||
ma_context context;
|
||||
if (ma_context_init(backends, sizeof(backends)/sizeof(backends[0]), &contextConfig, &context) != MA_SUCCESS) {
|
||||
printf("Failed to initialize context.");
|
||||
return -2;
|
||||
}
|
||||
|
||||
|
||||
// Enumerate devices.
|
||||
mal_device_info* pPlaybackDeviceInfos;
|
||||
mal_uint32 playbackDeviceCount;
|
||||
mal_device_info* pCaptureDeviceInfos;
|
||||
mal_uint32 captureDeviceCount;
|
||||
mal_result result = mal_context_get_devices(&context, &pPlaybackDeviceInfos, &playbackDeviceCount, &pCaptureDeviceInfos, &captureDeviceCount);
|
||||
ma_device_info* pPlaybackDeviceInfos;
|
||||
ma_uint32 playbackDeviceCount;
|
||||
ma_device_info* pCaptureDeviceInfos;
|
||||
ma_uint32 captureDeviceCount;
|
||||
ma_result result = ma_context_get_devices(&context, &pPlaybackDeviceInfos, &playbackDeviceCount, &pCaptureDeviceInfos, &captureDeviceCount);
|
||||
if (result != MA_SUCCESS) {
|
||||
printf("Failed to retrieve device information.\n");
|
||||
return -3;
|
||||
}
|
||||
|
||||
printf("Playback Devices (%d)\n", playbackDeviceCount);
|
||||
for (mal_uint32 iDevice = 0; iDevice < playbackDeviceCount; ++iDevice) {
|
||||
for (ma_uint32 iDevice = 0; iDevice < playbackDeviceCount; ++iDevice) {
|
||||
printf(" %u: %s\n", iDevice, pPlaybackDeviceInfos[iDevice].name);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
printf("Capture Devices (%d)\n", captureDeviceCount);
|
||||
for (mal_uint32 iDevice = 0; iDevice < captureDeviceCount; ++iDevice) {
|
||||
for (ma_uint32 iDevice = 0; iDevice < captureDeviceCount; ++iDevice) {
|
||||
printf(" %u: %s\n", iDevice, pCaptureDeviceInfos[iDevice].name);
|
||||
}
|
||||
|
||||
@@ -133,12 +133,12 @@ int main(int argc, char** argv)
|
||||
// Open the device.
|
||||
//
|
||||
// Unlike context configs, device configs are required. Similar to context configs, an API exists to help you
|
||||
// initialize a config object called mal_device_config_init().
|
||||
// initialize a config object called ma_device_config_init().
|
||||
//
|
||||
// When using full-duplex you may want to use a different sample format, channel count and channel map. To
|
||||
// support this, the device configuration splits these into "playback" and "capture" as shown below.
|
||||
mal_device_config deviceConfig = mal_device_config_init(mal_device_type_playback);
|
||||
deviceConfig.playback.format = mal_format_s16;
|
||||
ma_device_config deviceConfig = ma_device_config_init(ma_device_type_playback);
|
||||
deviceConfig.playback.format = ma_format_s16;
|
||||
deviceConfig.playback.channels = 2;
|
||||
deviceConfig.sampleRate = 48000;
|
||||
deviceConfig.dataCallback = data_callback;
|
||||
@@ -149,7 +149,7 @@ int main(int argc, char** argv)
|
||||
|
||||
// Applications can request exclusive control of the device using the config variable below. Note that not all
|
||||
// backends support this feature, so this is actually just a hint.
|
||||
deviceConfig.playback.shareMode = mal_share_mode_exclusive;
|
||||
deviceConfig.playback.shareMode = ma_share_mode_exclusive;
|
||||
|
||||
// miniaudio allows applications to control the mapping of channels. The config below swaps the left and right
|
||||
// channels. Normally in an interleaved audio stream, the left channel comes first, but we can change that
|
||||
@@ -165,12 +165,12 @@ int main(int argc, char** argv)
|
||||
deviceConfig.alsa.noMMap = MA_TRUE;
|
||||
|
||||
// This is not used in this example, but miniaudio allows you to directly control the device ID that's used
|
||||
// for device selection by mal_device_init(). Below is an example for ALSA. In this example it forces
|
||||
// mal_device_init() to try opening the "hw:0,0" device. This is useful for debugging in case you have
|
||||
// for device selection by ma_device_init(). Below is an example for ALSA. In this example it forces
|
||||
// ma_device_init() to try opening the "hw:0,0" device. This is useful for debugging in case you have
|
||||
// audio glitches or whatnot with specific devices.
|
||||
#ifdef MA_SUPPORT_ALSA
|
||||
mal_device_id customDeviceID;
|
||||
if (context.backend == mal_backend_alsa) {
|
||||
ma_device_id customDeviceID;
|
||||
if (context.backend == ma_backend_alsa) {
|
||||
strcpy(customDeviceID.alsa, "hw:0,0");
|
||||
|
||||
// The ALSA backend also supports a miniaudio-specific format which looks like this: ":0,0". In this case,
|
||||
@@ -181,26 +181,26 @@ int main(int argc, char** argv)
|
||||
}
|
||||
#endif
|
||||
|
||||
mal_device playbackDevice;
|
||||
if (mal_device_init(&context, &deviceConfig, &playbackDevice) != MA_SUCCESS) {
|
||||
ma_device playbackDevice;
|
||||
if (ma_device_init(&context, &deviceConfig, &playbackDevice) != MA_SUCCESS) {
|
||||
printf("Failed to initialize playback device.\n");
|
||||
mal_context_uninit(&context);
|
||||
ma_context_uninit(&context);
|
||||
return -7;
|
||||
}
|
||||
|
||||
if (mal_device_start(&playbackDevice) != MA_SUCCESS) {
|
||||
if (ma_device_start(&playbackDevice) != MA_SUCCESS) {
|
||||
printf("Failed to start playback device.\n");
|
||||
mal_device_uninit(&playbackDevice);
|
||||
mal_context_uninit(&context);
|
||||
ma_device_uninit(&playbackDevice);
|
||||
ma_context_uninit(&context);
|
||||
return -8;
|
||||
}
|
||||
|
||||
printf("Press Enter to quit...");
|
||||
getchar();
|
||||
|
||||
mal_device_uninit(&playbackDevice);
|
||||
ma_device_uninit(&playbackDevice);
|
||||
|
||||
|
||||
mal_context_uninit(&context);
|
||||
ma_context_uninit(&context);
|
||||
return 0;
|
||||
}
|
||||
|
||||
+10
-10
@@ -9,12 +9,12 @@
|
||||
#include <stdlib.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;
|
||||
|
||||
drwav* pWav = (drwav*)pDevice->pUserData;
|
||||
mal_assert(pWav != NULL);
|
||||
ma_assert(pWav != NULL);
|
||||
|
||||
drwav_write_pcm_frames(pWav, frameCount, pInput);
|
||||
}
|
||||
@@ -26,7 +26,7 @@ int main(int argc, char** argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
mal_result result;
|
||||
ma_result result;
|
||||
|
||||
drwav_data_format wavFormat;
|
||||
wavFormat.container = drwav_container_riff;
|
||||
@@ -41,23 +41,23 @@ int main(int argc, char** argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
mal_device_config config = mal_device_config_init(mal_device_type_capture);
|
||||
config.capture.format = mal_format_f32;
|
||||
ma_device_config config = ma_device_config_init(ma_device_type_capture);
|
||||
config.capture.format = ma_format_f32;
|
||||
config.capture.channels = wavFormat.channels;
|
||||
config.sampleRate = wavFormat.sampleRate;
|
||||
config.dataCallback = data_callback;
|
||||
config.pUserData = &wav;
|
||||
|
||||
mal_device device;
|
||||
result = mal_device_init(NULL, &config, &device);
|
||||
ma_device device;
|
||||
result = ma_device_init(NULL, &config, &device);
|
||||
if (result != MA_SUCCESS) {
|
||||
printf("Failed to initialize capture device.\n");
|
||||
return -2;
|
||||
}
|
||||
|
||||
result = mal_device_start(&device);
|
||||
result = ma_device_start(&device);
|
||||
if (result != MA_SUCCESS) {
|
||||
mal_device_uninit(&device);
|
||||
ma_device_uninit(&device);
|
||||
printf("Failed to start device.\n");
|
||||
return -3;
|
||||
}
|
||||
@@ -65,7 +65,7 @@ int main(int argc, char** argv)
|
||||
printf("Press Enter to stop recording...\n");
|
||||
getchar();
|
||||
|
||||
mal_device_uninit(&device);
|
||||
ma_device_uninit(&device);
|
||||
drwav_uninit(&wav);
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -8,35 +8,35 @@ int main(int argc, char** argv)
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
mal_context context;
|
||||
if (mal_context_init(NULL, 0, NULL, &context) != MA_SUCCESS) {
|
||||
ma_context context;
|
||||
if (ma_context_init(NULL, 0, NULL, &context) != MA_SUCCESS) {
|
||||
printf("Failed to initialize context.\n");
|
||||
return -2;
|
||||
}
|
||||
|
||||
mal_device_info* pPlaybackDeviceInfos;
|
||||
mal_uint32 playbackDeviceCount;
|
||||
mal_device_info* pCaptureDeviceInfos;
|
||||
mal_uint32 captureDeviceCount;
|
||||
mal_result result = mal_context_get_devices(&context, &pPlaybackDeviceInfos, &playbackDeviceCount, &pCaptureDeviceInfos, &captureDeviceCount);
|
||||
ma_device_info* pPlaybackDeviceInfos;
|
||||
ma_uint32 playbackDeviceCount;
|
||||
ma_device_info* pCaptureDeviceInfos;
|
||||
ma_uint32 captureDeviceCount;
|
||||
ma_result result = ma_context_get_devices(&context, &pPlaybackDeviceInfos, &playbackDeviceCount, &pCaptureDeviceInfos, &captureDeviceCount);
|
||||
if (result != MA_SUCCESS) {
|
||||
printf("Failed to retrieve device information.\n");
|
||||
return -3;
|
||||
}
|
||||
|
||||
printf("Playback Devices\n");
|
||||
for (mal_uint32 iDevice = 0; iDevice < playbackDeviceCount; ++iDevice) {
|
||||
for (ma_uint32 iDevice = 0; iDevice < playbackDeviceCount; ++iDevice) {
|
||||
printf(" %u: %s\n", iDevice, pPlaybackDeviceInfos[iDevice].name);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
printf("Capture Devices\n");
|
||||
for (mal_uint32 iDevice = 0; iDevice < captureDeviceCount; ++iDevice) {
|
||||
for (ma_uint32 iDevice = 0; iDevice < captureDeviceCount; ++iDevice) {
|
||||
printf(" %u: %s\n", iDevice, pCaptureDeviceInfos[iDevice].name);
|
||||
}
|
||||
|
||||
|
||||
mal_context_uninit(&context);
|
||||
ma_context_uninit(&context);
|
||||
return 0;
|
||||
}
|
||||
|
||||
+14
-14
@@ -10,14 +10,14 @@
|
||||
|
||||
#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) {
|
||||
return;
|
||||
}
|
||||
|
||||
mal_decoder_read_pcm_frames(pDecoder, pOutput, frameCount);
|
||||
ma_decoder_read_pcm_frames(pDecoder, pOutput, frameCount);
|
||||
|
||||
(void)pInput;
|
||||
}
|
||||
@@ -29,38 +29,38 @@ int main(int argc, char** argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
mal_decoder decoder;
|
||||
mal_result result = mal_decoder_init_file(argv[1], NULL, &decoder);
|
||||
ma_decoder decoder;
|
||||
ma_result result = ma_decoder_init_file(argv[1], NULL, &decoder);
|
||||
if (result != MA_SUCCESS) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
mal_device_config config = mal_device_config_init(mal_device_type_playback);
|
||||
ma_device_config config = ma_device_config_init(ma_device_type_playback);
|
||||
config.playback.format = decoder.outputFormat;
|
||||
config.playback.channels = decoder.outputChannels;
|
||||
config.sampleRate = decoder.outputSampleRate;
|
||||
config.dataCallback = data_callback;
|
||||
config.pUserData = &decoder;
|
||||
|
||||
mal_device device;
|
||||
if (mal_device_init(NULL, &config, &device) != MA_SUCCESS) {
|
||||
ma_device device;
|
||||
if (ma_device_init(NULL, &config, &device) != MA_SUCCESS) {
|
||||
printf("Failed to open playback device.\n");
|
||||
mal_decoder_uninit(&decoder);
|
||||
ma_decoder_uninit(&decoder);
|
||||
return -3;
|
||||
}
|
||||
|
||||
if (mal_device_start(&device) != MA_SUCCESS) {
|
||||
if (ma_device_start(&device) != MA_SUCCESS) {
|
||||
printf("Failed to start playback device.\n");
|
||||
mal_device_uninit(&device);
|
||||
mal_decoder_uninit(&decoder);
|
||||
ma_device_uninit(&device);
|
||||
ma_decoder_uninit(&decoder);
|
||||
return -4;
|
||||
}
|
||||
|
||||
printf("Press Enter to quit...");
|
||||
getchar();
|
||||
|
||||
mal_device_uninit(&device);
|
||||
mal_decoder_uninit(&decoder);
|
||||
ma_device_uninit(&device);
|
||||
ma_decoder_uninit(&decoder);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -11,19 +11,19 @@ void main_loop__em()
|
||||
}
|
||||
#endif
|
||||
|
||||
#define DEVICE_FORMAT mal_format_f32
|
||||
#define DEVICE_FORMAT ma_format_f32
|
||||
#define DEVICE_CHANNELS 1
|
||||
#define DEVICE_SAMPLE_RATE 48000
|
||||
|
||||
void data_callback(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 frameCount)
|
||||
void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount)
|
||||
{
|
||||
(void)pInput; /* Unused. */
|
||||
mal_assert(pDevice->playback.channels == DEVICE_CHANNELS);
|
||||
ma_assert(pDevice->playback.channels == DEVICE_CHANNELS);
|
||||
|
||||
mal_sine_wave* pSineWave = (mal_sine_wave*)pDevice->pUserData;
|
||||
mal_assert(pSineWave != NULL);
|
||||
ma_sine_wave* pSineWave = (ma_sine_wave*)pDevice->pUserData;
|
||||
ma_assert(pSineWave != NULL);
|
||||
|
||||
mal_sine_wave_read_f32(pSineWave, frameCount, (float*)pOutput);
|
||||
ma_sine_wave_read_f32(pSineWave, frameCount, (float*)pOutput);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
@@ -31,27 +31,27 @@ int main(int argc, char** argv)
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
mal_sine_wave sineWave;
|
||||
mal_sine_wave_init(0.2, 400, DEVICE_SAMPLE_RATE, &sineWave);
|
||||
ma_sine_wave sineWave;
|
||||
ma_sine_wave_init(0.2, 400, DEVICE_SAMPLE_RATE, &sineWave);
|
||||
|
||||
mal_device_config config = mal_device_config_init(mal_device_type_playback);
|
||||
ma_device_config config = ma_device_config_init(ma_device_type_playback);
|
||||
config.playback.format = DEVICE_FORMAT;
|
||||
config.playback.channels = DEVICE_CHANNELS;
|
||||
config.sampleRate = DEVICE_SAMPLE_RATE;
|
||||
config.dataCallback = data_callback;
|
||||
config.pUserData = &sineWave;
|
||||
|
||||
mal_device device;
|
||||
if (mal_device_init(NULL, &config, &device) != MA_SUCCESS) {
|
||||
ma_device device;
|
||||
if (ma_device_init(NULL, &config, &device) != MA_SUCCESS) {
|
||||
printf("Failed to open playback device.\n");
|
||||
return -4;
|
||||
}
|
||||
|
||||
printf("Device Name: %s\n", device.playback.name);
|
||||
|
||||
if (mal_device_start(&device) != MA_SUCCESS) {
|
||||
if (ma_device_start(&device) != MA_SUCCESS) {
|
||||
printf("Failed to start playback device.\n");
|
||||
mal_device_uninit(&device);
|
||||
ma_device_uninit(&device);
|
||||
return -5;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ int main(int argc, char** argv)
|
||||
getchar();
|
||||
#endif
|
||||
|
||||
mal_device_uninit(&device);
|
||||
ma_device_uninit(&device);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+8632
-8632
File diff suppressed because it is too large
Load Diff
+268
-268
File diff suppressed because it is too large
Load Diff
+199
-199
@@ -8,28 +8,28 @@
|
||||
|
||||
// USAGE
|
||||
//
|
||||
// - Call mal_rb_init() to initialize a simple buffer, with an optional pre-allocated buffer. If you pass in NULL
|
||||
// for the pre-allocated buffer, it will be allocated for you and free()'d in mal_rb_uninit(). If you pass in
|
||||
// - Call ma_rb_init() to initialize a simple buffer, with an optional pre-allocated buffer. If you pass in NULL
|
||||
// for the pre-allocated buffer, it will be allocated for you and free()'d in ma_rb_uninit(). If you pass in
|
||||
// your own pre-allocated buffer, free()-ing is left to you.
|
||||
//
|
||||
// - Call mal_rb_init_ex() if you need a deinterleaved buffer. The data for each sub-buffer is offset from each
|
||||
// other based on the stride. Use mal_rb_get_subbuffer_stride(), mal_rb_get_subbuffer_offset() and
|
||||
// mal_rb_get_subbuffer_ptr() to manage your sub-buffers.
|
||||
// - Call ma_rb_init_ex() if you need a deinterleaved buffer. The data for each sub-buffer is offset from each
|
||||
// other based on the stride. Use ma_rb_get_subbuffer_stride(), ma_rb_get_subbuffer_offset() and
|
||||
// ma_rb_get_subbuffer_ptr() to manage your sub-buffers.
|
||||
//
|
||||
// - Use mal_rb_acquire_read() and mal_rb_acquire_write() to retrieve a pointer to a section of the ring buffer.
|
||||
// - Use ma_rb_acquire_read() and ma_rb_acquire_write() to retrieve a pointer to a section of the ring buffer.
|
||||
// You specify the number of bytes you need, and on output it will set to what was actually acquired. If the
|
||||
// read or write pointer is positioned such that the number of bytes requested will require a loop, it will be
|
||||
// clamped to the end of the buffer. Therefore, the number of bytes you're given may be less than the number
|
||||
// you requested.
|
||||
//
|
||||
// - After calling mal_rb_acquire_read/write(), you do your work on the buffer and then "commit" it with
|
||||
// mal_rb_commit_read/write(). This is where the read/write pointers are updated. When you commit you need to
|
||||
// pass in the buffer that was returned by the earlier call to mal_rb_acquire_read/write() and is only used
|
||||
// for validation. The number of bytes passed to mal_rb_commit_read/write() is what's used to increment the
|
||||
// - After calling ma_rb_acquire_read/write(), you do your work on the buffer and then "commit" it with
|
||||
// ma_rb_commit_read/write(). This is where the read/write pointers are updated. When you commit you need to
|
||||
// pass in the buffer that was returned by the earlier call to ma_rb_acquire_read/write() and is only used
|
||||
// for validation. The number of bytes passed to ma_rb_commit_read/write() is what's used to increment the
|
||||
// pointers.
|
||||
//
|
||||
// - If you want to correct for drift between the write pointer and the read pointer you can use a combination
|
||||
// of mal_rb_pointer_distance(), mal_rb_seek_read() and mal_rb_seek_write(). Note that you can only move the
|
||||
// of ma_rb_pointer_distance(), ma_rb_seek_read() and ma_rb_seek_write(). Note that you can only move the
|
||||
// pointers forward, and you should only move the read pointer forward via the consumer thread, and the write
|
||||
// pointer forward by the producer thread. If there is too much space between the pointers, move the read
|
||||
// pointer forward. If there is too little space between the pointers, move the write pointer forward.
|
||||
@@ -45,99 +45,99 @@
|
||||
// - Operates on bytes. May end up adding to higher level helpers for doing everything per audio frame.
|
||||
// - Maximum buffer size is 0x7FFFFFFF-(MA_SIMD_ALIGNMENT-1) because of reasons.
|
||||
|
||||
#ifndef mal_ring_buffer_h
|
||||
#define mal_ring_buffer_h
|
||||
#ifndef ma_ring_buffer_h
|
||||
#define ma_ring_buffer_h
|
||||
|
||||
typedef struct
|
||||
{
|
||||
void* pBuffer;
|
||||
mal_uint32 subbufferSizeInBytes;
|
||||
mal_uint32 subbufferCount;
|
||||
mal_uint32 subbufferStrideInBytes;
|
||||
volatile mal_uint32 encodedReadOffset; /* Most significant bit is the loop flag. Lower 31 bits contains the actual offset in bytes. */
|
||||
volatile mal_uint32 encodedWriteOffset; /* Most significant bit is the loop flag. Lower 31 bits contains the actual offset in bytes. */
|
||||
mal_bool32 ownsBuffer : 1; /* Used to know whether or not miniaudio is responsible for free()-ing the buffer. */
|
||||
mal_bool32 clearOnWriteAcquire : 1; /* When set, clears the acquired write buffer before returning from mal_rb_acquire_write(). */
|
||||
} mal_rb;
|
||||
ma_uint32 subbufferSizeInBytes;
|
||||
ma_uint32 subbufferCount;
|
||||
ma_uint32 subbufferStrideInBytes;
|
||||
volatile ma_uint32 encodedReadOffset; /* Most significant bit is the loop flag. Lower 31 bits contains the actual offset in bytes. */
|
||||
volatile ma_uint32 encodedWriteOffset; /* Most significant bit is the loop flag. Lower 31 bits contains the actual offset in bytes. */
|
||||
ma_bool32 ownsBuffer : 1; /* Used to know whether or not miniaudio is responsible for free()-ing the buffer. */
|
||||
ma_bool32 clearOnWriteAcquire : 1; /* When set, clears the acquired write buffer before returning from ma_rb_acquire_write(). */
|
||||
} ma_rb;
|
||||
|
||||
mal_result mal_rb_init_ex(size_t subbufferSizeInBytes, size_t subbufferCount, size_t subbufferStrideInBytes, void* pOptionalPreallocatedBuffer, mal_rb* pRB);
|
||||
mal_result mal_rb_init(size_t bufferSizeInBytes, void* pOptionalPreallocatedBuffer, mal_rb* pRB);
|
||||
void mal_rb_uninit(mal_rb* pRB);
|
||||
mal_result mal_rb_acquire_read(mal_rb* pRB, size_t* pSizeInBytes, void** ppBufferOut);
|
||||
mal_result mal_rb_commit_read(mal_rb* pRB, size_t sizeInBytes, void* pBufferOut);
|
||||
mal_result mal_rb_acquire_write(mal_rb* pRB, size_t* pSizeInBytes, void** ppBufferOut);
|
||||
mal_result mal_rb_commit_write(mal_rb* pRB, size_t sizeInBytes, void* pBufferOut);
|
||||
mal_result mal_rb_seek_read(mal_rb* pRB, size_t offsetInBytes);
|
||||
mal_result mal_rb_seek_write(mal_rb* pRB, size_t offsetInBytes);
|
||||
mal_int32 mal_rb_pointer_distance(mal_rb* pRB); /* Returns the distance between the write pointer and the read pointer. Should never be negative for a correct program. */
|
||||
size_t mal_rb_get_subbuffer_stride(mal_rb* pRB);
|
||||
size_t mal_rb_get_subbuffer_offset(mal_rb* pRB, size_t subbufferIndex);
|
||||
void* mal_rb_get_subbuffer_ptr(mal_rb* pRB, size_t subbufferIndex, void* pBuffer);
|
||||
ma_result ma_rb_init_ex(size_t subbufferSizeInBytes, size_t subbufferCount, size_t subbufferStrideInBytes, void* pOptionalPreallocatedBuffer, ma_rb* pRB);
|
||||
ma_result ma_rb_init(size_t bufferSizeInBytes, void* pOptionalPreallocatedBuffer, ma_rb* pRB);
|
||||
void ma_rb_uninit(ma_rb* pRB);
|
||||
ma_result ma_rb_acquire_read(ma_rb* pRB, size_t* pSizeInBytes, void** ppBufferOut);
|
||||
ma_result ma_rb_commit_read(ma_rb* pRB, size_t sizeInBytes, void* pBufferOut);
|
||||
ma_result ma_rb_acquire_write(ma_rb* pRB, size_t* pSizeInBytes, void** ppBufferOut);
|
||||
ma_result ma_rb_commit_write(ma_rb* pRB, size_t sizeInBytes, void* pBufferOut);
|
||||
ma_result ma_rb_seek_read(ma_rb* pRB, size_t offsetInBytes);
|
||||
ma_result ma_rb_seek_write(ma_rb* pRB, size_t offsetInBytes);
|
||||
ma_int32 ma_rb_pointer_distance(ma_rb* pRB); /* Returns the distance between the write pointer and the read pointer. Should never be negative for a correct program. */
|
||||
size_t ma_rb_get_subbuffer_stride(ma_rb* pRB);
|
||||
size_t ma_rb_get_subbuffer_offset(ma_rb* pRB, size_t subbufferIndex);
|
||||
void* ma_rb_get_subbuffer_ptr(ma_rb* pRB, size_t subbufferIndex, void* pBuffer);
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
mal_rb rb;
|
||||
mal_format format;
|
||||
mal_uint32 channels;
|
||||
} mal_pcm_rb;
|
||||
ma_rb rb;
|
||||
ma_format format;
|
||||
ma_uint32 channels;
|
||||
} ma_pcm_rb;
|
||||
|
||||
mal_result mal_pcm_rb_init_ex(mal_format format, mal_uint32 channels, size_t subbufferSizeInFrames, size_t subbufferCount, size_t subbufferStrideInFrames, void* pOptionalPreallocatedBuffer, mal_pcm_rb* pRB);
|
||||
mal_result mal_pcm_rb_init(mal_format format, mal_uint32 channels, size_t bufferSizeInFrames, void* pOptionalPreallocatedBuffer, mal_pcm_rb* pRB);
|
||||
void mal_pcm_rb_uninit(mal_pcm_rb* pRB);
|
||||
mal_result mal_pcm_rb_acquire_read(mal_pcm_rb* pRB, size_t* pSizeInFrames, void** ppBufferOut);
|
||||
mal_result mal_pcm_rb_commit_read(mal_pcm_rb* pRB, size_t sizeInFrames, void* pBufferOut);
|
||||
mal_result mal_pcm_rb_acquire_write(mal_pcm_rb* pRB, size_t* pSizeInFrames, void** ppBufferOut);
|
||||
mal_result mal_pcm_rb_commit_write(mal_pcm_rb* pRB, size_t sizeInFrames, void* pBufferOut);
|
||||
mal_result mal_pcm_rb_seek_read(mal_pcm_rb* pRB, size_t offsetInFrames);
|
||||
mal_result mal_pcm_rb_seek_write(mal_pcm_rb* pRB, size_t offsetInFrames);
|
||||
mal_int32 mal_pcm_rb_pointer_disance(mal_pcm_rb* pRB); /* Return value is in frames. */
|
||||
size_t mal_pcm_rb_get_subbuffer_stride(mal_pcm_rb* pRB);
|
||||
size_t mal_pcm_rb_get_subbuffer_offset(mal_pcm_rb* pRB, size_t subbufferIndex);
|
||||
void* mal_pcm_rb_get_subbuffer_ptr(mal_pcm_rb* pRB, size_t subbufferIndex, void* pBuffer);
|
||||
ma_result ma_pcm_rb_init_ex(ma_format format, ma_uint32 channels, size_t subbufferSizeInFrames, size_t subbufferCount, size_t subbufferStrideInFrames, void* pOptionalPreallocatedBuffer, ma_pcm_rb* pRB);
|
||||
ma_result ma_pcm_rb_init(ma_format format, ma_uint32 channels, size_t bufferSizeInFrames, void* pOptionalPreallocatedBuffer, ma_pcm_rb* pRB);
|
||||
void ma_pcm_rb_uninit(ma_pcm_rb* pRB);
|
||||
ma_result ma_pcm_rb_acquire_read(ma_pcm_rb* pRB, size_t* pSizeInFrames, void** ppBufferOut);
|
||||
ma_result ma_pcm_rb_commit_read(ma_pcm_rb* pRB, size_t sizeInFrames, void* pBufferOut);
|
||||
ma_result ma_pcm_rb_acquire_write(ma_pcm_rb* pRB, size_t* pSizeInFrames, void** ppBufferOut);
|
||||
ma_result ma_pcm_rb_commit_write(ma_pcm_rb* pRB, size_t sizeInFrames, void* pBufferOut);
|
||||
ma_result ma_pcm_rb_seek_read(ma_pcm_rb* pRB, size_t offsetInFrames);
|
||||
ma_result ma_pcm_rb_seek_write(ma_pcm_rb* pRB, size_t offsetInFrames);
|
||||
ma_int32 ma_pcm_rb_pointer_disance(ma_pcm_rb* pRB); /* Return value is in frames. */
|
||||
size_t ma_pcm_rb_get_subbuffer_stride(ma_pcm_rb* pRB);
|
||||
size_t ma_pcm_rb_get_subbuffer_offset(ma_pcm_rb* pRB, size_t subbufferIndex);
|
||||
void* ma_pcm_rb_get_subbuffer_ptr(ma_pcm_rb* pRB, size_t subbufferIndex, void* pBuffer);
|
||||
|
||||
|
||||
#endif // mal_ring_buffer_h
|
||||
#endif // ma_ring_buffer_h
|
||||
|
||||
#ifdef MINIAUDIO_IMPLEMENTATION
|
||||
MA_INLINE mal_uint32 mal_rb__extract_offset_in_bytes(mal_uint32 encodedOffset)
|
||||
MA_INLINE ma_uint32 ma_rb__extract_offset_in_bytes(ma_uint32 encodedOffset)
|
||||
{
|
||||
return encodedOffset & 0x7FFFFFFF;
|
||||
}
|
||||
|
||||
MA_INLINE mal_uint32 mal_rb__extract_offset_loop_flag(mal_uint32 encodedOffset)
|
||||
MA_INLINE ma_uint32 ma_rb__extract_offset_loop_flag(ma_uint32 encodedOffset)
|
||||
{
|
||||
return encodedOffset & 0x80000000;
|
||||
}
|
||||
|
||||
MA_INLINE void* mal_rb__get_read_ptr(mal_rb* pRB)
|
||||
MA_INLINE void* ma_rb__get_read_ptr(ma_rb* pRB)
|
||||
{
|
||||
mal_assert(pRB != NULL);
|
||||
return mal_offset_ptr(pRB->pBuffer, mal_rb__extract_offset_in_bytes(pRB->encodedReadOffset));
|
||||
ma_assert(pRB != NULL);
|
||||
return ma_offset_ptr(pRB->pBuffer, ma_rb__extract_offset_in_bytes(pRB->encodedReadOffset));
|
||||
}
|
||||
|
||||
MA_INLINE void* mal_rb__get_write_ptr(mal_rb* pRB)
|
||||
MA_INLINE void* ma_rb__get_write_ptr(ma_rb* pRB)
|
||||
{
|
||||
mal_assert(pRB != NULL);
|
||||
return mal_offset_ptr(pRB->pBuffer, mal_rb__extract_offset_in_bytes(pRB->encodedWriteOffset));
|
||||
ma_assert(pRB != NULL);
|
||||
return ma_offset_ptr(pRB->pBuffer, ma_rb__extract_offset_in_bytes(pRB->encodedWriteOffset));
|
||||
}
|
||||
|
||||
MA_INLINE mal_uint32 mal_rb__construct_offset(mal_uint32 offsetInBytes, mal_uint32 offsetLoopFlag)
|
||||
MA_INLINE ma_uint32 ma_rb__construct_offset(ma_uint32 offsetInBytes, ma_uint32 offsetLoopFlag)
|
||||
{
|
||||
return offsetLoopFlag | offsetInBytes;
|
||||
}
|
||||
|
||||
MA_INLINE void mal_rb__deconstruct_offset(mal_uint32 encodedOffset, mal_uint32* pOffsetInBytes, mal_uint32* pOffsetLoopFlag)
|
||||
MA_INLINE void ma_rb__deconstruct_offset(ma_uint32 encodedOffset, ma_uint32* pOffsetInBytes, ma_uint32* pOffsetLoopFlag)
|
||||
{
|
||||
mal_assert(pOffsetInBytes != NULL);
|
||||
mal_assert(pOffsetLoopFlag != NULL);
|
||||
ma_assert(pOffsetInBytes != NULL);
|
||||
ma_assert(pOffsetLoopFlag != NULL);
|
||||
|
||||
*pOffsetInBytes = mal_rb__extract_offset_in_bytes(encodedOffset);
|
||||
*pOffsetLoopFlag = mal_rb__extract_offset_loop_flag(encodedOffset);
|
||||
*pOffsetInBytes = ma_rb__extract_offset_in_bytes(encodedOffset);
|
||||
*pOffsetLoopFlag = ma_rb__extract_offset_loop_flag(encodedOffset);
|
||||
}
|
||||
|
||||
|
||||
mal_result mal_rb_init_ex(size_t subbufferSizeInBytes, size_t subbufferCount, size_t subbufferStrideInBytes, void* pOptionalPreallocatedBuffer, mal_rb* pRB)
|
||||
ma_result ma_rb_init_ex(size_t subbufferSizeInBytes, size_t subbufferCount, size_t subbufferStrideInBytes, void* pOptionalPreallocatedBuffer, ma_rb* pRB)
|
||||
{
|
||||
if (pRB == NULL) {
|
||||
return MA_INVALID_ARGS;
|
||||
@@ -147,18 +147,18 @@ mal_result mal_rb_init_ex(size_t subbufferSizeInBytes, size_t subbufferCount, si
|
||||
return MA_INVALID_ARGS;
|
||||
}
|
||||
|
||||
const mal_uint32 maxSubBufferSize = 0x7FFFFFFF - (MA_SIMD_ALIGNMENT-1);
|
||||
const ma_uint32 maxSubBufferSize = 0x7FFFFFFF - (MA_SIMD_ALIGNMENT-1);
|
||||
if (subbufferSizeInBytes > maxSubBufferSize) {
|
||||
return MA_INVALID_ARGS; // Maximum buffer size is ~2GB. The most significant bit is a flag for use internally.
|
||||
}
|
||||
|
||||
|
||||
mal_zero_object(pRB);
|
||||
pRB->subbufferSizeInBytes = (mal_uint32)subbufferSizeInBytes;
|
||||
pRB->subbufferCount = (mal_uint32)subbufferCount;
|
||||
ma_zero_object(pRB);
|
||||
pRB->subbufferSizeInBytes = (ma_uint32)subbufferSizeInBytes;
|
||||
pRB->subbufferCount = (ma_uint32)subbufferCount;
|
||||
|
||||
if (pOptionalPreallocatedBuffer != NULL) {
|
||||
pRB->subbufferStrideInBytes = (mal_uint32)subbufferStrideInBytes;
|
||||
pRB->subbufferStrideInBytes = (ma_uint32)subbufferStrideInBytes;
|
||||
pRB->pBuffer = pOptionalPreallocatedBuffer;
|
||||
} else {
|
||||
// Here is where we allocate our own buffer. We always want to align this to MA_SIMD_ALIGNMENT for future SIMD optimization opportunity. To do this
|
||||
@@ -166,50 +166,50 @@ mal_result mal_rb_init_ex(size_t subbufferSizeInBytes, size_t subbufferCount, si
|
||||
pRB->subbufferStrideInBytes = (pRB->subbufferSizeInBytes + (MA_SIMD_ALIGNMENT-1)) & ~MA_SIMD_ALIGNMENT;
|
||||
|
||||
size_t bufferSizeInBytes = (size_t)pRB->subbufferCount*pRB->subbufferStrideInBytes;
|
||||
pRB->pBuffer = mal_aligned_malloc(bufferSizeInBytes, MA_SIMD_ALIGNMENT);
|
||||
pRB->pBuffer = ma_aligned_malloc(bufferSizeInBytes, MA_SIMD_ALIGNMENT);
|
||||
if (pRB->pBuffer == NULL) {
|
||||
return MA_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
mal_zero_memory(pRB->pBuffer, bufferSizeInBytes);
|
||||
ma_zero_memory(pRB->pBuffer, bufferSizeInBytes);
|
||||
pRB->ownsBuffer = MA_TRUE;
|
||||
}
|
||||
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
mal_result mal_rb_init(size_t bufferSizeInBytes, void* pOptionalPreallocatedBuffer, mal_rb* pRB)
|
||||
ma_result ma_rb_init(size_t bufferSizeInBytes, void* pOptionalPreallocatedBuffer, ma_rb* pRB)
|
||||
{
|
||||
return mal_rb_init_ex(bufferSizeInBytes, 1, 0, pOptionalPreallocatedBuffer, pRB);
|
||||
return ma_rb_init_ex(bufferSizeInBytes, 1, 0, pOptionalPreallocatedBuffer, pRB);
|
||||
}
|
||||
|
||||
void mal_rb_uninit(mal_rb* pRB)
|
||||
void ma_rb_uninit(ma_rb* pRB)
|
||||
{
|
||||
if (pRB == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pRB->ownsBuffer) {
|
||||
mal_free(pRB->pBuffer);
|
||||
ma_free(pRB->pBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
mal_result mal_rb_acquire_read(mal_rb* pRB, size_t* pSizeInBytes, void** ppBufferOut)
|
||||
ma_result ma_rb_acquire_read(ma_rb* pRB, size_t* pSizeInBytes, void** ppBufferOut)
|
||||
{
|
||||
if (pRB == NULL || pSizeInBytes == NULL || ppBufferOut == NULL) {
|
||||
return MA_INVALID_ARGS;
|
||||
}
|
||||
|
||||
// The returned buffer should never move ahead of the write pointer.
|
||||
mal_uint32 writeOffset = pRB->encodedWriteOffset;
|
||||
mal_uint32 writeOffsetInBytes;
|
||||
mal_uint32 writeOffsetLoopFlag;
|
||||
mal_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag);
|
||||
ma_uint32 writeOffset = pRB->encodedWriteOffset;
|
||||
ma_uint32 writeOffsetInBytes;
|
||||
ma_uint32 writeOffsetLoopFlag;
|
||||
ma_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag);
|
||||
|
||||
mal_uint32 readOffset = pRB->encodedReadOffset;
|
||||
mal_uint32 readOffsetInBytes;
|
||||
mal_uint32 readOffsetLoopFlag;
|
||||
mal_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag);
|
||||
ma_uint32 readOffset = pRB->encodedReadOffset;
|
||||
ma_uint32 readOffsetInBytes;
|
||||
ma_uint32 readOffsetLoopFlag;
|
||||
ma_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag);
|
||||
|
||||
// The number of bytes available depends on whether or not the read and write pointers are on the same loop iteration. If so, we
|
||||
// can only read up to the write pointer. If not, we can only read up to the end of the buffer.
|
||||
@@ -226,60 +226,60 @@ mal_result mal_rb_acquire_read(mal_rb* pRB, size_t* pSizeInBytes, void** ppBuffe
|
||||
}
|
||||
|
||||
*pSizeInBytes = bytesRequested;
|
||||
(*ppBufferOut) = mal_rb__get_read_ptr(pRB);
|
||||
(*ppBufferOut) = ma_rb__get_read_ptr(pRB);
|
||||
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
mal_result mal_rb_commit_read(mal_rb* pRB, size_t sizeInBytes, void* pBufferOut)
|
||||
ma_result ma_rb_commit_read(ma_rb* pRB, size_t sizeInBytes, void* pBufferOut)
|
||||
{
|
||||
if (pRB == NULL) {
|
||||
return MA_INVALID_ARGS;
|
||||
}
|
||||
|
||||
// Validate the buffer.
|
||||
if (pBufferOut != mal_rb__get_read_ptr(pRB)) {
|
||||
if (pBufferOut != ma_rb__get_read_ptr(pRB)) {
|
||||
return MA_INVALID_ARGS;
|
||||
}
|
||||
|
||||
mal_uint32 readOffset = pRB->encodedReadOffset;
|
||||
mal_uint32 readOffsetInBytes;
|
||||
mal_uint32 readOffsetLoopFlag;
|
||||
mal_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag);
|
||||
ma_uint32 readOffset = pRB->encodedReadOffset;
|
||||
ma_uint32 readOffsetInBytes;
|
||||
ma_uint32 readOffsetLoopFlag;
|
||||
ma_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag);
|
||||
|
||||
// Check that sizeInBytes is correct. It should never go beyond the end of the buffer.
|
||||
mal_uint32 newReadOffsetInBytes = (mal_uint32)(readOffsetInBytes + sizeInBytes);
|
||||
ma_uint32 newReadOffsetInBytes = (ma_uint32)(readOffsetInBytes + sizeInBytes);
|
||||
if (newReadOffsetInBytes > pRB->subbufferSizeInBytes) {
|
||||
return MA_INVALID_ARGS; // <-- sizeInBytes will cause the read offset to overflow.
|
||||
}
|
||||
|
||||
// Move the read pointer back to the start if necessary.
|
||||
mal_uint32 newReadOffsetLoopFlag = readOffsetLoopFlag;
|
||||
ma_uint32 newReadOffsetLoopFlag = readOffsetLoopFlag;
|
||||
if (newReadOffsetInBytes == pRB->subbufferSizeInBytes) {
|
||||
newReadOffsetInBytes = 0;
|
||||
newReadOffsetLoopFlag ^= 0x80000000;
|
||||
}
|
||||
|
||||
mal_atomic_exchange_32(&pRB->encodedReadOffset, mal_rb__construct_offset(newReadOffsetLoopFlag, newReadOffsetInBytes));
|
||||
ma_atomic_exchange_32(&pRB->encodedReadOffset, ma_rb__construct_offset(newReadOffsetLoopFlag, newReadOffsetInBytes));
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
mal_result mal_rb_acquire_write(mal_rb* pRB, size_t* pSizeInBytes, void** ppBufferOut)
|
||||
ma_result ma_rb_acquire_write(ma_rb* pRB, size_t* pSizeInBytes, void** ppBufferOut)
|
||||
{
|
||||
if (pRB == NULL || pSizeInBytes == NULL || ppBufferOut == NULL) {
|
||||
return MA_INVALID_ARGS;
|
||||
}
|
||||
|
||||
// The returned buffer should never overtake the read buffer.
|
||||
mal_uint32 readOffset = pRB->encodedReadOffset;
|
||||
mal_uint32 readOffsetInBytes;
|
||||
mal_uint32 readOffsetLoopFlag;
|
||||
mal_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag);
|
||||
ma_uint32 readOffset = pRB->encodedReadOffset;
|
||||
ma_uint32 readOffsetInBytes;
|
||||
ma_uint32 readOffsetLoopFlag;
|
||||
ma_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag);
|
||||
|
||||
mal_uint32 writeOffset = pRB->encodedWriteOffset;
|
||||
mal_uint32 writeOffsetInBytes;
|
||||
mal_uint32 writeOffsetLoopFlag;
|
||||
mal_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag);
|
||||
ma_uint32 writeOffset = pRB->encodedWriteOffset;
|
||||
ma_uint32 writeOffsetInBytes;
|
||||
ma_uint32 writeOffsetLoopFlag;
|
||||
ma_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag);
|
||||
|
||||
// In the case of writing, if the write pointer and the read pointer are on the same loop iteration we can only
|
||||
// write up to the end of the buffer. Otherwise we can only write up to the read pointer. The write pointer should
|
||||
@@ -297,144 +297,144 @@ mal_result mal_rb_acquire_write(mal_rb* pRB, size_t* pSizeInBytes, void** ppBuff
|
||||
}
|
||||
|
||||
*pSizeInBytes = bytesRequested;
|
||||
*ppBufferOut = mal_rb__get_write_ptr(pRB);
|
||||
*ppBufferOut = ma_rb__get_write_ptr(pRB);
|
||||
|
||||
// Clear the buffer if desired.
|
||||
if (pRB->clearOnWriteAcquire) {
|
||||
mal_zero_memory(*ppBufferOut, *pSizeInBytes);
|
||||
ma_zero_memory(*ppBufferOut, *pSizeInBytes);
|
||||
}
|
||||
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
mal_result mal_rb_commit_write(mal_rb* pRB, size_t sizeInBytes, void* pBufferOut)
|
||||
ma_result ma_rb_commit_write(ma_rb* pRB, size_t sizeInBytes, void* pBufferOut)
|
||||
{
|
||||
if (pRB == NULL) {
|
||||
return MA_INVALID_ARGS;
|
||||
}
|
||||
|
||||
// Validate the buffer.
|
||||
if (pBufferOut != mal_rb__get_write_ptr(pRB)) {
|
||||
if (pBufferOut != ma_rb__get_write_ptr(pRB)) {
|
||||
return MA_INVALID_ARGS;
|
||||
}
|
||||
|
||||
mal_uint32 writeOffset = pRB->encodedWriteOffset;
|
||||
mal_uint32 writeOffsetInBytes;
|
||||
mal_uint32 writeOffsetLoopFlag;
|
||||
mal_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag);
|
||||
ma_uint32 writeOffset = pRB->encodedWriteOffset;
|
||||
ma_uint32 writeOffsetInBytes;
|
||||
ma_uint32 writeOffsetLoopFlag;
|
||||
ma_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag);
|
||||
|
||||
// Check that sizeInBytes is correct. It should never go beyond the end of the buffer.
|
||||
mal_uint32 newWriteOffsetInBytes = (mal_uint32)(writeOffsetInBytes + sizeInBytes);
|
||||
ma_uint32 newWriteOffsetInBytes = (ma_uint32)(writeOffsetInBytes + sizeInBytes);
|
||||
if (newWriteOffsetInBytes > pRB->subbufferSizeInBytes) {
|
||||
return MA_INVALID_ARGS; // <-- sizeInBytes will cause the read offset to overflow.
|
||||
}
|
||||
|
||||
// Move the read pointer back to the start if necessary.
|
||||
mal_uint32 newWriteOffsetLoopFlag = writeOffsetLoopFlag;
|
||||
ma_uint32 newWriteOffsetLoopFlag = writeOffsetLoopFlag;
|
||||
if (newWriteOffsetInBytes == pRB->subbufferSizeInBytes) {
|
||||
newWriteOffsetInBytes = 0;
|
||||
newWriteOffsetLoopFlag ^= 0x80000000;
|
||||
}
|
||||
|
||||
mal_atomic_exchange_32(&pRB->encodedWriteOffset, mal_rb__construct_offset(newWriteOffsetLoopFlag, newWriteOffsetInBytes));
|
||||
ma_atomic_exchange_32(&pRB->encodedWriteOffset, ma_rb__construct_offset(newWriteOffsetLoopFlag, newWriteOffsetInBytes));
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
mal_result mal_rb_seek_read(mal_rb* pRB, size_t offsetInBytes)
|
||||
ma_result ma_rb_seek_read(ma_rb* pRB, size_t offsetInBytes)
|
||||
{
|
||||
if (pRB == NULL || offsetInBytes > pRB->subbufferSizeInBytes) {
|
||||
return MA_INVALID_ARGS;
|
||||
}
|
||||
|
||||
mal_uint32 readOffset = pRB->encodedReadOffset;
|
||||
mal_uint32 readOffsetInBytes;
|
||||
mal_uint32 readOffsetLoopFlag;
|
||||
mal_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag);
|
||||
ma_uint32 readOffset = pRB->encodedReadOffset;
|
||||
ma_uint32 readOffsetInBytes;
|
||||
ma_uint32 readOffsetLoopFlag;
|
||||
ma_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag);
|
||||
|
||||
mal_uint32 writeOffset = pRB->encodedWriteOffset;
|
||||
mal_uint32 writeOffsetInBytes;
|
||||
mal_uint32 writeOffsetLoopFlag;
|
||||
mal_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag);
|
||||
ma_uint32 writeOffset = pRB->encodedWriteOffset;
|
||||
ma_uint32 writeOffsetInBytes;
|
||||
ma_uint32 writeOffsetLoopFlag;
|
||||
ma_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag);
|
||||
|
||||
mal_uint32 newReadOffsetInBytes = readOffsetInBytes;
|
||||
mal_uint32 newReadOffsetLoopFlag = readOffsetLoopFlag;
|
||||
ma_uint32 newReadOffsetInBytes = readOffsetInBytes;
|
||||
ma_uint32 newReadOffsetLoopFlag = readOffsetLoopFlag;
|
||||
|
||||
// We cannot go past the write buffer.
|
||||
if (readOffsetLoopFlag == writeOffsetLoopFlag) {
|
||||
if ((readOffsetInBytes + offsetInBytes) > writeOffsetInBytes) {
|
||||
newReadOffsetInBytes = writeOffsetInBytes;
|
||||
} else {
|
||||
newReadOffsetInBytes = (mal_uint32)(readOffsetInBytes + offsetInBytes);
|
||||
newReadOffsetInBytes = (ma_uint32)(readOffsetInBytes + offsetInBytes);
|
||||
}
|
||||
} else {
|
||||
// May end up looping.
|
||||
if ((readOffsetInBytes + offsetInBytes) >= pRB->subbufferSizeInBytes) {
|
||||
newReadOffsetInBytes = (mal_uint32)(readOffsetInBytes + offsetInBytes) - pRB->subbufferSizeInBytes;
|
||||
newReadOffsetInBytes = (ma_uint32)(readOffsetInBytes + offsetInBytes) - pRB->subbufferSizeInBytes;
|
||||
newReadOffsetLoopFlag ^= 0x80000000; /* <-- Looped. */
|
||||
} else {
|
||||
newReadOffsetInBytes = (mal_uint32)(readOffsetInBytes + offsetInBytes);
|
||||
newReadOffsetInBytes = (ma_uint32)(readOffsetInBytes + offsetInBytes);
|
||||
}
|
||||
}
|
||||
|
||||
mal_atomic_exchange_32(&pRB->encodedReadOffset, mal_rb__construct_offset(newReadOffsetInBytes, newReadOffsetLoopFlag));
|
||||
ma_atomic_exchange_32(&pRB->encodedReadOffset, ma_rb__construct_offset(newReadOffsetInBytes, newReadOffsetLoopFlag));
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
mal_result mal_rb_seek_write(mal_rb* pRB, size_t offsetInBytes)
|
||||
ma_result ma_rb_seek_write(ma_rb* pRB, size_t offsetInBytes)
|
||||
{
|
||||
if (pRB == NULL) {
|
||||
return MA_INVALID_ARGS;
|
||||
}
|
||||
|
||||
mal_uint32 readOffset = pRB->encodedReadOffset;
|
||||
mal_uint32 readOffsetInBytes;
|
||||
mal_uint32 readOffsetLoopFlag;
|
||||
mal_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag);
|
||||
ma_uint32 readOffset = pRB->encodedReadOffset;
|
||||
ma_uint32 readOffsetInBytes;
|
||||
ma_uint32 readOffsetLoopFlag;
|
||||
ma_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag);
|
||||
|
||||
mal_uint32 writeOffset = pRB->encodedWriteOffset;
|
||||
mal_uint32 writeOffsetInBytes;
|
||||
mal_uint32 writeOffsetLoopFlag;
|
||||
mal_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag);
|
||||
ma_uint32 writeOffset = pRB->encodedWriteOffset;
|
||||
ma_uint32 writeOffsetInBytes;
|
||||
ma_uint32 writeOffsetLoopFlag;
|
||||
ma_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag);
|
||||
|
||||
mal_uint32 newWriteOffsetInBytes = writeOffsetInBytes;
|
||||
mal_uint32 newWriteOffsetLoopFlag = writeOffsetLoopFlag;
|
||||
ma_uint32 newWriteOffsetInBytes = writeOffsetInBytes;
|
||||
ma_uint32 newWriteOffsetLoopFlag = writeOffsetLoopFlag;
|
||||
|
||||
// We cannot go past the write buffer.
|
||||
if (readOffsetLoopFlag == writeOffsetLoopFlag) {
|
||||
// May end up looping.
|
||||
if ((writeOffsetInBytes + offsetInBytes) >= pRB->subbufferSizeInBytes) {
|
||||
newWriteOffsetInBytes = (mal_uint32)(writeOffsetInBytes + offsetInBytes) - pRB->subbufferSizeInBytes;
|
||||
newWriteOffsetInBytes = (ma_uint32)(writeOffsetInBytes + offsetInBytes) - pRB->subbufferSizeInBytes;
|
||||
newWriteOffsetLoopFlag ^= 0x80000000; /* <-- Looped. */
|
||||
} else {
|
||||
newWriteOffsetInBytes = (mal_uint32)(writeOffsetInBytes + offsetInBytes);
|
||||
newWriteOffsetInBytes = (ma_uint32)(writeOffsetInBytes + offsetInBytes);
|
||||
}
|
||||
} else {
|
||||
if ((writeOffsetInBytes + offsetInBytes) > readOffsetInBytes) {
|
||||
newWriteOffsetInBytes = readOffsetInBytes;
|
||||
} else {
|
||||
newWriteOffsetInBytes = (mal_uint32)(writeOffsetInBytes + offsetInBytes);
|
||||
newWriteOffsetInBytes = (ma_uint32)(writeOffsetInBytes + offsetInBytes);
|
||||
}
|
||||
}
|
||||
|
||||
mal_atomic_exchange_32(&pRB->encodedWriteOffset, mal_rb__construct_offset(newWriteOffsetInBytes, newWriteOffsetLoopFlag));
|
||||
ma_atomic_exchange_32(&pRB->encodedWriteOffset, ma_rb__construct_offset(newWriteOffsetInBytes, newWriteOffsetLoopFlag));
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
mal_int32 mal_rb_pointer_distance(mal_rb* pRB)
|
||||
ma_int32 ma_rb_pointer_distance(ma_rb* pRB)
|
||||
{
|
||||
if (pRB == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
mal_uint32 readOffset = pRB->encodedReadOffset;
|
||||
mal_uint32 readOffsetInBytes;
|
||||
mal_uint32 readOffsetLoopFlag;
|
||||
mal_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag);
|
||||
ma_uint32 readOffset = pRB->encodedReadOffset;
|
||||
ma_uint32 readOffsetInBytes;
|
||||
ma_uint32 readOffsetLoopFlag;
|
||||
ma_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag);
|
||||
|
||||
mal_uint32 writeOffset = pRB->encodedWriteOffset;
|
||||
mal_uint32 writeOffsetInBytes;
|
||||
mal_uint32 writeOffsetLoopFlag;
|
||||
mal_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag);
|
||||
ma_uint32 writeOffset = pRB->encodedWriteOffset;
|
||||
ma_uint32 writeOffsetInBytes;
|
||||
ma_uint32 writeOffsetLoopFlag;
|
||||
ma_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag);
|
||||
|
||||
if (readOffsetLoopFlag == writeOffsetLoopFlag) {
|
||||
return writeOffsetInBytes - readOffsetInBytes;
|
||||
@@ -443,7 +443,7 @@ mal_int32 mal_rb_pointer_distance(mal_rb* pRB)
|
||||
}
|
||||
}
|
||||
|
||||
size_t mal_rb_get_subbuffer_stride(mal_rb* pRB)
|
||||
size_t ma_rb_get_subbuffer_stride(ma_rb* pRB)
|
||||
{
|
||||
if (pRB == NULL) {
|
||||
return 0;
|
||||
@@ -456,48 +456,48 @@ size_t mal_rb_get_subbuffer_stride(mal_rb* pRB)
|
||||
return (size_t)pRB->subbufferStrideInBytes;
|
||||
}
|
||||
|
||||
size_t mal_rb_get_subbuffer_offset(mal_rb* pRB, size_t subbufferIndex)
|
||||
size_t ma_rb_get_subbuffer_offset(ma_rb* pRB, size_t subbufferIndex)
|
||||
{
|
||||
if (pRB == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return subbufferIndex * mal_rb_get_subbuffer_stride(pRB);
|
||||
return subbufferIndex * ma_rb_get_subbuffer_stride(pRB);
|
||||
}
|
||||
|
||||
void* mal_rb_get_subbuffer_ptr(mal_rb* pRB, size_t subbufferIndex, void* pBuffer)
|
||||
void* ma_rb_get_subbuffer_ptr(ma_rb* pRB, size_t subbufferIndex, void* pBuffer)
|
||||
{
|
||||
if (pRB == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return mal_offset_ptr(pBuffer, mal_rb_get_subbuffer_offset(pRB, subbufferIndex));
|
||||
return ma_offset_ptr(pBuffer, ma_rb_get_subbuffer_offset(pRB, subbufferIndex));
|
||||
}
|
||||
|
||||
|
||||
/* mal_pcm_rb */
|
||||
/* ma_pcm_rb */
|
||||
|
||||
mal_uint32 mal_pcm_rb_get_bpf(mal_pcm_rb* pRB)
|
||||
ma_uint32 ma_pcm_rb_get_bpf(ma_pcm_rb* pRB)
|
||||
{
|
||||
mal_assert(pRB != NULL);
|
||||
ma_assert(pRB != NULL);
|
||||
|
||||
return mal_get_bytes_per_frame(pRB->format, pRB->channels);
|
||||
return ma_get_bytes_per_frame(pRB->format, pRB->channels);
|
||||
}
|
||||
|
||||
mal_result mal_pcm_rb_init_ex(mal_format format, mal_uint32 channels, size_t subbufferSizeInFrames, size_t subbufferCount, size_t subbufferStrideInFrames, void* pOptionalPreallocatedBuffer, mal_pcm_rb* pRB)
|
||||
ma_result ma_pcm_rb_init_ex(ma_format format, ma_uint32 channels, size_t subbufferSizeInFrames, size_t subbufferCount, size_t subbufferStrideInFrames, void* pOptionalPreallocatedBuffer, ma_pcm_rb* pRB)
|
||||
{
|
||||
if (pRB == NULL) {
|
||||
return MA_INVALID_ARGS;
|
||||
}
|
||||
|
||||
mal_zero_object(pRB);
|
||||
ma_zero_object(pRB);
|
||||
|
||||
mal_uint32 bpf = mal_get_bytes_per_frame(format, channels);
|
||||
ma_uint32 bpf = ma_get_bytes_per_frame(format, channels);
|
||||
if (bpf == 0) {
|
||||
return MA_INVALID_ARGS;
|
||||
}
|
||||
|
||||
mal_result result = mal_rb_init_ex(subbufferSizeInFrames*bpf, subbufferCount, subbufferStrideInFrames*bpf, pOptionalPreallocatedBuffer, &pRB->rb);
|
||||
ma_result result = ma_rb_init_ex(subbufferSizeInFrames*bpf, subbufferCount, subbufferStrideInFrames*bpf, pOptionalPreallocatedBuffer, &pRB->rb);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
@@ -508,130 +508,130 @@ mal_result mal_pcm_rb_init_ex(mal_format format, mal_uint32 channels, size_t sub
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
mal_result mal_pcm_rb_init(mal_format format, mal_uint32 channels, size_t bufferSizeInFrames, void* pOptionalPreallocatedBuffer, mal_pcm_rb* pRB)
|
||||
ma_result ma_pcm_rb_init(ma_format format, ma_uint32 channels, size_t bufferSizeInFrames, void* pOptionalPreallocatedBuffer, ma_pcm_rb* pRB)
|
||||
{
|
||||
return mal_pcm_rb_init_ex(format, channels, bufferSizeInFrames, 1, 0, pOptionalPreallocatedBuffer, pRB);
|
||||
return ma_pcm_rb_init_ex(format, channels, bufferSizeInFrames, 1, 0, pOptionalPreallocatedBuffer, pRB);
|
||||
}
|
||||
|
||||
void mal_pcm_rb_uninit(mal_pcm_rb* pRB)
|
||||
void ma_pcm_rb_uninit(ma_pcm_rb* pRB)
|
||||
{
|
||||
if (pRB == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
mal_rb_uninit(&pRB->rb);
|
||||
ma_rb_uninit(&pRB->rb);
|
||||
}
|
||||
|
||||
mal_result mal_pcm_rb_acquire_read(mal_pcm_rb* pRB, size_t* pSizeInFrames, void** ppBufferOut)
|
||||
ma_result ma_pcm_rb_acquire_read(ma_pcm_rb* pRB, size_t* pSizeInFrames, void** ppBufferOut)
|
||||
{
|
||||
size_t sizeInBytes;
|
||||
mal_result result;
|
||||
ma_result result;
|
||||
|
||||
if (pRB == NULL || pSizeInFrames == NULL) {
|
||||
return MA_INVALID_ARGS;
|
||||
}
|
||||
|
||||
sizeInBytes = *pSizeInFrames * mal_pcm_rb_get_bpf(pRB);
|
||||
sizeInBytes = *pSizeInFrames * ma_pcm_rb_get_bpf(pRB);
|
||||
|
||||
result = mal_rb_acquire_read(&pRB->rb, &sizeInBytes, ppBufferOut);
|
||||
result = ma_rb_acquire_read(&pRB->rb, &sizeInBytes, ppBufferOut);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
*pSizeInFrames = sizeInBytes / mal_pcm_rb_get_bpf(pRB);
|
||||
*pSizeInFrames = sizeInBytes / ma_pcm_rb_get_bpf(pRB);
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
mal_result mal_pcm_rb_commit_read(mal_pcm_rb* pRB, size_t sizeInFrames, void* pBufferOut)
|
||||
ma_result ma_pcm_rb_commit_read(ma_pcm_rb* pRB, size_t sizeInFrames, void* pBufferOut)
|
||||
{
|
||||
if (pRB == NULL) {
|
||||
return MA_INVALID_ARGS;
|
||||
}
|
||||
|
||||
return mal_rb_commit_read(&pRB->rb, sizeInFrames * mal_pcm_rb_get_bpf(pRB), pBufferOut);
|
||||
return ma_rb_commit_read(&pRB->rb, sizeInFrames * ma_pcm_rb_get_bpf(pRB), pBufferOut);
|
||||
}
|
||||
|
||||
mal_result mal_pcm_rb_acquire_write(mal_pcm_rb* pRB, size_t* pSizeInFrames, void** ppBufferOut)
|
||||
ma_result ma_pcm_rb_acquire_write(ma_pcm_rb* pRB, size_t* pSizeInFrames, void** ppBufferOut)
|
||||
{
|
||||
size_t sizeInBytes;
|
||||
mal_result result;
|
||||
ma_result result;
|
||||
|
||||
if (pRB == NULL) {
|
||||
return MA_INVALID_ARGS;
|
||||
}
|
||||
|
||||
sizeInBytes = *pSizeInFrames * mal_pcm_rb_get_bpf(pRB);
|
||||
sizeInBytes = *pSizeInFrames * ma_pcm_rb_get_bpf(pRB);
|
||||
|
||||
result = mal_rb_acquire_write(&pRB->rb, &sizeInBytes, ppBufferOut);
|
||||
result = ma_rb_acquire_write(&pRB->rb, &sizeInBytes, ppBufferOut);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
*pSizeInFrames = sizeInBytes / mal_pcm_rb_get_bpf(pRB);
|
||||
*pSizeInFrames = sizeInBytes / ma_pcm_rb_get_bpf(pRB);
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
mal_result mal_pcm_rb_commit_write(mal_pcm_rb* pRB, size_t sizeInFrames, void* pBufferOut)
|
||||
ma_result ma_pcm_rb_commit_write(ma_pcm_rb* pRB, size_t sizeInFrames, void* pBufferOut)
|
||||
{
|
||||
if (pRB == NULL) {
|
||||
return MA_INVALID_ARGS;
|
||||
}
|
||||
|
||||
return mal_rb_commit_write(&pRB->rb, sizeInFrames * mal_pcm_rb_get_bpf(pRB), pBufferOut);
|
||||
return ma_rb_commit_write(&pRB->rb, sizeInFrames * ma_pcm_rb_get_bpf(pRB), pBufferOut);
|
||||
}
|
||||
|
||||
mal_result mal_pcm_rb_seek_read(mal_pcm_rb* pRB, size_t offsetInFrames)
|
||||
ma_result ma_pcm_rb_seek_read(ma_pcm_rb* pRB, size_t offsetInFrames)
|
||||
{
|
||||
if (pRB == NULL) {
|
||||
return MA_INVALID_ARGS;
|
||||
}
|
||||
|
||||
return mal_rb_seek_read(&pRB->rb, offsetInFrames * mal_pcm_rb_get_bpf(pRB));
|
||||
return ma_rb_seek_read(&pRB->rb, offsetInFrames * ma_pcm_rb_get_bpf(pRB));
|
||||
}
|
||||
|
||||
mal_result mal_pcm_rb_seek_write(mal_pcm_rb* pRB, size_t offsetInFrames)
|
||||
ma_result ma_pcm_rb_seek_write(ma_pcm_rb* pRB, size_t offsetInFrames)
|
||||
{
|
||||
if (pRB == NULL) {
|
||||
return MA_INVALID_ARGS;
|
||||
}
|
||||
|
||||
return mal_rb_seek_write(&pRB->rb, offsetInFrames * mal_pcm_rb_get_bpf(pRB));
|
||||
return ma_rb_seek_write(&pRB->rb, offsetInFrames * ma_pcm_rb_get_bpf(pRB));
|
||||
}
|
||||
|
||||
mal_int32 mal_pcm_rb_pointer_disance(mal_pcm_rb* pRB)
|
||||
ma_int32 ma_pcm_rb_pointer_disance(ma_pcm_rb* pRB)
|
||||
{
|
||||
if (pRB == NULL) {
|
||||
return MA_INVALID_ARGS;
|
||||
}
|
||||
|
||||
return mal_rb_pointer_distance(&pRB->rb) / mal_pcm_rb_get_bpf(pRB);
|
||||
return ma_rb_pointer_distance(&pRB->rb) / ma_pcm_rb_get_bpf(pRB);
|
||||
}
|
||||
|
||||
size_t mal_pcm_rb_get_subbuffer_stride(mal_pcm_rb* pRB)
|
||||
size_t ma_pcm_rb_get_subbuffer_stride(ma_pcm_rb* pRB)
|
||||
{
|
||||
if (pRB == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return mal_rb_get_subbuffer_stride(&pRB->rb) / mal_pcm_rb_get_bpf(pRB);
|
||||
return ma_rb_get_subbuffer_stride(&pRB->rb) / ma_pcm_rb_get_bpf(pRB);
|
||||
}
|
||||
|
||||
size_t mal_pcm_rb_get_subbuffer_offset(mal_pcm_rb* pRB, size_t subbufferIndex)
|
||||
size_t ma_pcm_rb_get_subbuffer_offset(ma_pcm_rb* pRB, size_t subbufferIndex)
|
||||
{
|
||||
if (pRB == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return mal_rb_get_subbuffer_offset(&pRB->rb, subbufferIndex) / mal_pcm_rb_get_bpf(pRB);
|
||||
return ma_rb_get_subbuffer_offset(&pRB->rb, subbufferIndex) / ma_pcm_rb_get_bpf(pRB);
|
||||
}
|
||||
|
||||
void* mal_pcm_rb_get_subbuffer_ptr(mal_pcm_rb* pRB, size_t subbufferIndex, void* pBuffer)
|
||||
void* ma_pcm_rb_get_subbuffer_ptr(ma_pcm_rb* pRB, size_t subbufferIndex, void* pBuffer)
|
||||
{
|
||||
if (pRB == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return mal_rb_get_subbuffer_ptr(&pRB->rb, subbufferIndex, pBuffer);
|
||||
return ma_rb_get_subbuffer_ptr(&pRB->rb, subbufferIndex, pBuffer);
|
||||
}
|
||||
|
||||
#endif // MINIAUDIO_IMPLEMENTATION
|
||||
|
||||
@@ -4,46 +4,46 @@
|
||||
#define MA_DEBUG_OUTPUT
|
||||
#define MINIAUDIO_IMPLEMENTATION
|
||||
#include "../../miniaudio.h"
|
||||
#include "../mal_resampler.h"
|
||||
#include "../ma_resampler.h"
|
||||
|
||||
#define SAMPLE_RATE_IN 44100
|
||||
#define SAMPLE_RATE_OUT 44100
|
||||
#define CHANNELS 1
|
||||
#define OUTPUT_FILE "output.wav"
|
||||
|
||||
mal_sine_wave sineWave;
|
||||
ma_sine_wave sineWave;
|
||||
|
||||
mal_uint32 on_read(mal_resampler* pResampler, mal_uint32 frameCount, void** ppFramesOut)
|
||||
ma_uint32 on_read(ma_resampler* pResampler, ma_uint32 frameCount, void** ppFramesOut)
|
||||
{
|
||||
mal_assert(pResampler->config.format == mal_format_f32);
|
||||
ma_assert(pResampler->config.format == ma_format_f32);
|
||||
|
||||
return (mal_uint32)mal_sine_wave_read_f32_ex(&sineWave, frameCount, pResampler->config.channels, pResampler->config.layout, (float**)ppFramesOut);
|
||||
return (ma_uint32)ma_sine_wave_read_f32_ex(&sineWave, frameCount, pResampler->config.channels, pResampler->config.layout, (float**)ppFramesOut);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
mal_result result;
|
||||
mal_resampler_config resamplerConfig;
|
||||
mal_resampler resampler;
|
||||
ma_result result;
|
||||
ma_resampler_config resamplerConfig;
|
||||
ma_resampler resampler;
|
||||
|
||||
mal_zero_object(&resamplerConfig);
|
||||
resamplerConfig.format = mal_format_f32;
|
||||
ma_zero_object(&resamplerConfig);
|
||||
resamplerConfig.format = ma_format_f32;
|
||||
resamplerConfig.channels = CHANNELS;
|
||||
resamplerConfig.sampleRateIn = SAMPLE_RATE_IN;
|
||||
resamplerConfig.sampleRateOut = SAMPLE_RATE_OUT;
|
||||
resamplerConfig.algorithm = mal_resampler_algorithm_linear;
|
||||
resamplerConfig.endOfInputMode = mal_resampler_end_of_input_mode_consume;
|
||||
resamplerConfig.layout = mal_stream_layout_interleaved;
|
||||
resamplerConfig.algorithm = ma_resampler_algorithm_linear;
|
||||
resamplerConfig.endOfInputMode = ma_resampler_end_of_input_mode_consume;
|
||||
resamplerConfig.layout = ma_stream_layout_interleaved;
|
||||
resamplerConfig.onRead = on_read;
|
||||
resamplerConfig.pUserData = NULL;
|
||||
|
||||
result = mal_resampler_init(&resamplerConfig, &resampler);
|
||||
result = ma_resampler_init(&resamplerConfig, &resampler);
|
||||
if (result != MA_SUCCESS) {
|
||||
printf("Failed to initialize resampler.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
mal_sine_wave_init(0.5, 400, resamplerConfig.sampleRateIn, &sineWave);
|
||||
ma_sine_wave_init(0.5, 400, resamplerConfig.sampleRateIn, &sineWave);
|
||||
|
||||
|
||||
// Write to a WAV file. We'll do about 10 seconds worth, making sure we read in chunks to make sure everything is seamless.
|
||||
@@ -57,10 +57,10 @@ int main(int argc, char** argv)
|
||||
|
||||
float buffer[SAMPLE_RATE_IN*CHANNELS];
|
||||
float* pBuffer = buffer;
|
||||
mal_uint32 iterations = 10;
|
||||
mal_uint32 framesToReadPerIteration = mal_countof(buffer)/CHANNELS;
|
||||
for (mal_uint32 i = 0; i < iterations; ++i) {
|
||||
mal_uint32 framesRead = (mal_uint32)mal_resampler_read(&resampler, framesToReadPerIteration, &pBuffer);
|
||||
ma_uint32 iterations = 10;
|
||||
ma_uint32 framesToReadPerIteration = ma_countof(buffer)/CHANNELS;
|
||||
for (ma_uint32 i = 0; i < iterations; ++i) {
|
||||
ma_uint32 framesRead = (ma_uint32)ma_resampler_read(&resampler, framesToReadPerIteration, &pBuffer);
|
||||
drwav_write(pWavWriter, framesRead*CHANNELS, buffer);
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -2,7 +2,7 @@ Building
|
||||
========
|
||||
Build and run these test from this folder. Example:
|
||||
|
||||
clear && ./mal_build_tests_linux && ./bin/mal_test_0
|
||||
clear && ./ma_build_tests_linux && ./bin/ma_test_0
|
||||
|
||||
These tests load resources from hard coded paths which point to the "res" folder. These
|
||||
paths are based on the assumption that the current directory is where the build files
|
||||
@@ -14,9 +14,9 @@ On Windows, you need to move into this directory and run emsdk_env.bat from a co
|
||||
prompt using an absolute path like "C:\emsdk\emsdk_env.bat". Note that PowerShell doesn't
|
||||
work for me for some reason. Then, run the relevant batch file:
|
||||
|
||||
mal_build_tests_emscripten.bat
|
||||
ma_build_tests_emscripten.bat
|
||||
|
||||
The output will be placed in the bin folder. If you have output WASM it may not work when
|
||||
running the web page locally. To test you can run with something like this:
|
||||
|
||||
emrun bin/mal_test_0_emscripten.html
|
||||
emrun bin/ma_test_0_emscripten.html
|
||||
@@ -1,8 +1,8 @@
|
||||
cc mal_test_0.c -o ./bin/mal_test_0 -Wall -lpthread -lm
|
||||
c++ mal_test_0.c -o ./bin/mal_test_0_cpp -Wall -lpthread -lm
|
||||
cc ma_test_0.c -o ./bin/ma_test_0 -Wall -lpthread -lm
|
||||
c++ ma_test_0.c -o ./bin/ma_test_0_cpp -Wall -lpthread -lm
|
||||
|
||||
cc mal_profiling.c -o ./bin/mal_profiling -Wall -lpthread -lm
|
||||
c++ mal_profiling.c -o ./bin/mal_profiling_cpp -Wall -lpthread -lm
|
||||
cc ma_profiling.c -o ./bin/ma_profiling -Wall -lpthread -lm
|
||||
c++ ma_profiling.c -o ./bin/ma_profiling_cpp -Wall -lpthread -lm
|
||||
|
||||
cc mal_dithering.c -o ./bin/mal_dithering -Wall -lpthread -lm
|
||||
c++ mal_dithering.c -o ./bin/mal_dithering_cpp -Wall -lpthread -lm
|
||||
cc ma_dithering.c -o ./bin/ma_dithering -Wall -lpthread -lm
|
||||
c++ ma_dithering.c -o ./bin/ma_dithering_cpp -Wall -lpthread -lm
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
emcc ./mal_test_0.c -o ./bin/mal_test_0_emscripten.html -s WASM=0 -std=c99
|
||||
emcc ./mal_duplex.c -o ./bin/mal_duplex.html -s WASM=0 -std=c99
|
||||
emcc ./ma_test_0.c -o ./bin/ma_test_0_emscripten.html -s WASM=0 -std=c99
|
||||
emcc ./ma_duplex.c -o ./bin/ma_duplex.html -s WASM=0 -std=c99
|
||||
@@ -1,11 +1,11 @@
|
||||
#!/bin/bash
|
||||
cc mal_test_0.c -o ./bin/mal_test_0 -Wall -ldl -lpthread -lm
|
||||
c++ mal_test_0.c -o ./bin/mal_test_0_cpp -Wall -ldl -lpthread -lm
|
||||
cc ma_test_0.c -o ./bin/ma_test_0 -Wall -ldl -lpthread -lm
|
||||
c++ ma_test_0.c -o ./bin/ma_test_0_cpp -Wall -ldl -lpthread -lm
|
||||
|
||||
cc mal_profiling.c -o ./bin/mal_profiling -Wall -ldl -lpthread -lm
|
||||
c++ mal_profiling.c -o ./bin/mal_profiling_cpp -Wall -ldl -lpthread -lm
|
||||
cc ma_profiling.c -o ./bin/ma_profiling -Wall -ldl -lpthread -lm
|
||||
c++ ma_profiling.c -o ./bin/ma_profiling_cpp -Wall -ldl -lpthread -lm
|
||||
|
||||
cc mal_dithering.c -o ./bin/mal_dithering -Wall -ldl -lpthread -lm
|
||||
c++ mal_dithering.c -o ./bin/mal_dithering_cpp -Wall -ldl -lpthread -lm
|
||||
cc ma_dithering.c -o ./bin/ma_dithering -Wall -ldl -lpthread -lm
|
||||
c++ ma_dithering.c -o ./bin/ma_dithering_cpp -Wall -ldl -lpthread -lm
|
||||
|
||||
cc mal_duplex.c -o ./bin/mal_duplex -Wall -ldl -lpthread -lm
|
||||
cc ma_duplex.c -o ./bin/ma_duplex -Wall -ldl -lpthread -lm
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
cc mal_test_0.c -o ./bin/mal_test_0 -Wall -lpthread -lm
|
||||
c++ mal_test_0.c -o ./bin/mal_test_0_cpp -Wall -lpthread -lm
|
||||
cc ma_test_0.c -o ./bin/ma_test_0 -Wall -lpthread -lm
|
||||
c++ ma_test_0.c -o ./bin/ma_test_0_cpp -Wall -lpthread -lm
|
||||
|
||||
cc mal_profiling.c -o ./bin/mal_profiling -Wall -lpthread -lm
|
||||
c++ mal_profiling.c -o ./bin/mal_profiling_cpp -Wall -lpthread -lm
|
||||
cc ma_profiling.c -o ./bin/ma_profiling -Wall -lpthread -lm
|
||||
c++ ma_profiling.c -o ./bin/ma_profiling_cpp -Wall -lpthread -lm
|
||||
|
||||
cc mal_dithering.c -o ./bin/mal_dithering -Wall -lpthread -lm
|
||||
c++ mal_dithering.c -o ./bin/mal_dithering_cpp -Wall -lpthread -lm
|
||||
cc ma_dithering.c -o ./bin/ma_dithering -Wall -lpthread -lm
|
||||
c++ ma_dithering.c -o ./bin/ma_dithering_cpp -Wall -lpthread -lm
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#!/bin/bash
|
||||
cc mal_test_0.c -o ./bin/mal_test_0 -Wall -ldl -lpthread -lm
|
||||
c++ mal_test_0.c -o ./bin/mal_test_0_cpp -Wall -ldl -lpthread -lm
|
||||
cc ma_test_0.c -o ./bin/ma_test_0 -Wall -ldl -lpthread -lm
|
||||
c++ ma_test_0.c -o ./bin/ma_test_0_cpp -Wall -ldl -lpthread -lm
|
||||
|
||||
cc mal_profiling.c -o ./bin/mal_profiling -Wall -ldl -lpthread -lm -mfpu=neon -O2
|
||||
c++ mal_profiling.c -o ./bin/mal_profiling_cpp -Wall -ldl -lpthread -lm -mfpu=neon -O2
|
||||
cc ma_profiling.c -o ./bin/ma_profiling -Wall -ldl -lpthread -lm -mfpu=neon -O2
|
||||
c++ ma_profiling.c -o ./bin/ma_profiling_cpp -Wall -ldl -lpthread -lm -mfpu=neon -O2
|
||||
|
||||
cc mal_dithering.c -o ./bin/mal_dithering -Wall -ldl -lpthread -lm
|
||||
c++ mal_dithering.c -o ./bin/mal_dithering_cpp -Wall -ldl -lpthread -lm
|
||||
cc ma_dithering.c -o ./bin/ma_dithering -Wall -ldl -lpthread -lm
|
||||
c++ ma_dithering.c -o ./bin/ma_dithering_cpp -Wall -ldl -lpthread -lm
|
||||
@@ -4,11 +4,11 @@ SET cpp_compiler=g++
|
||||
SET options=-Wall
|
||||
@echo on
|
||||
|
||||
%c_compiler% mal_test_0.c -o ./bin/mal_test_0.exe %options%
|
||||
%cpp_compiler% mal_test_0.cpp -o ./bin/mal_test_0_cpp.exe %options%
|
||||
%c_compiler% ma_test_0.c -o ./bin/ma_test_0.exe %options%
|
||||
%cpp_compiler% ma_test_0.cpp -o ./bin/ma_test_0_cpp.exe %options%
|
||||
|
||||
%c_compiler% mal_profiling.c -o ./bin/mal_profiling.exe %options% -s -O2
|
||||
%cpp_compiler% mal_profiling.c -o ./bin/mal_profiling_cpp.exe %options% -s -O2
|
||||
%c_compiler% ma_profiling.c -o ./bin/ma_profiling.exe %options% -s -O2
|
||||
%cpp_compiler% ma_profiling.c -o ./bin/ma_profiling_cpp.exe %options% -s -O2
|
||||
|
||||
%c_compiler% mal_dithering.c -o ./bin/mal_dithering.exe %options%
|
||||
%cpp_compiler% mal_dithering.c -o ./bin/mal_dithering_cpp.exe %options%
|
||||
%c_compiler% ma_dithering.c -o ./bin/ma_dithering.exe %options%
|
||||
%cpp_compiler% ma_dithering.c -o ./bin/ma_dithering_cpp.exe %options%
|
||||
+41
-41
@@ -4,20 +4,20 @@
|
||||
#define MINIAUDIO_IMPLEMENTATION
|
||||
#include "../miniaudio.h"
|
||||
|
||||
int print_context_info(mal_context* pContext)
|
||||
int print_context_info(ma_context* pContext)
|
||||
{
|
||||
mal_result result = MA_SUCCESS;
|
||||
mal_device_info* pPlaybackDeviceInfos;
|
||||
mal_uint32 playbackDeviceCount;
|
||||
mal_device_info* pCaptureDeviceInfos;
|
||||
mal_uint32 captureDeviceCount;
|
||||
ma_result result = MA_SUCCESS;
|
||||
ma_device_info* pPlaybackDeviceInfos;
|
||||
ma_uint32 playbackDeviceCount;
|
||||
ma_device_info* pCaptureDeviceInfos;
|
||||
ma_uint32 captureDeviceCount;
|
||||
|
||||
printf("BACKEND: %s\n", mal_get_backend_name(pContext->backend));
|
||||
printf("BACKEND: %s\n", ma_get_backend_name(pContext->backend));
|
||||
|
||||
// Enumeration.
|
||||
printf(" Enumerating Devices... ");
|
||||
{
|
||||
result = mal_context_get_devices(pContext, &pPlaybackDeviceInfos, &playbackDeviceCount, &pCaptureDeviceInfos, &captureDeviceCount);
|
||||
result = ma_context_get_devices(pContext, &pPlaybackDeviceInfos, &playbackDeviceCount, &pCaptureDeviceInfos, &captureDeviceCount);
|
||||
if (result == MA_SUCCESS) {
|
||||
printf("Done\n");
|
||||
} else {
|
||||
@@ -26,12 +26,12 @@ int print_context_info(mal_context* pContext)
|
||||
}
|
||||
|
||||
printf(" Playback Devices (%d)\n", playbackDeviceCount);
|
||||
for (mal_uint32 iDevice = 0; iDevice < playbackDeviceCount; ++iDevice) {
|
||||
for (ma_uint32 iDevice = 0; iDevice < playbackDeviceCount; ++iDevice) {
|
||||
printf(" %d: %s\n", iDevice, pPlaybackDeviceInfos[iDevice].name);
|
||||
}
|
||||
|
||||
printf(" Capture Devices (%d)\n", captureDeviceCount);
|
||||
for (mal_uint32 iDevice = 0; iDevice < captureDeviceCount; ++iDevice) {
|
||||
for (ma_uint32 iDevice = 0; iDevice < captureDeviceCount; ++iDevice) {
|
||||
printf(" %d: %s\n", iDevice, pCaptureDeviceInfos[iDevice].name);
|
||||
}
|
||||
}
|
||||
@@ -40,10 +40,10 @@ int print_context_info(mal_context* pContext)
|
||||
printf(" Getting Device Information...\n");
|
||||
{
|
||||
printf(" Playback Devices (%d)\n", playbackDeviceCount);
|
||||
for (mal_uint32 iDevice = 0; iDevice < playbackDeviceCount; ++iDevice) {
|
||||
for (ma_uint32 iDevice = 0; iDevice < playbackDeviceCount; ++iDevice) {
|
||||
printf(" %d: %s\n", iDevice, pPlaybackDeviceInfos[iDevice].name);
|
||||
|
||||
result = mal_context_get_device_info(pContext, mal_device_type_playback, &pPlaybackDeviceInfos[iDevice].id, mal_share_mode_shared, &pPlaybackDeviceInfos[iDevice]);
|
||||
result = ma_context_get_device_info(pContext, ma_device_type_playback, &pPlaybackDeviceInfos[iDevice].id, ma_share_mode_shared, &pPlaybackDeviceInfos[iDevice]);
|
||||
if (result == MA_SUCCESS) {
|
||||
printf(" Name: %s\n", pPlaybackDeviceInfos[iDevice].name);
|
||||
printf(" Min Channels: %d\n", pPlaybackDeviceInfos[iDevice].minChannels);
|
||||
@@ -51,8 +51,8 @@ int print_context_info(mal_context* pContext)
|
||||
printf(" Min Sample Rate: %d\n", pPlaybackDeviceInfos[iDevice].minSampleRate);
|
||||
printf(" Max Sample Rate: %d\n", pPlaybackDeviceInfos[iDevice].maxSampleRate);
|
||||
printf(" Format Count: %d\n", pPlaybackDeviceInfos[iDevice].formatCount);
|
||||
for (mal_uint32 iFormat = 0; iFormat < pPlaybackDeviceInfos[iDevice].formatCount; ++iFormat) {
|
||||
printf(" %s\n", mal_get_format_name(pPlaybackDeviceInfos[iDevice].formats[iFormat]));
|
||||
for (ma_uint32 iFormat = 0; iFormat < pPlaybackDeviceInfos[iDevice].formatCount; ++iFormat) {
|
||||
printf(" %s\n", ma_get_format_name(pPlaybackDeviceInfos[iDevice].formats[iFormat]));
|
||||
}
|
||||
} else {
|
||||
printf(" ERROR\n");
|
||||
@@ -60,10 +60,10 @@ int print_context_info(mal_context* pContext)
|
||||
}
|
||||
|
||||
printf(" Capture Devices (%d)\n", captureDeviceCount);
|
||||
for (mal_uint32 iDevice = 0; iDevice < captureDeviceCount; ++iDevice) {
|
||||
for (ma_uint32 iDevice = 0; iDevice < captureDeviceCount; ++iDevice) {
|
||||
printf(" %d: %s\n", iDevice, pCaptureDeviceInfos[iDevice].name);
|
||||
|
||||
result = mal_context_get_device_info(pContext, mal_device_type_capture, &pCaptureDeviceInfos[iDevice].id, mal_share_mode_shared, &pCaptureDeviceInfos[iDevice]);
|
||||
result = ma_context_get_device_info(pContext, ma_device_type_capture, &pCaptureDeviceInfos[iDevice].id, ma_share_mode_shared, &pCaptureDeviceInfos[iDevice]);
|
||||
if (result == MA_SUCCESS) {
|
||||
printf(" Name: %s\n", pCaptureDeviceInfos[iDevice].name);
|
||||
printf(" Min Channels: %d\n", pCaptureDeviceInfos[iDevice].minChannels);
|
||||
@@ -71,8 +71,8 @@ int print_context_info(mal_context* pContext)
|
||||
printf(" Min Sample Rate: %d\n", pCaptureDeviceInfos[iDevice].minSampleRate);
|
||||
printf(" Max Sample Rate: %d\n", pCaptureDeviceInfos[iDevice].maxSampleRate);
|
||||
printf(" Format Count: %d\n", pCaptureDeviceInfos[iDevice].formatCount);
|
||||
for (mal_uint32 iFormat = 0; iFormat < pCaptureDeviceInfos[iDevice].formatCount; ++iFormat) {
|
||||
printf(" %s\n", mal_get_format_name(pCaptureDeviceInfos[iDevice].formats[iFormat]));
|
||||
for (ma_uint32 iFormat = 0; iFormat < pCaptureDeviceInfos[iDevice].formatCount; ++iFormat) {
|
||||
printf(" %s\n", ma_get_format_name(pCaptureDeviceInfos[iDevice].formats[iFormat]));
|
||||
}
|
||||
} else {
|
||||
printf(" ERROR\n");
|
||||
@@ -85,10 +85,10 @@ done:
|
||||
return (result == MA_SUCCESS) ? 0 : -1;
|
||||
}
|
||||
|
||||
int print_device_info(mal_device* pDevice)
|
||||
int print_device_info(ma_device* pDevice)
|
||||
{
|
||||
printf("DEVICE NAME: %s\n", pDevice->name);
|
||||
printf(" Format: %s -> %s\n", mal_get_format_name(pDevice->format), mal_get_format_name(pDevice->internalFormat));
|
||||
printf(" Format: %s -> %s\n", ma_get_format_name(pDevice->format), ma_get_format_name(pDevice->internalFormat));
|
||||
printf(" Channels: %d -> %d\n", pDevice->channels, pDevice->internalChannels);
|
||||
printf(" Sample Rate: %d -> %d\n", pDevice->sampleRate, pDevice->internalSampleRate);
|
||||
printf(" Buffer Size: %d\n", pDevice->bufferSizeInFrames);
|
||||
@@ -97,17 +97,17 @@ int print_device_info(mal_device* pDevice)
|
||||
return 0;
|
||||
}
|
||||
|
||||
mal_uint32 on_send(mal_device* pDevice, mal_uint32 frameCount, void* pFramesOut)
|
||||
ma_uint32 on_send(ma_device* pDevice, ma_uint32 frameCount, void* pFramesOut)
|
||||
{
|
||||
mal_sine_wave* pSineWave = (mal_sine_wave*)pDevice->pUserData;
|
||||
mal_assert(pSineWave != NULL);
|
||||
ma_sine_wave* pSineWave = (ma_sine_wave*)pDevice->pUserData;
|
||||
ma_assert(pSineWave != NULL);
|
||||
|
||||
float* pFramesOutF32 = (float*)pFramesOut;
|
||||
|
||||
for (mal_uint32 iFrame = 0; iFrame < frameCount; ++iFrame) {
|
||||
for (ma_uint32 iFrame = 0; iFrame < frameCount; ++iFrame) {
|
||||
float sample;
|
||||
mal_sine_wave_read(pSineWave, 1, &sample);
|
||||
for (mal_uint32 iChannel = 0; iChannel < pDevice->channels; ++iChannel) {
|
||||
ma_sine_wave_read(pSineWave, 1, &sample);
|
||||
for (ma_uint32 iChannel = 0; iChannel < pDevice->channels; ++iChannel) {
|
||||
pFramesOutF32[iChannel] = sample;
|
||||
}
|
||||
|
||||
@@ -119,19 +119,19 @@ mal_uint32 on_send(mal_device* pDevice, mal_uint32 frameCount, void* pFramesOut)
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
mal_result result;
|
||||
ma_result result;
|
||||
|
||||
mal_sine_wave sineWave;
|
||||
result = mal_sine_wave_init(0.2, 400, 44100, &sineWave);
|
||||
ma_sine_wave sineWave;
|
||||
result = ma_sine_wave_init(0.2, 400, 44100, &sineWave);
|
||||
if (result != MA_SUCCESS) {
|
||||
printf("Failed to initialize sine wave.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Separate context for this test.
|
||||
mal_context_config contextConfig = mal_context_config_init(NULL); // <-- Don't need a log callback because we're using debug output instead.
|
||||
mal_context context;
|
||||
result = mal_context_init(NULL, 0, &contextConfig, &context);
|
||||
ma_context_config contextConfig = ma_context_config_init(NULL); // <-- Don't need a log callback because we're using debug output instead.
|
||||
ma_context context;
|
||||
result = ma_context_init(NULL, 0, &contextConfig, &context);
|
||||
if (result != MA_SUCCESS) {
|
||||
printf("Failed to initialize context.\n");
|
||||
return -1;
|
||||
@@ -141,13 +141,13 @@ int main(int argc, char** argv)
|
||||
|
||||
|
||||
// Device.
|
||||
mal_device_config deviceConfig = mal_device_config_init_playback(mal_format_f32, 2, 44100, on_send);
|
||||
ma_device_config deviceConfig = ma_device_config_init_playback(ma_format_f32, 2, 44100, on_send);
|
||||
deviceConfig.bufferSizeInFrames = 32768;
|
||||
|
||||
mal_device device;
|
||||
result = mal_device_init(&context, mal_device_type_playback, NULL, &deviceConfig, &sineWave, &device);
|
||||
ma_device device;
|
||||
result = ma_device_init(&context, ma_device_type_playback, NULL, &deviceConfig, &sineWave, &device);
|
||||
if (result != MA_SUCCESS) {
|
||||
mal_context_uninit(&context);
|
||||
ma_context_uninit(&context);
|
||||
printf("Failed to initialize device.\n");
|
||||
return -1;
|
||||
}
|
||||
@@ -156,10 +156,10 @@ int main(int argc, char** argv)
|
||||
|
||||
|
||||
// Start playback.
|
||||
result = mal_device_start(&device);
|
||||
result = ma_device_start(&device);
|
||||
if (result != MA_SUCCESS) {
|
||||
mal_device_uninit(&device);
|
||||
mal_context_uninit(&context);
|
||||
ma_device_uninit(&device);
|
||||
ma_context_uninit(&context);
|
||||
printf("Failed to start device.\n");
|
||||
return -1;
|
||||
}
|
||||
@@ -169,7 +169,7 @@ int main(int argc, char** argv)
|
||||
getchar();
|
||||
|
||||
|
||||
mal_device_uninit(&device);
|
||||
mal_context_uninit(&context);
|
||||
ma_device_uninit(&device);
|
||||
ma_context_uninit(&context);
|
||||
return 0;
|
||||
}
|
||||
|
||||
+43
-43
@@ -5,109 +5,109 @@
|
||||
|
||||
// Two converters are needed here. One for converting f32 samples from the sine wave generator to the input format,
|
||||
// and another for converting the input format to the output format for device output.
|
||||
mal_sine_wave sineWave;
|
||||
mal_format_converter converterIn;
|
||||
mal_format_converter converterOut;
|
||||
ma_sine_wave sineWave;
|
||||
ma_format_converter converterIn;
|
||||
ma_format_converter converterOut;
|
||||
|
||||
mal_uint32 on_convert_samples_in(mal_format_converter* pConverter, mal_uint32 frameCount, void* pFrames, void* pUserData)
|
||||
ma_uint32 on_convert_samples_in(ma_format_converter* pConverter, ma_uint32 frameCount, void* pFrames, void* pUserData)
|
||||
{
|
||||
(void)pUserData;
|
||||
mal_assert(pConverter->config.formatIn == mal_format_f32);
|
||||
ma_assert(pConverter->config.formatIn == ma_format_f32);
|
||||
|
||||
mal_sine_wave* pSineWave = (mal_sine_wave*)pConverter->config.pUserData;
|
||||
mal_assert(pSineWave);
|
||||
ma_sine_wave* pSineWave = (ma_sine_wave*)pConverter->config.pUserData;
|
||||
ma_assert(pSineWave);
|
||||
|
||||
return (mal_uint32)mal_sine_wave_read_f32(pSineWave, frameCount, (float*)pFrames);
|
||||
return (ma_uint32)ma_sine_wave_read_f32(pSineWave, frameCount, (float*)pFrames);
|
||||
}
|
||||
|
||||
mal_uint32 on_convert_samples_out(mal_format_converter* pConverter, mal_uint32 frameCount, void* pFrames, void* pUserData)
|
||||
ma_uint32 on_convert_samples_out(ma_format_converter* pConverter, ma_uint32 frameCount, void* pFrames, void* pUserData)
|
||||
{
|
||||
(void)pUserData;
|
||||
|
||||
mal_format_converter* pConverterIn = (mal_format_converter*)pConverter->config.pUserData;
|
||||
mal_assert(pConverterIn != NULL);
|
||||
ma_format_converter* pConverterIn = (ma_format_converter*)pConverter->config.pUserData;
|
||||
ma_assert(pConverterIn != NULL);
|
||||
|
||||
return (mal_uint32)mal_format_converter_read(pConverterIn, frameCount, pFrames, NULL);
|
||||
return (ma_uint32)ma_format_converter_read(pConverterIn, frameCount, pFrames, NULL);
|
||||
}
|
||||
|
||||
void on_send_to_device__original(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 frameCount)
|
||||
void on_send_to_device__original(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount)
|
||||
{
|
||||
mal_assert(pDevice->playback.format == mal_format_f32);
|
||||
mal_assert(pDevice->playback.channels == 1);
|
||||
ma_assert(pDevice->playback.format == ma_format_f32);
|
||||
ma_assert(pDevice->playback.channels == 1);
|
||||
|
||||
mal_sine_wave_read_f32(&sineWave, frameCount, (float*)pOutput);
|
||||
ma_sine_wave_read_f32(&sineWave, frameCount, (float*)pOutput);
|
||||
|
||||
(void)pDevice;
|
||||
(void)pInput;
|
||||
}
|
||||
|
||||
void on_send_to_device__dithered(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 frameCount)
|
||||
void on_send_to_device__dithered(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount)
|
||||
{
|
||||
mal_assert(pDevice->playback.channels == 1);
|
||||
ma_assert(pDevice->playback.channels == 1);
|
||||
|
||||
mal_format_converter* pConverter = (mal_format_converter*)pDevice->pUserData;
|
||||
mal_assert(pConverter != NULL);
|
||||
mal_assert(pDevice->playback.format == pConverter->config.formatOut);
|
||||
ma_format_converter* pConverter = (ma_format_converter*)pDevice->pUserData;
|
||||
ma_assert(pConverter != NULL);
|
||||
ma_assert(pDevice->playback.format == pConverter->config.formatOut);
|
||||
|
||||
mal_format_converter_read(pConverter, frameCount, pOutput, NULL);
|
||||
ma_format_converter_read(pConverter, frameCount, pOutput, NULL);
|
||||
|
||||
(void)pInput;
|
||||
}
|
||||
|
||||
int do_dithering_test()
|
||||
{
|
||||
mal_device_config config;
|
||||
mal_device device;
|
||||
mal_result result;
|
||||
ma_device_config config;
|
||||
ma_device device;
|
||||
ma_result result;
|
||||
|
||||
config = mal_device_config_init(mal_device_type_playback);
|
||||
config.playback.format = mal_format_f32;
|
||||
config = ma_device_config_init(ma_device_type_playback);
|
||||
config.playback.format = ma_format_f32;
|
||||
config.playback.channels = 1;
|
||||
config.sampleRate = 0;
|
||||
config.dataCallback = on_send_to_device__original;
|
||||
|
||||
// We first play the sound the way it's meant to be played.
|
||||
result = mal_device_init(NULL, &config, &device);
|
||||
result = ma_device_init(NULL, &config, &device);
|
||||
if (result != MA_SUCCESS) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
mal_sine_wave_init(0.5, 400, device.sampleRate, &sineWave);
|
||||
ma_sine_wave_init(0.5, 400, device.sampleRate, &sineWave);
|
||||
|
||||
result = mal_device_start(&device);
|
||||
result = ma_device_start(&device);
|
||||
if (result != MA_SUCCESS) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
printf("Press Enter to play enable dithering.\n");
|
||||
getchar();
|
||||
mal_device_uninit(&device);
|
||||
ma_device_uninit(&device);
|
||||
|
||||
|
||||
mal_format srcFormat = mal_format_s24;
|
||||
mal_format dstFormat = mal_format_u8;
|
||||
mal_dither_mode ditherMode = mal_dither_mode_triangle;
|
||||
ma_format srcFormat = ma_format_s24;
|
||||
ma_format dstFormat = ma_format_u8;
|
||||
ma_dither_mode ditherMode = ma_dither_mode_triangle;
|
||||
|
||||
mal_format_converter_config converterInConfig = mal_format_converter_config_init_new();
|
||||
converterInConfig.formatIn = mal_format_f32; // <-- From the sine wave generator.
|
||||
ma_format_converter_config converterInConfig = ma_format_converter_config_init_new();
|
||||
converterInConfig.formatIn = ma_format_f32; // <-- From the sine wave generator.
|
||||
converterInConfig.formatOut = srcFormat;
|
||||
converterInConfig.channels = config.playback.channels;
|
||||
converterInConfig.ditherMode = mal_dither_mode_none;
|
||||
converterInConfig.ditherMode = ma_dither_mode_none;
|
||||
converterInConfig.onRead = on_convert_samples_in;
|
||||
converterInConfig.pUserData = &sineWave;
|
||||
result = mal_format_converter_init(&converterInConfig, &converterIn);
|
||||
result = ma_format_converter_init(&converterInConfig, &converterIn);
|
||||
if (result != MA_SUCCESS) {
|
||||
return -3;
|
||||
}
|
||||
|
||||
mal_format_converter_config converterOutConfig = mal_format_converter_config_init_new();
|
||||
ma_format_converter_config converterOutConfig = ma_format_converter_config_init_new();
|
||||
converterOutConfig.formatIn = srcFormat;
|
||||
converterOutConfig.formatOut = dstFormat;
|
||||
converterOutConfig.channels = config.playback.channels;
|
||||
converterOutConfig.ditherMode = ditherMode;
|
||||
converterOutConfig.onRead = on_convert_samples_out;
|
||||
converterOutConfig.pUserData = &converterIn;
|
||||
result = mal_format_converter_init(&converterOutConfig, &converterOut);
|
||||
result = ma_format_converter_init(&converterOutConfig, &converterOut);
|
||||
if (result != MA_SUCCESS) {
|
||||
return -3;
|
||||
}
|
||||
@@ -116,15 +116,15 @@ int do_dithering_test()
|
||||
config.dataCallback = on_send_to_device__dithered;
|
||||
config.pUserData = &converterOut;
|
||||
|
||||
result = mal_device_init(NULL, &config, &device);
|
||||
result = ma_device_init(NULL, &config, &device);
|
||||
if (result != MA_SUCCESS) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Now we play the sound after it's run through a dithered format converter.
|
||||
mal_sine_wave_init(0.5, 400, device.sampleRate, &sineWave);
|
||||
ma_sine_wave_init(0.5, 400, device.sampleRate, &sineWave);
|
||||
|
||||
result = mal_device_start(&device);
|
||||
result = ma_device_start(&device);
|
||||
if (result != MA_SUCCESS) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
+18
-18
@@ -13,7 +13,7 @@ void main_loop__em()
|
||||
}
|
||||
#endif
|
||||
|
||||
void log_callback(mal_context* pContext, mal_device* pDevice, mal_uint32 logLevel, const char* message)
|
||||
void log_callback(ma_context* pContext, ma_device* pDevice, ma_uint32 logLevel, const char* message)
|
||||
{
|
||||
(void)pContext;
|
||||
(void)pDevice;
|
||||
@@ -21,21 +21,21 @@ void log_callback(mal_context* pContext, mal_device* pDevice, mal_uint32 logLeve
|
||||
printf("%s\n", message);
|
||||
}
|
||||
|
||||
void stop_callback(mal_device* pDevice)
|
||||
void stop_callback(ma_device* pDevice)
|
||||
{
|
||||
(void)pDevice;
|
||||
printf("STOPPED\n");
|
||||
}
|
||||
|
||||
void data_callback(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 frameCount)
|
||||
void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount)
|
||||
{
|
||||
/* In this test the format and channel count are the same for both input and output which means we can just memcpy(). */
|
||||
mal_copy_memory(pOutput, pInput, frameCount * mal_get_bytes_per_frame(pDevice->capture.format, pDevice->capture.channels));
|
||||
ma_copy_memory(pOutput, pInput, frameCount * ma_get_bytes_per_frame(pDevice->capture.format, pDevice->capture.channels));
|
||||
|
||||
#if 1
|
||||
/* Also write to a wav file for debugging. */
|
||||
drwav* pWav = (drwav*)pDevice->pUserData;
|
||||
mal_assert(pWav != NULL);
|
||||
ma_assert(pWav != NULL);
|
||||
|
||||
drwav_write_pcm_frames(pWav, frameCount, pInput);
|
||||
#endif
|
||||
@@ -43,7 +43,7 @@ void data_callback(mal_device* pDevice, void* pOutput, const void* pInput, mal_u
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
mal_result result;
|
||||
ma_result result;
|
||||
|
||||
#if 1
|
||||
drwav_data_format wavFormat;
|
||||
@@ -61,26 +61,26 @@ int main(int argc, char** argv)
|
||||
#endif
|
||||
|
||||
|
||||
mal_backend backend = mal_backend_wasapi;
|
||||
ma_backend backend = ma_backend_wasapi;
|
||||
|
||||
mal_context_config contextConfig = mal_context_config_init();
|
||||
ma_context_config contextConfig = ma_context_config_init();
|
||||
contextConfig.logCallback = log_callback;
|
||||
|
||||
mal_context context;
|
||||
result = mal_context_init(&backend, 1, &contextConfig, &context);
|
||||
ma_context context;
|
||||
result = ma_context_init(&backend, 1, &contextConfig, &context);
|
||||
if (result != MA_SUCCESS) {
|
||||
printf("Failed to initialize context.\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
mal_device_config deviceConfig = mal_device_config_init(mal_device_type_duplex);
|
||||
ma_device_config deviceConfig = ma_device_config_init(ma_device_type_duplex);
|
||||
deviceConfig.capture.pDeviceID = NULL;
|
||||
deviceConfig.capture.format = mal_format_s16;
|
||||
deviceConfig.capture.format = ma_format_s16;
|
||||
deviceConfig.capture.channels = 2;
|
||||
deviceConfig.playback.pDeviceID = NULL;
|
||||
deviceConfig.playback.format = mal_format_s16;
|
||||
deviceConfig.playback.format = ma_format_s16;
|
||||
deviceConfig.playback.channels = 2;
|
||||
deviceConfig.playback.shareMode = mal_share_mode_shared;
|
||||
deviceConfig.playback.shareMode = ma_share_mode_shared;
|
||||
deviceConfig.sampleRate = 44100;
|
||||
//deviceConfig.bufferSizeInMilliseconds = 60;
|
||||
deviceConfig.bufferSizeInFrames = 4096;
|
||||
@@ -89,8 +89,8 @@ int main(int argc, char** argv)
|
||||
deviceConfig.stopCallback = stop_callback;
|
||||
deviceConfig.pUserData = &wav;
|
||||
|
||||
mal_device device;
|
||||
result = mal_device_init(&context, &deviceConfig, &device);
|
||||
ma_device device;
|
||||
result = ma_device_init(&context, &deviceConfig, &device);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
@@ -99,7 +99,7 @@ int main(int argc, char** argv)
|
||||
getchar();
|
||||
#endif
|
||||
|
||||
mal_device_start(&device);
|
||||
ma_device_start(&device);
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(main_loop__em, 0, 1);
|
||||
@@ -108,7 +108,7 @@ int main(int argc, char** argv)
|
||||
getchar();
|
||||
#endif
|
||||
|
||||
mal_device_uninit(&device);
|
||||
ma_device_uninit(&device);
|
||||
drwav_uninit(&wav);
|
||||
|
||||
(void)argc;
|
||||
|
||||
@@ -13,15 +13,15 @@ int main(int argc, char** argv)
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
mal_result result = MA_ERROR;
|
||||
ma_result result = MA_ERROR;
|
||||
|
||||
mal_pcm_converter_config dspConfig = mal_pcm_converter_config_init_new();
|
||||
mal_pcm_converter converter;
|
||||
result = mal_pcm_converter_init(&dspConfig, &converter);
|
||||
ma_pcm_converter_config dspConfig = ma_pcm_converter_config_init_new();
|
||||
ma_pcm_converter converter;
|
||||
result = ma_pcm_converter_init(&dspConfig, &converter);
|
||||
|
||||
mal_decoder_config decoderConfig = mal_decoder_config_init(mal_format_unknown, 0, 0);
|
||||
mal_decoder decoder;
|
||||
result = mal_decoder_init_file("res/sine_s16_mono_48000.wav", &decoderConfig, &decoder);
|
||||
ma_decoder_config decoderConfig = ma_decoder_config_init(ma_format_unknown, 0, 0);
|
||||
ma_decoder decoder;
|
||||
result = ma_decoder_init_file("res/sine_s16_mono_48000.wav", &decoderConfig, &decoder);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
+322
-322
File diff suppressed because it is too large
Load Diff
+45
-45
@@ -13,8 +13,8 @@
|
||||
#endif
|
||||
|
||||
// There is a usage pattern for resampling that miniaudio does not properly support which is where the client continuously
|
||||
// reads samples until mal_src_read() returns 0. The problem with this pattern is that is consumes the samples sitting
|
||||
// in the window which are needed to compute the next samples in future calls to mal_src_read() (assuming the client
|
||||
// reads samples until ma_src_read() returns 0. The problem with this pattern is that is consumes the samples sitting
|
||||
// in the window which are needed to compute the next samples in future calls to ma_src_read() (assuming the client
|
||||
// has re-filled the resampler's input data).
|
||||
|
||||
/*
|
||||
@@ -22,72 +22,72 @@ for (;;) {
|
||||
fill_src_input_data(&src, someData);
|
||||
|
||||
float buffer[4096]
|
||||
while ((framesRead = mal_src_read(&src, ...) != 0) {
|
||||
while ((framesRead = ma_src_read(&src, ...) != 0) {
|
||||
do_something_with_resampled_data(buffer);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// In the use case above, the very last samples that are read from mal_src_read() will not have future samples to draw
|
||||
// In the use case above, the very last samples that are read from ma_src_read() will not have future samples to draw
|
||||
// from in order to calculate the correct interpolation factor which in turn results in crackling.
|
||||
|
||||
mal_uint32 sampleRateIn = 0;
|
||||
mal_uint32 sampleRateOut = 0;
|
||||
mal_sine_wave sineWave; // <-- This is the source data.
|
||||
mal_src src;
|
||||
ma_uint32 sampleRateIn = 0;
|
||||
ma_uint32 sampleRateOut = 0;
|
||||
ma_sine_wave sineWave; // <-- This is the source data.
|
||||
ma_src src;
|
||||
float srcInput[1024];
|
||||
mal_uint32 srcNextSampleIndex = mal_countof(srcInput);
|
||||
ma_uint32 srcNextSampleIndex = ma_countof(srcInput);
|
||||
|
||||
void reload_src_input()
|
||||
{
|
||||
mal_sine_wave_read_f32(&sineWave, mal_countof(srcInput), srcInput);
|
||||
ma_sine_wave_read_f32(&sineWave, ma_countof(srcInput), srcInput);
|
||||
srcNextSampleIndex = 0;
|
||||
}
|
||||
|
||||
mal_uint32 on_src(mal_src* pSRC, mal_uint32 frameCount, void** ppSamplesOut, void* pUserData)
|
||||
ma_uint32 on_src(ma_src* pSRC, ma_uint32 frameCount, void** ppSamplesOut, void* pUserData)
|
||||
{
|
||||
mal_assert(pSRC != NULL);
|
||||
mal_assert(pSRC->config.channels == 1);
|
||||
ma_assert(pSRC != NULL);
|
||||
ma_assert(pSRC->config.channels == 1);
|
||||
|
||||
(void)pUserData;
|
||||
|
||||
// Only read as much as is available in the input buffer. Do not reload the buffer here.
|
||||
mal_uint32 framesAvailable = mal_countof(srcInput) - srcNextSampleIndex;
|
||||
mal_uint32 framesToRead = frameCount;
|
||||
ma_uint32 framesAvailable = ma_countof(srcInput) - srcNextSampleIndex;
|
||||
ma_uint32 framesToRead = frameCount;
|
||||
if (framesToRead > framesAvailable) {
|
||||
framesToRead = framesAvailable;
|
||||
}
|
||||
|
||||
mal_copy_memory(ppSamplesOut[0], srcInput + srcNextSampleIndex, sizeof(float)*framesToRead);
|
||||
ma_copy_memory(ppSamplesOut[0], srcInput + srcNextSampleIndex, sizeof(float)*framesToRead);
|
||||
srcNextSampleIndex += framesToRead;
|
||||
|
||||
return framesToRead;
|
||||
}
|
||||
|
||||
void on_send_to_device(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 frameCount)
|
||||
void on_send_to_device(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount)
|
||||
{
|
||||
(void)pDevice;
|
||||
(void)pInput;
|
||||
|
||||
mal_assert(pDevice->playback.format == mal_format_f32);
|
||||
mal_assert(pDevice->playback.channels == 1);
|
||||
ma_assert(pDevice->playback.format == ma_format_f32);
|
||||
ma_assert(pDevice->playback.channels == 1);
|
||||
|
||||
float* pFramesF32 = (float*)pOutput;
|
||||
|
||||
// To reproduce the case we are needing to test, we need to read from the SRC in a very specific way. We keep looping
|
||||
// until we've read the requested frame count, however we have an inner loop that keeps running until mal_src_read()
|
||||
// until we've read the requested frame count, however we have an inner loop that keeps running until ma_src_read()
|
||||
// returns 0, in which case we need to reload the SRC's input data and keep going.
|
||||
mal_uint32 totalFramesRead = 0;
|
||||
ma_uint32 totalFramesRead = 0;
|
||||
while (totalFramesRead < frameCount) {
|
||||
mal_uint32 framesRemaining = frameCount - totalFramesRead;
|
||||
ma_uint32 framesRemaining = frameCount - totalFramesRead;
|
||||
|
||||
mal_uint32 maxFramesToRead = 128;
|
||||
mal_uint32 framesToRead = framesRemaining;
|
||||
ma_uint32 maxFramesToRead = 128;
|
||||
ma_uint32 framesToRead = framesRemaining;
|
||||
if (framesToRead > maxFramesToRead) {
|
||||
framesToRead = maxFramesToRead;
|
||||
}
|
||||
|
||||
mal_uint32 framesRead = (mal_uint32)mal_src_read_deinterleaved(&src, framesToRead, (void**)&pFramesF32, NULL);
|
||||
ma_uint32 framesRead = (ma_uint32)ma_src_read_deinterleaved(&src, framesToRead, (void**)&pFramesF32, NULL);
|
||||
if (framesRead == 0) {
|
||||
reload_src_input();
|
||||
}
|
||||
@@ -96,7 +96,7 @@ void on_send_to_device(mal_device* pDevice, void* pOutput, const void* pInput, m
|
||||
pFramesF32 += framesRead;
|
||||
}
|
||||
|
||||
mal_assert(totalFramesRead == frameCount);
|
||||
ma_assert(totalFramesRead == frameCount);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
@@ -105,18 +105,18 @@ int main(int argc, char** argv)
|
||||
(void)argv;
|
||||
|
||||
|
||||
mal_device_config config = mal_device_config_init(mal_device_type_playback);
|
||||
config.playback.format = mal_format_f32;
|
||||
ma_device_config config = ma_device_config_init(ma_device_type_playback);
|
||||
config.playback.format = ma_format_f32;
|
||||
config.playback.channels = 1;
|
||||
config.dataCallback = on_send_to_device;
|
||||
|
||||
mal_device device;
|
||||
mal_result result;
|
||||
ma_device device;
|
||||
ma_result result;
|
||||
|
||||
config.bufferSizeInFrames = 8192*1;
|
||||
|
||||
// We first play the sound the way it's meant to be played.
|
||||
result = mal_device_init(NULL, &config, &device);
|
||||
result = ma_device_init(NULL, &config, &device);
|
||||
if (result != MA_SUCCESS) {
|
||||
return -1;
|
||||
}
|
||||
@@ -125,13 +125,13 @@ int main(int argc, char** argv)
|
||||
// For this test, we need the sine wave to be a different format to the device.
|
||||
sampleRateOut = device.sampleRate;
|
||||
sampleRateIn = (sampleRateOut == 44100) ? 48000 : 44100;
|
||||
mal_sine_wave_init(0.2, 400, sampleRateIn, &sineWave);
|
||||
ma_sine_wave_init(0.2, 400, sampleRateIn, &sineWave);
|
||||
|
||||
mal_src_config srcConfig = mal_src_config_init(sampleRateIn, sampleRateOut, 1, on_src, NULL);
|
||||
srcConfig.algorithm = mal_src_algorithm_sinc;
|
||||
ma_src_config srcConfig = ma_src_config_init(sampleRateIn, sampleRateOut, 1, on_src, NULL);
|
||||
srcConfig.algorithm = ma_src_algorithm_sinc;
|
||||
srcConfig.neverConsumeEndOfInput = MA_TRUE;
|
||||
|
||||
result = mal_src_init(&srcConfig, &src);
|
||||
result = ma_src_init(&srcConfig, &src);
|
||||
if (result != MA_SUCCESS) {
|
||||
printf("Failed to create SRC.\n");
|
||||
return -1;
|
||||
@@ -158,7 +158,7 @@ int main(int argc, char** argv)
|
||||
|
||||
|
||||
msigvis_channel channelSineWave;
|
||||
result = msigvis_channel_init(&sigvis, mal_format_f32, sampleRateOut, &channelSineWave);
|
||||
result = msigvis_channel_init(&sigvis, ma_format_f32, sampleRateOut, &channelSineWave);
|
||||
if (result != MA_SUCCESS) {
|
||||
printf("Failed to initialize mini_sigvis channel.\n");
|
||||
return -3;
|
||||
@@ -168,17 +168,17 @@ int main(int argc, char** argv)
|
||||
float* pFramesF32 = testSamples;
|
||||
|
||||
// To reproduce the case we are needing to test, we need to read from the SRC in a very specific way. We keep looping
|
||||
// until we've read the requested frame count, however we have an inner loop that keeps running until mal_src_read()
|
||||
// until we've read the requested frame count, however we have an inner loop that keeps running until ma_src_read()
|
||||
// returns 0, in which case we need to reload the SRC's input data and keep going.
|
||||
mal_uint32 totalFramesRead = 0;
|
||||
while (totalFramesRead < mal_countof(testSamples)) {
|
||||
mal_uint32 maxFramesToRead = 128;
|
||||
mal_uint32 framesToRead = mal_countof(testSamples);
|
||||
ma_uint32 totalFramesRead = 0;
|
||||
while (totalFramesRead < ma_countof(testSamples)) {
|
||||
ma_uint32 maxFramesToRead = 128;
|
||||
ma_uint32 framesToRead = ma_countof(testSamples);
|
||||
if (framesToRead > maxFramesToRead) {
|
||||
framesToRead = maxFramesToRead;
|
||||
}
|
||||
|
||||
mal_uint32 framesRead = (mal_uint32)mal_src_read_deinterleaved(&src, framesToRead, (void**)&pFramesF32, NULL);
|
||||
ma_uint32 framesRead = (ma_uint32)ma_src_read_deinterleaved(&src, framesToRead, (void**)&pFramesF32, NULL);
|
||||
if (framesRead == 0) {
|
||||
reload_src_input();
|
||||
}
|
||||
@@ -187,7 +187,7 @@ int main(int argc, char** argv)
|
||||
pFramesF32 += framesRead;
|
||||
}
|
||||
|
||||
msigvis_channel_push_samples(&channelSineWave, mal_countof(testSamples), testSamples);
|
||||
msigvis_channel_push_samples(&channelSineWave, ma_countof(testSamples), testSamples);
|
||||
msigvis_screen_add_channel(&screen, &channelSineWave);
|
||||
|
||||
|
||||
@@ -197,14 +197,14 @@ int main(int argc, char** argv)
|
||||
msigvis_uninit(&sigvis);
|
||||
#else
|
||||
|
||||
result = mal_device_start(&device);
|
||||
result = ma_device_start(&device);
|
||||
if (result != MA_SUCCESS) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
printf("Press Enter to quit...\n");
|
||||
getchar();
|
||||
mal_device_uninit(&device);
|
||||
ma_device_uninit(&device);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
||||
+25
-25
@@ -3,38 +3,38 @@
|
||||
#define MINIAUDIO_IMPLEMENTATION
|
||||
#include "../miniaudio.h"
|
||||
|
||||
mal_sine_wave sineWave;
|
||||
mal_uint32 framesWritten;
|
||||
mal_event stopEvent;
|
||||
mal_bool32 isInitialRun = MA_TRUE;
|
||||
ma_sine_wave sineWave;
|
||||
ma_uint32 framesWritten;
|
||||
ma_event stopEvent;
|
||||
ma_bool32 isInitialRun = MA_TRUE;
|
||||
|
||||
void on_stop(mal_device* pDevice)
|
||||
void on_stop(ma_device* pDevice)
|
||||
{
|
||||
(void)pDevice;
|
||||
printf("STOPPED\n");
|
||||
}
|
||||
|
||||
void on_data(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 frameCount)
|
||||
void on_data(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount)
|
||||
{
|
||||
(void)pInput; /* Not used yet. */
|
||||
|
||||
/* Output exactly one second of data. Pad the end with silence. */
|
||||
mal_uint32 framesRemaining = pDevice->sampleRate - framesWritten;
|
||||
mal_uint32 framesToProcess = frameCount;
|
||||
ma_uint32 framesRemaining = pDevice->sampleRate - framesWritten;
|
||||
ma_uint32 framesToProcess = frameCount;
|
||||
if (framesToProcess > framesRemaining && isInitialRun) {
|
||||
framesToProcess = framesRemaining;
|
||||
}
|
||||
|
||||
mal_sine_wave_read_f32_ex(&sineWave, framesToProcess, pDevice->playback.channels, mal_stream_layout_interleaved, (float**)&pOutput);
|
||||
ma_sine_wave_read_f32_ex(&sineWave, framesToProcess, pDevice->playback.channels, ma_stream_layout_interleaved, (float**)&pOutput);
|
||||
if (isInitialRun) {
|
||||
framesWritten += framesToProcess;
|
||||
}
|
||||
|
||||
mal_assert(framesWritten <= pDevice->sampleRate);
|
||||
ma_assert(framesWritten <= pDevice->sampleRate);
|
||||
if (framesWritten >= pDevice->sampleRate) {
|
||||
if (isInitialRun) {
|
||||
printf("STOPPING [AUDIO THREAD]...\n");
|
||||
mal_event_signal(&stopEvent);
|
||||
ma_event_signal(&stopEvent);
|
||||
isInitialRun = MA_FALSE;
|
||||
}
|
||||
}
|
||||
@@ -42,57 +42,57 @@ void on_data(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
mal_result result;
|
||||
ma_result result;
|
||||
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
mal_backend backend = mal_backend_wasapi;
|
||||
ma_backend backend = ma_backend_wasapi;
|
||||
|
||||
mal_sine_wave_init(0.25, 400, 44100, &sineWave);
|
||||
ma_sine_wave_init(0.25, 400, 44100, &sineWave);
|
||||
|
||||
mal_device_config config = mal_device_config_init(mal_device_type_playback);
|
||||
config.playback.format = mal_format_f32;
|
||||
ma_device_config config = ma_device_config_init(ma_device_type_playback);
|
||||
config.playback.format = ma_format_f32;
|
||||
config.playback.channels = 2;
|
||||
config.sampleRate = 44100;
|
||||
config.dataCallback = on_data;
|
||||
config.stopCallback = on_stop;
|
||||
config.bufferSizeInFrames = 16384;
|
||||
|
||||
mal_device device;
|
||||
result = mal_device_init_ex(&backend, 1, NULL, &config, &device);
|
||||
ma_device device;
|
||||
result = ma_device_init_ex(&backend, 1, NULL, &config, &device);
|
||||
if (result != MA_SUCCESS) {
|
||||
printf("Failed to initialize device.\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
result = mal_event_init(device.pContext, &stopEvent);
|
||||
result = ma_event_init(device.pContext, &stopEvent);
|
||||
if (result != MA_SUCCESS) {
|
||||
printf("Failed to initialize stop event.\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
mal_device_start(&device);
|
||||
ma_device_start(&device);
|
||||
|
||||
/* We wait for the stop event, stop the device, then ask the user to press any key to restart. This checks that the device can restart after stopping. */
|
||||
mal_event_wait(&stopEvent);
|
||||
ma_event_wait(&stopEvent);
|
||||
|
||||
printf("STOPPING [MAIN THREAD]...\n");
|
||||
mal_device_stop(&device);
|
||||
ma_device_stop(&device);
|
||||
|
||||
printf("Press Enter to restart...\n");
|
||||
getchar();
|
||||
|
||||
result = mal_device_start(&device);
|
||||
result = ma_device_start(&device);
|
||||
if (result != MA_SUCCESS) {
|
||||
printf("Failed to restart the device.\n");
|
||||
mal_device_uninit(&device);
|
||||
ma_device_uninit(&device);
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Press Enter to quit...\n");
|
||||
getchar();
|
||||
|
||||
mal_device_uninit(&device);
|
||||
ma_device_uninit(&device);
|
||||
return 0;
|
||||
}
|
||||
+502
-502
File diff suppressed because it is too large
Load Diff
@@ -1 +1 @@
|
||||
#include "mal_test_0.c"
|
||||
#include "ma_test_0.c"
|
||||
+12
-12
@@ -29,7 +29,7 @@
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{3430EEA2-AC6E-4DC7-B684-1F698D01FAE8}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>mal_test_0</RootNamespace>
|
||||
<RootNamespace>ma_test_0</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
@@ -262,7 +262,7 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<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)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
|
||||
@@ -302,7 +302,7 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</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)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
|
||||
@@ -310,7 +310,7 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="mal_dithering.c">
|
||||
<ClCompile Include="ma_dithering.c">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
|
||||
@@ -318,7 +318,7 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="mal_duplex.c">
|
||||
<ClCompile Include="ma_duplex.c">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
|
||||
@@ -326,7 +326,7 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</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)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
|
||||
@@ -334,7 +334,7 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="mal_profiling.c">
|
||||
<ClCompile Include="ma_profiling.c">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
|
||||
@@ -342,7 +342,7 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="mal_resampling.c">
|
||||
<ClCompile Include="ma_resampling.c">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
|
||||
@@ -350,7 +350,7 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="mal_stop.c">
|
||||
<ClCompile Include="ma_stop.c">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
|
||||
@@ -358,7 +358,7 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</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|ARM'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
@@ -366,7 +366,7 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</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|ARM'">false</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild>
|
||||
@@ -377,7 +377,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\miniaudio.h" />
|
||||
<ClInclude Include="..\research\mal_resampler.h" />
|
||||
<ClInclude Include="..\research\ma_resampler.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
|
||||
@@ -15,40 +15,40 @@
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="mal_test_0.c">
|
||||
<ClCompile Include="ma_test_0.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="mal_test_0.cpp">
|
||||
<ClCompile Include="ma_test_0.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="mal_profiling.c">
|
||||
<ClCompile Include="ma_profiling.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="mal_dithering.c">
|
||||
<ClCompile Include="ma_dithering.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="mal_resampling.c">
|
||||
<ClCompile Include="ma_resampling.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="mal_no_device_io.c">
|
||||
<ClCompile Include="ma_no_device_io.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\research\tests\mal_resampler_test_0.c">
|
||||
<ClCompile Include="..\research\tests\ma_resampler_test_0.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\examples\simple_playback.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\debugging\source\mal_router_1.c">
|
||||
<ClCompile Include="..\debugging\source\ma_router_1.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\examples\simple_enumeration.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="mal_duplex.c">
|
||||
<ClCompile Include="ma_duplex.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="mal_stop.c">
|
||||
<ClCompile Include="ma_stop.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\examples\simple_capture.c">
|
||||
@@ -62,7 +62,7 @@
|
||||
<ClInclude Include="..\miniaudio.h">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\research\mal_resampler.h">
|
||||
<ClInclude Include="..\research\ma_resampler.h">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
<script>
|
||||
var runningTime = 0.0;
|
||||
|
||||
function mal_enum_devices(deviceType) {
|
||||
function ma_enum_devices(deviceType) {
|
||||
if (deviceType !== 'audiooutput' && deviceType !== 'audioinput') {
|
||||
alert("Invalid device type: " + deviceType);
|
||||
return null;
|
||||
@@ -71,7 +71,7 @@
|
||||
return promise;
|
||||
}
|
||||
|
||||
function mal_device_new(deviceType, deviceID) {
|
||||
function ma_device_new(deviceType, deviceID) {
|
||||
if (typeof(mal) === 'undefined') {
|
||||
return null; // Context not initialized.
|
||||
}
|
||||
@@ -202,11 +202,11 @@
|
||||
return device;
|
||||
}
|
||||
|
||||
function mal_device_delete(device) {
|
||||
function ma_device_delete(device) {
|
||||
Module._free(device.intermediaryBuffer);
|
||||
}
|
||||
|
||||
function mal_context_init() {
|
||||
function ma_context_init() {
|
||||
if ((window.AudioContext || window.webkitAudioContext) === undefined) {
|
||||
return 0; // Web Audio not supported.
|
||||
}
|
||||
@@ -235,7 +235,7 @@
|
||||
};
|
||||
|
||||
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;
|
||||
|
||||
// Trim the array if possible.
|
||||
@@ -265,14 +265,14 @@
|
||||
}
|
||||
|
||||
window.onload = function() {
|
||||
if (mal_context_init() != 1) {
|
||||
if (ma_context_init() != 1) {
|
||||
alert("Failed to initialize context.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Unfortunately this doesn't seem to work too well. See comment in mal_enum_devices().
|
||||
mal_enum_devices('audiooutput').then(function(outputDevices) {
|
||||
// Unfortunately this doesn't seem to work too well. See comment in ma_enum_devices().
|
||||
ma_enum_devices('audiooutput').then(function(outputDevices) {
|
||||
for (var iDevice = 0; iDevice < outputDevices.length; ++iDevice) {
|
||||
console.log("Output Device: ", JSON.stringify(outputDevices[iDevice]));
|
||||
}
|
||||
@@ -280,7 +280,7 @@
|
||||
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) {
|
||||
console.log("Input Device: ", JSON.stringify(inputDevices[iDevice]));
|
||||
}
|
||||
@@ -289,8 +289,8 @@
|
||||
});
|
||||
|
||||
|
||||
var outputDevice = mal_device_new('audiooutput', null);
|
||||
var inputDevice = mal_device_new('audioinput', null);
|
||||
var outputDevice = ma_device_new('audiooutput', null);
|
||||
var inputDevice = ma_device_new('audioinput', null);
|
||||
|
||||
var btnStartPlayback = document.getElementById("btnStartPlayback");
|
||||
btnStartPlayback.addEventListener('click', function() {
|
||||
|
||||
@@ -36,37 +36,37 @@ struct msigvis_screen
|
||||
|
||||
struct msigvis_channel
|
||||
{
|
||||
mal_format format;
|
||||
mal_uint32 sampleRate;
|
||||
ma_format format;
|
||||
ma_uint32 sampleRate;
|
||||
dtk_color color;
|
||||
mal_uint32 sampleCount;
|
||||
mal_uint32 bufferCapInSamples;
|
||||
mal_uint8* pBuffer; // The buffer containing the sample to visualize.
|
||||
ma_uint32 sampleCount;
|
||||
ma_uint32 bufferCapInSamples;
|
||||
ma_uint8* pBuffer; // The buffer containing the sample to visualize.
|
||||
};
|
||||
|
||||
|
||||
// Context
|
||||
mal_result msigvis_init(msigvis_context* pContext);
|
||||
ma_result msigvis_init(msigvis_context* pContext);
|
||||
void msigvis_uninit(msigvis_context* pContext);
|
||||
int msigvis_run(msigvis_context* pContext);
|
||||
|
||||
// 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);
|
||||
mal_result msigvis_screen_show(msigvis_screen* pScreen);
|
||||
mal_result msigvis_screen_hide(msigvis_screen* pScreen);
|
||||
mal_result msigvis_screen_add_channel(msigvis_screen* pScreen, msigvis_channel* pChannel);
|
||||
mal_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);
|
||||
mal_result msigvis_screen_find_channel_index(msigvis_screen* pScreen, msigvis_channel* pChannel, mal_uint32* pIndex);
|
||||
mal_result msigvis_screen_redraw(msigvis_screen* pScreen);
|
||||
ma_result msigvis_screen_show(msigvis_screen* pScreen);
|
||||
ma_result msigvis_screen_hide(msigvis_screen* pScreen);
|
||||
ma_result msigvis_screen_add_channel(msigvis_screen* pScreen, msigvis_channel* pChannel);
|
||||
ma_result msigvis_screen_remove_channel(msigvis_screen* pScreen, msigvis_channel* pChannel);
|
||||
ma_result msigvis_screen_remove_channel_by_index(msigvis_screen* pScreen, ma_uint32 iChannel);
|
||||
ma_result msigvis_screen_find_channel_index(msigvis_screen* pScreen, msigvis_channel* pChannel, ma_uint32* pIndex);
|
||||
ma_result msigvis_screen_redraw(msigvis_screen* pScreen);
|
||||
|
||||
// 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);
|
||||
mal_result msigvis_channel_push_samples(msigvis_channel* pChannel, mal_uint32 sampleCount, const void* pSamples);
|
||||
mal_result msigvis_channel_pop_samples(msigvis_channel* pChannel, mal_uint32 sampleCount);
|
||||
float msigvis_channel_get_sample_f32(msigvis_channel* pChannel, mal_uint32 iSample);
|
||||
ma_result msigvis_channel_push_samples(msigvis_channel* pChannel, ma_uint32 sampleCount, const void* pSamples);
|
||||
ma_result msigvis_channel_pop_samples(msigvis_channel* pChannel, ma_uint32 sampleCount);
|
||||
float msigvis_channel_get_sample_f32(msigvis_channel* pChannel, ma_uint32 iSample);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
@@ -86,19 +86,19 @@ float msigvis_channel_get_sample_f32(msigvis_channel* pChannel, mal_uint32 iSamp
|
||||
#include "../../miniaudio.h"
|
||||
#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) {
|
||||
return MA_INVALID_ARGS;
|
||||
}
|
||||
|
||||
mal_zero_object(pContext);
|
||||
ma_zero_object(pContext);
|
||||
|
||||
// DTK context.
|
||||
dtk_result resultDTK = dtk_init(&pContext->tk, NULL, pContext);
|
||||
@@ -188,23 +188,23 @@ dtk_bool32 msigvis_window_event_handler(dtk_event* pEvent)
|
||||
float baseSampleSpacingX = (screenSizeX / (float)(pScreen->sampleRate/10)) * pScreen->zoomX;
|
||||
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];
|
||||
float spacingFactorX = pScreen->sampleRate / (float)pChannel->sampleRate;
|
||||
float sampleSpacingX = baseSampleSpacingX * spacingFactorX;
|
||||
float sampleSpacingY = baseSampleSpacingY;
|
||||
|
||||
mal_uint32 sampleInterval = 1;
|
||||
ma_uint32 sampleInterval = 1;
|
||||
if (sampleSpacingX < 1) {
|
||||
sampleInterval = (mal_uint32)(1/sampleSpacingX);
|
||||
sampleInterval = (ma_uint32)(1/sampleSpacingX);
|
||||
}
|
||||
|
||||
if (sampleInterval == 0) {
|
||||
sampleInterval = 1; // Safety.
|
||||
}
|
||||
|
||||
mal_uint32 iFirstSample = 0;
|
||||
for (mal_uint32 iSample = iFirstSample; iSample < pChannel->sampleCount; iSample += sampleInterval) {
|
||||
ma_uint32 iFirstSample = 0;
|
||||
for (ma_uint32 iSample = iFirstSample; iSample < pChannel->sampleCount; iSample += sampleInterval) {
|
||||
float samplePosX = iSample * sampleSpacingX;
|
||||
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)
|
||||
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) {
|
||||
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);
|
||||
if (resultDTK != DTK_SUCCESS) {
|
||||
@@ -258,7 +258,7 @@ void msigvis_screen_uninit(msigvis_screen* pScreen)
|
||||
dtk_window_uninit(&pScreen->window);
|
||||
}
|
||||
|
||||
mal_result msigvis_screen_show(msigvis_screen* pScreen)
|
||||
ma_result msigvis_screen_show(msigvis_screen* pScreen)
|
||||
{
|
||||
if (pScreen == NULL) {
|
||||
return MA_INVALID_ARGS;
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
mal_result msigvis_screen_hide(msigvis_screen* pScreen)
|
||||
ma_result msigvis_screen_hide(msigvis_screen* pScreen)
|
||||
{
|
||||
if (pScreen == NULL) {
|
||||
return MA_INVALID_ARGS;
|
||||
@@ -276,7 +276,7 @@ mal_result msigvis_screen_hide(msigvis_screen* pScreen)
|
||||
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) {
|
||||
return MA_INVALID_ARGS;
|
||||
@@ -284,12 +284,12 @@ mal_result msigvis_screen_add_channel(msigvis_screen* pScreen, msigvis_channel*
|
||||
|
||||
// Expand if necessary.
|
||||
if (pScreen->channelCap == pScreen->channelCount) {
|
||||
mal_uint32 newCap = pScreen->channelCap*2;
|
||||
ma_uint32 newCap = pScreen->channelCap*2;
|
||||
if (newCap == 0) {
|
||||
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) {
|
||||
return MA_OUT_OF_MEMORY;
|
||||
}
|
||||
@@ -305,14 +305,14 @@ mal_result msigvis_screen_add_channel(msigvis_screen* pScreen, msigvis_channel*
|
||||
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) {
|
||||
return MA_INVALID_ARGS;
|
||||
}
|
||||
|
||||
mal_uint32 iChannel;
|
||||
mal_result result = msigvis_screen_find_channel_index(pScreen, pChannel, &iChannel);
|
||||
ma_uint32 iChannel;
|
||||
ma_result result = msigvis_screen_find_channel_index(pScreen, pChannel, &iChannel);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
@@ -320,7 +320,7 @@ mal_result msigvis_screen_remove_channel(msigvis_screen* pScreen, msigvis_channe
|
||||
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) {
|
||||
return MA_INVALID_ARGS;
|
||||
@@ -340,13 +340,13 @@ mal_result msigvis_screen_remove_channel_by_index(msigvis_screen* pScreen, mal_u
|
||||
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) {
|
||||
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) {
|
||||
*pIndex = iChannel;
|
||||
return MA_SUCCESS;
|
||||
@@ -356,7 +356,7 @@ mal_result msigvis_screen_find_channel_index(msigvis_screen* pScreen, msigvis_ch
|
||||
return MA_ERROR;
|
||||
}
|
||||
|
||||
mal_result msigvis_screen_redraw(msigvis_screen* pScreen)
|
||||
ma_result msigvis_screen_redraw(msigvis_screen* pScreen)
|
||||
{
|
||||
if (pScreen == NULL) {
|
||||
return MA_INVALID_ARGS;
|
||||
@@ -371,7 +371,7 @@ mal_result msigvis_screen_redraw(msigvis_screen* pScreen)
|
||||
// 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;
|
||||
|
||||
@@ -379,9 +379,9 @@ mal_result msigvis_channel_init(msigvis_context* pContext, mal_format format, ma
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -398,25 +398,25 @@ void msigvis_channel_uninit(msigvis_channel* pChannel)
|
||||
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) {
|
||||
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.
|
||||
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) {
|
||||
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) {
|
||||
return MA_OUT_OF_MEMORY;
|
||||
}
|
||||
@@ -425,13 +425,13 @@ mal_result msigvis_channel_push_samples(msigvis_channel* pChannel, mal_uint32 sa
|
||||
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;
|
||||
|
||||
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) {
|
||||
return MA_INVALID_ARGS;
|
||||
@@ -441,11 +441,11 @@ mal_result msigvis_channel_pop_samples(msigvis_channel* pChannel, mal_uint32 sam
|
||||
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.
|
||||
mal_uint32 bytesToRemove = sampleCount*bps;
|
||||
mal_assert(bytesToRemove > 0);
|
||||
ma_uint32 bytesToRemove = sampleCount*bps;
|
||||
ma_assert(bytesToRemove > 0);
|
||||
|
||||
memmove(pChannel->pBuffer, pChannel->pBuffer + bytesToRemove, pChannel->sampleCount*bps - bytesToRemove);
|
||||
pChannel->sampleCount -= sampleCount;
|
||||
@@ -453,11 +453,11 @@ mal_result msigvis_channel_pop_samples(msigvis_channel* pChannel, mal_uint32 sam
|
||||
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)
|
||||
{
|
||||
case mal_format_f32: return *((float*)pChannel->pBuffer + iSample);
|
||||
case ma_format_f32: return *((float*)pChannel->pBuffer + iSample);
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user