From f4930a4b52856b7767c476d165eff7465ca50947 Mon Sep 17 00:00:00 2001
From: chiefMarlin <96321026+chiefMarlin@users.noreply.github.com>
Date: Fri, 8 Dec 2023 15:45:14 -0500
Subject: [PATCH] Update miniaudio.h to 0.11.21
---
miniaudio.h | 28743 ++++++++++++++++++++++++++------------------------
1 file changed, 15069 insertions(+), 13674 deletions(-)
diff --git a/miniaudio.h b/miniaudio.h
index 324e432..47332e1 100644
--- a/miniaudio.h
+++ b/miniaudio.h
@@ -1,6 +1,6 @@
/*
Audio playback and capture library. Choice of public domain or MIT-0. See license statements at the end of this file.
-miniaudio - v0.11.10 - 2022-10-20
+miniaudio - v0.11.21 - 2023-11-15
David Reid - mackron@gmail.com
@@ -87,7 +87,7 @@ device on the stack, but you could allocate it on the heap if that suits your si
// Do something here. Probably your program's main loop.
- ma_device_uninit(&device); // This will stop the device so no need to do that manually.
+ ma_device_uninit(&device);
return 0;
}
```
@@ -398,13 +398,13 @@ the be started and/or stopped at a specific time. This can be done with the foll
```
The start/stop time needs to be specified based on the absolute timer which is controlled by the
-engine. The current global time time in PCM frames can be retrieved with `ma_engine_get_time()`.
-The engine's global time can be changed with `ma_engine_set_time()` for synchronization purposes if
-required. Note that scheduling a start time still requires an explicit call to `ma_sound_start()`
-before anything will play:
+engine. The current global time time in PCM frames can be retrieved with
+`ma_engine_get_time_in_pcm_frames()`. The engine's global time can be changed with
+`ma_engine_set_time_in_pcm_frames()` for synchronization purposes if required. Note that scheduling
+a start time still requires an explicit call to `ma_sound_start()` before anything will play:
```c
- ma_sound_set_start_time_in_pcm_frames(&sound, ma_engine_get_time(&engine) + (ma_engine_get_sample_rate(&engine) * 2);
+ ma_sound_set_start_time_in_pcm_frames(&sound, ma_engine_get_time_in_pcm_frames(&engine) + (ma_engine_get_sample_rate(&engine) * 2);
ma_sound_start(&sound);
```
@@ -460,6 +460,11 @@ is at the end, use `ma_sound_at_end()`. Looping of a sound can be controlled wit
miniaudio should work cleanly out of the box without the need to download or install any
dependencies. See below for platform-specific details.
+Note that GCC and Clang require `-msse2`, `-mavx2`, etc. for SIMD optimizations.
+
+If you get errors about undefined references to `__sync_val_compare_and_swap_8`, `__atomic_load_8`,
+etc. you need to link with `-latomic`.
+
2.1. Windows
------------
@@ -489,9 +494,10 @@ notarization process. To fix this there are two options. The first is to use the
#include "miniaudio.h"
```
-This will require linking with `-framework CoreFoundation -framework CoreAudio -framework AudioUnit`.
-Alternatively, if you would rather keep using runtime linking you can add the following to your
-entitlements.xcent file:
+This will require linking with `-framework CoreFoundation -framework CoreAudio -framework AudioToolbox`.
+If you get errors about AudioToolbox, try with `-framework AudioUnit` instead. You may get this when
+using older versions of iOS. Alternatively, if you would rather keep using runtime linking you can
+add the following to your entitlements.xcent file:
```
com.apple.security.cs.allow-dyld-environment-variables
@@ -532,6 +538,20 @@ you'll need to disable run-time linking with `MA_NO_RUNTIME_LINKING` and link wi
The Emscripten build emits Web Audio JavaScript directly and should compile cleanly out of the box.
You cannot use `-std=c*` compiler flags, nor `-ansi`.
+You can enable the use of AudioWorkets by defining `MA_ENABLE_AUDIO_WORKLETS` and then compiling
+with the following options:
+
+ -sAUDIO_WORKLET=1 -sWASM_WORKERS=1 -sASYNCIFY
+
+An example for compiling with AudioWorklet support might look like this:
+
+ emcc program.c -o bin/program.html -DMA_ENABLE_AUDIO_WORKLETS -sAUDIO_WORKLET=1 -sWASM_WORKERS=1 -sASYNCIFY
+
+To run locally, you'll need to use emrun:
+
+ emrun bin/program.html
+
+
2.7. Build Options
------------------
@@ -748,7 +768,7 @@ To read data from a data source:
ma_result result;
ma_uint64 framesRead;
- result = ma_data_source_read_pcm_frames(pDataSource, pFramesOut, frameCount, &framesRead, loop);
+ result = ma_data_source_read_pcm_frames(pDataSource, pFramesOut, frameCount, &framesRead);
if (result != MA_SUCCESS) {
return result; // Failed to read data from the data source.
}
@@ -768,7 +788,7 @@ you could plug in a decoder like so:
ma_uint64 framesRead;
ma_decoder decoder; // <-- This would be initialized with `ma_decoder_init_*()`.
- result = ma_data_source_read_pcm_frames(&decoder, pFramesOut, frameCount, &framesRead, loop);
+ result = ma_data_source_read_pcm_frames(&decoder, pFramesOut, frameCount, &framesRead);
if (result != MA_SUCCESS) {
return result; // Failed to read data from the decoder.
}
@@ -842,7 +862,9 @@ read data within a certain range of the underlying data. To do this you can use
```
This is useful if you have a sound bank where many sounds are stored in the same file and you want
-the data source to only play one of those sub-sounds.
+the data source to only play one of those sub-sounds. Note that once the range is set, everything
+that takes a position, such as cursors and loop points, should always be relatvie to the start of
+the range. When the range is set, any previously defined loop point will be reset.
Custom loop points can also be used with data sources. By default, data sources will loop after
they reach the end of the data source, but if you need to loop at a specific location, you can do
@@ -871,7 +893,7 @@ To do this, you can use chaining:
return result; // Failed to set the next data source.
}
- result = ma_data_source_read_pcm_frames(&decoder1, pFramesOut, frameCount, pFramesRead, MA_FALSE);
+ result = ma_data_source_read_pcm_frames(&decoder1, pFramesOut, frameCount, pFramesRead);
if (result != MA_SUCCESS) {
return result; // Failed to read from the decoder.
}
@@ -882,8 +904,8 @@ the top level data source in the chain. In the example above, `decoder1` is the
source in the chain. When `decoder1` reaches the end, `decoder2` will start seamlessly without any
gaps.
-Note that the `loop` parameter is set to false in the example above. When this is set to true, only
-the current data source will be looped. You can loop the entire chain by linking in a loop like so:
+Note that when looping is enabled, only the current data source will be looped. You can loop the
+entire chain by linking in a loop like so:
```c
ma_data_source_set_next(&decoder1, &decoder2); // decoder1 -> decoder2
@@ -894,9 +916,9 @@ Note that setting up chaining is not thread safe, so care needs to be taken if y
changing links while the audio thread is in the middle of reading.
Do not use `ma_decoder_seek_to_pcm_frame()` as a means to reuse a data source to play multiple
-instances of the same sound simultaneously. Instead, initialize multiple data sources for each
-instance. This can be extremely inefficient depending on the data source and can result in
-glitching due to subtle changes to the state of internal filters.
+instances of the same sound simultaneously. This can be extremely inefficient depending on the type
+of data source and can result in glitching due to subtle changes to the state of internal filters.
+Instead, initialize multiple data sources for each instance.
4.1. Custom Data Sources
@@ -941,7 +963,7 @@ base object (`ma_data_source_base`):
// Retrieve the length in PCM frames here. Return MA_NOT_IMPLEMENTED and set *pLength to 0 if there is no notion of a length or if the length is unknown.
}
- static g_my_data_source_vtable =
+ static ma_data_source_vtable g_my_data_source_vtable =
{
my_data_source_read,
my_data_source_seek,
@@ -1020,7 +1042,7 @@ configure the engine with an engine config:
ma_engine_config engineConfig;
engineConfig = ma_engine_config_init();
- engineConfig.pPlaybackDevice = &myDevice;
+ engineConfig.pDevice = &myDevice;
result = ma_engine_init(&engineConfig, &engine);
if (result != MA_SUCCESS) {
@@ -1061,7 +1083,7 @@ Note that when you're not using a device, you must set the channel count and sam
config or else miniaudio won't know what to use (miniaudio will use the device to determine this
normally). When not using a device, you need to use `ma_engine_read_pcm_frames()` to process audio
data from the engine. This kind of setup is useful if you want to do something like offline
-processing.
+processing or want to use a different audio system for playback such as SDL.
When a sound is loaded it goes through a resource manager. By default the engine will initialize a
resource manager internally, but you can also specify a pre-initialized resource manager:
@@ -1226,7 +1248,7 @@ might be beneficial to pre-decode the sound. You can do this with the `MA_SOUND_
By default, sounds will be loaded synchronously, meaning `ma_sound_init_*()` will not return until
the sound has been fully loaded. If this is prohibitive you can instead load sounds asynchronously
-by specificying the `MA_SOUND_FLAG_ASYNC` flag:
+by specifying the `MA_SOUND_FLAG_ASYNC` flag:
```c
ma_sound_init_from_file(&engine, "my_sound.wav", MA_SOUND_FLAG_DECODE | MA_SOUND_FLAG_ASYNC, pGroup, NULL, &sound);
@@ -1247,7 +1269,7 @@ counter hit's zero. You can specify a fence like so:
ma_sound sounds[4];
result = ma_fence_init(&fence);
- if (result != MA_SUCCES) {
+ if (result != MA_SUCCESS) {
return result;
}
@@ -1273,6 +1295,18 @@ When streaming sounds, 2 seconds worth of audio data is stored in memory. Althou
fine, it's inefficient to use streaming for short sounds. Streaming is useful for things like music
tracks in games.
+When loading a sound from a file path, the engine will reference count the file to prevent it from
+being loaded if it's already in memory. When you uninitialize a sound, the reference count will be
+decremented, and if it hits zero, the sound will be unloaded from memory. This reference counting
+system is not used for streams. The engine will use a 64-bit hash of the file name when comparing
+file paths which means there's a small chance you might encounter a name collision. If this is an
+issue, you'll need to use a different name for one of the colliding file paths, or just not load
+from files and instead load from a data source.
+
+You can use `ma_sound_init_copy()` to initialize a copy of another sound. Note, however, that this
+only works for sounds that were initialized with `ma_sound_init_from_file()` and without the
+`MA_SOUND_FLAG_STREAM` flag.
+
When you initialize a sound, if you specify a sound group the sound will be attached to that group
automatically. If you set it to NULL, it will be automatically attached to the engine's endpoint.
If you would instead rather leave the sound unattached by default, you can can specify the
@@ -1412,19 +1446,19 @@ can be useful to schedule a sound to start or stop:
```c
// Start the sound in 1 second from now.
- ma_sound_set_start_time_in_pcm_frames(&sound, ma_engine_get_time(&engine) + (ma_engine_get_sample_rate(&engine) * 1));
+ ma_sound_set_start_time_in_pcm_frames(&sound, ma_engine_get_time_in_pcm_frames(&engine) + (ma_engine_get_sample_rate(&engine) * 1));
// Stop the sound in 2 seconds from now.
- ma_sound_set_stop_time_in_pcm_frames(&sound, ma_engine_get_time(&engine) + (ma_engine_get_sample_rate(&engine) * 2));
+ ma_sound_set_stop_time_in_pcm_frames(&sound, ma_engine_get_time_in_pcm_frames(&engine) + (ma_engine_get_sample_rate(&engine) * 2));
```
Note that scheduling a start time still requires an explicit call to `ma_sound_start()` before
anything will play.
The time is specified in global time which is controlled by the engine. You can get the engine's
-current time with `ma_engine_get_time()`. The engine's global time is incremented automatically as
-audio data is read, but it can be reset with `ma_engine_set_time()` in case it needs to be
-resynchronized for some reason.
+current time with `ma_engine_get_time_in_pcm_frames()`. The engine's global time is incremented
+automatically as audio data is read, but it can be reset with `ma_engine_set_time_in_pcm_frames()`
+in case it needs to be resynchronized for some reason.
To determine whether or not a sound is currently playing, use `ma_sound_is_playing()`. This will
take the scheduled start and stop times into account.
@@ -1433,7 +1467,25 @@ Whether or not a sound should loop can be controlled with `ma_sound_set_looping(
be looping by default. Use `ma_sound_is_looping()` to determine whether or not a sound is looping.
Use `ma_sound_at_end()` to determine whether or not a sound is currently at the end. For a looping
-sound this should never return true.
+sound this should never return true. Alternatively, you can configure a callback that will be fired
+when the sound reaches the end. Note that the callback is fired from the audio thread which means
+you cannot be uninitializing sound from the callback. To set the callback you can use
+`ma_sound_set_end_callback()`. Alternatively, if you're using `ma_sound_init_ex()`, you can pass it
+into the config like so:
+
+ ```c
+ soundConfig.endCallback = my_end_callback;
+ soundConfig.pEndCallbackUserData = pMyEndCallbackUserData;
+ ```
+
+The end callback is declared like so:
+
+ ```c
+ void my_end_callback(void* pUserData, ma_sound* pSound)
+ {
+ ...
+ }
+ ```
Internally a sound wraps around a data source. Some APIs exist to control the underlying data
source, mainly for convenience:
@@ -1623,7 +1675,7 @@ an example for initializing a data source:
// ...
- ma_resource_manager_data_source_uninit(pResourceManager, &dataSource);
+ ma_resource_manager_data_source_uninit(&dataSource);
```
The `flags` parameter specifies how you want to perform loading of the sound file. It can be a
@@ -1860,19 +1912,21 @@ once after the other:
```c
ma_resource_manager_data_source_init(pResourceManager, "my_file", ..., &myDataBuffer0); // Refcount = 1. Initial load.
- ma_resource_manager_data_source_uninit(pResourceManager, &myDataBuffer0); // Refcount = 0. Unloaded.
+ ma_resource_manager_data_source_uninit(&myDataBuffer0); // Refcount = 0. Unloaded.
ma_resource_manager_data_source_init(pResourceManager, "my_file", ..., &myDataBuffer1); // Refcount = 1. Reloaded because previous uninit() unloaded it.
- ma_resource_manager_data_source_uninit(pResourceManager, &myDataBuffer1); // Refcount = 0. Unloaded.
+ ma_resource_manager_data_source_uninit(&myDataBuffer1); // Refcount = 0. Unloaded.
```
A binary search tree (BST) is used for storing data buffers as it has good balance between
efficiency and simplicity. The key of the BST is a 64-bit hash of the file path that was passed
into `ma_resource_manager_data_source_init()`. The advantage of using a hash is that it saves
memory over storing the entire path, has faster comparisons, and results in a mostly balanced BST
-due to the random nature of the hash. The disadvantage is that file names are case-sensitive. If
-this is an issue, you should normalize your file names to upper- or lower-case before initializing
-your data sources.
+due to the random nature of the hash. The disadvantages are that file names are case-sensitive and
+there's a small chance of name collisions. If case-sensitivity is an issue, you should normalize
+your file names to upper- or lower-case before initializing your data sources. If name collisions
+become an issue, you'll need to change the name of one of the colliding names or just not use the
+resource manager.
When a sound file has not already been loaded and the `MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_ASYNC`
flag is excluded, the file will be decoded synchronously by the calling thread. There are two
@@ -2018,14 +2072,14 @@ data from the graph:
```
When you read audio data, miniaudio starts at the node graph's endpoint node which then pulls in
-data from it's input attachments, which in turn recusively pull in data from their inputs, and so
+data from it's input attachments, which in turn recursively pull in data from their inputs, and so
on. At the start of the graph there will be some kind of data source node which will have zero
inputs and will instead read directly from a data source. The base nodes don't literally need to
read from a `ma_data_source` object, but they will always have some kind of underlying object that
sources some kind of audio. The `ma_data_source_node` node can be used to read from a
`ma_data_source`. Data is always in floating-point format and in the number of channels you
specified when the graph was initialized. The sample rate is defined by the underlying data sources.
-It's up to you to ensure they use a consistent and appropraite sample rate.
+It's up to you to ensure they use a consistent and appropriate sample rate.
The `ma_node` API is designed to allow custom nodes to be implemented with relative ease, but
miniaudio includes a few stock nodes for common functionality. This is how you would initialize a
@@ -2066,7 +2120,7 @@ another, you do not need to detach first. You can just call `ma_node_attach_outp
deal with it for you.
Less frequently you may want to create a specialized node. This will be a node where you implement
-your own processing callback to apply a custom effect of some kind. This is similar to initalizing
+your own processing callback to apply a custom effect of some kind. This is similar to initializing
one of the stock node types, only this time you need to specify a pointer to a vtable containing a
pointer to the processing function and the number of input and output buses. Example:
@@ -2105,7 +2159,7 @@ pointer to the processing function and the number of input and output buses. Exa
// Each bus needs to have a channel count specified. To do this you need to specify the channel
// counts in an array and then pass that into the node config.
ma_uint32 inputChannels[2]; // Equal in size to the number of input channels specified in the vtable.
- ma_uint32 outputChannels[1]; // Equal in size to the number of output channels specicied in the vtable.
+ ma_uint32 outputChannels[1]; // Equal in size to the number of output channels specified in the vtable.
inputChannels[0] = channelsIn;
inputChannels[1] = channelsIn;
@@ -2189,10 +2243,19 @@ and include the following:
+-----------------------------------------+---------------------------------------------------+
| MA_NODE_FLAG_CONTINUOUS_PROCESSING | Causes the processing callback to be called even |
| | when no data is available to be read from input |
- | | attachments. This is useful for effects like |
+ | | attachments. When a node has at least one input |
+ | | bus, but there are no inputs attached or the |
+ | | inputs do not deliver any data, the node's |
+ | | processing callback will not get fired. This flag |
+ | | will make it so the callback is always fired |
+ | | regardless of whether or not any input data is |
+ | | received. This is useful for effects like |
| | echos where there will be a tail of audio data |
| | that still needs to be processed even when the |
- | | original data sources have reached their ends. |
+ | | original data sources have reached their ends. It |
+ | | may also be useful for nodes that must always |
+ | | have their processing callback fired when there |
+ | | are no inputs attached. |
+-----------------------------------------+---------------------------------------------------+
| MA_NODE_FLAG_ALLOW_NULL_INPUT | Used in conjunction with |
| | `MA_NODE_FLAG_CONTINUOUS_PROCESSING`. When this |
@@ -2383,7 +2446,7 @@ bus and input bus is locked. This locking is specifically for attaching and deta
different threads and does not affect `ma_node_graph_read_pcm_frames()` in any way. The locking and
unlocking is mostly self-explanatory, but a slightly less intuitive aspect comes into it when
considering that iterating over attachments must not break as a result of attaching or detaching a
-node while iteration is occuring.
+node while iteration is occurring.
Attaching and detaching are both quite simple. When an output bus of a node is attached to an input
bus of another node, it's added to a linked list. Basically, an input bus is a linked list, where
@@ -2411,37 +2474,18 @@ used. The same general process applies to detachment. See `ma_node_attach_output
8. Decoding
===========
The `ma_decoder` API is used for reading audio files. Decoders are completely decoupled from
-devices and can be used independently. The following formats are supported:
+devices and can be used independently. Built-in support is included for the following formats:
- +---------+------------------+----------+
- | Format | Decoding Backend | Built-In |
- +---------+------------------+----------+
- | WAV | dr_wav | Yes |
- | MP3 | dr_mp3 | Yes |
- | FLAC | dr_flac | Yes |
- | Vorbis | stb_vorbis | No |
- +---------+------------------+----------+
+ +---------+
+ | Format |
+ +---------+
+ | WAV |
+ | MP3 |
+ | FLAC |
+ +---------+
-Vorbis is supported via stb_vorbis which can be enabled by including the header section before the
-implementation of miniaudio, like the following:
-
- ```c
- #define STB_VORBIS_HEADER_ONLY
- #include "extras/stb_vorbis.c" // Enables Vorbis decoding.
-
- #define MINIAUDIO_IMPLEMENTATION
- #include "miniaudio.h"
-
- // The stb_vorbis implementation must come after the implementation of miniaudio.
- #undef STB_VORBIS_HEADER_ONLY
- #include "extras/stb_vorbis.c"
- ```
-
-A copy of stb_vorbis is included in the "extras" folder in the miniaudio repository (https://github.com/mackron/miniaudio).
-
-Built-in decoders are amalgamated into the implementation section of miniaudio. You can disable the
-built-in decoders by specifying one or more of the following options before the miniaudio
-implementation:
+You can disable the built-in decoders by specifying one or more of the following options before the
+miniaudio implementation:
```c
#define MA_NO_WAV
@@ -2449,8 +2493,8 @@ built-in decoders by specifying one or more of the following options before the
#define MA_NO_FLAC
```
-Disabling built-in decoding libraries is useful if you use these libraries independantly of the
-`ma_decoder` API.
+miniaudio supports the ability to plug in custom decoders. See the section below for details on how
+to use custom decoders.
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
@@ -2563,11 +2607,11 @@ these are not specified, miniaudio will deal with it for you via a generic imple
When you initialize a custom data source (by implementing the `onInit` function in the vtable) you
will need to output a pointer to a `ma_data_source` which implements your custom decoder. See the
-section about data sources for details on how to implemen this. Alternatively, see the
+section about data sources for details on how to implement this. Alternatively, see the
"custom_decoders" example in the miniaudio repository.
The `onInit` function takes a pointer to some callbacks for the purpose of reading raw audio data
-from some abitrary source. You'll use these functions to read from the raw data and perform the
+from some arbitrary source. You'll use these functions to read from the raw data and perform the
decoding. When you call them, you will pass in the `pReadSeekTellUserData` pointer to the relevant
parameter.
@@ -2591,8 +2635,7 @@ opportunity to clean up and internal data.
9. Encoding
===========
-The `ma_encoding` API is used for writing audio files. The only supported output format is WAV
-which is achieved via dr_wav which is amalgamated into the implementation section of miniaudio.
+The `ma_encoding` API is used for writing audio files. The only supported output format is WAV.
This can be disabled by specifying the following option before the implementation of miniaudio:
```c
@@ -2632,9 +2675,16 @@ outputting any audio data. To output audio data, use `ma_encoder_write_pcm_frame
example below:
```c
- framesWritten = ma_encoder_write_pcm_frames(&encoder, pPCMFramesToWrite, framesToWrite);
+ ma_uint64 framesWritten;
+ result = ma_encoder_write_pcm_frames(&encoder, pPCMFramesToWrite, framesToWrite, &framesWritten);
+ if (result != MA_SUCCESS) {
+ ... handle error ...
+ }
```
+The `framesWritten` variable will contain the number of PCM frames that were actually written. This
+is optionally and you can pass in `NULL` if you need this.
+
Encoders must be uninitialized with `ma_encoder_uninit()`.
@@ -2718,7 +2768,7 @@ To perform the conversion simply call `ma_channel_converter_process_pcm_frames()
}
```
-It is up to the caller to ensure the output buffer is large enough to accomodate the new PCM
+It is up to the caller to ensure the output buffer is large enough to accommodate the new PCM
frames.
Input and output PCM frames are always interleaved. Deinterleaved layouts are not supported.
@@ -3164,7 +3214,7 @@ you can chain first and second order filters together.
If you need to change the configuration of the filter, but need to maintain the state of internal
registers you can do so with `ma_lpf_reinit()`. This may be useful if you need to change the sample
-rate and/or cutoff frequency dynamically while maintaing smooth transitions. Note that changing the
+rate and/or cutoff frequency dynamically while maintaining smooth transitions. Note that changing the
format or channel count after initialization is invalid and will result in an error.
The `ma_lpf` object supports a configurable order, but if you only need a first order filter you
@@ -3337,8 +3387,8 @@ The noise API uses simple LCG random number generation. It supports a custom see
for things like automated testing requiring reproducibility. Setting the seed to zero will default
to `MA_DEFAULT_LCG_SEED`.
-The amplitude, seed, and type can be changed dynamically with `ma_noise_set_amplitude()`,
-`ma_noise_set_seed()`, and `ma_noise_set_type()` respectively.
+The amplitude and seed can be changed dynamically with `ma_noise_set_amplitude()` and
+`ma_noise_set_seed()` respectively.
By default, the noise API will use different values for different channels. So, for example, the
left side in a stereo stream will be different to the right side. To instead have each channel use
@@ -3366,7 +3416,7 @@ miniaudio supports reading from a buffer of raw audio data via the `ma_audio_buf
read from memory that's managed by the application, but can also handle the memory management for
you internally. Memory management is flexible and should support most use cases.
-Audio buffers are initialised using the standard configuration system used everywhere in miniaudio:
+Audio buffers are initialized using the standard configuration system used everywhere in miniaudio:
```c
ma_audio_buffer_config config = ma_audio_buffer_config_init(
@@ -3486,7 +3536,7 @@ you will want to use. To initialize a ring buffer, do something like the followi
```
The `ma_pcm_rb_init()` function takes the sample format and channel count as parameters because
-it's the PCM varient of the ring buffer API. For the regular ring buffer that operates on bytes you
+it's the PCM variant of the ring buffer API. For the regular ring buffer that operates on bytes you
would call `ma_rb_init()` which leaves these out and just takes the size of the buffer in bytes
instead of frames. The fourth parameter is an optional pre-allocated buffer and the fifth parameter
is a pointer to a `ma_allocation_callbacks` structure for custom memory allocation routines.
@@ -3545,7 +3595,7 @@ example, ALSA, which is specific to Linux, will not be included in the Windows b
+-------------+-----------------------+--------------------------------------------------------+
| WASAPI | ma_backend_wasapi | Windows Vista+ |
| DirectSound | ma_backend_dsound | Windows XP+ |
- | WinMM | ma_backend_winmm | Windows XP+ (may work on older versions, but untested) |
+ | WinMM | ma_backend_winmm | Windows 95+ |
| Core Audio | ma_backend_coreaudio | macOS, iOS |
| sndio | ma_backend_sndio | OpenBSD |
| audio(4) | ma_backend_audio4 | NetBSD, OpenBSD |
@@ -3591,6 +3641,12 @@ Some backends have some nuance details you may want to be aware of.
miniaudio's built-in resampler is to take advantage of any potential device-specific
optimizations the driver may implement.
+BSD
+---
+- The sndio backend is currently only enabled on OpenBSD builds.
+- The audio(4) backend is supported on OpenBSD, but you may need to disable sndiod before you can
+ use it.
+
15.4. UWP
---------
- UWP only supports default playback and capture devices.
@@ -3621,14 +3677,28 @@ Some backends have some nuance details you may want to be aware of.
16. Optimization Tips
=====================
+See below for some tips on improving performance.
-16.1. High Level API
+16.1. Low Level API
+-------------------
+- In the data callback, if your data is already clipped prior to copying it into the output buffer,
+ set the `noClip` config option in the device config to true. This will disable miniaudio's built
+ in clipping function.
+- By default, miniaudio will pre-silence the data callback's output buffer. If you know that you
+ will always write valid data to the output buffer you can disable pre-silencing by setting the
+ `noPreSilence` config option in the device config to true.
+
+16.2. High Level API
--------------------
- If a sound does not require doppler or pitch shifting, consider disabling pitching by
initializing the sound with the `MA_SOUND_FLAG_NO_PITCH` flag.
-- If a sound does not require spatialization, disable it by initialzing the sound with the
- `MA_SOUND_FLAG_NO_SPATIALIZATION` flag. It can be renabled again post-initialization with
+- If a sound does not require spatialization, disable it by initializing the sound with the
+ `MA_SOUND_FLAG_NO_SPATIALIZATION` flag. It can be re-enabled again post-initialization with
`ma_sound_set_spatialization_enabled()`.
+- If you know all of your sounds will always be the same sample rate, set the engine's sample
+ rate to match that of the sounds. Likewise, if you're using a self-managed resource manager,
+ consider setting the decoded sample rate to match your sounds. By configuring everything to
+ use a consistent sample rate, sample rate conversion can be avoided.
@@ -3637,17 +3707,6 @@ Some backends have some nuance details you may want to be aware of.
- Automatic stream routing is enabled on a per-backend basis. Support is explicitly enabled for
WASAPI and Core Audio, however other backends such as PulseAudio may naturally support it, though
not all have been tested.
-- The contents of the output buffer passed into the data callback will always be pre-initialized to
- silence unless the `noPreSilencedOutputBuffer` config variable in `ma_device_config` is set to
- true, in which case it'll be undefined which will require you to write something to the entire
- buffer.
-- By default miniaudio will automatically clip samples. This only applies when the playback sample
- format is configured as `ma_format_f32`. If you are doing clipping yourself, you can disable this
- overhead by setting `noClip` to true in the device config.
-- Note that GCC and Clang requires `-msse2`, `-mavx2`, etc. for SIMD optimizations.
-- The sndio backend is currently only enabled on OpenBSD builds.
-- The audio(4) backend is supported on OpenBSD, but you may need to disable sndiod before you can
- use it.
- When compiling with VC6 and earlier, decoding is restricted to files less than 2GB in size. This
is due to 64-bit file APIs not being available.
*/
@@ -3664,7 +3723,7 @@ extern "C" {
#define MA_VERSION_MAJOR 0
#define MA_VERSION_MINOR 11
-#define MA_VERSION_REVISION 10
+#define MA_VERSION_REVISION 21
#define MA_VERSION_STRING MA_XSTRINGIFY(MA_VERSION_MAJOR) "." MA_XSTRINGIFY(MA_VERSION_MINOR) "." MA_XSTRINGIFY(MA_VERSION_REVISION)
#if defined(_MSC_VER) && !defined(__clang__)
@@ -3738,9 +3797,24 @@ typedef ma_uint32 ma_bool32;
#define MA_TRUE 1
#define MA_FALSE 0
+/* These float types are not used universally by miniaudio. It's to simplify some macro expansion for atomic types. */
+typedef float ma_float;
+typedef double ma_double;
+
typedef void* ma_handle;
typedef void* ma_ptr;
-typedef void (* ma_proc)(void);
+
+/*
+ma_proc is annoying because when compiling with GCC we get pendantic warnings about converting
+between `void*` and `void (*)()`. We can't use `void (*)()` with MSVC however, because we'll get
+warning C4191 about "type cast between incompatible function types". To work around this I'm going
+to use a different data type depending on the compiler.
+*/
+#if defined(__GNUC__)
+typedef void (*ma_proc)(void);
+#else
+typedef void* ma_proc;
+#endif
#if defined(_MSC_VER) && !defined(_WCHAR_T_DEFINED)
typedef ma_uint16 wchar_t;
@@ -3759,7 +3833,7 @@ typedef ma_uint16 wchar_t;
/* Platform/backend detection. */
-#ifdef _WIN32
+#if defined(_WIN32) || defined(__COSMOPOLITAN__)
#define MA_WIN32
#if defined(MA_FORCE_UWP) || (defined(WINAPI_FAMILY) && ((defined(WINAPI_FAMILY_PC_APP) && WINAPI_FAMILY == WINAPI_FAMILY_PC_APP) || (defined(WINAPI_FAMILY_PHONE_APP) && WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)))
#define MA_WIN32_UWP
@@ -3768,7 +3842,8 @@ typedef ma_uint16 wchar_t;
#else
#define MA_WIN32_DESKTOP
#endif
-#else
+#endif
+#if !defined(_WIN32) /* If it's not Win32, assume POSIX. */
#define MA_POSIX
/*
@@ -3789,29 +3864,64 @@ typedef ma_uint16 wchar_t;
typedef union ma_pthread_cond_t { char __data[48]; ma_uint64 __alignment; } ma_pthread_cond_t;
#endif
- #ifdef __unix__
+ #if defined(__unix__)
#define MA_UNIX
- #if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
- #define MA_BSD
- #endif
#endif
- #ifdef __linux__
+ #if defined(__linux__)
#define MA_LINUX
#endif
- #ifdef __APPLE__
+ #if defined(__APPLE__)
#define MA_APPLE
#endif
- #ifdef __ANDROID__
+ #if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+ #define MA_BSD
+ #endif
+ #if defined(__ANDROID__)
#define MA_ANDROID
#endif
- #ifdef __EMSCRIPTEN__
+ #if defined(__EMSCRIPTEN__)
#define MA_EMSCRIPTEN
#endif
+ #if defined(__ORBIS__)
+ #define MA_ORBIS
+ #endif
+ #if defined(__PROSPERO__)
+ #define MA_PROSPERO
+ #endif
+ #if defined(__NX__)
+ #define MA_NX
+ #endif
+ #if defined(__BEOS__) || defined(__HAIKU__)
+ #define MA_BEOS
+ #endif
+ #if defined(__HAIKU__)
+ #define MA_HAIKU
+ #endif
#endif
+#if defined(__has_c_attribute)
+ #if __has_c_attribute(fallthrough)
+ #define MA_FALLTHROUGH [[fallthrough]]
+ #endif
+#endif
+#if !defined(MA_FALLTHROUGH) && defined(__has_attribute) && (defined(__clang__) || defined(__GNUC__))
+ #if __has_attribute(fallthrough)
+ #define MA_FALLTHROUGH __attribute__((fallthrough))
+ #endif
+#endif
+#if !defined(MA_FALLTHROUGH)
+ #define MA_FALLTHROUGH ((void)0)
+#endif
#ifdef _MSC_VER
#define MA_INLINE __forceinline
+
+ /* noinline was introduced in Visual Studio 2005. */
+ #if _MSC_VER >= 1400
+ #define MA_NO_INLINE __declspec(noinline)
+ #else
+ #define MA_NO_INLINE
+ #endif
#elif defined(__GNUC__)
/*
I've had a bug report where GCC is emitting warnings about functions possibly not being inlineable. This warning happens when
@@ -3828,48 +3938,77 @@ typedef ma_uint16 wchar_t;
#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 2)) || defined(__clang__)
#define MA_INLINE MA_GNUC_INLINE_HINT __attribute__((always_inline))
+ #define MA_NO_INLINE __attribute__((noinline))
#else
#define MA_INLINE MA_GNUC_INLINE_HINT
+ #define MA_NO_INLINE __attribute__((noinline))
#endif
#elif defined(__WATCOMC__)
#define MA_INLINE __inline
+ #define MA_NO_INLINE
#else
#define MA_INLINE
+ #define MA_NO_INLINE
#endif
-#if !defined(MA_API)
- #if defined(MA_DLL)
- #if defined(_WIN32)
- #define MA_DLL_IMPORT __declspec(dllimport)
- #define MA_DLL_EXPORT __declspec(dllexport)
- #define MA_DLL_PRIVATE static
+/* MA_DLL is not officially supported. You're on your own if you want to use this. */
+#if defined(MA_DLL)
+ #if defined(_WIN32)
+ #define MA_DLL_IMPORT __declspec(dllimport)
+ #define MA_DLL_EXPORT __declspec(dllexport)
+ #define MA_DLL_PRIVATE static
+ #else
+ #if defined(__GNUC__) && __GNUC__ >= 4
+ #define MA_DLL_IMPORT __attribute__((visibility("default")))
+ #define MA_DLL_EXPORT __attribute__((visibility("default")))
+ #define MA_DLL_PRIVATE __attribute__((visibility("hidden")))
#else
- #if defined(__GNUC__) && __GNUC__ >= 4
- #define MA_DLL_IMPORT __attribute__((visibility("default")))
- #define MA_DLL_EXPORT __attribute__((visibility("default")))
- #define MA_DLL_PRIVATE __attribute__((visibility("hidden")))
- #else
- #define MA_DLL_IMPORT
- #define MA_DLL_EXPORT
- #define MA_DLL_PRIVATE static
- #endif
+ #define MA_DLL_IMPORT
+ #define MA_DLL_EXPORT
+ #define MA_DLL_PRIVATE static
#endif
+ #endif
+#endif
+#if !defined(MA_API)
+ #if defined(MA_DLL)
#if defined(MINIAUDIO_IMPLEMENTATION) || defined(MA_IMPLEMENTATION)
#define MA_API MA_DLL_EXPORT
#else
#define MA_API MA_DLL_IMPORT
#endif
- #define MA_PRIVATE MA_DLL_PRIVATE
#else
#define MA_API extern
+ #endif
+#endif
+
+#if !defined(MA_STATIC)
+ #if defined(MA_DLL)
+ #define MA_PRIVATE MA_DLL_PRIVATE
+ #else
#define MA_PRIVATE static
#endif
#endif
+
/* SIMD alignment in bytes. Currently set to 32 bytes in preparation for future AVX optimizations. */
#define MA_SIMD_ALIGNMENT 32
+/*
+Special wchar_t type to ensure any structures in the public sections that reference it have a
+consistent size across all platforms.
+
+On Windows, wchar_t is 2 bytes, whereas everywhere else it's 4 bytes. Since Windows likes to use
+wchar_t for it's IDs, we need a special explicitly sized wchar type that is always 2 bytes on all
+platforms.
+*/
+#if !defined(MA_POSIX) && defined(MA_WIN32)
+typedef wchar_t ma_wchar_win32;
+#else
+typedef ma_uint16 ma_wchar_win32;
+#endif
+
+
/*
Logging Levels
@@ -3916,7 +4055,7 @@ versions of Visual Studio, which I've confirmed with at least VC6.
*/
#if !defined(_MSC_VER) && defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
#include
- #define MA_ATOMIC(alignment, type) alignas(alignment) type
+ #define MA_ATOMIC(alignment, type) _Alignas(alignment) type
#else
#if defined(__GNUC__)
/* GCC-style compilers. */
@@ -4049,27 +4188,31 @@ typedef enum
MA_CANCELLED = -51,
MA_MEMORY_ALREADY_MAPPED = -52,
+ /* General non-standard errors. */
+ MA_CRC_MISMATCH = -100,
+
/* General miniaudio-specific errors. */
- MA_FORMAT_NOT_SUPPORTED = -100,
- MA_DEVICE_TYPE_NOT_SUPPORTED = -101,
- MA_SHARE_MODE_NOT_SUPPORTED = -102,
- MA_NO_BACKEND = -103,
- MA_NO_DEVICE = -104,
- MA_API_NOT_FOUND = -105,
- MA_INVALID_DEVICE_CONFIG = -106,
- MA_LOOP = -107,
+ MA_FORMAT_NOT_SUPPORTED = -200,
+ MA_DEVICE_TYPE_NOT_SUPPORTED = -201,
+ MA_SHARE_MODE_NOT_SUPPORTED = -202,
+ MA_NO_BACKEND = -203,
+ MA_NO_DEVICE = -204,
+ MA_API_NOT_FOUND = -205,
+ MA_INVALID_DEVICE_CONFIG = -206,
+ MA_LOOP = -207,
+ MA_BACKEND_NOT_ENABLED = -208,
/* State errors. */
- MA_DEVICE_NOT_INITIALIZED = -200,
- MA_DEVICE_ALREADY_INITIALIZED = -201,
- MA_DEVICE_NOT_STARTED = -202,
- MA_DEVICE_NOT_STOPPED = -203,
+ MA_DEVICE_NOT_INITIALIZED = -300,
+ MA_DEVICE_ALREADY_INITIALIZED = -301,
+ MA_DEVICE_NOT_STARTED = -302,
+ MA_DEVICE_NOT_STOPPED = -303,
/* Operation errors. */
- MA_FAILED_TO_INIT_BACKEND = -300,
- MA_FAILED_TO_OPEN_BACKEND_DEVICE = -301,
- MA_FAILED_TO_START_BACKEND_DEVICE = -302,
- MA_FAILED_TO_STOP_BACKEND_DEVICE = -303
+ MA_FAILED_TO_INIT_BACKEND = -400,
+ MA_FAILED_TO_OPEN_BACKEND_DEVICE = -401,
+ MA_FAILED_TO_START_BACKEND_DEVICE = -402,
+ MA_FAILED_TO_STOP_BACKEND_DEVICE = -403
} ma_result;
@@ -4131,7 +4274,7 @@ typedef enum
ma_standard_sample_rate_192000 = 192000,
ma_standard_sample_rate_16000 = 16000, /* Extreme lows */
- ma_standard_sample_rate_11025 = 11250,
+ ma_standard_sample_rate_11025 = 11025,
ma_standard_sample_rate_8000 = 8000,
ma_standard_sample_rate_352800 = 352800, /* Extreme highs */
@@ -4185,65 +4328,118 @@ typedef struct
} ma_lcg;
-/* Spinlocks are 32-bit for compatibility reasons. */
-typedef ma_uint32 ma_spinlock;
+/*
+Atomics.
-#ifndef MA_NO_THREADING
-/* Thread priorities should be ordered such that the default priority of the worker thread is 0. */
-typedef enum
-{
- ma_thread_priority_idle = -5,
- ma_thread_priority_lowest = -4,
- ma_thread_priority_low = -3,
- ma_thread_priority_normal = -2,
- ma_thread_priority_high = -1,
- ma_thread_priority_highest = 0,
- ma_thread_priority_realtime = 1,
- ma_thread_priority_default = 0
-} ma_thread_priority;
+These are typesafe structures to prevent errors as a result of forgetting to reference variables atomically. It's too
+easy to introduce subtle bugs where you accidentally do a regular assignment instead of an atomic load/store, etc. By
+using a struct we can enforce the use of atomics at compile time.
-#if defined(MA_WIN32)
-typedef ma_handle ma_thread;
-#endif
-#if defined(MA_POSIX)
-typedef ma_pthread_t ma_thread;
-#endif
+These types are declared in the header section because we need to reference them in structs below, but functions for
+using them are only exposed in the implementation section. I do not want these to be part of the public API.
-#if defined(MA_WIN32)
-typedef ma_handle ma_mutex;
-#endif
-#if defined(MA_POSIX)
-typedef ma_pthread_mutex_t ma_mutex;
-#endif
+There's a few downsides to this system. The first is that you need to declare a new struct for each type. Below are
+some macros to help with the declarations. They will be named like so:
-#if defined(MA_WIN32)
-typedef ma_handle ma_event;
-#endif
-#if defined(MA_POSIX)
-typedef struct
-{
- ma_uint32 value;
- ma_pthread_mutex_t lock;
- ma_pthread_cond_t cond;
-} ma_event;
-#endif /* MA_POSIX */
+ ma_atomic_uint32 - atomic ma_uint32
+ ma_atomic_int32 - atomic ma_int32
+ ma_atomic_uint64 - atomic ma_uint64
+ ma_atomic_float - atomic float
+ ma_atomic_bool32 - atomic ma_bool32
-#if defined(MA_WIN32)
-typedef ma_handle ma_semaphore;
-#endif
-#if defined(MA_POSIX)
-typedef struct
-{
- int value;
- ma_pthread_mutex_t lock;
- ma_pthread_cond_t cond;
-} ma_semaphore;
-#endif /* MA_POSIX */
+The other downside is that atomic pointers are extremely messy. You need to declare a new struct for each specific
+type of pointer you need to make atomic. For example, an atomic ma_node* will look like this:
+
+ MA_ATOMIC_SAFE_TYPE_IMPL_PTR(node)
+
+Which will declare a type struct that's named like so:
+
+ ma_atomic_ptr_node
+
+Functions to use the atomic types are declared in the implementation section. All atomic functions are prefixed with
+the name of the struct. For example:
+
+ ma_atomic_uint32_set() - Atomic store of ma_uint32
+ ma_atomic_uint32_get() - Atomic load of ma_uint32
+ etc.
+
+For pointer types it's the same, which makes them a bit messy to use due to the length of each function name, but in
+return you get type safety and enforcement of atomic operations.
+*/
+#define MA_ATOMIC_SAFE_TYPE_DECL(c89TypeExtension, typeSize, type) \
+ typedef struct \
+ { \
+ MA_ATOMIC(typeSize, ma_##type) value; \
+ } ma_atomic_##type; \
+
+#define MA_ATOMIC_SAFE_TYPE_DECL_PTR(type) \
+ typedef struct \
+ { \
+ MA_ATOMIC(MA_SIZEOF_PTR, ma_##type*) value; \
+ } ma_atomic_ptr_##type; \
+
+MA_ATOMIC_SAFE_TYPE_DECL(32, 4, uint32)
+MA_ATOMIC_SAFE_TYPE_DECL(i32, 4, int32)
+MA_ATOMIC_SAFE_TYPE_DECL(64, 8, uint64)
+MA_ATOMIC_SAFE_TYPE_DECL(f32, 4, float)
+MA_ATOMIC_SAFE_TYPE_DECL(32, 4, bool32)
+
+
+/* Spinlocks are 32-bit for compatibility reasons. */
+typedef ma_uint32 ma_spinlock;
+
+#ifndef MA_NO_THREADING
+ /* Thread priorities should be ordered such that the default priority of the worker thread is 0. */
+ typedef enum
+ {
+ ma_thread_priority_idle = -5,
+ ma_thread_priority_lowest = -4,
+ ma_thread_priority_low = -3,
+ ma_thread_priority_normal = -2,
+ ma_thread_priority_high = -1,
+ ma_thread_priority_highest = 0,
+ ma_thread_priority_realtime = 1,
+ ma_thread_priority_default = 0
+ } ma_thread_priority;
+
+ #if defined(MA_POSIX)
+ typedef ma_pthread_t ma_thread;
+ #elif defined(MA_WIN32)
+ typedef ma_handle ma_thread;
+ #endif
+
+ #if defined(MA_POSIX)
+ typedef ma_pthread_mutex_t ma_mutex;
+ #elif defined(MA_WIN32)
+ typedef ma_handle ma_mutex;
+ #endif
+
+ #if defined(MA_POSIX)
+ typedef struct
+ {
+ ma_uint32 value;
+ ma_pthread_mutex_t lock;
+ ma_pthread_cond_t cond;
+ } ma_event;
+ #elif defined(MA_WIN32)
+ typedef ma_handle ma_event;
+ #endif
+
+ #if defined(MA_POSIX)
+ typedef struct
+ {
+ int value;
+ ma_pthread_mutex_t lock;
+ ma_pthread_cond_t cond;
+ } ma_semaphore;
+ #elif defined(MA_WIN32)
+ typedef ma_handle ma_semaphore;
+ #endif
#else
-/* MA_NO_THREADING is set which means threading is disabled. Threading is required by some API families. If any of these are enabled we need to throw an error. */
-#ifndef MA_NO_DEVICE_IO
-#error "MA_NO_THREADING cannot be used without MA_NO_DEVICE_IO";
-#endif
+ /* MA_NO_THREADING is set which means threading is disabled. Threading is required by some API families. If any of these are enabled we need to throw an error. */
+ #ifndef MA_NO_DEVICE_IO
+ #error "MA_NO_THREADING cannot be used without MA_NO_DEVICE_IO";
+ #endif
#endif /* MA_NO_THREADING */
@@ -4271,7 +4467,7 @@ Logging
#endif
#endif
#ifndef MA_ATTRIBUTE_FORMAT
-#define MA_ATTRIBUTE_FORMAT(fmt,va)
+#define MA_ATTRIBUTE_FORMAT(fmt, va)
#endif
#ifndef MA_MAX_LOG_CALLBACKS
@@ -4302,11 +4498,6 @@ logLevel (in)
pMessage (in)
The log message.
-
-
-Remarks
--------
-Do not modify the state of the device from inside the callback.
*/
typedef void (* ma_log_callback_proc)(void* pUserData, ma_uint32 level, const char* pMessage);
@@ -4801,6 +4992,7 @@ typedef struct
{
ma_gainer_config config;
ma_uint32 t;
+ float masterVolume;
float* pOldGains;
float* pNewGains;
@@ -4816,6 +5008,8 @@ MA_API void ma_gainer_uninit(ma_gainer* pGainer, const ma_allocation_callbacks*
MA_API ma_result ma_gainer_process_pcm_frames(ma_gainer* pGainer, void* pFramesOut, const void* pFramesIn, ma_uint64 frameCount);
MA_API ma_result ma_gainer_set_gain(ma_gainer* pGainer, float newGain);
MA_API ma_result ma_gainer_set_gains(ma_gainer* pGainer, float* pNewGains);
+MA_API ma_result ma_gainer_set_master_volume(ma_gainer* pGainer, float volume);
+MA_API ma_result ma_gainer_get_master_volume(const ma_gainer* pGainer, float* pVolume);
@@ -4870,14 +5064,15 @@ typedef struct
float volumeBeg; /* If volumeBeg and volumeEnd is equal to 1, no fading happens (ma_fader_process_pcm_frames() will run as a passthrough). */
float volumeEnd;
ma_uint64 lengthInFrames; /* The total length of the fade. */
- ma_uint64 cursorInFrames; /* The current time in frames. Incremented by ma_fader_process_pcm_frames(). */
+ ma_int64 cursorInFrames; /* The current time in frames. Incremented by ma_fader_process_pcm_frames(). Signed because it'll be offset by startOffsetInFrames in set_fade_ex(). */
} ma_fader;
MA_API ma_result ma_fader_init(const ma_fader_config* pConfig, ma_fader* pFader);
MA_API ma_result ma_fader_process_pcm_frames(ma_fader* pFader, void* pFramesOut, const void* pFramesIn, ma_uint64 frameCount);
MA_API void ma_fader_get_data_format(const ma_fader* pFader, ma_format* pFormat, ma_uint32* pChannels, ma_uint32* pSampleRate);
MA_API void ma_fader_set_fade(ma_fader* pFader, float volumeBeg, float volumeEnd, ma_uint64 lengthInFrames);
-MA_API float ma_fader_get_current_volume(ma_fader* pFader);
+MA_API void ma_fader_set_fade_ex(ma_fader* pFader, float volumeBeg, float volumeEnd, ma_uint64 lengthInFrames, ma_int64 startOffsetInFrames);
+MA_API float ma_fader_get_current_volume(const ma_fader* pFader);
@@ -4889,6 +5084,12 @@ typedef struct
float z;
} ma_vec3f;
+typedef struct
+{
+ ma_vec3f v;
+ ma_spinlock lock;
+} ma_atomic_vec3f;
+
typedef enum
{
ma_attenuation_model_none, /* No distance attenuation and no spatialization. */
@@ -4928,9 +5129,9 @@ MA_API ma_spatializer_listener_config ma_spatializer_listener_config_init(ma_uin
typedef struct
{
ma_spatializer_listener_config config;
- ma_vec3f position; /* The absolute position of the listener. */
- ma_vec3f direction; /* The direction the listener is facing. The world up vector is config.worldUp. */
- ma_vec3f velocity;
+ ma_atomic_vec3f position; /* The absolute position of the listener. */
+ ma_atomic_vec3f direction; /* The direction the listener is facing. The world up vector is config.worldUp. */
+ ma_atomic_vec3f velocity;
ma_bool32 isEnabled;
/* Memory management. */
@@ -4977,6 +5178,7 @@ typedef struct
float coneOuterGain;
float dopplerFactor; /* Set to 0 to disable doppler effect. */
float directionalAttenuationFactor; /* Set to 0 to disable directional attenuation. */
+ float minSpatializationChannelGain; /* The minimal scaling factor to apply to channel gains when accounting for the direction of the sound relative to the listener. Must be in the range of 0..1. Smaller values means more aggressive directional panning, larger values means more subtle directional panning. */
ma_uint32 gainSmoothTimeInFrames; /* When the gain of a channel changes during spatialization, the transition will be linearly interpolated over this number of frames. */
} ma_spatializer_config;
@@ -5002,10 +5204,11 @@ typedef struct
float dopplerFactor; /* Set to 0 to disable doppler effect. */
float directionalAttenuationFactor; /* Set to 0 to disable directional attenuation. */
ma_uint32 gainSmoothTimeInFrames; /* When the gain of a channel changes during spatialization, the transition will be linearly interpolated over this number of frames. */
- ma_vec3f position;
- ma_vec3f direction;
- ma_vec3f velocity; /* For doppler effect. */
+ ma_atomic_vec3f position;
+ ma_atomic_vec3f direction;
+ ma_atomic_vec3f velocity; /* For doppler effect. */
float dopplerPitch; /* Will be updated by ma_spatializer_process_pcm_frames() and can be used by higher level functions to apply a pitch shift for doppler effect. */
+ float minSpatializationChannelGain;
ma_gainer gainer; /* For smooth gain transitions. */
float* pNewChannelGainsOut; /* An offset of _pHeap. Used by ma_spatializer_process_pcm_frames() to store new channel gains. The number of elements in this array is equal to config.channelsOut. */
@@ -5019,6 +5222,8 @@ MA_API ma_result ma_spatializer_init_preallocated(const ma_spatializer_config* p
MA_API ma_result ma_spatializer_init(const ma_spatializer_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_spatializer* pSpatializer);
MA_API void ma_spatializer_uninit(ma_spatializer* pSpatializer, const ma_allocation_callbacks* pAllocationCallbacks);
MA_API ma_result ma_spatializer_process_pcm_frames(ma_spatializer* pSpatializer, ma_spatializer_listener* pListener, void* pFramesOut, const void* pFramesIn, ma_uint64 frameCount);
+MA_API ma_result ma_spatializer_set_master_volume(ma_spatializer* pSpatializer, float volume);
+MA_API ma_result ma_spatializer_get_master_volume(const ma_spatializer* pSpatializer, float* pVolume);
MA_API ma_uint32 ma_spatializer_get_input_channels(const ma_spatializer* pSpatializer);
MA_API ma_uint32 ma_spatializer_get_output_channels(const ma_spatializer* pSpatializer);
MA_API void ma_spatializer_set_attenuation_model(ma_spatializer* pSpatializer, ma_attenuation_model attenuationModel);
@@ -5192,7 +5397,7 @@ MA_API void ma_resampler_uninit(ma_resampler* pResampler, const ma_allocation_ca
/*
Converts the given input data.
-Both the input and output frames must be in the format specified in the config when the resampler was initilized.
+Both the input and output frames must be in the format specified in the config when the resampler was initialized.
On input, [pFrameCountOut] contains the number of output frames to process. On output it contains the number of output frames that
were actually processed, which may be less than the requested amount which will happen if there's not enough input data. You can use
@@ -5215,7 +5420,7 @@ MA_API ma_result ma_resampler_process_pcm_frames(ma_resampler* pResampler, const
/*
-Sets the input and output sample sample rate.
+Sets the input and output sample rate.
*/
MA_API ma_result ma_resampler_set_rate(ma_resampler* pResampler, ma_uint32 sampleRateIn, ma_uint32 sampleRateOut);
@@ -5564,6 +5769,197 @@ MA_API ma_uint64 ma_convert_frames(void* pOut, ma_uint64 frameCountOut, ma_forma
MA_API ma_uint64 ma_convert_frames_ex(void* pOut, ma_uint64 frameCountOut, const void* pIn, ma_uint64 frameCountIn, const ma_data_converter_config* pConfig);
+/************************************************************************************************************************************************************
+
+Data Source
+
+************************************************************************************************************************************************************/
+typedef void ma_data_source;
+
+#define MA_DATA_SOURCE_SELF_MANAGED_RANGE_AND_LOOP_POINT 0x00000001
+
+typedef struct
+{
+ ma_result (* onRead)(ma_data_source* pDataSource, void* pFramesOut, ma_uint64 frameCount, ma_uint64* pFramesRead);
+ ma_result (* onSeek)(ma_data_source* pDataSource, ma_uint64 frameIndex);
+ ma_result (* onGetDataFormat)(ma_data_source* pDataSource, ma_format* pFormat, ma_uint32* pChannels, ma_uint32* pSampleRate, ma_channel* pChannelMap, size_t channelMapCap);
+ ma_result (* onGetCursor)(ma_data_source* pDataSource, ma_uint64* pCursor);
+ ma_result (* onGetLength)(ma_data_source* pDataSource, ma_uint64* pLength);
+ ma_result (* onSetLooping)(ma_data_source* pDataSource, ma_bool32 isLooping);
+ ma_uint32 flags;
+} ma_data_source_vtable;
+
+typedef ma_data_source* (* ma_data_source_get_next_proc)(ma_data_source* pDataSource);
+
+typedef struct
+{
+ const ma_data_source_vtable* vtable;
+} ma_data_source_config;
+
+MA_API ma_data_source_config ma_data_source_config_init(void);
+
+
+typedef struct
+{
+ const ma_data_source_vtable* vtable;
+ ma_uint64 rangeBegInFrames;
+ ma_uint64 rangeEndInFrames; /* Set to -1 for unranged (default). */
+ ma_uint64 loopBegInFrames; /* Relative to rangeBegInFrames. */
+ ma_uint64 loopEndInFrames; /* Relative to rangeBegInFrames. Set to -1 for the end of the range. */
+ ma_data_source* pCurrent; /* When non-NULL, the data source being initialized will act as a proxy and will route all operations to pCurrent. Used in conjunction with pNext/onGetNext for seamless chaining. */
+ ma_data_source* pNext; /* When set to NULL, onGetNext will be used. */
+ ma_data_source_get_next_proc onGetNext; /* Will be used when pNext is NULL. If both are NULL, no next will be used. */
+ MA_ATOMIC(4, ma_bool32) isLooping;
+} ma_data_source_base;
+
+MA_API ma_result ma_data_source_init(const ma_data_source_config* pConfig, ma_data_source* pDataSource);
+MA_API void ma_data_source_uninit(ma_data_source* pDataSource);
+MA_API ma_result ma_data_source_read_pcm_frames(ma_data_source* pDataSource, void* pFramesOut, ma_uint64 frameCount, ma_uint64* pFramesRead); /* Must support pFramesOut = NULL in which case a forward seek should be performed. */
+MA_API ma_result ma_data_source_seek_pcm_frames(ma_data_source* pDataSource, ma_uint64 frameCount, ma_uint64* pFramesSeeked); /* Can only seek forward. Equivalent to ma_data_source_read_pcm_frames(pDataSource, NULL, frameCount, &framesRead); */
+MA_API ma_result ma_data_source_seek_to_pcm_frame(ma_data_source* pDataSource, ma_uint64 frameIndex);
+MA_API ma_result ma_data_source_get_data_format(ma_data_source* pDataSource, ma_format* pFormat, ma_uint32* pChannels, ma_uint32* pSampleRate, ma_channel* pChannelMap, size_t channelMapCap);
+MA_API ma_result ma_data_source_get_cursor_in_pcm_frames(ma_data_source* pDataSource, ma_uint64* pCursor);
+MA_API ma_result ma_data_source_get_length_in_pcm_frames(ma_data_source* pDataSource, ma_uint64* pLength); /* Returns MA_NOT_IMPLEMENTED if the length is unknown or cannot be determined. Decoders can return this. */
+MA_API ma_result ma_data_source_get_cursor_in_seconds(ma_data_source* pDataSource, float* pCursor);
+MA_API ma_result ma_data_source_get_length_in_seconds(ma_data_source* pDataSource, float* pLength);
+MA_API ma_result ma_data_source_set_looping(ma_data_source* pDataSource, ma_bool32 isLooping);
+MA_API ma_bool32 ma_data_source_is_looping(const ma_data_source* pDataSource);
+MA_API ma_result ma_data_source_set_range_in_pcm_frames(ma_data_source* pDataSource, ma_uint64 rangeBegInFrames, ma_uint64 rangeEndInFrames);
+MA_API void ma_data_source_get_range_in_pcm_frames(const ma_data_source* pDataSource, ma_uint64* pRangeBegInFrames, ma_uint64* pRangeEndInFrames);
+MA_API ma_result ma_data_source_set_loop_point_in_pcm_frames(ma_data_source* pDataSource, ma_uint64 loopBegInFrames, ma_uint64 loopEndInFrames);
+MA_API void ma_data_source_get_loop_point_in_pcm_frames(const ma_data_source* pDataSource, ma_uint64* pLoopBegInFrames, ma_uint64* pLoopEndInFrames);
+MA_API ma_result ma_data_source_set_current(ma_data_source* pDataSource, ma_data_source* pCurrentDataSource);
+MA_API ma_data_source* ma_data_source_get_current(const ma_data_source* pDataSource);
+MA_API ma_result ma_data_source_set_next(ma_data_source* pDataSource, ma_data_source* pNextDataSource);
+MA_API ma_data_source* ma_data_source_get_next(const ma_data_source* pDataSource);
+MA_API ma_result ma_data_source_set_next_callback(ma_data_source* pDataSource, ma_data_source_get_next_proc onGetNext);
+MA_API ma_data_source_get_next_proc ma_data_source_get_next_callback(const ma_data_source* pDataSource);
+
+
+typedef struct
+{
+ ma_data_source_base ds;
+ ma_format format;
+ ma_uint32 channels;
+ ma_uint32 sampleRate;
+ ma_uint64 cursor;
+ ma_uint64 sizeInFrames;
+ const void* pData;
+} ma_audio_buffer_ref;
+
+MA_API ma_result ma_audio_buffer_ref_init(ma_format format, ma_uint32 channels, const void* pData, ma_uint64 sizeInFrames, ma_audio_buffer_ref* pAudioBufferRef);
+MA_API void ma_audio_buffer_ref_uninit(ma_audio_buffer_ref* pAudioBufferRef);
+MA_API ma_result ma_audio_buffer_ref_set_data(ma_audio_buffer_ref* pAudioBufferRef, const void* pData, ma_uint64 sizeInFrames);
+MA_API ma_uint64 ma_audio_buffer_ref_read_pcm_frames(ma_audio_buffer_ref* pAudioBufferRef, void* pFramesOut, ma_uint64 frameCount, ma_bool32 loop);
+MA_API ma_result ma_audio_buffer_ref_seek_to_pcm_frame(ma_audio_buffer_ref* pAudioBufferRef, ma_uint64 frameIndex);
+MA_API ma_result ma_audio_buffer_ref_map(ma_audio_buffer_ref* pAudioBufferRef, void** ppFramesOut, ma_uint64* pFrameCount);
+MA_API ma_result ma_audio_buffer_ref_unmap(ma_audio_buffer_ref* pAudioBufferRef, ma_uint64 frameCount); /* Returns MA_AT_END if the end has been reached. This should be considered successful. */
+MA_API ma_bool32 ma_audio_buffer_ref_at_end(const ma_audio_buffer_ref* pAudioBufferRef);
+MA_API ma_result ma_audio_buffer_ref_get_cursor_in_pcm_frames(const ma_audio_buffer_ref* pAudioBufferRef, ma_uint64* pCursor);
+MA_API ma_result ma_audio_buffer_ref_get_length_in_pcm_frames(const ma_audio_buffer_ref* pAudioBufferRef, ma_uint64* pLength);
+MA_API ma_result ma_audio_buffer_ref_get_available_frames(const ma_audio_buffer_ref* pAudioBufferRef, ma_uint64* pAvailableFrames);
+
+
+
+typedef struct
+{
+ ma_format format;
+ ma_uint32 channels;
+ ma_uint32 sampleRate;
+ ma_uint64 sizeInFrames;
+ const void* pData; /* If set to NULL, will allocate a block of memory for you. */
+ ma_allocation_callbacks allocationCallbacks;
+} ma_audio_buffer_config;
+
+MA_API ma_audio_buffer_config ma_audio_buffer_config_init(ma_format format, ma_uint32 channels, ma_uint64 sizeInFrames, const void* pData, const ma_allocation_callbacks* pAllocationCallbacks);
+
+typedef struct
+{
+ ma_audio_buffer_ref ref;
+ ma_allocation_callbacks allocationCallbacks;
+ ma_bool32 ownsData; /* Used to control whether or not miniaudio owns the data buffer. If set to true, pData will be freed in ma_audio_buffer_uninit(). */
+ ma_uint8 _pExtraData[1]; /* For allocating a buffer with the memory located directly after the other memory of the structure. */
+} ma_audio_buffer;
+
+MA_API ma_result ma_audio_buffer_init(const ma_audio_buffer_config* pConfig, ma_audio_buffer* pAudioBuffer);
+MA_API ma_result ma_audio_buffer_init_copy(const ma_audio_buffer_config* pConfig, ma_audio_buffer* pAudioBuffer);
+MA_API ma_result ma_audio_buffer_alloc_and_init(const ma_audio_buffer_config* pConfig, ma_audio_buffer** ppAudioBuffer); /* Always copies the data. Doesn't make sense to use this otherwise. Use ma_audio_buffer_uninit_and_free() to uninit. */
+MA_API void ma_audio_buffer_uninit(ma_audio_buffer* pAudioBuffer);
+MA_API void ma_audio_buffer_uninit_and_free(ma_audio_buffer* pAudioBuffer);
+MA_API ma_uint64 ma_audio_buffer_read_pcm_frames(ma_audio_buffer* pAudioBuffer, void* pFramesOut, ma_uint64 frameCount, ma_bool32 loop);
+MA_API ma_result ma_audio_buffer_seek_to_pcm_frame(ma_audio_buffer* pAudioBuffer, ma_uint64 frameIndex);
+MA_API ma_result ma_audio_buffer_map(ma_audio_buffer* pAudioBuffer, void** ppFramesOut, ma_uint64* pFrameCount);
+MA_API ma_result ma_audio_buffer_unmap(ma_audio_buffer* pAudioBuffer, ma_uint64 frameCount); /* Returns MA_AT_END if the end has been reached. This should be considered successful. */
+MA_API ma_bool32 ma_audio_buffer_at_end(const ma_audio_buffer* pAudioBuffer);
+MA_API ma_result ma_audio_buffer_get_cursor_in_pcm_frames(const ma_audio_buffer* pAudioBuffer, ma_uint64* pCursor);
+MA_API ma_result ma_audio_buffer_get_length_in_pcm_frames(const ma_audio_buffer* pAudioBuffer, ma_uint64* pLength);
+MA_API ma_result ma_audio_buffer_get_available_frames(const ma_audio_buffer* pAudioBuffer, ma_uint64* pAvailableFrames);
+
+
+/*
+Paged Audio Buffer
+==================
+A paged audio buffer is made up of a linked list of pages. It's expandable, but not shrinkable. It
+can be used for cases where audio data is streamed in asynchronously while allowing data to be read
+at the same time.
+
+This is lock-free, but not 100% thread safe. You can append a page and read from the buffer across
+simultaneously across different threads, however only one thread at a time can append, and only one
+thread at a time can read and seek.
+*/
+typedef struct ma_paged_audio_buffer_page ma_paged_audio_buffer_page;
+struct ma_paged_audio_buffer_page
+{
+ MA_ATOMIC(MA_SIZEOF_PTR, ma_paged_audio_buffer_page*) pNext;
+ ma_uint64 sizeInFrames;
+ ma_uint8 pAudioData[1];
+};
+
+typedef struct
+{
+ ma_format format;
+ ma_uint32 channels;
+ ma_paged_audio_buffer_page head; /* Dummy head for the lock-free algorithm. Always has a size of 0. */
+ MA_ATOMIC(MA_SIZEOF_PTR, ma_paged_audio_buffer_page*) pTail; /* Never null. Initially set to &head. */
+} ma_paged_audio_buffer_data;
+
+MA_API ma_result ma_paged_audio_buffer_data_init(ma_format format, ma_uint32 channels, ma_paged_audio_buffer_data* pData);
+MA_API void ma_paged_audio_buffer_data_uninit(ma_paged_audio_buffer_data* pData, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_paged_audio_buffer_page* ma_paged_audio_buffer_data_get_head(ma_paged_audio_buffer_data* pData);
+MA_API ma_paged_audio_buffer_page* ma_paged_audio_buffer_data_get_tail(ma_paged_audio_buffer_data* pData);
+MA_API ma_result ma_paged_audio_buffer_data_get_length_in_pcm_frames(ma_paged_audio_buffer_data* pData, ma_uint64* pLength);
+MA_API ma_result ma_paged_audio_buffer_data_allocate_page(ma_paged_audio_buffer_data* pData, ma_uint64 pageSizeInFrames, const void* pInitialData, const ma_allocation_callbacks* pAllocationCallbacks, ma_paged_audio_buffer_page** ppPage);
+MA_API ma_result ma_paged_audio_buffer_data_free_page(ma_paged_audio_buffer_data* pData, ma_paged_audio_buffer_page* pPage, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_result ma_paged_audio_buffer_data_append_page(ma_paged_audio_buffer_data* pData, ma_paged_audio_buffer_page* pPage);
+MA_API ma_result ma_paged_audio_buffer_data_allocate_and_append_page(ma_paged_audio_buffer_data* pData, ma_uint32 pageSizeInFrames, const void* pInitialData, const ma_allocation_callbacks* pAllocationCallbacks);
+
+
+typedef struct
+{
+ ma_paged_audio_buffer_data* pData; /* Must not be null. */
+} ma_paged_audio_buffer_config;
+
+MA_API ma_paged_audio_buffer_config ma_paged_audio_buffer_config_init(ma_paged_audio_buffer_data* pData);
+
+
+typedef struct
+{
+ ma_data_source_base ds;
+ ma_paged_audio_buffer_data* pData; /* Audio data is read from here. Cannot be null. */
+ ma_paged_audio_buffer_page* pCurrent;
+ ma_uint64 relativeCursor; /* Relative to the current page. */
+ ma_uint64 absoluteCursor;
+} ma_paged_audio_buffer;
+
+MA_API ma_result ma_paged_audio_buffer_init(const ma_paged_audio_buffer_config* pConfig, ma_paged_audio_buffer* pPagedAudioBuffer);
+MA_API void ma_paged_audio_buffer_uninit(ma_paged_audio_buffer* pPagedAudioBuffer);
+MA_API ma_result ma_paged_audio_buffer_read_pcm_frames(ma_paged_audio_buffer* pPagedAudioBuffer, void* pFramesOut, ma_uint64 frameCount, ma_uint64* pFramesRead); /* Returns MA_AT_END if no more pages available. */
+MA_API ma_result ma_paged_audio_buffer_seek_to_pcm_frame(ma_paged_audio_buffer* pPagedAudioBuffer, ma_uint64 frameIndex);
+MA_API ma_result ma_paged_audio_buffer_get_cursor_in_pcm_frames(ma_paged_audio_buffer* pPagedAudioBuffer, ma_uint64* pCursor);
+MA_API ma_result ma_paged_audio_buffer_get_length_in_pcm_frames(ma_paged_audio_buffer* pPagedAudioBuffer, ma_uint64* pLength);
+
+
+
/************************************************************************************************************************************************************
Ring Buffer
@@ -5603,9 +5999,11 @@ MA_API void* ma_rb_get_subbuffer_ptr(ma_rb* pRB, size_t subbufferIndex, void* pB
typedef struct
{
+ ma_data_source_base ds;
ma_rb rb;
ma_format format;
ma_uint32 channels;
+ ma_uint32 sampleRate; /* Not required for the ring buffer itself, but useful for associating the data with some sample rate, particularly for data sources. */
} ma_pcm_rb;
MA_API ma_result ma_pcm_rb_init_ex(ma_format format, ma_uint32 channels, ma_uint32 subbufferSizeInFrames, ma_uint32 subbufferCount, ma_uint32 subbufferStrideInFrames, void* pOptionalPreallocatedBuffer, const ma_allocation_callbacks* pAllocationCallbacks, ma_pcm_rb* pRB);
@@ -5625,6 +6023,10 @@ MA_API ma_uint32 ma_pcm_rb_get_subbuffer_size(ma_pcm_rb* pRB);
MA_API ma_uint32 ma_pcm_rb_get_subbuffer_stride(ma_pcm_rb* pRB);
MA_API ma_uint32 ma_pcm_rb_get_subbuffer_offset(ma_pcm_rb* pRB, ma_uint32 subbufferIndex);
MA_API void* ma_pcm_rb_get_subbuffer_ptr(ma_pcm_rb* pRB, ma_uint32 subbufferIndex, void* pBuffer);
+MA_API ma_format ma_pcm_rb_get_format(const ma_pcm_rb* pRB);
+MA_API ma_uint32 ma_pcm_rb_get_channels(const ma_pcm_rb* pRB);
+MA_API ma_uint32 ma_pcm_rb_get_sample_rate(const ma_pcm_rb* pRB);
+MA_API void ma_pcm_rb_set_sample_rate(ma_pcm_rb* pRB, ma_uint32 sampleRate);
/*
@@ -6135,15 +6537,20 @@ This section contains the APIs for device playback and capture. Here is where yo
/* Some backends are only supported on certain platforms. */
#if defined(MA_WIN32)
#define MA_SUPPORT_WASAPI
- #if defined(MA_WIN32_DESKTOP) /* DirectSound and WinMM backends are only supported on desktops. */
+
+ #if defined(MA_WIN32_DESKTOP) /* DirectSound and WinMM backends are only supported on desktops. */
#define MA_SUPPORT_DSOUND
#define MA_SUPPORT_WINMM
- #define MA_SUPPORT_JACK /* JACK is technically supported on Windows, but I don't know how many people use it in practice... */
+
+ /* Don't enable JACK here if compiling with Cosmopolitan. It'll be enabled in the Linux section below. */
+ #if !defined(__COSMOPOLITAN__)
+ #define MA_SUPPORT_JACK /* JACK is technically supported on Windows, but I don't know how many people use it in practice... */
+ #endif
#endif
#endif
-#if defined(MA_UNIX)
+#if defined(MA_UNIX) && !defined(MA_ORBIS) && !defined(MA_PROSPERO)
#if defined(MA_LINUX)
- #if !defined(MA_ANDROID) /* ALSA is not supported on Android. */
+ #if !defined(MA_ANDROID) && !defined(__COSMOPOLITAN__) /* ALSA is not supported on Android. */
#define MA_SUPPORT_ALSA
#endif
#endif
@@ -6151,10 +6558,6 @@ This section contains the APIs for device playback and capture. Here is where yo
#define MA_SUPPORT_PULSEAUDIO
#define MA_SUPPORT_JACK
#endif
- #if defined(MA_ANDROID)
- #define MA_SUPPORT_AAUDIO
- #define MA_SUPPORT_OPENSL
- #endif
#if defined(__OpenBSD__) /* <-- Change this to "#if defined(MA_BSD)" to enable sndio on all BSD flavors. */
#define MA_SUPPORT_SNDIO /* sndio is only supported on OpenBSD for now. May be expanded later if there's demand. */
#endif
@@ -6165,6 +6568,10 @@ This section contains the APIs for device playback and capture. Here is where yo
#define MA_SUPPORT_OSS /* Only support OSS on specific platforms with known support. */
#endif
#endif
+#if defined(MA_ANDROID)
+ #define MA_SUPPORT_AAUDIO
+ #define MA_SUPPORT_OPENSL
+#endif
#if defined(MA_APPLE)
#define MA_SUPPORT_COREAUDIO
#endif
@@ -6236,6 +6643,9 @@ typedef enum
ma_device_state_stopping = 4 /* Transitioning from a started state to stopped. */
} ma_device_state;
+MA_ATOMIC_SAFE_TYPE_DECL(i32, 4, device_state)
+
+
#ifdef MA_SUPPORT_WASAPI
/* We need a IMMNotificationClient object for WASAPI. */
typedef struct
@@ -6306,7 +6716,8 @@ typedef enum
ma_device_notification_type_stopped,
ma_device_notification_type_rerouted,
ma_device_notification_type_interruption_began,
- ma_device_notification_type_interruption_ended
+ ma_device_notification_type_interruption_ended,
+ ma_device_notification_type_unlocked
} ma_device_notification_type;
typedef struct
@@ -6428,7 +6839,7 @@ DEPRECATED. Use ma_device_notification_proc instead.
The callback for when the device has been stopped.
This will be called when the device is stopped explicitly with `ma_device_stop()` and also called implicitly when the device is stopped through external forces
-such as being unplugged or an internal error occuring.
+such as being unplugged or an internal error occurring.
Parameters
@@ -6557,6 +6968,13 @@ typedef enum
ma_aaudio_input_preset_voice_performance /* AAUDIO_INPUT_PRESET_VOICE_PERFORMANCE */
} ma_aaudio_input_preset;
+typedef enum
+{
+ ma_aaudio_allow_capture_default = 0, /* Leaves the allowed capture policy unset. */
+ ma_aaudio_allow_capture_by_all, /* AAUDIO_ALLOW_CAPTURE_BY_ALL */
+ ma_aaudio_allow_capture_by_system, /* AAUDIO_ALLOW_CAPTURE_BY_SYSTEM */
+ ma_aaudio_allow_capture_by_none /* AAUDIO_ALLOW_CAPTURE_BY_NONE */
+} ma_aaudio_allowed_capture_policy;
typedef union
{
@@ -6566,7 +6984,7 @@ typedef union
typedef union
{
- wchar_t wasapi[64]; /* WASAPI uses a wchar_t string for identification. */
+ ma_wchar_win32 wasapi[64]; /* WASAPI uses a wchar_t string for identification. */
ma_uint8 dsound[16]; /* DirectSound uses a GUID for identification. */
/*UINT_PTR*/ ma_uint32 winmm; /* When creating a device, WinMM expects a Win32 UINT_PTR for device identification. In practice it's actually just a UINT. */
char alsa[256]; /* ALSA uses a name string for identification. */
@@ -6625,7 +7043,7 @@ struct ma_device_config
ma_uint32 periods;
ma_performance_profile performanceProfile;
ma_bool8 noPreSilencedOutputBuffer; /* When set to true, the contents of the output buffer passed into the data callback will be left undefined rather than initialized to silence. */
- ma_bool8 noClip; /* When set to true, the contents of the output buffer passed into the data callback will be clipped after returning. Only applies when the playback sample format is f32. */
+ ma_bool8 noClip; /* When set to true, the contents of the output buffer passed into the data callback will not be clipped after returning. Only applies when the playback sample format is f32. */
ma_bool8 noDisableDenormals; /* Do not disable denormals when firing the data callback. */
ma_bool8 noFixedSizedCallback; /* Disables strict fixed-sized data callbacks. Setting this to true will result in the period size being treated only as a hint to the backend. This is an optimization for those who don't need fixed sized callbacks. */
ma_device_data_proc dataCallback;
@@ -6684,19 +7102,22 @@ struct ma_device_config
{
ma_opensl_stream_type streamType;
ma_opensl_recording_preset recordingPreset;
+ ma_bool32 enableCompatibilityWorkarounds;
} opensl;
struct
{
ma_aaudio_usage usage;
ma_aaudio_content_type contentType;
ma_aaudio_input_preset inputPreset;
+ ma_aaudio_allowed_capture_policy allowedCapturePolicy;
ma_bool32 noAutoStartAfterReroute;
+ ma_bool32 enableCompatibilityWorkarounds;
} aaudio;
};
/*
-The callback for handling device enumeration. This is fired from `ma_context_enumerated_devices()`.
+The callback for handling device enumeration. This is fired from `ma_context_enumerate_devices()`.
Parameters
@@ -6791,7 +7212,7 @@ If the backend requires absolute flexibility with it's data delivery, it can opt
which will allow it to implement the logic that will run on the audio thread. This is much more advanced and is completely optional.
The audio thread should run data delivery logic in a loop while `ma_device_get_state() == ma_device_state_started` and no errors have been
-encounted. Do not start or stop the device here. That will be handled from outside the `onDeviceDataLoop()` callback.
+encountered. Do not start or stop the device here. That will be handled from outside the `onDeviceDataLoop()` callback.
The invocation of the `onDeviceDataLoop()` callback will be handled by miniaudio. When you start the device, miniaudio will fire this
callback. When the device is stopped, the `ma_device_get_state() == ma_device_state_started` condition will fail and the loop will be terminated
@@ -6906,7 +7327,7 @@ struct ma_context
ma_uint32 commandCount;
ma_context_command__wasapi commands[4];
ma_handle hAvrt;
- ma_proc AvSetMmThreadCharacteristicsW;
+ ma_proc AvSetMmThreadCharacteristicsA;
ma_proc AvRevertMmThreadcharacteristics;
ma_handle hMMDevapi;
ma_proc ActivateAudioInterfaceAsync;
@@ -7204,6 +7625,7 @@ struct ma_context
ma_proc AAudioStreamBuilder_setUsage;
ma_proc AAudioStreamBuilder_setContentType;
ma_proc AAudioStreamBuilder_setInputPreset;
+ ma_proc AAudioStreamBuilder_setAllowedCapturePolicy;
ma_proc AAudioStreamBuilder_openStream;
ma_proc AAudioStream_close;
ma_proc AAudioStream_getState;
@@ -7249,10 +7671,11 @@ struct ma_context
union
{
-#ifdef MA_WIN32
+#if defined(MA_WIN32)
struct
{
/*HMODULE*/ ma_handle hOle32DLL;
+ ma_proc CoInitialize;
ma_proc CoInitializeEx;
ma_proc CoUninitialize;
ma_proc CoCreateInstance;
@@ -7268,27 +7691,14 @@ struct ma_context
ma_proc RegOpenKeyExA;
ma_proc RegCloseKey;
ma_proc RegQueryValueExA;
+
+ /*HRESULT*/ long CoInitializeResult;
} win32;
#endif
#ifdef MA_POSIX
struct
{
- ma_handle pthreadSO;
- ma_proc pthread_create;
- ma_proc pthread_join;
- ma_proc pthread_mutex_init;
- ma_proc pthread_mutex_destroy;
- ma_proc pthread_mutex_lock;
- ma_proc pthread_mutex_unlock;
- ma_proc pthread_cond_init;
- ma_proc pthread_cond_destroy;
- ma_proc pthread_cond_wait;
- ma_proc pthread_cond_signal;
- ma_proc pthread_attr_init;
- ma_proc pthread_attr_destroy;
- ma_proc pthread_attr_setschedpolicy;
- ma_proc pthread_attr_getschedparam;
- ma_proc pthread_attr_setschedparam;
+ int _unused;
} posix;
#endif
int _unused;
@@ -7300,7 +7710,7 @@ struct ma_device
ma_context* pContext;
ma_device_type type;
ma_uint32 sampleRate;
- MA_ATOMIC(4, ma_device_state) state; /* The state of the device is variable and can change at any time on any thread. Must be used atomically. */
+ ma_atomic_device_state state; /* The state of the device is variable and can change at any time on any thread. Must be used atomically. */
ma_device_data_proc onData; /* Set once at initialization time and should not be changed after. */
ma_device_notification_proc onNotification; /* Set once at initialization time and should not be changed after. */
ma_stop_proc onStop; /* DEPRECATED. Use the notification callback instead. Set once at initialization time and should not be changed after. */
@@ -7316,7 +7726,7 @@ struct ma_device
ma_bool8 noClip;
ma_bool8 noDisableDenormals;
ma_bool8 noFixedSizedCallback;
- MA_ATOMIC(4, float) masterVolumeFactor; /* Linear 0..1. Can be read and written simultaneously by different threads. Must be used atomically. */
+ ma_atomic_float masterVolumeFactor; /* Linear 0..1. Can be read and written simultaneously by different threads. Must be used atomically. */
ma_duplex_rb duplexRB; /* Intermediary buffer for duplex device on asynchronous backends. */
struct
{
@@ -7404,8 +7814,8 @@ struct ma_device
void* pMappedBufferPlayback;
ma_uint32 mappedBufferPlaybackCap;
ma_uint32 mappedBufferPlaybackLen;
- MA_ATOMIC(4, ma_bool32) isStartedCapture; /* Can be read and written simultaneously across different threads. Must be used atomically, and must be 32-bit. */
- MA_ATOMIC(4, ma_bool32) isStartedPlayback; /* Can be read and written simultaneously across different threads. Must be used atomically, and must be 32-bit. */
+ ma_atomic_bool32 isStartedCapture; /* Can be read and written simultaneously across different threads. Must be used atomically, and must be 32-bit. */
+ ma_atomic_bool32 isStartedPlayback; /* Can be read and written simultaneously across different threads. Must be used atomically, and must be 32-bit. */
ma_uint32 loopbackProcessID;
ma_bool8 loopbackProcessExclude;
ma_bool8 noAutoConvertSRC; /* When set to true, disables the use of AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM. */
@@ -7416,7 +7826,8 @@ struct ma_device
ma_bool8 isDetachedPlayback;
ma_bool8 isDetachedCapture;
ma_wasapi_usage usage;
- void *hAvrtHandle;
+ void* hAvrtHandle;
+ ma_mutex rerouteLock;
} wasapi;
#endif
#ifdef MA_SUPPORT_DSOUND
@@ -7534,6 +7945,7 @@ struct ma_device
ma_aaudio_usage usage;
ma_aaudio_content_type contentType;
ma_aaudio_input_preset inputPreset;
+ ma_aaudio_allowed_capture_policy allowedCapturePolicy;
ma_bool32 noAutoStartAfterReroute;
} aaudio;
#endif
@@ -7559,8 +7971,13 @@ struct ma_device
#ifdef MA_SUPPORT_WEBAUDIO
struct
{
- int indexPlayback; /* We use a factory on the JavaScript side to manage devices and use an index for JS/C interop. */
- int indexCapture;
+ /* AudioWorklets path. */
+ /* EMSCRIPTEN_WEBAUDIO_T */ int audioContext;
+ /* EMSCRIPTEN_WEBAUDIO_T */ int audioWorklet;
+ float* pIntermediaryBuffer;
+ void* pStackBuffer;
+ ma_result initResult; /* Set to MA_BUSY while initialization is in progress. */
+ int deviceIndex; /* We store the device in a list on the JavaScript side. This is used to map our C object to the JS object. */
} webaudio;
#endif
#ifdef MA_SUPPORT_NULL
@@ -7578,7 +7995,7 @@ struct ma_device
ma_uint32 currentPeriodFramesRemainingCapture;
ma_uint64 lastProcessedFramePlayback;
ma_uint64 lastProcessedFrameCapture;
- MA_ATOMIC(4, ma_bool32) isStarted; /* Read and written by multiple threads. Must be used atomically, and must be 32-bit for compiler compatibility. */
+ ma_atomic_bool32 isStarted; /* Read and written by multiple threads. Must be used atomically, and must be 32-bit for compiler compatibility. */
} null_device;
#endif
};
@@ -8210,8 +8627,8 @@ then be set directly on the structure. Below are the members of the `ma_device_c
callback will write to every sample in the output buffer, or if you are doing your own clearing.
noClip
- When set to true, the contents of the output buffer passed into the data callback will be clipped after returning. When set to false (default), the
- contents of the output buffer are left alone after returning and it will be left up to the backend itself to decide whether or not the clip. This only
+ When set to true, the contents of the output buffer are left alone after returning and it will be left up to the backend itself to decide whether or
+ not to clip. When set to false (default), the contents of the output buffer passed into the data callback will be clipped after returning. This only
applies when the playback sample format is f32.
noDisableDenormals
@@ -8242,7 +8659,7 @@ then be set directly on the structure. Below are the members of the `ma_device_c
A pointer that will passed to callbacks in pBackendVTable.
resampling.linear.lpfOrder
- The linear resampler applies a low-pass filter as part of it's procesing for anti-aliasing. This setting controls the order of the filter. The higher
+ The linear resampler applies a low-pass filter as part of it's processing for anti-aliasing. This setting controls the order of the filter. The higher
the value, the better the quality, in general. Setting this to 0 will disable low-pass filtering altogether. The maximum value is
`MA_MAX_FILTER_ORDER`. The default value is `min(4, MA_MAX_FILTER_ORDER)`.
@@ -8724,8 +9141,6 @@ speakers or received from the microphone which can in turn result in de-syncs.
Do not call this in any callback.
-This will be called implicitly by `ma_device_uninit()`.
-
See Also
--------
@@ -9160,6 +9575,11 @@ Retrieves a friendly name for a backend.
*/
MA_API const char* ma_get_backend_name(ma_backend backend);
+/*
+Retrieves the backend enum from the given name.
+*/
+MA_API ma_result ma_get_backend_from_name(const char* pBackendName, ma_backend* pBackend);
+
/*
Determines whether or not the given backend is available by the compilation environment.
*/
@@ -9249,7 +9669,7 @@ MA_API ma_bool32 ma_is_loopback_supported(ma_backend backend);
/************************************************************************************************************************************************************
-Utiltities
+Utilities
************************************************************************************************************************************************************/
@@ -9351,196 +9771,13 @@ Helper for converting gain in decibels to a linear factor.
MA_API float ma_volume_db_to_linear(float gain);
-
-
-/**************************************************************************************************
-
-Data Source
-
-**************************************************************************************************/
-typedef void ma_data_source;
-
-#define MA_DATA_SOURCE_SELF_MANAGED_RANGE_AND_LOOP_POINT 0x00000001
-
-typedef struct
-{
- ma_result (* onRead)(ma_data_source* pDataSource, void* pFramesOut, ma_uint64 frameCount, ma_uint64* pFramesRead);
- ma_result (* onSeek)(ma_data_source* pDataSource, ma_uint64 frameIndex);
- ma_result (* onGetDataFormat)(ma_data_source* pDataSource, ma_format* pFormat, ma_uint32* pChannels, ma_uint32* pSampleRate, ma_channel* pChannelMap, size_t channelMapCap);
- ma_result (* onGetCursor)(ma_data_source* pDataSource, ma_uint64* pCursor);
- ma_result (* onGetLength)(ma_data_source* pDataSource, ma_uint64* pLength);
- ma_result (* onSetLooping)(ma_data_source* pDataSource, ma_bool32 isLooping);
- ma_uint32 flags;
-} ma_data_source_vtable;
-
-typedef ma_data_source* (* ma_data_source_get_next_proc)(ma_data_source* pDataSource);
-
-typedef struct
-{
- const ma_data_source_vtable* vtable;
-} ma_data_source_config;
-
-MA_API ma_data_source_config ma_data_source_config_init(void);
-
-
-typedef struct
-{
- const ma_data_source_vtable* vtable;
- ma_uint64 rangeBegInFrames;
- ma_uint64 rangeEndInFrames; /* Set to -1 for unranged (default). */
- ma_uint64 loopBegInFrames; /* Relative to rangeBegInFrames. */
- ma_uint64 loopEndInFrames; /* Relative to rangeBegInFrames. Set to -1 for the end of the range. */
- ma_data_source* pCurrent; /* When non-NULL, the data source being initialized will act as a proxy and will route all operations to pCurrent. Used in conjunction with pNext/onGetNext for seamless chaining. */
- ma_data_source* pNext; /* When set to NULL, onGetNext will be used. */
- ma_data_source_get_next_proc onGetNext; /* Will be used when pNext is NULL. If both are NULL, no next will be used. */
- MA_ATOMIC(4, ma_bool32) isLooping;
-} ma_data_source_base;
-
-MA_API ma_result ma_data_source_init(const ma_data_source_config* pConfig, ma_data_source* pDataSource);
-MA_API void ma_data_source_uninit(ma_data_source* pDataSource);
-MA_API ma_result ma_data_source_read_pcm_frames(ma_data_source* pDataSource, void* pFramesOut, ma_uint64 frameCount, ma_uint64* pFramesRead); /* Must support pFramesOut = NULL in which case a forward seek should be performed. */
-MA_API ma_result ma_data_source_seek_pcm_frames(ma_data_source* pDataSource, ma_uint64 frameCount, ma_uint64* pFramesSeeked); /* Can only seek forward. Equivalent to ma_data_source_read_pcm_frames(pDataSource, NULL, frameCount, &framesRead); */
-MA_API ma_result ma_data_source_seek_to_pcm_frame(ma_data_source* pDataSource, ma_uint64 frameIndex);
-MA_API ma_result ma_data_source_get_data_format(ma_data_source* pDataSource, ma_format* pFormat, ma_uint32* pChannels, ma_uint32* pSampleRate, ma_channel* pChannelMap, size_t channelMapCap);
-MA_API ma_result ma_data_source_get_cursor_in_pcm_frames(ma_data_source* pDataSource, ma_uint64* pCursor);
-MA_API ma_result ma_data_source_get_length_in_pcm_frames(ma_data_source* pDataSource, ma_uint64* pLength); /* Returns MA_NOT_IMPLEMENTED if the length is unknown or cannot be determined. Decoders can return this. */
-MA_API ma_result ma_data_source_get_cursor_in_seconds(ma_data_source* pDataSource, float* pCursor);
-MA_API ma_result ma_data_source_get_length_in_seconds(ma_data_source* pDataSource, float* pLength);
-MA_API ma_result ma_data_source_set_looping(ma_data_source* pDataSource, ma_bool32 isLooping);
-MA_API ma_bool32 ma_data_source_is_looping(const ma_data_source* pDataSource);
-MA_API ma_result ma_data_source_set_range_in_pcm_frames(ma_data_source* pDataSource, ma_uint64 rangeBegInFrames, ma_uint64 rangeEndInFrames);
-MA_API void ma_data_source_get_range_in_pcm_frames(const ma_data_source* pDataSource, ma_uint64* pRangeBegInFrames, ma_uint64* pRangeEndInFrames);
-MA_API ma_result ma_data_source_set_loop_point_in_pcm_frames(ma_data_source* pDataSource, ma_uint64 loopBegInFrames, ma_uint64 loopEndInFrames);
-MA_API void ma_data_source_get_loop_point_in_pcm_frames(const ma_data_source* pDataSource, ma_uint64* pLoopBegInFrames, ma_uint64* pLoopEndInFrames);
-MA_API ma_result ma_data_source_set_current(ma_data_source* pDataSource, ma_data_source* pCurrentDataSource);
-MA_API ma_data_source* ma_data_source_get_current(const ma_data_source* pDataSource);
-MA_API ma_result ma_data_source_set_next(ma_data_source* pDataSource, ma_data_source* pNextDataSource);
-MA_API ma_data_source* ma_data_source_get_next(const ma_data_source* pDataSource);
-MA_API ma_result ma_data_source_set_next_callback(ma_data_source* pDataSource, ma_data_source_get_next_proc onGetNext);
-MA_API ma_data_source_get_next_proc ma_data_source_get_next_callback(const ma_data_source* pDataSource);
-
-
-typedef struct
-{
- ma_data_source_base ds;
- ma_format format;
- ma_uint32 channels;
- ma_uint32 sampleRate;
- ma_uint64 cursor;
- ma_uint64 sizeInFrames;
- const void* pData;
-} ma_audio_buffer_ref;
-
-MA_API ma_result ma_audio_buffer_ref_init(ma_format format, ma_uint32 channels, const void* pData, ma_uint64 sizeInFrames, ma_audio_buffer_ref* pAudioBufferRef);
-MA_API void ma_audio_buffer_ref_uninit(ma_audio_buffer_ref* pAudioBufferRef);
-MA_API ma_result ma_audio_buffer_ref_set_data(ma_audio_buffer_ref* pAudioBufferRef, const void* pData, ma_uint64 sizeInFrames);
-MA_API ma_uint64 ma_audio_buffer_ref_read_pcm_frames(ma_audio_buffer_ref* pAudioBufferRef, void* pFramesOut, ma_uint64 frameCount, ma_bool32 loop);
-MA_API ma_result ma_audio_buffer_ref_seek_to_pcm_frame(ma_audio_buffer_ref* pAudioBufferRef, ma_uint64 frameIndex);
-MA_API ma_result ma_audio_buffer_ref_map(ma_audio_buffer_ref* pAudioBufferRef, void** ppFramesOut, ma_uint64* pFrameCount);
-MA_API ma_result ma_audio_buffer_ref_unmap(ma_audio_buffer_ref* pAudioBufferRef, ma_uint64 frameCount); /* Returns MA_AT_END if the end has been reached. This should be considered successful. */
-MA_API ma_bool32 ma_audio_buffer_ref_at_end(const ma_audio_buffer_ref* pAudioBufferRef);
-MA_API ma_result ma_audio_buffer_ref_get_cursor_in_pcm_frames(const ma_audio_buffer_ref* pAudioBufferRef, ma_uint64* pCursor);
-MA_API ma_result ma_audio_buffer_ref_get_length_in_pcm_frames(const ma_audio_buffer_ref* pAudioBufferRef, ma_uint64* pLength);
-MA_API ma_result ma_audio_buffer_ref_get_available_frames(const ma_audio_buffer_ref* pAudioBufferRef, ma_uint64* pAvailableFrames);
-
-
-
-typedef struct
-{
- ma_format format;
- ma_uint32 channels;
- ma_uint32 sampleRate;
- ma_uint64 sizeInFrames;
- const void* pData; /* If set to NULL, will allocate a block of memory for you. */
- ma_allocation_callbacks allocationCallbacks;
-} ma_audio_buffer_config;
-
-MA_API ma_audio_buffer_config ma_audio_buffer_config_init(ma_format format, ma_uint32 channels, ma_uint64 sizeInFrames, const void* pData, const ma_allocation_callbacks* pAllocationCallbacks);
-
-typedef struct
-{
- ma_audio_buffer_ref ref;
- ma_allocation_callbacks allocationCallbacks;
- ma_bool32 ownsData; /* Used to control whether or not miniaudio owns the data buffer. If set to true, pData will be freed in ma_audio_buffer_uninit(). */
- ma_uint8 _pExtraData[1]; /* For allocating a buffer with the memory located directly after the other memory of the structure. */
-} ma_audio_buffer;
-
-MA_API ma_result ma_audio_buffer_init(const ma_audio_buffer_config* pConfig, ma_audio_buffer* pAudioBuffer);
-MA_API ma_result ma_audio_buffer_init_copy(const ma_audio_buffer_config* pConfig, ma_audio_buffer* pAudioBuffer);
-MA_API ma_result ma_audio_buffer_alloc_and_init(const ma_audio_buffer_config* pConfig, ma_audio_buffer** ppAudioBuffer); /* Always copies the data. Doesn't make sense to use this otherwise. Use ma_audio_buffer_uninit_and_free() to uninit. */
-MA_API void ma_audio_buffer_uninit(ma_audio_buffer* pAudioBuffer);
-MA_API void ma_audio_buffer_uninit_and_free(ma_audio_buffer* pAudioBuffer);
-MA_API ma_uint64 ma_audio_buffer_read_pcm_frames(ma_audio_buffer* pAudioBuffer, void* pFramesOut, ma_uint64 frameCount, ma_bool32 loop);
-MA_API ma_result ma_audio_buffer_seek_to_pcm_frame(ma_audio_buffer* pAudioBuffer, ma_uint64 frameIndex);
-MA_API ma_result ma_audio_buffer_map(ma_audio_buffer* pAudioBuffer, void** ppFramesOut, ma_uint64* pFrameCount);
-MA_API ma_result ma_audio_buffer_unmap(ma_audio_buffer* pAudioBuffer, ma_uint64 frameCount); /* Returns MA_AT_END if the end has been reached. This should be considered successful. */
-MA_API ma_bool32 ma_audio_buffer_at_end(const ma_audio_buffer* pAudioBuffer);
-MA_API ma_result ma_audio_buffer_get_cursor_in_pcm_frames(const ma_audio_buffer* pAudioBuffer, ma_uint64* pCursor);
-MA_API ma_result ma_audio_buffer_get_length_in_pcm_frames(const ma_audio_buffer* pAudioBuffer, ma_uint64* pLength);
-MA_API ma_result ma_audio_buffer_get_available_frames(const ma_audio_buffer* pAudioBuffer, ma_uint64* pAvailableFrames);
-
-
/*
-Paged Audio Buffer
-==================
-A paged audio buffer is made up of a linked list of pages. It's expandable, but not shrinkable. It
-can be used for cases where audio data is streamed in asynchronously while allowing data to be read
-at the same time.
+Mixes the specified number of frames in floating point format with a volume factor.
-This is lock-free, but not 100% thread safe. You can append a page and read from the buffer across
-simultaneously across different threads, however only one thread at a time can append, and only one
-thread at a time can read and seek.
+This will run on an optimized path when the volume is equal to 1.
*/
-typedef struct ma_paged_audio_buffer_page ma_paged_audio_buffer_page;
-struct ma_paged_audio_buffer_page
-{
- MA_ATOMIC(MA_SIZEOF_PTR, ma_paged_audio_buffer_page*) pNext;
- ma_uint64 sizeInFrames;
- ma_uint8 pAudioData[1];
-};
-
-typedef struct
-{
- ma_format format;
- ma_uint32 channels;
- ma_paged_audio_buffer_page head; /* Dummy head for the lock-free algorithm. Always has a size of 0. */
- MA_ATOMIC(MA_SIZEOF_PTR, ma_paged_audio_buffer_page*) pTail; /* Never null. Initially set to &head. */
-} ma_paged_audio_buffer_data;
+MA_API ma_result ma_mix_pcm_frames_f32(float* pDst, const float* pSrc, ma_uint64 frameCount, ma_uint32 channels, float volume);
-MA_API ma_result ma_paged_audio_buffer_data_init(ma_format format, ma_uint32 channels, ma_paged_audio_buffer_data* pData);
-MA_API void ma_paged_audio_buffer_data_uninit(ma_paged_audio_buffer_data* pData, const ma_allocation_callbacks* pAllocationCallbacks);
-MA_API ma_paged_audio_buffer_page* ma_paged_audio_buffer_data_get_head(ma_paged_audio_buffer_data* pData);
-MA_API ma_paged_audio_buffer_page* ma_paged_audio_buffer_data_get_tail(ma_paged_audio_buffer_data* pData);
-MA_API ma_result ma_paged_audio_buffer_data_get_length_in_pcm_frames(ma_paged_audio_buffer_data* pData, ma_uint64* pLength);
-MA_API ma_result ma_paged_audio_buffer_data_allocate_page(ma_paged_audio_buffer_data* pData, ma_uint64 pageSizeInFrames, const void* pInitialData, const ma_allocation_callbacks* pAllocationCallbacks, ma_paged_audio_buffer_page** ppPage);
-MA_API ma_result ma_paged_audio_buffer_data_free_page(ma_paged_audio_buffer_data* pData, ma_paged_audio_buffer_page* pPage, const ma_allocation_callbacks* pAllocationCallbacks);
-MA_API ma_result ma_paged_audio_buffer_data_append_page(ma_paged_audio_buffer_data* pData, ma_paged_audio_buffer_page* pPage);
-MA_API ma_result ma_paged_audio_buffer_data_allocate_and_append_page(ma_paged_audio_buffer_data* pData, ma_uint32 pageSizeInFrames, const void* pInitialData, const ma_allocation_callbacks* pAllocationCallbacks);
-
-
-typedef struct
-{
- ma_paged_audio_buffer_data* pData; /* Must not be null. */
-} ma_paged_audio_buffer_config;
-
-MA_API ma_paged_audio_buffer_config ma_paged_audio_buffer_config_init(ma_paged_audio_buffer_data* pData);
-
-
-typedef struct
-{
- ma_data_source_base ds;
- ma_paged_audio_buffer_data* pData; /* Audio data is read from here. Cannot be null. */
- ma_paged_audio_buffer_page* pCurrent;
- ma_uint64 relativeCursor; /* Relative to the current page. */
- ma_uint64 absoluteCursor;
-} ma_paged_audio_buffer;
-
-MA_API ma_result ma_paged_audio_buffer_init(const ma_paged_audio_buffer_config* pConfig, ma_paged_audio_buffer* pPagedAudioBuffer);
-MA_API void ma_paged_audio_buffer_uninit(ma_paged_audio_buffer* pPagedAudioBuffer);
-MA_API ma_result ma_paged_audio_buffer_read_pcm_frames(ma_paged_audio_buffer* pPagedAudioBuffer, void* pFramesOut, ma_uint64 frameCount, ma_uint64* pFramesRead); /* Returns MA_AT_END if no more pages available. */
-MA_API ma_result ma_paged_audio_buffer_seek_to_pcm_frame(ma_paged_audio_buffer* pPagedAudioBuffer, ma_uint64 frameIndex);
-MA_API ma_result ma_paged_audio_buffer_get_cursor_in_pcm_frames(ma_paged_audio_buffer* pPagedAudioBuffer, ma_uint64* pCursor);
-MA_API ma_result ma_paged_audio_buffer_get_length_in_pcm_frames(ma_paged_audio_buffer* pPagedAudioBuffer, ma_uint64* pLength);
@@ -9826,7 +10063,7 @@ struct ma_encoder
ma_encoder_uninit_proc onUninit;
ma_encoder_write_pcm_frames_proc onWritePCMFrames;
void* pUserData;
- void* pInternalEncoder; /* <-- The drwav/drflac/stb_vorbis/etc. objects. */
+ void* pInternalEncoder;
union
{
struct
@@ -9891,6 +10128,33 @@ MA_API ma_result ma_waveform_set_frequency(ma_waveform* pWaveform, double freque
MA_API ma_result ma_waveform_set_type(ma_waveform* pWaveform, ma_waveform_type type);
MA_API ma_result ma_waveform_set_sample_rate(ma_waveform* pWaveform, ma_uint32 sampleRate);
+typedef struct
+{
+ ma_format format;
+ ma_uint32 channels;
+ ma_uint32 sampleRate;
+ double dutyCycle;
+ double amplitude;
+ double frequency;
+} ma_pulsewave_config;
+
+MA_API ma_pulsewave_config ma_pulsewave_config_init(ma_format format, ma_uint32 channels, ma_uint32 sampleRate, double dutyCycle, double amplitude, double frequency);
+
+typedef struct
+{
+ ma_waveform waveform;
+ ma_pulsewave_config config;
+} ma_pulsewave;
+
+MA_API ma_result ma_pulsewave_init(const ma_pulsewave_config* pConfig, ma_pulsewave* pWaveform);
+MA_API void ma_pulsewave_uninit(ma_pulsewave* pWaveform);
+MA_API ma_result ma_pulsewave_read_pcm_frames(ma_pulsewave* pWaveform, void* pFramesOut, ma_uint64 frameCount, ma_uint64* pFramesRead);
+MA_API ma_result ma_pulsewave_seek_to_pcm_frame(ma_pulsewave* pWaveform, ma_uint64 frameIndex);
+MA_API ma_result ma_pulsewave_set_amplitude(ma_pulsewave* pWaveform, double amplitude);
+MA_API ma_result ma_pulsewave_set_frequency(ma_pulsewave* pWaveform, double frequency);
+MA_API ma_result ma_pulsewave_set_sample_rate(ma_pulsewave* pWaveform, ma_uint32 sampleRate);
+MA_API ma_result ma_pulsewave_set_duty_cycle(ma_pulsewave* pWaveform, double dutyCycle);
+
typedef enum
{
ma_noise_type_white,
@@ -9913,7 +10177,7 @@ MA_API ma_noise_config ma_noise_config_init(ma_format format, ma_uint32 channels
typedef struct
{
- ma_data_source_vtable ds;
+ ma_data_source_base ds;
ma_noise_config config;
ma_lcg lcg;
union
@@ -10108,7 +10372,7 @@ struct ma_resource_manager_data_buffer
ma_bool32 seekToCursorOnNextRead; /* On the next read we need to seek to the frame cursor. */
MA_ATOMIC(4, ma_result) result; /* Keeps track of a result of decoding. Set to MA_BUSY while the buffer is still loading. Set to MA_SUCCESS when loading is finished successfully. Otherwise set to some other code. */
MA_ATOMIC(4, ma_bool32) isLooping; /* Can be read and written by different threads at the same time. Must be used atomically. */
- ma_bool32 isConnectorInitialized; /* Used for asynchronous loading to ensure we don't try to initialize the connector multiple times while waiting for the node to fully load. */
+ ma_atomic_bool32 isConnectorInitialized; /* Used for asynchronous loading to ensure we don't try to initialize the connector multiple times while waiting for the node to fully load. */
union
{
ma_decoder decoder; /* Supply type is ma_resource_manager_data_supply_type_encoded */
@@ -10166,6 +10430,7 @@ typedef struct
ma_uint32 decodedChannels; /* The decoded channel count to use. Set to 0 (default) to use the file's native channel count. */
ma_uint32 decodedSampleRate; /* the decoded sample rate to use. Set to 0 (default) to use the file's native sample rate. */
ma_uint32 jobThreadCount; /* Set to 0 if you want to self-manage your job threads. Defaults to 1. */
+ size_t jobThreadStackSize;
ma_uint32 jobQueueCapacity; /* The maximum number of jobs that can fit in the queue at a time. Defaults to MA_JOB_TYPE_RESOURCE_MANAGER_QUEUE_CAPACITY. Cannot be zero. */
ma_uint32 flags;
ma_vfs* pVFS; /* Can be NULL in which case defaults will be used. */
@@ -10310,7 +10575,7 @@ typedef struct
/*
Extended processing callback. This callback is used for effects that process input and output
at different rates (i.e. they perform resampling). This is similar to the simple version, only
- they take two seperate frame counts: one for input, and one for output.
+ they take two separate frame counts: one for input, and one for output.
On input, `pFrameCountOut` is equal to the capacity of the output buffer for each bus, whereas
`pFrameCountIn` will be equal to the number of PCM frames in each of the buffers in `ppFramesIn`.
@@ -10374,7 +10639,7 @@ struct ma_node_output_bus
ma_uint8 channels; /* The number of channels in the audio stream for this bus. */
/* Mutable via multiple threads. Must be used atomically. The weird ordering here is for packing reasons. */
- MA_ATOMIC(1, ma_uint8) inputNodeInputBusIndex; /* The index of the input bus on the input. Required for detaching. */
+ ma_uint8 inputNodeInputBusIndex; /* The index of the input bus on the input. Required for detaching. Will only be used within the spinlock so does not need to be atomic. */
MA_ATOMIC(4, ma_uint32) flags; /* Some state flags for tracking the read state of the output buffer. A combination of MA_NODE_OUTPUT_BUS_FLAG_*. */
MA_ATOMIC(4, ma_uint32) refCount; /* Reference count for some thread-safety when detaching. */
MA_ATOMIC(4, ma_bool32) isAttached; /* This is used to prevent iteration of nodes that are in the middle of being detached. Used for thread safety. */
@@ -10398,7 +10663,7 @@ struct ma_node_input_bus
MA_ATOMIC(4, ma_spinlock) lock; /* Unfortunate lock, but significantly simplifies the implementation. Required for thread-safe attaching and detaching. */
/* Set once at startup. */
- ma_uint8 channels; /* The number of channels in the audio stream for this bus. */
+ ma_uint8 channels; /* The number of channels in the audio stream for this bus. */
};
@@ -10406,7 +10671,7 @@ typedef struct ma_node_base ma_node_base;
struct ma_node_base
{
/* These variables are set once at startup. */
- ma_node_graph* pNodeGraph; /* The graph this node belongs to. */
+ ma_node_graph* pNodeGraph; /* The graph this node belongs to. */
const ma_node_vtable* vtable;
float* pCachedData; /* Allocated on the heap. Fixed size. Needs to be stored on the heap because reading from output buses is done in separate function calls. */
ma_uint16 cachedDataCapInFramesPerBus; /* The capacity of the input data cache in frames, per bus. */
@@ -10508,7 +10773,7 @@ MA_API ma_result ma_data_source_node_set_looping(ma_data_source_node* pDataSourc
MA_API ma_bool32 ma_data_source_node_is_looping(ma_data_source_node* pDataSourceNode);
-/* Splitter Node. 1 input, 2 outputs. Used for splitting/copying a stream so it can be as input into two separate output nodes. */
+/* Splitter Node. 1 input, many outputs. Used for splitting/copying a stream so it can be as input into two separate output nodes. */
typedef struct
{
ma_node_config nodeConfig;
@@ -10752,13 +11017,17 @@ typedef struct ma_sound ma_sound;
/* Sound flags. */
typedef enum
{
+ /* Resource manager flags. */
MA_SOUND_FLAG_STREAM = 0x00000001, /* MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_STREAM */
MA_SOUND_FLAG_DECODE = 0x00000002, /* MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_DECODE */
MA_SOUND_FLAG_ASYNC = 0x00000004, /* MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_ASYNC */
MA_SOUND_FLAG_WAIT_INIT = 0x00000008, /* MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_WAIT_INIT */
- MA_SOUND_FLAG_NO_DEFAULT_ATTACHMENT = 0x00000010, /* Do not attach to the endpoint by default. Useful for when setting up nodes in a complex graph system. */
- MA_SOUND_FLAG_NO_PITCH = 0x00000020, /* Disable pitch shifting with ma_sound_set_pitch() and ma_sound_group_set_pitch(). This is an optimization. */
- MA_SOUND_FLAG_NO_SPATIALIZATION = 0x00000040 /* Disable spatialization. */
+ MA_SOUND_FLAG_UNKNOWN_LENGTH = 0x00000010, /* MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_UNKNOWN_LENGTH */
+
+ /* ma_sound specific flags. */
+ MA_SOUND_FLAG_NO_DEFAULT_ATTACHMENT = 0x00001000, /* Do not attach to the endpoint by default. Useful for when setting up nodes in a complex graph system. */
+ MA_SOUND_FLAG_NO_PITCH = 0x00002000, /* Disable pitch shifting with ma_sound_set_pitch() and ma_sound_group_set_pitch(). This is an optimization. */
+ MA_SOUND_FLAG_NO_SPATIALIZATION = 0x00004000 /* Disable spatialization. */
} ma_sound_flags;
#ifndef MA_ENGINE_MAX_LISTENERS
@@ -10780,8 +11049,9 @@ typedef struct
ma_uint32 channelsIn;
ma_uint32 channelsOut;
ma_uint32 sampleRate; /* Only used when the type is set to ma_engine_node_type_sound. */
+ ma_uint32 volumeSmoothTimeInPCMFrames; /* The number of frames to smooth over volume changes. Defaults to 0 in which case no smoothing is used. */
ma_mono_expansion_mode monoExpansionMode;
- ma_bool8 isPitchDisabled; /* Pitching can be explicitly disable with MA_SOUND_FLAG_NO_PITCH to optimize processing. */
+ ma_bool8 isPitchDisabled; /* Pitching can be explicitly disabled with MA_SOUND_FLAG_NO_PITCH to optimize processing. */
ma_bool8 isSpatializationDisabled; /* Spatialization can be explicitly disabled with MA_SOUND_FLAG_NO_SPATIALIZATION. */
ma_uint8 pinnedListenerIndex; /* The index of the listener this node should always use for spatialization. If set to MA_LISTENER_INDEX_CLOSEST the engine will use the closest listener. */
} ma_engine_node_config;
@@ -10795,11 +11065,14 @@ typedef struct
ma_node_base baseNode; /* Must be the first member for compatiblity with the ma_node API. */
ma_engine* pEngine; /* A pointer to the engine. Set based on the value from the config. */
ma_uint32 sampleRate; /* The sample rate of the input data. For sounds backed by a data source, this will be the data source's sample rate. Otherwise it'll be the engine's sample rate. */
+ ma_uint32 volumeSmoothTimeInPCMFrames;
ma_mono_expansion_mode monoExpansionMode;
ma_fader fader;
ma_linear_resampler resampler; /* For pitch shift. */
ma_spatializer spatializer;
ma_panner panner;
+ ma_gainer volumeGainer; /* This will only be used if volumeSmoothTimeInPCMFrames is > 0. */
+ ma_atomic_float volume; /* Defaults to 1. */
MA_ATOMIC(4, float) pitch;
float oldPitch; /* For determining whether or not the resampler needs to be updated to reflect the new pitch. The resampler will be updated on the mixing thread. */
float oldDopplerPitch; /* For determining whether or not the resampler needs to be updated to take a new doppler pitch into account. */
@@ -10807,6 +11080,15 @@ typedef struct
MA_ATOMIC(4, ma_bool32) isSpatializationDisabled; /* Set to false by default. When set to false, will not have spatialisation applied. */
MA_ATOMIC(4, ma_uint32) pinnedListenerIndex; /* The index of the listener this node should always use for spatialization. If set to MA_LISTENER_INDEX_CLOSEST the engine will use the closest listener. */
+ /* When setting a fade, it's not done immediately in ma_sound_set_fade(). It's deferred to the audio thread which means we need to store the settings here. */
+ struct
+ {
+ ma_atomic_float volumeBeg;
+ ma_atomic_float volumeEnd;
+ ma_atomic_uint64 fadeLengthInFrames; /* <-- Defaults to (~(ma_uint64)0) which is used to indicate that no fade should be applied. */
+ ma_atomic_uint64 absoluteGlobalTimeInFrames; /* <-- The time to start the fade. */
+ } fadeSettings;
+
/* Memory management. */
ma_bool8 _ownsHeap;
void* _pHeap;
@@ -10820,6 +11102,9 @@ MA_API void ma_engine_node_uninit(ma_engine_node* pEngineNode, const ma_allocati
#define MA_SOUND_SOURCE_CHANNEL_COUNT 0xFFFFFFFF
+/* Callback for when a sound reaches the end. */
+typedef void (* ma_sound_end_proc)(void* pUserData, ma_sound* pSound);
+
typedef struct
{
const char* pFilePath; /* Set this to load from the resource manager. */
@@ -10831,13 +11116,19 @@ typedef struct
ma_uint32 channelsOut; /* Set this to 0 (default) to use the engine's channel count. Set to MA_SOUND_SOURCE_CHANNEL_COUNT to use the data source's channel count (only used if using a data source as input). */
ma_mono_expansion_mode monoExpansionMode; /* Controls how the mono channel should be expanded to other channels when spatialization is disabled on a sound. */
ma_uint32 flags; /* A combination of MA_SOUND_FLAG_* flags. */
+ ma_uint32 volumeSmoothTimeInPCMFrames; /* The number of frames to smooth over volume changes. Defaults to 0 in which case no smoothing is used. */
ma_uint64 initialSeekPointInPCMFrames; /* Initializes the sound such that it's seeked to this location by default. */
ma_uint64 rangeBegInPCMFrames;
ma_uint64 rangeEndInPCMFrames;
ma_uint64 loopPointBegInPCMFrames;
ma_uint64 loopPointEndInPCMFrames;
ma_bool32 isLooping;
- ma_fence* pDoneFence; /* Released when the resource manager has finished decoding the entire sound. Not used with streams. */
+ ma_sound_end_proc endCallback; /* Fired when the sound reaches the end. Will be fired from the audio thread. Do not restart, uninitialize or otherwise change the state of the sound from here. Instead fire an event or set a variable to indicate to a different thread to change the start of the sound. Will not be fired in response to a scheduled stop with ma_sound_set_stop_time_*(). */
+ void* pEndCallbackUserData;
+#ifndef MA_NO_RESOURCE_MANAGER
+ ma_resource_manager_pipeline_notifications initNotifications;
+#endif
+ ma_fence* pDoneFence; /* Deprecated. Use initNotifications instead. Released when the resource manager has finished decoding the entire sound. Not used with streams. */
} ma_sound_config;
MA_API ma_sound_config ma_sound_config_init(void); /* Deprecated. Will be removed in version 0.12. Use ma_sound_config_2() instead. */
@@ -10849,6 +11140,8 @@ struct ma_sound
ma_data_source* pDataSource;
MA_ATOMIC(8, ma_uint64) seekTarget; /* The PCM frame index to seek to in the mixing thread. Set to (~(ma_uint64)0) to not perform any seeking. */
MA_ATOMIC(4, ma_bool32) atEnd;
+ ma_sound_end_proc endCallback;
+ void* pEndCallbackUserData;
ma_bool8 ownsDataSource;
/*
@@ -10876,30 +11169,36 @@ typedef ma_sound ma_sound_group;
MA_API ma_sound_group_config ma_sound_group_config_init(void); /* Deprecated. Will be removed in version 0.12. Use ma_sound_config_2() instead. */
MA_API ma_sound_group_config ma_sound_group_config_init_2(ma_engine* pEngine); /* Will be renamed to ma_sound_config_init() in version 0.12. */
+typedef void (* ma_engine_process_proc)(void* pUserData, float* pFramesOut, ma_uint64 frameCount);
+
typedef struct
{
#if !defined(MA_NO_RESOURCE_MANAGER)
- ma_resource_manager* pResourceManager; /* Can be null in which case a resource manager will be created for you. */
+ ma_resource_manager* pResourceManager; /* Can be null in which case a resource manager will be created for you. */
#endif
#if !defined(MA_NO_DEVICE_IO)
ma_context* pContext;
- ma_device* pDevice; /* If set, the caller is responsible for calling ma_engine_data_callback() in the device's data callback. */
- ma_device_id* pPlaybackDeviceID; /* The ID of the playback device to use with the default listener. */
+ ma_device* pDevice; /* If set, the caller is responsible for calling ma_engine_data_callback() in the device's data callback. */
+ ma_device_id* pPlaybackDeviceID; /* The ID of the playback device to use with the default listener. */
+ ma_device_data_proc dataCallback; /* Can be null. Can be used to provide a custom device data callback. */
ma_device_notification_proc notificationCallback;
#endif
- ma_log* pLog; /* When set to NULL, will use the context's log. */
- ma_uint32 listenerCount; /* Must be between 1 and MA_ENGINE_MAX_LISTENERS. */
- ma_uint32 channels; /* The number of channels to use when mixing and spatializing. When set to 0, will use the native channel count of the device. */
- ma_uint32 sampleRate; /* The sample rate. When set to 0 will use the native channel count of the device. */
- ma_uint32 periodSizeInFrames; /* If set to something other than 0, updates will always be exactly this size. The underlying device may be a different size, but from the perspective of the mixer that won't matter.*/
- ma_uint32 periodSizeInMilliseconds; /* Used if periodSizeInFrames is unset. */
- ma_uint32 gainSmoothTimeInFrames; /* The number of frames to interpolate the gain of spatialized sounds across. If set to 0, will use gainSmoothTimeInMilliseconds. */
- ma_uint32 gainSmoothTimeInMilliseconds; /* When set to 0, gainSmoothTimeInFrames will be used. If both are set to 0, a default value will be used. */
+ ma_log* pLog; /* When set to NULL, will use the context's log. */
+ ma_uint32 listenerCount; /* Must be between 1 and MA_ENGINE_MAX_LISTENERS. */
+ ma_uint32 channels; /* The number of channels to use when mixing and spatializing. When set to 0, will use the native channel count of the device. */
+ ma_uint32 sampleRate; /* The sample rate. When set to 0 will use the native channel count of the device. */
+ ma_uint32 periodSizeInFrames; /* If set to something other than 0, updates will always be exactly this size. The underlying device may be a different size, but from the perspective of the mixer that won't matter.*/
+ ma_uint32 periodSizeInMilliseconds; /* Used if periodSizeInFrames is unset. */
+ ma_uint32 gainSmoothTimeInFrames; /* The number of frames to interpolate the gain of spatialized sounds across. If set to 0, will use gainSmoothTimeInMilliseconds. */
+ ma_uint32 gainSmoothTimeInMilliseconds; /* When set to 0, gainSmoothTimeInFrames will be used. If both are set to 0, a default value will be used. */
+ ma_uint32 defaultVolumeSmoothTimeInPCMFrames; /* Defaults to 0. Controls the default amount of smoothing to apply to volume changes to sounds. High values means more smoothing at the expense of high latency (will take longer to reach the new volume). */
ma_allocation_callbacks allocationCallbacks;
- ma_bool32 noAutoStart; /* When set to true, requires an explicit call to ma_engine_start(). This is false by default, meaning the engine will be started automatically in ma_engine_init(). */
- ma_bool32 noDevice; /* When set to true, don't create a default device. ma_engine_read_pcm_frames() can be called manually to read data. */
- ma_mono_expansion_mode monoExpansionMode; /* Controls how the mono channel should be expanded to other channels when spatialization is disabled on a sound. */
- ma_vfs* pResourceManagerVFS; /* A pointer to a pre-allocated VFS object to use with the resource manager. This is ignored if pResourceManager is not NULL. */
+ ma_bool32 noAutoStart; /* When set to true, requires an explicit call to ma_engine_start(). This is false by default, meaning the engine will be started automatically in ma_engine_init(). */
+ ma_bool32 noDevice; /* When set to true, don't create a default device. ma_engine_read_pcm_frames() can be called manually to read data. */
+ ma_mono_expansion_mode monoExpansionMode; /* Controls how the mono channel should be expanded to other channels when spatialization is disabled on a sound. */
+ ma_vfs* pResourceManagerVFS; /* A pointer to a pre-allocated VFS object to use with the resource manager. This is ignored if pResourceManager is not NULL. */
+ ma_engine_process_proc onProcess; /* Fired at the end of each call to ma_engine_read_pcm_frames(). For engine's that manage their own internal device (the default configuration), this will be fired from the audio thread, and you do not need to call ma_engine_read_pcm_frames() manually in order to trigger this. */
+ void* pProcessUserData; /* User data that's passed into onProcess. */
} ma_engine_config;
MA_API ma_engine_config ma_engine_config_init(void);
@@ -10925,7 +11224,10 @@ struct ma_engine
ma_sound_inlined* pInlinedSoundHead; /* The first inlined sound. Inlined sounds are tracked in a linked list. */
MA_ATOMIC(4, ma_uint32) inlinedSoundCount; /* The total number of allocated inlined sound objects. Used for debugging. */
ma_uint32 gainSmoothTimeInFrames; /* The number of frames to interpolate the gain of spatialized sounds across. */
+ ma_uint32 defaultVolumeSmoothTimeInPCMFrames;
ma_mono_expansion_mode monoExpansionMode;
+ ma_engine_process_proc onProcess;
+ void* pProcessUserData;
};
MA_API ma_result ma_engine_init(const ma_engine_config* pConfig, ma_engine* pEngine);
@@ -10938,15 +11240,21 @@ MA_API ma_resource_manager* ma_engine_get_resource_manager(ma_engine* pEngine);
MA_API ma_device* ma_engine_get_device(ma_engine* pEngine);
MA_API ma_log* ma_engine_get_log(ma_engine* pEngine);
MA_API ma_node* ma_engine_get_endpoint(ma_engine* pEngine);
-MA_API ma_uint64 ma_engine_get_time(const ma_engine* pEngine);
-MA_API ma_result ma_engine_set_time(ma_engine* pEngine, ma_uint64 globalTime);
+MA_API ma_uint64 ma_engine_get_time_in_pcm_frames(const ma_engine* pEngine);
+MA_API ma_uint64 ma_engine_get_time_in_milliseconds(const ma_engine* pEngine);
+MA_API ma_result ma_engine_set_time_in_pcm_frames(ma_engine* pEngine, ma_uint64 globalTime);
+MA_API ma_result ma_engine_set_time_in_milliseconds(ma_engine* pEngine, ma_uint64 globalTime);
+MA_API ma_uint64 ma_engine_get_time(const ma_engine* pEngine); /* Deprecated. Use ma_engine_get_time_in_pcm_frames(). Will be removed in version 0.12. */
+MA_API ma_result ma_engine_set_time(ma_engine* pEngine, ma_uint64 globalTime); /* Deprecated. Use ma_engine_set_time_in_pcm_frames(). Will be removed in version 0.12. */
MA_API ma_uint32 ma_engine_get_channels(const ma_engine* pEngine);
MA_API ma_uint32 ma_engine_get_sample_rate(const ma_engine* pEngine);
MA_API ma_result ma_engine_start(ma_engine* pEngine);
MA_API ma_result ma_engine_stop(ma_engine* pEngine);
MA_API ma_result ma_engine_set_volume(ma_engine* pEngine, float volume);
+MA_API float ma_engine_get_volume(ma_engine* pEngine);
MA_API ma_result ma_engine_set_gain_db(ma_engine* pEngine, float gainDB);
+MA_API float ma_engine_get_gain_db(ma_engine* pEngine);
MA_API ma_uint32 ma_engine_get_listener_count(const ma_engine* pEngine);
MA_API ma_uint32 ma_engine_find_closest_listener(const ma_engine* pEngine, float absolutePosX, float absolutePosY, float absolutePosZ);
@@ -10980,6 +11288,8 @@ MA_API ma_engine* ma_sound_get_engine(const ma_sound* pSound);
MA_API ma_data_source* ma_sound_get_data_source(const ma_sound* pSound);
MA_API ma_result ma_sound_start(ma_sound* pSound);
MA_API ma_result ma_sound_stop(ma_sound* pSound);
+MA_API ma_result ma_sound_stop_with_fade_in_pcm_frames(ma_sound* pSound, ma_uint64 fadeLengthInFrames); /* Will overwrite any scheduled stop and fade. */
+MA_API ma_result ma_sound_stop_with_fade_in_milliseconds(ma_sound* pSound, ma_uint64 fadeLengthInFrames); /* Will overwrite any scheduled stop and fade. */
MA_API void ma_sound_set_volume(ma_sound* pSound, float volume);
MA_API float ma_sound_get_volume(const ma_sound* pSound);
MA_API void ma_sound_set_pan(ma_sound* pSound, float pan);
@@ -11022,13 +11332,18 @@ MA_API void ma_sound_set_directional_attenuation_factor(ma_sound* pSound, float
MA_API float ma_sound_get_directional_attenuation_factor(const ma_sound* pSound);
MA_API void ma_sound_set_fade_in_pcm_frames(ma_sound* pSound, float volumeBeg, float volumeEnd, ma_uint64 fadeLengthInFrames);
MA_API void ma_sound_set_fade_in_milliseconds(ma_sound* pSound, float volumeBeg, float volumeEnd, ma_uint64 fadeLengthInMilliseconds);
-MA_API float ma_sound_get_current_fade_volume(ma_sound* pSound);
+MA_API void ma_sound_set_fade_start_in_pcm_frames(ma_sound* pSound, float volumeBeg, float volumeEnd, ma_uint64 fadeLengthInFrames, ma_uint64 absoluteGlobalTimeInFrames);
+MA_API void ma_sound_set_fade_start_in_milliseconds(ma_sound* pSound, float volumeBeg, float volumeEnd, ma_uint64 fadeLengthInMilliseconds, ma_uint64 absoluteGlobalTimeInMilliseconds);
+MA_API float ma_sound_get_current_fade_volume(const ma_sound* pSound);
MA_API void ma_sound_set_start_time_in_pcm_frames(ma_sound* pSound, ma_uint64 absoluteGlobalTimeInFrames);
MA_API void ma_sound_set_start_time_in_milliseconds(ma_sound* pSound, ma_uint64 absoluteGlobalTimeInMilliseconds);
MA_API void ma_sound_set_stop_time_in_pcm_frames(ma_sound* pSound, ma_uint64 absoluteGlobalTimeInFrames);
MA_API void ma_sound_set_stop_time_in_milliseconds(ma_sound* pSound, ma_uint64 absoluteGlobalTimeInMilliseconds);
+MA_API void ma_sound_set_stop_time_with_fade_in_pcm_frames(ma_sound* pSound, ma_uint64 stopAbsoluteGlobalTimeInFrames, ma_uint64 fadeLengthInFrames);
+MA_API void ma_sound_set_stop_time_with_fade_in_milliseconds(ma_sound* pSound, ma_uint64 stopAbsoluteGlobalTimeInMilliseconds, ma_uint64 fadeLengthInMilliseconds);
MA_API ma_bool32 ma_sound_is_playing(const ma_sound* pSound);
MA_API ma_uint64 ma_sound_get_time_in_pcm_frames(const ma_sound* pSound);
+MA_API ma_uint64 ma_sound_get_time_in_milliseconds(const ma_sound* pSound);
MA_API void ma_sound_set_looping(ma_sound* pSound, ma_bool32 isLooping);
MA_API ma_bool32 ma_sound_is_looping(const ma_sound* pSound);
MA_API ma_bool32 ma_sound_at_end(const ma_sound* pSound);
@@ -11038,6 +11353,7 @@ MA_API ma_result ma_sound_get_cursor_in_pcm_frames(ma_sound* pSound, ma_uint64*
MA_API ma_result ma_sound_get_length_in_pcm_frames(ma_sound* pSound, ma_uint64* pLength);
MA_API ma_result ma_sound_get_cursor_in_seconds(ma_sound* pSound, float* pCursor);
MA_API ma_result ma_sound_get_length_in_seconds(ma_sound* pSound, float* pLength);
+MA_API ma_result ma_sound_set_end_callback(ma_sound* pSound, ma_sound_end_proc callback, void* pUserData);
MA_API ma_result ma_sound_group_init(ma_engine* pEngine, ma_uint32 flags, ma_sound_group* pParentGroup, ma_sound_group* pGroup);
MA_API ma_result ma_sound_group_init_ex(ma_engine* pEngine, const ma_sound_group_config* pConfig, ma_sound_group* pGroup);
@@ -11122,8 +11438,10 @@ IMPLEMENTATION
#define miniaudio_c
#include
-#include /* For INT_MAX */
-#include /* sin(), etc. */
+#include /* For INT_MAX */
+#include /* sin(), etc. */
+#include /* For malloc(), free(), wcstombs(). */
+#include /* For memset() */
#include
#include
@@ -11135,22 +11453,43 @@ IMPLEMENTATION
#include /* For _controlfp_s constants */
#endif
-#ifdef MA_WIN32
-#include
-#else
-#include /* For malloc(), free(), wcstombs(). */
-#include /* For memset() */
+#if defined(MA_WIN32)
+ #include
+
+ /*
+ There's a possibility that WIN32_LEAN_AND_MEAN has been defined which will exclude some symbols
+ such as STGM_READ and CLSCTL_ALL. We need to check these and define them ourselves if they're
+ unavailable.
+ */
+ #ifndef STGM_READ
+ #define STGM_READ 0x00000000L
+ #endif
+ #ifndef CLSCTX_ALL
+ #define CLSCTX_ALL 23
+ #endif
+
+ /* IUnknown is used by both the WASAPI and DirectSound backends. It easier to just declare our version here. */
+ typedef struct ma_IUnknown ma_IUnknown;
+#endif
+
+#if !defined(MA_WIN32)
#include
#include /* select() (used for ma_sleep()). */
#include
#endif
+#ifdef MA_NX
+#include /* For nanosleep() */
+#endif
+
#include /* For fstat(), etc. */
#ifdef MA_EMSCRIPTEN
#include
#endif
+
+/* Architecture Detection */
#if !defined(MA_64BIT) && !defined(MA_32BIT)
#ifdef _WIN32
#ifdef _WIN64
@@ -11180,17 +11519,23 @@ IMPLEMENTATION
#endif
#endif
-/* Architecture Detection */
+#if defined(__arm__) || defined(_M_ARM)
+#define MA_ARM32
+#endif
+#if defined(__arm64) || defined(__arm64__) || defined(__aarch64__) || defined(_M_ARM64)
+#define MA_ARM64
+#endif
+
#if defined(__x86_64__) || defined(_M_X64)
#define MA_X64
#elif defined(__i386) || defined(_M_IX86)
#define MA_X86
-#elif defined(__arm__) || defined(_M_ARM) || defined(__arm64) || defined(__arm64__) || defined(__aarch64__) || defined(_M_ARM64)
+#elif defined(MA_ARM32) || defined(MA_ARM64)
#define MA_ARM
#endif
/* Intrinsics Support */
-#if defined(MA_X64) || defined(MA_X86)
+#if (defined(MA_X64) || defined(MA_X86)) && !defined(__COSMOPOLITAN__)
#if defined(_MSC_VER) && !defined(__clang__)
/* MSVC. */
#if _MSC_VER >= 1400 && !defined(MA_NO_SSE2) /* 2005 */
@@ -11279,7 +11624,7 @@ IMPLEMENTATION
What's basically happening is that we're saving and restoring the ebx register manually.
*/
- #if defined(DRFLAC_X86) && defined(__PIC__)
+ #if defined(MA_X86) && defined(__PIC__)
__asm__ __volatile__ (
"xchg{l} {%%}ebx, %k1;"
"cpuid;"
@@ -11426,23 +11771,6 @@ static MA_INLINE ma_bool32 ma_has_neon(void)
#endif
}
-#define MA_SIMD_NONE 0
-#define MA_SIMD_SSE2 1
-#define MA_SIMD_AVX2 2
-#define MA_SIMD_NEON 3
-
-#ifndef MA_PREFERRED_SIMD
- # if defined(MA_SUPPORT_SSE2) && defined(MA_PREFER_SSE2)
- #define MA_PREFERRED_SIMD MA_SIMD_SSE2
- #elif defined(MA_SUPPORT_AVX2) && defined(MA_PREFER_AVX2)
- #define MA_PREFERRED_SIMD MA_SIMD_AVX2
- #elif defined(MA_SUPPORT_NEON) && defined(MA_PREFER_NEON)
- #define MA_PREFERRED_SIMD MA_SIMD_NEON
- #else
- #define MA_PREFERRED_SIMD MA_SIMD_NONE
- #endif
-#endif
-
#if defined(__has_builtin)
#define MA_COMPILER_HAS_BUILTIN(x) __has_builtin(x)
#else
@@ -11556,7 +11884,7 @@ static void ma_sleep__posix(ma_uint32 milliseconds)
(void)milliseconds;
MA_ASSERT(MA_FALSE); /* The Emscripten build should never sleep. */
#else
- #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309L
+ #if (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309L) || defined(MA_NX)
struct timespec ts;
ts.tv_sec = milliseconds / 1000;
ts.tv_nsec = milliseconds % 1000 * 1000000;
@@ -11582,7 +11910,7 @@ static MA_INLINE void ma_sleep(ma_uint32 milliseconds)
}
#endif
-static MA_INLINE void ma_yield()
+static MA_INLINE void ma_yield(void)
{
#if defined(__i386) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64)
/* x86/x64 */
@@ -11617,7 +11945,7 @@ static MA_INLINE void ma_yield()
#define MA_MM_DENORMALS_ZERO_MASK 0x0040
#define MA_MM_FLUSH_ZERO_MASK 0x8000
-static MA_INLINE unsigned int ma_disable_denormals()
+static MA_INLINE unsigned int ma_disable_denormals(void)
{
unsigned int prevState;
@@ -11644,7 +11972,7 @@ static MA_INLINE unsigned int ma_disable_denormals()
}
#elif defined(MA_X86) || defined(MA_X64)
{
- #if defined(__SSE2__) && !(defined(__TINYC__) || defined(__WATCOMC__)) /* <-- Add compilers that lack support for _mm_getcsr() and _mm_setcsr() to this list. */
+ #if defined(__SSE2__) && !(defined(__TINYC__) || defined(__WATCOMC__) || defined(__COSMOPOLITAN__)) /* <-- Add compilers that lack support for _mm_getcsr() and _mm_setcsr() to this list. */
{
prevState = _mm_getcsr();
_mm_setcsr(prevState | MA_MM_DENORMALS_ZERO_MASK | MA_MM_FLUSH_ZERO_MASK);
@@ -11684,7 +12012,7 @@ static MA_INLINE void ma_restore_denormals(unsigned int prevState)
}
#elif defined(MA_X86) || defined(MA_X64)
{
- #if defined(__SSE2__) && !(defined(__TINYC__) || defined(__WATCOMC__)) /* <-- Add compilers that lack support for _mm_getcsr() and _mm_setcsr() to this list. */
+ #if defined(__SSE2__) && !(defined(__TINYC__) || defined(__WATCOMC__) || defined(__COSMOPOLITAN__)) /* <-- Add compilers that lack support for _mm_getcsr() and _mm_setcsr() to this list. */
{
_mm_setcsr(prevState);
}
@@ -11704,6 +12032,20 @@ static MA_INLINE void ma_restore_denormals(unsigned int prevState)
}
+#ifdef MA_ANDROID
+#include
+
+int ma_android_sdk_version()
+{
+ char sdkVersion[PROP_VALUE_MAX + 1] = {0, };
+ if (__system_property_get("ro.build.version.sdk", sdkVersion)) {
+ return atoi(sdkVersion);
+ }
+
+ return 0;
+}
+#endif
+
#ifndef MA_COINIT_VALUE
#define MA_COINIT_VALUE 0 /* 0 = COINIT_MULTITHREADED */
@@ -11857,79 +12199,53 @@ MA_API const char* ma_version_string(void)
Standard Library Stuff
******************************************************************************/
-#ifndef MA_MALLOC
-#ifdef MA_WIN32
-#define MA_MALLOC(sz) HeapAlloc(GetProcessHeap(), 0, (sz))
-#else
-#define MA_MALLOC(sz) malloc((sz))
-#endif
+#ifndef MA_ASSERT
+#define MA_ASSERT(condition) assert(condition)
#endif
-#ifndef MA_REALLOC
-#ifdef MA_WIN32
-#define MA_REALLOC(p, sz) (((sz) > 0) ? ((p) ? HeapReAlloc(GetProcessHeap(), 0, (p), (sz)) : HeapAlloc(GetProcessHeap(), 0, (sz))) : ((VOID*)(size_t)(HeapFree(GetProcessHeap(), 0, (p)) & 0)))
-#else
-#define MA_REALLOC(p, sz) realloc((p), (sz))
+#ifndef MA_MALLOC
+#define MA_MALLOC(sz) malloc((sz))
#endif
+#ifndef MA_REALLOC
+#define MA_REALLOC(p, sz) realloc((p), (sz))
#endif
-
#ifndef MA_FREE
-#ifdef MA_WIN32
-#define MA_FREE(p) HeapFree(GetProcessHeap(), 0, (p))
-#else
-#define MA_FREE(p) free((p))
-#endif
+#define MA_FREE(p) free((p))
#endif
static MA_INLINE void ma_zero_memory_default(void* p, size_t sz)
{
-#ifdef MA_WIN32
- ZeroMemory(p, sz);
-#else
+ if (p == NULL) {
+ MA_ASSERT(sz == 0); /* If this is triggered there's an error with the calling code. */
+ return;
+ }
+
if (sz > 0) {
memset(p, 0, sz);
}
-#endif
}
+
#ifndef MA_ZERO_MEMORY
-#define MA_ZERO_MEMORY(p, sz) ma_zero_memory_default((p), (sz))
+#define MA_ZERO_MEMORY(p, sz) ma_zero_memory_default((p), (sz))
#endif
-
#ifndef MA_COPY_MEMORY
-#ifdef MA_WIN32
-#define MA_COPY_MEMORY(dst, src, sz) CopyMemory((dst), (src), (sz))
-#else
-#define MA_COPY_MEMORY(dst, src, sz) memcpy((dst), (src), (sz))
-#endif
+#define MA_COPY_MEMORY(dst, src, sz) memcpy((dst), (src), (sz))
#endif
-
#ifndef MA_MOVE_MEMORY
-#ifdef MA_WIN32
-#define MA_MOVE_MEMORY(dst, src, sz) MoveMemory((dst), (src), (sz))
-#else
-#define MA_MOVE_MEMORY(dst, src, sz) memmove((dst), (src), (sz))
-#endif
-#endif
-
-#ifndef MA_ASSERT
-#ifdef MA_WIN32
-#define MA_ASSERT(condition) assert(condition)
-#else
-#define MA_ASSERT(condition) assert(condition)
-#endif
+#define MA_MOVE_MEMORY(dst, src, sz) memmove((dst), (src), (sz))
#endif
-#define MA_ZERO_OBJECT(p) MA_ZERO_MEMORY((p), sizeof(*(p)))
+#define MA_ZERO_OBJECT(p) MA_ZERO_MEMORY((p), sizeof(*(p)))
-#define ma_countof(x) (sizeof(x) / sizeof(x[0]))
-#define ma_max(x, y) (((x) > (y)) ? (x) : (y))
-#define ma_min(x, y) (((x) < (y)) ? (x) : (y))
-#define ma_abs(x) (((x) > 0) ? (x) : -(x))
-#define ma_clamp(x, lo, hi) (ma_max(lo, ma_min(x, hi)))
-#define ma_offset_ptr(p, offset) (((ma_uint8*)(p)) + (offset))
-#define ma_align(x, a) ((x + (a-1)) & ~(a-1))
-#define ma_align_64(x) ma_align(x, 8)
+#define ma_countof(x) (sizeof(x) / sizeof(x[0]))
+#define ma_max(x, y) (((x) > (y)) ? (x) : (y))
+#define ma_min(x, y) (((x) < (y)) ? (x) : (y))
+#define ma_abs(x) (((x) > 0) ? (x) : -(x))
+#define ma_clamp(x, lo, hi) (ma_max(lo, ma_min(x, hi)))
+#define ma_offset_ptr(p, offset) (((ma_uint8*)(p)) + (offset))
+#define ma_align(x, a) (((x) + ((a)-1)) & ~((a)-1))
+#define ma_align_64(x) ma_align(x, 8)
#define ma_buffer_frame_capacity(buffer, channels, format) (sizeof(buffer) / ma_get_bytes_per_sample(format) / (channels))
@@ -11964,6 +12280,40 @@ static MA_INLINE double ma_sqrtd(double x)
}
+static MA_INLINE float ma_rsqrtf(float x)
+{
+ #if defined(MA_SUPPORT_SSE2) && !defined(MA_NO_SSE2) && (defined(MA_X64) || (defined(_M_IX86_FP) && _M_IX86_FP == 2) || defined(__SSE2__))
+ {
+ /*
+ For SSE we can use RSQRTSS.
+
+ This Stack Overflow post suggests that compilers don't necessarily generate optimal code
+ when using intrinsics:
+
+ https://web.archive.org/web/20221211012522/https://stackoverflow.com/questions/32687079/getting-fewest-instructions-for-rsqrtss-wrapper
+
+ I'm going to do something similar here, but a bit simpler.
+ */
+ #if defined(__GNUC__) || defined(__clang__)
+ {
+ float result;
+ __asm__ __volatile__("rsqrtss %1, %0" : "=x"(result) : "x"(x));
+ return result;
+ }
+ #else
+ {
+ return _mm_cvtss_f32(_mm_rsqrt_ss(_mm_set_ps1(x)));
+ }
+ #endif
+ }
+ #else
+ {
+ return 1 / (float)ma_sqrtd(x);
+ }
+ #endif
+}
+
+
static MA_INLINE float ma_sinf(float x)
{
return (float)ma_sind((float)x);
@@ -12023,8 +12373,11 @@ Return Values:
34: ERANGE
Not using symbolic constants for errors because I want to avoid #including errno.h
+
+These are marked as no-inline because of some bad code generation by Clang. None of these functions
+are used in any performance-critical code within miniaudio.
*/
-MA_API int ma_strcpy_s(char* dst, size_t dstSizeInBytes, const char* src)
+MA_API MA_NO_INLINE int ma_strcpy_s(char* dst, size_t dstSizeInBytes, const char* src)
{
size_t i;
@@ -12052,7 +12405,7 @@ MA_API int ma_strcpy_s(char* dst, size_t dstSizeInBytes, const char* src)
return 34;
}
-MA_API int ma_wcscpy_s(wchar_t* dst, size_t dstCap, const wchar_t* src)
+MA_API MA_NO_INLINE int ma_wcscpy_s(wchar_t* dst, size_t dstCap, const wchar_t* src)
{
size_t i;
@@ -12081,7 +12434,7 @@ MA_API int ma_wcscpy_s(wchar_t* dst, size_t dstCap, const wchar_t* src)
}
-MA_API int ma_strncpy_s(char* dst, size_t dstSizeInBytes, const char* src, size_t count)
+MA_API MA_NO_INLINE int ma_strncpy_s(char* dst, size_t dstSizeInBytes, const char* src, size_t count)
{
size_t maxcount;
size_t i;
@@ -12115,7 +12468,7 @@ MA_API int ma_strncpy_s(char* dst, size_t dstSizeInBytes, const char* src, size_
return 34;
}
-MA_API int ma_strcat_s(char* dst, size_t dstSizeInBytes, const char* src)
+MA_API MA_NO_INLINE int ma_strcat_s(char* dst, size_t dstSizeInBytes, const char* src)
{
char* dstorig;
@@ -12157,7 +12510,7 @@ MA_API int ma_strcat_s(char* dst, size_t dstSizeInBytes, const char* src)
return 0;
}
-MA_API int ma_strncat_s(char* dst, size_t dstSizeInBytes, const char* src, size_t count)
+MA_API MA_NO_INLINE int ma_strncat_s(char* dst, size_t dstSizeInBytes, const char* src, size_t count)
{
char* dstorig;
@@ -12203,7 +12556,7 @@ MA_API int ma_strncat_s(char* dst, size_t dstSizeInBytes, const char* src, size_
return 0;
}
-MA_API int ma_itoa_s(int value, char* dst, size_t dstSizeInBytes, int radix)
+MA_API MA_NO_INLINE int ma_itoa_s(int value, char* dst, size_t dstSizeInBytes, int radix)
{
int sign;
unsigned int valueU;
@@ -12272,7 +12625,7 @@ MA_API int ma_itoa_s(int value, char* dst, size_t dstSizeInBytes, int radix)
return 0;
}
-MA_API int ma_strcmp(const char* str1, const char* str2)
+MA_API MA_NO_INLINE int ma_strcmp(const char* str1, const char* str2)
{
if (str1 == str2) return 0;
@@ -12295,7 +12648,7 @@ MA_API int ma_strcmp(const char* str1, const char* str2)
return ((unsigned char*)str1)[0] - ((unsigned char*)str2)[0];
}
-MA_API int ma_strappend(char* dst, size_t dstSize, const char* srcA, const char* srcB)
+MA_API MA_NO_INLINE int ma_strappend(char* dst, size_t dstSize, const char* srcA, const char* srcB)
{
int result;
@@ -12312,7 +12665,7 @@ MA_API int ma_strappend(char* dst, size_t dstSize, const char* srcA, const char*
return result;
}
-MA_API char* ma_copy_string(const char* src, const ma_allocation_callbacks* pAllocationCallbacks)
+MA_API MA_NO_INLINE char* ma_copy_string(const char* src, const ma_allocation_callbacks* pAllocationCallbacks)
{
size_t sz;
char* dst;
@@ -12332,7 +12685,7 @@ MA_API char* ma_copy_string(const char* src, const ma_allocation_callbacks* pAll
return dst;
}
-MA_API wchar_t* ma_copy_string_w(const wchar_t* src, const ma_allocation_callbacks* pAllocationCallbacks)
+MA_API MA_NO_INLINE wchar_t* ma_copy_string_w(const wchar_t* src, const ma_allocation_callbacks* pAllocationCallbacks)
{
size_t sz = wcslen(src)+1;
wchar_t* dst = (wchar_t*)ma_malloc(sz * sizeof(*dst), pAllocationCallbacks);
@@ -12346,406 +12699,408 @@ MA_API wchar_t* ma_copy_string_w(const wchar_t* src, const ma_allocation_callbac
}
+
#include
static ma_result ma_result_from_errno(int e)
{
- switch (e)
- {
- case 0: return MA_SUCCESS;
- #ifdef EPERM
- case EPERM: return MA_INVALID_OPERATION;
- #endif
- #ifdef ENOENT
- case ENOENT: return MA_DOES_NOT_EXIST;
- #endif
- #ifdef ESRCH
- case ESRCH: return MA_DOES_NOT_EXIST;
- #endif
- #ifdef EINTR
- case EINTR: return MA_INTERRUPT;
- #endif
- #ifdef EIO
- case EIO: return MA_IO_ERROR;
- #endif
- #ifdef ENXIO
- case ENXIO: return MA_DOES_NOT_EXIST;
- #endif
- #ifdef E2BIG
- case E2BIG: return MA_INVALID_ARGS;
- #endif
- #ifdef ENOEXEC
- case ENOEXEC: return MA_INVALID_FILE;
- #endif
- #ifdef EBADF
- case EBADF: return MA_INVALID_FILE;
- #endif
- #ifdef ECHILD
- case ECHILD: return MA_ERROR;
- #endif
- #ifdef EAGAIN
- case EAGAIN: return MA_UNAVAILABLE;
- #endif
- #ifdef ENOMEM
- case ENOMEM: return MA_OUT_OF_MEMORY;
- #endif
- #ifdef EACCES
- case EACCES: return MA_ACCESS_DENIED;
- #endif
- #ifdef EFAULT
- case EFAULT: return MA_BAD_ADDRESS;
- #endif
- #ifdef ENOTBLK
- case ENOTBLK: return MA_ERROR;
- #endif
- #ifdef EBUSY
- case EBUSY: return MA_BUSY;
- #endif
- #ifdef EEXIST
- case EEXIST: return MA_ALREADY_EXISTS;
- #endif
- #ifdef EXDEV
- case EXDEV: return MA_ERROR;
- #endif
- #ifdef ENODEV
- case ENODEV: return MA_DOES_NOT_EXIST;
- #endif
- #ifdef ENOTDIR
- case ENOTDIR: return MA_NOT_DIRECTORY;
- #endif
- #ifdef EISDIR
- case EISDIR: return MA_IS_DIRECTORY;
- #endif
- #ifdef EINVAL
- case EINVAL: return MA_INVALID_ARGS;
- #endif
- #ifdef ENFILE
- case ENFILE: return MA_TOO_MANY_OPEN_FILES;
- #endif
- #ifdef EMFILE
- case EMFILE: return MA_TOO_MANY_OPEN_FILES;
- #endif
- #ifdef ENOTTY
- case ENOTTY: return MA_INVALID_OPERATION;
- #endif
- #ifdef ETXTBSY
- case ETXTBSY: return MA_BUSY;
- #endif
- #ifdef EFBIG
- case EFBIG: return MA_TOO_BIG;
- #endif
- #ifdef ENOSPC
- case ENOSPC: return MA_NO_SPACE;
- #endif
- #ifdef ESPIPE
- case ESPIPE: return MA_BAD_SEEK;
- #endif
- #ifdef EROFS
- case EROFS: return MA_ACCESS_DENIED;
- #endif
- #ifdef EMLINK
- case EMLINK: return MA_TOO_MANY_LINKS;
- #endif
- #ifdef EPIPE
- case EPIPE: return MA_BAD_PIPE;
- #endif
- #ifdef EDOM
- case EDOM: return MA_OUT_OF_RANGE;
- #endif
- #ifdef ERANGE
- case ERANGE: return MA_OUT_OF_RANGE;
- #endif
- #ifdef EDEADLK
- case EDEADLK: return MA_DEADLOCK;
- #endif
- #ifdef ENAMETOOLONG
- case ENAMETOOLONG: return MA_PATH_TOO_LONG;
- #endif
- #ifdef ENOLCK
- case ENOLCK: return MA_ERROR;
- #endif
- #ifdef ENOSYS
- case ENOSYS: return MA_NOT_IMPLEMENTED;
- #endif
- #ifdef ENOTEMPTY
- case ENOTEMPTY: return MA_DIRECTORY_NOT_EMPTY;
- #endif
- #ifdef ELOOP
- case ELOOP: return MA_TOO_MANY_LINKS;
- #endif
- #ifdef ENOMSG
- case ENOMSG: return MA_NO_MESSAGE;
- #endif
- #ifdef EIDRM
- case EIDRM: return MA_ERROR;
- #endif
- #ifdef ECHRNG
- case ECHRNG: return MA_ERROR;
- #endif
- #ifdef EL2NSYNC
- case EL2NSYNC: return MA_ERROR;
- #endif
- #ifdef EL3HLT
- case EL3HLT: return MA_ERROR;
- #endif
- #ifdef EL3RST
- case EL3RST: return MA_ERROR;
- #endif
- #ifdef ELNRNG
- case ELNRNG: return MA_OUT_OF_RANGE;
- #endif
- #ifdef EUNATCH
- case EUNATCH: return MA_ERROR;
- #endif
- #ifdef ENOCSI
- case ENOCSI: return MA_ERROR;
- #endif
- #ifdef EL2HLT
- case EL2HLT: return MA_ERROR;
- #endif
- #ifdef EBADE
- case EBADE: return MA_ERROR;
- #endif
- #ifdef EBADR
- case EBADR: return MA_ERROR;
- #endif
- #ifdef EXFULL
- case EXFULL: return MA_ERROR;
- #endif
- #ifdef ENOANO
- case ENOANO: return MA_ERROR;
- #endif
- #ifdef EBADRQC
- case EBADRQC: return MA_ERROR;
- #endif
- #ifdef EBADSLT
- case EBADSLT: return MA_ERROR;
- #endif
- #ifdef EBFONT
- case EBFONT: return MA_INVALID_FILE;
- #endif
- #ifdef ENOSTR
- case ENOSTR: return MA_ERROR;
- #endif
- #ifdef ENODATA
- case ENODATA: return MA_NO_DATA_AVAILABLE;
- #endif
- #ifdef ETIME
- case ETIME: return MA_TIMEOUT;
- #endif
- #ifdef ENOSR
- case ENOSR: return MA_NO_DATA_AVAILABLE;
- #endif
- #ifdef ENONET
- case ENONET: return MA_NO_NETWORK;
- #endif
- #ifdef ENOPKG
- case ENOPKG: return MA_ERROR;
- #endif
- #ifdef EREMOTE
- case EREMOTE: return MA_ERROR;
- #endif
- #ifdef ENOLINK
- case ENOLINK: return MA_ERROR;
- #endif
- #ifdef EADV
- case EADV: return MA_ERROR;
- #endif
- #ifdef ESRMNT
- case ESRMNT: return MA_ERROR;
- #endif
- #ifdef ECOMM
- case ECOMM: return MA_ERROR;
- #endif
- #ifdef EPROTO
- case EPROTO: return MA_ERROR;
- #endif
- #ifdef EMULTIHOP
- case EMULTIHOP: return MA_ERROR;
- #endif
- #ifdef EDOTDOT
- case EDOTDOT: return MA_ERROR;
- #endif
- #ifdef EBADMSG
- case EBADMSG: return MA_BAD_MESSAGE;
- #endif
- #ifdef EOVERFLOW
- case EOVERFLOW: return MA_TOO_BIG;
- #endif
- #ifdef ENOTUNIQ
- case ENOTUNIQ: return MA_NOT_UNIQUE;
- #endif
- #ifdef EBADFD
- case EBADFD: return MA_ERROR;
- #endif
- #ifdef EREMCHG
- case EREMCHG: return MA_ERROR;
- #endif
- #ifdef ELIBACC
- case ELIBACC: return MA_ACCESS_DENIED;
- #endif
- #ifdef ELIBBAD
- case ELIBBAD: return MA_INVALID_FILE;
- #endif
- #ifdef ELIBSCN
- case ELIBSCN: return MA_INVALID_FILE;
- #endif
- #ifdef ELIBMAX
- case ELIBMAX: return MA_ERROR;
- #endif
- #ifdef ELIBEXEC
- case ELIBEXEC: return MA_ERROR;
- #endif
- #ifdef EILSEQ
- case EILSEQ: return MA_INVALID_DATA;
- #endif
- #ifdef ERESTART
- case ERESTART: return MA_ERROR;
- #endif
- #ifdef ESTRPIPE
- case ESTRPIPE: return MA_ERROR;
- #endif
- #ifdef EUSERS
- case EUSERS: return MA_ERROR;
- #endif
- #ifdef ENOTSOCK
- case ENOTSOCK: return MA_NOT_SOCKET;
- #endif
- #ifdef EDESTADDRREQ
- case EDESTADDRREQ: return MA_NO_ADDRESS;
- #endif
- #ifdef EMSGSIZE
- case EMSGSIZE: return MA_TOO_BIG;
- #endif
- #ifdef EPROTOTYPE
- case EPROTOTYPE: return MA_BAD_PROTOCOL;
- #endif
- #ifdef ENOPROTOOPT
- case ENOPROTOOPT: return MA_PROTOCOL_UNAVAILABLE;
- #endif
- #ifdef EPROTONOSUPPORT
- case EPROTONOSUPPORT: return MA_PROTOCOL_NOT_SUPPORTED;
- #endif
- #ifdef ESOCKTNOSUPPORT
- case ESOCKTNOSUPPORT: return MA_SOCKET_NOT_SUPPORTED;
- #endif
- #ifdef EOPNOTSUPP
- case EOPNOTSUPP: return MA_INVALID_OPERATION;
- #endif
- #ifdef EPFNOSUPPORT
- case EPFNOSUPPORT: return MA_PROTOCOL_FAMILY_NOT_SUPPORTED;
- #endif
- #ifdef EAFNOSUPPORT
- case EAFNOSUPPORT: return MA_ADDRESS_FAMILY_NOT_SUPPORTED;
- #endif
- #ifdef EADDRINUSE
- case EADDRINUSE: return MA_ALREADY_IN_USE;
- #endif
- #ifdef EADDRNOTAVAIL
- case EADDRNOTAVAIL: return MA_ERROR;
- #endif
- #ifdef ENETDOWN
- case ENETDOWN: return MA_NO_NETWORK;
- #endif
- #ifdef ENETUNREACH
- case ENETUNREACH: return MA_NO_NETWORK;
- #endif
- #ifdef ENETRESET
- case ENETRESET: return MA_NO_NETWORK;
- #endif
- #ifdef ECONNABORTED
- case ECONNABORTED: return MA_NO_NETWORK;
- #endif
- #ifdef ECONNRESET
- case ECONNRESET: return MA_CONNECTION_RESET;
- #endif
- #ifdef ENOBUFS
- case ENOBUFS: return MA_NO_SPACE;
- #endif
- #ifdef EISCONN
- case EISCONN: return MA_ALREADY_CONNECTED;
- #endif
- #ifdef ENOTCONN
- case ENOTCONN: return MA_NOT_CONNECTED;
- #endif
- #ifdef ESHUTDOWN
- case ESHUTDOWN: return MA_ERROR;
- #endif
- #ifdef ETOOMANYREFS
- case ETOOMANYREFS: return MA_ERROR;
- #endif
- #ifdef ETIMEDOUT
- case ETIMEDOUT: return MA_TIMEOUT;
- #endif
- #ifdef ECONNREFUSED
- case ECONNREFUSED: return MA_CONNECTION_REFUSED;
- #endif
- #ifdef EHOSTDOWN
- case EHOSTDOWN: return MA_NO_HOST;
- #endif
- #ifdef EHOSTUNREACH
- case EHOSTUNREACH: return MA_NO_HOST;
- #endif
- #ifdef EALREADY
- case EALREADY: return MA_IN_PROGRESS;
- #endif
- #ifdef EINPROGRESS
- case EINPROGRESS: return MA_IN_PROGRESS;
- #endif
- #ifdef ESTALE
- case ESTALE: return MA_INVALID_FILE;
- #endif
- #ifdef EUCLEAN
- case EUCLEAN: return MA_ERROR;
- #endif
- #ifdef ENOTNAM
- case ENOTNAM: return MA_ERROR;
- #endif
- #ifdef ENAVAIL
- case ENAVAIL: return MA_ERROR;
- #endif
- #ifdef EISNAM
- case EISNAM: return MA_ERROR;
- #endif
- #ifdef EREMOTEIO
- case EREMOTEIO: return MA_IO_ERROR;
- #endif
- #ifdef EDQUOT
- case EDQUOT: return MA_NO_SPACE;
- #endif
- #ifdef ENOMEDIUM
- case ENOMEDIUM: return MA_DOES_NOT_EXIST;
- #endif
- #ifdef EMEDIUMTYPE
- case EMEDIUMTYPE: return MA_ERROR;
- #endif
- #ifdef ECANCELED
- case ECANCELED: return MA_CANCELLED;
- #endif
- #ifdef ENOKEY
- case ENOKEY: return MA_ERROR;
- #endif
- #ifdef EKEYEXPIRED
- case EKEYEXPIRED: return MA_ERROR;
- #endif
- #ifdef EKEYREVOKED
- case EKEYREVOKED: return MA_ERROR;
- #endif
- #ifdef EKEYREJECTED
- case EKEYREJECTED: return MA_ERROR;
- #endif
- #ifdef EOWNERDEAD
- case EOWNERDEAD: return MA_ERROR;
- #endif
- #ifdef ENOTRECOVERABLE
- case ENOTRECOVERABLE: return MA_ERROR;
- #endif
- #ifdef ERFKILL
- case ERFKILL: return MA_ERROR;
- #endif
- #ifdef EHWPOISON
- case EHWPOISON: return MA_ERROR;
- #endif
- default: return MA_ERROR;
+ if (e == 0) {
+ return MA_SUCCESS;
+ }
+#ifdef EPERM
+ else if (e == EPERM) { return MA_INVALID_OPERATION; }
+#endif
+#ifdef ENOENT
+ else if (e == ENOENT) { return MA_DOES_NOT_EXIST; }
+#endif
+#ifdef ESRCH
+ else if (e == ESRCH) { return MA_DOES_NOT_EXIST; }
+#endif
+#ifdef EINTR
+ else if (e == EINTR) { return MA_INTERRUPT; }
+#endif
+#ifdef EIO
+ else if (e == EIO) { return MA_IO_ERROR; }
+#endif
+#ifdef ENXIO
+ else if (e == ENXIO) { return MA_DOES_NOT_EXIST; }
+#endif
+#ifdef E2BIG
+ else if (e == E2BIG) { return MA_INVALID_ARGS; }
+#endif
+#ifdef ENOEXEC
+ else if (e == ENOEXEC) { return MA_INVALID_FILE; }
+#endif
+#ifdef EBADF
+ else if (e == EBADF) { return MA_INVALID_FILE; }
+#endif
+#ifdef ECHILD
+ else if (e == ECHILD) { return MA_ERROR; }
+#endif
+#ifdef EAGAIN
+ else if (e == EAGAIN) { return MA_UNAVAILABLE; }
+#endif
+#ifdef ENOMEM
+ else if (e == ENOMEM) { return MA_OUT_OF_MEMORY; }
+#endif
+#ifdef EACCES
+ else if (e == EACCES) { return MA_ACCESS_DENIED; }
+#endif
+#ifdef EFAULT
+ else if (e == EFAULT) { return MA_BAD_ADDRESS; }
+#endif
+#ifdef ENOTBLK
+ else if (e == ENOTBLK) { return MA_ERROR; }
+#endif
+#ifdef EBUSY
+ else if (e == EBUSY) { return MA_BUSY; }
+#endif
+#ifdef EEXIST
+ else if (e == EEXIST) { return MA_ALREADY_EXISTS; }
+#endif
+#ifdef EXDEV
+ else if (e == EXDEV) { return MA_ERROR; }
+#endif
+#ifdef ENODEV
+ else if (e == ENODEV) { return MA_DOES_NOT_EXIST; }
+#endif
+#ifdef ENOTDIR
+ else if (e == ENOTDIR) { return MA_NOT_DIRECTORY; }
+#endif
+#ifdef EISDIR
+ else if (e == EISDIR) { return MA_IS_DIRECTORY; }
+#endif
+#ifdef EINVAL
+ else if (e == EINVAL) { return MA_INVALID_ARGS; }
+#endif
+#ifdef ENFILE
+ else if (e == ENFILE) { return MA_TOO_MANY_OPEN_FILES; }
+#endif
+#ifdef EMFILE
+ else if (e == EMFILE) { return MA_TOO_MANY_OPEN_FILES; }
+#endif
+#ifdef ENOTTY
+ else if (e == ENOTTY) { return MA_INVALID_OPERATION; }
+#endif
+#ifdef ETXTBSY
+ else if (e == ETXTBSY) { return MA_BUSY; }
+#endif
+#ifdef EFBIG
+ else if (e == EFBIG) { return MA_TOO_BIG; }
+#endif
+#ifdef ENOSPC
+ else if (e == ENOSPC) { return MA_NO_SPACE; }
+#endif
+#ifdef ESPIPE
+ else if (e == ESPIPE) { return MA_BAD_SEEK; }
+#endif
+#ifdef EROFS
+ else if (e == EROFS) { return MA_ACCESS_DENIED; }
+#endif
+#ifdef EMLINK
+ else if (e == EMLINK) { return MA_TOO_MANY_LINKS; }
+#endif
+#ifdef EPIPE
+ else if (e == EPIPE) { return MA_BAD_PIPE; }
+#endif
+#ifdef EDOM
+ else if (e == EDOM) { return MA_OUT_OF_RANGE; }
+#endif
+#ifdef ERANGE
+ else if (e == ERANGE) { return MA_OUT_OF_RANGE; }
+#endif
+#ifdef EDEADLK
+ else if (e == EDEADLK) { return MA_DEADLOCK; }
+#endif
+#ifdef ENAMETOOLONG
+ else if (e == ENAMETOOLONG) { return MA_PATH_TOO_LONG; }
+#endif
+#ifdef ENOLCK
+ else if (e == ENOLCK) { return MA_ERROR; }
+#endif
+#ifdef ENOSYS
+ else if (e == ENOSYS) { return MA_NOT_IMPLEMENTED; }
+#endif
+#ifdef ENOTEMPTY
+ else if (e == ENOTEMPTY) { return MA_DIRECTORY_NOT_EMPTY; }
+#endif
+#ifdef ELOOP
+ else if (e == ELOOP) { return MA_TOO_MANY_LINKS; }
+#endif
+#ifdef ENOMSG
+ else if (e == ENOMSG) { return MA_NO_MESSAGE; }
+#endif
+#ifdef EIDRM
+ else if (e == EIDRM) { return MA_ERROR; }
+#endif
+#ifdef ECHRNG
+ else if (e == ECHRNG) { return MA_ERROR; }
+#endif
+#ifdef EL2NSYNC
+ else if (e == EL2NSYNC) { return MA_ERROR; }
+#endif
+#ifdef EL3HLT
+ else if (e == EL3HLT) { return MA_ERROR; }
+#endif
+#ifdef EL3RST
+ else if (e == EL3RST) { return MA_ERROR; }
+#endif
+#ifdef ELNRNG
+ else if (e == ELNRNG) { return MA_OUT_OF_RANGE; }
+#endif
+#ifdef EUNATCH
+ else if (e == EUNATCH) { return MA_ERROR; }
+#endif
+#ifdef ENOCSI
+ else if (e == ENOCSI) { return MA_ERROR; }
+#endif
+#ifdef EL2HLT
+ else if (e == EL2HLT) { return MA_ERROR; }
+#endif
+#ifdef EBADE
+ else if (e == EBADE) { return MA_ERROR; }
+#endif
+#ifdef EBADR
+ else if (e == EBADR) { return MA_ERROR; }
+#endif
+#ifdef EXFULL
+ else if (e == EXFULL) { return MA_ERROR; }
+#endif
+#ifdef ENOANO
+ else if (e == ENOANO) { return MA_ERROR; }
+#endif
+#ifdef EBADRQC
+ else if (e == EBADRQC) { return MA_ERROR; }
+#endif
+#ifdef EBADSLT
+ else if (e == EBADSLT) { return MA_ERROR; }
+#endif
+#ifdef EBFONT
+ else if (e == EBFONT) { return MA_INVALID_FILE; }
+#endif
+#ifdef ENOSTR
+ else if (e == ENOSTR) { return MA_ERROR; }
+#endif
+#ifdef ENODATA
+ else if (e == ENODATA) { return MA_NO_DATA_AVAILABLE; }
+#endif
+#ifdef ETIME
+ else if (e == ETIME) { return MA_TIMEOUT; }
+#endif
+#ifdef ENOSR
+ else if (e == ENOSR) { return MA_NO_DATA_AVAILABLE; }
+#endif
+#ifdef ENONET
+ else if (e == ENONET) { return MA_NO_NETWORK; }
+#endif
+#ifdef ENOPKG
+ else if (e == ENOPKG) { return MA_ERROR; }
+#endif
+#ifdef EREMOTE
+ else if (e == EREMOTE) { return MA_ERROR; }
+#endif
+#ifdef ENOLINK
+ else if (e == ENOLINK) { return MA_ERROR; }
+#endif
+#ifdef EADV
+ else if (e == EADV) { return MA_ERROR; }
+#endif
+#ifdef ESRMNT
+ else if (e == ESRMNT) { return MA_ERROR; }
+#endif
+#ifdef ECOMM
+ else if (e == ECOMM) { return MA_ERROR; }
+#endif
+#ifdef EPROTO
+ else if (e == EPROTO) { return MA_ERROR; }
+#endif
+#ifdef EMULTIHOP
+ else if (e == EMULTIHOP) { return MA_ERROR; }
+#endif
+#ifdef EDOTDOT
+ else if (e == EDOTDOT) { return MA_ERROR; }
+#endif
+#ifdef EBADMSG
+ else if (e == EBADMSG) { return MA_BAD_MESSAGE; }
+#endif
+#ifdef EOVERFLOW
+ else if (e == EOVERFLOW) { return MA_TOO_BIG; }
+#endif
+#ifdef ENOTUNIQ
+ else if (e == ENOTUNIQ) { return MA_NOT_UNIQUE; }
+#endif
+#ifdef EBADFD
+ else if (e == EBADFD) { return MA_ERROR; }
+#endif
+#ifdef EREMCHG
+ else if (e == EREMCHG) { return MA_ERROR; }
+#endif
+#ifdef ELIBACC
+ else if (e == ELIBACC) { return MA_ACCESS_DENIED; }
+#endif
+#ifdef ELIBBAD
+ else if (e == ELIBBAD) { return MA_INVALID_FILE; }
+#endif
+#ifdef ELIBSCN
+ else if (e == ELIBSCN) { return MA_INVALID_FILE; }
+#endif
+#ifdef ELIBMAX
+ else if (e == ELIBMAX) { return MA_ERROR; }
+#endif
+#ifdef ELIBEXEC
+ else if (e == ELIBEXEC) { return MA_ERROR; }
+#endif
+#ifdef EILSEQ
+ else if (e == EILSEQ) { return MA_INVALID_DATA; }
+#endif
+#ifdef ERESTART
+ else if (e == ERESTART) { return MA_ERROR; }
+#endif
+#ifdef ESTRPIPE
+ else if (e == ESTRPIPE) { return MA_ERROR; }
+#endif
+#ifdef EUSERS
+ else if (e == EUSERS) { return MA_ERROR; }
+#endif
+#ifdef ENOTSOCK
+ else if (e == ENOTSOCK) { return MA_NOT_SOCKET; }
+#endif
+#ifdef EDESTADDRREQ
+ else if (e == EDESTADDRREQ) { return MA_NO_ADDRESS; }
+#endif
+#ifdef EMSGSIZE
+ else if (e == EMSGSIZE) { return MA_TOO_BIG; }
+#endif
+#ifdef EPROTOTYPE
+ else if (e == EPROTOTYPE) { return MA_BAD_PROTOCOL; }
+#endif
+#ifdef ENOPROTOOPT
+ else if (e == ENOPROTOOPT) { return MA_PROTOCOL_UNAVAILABLE; }
+#endif
+#ifdef EPROTONOSUPPORT
+ else if (e == EPROTONOSUPPORT) { return MA_PROTOCOL_NOT_SUPPORTED; }
+#endif
+#ifdef ESOCKTNOSUPPORT
+ else if (e == ESOCKTNOSUPPORT) { return MA_SOCKET_NOT_SUPPORTED; }
+#endif
+#ifdef EOPNOTSUPP
+ else if (e == EOPNOTSUPP) { return MA_INVALID_OPERATION; }
+#endif
+#ifdef EPFNOSUPPORT
+ else if (e == EPFNOSUPPORT) { return MA_PROTOCOL_FAMILY_NOT_SUPPORTED; }
+#endif
+#ifdef EAFNOSUPPORT
+ else if (e == EAFNOSUPPORT) { return MA_ADDRESS_FAMILY_NOT_SUPPORTED; }
+#endif
+#ifdef EADDRINUSE
+ else if (e == EADDRINUSE) { return MA_ALREADY_IN_USE; }
+#endif
+#ifdef EADDRNOTAVAIL
+ else if (e == EADDRNOTAVAIL) { return MA_ERROR; }
+#endif
+#ifdef ENETDOWN
+ else if (e == ENETDOWN) { return MA_NO_NETWORK; }
+#endif
+#ifdef ENETUNREACH
+ else if (e == ENETUNREACH) { return MA_NO_NETWORK; }
+#endif
+#ifdef ENETRESET
+ else if (e == ENETRESET) { return MA_NO_NETWORK; }
+#endif
+#ifdef ECONNABORTED
+ else if (e == ECONNABORTED) { return MA_NO_NETWORK; }
+#endif
+#ifdef ECONNRESET
+ else if (e == ECONNRESET) { return MA_CONNECTION_RESET; }
+#endif
+#ifdef ENOBUFS
+ else if (e == ENOBUFS) { return MA_NO_SPACE; }
+#endif
+#ifdef EISCONN
+ else if (e == EISCONN) { return MA_ALREADY_CONNECTED; }
+#endif
+#ifdef ENOTCONN
+ else if (e == ENOTCONN) { return MA_NOT_CONNECTED; }
+#endif
+#ifdef ESHUTDOWN
+ else if (e == ESHUTDOWN) { return MA_ERROR; }
+#endif
+#ifdef ETOOMANYREFS
+ else if (e == ETOOMANYREFS) { return MA_ERROR; }
+#endif
+#ifdef ETIMEDOUT
+ else if (e == ETIMEDOUT) { return MA_TIMEOUT; }
+#endif
+#ifdef ECONNREFUSED
+ else if (e == ECONNREFUSED) { return MA_CONNECTION_REFUSED; }
+#endif
+#ifdef EHOSTDOWN
+ else if (e == EHOSTDOWN) { return MA_NO_HOST; }
+#endif
+#ifdef EHOSTUNREACH
+ else if (e == EHOSTUNREACH) { return MA_NO_HOST; }
+#endif
+#ifdef EALREADY
+ else if (e == EALREADY) { return MA_IN_PROGRESS; }
+#endif
+#ifdef EINPROGRESS
+ else if (e == EINPROGRESS) { return MA_IN_PROGRESS; }
+#endif
+#ifdef ESTALE
+ else if (e == ESTALE) { return MA_INVALID_FILE; }
+#endif
+#ifdef EUCLEAN
+ else if (e == EUCLEAN) { return MA_ERROR; }
+#endif
+#ifdef ENOTNAM
+ else if (e == ENOTNAM) { return MA_ERROR; }
+#endif
+#ifdef ENAVAIL
+ else if (e == ENAVAIL) { return MA_ERROR; }
+#endif
+#ifdef EISNAM
+ else if (e == EISNAM) { return MA_ERROR; }
+#endif
+#ifdef EREMOTEIO
+ else if (e == EREMOTEIO) { return MA_IO_ERROR; }
+#endif
+#ifdef EDQUOT
+ else if (e == EDQUOT) { return MA_NO_SPACE; }
+#endif
+#ifdef ENOMEDIUM
+ else if (e == ENOMEDIUM) { return MA_DOES_NOT_EXIST; }
+#endif
+#ifdef EMEDIUMTYPE
+ else if (e == EMEDIUMTYPE) { return MA_ERROR; }
+#endif
+#ifdef ECANCELED
+ else if (e == ECANCELED) { return MA_CANCELLED; }
+#endif
+#ifdef ENOKEY
+ else if (e == ENOKEY) { return MA_ERROR; }
+#endif
+#ifdef EKEYEXPIRED
+ else if (e == EKEYEXPIRED) { return MA_ERROR; }
+#endif
+#ifdef EKEYREVOKED
+ else if (e == EKEYREVOKED) { return MA_ERROR; }
+#endif
+#ifdef EKEYREJECTED
+ else if (e == EKEYREJECTED) { return MA_ERROR; }
+#endif
+#ifdef EOWNERDEAD
+ else if (e == EOWNERDEAD) { return MA_ERROR; }
+#endif
+#ifdef ENOTRECOVERABLE
+ else if (e == ENOTRECOVERABLE) { return MA_ERROR; }
+#endif
+#ifdef ERFKILL
+ else if (e == ERFKILL) { return MA_ERROR; }
+#endif
+#ifdef EHWPOISON
+ else if (e == EHWPOISON) { return MA_ERROR; }
+#endif
+ else {
+ return MA_ERROR;
}
}
@@ -13059,6 +13414,9 @@ MA_API const char* ma_log_level_to_string(ma_uint32 logLevel)
}
#if defined(MA_DEBUG_OUTPUT)
+#if defined(MA_ANDROID)
+ #include
+#endif
/* Customize this to use a specific tag in __android_log_print() for debug output messages. */
#ifndef MA_ANDROID_LOG_TAG
@@ -13287,7 +13645,7 @@ MA_API ma_result ma_log_postv(ma_log* pLog, ma_uint32 level, const char* pFormat
/* First try formatting into our fixed sized stack allocated buffer. If this is too small we'll fallback to a heap allocation. */
length = vsnprintf(pFormattedMessageStack, sizeof(pFormattedMessageStack), pFormat, args);
if (length < 0) {
- return MA_INVALID_OPERATION; /* An error occured when trying to convert the buffer. */
+ return MA_INVALID_OPERATION; /* An error occurred when trying to convert the buffer. */
}
if ((size_t)length < sizeof(pFormattedMessageStack)) {
@@ -13666,109 +14024,95 @@ static MA_INLINE ma_int32 ma_dither_s32(ma_dither_mode ditherMode, ma_int32 dith
Atomics
**************************************************************************************************************************************************************/
-/* c89atomic.h begin */
-#ifndef c89atomic_h
-#define c89atomic_h
+/* ma_atomic.h begin */
+#ifndef ma_atomic_h
#if defined(__cplusplus)
extern "C" {
#endif
-typedef signed char c89atomic_int8;
-typedef unsigned char c89atomic_uint8;
-typedef signed short c89atomic_int16;
-typedef unsigned short c89atomic_uint16;
-typedef signed int c89atomic_int32;
-typedef unsigned int c89atomic_uint32;
-#if defined(_MSC_VER) && !defined(__clang__)
- typedef signed __int64 c89atomic_int64;
- typedef unsigned __int64 c89atomic_uint64;
-#else
- #if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)))
- #pragma GCC diagnostic push
- #pragma GCC diagnostic ignored "-Wlong-long"
- #if defined(__clang__)
- #pragma GCC diagnostic ignored "-Wc++11-long-long"
- #endif
- #endif
- typedef signed long long c89atomic_int64;
- typedef unsigned long long c89atomic_uint64;
- #if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)))
- #pragma GCC diagnostic pop
- #endif
-#endif
-typedef int c89atomic_memory_order;
-typedef unsigned char c89atomic_bool;
-#if !defined(C89ATOMIC_64BIT) && !defined(C89ATOMIC_32BIT)
-#ifdef _WIN32
-#ifdef _WIN64
-#define C89ATOMIC_64BIT
-#else
-#define C89ATOMIC_32BIT
-#endif
-#endif
-#endif
-#if !defined(C89ATOMIC_64BIT) && !defined(C89ATOMIC_32BIT)
-#ifdef __GNUC__
-#ifdef __LP64__
-#define C89ATOMIC_64BIT
-#else
-#define C89ATOMIC_32BIT
-#endif
-#endif
-#endif
-#if !defined(C89ATOMIC_64BIT) && !defined(C89ATOMIC_32BIT)
-#include
-#if INTPTR_MAX == INT64_MAX
-#define C89ATOMIC_64BIT
-#else
-#define C89ATOMIC_32BIT
-#endif
-#endif
-#if defined(__x86_64__) || defined(_M_X64)
-#define C89ATOMIC_X64
-#elif defined(__i386) || defined(_M_IX86)
-#define C89ATOMIC_X86
-#elif defined(__arm__) || defined(_M_ARM) || defined(__arm64) || defined(__arm64__) || defined(__aarch64__) || defined(_M_ARM64)
-#define C89ATOMIC_ARM
-#endif
-#if defined(_MSC_VER)
- #define C89ATOMIC_INLINE __forceinline
-#elif defined(__GNUC__)
- #if defined(__STRICT_ANSI__)
- #define C89ATOMIC_INLINE __inline__ __attribute__((always_inline))
- #else
- #define C89ATOMIC_INLINE inline __attribute__((always_inline))
+#if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)))
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wlong-long"
+ #if defined(__clang__)
+ #pragma GCC diagnostic ignored "-Wc++11-long-long"
#endif
-#elif defined(__WATCOMC__) || defined(__DMC__)
- #define C89ATOMIC_INLINE __inline
-#else
- #define C89ATOMIC_INLINE
#endif
-#define C89ATOMIC_HAS_8
-#define C89ATOMIC_HAS_16
-#define C89ATOMIC_HAS_32
-#define C89ATOMIC_HAS_64
+typedef int ma_atomic_memory_order;
+#define MA_ATOMIC_HAS_8
+#define MA_ATOMIC_HAS_16
+#define MA_ATOMIC_HAS_32
+#define MA_ATOMIC_HAS_64
#if (defined(_MSC_VER) ) || defined(__WATCOMC__) || defined(__DMC__)
- #define c89atomic_memory_order_relaxed 0
- #define c89atomic_memory_order_consume 1
- #define c89atomic_memory_order_acquire 2
- #define c89atomic_memory_order_release 3
- #define c89atomic_memory_order_acq_rel 4
- #define c89atomic_memory_order_seq_cst 5
- #if _MSC_VER < 1600 && defined(C89ATOMIC_X86)
- #define C89ATOMIC_MSVC_USE_INLINED_ASSEMBLY
+ #define MA_ATOMIC_MSVC_ARM_INTRINSIC(dst, src, order, intrin, ma_atomicType, msvcType) \
+ ma_atomicType result; \
+ switch (order) \
+ { \
+ case ma_atomic_memory_order_relaxed: \
+ { \
+ result = (ma_atomicType)intrin##_nf((volatile msvcType*)dst, (msvcType)src); \
+ } break; \
+ case ma_atomic_memory_order_consume: \
+ case ma_atomic_memory_order_acquire: \
+ { \
+ result = (ma_atomicType)intrin##_acq((volatile msvcType*)dst, (msvcType)src); \
+ } break; \
+ case ma_atomic_memory_order_release: \
+ { \
+ result = (ma_atomicType)intrin##_rel((volatile msvcType*)dst, (msvcType)src); \
+ } break; \
+ case ma_atomic_memory_order_acq_rel: \
+ case ma_atomic_memory_order_seq_cst: \
+ default: \
+ { \
+ result = (ma_atomicType)intrin((volatile msvcType*)dst, (msvcType)src); \
+ } break; \
+ } \
+ return result;
+ #define MA_ATOMIC_MSVC_ARM_INTRINSIC_COMPARE_EXCHANGE(ptr, expected, desired, order, intrin, ma_atomicType, msvcType) \
+ ma_atomicType result; \
+ switch (order) \
+ { \
+ case ma_atomic_memory_order_relaxed: \
+ { \
+ result = (ma_atomicType)intrin##_nf((volatile msvcType*)ptr, (msvcType)expected, (msvcType)desired); \
+ } break; \
+ case ma_atomic_memory_order_consume: \
+ case ma_atomic_memory_order_acquire: \
+ { \
+ result = (ma_atomicType)intrin##_acq((volatile msvcType*)ptr, (msvcType)expected, (msvcType)desired); \
+ } break; \
+ case ma_atomic_memory_order_release: \
+ { \
+ result = (ma_atomicType)intrin##_rel((volatile msvcType*)ptr, (msvcType)expected, (msvcType)desired); \
+ } break; \
+ case ma_atomic_memory_order_acq_rel: \
+ case ma_atomic_memory_order_seq_cst: \
+ default: \
+ { \
+ result = (ma_atomicType)intrin((volatile msvcType*)ptr, (msvcType)expected, (msvcType)desired); \
+ } break; \
+ } \
+ return result;
+ #define ma_atomic_memory_order_relaxed 0
+ #define ma_atomic_memory_order_consume 1
+ #define ma_atomic_memory_order_acquire 2
+ #define ma_atomic_memory_order_release 3
+ #define ma_atomic_memory_order_acq_rel 4
+ #define ma_atomic_memory_order_seq_cst 5
+ #if _MSC_VER < 1600 && defined(MA_X86)
+ #define MA_ATOMIC_MSVC_USE_INLINED_ASSEMBLY
#endif
#if _MSC_VER < 1600
- #undef C89ATOMIC_HAS_8
- #undef C89ATOMIC_HAS_16
+ #undef MA_ATOMIC_HAS_8
+ #undef MA_ATOMIC_HAS_16
#endif
- #if !defined(C89ATOMIC_MSVC_USE_INLINED_ASSEMBLY)
+ #if !defined(MA_ATOMIC_MSVC_USE_INLINED_ASSEMBLY)
#include
#endif
- #if defined(C89ATOMIC_MSVC_USE_INLINED_ASSEMBLY)
- #if defined(C89ATOMIC_HAS_8)
- static C89ATOMIC_INLINE c89atomic_uint8 __stdcall c89atomic_compare_and_swap_8(volatile c89atomic_uint8* dst, c89atomic_uint8 expected, c89atomic_uint8 desired)
+ #if defined(MA_ATOMIC_MSVC_USE_INLINED_ASSEMBLY)
+ #if defined(MA_ATOMIC_HAS_8)
+ static MA_INLINE ma_uint8 __stdcall ma_atomic_compare_and_swap_8(volatile ma_uint8* dst, ma_uint8 expected, ma_uint8 desired)
{
- c89atomic_uint8 result = 0;
+ ma_uint8 result = 0;
__asm {
mov ecx, dst
mov al, expected
@@ -13779,10 +14123,10 @@ typedef unsigned char c89atomic_bool;
return result;
}
#endif
- #if defined(C89ATOMIC_HAS_16)
- static C89ATOMIC_INLINE c89atomic_uint16 __stdcall c89atomic_compare_and_swap_16(volatile c89atomic_uint16* dst, c89atomic_uint16 expected, c89atomic_uint16 desired)
+ #if defined(MA_ATOMIC_HAS_16)
+ static MA_INLINE ma_uint16 __stdcall ma_atomic_compare_and_swap_16(volatile ma_uint16* dst, ma_uint16 expected, ma_uint16 desired)
{
- c89atomic_uint16 result = 0;
+ ma_uint16 result = 0;
__asm {
mov ecx, dst
mov ax, expected
@@ -13793,10 +14137,10 @@ typedef unsigned char c89atomic_bool;
return result;
}
#endif
- #if defined(C89ATOMIC_HAS_32)
- static C89ATOMIC_INLINE c89atomic_uint32 __stdcall c89atomic_compare_and_swap_32(volatile c89atomic_uint32* dst, c89atomic_uint32 expected, c89atomic_uint32 desired)
+ #if defined(MA_ATOMIC_HAS_32)
+ static MA_INLINE ma_uint32 __stdcall ma_atomic_compare_and_swap_32(volatile ma_uint32* dst, ma_uint32 expected, ma_uint32 desired)
{
- c89atomic_uint32 result = 0;
+ ma_uint32 result = 0;
__asm {
mov ecx, dst
mov eax, expected
@@ -13807,11 +14151,11 @@ typedef unsigned char c89atomic_bool;
return result;
}
#endif
- #if defined(C89ATOMIC_HAS_64)
- static C89ATOMIC_INLINE c89atomic_uint64 __stdcall c89atomic_compare_and_swap_64(volatile c89atomic_uint64* dst, c89atomic_uint64 expected, c89atomic_uint64 desired)
+ #if defined(MA_ATOMIC_HAS_64)
+ static MA_INLINE ma_uint64 __stdcall ma_atomic_compare_and_swap_64(volatile ma_uint64* dst, ma_uint64 expected, ma_uint64 desired)
{
- c89atomic_uint32 resultEAX = 0;
- c89atomic_uint32 resultEDX = 0;
+ ma_uint32 resultEAX = 0;
+ ma_uint32 resultEDX = 0;
__asm {
mov esi, dst
mov eax, dword ptr expected
@@ -13822,28 +14166,28 @@ typedef unsigned char c89atomic_bool;
mov resultEAX, eax
mov resultEDX, edx
}
- return ((c89atomic_uint64)resultEDX << 32) | resultEAX;
+ return ((ma_uint64)resultEDX << 32) | resultEAX;
}
#endif
#else
- #if defined(C89ATOMIC_HAS_8)
- #define c89atomic_compare_and_swap_8( dst, expected, desired) (c89atomic_uint8 )_InterlockedCompareExchange8((volatile char*)dst, (char)desired, (char)expected)
+ #if defined(MA_ATOMIC_HAS_8)
+ #define ma_atomic_compare_and_swap_8( dst, expected, desired) (ma_uint8 )_InterlockedCompareExchange8((volatile char*)dst, (char)desired, (char)expected)
#endif
- #if defined(C89ATOMIC_HAS_16)
- #define c89atomic_compare_and_swap_16(dst, expected, desired) (c89atomic_uint16)_InterlockedCompareExchange16((volatile short*)dst, (short)desired, (short)expected)
+ #if defined(MA_ATOMIC_HAS_16)
+ #define ma_atomic_compare_and_swap_16(dst, expected, desired) (ma_uint16)_InterlockedCompareExchange16((volatile short*)dst, (short)desired, (short)expected)
#endif
- #if defined(C89ATOMIC_HAS_32)
- #define c89atomic_compare_and_swap_32(dst, expected, desired) (c89atomic_uint32)_InterlockedCompareExchange((volatile long*)dst, (long)desired, (long)expected)
+ #if defined(MA_ATOMIC_HAS_32)
+ #define ma_atomic_compare_and_swap_32(dst, expected, desired) (ma_uint32)_InterlockedCompareExchange((volatile long*)dst, (long)desired, (long)expected)
#endif
- #if defined(C89ATOMIC_HAS_64)
- #define c89atomic_compare_and_swap_64(dst, expected, desired) (c89atomic_uint64)_InterlockedCompareExchange64((volatile c89atomic_int64*)dst, (c89atomic_int64)desired, (c89atomic_int64)expected)
+ #if defined(MA_ATOMIC_HAS_64)
+ #define ma_atomic_compare_and_swap_64(dst, expected, desired) (ma_uint64)_InterlockedCompareExchange64((volatile ma_int64*)dst, (ma_int64)desired, (ma_int64)expected)
#endif
#endif
- #if defined(C89ATOMIC_MSVC_USE_INLINED_ASSEMBLY)
- #if defined(C89ATOMIC_HAS_8)
- static C89ATOMIC_INLINE c89atomic_uint8 __stdcall c89atomic_exchange_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_MSVC_USE_INLINED_ASSEMBLY)
+ #if defined(MA_ATOMIC_HAS_8)
+ static MA_INLINE ma_uint8 __stdcall ma_atomic_exchange_explicit_8(volatile ma_uint8* dst, ma_uint8 src, ma_atomic_memory_order order)
{
- c89atomic_uint8 result = 0;
+ ma_uint8 result = 0;
(void)order;
__asm {
mov ecx, dst
@@ -13854,10 +14198,10 @@ typedef unsigned char c89atomic_bool;
return result;
}
#endif
- #if defined(C89ATOMIC_HAS_16)
- static C89ATOMIC_INLINE c89atomic_uint16 __stdcall c89atomic_exchange_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_HAS_16)
+ static MA_INLINE ma_uint16 __stdcall ma_atomic_exchange_explicit_16(volatile ma_uint16* dst, ma_uint16 src, ma_atomic_memory_order order)
{
- c89atomic_uint16 result = 0;
+ ma_uint16 result = 0;
(void)order;
__asm {
mov ecx, dst
@@ -13868,10 +14212,10 @@ typedef unsigned char c89atomic_bool;
return result;
}
#endif
- #if defined(C89ATOMIC_HAS_32)
- static C89ATOMIC_INLINE c89atomic_uint32 __stdcall c89atomic_exchange_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_HAS_32)
+ static MA_INLINE ma_uint32 __stdcall ma_atomic_exchange_explicit_32(volatile ma_uint32* dst, ma_uint32 src, ma_atomic_memory_order order)
{
- c89atomic_uint32 result = 0;
+ ma_uint32 result = 0;
(void)order;
__asm {
mov ecx, dst
@@ -13883,52 +14227,68 @@ typedef unsigned char c89atomic_bool;
}
#endif
#else
- #if defined(C89ATOMIC_HAS_8)
- static C89ATOMIC_INLINE c89atomic_uint8 __stdcall c89atomic_exchange_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_HAS_8)
+ static MA_INLINE ma_uint8 __stdcall ma_atomic_exchange_explicit_8(volatile ma_uint8* dst, ma_uint8 src, ma_atomic_memory_order order)
{
+ #if defined(MA_ARM)
+ MA_ATOMIC_MSVC_ARM_INTRINSIC(dst, src, order, _InterlockedExchange8, ma_uint8, char);
+ #else
(void)order;
- return (c89atomic_uint8)_InterlockedExchange8((volatile char*)dst, (char)src);
+ return (ma_uint8)_InterlockedExchange8((volatile char*)dst, (char)src);
+ #endif
}
#endif
- #if defined(C89ATOMIC_HAS_16)
- static C89ATOMIC_INLINE c89atomic_uint16 __stdcall c89atomic_exchange_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_HAS_16)
+ static MA_INLINE ma_uint16 __stdcall ma_atomic_exchange_explicit_16(volatile ma_uint16* dst, ma_uint16 src, ma_atomic_memory_order order)
{
+ #if defined(MA_ARM)
+ MA_ATOMIC_MSVC_ARM_INTRINSIC(dst, src, order, _InterlockedExchange16, ma_uint16, short);
+ #else
(void)order;
- return (c89atomic_uint16)_InterlockedExchange16((volatile short*)dst, (short)src);
+ return (ma_uint16)_InterlockedExchange16((volatile short*)dst, (short)src);
+ #endif
}
#endif
- #if defined(C89ATOMIC_HAS_32)
- static C89ATOMIC_INLINE c89atomic_uint32 __stdcall c89atomic_exchange_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_HAS_32)
+ static MA_INLINE ma_uint32 __stdcall ma_atomic_exchange_explicit_32(volatile ma_uint32* dst, ma_uint32 src, ma_atomic_memory_order order)
{
+ #if defined(MA_ARM)
+ MA_ATOMIC_MSVC_ARM_INTRINSIC(dst, src, order, _InterlockedExchange, ma_uint32, long);
+ #else
(void)order;
- return (c89atomic_uint32)_InterlockedExchange((volatile long*)dst, (long)src);
+ return (ma_uint32)_InterlockedExchange((volatile long*)dst, (long)src);
+ #endif
}
#endif
- #if defined(C89ATOMIC_HAS_64) && defined(C89ATOMIC_64BIT)
- static C89ATOMIC_INLINE c89atomic_uint64 __stdcall c89atomic_exchange_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_HAS_64) && defined(MA_64BIT)
+ static MA_INLINE ma_uint64 __stdcall ma_atomic_exchange_explicit_64(volatile ma_uint64* dst, ma_uint64 src, ma_atomic_memory_order order)
{
+ #if defined(MA_ARM)
+ MA_ATOMIC_MSVC_ARM_INTRINSIC(dst, src, order, _InterlockedExchange64, ma_uint64, long long);
+ #else
(void)order;
- return (c89atomic_uint64)_InterlockedExchange64((volatile long long*)dst, (long long)src);
+ return (ma_uint64)_InterlockedExchange64((volatile long long*)dst, (long long)src);
+ #endif
}
#else
#endif
#endif
- #if defined(C89ATOMIC_HAS_64) && !defined(C89ATOMIC_64BIT)
- static C89ATOMIC_INLINE c89atomic_uint64 __stdcall c89atomic_exchange_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_HAS_64) && !defined(MA_64BIT)
+ static MA_INLINE ma_uint64 __stdcall ma_atomic_exchange_explicit_64(volatile ma_uint64* dst, ma_uint64 src, ma_atomic_memory_order order)
{
- c89atomic_uint64 oldValue;
+ ma_uint64 oldValue;
do {
oldValue = *dst;
- } while (c89atomic_compare_and_swap_64(dst, oldValue, src) != oldValue);
+ } while (ma_atomic_compare_and_swap_64(dst, oldValue, src) != oldValue);
(void)order;
return oldValue;
}
#endif
- #if defined(C89ATOMIC_MSVC_USE_INLINED_ASSEMBLY)
- #if defined(C89ATOMIC_HAS_8)
- static C89ATOMIC_INLINE c89atomic_uint8 __stdcall c89atomic_fetch_add_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_MSVC_USE_INLINED_ASSEMBLY)
+ #if defined(MA_ATOMIC_HAS_8)
+ static MA_INLINE ma_uint8 __stdcall ma_atomic_fetch_add_explicit_8(volatile ma_uint8* dst, ma_uint8 src, ma_atomic_memory_order order)
{
- c89atomic_uint8 result = 0;
+ ma_uint8 result = 0;
(void)order;
__asm {
mov ecx, dst
@@ -13939,10 +14299,10 @@ typedef unsigned char c89atomic_bool;
return result;
}
#endif
- #if defined(C89ATOMIC_HAS_16)
- static C89ATOMIC_INLINE c89atomic_uint16 __stdcall c89atomic_fetch_add_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_HAS_16)
+ static MA_INLINE ma_uint16 __stdcall ma_atomic_fetch_add_explicit_16(volatile ma_uint16* dst, ma_uint16 src, ma_atomic_memory_order order)
{
- c89atomic_uint16 result = 0;
+ ma_uint16 result = 0;
(void)order;
__asm {
mov ecx, dst
@@ -13953,10 +14313,10 @@ typedef unsigned char c89atomic_bool;
return result;
}
#endif
- #if defined(C89ATOMIC_HAS_32)
- static C89ATOMIC_INLINE c89atomic_uint32 __stdcall c89atomic_fetch_add_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_HAS_32)
+ static MA_INLINE ma_uint32 __stdcall ma_atomic_fetch_add_explicit_32(volatile ma_uint32* dst, ma_uint32 src, ma_atomic_memory_order order)
{
- c89atomic_uint32 result = 0;
+ ma_uint32 result = 0;
(void)order;
__asm {
mov ecx, dst
@@ -13968,51 +14328,67 @@ typedef unsigned char c89atomic_bool;
}
#endif
#else
- #if defined(C89ATOMIC_HAS_8)
- static C89ATOMIC_INLINE c89atomic_uint8 __stdcall c89atomic_fetch_add_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_HAS_8)
+ static MA_INLINE ma_uint8 __stdcall ma_atomic_fetch_add_explicit_8(volatile ma_uint8* dst, ma_uint8 src, ma_atomic_memory_order order)
{
+ #if defined(MA_ARM)
+ MA_ATOMIC_MSVC_ARM_INTRINSIC(dst, src, order, _InterlockedExchangeAdd8, ma_uint8, char);
+ #else
(void)order;
- return (c89atomic_uint8)_InterlockedExchangeAdd8((volatile char*)dst, (char)src);
+ return (ma_uint8)_InterlockedExchangeAdd8((volatile char*)dst, (char)src);
+ #endif
}
#endif
- #if defined(C89ATOMIC_HAS_16)
- static C89ATOMIC_INLINE c89atomic_uint16 __stdcall c89atomic_fetch_add_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_HAS_16)
+ static MA_INLINE ma_uint16 __stdcall ma_atomic_fetch_add_explicit_16(volatile ma_uint16* dst, ma_uint16 src, ma_atomic_memory_order order)
{
+ #if defined(MA_ARM)
+ MA_ATOMIC_MSVC_ARM_INTRINSIC(dst, src, order, _InterlockedExchangeAdd16, ma_uint16, short);
+ #else
(void)order;
- return (c89atomic_uint16)_InterlockedExchangeAdd16((volatile short*)dst, (short)src);
+ return (ma_uint16)_InterlockedExchangeAdd16((volatile short*)dst, (short)src);
+ #endif
}
#endif
- #if defined(C89ATOMIC_HAS_32)
- static C89ATOMIC_INLINE c89atomic_uint32 __stdcall c89atomic_fetch_add_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_HAS_32)
+ static MA_INLINE ma_uint32 __stdcall ma_atomic_fetch_add_explicit_32(volatile ma_uint32* dst, ma_uint32 src, ma_atomic_memory_order order)
{
+ #if defined(MA_ARM)
+ MA_ATOMIC_MSVC_ARM_INTRINSIC(dst, src, order, _InterlockedExchangeAdd, ma_uint32, long);
+ #else
(void)order;
- return (c89atomic_uint32)_InterlockedExchangeAdd((volatile long*)dst, (long)src);
+ return (ma_uint32)_InterlockedExchangeAdd((volatile long*)dst, (long)src);
+ #endif
}
#endif
- #if defined(C89ATOMIC_HAS_64) && defined(C89ATOMIC_64BIT)
- static C89ATOMIC_INLINE c89atomic_uint64 __stdcall c89atomic_fetch_add_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_HAS_64) && defined(MA_64BIT)
+ static MA_INLINE ma_uint64 __stdcall ma_atomic_fetch_add_explicit_64(volatile ma_uint64* dst, ma_uint64 src, ma_atomic_memory_order order)
{
+ #if defined(MA_ARM)
+ MA_ATOMIC_MSVC_ARM_INTRINSIC(dst, src, order, _InterlockedExchangeAdd64, ma_uint64, long long);
+ #else
(void)order;
- return (c89atomic_uint64)_InterlockedExchangeAdd64((volatile long long*)dst, (long long)src);
+ return (ma_uint64)_InterlockedExchangeAdd64((volatile long long*)dst, (long long)src);
+ #endif
}
#else
#endif
#endif
- #if defined(C89ATOMIC_HAS_64) && !defined(C89ATOMIC_64BIT)
- static C89ATOMIC_INLINE c89atomic_uint64 __stdcall c89atomic_fetch_add_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_HAS_64) && !defined(MA_64BIT)
+ static MA_INLINE ma_uint64 __stdcall ma_atomic_fetch_add_explicit_64(volatile ma_uint64* dst, ma_uint64 src, ma_atomic_memory_order order)
{
- c89atomic_uint64 oldValue;
- c89atomic_uint64 newValue;
+ ma_uint64 oldValue;
+ ma_uint64 newValue;
do {
oldValue = *dst;
newValue = oldValue + src;
- } while (c89atomic_compare_and_swap_64(dst, oldValue, newValue) != oldValue);
+ } while (ma_atomic_compare_and_swap_64(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
}
#endif
- #if defined(C89ATOMIC_MSVC_USE_INLINED_ASSEMBLY)
- static C89ATOMIC_INLINE void __stdcall c89atomic_thread_fence(c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_MSVC_USE_INLINED_ASSEMBLY)
+ static MA_INLINE void __stdcall ma_atomic_thread_fence(ma_atomic_memory_order order)
{
(void)order;
__asm {
@@ -14020,985 +14396,1067 @@ typedef unsigned char c89atomic_bool;
}
}
#else
- #if defined(C89ATOMIC_X64)
- #define c89atomic_thread_fence(order) __faststorefence(), (void)order
+ #if defined(MA_X64)
+ #define ma_atomic_thread_fence(order) __faststorefence(), (void)order
+ #elif defined(MA_ARM64)
+ #define ma_atomic_thread_fence(order) __dmb(_ARM64_BARRIER_ISH), (void)order
#else
- static C89ATOMIC_INLINE void c89atomic_thread_fence(c89atomic_memory_order order)
+ static MA_INLINE void ma_atomic_thread_fence(ma_atomic_memory_order order)
{
- volatile c89atomic_uint32 barrier = 0;
- c89atomic_fetch_add_explicit_32(&barrier, 0, order);
+ volatile ma_uint32 barrier = 0;
+ ma_atomic_fetch_add_explicit_32(&barrier, 0, order);
}
#endif
#endif
- #define c89atomic_compiler_fence() c89atomic_thread_fence(c89atomic_memory_order_seq_cst)
- #define c89atomic_signal_fence(order) c89atomic_thread_fence(order)
- #if defined(C89ATOMIC_HAS_8)
- static C89ATOMIC_INLINE c89atomic_uint8 c89atomic_load_explicit_8(volatile const c89atomic_uint8* ptr, c89atomic_memory_order order)
+ #define ma_atomic_compiler_fence() ma_atomic_thread_fence(ma_atomic_memory_order_seq_cst)
+ #define ma_atomic_signal_fence(order) ma_atomic_thread_fence(order)
+ #if defined(MA_ATOMIC_HAS_8)
+ static MA_INLINE ma_uint8 ma_atomic_load_explicit_8(volatile const ma_uint8* ptr, ma_atomic_memory_order order)
{
+ #if defined(MA_ARM)
+ MA_ATOMIC_MSVC_ARM_INTRINSIC_COMPARE_EXCHANGE(ptr, 0, 0, order, _InterlockedCompareExchange8, ma_uint8, char);
+ #else
(void)order;
- return c89atomic_compare_and_swap_8((volatile c89atomic_uint8*)ptr, 0, 0);
+ return ma_atomic_compare_and_swap_8((volatile ma_uint8*)ptr, 0, 0);
+ #endif
}
#endif
- #if defined(C89ATOMIC_HAS_16)
- static C89ATOMIC_INLINE c89atomic_uint16 c89atomic_load_explicit_16(volatile const c89atomic_uint16* ptr, c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_HAS_16)
+ static MA_INLINE ma_uint16 ma_atomic_load_explicit_16(volatile const ma_uint16* ptr, ma_atomic_memory_order order)
{
+ #if defined(MA_ARM)
+ MA_ATOMIC_MSVC_ARM_INTRINSIC_COMPARE_EXCHANGE(ptr, 0, 0, order, _InterlockedCompareExchange16, ma_uint16, short);
+ #else
(void)order;
- return c89atomic_compare_and_swap_16((volatile c89atomic_uint16*)ptr, 0, 0);
+ return ma_atomic_compare_and_swap_16((volatile ma_uint16*)ptr, 0, 0);
+ #endif
}
#endif
- #if defined(C89ATOMIC_HAS_32)
- static C89ATOMIC_INLINE c89atomic_uint32 c89atomic_load_explicit_32(volatile const c89atomic_uint32* ptr, c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_HAS_32)
+ static MA_INLINE ma_uint32 ma_atomic_load_explicit_32(volatile const ma_uint32* ptr, ma_atomic_memory_order order)
{
+ #if defined(MA_ARM)
+ MA_ATOMIC_MSVC_ARM_INTRINSIC_COMPARE_EXCHANGE(ptr, 0, 0, order, _InterlockedCompareExchange, ma_uint32, long);
+ #else
(void)order;
- return c89atomic_compare_and_swap_32((volatile c89atomic_uint32*)ptr, 0, 0);
+ return ma_atomic_compare_and_swap_32((volatile ma_uint32*)ptr, 0, 0);
+ #endif
}
#endif
- #if defined(C89ATOMIC_HAS_64)
- static C89ATOMIC_INLINE c89atomic_uint64 c89atomic_load_explicit_64(volatile const c89atomic_uint64* ptr, c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_HAS_64)
+ static MA_INLINE ma_uint64 ma_atomic_load_explicit_64(volatile const ma_uint64* ptr, ma_atomic_memory_order order)
{
+ #if defined(MA_ARM)
+ MA_ATOMIC_MSVC_ARM_INTRINSIC_COMPARE_EXCHANGE(ptr, 0, 0, order, _InterlockedCompareExchange64, ma_uint64, long long);
+ #else
(void)order;
- return c89atomic_compare_and_swap_64((volatile c89atomic_uint64*)ptr, 0, 0);
+ return ma_atomic_compare_and_swap_64((volatile ma_uint64*)ptr, 0, 0);
+ #endif
}
#endif
- #if defined(C89ATOMIC_HAS_8)
- #define c89atomic_store_explicit_8( dst, src, order) (void)c89atomic_exchange_explicit_8 (dst, src, order)
+ #if defined(MA_ATOMIC_HAS_8)
+ #define ma_atomic_store_explicit_8( dst, src, order) (void)ma_atomic_exchange_explicit_8 (dst, src, order)
#endif
- #if defined(C89ATOMIC_HAS_16)
- #define c89atomic_store_explicit_16(dst, src, order) (void)c89atomic_exchange_explicit_16(dst, src, order)
+ #if defined(MA_ATOMIC_HAS_16)
+ #define ma_atomic_store_explicit_16(dst, src, order) (void)ma_atomic_exchange_explicit_16(dst, src, order)
#endif
- #if defined(C89ATOMIC_HAS_32)
- #define c89atomic_store_explicit_32(dst, src, order) (void)c89atomic_exchange_explicit_32(dst, src, order)
+ #if defined(MA_ATOMIC_HAS_32)
+ #define ma_atomic_store_explicit_32(dst, src, order) (void)ma_atomic_exchange_explicit_32(dst, src, order)
#endif
- #if defined(C89ATOMIC_HAS_64)
- #define c89atomic_store_explicit_64(dst, src, order) (void)c89atomic_exchange_explicit_64(dst, src, order)
+ #if defined(MA_ATOMIC_HAS_64)
+ #define ma_atomic_store_explicit_64(dst, src, order) (void)ma_atomic_exchange_explicit_64(dst, src, order)
#endif
- #if defined(C89ATOMIC_HAS_8)
- static C89ATOMIC_INLINE c89atomic_uint8 __stdcall c89atomic_fetch_sub_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_HAS_8)
+ static MA_INLINE ma_uint8 __stdcall ma_atomic_fetch_sub_explicit_8(volatile ma_uint8* dst, ma_uint8 src, ma_atomic_memory_order order)
{
- c89atomic_uint8 oldValue;
- c89atomic_uint8 newValue;
+ ma_uint8 oldValue;
+ ma_uint8 newValue;
do {
oldValue = *dst;
- newValue = (c89atomic_uint8)(oldValue - src);
- } while (c89atomic_compare_and_swap_8(dst, oldValue, newValue) != oldValue);
+ newValue = (ma_uint8)(oldValue - src);
+ } while (ma_atomic_compare_and_swap_8(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
}
#endif
- #if defined(C89ATOMIC_HAS_16)
- static C89ATOMIC_INLINE c89atomic_uint16 __stdcall c89atomic_fetch_sub_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_HAS_16)
+ static MA_INLINE ma_uint16 __stdcall ma_atomic_fetch_sub_explicit_16(volatile ma_uint16* dst, ma_uint16 src, ma_atomic_memory_order order)
{
- c89atomic_uint16 oldValue;
- c89atomic_uint16 newValue;
+ ma_uint16 oldValue;
+ ma_uint16 newValue;
do {
oldValue = *dst;
- newValue = (c89atomic_uint16)(oldValue - src);
- } while (c89atomic_compare_and_swap_16(dst, oldValue, newValue) != oldValue);
+ newValue = (ma_uint16)(oldValue - src);
+ } while (ma_atomic_compare_and_swap_16(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
}
#endif
- #if defined(C89ATOMIC_HAS_32)
- static C89ATOMIC_INLINE c89atomic_uint32 __stdcall c89atomic_fetch_sub_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_HAS_32)
+ static MA_INLINE ma_uint32 __stdcall ma_atomic_fetch_sub_explicit_32(volatile ma_uint32* dst, ma_uint32 src, ma_atomic_memory_order order)
{
- c89atomic_uint32 oldValue;
- c89atomic_uint32 newValue;
+ ma_uint32 oldValue;
+ ma_uint32 newValue;
do {
oldValue = *dst;
newValue = oldValue - src;
- } while (c89atomic_compare_and_swap_32(dst, oldValue, newValue) != oldValue);
+ } while (ma_atomic_compare_and_swap_32(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
}
#endif
- #if defined(C89ATOMIC_HAS_64)
- static C89ATOMIC_INLINE c89atomic_uint64 __stdcall c89atomic_fetch_sub_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_HAS_64)
+ static MA_INLINE ma_uint64 __stdcall ma_atomic_fetch_sub_explicit_64(volatile ma_uint64* dst, ma_uint64 src, ma_atomic_memory_order order)
{
- c89atomic_uint64 oldValue;
- c89atomic_uint64 newValue;
+ ma_uint64 oldValue;
+ ma_uint64 newValue;
do {
oldValue = *dst;
newValue = oldValue - src;
- } while (c89atomic_compare_and_swap_64(dst, oldValue, newValue) != oldValue);
+ } while (ma_atomic_compare_and_swap_64(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
}
#endif
- #if defined(C89ATOMIC_HAS_8)
- static C89ATOMIC_INLINE c89atomic_uint8 __stdcall c89atomic_fetch_and_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_HAS_8)
+ static MA_INLINE ma_uint8 __stdcall ma_atomic_fetch_and_explicit_8(volatile ma_uint8* dst, ma_uint8 src, ma_atomic_memory_order order)
{
- c89atomic_uint8 oldValue;
- c89atomic_uint8 newValue;
+ #if defined(MA_ARM)
+ MA_ATOMIC_MSVC_ARM_INTRINSIC(dst, src, order, _InterlockedAnd8, ma_uint8, char);
+ #else
+ ma_uint8 oldValue;
+ ma_uint8 newValue;
do {
oldValue = *dst;
- newValue = (c89atomic_uint8)(oldValue & src);
- } while (c89atomic_compare_and_swap_8(dst, oldValue, newValue) != oldValue);
+ newValue = (ma_uint8)(oldValue & src);
+ } while (ma_atomic_compare_and_swap_8(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
+ #endif
}
#endif
- #if defined(C89ATOMIC_HAS_16)
- static C89ATOMIC_INLINE c89atomic_uint16 __stdcall c89atomic_fetch_and_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_HAS_16)
+ static MA_INLINE ma_uint16 __stdcall ma_atomic_fetch_and_explicit_16(volatile ma_uint16* dst, ma_uint16 src, ma_atomic_memory_order order)
{
- c89atomic_uint16 oldValue;
- c89atomic_uint16 newValue;
+ #if defined(MA_ARM)
+ MA_ATOMIC_MSVC_ARM_INTRINSIC(dst, src, order, _InterlockedAnd16, ma_uint16, short);
+ #else
+ ma_uint16 oldValue;
+ ma_uint16 newValue;
do {
oldValue = *dst;
- newValue = (c89atomic_uint16)(oldValue & src);
- } while (c89atomic_compare_and_swap_16(dst, oldValue, newValue) != oldValue);
+ newValue = (ma_uint16)(oldValue & src);
+ } while (ma_atomic_compare_and_swap_16(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
+ #endif
}
#endif
- #if defined(C89ATOMIC_HAS_32)
- static C89ATOMIC_INLINE c89atomic_uint32 __stdcall c89atomic_fetch_and_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_HAS_32)
+ static MA_INLINE ma_uint32 __stdcall ma_atomic_fetch_and_explicit_32(volatile ma_uint32* dst, ma_uint32 src, ma_atomic_memory_order order)
{
- c89atomic_uint32 oldValue;
- c89atomic_uint32 newValue;
+ #if defined(MA_ARM)
+ MA_ATOMIC_MSVC_ARM_INTRINSIC(dst, src, order, _InterlockedAnd, ma_uint32, long);
+ #else
+ ma_uint32 oldValue;
+ ma_uint32 newValue;
do {
oldValue = *dst;
newValue = oldValue & src;
- } while (c89atomic_compare_and_swap_32(dst, oldValue, newValue) != oldValue);
+ } while (ma_atomic_compare_and_swap_32(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
+ #endif
}
#endif
- #if defined(C89ATOMIC_HAS_64)
- static C89ATOMIC_INLINE c89atomic_uint64 __stdcall c89atomic_fetch_and_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_HAS_64)
+ static MA_INLINE ma_uint64 __stdcall ma_atomic_fetch_and_explicit_64(volatile ma_uint64* dst, ma_uint64 src, ma_atomic_memory_order order)
{
- c89atomic_uint64 oldValue;
- c89atomic_uint64 newValue;
+ #if defined(MA_ARM)
+ MA_ATOMIC_MSVC_ARM_INTRINSIC(dst, src, order, _InterlockedAnd64, ma_uint64, long long);
+ #else
+ ma_uint64 oldValue;
+ ma_uint64 newValue;
do {
oldValue = *dst;
newValue = oldValue & src;
- } while (c89atomic_compare_and_swap_64(dst, oldValue, newValue) != oldValue);
+ } while (ma_atomic_compare_and_swap_64(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
+ #endif
}
#endif
- #if defined(C89ATOMIC_HAS_8)
- static C89ATOMIC_INLINE c89atomic_uint8 __stdcall c89atomic_fetch_xor_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_HAS_8)
+ static MA_INLINE ma_uint8 __stdcall ma_atomic_fetch_xor_explicit_8(volatile ma_uint8* dst, ma_uint8 src, ma_atomic_memory_order order)
{
- c89atomic_uint8 oldValue;
- c89atomic_uint8 newValue;
+ #if defined(MA_ARM)
+ MA_ATOMIC_MSVC_ARM_INTRINSIC(dst, src, order, _InterlockedXor8, ma_uint8, char);
+ #else
+ ma_uint8 oldValue;
+ ma_uint8 newValue;
do {
oldValue = *dst;
- newValue = (c89atomic_uint8)(oldValue ^ src);
- } while (c89atomic_compare_and_swap_8(dst, oldValue, newValue) != oldValue);
+ newValue = (ma_uint8)(oldValue ^ src);
+ } while (ma_atomic_compare_and_swap_8(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
+ #endif
}
#endif
- #if defined(C89ATOMIC_HAS_16)
- static C89ATOMIC_INLINE c89atomic_uint16 __stdcall c89atomic_fetch_xor_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_HAS_16)
+ static MA_INLINE ma_uint16 __stdcall ma_atomic_fetch_xor_explicit_16(volatile ma_uint16* dst, ma_uint16 src, ma_atomic_memory_order order)
{
- c89atomic_uint16 oldValue;
- c89atomic_uint16 newValue;
+ #if defined(MA_ARM)
+ MA_ATOMIC_MSVC_ARM_INTRINSIC(dst, src, order, _InterlockedXor16, ma_uint16, short);
+ #else
+ ma_uint16 oldValue;
+ ma_uint16 newValue;
do {
oldValue = *dst;
- newValue = (c89atomic_uint16)(oldValue ^ src);
- } while (c89atomic_compare_and_swap_16(dst, oldValue, newValue) != oldValue);
+ newValue = (ma_uint16)(oldValue ^ src);
+ } while (ma_atomic_compare_and_swap_16(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
+ #endif
}
#endif
- #if defined(C89ATOMIC_HAS_32)
- static C89ATOMIC_INLINE c89atomic_uint32 __stdcall c89atomic_fetch_xor_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_HAS_32)
+ static MA_INLINE ma_uint32 __stdcall ma_atomic_fetch_xor_explicit_32(volatile ma_uint32* dst, ma_uint32 src, ma_atomic_memory_order order)
{
- c89atomic_uint32 oldValue;
- c89atomic_uint32 newValue;
+ #if defined(MA_ARM)
+ MA_ATOMIC_MSVC_ARM_INTRINSIC(dst, src, order, _InterlockedXor, ma_uint32, long);
+ #else
+ ma_uint32 oldValue;
+ ma_uint32 newValue;
do {
oldValue = *dst;
newValue = oldValue ^ src;
- } while (c89atomic_compare_and_swap_32(dst, oldValue, newValue) != oldValue);
+ } while (ma_atomic_compare_and_swap_32(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
+ #endif
}
#endif
- #if defined(C89ATOMIC_HAS_64)
- static C89ATOMIC_INLINE c89atomic_uint64 __stdcall c89atomic_fetch_xor_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_HAS_64)
+ static MA_INLINE ma_uint64 __stdcall ma_atomic_fetch_xor_explicit_64(volatile ma_uint64* dst, ma_uint64 src, ma_atomic_memory_order order)
{
- c89atomic_uint64 oldValue;
- c89atomic_uint64 newValue;
+ #if defined(MA_ARM)
+ MA_ATOMIC_MSVC_ARM_INTRINSIC(dst, src, order, _InterlockedXor64, ma_uint64, long long);
+ #else
+ ma_uint64 oldValue;
+ ma_uint64 newValue;
do {
oldValue = *dst;
newValue = oldValue ^ src;
- } while (c89atomic_compare_and_swap_64(dst, oldValue, newValue) != oldValue);
+ } while (ma_atomic_compare_and_swap_64(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
+ #endif
}
#endif
- #if defined(C89ATOMIC_HAS_8)
- static C89ATOMIC_INLINE c89atomic_uint8 __stdcall c89atomic_fetch_or_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_HAS_8)
+ static MA_INLINE ma_uint8 __stdcall ma_atomic_fetch_or_explicit_8(volatile ma_uint8* dst, ma_uint8 src, ma_atomic_memory_order order)
{
- c89atomic_uint8 oldValue;
- c89atomic_uint8 newValue;
+ #if defined(MA_ARM)
+ MA_ATOMIC_MSVC_ARM_INTRINSIC(dst, src, order, _InterlockedOr8, ma_uint8, char);
+ #else
+ ma_uint8 oldValue;
+ ma_uint8 newValue;
do {
oldValue = *dst;
- newValue = (c89atomic_uint8)(oldValue | src);
- } while (c89atomic_compare_and_swap_8(dst, oldValue, newValue) != oldValue);
+ newValue = (ma_uint8)(oldValue | src);
+ } while (ma_atomic_compare_and_swap_8(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
+ #endif
}
#endif
- #if defined(C89ATOMIC_HAS_16)
- static C89ATOMIC_INLINE c89atomic_uint16 __stdcall c89atomic_fetch_or_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_HAS_16)
+ static MA_INLINE ma_uint16 __stdcall ma_atomic_fetch_or_explicit_16(volatile ma_uint16* dst, ma_uint16 src, ma_atomic_memory_order order)
{
- c89atomic_uint16 oldValue;
- c89atomic_uint16 newValue;
+ #if defined(MA_ARM)
+ MA_ATOMIC_MSVC_ARM_INTRINSIC(dst, src, order, _InterlockedOr16, ma_uint16, short);
+ #else
+ ma_uint16 oldValue;
+ ma_uint16 newValue;
do {
oldValue = *dst;
- newValue = (c89atomic_uint16)(oldValue | src);
- } while (c89atomic_compare_and_swap_16(dst, oldValue, newValue) != oldValue);
+ newValue = (ma_uint16)(oldValue | src);
+ } while (ma_atomic_compare_and_swap_16(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
+ #endif
}
#endif
- #if defined(C89ATOMIC_HAS_32)
- static C89ATOMIC_INLINE c89atomic_uint32 __stdcall c89atomic_fetch_or_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_HAS_32)
+ static MA_INLINE ma_uint32 __stdcall ma_atomic_fetch_or_explicit_32(volatile ma_uint32* dst, ma_uint32 src, ma_atomic_memory_order order)
{
- c89atomic_uint32 oldValue;
- c89atomic_uint32 newValue;
+ #if defined(MA_ARM)
+ MA_ATOMIC_MSVC_ARM_INTRINSIC(dst, src, order, _InterlockedOr, ma_uint32, long);
+ #else
+ ma_uint32 oldValue;
+ ma_uint32 newValue;
do {
oldValue = *dst;
newValue = oldValue | src;
- } while (c89atomic_compare_and_swap_32(dst, oldValue, newValue) != oldValue);
+ } while (ma_atomic_compare_and_swap_32(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
+ #endif
}
#endif
- #if defined(C89ATOMIC_HAS_64)
- static C89ATOMIC_INLINE c89atomic_uint64 __stdcall c89atomic_fetch_or_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order)
+ #if defined(MA_ATOMIC_HAS_64)
+ static MA_INLINE ma_uint64 __stdcall ma_atomic_fetch_or_explicit_64(volatile ma_uint64* dst, ma_uint64 src, ma_atomic_memory_order order)
{
- c89atomic_uint64 oldValue;
- c89atomic_uint64 newValue;
+ #if defined(MA_ARM)
+ MA_ATOMIC_MSVC_ARM_INTRINSIC(dst, src, order, _InterlockedOr64, ma_uint64, long long);
+ #else
+ ma_uint64 oldValue;
+ ma_uint64 newValue;
do {
oldValue = *dst;
newValue = oldValue | src;
- } while (c89atomic_compare_and_swap_64(dst, oldValue, newValue) != oldValue);
+ } while (ma_atomic_compare_and_swap_64(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
+ #endif
}
#endif
- #if defined(C89ATOMIC_HAS_8)
- #define c89atomic_test_and_set_explicit_8( dst, order) c89atomic_exchange_explicit_8 (dst, 1, order)
+ #if defined(MA_ATOMIC_HAS_8)
+ #define ma_atomic_test_and_set_explicit_8( dst, order) ma_atomic_exchange_explicit_8 (dst, 1, order)
#endif
- #if defined(C89ATOMIC_HAS_16)
- #define c89atomic_test_and_set_explicit_16(dst, order) c89atomic_exchange_explicit_16(dst, 1, order)
+ #if defined(MA_ATOMIC_HAS_16)
+ #define ma_atomic_test_and_set_explicit_16(dst, order) ma_atomic_exchange_explicit_16(dst, 1, order)
#endif
- #if defined(C89ATOMIC_HAS_32)
- #define c89atomic_test_and_set_explicit_32(dst, order) c89atomic_exchange_explicit_32(dst, 1, order)
+ #if defined(MA_ATOMIC_HAS_32)
+ #define ma_atomic_test_and_set_explicit_32(dst, order) ma_atomic_exchange_explicit_32(dst, 1, order)
#endif
- #if defined(C89ATOMIC_HAS_64)
- #define c89atomic_test_and_set_explicit_64(dst, order) c89atomic_exchange_explicit_64(dst, 1, order)
+ #if defined(MA_ATOMIC_HAS_64)
+ #define ma_atomic_test_and_set_explicit_64(dst, order) ma_atomic_exchange_explicit_64(dst, 1, order)
#endif
- #if defined(C89ATOMIC_HAS_8)
- #define c89atomic_clear_explicit_8( dst, order) c89atomic_store_explicit_8 (dst, 0, order)
+ #if defined(MA_ATOMIC_HAS_8)
+ #define ma_atomic_clear_explicit_8( dst, order) ma_atomic_store_explicit_8 (dst, 0, order)
#endif
- #if defined(C89ATOMIC_HAS_16)
- #define c89atomic_clear_explicit_16(dst, order) c89atomic_store_explicit_16(dst, 0, order)
+ #if defined(MA_ATOMIC_HAS_16)
+ #define ma_atomic_clear_explicit_16(dst, order) ma_atomic_store_explicit_16(dst, 0, order)
#endif
- #if defined(C89ATOMIC_HAS_32)
- #define c89atomic_clear_explicit_32(dst, order) c89atomic_store_explicit_32(dst, 0, order)
+ #if defined(MA_ATOMIC_HAS_32)
+ #define ma_atomic_clear_explicit_32(dst, order) ma_atomic_store_explicit_32(dst, 0, order)
#endif
- #if defined(C89ATOMIC_HAS_64)
- #define c89atomic_clear_explicit_64(dst, order) c89atomic_store_explicit_64(dst, 0, order)
+ #if defined(MA_ATOMIC_HAS_64)
+ #define ma_atomic_clear_explicit_64(dst, order) ma_atomic_store_explicit_64(dst, 0, order)
#endif
- #if defined(C89ATOMIC_HAS_8)
- typedef c89atomic_uint8 c89atomic_flag;
- #define c89atomic_flag_test_and_set_explicit(ptr, order) (c89atomic_bool)c89atomic_test_and_set_explicit_8(ptr, order)
- #define c89atomic_flag_clear_explicit(ptr, order) c89atomic_clear_explicit_8(ptr, order)
- #define c89atoimc_flag_load_explicit(ptr, order) c89atomic_load_explicit_8(ptr, order)
+ #if defined(MA_ATOMIC_HAS_8)
+ typedef ma_uint8 ma_atomic_flag;
+ #define ma_atomic_flag_test_and_set_explicit(ptr, order) (ma_bool32)ma_atomic_test_and_set_explicit_8(ptr, order)
+ #define ma_atomic_flag_clear_explicit(ptr, order) ma_atomic_clear_explicit_8(ptr, order)
+ #define c89atoimc_flag_load_explicit(ptr, order) ma_atomic_load_explicit_8(ptr, order)
#else
- typedef c89atomic_uint32 c89atomic_flag;
- #define c89atomic_flag_test_and_set_explicit(ptr, order) (c89atomic_bool)c89atomic_test_and_set_explicit_32(ptr, order)
- #define c89atomic_flag_clear_explicit(ptr, order) c89atomic_clear_explicit_32(ptr, order)
- #define c89atoimc_flag_load_explicit(ptr, order) c89atomic_load_explicit_32(ptr, order)
+ typedef ma_uint32 ma_atomic_flag;
+ #define ma_atomic_flag_test_and_set_explicit(ptr, order) (ma_bool32)ma_atomic_test_and_set_explicit_32(ptr, order)
+ #define ma_atomic_flag_clear_explicit(ptr, order) ma_atomic_clear_explicit_32(ptr, order)
+ #define c89atoimc_flag_load_explicit(ptr, order) ma_atomic_load_explicit_32(ptr, order)
#endif
#elif defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)))
- #define C89ATOMIC_HAS_NATIVE_COMPARE_EXCHANGE
- #define C89ATOMIC_HAS_NATIVE_IS_LOCK_FREE
- #define c89atomic_memory_order_relaxed __ATOMIC_RELAXED
- #define c89atomic_memory_order_consume __ATOMIC_CONSUME
- #define c89atomic_memory_order_acquire __ATOMIC_ACQUIRE
- #define c89atomic_memory_order_release __ATOMIC_RELEASE
- #define c89atomic_memory_order_acq_rel __ATOMIC_ACQ_REL
- #define c89atomic_memory_order_seq_cst __ATOMIC_SEQ_CST
- #define c89atomic_compiler_fence() __asm__ __volatile__("":::"memory")
- #define c89atomic_thread_fence(order) __atomic_thread_fence(order)
- #define c89atomic_signal_fence(order) __atomic_signal_fence(order)
- #define c89atomic_is_lock_free_8(ptr) __atomic_is_lock_free(1, ptr)
- #define c89atomic_is_lock_free_16(ptr) __atomic_is_lock_free(2, ptr)
- #define c89atomic_is_lock_free_32(ptr) __atomic_is_lock_free(4, ptr)
- #define c89atomic_is_lock_free_64(ptr) __atomic_is_lock_free(8, ptr)
- #define c89atomic_test_and_set_explicit_8( dst, order) __atomic_exchange_n(dst, 1, order)
- #define c89atomic_test_and_set_explicit_16(dst, order) __atomic_exchange_n(dst, 1, order)
- #define c89atomic_test_and_set_explicit_32(dst, order) __atomic_exchange_n(dst, 1, order)
- #define c89atomic_test_and_set_explicit_64(dst, order) __atomic_exchange_n(dst, 1, order)
- #define c89atomic_clear_explicit_8( dst, order) __atomic_store_n(dst, 0, order)
- #define c89atomic_clear_explicit_16(dst, order) __atomic_store_n(dst, 0, order)
- #define c89atomic_clear_explicit_32(dst, order) __atomic_store_n(dst, 0, order)
- #define c89atomic_clear_explicit_64(dst, order) __atomic_store_n(dst, 0, order)
- #define c89atomic_store_explicit_8( dst, src, order) __atomic_store_n(dst, src, order)
- #define c89atomic_store_explicit_16(dst, src, order) __atomic_store_n(dst, src, order)
- #define c89atomic_store_explicit_32(dst, src, order) __atomic_store_n(dst, src, order)
- #define c89atomic_store_explicit_64(dst, src, order) __atomic_store_n(dst, src, order)
- #define c89atomic_load_explicit_8( dst, order) __atomic_load_n(dst, order)
- #define c89atomic_load_explicit_16(dst, order) __atomic_load_n(dst, order)
- #define c89atomic_load_explicit_32(dst, order) __atomic_load_n(dst, order)
- #define c89atomic_load_explicit_64(dst, order) __atomic_load_n(dst, order)
- #define c89atomic_exchange_explicit_8( dst, src, order) __atomic_exchange_n(dst, src, order)
- #define c89atomic_exchange_explicit_16(dst, src, order) __atomic_exchange_n(dst, src, order)
- #define c89atomic_exchange_explicit_32(dst, src, order) __atomic_exchange_n(dst, src, order)
- #define c89atomic_exchange_explicit_64(dst, src, order) __atomic_exchange_n(dst, src, order)
- #define c89atomic_compare_exchange_strong_explicit_8( dst, expected, desired, successOrder, failureOrder) __atomic_compare_exchange_n(dst, expected, desired, 0, successOrder, failureOrder)
- #define c89atomic_compare_exchange_strong_explicit_16(dst, expected, desired, successOrder, failureOrder) __atomic_compare_exchange_n(dst, expected, desired, 0, successOrder, failureOrder)
- #define c89atomic_compare_exchange_strong_explicit_32(dst, expected, desired, successOrder, failureOrder) __atomic_compare_exchange_n(dst, expected, desired, 0, successOrder, failureOrder)
- #define c89atomic_compare_exchange_strong_explicit_64(dst, expected, desired, successOrder, failureOrder) __atomic_compare_exchange_n(dst, expected, desired, 0, successOrder, failureOrder)
- #define c89atomic_compare_exchange_weak_explicit_8( dst, expected, desired, successOrder, failureOrder) __atomic_compare_exchange_n(dst, expected, desired, 1, successOrder, failureOrder)
- #define c89atomic_compare_exchange_weak_explicit_16(dst, expected, desired, successOrder, failureOrder) __atomic_compare_exchange_n(dst, expected, desired, 1, successOrder, failureOrder)
- #define c89atomic_compare_exchange_weak_explicit_32(dst, expected, desired, successOrder, failureOrder) __atomic_compare_exchange_n(dst, expected, desired, 1, successOrder, failureOrder)
- #define c89atomic_compare_exchange_weak_explicit_64(dst, expected, desired, successOrder, failureOrder) __atomic_compare_exchange_n(dst, expected, desired, 1, successOrder, failureOrder)
- #define c89atomic_fetch_add_explicit_8( dst, src, order) __atomic_fetch_add(dst, src, order)
- #define c89atomic_fetch_add_explicit_16(dst, src, order) __atomic_fetch_add(dst, src, order)
- #define c89atomic_fetch_add_explicit_32(dst, src, order) __atomic_fetch_add(dst, src, order)
- #define c89atomic_fetch_add_explicit_64(dst, src, order) __atomic_fetch_add(dst, src, order)
- #define c89atomic_fetch_sub_explicit_8( dst, src, order) __atomic_fetch_sub(dst, src, order)
- #define c89atomic_fetch_sub_explicit_16(dst, src, order) __atomic_fetch_sub(dst, src, order)
- #define c89atomic_fetch_sub_explicit_32(dst, src, order) __atomic_fetch_sub(dst, src, order)
- #define c89atomic_fetch_sub_explicit_64(dst, src, order) __atomic_fetch_sub(dst, src, order)
- #define c89atomic_fetch_or_explicit_8( dst, src, order) __atomic_fetch_or(dst, src, order)
- #define c89atomic_fetch_or_explicit_16(dst, src, order) __atomic_fetch_or(dst, src, order)
- #define c89atomic_fetch_or_explicit_32(dst, src, order) __atomic_fetch_or(dst, src, order)
- #define c89atomic_fetch_or_explicit_64(dst, src, order) __atomic_fetch_or(dst, src, order)
- #define c89atomic_fetch_xor_explicit_8( dst, src, order) __atomic_fetch_xor(dst, src, order)
- #define c89atomic_fetch_xor_explicit_16(dst, src, order) __atomic_fetch_xor(dst, src, order)
- #define c89atomic_fetch_xor_explicit_32(dst, src, order) __atomic_fetch_xor(dst, src, order)
- #define c89atomic_fetch_xor_explicit_64(dst, src, order) __atomic_fetch_xor(dst, src, order)
- #define c89atomic_fetch_and_explicit_8( dst, src, order) __atomic_fetch_and(dst, src, order)
- #define c89atomic_fetch_and_explicit_16(dst, src, order) __atomic_fetch_and(dst, src, order)
- #define c89atomic_fetch_and_explicit_32(dst, src, order) __atomic_fetch_and(dst, src, order)
- #define c89atomic_fetch_and_explicit_64(dst, src, order) __atomic_fetch_and(dst, src, order)
- #define c89atomic_compare_and_swap_8 (dst, expected, desired) __sync_val_compare_and_swap(dst, expected, desired)
- #define c89atomic_compare_and_swap_16(dst, expected, desired) __sync_val_compare_and_swap(dst, expected, desired)
- #define c89atomic_compare_and_swap_32(dst, expected, desired) __sync_val_compare_and_swap(dst, expected, desired)
- #define c89atomic_compare_and_swap_64(dst, expected, desired) __sync_val_compare_and_swap(dst, expected, desired)
- typedef c89atomic_uint8 c89atomic_flag;
- #define c89atomic_flag_test_and_set_explicit(dst, order) (c89atomic_bool)__atomic_test_and_set(dst, order)
- #define c89atomic_flag_clear_explicit(dst, order) __atomic_clear(dst, order)
- #define c89atoimc_flag_load_explicit(ptr, order) c89atomic_load_explicit_8(ptr, order)
+ #define MA_ATOMIC_HAS_NATIVE_COMPARE_EXCHANGE
+ #define MA_ATOMIC_HAS_NATIVE_IS_LOCK_FREE
+ #define ma_atomic_memory_order_relaxed __ATOMIC_RELAXED
+ #define ma_atomic_memory_order_consume __ATOMIC_CONSUME
+ #define ma_atomic_memory_order_acquire __ATOMIC_ACQUIRE
+ #define ma_atomic_memory_order_release __ATOMIC_RELEASE
+ #define ma_atomic_memory_order_acq_rel __ATOMIC_ACQ_REL
+ #define ma_atomic_memory_order_seq_cst __ATOMIC_SEQ_CST
+ #define ma_atomic_compiler_fence() __asm__ __volatile__("":::"memory")
+ #define ma_atomic_thread_fence(order) __atomic_thread_fence(order)
+ #define ma_atomic_signal_fence(order) __atomic_signal_fence(order)
+ #define ma_atomic_is_lock_free_8(ptr) __atomic_is_lock_free(1, ptr)
+ #define ma_atomic_is_lock_free_16(ptr) __atomic_is_lock_free(2, ptr)
+ #define ma_atomic_is_lock_free_32(ptr) __atomic_is_lock_free(4, ptr)
+ #define ma_atomic_is_lock_free_64(ptr) __atomic_is_lock_free(8, ptr)
+ #define ma_atomic_test_and_set_explicit_8( dst, order) __atomic_exchange_n(dst, 1, order)
+ #define ma_atomic_test_and_set_explicit_16(dst, order) __atomic_exchange_n(dst, 1, order)
+ #define ma_atomic_test_and_set_explicit_32(dst, order) __atomic_exchange_n(dst, 1, order)
+ #define ma_atomic_test_and_set_explicit_64(dst, order) __atomic_exchange_n(dst, 1, order)
+ #define ma_atomic_clear_explicit_8( dst, order) __atomic_store_n(dst, 0, order)
+ #define ma_atomic_clear_explicit_16(dst, order) __atomic_store_n(dst, 0, order)
+ #define ma_atomic_clear_explicit_32(dst, order) __atomic_store_n(dst, 0, order)
+ #define ma_atomic_clear_explicit_64(dst, order) __atomic_store_n(dst, 0, order)
+ #define ma_atomic_store_explicit_8( dst, src, order) __atomic_store_n(dst, src, order)
+ #define ma_atomic_store_explicit_16(dst, src, order) __atomic_store_n(dst, src, order)
+ #define ma_atomic_store_explicit_32(dst, src, order) __atomic_store_n(dst, src, order)
+ #define ma_atomic_store_explicit_64(dst, src, order) __atomic_store_n(dst, src, order)
+ #define ma_atomic_load_explicit_8( dst, order) __atomic_load_n(dst, order)
+ #define ma_atomic_load_explicit_16(dst, order) __atomic_load_n(dst, order)
+ #define ma_atomic_load_explicit_32(dst, order) __atomic_load_n(dst, order)
+ #define ma_atomic_load_explicit_64(dst, order) __atomic_load_n(dst, order)
+ #define ma_atomic_exchange_explicit_8( dst, src, order) __atomic_exchange_n(dst, src, order)
+ #define ma_atomic_exchange_explicit_16(dst, src, order) __atomic_exchange_n(dst, src, order)
+ #define ma_atomic_exchange_explicit_32(dst, src, order) __atomic_exchange_n(dst, src, order)
+ #define ma_atomic_exchange_explicit_64(dst, src, order) __atomic_exchange_n(dst, src, order)
+ #define ma_atomic_compare_exchange_strong_explicit_8( dst, expected, desired, successOrder, failureOrder) __atomic_compare_exchange_n(dst, expected, desired, 0, successOrder, failureOrder)
+ #define ma_atomic_compare_exchange_strong_explicit_16(dst, expected, desired, successOrder, failureOrder) __atomic_compare_exchange_n(dst, expected, desired, 0, successOrder, failureOrder)
+ #define ma_atomic_compare_exchange_strong_explicit_32(dst, expected, desired, successOrder, failureOrder) __atomic_compare_exchange_n(dst, expected, desired, 0, successOrder, failureOrder)
+ #define ma_atomic_compare_exchange_strong_explicit_64(dst, expected, desired, successOrder, failureOrder) __atomic_compare_exchange_n(dst, expected, desired, 0, successOrder, failureOrder)
+ #define ma_atomic_compare_exchange_weak_explicit_8( dst, expected, desired, successOrder, failureOrder) __atomic_compare_exchange_n(dst, expected, desired, 1, successOrder, failureOrder)
+ #define ma_atomic_compare_exchange_weak_explicit_16(dst, expected, desired, successOrder, failureOrder) __atomic_compare_exchange_n(dst, expected, desired, 1, successOrder, failureOrder)
+ #define ma_atomic_compare_exchange_weak_explicit_32(dst, expected, desired, successOrder, failureOrder) __atomic_compare_exchange_n(dst, expected, desired, 1, successOrder, failureOrder)
+ #define ma_atomic_compare_exchange_weak_explicit_64(dst, expected, desired, successOrder, failureOrder) __atomic_compare_exchange_n(dst, expected, desired, 1, successOrder, failureOrder)
+ #define ma_atomic_fetch_add_explicit_8( dst, src, order) __atomic_fetch_add(dst, src, order)
+ #define ma_atomic_fetch_add_explicit_16(dst, src, order) __atomic_fetch_add(dst, src, order)
+ #define ma_atomic_fetch_add_explicit_32(dst, src, order) __atomic_fetch_add(dst, src, order)
+ #define ma_atomic_fetch_add_explicit_64(dst, src, order) __atomic_fetch_add(dst, src, order)
+ #define ma_atomic_fetch_sub_explicit_8( dst, src, order) __atomic_fetch_sub(dst, src, order)
+ #define ma_atomic_fetch_sub_explicit_16(dst, src, order) __atomic_fetch_sub(dst, src, order)
+ #define ma_atomic_fetch_sub_explicit_32(dst, src, order) __atomic_fetch_sub(dst, src, order)
+ #define ma_atomic_fetch_sub_explicit_64(dst, src, order) __atomic_fetch_sub(dst, src, order)
+ #define ma_atomic_fetch_or_explicit_8( dst, src, order) __atomic_fetch_or(dst, src, order)
+ #define ma_atomic_fetch_or_explicit_16(dst, src, order) __atomic_fetch_or(dst, src, order)
+ #define ma_atomic_fetch_or_explicit_32(dst, src, order) __atomic_fetch_or(dst, src, order)
+ #define ma_atomic_fetch_or_explicit_64(dst, src, order) __atomic_fetch_or(dst, src, order)
+ #define ma_atomic_fetch_xor_explicit_8( dst, src, order) __atomic_fetch_xor(dst, src, order)
+ #define ma_atomic_fetch_xor_explicit_16(dst, src, order) __atomic_fetch_xor(dst, src, order)
+ #define ma_atomic_fetch_xor_explicit_32(dst, src, order) __atomic_fetch_xor(dst, src, order)
+ #define ma_atomic_fetch_xor_explicit_64(dst, src, order) __atomic_fetch_xor(dst, src, order)
+ #define ma_atomic_fetch_and_explicit_8( dst, src, order) __atomic_fetch_and(dst, src, order)
+ #define ma_atomic_fetch_and_explicit_16(dst, src, order) __atomic_fetch_and(dst, src, order)
+ #define ma_atomic_fetch_and_explicit_32(dst, src, order) __atomic_fetch_and(dst, src, order)
+ #define ma_atomic_fetch_and_explicit_64(dst, src, order) __atomic_fetch_and(dst, src, order)
+ static MA_INLINE ma_uint8 ma_atomic_compare_and_swap_8(volatile ma_uint8* dst, ma_uint8 expected, ma_uint8 desired)
+ {
+ __atomic_compare_exchange_n(dst, &expected, desired, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
+ return expected;
+ }
+ static MA_INLINE ma_uint16 ma_atomic_compare_and_swap_16(volatile ma_uint16* dst, ma_uint16 expected, ma_uint16 desired)
+ {
+ __atomic_compare_exchange_n(dst, &expected, desired, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
+ return expected;
+ }
+ static MA_INLINE ma_uint32 ma_atomic_compare_and_swap_32(volatile ma_uint32* dst, ma_uint32 expected, ma_uint32 desired)
+ {
+ __atomic_compare_exchange_n(dst, &expected, desired, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
+ return expected;
+ }
+ static MA_INLINE ma_uint64 ma_atomic_compare_and_swap_64(volatile ma_uint64* dst, ma_uint64 expected, ma_uint64 desired)
+ {
+ __atomic_compare_exchange_n(dst, &expected, desired, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
+ return expected;
+ }
+ typedef ma_uint8 ma_atomic_flag;
+ #define ma_atomic_flag_test_and_set_explicit(dst, order) (ma_bool32)__atomic_test_and_set(dst, order)
+ #define ma_atomic_flag_clear_explicit(dst, order) __atomic_clear(dst, order)
+ #define c89atoimc_flag_load_explicit(ptr, order) ma_atomic_load_explicit_8(ptr, order)
#else
- #define c89atomic_memory_order_relaxed 1
- #define c89atomic_memory_order_consume 2
- #define c89atomic_memory_order_acquire 3
- #define c89atomic_memory_order_release 4
- #define c89atomic_memory_order_acq_rel 5
- #define c89atomic_memory_order_seq_cst 6
- #define c89atomic_compiler_fence() __asm__ __volatile__("":::"memory")
+ #define ma_atomic_memory_order_relaxed 1
+ #define ma_atomic_memory_order_consume 2
+ #define ma_atomic_memory_order_acquire 3
+ #define ma_atomic_memory_order_release 4
+ #define ma_atomic_memory_order_acq_rel 5
+ #define ma_atomic_memory_order_seq_cst 6
+ #define ma_atomic_compiler_fence() __asm__ __volatile__("":::"memory")
#if defined(__GNUC__)
- #define c89atomic_thread_fence(order) __sync_synchronize(), (void)order
- static C89ATOMIC_INLINE c89atomic_uint8 c89atomic_exchange_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order)
+ #define ma_atomic_thread_fence(order) __sync_synchronize(), (void)order
+ static MA_INLINE ma_uint8 ma_atomic_exchange_explicit_8(volatile ma_uint8* dst, ma_uint8 src, ma_atomic_memory_order order)
{
- if (order > c89atomic_memory_order_acquire) {
+ if (order > ma_atomic_memory_order_acquire) {
__sync_synchronize();
}
return __sync_lock_test_and_set(dst, src);
}
- static C89ATOMIC_INLINE c89atomic_uint16 c89atomic_exchange_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint16 ma_atomic_exchange_explicit_16(volatile ma_uint16* dst, ma_uint16 src, ma_atomic_memory_order order)
{
- c89atomic_uint16 oldValue;
+ ma_uint16 oldValue;
do {
oldValue = *dst;
} while (__sync_val_compare_and_swap(dst, oldValue, src) != oldValue);
(void)order;
return oldValue;
}
- static C89ATOMIC_INLINE c89atomic_uint32 c89atomic_exchange_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint32 ma_atomic_exchange_explicit_32(volatile ma_uint32* dst, ma_uint32 src, ma_atomic_memory_order order)
{
- c89atomic_uint32 oldValue;
+ ma_uint32 oldValue;
do {
oldValue = *dst;
} while (__sync_val_compare_and_swap(dst, oldValue, src) != oldValue);
(void)order;
return oldValue;
}
- static C89ATOMIC_INLINE c89atomic_uint64 c89atomic_exchange_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint64 ma_atomic_exchange_explicit_64(volatile ma_uint64* dst, ma_uint64 src, ma_atomic_memory_order order)
{
- c89atomic_uint64 oldValue;
+ ma_uint64 oldValue;
do {
oldValue = *dst;
} while (__sync_val_compare_and_swap(dst, oldValue, src) != oldValue);
(void)order;
return oldValue;
}
- static C89ATOMIC_INLINE c89atomic_uint8 c89atomic_fetch_add_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint8 ma_atomic_fetch_add_explicit_8(volatile ma_uint8* dst, ma_uint8 src, ma_atomic_memory_order order)
{
(void)order;
return __sync_fetch_and_add(dst, src);
}
- static C89ATOMIC_INLINE c89atomic_uint16 c89atomic_fetch_add_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint16 ma_atomic_fetch_add_explicit_16(volatile ma_uint16* dst, ma_uint16 src, ma_atomic_memory_order order)
{
(void)order;
return __sync_fetch_and_add(dst, src);
}
- static C89ATOMIC_INLINE c89atomic_uint32 c89atomic_fetch_add_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint32 ma_atomic_fetch_add_explicit_32(volatile ma_uint32* dst, ma_uint32 src, ma_atomic_memory_order order)
{
(void)order;
return __sync_fetch_and_add(dst, src);
}
- static C89ATOMIC_INLINE c89atomic_uint64 c89atomic_fetch_add_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint64 ma_atomic_fetch_add_explicit_64(volatile ma_uint64* dst, ma_uint64 src, ma_atomic_memory_order order)
{
(void)order;
return __sync_fetch_and_add(dst, src);
}
- static C89ATOMIC_INLINE c89atomic_uint8 c89atomic_fetch_sub_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint8 ma_atomic_fetch_sub_explicit_8(volatile ma_uint8* dst, ma_uint8 src, ma_atomic_memory_order order)
{
(void)order;
return __sync_fetch_and_sub(dst, src);
}
- static C89ATOMIC_INLINE c89atomic_uint16 c89atomic_fetch_sub_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint16 ma_atomic_fetch_sub_explicit_16(volatile ma_uint16* dst, ma_uint16 src, ma_atomic_memory_order order)
{
(void)order;
return __sync_fetch_and_sub(dst, src);
}
- static C89ATOMIC_INLINE c89atomic_uint32 c89atomic_fetch_sub_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint32 ma_atomic_fetch_sub_explicit_32(volatile ma_uint32* dst, ma_uint32 src, ma_atomic_memory_order order)
{
(void)order;
return __sync_fetch_and_sub(dst, src);
}
- static C89ATOMIC_INLINE c89atomic_uint64 c89atomic_fetch_sub_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint64 ma_atomic_fetch_sub_explicit_64(volatile ma_uint64* dst, ma_uint64 src, ma_atomic_memory_order order)
{
(void)order;
return __sync_fetch_and_sub(dst, src);
}
- static C89ATOMIC_INLINE c89atomic_uint8 c89atomic_fetch_or_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint8 ma_atomic_fetch_or_explicit_8(volatile ma_uint8* dst, ma_uint8 src, ma_atomic_memory_order order)
{
(void)order;
return __sync_fetch_and_or(dst, src);
}
- static C89ATOMIC_INLINE c89atomic_uint16 c89atomic_fetch_or_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint16 ma_atomic_fetch_or_explicit_16(volatile ma_uint16* dst, ma_uint16 src, ma_atomic_memory_order order)
{
(void)order;
return __sync_fetch_and_or(dst, src);
}
- static C89ATOMIC_INLINE c89atomic_uint32 c89atomic_fetch_or_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint32 ma_atomic_fetch_or_explicit_32(volatile ma_uint32* dst, ma_uint32 src, ma_atomic_memory_order order)
{
(void)order;
return __sync_fetch_and_or(dst, src);
}
- static C89ATOMIC_INLINE c89atomic_uint64 c89atomic_fetch_or_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint64 ma_atomic_fetch_or_explicit_64(volatile ma_uint64* dst, ma_uint64 src, ma_atomic_memory_order order)
{
(void)order;
return __sync_fetch_and_or(dst, src);
}
- static C89ATOMIC_INLINE c89atomic_uint8 c89atomic_fetch_xor_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint8 ma_atomic_fetch_xor_explicit_8(volatile ma_uint8* dst, ma_uint8 src, ma_atomic_memory_order order)
{
(void)order;
return __sync_fetch_and_xor(dst, src);
}
- static C89ATOMIC_INLINE c89atomic_uint16 c89atomic_fetch_xor_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint16 ma_atomic_fetch_xor_explicit_16(volatile ma_uint16* dst, ma_uint16 src, ma_atomic_memory_order order)
{
(void)order;
return __sync_fetch_and_xor(dst, src);
}
- static C89ATOMIC_INLINE c89atomic_uint32 c89atomic_fetch_xor_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint32 ma_atomic_fetch_xor_explicit_32(volatile ma_uint32* dst, ma_uint32 src, ma_atomic_memory_order order)
{
(void)order;
return __sync_fetch_and_xor(dst, src);
}
- static C89ATOMIC_INLINE c89atomic_uint64 c89atomic_fetch_xor_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint64 ma_atomic_fetch_xor_explicit_64(volatile ma_uint64* dst, ma_uint64 src, ma_atomic_memory_order order)
{
(void)order;
return __sync_fetch_and_xor(dst, src);
}
- static C89ATOMIC_INLINE c89atomic_uint8 c89atomic_fetch_and_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint8 ma_atomic_fetch_and_explicit_8(volatile ma_uint8* dst, ma_uint8 src, ma_atomic_memory_order order)
{
(void)order;
return __sync_fetch_and_and(dst, src);
}
- static C89ATOMIC_INLINE c89atomic_uint16 c89atomic_fetch_and_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint16 ma_atomic_fetch_and_explicit_16(volatile ma_uint16* dst, ma_uint16 src, ma_atomic_memory_order order)
{
(void)order;
return __sync_fetch_and_and(dst, src);
}
- static C89ATOMIC_INLINE c89atomic_uint32 c89atomic_fetch_and_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint32 ma_atomic_fetch_and_explicit_32(volatile ma_uint32* dst, ma_uint32 src, ma_atomic_memory_order order)
{
(void)order;
return __sync_fetch_and_and(dst, src);
}
- static C89ATOMIC_INLINE c89atomic_uint64 c89atomic_fetch_and_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint64 ma_atomic_fetch_and_explicit_64(volatile ma_uint64* dst, ma_uint64 src, ma_atomic_memory_order order)
{
(void)order;
return __sync_fetch_and_and(dst, src);
}
- #define c89atomic_compare_and_swap_8( dst, expected, desired) __sync_val_compare_and_swap(dst, expected, desired)
- #define c89atomic_compare_and_swap_16(dst, expected, desired) __sync_val_compare_and_swap(dst, expected, desired)
- #define c89atomic_compare_and_swap_32(dst, expected, desired) __sync_val_compare_and_swap(dst, expected, desired)
- #define c89atomic_compare_and_swap_64(dst, expected, desired) __sync_val_compare_and_swap(dst, expected, desired)
+ #define ma_atomic_compare_and_swap_8( dst, expected, desired) __sync_val_compare_and_swap(dst, expected, desired)
+ #define ma_atomic_compare_and_swap_16(dst, expected, desired) __sync_val_compare_and_swap(dst, expected, desired)
+ #define ma_atomic_compare_and_swap_32(dst, expected, desired) __sync_val_compare_and_swap(dst, expected, desired)
+ #define ma_atomic_compare_and_swap_64(dst, expected, desired) __sync_val_compare_and_swap(dst, expected, desired)
#else
- #if defined(C89ATOMIC_X86)
- #define c89atomic_thread_fence(order) __asm__ __volatile__("lock; addl $0, (%%esp)" ::: "memory", "cc")
- #elif defined(C89ATOMIC_X64)
- #define c89atomic_thread_fence(order) __asm__ __volatile__("lock; addq $0, (%%rsp)" ::: "memory", "cc")
+ #if defined(MA_X86)
+ #define ma_atomic_thread_fence(order) __asm__ __volatile__("lock; addl $0, (%%esp)" ::: "memory", "cc")
+ #elif defined(MA_X64)
+ #define ma_atomic_thread_fence(order) __asm__ __volatile__("lock; addq $0, (%%rsp)" ::: "memory", "cc")
#else
#error Unsupported architecture. Please submit a feature request.
#endif
- static C89ATOMIC_INLINE c89atomic_uint8 c89atomic_compare_and_swap_8(volatile c89atomic_uint8* dst, c89atomic_uint8 expected, c89atomic_uint8 desired)
+ static MA_INLINE ma_uint8 ma_atomic_compare_and_swap_8(volatile ma_uint8* dst, ma_uint8 expected, ma_uint8 desired)
{
- c89atomic_uint8 result;
- #if defined(C89ATOMIC_X86) || defined(C89ATOMIC_X64)
+ ma_uint8 result;
+ #if defined(MA_X86) || defined(MA_X64)
__asm__ __volatile__("lock; cmpxchg %3, %0" : "+m"(*dst), "=a"(result) : "a"(expected), "d"(desired) : "cc");
#else
#error Unsupported architecture. Please submit a feature request.
#endif
return result;
}
- static C89ATOMIC_INLINE c89atomic_uint16 c89atomic_compare_and_swap_16(volatile c89atomic_uint16* dst, c89atomic_uint16 expected, c89atomic_uint16 desired)
+ static MA_INLINE ma_uint16 ma_atomic_compare_and_swap_16(volatile ma_uint16* dst, ma_uint16 expected, ma_uint16 desired)
{
- c89atomic_uint16 result;
- #if defined(C89ATOMIC_X86) || defined(C89ATOMIC_X64)
+ ma_uint16 result;
+ #if defined(MA_X86) || defined(MA_X64)
__asm__ __volatile__("lock; cmpxchg %3, %0" : "+m"(*dst), "=a"(result) : "a"(expected), "d"(desired) : "cc");
#else
#error Unsupported architecture. Please submit a feature request.
#endif
return result;
}
- static C89ATOMIC_INLINE c89atomic_uint32 c89atomic_compare_and_swap_32(volatile c89atomic_uint32* dst, c89atomic_uint32 expected, c89atomic_uint32 desired)
+ static MA_INLINE ma_uint32 ma_atomic_compare_and_swap_32(volatile ma_uint32* dst, ma_uint32 expected, ma_uint32 desired)
{
- c89atomic_uint32 result;
- #if defined(C89ATOMIC_X86) || defined(C89ATOMIC_X64)
+ ma_uint32 result;
+ #if defined(MA_X86) || defined(MA_X64)
__asm__ __volatile__("lock; cmpxchg %3, %0" : "+m"(*dst), "=a"(result) : "a"(expected), "d"(desired) : "cc");
#else
#error Unsupported architecture. Please submit a feature request.
#endif
return result;
}
- static C89ATOMIC_INLINE c89atomic_uint64 c89atomic_compare_and_swap_64(volatile c89atomic_uint64* dst, c89atomic_uint64 expected, c89atomic_uint64 desired)
+ static MA_INLINE ma_uint64 ma_atomic_compare_and_swap_64(volatile ma_uint64* dst, ma_uint64 expected, ma_uint64 desired)
{
- volatile c89atomic_uint64 result;
- #if defined(C89ATOMIC_X86)
- c89atomic_uint32 resultEAX;
- c89atomic_uint32 resultEDX;
+ volatile ma_uint64 result;
+ #if defined(MA_X86)
+ ma_uint32 resultEAX;
+ ma_uint32 resultEDX;
__asm__ __volatile__("push %%ebx; xchg %5, %%ebx; lock; cmpxchg8b %0; pop %%ebx" : "+m"(*dst), "=a"(resultEAX), "=d"(resultEDX) : "a"(expected & 0xFFFFFFFF), "d"(expected >> 32), "r"(desired & 0xFFFFFFFF), "c"(desired >> 32) : "cc");
- result = ((c89atomic_uint64)resultEDX << 32) | resultEAX;
- #elif defined(C89ATOMIC_X64)
+ result = ((ma_uint64)resultEDX << 32) | resultEAX;
+ #elif defined(MA_X64)
__asm__ __volatile__("lock; cmpxchg %3, %0" : "+m"(*dst), "=a"(result) : "a"(expected), "d"(desired) : "cc");
#else
#error Unsupported architecture. Please submit a feature request.
#endif
return result;
}
- static C89ATOMIC_INLINE c89atomic_uint8 c89atomic_exchange_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint8 ma_atomic_exchange_explicit_8(volatile ma_uint8* dst, ma_uint8 src, ma_atomic_memory_order order)
{
- c89atomic_uint8 result = 0;
+ ma_uint8 result = 0;
(void)order;
- #if defined(C89ATOMIC_X86) || defined(C89ATOMIC_X64)
+ #if defined(MA_X86) || defined(MA_X64)
__asm__ __volatile__("lock; xchg %1, %0" : "+m"(*dst), "=a"(result) : "a"(src));
#else
#error Unsupported architecture. Please submit a feature request.
#endif
return result;
}
- static C89ATOMIC_INLINE c89atomic_uint16 c89atomic_exchange_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint16 ma_atomic_exchange_explicit_16(volatile ma_uint16* dst, ma_uint16 src, ma_atomic_memory_order order)
{
- c89atomic_uint16 result = 0;
+ ma_uint16 result = 0;
(void)order;
- #if defined(C89ATOMIC_X86) || defined(C89ATOMIC_X64)
+ #if defined(MA_X86) || defined(MA_X64)
__asm__ __volatile__("lock; xchg %1, %0" : "+m"(*dst), "=a"(result) : "a"(src));
#else
#error Unsupported architecture. Please submit a feature request.
#endif
return result;
}
- static C89ATOMIC_INLINE c89atomic_uint32 c89atomic_exchange_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint32 ma_atomic_exchange_explicit_32(volatile ma_uint32* dst, ma_uint32 src, ma_atomic_memory_order order)
{
- c89atomic_uint32 result;
+ ma_uint32 result;
(void)order;
- #if defined(C89ATOMIC_X86) || defined(C89ATOMIC_X64)
+ #if defined(MA_X86) || defined(MA_X64)
__asm__ __volatile__("lock; xchg %1, %0" : "+m"(*dst), "=a"(result) : "a"(src));
#else
#error Unsupported architecture. Please submit a feature request.
#endif
return result;
}
- static C89ATOMIC_INLINE c89atomic_uint64 c89atomic_exchange_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint64 ma_atomic_exchange_explicit_64(volatile ma_uint64* dst, ma_uint64 src, ma_atomic_memory_order order)
{
- c89atomic_uint64 result;
+ ma_uint64 result;
(void)order;
- #if defined(C89ATOMIC_X86)
+ #if defined(MA_X86)
do {
result = *dst;
- } while (c89atomic_compare_and_swap_64(dst, result, src) != result);
- #elif defined(C89ATOMIC_X64)
+ } while (ma_atomic_compare_and_swap_64(dst, result, src) != result);
+ #elif defined(MA_X64)
__asm__ __volatile__("lock; xchg %1, %0" : "+m"(*dst), "=a"(result) : "a"(src));
#else
#error Unsupported architecture. Please submit a feature request.
#endif
return result;
}
- static C89ATOMIC_INLINE c89atomic_uint8 c89atomic_fetch_add_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint8 ma_atomic_fetch_add_explicit_8(volatile ma_uint8* dst, ma_uint8 src, ma_atomic_memory_order order)
{
- c89atomic_uint8 result;
+ ma_uint8 result;
(void)order;
- #if defined(C89ATOMIC_X86) || defined(C89ATOMIC_X64)
+ #if defined(MA_X86) || defined(MA_X64)
__asm__ __volatile__("lock; xadd %1, %0" : "+m"(*dst), "=a"(result) : "a"(src) : "cc");
#else
#error Unsupported architecture. Please submit a feature request.
#endif
return result;
}
- static C89ATOMIC_INLINE c89atomic_uint16 c89atomic_fetch_add_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint16 ma_atomic_fetch_add_explicit_16(volatile ma_uint16* dst, ma_uint16 src, ma_atomic_memory_order order)
{
- c89atomic_uint16 result;
+ ma_uint16 result;
(void)order;
- #if defined(C89ATOMIC_X86) || defined(C89ATOMIC_X64)
+ #if defined(MA_X86) || defined(MA_X64)
__asm__ __volatile__("lock; xadd %1, %0" : "+m"(*dst), "=a"(result) : "a"(src) : "cc");
#else
#error Unsupported architecture. Please submit a feature request.
#endif
return result;
}
- static C89ATOMIC_INLINE c89atomic_uint32 c89atomic_fetch_add_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint32 ma_atomic_fetch_add_explicit_32(volatile ma_uint32* dst, ma_uint32 src, ma_atomic_memory_order order)
{
- c89atomic_uint32 result;
+ ma_uint32 result;
(void)order;
- #if defined(C89ATOMIC_X86) || defined(C89ATOMIC_X64)
+ #if defined(MA_X86) || defined(MA_X64)
__asm__ __volatile__("lock; xadd %1, %0" : "+m"(*dst), "=a"(result) : "a"(src) : "cc");
#else
#error Unsupported architecture. Please submit a feature request.
#endif
return result;
}
- static C89ATOMIC_INLINE c89atomic_uint64 c89atomic_fetch_add_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint64 ma_atomic_fetch_add_explicit_64(volatile ma_uint64* dst, ma_uint64 src, ma_atomic_memory_order order)
{
- #if defined(C89ATOMIC_X86)
- c89atomic_uint64 oldValue;
- c89atomic_uint64 newValue;
+ #if defined(MA_X86)
+ ma_uint64 oldValue;
+ ma_uint64 newValue;
(void)order;
do {
oldValue = *dst;
newValue = oldValue + src;
- } while (c89atomic_compare_and_swap_64(dst, oldValue, newValue) != oldValue);
+ } while (ma_atomic_compare_and_swap_64(dst, oldValue, newValue) != oldValue);
return oldValue;
- #elif defined(C89ATOMIC_X64)
- c89atomic_uint64 result;
+ #elif defined(MA_X64)
+ ma_uint64 result;
(void)order;
__asm__ __volatile__("lock; xadd %1, %0" : "+m"(*dst), "=a"(result) : "a"(src) : "cc");
return result;
#endif
}
- static C89ATOMIC_INLINE c89atomic_uint8 c89atomic_fetch_sub_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint8 ma_atomic_fetch_sub_explicit_8(volatile ma_uint8* dst, ma_uint8 src, ma_atomic_memory_order order)
{
- c89atomic_uint8 oldValue;
- c89atomic_uint8 newValue;
+ ma_uint8 oldValue;
+ ma_uint8 newValue;
do {
oldValue = *dst;
- newValue = (c89atomic_uint8)(oldValue - src);
- } while (c89atomic_compare_and_swap_8(dst, oldValue, newValue) != oldValue);
+ newValue = (ma_uint8)(oldValue - src);
+ } while (ma_atomic_compare_and_swap_8(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
}
- static C89ATOMIC_INLINE c89atomic_uint16 c89atomic_fetch_sub_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint16 ma_atomic_fetch_sub_explicit_16(volatile ma_uint16* dst, ma_uint16 src, ma_atomic_memory_order order)
{
- c89atomic_uint16 oldValue;
- c89atomic_uint16 newValue;
+ ma_uint16 oldValue;
+ ma_uint16 newValue;
do {
oldValue = *dst;
- newValue = (c89atomic_uint16)(oldValue - src);
- } while (c89atomic_compare_and_swap_16(dst, oldValue, newValue) != oldValue);
+ newValue = (ma_uint16)(oldValue - src);
+ } while (ma_atomic_compare_and_swap_16(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
}
- static C89ATOMIC_INLINE c89atomic_uint32 c89atomic_fetch_sub_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint32 ma_atomic_fetch_sub_explicit_32(volatile ma_uint32* dst, ma_uint32 src, ma_atomic_memory_order order)
{
- c89atomic_uint32 oldValue;
- c89atomic_uint32 newValue;
+ ma_uint32 oldValue;
+ ma_uint32 newValue;
do {
oldValue = *dst;
newValue = oldValue - src;
- } while (c89atomic_compare_and_swap_32(dst, oldValue, newValue) != oldValue);
+ } while (ma_atomic_compare_and_swap_32(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
}
- static C89ATOMIC_INLINE c89atomic_uint64 c89atomic_fetch_sub_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint64 ma_atomic_fetch_sub_explicit_64(volatile ma_uint64* dst, ma_uint64 src, ma_atomic_memory_order order)
{
- c89atomic_uint64 oldValue;
- c89atomic_uint64 newValue;
+ ma_uint64 oldValue;
+ ma_uint64 newValue;
do {
oldValue = *dst;
newValue = oldValue - src;
- } while (c89atomic_compare_and_swap_64(dst, oldValue, newValue) != oldValue);
+ } while (ma_atomic_compare_and_swap_64(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
}
- static C89ATOMIC_INLINE c89atomic_uint8 c89atomic_fetch_and_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint8 ma_atomic_fetch_and_explicit_8(volatile ma_uint8* dst, ma_uint8 src, ma_atomic_memory_order order)
{
- c89atomic_uint8 oldValue;
- c89atomic_uint8 newValue;
+ ma_uint8 oldValue;
+ ma_uint8 newValue;
do {
oldValue = *dst;
- newValue = (c89atomic_uint8)(oldValue & src);
- } while (c89atomic_compare_and_swap_8(dst, oldValue, newValue) != oldValue);
+ newValue = (ma_uint8)(oldValue & src);
+ } while (ma_atomic_compare_and_swap_8(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
}
- static C89ATOMIC_INLINE c89atomic_uint16 c89atomic_fetch_and_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint16 ma_atomic_fetch_and_explicit_16(volatile ma_uint16* dst, ma_uint16 src, ma_atomic_memory_order order)
{
- c89atomic_uint16 oldValue;
- c89atomic_uint16 newValue;
+ ma_uint16 oldValue;
+ ma_uint16 newValue;
do {
oldValue = *dst;
- newValue = (c89atomic_uint16)(oldValue & src);
- } while (c89atomic_compare_and_swap_16(dst, oldValue, newValue) != oldValue);
+ newValue = (ma_uint16)(oldValue & src);
+ } while (ma_atomic_compare_and_swap_16(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
}
- static C89ATOMIC_INLINE c89atomic_uint32 c89atomic_fetch_and_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint32 ma_atomic_fetch_and_explicit_32(volatile ma_uint32* dst, ma_uint32 src, ma_atomic_memory_order order)
{
- c89atomic_uint32 oldValue;
- c89atomic_uint32 newValue;
+ ma_uint32 oldValue;
+ ma_uint32 newValue;
do {
oldValue = *dst;
newValue = oldValue & src;
- } while (c89atomic_compare_and_swap_32(dst, oldValue, newValue) != oldValue);
+ } while (ma_atomic_compare_and_swap_32(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
}
- static C89ATOMIC_INLINE c89atomic_uint64 c89atomic_fetch_and_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint64 ma_atomic_fetch_and_explicit_64(volatile ma_uint64* dst, ma_uint64 src, ma_atomic_memory_order order)
{
- c89atomic_uint64 oldValue;
- c89atomic_uint64 newValue;
+ ma_uint64 oldValue;
+ ma_uint64 newValue;
do {
oldValue = *dst;
newValue = oldValue & src;
- } while (c89atomic_compare_and_swap_64(dst, oldValue, newValue) != oldValue);
+ } while (ma_atomic_compare_and_swap_64(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
}
- static C89ATOMIC_INLINE c89atomic_uint8 c89atomic_fetch_xor_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint8 ma_atomic_fetch_xor_explicit_8(volatile ma_uint8* dst, ma_uint8 src, ma_atomic_memory_order order)
{
- c89atomic_uint8 oldValue;
- c89atomic_uint8 newValue;
+ ma_uint8 oldValue;
+ ma_uint8 newValue;
do {
oldValue = *dst;
- newValue = (c89atomic_uint8)(oldValue ^ src);
- } while (c89atomic_compare_and_swap_8(dst, oldValue, newValue) != oldValue);
+ newValue = (ma_uint8)(oldValue ^ src);
+ } while (ma_atomic_compare_and_swap_8(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
}
- static C89ATOMIC_INLINE c89atomic_uint16 c89atomic_fetch_xor_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint16 ma_atomic_fetch_xor_explicit_16(volatile ma_uint16* dst, ma_uint16 src, ma_atomic_memory_order order)
{
- c89atomic_uint16 oldValue;
- c89atomic_uint16 newValue;
+ ma_uint16 oldValue;
+ ma_uint16 newValue;
do {
oldValue = *dst;
- newValue = (c89atomic_uint16)(oldValue ^ src);
- } while (c89atomic_compare_and_swap_16(dst, oldValue, newValue) != oldValue);
+ newValue = (ma_uint16)(oldValue ^ src);
+ } while (ma_atomic_compare_and_swap_16(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
}
- static C89ATOMIC_INLINE c89atomic_uint32 c89atomic_fetch_xor_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint32 ma_atomic_fetch_xor_explicit_32(volatile ma_uint32* dst, ma_uint32 src, ma_atomic_memory_order order)
{
- c89atomic_uint32 oldValue;
- c89atomic_uint32 newValue;
+ ma_uint32 oldValue;
+ ma_uint32 newValue;
do {
oldValue = *dst;
newValue = oldValue ^ src;
- } while (c89atomic_compare_and_swap_32(dst, oldValue, newValue) != oldValue);
+ } while (ma_atomic_compare_and_swap_32(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
}
- static C89ATOMIC_INLINE c89atomic_uint64 c89atomic_fetch_xor_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint64 ma_atomic_fetch_xor_explicit_64(volatile ma_uint64* dst, ma_uint64 src, ma_atomic_memory_order order)
{
- c89atomic_uint64 oldValue;
- c89atomic_uint64 newValue;
+ ma_uint64 oldValue;
+ ma_uint64 newValue;
do {
oldValue = *dst;
newValue = oldValue ^ src;
- } while (c89atomic_compare_and_swap_64(dst, oldValue, newValue) != oldValue);
+ } while (ma_atomic_compare_and_swap_64(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
}
- static C89ATOMIC_INLINE c89atomic_uint8 c89atomic_fetch_or_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint8 ma_atomic_fetch_or_explicit_8(volatile ma_uint8* dst, ma_uint8 src, ma_atomic_memory_order order)
{
- c89atomic_uint8 oldValue;
- c89atomic_uint8 newValue;
+ ma_uint8 oldValue;
+ ma_uint8 newValue;
do {
oldValue = *dst;
- newValue = (c89atomic_uint8)(oldValue | src);
- } while (c89atomic_compare_and_swap_8(dst, oldValue, newValue) != oldValue);
+ newValue = (ma_uint8)(oldValue | src);
+ } while (ma_atomic_compare_and_swap_8(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
}
- static C89ATOMIC_INLINE c89atomic_uint16 c89atomic_fetch_or_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint16 ma_atomic_fetch_or_explicit_16(volatile ma_uint16* dst, ma_uint16 src, ma_atomic_memory_order order)
{
- c89atomic_uint16 oldValue;
- c89atomic_uint16 newValue;
+ ma_uint16 oldValue;
+ ma_uint16 newValue;
do {
oldValue = *dst;
- newValue = (c89atomic_uint16)(oldValue | src);
- } while (c89atomic_compare_and_swap_16(dst, oldValue, newValue) != oldValue);
+ newValue = (ma_uint16)(oldValue | src);
+ } while (ma_atomic_compare_and_swap_16(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
}
- static C89ATOMIC_INLINE c89atomic_uint32 c89atomic_fetch_or_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint32 ma_atomic_fetch_or_explicit_32(volatile ma_uint32* dst, ma_uint32 src, ma_atomic_memory_order order)
{
- c89atomic_uint32 oldValue;
- c89atomic_uint32 newValue;
+ ma_uint32 oldValue;
+ ma_uint32 newValue;
do {
oldValue = *dst;
newValue = oldValue | src;
- } while (c89atomic_compare_and_swap_32(dst, oldValue, newValue) != oldValue);
+ } while (ma_atomic_compare_and_swap_32(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
}
- static C89ATOMIC_INLINE c89atomic_uint64 c89atomic_fetch_or_explicit_64(volatile c89atomic_uint64* dst, c89atomic_uint64 src, c89atomic_memory_order order)
+ static MA_INLINE ma_uint64 ma_atomic_fetch_or_explicit_64(volatile ma_uint64* dst, ma_uint64 src, ma_atomic_memory_order order)
{
- c89atomic_uint64 oldValue;
- c89atomic_uint64 newValue;
+ ma_uint64 oldValue;
+ ma_uint64 newValue;
do {
oldValue = *dst;
newValue = oldValue | src;
- } while (c89atomic_compare_and_swap_64(dst, oldValue, newValue) != oldValue);
+ } while (ma_atomic_compare_and_swap_64(dst, oldValue, newValue) != oldValue);
(void)order;
return oldValue;
}
#endif
- #define c89atomic_signal_fence(order) c89atomic_thread_fence(order)
- static C89ATOMIC_INLINE c89atomic_uint8 c89atomic_load_explicit_8(volatile const c89atomic_uint8* ptr, c89atomic_memory_order order)
+ #define ma_atomic_signal_fence(order) ma_atomic_thread_fence(order)
+ static MA_INLINE ma_uint8 ma_atomic_load_explicit_8(volatile const ma_uint8* ptr, ma_atomic_memory_order order)
{
(void)order;
- return c89atomic_compare_and_swap_8((c89atomic_uint8*)ptr, 0, 0);
+ return ma_atomic_compare_and_swap_8((ma_uint8*)ptr, 0, 0);
}
- static C89ATOMIC_INLINE c89atomic_uint16 c89atomic_load_explicit_16(volatile const c89atomic_uint16* ptr, c89atomic_memory_order order)
+ static MA_INLINE ma_uint16 ma_atomic_load_explicit_16(volatile const ma_uint16* ptr, ma_atomic_memory_order order)
{
(void)order;
- return c89atomic_compare_and_swap_16((c89atomic_uint16*)ptr, 0, 0);
+ return ma_atomic_compare_and_swap_16((ma_uint16*)ptr, 0, 0);
}
- static C89ATOMIC_INLINE c89atomic_uint32 c89atomic_load_explicit_32(volatile const c89atomic_uint32* ptr, c89atomic_memory_order order)
+ static MA_INLINE ma_uint32 ma_atomic_load_explicit_32(volatile const ma_uint32* ptr, ma_atomic_memory_order order)
{
(void)order;
- return c89atomic_compare_and_swap_32((c89atomic_uint32*)ptr, 0, 0);
+ return ma_atomic_compare_and_swap_32((ma_uint32*)ptr, 0, 0);
}
- static C89ATOMIC_INLINE c89atomic_uint64 c89atomic_load_explicit_64(volatile const c89atomic_uint64* ptr, c89atomic_memory_order order)
+ static MA_INLINE ma_uint64 ma_atomic_load_explicit_64(volatile const ma_uint64* ptr, ma_atomic_memory_order order)
{
(void)order;
- return c89atomic_compare_and_swap_64((c89atomic_uint64*)ptr, 0, 0);
- }
- #define c89atomic_store_explicit_8( dst, src, order) (void)c89atomic_exchange_explicit_8 (dst, src, order)
- #define c89atomic_store_explicit_16(dst, src, order) (void)c89atomic_exchange_explicit_16(dst, src, order)
- #define c89atomic_store_explicit_32(dst, src, order) (void)c89atomic_exchange_explicit_32(dst, src, order)
- #define c89atomic_store_explicit_64(dst, src, order) (void)c89atomic_exchange_explicit_64(dst, src, order)
- #define c89atomic_test_and_set_explicit_8( dst, order) c89atomic_exchange_explicit_8 (dst, 1, order)
- #define c89atomic_test_and_set_explicit_16(dst, order) c89atomic_exchange_explicit_16(dst, 1, order)
- #define c89atomic_test_and_set_explicit_32(dst, order) c89atomic_exchange_explicit_32(dst, 1, order)
- #define c89atomic_test_and_set_explicit_64(dst, order) c89atomic_exchange_explicit_64(dst, 1, order)
- #define c89atomic_clear_explicit_8( dst, order) c89atomic_store_explicit_8 (dst, 0, order)
- #define c89atomic_clear_explicit_16(dst, order) c89atomic_store_explicit_16(dst, 0, order)
- #define c89atomic_clear_explicit_32(dst, order) c89atomic_store_explicit_32(dst, 0, order)
- #define c89atomic_clear_explicit_64(dst, order) c89atomic_store_explicit_64(dst, 0, order)
- typedef c89atomic_uint8 c89atomic_flag;
- #define c89atomic_flag_test_and_set_explicit(ptr, order) (c89atomic_bool)c89atomic_test_and_set_explicit_8(ptr, order)
- #define c89atomic_flag_clear_explicit(ptr, order) c89atomic_clear_explicit_8(ptr, order)
- #define c89atoimc_flag_load_explicit(ptr, order) c89atomic_load_explicit_8(ptr, order)
-#endif
-#if !defined(C89ATOMIC_HAS_NATIVE_COMPARE_EXCHANGE)
- #if defined(C89ATOMIC_HAS_8)
- c89atomic_bool c89atomic_compare_exchange_strong_explicit_8(volatile c89atomic_uint8* dst, c89atomic_uint8* expected, c89atomic_uint8 desired, c89atomic_memory_order successOrder, c89atomic_memory_order failureOrder)
+ return ma_atomic_compare_and_swap_64((ma_uint64*)ptr, 0, 0);
+ }
+ #define ma_atomic_store_explicit_8( dst, src, order) (void)ma_atomic_exchange_explicit_8 (dst, src, order)
+ #define ma_atomic_store_explicit_16(dst, src, order) (void)ma_atomic_exchange_explicit_16(dst, src, order)
+ #define ma_atomic_store_explicit_32(dst, src, order) (void)ma_atomic_exchange_explicit_32(dst, src, order)
+ #define ma_atomic_store_explicit_64(dst, src, order) (void)ma_atomic_exchange_explicit_64(dst, src, order)
+ #define ma_atomic_test_and_set_explicit_8( dst, order) ma_atomic_exchange_explicit_8 (dst, 1, order)
+ #define ma_atomic_test_and_set_explicit_16(dst, order) ma_atomic_exchange_explicit_16(dst, 1, order)
+ #define ma_atomic_test_and_set_explicit_32(dst, order) ma_atomic_exchange_explicit_32(dst, 1, order)
+ #define ma_atomic_test_and_set_explicit_64(dst, order) ma_atomic_exchange_explicit_64(dst, 1, order)
+ #define ma_atomic_clear_explicit_8( dst, order) ma_atomic_store_explicit_8 (dst, 0, order)
+ #define ma_atomic_clear_explicit_16(dst, order) ma_atomic_store_explicit_16(dst, 0, order)
+ #define ma_atomic_clear_explicit_32(dst, order) ma_atomic_store_explicit_32(dst, 0, order)
+ #define ma_atomic_clear_explicit_64(dst, order) ma_atomic_store_explicit_64(dst, 0, order)
+ typedef ma_uint8 ma_atomic_flag;
+ #define ma_atomic_flag_test_and_set_explicit(ptr, order) (ma_bool32)ma_atomic_test_and_set_explicit_8(ptr, order)
+ #define ma_atomic_flag_clear_explicit(ptr, order) ma_atomic_clear_explicit_8(ptr, order)
+ #define c89atoimc_flag_load_explicit(ptr, order) ma_atomic_load_explicit_8(ptr, order)
+#endif
+#if !defined(MA_ATOMIC_HAS_NATIVE_COMPARE_EXCHANGE)
+ #if defined(MA_ATOMIC_HAS_8)
+ static MA_INLINE ma_bool32 ma_atomic_compare_exchange_strong_explicit_8(volatile ma_uint8* dst, ma_uint8* expected, ma_uint8 desired, ma_atomic_memory_order successOrder, ma_atomic_memory_order failureOrder)
{
- c89atomic_uint8 expectedValue;
- c89atomic_uint8 result;
+ ma_uint8 expectedValue;
+ ma_uint8 result;
(void)successOrder;
(void)failureOrder;
- expectedValue = c89atomic_load_explicit_8(expected, c89atomic_memory_order_seq_cst);
- result = c89atomic_compare_and_swap_8(dst, expectedValue, desired);
+ expectedValue = ma_atomic_load_explicit_8(expected, ma_atomic_memory_order_seq_cst);
+ result = ma_atomic_compare_and_swap_8(dst, expectedValue, desired);
if (result == expectedValue) {
return 1;
} else {
- c89atomic_store_explicit_8(expected, result, failureOrder);
+ ma_atomic_store_explicit_8(expected, result, failureOrder);
return 0;
}
}
#endif
- #if defined(C89ATOMIC_HAS_16)
- c89atomic_bool c89atomic_compare_exchange_strong_explicit_16(volatile c89atomic_uint16* dst, c89atomic_uint16* expected, c89atomic_uint16 desired, c89atomic_memory_order successOrder, c89atomic_memory_order failureOrder)
+ #if defined(MA_ATOMIC_HAS_16)
+ static MA_INLINE ma_bool32 ma_atomic_compare_exchange_strong_explicit_16(volatile ma_uint16* dst, ma_uint16* expected, ma_uint16 desired, ma_atomic_memory_order successOrder, ma_atomic_memory_order failureOrder)
{
- c89atomic_uint16 expectedValue;
- c89atomic_uint16 result;
+ ma_uint16 expectedValue;
+ ma_uint16 result;
(void)successOrder;
(void)failureOrder;
- expectedValue = c89atomic_load_explicit_16(expected, c89atomic_memory_order_seq_cst);
- result = c89atomic_compare_and_swap_16(dst, expectedValue, desired);
+ expectedValue = ma_atomic_load_explicit_16(expected, ma_atomic_memory_order_seq_cst);
+ result = ma_atomic_compare_and_swap_16(dst, expectedValue, desired);
if (result == expectedValue) {
return 1;
} else {
- c89atomic_store_explicit_16(expected, result, failureOrder);
+ ma_atomic_store_explicit_16(expected, result, failureOrder);
return 0;
}
}
#endif
- #if defined(C89ATOMIC_HAS_32)
- c89atomic_bool c89atomic_compare_exchange_strong_explicit_32(volatile c89atomic_uint32* dst, c89atomic_uint32* expected, c89atomic_uint32 desired, c89atomic_memory_order successOrder, c89atomic_memory_order failureOrder)
+ #if defined(MA_ATOMIC_HAS_32)
+ static MA_INLINE ma_bool32 ma_atomic_compare_exchange_strong_explicit_32(volatile ma_uint32* dst, ma_uint32* expected, ma_uint32 desired, ma_atomic_memory_order successOrder, ma_atomic_memory_order failureOrder)
{
- c89atomic_uint32 expectedValue;
- c89atomic_uint32 result;
+ ma_uint32 expectedValue;
+ ma_uint32 result;
(void)successOrder;
(void)failureOrder;
- expectedValue = c89atomic_load_explicit_32(expected, c89atomic_memory_order_seq_cst);
- result = c89atomic_compare_and_swap_32(dst, expectedValue, desired);
+ expectedValue = ma_atomic_load_explicit_32(expected, ma_atomic_memory_order_seq_cst);
+ result = ma_atomic_compare_and_swap_32(dst, expectedValue, desired);
if (result == expectedValue) {
return 1;
} else {
- c89atomic_store_explicit_32(expected, result, failureOrder);
+ ma_atomic_store_explicit_32(expected, result, failureOrder);
return 0;
}
}
#endif
- #if defined(C89ATOMIC_HAS_64)
- c89atomic_bool c89atomic_compare_exchange_strong_explicit_64(volatile c89atomic_uint64* dst, volatile c89atomic_uint64* expected, c89atomic_uint64 desired, c89atomic_memory_order successOrder, c89atomic_memory_order failureOrder)
+ #if defined(MA_ATOMIC_HAS_64)
+ static MA_INLINE ma_bool32 ma_atomic_compare_exchange_strong_explicit_64(volatile ma_uint64* dst, volatile ma_uint64* expected, ma_uint64 desired, ma_atomic_memory_order successOrder, ma_atomic_memory_order failureOrder)
{
- c89atomic_uint64 expectedValue;
- c89atomic_uint64 result;
+ ma_uint64 expectedValue;
+ ma_uint64 result;
(void)successOrder;
(void)failureOrder;
- expectedValue = c89atomic_load_explicit_64(expected, c89atomic_memory_order_seq_cst);
- result = c89atomic_compare_and_swap_64(dst, expectedValue, desired);
+ expectedValue = ma_atomic_load_explicit_64(expected, ma_atomic_memory_order_seq_cst);
+ result = ma_atomic_compare_and_swap_64(dst, expectedValue, desired);
if (result == expectedValue) {
return 1;
} else {
- c89atomic_store_explicit_64(expected, result, failureOrder);
+ ma_atomic_store_explicit_64(expected, result, failureOrder);
return 0;
}
}
#endif
- #define c89atomic_compare_exchange_weak_explicit_8( dst, expected, desired, successOrder, failureOrder) c89atomic_compare_exchange_strong_explicit_8 (dst, expected, desired, successOrder, failureOrder)
- #define c89atomic_compare_exchange_weak_explicit_16(dst, expected, desired, successOrder, failureOrder) c89atomic_compare_exchange_strong_explicit_16(dst, expected, desired, successOrder, failureOrder)
- #define c89atomic_compare_exchange_weak_explicit_32(dst, expected, desired, successOrder, failureOrder) c89atomic_compare_exchange_strong_explicit_32(dst, expected, desired, successOrder, failureOrder)
- #define c89atomic_compare_exchange_weak_explicit_64(dst, expected, desired, successOrder, failureOrder) c89atomic_compare_exchange_strong_explicit_64(dst, expected, desired, successOrder, failureOrder)
+ #define ma_atomic_compare_exchange_weak_explicit_8( dst, expected, desired, successOrder, failureOrder) ma_atomic_compare_exchange_strong_explicit_8 (dst, expected, desired, successOrder, failureOrder)
+ #define ma_atomic_compare_exchange_weak_explicit_16(dst, expected, desired, successOrder, failureOrder) ma_atomic_compare_exchange_strong_explicit_16(dst, expected, desired, successOrder, failureOrder)
+ #define ma_atomic_compare_exchange_weak_explicit_32(dst, expected, desired, successOrder, failureOrder) ma_atomic_compare_exchange_strong_explicit_32(dst, expected, desired, successOrder, failureOrder)
+ #define ma_atomic_compare_exchange_weak_explicit_64(dst, expected, desired, successOrder, failureOrder) ma_atomic_compare_exchange_strong_explicit_64(dst, expected, desired, successOrder, failureOrder)
#endif
-#if !defined(C89ATOMIC_HAS_NATIVE_IS_LOCK_FREE)
- static C89ATOMIC_INLINE c89atomic_bool c89atomic_is_lock_free_8(volatile void* ptr)
+#if !defined(MA_ATOMIC_HAS_NATIVE_IS_LOCK_FREE)
+ static MA_INLINE ma_bool32 ma_atomic_is_lock_free_8(volatile void* ptr)
{
(void)ptr;
return 1;
}
- static C89ATOMIC_INLINE c89atomic_bool c89atomic_is_lock_free_16(volatile void* ptr)
+ static MA_INLINE ma_bool32 ma_atomic_is_lock_free_16(volatile void* ptr)
{
(void)ptr;
return 1;
}
- static C89ATOMIC_INLINE c89atomic_bool c89atomic_is_lock_free_32(volatile void* ptr)
+ static MA_INLINE ma_bool32 ma_atomic_is_lock_free_32(volatile void* ptr)
{
(void)ptr;
return 1;
}
- static C89ATOMIC_INLINE c89atomic_bool c89atomic_is_lock_free_64(volatile void* ptr)
+ static MA_INLINE ma_bool32 ma_atomic_is_lock_free_64(volatile void* ptr)
{
(void)ptr;
- #if defined(C89ATOMIC_64BIT)
+ #if defined(MA_64BIT)
return 1;
#else
- #if defined(C89ATOMIC_X86) || defined(C89ATOMIC_X64)
+ #if defined(MA_X86) || defined(MA_X64)
return 1;
#else
return 0;
@@ -15006,303 +15464,515 @@ typedef unsigned char c89atomic_bool;
#endif
}
#endif
-#if defined(C89ATOMIC_64BIT)
- static C89ATOMIC_INLINE c89atomic_bool c89atomic_is_lock_free_ptr(volatile void** ptr)
+#if defined(MA_64BIT)
+ static MA_INLINE ma_bool32 ma_atomic_is_lock_free_ptr(volatile void** ptr)
{
- return c89atomic_is_lock_free_64((volatile c89atomic_uint64*)ptr);
+ return ma_atomic_is_lock_free_64((volatile ma_uint64*)ptr);
}
- static C89ATOMIC_INLINE void* c89atomic_load_explicit_ptr(volatile void** ptr, c89atomic_memory_order order)
+ static MA_INLINE void* ma_atomic_load_explicit_ptr(volatile void** ptr, ma_atomic_memory_order order)
{
- return (void*)c89atomic_load_explicit_64((volatile c89atomic_uint64*)ptr, order);
+ return (void*)ma_atomic_load_explicit_64((volatile ma_uint64*)ptr, order);
}
- static C89ATOMIC_INLINE void c89atomic_store_explicit_ptr(volatile void** dst, void* src, c89atomic_memory_order order)
+ static MA_INLINE void ma_atomic_store_explicit_ptr(volatile void** dst, void* src, ma_atomic_memory_order order)
{
- c89atomic_store_explicit_64((volatile c89atomic_uint64*)dst, (c89atomic_uint64)src, order);
+ ma_atomic_store_explicit_64((volatile ma_uint64*)dst, (ma_uint64)src, order);
}
- static C89ATOMIC_INLINE void* c89atomic_exchange_explicit_ptr(volatile void** dst, void* src, c89atomic_memory_order order)
+ static MA_INLINE void* ma_atomic_exchange_explicit_ptr(volatile void** dst, void* src, ma_atomic_memory_order order)
{
- return (void*)c89atomic_exchange_explicit_64((volatile c89atomic_uint64*)dst, (c89atomic_uint64)src, order);
+ return (void*)ma_atomic_exchange_explicit_64((volatile ma_uint64*)dst, (ma_uint64)src, order);
}
- static C89ATOMIC_INLINE c89atomic_bool c89atomic_compare_exchange_strong_explicit_ptr(volatile void** dst, void** expected, void* desired, c89atomic_memory_order successOrder, c89atomic_memory_order failureOrder)
+ static MA_INLINE ma_bool32 ma_atomic_compare_exchange_strong_explicit_ptr(volatile void** dst, void** expected, void* desired, ma_atomic_memory_order successOrder, ma_atomic_memory_order failureOrder)
{
- return c89atomic_compare_exchange_strong_explicit_64((volatile c89atomic_uint64*)dst, (c89atomic_uint64*)expected, (c89atomic_uint64)desired, successOrder, failureOrder);
+ return ma_atomic_compare_exchange_strong_explicit_64((volatile ma_uint64*)dst, (ma_uint64*)expected, (ma_uint64)desired, successOrder, failureOrder);
}
- static C89ATOMIC_INLINE c89atomic_bool c89atomic_compare_exchange_weak_explicit_ptr(volatile void** dst, void** expected, void* desired, c89atomic_memory_order successOrder, c89atomic_memory_order failureOrder)
+ static MA_INLINE ma_bool32 ma_atomic_compare_exchange_weak_explicit_ptr(volatile void** dst, void** expected, void* desired, ma_atomic_memory_order successOrder, ma_atomic_memory_order failureOrder)
{
- return c89atomic_compare_exchange_weak_explicit_64((volatile c89atomic_uint64*)dst, (c89atomic_uint64*)expected, (c89atomic_uint64)desired, successOrder, failureOrder);
+ return ma_atomic_compare_exchange_weak_explicit_64((volatile ma_uint64*)dst, (ma_uint64*)expected, (ma_uint64)desired, successOrder, failureOrder);
}
- static C89ATOMIC_INLINE void* c89atomic_compare_and_swap_ptr(volatile void** dst, void* expected, void* desired)
+ static MA_INLINE void* ma_atomic_compare_and_swap_ptr(volatile void** dst, void* expected, void* desired)
{
- return (void*)c89atomic_compare_and_swap_64((volatile c89atomic_uint64*)dst, (c89atomic_uint64)expected, (c89atomic_uint64)desired);
+ return (void*)ma_atomic_compare_and_swap_64((volatile ma_uint64*)dst, (ma_uint64)expected, (ma_uint64)desired);
}
-#elif defined(C89ATOMIC_32BIT)
- static C89ATOMIC_INLINE c89atomic_bool c89atomic_is_lock_free_ptr(volatile void** ptr)
+#elif defined(MA_32BIT)
+ static MA_INLINE ma_bool32 ma_atomic_is_lock_free_ptr(volatile void** ptr)
{
- return c89atomic_is_lock_free_32((volatile c89atomic_uint32*)ptr);
+ return ma_atomic_is_lock_free_32((volatile ma_uint32*)ptr);
}
- static C89ATOMIC_INLINE void* c89atomic_load_explicit_ptr(volatile void** ptr, c89atomic_memory_order order)
+ static MA_INLINE void* ma_atomic_load_explicit_ptr(volatile void** ptr, ma_atomic_memory_order order)
{
- return (void*)c89atomic_load_explicit_32((volatile c89atomic_uint32*)ptr, order);
+ return (void*)ma_atomic_load_explicit_32((volatile ma_uint32*)ptr, order);
}
- static C89ATOMIC_INLINE void c89atomic_store_explicit_ptr(volatile void** dst, void* src, c89atomic_memory_order order)
+ static MA_INLINE void ma_atomic_store_explicit_ptr(volatile void** dst, void* src, ma_atomic_memory_order order)
{
- c89atomic_store_explicit_32((volatile c89atomic_uint32*)dst, (c89atomic_uint32)src, order);
+ ma_atomic_store_explicit_32((volatile ma_uint32*)dst, (ma_uint32)src, order);
}
- static C89ATOMIC_INLINE void* c89atomic_exchange_explicit_ptr(volatile void** dst, void* src, c89atomic_memory_order order)
+ static MA_INLINE void* ma_atomic_exchange_explicit_ptr(volatile void** dst, void* src, ma_atomic_memory_order order)
{
- return (void*)c89atomic_exchange_explicit_32((volatile c89atomic_uint32*)dst, (c89atomic_uint32)src, order);
+ return (void*)ma_atomic_exchange_explicit_32((volatile ma_uint32*)dst, (ma_uint32)src, order);
}
- static C89ATOMIC_INLINE c89atomic_bool c89atomic_compare_exchange_strong_explicit_ptr(volatile void** dst, void** expected, void* desired, c89atomic_memory_order successOrder, c89atomic_memory_order failureOrder)
+ static MA_INLINE ma_bool32 ma_atomic_compare_exchange_strong_explicit_ptr(volatile void** dst, void** expected, void* desired, ma_atomic_memory_order successOrder, ma_atomic_memory_order failureOrder)
{
- return c89atomic_compare_exchange_strong_explicit_32((volatile c89atomic_uint32*)dst, (c89atomic_uint32*)expected, (c89atomic_uint32)desired, successOrder, failureOrder);
+ return ma_atomic_compare_exchange_strong_explicit_32((volatile ma_uint32*)dst, (ma_uint32*)expected, (ma_uint32)desired, successOrder, failureOrder);
}
- static C89ATOMIC_INLINE c89atomic_bool c89atomic_compare_exchange_weak_explicit_ptr(volatile void** dst, void** expected, void* desired, c89atomic_memory_order successOrder, c89atomic_memory_order failureOrder)
+ static MA_INLINE ma_bool32 ma_atomic_compare_exchange_weak_explicit_ptr(volatile void** dst, void** expected, void* desired, ma_atomic_memory_order successOrder, ma_atomic_memory_order failureOrder)
{
- return c89atomic_compare_exchange_weak_explicit_32((volatile c89atomic_uint32*)dst, (c89atomic_uint32*)expected, (c89atomic_uint32)desired, successOrder, failureOrder);
+ return ma_atomic_compare_exchange_weak_explicit_32((volatile ma_uint32*)dst, (ma_uint32*)expected, (ma_uint32)desired, successOrder, failureOrder);
}
- static C89ATOMIC_INLINE void* c89atomic_compare_and_swap_ptr(volatile void** dst, void* expected, void* desired)
+ static MA_INLINE void* ma_atomic_compare_and_swap_ptr(volatile void** dst, void* expected, void* desired)
{
- return (void*)c89atomic_compare_and_swap_32((volatile c89atomic_uint32*)dst, (c89atomic_uint32)expected, (c89atomic_uint32)desired);
+ return (void*)ma_atomic_compare_and_swap_32((volatile ma_uint32*)dst, (ma_uint32)expected, (ma_uint32)desired);
}
#else
#error Unsupported architecture.
#endif
-#define c89atomic_flag_test_and_set(ptr) c89atomic_flag_test_and_set_explicit(ptr, c89atomic_memory_order_seq_cst)
-#define c89atomic_flag_clear(ptr) c89atomic_flag_clear_explicit(ptr, c89atomic_memory_order_seq_cst)
-#define c89atomic_store_ptr(dst, src) c89atomic_store_explicit_ptr((volatile void**)dst, (void*)src, c89atomic_memory_order_seq_cst)
-#define c89atomic_load_ptr(ptr) c89atomic_load_explicit_ptr((volatile void**)ptr, c89atomic_memory_order_seq_cst)
-#define c89atomic_exchange_ptr(dst, src) c89atomic_exchange_explicit_ptr((volatile void**)dst, (void*)src, c89atomic_memory_order_seq_cst)
-#define c89atomic_compare_exchange_strong_ptr(dst, expected, desired) c89atomic_compare_exchange_strong_explicit_ptr((volatile void**)dst, (void**)expected, (void*)desired, c89atomic_memory_order_seq_cst, c89atomic_memory_order_seq_cst)
-#define c89atomic_compare_exchange_weak_ptr(dst, expected, desired) c89atomic_compare_exchange_weak_explicit_ptr((volatile void**)dst, (void**)expected, (void*)desired, c89atomic_memory_order_seq_cst, c89atomic_memory_order_seq_cst)
-#define c89atomic_test_and_set_8( ptr) c89atomic_test_and_set_explicit_8( ptr, c89atomic_memory_order_seq_cst)
-#define c89atomic_test_and_set_16(ptr) c89atomic_test_and_set_explicit_16(ptr, c89atomic_memory_order_seq_cst)
-#define c89atomic_test_and_set_32(ptr) c89atomic_test_and_set_explicit_32(ptr, c89atomic_memory_order_seq_cst)
-#define c89atomic_test_and_set_64(ptr) c89atomic_test_and_set_explicit_64(ptr, c89atomic_memory_order_seq_cst)
-#define c89atomic_clear_8( ptr) c89atomic_clear_explicit_8( ptr, c89atomic_memory_order_seq_cst)
-#define c89atomic_clear_16(ptr) c89atomic_clear_explicit_16(ptr, c89atomic_memory_order_seq_cst)
-#define c89atomic_clear_32(ptr) c89atomic_clear_explicit_32(ptr, c89atomic_memory_order_seq_cst)
-#define c89atomic_clear_64(ptr) c89atomic_clear_explicit_64(ptr, c89atomic_memory_order_seq_cst)
-#define c89atomic_store_8( dst, src) c89atomic_store_explicit_8( dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_store_16(dst, src) c89atomic_store_explicit_16(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_store_32(dst, src) c89atomic_store_explicit_32(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_store_64(dst, src) c89atomic_store_explicit_64(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_load_8( ptr) c89atomic_load_explicit_8( ptr, c89atomic_memory_order_seq_cst)
-#define c89atomic_load_16(ptr) c89atomic_load_explicit_16(ptr, c89atomic_memory_order_seq_cst)
-#define c89atomic_load_32(ptr) c89atomic_load_explicit_32(ptr, c89atomic_memory_order_seq_cst)
-#define c89atomic_load_64(ptr) c89atomic_load_explicit_64(ptr, c89atomic_memory_order_seq_cst)
-#define c89atomic_exchange_8( dst, src) c89atomic_exchange_explicit_8( dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_exchange_16(dst, src) c89atomic_exchange_explicit_16(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_exchange_32(dst, src) c89atomic_exchange_explicit_32(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_exchange_64(dst, src) c89atomic_exchange_explicit_64(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_compare_exchange_strong_8( dst, expected, desired) c89atomic_compare_exchange_strong_explicit_8( dst, expected, desired, c89atomic_memory_order_seq_cst, c89atomic_memory_order_seq_cst)
-#define c89atomic_compare_exchange_strong_16(dst, expected, desired) c89atomic_compare_exchange_strong_explicit_16(dst, expected, desired, c89atomic_memory_order_seq_cst, c89atomic_memory_order_seq_cst)
-#define c89atomic_compare_exchange_strong_32(dst, expected, desired) c89atomic_compare_exchange_strong_explicit_32(dst, expected, desired, c89atomic_memory_order_seq_cst, c89atomic_memory_order_seq_cst)
-#define c89atomic_compare_exchange_strong_64(dst, expected, desired) c89atomic_compare_exchange_strong_explicit_64(dst, expected, desired, c89atomic_memory_order_seq_cst, c89atomic_memory_order_seq_cst)
-#define c89atomic_compare_exchange_weak_8( dst, expected, desired) c89atomic_compare_exchange_weak_explicit_8( dst, expected, desired, c89atomic_memory_order_seq_cst, c89atomic_memory_order_seq_cst)
-#define c89atomic_compare_exchange_weak_16( dst, expected, desired) c89atomic_compare_exchange_weak_explicit_16(dst, expected, desired, c89atomic_memory_order_seq_cst, c89atomic_memory_order_seq_cst)
-#define c89atomic_compare_exchange_weak_32( dst, expected, desired) c89atomic_compare_exchange_weak_explicit_32(dst, expected, desired, c89atomic_memory_order_seq_cst, c89atomic_memory_order_seq_cst)
-#define c89atomic_compare_exchange_weak_64( dst, expected, desired) c89atomic_compare_exchange_weak_explicit_64(dst, expected, desired, c89atomic_memory_order_seq_cst, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_add_8( dst, src) c89atomic_fetch_add_explicit_8( dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_add_16(dst, src) c89atomic_fetch_add_explicit_16(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_add_32(dst, src) c89atomic_fetch_add_explicit_32(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_add_64(dst, src) c89atomic_fetch_add_explicit_64(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_sub_8( dst, src) c89atomic_fetch_sub_explicit_8( dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_sub_16(dst, src) c89atomic_fetch_sub_explicit_16(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_sub_32(dst, src) c89atomic_fetch_sub_explicit_32(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_sub_64(dst, src) c89atomic_fetch_sub_explicit_64(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_or_8( dst, src) c89atomic_fetch_or_explicit_8( dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_or_16(dst, src) c89atomic_fetch_or_explicit_16(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_or_32(dst, src) c89atomic_fetch_or_explicit_32(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_or_64(dst, src) c89atomic_fetch_or_explicit_64(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_xor_8( dst, src) c89atomic_fetch_xor_explicit_8( dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_xor_16(dst, src) c89atomic_fetch_xor_explicit_16(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_xor_32(dst, src) c89atomic_fetch_xor_explicit_32(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_xor_64(dst, src) c89atomic_fetch_xor_explicit_64(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_and_8( dst, src) c89atomic_fetch_and_explicit_8 (dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_and_16(dst, src) c89atomic_fetch_and_explicit_16(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_and_32(dst, src) c89atomic_fetch_and_explicit_32(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_and_64(dst, src) c89atomic_fetch_and_explicit_64(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_test_and_set_explicit_i8( ptr, order) (c89atomic_int8 )c89atomic_test_and_set_explicit_8( (c89atomic_uint8* )ptr, order)
-#define c89atomic_test_and_set_explicit_i16(ptr, order) (c89atomic_int16)c89atomic_test_and_set_explicit_16((c89atomic_uint16*)ptr, order)
-#define c89atomic_test_and_set_explicit_i32(ptr, order) (c89atomic_int32)c89atomic_test_and_set_explicit_32((c89atomic_uint32*)ptr, order)
-#define c89atomic_test_and_set_explicit_i64(ptr, order) (c89atomic_int64)c89atomic_test_and_set_explicit_64((c89atomic_uint64*)ptr, order)
-#define c89atomic_clear_explicit_i8( ptr, order) c89atomic_clear_explicit_8( (c89atomic_uint8* )ptr, order)
-#define c89atomic_clear_explicit_i16(ptr, order) c89atomic_clear_explicit_16((c89atomic_uint16*)ptr, order)
-#define c89atomic_clear_explicit_i32(ptr, order) c89atomic_clear_explicit_32((c89atomic_uint32*)ptr, order)
-#define c89atomic_clear_explicit_i64(ptr, order) c89atomic_clear_explicit_64((c89atomic_uint64*)ptr, order)
-#define c89atomic_store_explicit_i8( dst, src, order) (c89atomic_int8 )c89atomic_store_explicit_8( (c89atomic_uint8* )dst, (c89atomic_uint8 )src, order)
-#define c89atomic_store_explicit_i16(dst, src, order) (c89atomic_int16)c89atomic_store_explicit_16((c89atomic_uint16*)dst, (c89atomic_uint16)src, order)
-#define c89atomic_store_explicit_i32(dst, src, order) (c89atomic_int32)c89atomic_store_explicit_32((c89atomic_uint32*)dst, (c89atomic_uint32)src, order)
-#define c89atomic_store_explicit_i64(dst, src, order) (c89atomic_int64)c89atomic_store_explicit_64((c89atomic_uint64*)dst, (c89atomic_uint64)src, order)
-#define c89atomic_load_explicit_i8( ptr, order) (c89atomic_int8 )c89atomic_load_explicit_8( (c89atomic_uint8* )ptr, order)
-#define c89atomic_load_explicit_i16(ptr, order) (c89atomic_int16)c89atomic_load_explicit_16((c89atomic_uint16*)ptr, order)
-#define c89atomic_load_explicit_i32(ptr, order) (c89atomic_int32)c89atomic_load_explicit_32((c89atomic_uint32*)ptr, order)
-#define c89atomic_load_explicit_i64(ptr, order) (c89atomic_int64)c89atomic_load_explicit_64((c89atomic_uint64*)ptr, order)
-#define c89atomic_exchange_explicit_i8( dst, src, order) (c89atomic_int8 )c89atomic_exchange_explicit_8 ((c89atomic_uint8* )dst, (c89atomic_uint8 )src, order)
-#define c89atomic_exchange_explicit_i16(dst, src, order) (c89atomic_int16)c89atomic_exchange_explicit_16((c89atomic_uint16*)dst, (c89atomic_uint16)src, order)
-#define c89atomic_exchange_explicit_i32(dst, src, order) (c89atomic_int32)c89atomic_exchange_explicit_32((c89atomic_uint32*)dst, (c89atomic_uint32)src, order)
-#define c89atomic_exchange_explicit_i64(dst, src, order) (c89atomic_int64)c89atomic_exchange_explicit_64((c89atomic_uint64*)dst, (c89atomic_uint64)src, order)
-#define c89atomic_compare_exchange_strong_explicit_i8( dst, expected, desired, successOrder, failureOrder) c89atomic_compare_exchange_strong_explicit_8( (c89atomic_uint8* )dst, (c89atomic_uint8* )expected, (c89atomic_uint8 )desired, successOrder, failureOrder)
-#define c89atomic_compare_exchange_strong_explicit_i16(dst, expected, desired, successOrder, failureOrder) c89atomic_compare_exchange_strong_explicit_16((c89atomic_uint16*)dst, (c89atomic_uint16*)expected, (c89atomic_uint16)desired, successOrder, failureOrder)
-#define c89atomic_compare_exchange_strong_explicit_i32(dst, expected, desired, successOrder, failureOrder) c89atomic_compare_exchange_strong_explicit_32((c89atomic_uint32*)dst, (c89atomic_uint32*)expected, (c89atomic_uint32)desired, successOrder, failureOrder)
-#define c89atomic_compare_exchange_strong_explicit_i64(dst, expected, desired, successOrder, failureOrder) c89atomic_compare_exchange_strong_explicit_64((c89atomic_uint64*)dst, (c89atomic_uint64*)expected, (c89atomic_uint64)desired, successOrder, failureOrder)
-#define c89atomic_compare_exchange_weak_explicit_i8( dst, expected, desired, successOrder, failureOrder) c89atomic_compare_exchange_weak_explicit_8( (c89atomic_uint8* )dst, (c89atomic_uint8* )expected, (c89atomic_uint8 )desired, successOrder, failureOrder)
-#define c89atomic_compare_exchange_weak_explicit_i16(dst, expected, desired, successOrder, failureOrder) c89atomic_compare_exchange_weak_explicit_16((c89atomic_uint16*)dst, (c89atomic_uint16*)expected, (c89atomic_uint16)desired, successOrder, failureOrder)
-#define c89atomic_compare_exchange_weak_explicit_i32(dst, expected, desired, successOrder, failureOrder) c89atomic_compare_exchange_weak_explicit_32((c89atomic_uint32*)dst, (c89atomic_uint32*)expected, (c89atomic_uint32)desired, successOrder, failureOrder)
-#define c89atomic_compare_exchange_weak_explicit_i64(dst, expected, desired, successOrder, failureOrder) c89atomic_compare_exchange_weak_explicit_64((c89atomic_uint64*)dst, (c89atomic_uint64*)expected, (c89atomic_uint64)desired, successOrder, failureOrder)
-#define c89atomic_fetch_add_explicit_i8( dst, src, order) (c89atomic_int8 )c89atomic_fetch_add_explicit_8( (c89atomic_uint8* )dst, (c89atomic_uint8 )src, order)
-#define c89atomic_fetch_add_explicit_i16(dst, src, order) (c89atomic_int16)c89atomic_fetch_add_explicit_16((c89atomic_uint16*)dst, (c89atomic_uint16)src, order)
-#define c89atomic_fetch_add_explicit_i32(dst, src, order) (c89atomic_int32)c89atomic_fetch_add_explicit_32((c89atomic_uint32*)dst, (c89atomic_uint32)src, order)
-#define c89atomic_fetch_add_explicit_i64(dst, src, order) (c89atomic_int64)c89atomic_fetch_add_explicit_64((c89atomic_uint64*)dst, (c89atomic_uint64)src, order)
-#define c89atomic_fetch_sub_explicit_i8( dst, src, order) (c89atomic_int8 )c89atomic_fetch_sub_explicit_8( (c89atomic_uint8* )dst, (c89atomic_uint8 )src, order)
-#define c89atomic_fetch_sub_explicit_i16(dst, src, order) (c89atomic_int16)c89atomic_fetch_sub_explicit_16((c89atomic_uint16*)dst, (c89atomic_uint16)src, order)
-#define c89atomic_fetch_sub_explicit_i32(dst, src, order) (c89atomic_int32)c89atomic_fetch_sub_explicit_32((c89atomic_uint32*)dst, (c89atomic_uint32)src, order)
-#define c89atomic_fetch_sub_explicit_i64(dst, src, order) (c89atomic_int64)c89atomic_fetch_sub_explicit_64((c89atomic_uint64*)dst, (c89atomic_uint64)src, order)
-#define c89atomic_fetch_or_explicit_i8( dst, src, order) (c89atomic_int8 )c89atomic_fetch_or_explicit_8( (c89atomic_uint8* )dst, (c89atomic_uint8 )src, order)
-#define c89atomic_fetch_or_explicit_i16(dst, src, order) (c89atomic_int16)c89atomic_fetch_or_explicit_16((c89atomic_uint16*)dst, (c89atomic_uint16)src, order)
-#define c89atomic_fetch_or_explicit_i32(dst, src, order) (c89atomic_int32)c89atomic_fetch_or_explicit_32((c89atomic_uint32*)dst, (c89atomic_uint32)src, order)
-#define c89atomic_fetch_or_explicit_i64(dst, src, order) (c89atomic_int64)c89atomic_fetch_or_explicit_64((c89atomic_uint64*)dst, (c89atomic_uint64)src, order)
-#define c89atomic_fetch_xor_explicit_i8( dst, src, order) (c89atomic_int8 )c89atomic_fetch_xor_explicit_8( (c89atomic_uint8* )dst, (c89atomic_uint8 )src, order)
-#define c89atomic_fetch_xor_explicit_i16(dst, src, order) (c89atomic_int16)c89atomic_fetch_xor_explicit_16((c89atomic_uint16*)dst, (c89atomic_uint16)src, order)
-#define c89atomic_fetch_xor_explicit_i32(dst, src, order) (c89atomic_int32)c89atomic_fetch_xor_explicit_32((c89atomic_uint32*)dst, (c89atomic_uint32)src, order)
-#define c89atomic_fetch_xor_explicit_i64(dst, src, order) (c89atomic_int64)c89atomic_fetch_xor_explicit_64((c89atomic_uint64*)dst, (c89atomic_uint64)src, order)
-#define c89atomic_fetch_and_explicit_i8( dst, src, order) (c89atomic_int8 )c89atomic_fetch_and_explicit_8( (c89atomic_uint8* )dst, (c89atomic_uint8 )src, order)
-#define c89atomic_fetch_and_explicit_i16(dst, src, order) (c89atomic_int16)c89atomic_fetch_and_explicit_16((c89atomic_uint16*)dst, (c89atomic_uint16)src, order)
-#define c89atomic_fetch_and_explicit_i32(dst, src, order) (c89atomic_int32)c89atomic_fetch_and_explicit_32((c89atomic_uint32*)dst, (c89atomic_uint32)src, order)
-#define c89atomic_fetch_and_explicit_i64(dst, src, order) (c89atomic_int64)c89atomic_fetch_and_explicit_64((c89atomic_uint64*)dst, (c89atomic_uint64)src, order)
-#define c89atomic_test_and_set_i8( ptr) c89atomic_test_and_set_explicit_i8( ptr, c89atomic_memory_order_seq_cst)
-#define c89atomic_test_and_set_i16(ptr) c89atomic_test_and_set_explicit_i16(ptr, c89atomic_memory_order_seq_cst)
-#define c89atomic_test_and_set_i32(ptr) c89atomic_test_and_set_explicit_i32(ptr, c89atomic_memory_order_seq_cst)
-#define c89atomic_test_and_set_i64(ptr) c89atomic_test_and_set_explicit_i64(ptr, c89atomic_memory_order_seq_cst)
-#define c89atomic_clear_i8( ptr) c89atomic_clear_explicit_i8( ptr, c89atomic_memory_order_seq_cst)
-#define c89atomic_clear_i16(ptr) c89atomic_clear_explicit_i16(ptr, c89atomic_memory_order_seq_cst)
-#define c89atomic_clear_i32(ptr) c89atomic_clear_explicit_i32(ptr, c89atomic_memory_order_seq_cst)
-#define c89atomic_clear_i64(ptr) c89atomic_clear_explicit_i64(ptr, c89atomic_memory_order_seq_cst)
-#define c89atomic_store_i8( dst, src) c89atomic_store_explicit_i8( dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_store_i16(dst, src) c89atomic_store_explicit_i16(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_store_i32(dst, src) c89atomic_store_explicit_i32(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_store_i64(dst, src) c89atomic_store_explicit_i64(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_load_i8( ptr) c89atomic_load_explicit_i8( ptr, c89atomic_memory_order_seq_cst)
-#define c89atomic_load_i16(ptr) c89atomic_load_explicit_i16(ptr, c89atomic_memory_order_seq_cst)
-#define c89atomic_load_i32(ptr) c89atomic_load_explicit_i32(ptr, c89atomic_memory_order_seq_cst)
-#define c89atomic_load_i64(ptr) c89atomic_load_explicit_i64(ptr, c89atomic_memory_order_seq_cst)
-#define c89atomic_exchange_i8( dst, src) c89atomic_exchange_explicit_i8( dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_exchange_i16(dst, src) c89atomic_exchange_explicit_i16(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_exchange_i32(dst, src) c89atomic_exchange_explicit_i32(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_exchange_i64(dst, src) c89atomic_exchange_explicit_i64(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_compare_exchange_strong_i8( dst, expected, desired) c89atomic_compare_exchange_strong_explicit_i8( dst, expected, desired, c89atomic_memory_order_seq_cst, c89atomic_memory_order_seq_cst)
-#define c89atomic_compare_exchange_strong_i16(dst, expected, desired) c89atomic_compare_exchange_strong_explicit_i16(dst, expected, desired, c89atomic_memory_order_seq_cst, c89atomic_memory_order_seq_cst)
-#define c89atomic_compare_exchange_strong_i32(dst, expected, desired) c89atomic_compare_exchange_strong_explicit_i32(dst, expected, desired, c89atomic_memory_order_seq_cst, c89atomic_memory_order_seq_cst)
-#define c89atomic_compare_exchange_strong_i64(dst, expected, desired) c89atomic_compare_exchange_strong_explicit_i64(dst, expected, desired, c89atomic_memory_order_seq_cst, c89atomic_memory_order_seq_cst)
-#define c89atomic_compare_exchange_weak_i8( dst, expected, desired) c89atomic_compare_exchange_weak_explicit_i8( dst, expected, desired, c89atomic_memory_order_seq_cst, c89atomic_memory_order_seq_cst)
-#define c89atomic_compare_exchange_weak_i16(dst, expected, desired) c89atomic_compare_exchange_weak_explicit_i16(dst, expected, desired, c89atomic_memory_order_seq_cst, c89atomic_memory_order_seq_cst)
-#define c89atomic_compare_exchange_weak_i32(dst, expected, desired) c89atomic_compare_exchange_weak_explicit_i32(dst, expected, desired, c89atomic_memory_order_seq_cst, c89atomic_memory_order_seq_cst)
-#define c89atomic_compare_exchange_weak_i64(dst, expected, desired) c89atomic_compare_exchange_weak_explicit_i64(dst, expected, desired, c89atomic_memory_order_seq_cst, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_add_i8( dst, src) c89atomic_fetch_add_explicit_i8( dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_add_i16(dst, src) c89atomic_fetch_add_explicit_i16(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_add_i32(dst, src) c89atomic_fetch_add_explicit_i32(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_add_i64(dst, src) c89atomic_fetch_add_explicit_i64(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_sub_i8( dst, src) c89atomic_fetch_sub_explicit_i8( dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_sub_i16(dst, src) c89atomic_fetch_sub_explicit_i16(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_sub_i32(dst, src) c89atomic_fetch_sub_explicit_i32(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_sub_i64(dst, src) c89atomic_fetch_sub_explicit_i64(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_or_i8( dst, src) c89atomic_fetch_or_explicit_i8( dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_or_i16(dst, src) c89atomic_fetch_or_explicit_i16(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_or_i32(dst, src) c89atomic_fetch_or_explicit_i32(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_or_i64(dst, src) c89atomic_fetch_or_explicit_i64(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_xor_i8( dst, src) c89atomic_fetch_xor_explicit_i8( dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_xor_i16(dst, src) c89atomic_fetch_xor_explicit_i16(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_xor_i32(dst, src) c89atomic_fetch_xor_explicit_i32(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_xor_i64(dst, src) c89atomic_fetch_xor_explicit_i64(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_and_i8( dst, src) c89atomic_fetch_and_explicit_i8( dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_and_i16(dst, src) c89atomic_fetch_and_explicit_i16(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_and_i32(dst, src) c89atomic_fetch_and_explicit_i32(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_fetch_and_i64(dst, src) c89atomic_fetch_and_explicit_i64(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_compare_and_swap_i8( dst, expected, dedsired) (c89atomic_int8 )c89atomic_compare_and_swap_8( (c89atomic_uint8* )dst, (c89atomic_uint8 )expected, (c89atomic_uint8 )dedsired)
-#define c89atomic_compare_and_swap_i16(dst, expected, dedsired) (c89atomic_int16)c89atomic_compare_and_swap_16((c89atomic_uint16*)dst, (c89atomic_uint16)expected, (c89atomic_uint16)dedsired)
-#define c89atomic_compare_and_swap_i32(dst, expected, dedsired) (c89atomic_int32)c89atomic_compare_and_swap_32((c89atomic_uint32*)dst, (c89atomic_uint32)expected, (c89atomic_uint32)dedsired)
-#define c89atomic_compare_and_swap_i64(dst, expected, dedsired) (c89atomic_int64)c89atomic_compare_and_swap_64((c89atomic_uint64*)dst, (c89atomic_uint64)expected, (c89atomic_uint64)dedsired)
+#define ma_atomic_flag_test_and_set(ptr) ma_atomic_flag_test_and_set_explicit(ptr, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_flag_clear(ptr) ma_atomic_flag_clear_explicit(ptr, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_store_ptr(dst, src) ma_atomic_store_explicit_ptr((volatile void**)dst, (void*)src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_load_ptr(ptr) ma_atomic_load_explicit_ptr((volatile void**)ptr, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_exchange_ptr(dst, src) ma_atomic_exchange_explicit_ptr((volatile void**)dst, (void*)src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_compare_exchange_strong_ptr(dst, expected, desired) ma_atomic_compare_exchange_strong_explicit_ptr((volatile void**)dst, (void**)expected, (void*)desired, ma_atomic_memory_order_seq_cst, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_compare_exchange_weak_ptr(dst, expected, desired) ma_atomic_compare_exchange_weak_explicit_ptr((volatile void**)dst, (void**)expected, (void*)desired, ma_atomic_memory_order_seq_cst, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_test_and_set_8( ptr) ma_atomic_test_and_set_explicit_8( ptr, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_test_and_set_16(ptr) ma_atomic_test_and_set_explicit_16(ptr, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_test_and_set_32(ptr) ma_atomic_test_and_set_explicit_32(ptr, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_test_and_set_64(ptr) ma_atomic_test_and_set_explicit_64(ptr, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_clear_8( ptr) ma_atomic_clear_explicit_8( ptr, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_clear_16(ptr) ma_atomic_clear_explicit_16(ptr, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_clear_32(ptr) ma_atomic_clear_explicit_32(ptr, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_clear_64(ptr) ma_atomic_clear_explicit_64(ptr, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_store_8( dst, src) ma_atomic_store_explicit_8( dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_store_16(dst, src) ma_atomic_store_explicit_16(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_store_32(dst, src) ma_atomic_store_explicit_32(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_store_64(dst, src) ma_atomic_store_explicit_64(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_load_8( ptr) ma_atomic_load_explicit_8( ptr, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_load_16(ptr) ma_atomic_load_explicit_16(ptr, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_load_32(ptr) ma_atomic_load_explicit_32(ptr, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_load_64(ptr) ma_atomic_load_explicit_64(ptr, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_exchange_8( dst, src) ma_atomic_exchange_explicit_8( dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_exchange_16(dst, src) ma_atomic_exchange_explicit_16(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_exchange_32(dst, src) ma_atomic_exchange_explicit_32(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_exchange_64(dst, src) ma_atomic_exchange_explicit_64(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_compare_exchange_strong_8( dst, expected, desired) ma_atomic_compare_exchange_strong_explicit_8( dst, expected, desired, ma_atomic_memory_order_seq_cst, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_compare_exchange_strong_16(dst, expected, desired) ma_atomic_compare_exchange_strong_explicit_16(dst, expected, desired, ma_atomic_memory_order_seq_cst, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_compare_exchange_strong_32(dst, expected, desired) ma_atomic_compare_exchange_strong_explicit_32(dst, expected, desired, ma_atomic_memory_order_seq_cst, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_compare_exchange_strong_64(dst, expected, desired) ma_atomic_compare_exchange_strong_explicit_64(dst, expected, desired, ma_atomic_memory_order_seq_cst, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_compare_exchange_weak_8( dst, expected, desired) ma_atomic_compare_exchange_weak_explicit_8( dst, expected, desired, ma_atomic_memory_order_seq_cst, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_compare_exchange_weak_16( dst, expected, desired) ma_atomic_compare_exchange_weak_explicit_16(dst, expected, desired, ma_atomic_memory_order_seq_cst, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_compare_exchange_weak_32( dst, expected, desired) ma_atomic_compare_exchange_weak_explicit_32(dst, expected, desired, ma_atomic_memory_order_seq_cst, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_compare_exchange_weak_64( dst, expected, desired) ma_atomic_compare_exchange_weak_explicit_64(dst, expected, desired, ma_atomic_memory_order_seq_cst, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_add_8( dst, src) ma_atomic_fetch_add_explicit_8( dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_add_16(dst, src) ma_atomic_fetch_add_explicit_16(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_add_32(dst, src) ma_atomic_fetch_add_explicit_32(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_add_64(dst, src) ma_atomic_fetch_add_explicit_64(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_sub_8( dst, src) ma_atomic_fetch_sub_explicit_8( dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_sub_16(dst, src) ma_atomic_fetch_sub_explicit_16(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_sub_32(dst, src) ma_atomic_fetch_sub_explicit_32(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_sub_64(dst, src) ma_atomic_fetch_sub_explicit_64(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_or_8( dst, src) ma_atomic_fetch_or_explicit_8( dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_or_16(dst, src) ma_atomic_fetch_or_explicit_16(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_or_32(dst, src) ma_atomic_fetch_or_explicit_32(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_or_64(dst, src) ma_atomic_fetch_or_explicit_64(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_xor_8( dst, src) ma_atomic_fetch_xor_explicit_8( dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_xor_16(dst, src) ma_atomic_fetch_xor_explicit_16(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_xor_32(dst, src) ma_atomic_fetch_xor_explicit_32(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_xor_64(dst, src) ma_atomic_fetch_xor_explicit_64(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_and_8( dst, src) ma_atomic_fetch_and_explicit_8 (dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_and_16(dst, src) ma_atomic_fetch_and_explicit_16(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_and_32(dst, src) ma_atomic_fetch_and_explicit_32(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_and_64(dst, src) ma_atomic_fetch_and_explicit_64(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_test_and_set_explicit_i8( ptr, order) (ma_int8 )ma_atomic_test_and_set_explicit_8( (ma_uint8* )ptr, order)
+#define ma_atomic_test_and_set_explicit_i16(ptr, order) (ma_int16)ma_atomic_test_and_set_explicit_16((ma_uint16*)ptr, order)
+#define ma_atomic_test_and_set_explicit_i32(ptr, order) (ma_int32)ma_atomic_test_and_set_explicit_32((ma_uint32*)ptr, order)
+#define ma_atomic_test_and_set_explicit_i64(ptr, order) (ma_int64)ma_atomic_test_and_set_explicit_64((ma_uint64*)ptr, order)
+#define ma_atomic_clear_explicit_i8( ptr, order) ma_atomic_clear_explicit_8( (ma_uint8* )ptr, order)
+#define ma_atomic_clear_explicit_i16(ptr, order) ma_atomic_clear_explicit_16((ma_uint16*)ptr, order)
+#define ma_atomic_clear_explicit_i32(ptr, order) ma_atomic_clear_explicit_32((ma_uint32*)ptr, order)
+#define ma_atomic_clear_explicit_i64(ptr, order) ma_atomic_clear_explicit_64((ma_uint64*)ptr, order)
+#define ma_atomic_store_explicit_i8( dst, src, order) ma_atomic_store_explicit_8( (ma_uint8* )dst, (ma_uint8 )src, order)
+#define ma_atomic_store_explicit_i16(dst, src, order) ma_atomic_store_explicit_16((ma_uint16*)dst, (ma_uint16)src, order)
+#define ma_atomic_store_explicit_i32(dst, src, order) ma_atomic_store_explicit_32((ma_uint32*)dst, (ma_uint32)src, order)
+#define ma_atomic_store_explicit_i64(dst, src, order) ma_atomic_store_explicit_64((ma_uint64*)dst, (ma_uint64)src, order)
+#define ma_atomic_load_explicit_i8( ptr, order) (ma_int8 )ma_atomic_load_explicit_8( (ma_uint8* )ptr, order)
+#define ma_atomic_load_explicit_i16(ptr, order) (ma_int16)ma_atomic_load_explicit_16((ma_uint16*)ptr, order)
+#define ma_atomic_load_explicit_i32(ptr, order) (ma_int32)ma_atomic_load_explicit_32((ma_uint32*)ptr, order)
+#define ma_atomic_load_explicit_i64(ptr, order) (ma_int64)ma_atomic_load_explicit_64((ma_uint64*)ptr, order)
+#define ma_atomic_exchange_explicit_i8( dst, src, order) (ma_int8 )ma_atomic_exchange_explicit_8 ((ma_uint8* )dst, (ma_uint8 )src, order)
+#define ma_atomic_exchange_explicit_i16(dst, src, order) (ma_int16)ma_atomic_exchange_explicit_16((ma_uint16*)dst, (ma_uint16)src, order)
+#define ma_atomic_exchange_explicit_i32(dst, src, order) (ma_int32)ma_atomic_exchange_explicit_32((ma_uint32*)dst, (ma_uint32)src, order)
+#define ma_atomic_exchange_explicit_i64(dst, src, order) (ma_int64)ma_atomic_exchange_explicit_64((ma_uint64*)dst, (ma_uint64)src, order)
+#define ma_atomic_compare_exchange_strong_explicit_i8( dst, expected, desired, successOrder, failureOrder) ma_atomic_compare_exchange_strong_explicit_8( (ma_uint8* )dst, (ma_uint8* )expected, (ma_uint8 )desired, successOrder, failureOrder)
+#define ma_atomic_compare_exchange_strong_explicit_i16(dst, expected, desired, successOrder, failureOrder) ma_atomic_compare_exchange_strong_explicit_16((ma_uint16*)dst, (ma_uint16*)expected, (ma_uint16)desired, successOrder, failureOrder)
+#define ma_atomic_compare_exchange_strong_explicit_i32(dst, expected, desired, successOrder, failureOrder) ma_atomic_compare_exchange_strong_explicit_32((ma_uint32*)dst, (ma_uint32*)expected, (ma_uint32)desired, successOrder, failureOrder)
+#define ma_atomic_compare_exchange_strong_explicit_i64(dst, expected, desired, successOrder, failureOrder) ma_atomic_compare_exchange_strong_explicit_64((ma_uint64*)dst, (ma_uint64*)expected, (ma_uint64)desired, successOrder, failureOrder)
+#define ma_atomic_compare_exchange_weak_explicit_i8( dst, expected, desired, successOrder, failureOrder) ma_atomic_compare_exchange_weak_explicit_8( (ma_uint8* )dst, (ma_uint8* )expected, (ma_uint8 )desired, successOrder, failureOrder)
+#define ma_atomic_compare_exchange_weak_explicit_i16(dst, expected, desired, successOrder, failureOrder) ma_atomic_compare_exchange_weak_explicit_16((ma_uint16*)dst, (ma_uint16*)expected, (ma_uint16)desired, successOrder, failureOrder)
+#define ma_atomic_compare_exchange_weak_explicit_i32(dst, expected, desired, successOrder, failureOrder) ma_atomic_compare_exchange_weak_explicit_32((ma_uint32*)dst, (ma_uint32*)expected, (ma_uint32)desired, successOrder, failureOrder)
+#define ma_atomic_compare_exchange_weak_explicit_i64(dst, expected, desired, successOrder, failureOrder) ma_atomic_compare_exchange_weak_explicit_64((ma_uint64*)dst, (ma_uint64*)expected, (ma_uint64)desired, successOrder, failureOrder)
+#define ma_atomic_fetch_add_explicit_i8( dst, src, order) (ma_int8 )ma_atomic_fetch_add_explicit_8( (ma_uint8* )dst, (ma_uint8 )src, order)
+#define ma_atomic_fetch_add_explicit_i16(dst, src, order) (ma_int16)ma_atomic_fetch_add_explicit_16((ma_uint16*)dst, (ma_uint16)src, order)
+#define ma_atomic_fetch_add_explicit_i32(dst, src, order) (ma_int32)ma_atomic_fetch_add_explicit_32((ma_uint32*)dst, (ma_uint32)src, order)
+#define ma_atomic_fetch_add_explicit_i64(dst, src, order) (ma_int64)ma_atomic_fetch_add_explicit_64((ma_uint64*)dst, (ma_uint64)src, order)
+#define ma_atomic_fetch_sub_explicit_i8( dst, src, order) (ma_int8 )ma_atomic_fetch_sub_explicit_8( (ma_uint8* )dst, (ma_uint8 )src, order)
+#define ma_atomic_fetch_sub_explicit_i16(dst, src, order) (ma_int16)ma_atomic_fetch_sub_explicit_16((ma_uint16*)dst, (ma_uint16)src, order)
+#define ma_atomic_fetch_sub_explicit_i32(dst, src, order) (ma_int32)ma_atomic_fetch_sub_explicit_32((ma_uint32*)dst, (ma_uint32)src, order)
+#define ma_atomic_fetch_sub_explicit_i64(dst, src, order) (ma_int64)ma_atomic_fetch_sub_explicit_64((ma_uint64*)dst, (ma_uint64)src, order)
+#define ma_atomic_fetch_or_explicit_i8( dst, src, order) (ma_int8 )ma_atomic_fetch_or_explicit_8( (ma_uint8* )dst, (ma_uint8 )src, order)
+#define ma_atomic_fetch_or_explicit_i16(dst, src, order) (ma_int16)ma_atomic_fetch_or_explicit_16((ma_uint16*)dst, (ma_uint16)src, order)
+#define ma_atomic_fetch_or_explicit_i32(dst, src, order) (ma_int32)ma_atomic_fetch_or_explicit_32((ma_uint32*)dst, (ma_uint32)src, order)
+#define ma_atomic_fetch_or_explicit_i64(dst, src, order) (ma_int64)ma_atomic_fetch_or_explicit_64((ma_uint64*)dst, (ma_uint64)src, order)
+#define ma_atomic_fetch_xor_explicit_i8( dst, src, order) (ma_int8 )ma_atomic_fetch_xor_explicit_8( (ma_uint8* )dst, (ma_uint8 )src, order)
+#define ma_atomic_fetch_xor_explicit_i16(dst, src, order) (ma_int16)ma_atomic_fetch_xor_explicit_16((ma_uint16*)dst, (ma_uint16)src, order)
+#define ma_atomic_fetch_xor_explicit_i32(dst, src, order) (ma_int32)ma_atomic_fetch_xor_explicit_32((ma_uint32*)dst, (ma_uint32)src, order)
+#define ma_atomic_fetch_xor_explicit_i64(dst, src, order) (ma_int64)ma_atomic_fetch_xor_explicit_64((ma_uint64*)dst, (ma_uint64)src, order)
+#define ma_atomic_fetch_and_explicit_i8( dst, src, order) (ma_int8 )ma_atomic_fetch_and_explicit_8( (ma_uint8* )dst, (ma_uint8 )src, order)
+#define ma_atomic_fetch_and_explicit_i16(dst, src, order) (ma_int16)ma_atomic_fetch_and_explicit_16((ma_uint16*)dst, (ma_uint16)src, order)
+#define ma_atomic_fetch_and_explicit_i32(dst, src, order) (ma_int32)ma_atomic_fetch_and_explicit_32((ma_uint32*)dst, (ma_uint32)src, order)
+#define ma_atomic_fetch_and_explicit_i64(dst, src, order) (ma_int64)ma_atomic_fetch_and_explicit_64((ma_uint64*)dst, (ma_uint64)src, order)
+#define ma_atomic_test_and_set_i8( ptr) ma_atomic_test_and_set_explicit_i8( ptr, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_test_and_set_i16(ptr) ma_atomic_test_and_set_explicit_i16(ptr, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_test_and_set_i32(ptr) ma_atomic_test_and_set_explicit_i32(ptr, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_test_and_set_i64(ptr) ma_atomic_test_and_set_explicit_i64(ptr, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_clear_i8( ptr) ma_atomic_clear_explicit_i8( ptr, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_clear_i16(ptr) ma_atomic_clear_explicit_i16(ptr, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_clear_i32(ptr) ma_atomic_clear_explicit_i32(ptr, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_clear_i64(ptr) ma_atomic_clear_explicit_i64(ptr, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_store_i8( dst, src) ma_atomic_store_explicit_i8( dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_store_i16(dst, src) ma_atomic_store_explicit_i16(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_store_i32(dst, src) ma_atomic_store_explicit_i32(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_store_i64(dst, src) ma_atomic_store_explicit_i64(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_load_i8( ptr) ma_atomic_load_explicit_i8( ptr, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_load_i16(ptr) ma_atomic_load_explicit_i16(ptr, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_load_i32(ptr) ma_atomic_load_explicit_i32(ptr, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_load_i64(ptr) ma_atomic_load_explicit_i64(ptr, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_exchange_i8( dst, src) ma_atomic_exchange_explicit_i8( dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_exchange_i16(dst, src) ma_atomic_exchange_explicit_i16(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_exchange_i32(dst, src) ma_atomic_exchange_explicit_i32(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_exchange_i64(dst, src) ma_atomic_exchange_explicit_i64(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_compare_exchange_strong_i8( dst, expected, desired) ma_atomic_compare_exchange_strong_explicit_i8( dst, expected, desired, ma_atomic_memory_order_seq_cst, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_compare_exchange_strong_i16(dst, expected, desired) ma_atomic_compare_exchange_strong_explicit_i16(dst, expected, desired, ma_atomic_memory_order_seq_cst, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_compare_exchange_strong_i32(dst, expected, desired) ma_atomic_compare_exchange_strong_explicit_i32(dst, expected, desired, ma_atomic_memory_order_seq_cst, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_compare_exchange_strong_i64(dst, expected, desired) ma_atomic_compare_exchange_strong_explicit_i64(dst, expected, desired, ma_atomic_memory_order_seq_cst, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_compare_exchange_weak_i8( dst, expected, desired) ma_atomic_compare_exchange_weak_explicit_i8( dst, expected, desired, ma_atomic_memory_order_seq_cst, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_compare_exchange_weak_i16(dst, expected, desired) ma_atomic_compare_exchange_weak_explicit_i16(dst, expected, desired, ma_atomic_memory_order_seq_cst, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_compare_exchange_weak_i32(dst, expected, desired) ma_atomic_compare_exchange_weak_explicit_i32(dst, expected, desired, ma_atomic_memory_order_seq_cst, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_compare_exchange_weak_i64(dst, expected, desired) ma_atomic_compare_exchange_weak_explicit_i64(dst, expected, desired, ma_atomic_memory_order_seq_cst, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_add_i8( dst, src) ma_atomic_fetch_add_explicit_i8( dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_add_i16(dst, src) ma_atomic_fetch_add_explicit_i16(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_add_i32(dst, src) ma_atomic_fetch_add_explicit_i32(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_add_i64(dst, src) ma_atomic_fetch_add_explicit_i64(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_sub_i8( dst, src) ma_atomic_fetch_sub_explicit_i8( dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_sub_i16(dst, src) ma_atomic_fetch_sub_explicit_i16(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_sub_i32(dst, src) ma_atomic_fetch_sub_explicit_i32(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_sub_i64(dst, src) ma_atomic_fetch_sub_explicit_i64(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_or_i8( dst, src) ma_atomic_fetch_or_explicit_i8( dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_or_i16(dst, src) ma_atomic_fetch_or_explicit_i16(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_or_i32(dst, src) ma_atomic_fetch_or_explicit_i32(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_or_i64(dst, src) ma_atomic_fetch_or_explicit_i64(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_xor_i8( dst, src) ma_atomic_fetch_xor_explicit_i8( dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_xor_i16(dst, src) ma_atomic_fetch_xor_explicit_i16(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_xor_i32(dst, src) ma_atomic_fetch_xor_explicit_i32(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_xor_i64(dst, src) ma_atomic_fetch_xor_explicit_i64(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_and_i8( dst, src) ma_atomic_fetch_and_explicit_i8( dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_and_i16(dst, src) ma_atomic_fetch_and_explicit_i16(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_and_i32(dst, src) ma_atomic_fetch_and_explicit_i32(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_and_i64(dst, src) ma_atomic_fetch_and_explicit_i64(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_compare_and_swap_i8( dst, expected, dedsired) (ma_int8 )ma_atomic_compare_and_swap_8( (ma_uint8* )dst, (ma_uint8 )expected, (ma_uint8 )dedsired)
+#define ma_atomic_compare_and_swap_i16(dst, expected, dedsired) (ma_int16)ma_atomic_compare_and_swap_16((ma_uint16*)dst, (ma_uint16)expected, (ma_uint16)dedsired)
+#define ma_atomic_compare_and_swap_i32(dst, expected, dedsired) (ma_int32)ma_atomic_compare_and_swap_32((ma_uint32*)dst, (ma_uint32)expected, (ma_uint32)dedsired)
+#define ma_atomic_compare_and_swap_i64(dst, expected, dedsired) (ma_int64)ma_atomic_compare_and_swap_64((ma_uint64*)dst, (ma_uint64)expected, (ma_uint64)dedsired)
typedef union
{
- c89atomic_uint32 i;
+ ma_uint32 i;
float f;
-} c89atomic_if32;
+} ma_atomic_if32;
typedef union
{
- c89atomic_uint64 i;
+ ma_uint64 i;
double f;
-} c89atomic_if64;
-#define c89atomic_clear_explicit_f32(ptr, order) c89atomic_clear_explicit_32((c89atomic_uint32*)ptr, order)
-#define c89atomic_clear_explicit_f64(ptr, order) c89atomic_clear_explicit_64((c89atomic_uint64*)ptr, order)
-static C89ATOMIC_INLINE void c89atomic_store_explicit_f32(volatile float* dst, float src, c89atomic_memory_order order)
+} ma_atomic_if64;
+#define ma_atomic_clear_explicit_f32(ptr, order) ma_atomic_clear_explicit_32((ma_uint32*)ptr, order)
+#define ma_atomic_clear_explicit_f64(ptr, order) ma_atomic_clear_explicit_64((ma_uint64*)ptr, order)
+static MA_INLINE void ma_atomic_store_explicit_f32(volatile float* dst, float src, ma_atomic_memory_order order)
+{
+ ma_atomic_if32 x;
+ x.f = src;
+ ma_atomic_store_explicit_32((volatile ma_uint32*)dst, x.i, order);
+}
+static MA_INLINE void ma_atomic_store_explicit_f64(volatile double* dst, double src, ma_atomic_memory_order order)
{
- c89atomic_if32 x;
+ ma_atomic_if64 x;
x.f = src;
- c89atomic_store_explicit_32((volatile c89atomic_uint32*)dst, x.i, order);
+ ma_atomic_store_explicit_64((volatile ma_uint64*)dst, x.i, order);
}
-static C89ATOMIC_INLINE void c89atomic_store_explicit_f64(volatile double* dst, double src, c89atomic_memory_order order)
+static MA_INLINE float ma_atomic_load_explicit_f32(volatile const float* ptr, ma_atomic_memory_order order)
{
- c89atomic_if64 x;
+ ma_atomic_if32 r;
+ r.i = ma_atomic_load_explicit_32((volatile const ma_uint32*)ptr, order);
+ return r.f;
+}
+static MA_INLINE double ma_atomic_load_explicit_f64(volatile const double* ptr, ma_atomic_memory_order order)
+{
+ ma_atomic_if64 r;
+ r.i = ma_atomic_load_explicit_64((volatile const ma_uint64*)ptr, order);
+ return r.f;
+}
+static MA_INLINE float ma_atomic_exchange_explicit_f32(volatile float* dst, float src, ma_atomic_memory_order order)
+{
+ ma_atomic_if32 r;
+ ma_atomic_if32 x;
x.f = src;
- c89atomic_store_explicit_64((volatile c89atomic_uint64*)dst, x.i, order);
+ r.i = ma_atomic_exchange_explicit_32((volatile ma_uint32*)dst, x.i, order);
+ return r.f;
}
-static C89ATOMIC_INLINE float c89atomic_load_explicit_f32(volatile const float* ptr, c89atomic_memory_order order)
+static MA_INLINE double ma_atomic_exchange_explicit_f64(volatile double* dst, double src, ma_atomic_memory_order order)
{
- c89atomic_if32 r;
- r.i = c89atomic_load_explicit_32((volatile const c89atomic_uint32*)ptr, order);
+ ma_atomic_if64 r;
+ ma_atomic_if64 x;
+ x.f = src;
+ r.i = ma_atomic_exchange_explicit_64((volatile ma_uint64*)dst, x.i, order);
return r.f;
}
-static C89ATOMIC_INLINE double c89atomic_load_explicit_f64(volatile const double* ptr, c89atomic_memory_order order)
+static MA_INLINE ma_bool32 ma_atomic_compare_exchange_strong_explicit_f32(volatile float* dst, float* expected, float desired, ma_atomic_memory_order successOrder, ma_atomic_memory_order failureOrder)
+{
+ ma_atomic_if32 d;
+ d.f = desired;
+ return ma_atomic_compare_exchange_strong_explicit_32((volatile ma_uint32*)dst, (ma_uint32*)expected, d.i, successOrder, failureOrder);
+}
+static MA_INLINE ma_bool32 ma_atomic_compare_exchange_strong_explicit_f64(volatile double* dst, double* expected, double desired, ma_atomic_memory_order successOrder, ma_atomic_memory_order failureOrder)
{
- c89atomic_if64 r;
- r.i = c89atomic_load_explicit_64((volatile const c89atomic_uint64*)ptr, order);
+ ma_atomic_if64 d;
+ d.f = desired;
+ return ma_atomic_compare_exchange_strong_explicit_64((volatile ma_uint64*)dst, (ma_uint64*)expected, d.i, successOrder, failureOrder);
+}
+static MA_INLINE ma_bool32 ma_atomic_compare_exchange_weak_explicit_f32(volatile float* dst, float* expected, float desired, ma_atomic_memory_order successOrder, ma_atomic_memory_order failureOrder)
+{
+ ma_atomic_if32 d;
+ d.f = desired;
+ return ma_atomic_compare_exchange_weak_explicit_32((volatile ma_uint32*)dst, (ma_uint32*)expected, d.i, successOrder, failureOrder);
+}
+static MA_INLINE ma_bool32 ma_atomic_compare_exchange_weak_explicit_f64(volatile double* dst, double* expected, double desired, ma_atomic_memory_order successOrder, ma_atomic_memory_order failureOrder)
+{
+ ma_atomic_if64 d;
+ d.f = desired;
+ return ma_atomic_compare_exchange_weak_explicit_64((volatile ma_uint64*)dst, (ma_uint64*)expected, d.i, successOrder, failureOrder);
+}
+static MA_INLINE float ma_atomic_fetch_add_explicit_f32(volatile float* dst, float src, ma_atomic_memory_order order)
+{
+ ma_atomic_if32 r;
+ ma_atomic_if32 x;
+ x.f = src;
+ r.i = ma_atomic_fetch_add_explicit_32((volatile ma_uint32*)dst, x.i, order);
return r.f;
}
-static C89ATOMIC_INLINE float c89atomic_exchange_explicit_f32(volatile float* dst, float src, c89atomic_memory_order order)
+static MA_INLINE double ma_atomic_fetch_add_explicit_f64(volatile double* dst, double src, ma_atomic_memory_order order)
{
- c89atomic_if32 r;
- c89atomic_if32 x;
+ ma_atomic_if64 r;
+ ma_atomic_if64 x;
x.f = src;
- r.i = c89atomic_exchange_explicit_32((volatile c89atomic_uint32*)dst, x.i, order);
+ r.i = ma_atomic_fetch_add_explicit_64((volatile ma_uint64*)dst, x.i, order);
return r.f;
}
-static C89ATOMIC_INLINE double c89atomic_exchange_explicit_f64(volatile double* dst, double src, c89atomic_memory_order order)
+static MA_INLINE float ma_atomic_fetch_sub_explicit_f32(volatile float* dst, float src, ma_atomic_memory_order order)
{
- c89atomic_if64 r;
- c89atomic_if64 x;
+ ma_atomic_if32 r;
+ ma_atomic_if32 x;
x.f = src;
- r.i = c89atomic_exchange_explicit_64((volatile c89atomic_uint64*)dst, x.i, order);
+ r.i = ma_atomic_fetch_sub_explicit_32((volatile ma_uint32*)dst, x.i, order);
return r.f;
}
-#define c89atomic_clear_f32(ptr) (float )c89atomic_clear_explicit_f32(ptr, c89atomic_memory_order_seq_cst)
-#define c89atomic_clear_f64(ptr) (double)c89atomic_clear_explicit_f64(ptr, c89atomic_memory_order_seq_cst)
-#define c89atomic_store_f32(dst, src) c89atomic_store_explicit_f32(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_store_f64(dst, src) c89atomic_store_explicit_f64(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_load_f32(ptr) (float )c89atomic_load_explicit_f32(ptr, c89atomic_memory_order_seq_cst)
-#define c89atomic_load_f64(ptr) (double)c89atomic_load_explicit_f64(ptr, c89atomic_memory_order_seq_cst)
-#define c89atomic_exchange_f32(dst, src) (float )c89atomic_exchange_explicit_f32(dst, src, c89atomic_memory_order_seq_cst)
-#define c89atomic_exchange_f64(dst, src) (double)c89atomic_exchange_explicit_f64(dst, src, c89atomic_memory_order_seq_cst)
-typedef c89atomic_flag c89atomic_spinlock;
-static C89ATOMIC_INLINE void c89atomic_spinlock_lock(volatile c89atomic_spinlock* pSpinlock)
+static MA_INLINE double ma_atomic_fetch_sub_explicit_f64(volatile double* dst, double src, ma_atomic_memory_order order)
+{
+ ma_atomic_if64 r;
+ ma_atomic_if64 x;
+ x.f = src;
+ r.i = ma_atomic_fetch_sub_explicit_64((volatile ma_uint64*)dst, x.i, order);
+ return r.f;
+}
+static MA_INLINE float ma_atomic_fetch_or_explicit_f32(volatile float* dst, float src, ma_atomic_memory_order order)
+{
+ ma_atomic_if32 r;
+ ma_atomic_if32 x;
+ x.f = src;
+ r.i = ma_atomic_fetch_or_explicit_32((volatile ma_uint32*)dst, x.i, order);
+ return r.f;
+}
+static MA_INLINE double ma_atomic_fetch_or_explicit_f64(volatile double* dst, double src, ma_atomic_memory_order order)
+{
+ ma_atomic_if64 r;
+ ma_atomic_if64 x;
+ x.f = src;
+ r.i = ma_atomic_fetch_or_explicit_64((volatile ma_uint64*)dst, x.i, order);
+ return r.f;
+}
+static MA_INLINE float ma_atomic_fetch_xor_explicit_f32(volatile float* dst, float src, ma_atomic_memory_order order)
+{
+ ma_atomic_if32 r;
+ ma_atomic_if32 x;
+ x.f = src;
+ r.i = ma_atomic_fetch_xor_explicit_32((volatile ma_uint32*)dst, x.i, order);
+ return r.f;
+}
+static MA_INLINE double ma_atomic_fetch_xor_explicit_f64(volatile double* dst, double src, ma_atomic_memory_order order)
+{
+ ma_atomic_if64 r;
+ ma_atomic_if64 x;
+ x.f = src;
+ r.i = ma_atomic_fetch_xor_explicit_64((volatile ma_uint64*)dst, x.i, order);
+ return r.f;
+}
+static MA_INLINE float ma_atomic_fetch_and_explicit_f32(volatile float* dst, float src, ma_atomic_memory_order order)
+{
+ ma_atomic_if32 r;
+ ma_atomic_if32 x;
+ x.f = src;
+ r.i = ma_atomic_fetch_and_explicit_32((volatile ma_uint32*)dst, x.i, order);
+ return r.f;
+}
+static MA_INLINE double ma_atomic_fetch_and_explicit_f64(volatile double* dst, double src, ma_atomic_memory_order order)
+{
+ ma_atomic_if64 r;
+ ma_atomic_if64 x;
+ x.f = src;
+ r.i = ma_atomic_fetch_and_explicit_64((volatile ma_uint64*)dst, x.i, order);
+ return r.f;
+}
+#define ma_atomic_clear_f32(ptr) (float )ma_atomic_clear_explicit_f32(ptr, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_clear_f64(ptr) (double)ma_atomic_clear_explicit_f64(ptr, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_store_f32(dst, src) ma_atomic_store_explicit_f32(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_store_f64(dst, src) ma_atomic_store_explicit_f64(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_load_f32(ptr) (float )ma_atomic_load_explicit_f32(ptr, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_load_f64(ptr) (double)ma_atomic_load_explicit_f64(ptr, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_exchange_f32(dst, src) (float )ma_atomic_exchange_explicit_f32(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_exchange_f64(dst, src) (double)ma_atomic_exchange_explicit_f64(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_compare_exchange_strong_f32(dst, expected, desired) ma_atomic_compare_exchange_strong_explicit_f32(dst, expected, desired, ma_atomic_memory_order_seq_cst, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_compare_exchange_strong_f64(dst, expected, desired) ma_atomic_compare_exchange_strong_explicit_f64(dst, expected, desired, ma_atomic_memory_order_seq_cst, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_compare_exchange_weak_f32(dst, expected, desired) ma_atomic_compare_exchange_weak_explicit_f32(dst, expected, desired, ma_atomic_memory_order_seq_cst, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_compare_exchange_weak_f64(dst, expected, desired) ma_atomic_compare_exchange_weak_explicit_f64(dst, expected, desired, ma_atomic_memory_order_seq_cst, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_add_f32(dst, src) ma_atomic_fetch_add_explicit_f32(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_add_f64(dst, src) ma_atomic_fetch_add_explicit_f64(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_sub_f32(dst, src) ma_atomic_fetch_sub_explicit_f32(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_sub_f64(dst, src) ma_atomic_fetch_sub_explicit_f64(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_or_f32(dst, src) ma_atomic_fetch_or_explicit_f32(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_or_f64(dst, src) ma_atomic_fetch_or_explicit_f64(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_xor_f32(dst, src) ma_atomic_fetch_xor_explicit_f32(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_xor_f64(dst, src) ma_atomic_fetch_xor_explicit_f64(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_and_f32(dst, src) ma_atomic_fetch_and_explicit_f32(dst, src, ma_atomic_memory_order_seq_cst)
+#define ma_atomic_fetch_and_f64(dst, src) ma_atomic_fetch_and_explicit_f64(dst, src, ma_atomic_memory_order_seq_cst)
+static MA_INLINE float ma_atomic_compare_and_swap_f32(volatile float* dst, float expected, float desired)
+{
+ ma_atomic_if32 r;
+ ma_atomic_if32 e, d;
+ e.f = expected;
+ d.f = desired;
+ r.i = ma_atomic_compare_and_swap_32((volatile ma_uint32*)dst, e.i, d.i);
+ return r.f;
+}
+static MA_INLINE double ma_atomic_compare_and_swap_f64(volatile double* dst, double expected, double desired)
+{
+ ma_atomic_if64 r;
+ ma_atomic_if64 e, d;
+ e.f = expected;
+ d.f = desired;
+ r.i = ma_atomic_compare_and_swap_64((volatile ma_uint64*)dst, e.i, d.i);
+ return r.f;
+}
+typedef ma_atomic_flag ma_atomic_spinlock;
+static MA_INLINE void ma_atomic_spinlock_lock(volatile ma_atomic_spinlock* pSpinlock)
{
for (;;) {
- if (c89atomic_flag_test_and_set_explicit(pSpinlock, c89atomic_memory_order_acquire) == 0) {
+ if (ma_atomic_flag_test_and_set_explicit(pSpinlock, ma_atomic_memory_order_acquire) == 0) {
break;
}
- while (c89atoimc_flag_load_explicit(pSpinlock, c89atomic_memory_order_relaxed) == 1) {
+ while (c89atoimc_flag_load_explicit(pSpinlock, ma_atomic_memory_order_relaxed) == 1) {
}
}
}
-static C89ATOMIC_INLINE void c89atomic_spinlock_unlock(volatile c89atomic_spinlock* pSpinlock)
+static MA_INLINE void ma_atomic_spinlock_unlock(volatile ma_atomic_spinlock* pSpinlock)
{
- c89atomic_flag_clear_explicit(pSpinlock, c89atomic_memory_order_release);
+ ma_atomic_flag_clear_explicit(pSpinlock, ma_atomic_memory_order_release);
}
+#if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)))
+ #pragma GCC diagnostic pop
+#endif
#if defined(__cplusplus)
}
#endif
#endif
-/* c89atomic.h end */
+/* ma_atomic.h end */
+
+#define MA_ATOMIC_SAFE_TYPE_IMPL(c89TypeExtension, type) \
+ static MA_INLINE ma_##type ma_atomic_##type##_get(ma_atomic_##type* x) \
+ { \
+ return (ma_##type)ma_atomic_load_##c89TypeExtension(&x->value); \
+ } \
+ static MA_INLINE void ma_atomic_##type##_set(ma_atomic_##type* x, ma_##type value) \
+ { \
+ ma_atomic_store_##c89TypeExtension(&x->value, value); \
+ } \
+ static MA_INLINE ma_##type ma_atomic_##type##_exchange(ma_atomic_##type* x, ma_##type value) \
+ { \
+ return (ma_##type)ma_atomic_exchange_##c89TypeExtension(&x->value, value); \
+ } \
+ static MA_INLINE ma_bool32 ma_atomic_##type##_compare_exchange(ma_atomic_##type* x, ma_##type* expected, ma_##type desired) \
+ { \
+ return ma_atomic_compare_exchange_weak_##c89TypeExtension(&x->value, expected, desired); \
+ } \
+ static MA_INLINE ma_##type ma_atomic_##type##_fetch_add(ma_atomic_##type* x, ma_##type y) \
+ { \
+ return (ma_##type)ma_atomic_fetch_add_##c89TypeExtension(&x->value, y); \
+ } \
+ static MA_INLINE ma_##type ma_atomic_##type##_fetch_sub(ma_atomic_##type* x, ma_##type y) \
+ { \
+ return (ma_##type)ma_atomic_fetch_sub_##c89TypeExtension(&x->value, y); \
+ } \
+ static MA_INLINE ma_##type ma_atomic_##type##_fetch_or(ma_atomic_##type* x, ma_##type y) \
+ { \
+ return (ma_##type)ma_atomic_fetch_or_##c89TypeExtension(&x->value, y); \
+ } \
+ static MA_INLINE ma_##type ma_atomic_##type##_fetch_xor(ma_atomic_##type* x, ma_##type y) \
+ { \
+ return (ma_##type)ma_atomic_fetch_xor_##c89TypeExtension(&x->value, y); \
+ } \
+ static MA_INLINE ma_##type ma_atomic_##type##_fetch_and(ma_atomic_##type* x, ma_##type y) \
+ { \
+ return (ma_##type)ma_atomic_fetch_and_##c89TypeExtension(&x->value, y); \
+ } \
+ static MA_INLINE ma_##type ma_atomic_##type##_compare_and_swap(ma_atomic_##type* x, ma_##type expected, ma_##type desired) \
+ { \
+ return (ma_##type)ma_atomic_compare_and_swap_##c89TypeExtension(&x->value, expected, desired); \
+ } \
+
+#define MA_ATOMIC_SAFE_TYPE_IMPL_PTR(type) \
+ static MA_INLINE ma_##type* ma_atomic_ptr_##type##_get(ma_atomic_ptr_##type* x) \
+ { \
+ return ma_atomic_load_ptr((void**)&x->value); \
+ } \
+ static MA_INLINE void ma_atomic_ptr_##type##_set(ma_atomic_ptr_##type* x, ma_##type* value) \
+ { \
+ ma_atomic_store_ptr((void**)&x->value, (void*)value); \
+ } \
+ static MA_INLINE ma_##type* ma_atomic_ptr_##type##_exchange(ma_atomic_ptr_##type* x, ma_##type* value) \
+ { \
+ return ma_atomic_exchange_ptr((void**)&x->value, (void*)value); \
+ } \
+ static MA_INLINE ma_bool32 ma_atomic_ptr_##type##_compare_exchange(ma_atomic_ptr_##type* x, ma_##type** expected, ma_##type* desired) \
+ { \
+ return ma_atomic_compare_exchange_weak_ptr((void**)&x->value, (void*)expected, (void*)desired); \
+ } \
+ static MA_INLINE ma_##type* ma_atomic_ptr_##type##_compare_and_swap(ma_atomic_ptr_##type* x, ma_##type* expected, ma_##type* desired) \
+ { \
+ return (ma_##type*)ma_atomic_compare_and_swap_ptr((void**)&x->value, (void*)expected, (void*)desired); \
+ } \
+
+MA_ATOMIC_SAFE_TYPE_IMPL(32, uint32)
+MA_ATOMIC_SAFE_TYPE_IMPL(i32, int32)
+MA_ATOMIC_SAFE_TYPE_IMPL(64, uint64)
+MA_ATOMIC_SAFE_TYPE_IMPL(f32, float)
+MA_ATOMIC_SAFE_TYPE_IMPL(32, bool32)
+#if !defined(MA_NO_DEVICE_IO)
+MA_ATOMIC_SAFE_TYPE_IMPL(i32, device_state)
+#endif
MA_API ma_uint64 ma_calculate_frame_count_after_resampling(ma_uint32 sampleRateOut, ma_uint32 sampleRateIn, ma_uint64 frameCountIn)
@@ -15374,11 +16044,11 @@ static MA_INLINE ma_result ma_spinlock_lock_ex(volatile ma_spinlock* pSpinlock,
}
for (;;) {
- if (c89atomic_exchange_explicit_32(pSpinlock, 1, c89atomic_memory_order_acquire) == 0) {
+ if (ma_atomic_exchange_explicit_32(pSpinlock, 1, ma_atomic_memory_order_acquire) == 0) {
break;
}
- while (c89atomic_load_explicit_32(pSpinlock, c89atomic_memory_order_relaxed) == 1) {
+ while (ma_atomic_load_explicit_32(pSpinlock, ma_atomic_memory_order_relaxed) == 1) {
if (yield) {
ma_yield();
}
@@ -15404,161 +16074,21 @@ MA_API ma_result ma_spinlock_unlock(volatile ma_spinlock* pSpinlock)
return MA_INVALID_ARGS;
}
- c89atomic_store_explicit_32(pSpinlock, 0, c89atomic_memory_order_release);
+ ma_atomic_store_explicit_32(pSpinlock, 0, ma_atomic_memory_order_release);
return MA_SUCCESS;
}
#ifndef MA_NO_THREADING
-#ifdef MA_WIN32
- #define MA_THREADCALL WINAPI
- typedef unsigned long ma_thread_result;
-#else
+#if defined(MA_POSIX)
#define MA_THREADCALL
typedef void* ma_thread_result;
-#endif
-typedef ma_thread_result (MA_THREADCALL * ma_thread_entry_proc)(void* pData);
-
-#ifdef MA_WIN32
-static int ma_thread_priority_to_win32(ma_thread_priority priority)
-{
- switch (priority) {
- case ma_thread_priority_idle: return THREAD_PRIORITY_IDLE;
- case ma_thread_priority_lowest: return THREAD_PRIORITY_LOWEST;
- case ma_thread_priority_low: return THREAD_PRIORITY_BELOW_NORMAL;
- case ma_thread_priority_normal: return THREAD_PRIORITY_NORMAL;
- case ma_thread_priority_high: return THREAD_PRIORITY_ABOVE_NORMAL;
- case ma_thread_priority_highest: return THREAD_PRIORITY_HIGHEST;
- case ma_thread_priority_realtime: return THREAD_PRIORITY_TIME_CRITICAL;
- default: return THREAD_PRIORITY_NORMAL;
- }
-}
-
-static ma_result ma_thread_create__win32(ma_thread* pThread, ma_thread_priority priority, size_t stackSize, ma_thread_entry_proc entryProc, void* pData)
-{
- *pThread = CreateThread(NULL, stackSize, entryProc, pData, 0, NULL);
- if (*pThread == NULL) {
- return ma_result_from_GetLastError(GetLastError());
- }
-
- SetThreadPriority((HANDLE)*pThread, ma_thread_priority_to_win32(priority));
-
- return MA_SUCCESS;
-}
-
-static void ma_thread_wait__win32(ma_thread* pThread)
-{
- WaitForSingleObject((HANDLE)*pThread, INFINITE);
- CloseHandle((HANDLE)*pThread);
-}
-
-
-static ma_result ma_mutex_init__win32(ma_mutex* pMutex)
-{
- *pMutex = CreateEventW(NULL, FALSE, TRUE, NULL);
- if (*pMutex == NULL) {
- return ma_result_from_GetLastError(GetLastError());
- }
-
- return MA_SUCCESS;
-}
-
-static void ma_mutex_uninit__win32(ma_mutex* pMutex)
-{
- CloseHandle((HANDLE)*pMutex);
-}
-
-static void ma_mutex_lock__win32(ma_mutex* pMutex)
-{
- WaitForSingleObject((HANDLE)*pMutex, INFINITE);
-}
-
-static void ma_mutex_unlock__win32(ma_mutex* pMutex)
-{
- SetEvent((HANDLE)*pMutex);
-}
-
-
-static ma_result ma_event_init__win32(ma_event* pEvent)
-{
- *pEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
- if (*pEvent == NULL) {
- return ma_result_from_GetLastError(GetLastError());
- }
-
- return MA_SUCCESS;
-}
-
-static void ma_event_uninit__win32(ma_event* pEvent)
-{
- CloseHandle((HANDLE)*pEvent);
-}
-
-static ma_result ma_event_wait__win32(ma_event* pEvent)
-{
- DWORD result = WaitForSingleObject((HANDLE)*pEvent, INFINITE);
- if (result == WAIT_OBJECT_0) {
- return MA_SUCCESS;
- }
-
- if (result == WAIT_TIMEOUT) {
- return MA_TIMEOUT;
- }
-
- return ma_result_from_GetLastError(GetLastError());
-}
-
-static ma_result ma_event_signal__win32(ma_event* pEvent)
-{
- BOOL result = SetEvent((HANDLE)*pEvent);
- if (result == 0) {
- return ma_result_from_GetLastError(GetLastError());
- }
-
- return MA_SUCCESS;
-}
-
-
-static ma_result ma_semaphore_init__win32(int initialValue, ma_semaphore* pSemaphore)
-{
- *pSemaphore = CreateSemaphoreW(NULL, (LONG)initialValue, LONG_MAX, NULL);
- if (*pSemaphore == NULL) {
- return ma_result_from_GetLastError(GetLastError());
- }
-
- return MA_SUCCESS;
-}
-
-static void ma_semaphore_uninit__win32(ma_semaphore* pSemaphore)
-{
- CloseHandle((HANDLE)*pSemaphore);
-}
-
-static ma_result ma_semaphore_wait__win32(ma_semaphore* pSemaphore)
-{
- DWORD result = WaitForSingleObject((HANDLE)*pSemaphore, INFINITE);
- if (result == WAIT_OBJECT_0) {
- return MA_SUCCESS;
- }
-
- if (result == WAIT_TIMEOUT) {
- return MA_TIMEOUT;
- }
-
- return ma_result_from_GetLastError(GetLastError());
-}
-
-static ma_result ma_semaphore_release__win32(ma_semaphore* pSemaphore)
-{
- BOOL result = ReleaseSemaphore((HANDLE)*pSemaphore, 1, NULL);
- if (result == 0) {
- return ma_result_from_GetLastError(GetLastError());
- }
-
- return MA_SUCCESS;
-}
+#elif defined(MA_WIN32)
+ #define MA_THREADCALL WINAPI
+ typedef unsigned long ma_thread_result;
#endif
+typedef ma_thread_result (MA_THREADCALL * ma_thread_entry_proc)(void* pData);
#ifdef MA_POSIX
static ma_result ma_thread_create__posix(ma_thread* pThread, ma_thread_priority priority, size_t stackSize, ma_thread_entry_proc entryProc, void* pData)
@@ -15571,23 +16101,32 @@ static ma_result ma_thread_create__posix(ma_thread* pThread, ma_thread_priority
pthread_attr_t attr;
if (pthread_attr_init(&attr) == 0) {
int scheduler = -1;
- if (priority == ma_thread_priority_idle) {
-#ifdef SCHED_IDLE
- if (pthread_attr_setschedpolicy(&attr, SCHED_IDLE) == 0) {
- scheduler = SCHED_IDLE;
- }
-#endif
- } else if (priority == ma_thread_priority_realtime) {
-#ifdef SCHED_FIFO
- if (pthread_attr_setschedpolicy(&attr, SCHED_FIFO) == 0) {
- scheduler = SCHED_FIFO;
+
+ /* We successfully initialized our attributes object so we can assign the pointer so it's passed into pthread_create(). */
+ pAttr = &attr;
+
+ /* We need to set the scheduler policy. Only do this if the OS supports pthread_attr_setschedpolicy() */
+ #if !defined(MA_BEOS)
+ {
+ if (priority == ma_thread_priority_idle) {
+ #ifdef SCHED_IDLE
+ if (pthread_attr_setschedpolicy(&attr, SCHED_IDLE) == 0) {
+ scheduler = SCHED_IDLE;
+ }
+ #endif
+ } else if (priority == ma_thread_priority_realtime) {
+ #ifdef SCHED_FIFO
+ if (pthread_attr_setschedpolicy(&attr, SCHED_FIFO) == 0) {
+ scheduler = SCHED_FIFO;
+ }
+ #endif
+ #ifdef MA_LINUX
+ } else {
+ scheduler = sched_getscheduler(0);
+ #endif
}
-#endif
-#ifdef MA_LINUX
- } else {
- scheduler = sched_getscheduler(0);
-#endif
}
+ #endif
if (stackSize > 0) {
pthread_attr_setstacksize(&attr, stackSize);
@@ -15614,9 +16153,8 @@ static ma_result ma_thread_create__posix(ma_thread* pThread, ma_thread_priority
}
}
- if (pthread_attr_setschedparam(&attr, &sched) == 0) {
- pAttr = &attr;
- }
+ /* I'm not treating a failure of setting the priority as a critical error so not checking the return value here. */
+ pthread_attr_setschedparam(&attr, &sched);
}
}
}
@@ -15648,7 +16186,15 @@ static void ma_thread_wait__posix(ma_thread* pThread)
static ma_result ma_mutex_init__posix(ma_mutex* pMutex)
{
- int result = pthread_mutex_init((pthread_mutex_t*)pMutex, NULL);
+ int result;
+
+ if (pMutex == NULL) {
+ return MA_INVALID_ARGS;
+ }
+
+ MA_ZERO_OBJECT(pMutex);
+
+ result = pthread_mutex_init((pthread_mutex_t*)pMutex, NULL);
if (result != 0) {
return ma_result_from_errno(result);
}
@@ -15793,6 +16339,146 @@ static ma_result ma_semaphore_release__posix(ma_semaphore* pSemaphore)
return MA_SUCCESS;
}
+#elif defined(MA_WIN32)
+static int ma_thread_priority_to_win32(ma_thread_priority priority)
+{
+ switch (priority) {
+ case ma_thread_priority_idle: return THREAD_PRIORITY_IDLE;
+ case ma_thread_priority_lowest: return THREAD_PRIORITY_LOWEST;
+ case ma_thread_priority_low: return THREAD_PRIORITY_BELOW_NORMAL;
+ case ma_thread_priority_normal: return THREAD_PRIORITY_NORMAL;
+ case ma_thread_priority_high: return THREAD_PRIORITY_ABOVE_NORMAL;
+ case ma_thread_priority_highest: return THREAD_PRIORITY_HIGHEST;
+ case ma_thread_priority_realtime: return THREAD_PRIORITY_TIME_CRITICAL;
+ default: return THREAD_PRIORITY_NORMAL;
+ }
+}
+
+static ma_result ma_thread_create__win32(ma_thread* pThread, ma_thread_priority priority, size_t stackSize, ma_thread_entry_proc entryProc, void* pData)
+{
+ DWORD threadID; /* Not used. Only used for passing into CreateThread() so it doesn't fail on Windows 98. */
+
+ *pThread = CreateThread(NULL, stackSize, entryProc, pData, 0, &threadID);
+ if (*pThread == NULL) {
+ return ma_result_from_GetLastError(GetLastError());
+ }
+
+ SetThreadPriority((HANDLE)*pThread, ma_thread_priority_to_win32(priority));
+
+ return MA_SUCCESS;
+}
+
+static void ma_thread_wait__win32(ma_thread* pThread)
+{
+ WaitForSingleObject((HANDLE)*pThread, INFINITE);
+ CloseHandle((HANDLE)*pThread);
+}
+
+
+static ma_result ma_mutex_init__win32(ma_mutex* pMutex)
+{
+ *pMutex = CreateEventA(NULL, FALSE, TRUE, NULL);
+ if (*pMutex == NULL) {
+ return ma_result_from_GetLastError(GetLastError());
+ }
+
+ return MA_SUCCESS;
+}
+
+static void ma_mutex_uninit__win32(ma_mutex* pMutex)
+{
+ CloseHandle((HANDLE)*pMutex);
+}
+
+static void ma_mutex_lock__win32(ma_mutex* pMutex)
+{
+ WaitForSingleObject((HANDLE)*pMutex, INFINITE);
+}
+
+static void ma_mutex_unlock__win32(ma_mutex* pMutex)
+{
+ SetEvent((HANDLE)*pMutex);
+}
+
+
+static ma_result ma_event_init__win32(ma_event* pEvent)
+{
+ *pEvent = CreateEventA(NULL, FALSE, FALSE, NULL);
+ if (*pEvent == NULL) {
+ return ma_result_from_GetLastError(GetLastError());
+ }
+
+ return MA_SUCCESS;
+}
+
+static void ma_event_uninit__win32(ma_event* pEvent)
+{
+ CloseHandle((HANDLE)*pEvent);
+}
+
+static ma_result ma_event_wait__win32(ma_event* pEvent)
+{
+ DWORD result = WaitForSingleObject((HANDLE)*pEvent, INFINITE);
+ if (result == WAIT_OBJECT_0) {
+ return MA_SUCCESS;
+ }
+
+ if (result == WAIT_TIMEOUT) {
+ return MA_TIMEOUT;
+ }
+
+ return ma_result_from_GetLastError(GetLastError());
+}
+
+static ma_result ma_event_signal__win32(ma_event* pEvent)
+{
+ BOOL result = SetEvent((HANDLE)*pEvent);
+ if (result == 0) {
+ return ma_result_from_GetLastError(GetLastError());
+ }
+
+ return MA_SUCCESS;
+}
+
+
+static ma_result ma_semaphore_init__win32(int initialValue, ma_semaphore* pSemaphore)
+{
+ *pSemaphore = CreateSemaphoreW(NULL, (LONG)initialValue, LONG_MAX, NULL);
+ if (*pSemaphore == NULL) {
+ return ma_result_from_GetLastError(GetLastError());
+ }
+
+ return MA_SUCCESS;
+}
+
+static void ma_semaphore_uninit__win32(ma_semaphore* pSemaphore)
+{
+ CloseHandle((HANDLE)*pSemaphore);
+}
+
+static ma_result ma_semaphore_wait__win32(ma_semaphore* pSemaphore)
+{
+ DWORD result = WaitForSingleObject((HANDLE)*pSemaphore, INFINITE);
+ if (result == WAIT_OBJECT_0) {
+ return MA_SUCCESS;
+ }
+
+ if (result == WAIT_TIMEOUT) {
+ return MA_TIMEOUT;
+ }
+
+ return ma_result_from_GetLastError(GetLastError());
+}
+
+static ma_result ma_semaphore_release__win32(ma_semaphore* pSemaphore)
+{
+ BOOL result = ReleaseSemaphore((HANDLE)*pSemaphore, 1, NULL);
+ if (result == 0) {
+ return ma_result_from_GetLastError(GetLastError());
+ }
+
+ return MA_SUCCESS;
+}
#endif
typedef struct
@@ -15842,15 +16528,20 @@ static ma_result ma_thread_create(ma_thread* pThread, ma_thread_priority priorit
return MA_OUT_OF_MEMORY;
}
+#if defined(MA_THREAD_DEFAULT_STACK_SIZE)
+ if (stackSize == 0) {
+ stackSize = MA_THREAD_DEFAULT_STACK_SIZE;
+ }
+#endif
+
pProxyData->entryProc = entryProc;
pProxyData->pData = pData;
ma_allocation_callbacks_init_copy(&pProxyData->allocationCallbacks, pAllocationCallbacks);
-#ifdef MA_WIN32
- result = ma_thread_create__win32(pThread, priority, stackSize, ma_thread_entry_proxy, pProxyData);
-#endif
-#ifdef MA_POSIX
+#if defined(MA_POSIX)
result = ma_thread_create__posix(pThread, priority, stackSize, ma_thread_entry_proxy, pProxyData);
+#elif defined(MA_WIN32)
+ result = ma_thread_create__win32(pThread, priority, stackSize, ma_thread_entry_proxy, pProxyData);
#endif
if (result != MA_SUCCESS) {
@@ -15867,11 +16558,10 @@ static void ma_thread_wait(ma_thread* pThread)
return;
}
-#ifdef MA_WIN32
- ma_thread_wait__win32(pThread);
-#endif
-#ifdef MA_POSIX
+#if defined(MA_POSIX)
ma_thread_wait__posix(pThread);
+#elif defined(MA_WIN32)
+ ma_thread_wait__win32(pThread);
#endif
}
@@ -15883,11 +16573,10 @@ MA_API ma_result ma_mutex_init(ma_mutex* pMutex)
return MA_INVALID_ARGS;
}
-#ifdef MA_WIN32
- return ma_mutex_init__win32(pMutex);
-#endif
-#ifdef MA_POSIX
+#if defined(MA_POSIX)
return ma_mutex_init__posix(pMutex);
+#elif defined(MA_WIN32)
+ return ma_mutex_init__win32(pMutex);
#endif
}
@@ -15897,11 +16586,10 @@ MA_API void ma_mutex_uninit(ma_mutex* pMutex)
return;
}
-#ifdef MA_WIN32
- ma_mutex_uninit__win32(pMutex);
-#endif
-#ifdef MA_POSIX
+#if defined(MA_POSIX)
ma_mutex_uninit__posix(pMutex);
+#elif defined(MA_WIN32)
+ ma_mutex_uninit__win32(pMutex);
#endif
}
@@ -15912,11 +16600,10 @@ MA_API void ma_mutex_lock(ma_mutex* pMutex)
return;
}
-#ifdef MA_WIN32
- ma_mutex_lock__win32(pMutex);
-#endif
-#ifdef MA_POSIX
+#if defined(MA_POSIX)
ma_mutex_lock__posix(pMutex);
+#elif defined(MA_WIN32)
+ ma_mutex_lock__win32(pMutex);
#endif
}
@@ -15925,13 +16612,12 @@ MA_API void ma_mutex_unlock(ma_mutex* pMutex)
if (pMutex == NULL) {
MA_ASSERT(MA_FALSE); /* Fire an assert so the caller is aware of this bug. */
return;
-}
+ }
-#ifdef MA_WIN32
- ma_mutex_unlock__win32(pMutex);
-#endif
-#ifdef MA_POSIX
+#if defined(MA_POSIX)
ma_mutex_unlock__posix(pMutex);
+#elif defined(MA_WIN32)
+ ma_mutex_unlock__win32(pMutex);
#endif
}
@@ -15943,11 +16629,10 @@ MA_API ma_result ma_event_init(ma_event* pEvent)
return MA_INVALID_ARGS;
}
-#ifdef MA_WIN32
- return ma_event_init__win32(pEvent);
-#endif
-#ifdef MA_POSIX
+#if defined(MA_POSIX)
return ma_event_init__posix(pEvent);
+#elif defined(MA_WIN32)
+ return ma_event_init__win32(pEvent);
#endif
}
@@ -15985,11 +16670,10 @@ MA_API void ma_event_uninit(ma_event* pEvent)
return;
}
-#ifdef MA_WIN32
- ma_event_uninit__win32(pEvent);
-#endif
-#ifdef MA_POSIX
+#if defined(MA_POSIX)
ma_event_uninit__posix(pEvent);
+#elif defined(MA_WIN32)
+ ma_event_uninit__win32(pEvent);
#endif
}
@@ -16012,11 +16696,10 @@ MA_API ma_result ma_event_wait(ma_event* pEvent)
return MA_INVALID_ARGS;
}
-#ifdef MA_WIN32
- return ma_event_wait__win32(pEvent);
-#endif
-#ifdef MA_POSIX
+#if defined(MA_POSIX)
return ma_event_wait__posix(pEvent);
+#elif defined(MA_WIN32)
+ return ma_event_wait__win32(pEvent);
#endif
}
@@ -16027,11 +16710,10 @@ MA_API ma_result ma_event_signal(ma_event* pEvent)
return MA_INVALID_ARGS;
}
-#ifdef MA_WIN32
- return ma_event_signal__win32(pEvent);
-#endif
-#ifdef MA_POSIX
+#if defined(MA_POSIX)
return ma_event_signal__posix(pEvent);
+#elif defined(MA_WIN32)
+ return ma_event_signal__win32(pEvent);
#endif
}
@@ -16043,11 +16725,10 @@ MA_API ma_result ma_semaphore_init(int initialValue, ma_semaphore* pSemaphore)
return MA_INVALID_ARGS;
}
-#ifdef MA_WIN32
- return ma_semaphore_init__win32(initialValue, pSemaphore);
-#endif
-#ifdef MA_POSIX
+#if defined(MA_POSIX)
return ma_semaphore_init__posix(initialValue, pSemaphore);
+#elif defined(MA_WIN32)
+ return ma_semaphore_init__win32(initialValue, pSemaphore);
#endif
}
@@ -16058,11 +16739,10 @@ MA_API void ma_semaphore_uninit(ma_semaphore* pSemaphore)
return;
}
-#ifdef MA_WIN32
- ma_semaphore_uninit__win32(pSemaphore);
-#endif
-#ifdef MA_POSIX
+#if defined(MA_POSIX)
ma_semaphore_uninit__posix(pSemaphore);
+#elif defined(MA_WIN32)
+ ma_semaphore_uninit__win32(pSemaphore);
#endif
}
@@ -16073,11 +16753,10 @@ MA_API ma_result ma_semaphore_wait(ma_semaphore* pSemaphore)
return MA_INVALID_ARGS;
}
-#ifdef MA_WIN32
- return ma_semaphore_wait__win32(pSemaphore);
-#endif
-#ifdef MA_POSIX
+#if defined(MA_POSIX)
return ma_semaphore_wait__posix(pSemaphore);
+#elif defined(MA_WIN32)
+ return ma_semaphore_wait__win32(pSemaphore);
#endif
}
@@ -16088,11 +16767,10 @@ MA_API ma_result ma_semaphore_release(ma_semaphore* pSemaphore)
return MA_INVALID_ARGS;
}
-#ifdef MA_WIN32
- return ma_semaphore_release__win32(pSemaphore);
-#endif
-#ifdef MA_POSIX
+#if defined(MA_POSIX)
return ma_semaphore_release__posix(pSemaphore);
+#elif defined(MA_WIN32)
+ return ma_semaphore_release__win32(pSemaphore);
#endif
}
#else
@@ -16151,7 +16829,7 @@ MA_API ma_result ma_fence_acquire(ma_fence* pFence)
}
for (;;) {
- ma_uint32 oldCounter = c89atomic_load_32(&pFence->counter);
+ ma_uint32 oldCounter = ma_atomic_load_32(&pFence->counter);
ma_uint32 newCounter = oldCounter + 1;
/* Make sure we're not about to exceed our maximum value. */
@@ -16160,7 +16838,7 @@ MA_API ma_result ma_fence_acquire(ma_fence* pFence)
return MA_OUT_OF_RANGE;
}
- if (c89atomic_compare_exchange_weak_32(&pFence->counter, &oldCounter, newCounter)) {
+ if (ma_atomic_compare_exchange_weak_32(&pFence->counter, &oldCounter, newCounter)) {
return MA_SUCCESS;
} else {
if (oldCounter == MA_FENCE_COUNTER_MAX) {
@@ -16181,7 +16859,7 @@ MA_API ma_result ma_fence_release(ma_fence* pFence)
}
for (;;) {
- ma_uint32 oldCounter = c89atomic_load_32(&pFence->counter);
+ ma_uint32 oldCounter = ma_atomic_load_32(&pFence->counter);
ma_uint32 newCounter = oldCounter - 1;
if (oldCounter == 0) {
@@ -16189,7 +16867,7 @@ MA_API ma_result ma_fence_release(ma_fence* pFence)
return MA_INVALID_OPERATION; /* Acquire/release mismatch. */
}
- if (c89atomic_compare_exchange_weak_32(&pFence->counter, &oldCounter, newCounter)) {
+ if (ma_atomic_compare_exchange_weak_32(&pFence->counter, &oldCounter, newCounter)) {
#ifndef MA_NO_THREADING
{
if (newCounter == 0) {
@@ -16220,7 +16898,7 @@ MA_API ma_result ma_fence_wait(ma_fence* pFence)
for (;;) {
ma_uint32 counter;
- counter = c89atomic_load_32(&pFence->counter);
+ counter = ma_atomic_load_32(&pFence->counter);
if (counter == 0) {
/*
Counter has hit zero. By the time we get here some other thread may have acquired the
@@ -16553,7 +17231,7 @@ MA_API ma_result ma_slot_allocator_alloc(ma_slot_allocator* pAllocator, ma_uint6
ma_uint32 newBitfield;
ma_uint32 bitOffset;
- oldBitfield = c89atomic_load_32(&pAllocator->pGroups[iGroup].bitfield); /* <-- This copy must happen. The compiler must not optimize this away. */
+ oldBitfield = ma_atomic_load_32(&pAllocator->pGroups[iGroup].bitfield); /* <-- This copy must happen. The compiler must not optimize this away. */
/* Fast check to see if anything is available. */
if (oldBitfield == 0xFFFFFFFF) {
@@ -16565,11 +17243,11 @@ MA_API ma_result ma_slot_allocator_alloc(ma_slot_allocator* pAllocator, ma_uint6
newBitfield = oldBitfield | (1 << bitOffset);
- if (c89atomic_compare_and_swap_32(&pAllocator->pGroups[iGroup].bitfield, oldBitfield, newBitfield) == oldBitfield) {
+ if (ma_atomic_compare_and_swap_32(&pAllocator->pGroups[iGroup].bitfield, oldBitfield, newBitfield) == oldBitfield) {
ma_uint32 slotIndex;
/* Increment the counter as soon as possible to have other threads report out-of-memory sooner than later. */
- c89atomic_fetch_add_32(&pAllocator->count, 1);
+ ma_atomic_fetch_add_32(&pAllocator->count, 1);
/* The slot index is required for constructing the output value. */
slotIndex = (iGroup << 5) + bitOffset; /* iGroup << 5 = iGroup * 32 */
@@ -16618,12 +17296,12 @@ MA_API ma_result ma_slot_allocator_free(ma_slot_allocator* pAllocator, ma_uint64
MA_ASSERT(iBit < 32); /* This must be true due to the logic we used to actually calculate it. */
- while (c89atomic_load_32(&pAllocator->count) > 0) {
+ while (ma_atomic_load_32(&pAllocator->count) > 0) {
/* CAS */
ma_uint32 oldBitfield;
ma_uint32 newBitfield;
- oldBitfield = c89atomic_load_32(&pAllocator->pGroups[iGroup].bitfield); /* <-- This copy must happen. The compiler must not optimize this away. */
+ oldBitfield = ma_atomic_load_32(&pAllocator->pGroups[iGroup].bitfield); /* <-- This copy must happen. The compiler must not optimize this away. */
newBitfield = oldBitfield & ~(1 << iBit);
/* Debugging for checking for double-frees. */
@@ -16635,8 +17313,8 @@ MA_API ma_result ma_slot_allocator_free(ma_slot_allocator* pAllocator, ma_uint64
}
#endif
- if (c89atomic_compare_and_swap_32(&pAllocator->pGroups[iGroup].bitfield, oldBitfield, newBitfield) == oldBitfield) {
- c89atomic_fetch_sub_32(&pAllocator->count, 1);
+ if (ma_atomic_compare_and_swap_32(&pAllocator->pGroups[iGroup].bitfield, oldBitfield, newBitfield) == oldBitfield) {
+ ma_atomic_fetch_sub_32(&pAllocator->count, 1);
return MA_SUCCESS;
}
}
@@ -16738,7 +17416,7 @@ MA_API ma_result ma_job_process(ma_job* pJob)
return MA_INVALID_ARGS;
}
- if (pJob->toc.breakup.code > MA_JOB_TYPE_COUNT) {
+ if (pJob->toc.breakup.code >= MA_JOB_TYPE_COUNT) {
return MA_INVALID_OPERATION;
}
@@ -16967,7 +17645,7 @@ MA_API void ma_job_queue_uninit(ma_job_queue* pQueue, const ma_allocation_callba
static ma_bool32 ma_job_queue_cas(volatile ma_uint64* dst, ma_uint64 expected, ma_uint64 desired)
{
/* The new counter is taken from the expected value. */
- return c89atomic_compare_and_swap_64(dst, expected, ma_job_set_refcount(desired, ma_job_extract_refcount(expected) + 1)) == expected;
+ return ma_atomic_compare_and_swap_64(dst, expected, ma_job_set_refcount(desired, ma_job_extract_refcount(expected) + 1)) == expected;
}
MA_API ma_result ma_job_queue_post(ma_job_queue* pQueue, const ma_job* pJob)
@@ -17005,10 +17683,10 @@ MA_API ma_result ma_job_queue_post(ma_job_queue* pQueue, const ma_job* pJob)
{
/* The job is stored in memory so now we need to add it to our linked list. We only ever add items to the end of the list. */
for (;;) {
- tail = c89atomic_load_64(&pQueue->tail);
- next = c89atomic_load_64(&pQueue->pJobs[ma_job_extract_slot(tail)].next);
+ tail = ma_atomic_load_64(&pQueue->tail);
+ next = ma_atomic_load_64(&pQueue->pJobs[ma_job_extract_slot(tail)].next);
- if (ma_job_toc_to_allocation(tail) == ma_job_toc_to_allocation(c89atomic_load_64(&pQueue->tail))) {
+ if (ma_job_toc_to_allocation(tail) == ma_job_toc_to_allocation(ma_atomic_load_64(&pQueue->tail))) {
if (ma_job_extract_slot(next) == 0xFFFF) {
if (ma_job_queue_cas(&pQueue->pJobs[ma_job_extract_slot(tail)].next, next, slot)) {
break;
@@ -17079,11 +17757,11 @@ MA_API ma_result ma_job_queue_next(ma_job_queue* pQueue, ma_job* pJob)
/* Now we need to remove the root item from the list. */
for (;;) {
- head = c89atomic_load_64(&pQueue->head);
- tail = c89atomic_load_64(&pQueue->tail);
- next = c89atomic_load_64(&pQueue->pJobs[ma_job_extract_slot(head)].next);
+ head = ma_atomic_load_64(&pQueue->head);
+ tail = ma_atomic_load_64(&pQueue->tail);
+ next = ma_atomic_load_64(&pQueue->pJobs[ma_job_extract_slot(head)].next);
- if (ma_job_toc_to_allocation(head) == ma_job_toc_to_allocation(c89atomic_load_64(&pQueue->head))) {
+ if (ma_job_toc_to_allocation(head) == ma_job_toc_to_allocation(ma_atomic_load_64(&pQueue->head))) {
if (ma_job_extract_slot(head) == ma_job_extract_slot(tail)) {
if (ma_job_extract_slot(next) == 0xFFFF) {
#ifndef MA_USE_EXPERIMENTAL_LOCK_FREE_JOB_QUEUE
@@ -17122,6 +17800,112 @@ MA_API ma_result ma_job_queue_next(ma_job_queue* pQueue, ma_job* pJob)
+/*******************************************************************************
+
+Dynamic Linking
+
+*******************************************************************************/
+#ifdef MA_POSIX
+ /* No need for dlfcn.h if we're not using runtime linking. */
+ #ifndef MA_NO_RUNTIME_LINKING
+ #include
+ #endif
+#endif
+
+MA_API ma_handle ma_dlopen(ma_log* pLog, const char* filename)
+{
+#ifndef MA_NO_RUNTIME_LINKING
+ ma_handle handle;
+
+ ma_log_postf(pLog, MA_LOG_LEVEL_DEBUG, "Loading library: %s\n", filename);
+
+ #ifdef MA_WIN32
+ /* From MSDN: Desktop applications cannot use LoadPackagedLibrary; if a desktop application calls this function it fails with APPMODEL_ERROR_NO_PACKAGE.*/
+ #if !defined(MA_WIN32_UWP) || !(defined(WINAPI_FAMILY) && ((defined(WINAPI_FAMILY_PHONE_APP) && WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)))
+ handle = (ma_handle)LoadLibraryA(filename);
+ #else
+ /* *sigh* It appears there is no ANSI version of LoadPackagedLibrary()... */
+ WCHAR filenameW[4096];
+ if (MultiByteToWideChar(CP_UTF8, 0, filename, -1, filenameW, sizeof(filenameW)) == 0) {
+ handle = NULL;
+ } else {
+ handle = (ma_handle)LoadPackagedLibrary(filenameW, 0);
+ }
+ #endif
+ #else
+ handle = (ma_handle)dlopen(filename, RTLD_NOW);
+ #endif
+
+ /*
+ I'm not considering failure to load a library an error nor a warning because seamlessly falling through to a lower-priority
+ backend is a deliberate design choice. Instead I'm logging it as an informational message.
+ */
+ if (handle == NULL) {
+ ma_log_postf(pLog, MA_LOG_LEVEL_INFO, "Failed to load library: %s\n", filename);
+ }
+
+ return handle;
+#else
+ /* Runtime linking is disabled. */
+ (void)pLog;
+ (void)filename;
+ return NULL;
+#endif
+}
+
+MA_API void ma_dlclose(ma_log* pLog, ma_handle handle)
+{
+#ifndef MA_NO_RUNTIME_LINKING
+ #ifdef MA_WIN32
+ FreeLibrary((HMODULE)handle);
+ #else
+ dlclose((void*)handle);
+ #endif
+
+ (void)pLog;
+#else
+ /* Runtime linking is disabled. */
+ (void)pLog;
+ (void)handle;
+#endif
+}
+
+MA_API ma_proc ma_dlsym(ma_log* pLog, ma_handle handle, const char* symbol)
+{
+#ifndef MA_NO_RUNTIME_LINKING
+ ma_proc proc;
+
+ ma_log_postf(pLog, MA_LOG_LEVEL_DEBUG, "Loading symbol: %s\n", symbol);
+
+#ifdef _WIN32
+ proc = (ma_proc)GetProcAddress((HMODULE)handle, symbol);
+#else
+#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wpedantic"
+#endif
+ proc = (ma_proc)dlsym((void*)handle, symbol);
+#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))
+ #pragma GCC diagnostic pop
+#endif
+#endif
+
+ if (proc == NULL) {
+ ma_log_postf(pLog, MA_LOG_LEVEL_WARNING, "Failed to load symbol: %s\n", symbol);
+ }
+
+ (void)pLog; /* It's possible for pContext to be unused. */
+ return proc;
+#else
+ /* Runtime linking is disabled. */
+ (void)pLog;
+ (void)handle;
+ (void)symbol;
+ return NULL;
+#endif
+}
+
+
/************************************************************************************************************************************************************
*************************************************************************************************************************************************************
@@ -17131,44 +17915,32 @@ DEVICE I/O
*************************************************************************************************************************************************************
************************************************************************************************************************************************************/
-#ifndef MA_NO_DEVICE_IO
-#ifdef MA_WIN32
- #include
- #include
- #include
+
+/* Disable run-time linking on certain backends and platforms. */
+#ifndef MA_NO_RUNTIME_LINKING
+ #if defined(MA_EMSCRIPTEN) || defined(MA_ORBIS) || defined(MA_PROSPERO)
+ #define MA_NO_RUNTIME_LINKING
+ #endif
#endif
+#ifndef MA_NO_DEVICE_IO
+
#if defined(MA_APPLE) && (__MAC_OS_X_VERSION_MIN_REQUIRED < 101200)
#include /* For mach_absolute_time() */
#endif
-#ifdef MA_ANDROID
- #include
-#endif
-
#ifdef MA_POSIX
#include
#include
- #include
-#endif
-
-/*
-Unfortunately using runtime linking for pthreads causes problems. This has occurred for me when testing on FreeBSD. When
-using runtime linking, deadlocks can occur (for me it happens when loading data from fread()). It turns out that doing
-compile-time linking fixes this. I'm not sure why this happens, but the safest way I can think of to fix this is to simply
-disable runtime linking by default. To enable runtime linking, #define this before the implementation of this file. I am
-not officially supporting this, but I'm leaving it here in case it's useful for somebody, somewhere.
-*/
-/*#define MA_USE_RUNTIME_LINKING_FOR_PTHREAD*/
-/* Disable run-time linking on certain backends. */
-#ifndef MA_NO_RUNTIME_LINKING
- #if defined(MA_EMSCRIPTEN)
- #define MA_NO_RUNTIME_LINKING
+ /* No need for dlfcn.h if we're not using runtime linking. */
+ #ifndef MA_NO_RUNTIME_LINKING
+ #include
#endif
#endif
+
MA_API void ma_device_info_add_native_data_format(ma_device_info* pDeviceInfo, ma_format format, ma_uint32 channels, ma_uint32 sampleRate, ma_uint32 flags)
{
if (pDeviceInfo == NULL) {
@@ -17185,27 +17957,60 @@ MA_API void ma_device_info_add_native_data_format(ma_device_info* pDeviceInfo, m
}
+typedef struct
+{
+ ma_backend backend;
+ const char* pName;
+} ma_backend_info;
+
+static ma_backend_info gBackendInfo[] = /* Indexed by the backend enum. Must be in the order backends are declared in the ma_backend enum. */
+{
+ {ma_backend_wasapi, "WASAPI"},
+ {ma_backend_dsound, "DirectSound"},
+ {ma_backend_winmm, "WinMM"},
+ {ma_backend_coreaudio, "Core Audio"},
+ {ma_backend_sndio, "sndio"},
+ {ma_backend_audio4, "audio(4)"},
+ {ma_backend_oss, "OSS"},
+ {ma_backend_pulseaudio, "PulseAudio"},
+ {ma_backend_alsa, "ALSA"},
+ {ma_backend_jack, "JACK"},
+ {ma_backend_aaudio, "AAudio"},
+ {ma_backend_opensl, "OpenSL|ES"},
+ {ma_backend_webaudio, "Web Audio"},
+ {ma_backend_custom, "Custom"},
+ {ma_backend_null, "Null"}
+};
+
MA_API const char* ma_get_backend_name(ma_backend backend)
{
- switch (backend)
- {
- case ma_backend_wasapi: return "WASAPI";
- case ma_backend_dsound: return "DirectSound";
- case ma_backend_winmm: return "WinMM";
- case ma_backend_coreaudio: return "Core Audio";
- case ma_backend_sndio: return "sndio";
- case ma_backend_audio4: return "audio(4)";
- case ma_backend_oss: return "OSS";
- case ma_backend_pulseaudio: return "PulseAudio";
- case ma_backend_alsa: return "ALSA";
- case ma_backend_jack: return "JACK";
- case ma_backend_aaudio: return "AAudio";
- case ma_backend_opensl: return "OpenSL|ES";
- case ma_backend_webaudio: return "Web Audio";
- case ma_backend_custom: return "Custom";
- case ma_backend_null: return "Null";
- default: return "Unknown";
+ if (backend < 0 || backend >= (int)ma_countof(gBackendInfo)) {
+ return "Unknown";
}
+
+ return gBackendInfo[backend].pName;
+}
+
+MA_API ma_result ma_get_backend_from_name(const char* pBackendName, ma_backend* pBackend)
+{
+ size_t iBackend;
+
+ if (pBackendName == NULL) {
+ return MA_INVALID_ARGS;
+ }
+
+ for (iBackend = 0; iBackend < ma_countof(gBackendInfo); iBackend += 1) {
+ if (ma_strcmp(pBackendName, gBackendInfo[iBackend].pName) == 0) {
+ if (pBackend != NULL) {
+ *pBackend = gBackendInfo[iBackend].backend;
+ }
+
+ return MA_SUCCESS;
+ }
+ }
+
+ /* Getting here means the backend name is unknown. */
+ return MA_INVALID_ARGS;
}
MA_API ma_bool32 ma_is_backend_enabled(ma_backend backend)
@@ -17280,16 +18085,7 @@ MA_API ma_bool32 ma_is_backend_enabled(ma_backend backend)
#if defined(MA_HAS_AAUDIO)
#if defined(MA_ANDROID)
{
- char sdkVersion[PROP_VALUE_MAX + 1] = {0, };
- if (__system_property_get("ro.build.version.sdk", sdkVersion)) {
- if (atoi(sdkVersion) >= 26) {
- return MA_TRUE;
- } else {
- return MA_FALSE;
- }
- } else {
- return MA_FALSE;
- }
+ return ma_android_sdk_version() >= 26;
}
#else
return MA_FALSE;
@@ -17301,16 +18097,7 @@ MA_API ma_bool32 ma_is_backend_enabled(ma_backend backend)
#if defined(MA_HAS_OPENSL)
#if defined(MA_ANDROID)
{
- char sdkVersion[PROP_VALUE_MAX + 1] = {0, };
- if (__system_property_get("ro.build.version.sdk", sdkVersion)) {
- if (atoi(sdkVersion) >= 9) {
- return MA_TRUE;
- } else {
- return MA_FALSE;
- }
- } else {
- return MA_FALSE;
- }
+ return ma_android_sdk_version() >= 9;
}
#else
return MA_TRUE;
@@ -17400,7 +18187,7 @@ MA_API ma_bool32 ma_is_loopback_supported(ma_backend backend)
-#ifdef MA_WIN32
+#if defined(MA_WIN32)
/* WASAPI error codes. */
#define MA_AUDCLNT_E_NOT_INITIALIZED ((HRESULT)0x88890001)
#define MA_AUDCLNT_E_ALREADY_INITIALIZED ((HRESULT)0x88890002)
@@ -17560,22 +18347,109 @@ static ma_result ma_result_from_HRESULT(HRESULT hr)
}
}
-typedef HRESULT (WINAPI * MA_PFN_CoInitializeEx)(LPVOID pvReserved, DWORD dwCoInit);
+/* PROPVARIANT */
+#define MA_VT_LPWSTR 31
+#define MA_VT_BLOB 65
+
+#if defined(_MSC_VER) && !defined(__clang__)
+ #pragma warning(push)
+ #pragma warning(disable:4201) /* nonstandard extension used: nameless struct/union */
+#elif defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)))
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wpedantic" /* For ISO C99 doesn't support unnamed structs/unions [-Wpedantic] */
+ #if defined(__clang__)
+ #pragma GCC diagnostic ignored "-Wc11-extensions" /* anonymous unions are a C11 extension */
+ #endif
+#endif
+typedef struct
+{
+ WORD vt;
+ WORD wReserved1;
+ WORD wReserved2;
+ WORD wReserved3;
+ union
+ {
+ struct
+ {
+ ULONG cbSize;
+ BYTE* pBlobData;
+ } blob;
+ WCHAR* pwszVal;
+ char pad[16]; /* Just to ensure the size of the struct matches the official version. */
+ };
+} MA_PROPVARIANT;
+#if defined(_MSC_VER) && !defined(__clang__)
+ #pragma warning(pop)
+#elif defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)))
+ #pragma GCC diagnostic pop
+#endif
+
+typedef HRESULT (WINAPI * MA_PFN_CoInitialize)(void* pvReserved);
+typedef HRESULT (WINAPI * MA_PFN_CoInitializeEx)(void* pvReserved, DWORD dwCoInit);
typedef void (WINAPI * MA_PFN_CoUninitialize)(void);
-typedef HRESULT (WINAPI * MA_PFN_CoCreateInstance)(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID riid, LPVOID *ppv);
-typedef void (WINAPI * MA_PFN_CoTaskMemFree)(LPVOID pv);
-typedef HRESULT (WINAPI * MA_PFN_PropVariantClear)(PROPVARIANT *pvar);
-typedef int (WINAPI * MA_PFN_StringFromGUID2)(const GUID* const rguid, LPOLESTR lpsz, int cchMax);
+typedef HRESULT (WINAPI * MA_PFN_CoCreateInstance)(const IID* rclsid, void* pUnkOuter, DWORD dwClsContext, const IID* riid, void* ppv);
+typedef void (WINAPI * MA_PFN_CoTaskMemFree)(void* pv);
+typedef HRESULT (WINAPI * MA_PFN_PropVariantClear)(MA_PROPVARIANT *pvar);
+typedef int (WINAPI * MA_PFN_StringFromGUID2)(const GUID* const rguid, WCHAR* lpsz, int cchMax);
-typedef HWND (WINAPI * MA_PFN_GetForegroundWindow)(void);
-typedef HWND (WINAPI * MA_PFN_GetDesktopWindow)(void);
+typedef HWND (WINAPI * MA_PFN_GetForegroundWindow)(void);
+typedef HWND (WINAPI * MA_PFN_GetDesktopWindow)(void);
#if defined(MA_WIN32_DESKTOP)
/* Microsoft documents these APIs as returning LSTATUS, but the Win32 API shipping with some compilers do not define it. It's just a LONG. */
-typedef LONG (WINAPI * MA_PFN_RegOpenKeyExA)(HKEY hKey, LPCSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult);
-typedef LONG (WINAPI * MA_PFN_RegCloseKey)(HKEY hKey);
-typedef LONG (WINAPI * MA_PFN_RegQueryValueExA)(HKEY hKey, LPCSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData);
+typedef LONG (WINAPI * MA_PFN_RegOpenKeyExA)(HKEY hKey, const char* lpSubKey, DWORD ulOptions, DWORD samDesired, HKEY* phkResult);
+typedef LONG (WINAPI * MA_PFN_RegCloseKey)(HKEY hKey);
+typedef LONG (WINAPI * MA_PFN_RegQueryValueExA)(HKEY hKey, const char* lpValueName, DWORD* lpReserved, DWORD* lpType, BYTE* lpData, DWORD* lpcbData);
#endif /* MA_WIN32_DESKTOP */
+
+
+MA_API size_t ma_strlen_WCHAR(const WCHAR* str)
+{
+ size_t len = 0;
+ while (str[len] != '\0') {
+ len += 1;
+ }
+
+ return len;
+}
+
+MA_API int ma_strcmp_WCHAR(const WCHAR *s1, const WCHAR *s2)
+{
+ while (*s1 != '\0' && *s1 == *s2) {
+ s1 += 1;
+ s2 += 1;
+ }
+
+ return *s1 - *s2;
+}
+
+MA_API int ma_strcpy_s_WCHAR(WCHAR* dst, size_t dstCap, const WCHAR* src)
+{
+ size_t i;
+
+ if (dst == 0) {
+ return 22;
+ }
+ if (dstCap == 0) {
+ return 34;
+ }
+ if (src == 0) {
+ dst[0] = '\0';
+ return 22;
+ }
+
+ for (i = 0; i < dstCap && src[i] != '\0'; ++i) {
+ dst[i] = src[i];
+ }
+
+ if (i < dstCap) {
+ dst[i] = '\0';
+ return 0;
+ }
+
+ dst[0] = '\0';
+ return 34;
+}
#endif /* MA_WIN32 */
@@ -17590,9 +18464,9 @@ typedef LONG (WINAPI * MA_PFN_RegQueryValueExA)(HKEY hKey, LPCSTR lpValueName, L
Timing
*******************************************************************************/
-#ifdef MA_WIN32
+#if defined(MA_WIN32) && !defined(MA_POSIX)
static LARGE_INTEGER g_ma_TimerFrequency; /* <-- Initialized to zero since it's static. */
- void ma_timer_init(ma_timer* pTimer)
+ static void ma_timer_init(ma_timer* pTimer)
{
LARGE_INTEGER counter;
@@ -17604,7 +18478,7 @@ Timing
pTimer->counter = counter.QuadPart;
}
- double ma_timer_get_time_in_seconds(ma_timer* pTimer)
+ static double ma_timer_get_time_in_seconds(ma_timer* pTimer)
{
LARGE_INTEGER counter;
if (!QueryPerformanceCounter(&counter)) {
@@ -17696,84 +18570,6 @@ Timing
#endif
-/*******************************************************************************
-
-Dynamic Linking
-
-*******************************************************************************/
-MA_API ma_handle ma_dlopen(ma_context* pContext, const char* filename)
-{
- ma_handle handle;
-
- ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_DEBUG, "Loading library: %s\n", filename);
-
-#ifdef _WIN32
- /* From MSDN: Desktop applications cannot use LoadPackagedLibrary; if a desktop application calls this function it fails with APPMODEL_ERROR_NO_PACKAGE.*/
- #if !defined(WINAPI_FAMILY) || (defined(WINAPI_FAMILY) && (defined(WINAPI_FAMILY_DESKTOP_APP) && WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP))
- handle = (ma_handle)LoadLibraryA(filename);
- #else
- /* *sigh* It appears there is no ANSI version of LoadPackagedLibrary()... */
- WCHAR filenameW[4096];
- if (MultiByteToWideChar(CP_UTF8, 0, filename, -1, filenameW, sizeof(filenameW)) == 0) {
- handle = NULL;
- } else {
- handle = (ma_handle)LoadPackagedLibrary(filenameW, 0);
- }
- #endif
-#else
- handle = (ma_handle)dlopen(filename, RTLD_NOW);
-#endif
-
- /*
- I'm not considering failure to load a library an error nor a warning because seamlessly falling through to a lower-priority
- backend is a deliberate design choice. Instead I'm logging it as an informational message.
- */
- if (handle == NULL) {
- ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_INFO, "Failed to load library: %s\n", filename);
- }
-
- (void)pContext; /* It's possible for pContext to be unused. */
- return handle;
-}
-
-MA_API void ma_dlclose(ma_context* pContext, ma_handle handle)
-{
-#ifdef _WIN32
- FreeLibrary((HMODULE)handle);
-#else
- dlclose((void*)handle);
-#endif
-
- (void)pContext;
-}
-
-MA_API ma_proc ma_dlsym(ma_context* pContext, ma_handle handle, const char* symbol)
-{
- ma_proc proc;
-
- ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_DEBUG, "Loading symbol: %s\n", symbol);
-
-#ifdef _WIN32
- proc = (ma_proc)GetProcAddress((HMODULE)handle, symbol);
-#else
-#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))
- #pragma GCC diagnostic push
- #pragma GCC diagnostic ignored "-Wpedantic"
-#endif
- proc = (ma_proc)dlsym((void*)handle, symbol);
-#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))
- #pragma GCC diagnostic pop
-#endif
-#endif
-
- if (proc == NULL) {
- ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_WARNING, "Failed to load symbol: %s\n", symbol);
- }
-
- (void)pContext; /* It's possible for pContext to be unused. */
- return proc;
-}
-
#if 0
static ma_uint32 ma_get_closest_standard_sample_rate(ma_uint32 sampleRateIn)
@@ -17855,30 +18651,31 @@ static void ma_device__on_notification(ma_device_notification notification)
}
}
-void ma_device__on_notification_started(ma_device* pDevice)
+static void ma_device__on_notification_started(ma_device* pDevice)
{
ma_device__on_notification(ma_device_notification_init(pDevice, ma_device_notification_type_started));
}
-void ma_device__on_notification_stopped(ma_device* pDevice)
+static void ma_device__on_notification_stopped(ma_device* pDevice)
{
ma_device__on_notification(ma_device_notification_init(pDevice, ma_device_notification_type_stopped));
}
-void ma_device__on_notification_rerouted(ma_device* pDevice)
+/* Not all platforms support reroute notifications. */
+#if !defined(MA_EMSCRIPTEN)
+static void ma_device__on_notification_rerouted(ma_device* pDevice)
{
ma_device__on_notification(ma_device_notification_init(pDevice, ma_device_notification_type_rerouted));
}
+#endif
-void ma_device__on_notification_interruption_began(ma_device* pDevice)
-{
- ma_device__on_notification(ma_device_notification_init(pDevice, ma_device_notification_type_interruption_began));
-}
-
-void ma_device__on_notification_interruption_ended(ma_device* pDevice)
+#if defined(MA_EMSCRIPTEN)
+EMSCRIPTEN_KEEPALIVE
+void ma_device__on_notification_unlocked(ma_device* pDevice)
{
- ma_device__on_notification(ma_device_notification_init(pDevice, ma_device_notification_type_interruption_ended));
+ ma_device__on_notification(ma_device_notification_init(pDevice, ma_device_notification_type_unlocked));
}
+#endif
static void ma_device__on_data_inner(ma_device* pDevice, void* pFramesOut, const void* pFramesIn, ma_uint32 frameCount)
@@ -18189,6 +18986,9 @@ static void ma_device__send_frames_to_client(ma_device* pDevice, ma_uint32 frame
totalDeviceFramesProcessed += deviceFramesProcessedThisIteration;
totalClientFramesProcessed += clientFramesProcessedThisIteration;
+ /* This is just to silence a warning. I might want to use this variable later so leaving in place for now. */
+ (void)totalClientFramesProcessed;
+
if (deviceFramesProcessedThisIteration == 0 && clientFramesProcessedThisIteration == 0) {
break; /* We're done. */
}
@@ -18325,15 +19125,15 @@ static ma_result ma_device__handle_duplex_callback_playback(ma_device* pDevice,
/* A helper for changing the state of the device. */
static MA_INLINE void ma_device__set_state(ma_device* pDevice, ma_device_state newState)
{
- c89atomic_exchange_i32((ma_int32*)&pDevice->state, (ma_int32)newState);
+ ma_atomic_device_state_set(&pDevice->state, newState);
}
-#ifdef MA_WIN32
- GUID MA_GUID_KSDATAFORMAT_SUBTYPE_PCM = {0x00000001, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
- GUID MA_GUID_KSDATAFORMAT_SUBTYPE_IEEE_FLOAT = {0x00000003, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
- /*GUID MA_GUID_KSDATAFORMAT_SUBTYPE_ALAW = {0x00000006, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};*/
- /*GUID MA_GUID_KSDATAFORMAT_SUBTYPE_MULAW = {0x00000007, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};*/
+#if defined(MA_WIN32)
+ static GUID MA_GUID_KSDATAFORMAT_SUBTYPE_PCM = {0x00000001, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
+ static GUID MA_GUID_KSDATAFORMAT_SUBTYPE_IEEE_FLOAT = {0x00000003, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
+ /*static GUID MA_GUID_KSDATAFORMAT_SUBTYPE_ALAW = {0x00000006, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};*/
+ /*static GUID MA_GUID_KSDATAFORMAT_SUBTYPE_MULAW = {0x00000007, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};*/
#endif
@@ -18836,7 +19636,7 @@ static ma_result ma_device_start__null(ma_device* pDevice)
ma_device_do_operation__null(pDevice, MA_DEVICE_OP_START__NULL);
- c89atomic_exchange_32(&pDevice->null_device.isStarted, MA_TRUE);
+ ma_atomic_bool32_set(&pDevice->null_device.isStarted, MA_TRUE);
return MA_SUCCESS;
}
@@ -18846,10 +19646,17 @@ static ma_result ma_device_stop__null(ma_device* pDevice)
ma_device_do_operation__null(pDevice, MA_DEVICE_OP_SUSPEND__NULL);
- c89atomic_exchange_32(&pDevice->null_device.isStarted, MA_FALSE);
+ ma_atomic_bool32_set(&pDevice->null_device.isStarted, MA_FALSE);
return MA_SUCCESS;
}
+static ma_bool32 ma_device_is_started__null(ma_device* pDevice)
+{
+ MA_ASSERT(pDevice != NULL);
+
+ return ma_atomic_bool32_get(&pDevice->null_device.isStarted);
+}
+
static ma_result ma_device_write__null(ma_device* pDevice, const void* pPCMFrames, ma_uint32 frameCount, ma_uint32* pFramesWritten)
{
ma_result result = MA_SUCCESS;
@@ -18860,7 +19667,7 @@ static ma_result ma_device_write__null(ma_device* pDevice, const void* pPCMFrame
*pFramesWritten = 0;
}
- wasStartedOnEntry = c89atomic_load_32(&pDevice->null_device.isStarted);
+ wasStartedOnEntry = ma_device_is_started__null(pDevice);
/* Keep going until everything has been read. */
totalPCMFramesProcessed = 0;
@@ -18886,7 +19693,7 @@ static ma_result ma_device_write__null(ma_device* pDevice, const void* pPCMFrame
if (pDevice->null_device.currentPeriodFramesRemainingPlayback == 0) {
pDevice->null_device.currentPeriodFramesRemainingPlayback = 0;
- if (!c89atomic_load_32(&pDevice->null_device.isStarted) && !wasStartedOnEntry) {
+ if (!ma_device_is_started__null(pDevice) && !wasStartedOnEntry) {
result = ma_device_start__null(pDevice);
if (result != MA_SUCCESS) {
break;
@@ -18906,7 +19713,7 @@ static ma_result ma_device_write__null(ma_device* pDevice, const void* pPCMFrame
ma_uint64 currentFrame;
/* Stop waiting if the device has been stopped. */
- if (!c89atomic_load_32(&pDevice->null_device.isStarted)) {
+ if (!ma_device_is_started__null(pDevice)) {
break;
}
@@ -18977,7 +19784,7 @@ static ma_result ma_device_read__null(ma_device* pDevice, void* pPCMFrames, ma_u
ma_uint64 currentFrame;
/* Stop waiting if the device has been stopped. */
- if (!c89atomic_load_32(&pDevice->null_device.isStarted)) {
+ if (!ma_device_is_started__null(pDevice)) {
break;
}
@@ -19042,8 +19849,8 @@ WIN32 COMMON
*******************************************************************************/
#if defined(MA_WIN32)
-#if defined(MA_WIN32_DESKTOP)
- #define ma_CoInitializeEx(pContext, pvReserved, dwCoInit) ((MA_PFN_CoInitializeEx)pContext->win32.CoInitializeEx)(pvReserved, dwCoInit)
+#if defined(MA_WIN32_DESKTOP) || defined(MA_WIN32_GDK)
+ #define ma_CoInitializeEx(pContext, pvReserved, dwCoInit) ((pContext->win32.CoInitializeEx) ? ((MA_PFN_CoInitializeEx)pContext->win32.CoInitializeEx)(pvReserved, dwCoInit) : ((MA_PFN_CoInitialize)pContext->win32.CoInitialize)(pvReserved))
#define ma_CoUninitialize(pContext) ((MA_PFN_CoUninitialize)pContext->win32.CoUninitialize)()
#define ma_CoCreateInstance(pContext, rclsid, pUnkOuter, dwClsContext, riid, ppv) ((MA_PFN_CoCreateInstance)pContext->win32.CoCreateInstance)(rclsid, pUnkOuter, dwClsContext, riid, ppv)
#define ma_CoTaskMemFree(pContext, pv) ((MA_PFN_CoTaskMemFree)pContext->win32.CoTaskMemFree)(pv)
@@ -19060,19 +19867,34 @@ WIN32 COMMON
typedef size_t DWORD_PTR;
#endif
+#if !defined(WAVE_FORMAT_1M08)
+#define WAVE_FORMAT_1M08 0x00000001
+#define WAVE_FORMAT_1S08 0x00000002
+#define WAVE_FORMAT_1M16 0x00000004
+#define WAVE_FORMAT_1S16 0x00000008
+#define WAVE_FORMAT_2M08 0x00000010
+#define WAVE_FORMAT_2S08 0x00000020
+#define WAVE_FORMAT_2M16 0x00000040
+#define WAVE_FORMAT_2S16 0x00000080
+#define WAVE_FORMAT_4M08 0x00000100
+#define WAVE_FORMAT_4S08 0x00000200
+#define WAVE_FORMAT_4M16 0x00000400
+#define WAVE_FORMAT_4S16 0x00000800
+#endif
+
#if !defined(WAVE_FORMAT_44M08)
-#define WAVE_FORMAT_44M08 0x00000100
-#define WAVE_FORMAT_44S08 0x00000200
-#define WAVE_FORMAT_44M16 0x00000400
-#define WAVE_FORMAT_44S16 0x00000800
-#define WAVE_FORMAT_48M08 0x00001000
-#define WAVE_FORMAT_48S08 0x00002000
-#define WAVE_FORMAT_48M16 0x00004000
-#define WAVE_FORMAT_48S16 0x00008000
-#define WAVE_FORMAT_96M08 0x00010000
-#define WAVE_FORMAT_96S08 0x00020000
-#define WAVE_FORMAT_96M16 0x00040000
-#define WAVE_FORMAT_96S16 0x00080000
+#define WAVE_FORMAT_44M08 0x00000100
+#define WAVE_FORMAT_44S08 0x00000200
+#define WAVE_FORMAT_44M16 0x00000400
+#define WAVE_FORMAT_44S16 0x00000800
+#define WAVE_FORMAT_48M08 0x00001000
+#define WAVE_FORMAT_48S08 0x00002000
+#define WAVE_FORMAT_48M16 0x00004000
+#define WAVE_FORMAT_48S16 0x00008000
+#define WAVE_FORMAT_96M08 0x00010000
+#define WAVE_FORMAT_96S08 0x00020000
+#define WAVE_FORMAT_96M16 0x00040000
+#define WAVE_FORMAT_96S16 0x00080000
#endif
#ifndef SPEAKER_FRONT_LEFT
@@ -19097,13 +19919,30 @@ typedef size_t DWORD_PTR;
#endif
/*
-The SDK that comes with old versions of MSVC (VC6, for example) does not appear to define WAVEFORMATEXTENSIBLE. We
-define our own implementation in this case.
+Implement our own version of MA_WAVEFORMATEXTENSIBLE so we can avoid a header. Be careful with this
+because MA_WAVEFORMATEX has an extra two bytes over standard WAVEFORMATEX due to padding. The
+standard version uses tight packing, but for compiler compatibility we're not doing that with ours.
*/
-#if (defined(_MSC_VER) && !defined(_WAVEFORMATEXTENSIBLE_)) || defined(__DMC__)
typedef struct
{
- WAVEFORMATEX Format;
+ WORD wFormatTag;
+ WORD nChannels;
+ DWORD nSamplesPerSec;
+ DWORD nAvgBytesPerSec;
+ WORD nBlockAlign;
+ WORD wBitsPerSample;
+ WORD cbSize;
+} MA_WAVEFORMATEX;
+
+typedef struct
+{
+ WORD wFormatTag;
+ WORD nChannels;
+ DWORD nSamplesPerSec;
+ DWORD nAvgBytesPerSec;
+ WORD nBlockAlign;
+ WORD wBitsPerSample;
+ WORD cbSize;
union
{
WORD wValidBitsPerSample;
@@ -19112,13 +19951,18 @@ typedef struct
} Samples;
DWORD dwChannelMask;
GUID SubFormat;
-} WAVEFORMATEXTENSIBLE;
-#endif
+} MA_WAVEFORMATEXTENSIBLE;
+
+
#ifndef WAVE_FORMAT_EXTENSIBLE
#define WAVE_FORMAT_EXTENSIBLE 0xFFFE
#endif
+#ifndef WAVE_FORMAT_PCM
+#define WAVE_FORMAT_PCM 1
+#endif
+
#ifndef WAVE_FORMAT_IEEE_FLOAT
#define WAVE_FORMAT_IEEE_FLOAT 0x0003
#endif
@@ -19232,21 +20076,21 @@ static MA_INLINE ma_bool32 ma_is_guid_null(const void* guid)
return ma_is_guid_equal(guid, &nullguid);
}
-static ma_format ma_format_from_WAVEFORMATEX(const WAVEFORMATEX* pWF)
+static ma_format ma_format_from_WAVEFORMATEX(const MA_WAVEFORMATEX* pWF)
{
MA_ASSERT(pWF != NULL);
if (pWF->wFormatTag == WAVE_FORMAT_EXTENSIBLE) {
- const WAVEFORMATEXTENSIBLE* pWFEX = (const WAVEFORMATEXTENSIBLE*)pWF;
+ const MA_WAVEFORMATEXTENSIBLE* pWFEX = (const MA_WAVEFORMATEXTENSIBLE*)pWF;
if (ma_is_guid_equal(&pWFEX->SubFormat, &MA_GUID_KSDATAFORMAT_SUBTYPE_PCM)) {
if (pWFEX->Samples.wValidBitsPerSample == 32) {
return ma_format_s32;
}
if (pWFEX->Samples.wValidBitsPerSample == 24) {
- if (pWFEX->Format.wBitsPerSample == 32) {
+ if (pWFEX->wBitsPerSample == 32) {
return ma_format_s32;
}
- if (pWFEX->Format.wBitsPerSample == 24) {
+ if (pWFEX->wBitsPerSample == 24) {
return ma_format_s24;
}
}
@@ -19354,7 +20198,7 @@ typedef struct
#endif
/* Some compilers don't define PropVariantInit(). We just do this ourselves since it's just a memset(). */
-static MA_INLINE void ma_PropVariantInit(PROPVARIANT* pProp)
+static MA_INLINE void ma_PropVariantInit(MA_PROPVARIANT* pProp)
{
MA_ZERO_OBJECT(pProp);
}
@@ -19380,17 +20224,9 @@ static const IID MA_IID_DEVINTERFACE_AUDIO_CAPTURE = {0x2EEF81BE,
static const IID MA_IID_IActivateAudioInterfaceCompletionHandler = {0x41D949AB, 0x9862, 0x444A, {0x80, 0xF6, 0xC2, 0x61, 0x33, 0x4D, 0xA5, 0xEB}}; /* 41D949AB-9862-444A-80F6-C261334DA5EB */
#endif
-static const IID MA_CLSID_MMDeviceEnumerator_Instance = {0xBCDE0395, 0xE52F, 0x467C, {0x8E, 0x3D, 0xC4, 0x57, 0x92, 0x91, 0x69, 0x2E}}; /* BCDE0395-E52F-467C-8E3D-C4579291692E = __uuidof(MMDeviceEnumerator) */
-static const IID MA_IID_IMMDeviceEnumerator_Instance = {0xA95664D2, 0x9614, 0x4F35, {0xA7, 0x46, 0xDE, 0x8D, 0xB6, 0x36, 0x17, 0xE6}}; /* A95664D2-9614-4F35-A746-DE8DB63617E6 = __uuidof(IMMDeviceEnumerator) */
-#ifdef __cplusplus
-#define MA_CLSID_MMDeviceEnumerator MA_CLSID_MMDeviceEnumerator_Instance
-#define MA_IID_IMMDeviceEnumerator MA_IID_IMMDeviceEnumerator_Instance
-#else
-#define MA_CLSID_MMDeviceEnumerator &MA_CLSID_MMDeviceEnumerator_Instance
-#define MA_IID_IMMDeviceEnumerator &MA_IID_IMMDeviceEnumerator_Instance
-#endif
+static const IID MA_CLSID_MMDeviceEnumerator = {0xBCDE0395, 0xE52F, 0x467C, {0x8E, 0x3D, 0xC4, 0x57, 0x92, 0x91, 0x69, 0x2E}}; /* BCDE0395-E52F-467C-8E3D-C4579291692E = __uuidof(MMDeviceEnumerator) */
+static const IID MA_IID_IMMDeviceEnumerator = {0xA95664D2, 0x9614, 0x4F35, {0xA7, 0x46, 0xDE, 0x8D, 0xB6, 0x36, 0x17, 0xE6}}; /* A95664D2-9614-4F35-A746-DE8DB63617E6 = __uuidof(IMMDeviceEnumerator) */
-typedef struct ma_IUnknown ma_IUnknown;
#if defined(MA_WIN32_DESKTOP) || defined(MA_WIN32_GDK)
#define MA_MM_DEVICE_STATE_ACTIVE 1
#define MA_MM_DEVICE_STATE_DISABLED 2
@@ -19487,11 +20323,11 @@ static MA_INLINE ULONG ma_IUnknown_Release(ma_IUnknown* pThis)
ULONG (STDMETHODCALLTYPE * Release) (ma_IMMNotificationClient* pThis);
/* IMMNotificationClient */
- HRESULT (STDMETHODCALLTYPE * OnDeviceStateChanged) (ma_IMMNotificationClient* pThis, LPCWSTR pDeviceID, DWORD dwNewState);
- HRESULT (STDMETHODCALLTYPE * OnDeviceAdded) (ma_IMMNotificationClient* pThis, LPCWSTR pDeviceID);
- HRESULT (STDMETHODCALLTYPE * OnDeviceRemoved) (ma_IMMNotificationClient* pThis, LPCWSTR pDeviceID);
- HRESULT (STDMETHODCALLTYPE * OnDefaultDeviceChanged)(ma_IMMNotificationClient* pThis, ma_EDataFlow dataFlow, ma_ERole role, LPCWSTR pDefaultDeviceID);
- HRESULT (STDMETHODCALLTYPE * OnPropertyValueChanged)(ma_IMMNotificationClient* pThis, LPCWSTR pDeviceID, const PROPERTYKEY key);
+ HRESULT (STDMETHODCALLTYPE * OnDeviceStateChanged) (ma_IMMNotificationClient* pThis, const WCHAR* pDeviceID, DWORD dwNewState);
+ HRESULT (STDMETHODCALLTYPE * OnDeviceAdded) (ma_IMMNotificationClient* pThis, const WCHAR* pDeviceID);
+ HRESULT (STDMETHODCALLTYPE * OnDeviceRemoved) (ma_IMMNotificationClient* pThis, const WCHAR* pDeviceID);
+ HRESULT (STDMETHODCALLTYPE * OnDefaultDeviceChanged)(ma_IMMNotificationClient* pThis, ma_EDataFlow dataFlow, ma_ERole role, const WCHAR* pDefaultDeviceID);
+ HRESULT (STDMETHODCALLTYPE * OnPropertyValueChanged)(ma_IMMNotificationClient* pThis, const WCHAR* pDeviceID, const PROPERTYKEY key);
} ma_IMMNotificationClientVtbl;
/* IMMDeviceEnumerator */
@@ -19505,7 +20341,7 @@ static MA_INLINE ULONG ma_IUnknown_Release(ma_IUnknown* pThis)
/* IMMDeviceEnumerator */
HRESULT (STDMETHODCALLTYPE * EnumAudioEndpoints) (ma_IMMDeviceEnumerator* pThis, ma_EDataFlow dataFlow, DWORD dwStateMask, ma_IMMDeviceCollection** ppDevices);
HRESULT (STDMETHODCALLTYPE * GetDefaultAudioEndpoint) (ma_IMMDeviceEnumerator* pThis, ma_EDataFlow dataFlow, ma_ERole role, ma_IMMDevice** ppEndpoint);
- HRESULT (STDMETHODCALLTYPE * GetDevice) (ma_IMMDeviceEnumerator* pThis, LPCWSTR pID, ma_IMMDevice** ppDevice);
+ HRESULT (STDMETHODCALLTYPE * GetDevice) (ma_IMMDeviceEnumerator* pThis, const WCHAR* pID, ma_IMMDevice** ppDevice);
HRESULT (STDMETHODCALLTYPE * RegisterEndpointNotificationCallback) (ma_IMMDeviceEnumerator* pThis, ma_IMMNotificationClient* pClient);
HRESULT (STDMETHODCALLTYPE * UnregisterEndpointNotificationCallback)(ma_IMMDeviceEnumerator* pThis, ma_IMMNotificationClient* pClient);
} ma_IMMDeviceEnumeratorVtbl;
@@ -19518,7 +20354,7 @@ static MA_INLINE ULONG ma_IUnknown_Release(ma_IUnknown* pThis)
static MA_INLINE ULONG ma_IMMDeviceEnumerator_Release(ma_IMMDeviceEnumerator* pThis) { return pThis->lpVtbl->Release(pThis); }
static MA_INLINE HRESULT ma_IMMDeviceEnumerator_EnumAudioEndpoints(ma_IMMDeviceEnumerator* pThis, ma_EDataFlow dataFlow, DWORD dwStateMask, ma_IMMDeviceCollection** ppDevices) { return pThis->lpVtbl->EnumAudioEndpoints(pThis, dataFlow, dwStateMask, ppDevices); }
static MA_INLINE HRESULT ma_IMMDeviceEnumerator_GetDefaultAudioEndpoint(ma_IMMDeviceEnumerator* pThis, ma_EDataFlow dataFlow, ma_ERole role, ma_IMMDevice** ppEndpoint) { return pThis->lpVtbl->GetDefaultAudioEndpoint(pThis, dataFlow, role, ppEndpoint); }
- static MA_INLINE HRESULT ma_IMMDeviceEnumerator_GetDevice(ma_IMMDeviceEnumerator* pThis, LPCWSTR pID, ma_IMMDevice** ppDevice) { return pThis->lpVtbl->GetDevice(pThis, pID, ppDevice); }
+ static MA_INLINE HRESULT ma_IMMDeviceEnumerator_GetDevice(ma_IMMDeviceEnumerator* pThis, const WCHAR* pID, ma_IMMDevice** ppDevice) { return pThis->lpVtbl->GetDevice(pThis, pID, ppDevice); }
static MA_INLINE HRESULT ma_IMMDeviceEnumerator_RegisterEndpointNotificationCallback(ma_IMMDeviceEnumerator* pThis, ma_IMMNotificationClient* pClient) { return pThis->lpVtbl->RegisterEndpointNotificationCallback(pThis, pClient); }
static MA_INLINE HRESULT ma_IMMDeviceEnumerator_UnregisterEndpointNotificationCallback(ma_IMMDeviceEnumerator* pThis, ma_IMMNotificationClient* pClient) { return pThis->lpVtbl->UnregisterEndpointNotificationCallback(pThis, pClient); }
@@ -19555,9 +20391,9 @@ static MA_INLINE ULONG ma_IUnknown_Release(ma_IUnknown* pThis)
ULONG (STDMETHODCALLTYPE * Release) (ma_IMMDevice* pThis);
/* IMMDevice */
- HRESULT (STDMETHODCALLTYPE * Activate) (ma_IMMDevice* pThis, const IID* const iid, DWORD dwClsCtx, PROPVARIANT* pActivationParams, void** ppInterface);
+ HRESULT (STDMETHODCALLTYPE * Activate) (ma_IMMDevice* pThis, const IID* const iid, DWORD dwClsCtx, MA_PROPVARIANT* pActivationParams, void** ppInterface);
HRESULT (STDMETHODCALLTYPE * OpenPropertyStore)(ma_IMMDevice* pThis, DWORD stgmAccess, ma_IPropertyStore** ppProperties);
- HRESULT (STDMETHODCALLTYPE * GetId) (ma_IMMDevice* pThis, LPWSTR *pID);
+ HRESULT (STDMETHODCALLTYPE * GetId) (ma_IMMDevice* pThis, WCHAR** pID);
HRESULT (STDMETHODCALLTYPE * GetState) (ma_IMMDevice* pThis, DWORD *pState);
} ma_IMMDeviceVtbl;
struct ma_IMMDevice
@@ -19567,9 +20403,9 @@ static MA_INLINE ULONG ma_IUnknown_Release(ma_IUnknown* pThis)
static MA_INLINE HRESULT ma_IMMDevice_QueryInterface(ma_IMMDevice* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); }
static MA_INLINE ULONG ma_IMMDevice_AddRef(ma_IMMDevice* pThis) { return pThis->lpVtbl->AddRef(pThis); }
static MA_INLINE ULONG ma_IMMDevice_Release(ma_IMMDevice* pThis) { return pThis->lpVtbl->Release(pThis); }
- static MA_INLINE HRESULT ma_IMMDevice_Activate(ma_IMMDevice* pThis, const IID* const iid, DWORD dwClsCtx, PROPVARIANT* pActivationParams, void** ppInterface) { return pThis->lpVtbl->Activate(pThis, iid, dwClsCtx, pActivationParams, ppInterface); }
+ static MA_INLINE HRESULT ma_IMMDevice_Activate(ma_IMMDevice* pThis, const IID* const iid, DWORD dwClsCtx, MA_PROPVARIANT* pActivationParams, void** ppInterface) { return pThis->lpVtbl->Activate(pThis, iid, dwClsCtx, pActivationParams, ppInterface); }
static MA_INLINE HRESULT ma_IMMDevice_OpenPropertyStore(ma_IMMDevice* pThis, DWORD stgmAccess, ma_IPropertyStore** ppProperties) { return pThis->lpVtbl->OpenPropertyStore(pThis, stgmAccess, ppProperties); }
- static MA_INLINE HRESULT ma_IMMDevice_GetId(ma_IMMDevice* pThis, LPWSTR *pID) { return pThis->lpVtbl->GetId(pThis, pID); }
+ static MA_INLINE HRESULT ma_IMMDevice_GetId(ma_IMMDevice* pThis, WCHAR** pID) { return pThis->lpVtbl->GetId(pThis, pID); }
static MA_INLINE HRESULT ma_IMMDevice_GetState(ma_IMMDevice* pThis, DWORD *pState) { return pThis->lpVtbl->GetState(pThis, pState); }
#else
/* IActivateAudioInterfaceAsyncOperation */
@@ -19604,8 +20440,8 @@ typedef struct
/* IPropertyStore */
HRESULT (STDMETHODCALLTYPE * GetCount)(ma_IPropertyStore* pThis, DWORD* pPropCount);
HRESULT (STDMETHODCALLTYPE * GetAt) (ma_IPropertyStore* pThis, DWORD propIndex, PROPERTYKEY* pPropKey);
- HRESULT (STDMETHODCALLTYPE * GetValue)(ma_IPropertyStore* pThis, const PROPERTYKEY* const pKey, PROPVARIANT* pPropVar);
- HRESULT (STDMETHODCALLTYPE * SetValue)(ma_IPropertyStore* pThis, const PROPERTYKEY* const pKey, const PROPVARIANT* const pPropVar);
+ HRESULT (STDMETHODCALLTYPE * GetValue)(ma_IPropertyStore* pThis, const PROPERTYKEY* const pKey, MA_PROPVARIANT* pPropVar);
+ HRESULT (STDMETHODCALLTYPE * SetValue)(ma_IPropertyStore* pThis, const PROPERTYKEY* const pKey, const MA_PROPVARIANT* const pPropVar);
HRESULT (STDMETHODCALLTYPE * Commit) (ma_IPropertyStore* pThis);
} ma_IPropertyStoreVtbl;
struct ma_IPropertyStore
@@ -19617,8 +20453,8 @@ static MA_INLINE ULONG ma_IPropertyStore_AddRef(ma_IPropertyStore* pThis)
static MA_INLINE ULONG ma_IPropertyStore_Release(ma_IPropertyStore* pThis) { return pThis->lpVtbl->Release(pThis); }
static MA_INLINE HRESULT ma_IPropertyStore_GetCount(ma_IPropertyStore* pThis, DWORD* pPropCount) { return pThis->lpVtbl->GetCount(pThis, pPropCount); }
static MA_INLINE HRESULT ma_IPropertyStore_GetAt(ma_IPropertyStore* pThis, DWORD propIndex, PROPERTYKEY* pPropKey) { return pThis->lpVtbl->GetAt(pThis, propIndex, pPropKey); }
-static MA_INLINE HRESULT ma_IPropertyStore_GetValue(ma_IPropertyStore* pThis, const PROPERTYKEY* const pKey, PROPVARIANT* pPropVar) { return pThis->lpVtbl->GetValue(pThis, pKey, pPropVar); }
-static MA_INLINE HRESULT ma_IPropertyStore_SetValue(ma_IPropertyStore* pThis, const PROPERTYKEY* const pKey, const PROPVARIANT* const pPropVar) { return pThis->lpVtbl->SetValue(pThis, pKey, pPropVar); }
+static MA_INLINE HRESULT ma_IPropertyStore_GetValue(ma_IPropertyStore* pThis, const PROPERTYKEY* const pKey, MA_PROPVARIANT* pPropVar) { return pThis->lpVtbl->GetValue(pThis, pKey, pPropVar); }
+static MA_INLINE HRESULT ma_IPropertyStore_SetValue(ma_IPropertyStore* pThis, const PROPERTYKEY* const pKey, const MA_PROPVARIANT* const pPropVar) { return pThis->lpVtbl->SetValue(pThis, pKey, pPropVar); }
static MA_INLINE HRESULT ma_IPropertyStore_Commit(ma_IPropertyStore* pThis) { return pThis->lpVtbl->Commit(pThis); }
@@ -19631,12 +20467,12 @@ typedef struct
ULONG (STDMETHODCALLTYPE * Release) (ma_IAudioClient* pThis);
/* IAudioClient */
- HRESULT (STDMETHODCALLTYPE * Initialize) (ma_IAudioClient* pThis, MA_AUDCLNT_SHAREMODE shareMode, DWORD streamFlags, MA_REFERENCE_TIME bufferDuration, MA_REFERENCE_TIME periodicity, const WAVEFORMATEX* pFormat, const GUID* pAudioSessionGuid);
+ HRESULT (STDMETHODCALLTYPE * Initialize) (ma_IAudioClient* pThis, MA_AUDCLNT_SHAREMODE shareMode, DWORD streamFlags, MA_REFERENCE_TIME bufferDuration, MA_REFERENCE_TIME periodicity, const MA_WAVEFORMATEX* pFormat, const GUID* pAudioSessionGuid);
HRESULT (STDMETHODCALLTYPE * GetBufferSize) (ma_IAudioClient* pThis, ma_uint32* pNumBufferFrames);
HRESULT (STDMETHODCALLTYPE * GetStreamLatency) (ma_IAudioClient* pThis, MA_REFERENCE_TIME* pLatency);
HRESULT (STDMETHODCALLTYPE * GetCurrentPadding)(ma_IAudioClient* pThis, ma_uint32* pNumPaddingFrames);
- HRESULT (STDMETHODCALLTYPE * IsFormatSupported)(ma_IAudioClient* pThis, MA_AUDCLNT_SHAREMODE shareMode, const WAVEFORMATEX* pFormat, WAVEFORMATEX** ppClosestMatch);
- HRESULT (STDMETHODCALLTYPE * GetMixFormat) (ma_IAudioClient* pThis, WAVEFORMATEX** ppDeviceFormat);
+ HRESULT (STDMETHODCALLTYPE * IsFormatSupported)(ma_IAudioClient* pThis, MA_AUDCLNT_SHAREMODE shareMode, const MA_WAVEFORMATEX* pFormat, MA_WAVEFORMATEX** ppClosestMatch);
+ HRESULT (STDMETHODCALLTYPE * GetMixFormat) (ma_IAudioClient* pThis, MA_WAVEFORMATEX** ppDeviceFormat);
HRESULT (STDMETHODCALLTYPE * GetDevicePeriod) (ma_IAudioClient* pThis, MA_REFERENCE_TIME* pDefaultDevicePeriod, MA_REFERENCE_TIME* pMinimumDevicePeriod);
HRESULT (STDMETHODCALLTYPE * Start) (ma_IAudioClient* pThis);
HRESULT (STDMETHODCALLTYPE * Stop) (ma_IAudioClient* pThis);
@@ -19651,12 +20487,12 @@ struct ma_IAudioClient
static MA_INLINE HRESULT ma_IAudioClient_QueryInterface(ma_IAudioClient* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); }
static MA_INLINE ULONG ma_IAudioClient_AddRef(ma_IAudioClient* pThis) { return pThis->lpVtbl->AddRef(pThis); }
static MA_INLINE ULONG ma_IAudioClient_Release(ma_IAudioClient* pThis) { return pThis->lpVtbl->Release(pThis); }
-static MA_INLINE HRESULT ma_IAudioClient_Initialize(ma_IAudioClient* pThis, MA_AUDCLNT_SHAREMODE shareMode, DWORD streamFlags, MA_REFERENCE_TIME bufferDuration, MA_REFERENCE_TIME periodicity, const WAVEFORMATEX* pFormat, const GUID* pAudioSessionGuid) { return pThis->lpVtbl->Initialize(pThis, shareMode, streamFlags, bufferDuration, periodicity, pFormat, pAudioSessionGuid); }
+static MA_INLINE HRESULT ma_IAudioClient_Initialize(ma_IAudioClient* pThis, MA_AUDCLNT_SHAREMODE shareMode, DWORD streamFlags, MA_REFERENCE_TIME bufferDuration, MA_REFERENCE_TIME periodicity, const MA_WAVEFORMATEX* pFormat, const GUID* pAudioSessionGuid) { return pThis->lpVtbl->Initialize(pThis, shareMode, streamFlags, bufferDuration, periodicity, pFormat, pAudioSessionGuid); }
static MA_INLINE HRESULT ma_IAudioClient_GetBufferSize(ma_IAudioClient* pThis, ma_uint32* pNumBufferFrames) { return pThis->lpVtbl->GetBufferSize(pThis, pNumBufferFrames); }
static MA_INLINE HRESULT ma_IAudioClient_GetStreamLatency(ma_IAudioClient* pThis, MA_REFERENCE_TIME* pLatency) { return pThis->lpVtbl->GetStreamLatency(pThis, pLatency); }
static MA_INLINE HRESULT ma_IAudioClient_GetCurrentPadding(ma_IAudioClient* pThis, ma_uint32* pNumPaddingFrames) { return pThis->lpVtbl->GetCurrentPadding(pThis, pNumPaddingFrames); }
-static MA_INLINE HRESULT ma_IAudioClient_IsFormatSupported(ma_IAudioClient* pThis, MA_AUDCLNT_SHAREMODE shareMode, const WAVEFORMATEX* pFormat, WAVEFORMATEX** ppClosestMatch) { return pThis->lpVtbl->IsFormatSupported(pThis, shareMode, pFormat, ppClosestMatch); }
-static MA_INLINE HRESULT ma_IAudioClient_GetMixFormat(ma_IAudioClient* pThis, WAVEFORMATEX** ppDeviceFormat) { return pThis->lpVtbl->GetMixFormat(pThis, ppDeviceFormat); }
+static MA_INLINE HRESULT ma_IAudioClient_IsFormatSupported(ma_IAudioClient* pThis, MA_AUDCLNT_SHAREMODE shareMode, const MA_WAVEFORMATEX* pFormat, MA_WAVEFORMATEX** ppClosestMatch) { return pThis->lpVtbl->IsFormatSupported(pThis, shareMode, pFormat, ppClosestMatch); }
+static MA_INLINE HRESULT ma_IAudioClient_GetMixFormat(ma_IAudioClient* pThis, MA_WAVEFORMATEX** ppDeviceFormat) { return pThis->lpVtbl->GetMixFormat(pThis, ppDeviceFormat); }
static MA_INLINE HRESULT ma_IAudioClient_GetDevicePeriod(ma_IAudioClient* pThis, MA_REFERENCE_TIME* pDefaultDevicePeriod, MA_REFERENCE_TIME* pMinimumDevicePeriod) { return pThis->lpVtbl->GetDevicePeriod(pThis, pDefaultDevicePeriod, pMinimumDevicePeriod); }
static MA_INLINE HRESULT ma_IAudioClient_Start(ma_IAudioClient* pThis) { return pThis->lpVtbl->Start(pThis); }
static MA_INLINE HRESULT ma_IAudioClient_Stop(ma_IAudioClient* pThis) { return pThis->lpVtbl->Stop(pThis); }
@@ -19673,12 +20509,12 @@ typedef struct
ULONG (STDMETHODCALLTYPE * Release) (ma_IAudioClient2* pThis);
/* IAudioClient */
- HRESULT (STDMETHODCALLTYPE * Initialize) (ma_IAudioClient2* pThis, MA_AUDCLNT_SHAREMODE shareMode, DWORD streamFlags, MA_REFERENCE_TIME bufferDuration, MA_REFERENCE_TIME periodicity, const WAVEFORMATEX* pFormat, const GUID* pAudioSessionGuid);
+ HRESULT (STDMETHODCALLTYPE * Initialize) (ma_IAudioClient2* pThis, MA_AUDCLNT_SHAREMODE shareMode, DWORD streamFlags, MA_REFERENCE_TIME bufferDuration, MA_REFERENCE_TIME periodicity, const MA_WAVEFORMATEX* pFormat, const GUID* pAudioSessionGuid);
HRESULT (STDMETHODCALLTYPE * GetBufferSize) (ma_IAudioClient2* pThis, ma_uint32* pNumBufferFrames);
HRESULT (STDMETHODCALLTYPE * GetStreamLatency) (ma_IAudioClient2* pThis, MA_REFERENCE_TIME* pLatency);
HRESULT (STDMETHODCALLTYPE * GetCurrentPadding)(ma_IAudioClient2* pThis, ma_uint32* pNumPaddingFrames);
- HRESULT (STDMETHODCALLTYPE * IsFormatSupported)(ma_IAudioClient2* pThis, MA_AUDCLNT_SHAREMODE shareMode, const WAVEFORMATEX* pFormat, WAVEFORMATEX** ppClosestMatch);
- HRESULT (STDMETHODCALLTYPE * GetMixFormat) (ma_IAudioClient2* pThis, WAVEFORMATEX** ppDeviceFormat);
+ HRESULT (STDMETHODCALLTYPE * IsFormatSupported)(ma_IAudioClient2* pThis, MA_AUDCLNT_SHAREMODE shareMode, const MA_WAVEFORMATEX* pFormat, MA_WAVEFORMATEX** ppClosestMatch);
+ HRESULT (STDMETHODCALLTYPE * GetMixFormat) (ma_IAudioClient2* pThis, MA_WAVEFORMATEX** ppDeviceFormat);
HRESULT (STDMETHODCALLTYPE * GetDevicePeriod) (ma_IAudioClient2* pThis, MA_REFERENCE_TIME* pDefaultDevicePeriod, MA_REFERENCE_TIME* pMinimumDevicePeriod);
HRESULT (STDMETHODCALLTYPE * Start) (ma_IAudioClient2* pThis);
HRESULT (STDMETHODCALLTYPE * Stop) (ma_IAudioClient2* pThis);
@@ -19689,7 +20525,7 @@ typedef struct
/* IAudioClient2 */
HRESULT (STDMETHODCALLTYPE * IsOffloadCapable) (ma_IAudioClient2* pThis, MA_AUDIO_STREAM_CATEGORY category, BOOL* pOffloadCapable);
HRESULT (STDMETHODCALLTYPE * SetClientProperties)(ma_IAudioClient2* pThis, const ma_AudioClientProperties* pProperties);
- HRESULT (STDMETHODCALLTYPE * GetBufferSizeLimits)(ma_IAudioClient2* pThis, const WAVEFORMATEX* pFormat, BOOL eventDriven, MA_REFERENCE_TIME* pMinBufferDuration, MA_REFERENCE_TIME* pMaxBufferDuration);
+ HRESULT (STDMETHODCALLTYPE * GetBufferSizeLimits)(ma_IAudioClient2* pThis, const MA_WAVEFORMATEX* pFormat, BOOL eventDriven, MA_REFERENCE_TIME* pMinBufferDuration, MA_REFERENCE_TIME* pMaxBufferDuration);
} ma_IAudioClient2Vtbl;
struct ma_IAudioClient2
{
@@ -19698,12 +20534,12 @@ struct ma_IAudioClient2
static MA_INLINE HRESULT ma_IAudioClient2_QueryInterface(ma_IAudioClient2* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); }
static MA_INLINE ULONG ma_IAudioClient2_AddRef(ma_IAudioClient2* pThis) { return pThis->lpVtbl->AddRef(pThis); }
static MA_INLINE ULONG ma_IAudioClient2_Release(ma_IAudioClient2* pThis) { return pThis->lpVtbl->Release(pThis); }
-static MA_INLINE HRESULT ma_IAudioClient2_Initialize(ma_IAudioClient2* pThis, MA_AUDCLNT_SHAREMODE shareMode, DWORD streamFlags, MA_REFERENCE_TIME bufferDuration, MA_REFERENCE_TIME periodicity, const WAVEFORMATEX* pFormat, const GUID* pAudioSessionGuid) { return pThis->lpVtbl->Initialize(pThis, shareMode, streamFlags, bufferDuration, periodicity, pFormat, pAudioSessionGuid); }
+static MA_INLINE HRESULT ma_IAudioClient2_Initialize(ma_IAudioClient2* pThis, MA_AUDCLNT_SHAREMODE shareMode, DWORD streamFlags, MA_REFERENCE_TIME bufferDuration, MA_REFERENCE_TIME periodicity, const MA_WAVEFORMATEX* pFormat, const GUID* pAudioSessionGuid) { return pThis->lpVtbl->Initialize(pThis, shareMode, streamFlags, bufferDuration, periodicity, pFormat, pAudioSessionGuid); }
static MA_INLINE HRESULT ma_IAudioClient2_GetBufferSize(ma_IAudioClient2* pThis, ma_uint32* pNumBufferFrames) { return pThis->lpVtbl->GetBufferSize(pThis, pNumBufferFrames); }
static MA_INLINE HRESULT ma_IAudioClient2_GetStreamLatency(ma_IAudioClient2* pThis, MA_REFERENCE_TIME* pLatency) { return pThis->lpVtbl->GetStreamLatency(pThis, pLatency); }
static MA_INLINE HRESULT ma_IAudioClient2_GetCurrentPadding(ma_IAudioClient2* pThis, ma_uint32* pNumPaddingFrames) { return pThis->lpVtbl->GetCurrentPadding(pThis, pNumPaddingFrames); }
-static MA_INLINE HRESULT ma_IAudioClient2_IsFormatSupported(ma_IAudioClient2* pThis, MA_AUDCLNT_SHAREMODE shareMode, const WAVEFORMATEX* pFormat, WAVEFORMATEX** ppClosestMatch) { return pThis->lpVtbl->IsFormatSupported(pThis, shareMode, pFormat, ppClosestMatch); }
-static MA_INLINE HRESULT ma_IAudioClient2_GetMixFormat(ma_IAudioClient2* pThis, WAVEFORMATEX** ppDeviceFormat) { return pThis->lpVtbl->GetMixFormat(pThis, ppDeviceFormat); }
+static MA_INLINE HRESULT ma_IAudioClient2_IsFormatSupported(ma_IAudioClient2* pThis, MA_AUDCLNT_SHAREMODE shareMode, const MA_WAVEFORMATEX* pFormat, MA_WAVEFORMATEX** ppClosestMatch) { return pThis->lpVtbl->IsFormatSupported(pThis, shareMode, pFormat, ppClosestMatch); }
+static MA_INLINE HRESULT ma_IAudioClient2_GetMixFormat(ma_IAudioClient2* pThis, MA_WAVEFORMATEX** ppDeviceFormat) { return pThis->lpVtbl->GetMixFormat(pThis, ppDeviceFormat); }
static MA_INLINE HRESULT ma_IAudioClient2_GetDevicePeriod(ma_IAudioClient2* pThis, MA_REFERENCE_TIME* pDefaultDevicePeriod, MA_REFERENCE_TIME* pMinimumDevicePeriod) { return pThis->lpVtbl->GetDevicePeriod(pThis, pDefaultDevicePeriod, pMinimumDevicePeriod); }
static MA_INLINE HRESULT ma_IAudioClient2_Start(ma_IAudioClient2* pThis) { return pThis->lpVtbl->Start(pThis); }
static MA_INLINE HRESULT ma_IAudioClient2_Stop(ma_IAudioClient2* pThis) { return pThis->lpVtbl->Stop(pThis); }
@@ -19712,7 +20548,7 @@ static MA_INLINE HRESULT ma_IAudioClient2_SetEventHandle(ma_IAudioClient2* pThis
static MA_INLINE HRESULT ma_IAudioClient2_GetService(ma_IAudioClient2* pThis, const IID* const riid, void** pp) { return pThis->lpVtbl->GetService(pThis, riid, pp); }
static MA_INLINE HRESULT ma_IAudioClient2_IsOffloadCapable(ma_IAudioClient2* pThis, MA_AUDIO_STREAM_CATEGORY category, BOOL* pOffloadCapable) { return pThis->lpVtbl->IsOffloadCapable(pThis, category, pOffloadCapable); }
static MA_INLINE HRESULT ma_IAudioClient2_SetClientProperties(ma_IAudioClient2* pThis, const ma_AudioClientProperties* pProperties) { return pThis->lpVtbl->SetClientProperties(pThis, pProperties); }
-static MA_INLINE HRESULT ma_IAudioClient2_GetBufferSizeLimits(ma_IAudioClient2* pThis, const WAVEFORMATEX* pFormat, BOOL eventDriven, MA_REFERENCE_TIME* pMinBufferDuration, MA_REFERENCE_TIME* pMaxBufferDuration) { return pThis->lpVtbl->GetBufferSizeLimits(pThis, pFormat, eventDriven, pMinBufferDuration, pMaxBufferDuration); }
+static MA_INLINE HRESULT ma_IAudioClient2_GetBufferSizeLimits(ma_IAudioClient2* pThis, const MA_WAVEFORMATEX* pFormat, BOOL eventDriven, MA_REFERENCE_TIME* pMinBufferDuration, MA_REFERENCE_TIME* pMaxBufferDuration) { return pThis->lpVtbl->GetBufferSizeLimits(pThis, pFormat, eventDriven, pMinBufferDuration, pMaxBufferDuration); }
/* IAudioClient3 */
@@ -19724,12 +20560,12 @@ typedef struct
ULONG (STDMETHODCALLTYPE * Release) (ma_IAudioClient3* pThis);
/* IAudioClient */
- HRESULT (STDMETHODCALLTYPE * Initialize) (ma_IAudioClient3* pThis, MA_AUDCLNT_SHAREMODE shareMode, DWORD streamFlags, MA_REFERENCE_TIME bufferDuration, MA_REFERENCE_TIME periodicity, const WAVEFORMATEX* pFormat, const GUID* pAudioSessionGuid);
+ HRESULT (STDMETHODCALLTYPE * Initialize) (ma_IAudioClient3* pThis, MA_AUDCLNT_SHAREMODE shareMode, DWORD streamFlags, MA_REFERENCE_TIME bufferDuration, MA_REFERENCE_TIME periodicity, const MA_WAVEFORMATEX* pFormat, const GUID* pAudioSessionGuid);
HRESULT (STDMETHODCALLTYPE * GetBufferSize) (ma_IAudioClient3* pThis, ma_uint32* pNumBufferFrames);
HRESULT (STDMETHODCALLTYPE * GetStreamLatency) (ma_IAudioClient3* pThis, MA_REFERENCE_TIME* pLatency);
HRESULT (STDMETHODCALLTYPE * GetCurrentPadding)(ma_IAudioClient3* pThis, ma_uint32* pNumPaddingFrames);
- HRESULT (STDMETHODCALLTYPE * IsFormatSupported)(ma_IAudioClient3* pThis, MA_AUDCLNT_SHAREMODE shareMode, const WAVEFORMATEX* pFormat, WAVEFORMATEX** ppClosestMatch);
- HRESULT (STDMETHODCALLTYPE * GetMixFormat) (ma_IAudioClient3* pThis, WAVEFORMATEX** ppDeviceFormat);
+ HRESULT (STDMETHODCALLTYPE * IsFormatSupported)(ma_IAudioClient3* pThis, MA_AUDCLNT_SHAREMODE shareMode, const MA_WAVEFORMATEX* pFormat, MA_WAVEFORMATEX** ppClosestMatch);
+ HRESULT (STDMETHODCALLTYPE * GetMixFormat) (ma_IAudioClient3* pThis, MA_WAVEFORMATEX** ppDeviceFormat);
HRESULT (STDMETHODCALLTYPE * GetDevicePeriod) (ma_IAudioClient3* pThis, MA_REFERENCE_TIME* pDefaultDevicePeriod, MA_REFERENCE_TIME* pMinimumDevicePeriod);
HRESULT (STDMETHODCALLTYPE * Start) (ma_IAudioClient3* pThis);
HRESULT (STDMETHODCALLTYPE * Stop) (ma_IAudioClient3* pThis);
@@ -19740,12 +20576,12 @@ typedef struct
/* IAudioClient2 */
HRESULT (STDMETHODCALLTYPE * IsOffloadCapable) (ma_IAudioClient3* pThis, MA_AUDIO_STREAM_CATEGORY category, BOOL* pOffloadCapable);
HRESULT (STDMETHODCALLTYPE * SetClientProperties)(ma_IAudioClient3* pThis, const ma_AudioClientProperties* pProperties);
- HRESULT (STDMETHODCALLTYPE * GetBufferSizeLimits)(ma_IAudioClient3* pThis, const WAVEFORMATEX* pFormat, BOOL eventDriven, MA_REFERENCE_TIME* pMinBufferDuration, MA_REFERENCE_TIME* pMaxBufferDuration);
+ HRESULT (STDMETHODCALLTYPE * GetBufferSizeLimits)(ma_IAudioClient3* pThis, const MA_WAVEFORMATEX* pFormat, BOOL eventDriven, MA_REFERENCE_TIME* pMinBufferDuration, MA_REFERENCE_TIME* pMaxBufferDuration);
/* IAudioClient3 */
- HRESULT (STDMETHODCALLTYPE * GetSharedModeEnginePeriod) (ma_IAudioClient3* pThis, const WAVEFORMATEX* pFormat, ma_uint32* pDefaultPeriodInFrames, ma_uint32* pFundamentalPeriodInFrames, ma_uint32* pMinPeriodInFrames, ma_uint32* pMaxPeriodInFrames);
- HRESULT (STDMETHODCALLTYPE * GetCurrentSharedModeEnginePeriod)(ma_IAudioClient3* pThis, WAVEFORMATEX** ppFormat, ma_uint32* pCurrentPeriodInFrames);
- HRESULT (STDMETHODCALLTYPE * InitializeSharedAudioStream) (ma_IAudioClient3* pThis, DWORD streamFlags, ma_uint32 periodInFrames, const WAVEFORMATEX* pFormat, const GUID* pAudioSessionGuid);
+ HRESULT (STDMETHODCALLTYPE * GetSharedModeEnginePeriod) (ma_IAudioClient3* pThis, const MA_WAVEFORMATEX* pFormat, ma_uint32* pDefaultPeriodInFrames, ma_uint32* pFundamentalPeriodInFrames, ma_uint32* pMinPeriodInFrames, ma_uint32* pMaxPeriodInFrames);
+ HRESULT (STDMETHODCALLTYPE * GetCurrentSharedModeEnginePeriod)(ma_IAudioClient3* pThis, MA_WAVEFORMATEX** ppFormat, ma_uint32* pCurrentPeriodInFrames);
+ HRESULT (STDMETHODCALLTYPE * InitializeSharedAudioStream) (ma_IAudioClient3* pThis, DWORD streamFlags, ma_uint32 periodInFrames, const MA_WAVEFORMATEX* pFormat, const GUID* pAudioSessionGuid);
} ma_IAudioClient3Vtbl;
struct ma_IAudioClient3
{
@@ -19754,12 +20590,12 @@ struct ma_IAudioClient3
static MA_INLINE HRESULT ma_IAudioClient3_QueryInterface(ma_IAudioClient3* pThis, const IID* const riid, void** ppObject) { return pThis->lpVtbl->QueryInterface(pThis, riid, ppObject); }
static MA_INLINE ULONG ma_IAudioClient3_AddRef(ma_IAudioClient3* pThis) { return pThis->lpVtbl->AddRef(pThis); }
static MA_INLINE ULONG ma_IAudioClient3_Release(ma_IAudioClient3* pThis) { return pThis->lpVtbl->Release(pThis); }
-static MA_INLINE HRESULT ma_IAudioClient3_Initialize(ma_IAudioClient3* pThis, MA_AUDCLNT_SHAREMODE shareMode, DWORD streamFlags, MA_REFERENCE_TIME bufferDuration, MA_REFERENCE_TIME periodicity, const WAVEFORMATEX* pFormat, const GUID* pAudioSessionGuid) { return pThis->lpVtbl->Initialize(pThis, shareMode, streamFlags, bufferDuration, periodicity, pFormat, pAudioSessionGuid); }
+static MA_INLINE HRESULT ma_IAudioClient3_Initialize(ma_IAudioClient3* pThis, MA_AUDCLNT_SHAREMODE shareMode, DWORD streamFlags, MA_REFERENCE_TIME bufferDuration, MA_REFERENCE_TIME periodicity, const MA_WAVEFORMATEX* pFormat, const GUID* pAudioSessionGuid) { return pThis->lpVtbl->Initialize(pThis, shareMode, streamFlags, bufferDuration, periodicity, pFormat, pAudioSessionGuid); }
static MA_INLINE HRESULT ma_IAudioClient3_GetBufferSize(ma_IAudioClient3* pThis, ma_uint32* pNumBufferFrames) { return pThis->lpVtbl->GetBufferSize(pThis, pNumBufferFrames); }
static MA_INLINE HRESULT ma_IAudioClient3_GetStreamLatency(ma_IAudioClient3* pThis, MA_REFERENCE_TIME* pLatency) { return pThis->lpVtbl->GetStreamLatency(pThis, pLatency); }
static MA_INLINE HRESULT ma_IAudioClient3_GetCurrentPadding(ma_IAudioClient3* pThis, ma_uint32* pNumPaddingFrames) { return pThis->lpVtbl->GetCurrentPadding(pThis, pNumPaddingFrames); }
-static MA_INLINE HRESULT ma_IAudioClient3_IsFormatSupported(ma_IAudioClient3* pThis, MA_AUDCLNT_SHAREMODE shareMode, const WAVEFORMATEX* pFormat, WAVEFORMATEX** ppClosestMatch) { return pThis->lpVtbl->IsFormatSupported(pThis, shareMode, pFormat, ppClosestMatch); }
-static MA_INLINE HRESULT ma_IAudioClient3_GetMixFormat(ma_IAudioClient3* pThis, WAVEFORMATEX** ppDeviceFormat) { return pThis->lpVtbl->GetMixFormat(pThis, ppDeviceFormat); }
+static MA_INLINE HRESULT ma_IAudioClient3_IsFormatSupported(ma_IAudioClient3* pThis, MA_AUDCLNT_SHAREMODE shareMode, const MA_WAVEFORMATEX* pFormat, MA_WAVEFORMATEX** ppClosestMatch) { return pThis->lpVtbl->IsFormatSupported(pThis, shareMode, pFormat, ppClosestMatch); }
+static MA_INLINE HRESULT ma_IAudioClient3_GetMixFormat(ma_IAudioClient3* pThis, MA_WAVEFORMATEX** ppDeviceFormat) { return pThis->lpVtbl->GetMixFormat(pThis, ppDeviceFormat); }
static MA_INLINE HRESULT ma_IAudioClient3_GetDevicePeriod(ma_IAudioClient3* pThis, MA_REFERENCE_TIME* pDefaultDevicePeriod, MA_REFERENCE_TIME* pMinimumDevicePeriod) { return pThis->lpVtbl->GetDevicePeriod(pThis, pDefaultDevicePeriod, pMinimumDevicePeriod); }
static MA_INLINE HRESULT ma_IAudioClient3_Start(ma_IAudioClient3* pThis) { return pThis->lpVtbl->Start(pThis); }
static MA_INLINE HRESULT ma_IAudioClient3_Stop(ma_IAudioClient3* pThis) { return pThis->lpVtbl->Stop(pThis); }
@@ -19768,10 +20604,10 @@ static MA_INLINE HRESULT ma_IAudioClient3_SetEventHandle(ma_IAudioClient3* pThis
static MA_INLINE HRESULT ma_IAudioClient3_GetService(ma_IAudioClient3* pThis, const IID* const riid, void** pp) { return pThis->lpVtbl->GetService(pThis, riid, pp); }
static MA_INLINE HRESULT ma_IAudioClient3_IsOffloadCapable(ma_IAudioClient3* pThis, MA_AUDIO_STREAM_CATEGORY category, BOOL* pOffloadCapable) { return pThis->lpVtbl->IsOffloadCapable(pThis, category, pOffloadCapable); }
static MA_INLINE HRESULT ma_IAudioClient3_SetClientProperties(ma_IAudioClient3* pThis, const ma_AudioClientProperties* pProperties) { return pThis->lpVtbl->SetClientProperties(pThis, pProperties); }
-static MA_INLINE HRESULT ma_IAudioClient3_GetBufferSizeLimits(ma_IAudioClient3* pThis, const WAVEFORMATEX* pFormat, BOOL eventDriven, MA_REFERENCE_TIME* pMinBufferDuration, MA_REFERENCE_TIME* pMaxBufferDuration) { return pThis->lpVtbl->GetBufferSizeLimits(pThis, pFormat, eventDriven, pMinBufferDuration, pMaxBufferDuration); }
-static MA_INLINE HRESULT ma_IAudioClient3_GetSharedModeEnginePeriod(ma_IAudioClient3* pThis, const WAVEFORMATEX* pFormat, ma_uint32* pDefaultPeriodInFrames, ma_uint32* pFundamentalPeriodInFrames, ma_uint32* pMinPeriodInFrames, ma_uint32* pMaxPeriodInFrames) { return pThis->lpVtbl->GetSharedModeEnginePeriod(pThis, pFormat, pDefaultPeriodInFrames, pFundamentalPeriodInFrames, pMinPeriodInFrames, pMaxPeriodInFrames); }
-static MA_INLINE HRESULT ma_IAudioClient3_GetCurrentSharedModeEnginePeriod(ma_IAudioClient3* pThis, WAVEFORMATEX** ppFormat, ma_uint32* pCurrentPeriodInFrames) { return pThis->lpVtbl->GetCurrentSharedModeEnginePeriod(pThis, ppFormat, pCurrentPeriodInFrames); }
-static MA_INLINE HRESULT ma_IAudioClient3_InitializeSharedAudioStream(ma_IAudioClient3* pThis, DWORD streamFlags, ma_uint32 periodInFrames, const WAVEFORMATEX* pFormat, const GUID* pAudioSessionGUID) { return pThis->lpVtbl->InitializeSharedAudioStream(pThis, streamFlags, periodInFrames, pFormat, pAudioSessionGUID); }
+static MA_INLINE HRESULT ma_IAudioClient3_GetBufferSizeLimits(ma_IAudioClient3* pThis, const MA_WAVEFORMATEX* pFormat, BOOL eventDriven, MA_REFERENCE_TIME* pMinBufferDuration, MA_REFERENCE_TIME* pMaxBufferDuration) { return pThis->lpVtbl->GetBufferSizeLimits(pThis, pFormat, eventDriven, pMinBufferDuration, pMaxBufferDuration); }
+static MA_INLINE HRESULT ma_IAudioClient3_GetSharedModeEnginePeriod(ma_IAudioClient3* pThis, const MA_WAVEFORMATEX* pFormat, ma_uint32* pDefaultPeriodInFrames, ma_uint32* pFundamentalPeriodInFrames, ma_uint32* pMinPeriodInFrames, ma_uint32* pMaxPeriodInFrames) { return pThis->lpVtbl->GetSharedModeEnginePeriod(pThis, pFormat, pDefaultPeriodInFrames, pFundamentalPeriodInFrames, pMinPeriodInFrames, pMaxPeriodInFrames); }
+static MA_INLINE HRESULT ma_IAudioClient3_GetCurrentSharedModeEnginePeriod(ma_IAudioClient3* pThis, MA_WAVEFORMATEX** ppFormat, ma_uint32* pCurrentPeriodInFrames) { return pThis->lpVtbl->GetCurrentSharedModeEnginePeriod(pThis, ppFormat, pCurrentPeriodInFrames); }
+static MA_INLINE HRESULT ma_IAudioClient3_InitializeSharedAudioStream(ma_IAudioClient3* pThis, DWORD streamFlags, ma_uint32 periodInFrames, const MA_WAVEFORMATEX* pFormat, const GUID* pAudioSessionGUID) { return pThis->lpVtbl->InitializeSharedAudioStream(pThis, streamFlags, periodInFrames, pFormat, pAudioSessionGUID); }
/* IAudioRenderClient */
@@ -19823,11 +20659,11 @@ static MA_INLINE HRESULT ma_IAudioCaptureClient_GetNextPacketSize(ma_IAudioCaptu
#if defined(MA_WIN32_UWP)
/* mmdevapi Functions */
-typedef HRESULT (WINAPI * MA_PFN_ActivateAudioInterfaceAsync)(LPCWSTR deviceInterfacePath, const IID* riid, PROPVARIANT *activationParams, ma_IActivateAudioInterfaceCompletionHandler *completionHandler, ma_IActivateAudioInterfaceAsyncOperation **activationOperation);
+typedef HRESULT (WINAPI * MA_PFN_ActivateAudioInterfaceAsync)(const wchar_t* deviceInterfacePath, const IID* riid, MA_PROPVARIANT* activationParams, ma_IActivateAudioInterfaceCompletionHandler* completionHandler, ma_IActivateAudioInterfaceAsyncOperation** activationOperation);
#endif
/* Avrt Functions */
-typedef HANDLE (WINAPI * MA_PFN_AvSetMmThreadCharacteristicsW)(LPCWSTR TaskName, LPDWORD TaskIndex);
+typedef HANDLE (WINAPI * MA_PFN_AvSetMmThreadCharacteristicsA)(const char* TaskName, DWORD* TaskIndex);
typedef BOOL (WINAPI * MA_PFN_AvRevertMmThreadCharacteristics)(HANDLE AvrtHandle);
#if !defined(MA_WIN32_DESKTOP) && !defined(MA_WIN32_GDK)
@@ -19869,12 +20705,12 @@ static HRESULT STDMETHODCALLTYPE ma_completion_handler_uwp_QueryInterface(ma_com
static ULONG STDMETHODCALLTYPE ma_completion_handler_uwp_AddRef(ma_completion_handler_uwp* pThis)
{
- return (ULONG)c89atomic_fetch_add_32(&pThis->counter, 1) + 1;
+ return (ULONG)ma_atomic_fetch_add_32(&pThis->counter, 1) + 1;
}
static ULONG STDMETHODCALLTYPE ma_completion_handler_uwp_Release(ma_completion_handler_uwp* pThis)
{
- ma_uint32 newRefCount = c89atomic_fetch_sub_32(&pThis->counter, 1) - 1;
+ ma_uint32 newRefCount = ma_atomic_fetch_sub_32(&pThis->counter, 1) - 1;
if (newRefCount == 0) {
return 0; /* We don't free anything here because we never allocate the object on the heap. */
}
@@ -19904,7 +20740,7 @@ static ma_result ma_completion_handler_uwp_init(ma_completion_handler_uwp* pHand
pHandler->lpVtbl = &g_maCompletionHandlerVtblInstance;
pHandler->counter = 1;
- pHandler->hEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
+ pHandler->hEvent = CreateEventA(NULL, FALSE, FALSE, NULL);
if (pHandler->hEvent == NULL) {
return ma_result_from_GetLastError(GetLastError());
}
@@ -19921,7 +20757,7 @@ static void ma_completion_handler_uwp_uninit(ma_completion_handler_uwp* pHandler
static void ma_completion_handler_uwp_wait(ma_completion_handler_uwp* pHandler)
{
- WaitForSingleObject(pHandler->hEvent, INFINITE);
+ WaitForSingleObject((HANDLE)pHandler->hEvent, INFINITE);
}
#endif /* !MA_WIN32_DESKTOP */
@@ -19946,12 +20782,12 @@ static HRESULT STDMETHODCALLTYPE ma_IMMNotificationClient_QueryInterface(ma_IMMN
static ULONG STDMETHODCALLTYPE ma_IMMNotificationClient_AddRef(ma_IMMNotificationClient* pThis)
{
- return (ULONG)c89atomic_fetch_add_32(&pThis->counter, 1) + 1;
+ return (ULONG)ma_atomic_fetch_add_32(&pThis->counter, 1) + 1;
}
static ULONG STDMETHODCALLTYPE ma_IMMNotificationClient_Release(ma_IMMNotificationClient* pThis)
{
- ma_uint32 newRefCount = c89atomic_fetch_sub_32(&pThis->counter, 1) - 1;
+ ma_uint32 newRefCount = ma_atomic_fetch_sub_32(&pThis->counter, 1) - 1;
if (newRefCount == 0) {
return 0; /* We don't free anything here because we never allocate the object on the heap. */
}
@@ -19959,7 +20795,7 @@ static ULONG STDMETHODCALLTYPE ma_IMMNotificationClient_Release(ma_IMMNotificati
return (ULONG)newRefCount;
}
-static HRESULT STDMETHODCALLTYPE ma_IMMNotificationClient_OnDeviceStateChanged(ma_IMMNotificationClient* pThis, LPCWSTR pDeviceID, DWORD dwNewState)
+static HRESULT STDMETHODCALLTYPE ma_IMMNotificationClient_OnDeviceStateChanged(ma_IMMNotificationClient* pThis, const WCHAR* pDeviceID, DWORD dwNewState)
{
ma_bool32 isThisDevice = MA_FALSE;
ma_bool32 isCapture = MA_FALSE;
@@ -19975,14 +20811,14 @@ static HRESULT STDMETHODCALLTYPE ma_IMMNotificationClient_OnDeviceStateChanged(m
*/
if (pThis->pDevice->wasapi.allowCaptureAutoStreamRouting && (pThis->pDevice->type == ma_device_type_capture || pThis->pDevice->type == ma_device_type_duplex || pThis->pDevice->type == ma_device_type_loopback)) {
isCapture = MA_TRUE;
- if (wcscmp(pThis->pDevice->capture.id.wasapi, pDeviceID) == 0) {
+ if (ma_strcmp_WCHAR(pThis->pDevice->capture.id.wasapi, pDeviceID) == 0) {
isThisDevice = MA_TRUE;
}
}
if (pThis->pDevice->wasapi.allowPlaybackAutoStreamRouting && (pThis->pDevice->type == ma_device_type_playback || pThis->pDevice->type == ma_device_type_duplex)) {
isPlayback = MA_TRUE;
- if (wcscmp(pThis->pDevice->playback.id.wasapi, pDeviceID) == 0) {
+ if (ma_strcmp_WCHAR(pThis->pDevice->playback.id.wasapi, pDeviceID) == 0) {
isThisDevice = MA_TRUE;
}
}
@@ -20043,7 +20879,7 @@ static HRESULT STDMETHODCALLTYPE ma_IMMNotificationClient_OnDeviceStateChanged(m
return S_OK;
}
-static HRESULT STDMETHODCALLTYPE ma_IMMNotificationClient_OnDeviceAdded(ma_IMMNotificationClient* pThis, LPCWSTR pDeviceID)
+static HRESULT STDMETHODCALLTYPE ma_IMMNotificationClient_OnDeviceAdded(ma_IMMNotificationClient* pThis, const WCHAR* pDeviceID)
{
#ifdef MA_DEBUG_OUTPUT
/*ma_log_postf(ma_device_get_log(pThis->pDevice), MA_LOG_LEVEL_DEBUG, "IMMNotificationClient_OnDeviceAdded(pDeviceID=%S)\n", (pDeviceID != NULL) ? pDeviceID : L"(NULL)");*/
@@ -20055,7 +20891,7 @@ static HRESULT STDMETHODCALLTYPE ma_IMMNotificationClient_OnDeviceAdded(ma_IMMNo
return S_OK;
}
-static HRESULT STDMETHODCALLTYPE ma_IMMNotificationClient_OnDeviceRemoved(ma_IMMNotificationClient* pThis, LPCWSTR pDeviceID)
+static HRESULT STDMETHODCALLTYPE ma_IMMNotificationClient_OnDeviceRemoved(ma_IMMNotificationClient* pThis, const WCHAR* pDeviceID)
{
#ifdef MA_DEBUG_OUTPUT
/*ma_log_postf(ma_device_get_log(pThis->pDevice), MA_LOG_LEVEL_DEBUG, "IMMNotificationClient_OnDeviceRemoved(pDeviceID=%S)\n", (pDeviceID != NULL) ? pDeviceID : L"(NULL)");*/
@@ -20067,25 +20903,27 @@ static HRESULT STDMETHODCALLTYPE ma_IMMNotificationClient_OnDeviceRemoved(ma_IMM
return S_OK;
}
-static HRESULT STDMETHODCALLTYPE ma_IMMNotificationClient_OnDefaultDeviceChanged(ma_IMMNotificationClient* pThis, ma_EDataFlow dataFlow, ma_ERole role, LPCWSTR pDefaultDeviceID)
+static HRESULT STDMETHODCALLTYPE ma_IMMNotificationClient_OnDefaultDeviceChanged(ma_IMMNotificationClient* pThis, ma_EDataFlow dataFlow, ma_ERole role, const WCHAR* pDefaultDeviceID)
{
#ifdef MA_DEBUG_OUTPUT
/*ma_log_postf(ma_device_get_log(pThis->pDevice), MA_LOG_LEVEL_DEBUG, "IMMNotificationClient_OnDefaultDeviceChanged(dataFlow=%d, role=%d, pDefaultDeviceID=%S)\n", dataFlow, role, (pDefaultDeviceID != NULL) ? pDefaultDeviceID : L"(NULL)");*/
#endif
- /* We only ever use the eConsole role in miniaudio. */
- if (role != ma_eConsole) {
- ma_log_postf(ma_device_get_log(pThis->pDevice), MA_LOG_LEVEL_DEBUG, "[WASAPI] Stream rerouting: role != eConsole\n");
- return S_OK;
- }
+ (void)role;
- /* We only care about devices with the same data flow and role as the current device. */
- if ((pThis->pDevice->type == ma_device_type_playback && dataFlow != ma_eRender) ||
- (pThis->pDevice->type == ma_device_type_capture && dataFlow != ma_eCapture)) {
+ /* We only care about devices with the same data flow as the current device. */
+ if ((pThis->pDevice->type == ma_device_type_playback && dataFlow != ma_eRender) ||
+ (pThis->pDevice->type == ma_device_type_capture && dataFlow != ma_eCapture) ||
+ (pThis->pDevice->type == ma_device_type_loopback && dataFlow != ma_eRender)) {
ma_log_postf(ma_device_get_log(pThis->pDevice), MA_LOG_LEVEL_DEBUG, "[WASAPI] Stream rerouting abandoned because dataFlow does match device type.\n");
return S_OK;
}
+ /* We need to consider dataFlow as ma_eCapture if device is ma_device_type_loopback */
+ if (pThis->pDevice->type == ma_device_type_loopback) {
+ dataFlow = ma_eCapture;
+ }
+
/* Don't do automatic stream routing if we're not allowed. */
if ((dataFlow == ma_eRender && pThis->pDevice->wasapi.allowPlaybackAutoStreamRouting == MA_FALSE) ||
(dataFlow == ma_eCapture && pThis->pDevice->wasapi.allowCaptureAutoStreamRouting == MA_FALSE)) {
@@ -20106,7 +20944,6 @@ static HRESULT STDMETHODCALLTYPE ma_IMMNotificationClient_OnDefaultDeviceChanged
-
/*
Second attempt at device rerouting. We're going to retrieve the device's state at the time of
the route change. We're then going to stop the device, reinitialize the device, and then start
@@ -20116,37 +20953,49 @@ static HRESULT STDMETHODCALLTYPE ma_IMMNotificationClient_OnDefaultDeviceChanged
ma_uint32 previousState = ma_device_get_state(pThis->pDevice);
ma_bool8 restartDevice = MA_FALSE;
+ if (previousState == ma_device_state_uninitialized || previousState == ma_device_state_starting) {
+ ma_log_postf(ma_device_get_log(pThis->pDevice), MA_LOG_LEVEL_DEBUG, "[WASAPI] Stream rerouting abandoned because the device is in the process of starting.\n");
+ return S_OK;
+ }
+
if (previousState == ma_device_state_started) {
ma_device_stop(pThis->pDevice);
restartDevice = MA_TRUE;
}
if (pDefaultDeviceID != NULL) { /* <-- The input device ID will be null if there's no other device available. */
- if (dataFlow == ma_eRender) {
- ma_device_reroute__wasapi(pThis->pDevice, ma_device_type_playback);
+ ma_mutex_lock(&pThis->pDevice->wasapi.rerouteLock);
+ {
+ if (dataFlow == ma_eRender) {
+ ma_device_reroute__wasapi(pThis->pDevice, ma_device_type_playback);
- if (pThis->pDevice->wasapi.isDetachedPlayback) {
- pThis->pDevice->wasapi.isDetachedPlayback = MA_FALSE;
+ if (pThis->pDevice->wasapi.isDetachedPlayback) {
+ pThis->pDevice->wasapi.isDetachedPlayback = MA_FALSE;
- if (pThis->pDevice->type == ma_device_type_duplex && pThis->pDevice->wasapi.isDetachedCapture) {
- restartDevice = MA_FALSE; /* It's a duplex device and the capture side is detached. We cannot be restarting the device just yet. */
- } else {
- restartDevice = MA_TRUE; /* It's not a duplex device, or the capture side is also attached so we can go ahead and restart the device. */
+ if (pThis->pDevice->type == ma_device_type_duplex && pThis->pDevice->wasapi.isDetachedCapture) {
+ restartDevice = MA_FALSE; /* It's a duplex device and the capture side is detached. We cannot be restarting the device just yet. */
+ }
+ else {
+ restartDevice = MA_TRUE; /* It's not a duplex device, or the capture side is also attached so we can go ahead and restart the device. */
+ }
}
}
- } else {
- ma_device_reroute__wasapi(pThis->pDevice, (pThis->pDevice->type == ma_device_type_loopback) ? ma_device_type_loopback : ma_device_type_capture);
+ else {
+ ma_device_reroute__wasapi(pThis->pDevice, (pThis->pDevice->type == ma_device_type_loopback) ? ma_device_type_loopback : ma_device_type_capture);
- if (pThis->pDevice->wasapi.isDetachedCapture) {
- pThis->pDevice->wasapi.isDetachedCapture = MA_FALSE;
+ if (pThis->pDevice->wasapi.isDetachedCapture) {
+ pThis->pDevice->wasapi.isDetachedCapture = MA_FALSE;
- if (pThis->pDevice->type == ma_device_type_duplex && pThis->pDevice->wasapi.isDetachedPlayback) {
- restartDevice = MA_FALSE; /* It's a duplex device and the playback side is detached. We cannot be restarting the device just yet. */
- } else {
- restartDevice = MA_TRUE; /* It's not a duplex device, or the playback side is also attached so we can go ahead and restart the device. */
+ if (pThis->pDevice->type == ma_device_type_duplex && pThis->pDevice->wasapi.isDetachedPlayback) {
+ restartDevice = MA_FALSE; /* It's a duplex device and the playback side is detached. We cannot be restarting the device just yet. */
+ }
+ else {
+ restartDevice = MA_TRUE; /* It's not a duplex device, or the playback side is also attached so we can go ahead and restart the device. */
+ }
}
}
}
+ ma_mutex_unlock(&pThis->pDevice->wasapi.rerouteLock);
if (restartDevice) {
ma_device_start(pThis->pDevice);
@@ -20157,7 +21006,7 @@ static HRESULT STDMETHODCALLTYPE ma_IMMNotificationClient_OnDefaultDeviceChanged
return S_OK;
}
-static HRESULT STDMETHODCALLTYPE ma_IMMNotificationClient_OnPropertyValueChanged(ma_IMMNotificationClient* pThis, LPCWSTR pDeviceID, const PROPERTYKEY key)
+static HRESULT STDMETHODCALLTYPE ma_IMMNotificationClient_OnPropertyValueChanged(ma_IMMNotificationClient* pThis, const WCHAR* pDeviceID, const PROPERTYKEY key)
{
#ifdef MA_DEBUG_OUTPUT
/*ma_log_postf(ma_device_get_log(pThis->pDevice), MA_LOG_LEVEL_DEBUG, "IMMNotificationClient_OnPropertyValueChanged(pDeviceID=%S)\n", (pDeviceID != NULL) ? pDeviceID : L"(NULL)");*/
@@ -20181,12 +21030,13 @@ static ma_IMMNotificationClientVtbl g_maNotificationCientVtbl = {
};
#endif /* MA_WIN32_DESKTOP */
-static LPCWSTR ma_to_usage_string__wasapi(ma_wasapi_usage usage)
+static const char* ma_to_usage_string__wasapi(ma_wasapi_usage usage)
{
- switch (usage) {
+ switch (usage)
+ {
case ma_wasapi_usage_default: return NULL;
- case ma_wasapi_usage_games: return L"Games";
- case ma_wasapi_usage_pro_audio: return L"Pro Audio";
+ case ma_wasapi_usage_games: return "Games";
+ case ma_wasapi_usage_pro_audio: return "Pro Audio";
default: break;
}
@@ -20384,7 +21234,7 @@ static ma_result ma_device_release_IAudioClient_service__wasapi(ma_device* pDevi
#endif
-static void ma_add_native_data_format_to_device_info_from_WAVEFORMATEX(const WAVEFORMATEX* pWF, ma_share_mode shareMode, ma_device_info* pInfo)
+static void ma_add_native_data_format_to_device_info_from_WAVEFORMATEX(const MA_WAVEFORMATEX* pWF, ma_share_mode shareMode, ma_device_info* pInfo)
{
MA_ASSERT(pWF != NULL);
MA_ASSERT(pInfo != NULL);
@@ -20403,13 +21253,13 @@ static void ma_add_native_data_format_to_device_info_from_WAVEFORMATEX(const WAV
static ma_result ma_context_get_device_info_from_IAudioClient__wasapi(ma_context* pContext, /*ma_IMMDevice**/void* pMMDevice, ma_IAudioClient* pAudioClient, ma_device_info* pInfo)
{
HRESULT hr;
- WAVEFORMATEX* pWF = NULL;
+ MA_WAVEFORMATEX* pWF = NULL;
MA_ASSERT(pAudioClient != NULL);
MA_ASSERT(pInfo != NULL);
/* Shared Mode. We use GetMixFormat() here. */
- hr = ma_IAudioClient_GetMixFormat((ma_IAudioClient*)pAudioClient, (WAVEFORMATEX**)&pWF);
+ hr = ma_IAudioClient_GetMixFormat((ma_IAudioClient*)pAudioClient, (MA_WAVEFORMATEX**)&pWF);
if (SUCCEEDED(hr)) {
ma_add_native_data_format_to_device_info_from_WAVEFORMATEX(pWF, ma_share_mode_shared, pInfo);
} else {
@@ -20432,12 +21282,12 @@ static ma_result ma_context_get_device_info_from_IAudioClient__wasapi(ma_context
*/
hr = ma_IMMDevice_OpenPropertyStore((ma_IMMDevice*)pMMDevice, STGM_READ, &pProperties);
if (SUCCEEDED(hr)) {
- PROPVARIANT var;
+ MA_PROPVARIANT var;
ma_PropVariantInit(&var);
hr = ma_IPropertyStore_GetValue(pProperties, &MA_PKEY_AudioEngine_DeviceFormat, &var);
if (SUCCEEDED(hr)) {
- pWF = (WAVEFORMATEX*)var.blob.pBlobData;
+ pWF = (MA_WAVEFORMATEX*)var.blob.pBlobData;
/*
In my testing, the format returned by PKEY_AudioEngine_DeviceFormat is suitable for exclusive mode so we check this format
@@ -20454,7 +21304,7 @@ static ma_result ma_context_get_device_info_from_IAudioClient__wasapi(ma_context
*/
ma_uint32 channels = pWF->nChannels;
ma_channel defaultChannelMap[MA_MAX_CHANNELS];
- WAVEFORMATEXTENSIBLE wf;
+ MA_WAVEFORMATEXTENSIBLE wf;
ma_bool32 found;
ma_uint32 iFormat;
@@ -20466,9 +21316,9 @@ static ma_result ma_context_get_device_info_from_IAudioClient__wasapi(ma_context
ma_channel_map_init_standard(ma_standard_channel_map_microsoft, defaultChannelMap, ma_countof(defaultChannelMap), channels);
MA_ZERO_OBJECT(&wf);
- wf.Format.cbSize = sizeof(wf);
- wf.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
- wf.Format.nChannels = (WORD)channels;
+ wf.cbSize = sizeof(wf);
+ wf.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
+ wf.nChannels = (WORD)channels;
wf.dwChannelMask = ma_channel_map_to_channel_mask__win32(defaultChannelMap, channels);
found = MA_FALSE;
@@ -20476,10 +21326,10 @@ static ma_result ma_context_get_device_info_from_IAudioClient__wasapi(ma_context
ma_format format = g_maFormatPriorities[iFormat];
ma_uint32 iSampleRate;
- wf.Format.wBitsPerSample = (WORD)(ma_get_bytes_per_sample(format)*8);
- wf.Format.nBlockAlign = (WORD)(wf.Format.nChannels * wf.Format.wBitsPerSample / 8);
- wf.Format.nAvgBytesPerSec = wf.Format.nBlockAlign * wf.Format.nSamplesPerSec;
- wf.Samples.wValidBitsPerSample = /*(format == ma_format_s24_32) ? 24 :*/ wf.Format.wBitsPerSample;
+ wf.wBitsPerSample = (WORD)(ma_get_bytes_per_sample(format)*8);
+ wf.nBlockAlign = (WORD)(wf.nChannels * wf.wBitsPerSample / 8);
+ wf.nAvgBytesPerSec = wf.nBlockAlign * wf.nSamplesPerSec;
+ wf.Samples.wValidBitsPerSample = /*(format == ma_format_s24_32) ? 24 :*/ wf.wBitsPerSample;
if (format == ma_format_f32) {
wf.SubFormat = MA_GUID_KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
} else {
@@ -20487,11 +21337,11 @@ static ma_result ma_context_get_device_info_from_IAudioClient__wasapi(ma_context
}
for (iSampleRate = 0; iSampleRate < ma_countof(g_maStandardSampleRatePriorities); ++iSampleRate) {
- wf.Format.nSamplesPerSec = g_maStandardSampleRatePriorities[iSampleRate];
+ wf.nSamplesPerSec = g_maStandardSampleRatePriorities[iSampleRate];
- hr = ma_IAudioClient_IsFormatSupported((ma_IAudioClient*)pAudioClient, MA_AUDCLNT_SHAREMODE_EXCLUSIVE, (WAVEFORMATEX*)&wf, NULL);
+ hr = ma_IAudioClient_IsFormatSupported((ma_IAudioClient*)pAudioClient, MA_AUDCLNT_SHAREMODE_EXCLUSIVE, (MA_WAVEFORMATEX*)&wf, NULL);
if (SUCCEEDED(hr)) {
- ma_add_native_data_format_to_device_info_from_WAVEFORMATEX((WAVEFORMATEX*)&wf, ma_share_mode_exclusive, pInfo);
+ ma_add_native_data_format_to_device_info_from_WAVEFORMATEX((MA_WAVEFORMATEX*)&wf, ma_share_mode_exclusive, pInfo);
found = MA_TRUE;
break;
}
@@ -20549,7 +21399,7 @@ static ma_result ma_context_create_IMMDeviceEnumerator__wasapi(ma_context* pCont
*ppDeviceEnumerator = NULL; /* Safety. */
- hr = ma_CoCreateInstance(pContext, MA_CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, MA_IID_IMMDeviceEnumerator, (void**)&pDeviceEnumerator);
+ hr = ma_CoCreateInstance(pContext, &MA_CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, &MA_IID_IMMDeviceEnumerator, (void**)&pDeviceEnumerator);
if (FAILED(hr)) {
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to create device enumerator.");
return ma_result_from_HRESULT(hr);
@@ -20560,11 +21410,11 @@ static ma_result ma_context_create_IMMDeviceEnumerator__wasapi(ma_context* pCont
return MA_SUCCESS;
}
-static LPWSTR ma_context_get_default_device_id_from_IMMDeviceEnumerator__wasapi(ma_context* pContext, ma_IMMDeviceEnumerator* pDeviceEnumerator, ma_device_type deviceType)
+static WCHAR* ma_context_get_default_device_id_from_IMMDeviceEnumerator__wasapi(ma_context* pContext, ma_IMMDeviceEnumerator* pDeviceEnumerator, ma_device_type deviceType)
{
HRESULT hr;
ma_IMMDevice* pMMDefaultDevice = NULL;
- LPWSTR pDefaultDeviceID = NULL;
+ WCHAR* pDefaultDeviceID = NULL;
ma_EDataFlow dataFlow;
ma_ERole role;
@@ -20596,11 +21446,11 @@ static LPWSTR ma_context_get_default_device_id_from_IMMDeviceEnumerator__wasapi(
return pDefaultDeviceID;
}
-static LPWSTR ma_context_get_default_device_id__wasapi(ma_context* pContext, ma_device_type deviceType) /* Free the returned pointer with ma_CoTaskMemFree() */
+static WCHAR* ma_context_get_default_device_id__wasapi(ma_context* pContext, ma_device_type deviceType) /* Free the returned pointer with ma_CoTaskMemFree() */
{
ma_result result;
ma_IMMDeviceEnumerator* pDeviceEnumerator;
- LPWSTR pDefaultDeviceID = NULL;
+ WCHAR* pDefaultDeviceID = NULL;
MA_ASSERT(pContext != NULL);
@@ -20623,7 +21473,7 @@ static ma_result ma_context_get_MMDevice__wasapi(ma_context* pContext, ma_device
MA_ASSERT(pContext != NULL);
MA_ASSERT(ppMMDevice != NULL);
- hr = ma_CoCreateInstance(pContext, MA_CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, MA_IID_IMMDeviceEnumerator, (void**)&pDeviceEnumerator);
+ hr = ma_CoCreateInstance(pContext, &MA_CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, &MA_IID_IMMDeviceEnumerator, (void**)&pDeviceEnumerator);
if (FAILED(hr)) {
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to create IMMDeviceEnumerator.\n");
return ma_result_from_HRESULT(hr);
@@ -20646,14 +21496,14 @@ static ma_result ma_context_get_MMDevice__wasapi(ma_context* pContext, ma_device
static ma_result ma_context_get_device_id_from_MMDevice__wasapi(ma_context* pContext, ma_IMMDevice* pMMDevice, ma_device_id* pDeviceID)
{
- LPWSTR pDeviceIDString;
+ WCHAR* pDeviceIDString;
HRESULT hr;
MA_ASSERT(pDeviceID != NULL);
hr = ma_IMMDevice_GetId(pMMDevice, &pDeviceIDString);
if (SUCCEEDED(hr)) {
- size_t idlen = wcslen(pDeviceIDString);
+ size_t idlen = ma_strlen_WCHAR(pDeviceIDString);
if (idlen+1 > ma_countof(pDeviceID->wasapi)) {
ma_CoTaskMemFree(pContext, pDeviceIDString);
MA_ASSERT(MA_FALSE); /* NOTE: If this is triggered, please report it. It means the format of the ID must haved change and is too long to fit in our fixed sized buffer. */
@@ -20671,7 +21521,7 @@ static ma_result ma_context_get_device_id_from_MMDevice__wasapi(ma_context* pCon
return MA_ERROR;
}
-static ma_result ma_context_get_device_info_from_MMDevice__wasapi(ma_context* pContext, ma_IMMDevice* pMMDevice, LPWSTR pDefaultDeviceID, ma_bool32 onlySimpleInfo, ma_device_info* pInfo)
+static ma_result ma_context_get_device_info_from_MMDevice__wasapi(ma_context* pContext, ma_IMMDevice* pMMDevice, WCHAR* pDefaultDeviceID, ma_bool32 onlySimpleInfo, ma_device_info* pInfo)
{
ma_result result;
HRESULT hr;
@@ -20684,7 +21534,7 @@ static ma_result ma_context_get_device_info_from_MMDevice__wasapi(ma_context* pC
result = ma_context_get_device_id_from_MMDevice__wasapi(pContext, pMMDevice, &pInfo->id);
if (result == MA_SUCCESS) {
if (pDefaultDeviceID != NULL) {
- if (wcscmp(pInfo->id.wasapi, pDefaultDeviceID) == 0) {
+ if (ma_strcmp_WCHAR(pInfo->id.wasapi, pDefaultDeviceID) == 0) {
pInfo->isDefault = MA_TRUE;
}
}
@@ -20695,7 +21545,7 @@ static ma_result ma_context_get_device_info_from_MMDevice__wasapi(ma_context* pC
ma_IPropertyStore *pProperties;
hr = ma_IMMDevice_OpenPropertyStore(pMMDevice, STGM_READ, &pProperties);
if (SUCCEEDED(hr)) {
- PROPVARIANT var;
+ MA_PROPVARIANT var;
ma_PropVariantInit(&var);
hr = ma_IPropertyStore_GetValue(pProperties, &MA_PKEY_Device_FriendlyName, &var);
@@ -20732,7 +21582,7 @@ static ma_result ma_context_enumerate_devices_by_type__wasapi(ma_context* pConte
UINT deviceCount;
HRESULT hr;
ma_uint32 iDevice;
- LPWSTR pDefaultDeviceID = NULL;
+ WCHAR* pDefaultDeviceID = NULL;
ma_IMMDeviceCollection* pDeviceCollection = NULL;
MA_ASSERT(pContext != NULL);
@@ -20786,7 +21636,7 @@ static ma_result ma_context_enumerate_devices_by_type__wasapi(ma_context* pConte
return result;
}
-static ma_result ma_context_get_IAudioClient_Desktop__wasapi(ma_context* pContext, ma_device_type deviceType, const ma_device_id* pDeviceID, PROPVARIANT* pActivationParams, ma_IAudioClient** ppAudioClient, ma_IMMDevice** ppMMDevice)
+static ma_result ma_context_get_IAudioClient_Desktop__wasapi(ma_context* pContext, ma_device_type deviceType, const ma_device_id* pDeviceID, MA_PROPVARIANT* pActivationParams, ma_IAudioClient** ppAudioClient, ma_IMMDevice** ppMMDevice)
{
ma_result result;
HRESULT hr;
@@ -20808,12 +21658,12 @@ static ma_result ma_context_get_IAudioClient_Desktop__wasapi(ma_context* pContex
return MA_SUCCESS;
}
#else
-static ma_result ma_context_get_IAudioClient_UWP__wasapi(ma_context* pContext, ma_device_type deviceType, const ma_device_id* pDeviceID, PROPVARIANT* pActivationParams, ma_IAudioClient** ppAudioClient, ma_IUnknown** ppActivatedInterface)
+static ma_result ma_context_get_IAudioClient_UWP__wasapi(ma_context* pContext, ma_device_type deviceType, const ma_device_id* pDeviceID, MA_PROPVARIANT* pActivationParams, ma_IAudioClient** ppAudioClient, ma_IUnknown** ppActivatedInterface)
{
ma_IActivateAudioInterfaceAsyncOperation *pAsyncOp = NULL;
ma_completion_handler_uwp completionHandler;
IID iid;
- LPOLESTR iidStr;
+ WCHAR* iidStr;
HRESULT hr;
ma_result result;
HRESULT activateResult;
@@ -20823,7 +21673,7 @@ static ma_result ma_context_get_IAudioClient_UWP__wasapi(ma_context* pContext, m
MA_ASSERT(ppAudioClient != NULL);
if (pDeviceID != NULL) {
- iidStr = (LPOLESTR)pDeviceID->wasapi;
+ iidStr = (WCHAR*)pDeviceID->wasapi;
} else {
if (deviceType == ma_device_type_capture) {
iid = MA_IID_DEVINTERFACE_AUDIO_CAPTURE;
@@ -20944,8 +21794,8 @@ static ma_result ma_context_get_IAudioClient__wasapi(ma_context* pContext, ma_de
ma_result result;
ma_bool32 usingProcessLoopback = MA_FALSE;
MA_AUDIOCLIENT_ACTIVATION_PARAMS audioclientActivationParams;
- PROPVARIANT activationParams;
- PROPVARIANT* pActivationParams = NULL;
+ MA_PROPVARIANT activationParams;
+ MA_PROPVARIANT* pActivationParams = NULL;
ma_device_id virtualDeviceID;
/* Activation parameters specific to loopback mode. Note that process-specific loopback will only work when a default device ID is specified. */
@@ -20960,7 +21810,7 @@ static ma_result ma_context_get_IAudioClient__wasapi(ma_context* pContext, ma_de
audioclientActivationParams.ProcessLoopbackParams.TargetProcessId = (DWORD)loopbackProcessID;
ma_PropVariantInit(&activationParams);
- activationParams.vt = VT_BLOB;
+ activationParams.vt = MA_VT_BLOB;
activationParams.blob.cbSize = sizeof(audioclientActivationParams);
activationParams.blob.pBlobData = (BYTE*)&audioclientActivationParams;
pActivationParams = &activationParams;
@@ -21001,7 +21851,7 @@ static ma_result ma_context_enumerate_devices__wasapi(ma_context* pContext, ma_e
HRESULT hr;
ma_IMMDeviceEnumerator* pDeviceEnumerator;
- hr = ma_CoCreateInstance(pContext, MA_CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, MA_IID_IMMDeviceEnumerator, (void**)&pDeviceEnumerator);
+ hr = ma_CoCreateInstance(pContext, &MA_CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, &MA_IID_IMMDeviceEnumerator, (void**)&pDeviceEnumerator);
if (FAILED(hr)) {
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to create device enumerator.");
return ma_result_from_HRESULT(hr);
@@ -21051,7 +21901,7 @@ static ma_result ma_context_get_device_info__wasapi(ma_context* pContext, ma_dev
#if defined(MA_WIN32_DESKTOP) || defined(MA_WIN32_GDK)
ma_result result;
ma_IMMDevice* pMMDevice = NULL;
- LPWSTR pDefaultDeviceID = NULL;
+ WCHAR* pDefaultDeviceID = NULL;
result = ma_context_get_MMDevice__wasapi(pContext, deviceType, pDeviceID, &pMMDevice);
if (result != MA_SUCCESS) {
@@ -21136,10 +21986,10 @@ static ma_result ma_device_uninit__wasapi(ma_device* pDevice)
}
if (pDevice->wasapi.hEventPlayback) {
- CloseHandle(pDevice->wasapi.hEventPlayback);
+ CloseHandle((HANDLE)pDevice->wasapi.hEventPlayback);
}
if (pDevice->wasapi.hEventCapture) {
- CloseHandle(pDevice->wasapi.hEventCapture);
+ CloseHandle((HANDLE)pDevice->wasapi.hEventCapture);
}
return MA_SUCCESS;
@@ -21188,10 +22038,11 @@ static ma_result ma_device_init_internal__wasapi(ma_context* pContext, ma_device
DWORD streamFlags = 0;
MA_REFERENCE_TIME periodDurationInMicroseconds;
ma_bool32 wasInitializedUsingIAudioClient3 = MA_FALSE;
- WAVEFORMATEXTENSIBLE wf;
+ MA_WAVEFORMATEXTENSIBLE wf;
ma_WASAPIDeviceInterface* pDeviceInterface = NULL;
ma_IAudioClient2* pAudioClient2;
ma_uint32 nativeSampleRate;
+ ma_bool32 usingProcessLoopback = MA_FALSE;
MA_ASSERT(pContext != NULL);
MA_ASSERT(pData != NULL);
@@ -21201,6 +22052,8 @@ static ma_result ma_device_init_internal__wasapi(ma_context* pContext, ma_device
return MA_INVALID_ARGS;
}
+ usingProcessLoopback = deviceType == ma_device_type_loopback && pData->loopbackProcessID != 0 && pDeviceID == NULL;
+
pData->pAudioClient = NULL;
pData->pRenderClient = NULL;
pData->pCaptureClient = NULL;
@@ -21250,14 +22103,14 @@ static ma_result ma_device_init_internal__wasapi(ma_context* pContext, ma_device
ma_IPropertyStore* pStore = NULL;
hr = ma_IMMDevice_OpenPropertyStore(pDeviceInterface, STGM_READ, &pStore);
if (SUCCEEDED(hr)) {
- PROPVARIANT prop;
+ MA_PROPVARIANT prop;
ma_PropVariantInit(&prop);
hr = ma_IPropertyStore_GetValue(pStore, &MA_PKEY_AudioEngine_DeviceFormat, &prop);
if (SUCCEEDED(hr)) {
- WAVEFORMATEX* pActualFormat = (WAVEFORMATEX*)prop.blob.pBlobData;
+ MA_WAVEFORMATEX* pActualFormat = (MA_WAVEFORMATEX*)prop.blob.pBlobData;
hr = ma_IAudioClient_IsFormatSupported((ma_IAudioClient*)pData->pAudioClient, MA_AUDCLNT_SHAREMODE_EXCLUSIVE, pActualFormat, NULL);
if (SUCCEEDED(hr)) {
- MA_COPY_MEMORY(&wf, pActualFormat, sizeof(WAVEFORMATEXTENSIBLE));
+ MA_COPY_MEMORY(&wf, pActualFormat, sizeof(MA_WAVEFORMATEXTENSIBLE));
}
ma_PropVariantClear(pContext, &prop);
@@ -21284,12 +22137,47 @@ static ma_result ma_device_init_internal__wasapi(ma_context* pContext, ma_device
}
} else {
/* In shared mode we are always using the format reported by the operating system. */
- WAVEFORMATEXTENSIBLE* pNativeFormat = NULL;
- hr = ma_IAudioClient_GetMixFormat((ma_IAudioClient*)pData->pAudioClient, (WAVEFORMATEX**)&pNativeFormat);
+ MA_WAVEFORMATEXTENSIBLE* pNativeFormat = NULL;
+ hr = ma_IAudioClient_GetMixFormat((ma_IAudioClient*)pData->pAudioClient, (MA_WAVEFORMATEX**)&pNativeFormat);
if (hr != S_OK) {
- result = MA_FORMAT_NOT_SUPPORTED;
+ /* When using process-specific loopback, GetMixFormat() seems to always fail. */
+ if (usingProcessLoopback) {
+ wf.wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
+ wf.nChannels = 2;
+ wf.nSamplesPerSec = 44100;
+ wf.wBitsPerSample = 32;
+ wf.nBlockAlign = wf.nChannels * wf.wBitsPerSample / 8;
+ wf.nAvgBytesPerSec = wf.nSamplesPerSec * wf.nBlockAlign;
+ wf.cbSize = sizeof(MA_WAVEFORMATEX);
+
+ result = MA_SUCCESS;
+ } else {
+ result = MA_FORMAT_NOT_SUPPORTED;
+ }
} else {
- MA_COPY_MEMORY(&wf, pNativeFormat, sizeof(wf));
+ /*
+ I've seen cases where cbSize will be set to sizeof(WAVEFORMATEX) even though the structure itself
+ is given the format tag of WAVE_FORMAT_EXTENSIBLE. If the format tag is WAVE_FORMAT_EXTENSIBLE
+ want to make sure we copy the whole WAVEFORMATEXTENSIBLE structure. Otherwise we'll have to be
+ safe and only copy the WAVEFORMATEX part.
+ */
+ if (pNativeFormat->wFormatTag == WAVE_FORMAT_EXTENSIBLE) {
+ MA_COPY_MEMORY(&wf, pNativeFormat, sizeof(MA_WAVEFORMATEXTENSIBLE));
+ } else {
+ /* I've seen a case where cbSize was set to 0. Assume sizeof(WAVEFORMATEX) in this case. */
+ size_t cbSize = pNativeFormat->cbSize;
+ if (cbSize == 0) {
+ cbSize = sizeof(MA_WAVEFORMATEX);
+ }
+
+ /* Make sure we don't copy more than the capacity of `wf`. */
+ if (cbSize > sizeof(wf)) {
+ cbSize = sizeof(wf);
+ }
+
+ MA_COPY_MEMORY(&wf, pNativeFormat, cbSize);
+ }
+
result = MA_SUCCESS;
}
@@ -21308,13 +22196,13 @@ static ma_result ma_device_init_internal__wasapi(ma_context* pContext, ma_device
Override the native sample rate with the one requested by the caller, but only if we're not using the default sample rate. We'll use
WASAPI to perform the sample rate conversion.
*/
- nativeSampleRate = wf.Format.nSamplesPerSec;
+ nativeSampleRate = wf.nSamplesPerSec;
if (streamFlags & MA_AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM) {
- wf.Format.nSamplesPerSec = (pData->sampleRateIn != 0) ? pData->sampleRateIn : MA_DEFAULT_SAMPLE_RATE;
- wf.Format.nAvgBytesPerSec = wf.Format.nSamplesPerSec * wf.Format.nBlockAlign;
+ wf.nSamplesPerSec = (pData->sampleRateIn != 0) ? pData->sampleRateIn : MA_DEFAULT_SAMPLE_RATE;
+ wf.nAvgBytesPerSec = wf.nSamplesPerSec * wf.nBlockAlign;
}
- pData->formatOut = ma_format_from_WAVEFORMATEX((WAVEFORMATEX*)&wf);
+ pData->formatOut = ma_format_from_WAVEFORMATEX((MA_WAVEFORMATEX*)&wf);
if (pData->formatOut == ma_format_unknown) {
/*
The format isn't supported. This is almost certainly because the exclusive mode format isn't supported by miniaudio. We need to return MA_SHARE_MODE_NOT_SUPPORTED
@@ -21331,11 +22219,19 @@ static ma_result ma_device_init_internal__wasapi(ma_context* pContext, ma_device
goto done;
}
- pData->channelsOut = wf.Format.nChannels;
- pData->sampleRateOut = wf.Format.nSamplesPerSec;
+ pData->channelsOut = wf.nChannels;
+ pData->sampleRateOut = wf.nSamplesPerSec;
- /* Get the internal channel map based on the channel mask. */
- ma_channel_mask_to_channel_map__win32(wf.dwChannelMask, pData->channelsOut, pData->channelMapOut);
+ /*
+ Get the internal channel map based on the channel mask. There is a possibility that GetMixFormat() returns
+ a WAVEFORMATEX instead of a WAVEFORMATEXTENSIBLE, in which case the channel mask will be undefined. In this
+ case we'll just use the default channel map.
+ */
+ if (wf.wFormatTag == WAVE_FORMAT_EXTENSIBLE || wf.cbSize >= sizeof(MA_WAVEFORMATEXTENSIBLE)) {
+ ma_channel_mask_to_channel_map__win32(wf.dwChannelMask, pData->channelsOut, pData->channelMapOut);
+ } else {
+ ma_channel_map_init_standard(ma_standard_channel_map_microsoft, pData->channelMapOut, ma_countof(pData->channelMapOut), pData->channelsOut);
+ }
/* Period size. */
pData->periodsOut = (pData->periodsIn != 0) ? pData->periodsIn : MA_DEFAULT_PERIODS;
@@ -21343,16 +22239,16 @@ static ma_result ma_device_init_internal__wasapi(ma_context* pContext, ma_device
if (pData->periodSizeInFramesOut == 0) {
if (pData->periodSizeInMillisecondsIn == 0) {
if (pData->performanceProfile == ma_performance_profile_low_latency) {
- pData->periodSizeInFramesOut = ma_calculate_buffer_size_in_frames_from_milliseconds(MA_DEFAULT_PERIOD_SIZE_IN_MILLISECONDS_LOW_LATENCY, wf.Format.nSamplesPerSec);
+ pData->periodSizeInFramesOut = ma_calculate_buffer_size_in_frames_from_milliseconds(MA_DEFAULT_PERIOD_SIZE_IN_MILLISECONDS_LOW_LATENCY, wf.nSamplesPerSec);
} else {
- pData->periodSizeInFramesOut = ma_calculate_buffer_size_in_frames_from_milliseconds(MA_DEFAULT_PERIOD_SIZE_IN_MILLISECONDS_CONSERVATIVE, wf.Format.nSamplesPerSec);
+ pData->periodSizeInFramesOut = ma_calculate_buffer_size_in_frames_from_milliseconds(MA_DEFAULT_PERIOD_SIZE_IN_MILLISECONDS_CONSERVATIVE, wf.nSamplesPerSec);
}
} else {
- pData->periodSizeInFramesOut = ma_calculate_buffer_size_in_frames_from_milliseconds(pData->periodSizeInMillisecondsIn, wf.Format.nSamplesPerSec);
+ pData->periodSizeInFramesOut = ma_calculate_buffer_size_in_frames_from_milliseconds(pData->periodSizeInMillisecondsIn, wf.nSamplesPerSec);
}
}
- periodDurationInMicroseconds = ((ma_uint64)pData->periodSizeInFramesOut * 1000 * 1000) / wf.Format.nSamplesPerSec;
+ periodDurationInMicroseconds = ((ma_uint64)pData->periodSizeInFramesOut * 1000 * 1000) / wf.nSamplesPerSec;
/* Slightly different initialization for shared and exclusive modes. We try exclusive mode first, and if it fails, fall back to shared mode. */
@@ -21365,7 +22261,7 @@ static ma_result ma_device_init_internal__wasapi(ma_context* pContext, ma_device
*/
hr = E_FAIL;
for (;;) {
- hr = ma_IAudioClient_Initialize((ma_IAudioClient*)pData->pAudioClient, shareMode, streamFlags, bufferDuration, bufferDuration, (WAVEFORMATEX*)&wf, NULL);
+ hr = ma_IAudioClient_Initialize((ma_IAudioClient*)pData->pAudioClient, shareMode, streamFlags, bufferDuration, bufferDuration, (MA_WAVEFORMATEX*)&wf, NULL);
if (hr == MA_AUDCLNT_E_INVALID_DEVICE_PERIOD) {
if (bufferDuration > 500*10000) {
break;
@@ -21386,7 +22282,7 @@ static ma_result ma_device_init_internal__wasapi(ma_context* pContext, ma_device
ma_uint32 bufferSizeInFrames;
hr = ma_IAudioClient_GetBufferSize((ma_IAudioClient*)pData->pAudioClient, &bufferSizeInFrames);
if (SUCCEEDED(hr)) {
- bufferDuration = (MA_REFERENCE_TIME)((10000.0 * 1000 / wf.Format.nSamplesPerSec * bufferSizeInFrames) + 0.5);
+ bufferDuration = (MA_REFERENCE_TIME)((10000.0 * 1000 / wf.nSamplesPerSec * bufferSizeInFrames) + 0.5);
/* Unfortunately we need to release and re-acquire the audio client according to MSDN. Seems silly - why not just call IAudioClient_Initialize() again?! */
ma_IAudioClient_Release((ma_IAudioClient*)pData->pAudioClient);
@@ -21398,7 +22294,7 @@ static ma_result ma_device_init_internal__wasapi(ma_context* pContext, ma_device
#endif
if (SUCCEEDED(hr)) {
- hr = ma_IAudioClient_Initialize((ma_IAudioClient*)pData->pAudioClient, shareMode, streamFlags, bufferDuration, bufferDuration, (WAVEFORMATEX*)&wf, NULL);
+ hr = ma_IAudioClient_Initialize((ma_IAudioClient*)pData->pAudioClient, shareMode, streamFlags, bufferDuration, bufferDuration, (MA_WAVEFORMATEX*)&wf, NULL);
}
}
}
@@ -21429,7 +22325,7 @@ static ma_result ma_device_init_internal__wasapi(ma_context* pContext, ma_device
*/
#ifndef MA_WASAPI_NO_LOW_LATENCY_SHARED_MODE
{
- if ((streamFlags & MA_AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM) == 0 || nativeSampleRate == wf.Format.nSamplesPerSec) {
+ if ((streamFlags & MA_AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM) == 0 || nativeSampleRate == wf.nSamplesPerSec) {
ma_IAudioClient3* pAudioClient3 = NULL;
hr = ma_IAudioClient_QueryInterface(pData->pAudioClient, &MA_IID_IAudioClient3, (void**)&pAudioClient3);
if (SUCCEEDED(hr)) {
@@ -21437,7 +22333,7 @@ static ma_result ma_device_init_internal__wasapi(ma_context* pContext, ma_device
ma_uint32 fundamentalPeriodInFrames;
ma_uint32 minPeriodInFrames;
ma_uint32 maxPeriodInFrames;
- hr = ma_IAudioClient3_GetSharedModeEnginePeriod(pAudioClient3, (WAVEFORMATEX*)&wf, &defaultPeriodInFrames, &fundamentalPeriodInFrames, &minPeriodInFrames, &maxPeriodInFrames);
+ hr = ma_IAudioClient3_GetSharedModeEnginePeriod(pAudioClient3, (MA_WAVEFORMATEX*)&wf, &defaultPeriodInFrames, &fundamentalPeriodInFrames, &minPeriodInFrames, &maxPeriodInFrames);
if (SUCCEEDED(hr)) {
ma_uint32 desiredPeriodInFrames = pData->periodSizeInFramesOut;
ma_uint32 actualPeriodInFrames = desiredPeriodInFrames;
@@ -21461,7 +22357,7 @@ static ma_result ma_device_init_internal__wasapi(ma_context* pContext, ma_device
MA_AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM | MA_AUDCLNT_STREAMFLAGS_SRC_DEFAULT_QUALITY must not be in the stream flags. If either of these are specified,
IAudioClient3_InitializeSharedAudioStream() will fail.
*/
- hr = ma_IAudioClient3_InitializeSharedAudioStream(pAudioClient3, streamFlags & ~(MA_AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM | MA_AUDCLNT_STREAMFLAGS_SRC_DEFAULT_QUALITY), actualPeriodInFrames, (WAVEFORMATEX*)&wf, NULL);
+ hr = ma_IAudioClient3_InitializeSharedAudioStream(pAudioClient3, streamFlags & ~(MA_AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM | MA_AUDCLNT_STREAMFLAGS_SRC_DEFAULT_QUALITY), actualPeriodInFrames, (MA_WAVEFORMATEX*)&wf, NULL);
if (SUCCEEDED(hr)) {
wasInitializedUsingIAudioClient3 = MA_TRUE;
pData->periodSizeInFramesOut = actualPeriodInFrames;
@@ -21492,7 +22388,7 @@ static ma_result ma_device_init_internal__wasapi(ma_context* pContext, ma_device
/* If we don't have an IAudioClient3 then we need to use the normal initialization routine. */
if (!wasInitializedUsingIAudioClient3) {
MA_REFERENCE_TIME bufferDuration = periodDurationInMicroseconds * pData->periodsOut * 10; /* <-- Multiply by 10 for microseconds to 100-nanoseconds. */
- hr = ma_IAudioClient_Initialize((ma_IAudioClient*)pData->pAudioClient, shareMode, streamFlags, bufferDuration, 0, (WAVEFORMATEX*)&wf, NULL);
+ hr = ma_IAudioClient_Initialize((ma_IAudioClient*)pData->pAudioClient, shareMode, streamFlags, bufferDuration, 0, (const MA_WAVEFORMATEX*)&wf, NULL);
if (FAILED(hr)) {
if (hr == E_ACCESSDENIED) {
errorMsg = "[WASAPI] Failed to initialize device. Access denied.", result = MA_ACCESS_DENIED;
@@ -21508,13 +22404,22 @@ static ma_result ma_device_init_internal__wasapi(ma_context* pContext, ma_device
}
if (!wasInitializedUsingIAudioClient3) {
- ma_uint32 bufferSizeInFrames;
+ ma_uint32 bufferSizeInFrames = 0;
hr = ma_IAudioClient_GetBufferSize((ma_IAudioClient*)pData->pAudioClient, &bufferSizeInFrames);
if (FAILED(hr)) {
errorMsg = "[WASAPI] Failed to get audio client's actual buffer size.", result = ma_result_from_HRESULT(hr);
goto done;
}
+ /*
+ When using process loopback mode, retrieval of the buffer size seems to result in totally
+ incorrect values. In this case we'll just assume it's the same size as what we requested
+ when we initialized the client.
+ */
+ if (usingProcessLoopback) {
+ bufferSizeInFrames = (ma_uint32)((periodDurationInMicroseconds * pData->periodsOut) * pData->sampleRateOut / 1000000);
+ }
+
pData->periodSizeInFramesOut = bufferSizeInFrames / pData->periodsOut;
}
@@ -21540,7 +22445,7 @@ static ma_result ma_device_init_internal__wasapi(ma_context* pContext, ma_device
ma_IPropertyStore *pProperties;
hr = ma_IMMDevice_OpenPropertyStore(pDeviceInterface, STGM_READ, &pProperties);
if (SUCCEEDED(hr)) {
- PROPVARIANT varName;
+ MA_PROPVARIANT varName;
ma_PropVariantInit(&varName);
hr = ma_IPropertyStore_GetValue(pProperties, &MA_PKEY_Device_FriendlyName, &varName);
if (SUCCEEDED(hr)) {
@@ -21694,13 +22599,13 @@ static ma_result ma_device_reinit__wasapi(ma_device* pDevice, ma_device_type dev
pDevice->capture.internalPeriods = data.periodsOut;
ma_strcpy_s(pDevice->capture.name, sizeof(pDevice->capture.name), data.deviceName);
- ma_IAudioClient_SetEventHandle((ma_IAudioClient*)pDevice->wasapi.pAudioClientCapture, pDevice->wasapi.hEventCapture);
+ ma_IAudioClient_SetEventHandle((ma_IAudioClient*)pDevice->wasapi.pAudioClientCapture, (HANDLE)pDevice->wasapi.hEventCapture);
pDevice->wasapi.periodSizeInFramesCapture = data.periodSizeInFramesOut;
ma_IAudioClient_GetBufferSize((ma_IAudioClient*)pDevice->wasapi.pAudioClientCapture, &pDevice->wasapi.actualBufferSizeInFramesCapture);
/* We must always have a valid ID. */
- ma_wcscpy_s(pDevice->capture.id.wasapi, sizeof(pDevice->capture.id.wasapi), data.id.wasapi);
+ ma_strcpy_s_WCHAR(pDevice->capture.id.wasapi, sizeof(pDevice->capture.id.wasapi), data.id.wasapi);
}
if (deviceType == ma_device_type_playback) {
@@ -21715,13 +22620,13 @@ static ma_result ma_device_reinit__wasapi(ma_device* pDevice, ma_device_type dev
pDevice->playback.internalPeriods = data.periodsOut;
ma_strcpy_s(pDevice->playback.name, sizeof(pDevice->playback.name), data.deviceName);
- ma_IAudioClient_SetEventHandle((ma_IAudioClient*)pDevice->wasapi.pAudioClientPlayback, pDevice->wasapi.hEventPlayback);
+ ma_IAudioClient_SetEventHandle((ma_IAudioClient*)pDevice->wasapi.pAudioClientPlayback, (HANDLE)pDevice->wasapi.hEventPlayback);
pDevice->wasapi.periodSizeInFramesPlayback = data.periodSizeInFramesOut;
ma_IAudioClient_GetBufferSize((ma_IAudioClient*)pDevice->wasapi.pAudioClientPlayback, &pDevice->wasapi.actualBufferSizeInFramesPlayback);
/* We must always have a valid ID because rerouting will look at it. */
- ma_wcscpy_s(pDevice->playback.id.wasapi, sizeof(pDevice->playback.id.wasapi), data.id.wasapi);
+ ma_strcpy_s_WCHAR(pDevice->playback.id.wasapi, sizeof(pDevice->playback.id.wasapi), data.id.wasapi);
}
return MA_SUCCESS;
@@ -21784,7 +22689,7 @@ static ma_result ma_device_init__wasapi(ma_device* pDevice, const ma_device_conf
The event for capture needs to be manual reset for the same reason as playback. We keep the initial state set to unsignaled,
however, because we want to block until we actually have something for the first call to ma_device_read().
*/
- pDevice->wasapi.hEventCapture = CreateEventW(NULL, FALSE, FALSE, NULL); /* Auto reset, unsignaled by default. */
+ pDevice->wasapi.hEventCapture = (ma_handle)CreateEventA(NULL, FALSE, FALSE, NULL); /* Auto reset, unsignaled by default. */
if (pDevice->wasapi.hEventCapture == NULL) {
result = ma_result_from_GetLastError(GetLastError());
@@ -21800,13 +22705,13 @@ static ma_result ma_device_init__wasapi(ma_device* pDevice, const ma_device_conf
ma_log_post(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to create event for capture.");
return result;
}
- ma_IAudioClient_SetEventHandle((ma_IAudioClient*)pDevice->wasapi.pAudioClientCapture, pDevice->wasapi.hEventCapture);
+ ma_IAudioClient_SetEventHandle((ma_IAudioClient*)pDevice->wasapi.pAudioClientCapture, (HANDLE)pDevice->wasapi.hEventCapture);
pDevice->wasapi.periodSizeInFramesCapture = data.periodSizeInFramesOut;
ma_IAudioClient_GetBufferSize((ma_IAudioClient*)pDevice->wasapi.pAudioClientCapture, &pDevice->wasapi.actualBufferSizeInFramesCapture);
/* We must always have a valid ID. */
- ma_wcscpy_s(pDevice->capture.id.wasapi, sizeof(pDevice->capture.id.wasapi), data.id.wasapi);
+ ma_strcpy_s_WCHAR(pDevice->capture.id.wasapi, sizeof(pDevice->capture.id.wasapi), data.id.wasapi);
/* The descriptor needs to be updated with actual values. */
pDescriptorCapture->format = data.formatOut;
@@ -21846,7 +22751,7 @@ static ma_result ma_device_init__wasapi(ma_device* pDevice, const ma_device_conf
pDevice->wasapi.pAudioClientCapture = NULL;
}
- CloseHandle(pDevice->wasapi.hEventCapture);
+ CloseHandle((HANDLE)pDevice->wasapi.hEventCapture);
pDevice->wasapi.hEventCapture = NULL;
}
return result;
@@ -21866,7 +22771,7 @@ static ma_result ma_device_init__wasapi(ma_device* pDevice, const ma_device_conf
The playback event also needs to be initially set to a signaled state so that the first call to ma_device_write() is able
to get passed WaitForMultipleObjects().
*/
- pDevice->wasapi.hEventPlayback = CreateEventW(NULL, FALSE, TRUE, NULL); /* Auto reset, signaled by default. */
+ pDevice->wasapi.hEventPlayback = (ma_handle)CreateEventA(NULL, FALSE, TRUE, NULL); /* Auto reset, signaled by default. */
if (pDevice->wasapi.hEventPlayback == NULL) {
result = ma_result_from_GetLastError(GetLastError());
@@ -21880,7 +22785,7 @@ static ma_result ma_device_init__wasapi(ma_device* pDevice, const ma_device_conf
pDevice->wasapi.pAudioClientCapture = NULL;
}
- CloseHandle(pDevice->wasapi.hEventCapture);
+ CloseHandle((HANDLE)pDevice->wasapi.hEventCapture);
pDevice->wasapi.hEventCapture = NULL;
}
@@ -21896,13 +22801,13 @@ static ma_result ma_device_init__wasapi(ma_device* pDevice, const ma_device_conf
ma_log_post(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to create event for playback.");
return result;
}
- ma_IAudioClient_SetEventHandle((ma_IAudioClient*)pDevice->wasapi.pAudioClientPlayback, pDevice->wasapi.hEventPlayback);
+ ma_IAudioClient_SetEventHandle((ma_IAudioClient*)pDevice->wasapi.pAudioClientPlayback, (HANDLE)pDevice->wasapi.hEventPlayback);
pDevice->wasapi.periodSizeInFramesPlayback = data.periodSizeInFramesOut;
ma_IAudioClient_GetBufferSize((ma_IAudioClient*)pDevice->wasapi.pAudioClientPlayback, &pDevice->wasapi.actualBufferSizeInFramesPlayback);
/* We must always have a valid ID because rerouting will look at it. */
- ma_wcscpy_s(pDevice->playback.id.wasapi, sizeof(pDevice->playback.id.wasapi), data.id.wasapi);
+ ma_strcpy_s_WCHAR(pDevice->playback.id.wasapi, sizeof(pDevice->playback.id.wasapi), data.id.wasapi);
/* The descriptor needs to be updated with actual values. */
pDescriptorPlayback->format = data.formatOut;
@@ -21920,7 +22825,7 @@ static ma_result ma_device_init__wasapi(ma_device* pDevice, const ma_device_conf
*/
#if defined(MA_WIN32_DESKTOP) || defined(MA_WIN32_GDK)
if (pConfig->wasapi.noAutoStreamRouting == MA_FALSE) {
- if ((pConfig->deviceType == ma_device_type_capture || pConfig->deviceType == ma_device_type_duplex) && pConfig->capture.pDeviceID == NULL) {
+ if ((pConfig->deviceType == ma_device_type_capture || pConfig->deviceType == ma_device_type_duplex || pConfig->deviceType == ma_device_type_loopback) && pConfig->capture.pDeviceID == NULL) {
pDevice->wasapi.allowCaptureAutoStreamRouting = MA_TRUE;
}
if ((pConfig->deviceType == ma_device_type_playback || pConfig->deviceType == ma_device_type_duplex) && pConfig->playback.pDeviceID == NULL) {
@@ -21928,7 +22833,9 @@ static ma_result ma_device_init__wasapi(ma_device* pDevice, const ma_device_conf
}
}
- hr = ma_CoCreateInstance(pDevice->pContext, MA_CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, MA_IID_IMMDeviceEnumerator, (void**)&pDeviceEnumerator);
+ ma_mutex_init(&pDevice->wasapi.rerouteLock);
+
+ hr = ma_CoCreateInstance(pDevice->pContext, &MA_CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, &MA_IID_IMMDeviceEnumerator, (void**)&pDeviceEnumerator);
if (FAILED(hr)) {
ma_device_uninit__wasapi(pDevice);
ma_log_post(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to create device enumerator.");
@@ -21948,8 +22855,8 @@ static ma_result ma_device_init__wasapi(ma_device* pDevice, const ma_device_conf
}
#endif
- c89atomic_exchange_32(&pDevice->wasapi.isStartedCapture, MA_FALSE);
- c89atomic_exchange_32(&pDevice->wasapi.isStartedPlayback, MA_FALSE);
+ ma_atomic_bool32_set(&pDevice->wasapi.isStartedCapture, MA_FALSE);
+ ma_atomic_bool32_set(&pDevice->wasapi.isStartedPlayback, MA_FALSE);
return MA_SUCCESS;
}
@@ -22027,50 +22934,65 @@ static ma_result ma_device_reroute__wasapi(ma_device* pDevice, ma_device_type de
}
ma_device__post_init_setup(pDevice, deviceType);
-
ma_device__on_notification_rerouted(pDevice);
+ ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_DEBUG, "=== DEVICE CHANGED ===\n");
+
return MA_SUCCESS;
}
-static ma_result ma_device_start__wasapi(ma_device* pDevice)
+static ma_result ma_device_start__wasapi_nolock(ma_device* pDevice)
{
HRESULT hr;
- MA_ASSERT(pDevice != NULL);
-
if (pDevice->pContext->wasapi.hAvrt) {
- LPCWSTR pTaskName = ma_to_usage_string__wasapi(pDevice->wasapi.usage);
+ const char* pTaskName = ma_to_usage_string__wasapi(pDevice->wasapi.usage);
if (pTaskName) {
DWORD idx = 0;
- pDevice->wasapi.hAvrtHandle = ((MA_PFN_AvSetMmThreadCharacteristicsW)pDevice->pContext->wasapi.AvSetMmThreadCharacteristicsW)(pTaskName, &idx);
+ pDevice->wasapi.hAvrtHandle = (ma_handle)((MA_PFN_AvSetMmThreadCharacteristicsA)pDevice->pContext->wasapi.AvSetMmThreadCharacteristicsA)(pTaskName, &idx);
}
}
if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex || pDevice->type == ma_device_type_loopback) {
hr = ma_IAudioClient_Start((ma_IAudioClient*)pDevice->wasapi.pAudioClientCapture);
if (FAILED(hr)) {
- ma_log_post(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to start internal capture device.");
+ ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to start internal capture device. HRESULT = %d.", (int)hr);
return ma_result_from_HRESULT(hr);
}
- c89atomic_exchange_32(&pDevice->wasapi.isStartedCapture, MA_TRUE);
+ ma_atomic_bool32_set(&pDevice->wasapi.isStartedCapture, MA_TRUE);
}
if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) {
hr = ma_IAudioClient_Start((ma_IAudioClient*)pDevice->wasapi.pAudioClientPlayback);
if (FAILED(hr)) {
- ma_log_post(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to start internal playback device.");
+ ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to start internal playback device. HRESULT = %d.", (int)hr);
return ma_result_from_HRESULT(hr);
}
- c89atomic_exchange_32(&pDevice->wasapi.isStartedPlayback, MA_TRUE);
+ ma_atomic_bool32_set(&pDevice->wasapi.isStartedPlayback, MA_TRUE);
}
return MA_SUCCESS;
}
-static ma_result ma_device_stop__wasapi(ma_device* pDevice)
+static ma_result ma_device_start__wasapi(ma_device* pDevice)
+{
+ ma_result result;
+
+ MA_ASSERT(pDevice != NULL);
+
+ /* Wait for any rerouting to finish before attempting to start the device. */
+ ma_mutex_lock(&pDevice->wasapi.rerouteLock);
+ {
+ result = ma_device_start__wasapi_nolock(pDevice);
+ }
+ ma_mutex_unlock(&pDevice->wasapi.rerouteLock);
+
+ return result;
+}
+
+static ma_result ma_device_stop__wasapi_nolock(ma_device* pDevice)
{
ma_result result;
HRESULT hr;
@@ -22099,12 +23021,12 @@ static ma_result ma_device_stop__wasapi(ma_device* pDevice)
/* If we have a mapped buffer we need to release it. */
if (pDevice->wasapi.pMappedBufferCapture != NULL) {
ma_IAudioCaptureClient_ReleaseBuffer((ma_IAudioCaptureClient*)pDevice->wasapi.pCaptureClient, pDevice->wasapi.mappedBufferCaptureCap);
- pDevice->wasapi.pMappedBufferCapture = NULL;
+ pDevice->wasapi.pMappedBufferCapture = NULL;
pDevice->wasapi.mappedBufferCaptureCap = 0;
pDevice->wasapi.mappedBufferCaptureLen = 0;
}
- c89atomic_exchange_32(&pDevice->wasapi.isStartedCapture, MA_FALSE);
+ ma_atomic_bool32_set(&pDevice->wasapi.isStartedCapture, MA_FALSE);
}
if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) {
@@ -22112,13 +23034,14 @@ static ma_result ma_device_stop__wasapi(ma_device* pDevice)
The buffer needs to be drained before stopping the device. Not doing this will result in the last few frames not getting output to
the speakers. This is a problem for very short sounds because it'll result in a significant portion of it not getting played.
*/
- if (c89atomic_load_32(&pDevice->wasapi.isStartedPlayback)) {
+ if (ma_atomic_bool32_get(&pDevice->wasapi.isStartedPlayback)) {
/* We need to make sure we put a timeout here or else we'll risk getting stuck in a deadlock in some cases. */
DWORD waitTime = pDevice->wasapi.actualBufferSizeInFramesPlayback / pDevice->playback.internalSampleRate;
if (pDevice->playback.shareMode == ma_share_mode_exclusive) {
- WaitForSingleObject(pDevice->wasapi.hEventPlayback, waitTime);
- } else {
+ WaitForSingleObject((HANDLE)pDevice->wasapi.hEventPlayback, waitTime);
+ }
+ else {
ma_uint32 prevFramesAvaialablePlayback = (ma_uint32)-1;
ma_uint32 framesAvailablePlayback;
for (;;) {
@@ -22140,8 +23063,8 @@ static ma_result ma_device_stop__wasapi(ma_device* pDevice)
}
prevFramesAvaialablePlayback = framesAvailablePlayback;
- WaitForSingleObject(pDevice->wasapi.hEventPlayback, waitTime * 1000);
- ResetEvent(pDevice->wasapi.hEventPlayback); /* Manual reset. */
+ WaitForSingleObject((HANDLE)pDevice->wasapi.hEventPlayback, waitTime * 1000);
+ ResetEvent((HANDLE)pDevice->wasapi.hEventPlayback); /* Manual reset. */
}
}
}
@@ -22161,17 +23084,33 @@ static ma_result ma_device_stop__wasapi(ma_device* pDevice)
if (pDevice->wasapi.pMappedBufferPlayback != NULL) {
ma_IAudioRenderClient_ReleaseBuffer((ma_IAudioRenderClient*)pDevice->wasapi.pRenderClient, pDevice->wasapi.mappedBufferPlaybackCap, 0);
- pDevice->wasapi.pMappedBufferPlayback = NULL;
+ pDevice->wasapi.pMappedBufferPlayback = NULL;
pDevice->wasapi.mappedBufferPlaybackCap = 0;
pDevice->wasapi.mappedBufferPlaybackLen = 0;
}
- c89atomic_exchange_32(&pDevice->wasapi.isStartedPlayback, MA_FALSE);
+ ma_atomic_bool32_set(&pDevice->wasapi.isStartedPlayback, MA_FALSE);
}
return MA_SUCCESS;
}
+static ma_result ma_device_stop__wasapi(ma_device* pDevice)
+{
+ ma_result result;
+
+ MA_ASSERT(pDevice != NULL);
+
+ /* Wait for any rerouting to finish before attempting to stop the device. */
+ ma_mutex_lock(&pDevice->wasapi.rerouteLock);
+ {
+ result = ma_device_stop__wasapi_nolock(pDevice);
+ }
+ ma_mutex_unlock(&pDevice->wasapi.rerouteLock);
+
+ return result;
+}
+
#ifndef MA_WASAPI_WAIT_TIMEOUT_MILLISECONDS
#define MA_WASAPI_WAIT_TIMEOUT_MILLISECONDS 5000
@@ -22220,50 +23159,100 @@ static ma_result ma_device_read__wasapi(ma_device* pDevice, void* pFrames, ma_ui
} else {
/* We don't have any cached data pointer, so grab another one. */
HRESULT hr;
- DWORD flags;
+ DWORD flags = 0;
/* First just ask WASAPI for a data buffer. If it's not available, we'll wait for more. */
hr = ma_IAudioCaptureClient_GetBuffer((ma_IAudioCaptureClient*)pDevice->wasapi.pCaptureClient, (BYTE**)&pDevice->wasapi.pMappedBufferCapture, &pDevice->wasapi.mappedBufferCaptureCap, &flags, NULL, NULL);
if (hr == S_OK) {
/* We got a data buffer. Continue to the next loop iteration which will then read from the mapped pointer. */
+ pDevice->wasapi.mappedBufferCaptureLen = pDevice->wasapi.mappedBufferCaptureCap;
+
+ /*
+ There have been reports that indicate that at times the AUDCLNT_BUFFERFLAGS_DATA_DISCONTINUITY is reported for every
+ call to IAudioCaptureClient_GetBuffer() above which results in spamming of the debug messages below. To partially
+ work around this, I'm only outputting these messages when MA_DEBUG_OUTPUT is explicitly defined. The better solution
+ would be to figure out why the flag is always getting reported.
+ */
+ #if defined(MA_DEBUG_OUTPUT)
+ {
+ if (flags != 0) {
+ ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_DEBUG, "[WASAPI] Capture Flags: %ld\n", flags);
+
+ if ((flags & MA_AUDCLNT_BUFFERFLAGS_DATA_DISCONTINUITY) != 0) {
+ ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_DEBUG, "[WASAPI] Data discontinuity (possible overrun). Attempting recovery. mappedBufferCaptureCap=%d\n", pDevice->wasapi.mappedBufferCaptureCap);
+ }
+ }
+ }
+ #endif
/* Overrun detection. */
if ((flags & MA_AUDCLNT_BUFFERFLAGS_DATA_DISCONTINUITY) != 0) {
/* Glitched. Probably due to an overrun. */
- ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_DEBUG, "[WASAPI] Data discontinuity (possible overrun). Attempting recovery. mappedBufferCaptureCap=%d\n", pDevice->wasapi.mappedBufferCaptureCap);
/*
- If we got an overrun it probably means we're straddling the end of the buffer. In order to prevent
- a never-ending sequence of glitches we're going to recover by completely clearing out the capture
- buffer.
+ If we got an overrun it probably means we're straddling the end of the buffer. In normal capture
+ mode this is the fault of the client application because they're responsible for ensuring data is
+ processed fast enough. In duplex mode, however, the processing of audio is tied to the playback
+ device, so this can possibly be the result of a timing de-sync.
+
+ In capture mode we're not going to do any kind of recovery because the real fix is for the client
+ application to process faster. In duplex mode, we'll treat this as a desync and reset the buffers
+ to prevent a never-ending sequence of glitches due to straddling the end of the buffer.
*/
- {
- ma_uint32 iterationCount = 4; /* Safety to prevent an infinite loop. */
+ if (pDevice->type == ma_device_type_duplex) {
+ /*
+ Experiment:
+
+ If we empty out the *entire* buffer we may end up putting ourselves into an underrun position
+ which isn't really any better than the overrun we're probably in right now. Instead we'll just
+ empty out about half.
+ */
ma_uint32 i;
+ ma_uint32 periodCount = (pDevice->wasapi.actualBufferSizeInFramesCapture / pDevice->wasapi.periodSizeInFramesCapture);
+ ma_uint32 iterationCount = periodCount / 2;
+ if ((periodCount % 2) > 0) {
+ iterationCount += 1;
+ }
for (i = 0; i < iterationCount; i += 1) {
hr = ma_IAudioCaptureClient_ReleaseBuffer((ma_IAudioCaptureClient*)pDevice->wasapi.pCaptureClient, pDevice->wasapi.mappedBufferCaptureCap);
if (FAILED(hr)) {
+ ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_DEBUG, "[WASAPI] Data discontinuity recovery: IAudioCaptureClient_ReleaseBuffer() failed with %ld.\n", hr);
break;
}
+ flags = 0;
hr = ma_IAudioCaptureClient_GetBuffer((ma_IAudioCaptureClient*)pDevice->wasapi.pCaptureClient, (BYTE**)&pDevice->wasapi.pMappedBufferCapture, &pDevice->wasapi.mappedBufferCaptureCap, &flags, NULL, NULL);
if (hr == MA_AUDCLNT_S_BUFFER_EMPTY || FAILED(hr)) {
+ /*
+ The buffer has been completely emptied or an error occurred. In this case we'll need
+ to reset the state of the mapped buffer which will trigger the next iteration to get
+ a fresh buffer from WASAPI.
+ */
+ pDevice->wasapi.pMappedBufferCapture = NULL;
+ pDevice->wasapi.mappedBufferCaptureCap = 0;
+ pDevice->wasapi.mappedBufferCaptureLen = 0;
+
+ if (hr == MA_AUDCLNT_S_BUFFER_EMPTY) {
+ if ((flags & MA_AUDCLNT_BUFFERFLAGS_DATA_DISCONTINUITY) != 0) {
+ ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_DEBUG, "[WASAPI] Data discontinuity recovery: Buffer emptied, and data discontinuity still reported.\n");
+ } else {
+ ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_DEBUG, "[WASAPI] Data discontinuity recovery: Buffer emptied.\n");
+ }
+ }
+
+ if (FAILED(hr)) {
+ ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_DEBUG, "[WASAPI] Data discontinuity recovery: IAudioCaptureClient_GetBuffer() failed with %ld.\n", hr);
+ }
+
break;
}
}
- }
-
- /* We should not have a valid buffer at this point so make sure everything is empty. */
- pDevice->wasapi.pMappedBufferCapture = NULL;
- pDevice->wasapi.mappedBufferCaptureCap = 0;
- pDevice->wasapi.mappedBufferCaptureLen = 0;
- } else {
- /* The data is clean. */
- pDevice->wasapi.mappedBufferCaptureLen = pDevice->wasapi.mappedBufferCaptureCap;
- if (flags != 0) {
- ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_DEBUG, "[WASAPI] Capture Flags: %ld\n", flags);
+ /* If at this point we have a valid buffer mapped, make sure the buffer length is set appropriately. */
+ if (pDevice->wasapi.pMappedBufferCapture != NULL) {
+ pDevice->wasapi.mappedBufferCaptureLen = pDevice->wasapi.mappedBufferCaptureCap;
+ }
}
}
@@ -22285,7 +23274,7 @@ static ma_result ma_device_read__wasapi(ma_device* pDevice, void* pFrames, ma_ui
timeoutInMilliseconds = 10;
}
- if (WaitForSingleObject(pDevice->wasapi.hEventCapture, timeoutInMilliseconds) != WAIT_OBJECT_0) {
+ if (WaitForSingleObject((HANDLE)pDevice->wasapi.hEventCapture, timeoutInMilliseconds) != WAIT_OBJECT_0) {
if (pDevice->type == ma_device_type_loopback) {
continue; /* Keep waiting in loopback mode. */
} else {
@@ -22296,7 +23285,7 @@ static ma_result ma_device_read__wasapi(ma_device* pDevice, void* pFrames, ma_ui
/* At this point we should be able to loop back to the start of the loop and try retrieving a data buffer again. */
} else {
- /* An error occured and we need to abort. */
+ /* An error occurred and we need to abort. */
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to retrieve internal buffer from capture device in preparation for reading from the device. HRESULT = %d. Stopping device.\n", (int)hr);
result = ma_result_from_HRESULT(hr);
break;
@@ -22370,7 +23359,7 @@ static ma_result ma_device_write__wasapi(ma_device* pDevice, const void* pFrames
whether or not we need to wait for more data.
*/
if (pDevice->playback.shareMode == ma_share_mode_exclusive) {
- if (WaitForSingleObject(pDevice->wasapi.hEventPlayback, MA_WASAPI_WAIT_TIMEOUT_MILLISECONDS) != WAIT_OBJECT_0) {
+ if (WaitForSingleObject((HANDLE)pDevice->wasapi.hEventPlayback, MA_WASAPI_WAIT_TIMEOUT_MILLISECONDS) != WAIT_OBJECT_0) {
result = MA_ERROR;
break; /* Wait failed. Probably timed out. */
}
@@ -22396,7 +23385,7 @@ static ma_result ma_device_write__wasapi(ma_device* pDevice, const void* pFrames
} else {
if (hr == MA_AUDCLNT_E_BUFFER_TOO_LARGE || hr == MA_AUDCLNT_E_BUFFER_ERROR) {
/* Not enough data available. We need to wait for more. */
- if (WaitForSingleObject(pDevice->wasapi.hEventPlayback, MA_WASAPI_WAIT_TIMEOUT_MILLISECONDS) != WAIT_OBJECT_0) {
+ if (WaitForSingleObject((HANDLE)pDevice->wasapi.hEventPlayback, MA_WASAPI_WAIT_TIMEOUT_MILLISECONDS) != WAIT_OBJECT_0) {
result = MA_ERROR;
break; /* Wait failed. Probably timed out. */
}
@@ -22435,32 +23424,31 @@ static ma_result ma_device_data_loop_wakeup__wasapi(ma_device* pDevice)
static ma_result ma_context_uninit__wasapi(ma_context* pContext)
{
+ ma_context_command__wasapi cmd = ma_context_init_command__wasapi(MA_CONTEXT_COMMAND_QUIT__WASAPI);
+
MA_ASSERT(pContext != NULL);
MA_ASSERT(pContext->backend == ma_backend_wasapi);
- if (pContext->wasapi.commandThread != NULL) {
- ma_context_command__wasapi cmd = ma_context_init_command__wasapi(MA_CONTEXT_COMMAND_QUIT__WASAPI);
- ma_context_post_command__wasapi(pContext, &cmd);
- ma_thread_wait(&pContext->wasapi.commandThread);
+ ma_context_post_command__wasapi(pContext, &cmd);
+ ma_thread_wait(&pContext->wasapi.commandThread);
- if (pContext->wasapi.hAvrt) {
- ma_dlclose(pContext, pContext->wasapi.hAvrt);
- pContext->wasapi.hAvrt = NULL;
- }
+ if (pContext->wasapi.hAvrt) {
+ ma_dlclose(ma_context_get_log(pContext), pContext->wasapi.hAvrt);
+ pContext->wasapi.hAvrt = NULL;
+ }
- #if defined(MA_WIN32_UWP)
- {
- if (pContext->wasapi.hMMDevapi) {
- ma_dlclose(pContext, pContext->wasapi.hMMDevapi);
- pContext->wasapi.hMMDevapi = NULL;
- }
+ #if defined(MA_WIN32_UWP)
+ {
+ if (pContext->wasapi.hMMDevapi) {
+ ma_dlclose(ma_context_get_log(pContext), pContext->wasapi.hMMDevapi);
+ pContext->wasapi.hMMDevapi = NULL;
}
- #endif
-
- /* Only after the thread has been terminated can we uninitialize the sync objects for the command thread. */
- ma_semaphore_uninit(&pContext->wasapi.commandSem);
- ma_mutex_uninit(&pContext->wasapi.commandLock);
}
+ #endif
+
+ /* Only after the thread has been terminated can we uninitialize the sync objects for the command thread. */
+ ma_semaphore_uninit(&pContext->wasapi.commandSem);
+ ma_mutex_uninit(&pContext->wasapi.commandLock);
return MA_SUCCESS;
}
@@ -22486,15 +23474,15 @@ static ma_result ma_context_init__wasapi(ma_context* pContext, const ma_context_
ma_PFNVerifyVersionInfoW _VerifyVersionInfoW;
ma_PFNVerSetConditionMask _VerSetConditionMask;
- kernel32DLL = ma_dlopen(pContext, "kernel32.dll");
+ kernel32DLL = ma_dlopen(ma_context_get_log(pContext), "kernel32.dll");
if (kernel32DLL == NULL) {
return MA_NO_BACKEND;
}
- _VerifyVersionInfoW = (ma_PFNVerifyVersionInfoW )ma_dlsym(pContext, kernel32DLL, "VerifyVersionInfoW");
- _VerSetConditionMask = (ma_PFNVerSetConditionMask)ma_dlsym(pContext, kernel32DLL, "VerSetConditionMask");
+ _VerifyVersionInfoW = (ma_PFNVerifyVersionInfoW )ma_dlsym(ma_context_get_log(pContext), kernel32DLL, "VerifyVersionInfoW");
+ _VerSetConditionMask = (ma_PFNVerSetConditionMask)ma_dlsym(ma_context_get_log(pContext), kernel32DLL, "VerSetConditionMask");
if (_VerifyVersionInfoW == NULL || _VerSetConditionMask == NULL) {
- ma_dlclose(pContext, kernel32DLL);
+ ma_dlclose(ma_context_get_log(pContext), kernel32DLL);
return MA_NO_BACKEND;
}
@@ -22509,7 +23497,7 @@ static ma_result ma_context_init__wasapi(ma_context* pContext, const ma_context_
result = MA_NO_BACKEND;
}
- ma_dlclose(pContext, kernel32DLL);
+ ma_dlclose(ma_context_get_log(pContext), kernel32DLL);
}
#endif
@@ -22519,6 +23507,39 @@ static ma_result ma_context_init__wasapi(ma_context* pContext, const ma_context_
MA_ZERO_OBJECT(&pContext->wasapi);
+
+ #if defined(MA_WIN32_UWP)
+ {
+ /* Link to mmdevapi so we can get access to ActivateAudioInterfaceAsync(). */
+ pContext->wasapi.hMMDevapi = ma_dlopen(ma_context_get_log(pContext), "mmdevapi.dll");
+ if (pContext->wasapi.hMMDevapi) {
+ pContext->wasapi.ActivateAudioInterfaceAsync = ma_dlsym(ma_context_get_log(pContext), pContext->wasapi.hMMDevapi, "ActivateAudioInterfaceAsync");
+ if (pContext->wasapi.ActivateAudioInterfaceAsync == NULL) {
+ ma_dlclose(ma_context_get_log(pContext), pContext->wasapi.hMMDevapi);
+ return MA_NO_BACKEND; /* ActivateAudioInterfaceAsync() could not be loaded. */
+ }
+ } else {
+ return MA_NO_BACKEND; /* Failed to load mmdevapi.dll which is required for ActivateAudioInterfaceAsync() */
+ }
+ }
+ #endif
+
+ /* Optionally use the Avrt API to specify the audio thread's latency sensitivity requirements */
+ pContext->wasapi.hAvrt = ma_dlopen(ma_context_get_log(pContext), "avrt.dll");
+ if (pContext->wasapi.hAvrt) {
+ pContext->wasapi.AvSetMmThreadCharacteristicsA = ma_dlsym(ma_context_get_log(pContext), pContext->wasapi.hAvrt, "AvSetMmThreadCharacteristicsA");
+ pContext->wasapi.AvRevertMmThreadcharacteristics = ma_dlsym(ma_context_get_log(pContext), pContext->wasapi.hAvrt, "AvRevertMmThreadCharacteristics");
+
+ /* If either function could not be found, disable use of avrt entirely. */
+ if (!pContext->wasapi.AvSetMmThreadCharacteristicsA || !pContext->wasapi.AvRevertMmThreadcharacteristics) {
+ pContext->wasapi.AvSetMmThreadCharacteristicsA = NULL;
+ pContext->wasapi.AvRevertMmThreadcharacteristics = NULL;
+ ma_dlclose(ma_context_get_log(pContext), pContext->wasapi.hAvrt);
+ pContext->wasapi.hAvrt = NULL;
+ }
+ }
+
+
/*
Annoyingly, WASAPI does not allow you to release an IAudioClient object from a different thread
than the one that retrieved it with GetService(). This can result in a deadlock in two
@@ -22562,41 +23583,6 @@ static ma_result ma_context_init__wasapi(ma_context* pContext, const ma_context_
ma_mutex_uninit(&pContext->wasapi.commandLock);
return result;
}
-
- #if defined(MA_WIN32_UWP)
- {
- /* Link to mmdevapi so we can get access to ActivateAudioInterfaceAsync(). */
- pContext->wasapi.hMMDevapi = ma_dlopen(pContext, "mmdevapi.dll");
- if (pContext->wasapi.hMMDevapi) {
- pContext->wasapi.ActivateAudioInterfaceAsync = ma_dlsym(pContext, pContext->wasapi.hMMDevapi, "ActivateAudioInterfaceAsync");
- if (pContext->wasapi.ActivateAudioInterfaceAsync == NULL) {
- ma_semaphore_uninit(&pContext->wasapi.commandSem);
- ma_mutex_uninit(&pContext->wasapi.commandLock);
- ma_dlclose(pContext, pContext->wasapi.hMMDevapi);
- return MA_NO_BACKEND; /* ActivateAudioInterfaceAsync() could not be loaded. */
- }
- } else {
- ma_semaphore_uninit(&pContext->wasapi.commandSem);
- ma_mutex_uninit(&pContext->wasapi.commandLock);
- return MA_NO_BACKEND; /* Failed to load mmdevapi.dll which is required for ActivateAudioInterfaceAsync() */
- }
- }
- #endif
-
- /* Optionally use the Avrt API to specify the audio thread's latency sensitivity requirements */
- pContext->wasapi.hAvrt = ma_dlopen(pContext, "avrt.dll");
- if (pContext->wasapi.hAvrt) {
- pContext->wasapi.AvSetMmThreadCharacteristicsW = ma_dlsym(pContext, pContext->wasapi.hAvrt, "AvSetMmThreadCharacteristicsW");
- pContext->wasapi.AvRevertMmThreadcharacteristics = ma_dlsym(pContext, pContext->wasapi.hAvrt, "AvRevertMmThreadCharacteristics");
-
- /* If either function could not be found, disable use of avrt entirely. */
- if (!pContext->wasapi.AvSetMmThreadCharacteristicsW || !pContext->wasapi.AvRevertMmThreadcharacteristics) {
- pContext->wasapi.AvSetMmThreadCharacteristicsW = NULL;
- pContext->wasapi.AvRevertMmThreadcharacteristics = NULL;
- ma_dlclose(pContext, pContext->wasapi.hAvrt);
- pContext->wasapi.hAvrt = NULL;
- }
- }
}
@@ -22677,7 +23663,7 @@ typedef struct
DWORD dwFlags;
DWORD dwBufferBytes;
DWORD dwReserved;
- WAVEFORMATEX* lpwfxFormat;
+ MA_WAVEFORMATEX* lpwfxFormat;
GUID guid3DAlgorithm;
} MA_DSBUFFERDESC;
@@ -22687,7 +23673,7 @@ typedef struct
DWORD dwFlags;
DWORD dwBufferBytes;
DWORD dwReserved;
- WAVEFORMATEX* lpwfxFormat;
+ MA_WAVEFORMATEX* lpwfxFormat;
DWORD dwFXCount;
void* lpDSCFXDesc; /* <-- miniaudio doesn't use this, so set to void*. */
} MA_DSCBUFFERDESC;
@@ -22811,7 +23797,7 @@ typedef struct
/* IDirectSoundBuffer */
HRESULT (STDMETHODCALLTYPE * GetCaps) (ma_IDirectSoundBuffer* pThis, MA_DSBCAPS* pDSBufferCaps);
HRESULT (STDMETHODCALLTYPE * GetCurrentPosition)(ma_IDirectSoundBuffer* pThis, DWORD* pCurrentPlayCursor, DWORD* pCurrentWriteCursor);
- HRESULT (STDMETHODCALLTYPE * GetFormat) (ma_IDirectSoundBuffer* pThis, WAVEFORMATEX* pFormat, DWORD dwSizeAllocated, DWORD* pSizeWritten);
+ HRESULT (STDMETHODCALLTYPE * GetFormat) (ma_IDirectSoundBuffer* pThis, MA_WAVEFORMATEX* pFormat, DWORD dwSizeAllocated, DWORD* pSizeWritten);
HRESULT (STDMETHODCALLTYPE * GetVolume) (ma_IDirectSoundBuffer* pThis, LONG* pVolume);
HRESULT (STDMETHODCALLTYPE * GetPan) (ma_IDirectSoundBuffer* pThis, LONG* pPan);
HRESULT (STDMETHODCALLTYPE * GetFrequency) (ma_IDirectSoundBuffer* pThis, DWORD* pFrequency);
@@ -22820,7 +23806,7 @@ typedef struct
HRESULT (STDMETHODCALLTYPE * Lock) (ma_IDirectSoundBuffer* pThis, DWORD dwOffset, DWORD dwBytes, void** ppAudioPtr1, DWORD* pAudioBytes1, void** ppAudioPtr2, DWORD* pAudioBytes2, DWORD dwFlags);
HRESULT (STDMETHODCALLTYPE * Play) (ma_IDirectSoundBuffer* pThis, DWORD dwReserved1, DWORD dwPriority, DWORD dwFlags);
HRESULT (STDMETHODCALLTYPE * SetCurrentPosition)(ma_IDirectSoundBuffer* pThis, DWORD dwNewPosition);
- HRESULT (STDMETHODCALLTYPE * SetFormat) (ma_IDirectSoundBuffer* pThis, const WAVEFORMATEX* pFormat);
+ HRESULT (STDMETHODCALLTYPE * SetFormat) (ma_IDirectSoundBuffer* pThis, const MA_WAVEFORMATEX* pFormat);
HRESULT (STDMETHODCALLTYPE * SetVolume) (ma_IDirectSoundBuffer* pThis, LONG volume);
HRESULT (STDMETHODCALLTYPE * SetPan) (ma_IDirectSoundBuffer* pThis, LONG pan);
HRESULT (STDMETHODCALLTYPE * SetFrequency) (ma_IDirectSoundBuffer* pThis, DWORD dwFrequency);
@@ -22837,7 +23823,7 @@ static MA_INLINE ULONG ma_IDirectSoundBuffer_AddRef(ma_IDirectSoundBuffer* pTh
static MA_INLINE ULONG ma_IDirectSoundBuffer_Release(ma_IDirectSoundBuffer* pThis) { return pThis->lpVtbl->Release(pThis); }
static MA_INLINE HRESULT ma_IDirectSoundBuffer_GetCaps(ma_IDirectSoundBuffer* pThis, MA_DSBCAPS* pDSBufferCaps) { return pThis->lpVtbl->GetCaps(pThis, pDSBufferCaps); }
static MA_INLINE HRESULT ma_IDirectSoundBuffer_GetCurrentPosition(ma_IDirectSoundBuffer* pThis, DWORD* pCurrentPlayCursor, DWORD* pCurrentWriteCursor) { return pThis->lpVtbl->GetCurrentPosition(pThis, pCurrentPlayCursor, pCurrentWriteCursor); }
-static MA_INLINE HRESULT ma_IDirectSoundBuffer_GetFormat(ma_IDirectSoundBuffer* pThis, WAVEFORMATEX* pFormat, DWORD dwSizeAllocated, DWORD* pSizeWritten) { return pThis->lpVtbl->GetFormat(pThis, pFormat, dwSizeAllocated, pSizeWritten); }
+static MA_INLINE HRESULT ma_IDirectSoundBuffer_GetFormat(ma_IDirectSoundBuffer* pThis, MA_WAVEFORMATEX* pFormat, DWORD dwSizeAllocated, DWORD* pSizeWritten) { return pThis->lpVtbl->GetFormat(pThis, pFormat, dwSizeAllocated, pSizeWritten); }
static MA_INLINE HRESULT ma_IDirectSoundBuffer_GetVolume(ma_IDirectSoundBuffer* pThis, LONG* pVolume) { return pThis->lpVtbl->GetVolume(pThis, pVolume); }
static MA_INLINE HRESULT ma_IDirectSoundBuffer_GetPan(ma_IDirectSoundBuffer* pThis, LONG* pPan) { return pThis->lpVtbl->GetPan(pThis, pPan); }
static MA_INLINE HRESULT ma_IDirectSoundBuffer_GetFrequency(ma_IDirectSoundBuffer* pThis, DWORD* pFrequency) { return pThis->lpVtbl->GetFrequency(pThis, pFrequency); }
@@ -22846,7 +23832,7 @@ static MA_INLINE HRESULT ma_IDirectSoundBuffer_Initialize(ma_IDirectSoundBuffer*
static MA_INLINE HRESULT ma_IDirectSoundBuffer_Lock(ma_IDirectSoundBuffer* pThis, DWORD dwOffset, DWORD dwBytes, void** ppAudioPtr1, DWORD* pAudioBytes1, void** ppAudioPtr2, DWORD* pAudioBytes2, DWORD dwFlags) { return pThis->lpVtbl->Lock(pThis, dwOffset, dwBytes, ppAudioPtr1, pAudioBytes1, ppAudioPtr2, pAudioBytes2, dwFlags); }
static MA_INLINE HRESULT ma_IDirectSoundBuffer_Play(ma_IDirectSoundBuffer* pThis, DWORD dwReserved1, DWORD dwPriority, DWORD dwFlags) { return pThis->lpVtbl->Play(pThis, dwReserved1, dwPriority, dwFlags); }
static MA_INLINE HRESULT ma_IDirectSoundBuffer_SetCurrentPosition(ma_IDirectSoundBuffer* pThis, DWORD dwNewPosition) { return pThis->lpVtbl->SetCurrentPosition(pThis, dwNewPosition); }
-static MA_INLINE HRESULT ma_IDirectSoundBuffer_SetFormat(ma_IDirectSoundBuffer* pThis, const WAVEFORMATEX* pFormat) { return pThis->lpVtbl->SetFormat(pThis, pFormat); }
+static MA_INLINE HRESULT ma_IDirectSoundBuffer_SetFormat(ma_IDirectSoundBuffer* pThis, const MA_WAVEFORMATEX* pFormat) { return pThis->lpVtbl->SetFormat(pThis, pFormat); }
static MA_INLINE HRESULT ma_IDirectSoundBuffer_SetVolume(ma_IDirectSoundBuffer* pThis, LONG volume) { return pThis->lpVtbl->SetVolume(pThis, volume); }
static MA_INLINE HRESULT ma_IDirectSoundBuffer_SetPan(ma_IDirectSoundBuffer* pThis, LONG pan) { return pThis->lpVtbl->SetPan(pThis, pan); }
static MA_INLINE HRESULT ma_IDirectSoundBuffer_SetFrequency(ma_IDirectSoundBuffer* pThis, DWORD dwFrequency) { return pThis->lpVtbl->SetFrequency(pThis, dwFrequency); }
@@ -22891,7 +23877,7 @@ typedef struct
/* IDirectSoundCaptureBuffer */
HRESULT (STDMETHODCALLTYPE * GetCaps) (ma_IDirectSoundCaptureBuffer* pThis, MA_DSCBCAPS* pDSCBCaps);
HRESULT (STDMETHODCALLTYPE * GetCurrentPosition)(ma_IDirectSoundCaptureBuffer* pThis, DWORD* pCapturePosition, DWORD* pReadPosition);
- HRESULT (STDMETHODCALLTYPE * GetFormat) (ma_IDirectSoundCaptureBuffer* pThis, WAVEFORMATEX* pFormat, DWORD dwSizeAllocated, DWORD* pSizeWritten);
+ HRESULT (STDMETHODCALLTYPE * GetFormat) (ma_IDirectSoundCaptureBuffer* pThis, MA_WAVEFORMATEX* pFormat, DWORD dwSizeAllocated, DWORD* pSizeWritten);
HRESULT (STDMETHODCALLTYPE * GetStatus) (ma_IDirectSoundCaptureBuffer* pThis, DWORD* pStatus);
HRESULT (STDMETHODCALLTYPE * Initialize) (ma_IDirectSoundCaptureBuffer* pThis, ma_IDirectSoundCapture* pDirectSoundCapture, const MA_DSCBUFFERDESC* pDSCBufferDesc);
HRESULT (STDMETHODCALLTYPE * Lock) (ma_IDirectSoundCaptureBuffer* pThis, DWORD dwOffset, DWORD dwBytes, void** ppAudioPtr1, DWORD* pAudioBytes1, void** ppAudioPtr2, DWORD* pAudioBytes2, DWORD dwFlags);
@@ -22908,7 +23894,7 @@ static MA_INLINE ULONG ma_IDirectSoundCaptureBuffer_AddRef(ma_IDirectSoundCapt
static MA_INLINE ULONG ma_IDirectSoundCaptureBuffer_Release(ma_IDirectSoundCaptureBuffer* pThis) { return pThis->lpVtbl->Release(pThis); }
static MA_INLINE HRESULT ma_IDirectSoundCaptureBuffer_GetCaps(ma_IDirectSoundCaptureBuffer* pThis, MA_DSCBCAPS* pDSCBCaps) { return pThis->lpVtbl->GetCaps(pThis, pDSCBCaps); }
static MA_INLINE HRESULT ma_IDirectSoundCaptureBuffer_GetCurrentPosition(ma_IDirectSoundCaptureBuffer* pThis, DWORD* pCapturePosition, DWORD* pReadPosition) { return pThis->lpVtbl->GetCurrentPosition(pThis, pCapturePosition, pReadPosition); }
-static MA_INLINE HRESULT ma_IDirectSoundCaptureBuffer_GetFormat(ma_IDirectSoundCaptureBuffer* pThis, WAVEFORMATEX* pFormat, DWORD dwSizeAllocated, DWORD* pSizeWritten) { return pThis->lpVtbl->GetFormat(pThis, pFormat, dwSizeAllocated, pSizeWritten); }
+static MA_INLINE HRESULT ma_IDirectSoundCaptureBuffer_GetFormat(ma_IDirectSoundCaptureBuffer* pThis, MA_WAVEFORMATEX* pFormat, DWORD dwSizeAllocated, DWORD* pSizeWritten) { return pThis->lpVtbl->GetFormat(pThis, pFormat, dwSizeAllocated, pSizeWritten); }
static MA_INLINE HRESULT ma_IDirectSoundCaptureBuffer_GetStatus(ma_IDirectSoundCaptureBuffer* pThis, DWORD* pStatus) { return pThis->lpVtbl->GetStatus(pThis, pStatus); }
static MA_INLINE HRESULT ma_IDirectSoundCaptureBuffer_Initialize(ma_IDirectSoundCaptureBuffer* pThis, ma_IDirectSoundCapture* pDirectSoundCapture, const MA_DSCBUFFERDESC* pDSCBufferDesc) { return pThis->lpVtbl->Initialize(pThis, pDirectSoundCapture, pDSCBufferDesc); }
static MA_INLINE HRESULT ma_IDirectSoundCaptureBuffer_Lock(ma_IDirectSoundCaptureBuffer* pThis, DWORD dwOffset, DWORD dwBytes, void** ppAudioPtr1, DWORD* pAudioBytes1, void** ppAudioPtr2, DWORD* pAudioBytes2, DWORD dwFlags) { return pThis->lpVtbl->Lock(pThis, dwOffset, dwBytes, ppAudioPtr1, pAudioBytes1, ppAudioPtr2, pAudioBytes2, dwFlags); }
@@ -22938,11 +23924,11 @@ static MA_INLINE ULONG ma_IDirectSoundNotify_Release(ma_IDirectSoundNotify* pT
static MA_INLINE HRESULT ma_IDirectSoundNotify_SetNotificationPositions(ma_IDirectSoundNotify* pThis, DWORD dwPositionNotifies, const MA_DSBPOSITIONNOTIFY* pPositionNotifies) { return pThis->lpVtbl->SetNotificationPositions(pThis, dwPositionNotifies, pPositionNotifies); }
-typedef BOOL (CALLBACK * ma_DSEnumCallbackAProc) (LPGUID pDeviceGUID, LPCSTR pDeviceDescription, LPCSTR pModule, LPVOID pContext);
-typedef HRESULT (WINAPI * ma_DirectSoundCreateProc) (const GUID* pcGuidDevice, ma_IDirectSound** ppDS8, LPUNKNOWN pUnkOuter);
-typedef HRESULT (WINAPI * ma_DirectSoundEnumerateAProc) (ma_DSEnumCallbackAProc pDSEnumCallback, LPVOID pContext);
-typedef HRESULT (WINAPI * ma_DirectSoundCaptureCreateProc) (const GUID* pcGuidDevice, ma_IDirectSoundCapture** ppDSC8, LPUNKNOWN pUnkOuter);
-typedef HRESULT (WINAPI * ma_DirectSoundCaptureEnumerateAProc)(ma_DSEnumCallbackAProc pDSEnumCallback, LPVOID pContext);
+typedef BOOL (CALLBACK * ma_DSEnumCallbackAProc) (GUID* pDeviceGUID, const char* pDeviceDescription, const char* pModule, void* pContext);
+typedef HRESULT (WINAPI * ma_DirectSoundCreateProc) (const GUID* pcGuidDevice, ma_IDirectSound** ppDS8, ma_IUnknown* pUnkOuter);
+typedef HRESULT (WINAPI * ma_DirectSoundEnumerateAProc) (ma_DSEnumCallbackAProc pDSEnumCallback, void* pContext);
+typedef HRESULT (WINAPI * ma_DirectSoundCaptureCreateProc) (const GUID* pcGuidDevice, ma_IDirectSoundCapture** ppDSC8, ma_IUnknown* pUnkOuter);
+typedef HRESULT (WINAPI * ma_DirectSoundCaptureEnumerateAProc)(ma_DSEnumCallbackAProc pDSEnumCallback, void* pContext);
static ma_uint32 ma_get_best_sample_rate_within_range(ma_uint32 sampleRateMin, ma_uint32 sampleRateMax)
{
@@ -23039,7 +24025,7 @@ static ma_result ma_context_create_IDirectSound__dsound(ma_context* pContext, ma
/* The cooperative level must be set before doing anything else. */
hWnd = ((MA_PFN_GetForegroundWindow)pContext->win32.GetForegroundWindow)();
- if (hWnd == NULL) {
+ if (hWnd == 0) {
hWnd = ((MA_PFN_GetDesktopWindow)pContext->win32.GetDesktopWindow)();
}
@@ -23191,7 +24177,7 @@ typedef struct
ma_bool32 terminated;
} ma_context_enumerate_devices_callback_data__dsound;
-static BOOL CALLBACK ma_context_enumerate_devices_callback__dsound(LPGUID lpGuid, LPCSTR lpcstrDescription, LPCSTR lpcstrModule, LPVOID lpContext)
+static BOOL CALLBACK ma_context_enumerate_devices_callback__dsound(GUID* lpGuid, const char* lpcstrDescription, const char* lpcstrModule, void* lpContext)
{
ma_context_enumerate_devices_callback_data__dsound* pData = (ma_context_enumerate_devices_callback_data__dsound*)lpContext;
ma_device_info deviceInfo;
@@ -23214,7 +24200,7 @@ static BOOL CALLBACK ma_context_enumerate_devices_callback__dsound(LPGUID lpGuid
/* Call the callback function, but make sure we stop enumerating if the callee requested so. */
MA_ASSERT(pData != NULL);
- pData->terminated = !pData->callback(pData->pContext, pData->deviceType, &deviceInfo, pData->pUserData);
+ pData->terminated = (pData->callback(pData->pContext, pData->deviceType, &deviceInfo, pData->pUserData) == MA_FALSE);
if (pData->terminated) {
return FALSE; /* Stop enumeration. */
} else {
@@ -23257,7 +24243,7 @@ typedef struct
ma_bool32 found;
} ma_context_get_device_info_callback_data__dsound;
-static BOOL CALLBACK ma_context_get_device_info_callback__dsound(LPGUID lpGuid, LPCSTR lpcstrDescription, LPCSTR lpcstrModule, LPVOID lpContext)
+static BOOL CALLBACK ma_context_get_device_info_callback__dsound(GUID* lpGuid, const char* lpcstrDescription, const char* lpcstrModule, void* lpContext)
{
ma_context_get_device_info_callback_data__dsound* pData = (ma_context_get_device_info_callback_data__dsound*)lpContext;
MA_ASSERT(pData != NULL);
@@ -23462,7 +24448,7 @@ static ma_result ma_device_uninit__dsound(ma_device* pDevice)
return MA_SUCCESS;
}
-static ma_result ma_config_to_WAVEFORMATEXTENSIBLE(ma_format format, ma_uint32 channels, ma_uint32 sampleRate, const ma_channel* pChannelMap, WAVEFORMATEXTENSIBLE* pWF)
+static ma_result ma_config_to_WAVEFORMATEXTENSIBLE(ma_format format, ma_uint32 channels, ma_uint32 sampleRate, const ma_channel* pChannelMap, MA_WAVEFORMATEXTENSIBLE* pWF)
{
GUID subformat;
@@ -23499,14 +24485,14 @@ static ma_result ma_config_to_WAVEFORMATEXTENSIBLE(ma_format format, ma_uint32 c
}
MA_ZERO_OBJECT(pWF);
- pWF->Format.cbSize = sizeof(*pWF);
- pWF->Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
- pWF->Format.nChannels = (WORD)channels;
- pWF->Format.nSamplesPerSec = (DWORD)sampleRate;
- pWF->Format.wBitsPerSample = (WORD)(ma_get_bytes_per_sample(format)*8);
- pWF->Format.nBlockAlign = (WORD)(pWF->Format.nChannels * pWF->Format.wBitsPerSample / 8);
- pWF->Format.nAvgBytesPerSec = pWF->Format.nBlockAlign * pWF->Format.nSamplesPerSec;
- pWF->Samples.wValidBitsPerSample = pWF->Format.wBitsPerSample;
+ pWF->cbSize = sizeof(*pWF);
+ pWF->wFormatTag = WAVE_FORMAT_EXTENSIBLE;
+ pWF->nChannels = (WORD)channels;
+ pWF->nSamplesPerSec = (DWORD)sampleRate;
+ pWF->wBitsPerSample = (WORD)(ma_get_bytes_per_sample(format)*8);
+ pWF->nBlockAlign = (WORD)(pWF->nChannels * pWF->wBitsPerSample / 8);
+ pWF->nAvgBytesPerSec = pWF->nBlockAlign * pWF->nSamplesPerSec;
+ pWF->Samples.wValidBitsPerSample = pWF->wBitsPerSample;
pWF->dwChannelMask = ma_channel_map_to_channel_mask__win32(pChannelMap, channels);
pWF->SubFormat = subformat;
@@ -23549,12 +24535,12 @@ static ma_result ma_device_init__dsound(ma_device* pDevice, const ma_device_conf
full-duplex mode.
*/
if (pConfig->deviceType == ma_device_type_capture || pConfig->deviceType == ma_device_type_duplex) {
- WAVEFORMATEXTENSIBLE wf;
+ MA_WAVEFORMATEXTENSIBLE wf;
MA_DSCBUFFERDESC descDS;
ma_uint32 periodSizeInFrames;
ma_uint32 periodCount;
char rawdata[1024]; /* <-- Ugly hack to avoid a malloc() due to a crappy DirectSound API. */
- WAVEFORMATEXTENSIBLE* pActualFormat;
+ MA_WAVEFORMATEXTENSIBLE* pActualFormat;
result = ma_config_to_WAVEFORMATEXTENSIBLE(pDescriptorCapture->format, pDescriptorCapture->channels, pDescriptorCapture->sampleRate, pDescriptorCapture->channelMap, &wf);
if (result != MA_SUCCESS) {
@@ -23567,26 +24553,26 @@ static ma_result ma_device_init__dsound(ma_device* pDevice, const ma_device_conf
return result;
}
- result = ma_context_get_format_info_for_IDirectSoundCapture__dsound(pDevice->pContext, (ma_IDirectSoundCapture*)pDevice->dsound.pCapture, &wf.Format.nChannels, &wf.Format.wBitsPerSample, &wf.Format.nSamplesPerSec);
+ result = ma_context_get_format_info_for_IDirectSoundCapture__dsound(pDevice->pContext, (ma_IDirectSoundCapture*)pDevice->dsound.pCapture, &wf.nChannels, &wf.wBitsPerSample, &wf.nSamplesPerSec);
if (result != MA_SUCCESS) {
ma_device_uninit__dsound(pDevice);
return result;
}
- wf.Format.nBlockAlign = (WORD)(wf.Format.nChannels * wf.Format.wBitsPerSample / 8);
- wf.Format.nAvgBytesPerSec = wf.Format.nBlockAlign * wf.Format.nSamplesPerSec;
- wf.Samples.wValidBitsPerSample = wf.Format.wBitsPerSample;
+ wf.nBlockAlign = (WORD)(wf.nChannels * wf.wBitsPerSample / 8);
+ wf.nAvgBytesPerSec = wf.nBlockAlign * wf.nSamplesPerSec;
+ wf.Samples.wValidBitsPerSample = wf.wBitsPerSample;
wf.SubFormat = MA_GUID_KSDATAFORMAT_SUBTYPE_PCM;
/* The size of the buffer must be a clean multiple of the period count. */
- periodSizeInFrames = ma_calculate_period_size_in_frames_from_descriptor__dsound(pDescriptorCapture, wf.Format.nSamplesPerSec, pConfig->performanceProfile);
+ periodSizeInFrames = ma_calculate_period_size_in_frames_from_descriptor__dsound(pDescriptorCapture, wf.nSamplesPerSec, pConfig->performanceProfile);
periodCount = (pDescriptorCapture->periodCount > 0) ? pDescriptorCapture->periodCount : MA_DEFAULT_PERIODS;
MA_ZERO_OBJECT(&descDS);
descDS.dwSize = sizeof(descDS);
descDS.dwFlags = 0;
- descDS.dwBufferBytes = periodSizeInFrames * periodCount * wf.Format.nBlockAlign;
- descDS.lpwfxFormat = (WAVEFORMATEX*)&wf;
+ descDS.dwBufferBytes = periodSizeInFrames * periodCount * wf.nBlockAlign;
+ descDS.lpwfxFormat = (MA_WAVEFORMATEX*)&wf;
hr = ma_IDirectSoundCapture_CreateCaptureBuffer((ma_IDirectSoundCapture*)pDevice->dsound.pCapture, &descDS, (ma_IDirectSoundCaptureBuffer**)&pDevice->dsound.pCaptureBuffer, NULL);
if (FAILED(hr)) {
ma_device_uninit__dsound(pDevice);
@@ -23595,8 +24581,8 @@ static ma_result ma_device_init__dsound(ma_device* pDevice, const ma_device_conf
}
/* Get the _actual_ properties of the buffer. */
- pActualFormat = (WAVEFORMATEXTENSIBLE*)rawdata;
- hr = ma_IDirectSoundCaptureBuffer_GetFormat((ma_IDirectSoundCaptureBuffer*)pDevice->dsound.pCaptureBuffer, (WAVEFORMATEX*)pActualFormat, sizeof(rawdata), NULL);
+ pActualFormat = (MA_WAVEFORMATEXTENSIBLE*)rawdata;
+ hr = ma_IDirectSoundCaptureBuffer_GetFormat((ma_IDirectSoundCaptureBuffer*)pDevice->dsound.pCaptureBuffer, (MA_WAVEFORMATEX*)pActualFormat, sizeof(rawdata), NULL);
if (FAILED(hr)) {
ma_device_uninit__dsound(pDevice);
ma_log_post(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[DirectSound] Failed to retrieve the actual format of the capture device's buffer.");
@@ -23604,12 +24590,12 @@ static ma_result ma_device_init__dsound(ma_device* pDevice, const ma_device_conf
}
/* We can now start setting the output data formats. */
- pDescriptorCapture->format = ma_format_from_WAVEFORMATEX((WAVEFORMATEX*)pActualFormat);
- pDescriptorCapture->channels = pActualFormat->Format.nChannels;
- pDescriptorCapture->sampleRate = pActualFormat->Format.nSamplesPerSec;
+ pDescriptorCapture->format = ma_format_from_WAVEFORMATEX((MA_WAVEFORMATEX*)pActualFormat);
+ pDescriptorCapture->channels = pActualFormat->nChannels;
+ pDescriptorCapture->sampleRate = pActualFormat->nSamplesPerSec;
/* Get the native channel map based on the channel mask. */
- if (pActualFormat->Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE) {
+ if (pActualFormat->wFormatTag == WAVE_FORMAT_EXTENSIBLE) {
ma_channel_mask_to_channel_map__win32(pActualFormat->dwChannelMask, pDescriptorCapture->channels, pDescriptorCapture->channelMap);
} else {
ma_channel_mask_to_channel_map__win32(wf.dwChannelMask, pDescriptorCapture->channels, pDescriptorCapture->channelMap);
@@ -23637,14 +24623,16 @@ static ma_result ma_device_init__dsound(ma_device* pDevice, const ma_device_conf
}
if (pConfig->deviceType == ma_device_type_playback || pConfig->deviceType == ma_device_type_duplex) {
- WAVEFORMATEXTENSIBLE wf;
+ MA_WAVEFORMATEXTENSIBLE wf;
MA_DSBUFFERDESC descDSPrimary;
MA_DSCAPS caps;
char rawdata[1024]; /* <-- Ugly hack to avoid a malloc() due to a crappy DirectSound API. */
- WAVEFORMATEXTENSIBLE* pActualFormat;
+ MA_WAVEFORMATEXTENSIBLE* pActualFormat;
ma_uint32 periodSizeInFrames;
ma_uint32 periodCount;
MA_DSBUFFERDESC descDS;
+ WORD nativeChannelCount;
+ DWORD nativeChannelMask = 0;
result = ma_config_to_WAVEFORMATEXTENSIBLE(pDescriptorPlayback->format, pDescriptorPlayback->channels, pDescriptorPlayback->sampleRate, pDescriptorPlayback->channelMap, &wf);
if (result != MA_SUCCESS) {
@@ -23678,34 +24666,38 @@ static ma_result ma_device_init__dsound(ma_device* pDevice, const ma_device_conf
return ma_result_from_HRESULT(hr);
}
- if (pDescriptorPlayback->channels == 0) {
- if ((caps.dwFlags & MA_DSCAPS_PRIMARYSTEREO) != 0) {
- DWORD speakerConfig;
+ if ((caps.dwFlags & MA_DSCAPS_PRIMARYSTEREO) != 0) {
+ DWORD speakerConfig;
- /* It supports at least stereo, but could support more. */
- wf.Format.nChannels = 2;
+ /* It supports at least stereo, but could support more. */
+ nativeChannelCount = 2;
- /* Look at the speaker configuration to get a better idea on the channel count. */
- if (SUCCEEDED(ma_IDirectSound_GetSpeakerConfig((ma_IDirectSound*)pDevice->dsound.pPlayback, &speakerConfig))) {
- ma_get_channels_from_speaker_config__dsound(speakerConfig, &wf.Format.nChannels, &wf.dwChannelMask);
- }
- } else {
- /* It does not support stereo, which means we are stuck with mono. */
- wf.Format.nChannels = 1;
+ /* Look at the speaker configuration to get a better idea on the channel count. */
+ if (SUCCEEDED(ma_IDirectSound_GetSpeakerConfig((ma_IDirectSound*)pDevice->dsound.pPlayback, &speakerConfig))) {
+ ma_get_channels_from_speaker_config__dsound(speakerConfig, &nativeChannelCount, &nativeChannelMask);
}
+ } else {
+ /* It does not support stereo, which means we are stuck with mono. */
+ nativeChannelCount = 1;
+ nativeChannelMask = 0x00000001;
+ }
+
+ if (pDescriptorPlayback->channels == 0) {
+ wf.nChannels = nativeChannelCount;
+ wf.dwChannelMask = nativeChannelMask;
}
if (pDescriptorPlayback->sampleRate == 0) {
/* We base the sample rate on the values returned by GetCaps(). */
if ((caps.dwFlags & MA_DSCAPS_CONTINUOUSRATE) != 0) {
- wf.Format.nSamplesPerSec = ma_get_best_sample_rate_within_range(caps.dwMinSecondarySampleRate, caps.dwMaxSecondarySampleRate);
+ wf.nSamplesPerSec = ma_get_best_sample_rate_within_range(caps.dwMinSecondarySampleRate, caps.dwMaxSecondarySampleRate);
} else {
- wf.Format.nSamplesPerSec = caps.dwMaxSecondarySampleRate;
+ wf.nSamplesPerSec = caps.dwMaxSecondarySampleRate;
}
}
- wf.Format.nBlockAlign = (WORD)(wf.Format.nChannels * wf.Format.wBitsPerSample / 8);
- wf.Format.nAvgBytesPerSec = wf.Format.nBlockAlign * wf.Format.nSamplesPerSec;
+ wf.nBlockAlign = (WORD)(wf.nChannels * wf.wBitsPerSample / 8);
+ wf.nAvgBytesPerSec = wf.nBlockAlign * wf.nSamplesPerSec;
/*
From MSDN:
@@ -23714,16 +24706,33 @@ static ma_result ma_device_init__dsound(ma_device* pDevice, const ma_device_conf
supported format. To determine whether this has happened, an application can call the GetFormat method for the primary buffer
and compare the result with the format that was requested with the SetFormat method.
*/
- hr = ma_IDirectSoundBuffer_SetFormat((ma_IDirectSoundBuffer*)pDevice->dsound.pPlaybackPrimaryBuffer, (WAVEFORMATEX*)&wf);
+ hr = ma_IDirectSoundBuffer_SetFormat((ma_IDirectSoundBuffer*)pDevice->dsound.pPlaybackPrimaryBuffer, (MA_WAVEFORMATEX*)&wf);
if (FAILED(hr)) {
- ma_device_uninit__dsound(pDevice);
- ma_log_post(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[DirectSound] Failed to set format of playback device's primary buffer.");
- return ma_result_from_HRESULT(hr);
+ /*
+ If setting of the format failed we'll try again with some fallback settings. On Windows 98 I have
+ observed that IEEE_FLOAT does not work. We'll therefore enforce PCM. I also had issues where a
+ sample rate of 48000 did not work correctly. Not sure if it was a driver issue or not, but will
+ use 44100 for the sample rate.
+ */
+ wf.cbSize = 18; /* NOTE: Don't use sizeof(MA_WAVEFORMATEX) here because it's got an extra 2 bytes due to padding. */
+ wf.wFormatTag = WAVE_FORMAT_PCM;
+ wf.wBitsPerSample = 16;
+ wf.nChannels = nativeChannelCount;
+ wf.nSamplesPerSec = 44100;
+ wf.nBlockAlign = wf.nChannels * (wf.wBitsPerSample / 8);
+ wf.nAvgBytesPerSec = wf.nSamplesPerSec * wf.nBlockAlign;
+
+ hr = ma_IDirectSoundBuffer_SetFormat((ma_IDirectSoundBuffer*)pDevice->dsound.pPlaybackPrimaryBuffer, (MA_WAVEFORMATEX*)&wf);
+ if (FAILED(hr)) {
+ ma_device_uninit__dsound(pDevice);
+ ma_log_post(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[DirectSound] Failed to set format of playback device's primary buffer.");
+ return ma_result_from_HRESULT(hr);
+ }
}
/* Get the _actual_ properties of the buffer. */
- pActualFormat = (WAVEFORMATEXTENSIBLE*)rawdata;
- hr = ma_IDirectSoundBuffer_GetFormat((ma_IDirectSoundBuffer*)pDevice->dsound.pPlaybackPrimaryBuffer, (WAVEFORMATEX*)pActualFormat, sizeof(rawdata), NULL);
+ pActualFormat = (MA_WAVEFORMATEXTENSIBLE*)rawdata;
+ hr = ma_IDirectSoundBuffer_GetFormat((ma_IDirectSoundBuffer*)pDevice->dsound.pPlaybackPrimaryBuffer, (MA_WAVEFORMATEX*)pActualFormat, sizeof(rawdata), NULL);
if (FAILED(hr)) {
ma_device_uninit__dsound(pDevice);
ma_log_post(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[DirectSound] Failed to retrieve the actual format of the playback device's primary buffer.");
@@ -23731,12 +24740,12 @@ static ma_result ma_device_init__dsound(ma_device* pDevice, const ma_device_conf
}
/* We now have enough information to start setting some output properties. */
- pDescriptorPlayback->format = ma_format_from_WAVEFORMATEX((WAVEFORMATEX*)pActualFormat);
- pDescriptorPlayback->channels = pActualFormat->Format.nChannels;
- pDescriptorPlayback->sampleRate = pActualFormat->Format.nSamplesPerSec;
+ pDescriptorPlayback->format = ma_format_from_WAVEFORMATEX((MA_WAVEFORMATEX*)pActualFormat);
+ pDescriptorPlayback->channels = pActualFormat->nChannels;
+ pDescriptorPlayback->sampleRate = pActualFormat->nSamplesPerSec;
/* Get the internal channel map based on the channel mask. */
- if (pActualFormat->Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE) {
+ if (pActualFormat->wFormatTag == WAVE_FORMAT_EXTENSIBLE) {
ma_channel_mask_to_channel_map__win32(pActualFormat->dwChannelMask, pDescriptorPlayback->channels, pDescriptorPlayback->channelMap);
} else {
ma_channel_mask_to_channel_map__win32(wf.dwChannelMask, pDescriptorPlayback->channels, pDescriptorPlayback->channelMap);
@@ -23765,7 +24774,7 @@ static ma_result ma_device_init__dsound(ma_device* pDevice, const ma_device_conf
descDS.dwSize = sizeof(descDS);
descDS.dwFlags = MA_DSBCAPS_CTRLPOSITIONNOTIFY | MA_DSBCAPS_GLOBALFOCUS | MA_DSBCAPS_GETCURRENTPOSITION2;
descDS.dwBufferBytes = periodSizeInFrames * periodCount * ma_get_bytes_per_frame(pDescriptorPlayback->format, pDescriptorPlayback->channels);
- descDS.lpwfxFormat = (WAVEFORMATEX*)&wf;
+ descDS.lpwfxFormat = (MA_WAVEFORMATEX*)pActualFormat;
hr = ma_IDirectSound_CreateSoundBuffer((ma_IDirectSound*)pDevice->dsound.pPlayback, &descDS, (ma_IDirectSoundBuffer**)&pDevice->dsound.pPlaybackBuffer, NULL);
if (FAILED(hr)) {
ma_device_uninit__dsound(pDevice);
@@ -24301,7 +25310,7 @@ static ma_result ma_context_uninit__dsound(ma_context* pContext)
MA_ASSERT(pContext != NULL);
MA_ASSERT(pContext->backend == ma_backend_dsound);
- ma_dlclose(pContext, pContext->dsound.hDSoundDLL);
+ ma_dlclose(ma_context_get_log(pContext), pContext->dsound.hDSoundDLL);
return MA_SUCCESS;
}
@@ -24312,15 +25321,27 @@ static ma_result ma_context_init__dsound(ma_context* pContext, const ma_context_
(void)pConfig;
- pContext->dsound.hDSoundDLL = ma_dlopen(pContext, "dsound.dll");
+ pContext->dsound.hDSoundDLL = ma_dlopen(ma_context_get_log(pContext), "dsound.dll");
if (pContext->dsound.hDSoundDLL == NULL) {
return MA_API_NOT_FOUND;
}
- pContext->dsound.DirectSoundCreate = ma_dlsym(pContext, pContext->dsound.hDSoundDLL, "DirectSoundCreate");
- pContext->dsound.DirectSoundEnumerateA = ma_dlsym(pContext, pContext->dsound.hDSoundDLL, "DirectSoundEnumerateA");
- pContext->dsound.DirectSoundCaptureCreate = ma_dlsym(pContext, pContext->dsound.hDSoundDLL, "DirectSoundCaptureCreate");
- pContext->dsound.DirectSoundCaptureEnumerateA = ma_dlsym(pContext, pContext->dsound.hDSoundDLL, "DirectSoundCaptureEnumerateA");
+ pContext->dsound.DirectSoundCreate = ma_dlsym(ma_context_get_log(pContext), pContext->dsound.hDSoundDLL, "DirectSoundCreate");
+ pContext->dsound.DirectSoundEnumerateA = ma_dlsym(ma_context_get_log(pContext), pContext->dsound.hDSoundDLL, "DirectSoundEnumerateA");
+ pContext->dsound.DirectSoundCaptureCreate = ma_dlsym(ma_context_get_log(pContext), pContext->dsound.hDSoundDLL, "DirectSoundCaptureCreate");
+ pContext->dsound.DirectSoundCaptureEnumerateA = ma_dlsym(ma_context_get_log(pContext), pContext->dsound.hDSoundDLL, "DirectSoundCaptureEnumerateA");
+
+ /*
+ We need to support all functions or nothing. DirectSound with Windows 95 seems to not work too
+ well in my testing. For example, it's missing DirectSoundCaptureEnumerateA(). This is a convenient
+ place to just disable the DirectSound backend for Windows 95.
+ */
+ if (pContext->dsound.DirectSoundCreate == NULL ||
+ pContext->dsound.DirectSoundEnumerateA == NULL ||
+ pContext->dsound.DirectSoundCaptureCreate == NULL ||
+ pContext->dsound.DirectSoundCaptureEnumerateA == NULL) {
+ return MA_API_NOT_FOUND;
+ }
pCallbacks->onContextInit = ma_context_init__dsound;
pCallbacks->onContextUninit = ma_context_uninit__dsound;
@@ -24348,16 +25369,75 @@ WinMM Backend
#ifdef MA_HAS_WINMM
/*
-Some older compilers don't have WAVEOUTCAPS2A and WAVEINCAPS2A, so we'll need to write this ourselves. These structures
-are exactly the same as the older ones but they have a few GUIDs for manufacturer/product/name identification. I'm keeping
-the names the same as the Win32 library for consistency, but namespaced to avoid naming conflicts with the Win32 version.
+Some build configurations will exclude the WinMM API. An example is when WIN32_LEAN_AND_MEAN
+is defined. We need to define the types and functions we need manually.
*/
+#define MA_MMSYSERR_NOERROR 0
+#define MA_MMSYSERR_ERROR 1
+#define MA_MMSYSERR_BADDEVICEID 2
+#define MA_MMSYSERR_INVALHANDLE 5
+#define MA_MMSYSERR_NOMEM 7
+#define MA_MMSYSERR_INVALFLAG 10
+#define MA_MMSYSERR_INVALPARAM 11
+#define MA_MMSYSERR_HANDLEBUSY 12
+
+#define MA_CALLBACK_EVENT 0x00050000
+#define MA_WAVE_ALLOWSYNC 0x0002
+
+#define MA_WHDR_DONE 0x00000001
+#define MA_WHDR_PREPARED 0x00000002
+#define MA_WHDR_BEGINLOOP 0x00000004
+#define MA_WHDR_ENDLOOP 0x00000008
+#define MA_WHDR_INQUEUE 0x00000010
+
+#define MA_MAXPNAMELEN 32
+
+typedef void* MA_HWAVEIN;
+typedef void* MA_HWAVEOUT;
+typedef UINT MA_MMRESULT;
+typedef UINT MA_MMVERSION;
+
typedef struct
{
WORD wMid;
WORD wPid;
- MMVERSION vDriverVersion;
- CHAR szPname[MAXPNAMELEN];
+ MA_MMVERSION vDriverVersion;
+ CHAR szPname[MA_MAXPNAMELEN];
+ DWORD dwFormats;
+ WORD wChannels;
+ WORD wReserved1;
+} MA_WAVEINCAPSA;
+
+typedef struct
+{
+ WORD wMid;
+ WORD wPid;
+ MA_MMVERSION vDriverVersion;
+ CHAR szPname[MA_MAXPNAMELEN];
+ DWORD dwFormats;
+ WORD wChannels;
+ WORD wReserved1;
+ DWORD dwSupport;
+} MA_WAVEOUTCAPSA;
+
+typedef struct tagWAVEHDR
+{
+ char* lpData;
+ DWORD dwBufferLength;
+ DWORD dwBytesRecorded;
+ DWORD_PTR dwUser;
+ DWORD dwFlags;
+ DWORD dwLoops;
+ struct tagWAVEHDR* lpNext;
+ DWORD_PTR reserved;
+} MA_WAVEHDR;
+
+typedef struct
+{
+ WORD wMid;
+ WORD wPid;
+ MA_MMVERSION vDriverVersion;
+ CHAR szPname[MA_MAXPNAMELEN];
DWORD dwFormats;
WORD wChannels;
WORD wReserved1;
@@ -24366,12 +25446,13 @@ typedef struct
GUID ProductGuid;
GUID NameGuid;
} MA_WAVEOUTCAPS2A;
+
typedef struct
{
WORD wMid;
WORD wPid;
- MMVERSION vDriverVersion;
- CHAR szPname[MAXPNAMELEN];
+ MA_MMVERSION vDriverVersion;
+ CHAR szPname[MA_MAXPNAMELEN];
DWORD dwFormats;
WORD wChannels;
WORD wReserved1;
@@ -24380,36 +25461,37 @@ typedef struct
GUID NameGuid;
} MA_WAVEINCAPS2A;
-typedef UINT (WINAPI * MA_PFN_waveOutGetNumDevs)(void);
-typedef MMRESULT (WINAPI * MA_PFN_waveOutGetDevCapsA)(ma_uintptr uDeviceID, LPWAVEOUTCAPSA pwoc, UINT cbwoc);
-typedef MMRESULT (WINAPI * MA_PFN_waveOutOpen)(LPHWAVEOUT phwo, UINT uDeviceID, LPCWAVEFORMATEX pwfx, DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD fdwOpen);
-typedef MMRESULT (WINAPI * MA_PFN_waveOutClose)(HWAVEOUT hwo);
-typedef MMRESULT (WINAPI * MA_PFN_waveOutPrepareHeader)(HWAVEOUT hwo, LPWAVEHDR pwh, UINT cbwh);
-typedef MMRESULT (WINAPI * MA_PFN_waveOutUnprepareHeader)(HWAVEOUT hwo, LPWAVEHDR pwh, UINT cbwh);
-typedef MMRESULT (WINAPI * MA_PFN_waveOutWrite)(HWAVEOUT hwo, LPWAVEHDR pwh, UINT cbwh);
-typedef MMRESULT (WINAPI * MA_PFN_waveOutReset)(HWAVEOUT hwo);
-typedef UINT (WINAPI * MA_PFN_waveInGetNumDevs)(void);
-typedef MMRESULT (WINAPI * MA_PFN_waveInGetDevCapsA)(ma_uintptr uDeviceID, LPWAVEINCAPSA pwic, UINT cbwic);
-typedef MMRESULT (WINAPI * MA_PFN_waveInOpen)(LPHWAVEIN phwi, UINT uDeviceID, LPCWAVEFORMATEX pwfx, DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD fdwOpen);
-typedef MMRESULT (WINAPI * MA_PFN_waveInClose)(HWAVEIN hwi);
-typedef MMRESULT (WINAPI * MA_PFN_waveInPrepareHeader)(HWAVEIN hwi, LPWAVEHDR pwh, UINT cbwh);
-typedef MMRESULT (WINAPI * MA_PFN_waveInUnprepareHeader)(HWAVEIN hwi, LPWAVEHDR pwh, UINT cbwh);
-typedef MMRESULT (WINAPI * MA_PFN_waveInAddBuffer)(HWAVEIN hwi, LPWAVEHDR pwh, UINT cbwh);
-typedef MMRESULT (WINAPI * MA_PFN_waveInStart)(HWAVEIN hwi);
-typedef MMRESULT (WINAPI * MA_PFN_waveInReset)(HWAVEIN hwi);
-
-static ma_result ma_result_from_MMRESULT(MMRESULT resultMM)
-{
- switch (resultMM) {
- case MMSYSERR_NOERROR: return MA_SUCCESS;
- case MMSYSERR_BADDEVICEID: return MA_INVALID_ARGS;
- case MMSYSERR_INVALHANDLE: return MA_INVALID_ARGS;
- case MMSYSERR_NOMEM: return MA_OUT_OF_MEMORY;
- case MMSYSERR_INVALFLAG: return MA_INVALID_ARGS;
- case MMSYSERR_INVALPARAM: return MA_INVALID_ARGS;
- case MMSYSERR_HANDLEBUSY: return MA_BUSY;
- case MMSYSERR_ERROR: return MA_ERROR;
- default: return MA_ERROR;
+typedef UINT (WINAPI * MA_PFN_waveOutGetNumDevs)(void);
+typedef MA_MMRESULT (WINAPI * MA_PFN_waveOutGetDevCapsA)(ma_uintptr uDeviceID, MA_WAVEOUTCAPSA* pwoc, UINT cbwoc);
+typedef MA_MMRESULT (WINAPI * MA_PFN_waveOutOpen)(MA_HWAVEOUT* phwo, UINT uDeviceID, const MA_WAVEFORMATEX* pwfx, DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD fdwOpen);
+typedef MA_MMRESULT (WINAPI * MA_PFN_waveOutClose)(MA_HWAVEOUT hwo);
+typedef MA_MMRESULT (WINAPI * MA_PFN_waveOutPrepareHeader)(MA_HWAVEOUT hwo, MA_WAVEHDR* pwh, UINT cbwh);
+typedef MA_MMRESULT (WINAPI * MA_PFN_waveOutUnprepareHeader)(MA_HWAVEOUT hwo, MA_WAVEHDR* pwh, UINT cbwh);
+typedef MA_MMRESULT (WINAPI * MA_PFN_waveOutWrite)(MA_HWAVEOUT hwo, MA_WAVEHDR* pwh, UINT cbwh);
+typedef MA_MMRESULT (WINAPI * MA_PFN_waveOutReset)(MA_HWAVEOUT hwo);
+typedef UINT (WINAPI * MA_PFN_waveInGetNumDevs)(void);
+typedef MA_MMRESULT (WINAPI * MA_PFN_waveInGetDevCapsA)(ma_uintptr uDeviceID, MA_WAVEINCAPSA* pwic, UINT cbwic);
+typedef MA_MMRESULT (WINAPI * MA_PFN_waveInOpen)(MA_HWAVEIN* phwi, UINT uDeviceID, const MA_WAVEFORMATEX* pwfx, DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD fdwOpen);
+typedef MA_MMRESULT (WINAPI * MA_PFN_waveInClose)(MA_HWAVEIN hwi);
+typedef MA_MMRESULT (WINAPI * MA_PFN_waveInPrepareHeader)(MA_HWAVEIN hwi, MA_WAVEHDR* pwh, UINT cbwh);
+typedef MA_MMRESULT (WINAPI * MA_PFN_waveInUnprepareHeader)(MA_HWAVEIN hwi, MA_WAVEHDR* pwh, UINT cbwh);
+typedef MA_MMRESULT (WINAPI * MA_PFN_waveInAddBuffer)(MA_HWAVEIN hwi, MA_WAVEHDR* pwh, UINT cbwh);
+typedef MA_MMRESULT (WINAPI * MA_PFN_waveInStart)(MA_HWAVEIN hwi);
+typedef MA_MMRESULT (WINAPI * MA_PFN_waveInReset)(MA_HWAVEIN hwi);
+
+static ma_result ma_result_from_MMRESULT(MA_MMRESULT resultMM)
+{
+ switch (resultMM)
+ {
+ case MA_MMSYSERR_NOERROR: return MA_SUCCESS;
+ case MA_MMSYSERR_BADDEVICEID: return MA_INVALID_ARGS;
+ case MA_MMSYSERR_INVALHANDLE: return MA_INVALID_ARGS;
+ case MA_MMSYSERR_NOMEM: return MA_OUT_OF_MEMORY;
+ case MA_MMSYSERR_INVALFLAG: return MA_INVALID_ARGS;
+ case MA_MMSYSERR_INVALPARAM: return MA_INVALID_ARGS;
+ case MA_MMSYSERR_HANDLEBUSY: return MA_BUSY;
+ case MA_MMSYSERR_ERROR: return MA_ERROR;
+ default: return MA_ERROR;
}
}
@@ -24445,7 +25527,7 @@ we can do things generically and typesafely. Names are being kept the same for c
*/
typedef struct
{
- CHAR szPname[MAXPNAMELEN];
+ CHAR szPname[MA_MAXPNAMELEN];
DWORD dwFormats;
WORD wChannels;
GUID NameGuid;
@@ -24531,7 +25613,7 @@ static ma_result ma_get_best_info_from_formats_flags__winmm(DWORD dwFormats, WOR
return MA_SUCCESS;
}
-static ma_result ma_formats_flags_to_WAVEFORMATEX__winmm(DWORD dwFormats, WORD channels, WAVEFORMATEX* pWF)
+static ma_result ma_formats_flags_to_WAVEFORMATEX__winmm(DWORD dwFormats, WORD channels, MA_WAVEFORMATEX* pWF)
{
ma_result result;
@@ -24588,7 +25670,7 @@ static ma_result ma_context_get_device_info_from_WAVECAPS(ma_context* pContext,
name, and then concatenate the name from the registry.
*/
if (!ma_is_guid_null(&pCaps->NameGuid)) {
- wchar_t guidStrW[256];
+ WCHAR guidStrW[256];
if (((MA_PFN_StringFromGUID2)pContext->win32.StringFromGUID2)(&pCaps->NameGuid, guidStrW, ma_countof(guidStrW)) > 0) {
char guidStr[256];
char keyStr[1024];
@@ -24602,7 +25684,7 @@ static ma_result ma_context_get_device_info_from_WAVECAPS(ma_context* pContext,
if (((MA_PFN_RegOpenKeyExA)pContext->win32.RegOpenKeyExA)(HKEY_LOCAL_MACHINE, keyStr, 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
BYTE nameFromReg[512];
DWORD nameFromRegSize = sizeof(nameFromReg);
- LONG resultWin32 = ((MA_PFN_RegQueryValueExA)pContext->win32.RegQueryValueExA)(hKey, "Name", 0, NULL, (LPBYTE)nameFromReg, (LPDWORD)&nameFromRegSize);
+ LONG resultWin32 = ((MA_PFN_RegQueryValueExA)pContext->win32.RegQueryValueExA)(hKey, "Name", 0, NULL, (BYTE*)nameFromReg, (DWORD*)&nameFromRegSize);
((MA_PFN_RegCloseKey)pContext->win32.RegCloseKey)(hKey);
if (resultWin32 == ERROR_SUCCESS) {
@@ -24696,13 +25778,13 @@ static ma_result ma_context_enumerate_devices__winmm(ma_context* pContext, ma_en
/* Playback. */
playbackDeviceCount = ((MA_PFN_waveOutGetNumDevs)pContext->winmm.waveOutGetNumDevs)();
for (iPlaybackDevice = 0; iPlaybackDevice < playbackDeviceCount; ++iPlaybackDevice) {
- MMRESULT result;
+ MA_MMRESULT result;
MA_WAVEOUTCAPS2A caps;
MA_ZERO_OBJECT(&caps);
- result = ((MA_PFN_waveOutGetDevCapsA)pContext->winmm.waveOutGetDevCapsA)(iPlaybackDevice, (WAVEOUTCAPSA*)&caps, sizeof(caps));
- if (result == MMSYSERR_NOERROR) {
+ result = ((MA_PFN_waveOutGetDevCapsA)pContext->winmm.waveOutGetDevCapsA)(iPlaybackDevice, (MA_WAVEOUTCAPSA*)&caps, sizeof(caps));
+ if (result == MA_MMSYSERR_NOERROR) {
ma_device_info deviceInfo;
MA_ZERO_OBJECT(&deviceInfo);
@@ -24725,13 +25807,13 @@ static ma_result ma_context_enumerate_devices__winmm(ma_context* pContext, ma_en
/* Capture. */
captureDeviceCount = ((MA_PFN_waveInGetNumDevs)pContext->winmm.waveInGetNumDevs)();
for (iCaptureDevice = 0; iCaptureDevice < captureDeviceCount; ++iCaptureDevice) {
- MMRESULT result;
+ MA_MMRESULT result;
MA_WAVEINCAPS2A caps;
MA_ZERO_OBJECT(&caps);
- result = ((MA_PFN_waveInGetDevCapsA)pContext->winmm.waveInGetDevCapsA)(iCaptureDevice, (WAVEINCAPSA*)&caps, sizeof(caps));
- if (result == MMSYSERR_NOERROR) {
+ result = ((MA_PFN_waveInGetDevCapsA)pContext->winmm.waveInGetDevCapsA)(iCaptureDevice, (MA_WAVEINCAPSA*)&caps, sizeof(caps));
+ if (result == MA_MMSYSERR_NOERROR) {
ma_device_info deviceInfo;
MA_ZERO_OBJECT(&deviceInfo);
@@ -24773,23 +25855,23 @@ static ma_result ma_context_get_device_info__winmm(ma_context* pContext, ma_devi
}
if (deviceType == ma_device_type_playback) {
- MMRESULT result;
+ MA_MMRESULT result;
MA_WAVEOUTCAPS2A caps;
MA_ZERO_OBJECT(&caps);
- result = ((MA_PFN_waveOutGetDevCapsA)pContext->winmm.waveOutGetDevCapsA)(winMMDeviceID, (WAVEOUTCAPSA*)&caps, sizeof(caps));
- if (result == MMSYSERR_NOERROR) {
+ result = ((MA_PFN_waveOutGetDevCapsA)pContext->winmm.waveOutGetDevCapsA)(winMMDeviceID, (MA_WAVEOUTCAPSA*)&caps, sizeof(caps));
+ if (result == MA_MMSYSERR_NOERROR) {
return ma_context_get_device_info_from_WAVEOUTCAPS2(pContext, &caps, pDeviceInfo);
}
} else {
- MMRESULT result;
+ MA_MMRESULT result;
MA_WAVEINCAPS2A caps;
MA_ZERO_OBJECT(&caps);
- result = ((MA_PFN_waveInGetDevCapsA)pContext->winmm.waveInGetDevCapsA)(winMMDeviceID, (WAVEINCAPSA*)&caps, sizeof(caps));
- if (result == MMSYSERR_NOERROR) {
+ result = ((MA_PFN_waveInGetDevCapsA)pContext->winmm.waveInGetDevCapsA)(winMMDeviceID, (MA_WAVEINCAPSA*)&caps, sizeof(caps));
+ if (result == MA_MMSYSERR_NOERROR) {
return ma_context_get_device_info_from_WAVEINCAPS2(pContext, &caps, pDeviceInfo);
}
}
@@ -24803,13 +25885,13 @@ static ma_result ma_device_uninit__winmm(ma_device* pDevice)
MA_ASSERT(pDevice != NULL);
if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) {
- ((MA_PFN_waveInClose)pDevice->pContext->winmm.waveInClose)((HWAVEIN)pDevice->winmm.hDeviceCapture);
+ ((MA_PFN_waveInClose)pDevice->pContext->winmm.waveInClose)((MA_HWAVEIN)pDevice->winmm.hDeviceCapture);
CloseHandle((HANDLE)pDevice->winmm.hEventCapture);
}
if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) {
- ((MA_PFN_waveOutReset)pDevice->pContext->winmm.waveOutReset)((HWAVEOUT)pDevice->winmm.hDevicePlayback);
- ((MA_PFN_waveOutClose)pDevice->pContext->winmm.waveOutClose)((HWAVEOUT)pDevice->winmm.hDevicePlayback);
+ ((MA_PFN_waveOutReset)pDevice->pContext->winmm.waveOutReset)((MA_HWAVEOUT)pDevice->winmm.hDevicePlayback);
+ ((MA_PFN_waveOutClose)pDevice->pContext->winmm.waveOutClose)((MA_HWAVEOUT)pDevice->winmm.hDevicePlayback);
CloseHandle((HANDLE)pDevice->winmm.hEventPlayback);
}
@@ -24866,19 +25948,19 @@ static ma_result ma_device_init__winmm(ma_device* pDevice, const ma_device_confi
/* The capture device needs to be initialized first. */
if (pConfig->deviceType == ma_device_type_capture || pConfig->deviceType == ma_device_type_duplex) {
- WAVEINCAPSA caps;
- WAVEFORMATEX wf;
- MMRESULT resultMM;
+ MA_WAVEINCAPSA caps;
+ MA_WAVEFORMATEX wf;
+ MA_MMRESULT resultMM;
/* We use an event to know when a new fragment needs to be enqueued. */
- pDevice->winmm.hEventCapture = (ma_handle)CreateEventW(NULL, TRUE, TRUE, NULL);
+ pDevice->winmm.hEventCapture = (ma_handle)CreateEventA(NULL, TRUE, TRUE, NULL);
if (pDevice->winmm.hEventCapture == NULL) {
errorMsg = "[WinMM] Failed to create event for fragment enqueing for the capture device.", errorCode = ma_result_from_GetLastError(GetLastError());
goto on_error;
}
/* The format should be based on the device's actual format. */
- if (((MA_PFN_waveInGetDevCapsA)pDevice->pContext->winmm.waveInGetDevCapsA)(winMMDeviceIDCapture, &caps, sizeof(caps)) != MMSYSERR_NOERROR) {
+ if (((MA_PFN_waveInGetDevCapsA)pDevice->pContext->winmm.waveInGetDevCapsA)(winMMDeviceIDCapture, &caps, sizeof(caps)) != MA_MMSYSERR_NOERROR) {
errorMsg = "[WinMM] Failed to retrieve internal device caps.", errorCode = MA_FORMAT_NOT_SUPPORTED;
goto on_error;
}
@@ -24889,8 +25971,8 @@ static ma_result ma_device_init__winmm(ma_device* pDevice, const ma_device_confi
goto on_error;
}
- resultMM = ((MA_PFN_waveInOpen)pDevice->pContext->winmm.waveInOpen)((LPHWAVEIN)&pDevice->winmm.hDeviceCapture, winMMDeviceIDCapture, &wf, (DWORD_PTR)pDevice->winmm.hEventCapture, (DWORD_PTR)pDevice, CALLBACK_EVENT | WAVE_ALLOWSYNC);
- if (resultMM != MMSYSERR_NOERROR) {
+ resultMM = ((MA_PFN_waveInOpen)pDevice->pContext->winmm.waveInOpen)((MA_HWAVEIN*)&pDevice->winmm.hDeviceCapture, winMMDeviceIDCapture, &wf, (DWORD_PTR)pDevice->winmm.hEventCapture, (DWORD_PTR)pDevice, MA_CALLBACK_EVENT | MA_WAVE_ALLOWSYNC);
+ if (resultMM != MA_MMSYSERR_NOERROR) {
errorMsg = "[WinMM] Failed to open capture device.", errorCode = MA_FAILED_TO_OPEN_BACKEND_DEVICE;
goto on_error;
}
@@ -24904,19 +25986,19 @@ static ma_result ma_device_init__winmm(ma_device* pDevice, const ma_device_confi
}
if (pConfig->deviceType == ma_device_type_playback || pConfig->deviceType == ma_device_type_duplex) {
- WAVEOUTCAPSA caps;
- WAVEFORMATEX wf;
- MMRESULT resultMM;
+ MA_WAVEOUTCAPSA caps;
+ MA_WAVEFORMATEX wf;
+ MA_MMRESULT resultMM;
/* We use an event to know when a new fragment needs to be enqueued. */
- pDevice->winmm.hEventPlayback = (ma_handle)CreateEventW(NULL, TRUE, TRUE, NULL);
+ pDevice->winmm.hEventPlayback = (ma_handle)CreateEventA(NULL, TRUE, TRUE, NULL);
if (pDevice->winmm.hEventPlayback == NULL) {
errorMsg = "[WinMM] Failed to create event for fragment enqueing for the playback device.", errorCode = ma_result_from_GetLastError(GetLastError());
goto on_error;
}
/* The format should be based on the device's actual format. */
- if (((MA_PFN_waveOutGetDevCapsA)pDevice->pContext->winmm.waveOutGetDevCapsA)(winMMDeviceIDPlayback, &caps, sizeof(caps)) != MMSYSERR_NOERROR) {
+ if (((MA_PFN_waveOutGetDevCapsA)pDevice->pContext->winmm.waveOutGetDevCapsA)(winMMDeviceIDPlayback, &caps, sizeof(caps)) != MA_MMSYSERR_NOERROR) {
errorMsg = "[WinMM] Failed to retrieve internal device caps.", errorCode = MA_FORMAT_NOT_SUPPORTED;
goto on_error;
}
@@ -24927,8 +26009,8 @@ static ma_result ma_device_init__winmm(ma_device* pDevice, const ma_device_confi
goto on_error;
}
- resultMM = ((MA_PFN_waveOutOpen)pDevice->pContext->winmm.waveOutOpen)((LPHWAVEOUT)&pDevice->winmm.hDevicePlayback, winMMDeviceIDPlayback, &wf, (DWORD_PTR)pDevice->winmm.hEventPlayback, (DWORD_PTR)pDevice, CALLBACK_EVENT | WAVE_ALLOWSYNC);
- if (resultMM != MMSYSERR_NOERROR) {
+ resultMM = ((MA_PFN_waveOutOpen)pDevice->pContext->winmm.waveOutOpen)((MA_HWAVEOUT*)&pDevice->winmm.hDevicePlayback, winMMDeviceIDPlayback, &wf, (DWORD_PTR)pDevice->winmm.hEventPlayback, (DWORD_PTR)pDevice, MA_CALLBACK_EVENT | MA_WAVE_ALLOWSYNC);
+ if (resultMM != MA_MMSYSERR_NOERROR) {
errorMsg = "[WinMM] Failed to open playback device.", errorCode = MA_FAILED_TO_OPEN_BACKEND_DEVICE;
goto on_error;
}
@@ -24948,10 +26030,10 @@ static ma_result ma_device_init__winmm(ma_device* pDevice, const ma_device_confi
*/
heapSize = 0;
if (pConfig->deviceType == ma_device_type_capture || pConfig->deviceType == ma_device_type_duplex) {
- heapSize += sizeof(WAVEHDR)*pDescriptorCapture->periodCount + (pDescriptorCapture->periodSizeInFrames * pDescriptorCapture->periodCount * ma_get_bytes_per_frame(pDescriptorCapture->format, pDescriptorCapture->channels));
+ heapSize += sizeof(MA_WAVEHDR)*pDescriptorCapture->periodCount + (pDescriptorCapture->periodSizeInFrames * pDescriptorCapture->periodCount * ma_get_bytes_per_frame(pDescriptorCapture->format, pDescriptorCapture->channels));
}
if (pConfig->deviceType == ma_device_type_playback || pConfig->deviceType == ma_device_type_duplex) {
- heapSize += sizeof(WAVEHDR)*pDescriptorPlayback->periodCount + (pDescriptorPlayback->periodSizeInFrames * pDescriptorPlayback->periodCount * ma_get_bytes_per_frame(pDescriptorPlayback->format, pDescriptorPlayback->channels));
+ heapSize += sizeof(MA_WAVEHDR)*pDescriptorPlayback->periodCount + (pDescriptorPlayback->periodSizeInFrames * pDescriptorPlayback->periodCount * ma_get_bytes_per_frame(pDescriptorPlayback->format, pDescriptorPlayback->channels));
}
pDevice->winmm._pHeapData = (ma_uint8*)ma_calloc(heapSize, &pDevice->pContext->allocationCallbacks);
@@ -24967,27 +26049,27 @@ static ma_result ma_device_init__winmm(ma_device* pDevice, const ma_device_confi
if (pConfig->deviceType == ma_device_type_capture) {
pDevice->winmm.pWAVEHDRCapture = pDevice->winmm._pHeapData;
- pDevice->winmm.pIntermediaryBufferCapture = pDevice->winmm._pHeapData + (sizeof(WAVEHDR)*(pDescriptorCapture->periodCount));
+ pDevice->winmm.pIntermediaryBufferCapture = pDevice->winmm._pHeapData + (sizeof(MA_WAVEHDR)*(pDescriptorCapture->periodCount));
} else {
pDevice->winmm.pWAVEHDRCapture = pDevice->winmm._pHeapData;
- pDevice->winmm.pIntermediaryBufferCapture = pDevice->winmm._pHeapData + (sizeof(WAVEHDR)*(pDescriptorCapture->periodCount + pDescriptorPlayback->periodCount));
+ pDevice->winmm.pIntermediaryBufferCapture = pDevice->winmm._pHeapData + (sizeof(MA_WAVEHDR)*(pDescriptorCapture->periodCount + pDescriptorPlayback->periodCount));
}
/* Prepare headers. */
for (iPeriod = 0; iPeriod < pDescriptorCapture->periodCount; ++iPeriod) {
ma_uint32 periodSizeInBytes = ma_get_period_size_in_bytes(pDescriptorCapture->periodSizeInFrames, pDescriptorCapture->format, pDescriptorCapture->channels);
- ((WAVEHDR*)pDevice->winmm.pWAVEHDRCapture)[iPeriod].lpData = (LPSTR)(pDevice->winmm.pIntermediaryBufferCapture + (periodSizeInBytes*iPeriod));
- ((WAVEHDR*)pDevice->winmm.pWAVEHDRCapture)[iPeriod].dwBufferLength = periodSizeInBytes;
- ((WAVEHDR*)pDevice->winmm.pWAVEHDRCapture)[iPeriod].dwFlags = 0L;
- ((WAVEHDR*)pDevice->winmm.pWAVEHDRCapture)[iPeriod].dwLoops = 0L;
- ((MA_PFN_waveInPrepareHeader)pDevice->pContext->winmm.waveInPrepareHeader)((HWAVEIN)pDevice->winmm.hDeviceCapture, &((WAVEHDR*)pDevice->winmm.pWAVEHDRCapture)[iPeriod], sizeof(WAVEHDR));
+ ((MA_WAVEHDR*)pDevice->winmm.pWAVEHDRCapture)[iPeriod].lpData = (char*)(pDevice->winmm.pIntermediaryBufferCapture + (periodSizeInBytes*iPeriod));
+ ((MA_WAVEHDR*)pDevice->winmm.pWAVEHDRCapture)[iPeriod].dwBufferLength = periodSizeInBytes;
+ ((MA_WAVEHDR*)pDevice->winmm.pWAVEHDRCapture)[iPeriod].dwFlags = 0L;
+ ((MA_WAVEHDR*)pDevice->winmm.pWAVEHDRCapture)[iPeriod].dwLoops = 0L;
+ ((MA_PFN_waveInPrepareHeader)pDevice->pContext->winmm.waveInPrepareHeader)((MA_HWAVEIN)pDevice->winmm.hDeviceCapture, &((MA_WAVEHDR*)pDevice->winmm.pWAVEHDRCapture)[iPeriod], sizeof(MA_WAVEHDR));
/*
- The user data of the WAVEHDR structure is a single flag the controls whether or not it is ready for writing. Consider it to be named "isLocked". A value of 0 means
+ The user data of the MA_WAVEHDR structure is a single flag the controls whether or not it is ready for writing. Consider it to be named "isLocked". A value of 0 means
it's unlocked and available for writing. A value of 1 means it's locked.
*/
- ((WAVEHDR*)pDevice->winmm.pWAVEHDRCapture)[iPeriod].dwUser = 0;
+ ((MA_WAVEHDR*)pDevice->winmm.pWAVEHDRCapture)[iPeriod].dwUser = 0;
}
}
@@ -24996,27 +26078,27 @@ static ma_result ma_device_init__winmm(ma_device* pDevice, const ma_device_confi
if (pConfig->deviceType == ma_device_type_playback) {
pDevice->winmm.pWAVEHDRPlayback = pDevice->winmm._pHeapData;
- pDevice->winmm.pIntermediaryBufferPlayback = pDevice->winmm._pHeapData + (sizeof(WAVEHDR)*pDescriptorPlayback->periodCount);
+ pDevice->winmm.pIntermediaryBufferPlayback = pDevice->winmm._pHeapData + (sizeof(MA_WAVEHDR)*pDescriptorPlayback->periodCount);
} else {
- pDevice->winmm.pWAVEHDRPlayback = pDevice->winmm._pHeapData + (sizeof(WAVEHDR)*(pDescriptorCapture->periodCount));
- pDevice->winmm.pIntermediaryBufferPlayback = pDevice->winmm._pHeapData + (sizeof(WAVEHDR)*(pDescriptorCapture->periodCount + pDescriptorPlayback->periodCount)) + (pDescriptorCapture->periodSizeInFrames*pDescriptorCapture->periodCount*ma_get_bytes_per_frame(pDescriptorCapture->format, pDescriptorCapture->channels));
+ pDevice->winmm.pWAVEHDRPlayback = pDevice->winmm._pHeapData + (sizeof(MA_WAVEHDR)*(pDescriptorCapture->periodCount));
+ pDevice->winmm.pIntermediaryBufferPlayback = pDevice->winmm._pHeapData + (sizeof(MA_WAVEHDR)*(pDescriptorCapture->periodCount + pDescriptorPlayback->periodCount)) + (pDescriptorCapture->periodSizeInFrames*pDescriptorCapture->periodCount*ma_get_bytes_per_frame(pDescriptorCapture->format, pDescriptorCapture->channels));
}
/* Prepare headers. */
for (iPeriod = 0; iPeriod < pDescriptorPlayback->periodCount; ++iPeriod) {
ma_uint32 periodSizeInBytes = ma_get_period_size_in_bytes(pDescriptorPlayback->periodSizeInFrames, pDescriptorPlayback->format, pDescriptorPlayback->channels);
- ((WAVEHDR*)pDevice->winmm.pWAVEHDRPlayback)[iPeriod].lpData = (LPSTR)(pDevice->winmm.pIntermediaryBufferPlayback + (periodSizeInBytes*iPeriod));
- ((WAVEHDR*)pDevice->winmm.pWAVEHDRPlayback)[iPeriod].dwBufferLength = periodSizeInBytes;
- ((WAVEHDR*)pDevice->winmm.pWAVEHDRPlayback)[iPeriod].dwFlags = 0L;
- ((WAVEHDR*)pDevice->winmm.pWAVEHDRPlayback)[iPeriod].dwLoops = 0L;
- ((MA_PFN_waveOutPrepareHeader)pDevice->pContext->winmm.waveOutPrepareHeader)((HWAVEOUT)pDevice->winmm.hDevicePlayback, &((WAVEHDR*)pDevice->winmm.pWAVEHDRPlayback)[iPeriod], sizeof(WAVEHDR));
+ ((MA_WAVEHDR*)pDevice->winmm.pWAVEHDRPlayback)[iPeriod].lpData = (char*)(pDevice->winmm.pIntermediaryBufferPlayback + (periodSizeInBytes*iPeriod));
+ ((MA_WAVEHDR*)pDevice->winmm.pWAVEHDRPlayback)[iPeriod].dwBufferLength = periodSizeInBytes;
+ ((MA_WAVEHDR*)pDevice->winmm.pWAVEHDRPlayback)[iPeriod].dwFlags = 0L;
+ ((MA_WAVEHDR*)pDevice->winmm.pWAVEHDRPlayback)[iPeriod].dwLoops = 0L;
+ ((MA_PFN_waveOutPrepareHeader)pDevice->pContext->winmm.waveOutPrepareHeader)((MA_HWAVEOUT)pDevice->winmm.hDevicePlayback, &((MA_WAVEHDR*)pDevice->winmm.pWAVEHDRPlayback)[iPeriod], sizeof(MA_WAVEHDR));
/*
- The user data of the WAVEHDR structure is a single flag the controls whether or not it is ready for writing. Consider it to be named "isLocked". A value of 0 means
+ The user data of the MA_WAVEHDR structure is a single flag the controls whether or not it is ready for writing. Consider it to be named "isLocked". A value of 0 means
it's unlocked and available for writing. A value of 1 means it's locked.
*/
- ((WAVEHDR*)pDevice->winmm.pWAVEHDRPlayback)[iPeriod].dwUser = 0;
+ ((MA_WAVEHDR*)pDevice->winmm.pWAVEHDRPlayback)[iPeriod].dwUser = 0;
}
}
@@ -25027,22 +26109,22 @@ static ma_result ma_device_init__winmm(ma_device* pDevice, const ma_device_confi
if (pDevice->winmm.pWAVEHDRCapture != NULL) {
ma_uint32 iPeriod;
for (iPeriod = 0; iPeriod < pDescriptorCapture->periodCount; ++iPeriod) {
- ((MA_PFN_waveInUnprepareHeader)pDevice->pContext->winmm.waveInUnprepareHeader)((HWAVEIN)pDevice->winmm.hDeviceCapture, &((WAVEHDR*)pDevice->winmm.pWAVEHDRCapture)[iPeriod], sizeof(WAVEHDR));
+ ((MA_PFN_waveInUnprepareHeader)pDevice->pContext->winmm.waveInUnprepareHeader)((MA_HWAVEIN)pDevice->winmm.hDeviceCapture, &((MA_WAVEHDR*)pDevice->winmm.pWAVEHDRCapture)[iPeriod], sizeof(MA_WAVEHDR));
}
}
- ((MA_PFN_waveInClose)pDevice->pContext->winmm.waveInClose)((HWAVEIN)pDevice->winmm.hDeviceCapture);
+ ((MA_PFN_waveInClose)pDevice->pContext->winmm.waveInClose)((MA_HWAVEIN)pDevice->winmm.hDeviceCapture);
}
if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) {
if (pDevice->winmm.pWAVEHDRCapture != NULL) {
ma_uint32 iPeriod;
for (iPeriod = 0; iPeriod < pDescriptorPlayback->periodCount; ++iPeriod) {
- ((MA_PFN_waveOutUnprepareHeader)pDevice->pContext->winmm.waveOutUnprepareHeader)((HWAVEOUT)pDevice->winmm.hDevicePlayback, &((WAVEHDR*)pDevice->winmm.pWAVEHDRPlayback)[iPeriod], sizeof(WAVEHDR));
+ ((MA_PFN_waveOutUnprepareHeader)pDevice->pContext->winmm.waveOutUnprepareHeader)((MA_HWAVEOUT)pDevice->winmm.hDevicePlayback, &((MA_WAVEHDR*)pDevice->winmm.pWAVEHDRPlayback)[iPeriod], sizeof(MA_WAVEHDR));
}
}
- ((MA_PFN_waveOutClose)pDevice->pContext->winmm.waveOutClose)((HWAVEOUT)pDevice->winmm.hDevicePlayback);
+ ((MA_PFN_waveOutClose)pDevice->pContext->winmm.waveOutClose)((MA_HWAVEOUT)pDevice->winmm.hDevicePlayback);
}
ma_free(pDevice->winmm._pHeapData, &pDevice->pContext->allocationCallbacks);
@@ -25059,19 +26141,19 @@ static ma_result ma_device_start__winmm(ma_device* pDevice)
MA_ASSERT(pDevice != NULL);
if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) {
- MMRESULT resultMM;
- WAVEHDR* pWAVEHDR;
+ MA_MMRESULT resultMM;
+ MA_WAVEHDR* pWAVEHDR;
ma_uint32 iPeriod;
- pWAVEHDR = (WAVEHDR*)pDevice->winmm.pWAVEHDRCapture;
+ pWAVEHDR = (MA_WAVEHDR*)pDevice->winmm.pWAVEHDRCapture;
/* Make sure the event is reset to a non-signaled state to ensure we don't prematurely return from WaitForSingleObject(). */
ResetEvent((HANDLE)pDevice->winmm.hEventCapture);
/* To start the device we attach all of the buffers and then start it. As the buffers are filled with data we will get notifications. */
for (iPeriod = 0; iPeriod < pDevice->capture.internalPeriods; ++iPeriod) {
- resultMM = ((MA_PFN_waveInAddBuffer)pDevice->pContext->winmm.waveInAddBuffer)((HWAVEIN)pDevice->winmm.hDeviceCapture, &((LPWAVEHDR)pDevice->winmm.pWAVEHDRCapture)[iPeriod], sizeof(WAVEHDR));
- if (resultMM != MMSYSERR_NOERROR) {
+ resultMM = ((MA_PFN_waveInAddBuffer)pDevice->pContext->winmm.waveInAddBuffer)((MA_HWAVEIN)pDevice->winmm.hDeviceCapture, &((MA_WAVEHDR*)pDevice->winmm.pWAVEHDRCapture)[iPeriod], sizeof(MA_WAVEHDR));
+ if (resultMM != MA_MMSYSERR_NOERROR) {
ma_log_post(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[WinMM] Failed to attach input buffers to capture device in preparation for capture.");
return ma_result_from_MMRESULT(resultMM);
}
@@ -25081,8 +26163,8 @@ static ma_result ma_device_start__winmm(ma_device* pDevice)
}
/* Capture devices need to be explicitly started, unlike playback devices. */
- resultMM = ((MA_PFN_waveInStart)pDevice->pContext->winmm.waveInStart)((HWAVEIN)pDevice->winmm.hDeviceCapture);
- if (resultMM != MMSYSERR_NOERROR) {
+ resultMM = ((MA_PFN_waveInStart)pDevice->pContext->winmm.waveInStart)((MA_HWAVEIN)pDevice->winmm.hDeviceCapture);
+ if (resultMM != MA_MMSYSERR_NOERROR) {
ma_log_post(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[WinMM] Failed to start backend device.");
return ma_result_from_MMRESULT(resultMM);
}
@@ -25097,7 +26179,7 @@ static ma_result ma_device_start__winmm(ma_device* pDevice)
static ma_result ma_device_stop__winmm(ma_device* pDevice)
{
- MMRESULT resultMM;
+ MA_MMRESULT resultMM;
MA_ASSERT(pDevice != NULL);
@@ -25106,22 +26188,22 @@ static ma_result ma_device_stop__winmm(ma_device* pDevice)
return MA_INVALID_ARGS;
}
- resultMM = ((MA_PFN_waveInReset)pDevice->pContext->winmm.waveInReset)((HWAVEIN)pDevice->winmm.hDeviceCapture);
- if (resultMM != MMSYSERR_NOERROR) {
+ resultMM = ((MA_PFN_waveInReset)pDevice->pContext->winmm.waveInReset)((MA_HWAVEIN)pDevice->winmm.hDeviceCapture);
+ if (resultMM != MA_MMSYSERR_NOERROR) {
ma_log_post(ma_device_get_log(pDevice), MA_LOG_LEVEL_WARNING, "[WinMM] WARNING: Failed to reset capture device.");
}
}
if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) {
ma_uint32 iPeriod;
- WAVEHDR* pWAVEHDR;
+ MA_WAVEHDR* pWAVEHDR;
if (pDevice->winmm.hDevicePlayback == NULL) {
return MA_INVALID_ARGS;
}
/* We need to drain the device. To do this we just loop over each header and if it's locked just wait for the event. */
- pWAVEHDR = (WAVEHDR*)pDevice->winmm.pWAVEHDRPlayback;
+ pWAVEHDR = (MA_WAVEHDR*)pDevice->winmm.pWAVEHDRPlayback;
for (iPeriod = 0; iPeriod < pDevice->playback.internalPeriods; iPeriod += 1) {
if (pWAVEHDR[iPeriod].dwUser == 1) { /* 1 = locked. */
if (WaitForSingleObject((HANDLE)pDevice->winmm.hEventPlayback, INFINITE) != WAIT_OBJECT_0) {
@@ -25132,8 +26214,8 @@ static ma_result ma_device_stop__winmm(ma_device* pDevice)
}
}
- resultMM = ((MA_PFN_waveOutReset)pDevice->pContext->winmm.waveOutReset)((HWAVEOUT)pDevice->winmm.hDevicePlayback);
- if (resultMM != MMSYSERR_NOERROR) {
+ resultMM = ((MA_PFN_waveOutReset)pDevice->pContext->winmm.waveOutReset)((MA_HWAVEOUT)pDevice->winmm.hDevicePlayback);
+ if (resultMM != MA_MMSYSERR_NOERROR) {
ma_log_post(ma_device_get_log(pDevice), MA_LOG_LEVEL_WARNING, "[WinMM] WARNING: Failed to reset playback device.");
}
}
@@ -25144,9 +26226,9 @@ static ma_result ma_device_stop__winmm(ma_device* pDevice)
static ma_result ma_device_write__winmm(ma_device* pDevice, const void* pPCMFrames, ma_uint32 frameCount, ma_uint32* pFramesWritten)
{
ma_result result = MA_SUCCESS;
- MMRESULT resultMM;
+ MA_MMRESULT resultMM;
ma_uint32 totalFramesWritten;
- WAVEHDR* pWAVEHDR;
+ MA_WAVEHDR* pWAVEHDR;
MA_ASSERT(pDevice != NULL);
MA_ASSERT(pPCMFrames != NULL);
@@ -25155,7 +26237,7 @@ static ma_result ma_device_write__winmm(ma_device* pDevice, const void* pPCMFram
*pFramesWritten = 0;
}
- pWAVEHDR = (WAVEHDR*)pDevice->winmm.pWAVEHDRPlayback;
+ pWAVEHDR = (MA_WAVEHDR*)pDevice->winmm.pWAVEHDRPlayback;
/* Keep processing as much data as possible. */
totalFramesWritten = 0;
@@ -25180,14 +26262,14 @@ static ma_result ma_device_write__winmm(ma_device* pDevice, const void* pPCMFram
/* If we've consumed the buffer entirely we need to write it out to the device. */
if (pDevice->winmm.headerFramesConsumedPlayback == (pWAVEHDR[pDevice->winmm.iNextHeaderPlayback].dwBufferLength/bpf)) {
pWAVEHDR[pDevice->winmm.iNextHeaderPlayback].dwUser = 1; /* 1 = locked. */
- pWAVEHDR[pDevice->winmm.iNextHeaderPlayback].dwFlags &= ~WHDR_DONE; /* <-- Need to make sure the WHDR_DONE flag is unset. */
+ pWAVEHDR[pDevice->winmm.iNextHeaderPlayback].dwFlags &= ~MA_WHDR_DONE; /* <-- Need to make sure the WHDR_DONE flag is unset. */
/* Make sure the event is reset to a non-signaled state to ensure we don't prematurely return from WaitForSingleObject(). */
ResetEvent((HANDLE)pDevice->winmm.hEventPlayback);
/* The device will be started here. */
- resultMM = ((MA_PFN_waveOutWrite)pDevice->pContext->winmm.waveOutWrite)((HWAVEOUT)pDevice->winmm.hDevicePlayback, &pWAVEHDR[pDevice->winmm.iNextHeaderPlayback], sizeof(WAVEHDR));
- if (resultMM != MMSYSERR_NOERROR) {
+ resultMM = ((MA_PFN_waveOutWrite)pDevice->pContext->winmm.waveOutWrite)((MA_HWAVEOUT)pDevice->winmm.hDevicePlayback, &pWAVEHDR[pDevice->winmm.iNextHeaderPlayback], sizeof(MA_WAVEHDR));
+ if (resultMM != MA_MMSYSERR_NOERROR) {
result = ma_result_from_MMRESULT(resultMM);
ma_log_post(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[WinMM] waveOutWrite() failed.");
break;
@@ -25215,7 +26297,7 @@ static ma_result ma_device_write__winmm(ma_device* pDevice, const void* pPCMFram
}
/* Something happened. If the next buffer has been marked as done we need to reset a bit of state. */
- if ((pWAVEHDR[pDevice->winmm.iNextHeaderPlayback].dwFlags & WHDR_DONE) != 0) {
+ if ((pWAVEHDR[pDevice->winmm.iNextHeaderPlayback].dwFlags & MA_WHDR_DONE) != 0) {
pWAVEHDR[pDevice->winmm.iNextHeaderPlayback].dwUser = 0; /* 0 = unlocked (make it available for writing). */
pDevice->winmm.headerFramesConsumedPlayback = 0;
}
@@ -25236,9 +26318,9 @@ static ma_result ma_device_write__winmm(ma_device* pDevice, const void* pPCMFram
static ma_result ma_device_read__winmm(ma_device* pDevice, void* pPCMFrames, ma_uint32 frameCount, ma_uint32* pFramesRead)
{
ma_result result = MA_SUCCESS;
- MMRESULT resultMM;
+ MA_MMRESULT resultMM;
ma_uint32 totalFramesRead;
- WAVEHDR* pWAVEHDR;
+ MA_WAVEHDR* pWAVEHDR;
MA_ASSERT(pDevice != NULL);
MA_ASSERT(pPCMFrames != NULL);
@@ -25247,7 +26329,7 @@ static ma_result ma_device_read__winmm(ma_device* pDevice, void* pPCMFrames, ma_
*pFramesRead = 0;
}
- pWAVEHDR = (WAVEHDR*)pDevice->winmm.pWAVEHDRCapture;
+ pWAVEHDR = (MA_WAVEHDR*)pDevice->winmm.pWAVEHDRCapture;
/* Keep processing as much data as possible. */
totalFramesRead = 0;
@@ -25269,14 +26351,14 @@ static ma_result ma_device_read__winmm(ma_device* pDevice, void* pPCMFrames, ma_
/* If we've consumed the buffer entirely we need to add it back to the device. */
if (pDevice->winmm.headerFramesConsumedCapture == (pWAVEHDR[pDevice->winmm.iNextHeaderCapture].dwBufferLength/bpf)) {
pWAVEHDR[pDevice->winmm.iNextHeaderCapture].dwUser = 1; /* 1 = locked. */
- pWAVEHDR[pDevice->winmm.iNextHeaderCapture].dwFlags &= ~WHDR_DONE; /* <-- Need to make sure the WHDR_DONE flag is unset. */
+ pWAVEHDR[pDevice->winmm.iNextHeaderCapture].dwFlags &= ~MA_WHDR_DONE; /* <-- Need to make sure the WHDR_DONE flag is unset. */
/* Make sure the event is reset to a non-signaled state to ensure we don't prematurely return from WaitForSingleObject(). */
ResetEvent((HANDLE)pDevice->winmm.hEventCapture);
/* The device will be started here. */
- resultMM = ((MA_PFN_waveInAddBuffer)pDevice->pContext->winmm.waveInAddBuffer)((HWAVEIN)pDevice->winmm.hDeviceCapture, &((LPWAVEHDR)pDevice->winmm.pWAVEHDRCapture)[pDevice->winmm.iNextHeaderCapture], sizeof(WAVEHDR));
- if (resultMM != MMSYSERR_NOERROR) {
+ resultMM = ((MA_PFN_waveInAddBuffer)pDevice->pContext->winmm.waveInAddBuffer)((MA_HWAVEIN)pDevice->winmm.hDeviceCapture, &((MA_WAVEHDR*)pDevice->winmm.pWAVEHDRCapture)[pDevice->winmm.iNextHeaderCapture], sizeof(MA_WAVEHDR));
+ if (resultMM != MA_MMSYSERR_NOERROR) {
result = ma_result_from_MMRESULT(resultMM);
ma_log_post(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[WinMM] waveInAddBuffer() failed.");
break;
@@ -25304,7 +26386,7 @@ static ma_result ma_device_read__winmm(ma_device* pDevice, void* pPCMFrames, ma_
}
/* Something happened. If the next buffer has been marked as done we need to reset a bit of state. */
- if ((pWAVEHDR[pDevice->winmm.iNextHeaderCapture].dwFlags & WHDR_DONE) != 0) {
+ if ((pWAVEHDR[pDevice->winmm.iNextHeaderCapture].dwFlags & MA_WHDR_DONE) != 0) {
pWAVEHDR[pDevice->winmm.iNextHeaderCapture].dwUser = 0; /* 0 = unlocked (make it available for reading). */
pDevice->winmm.headerFramesConsumedCapture = 0;
}
@@ -25327,7 +26409,7 @@ static ma_result ma_context_uninit__winmm(ma_context* pContext)
MA_ASSERT(pContext != NULL);
MA_ASSERT(pContext->backend == ma_backend_winmm);
- ma_dlclose(pContext, pContext->winmm.hWinMM);
+ ma_dlclose(ma_context_get_log(pContext), pContext->winmm.hWinMM);
return MA_SUCCESS;
}
@@ -25337,28 +26419,28 @@ static ma_result ma_context_init__winmm(ma_context* pContext, const ma_context_c
(void)pConfig;
- pContext->winmm.hWinMM = ma_dlopen(pContext, "winmm.dll");
+ pContext->winmm.hWinMM = ma_dlopen(ma_context_get_log(pContext), "winmm.dll");
if (pContext->winmm.hWinMM == NULL) {
return MA_NO_BACKEND;
}
- pContext->winmm.waveOutGetNumDevs = ma_dlsym(pContext, pContext->winmm.hWinMM, "waveOutGetNumDevs");
- pContext->winmm.waveOutGetDevCapsA = ma_dlsym(pContext, pContext->winmm.hWinMM, "waveOutGetDevCapsA");
- pContext->winmm.waveOutOpen = ma_dlsym(pContext, pContext->winmm.hWinMM, "waveOutOpen");
- pContext->winmm.waveOutClose = ma_dlsym(pContext, pContext->winmm.hWinMM, "waveOutClose");
- pContext->winmm.waveOutPrepareHeader = ma_dlsym(pContext, pContext->winmm.hWinMM, "waveOutPrepareHeader");
- pContext->winmm.waveOutUnprepareHeader = ma_dlsym(pContext, pContext->winmm.hWinMM, "waveOutUnprepareHeader");
- pContext->winmm.waveOutWrite = ma_dlsym(pContext, pContext->winmm.hWinMM, "waveOutWrite");
- pContext->winmm.waveOutReset = ma_dlsym(pContext, pContext->winmm.hWinMM, "waveOutReset");
- pContext->winmm.waveInGetNumDevs = ma_dlsym(pContext, pContext->winmm.hWinMM, "waveInGetNumDevs");
- pContext->winmm.waveInGetDevCapsA = ma_dlsym(pContext, pContext->winmm.hWinMM, "waveInGetDevCapsA");
- pContext->winmm.waveInOpen = ma_dlsym(pContext, pContext->winmm.hWinMM, "waveInOpen");
- pContext->winmm.waveInClose = ma_dlsym(pContext, pContext->winmm.hWinMM, "waveInClose");
- pContext->winmm.waveInPrepareHeader = ma_dlsym(pContext, pContext->winmm.hWinMM, "waveInPrepareHeader");
- pContext->winmm.waveInUnprepareHeader = ma_dlsym(pContext, pContext->winmm.hWinMM, "waveInUnprepareHeader");
- pContext->winmm.waveInAddBuffer = ma_dlsym(pContext, pContext->winmm.hWinMM, "waveInAddBuffer");
- pContext->winmm.waveInStart = ma_dlsym(pContext, pContext->winmm.hWinMM, "waveInStart");
- pContext->winmm.waveInReset = ma_dlsym(pContext, pContext->winmm.hWinMM, "waveInReset");
+ pContext->winmm.waveOutGetNumDevs = ma_dlsym(ma_context_get_log(pContext), pContext->winmm.hWinMM, "waveOutGetNumDevs");
+ pContext->winmm.waveOutGetDevCapsA = ma_dlsym(ma_context_get_log(pContext), pContext->winmm.hWinMM, "waveOutGetDevCapsA");
+ pContext->winmm.waveOutOpen = ma_dlsym(ma_context_get_log(pContext), pContext->winmm.hWinMM, "waveOutOpen");
+ pContext->winmm.waveOutClose = ma_dlsym(ma_context_get_log(pContext), pContext->winmm.hWinMM, "waveOutClose");
+ pContext->winmm.waveOutPrepareHeader = ma_dlsym(ma_context_get_log(pContext), pContext->winmm.hWinMM, "waveOutPrepareHeader");
+ pContext->winmm.waveOutUnprepareHeader = ma_dlsym(ma_context_get_log(pContext), pContext->winmm.hWinMM, "waveOutUnprepareHeader");
+ pContext->winmm.waveOutWrite = ma_dlsym(ma_context_get_log(pContext), pContext->winmm.hWinMM, "waveOutWrite");
+ pContext->winmm.waveOutReset = ma_dlsym(ma_context_get_log(pContext), pContext->winmm.hWinMM, "waveOutReset");
+ pContext->winmm.waveInGetNumDevs = ma_dlsym(ma_context_get_log(pContext), pContext->winmm.hWinMM, "waveInGetNumDevs");
+ pContext->winmm.waveInGetDevCapsA = ma_dlsym(ma_context_get_log(pContext), pContext->winmm.hWinMM, "waveInGetDevCapsA");
+ pContext->winmm.waveInOpen = ma_dlsym(ma_context_get_log(pContext), pContext->winmm.hWinMM, "waveInOpen");
+ pContext->winmm.waveInClose = ma_dlsym(ma_context_get_log(pContext), pContext->winmm.hWinMM, "waveInClose");
+ pContext->winmm.waveInPrepareHeader = ma_dlsym(ma_context_get_log(pContext), pContext->winmm.hWinMM, "waveInPrepareHeader");
+ pContext->winmm.waveInUnprepareHeader = ma_dlsym(ma_context_get_log(pContext), pContext->winmm.hWinMM, "waveInUnprepareHeader");
+ pContext->winmm.waveInAddBuffer = ma_dlsym(ma_context_get_log(pContext), pContext->winmm.hWinMM, "waveInAddBuffer");
+ pContext->winmm.waveInStart = ma_dlsym(ma_context_get_log(pContext), pContext->winmm.hWinMM, "waveInStart");
+ pContext->winmm.waveInReset = ma_dlsym(ma_context_get_log(pContext), pContext->winmm.hWinMM, "waveInReset");
pCallbacks->onContextInit = ma_context_init__winmm;
pCallbacks->onContextUninit = ma_context_uninit__winmm;
@@ -26554,7 +27636,7 @@ static ma_result ma_device_init_by_type__alsa(ma_device* pDevice, const ma_devic
isUsingMMap = MA_FALSE;
#if 0 /* NOTE: MMAP mode temporarily disabled. */
if (deviceType != ma_device_type_capture) { /* <-- Disabling MMAP mode for capture devices because I apparently do not have a device that supports it which means I can't test it... Contributions welcome. */
- if (!pConfig->alsa.noMMap && ma_device__is_async(pDevice)) {
+ if (!pConfig->alsa.noMMap) {
if (((ma_snd_pcm_hw_params_set_access_proc)pDevice->pContext->alsa.snd_pcm_hw_params_set_access)(pPCM, pHWParams, MA_SND_PCM_ACCESS_MMAP_INTERLEAVED) == 0) {
pDevice->alsa.isUsingMMap = MA_TRUE;
}
@@ -26976,6 +28058,12 @@ static ma_result ma_device_start__alsa(ma_device* pDevice)
static ma_result ma_device_stop__alsa(ma_device* pDevice)
{
+ /*
+ The stop callback will get called on the worker thread after read/write__alsa() has returned. At this point there is
+ a small chance that our wakeupfd has not been cleared. We'll clear that out now if applicable.
+ */
+ int resultPoll;
+
if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) {
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_DEBUG, "[ALSA] Dropping capture device...\n");
((ma_snd_pcm_drop_proc)pDevice->pContext->alsa.snd_pcm_drop)((ma_snd_pcm_t*)pDevice->alsa.pPCMCapture);
@@ -26988,6 +28076,13 @@ static ma_result ma_device_stop__alsa(ma_device* pDevice)
} else {
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_DEBUG, "[ALSA] Preparing capture device successful.\n");
}
+
+ /* Clear the wakeupfd. */
+ resultPoll = poll((struct pollfd*)pDevice->alsa.pPollDescriptorsCapture, 1, 0);
+ if (resultPoll > 0) {
+ ma_uint64 t;
+ read(((struct pollfd*)pDevice->alsa.pPollDescriptorsCapture)[0].fd, &t, sizeof(t));
+ }
}
if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) {
@@ -27002,6 +28097,14 @@ static ma_result ma_device_stop__alsa(ma_device* pDevice)
} else {
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_DEBUG, "[ALSA] Preparing playback device successful.\n");
}
+
+ /* Clear the wakeupfd. */
+ resultPoll = poll((struct pollfd*)pDevice->alsa.pPollDescriptorsPlayback, 1, 0);
+ if (resultPoll > 0) {
+ ma_uint64 t;
+ read(((struct pollfd*)pDevice->alsa.pPollDescriptorsPlayback)[0].fd, &t, sizeof(t));
+ }
+
}
return MA_SUCCESS;
@@ -27014,7 +28117,7 @@ static ma_result ma_device_wait__alsa(ma_device* pDevice, ma_snd_pcm_t* pPCM, st
int resultALSA;
int resultPoll = poll(pPollDescriptors, pollDescriptorCount, -1);
if (resultPoll < 0) {
- ma_log_post(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[ALSA] poll() failed.");
+ ma_log_post(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[ALSA] poll() failed.\n");
return ma_result_from_errno(errno);
}
@@ -27027,7 +28130,7 @@ static ma_result ma_device_wait__alsa(ma_device* pDevice, ma_snd_pcm_t* pPCM, st
ma_uint64 t;
int resultRead = read(pPollDescriptors[0].fd, &t, sizeof(t)); /* <-- Important that we read here so that the next write() does not block. */
if (resultRead < 0) {
- ma_log_post(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[ALSA] read() failed.");
+ ma_log_post(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[ALSA] read() failed.\n");
return ma_result_from_errno(errno);
}
@@ -27041,13 +28144,17 @@ static ma_result ma_device_wait__alsa(ma_device* pDevice, ma_snd_pcm_t* pPCM, st
*/
resultALSA = ((ma_snd_pcm_poll_descriptors_revents_proc)pDevice->pContext->alsa.snd_pcm_poll_descriptors_revents)(pPCM, pPollDescriptors + 1, pollDescriptorCount - 1, &revents); /* +1, -1 to ignore the wakeup descriptor. */
if (resultALSA < 0) {
- ma_log_post(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[ALSA] snd_pcm_poll_descriptors_revents() failed.");
+ ma_log_post(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[ALSA] snd_pcm_poll_descriptors_revents() failed.\n");
return ma_result_from_errno(-resultALSA);
}
if ((revents & POLLERR) != 0) {
- ma_log_post(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[ALSA] POLLERR detected.");
- return ma_result_from_errno(errno);
+ ma_snd_pcm_state_t state = ((ma_snd_pcm_state_proc)pDevice->pContext->alsa.snd_pcm_state)(pPCM);
+ if (state == MA_SND_PCM_STATE_XRUN) {
+ /* The PCM is in a xrun state. This will be recovered from at a higher level. We can disregard this. */
+ } else {
+ ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_WARNING, "[ALSA] POLLERR detected. status = %d\n", ((ma_snd_pcm_state_proc)pDevice->pContext->alsa.snd_pcm_state)(pPCM));
+ }
}
if ((revents & requiredEvent) == requiredEvent) {
@@ -27222,7 +28329,7 @@ static ma_result ma_context_uninit__alsa(ma_context* pContext)
((ma_snd_config_update_free_global_proc)pContext->alsa.snd_config_update_free_global)();
#ifndef MA_NO_RUNTIME_LINKING
- ma_dlclose(pContext, pContext->alsa.asoundSO);
+ ma_dlclose(ma_context_get_log(pContext), pContext->alsa.asoundSO);
#endif
ma_mutex_uninit(&pContext->alsa.internalDeviceEnumLock);
@@ -27241,7 +28348,7 @@ static ma_result ma_context_init__alsa(ma_context* pContext, const ma_context_co
size_t i;
for (i = 0; i < ma_countof(libasoundNames); ++i) {
- pContext->alsa.asoundSO = ma_dlopen(pContext, libasoundNames[i]);
+ pContext->alsa.asoundSO = ma_dlopen(ma_context_get_log(pContext), libasoundNames[i]);
if (pContext->alsa.asoundSO != NULL) {
break;
}
@@ -27252,72 +28359,72 @@ static ma_result ma_context_init__alsa(ma_context* pContext, const ma_context_co
return MA_NO_BACKEND;
}
- pContext->alsa.snd_pcm_open = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_open");
- pContext->alsa.snd_pcm_close = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_close");
- pContext->alsa.snd_pcm_hw_params_sizeof = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_hw_params_sizeof");
- pContext->alsa.snd_pcm_hw_params_any = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_hw_params_any");
- pContext->alsa.snd_pcm_hw_params_set_format = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_hw_params_set_format");
- pContext->alsa.snd_pcm_hw_params_set_format_first = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_hw_params_set_format_first");
- pContext->alsa.snd_pcm_hw_params_get_format_mask = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_hw_params_get_format_mask");
- pContext->alsa.snd_pcm_hw_params_set_channels = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_hw_params_set_channels");
- pContext->alsa.snd_pcm_hw_params_set_channels_near = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_hw_params_set_channels_near");
- pContext->alsa.snd_pcm_hw_params_set_channels_minmax = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_hw_params_set_channels_minmax");
- pContext->alsa.snd_pcm_hw_params_set_rate_resample = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_hw_params_set_rate_resample");
- pContext->alsa.snd_pcm_hw_params_set_rate = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_hw_params_set_rate");
- pContext->alsa.snd_pcm_hw_params_set_rate_near = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_hw_params_set_rate_near");
- pContext->alsa.snd_pcm_hw_params_set_buffer_size_near = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_hw_params_set_buffer_size_near");
- pContext->alsa.snd_pcm_hw_params_set_periods_near = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_hw_params_set_periods_near");
- pContext->alsa.snd_pcm_hw_params_set_access = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_hw_params_set_access");
- pContext->alsa.snd_pcm_hw_params_get_format = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_hw_params_get_format");
- pContext->alsa.snd_pcm_hw_params_get_channels = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_hw_params_get_channels");
- pContext->alsa.snd_pcm_hw_params_get_channels_min = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_hw_params_get_channels_min");
- pContext->alsa.snd_pcm_hw_params_get_channels_max = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_hw_params_get_channels_max");
- pContext->alsa.snd_pcm_hw_params_get_rate = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_hw_params_get_rate");
- pContext->alsa.snd_pcm_hw_params_get_rate_min = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_hw_params_get_rate_min");
- pContext->alsa.snd_pcm_hw_params_get_rate_max = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_hw_params_get_rate_max");
- pContext->alsa.snd_pcm_hw_params_get_buffer_size = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_hw_params_get_buffer_size");
- pContext->alsa.snd_pcm_hw_params_get_periods = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_hw_params_get_periods");
- pContext->alsa.snd_pcm_hw_params_get_access = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_hw_params_get_access");
- pContext->alsa.snd_pcm_hw_params_test_format = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_hw_params_test_format");
- pContext->alsa.snd_pcm_hw_params_test_channels = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_hw_params_test_channels");
- pContext->alsa.snd_pcm_hw_params_test_rate = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_hw_params_test_rate");
- pContext->alsa.snd_pcm_hw_params = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_hw_params");
- pContext->alsa.snd_pcm_sw_params_sizeof = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_sw_params_sizeof");
- pContext->alsa.snd_pcm_sw_params_current = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_sw_params_current");
- pContext->alsa.snd_pcm_sw_params_get_boundary = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_sw_params_get_boundary");
- pContext->alsa.snd_pcm_sw_params_set_avail_min = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_sw_params_set_avail_min");
- pContext->alsa.snd_pcm_sw_params_set_start_threshold = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_sw_params_set_start_threshold");
- pContext->alsa.snd_pcm_sw_params_set_stop_threshold = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_sw_params_set_stop_threshold");
- pContext->alsa.snd_pcm_sw_params = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_sw_params");
- pContext->alsa.snd_pcm_format_mask_sizeof = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_format_mask_sizeof");
- pContext->alsa.snd_pcm_format_mask_test = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_format_mask_test");
- pContext->alsa.snd_pcm_get_chmap = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_get_chmap");
- pContext->alsa.snd_pcm_state = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_state");
- pContext->alsa.snd_pcm_prepare = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_prepare");
- pContext->alsa.snd_pcm_start = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_start");
- pContext->alsa.snd_pcm_drop = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_drop");
- pContext->alsa.snd_pcm_drain = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_drain");
- pContext->alsa.snd_pcm_reset = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_reset");
- pContext->alsa.snd_device_name_hint = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_device_name_hint");
- pContext->alsa.snd_device_name_get_hint = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_device_name_get_hint");
- pContext->alsa.snd_card_get_index = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_card_get_index");
- pContext->alsa.snd_device_name_free_hint = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_device_name_free_hint");
- pContext->alsa.snd_pcm_mmap_begin = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_mmap_begin");
- pContext->alsa.snd_pcm_mmap_commit = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_mmap_commit");
- pContext->alsa.snd_pcm_recover = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_recover");
- pContext->alsa.snd_pcm_readi = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_readi");
- pContext->alsa.snd_pcm_writei = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_writei");
- pContext->alsa.snd_pcm_avail = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_avail");
- pContext->alsa.snd_pcm_avail_update = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_avail_update");
- pContext->alsa.snd_pcm_wait = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_wait");
- pContext->alsa.snd_pcm_nonblock = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_nonblock");
- pContext->alsa.snd_pcm_info = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_info");
- pContext->alsa.snd_pcm_info_sizeof = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_info_sizeof");
- pContext->alsa.snd_pcm_info_get_name = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_info_get_name");
- pContext->alsa.snd_pcm_poll_descriptors = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_poll_descriptors");
- pContext->alsa.snd_pcm_poll_descriptors_count = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_poll_descriptors_count");
- pContext->alsa.snd_pcm_poll_descriptors_revents = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_pcm_poll_descriptors_revents");
- pContext->alsa.snd_config_update_free_global = (ma_proc)ma_dlsym(pContext, pContext->alsa.asoundSO, "snd_config_update_free_global");
+ pContext->alsa.snd_pcm_open = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_open");
+ pContext->alsa.snd_pcm_close = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_close");
+ pContext->alsa.snd_pcm_hw_params_sizeof = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_hw_params_sizeof");
+ pContext->alsa.snd_pcm_hw_params_any = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_hw_params_any");
+ pContext->alsa.snd_pcm_hw_params_set_format = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_hw_params_set_format");
+ pContext->alsa.snd_pcm_hw_params_set_format_first = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_hw_params_set_format_first");
+ pContext->alsa.snd_pcm_hw_params_get_format_mask = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_hw_params_get_format_mask");
+ pContext->alsa.snd_pcm_hw_params_set_channels = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_hw_params_set_channels");
+ pContext->alsa.snd_pcm_hw_params_set_channels_near = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_hw_params_set_channels_near");
+ pContext->alsa.snd_pcm_hw_params_set_channels_minmax = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_hw_params_set_channels_minmax");
+ pContext->alsa.snd_pcm_hw_params_set_rate_resample = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_hw_params_set_rate_resample");
+ pContext->alsa.snd_pcm_hw_params_set_rate = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_hw_params_set_rate");
+ pContext->alsa.snd_pcm_hw_params_set_rate_near = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_hw_params_set_rate_near");
+ pContext->alsa.snd_pcm_hw_params_set_buffer_size_near = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_hw_params_set_buffer_size_near");
+ pContext->alsa.snd_pcm_hw_params_set_periods_near = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_hw_params_set_periods_near");
+ pContext->alsa.snd_pcm_hw_params_set_access = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_hw_params_set_access");
+ pContext->alsa.snd_pcm_hw_params_get_format = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_hw_params_get_format");
+ pContext->alsa.snd_pcm_hw_params_get_channels = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_hw_params_get_channels");
+ pContext->alsa.snd_pcm_hw_params_get_channels_min = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_hw_params_get_channels_min");
+ pContext->alsa.snd_pcm_hw_params_get_channels_max = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_hw_params_get_channels_max");
+ pContext->alsa.snd_pcm_hw_params_get_rate = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_hw_params_get_rate");
+ pContext->alsa.snd_pcm_hw_params_get_rate_min = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_hw_params_get_rate_min");
+ pContext->alsa.snd_pcm_hw_params_get_rate_max = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_hw_params_get_rate_max");
+ pContext->alsa.snd_pcm_hw_params_get_buffer_size = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_hw_params_get_buffer_size");
+ pContext->alsa.snd_pcm_hw_params_get_periods = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_hw_params_get_periods");
+ pContext->alsa.snd_pcm_hw_params_get_access = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_hw_params_get_access");
+ pContext->alsa.snd_pcm_hw_params_test_format = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_hw_params_test_format");
+ pContext->alsa.snd_pcm_hw_params_test_channels = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_hw_params_test_channels");
+ pContext->alsa.snd_pcm_hw_params_test_rate = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_hw_params_test_rate");
+ pContext->alsa.snd_pcm_hw_params = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_hw_params");
+ pContext->alsa.snd_pcm_sw_params_sizeof = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_sw_params_sizeof");
+ pContext->alsa.snd_pcm_sw_params_current = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_sw_params_current");
+ pContext->alsa.snd_pcm_sw_params_get_boundary = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_sw_params_get_boundary");
+ pContext->alsa.snd_pcm_sw_params_set_avail_min = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_sw_params_set_avail_min");
+ pContext->alsa.snd_pcm_sw_params_set_start_threshold = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_sw_params_set_start_threshold");
+ pContext->alsa.snd_pcm_sw_params_set_stop_threshold = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_sw_params_set_stop_threshold");
+ pContext->alsa.snd_pcm_sw_params = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_sw_params");
+ pContext->alsa.snd_pcm_format_mask_sizeof = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_format_mask_sizeof");
+ pContext->alsa.snd_pcm_format_mask_test = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_format_mask_test");
+ pContext->alsa.snd_pcm_get_chmap = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_get_chmap");
+ pContext->alsa.snd_pcm_state = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_state");
+ pContext->alsa.snd_pcm_prepare = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_prepare");
+ pContext->alsa.snd_pcm_start = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_start");
+ pContext->alsa.snd_pcm_drop = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_drop");
+ pContext->alsa.snd_pcm_drain = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_drain");
+ pContext->alsa.snd_pcm_reset = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_reset");
+ pContext->alsa.snd_device_name_hint = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_device_name_hint");
+ pContext->alsa.snd_device_name_get_hint = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_device_name_get_hint");
+ pContext->alsa.snd_card_get_index = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_card_get_index");
+ pContext->alsa.snd_device_name_free_hint = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_device_name_free_hint");
+ pContext->alsa.snd_pcm_mmap_begin = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_mmap_begin");
+ pContext->alsa.snd_pcm_mmap_commit = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_mmap_commit");
+ pContext->alsa.snd_pcm_recover = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_recover");
+ pContext->alsa.snd_pcm_readi = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_readi");
+ pContext->alsa.snd_pcm_writei = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_writei");
+ pContext->alsa.snd_pcm_avail = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_avail");
+ pContext->alsa.snd_pcm_avail_update = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_avail_update");
+ pContext->alsa.snd_pcm_wait = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_wait");
+ pContext->alsa.snd_pcm_nonblock = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_nonblock");
+ pContext->alsa.snd_pcm_info = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_info");
+ pContext->alsa.snd_pcm_info_sizeof = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_info_sizeof");
+ pContext->alsa.snd_pcm_info_get_name = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_info_get_name");
+ pContext->alsa.snd_pcm_poll_descriptors = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_poll_descriptors");
+ pContext->alsa.snd_pcm_poll_descriptors_count = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_poll_descriptors_count");
+ pContext->alsa.snd_pcm_poll_descriptors_revents = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_pcm_poll_descriptors_revents");
+ pContext->alsa.snd_config_update_free_global = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->alsa.asoundSO, "snd_config_update_free_global");
#else
/* The system below is just for type safety. */
ma_snd_pcm_open_proc _snd_pcm_open = snd_pcm_open;
@@ -29173,11 +30280,6 @@ static ma_result ma_device_init__pulse(ma_device* pDevice, const ma_device_confi
/*
Notes for PulseAudio:
- - We're always using native format/channels/rate regardless of whether or not PulseAudio
- supports the format directly through their own data conversion system. I'm doing this to
- reduce as much variability from the PulseAudio side as possible because it's seems to be
- extremely unreliable at everything it does.
-
- When both the period size in frames and milliseconds are 0, we default to miniaudio's
default buffer sizes rather than leaving it up to PulseAudio because I don't trust
PulseAudio to give us any kind of reasonable latency by default.
@@ -29199,7 +30301,6 @@ static ma_result ma_device_init__pulse(ma_device* pDevice, const ma_device_confi
ma_pa_channel_map cmap;
ma_pa_buffer_attr attr;
const ma_pa_sample_spec* pActualSS = NULL;
- const ma_pa_channel_map* pActualCMap = NULL;
const ma_pa_buffer_attr* pActualAttr = NULL;
ma_uint32 iChannel;
ma_pa_stream_flags_t streamFlags;
@@ -29255,10 +30356,19 @@ static ma_result ma_device_init__pulse(ma_device* pDevice, const ma_device_confi
ss = sourceInfo.sample_spec;
cmap = sourceInfo.channel_map;
+ /* Use the requested channel count if we have one. */
+ if (pDescriptorCapture->channels != 0) {
+ ss.channels = pDescriptorCapture->channels;
+ }
+
+ /* Use a default channel map. */
+ ((ma_pa_channel_map_init_extend_proc)pDevice->pContext->pulse.pa_channel_map_init_extend)(&cmap, ss.channels, MA_PA_CHANNEL_MAP_DEFAULT);
+
/* Use the requested sample rate if one was specified. */
if (pDescriptorCapture->sampleRate != 0) {
ss.rate = pDescriptorCapture->sampleRate;
}
+ streamFlags = MA_PA_STREAM_START_CORKED | MA_PA_STREAM_ADJUST_LATENCY;
if (ma_format_from_pulse(ss.format) == ma_format_unknown) {
if (ma_is_little_endian()) {
@@ -29266,14 +30376,17 @@ static ma_result ma_device_init__pulse(ma_device* pDevice, const ma_device_confi
} else {
ss.format = MA_PA_SAMPLE_FLOAT32BE;
}
+ streamFlags |= MA_PA_STREAM_FIX_FORMAT;
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_INFO, "[PulseAudio] sample_spec.format not supported by miniaudio. Defaulting to PA_SAMPLE_FLOAT32.\n");
}
if (ss.rate == 0) {
ss.rate = MA_DEFAULT_SAMPLE_RATE;
+ streamFlags |= MA_PA_STREAM_FIX_RATE;
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_INFO, "[PulseAudio] sample_spec.rate = 0. Defaulting to %d.\n", ss.rate);
}
if (ss.channels == 0) {
ss.channels = MA_DEFAULT_CHANNELS;
+ streamFlags |= MA_PA_STREAM_FIX_CHANNELS;
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_INFO, "[PulseAudio] sample_spec.channels = 0. Defaulting to %d.\n", ss.channels);
}
@@ -29302,7 +30415,6 @@ static ma_result ma_device_init__pulse(ma_device* pDevice, const ma_device_confi
/* Connect after we've got all of our internal state set up. */
- streamFlags = MA_PA_STREAM_START_CORKED | MA_PA_STREAM_ADJUST_LATENCY | MA_PA_STREAM_FIX_FORMAT | MA_PA_STREAM_FIX_RATE | MA_PA_STREAM_FIX_CHANNELS;
if (devCapture != NULL) {
streamFlags |= MA_PA_STREAM_DONT_MOVE;
}
@@ -29349,11 +30461,6 @@ static ma_result ma_device_init__pulse(ma_device* pDevice, const ma_device_confi
fixed sooner than later. I might remove this hack later.
*/
if (pDescriptorCapture->channels > 2) {
- pActualCMap = ((ma_pa_stream_get_channel_map_proc)pDevice->pContext->pulse.pa_stream_get_channel_map)((ma_pa_stream*)pDevice->pulse.pStreamCapture);
- if (pActualCMap != NULL) {
- cmap = *pActualCMap;
- }
-
for (iChannel = 0; iChannel < pDescriptorCapture->channels; ++iChannel) {
pDescriptorCapture->channelMap[iChannel] = ma_channel_position_from_pulse(cmap.map[iChannel]);
}
@@ -29396,25 +30503,38 @@ static ma_result ma_device_init__pulse(ma_device* pDevice, const ma_device_confi
ss = sinkInfo.sample_spec;
cmap = sinkInfo.channel_map;
+ /* Use the requested channel count if we have one. */
+ if (pDescriptorPlayback->channels != 0) {
+ ss.channels = pDescriptorPlayback->channels;
+ }
+
+ /* Use a default channel map. */
+ ((ma_pa_channel_map_init_extend_proc)pDevice->pContext->pulse.pa_channel_map_init_extend)(&cmap, ss.channels, MA_PA_CHANNEL_MAP_DEFAULT);
+
+
/* Use the requested sample rate if one was specified. */
if (pDescriptorPlayback->sampleRate != 0) {
ss.rate = pDescriptorPlayback->sampleRate;
}
+ streamFlags = MA_PA_STREAM_START_CORKED | MA_PA_STREAM_ADJUST_LATENCY;
if (ma_format_from_pulse(ss.format) == ma_format_unknown) {
if (ma_is_little_endian()) {
ss.format = MA_PA_SAMPLE_FLOAT32LE;
} else {
ss.format = MA_PA_SAMPLE_FLOAT32BE;
}
+ streamFlags |= MA_PA_STREAM_FIX_FORMAT;
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_INFO, "[PulseAudio] sample_spec.format not supported by miniaudio. Defaulting to PA_SAMPLE_FLOAT32.\n");
}
if (ss.rate == 0) {
ss.rate = MA_DEFAULT_SAMPLE_RATE;
+ streamFlags |= MA_PA_STREAM_FIX_RATE;
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_INFO, "[PulseAudio] sample_spec.rate = 0. Defaulting to %d.\n", ss.rate);
}
if (ss.channels == 0) {
ss.channels = MA_DEFAULT_CHANNELS;
+ streamFlags |= MA_PA_STREAM_FIX_CHANNELS;
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_INFO, "[PulseAudio] sample_spec.channels = 0. Defaulting to %d.\n", ss.channels);
}
@@ -29447,7 +30567,6 @@ static ma_result ma_device_init__pulse(ma_device* pDevice, const ma_device_confi
/* Connect after we've got all of our internal state set up. */
- streamFlags = MA_PA_STREAM_START_CORKED | MA_PA_STREAM_ADJUST_LATENCY | MA_PA_STREAM_FIX_FORMAT | MA_PA_STREAM_FIX_RATE | MA_PA_STREAM_FIX_CHANNELS;
if (devPlayback != NULL) {
streamFlags |= MA_PA_STREAM_DONT_MOVE;
}
@@ -29494,11 +30613,6 @@ static ma_result ma_device_init__pulse(ma_device* pDevice, const ma_device_confi
fixed sooner than later. I might remove this hack later.
*/
if (pDescriptorPlayback->channels > 2) {
- pActualCMap = ((ma_pa_stream_get_channel_map_proc)pDevice->pContext->pulse.pa_stream_get_channel_map)((ma_pa_stream*)pDevice->pulse.pStreamPlayback);
- if (pActualCMap != NULL) {
- cmap = *pActualCMap;
- }
-
for (iChannel = 0; iChannel < pDescriptorPlayback->channels; ++iChannel) {
pDescriptorPlayback->channelMap[iChannel] = ma_channel_position_from_pulse(cmap.map[iChannel]);
}
@@ -29731,7 +30845,7 @@ static ma_result ma_context_uninit__pulse(ma_context* pContext)
ma_free(pContext->pulse.pApplicationName, &pContext->allocationCallbacks);
#ifndef MA_NO_RUNTIME_LINKING
- ma_dlclose(pContext, pContext->pulse.pulseSO);
+ ma_dlclose(ma_context_get_log(pContext), pContext->pulse.pulseSO);
#endif
return MA_SUCCESS;
@@ -29748,7 +30862,7 @@ static ma_result ma_context_init__pulse(ma_context* pContext, const ma_context_c
size_t i;
for (i = 0; i < ma_countof(libpulseNames); ++i) {
- pContext->pulse.pulseSO = ma_dlopen(pContext, libpulseNames[i]);
+ pContext->pulse.pulseSO = ma_dlopen(ma_context_get_log(pContext), libpulseNames[i]);
if (pContext->pulse.pulseSO != NULL) {
break;
}
@@ -29758,67 +30872,67 @@ static ma_result ma_context_init__pulse(ma_context* pContext, const ma_context_c
return MA_NO_BACKEND;
}
- pContext->pulse.pa_mainloop_new = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_mainloop_new");
- pContext->pulse.pa_mainloop_free = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_mainloop_free");
- pContext->pulse.pa_mainloop_quit = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_mainloop_quit");
- pContext->pulse.pa_mainloop_get_api = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_mainloop_get_api");
- pContext->pulse.pa_mainloop_iterate = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_mainloop_iterate");
- pContext->pulse.pa_mainloop_wakeup = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_mainloop_wakeup");
- pContext->pulse.pa_threaded_mainloop_new = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_threaded_mainloop_new");
- pContext->pulse.pa_threaded_mainloop_free = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_threaded_mainloop_free");
- pContext->pulse.pa_threaded_mainloop_start = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_threaded_mainloop_start");
- pContext->pulse.pa_threaded_mainloop_stop = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_threaded_mainloop_stop");
- pContext->pulse.pa_threaded_mainloop_lock = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_threaded_mainloop_lock");
- pContext->pulse.pa_threaded_mainloop_unlock = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_threaded_mainloop_unlock");
- pContext->pulse.pa_threaded_mainloop_wait = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_threaded_mainloop_wait");
- pContext->pulse.pa_threaded_mainloop_signal = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_threaded_mainloop_signal");
- pContext->pulse.pa_threaded_mainloop_accept = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_threaded_mainloop_accept");
- pContext->pulse.pa_threaded_mainloop_get_retval = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_threaded_mainloop_get_retval");
- pContext->pulse.pa_threaded_mainloop_get_api = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_threaded_mainloop_get_api");
- pContext->pulse.pa_threaded_mainloop_in_thread = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_threaded_mainloop_in_thread");
- pContext->pulse.pa_threaded_mainloop_set_name = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_threaded_mainloop_set_name");
- pContext->pulse.pa_context_new = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_context_new");
- pContext->pulse.pa_context_unref = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_context_unref");
- pContext->pulse.pa_context_connect = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_context_connect");
- pContext->pulse.pa_context_disconnect = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_context_disconnect");
- pContext->pulse.pa_context_set_state_callback = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_context_set_state_callback");
- pContext->pulse.pa_context_get_state = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_context_get_state");
- pContext->pulse.pa_context_get_sink_info_list = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_context_get_sink_info_list");
- pContext->pulse.pa_context_get_source_info_list = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_context_get_source_info_list");
- pContext->pulse.pa_context_get_sink_info_by_name = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_context_get_sink_info_by_name");
- pContext->pulse.pa_context_get_source_info_by_name = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_context_get_source_info_by_name");
- pContext->pulse.pa_operation_unref = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_operation_unref");
- pContext->pulse.pa_operation_get_state = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_operation_get_state");
- pContext->pulse.pa_channel_map_init_extend = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_channel_map_init_extend");
- pContext->pulse.pa_channel_map_valid = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_channel_map_valid");
- pContext->pulse.pa_channel_map_compatible = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_channel_map_compatible");
- pContext->pulse.pa_stream_new = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_stream_new");
- pContext->pulse.pa_stream_unref = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_stream_unref");
- pContext->pulse.pa_stream_connect_playback = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_stream_connect_playback");
- pContext->pulse.pa_stream_connect_record = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_stream_connect_record");
- pContext->pulse.pa_stream_disconnect = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_stream_disconnect");
- pContext->pulse.pa_stream_get_state = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_stream_get_state");
- pContext->pulse.pa_stream_get_sample_spec = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_stream_get_sample_spec");
- pContext->pulse.pa_stream_get_channel_map = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_stream_get_channel_map");
- pContext->pulse.pa_stream_get_buffer_attr = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_stream_get_buffer_attr");
- pContext->pulse.pa_stream_set_buffer_attr = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_stream_set_buffer_attr");
- pContext->pulse.pa_stream_get_device_name = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_stream_get_device_name");
- pContext->pulse.pa_stream_set_write_callback = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_stream_set_write_callback");
- pContext->pulse.pa_stream_set_read_callback = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_stream_set_read_callback");
- pContext->pulse.pa_stream_set_suspended_callback = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_stream_set_suspended_callback");
- pContext->pulse.pa_stream_set_moved_callback = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_stream_set_moved_callback");
- pContext->pulse.pa_stream_is_suspended = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_stream_is_suspended");
- pContext->pulse.pa_stream_flush = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_stream_flush");
- pContext->pulse.pa_stream_drain = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_stream_drain");
- pContext->pulse.pa_stream_is_corked = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_stream_is_corked");
- pContext->pulse.pa_stream_cork = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_stream_cork");
- pContext->pulse.pa_stream_trigger = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_stream_trigger");
- pContext->pulse.pa_stream_begin_write = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_stream_begin_write");
- pContext->pulse.pa_stream_write = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_stream_write");
- pContext->pulse.pa_stream_peek = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_stream_peek");
- pContext->pulse.pa_stream_drop = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_stream_drop");
- pContext->pulse.pa_stream_writable_size = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_stream_writable_size");
- pContext->pulse.pa_stream_readable_size = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_stream_readable_size");
+ pContext->pulse.pa_mainloop_new = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_mainloop_new");
+ pContext->pulse.pa_mainloop_free = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_mainloop_free");
+ pContext->pulse.pa_mainloop_quit = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_mainloop_quit");
+ pContext->pulse.pa_mainloop_get_api = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_mainloop_get_api");
+ pContext->pulse.pa_mainloop_iterate = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_mainloop_iterate");
+ pContext->pulse.pa_mainloop_wakeup = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_mainloop_wakeup");
+ pContext->pulse.pa_threaded_mainloop_new = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_threaded_mainloop_new");
+ pContext->pulse.pa_threaded_mainloop_free = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_threaded_mainloop_free");
+ pContext->pulse.pa_threaded_mainloop_start = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_threaded_mainloop_start");
+ pContext->pulse.pa_threaded_mainloop_stop = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_threaded_mainloop_stop");
+ pContext->pulse.pa_threaded_mainloop_lock = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_threaded_mainloop_lock");
+ pContext->pulse.pa_threaded_mainloop_unlock = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_threaded_mainloop_unlock");
+ pContext->pulse.pa_threaded_mainloop_wait = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_threaded_mainloop_wait");
+ pContext->pulse.pa_threaded_mainloop_signal = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_threaded_mainloop_signal");
+ pContext->pulse.pa_threaded_mainloop_accept = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_threaded_mainloop_accept");
+ pContext->pulse.pa_threaded_mainloop_get_retval = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_threaded_mainloop_get_retval");
+ pContext->pulse.pa_threaded_mainloop_get_api = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_threaded_mainloop_get_api");
+ pContext->pulse.pa_threaded_mainloop_in_thread = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_threaded_mainloop_in_thread");
+ pContext->pulse.pa_threaded_mainloop_set_name = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_threaded_mainloop_set_name");
+ pContext->pulse.pa_context_new = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_context_new");
+ pContext->pulse.pa_context_unref = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_context_unref");
+ pContext->pulse.pa_context_connect = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_context_connect");
+ pContext->pulse.pa_context_disconnect = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_context_disconnect");
+ pContext->pulse.pa_context_set_state_callback = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_context_set_state_callback");
+ pContext->pulse.pa_context_get_state = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_context_get_state");
+ pContext->pulse.pa_context_get_sink_info_list = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_context_get_sink_info_list");
+ pContext->pulse.pa_context_get_source_info_list = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_context_get_source_info_list");
+ pContext->pulse.pa_context_get_sink_info_by_name = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_context_get_sink_info_by_name");
+ pContext->pulse.pa_context_get_source_info_by_name = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_context_get_source_info_by_name");
+ pContext->pulse.pa_operation_unref = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_operation_unref");
+ pContext->pulse.pa_operation_get_state = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_operation_get_state");
+ pContext->pulse.pa_channel_map_init_extend = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_channel_map_init_extend");
+ pContext->pulse.pa_channel_map_valid = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_channel_map_valid");
+ pContext->pulse.pa_channel_map_compatible = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_channel_map_compatible");
+ pContext->pulse.pa_stream_new = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_stream_new");
+ pContext->pulse.pa_stream_unref = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_stream_unref");
+ pContext->pulse.pa_stream_connect_playback = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_stream_connect_playback");
+ pContext->pulse.pa_stream_connect_record = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_stream_connect_record");
+ pContext->pulse.pa_stream_disconnect = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_stream_disconnect");
+ pContext->pulse.pa_stream_get_state = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_stream_get_state");
+ pContext->pulse.pa_stream_get_sample_spec = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_stream_get_sample_spec");
+ pContext->pulse.pa_stream_get_channel_map = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_stream_get_channel_map");
+ pContext->pulse.pa_stream_get_buffer_attr = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_stream_get_buffer_attr");
+ pContext->pulse.pa_stream_set_buffer_attr = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_stream_set_buffer_attr");
+ pContext->pulse.pa_stream_get_device_name = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_stream_get_device_name");
+ pContext->pulse.pa_stream_set_write_callback = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_stream_set_write_callback");
+ pContext->pulse.pa_stream_set_read_callback = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_stream_set_read_callback");
+ pContext->pulse.pa_stream_set_suspended_callback = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_stream_set_suspended_callback");
+ pContext->pulse.pa_stream_set_moved_callback = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_stream_set_moved_callback");
+ pContext->pulse.pa_stream_is_suspended = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_stream_is_suspended");
+ pContext->pulse.pa_stream_flush = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_stream_flush");
+ pContext->pulse.pa_stream_drain = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_stream_drain");
+ pContext->pulse.pa_stream_is_corked = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_stream_is_corked");
+ pContext->pulse.pa_stream_cork = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_stream_cork");
+ pContext->pulse.pa_stream_trigger = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_stream_trigger");
+ pContext->pulse.pa_stream_begin_write = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_stream_begin_write");
+ pContext->pulse.pa_stream_write = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_stream_write");
+ pContext->pulse.pa_stream_peek = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_stream_peek");
+ pContext->pulse.pa_stream_drop = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_stream_drop");
+ pContext->pulse.pa_stream_writable_size = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_stream_writable_size");
+ pContext->pulse.pa_stream_readable_size = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->pulse.pulseSO, "pa_stream_readable_size");
#else
/* This strange assignment system is just for type safety. */
ma_pa_mainloop_new_proc _pa_mainloop_new = pa_mainloop_new;
@@ -29963,7 +31077,7 @@ static ma_result ma_context_init__pulse(ma_context* pContext, const ma_context_c
ma_free(pContext->pulse.pServerName, &pContext->allocationCallbacks);
ma_free(pContext->pulse.pApplicationName, &pContext->allocationCallbacks);
#ifndef MA_NO_RUNTIME_LINKING
- ma_dlclose(pContext, pContext->pulse.pulseSO);
+ ma_dlclose(ma_context_get_log(pContext), pContext->pulse.pulseSO);
#endif
return result;
}
@@ -30527,7 +31641,7 @@ static ma_result ma_context_uninit__jack(ma_context* pContext)
pContext->jack.pClientName = NULL;
#ifndef MA_NO_RUNTIME_LINKING
- ma_dlclose(pContext, pContext->jack.jackSO);
+ ma_dlclose(ma_context_get_log(pContext), pContext->jack.jackSO);
#endif
return MA_SUCCESS;
@@ -30537,10 +31651,11 @@ static ma_result ma_context_init__jack(ma_context* pContext, const ma_context_co
{
#ifndef MA_NO_RUNTIME_LINKING
const char* libjackNames[] = {
-#ifdef MA_WIN32
+#if defined(MA_WIN32)
"libjack.dll",
"libjack64.dll"
-#else
+#endif
+#if defined(MA_UNIX)
"libjack.so",
"libjack.so.0"
#endif
@@ -30548,7 +31663,7 @@ static ma_result ma_context_init__jack(ma_context* pContext, const ma_context_co
size_t i;
for (i = 0; i < ma_countof(libjackNames); ++i) {
- pContext->jack.jackSO = ma_dlopen(pContext, libjackNames[i]);
+ pContext->jack.jackSO = ma_dlopen(ma_context_get_log(pContext), libjackNames[i]);
if (pContext->jack.jackSO != NULL) {
break;
}
@@ -30558,22 +31673,22 @@ static ma_result ma_context_init__jack(ma_context* pContext, const ma_context_co
return MA_NO_BACKEND;
}
- pContext->jack.jack_client_open = (ma_proc)ma_dlsym(pContext, pContext->jack.jackSO, "jack_client_open");
- pContext->jack.jack_client_close = (ma_proc)ma_dlsym(pContext, pContext->jack.jackSO, "jack_client_close");
- pContext->jack.jack_client_name_size = (ma_proc)ma_dlsym(pContext, pContext->jack.jackSO, "jack_client_name_size");
- pContext->jack.jack_set_process_callback = (ma_proc)ma_dlsym(pContext, pContext->jack.jackSO, "jack_set_process_callback");
- pContext->jack.jack_set_buffer_size_callback = (ma_proc)ma_dlsym(pContext, pContext->jack.jackSO, "jack_set_buffer_size_callback");
- pContext->jack.jack_on_shutdown = (ma_proc)ma_dlsym(pContext, pContext->jack.jackSO, "jack_on_shutdown");
- pContext->jack.jack_get_sample_rate = (ma_proc)ma_dlsym(pContext, pContext->jack.jackSO, "jack_get_sample_rate");
- pContext->jack.jack_get_buffer_size = (ma_proc)ma_dlsym(pContext, pContext->jack.jackSO, "jack_get_buffer_size");
- pContext->jack.jack_get_ports = (ma_proc)ma_dlsym(pContext, pContext->jack.jackSO, "jack_get_ports");
- pContext->jack.jack_activate = (ma_proc)ma_dlsym(pContext, pContext->jack.jackSO, "jack_activate");
- pContext->jack.jack_deactivate = (ma_proc)ma_dlsym(pContext, pContext->jack.jackSO, "jack_deactivate");
- pContext->jack.jack_connect = (ma_proc)ma_dlsym(pContext, pContext->jack.jackSO, "jack_connect");
- pContext->jack.jack_port_register = (ma_proc)ma_dlsym(pContext, pContext->jack.jackSO, "jack_port_register");
- pContext->jack.jack_port_name = (ma_proc)ma_dlsym(pContext, pContext->jack.jackSO, "jack_port_name");
- pContext->jack.jack_port_get_buffer = (ma_proc)ma_dlsym(pContext, pContext->jack.jackSO, "jack_port_get_buffer");
- pContext->jack.jack_free = (ma_proc)ma_dlsym(pContext, pContext->jack.jackSO, "jack_free");
+ pContext->jack.jack_client_open = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->jack.jackSO, "jack_client_open");
+ pContext->jack.jack_client_close = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->jack.jackSO, "jack_client_close");
+ pContext->jack.jack_client_name_size = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->jack.jackSO, "jack_client_name_size");
+ pContext->jack.jack_set_process_callback = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->jack.jackSO, "jack_set_process_callback");
+ pContext->jack.jack_set_buffer_size_callback = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->jack.jackSO, "jack_set_buffer_size_callback");
+ pContext->jack.jack_on_shutdown = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->jack.jackSO, "jack_on_shutdown");
+ pContext->jack.jack_get_sample_rate = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->jack.jackSO, "jack_get_sample_rate");
+ pContext->jack.jack_get_buffer_size = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->jack.jackSO, "jack_get_buffer_size");
+ pContext->jack.jack_get_ports = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->jack.jackSO, "jack_get_ports");
+ pContext->jack.jack_activate = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->jack.jackSO, "jack_activate");
+ pContext->jack.jack_deactivate = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->jack.jackSO, "jack_deactivate");
+ pContext->jack.jack_connect = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->jack.jackSO, "jack_connect");
+ pContext->jack.jack_port_register = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->jack.jackSO, "jack_port_register");
+ pContext->jack.jack_port_name = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->jack.jackSO, "jack_port_name");
+ pContext->jack.jack_port_get_buffer = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->jack.jackSO, "jack_port_get_buffer");
+ pContext->jack.jack_free = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->jack.jackSO, "jack_free");
#else
/*
This strange assignment system is here just to ensure type safety of miniaudio's function pointer
@@ -30629,7 +31744,7 @@ static ma_result ma_context_init__jack(ma_context* pContext, const ma_context_co
if (result != MA_SUCCESS) {
ma_free(pContext->jack.pClientName, &pContext->allocationCallbacks);
#ifndef MA_NO_RUNTIME_LINKING
- ma_dlclose(pContext, pContext->jack.jackSO);
+ ma_dlclose(ma_context_get_log(pContext), pContext->jack.jackSO);
#endif
return MA_NO_BACKEND;
}
@@ -30763,6 +31878,18 @@ size, allocate a block of memory of that size and then call AudioObjectGetProper
AudioDeviceID's so just do "dataSize/sizeof(AudioDeviceID)" to know the device count.
*/
+#if defined(MA_APPLE_MOBILE)
+static void ma_device__on_notification_interruption_began(ma_device* pDevice)
+{
+ ma_device__on_notification(ma_device_notification_init(pDevice, ma_device_notification_type_interruption_began));
+}
+
+static void ma_device__on_notification_interruption_ended(ma_device* pDevice)
+{
+ ma_device__on_notification(ma_device_notification_init(pDevice, ma_device_notification_type_interruption_ended));
+}
+#endif
+
static ma_result ma_result_from_OSStatus(OSStatus status)
{
switch (status)
@@ -31029,15 +32156,15 @@ static ma_result ma_get_channel_map_from_AudioChannelLayout(AudioChannelLayout*
{
pChannelMap[7] = MA_CHANNEL_SIDE_RIGHT;
pChannelMap[6] = MA_CHANNEL_SIDE_LEFT;
- } /* Intentional fallthrough. */
+ } MA_FALLTHROUGH; /* Intentional fallthrough. */
case kAudioChannelLayoutTag_Hexagonal:
{
pChannelMap[5] = MA_CHANNEL_BACK_CENTER;
- } /* Intentional fallthrough. */
+ } MA_FALLTHROUGH; /* Intentional fallthrough. */
case kAudioChannelLayoutTag_Pentagonal:
{
pChannelMap[4] = MA_CHANNEL_FRONT_CENTER;
- } /* Intentional fallghrough. */
+ } MA_FALLTHROUGH; /* Intentional fallthrough. */
case kAudioChannelLayoutTag_Quadraphonic:
{
pChannelMap[3] = MA_CHANNEL_BACK_RIGHT;
@@ -31679,9 +32806,9 @@ static ma_result ma_find_best_format__coreaudio(ma_context* pContext, AudioObjec
hasSupportedFormat = MA_FALSE;
for (iFormat = 0; iFormat < deviceFormatDescriptionCount; ++iFormat) {
- ma_format format;
- ma_result formatResult = ma_format_from_AudioStreamBasicDescription(&pDeviceFormatDescriptions[iFormat].mFormat, &format);
- if (formatResult == MA_SUCCESS && format != ma_format_unknown) {
+ ma_format formatFromDescription;
+ ma_result formatResult = ma_format_from_AudioStreamBasicDescription(&pDeviceFormatDescriptions[iFormat].mFormat, &formatFromDescription);
+ if (formatResult == MA_SUCCESS && formatFromDescription != ma_format_unknown) {
hasSupportedFormat = MA_TRUE;
bestDeviceFormatSoFar = pDeviceFormatDescriptions[iFormat].mFormat;
break;
@@ -33641,9 +34768,9 @@ static ma_result ma_context_uninit__coreaudio(ma_context* pContext)
#endif
#if !defined(MA_NO_RUNTIME_LINKING) && !defined(MA_APPLE_MOBILE)
- ma_dlclose(pContext, pContext->coreaudio.hAudioUnit);
- ma_dlclose(pContext, pContext->coreaudio.hCoreAudio);
- ma_dlclose(pContext, pContext->coreaudio.hCoreFoundation);
+ ma_dlclose(ma_context_get_log(pContext), pContext->coreaudio.hAudioUnit);
+ ma_dlclose(ma_context_get_log(pContext), pContext->coreaudio.hCoreAudio);
+ ma_dlclose(ma_context_get_log(pContext), pContext->coreaudio.hCoreFoundation);
#endif
#if !defined(MA_APPLE_MOBILE)
@@ -33732,26 +34859,26 @@ static ma_result ma_context_init__coreaudio(ma_context* pContext, const ma_conte
#endif
#if !defined(MA_NO_RUNTIME_LINKING) && !defined(MA_APPLE_MOBILE)
- pContext->coreaudio.hCoreFoundation = ma_dlopen(pContext, "CoreFoundation.framework/CoreFoundation");
+ pContext->coreaudio.hCoreFoundation = ma_dlopen(ma_context_get_log(pContext), "/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation");
if (pContext->coreaudio.hCoreFoundation == NULL) {
return MA_API_NOT_FOUND;
}
- pContext->coreaudio.CFStringGetCString = ma_dlsym(pContext, pContext->coreaudio.hCoreFoundation, "CFStringGetCString");
- pContext->coreaudio.CFRelease = ma_dlsym(pContext, pContext->coreaudio.hCoreFoundation, "CFRelease");
+ pContext->coreaudio.CFStringGetCString = ma_dlsym(ma_context_get_log(pContext), pContext->coreaudio.hCoreFoundation, "CFStringGetCString");
+ pContext->coreaudio.CFRelease = ma_dlsym(ma_context_get_log(pContext), pContext->coreaudio.hCoreFoundation, "CFRelease");
- pContext->coreaudio.hCoreAudio = ma_dlopen(pContext, "CoreAudio.framework/CoreAudio");
+ pContext->coreaudio.hCoreAudio = ma_dlopen(ma_context_get_log(pContext), "/System/Library/Frameworks/CoreAudio.framework/CoreAudio");
if (pContext->coreaudio.hCoreAudio == NULL) {
- ma_dlclose(pContext, pContext->coreaudio.hCoreFoundation);
+ ma_dlclose(ma_context_get_log(pContext), pContext->coreaudio.hCoreFoundation);
return MA_API_NOT_FOUND;
}
- pContext->coreaudio.AudioObjectGetPropertyData = ma_dlsym(pContext, pContext->coreaudio.hCoreAudio, "AudioObjectGetPropertyData");
- pContext->coreaudio.AudioObjectGetPropertyDataSize = ma_dlsym(pContext, pContext->coreaudio.hCoreAudio, "AudioObjectGetPropertyDataSize");
- pContext->coreaudio.AudioObjectSetPropertyData = ma_dlsym(pContext, pContext->coreaudio.hCoreAudio, "AudioObjectSetPropertyData");
- pContext->coreaudio.AudioObjectAddPropertyListener = ma_dlsym(pContext, pContext->coreaudio.hCoreAudio, "AudioObjectAddPropertyListener");
- pContext->coreaudio.AudioObjectRemovePropertyListener = ma_dlsym(pContext, pContext->coreaudio.hCoreAudio, "AudioObjectRemovePropertyListener");
+ pContext->coreaudio.AudioObjectGetPropertyData = ma_dlsym(ma_context_get_log(pContext), pContext->coreaudio.hCoreAudio, "AudioObjectGetPropertyData");
+ pContext->coreaudio.AudioObjectGetPropertyDataSize = ma_dlsym(ma_context_get_log(pContext), pContext->coreaudio.hCoreAudio, "AudioObjectGetPropertyDataSize");
+ pContext->coreaudio.AudioObjectSetPropertyData = ma_dlsym(ma_context_get_log(pContext), pContext->coreaudio.hCoreAudio, "AudioObjectSetPropertyData");
+ pContext->coreaudio.AudioObjectAddPropertyListener = ma_dlsym(ma_context_get_log(pContext), pContext->coreaudio.hCoreAudio, "AudioObjectAddPropertyListener");
+ pContext->coreaudio.AudioObjectRemovePropertyListener = ma_dlsym(ma_context_get_log(pContext), pContext->coreaudio.hCoreAudio, "AudioObjectRemovePropertyListener");
/*
It looks like Apple has moved some APIs from AudioUnit into AudioToolbox on more recent versions of macOS. They are still
@@ -33759,35 +34886,35 @@ static ma_result ma_context_init__coreaudio(ma_context* pContext, const ma_conte
The way it'll work is that it'll first try AudioUnit, and if the required symbols are not present there we'll fall back to
AudioToolbox.
*/
- pContext->coreaudio.hAudioUnit = ma_dlopen(pContext, "AudioUnit.framework/AudioUnit");
+ pContext->coreaudio.hAudioUnit = ma_dlopen(ma_context_get_log(pContext), "/System/Library/Frameworks/AudioUnit.framework/AudioUnit");
if (pContext->coreaudio.hAudioUnit == NULL) {
- ma_dlclose(pContext, pContext->coreaudio.hCoreAudio);
- ma_dlclose(pContext, pContext->coreaudio.hCoreFoundation);
+ ma_dlclose(ma_context_get_log(pContext), pContext->coreaudio.hCoreAudio);
+ ma_dlclose(ma_context_get_log(pContext), pContext->coreaudio.hCoreFoundation);
return MA_API_NOT_FOUND;
}
- if (ma_dlsym(pContext, pContext->coreaudio.hAudioUnit, "AudioComponentFindNext") == NULL) {
+ if (ma_dlsym(ma_context_get_log(pContext), pContext->coreaudio.hAudioUnit, "AudioComponentFindNext") == NULL) {
/* Couldn't find the required symbols in AudioUnit, so fall back to AudioToolbox. */
- ma_dlclose(pContext, pContext->coreaudio.hAudioUnit);
- pContext->coreaudio.hAudioUnit = ma_dlopen(pContext, "AudioToolbox.framework/AudioToolbox");
+ ma_dlclose(ma_context_get_log(pContext), pContext->coreaudio.hAudioUnit);
+ pContext->coreaudio.hAudioUnit = ma_dlopen(ma_context_get_log(pContext), "/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox");
if (pContext->coreaudio.hAudioUnit == NULL) {
- ma_dlclose(pContext, pContext->coreaudio.hCoreAudio);
- ma_dlclose(pContext, pContext->coreaudio.hCoreFoundation);
+ ma_dlclose(ma_context_get_log(pContext), pContext->coreaudio.hCoreAudio);
+ ma_dlclose(ma_context_get_log(pContext), pContext->coreaudio.hCoreFoundation);
return MA_API_NOT_FOUND;
}
}
- pContext->coreaudio.AudioComponentFindNext = ma_dlsym(pContext, pContext->coreaudio.hAudioUnit, "AudioComponentFindNext");
- pContext->coreaudio.AudioComponentInstanceDispose = ma_dlsym(pContext, pContext->coreaudio.hAudioUnit, "AudioComponentInstanceDispose");
- pContext->coreaudio.AudioComponentInstanceNew = ma_dlsym(pContext, pContext->coreaudio.hAudioUnit, "AudioComponentInstanceNew");
- pContext->coreaudio.AudioOutputUnitStart = ma_dlsym(pContext, pContext->coreaudio.hAudioUnit, "AudioOutputUnitStart");
- pContext->coreaudio.AudioOutputUnitStop = ma_dlsym(pContext, pContext->coreaudio.hAudioUnit, "AudioOutputUnitStop");
- pContext->coreaudio.AudioUnitAddPropertyListener = ma_dlsym(pContext, pContext->coreaudio.hAudioUnit, "AudioUnitAddPropertyListener");
- pContext->coreaudio.AudioUnitGetPropertyInfo = ma_dlsym(pContext, pContext->coreaudio.hAudioUnit, "AudioUnitGetPropertyInfo");
- pContext->coreaudio.AudioUnitGetProperty = ma_dlsym(pContext, pContext->coreaudio.hAudioUnit, "AudioUnitGetProperty");
- pContext->coreaudio.AudioUnitSetProperty = ma_dlsym(pContext, pContext->coreaudio.hAudioUnit, "AudioUnitSetProperty");
- pContext->coreaudio.AudioUnitInitialize = ma_dlsym(pContext, pContext->coreaudio.hAudioUnit, "AudioUnitInitialize");
- pContext->coreaudio.AudioUnitRender = ma_dlsym(pContext, pContext->coreaudio.hAudioUnit, "AudioUnitRender");
+ pContext->coreaudio.AudioComponentFindNext = ma_dlsym(ma_context_get_log(pContext), pContext->coreaudio.hAudioUnit, "AudioComponentFindNext");
+ pContext->coreaudio.AudioComponentInstanceDispose = ma_dlsym(ma_context_get_log(pContext), pContext->coreaudio.hAudioUnit, "AudioComponentInstanceDispose");
+ pContext->coreaudio.AudioComponentInstanceNew = ma_dlsym(ma_context_get_log(pContext), pContext->coreaudio.hAudioUnit, "AudioComponentInstanceNew");
+ pContext->coreaudio.AudioOutputUnitStart = ma_dlsym(ma_context_get_log(pContext), pContext->coreaudio.hAudioUnit, "AudioOutputUnitStart");
+ pContext->coreaudio.AudioOutputUnitStop = ma_dlsym(ma_context_get_log(pContext), pContext->coreaudio.hAudioUnit, "AudioOutputUnitStop");
+ pContext->coreaudio.AudioUnitAddPropertyListener = ma_dlsym(ma_context_get_log(pContext), pContext->coreaudio.hAudioUnit, "AudioUnitAddPropertyListener");
+ pContext->coreaudio.AudioUnitGetPropertyInfo = ma_dlsym(ma_context_get_log(pContext), pContext->coreaudio.hAudioUnit, "AudioUnitGetPropertyInfo");
+ pContext->coreaudio.AudioUnitGetProperty = ma_dlsym(ma_context_get_log(pContext), pContext->coreaudio.hAudioUnit, "AudioUnitGetProperty");
+ pContext->coreaudio.AudioUnitSetProperty = ma_dlsym(ma_context_get_log(pContext), pContext->coreaudio.hAudioUnit, "AudioUnitSetProperty");
+ pContext->coreaudio.AudioUnitInitialize = ma_dlsym(ma_context_get_log(pContext), pContext->coreaudio.hAudioUnit, "AudioUnitInitialize");
+ pContext->coreaudio.AudioUnitRender = ma_dlsym(ma_context_get_log(pContext), pContext->coreaudio.hAudioUnit, "AudioUnitRender");
#else
pContext->coreaudio.CFStringGetCString = (ma_proc)CFStringGetCString;
pContext->coreaudio.CFRelease = (ma_proc)CFRelease;
@@ -33829,9 +34956,9 @@ static ma_result ma_context_init__coreaudio(ma_context* pContext, const ma_conte
pContext->coreaudio.component = ((ma_AudioComponentFindNext_proc)pContext->coreaudio.AudioComponentFindNext)(NULL, &desc);
if (pContext->coreaudio.component == NULL) {
#if !defined(MA_NO_RUNTIME_LINKING) && !defined(MA_APPLE_MOBILE)
- ma_dlclose(pContext, pContext->coreaudio.hAudioUnit);
- ma_dlclose(pContext, pContext->coreaudio.hCoreAudio);
- ma_dlclose(pContext, pContext->coreaudio.hCoreFoundation);
+ ma_dlclose(ma_context_get_log(pContext), pContext->coreaudio.hAudioUnit);
+ ma_dlclose(ma_context_get_log(pContext), pContext->coreaudio.hCoreAudio);
+ ma_dlclose(ma_context_get_log(pContext), pContext->coreaudio.hCoreFoundation);
#endif
return MA_FAILED_TO_INIT_BACKEND;
}
@@ -33841,9 +34968,9 @@ static ma_result ma_context_init__coreaudio(ma_context* pContext, const ma_conte
result = ma_context__init_device_tracking__coreaudio(pContext);
if (result != MA_SUCCESS) {
#if !defined(MA_NO_RUNTIME_LINKING) && !defined(MA_APPLE_MOBILE)
- ma_dlclose(pContext, pContext->coreaudio.hAudioUnit);
- ma_dlclose(pContext, pContext->coreaudio.hCoreAudio);
- ma_dlclose(pContext, pContext->coreaudio.hCoreFoundation);
+ ma_dlclose(ma_context_get_log(pContext), pContext->coreaudio.hAudioUnit);
+ ma_dlclose(ma_context_get_log(pContext), pContext->coreaudio.hCoreAudio);
+ ma_dlclose(ma_context_get_log(pContext), pContext->coreaudio.hCoreFoundation);
#endif
return result;
}
@@ -34664,7 +35791,7 @@ static ma_result ma_context_init__sndio(ma_context* pContext, const ma_context_c
size_t i;
for (i = 0; i < ma_countof(libsndioNames); ++i) {
- pContext->sndio.sndioSO = ma_dlopen(pContext, libsndioNames[i]);
+ pContext->sndio.sndioSO = ma_dlopen(ma_context_get_log(pContext), libsndioNames[i]);
if (pContext->sndio.sndioSO != NULL) {
break;
}
@@ -34674,16 +35801,16 @@ static ma_result ma_context_init__sndio(ma_context* pContext, const ma_context_c
return MA_NO_BACKEND;
}
- pContext->sndio.sio_open = (ma_proc)ma_dlsym(pContext, pContext->sndio.sndioSO, "sio_open");
- pContext->sndio.sio_close = (ma_proc)ma_dlsym(pContext, pContext->sndio.sndioSO, "sio_close");
- pContext->sndio.sio_setpar = (ma_proc)ma_dlsym(pContext, pContext->sndio.sndioSO, "sio_setpar");
- pContext->sndio.sio_getpar = (ma_proc)ma_dlsym(pContext, pContext->sndio.sndioSO, "sio_getpar");
- pContext->sndio.sio_getcap = (ma_proc)ma_dlsym(pContext, pContext->sndio.sndioSO, "sio_getcap");
- pContext->sndio.sio_write = (ma_proc)ma_dlsym(pContext, pContext->sndio.sndioSO, "sio_write");
- pContext->sndio.sio_read = (ma_proc)ma_dlsym(pContext, pContext->sndio.sndioSO, "sio_read");
- pContext->sndio.sio_start = (ma_proc)ma_dlsym(pContext, pContext->sndio.sndioSO, "sio_start");
- pContext->sndio.sio_stop = (ma_proc)ma_dlsym(pContext, pContext->sndio.sndioSO, "sio_stop");
- pContext->sndio.sio_initpar = (ma_proc)ma_dlsym(pContext, pContext->sndio.sndioSO, "sio_initpar");
+ pContext->sndio.sio_open = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->sndio.sndioSO, "sio_open");
+ pContext->sndio.sio_close = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->sndio.sndioSO, "sio_close");
+ pContext->sndio.sio_setpar = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->sndio.sndioSO, "sio_setpar");
+ pContext->sndio.sio_getpar = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->sndio.sndioSO, "sio_getpar");
+ pContext->sndio.sio_getcap = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->sndio.sndioSO, "sio_getcap");
+ pContext->sndio.sio_write = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->sndio.sndioSO, "sio_write");
+ pContext->sndio.sio_read = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->sndio.sndioSO, "sio_read");
+ pContext->sndio.sio_start = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->sndio.sndioSO, "sio_start");
+ pContext->sndio.sio_stop = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->sndio.sndioSO, "sio_stop");
+ pContext->sndio.sio_initpar = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->sndio.sndioSO, "sio_initpar");
#else
pContext->sndio.sio_open = sio_open;
pContext->sndio.sio_close = sio_close;
@@ -35144,8 +36271,13 @@ static ma_result ma_device_init_fd__audio4(ma_device* pDevice, const ma_device_c
"/dev/audio",
"/dev/audio0"
};
+ const char* pDefaultDeviceCtlNames[] = {
+ "/dev/audioctl",
+ "/dev/audioctl0"
+ };
int fd;
int fdFlags = 0;
+ size_t iDefaultDevice = (size_t)-1;
ma_format internalFormat;
ma_uint32 internalChannels;
ma_uint32 internalSampleRate;
@@ -35164,11 +36296,11 @@ static ma_result ma_device_init_fd__audio4(ma_device* pDevice, const ma_device_c
}
/*fdFlags |= O_NONBLOCK;*/
+ /* Find the index of the default device as a start. We'll use this index later. Set it to (size_t)-1 otherwise. */
if (pDescriptor->pDeviceID == NULL) {
/* Default device. */
- size_t iDevice;
- for (iDevice = 0; iDevice < ma_countof(pDefaultDeviceNames); ++iDevice) {
- fd = open(pDefaultDeviceNames[iDevice], fdFlags, 0);
+ for (iDefaultDevice = 0; iDefaultDevice < ma_countof(pDefaultDeviceNames); ++iDefaultDevice) {
+ fd = open(pDefaultDeviceNames[iDefaultDevice], fdFlags, 0);
if (fd != -1) {
break;
}
@@ -35176,6 +36308,16 @@ static ma_result ma_device_init_fd__audio4(ma_device* pDevice, const ma_device_c
} else {
/* Specific device. */
fd = open(pDescriptor->pDeviceID->audio4, fdFlags, 0);
+
+ for (iDefaultDevice = 0; iDefaultDevice < ma_countof(pDefaultDeviceNames); iDefaultDevice += 1) {
+ if (ma_strcmp(pDefaultDeviceNames[iDefaultDevice], pDescriptor->pDeviceID->audio4) == 0) {
+ break;
+ }
+ }
+
+ if (iDefaultDevice == ma_countof(pDefaultDeviceNames)) {
+ iDefaultDevice = (size_t)-1;
+ }
}
if (fd == -1) {
@@ -35186,6 +36328,7 @@ static ma_result ma_device_init_fd__audio4(ma_device* pDevice, const ma_device_c
#if !defined(MA_AUDIO4_USE_NEW_API) /* Old API */
{
audio_info_t fdInfo;
+ int fdInfoResult = -1;
/*
The documentation is a little bit unclear to me as to how it handles formats. It says the
@@ -35205,6 +36348,28 @@ static ma_result ma_device_init_fd__audio4(ma_device* pDevice, const ma_device_c
*/
AUDIO_INITINFO(&fdInfo);
+ /*
+ Get the default format from the audioctl file if we're asking for a default device. If we
+ retrieve it from /dev/audio it'll default to mono 8000Hz.
+ */
+ if (iDefaultDevice != (size_t)-1) {
+ /* We're using a default device. Get the info from the /dev/audioctl file instead of /dev/audio. */
+ int fdctl = open(pDefaultDeviceCtlNames[iDefaultDevice], fdFlags, 0);
+ if (fdctl != -1) {
+ fdInfoResult = ioctl(fdctl, AUDIO_GETINFO, &fdInfo);
+ close(fdctl);
+ }
+ }
+
+ if (fdInfoResult == -1) {
+ /* We still don't have the default device info so just retrieve it from the main audio device. */
+ if (ioctl(fd, AUDIO_GETINFO, &fdInfo) < 0) {
+ close(fd);
+ ma_log_post(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[audio4] AUDIO_GETINFO failed.");
+ return ma_result_from_errno(errno);
+ }
+ }
+
/* We get the driver to do as much of the data conversion as possible. */
if (deviceType == ma_device_type_capture) {
fdInfo.mode = AUMODE_RECORD;
@@ -36192,6 +37357,9 @@ static ma_result ma_context_init__oss(ma_context* pContext, const ma_context_con
#endif /* OSS */
+
+
+
/******************************************************************************
AAudio Backend
@@ -36210,6 +37378,7 @@ typedef int32_t ma_aaudio_performance_mo
typedef int32_t ma_aaudio_usage_t;
typedef int32_t ma_aaudio_content_type_t;
typedef int32_t ma_aaudio_input_preset_t;
+typedef int32_t ma_aaudio_allowed_capture_policy_t;
typedef int32_t ma_aaudio_data_callback_result_t;
typedef struct ma_AAudioStreamBuilder_t* ma_AAudioStreamBuilder;
typedef struct ma_AAudioStream_t* ma_AAudioStream;
@@ -36284,6 +37453,11 @@ typedef struct ma_AAudioStream_t* ma_AAudioStream;
#define MA_AAUDIO_INPUT_PRESET_UNPROCESSED 9
#define MA_AAUDIO_INPUT_PRESET_VOICE_PERFORMANCE 10
+/* Allowed Capture Policies */
+#define MA_AAUDIO_ALLOW_CAPTURE_BY_ALL 1
+#define MA_AAUDIO_ALLOW_CAPTURE_BY_SYSTEM 2
+#define MA_AAUDIO_ALLOW_CAPTURE_BY_NONE 3
+
/* Callback results. */
#define MA_AAUDIO_CALLBACK_RESULT_CONTINUE 0
#define MA_AAUDIO_CALLBACK_RESULT_STOP 1
@@ -36308,6 +37482,7 @@ typedef void (* MA_PFN_AAudioStreamBuilder_setPerformanceMod
typedef void (* MA_PFN_AAudioStreamBuilder_setUsage) (ma_AAudioStreamBuilder* pBuilder, ma_aaudio_usage_t contentType);
typedef void (* MA_PFN_AAudioStreamBuilder_setContentType) (ma_AAudioStreamBuilder* pBuilder, ma_aaudio_content_type_t contentType);
typedef void (* MA_PFN_AAudioStreamBuilder_setInputPreset) (ma_AAudioStreamBuilder* pBuilder, ma_aaudio_input_preset_t inputPreset);
+typedef void (* MA_PFN_AAudioStreamBuilder_setAllowedCapturePolicy) (ma_AAudioStreamBuilder* pBuilder, ma_aaudio_allowed_capture_policy_t policy);
typedef ma_aaudio_result_t (* MA_PFN_AAudioStreamBuilder_openStream) (ma_AAudioStreamBuilder* pBuilder, ma_AAudioStream** ppStream);
typedef ma_aaudio_result_t (* MA_PFN_AAudioStream_close) (ma_AAudioStream* pStream);
typedef ma_aaudio_stream_state_t (* MA_PFN_AAudioStream_getState) (ma_AAudioStream* pStream);
@@ -36385,8 +37560,22 @@ static ma_aaudio_input_preset_t ma_to_input_preset__aaudio(ma_aaudio_input_prese
return MA_AAUDIO_INPUT_PRESET_GENERIC;
}
+static ma_aaudio_allowed_capture_policy_t ma_to_allowed_capture_policy__aaudio(ma_aaudio_allowed_capture_policy allowedCapturePolicy)
+{
+ switch (allowedCapturePolicy) {
+ case ma_aaudio_allow_capture_by_all: return MA_AAUDIO_ALLOW_CAPTURE_BY_ALL;
+ case ma_aaudio_allow_capture_by_system: return MA_AAUDIO_ALLOW_CAPTURE_BY_SYSTEM;
+ case ma_aaudio_allow_capture_by_none: return MA_AAUDIO_ALLOW_CAPTURE_BY_NONE;
+ default: break;
+ }
+
+ return MA_AAUDIO_ALLOW_CAPTURE_BY_ALL;
+}
+
static void ma_stream_error_callback__aaudio(ma_AAudioStream* pStream, void* pUserData, ma_aaudio_result_t error)
{
+ ma_result result;
+ ma_job job;
ma_device* pDevice = (ma_device*)pUserData;
MA_ASSERT(pDevice != NULL);
@@ -36395,26 +37584,24 @@ static void ma_stream_error_callback__aaudio(ma_AAudioStream* pStream, void* pUs
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_INFO, "[AAudio] ERROR CALLBACK: error=%d, AAudioStream_getState()=%d\n", error, ((MA_PFN_AAudioStream_getState)pDevice->pContext->aaudio.AAudioStream_getState)(pStream));
/*
- From the documentation for AAudio, when a device is disconnected all we can do is stop it. However, we cannot stop it from the callback - we need
- to do it from another thread. Therefore we are going to use an event thread for the AAudio backend to do this cleanly and safely.
+ When we get an error, we'll assume that the stream is in an erroneous state and needs to be restarted. From the documentation,
+ we cannot do this from the error callback. Therefore we are going to use an event thread for the AAudio backend to do this
+ cleanly and safely.
*/
- if (((MA_PFN_AAudioStream_getState)pDevice->pContext->aaudio.AAudioStream_getState)(pStream) == MA_AAUDIO_STREAM_STATE_DISCONNECTED) {
- /* We need to post a job to the job thread for processing. This will reroute the device by reinitializing the stream. */
- ma_result result;
- ma_job job = ma_job_init(MA_JOB_TYPE_DEVICE_AAUDIO_REROUTE);
- job.data.device.aaudio.reroute.pDevice = pDevice;
+ job = ma_job_init(MA_JOB_TYPE_DEVICE_AAUDIO_REROUTE);
+ job.data.device.aaudio.reroute.pDevice = pDevice;
- if (pStream == pDevice->aaudio.pStreamCapture) {
- job.data.device.aaudio.reroute.deviceType = ma_device_type_capture;
- } else {
- job.data.device.aaudio.reroute.deviceType = ma_device_type_playback;
- }
+ if (pStream == pDevice->aaudio.pStreamCapture) {
+ job.data.device.aaudio.reroute.deviceType = ma_device_type_capture;
+ }
+ else {
+ job.data.device.aaudio.reroute.deviceType = ma_device_type_playback;
+ }
- result = ma_device_job_thread_post(&pDevice->pContext->aaudio.jobThread, &job);
- if (result != MA_SUCCESS) {
- ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_INFO, "[AAudio] Device Disconnected. Failed to post job for rerouting.\n");
- return;
- }
+ result = ma_device_job_thread_post(&pDevice->pContext->aaudio.jobThread, &job);
+ if (result != MA_SUCCESS) {
+ ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_INFO, "[AAudio] Device Disconnected. Failed to post job for rerouting.\n");
+ return;
}
}
@@ -36444,7 +37631,6 @@ static ma_result ma_create_and_configure_AAudioStreamBuilder__aaudio(ma_context*
{
ma_AAudioStreamBuilder* pBuilder;
ma_aaudio_result_t resultAA;
- ma_uint32 bufferCapacityInFrames;
/* Safety. */
*ppBuilder = NULL;
@@ -36486,17 +37672,26 @@ static ma_result ma_create_and_configure_AAudioStreamBuilder__aaudio(ma_context*
}
}
- /*
- AAudio is annoying when it comes to it's buffer calculation stuff because it doesn't let you
- retrieve the actual sample rate until after you've opened the stream. But you need to configure
- the buffer capacity before you open the stream... :/
- To solve, we're just going to assume MA_DEFAULT_SAMPLE_RATE (48000) and move on.
+ /*
+ There have been reports where setting the frames per data callback results in an error
+ later on from Android. To address this, I'm experimenting with simply not setting it on
+ anything from Android 11 and earlier. Suggestions welcome on how we might be able to make
+ this more targetted.
*/
- bufferCapacityInFrames = ma_calculate_buffer_size_in_frames_from_descriptor(pDescriptor, pDescriptor->sampleRate, pConfig->performanceProfile) * pDescriptor->periodCount;
+ if (!pConfig->aaudio.enableCompatibilityWorkarounds || ma_android_sdk_version() > 30) {
+ /*
+ AAudio is annoying when it comes to it's buffer calculation stuff because it doesn't let you
+ retrieve the actual sample rate until after you've opened the stream. But you need to configure
+ the buffer capacity before you open the stream... :/
+
+ To solve, we're just going to assume MA_DEFAULT_SAMPLE_RATE (48000) and move on.
+ */
+ ma_uint32 bufferCapacityInFrames = ma_calculate_buffer_size_in_frames_from_descriptor(pDescriptor, pDescriptor->sampleRate, pConfig->performanceProfile) * pDescriptor->periodCount;
- ((MA_PFN_AAudioStreamBuilder_setBufferCapacityInFrames)pContext->aaudio.AAudioStreamBuilder_setBufferCapacityInFrames)(pBuilder, bufferCapacityInFrames);
- ((MA_PFN_AAudioStreamBuilder_setFramesPerDataCallback)pContext->aaudio.AAudioStreamBuilder_setFramesPerDataCallback)(pBuilder, bufferCapacityInFrames / pDescriptor->periodCount);
+ ((MA_PFN_AAudioStreamBuilder_setBufferCapacityInFrames)pContext->aaudio.AAudioStreamBuilder_setBufferCapacityInFrames)(pBuilder, bufferCapacityInFrames);
+ ((MA_PFN_AAudioStreamBuilder_setFramesPerDataCallback)pContext->aaudio.AAudioStreamBuilder_setFramesPerDataCallback)(pBuilder, bufferCapacityInFrames / pDescriptor->periodCount);
+ }
if (deviceType == ma_device_type_capture) {
if (pConfig->aaudio.inputPreset != ma_aaudio_input_preset_default && pContext->aaudio.AAudioStreamBuilder_setInputPreset != NULL) {
@@ -36513,6 +37708,10 @@ static ma_result ma_create_and_configure_AAudioStreamBuilder__aaudio(ma_context*
((MA_PFN_AAudioStreamBuilder_setContentType)pContext->aaudio.AAudioStreamBuilder_setContentType)(pBuilder, ma_to_content_type__aaudio(pConfig->aaudio.contentType));
}
+ if (pConfig->aaudio.allowedCapturePolicy != ma_aaudio_allow_capture_default && pContext->aaudio.AAudioStreamBuilder_setAllowedCapturePolicy != NULL) {
+ ((MA_PFN_AAudioStreamBuilder_setAllowedCapturePolicy)pContext->aaudio.AAudioStreamBuilder_setAllowedCapturePolicy)(pBuilder, ma_to_allowed_capture_policy__aaudio(pConfig->aaudio.allowedCapturePolicy));
+ }
+
((MA_PFN_AAudioStreamBuilder_setDataCallback)pContext->aaudio.AAudioStreamBuilder_setDataCallback)(pBuilder, ma_stream_data_callback_playback__aaudio, (void*)pDevice);
}
@@ -36780,6 +37979,7 @@ static ma_result ma_device_init__aaudio(ma_device* pDevice, const ma_device_conf
pDevice->aaudio.usage = pConfig->aaudio.usage;
pDevice->aaudio.contentType = pConfig->aaudio.contentType;
pDevice->aaudio.inputPreset = pConfig->aaudio.inputPreset;
+ pDevice->aaudio.allowedCapturePolicy = pConfig->aaudio.allowedCapturePolicy;
pDevice->aaudio.noAutoStartAfterReroute = pConfig->aaudio.noAutoStartAfterReroute;
if (pConfig->deviceType == ma_device_type_capture || pConfig->deviceType == ma_device_type_duplex) {
@@ -36956,6 +38156,7 @@ static ma_result ma_device_reinit__aaudio(ma_device* pDevice, ma_device_type dev
deviceConfig.aaudio.usage = pDevice->aaudio.usage;
deviceConfig.aaudio.contentType = pDevice->aaudio.contentType;
deviceConfig.aaudio.inputPreset = pDevice->aaudio.inputPreset;
+ deviceConfig.aaudio.allowedCapturePolicy = pDevice->aaudio.allowedCapturePolicy;
deviceConfig.aaudio.noAutoStartAfterReroute = pDevice->aaudio.noAutoStartAfterReroute;
deviceConfig.periods = 1;
@@ -37051,7 +38252,7 @@ static ma_result ma_context_uninit__aaudio(ma_context* pContext)
ma_device_job_thread_uninit(&pContext->aaudio.jobThread, &pContext->allocationCallbacks);
- ma_dlclose(pContext, pContext->aaudio.hAAudio);
+ ma_dlclose(ma_context_get_log(pContext), pContext->aaudio.hAAudio);
pContext->aaudio.hAAudio = NULL;
return MA_SUCCESS;
@@ -37065,7 +38266,7 @@ static ma_result ma_context_init__aaudio(ma_context* pContext, const ma_context_
};
for (i = 0; i < ma_countof(libNames); ++i) {
- pContext->aaudio.hAAudio = ma_dlopen(pContext, libNames[i]);
+ pContext->aaudio.hAAudio = ma_dlopen(ma_context_get_log(pContext), libNames[i]);
if (pContext->aaudio.hAAudio != NULL) {
break;
}
@@ -37075,34 +38276,35 @@ static ma_result ma_context_init__aaudio(ma_context* pContext, const ma_context_
return MA_FAILED_TO_INIT_BACKEND;
}
- pContext->aaudio.AAudio_createStreamBuilder = (ma_proc)ma_dlsym(pContext, pContext->aaudio.hAAudio, "AAudio_createStreamBuilder");
- pContext->aaudio.AAudioStreamBuilder_delete = (ma_proc)ma_dlsym(pContext, pContext->aaudio.hAAudio, "AAudioStreamBuilder_delete");
- pContext->aaudio.AAudioStreamBuilder_setDeviceId = (ma_proc)ma_dlsym(pContext, pContext->aaudio.hAAudio, "AAudioStreamBuilder_setDeviceId");
- pContext->aaudio.AAudioStreamBuilder_setDirection = (ma_proc)ma_dlsym(pContext, pContext->aaudio.hAAudio, "AAudioStreamBuilder_setDirection");
- pContext->aaudio.AAudioStreamBuilder_setSharingMode = (ma_proc)ma_dlsym(pContext, pContext->aaudio.hAAudio, "AAudioStreamBuilder_setSharingMode");
- pContext->aaudio.AAudioStreamBuilder_setFormat = (ma_proc)ma_dlsym(pContext, pContext->aaudio.hAAudio, "AAudioStreamBuilder_setFormat");
- pContext->aaudio.AAudioStreamBuilder_setChannelCount = (ma_proc)ma_dlsym(pContext, pContext->aaudio.hAAudio, "AAudioStreamBuilder_setChannelCount");
- pContext->aaudio.AAudioStreamBuilder_setSampleRate = (ma_proc)ma_dlsym(pContext, pContext->aaudio.hAAudio, "AAudioStreamBuilder_setSampleRate");
- pContext->aaudio.AAudioStreamBuilder_setBufferCapacityInFrames = (ma_proc)ma_dlsym(pContext, pContext->aaudio.hAAudio, "AAudioStreamBuilder_setBufferCapacityInFrames");
- pContext->aaudio.AAudioStreamBuilder_setFramesPerDataCallback = (ma_proc)ma_dlsym(pContext, pContext->aaudio.hAAudio, "AAudioStreamBuilder_setFramesPerDataCallback");
- pContext->aaudio.AAudioStreamBuilder_setDataCallback = (ma_proc)ma_dlsym(pContext, pContext->aaudio.hAAudio, "AAudioStreamBuilder_setDataCallback");
- pContext->aaudio.AAudioStreamBuilder_setErrorCallback = (ma_proc)ma_dlsym(pContext, pContext->aaudio.hAAudio, "AAudioStreamBuilder_setErrorCallback");
- pContext->aaudio.AAudioStreamBuilder_setPerformanceMode = (ma_proc)ma_dlsym(pContext, pContext->aaudio.hAAudio, "AAudioStreamBuilder_setPerformanceMode");
- pContext->aaudio.AAudioStreamBuilder_setUsage = (ma_proc)ma_dlsym(pContext, pContext->aaudio.hAAudio, "AAudioStreamBuilder_setUsage");
- pContext->aaudio.AAudioStreamBuilder_setContentType = (ma_proc)ma_dlsym(pContext, pContext->aaudio.hAAudio, "AAudioStreamBuilder_setContentType");
- pContext->aaudio.AAudioStreamBuilder_setInputPreset = (ma_proc)ma_dlsym(pContext, pContext->aaudio.hAAudio, "AAudioStreamBuilder_setInputPreset");
- pContext->aaudio.AAudioStreamBuilder_openStream = (ma_proc)ma_dlsym(pContext, pContext->aaudio.hAAudio, "AAudioStreamBuilder_openStream");
- pContext->aaudio.AAudioStream_close = (ma_proc)ma_dlsym(pContext, pContext->aaudio.hAAudio, "AAudioStream_close");
- pContext->aaudio.AAudioStream_getState = (ma_proc)ma_dlsym(pContext, pContext->aaudio.hAAudio, "AAudioStream_getState");
- pContext->aaudio.AAudioStream_waitForStateChange = (ma_proc)ma_dlsym(pContext, pContext->aaudio.hAAudio, "AAudioStream_waitForStateChange");
- pContext->aaudio.AAudioStream_getFormat = (ma_proc)ma_dlsym(pContext, pContext->aaudio.hAAudio, "AAudioStream_getFormat");
- pContext->aaudio.AAudioStream_getChannelCount = (ma_proc)ma_dlsym(pContext, pContext->aaudio.hAAudio, "AAudioStream_getChannelCount");
- pContext->aaudio.AAudioStream_getSampleRate = (ma_proc)ma_dlsym(pContext, pContext->aaudio.hAAudio, "AAudioStream_getSampleRate");
- pContext->aaudio.AAudioStream_getBufferCapacityInFrames = (ma_proc)ma_dlsym(pContext, pContext->aaudio.hAAudio, "AAudioStream_getBufferCapacityInFrames");
- pContext->aaudio.AAudioStream_getFramesPerDataCallback = (ma_proc)ma_dlsym(pContext, pContext->aaudio.hAAudio, "AAudioStream_getFramesPerDataCallback");
- pContext->aaudio.AAudioStream_getFramesPerBurst = (ma_proc)ma_dlsym(pContext, pContext->aaudio.hAAudio, "AAudioStream_getFramesPerBurst");
- pContext->aaudio.AAudioStream_requestStart = (ma_proc)ma_dlsym(pContext, pContext->aaudio.hAAudio, "AAudioStream_requestStart");
- pContext->aaudio.AAudioStream_requestStop = (ma_proc)ma_dlsym(pContext, pContext->aaudio.hAAudio, "AAudioStream_requestStop");
+ pContext->aaudio.AAudio_createStreamBuilder = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->aaudio.hAAudio, "AAudio_createStreamBuilder");
+ pContext->aaudio.AAudioStreamBuilder_delete = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->aaudio.hAAudio, "AAudioStreamBuilder_delete");
+ pContext->aaudio.AAudioStreamBuilder_setDeviceId = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->aaudio.hAAudio, "AAudioStreamBuilder_setDeviceId");
+ pContext->aaudio.AAudioStreamBuilder_setDirection = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->aaudio.hAAudio, "AAudioStreamBuilder_setDirection");
+ pContext->aaudio.AAudioStreamBuilder_setSharingMode = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->aaudio.hAAudio, "AAudioStreamBuilder_setSharingMode");
+ pContext->aaudio.AAudioStreamBuilder_setFormat = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->aaudio.hAAudio, "AAudioStreamBuilder_setFormat");
+ pContext->aaudio.AAudioStreamBuilder_setChannelCount = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->aaudio.hAAudio, "AAudioStreamBuilder_setChannelCount");
+ pContext->aaudio.AAudioStreamBuilder_setSampleRate = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->aaudio.hAAudio, "AAudioStreamBuilder_setSampleRate");
+ pContext->aaudio.AAudioStreamBuilder_setBufferCapacityInFrames = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->aaudio.hAAudio, "AAudioStreamBuilder_setBufferCapacityInFrames");
+ pContext->aaudio.AAudioStreamBuilder_setFramesPerDataCallback = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->aaudio.hAAudio, "AAudioStreamBuilder_setFramesPerDataCallback");
+ pContext->aaudio.AAudioStreamBuilder_setDataCallback = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->aaudio.hAAudio, "AAudioStreamBuilder_setDataCallback");
+ pContext->aaudio.AAudioStreamBuilder_setErrorCallback = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->aaudio.hAAudio, "AAudioStreamBuilder_setErrorCallback");
+ pContext->aaudio.AAudioStreamBuilder_setPerformanceMode = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->aaudio.hAAudio, "AAudioStreamBuilder_setPerformanceMode");
+ pContext->aaudio.AAudioStreamBuilder_setUsage = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->aaudio.hAAudio, "AAudioStreamBuilder_setUsage");
+ pContext->aaudio.AAudioStreamBuilder_setContentType = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->aaudio.hAAudio, "AAudioStreamBuilder_setContentType");
+ pContext->aaudio.AAudioStreamBuilder_setInputPreset = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->aaudio.hAAudio, "AAudioStreamBuilder_setInputPreset");
+ pContext->aaudio.AAudioStreamBuilder_setAllowedCapturePolicy = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->aaudio.hAAudio, "AAudioStreamBuilder_setAllowedCapturePolicy");
+ pContext->aaudio.AAudioStreamBuilder_openStream = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->aaudio.hAAudio, "AAudioStreamBuilder_openStream");
+ pContext->aaudio.AAudioStream_close = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->aaudio.hAAudio, "AAudioStream_close");
+ pContext->aaudio.AAudioStream_getState = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->aaudio.hAAudio, "AAudioStream_getState");
+ pContext->aaudio.AAudioStream_waitForStateChange = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->aaudio.hAAudio, "AAudioStream_waitForStateChange");
+ pContext->aaudio.AAudioStream_getFormat = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->aaudio.hAAudio, "AAudioStream_getFormat");
+ pContext->aaudio.AAudioStream_getChannelCount = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->aaudio.hAAudio, "AAudioStream_getChannelCount");
+ pContext->aaudio.AAudioStream_getSampleRate = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->aaudio.hAAudio, "AAudioStream_getSampleRate");
+ pContext->aaudio.AAudioStream_getBufferCapacityInFrames = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->aaudio.hAAudio, "AAudioStream_getBufferCapacityInFrames");
+ pContext->aaudio.AAudioStream_getFramesPerDataCallback = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->aaudio.hAAudio, "AAudioStream_getFramesPerDataCallback");
+ pContext->aaudio.AAudioStream_getFramesPerBurst = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->aaudio.hAAudio, "AAudioStream_getFramesPerBurst");
+ pContext->aaudio.AAudioStream_requestStart = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->aaudio.hAAudio, "AAudioStream_requestStart");
+ pContext->aaudio.AAudioStream_requestStop = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->aaudio.hAAudio, "AAudioStream_requestStop");
pCallbacks->onContextInit = ma_context_init__aaudio;
@@ -37128,7 +38330,7 @@ static ma_result ma_context_init__aaudio(ma_context* pContext, const ma_context_
result = ma_device_job_thread_init(&jobThreadConfig, &pContext->allocationCallbacks, &pContext->aaudio.jobThread);
if (result != MA_SUCCESS) {
- ma_dlclose(pContext, pContext->aaudio.hAAudio);
+ ma_dlclose(ma_context_get_log(pContext), pContext->aaudio.hAAudio);
pContext->aaudio.hAAudio = NULL;
return result;
}
@@ -38144,7 +39346,7 @@ static ma_result ma_device_start__opensl(ma_device* pDevice)
return ma_result_from_OpenSL(resultSL);
}
- /* In playback mode (no duplex) we need to load some initial buffers. In duplex mode we need to enqueu silent buffers. */
+ /* In playback mode (no duplex) we need to load some initial buffers. In duplex mode we need to enqueue silent buffers. */
if (pDevice->type == ma_device_type_duplex) {
MA_ZERO_MEMORY(pDevice->opensl.pBufferPlayback, pDevice->playback.internalPeriodSizeInFrames * pDevice->playback.internalPeriods * ma_get_bytes_per_frame(pDevice->playback.internalFormat, pDevice->playback.internalChannels));
} else {
@@ -38265,7 +39467,7 @@ static ma_result ma_context_uninit__opensl(ma_context* pContext)
static ma_result ma_dlsym_SLInterfaceID__opensl(ma_context* pContext, const char* pName, ma_handle* pHandle)
{
/* We need to return an error if the symbol cannot be found. This is important because there have been reports that some symbols do not exist. */
- ma_handle* p = (ma_handle*)ma_dlsym(pContext, pContext->opensl.libOpenSLES, pName);
+ ma_handle* p = (ma_handle*)ma_dlsym(ma_context_get_log(pContext), pContext->opensl.libOpenSLES, pName);
if (p == NULL) {
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_INFO, "[OpenSL] Cannot find symbol %s", pName);
return MA_NO_BACKEND;
@@ -38323,7 +39525,7 @@ static ma_result ma_context_init__opensl(ma_context* pContext, const ma_context_
references to the symbols and will hopefully skip the checks.
*/
for (i = 0; i < ma_countof(libOpenSLESNames); i += 1) {
- pContext->opensl.libOpenSLES = ma_dlopen(pContext, libOpenSLESNames[i]);
+ pContext->opensl.libOpenSLES = ma_dlopen(ma_context_get_log(pContext), libOpenSLESNames[i]);
if (pContext->opensl.libOpenSLES != NULL) {
break;
}
@@ -38336,49 +39538,49 @@ static ma_result ma_context_init__opensl(ma_context* pContext, const ma_context_
result = ma_dlsym_SLInterfaceID__opensl(pContext, "SL_IID_ENGINE", &pContext->opensl.SL_IID_ENGINE);
if (result != MA_SUCCESS) {
- ma_dlclose(pContext, pContext->opensl.libOpenSLES);
+ ma_dlclose(ma_context_get_log(pContext), pContext->opensl.libOpenSLES);
return result;
}
result = ma_dlsym_SLInterfaceID__opensl(pContext, "SL_IID_AUDIOIODEVICECAPABILITIES", &pContext->opensl.SL_IID_AUDIOIODEVICECAPABILITIES);
if (result != MA_SUCCESS) {
- ma_dlclose(pContext, pContext->opensl.libOpenSLES);
+ ma_dlclose(ma_context_get_log(pContext), pContext->opensl.libOpenSLES);
return result;
}
result = ma_dlsym_SLInterfaceID__opensl(pContext, "SL_IID_ANDROIDSIMPLEBUFFERQUEUE", &pContext->opensl.SL_IID_ANDROIDSIMPLEBUFFERQUEUE);
if (result != MA_SUCCESS) {
- ma_dlclose(pContext, pContext->opensl.libOpenSLES);
+ ma_dlclose(ma_context_get_log(pContext), pContext->opensl.libOpenSLES);
return result;
}
result = ma_dlsym_SLInterfaceID__opensl(pContext, "SL_IID_RECORD", &pContext->opensl.SL_IID_RECORD);
if (result != MA_SUCCESS) {
- ma_dlclose(pContext, pContext->opensl.libOpenSLES);
+ ma_dlclose(ma_context_get_log(pContext), pContext->opensl.libOpenSLES);
return result;
}
result = ma_dlsym_SLInterfaceID__opensl(pContext, "SL_IID_PLAY", &pContext->opensl.SL_IID_PLAY);
if (result != MA_SUCCESS) {
- ma_dlclose(pContext, pContext->opensl.libOpenSLES);
+ ma_dlclose(ma_context_get_log(pContext), pContext->opensl.libOpenSLES);
return result;
}
result = ma_dlsym_SLInterfaceID__opensl(pContext, "SL_IID_OUTPUTMIX", &pContext->opensl.SL_IID_OUTPUTMIX);
if (result != MA_SUCCESS) {
- ma_dlclose(pContext, pContext->opensl.libOpenSLES);
+ ma_dlclose(ma_context_get_log(pContext), pContext->opensl.libOpenSLES);
return result;
}
result = ma_dlsym_SLInterfaceID__opensl(pContext, "SL_IID_ANDROIDCONFIGURATION", &pContext->opensl.SL_IID_ANDROIDCONFIGURATION);
if (result != MA_SUCCESS) {
- ma_dlclose(pContext, pContext->opensl.libOpenSLES);
+ ma_dlclose(ma_context_get_log(pContext), pContext->opensl.libOpenSLES);
return result;
}
- pContext->opensl.slCreateEngine = (ma_proc)ma_dlsym(pContext, pContext->opensl.libOpenSLES, "slCreateEngine");
+ pContext->opensl.slCreateEngine = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->opensl.libOpenSLES, "slCreateEngine");
if (pContext->opensl.slCreateEngine == NULL) {
- ma_dlclose(pContext, pContext->opensl.libOpenSLES);
+ ma_dlclose(ma_context_get_log(pContext), pContext->opensl.libOpenSLES);
ma_log_post(ma_context_get_log(pContext), MA_LOG_LEVEL_INFO, "[OpenSL] Cannot find symbol slCreateEngine.");
return MA_NO_BACKEND;
}
@@ -38402,7 +39604,7 @@ static ma_result ma_context_init__opensl(ma_context* pContext, const ma_context_
ma_spinlock_unlock(&g_maOpenSLSpinlock);
if (result != MA_SUCCESS) {
- ma_dlclose(pContext, pContext->opensl.libOpenSLES);
+ ma_dlclose(ma_context_get_log(pContext), pContext->opensl.libOpenSLES);
ma_log_post(ma_context_get_log(pContext), MA_LOG_LEVEL_INFO, "[OpenSL] Failed to initialize OpenSL engine.");
return result;
}
@@ -38432,6 +39634,29 @@ Web Audio Backend
#ifdef MA_HAS_WEBAUDIO
#include
+#if (__EMSCRIPTEN_major__ > 3) || (__EMSCRIPTEN_major__ == 3 && (__EMSCRIPTEN_minor__ > 1 || (__EMSCRIPTEN_minor__ == 1 && __EMSCRIPTEN_tiny__ >= 32)))
+ #include
+ #define MA_SUPPORT_AUDIO_WORKLETS
+#endif
+
+/*
+TODO: Version 0.12: Swap this logic around so that AudioWorklets are used by default. Add MA_NO_AUDIO_WORKLETS.
+*/
+#if defined(MA_ENABLE_AUDIO_WORKLETS) && defined(MA_SUPPORT_AUDIO_WORKLETS)
+ #define MA_USE_AUDIO_WORKLETS
+#endif
+
+/* The thread stack size must be a multiple of 16. */
+#ifndef MA_AUDIO_WORKLETS_THREAD_STACK_SIZE
+#define MA_AUDIO_WORKLETS_THREAD_STACK_SIZE 16384
+#endif
+
+#if defined(MA_USE_AUDIO_WORKLETS)
+#define MA_WEBAUDIO_LATENCY_HINT_BALANCED "balanced"
+#define MA_WEBAUDIO_LATENCY_HINT_INTERACTIVE "interactive"
+#define MA_WEBAUDIO_LATENCY_HINT_PLAYBACK "playback"
+#endif
+
static ma_bool32 ma_is_capture_supported__webaudio()
{
return EM_ASM_INT({
@@ -38442,6 +39667,16 @@ static ma_bool32 ma_is_capture_supported__webaudio()
#ifdef __cplusplus
extern "C" {
#endif
+void* EMSCRIPTEN_KEEPALIVE ma_malloc_emscripten(size_t sz, const ma_allocation_callbacks* pAllocationCallbacks)
+{
+ return ma_malloc(sz, pAllocationCallbacks);
+}
+
+void EMSCRIPTEN_KEEPALIVE ma_free_emscripten(void* p, const ma_allocation_callbacks* pAllocationCallbacks)
+{
+ ma_free(p, pAllocationCallbacks);
+}
+
void EMSCRIPTEN_KEEPALIVE ma_device_process_pcm_frames_capture__webaudio(ma_device* pDevice, int frameCount, float* pFrames)
{
ma_device_handle_backend_data_callback(pDevice, NULL, pFrames, (ma_uint32)frameCount);
@@ -38532,69 +39767,76 @@ static ma_result ma_context_get_device_info__webaudio(ma_context* pContext, ma_d
return MA_SUCCESS;
}
-
-static void ma_device_uninit_by_index__webaudio(ma_device* pDevice, ma_device_type deviceType, int deviceIndex)
+static ma_result ma_device_uninit__webaudio(ma_device* pDevice)
{
MA_ASSERT(pDevice != NULL);
- EM_ASM({
- var device = miniaudio.get_device_by_index($0);
-
- /* Make sure all nodes are disconnected and marked for collection. */
- if (device.scriptNode !== undefined) {
- device.scriptNode.onaudioprocess = function(e) {}; /* We want to reset the callback to ensure it doesn't get called after AudioContext.close() has returned. Shouldn't happen since we're disconnecting, but just to be safe... */
- device.scriptNode.disconnect();
- device.scriptNode = undefined;
- }
- if (device.streamNode !== undefined) {
- device.streamNode.disconnect();
- device.streamNode = undefined;
- }
+ #if defined(MA_USE_AUDIO_WORKLETS)
+ {
+ EM_ASM({
+ var device = miniaudio.get_device_by_index($0);
- /*
- Stop the device. I think there is a chance the callback could get fired after calling this, hence why we want
- to clear the callback before closing.
- */
- device.webaudio.close();
- device.webaudio = undefined;
+ if (device.streamNode !== undefined) {
+ device.streamNode.disconnect();
+ device.streamNode = undefined;
+ }
+ }, pDevice->webaudio.deviceIndex);
- /* Can't forget to free the intermediary buffer. This is the buffer that's shared between JavaScript and C. */
- if (device.intermediaryBuffer !== undefined) {
- Module._free(device.intermediaryBuffer);
- device.intermediaryBuffer = undefined;
- device.intermediaryBufferView = undefined;
- device.intermediaryBufferSizeInBytes = undefined;
- }
+ emscripten_destroy_web_audio_node(pDevice->webaudio.audioWorklet);
+ emscripten_destroy_audio_context(pDevice->webaudio.audioContext);
+ ma_free(pDevice->webaudio.pStackBuffer, &pDevice->pContext->allocationCallbacks);
+ }
+ #else
+ {
+ EM_ASM({
+ var device = miniaudio.get_device_by_index($0);
- /* Make sure the device is untracked so the slot can be reused later. */
- miniaudio.untrack_device_by_index($0);
- }, deviceIndex, deviceType);
-}
+ /* Make sure all nodes are disconnected and marked for collection. */
+ if (device.scriptNode !== undefined) {
+ device.scriptNode.onaudioprocess = function(e) {}; /* We want to reset the callback to ensure it doesn't get called after AudioContext.close() has returned. Shouldn't happen since we're disconnecting, but just to be safe... */
+ device.scriptNode.disconnect();
+ device.scriptNode = undefined;
+ }
-static ma_result ma_device_uninit__webaudio(ma_device* pDevice)
-{
- MA_ASSERT(pDevice != NULL);
+ if (device.streamNode !== undefined) {
+ device.streamNode.disconnect();
+ device.streamNode = undefined;
+ }
- if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) {
- ma_device_uninit_by_index__webaudio(pDevice, ma_device_type_capture, pDevice->webaudio.indexCapture);
+ /*
+ Stop the device. I think there is a chance the callback could get fired after calling this, hence why we want
+ to clear the callback before closing.
+ */
+ device.webaudio.close();
+ device.webaudio = undefined;
+ device.pDevice = undefined;
+ }, pDevice->webaudio.deviceIndex);
}
+ #endif
- if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) {
- ma_device_uninit_by_index__webaudio(pDevice, ma_device_type_playback, pDevice->webaudio.indexPlayback);
- }
+ /* Clean up the device on the JS side. */
+ EM_ASM({
+ miniaudio.untrack_device_by_index($0);
+ }, pDevice->webaudio.deviceIndex);
+
+ ma_free(pDevice->webaudio.pIntermediaryBuffer, &pDevice->pContext->allocationCallbacks);
return MA_SUCCESS;
}
+#if !defined(MA_USE_AUDIO_WORKLETS)
static ma_uint32 ma_calculate_period_size_in_frames_from_descriptor__webaudio(const ma_device_descriptor* pDescriptor, ma_uint32 nativeSampleRate, ma_performance_profile performanceProfile)
{
/*
- There have been reports of the default buffer size being too small on some browsers. There have been reports of the default buffer
- size being too small on some browsers. If we're using default buffer size, we'll make sure the period size is a big biffer than our
- standard defaults.
+ There have been reports of the default buffer size being too small on some browsers. If we're using
+ the default buffer size, we'll make sure the period size is bigger than our standard defaults.
*/
ma_uint32 periodSizeInFrames;
+ if (nativeSampleRate == 0) {
+ nativeSampleRate = MA_DEFAULT_SAMPLE_RATE;
+ }
+
if (pDescriptor->periodSizeInFrames == 0) {
if (pDescriptor->periodSizeInMilliseconds == 0) {
if (performanceProfile == ma_performance_profile_low_latency) {
@@ -38620,220 +39862,224 @@ static ma_uint32 ma_calculate_period_size_in_frames_from_descriptor__webaudio(co
return periodSizeInFrames;
}
+#endif
-static ma_result ma_device_init_by_type__webaudio(ma_device* pDevice, const ma_device_config* pConfig, ma_device_descriptor* pDescriptor, ma_device_type deviceType)
+
+#if defined(MA_USE_AUDIO_WORKLETS)
+typedef struct
{
- int deviceIndex;
- ma_uint32 channels;
- ma_uint32 sampleRate;
- ma_uint32 periodSizeInFrames;
+ ma_device* pDevice;
+ const ma_device_config* pConfig;
+ ma_device_descriptor* pDescriptorPlayback;
+ ma_device_descriptor* pDescriptorCapture;
+} ma_audio_worklet_thread_initialized_data;
- MA_ASSERT(pDevice != NULL);
- MA_ASSERT(pConfig != NULL);
- MA_ASSERT(deviceType != ma_device_type_duplex);
+static EM_BOOL ma_audio_worklet_process_callback__webaudio(int inputCount, const AudioSampleFrame* pInputs, int outputCount, AudioSampleFrame* pOutputs, int paramCount, const AudioParamFrame* pParams, void* pUserData)
+{
+ ma_device* pDevice = (ma_device*)pUserData;
+ ma_uint32 frameCount;
- if (deviceType == ma_device_type_capture && !ma_is_capture_supported__webaudio()) {
- return MA_NO_DEVICE;
+ (void)paramCount;
+ (void)pParams;
+
+ if (ma_device_get_state(pDevice) != ma_device_state_started) {
+ return EM_TRUE;
}
- /* We're going to calculate some stuff in C just to simplify the JS code. */
- channels = (pDescriptor->channels > 0) ? pDescriptor->channels : MA_DEFAULT_CHANNELS;
- sampleRate = (pDescriptor->sampleRate > 0) ? pDescriptor->sampleRate : MA_DEFAULT_SAMPLE_RATE;
- periodSizeInFrames = ma_calculate_period_size_in_frames_from_descriptor__webaudio(pDescriptor, sampleRate, pConfig->performanceProfile);
+ /*
+ The Emscripten documentation says that it'll always be 128 frames being passed in. Hard coding it like that feels
+ like a very bad idea to me. Even if it's hard coded in the backend, the API and documentation should always refer
+ to variables instead of a hard coded number. In any case, will follow along for the time being.
- ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_DEBUG, "periodSizeInFrames = %d\n", (int)periodSizeInFrames);
+ Unfortunately the audio data is not interleaved so we'll need to convert it before we give the data to miniaudio
+ for further processing.
+ */
+ frameCount = 128;
- /* We create the device on the JavaScript side and reference it using an index. We use this to make it possible to reference the device between JavaScript and C. */
- deviceIndex = EM_ASM_INT({
- var channels = $0;
- var sampleRate = $1;
- var bufferSize = $2; /* In PCM frames. */
- var isCapture = $3;
- var pDevice = $4;
+ if (inputCount > 0) {
+ /* Input data needs to be interleaved before we hand it to the client. */
+ for (ma_uint32 iChannel = 0; iChannel < pDevice->capture.internalChannels; iChannel += 1) {
+ for (ma_uint32 iFrame = 0; iFrame < frameCount; iFrame += 1) {
+ pDevice->webaudio.pIntermediaryBuffer[iFrame*pDevice->capture.internalChannels + iChannel] = pInputs[0].data[frameCount*iChannel + iFrame];
+ }
+ }
- if (typeof(window.miniaudio) === 'undefined') {
- return -1; /* Context not initialized. */
+ ma_device_process_pcm_frames_capture__webaudio(pDevice, frameCount, pDevice->webaudio.pIntermediaryBuffer);
+ }
+
+ if (outputCount > 0) {
+ /* If it's a capture-only device, we'll need to output silence. */
+ if (pDevice->type == ma_device_type_capture) {
+ MA_ZERO_MEMORY(pOutputs[0].data, frameCount * pDevice->playback.internalChannels * sizeof(float));
+ } else {
+ ma_device_process_pcm_frames_playback__webaudio(pDevice, frameCount, pDevice->webaudio.pIntermediaryBuffer);
+
+ /* We've read the data from the client. Now we need to deinterleave the buffer and output to the output buffer. */
+ for (ma_uint32 iChannel = 0; iChannel < pDevice->playback.internalChannels; iChannel += 1) {
+ for (ma_uint32 iFrame = 0; iFrame < frameCount; iFrame += 1) {
+ pOutputs[0].data[frameCount*iChannel + iFrame] = pDevice->webaudio.pIntermediaryBuffer[iFrame*pDevice->playback.internalChannels + iChannel];
+ }
+ }
}
+ }
- var device = {};
+ return EM_TRUE;
+}
- /* The AudioContext must be created in a suspended state. */
- device.webaudio = new (window.AudioContext || window.webkitAudioContext)({sampleRate:sampleRate});
- device.webaudio.suspend();
- device.state = 1; /* ma_device_state_stopped */
- /*
- We need an intermediary buffer which we use for JavaScript and C interop. This buffer stores interleaved f32 PCM data. Because it's passed between
- JavaScript and C it needs to be allocated and freed using Module._malloc() and Module._free().
- */
- device.intermediaryBufferSizeInBytes = channels * bufferSize * 4;
- device.intermediaryBuffer = Module._malloc(device.intermediaryBufferSizeInBytes);
- device.intermediaryBufferView = new Float32Array(Module.HEAPF32.buffer, device.intermediaryBuffer, device.intermediaryBufferSizeInBytes);
+static void ma_audio_worklet_processor_created__webaudio(EMSCRIPTEN_WEBAUDIO_T audioContext, EM_BOOL success, void* pUserData)
+{
+ ma_audio_worklet_thread_initialized_data* pParameters = (ma_audio_worklet_thread_initialized_data*)pUserData;
+ EmscriptenAudioWorkletNodeCreateOptions audioWorkletOptions;
+ int channels = 0;
+ size_t intermediaryBufferSizeInFrames;
+ int sampleRate;
- /*
- Both playback and capture devices use a ScriptProcessorNode for performing per-sample operations.
-
- ScriptProcessorNode is actually deprecated so this is likely to be temporary. The way this works for playback is very simple. You just set a callback
- that's periodically fired, just like a normal audio callback function. But apparently this design is "flawed" and is now deprecated in favour of
- something called AudioWorklets which _forces_ you to load a _separate_ .js file at run time... nice... Hopefully ScriptProcessorNode will continue to
- work for years to come, but this may need to change to use AudioSourceBufferNode instead, which I think is what Emscripten uses for it's built-in SDL
- implementation. I'll be avoiding that insane AudioWorklet API like the plague...
-
- For capture it is a bit unintuitive. We use the ScriptProccessorNode _only_ to get the raw PCM data. It is connected to an AudioContext just like the
- playback case, however we just output silence to the AudioContext instead of passing any real data. It would make more sense to me to use the
- MediaRecorder API, but unfortunately you need to specify a MIME time (Opus, Vorbis, etc.) for the binary blob that's returned to the client, but I've
- been unable to figure out how to get this as raw PCM. The closest I can think is to use the MIME type for WAV files and just parse it, but I don't know
- how well this would work. Although ScriptProccessorNode is deprecated, in practice it seems to have pretty good browser support so I'm leaving it like
- this for now. If anyone knows how I could get raw PCM data using the MediaRecorder API please let me know!
- */
- device.scriptNode = device.webaudio.createScriptProcessor(bufferSize, (isCapture) ? channels : 0, (isCapture) ? 0 : channels);
+ if (success == EM_FALSE) {
+ pParameters->pDevice->webaudio.initResult = MA_ERROR;
+ ma_free(pParameters, &pParameters->pDevice->pContext->allocationCallbacks);
+ return;
+ }
- if (isCapture) {
- device.scriptNode.onaudioprocess = function(e) {
- if (device.intermediaryBuffer === undefined) {
- return; /* This means the device has been uninitialized. */
- }
+ /* The next step is to initialize the audio worklet node. */
+ MA_ZERO_OBJECT(&audioWorkletOptions);
- if (device.intermediaryBufferView.length == 0) {
- /* Recreate intermediaryBufferView when losing reference to the underlying buffer, probably due to emscripten resizing heap. */
- device.intermediaryBufferView = new Float32Array(Module.HEAPF32.buffer, device.intermediaryBuffer, device.intermediaryBufferSizeInBytes);
- }
+ /*
+ The way channel counts work with Web Audio is confusing. As far as I can tell, there's no way to know the channel
+ count from MediaStreamAudioSourceNode (what we use for capture)? The only way to have control is to configure an
+ output channel count on the capture side. This is slightly confusing for capture mode because intuitively you
+ wouldn't actually connect an output to an input-only node, but this is what we'll have to do in order to have
+ proper control over the channel count. In the capture case, we'll have to output silence to it's output node.
+ */
+ if (pParameters->pConfig->deviceType == ma_device_type_capture) {
+ channels = (int)((pParameters->pDescriptorCapture->channels > 0) ? pParameters->pDescriptorCapture->channels : MA_DEFAULT_CHANNELS);
+ audioWorkletOptions.numberOfInputs = 1;
+ } else {
+ channels = (int)((pParameters->pDescriptorPlayback->channels > 0) ? pParameters->pDescriptorPlayback->channels : MA_DEFAULT_CHANNELS);
- /* Make sure silence it output to the AudioContext destination. Not doing this will cause sound to come out of the speakers! */
- for (var iChannel = 0; iChannel < e.outputBuffer.numberOfChannels; ++iChannel) {
- e.outputBuffer.getChannelData(iChannel).fill(0.0);
- }
+ if (pParameters->pConfig->deviceType == ma_device_type_duplex) {
+ audioWorkletOptions.numberOfInputs = 1;
+ } else {
+ audioWorkletOptions.numberOfInputs = 0;
+ }
+ }
- /* There are some situations where we may want to send silence to the client. */
- var sendSilence = false;
- if (device.streamNode === undefined) {
- sendSilence = true;
- }
+ audioWorkletOptions.numberOfOutputs = 1;
+ audioWorkletOptions.outputChannelCounts = &channels;
- /* Sanity check. This will never happen, right? */
- if (e.inputBuffer.numberOfChannels != channels) {
- console.log("Capture: Channel count mismatch. " + e.inputBufer.numberOfChannels + " != " + channels + ". Sending silence.");
- sendSilence = true;
- }
- /* This looped design guards against the situation where e.inputBuffer is a different size to the original buffer size. Should never happen in practice. */
- var totalFramesProcessed = 0;
- while (totalFramesProcessed < e.inputBuffer.length) {
- var framesRemaining = e.inputBuffer.length - totalFramesProcessed;
- var framesToProcess = framesRemaining;
- if (framesToProcess > (device.intermediaryBufferSizeInBytes/channels/4)) {
- framesToProcess = (device.intermediaryBufferSizeInBytes/channels/4);
- }
+ /*
+ Now that we know the channel count to use we can allocate the intermediary buffer. The
+ intermediary buffer is used for interleaving and deinterleaving.
+ */
+ intermediaryBufferSizeInFrames = 128;
- /* We need to do the reverse of the playback case. We need to interleave the input data and copy it into the intermediary buffer. Then we send it to the client. */
- if (sendSilence) {
- device.intermediaryBufferView.fill(0.0);
- } else {
- for (var iFrame = 0; iFrame < framesToProcess; ++iFrame) {
- for (var iChannel = 0; iChannel < e.inputBuffer.numberOfChannels; ++iChannel) {
- device.intermediaryBufferView[iFrame*channels + iChannel] = e.inputBuffer.getChannelData(iChannel)[totalFramesProcessed + iFrame];
- }
- }
- }
+ pParameters->pDevice->webaudio.pIntermediaryBuffer = (float*)ma_malloc(intermediaryBufferSizeInFrames * (ma_uint32)channels * sizeof(float), &pParameters->pDevice->pContext->allocationCallbacks);
+ if (pParameters->pDevice->webaudio.pIntermediaryBuffer == NULL) {
+ pParameters->pDevice->webaudio.initResult = MA_OUT_OF_MEMORY;
+ ma_free(pParameters, &pParameters->pDevice->pContext->allocationCallbacks);
+ return;
+ }
- /* Send data to the client from our intermediary buffer. */
- ccall("ma_device_process_pcm_frames_capture__webaudio", "undefined", ["number", "number", "number"], [pDevice, framesToProcess, device.intermediaryBuffer]);
- totalFramesProcessed += framesToProcess;
- }
- };
+ pParameters->pDevice->webaudio.audioWorklet = emscripten_create_wasm_audio_worklet_node(audioContext, "miniaudio", &audioWorkletOptions, &ma_audio_worklet_process_callback__webaudio, pParameters->pDevice);
+
+ /* With the audio worklet initialized we can now attach it to the graph. */
+ if (pParameters->pConfig->deviceType == ma_device_type_capture || pParameters->pConfig->deviceType == ma_device_type_duplex) {
+ ma_result attachmentResult = (ma_result)EM_ASM_INT({
+ var getUserMediaResult = 0;
+ var audioWorklet = emscriptenGetAudioObject($0);
+ var audioContext = emscriptenGetAudioObject($1);
navigator.mediaDevices.getUserMedia({audio:true, video:false})
.then(function(stream) {
- device.streamNode = device.webaudio.createMediaStreamSource(stream);
- device.streamNode.connect(device.scriptNode);
- device.scriptNode.connect(device.webaudio.destination);
+ audioContext.streamNode = audioContext.createMediaStreamSource(stream);
+ audioContext.streamNode.connect(audioWorklet);
+ audioWorklet.connect(audioContext.destination);
+ getUserMediaResult = 0; /* 0 = MA_SUCCESS */
})
.catch(function(error) {
- /* I think this should output silence... */
- device.scriptNode.connect(device.webaudio.destination);
+ console.log("navigator.mediaDevices.getUserMedia Failed: " + error);
+ getUserMediaResult = -1; /* -1 = MA_ERROR */
});
- } else {
- device.scriptNode.onaudioprocess = function(e) {
- if (device.intermediaryBuffer === undefined) {
- return; /* This means the device has been uninitialized. */
- }
- if(device.intermediaryBufferView.length == 0) {
- /* Recreate intermediaryBufferView when losing reference to the underlying buffer, probably due to emscripten resizing heap. */
- device.intermediaryBufferView = new Float32Array(Module.HEAPF32.buffer, device.intermediaryBuffer, device.intermediaryBufferSizeInBytes);
- }
+ return getUserMediaResult;
+ }, pParameters->pDevice->webaudio.audioWorklet, audioContext);
- var outputSilence = false;
+ if (attachmentResult != MA_SUCCESS) {
+ ma_log_postf(ma_device_get_log(pParameters->pDevice), MA_LOG_LEVEL_ERROR, "Web Audio: Failed to connect capture node.");
+ emscripten_destroy_web_audio_node(pParameters->pDevice->webaudio.audioWorklet);
+ pParameters->pDevice->webaudio.initResult = attachmentResult;
+ ma_free(pParameters, &pParameters->pDevice->pContext->allocationCallbacks);
+ return;
+ }
+ }
- /* Sanity check. This will never happen, right? */
- if (e.outputBuffer.numberOfChannels != channels) {
- console.log("Playback: Channel count mismatch. " + e.outputBufer.numberOfChannels + " != " + channels + ". Outputting silence.");
- outputSilence = true;
- return;
- }
+ /* If it's playback only we can now attach the worklet node to the graph. This has already been done for the duplex case. */
+ if (pParameters->pConfig->deviceType == ma_device_type_playback) {
+ ma_result attachmentResult = (ma_result)EM_ASM_INT({
+ var audioWorklet = emscriptenGetAudioObject($0);
+ var audioContext = emscriptenGetAudioObject($1);
+ audioWorklet.connect(audioContext.destination);
+ return 0; /* 0 = MA_SUCCESS */
+ }, pParameters->pDevice->webaudio.audioWorklet, audioContext);
- /* This looped design guards against the situation where e.outputBuffer is a different size to the original buffer size. Should never happen in practice. */
- var totalFramesProcessed = 0;
- while (totalFramesProcessed < e.outputBuffer.length) {
- var framesRemaining = e.outputBuffer.length - totalFramesProcessed;
- var framesToProcess = framesRemaining;
- if (framesToProcess > (device.intermediaryBufferSizeInBytes/channels/4)) {
- framesToProcess = (device.intermediaryBufferSizeInBytes/channels/4);
- }
+ if (attachmentResult != MA_SUCCESS) {
+ ma_log_postf(ma_device_get_log(pParameters->pDevice), MA_LOG_LEVEL_ERROR, "Web Audio: Failed to connect playback node.");
+ pParameters->pDevice->webaudio.initResult = attachmentResult;
+ ma_free(pParameters, &pParameters->pDevice->pContext->allocationCallbacks);
+ return;
+ }
+ }
- /* Read data from the client into our intermediary buffer. */
- ccall("ma_device_process_pcm_frames_playback__webaudio", "undefined", ["number", "number", "number"], [pDevice, framesToProcess, device.intermediaryBuffer]);
+ /* We need to update the descriptors so that they reflect the internal data format. Both capture and playback should be the same. */
+ sampleRate = EM_ASM_INT({ return emscriptenGetAudioObject($0).sampleRate; }, audioContext);
- /* At this point we'll have data in our intermediary buffer which we now need to deinterleave and copy over to the output buffers. */
- if (outputSilence) {
- for (var iChannel = 0; iChannel < e.outputBuffer.numberOfChannels; ++iChannel) {
- e.outputBuffer.getChannelData(iChannel).fill(0.0);
- }
- } else {
- for (var iChannel = 0; iChannel < e.outputBuffer.numberOfChannels; ++iChannel) {
- var outputBuffer = e.outputBuffer.getChannelData(iChannel);
- var intermediaryBuffer = device.intermediaryBufferView;
- for (var iFrame = 0; iFrame < framesToProcess; ++iFrame) {
- outputBuffer[totalFramesProcessed + iFrame] = intermediaryBuffer[iFrame*channels + iChannel];
- }
- }
- }
+ if (pParameters->pDescriptorCapture != NULL) {
+ pParameters->pDescriptorCapture->format = ma_format_f32;
+ pParameters->pDescriptorCapture->channels = (ma_uint32)channels;
+ pParameters->pDescriptorCapture->sampleRate = (ma_uint32)sampleRate;
+ ma_channel_map_init_standard(ma_standard_channel_map_webaudio, pParameters->pDescriptorCapture->channelMap, ma_countof(pParameters->pDescriptorCapture->channelMap), pParameters->pDescriptorCapture->channels);
+ pParameters->pDescriptorCapture->periodSizeInFrames = intermediaryBufferSizeInFrames;
+ pParameters->pDescriptorCapture->periodCount = 1;
+ }
- totalFramesProcessed += framesToProcess;
- }
- };
+ if (pParameters->pDescriptorPlayback != NULL) {
+ pParameters->pDescriptorPlayback->format = ma_format_f32;
+ pParameters->pDescriptorPlayback->channels = (ma_uint32)channels;
+ pParameters->pDescriptorPlayback->sampleRate = (ma_uint32)sampleRate;
+ ma_channel_map_init_standard(ma_standard_channel_map_webaudio, pParameters->pDescriptorPlayback->channelMap, ma_countof(pParameters->pDescriptorPlayback->channelMap), pParameters->pDescriptorPlayback->channels);
+ pParameters->pDescriptorPlayback->periodSizeInFrames = intermediaryBufferSizeInFrames;
+ pParameters->pDescriptorPlayback->periodCount = 1;
+ }
- device.scriptNode.connect(device.webaudio.destination);
- }
+ /* At this point we're done and we can return. */
+ ma_log_postf(ma_device_get_log(pParameters->pDevice), MA_LOG_LEVEL_DEBUG, "AudioWorklets: Created worklet node: %d\n", pParameters->pDevice->webaudio.audioWorklet);
+ pParameters->pDevice->webaudio.initResult = MA_SUCCESS;
+ ma_free(pParameters, &pParameters->pDevice->pContext->allocationCallbacks);
+}
- return miniaudio.track_device(device);
- }, channels, sampleRate, periodSizeInFrames, deviceType == ma_device_type_capture, pDevice);
+static void ma_audio_worklet_thread_initialized__webaudio(EMSCRIPTEN_WEBAUDIO_T audioContext, EM_BOOL success, void* pUserData)
+{
+ ma_audio_worklet_thread_initialized_data* pParameters = (ma_audio_worklet_thread_initialized_data*)pUserData;
+ WebAudioWorkletProcessorCreateOptions workletProcessorOptions;
- if (deviceIndex < 0) {
- return MA_FAILED_TO_OPEN_BACKEND_DEVICE;
- }
+ MA_ASSERT(pParameters != NULL);
- if (deviceType == ma_device_type_capture) {
- pDevice->webaudio.indexCapture = deviceIndex;
- } else {
- pDevice->webaudio.indexPlayback = deviceIndex;
+ if (success == EM_FALSE) {
+ pParameters->pDevice->webaudio.initResult = MA_ERROR;
+ return;
}
- pDescriptor->format = ma_format_f32;
- pDescriptor->channels = channels;
- ma_channel_map_init_standard(ma_standard_channel_map_webaudio, pDescriptor->channelMap, ma_countof(pDescriptor->channelMap), pDescriptor->channels);
- pDescriptor->sampleRate = EM_ASM_INT({ return miniaudio.get_device_by_index($0).webaudio.sampleRate; }, deviceIndex);
- pDescriptor->periodSizeInFrames = periodSizeInFrames;
- pDescriptor->periodCount = 1;
+ MA_ZERO_OBJECT(&workletProcessorOptions);
+ workletProcessorOptions.name = "miniaudio"; /* I'm not entirely sure what to call this. Does this need to be globally unique, or does it need only be unique for a given AudioContext? */
- return MA_SUCCESS;
+ emscripten_create_wasm_audio_worklet_processor_async(audioContext, &workletProcessorOptions, ma_audio_worklet_processor_created__webaudio, pParameters);
}
+#endif
static ma_result ma_device_init__webaudio(ma_device* pDevice, const ma_device_config* pConfig, ma_device_descriptor* pDescriptorPlayback, ma_device_descriptor* pDescriptorCapture)
{
- ma_result result;
-
if (pConfig->deviceType == ma_device_type_loopback) {
return MA_DEVICE_TYPE_NOT_SUPPORTED;
}
@@ -38844,45 +40090,271 @@ static ma_result ma_device_init__webaudio(ma_device* pDevice, const ma_device_co
return MA_SHARE_MODE_NOT_SUPPORTED;
}
- if (pConfig->deviceType == ma_device_type_capture || pConfig->deviceType == ma_device_type_duplex) {
- result = ma_device_init_by_type__webaudio(pDevice, pConfig, pDescriptorCapture, ma_device_type_capture);
- if (result != MA_SUCCESS) {
- return result;
+ /*
+ With AudioWorklets we'll have just a single AudioContext. I'm not sure why I'm not doing this for ScriptProcessorNode so
+ it might be worthwhile to look into that as well.
+ */
+ #if defined(MA_USE_AUDIO_WORKLETS)
+ {
+ EmscriptenWebAudioCreateAttributes audioContextAttributes;
+ ma_audio_worklet_thread_initialized_data* pInitParameters;
+ void* pStackBuffer;
+
+ if (pConfig->performanceProfile == ma_performance_profile_conservative) {
+ audioContextAttributes.latencyHint = MA_WEBAUDIO_LATENCY_HINT_PLAYBACK;
+ } else {
+ audioContextAttributes.latencyHint = MA_WEBAUDIO_LATENCY_HINT_INTERACTIVE;
}
+
+ /*
+ In my testing, Firefox does not seem to capture audio data properly if the sample rate is set
+ to anything other than 48K. This does not seem to be the case for other browsers. For this reason,
+ if the device type is anything other than playback, we'll leave the sample rate as-is and let the
+ browser pick the appropriate rate for us.
+ */
+ if (pConfig->deviceType == ma_device_type_playback) {
+ audioContextAttributes.sampleRate = pDescriptorPlayback->sampleRate;
+ } else {
+ audioContextAttributes.sampleRate = 0;
+ }
+
+ /* It's not clear if this can return an error. None of the tests in the Emscripten repository check for this, so neither am I for now. */
+ pDevice->webaudio.audioContext = emscripten_create_audio_context(&audioContextAttributes);
+
+
+ /*
+ With the context created we can now create the worklet. We can only have a single worklet per audio
+ context which means we'll need to craft this appropriately to handle duplex devices correctly.
+ */
+
+ /*
+ We now need to create a worker thread. This is a bit weird because we need to allocate our
+ own buffer for the thread's stack. The stack needs to be aligned to 16 bytes. I'm going to
+ allocate this on the heap to keep it simple.
+ */
+ pStackBuffer = ma_aligned_malloc(MA_AUDIO_WORKLETS_THREAD_STACK_SIZE, 16, &pDevice->pContext->allocationCallbacks);
+ if (pStackBuffer == NULL) {
+ emscripten_destroy_audio_context(pDevice->webaudio.audioContext);
+ return MA_OUT_OF_MEMORY;
+ }
+
+ /* Our thread initialization parameters need to be allocated on the heap so they don't go out of scope. */
+ pInitParameters = (ma_audio_worklet_thread_initialized_data*)ma_malloc(sizeof(*pInitParameters), &pDevice->pContext->allocationCallbacks);
+ if (pInitParameters == NULL) {
+ ma_free(pStackBuffer, &pDevice->pContext->allocationCallbacks);
+ emscripten_destroy_audio_context(pDevice->webaudio.audioContext);
+ return MA_OUT_OF_MEMORY;
+ }
+
+ pInitParameters->pDevice = pDevice;
+ pInitParameters->pConfig = pConfig;
+ pInitParameters->pDescriptorPlayback = pDescriptorPlayback;
+ pInitParameters->pDescriptorCapture = pDescriptorCapture;
+
+ /*
+ We need to flag the device as not yet initialized so we can wait on it later. Unfortunately all of
+ the Emscripten WebAudio stuff is asynchronous.
+ */
+ pDevice->webaudio.initResult = MA_BUSY;
+ {
+ emscripten_start_wasm_audio_worklet_thread_async(pDevice->webaudio.audioContext, pStackBuffer, MA_AUDIO_WORKLETS_THREAD_STACK_SIZE, ma_audio_worklet_thread_initialized__webaudio, pInitParameters);
+ }
+ while (pDevice->webaudio.initResult == MA_BUSY) { emscripten_sleep(1); } /* We must wait for initialization to complete. We're just spinning here. The emscripten_sleep() call is why we need to build with `-sASYNCIFY`. */
+
+ /* Initialization is now complete. Descriptors were updated when the worklet was initialized. */
+ if (pDevice->webaudio.initResult != MA_SUCCESS) {
+ ma_free(pStackBuffer, &pDevice->pContext->allocationCallbacks);
+ emscripten_destroy_audio_context(pDevice->webaudio.audioContext);
+ return pDevice->webaudio.initResult;
+ }
+
+ /* We need to add an entry to the miniaudio.devices list on the JS side so we can do some JS/C interop. */
+ pDevice->webaudio.deviceIndex = EM_ASM_INT({
+ return miniaudio.track_device({
+ webaudio: emscriptenGetAudioObject($0),
+ state: 1 /* 1 = ma_device_state_stopped */
+ });
+ }, pDevice->webaudio.audioContext);
+
+ return MA_SUCCESS;
}
+ #else
+ {
+ /* ScriptProcessorNode. This path requires us to do almost everything in JS, but we'll do as much as we can in C. */
+ ma_uint32 deviceIndex;
+ ma_uint32 channels;
+ ma_uint32 sampleRate;
+ ma_uint32 periodSizeInFrames;
- if (pConfig->deviceType == ma_device_type_playback || pConfig->deviceType == ma_device_type_duplex) {
- result = ma_device_init_by_type__webaudio(pDevice, pConfig, pDescriptorPlayback, ma_device_type_playback);
- if (result != MA_SUCCESS) {
- if (pConfig->deviceType == ma_device_type_duplex) {
- ma_device_uninit_by_index__webaudio(pDevice, ma_device_type_capture, pDevice->webaudio.indexCapture);
+ /* The channel count will depend on the device type. If it's a capture, use it's, otherwise use the playback side. */
+ if (pConfig->deviceType == ma_device_type_capture) {
+ channels = (pDescriptorCapture->channels > 0) ? pDescriptorCapture->channels : MA_DEFAULT_CHANNELS;
+ } else {
+ channels = (pDescriptorPlayback->channels > 0) ? pDescriptorPlayback->channels : MA_DEFAULT_CHANNELS;
+ }
+
+ /*
+ When testing in Firefox, I've seen it where capture mode fails if the sample rate is changed to anything other than it's
+ native rate. For this reason we're leaving the sample rate untouched for capture devices.
+ */
+ if (pConfig->deviceType == ma_device_type_playback) {
+ sampleRate = pDescriptorPlayback->sampleRate;
+ } else {
+ sampleRate = 0; /* Let the browser decide when capturing. */
+ }
+
+ /* The period size needs to be a power of 2. */
+ if (pConfig->deviceType == ma_device_type_capture) {
+ periodSizeInFrames = ma_calculate_period_size_in_frames_from_descriptor__webaudio(pDescriptorCapture, sampleRate, pConfig->performanceProfile);
+ } else {
+ periodSizeInFrames = ma_calculate_period_size_in_frames_from_descriptor__webaudio(pDescriptorPlayback, sampleRate, pConfig->performanceProfile);
+ }
+
+ /* We need an intermediary buffer for doing interleaving and deinterleaving. */
+ pDevice->webaudio.pIntermediaryBuffer = (float*)ma_malloc(periodSizeInFrames * channels * sizeof(float), &pDevice->pContext->allocationCallbacks);
+ if (pDevice->webaudio.pIntermediaryBuffer == NULL) {
+ return MA_OUT_OF_MEMORY;
+ }
+
+ deviceIndex = EM_ASM_INT({
+ var deviceType = $0;
+ var channels = $1;
+ var sampleRate = $2;
+ var bufferSize = $3;
+ var pIntermediaryBuffer = $4;
+ var pDevice = $5;
+
+ if (typeof(window.miniaudio) === 'undefined') {
+ return -1; /* Context not initialized. */
}
- return result;
+
+ var device = {};
+
+ /* First thing we need is an AudioContext. */
+ var audioContextOptions = {};
+ if (deviceType == window.miniaudio.device_type.playback && sampleRate != 0) {
+ audioContextOptions.sampleRate = sampleRate;
+ }
+
+ device.webaudio = new (window.AudioContext || window.webkitAudioContext)(audioContextOptions);
+ device.webaudio.suspend(); /* The AudioContext must be created in a suspended state. */
+ device.state = window.miniaudio.device_state.stopped;
+
+ /*
+ We need to create a ScriptProcessorNode. The channel situation is the same as the AudioWorklet path in that we
+ need to specify an output and configure the channel count there.
+ */
+ var channelCountIn = 0;
+ var channelCountOut = channels;
+ if (deviceType != window.miniaudio.device_type.playback) {
+ channelCountIn = channels;
+ }
+
+ device.scriptNode = device.webaudio.createScriptProcessor(bufferSize, channelCountIn, channelCountOut);
+
+ /* The node processing callback. */
+ device.scriptNode.onaudioprocess = function(e) {
+ if (device.intermediaryBufferView == null || device.intermediaryBufferView.length == 0) {
+ device.intermediaryBufferView = new Float32Array(Module.HEAPF32.buffer, pIntermediaryBuffer, bufferSize * channels);
+ }
+
+ /* Do the capture side first. */
+ if (deviceType == miniaudio.device_type.capture || deviceType == miniaudio.device_type.duplex) {
+ /* The data must be interleaved before being processed miniaudio. */
+ for (var iChannel = 0; iChannel < channels; iChannel += 1) {
+ var inputBuffer = e.inputBuffer.getChannelData(iChannel);
+ var intermediaryBuffer = device.intermediaryBufferView;
+
+ for (var iFrame = 0; iFrame < bufferSize; iFrame += 1) {
+ intermediaryBuffer[iFrame*channels + iChannel] = inputBuffer[iFrame];
+ }
+ }
+
+ _ma_device_process_pcm_frames_capture__webaudio(pDevice, bufferSize, pIntermediaryBuffer);
+ }
+
+ if (deviceType == miniaudio.device_type.playback || deviceType == miniaudio.device_type.duplex) {
+ _ma_device_process_pcm_frames_playback__webaudio(pDevice, bufferSize, pIntermediaryBuffer);
+
+ for (var iChannel = 0; iChannel < e.outputBuffer.numberOfChannels; ++iChannel) {
+ var outputBuffer = e.outputBuffer.getChannelData(iChannel);
+ var intermediaryBuffer = device.intermediaryBufferView;
+
+ for (var iFrame = 0; iFrame < bufferSize; iFrame += 1) {
+ outputBuffer[iFrame] = intermediaryBuffer[iFrame*channels + iChannel];
+ }
+ }
+ } else {
+ /* It's a capture-only device. Make sure the output is silenced. */
+ for (var iChannel = 0; iChannel < e.outputBuffer.numberOfChannels; ++iChannel) {
+ e.outputBuffer.getChannelData(iChannel).fill(0.0);
+ }
+ }
+ };
+
+ /* Now we need to connect our node to the graph. */
+ if (deviceType == miniaudio.device_type.capture || deviceType == miniaudio.device_type.duplex) {
+ navigator.mediaDevices.getUserMedia({audio:true, video:false})
+ .then(function(stream) {
+ device.streamNode = device.webaudio.createMediaStreamSource(stream);
+ device.streamNode.connect(device.scriptNode);
+ device.scriptNode.connect(device.webaudio.destination);
+ })
+ .catch(function(error) {
+ console.log("Failed to get user media: " + error);
+ });
+ }
+
+ if (deviceType == miniaudio.device_type.playback) {
+ device.scriptNode.connect(device.webaudio.destination);
+ }
+
+ device.pDevice = pDevice;
+
+ return miniaudio.track_device(device);
+ }, pConfig->deviceType, channels, sampleRate, periodSizeInFrames, pDevice->webaudio.pIntermediaryBuffer, pDevice);
+
+ if (deviceIndex < 0) {
+ return MA_FAILED_TO_OPEN_BACKEND_DEVICE;
}
- }
- return MA_SUCCESS;
+ pDevice->webaudio.deviceIndex = deviceIndex;
+
+ /* Grab the sample rate from the audio context directly. */
+ sampleRate = (ma_uint32)EM_ASM_INT({ return miniaudio.get_device_by_index($0).webaudio.sampleRate; }, deviceIndex);
+
+ if (pDescriptorCapture != NULL) {
+ pDescriptorCapture->format = ma_format_f32;
+ pDescriptorCapture->channels = channels;
+ pDescriptorCapture->sampleRate = sampleRate;
+ ma_channel_map_init_standard(ma_standard_channel_map_webaudio, pDescriptorCapture->channelMap, ma_countof(pDescriptorCapture->channelMap), pDescriptorCapture->channels);
+ pDescriptorCapture->periodSizeInFrames = periodSizeInFrames;
+ pDescriptorCapture->periodCount = 1;
+ }
+
+ if (pDescriptorPlayback != NULL) {
+ pDescriptorPlayback->format = ma_format_f32;
+ pDescriptorPlayback->channels = channels;
+ pDescriptorPlayback->sampleRate = sampleRate;
+ ma_channel_map_init_standard(ma_standard_channel_map_webaudio, pDescriptorPlayback->channelMap, ma_countof(pDescriptorPlayback->channelMap), pDescriptorPlayback->channels);
+ pDescriptorPlayback->periodSizeInFrames = periodSizeInFrames;
+ pDescriptorPlayback->periodCount = 1;
+ }
+
+ return MA_SUCCESS;
+ }
+ #endif
}
static ma_result ma_device_start__webaudio(ma_device* pDevice)
{
MA_ASSERT(pDevice != NULL);
- if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) {
- EM_ASM({
- var device = miniaudio.get_device_by_index($0);
- device.webaudio.resume();
- device.state = 2; /* ma_device_state_started */
- }, pDevice->webaudio.indexCapture);
- }
-
- if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) {
- EM_ASM({
- var device = miniaudio.get_device_by_index($0);
- device.webaudio.resume();
- device.state = 2; /* ma_device_state_started */
- }, pDevice->webaudio.indexPlayback);
- }
+ EM_ASM({
+ var device = miniaudio.get_device_by_index($0);
+ device.webaudio.resume();
+ device.state = miniaudio.device_state.started;
+ }, pDevice->webaudio.deviceIndex);
return MA_SUCCESS;
}
@@ -38900,22 +40372,11 @@ static ma_result ma_device_stop__webaudio(ma_device* pDevice)
I read this to mean that "any current context processing blocks" are processed by suspend() - i.e. They they are drained. We therefore shouldn't need to
do any kind of explicit draining.
*/
-
- if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) {
- EM_ASM({
- var device = miniaudio.get_device_by_index($0);
- device.webaudio.suspend();
- device.state = 1; /* ma_device_state_stopped */
- }, pDevice->webaudio.indexCapture);
- }
-
- if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) {
- EM_ASM({
- var device = miniaudio.get_device_by_index($0);
- device.webaudio.suspend();
- device.state = 1; /* ma_device_state_stopped */
- }, pDevice->webaudio.indexPlayback);
- }
+ EM_ASM({
+ var device = miniaudio.get_device_by_index($0);
+ device.webaudio.suspend();
+ device.state = miniaudio.device_state.stopped;
+ }, pDevice->webaudio.deviceIndex);
ma_device__on_notification_stopped(pDevice);
@@ -38932,7 +40393,7 @@ static ma_result ma_context_uninit__webaudio(ma_context* pContext)
/* Remove the global miniaudio object from window if there are no more references to it. */
EM_ASM({
if (typeof(window.miniaudio) !== 'undefined') {
- window.miniaudio.referenceCount--;
+ window.miniaudio.referenceCount -= 1;
if (window.miniaudio.referenceCount === 0) {
delete window.miniaudio;
}
@@ -38960,7 +40421,20 @@ static ma_result ma_context_init__webaudio(ma_context* pContext, const ma_contex
window.miniaudio = {
referenceCount: 0
};
- miniaudio.devices = []; /* Device cache for mapping devices to indexes for JavaScript/C interop. */
+
+ /* Device types. */
+ window.miniaudio.device_type = {};
+ window.miniaudio.device_type.playback = $0;
+ window.miniaudio.device_type.capture = $1;
+ window.miniaudio.device_type.duplex = $2;
+
+ /* Device states. */
+ window.miniaudio.device_state = {};
+ window.miniaudio.device_state.stopped = $3;
+ window.miniaudio.device_state.started = $4;
+
+ /* Device cache for mapping devices to indexes for JavaScript/C interop. */
+ miniaudio.devices = [];
miniaudio.track_device = function(device) {
/* Try inserting into a free slot first. */
@@ -39003,14 +40477,21 @@ static ma_result ma_context_init__webaudio(ma_context* pContext, const ma_contex
};
miniaudio.unlock_event_types = (function(){
- return ['touchstart', 'touchend', 'click'];
+ return ['touchend', 'click'];
})();
miniaudio.unlock = function() {
for(var i = 0; i < miniaudio.devices.length; ++i) {
var device = miniaudio.devices[i];
- if (device != null && device.webaudio != null && device.state === 2 /* ma_device_state_started */) {
- device.webaudio.resume();
+ if (device != null &&
+ device.webaudio != null &&
+ device.state === window.miniaudio.device_state.started) {
+
+ device.webaudio.resume().then(() => {
+ Module._ma_device__on_notification_unlocked(device.pDevice);
+ },
+ (error) => {console.error("Failed to resume audiocontext", error);
+ });
}
}
miniaudio.unlock_event_types.map(function(event_type) {
@@ -39023,10 +40504,10 @@ static ma_result ma_context_init__webaudio(ma_context* pContext, const ma_contex
});
}
- window.miniaudio.referenceCount++;
+ window.miniaudio.referenceCount += 1;
return 1;
- }, 0); /* Must pass in a dummy argument for C99 compatibility. */
+ }, ma_device_type_playback, ma_device_type_capture, ma_device_type_duplex, ma_device_state_stopped, ma_device_state_started);
if (resultFromJS != 1) {
return MA_FAILED_TO_INIT_BACKEND;
@@ -39075,6 +40556,22 @@ static ma_bool32 ma__is_channel_map_valid(const ma_channel* pChannelMap, ma_uint
}
+static ma_bool32 ma_context_is_backend_asynchronous(ma_context* pContext)
+{
+ MA_ASSERT(pContext != NULL);
+
+ if (pContext->callbacks.onDeviceRead == NULL && pContext->callbacks.onDeviceWrite == NULL) {
+ if (pContext->callbacks.onDeviceDataLoop == NULL) {
+ return MA_TRUE;
+ } else {
+ return MA_FALSE;
+ }
+ } else {
+ return MA_FALSE;
+ }
+}
+
+
static ma_result ma_device__post_init_setup(ma_device* pDevice, ma_device_type deviceType)
{
ma_result result;
@@ -39194,8 +40691,23 @@ static ma_result ma_device__post_init_setup(ma_device* pDevice, ma_device_type d
/*
- In playback mode, if the data converter does not support retrieval of the required number of
- input frames given a number of output frames, we need to fall back to a heap-allocated cache.
+ If the device is doing playback (ma_device_type_playback or ma_device_type_duplex), there's
+ a couple of situations where we'll need a heap allocated cache.
+
+ The first is a duplex device for backends that use a callback for data delivery. The reason
+ this is needed is that the input stage needs to have a buffer to place the input data while it
+ waits for the playback stage, after which the miniaudio data callback will get fired. This is
+ not needed for backends that use a blocking API because miniaudio manages temporary buffers on
+ the stack to achieve this.
+
+ The other situation is when the data converter does not have the ability to query the number
+ of input frames that are required in order to process a given number of output frames. When
+ performing data conversion, it's useful if miniaudio know exactly how many frames it needs
+ from the client in order to generate a given number of output frames. This way, only exactly
+ the number of frames are needed to be read from the client which means no cache is necessary.
+ On the other hand, if miniaudio doesn't know how many frames to read, it is forced to read
+ in fixed sized chunks and then cache any residual unused input frames, those of which will be
+ processed at a later stage.
*/
if (deviceType == ma_device_type_playback || deviceType == ma_device_type_duplex) {
ma_uint64 unused;
@@ -39203,7 +40715,9 @@ static ma_result ma_device__post_init_setup(ma_device* pDevice, ma_device_type d
pDevice->playback.inputCacheConsumed = 0;
pDevice->playback.inputCacheRemaining = 0;
- if (deviceType == ma_device_type_duplex || ma_data_converter_get_required_input_frame_count(&pDevice->playback.converter, 1, &unused) != MA_SUCCESS) {
+ if (pDevice->type == ma_device_type_duplex || /* Duplex. backend may decide to use ma_device_handle_backend_data_callback() which will require this cache. */
+ ma_data_converter_get_required_input_frame_count(&pDevice->playback.converter, 1, &unused) != MA_SUCCESS) /* Data conversion required input frame calculation not supported. */
+ {
/* We need a heap allocated cache. We want to size this based on the period size. */
void* pNewInputCache;
ma_uint64 newInputCacheCap;
@@ -39219,7 +40733,7 @@ static ma_result ma_device__post_init_setup(ma_device* pDevice, ma_device_type d
return MA_OUT_OF_MEMORY; /* Allocation too big. Should never hit this, but makes the cast below safer for 32-bit builds. */
}
- pNewInputCache = ma_realloc(pDevice->playback.pInputCache, (size_t)newInputCacheSizeInBytes, &pDevice->pContext->allocationCallbacks);
+ pNewInputCache = ma_realloc(pDevice->playback.pInputCache, (size_t)newInputCacheSizeInBytes, &pDevice->pContext->allocationCallbacks);
if (pNewInputCache == NULL) {
ma_free(pDevice->playback.pInputCache, &pDevice->pContext->allocationCallbacks);
pDevice->playback.pInputCache = NULL;
@@ -39328,10 +40842,14 @@ MA_API ma_result ma_device_post_init(ma_device* pDevice, ma_device_type deviceTy
static ma_thread_result MA_THREADCALL ma_worker_thread(void* pData)
{
ma_device* pDevice = (ma_device*)pData;
+#ifdef MA_WIN32
+ HRESULT CoInitializeResult;
+#endif
+
MA_ASSERT(pDevice != NULL);
#ifdef MA_WIN32
- ma_CoInitializeEx(pDevice->pContext, NULL, MA_COINIT_VALUE);
+ CoInitializeResult = ma_CoInitializeEx(pDevice->pContext, NULL, MA_COINIT_VALUE);
#endif
/*
@@ -39411,13 +40929,20 @@ static ma_thread_result MA_THREADCALL ma_worker_thread(void* pData)
ma_device__on_notification_stopped(pDevice);
}
+ /* If we stopped because the device has been uninitialized, abort now. */
+ if (ma_device_get_state(pDevice) == ma_device_state_uninitialized) {
+ break;
+ }
+
/* A function somewhere is waiting for the device to have stopped for real so we need to signal an event to allow it to continue. */
ma_device__set_state(pDevice, ma_device_state_stopped);
ma_event_signal(&pDevice->stopEvent);
}
#ifdef MA_WIN32
- ma_CoUninitialize(pDevice->pContext);
+ if (CoInitializeResult == S_OK) {
+ ma_CoUninitialize(pDevice->pContext);
+ }
#endif
return (ma_thread_result)0;
@@ -39439,11 +40964,17 @@ static ma_bool32 ma_device__is_initialized(ma_device* pDevice)
static ma_result ma_context_uninit_backend_apis__win32(ma_context* pContext)
{
/* For some reason UWP complains when CoUninitialize() is called. I'm just not going to call it on UWP. */
-#ifdef MA_WIN32_DESKTOP
- ma_CoUninitialize(pContext);
- ma_dlclose(pContext, pContext->win32.hUser32DLL);
- ma_dlclose(pContext, pContext->win32.hOle32DLL);
- ma_dlclose(pContext, pContext->win32.hAdvapi32DLL);
+#if defined(MA_WIN32_DESKTOP) || defined(MA_WIN32_GDK)
+ if (pContext->win32.CoInitializeResult == S_OK) {
+ ma_CoUninitialize(pContext);
+ }
+
+ #if defined(MA_WIN32_DESKTOP)
+ ma_dlclose(ma_context_get_log(pContext), pContext->win32.hUser32DLL);
+ ma_dlclose(ma_context_get_log(pContext), pContext->win32.hAdvapi32DLL);
+ #endif
+
+ ma_dlclose(ma_context_get_log(pContext), pContext->win32.hOle32DLL);
#else
(void)pContext;
#endif
@@ -39453,115 +40984,60 @@ static ma_result ma_context_uninit_backend_apis__win32(ma_context* pContext)
static ma_result ma_context_init_backend_apis__win32(ma_context* pContext)
{
-#ifdef MA_WIN32_DESKTOP
- /* Ole32.dll */
- pContext->win32.hOle32DLL = ma_dlopen(pContext, "ole32.dll");
- if (pContext->win32.hOle32DLL == NULL) {
- return MA_FAILED_TO_INIT_BACKEND;
- }
-
- pContext->win32.CoInitializeEx = (ma_proc)ma_dlsym(pContext, pContext->win32.hOle32DLL, "CoInitializeEx");
- pContext->win32.CoUninitialize = (ma_proc)ma_dlsym(pContext, pContext->win32.hOle32DLL, "CoUninitialize");
- pContext->win32.CoCreateInstance = (ma_proc)ma_dlsym(pContext, pContext->win32.hOle32DLL, "CoCreateInstance");
- pContext->win32.CoTaskMemFree = (ma_proc)ma_dlsym(pContext, pContext->win32.hOle32DLL, "CoTaskMemFree");
- pContext->win32.PropVariantClear = (ma_proc)ma_dlsym(pContext, pContext->win32.hOle32DLL, "PropVariantClear");
- pContext->win32.StringFromGUID2 = (ma_proc)ma_dlsym(pContext, pContext->win32.hOle32DLL, "StringFromGUID2");
+#if defined(MA_WIN32_DESKTOP) || defined(MA_WIN32_GDK)
+ #if defined(MA_WIN32_DESKTOP)
+ /* User32.dll */
+ pContext->win32.hUser32DLL = ma_dlopen(ma_context_get_log(pContext), "user32.dll");
+ if (pContext->win32.hUser32DLL == NULL) {
+ return MA_FAILED_TO_INIT_BACKEND;
+ }
+ pContext->win32.GetForegroundWindow = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->win32.hUser32DLL, "GetForegroundWindow");
+ pContext->win32.GetDesktopWindow = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->win32.hUser32DLL, "GetDesktopWindow");
- /* User32.dll */
- pContext->win32.hUser32DLL = ma_dlopen(pContext, "user32.dll");
- if (pContext->win32.hUser32DLL == NULL) {
- return MA_FAILED_TO_INIT_BACKEND;
- }
- pContext->win32.GetForegroundWindow = (ma_proc)ma_dlsym(pContext, pContext->win32.hUser32DLL, "GetForegroundWindow");
- pContext->win32.GetDesktopWindow = (ma_proc)ma_dlsym(pContext, pContext->win32.hUser32DLL, "GetDesktopWindow");
+ /* Advapi32.dll */
+ pContext->win32.hAdvapi32DLL = ma_dlopen(ma_context_get_log(pContext), "advapi32.dll");
+ if (pContext->win32.hAdvapi32DLL == NULL) {
+ return MA_FAILED_TO_INIT_BACKEND;
+ }
+ pContext->win32.RegOpenKeyExA = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->win32.hAdvapi32DLL, "RegOpenKeyExA");
+ pContext->win32.RegCloseKey = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->win32.hAdvapi32DLL, "RegCloseKey");
+ pContext->win32.RegQueryValueExA = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->win32.hAdvapi32DLL, "RegQueryValueExA");
+ #endif
- /* Advapi32.dll */
- pContext->win32.hAdvapi32DLL = ma_dlopen(pContext, "advapi32.dll");
- if (pContext->win32.hAdvapi32DLL == NULL) {
+ /* Ole32.dll */
+ pContext->win32.hOle32DLL = ma_dlopen(ma_context_get_log(pContext), "ole32.dll");
+ if (pContext->win32.hOle32DLL == NULL) {
return MA_FAILED_TO_INIT_BACKEND;
}
- pContext->win32.RegOpenKeyExA = (ma_proc)ma_dlsym(pContext, pContext->win32.hAdvapi32DLL, "RegOpenKeyExA");
- pContext->win32.RegCloseKey = (ma_proc)ma_dlsym(pContext, pContext->win32.hAdvapi32DLL, "RegCloseKey");
- pContext->win32.RegQueryValueExA = (ma_proc)ma_dlsym(pContext, pContext->win32.hAdvapi32DLL, "RegQueryValueExA");
+ pContext->win32.CoInitialize = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->win32.hOle32DLL, "CoInitialize");
+ pContext->win32.CoInitializeEx = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->win32.hOle32DLL, "CoInitializeEx");
+ pContext->win32.CoUninitialize = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->win32.hOle32DLL, "CoUninitialize");
+ pContext->win32.CoCreateInstance = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->win32.hOle32DLL, "CoCreateInstance");
+ pContext->win32.CoTaskMemFree = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->win32.hOle32DLL, "CoTaskMemFree");
+ pContext->win32.PropVariantClear = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->win32.hOle32DLL, "PropVariantClear");
+ pContext->win32.StringFromGUID2 = (ma_proc)ma_dlsym(ma_context_get_log(pContext), pContext->win32.hOle32DLL, "StringFromGUID2");
#else
(void)pContext; /* Unused. */
#endif
- ma_CoInitializeEx(pContext, NULL, MA_COINIT_VALUE);
+ pContext->win32.CoInitializeResult = ma_CoInitializeEx(pContext, NULL, MA_COINIT_VALUE);
return MA_SUCCESS;
}
#else
static ma_result ma_context_uninit_backend_apis__nix(ma_context* pContext)
{
-#if defined(MA_USE_RUNTIME_LINKING_FOR_PTHREAD) && !defined(MA_NO_RUNTIME_LINKING)
- ma_dlclose(pContext, pContext->posix.pthreadSO);
-#else
(void)pContext;
-#endif
return MA_SUCCESS;
}
static ma_result ma_context_init_backend_apis__nix(ma_context* pContext)
{
- /* pthread */
-#if defined(MA_USE_RUNTIME_LINKING_FOR_PTHREAD) && !defined(MA_NO_RUNTIME_LINKING)
- const char* libpthreadFileNames[] = {
- "libpthread.so",
- "libpthread.so.0",
- "libpthread.dylib"
- };
- size_t i;
-
- for (i = 0; i < sizeof(libpthreadFileNames) / sizeof(libpthreadFileNames[0]); ++i) {
- pContext->posix.pthreadSO = ma_dlopen(pContext, libpthreadFileNames[i]);
- if (pContext->posix.pthreadSO != NULL) {
- break;
- }
- }
-
- if (pContext->posix.pthreadSO == NULL) {
- return MA_FAILED_TO_INIT_BACKEND;
- }
-
- pContext->posix.pthread_create = (ma_proc)ma_dlsym(pContext, pContext->posix.pthreadSO, "pthread_create");
- pContext->posix.pthread_join = (ma_proc)ma_dlsym(pContext, pContext->posix.pthreadSO, "pthread_join");
- pContext->posix.pthread_mutex_init = (ma_proc)ma_dlsym(pContext, pContext->posix.pthreadSO, "pthread_mutex_init");
- pContext->posix.pthread_mutex_destroy = (ma_proc)ma_dlsym(pContext, pContext->posix.pthreadSO, "pthread_mutex_destroy");
- pContext->posix.pthread_mutex_lock = (ma_proc)ma_dlsym(pContext, pContext->posix.pthreadSO, "pthread_mutex_lock");
- pContext->posix.pthread_mutex_unlock = (ma_proc)ma_dlsym(pContext, pContext->posix.pthreadSO, "pthread_mutex_unlock");
- pContext->posix.pthread_cond_init = (ma_proc)ma_dlsym(pContext, pContext->posix.pthreadSO, "pthread_cond_init");
- pContext->posix.pthread_cond_destroy = (ma_proc)ma_dlsym(pContext, pContext->posix.pthreadSO, "pthread_cond_destroy");
- pContext->posix.pthread_cond_wait = (ma_proc)ma_dlsym(pContext, pContext->posix.pthreadSO, "pthread_cond_wait");
- pContext->posix.pthread_cond_signal = (ma_proc)ma_dlsym(pContext, pContext->posix.pthreadSO, "pthread_cond_signal");
- pContext->posix.pthread_attr_init = (ma_proc)ma_dlsym(pContext, pContext->posix.pthreadSO, "pthread_attr_init");
- pContext->posix.pthread_attr_destroy = (ma_proc)ma_dlsym(pContext, pContext->posix.pthreadSO, "pthread_attr_destroy");
- pContext->posix.pthread_attr_setschedpolicy = (ma_proc)ma_dlsym(pContext, pContext->posix.pthreadSO, "pthread_attr_setschedpolicy");
- pContext->posix.pthread_attr_getschedparam = (ma_proc)ma_dlsym(pContext, pContext->posix.pthreadSO, "pthread_attr_getschedparam");
- pContext->posix.pthread_attr_setschedparam = (ma_proc)ma_dlsym(pContext, pContext->posix.pthreadSO, "pthread_attr_setschedparam");
-#else
- pContext->posix.pthread_create = (ma_proc)pthread_create;
- pContext->posix.pthread_join = (ma_proc)pthread_join;
- pContext->posix.pthread_mutex_init = (ma_proc)pthread_mutex_init;
- pContext->posix.pthread_mutex_destroy = (ma_proc)pthread_mutex_destroy;
- pContext->posix.pthread_mutex_lock = (ma_proc)pthread_mutex_lock;
- pContext->posix.pthread_mutex_unlock = (ma_proc)pthread_mutex_unlock;
- pContext->posix.pthread_cond_init = (ma_proc)pthread_cond_init;
- pContext->posix.pthread_cond_destroy = (ma_proc)pthread_cond_destroy;
- pContext->posix.pthread_cond_wait = (ma_proc)pthread_cond_wait;
- pContext->posix.pthread_cond_signal = (ma_proc)pthread_cond_signal;
- pContext->posix.pthread_attr_init = (ma_proc)pthread_attr_init;
- pContext->posix.pthread_attr_destroy = (ma_proc)pthread_attr_destroy;
-#if !defined(__EMSCRIPTEN__)
- pContext->posix.pthread_attr_setschedpolicy = (ma_proc)pthread_attr_setschedpolicy;
- pContext->posix.pthread_attr_getschedparam = (ma_proc)pthread_attr_getschedparam;
- pContext->posix.pthread_attr_setschedparam = (ma_proc)pthread_attr_setschedparam;
-#endif
-#endif
+ (void)pContext;
return MA_SUCCESS;
}
@@ -39592,22 +41068,6 @@ static ma_result ma_context_uninit_backend_apis(ma_context* pContext)
}
-static ma_bool32 ma_context_is_backend_asynchronous(ma_context* pContext)
-{
- MA_ASSERT(pContext != NULL);
-
- if (pContext->callbacks.onDeviceRead == NULL && pContext->callbacks.onDeviceWrite == NULL) {
- if (pContext->callbacks.onDeviceDataLoop == NULL) {
- return MA_TRUE;
- } else {
- return MA_FALSE;
- }
- } else {
- return MA_FALSE;
- }
-}
-
-
/* The default capacity doesn't need to be too big. */
#ifndef MA_DEFAULT_DEVICE_JOB_QUEUE_CAPACITY
#define MA_DEFAULT_DEVICE_JOB_QUEUE_CAPACITY 32
@@ -39920,7 +41380,16 @@ MA_API ma_result ma_context_init(const ma_backend backends[], ma_uint32 backendC
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_DEBUG, "Attempting to initialize %s backend...\n", ma_get_backend_name(backend));
result = pContext->callbacks.onContextInit(pContext, pConfig, &pContext->callbacks);
} else {
- result = MA_NO_BACKEND;
+ /* Getting here means the onContextInit callback is not set which means the backend is not enabled. Special case for the custom backend. */
+ if (backend != ma_backend_custom) {
+ result = MA_BACKEND_NOT_ENABLED;
+ } else {
+ #if !defined(MA_HAS_CUSTOM)
+ result = MA_BACKEND_NOT_ENABLED;
+ #else
+ result = MA_NO_BACKEND;
+ #endif
+ }
}
/* If this iteration was successful, return. */
@@ -39944,7 +41413,11 @@ MA_API ma_result ma_context_init(const ma_backend backends[], ma_uint32 backendC
pContext->backend = backend;
return result;
} else {
- ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_DEBUG, "Failed to initialize %s backend.\n", ma_get_backend_name(backend));
+ if (result == MA_BACKEND_NOT_ENABLED) {
+ ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_DEBUG, "%s backend is disabled.\n", ma_get_backend_name(backend));
+ } else {
+ ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_DEBUG, "Failed to initialize %s backend.\n", ma_get_backend_name(backend));
+ }
}
}
@@ -39975,7 +41448,7 @@ MA_API ma_result ma_context_uninit(ma_context* pContext)
return MA_SUCCESS;
}
-MA_API size_t ma_context_sizeof()
+MA_API size_t ma_context_sizeof(void)
{
return sizeof(ma_context);
}
@@ -40240,7 +41713,7 @@ MA_API ma_result ma_device_init(ma_context* pContext, const ma_device_config* pC
pDevice->noClip = pConfig->noClip;
pDevice->noDisableDenormals = pConfig->noDisableDenormals;
pDevice->noFixedSizedCallback = pConfig->noFixedSizedCallback;
- pDevice->masterVolumeFactor = 1;
+ ma_atomic_float_set(&pDevice->masterVolumeFactor, 1);
pDevice->type = pConfig->deviceType;
pDevice->sampleRate = pConfig->sampleRate;
@@ -40426,7 +41899,6 @@ MA_API ma_result ma_device_init(ma_context* pContext, const ma_device_config* pC
}
-
/*
If we're using fixed sized callbacks we'll need to make use of an intermediary buffer. Needs to
be done after post_init_setup() because we'll need access to the sample rate.
@@ -40600,7 +42072,6 @@ MA_API ma_result ma_device_init_ex(const ma_backend backends[], ma_uint32 backen
allocationCallbacks = ma_allocation_callbacks_init_default();
}
-
pContext = (ma_context*)ma_malloc(sizeof(*pContext), &allocationCallbacks);
if (pContext == NULL) {
return MA_OUT_OF_MEMORY;
@@ -40673,10 +42144,23 @@ MA_API void ma_device_uninit(ma_device* pDevice)
return;
}
- /* Make sure the device is stopped first. The backends will probably handle this naturally, but I like to do it explicitly for my own sanity. */
- if (ma_device_is_started(pDevice)) {
- ma_device_stop(pDevice);
+ /*
+ It's possible for the miniaudio side of the device and the backend to not be in sync due to
+ system-level situations such as the computer being put into sleep mode and the backend not
+ notifying miniaudio of the fact the device has stopped. It's possible for this to result in a
+ deadlock due to miniaudio thinking the device is in a running state, when in fact it's not
+ running at all. For this reason I am no longer explicitly stopping the device. I don't think
+ this should affect anyone in practice since uninitializing the backend will naturally stop the
+ device anyway.
+ */
+ #if 0
+ {
+ /* Make sure the device is stopped first. The backends will probably handle this naturally, but I like to do it explicitly for my own sanity. */
+ if (ma_device_is_started(pDevice)) {
+ ma_device_stop(pDevice);
+ }
}
+ #endif
/* Putting the device into an uninitialized state will make the worker thread return. */
ma_device__set_state(pDevice, ma_device_state_uninitialized);
@@ -40948,7 +42432,7 @@ MA_API ma_device_state ma_device_get_state(const ma_device* pDevice)
return ma_device_state_uninitialized;
}
- return (ma_device_state)c89atomic_load_i32((ma_int32*)&pDevice->state); /* Naughty cast to get rid of a const warning. */
+ return ma_atomic_device_state_get((ma_atomic_device_state*)&pDevice->state); /* Naughty cast to get rid of a const warning. */
}
MA_API ma_result ma_device_set_master_volume(ma_device* pDevice, float volume)
@@ -40961,7 +42445,7 @@ MA_API ma_result ma_device_set_master_volume(ma_device* pDevice, float volume)
return MA_INVALID_ARGS;
}
- c89atomic_exchange_f32(&pDevice->masterVolumeFactor, volume);
+ ma_atomic_float_set(&pDevice->masterVolumeFactor, volume);
return MA_SUCCESS;
}
@@ -40977,7 +42461,7 @@ MA_API ma_result ma_device_get_master_volume(ma_device* pDevice, float* pVolume)
return MA_INVALID_ARGS;
}
- *pVolume = c89atomic_load_f32(&pDevice->masterVolumeFactor);
+ *pVolume = ma_atomic_float_get(&pDevice->masterVolumeFactor);
return MA_SUCCESS;
}
@@ -41572,6 +43056,35 @@ MA_API float ma_volume_db_to_linear(float gain)
}
+MA_API ma_result ma_mix_pcm_frames_f32(float* pDst, const float* pSrc, ma_uint64 frameCount, ma_uint32 channels, float volume)
+{
+ ma_uint64 iSample;
+ ma_uint64 sampleCount;
+
+ if (pDst == NULL || pSrc == NULL || channels == 0) {
+ return MA_INVALID_ARGS;
+ }
+
+ if (volume == 0) {
+ return MA_SUCCESS; /* No changes if the volume is 0. */
+ }
+
+ sampleCount = frameCount * channels;
+
+ if (volume == 1) {
+ for (iSample = 0; iSample < sampleCount; iSample += 1) {
+ pDst[iSample] += pSrc[iSample];
+ }
+ } else {
+ for (iSample = 0; iSample < sampleCount; iSample += 1) {
+ pDst[iSample] += ma_apply_volume_unclipped_f32(pSrc[iSample], volume);
+ }
+ }
+
+ return MA_SUCCESS;
+}
+
+
/**************************************************************************************************************************************************************
@@ -41637,12 +43150,6 @@ static MA_INLINE void ma_pcm_u8_to_s16__sse2(void* dst, const void* src, ma_uint
ma_pcm_u8_to_s16__optimized(dst, src, count, ditherMode);
}
#endif
-#if defined(MA_SUPPORT_AVX2)
-static MA_INLINE void ma_pcm_u8_to_s16__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
-{
- ma_pcm_u8_to_s16__optimized(dst, src, count, ditherMode);
-}
-#endif
#if defined(MA_SUPPORT_NEON)
static MA_INLINE void ma_pcm_u8_to_s16__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
{
@@ -41655,15 +43162,11 @@ MA_API void ma_pcm_u8_to_s16(void* dst, const void* src, ma_uint64 count, ma_dit
#ifdef MA_USE_REFERENCE_CONVERSION_APIS
ma_pcm_u8_to_s16__reference(dst, src, count, ditherMode);
#else
- # if MA_PREFERRED_SIMD == MA_SIMD_AVX2
- if (ma_has_avx2()) {
- ma_pcm_u8_to_s16__avx2(dst, src, count, ditherMode);
- } else
- #elif MA_PREFERRED_SIMD == MA_SIMD_SSE2
+ # if defined(MA_SUPPORT_SSE2)
if (ma_has_sse2()) {
ma_pcm_u8_to_s16__sse2(dst, src, count, ditherMode);
} else
- #elif MA_PREFERRED_SIMD == MA_SIMD_NEON
+ #elif defined(MA_SUPPORT_NEON)
if (ma_has_neon()) {
ma_pcm_u8_to_s16__neon(dst, src, count, ditherMode);
} else
@@ -41704,12 +43207,6 @@ static MA_INLINE void ma_pcm_u8_to_s24__sse2(void* dst, const void* src, ma_uint
ma_pcm_u8_to_s24__optimized(dst, src, count, ditherMode);
}
#endif
-#if defined(MA_SUPPORT_AVX2)
-static MA_INLINE void ma_pcm_u8_to_s24__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
-{
- ma_pcm_u8_to_s24__optimized(dst, src, count, ditherMode);
-}
-#endif
#if defined(MA_SUPPORT_NEON)
static MA_INLINE void ma_pcm_u8_to_s24__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
{
@@ -41722,15 +43219,11 @@ MA_API void ma_pcm_u8_to_s24(void* dst, const void* src, ma_uint64 count, ma_dit
#ifdef MA_USE_REFERENCE_CONVERSION_APIS
ma_pcm_u8_to_s24__reference(dst, src, count, ditherMode);
#else
- # if MA_PREFERRED_SIMD == MA_SIMD_AVX2
- if (ma_has_avx2()) {
- ma_pcm_u8_to_s24__avx2(dst, src, count, ditherMode);
- } else
- #elif MA_PREFERRED_SIMD == MA_SIMD_SSE2
+ # if defined(MA_SUPPORT_SSE2)
if (ma_has_sse2()) {
ma_pcm_u8_to_s24__sse2(dst, src, count, ditherMode);
} else
- #elif MA_PREFERRED_SIMD == MA_SIMD_NEON
+ #elif defined(MA_SUPPORT_NEON)
if (ma_has_neon()) {
ma_pcm_u8_to_s24__neon(dst, src, count, ditherMode);
} else
@@ -41769,12 +43262,6 @@ static MA_INLINE void ma_pcm_u8_to_s32__sse2(void* dst, const void* src, ma_uint
ma_pcm_u8_to_s32__optimized(dst, src, count, ditherMode);
}
#endif
-#if defined(MA_SUPPORT_AVX2)
-static MA_INLINE void ma_pcm_u8_to_s32__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
-{
- ma_pcm_u8_to_s32__optimized(dst, src, count, ditherMode);
-}
-#endif
#if defined(MA_SUPPORT_NEON)
static MA_INLINE void ma_pcm_u8_to_s32__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
{
@@ -41787,15 +43274,11 @@ MA_API void ma_pcm_u8_to_s32(void* dst, const void* src, ma_uint64 count, ma_dit
#ifdef MA_USE_REFERENCE_CONVERSION_APIS
ma_pcm_u8_to_s32__reference(dst, src, count, ditherMode);
#else
- # if MA_PREFERRED_SIMD == MA_SIMD_AVX2
- if (ma_has_avx2()) {
- ma_pcm_u8_to_s32__avx2(dst, src, count, ditherMode);
- } else
- #elif MA_PREFERRED_SIMD == MA_SIMD_SSE2
+ # if defined(MA_SUPPORT_SSE2)
if (ma_has_sse2()) {
ma_pcm_u8_to_s32__sse2(dst, src, count, ditherMode);
} else
- #elif MA_PREFERRED_SIMD == MA_SIMD_NEON
+ #elif defined(MA_SUPPORT_NEON)
if (ma_has_neon()) {
ma_pcm_u8_to_s32__neon(dst, src, count, ditherMode);
} else
@@ -41835,12 +43318,6 @@ static MA_INLINE void ma_pcm_u8_to_f32__sse2(void* dst, const void* src, ma_uint
ma_pcm_u8_to_f32__optimized(dst, src, count, ditherMode);
}
#endif
-#if defined(MA_SUPPORT_AVX2)
-static MA_INLINE void ma_pcm_u8_to_f32__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
-{
- ma_pcm_u8_to_f32__optimized(dst, src, count, ditherMode);
-}
-#endif
#if defined(MA_SUPPORT_NEON)
static MA_INLINE void ma_pcm_u8_to_f32__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
{
@@ -41853,15 +43330,11 @@ MA_API void ma_pcm_u8_to_f32(void* dst, const void* src, ma_uint64 count, ma_dit
#ifdef MA_USE_REFERENCE_CONVERSION_APIS
ma_pcm_u8_to_f32__reference(dst, src, count, ditherMode);
#else
- # if MA_PREFERRED_SIMD == MA_SIMD_AVX2
- if (ma_has_avx2()) {
- ma_pcm_u8_to_f32__avx2(dst, src, count, ditherMode);
- } else
- #elif MA_PREFERRED_SIMD == MA_SIMD_SSE2
+ # if defined(MA_SUPPORT_SSE2)
if (ma_has_sse2()) {
ma_pcm_u8_to_f32__sse2(dst, src, count, ditherMode);
} else
- #elif MA_PREFERRED_SIMD == MA_SIMD_NEON
+ #elif defined(MA_SUPPORT_NEON)
if (ma_has_neon()) {
ma_pcm_u8_to_f32__neon(dst, src, count, ditherMode);
} else
@@ -41997,12 +43470,6 @@ static MA_INLINE void ma_pcm_s16_to_u8__sse2(void* dst, const void* src, ma_uint
ma_pcm_s16_to_u8__optimized(dst, src, count, ditherMode);
}
#endif
-#if defined(MA_SUPPORT_AVX2)
-static MA_INLINE void ma_pcm_s16_to_u8__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
-{
- ma_pcm_s16_to_u8__optimized(dst, src, count, ditherMode);
-}
-#endif
#if defined(MA_SUPPORT_NEON)
static MA_INLINE void ma_pcm_s16_to_u8__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
{
@@ -42015,15 +43482,11 @@ MA_API void ma_pcm_s16_to_u8(void* dst, const void* src, ma_uint64 count, ma_dit
#ifdef MA_USE_REFERENCE_CONVERSION_APIS
ma_pcm_s16_to_u8__reference(dst, src, count, ditherMode);
#else
- # if MA_PREFERRED_SIMD == MA_SIMD_AVX2
- if (ma_has_avx2()) {
- ma_pcm_s16_to_u8__avx2(dst, src, count, ditherMode);
- } else
- #elif MA_PREFERRED_SIMD == MA_SIMD_SSE2
+ # if defined(MA_SUPPORT_SSE2)
if (ma_has_sse2()) {
ma_pcm_s16_to_u8__sse2(dst, src, count, ditherMode);
} else
- #elif MA_PREFERRED_SIMD == MA_SIMD_NEON
+ #elif defined(MA_SUPPORT_NEON)
if (ma_has_neon()) {
ma_pcm_s16_to_u8__neon(dst, src, count, ditherMode);
} else
@@ -42068,12 +43531,6 @@ static MA_INLINE void ma_pcm_s16_to_s24__sse2(void* dst, const void* src, ma_uin
ma_pcm_s16_to_s24__optimized(dst, src, count, ditherMode);
}
#endif
-#if defined(MA_SUPPORT_AVX2)
-static MA_INLINE void ma_pcm_s16_to_s24__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
-{
- ma_pcm_s16_to_s24__optimized(dst, src, count, ditherMode);
-}
-#endif
#if defined(MA_SUPPORT_NEON)
static MA_INLINE void ma_pcm_s16_to_s24__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
{
@@ -42086,15 +43543,11 @@ MA_API void ma_pcm_s16_to_s24(void* dst, const void* src, ma_uint64 count, ma_di
#ifdef MA_USE_REFERENCE_CONVERSION_APIS
ma_pcm_s16_to_s24__reference(dst, src, count, ditherMode);
#else
- # if MA_PREFERRED_SIMD == MA_SIMD_AVX2
- if (ma_has_avx2()) {
- ma_pcm_s16_to_s24__avx2(dst, src, count, ditherMode);
- } else
- #elif MA_PREFERRED_SIMD == MA_SIMD_SSE2
+ # if defined(MA_SUPPORT_SSE2)
if (ma_has_sse2()) {
ma_pcm_s16_to_s24__sse2(dst, src, count, ditherMode);
} else
- #elif MA_PREFERRED_SIMD == MA_SIMD_NEON
+ #elif defined(MA_SUPPORT_NEON)
if (ma_has_neon()) {
ma_pcm_s16_to_s24__neon(dst, src, count, ditherMode);
} else
@@ -42130,12 +43583,6 @@ static MA_INLINE void ma_pcm_s16_to_s32__sse2(void* dst, const void* src, ma_uin
ma_pcm_s16_to_s32__optimized(dst, src, count, ditherMode);
}
#endif
-#if defined(MA_SUPPORT_AVX2)
-static MA_INLINE void ma_pcm_s16_to_s32__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
-{
- ma_pcm_s16_to_s32__optimized(dst, src, count, ditherMode);
-}
-#endif
#if defined(MA_SUPPORT_NEON)
static MA_INLINE void ma_pcm_s16_to_s32__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
{
@@ -42148,15 +43595,11 @@ MA_API void ma_pcm_s16_to_s32(void* dst, const void* src, ma_uint64 count, ma_di
#ifdef MA_USE_REFERENCE_CONVERSION_APIS
ma_pcm_s16_to_s32__reference(dst, src, count, ditherMode);
#else
- # if MA_PREFERRED_SIMD == MA_SIMD_AVX2
- if (ma_has_avx2()) {
- ma_pcm_s16_to_s32__avx2(dst, src, count, ditherMode);
- } else
- #elif MA_PREFERRED_SIMD == MA_SIMD_SSE2
+ # if defined(MA_SUPPORT_SSE2)
if (ma_has_sse2()) {
ma_pcm_s16_to_s32__sse2(dst, src, count, ditherMode);
} else
- #elif MA_PREFERRED_SIMD == MA_SIMD_NEON
+ #elif defined(MA_SUPPORT_NEON)
if (ma_has_neon()) {
ma_pcm_s16_to_s32__neon(dst, src, count, ditherMode);
} else
@@ -42204,12 +43647,6 @@ static MA_INLINE void ma_pcm_s16_to_f32__sse2(void* dst, const void* src, ma_uin
ma_pcm_s16_to_f32__optimized(dst, src, count, ditherMode);
}
#endif
-#if defined(MA_SUPPORT_AVX2)
-static MA_INLINE void ma_pcm_s16_to_f32__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
-{
- ma_pcm_s16_to_f32__optimized(dst, src, count, ditherMode);
-}
-#endif
#if defined(MA_SUPPORT_NEON)
static MA_INLINE void ma_pcm_s16_to_f32__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
{
@@ -42222,15 +43659,11 @@ MA_API void ma_pcm_s16_to_f32(void* dst, const void* src, ma_uint64 count, ma_di
#ifdef MA_USE_REFERENCE_CONVERSION_APIS
ma_pcm_s16_to_f32__reference(dst, src, count, ditherMode);
#else
- # if MA_PREFERRED_SIMD == MA_SIMD_AVX2
- if (ma_has_avx2()) {
- ma_pcm_s16_to_f32__avx2(dst, src, count, ditherMode);
- } else
- #elif MA_PREFERRED_SIMD == MA_SIMD_SSE2
+ # if defined(MA_SUPPORT_SSE2)
if (ma_has_sse2()) {
ma_pcm_s16_to_f32__sse2(dst, src, count, ditherMode);
} else
- #elif MA_PREFERRED_SIMD == MA_SIMD_NEON
+ #elif defined(MA_SUPPORT_NEON)
if (ma_has_neon()) {
ma_pcm_s16_to_f32__neon(dst, src, count, ditherMode);
} else
@@ -42342,12 +43775,6 @@ static MA_INLINE void ma_pcm_s24_to_u8__sse2(void* dst, const void* src, ma_uint
ma_pcm_s24_to_u8__optimized(dst, src, count, ditherMode);
}
#endif
-#if defined(MA_SUPPORT_AVX2)
-static MA_INLINE void ma_pcm_s24_to_u8__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
-{
- ma_pcm_s24_to_u8__optimized(dst, src, count, ditherMode);
-}
-#endif
#if defined(MA_SUPPORT_NEON)
static MA_INLINE void ma_pcm_s24_to_u8__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
{
@@ -42360,15 +43787,11 @@ MA_API void ma_pcm_s24_to_u8(void* dst, const void* src, ma_uint64 count, ma_dit
#ifdef MA_USE_REFERENCE_CONVERSION_APIS
ma_pcm_s24_to_u8__reference(dst, src, count, ditherMode);
#else
- # if MA_PREFERRED_SIMD == MA_SIMD_AVX2
- if (ma_has_avx2()) {
- ma_pcm_s24_to_u8__avx2(dst, src, count, ditherMode);
- } else
- #elif MA_PREFERRED_SIMD == MA_SIMD_SSE2
+ # if defined(MA_SUPPORT_SSE2)
if (ma_has_sse2()) {
ma_pcm_s24_to_u8__sse2(dst, src, count, ditherMode);
} else
- #elif MA_PREFERRED_SIMD == MA_SIMD_NEON
+ #elif defined(MA_SUPPORT_NEON)
if (ma_has_neon()) {
ma_pcm_s24_to_u8__neon(dst, src, count, ditherMode);
} else
@@ -42422,12 +43845,6 @@ static MA_INLINE void ma_pcm_s24_to_s16__sse2(void* dst, const void* src, ma_uin
ma_pcm_s24_to_s16__optimized(dst, src, count, ditherMode);
}
#endif
-#if defined(MA_SUPPORT_AVX2)
-static MA_INLINE void ma_pcm_s24_to_s16__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
-{
- ma_pcm_s24_to_s16__optimized(dst, src, count, ditherMode);
-}
-#endif
#if defined(MA_SUPPORT_NEON)
static MA_INLINE void ma_pcm_s24_to_s16__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
{
@@ -42440,15 +43857,11 @@ MA_API void ma_pcm_s24_to_s16(void* dst, const void* src, ma_uint64 count, ma_di
#ifdef MA_USE_REFERENCE_CONVERSION_APIS
ma_pcm_s24_to_s16__reference(dst, src, count, ditherMode);
#else
- # if MA_PREFERRED_SIMD == MA_SIMD_AVX2
- if (ma_has_avx2()) {
- ma_pcm_s24_to_s16__avx2(dst, src, count, ditherMode);
- } else
- #elif MA_PREFERRED_SIMD == MA_SIMD_SSE2
+ # if defined(MA_SUPPORT_SSE2)
if (ma_has_sse2()) {
ma_pcm_s24_to_s16__sse2(dst, src, count, ditherMode);
} else
- #elif MA_PREFERRED_SIMD == MA_SIMD_NEON
+ #elif defined(MA_SUPPORT_NEON)
if (ma_has_neon()) {
ma_pcm_s24_to_s16__neon(dst, src, count, ditherMode);
} else
@@ -42492,12 +43905,6 @@ static MA_INLINE void ma_pcm_s24_to_s32__sse2(void* dst, const void* src, ma_uin
ma_pcm_s24_to_s32__optimized(dst, src, count, ditherMode);
}
#endif
-#if defined(MA_SUPPORT_AVX2)
-static MA_INLINE void ma_pcm_s24_to_s32__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
-{
- ma_pcm_s24_to_s32__optimized(dst, src, count, ditherMode);
-}
-#endif
#if defined(MA_SUPPORT_NEON)
static MA_INLINE void ma_pcm_s24_to_s32__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
{
@@ -42510,15 +43917,11 @@ MA_API void ma_pcm_s24_to_s32(void* dst, const void* src, ma_uint64 count, ma_di
#ifdef MA_USE_REFERENCE_CONVERSION_APIS
ma_pcm_s24_to_s32__reference(dst, src, count, ditherMode);
#else
- # if MA_PREFERRED_SIMD == MA_SIMD_AVX2
- if (ma_has_avx2()) {
- ma_pcm_s24_to_s32__avx2(dst, src, count, ditherMode);
- } else
- #elif MA_PREFERRED_SIMD == MA_SIMD_SSE2
+ # if defined(MA_SUPPORT_SSE2)
if (ma_has_sse2()) {
ma_pcm_s24_to_s32__sse2(dst, src, count, ditherMode);
} else
- #elif MA_PREFERRED_SIMD == MA_SIMD_NEON
+ #elif defined(MA_SUPPORT_NEON)
if (ma_has_neon()) {
ma_pcm_s24_to_s32__neon(dst, src, count, ditherMode);
} else
@@ -42566,12 +43969,6 @@ static MA_INLINE void ma_pcm_s24_to_f32__sse2(void* dst, const void* src, ma_uin
ma_pcm_s24_to_f32__optimized(dst, src, count, ditherMode);
}
#endif
-#if defined(MA_SUPPORT_AVX2)
-static MA_INLINE void ma_pcm_s24_to_f32__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
-{
- ma_pcm_s24_to_f32__optimized(dst, src, count, ditherMode);
-}
-#endif
#if defined(MA_SUPPORT_NEON)
static MA_INLINE void ma_pcm_s24_to_f32__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
{
@@ -42584,15 +43981,11 @@ MA_API void ma_pcm_s24_to_f32(void* dst, const void* src, ma_uint64 count, ma_di
#ifdef MA_USE_REFERENCE_CONVERSION_APIS
ma_pcm_s24_to_f32__reference(dst, src, count, ditherMode);
#else
- # if MA_PREFERRED_SIMD == MA_SIMD_AVX2
- if (ma_has_avx2()) {
- ma_pcm_s24_to_f32__avx2(dst, src, count, ditherMode);
- } else
- #elif MA_PREFERRED_SIMD == MA_SIMD_SSE2
+ # if defined(MA_SUPPORT_SSE2)
if (ma_has_sse2()) {
ma_pcm_s24_to_f32__sse2(dst, src, count, ditherMode);
} else
- #elif MA_PREFERRED_SIMD == MA_SIMD_NEON
+ #elif defined(MA_SUPPORT_NEON)
if (ma_has_neon()) {
ma_pcm_s24_to_f32__neon(dst, src, count, ditherMode);
} else
@@ -42712,12 +44105,6 @@ static MA_INLINE void ma_pcm_s32_to_u8__sse2(void* dst, const void* src, ma_uint
ma_pcm_s32_to_u8__optimized(dst, src, count, ditherMode);
}
#endif
-#if defined(MA_SUPPORT_AVX2)
-static MA_INLINE void ma_pcm_s32_to_u8__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
-{
- ma_pcm_s32_to_u8__optimized(dst, src, count, ditherMode);
-}
-#endif
#if defined(MA_SUPPORT_NEON)
static MA_INLINE void ma_pcm_s32_to_u8__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
{
@@ -42730,15 +44117,11 @@ MA_API void ma_pcm_s32_to_u8(void* dst, const void* src, ma_uint64 count, ma_dit
#ifdef MA_USE_REFERENCE_CONVERSION_APIS
ma_pcm_s32_to_u8__reference(dst, src, count, ditherMode);
#else
- # if MA_PREFERRED_SIMD == MA_SIMD_AVX2
- if (ma_has_avx2()) {
- ma_pcm_s32_to_u8__avx2(dst, src, count, ditherMode);
- } else
- #elif MA_PREFERRED_SIMD == MA_SIMD_SSE2
+ # if defined(MA_SUPPORT_SSE2)
if (ma_has_sse2()) {
ma_pcm_s32_to_u8__sse2(dst, src, count, ditherMode);
} else
- #elif MA_PREFERRED_SIMD == MA_SIMD_NEON
+ #elif defined(MA_SUPPORT_NEON)
if (ma_has_neon()) {
ma_pcm_s32_to_u8__neon(dst, src, count, ditherMode);
} else
@@ -42792,12 +44175,6 @@ static MA_INLINE void ma_pcm_s32_to_s16__sse2(void* dst, const void* src, ma_uin
ma_pcm_s32_to_s16__optimized(dst, src, count, ditherMode);
}
#endif
-#if defined(MA_SUPPORT_AVX2)
-static MA_INLINE void ma_pcm_s32_to_s16__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
-{
- ma_pcm_s32_to_s16__optimized(dst, src, count, ditherMode);
-}
-#endif
#if defined(MA_SUPPORT_NEON)
static MA_INLINE void ma_pcm_s32_to_s16__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
{
@@ -42810,15 +44187,11 @@ MA_API void ma_pcm_s32_to_s16(void* dst, const void* src, ma_uint64 count, ma_di
#ifdef MA_USE_REFERENCE_CONVERSION_APIS
ma_pcm_s32_to_s16__reference(dst, src, count, ditherMode);
#else
- # if MA_PREFERRED_SIMD == MA_SIMD_AVX2
- if (ma_has_avx2()) {
- ma_pcm_s32_to_s16__avx2(dst, src, count, ditherMode);
- } else
- #elif MA_PREFERRED_SIMD == MA_SIMD_SSE2
+ # if defined(MA_SUPPORT_SSE2)
if (ma_has_sse2()) {
ma_pcm_s32_to_s16__sse2(dst, src, count, ditherMode);
} else
- #elif MA_PREFERRED_SIMD == MA_SIMD_NEON
+ #elif defined(MA_SUPPORT_NEON)
if (ma_has_neon()) {
ma_pcm_s32_to_s16__neon(dst, src, count, ditherMode);
} else
@@ -42857,12 +44230,6 @@ static MA_INLINE void ma_pcm_s32_to_s24__sse2(void* dst, const void* src, ma_uin
ma_pcm_s32_to_s24__optimized(dst, src, count, ditherMode);
}
#endif
-#if defined(MA_SUPPORT_AVX2)
-static MA_INLINE void ma_pcm_s32_to_s24__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
-{
- ma_pcm_s32_to_s24__optimized(dst, src, count, ditherMode);
-}
-#endif
#if defined(MA_SUPPORT_NEON)
static MA_INLINE void ma_pcm_s32_to_s24__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
{
@@ -42875,15 +44242,11 @@ MA_API void ma_pcm_s32_to_s24(void* dst, const void* src, ma_uint64 count, ma_di
#ifdef MA_USE_REFERENCE_CONVERSION_APIS
ma_pcm_s32_to_s24__reference(dst, src, count, ditherMode);
#else
- # if MA_PREFERRED_SIMD == MA_SIMD_AVX2
- if (ma_has_avx2()) {
- ma_pcm_s32_to_s24__avx2(dst, src, count, ditherMode);
- } else
- #elif MA_PREFERRED_SIMD == MA_SIMD_SSE2
+ # if defined(MA_SUPPORT_SSE2)
if (ma_has_sse2()) {
ma_pcm_s32_to_s24__sse2(dst, src, count, ditherMode);
} else
- #elif MA_PREFERRED_SIMD == MA_SIMD_NEON
+ #elif defined(MA_SUPPORT_NEON)
if (ma_has_neon()) {
ma_pcm_s32_to_s24__neon(dst, src, count, ditherMode);
} else
@@ -42937,12 +44300,6 @@ static MA_INLINE void ma_pcm_s32_to_f32__sse2(void* dst, const void* src, ma_uin
ma_pcm_s32_to_f32__optimized(dst, src, count, ditherMode);
}
#endif
-#if defined(MA_SUPPORT_AVX2)
-static MA_INLINE void ma_pcm_s32_to_f32__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
-{
- ma_pcm_s32_to_f32__optimized(dst, src, count, ditherMode);
-}
-#endif
#if defined(MA_SUPPORT_NEON)
static MA_INLINE void ma_pcm_s32_to_f32__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
{
@@ -42955,15 +44312,11 @@ MA_API void ma_pcm_s32_to_f32(void* dst, const void* src, ma_uint64 count, ma_di
#ifdef MA_USE_REFERENCE_CONVERSION_APIS
ma_pcm_s32_to_f32__reference(dst, src, count, ditherMode);
#else
- # if MA_PREFERRED_SIMD == MA_SIMD_AVX2
- if (ma_has_avx2()) {
- ma_pcm_s32_to_f32__avx2(dst, src, count, ditherMode);
- } else
- #elif MA_PREFERRED_SIMD == MA_SIMD_SSE2
+ # if defined(MA_SUPPORT_SSE2)
if (ma_has_sse2()) {
ma_pcm_s32_to_f32__sse2(dst, src, count, ditherMode);
} else
- #elif MA_PREFERRED_SIMD == MA_SIMD_NEON
+ #elif defined(MA_SUPPORT_NEON)
if (ma_has_neon()) {
ma_pcm_s32_to_f32__neon(dst, src, count, ditherMode);
} else
@@ -43070,12 +44423,6 @@ static MA_INLINE void ma_pcm_f32_to_u8__sse2(void* dst, const void* src, ma_uint
ma_pcm_f32_to_u8__optimized(dst, src, count, ditherMode);
}
#endif
-#if defined(MA_SUPPORT_AVX2)
-static MA_INLINE void ma_pcm_f32_to_u8__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
-{
- ma_pcm_f32_to_u8__optimized(dst, src, count, ditherMode);
-}
-#endif
#if defined(MA_SUPPORT_NEON)
static MA_INLINE void ma_pcm_f32_to_u8__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
{
@@ -43088,15 +44435,11 @@ MA_API void ma_pcm_f32_to_u8(void* dst, const void* src, ma_uint64 count, ma_dit
#ifdef MA_USE_REFERENCE_CONVERSION_APIS
ma_pcm_f32_to_u8__reference(dst, src, count, ditherMode);
#else
- # if MA_PREFERRED_SIMD == MA_SIMD_AVX2
- if (ma_has_avx2()) {
- ma_pcm_f32_to_u8__avx2(dst, src, count, ditherMode);
- } else
- #elif MA_PREFERRED_SIMD == MA_SIMD_SSE2
+ # if defined(MA_SUPPORT_SSE2)
if (ma_has_sse2()) {
ma_pcm_f32_to_u8__sse2(dst, src, count, ditherMode);
} else
- #elif MA_PREFERRED_SIMD == MA_SIMD_NEON
+ #elif defined(MA_SUPPORT_NEON)
if (ma_has_neon()) {
ma_pcm_f32_to_u8__neon(dst, src, count, ditherMode);
} else
@@ -43300,129 +44643,6 @@ static MA_INLINE void ma_pcm_f32_to_s16__sse2(void* dst, const void* src, ma_uin
}
#endif /* SSE2 */
-#if defined(MA_SUPPORT_AVX2)
-static MA_INLINE void ma_pcm_f32_to_s16__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
-{
- ma_uint64 i;
- ma_uint64 i16;
- ma_uint64 count16;
- ma_int16* dst_s16;
- const float* src_f32;
- float ditherMin;
- float ditherMax;
-
- /* Both the input and output buffers need to be aligned to 32 bytes. */
- if ((((ma_uintptr)dst & 31) != 0) || (((ma_uintptr)src & 31) != 0)) {
- ma_pcm_f32_to_s16__optimized(dst, src, count, ditherMode);
- return;
- }
-
- dst_s16 = (ma_int16*)dst;
- src_f32 = (const float*)src;
-
- ditherMin = 0;
- ditherMax = 0;
- if (ditherMode != ma_dither_mode_none) {
- ditherMin = 1.0f / -32768;
- ditherMax = 1.0f / 32767;
- }
-
- i = 0;
-
- /* AVX2. AVX2 allows us to output 16 s16's at a time which means our loop is unrolled 16 times. */
- count16 = count >> 4;
- for (i16 = 0; i16 < count16; i16 += 1) {
- __m256 d0;
- __m256 d1;
- __m256 x0;
- __m256 x1;
- __m256i i0;
- __m256i i1;
- __m256i p0;
- __m256i p1;
- __m256i r;
-
- if (ditherMode == ma_dither_mode_none) {
- d0 = _mm256_set1_ps(0);
- d1 = _mm256_set1_ps(0);
- } else if (ditherMode == ma_dither_mode_rectangle) {
- d0 = _mm256_set_ps(
- ma_dither_f32_rectangle(ditherMin, ditherMax),
- ma_dither_f32_rectangle(ditherMin, ditherMax),
- ma_dither_f32_rectangle(ditherMin, ditherMax),
- ma_dither_f32_rectangle(ditherMin, ditherMax),
- ma_dither_f32_rectangle(ditherMin, ditherMax),
- ma_dither_f32_rectangle(ditherMin, ditherMax),
- ma_dither_f32_rectangle(ditherMin, ditherMax),
- ma_dither_f32_rectangle(ditherMin, ditherMax)
- );
- d1 = _mm256_set_ps(
- ma_dither_f32_rectangle(ditherMin, ditherMax),
- ma_dither_f32_rectangle(ditherMin, ditherMax),
- ma_dither_f32_rectangle(ditherMin, ditherMax),
- ma_dither_f32_rectangle(ditherMin, ditherMax),
- ma_dither_f32_rectangle(ditherMin, ditherMax),
- ma_dither_f32_rectangle(ditherMin, ditherMax),
- ma_dither_f32_rectangle(ditherMin, ditherMax),
- ma_dither_f32_rectangle(ditherMin, ditherMax)
- );
- } else {
- d0 = _mm256_set_ps(
- ma_dither_f32_triangle(ditherMin, ditherMax),
- ma_dither_f32_triangle(ditherMin, ditherMax),
- ma_dither_f32_triangle(ditherMin, ditherMax),
- ma_dither_f32_triangle(ditherMin, ditherMax),
- ma_dither_f32_triangle(ditherMin, ditherMax),
- ma_dither_f32_triangle(ditherMin, ditherMax),
- ma_dither_f32_triangle(ditherMin, ditherMax),
- ma_dither_f32_triangle(ditherMin, ditherMax)
- );
- d1 = _mm256_set_ps(
- ma_dither_f32_triangle(ditherMin, ditherMax),
- ma_dither_f32_triangle(ditherMin, ditherMax),
- ma_dither_f32_triangle(ditherMin, ditherMax),
- ma_dither_f32_triangle(ditherMin, ditherMax),
- ma_dither_f32_triangle(ditherMin, ditherMax),
- ma_dither_f32_triangle(ditherMin, ditherMax),
- ma_dither_f32_triangle(ditherMin, ditherMax),
- ma_dither_f32_triangle(ditherMin, ditherMax)
- );
- }
-
- x0 = *((__m256*)(src_f32 + i) + 0);
- x1 = *((__m256*)(src_f32 + i) + 1);
-
- x0 = _mm256_add_ps(x0, d0);
- x1 = _mm256_add_ps(x1, d1);
-
- x0 = _mm256_mul_ps(x0, _mm256_set1_ps(32767.0f));
- x1 = _mm256_mul_ps(x1, _mm256_set1_ps(32767.0f));
-
- /* Computing the final result is a little more complicated for AVX2 than SSE2. */
- i0 = _mm256_cvttps_epi32(x0);
- i1 = _mm256_cvttps_epi32(x1);
- p0 = _mm256_permute2x128_si256(i0, i1, 0 | 32);
- p1 = _mm256_permute2x128_si256(i0, i1, 1 | 48);
- r = _mm256_packs_epi32(p0, p1);
-
- _mm256_stream_si256(((__m256i*)(dst_s16 + i)), r);
-
- i += 16;
- }
-
-
- /* Leftover. */
- for (; i < count; i += 1) {
- float x = src_f32[i];
- x = x + ma_dither_f32(ditherMode, ditherMin, ditherMax);
- x = ((x < -1) ? -1 : ((x > 1) ? 1 : x)); /* clip */
- x = x * 32767.0f; /* -1..1 to -32767..32767 */
-
- dst_s16[i] = (ma_int16)x;
- }
-}
-#endif /* AVX2 */
-
#if defined(MA_SUPPORT_NEON)
static MA_INLINE void ma_pcm_f32_to_s16__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
{
@@ -43435,7 +44655,8 @@ static MA_INLINE void ma_pcm_f32_to_s16__neon(void* dst, const void* src, ma_uin
float ditherMax;
if (!ma_has_neon()) {
- return ma_pcm_f32_to_s16__optimized(dst, src, count, ditherMode);
+ ma_pcm_f32_to_s16__optimized(dst, src, count, ditherMode);
+ return;
}
/* Both the input and output buffers need to be aligned to 16 bytes. */
@@ -43471,13 +44692,14 @@ static MA_INLINE void ma_pcm_f32_to_s16__neon(void* dst, const void* src, ma_uin
d1 = vmovq_n_f32(0);
} else if (ditherMode == ma_dither_mode_rectangle) {
float d0v[4];
+ float d1v[4];
+
d0v[0] = ma_dither_f32_rectangle(ditherMin, ditherMax);
d0v[1] = ma_dither_f32_rectangle(ditherMin, ditherMax);
d0v[2] = ma_dither_f32_rectangle(ditherMin, ditherMax);
d0v[3] = ma_dither_f32_rectangle(ditherMin, ditherMax);
d0 = vld1q_f32(d0v);
- float d1v[4];
d1v[0] = ma_dither_f32_rectangle(ditherMin, ditherMax);
d1v[1] = ma_dither_f32_rectangle(ditherMin, ditherMax);
d1v[2] = ma_dither_f32_rectangle(ditherMin, ditherMax);
@@ -43485,13 +44707,14 @@ static MA_INLINE void ma_pcm_f32_to_s16__neon(void* dst, const void* src, ma_uin
d1 = vld1q_f32(d1v);
} else {
float d0v[4];
+ float d1v[4];
+
d0v[0] = ma_dither_f32_triangle(ditherMin, ditherMax);
d0v[1] = ma_dither_f32_triangle(ditherMin, ditherMax);
d0v[2] = ma_dither_f32_triangle(ditherMin, ditherMax);
d0v[3] = ma_dither_f32_triangle(ditherMin, ditherMax);
d0 = vld1q_f32(d0v);
- float d1v[4];
d1v[0] = ma_dither_f32_triangle(ditherMin, ditherMax);
d1v[1] = ma_dither_f32_triangle(ditherMin, ditherMax);
d1v[2] = ma_dither_f32_triangle(ditherMin, ditherMax);
@@ -43534,15 +44757,11 @@ MA_API void ma_pcm_f32_to_s16(void* dst, const void* src, ma_uint64 count, ma_di
#ifdef MA_USE_REFERENCE_CONVERSION_APIS
ma_pcm_f32_to_s16__reference(dst, src, count, ditherMode);
#else
- # if MA_PREFERRED_SIMD == MA_SIMD_AVX2
- if (ma_has_avx2()) {
- ma_pcm_f32_to_s16__avx2(dst, src, count, ditherMode);
- } else
- #elif MA_PREFERRED_SIMD == MA_SIMD_SSE2
+ # if defined(MA_SUPPORT_SSE2)
if (ma_has_sse2()) {
ma_pcm_f32_to_s16__sse2(dst, src, count, ditherMode);
} else
- #elif MA_PREFERRED_SIMD == MA_SIMD_NEON
+ #elif defined(MA_SUPPORT_NEON)
if (ma_has_neon()) {
ma_pcm_f32_to_s16__neon(dst, src, count, ditherMode);
} else
@@ -43595,12 +44814,6 @@ static MA_INLINE void ma_pcm_f32_to_s24__sse2(void* dst, const void* src, ma_uin
ma_pcm_f32_to_s24__optimized(dst, src, count, ditherMode);
}
#endif
-#if defined(MA_SUPPORT_AVX2)
-static MA_INLINE void ma_pcm_f32_to_s24__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
-{
- ma_pcm_f32_to_s24__optimized(dst, src, count, ditherMode);
-}
-#endif
#if defined(MA_SUPPORT_NEON)
static MA_INLINE void ma_pcm_f32_to_s24__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
{
@@ -43613,15 +44826,11 @@ MA_API void ma_pcm_f32_to_s24(void* dst, const void* src, ma_uint64 count, ma_di
#ifdef MA_USE_REFERENCE_CONVERSION_APIS
ma_pcm_f32_to_s24__reference(dst, src, count, ditherMode);
#else
- # if MA_PREFERRED_SIMD == MA_SIMD_AVX2
- if (ma_has_avx2()) {
- ma_pcm_f32_to_s24__avx2(dst, src, count, ditherMode);
- } else
- #elif MA_PREFERRED_SIMD == MA_SIMD_SSE2
+ # if defined(MA_SUPPORT_SSE2)
if (ma_has_sse2()) {
ma_pcm_f32_to_s24__sse2(dst, src, count, ditherMode);
} else
- #elif MA_PREFERRED_SIMD == MA_SIMD_NEON
+ #elif defined(MA_SUPPORT_NEON)
if (ma_has_neon()) {
ma_pcm_f32_to_s24__neon(dst, src, count, ditherMode);
} else
@@ -43670,12 +44879,6 @@ static MA_INLINE void ma_pcm_f32_to_s32__sse2(void* dst, const void* src, ma_uin
ma_pcm_f32_to_s32__optimized(dst, src, count, ditherMode);
}
#endif
-#if defined(MA_SUPPORT_AVX2)
-static MA_INLINE void ma_pcm_f32_to_s32__avx2(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
-{
- ma_pcm_f32_to_s32__optimized(dst, src, count, ditherMode);
-}
-#endif
#if defined(MA_SUPPORT_NEON)
static MA_INLINE void ma_pcm_f32_to_s32__neon(void* dst, const void* src, ma_uint64 count, ma_dither_mode ditherMode)
{
@@ -43688,15 +44891,11 @@ MA_API void ma_pcm_f32_to_s32(void* dst, const void* src, ma_uint64 count, ma_di
#ifdef MA_USE_REFERENCE_CONVERSION_APIS
ma_pcm_f32_to_s32__reference(dst, src, count, ditherMode);
#else
- # if MA_PREFERRED_SIMD == MA_SIMD_AVX2
- if (ma_has_avx2()) {
- ma_pcm_f32_to_s32__avx2(dst, src, count, ditherMode);
- } else
- #elif MA_PREFERRED_SIMD == MA_SIMD_SSE2
+ # if defined(MA_SUPPORT_SSE2)
if (ma_has_sse2()) {
ma_pcm_f32_to_s32__sse2(dst, src, count, ditherMode);
} else
- #elif MA_PREFERRED_SIMD == MA_SIMD_NEON
+ #elif defined(MA_SUPPORT_NEON)
if (ma_has_neon()) {
ma_pcm_f32_to_s32__neon(dst, src, count, ditherMode);
} else
@@ -45071,7 +46270,7 @@ static MA_INLINE void ma_lpf_process_pcm_frame_f32(ma_lpf* pLPF, float* pY, cons
MA_ASSERT(pLPF->format == ma_format_f32);
- MA_COPY_MEMORY(pY, pX, ma_get_bytes_per_frame(pLPF->format, pLPF->channels));
+ MA_MOVE_MEMORY(pY, pX, ma_get_bytes_per_frame(pLPF->format, pLPF->channels));
for (ilpf1 = 0; ilpf1 < pLPF->lpf1Count; ilpf1 += 1) {
ma_lpf1_process_pcm_frame_f32(&pLPF->pLPF1[ilpf1], pY, pY);
@@ -45089,7 +46288,7 @@ static MA_INLINE void ma_lpf_process_pcm_frame_s16(ma_lpf* pLPF, ma_int16* pY, c
MA_ASSERT(pLPF->format == ma_format_s16);
- MA_COPY_MEMORY(pY, pX, ma_get_bytes_per_frame(pLPF->format, pLPF->channels));
+ MA_MOVE_MEMORY(pY, pX, ma_get_bytes_per_frame(pLPF->format, pLPF->channels));
for (ilpf1 = 0; ilpf1 < pLPF->lpf1Count; ilpf1 += 1) {
ma_lpf1_process_pcm_frame_s16(&pLPF->pLPF1[ilpf1], pY, pY);
@@ -47428,6 +48627,7 @@ MA_API ma_result ma_gainer_init_preallocated(const ma_gainer_config* pConfig, vo
pGainer->pOldGains = (float*)ma_offset_ptr(pHeap, heapLayout.oldGainsOffset);
pGainer->pNewGains = (float*)ma_offset_ptr(pHeap, heapLayout.newGainsOffset);
+ pGainer->masterVolume = 1;
pGainer->config = *pConfig;
pGainer->t = (ma_uint32)-1; /* No interpolation by default. */
@@ -47487,20 +48687,256 @@ static float ma_gainer_calculate_current_gain(const ma_gainer* pGainer, ma_uint3
return ma_mix_f32_fast(pGainer->pOldGains[channel], pGainer->pNewGains[channel], a);
}
-MA_API ma_result ma_gainer_process_pcm_frames(ma_gainer* pGainer, void* pFramesOut, const void* pFramesIn, ma_uint64 frameCount)
+static /*__attribute__((noinline))*/ ma_result ma_gainer_process_pcm_frames_internal(ma_gainer * pGainer, void* MA_RESTRICT pFramesOut, const void* MA_RESTRICT pFramesIn, ma_uint64 frameCount)
{
ma_uint64 iFrame;
ma_uint32 iChannel;
- float* pFramesOutF32 = (float*)pFramesOut;
- const float* pFramesInF32 = (const float*)pFramesIn;
+ ma_uint64 interpolatedFrameCount;
- if (pGainer == NULL) {
- return MA_INVALID_ARGS;
+ MA_ASSERT(pGainer != NULL);
+
+ /*
+ We don't necessarily need to apply a linear interpolation for the entire frameCount frames. When
+ linear interpolation is not needed we can do a simple volume adjustment which will be more
+ efficient than a lerp with an alpha value of 1.
+
+ To do this, all we need to do is determine how many frames need to have a lerp applied. Then we
+ just process that number of frames with linear interpolation. After that we run on an optimized
+ path which just applies the new gains without a lerp.
+ */
+ if (pGainer->t >= pGainer->config.smoothTimeInFrames) {
+ interpolatedFrameCount = 0;
+ } else {
+ interpolatedFrameCount = pGainer->t - pGainer->config.smoothTimeInFrames;
+ if (interpolatedFrameCount > frameCount) {
+ interpolatedFrameCount = frameCount;
+ }
}
+ /*
+ Start off with our interpolated frames. When we do this, we'll adjust frameCount and our pointers
+ so that the fast path can work naturally without consideration of the interpolated path.
+ */
+ if (interpolatedFrameCount > 0) {
+ /* We can allow the input and output buffers to be null in which case we'll just update the internal timer. */
+ if (pFramesOut != NULL && pFramesIn != NULL) {
+ /*
+ All we're really doing here is moving the old gains towards the new gains. We don't want to
+ be modifying the gains inside the ma_gainer object because that will break things. Instead
+ we can make a copy here on the stack. For extreme channel counts we can fall back to a slower
+ implementation which just uses a standard lerp.
+ */
+ float* pFramesOutF32 = (float*)pFramesOut;
+ const float* pFramesInF32 = (const float*)pFramesIn;
+ float a = (float)pGainer->t / pGainer->config.smoothTimeInFrames;
+ float d = 1.0f / pGainer->config.smoothTimeInFrames;
+
+ if (pGainer->config.channels <= 32) {
+ float pRunningGain[32];
+ float pRunningGainDelta[32]; /* Could this be heap-allocated as part of the ma_gainer object? */
+
+ /* Initialize the running gain. */
+ for (iChannel = 0; iChannel < pGainer->config.channels; iChannel += 1) {
+ float t = (pGainer->pNewGains[iChannel] - pGainer->pOldGains[iChannel]) * pGainer->masterVolume;
+ pRunningGainDelta[iChannel] = t * d;
+ pRunningGain[iChannel] = (pGainer->pOldGains[iChannel] * pGainer->masterVolume) + (t * a);
+ }
+
+ iFrame = 0;
+
+ /* Optimized paths for common channel counts. This is mostly just experimenting with some SIMD ideas. It's not necessarily final. */
+ if (pGainer->config.channels == 2) {
+ #if defined(MA_SUPPORT_SSE2)
+ if (ma_has_sse2()) {
+ ma_uint64 unrolledLoopCount = interpolatedFrameCount >> 1;
+
+ /* Expand some arrays so we can have a clean SIMD loop below. */
+ __m128 runningGainDelta0 = _mm_set_ps(pRunningGainDelta[1], pRunningGainDelta[0], pRunningGainDelta[1], pRunningGainDelta[0]);
+ __m128 runningGain0 = _mm_set_ps(pRunningGain[1] + pRunningGainDelta[1], pRunningGain[0] + pRunningGainDelta[0], pRunningGain[1], pRunningGain[0]);
+
+ for (; iFrame < unrolledLoopCount; iFrame += 1) {
+ _mm_storeu_ps(&pFramesOutF32[iFrame*4 + 0], _mm_mul_ps(_mm_loadu_ps(&pFramesInF32[iFrame*4 + 0]), runningGain0));
+ runningGain0 = _mm_add_ps(runningGain0, runningGainDelta0);
+ }
+
+ iFrame = unrolledLoopCount << 1;
+ } else
+ #endif
+ {
+ /*
+ Two different scalar implementations here. Clang (and I assume GCC) will vectorize
+ both of these, but the bottom version results in a nicer vectorization with less
+ instructions emitted. The problem, however, is that the bottom version runs slower
+ when compiled with MSVC. The top version will be partially vectorized by MSVC.
+ */
+ #if defined(_MSC_VER) && !defined(__clang__)
+ ma_uint64 unrolledLoopCount = interpolatedFrameCount >> 1;
+
+ /* Expand some arrays so we can have a clean 4x SIMD operation in the loop. */
+ pRunningGainDelta[2] = pRunningGainDelta[0];
+ pRunningGainDelta[3] = pRunningGainDelta[1];
+ pRunningGain[2] = pRunningGain[0] + pRunningGainDelta[0];
+ pRunningGain[3] = pRunningGain[1] + pRunningGainDelta[1];
+
+ for (; iFrame < unrolledLoopCount; iFrame += 1) {
+ pFramesOutF32[iFrame*4 + 0] = pFramesInF32[iFrame*4 + 0] * pRunningGain[0];
+ pFramesOutF32[iFrame*4 + 1] = pFramesInF32[iFrame*4 + 1] * pRunningGain[1];
+ pFramesOutF32[iFrame*4 + 2] = pFramesInF32[iFrame*4 + 2] * pRunningGain[2];
+ pFramesOutF32[iFrame*4 + 3] = pFramesInF32[iFrame*4 + 3] * pRunningGain[3];
+
+ /* Move the running gain forward towards the new gain. */
+ pRunningGain[0] += pRunningGainDelta[0];
+ pRunningGain[1] += pRunningGainDelta[1];
+ pRunningGain[2] += pRunningGainDelta[2];
+ pRunningGain[3] += pRunningGainDelta[3];
+ }
+
+ iFrame = unrolledLoopCount << 1;
+ #else
+ for (; iFrame < interpolatedFrameCount; iFrame += 1) {
+ for (iChannel = 0; iChannel < 2; iChannel += 1) {
+ pFramesOutF32[iFrame*2 + iChannel] = pFramesInF32[iFrame*2 + iChannel] * pRunningGain[iChannel];
+ }
+
+ for (iChannel = 0; iChannel < 2; iChannel += 1) {
+ pRunningGain[iChannel] += pRunningGainDelta[iChannel];
+ }
+ }
+ #endif
+ }
+ } else if (pGainer->config.channels == 6) {
+ #if defined(MA_SUPPORT_SSE2)
+ if (ma_has_sse2()) {
+ /*
+ For 6 channels things are a bit more complicated because 6 isn't cleanly divisible by 4. We need to do 2 frames
+ at a time, meaning we'll be doing 12 samples in a group. Like the stereo case we'll need to expand some arrays
+ so we can do clean 4x SIMD operations.
+ */
+ ma_uint64 unrolledLoopCount = interpolatedFrameCount >> 1;
+
+ /* Expand some arrays so we can have a clean SIMD loop below. */
+ __m128 runningGainDelta0 = _mm_set_ps(pRunningGainDelta[3], pRunningGainDelta[2], pRunningGainDelta[1], pRunningGainDelta[0]);
+ __m128 runningGainDelta1 = _mm_set_ps(pRunningGainDelta[1], pRunningGainDelta[0], pRunningGainDelta[5], pRunningGainDelta[4]);
+ __m128 runningGainDelta2 = _mm_set_ps(pRunningGainDelta[5], pRunningGainDelta[4], pRunningGainDelta[3], pRunningGainDelta[2]);
+
+ __m128 runningGain0 = _mm_set_ps(pRunningGain[3], pRunningGain[2], pRunningGain[1], pRunningGain[0]);
+ __m128 runningGain1 = _mm_set_ps(pRunningGain[1] + pRunningGainDelta[1], pRunningGain[0] + pRunningGainDelta[0], pRunningGain[5], pRunningGain[4]);
+ __m128 runningGain2 = _mm_set_ps(pRunningGain[5] + pRunningGainDelta[5], pRunningGain[4] + pRunningGainDelta[4], pRunningGain[3] + pRunningGainDelta[3], pRunningGain[2] + pRunningGainDelta[2]);
+
+ for (; iFrame < unrolledLoopCount; iFrame += 1) {
+ _mm_storeu_ps(&pFramesOutF32[iFrame*12 + 0], _mm_mul_ps(_mm_loadu_ps(&pFramesInF32[iFrame*12 + 0]), runningGain0));
+ _mm_storeu_ps(&pFramesOutF32[iFrame*12 + 4], _mm_mul_ps(_mm_loadu_ps(&pFramesInF32[iFrame*12 + 4]), runningGain1));
+ _mm_storeu_ps(&pFramesOutF32[iFrame*12 + 8], _mm_mul_ps(_mm_loadu_ps(&pFramesInF32[iFrame*12 + 8]), runningGain2));
+
+ runningGain0 = _mm_add_ps(runningGain0, runningGainDelta0);
+ runningGain1 = _mm_add_ps(runningGain1, runningGainDelta1);
+ runningGain2 = _mm_add_ps(runningGain2, runningGainDelta2);
+ }
+
+ iFrame = unrolledLoopCount << 1;
+ } else
+ #endif
+ {
+ for (; iFrame < interpolatedFrameCount; iFrame += 1) {
+ for (iChannel = 0; iChannel < 6; iChannel += 1) {
+ pFramesOutF32[iFrame*6 + iChannel] = pFramesInF32[iFrame*6 + iChannel] * pRunningGain[iChannel];
+ }
+
+ /* Move the running gain forward towards the new gain. */
+ for (iChannel = 0; iChannel < 6; iChannel += 1) {
+ pRunningGain[iChannel] += pRunningGainDelta[iChannel];
+ }
+ }
+ }
+ } else if (pGainer->config.channels == 8) {
+ /* For 8 channels we can just go over frame by frame and do all eight channels as 2 separate 4x SIMD operations. */
+ #if defined(MA_SUPPORT_SSE2)
+ if (ma_has_sse2()) {
+ __m128 runningGainDelta0 = _mm_loadu_ps(&pRunningGainDelta[0]);
+ __m128 runningGainDelta1 = _mm_loadu_ps(&pRunningGainDelta[4]);
+ __m128 runningGain0 = _mm_loadu_ps(&pRunningGain[0]);
+ __m128 runningGain1 = _mm_loadu_ps(&pRunningGain[4]);
+
+ for (; iFrame < interpolatedFrameCount; iFrame += 1) {
+ _mm_storeu_ps(&pFramesOutF32[iFrame*8 + 0], _mm_mul_ps(_mm_loadu_ps(&pFramesInF32[iFrame*8 + 0]), runningGain0));
+ _mm_storeu_ps(&pFramesOutF32[iFrame*8 + 4], _mm_mul_ps(_mm_loadu_ps(&pFramesInF32[iFrame*8 + 4]), runningGain1));
+
+ runningGain0 = _mm_add_ps(runningGain0, runningGainDelta0);
+ runningGain1 = _mm_add_ps(runningGain1, runningGainDelta1);
+ }
+ } else
+ #endif
+ {
+ /* This is crafted so that it auto-vectorizes when compiled with Clang. */
+ for (; iFrame < interpolatedFrameCount; iFrame += 1) {
+ for (iChannel = 0; iChannel < 8; iChannel += 1) {
+ pFramesOutF32[iFrame*8 + iChannel] = pFramesInF32[iFrame*8 + iChannel] * pRunningGain[iChannel];
+ }
+
+ /* Move the running gain forward towards the new gain. */
+ for (iChannel = 0; iChannel < 8; iChannel += 1) {
+ pRunningGain[iChannel] += pRunningGainDelta[iChannel];
+ }
+ }
+ }
+ }
+
+ for (; iFrame < interpolatedFrameCount; iFrame += 1) {
+ for (iChannel = 0; iChannel < pGainer->config.channels; iChannel += 1) {
+ pFramesOutF32[iFrame*pGainer->config.channels + iChannel] = pFramesInF32[iFrame*pGainer->config.channels + iChannel] * pRunningGain[iChannel];
+ pRunningGain[iChannel] += pRunningGainDelta[iChannel];
+ }
+ }
+ } else {
+ /* Slower path for extreme channel counts where we can't fit enough on the stack. We could also move this to the heap as part of the ma_gainer object which might even be better since it'll only be updated when the gains actually change. */
+ for (iFrame = 0; iFrame < interpolatedFrameCount; iFrame += 1) {
+ for (iChannel = 0; iChannel < pGainer->config.channels; iChannel += 1) {
+ pFramesOutF32[iFrame*pGainer->config.channels + iChannel] = pFramesInF32[iFrame*pGainer->config.channels + iChannel] * ma_mix_f32_fast(pGainer->pOldGains[iChannel], pGainer->pNewGains[iChannel], a) * pGainer->masterVolume;
+ }
+
+ a += d;
+ }
+ }
+ }
+
+ /* Make sure the timer is updated. */
+ pGainer->t = (ma_uint32)ma_min(pGainer->t + interpolatedFrameCount, pGainer->config.smoothTimeInFrames);
+
+ /* Adjust our arguments so the next part can work normally. */
+ frameCount -= interpolatedFrameCount;
+ pFramesOut = ma_offset_ptr(pFramesOut, interpolatedFrameCount * sizeof(float));
+ pFramesIn = ma_offset_ptr(pFramesIn, interpolatedFrameCount * sizeof(float));
+ }
+
+ /* All we need to do here is apply the new gains using an optimized path. */
+ if (pFramesOut != NULL && pFramesIn != NULL) {
+ if (pGainer->config.channels <= 32) {
+ float gains[32];
+ for (iChannel = 0; iChannel < pGainer->config.channels; iChannel += 1) {
+ gains[iChannel] = pGainer->pNewGains[iChannel] * pGainer->masterVolume;
+ }
+
+ ma_copy_and_apply_volume_factor_per_channel_f32((float*)pFramesOut, (const float*)pFramesIn, frameCount, pGainer->config.channels, gains);
+ } else {
+ /* Slow path. Too many channels to fit on the stack. Need to apply a master volume as a separate path. */
+ for (iFrame = 0; iFrame < frameCount; iFrame += 1) {
+ for (iChannel = 0; iChannel < pGainer->config.channels; iChannel += 1) {
+ ((float*)pFramesOut)[iFrame*pGainer->config.channels + iChannel] = ((const float*)pFramesIn)[iFrame*pGainer->config.channels + iChannel] * pGainer->pNewGains[iChannel] * pGainer->masterVolume;
+ }
+ }
+ }
+ }
+
+ /* Now that some frames have been processed we need to make sure future changes to the gain are interpolated. */
+ if (pGainer->t == (ma_uint32)-1) {
+ pGainer->t = (ma_uint32)ma_min(pGainer->config.smoothTimeInFrames, frameCount);
+ }
+
+#if 0
if (pGainer->t >= pGainer->config.smoothTimeInFrames) {
/* Fast path. No gain calculation required. */
ma_copy_and_apply_volume_factor_per_channel_f32(pFramesOutF32, pFramesInF32, frameCount, pGainer->config.channels, pGainer->pNewGains);
+ ma_apply_volume_factor_f32(pFramesOutF32, frameCount * pGainer->config.channels, pGainer->masterVolume);
/* Now that some frames have been processed we need to make sure future changes to the gain are interpolated. */
if (pGainer->t == (ma_uint32)-1) {
@@ -47517,7 +48953,7 @@ MA_API ma_result ma_gainer_process_pcm_frames(ma_gainer* pGainer, void* pFramesO
for (iFrame = 0; iFrame < frameCount; iFrame += 1) {
for (iChannel = 0; iChannel < channelCount; iChannel += 1) {
- pFramesOutF32[iChannel] = pFramesInF32[iChannel] * ma_mix_f32_fast(pGainer->pOldGains[iChannel], pGainer->pNewGains[iChannel], a);
+ pFramesOutF32[iChannel] = pFramesInF32[iChannel] * ma_mix_f32_fast(pGainer->pOldGains[iChannel], pGainer->pNewGains[iChannel], a) * pGainer->masterVolume;
}
pFramesOutF32 += channelCount;
@@ -47537,7 +48973,7 @@ MA_API ma_result ma_gainer_process_pcm_frames(ma_gainer* pGainer, void* pFramesO
/* We can allow the input and output buffers to be null in which case we'll just update the internal timer. */
if (pFramesOut != NULL && pFramesIn != NULL) {
for (iChannel = 0; iChannel < pGainer->config.channels; iChannel += 1) {
- pFramesOutF32[iFrame*pGainer->config.channels + iChannel] = pFramesInF32[iFrame*pGainer->config.channels + iChannel] * ma_gainer_calculate_current_gain(pGainer, iChannel);
+ pFramesOutF32[iFrame * pGainer->config.channels + iChannel] = pFramesInF32[iFrame * pGainer->config.channels + iChannel] * ma_gainer_calculate_current_gain(pGainer, iChannel) * pGainer->masterVolume;
}
}
@@ -47546,10 +48982,24 @@ MA_API ma_result ma_gainer_process_pcm_frames(ma_gainer* pGainer, void* pFramesO
}
#endif
}
+#endif
return MA_SUCCESS;
}
+MA_API ma_result ma_gainer_process_pcm_frames(ma_gainer* pGainer, void* pFramesOut, const void* pFramesIn, ma_uint64 frameCount)
+{
+ if (pGainer == NULL) {
+ return MA_INVALID_ARGS;
+ }
+
+ /*
+ ma_gainer_process_pcm_frames_internal() marks pFramesOut and pFramesIn with MA_RESTRICT which
+ helps with auto-vectorization.
+ */
+ return ma_gainer_process_pcm_frames_internal(pGainer, pFramesOut, pFramesIn, frameCount);
+}
+
static void ma_gainer_set_gain_by_index(ma_gainer* pGainer, float newGain, ma_uint32 iChannel)
{
pGainer->pOldGains[iChannel] = ma_gainer_calculate_current_gain(pGainer, iChannel);
@@ -47601,6 +49051,28 @@ MA_API ma_result ma_gainer_set_gains(ma_gainer* pGainer, float* pNewGains)
return MA_SUCCESS;
}
+MA_API ma_result ma_gainer_set_master_volume(ma_gainer* pGainer, float volume)
+{
+ if (pGainer == NULL) {
+ return MA_INVALID_ARGS;
+ }
+
+ pGainer->masterVolume = volume;
+
+ return MA_SUCCESS;
+}
+
+MA_API ma_result ma_gainer_get_master_volume(const ma_gainer* pGainer, float* pVolume)
+{
+ if (pGainer == NULL || pVolume == NULL) {
+ return MA_INVALID_ARGS;
+ }
+
+ *pVolume = pGainer->masterVolume;
+
+ return MA_SUCCESS;
+}
+
MA_API ma_panner_config ma_panner_config_init(ma_format format, ma_uint32 channels)
{
@@ -47855,48 +49327,65 @@ MA_API ma_result ma_fader_process_pcm_frames(ma_fader* pFader, void* pFramesOut,
return MA_INVALID_ARGS;
}
- /*
- For now we need to clamp frameCount so that the cursor never overflows 32-bits. This is required for
- the conversion to a float which we use for the linear interpolation. This might be changed later.
- */
- if (frameCount + pFader->cursorInFrames > UINT_MAX) {
- frameCount = UINT_MAX - pFader->cursorInFrames;
+ /* If the cursor is still negative we need to just copy the absolute number of those frames, but no more than frameCount. */
+ if (pFader->cursorInFrames < 0) {
+ ma_uint64 absCursorInFrames = (ma_uint64)0 - pFader->cursorInFrames;
+ if (absCursorInFrames > frameCount) {
+ absCursorInFrames = frameCount;
+ }
+
+ ma_copy_pcm_frames(pFramesOut, pFramesIn, absCursorInFrames, pFader->config.format, pFader->config.channels);
+
+ pFader->cursorInFrames += absCursorInFrames;
+ frameCount -= absCursorInFrames;
+ pFramesOut = ma_offset_ptr(pFramesOut, ma_get_bytes_per_frame(pFader->config.format, pFader->config.channels)*absCursorInFrames);
+ pFramesIn = ma_offset_ptr(pFramesIn, ma_get_bytes_per_frame(pFader->config.format, pFader->config.channels)*absCursorInFrames);
}
- /* Optimized path if volumeBeg and volumeEnd are equal. */
- if (pFader->volumeBeg == pFader->volumeEnd) {
- if (pFader->volumeBeg == 1) {
- /* Straight copy. */
- ma_copy_pcm_frames(pFramesOut, pFramesIn, frameCount, pFader->config.format, pFader->config.channels);
- } else {
- /* Copy with volume. */
- ma_copy_and_apply_volume_and_clip_pcm_frames(pFramesOut, pFramesIn, frameCount, pFader->config.format, pFader->config.channels, pFader->volumeEnd);
+ if (pFader->cursorInFrames >= 0) {
+ /*
+ For now we need to clamp frameCount so that the cursor never overflows 32-bits. This is required for
+ the conversion to a float which we use for the linear interpolation. This might be changed later.
+ */
+ if (frameCount + pFader->cursorInFrames > UINT_MAX) {
+ frameCount = UINT_MAX - pFader->cursorInFrames;
}
- } else {
- /* Slower path. Volumes are different, so may need to do an interpolation. */
- if (pFader->cursorInFrames >= pFader->lengthInFrames) {
- /* Fast path. We've gone past the end of the fade period so just apply the end volume to all samples. */
- ma_copy_and_apply_volume_and_clip_pcm_frames(pFramesOut, pFramesIn, frameCount, pFader->config.format, pFader->config.channels, pFader->volumeEnd);
+
+ /* Optimized path if volumeBeg and volumeEnd are equal. */
+ if (pFader->volumeBeg == pFader->volumeEnd) {
+ if (pFader->volumeBeg == 1) {
+ /* Straight copy. */
+ ma_copy_pcm_frames(pFramesOut, pFramesIn, frameCount, pFader->config.format, pFader->config.channels);
+ } else {
+ /* Copy with volume. */
+ ma_copy_and_apply_volume_and_clip_pcm_frames(pFramesOut, pFramesIn, frameCount, pFader->config.format, pFader->config.channels, pFader->volumeBeg);
+ }
} else {
- /* Slow path. This is where we do the actual fading. */
- ma_uint64 iFrame;
- ma_uint32 iChannel;
+ /* Slower path. Volumes are different, so may need to do an interpolation. */
+ if ((ma_uint64)pFader->cursorInFrames >= pFader->lengthInFrames) {
+ /* Fast path. We've gone past the end of the fade period so just apply the end volume to all samples. */
+ ma_copy_and_apply_volume_and_clip_pcm_frames(pFramesOut, pFramesIn, frameCount, pFader->config.format, pFader->config.channels, pFader->volumeEnd);
+ } else {
+ /* Slow path. This is where we do the actual fading. */
+ ma_uint64 iFrame;
+ ma_uint32 iChannel;
- /* For now we only support f32. Support for other formats will be added later. */
- if (pFader->config.format == ma_format_f32) {
- const float* pFramesInF32 = (const float*)pFramesIn;
- /* */ float* pFramesOutF32 = ( float*)pFramesOut;
+ /* For now we only support f32. Support for other formats might be added later. */
+ if (pFader->config.format == ma_format_f32) {
+ const float* pFramesInF32 = (const float*)pFramesIn;
+ /* */ float* pFramesOutF32 = ( float*)pFramesOut;
- for (iFrame = 0; iFrame < frameCount; iFrame += 1) {
- float a = (ma_uint32)ma_min(pFader->cursorInFrames + iFrame, pFader->lengthInFrames) / (float)((ma_uint32)pFader->lengthInFrames); /* Safe cast due to the frameCount clamp at the top of this function. */
- float volume = ma_mix_f32_fast(pFader->volumeBeg, pFader->volumeEnd, a);
+ for (iFrame = 0; iFrame < frameCount; iFrame += 1) {
+ float a = (ma_uint32)ma_min(pFader->cursorInFrames + iFrame, pFader->lengthInFrames) / (float)((ma_uint32)pFader->lengthInFrames); /* Safe cast due to the frameCount clamp at the top of this function. */
+ float volume = ma_mix_f32_fast(pFader->volumeBeg, pFader->volumeEnd, a);
- for (iChannel = 0; iChannel < pFader->config.channels; iChannel += 1) {
- pFramesOutF32[iFrame*pFader->config.channels + iChannel] = pFramesInF32[iFrame*pFader->config.channels + iChannel] * volume;
+ for (iChannel = 0; iChannel < pFader->config.channels; iChannel += 1) {
+ pFramesOutF32[iFrame*pFader->config.channels + iChannel] = pFramesInF32[iFrame*pFader->config.channels + iChannel] * volume;
+ }
}
+ } else {
+ return MA_NOT_IMPLEMENTED;
}
- } else {
- return MA_NOT_IMPLEMENTED;
}
}
}
@@ -47926,6 +49415,11 @@ MA_API void ma_fader_get_data_format(const ma_fader* pFader, ma_format* pFormat,
}
MA_API void ma_fader_set_fade(ma_fader* pFader, float volumeBeg, float volumeEnd, ma_uint64 lengthInFrames)
+{
+ ma_fader_set_fade_ex(pFader, volumeBeg, volumeEnd, lengthInFrames, 0);
+}
+
+MA_API void ma_fader_set_fade_ex(ma_fader* pFader, float volumeBeg, float volumeEnd, ma_uint64 lengthInFrames, ma_int64 startOffsetInFrames)
{
if (pFader == NULL) {
return;
@@ -47944,22 +49438,32 @@ MA_API void ma_fader_set_fade(ma_fader* pFader, float volumeBeg, float volumeEnd
lengthInFrames = UINT_MAX;
}
+ /* The start offset needs to be clamped to ensure it doesn't overflow a signed number. */
+ if (startOffsetInFrames > INT_MAX) {
+ startOffsetInFrames = INT_MAX;
+ }
+
pFader->volumeBeg = volumeBeg;
pFader->volumeEnd = volumeEnd;
pFader->lengthInFrames = lengthInFrames;
- pFader->cursorInFrames = 0; /* Reset cursor. */
+ pFader->cursorInFrames = -startOffsetInFrames;
}
-MA_API float ma_fader_get_current_volume(ma_fader* pFader)
+MA_API float ma_fader_get_current_volume(const ma_fader* pFader)
{
if (pFader == NULL) {
return 0.0f;
}
+ /* Any frames prior to the start of the fade period will be at unfaded volume. */
+ if (pFader->cursorInFrames < 0) {
+ return 1.0f;
+ }
+
/* The current volume depends on the position of the cursor. */
if (pFader->cursorInFrames == 0) {
return pFader->volumeBeg;
- } else if (pFader->cursorInFrames >= pFader->lengthInFrames) {
+ } else if ((ma_uint64)pFader->cursorInFrames >= pFader->lengthInFrames) { /* Safe case because the < 0 case was checked above. */
return pFader->volumeEnd;
} else {
/* The cursor is somewhere inside the fading period. We can figure this out with a simple linear interpoluation between volumeBeg and volumeEnd based on our cursor position. */
@@ -48015,6 +49519,8 @@ MA_API float ma_vec3f_len(ma_vec3f v)
return (float)ma_sqrtd(ma_vec3f_len2(v));
}
+
+
MA_API float ma_vec3f_dist(ma_vec3f a, ma_vec3f b)
{
return ma_vec3f_len(ma_vec3f_sub(a, b));
@@ -48022,16 +49528,16 @@ MA_API float ma_vec3f_dist(ma_vec3f a, ma_vec3f b)
MA_API ma_vec3f ma_vec3f_normalize(ma_vec3f v)
{
- float f;
- float l = ma_vec3f_len(v);
- if (l == 0) {
+ float invLen;
+ float len2 = ma_vec3f_len2(v);
+ if (len2 == 0) {
return ma_vec3f_init_3f(0, 0, 0);
}
- f = 1 / l;
- v.x *= f;
- v.y *= f;
- v.z *= f;
+ invLen = ma_rsqrtf(len2);
+ v.x *= invLen;
+ v.y *= invLen;
+ v.z *= invLen;
return v;
}
@@ -48046,6 +49552,35 @@ MA_API ma_vec3f ma_vec3f_cross(ma_vec3f a, ma_vec3f b)
}
+MA_API void ma_atomic_vec3f_init(ma_atomic_vec3f* v, ma_vec3f value)
+{
+ v->v = value;
+ v->lock = 0; /* Important this is initialized to 0. */
+}
+
+MA_API void ma_atomic_vec3f_set(ma_atomic_vec3f* v, ma_vec3f value)
+{
+ ma_spinlock_lock(&v->lock);
+ {
+ v->v = value;
+ }
+ ma_spinlock_unlock(&v->lock);
+}
+
+MA_API ma_vec3f ma_atomic_vec3f_get(ma_atomic_vec3f* v)
+{
+ ma_vec3f r;
+
+ ma_spinlock_lock(&v->lock);
+ {
+ r = v->v;
+ }
+ ma_spinlock_unlock(&v->lock);
+
+ return r;
+}
+
+
static void ma_channel_map_apply_f32(float* pFramesOut, const ma_channel* pChannelMapOut, ma_uint32 channelsOut, const float* pFramesIn, const ma_channel* pChannelMapIn, ma_uint32 channelsIn, ma_uint64 frameCount, ma_channel_mix_mode mode, ma_mono_expansion_mode monoExpansionMode);
static ma_bool32 ma_is_spatial_channel_position(ma_channel channelPosition);
@@ -48296,14 +49831,15 @@ MA_API ma_result ma_spatializer_listener_init_preallocated(const ma_spatializer_
MA_ZERO_MEMORY(pHeap, heapLayout.sizeInBytes);
pListener->config = *pConfig;
- pListener->position = ma_vec3f_init_3f(0, 0, 0);
- pListener->direction = ma_vec3f_init_3f(0, 0, -1);
- pListener->velocity = ma_vec3f_init_3f(0, 0, 0);
+ ma_atomic_vec3f_init(&pListener->position, ma_vec3f_init_3f(0, 0, 0));
+ ma_atomic_vec3f_init(&pListener->direction, ma_vec3f_init_3f(0, 0, -1));
+ ma_atomic_vec3f_init(&pListener->velocity, ma_vec3f_init_3f(0, 0, 0));
pListener->isEnabled = MA_TRUE;
/* Swap the forward direction if we're left handed (it was initialized based on right handed). */
if (pListener->config.handedness == ma_handedness_left) {
- pListener->direction = ma_vec3f_neg(pListener->direction);
+ ma_vec3f negDir = ma_vec3f_neg(ma_spatializer_listener_get_direction(pListener));
+ ma_spatializer_listener_set_direction(pListener, negDir.x, negDir.y, negDir.z);
}
@@ -48406,7 +49942,7 @@ MA_API void ma_spatializer_listener_set_position(ma_spatializer_listener* pListe
return;
}
- pListener->position = ma_vec3f_init_3f(x, y, z);
+ ma_atomic_vec3f_set(&pListener->position, ma_vec3f_init_3f(x, y, z));
}
MA_API ma_vec3f ma_spatializer_listener_get_position(const ma_spatializer_listener* pListener)
@@ -48415,7 +49951,7 @@ MA_API ma_vec3f ma_spatializer_listener_get_position(const ma_spatializer_listen
return ma_vec3f_init_3f(0, 0, 0);
}
- return pListener->position;
+ return ma_atomic_vec3f_get((ma_atomic_vec3f*)&pListener->position); /* Naughty const-cast. It's just for atomically loading the vec3 which should be safe. */
}
MA_API void ma_spatializer_listener_set_direction(ma_spatializer_listener* pListener, float x, float y, float z)
@@ -48424,7 +49960,7 @@ MA_API void ma_spatializer_listener_set_direction(ma_spatializer_listener* pList
return;
}
- pListener->direction = ma_vec3f_init_3f(x, y, z);
+ ma_atomic_vec3f_set(&pListener->direction, ma_vec3f_init_3f(x, y, z));
}
MA_API ma_vec3f ma_spatializer_listener_get_direction(const ma_spatializer_listener* pListener)
@@ -48433,7 +49969,7 @@ MA_API ma_vec3f ma_spatializer_listener_get_direction(const ma_spatializer_liste
return ma_vec3f_init_3f(0, 0, -1);
}
- return pListener->direction;
+ return ma_atomic_vec3f_get((ma_atomic_vec3f*)&pListener->direction); /* Naughty const-cast. It's just for atomically loading the vec3 which should be safe. */
}
MA_API void ma_spatializer_listener_set_velocity(ma_spatializer_listener* pListener, float x, float y, float z)
@@ -48442,7 +49978,7 @@ MA_API void ma_spatializer_listener_set_velocity(ma_spatializer_listener* pListe
return;
}
- pListener->velocity = ma_vec3f_init_3f(x, y, z);
+ ma_atomic_vec3f_set(&pListener->velocity, ma_vec3f_init_3f(x, y, z));
}
MA_API ma_vec3f ma_spatializer_listener_get_velocity(const ma_spatializer_listener* pListener)
@@ -48451,7 +49987,7 @@ MA_API ma_vec3f ma_spatializer_listener_get_velocity(const ma_spatializer_listen
return ma_vec3f_init_3f(0, 0, 0);
}
- return pListener->velocity;
+ return ma_atomic_vec3f_get((ma_atomic_vec3f*)&pListener->velocity); /* Naughty const-cast. It's just for atomically loading the vec3 which should be safe. */
}
MA_API void ma_spatializer_listener_set_speed_of_sound(ma_spatializer_listener* pListener, float speedOfSound)
@@ -48532,6 +50068,7 @@ MA_API ma_spatializer_config ma_spatializer_config_init(ma_uint32 channelsIn, ma
config.coneOuterGain = 0.0f;
config.dopplerFactor = 1;
config.directionalAttenuationFactor = 1;
+ config.minSpatializationChannelGain = 0.2f;
config.gainSmoothTimeInFrames = 360; /* 7.5ms @ 48K. */
return config;
@@ -48672,16 +50209,18 @@ MA_API ma_result ma_spatializer_init_preallocated(const ma_spatializer_config* p
pSpatializer->coneOuterAngleInRadians = pConfig->coneOuterAngleInRadians;
pSpatializer->coneOuterGain = pConfig->coneOuterGain;
pSpatializer->dopplerFactor = pConfig->dopplerFactor;
+ pSpatializer->minSpatializationChannelGain = pConfig->minSpatializationChannelGain;
pSpatializer->directionalAttenuationFactor = pConfig->directionalAttenuationFactor;
pSpatializer->gainSmoothTimeInFrames = pConfig->gainSmoothTimeInFrames;
- pSpatializer->position = ma_vec3f_init_3f(0, 0, 0);
- pSpatializer->direction = ma_vec3f_init_3f(0, 0, -1);
- pSpatializer->velocity = ma_vec3f_init_3f(0, 0, 0);
+ ma_atomic_vec3f_init(&pSpatializer->position, ma_vec3f_init_3f(0, 0, 0));
+ ma_atomic_vec3f_init(&pSpatializer->direction, ma_vec3f_init_3f(0, 0, -1));
+ ma_atomic_vec3f_init(&pSpatializer->velocity, ma_vec3f_init_3f(0, 0, 0));
pSpatializer->dopplerPitch = 1;
/* Swap the forward direction if we're left handed (it was initialized based on right handed). */
if (pSpatializer->handedness == ma_handedness_left) {
- pSpatializer->direction = ma_vec3f_neg(pSpatializer->direction);
+ ma_vec3f negDir = ma_vec3f_neg(ma_spatializer_get_direction(pSpatializer));
+ ma_spatializer_set_direction(pSpatializer, negDir.x, negDir.y, negDir.z);
}
/* Channel map. This will be on the heap. */
@@ -48802,7 +50341,7 @@ MA_API ma_result ma_spatializer_process_pcm_frames(ma_spatializer* pSpatializer,
}
/* If we're not spatializing we need to run an optimized path. */
- if (c89atomic_load_i32(&pSpatializer->attenuationModel) == ma_attenuation_model_none) {
+ if (ma_atomic_load_i32(&pSpatializer->attenuationModel) == ma_attenuation_model_none) {
if (ma_spatializer_listener_is_enabled(pListener)) {
/* No attenuation is required, but we'll need to do some channel conversion. */
if (pSpatializer->channelsIn == pSpatializer->channelsOut) {
@@ -48846,7 +50385,7 @@ MA_API ma_result ma_spatializer_process_pcm_frames(ma_spatializer* pSpatializer,
defined by the listener, so we'll grab that here too.
*/
if (pListener != NULL) {
- listenerVel = pListener->velocity;
+ listenerVel = ma_spatializer_listener_get_velocity(pListener);
speedOfSound = pListener->config.speedOfSound;
} else {
listenerVel = ma_vec3f_init_3f(0, 0, 0);
@@ -48855,8 +50394,8 @@ MA_API ma_result ma_spatializer_process_pcm_frames(ma_spatializer* pSpatializer,
if (pListener == NULL || ma_spatializer_get_positioning(pSpatializer) == ma_positioning_relative) {
/* There's no listener or we're using relative positioning. */
- relativePos = pSpatializer->position;
- relativeDir = pSpatializer->direction;
+ relativePos = ma_spatializer_get_position(pSpatializer);
+ relativeDir = ma_spatializer_get_direction(pSpatializer);
} else {
/*
We've found a listener and we're using absolute positioning. We need to transform the
@@ -48952,6 +50491,26 @@ MA_API ma_result ma_spatializer_process_pcm_frames(ma_spatializer* pSpatializer,
/* Clamp the gain. */
gain = ma_clamp(gain, ma_spatializer_get_min_gain(pSpatializer), ma_spatializer_get_max_gain(pSpatializer));
+ /*
+ The gain needs to be applied per-channel here. The spatialization code below will be changing the per-channel
+ gains which will then eventually be passed into the gainer which will deal with smoothing the gain transitions
+ to avoid harsh changes in gain.
+ */
+ for (iChannel = 0; iChannel < channelsOut; iChannel += 1) {
+ pSpatializer->pNewChannelGainsOut[iChannel] = gain;
+ }
+
+ /*
+ Convert to our output channel count. If the listener is disabled we just output silence here. We cannot ignore
+ the whole section of code here because we need to update some internal spatialization state.
+ */
+ if (ma_spatializer_listener_is_enabled(pListener)) {
+ ma_channel_map_apply_f32((float*)pFramesOut, pChannelMapOut, channelsOut, (const float*)pFramesIn, pChannelMapIn, channelsIn, frameCount, ma_channel_mix_mode_rectangular, ma_mono_expansion_mode_default);
+ } else {
+ ma_silence_pcm_frames(pFramesOut, frameCount, ma_format_f32, pSpatializer->channelsOut);
+ }
+
+
/*
Panning. This is where we'll apply the gain and convert to the output channel count. We have an optimized path for
when we're converting to a mono stream. In that case we don't really need to do any panning - we just apply the
@@ -48973,19 +50532,6 @@ MA_API ma_result ma_spatializer_process_pcm_frames(ma_spatializer* pSpatializer,
be +1 on the X axis. A dot product is performed against the direction vector of the channel and the normalized
position of the sound.
*/
- for (iChannel = 0; iChannel < channelsOut; iChannel += 1) {
- pSpatializer->pNewChannelGainsOut[iChannel] = gain;
- }
-
- /*
- Convert to our output channel count. If the listener is disabled we just output silence here. We cannot ignore
- the whole section of code here because we need to update some internal spatialization state.
- */
- if (ma_spatializer_listener_is_enabled(pListener)) {
- ma_channel_map_apply_f32((float*)pFramesOut, pChannelMapOut, channelsOut, (const float*)pFramesIn, pChannelMapIn, channelsIn, frameCount, ma_channel_mix_mode_rectangular, ma_mono_expansion_mode_default);
- } else {
- ma_silence_pcm_frames(pFramesOut, frameCount, ma_format_f32, pSpatializer->channelsOut);
- }
/*
Calculate our per-channel gains. We do this based on the normalized relative position of the sound and it's
@@ -49016,13 +50562,13 @@ MA_API ma_result ma_spatializer_process_pcm_frames(ma_spatializer* pSpatializer,
0, panning will be most extreme and any sounds that are positioned on the opposite side of the
speaker will be completely silent from that speaker. Not only does this feel uncomfortable, it
doesn't even remotely represent the real world at all because sounds that come from your right side
- are still clearly audible from your left side. Setting "dMin" to 1 will result in no panning at
+ are still clearly audible from your left side. Setting "dMin" to 1 will result in no panning at
all, which is also not ideal. By setting it to something greater than 0, the spatialization effect
becomes much less dramatic and a lot more bearable.
Summary: 0 = more extreme panning; 1 = no panning.
*/
- dMin = 0.2f; /* TODO: Consider making this configurable. */
+ dMin = pSpatializer->minSpatializationChannelGain;
/*
At this point, "d" will be positive if the sound is on the same side as the channel and negative if
@@ -49085,7 +50631,7 @@ MA_API ma_result ma_spatializer_process_pcm_frames(ma_spatializer* pSpatializer,
source.
*/
if (dopplerFactor > 0) {
- pSpatializer->dopplerPitch = ma_doppler_pitch(ma_vec3f_sub(pListener->position, pSpatializer->position), pSpatializer->velocity, listenerVel, speedOfSound, dopplerFactor);
+ pSpatializer->dopplerPitch = ma_doppler_pitch(ma_vec3f_sub(ma_spatializer_listener_get_position(pListener), ma_spatializer_get_position(pSpatializer)), ma_spatializer_get_velocity(pSpatializer), listenerVel, speedOfSound, dopplerFactor);
} else {
pSpatializer->dopplerPitch = 1;
}
@@ -49094,6 +50640,24 @@ MA_API ma_result ma_spatializer_process_pcm_frames(ma_spatializer* pSpatializer,
return MA_SUCCESS;
}
+MA_API ma_result ma_spatializer_set_master_volume(ma_spatializer* pSpatializer, float volume)
+{
+ if (pSpatializer == NULL) {
+ return MA_INVALID_ARGS;
+ }
+
+ return ma_gainer_set_master_volume(&pSpatializer->gainer, volume);
+}
+
+MA_API ma_result ma_spatializer_get_master_volume(const ma_spatializer* pSpatializer, float* pVolume)
+{
+ if (pSpatializer == NULL) {
+ return MA_INVALID_ARGS;
+ }
+
+ return ma_gainer_get_master_volume(&pSpatializer->gainer, pVolume);
+}
+
MA_API ma_uint32 ma_spatializer_get_input_channels(const ma_spatializer* pSpatializer)
{
if (pSpatializer == NULL) {
@@ -49118,7 +50682,7 @@ MA_API void ma_spatializer_set_attenuation_model(ma_spatializer* pSpatializer, m
return;
}
- c89atomic_exchange_i32(&pSpatializer->attenuationModel, attenuationModel);
+ ma_atomic_exchange_i32(&pSpatializer->attenuationModel, attenuationModel);
}
MA_API ma_attenuation_model ma_spatializer_get_attenuation_model(const ma_spatializer* pSpatializer)
@@ -49127,7 +50691,7 @@ MA_API ma_attenuation_model ma_spatializer_get_attenuation_model(const ma_spatia
return ma_attenuation_model_none;
}
- return (ma_attenuation_model)c89atomic_load_i32(&pSpatializer->attenuationModel);
+ return (ma_attenuation_model)ma_atomic_load_i32(&pSpatializer->attenuationModel);
}
MA_API void ma_spatializer_set_positioning(ma_spatializer* pSpatializer, ma_positioning positioning)
@@ -49136,7 +50700,7 @@ MA_API void ma_spatializer_set_positioning(ma_spatializer* pSpatializer, ma_posi
return;
}
- c89atomic_exchange_i32(&pSpatializer->positioning, positioning);
+ ma_atomic_exchange_i32(&pSpatializer->positioning, positioning);
}
MA_API ma_positioning ma_spatializer_get_positioning(const ma_spatializer* pSpatializer)
@@ -49145,7 +50709,7 @@ MA_API ma_positioning ma_spatializer_get_positioning(const ma_spatializer* pSpat
return ma_positioning_absolute;
}
- return (ma_positioning)c89atomic_load_i32(&pSpatializer->positioning);
+ return (ma_positioning)ma_atomic_load_i32(&pSpatializer->positioning);
}
MA_API void ma_spatializer_set_rolloff(ma_spatializer* pSpatializer, float rolloff)
@@ -49154,7 +50718,7 @@ MA_API void ma_spatializer_set_rolloff(ma_spatializer* pSpatializer, float rollo
return;
}
- c89atomic_exchange_f32(&pSpatializer->rolloff, rolloff);
+ ma_atomic_exchange_f32(&pSpatializer->rolloff, rolloff);
}
MA_API float ma_spatializer_get_rolloff(const ma_spatializer* pSpatializer)
@@ -49163,7 +50727,7 @@ MA_API float ma_spatializer_get_rolloff(const ma_spatializer* pSpatializer)
return 0;
}
- return c89atomic_load_f32(&pSpatializer->rolloff);
+ return ma_atomic_load_f32(&pSpatializer->rolloff);
}
MA_API void ma_spatializer_set_min_gain(ma_spatializer* pSpatializer, float minGain)
@@ -49172,7 +50736,7 @@ MA_API void ma_spatializer_set_min_gain(ma_spatializer* pSpatializer, float minG
return;
}
- c89atomic_exchange_f32(&pSpatializer->minGain, minGain);
+ ma_atomic_exchange_f32(&pSpatializer->minGain, minGain);
}
MA_API float ma_spatializer_get_min_gain(const ma_spatializer* pSpatializer)
@@ -49181,7 +50745,7 @@ MA_API float ma_spatializer_get_min_gain(const ma_spatializer* pSpatializer)
return 0;
}
- return c89atomic_load_f32(&pSpatializer->minGain);
+ return ma_atomic_load_f32(&pSpatializer->minGain);
}
MA_API void ma_spatializer_set_max_gain(ma_spatializer* pSpatializer, float maxGain)
@@ -49190,7 +50754,7 @@ MA_API void ma_spatializer_set_max_gain(ma_spatializer* pSpatializer, float maxG
return;
}
- c89atomic_exchange_f32(&pSpatializer->maxGain, maxGain);
+ ma_atomic_exchange_f32(&pSpatializer->maxGain, maxGain);
}
MA_API float ma_spatializer_get_max_gain(const ma_spatializer* pSpatializer)
@@ -49199,7 +50763,7 @@ MA_API float ma_spatializer_get_max_gain(const ma_spatializer* pSpatializer)
return 0;
}
- return c89atomic_load_f32(&pSpatializer->maxGain);
+ return ma_atomic_load_f32(&pSpatializer->maxGain);
}
MA_API void ma_spatializer_set_min_distance(ma_spatializer* pSpatializer, float minDistance)
@@ -49208,7 +50772,7 @@ MA_API void ma_spatializer_set_min_distance(ma_spatializer* pSpatializer, float
return;
}
- c89atomic_exchange_f32(&pSpatializer->minDistance, minDistance);
+ ma_atomic_exchange_f32(&pSpatializer->minDistance, minDistance);
}
MA_API float ma_spatializer_get_min_distance(const ma_spatializer* pSpatializer)
@@ -49217,7 +50781,7 @@ MA_API float ma_spatializer_get_min_distance(const ma_spatializer* pSpatializer)
return 0;
}
- return c89atomic_load_f32(&pSpatializer->minDistance);
+ return ma_atomic_load_f32(&pSpatializer->minDistance);
}
MA_API void ma_spatializer_set_max_distance(ma_spatializer* pSpatializer, float maxDistance)
@@ -49226,7 +50790,7 @@ MA_API void ma_spatializer_set_max_distance(ma_spatializer* pSpatializer, float
return;
}
- c89atomic_exchange_f32(&pSpatializer->maxDistance, maxDistance);
+ ma_atomic_exchange_f32(&pSpatializer->maxDistance, maxDistance);
}
MA_API float ma_spatializer_get_max_distance(const ma_spatializer* pSpatializer)
@@ -49235,7 +50799,7 @@ MA_API float ma_spatializer_get_max_distance(const ma_spatializer* pSpatializer)
return 0;
}
- return c89atomic_load_f32(&pSpatializer->maxDistance);
+ return ma_atomic_load_f32(&pSpatializer->maxDistance);
}
MA_API void ma_spatializer_set_cone(ma_spatializer* pSpatializer, float innerAngleInRadians, float outerAngleInRadians, float outerGain)
@@ -49244,9 +50808,9 @@ MA_API void ma_spatializer_set_cone(ma_spatializer* pSpatializer, float innerAng
return;
}
- c89atomic_exchange_f32(&pSpatializer->coneInnerAngleInRadians, innerAngleInRadians);
- c89atomic_exchange_f32(&pSpatializer->coneOuterAngleInRadians, outerAngleInRadians);
- c89atomic_exchange_f32(&pSpatializer->coneOuterGain, outerGain);
+ ma_atomic_exchange_f32(&pSpatializer->coneInnerAngleInRadians, innerAngleInRadians);
+ ma_atomic_exchange_f32(&pSpatializer->coneOuterAngleInRadians, outerAngleInRadians);
+ ma_atomic_exchange_f32(&pSpatializer->coneOuterGain, outerGain);
}
MA_API void ma_spatializer_get_cone(const ma_spatializer* pSpatializer, float* pInnerAngleInRadians, float* pOuterAngleInRadians, float* pOuterGain)
@@ -49256,15 +50820,15 @@ MA_API void ma_spatializer_get_cone(const ma_spatializer* pSpatializer, float* p
}
if (pInnerAngleInRadians != NULL) {
- *pInnerAngleInRadians = c89atomic_load_f32(&pSpatializer->coneInnerAngleInRadians);
+ *pInnerAngleInRadians = ma_atomic_load_f32(&pSpatializer->coneInnerAngleInRadians);
}
if (pOuterAngleInRadians != NULL) {
- *pOuterAngleInRadians = c89atomic_load_f32(&pSpatializer->coneOuterAngleInRadians);
+ *pOuterAngleInRadians = ma_atomic_load_f32(&pSpatializer->coneOuterAngleInRadians);
}
if (pOuterGain != NULL) {
- *pOuterGain = c89atomic_load_f32(&pSpatializer->coneOuterGain);
+ *pOuterGain = ma_atomic_load_f32(&pSpatializer->coneOuterGain);
}
}
@@ -49274,7 +50838,7 @@ MA_API void ma_spatializer_set_doppler_factor(ma_spatializer* pSpatializer, floa
return;
}
- c89atomic_exchange_f32(&pSpatializer->dopplerFactor, dopplerFactor);
+ ma_atomic_exchange_f32(&pSpatializer->dopplerFactor, dopplerFactor);
}
MA_API float ma_spatializer_get_doppler_factor(const ma_spatializer* pSpatializer)
@@ -49283,7 +50847,7 @@ MA_API float ma_spatializer_get_doppler_factor(const ma_spatializer* pSpatialize
return 1;
}
- return c89atomic_load_f32(&pSpatializer->dopplerFactor);
+ return ma_atomic_load_f32(&pSpatializer->dopplerFactor);
}
MA_API void ma_spatializer_set_directional_attenuation_factor(ma_spatializer* pSpatializer, float directionalAttenuationFactor)
@@ -49292,7 +50856,7 @@ MA_API void ma_spatializer_set_directional_attenuation_factor(ma_spatializer* pS
return;
}
- c89atomic_exchange_f32(&pSpatializer->directionalAttenuationFactor, directionalAttenuationFactor);
+ ma_atomic_exchange_f32(&pSpatializer->directionalAttenuationFactor, directionalAttenuationFactor);
}
MA_API float ma_spatializer_get_directional_attenuation_factor(const ma_spatializer* pSpatializer)
@@ -49301,7 +50865,7 @@ MA_API float ma_spatializer_get_directional_attenuation_factor(const ma_spatiali
return 1;
}
- return c89atomic_load_f32(&pSpatializer->directionalAttenuationFactor);
+ return ma_atomic_load_f32(&pSpatializer->directionalAttenuationFactor);
}
MA_API void ma_spatializer_set_position(ma_spatializer* pSpatializer, float x, float y, float z)
@@ -49310,7 +50874,7 @@ MA_API void ma_spatializer_set_position(ma_spatializer* pSpatializer, float x, f
return;
}
- pSpatializer->position = ma_vec3f_init_3f(x, y, z);
+ ma_atomic_vec3f_set(&pSpatializer->position, ma_vec3f_init_3f(x, y, z));
}
MA_API ma_vec3f ma_spatializer_get_position(const ma_spatializer* pSpatializer)
@@ -49319,7 +50883,7 @@ MA_API ma_vec3f ma_spatializer_get_position(const ma_spatializer* pSpatializer)
return ma_vec3f_init_3f(0, 0, 0);
}
- return pSpatializer->position;
+ return ma_atomic_vec3f_get((ma_atomic_vec3f*)&pSpatializer->position); /* Naughty const-cast. It's just for atomically loading the vec3 which should be safe. */
}
MA_API void ma_spatializer_set_direction(ma_spatializer* pSpatializer, float x, float y, float z)
@@ -49328,7 +50892,7 @@ MA_API void ma_spatializer_set_direction(ma_spatializer* pSpatializer, float x,
return;
}
- pSpatializer->direction = ma_vec3f_init_3f(x, y, z);
+ ma_atomic_vec3f_set(&pSpatializer->direction, ma_vec3f_init_3f(x, y, z));
}
MA_API ma_vec3f ma_spatializer_get_direction(const ma_spatializer* pSpatializer)
@@ -49337,7 +50901,7 @@ MA_API ma_vec3f ma_spatializer_get_direction(const ma_spatializer* pSpatializer)
return ma_vec3f_init_3f(0, 0, -1);
}
- return pSpatializer->direction;
+ return ma_atomic_vec3f_get((ma_atomic_vec3f*)&pSpatializer->direction); /* Naughty const-cast. It's just for atomically loading the vec3 which should be safe. */
}
MA_API void ma_spatializer_set_velocity(ma_spatializer* pSpatializer, float x, float y, float z)
@@ -49346,7 +50910,7 @@ MA_API void ma_spatializer_set_velocity(ma_spatializer* pSpatializer, float x, f
return;
}
- pSpatializer->velocity = ma_vec3f_init_3f(x, y, z);
+ ma_atomic_vec3f_set(&pSpatializer->velocity, ma_vec3f_init_3f(x, y, z));
}
MA_API ma_vec3f ma_spatializer_get_velocity(const ma_spatializer* pSpatializer)
@@ -49355,7 +50919,7 @@ MA_API ma_vec3f ma_spatializer_get_velocity(const ma_spatializer* pSpatializer)
return ma_vec3f_init_3f(0, 0, 0);
}
- return pSpatializer->velocity;
+ return ma_atomic_vec3f_get((ma_atomic_vec3f*)&pSpatializer->velocity); /* Naughty const-cast. It's just for atomically loading the vec3 which should be safe. */
}
MA_API void ma_spatializer_get_relative_position_and_direction(const ma_spatializer* pSpatializer, const ma_spatializer_listener* pListener, ma_vec3f* pRelativePos, ma_vec3f* pRelativeDir)
@@ -49379,23 +50943,32 @@ MA_API void ma_spatializer_get_relative_position_and_direction(const ma_spatiali
if (pListener == NULL || ma_spatializer_get_positioning(pSpatializer) == ma_positioning_relative) {
/* There's no listener or we're using relative positioning. */
if (pRelativePos != NULL) {
- *pRelativePos = pSpatializer->position;
+ *pRelativePos = ma_spatializer_get_position(pSpatializer);
}
if (pRelativeDir != NULL) {
- *pRelativeDir = pSpatializer->direction;
+ *pRelativeDir = ma_spatializer_get_direction(pSpatializer);
}
} else {
+ ma_vec3f spatializerPosition;
+ ma_vec3f spatializerDirection;
+ ma_vec3f listenerPosition;
+ ma_vec3f listenerDirection;
ma_vec3f v;
ma_vec3f axisX;
ma_vec3f axisY;
ma_vec3f axisZ;
float m[4][4];
+ spatializerPosition = ma_spatializer_get_position(pSpatializer);
+ spatializerDirection = ma_spatializer_get_direction(pSpatializer);
+ listenerPosition = ma_spatializer_listener_get_position(pListener);
+ listenerDirection = ma_spatializer_listener_get_direction(pListener);
+
/*
We need to calcualte the right vector from our forward and up vectors. This is done with
a cross product.
*/
- axisZ = ma_vec3f_normalize(pListener->direction); /* Normalization required here because we can't trust the caller. */
+ axisZ = ma_vec3f_normalize(listenerDirection); /* Normalization required here because we can't trust the caller. */
axisX = ma_vec3f_normalize(ma_vec3f_cross(axisZ, pListener->config.worldUp)); /* Normalization required here because the world up vector may not be perpendicular with the forward vector. */
/*
@@ -49420,9 +50993,9 @@ MA_API void ma_spatializer_get_relative_position_and_direction(const ma_spatiali
}
/* Lookat. */
- m[0][0] = axisX.x; m[1][0] = axisX.y; m[2][0] = axisX.z; m[3][0] = -ma_vec3f_dot(axisX, pListener->position);
- m[0][1] = axisY.x; m[1][1] = axisY.y; m[2][1] = axisY.z; m[3][1] = -ma_vec3f_dot(axisY, pListener->position);
- m[0][2] = -axisZ.x; m[1][2] = -axisZ.y; m[2][2] = -axisZ.z; m[3][2] = -ma_vec3f_dot(ma_vec3f_neg(axisZ), pListener->position);
+ m[0][0] = axisX.x; m[1][0] = axisX.y; m[2][0] = axisX.z; m[3][0] = -ma_vec3f_dot(axisX, listenerPosition);
+ m[0][1] = axisY.x; m[1][1] = axisY.y; m[2][1] = axisY.z; m[3][1] = -ma_vec3f_dot(axisY, listenerPosition);
+ m[0][2] = -axisZ.x; m[1][2] = -axisZ.y; m[2][2] = -axisZ.z; m[3][2] = -ma_vec3f_dot(ma_vec3f_neg(axisZ), listenerPosition);
m[0][3] = 0; m[1][3] = 0; m[2][3] = 0; m[3][3] = 1;
/*
@@ -49431,7 +51004,7 @@ MA_API void ma_spatializer_get_relative_position_and_direction(const ma_spatiali
origin which makes things simpler.
*/
if (pRelativePos != NULL) {
- v = pSpatializer->position;
+ v = spatializerPosition;
pRelativePos->x = m[0][0] * v.x + m[1][0] * v.y + m[2][0] * v.z + m[3][0] * 1;
pRelativePos->y = m[0][1] * v.x + m[1][1] * v.y + m[2][1] * v.z + m[3][1] * 1;
pRelativePos->z = m[0][2] * v.x + m[1][2] * v.y + m[2][2] * v.z + m[3][2] * 1;
@@ -49442,7 +51015,7 @@ MA_API void ma_spatializer_get_relative_position_and_direction(const ma_spatiali
rotation of the listener.
*/
if (pRelativeDir != NULL) {
- v = pSpatializer->direction;
+ v = spatializerDirection;
pRelativeDir->x = m[0][0] * v.x + m[1][0] * v.y + m[2][0] * v.z;
pRelativeDir->y = m[0][1] * v.x + m[1][1] * v.y + m[2][1] * v.z;
pRelativeDir->z = m[0][2] * v.x + m[1][2] * v.y + m[2][2] * v.z;
@@ -49814,8 +51387,10 @@ static ma_result ma_linear_resampler_process_pcm_frames_s16_downsample(ma_linear
}
}
- /* Filter. */
- ma_lpf_process_pcm_frame_s16(&pResampler->lpf, pResampler->x1.s16, pResampler->x1.s16);
+ /* Filter. Do not apply filtering if sample rates are the same or else you'll get dangerous glitching. */
+ if (pResampler->config.sampleRateIn != pResampler->config.sampleRateOut) {
+ ma_lpf_process_pcm_frame_s16(&pResampler->lpf, pResampler->x1.s16, pResampler->x1.s16);
+ }
framesProcessedIn += 1;
pResampler->inTimeInt -= 1;
@@ -49901,8 +51476,10 @@ static ma_result ma_linear_resampler_process_pcm_frames_s16_upsample(ma_linear_r
MA_ASSERT(pResampler->inTimeInt == 0);
ma_linear_resampler_interpolate_frame_s16(pResampler, pFramesOutS16);
- /* Filter. */
- ma_lpf_process_pcm_frame_s16(&pResampler->lpf, pFramesOutS16, pFramesOutS16);
+ /* Filter. Do not apply filtering if sample rates are the same or else you'll get dangerous glitching. */
+ if (pResampler->config.sampleRateIn != pResampler->config.sampleRateOut) {
+ ma_lpf_process_pcm_frame_s16(&pResampler->lpf, pFramesOutS16, pFramesOutS16);
+ }
pFramesOutS16 += pResampler->config.channels;
}
@@ -49974,8 +51551,10 @@ static ma_result ma_linear_resampler_process_pcm_frames_f32_downsample(ma_linear
}
}
- /* Filter. */
- ma_lpf_process_pcm_frame_f32(&pResampler->lpf, pResampler->x1.f32, pResampler->x1.f32);
+ /* Filter. Do not apply filtering if sample rates are the same or else you'll get dangerous glitching. */
+ if (pResampler->config.sampleRateIn != pResampler->config.sampleRateOut) {
+ ma_lpf_process_pcm_frame_f32(&pResampler->lpf, pResampler->x1.f32, pResampler->x1.f32);
+ }
framesProcessedIn += 1;
pResampler->inTimeInt -= 1;
@@ -50061,8 +51640,10 @@ static ma_result ma_linear_resampler_process_pcm_frames_f32_upsample(ma_linear_r
MA_ASSERT(pResampler->inTimeInt == 0);
ma_linear_resampler_interpolate_frame_f32(pResampler, pFramesOutF32);
- /* Filter. */
- ma_lpf_process_pcm_frame_f32(&pResampler->lpf, pFramesOutF32, pFramesOutF32);
+ /* Filter. Do not apply filtering if sample rates are the same or else you'll get dangerous glitching. */
+ if (pResampler->config.sampleRateIn != pResampler->config.sampleRateOut) {
+ ma_lpf_process_pcm_frame_f32(&pResampler->lpf, pFramesOutF32, pFramesOutF32);
+ }
pFramesOutF32 += pResampler->config.channels;
}
@@ -50132,7 +51713,7 @@ MA_API ma_result ma_linear_resampler_set_rate_ratio(ma_linear_resampler* pResamp
return MA_INVALID_ARGS;
}
- d = 1000;
+ d = 1000000;
n = (ma_uint32)(ratioInOut * d);
if (n == 0) {
@@ -51182,7 +52763,7 @@ static ma_result ma_channel_map_apply_mono_out_f32(float* pFramesOut, const floa
return MA_SUCCESS;
}
-static ma_result ma_channel_map_apply_mono_in_f32(float* pFramesOut, const ma_channel* pChannelMapOut, ma_uint32 channelsOut, const float* pFramesIn, ma_uint64 frameCount, ma_mono_expansion_mode monoExpansionMode)
+static ma_result ma_channel_map_apply_mono_in_f32(float* MA_RESTRICT pFramesOut, const ma_channel* pChannelMapOut, ma_uint32 channelsOut, const float* MA_RESTRICT pFramesIn, ma_uint64 frameCount, ma_mono_expansion_mode monoExpansionMode)
{
ma_uint64 iFrame;
ma_uint32 iChannelOut;
@@ -51287,16 +52868,123 @@ static ma_result ma_channel_map_apply_mono_in_f32(float* pFramesOut, const ma_ch
{
default_handler:
{
- for (iFrame = 0; iFrame < frameCount; iFrame += 1) {
+ if (channelsOut <= MA_MAX_CHANNELS) {
+ ma_bool32 hasEmptyChannel = MA_FALSE;
+ ma_channel channelPositions[MA_MAX_CHANNELS];
for (iChannelOut = 0; iChannelOut < channelsOut; iChannelOut += 1) {
- ma_channel channelOut = ma_channel_map_get_channel(pChannelMapOut, channelsOut, iChannelOut);
- if (channelOut != MA_CHANNEL_NONE) {
- pFramesOut[iChannelOut] = pFramesIn[0];
+ channelPositions[iChannelOut] = ma_channel_map_get_channel(pChannelMapOut, channelsOut, iChannelOut);
+ if (channelPositions[iChannelOut] == MA_CHANNEL_NONE) {
+ hasEmptyChannel = MA_TRUE;
}
}
- pFramesOut += channelsOut;
- pFramesIn += 1;
+ if (hasEmptyChannel == MA_FALSE) {
+ /*
+ Faster path when there's no MA_CHANNEL_NONE channel positions. This should hopefully
+ help the compiler with auto-vectorization.m
+ */
+ if (channelsOut == 2) {
+ #if defined(MA_SUPPORT_SSE2)
+ if (ma_has_sse2()) {
+ /* We want to do two frames in each iteration. */
+ ma_uint64 unrolledFrameCount = frameCount >> 1;
+
+ for (iFrame = 0; iFrame < unrolledFrameCount; iFrame += 1) {
+ __m128 in0 = _mm_set1_ps(pFramesIn[iFrame*2 + 0]);
+ __m128 in1 = _mm_set1_ps(pFramesIn[iFrame*2 + 1]);
+ _mm_storeu_ps(&pFramesOut[iFrame*4 + 0], _mm_shuffle_ps(in0, in1, _MM_SHUFFLE(0, 0, 0, 0)));
+ }
+
+ /* Tail. */
+ iFrame = unrolledFrameCount << 1;
+ goto generic_on_fastpath;
+ } else
+ #endif
+ {
+ for (iFrame = 0; iFrame < frameCount; iFrame += 1) {
+ for (iChannelOut = 0; iChannelOut < 2; iChannelOut += 1) {
+ pFramesOut[iFrame*2 + iChannelOut] = pFramesIn[iFrame];
+ }
+ }
+ }
+ } else if (channelsOut == 6) {
+ #if defined(MA_SUPPORT_SSE2)
+ if (ma_has_sse2()) {
+ /* We want to do two frames in each iteration so we can have a multiple of 4 samples. */
+ ma_uint64 unrolledFrameCount = frameCount >> 1;
+
+ for (iFrame = 0; iFrame < unrolledFrameCount; iFrame += 1) {
+ __m128 in0 = _mm_set1_ps(pFramesIn[iFrame*2 + 0]);
+ __m128 in1 = _mm_set1_ps(pFramesIn[iFrame*2 + 1]);
+
+ _mm_storeu_ps(&pFramesOut[iFrame*12 + 0], in0);
+ _mm_storeu_ps(&pFramesOut[iFrame*12 + 4], _mm_shuffle_ps(in0, in1, _MM_SHUFFLE(0, 0, 0, 0)));
+ _mm_storeu_ps(&pFramesOut[iFrame*12 + 8], in1);
+ }
+
+ /* Tail. */
+ iFrame = unrolledFrameCount << 1;
+ goto generic_on_fastpath;
+ } else
+ #endif
+ {
+ for (iFrame = 0; iFrame < frameCount; iFrame += 1) {
+ for (iChannelOut = 0; iChannelOut < 6; iChannelOut += 1) {
+ pFramesOut[iFrame*6 + iChannelOut] = pFramesIn[iFrame];
+ }
+ }
+ }
+ } else if (channelsOut == 8) {
+ #if defined(MA_SUPPORT_SSE2)
+ if (ma_has_sse2()) {
+ for (iFrame = 0; iFrame < frameCount; iFrame += 1) {
+ __m128 in = _mm_set1_ps(pFramesIn[iFrame]);
+ _mm_storeu_ps(&pFramesOut[iFrame*8 + 0], in);
+ _mm_storeu_ps(&pFramesOut[iFrame*8 + 4], in);
+ }
+ } else
+ #endif
+ {
+ for (iFrame = 0; iFrame < frameCount; iFrame += 1) {
+ for (iChannelOut = 0; iChannelOut < 8; iChannelOut += 1) {
+ pFramesOut[iFrame*8 + iChannelOut] = pFramesIn[iFrame];
+ }
+ }
+ }
+ } else {
+ iFrame = 0;
+
+ #if defined(MA_SUPPORT_SSE2) /* For silencing a warning with non-x86 builds. */
+ generic_on_fastpath:
+ #endif
+ {
+ for (; iFrame < frameCount; iFrame += 1) {
+ for (iChannelOut = 0; iChannelOut < channelsOut; iChannelOut += 1) {
+ pFramesOut[iFrame*channelsOut + iChannelOut] = pFramesIn[iFrame];
+ }
+ }
+ }
+ }
+ } else {
+ /* Slow path. Need to handle MA_CHANNEL_NONE. */
+ for (iFrame = 0; iFrame < frameCount; iFrame += 1) {
+ for (iChannelOut = 0; iChannelOut < channelsOut; iChannelOut += 1) {
+ if (channelPositions[iChannelOut] != MA_CHANNEL_NONE) {
+ pFramesOut[iFrame*channelsOut + iChannelOut] = pFramesIn[iFrame];
+ }
+ }
+ }
+ }
+ } else {
+ /* Slow path. Too many channels to store on the stack. */
+ for (iFrame = 0; iFrame < frameCount; iFrame += 1) {
+ for (iChannelOut = 0; iChannelOut < channelsOut; iChannelOut += 1) {
+ ma_channel channelOut = ma_channel_map_get_channel(pChannelMapOut, channelsOut, iChannelOut);
+ if (channelOut != MA_CHANNEL_NONE) {
+ pFramesOut[iFrame*channelsOut + iChannelOut] = pFramesIn[iFrame];
+ }
+ }
+ }
}
}
} break;
@@ -51363,19 +53051,105 @@ static void ma_channel_map_apply_f32(float* pFramesOut, const ma_channel* pChann
}
}
- for (iFrame = 0; iFrame < frameCount; iFrame += 1) {
+ iFrame = 0;
+
+ /* Experiment: Try an optimized unroll for some specific cases to see how it improves performance. RESULT: Good gains. */
+ if (channelsOut == 8) {
+ /* Experiment 2: Expand the inner loop to see what kind of different it makes. RESULT: Small, but worthwhile gain. */
+ if (channelsIn == 2) {
+ for (; iFrame < frameCount; iFrame += 1) {
+ float accumulation[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
+
+ accumulation[0] += pFramesIn[iFrame*2 + 0] * weights[0][0];
+ accumulation[1] += pFramesIn[iFrame*2 + 0] * weights[1][0];
+ accumulation[2] += pFramesIn[iFrame*2 + 0] * weights[2][0];
+ accumulation[3] += pFramesIn[iFrame*2 + 0] * weights[3][0];
+ accumulation[4] += pFramesIn[iFrame*2 + 0] * weights[4][0];
+ accumulation[5] += pFramesIn[iFrame*2 + 0] * weights[5][0];
+ accumulation[6] += pFramesIn[iFrame*2 + 0] * weights[6][0];
+ accumulation[7] += pFramesIn[iFrame*2 + 0] * weights[7][0];
+
+ accumulation[0] += pFramesIn[iFrame*2 + 1] * weights[0][1];
+ accumulation[1] += pFramesIn[iFrame*2 + 1] * weights[1][1];
+ accumulation[2] += pFramesIn[iFrame*2 + 1] * weights[2][1];
+ accumulation[3] += pFramesIn[iFrame*2 + 1] * weights[3][1];
+ accumulation[4] += pFramesIn[iFrame*2 + 1] * weights[4][1];
+ accumulation[5] += pFramesIn[iFrame*2 + 1] * weights[5][1];
+ accumulation[6] += pFramesIn[iFrame*2 + 1] * weights[6][1];
+ accumulation[7] += pFramesIn[iFrame*2 + 1] * weights[7][1];
+
+ pFramesOut[iFrame*8 + 0] = accumulation[0];
+ pFramesOut[iFrame*8 + 1] = accumulation[1];
+ pFramesOut[iFrame*8 + 2] = accumulation[2];
+ pFramesOut[iFrame*8 + 3] = accumulation[3];
+ pFramesOut[iFrame*8 + 4] = accumulation[4];
+ pFramesOut[iFrame*8 + 5] = accumulation[5];
+ pFramesOut[iFrame*8 + 6] = accumulation[6];
+ pFramesOut[iFrame*8 + 7] = accumulation[7];
+ }
+ } else {
+ /* When outputting to 8 channels, we can do everything in groups of two 4x SIMD operations. */
+ for (; iFrame < frameCount; iFrame += 1) {
+ float accumulation[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
+
+ for (iChannelIn = 0; iChannelIn < channelsIn; iChannelIn += 1) {
+ accumulation[0] += pFramesIn[iFrame*channelsIn + iChannelIn] * weights[0][iChannelIn];
+ accumulation[1] += pFramesIn[iFrame*channelsIn + iChannelIn] * weights[1][iChannelIn];
+ accumulation[2] += pFramesIn[iFrame*channelsIn + iChannelIn] * weights[2][iChannelIn];
+ accumulation[3] += pFramesIn[iFrame*channelsIn + iChannelIn] * weights[3][iChannelIn];
+ accumulation[4] += pFramesIn[iFrame*channelsIn + iChannelIn] * weights[4][iChannelIn];
+ accumulation[5] += pFramesIn[iFrame*channelsIn + iChannelIn] * weights[5][iChannelIn];
+ accumulation[6] += pFramesIn[iFrame*channelsIn + iChannelIn] * weights[6][iChannelIn];
+ accumulation[7] += pFramesIn[iFrame*channelsIn + iChannelIn] * weights[7][iChannelIn];
+ }
+
+ pFramesOut[iFrame*8 + 0] = accumulation[0];
+ pFramesOut[iFrame*8 + 1] = accumulation[1];
+ pFramesOut[iFrame*8 + 2] = accumulation[2];
+ pFramesOut[iFrame*8 + 3] = accumulation[3];
+ pFramesOut[iFrame*8 + 4] = accumulation[4];
+ pFramesOut[iFrame*8 + 5] = accumulation[5];
+ pFramesOut[iFrame*8 + 6] = accumulation[6];
+ pFramesOut[iFrame*8 + 7] = accumulation[7];
+ }
+ }
+ } else if (channelsOut == 6) {
+ /*
+ When outputting to 6 channels we unfortunately don't have a nice multiple of 4 to do 4x SIMD operations. Instead we'll
+ expand our weights and do two frames at a time.
+ */
+ for (; iFrame < frameCount; iFrame += 1) {
+ float accumulation[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+
+ for (iChannelIn = 0; iChannelIn < channelsIn; iChannelIn += 1) {
+ accumulation[0] += pFramesIn[iFrame*channelsIn + iChannelIn] * weights[0][iChannelIn];
+ accumulation[1] += pFramesIn[iFrame*channelsIn + iChannelIn] * weights[1][iChannelIn];
+ accumulation[2] += pFramesIn[iFrame*channelsIn + iChannelIn] * weights[2][iChannelIn];
+ accumulation[3] += pFramesIn[iFrame*channelsIn + iChannelIn] * weights[3][iChannelIn];
+ accumulation[4] += pFramesIn[iFrame*channelsIn + iChannelIn] * weights[4][iChannelIn];
+ accumulation[5] += pFramesIn[iFrame*channelsIn + iChannelIn] * weights[5][iChannelIn];
+ }
+
+ pFramesOut[iFrame*6 + 0] = accumulation[0];
+ pFramesOut[iFrame*6 + 1] = accumulation[1];
+ pFramesOut[iFrame*6 + 2] = accumulation[2];
+ pFramesOut[iFrame*6 + 3] = accumulation[3];
+ pFramesOut[iFrame*6 + 4] = accumulation[4];
+ pFramesOut[iFrame*6 + 5] = accumulation[5];
+ }
+ }
+
+ /* Leftover frames. */
+ for (; iFrame < frameCount; iFrame += 1) {
for (iChannelOut = 0; iChannelOut < channelsOut; iChannelOut += 1) {
float accumulation = 0;
for (iChannelIn = 0; iChannelIn < channelsIn; iChannelIn += 1) {
- accumulation += pFramesIn[iChannelIn] * weights[iChannelOut][iChannelIn];
+ accumulation += pFramesIn[iFrame*channelsIn + iChannelIn] * weights[iChannelOut][iChannelIn];
}
- pFramesOut[iChannelOut] = accumulation;
+ pFramesOut[iFrame*channelsOut + iChannelOut] = accumulation;
}
-
- pFramesOut += channelsOut;
- pFramesIn += channelsIn;
}
} else {
/* Cannot pre-compute weights because not enough room in stack-allocated buffer. */
@@ -51386,14 +53160,11 @@ static void ma_channel_map_apply_f32(float* pFramesOut, const ma_channel* pChann
for (iChannelIn = 0; iChannelIn < channelsIn; iChannelIn += 1) {
ma_channel channelIn = ma_channel_map_get_channel(pChannelMapIn, channelsIn, iChannelIn);
- accumulation += pFramesIn[iChannelIn] * ma_calculate_channel_position_rectangular_weight(channelOut, channelIn);
+ accumulation += pFramesIn[iFrame*channelsIn + iChannelIn] * ma_calculate_channel_position_rectangular_weight(channelOut, channelIn);
}
- pFramesOut[iChannelOut] = accumulation;
+ pFramesOut[iFrame*channelsOut + iChannelOut] = accumulation;
}
-
- pFramesOut += channelsOut;
- pFramesIn += channelsIn;
}
}
}
@@ -52138,7 +53909,7 @@ MA_API ma_result ma_channel_converter_get_output_channel_map(const ma_channel_co
Data Conversion
**************************************************************************************************************************************************************/
-MA_API ma_data_converter_config ma_data_converter_config_init_default()
+MA_API ma_data_converter_config ma_data_converter_config_init_default(void)
{
ma_data_converter_config config;
MA_ZERO_OBJECT(&config);
@@ -54342,13 +56113,13 @@ static MA_INLINE ma_uint32 ma_rb__extract_offset_loop_flag(ma_uint32 encodedOffs
static MA_INLINE void* ma_rb__get_read_ptr(ma_rb* pRB)
{
MA_ASSERT(pRB != NULL);
- return ma_offset_ptr(pRB->pBuffer, ma_rb__extract_offset_in_bytes(c89atomic_load_32(&pRB->encodedReadOffset)));
+ return ma_offset_ptr(pRB->pBuffer, ma_rb__extract_offset_in_bytes(ma_atomic_load_32(&pRB->encodedReadOffset)));
}
static MA_INLINE void* ma_rb__get_write_ptr(ma_rb* pRB)
{
MA_ASSERT(pRB != NULL);
- return ma_offset_ptr(pRB->pBuffer, ma_rb__extract_offset_in_bytes(c89atomic_load_32(&pRB->encodedWriteOffset)));
+ return ma_offset_ptr(pRB->pBuffer, ma_rb__extract_offset_in_bytes(ma_atomic_load_32(&pRB->encodedWriteOffset)));
}
static MA_INLINE ma_uint32 ma_rb__construct_offset(ma_uint32 offsetInBytes, ma_uint32 offsetLoopFlag)
@@ -54441,8 +56212,8 @@ MA_API void ma_rb_reset(ma_rb* pRB)
return;
}
- c89atomic_exchange_32(&pRB->encodedReadOffset, 0);
- c89atomic_exchange_32(&pRB->encodedWriteOffset, 0);
+ ma_atomic_exchange_32(&pRB->encodedReadOffset, 0);
+ ma_atomic_exchange_32(&pRB->encodedWriteOffset, 0);
}
MA_API ma_result ma_rb_acquire_read(ma_rb* pRB, size_t* pSizeInBytes, void** ppBufferOut)
@@ -54461,10 +56232,10 @@ MA_API ma_result ma_rb_acquire_read(ma_rb* pRB, size_t* pSizeInBytes, void** ppB
}
/* The returned buffer should never move ahead of the write pointer. */
- writeOffset = c89atomic_load_32(&pRB->encodedWriteOffset);
+ writeOffset = ma_atomic_load_32(&pRB->encodedWriteOffset);
ma_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag);
- readOffset = c89atomic_load_32(&pRB->encodedReadOffset);
+ readOffset = ma_atomic_load_32(&pRB->encodedReadOffset);
ma_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag);
/*
@@ -54500,7 +56271,7 @@ MA_API ma_result ma_rb_commit_read(ma_rb* pRB, size_t sizeInBytes)
return MA_INVALID_ARGS;
}
- readOffset = c89atomic_load_32(&pRB->encodedReadOffset);
+ readOffset = ma_atomic_load_32(&pRB->encodedReadOffset);
ma_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag);
/* Check that sizeInBytes is correct. It should never go beyond the end of the buffer. */
@@ -54516,7 +56287,7 @@ MA_API ma_result ma_rb_commit_read(ma_rb* pRB, size_t sizeInBytes)
newReadOffsetLoopFlag ^= 0x80000000;
}
- c89atomic_exchange_32(&pRB->encodedReadOffset, ma_rb__construct_offset(newReadOffsetLoopFlag, newReadOffsetInBytes));
+ ma_atomic_exchange_32(&pRB->encodedReadOffset, ma_rb__construct_offset(newReadOffsetLoopFlag, newReadOffsetInBytes));
if (ma_rb_pointer_distance(pRB) == 0) {
return MA_AT_END;
@@ -54541,10 +56312,10 @@ MA_API ma_result ma_rb_acquire_write(ma_rb* pRB, size_t* pSizeInBytes, void** pp
}
/* The returned buffer should never overtake the read buffer. */
- readOffset = c89atomic_load_32(&pRB->encodedReadOffset);
+ readOffset = ma_atomic_load_32(&pRB->encodedReadOffset);
ma_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag);
- writeOffset = c89atomic_load_32(&pRB->encodedWriteOffset);
+ writeOffset = ma_atomic_load_32(&pRB->encodedWriteOffset);
ma_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag);
/*
@@ -54586,7 +56357,7 @@ MA_API ma_result ma_rb_commit_write(ma_rb* pRB, size_t sizeInBytes)
return MA_INVALID_ARGS;
}
- writeOffset = c89atomic_load_32(&pRB->encodedWriteOffset);
+ writeOffset = ma_atomic_load_32(&pRB->encodedWriteOffset);
ma_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag);
/* Check that sizeInBytes is correct. It should never go beyond the end of the buffer. */
@@ -54602,7 +56373,7 @@ MA_API ma_result ma_rb_commit_write(ma_rb* pRB, size_t sizeInBytes)
newWriteOffsetLoopFlag ^= 0x80000000;
}
- c89atomic_exchange_32(&pRB->encodedWriteOffset, ma_rb__construct_offset(newWriteOffsetLoopFlag, newWriteOffsetInBytes));
+ ma_atomic_exchange_32(&pRB->encodedWriteOffset, ma_rb__construct_offset(newWriteOffsetLoopFlag, newWriteOffsetInBytes));
if (ma_rb_pointer_distance(pRB) == 0) {
return MA_AT_END;
@@ -54626,10 +56397,10 @@ MA_API ma_result ma_rb_seek_read(ma_rb* pRB, size_t offsetInBytes)
return MA_INVALID_ARGS;
}
- readOffset = c89atomic_load_32(&pRB->encodedReadOffset);
+ readOffset = ma_atomic_load_32(&pRB->encodedReadOffset);
ma_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag);
- writeOffset = c89atomic_load_32(&pRB->encodedWriteOffset);
+ writeOffset = ma_atomic_load_32(&pRB->encodedWriteOffset);
ma_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag);
newReadOffsetLoopFlag = readOffsetLoopFlag;
@@ -54651,7 +56422,7 @@ MA_API ma_result ma_rb_seek_read(ma_rb* pRB, size_t offsetInBytes)
}
}
- c89atomic_exchange_32(&pRB->encodedReadOffset, ma_rb__construct_offset(newReadOffsetInBytes, newReadOffsetLoopFlag));
+ ma_atomic_exchange_32(&pRB->encodedReadOffset, ma_rb__construct_offset(newReadOffsetInBytes, newReadOffsetLoopFlag));
return MA_SUCCESS;
}
@@ -54670,10 +56441,10 @@ MA_API ma_result ma_rb_seek_write(ma_rb* pRB, size_t offsetInBytes)
return MA_INVALID_ARGS;
}
- readOffset = c89atomic_load_32(&pRB->encodedReadOffset);
+ readOffset = ma_atomic_load_32(&pRB->encodedReadOffset);
ma_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag);
- writeOffset = c89atomic_load_32(&pRB->encodedWriteOffset);
+ writeOffset = ma_atomic_load_32(&pRB->encodedWriteOffset);
ma_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag);
newWriteOffsetLoopFlag = writeOffsetLoopFlag;
@@ -54695,7 +56466,7 @@ MA_API ma_result ma_rb_seek_write(ma_rb* pRB, size_t offsetInBytes)
}
}
- c89atomic_exchange_32(&pRB->encodedWriteOffset, ma_rb__construct_offset(newWriteOffsetInBytes, newWriteOffsetLoopFlag));
+ ma_atomic_exchange_32(&pRB->encodedWriteOffset, ma_rb__construct_offset(newWriteOffsetInBytes, newWriteOffsetLoopFlag));
return MA_SUCCESS;
}
@@ -54712,10 +56483,10 @@ MA_API ma_int32 ma_rb_pointer_distance(ma_rb* pRB)
return 0;
}
- readOffset = c89atomic_load_32(&pRB->encodedReadOffset);
+ readOffset = ma_atomic_load_32(&pRB->encodedReadOffset);
ma_rb__deconstruct_offset(readOffset, &readOffsetInBytes, &readOffsetLoopFlag);
- writeOffset = c89atomic_load_32(&pRB->encodedWriteOffset);
+ writeOffset = ma_atomic_load_32(&pRB->encodedWriteOffset);
ma_rb__deconstruct_offset(writeOffset, &writeOffsetInBytes, &writeOffsetLoopFlag);
if (readOffsetLoopFlag == writeOffsetLoopFlag) {
@@ -54792,6 +56563,85 @@ MA_API void* ma_rb_get_subbuffer_ptr(ma_rb* pRB, size_t subbufferIndex, void* pB
+static ma_result ma_pcm_rb_data_source__on_read(ma_data_source* pDataSource, void* pFramesOut, ma_uint64 frameCount, ma_uint64* pFramesRead)
+{
+ /* Since there's no notion of an end, we don't ever want to return MA_AT_END here. But it is possible to return 0. */
+ ma_pcm_rb* pRB = (ma_pcm_rb*)pDataSource;
+ ma_result result;
+ ma_uint64 totalFramesRead;
+
+ MA_ASSERT(pRB != NULL);
+
+ /* We need to run this in a loop since the ring buffer itself may loop. */
+ totalFramesRead = 0;
+ while (totalFramesRead < frameCount) {
+ void* pMappedBuffer;
+ ma_uint32 mappedFrameCount;
+ ma_uint64 framesToRead = frameCount - totalFramesRead;
+ if (framesToRead > 0xFFFFFFFF) {
+ framesToRead = 0xFFFFFFFF;
+ }
+
+ mappedFrameCount = (ma_uint32)framesToRead;
+ result = ma_pcm_rb_acquire_read(pRB, &mappedFrameCount, &pMappedBuffer);
+ if (result != MA_SUCCESS) {
+ break;
+ }
+
+ if (mappedFrameCount == 0) {
+ break; /* <-- End of ring buffer. */
+ }
+
+ ma_copy_pcm_frames(ma_offset_pcm_frames_ptr(pFramesOut, totalFramesRead, pRB->format, pRB->channels), pMappedBuffer, mappedFrameCount, pRB->format, pRB->channels);
+
+ result = ma_pcm_rb_commit_read(pRB, mappedFrameCount);
+ if (result != MA_SUCCESS) {
+ break;
+ }
+
+ totalFramesRead += mappedFrameCount;
+ }
+
+ *pFramesRead = totalFramesRead;
+ return MA_SUCCESS;
+}
+
+static ma_result ma_pcm_rb_data_source__on_get_data_format(ma_data_source* pDataSource, ma_format* pFormat, ma_uint32* pChannels, ma_uint32* pSampleRate, ma_channel* pChannelMap, size_t channelMapCap)
+{
+ ma_pcm_rb* pRB = (ma_pcm_rb*)pDataSource;
+ MA_ASSERT(pRB != NULL);
+
+ if (pFormat != NULL) {
+ *pFormat = pRB->format;
+ }
+
+ if (pChannels != NULL) {
+ *pChannels = pRB->channels;
+ }
+
+ if (pSampleRate != NULL) {
+ *pSampleRate = pRB->sampleRate;
+ }
+
+ /* Just assume the default channel map. */
+ if (pChannelMap != NULL) {
+ ma_channel_map_init_standard(ma_standard_channel_map_default, pChannelMap, channelMapCap, pRB->channels);
+ }
+
+ return MA_SUCCESS;
+}
+
+static ma_data_source_vtable ma_gRBDataSourceVTable =
+{
+ ma_pcm_rb_data_source__on_read,
+ NULL, /* onSeek */
+ ma_pcm_rb_data_source__on_get_data_format,
+ NULL, /* onGetCursor */
+ NULL, /* onGetLength */
+ NULL, /* onSetLooping */
+ 0
+};
+
static MA_INLINE ma_uint32 ma_pcm_rb_get_bpf(ma_pcm_rb* pRB)
{
MA_ASSERT(pRB != NULL);
@@ -54820,8 +56670,21 @@ MA_API ma_result ma_pcm_rb_init_ex(ma_format format, ma_uint32 channels, ma_uint
return result;
}
- pRB->format = format;
- pRB->channels = channels;
+ pRB->format = format;
+ pRB->channels = channels;
+ pRB->sampleRate = 0; /* The sample rate is not passed in as a parameter. */
+
+ /* The PCM ring buffer is a data source. We need to get that set up as well. */
+ {
+ ma_data_source_config dataSourceConfig = ma_data_source_config_init();
+ dataSourceConfig.vtable = &ma_gRBDataSourceVTable;
+
+ result = ma_data_source_init(&dataSourceConfig, &pRB->ds);
+ if (result != MA_SUCCESS) {
+ ma_rb_uninit(&pRB->rb);
+ return result;
+ }
+ }
return MA_SUCCESS;
}
@@ -54837,6 +56700,7 @@ MA_API void ma_pcm_rb_uninit(ma_pcm_rb* pRB)
return;
}
+ ma_data_source_uninit(&pRB->ds);
ma_rb_uninit(&pRB->rb);
}
@@ -54988,6 +56852,42 @@ MA_API void* ma_pcm_rb_get_subbuffer_ptr(ma_pcm_rb* pRB, ma_uint32 subbufferInde
return ma_rb_get_subbuffer_ptr(&pRB->rb, subbufferIndex, pBuffer);
}
+MA_API ma_format ma_pcm_rb_get_format(const ma_pcm_rb* pRB)
+{
+ if (pRB == NULL) {
+ return ma_format_unknown;
+ }
+
+ return pRB->format;
+}
+
+MA_API ma_uint32 ma_pcm_rb_get_channels(const ma_pcm_rb* pRB)
+{
+ if (pRB == NULL) {
+ return 0;
+ }
+
+ return pRB->channels;
+}
+
+MA_API ma_uint32 ma_pcm_rb_get_sample_rate(const ma_pcm_rb* pRB)
+{
+ if (pRB == NULL) {
+ return 0;
+ }
+
+ return pRB->sampleRate;
+}
+
+MA_API void ma_pcm_rb_set_sample_rate(ma_pcm_rb* pRB, ma_uint32 sampleRate)
+{
+ if (pRB == NULL) {
+ return;
+ }
+
+ pRB->sampleRate = sampleRate;
+}
+
MA_API ma_result ma_duplex_rb_init(ma_format captureFormat, ma_uint32 captureChannels, ma_uint32 sampleRate, ma_uint32 captureInternalSampleRate, ma_uint32 captureInternalPeriodSizeInFrames, const ma_allocation_callbacks* pAllocationCallbacks, ma_duplex_rb* pRB)
@@ -55221,6 +57121,11 @@ MA_API ma_uint32 ma_get_bytes_per_sample(ma_format format)
+#define MA_DATA_SOURCE_DEFAULT_RANGE_BEG 0
+#define MA_DATA_SOURCE_DEFAULT_RANGE_END ~((ma_uint64)0)
+#define MA_DATA_SOURCE_DEFAULT_LOOP_POINT_BEG 0
+#define MA_DATA_SOURCE_DEFAULT_LOOP_POINT_END ~((ma_uint64)0)
+
MA_API ma_data_source_config ma_data_source_config_init(void)
{
ma_data_source_config config;
@@ -55246,10 +57151,10 @@ MA_API ma_result ma_data_source_init(const ma_data_source_config* pConfig, ma_da
}
pDataSourceBase->vtable = pConfig->vtable;
- pDataSourceBase->rangeBegInFrames = 0;
- pDataSourceBase->rangeEndInFrames = ~((ma_uint64)0);
- pDataSourceBase->loopBegInFrames = 0;
- pDataSourceBase->loopEndInFrames = ~((ma_uint64)0);
+ pDataSourceBase->rangeBegInFrames = MA_DATA_SOURCE_DEFAULT_RANGE_BEG;
+ pDataSourceBase->rangeEndInFrames = MA_DATA_SOURCE_DEFAULT_RANGE_END;
+ pDataSourceBase->loopBegInFrames = MA_DATA_SOURCE_DEFAULT_LOOP_POINT_BEG;
+ pDataSourceBase->loopEndInFrames = MA_DATA_SOURCE_DEFAULT_LOOP_POINT_END;
pDataSourceBase->pCurrent = pDataSource; /* Always read from ourself by default. */
pDataSourceBase->pNext = NULL;
pDataSourceBase->onGetNext = NULL;
@@ -55315,18 +57220,23 @@ static ma_result ma_data_source_read_pcm_frames_within_range(ma_data_source* pDa
result = pDataSourceBase->vtable->onRead(pDataSourceBase, pFramesOut, frameCount, &framesRead);
} else {
/* Need to clamp to within the range. */
- ma_uint64 cursor;
+ ma_uint64 relativeCursor;
+ ma_uint64 absoluteCursor;
- result = ma_data_source_get_cursor_in_pcm_frames(pDataSourceBase, &cursor);
+ result = ma_data_source_get_cursor_in_pcm_frames(pDataSourceBase, &relativeCursor);
if (result != MA_SUCCESS) {
/* Failed to retrieve the cursor. Cannot read within a range or loop points. Just read like normal - this may happen for things like noise data sources where it doesn't really matter. */
result = pDataSourceBase->vtable->onRead(pDataSourceBase, pFramesOut, frameCount, &framesRead);
} else {
+ ma_uint64 rangeBeg;
ma_uint64 rangeEnd;
/* We have the cursor. We need to make sure we don't read beyond our range. */
+ rangeBeg = pDataSourceBase->rangeBegInFrames;
rangeEnd = pDataSourceBase->rangeEndInFrames;
+ absoluteCursor = rangeBeg + relativeCursor;
+
/* If looping, make sure we're within range. */
if (loop) {
if (pDataSourceBase->loopEndInFrames != ~((ma_uint64)0)) {
@@ -55334,8 +57244,8 @@ static ma_result ma_data_source_read_pcm_frames_within_range(ma_data_source* pDa
}
}
- if (frameCount > (rangeEnd - cursor) && rangeEnd != ~((ma_uint64)0)) {
- frameCount = (rangeEnd - cursor);
+ if (frameCount > (rangeEnd - absoluteCursor) && rangeEnd != ~((ma_uint64)0)) {
+ frameCount = (rangeEnd - absoluteCursor);
}
/*
@@ -55715,7 +57625,7 @@ MA_API ma_result ma_data_source_set_looping(ma_data_source* pDataSource, ma_bool
return MA_INVALID_ARGS;
}
- c89atomic_exchange_32(&pDataSourceBase->isLooping, isLooping);
+ ma_atomic_exchange_32(&pDataSourceBase->isLooping, isLooping);
/* If there's no callback for this just treat it as a successful no-op. */
if (pDataSourceBase->vtable->onSetLooping == NULL) {
@@ -55733,16 +57643,16 @@ MA_API ma_bool32 ma_data_source_is_looping(const ma_data_source* pDataSource)
return MA_FALSE;
}
- return c89atomic_load_32(&pDataSourceBase->isLooping);
+ return ma_atomic_load_32(&pDataSourceBase->isLooping);
}
MA_API ma_result ma_data_source_set_range_in_pcm_frames(ma_data_source* pDataSource, ma_uint64 rangeBegInFrames, ma_uint64 rangeEndInFrames)
{
ma_data_source_base* pDataSourceBase = (ma_data_source_base*)pDataSource;
ma_result result;
- ma_uint64 cursor;
- ma_uint64 loopBegAbsolute;
- ma_uint64 loopEndAbsolute;
+ ma_uint64 relativeCursor;
+ ma_uint64 absoluteCursor;
+ ma_bool32 doSeekAdjustment = MA_FALSE;
if (pDataSource == NULL) {
return MA_INVALID_ARGS;
@@ -55753,51 +57663,51 @@ MA_API ma_result ma_data_source_set_range_in_pcm_frames(ma_data_source* pDataSou
}
/*
- The loop points need to be updated. We'll be storing the loop points relative to the range. We'll update
- these so that they maintain their absolute positioning. The loop points will then be clamped to the range.
+ We may need to adjust the position of the cursor to ensure it's clamped to the range. Grab it now
+ so we can calculate it's absolute position before we change the range.
*/
- loopBegAbsolute = pDataSourceBase->loopBegInFrames + pDataSourceBase->rangeBegInFrames;
- loopEndAbsolute = pDataSourceBase->loopEndInFrames + ((pDataSourceBase->loopEndInFrames != ~((ma_uint64)0)) ? pDataSourceBase->rangeBegInFrames : 0);
-
- pDataSourceBase->rangeBegInFrames = rangeBegInFrames;
- pDataSourceBase->rangeEndInFrames = rangeEndInFrames;
-
- /* Make the loop points relative again, and make sure they're clamped to within the range. */
- if (loopBegAbsolute > pDataSourceBase->rangeBegInFrames) {
- pDataSourceBase->loopBegInFrames = loopBegAbsolute - pDataSourceBase->rangeBegInFrames;
+ result = ma_data_source_get_cursor_in_pcm_frames(pDataSource, &relativeCursor);
+ if (result == MA_SUCCESS) {
+ doSeekAdjustment = MA_TRUE;
+ absoluteCursor = relativeCursor + pDataSourceBase->rangeBegInFrames;
} else {
- pDataSourceBase->loopBegInFrames = 0;
+ /*
+ We couldn't get the position of the cursor. It probably means the data source has no notion
+ of a cursor. We'll just leave it at position 0. Don't treat this as an error.
+ */
+ doSeekAdjustment = MA_FALSE;
+ relativeCursor = 0;
+ absoluteCursor = 0;
}
- if (pDataSourceBase->loopBegInFrames > pDataSourceBase->rangeEndInFrames) {
- pDataSourceBase->loopBegInFrames = pDataSourceBase->rangeEndInFrames;
- }
+ pDataSourceBase->rangeBegInFrames = rangeBegInFrames;
+ pDataSourceBase->rangeEndInFrames = rangeEndInFrames;
- /* Only need to update the loop end point if it's not -1. */
- if (loopEndAbsolute != ~((ma_uint64)0)) {
- if (loopEndAbsolute > pDataSourceBase->rangeBegInFrames) {
- pDataSourceBase->loopEndInFrames = loopEndAbsolute - pDataSourceBase->rangeBegInFrames;
- } else {
- pDataSourceBase->loopEndInFrames = 0;
- }
+ /*
+ The commented out logic below was intended to maintain loop points in response to a change in the
+ range. However, this is not useful because it results in the sound breaking when you move the range
+ outside of the old loop points. I'm simplifying this by simply resetting the loop points. The
+ caller is expected to update their loop points if they change the range.
- if (pDataSourceBase->loopEndInFrames > pDataSourceBase->rangeEndInFrames && pDataSourceBase->loopEndInFrames) {
- pDataSourceBase->loopEndInFrames = pDataSourceBase->rangeEndInFrames;
- }
- }
+ In practice this should be mostly a non-issue because the majority of the time the range will be
+ set once right after initialization.
+ */
+ pDataSourceBase->loopBegInFrames = 0;
+ pDataSourceBase->loopEndInFrames = ~((ma_uint64)0);
- /* If the new range is past the current cursor position we need to seek to it. */
- result = ma_data_source_get_cursor_in_pcm_frames(pDataSource, &cursor);
- if (result == MA_SUCCESS) {
- /* Seek to within range. Note that our seek positions here are relative to the new range. */
- if (cursor < rangeBegInFrames) {
+ /*
+ Seek to within range. Note that our seek positions here are relative to the new range. We don't want
+ do do this if we failed to retrieve the cursor earlier on because it probably means the data source
+ has no notion of a cursor. In practice the seek would probably fail (which we silently ignore), but
+ I'm just not even going to attempt it.
+ */
+ if (doSeekAdjustment) {
+ if (absoluteCursor < rangeBegInFrames) {
ma_data_source_seek_to_pcm_frame(pDataSource, 0);
- } else if (cursor > rangeEndInFrames) {
+ } else if (absoluteCursor > rangeEndInFrames) {
ma_data_source_seek_to_pcm_frame(pDataSource, rangeEndInFrames - rangeBegInFrames);
}
- } else {
- /* We failed to get the cursor position. Probably means the data source has no notion of a cursor such a noise data source. Just pretend the seeking worked. */
}
return MA_SUCCESS;
@@ -56499,9 +58409,9 @@ MA_API void ma_paged_audio_buffer_data_uninit(ma_paged_audio_buffer_data* pData,
}
/* All pages need to be freed. */
- pPage = (ma_paged_audio_buffer_page*)c89atomic_load_ptr(&pData->head.pNext);
+ pPage = (ma_paged_audio_buffer_page*)ma_atomic_load_ptr(&pData->head.pNext);
while (pPage != NULL) {
- ma_paged_audio_buffer_page* pNext = (ma_paged_audio_buffer_page*)c89atomic_load_ptr(&pPage->pNext);
+ ma_paged_audio_buffer_page* pNext = (ma_paged_audio_buffer_page*)ma_atomic_load_ptr(&pPage->pNext);
ma_free(pPage, pAllocationCallbacks);
pPage = pNext;
@@ -56541,7 +58451,7 @@ MA_API ma_result ma_paged_audio_buffer_data_get_length_in_pcm_frames(ma_paged_au
}
/* Calculate the length from the linked list. */
- for (pPage = (ma_paged_audio_buffer_page*)c89atomic_load_ptr(&pData->head.pNext); pPage != NULL; pPage = (ma_paged_audio_buffer_page*)c89atomic_load_ptr(&pPage->pNext)) {
+ for (pPage = (ma_paged_audio_buffer_page*)ma_atomic_load_ptr(&pData->head.pNext); pPage != NULL; pPage = (ma_paged_audio_buffer_page*)ma_atomic_load_ptr(&pPage->pNext)) {
*pLength += pPage->sizeInFrames;
}
@@ -56607,12 +58517,12 @@ MA_API ma_result ma_paged_audio_buffer_data_append_page(ma_paged_audio_buffer_da
/* First thing to do is update the tail. */
for (;;) {
- ma_paged_audio_buffer_page* pOldTail = (ma_paged_audio_buffer_page*)c89atomic_load_ptr(&pData->pTail);
+ ma_paged_audio_buffer_page* pOldTail = (ma_paged_audio_buffer_page*)ma_atomic_load_ptr(&pData->pTail);
ma_paged_audio_buffer_page* pNewTail = pPage;
- if (c89atomic_compare_exchange_weak_ptr((volatile void**)&pData->pTail, (void**)&pOldTail, pNewTail)) {
+ if (ma_atomic_compare_exchange_weak_ptr((volatile void**)&pData->pTail, (void**)&pOldTail, pNewTail)) {
/* Here is where we append the page to the list. After this, the page is attached to the list and ready to be read from. */
- c89atomic_exchange_ptr(&pOldTail->pNext, pPage);
+ ma_atomic_exchange_ptr(&pOldTail->pNext, pPage);
break; /* Done. */
}
}
@@ -56769,7 +58679,7 @@ MA_API ma_result ma_paged_audio_buffer_read_pcm_frames(ma_paged_audio_buffer* pP
if (pPagedAudioBuffer->relativeCursor == pPagedAudioBuffer->pCurrent->sizeInFrames) {
/* We reached the end of the page. Need to move to the next. If there's no more pages, we're done. */
- ma_paged_audio_buffer_page* pNext = (ma_paged_audio_buffer_page*)c89atomic_load_ptr(&pPagedAudioBuffer->pCurrent->pNext);
+ ma_paged_audio_buffer_page* pNext = (ma_paged_audio_buffer_page*)ma_atomic_load_ptr(&pPagedAudioBuffer->pCurrent->pNext);
if (pNext == NULL) {
result = MA_AT_END;
break; /* We've reached the end. */
@@ -56811,12 +58721,12 @@ MA_API ma_result ma_paged_audio_buffer_seek_to_pcm_frame(ma_paged_audio_buffer*
ma_paged_audio_buffer_page* pPage;
ma_uint64 runningCursor = 0;
- for (pPage = (ma_paged_audio_buffer_page*)c89atomic_load_ptr(&ma_paged_audio_buffer_data_get_head(pPagedAudioBuffer->pData)->pNext); pPage != NULL; pPage = (ma_paged_audio_buffer_page*)c89atomic_load_ptr(&pPage->pNext)) {
+ for (pPage = (ma_paged_audio_buffer_page*)ma_atomic_load_ptr(&ma_paged_audio_buffer_data_get_head(pPagedAudioBuffer->pData)->pNext); pPage != NULL; pPage = (ma_paged_audio_buffer_page*)ma_atomic_load_ptr(&pPage->pNext)) {
ma_uint64 pageRangeBeg = runningCursor;
ma_uint64 pageRangeEnd = pageRangeBeg + pPage->sizeInFrames;
if (frameIndex >= pageRangeBeg) {
- if (frameIndex < pageRangeEnd || (frameIndex == pageRangeEnd && pPage == (ma_paged_audio_buffer_page*)c89atomic_load_ptr(ma_paged_audio_buffer_data_get_tail(pPagedAudioBuffer->pData)))) { /* A small edge case - allow seeking to the very end of the buffer. */
+ if (frameIndex < pageRangeEnd || (frameIndex == pageRangeEnd && pPage == (ma_paged_audio_buffer_page*)ma_atomic_load_ptr(ma_paged_audio_buffer_data_get_tail(pPagedAudioBuffer->pData)))) { /* A small edge case - allow seeking to the very end of the buffer. */
/* We found the page. */
pPagedAudioBuffer->pCurrent = pPage;
pPagedAudioBuffer->absoluteCursor = frameIndex;
@@ -56925,7 +58835,7 @@ MA_API ma_result ma_vfs_read(ma_vfs* pVFS, ma_vfs_file file, void* pDst, size_t
{
ma_vfs_callbacks* pCallbacks = (ma_vfs_callbacks*)pVFS;
ma_result result;
- size_t bytesRead;
+ size_t bytesRead = 0;
if (pBytesRead != NULL) {
*pBytesRead = 0;
@@ -57029,81 +58939,36 @@ MA_API ma_result ma_vfs_info(ma_vfs* pVFS, ma_vfs_file file, ma_file_info* pInfo
}
-static ma_result ma_vfs_open_and_read_file_ex(ma_vfs* pVFS, const char* pFilePath, const wchar_t* pFilePathW, void** ppData, size_t* pSize, const ma_allocation_callbacks* pAllocationCallbacks)
-{
- ma_result result;
- ma_vfs_file file;
- ma_file_info info;
- void* pData;
- size_t bytesRead;
-
- if (ppData != NULL) {
- *ppData = NULL;
- }
- if (pSize != NULL) {
- *pSize = 0;
- }
-
- if (ppData == NULL) {
- return MA_INVALID_ARGS;
- }
-
- if (pFilePath != NULL) {
- result = ma_vfs_open(pVFS, pFilePath, MA_OPEN_MODE_READ, &file);
- } else {
- result = ma_vfs_open_w(pVFS, pFilePathW, MA_OPEN_MODE_READ, &file);
- }
- if (result != MA_SUCCESS) {
- return result;
- }
-
- result = ma_vfs_info(pVFS, file, &info);
- if (result != MA_SUCCESS) {
- ma_vfs_close(pVFS, file);
- return result;
- }
-
- if (info.sizeInBytes > MA_SIZE_MAX) {
- ma_vfs_close(pVFS, file);
- return MA_TOO_BIG;
- }
-
- pData = ma_malloc((size_t)info.sizeInBytes, pAllocationCallbacks); /* Safe cast. */
- if (pData == NULL) {
- ma_vfs_close(pVFS, file);
- return result;
- }
-
- result = ma_vfs_read(pVFS, file, pData, (size_t)info.sizeInBytes, &bytesRead); /* Safe cast. */
- ma_vfs_close(pVFS, file);
-
- if (result != MA_SUCCESS) {
- ma_free(pData, pAllocationCallbacks);
- return result;
- }
-
- if (pSize != NULL) {
- *pSize = bytesRead;
- }
+#if !defined(MA_USE_WIN32_FILEIO) && (defined(MA_WIN32) && defined(MA_WIN32_DESKTOP) && !defined(MA_NO_WIN32_FILEIO) && !defined(MA_POSIX))
+ #define MA_USE_WIN32_FILEIO
+#endif
- MA_ASSERT(ppData != NULL);
- *ppData = pData;
+#if defined(MA_USE_WIN32_FILEIO)
+/*
+We need to dynamically load SetFilePointer or SetFilePointerEx because older versions of Windows do
+not have the Ex version. We therefore need to do some dynamic branching depending on what's available.
- return MA_SUCCESS;
-}
+We load these when we load our first file from the default VFS. It's left open for the life of the
+program and is left to the OS to uninitialize when the program terminates.
+*/
+typedef DWORD (__stdcall * ma_SetFilePointer_proc)(HANDLE hFile, LONG lDistanceToMove, LONG* lpDistanceToMoveHigh, DWORD dwMoveMethod);
+typedef BOOL (__stdcall * ma_SetFilePointerEx_proc)(HANDLE hFile, LARGE_INTEGER liDistanceToMove, LARGE_INTEGER* lpNewFilePointer, DWORD dwMoveMethod);
-MA_API ma_result ma_vfs_open_and_read_file(ma_vfs* pVFS, const char* pFilePath, void** ppData, size_t* pSize, const ma_allocation_callbacks* pAllocationCallbacks)
-{
- return ma_vfs_open_and_read_file_ex(pVFS, pFilePath, NULL, ppData, pSize, pAllocationCallbacks);
-}
+static ma_handle hKernel32DLL = NULL;
+static ma_SetFilePointer_proc ma_SetFilePointer = NULL;
+static ma_SetFilePointerEx_proc ma_SetFilePointerEx = NULL;
-MA_API ma_result ma_vfs_open_and_read_file_w(ma_vfs* pVFS, const wchar_t* pFilePath, void** ppData, size_t* pSize, const ma_allocation_callbacks* pAllocationCallbacks)
+static void ma_win32_fileio_init(void)
{
- return ma_vfs_open_and_read_file_ex(pVFS, NULL, pFilePath, ppData, pSize, pAllocationCallbacks);
+ if (hKernel32DLL == NULL) {
+ hKernel32DLL = ma_dlopen(NULL, "kernel32.dll");
+ if (hKernel32DLL != NULL) {
+ ma_SetFilePointer = (ma_SetFilePointer_proc) ma_dlsym(NULL, hKernel32DLL, "SetFilePointer");
+ ma_SetFilePointerEx = (ma_SetFilePointerEx_proc)ma_dlsym(NULL, hKernel32DLL, "SetFilePointerEx");
+ }
+ }
}
-
-#if defined(MA_WIN32) && defined(MA_WIN32_DESKTOP) && !defined(MA_NO_WIN32_FILEIO)
static void ma_default_vfs__get_open_settings_win32(ma_uint32 openMode, DWORD* pDesiredAccess, DWORD* pShareMode, DWORD* pCreationDisposition)
{
*pDesiredAccess = 0;
@@ -57135,6 +59000,9 @@ static ma_result ma_default_vfs_open__win32(ma_vfs* pVFS, const char* pFilePath,
(void)pVFS;
+ /* Load some Win32 symbols dynamically so we can dynamically check for the existence of SetFilePointerEx. */
+ ma_win32_fileio_init();
+
ma_default_vfs__get_open_settings_win32(openMode, &dwDesiredAccess, &dwShareMode, &dwCreationDisposition);
hFile = CreateFileA(pFilePath, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, FILE_ATTRIBUTE_NORMAL, NULL);
@@ -57155,6 +59023,9 @@ static ma_result ma_default_vfs_open_w__win32(ma_vfs* pVFS, const wchar_t* pFile
(void)pVFS;
+ /* Load some Win32 symbols dynamically so we can dynamically check for the existence of SetFilePointerEx. */
+ ma_win32_fileio_init();
+
ma_default_vfs__get_open_settings_win32(openMode, &dwDesiredAccess, &dwShareMode, &dwCreationDisposition);
hFile = CreateFileW(pFilePath, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, FILE_ATTRIBUTE_NORMAL, NULL);
@@ -57280,16 +59151,19 @@ static ma_result ma_default_vfs_seek__win32(ma_vfs* pVFS, ma_vfs_file file, ma_i
dwMoveMethod = FILE_BEGIN;
}
-#if (defined(_MSC_VER) && _MSC_VER <= 1200) || defined(__DMC__)
- /* No SetFilePointerEx() so restrict to 31 bits. */
- if (origin > 0x7FFFFFFF) {
- return MA_OUT_OF_RANGE;
+ if (ma_SetFilePointerEx != NULL) {
+ result = ma_SetFilePointerEx((HANDLE)file, liDistanceToMove, NULL, dwMoveMethod);
+ } else if (ma_SetFilePointer != NULL) {
+ /* No SetFilePointerEx() so restrict to 31 bits. */
+ if (origin > 0x7FFFFFFF) {
+ return MA_OUT_OF_RANGE;
+ }
+
+ result = ma_SetFilePointer((HANDLE)file, (LONG)liDistanceToMove.QuadPart, NULL, dwMoveMethod);
+ } else {
+ return MA_NOT_IMPLEMENTED;
}
- result = SetFilePointer((HANDLE)file, (LONG)liDistanceToMove.QuadPart, NULL, dwMoveMethod);
-#else
- result = SetFilePointerEx((HANDLE)file, liDistanceToMove, NULL, dwMoveMethod);
-#endif
if (result == 0) {
return ma_result_from_GetLastError(GetLastError());
}
@@ -57302,20 +59176,22 @@ static ma_result ma_default_vfs_tell__win32(ma_vfs* pVFS, ma_vfs_file file, ma_i
LARGE_INTEGER liZero;
LARGE_INTEGER liTell;
BOOL result;
-#if (defined(_MSC_VER) && _MSC_VER <= 1200) || defined(__DMC__)
- LONG tell;
-#endif
(void)pVFS;
liZero.QuadPart = 0;
-#if (defined(_MSC_VER) && _MSC_VER <= 1200) || defined(__DMC__)
- result = SetFilePointer((HANDLE)file, (LONG)liZero.QuadPart, &tell, FILE_CURRENT);
- liTell.QuadPart = tell;
-#else
- result = SetFilePointerEx((HANDLE)file, liZero, &liTell, FILE_CURRENT);
-#endif
+ if (ma_SetFilePointerEx != NULL) {
+ result = ma_SetFilePointerEx((HANDLE)file, liZero, &liTell, FILE_CURRENT);
+ } else if (ma_SetFilePointer != NULL) {
+ LONG tell;
+
+ result = ma_SetFilePointer((HANDLE)file, (LONG)liZero.QuadPart, &tell, FILE_CURRENT);
+ liTell.QuadPart = tell;
+ } else {
+ return MA_NOT_IMPLEMENTED;
+ }
+
if (result == 0) {
return ma_result_from_GetLastError(GetLastError());
}
@@ -57572,7 +59448,7 @@ static ma_result ma_default_vfs_open(ma_vfs* pVFS, const char* pFilePath, ma_uin
return MA_INVALID_ARGS;
}
-#if defined(MA_WIN32) && defined(MA_WIN32_DESKTOP) && !defined(MA_NO_WIN32_FILEIO)
+#if defined(MA_USE_WIN32_FILEIO)
return ma_default_vfs_open__win32(pVFS, pFilePath, openMode, pFile);
#else
return ma_default_vfs_open__stdio(pVFS, pFilePath, openMode, pFile);
@@ -57591,7 +59467,7 @@ static ma_result ma_default_vfs_open_w(ma_vfs* pVFS, const wchar_t* pFilePath, m
return MA_INVALID_ARGS;
}
-#if defined(MA_WIN32) && defined(MA_WIN32_DESKTOP) && !defined(MA_NO_WIN32_FILEIO)
+#if defined(MA_USE_WIN32_FILEIO)
return ma_default_vfs_open_w__win32(pVFS, pFilePath, openMode, pFile);
#else
return ma_default_vfs_open_w__stdio(pVFS, pFilePath, openMode, pFile);
@@ -57604,7 +59480,7 @@ static ma_result ma_default_vfs_close(ma_vfs* pVFS, ma_vfs_file file)
return MA_INVALID_ARGS;
}
-#if defined(MA_WIN32) && defined(MA_WIN32_DESKTOP) && !defined(MA_NO_WIN32_FILEIO)
+#if defined(MA_USE_WIN32_FILEIO)
return ma_default_vfs_close__win32(pVFS, file);
#else
return ma_default_vfs_close__stdio(pVFS, file);
@@ -57621,7 +59497,7 @@ static ma_result ma_default_vfs_read(ma_vfs* pVFS, ma_vfs_file file, void* pDst,
return MA_INVALID_ARGS;
}
-#if defined(MA_WIN32) && defined(MA_WIN32_DESKTOP) && !defined(MA_NO_WIN32_FILEIO)
+#if defined(MA_USE_WIN32_FILEIO)
return ma_default_vfs_read__win32(pVFS, file, pDst, sizeInBytes, pBytesRead);
#else
return ma_default_vfs_read__stdio(pVFS, file, pDst, sizeInBytes, pBytesRead);
@@ -57638,7 +59514,7 @@ static ma_result ma_default_vfs_write(ma_vfs* pVFS, ma_vfs_file file, const void
return MA_INVALID_ARGS;
}
-#if defined(MA_WIN32) && defined(MA_WIN32_DESKTOP) && !defined(MA_NO_WIN32_FILEIO)
+#if defined(MA_USE_WIN32_FILEIO)
return ma_default_vfs_write__win32(pVFS, file, pSrc, sizeInBytes, pBytesWritten);
#else
return ma_default_vfs_write__stdio(pVFS, file, pSrc, sizeInBytes, pBytesWritten);
@@ -57651,7 +59527,7 @@ static ma_result ma_default_vfs_seek(ma_vfs* pVFS, ma_vfs_file file, ma_int64 of
return MA_INVALID_ARGS;
}
-#if defined(MA_WIN32) && defined(MA_WIN32_DESKTOP) && !defined(MA_NO_WIN32_FILEIO)
+#if defined(MA_USE_WIN32_FILEIO)
return ma_default_vfs_seek__win32(pVFS, file, offset, origin);
#else
return ma_default_vfs_seek__stdio(pVFS, file, offset, origin);
@@ -57670,7 +59546,7 @@ static ma_result ma_default_vfs_tell(ma_vfs* pVFS, ma_vfs_file file, ma_int64* p
return MA_INVALID_ARGS;
}
-#if defined(MA_WIN32) && defined(MA_WIN32_DESKTOP) && !defined(MA_NO_WIN32_FILEIO)
+#if defined(MA_USE_WIN32_FILEIO)
return ma_default_vfs_tell__win32(pVFS, file, pCursor);
#else
return ma_default_vfs_tell__stdio(pVFS, file, pCursor);
@@ -57689,7 +59565,7 @@ static ma_result ma_default_vfs_info(ma_vfs* pVFS, ma_vfs_file file, ma_file_inf
return MA_INVALID_ARGS;
}
-#if defined(MA_WIN32) && defined(MA_WIN32_DESKTOP) && !defined(MA_NO_WIN32_FILEIO)
+#if defined(MA_USE_WIN32_FILEIO)
return ma_default_vfs_info__win32(pVFS, file, pInfo);
#else
return ma_default_vfs_info__stdio(pVFS, file, pInfo);
@@ -57791,6 +59667,81 @@ MA_API ma_result ma_vfs_or_default_info(ma_vfs* pVFS, ma_vfs_file file, ma_file_
+static ma_result ma_vfs_open_and_read_file_ex(ma_vfs* pVFS, const char* pFilePath, const wchar_t* pFilePathW, void** ppData, size_t* pSize, const ma_allocation_callbacks* pAllocationCallbacks)
+{
+ ma_result result;
+ ma_vfs_file file;
+ ma_file_info info;
+ void* pData;
+ size_t bytesRead;
+
+ if (ppData != NULL) {
+ *ppData = NULL;
+ }
+ if (pSize != NULL) {
+ *pSize = 0;
+ }
+
+ if (ppData == NULL) {
+ return MA_INVALID_ARGS;
+ }
+
+ if (pFilePath != NULL) {
+ result = ma_vfs_or_default_open(pVFS, pFilePath, MA_OPEN_MODE_READ, &file);
+ } else {
+ result = ma_vfs_or_default_open_w(pVFS, pFilePathW, MA_OPEN_MODE_READ, &file);
+ }
+ if (result != MA_SUCCESS) {
+ return result;
+ }
+
+ result = ma_vfs_or_default_info(pVFS, file, &info);
+ if (result != MA_SUCCESS) {
+ ma_vfs_or_default_close(pVFS, file);
+ return result;
+ }
+
+ if (info.sizeInBytes > MA_SIZE_MAX) {
+ ma_vfs_or_default_close(pVFS, file);
+ return MA_TOO_BIG;
+ }
+
+ pData = ma_malloc((size_t)info.sizeInBytes, pAllocationCallbacks); /* Safe cast. */
+ if (pData == NULL) {
+ ma_vfs_or_default_close(pVFS, file);
+ return result;
+ }
+
+ result = ma_vfs_or_default_read(pVFS, file, pData, (size_t)info.sizeInBytes, &bytesRead); /* Safe cast. */
+ ma_vfs_or_default_close(pVFS, file);
+
+ if (result != MA_SUCCESS) {
+ ma_free(pData, pAllocationCallbacks);
+ return result;
+ }
+
+ if (pSize != NULL) {
+ *pSize = bytesRead;
+ }
+
+ MA_ASSERT(ppData != NULL);
+ *ppData = pData;
+
+ return MA_SUCCESS;
+}
+
+MA_API ma_result ma_vfs_open_and_read_file(ma_vfs* pVFS, const char* pFilePath, void** ppData, size_t* pSize, const ma_allocation_callbacks* pAllocationCallbacks)
+{
+ return ma_vfs_open_and_read_file_ex(pVFS, pFilePath, NULL, ppData, pSize, pAllocationCallbacks);
+}
+
+MA_API ma_result ma_vfs_open_and_read_file_w(ma_vfs* pVFS, const wchar_t* pFilePath, void** ppData, size_t* pSize, const ma_allocation_callbacks* pAllocationCallbacks)
+{
+ return ma_vfs_open_and_read_file_ex(pVFS, NULL, pFilePath, ppData, pSize, pAllocationCallbacks);
+}
+
+
+
/**************************************************************************************************************************************************************
Decoding and Encoding Headers. These are auto-generated from a tool.
@@ -57798,195 +59749,76 @@ Decoding and Encoding Headers. These are auto-generated from a tool.
**************************************************************************************************************************************************************/
#if !defined(MA_NO_WAV) && (!defined(MA_NO_DECODING) || !defined(MA_NO_ENCODING))
/* dr_wav_h begin */
-#ifndef dr_wav_h
-#define dr_wav_h
+#ifndef ma_dr_wav_h
+#define ma_dr_wav_h
#ifdef __cplusplus
extern "C" {
#endif
-#define DRWAV_STRINGIFY(x) #x
-#define DRWAV_XSTRINGIFY(x) DRWAV_STRINGIFY(x)
-#define DRWAV_VERSION_MAJOR 0
-#define DRWAV_VERSION_MINOR 13
-#define DRWAV_VERSION_REVISION 7
-#define DRWAV_VERSION_STRING DRWAV_XSTRINGIFY(DRWAV_VERSION_MAJOR) "." DRWAV_XSTRINGIFY(DRWAV_VERSION_MINOR) "." DRWAV_XSTRINGIFY(DRWAV_VERSION_REVISION)
+#define MA_DR_WAV_STRINGIFY(x) #x
+#define MA_DR_WAV_XSTRINGIFY(x) MA_DR_WAV_STRINGIFY(x)
+#define MA_DR_WAV_VERSION_MAJOR 0
+#define MA_DR_WAV_VERSION_MINOR 13
+#define MA_DR_WAV_VERSION_REVISION 13
+#define MA_DR_WAV_VERSION_STRING MA_DR_WAV_XSTRINGIFY(MA_DR_WAV_VERSION_MAJOR) "." MA_DR_WAV_XSTRINGIFY(MA_DR_WAV_VERSION_MINOR) "." MA_DR_WAV_XSTRINGIFY(MA_DR_WAV_VERSION_REVISION)
#include
-typedef signed char drwav_int8;
-typedef unsigned char drwav_uint8;
-typedef signed short drwav_int16;
-typedef unsigned short drwav_uint16;
-typedef signed int drwav_int32;
-typedef unsigned int drwav_uint32;
-#if defined(_MSC_VER) && !defined(__clang__)
- typedef signed __int64 drwav_int64;
- typedef unsigned __int64 drwav_uint64;
-#else
- #if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)))
- #pragma GCC diagnostic push
- #pragma GCC diagnostic ignored "-Wlong-long"
- #if defined(__clang__)
- #pragma GCC diagnostic ignored "-Wc++11-long-long"
- #endif
- #endif
- typedef signed long long drwav_int64;
- typedef unsigned long long drwav_uint64;
- #if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)))
- #pragma GCC diagnostic pop
- #endif
-#endif
-#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__)) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(_M_ARM64) || defined(__powerpc64__)
- typedef drwav_uint64 drwav_uintptr;
-#else
- typedef drwav_uint32 drwav_uintptr;
-#endif
-typedef drwav_uint8 drwav_bool8;
-typedef drwav_uint32 drwav_bool32;
-#define DRWAV_TRUE 1
-#define DRWAV_FALSE 0
-#if !defined(DRWAV_API)
- #if defined(DRWAV_DLL)
- #if defined(_WIN32)
- #define DRWAV_DLL_IMPORT __declspec(dllimport)
- #define DRWAV_DLL_EXPORT __declspec(dllexport)
- #define DRWAV_DLL_PRIVATE static
- #else
- #if defined(__GNUC__) && __GNUC__ >= 4
- #define DRWAV_DLL_IMPORT __attribute__((visibility("default")))
- #define DRWAV_DLL_EXPORT __attribute__((visibility("default")))
- #define DRWAV_DLL_PRIVATE __attribute__((visibility("hidden")))
- #else
- #define DRWAV_DLL_IMPORT
- #define DRWAV_DLL_EXPORT
- #define DRWAV_DLL_PRIVATE static
- #endif
- #endif
- #if defined(DR_WAV_IMPLEMENTATION) || defined(DRWAV_IMPLEMENTATION)
- #define DRWAV_API DRWAV_DLL_EXPORT
- #else
- #define DRWAV_API DRWAV_DLL_IMPORT
- #endif
- #define DRWAV_PRIVATE DRWAV_DLL_PRIVATE
- #else
- #define DRWAV_API extern
- #define DRWAV_PRIVATE static
- #endif
-#endif
-typedef drwav_int32 drwav_result;
-#define DRWAV_SUCCESS 0
-#define DRWAV_ERROR -1
-#define DRWAV_INVALID_ARGS -2
-#define DRWAV_INVALID_OPERATION -3
-#define DRWAV_OUT_OF_MEMORY -4
-#define DRWAV_OUT_OF_RANGE -5
-#define DRWAV_ACCESS_DENIED -6
-#define DRWAV_DOES_NOT_EXIST -7
-#define DRWAV_ALREADY_EXISTS -8
-#define DRWAV_TOO_MANY_OPEN_FILES -9
-#define DRWAV_INVALID_FILE -10
-#define DRWAV_TOO_BIG -11
-#define DRWAV_PATH_TOO_LONG -12
-#define DRWAV_NAME_TOO_LONG -13
-#define DRWAV_NOT_DIRECTORY -14
-#define DRWAV_IS_DIRECTORY -15
-#define DRWAV_DIRECTORY_NOT_EMPTY -16
-#define DRWAV_END_OF_FILE -17
-#define DRWAV_NO_SPACE -18
-#define DRWAV_BUSY -19
-#define DRWAV_IO_ERROR -20
-#define DRWAV_INTERRUPT -21
-#define DRWAV_UNAVAILABLE -22
-#define DRWAV_ALREADY_IN_USE -23
-#define DRWAV_BAD_ADDRESS -24
-#define DRWAV_BAD_SEEK -25
-#define DRWAV_BAD_PIPE -26
-#define DRWAV_DEADLOCK -27
-#define DRWAV_TOO_MANY_LINKS -28
-#define DRWAV_NOT_IMPLEMENTED -29
-#define DRWAV_NO_MESSAGE -30
-#define DRWAV_BAD_MESSAGE -31
-#define DRWAV_NO_DATA_AVAILABLE -32
-#define DRWAV_INVALID_DATA -33
-#define DRWAV_TIMEOUT -34
-#define DRWAV_NO_NETWORK -35
-#define DRWAV_NOT_UNIQUE -36
-#define DRWAV_NOT_SOCKET -37
-#define DRWAV_NO_ADDRESS -38
-#define DRWAV_BAD_PROTOCOL -39
-#define DRWAV_PROTOCOL_UNAVAILABLE -40
-#define DRWAV_PROTOCOL_NOT_SUPPORTED -41
-#define DRWAV_PROTOCOL_FAMILY_NOT_SUPPORTED -42
-#define DRWAV_ADDRESS_FAMILY_NOT_SUPPORTED -43
-#define DRWAV_SOCKET_NOT_SUPPORTED -44
-#define DRWAV_CONNECTION_RESET -45
-#define DRWAV_ALREADY_CONNECTED -46
-#define DRWAV_NOT_CONNECTED -47
-#define DRWAV_CONNECTION_REFUSED -48
-#define DRWAV_NO_HOST -49
-#define DRWAV_IN_PROGRESS -50
-#define DRWAV_CANCELLED -51
-#define DRWAV_MEMORY_ALREADY_MAPPED -52
-#define DRWAV_AT_END -53
-#define DR_WAVE_FORMAT_PCM 0x1
-#define DR_WAVE_FORMAT_ADPCM 0x2
-#define DR_WAVE_FORMAT_IEEE_FLOAT 0x3
-#define DR_WAVE_FORMAT_ALAW 0x6
-#define DR_WAVE_FORMAT_MULAW 0x7
-#define DR_WAVE_FORMAT_DVI_ADPCM 0x11
-#define DR_WAVE_FORMAT_EXTENSIBLE 0xFFFE
-#define DRWAV_SEQUENTIAL 0x00000001
-DRWAV_API void drwav_version(drwav_uint32* pMajor, drwav_uint32* pMinor, drwav_uint32* pRevision);
-DRWAV_API const char* drwav_version_string(void);
+#define MA_DR_WAVE_FORMAT_PCM 0x1
+#define MA_DR_WAVE_FORMAT_ADPCM 0x2
+#define MA_DR_WAVE_FORMAT_IEEE_FLOAT 0x3
+#define MA_DR_WAVE_FORMAT_ALAW 0x6
+#define MA_DR_WAVE_FORMAT_MULAW 0x7
+#define MA_DR_WAVE_FORMAT_DVI_ADPCM 0x11
+#define MA_DR_WAVE_FORMAT_EXTENSIBLE 0xFFFE
+#define MA_DR_WAV_SEQUENTIAL 0x00000001
+#define MA_DR_WAV_WITH_METADATA 0x00000002
+MA_API void ma_dr_wav_version(ma_uint32* pMajor, ma_uint32* pMinor, ma_uint32* pRevision);
+MA_API const char* ma_dr_wav_version_string(void);
typedef enum
{
- drwav_seek_origin_start,
- drwav_seek_origin_current
-} drwav_seek_origin;
+ ma_dr_wav_seek_origin_start,
+ ma_dr_wav_seek_origin_current
+} ma_dr_wav_seek_origin;
typedef enum
{
- drwav_container_riff,
- drwav_container_w64,
- drwav_container_rf64
-} drwav_container;
+ ma_dr_wav_container_riff,
+ ma_dr_wav_container_rifx,
+ ma_dr_wav_container_w64,
+ ma_dr_wav_container_rf64,
+ ma_dr_wav_container_aiff
+} ma_dr_wav_container;
typedef struct
{
union
{
- drwav_uint8 fourcc[4];
- drwav_uint8 guid[16];
+ ma_uint8 fourcc[4];
+ ma_uint8 guid[16];
} id;
- drwav_uint64 sizeInBytes;
+ ma_uint64 sizeInBytes;
unsigned int paddingSize;
-} drwav_chunk_header;
+} ma_dr_wav_chunk_header;
typedef struct
{
- drwav_uint16 formatTag;
- drwav_uint16 channels;
- drwav_uint32 sampleRate;
- drwav_uint32 avgBytesPerSec;
- drwav_uint16 blockAlign;
- drwav_uint16 bitsPerSample;
- drwav_uint16 extendedSize;
- drwav_uint16 validBitsPerSample;
- drwav_uint32 channelMask;
- drwav_uint8 subFormat[16];
-} drwav_fmt;
-DRWAV_API drwav_uint16 drwav_fmt_get_format(const drwav_fmt* pFMT);
-typedef size_t (* drwav_read_proc)(void* pUserData, void* pBufferOut, size_t bytesToRead);
-typedef size_t (* drwav_write_proc)(void* pUserData, const void* pData, size_t bytesToWrite);
-typedef drwav_bool32 (* drwav_seek_proc)(void* pUserData, int offset, drwav_seek_origin origin);
-typedef drwav_uint64 (* drwav_chunk_proc)(void* pChunkUserData, drwav_read_proc onRead, drwav_seek_proc onSeek, void* pReadSeekUserData, const drwav_chunk_header* pChunkHeader, drwav_container container, const drwav_fmt* pFMT);
-typedef struct
-{
- void* pUserData;
- void* (* onMalloc)(size_t sz, void* pUserData);
- void* (* onRealloc)(void* p, size_t sz, void* pUserData);
- void (* onFree)(void* p, void* pUserData);
-} drwav_allocation_callbacks;
+ ma_uint16 formatTag;
+ ma_uint16 channels;
+ ma_uint32 sampleRate;
+ ma_uint32 avgBytesPerSec;
+ ma_uint16 blockAlign;
+ ma_uint16 bitsPerSample;
+ ma_uint16 extendedSize;
+ ma_uint16 validBitsPerSample;
+ ma_uint32 channelMask;
+ ma_uint8 subFormat[16];
+} ma_dr_wav_fmt;
+MA_API ma_uint16 ma_dr_wav_fmt_get_format(const ma_dr_wav_fmt* pFMT);
+typedef size_t (* ma_dr_wav_read_proc)(void* pUserData, void* pBufferOut, size_t bytesToRead);
+typedef size_t (* ma_dr_wav_write_proc)(void* pUserData, const void* pData, size_t bytesToWrite);
+typedef ma_bool32 (* ma_dr_wav_seek_proc)(void* pUserData, int offset, ma_dr_wav_seek_origin origin);
+typedef ma_uint64 (* ma_dr_wav_chunk_proc)(void* pChunkUserData, ma_dr_wav_read_proc onRead, ma_dr_wav_seek_proc onSeek, void* pReadSeekUserData, const ma_dr_wav_chunk_header* pChunkHeader, ma_dr_wav_container container, const ma_dr_wav_fmt* pFMT);
typedef struct
{
- const drwav_uint8* data;
+ const ma_uint8* data;
size_t dataSize;
size_t currentReadPos;
-} drwav__memory_stream;
+} ma_dr_wav__memory_stream;
typedef struct
{
void** ppData;
@@ -57994,129 +59826,129 @@ typedef struct
size_t dataSize;
size_t dataCapacity;
size_t currentWritePos;
-} drwav__memory_stream_write;
+} ma_dr_wav__memory_stream_write;
typedef struct
{
- drwav_container container;
- drwav_uint32 format;
- drwav_uint32 channels;
- drwav_uint32 sampleRate;
- drwav_uint32 bitsPerSample;
-} drwav_data_format;
+ ma_dr_wav_container container;
+ ma_uint32 format;
+ ma_uint32 channels;
+ ma_uint32 sampleRate;
+ ma_uint32 bitsPerSample;
+} ma_dr_wav_data_format;
typedef enum
{
- drwav_metadata_type_none = 0,
- drwav_metadata_type_unknown = 1 << 0,
- drwav_metadata_type_smpl = 1 << 1,
- drwav_metadata_type_inst = 1 << 2,
- drwav_metadata_type_cue = 1 << 3,
- drwav_metadata_type_acid = 1 << 4,
- drwav_metadata_type_bext = 1 << 5,
- drwav_metadata_type_list_label = 1 << 6,
- drwav_metadata_type_list_note = 1 << 7,
- drwav_metadata_type_list_labelled_cue_region = 1 << 8,
- drwav_metadata_type_list_info_software = 1 << 9,
- drwav_metadata_type_list_info_copyright = 1 << 10,
- drwav_metadata_type_list_info_title = 1 << 11,
- drwav_metadata_type_list_info_artist = 1 << 12,
- drwav_metadata_type_list_info_comment = 1 << 13,
- drwav_metadata_type_list_info_date = 1 << 14,
- drwav_metadata_type_list_info_genre = 1 << 15,
- drwav_metadata_type_list_info_album = 1 << 16,
- drwav_metadata_type_list_info_tracknumber = 1 << 17,
- drwav_metadata_type_list_all_info_strings = drwav_metadata_type_list_info_software
- | drwav_metadata_type_list_info_copyright
- | drwav_metadata_type_list_info_title
- | drwav_metadata_type_list_info_artist
- | drwav_metadata_type_list_info_comment
- | drwav_metadata_type_list_info_date
- | drwav_metadata_type_list_info_genre
- | drwav_metadata_type_list_info_album
- | drwav_metadata_type_list_info_tracknumber,
- drwav_metadata_type_list_all_adtl = drwav_metadata_type_list_label
- | drwav_metadata_type_list_note
- | drwav_metadata_type_list_labelled_cue_region,
- drwav_metadata_type_all = -2,
- drwav_metadata_type_all_including_unknown = -1
-} drwav_metadata_type;
+ ma_dr_wav_metadata_type_none = 0,
+ ma_dr_wav_metadata_type_unknown = 1 << 0,
+ ma_dr_wav_metadata_type_smpl = 1 << 1,
+ ma_dr_wav_metadata_type_inst = 1 << 2,
+ ma_dr_wav_metadata_type_cue = 1 << 3,
+ ma_dr_wav_metadata_type_acid = 1 << 4,
+ ma_dr_wav_metadata_type_bext = 1 << 5,
+ ma_dr_wav_metadata_type_list_label = 1 << 6,
+ ma_dr_wav_metadata_type_list_note = 1 << 7,
+ ma_dr_wav_metadata_type_list_labelled_cue_region = 1 << 8,
+ ma_dr_wav_metadata_type_list_info_software = 1 << 9,
+ ma_dr_wav_metadata_type_list_info_copyright = 1 << 10,
+ ma_dr_wav_metadata_type_list_info_title = 1 << 11,
+ ma_dr_wav_metadata_type_list_info_artist = 1 << 12,
+ ma_dr_wav_metadata_type_list_info_comment = 1 << 13,
+ ma_dr_wav_metadata_type_list_info_date = 1 << 14,
+ ma_dr_wav_metadata_type_list_info_genre = 1 << 15,
+ ma_dr_wav_metadata_type_list_info_album = 1 << 16,
+ ma_dr_wav_metadata_type_list_info_tracknumber = 1 << 17,
+ ma_dr_wav_metadata_type_list_all_info_strings = ma_dr_wav_metadata_type_list_info_software
+ | ma_dr_wav_metadata_type_list_info_copyright
+ | ma_dr_wav_metadata_type_list_info_title
+ | ma_dr_wav_metadata_type_list_info_artist
+ | ma_dr_wav_metadata_type_list_info_comment
+ | ma_dr_wav_metadata_type_list_info_date
+ | ma_dr_wav_metadata_type_list_info_genre
+ | ma_dr_wav_metadata_type_list_info_album
+ | ma_dr_wav_metadata_type_list_info_tracknumber,
+ ma_dr_wav_metadata_type_list_all_adtl = ma_dr_wav_metadata_type_list_label
+ | ma_dr_wav_metadata_type_list_note
+ | ma_dr_wav_metadata_type_list_labelled_cue_region,
+ ma_dr_wav_metadata_type_all = -2,
+ ma_dr_wav_metadata_type_all_including_unknown = -1
+} ma_dr_wav_metadata_type;
typedef enum
{
- drwav_smpl_loop_type_forward = 0,
- drwav_smpl_loop_type_pingpong = 1,
- drwav_smpl_loop_type_backward = 2
-} drwav_smpl_loop_type;
+ ma_dr_wav_smpl_loop_type_forward = 0,
+ ma_dr_wav_smpl_loop_type_pingpong = 1,
+ ma_dr_wav_smpl_loop_type_backward = 2
+} ma_dr_wav_smpl_loop_type;
typedef struct
{
- drwav_uint32 cuePointId;
- drwav_uint32 type;
- drwav_uint32 firstSampleByteOffset;
- drwav_uint32 lastSampleByteOffset;
- drwav_uint32 sampleFraction;
- drwav_uint32 playCount;
-} drwav_smpl_loop;
+ ma_uint32 cuePointId;
+ ma_uint32 type;
+ ma_uint32 firstSampleByteOffset;
+ ma_uint32 lastSampleByteOffset;
+ ma_uint32 sampleFraction;
+ ma_uint32 playCount;
+} ma_dr_wav_smpl_loop;
typedef struct
{
- drwav_uint32 manufacturerId;
- drwav_uint32 productId;
- drwav_uint32 samplePeriodNanoseconds;
- drwav_uint32 midiUnityNote;
- drwav_uint32 midiPitchFraction;
- drwav_uint32 smpteFormat;
- drwav_uint32 smpteOffset;
- drwav_uint32 sampleLoopCount;
- drwav_uint32 samplerSpecificDataSizeInBytes;
- drwav_smpl_loop* pLoops;
- drwav_uint8* pSamplerSpecificData;
-} drwav_smpl;
+ ma_uint32 manufacturerId;
+ ma_uint32 productId;
+ ma_uint32 samplePeriodNanoseconds;
+ ma_uint32 midiUnityNote;
+ ma_uint32 midiPitchFraction;
+ ma_uint32 smpteFormat;
+ ma_uint32 smpteOffset;
+ ma_uint32 sampleLoopCount;
+ ma_uint32 samplerSpecificDataSizeInBytes;
+ ma_dr_wav_smpl_loop* pLoops;
+ ma_uint8* pSamplerSpecificData;
+} ma_dr_wav_smpl;
typedef struct
{
- drwav_int8 midiUnityNote;
- drwav_int8 fineTuneCents;
- drwav_int8 gainDecibels;
- drwav_int8 lowNote;
- drwav_int8 highNote;
- drwav_int8 lowVelocity;
- drwav_int8 highVelocity;
-} drwav_inst;
+ ma_int8 midiUnityNote;
+ ma_int8 fineTuneCents;
+ ma_int8 gainDecibels;
+ ma_int8 lowNote;
+ ma_int8 highNote;
+ ma_int8 lowVelocity;
+ ma_int8 highVelocity;
+} ma_dr_wav_inst;
typedef struct
{
- drwav_uint32 id;
- drwav_uint32 playOrderPosition;
- drwav_uint8 dataChunkId[4];
- drwav_uint32 chunkStart;
- drwav_uint32 blockStart;
- drwav_uint32 sampleByteOffset;
-} drwav_cue_point;
+ ma_uint32 id;
+ ma_uint32 playOrderPosition;
+ ma_uint8 dataChunkId[4];
+ ma_uint32 chunkStart;
+ ma_uint32 blockStart;
+ ma_uint32 sampleByteOffset;
+} ma_dr_wav_cue_point;
typedef struct
{
- drwav_uint32 cuePointCount;
- drwav_cue_point *pCuePoints;
-} drwav_cue;
+ ma_uint32 cuePointCount;
+ ma_dr_wav_cue_point *pCuePoints;
+} ma_dr_wav_cue;
typedef enum
{
- drwav_acid_flag_one_shot = 1,
- drwav_acid_flag_root_note_set = 2,
- drwav_acid_flag_stretch = 4,
- drwav_acid_flag_disk_based = 8,
- drwav_acid_flag_acidizer = 16
-} drwav_acid_flag;
+ ma_dr_wav_acid_flag_one_shot = 1,
+ ma_dr_wav_acid_flag_root_note_set = 2,
+ ma_dr_wav_acid_flag_stretch = 4,
+ ma_dr_wav_acid_flag_disk_based = 8,
+ ma_dr_wav_acid_flag_acidizer = 16
+} ma_dr_wav_acid_flag;
typedef struct
{
- drwav_uint32 flags;
- drwav_uint16 midiUnityNote;
- drwav_uint16 reserved1;
+ ma_uint32 flags;
+ ma_uint16 midiUnityNote;
+ ma_uint16 reserved1;
float reserved2;
- drwav_uint32 numBeats;
- drwav_uint16 meterDenominator;
- drwav_uint16 meterNumerator;
+ ma_uint32 numBeats;
+ ma_uint16 meterDenominator;
+ ma_uint16 meterNumerator;
float tempo;
-} drwav_acid;
+} ma_dr_wav_acid;
typedef struct
{
- drwav_uint32 cuePointId;
- drwav_uint32 stringLength;
+ ma_uint32 cuePointId;
+ ma_uint32 stringLength;
char* pString;
-} drwav_list_label_or_note;
+} ma_dr_wav_list_label_or_note;
typedef struct
{
char* pDescription;
@@ -58124,206 +59956,210 @@ typedef struct
char* pOriginatorReference;
char pOriginationDate[10];
char pOriginationTime[8];
- drwav_uint64 timeReference;
- drwav_uint16 version;
+ ma_uint64 timeReference;
+ ma_uint16 version;
char* pCodingHistory;
- drwav_uint32 codingHistorySize;
- drwav_uint8* pUMID;
- drwav_uint16 loudnessValue;
- drwav_uint16 loudnessRange;
- drwav_uint16 maxTruePeakLevel;
- drwav_uint16 maxMomentaryLoudness;
- drwav_uint16 maxShortTermLoudness;
-} drwav_bext;
+ ma_uint32 codingHistorySize;
+ ma_uint8* pUMID;
+ ma_uint16 loudnessValue;
+ ma_uint16 loudnessRange;
+ ma_uint16 maxTruePeakLevel;
+ ma_uint16 maxMomentaryLoudness;
+ ma_uint16 maxShortTermLoudness;
+} ma_dr_wav_bext;
typedef struct
{
- drwav_uint32 stringLength;
+ ma_uint32 stringLength;
char* pString;
-} drwav_list_info_text;
+} ma_dr_wav_list_info_text;
typedef struct
{
- drwav_uint32 cuePointId;
- drwav_uint32 sampleLength;
- drwav_uint8 purposeId[4];
- drwav_uint16 country;
- drwav_uint16 language;
- drwav_uint16 dialect;
- drwav_uint16 codePage;
- drwav_uint32 stringLength;
+ ma_uint32 cuePointId;
+ ma_uint32 sampleLength;
+ ma_uint8 purposeId[4];
+ ma_uint16 country;
+ ma_uint16 language;
+ ma_uint16 dialect;
+ ma_uint16 codePage;
+ ma_uint32 stringLength;
char* pString;
-} drwav_list_labelled_cue_region;
+} ma_dr_wav_list_labelled_cue_region;
typedef enum
{
- drwav_metadata_location_invalid,
- drwav_metadata_location_top_level,
- drwav_metadata_location_inside_info_list,
- drwav_metadata_location_inside_adtl_list
-} drwav_metadata_location;
+ ma_dr_wav_metadata_location_invalid,
+ ma_dr_wav_metadata_location_top_level,
+ ma_dr_wav_metadata_location_inside_info_list,
+ ma_dr_wav_metadata_location_inside_adtl_list
+} ma_dr_wav_metadata_location;
typedef struct
{
- drwav_uint8 id[4];
- drwav_metadata_location chunkLocation;
- drwav_uint32 dataSizeInBytes;
- drwav_uint8* pData;
-} drwav_unknown_metadata;
+ ma_uint8 id[4];
+ ma_dr_wav_metadata_location chunkLocation;
+ ma_uint32 dataSizeInBytes;
+ ma_uint8* pData;
+} ma_dr_wav_unknown_metadata;
typedef struct
{
- drwav_metadata_type type;
+ ma_dr_wav_metadata_type type;
union
{
- drwav_cue cue;
- drwav_smpl smpl;
- drwav_acid acid;
- drwav_inst inst;
- drwav_bext bext;
- drwav_list_label_or_note labelOrNote;
- drwav_list_labelled_cue_region labelledCueRegion;
- drwav_list_info_text infoText;
- drwav_unknown_metadata unknown;
+ ma_dr_wav_cue cue;
+ ma_dr_wav_smpl smpl;
+ ma_dr_wav_acid acid;
+ ma_dr_wav_inst inst;
+ ma_dr_wav_bext bext;
+ ma_dr_wav_list_label_or_note labelOrNote;
+ ma_dr_wav_list_labelled_cue_region labelledCueRegion;
+ ma_dr_wav_list_info_text infoText;
+ ma_dr_wav_unknown_metadata unknown;
} data;
-} drwav_metadata;
+} ma_dr_wav_metadata;
typedef struct
{
- drwav_read_proc onRead;
- drwav_write_proc onWrite;
- drwav_seek_proc onSeek;
+ ma_dr_wav_read_proc onRead;
+ ma_dr_wav_write_proc onWrite;
+ ma_dr_wav_seek_proc onSeek;
void* pUserData;
- drwav_allocation_callbacks allocationCallbacks;
- drwav_container container;
- drwav_fmt fmt;
- drwav_uint32 sampleRate;
- drwav_uint16 channels;
- drwav_uint16 bitsPerSample;
- drwav_uint16 translatedFormatTag;
- drwav_uint64 totalPCMFrameCount;
- drwav_uint64 dataChunkDataSize;
- drwav_uint64 dataChunkDataPos;
- drwav_uint64 bytesRemaining;
- drwav_uint64 readCursorInPCMFrames;
- drwav_uint64 dataChunkDataSizeTargetWrite;
- drwav_bool32 isSequentialWrite;
- drwav_metadata_type allowedMetadataTypes;
- drwav_metadata* pMetadata;
- drwav_uint32 metadataCount;
- drwav__memory_stream memoryStream;
- drwav__memory_stream_write memoryStreamWrite;
+ ma_allocation_callbacks allocationCallbacks;
+ ma_dr_wav_container container;
+ ma_dr_wav_fmt fmt;
+ ma_uint32 sampleRate;
+ ma_uint16 channels;
+ ma_uint16 bitsPerSample;
+ ma_uint16 translatedFormatTag;
+ ma_uint64 totalPCMFrameCount;
+ ma_uint64 dataChunkDataSize;
+ ma_uint64 dataChunkDataPos;
+ ma_uint64 bytesRemaining;
+ ma_uint64 readCursorInPCMFrames;
+ ma_uint64 dataChunkDataSizeTargetWrite;
+ ma_bool32 isSequentialWrite;
+ ma_dr_wav_metadata* pMetadata;
+ ma_uint32 metadataCount;
+ ma_dr_wav__memory_stream memoryStream;
+ ma_dr_wav__memory_stream_write memoryStreamWrite;
struct
{
- drwav_uint32 bytesRemainingInBlock;
- drwav_uint16 predictor[2];
- drwav_int32 delta[2];
- drwav_int32 cachedFrames[4];
- drwav_uint32 cachedFrameCount;
- drwav_int32 prevFrames[2][2];
+ ma_uint32 bytesRemainingInBlock;
+ ma_uint16 predictor[2];
+ ma_int32 delta[2];
+ ma_int32 cachedFrames[4];
+ ma_uint32 cachedFrameCount;
+ ma_int32 prevFrames[2][2];
} msadpcm;
struct
{
- drwav_uint32 bytesRemainingInBlock;
- drwav_int32 predictor[2];
- drwav_int32 stepIndex[2];
- drwav_int32 cachedFrames[16];
- drwav_uint32 cachedFrameCount;
+ ma_uint32 bytesRemainingInBlock;
+ ma_int32 predictor[2];
+ ma_int32 stepIndex[2];
+ ma_int32 cachedFrames[16];
+ ma_uint32 cachedFrameCount;
} ima;
-} drwav;
-DRWAV_API drwav_bool32 drwav_init(drwav* pWav, drwav_read_proc onRead, drwav_seek_proc onSeek, void* pUserData, const drwav_allocation_callbacks* pAllocationCallbacks);
-DRWAV_API drwav_bool32 drwav_init_ex(drwav* pWav, drwav_read_proc onRead, drwav_seek_proc onSeek, drwav_chunk_proc onChunk, void* pReadSeekUserData, void* pChunkUserData, drwav_uint32 flags, const drwav_allocation_callbacks* pAllocationCallbacks);
-DRWAV_API drwav_bool32 drwav_init_with_metadata(drwav* pWav, drwav_read_proc onRead, drwav_seek_proc onSeek, void* pUserData, drwav_uint32 flags, const drwav_allocation_callbacks* pAllocationCallbacks);
-DRWAV_API drwav_bool32 drwav_init_write(drwav* pWav, const drwav_data_format* pFormat, drwav_write_proc onWrite, drwav_seek_proc onSeek, void* pUserData, const drwav_allocation_callbacks* pAllocationCallbacks);
-DRWAV_API drwav_bool32 drwav_init_write_sequential(drwav* pWav, const drwav_data_format* pFormat, drwav_uint64 totalSampleCount, drwav_write_proc onWrite, void* pUserData, const drwav_allocation_callbacks* pAllocationCallbacks);
-DRWAV_API drwav_bool32 drwav_init_write_sequential_pcm_frames(drwav* pWav, const drwav_data_format* pFormat, drwav_uint64 totalPCMFrameCount, drwav_write_proc onWrite, void* pUserData, const drwav_allocation_callbacks* pAllocationCallbacks);
-DRWAV_API drwav_bool32 drwav_init_write_with_metadata(drwav* pWav, const drwav_data_format* pFormat, drwav_write_proc onWrite, drwav_seek_proc onSeek, void* pUserData, const drwav_allocation_callbacks* pAllocationCallbacks, drwav_metadata* pMetadata, drwav_uint32 metadataCount);
-DRWAV_API drwav_uint64 drwav_target_write_size_bytes(const drwav_data_format* pFormat, drwav_uint64 totalFrameCount, drwav_metadata* pMetadata, drwav_uint32 metadataCount);
-DRWAV_API drwav_metadata* drwav_take_ownership_of_metadata(drwav* pWav);
-DRWAV_API drwav_result drwav_uninit(drwav* pWav);
-DRWAV_API size_t drwav_read_raw(drwav* pWav, size_t bytesToRead, void* pBufferOut);
-DRWAV_API drwav_uint64 drwav_read_pcm_frames(drwav* pWav, drwav_uint64 framesToRead, void* pBufferOut);
-DRWAV_API drwav_uint64 drwav_read_pcm_frames_le(drwav* pWav, drwav_uint64 framesToRead, void* pBufferOut);
-DRWAV_API drwav_uint64 drwav_read_pcm_frames_be(drwav* pWav, drwav_uint64 framesToRead, void* pBufferOut);
-DRWAV_API drwav_bool32 drwav_seek_to_pcm_frame(drwav* pWav, drwav_uint64 targetFrameIndex);
-DRWAV_API drwav_result drwav_get_cursor_in_pcm_frames(drwav* pWav, drwav_uint64* pCursor);
-DRWAV_API drwav_result drwav_get_length_in_pcm_frames(drwav* pWav, drwav_uint64* pLength);
-DRWAV_API size_t drwav_write_raw(drwav* pWav, size_t bytesToWrite, const void* pData);
-DRWAV_API drwav_uint64 drwav_write_pcm_frames(drwav* pWav, drwav_uint64 framesToWrite, const void* pData);
-DRWAV_API drwav_uint64 drwav_write_pcm_frames_le(drwav* pWav, drwav_uint64 framesToWrite, const void* pData);
-DRWAV_API drwav_uint64 drwav_write_pcm_frames_be(drwav* pWav, drwav_uint64 framesToWrite, const void* pData);
-#ifndef DR_WAV_NO_CONVERSION_API
-DRWAV_API drwav_uint64 drwav_read_pcm_frames_s16(drwav* pWav, drwav_uint64 framesToRead, drwav_int16* pBufferOut);
-DRWAV_API drwav_uint64 drwav_read_pcm_frames_s16le(drwav* pWav, drwav_uint64 framesToRead, drwav_int16* pBufferOut);
-DRWAV_API drwav_uint64 drwav_read_pcm_frames_s16be(drwav* pWav, drwav_uint64 framesToRead, drwav_int16* pBufferOut);
-DRWAV_API void drwav_u8_to_s16(drwav_int16* pOut, const drwav_uint8* pIn, size_t sampleCount);
-DRWAV_API void drwav_s24_to_s16(drwav_int16* pOut, const drwav_uint8* pIn, size_t sampleCount);
-DRWAV_API void drwav_s32_to_s16(drwav_int16* pOut, const drwav_int32* pIn, size_t sampleCount);
-DRWAV_API void drwav_f32_to_s16(drwav_int16* pOut, const float* pIn, size_t sampleCount);
-DRWAV_API void drwav_f64_to_s16(drwav_int16* pOut, const double* pIn, size_t sampleCount);
-DRWAV_API void drwav_alaw_to_s16(drwav_int16* pOut, const drwav_uint8* pIn, size_t sampleCount);
-DRWAV_API void drwav_mulaw_to_s16(drwav_int16* pOut, const drwav_uint8* pIn, size_t sampleCount);
-DRWAV_API drwav_uint64 drwav_read_pcm_frames_f32(drwav* pWav, drwav_uint64 framesToRead, float* pBufferOut);
-DRWAV_API drwav_uint64 drwav_read_pcm_frames_f32le(drwav* pWav, drwav_uint64 framesToRead, float* pBufferOut);
-DRWAV_API drwav_uint64 drwav_read_pcm_frames_f32be(drwav* pWav, drwav_uint64 framesToRead, float* pBufferOut);
-DRWAV_API void drwav_u8_to_f32(float* pOut, const drwav_uint8* pIn, size_t sampleCount);
-DRWAV_API void drwav_s16_to_f32(float* pOut, const drwav_int16* pIn, size_t sampleCount);
-DRWAV_API void drwav_s24_to_f32(float* pOut, const drwav_uint8* pIn, size_t sampleCount);
-DRWAV_API void drwav_s32_to_f32(float* pOut, const drwav_int32* pIn, size_t sampleCount);
-DRWAV_API void drwav_f64_to_f32(float* pOut, const double* pIn, size_t sampleCount);
-DRWAV_API void drwav_alaw_to_f32(float* pOut, const drwav_uint8* pIn, size_t sampleCount);
-DRWAV_API void drwav_mulaw_to_f32(float* pOut, const drwav_uint8* pIn, size_t sampleCount);
-DRWAV_API drwav_uint64 drwav_read_pcm_frames_s32(drwav* pWav, drwav_uint64 framesToRead, drwav_int32* pBufferOut);
-DRWAV_API drwav_uint64 drwav_read_pcm_frames_s32le(drwav* pWav, drwav_uint64 framesToRead, drwav_int32* pBufferOut);
-DRWAV_API drwav_uint64 drwav_read_pcm_frames_s32be(drwav* pWav, drwav_uint64 framesToRead, drwav_int32* pBufferOut);
-DRWAV_API void drwav_u8_to_s32(drwav_int32* pOut, const drwav_uint8* pIn, size_t sampleCount);
-DRWAV_API void drwav_s16_to_s32(drwav_int32* pOut, const drwav_int16* pIn, size_t sampleCount);
-DRWAV_API void drwav_s24_to_s32(drwav_int32* pOut, const drwav_uint8* pIn, size_t sampleCount);
-DRWAV_API void drwav_f32_to_s32(drwav_int32* pOut, const float* pIn, size_t sampleCount);
-DRWAV_API void drwav_f64_to_s32(drwav_int32* pOut, const double* pIn, size_t sampleCount);
-DRWAV_API void drwav_alaw_to_s32(drwav_int32* pOut, const drwav_uint8* pIn, size_t sampleCount);
-DRWAV_API void drwav_mulaw_to_s32(drwav_int32* pOut, const drwav_uint8* pIn, size_t sampleCount);
-#endif
-#ifndef DR_WAV_NO_STDIO
-DRWAV_API drwav_bool32 drwav_init_file(drwav* pWav, const char* filename, const drwav_allocation_callbacks* pAllocationCallbacks);
-DRWAV_API drwav_bool32 drwav_init_file_ex(drwav* pWav, const char* filename, drwav_chunk_proc onChunk, void* pChunkUserData, drwav_uint32 flags, const drwav_allocation_callbacks* pAllocationCallbacks);
-DRWAV_API drwav_bool32 drwav_init_file_w(drwav* pWav, const wchar_t* filename, const drwav_allocation_callbacks* pAllocationCallbacks);
-DRWAV_API drwav_bool32 drwav_init_file_ex_w(drwav* pWav, const wchar_t* filename, drwav_chunk_proc onChunk, void* pChunkUserData, drwav_uint32 flags, const drwav_allocation_callbacks* pAllocationCallbacks);
-DRWAV_API drwav_bool32 drwav_init_file_with_metadata(drwav* pWav, const char* filename, drwav_uint32 flags, const drwav_allocation_callbacks* pAllocationCallbacks);
-DRWAV_API drwav_bool32 drwav_init_file_with_metadata_w(drwav* pWav, const wchar_t* filename, drwav_uint32 flags, const drwav_allocation_callbacks* pAllocationCallbacks);
-DRWAV_API drwav_bool32 drwav_init_file_write(drwav* pWav, const char* filename, const drwav_data_format* pFormat, const drwav_allocation_callbacks* pAllocationCallbacks);
-DRWAV_API drwav_bool32 drwav_init_file_write_sequential(drwav* pWav, const char* filename, const drwav_data_format* pFormat, drwav_uint64 totalSampleCount, const drwav_allocation_callbacks* pAllocationCallbacks);
-DRWAV_API drwav_bool32 drwav_init_file_write_sequential_pcm_frames(drwav* pWav, const char* filename, const drwav_data_format* pFormat, drwav_uint64 totalPCMFrameCount, const drwav_allocation_callbacks* pAllocationCallbacks);
-DRWAV_API drwav_bool32 drwav_init_file_write_w(drwav* pWav, const wchar_t* filename, const drwav_data_format* pFormat, const drwav_allocation_callbacks* pAllocationCallbacks);
-DRWAV_API drwav_bool32 drwav_init_file_write_sequential_w(drwav* pWav, const wchar_t* filename, const drwav_data_format* pFormat, drwav_uint64 totalSampleCount, const drwav_allocation_callbacks* pAllocationCallbacks);
-DRWAV_API drwav_bool32 drwav_init_file_write_sequential_pcm_frames_w(drwav* pWav, const wchar_t* filename, const drwav_data_format* pFormat, drwav_uint64 totalPCMFrameCount, const drwav_allocation_callbacks* pAllocationCallbacks);
-#endif
-DRWAV_API drwav_bool32 drwav_init_memory(drwav* pWav, const void* data, size_t dataSize, const drwav_allocation_callbacks* pAllocationCallbacks);
-DRWAV_API drwav_bool32 drwav_init_memory_ex(drwav* pWav, const void* data, size_t dataSize, drwav_chunk_proc onChunk, void* pChunkUserData, drwav_uint32 flags, const drwav_allocation_callbacks* pAllocationCallbacks);
-DRWAV_API drwav_bool32 drwav_init_memory_with_metadata(drwav* pWav, const void* data, size_t dataSize, drwav_uint32 flags, const drwav_allocation_callbacks* pAllocationCallbacks);
-DRWAV_API drwav_bool32 drwav_init_memory_write(drwav* pWav, void** ppData, size_t* pDataSize, const drwav_data_format* pFormat, const drwav_allocation_callbacks* pAllocationCallbacks);
-DRWAV_API drwav_bool32 drwav_init_memory_write_sequential(drwav* pWav, void** ppData, size_t* pDataSize, const drwav_data_format* pFormat, drwav_uint64 totalSampleCount, const drwav_allocation_callbacks* pAllocationCallbacks);
-DRWAV_API drwav_bool32 drwav_init_memory_write_sequential_pcm_frames(drwav* pWav, void** ppData, size_t* pDataSize, const drwav_data_format* pFormat, drwav_uint64 totalPCMFrameCount, const drwav_allocation_callbacks* pAllocationCallbacks);
-#ifndef DR_WAV_NO_CONVERSION_API
-DRWAV_API drwav_int16* drwav_open_and_read_pcm_frames_s16(drwav_read_proc onRead, drwav_seek_proc onSeek, void* pUserData, unsigned int* channelsOut, unsigned int* sampleRateOut, drwav_uint64* totalFrameCountOut, const drwav_allocation_callbacks* pAllocationCallbacks);
-DRWAV_API float* drwav_open_and_read_pcm_frames_f32(drwav_read_proc onRead, drwav_seek_proc onSeek, void* pUserData, unsigned int* channelsOut, unsigned int* sampleRateOut, drwav_uint64* totalFrameCountOut, const drwav_allocation_callbacks* pAllocationCallbacks);
-DRWAV_API drwav_int32* drwav_open_and_read_pcm_frames_s32(drwav_read_proc onRead, drwav_seek_proc onSeek, void* pUserData, unsigned int* channelsOut, unsigned int* sampleRateOut, drwav_uint64* totalFrameCountOut, const drwav_allocation_callbacks* pAllocationCallbacks);
-#ifndef DR_WAV_NO_STDIO
-DRWAV_API drwav_int16* drwav_open_file_and_read_pcm_frames_s16(const char* filename, unsigned int* channelsOut, unsigned int* sampleRateOut, drwav_uint64* totalFrameCountOut, const drwav_allocation_callbacks* pAllocationCallbacks);
-DRWAV_API float* drwav_open_file_and_read_pcm_frames_f32(const char* filename, unsigned int* channelsOut, unsigned int* sampleRateOut, drwav_uint64* totalFrameCountOut, const drwav_allocation_callbacks* pAllocationCallbacks);
-DRWAV_API drwav_int32* drwav_open_file_and_read_pcm_frames_s32(const char* filename, unsigned int* channelsOut, unsigned int* sampleRateOut, drwav_uint64* totalFrameCountOut, const drwav_allocation_callbacks* pAllocationCallbacks);
-DRWAV_API drwav_int16* drwav_open_file_and_read_pcm_frames_s16_w(const wchar_t* filename, unsigned int* channelsOut, unsigned int* sampleRateOut, drwav_uint64* totalFrameCountOut, const drwav_allocation_callbacks* pAllocationCallbacks);
-DRWAV_API float* drwav_open_file_and_read_pcm_frames_f32_w(const wchar_t* filename, unsigned int* channelsOut, unsigned int* sampleRateOut, drwav_uint64* totalFrameCountOut, const drwav_allocation_callbacks* pAllocationCallbacks);
-DRWAV_API drwav_int32* drwav_open_file_and_read_pcm_frames_s32_w(const wchar_t* filename, unsigned int* channelsOut, unsigned int* sampleRateOut, drwav_uint64* totalFrameCountOut, const drwav_allocation_callbacks* pAllocationCallbacks);
-#endif
-DRWAV_API drwav_int16* drwav_open_memory_and_read_pcm_frames_s16(const void* data, size_t dataSize, unsigned int* channelsOut, unsigned int* sampleRateOut, drwav_uint64* totalFrameCountOut, const drwav_allocation_callbacks* pAllocationCallbacks);
-DRWAV_API float* drwav_open_memory_and_read_pcm_frames_f32(const void* data, size_t dataSize, unsigned int* channelsOut, unsigned int* sampleRateOut, drwav_uint64* totalFrameCountOut, const drwav_allocation_callbacks* pAllocationCallbacks);
-DRWAV_API drwav_int32* drwav_open_memory_and_read_pcm_frames_s32(const void* data, size_t dataSize, unsigned int* channelsOut, unsigned int* sampleRateOut, drwav_uint64* totalFrameCountOut, const drwav_allocation_callbacks* pAllocationCallbacks);
-#endif
-DRWAV_API void drwav_free(void* p, const drwav_allocation_callbacks* pAllocationCallbacks);
-DRWAV_API drwav_uint16 drwav_bytes_to_u16(const drwav_uint8* data);
-DRWAV_API drwav_int16 drwav_bytes_to_s16(const drwav_uint8* data);
-DRWAV_API drwav_uint32 drwav_bytes_to_u32(const drwav_uint8* data);
-DRWAV_API drwav_int32 drwav_bytes_to_s32(const drwav_uint8* data);
-DRWAV_API drwav_uint64 drwav_bytes_to_u64(const drwav_uint8* data);
-DRWAV_API drwav_int64 drwav_bytes_to_s64(const drwav_uint8* data);
-DRWAV_API float drwav_bytes_to_f32(const drwav_uint8* data);
-DRWAV_API drwav_bool32 drwav_guid_equal(const drwav_uint8 a[16], const drwav_uint8 b[16]);
-DRWAV_API drwav_bool32 drwav_fourcc_equal(const drwav_uint8* a, const char* b);
+ struct
+ {
+ ma_bool8 isLE;
+ ma_bool8 isUnsigned;
+ } aiff;
+} ma_dr_wav;
+MA_API ma_bool32 ma_dr_wav_init(ma_dr_wav* pWav, ma_dr_wav_read_proc onRead, ma_dr_wav_seek_proc onSeek, void* pUserData, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_bool32 ma_dr_wav_init_ex(ma_dr_wav* pWav, ma_dr_wav_read_proc onRead, ma_dr_wav_seek_proc onSeek, ma_dr_wav_chunk_proc onChunk, void* pReadSeekUserData, void* pChunkUserData, ma_uint32 flags, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_bool32 ma_dr_wav_init_with_metadata(ma_dr_wav* pWav, ma_dr_wav_read_proc onRead, ma_dr_wav_seek_proc onSeek, void* pUserData, ma_uint32 flags, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_bool32 ma_dr_wav_init_write(ma_dr_wav* pWav, const ma_dr_wav_data_format* pFormat, ma_dr_wav_write_proc onWrite, ma_dr_wav_seek_proc onSeek, void* pUserData, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_bool32 ma_dr_wav_init_write_sequential(ma_dr_wav* pWav, const ma_dr_wav_data_format* pFormat, ma_uint64 totalSampleCount, ma_dr_wav_write_proc onWrite, void* pUserData, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_bool32 ma_dr_wav_init_write_sequential_pcm_frames(ma_dr_wav* pWav, const ma_dr_wav_data_format* pFormat, ma_uint64 totalPCMFrameCount, ma_dr_wav_write_proc onWrite, void* pUserData, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_bool32 ma_dr_wav_init_write_with_metadata(ma_dr_wav* pWav, const ma_dr_wav_data_format* pFormat, ma_dr_wav_write_proc onWrite, ma_dr_wav_seek_proc onSeek, void* pUserData, const ma_allocation_callbacks* pAllocationCallbacks, ma_dr_wav_metadata* pMetadata, ma_uint32 metadataCount);
+MA_API ma_uint64 ma_dr_wav_target_write_size_bytes(const ma_dr_wav_data_format* pFormat, ma_uint64 totalFrameCount, ma_dr_wav_metadata* pMetadata, ma_uint32 metadataCount);
+MA_API ma_dr_wav_metadata* ma_dr_wav_take_ownership_of_metadata(ma_dr_wav* pWav);
+MA_API ma_result ma_dr_wav_uninit(ma_dr_wav* pWav);
+MA_API size_t ma_dr_wav_read_raw(ma_dr_wav* pWav, size_t bytesToRead, void* pBufferOut);
+MA_API ma_uint64 ma_dr_wav_read_pcm_frames(ma_dr_wav* pWav, ma_uint64 framesToRead, void* pBufferOut);
+MA_API ma_uint64 ma_dr_wav_read_pcm_frames_le(ma_dr_wav* pWav, ma_uint64 framesToRead, void* pBufferOut);
+MA_API ma_uint64 ma_dr_wav_read_pcm_frames_be(ma_dr_wav* pWav, ma_uint64 framesToRead, void* pBufferOut);
+MA_API ma_bool32 ma_dr_wav_seek_to_pcm_frame(ma_dr_wav* pWav, ma_uint64 targetFrameIndex);
+MA_API ma_result ma_dr_wav_get_cursor_in_pcm_frames(ma_dr_wav* pWav, ma_uint64* pCursor);
+MA_API ma_result ma_dr_wav_get_length_in_pcm_frames(ma_dr_wav* pWav, ma_uint64* pLength);
+MA_API size_t ma_dr_wav_write_raw(ma_dr_wav* pWav, size_t bytesToWrite, const void* pData);
+MA_API ma_uint64 ma_dr_wav_write_pcm_frames(ma_dr_wav* pWav, ma_uint64 framesToWrite, const void* pData);
+MA_API ma_uint64 ma_dr_wav_write_pcm_frames_le(ma_dr_wav* pWav, ma_uint64 framesToWrite, const void* pData);
+MA_API ma_uint64 ma_dr_wav_write_pcm_frames_be(ma_dr_wav* pWav, ma_uint64 framesToWrite, const void* pData);
+#ifndef MA_DR_WAV_NO_CONVERSION_API
+MA_API ma_uint64 ma_dr_wav_read_pcm_frames_s16(ma_dr_wav* pWav, ma_uint64 framesToRead, ma_int16* pBufferOut);
+MA_API ma_uint64 ma_dr_wav_read_pcm_frames_s16le(ma_dr_wav* pWav, ma_uint64 framesToRead, ma_int16* pBufferOut);
+MA_API ma_uint64 ma_dr_wav_read_pcm_frames_s16be(ma_dr_wav* pWav, ma_uint64 framesToRead, ma_int16* pBufferOut);
+MA_API void ma_dr_wav_u8_to_s16(ma_int16* pOut, const ma_uint8* pIn, size_t sampleCount);
+MA_API void ma_dr_wav_s24_to_s16(ma_int16* pOut, const ma_uint8* pIn, size_t sampleCount);
+MA_API void ma_dr_wav_s32_to_s16(ma_int16* pOut, const ma_int32* pIn, size_t sampleCount);
+MA_API void ma_dr_wav_f32_to_s16(ma_int16* pOut, const float* pIn, size_t sampleCount);
+MA_API void ma_dr_wav_f64_to_s16(ma_int16* pOut, const double* pIn, size_t sampleCount);
+MA_API void ma_dr_wav_alaw_to_s16(ma_int16* pOut, const ma_uint8* pIn, size_t sampleCount);
+MA_API void ma_dr_wav_mulaw_to_s16(ma_int16* pOut, const ma_uint8* pIn, size_t sampleCount);
+MA_API ma_uint64 ma_dr_wav_read_pcm_frames_f32(ma_dr_wav* pWav, ma_uint64 framesToRead, float* pBufferOut);
+MA_API ma_uint64 ma_dr_wav_read_pcm_frames_f32le(ma_dr_wav* pWav, ma_uint64 framesToRead, float* pBufferOut);
+MA_API ma_uint64 ma_dr_wav_read_pcm_frames_f32be(ma_dr_wav* pWav, ma_uint64 framesToRead, float* pBufferOut);
+MA_API void ma_dr_wav_u8_to_f32(float* pOut, const ma_uint8* pIn, size_t sampleCount);
+MA_API void ma_dr_wav_s16_to_f32(float* pOut, const ma_int16* pIn, size_t sampleCount);
+MA_API void ma_dr_wav_s24_to_f32(float* pOut, const ma_uint8* pIn, size_t sampleCount);
+MA_API void ma_dr_wav_s32_to_f32(float* pOut, const ma_int32* pIn, size_t sampleCount);
+MA_API void ma_dr_wav_f64_to_f32(float* pOut, const double* pIn, size_t sampleCount);
+MA_API void ma_dr_wav_alaw_to_f32(float* pOut, const ma_uint8* pIn, size_t sampleCount);
+MA_API void ma_dr_wav_mulaw_to_f32(float* pOut, const ma_uint8* pIn, size_t sampleCount);
+MA_API ma_uint64 ma_dr_wav_read_pcm_frames_s32(ma_dr_wav* pWav, ma_uint64 framesToRead, ma_int32* pBufferOut);
+MA_API ma_uint64 ma_dr_wav_read_pcm_frames_s32le(ma_dr_wav* pWav, ma_uint64 framesToRead, ma_int32* pBufferOut);
+MA_API ma_uint64 ma_dr_wav_read_pcm_frames_s32be(ma_dr_wav* pWav, ma_uint64 framesToRead, ma_int32* pBufferOut);
+MA_API void ma_dr_wav_u8_to_s32(ma_int32* pOut, const ma_uint8* pIn, size_t sampleCount);
+MA_API void ma_dr_wav_s16_to_s32(ma_int32* pOut, const ma_int16* pIn, size_t sampleCount);
+MA_API void ma_dr_wav_s24_to_s32(ma_int32* pOut, const ma_uint8* pIn, size_t sampleCount);
+MA_API void ma_dr_wav_f32_to_s32(ma_int32* pOut, const float* pIn, size_t sampleCount);
+MA_API void ma_dr_wav_f64_to_s32(ma_int32* pOut, const double* pIn, size_t sampleCount);
+MA_API void ma_dr_wav_alaw_to_s32(ma_int32* pOut, const ma_uint8* pIn, size_t sampleCount);
+MA_API void ma_dr_wav_mulaw_to_s32(ma_int32* pOut, const ma_uint8* pIn, size_t sampleCount);
+#endif
+#ifndef MA_DR_WAV_NO_STDIO
+MA_API ma_bool32 ma_dr_wav_init_file(ma_dr_wav* pWav, const char* filename, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_bool32 ma_dr_wav_init_file_ex(ma_dr_wav* pWav, const char* filename, ma_dr_wav_chunk_proc onChunk, void* pChunkUserData, ma_uint32 flags, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_bool32 ma_dr_wav_init_file_w(ma_dr_wav* pWav, const wchar_t* filename, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_bool32 ma_dr_wav_init_file_ex_w(ma_dr_wav* pWav, const wchar_t* filename, ma_dr_wav_chunk_proc onChunk, void* pChunkUserData, ma_uint32 flags, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_bool32 ma_dr_wav_init_file_with_metadata(ma_dr_wav* pWav, const char* filename, ma_uint32 flags, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_bool32 ma_dr_wav_init_file_with_metadata_w(ma_dr_wav* pWav, const wchar_t* filename, ma_uint32 flags, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_bool32 ma_dr_wav_init_file_write(ma_dr_wav* pWav, const char* filename, const ma_dr_wav_data_format* pFormat, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_bool32 ma_dr_wav_init_file_write_sequential(ma_dr_wav* pWav, const char* filename, const ma_dr_wav_data_format* pFormat, ma_uint64 totalSampleCount, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_bool32 ma_dr_wav_init_file_write_sequential_pcm_frames(ma_dr_wav* pWav, const char* filename, const ma_dr_wav_data_format* pFormat, ma_uint64 totalPCMFrameCount, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_bool32 ma_dr_wav_init_file_write_w(ma_dr_wav* pWav, const wchar_t* filename, const ma_dr_wav_data_format* pFormat, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_bool32 ma_dr_wav_init_file_write_sequential_w(ma_dr_wav* pWav, const wchar_t* filename, const ma_dr_wav_data_format* pFormat, ma_uint64 totalSampleCount, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_bool32 ma_dr_wav_init_file_write_sequential_pcm_frames_w(ma_dr_wav* pWav, const wchar_t* filename, const ma_dr_wav_data_format* pFormat, ma_uint64 totalPCMFrameCount, const ma_allocation_callbacks* pAllocationCallbacks);
+#endif
+MA_API ma_bool32 ma_dr_wav_init_memory(ma_dr_wav* pWav, const void* data, size_t dataSize, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_bool32 ma_dr_wav_init_memory_ex(ma_dr_wav* pWav, const void* data, size_t dataSize, ma_dr_wav_chunk_proc onChunk, void* pChunkUserData, ma_uint32 flags, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_bool32 ma_dr_wav_init_memory_with_metadata(ma_dr_wav* pWav, const void* data, size_t dataSize, ma_uint32 flags, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_bool32 ma_dr_wav_init_memory_write(ma_dr_wav* pWav, void** ppData, size_t* pDataSize, const ma_dr_wav_data_format* pFormat, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_bool32 ma_dr_wav_init_memory_write_sequential(ma_dr_wav* pWav, void** ppData, size_t* pDataSize, const ma_dr_wav_data_format* pFormat, ma_uint64 totalSampleCount, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_bool32 ma_dr_wav_init_memory_write_sequential_pcm_frames(ma_dr_wav* pWav, void** ppData, size_t* pDataSize, const ma_dr_wav_data_format* pFormat, ma_uint64 totalPCMFrameCount, const ma_allocation_callbacks* pAllocationCallbacks);
+#ifndef MA_DR_WAV_NO_CONVERSION_API
+MA_API ma_int16* ma_dr_wav_open_and_read_pcm_frames_s16(ma_dr_wav_read_proc onRead, ma_dr_wav_seek_proc onSeek, void* pUserData, unsigned int* channelsOut, unsigned int* sampleRateOut, ma_uint64* totalFrameCountOut, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API float* ma_dr_wav_open_and_read_pcm_frames_f32(ma_dr_wav_read_proc onRead, ma_dr_wav_seek_proc onSeek, void* pUserData, unsigned int* channelsOut, unsigned int* sampleRateOut, ma_uint64* totalFrameCountOut, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_int32* ma_dr_wav_open_and_read_pcm_frames_s32(ma_dr_wav_read_proc onRead, ma_dr_wav_seek_proc onSeek, void* pUserData, unsigned int* channelsOut, unsigned int* sampleRateOut, ma_uint64* totalFrameCountOut, const ma_allocation_callbacks* pAllocationCallbacks);
+#ifndef MA_DR_WAV_NO_STDIO
+MA_API ma_int16* ma_dr_wav_open_file_and_read_pcm_frames_s16(const char* filename, unsigned int* channelsOut, unsigned int* sampleRateOut, ma_uint64* totalFrameCountOut, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API float* ma_dr_wav_open_file_and_read_pcm_frames_f32(const char* filename, unsigned int* channelsOut, unsigned int* sampleRateOut, ma_uint64* totalFrameCountOut, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_int32* ma_dr_wav_open_file_and_read_pcm_frames_s32(const char* filename, unsigned int* channelsOut, unsigned int* sampleRateOut, ma_uint64* totalFrameCountOut, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_int16* ma_dr_wav_open_file_and_read_pcm_frames_s16_w(const wchar_t* filename, unsigned int* channelsOut, unsigned int* sampleRateOut, ma_uint64* totalFrameCountOut, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API float* ma_dr_wav_open_file_and_read_pcm_frames_f32_w(const wchar_t* filename, unsigned int* channelsOut, unsigned int* sampleRateOut, ma_uint64* totalFrameCountOut, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_int32* ma_dr_wav_open_file_and_read_pcm_frames_s32_w(const wchar_t* filename, unsigned int* channelsOut, unsigned int* sampleRateOut, ma_uint64* totalFrameCountOut, const ma_allocation_callbacks* pAllocationCallbacks);
+#endif
+MA_API ma_int16* ma_dr_wav_open_memory_and_read_pcm_frames_s16(const void* data, size_t dataSize, unsigned int* channelsOut, unsigned int* sampleRateOut, ma_uint64* totalFrameCountOut, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API float* ma_dr_wav_open_memory_and_read_pcm_frames_f32(const void* data, size_t dataSize, unsigned int* channelsOut, unsigned int* sampleRateOut, ma_uint64* totalFrameCountOut, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_int32* ma_dr_wav_open_memory_and_read_pcm_frames_s32(const void* data, size_t dataSize, unsigned int* channelsOut, unsigned int* sampleRateOut, ma_uint64* totalFrameCountOut, const ma_allocation_callbacks* pAllocationCallbacks);
+#endif
+MA_API void ma_dr_wav_free(void* p, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_uint16 ma_dr_wav_bytes_to_u16(const ma_uint8* data);
+MA_API ma_int16 ma_dr_wav_bytes_to_s16(const ma_uint8* data);
+MA_API ma_uint32 ma_dr_wav_bytes_to_u32(const ma_uint8* data);
+MA_API ma_int32 ma_dr_wav_bytes_to_s32(const ma_uint8* data);
+MA_API ma_uint64 ma_dr_wav_bytes_to_u64(const ma_uint8* data);
+MA_API ma_int64 ma_dr_wav_bytes_to_s64(const ma_uint8* data);
+MA_API float ma_dr_wav_bytes_to_f32(const ma_uint8* data);
+MA_API ma_bool32 ma_dr_wav_guid_equal(const ma_uint8 a[16], const ma_uint8 b[16]);
+MA_API ma_bool32 ma_dr_wav_fourcc_equal(const ma_uint8* a, const char* b);
#ifdef __cplusplus
}
#endif
@@ -58333,354 +60169,284 @@ DRWAV_API drwav_bool32 drwav_fourcc_equal(const drwav_uint8* a, const char* b);
#if !defined(MA_NO_FLAC) && !defined(MA_NO_DECODING)
/* dr_flac_h begin */
-#ifndef dr_flac_h
-#define dr_flac_h
+#ifndef ma_dr_flac_h
+#define ma_dr_flac_h
#ifdef __cplusplus
extern "C" {
#endif
-#define DRFLAC_STRINGIFY(x) #x
-#define DRFLAC_XSTRINGIFY(x) DRFLAC_STRINGIFY(x)
-#define DRFLAC_VERSION_MAJOR 0
-#define DRFLAC_VERSION_MINOR 12
-#define DRFLAC_VERSION_REVISION 39
-#define DRFLAC_VERSION_STRING DRFLAC_XSTRINGIFY(DRFLAC_VERSION_MAJOR) "." DRFLAC_XSTRINGIFY(DRFLAC_VERSION_MINOR) "." DRFLAC_XSTRINGIFY(DRFLAC_VERSION_REVISION)
+#define MA_DR_FLAC_STRINGIFY(x) #x
+#define MA_DR_FLAC_XSTRINGIFY(x) MA_DR_FLAC_STRINGIFY(x)
+#define MA_DR_FLAC_VERSION_MAJOR 0
+#define MA_DR_FLAC_VERSION_MINOR 12
+#define MA_DR_FLAC_VERSION_REVISION 42
+#define MA_DR_FLAC_VERSION_STRING MA_DR_FLAC_XSTRINGIFY(MA_DR_FLAC_VERSION_MAJOR) "." MA_DR_FLAC_XSTRINGIFY(MA_DR_FLAC_VERSION_MINOR) "." MA_DR_FLAC_XSTRINGIFY(MA_DR_FLAC_VERSION_REVISION)
#include
-typedef signed char drflac_int8;
-typedef unsigned char drflac_uint8;
-typedef signed short drflac_int16;
-typedef unsigned short drflac_uint16;
-typedef signed int drflac_int32;
-typedef unsigned int drflac_uint32;
-#if defined(_MSC_VER) && !defined(__clang__)
- typedef signed __int64 drflac_int64;
- typedef unsigned __int64 drflac_uint64;
-#else
- #if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)))
- #pragma GCC diagnostic push
- #pragma GCC diagnostic ignored "-Wlong-long"
- #if defined(__clang__)
- #pragma GCC diagnostic ignored "-Wc++11-long-long"
- #endif
- #endif
- typedef signed long long drflac_int64;
- typedef unsigned long long drflac_uint64;
- #if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)))
- #pragma GCC diagnostic pop
- #endif
-#endif
-#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__)) || defined(_M_X64) || defined(__ia64) || defined(_M_IA64) || defined(__aarch64__) || defined(_M_ARM64) || defined(__powerpc64__)
- typedef drflac_uint64 drflac_uintptr;
-#else
- typedef drflac_uint32 drflac_uintptr;
-#endif
-typedef drflac_uint8 drflac_bool8;
-typedef drflac_uint32 drflac_bool32;
-#define DRFLAC_TRUE 1
-#define DRFLAC_FALSE 0
-#if !defined(DRFLAC_API)
- #if defined(DRFLAC_DLL)
- #if defined(_WIN32)
- #define DRFLAC_DLL_IMPORT __declspec(dllimport)
- #define DRFLAC_DLL_EXPORT __declspec(dllexport)
- #define DRFLAC_DLL_PRIVATE static
- #else
- #if defined(__GNUC__) && __GNUC__ >= 4
- #define DRFLAC_DLL_IMPORT __attribute__((visibility("default")))
- #define DRFLAC_DLL_EXPORT __attribute__((visibility("default")))
- #define DRFLAC_DLL_PRIVATE __attribute__((visibility("hidden")))
- #else
- #define DRFLAC_DLL_IMPORT
- #define DRFLAC_DLL_EXPORT
- #define DRFLAC_DLL_PRIVATE static
- #endif
- #endif
- #if defined(DR_FLAC_IMPLEMENTATION) || defined(DRFLAC_IMPLEMENTATION)
- #define DRFLAC_API DRFLAC_DLL_EXPORT
- #else
- #define DRFLAC_API DRFLAC_DLL_IMPORT
- #endif
- #define DRFLAC_PRIVATE DRFLAC_DLL_PRIVATE
- #else
- #define DRFLAC_API extern
- #define DRFLAC_PRIVATE static
- #endif
-#endif
#if defined(_MSC_VER) && _MSC_VER >= 1700
- #define DRFLAC_DEPRECATED __declspec(deprecated)
+ #define MA_DR_FLAC_DEPRECATED __declspec(deprecated)
#elif (defined(__GNUC__) && __GNUC__ >= 4)
- #define DRFLAC_DEPRECATED __attribute__((deprecated))
+ #define MA_DR_FLAC_DEPRECATED __attribute__((deprecated))
#elif defined(__has_feature)
#if __has_feature(attribute_deprecated)
- #define DRFLAC_DEPRECATED __attribute__((deprecated))
+ #define MA_DR_FLAC_DEPRECATED __attribute__((deprecated))
#else
- #define DRFLAC_DEPRECATED
+ #define MA_DR_FLAC_DEPRECATED
#endif
#else
- #define DRFLAC_DEPRECATED
+ #define MA_DR_FLAC_DEPRECATED
#endif
-DRFLAC_API void drflac_version(drflac_uint32* pMajor, drflac_uint32* pMinor, drflac_uint32* pRevision);
-DRFLAC_API const char* drflac_version_string(void);
-#ifndef DR_FLAC_BUFFER_SIZE
-#define DR_FLAC_BUFFER_SIZE 4096
+MA_API void ma_dr_flac_version(ma_uint32* pMajor, ma_uint32* pMinor, ma_uint32* pRevision);
+MA_API const char* ma_dr_flac_version_string(void);
+#ifndef MA_DR_FLAC_BUFFER_SIZE
+#define MA_DR_FLAC_BUFFER_SIZE 4096
#endif
-#if defined(_WIN64) || defined(_LP64) || defined(__LP64__)
-#define DRFLAC_64BIT
-#endif
-#ifdef DRFLAC_64BIT
-typedef drflac_uint64 drflac_cache_t;
+#ifdef MA_64BIT
+typedef ma_uint64 ma_dr_flac_cache_t;
#else
-typedef drflac_uint32 drflac_cache_t;
-#endif
-#define DRFLAC_METADATA_BLOCK_TYPE_STREAMINFO 0
-#define DRFLAC_METADATA_BLOCK_TYPE_PADDING 1
-#define DRFLAC_METADATA_BLOCK_TYPE_APPLICATION 2
-#define DRFLAC_METADATA_BLOCK_TYPE_SEEKTABLE 3
-#define DRFLAC_METADATA_BLOCK_TYPE_VORBIS_COMMENT 4
-#define DRFLAC_METADATA_BLOCK_TYPE_CUESHEET 5
-#define DRFLAC_METADATA_BLOCK_TYPE_PICTURE 6
-#define DRFLAC_METADATA_BLOCK_TYPE_INVALID 127
-#define DRFLAC_PICTURE_TYPE_OTHER 0
-#define DRFLAC_PICTURE_TYPE_FILE_ICON 1
-#define DRFLAC_PICTURE_TYPE_OTHER_FILE_ICON 2
-#define DRFLAC_PICTURE_TYPE_COVER_FRONT 3
-#define DRFLAC_PICTURE_TYPE_COVER_BACK 4
-#define DRFLAC_PICTURE_TYPE_LEAFLET_PAGE 5
-#define DRFLAC_PICTURE_TYPE_MEDIA 6
-#define DRFLAC_PICTURE_TYPE_LEAD_ARTIST 7
-#define DRFLAC_PICTURE_TYPE_ARTIST 8
-#define DRFLAC_PICTURE_TYPE_CONDUCTOR 9
-#define DRFLAC_PICTURE_TYPE_BAND 10
-#define DRFLAC_PICTURE_TYPE_COMPOSER 11
-#define DRFLAC_PICTURE_TYPE_LYRICIST 12
-#define DRFLAC_PICTURE_TYPE_RECORDING_LOCATION 13
-#define DRFLAC_PICTURE_TYPE_DURING_RECORDING 14
-#define DRFLAC_PICTURE_TYPE_DURING_PERFORMANCE 15
-#define DRFLAC_PICTURE_TYPE_SCREEN_CAPTURE 16
-#define DRFLAC_PICTURE_TYPE_BRIGHT_COLORED_FISH 17
-#define DRFLAC_PICTURE_TYPE_ILLUSTRATION 18
-#define DRFLAC_PICTURE_TYPE_BAND_LOGOTYPE 19
-#define DRFLAC_PICTURE_TYPE_PUBLISHER_LOGOTYPE 20
+typedef ma_uint32 ma_dr_flac_cache_t;
+#endif
+#define MA_DR_FLAC_METADATA_BLOCK_TYPE_STREAMINFO 0
+#define MA_DR_FLAC_METADATA_BLOCK_TYPE_PADDING 1
+#define MA_DR_FLAC_METADATA_BLOCK_TYPE_APPLICATION 2
+#define MA_DR_FLAC_METADATA_BLOCK_TYPE_SEEKTABLE 3
+#define MA_DR_FLAC_METADATA_BLOCK_TYPE_VORBIS_COMMENT 4
+#define MA_DR_FLAC_METADATA_BLOCK_TYPE_CUESHEET 5
+#define MA_DR_FLAC_METADATA_BLOCK_TYPE_PICTURE 6
+#define MA_DR_FLAC_METADATA_BLOCK_TYPE_INVALID 127
+#define MA_DR_FLAC_PICTURE_TYPE_OTHER 0
+#define MA_DR_FLAC_PICTURE_TYPE_FILE_ICON 1
+#define MA_DR_FLAC_PICTURE_TYPE_OTHER_FILE_ICON 2
+#define MA_DR_FLAC_PICTURE_TYPE_COVER_FRONT 3
+#define MA_DR_FLAC_PICTURE_TYPE_COVER_BACK 4
+#define MA_DR_FLAC_PICTURE_TYPE_LEAFLET_PAGE 5
+#define MA_DR_FLAC_PICTURE_TYPE_MEDIA 6
+#define MA_DR_FLAC_PICTURE_TYPE_LEAD_ARTIST 7
+#define MA_DR_FLAC_PICTURE_TYPE_ARTIST 8
+#define MA_DR_FLAC_PICTURE_TYPE_CONDUCTOR 9
+#define MA_DR_FLAC_PICTURE_TYPE_BAND 10
+#define MA_DR_FLAC_PICTURE_TYPE_COMPOSER 11
+#define MA_DR_FLAC_PICTURE_TYPE_LYRICIST 12
+#define MA_DR_FLAC_PICTURE_TYPE_RECORDING_LOCATION 13
+#define MA_DR_FLAC_PICTURE_TYPE_DURING_RECORDING 14
+#define MA_DR_FLAC_PICTURE_TYPE_DURING_PERFORMANCE 15
+#define MA_DR_FLAC_PICTURE_TYPE_SCREEN_CAPTURE 16
+#define MA_DR_FLAC_PICTURE_TYPE_BRIGHT_COLORED_FISH 17
+#define MA_DR_FLAC_PICTURE_TYPE_ILLUSTRATION 18
+#define MA_DR_FLAC_PICTURE_TYPE_BAND_LOGOTYPE 19
+#define MA_DR_FLAC_PICTURE_TYPE_PUBLISHER_LOGOTYPE 20
typedef enum
{
- drflac_container_native,
- drflac_container_ogg,
- drflac_container_unknown
-} drflac_container;
+ ma_dr_flac_container_native,
+ ma_dr_flac_container_ogg,
+ ma_dr_flac_container_unknown
+} ma_dr_flac_container;
typedef enum
{
- drflac_seek_origin_start,
- drflac_seek_origin_current
-} drflac_seek_origin;
+ ma_dr_flac_seek_origin_start,
+ ma_dr_flac_seek_origin_current
+} ma_dr_flac_seek_origin;
typedef struct
{
- drflac_uint64 firstPCMFrame;
- drflac_uint64 flacFrameOffset;
- drflac_uint16 pcmFrameCount;
-} drflac_seekpoint;
+ ma_uint64 firstPCMFrame;
+ ma_uint64 flacFrameOffset;
+ ma_uint16 pcmFrameCount;
+} ma_dr_flac_seekpoint;
typedef struct
{
- drflac_uint16 minBlockSizeInPCMFrames;
- drflac_uint16 maxBlockSizeInPCMFrames;
- drflac_uint32 minFrameSizeInPCMFrames;
- drflac_uint32 maxFrameSizeInPCMFrames;
- drflac_uint32 sampleRate;
- drflac_uint8 channels;
- drflac_uint8 bitsPerSample;
- drflac_uint64 totalPCMFrameCount;
- drflac_uint8 md5[16];
-} drflac_streaminfo;
+ ma_uint16 minBlockSizeInPCMFrames;
+ ma_uint16 maxBlockSizeInPCMFrames;
+ ma_uint32 minFrameSizeInPCMFrames;
+ ma_uint32 maxFrameSizeInPCMFrames;
+ ma_uint32 sampleRate;
+ ma_uint8 channels;
+ ma_uint8 bitsPerSample;
+ ma_uint64 totalPCMFrameCount;
+ ma_uint8 md5[16];
+} ma_dr_flac_streaminfo;
typedef struct
{
- drflac_uint32 type;
+ ma_uint32 type;
const void* pRawData;
- drflac_uint32 rawDataSize;
+ ma_uint32 rawDataSize;
union
{
- drflac_streaminfo streaminfo;
+ ma_dr_flac_streaminfo streaminfo;
struct
{
int unused;
} padding;
struct
{
- drflac_uint32 id;
+ ma_uint32 id;
const void* pData;
- drflac_uint32 dataSize;
+ ma_uint32 dataSize;
} application;
struct
{
- drflac_uint32 seekpointCount;
- const drflac_seekpoint* pSeekpoints;
+ ma_uint32 seekpointCount;
+ const ma_dr_flac_seekpoint* pSeekpoints;
} seektable;
struct
{
- drflac_uint32 vendorLength;
+ ma_uint32 vendorLength;
const char* vendor;
- drflac_uint32 commentCount;
+ ma_uint32 commentCount;
const void* pComments;
} vorbis_comment;
struct
{
char catalog[128];
- drflac_uint64 leadInSampleCount;
- drflac_bool32 isCD;
- drflac_uint8 trackCount;
+ ma_uint64 leadInSampleCount;
+ ma_bool32 isCD;
+ ma_uint8 trackCount;
const void* pTrackData;
} cuesheet;
struct
{
- drflac_uint32 type;
- drflac_uint32 mimeLength;
+ ma_uint32 type;
+ ma_uint32 mimeLength;
const char* mime;
- drflac_uint32 descriptionLength;
+ ma_uint32 descriptionLength;
const char* description;
- drflac_uint32 width;
- drflac_uint32 height;
- drflac_uint32 colorDepth;
- drflac_uint32 indexColorCount;
- drflac_uint32 pictureDataSize;
- const drflac_uint8* pPictureData;
+ ma_uint32 width;
+ ma_uint32 height;
+ ma_uint32 colorDepth;
+ ma_uint32 indexColorCount;
+ ma_uint32 pictureDataSize;
+ const ma_uint8* pPictureData;
} picture;
} data;
-} drflac_metadata;
-typedef size_t (* drflac_read_proc)(void* pUserData, void* pBufferOut, size_t bytesToRead);
-typedef drflac_bool32 (* drflac_seek_proc)(void* pUserData, int offset, drflac_seek_origin origin);
-typedef void (* drflac_meta_proc)(void* pUserData, drflac_metadata* pMetadata);
+} ma_dr_flac_metadata;
+typedef size_t (* ma_dr_flac_read_proc)(void* pUserData, void* pBufferOut, size_t bytesToRead);
+typedef ma_bool32 (* ma_dr_flac_seek_proc)(void* pUserData, int offset, ma_dr_flac_seek_origin origin);
+typedef void (* ma_dr_flac_meta_proc)(void* pUserData, ma_dr_flac_metadata* pMetadata);
typedef struct
{
- void* pUserData;
- void* (* onMalloc)(size_t sz, void* pUserData);
- void* (* onRealloc)(void* p, size_t sz, void* pUserData);
- void (* onFree)(void* p, void* pUserData);
-} drflac_allocation_callbacks;
-typedef struct
-{
- const drflac_uint8* data;
+ const ma_uint8* data;
size_t dataSize;
size_t currentReadPos;
-} drflac__memory_stream;
+} ma_dr_flac__memory_stream;
typedef struct
{
- drflac_read_proc onRead;
- drflac_seek_proc onSeek;
+ ma_dr_flac_read_proc onRead;
+ ma_dr_flac_seek_proc onSeek;
void* pUserData;
size_t unalignedByteCount;
- drflac_cache_t unalignedCache;
- drflac_uint32 nextL2Line;
- drflac_uint32 consumedBits;
- drflac_cache_t cacheL2[DR_FLAC_BUFFER_SIZE/sizeof(drflac_cache_t)];
- drflac_cache_t cache;
- drflac_uint16 crc16;
- drflac_cache_t crc16Cache;
- drflac_uint32 crc16CacheIgnoredBytes;
-} drflac_bs;
+ ma_dr_flac_cache_t unalignedCache;
+ ma_uint32 nextL2Line;
+ ma_uint32 consumedBits;
+ ma_dr_flac_cache_t cacheL2[MA_DR_FLAC_BUFFER_SIZE/sizeof(ma_dr_flac_cache_t)];
+ ma_dr_flac_cache_t cache;
+ ma_uint16 crc16;
+ ma_dr_flac_cache_t crc16Cache;
+ ma_uint32 crc16CacheIgnoredBytes;
+} ma_dr_flac_bs;
typedef struct
{
- drflac_uint8 subframeType;
- drflac_uint8 wastedBitsPerSample;
- drflac_uint8 lpcOrder;
- drflac_int32* pSamplesS32;
-} drflac_subframe;
+ ma_uint8 subframeType;
+ ma_uint8 wastedBitsPerSample;
+ ma_uint8 lpcOrder;
+ ma_int32* pSamplesS32;
+} ma_dr_flac_subframe;
typedef struct
{
- drflac_uint64 pcmFrameNumber;
- drflac_uint32 flacFrameNumber;
- drflac_uint32 sampleRate;
- drflac_uint16 blockSizeInPCMFrames;
- drflac_uint8 channelAssignment;
- drflac_uint8 bitsPerSample;
- drflac_uint8 crc8;
-} drflac_frame_header;
+ ma_uint64 pcmFrameNumber;
+ ma_uint32 flacFrameNumber;
+ ma_uint32 sampleRate;
+ ma_uint16 blockSizeInPCMFrames;
+ ma_uint8 channelAssignment;
+ ma_uint8 bitsPerSample;
+ ma_uint8 crc8;
+} ma_dr_flac_frame_header;
typedef struct
{
- drflac_frame_header header;
- drflac_uint32 pcmFramesRemaining;
- drflac_subframe subframes[8];
-} drflac_frame;
+ ma_dr_flac_frame_header header;
+ ma_uint32 pcmFramesRemaining;
+ ma_dr_flac_subframe subframes[8];
+} ma_dr_flac_frame;
typedef struct
{
- drflac_meta_proc onMeta;
+ ma_dr_flac_meta_proc onMeta;
void* pUserDataMD;
- drflac_allocation_callbacks allocationCallbacks;
- drflac_uint32 sampleRate;
- drflac_uint8 channels;
- drflac_uint8 bitsPerSample;
- drflac_uint16 maxBlockSizeInPCMFrames;
- drflac_uint64 totalPCMFrameCount;
- drflac_container container;
- drflac_uint32 seekpointCount;
- drflac_frame currentFLACFrame;
- drflac_uint64 currentPCMFrame;
- drflac_uint64 firstFLACFramePosInBytes;
- drflac__memory_stream memoryStream;
- drflac_int32* pDecodedSamples;
- drflac_seekpoint* pSeekpoints;
+ ma_allocation_callbacks allocationCallbacks;
+ ma_uint32 sampleRate;
+ ma_uint8 channels;
+ ma_uint8 bitsPerSample;
+ ma_uint16 maxBlockSizeInPCMFrames;
+ ma_uint64 totalPCMFrameCount;
+ ma_dr_flac_container container;
+ ma_uint32 seekpointCount;
+ ma_dr_flac_frame currentFLACFrame;
+ ma_uint64 currentPCMFrame;
+ ma_uint64 firstFLACFramePosInBytes;
+ ma_dr_flac__memory_stream memoryStream;
+ ma_int32* pDecodedSamples;
+ ma_dr_flac_seekpoint* pSeekpoints;
void* _oggbs;
- drflac_bool32 _noSeekTableSeek : 1;
- drflac_bool32 _noBinarySearchSeek : 1;
- drflac_bool32 _noBruteForceSeek : 1;
- drflac_bs bs;
- drflac_uint8 pExtraData[1];
-} drflac;
-DRFLAC_API drflac* drflac_open(drflac_read_proc onRead, drflac_seek_proc onSeek, void* pUserData, const drflac_allocation_callbacks* pAllocationCallbacks);
-DRFLAC_API drflac* drflac_open_relaxed(drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_container container, void* pUserData, const drflac_allocation_callbacks* pAllocationCallbacks);
-DRFLAC_API drflac* drflac_open_with_metadata(drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_meta_proc onMeta, void* pUserData, const drflac_allocation_callbacks* pAllocationCallbacks);
-DRFLAC_API drflac* drflac_open_with_metadata_relaxed(drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_meta_proc onMeta, drflac_container container, void* pUserData, const drflac_allocation_callbacks* pAllocationCallbacks);
-DRFLAC_API void drflac_close(drflac* pFlac);
-DRFLAC_API drflac_uint64 drflac_read_pcm_frames_s32(drflac* pFlac, drflac_uint64 framesToRead, drflac_int32* pBufferOut);
-DRFLAC_API drflac_uint64 drflac_read_pcm_frames_s16(drflac* pFlac, drflac_uint64 framesToRead, drflac_int16* pBufferOut);
-DRFLAC_API drflac_uint64 drflac_read_pcm_frames_f32(drflac* pFlac, drflac_uint64 framesToRead, float* pBufferOut);
-DRFLAC_API drflac_bool32 drflac_seek_to_pcm_frame(drflac* pFlac, drflac_uint64 pcmFrameIndex);
-#ifndef DR_FLAC_NO_STDIO
-DRFLAC_API drflac* drflac_open_file(const char* pFileName, const drflac_allocation_callbacks* pAllocationCallbacks);
-DRFLAC_API drflac* drflac_open_file_w(const wchar_t* pFileName, const drflac_allocation_callbacks* pAllocationCallbacks);
-DRFLAC_API drflac* drflac_open_file_with_metadata(const char* pFileName, drflac_meta_proc onMeta, void* pUserData, const drflac_allocation_callbacks* pAllocationCallbacks);
-DRFLAC_API drflac* drflac_open_file_with_metadata_w(const wchar_t* pFileName, drflac_meta_proc onMeta, void* pUserData, const drflac_allocation_callbacks* pAllocationCallbacks);
-#endif
-DRFLAC_API drflac* drflac_open_memory(const void* pData, size_t dataSize, const drflac_allocation_callbacks* pAllocationCallbacks);
-DRFLAC_API drflac* drflac_open_memory_with_metadata(const void* pData, size_t dataSize, drflac_meta_proc onMeta, void* pUserData, const drflac_allocation_callbacks* pAllocationCallbacks);
-DRFLAC_API drflac_int32* drflac_open_and_read_pcm_frames_s32(drflac_read_proc onRead, drflac_seek_proc onSeek, void* pUserData, unsigned int* channels, unsigned int* sampleRate, drflac_uint64* totalPCMFrameCount, const drflac_allocation_callbacks* pAllocationCallbacks);
-DRFLAC_API drflac_int16* drflac_open_and_read_pcm_frames_s16(drflac_read_proc onRead, drflac_seek_proc onSeek, void* pUserData, unsigned int* channels, unsigned int* sampleRate, drflac_uint64* totalPCMFrameCount, const drflac_allocation_callbacks* pAllocationCallbacks);
-DRFLAC_API float* drflac_open_and_read_pcm_frames_f32(drflac_read_proc onRead, drflac_seek_proc onSeek, void* pUserData, unsigned int* channels, unsigned int* sampleRate, drflac_uint64* totalPCMFrameCount, const drflac_allocation_callbacks* pAllocationCallbacks);
-#ifndef DR_FLAC_NO_STDIO
-DRFLAC_API drflac_int32* drflac_open_file_and_read_pcm_frames_s32(const char* filename, unsigned int* channels, unsigned int* sampleRate, drflac_uint64* totalPCMFrameCount, const drflac_allocation_callbacks* pAllocationCallbacks);
-DRFLAC_API drflac_int16* drflac_open_file_and_read_pcm_frames_s16(const char* filename, unsigned int* channels, unsigned int* sampleRate, drflac_uint64* totalPCMFrameCount, const drflac_allocation_callbacks* pAllocationCallbacks);
-DRFLAC_API float* drflac_open_file_and_read_pcm_frames_f32(const char* filename, unsigned int* channels, unsigned int* sampleRate, drflac_uint64* totalPCMFrameCount, const drflac_allocation_callbacks* pAllocationCallbacks);
-#endif
-DRFLAC_API drflac_int32* drflac_open_memory_and_read_pcm_frames_s32(const void* data, size_t dataSize, unsigned int* channels, unsigned int* sampleRate, drflac_uint64* totalPCMFrameCount, const drflac_allocation_callbacks* pAllocationCallbacks);
-DRFLAC_API drflac_int16* drflac_open_memory_and_read_pcm_frames_s16(const void* data, size_t dataSize, unsigned int* channels, unsigned int* sampleRate, drflac_uint64* totalPCMFrameCount, const drflac_allocation_callbacks* pAllocationCallbacks);
-DRFLAC_API float* drflac_open_memory_and_read_pcm_frames_f32(const void* data, size_t dataSize, unsigned int* channels, unsigned int* sampleRate, drflac_uint64* totalPCMFrameCount, const drflac_allocation_callbacks* pAllocationCallbacks);
-DRFLAC_API void drflac_free(void* p, const drflac_allocation_callbacks* pAllocationCallbacks);
+ ma_bool32 _noSeekTableSeek : 1;
+ ma_bool32 _noBinarySearchSeek : 1;
+ ma_bool32 _noBruteForceSeek : 1;
+ ma_dr_flac_bs bs;
+ ma_uint8 pExtraData[1];
+} ma_dr_flac;
+MA_API ma_dr_flac* ma_dr_flac_open(ma_dr_flac_read_proc onRead, ma_dr_flac_seek_proc onSeek, void* pUserData, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_dr_flac* ma_dr_flac_open_relaxed(ma_dr_flac_read_proc onRead, ma_dr_flac_seek_proc onSeek, ma_dr_flac_container container, void* pUserData, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_dr_flac* ma_dr_flac_open_with_metadata(ma_dr_flac_read_proc onRead, ma_dr_flac_seek_proc onSeek, ma_dr_flac_meta_proc onMeta, void* pUserData, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_dr_flac* ma_dr_flac_open_with_metadata_relaxed(ma_dr_flac_read_proc onRead, ma_dr_flac_seek_proc onSeek, ma_dr_flac_meta_proc onMeta, ma_dr_flac_container container, void* pUserData, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API void ma_dr_flac_close(ma_dr_flac* pFlac);
+MA_API ma_uint64 ma_dr_flac_read_pcm_frames_s32(ma_dr_flac* pFlac, ma_uint64 framesToRead, ma_int32* pBufferOut);
+MA_API ma_uint64 ma_dr_flac_read_pcm_frames_s16(ma_dr_flac* pFlac, ma_uint64 framesToRead, ma_int16* pBufferOut);
+MA_API ma_uint64 ma_dr_flac_read_pcm_frames_f32(ma_dr_flac* pFlac, ma_uint64 framesToRead, float* pBufferOut);
+MA_API ma_bool32 ma_dr_flac_seek_to_pcm_frame(ma_dr_flac* pFlac, ma_uint64 pcmFrameIndex);
+#ifndef MA_DR_FLAC_NO_STDIO
+MA_API ma_dr_flac* ma_dr_flac_open_file(const char* pFileName, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_dr_flac* ma_dr_flac_open_file_w(const wchar_t* pFileName, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_dr_flac* ma_dr_flac_open_file_with_metadata(const char* pFileName, ma_dr_flac_meta_proc onMeta, void* pUserData, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_dr_flac* ma_dr_flac_open_file_with_metadata_w(const wchar_t* pFileName, ma_dr_flac_meta_proc onMeta, void* pUserData, const ma_allocation_callbacks* pAllocationCallbacks);
+#endif
+MA_API ma_dr_flac* ma_dr_flac_open_memory(const void* pData, size_t dataSize, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_dr_flac* ma_dr_flac_open_memory_with_metadata(const void* pData, size_t dataSize, ma_dr_flac_meta_proc onMeta, void* pUserData, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_int32* ma_dr_flac_open_and_read_pcm_frames_s32(ma_dr_flac_read_proc onRead, ma_dr_flac_seek_proc onSeek, void* pUserData, unsigned int* channels, unsigned int* sampleRate, ma_uint64* totalPCMFrameCount, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_int16* ma_dr_flac_open_and_read_pcm_frames_s16(ma_dr_flac_read_proc onRead, ma_dr_flac_seek_proc onSeek, void* pUserData, unsigned int* channels, unsigned int* sampleRate, ma_uint64* totalPCMFrameCount, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API float* ma_dr_flac_open_and_read_pcm_frames_f32(ma_dr_flac_read_proc onRead, ma_dr_flac_seek_proc onSeek, void* pUserData, unsigned int* channels, unsigned int* sampleRate, ma_uint64* totalPCMFrameCount, const ma_allocation_callbacks* pAllocationCallbacks);
+#ifndef MA_DR_FLAC_NO_STDIO
+MA_API ma_int32* ma_dr_flac_open_file_and_read_pcm_frames_s32(const char* filename, unsigned int* channels, unsigned int* sampleRate, ma_uint64* totalPCMFrameCount, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_int16* ma_dr_flac_open_file_and_read_pcm_frames_s16(const char* filename, unsigned int* channels, unsigned int* sampleRate, ma_uint64* totalPCMFrameCount, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API float* ma_dr_flac_open_file_and_read_pcm_frames_f32(const char* filename, unsigned int* channels, unsigned int* sampleRate, ma_uint64* totalPCMFrameCount, const ma_allocation_callbacks* pAllocationCallbacks);
+#endif
+MA_API ma_int32* ma_dr_flac_open_memory_and_read_pcm_frames_s32(const void* data, size_t dataSize, unsigned int* channels, unsigned int* sampleRate, ma_uint64* totalPCMFrameCount, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_int16* ma_dr_flac_open_memory_and_read_pcm_frames_s16(const void* data, size_t dataSize, unsigned int* channels, unsigned int* sampleRate, ma_uint64* totalPCMFrameCount, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API float* ma_dr_flac_open_memory_and_read_pcm_frames_f32(const void* data, size_t dataSize, unsigned int* channels, unsigned int* sampleRate, ma_uint64* totalPCMFrameCount, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API void ma_dr_flac_free(void* p, const ma_allocation_callbacks* pAllocationCallbacks);
typedef struct
{
- drflac_uint32 countRemaining;
+ ma_uint32 countRemaining;
const char* pRunningData;
-} drflac_vorbis_comment_iterator;
-DRFLAC_API void drflac_init_vorbis_comment_iterator(drflac_vorbis_comment_iterator* pIter, drflac_uint32 commentCount, const void* pComments);
-DRFLAC_API const char* drflac_next_vorbis_comment(drflac_vorbis_comment_iterator* pIter, drflac_uint32* pCommentLengthOut);
+} ma_dr_flac_vorbis_comment_iterator;
+MA_API void ma_dr_flac_init_vorbis_comment_iterator(ma_dr_flac_vorbis_comment_iterator* pIter, ma_uint32 commentCount, const void* pComments);
+MA_API const char* ma_dr_flac_next_vorbis_comment(ma_dr_flac_vorbis_comment_iterator* pIter, ma_uint32* pCommentLengthOut);
typedef struct
{
- drflac_uint32 countRemaining;
+ ma_uint32 countRemaining;
const char* pRunningData;
-} drflac_cuesheet_track_iterator;
+} ma_dr_flac_cuesheet_track_iterator;
typedef struct
{
- drflac_uint64 offset;
- drflac_uint8 index;
- drflac_uint8 reserved[3];
-} drflac_cuesheet_track_index;
+ ma_uint64 offset;
+ ma_uint8 index;
+ ma_uint8 reserved[3];
+} ma_dr_flac_cuesheet_track_index;
typedef struct
{
- drflac_uint64 offset;
- drflac_uint8 trackNumber;
+ ma_uint64 offset;
+ ma_uint8 trackNumber;
char ISRC[12];
- drflac_bool8 isAudio;
- drflac_bool8 preEmphasis;
- drflac_uint8 indexCount;
- const drflac_cuesheet_track_index* pIndexPoints;
-} drflac_cuesheet_track;
-DRFLAC_API void drflac_init_cuesheet_track_iterator(drflac_cuesheet_track_iterator* pIter, drflac_uint32 trackCount, const void* pTrackData);
-DRFLAC_API drflac_bool32 drflac_next_cuesheet_track(drflac_cuesheet_track_iterator* pIter, drflac_cuesheet_track* pCuesheetTrack);
+ ma_bool8 isAudio;
+ ma_bool8 preEmphasis;
+ ma_uint8 indexCount;
+ const ma_dr_flac_cuesheet_track_index* pIndexPoints;
+} ma_dr_flac_cuesheet_track;
+MA_API void ma_dr_flac_init_cuesheet_track_iterator(ma_dr_flac_cuesheet_track_iterator* pIter, ma_uint32 trackCount, const void* pTrackData);
+MA_API ma_bool32 ma_dr_flac_next_cuesheet_track(ma_dr_flac_cuesheet_track_iterator* pIter, ma_dr_flac_cuesheet_track* pCuesheetTrack);
#ifdef __cplusplus
}
#endif
@@ -58690,249 +60456,109 @@ DRFLAC_API drflac_bool32 drflac_next_cuesheet_track(drflac_cuesheet_track_iterat
#if !defined(MA_NO_MP3) && !defined(MA_NO_DECODING)
/* dr_mp3_h begin */
-#ifndef dr_mp3_h
-#define dr_mp3_h
+#ifndef ma_dr_mp3_h
+#define ma_dr_mp3_h
#ifdef __cplusplus
extern "C" {
#endif
-#define DRMP3_STRINGIFY(x) #x
-#define DRMP3_XSTRINGIFY(x) DRMP3_STRINGIFY(x)
-#define DRMP3_VERSION_MAJOR 0
-#define DRMP3_VERSION_MINOR 6
-#define DRMP3_VERSION_REVISION 34
-#define DRMP3_VERSION_STRING DRMP3_XSTRINGIFY(DRMP3_VERSION_MAJOR) "." DRMP3_XSTRINGIFY(DRMP3_VERSION_MINOR) "." DRMP3_XSTRINGIFY(DRMP3_VERSION_REVISION)
+#define MA_DR_MP3_STRINGIFY(x) #x
+#define MA_DR_MP3_XSTRINGIFY(x) MA_DR_MP3_STRINGIFY(x)
+#define MA_DR_MP3_VERSION_MAJOR 0
+#define MA_DR_MP3_VERSION_MINOR 6
+#define MA_DR_MP3_VERSION_REVISION 38
+#define MA_DR_MP3_VERSION_STRING MA_DR_MP3_XSTRINGIFY(MA_DR_MP3_VERSION_MAJOR) "." MA_DR_MP3_XSTRINGIFY(MA_DR_MP3_VERSION_MINOR) "." MA_DR_MP3_XSTRINGIFY(MA_DR_MP3_VERSION_REVISION)
#include
-typedef signed char drmp3_int8;
-typedef unsigned char drmp3_uint8;
-typedef signed short drmp3_int16;
-typedef unsigned short drmp3_uint16;
-typedef signed int drmp3_int32;
-typedef unsigned int drmp3_uint32;
-#if defined(_MSC_VER) && !defined(__clang__)
- typedef signed __int64 drmp3_int64;
- typedef unsigned __int64 drmp3_uint64;
-#else
- #if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)))
- #pragma GCC diagnostic push
- #pragma GCC diagnostic ignored "-Wlong-long"
- #if defined(__clang__)
- #pragma GCC diagnostic ignored "-Wc++11-long-long"
- #endif
- #endif
- typedef signed long long drmp3_int64;
- typedef unsigned long long drmp3_uint64;
- #if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)))
- #pragma GCC diagnostic pop
- #endif
-#endif
-#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__)) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(_M_ARM64) || defined(__powerpc64__)
- typedef drmp3_uint64 drmp3_uintptr;
-#else
- typedef drmp3_uint32 drmp3_uintptr;
-#endif
-typedef drmp3_uint8 drmp3_bool8;
-typedef drmp3_uint32 drmp3_bool32;
-#define DRMP3_TRUE 1
-#define DRMP3_FALSE 0
-#if !defined(DRMP3_API)
- #if defined(DRMP3_DLL)
- #if defined(_WIN32)
- #define DRMP3_DLL_IMPORT __declspec(dllimport)
- #define DRMP3_DLL_EXPORT __declspec(dllexport)
- #define DRMP3_DLL_PRIVATE static
- #else
- #if defined(__GNUC__) && __GNUC__ >= 4
- #define DRMP3_DLL_IMPORT __attribute__((visibility("default")))
- #define DRMP3_DLL_EXPORT __attribute__((visibility("default")))
- #define DRMP3_DLL_PRIVATE __attribute__((visibility("hidden")))
- #else
- #define DRMP3_DLL_IMPORT
- #define DRMP3_DLL_EXPORT
- #define DRMP3_DLL_PRIVATE static
- #endif
- #endif
- #if defined(DR_MP3_IMPLEMENTATION) || defined(DRMP3_IMPLEMENTATION)
- #define DRMP3_API DRMP3_DLL_EXPORT
- #else
- #define DRMP3_API DRMP3_DLL_IMPORT
- #endif
- #define DRMP3_PRIVATE DRMP3_DLL_PRIVATE
- #else
- #define DRMP3_API extern
- #define DRMP3_PRIVATE static
- #endif
-#endif
-typedef drmp3_int32 drmp3_result;
-#define DRMP3_SUCCESS 0
-#define DRMP3_ERROR -1
-#define DRMP3_INVALID_ARGS -2
-#define DRMP3_INVALID_OPERATION -3
-#define DRMP3_OUT_OF_MEMORY -4
-#define DRMP3_OUT_OF_RANGE -5
-#define DRMP3_ACCESS_DENIED -6
-#define DRMP3_DOES_NOT_EXIST -7
-#define DRMP3_ALREADY_EXISTS -8
-#define DRMP3_TOO_MANY_OPEN_FILES -9
-#define DRMP3_INVALID_FILE -10
-#define DRMP3_TOO_BIG -11
-#define DRMP3_PATH_TOO_LONG -12
-#define DRMP3_NAME_TOO_LONG -13
-#define DRMP3_NOT_DIRECTORY -14
-#define DRMP3_IS_DIRECTORY -15
-#define DRMP3_DIRECTORY_NOT_EMPTY -16
-#define DRMP3_END_OF_FILE -17
-#define DRMP3_NO_SPACE -18
-#define DRMP3_BUSY -19
-#define DRMP3_IO_ERROR -20
-#define DRMP3_INTERRUPT -21
-#define DRMP3_UNAVAILABLE -22
-#define DRMP3_ALREADY_IN_USE -23
-#define DRMP3_BAD_ADDRESS -24
-#define DRMP3_BAD_SEEK -25
-#define DRMP3_BAD_PIPE -26
-#define DRMP3_DEADLOCK -27
-#define DRMP3_TOO_MANY_LINKS -28
-#define DRMP3_NOT_IMPLEMENTED -29
-#define DRMP3_NO_MESSAGE -30
-#define DRMP3_BAD_MESSAGE -31
-#define DRMP3_NO_DATA_AVAILABLE -32
-#define DRMP3_INVALID_DATA -33
-#define DRMP3_TIMEOUT -34
-#define DRMP3_NO_NETWORK -35
-#define DRMP3_NOT_UNIQUE -36
-#define DRMP3_NOT_SOCKET -37
-#define DRMP3_NO_ADDRESS -38
-#define DRMP3_BAD_PROTOCOL -39
-#define DRMP3_PROTOCOL_UNAVAILABLE -40
-#define DRMP3_PROTOCOL_NOT_SUPPORTED -41
-#define DRMP3_PROTOCOL_FAMILY_NOT_SUPPORTED -42
-#define DRMP3_ADDRESS_FAMILY_NOT_SUPPORTED -43
-#define DRMP3_SOCKET_NOT_SUPPORTED -44
-#define DRMP3_CONNECTION_RESET -45
-#define DRMP3_ALREADY_CONNECTED -46
-#define DRMP3_NOT_CONNECTED -47
-#define DRMP3_CONNECTION_REFUSED -48
-#define DRMP3_NO_HOST -49
-#define DRMP3_IN_PROGRESS -50
-#define DRMP3_CANCELLED -51
-#define DRMP3_MEMORY_ALREADY_MAPPED -52
-#define DRMP3_AT_END -53
-#define DRMP3_MAX_PCM_FRAMES_PER_MP3_FRAME 1152
-#define DRMP3_MAX_SAMPLES_PER_FRAME (DRMP3_MAX_PCM_FRAMES_PER_MP3_FRAME*2)
-#ifdef _MSC_VER
- #define DRMP3_INLINE __forceinline
-#elif defined(__GNUC__)
- #if defined(__STRICT_ANSI__)
- #define DRMP3_GNUC_INLINE_HINT __inline__
- #else
- #define DRMP3_GNUC_INLINE_HINT inline
- #endif
- #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 2)) || defined(__clang__)
- #define DRMP3_INLINE DRMP3_GNUC_INLINE_HINT __attribute__((always_inline))
- #else
- #define DRMP3_INLINE DRMP3_GNUC_INLINE_HINT
- #endif
-#elif defined(__WATCOMC__)
- #define DRMP3_INLINE __inline
-#else
- #define DRMP3_INLINE
-#endif
-DRMP3_API void drmp3_version(drmp3_uint32* pMajor, drmp3_uint32* pMinor, drmp3_uint32* pRevision);
-DRMP3_API const char* drmp3_version_string(void);
+#define MA_DR_MP3_MAX_PCM_FRAMES_PER_MP3_FRAME 1152
+#define MA_DR_MP3_MAX_SAMPLES_PER_FRAME (MA_DR_MP3_MAX_PCM_FRAMES_PER_MP3_FRAME*2)
+MA_API void ma_dr_mp3_version(ma_uint32* pMajor, ma_uint32* pMinor, ma_uint32* pRevision);
+MA_API const char* ma_dr_mp3_version_string(void);
typedef struct
{
int frame_bytes, channels, hz, layer, bitrate_kbps;
-} drmp3dec_frame_info;
+} ma_dr_mp3dec_frame_info;
typedef struct
{
float mdct_overlap[2][9*32], qmf_state[15*2*32];
int reserv, free_format_bytes;
- drmp3_uint8 header[4], reserv_buf[511];
-} drmp3dec;
-DRMP3_API void drmp3dec_init(drmp3dec *dec);
-DRMP3_API int drmp3dec_decode_frame(drmp3dec *dec, const drmp3_uint8 *mp3, int mp3_bytes, void *pcm, drmp3dec_frame_info *info);
-DRMP3_API void drmp3dec_f32_to_s16(const float *in, drmp3_int16 *out, size_t num_samples);
+ ma_uint8 header[4], reserv_buf[511];
+} ma_dr_mp3dec;
+MA_API void ma_dr_mp3dec_init(ma_dr_mp3dec *dec);
+MA_API int ma_dr_mp3dec_decode_frame(ma_dr_mp3dec *dec, const ma_uint8 *mp3, int mp3_bytes, void *pcm, ma_dr_mp3dec_frame_info *info);
+MA_API void ma_dr_mp3dec_f32_to_s16(const float *in, ma_int16 *out, size_t num_samples);
typedef enum
{
- drmp3_seek_origin_start,
- drmp3_seek_origin_current
-} drmp3_seek_origin;
+ ma_dr_mp3_seek_origin_start,
+ ma_dr_mp3_seek_origin_current
+} ma_dr_mp3_seek_origin;
typedef struct
{
- drmp3_uint64 seekPosInBytes;
- drmp3_uint64 pcmFrameIndex;
- drmp3_uint16 mp3FramesToDiscard;
- drmp3_uint16 pcmFramesToDiscard;
-} drmp3_seek_point;
-typedef size_t (* drmp3_read_proc)(void* pUserData, void* pBufferOut, size_t bytesToRead);
-typedef drmp3_bool32 (* drmp3_seek_proc)(void* pUserData, int offset, drmp3_seek_origin origin);
+ ma_uint64 seekPosInBytes;
+ ma_uint64 pcmFrameIndex;
+ ma_uint16 mp3FramesToDiscard;
+ ma_uint16 pcmFramesToDiscard;
+} ma_dr_mp3_seek_point;
+typedef size_t (* ma_dr_mp3_read_proc)(void* pUserData, void* pBufferOut, size_t bytesToRead);
+typedef ma_bool32 (* ma_dr_mp3_seek_proc)(void* pUserData, int offset, ma_dr_mp3_seek_origin origin);
typedef struct
{
- void* pUserData;
- void* (* onMalloc)(size_t sz, void* pUserData);
- void* (* onRealloc)(void* p, size_t sz, void* pUserData);
- void (* onFree)(void* p, void* pUserData);
-} drmp3_allocation_callbacks;
-typedef struct
-{
- drmp3_uint32 channels;
- drmp3_uint32 sampleRate;
-} drmp3_config;
+ ma_uint32 channels;
+ ma_uint32 sampleRate;
+} ma_dr_mp3_config;
typedef struct
{
- drmp3dec decoder;
- drmp3_uint32 channels;
- drmp3_uint32 sampleRate;
- drmp3_read_proc onRead;
- drmp3_seek_proc onSeek;
+ ma_dr_mp3dec decoder;
+ ma_uint32 channels;
+ ma_uint32 sampleRate;
+ ma_dr_mp3_read_proc onRead;
+ ma_dr_mp3_seek_proc onSeek;
void* pUserData;
- drmp3_allocation_callbacks allocationCallbacks;
- drmp3_uint32 mp3FrameChannels;
- drmp3_uint32 mp3FrameSampleRate;
- drmp3_uint32 pcmFramesConsumedInMP3Frame;
- drmp3_uint32 pcmFramesRemainingInMP3Frame;
- drmp3_uint8 pcmFrames[sizeof(float)*DRMP3_MAX_SAMPLES_PER_FRAME];
- drmp3_uint64 currentPCMFrame;
- drmp3_uint64 streamCursor;
- drmp3_seek_point* pSeekPoints;
- drmp3_uint32 seekPointCount;
+ ma_allocation_callbacks allocationCallbacks;
+ ma_uint32 mp3FrameChannels;
+ ma_uint32 mp3FrameSampleRate;
+ ma_uint32 pcmFramesConsumedInMP3Frame;
+ ma_uint32 pcmFramesRemainingInMP3Frame;
+ ma_uint8 pcmFrames[sizeof(float)*MA_DR_MP3_MAX_SAMPLES_PER_FRAME];
+ ma_uint64 currentPCMFrame;
+ ma_uint64 streamCursor;
+ ma_dr_mp3_seek_point* pSeekPoints;
+ ma_uint32 seekPointCount;
size_t dataSize;
size_t dataCapacity;
size_t dataConsumed;
- drmp3_uint8* pData;
- drmp3_bool32 atEnd : 1;
+ ma_uint8* pData;
+ ma_bool32 atEnd : 1;
struct
{
- const drmp3_uint8* pData;
+ const ma_uint8* pData;
size_t dataSize;
size_t currentReadPos;
} memory;
-} drmp3;
-DRMP3_API drmp3_bool32 drmp3_init(drmp3* pMP3, drmp3_read_proc onRead, drmp3_seek_proc onSeek, void* pUserData, const drmp3_allocation_callbacks* pAllocationCallbacks);
-DRMP3_API drmp3_bool32 drmp3_init_memory(drmp3* pMP3, const void* pData, size_t dataSize, const drmp3_allocation_callbacks* pAllocationCallbacks);
-#ifndef DR_MP3_NO_STDIO
-DRMP3_API drmp3_bool32 drmp3_init_file(drmp3* pMP3, const char* pFilePath, const drmp3_allocation_callbacks* pAllocationCallbacks);
-DRMP3_API drmp3_bool32 drmp3_init_file_w(drmp3* pMP3, const wchar_t* pFilePath, const drmp3_allocation_callbacks* pAllocationCallbacks);
-#endif
-DRMP3_API void drmp3_uninit(drmp3* pMP3);
-DRMP3_API drmp3_uint64 drmp3_read_pcm_frames_f32(drmp3* pMP3, drmp3_uint64 framesToRead, float* pBufferOut);
-DRMP3_API drmp3_uint64 drmp3_read_pcm_frames_s16(drmp3* pMP3, drmp3_uint64 framesToRead, drmp3_int16* pBufferOut);
-DRMP3_API drmp3_bool32 drmp3_seek_to_pcm_frame(drmp3* pMP3, drmp3_uint64 frameIndex);
-DRMP3_API drmp3_uint64 drmp3_get_pcm_frame_count(drmp3* pMP3);
-DRMP3_API drmp3_uint64 drmp3_get_mp3_frame_count(drmp3* pMP3);
-DRMP3_API drmp3_bool32 drmp3_get_mp3_and_pcm_frame_count(drmp3* pMP3, drmp3_uint64* pMP3FrameCount, drmp3_uint64* pPCMFrameCount);
-DRMP3_API drmp3_bool32 drmp3_calculate_seek_points(drmp3* pMP3, drmp3_uint32* pSeekPointCount, drmp3_seek_point* pSeekPoints);
-DRMP3_API drmp3_bool32 drmp3_bind_seek_table(drmp3* pMP3, drmp3_uint32 seekPointCount, drmp3_seek_point* pSeekPoints);
-DRMP3_API float* drmp3_open_and_read_pcm_frames_f32(drmp3_read_proc onRead, drmp3_seek_proc onSeek, void* pUserData, drmp3_config* pConfig, drmp3_uint64* pTotalFrameCount, const drmp3_allocation_callbacks* pAllocationCallbacks);
-DRMP3_API drmp3_int16* drmp3_open_and_read_pcm_frames_s16(drmp3_read_proc onRead, drmp3_seek_proc onSeek, void* pUserData, drmp3_config* pConfig, drmp3_uint64* pTotalFrameCount, const drmp3_allocation_callbacks* pAllocationCallbacks);
-DRMP3_API float* drmp3_open_memory_and_read_pcm_frames_f32(const void* pData, size_t dataSize, drmp3_config* pConfig, drmp3_uint64* pTotalFrameCount, const drmp3_allocation_callbacks* pAllocationCallbacks);
-DRMP3_API drmp3_int16* drmp3_open_memory_and_read_pcm_frames_s16(const void* pData, size_t dataSize, drmp3_config* pConfig, drmp3_uint64* pTotalFrameCount, const drmp3_allocation_callbacks* pAllocationCallbacks);
-#ifndef DR_MP3_NO_STDIO
-DRMP3_API float* drmp3_open_file_and_read_pcm_frames_f32(const char* filePath, drmp3_config* pConfig, drmp3_uint64* pTotalFrameCount, const drmp3_allocation_callbacks* pAllocationCallbacks);
-DRMP3_API drmp3_int16* drmp3_open_file_and_read_pcm_frames_s16(const char* filePath, drmp3_config* pConfig, drmp3_uint64* pTotalFrameCount, const drmp3_allocation_callbacks* pAllocationCallbacks);
-#endif
-DRMP3_API void* drmp3_malloc(size_t sz, const drmp3_allocation_callbacks* pAllocationCallbacks);
-DRMP3_API void drmp3_free(void* p, const drmp3_allocation_callbacks* pAllocationCallbacks);
+} ma_dr_mp3;
+MA_API ma_bool32 ma_dr_mp3_init(ma_dr_mp3* pMP3, ma_dr_mp3_read_proc onRead, ma_dr_mp3_seek_proc onSeek, void* pUserData, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_bool32 ma_dr_mp3_init_memory(ma_dr_mp3* pMP3, const void* pData, size_t dataSize, const ma_allocation_callbacks* pAllocationCallbacks);
+#ifndef MA_DR_MP3_NO_STDIO
+MA_API ma_bool32 ma_dr_mp3_init_file(ma_dr_mp3* pMP3, const char* pFilePath, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_bool32 ma_dr_mp3_init_file_w(ma_dr_mp3* pMP3, const wchar_t* pFilePath, const ma_allocation_callbacks* pAllocationCallbacks);
+#endif
+MA_API void ma_dr_mp3_uninit(ma_dr_mp3* pMP3);
+MA_API ma_uint64 ma_dr_mp3_read_pcm_frames_f32(ma_dr_mp3* pMP3, ma_uint64 framesToRead, float* pBufferOut);
+MA_API ma_uint64 ma_dr_mp3_read_pcm_frames_s16(ma_dr_mp3* pMP3, ma_uint64 framesToRead, ma_int16* pBufferOut);
+MA_API ma_bool32 ma_dr_mp3_seek_to_pcm_frame(ma_dr_mp3* pMP3, ma_uint64 frameIndex);
+MA_API ma_uint64 ma_dr_mp3_get_pcm_frame_count(ma_dr_mp3* pMP3);
+MA_API ma_uint64 ma_dr_mp3_get_mp3_frame_count(ma_dr_mp3* pMP3);
+MA_API ma_bool32 ma_dr_mp3_get_mp3_and_pcm_frame_count(ma_dr_mp3* pMP3, ma_uint64* pMP3FrameCount, ma_uint64* pPCMFrameCount);
+MA_API ma_bool32 ma_dr_mp3_calculate_seek_points(ma_dr_mp3* pMP3, ma_uint32* pSeekPointCount, ma_dr_mp3_seek_point* pSeekPoints);
+MA_API ma_bool32 ma_dr_mp3_bind_seek_table(ma_dr_mp3* pMP3, ma_uint32 seekPointCount, ma_dr_mp3_seek_point* pSeekPoints);
+MA_API float* ma_dr_mp3_open_and_read_pcm_frames_f32(ma_dr_mp3_read_proc onRead, ma_dr_mp3_seek_proc onSeek, void* pUserData, ma_dr_mp3_config* pConfig, ma_uint64* pTotalFrameCount, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_int16* ma_dr_mp3_open_and_read_pcm_frames_s16(ma_dr_mp3_read_proc onRead, ma_dr_mp3_seek_proc onSeek, void* pUserData, ma_dr_mp3_config* pConfig, ma_uint64* pTotalFrameCount, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API float* ma_dr_mp3_open_memory_and_read_pcm_frames_f32(const void* pData, size_t dataSize, ma_dr_mp3_config* pConfig, ma_uint64* pTotalFrameCount, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_int16* ma_dr_mp3_open_memory_and_read_pcm_frames_s16(const void* pData, size_t dataSize, ma_dr_mp3_config* pConfig, ma_uint64* pTotalFrameCount, const ma_allocation_callbacks* pAllocationCallbacks);
+#ifndef MA_DR_MP3_NO_STDIO
+MA_API float* ma_dr_mp3_open_file_and_read_pcm_frames_f32(const char* filePath, ma_dr_mp3_config* pConfig, ma_uint64* pTotalFrameCount, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API ma_int16* ma_dr_mp3_open_file_and_read_pcm_frames_s16(const char* filePath, ma_dr_mp3_config* pConfig, ma_uint64* pTotalFrameCount, const ma_allocation_callbacks* pAllocationCallbacks);
+#endif
+MA_API void* ma_dr_mp3_malloc(size_t sz, const ma_allocation_callbacks* pAllocationCallbacks);
+MA_API void ma_dr_mp3_free(void* p, const ma_allocation_callbacks* pAllocationCallbacks);
#ifdef __cplusplus
}
#endif
@@ -59146,7 +60772,7 @@ static ma_result ma_decoder_internal_on_tell__custom(void* pUserData, ma_int64*
}
-static ma_result ma_decoder_init_from_vtable(const ma_decoding_backend_vtable* pVTable, void* pVTableUserData, const ma_decoder_config* pConfig, ma_decoder* pDecoder)
+static ma_result ma_decoder_init_from_vtable__internal(const ma_decoding_backend_vtable* pVTable, void* pVTableUserData, const ma_decoder_config* pConfig, ma_decoder* pDecoder)
{
ma_result result;
ma_decoding_backend_config backendConfig;
@@ -59175,6 +60801,93 @@ static ma_result ma_decoder_init_from_vtable(const ma_decoding_backend_vtable* p
return MA_SUCCESS;
}
+static ma_result ma_decoder_init_from_file__internal(const ma_decoding_backend_vtable* pVTable, void* pVTableUserData, const char* pFilePath, const ma_decoder_config* pConfig, ma_decoder* pDecoder)
+{
+ ma_result result;
+ ma_decoding_backend_config backendConfig;
+ ma_data_source* pBackend;
+
+ MA_ASSERT(pVTable != NULL);
+ MA_ASSERT(pConfig != NULL);
+ MA_ASSERT(pDecoder != NULL);
+
+ if (pVTable->onInitFile == NULL) {
+ return MA_NOT_IMPLEMENTED;
+ }
+
+ backendConfig = ma_decoding_backend_config_init(pConfig->format, pConfig->seekPointCount);
+
+ result = pVTable->onInitFile(pVTableUserData, pFilePath, &backendConfig, &pDecoder->allocationCallbacks, &pBackend);
+ if (result != MA_SUCCESS) {
+ return result; /* Failed to initialize the backend from this vtable. */
+ }
+
+ /* Getting here means we were able to initialize the backend so we can now initialize the decoder. */
+ pDecoder->pBackend = pBackend;
+ pDecoder->pBackendVTable = pVTable;
+ pDecoder->pBackendUserData = pConfig->pCustomBackendUserData;
+
+ return MA_SUCCESS;
+}
+
+static ma_result ma_decoder_init_from_file_w__internal(const ma_decoding_backend_vtable* pVTable, void* pVTableUserData, const wchar_t* pFilePath, const ma_decoder_config* pConfig, ma_decoder* pDecoder)
+{
+ ma_result result;
+ ma_decoding_backend_config backendConfig;
+ ma_data_source* pBackend;
+
+ MA_ASSERT(pVTable != NULL);
+ MA_ASSERT(pConfig != NULL);
+ MA_ASSERT(pDecoder != NULL);
+
+ if (pVTable->onInitFileW == NULL) {
+ return MA_NOT_IMPLEMENTED;
+ }
+
+ backendConfig = ma_decoding_backend_config_init(pConfig->format, pConfig->seekPointCount);
+
+ result = pVTable->onInitFileW(pVTableUserData, pFilePath, &backendConfig, &pDecoder->allocationCallbacks, &pBackend);
+ if (result != MA_SUCCESS) {
+ return result; /* Failed to initialize the backend from this vtable. */
+ }
+
+ /* Getting here means we were able to initialize the backend so we can now initialize the decoder. */
+ pDecoder->pBackend = pBackend;
+ pDecoder->pBackendVTable = pVTable;
+ pDecoder->pBackendUserData = pConfig->pCustomBackendUserData;
+
+ return MA_SUCCESS;
+}
+
+static ma_result ma_decoder_init_from_memory__internal(const ma_decoding_backend_vtable* pVTable, void* pVTableUserData, const void* pData, size_t dataSize, const ma_decoder_config* pConfig, ma_decoder* pDecoder)
+{
+ ma_result result;
+ ma_decoding_backend_config backendConfig;
+ ma_data_source* pBackend;
+
+ MA_ASSERT(pVTable != NULL);
+ MA_ASSERT(pConfig != NULL);
+ MA_ASSERT(pDecoder != NULL);
+
+ if (pVTable->onInitMemory == NULL) {
+ return MA_NOT_IMPLEMENTED;
+ }
+
+ backendConfig = ma_decoding_backend_config_init(pConfig->format, pConfig->seekPointCount);
+
+ result = pVTable->onInitMemory(pVTableUserData, pData, dataSize, &backendConfig, &pDecoder->allocationCallbacks, &pBackend);
+ if (result != MA_SUCCESS) {
+ return result; /* Failed to initialize the backend from this vtable. */
+ }
+
+ /* Getting here means we were able to initialize the backend so we can now initialize the decoder. */
+ pDecoder->pBackend = pBackend;
+ pDecoder->pBackendVTable = pVTable;
+ pDecoder->pBackendUserData = pConfig->pCustomBackendUserData;
+
+ return MA_SUCCESS;
+}
+
static ma_result ma_decoder_init_custom__internal(const ma_decoder_config* pConfig, ma_decoder* pDecoder)
@@ -59192,8 +60905,8 @@ static ma_result ma_decoder_init_custom__internal(const ma_decoder_config* pConf
/* The order each backend is listed is what defines the priority. */
for (ivtable = 0; ivtable < pConfig->customBackendCount; ivtable += 1) {
const ma_decoding_backend_vtable* pVTable = pConfig->ppCustomBackendVTables[ivtable];
- if (pVTable != NULL && pVTable->onInit != NULL) {
- result = ma_decoder_init_from_vtable(pVTable, pConfig->pCustomBackendUserData, pConfig, pDecoder);
+ if (pVTable != NULL) {
+ result = ma_decoder_init_from_vtable__internal(pVTable, pConfig->pCustomBackendUserData, pConfig, pDecoder);
if (result == MA_SUCCESS) {
return MA_SUCCESS;
} else {
@@ -59212,9 +60925,96 @@ static ma_result ma_decoder_init_custom__internal(const ma_decoder_config* pConf
return MA_NO_BACKEND;
}
+static ma_result ma_decoder_init_custom_from_file__internal(const char* pFilePath, const ma_decoder_config* pConfig, ma_decoder* pDecoder)
+{
+ ma_result result = MA_NO_BACKEND;
+ size_t ivtable;
+
+ MA_ASSERT(pConfig != NULL);
+ MA_ASSERT(pDecoder != NULL);
+
+ if (pConfig->ppCustomBackendVTables == NULL) {
+ return MA_NO_BACKEND;
+ }
+
+ /* The order each backend is listed is what defines the priority. */
+ for (ivtable = 0; ivtable < pConfig->customBackendCount; ivtable += 1) {
+ const ma_decoding_backend_vtable* pVTable = pConfig->ppCustomBackendVTables[ivtable];
+ if (pVTable != NULL) {
+ result = ma_decoder_init_from_file__internal(pVTable, pConfig->pCustomBackendUserData, pFilePath, pConfig, pDecoder);
+ if (result == MA_SUCCESS) {
+ return MA_SUCCESS;
+ }
+ } else {
+ /* No vtable. */
+ }
+ }
+
+ /* Getting here means we couldn't find a backend. */
+ return MA_NO_BACKEND;
+}
+
+static ma_result ma_decoder_init_custom_from_file_w__internal(const wchar_t* pFilePath, const ma_decoder_config* pConfig, ma_decoder* pDecoder)
+{
+ ma_result result = MA_NO_BACKEND;
+ size_t ivtable;
+
+ MA_ASSERT(pConfig != NULL);
+ MA_ASSERT(pDecoder != NULL);
+
+ if (pConfig->ppCustomBackendVTables == NULL) {
+ return MA_NO_BACKEND;
+ }
+
+ /* The order each backend is listed is what defines the priority. */
+ for (ivtable = 0; ivtable < pConfig->customBackendCount; ivtable += 1) {
+ const ma_decoding_backend_vtable* pVTable = pConfig->ppCustomBackendVTables[ivtable];
+ if (pVTable != NULL) {
+ result = ma_decoder_init_from_file_w__internal(pVTable, pConfig->pCustomBackendUserData, pFilePath, pConfig, pDecoder);
+ if (result == MA_SUCCESS) {
+ return MA_SUCCESS;
+ }
+ } else {
+ /* No vtable. */
+ }
+ }
+
+ /* Getting here means we couldn't find a backend. */
+ return MA_NO_BACKEND;
+}
+
+static ma_result ma_decoder_init_custom_from_memory__internal(const void* pData, size_t dataSize, const ma_decoder_config* pConfig, ma_decoder* pDecoder)
+{
+ ma_result result = MA_NO_BACKEND;
+ size_t ivtable;
+
+ MA_ASSERT(pConfig != NULL);
+ MA_ASSERT(pDecoder != NULL);
+
+ if (pConfig->ppCustomBackendVTables == NULL) {
+ return MA_NO_BACKEND;
+ }
+
+ /* The order each backend is listed is what defines the priority. */
+ for (ivtable = 0; ivtable < pConfig->customBackendCount; ivtable += 1) {
+ const ma_decoding_backend_vtable* pVTable = pConfig->ppCustomBackendVTables[ivtable];
+ if (pVTable != NULL) {
+ result = ma_decoder_init_from_memory__internal(pVTable, pConfig->pCustomBackendUserData, pData, dataSize, pConfig, pDecoder);
+ if (result == MA_SUCCESS) {
+ return MA_SUCCESS;
+ }
+ } else {
+ /* No vtable. */
+ }
+ }
+
+ /* Getting here means we couldn't find a backend. */
+ return MA_NO_BACKEND;
+}
+
/* WAV */
-#ifdef dr_wav_h
+#ifdef ma_dr_wav_h
#define MA_HAS_WAV
typedef struct
@@ -59226,7 +61026,7 @@ typedef struct
void* pReadSeekTellUserData;
ma_format format; /* Can be f32, s16 or s32. */
#if !defined(MA_NO_WAV)
- drwav dr;
+ ma_dr_wav dr;
#endif
} ma_wav;
@@ -59280,25 +61080,6 @@ static ma_data_source_vtable g_ma_wav_ds_vtable =
#if !defined(MA_NO_WAV)
-static drwav_allocation_callbacks drwav_allocation_callbacks_from_miniaudio(const ma_allocation_callbacks* pAllocationCallbacks)
-{
- drwav_allocation_callbacks callbacks;
-
- if (pAllocationCallbacks != NULL) {
- callbacks.onMalloc = pAllocationCallbacks->onMalloc;
- callbacks.onRealloc = pAllocationCallbacks->onRealloc;
- callbacks.onFree = pAllocationCallbacks->onFree;
- callbacks.pUserData = pAllocationCallbacks->pUserData;
- } else {
- callbacks.onMalloc = ma__malloc_default;
- callbacks.onRealloc = ma__realloc_default;
- callbacks.onFree = ma__free_default;
- callbacks.pUserData = NULL;
- }
-
- return callbacks;
-}
-
static size_t ma_wav_dr_callback__read(void* pUserData, void* pBufferOut, size_t bytesToRead)
{
ma_wav* pWav = (ma_wav*)pUserData;
@@ -59313,7 +61094,7 @@ static size_t ma_wav_dr_callback__read(void* pUserData, void* pBufferOut, size_t
return bytesRead;
}
-static drwav_bool32 ma_wav_dr_callback__seek(void* pUserData, int offset, drwav_seek_origin origin)
+static ma_bool32 ma_wav_dr_callback__seek(void* pUserData, int offset, ma_dr_wav_seek_origin origin)
{
ma_wav* pWav = (ma_wav*)pUserData;
ma_result result;
@@ -59322,7 +61103,7 @@ static drwav_bool32 ma_wav_dr_callback__seek(void* pUserData, int offset, drwav_
MA_ASSERT(pWav != NULL);
maSeekOrigin = ma_seek_origin_start;
- if (origin == drwav_seek_origin_current) {
+ if (origin == ma_dr_wav_seek_origin_current) {
maSeekOrigin = ma_seek_origin_current;
}
@@ -59364,6 +61145,47 @@ static ma_result ma_wav_init_internal(const ma_decoding_backend_config* pConfig,
return MA_SUCCESS;
}
+static ma_result ma_wav_post_init(ma_wav* pWav)
+{
+ /*
+ If an explicit format was not specified, try picking the closest match based on the internal
+ format. The format needs to be supported by miniaudio.
+ */
+ if (pWav->format == ma_format_unknown) {
+ switch (pWav->dr.translatedFormatTag)
+ {
+ case MA_DR_WAVE_FORMAT_PCM:
+ {
+ if (pWav->dr.bitsPerSample == 8) {
+ pWav->format = ma_format_u8;
+ } else if (pWav->dr.bitsPerSample == 16) {
+ pWav->format = ma_format_s16;
+ } else if (pWav->dr.bitsPerSample == 24) {
+ pWav->format = ma_format_s24;
+ } else if (pWav->dr.bitsPerSample == 32) {
+ pWav->format = ma_format_s32;
+ }
+ } break;
+
+ case MA_DR_WAVE_FORMAT_IEEE_FLOAT:
+ {
+ if (pWav->dr.bitsPerSample == 32) {
+ pWav->format = ma_format_f32;
+ }
+ } break;
+
+ default: break;
+ }
+
+ /* Fall back to f32 if we couldn't find anything. */
+ if (pWav->format == ma_format_unknown) {
+ pWav->format = ma_format_f32;
+ }
+ }
+
+ return MA_SUCCESS;
+}
+
MA_API ma_result ma_wav_init(ma_read_proc onRead, ma_seek_proc onSeek, ma_tell_proc onTell, void* pReadSeekTellUserData, const ma_decoding_backend_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_wav* pWav)
{
ma_result result;
@@ -59384,49 +61206,14 @@ MA_API ma_result ma_wav_init(ma_read_proc onRead, ma_seek_proc onSeek, ma_tell_p
#if !defined(MA_NO_WAV)
{
- drwav_allocation_callbacks wavAllocationCallbacks = drwav_allocation_callbacks_from_miniaudio(pAllocationCallbacks);
- drwav_bool32 wavResult;
+ ma_bool32 wavResult;
- wavResult = drwav_init(&pWav->dr, ma_wav_dr_callback__read, ma_wav_dr_callback__seek, pWav, &wavAllocationCallbacks);
+ wavResult = ma_dr_wav_init(&pWav->dr, ma_wav_dr_callback__read, ma_wav_dr_callback__seek, pWav, pAllocationCallbacks);
if (wavResult != MA_TRUE) {
return MA_INVALID_FILE;
}
- /*
- If an explicit format was not specified, try picking the closest match based on the internal
- format. The format needs to be supported by miniaudio.
- */
- if (pWav->format == ma_format_unknown) {
- switch (pWav->dr.translatedFormatTag)
- {
- case DR_WAVE_FORMAT_PCM:
- {
- if (pWav->dr.bitsPerSample == 8) {
- pWav->format = ma_format_u8;
- } else if (pWav->dr.bitsPerSample == 16) {
- pWav->format = ma_format_s16;
- } else if (pWav->dr.bitsPerSample == 24) {
- pWav->format = ma_format_s24;
- } else if (pWav->dr.bitsPerSample == 32) {
- pWav->format = ma_format_s32;
- }
- } break;
-
- case DR_WAVE_FORMAT_IEEE_FLOAT:
- {
- if (pWav->dr.bitsPerSample == 32) {
- pWav->format = ma_format_f32;
- }
- } break;
-
- default: break;
- }
-
- /* Fall back to f32 if we couldn't find anything. */
- if (pWav->format == ma_format_unknown) {
- pWav->format = ma_format_f32;
- }
- }
+ ma_wav_post_init(pWav);
return MA_SUCCESS;
}
@@ -59450,14 +61237,15 @@ MA_API ma_result ma_wav_init_file(const char* pFilePath, const ma_decoding_backe
#if !defined(MA_NO_WAV)
{
- drwav_allocation_callbacks wavAllocationCallbacks = drwav_allocation_callbacks_from_miniaudio(pAllocationCallbacks);
- drwav_bool32 wavResult;
+ ma_bool32 wavResult;
- wavResult = drwav_init_file(&pWav->dr, pFilePath, &wavAllocationCallbacks);
+ wavResult = ma_dr_wav_init_file(&pWav->dr, pFilePath, pAllocationCallbacks);
if (wavResult != MA_TRUE) {
return MA_INVALID_FILE;
}
+ ma_wav_post_init(pWav);
+
return MA_SUCCESS;
}
#else
@@ -59481,14 +61269,15 @@ MA_API ma_result ma_wav_init_file_w(const wchar_t* pFilePath, const ma_decoding_
#if !defined(MA_NO_WAV)
{
- drwav_allocation_callbacks wavAllocationCallbacks = drwav_allocation_callbacks_from_miniaudio(pAllocationCallbacks);
- drwav_bool32 wavResult;
+ ma_bool32 wavResult;
- wavResult = drwav_init_file_w(&pWav->dr, pFilePath, &wavAllocationCallbacks);
+ wavResult = ma_dr_wav_init_file_w(&pWav->dr, pFilePath, pAllocationCallbacks);
if (wavResult != MA_TRUE) {
return MA_INVALID_FILE;
}
+ ma_wav_post_init(pWav);
+
return MA_SUCCESS;
}
#else
@@ -59512,14 +61301,15 @@ MA_API ma_result ma_wav_init_memory(const void* pData, size_t dataSize, const ma
#if !defined(MA_NO_WAV)
{
- drwav_allocation_callbacks wavAllocationCallbacks = drwav_allocation_callbacks_from_miniaudio(pAllocationCallbacks);
- drwav_bool32 wavResult;
+ ma_bool32 wavResult;
- wavResult = drwav_init_memory(&pWav->dr, pData, dataSize, &wavAllocationCallbacks);
+ wavResult = ma_dr_wav_init_memory(&pWav->dr, pData, dataSize, pAllocationCallbacks);
if (wavResult != MA_TRUE) {
return MA_INVALID_FILE;
}
+ ma_wav_post_init(pWav);
+
return MA_SUCCESS;
}
#else
@@ -59543,7 +61333,7 @@ MA_API void ma_wav_uninit(ma_wav* pWav, const ma_allocation_callbacks* pAllocati
#if !defined(MA_NO_WAV)
{
- drwav_uninit(&pWav->dr);
+ ma_dr_wav_uninit(&pWav->dr);
}
#else
{
@@ -59582,28 +61372,28 @@ MA_API ma_result ma_wav_read_pcm_frames(ma_wav* pWav, void* pFramesOut, ma_uint6
{
case ma_format_f32:
{
- totalFramesRead = drwav_read_pcm_frames_f32(&pWav->dr, frameCount, (float*)pFramesOut);
+ totalFramesRead = ma_dr_wav_read_pcm_frames_f32(&pWav->dr, frameCount, (float*)pFramesOut);
} break;
case ma_format_s16:
{
- totalFramesRead = drwav_read_pcm_frames_s16(&pWav->dr, frameCount, (drwav_int16*)pFramesOut);
+ totalFramesRead = ma_dr_wav_read_pcm_frames_s16(&pWav->dr, frameCount, (ma_int16*)pFramesOut);
} break;
case ma_format_s32:
{
- totalFramesRead = drwav_read_pcm_frames_s32(&pWav->dr, frameCount, (drwav_int32*)pFramesOut);
+ totalFramesRead = ma_dr_wav_read_pcm_frames_s32(&pWav->dr, frameCount, (ma_int32*)pFramesOut);
} break;
/* Fallback to a raw read. */
case ma_format_unknown: return MA_INVALID_OPERATION; /* <-- this should never be hit because initialization would just fall back to a supported format. */
default:
{
- totalFramesRead = drwav_read_pcm_frames(&pWav->dr, frameCount, pFramesOut);
+ totalFramesRead = ma_dr_wav_read_pcm_frames(&pWav->dr, frameCount, pFramesOut);
} break;
}
- /* In the future we'll update dr_wav to return MA_AT_END for us. */
+ /* In the future we'll update ma_dr_wav to return MA_AT_END for us. */
if (totalFramesRead == 0) {
result = MA_AT_END;
}
@@ -59640,10 +61430,10 @@ MA_API ma_result ma_wav_seek_to_pcm_frame(ma_wav* pWav, ma_uint64 frameIndex)
#if !defined(MA_NO_WAV)
{
- drwav_bool32 wavResult;
+ ma_bool32 wavResult;
- wavResult = drwav_seek_to_pcm_frame(&pWav->dr, frameIndex);
- if (wavResult != DRWAV_TRUE) {
+ wavResult = ma_dr_wav_seek_to_pcm_frame(&pWav->dr, frameIndex);
+ if (wavResult != MA_TRUE) {
return MA_ERROR;
}
@@ -59724,9 +61514,9 @@ MA_API ma_result ma_wav_get_cursor_in_pcm_frames(ma_wav* pWav, ma_uint64* pCurso
#if !defined(MA_NO_WAV)
{
- drwav_result wavResult = drwav_get_cursor_in_pcm_frames(&pWav->dr, pCursor);
- if (wavResult != DRWAV_SUCCESS) {
- return (ma_result)wavResult; /* dr_wav result codes map to miniaudio's. */
+ ma_result wavResult = ma_dr_wav_get_cursor_in_pcm_frames(&pWav->dr, pCursor);
+ if (wavResult != MA_SUCCESS) {
+ return (ma_result)wavResult; /* ma_dr_wav result codes map to miniaudio's. */
}
return MA_SUCCESS;
@@ -59754,9 +61544,9 @@ MA_API ma_result ma_wav_get_length_in_pcm_frames(ma_wav* pWav, ma_uint64* pLengt
#if !defined(MA_NO_WAV)
{
- drwav_result wavResult = drwav_get_length_in_pcm_frames(&pWav->dr, pLength);
- if (wavResult != DRWAV_SUCCESS) {
- return (ma_result)wavResult; /* dr_wav result codes map to miniaudio's. */
+ ma_result wavResult = ma_dr_wav_get_length_in_pcm_frames(&pWav->dr, pLength);
+ if (wavResult != MA_SUCCESS) {
+ return (ma_result)wavResult; /* ma_dr_wav result codes map to miniaudio's. */
}
return MA_SUCCESS;
@@ -59888,12 +61678,27 @@ static ma_decoding_backend_vtable g_ma_decoding_backend_vtable_wav =
static ma_result ma_decoder_init_wav__internal(const ma_decoder_config* pConfig, ma_decoder* pDecoder)
{
- return ma_decoder_init_from_vtable(&g_ma_decoding_backend_vtable_wav, NULL, pConfig, pDecoder);
+ return ma_decoder_init_from_vtable__internal(&g_ma_decoding_backend_vtable_wav, NULL, pConfig, pDecoder);
}
-#endif /* dr_wav_h */
+
+static ma_result ma_decoder_init_wav_from_file__internal(const char* pFilePath, const ma_decoder_config* pConfig, ma_decoder* pDecoder)
+{
+ return ma_decoder_init_from_file__internal(&g_ma_decoding_backend_vtable_wav, NULL, pFilePath, pConfig, pDecoder);
+}
+
+static ma_result ma_decoder_init_wav_from_file_w__internal(const wchar_t* pFilePath, const ma_decoder_config* pConfig, ma_decoder* pDecoder)
+{
+ return ma_decoder_init_from_file_w__internal(&g_ma_decoding_backend_vtable_wav, NULL, pFilePath, pConfig, pDecoder);
+}
+
+static ma_result ma_decoder_init_wav_from_memory__internal(const void* pData, size_t dataSize, const ma_decoder_config* pConfig, ma_decoder* pDecoder)
+{
+ return ma_decoder_init_from_memory__internal(&g_ma_decoding_backend_vtable_wav, NULL, pData, dataSize, pConfig, pDecoder);
+}
+#endif /* ma_dr_wav_h */
/* FLAC */
-#ifdef dr_flac_h
+#ifdef ma_dr_flac_h
#define MA_HAS_FLAC
typedef struct
@@ -59905,7 +61710,7 @@ typedef struct
void* pReadSeekTellUserData;
ma_format format; /* Can be f32, s16 or s32. */
#if !defined(MA_NO_FLAC)
- drflac* dr;
+ ma_dr_flac* dr;
#endif
} ma_flac;
@@ -59959,25 +61764,6 @@ static ma_data_source_vtable g_ma_flac_ds_vtable =
#if !defined(MA_NO_FLAC)
-static drflac_allocation_callbacks drflac_allocation_callbacks_from_miniaudio(const ma_allocation_callbacks* pAllocationCallbacks)
-{
- drflac_allocation_callbacks callbacks;
-
- if (pAllocationCallbacks != NULL) {
- callbacks.onMalloc = pAllocationCallbacks->onMalloc;
- callbacks.onRealloc = pAllocationCallbacks->onRealloc;
- callbacks.onFree = pAllocationCallbacks->onFree;
- callbacks.pUserData = pAllocationCallbacks->pUserData;
- } else {
- callbacks.onMalloc = ma__malloc_default;
- callbacks.onRealloc = ma__realloc_default;
- callbacks.onFree = ma__free_default;
- callbacks.pUserData = NULL;
- }
-
- return callbacks;
-}
-
static size_t ma_flac_dr_callback__read(void* pUserData, void* pBufferOut, size_t bytesToRead)
{
ma_flac* pFlac = (ma_flac*)pUserData;
@@ -59992,7 +61778,7 @@ static size_t ma_flac_dr_callback__read(void* pUserData, void* pBufferOut, size_
return bytesRead;
}
-static drflac_bool32 ma_flac_dr_callback__seek(void* pUserData, int offset, drflac_seek_origin origin)
+static ma_bool32 ma_flac_dr_callback__seek(void* pUserData, int offset, ma_dr_flac_seek_origin origin)
{
ma_flac* pFlac = (ma_flac*)pUserData;
ma_result result;
@@ -60001,7 +61787,7 @@ static drflac_bool32 ma_flac_dr_callback__seek(void* pUserData, int offset, drfl
MA_ASSERT(pFlac != NULL);
maSeekOrigin = ma_seek_origin_start;
- if (origin == drflac_seek_origin_current) {
+ if (origin == ma_dr_flac_seek_origin_current) {
maSeekOrigin = ma_seek_origin_current;
}
@@ -60063,9 +61849,7 @@ MA_API ma_result ma_flac_init(ma_read_proc onRead, ma_seek_proc onSeek, ma_tell_
#if !defined(MA_NO_FLAC)
{
- drflac_allocation_callbacks flacAllocationCallbacks = drflac_allocation_callbacks_from_miniaudio(pAllocationCallbacks);
-
- pFlac->dr = drflac_open(ma_flac_dr_callback__read, ma_flac_dr_callback__seek, pFlac, &flacAllocationCallbacks);
+ pFlac->dr = ma_dr_flac_open(ma_flac_dr_callback__read, ma_flac_dr_callback__seek, pFlac, pAllocationCallbacks);
if (pFlac->dr == NULL) {
return MA_INVALID_FILE;
}
@@ -60092,9 +61876,7 @@ MA_API ma_result ma_flac_init_file(const char* pFilePath, const ma_decoding_back
#if !defined(MA_NO_FLAC)
{
- drflac_allocation_callbacks flacAllocationCallbacks = drflac_allocation_callbacks_from_miniaudio(pAllocationCallbacks);
-
- pFlac->dr = drflac_open_file(pFilePath, &flacAllocationCallbacks);
+ pFlac->dr = ma_dr_flac_open_file(pFilePath, pAllocationCallbacks);
if (pFlac->dr == NULL) {
return MA_INVALID_FILE;
}
@@ -60122,9 +61904,7 @@ MA_API ma_result ma_flac_init_file_w(const wchar_t* pFilePath, const ma_decoding
#if !defined(MA_NO_FLAC)
{
- drflac_allocation_callbacks flacAllocationCallbacks = drflac_allocation_callbacks_from_miniaudio(pAllocationCallbacks);
-
- pFlac->dr = drflac_open_file_w(pFilePath, &flacAllocationCallbacks);
+ pFlac->dr = ma_dr_flac_open_file_w(pFilePath, pAllocationCallbacks);
if (pFlac->dr == NULL) {
return MA_INVALID_FILE;
}
@@ -60152,9 +61932,7 @@ MA_API ma_result ma_flac_init_memory(const void* pData, size_t dataSize, const m
#if !defined(MA_NO_FLAC)
{
- drflac_allocation_callbacks flacAllocationCallbacks = drflac_allocation_callbacks_from_miniaudio(pAllocationCallbacks);
-
- pFlac->dr = drflac_open_memory(pData, dataSize, &flacAllocationCallbacks);
+ pFlac->dr = ma_dr_flac_open_memory(pData, dataSize, pAllocationCallbacks);
if (pFlac->dr == NULL) {
return MA_INVALID_FILE;
}
@@ -60182,7 +61960,7 @@ MA_API void ma_flac_uninit(ma_flac* pFlac, const ma_allocation_callbacks* pAlloc
#if !defined(MA_NO_FLAC)
{
- drflac_close(pFlac->dr);
+ ma_dr_flac_close(pFlac->dr);
}
#else
{
@@ -60221,17 +61999,17 @@ MA_API ma_result ma_flac_read_pcm_frames(ma_flac* pFlac, void* pFramesOut, ma_ui
{
case ma_format_f32:
{
- totalFramesRead = drflac_read_pcm_frames_f32(pFlac->dr, frameCount, (float*)pFramesOut);
+ totalFramesRead = ma_dr_flac_read_pcm_frames_f32(pFlac->dr, frameCount, (float*)pFramesOut);
} break;
case ma_format_s16:
{
- totalFramesRead = drflac_read_pcm_frames_s16(pFlac->dr, frameCount, (drflac_int16*)pFramesOut);
+ totalFramesRead = ma_dr_flac_read_pcm_frames_s16(pFlac->dr, frameCount, (ma_int16*)pFramesOut);
} break;
case ma_format_s32:
{
- totalFramesRead = drflac_read_pcm_frames_s32(pFlac->dr, frameCount, (drflac_int32*)pFramesOut);
+ totalFramesRead = ma_dr_flac_read_pcm_frames_s32(pFlac->dr, frameCount, (ma_int32*)pFramesOut);
} break;
case ma_format_u8:
@@ -60243,7 +62021,7 @@ MA_API ma_result ma_flac_read_pcm_frames(ma_flac* pFlac, void* pFramesOut, ma_ui
};
}
- /* In the future we'll update dr_flac to return MA_AT_END for us. */
+ /* In the future we'll update ma_dr_flac to return MA_AT_END for us. */
if (totalFramesRead == 0) {
result = MA_AT_END;
}
@@ -60280,10 +62058,10 @@ MA_API ma_result ma_flac_seek_to_pcm_frame(ma_flac* pFlac, ma_uint64 frameIndex)
#if !defined(MA_NO_FLAC)
{
- drflac_bool32 flacResult;
+ ma_bool32 flacResult;
- flacResult = drflac_seek_to_pcm_frame(pFlac->dr, frameIndex);
- if (flacResult != DRFLAC_TRUE) {
+ flacResult = ma_dr_flac_seek_to_pcm_frame(pFlac->dr, frameIndex);
+ if (flacResult != MA_TRUE) {
return MA_ERROR;
}
@@ -60522,12 +62300,27 @@ static ma_decoding_backend_vtable g_ma_decoding_backend_vtable_flac =
static ma_result ma_decoder_init_flac__internal(const ma_decoder_config* pConfig, ma_decoder* pDecoder)
{
- return ma_decoder_init_from_vtable(&g_ma_decoding_backend_vtable_flac, NULL, pConfig, pDecoder);
+ return ma_decoder_init_from_vtable__internal(&g_ma_decoding_backend_vtable_flac, NULL, pConfig, pDecoder);
+}
+
+static ma_result ma_decoder_init_flac_from_file__internal(const char* pFilePath, const ma_decoder_config* pConfig, ma_decoder* pDecoder)
+{
+ return ma_decoder_init_from_file__internal(&g_ma_decoding_backend_vtable_flac, NULL, pFilePath, pConfig, pDecoder);
+}
+
+static ma_result ma_decoder_init_flac_from_file_w__internal(const wchar_t* pFilePath, const ma_decoder_config* pConfig, ma_decoder* pDecoder)
+{
+ return ma_decoder_init_from_file_w__internal(&g_ma_decoding_backend_vtable_flac, NULL, pFilePath, pConfig, pDecoder);
+}
+
+static ma_result ma_decoder_init_flac_from_memory__internal(const void* pData, size_t dataSize, const ma_decoder_config* pConfig, ma_decoder* pDecoder)
+{
+ return ma_decoder_init_from_memory__internal(&g_ma_decoding_backend_vtable_flac, NULL, pData, dataSize, pConfig, pDecoder);
}
-#endif /* dr_flac_h */
+#endif /* ma_dr_flac_h */
/* MP3 */
-#ifdef dr_mp3_h
+#ifdef ma_dr_mp3_h
#define MA_HAS_MP3
typedef struct
@@ -60539,9 +62332,9 @@ typedef struct
void* pReadSeekTellUserData;
ma_format format; /* Can be f32 or s16. */
#if !defined(MA_NO_MP3)
- drmp3 dr;
- drmp3_uint32 seekPointCount;
- drmp3_seek_point* pSeekPoints; /* Only used if seek table generation is used. */
+ ma_dr_mp3 dr;
+ ma_uint32 seekPointCount;
+ ma_dr_mp3_seek_point* pSeekPoints; /* Only used if seek table generation is used. */
#endif
} ma_mp3;
@@ -60595,25 +62388,6 @@ static ma_data_source_vtable g_ma_mp3_ds_vtable =
#if !defined(MA_NO_MP3)
-static drmp3_allocation_callbacks drmp3_allocation_callbacks_from_miniaudio(const ma_allocation_callbacks* pAllocationCallbacks)
-{
- drmp3_allocation_callbacks callbacks;
-
- if (pAllocationCallbacks != NULL) {
- callbacks.onMalloc = pAllocationCallbacks->onMalloc;
- callbacks.onRealloc = pAllocationCallbacks->onRealloc;
- callbacks.onFree = pAllocationCallbacks->onFree;
- callbacks.pUserData = pAllocationCallbacks->pUserData;
- } else {
- callbacks.onMalloc = ma__malloc_default;
- callbacks.onRealloc = ma__realloc_default;
- callbacks.onFree = ma__free_default;
- callbacks.pUserData = NULL;
- }
-
- return callbacks;
-}
-
static size_t ma_mp3_dr_callback__read(void* pUserData, void* pBufferOut, size_t bytesToRead)
{
ma_mp3* pMP3 = (ma_mp3*)pUserData;
@@ -60628,7 +62402,7 @@ static size_t ma_mp3_dr_callback__read(void* pUserData, void* pBufferOut, size_t
return bytesRead;
}
-static drmp3_bool32 ma_mp3_dr_callback__seek(void* pUserData, int offset, drmp3_seek_origin origin)
+static ma_bool32 ma_mp3_dr_callback__seek(void* pUserData, int offset, ma_dr_mp3_seek_origin origin)
{
ma_mp3* pMP3 = (ma_mp3*)pUserData;
ma_result result;
@@ -60637,7 +62411,7 @@ static drmp3_bool32 ma_mp3_dr_callback__seek(void* pUserData, int offset, drmp3_
MA_ASSERT(pMP3 != NULL);
maSeekOrigin = ma_seek_origin_start;
- if (origin == drmp3_seek_origin_current) {
+ if (origin == ma_dr_mp3_seek_origin_current) {
maSeekOrigin = ma_seek_origin_current;
}
@@ -60681,28 +62455,28 @@ static ma_result ma_mp3_init_internal(const ma_decoding_backend_config* pConfig,
static ma_result ma_mp3_generate_seek_table(ma_mp3* pMP3, const ma_decoding_backend_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drmp3_bool32 mp3Result;
- drmp3_uint32 seekPointCount = 0;
- drmp3_seek_point* pSeekPoints = NULL;
+ ma_bool32 mp3Result;
+ ma_uint32 seekPointCount = 0;
+ ma_dr_mp3_seek_point* pSeekPoints = NULL;
MA_ASSERT(pMP3 != NULL);
MA_ASSERT(pConfig != NULL);
seekPointCount = pConfig->seekPointCount;
if (seekPointCount > 0) {
- pSeekPoints = (drmp3_seek_point*)ma_malloc(sizeof(*pMP3->pSeekPoints) * seekPointCount, pAllocationCallbacks);
+ pSeekPoints = (ma_dr_mp3_seek_point*)ma_malloc(sizeof(*pMP3->pSeekPoints) * seekPointCount, pAllocationCallbacks);
if (pSeekPoints == NULL) {
return MA_OUT_OF_MEMORY;
}
}
- mp3Result = drmp3_calculate_seek_points(&pMP3->dr, &seekPointCount, pSeekPoints);
+ mp3Result = ma_dr_mp3_calculate_seek_points(&pMP3->dr, &seekPointCount, pSeekPoints);
if (mp3Result != MA_TRUE) {
ma_free(pSeekPoints, pAllocationCallbacks);
return MA_ERROR;
}
- mp3Result = drmp3_bind_seek_table(&pMP3->dr, seekPointCount, pSeekPoints);
+ mp3Result = ma_dr_mp3_bind_seek_table(&pMP3->dr, seekPointCount, pSeekPoints);
if (mp3Result != MA_TRUE) {
ma_free(pSeekPoints, pAllocationCallbacks);
return MA_ERROR;
@@ -60714,6 +62488,18 @@ static ma_result ma_mp3_generate_seek_table(ma_mp3* pMP3, const ma_decoding_back
return MA_SUCCESS;
}
+static ma_result ma_mp3_post_init(ma_mp3* pMP3, const ma_decoding_backend_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks)
+{
+ ma_result result;
+
+ result = ma_mp3_generate_seek_table(pMP3, pConfig, pAllocationCallbacks);
+ if (result != MA_SUCCESS) {
+ return result;
+ }
+
+ return MA_SUCCESS;
+}
+
MA_API ma_result ma_mp3_init(ma_read_proc onRead, ma_seek_proc onSeek, ma_tell_proc onTell, void* pReadSeekTellUserData, const ma_decoding_backend_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_mp3* pMP3)
{
ma_result result;
@@ -60734,15 +62520,14 @@ MA_API ma_result ma_mp3_init(ma_read_proc onRead, ma_seek_proc onSeek, ma_tell_p
#if !defined(MA_NO_MP3)
{
- drmp3_allocation_callbacks mp3AllocationCallbacks = drmp3_allocation_callbacks_from_miniaudio(pAllocationCallbacks);
- drmp3_bool32 mp3Result;
+ ma_bool32 mp3Result;
- mp3Result = drmp3_init(&pMP3->dr, ma_mp3_dr_callback__read, ma_mp3_dr_callback__seek, pMP3, &mp3AllocationCallbacks);
+ mp3Result = ma_dr_mp3_init(&pMP3->dr, ma_mp3_dr_callback__read, ma_mp3_dr_callback__seek, pMP3, pAllocationCallbacks);
if (mp3Result != MA_TRUE) {
return MA_INVALID_FILE;
}
- ma_mp3_generate_seek_table(pMP3, pConfig, pAllocationCallbacks);
+ ma_mp3_post_init(pMP3, pConfig, pAllocationCallbacks);
return MA_SUCCESS;
}
@@ -60766,15 +62551,14 @@ MA_API ma_result ma_mp3_init_file(const char* pFilePath, const ma_decoding_backe
#if !defined(MA_NO_MP3)
{
- drmp3_allocation_callbacks mp3AllocationCallbacks = drmp3_allocation_callbacks_from_miniaudio(pAllocationCallbacks);
- drmp3_bool32 mp3Result;
+ ma_bool32 mp3Result;
- mp3Result = drmp3_init_file(&pMP3->dr, pFilePath, &mp3AllocationCallbacks);
+ mp3Result = ma_dr_mp3_init_file(&pMP3->dr, pFilePath, pAllocationCallbacks);
if (mp3Result != MA_TRUE) {
return MA_INVALID_FILE;
}
- ma_mp3_generate_seek_table(pMP3, pConfig, pAllocationCallbacks);
+ ma_mp3_post_init(pMP3, pConfig, pAllocationCallbacks);
return MA_SUCCESS;
}
@@ -60799,15 +62583,14 @@ MA_API ma_result ma_mp3_init_file_w(const wchar_t* pFilePath, const ma_decoding_
#if !defined(MA_NO_MP3)
{
- drmp3_allocation_callbacks mp3AllocationCallbacks = drmp3_allocation_callbacks_from_miniaudio(pAllocationCallbacks);
- drmp3_bool32 mp3Result;
+ ma_bool32 mp3Result;
- mp3Result = drmp3_init_file_w(&pMP3->dr, pFilePath, &mp3AllocationCallbacks);
+ mp3Result = ma_dr_mp3_init_file_w(&pMP3->dr, pFilePath, pAllocationCallbacks);
if (mp3Result != MA_TRUE) {
return MA_INVALID_FILE;
}
- ma_mp3_generate_seek_table(pMP3, pConfig, pAllocationCallbacks);
+ ma_mp3_post_init(pMP3, pConfig, pAllocationCallbacks);
return MA_SUCCESS;
}
@@ -60832,15 +62615,14 @@ MA_API ma_result ma_mp3_init_memory(const void* pData, size_t dataSize, const ma
#if !defined(MA_NO_MP3)
{
- drmp3_allocation_callbacks mp3AllocationCallbacks = drmp3_allocation_callbacks_from_miniaudio(pAllocationCallbacks);
- drmp3_bool32 mp3Result;
+ ma_bool32 mp3Result;
- mp3Result = drmp3_init_memory(&pMP3->dr, pData, dataSize, &mp3AllocationCallbacks);
+ mp3Result = ma_dr_mp3_init_memory(&pMP3->dr, pData, dataSize, pAllocationCallbacks);
if (mp3Result != MA_TRUE) {
return MA_INVALID_FILE;
}
- ma_mp3_generate_seek_table(pMP3, pConfig, pAllocationCallbacks);
+ ma_mp3_post_init(pMP3, pConfig, pAllocationCallbacks);
return MA_SUCCESS;
}
@@ -60863,7 +62645,7 @@ MA_API void ma_mp3_uninit(ma_mp3* pMP3, const ma_allocation_callbacks* pAllocati
#if !defined(MA_NO_MP3)
{
- drmp3_uninit(&pMP3->dr);
+ ma_dr_mp3_uninit(&pMP3->dr);
}
#else
{
@@ -60905,12 +62687,12 @@ MA_API ma_result ma_mp3_read_pcm_frames(ma_mp3* pMP3, void* pFramesOut, ma_uint6
{
case ma_format_f32:
{
- totalFramesRead = drmp3_read_pcm_frames_f32(&pMP3->dr, frameCount, (float*)pFramesOut);
+ totalFramesRead = ma_dr_mp3_read_pcm_frames_f32(&pMP3->dr, frameCount, (float*)pFramesOut);
} break;
case ma_format_s16:
{
- totalFramesRead = drmp3_read_pcm_frames_s16(&pMP3->dr, frameCount, (drmp3_int16*)pFramesOut);
+ totalFramesRead = ma_dr_mp3_read_pcm_frames_s16(&pMP3->dr, frameCount, (ma_int16*)pFramesOut);
} break;
case ma_format_u8:
@@ -60923,7 +62705,7 @@ MA_API ma_result ma_mp3_read_pcm_frames(ma_mp3* pMP3, void* pFramesOut, ma_uint6
};
}
- /* In the future we'll update dr_mp3 to return MA_AT_END for us. */
+ /* In the future we'll update ma_dr_mp3 to return MA_AT_END for us. */
if (totalFramesRead == 0) {
result = MA_AT_END;
}
@@ -60956,10 +62738,10 @@ MA_API ma_result ma_mp3_seek_to_pcm_frame(ma_mp3* pMP3, ma_uint64 frameIndex)
#if !defined(MA_NO_MP3)
{
- drmp3_bool32 mp3Result;
+ ma_bool32 mp3Result;
- mp3Result = drmp3_seek_to_pcm_frame(&pMP3->dr, frameIndex);
- if (mp3Result != DRMP3_TRUE) {
+ mp3Result = ma_dr_mp3_seek_to_pcm_frame(&pMP3->dr, frameIndex);
+ if (mp3Result != MA_TRUE) {
return MA_ERROR;
}
@@ -61067,7 +62849,7 @@ MA_API ma_result ma_mp3_get_length_in_pcm_frames(ma_mp3* pMP3, ma_uint64* pLengt
#if !defined(MA_NO_MP3)
{
- *pLength = drmp3_get_pcm_frame_count(&pMP3->dr);
+ *pLength = ma_dr_mp3_get_pcm_frame_count(&pMP3->dr);
return MA_SUCCESS;
}
@@ -61198,9 +62980,24 @@ static ma_decoding_backend_vtable g_ma_decoding_backend_vtable_mp3 =
static ma_result ma_decoder_init_mp3__internal(const ma_decoder_config* pConfig, ma_decoder* pDecoder)
{
- return ma_decoder_init_from_vtable(&g_ma_decoding_backend_vtable_mp3, NULL, pConfig, pDecoder);
+ return ma_decoder_init_from_vtable__internal(&g_ma_decoding_backend_vtable_mp3, NULL, pConfig, pDecoder);
+}
+
+static ma_result ma_decoder_init_mp3_from_file__internal(const char* pFilePath, const ma_decoder_config* pConfig, ma_decoder* pDecoder)
+{
+ return ma_decoder_init_from_file__internal(&g_ma_decoding_backend_vtable_mp3, NULL, pFilePath, pConfig, pDecoder);
+}
+
+static ma_result ma_decoder_init_mp3_from_file_w__internal(const wchar_t* pFilePath, const ma_decoder_config* pConfig, ma_decoder* pDecoder)
+{
+ return ma_decoder_init_from_file_w__internal(&g_ma_decoding_backend_vtable_mp3, NULL, pFilePath, pConfig, pDecoder);
+}
+
+static ma_result ma_decoder_init_mp3_from_memory__internal(const void* pData, size_t dataSize, const ma_decoder_config* pConfig, ma_decoder* pDecoder)
+{
+ return ma_decoder_init_from_memory__internal(&g_ma_decoding_backend_vtable_mp3, NULL, pData, dataSize, pConfig, pDecoder);
}
-#endif /* dr_mp3_h */
+#endif /* ma_dr_mp3_h */
/* Vorbis */
#ifdef STB_VORBIS_INCLUDE_STB_VORBIS_H
@@ -61229,6 +63026,7 @@ typedef struct
ma_uint8* pData;
size_t dataSize;
size_t dataCapacity;
+ size_t audioStartOffsetInBytes;
ma_uint32 framesConsumed; /* The number of frames consumed in ppPacketData. */
ma_uint32 framesRemaining; /* The number of frames remaining in ppPacketData. */
float** ppPacketData;
@@ -61323,6 +63121,81 @@ static ma_result ma_stbvorbis_post_init(ma_stbvorbis* pVorbis)
return MA_SUCCESS;
}
+
+static ma_result ma_stbvorbis_init_internal_decoder_push(ma_stbvorbis* pVorbis)
+{
+ ma_result result;
+ stb_vorbis* stb;
+ size_t dataSize = 0;
+ size_t dataCapacity = 0;
+ ma_uint8* pData = NULL; /* <-- Must be initialized to NULL. */
+
+ for (;;) {
+ int vorbisError;
+ int consumedDataSize; /* <-- Fill by stb_vorbis_open_pushdata(). */
+ size_t bytesRead;
+ ma_uint8* pNewData;
+
+ /* Allocate memory for the new chunk. */
+ dataCapacity += MA_VORBIS_DATA_CHUNK_SIZE;
+ pNewData = (ma_uint8*)ma_realloc(pData, dataCapacity, &pVorbis->allocationCallbacks);
+ if (pNewData == NULL) {
+ ma_free(pData, &pVorbis->allocationCallbacks);
+ return MA_OUT_OF_MEMORY;
+ }
+
+ pData = pNewData;
+
+ /* Read in the next chunk. */
+ result = pVorbis->onRead(pVorbis->pReadSeekTellUserData, ma_offset_ptr(pData, dataSize), (dataCapacity - dataSize), &bytesRead);
+ dataSize += bytesRead;
+
+ if (result != MA_SUCCESS) {
+ ma_free(pData, &pVorbis->allocationCallbacks);
+ return result;
+ }
+
+ /* We have a maximum of 31 bits with stb_vorbis. */
+ if (dataSize > INT_MAX) {
+ ma_free(pData, &pVorbis->allocationCallbacks);
+ return MA_TOO_BIG;
+ }
+
+ stb = stb_vorbis_open_pushdata(pData, (int)dataSize, &consumedDataSize, &vorbisError, NULL);
+ if (stb != NULL) {
+ /*
+ Successfully opened the Vorbis decoder. We might have some leftover unprocessed
+ data so we'll need to move that down to the front.
+ */
+ dataSize -= (size_t)consumedDataSize; /* Consume the data. */
+ MA_MOVE_MEMORY(pData, ma_offset_ptr(pData, consumedDataSize), dataSize);
+
+ /*
+ We need to track the start point so we can seek back to the start of the audio
+ data when seeking.
+ */
+ pVorbis->push.audioStartOffsetInBytes = consumedDataSize;
+
+ break;
+ } else {
+ /* Failed to open the decoder. */
+ if (vorbisError == VORBIS_need_more_data) {
+ continue;
+ } else {
+ ma_free(pData, &pVorbis->allocationCallbacks);
+ return MA_ERROR; /* Failed to open the stb_vorbis decoder. */
+ }
+ }
+ }
+
+ MA_ASSERT(stb != NULL);
+ pVorbis->stb = stb;
+ pVorbis->push.pData = pData;
+ pVorbis->push.dataSize = dataSize;
+ pVorbis->push.dataCapacity = dataCapacity;
+
+ return MA_SUCCESS;
+}
#endif
MA_API ma_result ma_stbvorbis_init(ma_read_proc onRead, ma_seek_proc onSeek, ma_tell_proc onTell, void* pReadSeekTellUserData, const ma_decoding_backend_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_stbvorbis* pVorbis)
@@ -61351,74 +63224,17 @@ MA_API ma_result ma_stbvorbis_init(ma_read_proc onRead, ma_seek_proc onSeek, ma_
pushing API. In order for us to be able to successfully initialize the decoder we need to
supply it with enough data. We need to keep loading data until we have enough.
*/
- stb_vorbis* stb;
- size_t dataSize = 0;
- size_t dataCapacity = 0;
- ma_uint8* pData = NULL; /* <-- Must be initialized to NULL. */
-
- for (;;) {
- int vorbisError;
- int consumedDataSize; /* <-- Fill by stb_vorbis_open_pushdata(). */
- size_t bytesRead;
- ma_uint8* pNewData;
-
- /* Allocate memory for the new chunk. */
- dataCapacity += MA_VORBIS_DATA_CHUNK_SIZE;
- pNewData = (ma_uint8*)ma_realloc(pData, dataCapacity, pAllocationCallbacks);
- if (pNewData == NULL) {
- ma_free(pData, pAllocationCallbacks);
- return MA_OUT_OF_MEMORY;
- }
-
- pData = pNewData;
-
- /* Read in the next chunk. */
- result = pVorbis->onRead(pVorbis->pReadSeekTellUserData, ma_offset_ptr(pData, dataSize), (dataCapacity - dataSize), &bytesRead);
- dataSize += bytesRead;
-
- if (result != MA_SUCCESS) {
- ma_free(pData, pAllocationCallbacks);
- return result;
- }
-
- /* We have a maximum of 31 bits with stb_vorbis. */
- if (dataSize > INT_MAX) {
- ma_free(pData, pAllocationCallbacks);
- return MA_TOO_BIG;
- }
-
- stb = stb_vorbis_open_pushdata(pData, (int)dataSize, &consumedDataSize, &vorbisError, NULL);
- if (stb != NULL) {
- /*
- Successfully opened the Vorbis decoder. We might have some leftover unprocessed
- data so we'll need to move that down to the front.
- */
- dataSize -= (size_t)consumedDataSize; /* Consume the data. */
- MA_MOVE_MEMORY(pData, ma_offset_ptr(pData, consumedDataSize), dataSize);
- break;
- } else {
- /* Failed to open the decoder. */
- if (vorbisError == VORBIS_need_more_data) {
- continue;
- } else {
- ma_free(pData, pAllocationCallbacks);
- return MA_ERROR; /* Failed to open the stb_vorbis decoder. */
- }
- }
+ result = ma_stbvorbis_init_internal_decoder_push(pVorbis);
+ if (result != MA_SUCCESS) {
+ return result;
}
- MA_ASSERT(stb != NULL);
- pVorbis->stb = stb;
- pVorbis->push.pData = pData;
- pVorbis->push.dataSize = dataSize;
- pVorbis->push.dataCapacity = dataCapacity;
-
pVorbis->usingPushMode = MA_TRUE;
result = ma_stbvorbis_post_init(pVorbis);
if (result != MA_SUCCESS) {
stb_vorbis_close(pVorbis->stb);
- ma_free(pData, pAllocationCallbacks);
+ ma_free(pVorbis->push.pData, pAllocationCallbacks);
return result;
}
@@ -61720,27 +63536,39 @@ MA_API ma_result ma_stbvorbis_seek_to_pcm_frame(ma_stbvorbis* pVorbis, ma_uint64
ma_result result;
float buffer[4096];
- /*
- This is terribly inefficient because stb_vorbis does not have a good seeking solution with it's push API. Currently this just performs
- a full decode right from the start of the stream. Later on I'll need to write a layer that goes through all of the Ogg pages until we
- find the one containing the sample we need. Then we know exactly where to seek for stb_vorbis.
+ /* If we're seeking backwards, we need to seek back to the start and then brute-force forward. */
+ if (frameIndex < pVorbis->cursor) {
+ if (frameIndex > 0x7FFFFFFF) {
+ return MA_INVALID_ARGS; /* Trying to seek beyond the 32-bit maximum of stb_vorbis. */
+ }
- TODO: Use seeking logic documented for stb_vorbis_flush_pushdata().
- */
+ /*
+ This is wildly inefficient due to me having trouble getting sample exact seeking working
+ robustly with stb_vorbis_flush_pushdata(). The only way I can think to make this work
+ perfectly is to reinitialize the decoder. Note that we only enter this path when seeking
+ backwards. This will hopefully be removed once we get our own Vorbis decoder implemented.
+ */
+ stb_vorbis_close(pVorbis->stb);
+ ma_free(pVorbis->push.pData, &pVorbis->allocationCallbacks);
- /* Seek to the start of the file to begin with. */
- result = pVorbis->onSeek(pVorbis->pReadSeekTellUserData, 0, ma_seek_origin_start);
- if (result != MA_SUCCESS) {
- return result;
- }
+ MA_ZERO_OBJECT(&pVorbis->push);
- stb_vorbis_flush_pushdata(pVorbis->stb);
- pVorbis->push.framesRemaining = 0;
- pVorbis->push.dataSize = 0;
+ /* Seek to the start of the file. */
+ result = pVorbis->onSeek(pVorbis->pReadSeekTellUserData, 0, ma_seek_origin_start);
+ if (result != MA_SUCCESS) {
+ return result;
+ }
- /* Move the cursor back to the start. We'll increment this in the loop below. */
- pVorbis->cursor = 0;
+ result = ma_stbvorbis_init_internal_decoder_push(pVorbis);
+ if (result != MA_SUCCESS) {
+ return result;
+ }
+
+ /* At this point we should be sitting on the first frame. */
+ pVorbis->cursor = 0;
+ }
+ /* We're just brute-forcing this for now. */
while (pVorbis->cursor < frameIndex) {
ma_uint64 framesRead;
ma_uint64 framesToRead = ma_countof(buffer)/pVorbis->channels;
@@ -61749,8 +63577,6 @@ MA_API ma_result ma_stbvorbis_seek_to_pcm_frame(ma_stbvorbis* pVorbis, ma_uint64
}
result = ma_stbvorbis_read_pcm_frames(pVorbis, buffer, framesToRead, &framesRead);
- pVorbis->cursor += framesRead;
-
if (result != MA_SUCCESS) {
return result;
}
@@ -61986,7 +63812,22 @@ static ma_decoding_backend_vtable g_ma_decoding_backend_vtable_stbvorbis =
static ma_result ma_decoder_init_vorbis__internal(const ma_decoder_config* pConfig, ma_decoder* pDecoder)
{
- return ma_decoder_init_from_vtable(&g_ma_decoding_backend_vtable_stbvorbis, NULL, pConfig, pDecoder);
+ return ma_decoder_init_from_vtable__internal(&g_ma_decoding_backend_vtable_stbvorbis, NULL, pConfig, pDecoder);
+}
+
+static ma_result ma_decoder_init_vorbis_from_file__internal(const char* pFilePath, const ma_decoder_config* pConfig, ma_decoder* pDecoder)
+{
+ return ma_decoder_init_from_file__internal(&g_ma_decoding_backend_vtable_stbvorbis, NULL, pFilePath, pConfig, pDecoder);
+}
+
+static ma_result ma_decoder_init_vorbis_from_file_w__internal(const wchar_t* pFilePath, const ma_decoder_config* pConfig, ma_decoder* pDecoder)
+{
+ return ma_decoder_init_from_file_w__internal(&g_ma_decoding_backend_vtable_stbvorbis, NULL, pFilePath, pConfig, pDecoder);
+}
+
+static ma_result ma_decoder_init_vorbis_from_memory__internal(const void* pData, size_t dataSize, const ma_decoder_config* pConfig, ma_decoder* pDecoder)
+{
+ return ma_decoder_init_from_memory__internal(&g_ma_decoding_backend_vtable_stbvorbis, NULL, pData, dataSize, pConfig, pDecoder);
}
#endif /* STB_VORBIS_INCLUDE_STB_VORBIS_H */
@@ -62053,10 +63894,6 @@ static ma_result ma_decoder__preinit(ma_decoder_read_proc onRead, ma_decoder_see
MA_ZERO_OBJECT(pDecoder);
- if (onRead == NULL || onSeek == NULL) {
- return MA_INVALID_ARGS;
- }
-
dataSourceConfig = ma_data_source_config_init();
dataSourceConfig.vtable = &g_ma_decoder_data_source_vtable;
@@ -62300,7 +64137,7 @@ static ma_result ma_decoder__on_tell_memory(ma_decoder* pDecoder, ma_int64* pCur
return MA_SUCCESS;
}
-static ma_result ma_decoder__preinit_memory(const void* pData, size_t dataSize, const ma_decoder_config* pConfig, ma_decoder* pDecoder)
+static ma_result ma_decoder__preinit_memory_wrapper(const void* pData, size_t dataSize, const ma_decoder_config* pConfig, ma_decoder* pDecoder)
{
ma_result result = ma_decoder__preinit(ma_decoder__on_read_memory, ma_decoder__on_seek_memory, ma_decoder__on_tell_memory, NULL, pConfig, pDecoder);
if (result != MA_SUCCESS) {
@@ -62321,17 +64158,121 @@ static ma_result ma_decoder__preinit_memory(const void* pData, size_t dataSize,
MA_API ma_result ma_decoder_init_memory(const void* pData, size_t dataSize, const ma_decoder_config* pConfig, ma_decoder* pDecoder)
{
- ma_decoder_config config;
ma_result result;
+ ma_decoder_config config;
- config = ma_decoder_config_init_copy(pConfig); /* Make sure the config is not NULL. */
+ config = ma_decoder_config_init_copy(pConfig);
- result = ma_decoder__preinit_memory(pData, dataSize, &config, pDecoder);
+ result = ma_decoder__preinit(NULL, NULL, NULL, NULL, &config, pDecoder);
if (result != MA_SUCCESS) {
return result;
}
- return ma_decoder_init__internal(ma_decoder__on_read_memory, ma_decoder__on_seek_memory, NULL, &config, pDecoder);
+ if (pData == NULL || dataSize == 0) {
+ return MA_INVALID_ARGS;
+ }
+
+ /* If the backend has support for loading from a file path we'll want to use that. If that all fails we'll fall back to the VFS path. */
+ result = MA_NO_BACKEND;
+
+ if (config.encodingFormat != ma_encoding_format_unknown) {
+ #ifdef MA_HAS_WAV
+ if (config.encodingFormat == ma_encoding_format_wav) {
+ result = ma_decoder_init_wav_from_memory__internal(pData, dataSize, &config, pDecoder);
+ }
+ #endif
+ #ifdef MA_HAS_FLAC
+ if (config.encodingFormat == ma_encoding_format_flac) {
+ result = ma_decoder_init_flac_from_memory__internal(pData, dataSize, &config, pDecoder);
+ }
+ #endif
+ #ifdef MA_HAS_MP3
+ if (config.encodingFormat == ma_encoding_format_mp3) {
+ result = ma_decoder_init_mp3_from_memory__internal(pData, dataSize, &config, pDecoder);
+ }
+ #endif
+ #ifdef MA_HAS_VORBIS
+ if (config.encodingFormat == ma_encoding_format_vorbis) {
+ result = ma_decoder_init_vorbis_from_memory__internal(pData, dataSize, &config, pDecoder);
+ }
+ #endif
+ }
+
+ if (result != MA_SUCCESS) {
+ /* Getting here means we weren't able to initialize a decoder of a specific encoding format. */
+
+ /*
+ We use trial and error to open a decoder. We prioritize custom decoders so that if they
+ implement the same encoding format they take priority over the built-in decoders.
+ */
+ result = ma_decoder_init_custom_from_memory__internal(pData, dataSize, &config, pDecoder);
+
+ /*
+ If we get to this point and we still haven't found a decoder, and the caller has requested a
+ specific encoding format, there's no hope for it. Abort.
+ */
+ if (result != MA_SUCCESS && config.encodingFormat != ma_encoding_format_unknown) {
+ return MA_NO_BACKEND;
+ }
+
+ /* Use trial and error for stock decoders. */
+ if (result != MA_SUCCESS) {
+ #ifdef MA_HAS_WAV
+ if (result != MA_SUCCESS) {
+ result = ma_decoder_init_wav_from_memory__internal(pData, dataSize, &config, pDecoder);
+ }
+ #endif
+ #ifdef MA_HAS_FLAC
+ if (result != MA_SUCCESS) {
+ result = ma_decoder_init_flac_from_memory__internal(pData, dataSize, &config, pDecoder);
+ }
+ #endif
+ #ifdef MA_HAS_MP3
+ if (result != MA_SUCCESS) {
+ result = ma_decoder_init_mp3_from_memory__internal(pData, dataSize, &config, pDecoder);
+ }
+ #endif
+ #ifdef MA_HAS_VORBIS
+ if (result != MA_SUCCESS) {
+ result = ma_decoder_init_vorbis_from_memory__internal(pData, dataSize, &config, pDecoder);
+ }
+ #endif
+ }
+ }
+
+ /*
+ If at this point we still haven't successfully initialized the decoder it most likely means
+ the backend doesn't have an implementation for loading from a file path. We'll try using
+ miniaudio's built-in file IO for loading file.
+ */
+ if (result == MA_SUCCESS) {
+ /* Initialization was successful. Finish up. */
+ result = ma_decoder__postinit(&config, pDecoder);
+ if (result != MA_SUCCESS) {
+ /*
+ The backend was initialized successfully, but for some reason post-initialization failed. This is most likely
+ due to an out of memory error. We're going to abort with an error here and not try to recover.
+ */
+ if (pDecoder->pBackendVTable != NULL && pDecoder->pBackendVTable->onUninit != NULL) {
+ pDecoder->pBackendVTable->onUninit(pDecoder->pBackendUserData, &pDecoder->pBackend, &pDecoder->allocationCallbacks);
+ }
+
+ return result;
+ }
+ } else {
+ /* Probably no implementation for loading from a block of memory. Use miniaudio's abstraction instead. */
+ result = ma_decoder__preinit_memory_wrapper(pData, dataSize, &config, pDecoder);
+ if (result != MA_SUCCESS) {
+ return result;
+ }
+
+ result = ma_decoder_init__internal(ma_decoder__on_read_memory, ma_decoder__on_seek_memory, NULL, &config, pDecoder);
+ if (result != MA_SUCCESS) {
+ return result;
+ }
+ }
+
+ return MA_SUCCESS;
}
@@ -62798,14 +64739,305 @@ MA_API ma_result ma_decoder_init_vfs_w(ma_vfs* pVFS, const wchar_t* pFilePath, c
return MA_SUCCESS;
}
+
+static ma_result ma_decoder__preinit_file(const char* pFilePath, const ma_decoder_config* pConfig, ma_decoder* pDecoder)
+{
+ ma_result result;
+
+ result = ma_decoder__preinit(NULL, NULL, NULL, NULL, pConfig, pDecoder);
+ if (result != MA_SUCCESS) {
+ return result;
+ }
+
+ if (pFilePath == NULL || pFilePath[0] == '\0') {
+ return MA_INVALID_ARGS;
+ }
+
+ return MA_SUCCESS;
+}
+
MA_API ma_result ma_decoder_init_file(const char* pFilePath, const ma_decoder_config* pConfig, ma_decoder* pDecoder)
{
- return ma_decoder_init_vfs(NULL, pFilePath, pConfig, pDecoder);
+ ma_result result;
+ ma_decoder_config config;
+
+ config = ma_decoder_config_init_copy(pConfig);
+ result = ma_decoder__preinit_file(pFilePath, &config, pDecoder);
+ if (result != MA_SUCCESS) {
+ return result;
+ }
+
+ /* If the backend has support for loading from a file path we'll want to use that. If that all fails we'll fall back to the VFS path. */
+ result = MA_NO_BACKEND;
+
+ if (config.encodingFormat != ma_encoding_format_unknown) {
+ #ifdef MA_HAS_WAV
+ if (config.encodingFormat == ma_encoding_format_wav) {
+ result = ma_decoder_init_wav_from_file__internal(pFilePath, &config, pDecoder);
+ }
+ #endif
+ #ifdef MA_HAS_FLAC
+ if (config.encodingFormat == ma_encoding_format_flac) {
+ result = ma_decoder_init_flac_from_file__internal(pFilePath, &config, pDecoder);
+ }
+ #endif
+ #ifdef MA_HAS_MP3
+ if (config.encodingFormat == ma_encoding_format_mp3) {
+ result = ma_decoder_init_mp3_from_file__internal(pFilePath, &config, pDecoder);
+ }
+ #endif
+ #ifdef MA_HAS_VORBIS
+ if (config.encodingFormat == ma_encoding_format_vorbis) {
+ result = ma_decoder_init_vorbis_from_file__internal(pFilePath, &config, pDecoder);
+ }
+ #endif
+ }
+
+ if (result != MA_SUCCESS) {
+ /* Getting here means we weren't able to initialize a decoder of a specific encoding format. */
+
+ /*
+ We use trial and error to open a decoder. We prioritize custom decoders so that if they
+ implement the same encoding format they take priority over the built-in decoders.
+ */
+ result = ma_decoder_init_custom_from_file__internal(pFilePath, &config, pDecoder);
+
+ /*
+ If we get to this point and we still haven't found a decoder, and the caller has requested a
+ specific encoding format, there's no hope for it. Abort.
+ */
+ if (result != MA_SUCCESS && config.encodingFormat != ma_encoding_format_unknown) {
+ return MA_NO_BACKEND;
+ }
+
+ /* First try loading based on the file extension so we don't waste time opening and closing files. */
+ #ifdef MA_HAS_WAV
+ if (result != MA_SUCCESS && ma_path_extension_equal(pFilePath, "wav")) {
+ result = ma_decoder_init_wav_from_file__internal(pFilePath, &config, pDecoder);
+ }
+ #endif
+ #ifdef MA_HAS_FLAC
+ if (result != MA_SUCCESS && ma_path_extension_equal(pFilePath, "flac")) {
+ result = ma_decoder_init_flac_from_file__internal(pFilePath, &config, pDecoder);
+ }
+ #endif
+ #ifdef MA_HAS_MP3
+ if (result != MA_SUCCESS && ma_path_extension_equal(pFilePath, "mp3")) {
+ result = ma_decoder_init_mp3_from_file__internal(pFilePath, &config, pDecoder);
+ }
+ #endif
+ #ifdef MA_HAS_VORBIS
+ if (result != MA_SUCCESS && ma_path_extension_equal(pFilePath, "ogg")) {
+ result = ma_decoder_init_vorbis_from_file__internal(pFilePath, &config, pDecoder);
+ }
+ #endif
+
+ /*
+ If we still haven't got a result just use trial and error. Custom decoders have already been attempted, so here we
+ need only iterate over our stock decoders.
+ */
+ if (result != MA_SUCCESS) {
+ #ifdef MA_HAS_WAV
+ if (result != MA_SUCCESS) {
+ result = ma_decoder_init_wav_from_file__internal(pFilePath, &config, pDecoder);
+ }
+ #endif
+ #ifdef MA_HAS_FLAC
+ if (result != MA_SUCCESS) {
+ result = ma_decoder_init_flac_from_file__internal(pFilePath, &config, pDecoder);
+ }
+ #endif
+ #ifdef MA_HAS_MP3
+ if (result != MA_SUCCESS) {
+ result = ma_decoder_init_mp3_from_file__internal(pFilePath, &config, pDecoder);
+ }
+ #endif
+ #ifdef MA_HAS_VORBIS
+ if (result != MA_SUCCESS) {
+ result = ma_decoder_init_vorbis_from_file__internal(pFilePath, &config, pDecoder);
+ }
+ #endif
+ }
+ }
+
+ /*
+ If at this point we still haven't successfully initialized the decoder it most likely means
+ the backend doesn't have an implementation for loading from a file path. We'll try using
+ miniaudio's built-in file IO for loading file.
+ */
+ if (result == MA_SUCCESS) {
+ /* Initialization was successful. Finish up. */
+ result = ma_decoder__postinit(&config, pDecoder);
+ if (result != MA_SUCCESS) {
+ /*
+ The backend was initialized successfully, but for some reason post-initialization failed. This is most likely
+ due to an out of memory error. We're going to abort with an error here and not try to recover.
+ */
+ if (pDecoder->pBackendVTable != NULL && pDecoder->pBackendVTable->onUninit != NULL) {
+ pDecoder->pBackendVTable->onUninit(pDecoder->pBackendUserData, &pDecoder->pBackend, &pDecoder->allocationCallbacks);
+ }
+
+ return result;
+ }
+ } else {
+ /* Probably no implementation for loading from a file path. Use miniaudio's file IO instead. */
+ result = ma_decoder_init_vfs(NULL, pFilePath, pConfig, pDecoder);
+ if (result != MA_SUCCESS) {
+ return result;
+ }
+ }
+
+ return MA_SUCCESS;
+}
+
+static ma_result ma_decoder__preinit_file_w(const wchar_t* pFilePath, const ma_decoder_config* pConfig, ma_decoder* pDecoder)
+{
+ ma_result result;
+
+ result = ma_decoder__preinit(NULL, NULL, NULL, NULL, pConfig, pDecoder);
+ if (result != MA_SUCCESS) {
+ return result;
+ }
+
+ if (pFilePath == NULL || pFilePath[0] == '\0') {
+ return MA_INVALID_ARGS;
+ }
+
+ return MA_SUCCESS;
}
MA_API ma_result ma_decoder_init_file_w(const wchar_t* pFilePath, const ma_decoder_config* pConfig, ma_decoder* pDecoder)
{
- return ma_decoder_init_vfs_w(NULL, pFilePath, pConfig, pDecoder);
+ ma_result result;
+ ma_decoder_config config;
+
+ config = ma_decoder_config_init_copy(pConfig);
+ result = ma_decoder__preinit_file_w(pFilePath, &config, pDecoder);
+ if (result != MA_SUCCESS) {
+ return result;
+ }
+
+ /* If the backend has support for loading from a file path we'll want to use that. If that all fails we'll fall back to the VFS path. */
+ result = MA_NO_BACKEND;
+
+ if (config.encodingFormat != ma_encoding_format_unknown) {
+ #ifdef MA_HAS_WAV
+ if (config.encodingFormat == ma_encoding_format_wav) {
+ result = ma_decoder_init_wav_from_file_w__internal(pFilePath, &config, pDecoder);
+ }
+ #endif
+ #ifdef MA_HAS_FLAC
+ if (config.encodingFormat == ma_encoding_format_flac) {
+ result = ma_decoder_init_flac_from_file_w__internal(pFilePath, &config, pDecoder);
+ }
+ #endif
+ #ifdef MA_HAS_MP3
+ if (config.encodingFormat == ma_encoding_format_mp3) {
+ result = ma_decoder_init_mp3_from_file_w__internal(pFilePath, &config, pDecoder);
+ }
+ #endif
+ #ifdef MA_HAS_VORBIS
+ if (config.encodingFormat == ma_encoding_format_vorbis) {
+ result = ma_decoder_init_vorbis_from_file_w__internal(pFilePath, &config, pDecoder);
+ }
+ #endif
+ }
+
+ if (result != MA_SUCCESS) {
+ /* Getting here means we weren't able to initialize a decoder of a specific encoding format. */
+
+ /*
+ We use trial and error to open a decoder. We prioritize custom decoders so that if they
+ implement the same encoding format they take priority over the built-in decoders.
+ */
+ result = ma_decoder_init_custom_from_file_w__internal(pFilePath, &config, pDecoder);
+
+ /*
+ If we get to this point and we still haven't found a decoder, and the caller has requested a
+ specific encoding format, there's no hope for it. Abort.
+ */
+ if (result != MA_SUCCESS && config.encodingFormat != ma_encoding_format_unknown) {
+ return MA_NO_BACKEND;
+ }
+
+ /* First try loading based on the file extension so we don't waste time opening and closing files. */
+ #ifdef MA_HAS_WAV
+ if (result != MA_SUCCESS && ma_path_extension_equal_w(pFilePath, L"wav")) {
+ result = ma_decoder_init_wav_from_file_w__internal(pFilePath, &config, pDecoder);
+ }
+ #endif
+ #ifdef MA_HAS_FLAC
+ if (result != MA_SUCCESS && ma_path_extension_equal_w(pFilePath, L"flac")) {
+ result = ma_decoder_init_flac_from_file_w__internal(pFilePath, &config, pDecoder);
+ }
+ #endif
+ #ifdef MA_HAS_MP3
+ if (result != MA_SUCCESS && ma_path_extension_equal_w(pFilePath, L"mp3")) {
+ result = ma_decoder_init_mp3_from_file_w__internal(pFilePath, &config, pDecoder);
+ }
+ #endif
+ #ifdef MA_HAS_VORBIS
+ if (result != MA_SUCCESS && ma_path_extension_equal_w(pFilePath, L"ogg")) {
+ result = ma_decoder_init_vorbis_from_file_w__internal(pFilePath, &config, pDecoder);
+ }
+ #endif
+
+ /*
+ If we still haven't got a result just use trial and error. Custom decoders have already been attempted, so here we
+ need only iterate over our stock decoders.
+ */
+ if (result != MA_SUCCESS) {
+ #ifdef MA_HAS_WAV
+ if (result != MA_SUCCESS) {
+ result = ma_decoder_init_wav_from_file_w__internal(pFilePath, &config, pDecoder);
+ }
+ #endif
+ #ifdef MA_HAS_FLAC
+ if (result != MA_SUCCESS) {
+ result = ma_decoder_init_flac_from_file_w__internal(pFilePath, &config, pDecoder);
+ }
+ #endif
+ #ifdef MA_HAS_MP3
+ if (result != MA_SUCCESS) {
+ result = ma_decoder_init_mp3_from_file_w__internal(pFilePath, &config, pDecoder);
+ }
+ #endif
+ #ifdef MA_HAS_VORBIS
+ if (result != MA_SUCCESS) {
+ result = ma_decoder_init_vorbis_from_file_w__internal(pFilePath, &config, pDecoder);
+ }
+ #endif
+ }
+ }
+
+ /*
+ If at this point we still haven't successfully initialized the decoder it most likely means
+ the backend doesn't have an implementation for loading from a file path. We'll try using
+ miniaudio's built-in file IO for loading file.
+ */
+ if (result == MA_SUCCESS) {
+ /* Initialization was successful. Finish up. */
+ result = ma_decoder__postinit(&config, pDecoder);
+ if (result != MA_SUCCESS) {
+ /*
+ The backend was initialized successfully, but for some reason post-initialization failed. This is most likely
+ due to an out of memory error. We're going to abort with an error here and not try to recover.
+ */
+ if (pDecoder->pBackendVTable != NULL && pDecoder->pBackendVTable->onUninit != NULL) {
+ pDecoder->pBackendVTable->onUninit(pDecoder->pBackendUserData, &pDecoder->pBackend, &pDecoder->allocationCallbacks);
+ }
+
+ return result;
+ }
+ } else {
+ /* Probably no implementation for loading from a file path. Use miniaudio's file IO instead. */
+ result = ma_decoder_init_vfs_w(NULL, pFilePath, pConfig, pDecoder);
+ if (result != MA_SUCCESS) {
+ return result;
+ }
+ }
+
+ return MA_SUCCESS;
}
MA_API ma_result ma_decoder_uninit(ma_decoder* pDecoder)
@@ -63299,42 +65531,42 @@ static size_t ma_encoder__internal_on_write_wav(void* pUserData, const void* pDa
return bytesWritten;
}
-static drwav_bool32 ma_encoder__internal_on_seek_wav(void* pUserData, int offset, drwav_seek_origin origin)
+static ma_bool32 ma_encoder__internal_on_seek_wav(void* pUserData, int offset, ma_dr_wav_seek_origin origin)
{
ma_encoder* pEncoder = (ma_encoder*)pUserData;
ma_result result;
MA_ASSERT(pEncoder != NULL);
- result = pEncoder->onSeek(pEncoder, offset, (origin == drwav_seek_origin_start) ? ma_seek_origin_start : ma_seek_origin_current);
+ result = pEncoder->onSeek(pEncoder, offset, (origin == ma_dr_wav_seek_origin_start) ? ma_seek_origin_start : ma_seek_origin_current);
if (result != MA_SUCCESS) {
- return DRWAV_FALSE;
+ return MA_FALSE;
} else {
- return DRWAV_TRUE;
+ return MA_TRUE;
}
}
static ma_result ma_encoder__on_init_wav(ma_encoder* pEncoder)
{
- drwav_data_format wavFormat;
- drwav_allocation_callbacks allocationCallbacks;
- drwav* pWav;
+ ma_dr_wav_data_format wavFormat;
+ ma_allocation_callbacks allocationCallbacks;
+ ma_dr_wav* pWav;
MA_ASSERT(pEncoder != NULL);
- pWav = (drwav*)ma_malloc(sizeof(*pWav), &pEncoder->config.allocationCallbacks);
+ pWav = (ma_dr_wav*)ma_malloc(sizeof(*pWav), &pEncoder->config.allocationCallbacks);
if (pWav == NULL) {
return MA_OUT_OF_MEMORY;
}
- wavFormat.container = drwav_container_riff;
+ wavFormat.container = ma_dr_wav_container_riff;
wavFormat.channels = pEncoder->config.channels;
wavFormat.sampleRate = pEncoder->config.sampleRate;
wavFormat.bitsPerSample = ma_get_bytes_per_sample(pEncoder->config.format) * 8;
if (pEncoder->config.format == ma_format_f32) {
- wavFormat.format = DR_WAVE_FORMAT_IEEE_FLOAT;
+ wavFormat.format = MA_DR_WAVE_FORMAT_IEEE_FLOAT;
} else {
- wavFormat.format = DR_WAVE_FORMAT_PCM;
+ wavFormat.format = MA_DR_WAVE_FORMAT_PCM;
}
allocationCallbacks.pUserData = pEncoder->config.allocationCallbacks.pUserData;
@@ -63342,7 +65574,7 @@ static ma_result ma_encoder__on_init_wav(ma_encoder* pEncoder)
allocationCallbacks.onRealloc = pEncoder->config.allocationCallbacks.onRealloc;
allocationCallbacks.onFree = pEncoder->config.allocationCallbacks.onFree;
- if (!drwav_init_write(pWav, &wavFormat, ma_encoder__internal_on_write_wav, ma_encoder__internal_on_seek_wav, pEncoder, &allocationCallbacks)) {
+ if (!ma_dr_wav_init_write(pWav, &wavFormat, ma_encoder__internal_on_write_wav, ma_encoder__internal_on_seek_wav, pEncoder, &allocationCallbacks)) {
return MA_ERROR;
}
@@ -63353,28 +65585,28 @@ static ma_result ma_encoder__on_init_wav(ma_encoder* pEncoder)
static void ma_encoder__on_uninit_wav(ma_encoder* pEncoder)
{
- drwav* pWav;
+ ma_dr_wav* pWav;
MA_ASSERT(pEncoder != NULL);
- pWav = (drwav*)pEncoder->pInternalEncoder;
+ pWav = (ma_dr_wav*)pEncoder->pInternalEncoder;
MA_ASSERT(pWav != NULL);
- drwav_uninit(pWav);
+ ma_dr_wav_uninit(pWav);
ma_free(pWav, &pEncoder->config.allocationCallbacks);
}
static ma_result ma_encoder__on_write_pcm_frames_wav(ma_encoder* pEncoder, const void* pFramesIn, ma_uint64 frameCount, ma_uint64* pFramesWritten)
{
- drwav* pWav;
+ ma_dr_wav* pWav;
ma_uint64 framesWritten;
MA_ASSERT(pEncoder != NULL);
- pWav = (drwav*)pEncoder->pInternalEncoder;
+ pWav = (ma_dr_wav*)pEncoder->pInternalEncoder;
MA_ASSERT(pWav != NULL);
- framesWritten = drwav_write_pcm_frames(pWav, frameCount, pFramesIn);
+ framesWritten = ma_dr_wav_write_pcm_frames(pWav, frameCount, pFramesIn);
if (pFramesWritten != NULL) {
*pFramesWritten = framesWritten;
@@ -63752,12 +65984,12 @@ static ma_int16 ma_waveform_sine_s16(double time, double amplitude)
return ma_pcm_sample_f32_to_s16(ma_waveform_sine_f32(time, amplitude));
}
-static float ma_waveform_square_f32(double time, double amplitude)
+static float ma_waveform_square_f32(double time, double dutyCycle, double amplitude)
{
double f = time - (ma_int64)time;
double r;
- if (f < 0.5) {
+ if (f < dutyCycle) {
r = amplitude;
} else {
r = -amplitude;
@@ -63766,9 +65998,9 @@ static float ma_waveform_square_f32(double time, double amplitude)
return (float)r;
}
-static ma_int16 ma_waveform_square_s16(double time, double amplitude)
+static ma_int16 ma_waveform_square_s16(double time, double dutyCycle, double amplitude)
{
- return ma_pcm_sample_f32_to_s16(ma_waveform_square_f32(time, amplitude));
+ return ma_pcm_sample_f32_to_s16(ma_waveform_square_f32(time, dutyCycle, amplitude));
}
static float ma_waveform_triangle_f32(double time, double amplitude)
@@ -63843,7 +66075,7 @@ static void ma_waveform_read_pcm_frames__sine(ma_waveform* pWaveform, void* pFra
}
}
-static void ma_waveform_read_pcm_frames__square(ma_waveform* pWaveform, void* pFramesOut, ma_uint64 frameCount)
+static void ma_waveform_read_pcm_frames__square(ma_waveform* pWaveform, double dutyCycle, void* pFramesOut, ma_uint64 frameCount)
{
ma_uint64 iFrame;
ma_uint64 iChannel;
@@ -63856,7 +66088,7 @@ static void ma_waveform_read_pcm_frames__square(ma_waveform* pWaveform, void* pF
if (pWaveform->config.format == ma_format_f32) {
float* pFramesOutF32 = (float*)pFramesOut;
for (iFrame = 0; iFrame < frameCount; iFrame += 1) {
- float s = ma_waveform_square_f32(pWaveform->time, pWaveform->config.amplitude);
+ float s = ma_waveform_square_f32(pWaveform->time, dutyCycle, pWaveform->config.amplitude);
pWaveform->time += pWaveform->advance;
for (iChannel = 0; iChannel < pWaveform->config.channels; iChannel += 1) {
@@ -63866,7 +66098,7 @@ static void ma_waveform_read_pcm_frames__square(ma_waveform* pWaveform, void* pF
} else if (pWaveform->config.format == ma_format_s16) {
ma_int16* pFramesOutS16 = (ma_int16*)pFramesOut;
for (iFrame = 0; iFrame < frameCount; iFrame += 1) {
- ma_int16 s = ma_waveform_square_s16(pWaveform->time, pWaveform->config.amplitude);
+ ma_int16 s = ma_waveform_square_s16(pWaveform->time, dutyCycle, pWaveform->config.amplitude);
pWaveform->time += pWaveform->advance;
for (iChannel = 0; iChannel < pWaveform->config.channels; iChannel += 1) {
@@ -63875,7 +66107,7 @@ static void ma_waveform_read_pcm_frames__square(ma_waveform* pWaveform, void* pF
}
} else {
for (iFrame = 0; iFrame < frameCount; iFrame += 1) {
- float s = ma_waveform_square_f32(pWaveform->time, pWaveform->config.amplitude);
+ float s = ma_waveform_square_f32(pWaveform->time, dutyCycle, pWaveform->config.amplitude);
pWaveform->time += pWaveform->advance;
for (iChannel = 0; iChannel < pWaveform->config.channels; iChannel += 1) {
@@ -63993,7 +66225,7 @@ MA_API ma_result ma_waveform_read_pcm_frames(ma_waveform* pWaveform, void* pFram
case ma_waveform_type_square:
{
- ma_waveform_read_pcm_frames__square(pWaveform, pFramesOut, frameCount);
+ ma_waveform_read_pcm_frames__square(pWaveform, 0.5, pFramesOut, frameCount);
} break;
case ma_waveform_type_triangle:
@@ -64030,6 +66262,142 @@ MA_API ma_result ma_waveform_seek_to_pcm_frame(ma_waveform* pWaveform, ma_uint64
return MA_SUCCESS;
}
+MA_API ma_pulsewave_config ma_pulsewave_config_init(ma_format format, ma_uint32 channels, ma_uint32 sampleRate, double dutyCycle, double amplitude, double frequency)
+{
+ ma_pulsewave_config config;
+
+ MA_ZERO_OBJECT(&config);
+ config.format = format;
+ config.channels = channels;
+ config.sampleRate = sampleRate;
+ config.dutyCycle = dutyCycle;
+ config.amplitude = amplitude;
+ config.frequency = frequency;
+
+ return config;
+}
+
+MA_API ma_result ma_pulsewave_init(const ma_pulsewave_config* pConfig, ma_pulsewave* pWaveform)
+{
+ ma_result result;
+ ma_waveform_config config;
+
+ if (pWaveform == NULL) {
+ return MA_INVALID_ARGS;
+ }
+
+ MA_ZERO_OBJECT(pWaveform);
+
+ config = ma_waveform_config_init(
+ pConfig->format,
+ pConfig->channels,
+ pConfig->sampleRate,
+ ma_waveform_type_square,
+ pConfig->amplitude,
+ pConfig->frequency
+ );
+
+ result = ma_waveform_init(&config, &pWaveform->waveform);
+ ma_pulsewave_set_duty_cycle(pWaveform, pConfig->dutyCycle);
+
+ return result;
+}
+
+MA_API void ma_pulsewave_uninit(ma_pulsewave* pWaveform)
+{
+ if (pWaveform == NULL) {
+ return;
+ }
+
+ ma_waveform_uninit(&pWaveform->waveform);
+}
+
+MA_API ma_result ma_pulsewave_read_pcm_frames(ma_pulsewave* pWaveform, void* pFramesOut, ma_uint64 frameCount, ma_uint64* pFramesRead)
+{
+ if (pFramesRead != NULL) {
+ *pFramesRead = 0;
+ }
+
+ if (frameCount == 0) {
+ return MA_INVALID_ARGS;
+ }
+
+ if (pWaveform == NULL) {
+ return MA_INVALID_ARGS;
+ }
+
+ if (pFramesOut != NULL) {
+ ma_waveform_read_pcm_frames__square(&pWaveform->waveform, pWaveform->config.dutyCycle, pFramesOut, frameCount);
+ } else {
+ pWaveform->waveform.time += pWaveform->waveform.advance * (ma_int64)frameCount; /* Cast to int64 required for VC6. Won't affect anything in practice. */
+ }
+
+ if (pFramesRead != NULL) {
+ *pFramesRead = frameCount;
+ }
+
+ return MA_SUCCESS;
+}
+
+MA_API ma_result ma_pulsewave_seek_to_pcm_frame(ma_pulsewave* pWaveform, ma_uint64 frameIndex)
+{
+ if (pWaveform == NULL) {
+ return MA_INVALID_ARGS;
+ }
+
+ ma_waveform_seek_to_pcm_frame(&pWaveform->waveform, frameIndex);
+
+ return MA_SUCCESS;
+}
+
+MA_API ma_result ma_pulsewave_set_amplitude(ma_pulsewave* pWaveform, double amplitude)
+{
+ if (pWaveform == NULL) {
+ return MA_INVALID_ARGS;
+ }
+
+ pWaveform->config.amplitude = amplitude;
+ ma_waveform_set_amplitude(&pWaveform->waveform, amplitude);
+
+ return MA_SUCCESS;
+}
+
+MA_API ma_result ma_pulsewave_set_frequency(ma_pulsewave* pWaveform, double frequency)
+{
+ if (pWaveform == NULL) {
+ return MA_INVALID_ARGS;
+ }
+
+ pWaveform->config.frequency = frequency;
+ ma_waveform_set_frequency(&pWaveform->waveform, frequency);
+
+ return MA_SUCCESS;
+}
+
+MA_API ma_result ma_pulsewave_set_sample_rate(ma_pulsewave* pWaveform, ma_uint32 sampleRate)
+{
+ if (pWaveform == NULL) {
+ return MA_INVALID_ARGS;
+ }
+
+ pWaveform->config.sampleRate = sampleRate;
+ ma_waveform_set_sample_rate(&pWaveform->waveform, sampleRate);
+
+ return MA_SUCCESS;
+}
+
+MA_API ma_result ma_pulsewave_set_duty_cycle(ma_pulsewave* pWaveform, double dutyCycle)
+{
+ if (pWaveform == NULL) {
+ return MA_INVALID_ARGS;
+ }
+
+ pWaveform->config.dutyCycle = dutyCycle;
+
+ return MA_SUCCESS;
+}
+
+
MA_API ma_noise_config ma_noise_config_init(ma_format format, ma_uint32 channels, ma_noise_type type, ma_int32 seed, double amplitude)
{
@@ -64297,8 +66665,15 @@ MA_API ma_result ma_noise_set_type(ma_noise* pNoise, ma_noise_type type)
return MA_INVALID_ARGS;
}
- pNoise->config.type = type;
- return MA_SUCCESS;
+ /*
+ This function should never have been implemented in the first place. Changing the type dynamically is not
+ supported. Instead you need to uninitialize and reinitiailize a fresh `ma_noise` object. This function
+ will be removed in version 0.12.
+ */
+ MA_ASSERT(MA_FALSE);
+ (void)type;
+
+ return MA_INVALID_OPERATION;
}
static MA_INLINE float ma_noise_f32_white(ma_noise* pNoise)
@@ -65059,12 +67434,12 @@ static ma_result ma_resource_manager_data_buffer_node_remove_by_key(ma_resource_
static ma_resource_manager_data_supply_type ma_resource_manager_data_buffer_node_get_data_supply_type(ma_resource_manager_data_buffer_node* pDataBufferNode)
{
- return (ma_resource_manager_data_supply_type)c89atomic_load_i32(&pDataBufferNode->data.type);
+ return (ma_resource_manager_data_supply_type)ma_atomic_load_i32(&pDataBufferNode->data.type);
}
static void ma_resource_manager_data_buffer_node_set_data_supply_type(ma_resource_manager_data_buffer_node* pDataBufferNode, ma_resource_manager_data_supply_type supplyType)
{
- c89atomic_exchange_i32(&pDataBufferNode->data.type, supplyType);
+ ma_atomic_exchange_i32(&pDataBufferNode->data.type, supplyType);
}
static ma_result ma_resource_manager_data_buffer_node_increment_ref(ma_resource_manager* pResourceManager, ma_resource_manager_data_buffer_node* pDataBufferNode, ma_uint32* pNewRefCount)
@@ -65076,7 +67451,7 @@ static ma_result ma_resource_manager_data_buffer_node_increment_ref(ma_resource_
(void)pResourceManager;
- refCount = c89atomic_fetch_add_32(&pDataBufferNode->refCount, 1) + 1;
+ refCount = ma_atomic_fetch_add_32(&pDataBufferNode->refCount, 1) + 1;
if (pNewRefCount != NULL) {
*pNewRefCount = refCount;
@@ -65094,7 +67469,7 @@ static ma_result ma_resource_manager_data_buffer_node_decrement_ref(ma_resource_
(void)pResourceManager;
- refCount = c89atomic_fetch_sub_32(&pDataBufferNode->refCount, 1) - 1;
+ refCount = ma_atomic_fetch_sub_32(&pDataBufferNode->refCount, 1) - 1;
if (pNewRefCount != NULL) {
*pNewRefCount = refCount;
@@ -65133,7 +67508,7 @@ static ma_result ma_resource_manager_data_buffer_node_result(const ma_resource_m
{
MA_ASSERT(pDataBufferNode != NULL);
- return (ma_result)c89atomic_load_i32((ma_result*)&pDataBufferNode->result); /* Need a naughty const-cast here. */
+ return (ma_result)ma_atomic_load_i32((ma_result*)&pDataBufferNode->result); /* Need a naughty const-cast here. */
}
@@ -65405,7 +67780,7 @@ MA_API ma_result ma_resource_manager_init(const ma_resource_manager_config* pCon
/* Create the job threads last to ensure the threads has access to valid data. */
for (iJobThread = 0; iJobThread < pResourceManager->config.jobThreadCount; iJobThread += 1) {
- result = ma_thread_create(&pResourceManager->jobThreads[iJobThread], ma_thread_priority_normal, 0, ma_resource_manager_job_thread, pResourceManager, &pResourceManager->config.allocationCallbacks);
+ result = ma_thread_create(&pResourceManager->jobThreads[iJobThread], ma_thread_priority_normal, pResourceManager->config.jobThreadStackSize, ma_resource_manager_job_thread, pResourceManager, &pResourceManager->config.allocationCallbacks);
if (result != MA_SUCCESS) {
ma_mutex_uninit(&pResourceManager->dataBufferBSTLock);
ma_job_queue_uninit(&pResourceManager->jobQueue, &pResourceManager->config.allocationCallbacks);
@@ -65510,8 +67885,11 @@ MA_API ma_resource_manager_data_source_config ma_resource_manager_data_source_co
ma_resource_manager_data_source_config config;
MA_ZERO_OBJECT(&config);
- config.rangeEndInPCMFrames = ~((ma_uint64)0);
- config.loopPointEndInPCMFrames = ~((ma_uint64)0);
+ config.rangeBegInPCMFrames = MA_DATA_SOURCE_DEFAULT_RANGE_BEG;
+ config.rangeEndInPCMFrames = MA_DATA_SOURCE_DEFAULT_RANGE_END;
+ config.loopPointBegInPCMFrames = MA_DATA_SOURCE_DEFAULT_LOOP_POINT_BEG;
+ config.loopPointEndInPCMFrames = MA_DATA_SOURCE_DEFAULT_LOOP_POINT_END;
+ config.isLooping = MA_FALSE;
return config;
}
@@ -65560,8 +67938,17 @@ static ma_result ma_resource_manager__init_decoder(ma_resource_manager* pResourc
return MA_SUCCESS;
}
+static ma_bool32 ma_resource_manager_data_buffer_has_connector(ma_resource_manager_data_buffer* pDataBuffer)
+{
+ return ma_atomic_bool32_get(&pDataBuffer->isConnectorInitialized);
+}
+
static ma_data_source* ma_resource_manager_data_buffer_get_connector(ma_resource_manager_data_buffer* pDataBuffer)
{
+ if (ma_resource_manager_data_buffer_has_connector(pDataBuffer) == MA_FALSE) {
+ return NULL; /* Connector not yet initialized. */
+ }
+
switch (pDataBuffer->pNode->data.type)
{
case ma_resource_manager_data_supply_type_encoded: return &pDataBuffer->connector.decoder;
@@ -65583,7 +67970,7 @@ static ma_result ma_resource_manager_data_buffer_init_connector(ma_resource_mana
MA_ASSERT(pDataBuffer != NULL);
MA_ASSERT(pConfig != NULL);
- MA_ASSERT(pDataBuffer->isConnectorInitialized == MA_FALSE);
+ MA_ASSERT(ma_resource_manager_data_buffer_has_connector(pDataBuffer) == MA_FALSE);
/* The underlying data buffer must be initialized before we'll be able to know how to initialize the backend. */
result = ma_resource_manager_data_buffer_node_result(pDataBuffer->pNode);
@@ -65633,14 +68020,30 @@ static ma_result ma_resource_manager_data_buffer_init_connector(ma_resource_mana
*/
if (result == MA_SUCCESS) {
/*
- Make sure the looping state is set before returning in order to handle the case where the
- loop state was set on the data buffer before the connector was initialized.
+ The resource manager supports the ability to set the range and loop settings via a config at
+ initialization time. This results in an case where the ranges could be set explicitly via
+ ma_data_source_set_*() before we get to this point here. If this happens, we'll end up
+ hitting a case where we just override those settings which results in what feels like a bug.
+
+ To address this we only change the relevant properties if they're not equal to defaults. If
+ they're equal to defaults there's no need to change them anyway. If they're *not* set to the
+ default values, we can assume the user has set the range and loop settings via the config. If
+ they're doing their own calls to ma_data_source_set_*() in addition to setting them via the
+ config, that's entirely on the caller and any synchronization issue becomes their problem.
*/
- ma_data_source_set_range_in_pcm_frames(pDataBuffer, pConfig->rangeBegInPCMFrames, pConfig->rangeEndInPCMFrames);
- ma_data_source_set_loop_point_in_pcm_frames(pDataBuffer, pConfig->loopPointBegInPCMFrames, pConfig->loopPointEndInPCMFrames);
- ma_data_source_set_looping(pDataBuffer, pConfig->isLooping);
+ if (pConfig->rangeBegInPCMFrames != MA_DATA_SOURCE_DEFAULT_RANGE_BEG || pConfig->rangeEndInPCMFrames != MA_DATA_SOURCE_DEFAULT_RANGE_END) {
+ ma_data_source_set_range_in_pcm_frames(pDataBuffer, pConfig->rangeBegInPCMFrames, pConfig->rangeEndInPCMFrames);
+ }
+
+ if (pConfig->loopPointBegInPCMFrames != MA_DATA_SOURCE_DEFAULT_LOOP_POINT_BEG || pConfig->loopPointEndInPCMFrames != MA_DATA_SOURCE_DEFAULT_LOOP_POINT_END) {
+ ma_data_source_set_loop_point_in_pcm_frames(pDataBuffer, pConfig->loopPointBegInPCMFrames, pConfig->loopPointEndInPCMFrames);
+ }
- pDataBuffer->isConnectorInitialized = MA_TRUE;
+ if (pConfig->isLooping != MA_FALSE) {
+ ma_data_source_set_looping(pDataBuffer, pConfig->isLooping);
+ }
+
+ ma_atomic_bool32_set(&pDataBuffer->isConnectorInitialized, MA_TRUE);
if (pInitNotification != NULL) {
ma_async_notification_signal(pInitNotification);
@@ -65660,6 +68063,8 @@ static ma_result ma_resource_manager_data_buffer_uninit_connector(ma_resource_ma
MA_ASSERT(pResourceManager != NULL);
MA_ASSERT(pDataBuffer != NULL);
+ (void)pResourceManager;
+
switch (ma_resource_manager_data_buffer_node_get_data_supply_type(pDataBuffer->pNode))
{
case ma_resource_manager_data_supply_type_encoded: /* Connector is a decoder. */
@@ -65691,7 +68096,7 @@ static ma_result ma_resource_manager_data_buffer_uninit_connector(ma_resource_ma
static ma_uint32 ma_resource_manager_data_buffer_node_next_execution_order(ma_resource_manager_data_buffer_node* pDataBufferNode)
{
MA_ASSERT(pDataBufferNode != NULL);
- return c89atomic_fetch_add_32(&pDataBufferNode->executionCounter, 1);
+ return ma_atomic_fetch_add_32(&pDataBufferNode->executionCounter, 1);
}
static ma_result ma_resource_manager_data_buffer_node_init_supply_encoded(ma_resource_manager* pResourceManager, ma_resource_manager_data_buffer_node* pDataBufferNode, const char* pFilePath, const wchar_t* pFilePathW)
@@ -66008,7 +68413,12 @@ static ma_result ma_resource_manager_data_buffer_node_acquire_critical_section(m
job.data.resourceManager.loadDataBufferNode.pInitFence = pInitFence;
job.data.resourceManager.loadDataBufferNode.pDoneFence = pDoneFence;
- result = ma_resource_manager_post_job(pResourceManager, &job);
+ if ((flags & MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_WAIT_INIT) != 0) {
+ result = ma_job_process(&job);
+ } else {
+ result = ma_resource_manager_post_job(pResourceManager, &job);
+ }
+
if (result != MA_SUCCESS) {
/* Failed to post job. Probably ran out of memory. */
ma_log_postf(ma_resource_manager_get_log(pResourceManager), MA_LOG_LEVEL_ERROR, "Failed to post MA_JOB_TYPE_RESOURCE_MANAGER_LOAD_DATA_BUFFER_NODE job. %s.\n", ma_result_description(result));
@@ -66021,12 +68431,13 @@ static ma_result ma_resource_manager_data_buffer_node_acquire_critical_section(m
if (pDoneFence != NULL) { ma_fence_release(pDoneFence); }
if ((flags & MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_WAIT_INIT) != 0) {
- ma_resource_manager_inline_notification_init(pResourceManager, pInitNotification);
+ ma_resource_manager_inline_notification_uninit(pInitNotification);
+ } else {
+ /* These will have been freed by the job thread, but with WAIT_INIT they will already have happend sinced the job has already been handled. */
+ ma_free(pFilePathCopy, &pResourceManager->config.allocationCallbacks);
+ ma_free(pFilePathWCopy, &pResourceManager->config.allocationCallbacks);
}
- ma_free(pFilePathCopy, &pResourceManager->config.allocationCallbacks);
- ma_free(pFilePathWCopy, &pResourceManager->config.allocationCallbacks);
-
ma_resource_manager_data_buffer_node_remove(pResourceManager, pDataBufferNode);
ma_free(pDataBufferNode, &pResourceManager->config.allocationCallbacks);
@@ -66156,7 +68567,7 @@ static ma_result ma_resource_manager_data_buffer_node_acquire(ma_resource_manage
}
/* Getting here means we were successful. Make sure the status of the node is updated accordingly. */
- c89atomic_exchange_i32(&pDataBufferNode->result, result);
+ ma_atomic_exchange_i32(&pDataBufferNode->result, result);
} else {
/* Loading asynchronously. We may need to wait for initialization. */
if ((flags & MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_WAIT_INIT) != 0) {
@@ -66261,7 +68672,7 @@ static ma_result ma_resource_manager_data_buffer_node_unacquire(ma_resource_mana
ma_job job;
/* We need to mark the node as unavailable for the sake of the resource manager worker threads. */
- c89atomic_exchange_i32(&pDataBufferNode->result, MA_UNAVAILABLE);
+ ma_atomic_exchange_i32(&pDataBufferNode->result, MA_UNAVAILABLE);
job = ma_job_init(MA_JOB_TYPE_RESOURCE_MANAGER_FREE_DATA_BUFFER_NODE);
job.order = ma_resource_manager_data_buffer_node_next_execution_order(pDataBufferNode);
@@ -66300,7 +68711,7 @@ static ma_result ma_resource_manager_data_buffer_node_unacquire(ma_resource_mana
static ma_uint32 ma_resource_manager_data_buffer_next_execution_order(ma_resource_manager_data_buffer* pDataBuffer)
{
MA_ASSERT(pDataBuffer != NULL);
- return c89atomic_fetch_add_32(&pDataBuffer->executionCounter, 1);
+ return ma_atomic_fetch_add_32(&pDataBuffer->executionCounter, 1);
}
static ma_result ma_resource_manager_data_buffer_cb__read_pcm_frames(ma_data_source* pDataSource, void* pFramesOut, ma_uint64 frameCount, ma_uint64* pFramesRead)
@@ -66333,7 +68744,7 @@ static ma_result ma_resource_manager_data_buffer_cb__set_looping(ma_data_source*
ma_resource_manager_data_buffer* pDataBuffer = (ma_resource_manager_data_buffer*)pDataSource;
MA_ASSERT(pDataBuffer != NULL);
- c89atomic_exchange_32(&pDataBuffer->isLooping, isLooping);
+ ma_atomic_exchange_32(&pDataBuffer->isLooping, isLooping);
/* The looping state needs to be set on the connector as well or else looping won't work when we read audio data. */
ma_data_source_set_looping(ma_resource_manager_data_buffer_get_connector(pDataBuffer), isLooping);
@@ -66390,7 +68801,7 @@ static ma_result ma_resource_manager_data_buffer_init_ex_internal(ma_resource_ma
async = (flags & MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_ASYNC) != 0;
/*
- Fences need to be acquired before doing anything. These must be aquired and released outside of
+ Fences need to be acquired before doing anything. These must be acquired and released outside of
the node to ensure there's no holes where ma_fence_wait() could prematurely return before the
data buffer has completed initialization.
@@ -66429,7 +68840,7 @@ static ma_result ma_resource_manager_data_buffer_init_ex_internal(ma_resource_ma
if (async == MA_FALSE || ma_resource_manager_data_buffer_node_result(pDataBufferNode) == MA_SUCCESS) {
/* Loading synchronously or the data has already been fully loaded. We can just initialize the connector from here without a job. */
result = ma_resource_manager_data_buffer_init_connector(pDataBuffer, pConfig, NULL, NULL);
- c89atomic_exchange_i32(&pDataBuffer->result, result);
+ ma_atomic_exchange_i32(&pDataBuffer->result, result);
ma_resource_manager_pipeline_notifications_signal_all_notifications(¬ifications);
goto done;
@@ -66447,7 +68858,7 @@ static ma_result ma_resource_manager_data_buffer_init_ex_internal(ma_resource_ma
worker thread is aware of it's busy state. If the LOAD_DATA_BUFFER job sees a status other
than MA_BUSY, it'll assume an error and fall through to an early exit.
*/
- c89atomic_exchange_i32(&pDataBuffer->result, MA_BUSY);
+ ma_atomic_exchange_i32(&pDataBuffer->result, MA_BUSY);
/* Acquire fences a second time. These will be released by the async thread. */
ma_resource_manager_pipeline_notifications_acquire_all_fences(¬ifications);
@@ -66465,11 +68876,17 @@ static ma_result ma_resource_manager_data_buffer_init_ex_internal(ma_resource_ma
job.data.resourceManager.loadDataBuffer.loopPointEndInPCMFrames = pConfig->loopPointEndInPCMFrames;
job.data.resourceManager.loadDataBuffer.isLooping = pConfig->isLooping;
- result = ma_resource_manager_post_job(pResourceManager, &job);
+ /* If we need to wait for initialization to complete we can just process the job in place. */
+ if ((flags & MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_WAIT_INIT) != 0) {
+ result = ma_job_process(&job);
+ } else {
+ result = ma_resource_manager_post_job(pResourceManager, &job);
+ }
+
if (result != MA_SUCCESS) {
/* We failed to post the job. Most likely there isn't enough room in the queue's buffer. */
ma_log_postf(ma_resource_manager_get_log(pResourceManager), MA_LOG_LEVEL_ERROR, "Failed to post MA_JOB_TYPE_RESOURCE_MANAGER_LOAD_DATA_BUFFER job. %s.\n", ma_result_description(result));
- c89atomic_exchange_i32(&pDataBuffer->result, result);
+ ma_atomic_exchange_i32(&pDataBuffer->result, result);
/* Release the fences after the result has been set on the data buffer. */
ma_resource_manager_pipeline_notifications_release_all_fences(¬ifications);
@@ -66598,7 +69015,7 @@ MA_API ma_result ma_resource_manager_data_buffer_uninit(ma_resource_manager_data
We need to mark the node as unavailable so we don't try reading from it anymore, but also to
let the loading thread know that it needs to abort it's loading procedure.
*/
- c89atomic_exchange_i32(&pDataBuffer->result, MA_UNAVAILABLE);
+ ma_atomic_exchange_i32(&pDataBuffer->result, MA_UNAVAILABLE);
result = ma_resource_manager_inline_notification_init(pDataBuffer->pResourceManager, ¬ification);
if (result != MA_SUCCESS) {
@@ -66645,15 +69062,25 @@ MA_API ma_result ma_resource_manager_data_buffer_read_pcm_frames(ma_resource_man
MA_ASSERT(ma_resource_manager_data_buffer_node_result(pDataBuffer->pNode) != MA_UNAVAILABLE);
/* If the node is not initialized we need to abort with a busy code. */
- if (ma_resource_manager_data_buffer_node_get_data_supply_type(pDataBuffer->pNode) == ma_resource_manager_data_supply_type_unknown) {
+ if (ma_resource_manager_data_buffer_has_connector(pDataBuffer) == MA_FALSE) {
return MA_BUSY; /* Still loading. */
}
+ /*
+ If we've got a seek scheduled we'll want to do that before reading. However, for paged buffers, there's
+ a chance that the sound hasn't yet been decoded up to the seek point will result in the seek failing. If
+ this happens, we need to keep the seek scheduled and return MA_BUSY.
+ */
if (pDataBuffer->seekToCursorOnNextRead) {
pDataBuffer->seekToCursorOnNextRead = MA_FALSE;
result = ma_data_source_seek_to_pcm_frame(ma_resource_manager_data_buffer_get_connector(pDataBuffer), pDataBuffer->seekTargetInPCMFrames);
if (result != MA_SUCCESS) {
+ if (result == MA_BAD_SEEK && ma_resource_manager_data_buffer_node_get_data_supply_type(pDataBuffer->pNode) == ma_resource_manager_data_supply_type_decoded_paged) {
+ pDataBuffer->seekToCursorOnNextRead = MA_TRUE; /* Keep the seek scheduled. We just haven't loaded enough data yet to do the seek properly. */
+ return MA_BUSY;
+ }
+
return result;
}
}
@@ -66726,7 +69153,7 @@ MA_API ma_result ma_resource_manager_data_buffer_seek_to_pcm_frame(ma_resource_m
MA_ASSERT(ma_resource_manager_data_buffer_node_result(pDataBuffer->pNode) != MA_UNAVAILABLE);
/* If we haven't yet got a connector we need to abort. */
- if (ma_resource_manager_data_buffer_node_get_data_supply_type(pDataBuffer->pNode) == ma_resource_manager_data_supply_type_unknown) {
+ if (ma_resource_manager_data_buffer_has_connector(pDataBuffer) == MA_FALSE) {
pDataBuffer->seekTargetInPCMFrames = frameIndex;
pDataBuffer->seekToCursorOnNextRead = MA_TRUE;
return MA_BUSY; /* Still loading. */
@@ -66848,7 +69275,7 @@ MA_API ma_result ma_resource_manager_data_buffer_result(const ma_resource_manage
return MA_INVALID_ARGS;
}
- return (ma_result)c89atomic_load_i32((ma_result*)&pDataBuffer->result); /* Need a naughty const-cast here. */
+ return (ma_result)ma_atomic_load_i32((ma_result*)&pDataBuffer->result); /* Need a naughty const-cast here. */
}
MA_API ma_result ma_resource_manager_data_buffer_set_looping(ma_resource_manager_data_buffer* pDataBuffer, ma_bool32 isLooping)
@@ -67001,19 +69428,19 @@ MA_API ma_result ma_resource_manager_unregister_data_w(ma_resource_manager* pRes
static ma_uint32 ma_resource_manager_data_stream_next_execution_order(ma_resource_manager_data_stream* pDataStream)
{
MA_ASSERT(pDataStream != NULL);
- return c89atomic_fetch_add_32(&pDataStream->executionCounter, 1);
+ return ma_atomic_fetch_add_32(&pDataStream->executionCounter, 1);
}
static ma_bool32 ma_resource_manager_data_stream_is_decoder_at_end(const ma_resource_manager_data_stream* pDataStream)
{
MA_ASSERT(pDataStream != NULL);
- return c89atomic_load_32((ma_bool32*)&pDataStream->isDecoderAtEnd);
+ return ma_atomic_load_32((ma_bool32*)&pDataStream->isDecoderAtEnd);
}
static ma_uint32 ma_resource_manager_data_stream_seek_counter(const ma_resource_manager_data_stream* pDataStream)
{
MA_ASSERT(pDataStream != NULL);
- return c89atomic_load_32((ma_uint32*)&pDataStream->seekCounter);
+ return ma_atomic_load_32((ma_uint32*)&pDataStream->seekCounter);
}
@@ -67047,7 +69474,7 @@ static ma_result ma_resource_manager_data_stream_cb__set_looping(ma_data_source*
ma_resource_manager_data_stream* pDataStream = (ma_resource_manager_data_stream*)pDataSource;
MA_ASSERT(pDataStream != NULL);
- c89atomic_exchange_32(&pDataStream->isLooping, isLooping);
+ ma_atomic_exchange_32(&pDataStream->isLooping, isLooping);
return MA_SUCCESS;
}
@@ -67060,7 +69487,7 @@ static ma_data_source_vtable g_ma_resource_manager_data_stream_vtable =
ma_resource_manager_data_stream_cb__get_cursor_in_pcm_frames,
ma_resource_manager_data_stream_cb__get_length_in_pcm_frames,
ma_resource_manager_data_stream_cb__set_looping,
- MA_DATA_SOURCE_SELF_MANAGED_RANGE_AND_LOOP_POINT
+ 0 /*MA_DATA_SOURCE_SELF_MANAGED_RANGE_AND_LOOP_POINT*/
};
static void ma_resource_manager_data_stream_set_absolute_cursor(ma_resource_manager_data_stream* pDataStream, ma_uint64 absoluteCursor)
@@ -67070,7 +69497,7 @@ static void ma_resource_manager_data_stream_set_absolute_cursor(ma_resource_mana
absoluteCursor = absoluteCursor % pDataStream->totalLengthInPCMFrames;
}
- c89atomic_exchange_64(&pDataStream->absoluteCursor, absoluteCursor);
+ ma_atomic_exchange_64(&pDataStream->absoluteCursor, absoluteCursor);
}
MA_API ma_result ma_resource_manager_data_stream_init_ex(ma_resource_manager* pResourceManager, const ma_resource_manager_data_source_config* pConfig, ma_resource_manager_data_stream* pDataStream)
@@ -67185,6 +69612,14 @@ MA_API ma_result ma_resource_manager_data_stream_init_ex(ma_resource_manager* pR
ma_async_notification_signal(notifications.init.pNotification);
}
+ /*
+ If there was an error during initialization make sure we return that result here. We don't want to do this
+ if we're not waiting because it will most likely be in a busy state.
+ */
+ if (pDataStream->result != MA_SUCCESS) {
+ return pDataStream->result;
+ }
+
/* NOTE: Do not release pInitFence here. That will be done by the job. */
}
@@ -67225,7 +69660,7 @@ MA_API ma_result ma_resource_manager_data_stream_uninit(ma_resource_manager_data
}
/* The first thing to do is set the result to unavailable. This will prevent future page decoding. */
- c89atomic_exchange_i32(&pDataStream->result, MA_UNAVAILABLE);
+ ma_atomic_exchange_i32(&pDataStream->result, MA_UNAVAILABLE);
/*
We need to post a job to ensure we're not in the middle or decoding or anything. Because the object is owned by the caller, we'll need
@@ -67292,11 +69727,11 @@ static void ma_resource_manager_data_stream_fill_page(ma_resource_manager_data_s
/* Just read straight from the decoder. It will deal with ranges and looping for us. */
result = ma_data_source_read_pcm_frames(&pDataStream->decoder, pPageData, pageSizeInFrames, &totalFramesReadForThisPage);
if (result == MA_AT_END || totalFramesReadForThisPage < pageSizeInFrames) {
- c89atomic_exchange_32(&pDataStream->isDecoderAtEnd, MA_TRUE);
+ ma_atomic_exchange_32(&pDataStream->isDecoderAtEnd, MA_TRUE);
}
- c89atomic_exchange_32(&pDataStream->pageFrameCount[pageIndex], (ma_uint32)totalFramesReadForThisPage);
- c89atomic_exchange_32(&pDataStream->isPageValid[pageIndex], MA_TRUE);
+ ma_atomic_exchange_32(&pDataStream->pageFrameCount[pageIndex], (ma_uint32)totalFramesReadForThisPage);
+ ma_atomic_exchange_32(&pDataStream->isPageValid[pageIndex], MA_TRUE);
}
static void ma_resource_manager_data_stream_fill_pages(ma_resource_manager_data_stream* pDataStream)
@@ -67341,14 +69776,14 @@ static ma_result ma_resource_manager_data_stream_map(ma_resource_manager_data_st
}
/* If the page we're on is invalid it means we've caught up to the job thread. */
- if (c89atomic_load_32(&pDataStream->isPageValid[pDataStream->currentPageIndex]) == MA_FALSE) {
+ if (ma_atomic_load_32(&pDataStream->isPageValid[pDataStream->currentPageIndex]) == MA_FALSE) {
framesAvailable = 0;
} else {
/*
The page we're on is valid so we must have some frames available. We need to make sure that we don't overflow into the next page, even if it's valid. The reason is
that the unmap process will only post an update for one page at a time. Keeping mapping tied to page boundaries makes this simpler.
*/
- ma_uint32 currentPageFrameCount = c89atomic_load_32(&pDataStream->pageFrameCount[pDataStream->currentPageIndex]);
+ ma_uint32 currentPageFrameCount = ma_atomic_load_32(&pDataStream->pageFrameCount[pDataStream->currentPageIndex]);
MA_ASSERT(currentPageFrameCount >= pDataStream->relativeCursor);
framesAvailable = currentPageFrameCount - pDataStream->relativeCursor;
@@ -67400,7 +69835,7 @@ static ma_result ma_resource_manager_data_stream_unmap(ma_resource_manager_data_
pageSizeInFrames = ma_resource_manager_data_stream_get_page_size_in_frames(pDataStream);
/* The absolute cursor needs to be updated for ma_resource_manager_data_stream_get_cursor_in_pcm_frames(). */
- ma_resource_manager_data_stream_set_absolute_cursor(pDataStream, c89atomic_load_64(&pDataStream->absoluteCursor) + frameCount);
+ ma_resource_manager_data_stream_set_absolute_cursor(pDataStream, ma_atomic_load_64(&pDataStream->absoluteCursor) + frameCount);
/* Here is where we need to check if we need to load a new page, and if so, post a job to load it. */
newRelativeCursor = pDataStream->relativeCursor + (ma_uint32)frameCount;
@@ -67416,7 +69851,7 @@ static ma_result ma_resource_manager_data_stream_unmap(ma_resource_manager_data_
job.data.resourceManager.pageDataStream.pageIndex = pDataStream->currentPageIndex;
/* The page needs to be marked as invalid so that the public API doesn't try reading from it. */
- c89atomic_exchange_32(&pDataStream->isPageValid[pDataStream->currentPageIndex], MA_FALSE);
+ ma_atomic_exchange_32(&pDataStream->isPageValid[pDataStream->currentPageIndex], MA_FALSE);
/* Before posting the job we need to make sure we set some state. */
pDataStream->relativeCursor = newRelativeCursor;
@@ -67519,15 +69954,15 @@ MA_API ma_result ma_resource_manager_data_stream_seek_to_pcm_frame(ma_resource_m
}
/* If we're not already seeking and we're sitting on the same frame, just make this a no-op. */
- if (c89atomic_load_32(&pDataStream->seekCounter) == 0) {
- if (c89atomic_load_64(&pDataStream->absoluteCursor) == frameIndex) {
+ if (ma_atomic_load_32(&pDataStream->seekCounter) == 0) {
+ if (ma_atomic_load_64(&pDataStream->absoluteCursor) == frameIndex) {
return MA_SUCCESS;
}
}
/* Increment the seek counter first to indicate to read_paged_pcm_frames() and map_paged_pcm_frames() that we are in the middle of a seek and MA_BUSY should be returned. */
- c89atomic_fetch_add_32(&pDataStream->seekCounter, 1);
+ ma_atomic_fetch_add_32(&pDataStream->seekCounter, 1);
/* Update the absolute cursor so that ma_resource_manager_data_stream_get_cursor_in_pcm_frames() returns the new position. */
ma_resource_manager_data_stream_set_absolute_cursor(pDataStream, frameIndex);
@@ -67539,11 +69974,11 @@ MA_API ma_result ma_resource_manager_data_stream_seek_to_pcm_frame(ma_resource_m
*/
pDataStream->relativeCursor = 0;
pDataStream->currentPageIndex = 0;
- c89atomic_exchange_32(&pDataStream->isPageValid[0], MA_FALSE);
- c89atomic_exchange_32(&pDataStream->isPageValid[1], MA_FALSE);
+ ma_atomic_exchange_32(&pDataStream->isPageValid[0], MA_FALSE);
+ ma_atomic_exchange_32(&pDataStream->isPageValid[1], MA_FALSE);
/* Make sure the data stream is not marked as at the end or else if we seek in response to hitting the end, we won't be able to read any more data. */
- c89atomic_exchange_32(&pDataStream->isDecoderAtEnd, MA_FALSE);
+ ma_atomic_exchange_32(&pDataStream->isDecoderAtEnd, MA_FALSE);
/*
The public API is not allowed to touch the internal decoder so we need to use a job to perform the seek. When seeking, the job thread will assume both pages
@@ -67619,7 +70054,7 @@ MA_API ma_result ma_resource_manager_data_stream_get_cursor_in_pcm_frames(ma_res
return MA_INVALID_OPERATION;
}
- *pCursor = c89atomic_load_64(&pDataStream->absoluteCursor);
+ *pCursor = ma_atomic_load_64(&pDataStream->absoluteCursor);
return MA_SUCCESS;
}
@@ -67665,7 +70100,7 @@ MA_API ma_result ma_resource_manager_data_stream_result(const ma_resource_manage
return MA_INVALID_ARGS;
}
- return (ma_result)c89atomic_load_i32(&pDataStream->result);
+ return (ma_result)ma_atomic_load_i32(&pDataStream->result);
}
MA_API ma_result ma_resource_manager_data_stream_set_looping(ma_resource_manager_data_stream* pDataStream, ma_bool32 isLooping)
@@ -67679,7 +70114,7 @@ MA_API ma_bool32 ma_resource_manager_data_stream_is_looping(const ma_resource_ma
return MA_FALSE;
}
- return c89atomic_load_32((ma_bool32*)&pDataStream->isLooping); /* Naughty const-cast. Value won't change from here in practice (maybe from another thread). */
+ return ma_atomic_load_32((ma_bool32*)&pDataStream->isLooping); /* Naughty const-cast. Value won't change from here in practice (maybe from another thread). */
}
MA_API ma_result ma_resource_manager_data_stream_get_available_frames(ma_resource_manager_data_stream* pDataStream, ma_uint64* pAvailableFrames)
@@ -67704,10 +70139,10 @@ MA_API ma_result ma_resource_manager_data_stream_get_available_frames(ma_resourc
relativeCursor = pDataStream->relativeCursor;
availableFrames = 0;
- if (c89atomic_load_32(&pDataStream->isPageValid[pageIndex0])) {
- availableFrames += c89atomic_load_32(&pDataStream->pageFrameCount[pageIndex0]) - relativeCursor;
- if (c89atomic_load_32(&pDataStream->isPageValid[pageIndex1])) {
- availableFrames += c89atomic_load_32(&pDataStream->pageFrameCount[pageIndex1]);
+ if (ma_atomic_load_32(&pDataStream->isPageValid[pageIndex0])) {
+ availableFrames += ma_atomic_load_32(&pDataStream->pageFrameCount[pageIndex0]) - relativeCursor;
+ if (ma_atomic_load_32(&pDataStream->isPageValid[pageIndex1])) {
+ availableFrames += ma_atomic_load_32(&pDataStream->pageFrameCount[pageIndex1]);
}
}
@@ -68013,7 +70448,7 @@ static ma_result ma_job_process__resource_manager__load_data_buffer_node(ma_job*
MA_ASSERT(pDataBufferNode->isDataOwnedByResourceManager == MA_TRUE); /* The data should always be owned by the resource manager. */
/* The data buffer is not getting deleted, but we may be getting executed out of order. If so, we need to push the job back onto the queue and return. */
- if (pJob->order != c89atomic_load_32(&pDataBufferNode->executionPointer)) {
+ if (pJob->order != ma_atomic_load_32(&pDataBufferNode->executionPointer)) {
return ma_resource_manager_post_job(pResourceManager, pJob); /* Attempting to execute out of order. Probably interleaved with a MA_JOB_TYPE_RESOURCE_MANAGER_FREE_DATA_BUFFER job. */
}
@@ -68124,7 +70559,7 @@ static ma_result ma_job_process__resource_manager__load_data_buffer_node(ma_job*
immediately deletes it before we've got to this point. In this case, pDataBuffer->result will be MA_UNAVAILABLE, and setting it to MA_SUCCESS or any
other error code would cause the buffer to look like it's in a state that it's not.
*/
- c89atomic_compare_and_swap_i32(&pDataBufferNode->result, MA_BUSY, result);
+ ma_atomic_compare_and_swap_i32(&pDataBufferNode->result, MA_BUSY, result);
/* At this point initialization is complete and we can signal the notification if any. */
if (pJob->data.resourceManager.loadDataBufferNode.pInitNotification != NULL) {
@@ -68145,7 +70580,13 @@ static ma_result ma_job_process__resource_manager__load_data_buffer_node(ma_job*
}
/* Increment the node's execution pointer so that the next jobs can be processed. This is how we keep decoding of pages in-order. */
- c89atomic_fetch_add_32(&pDataBufferNode->executionPointer, 1);
+ ma_atomic_fetch_add_32(&pDataBufferNode->executionPointer, 1);
+
+ /* A busy result should be considered successful from the point of view of the job system. */
+ if (result == MA_BUSY) {
+ result = MA_SUCCESS;
+ }
+
return result;
}
@@ -68162,7 +70603,7 @@ static ma_result ma_job_process__resource_manager__free_data_buffer_node(ma_job*
pDataBufferNode = (ma_resource_manager_data_buffer_node*)pJob->data.resourceManager.freeDataBufferNode.pDataBufferNode;
MA_ASSERT(pDataBufferNode != NULL);
- if (pJob->order != c89atomic_load_32(&pDataBufferNode->executionPointer)) {
+ if (pJob->order != ma_atomic_load_32(&pDataBufferNode->executionPointer)) {
return ma_resource_manager_post_job(pResourceManager, pJob); /* Out of order. */
}
@@ -68177,7 +70618,7 @@ static ma_result ma_job_process__resource_manager__free_data_buffer_node(ma_job*
ma_fence_release(pJob->data.resourceManager.freeDataBufferNode.pDoneFence);
}
- c89atomic_fetch_add_32(&pDataBufferNode->executionPointer, 1);
+ ma_atomic_fetch_add_32(&pDataBufferNode->executionPointer, 1);
return MA_SUCCESS;
}
@@ -68195,7 +70636,7 @@ static ma_result ma_job_process__resource_manager__page_data_buffer_node(ma_job*
pDataBufferNode = (ma_resource_manager_data_buffer_node*)pJob->data.resourceManager.pageDataBufferNode.pDataBufferNode;
MA_ASSERT(pDataBufferNode != NULL);
- if (pJob->order != c89atomic_load_32(&pDataBufferNode->executionPointer)) {
+ if (pJob->order != ma_atomic_load_32(&pDataBufferNode->executionPointer)) {
return ma_resource_manager_post_job(pResourceManager, pJob); /* Out of order. */
}
@@ -68238,7 +70679,7 @@ static ma_result ma_job_process__resource_manager__page_data_buffer_node(ma_job*
}
/* Make sure we set the result of node in case some error occurred. */
- c89atomic_compare_and_swap_i32(&pDataBufferNode->result, MA_BUSY, result);
+ ma_atomic_compare_and_swap_i32(&pDataBufferNode->result, MA_BUSY, result);
/* Signal the notification after setting the result in case the notification callback wants to inspect the result code. */
if (result != MA_BUSY) {
@@ -68251,7 +70692,7 @@ static ma_result ma_job_process__resource_manager__page_data_buffer_node(ma_job*
}
}
- c89atomic_fetch_add_32(&pDataBufferNode->executionPointer, 1);
+ ma_atomic_fetch_add_32(&pDataBufferNode->executionPointer, 1);
return result;
}
@@ -68275,7 +70716,7 @@ static ma_result ma_job_process__resource_manager__load_data_buffer(ma_job* pJob
pResourceManager = pDataBuffer->pResourceManager;
- if (pJob->order != c89atomic_load_32(&pDataBuffer->executionPointer)) {
+ if (pJob->order != ma_atomic_load_32(&pDataBuffer->executionPointer)) {
return ma_resource_manager_post_job(pResourceManager, pJob); /* Attempting to execute out of order. Probably interleaved with a MA_JOB_TYPE_RESOURCE_MANAGER_FREE_DATA_BUFFER job. */
}
@@ -68291,7 +70732,7 @@ static ma_result ma_job_process__resource_manager__load_data_buffer(ma_job* pJob
}
/* Try initializing the connector if we haven't already. */
- isConnectorInitialized = pDataBuffer->isConnectorInitialized;
+ isConnectorInitialized = ma_resource_manager_data_buffer_has_connector(pDataBuffer);
if (isConnectorInitialized == MA_FALSE) {
dataSupplyType = ma_resource_manager_data_buffer_node_get_data_supply_type(pDataBuffer->pNode);
@@ -68333,7 +70774,7 @@ static ma_result ma_job_process__resource_manager__load_data_buffer(ma_job* pJob
done:
/* Only move away from a busy code so that we don't trash any existing error codes. */
- c89atomic_compare_and_swap_i32(&pDataBuffer->result, MA_BUSY, result);
+ ma_atomic_compare_and_swap_i32(&pDataBuffer->result, MA_BUSY, result);
/* Only signal the other threads after the result has been set just for cleanliness sake. */
if (pJob->data.resourceManager.loadDataBuffer.pDoneNotification != NULL) {
@@ -68347,7 +70788,7 @@ static ma_result ma_job_process__resource_manager__load_data_buffer(ma_job* pJob
If at this point the data buffer has not had it's connector initialized, it means the
notification event was never signalled which means we need to signal it here.
*/
- if (pDataBuffer->isConnectorInitialized == MA_FALSE && result != MA_SUCCESS) {
+ if (ma_resource_manager_data_buffer_has_connector(pDataBuffer) == MA_FALSE && result != MA_SUCCESS) {
if (pJob->data.resourceManager.loadDataBuffer.pInitNotification != NULL) {
ma_async_notification_signal(pJob->data.resourceManager.loadDataBuffer.pInitNotification);
}
@@ -68356,7 +70797,7 @@ static ma_result ma_job_process__resource_manager__load_data_buffer(ma_job* pJob
}
}
- c89atomic_fetch_add_32(&pDataBuffer->executionPointer, 1);
+ ma_atomic_fetch_add_32(&pDataBuffer->executionPointer, 1);
return result;
}
@@ -68372,7 +70813,7 @@ static ma_result ma_job_process__resource_manager__free_data_buffer(ma_job* pJob
pResourceManager = pDataBuffer->pResourceManager;
- if (pJob->order != c89atomic_load_32(&pDataBuffer->executionPointer)) {
+ if (pJob->order != ma_atomic_load_32(&pDataBuffer->executionPointer)) {
return ma_resource_manager_post_job(pResourceManager, pJob); /* Out of order. */
}
@@ -68387,7 +70828,7 @@ static ma_result ma_job_process__resource_manager__free_data_buffer(ma_job* pJob
ma_fence_release(pJob->data.resourceManager.freeDataBuffer.pDoneFence);
}
- c89atomic_fetch_add_32(&pDataBuffer->executionPointer, 1);
+ ma_atomic_fetch_add_32(&pDataBuffer->executionPointer, 1);
return MA_SUCCESS;
}
@@ -68406,7 +70847,7 @@ static ma_result ma_job_process__resource_manager__load_data_stream(ma_job* pJob
pResourceManager = pDataStream->pResourceManager;
- if (pJob->order != c89atomic_load_32(&pDataStream->executionPointer)) {
+ if (pJob->order != ma_atomic_load_32(&pDataStream->executionPointer)) {
return ma_resource_manager_post_job(pResourceManager, pJob); /* Out of order. */
}
@@ -68427,7 +70868,7 @@ static ma_result ma_job_process__resource_manager__load_data_stream(ma_job* pJob
goto done;
}
- /* Retrieve the total length of the file before marking the decoder are loaded. */
+ /* Retrieve the total length of the file before marking the decoder as loaded. */
if ((pDataStream->flags & MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_UNKNOWN_LENGTH) == 0) {
result = ma_decoder_get_length_in_pcm_frames(&pDataStream->decoder, &pDataStream->totalLengthInPCMFrames);
if (result != MA_SUCCESS) {
@@ -68467,7 +70908,7 @@ static ma_result ma_job_process__resource_manager__load_data_stream(ma_job* pJob
ma_free(pJob->data.resourceManager.loadDataStream.pFilePathW, &pResourceManager->config.allocationCallbacks);
/* We can only change the status away from MA_BUSY. If it's set to anything else it means an error has occurred somewhere or the uninitialization process has started (most likely). */
- c89atomic_compare_and_swap_i32(&pDataStream->result, MA_BUSY, result);
+ ma_atomic_compare_and_swap_i32(&pDataStream->result, MA_BUSY, result);
/* Only signal the other threads after the result has been set just for cleanliness sake. */
if (pJob->data.resourceManager.loadDataStream.pInitNotification != NULL) {
@@ -68477,7 +70918,7 @@ static ma_result ma_job_process__resource_manager__load_data_stream(ma_job* pJob
ma_fence_release(pJob->data.resourceManager.loadDataStream.pInitFence);
}
- c89atomic_fetch_add_32(&pDataStream->executionPointer, 1);
+ ma_atomic_fetch_add_32(&pDataStream->executionPointer, 1);
return result;
}
@@ -68493,7 +70934,7 @@ static ma_result ma_job_process__resource_manager__free_data_stream(ma_job* pJob
pResourceManager = pDataStream->pResourceManager;
- if (pJob->order != c89atomic_load_32(&pDataStream->executionPointer)) {
+ if (pJob->order != ma_atomic_load_32(&pDataStream->executionPointer)) {
return ma_resource_manager_post_job(pResourceManager, pJob); /* Out of order. */
}
@@ -68519,7 +70960,7 @@ static ma_result ma_job_process__resource_manager__free_data_stream(ma_job* pJob
ma_fence_release(pJob->data.resourceManager.freeDataStream.pDoneFence);
}
- /*c89atomic_fetch_add_32(&pDataStream->executionPointer, 1);*/
+ /*ma_atomic_fetch_add_32(&pDataStream->executionPointer, 1);*/
return MA_SUCCESS;
}
@@ -68536,7 +70977,7 @@ static ma_result ma_job_process__resource_manager__page_data_stream(ma_job* pJob
pResourceManager = pDataStream->pResourceManager;
- if (pJob->order != c89atomic_load_32(&pDataStream->executionPointer)) {
+ if (pJob->order != ma_atomic_load_32(&pDataStream->executionPointer)) {
return ma_resource_manager_post_job(pResourceManager, pJob); /* Out of order. */
}
@@ -68549,7 +70990,7 @@ static ma_result ma_job_process__resource_manager__page_data_stream(ma_job* pJob
ma_resource_manager_data_stream_fill_page(pDataStream, pJob->data.resourceManager.pageDataStream.pageIndex);
done:
- c89atomic_fetch_add_32(&pDataStream->executionPointer, 1);
+ ma_atomic_fetch_add_32(&pDataStream->executionPointer, 1);
return result;
}
@@ -68566,7 +71007,7 @@ static ma_result ma_job_process__resource_manager__seek_data_stream(ma_job* pJob
pResourceManager = pDataStream->pResourceManager;
- if (pJob->order != c89atomic_load_32(&pDataStream->executionPointer)) {
+ if (pJob->order != ma_atomic_load_32(&pDataStream->executionPointer)) {
return ma_resource_manager_post_job(pResourceManager, pJob); /* Out of order. */
}
@@ -68586,10 +71027,10 @@ static ma_result ma_job_process__resource_manager__seek_data_stream(ma_job* pJob
ma_resource_manager_data_stream_fill_pages(pDataStream);
/* We need to let the public API know that we're done seeking. */
- c89atomic_fetch_sub_32(&pDataStream->seekCounter, 1);
+ ma_atomic_fetch_sub_32(&pDataStream->seekCounter, 1);
done:
- c89atomic_fetch_add_32(&pDataStream->executionPointer, 1);
+ ma_atomic_fetch_add_32(&pDataStream->executionPointer, 1);
return result;
}
@@ -68673,35 +71114,6 @@ MA_API void ma_debug_fill_pcm_frames_with_sine_wave(float* pFramesOut, ma_uint32
-static ma_result ma_mix_pcm_frames_f32(float* pDst, const float* pSrc, ma_uint64 frameCount, ma_uint32 channels, float volume)
-{
- ma_uint64 iSample;
- ma_uint64 sampleCount;
-
- if (pDst == NULL || pSrc == NULL || channels == 0) {
- return MA_INVALID_ARGS;
- }
-
- if (volume == 0) {
- return MA_SUCCESS; /* No changes if the volume is 0. */
- }
-
- sampleCount = frameCount * channels;
-
- if (volume == 1) {
- for (iSample = 0; iSample < sampleCount; iSample += 1) {
- pDst[iSample] += pSrc[iSample];
- }
- } else {
- for (iSample = 0; iSample < sampleCount; iSample += 1) {
- pDst[iSample] += ma_apply_volume_unclipped_f32(pSrc[iSample], volume);
- }
- }
-
- return MA_SUCCESS;
-}
-
-
MA_API ma_node_graph_config ma_node_graph_config_init(ma_uint32 channels)
{
ma_node_graph_config config;
@@ -68717,14 +71129,14 @@ MA_API ma_node_graph_config ma_node_graph_config_init(ma_uint32 channels)
static void ma_node_graph_set_is_reading(ma_node_graph* pNodeGraph, ma_bool32 isReading)
{
MA_ASSERT(pNodeGraph != NULL);
- c89atomic_exchange_32(&pNodeGraph->isReading, isReading);
+ ma_atomic_exchange_32(&pNodeGraph->isReading, isReading);
}
#if 0
static ma_bool32 ma_node_graph_is_reading(ma_node_graph* pNodeGraph)
{
MA_ASSERT(pNodeGraph != NULL);
- return c89atomic_load_32(&pNodeGraph->isReading);
+ return ma_atomic_load_32(&pNodeGraph->isReading);
}
#endif
@@ -68974,26 +71386,26 @@ static ma_uint32 ma_node_output_bus_get_channels(const ma_node_output_bus* pOutp
static void ma_node_output_bus_set_has_read(ma_node_output_bus* pOutputBus, ma_bool32 hasRead)
{
if (hasRead) {
- c89atomic_fetch_or_32(&pOutputBus->flags, MA_NODE_OUTPUT_BUS_FLAG_HAS_READ);
+ ma_atomic_fetch_or_32(&pOutputBus->flags, MA_NODE_OUTPUT_BUS_FLAG_HAS_READ);
} else {
- c89atomic_fetch_and_32(&pOutputBus->flags, (ma_uint32)~MA_NODE_OUTPUT_BUS_FLAG_HAS_READ);
+ ma_atomic_fetch_and_32(&pOutputBus->flags, (ma_uint32)~MA_NODE_OUTPUT_BUS_FLAG_HAS_READ);
}
}
static ma_bool32 ma_node_output_bus_has_read(ma_node_output_bus* pOutputBus)
{
- return (c89atomic_load_32(&pOutputBus->flags) & MA_NODE_OUTPUT_BUS_FLAG_HAS_READ) != 0;
+ return (ma_atomic_load_32(&pOutputBus->flags) & MA_NODE_OUTPUT_BUS_FLAG_HAS_READ) != 0;
}
static void ma_node_output_bus_set_is_attached(ma_node_output_bus* pOutputBus, ma_bool32 isAttached)
{
- c89atomic_exchange_32(&pOutputBus->isAttached, isAttached);
+ ma_atomic_exchange_32(&pOutputBus->isAttached, isAttached);
}
static ma_bool32 ma_node_output_bus_is_attached(ma_node_output_bus* pOutputBus)
{
- return c89atomic_load_32(&pOutputBus->isAttached);
+ return ma_atomic_load_32(&pOutputBus->isAttached);
}
@@ -69005,14 +71417,14 @@ static ma_result ma_node_output_bus_set_volume(ma_node_output_bus* pOutputBus, f
volume = 0.0f;
}
- c89atomic_exchange_f32(&pOutputBus->volume, volume);
+ ma_atomic_exchange_f32(&pOutputBus->volume, volume);
return MA_SUCCESS;
}
static float ma_node_output_bus_get_volume(const ma_node_output_bus* pOutputBus)
{
- return c89atomic_load_f32((float*)&pOutputBus->volume);
+ return ma_atomic_load_f32((float*)&pOutputBus->volume);
}
@@ -69049,17 +71461,17 @@ static void ma_node_input_bus_unlock(ma_node_input_bus* pInputBus)
static void ma_node_input_bus_next_begin(ma_node_input_bus* pInputBus)
{
- c89atomic_fetch_add_32(&pInputBus->nextCounter, 1);
+ ma_atomic_fetch_add_32(&pInputBus->nextCounter, 1);
}
static void ma_node_input_bus_next_end(ma_node_input_bus* pInputBus)
{
- c89atomic_fetch_sub_32(&pInputBus->nextCounter, 1);
+ ma_atomic_fetch_sub_32(&pInputBus->nextCounter, 1);
}
static ma_uint32 ma_node_input_bus_get_next_counter(ma_node_input_bus* pInputBus)
{
- return c89atomic_load_32(&pInputBus->nextCounter);
+ return ma_atomic_load_32(&pInputBus->nextCounter);
}
@@ -69094,21 +71506,21 @@ static void ma_node_input_bus_detach__no_output_bus_lock(ma_node_input_bus* pInp
*/
ma_node_input_bus_lock(pInputBus);
{
- ma_node_output_bus* pOldPrev = (ma_node_output_bus*)c89atomic_load_ptr(&pOutputBus->pPrev);
- ma_node_output_bus* pOldNext = (ma_node_output_bus*)c89atomic_load_ptr(&pOutputBus->pNext);
+ ma_node_output_bus* pOldPrev = (ma_node_output_bus*)ma_atomic_load_ptr(&pOutputBus->pPrev);
+ ma_node_output_bus* pOldNext = (ma_node_output_bus*)ma_atomic_load_ptr(&pOutputBus->pNext);
if (pOldPrev != NULL) {
- c89atomic_exchange_ptr(&pOldPrev->pNext, pOldNext); /* <-- This is where the output bus is detached from the list. */
+ ma_atomic_exchange_ptr(&pOldPrev->pNext, pOldNext); /* <-- This is where the output bus is detached from the list. */
}
if (pOldNext != NULL) {
- c89atomic_exchange_ptr(&pOldNext->pPrev, pOldPrev); /* <-- This is required for detachment. */
+ ma_atomic_exchange_ptr(&pOldNext->pPrev, pOldPrev); /* <-- This is required for detachment. */
}
}
ma_node_input_bus_unlock(pInputBus);
/* At this point the output bus is detached and the linked list is completely unaware of it. Reset some data for safety. */
- c89atomic_exchange_ptr(&pOutputBus->pNext, NULL); /* Using atomic exchanges here, mainly for the benefit of analysis tools which don't always recognize spinlocks. */
- c89atomic_exchange_ptr(&pOutputBus->pPrev, NULL); /* As above. */
+ ma_atomic_exchange_ptr(&pOutputBus->pNext, NULL); /* Using atomic exchanges here, mainly for the benefit of analysis tools which don't always recognize spinlocks. */
+ ma_atomic_exchange_ptr(&pOutputBus->pPrev, NULL); /* As above. */
pOutputBus->pInputNode = NULL;
pOutputBus->inputNodeInputBusIndex = 0;
@@ -69132,7 +71544,7 @@ static void ma_node_input_bus_detach__no_output_bus_lock(ma_node_input_bus* pInp
}
/* Part 2: Wait for any reads to complete. */
- while (c89atomic_load_32(&pOutputBus->refCount) > 0) {
+ while (ma_atomic_load_32(&pOutputBus->refCount) > 0) {
ma_yield();
}
@@ -69163,7 +71575,7 @@ static void ma_node_input_bus_attach(ma_node_input_bus* pInputBus, ma_node_outpu
ma_node_output_bus_lock(pOutputBus);
{
- ma_node_output_bus* pOldInputNode = (ma_node_output_bus*)c89atomic_load_ptr(&pOutputBus->pInputNode);
+ ma_node_output_bus* pOldInputNode = (ma_node_output_bus*)ma_atomic_load_ptr(&pOutputBus->pInputNode);
/* Detach from any existing attachment first if necessary. */
if (pOldInputNode != NULL) {
@@ -69175,7 +71587,7 @@ static void ma_node_input_bus_attach(ma_node_input_bus* pInputBus, ma_node_outpu
old input bus has been updated so that pOutputBus will not get iterated again.
*/
pOutputBus->pInputNode = pNewInputNode; /* No need for an atomic assignment here because modification of this variable always happens within a lock. */
- pOutputBus->inputNodeInputBusIndex = (ma_uint8)inputNodeInputBusIndex; /* As above. */
+ pOutputBus->inputNodeInputBusIndex = (ma_uint8)inputNodeInputBusIndex;
/*
Now we need to attach the output bus to the linked list. This involves updating two pointers on
@@ -69193,18 +71605,18 @@ static void ma_node_input_bus_attach(ma_node_input_bus* pInputBus, ma_node_outpu
ma_node_input_bus_lock(pInputBus);
{
ma_node_output_bus* pNewPrev = &pInputBus->head;
- ma_node_output_bus* pNewNext = (ma_node_output_bus*)c89atomic_load_ptr(&pInputBus->head.pNext);
+ ma_node_output_bus* pNewNext = (ma_node_output_bus*)ma_atomic_load_ptr(&pInputBus->head.pNext);
/* Update the local output bus. */
- c89atomic_exchange_ptr(&pOutputBus->pPrev, pNewPrev);
- c89atomic_exchange_ptr(&pOutputBus->pNext, pNewNext);
+ ma_atomic_exchange_ptr(&pOutputBus->pPrev, pNewPrev);
+ ma_atomic_exchange_ptr(&pOutputBus->pNext, pNewNext);
/* Update the other output buses to point back to the local output bus. */
- c89atomic_exchange_ptr(&pInputBus->head.pNext, pOutputBus); /* <-- This is where the output bus is actually attached to the input bus. */
+ ma_atomic_exchange_ptr(&pInputBus->head.pNext, pOutputBus); /* <-- This is where the output bus is actually attached to the input bus. */
/* Do the previous pointer last. This is only used for detachment. */
if (pNewNext != NULL) {
- c89atomic_exchange_ptr(&pNewNext->pPrev, pOutputBus);
+ ma_atomic_exchange_ptr(&pNewNext->pPrev, pOutputBus);
}
}
ma_node_input_bus_unlock(pInputBus);
@@ -69232,7 +71644,7 @@ static ma_node_output_bus* ma_node_input_bus_next(ma_node_input_bus* pInputBus,
{
pNext = pOutputBus;
for (;;) {
- pNext = (ma_node_output_bus*)c89atomic_load_ptr(&pNext->pNext);
+ pNext = (ma_node_output_bus*)ma_atomic_load_ptr(&pNext->pNext);
if (pNext == NULL) {
break; /* Reached the end. */
}
@@ -69247,11 +71659,11 @@ static ma_node_output_bus* ma_node_input_bus_next(ma_node_input_bus* pInputBus,
/* We need to increment the reference count of the selected node. */
if (pNext != NULL) {
- c89atomic_fetch_add_32(&pNext->refCount, 1);
+ ma_atomic_fetch_add_32(&pNext->refCount, 1);
}
/* The previous node is no longer being referenced. */
- c89atomic_fetch_sub_32(&pOutputBus->refCount, 1);
+ ma_atomic_fetch_sub_32(&pOutputBus->refCount, 1);
}
ma_node_input_bus_next_end(pInputBus);
@@ -69273,6 +71685,8 @@ static ma_result ma_node_input_bus_read_pcm_frames(ma_node* pInputNode, ma_node_
ma_uint32 inputChannels;
ma_bool32 doesOutputBufferHaveContent = MA_FALSE;
+ (void)pInputNode; /* Not currently used. */
+
/*
This will be called from the audio thread which means we can't be doing any locking. Basically,
this function will not perfom any locking, whereas attaching and detaching will, but crafted in
@@ -69315,6 +71729,7 @@ static ma_result ma_node_input_bus_read_pcm_frames(ma_node* pInputNode, ma_node_
ma_bool32 isSilentOutput = MA_FALSE;
MA_ASSERT(pOutputBus->pNode != NULL);
+ MA_ASSERT(((ma_node_base*)pOutputBus->pNode)->vtable != NULL);
isSilentOutput = (((ma_node_base*)pOutputBus->pNode)->vtable->flags & MA_NODE_FLAG_SILENT_OUTPUT) != 0;
@@ -69497,8 +71912,8 @@ static ma_result ma_node_translate_bus_counts(const ma_node_config* pConfig, ma_
/* Some special rules for passthrough nodes. */
if ((pConfig->vtable->flags & MA_NODE_FLAG_PASSTHROUGH) != 0) {
- if (pConfig->vtable->inputBusCount != 1 || pConfig->vtable->outputBusCount != 1) {
- return MA_INVALID_ARGS; /* Passthrough nodes must have exactly 1 input bus and 1 output bus. */
+ if ((pConfig->vtable->inputBusCount != 0 && pConfig->vtable->inputBusCount != 1) || pConfig->vtable->outputBusCount != 1) {
+ return MA_INVALID_ARGS; /* Passthrough nodes must have exactly 1 output bus and either 0 or 1 input bus. */
}
if (pConfig->pInputChannels[0] != pConfig->pOutputChannels[0]) {
@@ -69658,7 +72073,7 @@ MA_API ma_result ma_node_init_preallocated(ma_node_graph* pNodeGraph, const ma_n
}
if (heapLayout.outputBusOffset != MA_SIZE_MAX) {
- pNodeBase->pOutputBuses = (ma_node_output_bus*)ma_offset_ptr(pHeap, heapLayout.inputBusOffset);
+ pNodeBase->pOutputBuses = (ma_node_output_bus*)ma_offset_ptr(pHeap, heapLayout.outputBusOffset);
} else {
pNodeBase->pOutputBuses = pNodeBase->_outputBuses;
}
@@ -69860,7 +72275,7 @@ static ma_result ma_node_detach_full(ma_node* pNode)
linked list logic. We don't need to worry about the audio thread referencing these because the step
above severed the connection to the graph.
*/
- for (pOutputBus = (ma_node_output_bus*)c89atomic_load_ptr(&pInputBus->head.pNext); pOutputBus != NULL; pOutputBus = (ma_node_output_bus*)c89atomic_load_ptr(&pOutputBus->pNext)) {
+ for (pOutputBus = (ma_node_output_bus*)ma_atomic_load_ptr(&pInputBus->head.pNext); pOutputBus != NULL; pOutputBus = (ma_node_output_bus*)ma_atomic_load_ptr(&pOutputBus->pNext)) {
ma_node_detach_output_bus(pOutputBus->pNode, pOutputBus->outputBusIndex); /* This won't do any waiting in practice and should be efficient. */
}
}
@@ -69976,7 +72391,7 @@ MA_API ma_result ma_node_set_state(ma_node* pNode, ma_node_state state)
return MA_INVALID_ARGS;
}
- c89atomic_exchange_i32(&pNodeBase->state, state);
+ ma_atomic_exchange_i32(&pNodeBase->state, state);
return MA_SUCCESS;
}
@@ -69989,7 +72404,7 @@ MA_API ma_node_state ma_node_get_state(const ma_node* pNode)
return ma_node_state_stopped;
}
- return (ma_node_state)c89atomic_load_i32(&pNodeBase->state);
+ return (ma_node_state)ma_atomic_load_i32(&pNodeBase->state);
}
MA_API ma_result ma_node_set_state_time(ma_node* pNode, ma_node_state state, ma_uint64 globalTime)
@@ -70003,7 +72418,7 @@ MA_API ma_result ma_node_set_state_time(ma_node* pNode, ma_node_state state, ma_
return MA_INVALID_ARGS;
}
- c89atomic_exchange_64(&((ma_node_base*)pNode)->stateTimes[state], globalTime);
+ ma_atomic_exchange_64(&((ma_node_base*)pNode)->stateTimes[state], globalTime);
return MA_SUCCESS;
}
@@ -70019,7 +72434,7 @@ MA_API ma_uint64 ma_node_get_state_time(const ma_node* pNode, ma_node_state stat
return 0;
}
- return c89atomic_load_64(&((ma_node_base*)pNode)->stateTimes[state]);
+ return ma_atomic_load_64(&((ma_node_base*)pNode)->stateTimes[state]);
}
MA_API ma_node_state ma_node_get_state_by_time(const ma_node* pNode, ma_uint64 globalTime)
@@ -70069,7 +72484,7 @@ MA_API ma_uint64 ma_node_get_time(const ma_node* pNode)
return 0;
}
- return c89atomic_load_64(&((ma_node_base*)pNode)->localTime);
+ return ma_atomic_load_64(&((ma_node_base*)pNode)->localTime);
}
MA_API ma_result ma_node_set_time(ma_node* pNode, ma_uint64 localTime)
@@ -70078,7 +72493,7 @@ MA_API ma_result ma_node_set_time(ma_node* pNode, ma_uint64 localTime)
return MA_INVALID_ARGS;
}
- c89atomic_exchange_64(&((ma_node_base*)pNode)->localTime, localTime);
+ ma_atomic_exchange_64(&((ma_node_base*)pNode)->localTime, localTime);
return MA_SUCCESS;
}
@@ -70149,11 +72564,11 @@ static ma_result ma_node_read_pcm_frames(ma_node* pNode, ma_uint32 outputBusInde
/*
At this point we know that we are inside our start/stop times. However, we may need to adjust
- our frame count and output pointer to accomodate since we could be straddling the time period
+ our frame count and output pointer to accommodate since we could be straddling the time period
that this function is getting called for.
It's possible (and likely) that the start time does not line up with the output buffer. We
- therefore need to offset it by a number of frames to accomodate. The same thing applies for
+ therefore need to offset it by a number of frames to accommodate. The same thing applies for
the stop time.
*/
timeOffsetBeg = (globalTimeBeg < startTime) ? (ma_uint32)(globalTimeEnd - startTime) : 0;
@@ -70187,6 +72602,15 @@ static ma_result ma_node_read_pcm_frames(ma_node* pNode, ma_uint32 outputBusInde
frameCountOut = frameCount; /* Just read as much as we can. The callback will return what was actually read. */
ppFramesOut[0] = pFramesOut;
+
+ /*
+ If it's a passthrough we won't be expecting the callback to output anything, so we'll
+ need to pre-silence the output buffer.
+ */
+ if ((pNodeBase->vtable->flags & MA_NODE_FLAG_PASSTHROUGH) != 0) {
+ ma_silence_pcm_frames(pFramesOut, frameCount, ma_format_f32, ma_node_get_output_channels(pNode, outputBusIndex));
+ }
+
ma_node_process_pcm_frames_internal(pNode, NULL, &frameCountIn, ppFramesOut, &frameCountOut);
totalFramesRead = frameCountOut;
} else {
@@ -70444,7 +72868,7 @@ static ma_result ma_node_read_pcm_frames(ma_node* pNode, ma_uint32 outputBusInde
ma_apply_volume_factor_f32(pFramesOut, totalFramesRead * ma_node_get_output_channels(pNodeBase, outputBusIndex), ma_node_output_bus_get_volume(&pNodeBase->pOutputBuses[outputBusIndex]));
/* Advance our local time forward. */
- c89atomic_fetch_add_64(&pNodeBase->localTime, (ma_uint64)totalFramesRead);
+ ma_atomic_fetch_add_64(&pNodeBase->localTime, (ma_uint64)totalFramesRead);
*pFramesRead = totalFramesRead + timeOffsetBeg; /* Must include the silenced section at the start of the buffer. */
return result;
@@ -70608,8 +73032,7 @@ static void ma_splitter_node_process_pcm_frames(ma_node* pNode, const float** pp
ma_uint32 channels;
MA_ASSERT(pNodeBase != NULL);
- MA_ASSERT(ma_node_get_input_bus_count(pNodeBase) == 1);
- MA_ASSERT(ma_node_get_output_bus_count(pNodeBase) >= 2);
+ MA_ASSERT(ma_node_get_input_bus_count(pNodeBase) == 1);
/* We don't need to consider the input frame count - it'll be the same as the output frame count and we process everything. */
(void)pFrameCountIn;
@@ -71568,6 +73991,27 @@ Engine
**************************************************************************************************************************************************************/
#define MA_SEEK_TARGET_NONE (~(ma_uint64)0)
+
+static void ma_sound_set_at_end(ma_sound* pSound, ma_bool32 atEnd)
+{
+ MA_ASSERT(pSound != NULL);
+ ma_atomic_exchange_32(&pSound->atEnd, atEnd);
+
+ /* Fire any callbacks or events. */
+ if (atEnd) {
+ if (pSound->endCallback != NULL) {
+ pSound->endCallback(pSound->pEndCallbackUserData, pSound);
+ }
+ }
+}
+
+static ma_bool32 ma_sound_get_at_end(const ma_sound* pSound)
+{
+ MA_ASSERT(pSound != NULL);
+ return ma_atomic_load_32(&pSound->atEnd);
+}
+
+
MA_API ma_engine_node_config ma_engine_node_config_init(ma_engine* pEngine, ma_engine_node_type type, ma_uint32 flags)
{
ma_engine_node_config config;
@@ -71590,7 +74034,7 @@ static void ma_engine_node_update_pitch_if_required(ma_engine_node* pEngineNode)
MA_ASSERT(pEngineNode != NULL);
- newPitch = c89atomic_load_explicit_f32(&pEngineNode->pitch, c89atomic_memory_order_acquire);
+ newPitch = ma_atomic_load_explicit_f32(&pEngineNode->pitch, ma_atomic_memory_order_acquire);
if (pEngineNode->oldPitch != newPitch) {
pEngineNode->oldPitch = newPitch;
@@ -71613,14 +74057,14 @@ static ma_bool32 ma_engine_node_is_pitching_enabled(const ma_engine_node* pEngin
MA_ASSERT(pEngineNode != NULL);
/* Don't try to be clever by skiping resampling in the pitch=1 case or else you'll glitch when moving away from 1. */
- return !c89atomic_load_explicit_32(&pEngineNode->isPitchDisabled, c89atomic_memory_order_acquire);
+ return !ma_atomic_load_explicit_32(&pEngineNode->isPitchDisabled, ma_atomic_memory_order_acquire);
}
static ma_bool32 ma_engine_node_is_spatialization_enabled(const ma_engine_node* pEngineNode)
{
MA_ASSERT(pEngineNode != NULL);
- return !c89atomic_load_explicit_32(&pEngineNode->isSpatializationDisabled, c89atomic_memory_order_acquire);
+ return !ma_atomic_load_explicit_32(&pEngineNode->isSpatializationDisabled, ma_atomic_memory_order_acquire);
}
static ma_uint64 ma_engine_node_get_required_input_frame_count(const ma_engine_node* pEngineNode, ma_uint64 outputFrameCount)
@@ -71639,6 +74083,44 @@ static ma_uint64 ma_engine_node_get_required_input_frame_count(const ma_engine_n
return inputFrameCount;
}
+static ma_result ma_engine_node_set_volume(ma_engine_node* pEngineNode, float volume)
+{
+ if (pEngineNode == NULL) {
+ return MA_INVALID_ARGS;
+ }
+
+ ma_atomic_float_set(&pEngineNode->volume, volume);
+
+ /* If we're not smoothing we should bypass the volume gainer entirely. */
+ if (pEngineNode->volumeSmoothTimeInPCMFrames == 0) {
+ /* We should always have an active spatializer because it can be enabled and disabled dynamically. We can just use that for hodling our volume. */
+ ma_spatializer_set_master_volume(&pEngineNode->spatializer, volume);
+ } else {
+ /* We're using volume smoothing, so apply the master volume to the gainer. */
+ ma_gainer_set_gain(&pEngineNode->volumeGainer, volume);
+ }
+
+ return MA_SUCCESS;
+}
+
+static ma_result ma_engine_node_get_volume(const ma_engine_node* pEngineNode, float* pVolume)
+{
+ if (pVolume == NULL) {
+ return MA_INVALID_ARGS;
+ }
+
+ *pVolume = 0.0f;
+
+ if (pEngineNode == NULL) {
+ return MA_INVALID_ARGS;
+ }
+
+ *pVolume = ma_atomic_float_get((ma_atomic_float*)&pEngineNode->volume);
+
+ return MA_SUCCESS;
+}
+
+
static void ma_engine_node_process_pcm_frames__general(ma_engine_node* pEngineNode, const float** ppFramesIn, ma_uint32* pFrameCountIn, float** ppFramesOut, ma_uint32* pFrameCountOut)
{
ma_uint32 frameCountIn;
@@ -71651,6 +74133,7 @@ static void ma_engine_node_process_pcm_frames__general(ma_engine_node* pEngineNo
ma_bool32 isFadingEnabled;
ma_bool32 isSpatializationEnabled;
ma_bool32 isPanningEnabled;
+ ma_bool32 isVolumeSmoothingEnabled;
frameCountIn = *pFrameCountIn;
frameCountOut = *pFrameCountOut;
@@ -71661,10 +74144,31 @@ static void ma_engine_node_process_pcm_frames__general(ma_engine_node* pEngineNo
totalFramesProcessedIn = 0;
totalFramesProcessedOut = 0;
- isPitchingEnabled = ma_engine_node_is_pitching_enabled(pEngineNode);
- isFadingEnabled = pEngineNode->fader.volumeBeg != 1 || pEngineNode->fader.volumeEnd != 1;
- isSpatializationEnabled = ma_engine_node_is_spatialization_enabled(pEngineNode);
- isPanningEnabled = pEngineNode->panner.pan != 0 && channelsOut != 1;
+ /* Update the fader if applicable. */
+ {
+ ma_uint64 fadeLengthInFrames = ma_atomic_uint64_get(&pEngineNode->fadeSettings.fadeLengthInFrames);
+ if (fadeLengthInFrames != ~(ma_uint64)0) {
+ float fadeVolumeBeg = ma_atomic_float_get(&pEngineNode->fadeSettings.volumeBeg);
+ float fadeVolumeEnd = ma_atomic_float_get(&pEngineNode->fadeSettings.volumeEnd);
+ ma_int64 fadeStartOffsetInFrames = (ma_int64)ma_atomic_uint64_get(&pEngineNode->fadeSettings.absoluteGlobalTimeInFrames);
+ if (fadeStartOffsetInFrames == (ma_int64)(~(ma_uint64)0)) {
+ fadeStartOffsetInFrames = 0;
+ } else {
+ fadeStartOffsetInFrames -= ma_engine_get_time_in_pcm_frames(pEngineNode->pEngine);
+ }
+
+ ma_fader_set_fade_ex(&pEngineNode->fader, fadeVolumeBeg, fadeVolumeEnd, fadeLengthInFrames, fadeStartOffsetInFrames);
+
+ /* Reset the fade length so we don't erroneously apply it again. */
+ ma_atomic_uint64_set(&pEngineNode->fadeSettings.fadeLengthInFrames, ~(ma_uint64)0);
+ }
+ }
+
+ isPitchingEnabled = ma_engine_node_is_pitching_enabled(pEngineNode);
+ isFadingEnabled = pEngineNode->fader.volumeBeg != 1 || pEngineNode->fader.volumeEnd != 1;
+ isSpatializationEnabled = ma_engine_node_is_spatialization_enabled(pEngineNode);
+ isPanningEnabled = pEngineNode->panner.pan != 0 && channelsOut != 1;
+ isVolumeSmoothingEnabled = pEngineNode->volumeSmoothTimeInPCMFrames > 0;
/* Keep going while we've still got data available for processing. */
while (totalFramesProcessedOut < frameCountOut) {
@@ -71678,10 +74182,10 @@ static void ma_engine_node_process_pcm_frames__general(ma_engine_node* pEngineNo
the output buffer and then do all effects from that point directly in the output buffer
in-place.
- Note that we're always running the resampler. If we try to be clever and skip resampling
- when the pitch is 1, we'll get a glitch when we move away from 1, back to 1, and then
- away from 1 again. We'll want to implement any pitch=1 optimizations in the resampler
- itself.
+ Note that we're always running the resampler if pitching is enabled, even when the pitch
+ is 1. If we try to be clever and skip resampling when the pitch is 1, we'll get a glitch
+ when we move away from 1, back to 1, and then away from 1 again. We'll want to implement
+ any pitch=1 optimizations in the resampler itself.
There's a small optimization here that we'll utilize since it might be a fairly common
case. When the input and output channel counts are the same, we'll read straight into the
@@ -71740,6 +74244,19 @@ static void ma_engine_node_process_pcm_frames__general(ma_engine_node* pEngineNo
}
}
+ /*
+ If we're using smoothing, we won't be applying volume via the spatializer, but instead from a ma_gainer. In this case
+ we'll want to apply our volume now.
+ */
+ if (isVolumeSmoothingEnabled) {
+ if (isWorkingBufferValid) {
+ ma_gainer_process_pcm_frames(&pEngineNode->volumeGainer, pWorkingBuffer, pWorkingBuffer, framesJustProcessedOut);
+ } else {
+ ma_gainer_process_pcm_frames(&pEngineNode->volumeGainer, pWorkingBuffer, pRunningFramesIn, framesJustProcessedOut);
+ isWorkingBufferValid = MA_TRUE;
+ }
+ }
+
/*
If at this point we still haven't actually done anything with the working buffer we need
to just read straight from the input buffer.
@@ -71759,18 +74276,33 @@ static void ma_engine_node_process_pcm_frames__general(ma_engine_node* pEngineNo
if (pEngineNode->pinnedListenerIndex != MA_LISTENER_INDEX_CLOSEST && pEngineNode->pinnedListenerIndex < ma_engine_get_listener_count(pEngineNode->pEngine)) {
iListener = pEngineNode->pinnedListenerIndex;
} else {
- iListener = ma_engine_find_closest_listener(pEngineNode->pEngine, pEngineNode->spatializer.position.x, pEngineNode->spatializer.position.y, pEngineNode->spatializer.position.z);
+ ma_vec3f spatializerPosition = ma_spatializer_get_position(&pEngineNode->spatializer);
+ iListener = ma_engine_find_closest_listener(pEngineNode->pEngine, spatializerPosition.x, spatializerPosition.y, spatializerPosition.z);
}
ma_spatializer_process_pcm_frames(&pEngineNode->spatializer, &pEngineNode->pEngine->listeners[iListener], pRunningFramesOut, pWorkingBuffer, framesJustProcessedOut);
} else {
- /* No spatialization, but we still need to do channel conversion. */
+ /* No spatialization, but we still need to do channel conversion and master volume. */
+ float volume;
+ ma_engine_node_get_volume(pEngineNode, &volume); /* Should never fail. */
+
if (channelsIn == channelsOut) {
/* No channel conversion required. Just copy straight to the output buffer. */
- ma_copy_pcm_frames(pRunningFramesOut, pWorkingBuffer, framesJustProcessedOut, ma_format_f32, channelsOut);
+ if (isVolumeSmoothingEnabled) {
+ /* Volume has already been applied. Just copy straight to the output buffer. */
+ ma_copy_pcm_frames(pRunningFramesOut, pWorkingBuffer, framesJustProcessedOut * channelsOut, ma_format_f32, channelsOut);
+ } else {
+ /* Volume has not been applied yet. Copy and apply volume in the same pass. */
+ ma_copy_and_apply_volume_factor_f32(pRunningFramesOut, pWorkingBuffer, framesJustProcessedOut * channelsOut, volume);
+ }
} else {
/* Channel conversion required. TODO: Add support for channel maps here. */
ma_channel_map_apply_f32(pRunningFramesOut, NULL, channelsOut, pWorkingBuffer, NULL, channelsIn, framesJustProcessedOut, ma_channel_mix_mode_simple, pEngineNode->monoExpansionMode);
+
+ /* If we're using smoothing, the volume will have already been applied. */
+ if (!isVolumeSmoothingEnabled) {
+ ma_apply_volume_factor_f32(pRunningFramesOut, framesJustProcessedOut * channelsOut, volume);
+ }
}
}
@@ -71821,14 +74353,14 @@ static void ma_engine_node_process_pcm_frames__sound(ma_node* pNode, const float
}
/* If we're seeking, do so now before reading. */
- seekTarget = c89atomic_load_64(&pSound->seekTarget);
+ seekTarget = ma_atomic_load_64(&pSound->seekTarget);
if (seekTarget != MA_SEEK_TARGET_NONE) {
ma_data_source_seek_to_pcm_frame(pSound->pDataSource, seekTarget);
/* Any time-dependant effects need to have their times updated. */
ma_node_set_time(pSound, seekTarget);
- c89atomic_exchange_64(&pSound->seekTarget, MA_SEEK_TARGET_NONE);
+ ma_atomic_exchange_64(&pSound->seekTarget, MA_SEEK_TARGET_NONE);
}
/*
@@ -71873,7 +74405,7 @@ static void ma_engine_node_process_pcm_frames__sound(ma_node* pNode, const float
/* If we reached the end of the sound we'll want to mark it as at the end and stop it. This should never be returned for looping sounds. */
if (result == MA_AT_END) {
- c89atomic_exchange_32(&pSound->atEnd, MA_TRUE); /* This will be set to false in ma_sound_start(). */
+ ma_sound_set_at_end(pSound, MA_TRUE); /* This will be set to false in ma_sound_start(). */
}
pRunningFramesOut = ma_offset_pcm_frames_ptr_f32(ppFramesOut[0], totalFramesRead, ma_engine_get_channels(ma_sound_get_engine(pSound)));
@@ -71994,6 +74526,7 @@ typedef struct
size_t baseNodeOffset;
size_t resamplerOffset;
size_t spatializerOffset;
+ size_t gainerOffset;
} ma_engine_node_heap_layout;
static ma_result ma_engine_node_get_heap_layout(const ma_engine_node_config* pConfig, ma_engine_node_heap_layout* pHeapLayout)
@@ -72003,8 +74536,10 @@ static ma_result ma_engine_node_get_heap_layout(const ma_engine_node_config* pCo
ma_node_config baseNodeConfig;
ma_linear_resampler_config resamplerConfig;
ma_spatializer_config spatializerConfig;
+ ma_gainer_config gainerConfig;
ma_uint32 channelsIn;
ma_uint32 channelsOut;
+ ma_channel defaultStereoChannelMap[2] = {MA_CHANNEL_SIDE_LEFT, MA_CHANNEL_SIDE_RIGHT}; /* <-- Consistent with the default channel map of a stereo listener. Means channel conversion can run on a fast path. */
MA_ASSERT(pHeapLayout);
@@ -72054,6 +74589,10 @@ static ma_result ma_engine_node_get_heap_layout(const ma_engine_node_config* pCo
/* Spatializer. */
spatializerConfig = ma_engine_node_spatializer_config_init(&baseNodeConfig);
+ if (spatializerConfig.channelsIn == 2) {
+ spatializerConfig.pChannelMapIn = defaultStereoChannelMap;
+ }
+
result = ma_spatializer_get_heap_size(&spatializerConfig, &tempHeapSize);
if (result != MA_SUCCESS) {
return result; /* Failed to retrieve the size of the heap for the spatializer. */
@@ -72063,6 +74602,20 @@ static ma_result ma_engine_node_get_heap_layout(const ma_engine_node_config* pCo
pHeapLayout->sizeInBytes += ma_align_64(tempHeapSize);
+ /* Gainer. Will not be used if we are not using smoothing. */
+ if (pConfig->volumeSmoothTimeInPCMFrames > 0) {
+ gainerConfig = ma_gainer_config_init(channelsIn, pConfig->volumeSmoothTimeInPCMFrames);
+
+ result = ma_gainer_get_heap_size(&gainerConfig, &tempHeapSize);
+ if (result != MA_SUCCESS) {
+ return result;
+ }
+
+ pHeapLayout->gainerOffset = pHeapLayout->sizeInBytes;
+ pHeapLayout->sizeInBytes += ma_align_64(tempHeapSize);
+ }
+
+
return MA_SUCCESS;
}
@@ -72096,8 +74649,10 @@ MA_API ma_result ma_engine_node_init_preallocated(const ma_engine_node_config* p
ma_fader_config faderConfig;
ma_spatializer_config spatializerConfig;
ma_panner_config pannerConfig;
+ ma_gainer_config gainerConfig;
ma_uint32 channelsIn;
ma_uint32 channelsOut;
+ ma_channel defaultStereoChannelMap[2] = {MA_CHANNEL_SIDE_LEFT, MA_CHANNEL_SIDE_RIGHT}; /* <-- Consistent with the default channel map of a stereo listener. Means channel conversion can run on a fast path. */
if (pEngineNode == NULL) {
return MA_INVALID_ARGS;
@@ -72117,20 +74672,33 @@ MA_API ma_result ma_engine_node_init_preallocated(const ma_engine_node_config* p
pEngineNode->_pHeap = pHeap;
MA_ZERO_MEMORY(pHeap, heapLayout.sizeInBytes);
- pEngineNode->pEngine = pConfig->pEngine;
- pEngineNode->sampleRate = (pConfig->sampleRate > 0) ? pConfig->sampleRate : ma_engine_get_sample_rate(pEngineNode->pEngine);
- pEngineNode->monoExpansionMode = pConfig->monoExpansionMode;
- pEngineNode->pitch = 1;
- pEngineNode->oldPitch = 1;
- pEngineNode->oldDopplerPitch = 1;
- pEngineNode->isPitchDisabled = pConfig->isPitchDisabled;
- pEngineNode->isSpatializationDisabled = pConfig->isSpatializationDisabled;
- pEngineNode->pinnedListenerIndex = pConfig->pinnedListenerIndex;
-
+ pEngineNode->pEngine = pConfig->pEngine;
+ pEngineNode->sampleRate = (pConfig->sampleRate > 0) ? pConfig->sampleRate : ma_engine_get_sample_rate(pEngineNode->pEngine);
+ pEngineNode->volumeSmoothTimeInPCMFrames = pConfig->volumeSmoothTimeInPCMFrames;
+ pEngineNode->monoExpansionMode = pConfig->monoExpansionMode;
+ ma_atomic_float_set(&pEngineNode->volume, 1);
+ pEngineNode->pitch = 1;
+ pEngineNode->oldPitch = 1;
+ pEngineNode->oldDopplerPitch = 1;
+ pEngineNode->isPitchDisabled = pConfig->isPitchDisabled;
+ pEngineNode->isSpatializationDisabled = pConfig->isSpatializationDisabled;
+ pEngineNode->pinnedListenerIndex = pConfig->pinnedListenerIndex;
+ ma_atomic_float_set(&pEngineNode->fadeSettings.volumeBeg, 1);
+ ma_atomic_float_set(&pEngineNode->fadeSettings.volumeEnd, 1);
+ ma_atomic_uint64_set(&pEngineNode->fadeSettings.fadeLengthInFrames, (~(ma_uint64)0));
+ ma_atomic_uint64_set(&pEngineNode->fadeSettings.absoluteGlobalTimeInFrames, (~(ma_uint64)0)); /* <-- Indicates that the fade should start immediately. */
channelsIn = (pConfig->channelsIn != 0) ? pConfig->channelsIn : ma_engine_get_channels(pConfig->pEngine);
channelsOut = (pConfig->channelsOut != 0) ? pConfig->channelsOut : ma_engine_get_channels(pConfig->pEngine);
+ /*
+ If the sample rate of the sound is different to the engine, make sure pitching is enabled so that the resampler
+ is activated. Not doing this will result in the sound not being resampled if MA_SOUND_FLAG_NO_PITCH is used.
+ */
+ if (pEngineNode->sampleRate != ma_engine_get_sample_rate(pEngineNode->pEngine)) {
+ pEngineNode->isPitchDisabled = MA_FALSE;
+ }
+
/* Base node. */
baseNodeConfig = ma_engine_node_base_node_config_init(pConfig);
@@ -72177,6 +74745,10 @@ MA_API ma_result ma_engine_node_init_preallocated(const ma_engine_node_config* p
spatializerConfig = ma_engine_node_spatializer_config_init(&baseNodeConfig);
spatializerConfig.gainSmoothTimeInFrames = pEngineNode->pEngine->gainSmoothTimeInFrames;
+ if (spatializerConfig.channelsIn == 2) {
+ spatializerConfig.pChannelMapIn = defaultStereoChannelMap;
+ }
+
result = ma_spatializer_init_preallocated(&spatializerConfig, ma_offset_ptr(pHeap, heapLayout.spatializerOffset), &pEngineNode->spatializer);
if (result != MA_SUCCESS) {
goto error2;
@@ -72194,6 +74766,18 @@ MA_API ma_result ma_engine_node_init_preallocated(const ma_engine_node_config* p
goto error3;
}
+
+ /* We'll need a gainer for smoothing out volume changes if we have a non-zero smooth time. We apply this before converting to the output channel count. */
+ if (pConfig->volumeSmoothTimeInPCMFrames > 0) {
+ gainerConfig = ma_gainer_config_init(channelsIn, pConfig->volumeSmoothTimeInPCMFrames);
+
+ result = ma_gainer_init_preallocated(&gainerConfig, ma_offset_ptr(pHeap, heapLayout.gainerOffset), &pEngineNode->volumeGainer);
+ if (result != MA_SUCCESS) {
+ goto error3;
+ }
+ }
+
+
return MA_SUCCESS;
/* No need for allocation callbacks here because we use a preallocated heap. */
@@ -72242,6 +74826,10 @@ MA_API void ma_engine_node_uninit(ma_engine_node* pEngineNode, const ma_allocati
ma_node_uninit(&pEngineNode->baseNode, pAllocationCallbacks);
/* Now that the node has been uninitialized we can safely uninitialize the rest. */
+ if (pEngineNode->volumeSmoothTimeInPCMFrames > 0) {
+ ma_gainer_uninit(&pEngineNode->volumeGainer, pAllocationCallbacks);
+ }
+
ma_spatializer_uninit(&pEngineNode->spatializer, pAllocationCallbacks);
ma_linear_resampler_uninit(&pEngineNode->resampler, pAllocationCallbacks);
@@ -72365,6 +74953,9 @@ MA_API ma_result ma_engine_init(const ma_engine_config* pConfig, ma_engine* pEng
}
pEngine->monoExpansionMode = engineConfig.monoExpansionMode;
+ pEngine->defaultVolumeSmoothTimeInPCMFrames = engineConfig.defaultVolumeSmoothTimeInPCMFrames;
+ pEngine->onProcess = engineConfig.onProcess;
+ pEngine->pProcessUserData = engineConfig.pProcessUserData;
ma_allocation_callbacks_init_copy(&pEngine->allocationCallbacks, &engineConfig.allocationCallbacks);
#if !defined(MA_NO_RESOURCE_MANAGER)
@@ -72391,7 +74982,7 @@ MA_API ma_result ma_engine_init(const ma_engine_config* pConfig, ma_engine* pEng
deviceConfig.playback.format = ma_format_f32;
deviceConfig.playback.channels = engineConfig.channels;
deviceConfig.sampleRate = engineConfig.sampleRate;
- deviceConfig.dataCallback = ma_engine_data_callback_internal;
+ deviceConfig.dataCallback = (engineConfig.dataCallback != NULL) ? engineConfig.dataCallback : ma_engine_data_callback_internal;
deviceConfig.pUserData = pEngine;
deviceConfig.notificationCallback = engineConfig.notificationCallback;
deviceConfig.periodSizeInFrames = engineConfig.periodSizeInFrames;
@@ -72491,7 +75082,7 @@ MA_API ma_result ma_engine_init(const ma_engine_config* pConfig, ma_engine* pEng
Temporarily disabled. There is a subtle bug here where front-left and front-right
will be used by the device's channel map, but this is not what we want to use for
spatialization. Instead we want to use side-left and side-right. I need to figure
- out a better solution for this. For now, disabling the user of device channel maps.
+ out a better solution for this. For now, disabling the use of device channel maps.
*/
/*listenerConfig.pChannelMapOut = pEngine->pDevice->playback.channelMap;*/
}
@@ -72663,7 +75254,27 @@ MA_API void ma_engine_uninit(ma_engine* pEngine)
MA_API ma_result ma_engine_read_pcm_frames(ma_engine* pEngine, void* pFramesOut, ma_uint64 frameCount, ma_uint64* pFramesRead)
{
- return ma_node_graph_read_pcm_frames(&pEngine->nodeGraph, pFramesOut, frameCount, pFramesRead);
+ ma_result result;
+ ma_uint64 framesRead = 0;
+
+ if (pFramesRead != NULL) {
+ *pFramesRead = 0;
+ }
+
+ result = ma_node_graph_read_pcm_frames(&pEngine->nodeGraph, pFramesOut, frameCount, &framesRead);
+ if (result != MA_SUCCESS) {
+ return result;
+ }
+
+ if (pFramesRead != NULL) {
+ *pFramesRead = framesRead;
+ }
+
+ if (pEngine->onProcess) {
+ pEngine->onProcess(pEngine->pProcessUserData, (float*)pFramesOut, framesRead); /* Safe cast to float* because the engine always works on floating point samples. */
+ }
+
+ return MA_SUCCESS;
}
MA_API ma_node_graph* ma_engine_get_node_graph(ma_engine* pEngine)
@@ -72737,16 +75348,36 @@ MA_API ma_node* ma_engine_get_endpoint(ma_engine* pEngine)
return ma_node_graph_get_endpoint(&pEngine->nodeGraph);
}
-MA_API ma_uint64 ma_engine_get_time(const ma_engine* pEngine)
+MA_API ma_uint64 ma_engine_get_time_in_pcm_frames(const ma_engine* pEngine)
{
return ma_node_graph_get_time(&pEngine->nodeGraph);
}
-MA_API ma_result ma_engine_set_time(ma_engine* pEngine, ma_uint64 globalTime)
+MA_API ma_uint64 ma_engine_get_time_in_milliseconds(const ma_engine* pEngine)
+{
+ return ma_engine_get_time_in_pcm_frames(pEngine) * 1000 / ma_engine_get_sample_rate(pEngine);
+}
+
+MA_API ma_result ma_engine_set_time_in_pcm_frames(ma_engine* pEngine, ma_uint64 globalTime)
{
return ma_node_graph_set_time(&pEngine->nodeGraph, globalTime);
}
+MA_API ma_result ma_engine_set_time_in_milliseconds(ma_engine* pEngine, ma_uint64 globalTime)
+{
+ return ma_engine_set_time_in_pcm_frames(pEngine, globalTime * ma_engine_get_sample_rate(pEngine) / 1000);
+}
+
+MA_API ma_uint64 ma_engine_get_time(const ma_engine* pEngine)
+{
+ return ma_engine_get_time_in_pcm_frames(pEngine);
+}
+
+MA_API ma_result ma_engine_set_time(ma_engine* pEngine, ma_uint64 globalTime)
+{
+ return ma_engine_set_time_in_pcm_frames(pEngine, globalTime);
+}
+
MA_API ma_uint32 ma_engine_get_channels(const ma_engine* pEngine)
{
return ma_node_graph_get_channels(&pEngine->nodeGraph);
@@ -72829,13 +75460,23 @@ MA_API ma_result ma_engine_set_volume(ma_engine* pEngine, float volume)
return ma_node_set_output_bus_volume(ma_node_graph_get_endpoint(&pEngine->nodeGraph), 0, volume);
}
-MA_API ma_result ma_engine_set_gain_db(ma_engine* pEngine, float gainDB)
+MA_API float ma_engine_get_volume(ma_engine* pEngine)
{
if (pEngine == NULL) {
- return MA_INVALID_ARGS;
+ return 0;
}
- return ma_node_set_output_bus_volume(ma_node_graph_get_endpoint(&pEngine->nodeGraph), 0, ma_volume_db_to_linear(gainDB));
+ return ma_node_get_output_bus_volume(ma_node_graph_get_endpoint(&pEngine->nodeGraph), 0);
+}
+
+MA_API ma_result ma_engine_set_gain_db(ma_engine* pEngine, float gainDB)
+{
+ return ma_engine_set_volume(pEngine, ma_volume_db_to_linear(gainDB));
+}
+
+MA_API float ma_engine_get_gain_db(ma_engine* pEngine)
+{
+ return ma_volume_linear_to_db(ma_engine_get_volume(pEngine));
}
@@ -72861,7 +75502,7 @@ MA_API ma_uint32 ma_engine_find_closest_listener(const ma_engine* pEngine, float
iListenerClosest = 0;
for (iListener = 0; iListener < pEngine->listenerCount; iListener += 1) {
if (ma_engine_listener_is_enabled(pEngine, iListener)) {
- float len2 = ma_vec3f_len2(ma_vec3f_sub(pEngine->listeners[iListener].position, ma_vec3f_init_3f(absolutePosX, absolutePosY, absolutePosZ)));
+ float len2 = ma_vec3f_len2(ma_vec3f_sub(ma_spatializer_listener_get_position(&pEngine->listeners[iListener]), ma_vec3f_init_3f(absolutePosX, absolutePosY, absolutePosZ)));
if (closestLen2 > len2) {
closestLen2 = len2;
iListenerClosest = iListener;
@@ -72950,6 +75591,10 @@ MA_API void ma_engine_listener_get_cone(const ma_engine* pEngine, ma_uint32 list
*pOuterGain = 0;
}
+ if (pEngine == NULL || listenerIndex >= pEngine->listenerCount) {
+ return;
+ }
+
ma_spatializer_listener_get_cone(&pEngine->listeners[listenerIndex], pInnerAngleInRadians, pOuterAngleInRadians, pOuterGain);
}
@@ -73030,7 +75675,7 @@ MA_API ma_result ma_engine_play_sound_ex(ma_engine* pEngine, const char* pFilePa
is uninitialize it and reinitialize it. All we're doing is recycling memory.
*/
pSound = pNextSound;
- c89atomic_fetch_sub_32(&pEngine->inlinedSoundCount, 1);
+ ma_atomic_fetch_sub_32(&pEngine->inlinedSoundCount, 1);
break;
}
}
@@ -73101,11 +75746,11 @@ MA_API ma_result ma_engine_play_sound_ex(ma_engine* pEngine, const char* pFilePa
result = ma_sound_start(&pSound->sound);
if (result != MA_SUCCESS) {
/* Failed to start the sound. We need to mark it for recycling and return an error. */
- c89atomic_exchange_32(&pSound->sound.atEnd, MA_TRUE);
+ ma_atomic_exchange_32(&pSound->sound.atEnd, MA_TRUE);
return result;
}
- c89atomic_fetch_add_32(&pEngine->inlinedSoundCount, 1);
+ ma_atomic_fetch_add_32(&pEngine->inlinedSoundCount, 1);
return result;
}
@@ -73160,9 +75805,14 @@ static ma_result ma_sound_init_from_data_source_internal(ma_engine* pEngine, con
source that provides this information upfront.
*/
engineNodeConfig = ma_engine_node_config_init(pEngine, type, pConfig->flags);
- engineNodeConfig.channelsIn = pConfig->channelsIn;
- engineNodeConfig.channelsOut = pConfig->channelsOut;
- engineNodeConfig.monoExpansionMode = pConfig->monoExpansionMode;
+ engineNodeConfig.channelsIn = pConfig->channelsIn;
+ engineNodeConfig.channelsOut = pConfig->channelsOut;
+ engineNodeConfig.volumeSmoothTimeInPCMFrames = pConfig->volumeSmoothTimeInPCMFrames;
+ engineNodeConfig.monoExpansionMode = pConfig->monoExpansionMode;
+
+ if (engineNodeConfig.volumeSmoothTimeInPCMFrames == 0) {
+ engineNodeConfig.volumeSmoothTimeInPCMFrames = pEngine->defaultVolumeSmoothTimeInPCMFrames;
+ }
/* If we're loading from a data source the input channel count needs to be the data source's native channel count. */
if (pConfig->pDataSource != NULL) {
@@ -73243,8 +75893,11 @@ MA_API ma_result ma_sound_init_from_file_internal(ma_engine* pEngine, const ma_s
return MA_OUT_OF_MEMORY;
}
- notifications = ma_resource_manager_pipeline_notifications_init();
- notifications.done.pFence = pConfig->pDoneFence;
+ /* Removed in 0.12. Set pDoneFence on the notifications. */
+ notifications = pConfig->initNotifications;
+ if (pConfig->pDoneFence != NULL && notifications.done.pFence == NULL) {
+ notifications.done.pFence = pConfig->pDoneFence;
+ }
/*
We must wrap everything around the fence if one was specified. This ensures ma_fence_wait() does
@@ -73292,21 +75945,35 @@ MA_API ma_result ma_sound_init_from_file_internal(ma_engine* pEngine, const ma_s
MA_API ma_result ma_sound_init_from_file(ma_engine* pEngine, const char* pFilePath, ma_uint32 flags, ma_sound_group* pGroup, ma_fence* pDoneFence, ma_sound* pSound)
{
- ma_sound_config config = ma_sound_config_init_2(pEngine);
+ ma_sound_config config;
+
+ if (pFilePath == NULL) {
+ return MA_INVALID_ARGS;
+ }
+
+ config = ma_sound_config_init_2(pEngine);
config.pFilePath = pFilePath;
config.flags = flags;
config.pInitialAttachment = pGroup;
config.pDoneFence = pDoneFence;
+
return ma_sound_init_ex(pEngine, &config, pSound);
}
MA_API ma_result ma_sound_init_from_file_w(ma_engine* pEngine, const wchar_t* pFilePath, ma_uint32 flags, ma_sound_group* pGroup, ma_fence* pDoneFence, ma_sound* pSound)
{
- ma_sound_config config = ma_sound_config_init_2(pEngine);
+ ma_sound_config config;
+
+ if (pFilePath == NULL) {
+ return MA_INVALID_ARGS;
+ }
+
+ config = ma_sound_config_init_2(pEngine);
config.pFilePathW = pFilePath;
config.flags = flags;
config.pInitialAttachment = pGroup;
config.pDoneFence = pDoneFence;
+
return ma_sound_init_ex(pEngine, &config, pSound);
}
@@ -73331,7 +75998,7 @@ MA_API ma_result ma_sound_init_copy(ma_engine* pEngine, const ma_sound* pExistin
/*
We need to make a clone of the data source. If the data source is not a data buffer (i.e. a stream)
- the this will fail.
+ this will fail.
*/
pSound->pResourceManagerDataSource = (ma_resource_manager_data_source*)ma_malloc(sizeof(*pSound->pResourceManagerDataSource), &pEngine->allocationCallbacks);
if (pSound->pResourceManagerDataSource == NULL) {
@@ -73345,10 +76012,11 @@ MA_API ma_result ma_sound_init_copy(ma_engine* pEngine, const ma_sound* pExistin
}
config = ma_sound_config_init_2(pEngine);
- config.pDataSource = pSound->pResourceManagerDataSource;
- config.flags = flags;
- config.pInitialAttachment = pGroup;
- config.monoExpansionMode = pExistingSound->engineNode.monoExpansionMode;
+ config.pDataSource = pSound->pResourceManagerDataSource;
+ config.flags = flags;
+ config.pInitialAttachment = pGroup;
+ config.monoExpansionMode = pExistingSound->engineNode.monoExpansionMode;
+ config.volumeSmoothTimeInPCMFrames = pExistingSound->engineNode.volumeSmoothTimeInPCMFrames;
result = ma_sound_init_from_data_source_internal(pEngine, &config, pSound);
if (result != MA_SUCCESS) {
@@ -73358,6 +76026,9 @@ MA_API ma_result ma_sound_init_copy(ma_engine* pEngine, const ma_sound* pExistin
return result;
}
+ /* Make sure the sound is marked as the owner of the data source or else it will never get uninitialized. */
+ pSound->ownsDataSource = MA_TRUE;
+
return MA_SUCCESS;
}
#endif
@@ -73384,6 +76055,9 @@ MA_API ma_result ma_sound_init_ex(ma_engine* pEngine, const ma_sound_config* pCo
return MA_INVALID_ARGS;
}
+ pSound->endCallback = pConfig->endCallback;
+ pSound->pEndCallbackUserData = pConfig->pEndCallbackUserData;
+
/* We need to load the sound differently depending on whether or not we're loading from a file. */
#ifndef MA_NO_RESOURCE_MANAGER
if (pConfig->pFilePath != NULL || pConfig->pFilePathW != NULL) {
@@ -73462,7 +76136,7 @@ MA_API ma_result ma_sound_start(ma_sound* pSound)
}
/* Make sure we clear the end indicator. */
- c89atomic_exchange_32(&pSound->atEnd, MA_FALSE);
+ ma_atomic_exchange_32(&pSound->atEnd, MA_FALSE);
}
/* Make sure the sound is started. If there's a start delay, the sound won't actually start until the start time is reached. */
@@ -73483,23 +76157,51 @@ MA_API ma_result ma_sound_stop(ma_sound* pSound)
return MA_SUCCESS;
}
+MA_API ma_result ma_sound_stop_with_fade_in_pcm_frames(ma_sound* pSound, ma_uint64 fadeLengthInFrames)
+{
+ if (pSound == NULL) {
+ return MA_INVALID_ARGS;
+ }
+
+ /* Stopping with a fade out requires us to schedule the stop into the future by the fade length. */
+ ma_sound_set_stop_time_with_fade_in_pcm_frames(pSound, ma_engine_get_time_in_pcm_frames(ma_sound_get_engine(pSound)) + fadeLengthInFrames, fadeLengthInFrames);
+
+ return MA_SUCCESS;
+}
+
+MA_API ma_result ma_sound_stop_with_fade_in_milliseconds(ma_sound* pSound, ma_uint64 fadeLengthInMilliseconds)
+{
+ ma_uint64 sampleRate;
+
+ if (pSound == NULL) {
+ return MA_INVALID_ARGS;
+ }
+
+ sampleRate = ma_engine_get_sample_rate(ma_sound_get_engine(pSound));
+
+ return ma_sound_stop_with_fade_in_pcm_frames(pSound, (fadeLengthInMilliseconds * sampleRate) / 1000);
+}
+
MA_API void ma_sound_set_volume(ma_sound* pSound, float volume)
{
if (pSound == NULL) {
return;
}
- /* The volume is controlled via the output bus. */
- ma_node_set_output_bus_volume(pSound, 0, volume);
+ ma_engine_node_set_volume(&pSound->engineNode, volume);
}
MA_API float ma_sound_get_volume(const ma_sound* pSound)
{
+ float volume = 0;
+
if (pSound == NULL) {
return 0;
}
- return ma_node_get_output_bus_volume(pSound, 0);
+ ma_engine_node_get_volume(&pSound->engineNode, &volume);
+
+ return volume;
}
MA_API void ma_sound_set_pan(ma_sound* pSound, float pan)
@@ -73548,7 +76250,7 @@ MA_API void ma_sound_set_pitch(ma_sound* pSound, float pitch)
return;
}
- c89atomic_exchange_explicit_f32(&pSound->engineNode.pitch, pitch, c89atomic_memory_order_release);
+ ma_atomic_exchange_explicit_f32(&pSound->engineNode.pitch, pitch, ma_atomic_memory_order_release);
}
MA_API float ma_sound_get_pitch(const ma_sound* pSound)
@@ -73557,7 +76259,7 @@ MA_API float ma_sound_get_pitch(const ma_sound* pSound)
return 0;
}
- return c89atomic_load_f32(&pSound->engineNode.pitch); /* Naughty const-cast for this. */
+ return ma_atomic_load_f32(&pSound->engineNode.pitch); /* Naughty const-cast for this. */
}
MA_API void ma_sound_set_spatialization_enabled(ma_sound* pSound, ma_bool32 enabled)
@@ -73566,7 +76268,7 @@ MA_API void ma_sound_set_spatialization_enabled(ma_sound* pSound, ma_bool32 enab
return;
}
- c89atomic_exchange_explicit_32(&pSound->engineNode.isSpatializationDisabled, !enabled, c89atomic_memory_order_release);
+ ma_atomic_exchange_explicit_32(&pSound->engineNode.isSpatializationDisabled, !enabled, ma_atomic_memory_order_release);
}
MA_API ma_bool32 ma_sound_is_spatialization_enabled(const ma_sound* pSound)
@@ -73584,7 +76286,7 @@ MA_API void ma_sound_set_pinned_listener_index(ma_sound* pSound, ma_uint32 liste
return;
}
- c89atomic_exchange_explicit_32(&pSound->engineNode.pinnedListenerIndex, listenerIndex, c89atomic_memory_order_release);
+ ma_atomic_exchange_explicit_32(&pSound->engineNode.pinnedListenerIndex, listenerIndex, ma_atomic_memory_order_release);
}
MA_API ma_uint32 ma_sound_get_pinned_listener_index(const ma_sound* pSound)
@@ -73593,7 +76295,7 @@ MA_API ma_uint32 ma_sound_get_pinned_listener_index(const ma_sound* pSound)
return MA_LISTENER_INDEX_CLOSEST;
}
- return c89atomic_load_explicit_32(&pSound->engineNode.pinnedListenerIndex, c89atomic_memory_order_acquire);
+ return ma_atomic_load_explicit_32(&pSound->engineNode.pinnedListenerIndex, ma_atomic_memory_order_acquire);
}
MA_API ma_uint32 ma_sound_get_listener_index(const ma_sound* pSound)
@@ -73835,6 +76537,10 @@ MA_API void ma_sound_get_cone(const ma_sound* pSound, float* pInnerAngleInRadian
*pOuterGain = 0;
}
+ if (pSound == NULL) {
+ return;
+ }
+
ma_spatializer_get_cone(&pSound->engineNode.spatializer, pInnerAngleInRadians, pOuterAngleInRadians, pOuterGain);
}
@@ -73881,7 +76587,7 @@ MA_API void ma_sound_set_fade_in_pcm_frames(ma_sound* pSound, float volumeBeg, f
return;
}
- ma_fader_set_fade(&pSound->engineNode.fader, volumeBeg, volumeEnd, fadeLengthInFrames);
+ ma_sound_set_fade_start_in_pcm_frames(pSound, volumeBeg, volumeEnd, fadeLengthInFrames, (~(ma_uint64)0));
}
MA_API void ma_sound_set_fade_in_milliseconds(ma_sound* pSound, float volumeBeg, float volumeEnd, ma_uint64 fadeLengthInMilliseconds)
@@ -73893,7 +76599,37 @@ MA_API void ma_sound_set_fade_in_milliseconds(ma_sound* pSound, float volumeBeg,
ma_sound_set_fade_in_pcm_frames(pSound, volumeBeg, volumeEnd, (fadeLengthInMilliseconds * pSound->engineNode.fader.config.sampleRate) / 1000);
}
-MA_API float ma_sound_get_current_fade_volume(ma_sound* pSound)
+MA_API void ma_sound_set_fade_start_in_pcm_frames(ma_sound* pSound, float volumeBeg, float volumeEnd, ma_uint64 fadeLengthInFrames, ma_uint64 absoluteGlobalTimeInFrames)
+{
+ if (pSound == NULL) {
+ return;
+ }
+
+ /*
+ We don't want to update the fader at this point because we need to use the engine's current time
+ to derive the fader's start offset. The timer is being updated on the audio thread so in order to
+ do this as accurately as possible we'll need to defer this to the audio thread.
+ */
+ ma_atomic_float_set(&pSound->engineNode.fadeSettings.volumeBeg, volumeBeg);
+ ma_atomic_float_set(&pSound->engineNode.fadeSettings.volumeEnd, volumeEnd);
+ ma_atomic_uint64_set(&pSound->engineNode.fadeSettings.fadeLengthInFrames, fadeLengthInFrames);
+ ma_atomic_uint64_set(&pSound->engineNode.fadeSettings.absoluteGlobalTimeInFrames, absoluteGlobalTimeInFrames);
+}
+
+MA_API void ma_sound_set_fade_start_in_milliseconds(ma_sound* pSound, float volumeBeg, float volumeEnd, ma_uint64 fadeLengthInMilliseconds, ma_uint64 absoluteGlobalTimeInMilliseconds)
+{
+ ma_uint32 sampleRate;
+
+ if (pSound == NULL) {
+ return;
+ }
+
+ sampleRate = ma_engine_get_sample_rate(ma_sound_get_engine(pSound));
+
+ ma_sound_set_fade_start_in_pcm_frames(pSound, volumeBeg, volumeEnd, (fadeLengthInMilliseconds * sampleRate) / 1000, (absoluteGlobalTimeInMilliseconds * sampleRate) / 1000);
+}
+
+MA_API float ma_sound_get_current_fade_volume(const ma_sound* pSound)
{
if (pSound == NULL) {
return MA_INVALID_ARGS;
@@ -73926,7 +76662,7 @@ MA_API void ma_sound_set_stop_time_in_pcm_frames(ma_sound* pSound, ma_uint64 abs
return;
}
- ma_node_set_state_time(pSound, ma_node_state_stopped, absoluteGlobalTimeInFrames);
+ ma_sound_set_stop_time_with_fade_in_pcm_frames(pSound, absoluteGlobalTimeInFrames, 0);
}
MA_API void ma_sound_set_stop_time_in_milliseconds(ma_sound* pSound, ma_uint64 absoluteGlobalTimeInMilliseconds)
@@ -73938,13 +76674,43 @@ MA_API void ma_sound_set_stop_time_in_milliseconds(ma_sound* pSound, ma_uint64 a
ma_sound_set_stop_time_in_pcm_frames(pSound, absoluteGlobalTimeInMilliseconds * ma_engine_get_sample_rate(ma_sound_get_engine(pSound)) / 1000);
}
+MA_API void ma_sound_set_stop_time_with_fade_in_pcm_frames(ma_sound* pSound, ma_uint64 stopAbsoluteGlobalTimeInFrames, ma_uint64 fadeLengthInFrames)
+{
+ if (pSound == NULL) {
+ return;
+ }
+
+ if (fadeLengthInFrames > 0) {
+ if (fadeLengthInFrames > stopAbsoluteGlobalTimeInFrames) {
+ fadeLengthInFrames = stopAbsoluteGlobalTimeInFrames;
+ }
+
+ ma_sound_set_fade_start_in_pcm_frames(pSound, -1, 0, fadeLengthInFrames, stopAbsoluteGlobalTimeInFrames - fadeLengthInFrames);
+ }
+
+ ma_node_set_state_time(pSound, ma_node_state_stopped, stopAbsoluteGlobalTimeInFrames);
+}
+
+MA_API void ma_sound_set_stop_time_with_fade_in_milliseconds(ma_sound* pSound, ma_uint64 stopAbsoluteGlobalTimeInMilliseconds, ma_uint64 fadeLengthInMilliseconds)
+{
+ ma_uint32 sampleRate;
+
+ if (pSound == NULL) {
+ return;
+ }
+
+ sampleRate = ma_engine_get_sample_rate(ma_sound_get_engine(pSound));
+
+ ma_sound_set_stop_time_with_fade_in_pcm_frames(pSound, (stopAbsoluteGlobalTimeInMilliseconds * sampleRate) / 1000, (fadeLengthInMilliseconds * sampleRate) / 1000);
+}
+
MA_API ma_bool32 ma_sound_is_playing(const ma_sound* pSound)
{
if (pSound == NULL) {
return MA_FALSE;
}
- return ma_node_get_state_by_time(pSound, ma_engine_get_time(ma_sound_get_engine(pSound))) == ma_node_state_started;
+ return ma_node_get_state_by_time(pSound, ma_engine_get_time_in_pcm_frames(ma_sound_get_engine(pSound))) == ma_node_state_started;
}
MA_API ma_uint64 ma_sound_get_time_in_pcm_frames(const ma_sound* pSound)
@@ -73956,6 +76722,11 @@ MA_API ma_uint64 ma_sound_get_time_in_pcm_frames(const ma_sound* pSound)
return ma_node_get_time(pSound);
}
+MA_API ma_uint64 ma_sound_get_time_in_milliseconds(const ma_sound* pSound)
+{
+ return ma_sound_get_time_in_pcm_frames(pSound) * 1000 / ma_engine_get_sample_rate(ma_sound_get_engine(pSound));
+}
+
MA_API void ma_sound_set_looping(ma_sound* pSound, ma_bool32 isLooping)
{
if (pSound == NULL) {
@@ -73996,7 +76767,7 @@ MA_API ma_bool32 ma_sound_at_end(const ma_sound* pSound)
return MA_FALSE;
}
- return c89atomic_load_32(&pSound->atEnd);
+ return ma_sound_get_at_end(pSound);
}
MA_API ma_result ma_sound_seek_to_pcm_frame(ma_sound* pSound, ma_uint64 frameIndex)
@@ -74011,7 +76782,7 @@ MA_API ma_result ma_sound_seek_to_pcm_frame(ma_sound* pSound, ma_uint64 frameInd
}
/* We can't be seeking while reading at the same time. We just set the seek target and get the mixing thread to do the actual seek. */
- c89atomic_exchange_64(&pSound->seekTarget, frameIndex);
+ ma_atomic_exchange_64(&pSound->seekTarget, frameIndex);
return MA_SUCCESS;
}
@@ -74051,6 +76822,8 @@ MA_API ma_result ma_sound_get_data_format(ma_sound* pSound, ma_format* pFormat,
MA_API ma_result ma_sound_get_cursor_in_pcm_frames(ma_sound* pSound, ma_uint64* pCursor)
{
+ ma_uint64 seekTarget;
+
if (pSound == NULL) {
return MA_INVALID_ARGS;
}
@@ -74060,7 +76833,13 @@ MA_API ma_result ma_sound_get_cursor_in_pcm_frames(ma_sound* pSound, ma_uint64*
return MA_INVALID_OPERATION;
}
- return ma_data_source_get_cursor_in_pcm_frames(pSound->pDataSource, pCursor);
+ seekTarget = ma_atomic_load_64(&pSound->seekTarget);
+ if (seekTarget != MA_SEEK_TARGET_NONE) {
+ *pCursor = seekTarget;
+ return MA_SUCCESS;
+ } else {
+ return ma_data_source_get_cursor_in_pcm_frames(pSound->pDataSource, pCursor);
+ }
}
MA_API ma_result ma_sound_get_length_in_pcm_frames(ma_sound* pSound, ma_uint64* pLength)
@@ -74078,31 +76857,60 @@ MA_API ma_result ma_sound_get_length_in_pcm_frames(ma_sound* pSound, ma_uint64*
}
MA_API ma_result ma_sound_get_cursor_in_seconds(ma_sound* pSound, float* pCursor)
+{
+ ma_result result;
+ ma_uint64 cursorInPCMFrames;
+ ma_uint32 sampleRate;
+
+ if (pCursor != NULL) {
+ *pCursor = 0;
+ }
+
+ result = ma_sound_get_cursor_in_pcm_frames(pSound, &cursorInPCMFrames);
+ if (result != MA_SUCCESS) {
+ return result;
+ }
+
+ result = ma_sound_get_data_format(pSound, NULL, NULL, &sampleRate, NULL, 0);
+ if (result != MA_SUCCESS) {
+ return result;
+ }
+
+ /* VC6 does not support division of unsigned 64-bit integers with floating point numbers. Need to use a signed number. This shouldn't effect anything in practice. */
+ *pCursor = (ma_int64)cursorInPCMFrames / (float)sampleRate;
+
+ return MA_SUCCESS;
+}
+
+MA_API ma_result ma_sound_get_length_in_seconds(ma_sound* pSound, float* pLength)
{
if (pSound == NULL) {
return MA_INVALID_ARGS;
}
- /* The notion of a cursor is only valid for sounds that are backed by a data source. */
+ /* The notion of a sound length is only valid for sounds that are backed by a data source. */
if (pSound->pDataSource == NULL) {
return MA_INVALID_OPERATION;
}
- return ma_data_source_get_cursor_in_seconds(pSound->pDataSource, pCursor);
+ return ma_data_source_get_length_in_seconds(pSound->pDataSource, pLength);
}
-MA_API ma_result ma_sound_get_length_in_seconds(ma_sound* pSound, float* pLength)
+MA_API ma_result ma_sound_set_end_callback(ma_sound* pSound, ma_sound_end_proc callback, void* pUserData)
{
if (pSound == NULL) {
return MA_INVALID_ARGS;
}
- /* The notion of a sound length is only valid for sounds that are backed by a data source. */
+ /* The notion of an end is only valid for sounds that are backed by a data source. */
if (pSound->pDataSource == NULL) {
return MA_INVALID_OPERATION;
}
- return ma_data_source_get_length_in_seconds(pSound->pDataSource, pLength);
+ pSound->endCallback = callback;
+ pSound->pEndCallbackUserData = pUserData;
+
+ return MA_SUCCESS;
}
@@ -74419,167 +77227,135 @@ MA_API ma_uint64 ma_sound_group_get_time_in_pcm_frames(const ma_sound_group* pGr
Auto Generated
==============
-All code below is auto-generated from a tool. This mostly consists of decoding backend implementations such as dr_wav, dr_flac, etc. If you find a bug in the
+All code below is auto-generated from a tool. This mostly consists of decoding backend implementations such as ma_dr_wav, ma_dr_flac, etc. If you find a bug in the
code below please report the bug to the respective repository for the relevant project (probably dr_libs).
***************************************************************************************************************************************************************
**************************************************************************************************************************************************************/
#if !defined(MA_NO_WAV) && (!defined(MA_NO_DECODING) || !defined(MA_NO_ENCODING))
-#if !defined(DR_WAV_IMPLEMENTATION) && !defined(DRWAV_IMPLEMENTATION) /* For backwards compatibility. Will be removed in version 0.11 for cleanliness. */
+#if !defined(MA_DR_WAV_IMPLEMENTATION) && !defined(MA_DR_WAV_IMPLEMENTATION) /* For backwards compatibility. Will be removed in version 0.11 for cleanliness. */
/* dr_wav_c begin */
-#ifndef dr_wav_c
-#define dr_wav_c
+#ifndef ma_dr_wav_c
+#define ma_dr_wav_c
#ifdef __MRC__
#pragma options opt off
#endif
#include
#include
#include
-#ifndef DR_WAV_NO_STDIO
+#ifndef MA_DR_WAV_NO_STDIO
#include
-#ifndef DR_WAV_NO_WCHAR
+#ifndef MA_DR_WAV_NO_WCHAR
#include
#endif
#endif
-#ifndef DRWAV_ASSERT
+#ifndef MA_DR_WAV_ASSERT
#include
-#define DRWAV_ASSERT(expression) assert(expression)
-#endif
-#ifndef DRWAV_MALLOC
-#define DRWAV_MALLOC(sz) malloc((sz))
-#endif
-#ifndef DRWAV_REALLOC
-#define DRWAV_REALLOC(p, sz) realloc((p), (sz))
+#define MA_DR_WAV_ASSERT(expression) assert(expression)
#endif
-#ifndef DRWAV_FREE
-#define DRWAV_FREE(p) free((p))
+#ifndef MA_DR_WAV_MALLOC
+#define MA_DR_WAV_MALLOC(sz) malloc((sz))
#endif
-#ifndef DRWAV_COPY_MEMORY
-#define DRWAV_COPY_MEMORY(dst, src, sz) memcpy((dst), (src), (sz))
+#ifndef MA_DR_WAV_REALLOC
+#define MA_DR_WAV_REALLOC(p, sz) realloc((p), (sz))
#endif
-#ifndef DRWAV_ZERO_MEMORY
-#define DRWAV_ZERO_MEMORY(p, sz) memset((p), 0, (sz))
+#ifndef MA_DR_WAV_FREE
+#define MA_DR_WAV_FREE(p) free((p))
#endif
-#ifndef DRWAV_ZERO_OBJECT
-#define DRWAV_ZERO_OBJECT(p) DRWAV_ZERO_MEMORY((p), sizeof(*p))
+#ifndef MA_DR_WAV_COPY_MEMORY
+#define MA_DR_WAV_COPY_MEMORY(dst, src, sz) memcpy((dst), (src), (sz))
#endif
-#define drwav_countof(x) (sizeof(x) / sizeof(x[0]))
-#define drwav_align(x, a) ((((x) + (a) - 1) / (a)) * (a))
-#define drwav_min(a, b) (((a) < (b)) ? (a) : (b))
-#define drwav_max(a, b) (((a) > (b)) ? (a) : (b))
-#define drwav_clamp(x, lo, hi) (drwav_max((lo), drwav_min((hi), (x))))
-#define drwav_offset_ptr(p, offset) (((drwav_uint8*)(p)) + (offset))
-#define DRWAV_MAX_SIMD_VECTOR_SIZE 64
-#if defined(__x86_64__) || defined(_M_X64)
- #define DRWAV_X64
-#elif defined(__i386) || defined(_M_IX86)
- #define DRWAV_X86
-#elif defined(__arm__) || defined(_M_ARM)
- #define DRWAV_ARM
-#endif
-#ifdef _MSC_VER
- #define DRWAV_INLINE __forceinline
-#elif defined(__GNUC__)
- #if defined(__STRICT_ANSI__)
- #define DRWAV_GNUC_INLINE_HINT __inline__
- #else
- #define DRWAV_GNUC_INLINE_HINT inline
- #endif
- #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 2)) || defined(__clang__)
- #define DRWAV_INLINE DRWAV_GNUC_INLINE_HINT __attribute__((always_inline))
- #else
- #define DRWAV_INLINE DRWAV_GNUC_INLINE_HINT
- #endif
-#elif defined(__WATCOMC__)
- #define DRWAV_INLINE __inline
-#else
- #define DRWAV_INLINE
+#ifndef MA_DR_WAV_ZERO_MEMORY
+#define MA_DR_WAV_ZERO_MEMORY(p, sz) memset((p), 0, (sz))
#endif
-#if defined(SIZE_MAX)
- #define DRWAV_SIZE_MAX SIZE_MAX
-#else
- #if defined(_WIN64) || defined(_LP64) || defined(__LP64__)
- #define DRWAV_SIZE_MAX ((drwav_uint64)0xFFFFFFFFFFFFFFFF)
- #else
- #define DRWAV_SIZE_MAX 0xFFFFFFFF
- #endif
+#ifndef MA_DR_WAV_ZERO_OBJECT
+#define MA_DR_WAV_ZERO_OBJECT(p) MA_DR_WAV_ZERO_MEMORY((p), sizeof(*p))
#endif
+#define ma_dr_wav_countof(x) (sizeof(x) / sizeof(x[0]))
+#define ma_dr_wav_align(x, a) ((((x) + (a) - 1) / (a)) * (a))
+#define ma_dr_wav_min(a, b) (((a) < (b)) ? (a) : (b))
+#define ma_dr_wav_max(a, b) (((a) > (b)) ? (a) : (b))
+#define ma_dr_wav_clamp(x, lo, hi) (ma_dr_wav_max((lo), ma_dr_wav_min((hi), (x))))
+#define ma_dr_wav_offset_ptr(p, offset) (((ma_uint8*)(p)) + (offset))
+#define MA_DR_WAV_MAX_SIMD_VECTOR_SIZE 32
+#define MA_DR_WAV_INT64_MIN ((ma_int64) ((ma_uint64)0x80000000 << 32))
+#define MA_DR_WAV_INT64_MAX ((ma_int64)(((ma_uint64)0x7FFFFFFF << 32) | 0xFFFFFFFF))
#if defined(_MSC_VER) && _MSC_VER >= 1400
- #define DRWAV_HAS_BYTESWAP16_INTRINSIC
- #define DRWAV_HAS_BYTESWAP32_INTRINSIC
- #define DRWAV_HAS_BYTESWAP64_INTRINSIC
+ #define MA_DR_WAV_HAS_BYTESWAP16_INTRINSIC
+ #define MA_DR_WAV_HAS_BYTESWAP32_INTRINSIC
+ #define MA_DR_WAV_HAS_BYTESWAP64_INTRINSIC
#elif defined(__clang__)
#if defined(__has_builtin)
#if __has_builtin(__builtin_bswap16)
- #define DRWAV_HAS_BYTESWAP16_INTRINSIC
+ #define MA_DR_WAV_HAS_BYTESWAP16_INTRINSIC
#endif
#if __has_builtin(__builtin_bswap32)
- #define DRWAV_HAS_BYTESWAP32_INTRINSIC
+ #define MA_DR_WAV_HAS_BYTESWAP32_INTRINSIC
#endif
#if __has_builtin(__builtin_bswap64)
- #define DRWAV_HAS_BYTESWAP64_INTRINSIC
+ #define MA_DR_WAV_HAS_BYTESWAP64_INTRINSIC
#endif
#endif
#elif defined(__GNUC__)
#if ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
- #define DRWAV_HAS_BYTESWAP32_INTRINSIC
- #define DRWAV_HAS_BYTESWAP64_INTRINSIC
+ #define MA_DR_WAV_HAS_BYTESWAP32_INTRINSIC
+ #define MA_DR_WAV_HAS_BYTESWAP64_INTRINSIC
#endif
#if ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))
- #define DRWAV_HAS_BYTESWAP16_INTRINSIC
+ #define MA_DR_WAV_HAS_BYTESWAP16_INTRINSIC
#endif
#endif
-DRWAV_API void drwav_version(drwav_uint32* pMajor, drwav_uint32* pMinor, drwav_uint32* pRevision)
+MA_API void ma_dr_wav_version(ma_uint32* pMajor, ma_uint32* pMinor, ma_uint32* pRevision)
{
if (pMajor) {
- *pMajor = DRWAV_VERSION_MAJOR;
+ *pMajor = MA_DR_WAV_VERSION_MAJOR;
}
if (pMinor) {
- *pMinor = DRWAV_VERSION_MINOR;
+ *pMinor = MA_DR_WAV_VERSION_MINOR;
}
if (pRevision) {
- *pRevision = DRWAV_VERSION_REVISION;
+ *pRevision = MA_DR_WAV_VERSION_REVISION;
}
}
-DRWAV_API const char* drwav_version_string(void)
+MA_API const char* ma_dr_wav_version_string(void)
{
- return DRWAV_VERSION_STRING;
+ return MA_DR_WAV_VERSION_STRING;
}
-#ifndef DRWAV_MAX_SAMPLE_RATE
-#define DRWAV_MAX_SAMPLE_RATE 384000
+#ifndef MA_DR_WAV_MAX_SAMPLE_RATE
+#define MA_DR_WAV_MAX_SAMPLE_RATE 384000
#endif
-#ifndef DRWAV_MAX_CHANNELS
-#define DRWAV_MAX_CHANNELS 256
+#ifndef MA_DR_WAV_MAX_CHANNELS
+#define MA_DR_WAV_MAX_CHANNELS 256
#endif
-#ifndef DRWAV_MAX_BITS_PER_SAMPLE
-#define DRWAV_MAX_BITS_PER_SAMPLE 64
+#ifndef MA_DR_WAV_MAX_BITS_PER_SAMPLE
+#define MA_DR_WAV_MAX_BITS_PER_SAMPLE 64
#endif
-static const drwav_uint8 drwavGUID_W64_RIFF[16] = {0x72,0x69,0x66,0x66, 0x2E,0x91, 0xCF,0x11, 0xA5,0xD6, 0x28,0xDB,0x04,0xC1,0x00,0x00};
-static const drwav_uint8 drwavGUID_W64_WAVE[16] = {0x77,0x61,0x76,0x65, 0xF3,0xAC, 0xD3,0x11, 0x8C,0xD1, 0x00,0xC0,0x4F,0x8E,0xDB,0x8A};
-static const drwav_uint8 drwavGUID_W64_FMT [16] = {0x66,0x6D,0x74,0x20, 0xF3,0xAC, 0xD3,0x11, 0x8C,0xD1, 0x00,0xC0,0x4F,0x8E,0xDB,0x8A};
-static const drwav_uint8 drwavGUID_W64_FACT[16] = {0x66,0x61,0x63,0x74, 0xF3,0xAC, 0xD3,0x11, 0x8C,0xD1, 0x00,0xC0,0x4F,0x8E,0xDB,0x8A};
-static const drwav_uint8 drwavGUID_W64_DATA[16] = {0x64,0x61,0x74,0x61, 0xF3,0xAC, 0xD3,0x11, 0x8C,0xD1, 0x00,0xC0,0x4F,0x8E,0xDB,0x8A};
-static DRWAV_INLINE int drwav__is_little_endian(void)
+static const ma_uint8 ma_dr_wavGUID_W64_RIFF[16] = {0x72,0x69,0x66,0x66, 0x2E,0x91, 0xCF,0x11, 0xA5,0xD6, 0x28,0xDB,0x04,0xC1,0x00,0x00};
+static const ma_uint8 ma_dr_wavGUID_W64_WAVE[16] = {0x77,0x61,0x76,0x65, 0xF3,0xAC, 0xD3,0x11, 0x8C,0xD1, 0x00,0xC0,0x4F,0x8E,0xDB,0x8A};
+static const ma_uint8 ma_dr_wavGUID_W64_FMT [16] = {0x66,0x6D,0x74,0x20, 0xF3,0xAC, 0xD3,0x11, 0x8C,0xD1, 0x00,0xC0,0x4F,0x8E,0xDB,0x8A};
+static const ma_uint8 ma_dr_wavGUID_W64_FACT[16] = {0x66,0x61,0x63,0x74, 0xF3,0xAC, 0xD3,0x11, 0x8C,0xD1, 0x00,0xC0,0x4F,0x8E,0xDB,0x8A};
+static const ma_uint8 ma_dr_wavGUID_W64_DATA[16] = {0x64,0x61,0x74,0x61, 0xF3,0xAC, 0xD3,0x11, 0x8C,0xD1, 0x00,0xC0,0x4F,0x8E,0xDB,0x8A};
+static MA_INLINE int ma_dr_wav__is_little_endian(void)
{
-#if defined(DRWAV_X86) || defined(DRWAV_X64)
- return DRWAV_TRUE;
+#if defined(MA_X86) || defined(MA_X64)
+ return MA_TRUE;
#elif defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && __BYTE_ORDER == __LITTLE_ENDIAN
- return DRWAV_TRUE;
+ return MA_TRUE;
#else
int n = 1;
return (*(char*)&n) == 1;
#endif
}
-static DRWAV_INLINE void drwav_bytes_to_guid(const drwav_uint8* data, drwav_uint8* guid)
+static MA_INLINE void ma_dr_wav_bytes_to_guid(const ma_uint8* data, ma_uint8* guid)
{
int i;
for (i = 0; i < 16; ++i) {
guid[i] = data[i];
}
}
-static DRWAV_INLINE drwav_uint16 drwav__bswap16(drwav_uint16 n)
+static MA_INLINE ma_uint16 ma_dr_wav__bswap16(ma_uint16 n)
{
-#ifdef DRWAV_HAS_BYTESWAP16_INTRINSIC
+#ifdef MA_DR_WAV_HAS_BYTESWAP16_INTRINSIC
#if defined(_MSC_VER)
return _byteswap_ushort(n);
#elif defined(__GNUC__) || defined(__clang__)
@@ -74592,16 +77368,16 @@ static DRWAV_INLINE drwav_uint16 drwav__bswap16(drwav_uint16 n)
((n & 0x00FF) << 8);
#endif
}
-static DRWAV_INLINE drwav_uint32 drwav__bswap32(drwav_uint32 n)
+static MA_INLINE ma_uint32 ma_dr_wav__bswap32(ma_uint32 n)
{
-#ifdef DRWAV_HAS_BYTESWAP32_INTRINSIC
+#ifdef MA_DR_WAV_HAS_BYTESWAP32_INTRINSIC
#if defined(_MSC_VER)
return _byteswap_ulong(n);
#elif defined(__GNUC__) || defined(__clang__)
- #if defined(DRWAV_ARM) && (defined(__ARM_ARCH) && __ARM_ARCH >= 6) && !defined(DRWAV_64BIT)
- drwav_uint32 r;
+ #if defined(MA_ARM) && (defined(__ARM_ARCH) && __ARM_ARCH >= 6) && !defined(MA_64BIT)
+ ma_uint32 r;
__asm__ __volatile__ (
- #if defined(DRWAV_64BIT)
+ #if defined(MA_64BIT)
"rev %w[out], %w[in]" : [out]"=r"(r) : [in]"r"(n)
#else
"rev %[out], %[in]" : [out]"=r"(r) : [in]"r"(n)
@@ -74621,9 +77397,9 @@ static DRWAV_INLINE drwav_uint32 drwav__bswap32(drwav_uint32 n)
((n & 0x000000FF) << 24);
#endif
}
-static DRWAV_INLINE drwav_uint64 drwav__bswap64(drwav_uint64 n)
+static MA_INLINE ma_uint64 ma_dr_wav__bswap64(ma_uint64 n)
{
-#ifdef DRWAV_HAS_BYTESWAP64_INTRINSIC
+#ifdef MA_DR_WAV_HAS_BYTESWAP64_INTRINSIC
#if defined(_MSC_VER)
return _byteswap_uint64(n);
#elif defined(__GNUC__) || defined(__clang__)
@@ -74632,88 +77408,82 @@ static DRWAV_INLINE drwav_uint64 drwav__bswap64(drwav_uint64 n)
#error "This compiler does not support the byte swap intrinsic."
#endif
#else
- return ((n & ((drwav_uint64)0xFF000000 << 32)) >> 56) |
- ((n & ((drwav_uint64)0x00FF0000 << 32)) >> 40) |
- ((n & ((drwav_uint64)0x0000FF00 << 32)) >> 24) |
- ((n & ((drwav_uint64)0x000000FF << 32)) >> 8) |
- ((n & ((drwav_uint64)0xFF000000 )) << 8) |
- ((n & ((drwav_uint64)0x00FF0000 )) << 24) |
- ((n & ((drwav_uint64)0x0000FF00 )) << 40) |
- ((n & ((drwav_uint64)0x000000FF )) << 56);
+ return ((n & ((ma_uint64)0xFF000000 << 32)) >> 56) |
+ ((n & ((ma_uint64)0x00FF0000 << 32)) >> 40) |
+ ((n & ((ma_uint64)0x0000FF00 << 32)) >> 24) |
+ ((n & ((ma_uint64)0x000000FF << 32)) >> 8) |
+ ((n & ((ma_uint64)0xFF000000 )) << 8) |
+ ((n & ((ma_uint64)0x00FF0000 )) << 24) |
+ ((n & ((ma_uint64)0x0000FF00 )) << 40) |
+ ((n & ((ma_uint64)0x000000FF )) << 56);
#endif
}
-static DRWAV_INLINE drwav_int16 drwav__bswap_s16(drwav_int16 n)
+static MA_INLINE ma_int16 ma_dr_wav__bswap_s16(ma_int16 n)
{
- return (drwav_int16)drwav__bswap16((drwav_uint16)n);
+ return (ma_int16)ma_dr_wav__bswap16((ma_uint16)n);
}
-static DRWAV_INLINE void drwav__bswap_samples_s16(drwav_int16* pSamples, drwav_uint64 sampleCount)
+static MA_INLINE void ma_dr_wav__bswap_samples_s16(ma_int16* pSamples, ma_uint64 sampleCount)
{
- drwav_uint64 iSample;
+ ma_uint64 iSample;
for (iSample = 0; iSample < sampleCount; iSample += 1) {
- pSamples[iSample] = drwav__bswap_s16(pSamples[iSample]);
+ pSamples[iSample] = ma_dr_wav__bswap_s16(pSamples[iSample]);
}
}
-static DRWAV_INLINE void drwav__bswap_s24(drwav_uint8* p)
+static MA_INLINE void ma_dr_wav__bswap_s24(ma_uint8* p)
{
- drwav_uint8 t;
+ ma_uint8 t;
t = p[0];
p[0] = p[2];
p[2] = t;
}
-static DRWAV_INLINE void drwav__bswap_samples_s24(drwav_uint8* pSamples, drwav_uint64 sampleCount)
+static MA_INLINE void ma_dr_wav__bswap_samples_s24(ma_uint8* pSamples, ma_uint64 sampleCount)
{
- drwav_uint64 iSample;
+ ma_uint64 iSample;
for (iSample = 0; iSample < sampleCount; iSample += 1) {
- drwav_uint8* pSample = pSamples + (iSample*3);
- drwav__bswap_s24(pSample);
+ ma_uint8* pSample = pSamples + (iSample*3);
+ ma_dr_wav__bswap_s24(pSample);
}
}
-static DRWAV_INLINE drwav_int32 drwav__bswap_s32(drwav_int32 n)
+static MA_INLINE ma_int32 ma_dr_wav__bswap_s32(ma_int32 n)
{
- return (drwav_int32)drwav__bswap32((drwav_uint32)n);
+ return (ma_int32)ma_dr_wav__bswap32((ma_uint32)n);
}
-static DRWAV_INLINE void drwav__bswap_samples_s32(drwav_int32* pSamples, drwav_uint64 sampleCount)
+static MA_INLINE void ma_dr_wav__bswap_samples_s32(ma_int32* pSamples, ma_uint64 sampleCount)
{
- drwav_uint64 iSample;
+ ma_uint64 iSample;
for (iSample = 0; iSample < sampleCount; iSample += 1) {
- pSamples[iSample] = drwav__bswap_s32(pSamples[iSample]);
+ pSamples[iSample] = ma_dr_wav__bswap_s32(pSamples[iSample]);
}
}
-static DRWAV_INLINE float drwav__bswap_f32(float n)
+static MA_INLINE ma_int64 ma_dr_wav__bswap_s64(ma_int64 n)
{
- union {
- drwav_uint32 i;
- float f;
- } x;
- x.f = n;
- x.i = drwav__bswap32(x.i);
- return x.f;
+ return (ma_int64)ma_dr_wav__bswap64((ma_uint64)n);
}
-static DRWAV_INLINE void drwav__bswap_samples_f32(float* pSamples, drwav_uint64 sampleCount)
+static MA_INLINE void ma_dr_wav__bswap_samples_s64(ma_int64* pSamples, ma_uint64 sampleCount)
{
- drwav_uint64 iSample;
+ ma_uint64 iSample;
for (iSample = 0; iSample < sampleCount; iSample += 1) {
- pSamples[iSample] = drwav__bswap_f32(pSamples[iSample]);
+ pSamples[iSample] = ma_dr_wav__bswap_s64(pSamples[iSample]);
}
}
-static DRWAV_INLINE double drwav__bswap_f64(double n)
+static MA_INLINE float ma_dr_wav__bswap_f32(float n)
{
union {
- drwav_uint64 i;
- double f;
+ ma_uint32 i;
+ float f;
} x;
x.f = n;
- x.i = drwav__bswap64(x.i);
+ x.i = ma_dr_wav__bswap32(x.i);
return x.f;
}
-static DRWAV_INLINE void drwav__bswap_samples_f64(double* pSamples, drwav_uint64 sampleCount)
+static MA_INLINE void ma_dr_wav__bswap_samples_f32(float* pSamples, ma_uint64 sampleCount)
{
- drwav_uint64 iSample;
+ ma_uint64 iSample;
for (iSample = 0; iSample < sampleCount; iSample += 1) {
- pSamples[iSample] = drwav__bswap_f64(pSamples[iSample]);
+ pSamples[iSample] = ma_dr_wav__bswap_f32(pSamples[iSample]);
}
}
-static DRWAV_INLINE void drwav__bswap_samples_pcm(void* pSamples, drwav_uint64 sampleCount, drwav_uint32 bytesPerSample)
+static MA_INLINE void ma_dr_wav__bswap_samples(void* pSamples, ma_uint64 sampleCount, ma_uint32 bytesPerSample)
{
switch (bytesPerSample)
{
@@ -74722,87 +77492,108 @@ static DRWAV_INLINE void drwav__bswap_samples_pcm(void* pSamples, drwav_uint64 s
} break;
case 2:
{
- drwav__bswap_samples_s16((drwav_int16*)pSamples, sampleCount);
+ ma_dr_wav__bswap_samples_s16((ma_int16*)pSamples, sampleCount);
} break;
case 3:
{
- drwav__bswap_samples_s24((drwav_uint8*)pSamples, sampleCount);
- } break;
- case 4:
- {
- drwav__bswap_samples_s32((drwav_int32*)pSamples, sampleCount);
- } break;
- default:
- {
- DRWAV_ASSERT(DRWAV_FALSE);
- } break;
- }
-}
-static DRWAV_INLINE void drwav__bswap_samples_ieee(void* pSamples, drwav_uint64 sampleCount, drwav_uint32 bytesPerSample)
-{
- switch (bytesPerSample)
- {
- #if 0
- case 2:
- {
- drwav__bswap_samples_f16((drwav_float16*)pSamples, sampleCount);
+ ma_dr_wav__bswap_samples_s24((ma_uint8*)pSamples, sampleCount);
} break;
- #endif
case 4:
{
- drwav__bswap_samples_f32((float*)pSamples, sampleCount);
+ ma_dr_wav__bswap_samples_s32((ma_int32*)pSamples, sampleCount);
} break;
case 8:
{
- drwav__bswap_samples_f64((double*)pSamples, sampleCount);
+ ma_dr_wav__bswap_samples_s64((ma_int64*)pSamples, sampleCount);
} break;
default:
{
- DRWAV_ASSERT(DRWAV_FALSE);
+ MA_DR_WAV_ASSERT(MA_FALSE);
} break;
}
}
-static DRWAV_INLINE void drwav__bswap_samples(void* pSamples, drwav_uint64 sampleCount, drwav_uint32 bytesPerSample, drwav_uint16 format)
+MA_PRIVATE MA_INLINE ma_bool32 ma_dr_wav_is_container_be(ma_dr_wav_container container)
{
- switch (format)
- {
- case DR_WAVE_FORMAT_PCM:
- {
- drwav__bswap_samples_pcm(pSamples, sampleCount, bytesPerSample);
- } break;
- case DR_WAVE_FORMAT_IEEE_FLOAT:
- {
- drwav__bswap_samples_ieee(pSamples, sampleCount, bytesPerSample);
- } break;
- case DR_WAVE_FORMAT_ALAW:
- case DR_WAVE_FORMAT_MULAW:
- {
- drwav__bswap_samples_s16((drwav_int16*)pSamples, sampleCount);
- } break;
- case DR_WAVE_FORMAT_ADPCM:
- case DR_WAVE_FORMAT_DVI_ADPCM:
- default:
- {
- DRWAV_ASSERT(DRWAV_FALSE);
- } break;
+ if (container == ma_dr_wav_container_rifx || container == ma_dr_wav_container_aiff) {
+ return MA_TRUE;
+ } else {
+ return MA_FALSE;
}
}
-DRWAV_PRIVATE void* drwav__malloc_default(size_t sz, void* pUserData)
+MA_PRIVATE MA_INLINE ma_uint16 ma_dr_wav_bytes_to_u16_le(const ma_uint8* data)
+{
+ return ((ma_uint16)data[0] << 0) | ((ma_uint16)data[1] << 8);
+}
+MA_PRIVATE MA_INLINE ma_uint16 ma_dr_wav_bytes_to_u16_be(const ma_uint8* data)
+{
+ return ((ma_uint16)data[1] << 0) | ((ma_uint16)data[0] << 8);
+}
+MA_PRIVATE MA_INLINE ma_uint16 ma_dr_wav_bytes_to_u16_ex(const ma_uint8* data, ma_dr_wav_container container)
+{
+ if (ma_dr_wav_is_container_be(container)) {
+ return ma_dr_wav_bytes_to_u16_be(data);
+ } else {
+ return ma_dr_wav_bytes_to_u16_le(data);
+ }
+}
+MA_PRIVATE MA_INLINE ma_uint32 ma_dr_wav_bytes_to_u32_le(const ma_uint8* data)
+{
+ return ((ma_uint32)data[0] << 0) | ((ma_uint32)data[1] << 8) | ((ma_uint32)data[2] << 16) | ((ma_uint32)data[3] << 24);
+}
+MA_PRIVATE MA_INLINE ma_uint32 ma_dr_wav_bytes_to_u32_be(const ma_uint8* data)
+{
+ return ((ma_uint32)data[3] << 0) | ((ma_uint32)data[2] << 8) | ((ma_uint32)data[1] << 16) | ((ma_uint32)data[0] << 24);
+}
+MA_PRIVATE MA_INLINE ma_uint32 ma_dr_wav_bytes_to_u32_ex(const ma_uint8* data, ma_dr_wav_container container)
+{
+ if (ma_dr_wav_is_container_be(container)) {
+ return ma_dr_wav_bytes_to_u32_be(data);
+ } else {
+ return ma_dr_wav_bytes_to_u32_le(data);
+ }
+}
+MA_PRIVATE ma_int64 ma_dr_wav_aiff_extented_to_s64(const ma_uint8* data)
+{
+ ma_uint32 exponent = ((ma_uint32)data[0] << 8) | data[1];
+ ma_uint64 hi = ((ma_uint64)data[2] << 24) | ((ma_uint64)data[3] << 16) | ((ma_uint64)data[4] << 8) | ((ma_uint64)data[5] << 0);
+ ma_uint64 lo = ((ma_uint64)data[6] << 24) | ((ma_uint64)data[7] << 16) | ((ma_uint64)data[8] << 8) | ((ma_uint64)data[9] << 0);
+ ma_uint64 significand = (hi << 32) | lo;
+ int sign = exponent >> 15;
+ exponent &= 0x7FFF;
+ if (exponent == 0 && significand == 0) {
+ return 0;
+ } else if (exponent == 0x7FFF) {
+ return sign ? MA_DR_WAV_INT64_MIN : MA_DR_WAV_INT64_MAX;
+ }
+ exponent -= 16383;
+ if (exponent > 63) {
+ return sign ? MA_DR_WAV_INT64_MIN : MA_DR_WAV_INT64_MAX;
+ } else if (exponent < 1) {
+ return 0;
+ }
+ significand >>= (63 - exponent);
+ if (sign) {
+ return -(ma_int64)significand;
+ } else {
+ return (ma_int64)significand;
+ }
+}
+MA_PRIVATE void* ma_dr_wav__malloc_default(size_t sz, void* pUserData)
{
(void)pUserData;
- return DRWAV_MALLOC(sz);
+ return MA_DR_WAV_MALLOC(sz);
}
-DRWAV_PRIVATE void* drwav__realloc_default(void* p, size_t sz, void* pUserData)
+MA_PRIVATE void* ma_dr_wav__realloc_default(void* p, size_t sz, void* pUserData)
{
(void)pUserData;
- return DRWAV_REALLOC(p, sz);
+ return MA_DR_WAV_REALLOC(p, sz);
}
-DRWAV_PRIVATE void drwav__free_default(void* p, void* pUserData)
+MA_PRIVATE void ma_dr_wav__free_default(void* p, void* pUserData)
{
(void)pUserData;
- DRWAV_FREE(p);
+ MA_DR_WAV_FREE(p);
}
-DRWAV_PRIVATE void* drwav__malloc_from_callbacks(size_t sz, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_PRIVATE void* ma_dr_wav__malloc_from_callbacks(size_t sz, const ma_allocation_callbacks* pAllocationCallbacks)
{
if (pAllocationCallbacks == NULL) {
return NULL;
@@ -74815,7 +77606,7 @@ DRWAV_PRIVATE void* drwav__malloc_from_callbacks(size_t sz, const drwav_allocati
}
return NULL;
}
-DRWAV_PRIVATE void* drwav__realloc_from_callbacks(void* p, size_t szNew, size_t szOld, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_PRIVATE void* ma_dr_wav__realloc_from_callbacks(void* p, size_t szNew, size_t szOld, const ma_allocation_callbacks* pAllocationCallbacks)
{
if (pAllocationCallbacks == NULL) {
return NULL;
@@ -74830,14 +77621,14 @@ DRWAV_PRIVATE void* drwav__realloc_from_callbacks(void* p, size_t szNew, size_t
return NULL;
}
if (p != NULL) {
- DRWAV_COPY_MEMORY(p2, p, szOld);
+ MA_DR_WAV_COPY_MEMORY(p2, p, szOld);
pAllocationCallbacks->onFree(p, pAllocationCallbacks->pUserData);
}
return p2;
}
return NULL;
}
-DRWAV_PRIVATE void drwav__free_from_callbacks(void* p, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_PRIVATE void ma_dr_wav__free_from_callbacks(void* p, const ma_allocation_callbacks* pAllocationCallbacks)
{
if (p == NULL || pAllocationCallbacks == NULL) {
return;
@@ -74846,361 +77637,288 @@ DRWAV_PRIVATE void drwav__free_from_callbacks(void* p, const drwav_allocation_ca
pAllocationCallbacks->onFree(p, pAllocationCallbacks->pUserData);
}
}
-DRWAV_PRIVATE drwav_allocation_callbacks drwav_copy_allocation_callbacks_or_defaults(const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_PRIVATE ma_allocation_callbacks ma_dr_wav_copy_allocation_callbacks_or_defaults(const ma_allocation_callbacks* pAllocationCallbacks)
{
if (pAllocationCallbacks != NULL) {
return *pAllocationCallbacks;
} else {
- drwav_allocation_callbacks allocationCallbacks;
+ ma_allocation_callbacks allocationCallbacks;
allocationCallbacks.pUserData = NULL;
- allocationCallbacks.onMalloc = drwav__malloc_default;
- allocationCallbacks.onRealloc = drwav__realloc_default;
- allocationCallbacks.onFree = drwav__free_default;
+ allocationCallbacks.onMalloc = ma_dr_wav__malloc_default;
+ allocationCallbacks.onRealloc = ma_dr_wav__realloc_default;
+ allocationCallbacks.onFree = ma_dr_wav__free_default;
return allocationCallbacks;
}
}
-static DRWAV_INLINE drwav_bool32 drwav__is_compressed_format_tag(drwav_uint16 formatTag)
+static MA_INLINE ma_bool32 ma_dr_wav__is_compressed_format_tag(ma_uint16 formatTag)
{
return
- formatTag == DR_WAVE_FORMAT_ADPCM ||
- formatTag == DR_WAVE_FORMAT_DVI_ADPCM;
+ formatTag == MA_DR_WAVE_FORMAT_ADPCM ||
+ formatTag == MA_DR_WAVE_FORMAT_DVI_ADPCM;
}
-DRWAV_PRIVATE unsigned int drwav__chunk_padding_size_riff(drwav_uint64 chunkSize)
+MA_PRIVATE unsigned int ma_dr_wav__chunk_padding_size_riff(ma_uint64 chunkSize)
{
return (unsigned int)(chunkSize % 2);
}
-DRWAV_PRIVATE unsigned int drwav__chunk_padding_size_w64(drwav_uint64 chunkSize)
+MA_PRIVATE unsigned int ma_dr_wav__chunk_padding_size_w64(ma_uint64 chunkSize)
{
return (unsigned int)(chunkSize % 8);
}
-DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__msadpcm(drwav* pWav, drwav_uint64 samplesToRead, drwav_int16* pBufferOut);
-DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__ima(drwav* pWav, drwav_uint64 samplesToRead, drwav_int16* pBufferOut);
-DRWAV_PRIVATE drwav_bool32 drwav_init_write__internal(drwav* pWav, const drwav_data_format* pFormat, drwav_uint64 totalSampleCount);
-DRWAV_PRIVATE drwav_result drwav__read_chunk_header(drwav_read_proc onRead, void* pUserData, drwav_container container, drwav_uint64* pRunningBytesReadOut, drwav_chunk_header* pHeaderOut)
+MA_PRIVATE ma_uint64 ma_dr_wav_read_pcm_frames_s16__msadpcm(ma_dr_wav* pWav, ma_uint64 samplesToRead, ma_int16* pBufferOut);
+MA_PRIVATE ma_uint64 ma_dr_wav_read_pcm_frames_s16__ima(ma_dr_wav* pWav, ma_uint64 samplesToRead, ma_int16* pBufferOut);
+MA_PRIVATE ma_bool32 ma_dr_wav_init_write__internal(ma_dr_wav* pWav, const ma_dr_wav_data_format* pFormat, ma_uint64 totalSampleCount);
+MA_PRIVATE ma_result ma_dr_wav__read_chunk_header(ma_dr_wav_read_proc onRead, void* pUserData, ma_dr_wav_container container, ma_uint64* pRunningBytesReadOut, ma_dr_wav_chunk_header* pHeaderOut)
{
- if (container == drwav_container_riff || container == drwav_container_rf64) {
- drwav_uint8 sizeInBytes[4];
+ if (container == ma_dr_wav_container_riff || container == ma_dr_wav_container_rifx || container == ma_dr_wav_container_rf64 || container == ma_dr_wav_container_aiff) {
+ ma_uint8 sizeInBytes[4];
if (onRead(pUserData, pHeaderOut->id.fourcc, 4) != 4) {
- return DRWAV_AT_END;
+ return MA_AT_END;
}
if (onRead(pUserData, sizeInBytes, 4) != 4) {
- return DRWAV_INVALID_FILE;
+ return MA_INVALID_FILE;
}
- pHeaderOut->sizeInBytes = drwav_bytes_to_u32(sizeInBytes);
- pHeaderOut->paddingSize = drwav__chunk_padding_size_riff(pHeaderOut->sizeInBytes);
+ pHeaderOut->sizeInBytes = ma_dr_wav_bytes_to_u32_ex(sizeInBytes, container);
+ pHeaderOut->paddingSize = ma_dr_wav__chunk_padding_size_riff(pHeaderOut->sizeInBytes);
*pRunningBytesReadOut += 8;
- } else {
- drwav_uint8 sizeInBytes[8];
+ } else if (container == ma_dr_wav_container_w64) {
+ ma_uint8 sizeInBytes[8];
if (onRead(pUserData, pHeaderOut->id.guid, 16) != 16) {
- return DRWAV_AT_END;
+ return MA_AT_END;
}
if (onRead(pUserData, sizeInBytes, 8) != 8) {
- return DRWAV_INVALID_FILE;
+ return MA_INVALID_FILE;
}
- pHeaderOut->sizeInBytes = drwav_bytes_to_u64(sizeInBytes) - 24;
- pHeaderOut->paddingSize = drwav__chunk_padding_size_w64(pHeaderOut->sizeInBytes);
+ pHeaderOut->sizeInBytes = ma_dr_wav_bytes_to_u64(sizeInBytes) - 24;
+ pHeaderOut->paddingSize = ma_dr_wav__chunk_padding_size_w64(pHeaderOut->sizeInBytes);
*pRunningBytesReadOut += 24;
+ } else {
+ return MA_INVALID_FILE;
}
- return DRWAV_SUCCESS;
+ return MA_SUCCESS;
}
-DRWAV_PRIVATE drwav_bool32 drwav__seek_forward(drwav_seek_proc onSeek, drwav_uint64 offset, void* pUserData)
+MA_PRIVATE ma_bool32 ma_dr_wav__seek_forward(ma_dr_wav_seek_proc onSeek, ma_uint64 offset, void* pUserData)
{
- drwav_uint64 bytesRemainingToSeek = offset;
+ ma_uint64 bytesRemainingToSeek = offset;
while (bytesRemainingToSeek > 0) {
if (bytesRemainingToSeek > 0x7FFFFFFF) {
- if (!onSeek(pUserData, 0x7FFFFFFF, drwav_seek_origin_current)) {
- return DRWAV_FALSE;
+ if (!onSeek(pUserData, 0x7FFFFFFF, ma_dr_wav_seek_origin_current)) {
+ return MA_FALSE;
}
bytesRemainingToSeek -= 0x7FFFFFFF;
} else {
- if (!onSeek(pUserData, (int)bytesRemainingToSeek, drwav_seek_origin_current)) {
- return DRWAV_FALSE;
+ if (!onSeek(pUserData, (int)bytesRemainingToSeek, ma_dr_wav_seek_origin_current)) {
+ return MA_FALSE;
}
bytesRemainingToSeek = 0;
}
}
- return DRWAV_TRUE;
+ return MA_TRUE;
}
-DRWAV_PRIVATE drwav_bool32 drwav__seek_from_start(drwav_seek_proc onSeek, drwav_uint64 offset, void* pUserData)
+MA_PRIVATE ma_bool32 ma_dr_wav__seek_from_start(ma_dr_wav_seek_proc onSeek, ma_uint64 offset, void* pUserData)
{
if (offset <= 0x7FFFFFFF) {
- return onSeek(pUserData, (int)offset, drwav_seek_origin_start);
+ return onSeek(pUserData, (int)offset, ma_dr_wav_seek_origin_start);
}
- if (!onSeek(pUserData, 0x7FFFFFFF, drwav_seek_origin_start)) {
- return DRWAV_FALSE;
+ if (!onSeek(pUserData, 0x7FFFFFFF, ma_dr_wav_seek_origin_start)) {
+ return MA_FALSE;
}
offset -= 0x7FFFFFFF;
for (;;) {
if (offset <= 0x7FFFFFFF) {
- return onSeek(pUserData, (int)offset, drwav_seek_origin_current);
+ return onSeek(pUserData, (int)offset, ma_dr_wav_seek_origin_current);
}
- if (!onSeek(pUserData, 0x7FFFFFFF, drwav_seek_origin_current)) {
- return DRWAV_FALSE;
+ if (!onSeek(pUserData, 0x7FFFFFFF, ma_dr_wav_seek_origin_current)) {
+ return MA_FALSE;
}
offset -= 0x7FFFFFFF;
}
}
-DRWAV_PRIVATE drwav_bool32 drwav__read_fmt(drwav_read_proc onRead, drwav_seek_proc onSeek, void* pUserData, drwav_container container, drwav_uint64* pRunningBytesReadOut, drwav_fmt* fmtOut)
-{
- drwav_chunk_header header;
- drwav_uint8 fmt[16];
- if (drwav__read_chunk_header(onRead, pUserData, container, pRunningBytesReadOut, &header) != DRWAV_SUCCESS) {
- return DRWAV_FALSE;
- }
- while (((container == drwav_container_riff || container == drwav_container_rf64) && !drwav_fourcc_equal(header.id.fourcc, "fmt ")) || (container == drwav_container_w64 && !drwav_guid_equal(header.id.guid, drwavGUID_W64_FMT))) {
- if (!drwav__seek_forward(onSeek, header.sizeInBytes + header.paddingSize, pUserData)) {
- return DRWAV_FALSE;
- }
- *pRunningBytesReadOut += header.sizeInBytes + header.paddingSize;
- if (drwav__read_chunk_header(onRead, pUserData, container, pRunningBytesReadOut, &header) != DRWAV_SUCCESS) {
- return DRWAV_FALSE;
- }
- }
- if (container == drwav_container_riff || container == drwav_container_rf64) {
- if (!drwav_fourcc_equal(header.id.fourcc, "fmt ")) {
- return DRWAV_FALSE;
- }
- } else {
- if (!drwav_guid_equal(header.id.guid, drwavGUID_W64_FMT)) {
- return DRWAV_FALSE;
- }
- }
- if (onRead(pUserData, fmt, sizeof(fmt)) != sizeof(fmt)) {
- return DRWAV_FALSE;
- }
- *pRunningBytesReadOut += sizeof(fmt);
- fmtOut->formatTag = drwav_bytes_to_u16(fmt + 0);
- fmtOut->channels = drwav_bytes_to_u16(fmt + 2);
- fmtOut->sampleRate = drwav_bytes_to_u32(fmt + 4);
- fmtOut->avgBytesPerSec = drwav_bytes_to_u32(fmt + 8);
- fmtOut->blockAlign = drwav_bytes_to_u16(fmt + 12);
- fmtOut->bitsPerSample = drwav_bytes_to_u16(fmt + 14);
- fmtOut->extendedSize = 0;
- fmtOut->validBitsPerSample = 0;
- fmtOut->channelMask = 0;
- DRWAV_ZERO_MEMORY(fmtOut->subFormat, sizeof(fmtOut->subFormat));
- if (header.sizeInBytes > 16) {
- drwav_uint8 fmt_cbSize[2];
- int bytesReadSoFar = 0;
- if (onRead(pUserData, fmt_cbSize, sizeof(fmt_cbSize)) != sizeof(fmt_cbSize)) {
- return DRWAV_FALSE;
- }
- *pRunningBytesReadOut += sizeof(fmt_cbSize);
- bytesReadSoFar = 18;
- fmtOut->extendedSize = drwav_bytes_to_u16(fmt_cbSize);
- if (fmtOut->extendedSize > 0) {
- if (fmtOut->formatTag == DR_WAVE_FORMAT_EXTENSIBLE) {
- if (fmtOut->extendedSize != 22) {
- return DRWAV_FALSE;
- }
- }
- if (fmtOut->formatTag == DR_WAVE_FORMAT_EXTENSIBLE) {
- drwav_uint8 fmtext[22];
- if (onRead(pUserData, fmtext, fmtOut->extendedSize) != fmtOut->extendedSize) {
- return DRWAV_FALSE;
- }
- fmtOut->validBitsPerSample = drwav_bytes_to_u16(fmtext + 0);
- fmtOut->channelMask = drwav_bytes_to_u32(fmtext + 2);
- drwav_bytes_to_guid(fmtext + 6, fmtOut->subFormat);
- } else {
- if (!onSeek(pUserData, fmtOut->extendedSize, drwav_seek_origin_current)) {
- return DRWAV_FALSE;
- }
- }
- *pRunningBytesReadOut += fmtOut->extendedSize;
- bytesReadSoFar += fmtOut->extendedSize;
- }
- if (!onSeek(pUserData, (int)(header.sizeInBytes - bytesReadSoFar), drwav_seek_origin_current)) {
- return DRWAV_FALSE;
- }
- *pRunningBytesReadOut += (header.sizeInBytes - bytesReadSoFar);
- }
- if (header.paddingSize > 0) {
- if (!onSeek(pUserData, header.paddingSize, drwav_seek_origin_current)) {
- return DRWAV_FALSE;
- }
- *pRunningBytesReadOut += header.paddingSize;
- }
- return DRWAV_TRUE;
-}
-DRWAV_PRIVATE size_t drwav__on_read(drwav_read_proc onRead, void* pUserData, void* pBufferOut, size_t bytesToRead, drwav_uint64* pCursor)
+MA_PRIVATE size_t ma_dr_wav__on_read(ma_dr_wav_read_proc onRead, void* pUserData, void* pBufferOut, size_t bytesToRead, ma_uint64* pCursor)
{
size_t bytesRead;
- DRWAV_ASSERT(onRead != NULL);
- DRWAV_ASSERT(pCursor != NULL);
+ MA_DR_WAV_ASSERT(onRead != NULL);
+ MA_DR_WAV_ASSERT(pCursor != NULL);
bytesRead = onRead(pUserData, pBufferOut, bytesToRead);
*pCursor += bytesRead;
return bytesRead;
}
#if 0
-DRWAV_PRIVATE drwav_bool32 drwav__on_seek(drwav_seek_proc onSeek, void* pUserData, int offset, drwav_seek_origin origin, drwav_uint64* pCursor)
+MA_PRIVATE ma_bool32 ma_dr_wav__on_seek(ma_dr_wav_seek_proc onSeek, void* pUserData, int offset, ma_dr_wav_seek_origin origin, ma_uint64* pCursor)
{
- DRWAV_ASSERT(onSeek != NULL);
- DRWAV_ASSERT(pCursor != NULL);
+ MA_DR_WAV_ASSERT(onSeek != NULL);
+ MA_DR_WAV_ASSERT(pCursor != NULL);
if (!onSeek(pUserData, offset, origin)) {
- return DRWAV_FALSE;
+ return MA_FALSE;
}
- if (origin == drwav_seek_origin_start) {
+ if (origin == ma_dr_wav_seek_origin_start) {
*pCursor = offset;
} else {
*pCursor += offset;
}
- return DRWAV_TRUE;
-}
-#endif
-#define DRWAV_SMPL_BYTES 36
-#define DRWAV_SMPL_LOOP_BYTES 24
-#define DRWAV_INST_BYTES 7
-#define DRWAV_ACID_BYTES 24
-#define DRWAV_CUE_BYTES 4
-#define DRWAV_BEXT_BYTES 602
-#define DRWAV_BEXT_DESCRIPTION_BYTES 256
-#define DRWAV_BEXT_ORIGINATOR_NAME_BYTES 32
-#define DRWAV_BEXT_ORIGINATOR_REF_BYTES 32
-#define DRWAV_BEXT_RESERVED_BYTES 180
-#define DRWAV_BEXT_UMID_BYTES 64
-#define DRWAV_CUE_POINT_BYTES 24
-#define DRWAV_LIST_LABEL_OR_NOTE_BYTES 4
-#define DRWAV_LIST_LABELLED_TEXT_BYTES 20
-#define DRWAV_METADATA_ALIGNMENT 8
+ return MA_TRUE;
+}
+#endif
+#define MA_DR_WAV_SMPL_BYTES 36
+#define MA_DR_WAV_SMPL_LOOP_BYTES 24
+#define MA_DR_WAV_INST_BYTES 7
+#define MA_DR_WAV_ACID_BYTES 24
+#define MA_DR_WAV_CUE_BYTES 4
+#define MA_DR_WAV_BEXT_BYTES 602
+#define MA_DR_WAV_BEXT_DESCRIPTION_BYTES 256
+#define MA_DR_WAV_BEXT_ORIGINATOR_NAME_BYTES 32
+#define MA_DR_WAV_BEXT_ORIGINATOR_REF_BYTES 32
+#define MA_DR_WAV_BEXT_RESERVED_BYTES 180
+#define MA_DR_WAV_BEXT_UMID_BYTES 64
+#define MA_DR_WAV_CUE_POINT_BYTES 24
+#define MA_DR_WAV_LIST_LABEL_OR_NOTE_BYTES 4
+#define MA_DR_WAV_LIST_LABELLED_TEXT_BYTES 20
+#define MA_DR_WAV_METADATA_ALIGNMENT 8
typedef enum
{
- drwav__metadata_parser_stage_count,
- drwav__metadata_parser_stage_read
-} drwav__metadata_parser_stage;
+ ma_dr_wav__metadata_parser_stage_count,
+ ma_dr_wav__metadata_parser_stage_read
+} ma_dr_wav__metadata_parser_stage;
typedef struct
{
- drwav_read_proc onRead;
- drwav_seek_proc onSeek;
+ ma_dr_wav_read_proc onRead;
+ ma_dr_wav_seek_proc onSeek;
void *pReadSeekUserData;
- drwav__metadata_parser_stage stage;
- drwav_metadata *pMetadata;
- drwav_uint32 metadataCount;
- drwav_uint8 *pData;
- drwav_uint8 *pDataCursor;
- drwav_uint64 metadataCursor;
- drwav_uint64 extraCapacity;
-} drwav__metadata_parser;
-DRWAV_PRIVATE size_t drwav__metadata_memory_capacity(drwav__metadata_parser* pParser)
-{
- drwav_uint64 cap = sizeof(drwav_metadata) * (drwav_uint64)pParser->metadataCount + pParser->extraCapacity;
- if (cap > DRWAV_SIZE_MAX) {
+ ma_dr_wav__metadata_parser_stage stage;
+ ma_dr_wav_metadata *pMetadata;
+ ma_uint32 metadataCount;
+ ma_uint8 *pData;
+ ma_uint8 *pDataCursor;
+ ma_uint64 metadataCursor;
+ ma_uint64 extraCapacity;
+} ma_dr_wav__metadata_parser;
+MA_PRIVATE size_t ma_dr_wav__metadata_memory_capacity(ma_dr_wav__metadata_parser* pParser)
+{
+ ma_uint64 cap = sizeof(ma_dr_wav_metadata) * (ma_uint64)pParser->metadataCount + pParser->extraCapacity;
+ if (cap > MA_SIZE_MAX) {
return 0;
}
return (size_t)cap;
}
-DRWAV_PRIVATE drwav_uint8* drwav__metadata_get_memory(drwav__metadata_parser* pParser, size_t size, size_t align)
+MA_PRIVATE ma_uint8* ma_dr_wav__metadata_get_memory(ma_dr_wav__metadata_parser* pParser, size_t size, size_t align)
{
- drwav_uint8* pResult;
+ ma_uint8* pResult;
if (align) {
- drwav_uintptr modulo = (drwav_uintptr)pParser->pDataCursor % align;
+ ma_uintptr modulo = (ma_uintptr)pParser->pDataCursor % align;
if (modulo != 0) {
pParser->pDataCursor += align - modulo;
}
}
pResult = pParser->pDataCursor;
- DRWAV_ASSERT((pResult + size) <= (pParser->pData + drwav__metadata_memory_capacity(pParser)));
+ MA_DR_WAV_ASSERT((pResult + size) <= (pParser->pData + ma_dr_wav__metadata_memory_capacity(pParser)));
pParser->pDataCursor += size;
return pResult;
}
-DRWAV_PRIVATE void drwav__metadata_request_extra_memory_for_stage_2(drwav__metadata_parser* pParser, size_t bytes, size_t align)
+MA_PRIVATE void ma_dr_wav__metadata_request_extra_memory_for_stage_2(ma_dr_wav__metadata_parser* pParser, size_t bytes, size_t align)
{
size_t extra = bytes + (align ? (align - 1) : 0);
pParser->extraCapacity += extra;
}
-DRWAV_PRIVATE drwav_result drwav__metadata_alloc(drwav__metadata_parser* pParser, drwav_allocation_callbacks* pAllocationCallbacks)
+MA_PRIVATE ma_result ma_dr_wav__metadata_alloc(ma_dr_wav__metadata_parser* pParser, ma_allocation_callbacks* pAllocationCallbacks)
{
if (pParser->extraCapacity != 0 || pParser->metadataCount != 0) {
pAllocationCallbacks->onFree(pParser->pData, pAllocationCallbacks->pUserData);
- pParser->pData = (drwav_uint8*)pAllocationCallbacks->onMalloc(drwav__metadata_memory_capacity(pParser), pAllocationCallbacks->pUserData);
+ pParser->pData = (ma_uint8*)pAllocationCallbacks->onMalloc(ma_dr_wav__metadata_memory_capacity(pParser), pAllocationCallbacks->pUserData);
pParser->pDataCursor = pParser->pData;
if (pParser->pData == NULL) {
- return DRWAV_OUT_OF_MEMORY;
+ return MA_OUT_OF_MEMORY;
}
- pParser->pMetadata = (drwav_metadata*)drwav__metadata_get_memory(pParser, sizeof(drwav_metadata) * pParser->metadataCount, 1);
+ pParser->pMetadata = (ma_dr_wav_metadata*)ma_dr_wav__metadata_get_memory(pParser, sizeof(ma_dr_wav_metadata) * pParser->metadataCount, 1);
pParser->metadataCursor = 0;
}
- return DRWAV_SUCCESS;
+ return MA_SUCCESS;
}
-DRWAV_PRIVATE size_t drwav__metadata_parser_read(drwav__metadata_parser* pParser, void* pBufferOut, size_t bytesToRead, drwav_uint64* pCursor)
+MA_PRIVATE size_t ma_dr_wav__metadata_parser_read(ma_dr_wav__metadata_parser* pParser, void* pBufferOut, size_t bytesToRead, ma_uint64* pCursor)
{
if (pCursor != NULL) {
- return drwav__on_read(pParser->onRead, pParser->pReadSeekUserData, pBufferOut, bytesToRead, pCursor);
+ return ma_dr_wav__on_read(pParser->onRead, pParser->pReadSeekUserData, pBufferOut, bytesToRead, pCursor);
} else {
return pParser->onRead(pParser->pReadSeekUserData, pBufferOut, bytesToRead);
}
}
-DRWAV_PRIVATE drwav_uint64 drwav__read_smpl_to_metadata_obj(drwav__metadata_parser* pParser, const drwav_chunk_header* pChunkHeader, drwav_metadata* pMetadata)
-{
- drwav_uint8 smplHeaderData[DRWAV_SMPL_BYTES];
- drwav_uint64 totalBytesRead = 0;
- size_t bytesJustRead = drwav__metadata_parser_read(pParser, smplHeaderData, sizeof(smplHeaderData), &totalBytesRead);
- DRWAV_ASSERT(pParser->stage == drwav__metadata_parser_stage_read);
- DRWAV_ASSERT(pChunkHeader != NULL);
- if (bytesJustRead == sizeof(smplHeaderData)) {
- drwav_uint32 iSampleLoop;
- pMetadata->type = drwav_metadata_type_smpl;
- pMetadata->data.smpl.manufacturerId = drwav_bytes_to_u32(smplHeaderData + 0);
- pMetadata->data.smpl.productId = drwav_bytes_to_u32(smplHeaderData + 4);
- pMetadata->data.smpl.samplePeriodNanoseconds = drwav_bytes_to_u32(smplHeaderData + 8);
- pMetadata->data.smpl.midiUnityNote = drwav_bytes_to_u32(smplHeaderData + 12);
- pMetadata->data.smpl.midiPitchFraction = drwav_bytes_to_u32(smplHeaderData + 16);
- pMetadata->data.smpl.smpteFormat = drwav_bytes_to_u32(smplHeaderData + 20);
- pMetadata->data.smpl.smpteOffset = drwav_bytes_to_u32(smplHeaderData + 24);
- pMetadata->data.smpl.sampleLoopCount = drwav_bytes_to_u32(smplHeaderData + 28);
- pMetadata->data.smpl.samplerSpecificDataSizeInBytes = drwav_bytes_to_u32(smplHeaderData + 32);
- if (pMetadata->data.smpl.sampleLoopCount == (pChunkHeader->sizeInBytes - DRWAV_SMPL_BYTES) / DRWAV_SMPL_LOOP_BYTES) {
- pMetadata->data.smpl.pLoops = (drwav_smpl_loop*)drwav__metadata_get_memory(pParser, sizeof(drwav_smpl_loop) * pMetadata->data.smpl.sampleLoopCount, DRWAV_METADATA_ALIGNMENT);
+MA_PRIVATE ma_uint64 ma_dr_wav__read_smpl_to_metadata_obj(ma_dr_wav__metadata_parser* pParser, const ma_dr_wav_chunk_header* pChunkHeader, ma_dr_wav_metadata* pMetadata)
+{
+ ma_uint8 smplHeaderData[MA_DR_WAV_SMPL_BYTES];
+ ma_uint64 totalBytesRead = 0;
+ size_t bytesJustRead;
+ if (pMetadata == NULL) {
+ return 0;
+ }
+ bytesJustRead = ma_dr_wav__metadata_parser_read(pParser, smplHeaderData, sizeof(smplHeaderData), &totalBytesRead);
+ MA_DR_WAV_ASSERT(pParser->stage == ma_dr_wav__metadata_parser_stage_read);
+ MA_DR_WAV_ASSERT(pChunkHeader != NULL);
+ if (pMetadata != NULL && bytesJustRead == sizeof(smplHeaderData)) {
+ ma_uint32 iSampleLoop;
+ pMetadata->type = ma_dr_wav_metadata_type_smpl;
+ pMetadata->data.smpl.manufacturerId = ma_dr_wav_bytes_to_u32(smplHeaderData + 0);
+ pMetadata->data.smpl.productId = ma_dr_wav_bytes_to_u32(smplHeaderData + 4);
+ pMetadata->data.smpl.samplePeriodNanoseconds = ma_dr_wav_bytes_to_u32(smplHeaderData + 8);
+ pMetadata->data.smpl.midiUnityNote = ma_dr_wav_bytes_to_u32(smplHeaderData + 12);
+ pMetadata->data.smpl.midiPitchFraction = ma_dr_wav_bytes_to_u32(smplHeaderData + 16);
+ pMetadata->data.smpl.smpteFormat = ma_dr_wav_bytes_to_u32(smplHeaderData + 20);
+ pMetadata->data.smpl.smpteOffset = ma_dr_wav_bytes_to_u32(smplHeaderData + 24);
+ pMetadata->data.smpl.sampleLoopCount = ma_dr_wav_bytes_to_u32(smplHeaderData + 28);
+ pMetadata->data.smpl.samplerSpecificDataSizeInBytes = ma_dr_wav_bytes_to_u32(smplHeaderData + 32);
+ if (pMetadata->data.smpl.sampleLoopCount == (pChunkHeader->sizeInBytes - MA_DR_WAV_SMPL_BYTES) / MA_DR_WAV_SMPL_LOOP_BYTES) {
+ pMetadata->data.smpl.pLoops = (ma_dr_wav_smpl_loop*)ma_dr_wav__metadata_get_memory(pParser, sizeof(ma_dr_wav_smpl_loop) * pMetadata->data.smpl.sampleLoopCount, MA_DR_WAV_METADATA_ALIGNMENT);
for (iSampleLoop = 0; iSampleLoop < pMetadata->data.smpl.sampleLoopCount; ++iSampleLoop) {
- drwav_uint8 smplLoopData[DRWAV_SMPL_LOOP_BYTES];
- bytesJustRead = drwav__metadata_parser_read(pParser, smplLoopData, sizeof(smplLoopData), &totalBytesRead);
+ ma_uint8 smplLoopData[MA_DR_WAV_SMPL_LOOP_BYTES];
+ bytesJustRead = ma_dr_wav__metadata_parser_read(pParser, smplLoopData, sizeof(smplLoopData), &totalBytesRead);
if (bytesJustRead == sizeof(smplLoopData)) {
- pMetadata->data.smpl.pLoops[iSampleLoop].cuePointId = drwav_bytes_to_u32(smplLoopData + 0);
- pMetadata->data.smpl.pLoops[iSampleLoop].type = drwav_bytes_to_u32(smplLoopData + 4);
- pMetadata->data.smpl.pLoops[iSampleLoop].firstSampleByteOffset = drwav_bytes_to_u32(smplLoopData + 8);
- pMetadata->data.smpl.pLoops[iSampleLoop].lastSampleByteOffset = drwav_bytes_to_u32(smplLoopData + 12);
- pMetadata->data.smpl.pLoops[iSampleLoop].sampleFraction = drwav_bytes_to_u32(smplLoopData + 16);
- pMetadata->data.smpl.pLoops[iSampleLoop].playCount = drwav_bytes_to_u32(smplLoopData + 20);
+ pMetadata->data.smpl.pLoops[iSampleLoop].cuePointId = ma_dr_wav_bytes_to_u32(smplLoopData + 0);
+ pMetadata->data.smpl.pLoops[iSampleLoop].type = ma_dr_wav_bytes_to_u32(smplLoopData + 4);
+ pMetadata->data.smpl.pLoops[iSampleLoop].firstSampleByteOffset = ma_dr_wav_bytes_to_u32(smplLoopData + 8);
+ pMetadata->data.smpl.pLoops[iSampleLoop].lastSampleByteOffset = ma_dr_wav_bytes_to_u32(smplLoopData + 12);
+ pMetadata->data.smpl.pLoops[iSampleLoop].sampleFraction = ma_dr_wav_bytes_to_u32(smplLoopData + 16);
+ pMetadata->data.smpl.pLoops[iSampleLoop].playCount = ma_dr_wav_bytes_to_u32(smplLoopData + 20);
} else {
break;
}
}
if (pMetadata->data.smpl.samplerSpecificDataSizeInBytes > 0) {
- pMetadata->data.smpl.pSamplerSpecificData = drwav__metadata_get_memory(pParser, pMetadata->data.smpl.samplerSpecificDataSizeInBytes, 1);
- DRWAV_ASSERT(pMetadata->data.smpl.pSamplerSpecificData != NULL);
- drwav__metadata_parser_read(pParser, pMetadata->data.smpl.pSamplerSpecificData, pMetadata->data.smpl.samplerSpecificDataSizeInBytes, &totalBytesRead);
+ pMetadata->data.smpl.pSamplerSpecificData = ma_dr_wav__metadata_get_memory(pParser, pMetadata->data.smpl.samplerSpecificDataSizeInBytes, 1);
+ MA_DR_WAV_ASSERT(pMetadata->data.smpl.pSamplerSpecificData != NULL);
+ ma_dr_wav__metadata_parser_read(pParser, pMetadata->data.smpl.pSamplerSpecificData, pMetadata->data.smpl.samplerSpecificDataSizeInBytes, &totalBytesRead);
}
}
}
return totalBytesRead;
}
-DRWAV_PRIVATE drwav_uint64 drwav__read_cue_to_metadata_obj(drwav__metadata_parser* pParser, const drwav_chunk_header* pChunkHeader, drwav_metadata* pMetadata)
+MA_PRIVATE ma_uint64 ma_dr_wav__read_cue_to_metadata_obj(ma_dr_wav__metadata_parser* pParser, const ma_dr_wav_chunk_header* pChunkHeader, ma_dr_wav_metadata* pMetadata)
{
- drwav_uint8 cueHeaderSectionData[DRWAV_CUE_BYTES];
- drwav_uint64 totalBytesRead = 0;
- size_t bytesJustRead = drwav__metadata_parser_read(pParser, cueHeaderSectionData, sizeof(cueHeaderSectionData), &totalBytesRead);
- DRWAV_ASSERT(pParser->stage == drwav__metadata_parser_stage_read);
+ ma_uint8 cueHeaderSectionData[MA_DR_WAV_CUE_BYTES];
+ ma_uint64 totalBytesRead = 0;
+ size_t bytesJustRead;
+ if (pMetadata == NULL) {
+ return 0;
+ }
+ bytesJustRead = ma_dr_wav__metadata_parser_read(pParser, cueHeaderSectionData, sizeof(cueHeaderSectionData), &totalBytesRead);
+ MA_DR_WAV_ASSERT(pParser->stage == ma_dr_wav__metadata_parser_stage_read);
if (bytesJustRead == sizeof(cueHeaderSectionData)) {
- pMetadata->type = drwav_metadata_type_cue;
- pMetadata->data.cue.cuePointCount = drwav_bytes_to_u32(cueHeaderSectionData);
- if (pMetadata->data.cue.cuePointCount == (pChunkHeader->sizeInBytes - DRWAV_CUE_BYTES) / DRWAV_CUE_POINT_BYTES) {
- pMetadata->data.cue.pCuePoints = (drwav_cue_point*)drwav__metadata_get_memory(pParser, sizeof(drwav_cue_point) * pMetadata->data.cue.cuePointCount, DRWAV_METADATA_ALIGNMENT);
- DRWAV_ASSERT(pMetadata->data.cue.pCuePoints != NULL);
+ pMetadata->type = ma_dr_wav_metadata_type_cue;
+ pMetadata->data.cue.cuePointCount = ma_dr_wav_bytes_to_u32(cueHeaderSectionData);
+ if (pMetadata->data.cue.cuePointCount == (pChunkHeader->sizeInBytes - MA_DR_WAV_CUE_BYTES) / MA_DR_WAV_CUE_POINT_BYTES) {
+ pMetadata->data.cue.pCuePoints = (ma_dr_wav_cue_point*)ma_dr_wav__metadata_get_memory(pParser, sizeof(ma_dr_wav_cue_point) * pMetadata->data.cue.cuePointCount, MA_DR_WAV_METADATA_ALIGNMENT);
+ MA_DR_WAV_ASSERT(pMetadata->data.cue.pCuePoints != NULL);
if (pMetadata->data.cue.cuePointCount > 0) {
- drwav_uint32 iCuePoint;
+ ma_uint32 iCuePoint;
for (iCuePoint = 0; iCuePoint < pMetadata->data.cue.cuePointCount; ++iCuePoint) {
- drwav_uint8 cuePointData[DRWAV_CUE_POINT_BYTES];
- bytesJustRead = drwav__metadata_parser_read(pParser, cuePointData, sizeof(cuePointData), &totalBytesRead);
+ ma_uint8 cuePointData[MA_DR_WAV_CUE_POINT_BYTES];
+ bytesJustRead = ma_dr_wav__metadata_parser_read(pParser, cuePointData, sizeof(cuePointData), &totalBytesRead);
if (bytesJustRead == sizeof(cuePointData)) {
- pMetadata->data.cue.pCuePoints[iCuePoint].id = drwav_bytes_to_u32(cuePointData + 0);
- pMetadata->data.cue.pCuePoints[iCuePoint].playOrderPosition = drwav_bytes_to_u32(cuePointData + 4);
+ pMetadata->data.cue.pCuePoints[iCuePoint].id = ma_dr_wav_bytes_to_u32(cuePointData + 0);
+ pMetadata->data.cue.pCuePoints[iCuePoint].playOrderPosition = ma_dr_wav_bytes_to_u32(cuePointData + 4);
pMetadata->data.cue.pCuePoints[iCuePoint].dataChunkId[0] = cuePointData[8];
pMetadata->data.cue.pCuePoints[iCuePoint].dataChunkId[1] = cuePointData[9];
pMetadata->data.cue.pCuePoints[iCuePoint].dataChunkId[2] = cuePointData[10];
pMetadata->data.cue.pCuePoints[iCuePoint].dataChunkId[3] = cuePointData[11];
- pMetadata->data.cue.pCuePoints[iCuePoint].chunkStart = drwav_bytes_to_u32(cuePointData + 12);
- pMetadata->data.cue.pCuePoints[iCuePoint].blockStart = drwav_bytes_to_u32(cuePointData + 16);
- pMetadata->data.cue.pCuePoints[iCuePoint].sampleByteOffset = drwav_bytes_to_u32(cuePointData + 20);
+ pMetadata->data.cue.pCuePoints[iCuePoint].chunkStart = ma_dr_wav_bytes_to_u32(cuePointData + 12);
+ pMetadata->data.cue.pCuePoints[iCuePoint].blockStart = ma_dr_wav_bytes_to_u32(cuePointData + 16);
+ pMetadata->data.cue.pCuePoints[iCuePoint].sampleByteOffset = ma_dr_wav_bytes_to_u32(cuePointData + 20);
} else {
break;
}
@@ -75210,42 +77928,50 @@ DRWAV_PRIVATE drwav_uint64 drwav__read_cue_to_metadata_obj(drwav__metadata_parse
}
return totalBytesRead;
}
-DRWAV_PRIVATE drwav_uint64 drwav__read_inst_to_metadata_obj(drwav__metadata_parser* pParser, drwav_metadata* pMetadata)
+MA_PRIVATE ma_uint64 ma_dr_wav__read_inst_to_metadata_obj(ma_dr_wav__metadata_parser* pParser, ma_dr_wav_metadata* pMetadata)
{
- drwav_uint8 instData[DRWAV_INST_BYTES];
- drwav_uint64 bytesRead = drwav__metadata_parser_read(pParser, instData, sizeof(instData), NULL);
- DRWAV_ASSERT(pParser->stage == drwav__metadata_parser_stage_read);
+ ma_uint8 instData[MA_DR_WAV_INST_BYTES];
+ ma_uint64 bytesRead;
+ if (pMetadata == NULL) {
+ return 0;
+ }
+ bytesRead = ma_dr_wav__metadata_parser_read(pParser, instData, sizeof(instData), NULL);
+ MA_DR_WAV_ASSERT(pParser->stage == ma_dr_wav__metadata_parser_stage_read);
if (bytesRead == sizeof(instData)) {
- pMetadata->type = drwav_metadata_type_inst;
- pMetadata->data.inst.midiUnityNote = (drwav_int8)instData[0];
- pMetadata->data.inst.fineTuneCents = (drwav_int8)instData[1];
- pMetadata->data.inst.gainDecibels = (drwav_int8)instData[2];
- pMetadata->data.inst.lowNote = (drwav_int8)instData[3];
- pMetadata->data.inst.highNote = (drwav_int8)instData[4];
- pMetadata->data.inst.lowVelocity = (drwav_int8)instData[5];
- pMetadata->data.inst.highVelocity = (drwav_int8)instData[6];
+ pMetadata->type = ma_dr_wav_metadata_type_inst;
+ pMetadata->data.inst.midiUnityNote = (ma_int8)instData[0];
+ pMetadata->data.inst.fineTuneCents = (ma_int8)instData[1];
+ pMetadata->data.inst.gainDecibels = (ma_int8)instData[2];
+ pMetadata->data.inst.lowNote = (ma_int8)instData[3];
+ pMetadata->data.inst.highNote = (ma_int8)instData[4];
+ pMetadata->data.inst.lowVelocity = (ma_int8)instData[5];
+ pMetadata->data.inst.highVelocity = (ma_int8)instData[6];
}
return bytesRead;
}
-DRWAV_PRIVATE drwav_uint64 drwav__read_acid_to_metadata_obj(drwav__metadata_parser* pParser, drwav_metadata* pMetadata)
+MA_PRIVATE ma_uint64 ma_dr_wav__read_acid_to_metadata_obj(ma_dr_wav__metadata_parser* pParser, ma_dr_wav_metadata* pMetadata)
{
- drwav_uint8 acidData[DRWAV_ACID_BYTES];
- drwav_uint64 bytesRead = drwav__metadata_parser_read(pParser, acidData, sizeof(acidData), NULL);
- DRWAV_ASSERT(pParser->stage == drwav__metadata_parser_stage_read);
+ ma_uint8 acidData[MA_DR_WAV_ACID_BYTES];
+ ma_uint64 bytesRead;
+ if (pMetadata == NULL) {
+ return 0;
+ }
+ bytesRead = ma_dr_wav__metadata_parser_read(pParser, acidData, sizeof(acidData), NULL);
+ MA_DR_WAV_ASSERT(pParser->stage == ma_dr_wav__metadata_parser_stage_read);
if (bytesRead == sizeof(acidData)) {
- pMetadata->type = drwav_metadata_type_acid;
- pMetadata->data.acid.flags = drwav_bytes_to_u32(acidData + 0);
- pMetadata->data.acid.midiUnityNote = drwav_bytes_to_u16(acidData + 4);
- pMetadata->data.acid.reserved1 = drwav_bytes_to_u16(acidData + 6);
- pMetadata->data.acid.reserved2 = drwav_bytes_to_f32(acidData + 8);
- pMetadata->data.acid.numBeats = drwav_bytes_to_u32(acidData + 12);
- pMetadata->data.acid.meterDenominator = drwav_bytes_to_u16(acidData + 16);
- pMetadata->data.acid.meterNumerator = drwav_bytes_to_u16(acidData + 18);
- pMetadata->data.acid.tempo = drwav_bytes_to_f32(acidData + 20);
+ pMetadata->type = ma_dr_wav_metadata_type_acid;
+ pMetadata->data.acid.flags = ma_dr_wav_bytes_to_u32(acidData + 0);
+ pMetadata->data.acid.midiUnityNote = ma_dr_wav_bytes_to_u16(acidData + 4);
+ pMetadata->data.acid.reserved1 = ma_dr_wav_bytes_to_u16(acidData + 6);
+ pMetadata->data.acid.reserved2 = ma_dr_wav_bytes_to_f32(acidData + 8);
+ pMetadata->data.acid.numBeats = ma_dr_wav_bytes_to_u32(acidData + 12);
+ pMetadata->data.acid.meterDenominator = ma_dr_wav_bytes_to_u16(acidData + 16);
+ pMetadata->data.acid.meterNumerator = ma_dr_wav_bytes_to_u16(acidData + 18);
+ pMetadata->data.acid.tempo = ma_dr_wav_bytes_to_f32(acidData + 20);
}
return bytesRead;
}
-DRWAV_PRIVATE size_t drwav__strlen(const char* str)
+MA_PRIVATE size_t ma_dr_wav__strlen(const char* str)
{
size_t result = 0;
while (*str++) {
@@ -75253,7 +77979,7 @@ DRWAV_PRIVATE size_t drwav__strlen(const char* str)
}
return result;
}
-DRWAV_PRIVATE size_t drwav__strlen_clamped(const char* str, size_t maxToRead)
+MA_PRIVATE size_t ma_dr_wav__strlen_clamped(const char* str, size_t maxToRead)
{
size_t result = 0;
while (*str++ && result < maxToRead) {
@@ -75261,13 +77987,13 @@ DRWAV_PRIVATE size_t drwav__strlen_clamped(const char* str, size_t maxToRead)
}
return result;
}
-DRWAV_PRIVATE char* drwav__metadata_copy_string(drwav__metadata_parser* pParser, const char* str, size_t maxToRead)
+MA_PRIVATE char* ma_dr_wav__metadata_copy_string(ma_dr_wav__metadata_parser* pParser, const char* str, size_t maxToRead)
{
- size_t len = drwav__strlen_clamped(str, maxToRead);
+ size_t len = ma_dr_wav__strlen_clamped(str, maxToRead);
if (len) {
- char* result = (char*)drwav__metadata_get_memory(pParser, len + 1, 1);
- DRWAV_ASSERT(result != NULL);
- DRWAV_COPY_MEMORY(result, str, len);
+ char* result = (char*)ma_dr_wav__metadata_get_memory(pParser, len + 1, 1);
+ MA_DR_WAV_ASSERT(result != NULL);
+ MA_DR_WAV_COPY_MEMORY(result, str, len);
result[len] = '\0';
return result;
} else {
@@ -75279,36 +78005,36 @@ typedef struct
const void* pBuffer;
size_t sizeInBytes;
size_t cursor;
-} drwav_buffer_reader;
-DRWAV_PRIVATE drwav_result drwav_buffer_reader_init(const void* pBuffer, size_t sizeInBytes, drwav_buffer_reader* pReader)
+} ma_dr_wav_buffer_reader;
+MA_PRIVATE ma_result ma_dr_wav_buffer_reader_init(const void* pBuffer, size_t sizeInBytes, ma_dr_wav_buffer_reader* pReader)
{
- DRWAV_ASSERT(pBuffer != NULL);
- DRWAV_ASSERT(pReader != NULL);
- DRWAV_ZERO_OBJECT(pReader);
+ MA_DR_WAV_ASSERT(pBuffer != NULL);
+ MA_DR_WAV_ASSERT(pReader != NULL);
+ MA_DR_WAV_ZERO_OBJECT(pReader);
pReader->pBuffer = pBuffer;
pReader->sizeInBytes = sizeInBytes;
pReader->cursor = 0;
- return DRWAV_SUCCESS;
+ return MA_SUCCESS;
}
-DRWAV_PRIVATE const void* drwav_buffer_reader_ptr(const drwav_buffer_reader* pReader)
+MA_PRIVATE const void* ma_dr_wav_buffer_reader_ptr(const ma_dr_wav_buffer_reader* pReader)
{
- DRWAV_ASSERT(pReader != NULL);
- return drwav_offset_ptr(pReader->pBuffer, pReader->cursor);
+ MA_DR_WAV_ASSERT(pReader != NULL);
+ return ma_dr_wav_offset_ptr(pReader->pBuffer, pReader->cursor);
}
-DRWAV_PRIVATE drwav_result drwav_buffer_reader_seek(drwav_buffer_reader* pReader, size_t bytesToSeek)
+MA_PRIVATE ma_result ma_dr_wav_buffer_reader_seek(ma_dr_wav_buffer_reader* pReader, size_t bytesToSeek)
{
- DRWAV_ASSERT(pReader != NULL);
+ MA_DR_WAV_ASSERT(pReader != NULL);
if (pReader->cursor + bytesToSeek > pReader->sizeInBytes) {
- return DRWAV_BAD_SEEK;
+ return MA_BAD_SEEK;
}
pReader->cursor += bytesToSeek;
- return DRWAV_SUCCESS;
+ return MA_SUCCESS;
}
-DRWAV_PRIVATE drwav_result drwav_buffer_reader_read(drwav_buffer_reader* pReader, void* pDst, size_t bytesToRead, size_t* pBytesRead)
+MA_PRIVATE ma_result ma_dr_wav_buffer_reader_read(ma_dr_wav_buffer_reader* pReader, void* pDst, size_t bytesToRead, size_t* pBytesRead)
{
- drwav_result result = DRWAV_SUCCESS;
+ ma_result result = MA_SUCCESS;
size_t bytesRemaining;
- DRWAV_ASSERT(pReader != NULL);
+ MA_DR_WAV_ASSERT(pReader != NULL);
if (pBytesRead != NULL) {
*pBytesRead = 0;
}
@@ -75317,87 +78043,87 @@ DRWAV_PRIVATE drwav_result drwav_buffer_reader_read(drwav_buffer_reader* pReader
bytesToRead = bytesRemaining;
}
if (pDst == NULL) {
- result = drwav_buffer_reader_seek(pReader, bytesToRead);
+ result = ma_dr_wav_buffer_reader_seek(pReader, bytesToRead);
} else {
- DRWAV_COPY_MEMORY(pDst, drwav_buffer_reader_ptr(pReader), bytesToRead);
+ MA_DR_WAV_COPY_MEMORY(pDst, ma_dr_wav_buffer_reader_ptr(pReader), bytesToRead);
pReader->cursor += bytesToRead;
}
- DRWAV_ASSERT(pReader->cursor <= pReader->sizeInBytes);
- if (result == DRWAV_SUCCESS) {
+ MA_DR_WAV_ASSERT(pReader->cursor <= pReader->sizeInBytes);
+ if (result == MA_SUCCESS) {
if (pBytesRead != NULL) {
*pBytesRead = bytesToRead;
}
}
- return DRWAV_SUCCESS;
+ return MA_SUCCESS;
}
-DRWAV_PRIVATE drwav_result drwav_buffer_reader_read_u16(drwav_buffer_reader* pReader, drwav_uint16* pDst)
+MA_PRIVATE ma_result ma_dr_wav_buffer_reader_read_u16(ma_dr_wav_buffer_reader* pReader, ma_uint16* pDst)
{
- drwav_result result;
+ ma_result result;
size_t bytesRead;
- drwav_uint8 data[2];
- DRWAV_ASSERT(pReader != NULL);
- DRWAV_ASSERT(pDst != NULL);
+ ma_uint8 data[2];
+ MA_DR_WAV_ASSERT(pReader != NULL);
+ MA_DR_WAV_ASSERT(pDst != NULL);
*pDst = 0;
- result = drwav_buffer_reader_read(pReader, data, sizeof(*pDst), &bytesRead);
- if (result != DRWAV_SUCCESS || bytesRead != sizeof(*pDst)) {
+ result = ma_dr_wav_buffer_reader_read(pReader, data, sizeof(*pDst), &bytesRead);
+ if (result != MA_SUCCESS || bytesRead != sizeof(*pDst)) {
return result;
}
- *pDst = drwav_bytes_to_u16(data);
- return DRWAV_SUCCESS;
+ *pDst = ma_dr_wav_bytes_to_u16(data);
+ return MA_SUCCESS;
}
-DRWAV_PRIVATE drwav_result drwav_buffer_reader_read_u32(drwav_buffer_reader* pReader, drwav_uint32* pDst)
+MA_PRIVATE ma_result ma_dr_wav_buffer_reader_read_u32(ma_dr_wav_buffer_reader* pReader, ma_uint32* pDst)
{
- drwav_result result;
+ ma_result result;
size_t bytesRead;
- drwav_uint8 data[4];
- DRWAV_ASSERT(pReader != NULL);
- DRWAV_ASSERT(pDst != NULL);
+ ma_uint8 data[4];
+ MA_DR_WAV_ASSERT(pReader != NULL);
+ MA_DR_WAV_ASSERT(pDst != NULL);
*pDst = 0;
- result = drwav_buffer_reader_read(pReader, data, sizeof(*pDst), &bytesRead);
- if (result != DRWAV_SUCCESS || bytesRead != sizeof(*pDst)) {
+ result = ma_dr_wav_buffer_reader_read(pReader, data, sizeof(*pDst), &bytesRead);
+ if (result != MA_SUCCESS || bytesRead != sizeof(*pDst)) {
return result;
}
- *pDst = drwav_bytes_to_u32(data);
- return DRWAV_SUCCESS;
+ *pDst = ma_dr_wav_bytes_to_u32(data);
+ return MA_SUCCESS;
}
-DRWAV_PRIVATE drwav_uint64 drwav__read_bext_to_metadata_obj(drwav__metadata_parser* pParser, drwav_metadata* pMetadata, drwav_uint64 chunkSize)
+MA_PRIVATE ma_uint64 ma_dr_wav__read_bext_to_metadata_obj(ma_dr_wav__metadata_parser* pParser, ma_dr_wav_metadata* pMetadata, ma_uint64 chunkSize)
{
- drwav_uint8 bextData[DRWAV_BEXT_BYTES];
- size_t bytesRead = drwav__metadata_parser_read(pParser, bextData, sizeof(bextData), NULL);
- DRWAV_ASSERT(pParser->stage == drwav__metadata_parser_stage_read);
+ ma_uint8 bextData[MA_DR_WAV_BEXT_BYTES];
+ size_t bytesRead = ma_dr_wav__metadata_parser_read(pParser, bextData, sizeof(bextData), NULL);
+ MA_DR_WAV_ASSERT(pParser->stage == ma_dr_wav__metadata_parser_stage_read);
if (bytesRead == sizeof(bextData)) {
- drwav_buffer_reader reader;
- drwav_uint32 timeReferenceLow;
- drwav_uint32 timeReferenceHigh;
+ ma_dr_wav_buffer_reader reader;
+ ma_uint32 timeReferenceLow;
+ ma_uint32 timeReferenceHigh;
size_t extraBytes;
- pMetadata->type = drwav_metadata_type_bext;
- if (drwav_buffer_reader_init(bextData, bytesRead, &reader) == DRWAV_SUCCESS) {
- pMetadata->data.bext.pDescription = drwav__metadata_copy_string(pParser, (const char*)drwav_buffer_reader_ptr(&reader), DRWAV_BEXT_DESCRIPTION_BYTES);
- drwav_buffer_reader_seek(&reader, DRWAV_BEXT_DESCRIPTION_BYTES);
- pMetadata->data.bext.pOriginatorName = drwav__metadata_copy_string(pParser, (const char*)drwav_buffer_reader_ptr(&reader), DRWAV_BEXT_ORIGINATOR_NAME_BYTES);
- drwav_buffer_reader_seek(&reader, DRWAV_BEXT_ORIGINATOR_NAME_BYTES);
- pMetadata->data.bext.pOriginatorReference = drwav__metadata_copy_string(pParser, (const char*)drwav_buffer_reader_ptr(&reader), DRWAV_BEXT_ORIGINATOR_REF_BYTES);
- drwav_buffer_reader_seek(&reader, DRWAV_BEXT_ORIGINATOR_REF_BYTES);
- drwav_buffer_reader_read(&reader, pMetadata->data.bext.pOriginationDate, sizeof(pMetadata->data.bext.pOriginationDate), NULL);
- drwav_buffer_reader_read(&reader, pMetadata->data.bext.pOriginationTime, sizeof(pMetadata->data.bext.pOriginationTime), NULL);
- drwav_buffer_reader_read_u32(&reader, &timeReferenceLow);
- drwav_buffer_reader_read_u32(&reader, &timeReferenceHigh);
- pMetadata->data.bext.timeReference = ((drwav_uint64)timeReferenceHigh << 32) + timeReferenceLow;
- drwav_buffer_reader_read_u16(&reader, &pMetadata->data.bext.version);
- pMetadata->data.bext.pUMID = drwav__metadata_get_memory(pParser, DRWAV_BEXT_UMID_BYTES, 1);
- drwav_buffer_reader_read(&reader, pMetadata->data.bext.pUMID, DRWAV_BEXT_UMID_BYTES, NULL);
- drwav_buffer_reader_read_u16(&reader, &pMetadata->data.bext.loudnessValue);
- drwav_buffer_reader_read_u16(&reader, &pMetadata->data.bext.loudnessRange);
- drwav_buffer_reader_read_u16(&reader, &pMetadata->data.bext.maxTruePeakLevel);
- drwav_buffer_reader_read_u16(&reader, &pMetadata->data.bext.maxMomentaryLoudness);
- drwav_buffer_reader_read_u16(&reader, &pMetadata->data.bext.maxShortTermLoudness);
- DRWAV_ASSERT((drwav_offset_ptr(drwav_buffer_reader_ptr(&reader), DRWAV_BEXT_RESERVED_BYTES)) == (bextData + DRWAV_BEXT_BYTES));
- extraBytes = (size_t)(chunkSize - DRWAV_BEXT_BYTES);
+ pMetadata->type = ma_dr_wav_metadata_type_bext;
+ if (ma_dr_wav_buffer_reader_init(bextData, bytesRead, &reader) == MA_SUCCESS) {
+ pMetadata->data.bext.pDescription = ma_dr_wav__metadata_copy_string(pParser, (const char*)ma_dr_wav_buffer_reader_ptr(&reader), MA_DR_WAV_BEXT_DESCRIPTION_BYTES);
+ ma_dr_wav_buffer_reader_seek(&reader, MA_DR_WAV_BEXT_DESCRIPTION_BYTES);
+ pMetadata->data.bext.pOriginatorName = ma_dr_wav__metadata_copy_string(pParser, (const char*)ma_dr_wav_buffer_reader_ptr(&reader), MA_DR_WAV_BEXT_ORIGINATOR_NAME_BYTES);
+ ma_dr_wav_buffer_reader_seek(&reader, MA_DR_WAV_BEXT_ORIGINATOR_NAME_BYTES);
+ pMetadata->data.bext.pOriginatorReference = ma_dr_wav__metadata_copy_string(pParser, (const char*)ma_dr_wav_buffer_reader_ptr(&reader), MA_DR_WAV_BEXT_ORIGINATOR_REF_BYTES);
+ ma_dr_wav_buffer_reader_seek(&reader, MA_DR_WAV_BEXT_ORIGINATOR_REF_BYTES);
+ ma_dr_wav_buffer_reader_read(&reader, pMetadata->data.bext.pOriginationDate, sizeof(pMetadata->data.bext.pOriginationDate), NULL);
+ ma_dr_wav_buffer_reader_read(&reader, pMetadata->data.bext.pOriginationTime, sizeof(pMetadata->data.bext.pOriginationTime), NULL);
+ ma_dr_wav_buffer_reader_read_u32(&reader, &timeReferenceLow);
+ ma_dr_wav_buffer_reader_read_u32(&reader, &timeReferenceHigh);
+ pMetadata->data.bext.timeReference = ((ma_uint64)timeReferenceHigh << 32) + timeReferenceLow;
+ ma_dr_wav_buffer_reader_read_u16(&reader, &pMetadata->data.bext.version);
+ pMetadata->data.bext.pUMID = ma_dr_wav__metadata_get_memory(pParser, MA_DR_WAV_BEXT_UMID_BYTES, 1);
+ ma_dr_wav_buffer_reader_read(&reader, pMetadata->data.bext.pUMID, MA_DR_WAV_BEXT_UMID_BYTES, NULL);
+ ma_dr_wav_buffer_reader_read_u16(&reader, &pMetadata->data.bext.loudnessValue);
+ ma_dr_wav_buffer_reader_read_u16(&reader, &pMetadata->data.bext.loudnessRange);
+ ma_dr_wav_buffer_reader_read_u16(&reader, &pMetadata->data.bext.maxTruePeakLevel);
+ ma_dr_wav_buffer_reader_read_u16(&reader, &pMetadata->data.bext.maxMomentaryLoudness);
+ ma_dr_wav_buffer_reader_read_u16(&reader, &pMetadata->data.bext.maxShortTermLoudness);
+ MA_DR_WAV_ASSERT((ma_dr_wav_offset_ptr(ma_dr_wav_buffer_reader_ptr(&reader), MA_DR_WAV_BEXT_RESERVED_BYTES)) == (bextData + MA_DR_WAV_BEXT_BYTES));
+ extraBytes = (size_t)(chunkSize - MA_DR_WAV_BEXT_BYTES);
if (extraBytes > 0) {
- pMetadata->data.bext.pCodingHistory = (char*)drwav__metadata_get_memory(pParser, extraBytes + 1, 1);
- DRWAV_ASSERT(pMetadata->data.bext.pCodingHistory != NULL);
- bytesRead += drwav__metadata_parser_read(pParser, pMetadata->data.bext.pCodingHistory, extraBytes, NULL);
- pMetadata->data.bext.codingHistorySize = (drwav_uint32)drwav__strlen(pMetadata->data.bext.pCodingHistory);
+ pMetadata->data.bext.pCodingHistory = (char*)ma_dr_wav__metadata_get_memory(pParser, extraBytes + 1, 1);
+ MA_DR_WAV_ASSERT(pMetadata->data.bext.pCodingHistory != NULL);
+ bytesRead += ma_dr_wav__metadata_parser_read(pParser, pMetadata->data.bext.pCodingHistory, extraBytes, NULL);
+ pMetadata->data.bext.codingHistorySize = (ma_uint32)ma_dr_wav__strlen(pMetadata->data.bext.pCodingHistory);
} else {
pMetadata->data.bext.pCodingHistory = NULL;
pMetadata->data.bext.codingHistorySize = 0;
@@ -75406,22 +78132,22 @@ DRWAV_PRIVATE drwav_uint64 drwav__read_bext_to_metadata_obj(drwav__metadata_pars
}
return bytesRead;
}
-DRWAV_PRIVATE drwav_uint64 drwav__read_list_label_or_note_to_metadata_obj(drwav__metadata_parser* pParser, drwav_metadata* pMetadata, drwav_uint64 chunkSize, drwav_metadata_type type)
+MA_PRIVATE ma_uint64 ma_dr_wav__read_list_label_or_note_to_metadata_obj(ma_dr_wav__metadata_parser* pParser, ma_dr_wav_metadata* pMetadata, ma_uint64 chunkSize, ma_dr_wav_metadata_type type)
{
- drwav_uint8 cueIDBuffer[DRWAV_LIST_LABEL_OR_NOTE_BYTES];
- drwav_uint64 totalBytesRead = 0;
- size_t bytesJustRead = drwav__metadata_parser_read(pParser, cueIDBuffer, sizeof(cueIDBuffer), &totalBytesRead);
- DRWAV_ASSERT(pParser->stage == drwav__metadata_parser_stage_read);
+ ma_uint8 cueIDBuffer[MA_DR_WAV_LIST_LABEL_OR_NOTE_BYTES];
+ ma_uint64 totalBytesRead = 0;
+ size_t bytesJustRead = ma_dr_wav__metadata_parser_read(pParser, cueIDBuffer, sizeof(cueIDBuffer), &totalBytesRead);
+ MA_DR_WAV_ASSERT(pParser->stage == ma_dr_wav__metadata_parser_stage_read);
if (bytesJustRead == sizeof(cueIDBuffer)) {
- drwav_uint32 sizeIncludingNullTerminator;
+ ma_uint32 sizeIncludingNullTerminator;
pMetadata->type = type;
- pMetadata->data.labelOrNote.cuePointId = drwav_bytes_to_u32(cueIDBuffer);
- sizeIncludingNullTerminator = (drwav_uint32)chunkSize - DRWAV_LIST_LABEL_OR_NOTE_BYTES;
+ pMetadata->data.labelOrNote.cuePointId = ma_dr_wav_bytes_to_u32(cueIDBuffer);
+ sizeIncludingNullTerminator = (ma_uint32)chunkSize - MA_DR_WAV_LIST_LABEL_OR_NOTE_BYTES;
if (sizeIncludingNullTerminator > 0) {
pMetadata->data.labelOrNote.stringLength = sizeIncludingNullTerminator - 1;
- pMetadata->data.labelOrNote.pString = (char*)drwav__metadata_get_memory(pParser, sizeIncludingNullTerminator, 1);
- DRWAV_ASSERT(pMetadata->data.labelOrNote.pString != NULL);
- drwav__metadata_parser_read(pParser, pMetadata->data.labelOrNote.pString, sizeIncludingNullTerminator, &totalBytesRead);
+ pMetadata->data.labelOrNote.pString = (char*)ma_dr_wav__metadata_get_memory(pParser, sizeIncludingNullTerminator, 1);
+ MA_DR_WAV_ASSERT(pMetadata->data.labelOrNote.pString != NULL);
+ ma_dr_wav__metadata_parser_read(pParser, pMetadata->data.labelOrNote.pString, sizeIncludingNullTerminator, &totalBytesRead);
} else {
pMetadata->data.labelOrNote.stringLength = 0;
pMetadata->data.labelOrNote.pString = NULL;
@@ -75429,31 +78155,31 @@ DRWAV_PRIVATE drwav_uint64 drwav__read_list_label_or_note_to_metadata_obj(drwav_
}
return totalBytesRead;
}
-DRWAV_PRIVATE drwav_uint64 drwav__read_list_labelled_cue_region_to_metadata_obj(drwav__metadata_parser* pParser, drwav_metadata* pMetadata, drwav_uint64 chunkSize)
+MA_PRIVATE ma_uint64 ma_dr_wav__read_list_labelled_cue_region_to_metadata_obj(ma_dr_wav__metadata_parser* pParser, ma_dr_wav_metadata* pMetadata, ma_uint64 chunkSize)
{
- drwav_uint8 buffer[DRWAV_LIST_LABELLED_TEXT_BYTES];
- drwav_uint64 totalBytesRead = 0;
- size_t bytesJustRead = drwav__metadata_parser_read(pParser, buffer, sizeof(buffer), &totalBytesRead);
- DRWAV_ASSERT(pParser->stage == drwav__metadata_parser_stage_read);
+ ma_uint8 buffer[MA_DR_WAV_LIST_LABELLED_TEXT_BYTES];
+ ma_uint64 totalBytesRead = 0;
+ size_t bytesJustRead = ma_dr_wav__metadata_parser_read(pParser, buffer, sizeof(buffer), &totalBytesRead);
+ MA_DR_WAV_ASSERT(pParser->stage == ma_dr_wav__metadata_parser_stage_read);
if (bytesJustRead == sizeof(buffer)) {
- drwav_uint32 sizeIncludingNullTerminator;
- pMetadata->type = drwav_metadata_type_list_labelled_cue_region;
- pMetadata->data.labelledCueRegion.cuePointId = drwav_bytes_to_u32(buffer + 0);
- pMetadata->data.labelledCueRegion.sampleLength = drwav_bytes_to_u32(buffer + 4);
+ ma_uint32 sizeIncludingNullTerminator;
+ pMetadata->type = ma_dr_wav_metadata_type_list_labelled_cue_region;
+ pMetadata->data.labelledCueRegion.cuePointId = ma_dr_wav_bytes_to_u32(buffer + 0);
+ pMetadata->data.labelledCueRegion.sampleLength = ma_dr_wav_bytes_to_u32(buffer + 4);
pMetadata->data.labelledCueRegion.purposeId[0] = buffer[8];
pMetadata->data.labelledCueRegion.purposeId[1] = buffer[9];
pMetadata->data.labelledCueRegion.purposeId[2] = buffer[10];
pMetadata->data.labelledCueRegion.purposeId[3] = buffer[11];
- pMetadata->data.labelledCueRegion.country = drwav_bytes_to_u16(buffer + 12);
- pMetadata->data.labelledCueRegion.language = drwav_bytes_to_u16(buffer + 14);
- pMetadata->data.labelledCueRegion.dialect = drwav_bytes_to_u16(buffer + 16);
- pMetadata->data.labelledCueRegion.codePage = drwav_bytes_to_u16(buffer + 18);
- sizeIncludingNullTerminator = (drwav_uint32)chunkSize - DRWAV_LIST_LABELLED_TEXT_BYTES;
+ pMetadata->data.labelledCueRegion.country = ma_dr_wav_bytes_to_u16(buffer + 12);
+ pMetadata->data.labelledCueRegion.language = ma_dr_wav_bytes_to_u16(buffer + 14);
+ pMetadata->data.labelledCueRegion.dialect = ma_dr_wav_bytes_to_u16(buffer + 16);
+ pMetadata->data.labelledCueRegion.codePage = ma_dr_wav_bytes_to_u16(buffer + 18);
+ sizeIncludingNullTerminator = (ma_uint32)chunkSize - MA_DR_WAV_LIST_LABELLED_TEXT_BYTES;
if (sizeIncludingNullTerminator > 0) {
pMetadata->data.labelledCueRegion.stringLength = sizeIncludingNullTerminator - 1;
- pMetadata->data.labelledCueRegion.pString = (char*)drwav__metadata_get_memory(pParser, sizeIncludingNullTerminator, 1);
- DRWAV_ASSERT(pMetadata->data.labelledCueRegion.pString != NULL);
- drwav__metadata_parser_read(pParser, pMetadata->data.labelledCueRegion.pString, sizeIncludingNullTerminator, &totalBytesRead);
+ pMetadata->data.labelledCueRegion.pString = (char*)ma_dr_wav__metadata_get_memory(pParser, sizeIncludingNullTerminator, 1);
+ MA_DR_WAV_ASSERT(pMetadata->data.labelledCueRegion.pString != NULL);
+ ma_dr_wav__metadata_parser_read(pParser, pMetadata->data.labelledCueRegion.pString, sizeIncludingNullTerminator, &totalBytesRead);
} else {
pMetadata->data.labelledCueRegion.stringLength = 0;
pMetadata->data.labelledCueRegion.pString = NULL;
@@ -75461,21 +78187,21 @@ DRWAV_PRIVATE drwav_uint64 drwav__read_list_labelled_cue_region_to_metadata_obj(
}
return totalBytesRead;
}
-DRWAV_PRIVATE drwav_uint64 drwav__metadata_process_info_text_chunk(drwav__metadata_parser* pParser, drwav_uint64 chunkSize, drwav_metadata_type type)
+MA_PRIVATE ma_uint64 ma_dr_wav__metadata_process_info_text_chunk(ma_dr_wav__metadata_parser* pParser, ma_uint64 chunkSize, ma_dr_wav_metadata_type type)
{
- drwav_uint64 bytesRead = 0;
- drwav_uint32 stringSizeWithNullTerminator = (drwav_uint32)chunkSize;
- if (pParser->stage == drwav__metadata_parser_stage_count) {
+ ma_uint64 bytesRead = 0;
+ ma_uint32 stringSizeWithNullTerminator = (ma_uint32)chunkSize;
+ if (pParser->stage == ma_dr_wav__metadata_parser_stage_count) {
pParser->metadataCount += 1;
- drwav__metadata_request_extra_memory_for_stage_2(pParser, stringSizeWithNullTerminator, 1);
+ ma_dr_wav__metadata_request_extra_memory_for_stage_2(pParser, stringSizeWithNullTerminator, 1);
} else {
- drwav_metadata* pMetadata = &pParser->pMetadata[pParser->metadataCursor];
+ ma_dr_wav_metadata* pMetadata = &pParser->pMetadata[pParser->metadataCursor];
pMetadata->type = type;
if (stringSizeWithNullTerminator > 0) {
pMetadata->data.infoText.stringLength = stringSizeWithNullTerminator - 1;
- pMetadata->data.infoText.pString = (char*)drwav__metadata_get_memory(pParser, stringSizeWithNullTerminator, 1);
- DRWAV_ASSERT(pMetadata->data.infoText.pString != NULL);
- bytesRead = drwav__metadata_parser_read(pParser, pMetadata->data.infoText.pString, (size_t)stringSizeWithNullTerminator, NULL);
+ pMetadata->data.infoText.pString = (char*)ma_dr_wav__metadata_get_memory(pParser, stringSizeWithNullTerminator, 1);
+ MA_DR_WAV_ASSERT(pMetadata->data.infoText.pString != NULL);
+ bytesRead = ma_dr_wav__metadata_parser_read(pParser, pMetadata->data.infoText.pString, (size_t)stringSizeWithNullTerminator, NULL);
if (bytesRead == chunkSize) {
pParser->metadataCursor += 1;
} else {
@@ -75488,30 +78214,30 @@ DRWAV_PRIVATE drwav_uint64 drwav__metadata_process_info_text_chunk(drwav__metada
}
return bytesRead;
}
-DRWAV_PRIVATE drwav_uint64 drwav__metadata_process_unknown_chunk(drwav__metadata_parser* pParser, const drwav_uint8* pChunkId, drwav_uint64 chunkSize, drwav_metadata_location location)
+MA_PRIVATE ma_uint64 ma_dr_wav__metadata_process_unknown_chunk(ma_dr_wav__metadata_parser* pParser, const ma_uint8* pChunkId, ma_uint64 chunkSize, ma_dr_wav_metadata_location location)
{
- drwav_uint64 bytesRead = 0;
- if (location == drwav_metadata_location_invalid) {
+ ma_uint64 bytesRead = 0;
+ if (location == ma_dr_wav_metadata_location_invalid) {
return 0;
}
- if (drwav_fourcc_equal(pChunkId, "data") || drwav_fourcc_equal(pChunkId, "fmt") || drwav_fourcc_equal(pChunkId, "fact")) {
+ if (ma_dr_wav_fourcc_equal(pChunkId, "data") || ma_dr_wav_fourcc_equal(pChunkId, "fmt ") || ma_dr_wav_fourcc_equal(pChunkId, "fact")) {
return 0;
}
- if (pParser->stage == drwav__metadata_parser_stage_count) {
+ if (pParser->stage == ma_dr_wav__metadata_parser_stage_count) {
pParser->metadataCount += 1;
- drwav__metadata_request_extra_memory_for_stage_2(pParser, (size_t)chunkSize, 1);
+ ma_dr_wav__metadata_request_extra_memory_for_stage_2(pParser, (size_t)chunkSize, 1);
} else {
- drwav_metadata* pMetadata = &pParser->pMetadata[pParser->metadataCursor];
- pMetadata->type = drwav_metadata_type_unknown;
+ ma_dr_wav_metadata* pMetadata = &pParser->pMetadata[pParser->metadataCursor];
+ pMetadata->type = ma_dr_wav_metadata_type_unknown;
pMetadata->data.unknown.chunkLocation = location;
pMetadata->data.unknown.id[0] = pChunkId[0];
pMetadata->data.unknown.id[1] = pChunkId[1];
pMetadata->data.unknown.id[2] = pChunkId[2];
pMetadata->data.unknown.id[3] = pChunkId[3];
- pMetadata->data.unknown.dataSizeInBytes = (drwav_uint32)chunkSize;
- pMetadata->data.unknown.pData = (drwav_uint8 *)drwav__metadata_get_memory(pParser, (size_t)chunkSize, 1);
- DRWAV_ASSERT(pMetadata->data.unknown.pData != NULL);
- bytesRead = drwav__metadata_parser_read(pParser, pMetadata->data.unknown.pData, pMetadata->data.unknown.dataSizeInBytes, NULL);
+ pMetadata->data.unknown.dataSizeInBytes = (ma_uint32)chunkSize;
+ pMetadata->data.unknown.pData = (ma_uint8 *)ma_dr_wav__metadata_get_memory(pParser, (size_t)chunkSize, 1);
+ MA_DR_WAV_ASSERT(pMetadata->data.unknown.pData != NULL);
+ bytesRead = ma_dr_wav__metadata_parser_read(pParser, pMetadata->data.unknown.pData, pMetadata->data.unknown.dataSizeInBytes, NULL);
if (bytesRead == pMetadata->data.unknown.dataSizeInBytes) {
pParser->metadataCursor += 1;
} else {
@@ -75519,41 +78245,41 @@ DRWAV_PRIVATE drwav_uint64 drwav__metadata_process_unknown_chunk(drwav__metadata
}
return bytesRead;
}
-DRWAV_PRIVATE drwav_bool32 drwav__chunk_matches(drwav_metadata_type allowedMetadataTypes, const drwav_uint8* pChunkID, drwav_metadata_type type, const char* pID)
+MA_PRIVATE ma_bool32 ma_dr_wav__chunk_matches(ma_dr_wav_metadata_type allowedMetadataTypes, const ma_uint8* pChunkID, ma_dr_wav_metadata_type type, const char* pID)
{
- return (allowedMetadataTypes & type) && drwav_fourcc_equal(pChunkID, pID);
+ return (allowedMetadataTypes & type) && ma_dr_wav_fourcc_equal(pChunkID, pID);
}
-DRWAV_PRIVATE drwav_uint64 drwav__metadata_process_chunk(drwav__metadata_parser* pParser, const drwav_chunk_header* pChunkHeader, drwav_metadata_type allowedMetadataTypes)
+MA_PRIVATE ma_uint64 ma_dr_wav__metadata_process_chunk(ma_dr_wav__metadata_parser* pParser, const ma_dr_wav_chunk_header* pChunkHeader, ma_dr_wav_metadata_type allowedMetadataTypes)
{
- const drwav_uint8 *pChunkID = pChunkHeader->id.fourcc;
- drwav_uint64 bytesRead = 0;
- if (drwav__chunk_matches(allowedMetadataTypes, pChunkID, drwav_metadata_type_smpl, "smpl")) {
- if (pChunkHeader->sizeInBytes >= DRWAV_SMPL_BYTES) {
- if (pParser->stage == drwav__metadata_parser_stage_count) {
- drwav_uint8 buffer[4];
+ const ma_uint8 *pChunkID = pChunkHeader->id.fourcc;
+ ma_uint64 bytesRead = 0;
+ if (ma_dr_wav__chunk_matches(allowedMetadataTypes, pChunkID, ma_dr_wav_metadata_type_smpl, "smpl")) {
+ if (pChunkHeader->sizeInBytes >= MA_DR_WAV_SMPL_BYTES) {
+ if (pParser->stage == ma_dr_wav__metadata_parser_stage_count) {
+ ma_uint8 buffer[4];
size_t bytesJustRead;
- if (!pParser->onSeek(pParser->pReadSeekUserData, 28, drwav_seek_origin_current)) {
+ if (!pParser->onSeek(pParser->pReadSeekUserData, 28, ma_dr_wav_seek_origin_current)) {
return bytesRead;
}
bytesRead += 28;
- bytesJustRead = drwav__metadata_parser_read(pParser, buffer, sizeof(buffer), &bytesRead);
+ bytesJustRead = ma_dr_wav__metadata_parser_read(pParser, buffer, sizeof(buffer), &bytesRead);
if (bytesJustRead == sizeof(buffer)) {
- drwav_uint32 loopCount = drwav_bytes_to_u32(buffer);
- drwav_uint64 calculatedLoopCount;
- calculatedLoopCount = (pChunkHeader->sizeInBytes - DRWAV_SMPL_BYTES) / DRWAV_SMPL_LOOP_BYTES;
+ ma_uint32 loopCount = ma_dr_wav_bytes_to_u32(buffer);
+ ma_uint64 calculatedLoopCount;
+ calculatedLoopCount = (pChunkHeader->sizeInBytes - MA_DR_WAV_SMPL_BYTES) / MA_DR_WAV_SMPL_LOOP_BYTES;
if (calculatedLoopCount == loopCount) {
- bytesJustRead = drwav__metadata_parser_read(pParser, buffer, sizeof(buffer), &bytesRead);
+ bytesJustRead = ma_dr_wav__metadata_parser_read(pParser, buffer, sizeof(buffer), &bytesRead);
if (bytesJustRead == sizeof(buffer)) {
- drwav_uint32 samplerSpecificDataSizeInBytes = drwav_bytes_to_u32(buffer);
+ ma_uint32 samplerSpecificDataSizeInBytes = ma_dr_wav_bytes_to_u32(buffer);
pParser->metadataCount += 1;
- drwav__metadata_request_extra_memory_for_stage_2(pParser, sizeof(drwav_smpl_loop) * loopCount, DRWAV_METADATA_ALIGNMENT);
- drwav__metadata_request_extra_memory_for_stage_2(pParser, samplerSpecificDataSizeInBytes, 1);
+ ma_dr_wav__metadata_request_extra_memory_for_stage_2(pParser, sizeof(ma_dr_wav_smpl_loop) * loopCount, MA_DR_WAV_METADATA_ALIGNMENT);
+ ma_dr_wav__metadata_request_extra_memory_for_stage_2(pParser, samplerSpecificDataSizeInBytes, 1);
}
} else {
}
}
} else {
- bytesRead = drwav__read_smpl_to_metadata_obj(pParser, pChunkHeader, &pParser->pMetadata[pParser->metadataCursor]);
+ bytesRead = ma_dr_wav__read_smpl_to_metadata_obj(pParser, pChunkHeader, &pParser->pMetadata[pParser->metadataCursor]);
if (bytesRead == pChunkHeader->sizeInBytes) {
pParser->metadataCursor += 1;
} else {
@@ -75561,12 +78287,12 @@ DRWAV_PRIVATE drwav_uint64 drwav__metadata_process_chunk(drwav__metadata_parser*
}
} else {
}
- } else if (drwav__chunk_matches(allowedMetadataTypes, pChunkID, drwav_metadata_type_inst, "inst")) {
- if (pChunkHeader->sizeInBytes == DRWAV_INST_BYTES) {
- if (pParser->stage == drwav__metadata_parser_stage_count) {
+ } else if (ma_dr_wav__chunk_matches(allowedMetadataTypes, pChunkID, ma_dr_wav_metadata_type_inst, "inst")) {
+ if (pChunkHeader->sizeInBytes == MA_DR_WAV_INST_BYTES) {
+ if (pParser->stage == ma_dr_wav__metadata_parser_stage_count) {
pParser->metadataCount += 1;
} else {
- bytesRead = drwav__read_inst_to_metadata_obj(pParser, &pParser->pMetadata[pParser->metadataCursor]);
+ bytesRead = ma_dr_wav__read_inst_to_metadata_obj(pParser, &pParser->pMetadata[pParser->metadataCursor]);
if (bytesRead == pChunkHeader->sizeInBytes) {
pParser->metadataCursor += 1;
} else {
@@ -75574,12 +78300,12 @@ DRWAV_PRIVATE drwav_uint64 drwav__metadata_process_chunk(drwav__metadata_parser*
}
} else {
}
- } else if (drwav__chunk_matches(allowedMetadataTypes, pChunkID, drwav_metadata_type_acid, "acid")) {
- if (pChunkHeader->sizeInBytes == DRWAV_ACID_BYTES) {
- if (pParser->stage == drwav__metadata_parser_stage_count) {
+ } else if (ma_dr_wav__chunk_matches(allowedMetadataTypes, pChunkID, ma_dr_wav_metadata_type_acid, "acid")) {
+ if (pChunkHeader->sizeInBytes == MA_DR_WAV_ACID_BYTES) {
+ if (pParser->stage == ma_dr_wav__metadata_parser_stage_count) {
pParser->metadataCount += 1;
} else {
- bytesRead = drwav__read_acid_to_metadata_obj(pParser, &pParser->pMetadata[pParser->metadataCursor]);
+ bytesRead = ma_dr_wav__read_acid_to_metadata_obj(pParser, &pParser->pMetadata[pParser->metadataCursor]);
if (bytesRead == pChunkHeader->sizeInBytes) {
pParser->metadataCursor += 1;
} else {
@@ -75587,15 +78313,15 @@ DRWAV_PRIVATE drwav_uint64 drwav__metadata_process_chunk(drwav__metadata_parser*
}
} else {
}
- } else if (drwav__chunk_matches(allowedMetadataTypes, pChunkID, drwav_metadata_type_cue, "cue ")) {
- if (pChunkHeader->sizeInBytes >= DRWAV_CUE_BYTES) {
- if (pParser->stage == drwav__metadata_parser_stage_count) {
+ } else if (ma_dr_wav__chunk_matches(allowedMetadataTypes, pChunkID, ma_dr_wav_metadata_type_cue, "cue ")) {
+ if (pChunkHeader->sizeInBytes >= MA_DR_WAV_CUE_BYTES) {
+ if (pParser->stage == ma_dr_wav__metadata_parser_stage_count) {
size_t cueCount;
pParser->metadataCount += 1;
- cueCount = (size_t)(pChunkHeader->sizeInBytes - DRWAV_CUE_BYTES) / DRWAV_CUE_POINT_BYTES;
- drwav__metadata_request_extra_memory_for_stage_2(pParser, sizeof(drwav_cue_point) * cueCount, DRWAV_METADATA_ALIGNMENT);
+ cueCount = (size_t)(pChunkHeader->sizeInBytes - MA_DR_WAV_CUE_BYTES) / MA_DR_WAV_CUE_POINT_BYTES;
+ ma_dr_wav__metadata_request_extra_memory_for_stage_2(pParser, sizeof(ma_dr_wav_cue_point) * cueCount, MA_DR_WAV_METADATA_ALIGNMENT);
} else {
- bytesRead = drwav__read_cue_to_metadata_obj(pParser, pChunkHeader, &pParser->pMetadata[pParser->metadataCursor]);
+ bytesRead = ma_dr_wav__read_cue_to_metadata_obj(pParser, pChunkHeader, &pParser->pMetadata[pParser->metadataCursor]);
if (bytesRead == pChunkHeader->sizeInBytes) {
pParser->metadataCursor += 1;
} else {
@@ -75603,35 +78329,35 @@ DRWAV_PRIVATE drwav_uint64 drwav__metadata_process_chunk(drwav__metadata_parser*
}
} else {
}
- } else if (drwav__chunk_matches(allowedMetadataTypes, pChunkID, drwav_metadata_type_bext, "bext")) {
- if (pChunkHeader->sizeInBytes >= DRWAV_BEXT_BYTES) {
- if (pParser->stage == drwav__metadata_parser_stage_count) {
- char buffer[DRWAV_BEXT_DESCRIPTION_BYTES + 1];
- size_t allocSizeNeeded = DRWAV_BEXT_UMID_BYTES;
+ } else if (ma_dr_wav__chunk_matches(allowedMetadataTypes, pChunkID, ma_dr_wav_metadata_type_bext, "bext")) {
+ if (pChunkHeader->sizeInBytes >= MA_DR_WAV_BEXT_BYTES) {
+ if (pParser->stage == ma_dr_wav__metadata_parser_stage_count) {
+ char buffer[MA_DR_WAV_BEXT_DESCRIPTION_BYTES + 1];
+ size_t allocSizeNeeded = MA_DR_WAV_BEXT_UMID_BYTES;
size_t bytesJustRead;
- buffer[DRWAV_BEXT_DESCRIPTION_BYTES] = '\0';
- bytesJustRead = drwav__metadata_parser_read(pParser, buffer, DRWAV_BEXT_DESCRIPTION_BYTES, &bytesRead);
- if (bytesJustRead != DRWAV_BEXT_DESCRIPTION_BYTES) {
+ buffer[MA_DR_WAV_BEXT_DESCRIPTION_BYTES] = '\0';
+ bytesJustRead = ma_dr_wav__metadata_parser_read(pParser, buffer, MA_DR_WAV_BEXT_DESCRIPTION_BYTES, &bytesRead);
+ if (bytesJustRead != MA_DR_WAV_BEXT_DESCRIPTION_BYTES) {
return bytesRead;
}
- allocSizeNeeded += drwav__strlen(buffer) + 1;
- buffer[DRWAV_BEXT_ORIGINATOR_NAME_BYTES] = '\0';
- bytesJustRead = drwav__metadata_parser_read(pParser, buffer, DRWAV_BEXT_ORIGINATOR_NAME_BYTES, &bytesRead);
- if (bytesJustRead != DRWAV_BEXT_ORIGINATOR_NAME_BYTES) {
+ allocSizeNeeded += ma_dr_wav__strlen(buffer) + 1;
+ buffer[MA_DR_WAV_BEXT_ORIGINATOR_NAME_BYTES] = '\0';
+ bytesJustRead = ma_dr_wav__metadata_parser_read(pParser, buffer, MA_DR_WAV_BEXT_ORIGINATOR_NAME_BYTES, &bytesRead);
+ if (bytesJustRead != MA_DR_WAV_BEXT_ORIGINATOR_NAME_BYTES) {
return bytesRead;
}
- allocSizeNeeded += drwav__strlen(buffer) + 1;
- buffer[DRWAV_BEXT_ORIGINATOR_REF_BYTES] = '\0';
- bytesJustRead = drwav__metadata_parser_read(pParser, buffer, DRWAV_BEXT_ORIGINATOR_REF_BYTES, &bytesRead);
- if (bytesJustRead != DRWAV_BEXT_ORIGINATOR_REF_BYTES) {
+ allocSizeNeeded += ma_dr_wav__strlen(buffer) + 1;
+ buffer[MA_DR_WAV_BEXT_ORIGINATOR_REF_BYTES] = '\0';
+ bytesJustRead = ma_dr_wav__metadata_parser_read(pParser, buffer, MA_DR_WAV_BEXT_ORIGINATOR_REF_BYTES, &bytesRead);
+ if (bytesJustRead != MA_DR_WAV_BEXT_ORIGINATOR_REF_BYTES) {
return bytesRead;
}
- allocSizeNeeded += drwav__strlen(buffer) + 1;
- allocSizeNeeded += (size_t)pChunkHeader->sizeInBytes - DRWAV_BEXT_BYTES;
- drwav__metadata_request_extra_memory_for_stage_2(pParser, allocSizeNeeded, 1);
+ allocSizeNeeded += ma_dr_wav__strlen(buffer) + 1;
+ allocSizeNeeded += (size_t)pChunkHeader->sizeInBytes - MA_DR_WAV_BEXT_BYTES;
+ ma_dr_wav__metadata_request_extra_memory_for_stage_2(pParser, allocSizeNeeded, 1);
pParser->metadataCount += 1;
} else {
- bytesRead = drwav__read_bext_to_metadata_obj(pParser, &pParser->pMetadata[pParser->metadataCursor], pChunkHeader->sizeInBytes);
+ bytesRead = ma_dr_wav__read_bext_to_metadata_obj(pParser, &pParser->pMetadata[pParser->metadataCursor], pChunkHeader->sizeInBytes);
if (bytesRead == pChunkHeader->sizeInBytes) {
pParser->metadataCursor += 1;
} else {
@@ -75639,37 +78365,37 @@ DRWAV_PRIVATE drwav_uint64 drwav__metadata_process_chunk(drwav__metadata_parser*
}
} else {
}
- } else if (drwav_fourcc_equal(pChunkID, "LIST") || drwav_fourcc_equal(pChunkID, "list")) {
- drwav_metadata_location listType = drwav_metadata_location_invalid;
+ } else if (ma_dr_wav_fourcc_equal(pChunkID, "LIST") || ma_dr_wav_fourcc_equal(pChunkID, "list")) {
+ ma_dr_wav_metadata_location listType = ma_dr_wav_metadata_location_invalid;
while (bytesRead < pChunkHeader->sizeInBytes) {
- drwav_uint8 subchunkId[4];
- drwav_uint8 subchunkSizeBuffer[4];
- drwav_uint64 subchunkDataSize;
- drwav_uint64 subchunkBytesRead = 0;
- drwav_uint64 bytesJustRead = drwav__metadata_parser_read(pParser, subchunkId, sizeof(subchunkId), &bytesRead);
+ ma_uint8 subchunkId[4];
+ ma_uint8 subchunkSizeBuffer[4];
+ ma_uint64 subchunkDataSize;
+ ma_uint64 subchunkBytesRead = 0;
+ ma_uint64 bytesJustRead = ma_dr_wav__metadata_parser_read(pParser, subchunkId, sizeof(subchunkId), &bytesRead);
if (bytesJustRead != sizeof(subchunkId)) {
break;
}
- if (drwav_fourcc_equal(subchunkId, "adtl")) {
- listType = drwav_metadata_location_inside_adtl_list;
+ if (ma_dr_wav_fourcc_equal(subchunkId, "adtl")) {
+ listType = ma_dr_wav_metadata_location_inside_adtl_list;
continue;
- } else if (drwav_fourcc_equal(subchunkId, "INFO")) {
- listType = drwav_metadata_location_inside_info_list;
+ } else if (ma_dr_wav_fourcc_equal(subchunkId, "INFO")) {
+ listType = ma_dr_wav_metadata_location_inside_info_list;
continue;
}
- bytesJustRead = drwav__metadata_parser_read(pParser, subchunkSizeBuffer, sizeof(subchunkSizeBuffer), &bytesRead);
+ bytesJustRead = ma_dr_wav__metadata_parser_read(pParser, subchunkSizeBuffer, sizeof(subchunkSizeBuffer), &bytesRead);
if (bytesJustRead != sizeof(subchunkSizeBuffer)) {
break;
}
- subchunkDataSize = drwav_bytes_to_u32(subchunkSizeBuffer);
- if (drwav__chunk_matches(allowedMetadataTypes, subchunkId, drwav_metadata_type_list_label, "labl") || drwav__chunk_matches(allowedMetadataTypes, subchunkId, drwav_metadata_type_list_note, "note")) {
- if (subchunkDataSize >= DRWAV_LIST_LABEL_OR_NOTE_BYTES) {
- drwav_uint64 stringSizeWithNullTerm = subchunkDataSize - DRWAV_LIST_LABEL_OR_NOTE_BYTES;
- if (pParser->stage == drwav__metadata_parser_stage_count) {
+ subchunkDataSize = ma_dr_wav_bytes_to_u32(subchunkSizeBuffer);
+ if (ma_dr_wav__chunk_matches(allowedMetadataTypes, subchunkId, ma_dr_wav_metadata_type_list_label, "labl") || ma_dr_wav__chunk_matches(allowedMetadataTypes, subchunkId, ma_dr_wav_metadata_type_list_note, "note")) {
+ if (subchunkDataSize >= MA_DR_WAV_LIST_LABEL_OR_NOTE_BYTES) {
+ ma_uint64 stringSizeWithNullTerm = subchunkDataSize - MA_DR_WAV_LIST_LABEL_OR_NOTE_BYTES;
+ if (pParser->stage == ma_dr_wav__metadata_parser_stage_count) {
pParser->metadataCount += 1;
- drwav__metadata_request_extra_memory_for_stage_2(pParser, (size_t)stringSizeWithNullTerm, 1);
+ ma_dr_wav__metadata_request_extra_memory_for_stage_2(pParser, (size_t)stringSizeWithNullTerm, 1);
} else {
- subchunkBytesRead = drwav__read_list_label_or_note_to_metadata_obj(pParser, &pParser->pMetadata[pParser->metadataCursor], subchunkDataSize, drwav_fourcc_equal(subchunkId, "labl") ? drwav_metadata_type_list_label : drwav_metadata_type_list_note);
+ subchunkBytesRead = ma_dr_wav__read_list_label_or_note_to_metadata_obj(pParser, &pParser->pMetadata[pParser->metadataCursor], subchunkDataSize, ma_dr_wav_fourcc_equal(subchunkId, "labl") ? ma_dr_wav_metadata_type_list_label : ma_dr_wav_metadata_type_list_note);
if (subchunkBytesRead == subchunkDataSize) {
pParser->metadataCursor += 1;
} else {
@@ -75677,14 +78403,14 @@ DRWAV_PRIVATE drwav_uint64 drwav__metadata_process_chunk(drwav__metadata_parser*
}
} else {
}
- } else if (drwav__chunk_matches(allowedMetadataTypes, subchunkId, drwav_metadata_type_list_labelled_cue_region, "ltxt")) {
- if (subchunkDataSize >= DRWAV_LIST_LABELLED_TEXT_BYTES) {
- drwav_uint64 stringSizeWithNullTerminator = subchunkDataSize - DRWAV_LIST_LABELLED_TEXT_BYTES;
- if (pParser->stage == drwav__metadata_parser_stage_count) {
+ } else if (ma_dr_wav__chunk_matches(allowedMetadataTypes, subchunkId, ma_dr_wav_metadata_type_list_labelled_cue_region, "ltxt")) {
+ if (subchunkDataSize >= MA_DR_WAV_LIST_LABELLED_TEXT_BYTES) {
+ ma_uint64 stringSizeWithNullTerminator = subchunkDataSize - MA_DR_WAV_LIST_LABELLED_TEXT_BYTES;
+ if (pParser->stage == ma_dr_wav__metadata_parser_stage_count) {
pParser->metadataCount += 1;
- drwav__metadata_request_extra_memory_for_stage_2(pParser, (size_t)stringSizeWithNullTerminator, 1);
+ ma_dr_wav__metadata_request_extra_memory_for_stage_2(pParser, (size_t)stringSizeWithNullTerminator, 1);
} else {
- subchunkBytesRead = drwav__read_list_labelled_cue_region_to_metadata_obj(pParser, &pParser->pMetadata[pParser->metadataCursor], subchunkDataSize);
+ subchunkBytesRead = ma_dr_wav__read_list_labelled_cue_region_to_metadata_obj(pParser, &pParser->pMetadata[pParser->metadataCursor], subchunkDataSize);
if (subchunkBytesRead == subchunkDataSize) {
pParser->metadataCursor += 1;
} else {
@@ -75692,332 +78418,542 @@ DRWAV_PRIVATE drwav_uint64 drwav__metadata_process_chunk(drwav__metadata_parser*
}
} else {
}
- } else if (drwav__chunk_matches(allowedMetadataTypes, subchunkId, drwav_metadata_type_list_info_software, "ISFT")) {
- subchunkBytesRead = drwav__metadata_process_info_text_chunk(pParser, subchunkDataSize, drwav_metadata_type_list_info_software);
- } else if (drwav__chunk_matches(allowedMetadataTypes, subchunkId, drwav_metadata_type_list_info_copyright, "ICOP")) {
- subchunkBytesRead = drwav__metadata_process_info_text_chunk(pParser, subchunkDataSize, drwav_metadata_type_list_info_copyright);
- } else if (drwav__chunk_matches(allowedMetadataTypes, subchunkId, drwav_metadata_type_list_info_title, "INAM")) {
- subchunkBytesRead = drwav__metadata_process_info_text_chunk(pParser, subchunkDataSize, drwav_metadata_type_list_info_title);
- } else if (drwav__chunk_matches(allowedMetadataTypes, subchunkId, drwav_metadata_type_list_info_artist, "IART")) {
- subchunkBytesRead = drwav__metadata_process_info_text_chunk(pParser, subchunkDataSize, drwav_metadata_type_list_info_artist);
- } else if (drwav__chunk_matches(allowedMetadataTypes, subchunkId, drwav_metadata_type_list_info_comment, "ICMT")) {
- subchunkBytesRead = drwav__metadata_process_info_text_chunk(pParser, subchunkDataSize, drwav_metadata_type_list_info_comment);
- } else if (drwav__chunk_matches(allowedMetadataTypes, subchunkId, drwav_metadata_type_list_info_date, "ICRD")) {
- subchunkBytesRead = drwav__metadata_process_info_text_chunk(pParser, subchunkDataSize, drwav_metadata_type_list_info_date);
- } else if (drwav__chunk_matches(allowedMetadataTypes, subchunkId, drwav_metadata_type_list_info_genre, "IGNR")) {
- subchunkBytesRead = drwav__metadata_process_info_text_chunk(pParser, subchunkDataSize, drwav_metadata_type_list_info_genre);
- } else if (drwav__chunk_matches(allowedMetadataTypes, subchunkId, drwav_metadata_type_list_info_album, "IPRD")) {
- subchunkBytesRead = drwav__metadata_process_info_text_chunk(pParser, subchunkDataSize, drwav_metadata_type_list_info_album);
- } else if (drwav__chunk_matches(allowedMetadataTypes, subchunkId, drwav_metadata_type_list_info_tracknumber, "ITRK")) {
- subchunkBytesRead = drwav__metadata_process_info_text_chunk(pParser, subchunkDataSize, drwav_metadata_type_list_info_tracknumber);
- } else if ((allowedMetadataTypes & drwav_metadata_type_unknown) != 0) {
- subchunkBytesRead = drwav__metadata_process_unknown_chunk(pParser, subchunkId, subchunkDataSize, listType);
+ } else if (ma_dr_wav__chunk_matches(allowedMetadataTypes, subchunkId, ma_dr_wav_metadata_type_list_info_software, "ISFT")) {
+ subchunkBytesRead = ma_dr_wav__metadata_process_info_text_chunk(pParser, subchunkDataSize, ma_dr_wav_metadata_type_list_info_software);
+ } else if (ma_dr_wav__chunk_matches(allowedMetadataTypes, subchunkId, ma_dr_wav_metadata_type_list_info_copyright, "ICOP")) {
+ subchunkBytesRead = ma_dr_wav__metadata_process_info_text_chunk(pParser, subchunkDataSize, ma_dr_wav_metadata_type_list_info_copyright);
+ } else if (ma_dr_wav__chunk_matches(allowedMetadataTypes, subchunkId, ma_dr_wav_metadata_type_list_info_title, "INAM")) {
+ subchunkBytesRead = ma_dr_wav__metadata_process_info_text_chunk(pParser, subchunkDataSize, ma_dr_wav_metadata_type_list_info_title);
+ } else if (ma_dr_wav__chunk_matches(allowedMetadataTypes, subchunkId, ma_dr_wav_metadata_type_list_info_artist, "IART")) {
+ subchunkBytesRead = ma_dr_wav__metadata_process_info_text_chunk(pParser, subchunkDataSize, ma_dr_wav_metadata_type_list_info_artist);
+ } else if (ma_dr_wav__chunk_matches(allowedMetadataTypes, subchunkId, ma_dr_wav_metadata_type_list_info_comment, "ICMT")) {
+ subchunkBytesRead = ma_dr_wav__metadata_process_info_text_chunk(pParser, subchunkDataSize, ma_dr_wav_metadata_type_list_info_comment);
+ } else if (ma_dr_wav__chunk_matches(allowedMetadataTypes, subchunkId, ma_dr_wav_metadata_type_list_info_date, "ICRD")) {
+ subchunkBytesRead = ma_dr_wav__metadata_process_info_text_chunk(pParser, subchunkDataSize, ma_dr_wav_metadata_type_list_info_date);
+ } else if (ma_dr_wav__chunk_matches(allowedMetadataTypes, subchunkId, ma_dr_wav_metadata_type_list_info_genre, "IGNR")) {
+ subchunkBytesRead = ma_dr_wav__metadata_process_info_text_chunk(pParser, subchunkDataSize, ma_dr_wav_metadata_type_list_info_genre);
+ } else if (ma_dr_wav__chunk_matches(allowedMetadataTypes, subchunkId, ma_dr_wav_metadata_type_list_info_album, "IPRD")) {
+ subchunkBytesRead = ma_dr_wav__metadata_process_info_text_chunk(pParser, subchunkDataSize, ma_dr_wav_metadata_type_list_info_album);
+ } else if (ma_dr_wav__chunk_matches(allowedMetadataTypes, subchunkId, ma_dr_wav_metadata_type_list_info_tracknumber, "ITRK")) {
+ subchunkBytesRead = ma_dr_wav__metadata_process_info_text_chunk(pParser, subchunkDataSize, ma_dr_wav_metadata_type_list_info_tracknumber);
+ } else if ((allowedMetadataTypes & ma_dr_wav_metadata_type_unknown) != 0) {
+ subchunkBytesRead = ma_dr_wav__metadata_process_unknown_chunk(pParser, subchunkId, subchunkDataSize, listType);
}
bytesRead += subchunkBytesRead;
- DRWAV_ASSERT(subchunkBytesRead <= subchunkDataSize);
+ MA_DR_WAV_ASSERT(subchunkBytesRead <= subchunkDataSize);
if (subchunkBytesRead < subchunkDataSize) {
- drwav_uint64 bytesToSeek = subchunkDataSize - subchunkBytesRead;
- if (!pParser->onSeek(pParser->pReadSeekUserData, (int)bytesToSeek, drwav_seek_origin_current)) {
+ ma_uint64 bytesToSeek = subchunkDataSize - subchunkBytesRead;
+ if (!pParser->onSeek(pParser->pReadSeekUserData, (int)bytesToSeek, ma_dr_wav_seek_origin_current)) {
break;
}
bytesRead += bytesToSeek;
}
if ((subchunkDataSize % 2) == 1) {
- if (!pParser->onSeek(pParser->pReadSeekUserData, 1, drwav_seek_origin_current)) {
+ if (!pParser->onSeek(pParser->pReadSeekUserData, 1, ma_dr_wav_seek_origin_current)) {
break;
}
bytesRead += 1;
}
}
- } else if ((allowedMetadataTypes & drwav_metadata_type_unknown) != 0) {
- bytesRead = drwav__metadata_process_unknown_chunk(pParser, pChunkID, pChunkHeader->sizeInBytes, drwav_metadata_location_top_level);
+ } else if ((allowedMetadataTypes & ma_dr_wav_metadata_type_unknown) != 0) {
+ bytesRead = ma_dr_wav__metadata_process_unknown_chunk(pParser, pChunkID, pChunkHeader->sizeInBytes, ma_dr_wav_metadata_location_top_level);
}
return bytesRead;
}
-DRWAV_PRIVATE drwav_uint32 drwav_get_bytes_per_pcm_frame(drwav* pWav)
+MA_PRIVATE ma_uint32 ma_dr_wav_get_bytes_per_pcm_frame(ma_dr_wav* pWav)
{
- drwav_uint32 bytesPerFrame;
+ ma_uint32 bytesPerFrame;
if ((pWav->bitsPerSample & 0x7) == 0) {
bytesPerFrame = (pWav->bitsPerSample * pWav->fmt.channels) >> 3;
} else {
bytesPerFrame = pWav->fmt.blockAlign;
}
- if (pWav->translatedFormatTag == DR_WAVE_FORMAT_ALAW || pWav->translatedFormatTag == DR_WAVE_FORMAT_MULAW) {
+ if (pWav->translatedFormatTag == MA_DR_WAVE_FORMAT_ALAW || pWav->translatedFormatTag == MA_DR_WAVE_FORMAT_MULAW) {
if (bytesPerFrame != pWav->fmt.channels) {
return 0;
}
}
return bytesPerFrame;
}
-DRWAV_API drwav_uint16 drwav_fmt_get_format(const drwav_fmt* pFMT)
+MA_API ma_uint16 ma_dr_wav_fmt_get_format(const ma_dr_wav_fmt* pFMT)
{
if (pFMT == NULL) {
return 0;
}
- if (pFMT->formatTag != DR_WAVE_FORMAT_EXTENSIBLE) {
+ if (pFMT->formatTag != MA_DR_WAVE_FORMAT_EXTENSIBLE) {
return pFMT->formatTag;
} else {
- return drwav_bytes_to_u16(pFMT->subFormat);
+ return ma_dr_wav_bytes_to_u16(pFMT->subFormat);
}
}
-DRWAV_PRIVATE drwav_bool32 drwav_preinit(drwav* pWav, drwav_read_proc onRead, drwav_seek_proc onSeek, void* pReadSeekUserData, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_PRIVATE ma_bool32 ma_dr_wav_preinit(ma_dr_wav* pWav, ma_dr_wav_read_proc onRead, ma_dr_wav_seek_proc onSeek, void* pReadSeekUserData, const ma_allocation_callbacks* pAllocationCallbacks)
{
if (pWav == NULL || onRead == NULL || onSeek == NULL) {
- return DRWAV_FALSE;
+ return MA_FALSE;
}
- DRWAV_ZERO_MEMORY(pWav, sizeof(*pWav));
+ MA_DR_WAV_ZERO_MEMORY(pWav, sizeof(*pWav));
pWav->onRead = onRead;
pWav->onSeek = onSeek;
pWav->pUserData = pReadSeekUserData;
- pWav->allocationCallbacks = drwav_copy_allocation_callbacks_or_defaults(pAllocationCallbacks);
+ pWav->allocationCallbacks = ma_dr_wav_copy_allocation_callbacks_or_defaults(pAllocationCallbacks);
if (pWav->allocationCallbacks.onFree == NULL || (pWav->allocationCallbacks.onMalloc == NULL && pWav->allocationCallbacks.onRealloc == NULL)) {
- return DRWAV_FALSE;
+ return MA_FALSE;
}
- return DRWAV_TRUE;
+ return MA_TRUE;
}
-DRWAV_PRIVATE drwav_bool32 drwav_init__internal(drwav* pWav, drwav_chunk_proc onChunk, void* pChunkUserData, drwav_uint32 flags)
+MA_PRIVATE ma_bool32 ma_dr_wav_init__internal(ma_dr_wav* pWav, ma_dr_wav_chunk_proc onChunk, void* pChunkUserData, ma_uint32 flags)
{
- drwav_uint64 cursor;
- drwav_bool32 sequential;
- drwav_uint8 riff[4];
- drwav_fmt fmt;
+ ma_result result;
+ ma_uint64 cursor;
+ ma_bool32 sequential;
+ ma_uint8 riff[4];
+ ma_dr_wav_fmt fmt;
unsigned short translatedFormatTag;
- drwav_bool32 foundDataChunk;
- drwav_uint64 dataChunkSize = 0;
- drwav_uint64 sampleCountFromFactChunk = 0;
- drwav_uint64 chunkSize;
- drwav__metadata_parser metadataParser;
+ ma_uint64 dataChunkSize = 0;
+ ma_uint64 sampleCountFromFactChunk = 0;
+ ma_uint64 metadataStartPos;
+ ma_dr_wav__metadata_parser metadataParser;
+ ma_bool8 isProcessingMetadata = MA_FALSE;
+ ma_bool8 foundChunk_fmt = MA_FALSE;
+ ma_bool8 foundChunk_data = MA_FALSE;
+ ma_bool8 isAIFCFormType = MA_FALSE;
+ ma_uint64 aiffFrameCount = 0;
cursor = 0;
- sequential = (flags & DRWAV_SEQUENTIAL) != 0;
- if (drwav__on_read(pWav->onRead, pWav->pUserData, riff, sizeof(riff), &cursor) != sizeof(riff)) {
- return DRWAV_FALSE;
+ sequential = (flags & MA_DR_WAV_SEQUENTIAL) != 0;
+ MA_DR_WAV_ZERO_OBJECT(&fmt);
+ if (ma_dr_wav__on_read(pWav->onRead, pWav->pUserData, riff, sizeof(riff), &cursor) != sizeof(riff)) {
+ return MA_FALSE;
}
- if (drwav_fourcc_equal(riff, "RIFF")) {
- pWav->container = drwav_container_riff;
- } else if (drwav_fourcc_equal(riff, "riff")) {
+ if (ma_dr_wav_fourcc_equal(riff, "RIFF")) {
+ pWav->container = ma_dr_wav_container_riff;
+ } else if (ma_dr_wav_fourcc_equal(riff, "RIFX")) {
+ pWav->container = ma_dr_wav_container_rifx;
+ } else if (ma_dr_wav_fourcc_equal(riff, "riff")) {
int i;
- drwav_uint8 riff2[12];
- pWav->container = drwav_container_w64;
- if (drwav__on_read(pWav->onRead, pWav->pUserData, riff2, sizeof(riff2), &cursor) != sizeof(riff2)) {
- return DRWAV_FALSE;
+ ma_uint8 riff2[12];
+ pWav->container = ma_dr_wav_container_w64;
+ if (ma_dr_wav__on_read(pWav->onRead, pWav->pUserData, riff2, sizeof(riff2), &cursor) != sizeof(riff2)) {
+ return MA_FALSE;
}
for (i = 0; i < 12; ++i) {
- if (riff2[i] != drwavGUID_W64_RIFF[i+4]) {
- return DRWAV_FALSE;
+ if (riff2[i] != ma_dr_wavGUID_W64_RIFF[i+4]) {
+ return MA_FALSE;
}
}
- } else if (drwav_fourcc_equal(riff, "RF64")) {
- pWav->container = drwav_container_rf64;
+ } else if (ma_dr_wav_fourcc_equal(riff, "RF64")) {
+ pWav->container = ma_dr_wav_container_rf64;
+ } else if (ma_dr_wav_fourcc_equal(riff, "FORM")) {
+ pWav->container = ma_dr_wav_container_aiff;
} else {
- return DRWAV_FALSE;
+ return MA_FALSE;
}
- if (pWav->container == drwav_container_riff || pWav->container == drwav_container_rf64) {
- drwav_uint8 chunkSizeBytes[4];
- drwav_uint8 wave[4];
- if (drwav__on_read(pWav->onRead, pWav->pUserData, chunkSizeBytes, sizeof(chunkSizeBytes), &cursor) != sizeof(chunkSizeBytes)) {
- return DRWAV_FALSE;
+ if (pWav->container == ma_dr_wav_container_riff || pWav->container == ma_dr_wav_container_rifx || pWav->container == ma_dr_wav_container_rf64) {
+ ma_uint8 chunkSizeBytes[4];
+ ma_uint8 wave[4];
+ if (ma_dr_wav__on_read(pWav->onRead, pWav->pUserData, chunkSizeBytes, sizeof(chunkSizeBytes), &cursor) != sizeof(chunkSizeBytes)) {
+ return MA_FALSE;
}
- if (pWav->container == drwav_container_riff) {
- if (drwav_bytes_to_u32(chunkSizeBytes) < 36) {
- return DRWAV_FALSE;
+ if (pWav->container == ma_dr_wav_container_riff || pWav->container == ma_dr_wav_container_rifx) {
+ if (ma_dr_wav_bytes_to_u32_ex(chunkSizeBytes, pWav->container) < 36) {
+ return MA_FALSE;
}
- } else {
- if (drwav_bytes_to_u32(chunkSizeBytes) != 0xFFFFFFFF) {
- return DRWAV_FALSE;
+ } else if (pWav->container == ma_dr_wav_container_rf64) {
+ if (ma_dr_wav_bytes_to_u32_le(chunkSizeBytes) != 0xFFFFFFFF) {
+ return MA_FALSE;
}
+ } else {
+ return MA_FALSE;
}
- if (drwav__on_read(pWav->onRead, pWav->pUserData, wave, sizeof(wave), &cursor) != sizeof(wave)) {
- return DRWAV_FALSE;
+ if (ma_dr_wav__on_read(pWav->onRead, pWav->pUserData, wave, sizeof(wave), &cursor) != sizeof(wave)) {
+ return MA_FALSE;
}
- if (!drwav_fourcc_equal(wave, "WAVE")) {
- return DRWAV_FALSE;
+ if (!ma_dr_wav_fourcc_equal(wave, "WAVE")) {
+ return MA_FALSE;
}
- } else {
- drwav_uint8 chunkSizeBytes[8];
- drwav_uint8 wave[16];
- if (drwav__on_read(pWav->onRead, pWav->pUserData, chunkSizeBytes, sizeof(chunkSizeBytes), &cursor) != sizeof(chunkSizeBytes)) {
- return DRWAV_FALSE;
+ } else if (pWav->container == ma_dr_wav_container_w64) {
+ ma_uint8 chunkSizeBytes[8];
+ ma_uint8 wave[16];
+ if (ma_dr_wav__on_read(pWav->onRead, pWav->pUserData, chunkSizeBytes, sizeof(chunkSizeBytes), &cursor) != sizeof(chunkSizeBytes)) {
+ return MA_FALSE;
+ }
+ if (ma_dr_wav_bytes_to_u64(chunkSizeBytes) < 80) {
+ return MA_FALSE;
+ }
+ if (ma_dr_wav__on_read(pWav->onRead, pWav->pUserData, wave, sizeof(wave), &cursor) != sizeof(wave)) {
+ return MA_FALSE;
+ }
+ if (!ma_dr_wav_guid_equal(wave, ma_dr_wavGUID_W64_WAVE)) {
+ return MA_FALSE;
+ }
+ } else if (pWav->container == ma_dr_wav_container_aiff) {
+ ma_uint8 chunkSizeBytes[4];
+ ma_uint8 aiff[4];
+ if (ma_dr_wav__on_read(pWav->onRead, pWav->pUserData, chunkSizeBytes, sizeof(chunkSizeBytes), &cursor) != sizeof(chunkSizeBytes)) {
+ return MA_FALSE;
}
- if (drwav_bytes_to_u64(chunkSizeBytes) < 80) {
- return DRWAV_FALSE;
+ if (ma_dr_wav_bytes_to_u32_be(chunkSizeBytes) < 18) {
+ return MA_FALSE;
}
- if (drwav__on_read(pWav->onRead, pWav->pUserData, wave, sizeof(wave), &cursor) != sizeof(wave)) {
- return DRWAV_FALSE;
+ if (ma_dr_wav__on_read(pWav->onRead, pWav->pUserData, aiff, sizeof(aiff), &cursor) != sizeof(aiff)) {
+ return MA_FALSE;
}
- if (!drwav_guid_equal(wave, drwavGUID_W64_WAVE)) {
- return DRWAV_FALSE;
+ if (ma_dr_wav_fourcc_equal(aiff, "AIFF")) {
+ isAIFCFormType = MA_FALSE;
+ } else if (ma_dr_wav_fourcc_equal(aiff, "AIFC")) {
+ isAIFCFormType = MA_TRUE;
+ } else {
+ return MA_FALSE;
}
+ } else {
+ return MA_FALSE;
}
- if (pWav->container == drwav_container_rf64) {
- drwav_uint8 sizeBytes[8];
- drwav_uint64 bytesRemainingInChunk;
- drwav_chunk_header header;
- drwav_result result = drwav__read_chunk_header(pWav->onRead, pWav->pUserData, pWav->container, &cursor, &header);
- if (result != DRWAV_SUCCESS) {
- return DRWAV_FALSE;
+ if (pWav->container == ma_dr_wav_container_rf64) {
+ ma_uint8 sizeBytes[8];
+ ma_uint64 bytesRemainingInChunk;
+ ma_dr_wav_chunk_header header;
+ result = ma_dr_wav__read_chunk_header(pWav->onRead, pWav->pUserData, pWav->container, &cursor, &header);
+ if (result != MA_SUCCESS) {
+ return MA_FALSE;
}
- if (!drwav_fourcc_equal(header.id.fourcc, "ds64")) {
- return DRWAV_FALSE;
+ if (!ma_dr_wav_fourcc_equal(header.id.fourcc, "ds64")) {
+ return MA_FALSE;
}
bytesRemainingInChunk = header.sizeInBytes + header.paddingSize;
- if (!drwav__seek_forward(pWav->onSeek, 8, pWav->pUserData)) {
- return DRWAV_FALSE;
+ if (!ma_dr_wav__seek_forward(pWav->onSeek, 8, pWav->pUserData)) {
+ return MA_FALSE;
}
bytesRemainingInChunk -= 8;
cursor += 8;
- if (drwav__on_read(pWav->onRead, pWav->pUserData, sizeBytes, sizeof(sizeBytes), &cursor) != sizeof(sizeBytes)) {
- return DRWAV_FALSE;
+ if (ma_dr_wav__on_read(pWav->onRead, pWav->pUserData, sizeBytes, sizeof(sizeBytes), &cursor) != sizeof(sizeBytes)) {
+ return MA_FALSE;
}
bytesRemainingInChunk -= 8;
- dataChunkSize = drwav_bytes_to_u64(sizeBytes);
- if (drwav__on_read(pWav->onRead, pWav->pUserData, sizeBytes, sizeof(sizeBytes), &cursor) != sizeof(sizeBytes)) {
- return DRWAV_FALSE;
+ dataChunkSize = ma_dr_wav_bytes_to_u64(sizeBytes);
+ if (ma_dr_wav__on_read(pWav->onRead, pWav->pUserData, sizeBytes, sizeof(sizeBytes), &cursor) != sizeof(sizeBytes)) {
+ return MA_FALSE;
}
bytesRemainingInChunk -= 8;
- sampleCountFromFactChunk = drwav_bytes_to_u64(sizeBytes);
- if (!drwav__seek_forward(pWav->onSeek, bytesRemainingInChunk, pWav->pUserData)) {
- return DRWAV_FALSE;
+ sampleCountFromFactChunk = ma_dr_wav_bytes_to_u64(sizeBytes);
+ if (!ma_dr_wav__seek_forward(pWav->onSeek, bytesRemainingInChunk, pWav->pUserData)) {
+ return MA_FALSE;
}
cursor += bytesRemainingInChunk;
}
- if (!drwav__read_fmt(pWav->onRead, pWav->onSeek, pWav->pUserData, pWav->container, &cursor, &fmt)) {
- return DRWAV_FALSE;
- }
- if ((fmt.sampleRate == 0 || fmt.sampleRate > DRWAV_MAX_SAMPLE_RATE) ||
- (fmt.channels == 0 || fmt.channels > DRWAV_MAX_CHANNELS) ||
- (fmt.bitsPerSample == 0 || fmt.bitsPerSample > DRWAV_MAX_BITS_PER_SAMPLE) ||
- fmt.blockAlign == 0) {
- return DRWAV_FALSE;
+ metadataStartPos = cursor;
+ isProcessingMetadata = !sequential && ((flags & MA_DR_WAV_WITH_METADATA) != 0);
+ if (pWav->container != ma_dr_wav_container_riff && pWav->container != ma_dr_wav_container_rf64) {
+ isProcessingMetadata = MA_FALSE;
}
- translatedFormatTag = fmt.formatTag;
- if (translatedFormatTag == DR_WAVE_FORMAT_EXTENSIBLE) {
- translatedFormatTag = drwav_bytes_to_u16(fmt.subFormat + 0);
- }
- DRWAV_ZERO_MEMORY(&metadataParser, sizeof(metadataParser));
- if (!sequential && pWav->allowedMetadataTypes != drwav_metadata_type_none && (pWav->container == drwav_container_riff || pWav->container == drwav_container_rf64)) {
- drwav_uint64 cursorForMetadata = cursor;
+ MA_DR_WAV_ZERO_MEMORY(&metadataParser, sizeof(metadataParser));
+ if (isProcessingMetadata) {
metadataParser.onRead = pWav->onRead;
metadataParser.onSeek = pWav->onSeek;
metadataParser.pReadSeekUserData = pWav->pUserData;
- metadataParser.stage = drwav__metadata_parser_stage_count;
- for (;;) {
- drwav_result result;
- drwav_uint64 bytesRead;
- drwav_uint64 remainingBytes;
- drwav_chunk_header header;
- result = drwav__read_chunk_header(pWav->onRead, pWav->pUserData, pWav->container, &cursorForMetadata, &header);
- if (result != DRWAV_SUCCESS) {
- break;
- }
- bytesRead = drwav__metadata_process_chunk(&metadataParser, &header, pWav->allowedMetadataTypes);
- DRWAV_ASSERT(bytesRead <= header.sizeInBytes);
- remainingBytes = header.sizeInBytes - bytesRead + header.paddingSize;
- if (!drwav__seek_forward(pWav->onSeek, remainingBytes, pWav->pUserData)) {
- break;
- }
- cursorForMetadata += remainingBytes;
- }
- if (!drwav__seek_from_start(pWav->onSeek, cursor, pWav->pUserData)) {
- return DRWAV_FALSE;
- }
- drwav__metadata_alloc(&metadataParser, &pWav->allocationCallbacks);
- metadataParser.stage = drwav__metadata_parser_stage_read;
+ metadataParser.stage = ma_dr_wav__metadata_parser_stage_count;
}
- foundDataChunk = DRWAV_FALSE;
for (;;) {
- drwav_chunk_header header;
- drwav_result result = drwav__read_chunk_header(pWav->onRead, pWav->pUserData, pWav->container, &cursor, &header);
- if (result != DRWAV_SUCCESS) {
- if (!foundDataChunk) {
- return DRWAV_FALSE;
- } else {
- break;
- }
+ ma_dr_wav_chunk_header header;
+ ma_uint64 chunkSize;
+ result = ma_dr_wav__read_chunk_header(pWav->onRead, pWav->pUserData, pWav->container, &cursor, &header);
+ if (result != MA_SUCCESS) {
+ break;
}
+ chunkSize = header.sizeInBytes;
if (!sequential && onChunk != NULL) {
- drwav_uint64 callbackBytesRead = onChunk(pChunkUserData, pWav->onRead, pWav->onSeek, pWav->pUserData, &header, pWav->container, &fmt);
+ ma_uint64 callbackBytesRead = onChunk(pChunkUserData, pWav->onRead, pWav->onSeek, pWav->pUserData, &header, pWav->container, &fmt);
if (callbackBytesRead > 0) {
- if (!drwav__seek_from_start(pWav->onSeek, cursor, pWav->pUserData)) {
- return DRWAV_FALSE;
+ if (ma_dr_wav__seek_from_start(pWav->onSeek, cursor, pWav->pUserData) == MA_FALSE) {
+ return MA_FALSE;
}
}
}
- if (!sequential && pWav->allowedMetadataTypes != drwav_metadata_type_none && (pWav->container == drwav_container_riff || pWav->container == drwav_container_rf64)) {
- drwav_uint64 bytesRead = drwav__metadata_process_chunk(&metadataParser, &header, pWav->allowedMetadataTypes);
- if (bytesRead > 0) {
- if (!drwav__seek_from_start(pWav->onSeek, cursor, pWav->pUserData)) {
- return DRWAV_FALSE;
+ if (((pWav->container == ma_dr_wav_container_riff || pWav->container == ma_dr_wav_container_rifx || pWav->container == ma_dr_wav_container_rf64) && ma_dr_wav_fourcc_equal(header.id.fourcc, "fmt ")) ||
+ ((pWav->container == ma_dr_wav_container_w64) && ma_dr_wav_guid_equal(header.id.guid, ma_dr_wavGUID_W64_FMT))) {
+ ma_uint8 fmtData[16];
+ foundChunk_fmt = MA_TRUE;
+ if (pWav->onRead(pWav->pUserData, fmtData, sizeof(fmtData)) != sizeof(fmtData)) {
+ return MA_FALSE;
+ }
+ cursor += sizeof(fmtData);
+ fmt.formatTag = ma_dr_wav_bytes_to_u16_ex(fmtData + 0, pWav->container);
+ fmt.channels = ma_dr_wav_bytes_to_u16_ex(fmtData + 2, pWav->container);
+ fmt.sampleRate = ma_dr_wav_bytes_to_u32_ex(fmtData + 4, pWav->container);
+ fmt.avgBytesPerSec = ma_dr_wav_bytes_to_u32_ex(fmtData + 8, pWav->container);
+ fmt.blockAlign = ma_dr_wav_bytes_to_u16_ex(fmtData + 12, pWav->container);
+ fmt.bitsPerSample = ma_dr_wav_bytes_to_u16_ex(fmtData + 14, pWav->container);
+ fmt.extendedSize = 0;
+ fmt.validBitsPerSample = 0;
+ fmt.channelMask = 0;
+ MA_DR_WAV_ZERO_MEMORY(fmt.subFormat, sizeof(fmt.subFormat));
+ if (header.sizeInBytes > 16) {
+ ma_uint8 fmt_cbSize[2];
+ int bytesReadSoFar = 0;
+ if (pWav->onRead(pWav->pUserData, fmt_cbSize, sizeof(fmt_cbSize)) != sizeof(fmt_cbSize)) {
+ return MA_FALSE;
+ }
+ cursor += sizeof(fmt_cbSize);
+ bytesReadSoFar = 18;
+ fmt.extendedSize = ma_dr_wav_bytes_to_u16_ex(fmt_cbSize, pWav->container);
+ if (fmt.extendedSize > 0) {
+ if (fmt.formatTag == MA_DR_WAVE_FORMAT_EXTENSIBLE) {
+ if (fmt.extendedSize != 22) {
+ return MA_FALSE;
+ }
+ }
+ if (fmt.formatTag == MA_DR_WAVE_FORMAT_EXTENSIBLE) {
+ ma_uint8 fmtext[22];
+ if (pWav->onRead(pWav->pUserData, fmtext, fmt.extendedSize) != fmt.extendedSize) {
+ return MA_FALSE;
+ }
+ fmt.validBitsPerSample = ma_dr_wav_bytes_to_u16_ex(fmtext + 0, pWav->container);
+ fmt.channelMask = ma_dr_wav_bytes_to_u32_ex(fmtext + 2, pWav->container);
+ ma_dr_wav_bytes_to_guid(fmtext + 6, fmt.subFormat);
+ } else {
+ if (pWav->onSeek(pWav->pUserData, fmt.extendedSize, ma_dr_wav_seek_origin_current) == MA_FALSE) {
+ return MA_FALSE;
+ }
+ }
+ cursor += fmt.extendedSize;
+ bytesReadSoFar += fmt.extendedSize;
}
+ if (pWav->onSeek(pWav->pUserData, (int)(header.sizeInBytes - bytesReadSoFar), ma_dr_wav_seek_origin_current) == MA_FALSE) {
+ return MA_FALSE;
+ }
+ cursor += (header.sizeInBytes - bytesReadSoFar);
}
- }
- if (!foundDataChunk) {
- pWav->dataChunkDataPos = cursor;
- }
- chunkSize = header.sizeInBytes;
- if (pWav->container == drwav_container_riff || pWav->container == drwav_container_rf64) {
- if (drwav_fourcc_equal(header.id.fourcc, "data")) {
- foundDataChunk = DRWAV_TRUE;
- if (pWav->container != drwav_container_rf64) {
- dataChunkSize = chunkSize;
+ if (header.paddingSize > 0) {
+ if (ma_dr_wav__seek_forward(pWav->onSeek, header.paddingSize, pWav->pUserData) == MA_FALSE) {
+ break;
}
+ cursor += header.paddingSize;
}
- } else {
- if (drwav_guid_equal(header.id.guid, drwavGUID_W64_DATA)) {
- foundDataChunk = DRWAV_TRUE;
+ continue;
+ }
+ if (((pWav->container == ma_dr_wav_container_riff || pWav->container == ma_dr_wav_container_rifx || pWav->container == ma_dr_wav_container_rf64) && ma_dr_wav_fourcc_equal(header.id.fourcc, "data")) ||
+ ((pWav->container == ma_dr_wav_container_w64) && ma_dr_wav_guid_equal(header.id.guid, ma_dr_wavGUID_W64_DATA))) {
+ foundChunk_data = MA_TRUE;
+ pWav->dataChunkDataPos = cursor;
+ if (pWav->container != ma_dr_wav_container_rf64) {
dataChunkSize = chunkSize;
}
+ if (sequential || !isProcessingMetadata) {
+ break;
+ } else {
+ chunkSize += header.paddingSize;
+ if (ma_dr_wav__seek_forward(pWav->onSeek, chunkSize, pWav->pUserData) == MA_FALSE) {
+ break;
+ }
+ cursor += chunkSize;
+ continue;
+ }
}
- if (foundDataChunk && sequential) {
- break;
- }
- if (pWav->container == drwav_container_riff) {
- if (drwav_fourcc_equal(header.id.fourcc, "fact")) {
- drwav_uint32 sampleCount;
- if (drwav__on_read(pWav->onRead, pWav->pUserData, &sampleCount, 4, &cursor) != 4) {
- return DRWAV_FALSE;
+ if (((pWav->container == ma_dr_wav_container_riff || pWav->container == ma_dr_wav_container_rifx || pWav->container == ma_dr_wav_container_rf64) && ma_dr_wav_fourcc_equal(header.id.fourcc, "fact")) ||
+ ((pWav->container == ma_dr_wav_container_w64) && ma_dr_wav_guid_equal(header.id.guid, ma_dr_wavGUID_W64_FACT))) {
+ if (pWav->container == ma_dr_wav_container_riff || pWav->container == ma_dr_wav_container_rifx) {
+ ma_uint8 sampleCount[4];
+ if (ma_dr_wav__on_read(pWav->onRead, pWav->pUserData, &sampleCount, 4, &cursor) != 4) {
+ return MA_FALSE;
}
chunkSize -= 4;
- if (!foundDataChunk) {
- pWav->dataChunkDataPos = cursor;
- }
- if (pWav->translatedFormatTag == DR_WAVE_FORMAT_ADPCM) {
- sampleCountFromFactChunk = sampleCount;
+ if (pWav->translatedFormatTag == MA_DR_WAVE_FORMAT_ADPCM) {
+ sampleCountFromFactChunk = ma_dr_wav_bytes_to_u32_ex(sampleCount, pWav->container);
} else {
sampleCountFromFactChunk = 0;
}
- }
- } else if (pWav->container == drwav_container_w64) {
- if (drwav_guid_equal(header.id.guid, drwavGUID_W64_FACT)) {
- if (drwav__on_read(pWav->onRead, pWav->pUserData, &sampleCountFromFactChunk, 8, &cursor) != 8) {
- return DRWAV_FALSE;
+ } else if (pWav->container == ma_dr_wav_container_w64) {
+ if (ma_dr_wav__on_read(pWav->onRead, pWav->pUserData, &sampleCountFromFactChunk, 8, &cursor) != 8) {
+ return MA_FALSE;
}
chunkSize -= 8;
- if (!foundDataChunk) {
- pWav->dataChunkDataPos = cursor;
+ } else if (pWav->container == ma_dr_wav_container_rf64) {
+ }
+ chunkSize += header.paddingSize;
+ if (ma_dr_wav__seek_forward(pWav->onSeek, chunkSize, pWav->pUserData) == MA_FALSE) {
+ break;
+ }
+ cursor += chunkSize;
+ continue;
+ }
+ if (pWav->container == ma_dr_wav_container_aiff && ma_dr_wav_fourcc_equal(header.id.fourcc, "COMM")) {
+ ma_uint8 commData[24];
+ ma_uint32 commDataBytesToRead;
+ ma_uint16 channels;
+ ma_uint32 frameCount;
+ ma_uint16 sampleSizeInBits;
+ ma_int64 sampleRate;
+ ma_uint16 compressionFormat;
+ foundChunk_fmt = MA_TRUE;
+ if (isAIFCFormType) {
+ commDataBytesToRead = 24;
+ if (header.sizeInBytes < commDataBytesToRead) {
+ return MA_FALSE;
+ }
+ } else {
+ commDataBytesToRead = 18;
+ if (header.sizeInBytes != commDataBytesToRead) {
+ return MA_FALSE;
+ }
+ }
+ if (ma_dr_wav__on_read(pWav->onRead, pWav->pUserData, commData, commDataBytesToRead, &cursor) != commDataBytesToRead) {
+ return MA_FALSE;
+ }
+ channels = ma_dr_wav_bytes_to_u16_ex (commData + 0, pWav->container);
+ frameCount = ma_dr_wav_bytes_to_u32_ex (commData + 2, pWav->container);
+ sampleSizeInBits = ma_dr_wav_bytes_to_u16_ex (commData + 6, pWav->container);
+ sampleRate = ma_dr_wav_aiff_extented_to_s64(commData + 8);
+ if (sampleRate < 0 || sampleRate > 0xFFFFFFFF) {
+ return MA_FALSE;
+ }
+ if (isAIFCFormType) {
+ const ma_uint8* type = commData + 18;
+ if (ma_dr_wav_fourcc_equal(type, "NONE")) {
+ compressionFormat = MA_DR_WAVE_FORMAT_PCM;
+ } else if (ma_dr_wav_fourcc_equal(type, "raw ")) {
+ compressionFormat = MA_DR_WAVE_FORMAT_PCM;
+ if (sampleSizeInBits == 8) {
+ pWav->aiff.isUnsigned = MA_TRUE;
+ }
+ } else if (ma_dr_wav_fourcc_equal(type, "sowt")) {
+ compressionFormat = MA_DR_WAVE_FORMAT_PCM;
+ pWav->aiff.isLE = MA_TRUE;
+ } else if (ma_dr_wav_fourcc_equal(type, "fl32") || ma_dr_wav_fourcc_equal(type, "fl64") || ma_dr_wav_fourcc_equal(type, "FL32") || ma_dr_wav_fourcc_equal(type, "FL64")) {
+ compressionFormat = MA_DR_WAVE_FORMAT_IEEE_FLOAT;
+ } else if (ma_dr_wav_fourcc_equal(type, "alaw") || ma_dr_wav_fourcc_equal(type, "ALAW")) {
+ compressionFormat = MA_DR_WAVE_FORMAT_ALAW;
+ } else if (ma_dr_wav_fourcc_equal(type, "ulaw") || ma_dr_wav_fourcc_equal(type, "ULAW")) {
+ compressionFormat = MA_DR_WAVE_FORMAT_MULAW;
+ } else if (ma_dr_wav_fourcc_equal(type, "ima4")) {
+ compressionFormat = MA_DR_WAVE_FORMAT_DVI_ADPCM;
+ sampleSizeInBits = 4;
+ return MA_FALSE;
+ } else {
+ return MA_FALSE;
+ }
+ } else {
+ compressionFormat = MA_DR_WAVE_FORMAT_PCM;
+ }
+ aiffFrameCount = frameCount;
+ fmt.formatTag = compressionFormat;
+ fmt.channels = channels;
+ fmt.sampleRate = (ma_uint32)sampleRate;
+ fmt.bitsPerSample = sampleSizeInBits;
+ fmt.blockAlign = (ma_uint16)(fmt.channels * fmt.bitsPerSample / 8);
+ fmt.avgBytesPerSec = fmt.blockAlign * fmt.sampleRate;
+ if (fmt.blockAlign == 0 && compressionFormat == MA_DR_WAVE_FORMAT_DVI_ADPCM) {
+ fmt.blockAlign = 34 * fmt.channels;
+ }
+ if (compressionFormat == MA_DR_WAVE_FORMAT_ALAW || compressionFormat == MA_DR_WAVE_FORMAT_MULAW) {
+ if (fmt.bitsPerSample > 8) {
+ fmt.bitsPerSample = 8;
+ fmt.blockAlign = fmt.channels;
+ }
+ }
+ fmt.bitsPerSample += (fmt.bitsPerSample & 7);
+ if (isAIFCFormType) {
+ if (ma_dr_wav__seek_forward(pWav->onSeek, (chunkSize - commDataBytesToRead), pWav->pUserData) == MA_FALSE) {
+ return MA_FALSE;
+ }
+ cursor += (chunkSize - commDataBytesToRead);
+ }
+ continue;
+ }
+ if (pWav->container == ma_dr_wav_container_aiff && ma_dr_wav_fourcc_equal(header.id.fourcc, "SSND")) {
+ ma_uint8 offsetAndBlockSizeData[8];
+ ma_uint32 offset;
+ foundChunk_data = MA_TRUE;
+ if (ma_dr_wav__on_read(pWav->onRead, pWav->pUserData, offsetAndBlockSizeData, sizeof(offsetAndBlockSizeData), &cursor) != sizeof(offsetAndBlockSizeData)) {
+ return MA_FALSE;
+ }
+ offset = ma_dr_wav_bytes_to_u32_ex(offsetAndBlockSizeData + 0, pWav->container);
+ if (ma_dr_wav__seek_forward(pWav->onSeek, offset, pWav->pUserData) == MA_FALSE) {
+ return MA_FALSE;
+ }
+ cursor += offset;
+ pWav->dataChunkDataPos = cursor;
+ dataChunkSize = chunkSize;
+ if (sequential || !isProcessingMetadata) {
+ break;
+ } else {
+ if (ma_dr_wav__seek_forward(pWav->onSeek, chunkSize, pWav->pUserData) == MA_FALSE) {
+ break;
}
+ cursor += chunkSize;
+ continue;
+ }
+ }
+ if (isProcessingMetadata) {
+ ma_uint64 metadataBytesRead;
+ metadataBytesRead = ma_dr_wav__metadata_process_chunk(&metadataParser, &header, ma_dr_wav_metadata_type_all_including_unknown);
+ MA_DR_WAV_ASSERT(metadataBytesRead <= header.sizeInBytes);
+ if (ma_dr_wav__seek_from_start(pWav->onSeek, cursor, pWav->pUserData) == MA_FALSE) {
+ break;
}
- } else if (pWav->container == drwav_container_rf64) {
}
chunkSize += header.paddingSize;
- if (!drwav__seek_forward(pWav->onSeek, chunkSize, pWav->pUserData)) {
+ if (ma_dr_wav__seek_forward(pWav->onSeek, chunkSize, pWav->pUserData) == MA_FALSE) {
break;
}
cursor += chunkSize;
- if (!foundDataChunk) {
- pWav->dataChunkDataPos = cursor;
- }
}
- pWav->pMetadata = metadataParser.pMetadata;
- pWav->metadataCount = metadataParser.metadataCount;
- if (!foundDataChunk) {
- return DRWAV_FALSE;
+ if (!foundChunk_fmt || !foundChunk_data) {
+ return MA_FALSE;
+ }
+ if ((fmt.sampleRate == 0 || fmt.sampleRate > MA_DR_WAV_MAX_SAMPLE_RATE ) ||
+ (fmt.channels == 0 || fmt.channels > MA_DR_WAV_MAX_CHANNELS ) ||
+ (fmt.bitsPerSample == 0 || fmt.bitsPerSample > MA_DR_WAV_MAX_BITS_PER_SAMPLE) ||
+ fmt.blockAlign == 0) {
+ return MA_FALSE;
+ }
+ translatedFormatTag = fmt.formatTag;
+ if (translatedFormatTag == MA_DR_WAVE_FORMAT_EXTENSIBLE) {
+ translatedFormatTag = ma_dr_wav_bytes_to_u16_ex(fmt.subFormat + 0, pWav->container);
}
if (!sequential) {
- if (!drwav__seek_from_start(pWav->onSeek, pWav->dataChunkDataPos, pWav->pUserData)) {
- return DRWAV_FALSE;
+ if (!ma_dr_wav__seek_from_start(pWav->onSeek, pWav->dataChunkDataPos, pWav->pUserData)) {
+ return MA_FALSE;
}
cursor = pWav->dataChunkDataPos;
}
+ if (isProcessingMetadata && metadataParser.metadataCount > 0) {
+ if (ma_dr_wav__seek_from_start(pWav->onSeek, metadataStartPos, pWav->pUserData) == MA_FALSE) {
+ return MA_FALSE;
+ }
+ result = ma_dr_wav__metadata_alloc(&metadataParser, &pWav->allocationCallbacks);
+ if (result != MA_SUCCESS) {
+ return MA_FALSE;
+ }
+ metadataParser.stage = ma_dr_wav__metadata_parser_stage_read;
+ for (;;) {
+ ma_dr_wav_chunk_header header;
+ ma_uint64 metadataBytesRead;
+ result = ma_dr_wav__read_chunk_header(pWav->onRead, pWav->pUserData, pWav->container, &cursor, &header);
+ if (result != MA_SUCCESS) {
+ break;
+ }
+ metadataBytesRead = ma_dr_wav__metadata_process_chunk(&metadataParser, &header, ma_dr_wav_metadata_type_all_including_unknown);
+ if (ma_dr_wav__seek_forward(pWav->onSeek, (header.sizeInBytes + header.paddingSize) - metadataBytesRead, pWav->pUserData) == MA_FALSE) {
+ ma_dr_wav_free(metadataParser.pMetadata, &pWav->allocationCallbacks);
+ return MA_FALSE;
+ }
+ }
+ pWav->pMetadata = metadataParser.pMetadata;
+ pWav->metadataCount = metadataParser.metadataCount;
+ }
+ if (dataChunkSize == 0xFFFFFFFF && (pWav->container == ma_dr_wav_container_riff || pWav->container == ma_dr_wav_container_rifx) && pWav->isSequentialWrite == MA_FALSE) {
+ dataChunkSize = 0;
+ for (;;) {
+ ma_uint8 temp[4096];
+ size_t bytesRead = pWav->onRead(pWav->pUserData, temp, sizeof(temp));
+ dataChunkSize += bytesRead;
+ if (bytesRead < sizeof(temp)) {
+ break;
+ }
+ }
+ }
+ if (ma_dr_wav__seek_from_start(pWav->onSeek, pWav->dataChunkDataPos, pWav->pUserData) == MA_FALSE) {
+ ma_dr_wav_free(pWav->pMetadata, &pWav->allocationCallbacks);
+ return MA_FALSE;
+ }
pWav->fmt = fmt;
pWav->sampleRate = fmt.sampleRate;
pWav->channels = fmt.channels;
@@ -76027,24 +78963,27 @@ DRWAV_PRIVATE drwav_bool32 drwav_init__internal(drwav* pWav, drwav_chunk_proc on
pWav->dataChunkDataSize = dataChunkSize;
if (sampleCountFromFactChunk != 0) {
pWav->totalPCMFrameCount = sampleCountFromFactChunk;
+ } else if (aiffFrameCount != 0) {
+ pWav->totalPCMFrameCount = aiffFrameCount;
} else {
- drwav_uint32 bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
+ ma_uint32 bytesPerFrame = ma_dr_wav_get_bytes_per_pcm_frame(pWav);
if (bytesPerFrame == 0) {
- return DRWAV_FALSE;
+ ma_dr_wav_free(pWav->pMetadata, &pWav->allocationCallbacks);
+ return MA_FALSE;
}
pWav->totalPCMFrameCount = dataChunkSize / bytesPerFrame;
- if (pWav->translatedFormatTag == DR_WAVE_FORMAT_ADPCM) {
- drwav_uint64 totalBlockHeaderSizeInBytes;
- drwav_uint64 blockCount = dataChunkSize / fmt.blockAlign;
+ if (pWav->translatedFormatTag == MA_DR_WAVE_FORMAT_ADPCM) {
+ ma_uint64 totalBlockHeaderSizeInBytes;
+ ma_uint64 blockCount = dataChunkSize / fmt.blockAlign;
if ((blockCount * fmt.blockAlign) < dataChunkSize) {
blockCount += 1;
}
totalBlockHeaderSizeInBytes = blockCount * (6*fmt.channels);
pWav->totalPCMFrameCount = ((dataChunkSize - totalBlockHeaderSizeInBytes) * 2) / fmt.channels;
}
- if (pWav->translatedFormatTag == DR_WAVE_FORMAT_DVI_ADPCM) {
- drwav_uint64 totalBlockHeaderSizeInBytes;
- drwav_uint64 blockCount = dataChunkSize / fmt.blockAlign;
+ if (pWav->translatedFormatTag == MA_DR_WAVE_FORMAT_DVI_ADPCM) {
+ ma_uint64 totalBlockHeaderSizeInBytes;
+ ma_uint64 blockCount = dataChunkSize / fmt.blockAlign;
if ((blockCount * fmt.blockAlign) < dataChunkSize) {
blockCount += 1;
}
@@ -76053,307 +78992,308 @@ DRWAV_PRIVATE drwav_bool32 drwav_init__internal(drwav* pWav, drwav_chunk_proc on
pWav->totalPCMFrameCount += blockCount;
}
}
- if (pWav->translatedFormatTag == DR_WAVE_FORMAT_ADPCM || pWav->translatedFormatTag == DR_WAVE_FORMAT_DVI_ADPCM) {
+ if (pWav->translatedFormatTag == MA_DR_WAVE_FORMAT_ADPCM || pWav->translatedFormatTag == MA_DR_WAVE_FORMAT_DVI_ADPCM) {
if (pWav->channels > 2) {
- return DRWAV_FALSE;
+ ma_dr_wav_free(pWav->pMetadata, &pWav->allocationCallbacks);
+ return MA_FALSE;
}
}
- if (drwav_get_bytes_per_pcm_frame(pWav) == 0) {
- return DRWAV_FALSE;
+ if (ma_dr_wav_get_bytes_per_pcm_frame(pWav) == 0) {
+ ma_dr_wav_free(pWav->pMetadata, &pWav->allocationCallbacks);
+ return MA_FALSE;
}
-#ifdef DR_WAV_LIBSNDFILE_COMPAT
- if (pWav->translatedFormatTag == DR_WAVE_FORMAT_ADPCM) {
- drwav_uint64 blockCount = dataChunkSize / fmt.blockAlign;
+#ifdef MA_DR_WAV_LIBSNDFILE_COMPAT
+ if (pWav->translatedFormatTag == MA_DR_WAVE_FORMAT_ADPCM) {
+ ma_uint64 blockCount = dataChunkSize / fmt.blockAlign;
pWav->totalPCMFrameCount = (((blockCount * (fmt.blockAlign - (6*pWav->channels))) * 2)) / fmt.channels;
}
- if (pWav->translatedFormatTag == DR_WAVE_FORMAT_DVI_ADPCM) {
- drwav_uint64 blockCount = dataChunkSize / fmt.blockAlign;
+ if (pWav->translatedFormatTag == MA_DR_WAVE_FORMAT_DVI_ADPCM) {
+ ma_uint64 blockCount = dataChunkSize / fmt.blockAlign;
pWav->totalPCMFrameCount = (((blockCount * (fmt.blockAlign - (4*pWav->channels))) * 2) + (blockCount * pWav->channels)) / fmt.channels;
}
#endif
- return DRWAV_TRUE;
+ return MA_TRUE;
}
-DRWAV_API drwav_bool32 drwav_init(drwav* pWav, drwav_read_proc onRead, drwav_seek_proc onSeek, void* pUserData, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_bool32 ma_dr_wav_init(ma_dr_wav* pWav, ma_dr_wav_read_proc onRead, ma_dr_wav_seek_proc onSeek, void* pUserData, const ma_allocation_callbacks* pAllocationCallbacks)
{
- return drwav_init_ex(pWav, onRead, onSeek, NULL, pUserData, NULL, 0, pAllocationCallbacks);
+ return ma_dr_wav_init_ex(pWav, onRead, onSeek, NULL, pUserData, NULL, 0, pAllocationCallbacks);
}
-DRWAV_API drwav_bool32 drwav_init_ex(drwav* pWav, drwav_read_proc onRead, drwav_seek_proc onSeek, drwav_chunk_proc onChunk, void* pReadSeekUserData, void* pChunkUserData, drwav_uint32 flags, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_bool32 ma_dr_wav_init_ex(ma_dr_wav* pWav, ma_dr_wav_read_proc onRead, ma_dr_wav_seek_proc onSeek, ma_dr_wav_chunk_proc onChunk, void* pReadSeekUserData, void* pChunkUserData, ma_uint32 flags, const ma_allocation_callbacks* pAllocationCallbacks)
{
- if (!drwav_preinit(pWav, onRead, onSeek, pReadSeekUserData, pAllocationCallbacks)) {
- return DRWAV_FALSE;
+ if (!ma_dr_wav_preinit(pWav, onRead, onSeek, pReadSeekUserData, pAllocationCallbacks)) {
+ return MA_FALSE;
}
- return drwav_init__internal(pWav, onChunk, pChunkUserData, flags);
+ return ma_dr_wav_init__internal(pWav, onChunk, pChunkUserData, flags);
}
-DRWAV_API drwav_bool32 drwav_init_with_metadata(drwav* pWav, drwav_read_proc onRead, drwav_seek_proc onSeek, void* pUserData, drwav_uint32 flags, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_bool32 ma_dr_wav_init_with_metadata(ma_dr_wav* pWav, ma_dr_wav_read_proc onRead, ma_dr_wav_seek_proc onSeek, void* pUserData, ma_uint32 flags, const ma_allocation_callbacks* pAllocationCallbacks)
{
- if (!drwav_preinit(pWav, onRead, onSeek, pUserData, pAllocationCallbacks)) {
- return DRWAV_FALSE;
+ if (!ma_dr_wav_preinit(pWav, onRead, onSeek, pUserData, pAllocationCallbacks)) {
+ return MA_FALSE;
}
- pWav->allowedMetadataTypes = drwav_metadata_type_all_including_unknown;
- return drwav_init__internal(pWav, NULL, NULL, flags);
+ return ma_dr_wav_init__internal(pWav, NULL, NULL, flags | MA_DR_WAV_WITH_METADATA);
}
-DRWAV_API drwav_metadata* drwav_take_ownership_of_metadata(drwav* pWav)
+MA_API ma_dr_wav_metadata* ma_dr_wav_take_ownership_of_metadata(ma_dr_wav* pWav)
{
- drwav_metadata *result = pWav->pMetadata;
+ ma_dr_wav_metadata *result = pWav->pMetadata;
pWav->pMetadata = NULL;
pWav->metadataCount = 0;
return result;
}
-DRWAV_PRIVATE size_t drwav__write(drwav* pWav, const void* pData, size_t dataSize)
+MA_PRIVATE size_t ma_dr_wav__write(ma_dr_wav* pWav, const void* pData, size_t dataSize)
{
- DRWAV_ASSERT(pWav != NULL);
- DRWAV_ASSERT(pWav->onWrite != NULL);
+ MA_DR_WAV_ASSERT(pWav != NULL);
+ MA_DR_WAV_ASSERT(pWav->onWrite != NULL);
return pWav->onWrite(pWav->pUserData, pData, dataSize);
}
-DRWAV_PRIVATE size_t drwav__write_byte(drwav* pWav, drwav_uint8 byte)
+MA_PRIVATE size_t ma_dr_wav__write_byte(ma_dr_wav* pWav, ma_uint8 byte)
{
- DRWAV_ASSERT(pWav != NULL);
- DRWAV_ASSERT(pWav->onWrite != NULL);
+ MA_DR_WAV_ASSERT(pWav != NULL);
+ MA_DR_WAV_ASSERT(pWav->onWrite != NULL);
return pWav->onWrite(pWav->pUserData, &byte, 1);
}
-DRWAV_PRIVATE size_t drwav__write_u16ne_to_le(drwav* pWav, drwav_uint16 value)
+MA_PRIVATE size_t ma_dr_wav__write_u16ne_to_le(ma_dr_wav* pWav, ma_uint16 value)
{
- DRWAV_ASSERT(pWav != NULL);
- DRWAV_ASSERT(pWav->onWrite != NULL);
- if (!drwav__is_little_endian()) {
- value = drwav__bswap16(value);
+ MA_DR_WAV_ASSERT(pWav != NULL);
+ MA_DR_WAV_ASSERT(pWav->onWrite != NULL);
+ if (!ma_dr_wav__is_little_endian()) {
+ value = ma_dr_wav__bswap16(value);
}
- return drwav__write(pWav, &value, 2);
+ return ma_dr_wav__write(pWav, &value, 2);
}
-DRWAV_PRIVATE size_t drwav__write_u32ne_to_le(drwav* pWav, drwav_uint32 value)
+MA_PRIVATE size_t ma_dr_wav__write_u32ne_to_le(ma_dr_wav* pWav, ma_uint32 value)
{
- DRWAV_ASSERT(pWav != NULL);
- DRWAV_ASSERT(pWav->onWrite != NULL);
- if (!drwav__is_little_endian()) {
- value = drwav__bswap32(value);
+ MA_DR_WAV_ASSERT(pWav != NULL);
+ MA_DR_WAV_ASSERT(pWav->onWrite != NULL);
+ if (!ma_dr_wav__is_little_endian()) {
+ value = ma_dr_wav__bswap32(value);
}
- return drwav__write(pWav, &value, 4);
+ return ma_dr_wav__write(pWav, &value, 4);
}
-DRWAV_PRIVATE size_t drwav__write_u64ne_to_le(drwav* pWav, drwav_uint64 value)
+MA_PRIVATE size_t ma_dr_wav__write_u64ne_to_le(ma_dr_wav* pWav, ma_uint64 value)
{
- DRWAV_ASSERT(pWav != NULL);
- DRWAV_ASSERT(pWav->onWrite != NULL);
- if (!drwav__is_little_endian()) {
- value = drwav__bswap64(value);
+ MA_DR_WAV_ASSERT(pWav != NULL);
+ MA_DR_WAV_ASSERT(pWav->onWrite != NULL);
+ if (!ma_dr_wav__is_little_endian()) {
+ value = ma_dr_wav__bswap64(value);
}
- return drwav__write(pWav, &value, 8);
+ return ma_dr_wav__write(pWav, &value, 8);
}
-DRWAV_PRIVATE size_t drwav__write_f32ne_to_le(drwav* pWav, float value)
+MA_PRIVATE size_t ma_dr_wav__write_f32ne_to_le(ma_dr_wav* pWav, float value)
{
union {
- drwav_uint32 u32;
+ ma_uint32 u32;
float f32;
} u;
- DRWAV_ASSERT(pWav != NULL);
- DRWAV_ASSERT(pWav->onWrite != NULL);
+ MA_DR_WAV_ASSERT(pWav != NULL);
+ MA_DR_WAV_ASSERT(pWav->onWrite != NULL);
u.f32 = value;
- if (!drwav__is_little_endian()) {
- u.u32 = drwav__bswap32(u.u32);
+ if (!ma_dr_wav__is_little_endian()) {
+ u.u32 = ma_dr_wav__bswap32(u.u32);
}
- return drwav__write(pWav, &u.u32, 4);
+ return ma_dr_wav__write(pWav, &u.u32, 4);
}
-DRWAV_PRIVATE size_t drwav__write_or_count(drwav* pWav, const void* pData, size_t dataSize)
+MA_PRIVATE size_t ma_dr_wav__write_or_count(ma_dr_wav* pWav, const void* pData, size_t dataSize)
{
if (pWav == NULL) {
return dataSize;
}
- return drwav__write(pWav, pData, dataSize);
+ return ma_dr_wav__write(pWav, pData, dataSize);
}
-DRWAV_PRIVATE size_t drwav__write_or_count_byte(drwav* pWav, drwav_uint8 byte)
+MA_PRIVATE size_t ma_dr_wav__write_or_count_byte(ma_dr_wav* pWav, ma_uint8 byte)
{
if (pWav == NULL) {
return 1;
}
- return drwav__write_byte(pWav, byte);
+ return ma_dr_wav__write_byte(pWav, byte);
}
-DRWAV_PRIVATE size_t drwav__write_or_count_u16ne_to_le(drwav* pWav, drwav_uint16 value)
+MA_PRIVATE size_t ma_dr_wav__write_or_count_u16ne_to_le(ma_dr_wav* pWav, ma_uint16 value)
{
if (pWav == NULL) {
return 2;
}
- return drwav__write_u16ne_to_le(pWav, value);
+ return ma_dr_wav__write_u16ne_to_le(pWav, value);
}
-DRWAV_PRIVATE size_t drwav__write_or_count_u32ne_to_le(drwav* pWav, drwav_uint32 value)
+MA_PRIVATE size_t ma_dr_wav__write_or_count_u32ne_to_le(ma_dr_wav* pWav, ma_uint32 value)
{
if (pWav == NULL) {
return 4;
}
- return drwav__write_u32ne_to_le(pWav, value);
+ return ma_dr_wav__write_u32ne_to_le(pWav, value);
}
#if 0
-DRWAV_PRIVATE size_t drwav__write_or_count_u64ne_to_le(drwav* pWav, drwav_uint64 value)
+MA_PRIVATE size_t ma_dr_wav__write_or_count_u64ne_to_le(ma_dr_wav* pWav, ma_uint64 value)
{
if (pWav == NULL) {
return 8;
}
- return drwav__write_u64ne_to_le(pWav, value);
+ return ma_dr_wav__write_u64ne_to_le(pWav, value);
}
#endif
-DRWAV_PRIVATE size_t drwav__write_or_count_f32ne_to_le(drwav* pWav, float value)
+MA_PRIVATE size_t ma_dr_wav__write_or_count_f32ne_to_le(ma_dr_wav* pWav, float value)
{
if (pWav == NULL) {
return 4;
}
- return drwav__write_f32ne_to_le(pWav, value);
+ return ma_dr_wav__write_f32ne_to_le(pWav, value);
}
-DRWAV_PRIVATE size_t drwav__write_or_count_string_to_fixed_size_buf(drwav* pWav, char* str, size_t bufFixedSize)
+MA_PRIVATE size_t ma_dr_wav__write_or_count_string_to_fixed_size_buf(ma_dr_wav* pWav, char* str, size_t bufFixedSize)
{
size_t len;
if (pWav == NULL) {
return bufFixedSize;
}
- len = drwav__strlen_clamped(str, bufFixedSize);
- drwav__write_or_count(pWav, str, len);
+ len = ma_dr_wav__strlen_clamped(str, bufFixedSize);
+ ma_dr_wav__write_or_count(pWav, str, len);
if (len < bufFixedSize) {
size_t i;
for (i = 0; i < bufFixedSize - len; ++i) {
- drwav__write_byte(pWav, 0);
+ ma_dr_wav__write_byte(pWav, 0);
}
}
return bufFixedSize;
}
-DRWAV_PRIVATE size_t drwav__write_or_count_metadata(drwav* pWav, drwav_metadata* pMetadatas, drwav_uint32 metadataCount)
+MA_PRIVATE size_t ma_dr_wav__write_or_count_metadata(ma_dr_wav* pWav, ma_dr_wav_metadata* pMetadatas, ma_uint32 metadataCount)
{
size_t bytesWritten = 0;
- drwav_bool32 hasListAdtl = DRWAV_FALSE;
- drwav_bool32 hasListInfo = DRWAV_FALSE;
- drwav_uint32 iMetadata;
+ ma_bool32 hasListAdtl = MA_FALSE;
+ ma_bool32 hasListInfo = MA_FALSE;
+ ma_uint32 iMetadata;
if (pMetadatas == NULL || metadataCount == 0) {
return 0;
}
for (iMetadata = 0; iMetadata < metadataCount; ++iMetadata) {
- drwav_metadata* pMetadata = &pMetadatas[iMetadata];
- drwav_uint32 chunkSize = 0;
- if ((pMetadata->type & drwav_metadata_type_list_all_info_strings) || (pMetadata->type == drwav_metadata_type_unknown && pMetadata->data.unknown.chunkLocation == drwav_metadata_location_inside_info_list)) {
- hasListInfo = DRWAV_TRUE;
+ ma_dr_wav_metadata* pMetadata = &pMetadatas[iMetadata];
+ ma_uint32 chunkSize = 0;
+ if ((pMetadata->type & ma_dr_wav_metadata_type_list_all_info_strings) || (pMetadata->type == ma_dr_wav_metadata_type_unknown && pMetadata->data.unknown.chunkLocation == ma_dr_wav_metadata_location_inside_info_list)) {
+ hasListInfo = MA_TRUE;
}
- if ((pMetadata->type & drwav_metadata_type_list_all_adtl) || (pMetadata->type == drwav_metadata_type_unknown && pMetadata->data.unknown.chunkLocation == drwav_metadata_location_inside_adtl_list)) {
- hasListAdtl = DRWAV_TRUE;
+ if ((pMetadata->type & ma_dr_wav_metadata_type_list_all_adtl) || (pMetadata->type == ma_dr_wav_metadata_type_unknown && pMetadata->data.unknown.chunkLocation == ma_dr_wav_metadata_location_inside_adtl_list)) {
+ hasListAdtl = MA_TRUE;
}
switch (pMetadata->type) {
- case drwav_metadata_type_smpl:
+ case ma_dr_wav_metadata_type_smpl:
{
- drwav_uint32 iLoop;
- chunkSize = DRWAV_SMPL_BYTES + DRWAV_SMPL_LOOP_BYTES * pMetadata->data.smpl.sampleLoopCount + pMetadata->data.smpl.samplerSpecificDataSizeInBytes;
- bytesWritten += drwav__write_or_count(pWav, "smpl", 4);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, chunkSize);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, pMetadata->data.smpl.manufacturerId);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, pMetadata->data.smpl.productId);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, pMetadata->data.smpl.samplePeriodNanoseconds);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, pMetadata->data.smpl.midiUnityNote);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, pMetadata->data.smpl.midiPitchFraction);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, pMetadata->data.smpl.smpteFormat);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, pMetadata->data.smpl.smpteOffset);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, pMetadata->data.smpl.sampleLoopCount);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, pMetadata->data.smpl.samplerSpecificDataSizeInBytes);
+ ma_uint32 iLoop;
+ chunkSize = MA_DR_WAV_SMPL_BYTES + MA_DR_WAV_SMPL_LOOP_BYTES * pMetadata->data.smpl.sampleLoopCount + pMetadata->data.smpl.samplerSpecificDataSizeInBytes;
+ bytesWritten += ma_dr_wav__write_or_count(pWav, "smpl", 4);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, chunkSize);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, pMetadata->data.smpl.manufacturerId);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, pMetadata->data.smpl.productId);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, pMetadata->data.smpl.samplePeriodNanoseconds);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, pMetadata->data.smpl.midiUnityNote);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, pMetadata->data.smpl.midiPitchFraction);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, pMetadata->data.smpl.smpteFormat);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, pMetadata->data.smpl.smpteOffset);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, pMetadata->data.smpl.sampleLoopCount);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, pMetadata->data.smpl.samplerSpecificDataSizeInBytes);
for (iLoop = 0; iLoop < pMetadata->data.smpl.sampleLoopCount; ++iLoop) {
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, pMetadata->data.smpl.pLoops[iLoop].cuePointId);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, pMetadata->data.smpl.pLoops[iLoop].type);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, pMetadata->data.smpl.pLoops[iLoop].firstSampleByteOffset);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, pMetadata->data.smpl.pLoops[iLoop].lastSampleByteOffset);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, pMetadata->data.smpl.pLoops[iLoop].sampleFraction);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, pMetadata->data.smpl.pLoops[iLoop].playCount);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, pMetadata->data.smpl.pLoops[iLoop].cuePointId);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, pMetadata->data.smpl.pLoops[iLoop].type);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, pMetadata->data.smpl.pLoops[iLoop].firstSampleByteOffset);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, pMetadata->data.smpl.pLoops[iLoop].lastSampleByteOffset);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, pMetadata->data.smpl.pLoops[iLoop].sampleFraction);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, pMetadata->data.smpl.pLoops[iLoop].playCount);
}
if (pMetadata->data.smpl.samplerSpecificDataSizeInBytes > 0) {
- bytesWritten += drwav__write(pWav, pMetadata->data.smpl.pSamplerSpecificData, pMetadata->data.smpl.samplerSpecificDataSizeInBytes);
+ bytesWritten += ma_dr_wav__write_or_count(pWav, pMetadata->data.smpl.pSamplerSpecificData, pMetadata->data.smpl.samplerSpecificDataSizeInBytes);
}
} break;
- case drwav_metadata_type_inst:
+ case ma_dr_wav_metadata_type_inst:
{
- chunkSize = DRWAV_INST_BYTES;
- bytesWritten += drwav__write_or_count(pWav, "inst", 4);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, chunkSize);
- bytesWritten += drwav__write_or_count(pWav, &pMetadata->data.inst.midiUnityNote, 1);
- bytesWritten += drwav__write_or_count(pWav, &pMetadata->data.inst.fineTuneCents, 1);
- bytesWritten += drwav__write_or_count(pWav, &pMetadata->data.inst.gainDecibels, 1);
- bytesWritten += drwav__write_or_count(pWav, &pMetadata->data.inst.lowNote, 1);
- bytesWritten += drwav__write_or_count(pWav, &pMetadata->data.inst.highNote, 1);
- bytesWritten += drwav__write_or_count(pWav, &pMetadata->data.inst.lowVelocity, 1);
- bytesWritten += drwav__write_or_count(pWav, &pMetadata->data.inst.highVelocity, 1);
+ chunkSize = MA_DR_WAV_INST_BYTES;
+ bytesWritten += ma_dr_wav__write_or_count(pWav, "inst", 4);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, chunkSize);
+ bytesWritten += ma_dr_wav__write_or_count(pWav, &pMetadata->data.inst.midiUnityNote, 1);
+ bytesWritten += ma_dr_wav__write_or_count(pWav, &pMetadata->data.inst.fineTuneCents, 1);
+ bytesWritten += ma_dr_wav__write_or_count(pWav, &pMetadata->data.inst.gainDecibels, 1);
+ bytesWritten += ma_dr_wav__write_or_count(pWav, &pMetadata->data.inst.lowNote, 1);
+ bytesWritten += ma_dr_wav__write_or_count(pWav, &pMetadata->data.inst.highNote, 1);
+ bytesWritten += ma_dr_wav__write_or_count(pWav, &pMetadata->data.inst.lowVelocity, 1);
+ bytesWritten += ma_dr_wav__write_or_count(pWav, &pMetadata->data.inst.highVelocity, 1);
} break;
- case drwav_metadata_type_cue:
+ case ma_dr_wav_metadata_type_cue:
{
- drwav_uint32 iCuePoint;
- chunkSize = DRWAV_CUE_BYTES + DRWAV_CUE_POINT_BYTES * pMetadata->data.cue.cuePointCount;
- bytesWritten += drwav__write_or_count(pWav, "cue ", 4);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, chunkSize);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, pMetadata->data.cue.cuePointCount);
+ ma_uint32 iCuePoint;
+ chunkSize = MA_DR_WAV_CUE_BYTES + MA_DR_WAV_CUE_POINT_BYTES * pMetadata->data.cue.cuePointCount;
+ bytesWritten += ma_dr_wav__write_or_count(pWav, "cue ", 4);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, chunkSize);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, pMetadata->data.cue.cuePointCount);
for (iCuePoint = 0; iCuePoint < pMetadata->data.cue.cuePointCount; ++iCuePoint) {
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, pMetadata->data.cue.pCuePoints[iCuePoint].id);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, pMetadata->data.cue.pCuePoints[iCuePoint].playOrderPosition);
- bytesWritten += drwav__write_or_count(pWav, pMetadata->data.cue.pCuePoints[iCuePoint].dataChunkId, 4);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, pMetadata->data.cue.pCuePoints[iCuePoint].chunkStart);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, pMetadata->data.cue.pCuePoints[iCuePoint].blockStart);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, pMetadata->data.cue.pCuePoints[iCuePoint].sampleByteOffset);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, pMetadata->data.cue.pCuePoints[iCuePoint].id);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, pMetadata->data.cue.pCuePoints[iCuePoint].playOrderPosition);
+ bytesWritten += ma_dr_wav__write_or_count(pWav, pMetadata->data.cue.pCuePoints[iCuePoint].dataChunkId, 4);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, pMetadata->data.cue.pCuePoints[iCuePoint].chunkStart);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, pMetadata->data.cue.pCuePoints[iCuePoint].blockStart);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, pMetadata->data.cue.pCuePoints[iCuePoint].sampleByteOffset);
}
} break;
- case drwav_metadata_type_acid:
+ case ma_dr_wav_metadata_type_acid:
{
- chunkSize = DRWAV_ACID_BYTES;
- bytesWritten += drwav__write_or_count(pWav, "acid", 4);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, chunkSize);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, pMetadata->data.acid.flags);
- bytesWritten += drwav__write_or_count_u16ne_to_le(pWav, pMetadata->data.acid.midiUnityNote);
- bytesWritten += drwav__write_or_count_u16ne_to_le(pWav, pMetadata->data.acid.reserved1);
- bytesWritten += drwav__write_or_count_f32ne_to_le(pWav, pMetadata->data.acid.reserved2);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, pMetadata->data.acid.numBeats);
- bytesWritten += drwav__write_or_count_u16ne_to_le(pWav, pMetadata->data.acid.meterDenominator);
- bytesWritten += drwav__write_or_count_u16ne_to_le(pWav, pMetadata->data.acid.meterNumerator);
- bytesWritten += drwav__write_or_count_f32ne_to_le(pWav, pMetadata->data.acid.tempo);
+ chunkSize = MA_DR_WAV_ACID_BYTES;
+ bytesWritten += ma_dr_wav__write_or_count(pWav, "acid", 4);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, chunkSize);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, pMetadata->data.acid.flags);
+ bytesWritten += ma_dr_wav__write_or_count_u16ne_to_le(pWav, pMetadata->data.acid.midiUnityNote);
+ bytesWritten += ma_dr_wav__write_or_count_u16ne_to_le(pWav, pMetadata->data.acid.reserved1);
+ bytesWritten += ma_dr_wav__write_or_count_f32ne_to_le(pWav, pMetadata->data.acid.reserved2);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, pMetadata->data.acid.numBeats);
+ bytesWritten += ma_dr_wav__write_or_count_u16ne_to_le(pWav, pMetadata->data.acid.meterDenominator);
+ bytesWritten += ma_dr_wav__write_or_count_u16ne_to_le(pWav, pMetadata->data.acid.meterNumerator);
+ bytesWritten += ma_dr_wav__write_or_count_f32ne_to_le(pWav, pMetadata->data.acid.tempo);
} break;
- case drwav_metadata_type_bext:
+ case ma_dr_wav_metadata_type_bext:
{
- char reservedBuf[DRWAV_BEXT_RESERVED_BYTES];
- drwav_uint32 timeReferenceLow;
- drwav_uint32 timeReferenceHigh;
- chunkSize = DRWAV_BEXT_BYTES + pMetadata->data.bext.codingHistorySize;
- bytesWritten += drwav__write_or_count(pWav, "bext", 4);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, chunkSize);
- bytesWritten += drwav__write_or_count_string_to_fixed_size_buf(pWav, pMetadata->data.bext.pDescription, DRWAV_BEXT_DESCRIPTION_BYTES);
- bytesWritten += drwav__write_or_count_string_to_fixed_size_buf(pWav, pMetadata->data.bext.pOriginatorName, DRWAV_BEXT_ORIGINATOR_NAME_BYTES);
- bytesWritten += drwav__write_or_count_string_to_fixed_size_buf(pWav, pMetadata->data.bext.pOriginatorReference, DRWAV_BEXT_ORIGINATOR_REF_BYTES);
- bytesWritten += drwav__write_or_count(pWav, pMetadata->data.bext.pOriginationDate, sizeof(pMetadata->data.bext.pOriginationDate));
- bytesWritten += drwav__write_or_count(pWav, pMetadata->data.bext.pOriginationTime, sizeof(pMetadata->data.bext.pOriginationTime));
- timeReferenceLow = (drwav_uint32)(pMetadata->data.bext.timeReference & 0xFFFFFFFF);
- timeReferenceHigh = (drwav_uint32)(pMetadata->data.bext.timeReference >> 32);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, timeReferenceLow);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, timeReferenceHigh);
- bytesWritten += drwav__write_or_count_u16ne_to_le(pWav, pMetadata->data.bext.version);
- bytesWritten += drwav__write_or_count(pWav, pMetadata->data.bext.pUMID, DRWAV_BEXT_UMID_BYTES);
- bytesWritten += drwav__write_or_count_u16ne_to_le(pWav, pMetadata->data.bext.loudnessValue);
- bytesWritten += drwav__write_or_count_u16ne_to_le(pWav, pMetadata->data.bext.loudnessRange);
- bytesWritten += drwav__write_or_count_u16ne_to_le(pWav, pMetadata->data.bext.maxTruePeakLevel);
- bytesWritten += drwav__write_or_count_u16ne_to_le(pWav, pMetadata->data.bext.maxMomentaryLoudness);
- bytesWritten += drwav__write_or_count_u16ne_to_le(pWav, pMetadata->data.bext.maxShortTermLoudness);
- DRWAV_ZERO_MEMORY(reservedBuf, sizeof(reservedBuf));
- bytesWritten += drwav__write_or_count(pWav, reservedBuf, sizeof(reservedBuf));
+ char reservedBuf[MA_DR_WAV_BEXT_RESERVED_BYTES];
+ ma_uint32 timeReferenceLow;
+ ma_uint32 timeReferenceHigh;
+ chunkSize = MA_DR_WAV_BEXT_BYTES + pMetadata->data.bext.codingHistorySize;
+ bytesWritten += ma_dr_wav__write_or_count(pWav, "bext", 4);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, chunkSize);
+ bytesWritten += ma_dr_wav__write_or_count_string_to_fixed_size_buf(pWav, pMetadata->data.bext.pDescription, MA_DR_WAV_BEXT_DESCRIPTION_BYTES);
+ bytesWritten += ma_dr_wav__write_or_count_string_to_fixed_size_buf(pWav, pMetadata->data.bext.pOriginatorName, MA_DR_WAV_BEXT_ORIGINATOR_NAME_BYTES);
+ bytesWritten += ma_dr_wav__write_or_count_string_to_fixed_size_buf(pWav, pMetadata->data.bext.pOriginatorReference, MA_DR_WAV_BEXT_ORIGINATOR_REF_BYTES);
+ bytesWritten += ma_dr_wav__write_or_count(pWav, pMetadata->data.bext.pOriginationDate, sizeof(pMetadata->data.bext.pOriginationDate));
+ bytesWritten += ma_dr_wav__write_or_count(pWav, pMetadata->data.bext.pOriginationTime, sizeof(pMetadata->data.bext.pOriginationTime));
+ timeReferenceLow = (ma_uint32)(pMetadata->data.bext.timeReference & 0xFFFFFFFF);
+ timeReferenceHigh = (ma_uint32)(pMetadata->data.bext.timeReference >> 32);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, timeReferenceLow);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, timeReferenceHigh);
+ bytesWritten += ma_dr_wav__write_or_count_u16ne_to_le(pWav, pMetadata->data.bext.version);
+ bytesWritten += ma_dr_wav__write_or_count(pWav, pMetadata->data.bext.pUMID, MA_DR_WAV_BEXT_UMID_BYTES);
+ bytesWritten += ma_dr_wav__write_or_count_u16ne_to_le(pWav, pMetadata->data.bext.loudnessValue);
+ bytesWritten += ma_dr_wav__write_or_count_u16ne_to_le(pWav, pMetadata->data.bext.loudnessRange);
+ bytesWritten += ma_dr_wav__write_or_count_u16ne_to_le(pWav, pMetadata->data.bext.maxTruePeakLevel);
+ bytesWritten += ma_dr_wav__write_or_count_u16ne_to_le(pWav, pMetadata->data.bext.maxMomentaryLoudness);
+ bytesWritten += ma_dr_wav__write_or_count_u16ne_to_le(pWav, pMetadata->data.bext.maxShortTermLoudness);
+ MA_DR_WAV_ZERO_MEMORY(reservedBuf, sizeof(reservedBuf));
+ bytesWritten += ma_dr_wav__write_or_count(pWav, reservedBuf, sizeof(reservedBuf));
if (pMetadata->data.bext.codingHistorySize > 0) {
- bytesWritten += drwav__write_or_count(pWav, pMetadata->data.bext.pCodingHistory, pMetadata->data.bext.codingHistorySize);
+ bytesWritten += ma_dr_wav__write_or_count(pWav, pMetadata->data.bext.pCodingHistory, pMetadata->data.bext.codingHistorySize);
}
} break;
- case drwav_metadata_type_unknown:
+ case ma_dr_wav_metadata_type_unknown:
{
- if (pMetadata->data.unknown.chunkLocation == drwav_metadata_location_top_level) {
+ if (pMetadata->data.unknown.chunkLocation == ma_dr_wav_metadata_location_top_level) {
chunkSize = pMetadata->data.unknown.dataSizeInBytes;
- bytesWritten += drwav__write_or_count(pWav, pMetadata->data.unknown.id, 4);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, chunkSize);
- bytesWritten += drwav__write_or_count(pWav, pMetadata->data.unknown.pData, pMetadata->data.unknown.dataSizeInBytes);
+ bytesWritten += ma_dr_wav__write_or_count(pWav, pMetadata->data.unknown.id, 4);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, chunkSize);
+ bytesWritten += ma_dr_wav__write_or_count(pWav, pMetadata->data.unknown.pData, pMetadata->data.unknown.dataSizeInBytes);
}
} break;
default: break;
}
if ((chunkSize % 2) != 0) {
- bytesWritten += drwav__write_or_count_byte(pWav, 0);
+ bytesWritten += ma_dr_wav__write_or_count_byte(pWav, 0);
}
}
if (hasListInfo) {
- drwav_uint32 chunkSize = 4;
+ ma_uint32 chunkSize = 4;
for (iMetadata = 0; iMetadata < metadataCount; ++iMetadata) {
- drwav_metadata* pMetadata = &pMetadatas[iMetadata];
- if ((pMetadata->type & drwav_metadata_type_list_all_info_strings)) {
+ ma_dr_wav_metadata* pMetadata = &pMetadatas[iMetadata];
+ if ((pMetadata->type & ma_dr_wav_metadata_type_list_all_info_strings)) {
chunkSize += 8;
chunkSize += pMetadata->data.infoText.stringLength + 1;
- } else if (pMetadata->type == drwav_metadata_type_unknown && pMetadata->data.unknown.chunkLocation == drwav_metadata_location_inside_info_list) {
+ } else if (pMetadata->type == ma_dr_wav_metadata_type_unknown && pMetadata->data.unknown.chunkLocation == ma_dr_wav_metadata_location_inside_info_list) {
chunkSize += 8;
chunkSize += pMetadata->data.unknown.dataSizeInBytes;
}
@@ -76361,73 +79301,73 @@ DRWAV_PRIVATE size_t drwav__write_or_count_metadata(drwav* pWav, drwav_metadata*
chunkSize += 1;
}
}
- bytesWritten += drwav__write_or_count(pWav, "LIST", 4);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, chunkSize);
- bytesWritten += drwav__write_or_count(pWav, "INFO", 4);
+ bytesWritten += ma_dr_wav__write_or_count(pWav, "LIST", 4);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, chunkSize);
+ bytesWritten += ma_dr_wav__write_or_count(pWav, "INFO", 4);
for (iMetadata = 0; iMetadata < metadataCount; ++iMetadata) {
- drwav_metadata* pMetadata = &pMetadatas[iMetadata];
- drwav_uint32 subchunkSize = 0;
- if (pMetadata->type & drwav_metadata_type_list_all_info_strings) {
+ ma_dr_wav_metadata* pMetadata = &pMetadatas[iMetadata];
+ ma_uint32 subchunkSize = 0;
+ if (pMetadata->type & ma_dr_wav_metadata_type_list_all_info_strings) {
const char* pID = NULL;
switch (pMetadata->type) {
- case drwav_metadata_type_list_info_software: pID = "ISFT"; break;
- case drwav_metadata_type_list_info_copyright: pID = "ICOP"; break;
- case drwav_metadata_type_list_info_title: pID = "INAM"; break;
- case drwav_metadata_type_list_info_artist: pID = "IART"; break;
- case drwav_metadata_type_list_info_comment: pID = "ICMT"; break;
- case drwav_metadata_type_list_info_date: pID = "ICRD"; break;
- case drwav_metadata_type_list_info_genre: pID = "IGNR"; break;
- case drwav_metadata_type_list_info_album: pID = "IPRD"; break;
- case drwav_metadata_type_list_info_tracknumber: pID = "ITRK"; break;
+ case ma_dr_wav_metadata_type_list_info_software: pID = "ISFT"; break;
+ case ma_dr_wav_metadata_type_list_info_copyright: pID = "ICOP"; break;
+ case ma_dr_wav_metadata_type_list_info_title: pID = "INAM"; break;
+ case ma_dr_wav_metadata_type_list_info_artist: pID = "IART"; break;
+ case ma_dr_wav_metadata_type_list_info_comment: pID = "ICMT"; break;
+ case ma_dr_wav_metadata_type_list_info_date: pID = "ICRD"; break;
+ case ma_dr_wav_metadata_type_list_info_genre: pID = "IGNR"; break;
+ case ma_dr_wav_metadata_type_list_info_album: pID = "IPRD"; break;
+ case ma_dr_wav_metadata_type_list_info_tracknumber: pID = "ITRK"; break;
default: break;
}
- DRWAV_ASSERT(pID != NULL);
+ MA_DR_WAV_ASSERT(pID != NULL);
if (pMetadata->data.infoText.stringLength) {
subchunkSize = pMetadata->data.infoText.stringLength + 1;
- bytesWritten += drwav__write_or_count(pWav, pID, 4);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, subchunkSize);
- bytesWritten += drwav__write_or_count(pWav, pMetadata->data.infoText.pString, pMetadata->data.infoText.stringLength);
- bytesWritten += drwav__write_or_count_byte(pWav, '\0');
+ bytesWritten += ma_dr_wav__write_or_count(pWav, pID, 4);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, subchunkSize);
+ bytesWritten += ma_dr_wav__write_or_count(pWav, pMetadata->data.infoText.pString, pMetadata->data.infoText.stringLength);
+ bytesWritten += ma_dr_wav__write_or_count_byte(pWav, '\0');
}
- } else if (pMetadata->type == drwav_metadata_type_unknown && pMetadata->data.unknown.chunkLocation == drwav_metadata_location_inside_info_list) {
+ } else if (pMetadata->type == ma_dr_wav_metadata_type_unknown && pMetadata->data.unknown.chunkLocation == ma_dr_wav_metadata_location_inside_info_list) {
if (pMetadata->data.unknown.dataSizeInBytes) {
subchunkSize = pMetadata->data.unknown.dataSizeInBytes;
- bytesWritten += drwav__write_or_count(pWav, pMetadata->data.unknown.id, 4);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, pMetadata->data.unknown.dataSizeInBytes);
- bytesWritten += drwav__write_or_count(pWav, pMetadata->data.unknown.pData, subchunkSize);
+ bytesWritten += ma_dr_wav__write_or_count(pWav, pMetadata->data.unknown.id, 4);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, pMetadata->data.unknown.dataSizeInBytes);
+ bytesWritten += ma_dr_wav__write_or_count(pWav, pMetadata->data.unknown.pData, subchunkSize);
}
}
if ((subchunkSize % 2) != 0) {
- bytesWritten += drwav__write_or_count_byte(pWav, 0);
+ bytesWritten += ma_dr_wav__write_or_count_byte(pWav, 0);
}
}
}
if (hasListAdtl) {
- drwav_uint32 chunkSize = 4;
+ ma_uint32 chunkSize = 4;
for (iMetadata = 0; iMetadata < metadataCount; ++iMetadata) {
- drwav_metadata* pMetadata = &pMetadatas[iMetadata];
+ ma_dr_wav_metadata* pMetadata = &pMetadatas[iMetadata];
switch (pMetadata->type)
{
- case drwav_metadata_type_list_label:
- case drwav_metadata_type_list_note:
+ case ma_dr_wav_metadata_type_list_label:
+ case ma_dr_wav_metadata_type_list_note:
{
chunkSize += 8;
- chunkSize += DRWAV_LIST_LABEL_OR_NOTE_BYTES;
+ chunkSize += MA_DR_WAV_LIST_LABEL_OR_NOTE_BYTES;
if (pMetadata->data.labelOrNote.stringLength > 0) {
chunkSize += pMetadata->data.labelOrNote.stringLength + 1;
}
} break;
- case drwav_metadata_type_list_labelled_cue_region:
+ case ma_dr_wav_metadata_type_list_labelled_cue_region:
{
chunkSize += 8;
- chunkSize += DRWAV_LIST_LABELLED_TEXT_BYTES;
+ chunkSize += MA_DR_WAV_LIST_LABELLED_TEXT_BYTES;
if (pMetadata->data.labelledCueRegion.stringLength > 0) {
chunkSize += pMetadata->data.labelledCueRegion.stringLength + 1;
}
} break;
- case drwav_metadata_type_unknown:
+ case ma_dr_wav_metadata_type_unknown:
{
- if (pMetadata->data.unknown.chunkLocation == drwav_metadata_location_inside_adtl_list) {
+ if (pMetadata->data.unknown.chunkLocation == ma_dr_wav_metadata_location_inside_adtl_list) {
chunkSize += 8;
chunkSize += pMetadata->data.unknown.dataSizeInBytes;
}
@@ -76438,968 +79378,457 @@ DRWAV_PRIVATE size_t drwav__write_or_count_metadata(drwav* pWav, drwav_metadata*
chunkSize += 1;
}
}
- bytesWritten += drwav__write_or_count(pWav, "LIST", 4);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, chunkSize);
- bytesWritten += drwav__write_or_count(pWav, "adtl", 4);
+ bytesWritten += ma_dr_wav__write_or_count(pWav, "LIST", 4);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, chunkSize);
+ bytesWritten += ma_dr_wav__write_or_count(pWav, "adtl", 4);
for (iMetadata = 0; iMetadata < metadataCount; ++iMetadata) {
- drwav_metadata* pMetadata = &pMetadatas[iMetadata];
- drwav_uint32 subchunkSize = 0;
+ ma_dr_wav_metadata* pMetadata = &pMetadatas[iMetadata];
+ ma_uint32 subchunkSize = 0;
switch (pMetadata->type)
{
- case drwav_metadata_type_list_label:
- case drwav_metadata_type_list_note:
+ case ma_dr_wav_metadata_type_list_label:
+ case ma_dr_wav_metadata_type_list_note:
{
if (pMetadata->data.labelOrNote.stringLength > 0) {
const char *pID = NULL;
- if (pMetadata->type == drwav_metadata_type_list_label) {
+ if (pMetadata->type == ma_dr_wav_metadata_type_list_label) {
pID = "labl";
}
- else if (pMetadata->type == drwav_metadata_type_list_note) {
+ else if (pMetadata->type == ma_dr_wav_metadata_type_list_note) {
pID = "note";
}
- DRWAV_ASSERT(pID != NULL);
- DRWAV_ASSERT(pMetadata->data.labelOrNote.pString != NULL);
- subchunkSize = DRWAV_LIST_LABEL_OR_NOTE_BYTES;
- bytesWritten += drwav__write_or_count(pWav, pID, 4);
+ MA_DR_WAV_ASSERT(pID != NULL);
+ MA_DR_WAV_ASSERT(pMetadata->data.labelOrNote.pString != NULL);
+ subchunkSize = MA_DR_WAV_LIST_LABEL_OR_NOTE_BYTES;
+ bytesWritten += ma_dr_wav__write_or_count(pWav, pID, 4);
subchunkSize += pMetadata->data.labelOrNote.stringLength + 1;
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, subchunkSize);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, pMetadata->data.labelOrNote.cuePointId);
- bytesWritten += drwav__write_or_count(pWav, pMetadata->data.labelOrNote.pString, pMetadata->data.labelOrNote.stringLength);
- bytesWritten += drwav__write_or_count_byte(pWav, '\0');
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, subchunkSize);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, pMetadata->data.labelOrNote.cuePointId);
+ bytesWritten += ma_dr_wav__write_or_count(pWav, pMetadata->data.labelOrNote.pString, pMetadata->data.labelOrNote.stringLength);
+ bytesWritten += ma_dr_wav__write_or_count_byte(pWav, '\0');
}
} break;
- case drwav_metadata_type_list_labelled_cue_region:
+ case ma_dr_wav_metadata_type_list_labelled_cue_region:
{
- subchunkSize = DRWAV_LIST_LABELLED_TEXT_BYTES;
- bytesWritten += drwav__write_or_count(pWav, "ltxt", 4);
+ subchunkSize = MA_DR_WAV_LIST_LABELLED_TEXT_BYTES;
+ bytesWritten += ma_dr_wav__write_or_count(pWav, "ltxt", 4);
if (pMetadata->data.labelledCueRegion.stringLength > 0) {
subchunkSize += pMetadata->data.labelledCueRegion.stringLength + 1;
}
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, subchunkSize);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, pMetadata->data.labelledCueRegion.cuePointId);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, pMetadata->data.labelledCueRegion.sampleLength);
- bytesWritten += drwav__write_or_count(pWav, pMetadata->data.labelledCueRegion.purposeId, 4);
- bytesWritten += drwav__write_or_count_u16ne_to_le(pWav, pMetadata->data.labelledCueRegion.country);
- bytesWritten += drwav__write_or_count_u16ne_to_le(pWav, pMetadata->data.labelledCueRegion.language);
- bytesWritten += drwav__write_or_count_u16ne_to_le(pWav, pMetadata->data.labelledCueRegion.dialect);
- bytesWritten += drwav__write_or_count_u16ne_to_le(pWav, pMetadata->data.labelledCueRegion.codePage);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, subchunkSize);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, pMetadata->data.labelledCueRegion.cuePointId);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, pMetadata->data.labelledCueRegion.sampleLength);
+ bytesWritten += ma_dr_wav__write_or_count(pWav, pMetadata->data.labelledCueRegion.purposeId, 4);
+ bytesWritten += ma_dr_wav__write_or_count_u16ne_to_le(pWav, pMetadata->data.labelledCueRegion.country);
+ bytesWritten += ma_dr_wav__write_or_count_u16ne_to_le(pWav, pMetadata->data.labelledCueRegion.language);
+ bytesWritten += ma_dr_wav__write_or_count_u16ne_to_le(pWav, pMetadata->data.labelledCueRegion.dialect);
+ bytesWritten += ma_dr_wav__write_or_count_u16ne_to_le(pWav, pMetadata->data.labelledCueRegion.codePage);
if (pMetadata->data.labelledCueRegion.stringLength > 0) {
- DRWAV_ASSERT(pMetadata->data.labelledCueRegion.pString != NULL);
- bytesWritten += drwav__write_or_count(pWav, pMetadata->data.labelledCueRegion.pString, pMetadata->data.labelledCueRegion.stringLength);
- bytesWritten += drwav__write_or_count_byte(pWav, '\0');
+ MA_DR_WAV_ASSERT(pMetadata->data.labelledCueRegion.pString != NULL);
+ bytesWritten += ma_dr_wav__write_or_count(pWav, pMetadata->data.labelledCueRegion.pString, pMetadata->data.labelledCueRegion.stringLength);
+ bytesWritten += ma_dr_wav__write_or_count_byte(pWav, '\0');
}
} break;
- case drwav_metadata_type_unknown:
+ case ma_dr_wav_metadata_type_unknown:
{
- if (pMetadata->data.unknown.chunkLocation == drwav_metadata_location_inside_adtl_list) {
+ if (pMetadata->data.unknown.chunkLocation == ma_dr_wav_metadata_location_inside_adtl_list) {
subchunkSize = pMetadata->data.unknown.dataSizeInBytes;
- DRWAV_ASSERT(pMetadata->data.unknown.pData != NULL);
- bytesWritten += drwav__write_or_count(pWav, pMetadata->data.unknown.id, 4);
- bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, subchunkSize);
- bytesWritten += drwav__write_or_count(pWav, pMetadata->data.unknown.pData, subchunkSize);
+ MA_DR_WAV_ASSERT(pMetadata->data.unknown.pData != NULL);
+ bytesWritten += ma_dr_wav__write_or_count(pWav, pMetadata->data.unknown.id, 4);
+ bytesWritten += ma_dr_wav__write_or_count_u32ne_to_le(pWav, subchunkSize);
+ bytesWritten += ma_dr_wav__write_or_count(pWav, pMetadata->data.unknown.pData, subchunkSize);
}
} break;
default: break;
}
if ((subchunkSize % 2) != 0) {
- bytesWritten += drwav__write_or_count_byte(pWav, 0);
+ bytesWritten += ma_dr_wav__write_or_count_byte(pWav, 0);
}
}
}
- DRWAV_ASSERT((bytesWritten % 2) == 0);
+ MA_DR_WAV_ASSERT((bytesWritten % 2) == 0);
return bytesWritten;
}
-DRWAV_PRIVATE drwav_uint32 drwav__riff_chunk_size_riff(drwav_uint64 dataChunkSize, drwav_metadata* pMetadata, drwav_uint32 metadataCount)
+MA_PRIVATE ma_uint32 ma_dr_wav__riff_chunk_size_riff(ma_uint64 dataChunkSize, ma_dr_wav_metadata* pMetadata, ma_uint32 metadataCount)
{
- drwav_uint64 chunkSize = 4 + 24 + (drwav_uint64)drwav__write_or_count_metadata(NULL, pMetadata, metadataCount) + 8 + dataChunkSize + drwav__chunk_padding_size_riff(dataChunkSize);
+ ma_uint64 chunkSize = 4 + 24 + (ma_uint64)ma_dr_wav__write_or_count_metadata(NULL, pMetadata, metadataCount) + 8 + dataChunkSize + ma_dr_wav__chunk_padding_size_riff(dataChunkSize);
if (chunkSize > 0xFFFFFFFFUL) {
chunkSize = 0xFFFFFFFFUL;
}
- return (drwav_uint32)chunkSize;
+ return (ma_uint32)chunkSize;
}
-DRWAV_PRIVATE drwav_uint32 drwav__data_chunk_size_riff(drwav_uint64 dataChunkSize)
+MA_PRIVATE ma_uint32 ma_dr_wav__data_chunk_size_riff(ma_uint64 dataChunkSize)
{
if (dataChunkSize <= 0xFFFFFFFFUL) {
- return (drwav_uint32)dataChunkSize;
+ return (ma_uint32)dataChunkSize;
} else {
return 0xFFFFFFFFUL;
}
}
-DRWAV_PRIVATE drwav_uint64 drwav__riff_chunk_size_w64(drwav_uint64 dataChunkSize)
+MA_PRIVATE ma_uint64 ma_dr_wav__riff_chunk_size_w64(ma_uint64 dataChunkSize)
{
- drwav_uint64 dataSubchunkPaddingSize = drwav__chunk_padding_size_w64(dataChunkSize);
+ ma_uint64 dataSubchunkPaddingSize = ma_dr_wav__chunk_padding_size_w64(dataChunkSize);
return 80 + 24 + dataChunkSize + dataSubchunkPaddingSize;
}
-DRWAV_PRIVATE drwav_uint64 drwav__data_chunk_size_w64(drwav_uint64 dataChunkSize)
+MA_PRIVATE ma_uint64 ma_dr_wav__data_chunk_size_w64(ma_uint64 dataChunkSize)
{
return 24 + dataChunkSize;
}
-DRWAV_PRIVATE drwav_uint64 drwav__riff_chunk_size_rf64(drwav_uint64 dataChunkSize, drwav_metadata *metadata, drwav_uint32 numMetadata)
+MA_PRIVATE ma_uint64 ma_dr_wav__riff_chunk_size_rf64(ma_uint64 dataChunkSize, ma_dr_wav_metadata *metadata, ma_uint32 numMetadata)
{
- drwav_uint64 chunkSize = 4 + 36 + 24 + (drwav_uint64)drwav__write_or_count_metadata(NULL, metadata, numMetadata) + 8 + dataChunkSize + drwav__chunk_padding_size_riff(dataChunkSize);
+ ma_uint64 chunkSize = 4 + 36 + 24 + (ma_uint64)ma_dr_wav__write_or_count_metadata(NULL, metadata, numMetadata) + 8 + dataChunkSize + ma_dr_wav__chunk_padding_size_riff(dataChunkSize);
if (chunkSize > 0xFFFFFFFFUL) {
chunkSize = 0xFFFFFFFFUL;
}
return chunkSize;
}
-DRWAV_PRIVATE drwav_uint64 drwav__data_chunk_size_rf64(drwav_uint64 dataChunkSize)
+MA_PRIVATE ma_uint64 ma_dr_wav__data_chunk_size_rf64(ma_uint64 dataChunkSize)
{
return dataChunkSize;
}
-DRWAV_PRIVATE drwav_bool32 drwav_preinit_write(drwav* pWav, const drwav_data_format* pFormat, drwav_bool32 isSequential, drwav_write_proc onWrite, drwav_seek_proc onSeek, void* pUserData, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_PRIVATE ma_bool32 ma_dr_wav_preinit_write(ma_dr_wav* pWav, const ma_dr_wav_data_format* pFormat, ma_bool32 isSequential, ma_dr_wav_write_proc onWrite, ma_dr_wav_seek_proc onSeek, void* pUserData, const ma_allocation_callbacks* pAllocationCallbacks)
{
if (pWav == NULL || onWrite == NULL) {
- return DRWAV_FALSE;
+ return MA_FALSE;
}
if (!isSequential && onSeek == NULL) {
- return DRWAV_FALSE;
+ return MA_FALSE;
}
- if (pFormat->format == DR_WAVE_FORMAT_EXTENSIBLE) {
- return DRWAV_FALSE;
+ if (pFormat->format == MA_DR_WAVE_FORMAT_EXTENSIBLE) {
+ return MA_FALSE;
}
- if (pFormat->format == DR_WAVE_FORMAT_ADPCM || pFormat->format == DR_WAVE_FORMAT_DVI_ADPCM) {
- return DRWAV_FALSE;
+ if (pFormat->format == MA_DR_WAVE_FORMAT_ADPCM || pFormat->format == MA_DR_WAVE_FORMAT_DVI_ADPCM) {
+ return MA_FALSE;
}
- DRWAV_ZERO_MEMORY(pWav, sizeof(*pWav));
+ MA_DR_WAV_ZERO_MEMORY(pWav, sizeof(*pWav));
pWav->onWrite = onWrite;
pWav->onSeek = onSeek;
pWav->pUserData = pUserData;
- pWav->allocationCallbacks = drwav_copy_allocation_callbacks_or_defaults(pAllocationCallbacks);
+ pWav->allocationCallbacks = ma_dr_wav_copy_allocation_callbacks_or_defaults(pAllocationCallbacks);
if (pWav->allocationCallbacks.onFree == NULL || (pWav->allocationCallbacks.onMalloc == NULL && pWav->allocationCallbacks.onRealloc == NULL)) {
- return DRWAV_FALSE;
+ return MA_FALSE;
}
- pWav->fmt.formatTag = (drwav_uint16)pFormat->format;
- pWav->fmt.channels = (drwav_uint16)pFormat->channels;
+ pWav->fmt.formatTag = (ma_uint16)pFormat->format;
+ pWav->fmt.channels = (ma_uint16)pFormat->channels;
pWav->fmt.sampleRate = pFormat->sampleRate;
- pWav->fmt.avgBytesPerSec = (drwav_uint32)((pFormat->bitsPerSample * pFormat->sampleRate * pFormat->channels) / 8);
- pWav->fmt.blockAlign = (drwav_uint16)((pFormat->channels * pFormat->bitsPerSample) / 8);
- pWav->fmt.bitsPerSample = (drwav_uint16)pFormat->bitsPerSample;
+ pWav->fmt.avgBytesPerSec = (ma_uint32)((pFormat->bitsPerSample * pFormat->sampleRate * pFormat->channels) / 8);
+ pWav->fmt.blockAlign = (ma_uint16)((pFormat->channels * pFormat->bitsPerSample) / 8);
+ pWav->fmt.bitsPerSample = (ma_uint16)pFormat->bitsPerSample;
pWav->fmt.extendedSize = 0;
pWav->isSequentialWrite = isSequential;
- return DRWAV_TRUE;
+ return MA_TRUE;
}
-DRWAV_PRIVATE drwav_bool32 drwav_init_write__internal(drwav* pWav, const drwav_data_format* pFormat, drwav_uint64 totalSampleCount)
+MA_PRIVATE ma_bool32 ma_dr_wav_init_write__internal(ma_dr_wav* pWav, const ma_dr_wav_data_format* pFormat, ma_uint64 totalSampleCount)
{
size_t runningPos = 0;
- drwav_uint64 initialDataChunkSize = 0;
- drwav_uint64 chunkSizeFMT;
+ ma_uint64 initialDataChunkSize = 0;
+ ma_uint64 chunkSizeFMT;
if (pWav->isSequentialWrite) {
initialDataChunkSize = (totalSampleCount * pWav->fmt.bitsPerSample) / 8;
- if (pFormat->container == drwav_container_riff) {
+ if (pFormat->container == ma_dr_wav_container_riff) {
if (initialDataChunkSize > (0xFFFFFFFFUL - 36)) {
- return DRWAV_FALSE;
+ return MA_FALSE;
}
}
}
pWav->dataChunkDataSizeTargetWrite = initialDataChunkSize;
- if (pFormat->container == drwav_container_riff) {
- drwav_uint32 chunkSizeRIFF = 28 + (drwav_uint32)initialDataChunkSize;
- runningPos += drwav__write(pWav, "RIFF", 4);
- runningPos += drwav__write_u32ne_to_le(pWav, chunkSizeRIFF);
- runningPos += drwav__write(pWav, "WAVE", 4);
- } else if (pFormat->container == drwav_container_w64) {
- drwav_uint64 chunkSizeRIFF = 80 + 24 + initialDataChunkSize;
- runningPos += drwav__write(pWav, drwavGUID_W64_RIFF, 16);
- runningPos += drwav__write_u64ne_to_le(pWav, chunkSizeRIFF);
- runningPos += drwav__write(pWav, drwavGUID_W64_WAVE, 16);
- } else if (pFormat->container == drwav_container_rf64) {
- runningPos += drwav__write(pWav, "RF64", 4);
- runningPos += drwav__write_u32ne_to_le(pWav, 0xFFFFFFFF);
- runningPos += drwav__write(pWav, "WAVE", 4);
- }
- if (pFormat->container == drwav_container_rf64) {
- drwav_uint32 initialds64ChunkSize = 28;
- drwav_uint64 initialRiffChunkSize = 8 + initialds64ChunkSize + initialDataChunkSize;
- runningPos += drwav__write(pWav, "ds64", 4);
- runningPos += drwav__write_u32ne_to_le(pWav, initialds64ChunkSize);
- runningPos += drwav__write_u64ne_to_le(pWav, initialRiffChunkSize);
- runningPos += drwav__write_u64ne_to_le(pWav, initialDataChunkSize);
- runningPos += drwav__write_u64ne_to_le(pWav, totalSampleCount);
- runningPos += drwav__write_u32ne_to_le(pWav, 0);
- }
- if (pFormat->container == drwav_container_riff || pFormat->container == drwav_container_rf64) {
+ if (pFormat->container == ma_dr_wav_container_riff) {
+ ma_uint32 chunkSizeRIFF = 28 + (ma_uint32)initialDataChunkSize;
+ runningPos += ma_dr_wav__write(pWav, "RIFF", 4);
+ runningPos += ma_dr_wav__write_u32ne_to_le(pWav, chunkSizeRIFF);
+ runningPos += ma_dr_wav__write(pWav, "WAVE", 4);
+ } else if (pFormat->container == ma_dr_wav_container_w64) {
+ ma_uint64 chunkSizeRIFF = 80 + 24 + initialDataChunkSize;
+ runningPos += ma_dr_wav__write(pWav, ma_dr_wavGUID_W64_RIFF, 16);
+ runningPos += ma_dr_wav__write_u64ne_to_le(pWav, chunkSizeRIFF);
+ runningPos += ma_dr_wav__write(pWav, ma_dr_wavGUID_W64_WAVE, 16);
+ } else if (pFormat->container == ma_dr_wav_container_rf64) {
+ runningPos += ma_dr_wav__write(pWav, "RF64", 4);
+ runningPos += ma_dr_wav__write_u32ne_to_le(pWav, 0xFFFFFFFF);
+ runningPos += ma_dr_wav__write(pWav, "WAVE", 4);
+ } else {
+ return MA_FALSE;
+ }
+ if (pFormat->container == ma_dr_wav_container_rf64) {
+ ma_uint32 initialds64ChunkSize = 28;
+ ma_uint64 initialRiffChunkSize = 8 + initialds64ChunkSize + initialDataChunkSize;
+ runningPos += ma_dr_wav__write(pWav, "ds64", 4);
+ runningPos += ma_dr_wav__write_u32ne_to_le(pWav, initialds64ChunkSize);
+ runningPos += ma_dr_wav__write_u64ne_to_le(pWav, initialRiffChunkSize);
+ runningPos += ma_dr_wav__write_u64ne_to_le(pWav, initialDataChunkSize);
+ runningPos += ma_dr_wav__write_u64ne_to_le(pWav, totalSampleCount);
+ runningPos += ma_dr_wav__write_u32ne_to_le(pWav, 0);
+ }
+ if (pFormat->container == ma_dr_wav_container_riff || pFormat->container == ma_dr_wav_container_rf64) {
chunkSizeFMT = 16;
- runningPos += drwav__write(pWav, "fmt ", 4);
- runningPos += drwav__write_u32ne_to_le(pWav, (drwav_uint32)chunkSizeFMT);
- } else if (pFormat->container == drwav_container_w64) {
+ runningPos += ma_dr_wav__write(pWav, "fmt ", 4);
+ runningPos += ma_dr_wav__write_u32ne_to_le(pWav, (ma_uint32)chunkSizeFMT);
+ } else if (pFormat->container == ma_dr_wav_container_w64) {
chunkSizeFMT = 40;
- runningPos += drwav__write(pWav, drwavGUID_W64_FMT, 16);
- runningPos += drwav__write_u64ne_to_le(pWav, chunkSizeFMT);
- }
- runningPos += drwav__write_u16ne_to_le(pWav, pWav->fmt.formatTag);
- runningPos += drwav__write_u16ne_to_le(pWav, pWav->fmt.channels);
- runningPos += drwav__write_u32ne_to_le(pWav, pWav->fmt.sampleRate);
- runningPos += drwav__write_u32ne_to_le(pWav, pWav->fmt.avgBytesPerSec);
- runningPos += drwav__write_u16ne_to_le(pWav, pWav->fmt.blockAlign);
- runningPos += drwav__write_u16ne_to_le(pWav, pWav->fmt.bitsPerSample);
- if (!pWav->isSequentialWrite && pWav->pMetadata != NULL && pWav->metadataCount > 0 && (pFormat->container == drwav_container_riff || pFormat->container == drwav_container_rf64)) {
- runningPos += drwav__write_or_count_metadata(pWav, pWav->pMetadata, pWav->metadataCount);
+ runningPos += ma_dr_wav__write(pWav, ma_dr_wavGUID_W64_FMT, 16);
+ runningPos += ma_dr_wav__write_u64ne_to_le(pWav, chunkSizeFMT);
+ }
+ runningPos += ma_dr_wav__write_u16ne_to_le(pWav, pWav->fmt.formatTag);
+ runningPos += ma_dr_wav__write_u16ne_to_le(pWav, pWav->fmt.channels);
+ runningPos += ma_dr_wav__write_u32ne_to_le(pWav, pWav->fmt.sampleRate);
+ runningPos += ma_dr_wav__write_u32ne_to_le(pWav, pWav->fmt.avgBytesPerSec);
+ runningPos += ma_dr_wav__write_u16ne_to_le(pWav, pWav->fmt.blockAlign);
+ runningPos += ma_dr_wav__write_u16ne_to_le(pWav, pWav->fmt.bitsPerSample);
+ if (!pWav->isSequentialWrite && pWav->pMetadata != NULL && pWav->metadataCount > 0 && (pFormat->container == ma_dr_wav_container_riff || pFormat->container == ma_dr_wav_container_rf64)) {
+ runningPos += ma_dr_wav__write_or_count_metadata(pWav, pWav->pMetadata, pWav->metadataCount);
}
pWav->dataChunkDataPos = runningPos;
- if (pFormat->container == drwav_container_riff) {
- drwav_uint32 chunkSizeDATA = (drwav_uint32)initialDataChunkSize;
- runningPos += drwav__write(pWav, "data", 4);
- runningPos += drwav__write_u32ne_to_le(pWav, chunkSizeDATA);
- } else if (pFormat->container == drwav_container_w64) {
- drwav_uint64 chunkSizeDATA = 24 + initialDataChunkSize;
- runningPos += drwav__write(pWav, drwavGUID_W64_DATA, 16);
- runningPos += drwav__write_u64ne_to_le(pWav, chunkSizeDATA);
- } else if (pFormat->container == drwav_container_rf64) {
- runningPos += drwav__write(pWav, "data", 4);
- runningPos += drwav__write_u32ne_to_le(pWav, 0xFFFFFFFF);
+ if (pFormat->container == ma_dr_wav_container_riff) {
+ ma_uint32 chunkSizeDATA = (ma_uint32)initialDataChunkSize;
+ runningPos += ma_dr_wav__write(pWav, "data", 4);
+ runningPos += ma_dr_wav__write_u32ne_to_le(pWav, chunkSizeDATA);
+ } else if (pFormat->container == ma_dr_wav_container_w64) {
+ ma_uint64 chunkSizeDATA = 24 + initialDataChunkSize;
+ runningPos += ma_dr_wav__write(pWav, ma_dr_wavGUID_W64_DATA, 16);
+ runningPos += ma_dr_wav__write_u64ne_to_le(pWav, chunkSizeDATA);
+ } else if (pFormat->container == ma_dr_wav_container_rf64) {
+ runningPos += ma_dr_wav__write(pWav, "data", 4);
+ runningPos += ma_dr_wav__write_u32ne_to_le(pWav, 0xFFFFFFFF);
}
pWav->container = pFormat->container;
- pWav->channels = (drwav_uint16)pFormat->channels;
+ pWav->channels = (ma_uint16)pFormat->channels;
pWav->sampleRate = pFormat->sampleRate;
- pWav->bitsPerSample = (drwav_uint16)pFormat->bitsPerSample;
- pWav->translatedFormatTag = (drwav_uint16)pFormat->format;
+ pWav->bitsPerSample = (ma_uint16)pFormat->bitsPerSample;
+ pWav->translatedFormatTag = (ma_uint16)pFormat->format;
pWav->dataChunkDataPos = runningPos;
- return DRWAV_TRUE;
+ return MA_TRUE;
}
-DRWAV_API drwav_bool32 drwav_init_write(drwav* pWav, const drwav_data_format* pFormat, drwav_write_proc onWrite, drwav_seek_proc onSeek, void* pUserData, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_bool32 ma_dr_wav_init_write(ma_dr_wav* pWav, const ma_dr_wav_data_format* pFormat, ma_dr_wav_write_proc onWrite, ma_dr_wav_seek_proc onSeek, void* pUserData, const ma_allocation_callbacks* pAllocationCallbacks)
{
- if (!drwav_preinit_write(pWav, pFormat, DRWAV_FALSE, onWrite, onSeek, pUserData, pAllocationCallbacks)) {
- return DRWAV_FALSE;
+ if (!ma_dr_wav_preinit_write(pWav, pFormat, MA_FALSE, onWrite, onSeek, pUserData, pAllocationCallbacks)) {
+ return MA_FALSE;
}
- return drwav_init_write__internal(pWav, pFormat, 0);
+ return ma_dr_wav_init_write__internal(pWav, pFormat, 0);
}
-DRWAV_API drwav_bool32 drwav_init_write_sequential(drwav* pWav, const drwav_data_format* pFormat, drwav_uint64 totalSampleCount, drwav_write_proc onWrite, void* pUserData, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_bool32 ma_dr_wav_init_write_sequential(ma_dr_wav* pWav, const ma_dr_wav_data_format* pFormat, ma_uint64 totalSampleCount, ma_dr_wav_write_proc onWrite, void* pUserData, const ma_allocation_callbacks* pAllocationCallbacks)
{
- if (!drwav_preinit_write(pWav, pFormat, DRWAV_TRUE, onWrite, NULL, pUserData, pAllocationCallbacks)) {
- return DRWAV_FALSE;
+ if (!ma_dr_wav_preinit_write(pWav, pFormat, MA_TRUE, onWrite, NULL, pUserData, pAllocationCallbacks)) {
+ return MA_FALSE;
}
- return drwav_init_write__internal(pWav, pFormat, totalSampleCount);
+ return ma_dr_wav_init_write__internal(pWav, pFormat, totalSampleCount);
}
-DRWAV_API drwav_bool32 drwav_init_write_sequential_pcm_frames(drwav* pWav, const drwav_data_format* pFormat, drwav_uint64 totalPCMFrameCount, drwav_write_proc onWrite, void* pUserData, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_bool32 ma_dr_wav_init_write_sequential_pcm_frames(ma_dr_wav* pWav, const ma_dr_wav_data_format* pFormat, ma_uint64 totalPCMFrameCount, ma_dr_wav_write_proc onWrite, void* pUserData, const ma_allocation_callbacks* pAllocationCallbacks)
{
if (pFormat == NULL) {
- return DRWAV_FALSE;
+ return MA_FALSE;
}
- return drwav_init_write_sequential(pWav, pFormat, totalPCMFrameCount*pFormat->channels, onWrite, pUserData, pAllocationCallbacks);
+ return ma_dr_wav_init_write_sequential(pWav, pFormat, totalPCMFrameCount*pFormat->channels, onWrite, pUserData, pAllocationCallbacks);
}
-DRWAV_API drwav_bool32 drwav_init_write_with_metadata(drwav* pWav, const drwav_data_format* pFormat, drwav_write_proc onWrite, drwav_seek_proc onSeek, void* pUserData, const drwav_allocation_callbacks* pAllocationCallbacks, drwav_metadata* pMetadata, drwav_uint32 metadataCount)
+MA_API ma_bool32 ma_dr_wav_init_write_with_metadata(ma_dr_wav* pWav, const ma_dr_wav_data_format* pFormat, ma_dr_wav_write_proc onWrite, ma_dr_wav_seek_proc onSeek, void* pUserData, const ma_allocation_callbacks* pAllocationCallbacks, ma_dr_wav_metadata* pMetadata, ma_uint32 metadataCount)
{
- if (!drwav_preinit_write(pWav, pFormat, DRWAV_FALSE, onWrite, onSeek, pUserData, pAllocationCallbacks)) {
- return DRWAV_FALSE;
+ if (!ma_dr_wav_preinit_write(pWav, pFormat, MA_FALSE, onWrite, onSeek, pUserData, pAllocationCallbacks)) {
+ return MA_FALSE;
}
pWav->pMetadata = pMetadata;
pWav->metadataCount = metadataCount;
- return drwav_init_write__internal(pWav, pFormat, 0);
+ return ma_dr_wav_init_write__internal(pWav, pFormat, 0);
}
-DRWAV_API drwav_uint64 drwav_target_write_size_bytes(const drwav_data_format* pFormat, drwav_uint64 totalFrameCount, drwav_metadata* pMetadata, drwav_uint32 metadataCount)
+MA_API ma_uint64 ma_dr_wav_target_write_size_bytes(const ma_dr_wav_data_format* pFormat, ma_uint64 totalFrameCount, ma_dr_wav_metadata* pMetadata, ma_uint32 metadataCount)
{
- drwav_uint64 targetDataSizeBytes = (drwav_uint64)((drwav_int64)totalFrameCount * pFormat->channels * pFormat->bitsPerSample/8.0);
- drwav_uint64 riffChunkSizeBytes;
- drwav_uint64 fileSizeBytes = 0;
- if (pFormat->container == drwav_container_riff) {
- riffChunkSizeBytes = drwav__riff_chunk_size_riff(targetDataSizeBytes, pMetadata, metadataCount);
+ ma_uint64 targetDataSizeBytes = (ma_uint64)((ma_int64)totalFrameCount * pFormat->channels * pFormat->bitsPerSample/8.0);
+ ma_uint64 riffChunkSizeBytes;
+ ma_uint64 fileSizeBytes = 0;
+ if (pFormat->container == ma_dr_wav_container_riff) {
+ riffChunkSizeBytes = ma_dr_wav__riff_chunk_size_riff(targetDataSizeBytes, pMetadata, metadataCount);
fileSizeBytes = (8 + riffChunkSizeBytes);
- } else if (pFormat->container == drwav_container_w64) {
- riffChunkSizeBytes = drwav__riff_chunk_size_w64(targetDataSizeBytes);
+ } else if (pFormat->container == ma_dr_wav_container_w64) {
+ riffChunkSizeBytes = ma_dr_wav__riff_chunk_size_w64(targetDataSizeBytes);
fileSizeBytes = riffChunkSizeBytes;
- } else if (pFormat->container == drwav_container_rf64) {
- riffChunkSizeBytes = drwav__riff_chunk_size_rf64(targetDataSizeBytes, pMetadata, metadataCount);
+ } else if (pFormat->container == ma_dr_wav_container_rf64) {
+ riffChunkSizeBytes = ma_dr_wav__riff_chunk_size_rf64(targetDataSizeBytes, pMetadata, metadataCount);
fileSizeBytes = (8 + riffChunkSizeBytes);
}
return fileSizeBytes;
}
-#ifndef DR_WAV_NO_STDIO
-#include
-DRWAV_PRIVATE drwav_result drwav_result_from_errno(int e)
-{
- switch (e)
- {
- case 0: return DRWAV_SUCCESS;
- #ifdef EPERM
- case EPERM: return DRWAV_INVALID_OPERATION;
- #endif
- #ifdef ENOENT
- case ENOENT: return DRWAV_DOES_NOT_EXIST;
- #endif
- #ifdef ESRCH
- case ESRCH: return DRWAV_DOES_NOT_EXIST;
- #endif
- #ifdef EINTR
- case EINTR: return DRWAV_INTERRUPT;
- #endif
- #ifdef EIO
- case EIO: return DRWAV_IO_ERROR;
- #endif
- #ifdef ENXIO
- case ENXIO: return DRWAV_DOES_NOT_EXIST;
- #endif
- #ifdef E2BIG
- case E2BIG: return DRWAV_INVALID_ARGS;
- #endif
- #ifdef ENOEXEC
- case ENOEXEC: return DRWAV_INVALID_FILE;
- #endif
- #ifdef EBADF
- case EBADF: return DRWAV_INVALID_FILE;
- #endif
- #ifdef ECHILD
- case ECHILD: return DRWAV_ERROR;
- #endif
- #ifdef EAGAIN
- case EAGAIN: return DRWAV_UNAVAILABLE;
- #endif
- #ifdef ENOMEM
- case ENOMEM: return DRWAV_OUT_OF_MEMORY;
- #endif
- #ifdef EACCES
- case EACCES: return DRWAV_ACCESS_DENIED;
- #endif
- #ifdef EFAULT
- case EFAULT: return DRWAV_BAD_ADDRESS;
- #endif
- #ifdef ENOTBLK
- case ENOTBLK: return DRWAV_ERROR;
- #endif
- #ifdef EBUSY
- case EBUSY: return DRWAV_BUSY;
- #endif
- #ifdef EEXIST
- case EEXIST: return DRWAV_ALREADY_EXISTS;
- #endif
- #ifdef EXDEV
- case EXDEV: return DRWAV_ERROR;
- #endif
- #ifdef ENODEV
- case ENODEV: return DRWAV_DOES_NOT_EXIST;
- #endif
- #ifdef ENOTDIR
- case ENOTDIR: return DRWAV_NOT_DIRECTORY;
- #endif
- #ifdef EISDIR
- case EISDIR: return DRWAV_IS_DIRECTORY;
- #endif
- #ifdef EINVAL
- case EINVAL: return DRWAV_INVALID_ARGS;
- #endif
- #ifdef ENFILE
- case ENFILE: return DRWAV_TOO_MANY_OPEN_FILES;
- #endif
- #ifdef EMFILE
- case EMFILE: return DRWAV_TOO_MANY_OPEN_FILES;
- #endif
- #ifdef ENOTTY
- case ENOTTY: return DRWAV_INVALID_OPERATION;
- #endif
- #ifdef ETXTBSY
- case ETXTBSY: return DRWAV_BUSY;
- #endif
- #ifdef EFBIG
- case EFBIG: return DRWAV_TOO_BIG;
- #endif
- #ifdef ENOSPC
- case ENOSPC: return DRWAV_NO_SPACE;
- #endif
- #ifdef ESPIPE
- case ESPIPE: return DRWAV_BAD_SEEK;
- #endif
- #ifdef EROFS
- case EROFS: return DRWAV_ACCESS_DENIED;
- #endif
- #ifdef EMLINK
- case EMLINK: return DRWAV_TOO_MANY_LINKS;
- #endif
- #ifdef EPIPE
- case EPIPE: return DRWAV_BAD_PIPE;
- #endif
- #ifdef EDOM
- case EDOM: return DRWAV_OUT_OF_RANGE;
- #endif
- #ifdef ERANGE
- case ERANGE: return DRWAV_OUT_OF_RANGE;
- #endif
- #ifdef EDEADLK
- case EDEADLK: return DRWAV_DEADLOCK;
- #endif
- #ifdef ENAMETOOLONG
- case ENAMETOOLONG: return DRWAV_PATH_TOO_LONG;
- #endif
- #ifdef ENOLCK
- case ENOLCK: return DRWAV_ERROR;
- #endif
- #ifdef ENOSYS
- case ENOSYS: return DRWAV_NOT_IMPLEMENTED;
- #endif
- #ifdef ENOTEMPTY
- case ENOTEMPTY: return DRWAV_DIRECTORY_NOT_EMPTY;
- #endif
- #ifdef ELOOP
- case ELOOP: return DRWAV_TOO_MANY_LINKS;
- #endif
- #ifdef ENOMSG
- case ENOMSG: return DRWAV_NO_MESSAGE;
- #endif
- #ifdef EIDRM
- case EIDRM: return DRWAV_ERROR;
- #endif
- #ifdef ECHRNG
- case ECHRNG: return DRWAV_ERROR;
- #endif
- #ifdef EL2NSYNC
- case EL2NSYNC: return DRWAV_ERROR;
- #endif
- #ifdef EL3HLT
- case EL3HLT: return DRWAV_ERROR;
- #endif
- #ifdef EL3RST
- case EL3RST: return DRWAV_ERROR;
- #endif
- #ifdef ELNRNG
- case ELNRNG: return DRWAV_OUT_OF_RANGE;
- #endif
- #ifdef EUNATCH
- case EUNATCH: return DRWAV_ERROR;
- #endif
- #ifdef ENOCSI
- case ENOCSI: return DRWAV_ERROR;
- #endif
- #ifdef EL2HLT
- case EL2HLT: return DRWAV_ERROR;
- #endif
- #ifdef EBADE
- case EBADE: return DRWAV_ERROR;
- #endif
- #ifdef EBADR
- case EBADR: return DRWAV_ERROR;
- #endif
- #ifdef EXFULL
- case EXFULL: return DRWAV_ERROR;
- #endif
- #ifdef ENOANO
- case ENOANO: return DRWAV_ERROR;
- #endif
- #ifdef EBADRQC
- case EBADRQC: return DRWAV_ERROR;
- #endif
- #ifdef EBADSLT
- case EBADSLT: return DRWAV_ERROR;
- #endif
- #ifdef EBFONT
- case EBFONT: return DRWAV_INVALID_FILE;
- #endif
- #ifdef ENOSTR
- case ENOSTR: return DRWAV_ERROR;
- #endif
- #ifdef ENODATA
- case ENODATA: return DRWAV_NO_DATA_AVAILABLE;
- #endif
- #ifdef ETIME
- case ETIME: return DRWAV_TIMEOUT;
- #endif
- #ifdef ENOSR
- case ENOSR: return DRWAV_NO_DATA_AVAILABLE;
- #endif
- #ifdef ENONET
- case ENONET: return DRWAV_NO_NETWORK;
- #endif
- #ifdef ENOPKG
- case ENOPKG: return DRWAV_ERROR;
- #endif
- #ifdef EREMOTE
- case EREMOTE: return DRWAV_ERROR;
- #endif
- #ifdef ENOLINK
- case ENOLINK: return DRWAV_ERROR;
- #endif
- #ifdef EADV
- case EADV: return DRWAV_ERROR;
- #endif
- #ifdef ESRMNT
- case ESRMNT: return DRWAV_ERROR;
- #endif
- #ifdef ECOMM
- case ECOMM: return DRWAV_ERROR;
- #endif
- #ifdef EPROTO
- case EPROTO: return DRWAV_ERROR;
- #endif
- #ifdef EMULTIHOP
- case EMULTIHOP: return DRWAV_ERROR;
- #endif
- #ifdef EDOTDOT
- case EDOTDOT: return DRWAV_ERROR;
- #endif
- #ifdef EBADMSG
- case EBADMSG: return DRWAV_BAD_MESSAGE;
- #endif
- #ifdef EOVERFLOW
- case EOVERFLOW: return DRWAV_TOO_BIG;
- #endif
- #ifdef ENOTUNIQ
- case ENOTUNIQ: return DRWAV_NOT_UNIQUE;
- #endif
- #ifdef EBADFD
- case EBADFD: return DRWAV_ERROR;
- #endif
- #ifdef EREMCHG
- case EREMCHG: return DRWAV_ERROR;
- #endif
- #ifdef ELIBACC
- case ELIBACC: return DRWAV_ACCESS_DENIED;
- #endif
- #ifdef ELIBBAD
- case ELIBBAD: return DRWAV_INVALID_FILE;
- #endif
- #ifdef ELIBSCN
- case ELIBSCN: return DRWAV_INVALID_FILE;
- #endif
- #ifdef ELIBMAX
- case ELIBMAX: return DRWAV_ERROR;
- #endif
- #ifdef ELIBEXEC
- case ELIBEXEC: return DRWAV_ERROR;
- #endif
- #ifdef EILSEQ
- case EILSEQ: return DRWAV_INVALID_DATA;
- #endif
- #ifdef ERESTART
- case ERESTART: return DRWAV_ERROR;
- #endif
- #ifdef ESTRPIPE
- case ESTRPIPE: return DRWAV_ERROR;
- #endif
- #ifdef EUSERS
- case EUSERS: return DRWAV_ERROR;
- #endif
- #ifdef ENOTSOCK
- case ENOTSOCK: return DRWAV_NOT_SOCKET;
- #endif
- #ifdef EDESTADDRREQ
- case EDESTADDRREQ: return DRWAV_NO_ADDRESS;
- #endif
- #ifdef EMSGSIZE
- case EMSGSIZE: return DRWAV_TOO_BIG;
- #endif
- #ifdef EPROTOTYPE
- case EPROTOTYPE: return DRWAV_BAD_PROTOCOL;
- #endif
- #ifdef ENOPROTOOPT
- case ENOPROTOOPT: return DRWAV_PROTOCOL_UNAVAILABLE;
- #endif
- #ifdef EPROTONOSUPPORT
- case EPROTONOSUPPORT: return DRWAV_PROTOCOL_NOT_SUPPORTED;
- #endif
- #ifdef ESOCKTNOSUPPORT
- case ESOCKTNOSUPPORT: return DRWAV_SOCKET_NOT_SUPPORTED;
- #endif
- #ifdef EOPNOTSUPP
- case EOPNOTSUPP: return DRWAV_INVALID_OPERATION;
- #endif
- #ifdef EPFNOSUPPORT
- case EPFNOSUPPORT: return DRWAV_PROTOCOL_FAMILY_NOT_SUPPORTED;
- #endif
- #ifdef EAFNOSUPPORT
- case EAFNOSUPPORT: return DRWAV_ADDRESS_FAMILY_NOT_SUPPORTED;
- #endif
- #ifdef EADDRINUSE
- case EADDRINUSE: return DRWAV_ALREADY_IN_USE;
- #endif
- #ifdef EADDRNOTAVAIL
- case EADDRNOTAVAIL: return DRWAV_ERROR;
- #endif
- #ifdef ENETDOWN
- case ENETDOWN: return DRWAV_NO_NETWORK;
- #endif
- #ifdef ENETUNREACH
- case ENETUNREACH: return DRWAV_NO_NETWORK;
- #endif
- #ifdef ENETRESET
- case ENETRESET: return DRWAV_NO_NETWORK;
- #endif
- #ifdef ECONNABORTED
- case ECONNABORTED: return DRWAV_NO_NETWORK;
- #endif
- #ifdef ECONNRESET
- case ECONNRESET: return DRWAV_CONNECTION_RESET;
- #endif
- #ifdef ENOBUFS
- case ENOBUFS: return DRWAV_NO_SPACE;
- #endif
- #ifdef EISCONN
- case EISCONN: return DRWAV_ALREADY_CONNECTED;
- #endif
- #ifdef ENOTCONN
- case ENOTCONN: return DRWAV_NOT_CONNECTED;
- #endif
- #ifdef ESHUTDOWN
- case ESHUTDOWN: return DRWAV_ERROR;
- #endif
- #ifdef ETOOMANYREFS
- case ETOOMANYREFS: return DRWAV_ERROR;
- #endif
- #ifdef ETIMEDOUT
- case ETIMEDOUT: return DRWAV_TIMEOUT;
- #endif
- #ifdef ECONNREFUSED
- case ECONNREFUSED: return DRWAV_CONNECTION_REFUSED;
- #endif
- #ifdef EHOSTDOWN
- case EHOSTDOWN: return DRWAV_NO_HOST;
- #endif
- #ifdef EHOSTUNREACH
- case EHOSTUNREACH: return DRWAV_NO_HOST;
- #endif
- #ifdef EALREADY
- case EALREADY: return DRWAV_IN_PROGRESS;
- #endif
- #ifdef EINPROGRESS
- case EINPROGRESS: return DRWAV_IN_PROGRESS;
- #endif
- #ifdef ESTALE
- case ESTALE: return DRWAV_INVALID_FILE;
- #endif
- #ifdef EUCLEAN
- case EUCLEAN: return DRWAV_ERROR;
- #endif
- #ifdef ENOTNAM
- case ENOTNAM: return DRWAV_ERROR;
- #endif
- #ifdef ENAVAIL
- case ENAVAIL: return DRWAV_ERROR;
- #endif
- #ifdef EISNAM
- case EISNAM: return DRWAV_ERROR;
- #endif
- #ifdef EREMOTEIO
- case EREMOTEIO: return DRWAV_IO_ERROR;
- #endif
- #ifdef EDQUOT
- case EDQUOT: return DRWAV_NO_SPACE;
- #endif
- #ifdef ENOMEDIUM
- case ENOMEDIUM: return DRWAV_DOES_NOT_EXIST;
- #endif
- #ifdef EMEDIUMTYPE
- case EMEDIUMTYPE: return DRWAV_ERROR;
- #endif
- #ifdef ECANCELED
- case ECANCELED: return DRWAV_CANCELLED;
- #endif
- #ifdef ENOKEY
- case ENOKEY: return DRWAV_ERROR;
- #endif
- #ifdef EKEYEXPIRED
- case EKEYEXPIRED: return DRWAV_ERROR;
- #endif
- #ifdef EKEYREVOKED
- case EKEYREVOKED: return DRWAV_ERROR;
- #endif
- #ifdef EKEYREJECTED
- case EKEYREJECTED: return DRWAV_ERROR;
- #endif
- #ifdef EOWNERDEAD
- case EOWNERDEAD: return DRWAV_ERROR;
- #endif
- #ifdef ENOTRECOVERABLE
- case ENOTRECOVERABLE: return DRWAV_ERROR;
- #endif
- #ifdef ERFKILL
- case ERFKILL: return DRWAV_ERROR;
- #endif
- #ifdef EHWPOISON
- case EHWPOISON: return DRWAV_ERROR;
- #endif
- default: return DRWAV_ERROR;
- }
-}
-DRWAV_PRIVATE drwav_result drwav_fopen(FILE** ppFile, const char* pFilePath, const char* pOpenMode)
-{
-#if defined(_MSC_VER) && _MSC_VER >= 1400
- errno_t err;
-#endif
- if (ppFile != NULL) {
- *ppFile = NULL;
- }
- if (pFilePath == NULL || pOpenMode == NULL || ppFile == NULL) {
- return DRWAV_INVALID_ARGS;
- }
-#if defined(_MSC_VER) && _MSC_VER >= 1400
- err = fopen_s(ppFile, pFilePath, pOpenMode);
- if (err != 0) {
- return drwav_result_from_errno(err);
- }
-#else
-#if defined(_WIN32) || defined(__APPLE__)
- *ppFile = fopen(pFilePath, pOpenMode);
-#else
- #if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64 && defined(_LARGEFILE64_SOURCE)
- *ppFile = fopen64(pFilePath, pOpenMode);
- #else
- *ppFile = fopen(pFilePath, pOpenMode);
- #endif
-#endif
- if (*ppFile == NULL) {
- drwav_result result = drwav_result_from_errno(errno);
- if (result == DRWAV_SUCCESS) {
- result = DRWAV_ERROR;
- }
- return result;
- }
-#endif
- return DRWAV_SUCCESS;
-}
-#if defined(_WIN32)
- #if defined(_MSC_VER) || defined(__MINGW64__) || (!defined(__STRICT_ANSI__) && !defined(_NO_EXT_KEYS))
- #define DRWAV_HAS_WFOPEN
- #endif
-#endif
-#ifndef DR_WAV_NO_WCHAR
-DRWAV_PRIVATE drwav_result drwav_wfopen(FILE** ppFile, const wchar_t* pFilePath, const wchar_t* pOpenMode, const drwav_allocation_callbacks* pAllocationCallbacks)
-{
- if (ppFile != NULL) {
- *ppFile = NULL;
- }
- if (pFilePath == NULL || pOpenMode == NULL || ppFile == NULL) {
- return DRWAV_INVALID_ARGS;
- }
-#if defined(DRWAV_HAS_WFOPEN)
- {
- #if defined(_MSC_VER) && _MSC_VER >= 1400
- errno_t err = _wfopen_s(ppFile, pFilePath, pOpenMode);
- if (err != 0) {
- return drwav_result_from_errno(err);
- }
- #else
- *ppFile = _wfopen(pFilePath, pOpenMode);
- if (*ppFile == NULL) {
- return drwav_result_from_errno(errno);
- }
- #endif
- (void)pAllocationCallbacks;
- }
-#else
- #if defined(__DJGPP__)
- {
- }
- #else
- {
- mbstate_t mbs;
- size_t lenMB;
- const wchar_t* pFilePathTemp = pFilePath;
- char* pFilePathMB = NULL;
- char pOpenModeMB[32] = {0};
- DRWAV_ZERO_OBJECT(&mbs);
- lenMB = wcsrtombs(NULL, &pFilePathTemp, 0, &mbs);
- if (lenMB == (size_t)-1) {
- return drwav_result_from_errno(errno);
- }
- pFilePathMB = (char*)drwav__malloc_from_callbacks(lenMB + 1, pAllocationCallbacks);
- if (pFilePathMB == NULL) {
- return DRWAV_OUT_OF_MEMORY;
- }
- pFilePathTemp = pFilePath;
- DRWAV_ZERO_OBJECT(&mbs);
- wcsrtombs(pFilePathMB, &pFilePathTemp, lenMB + 1, &mbs);
- {
- size_t i = 0;
- for (;;) {
- if (pOpenMode[i] == 0) {
- pOpenModeMB[i] = '\0';
- break;
- }
- pOpenModeMB[i] = (char)pOpenMode[i];
- i += 1;
- }
- }
- *ppFile = fopen(pFilePathMB, pOpenModeMB);
- drwav__free_from_callbacks(pFilePathMB, pAllocationCallbacks);
- }
- #endif
- if (*ppFile == NULL) {
- return DRWAV_ERROR;
- }
-#endif
- return DRWAV_SUCCESS;
-}
-#endif
-DRWAV_PRIVATE size_t drwav__on_read_stdio(void* pUserData, void* pBufferOut, size_t bytesToRead)
+#ifndef MA_DR_WAV_NO_STDIO
+MA_PRIVATE size_t ma_dr_wav__on_read_stdio(void* pUserData, void* pBufferOut, size_t bytesToRead)
{
return fread(pBufferOut, 1, bytesToRead, (FILE*)pUserData);
}
-DRWAV_PRIVATE size_t drwav__on_write_stdio(void* pUserData, const void* pData, size_t bytesToWrite)
+MA_PRIVATE size_t ma_dr_wav__on_write_stdio(void* pUserData, const void* pData, size_t bytesToWrite)
{
return fwrite(pData, 1, bytesToWrite, (FILE*)pUserData);
}
-DRWAV_PRIVATE drwav_bool32 drwav__on_seek_stdio(void* pUserData, int offset, drwav_seek_origin origin)
+MA_PRIVATE ma_bool32 ma_dr_wav__on_seek_stdio(void* pUserData, int offset, ma_dr_wav_seek_origin origin)
{
- return fseek((FILE*)pUserData, offset, (origin == drwav_seek_origin_current) ? SEEK_CUR : SEEK_SET) == 0;
+ return fseek((FILE*)pUserData, offset, (origin == ma_dr_wav_seek_origin_current) ? SEEK_CUR : SEEK_SET) == 0;
}
-DRWAV_API drwav_bool32 drwav_init_file(drwav* pWav, const char* filename, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_bool32 ma_dr_wav_init_file(ma_dr_wav* pWav, const char* filename, const ma_allocation_callbacks* pAllocationCallbacks)
{
- return drwav_init_file_ex(pWav, filename, NULL, NULL, 0, pAllocationCallbacks);
+ return ma_dr_wav_init_file_ex(pWav, filename, NULL, NULL, 0, pAllocationCallbacks);
}
-DRWAV_PRIVATE drwav_bool32 drwav_init_file__internal_FILE(drwav* pWav, FILE* pFile, drwav_chunk_proc onChunk, void* pChunkUserData, drwav_uint32 flags, drwav_metadata_type allowedMetadataTypes, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_PRIVATE ma_bool32 ma_dr_wav_init_file__internal_FILE(ma_dr_wav* pWav, FILE* pFile, ma_dr_wav_chunk_proc onChunk, void* pChunkUserData, ma_uint32 flags, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drwav_bool32 result;
- result = drwav_preinit(pWav, drwav__on_read_stdio, drwav__on_seek_stdio, (void*)pFile, pAllocationCallbacks);
- if (result != DRWAV_TRUE) {
+ ma_bool32 result;
+ result = ma_dr_wav_preinit(pWav, ma_dr_wav__on_read_stdio, ma_dr_wav__on_seek_stdio, (void*)pFile, pAllocationCallbacks);
+ if (result != MA_TRUE) {
fclose(pFile);
return result;
}
- pWav->allowedMetadataTypes = allowedMetadataTypes;
- result = drwav_init__internal(pWav, onChunk, pChunkUserData, flags);
- if (result != DRWAV_TRUE) {
+ result = ma_dr_wav_init__internal(pWav, onChunk, pChunkUserData, flags);
+ if (result != MA_TRUE) {
fclose(pFile);
return result;
}
- return DRWAV_TRUE;
+ return MA_TRUE;
}
-DRWAV_API drwav_bool32 drwav_init_file_ex(drwav* pWav, const char* filename, drwav_chunk_proc onChunk, void* pChunkUserData, drwav_uint32 flags, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_bool32 ma_dr_wav_init_file_ex(ma_dr_wav* pWav, const char* filename, ma_dr_wav_chunk_proc onChunk, void* pChunkUserData, ma_uint32 flags, const ma_allocation_callbacks* pAllocationCallbacks)
{
FILE* pFile;
- if (drwav_fopen(&pFile, filename, "rb") != DRWAV_SUCCESS) {
- return DRWAV_FALSE;
+ if (ma_fopen(&pFile, filename, "rb") != MA_SUCCESS) {
+ return MA_FALSE;
}
- return drwav_init_file__internal_FILE(pWav, pFile, onChunk, pChunkUserData, flags, drwav_metadata_type_none, pAllocationCallbacks);
+ return ma_dr_wav_init_file__internal_FILE(pWav, pFile, onChunk, pChunkUserData, flags, pAllocationCallbacks);
}
-#ifndef DR_WAV_NO_WCHAR
-DRWAV_API drwav_bool32 drwav_init_file_w(drwav* pWav, const wchar_t* filename, const drwav_allocation_callbacks* pAllocationCallbacks)
+#ifndef MA_DR_WAV_NO_WCHAR
+MA_API ma_bool32 ma_dr_wav_init_file_w(ma_dr_wav* pWav, const wchar_t* filename, const ma_allocation_callbacks* pAllocationCallbacks)
{
- return drwav_init_file_ex_w(pWav, filename, NULL, NULL, 0, pAllocationCallbacks);
+ return ma_dr_wav_init_file_ex_w(pWav, filename, NULL, NULL, 0, pAllocationCallbacks);
}
-DRWAV_API drwav_bool32 drwav_init_file_ex_w(drwav* pWav, const wchar_t* filename, drwav_chunk_proc onChunk, void* pChunkUserData, drwav_uint32 flags, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_bool32 ma_dr_wav_init_file_ex_w(ma_dr_wav* pWav, const wchar_t* filename, ma_dr_wav_chunk_proc onChunk, void* pChunkUserData, ma_uint32 flags, const ma_allocation_callbacks* pAllocationCallbacks)
{
FILE* pFile;
- if (drwav_wfopen(&pFile, filename, L"rb", pAllocationCallbacks) != DRWAV_SUCCESS) {
- return DRWAV_FALSE;
+ if (ma_wfopen(&pFile, filename, L"rb", pAllocationCallbacks) != MA_SUCCESS) {
+ return MA_FALSE;
}
- return drwav_init_file__internal_FILE(pWav, pFile, onChunk, pChunkUserData, flags, drwav_metadata_type_none, pAllocationCallbacks);
+ return ma_dr_wav_init_file__internal_FILE(pWav, pFile, onChunk, pChunkUserData, flags, pAllocationCallbacks);
}
#endif
-DRWAV_API drwav_bool32 drwav_init_file_with_metadata(drwav* pWav, const char* filename, drwav_uint32 flags, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_bool32 ma_dr_wav_init_file_with_metadata(ma_dr_wav* pWav, const char* filename, ma_uint32 flags, const ma_allocation_callbacks* pAllocationCallbacks)
{
FILE* pFile;
- if (drwav_fopen(&pFile, filename, "rb") != DRWAV_SUCCESS) {
- return DRWAV_FALSE;
+ if (ma_fopen(&pFile, filename, "rb") != MA_SUCCESS) {
+ return MA_FALSE;
}
- return drwav_init_file__internal_FILE(pWav, pFile, NULL, NULL, flags, drwav_metadata_type_all_including_unknown, pAllocationCallbacks);
+ return ma_dr_wav_init_file__internal_FILE(pWav, pFile, NULL, NULL, flags | MA_DR_WAV_WITH_METADATA, pAllocationCallbacks);
}
-#ifndef DR_WAV_NO_WCHAR
-DRWAV_API drwav_bool32 drwav_init_file_with_metadata_w(drwav* pWav, const wchar_t* filename, drwav_uint32 flags, const drwav_allocation_callbacks* pAllocationCallbacks)
+#ifndef MA_DR_WAV_NO_WCHAR
+MA_API ma_bool32 ma_dr_wav_init_file_with_metadata_w(ma_dr_wav* pWav, const wchar_t* filename, ma_uint32 flags, const ma_allocation_callbacks* pAllocationCallbacks)
{
FILE* pFile;
- if (drwav_wfopen(&pFile, filename, L"rb", pAllocationCallbacks) != DRWAV_SUCCESS) {
- return DRWAV_FALSE;
+ if (ma_wfopen(&pFile, filename, L"rb", pAllocationCallbacks) != MA_SUCCESS) {
+ return MA_FALSE;
}
- return drwav_init_file__internal_FILE(pWav, pFile, NULL, NULL, flags, drwav_metadata_type_all_including_unknown, pAllocationCallbacks);
+ return ma_dr_wav_init_file__internal_FILE(pWav, pFile, NULL, NULL, flags | MA_DR_WAV_WITH_METADATA, pAllocationCallbacks);
}
#endif
-DRWAV_PRIVATE drwav_bool32 drwav_init_file_write__internal_FILE(drwav* pWav, FILE* pFile, const drwav_data_format* pFormat, drwav_uint64 totalSampleCount, drwav_bool32 isSequential, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_PRIVATE ma_bool32 ma_dr_wav_init_file_write__internal_FILE(ma_dr_wav* pWav, FILE* pFile, const ma_dr_wav_data_format* pFormat, ma_uint64 totalSampleCount, ma_bool32 isSequential, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drwav_bool32 result;
- result = drwav_preinit_write(pWav, pFormat, isSequential, drwav__on_write_stdio, drwav__on_seek_stdio, (void*)pFile, pAllocationCallbacks);
- if (result != DRWAV_TRUE) {
+ ma_bool32 result;
+ result = ma_dr_wav_preinit_write(pWav, pFormat, isSequential, ma_dr_wav__on_write_stdio, ma_dr_wav__on_seek_stdio, (void*)pFile, pAllocationCallbacks);
+ if (result != MA_TRUE) {
fclose(pFile);
return result;
}
- result = drwav_init_write__internal(pWav, pFormat, totalSampleCount);
- if (result != DRWAV_TRUE) {
+ result = ma_dr_wav_init_write__internal(pWav, pFormat, totalSampleCount);
+ if (result != MA_TRUE) {
fclose(pFile);
return result;
}
- return DRWAV_TRUE;
+ return MA_TRUE;
}
-DRWAV_PRIVATE drwav_bool32 drwav_init_file_write__internal(drwav* pWav, const char* filename, const drwav_data_format* pFormat, drwav_uint64 totalSampleCount, drwav_bool32 isSequential, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_PRIVATE ma_bool32 ma_dr_wav_init_file_write__internal(ma_dr_wav* pWav, const char* filename, const ma_dr_wav_data_format* pFormat, ma_uint64 totalSampleCount, ma_bool32 isSequential, const ma_allocation_callbacks* pAllocationCallbacks)
{
FILE* pFile;
- if (drwav_fopen(&pFile, filename, "wb") != DRWAV_SUCCESS) {
- return DRWAV_FALSE;
+ if (ma_fopen(&pFile, filename, "wb") != MA_SUCCESS) {
+ return MA_FALSE;
}
- return drwav_init_file_write__internal_FILE(pWav, pFile, pFormat, totalSampleCount, isSequential, pAllocationCallbacks);
+ return ma_dr_wav_init_file_write__internal_FILE(pWav, pFile, pFormat, totalSampleCount, isSequential, pAllocationCallbacks);
}
-#ifndef DR_WAV_NO_WCHAR
-DRWAV_PRIVATE drwav_bool32 drwav_init_file_write_w__internal(drwav* pWav, const wchar_t* filename, const drwav_data_format* pFormat, drwav_uint64 totalSampleCount, drwav_bool32 isSequential, const drwav_allocation_callbacks* pAllocationCallbacks)
+#ifndef MA_DR_WAV_NO_WCHAR
+MA_PRIVATE ma_bool32 ma_dr_wav_init_file_write_w__internal(ma_dr_wav* pWav, const wchar_t* filename, const ma_dr_wav_data_format* pFormat, ma_uint64 totalSampleCount, ma_bool32 isSequential, const ma_allocation_callbacks* pAllocationCallbacks)
{
FILE* pFile;
- if (drwav_wfopen(&pFile, filename, L"wb", pAllocationCallbacks) != DRWAV_SUCCESS) {
- return DRWAV_FALSE;
+ if (ma_wfopen(&pFile, filename, L"wb", pAllocationCallbacks) != MA_SUCCESS) {
+ return MA_FALSE;
}
- return drwav_init_file_write__internal_FILE(pWav, pFile, pFormat, totalSampleCount, isSequential, pAllocationCallbacks);
+ return ma_dr_wav_init_file_write__internal_FILE(pWav, pFile, pFormat, totalSampleCount, isSequential, pAllocationCallbacks);
}
#endif
-DRWAV_API drwav_bool32 drwav_init_file_write(drwav* pWav, const char* filename, const drwav_data_format* pFormat, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_bool32 ma_dr_wav_init_file_write(ma_dr_wav* pWav, const char* filename, const ma_dr_wav_data_format* pFormat, const ma_allocation_callbacks* pAllocationCallbacks)
{
- return drwav_init_file_write__internal(pWav, filename, pFormat, 0, DRWAV_FALSE, pAllocationCallbacks);
+ return ma_dr_wav_init_file_write__internal(pWav, filename, pFormat, 0, MA_FALSE, pAllocationCallbacks);
}
-DRWAV_API drwav_bool32 drwav_init_file_write_sequential(drwav* pWav, const char* filename, const drwav_data_format* pFormat, drwav_uint64 totalSampleCount, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_bool32 ma_dr_wav_init_file_write_sequential(ma_dr_wav* pWav, const char* filename, const ma_dr_wav_data_format* pFormat, ma_uint64 totalSampleCount, const ma_allocation_callbacks* pAllocationCallbacks)
{
- return drwav_init_file_write__internal(pWav, filename, pFormat, totalSampleCount, DRWAV_TRUE, pAllocationCallbacks);
+ return ma_dr_wav_init_file_write__internal(pWav, filename, pFormat, totalSampleCount, MA_TRUE, pAllocationCallbacks);
}
-DRWAV_API drwav_bool32 drwav_init_file_write_sequential_pcm_frames(drwav* pWav, const char* filename, const drwav_data_format* pFormat, drwav_uint64 totalPCMFrameCount, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_bool32 ma_dr_wav_init_file_write_sequential_pcm_frames(ma_dr_wav* pWav, const char* filename, const ma_dr_wav_data_format* pFormat, ma_uint64 totalPCMFrameCount, const ma_allocation_callbacks* pAllocationCallbacks)
{
if (pFormat == NULL) {
- return DRWAV_FALSE;
+ return MA_FALSE;
}
- return drwav_init_file_write_sequential(pWav, filename, pFormat, totalPCMFrameCount*pFormat->channels, pAllocationCallbacks);
+ return ma_dr_wav_init_file_write_sequential(pWav, filename, pFormat, totalPCMFrameCount*pFormat->channels, pAllocationCallbacks);
}
-#ifndef DR_WAV_NO_WCHAR
-DRWAV_API drwav_bool32 drwav_init_file_write_w(drwav* pWav, const wchar_t* filename, const drwav_data_format* pFormat, const drwav_allocation_callbacks* pAllocationCallbacks)
+#ifndef MA_DR_WAV_NO_WCHAR
+MA_API ma_bool32 ma_dr_wav_init_file_write_w(ma_dr_wav* pWav, const wchar_t* filename, const ma_dr_wav_data_format* pFormat, const ma_allocation_callbacks* pAllocationCallbacks)
{
- return drwav_init_file_write_w__internal(pWav, filename, pFormat, 0, DRWAV_FALSE, pAllocationCallbacks);
+ return ma_dr_wav_init_file_write_w__internal(pWav, filename, pFormat, 0, MA_FALSE, pAllocationCallbacks);
}
-DRWAV_API drwav_bool32 drwav_init_file_write_sequential_w(drwav* pWav, const wchar_t* filename, const drwav_data_format* pFormat, drwav_uint64 totalSampleCount, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_bool32 ma_dr_wav_init_file_write_sequential_w(ma_dr_wav* pWav, const wchar_t* filename, const ma_dr_wav_data_format* pFormat, ma_uint64 totalSampleCount, const ma_allocation_callbacks* pAllocationCallbacks)
{
- return drwav_init_file_write_w__internal(pWav, filename, pFormat, totalSampleCount, DRWAV_TRUE, pAllocationCallbacks);
+ return ma_dr_wav_init_file_write_w__internal(pWav, filename, pFormat, totalSampleCount, MA_TRUE, pAllocationCallbacks);
}
-DRWAV_API drwav_bool32 drwav_init_file_write_sequential_pcm_frames_w(drwav* pWav, const wchar_t* filename, const drwav_data_format* pFormat, drwav_uint64 totalPCMFrameCount, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_bool32 ma_dr_wav_init_file_write_sequential_pcm_frames_w(ma_dr_wav* pWav, const wchar_t* filename, const ma_dr_wav_data_format* pFormat, ma_uint64 totalPCMFrameCount, const ma_allocation_callbacks* pAllocationCallbacks)
{
if (pFormat == NULL) {
- return DRWAV_FALSE;
+ return MA_FALSE;
}
- return drwav_init_file_write_sequential_w(pWav, filename, pFormat, totalPCMFrameCount*pFormat->channels, pAllocationCallbacks);
+ return ma_dr_wav_init_file_write_sequential_w(pWav, filename, pFormat, totalPCMFrameCount*pFormat->channels, pAllocationCallbacks);
}
#endif
#endif
-DRWAV_PRIVATE size_t drwav__on_read_memory(void* pUserData, void* pBufferOut, size_t bytesToRead)
+MA_PRIVATE size_t ma_dr_wav__on_read_memory(void* pUserData, void* pBufferOut, size_t bytesToRead)
{
- drwav* pWav = (drwav*)pUserData;
+ ma_dr_wav* pWav = (ma_dr_wav*)pUserData;
size_t bytesRemaining;
- DRWAV_ASSERT(pWav != NULL);
- DRWAV_ASSERT(pWav->memoryStream.dataSize >= pWav->memoryStream.currentReadPos);
+ MA_DR_WAV_ASSERT(pWav != NULL);
+ MA_DR_WAV_ASSERT(pWav->memoryStream.dataSize >= pWav->memoryStream.currentReadPos);
bytesRemaining = pWav->memoryStream.dataSize - pWav->memoryStream.currentReadPos;
if (bytesToRead > bytesRemaining) {
bytesToRead = bytesRemaining;
}
if (bytesToRead > 0) {
- DRWAV_COPY_MEMORY(pBufferOut, pWav->memoryStream.data + pWav->memoryStream.currentReadPos, bytesToRead);
+ MA_DR_WAV_COPY_MEMORY(pBufferOut, pWav->memoryStream.data + pWav->memoryStream.currentReadPos, bytesToRead);
pWav->memoryStream.currentReadPos += bytesToRead;
}
return bytesToRead;
}
-DRWAV_PRIVATE drwav_bool32 drwav__on_seek_memory(void* pUserData, int offset, drwav_seek_origin origin)
+MA_PRIVATE ma_bool32 ma_dr_wav__on_seek_memory(void* pUserData, int offset, ma_dr_wav_seek_origin origin)
{
- drwav* pWav = (drwav*)pUserData;
- DRWAV_ASSERT(pWav != NULL);
- if (origin == drwav_seek_origin_current) {
+ ma_dr_wav* pWav = (ma_dr_wav*)pUserData;
+ MA_DR_WAV_ASSERT(pWav != NULL);
+ if (origin == ma_dr_wav_seek_origin_current) {
if (offset > 0) {
if (pWav->memoryStream.currentReadPos + offset > pWav->memoryStream.dataSize) {
- return DRWAV_FALSE;
+ return MA_FALSE;
}
} else {
if (pWav->memoryStream.currentReadPos < (size_t)-offset) {
- return DRWAV_FALSE;
+ return MA_FALSE;
}
}
pWav->memoryStream.currentReadPos += offset;
} else {
- if ((drwav_uint32)offset <= pWav->memoryStream.dataSize) {
+ if ((ma_uint32)offset <= pWav->memoryStream.dataSize) {
pWav->memoryStream.currentReadPos = offset;
} else {
- return DRWAV_FALSE;
+ return MA_FALSE;
}
}
- return DRWAV_TRUE;
+ return MA_TRUE;
}
-DRWAV_PRIVATE size_t drwav__on_write_memory(void* pUserData, const void* pDataIn, size_t bytesToWrite)
+MA_PRIVATE size_t ma_dr_wav__on_write_memory(void* pUserData, const void* pDataIn, size_t bytesToWrite)
{
- drwav* pWav = (drwav*)pUserData;
+ ma_dr_wav* pWav = (ma_dr_wav*)pUserData;
size_t bytesRemaining;
- DRWAV_ASSERT(pWav != NULL);
- DRWAV_ASSERT(pWav->memoryStreamWrite.dataCapacity >= pWav->memoryStreamWrite.currentWritePos);
+ MA_DR_WAV_ASSERT(pWav != NULL);
+ MA_DR_WAV_ASSERT(pWav->memoryStreamWrite.dataCapacity >= pWav->memoryStreamWrite.currentWritePos);
bytesRemaining = pWav->memoryStreamWrite.dataCapacity - pWav->memoryStreamWrite.currentWritePos;
if (bytesRemaining < bytesToWrite) {
void* pNewData;
@@ -77407,14 +79836,14 @@ DRWAV_PRIVATE size_t drwav__on_write_memory(void* pUserData, const void* pDataIn
if ((newDataCapacity - pWav->memoryStreamWrite.currentWritePos) < bytesToWrite) {
newDataCapacity = pWav->memoryStreamWrite.currentWritePos + bytesToWrite;
}
- pNewData = drwav__realloc_from_callbacks(*pWav->memoryStreamWrite.ppData, newDataCapacity, pWav->memoryStreamWrite.dataCapacity, &pWav->allocationCallbacks);
+ pNewData = ma_dr_wav__realloc_from_callbacks(*pWav->memoryStreamWrite.ppData, newDataCapacity, pWav->memoryStreamWrite.dataCapacity, &pWav->allocationCallbacks);
if (pNewData == NULL) {
return 0;
}
*pWav->memoryStreamWrite.ppData = pNewData;
pWav->memoryStreamWrite.dataCapacity = newDataCapacity;
}
- DRWAV_COPY_MEMORY(((drwav_uint8*)(*pWav->memoryStreamWrite.ppData)) + pWav->memoryStreamWrite.currentWritePos, pDataIn, bytesToWrite);
+ MA_DR_WAV_COPY_MEMORY(((ma_uint8*)(*pWav->memoryStreamWrite.ppData)) + pWav->memoryStreamWrite.currentWritePos, pDataIn, bytesToWrite);
pWav->memoryStreamWrite.currentWritePos += bytesToWrite;
if (pWav->memoryStreamWrite.dataSize < pWav->memoryStreamWrite.currentWritePos) {
pWav->memoryStreamWrite.dataSize = pWav->memoryStreamWrite.currentWritePos;
@@ -77422,11 +79851,11 @@ DRWAV_PRIVATE size_t drwav__on_write_memory(void* pUserData, const void* pDataIn
*pWav->memoryStreamWrite.pDataSize = pWav->memoryStreamWrite.dataSize;
return bytesToWrite;
}
-DRWAV_PRIVATE drwav_bool32 drwav__on_seek_memory_write(void* pUserData, int offset, drwav_seek_origin origin)
+MA_PRIVATE ma_bool32 ma_dr_wav__on_seek_memory_write(void* pUserData, int offset, ma_dr_wav_seek_origin origin)
{
- drwav* pWav = (drwav*)pUserData;
- DRWAV_ASSERT(pWav != NULL);
- if (origin == drwav_seek_origin_current) {
+ ma_dr_wav* pWav = (ma_dr_wav*)pUserData;
+ MA_DR_WAV_ASSERT(pWav != NULL);
+ if (origin == ma_dr_wav_seek_origin_current) {
if (offset > 0) {
if (pWav->memoryStreamWrite.currentWritePos + offset > pWav->memoryStreamWrite.dataSize) {
offset = (int)(pWav->memoryStreamWrite.dataSize - pWav->memoryStreamWrite.currentWritePos);
@@ -77438,146 +79867,143 @@ DRWAV_PRIVATE drwav_bool32 drwav__on_seek_memory_write(void* pUserData, int offs
}
pWav->memoryStreamWrite.currentWritePos += offset;
} else {
- if ((drwav_uint32)offset <= pWav->memoryStreamWrite.dataSize) {
+ if ((ma_uint32)offset <= pWav->memoryStreamWrite.dataSize) {
pWav->memoryStreamWrite.currentWritePos = offset;
} else {
pWav->memoryStreamWrite.currentWritePos = pWav->memoryStreamWrite.dataSize;
}
}
- return DRWAV_TRUE;
+ return MA_TRUE;
}
-DRWAV_API drwav_bool32 drwav_init_memory(drwav* pWav, const void* data, size_t dataSize, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_bool32 ma_dr_wav_init_memory(ma_dr_wav* pWav, const void* data, size_t dataSize, const ma_allocation_callbacks* pAllocationCallbacks)
{
- return drwav_init_memory_ex(pWav, data, dataSize, NULL, NULL, 0, pAllocationCallbacks);
+ return ma_dr_wav_init_memory_ex(pWav, data, dataSize, NULL, NULL, 0, pAllocationCallbacks);
}
-DRWAV_API drwav_bool32 drwav_init_memory_ex(drwav* pWav, const void* data, size_t dataSize, drwav_chunk_proc onChunk, void* pChunkUserData, drwav_uint32 flags, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_bool32 ma_dr_wav_init_memory_ex(ma_dr_wav* pWav, const void* data, size_t dataSize, ma_dr_wav_chunk_proc onChunk, void* pChunkUserData, ma_uint32 flags, const ma_allocation_callbacks* pAllocationCallbacks)
{
if (data == NULL || dataSize == 0) {
- return DRWAV_FALSE;
+ return MA_FALSE;
}
- if (!drwav_preinit(pWav, drwav__on_read_memory, drwav__on_seek_memory, pWav, pAllocationCallbacks)) {
- return DRWAV_FALSE;
+ if (!ma_dr_wav_preinit(pWav, ma_dr_wav__on_read_memory, ma_dr_wav__on_seek_memory, pWav, pAllocationCallbacks)) {
+ return MA_FALSE;
}
- pWav->memoryStream.data = (const drwav_uint8*)data;
+ pWav->memoryStream.data = (const ma_uint8*)data;
pWav->memoryStream.dataSize = dataSize;
pWav->memoryStream.currentReadPos = 0;
- return drwav_init__internal(pWav, onChunk, pChunkUserData, flags);
+ return ma_dr_wav_init__internal(pWav, onChunk, pChunkUserData, flags);
}
-DRWAV_API drwav_bool32 drwav_init_memory_with_metadata(drwav* pWav, const void* data, size_t dataSize, drwav_uint32 flags, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_bool32 ma_dr_wav_init_memory_with_metadata(ma_dr_wav* pWav, const void* data, size_t dataSize, ma_uint32 flags, const ma_allocation_callbacks* pAllocationCallbacks)
{
if (data == NULL || dataSize == 0) {
- return DRWAV_FALSE;
+ return MA_FALSE;
}
- if (!drwav_preinit(pWav, drwav__on_read_memory, drwav__on_seek_memory, pWav, pAllocationCallbacks)) {
- return DRWAV_FALSE;
+ if (!ma_dr_wav_preinit(pWav, ma_dr_wav__on_read_memory, ma_dr_wav__on_seek_memory, pWav, pAllocationCallbacks)) {
+ return MA_FALSE;
}
- pWav->memoryStream.data = (const drwav_uint8*)data;
+ pWav->memoryStream.data = (const ma_uint8*)data;
pWav->memoryStream.dataSize = dataSize;
pWav->memoryStream.currentReadPos = 0;
- pWav->allowedMetadataTypes = drwav_metadata_type_all_including_unknown;
- return drwav_init__internal(pWav, NULL, NULL, flags);
+ return ma_dr_wav_init__internal(pWav, NULL, NULL, flags | MA_DR_WAV_WITH_METADATA);
}
-DRWAV_PRIVATE drwav_bool32 drwav_init_memory_write__internal(drwav* pWav, void** ppData, size_t* pDataSize, const drwav_data_format* pFormat, drwav_uint64 totalSampleCount, drwav_bool32 isSequential, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_PRIVATE ma_bool32 ma_dr_wav_init_memory_write__internal(ma_dr_wav* pWav, void** ppData, size_t* pDataSize, const ma_dr_wav_data_format* pFormat, ma_uint64 totalSampleCount, ma_bool32 isSequential, const ma_allocation_callbacks* pAllocationCallbacks)
{
if (ppData == NULL || pDataSize == NULL) {
- return DRWAV_FALSE;
+ return MA_FALSE;
}
*ppData = NULL;
*pDataSize = 0;
- if (!drwav_preinit_write(pWav, pFormat, isSequential, drwav__on_write_memory, drwav__on_seek_memory_write, pWav, pAllocationCallbacks)) {
- return DRWAV_FALSE;
+ if (!ma_dr_wav_preinit_write(pWav, pFormat, isSequential, ma_dr_wav__on_write_memory, ma_dr_wav__on_seek_memory_write, pWav, pAllocationCallbacks)) {
+ return MA_FALSE;
}
pWav->memoryStreamWrite.ppData = ppData;
pWav->memoryStreamWrite.pDataSize = pDataSize;
pWav->memoryStreamWrite.dataSize = 0;
pWav->memoryStreamWrite.dataCapacity = 0;
pWav->memoryStreamWrite.currentWritePos = 0;
- return drwav_init_write__internal(pWav, pFormat, totalSampleCount);
+ return ma_dr_wav_init_write__internal(pWav, pFormat, totalSampleCount);
}
-DRWAV_API drwav_bool32 drwav_init_memory_write(drwav* pWav, void** ppData, size_t* pDataSize, const drwav_data_format* pFormat, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_bool32 ma_dr_wav_init_memory_write(ma_dr_wav* pWav, void** ppData, size_t* pDataSize, const ma_dr_wav_data_format* pFormat, const ma_allocation_callbacks* pAllocationCallbacks)
{
- return drwav_init_memory_write__internal(pWav, ppData, pDataSize, pFormat, 0, DRWAV_FALSE, pAllocationCallbacks);
+ return ma_dr_wav_init_memory_write__internal(pWav, ppData, pDataSize, pFormat, 0, MA_FALSE, pAllocationCallbacks);
}
-DRWAV_API drwav_bool32 drwav_init_memory_write_sequential(drwav* pWav, void** ppData, size_t* pDataSize, const drwav_data_format* pFormat, drwav_uint64 totalSampleCount, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_bool32 ma_dr_wav_init_memory_write_sequential(ma_dr_wav* pWav, void** ppData, size_t* pDataSize, const ma_dr_wav_data_format* pFormat, ma_uint64 totalSampleCount, const ma_allocation_callbacks* pAllocationCallbacks)
{
- return drwav_init_memory_write__internal(pWav, ppData, pDataSize, pFormat, totalSampleCount, DRWAV_TRUE, pAllocationCallbacks);
+ return ma_dr_wav_init_memory_write__internal(pWav, ppData, pDataSize, pFormat, totalSampleCount, MA_TRUE, pAllocationCallbacks);
}
-DRWAV_API drwav_bool32 drwav_init_memory_write_sequential_pcm_frames(drwav* pWav, void** ppData, size_t* pDataSize, const drwav_data_format* pFormat, drwav_uint64 totalPCMFrameCount, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_bool32 ma_dr_wav_init_memory_write_sequential_pcm_frames(ma_dr_wav* pWav, void** ppData, size_t* pDataSize, const ma_dr_wav_data_format* pFormat, ma_uint64 totalPCMFrameCount, const ma_allocation_callbacks* pAllocationCallbacks)
{
if (pFormat == NULL) {
- return DRWAV_FALSE;
+ return MA_FALSE;
}
- return drwav_init_memory_write_sequential(pWav, ppData, pDataSize, pFormat, totalPCMFrameCount*pFormat->channels, pAllocationCallbacks);
+ return ma_dr_wav_init_memory_write_sequential(pWav, ppData, pDataSize, pFormat, totalPCMFrameCount*pFormat->channels, pAllocationCallbacks);
}
-DRWAV_API drwav_result drwav_uninit(drwav* pWav)
+MA_API ma_result ma_dr_wav_uninit(ma_dr_wav* pWav)
{
- drwav_result result = DRWAV_SUCCESS;
+ ma_result result = MA_SUCCESS;
if (pWav == NULL) {
- return DRWAV_INVALID_ARGS;
+ return MA_INVALID_ARGS;
}
if (pWav->onWrite != NULL) {
- drwav_uint32 paddingSize = 0;
- if (pWav->container == drwav_container_riff || pWav->container == drwav_container_rf64) {
- paddingSize = drwav__chunk_padding_size_riff(pWav->dataChunkDataSize);
+ ma_uint32 paddingSize = 0;
+ if (pWav->container == ma_dr_wav_container_riff || pWav->container == ma_dr_wav_container_rf64) {
+ paddingSize = ma_dr_wav__chunk_padding_size_riff(pWav->dataChunkDataSize);
} else {
- paddingSize = drwav__chunk_padding_size_w64(pWav->dataChunkDataSize);
+ paddingSize = ma_dr_wav__chunk_padding_size_w64(pWav->dataChunkDataSize);
}
if (paddingSize > 0) {
- drwav_uint64 paddingData = 0;
- drwav__write(pWav, &paddingData, paddingSize);
+ ma_uint64 paddingData = 0;
+ ma_dr_wav__write(pWav, &paddingData, paddingSize);
}
if (pWav->onSeek && !pWav->isSequentialWrite) {
- if (pWav->container == drwav_container_riff) {
- if (pWav->onSeek(pWav->pUserData, 4, drwav_seek_origin_start)) {
- drwav_uint32 riffChunkSize = drwav__riff_chunk_size_riff(pWav->dataChunkDataSize, pWav->pMetadata, pWav->metadataCount);
- drwav__write_u32ne_to_le(pWav, riffChunkSize);
+ if (pWav->container == ma_dr_wav_container_riff) {
+ if (pWav->onSeek(pWav->pUserData, 4, ma_dr_wav_seek_origin_start)) {
+ ma_uint32 riffChunkSize = ma_dr_wav__riff_chunk_size_riff(pWav->dataChunkDataSize, pWav->pMetadata, pWav->metadataCount);
+ ma_dr_wav__write_u32ne_to_le(pWav, riffChunkSize);
}
- if (pWav->onSeek(pWav->pUserData, (int)pWav->dataChunkDataPos - 4, drwav_seek_origin_start)) {
- drwav_uint32 dataChunkSize = drwav__data_chunk_size_riff(pWav->dataChunkDataSize);
- drwav__write_u32ne_to_le(pWav, dataChunkSize);
+ if (pWav->onSeek(pWav->pUserData, (int)pWav->dataChunkDataPos - 4, ma_dr_wav_seek_origin_start)) {
+ ma_uint32 dataChunkSize = ma_dr_wav__data_chunk_size_riff(pWav->dataChunkDataSize);
+ ma_dr_wav__write_u32ne_to_le(pWav, dataChunkSize);
}
- } else if (pWav->container == drwav_container_w64) {
- if (pWav->onSeek(pWav->pUserData, 16, drwav_seek_origin_start)) {
- drwav_uint64 riffChunkSize = drwav__riff_chunk_size_w64(pWav->dataChunkDataSize);
- drwav__write_u64ne_to_le(pWav, riffChunkSize);
+ } else if (pWav->container == ma_dr_wav_container_w64) {
+ if (pWav->onSeek(pWav->pUserData, 16, ma_dr_wav_seek_origin_start)) {
+ ma_uint64 riffChunkSize = ma_dr_wav__riff_chunk_size_w64(pWav->dataChunkDataSize);
+ ma_dr_wav__write_u64ne_to_le(pWav, riffChunkSize);
}
- if (pWav->onSeek(pWav->pUserData, (int)pWav->dataChunkDataPos - 8, drwav_seek_origin_start)) {
- drwav_uint64 dataChunkSize = drwav__data_chunk_size_w64(pWav->dataChunkDataSize);
- drwav__write_u64ne_to_le(pWav, dataChunkSize);
+ if (pWav->onSeek(pWav->pUserData, (int)pWav->dataChunkDataPos - 8, ma_dr_wav_seek_origin_start)) {
+ ma_uint64 dataChunkSize = ma_dr_wav__data_chunk_size_w64(pWav->dataChunkDataSize);
+ ma_dr_wav__write_u64ne_to_le(pWav, dataChunkSize);
}
- } else if (pWav->container == drwav_container_rf64) {
+ } else if (pWav->container == ma_dr_wav_container_rf64) {
int ds64BodyPos = 12 + 8;
- if (pWav->onSeek(pWav->pUserData, ds64BodyPos + 0, drwav_seek_origin_start)) {
- drwav_uint64 riffChunkSize = drwav__riff_chunk_size_rf64(pWav->dataChunkDataSize, pWav->pMetadata, pWav->metadataCount);
- drwav__write_u64ne_to_le(pWav, riffChunkSize);
+ if (pWav->onSeek(pWav->pUserData, ds64BodyPos + 0, ma_dr_wav_seek_origin_start)) {
+ ma_uint64 riffChunkSize = ma_dr_wav__riff_chunk_size_rf64(pWav->dataChunkDataSize, pWav->pMetadata, pWav->metadataCount);
+ ma_dr_wav__write_u64ne_to_le(pWav, riffChunkSize);
}
- if (pWav->onSeek(pWav->pUserData, ds64BodyPos + 8, drwav_seek_origin_start)) {
- drwav_uint64 dataChunkSize = drwav__data_chunk_size_rf64(pWav->dataChunkDataSize);
- drwav__write_u64ne_to_le(pWav, dataChunkSize);
+ if (pWav->onSeek(pWav->pUserData, ds64BodyPos + 8, ma_dr_wav_seek_origin_start)) {
+ ma_uint64 dataChunkSize = ma_dr_wav__data_chunk_size_rf64(pWav->dataChunkDataSize);
+ ma_dr_wav__write_u64ne_to_le(pWav, dataChunkSize);
}
}
}
if (pWav->isSequentialWrite) {
if (pWav->dataChunkDataSize != pWav->dataChunkDataSizeTargetWrite) {
- result = DRWAV_INVALID_FILE;
+ result = MA_INVALID_FILE;
}
}
} else {
- if (pWav->pMetadata != NULL) {
- pWav->allocationCallbacks.onFree(pWav->pMetadata, pWav->allocationCallbacks.pUserData);
- }
+ ma_dr_wav_free(pWav->pMetadata, &pWav->allocationCallbacks);
}
-#ifndef DR_WAV_NO_STDIO
- if (pWav->onRead == drwav__on_read_stdio || pWav->onWrite == drwav__on_write_stdio) {
+#ifndef MA_DR_WAV_NO_STDIO
+ if (pWav->onRead == ma_dr_wav__on_read_stdio || pWav->onWrite == ma_dr_wav__on_write_stdio) {
fclose((FILE*)pWav->pUserData);
}
#endif
return result;
}
-DRWAV_API size_t drwav_read_raw(drwav* pWav, size_t bytesToRead, void* pBufferOut)
+MA_API size_t ma_dr_wav_read_raw(ma_dr_wav* pWav, size_t bytesToRead, void* pBufferOut)
{
size_t bytesRead;
- drwav_uint32 bytesPerFrame;
+ ma_uint32 bytesPerFrame;
if (pWav == NULL || bytesToRead == 0) {
return 0;
}
@@ -77587,7 +80013,7 @@ DRWAV_API size_t drwav_read_raw(drwav* pWav, size_t bytesToRead, void* pBufferOu
if (bytesToRead == 0) {
return 0;
}
- bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
+ bytesPerFrame = ma_dr_wav_get_bytes_per_pcm_frame(pWav);
if (bytesPerFrame == 0) {
return 0;
}
@@ -77600,13 +80026,13 @@ DRWAV_API size_t drwav_read_raw(drwav* pWav, size_t bytesToRead, void* pBufferOu
if (bytesToSeek > 0x7FFFFFFF) {
bytesToSeek = 0x7FFFFFFF;
}
- if (pWav->onSeek(pWav->pUserData, (int)bytesToSeek, drwav_seek_origin_current) == DRWAV_FALSE) {
+ if (pWav->onSeek(pWav->pUserData, (int)bytesToSeek, ma_dr_wav_seek_origin_current) == MA_FALSE) {
break;
}
bytesRead += bytesToSeek;
}
while (bytesRead < bytesToRead) {
- drwav_uint8 buffer[4096];
+ ma_uint8 buffer[4096];
size_t bytesSeeked;
size_t bytesToSeek = (bytesToRead - bytesRead);
if (bytesToSeek > sizeof(buffer)) {
@@ -77623,171 +80049,198 @@ DRWAV_API size_t drwav_read_raw(drwav* pWav, size_t bytesToRead, void* pBufferOu
pWav->bytesRemaining -= bytesRead;
return bytesRead;
}
-DRWAV_API drwav_uint64 drwav_read_pcm_frames_le(drwav* pWav, drwav_uint64 framesToRead, void* pBufferOut)
+MA_API ma_uint64 ma_dr_wav_read_pcm_frames_le(ma_dr_wav* pWav, ma_uint64 framesToRead, void* pBufferOut)
{
- drwav_uint32 bytesPerFrame;
- drwav_uint64 bytesToRead;
+ ma_uint32 bytesPerFrame;
+ ma_uint64 bytesToRead;
+ ma_uint64 framesRemainingInFile;
if (pWav == NULL || framesToRead == 0) {
return 0;
}
- if (drwav__is_compressed_format_tag(pWav->translatedFormatTag)) {
+ if (ma_dr_wav__is_compressed_format_tag(pWav->translatedFormatTag)) {
return 0;
}
- bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
+ framesRemainingInFile = pWav->totalPCMFrameCount - pWav->readCursorInPCMFrames;
+ if (framesToRead > framesRemainingInFile) {
+ framesToRead = framesRemainingInFile;
+ }
+ bytesPerFrame = ma_dr_wav_get_bytes_per_pcm_frame(pWav);
if (bytesPerFrame == 0) {
return 0;
}
bytesToRead = framesToRead * bytesPerFrame;
- if (bytesToRead > DRWAV_SIZE_MAX) {
- bytesToRead = (DRWAV_SIZE_MAX / bytesPerFrame) * bytesPerFrame;
+ if (bytesToRead > MA_SIZE_MAX) {
+ bytesToRead = (MA_SIZE_MAX / bytesPerFrame) * bytesPerFrame;
}
if (bytesToRead == 0) {
return 0;
}
- return drwav_read_raw(pWav, (size_t)bytesToRead, pBufferOut) / bytesPerFrame;
+ return ma_dr_wav_read_raw(pWav, (size_t)bytesToRead, pBufferOut) / bytesPerFrame;
}
-DRWAV_API drwav_uint64 drwav_read_pcm_frames_be(drwav* pWav, drwav_uint64 framesToRead, void* pBufferOut)
+MA_API ma_uint64 ma_dr_wav_read_pcm_frames_be(ma_dr_wav* pWav, ma_uint64 framesToRead, void* pBufferOut)
{
- drwav_uint64 framesRead = drwav_read_pcm_frames_le(pWav, framesToRead, pBufferOut);
+ ma_uint64 framesRead = ma_dr_wav_read_pcm_frames_le(pWav, framesToRead, pBufferOut);
if (pBufferOut != NULL) {
- drwav_uint32 bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
+ ma_uint32 bytesPerFrame = ma_dr_wav_get_bytes_per_pcm_frame(pWav);
if (bytesPerFrame == 0) {
return 0;
}
- drwav__bswap_samples(pBufferOut, framesRead*pWav->channels, bytesPerFrame/pWav->channels, pWav->translatedFormatTag);
+ ma_dr_wav__bswap_samples(pBufferOut, framesRead*pWav->channels, bytesPerFrame/pWav->channels);
}
return framesRead;
}
-DRWAV_API drwav_uint64 drwav_read_pcm_frames(drwav* pWav, drwav_uint64 framesToRead, void* pBufferOut)
+MA_API ma_uint64 ma_dr_wav_read_pcm_frames(ma_dr_wav* pWav, ma_uint64 framesToRead, void* pBufferOut)
{
- if (drwav__is_little_endian()) {
- return drwav_read_pcm_frames_le(pWav, framesToRead, pBufferOut);
+ ma_uint64 framesRead = 0;
+ if (ma_dr_wav_is_container_be(pWav->container)) {
+ if (pWav->container != ma_dr_wav_container_aiff || pWav->aiff.isLE == MA_FALSE) {
+ if (ma_dr_wav__is_little_endian()) {
+ framesRead = ma_dr_wav_read_pcm_frames_be(pWav, framesToRead, pBufferOut);
+ } else {
+ framesRead = ma_dr_wav_read_pcm_frames_le(pWav, framesToRead, pBufferOut);
+ }
+ goto post_process;
+ }
+ }
+ if (ma_dr_wav__is_little_endian()) {
+ framesRead = ma_dr_wav_read_pcm_frames_le(pWav, framesToRead, pBufferOut);
} else {
- return drwav_read_pcm_frames_be(pWav, framesToRead, pBufferOut);
+ framesRead = ma_dr_wav_read_pcm_frames_be(pWav, framesToRead, pBufferOut);
}
+ post_process:
+ {
+ if (pWav->container == ma_dr_wav_container_aiff && pWav->bitsPerSample == 8 && pWav->aiff.isUnsigned == MA_FALSE) {
+ if (pBufferOut != NULL) {
+ ma_uint64 iSample;
+ for (iSample = 0; iSample < framesRead * pWav->channels; iSample += 1) {
+ ((ma_uint8*)pBufferOut)[iSample] += 128;
+ }
+ }
+ }
+ }
+ return framesRead;
}
-DRWAV_PRIVATE drwav_bool32 drwav_seek_to_first_pcm_frame(drwav* pWav)
+MA_PRIVATE ma_bool32 ma_dr_wav_seek_to_first_pcm_frame(ma_dr_wav* pWav)
{
if (pWav->onWrite != NULL) {
- return DRWAV_FALSE;
+ return MA_FALSE;
}
- if (!pWav->onSeek(pWav->pUserData, (int)pWav->dataChunkDataPos, drwav_seek_origin_start)) {
- return DRWAV_FALSE;
+ if (!pWav->onSeek(pWav->pUserData, (int)pWav->dataChunkDataPos, ma_dr_wav_seek_origin_start)) {
+ return MA_FALSE;
}
- if (drwav__is_compressed_format_tag(pWav->translatedFormatTag)) {
- if (pWav->translatedFormatTag == DR_WAVE_FORMAT_ADPCM) {
- DRWAV_ZERO_OBJECT(&pWav->msadpcm);
- } else if (pWav->translatedFormatTag == DR_WAVE_FORMAT_DVI_ADPCM) {
- DRWAV_ZERO_OBJECT(&pWav->ima);
+ if (ma_dr_wav__is_compressed_format_tag(pWav->translatedFormatTag)) {
+ if (pWav->translatedFormatTag == MA_DR_WAVE_FORMAT_ADPCM) {
+ MA_DR_WAV_ZERO_OBJECT(&pWav->msadpcm);
+ } else if (pWav->translatedFormatTag == MA_DR_WAVE_FORMAT_DVI_ADPCM) {
+ MA_DR_WAV_ZERO_OBJECT(&pWav->ima);
} else {
- DRWAV_ASSERT(DRWAV_FALSE);
+ MA_DR_WAV_ASSERT(MA_FALSE);
}
}
pWav->readCursorInPCMFrames = 0;
pWav->bytesRemaining = pWav->dataChunkDataSize;
- return DRWAV_TRUE;
+ return MA_TRUE;
}
-DRWAV_API drwav_bool32 drwav_seek_to_pcm_frame(drwav* pWav, drwav_uint64 targetFrameIndex)
+MA_API ma_bool32 ma_dr_wav_seek_to_pcm_frame(ma_dr_wav* pWav, ma_uint64 targetFrameIndex)
{
if (pWav == NULL || pWav->onSeek == NULL) {
- return DRWAV_FALSE;
+ return MA_FALSE;
}
if (pWav->onWrite != NULL) {
- return DRWAV_FALSE;
+ return MA_FALSE;
}
if (pWav->totalPCMFrameCount == 0) {
- return DRWAV_TRUE;
+ return MA_TRUE;
}
if (targetFrameIndex > pWav->totalPCMFrameCount) {
targetFrameIndex = pWav->totalPCMFrameCount;
}
- if (drwav__is_compressed_format_tag(pWav->translatedFormatTag)) {
+ if (ma_dr_wav__is_compressed_format_tag(pWav->translatedFormatTag)) {
if (targetFrameIndex < pWav->readCursorInPCMFrames) {
- if (!drwav_seek_to_first_pcm_frame(pWav)) {
- return DRWAV_FALSE;
+ if (!ma_dr_wav_seek_to_first_pcm_frame(pWav)) {
+ return MA_FALSE;
}
}
if (targetFrameIndex > pWav->readCursorInPCMFrames) {
- drwav_uint64 offsetInFrames = targetFrameIndex - pWav->readCursorInPCMFrames;
- drwav_int16 devnull[2048];
+ ma_uint64 offsetInFrames = targetFrameIndex - pWav->readCursorInPCMFrames;
+ ma_int16 devnull[2048];
while (offsetInFrames > 0) {
- drwav_uint64 framesRead = 0;
- drwav_uint64 framesToRead = offsetInFrames;
- if (framesToRead > drwav_countof(devnull)/pWav->channels) {
- framesToRead = drwav_countof(devnull)/pWav->channels;
+ ma_uint64 framesRead = 0;
+ ma_uint64 framesToRead = offsetInFrames;
+ if (framesToRead > ma_dr_wav_countof(devnull)/pWav->channels) {
+ framesToRead = ma_dr_wav_countof(devnull)/pWav->channels;
}
- if (pWav->translatedFormatTag == DR_WAVE_FORMAT_ADPCM) {
- framesRead = drwav_read_pcm_frames_s16__msadpcm(pWav, framesToRead, devnull);
- } else if (pWav->translatedFormatTag == DR_WAVE_FORMAT_DVI_ADPCM) {
- framesRead = drwav_read_pcm_frames_s16__ima(pWav, framesToRead, devnull);
+ if (pWav->translatedFormatTag == MA_DR_WAVE_FORMAT_ADPCM) {
+ framesRead = ma_dr_wav_read_pcm_frames_s16__msadpcm(pWav, framesToRead, devnull);
+ } else if (pWav->translatedFormatTag == MA_DR_WAVE_FORMAT_DVI_ADPCM) {
+ framesRead = ma_dr_wav_read_pcm_frames_s16__ima(pWav, framesToRead, devnull);
} else {
- DRWAV_ASSERT(DRWAV_FALSE);
+ MA_DR_WAV_ASSERT(MA_FALSE);
}
if (framesRead != framesToRead) {
- return DRWAV_FALSE;
+ return MA_FALSE;
}
offsetInFrames -= framesRead;
}
}
} else {
- drwav_uint64 totalSizeInBytes;
- drwav_uint64 currentBytePos;
- drwav_uint64 targetBytePos;
- drwav_uint64 offset;
- drwav_uint32 bytesPerFrame;
- bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
+ ma_uint64 totalSizeInBytes;
+ ma_uint64 currentBytePos;
+ ma_uint64 targetBytePos;
+ ma_uint64 offset;
+ ma_uint32 bytesPerFrame;
+ bytesPerFrame = ma_dr_wav_get_bytes_per_pcm_frame(pWav);
if (bytesPerFrame == 0) {
- return DRWAV_FALSE;
+ return MA_FALSE;
}
totalSizeInBytes = pWav->totalPCMFrameCount * bytesPerFrame;
- DRWAV_ASSERT(totalSizeInBytes >= pWav->bytesRemaining);
currentBytePos = totalSizeInBytes - pWav->bytesRemaining;
targetBytePos = targetFrameIndex * bytesPerFrame;
if (currentBytePos < targetBytePos) {
offset = (targetBytePos - currentBytePos);
} else {
- if (!drwav_seek_to_first_pcm_frame(pWav)) {
- return DRWAV_FALSE;
+ if (!ma_dr_wav_seek_to_first_pcm_frame(pWav)) {
+ return MA_FALSE;
}
offset = targetBytePos;
}
while (offset > 0) {
int offset32 = ((offset > INT_MAX) ? INT_MAX : (int)offset);
- if (!pWav->onSeek(pWav->pUserData, offset32, drwav_seek_origin_current)) {
- return DRWAV_FALSE;
+ if (!pWav->onSeek(pWav->pUserData, offset32, ma_dr_wav_seek_origin_current)) {
+ return MA_FALSE;
}
pWav->readCursorInPCMFrames += offset32 / bytesPerFrame;
pWav->bytesRemaining -= offset32;
offset -= offset32;
}
}
- return DRWAV_TRUE;
+ return MA_TRUE;
}
-DRWAV_API drwav_result drwav_get_cursor_in_pcm_frames(drwav* pWav, drwav_uint64* pCursor)
+MA_API ma_result ma_dr_wav_get_cursor_in_pcm_frames(ma_dr_wav* pWav, ma_uint64* pCursor)
{
if (pCursor == NULL) {
- return DRWAV_INVALID_ARGS;
+ return MA_INVALID_ARGS;
}
*pCursor = 0;
if (pWav == NULL) {
- return DRWAV_INVALID_ARGS;
+ return MA_INVALID_ARGS;
}
*pCursor = pWav->readCursorInPCMFrames;
- return DRWAV_SUCCESS;
+ return MA_SUCCESS;
}
-DRWAV_API drwav_result drwav_get_length_in_pcm_frames(drwav* pWav, drwav_uint64* pLength)
+MA_API ma_result ma_dr_wav_get_length_in_pcm_frames(ma_dr_wav* pWav, ma_uint64* pLength)
{
if (pLength == NULL) {
- return DRWAV_INVALID_ARGS;
+ return MA_INVALID_ARGS;
}
*pLength = 0;
if (pWav == NULL) {
- return DRWAV_INVALID_ARGS;
+ return MA_INVALID_ARGS;
}
*pLength = pWav->totalPCMFrameCount;
- return DRWAV_SUCCESS;
+ return MA_SUCCESS;
}
-DRWAV_API size_t drwav_write_raw(drwav* pWav, size_t bytesToWrite, const void* pData)
+MA_API size_t ma_dr_wav_write_raw(ma_dr_wav* pWav, size_t bytesToWrite, const void* pData)
{
size_t bytesWritten;
if (pWav == NULL || bytesToWrite == 0 || pData == NULL) {
@@ -77797,26 +80250,26 @@ DRWAV_API size_t drwav_write_raw(drwav* pWav, size_t bytesToWrite, const void* p
pWav->dataChunkDataSize += bytesWritten;
return bytesWritten;
}
-DRWAV_API drwav_uint64 drwav_write_pcm_frames_le(drwav* pWav, drwav_uint64 framesToWrite, const void* pData)
+MA_API ma_uint64 ma_dr_wav_write_pcm_frames_le(ma_dr_wav* pWav, ma_uint64 framesToWrite, const void* pData)
{
- drwav_uint64 bytesToWrite;
- drwav_uint64 bytesWritten;
- const drwav_uint8* pRunningData;
+ ma_uint64 bytesToWrite;
+ ma_uint64 bytesWritten;
+ const ma_uint8* pRunningData;
if (pWav == NULL || framesToWrite == 0 || pData == NULL) {
return 0;
}
bytesToWrite = ((framesToWrite * pWav->channels * pWav->bitsPerSample) / 8);
- if (bytesToWrite > DRWAV_SIZE_MAX) {
+ if (bytesToWrite > MA_SIZE_MAX) {
return 0;
}
bytesWritten = 0;
- pRunningData = (const drwav_uint8*)pData;
+ pRunningData = (const ma_uint8*)pData;
while (bytesToWrite > 0) {
size_t bytesJustWritten;
- drwav_uint64 bytesToWriteThisIteration;
+ ma_uint64 bytesToWriteThisIteration;
bytesToWriteThisIteration = bytesToWrite;
- DRWAV_ASSERT(bytesToWriteThisIteration <= DRWAV_SIZE_MAX);
- bytesJustWritten = drwav_write_raw(pWav, (size_t)bytesToWriteThisIteration, pRunningData);
+ MA_DR_WAV_ASSERT(bytesToWriteThisIteration <= MA_SIZE_MAX);
+ bytesJustWritten = ma_dr_wav_write_raw(pWav, (size_t)bytesToWriteThisIteration, pRunningData);
if (bytesJustWritten == 0) {
break;
}
@@ -77826,39 +80279,39 @@ DRWAV_API drwav_uint64 drwav_write_pcm_frames_le(drwav* pWav, drwav_uint64 frame
}
return (bytesWritten * 8) / pWav->bitsPerSample / pWav->channels;
}
-DRWAV_API drwav_uint64 drwav_write_pcm_frames_be(drwav* pWav, drwav_uint64 framesToWrite, const void* pData)
+MA_API ma_uint64 ma_dr_wav_write_pcm_frames_be(ma_dr_wav* pWav, ma_uint64 framesToWrite, const void* pData)
{
- drwav_uint64 bytesToWrite;
- drwav_uint64 bytesWritten;
- drwav_uint32 bytesPerSample;
- const drwav_uint8* pRunningData;
+ ma_uint64 bytesToWrite;
+ ma_uint64 bytesWritten;
+ ma_uint32 bytesPerSample;
+ const ma_uint8* pRunningData;
if (pWav == NULL || framesToWrite == 0 || pData == NULL) {
return 0;
}
bytesToWrite = ((framesToWrite * pWav->channels * pWav->bitsPerSample) / 8);
- if (bytesToWrite > DRWAV_SIZE_MAX) {
+ if (bytesToWrite > MA_SIZE_MAX) {
return 0;
}
bytesWritten = 0;
- pRunningData = (const drwav_uint8*)pData;
- bytesPerSample = drwav_get_bytes_per_pcm_frame(pWav) / pWav->channels;
+ pRunningData = (const ma_uint8*)pData;
+ bytesPerSample = ma_dr_wav_get_bytes_per_pcm_frame(pWav) / pWav->channels;
if (bytesPerSample == 0) {
return 0;
}
while (bytesToWrite > 0) {
- drwav_uint8 temp[4096];
- drwav_uint32 sampleCount;
+ ma_uint8 temp[4096];
+ ma_uint32 sampleCount;
size_t bytesJustWritten;
- drwav_uint64 bytesToWriteThisIteration;
+ ma_uint64 bytesToWriteThisIteration;
bytesToWriteThisIteration = bytesToWrite;
- DRWAV_ASSERT(bytesToWriteThisIteration <= DRWAV_SIZE_MAX);
+ MA_DR_WAV_ASSERT(bytesToWriteThisIteration <= MA_SIZE_MAX);
sampleCount = sizeof(temp)/bytesPerSample;
- if (bytesToWriteThisIteration > ((drwav_uint64)sampleCount)*bytesPerSample) {
- bytesToWriteThisIteration = ((drwav_uint64)sampleCount)*bytesPerSample;
+ if (bytesToWriteThisIteration > ((ma_uint64)sampleCount)*bytesPerSample) {
+ bytesToWriteThisIteration = ((ma_uint64)sampleCount)*bytesPerSample;
}
- DRWAV_COPY_MEMORY(temp, pRunningData, (size_t)bytesToWriteThisIteration);
- drwav__bswap_samples(temp, sampleCount, bytesPerSample, pWav->translatedFormatTag);
- bytesJustWritten = drwav_write_raw(pWav, (size_t)bytesToWriteThisIteration, temp);
+ MA_DR_WAV_COPY_MEMORY(temp, pRunningData, (size_t)bytesToWriteThisIteration);
+ ma_dr_wav__bswap_samples(temp, sampleCount, bytesPerSample);
+ bytesJustWritten = ma_dr_wav_write_raw(pWav, (size_t)bytesToWriteThisIteration, temp);
if (bytesJustWritten == 0) {
break;
}
@@ -77868,49 +80321,49 @@ DRWAV_API drwav_uint64 drwav_write_pcm_frames_be(drwav* pWav, drwav_uint64 frame
}
return (bytesWritten * 8) / pWav->bitsPerSample / pWav->channels;
}
-DRWAV_API drwav_uint64 drwav_write_pcm_frames(drwav* pWav, drwav_uint64 framesToWrite, const void* pData)
+MA_API ma_uint64 ma_dr_wav_write_pcm_frames(ma_dr_wav* pWav, ma_uint64 framesToWrite, const void* pData)
{
- if (drwav__is_little_endian()) {
- return drwav_write_pcm_frames_le(pWav, framesToWrite, pData);
+ if (ma_dr_wav__is_little_endian()) {
+ return ma_dr_wav_write_pcm_frames_le(pWav, framesToWrite, pData);
} else {
- return drwav_write_pcm_frames_be(pWav, framesToWrite, pData);
+ return ma_dr_wav_write_pcm_frames_be(pWav, framesToWrite, pData);
}
}
-DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__msadpcm(drwav* pWav, drwav_uint64 framesToRead, drwav_int16* pBufferOut)
+MA_PRIVATE ma_uint64 ma_dr_wav_read_pcm_frames_s16__msadpcm(ma_dr_wav* pWav, ma_uint64 framesToRead, ma_int16* pBufferOut)
{
- drwav_uint64 totalFramesRead = 0;
- DRWAV_ASSERT(pWav != NULL);
- DRWAV_ASSERT(framesToRead > 0);
+ ma_uint64 totalFramesRead = 0;
+ MA_DR_WAV_ASSERT(pWav != NULL);
+ MA_DR_WAV_ASSERT(framesToRead > 0);
while (pWav->readCursorInPCMFrames < pWav->totalPCMFrameCount) {
- DRWAV_ASSERT(framesToRead > 0);
+ MA_DR_WAV_ASSERT(framesToRead > 0);
if (pWav->msadpcm.cachedFrameCount == 0 && pWav->msadpcm.bytesRemainingInBlock == 0) {
if (pWav->channels == 1) {
- drwav_uint8 header[7];
+ ma_uint8 header[7];
if (pWav->onRead(pWav->pUserData, header, sizeof(header)) != sizeof(header)) {
return totalFramesRead;
}
pWav->msadpcm.bytesRemainingInBlock = pWav->fmt.blockAlign - sizeof(header);
pWav->msadpcm.predictor[0] = header[0];
- pWav->msadpcm.delta[0] = drwav_bytes_to_s16(header + 1);
- pWav->msadpcm.prevFrames[0][1] = (drwav_int32)drwav_bytes_to_s16(header + 3);
- pWav->msadpcm.prevFrames[0][0] = (drwav_int32)drwav_bytes_to_s16(header + 5);
+ pWav->msadpcm.delta[0] = ma_dr_wav_bytes_to_s16(header + 1);
+ pWav->msadpcm.prevFrames[0][1] = (ma_int32)ma_dr_wav_bytes_to_s16(header + 3);
+ pWav->msadpcm.prevFrames[0][0] = (ma_int32)ma_dr_wav_bytes_to_s16(header + 5);
pWav->msadpcm.cachedFrames[2] = pWav->msadpcm.prevFrames[0][0];
pWav->msadpcm.cachedFrames[3] = pWav->msadpcm.prevFrames[0][1];
pWav->msadpcm.cachedFrameCount = 2;
} else {
- drwav_uint8 header[14];
+ ma_uint8 header[14];
if (pWav->onRead(pWav->pUserData, header, sizeof(header)) != sizeof(header)) {
return totalFramesRead;
}
pWav->msadpcm.bytesRemainingInBlock = pWav->fmt.blockAlign - sizeof(header);
pWav->msadpcm.predictor[0] = header[0];
pWav->msadpcm.predictor[1] = header[1];
- pWav->msadpcm.delta[0] = drwav_bytes_to_s16(header + 2);
- pWav->msadpcm.delta[1] = drwav_bytes_to_s16(header + 4);
- pWav->msadpcm.prevFrames[0][1] = (drwav_int32)drwav_bytes_to_s16(header + 6);
- pWav->msadpcm.prevFrames[1][1] = (drwav_int32)drwav_bytes_to_s16(header + 8);
- pWav->msadpcm.prevFrames[0][0] = (drwav_int32)drwav_bytes_to_s16(header + 10);
- pWav->msadpcm.prevFrames[1][0] = (drwav_int32)drwav_bytes_to_s16(header + 12);
+ pWav->msadpcm.delta[0] = ma_dr_wav_bytes_to_s16(header + 2);
+ pWav->msadpcm.delta[1] = ma_dr_wav_bytes_to_s16(header + 4);
+ pWav->msadpcm.prevFrames[0][1] = (ma_int32)ma_dr_wav_bytes_to_s16(header + 6);
+ pWav->msadpcm.prevFrames[1][1] = (ma_int32)ma_dr_wav_bytes_to_s16(header + 8);
+ pWav->msadpcm.prevFrames[0][0] = (ma_int32)ma_dr_wav_bytes_to_s16(header + 10);
+ pWav->msadpcm.prevFrames[1][0] = (ma_int32)ma_dr_wav_bytes_to_s16(header + 12);
pWav->msadpcm.cachedFrames[0] = pWav->msadpcm.prevFrames[0][0];
pWav->msadpcm.cachedFrames[1] = pWav->msadpcm.prevFrames[1][0];
pWav->msadpcm.cachedFrames[2] = pWav->msadpcm.prevFrames[0][1];
@@ -77920,9 +80373,9 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__msadpcm(drwav* pWav, drwav
}
while (framesToRead > 0 && pWav->msadpcm.cachedFrameCount > 0 && pWav->readCursorInPCMFrames < pWav->totalPCMFrameCount) {
if (pBufferOut != NULL) {
- drwav_uint32 iSample = 0;
+ ma_uint32 iSample = 0;
for (iSample = 0; iSample < pWav->channels; iSample += 1) {
- pBufferOut[iSample] = (drwav_int16)pWav->msadpcm.cachedFrames[(drwav_countof(pWav->msadpcm.cachedFrames) - (pWav->msadpcm.cachedFrameCount*pWav->channels)) + iSample];
+ pBufferOut[iSample] = (ma_int16)pWav->msadpcm.cachedFrames[(ma_dr_wav_countof(pWav->msadpcm.cachedFrames) - (pWav->msadpcm.cachedFrameCount*pWav->channels)) + iSample];
}
pBufferOut += pWav->channels;
}
@@ -77938,15 +80391,15 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__msadpcm(drwav* pWav, drwav
if (pWav->msadpcm.bytesRemainingInBlock == 0) {
continue;
} else {
- static drwav_int32 adaptationTable[] = {
+ static ma_int32 adaptationTable[] = {
230, 230, 230, 230, 307, 409, 512, 614,
768, 614, 512, 409, 307, 230, 230, 230
};
- static drwav_int32 coeff1Table[] = { 256, 512, 0, 192, 240, 460, 392 };
- static drwav_int32 coeff2Table[] = { 0, -256, 0, 64, 0, -208, -232 };
- drwav_uint8 nibbles;
- drwav_int32 nibble0;
- drwav_int32 nibble1;
+ static ma_int32 coeff1Table[] = { 256, 512, 0, 192, 240, 460, 392 };
+ static ma_int32 coeff2Table[] = { 0, -256, 0, 64, 0, -208, -232 };
+ ma_uint8 nibbles;
+ ma_int32 nibble0;
+ ma_int32 nibble1;
if (pWav->onRead(pWav->pUserData, &nibbles, 1) != 1) {
return totalFramesRead;
}
@@ -77954,11 +80407,11 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__msadpcm(drwav* pWav, drwav
nibble0 = ((nibbles & 0xF0) >> 4); if ((nibbles & 0x80)) { nibble0 |= 0xFFFFFFF0UL; }
nibble1 = ((nibbles & 0x0F) >> 0); if ((nibbles & 0x08)) { nibble1 |= 0xFFFFFFF0UL; }
if (pWav->channels == 1) {
- drwav_int32 newSample0;
- drwav_int32 newSample1;
+ ma_int32 newSample0;
+ ma_int32 newSample1;
newSample0 = ((pWav->msadpcm.prevFrames[0][1] * coeff1Table[pWav->msadpcm.predictor[0]]) + (pWav->msadpcm.prevFrames[0][0] * coeff2Table[pWav->msadpcm.predictor[0]])) >> 8;
newSample0 += nibble0 * pWav->msadpcm.delta[0];
- newSample0 = drwav_clamp(newSample0, -32768, 32767);
+ newSample0 = ma_dr_wav_clamp(newSample0, -32768, 32767);
pWav->msadpcm.delta[0] = (adaptationTable[((nibbles & 0xF0) >> 4)] * pWav->msadpcm.delta[0]) >> 8;
if (pWav->msadpcm.delta[0] < 16) {
pWav->msadpcm.delta[0] = 16;
@@ -77967,7 +80420,7 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__msadpcm(drwav* pWav, drwav
pWav->msadpcm.prevFrames[0][1] = newSample0;
newSample1 = ((pWav->msadpcm.prevFrames[0][1] * coeff1Table[pWav->msadpcm.predictor[0]]) + (pWav->msadpcm.prevFrames[0][0] * coeff2Table[pWav->msadpcm.predictor[0]])) >> 8;
newSample1 += nibble1 * pWav->msadpcm.delta[0];
- newSample1 = drwav_clamp(newSample1, -32768, 32767);
+ newSample1 = ma_dr_wav_clamp(newSample1, -32768, 32767);
pWav->msadpcm.delta[0] = (adaptationTable[((nibbles & 0x0F) >> 0)] * pWav->msadpcm.delta[0]) >> 8;
if (pWav->msadpcm.delta[0] < 16) {
pWav->msadpcm.delta[0] = 16;
@@ -77978,11 +80431,11 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__msadpcm(drwav* pWav, drwav
pWav->msadpcm.cachedFrames[3] = newSample1;
pWav->msadpcm.cachedFrameCount = 2;
} else {
- drwav_int32 newSample0;
- drwav_int32 newSample1;
+ ma_int32 newSample0;
+ ma_int32 newSample1;
newSample0 = ((pWav->msadpcm.prevFrames[0][1] * coeff1Table[pWav->msadpcm.predictor[0]]) + (pWav->msadpcm.prevFrames[0][0] * coeff2Table[pWav->msadpcm.predictor[0]])) >> 8;
newSample0 += nibble0 * pWav->msadpcm.delta[0];
- newSample0 = drwav_clamp(newSample0, -32768, 32767);
+ newSample0 = ma_dr_wav_clamp(newSample0, -32768, 32767);
pWav->msadpcm.delta[0] = (adaptationTable[((nibbles & 0xF0) >> 4)] * pWav->msadpcm.delta[0]) >> 8;
if (pWav->msadpcm.delta[0] < 16) {
pWav->msadpcm.delta[0] = 16;
@@ -77991,7 +80444,7 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__msadpcm(drwav* pWav, drwav
pWav->msadpcm.prevFrames[0][1] = newSample0;
newSample1 = ((pWav->msadpcm.prevFrames[1][1] * coeff1Table[pWav->msadpcm.predictor[1]]) + (pWav->msadpcm.prevFrames[1][0] * coeff2Table[pWav->msadpcm.predictor[1]])) >> 8;
newSample1 += nibble1 * pWav->msadpcm.delta[1];
- newSample1 = drwav_clamp(newSample1, -32768, 32767);
+ newSample1 = ma_dr_wav_clamp(newSample1, -32768, 32767);
pWav->msadpcm.delta[1] = (adaptationTable[((nibbles & 0x0F) >> 0)] * pWav->msadpcm.delta[1]) >> 8;
if (pWav->msadpcm.delta[1] < 16) {
pWav->msadpcm.delta[1] = 16;
@@ -78007,15 +80460,15 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__msadpcm(drwav* pWav, drwav
}
return totalFramesRead;
}
-DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__ima(drwav* pWav, drwav_uint64 framesToRead, drwav_int16* pBufferOut)
+MA_PRIVATE ma_uint64 ma_dr_wav_read_pcm_frames_s16__ima(ma_dr_wav* pWav, ma_uint64 framesToRead, ma_int16* pBufferOut)
{
- drwav_uint64 totalFramesRead = 0;
- drwav_uint32 iChannel;
- static drwav_int32 indexTable[16] = {
+ ma_uint64 totalFramesRead = 0;
+ ma_uint32 iChannel;
+ static ma_int32 indexTable[16] = {
-1, -1, -1, -1, 2, 4, 6, 8,
-1, -1, -1, -1, 2, 4, 6, 8
};
- static drwav_int32 stepTable[89] = {
+ static ma_int32 stepTable[89] = {
7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
@@ -78026,51 +80479,51 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__ima(drwav* pWav, drwav_uin
5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
};
- DRWAV_ASSERT(pWav != NULL);
- DRWAV_ASSERT(framesToRead > 0);
+ MA_DR_WAV_ASSERT(pWav != NULL);
+ MA_DR_WAV_ASSERT(framesToRead > 0);
while (pWav->readCursorInPCMFrames < pWav->totalPCMFrameCount) {
- DRWAV_ASSERT(framesToRead > 0);
+ MA_DR_WAV_ASSERT(framesToRead > 0);
if (pWav->ima.cachedFrameCount == 0 && pWav->ima.bytesRemainingInBlock == 0) {
if (pWav->channels == 1) {
- drwav_uint8 header[4];
+ ma_uint8 header[4];
if (pWav->onRead(pWav->pUserData, header, sizeof(header)) != sizeof(header)) {
return totalFramesRead;
}
pWav->ima.bytesRemainingInBlock = pWav->fmt.blockAlign - sizeof(header);
- if (header[2] >= drwav_countof(stepTable)) {
- pWav->onSeek(pWav->pUserData, pWav->ima.bytesRemainingInBlock, drwav_seek_origin_current);
+ if (header[2] >= ma_dr_wav_countof(stepTable)) {
+ pWav->onSeek(pWav->pUserData, pWav->ima.bytesRemainingInBlock, ma_dr_wav_seek_origin_current);
pWav->ima.bytesRemainingInBlock = 0;
return totalFramesRead;
}
- pWav->ima.predictor[0] = drwav_bytes_to_s16(header + 0);
- pWav->ima.stepIndex[0] = drwav_clamp(header[2], 0, (drwav_int32)drwav_countof(stepTable)-1);
- pWav->ima.cachedFrames[drwav_countof(pWav->ima.cachedFrames) - 1] = pWav->ima.predictor[0];
+ pWav->ima.predictor[0] = (ma_int16)ma_dr_wav_bytes_to_u16(header + 0);
+ pWav->ima.stepIndex[0] = ma_dr_wav_clamp(header[2], 0, (ma_int32)ma_dr_wav_countof(stepTable)-1);
+ pWav->ima.cachedFrames[ma_dr_wav_countof(pWav->ima.cachedFrames) - 1] = pWav->ima.predictor[0];
pWav->ima.cachedFrameCount = 1;
} else {
- drwav_uint8 header[8];
+ ma_uint8 header[8];
if (pWav->onRead(pWav->pUserData, header, sizeof(header)) != sizeof(header)) {
return totalFramesRead;
}
pWav->ima.bytesRemainingInBlock = pWav->fmt.blockAlign - sizeof(header);
- if (header[2] >= drwav_countof(stepTable) || header[6] >= drwav_countof(stepTable)) {
- pWav->onSeek(pWav->pUserData, pWav->ima.bytesRemainingInBlock, drwav_seek_origin_current);
+ if (header[2] >= ma_dr_wav_countof(stepTable) || header[6] >= ma_dr_wav_countof(stepTable)) {
+ pWav->onSeek(pWav->pUserData, pWav->ima.bytesRemainingInBlock, ma_dr_wav_seek_origin_current);
pWav->ima.bytesRemainingInBlock = 0;
return totalFramesRead;
}
- pWav->ima.predictor[0] = drwav_bytes_to_s16(header + 0);
- pWav->ima.stepIndex[0] = drwav_clamp(header[2], 0, (drwav_int32)drwav_countof(stepTable)-1);
- pWav->ima.predictor[1] = drwav_bytes_to_s16(header + 4);
- pWav->ima.stepIndex[1] = drwav_clamp(header[6], 0, (drwav_int32)drwav_countof(stepTable)-1);
- pWav->ima.cachedFrames[drwav_countof(pWav->ima.cachedFrames) - 2] = pWav->ima.predictor[0];
- pWav->ima.cachedFrames[drwav_countof(pWav->ima.cachedFrames) - 1] = pWav->ima.predictor[1];
+ pWav->ima.predictor[0] = ma_dr_wav_bytes_to_s16(header + 0);
+ pWav->ima.stepIndex[0] = ma_dr_wav_clamp(header[2], 0, (ma_int32)ma_dr_wav_countof(stepTable)-1);
+ pWav->ima.predictor[1] = ma_dr_wav_bytes_to_s16(header + 4);
+ pWav->ima.stepIndex[1] = ma_dr_wav_clamp(header[6], 0, (ma_int32)ma_dr_wav_countof(stepTable)-1);
+ pWav->ima.cachedFrames[ma_dr_wav_countof(pWav->ima.cachedFrames) - 2] = pWav->ima.predictor[0];
+ pWav->ima.cachedFrames[ma_dr_wav_countof(pWav->ima.cachedFrames) - 1] = pWav->ima.predictor[1];
pWav->ima.cachedFrameCount = 1;
}
}
while (framesToRead > 0 && pWav->ima.cachedFrameCount > 0 && pWav->readCursorInPCMFrames < pWav->totalPCMFrameCount) {
if (pBufferOut != NULL) {
- drwav_uint32 iSample;
+ ma_uint32 iSample;
for (iSample = 0; iSample < pWav->channels; iSample += 1) {
- pBufferOut[iSample] = (drwav_int16)pWav->ima.cachedFrames[(drwav_countof(pWav->ima.cachedFrames) - (pWav->ima.cachedFrameCount*pWav->channels)) + iSample];
+ pBufferOut[iSample] = (ma_int16)pWav->ima.cachedFrames[(ma_dr_wav_countof(pWav->ima.cachedFrames) - (pWav->ima.cachedFrameCount*pWav->channels)) + iSample];
}
pBufferOut += pWav->channels;
}
@@ -78088,27 +80541,27 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__ima(drwav* pWav, drwav_uin
} else {
pWav->ima.cachedFrameCount = 8;
for (iChannel = 0; iChannel < pWav->channels; ++iChannel) {
- drwav_uint32 iByte;
- drwav_uint8 nibbles[4];
+ ma_uint32 iByte;
+ ma_uint8 nibbles[4];
if (pWav->onRead(pWav->pUserData, &nibbles, 4) != 4) {
pWav->ima.cachedFrameCount = 0;
return totalFramesRead;
}
pWav->ima.bytesRemainingInBlock -= 4;
for (iByte = 0; iByte < 4; ++iByte) {
- drwav_uint8 nibble0 = ((nibbles[iByte] & 0x0F) >> 0);
- drwav_uint8 nibble1 = ((nibbles[iByte] & 0xF0) >> 4);
- drwav_int32 step = stepTable[pWav->ima.stepIndex[iChannel]];
- drwav_int32 predictor = pWav->ima.predictor[iChannel];
- drwav_int32 diff = step >> 3;
+ ma_uint8 nibble0 = ((nibbles[iByte] & 0x0F) >> 0);
+ ma_uint8 nibble1 = ((nibbles[iByte] & 0xF0) >> 4);
+ ma_int32 step = stepTable[pWav->ima.stepIndex[iChannel]];
+ ma_int32 predictor = pWav->ima.predictor[iChannel];
+ ma_int32 diff = step >> 3;
if (nibble0 & 1) diff += step >> 2;
if (nibble0 & 2) diff += step >> 1;
if (nibble0 & 4) diff += step;
if (nibble0 & 8) diff = -diff;
- predictor = drwav_clamp(predictor + diff, -32768, 32767);
+ predictor = ma_dr_wav_clamp(predictor + diff, -32768, 32767);
pWav->ima.predictor[iChannel] = predictor;
- pWav->ima.stepIndex[iChannel] = drwav_clamp(pWav->ima.stepIndex[iChannel] + indexTable[nibble0], 0, (drwav_int32)drwav_countof(stepTable)-1);
- pWav->ima.cachedFrames[(drwav_countof(pWav->ima.cachedFrames) - (pWav->ima.cachedFrameCount*pWav->channels)) + (iByte*2+0)*pWav->channels + iChannel] = predictor;
+ pWav->ima.stepIndex[iChannel] = ma_dr_wav_clamp(pWav->ima.stepIndex[iChannel] + indexTable[nibble0], 0, (ma_int32)ma_dr_wav_countof(stepTable)-1);
+ pWav->ima.cachedFrames[(ma_dr_wav_countof(pWav->ima.cachedFrames) - (pWav->ima.cachedFrameCount*pWav->channels)) + (iByte*2+0)*pWav->channels + iChannel] = predictor;
step = stepTable[pWav->ima.stepIndex[iChannel]];
predictor = pWav->ima.predictor[iChannel];
diff = step >> 3;
@@ -78116,10 +80569,10 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__ima(drwav* pWav, drwav_uin
if (nibble1 & 2) diff += step >> 1;
if (nibble1 & 4) diff += step;
if (nibble1 & 8) diff = -diff;
- predictor = drwav_clamp(predictor + diff, -32768, 32767);
+ predictor = ma_dr_wav_clamp(predictor + diff, -32768, 32767);
pWav->ima.predictor[iChannel] = predictor;
- pWav->ima.stepIndex[iChannel] = drwav_clamp(pWav->ima.stepIndex[iChannel] + indexTable[nibble1], 0, (drwav_int32)drwav_countof(stepTable)-1);
- pWav->ima.cachedFrames[(drwav_countof(pWav->ima.cachedFrames) - (pWav->ima.cachedFrameCount*pWav->channels)) + (iByte*2+1)*pWav->channels + iChannel] = predictor;
+ pWav->ima.stepIndex[iChannel] = ma_dr_wav_clamp(pWav->ima.stepIndex[iChannel] + indexTable[nibble1], 0, (ma_int32)ma_dr_wav_countof(stepTable)-1);
+ pWav->ima.cachedFrames[(ma_dr_wav_countof(pWav->ima.cachedFrames) - (pWav->ima.cachedFrameCount*pWav->channels)) + (iByte*2+1)*pWav->channels + iChannel] = predictor;
}
}
}
@@ -78127,8 +80580,8 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__ima(drwav* pWav, drwav_uin
}
return totalFramesRead;
}
-#ifndef DR_WAV_NO_CONVERSION_API
-static unsigned short g_drwavAlawTable[256] = {
+#ifndef MA_DR_WAV_NO_CONVERSION_API
+static unsigned short g_ma_dr_wavAlawTable[256] = {
0xEA80, 0xEB80, 0xE880, 0xE980, 0xEE80, 0xEF80, 0xEC80, 0xED80, 0xE280, 0xE380, 0xE080, 0xE180, 0xE680, 0xE780, 0xE480, 0xE580,
0xF540, 0xF5C0, 0xF440, 0xF4C0, 0xF740, 0xF7C0, 0xF640, 0xF6C0, 0xF140, 0xF1C0, 0xF040, 0xF0C0, 0xF340, 0xF3C0, 0xF240, 0xF2C0,
0xAA00, 0xAE00, 0xA200, 0xA600, 0xBA00, 0xBE00, 0xB200, 0xB600, 0x8A00, 0x8E00, 0x8200, 0x8600, 0x9A00, 0x9E00, 0x9200, 0x9600,
@@ -78146,7 +80599,7 @@ static unsigned short g_drwavAlawTable[256] = {
0x0560, 0x0520, 0x05E0, 0x05A0, 0x0460, 0x0420, 0x04E0, 0x04A0, 0x0760, 0x0720, 0x07E0, 0x07A0, 0x0660, 0x0620, 0x06E0, 0x06A0,
0x02B0, 0x0290, 0x02F0, 0x02D0, 0x0230, 0x0210, 0x0270, 0x0250, 0x03B0, 0x0390, 0x03F0, 0x03D0, 0x0330, 0x0310, 0x0370, 0x0350
};
-static unsigned short g_drwavMulawTable[256] = {
+static unsigned short g_ma_dr_wavMulawTable[256] = {
0x8284, 0x8684, 0x8A84, 0x8E84, 0x9284, 0x9684, 0x9A84, 0x9E84, 0xA284, 0xA684, 0xAA84, 0xAE84, 0xB284, 0xB684, 0xBA84, 0xBE84,
0xC184, 0xC384, 0xC584, 0xC784, 0xC984, 0xCB84, 0xCD84, 0xCF84, 0xD184, 0xD384, 0xD584, 0xD784, 0xD984, 0xDB84, 0xDD84, 0xDF84,
0xE104, 0xE204, 0xE304, 0xE404, 0xE504, 0xE604, 0xE704, 0xE804, 0xE904, 0xEA04, 0xEB04, 0xEC04, 0xED04, 0xEE04, 0xEF04, 0xF004,
@@ -78164,76 +80617,76 @@ static unsigned short g_drwavMulawTable[256] = {
0x0174, 0x0164, 0x0154, 0x0144, 0x0134, 0x0124, 0x0114, 0x0104, 0x00F4, 0x00E4, 0x00D4, 0x00C4, 0x00B4, 0x00A4, 0x0094, 0x0084,
0x0078, 0x0070, 0x0068, 0x0060, 0x0058, 0x0050, 0x0048, 0x0040, 0x0038, 0x0030, 0x0028, 0x0020, 0x0018, 0x0010, 0x0008, 0x0000
};
-static DRWAV_INLINE drwav_int16 drwav__alaw_to_s16(drwav_uint8 sampleIn)
+static MA_INLINE ma_int16 ma_dr_wav__alaw_to_s16(ma_uint8 sampleIn)
{
- return (short)g_drwavAlawTable[sampleIn];
+ return (short)g_ma_dr_wavAlawTable[sampleIn];
}
-static DRWAV_INLINE drwav_int16 drwav__mulaw_to_s16(drwav_uint8 sampleIn)
+static MA_INLINE ma_int16 ma_dr_wav__mulaw_to_s16(ma_uint8 sampleIn)
{
- return (short)g_drwavMulawTable[sampleIn];
+ return (short)g_ma_dr_wavMulawTable[sampleIn];
}
-DRWAV_PRIVATE void drwav__pcm_to_s16(drwav_int16* pOut, const drwav_uint8* pIn, size_t totalSampleCount, unsigned int bytesPerSample)
+MA_PRIVATE void ma_dr_wav__pcm_to_s16(ma_int16* pOut, const ma_uint8* pIn, size_t totalSampleCount, unsigned int bytesPerSample)
{
size_t i;
if (bytesPerSample == 1) {
- drwav_u8_to_s16(pOut, pIn, totalSampleCount);
+ ma_dr_wav_u8_to_s16(pOut, pIn, totalSampleCount);
return;
}
if (bytesPerSample == 2) {
for (i = 0; i < totalSampleCount; ++i) {
- *pOut++ = ((const drwav_int16*)pIn)[i];
+ *pOut++ = ((const ma_int16*)pIn)[i];
}
return;
}
if (bytesPerSample == 3) {
- drwav_s24_to_s16(pOut, pIn, totalSampleCount);
+ ma_dr_wav_s24_to_s16(pOut, pIn, totalSampleCount);
return;
}
if (bytesPerSample == 4) {
- drwav_s32_to_s16(pOut, (const drwav_int32*)pIn, totalSampleCount);
+ ma_dr_wav_s32_to_s16(pOut, (const ma_int32*)pIn, totalSampleCount);
return;
}
if (bytesPerSample > 8) {
- DRWAV_ZERO_MEMORY(pOut, totalSampleCount * sizeof(*pOut));
+ MA_DR_WAV_ZERO_MEMORY(pOut, totalSampleCount * sizeof(*pOut));
return;
}
for (i = 0; i < totalSampleCount; ++i) {
- drwav_uint64 sample = 0;
+ ma_uint64 sample = 0;
unsigned int shift = (8 - bytesPerSample) * 8;
unsigned int j;
for (j = 0; j < bytesPerSample; j += 1) {
- DRWAV_ASSERT(j < 8);
- sample |= (drwav_uint64)(pIn[j]) << shift;
+ MA_DR_WAV_ASSERT(j < 8);
+ sample |= (ma_uint64)(pIn[j]) << shift;
shift += 8;
}
pIn += j;
- *pOut++ = (drwav_int16)((drwav_int64)sample >> 48);
+ *pOut++ = (ma_int16)((ma_int64)sample >> 48);
}
}
-DRWAV_PRIVATE void drwav__ieee_to_s16(drwav_int16* pOut, const drwav_uint8* pIn, size_t totalSampleCount, unsigned int bytesPerSample)
+MA_PRIVATE void ma_dr_wav__ieee_to_s16(ma_int16* pOut, const ma_uint8* pIn, size_t totalSampleCount, unsigned int bytesPerSample)
{
if (bytesPerSample == 4) {
- drwav_f32_to_s16(pOut, (const float*)pIn, totalSampleCount);
+ ma_dr_wav_f32_to_s16(pOut, (const float*)pIn, totalSampleCount);
return;
} else if (bytesPerSample == 8) {
- drwav_f64_to_s16(pOut, (const double*)pIn, totalSampleCount);
+ ma_dr_wav_f64_to_s16(pOut, (const double*)pIn, totalSampleCount);
return;
} else {
- DRWAV_ZERO_MEMORY(pOut, totalSampleCount * sizeof(*pOut));
+ MA_DR_WAV_ZERO_MEMORY(pOut, totalSampleCount * sizeof(*pOut));
return;
}
}
-DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__pcm(drwav* pWav, drwav_uint64 framesToRead, drwav_int16* pBufferOut)
+MA_PRIVATE ma_uint64 ma_dr_wav_read_pcm_frames_s16__pcm(ma_dr_wav* pWav, ma_uint64 framesToRead, ma_int16* pBufferOut)
{
- drwav_uint64 totalFramesRead;
- drwav_uint8 sampleData[4096] = {0};
- drwav_uint32 bytesPerFrame;
- drwav_uint32 bytesPerSample;
- drwav_uint64 samplesRead;
- if ((pWav->translatedFormatTag == DR_WAVE_FORMAT_PCM && pWav->bitsPerSample == 16) || pBufferOut == NULL) {
- return drwav_read_pcm_frames(pWav, framesToRead, pBufferOut);
- }
- bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
+ ma_uint64 totalFramesRead;
+ ma_uint8 sampleData[4096] = {0};
+ ma_uint32 bytesPerFrame;
+ ma_uint32 bytesPerSample;
+ ma_uint64 samplesRead;
+ if ((pWav->translatedFormatTag == MA_DR_WAVE_FORMAT_PCM && pWav->bitsPerSample == 16) || pBufferOut == NULL) {
+ return ma_dr_wav_read_pcm_frames(pWav, framesToRead, pBufferOut);
+ }
+ bytesPerFrame = ma_dr_wav_get_bytes_per_pcm_frame(pWav);
if (bytesPerFrame == 0) {
return 0;
}
@@ -78243,35 +80696,35 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__pcm(drwav* pWav, drwav_uin
}
totalFramesRead = 0;
while (framesToRead > 0) {
- drwav_uint64 framesToReadThisIteration = drwav_min(framesToRead, sizeof(sampleData)/bytesPerFrame);
- drwav_uint64 framesRead = drwav_read_pcm_frames(pWav, framesToReadThisIteration, sampleData);
+ ma_uint64 framesToReadThisIteration = ma_dr_wav_min(framesToRead, sizeof(sampleData)/bytesPerFrame);
+ ma_uint64 framesRead = ma_dr_wav_read_pcm_frames(pWav, framesToReadThisIteration, sampleData);
if (framesRead == 0) {
break;
}
- DRWAV_ASSERT(framesRead <= framesToReadThisIteration);
+ MA_DR_WAV_ASSERT(framesRead <= framesToReadThisIteration);
samplesRead = framesRead * pWav->channels;
if ((samplesRead * bytesPerSample) > sizeof(sampleData)) {
- DRWAV_ASSERT(DRWAV_FALSE);
+ MA_DR_WAV_ASSERT(MA_FALSE);
break;
}
- drwav__pcm_to_s16(pBufferOut, sampleData, (size_t)samplesRead, bytesPerSample);
+ ma_dr_wav__pcm_to_s16(pBufferOut, sampleData, (size_t)samplesRead, bytesPerSample);
pBufferOut += samplesRead;
framesToRead -= framesRead;
totalFramesRead += framesRead;
}
return totalFramesRead;
}
-DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__ieee(drwav* pWav, drwav_uint64 framesToRead, drwav_int16* pBufferOut)
+MA_PRIVATE ma_uint64 ma_dr_wav_read_pcm_frames_s16__ieee(ma_dr_wav* pWav, ma_uint64 framesToRead, ma_int16* pBufferOut)
{
- drwav_uint64 totalFramesRead;
- drwav_uint8 sampleData[4096] = {0};
- drwav_uint32 bytesPerFrame;
- drwav_uint32 bytesPerSample;
- drwav_uint64 samplesRead;
+ ma_uint64 totalFramesRead;
+ ma_uint8 sampleData[4096] = {0};
+ ma_uint32 bytesPerFrame;
+ ma_uint32 bytesPerSample;
+ ma_uint64 samplesRead;
if (pBufferOut == NULL) {
- return drwav_read_pcm_frames(pWav, framesToRead, NULL);
+ return ma_dr_wav_read_pcm_frames(pWav, framesToRead, NULL);
}
- bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
+ bytesPerFrame = ma_dr_wav_get_bytes_per_pcm_frame(pWav);
if (bytesPerFrame == 0) {
return 0;
}
@@ -78281,35 +80734,35 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__ieee(drwav* pWav, drwav_ui
}
totalFramesRead = 0;
while (framesToRead > 0) {
- drwav_uint64 framesToReadThisIteration = drwav_min(framesToRead, sizeof(sampleData)/bytesPerFrame);
- drwav_uint64 framesRead = drwav_read_pcm_frames(pWav, framesToReadThisIteration, sampleData);
+ ma_uint64 framesToReadThisIteration = ma_dr_wav_min(framesToRead, sizeof(sampleData)/bytesPerFrame);
+ ma_uint64 framesRead = ma_dr_wav_read_pcm_frames(pWav, framesToReadThisIteration, sampleData);
if (framesRead == 0) {
break;
}
- DRWAV_ASSERT(framesRead <= framesToReadThisIteration);
+ MA_DR_WAV_ASSERT(framesRead <= framesToReadThisIteration);
samplesRead = framesRead * pWav->channels;
if ((samplesRead * bytesPerSample) > sizeof(sampleData)) {
- DRWAV_ASSERT(DRWAV_FALSE);
+ MA_DR_WAV_ASSERT(MA_FALSE);
break;
}
- drwav__ieee_to_s16(pBufferOut, sampleData, (size_t)samplesRead, bytesPerSample);
+ ma_dr_wav__ieee_to_s16(pBufferOut, sampleData, (size_t)samplesRead, bytesPerSample);
pBufferOut += samplesRead;
framesToRead -= framesRead;
totalFramesRead += framesRead;
}
return totalFramesRead;
}
-DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__alaw(drwav* pWav, drwav_uint64 framesToRead, drwav_int16* pBufferOut)
+MA_PRIVATE ma_uint64 ma_dr_wav_read_pcm_frames_s16__alaw(ma_dr_wav* pWav, ma_uint64 framesToRead, ma_int16* pBufferOut)
{
- drwav_uint64 totalFramesRead;
- drwav_uint8 sampleData[4096] = {0};
- drwav_uint32 bytesPerFrame;
- drwav_uint32 bytesPerSample;
- drwav_uint64 samplesRead;
+ ma_uint64 totalFramesRead;
+ ma_uint8 sampleData[4096] = {0};
+ ma_uint32 bytesPerFrame;
+ ma_uint32 bytesPerSample;
+ ma_uint64 samplesRead;
if (pBufferOut == NULL) {
- return drwav_read_pcm_frames(pWav, framesToRead, NULL);
+ return ma_dr_wav_read_pcm_frames(pWav, framesToRead, NULL);
}
- bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
+ bytesPerFrame = ma_dr_wav_get_bytes_per_pcm_frame(pWav);
if (bytesPerFrame == 0) {
return 0;
}
@@ -78319,35 +80772,45 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__alaw(drwav* pWav, drwav_ui
}
totalFramesRead = 0;
while (framesToRead > 0) {
- drwav_uint64 framesToReadThisIteration = drwav_min(framesToRead, sizeof(sampleData)/bytesPerFrame);
- drwav_uint64 framesRead = drwav_read_pcm_frames(pWav, framesToReadThisIteration, sampleData);
+ ma_uint64 framesToReadThisIteration = ma_dr_wav_min(framesToRead, sizeof(sampleData)/bytesPerFrame);
+ ma_uint64 framesRead = ma_dr_wav_read_pcm_frames(pWav, framesToReadThisIteration, sampleData);
if (framesRead == 0) {
break;
}
- DRWAV_ASSERT(framesRead <= framesToReadThisIteration);
+ MA_DR_WAV_ASSERT(framesRead <= framesToReadThisIteration);
samplesRead = framesRead * pWav->channels;
if ((samplesRead * bytesPerSample) > sizeof(sampleData)) {
- DRWAV_ASSERT(DRWAV_FALSE);
+ MA_DR_WAV_ASSERT(MA_FALSE);
break;
}
- drwav_alaw_to_s16(pBufferOut, sampleData, (size_t)samplesRead);
+ ma_dr_wav_alaw_to_s16(pBufferOut, sampleData, (size_t)samplesRead);
+ #ifdef MA_DR_WAV_LIBSNDFILE_COMPAT
+ {
+ if (pWav->container == ma_dr_wav_container_aiff) {
+ ma_uint64 iSample;
+ for (iSample = 0; iSample < samplesRead; iSample += 1) {
+ pBufferOut[iSample] = -pBufferOut[iSample];
+ }
+ }
+ }
+ #endif
pBufferOut += samplesRead;
framesToRead -= framesRead;
totalFramesRead += framesRead;
}
return totalFramesRead;
}
-DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__mulaw(drwav* pWav, drwav_uint64 framesToRead, drwav_int16* pBufferOut)
+MA_PRIVATE ma_uint64 ma_dr_wav_read_pcm_frames_s16__mulaw(ma_dr_wav* pWav, ma_uint64 framesToRead, ma_int16* pBufferOut)
{
- drwav_uint64 totalFramesRead;
- drwav_uint8 sampleData[4096] = {0};
- drwav_uint32 bytesPerFrame;
- drwav_uint32 bytesPerSample;
- drwav_uint64 samplesRead;
+ ma_uint64 totalFramesRead;
+ ma_uint8 sampleData[4096] = {0};
+ ma_uint32 bytesPerFrame;
+ ma_uint32 bytesPerSample;
+ ma_uint64 samplesRead;
if (pBufferOut == NULL) {
- return drwav_read_pcm_frames(pWav, framesToRead, NULL);
+ return ma_dr_wav_read_pcm_frames(pWav, framesToRead, NULL);
}
- bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
+ bytesPerFrame = ma_dr_wav_get_bytes_per_pcm_frame(pWav);
if (bytesPerFrame == 0) {
return 0;
}
@@ -78357,72 +80820,82 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__mulaw(drwav* pWav, drwav_u
}
totalFramesRead = 0;
while (framesToRead > 0) {
- drwav_uint64 framesToReadThisIteration = drwav_min(framesToRead, sizeof(sampleData)/bytesPerFrame);
- drwav_uint64 framesRead = drwav_read_pcm_frames(pWav, framesToReadThisIteration, sampleData);
+ ma_uint64 framesToReadThisIteration = ma_dr_wav_min(framesToRead, sizeof(sampleData)/bytesPerFrame);
+ ma_uint64 framesRead = ma_dr_wav_read_pcm_frames(pWav, framesToReadThisIteration, sampleData);
if (framesRead == 0) {
break;
}
- DRWAV_ASSERT(framesRead <= framesToReadThisIteration);
+ MA_DR_WAV_ASSERT(framesRead <= framesToReadThisIteration);
samplesRead = framesRead * pWav->channels;
if ((samplesRead * bytesPerSample) > sizeof(sampleData)) {
- DRWAV_ASSERT(DRWAV_FALSE);
+ MA_DR_WAV_ASSERT(MA_FALSE);
break;
}
- drwav_mulaw_to_s16(pBufferOut, sampleData, (size_t)samplesRead);
+ ma_dr_wav_mulaw_to_s16(pBufferOut, sampleData, (size_t)samplesRead);
+ #ifdef MA_DR_WAV_LIBSNDFILE_COMPAT
+ {
+ if (pWav->container == ma_dr_wav_container_aiff) {
+ ma_uint64 iSample;
+ for (iSample = 0; iSample < samplesRead; iSample += 1) {
+ pBufferOut[iSample] = -pBufferOut[iSample];
+ }
+ }
+ }
+ #endif
pBufferOut += samplesRead;
framesToRead -= framesRead;
totalFramesRead += framesRead;
}
return totalFramesRead;
}
-DRWAV_API drwav_uint64 drwav_read_pcm_frames_s16(drwav* pWav, drwav_uint64 framesToRead, drwav_int16* pBufferOut)
+MA_API ma_uint64 ma_dr_wav_read_pcm_frames_s16(ma_dr_wav* pWav, ma_uint64 framesToRead, ma_int16* pBufferOut)
{
if (pWav == NULL || framesToRead == 0) {
return 0;
}
if (pBufferOut == NULL) {
- return drwav_read_pcm_frames(pWav, framesToRead, NULL);
+ return ma_dr_wav_read_pcm_frames(pWav, framesToRead, NULL);
}
- if (framesToRead * pWav->channels * sizeof(drwav_int16) > DRWAV_SIZE_MAX) {
- framesToRead = DRWAV_SIZE_MAX / sizeof(drwav_int16) / pWav->channels;
+ if (framesToRead * pWav->channels * sizeof(ma_int16) > MA_SIZE_MAX) {
+ framesToRead = MA_SIZE_MAX / sizeof(ma_int16) / pWav->channels;
}
- if (pWav->translatedFormatTag == DR_WAVE_FORMAT_PCM) {
- return drwav_read_pcm_frames_s16__pcm(pWav, framesToRead, pBufferOut);
+ if (pWav->translatedFormatTag == MA_DR_WAVE_FORMAT_PCM) {
+ return ma_dr_wav_read_pcm_frames_s16__pcm(pWav, framesToRead, pBufferOut);
}
- if (pWav->translatedFormatTag == DR_WAVE_FORMAT_IEEE_FLOAT) {
- return drwav_read_pcm_frames_s16__ieee(pWav, framesToRead, pBufferOut);
+ if (pWav->translatedFormatTag == MA_DR_WAVE_FORMAT_IEEE_FLOAT) {
+ return ma_dr_wav_read_pcm_frames_s16__ieee(pWav, framesToRead, pBufferOut);
}
- if (pWav->translatedFormatTag == DR_WAVE_FORMAT_ALAW) {
- return drwav_read_pcm_frames_s16__alaw(pWav, framesToRead, pBufferOut);
+ if (pWav->translatedFormatTag == MA_DR_WAVE_FORMAT_ALAW) {
+ return ma_dr_wav_read_pcm_frames_s16__alaw(pWav, framesToRead, pBufferOut);
}
- if (pWav->translatedFormatTag == DR_WAVE_FORMAT_MULAW) {
- return drwav_read_pcm_frames_s16__mulaw(pWav, framesToRead, pBufferOut);
+ if (pWav->translatedFormatTag == MA_DR_WAVE_FORMAT_MULAW) {
+ return ma_dr_wav_read_pcm_frames_s16__mulaw(pWav, framesToRead, pBufferOut);
}
- if (pWav->translatedFormatTag == DR_WAVE_FORMAT_ADPCM) {
- return drwav_read_pcm_frames_s16__msadpcm(pWav, framesToRead, pBufferOut);
+ if (pWav->translatedFormatTag == MA_DR_WAVE_FORMAT_ADPCM) {
+ return ma_dr_wav_read_pcm_frames_s16__msadpcm(pWav, framesToRead, pBufferOut);
}
- if (pWav->translatedFormatTag == DR_WAVE_FORMAT_DVI_ADPCM) {
- return drwav_read_pcm_frames_s16__ima(pWav, framesToRead, pBufferOut);
+ if (pWav->translatedFormatTag == MA_DR_WAVE_FORMAT_DVI_ADPCM) {
+ return ma_dr_wav_read_pcm_frames_s16__ima(pWav, framesToRead, pBufferOut);
}
return 0;
}
-DRWAV_API drwav_uint64 drwav_read_pcm_frames_s16le(drwav* pWav, drwav_uint64 framesToRead, drwav_int16* pBufferOut)
+MA_API ma_uint64 ma_dr_wav_read_pcm_frames_s16le(ma_dr_wav* pWav, ma_uint64 framesToRead, ma_int16* pBufferOut)
{
- drwav_uint64 framesRead = drwav_read_pcm_frames_s16(pWav, framesToRead, pBufferOut);
- if (pBufferOut != NULL && drwav__is_little_endian() == DRWAV_FALSE) {
- drwav__bswap_samples_s16(pBufferOut, framesRead*pWav->channels);
+ ma_uint64 framesRead = ma_dr_wav_read_pcm_frames_s16(pWav, framesToRead, pBufferOut);
+ if (pBufferOut != NULL && ma_dr_wav__is_little_endian() == MA_FALSE) {
+ ma_dr_wav__bswap_samples_s16(pBufferOut, framesRead*pWav->channels);
}
return framesRead;
}
-DRWAV_API drwav_uint64 drwav_read_pcm_frames_s16be(drwav* pWav, drwav_uint64 framesToRead, drwav_int16* pBufferOut)
+MA_API ma_uint64 ma_dr_wav_read_pcm_frames_s16be(ma_dr_wav* pWav, ma_uint64 framesToRead, ma_int16* pBufferOut)
{
- drwav_uint64 framesRead = drwav_read_pcm_frames_s16(pWav, framesToRead, pBufferOut);
- if (pBufferOut != NULL && drwav__is_little_endian() == DRWAV_TRUE) {
- drwav__bswap_samples_s16(pBufferOut, framesRead*pWav->channels);
+ ma_uint64 framesRead = ma_dr_wav_read_pcm_frames_s16(pWav, framesToRead, pBufferOut);
+ if (pBufferOut != NULL && ma_dr_wav__is_little_endian() == MA_TRUE) {
+ ma_dr_wav__bswap_samples_s16(pBufferOut, framesRead*pWav->channels);
}
return framesRead;
}
-DRWAV_API void drwav_u8_to_s16(drwav_int16* pOut, const drwav_uint8* pIn, size_t sampleCount)
+MA_API void ma_dr_wav_u8_to_s16(ma_int16* pOut, const ma_uint8* pIn, size_t sampleCount)
{
int r;
size_t i;
@@ -78433,17 +80906,17 @@ DRWAV_API void drwav_u8_to_s16(drwav_int16* pOut, const drwav_uint8* pIn, size_t
pOut[i] = (short)r;
}
}
-DRWAV_API void drwav_s24_to_s16(drwav_int16* pOut, const drwav_uint8* pIn, size_t sampleCount)
+MA_API void ma_dr_wav_s24_to_s16(ma_int16* pOut, const ma_uint8* pIn, size_t sampleCount)
{
int r;
size_t i;
for (i = 0; i < sampleCount; ++i) {
- int x = ((int)(((unsigned int)(((const drwav_uint8*)pIn)[i*3+0]) << 8) | ((unsigned int)(((const drwav_uint8*)pIn)[i*3+1]) << 16) | ((unsigned int)(((const drwav_uint8*)pIn)[i*3+2])) << 24)) >> 8;
+ int x = ((int)(((unsigned int)(((const ma_uint8*)pIn)[i*3+0]) << 8) | ((unsigned int)(((const ma_uint8*)pIn)[i*3+1]) << 16) | ((unsigned int)(((const ma_uint8*)pIn)[i*3+2])) << 24)) >> 8;
r = x >> 8;
pOut[i] = (short)r;
}
}
-DRWAV_API void drwav_s32_to_s16(drwav_int16* pOut, const drwav_int32* pIn, size_t sampleCount)
+MA_API void ma_dr_wav_s32_to_s16(ma_int16* pOut, const ma_int32* pIn, size_t sampleCount)
{
int r;
size_t i;
@@ -78453,7 +80926,7 @@ DRWAV_API void drwav_s32_to_s16(drwav_int16* pOut, const drwav_int32* pIn, size_
pOut[i] = (short)r;
}
}
-DRWAV_API void drwav_f32_to_s16(drwav_int16* pOut, const float* pIn, size_t sampleCount)
+MA_API void ma_dr_wav_f32_to_s16(ma_int16* pOut, const float* pIn, size_t sampleCount)
{
int r;
size_t i;
@@ -78467,7 +80940,7 @@ DRWAV_API void drwav_f32_to_s16(drwav_int16* pOut, const float* pIn, size_t samp
pOut[i] = (short)r;
}
}
-DRWAV_API void drwav_f64_to_s16(drwav_int16* pOut, const double* pIn, size_t sampleCount)
+MA_API void ma_dr_wav_f64_to_s16(ma_int16* pOut, const double* pIn, size_t sampleCount)
{
int r;
size_t i;
@@ -78481,57 +80954,57 @@ DRWAV_API void drwav_f64_to_s16(drwav_int16* pOut, const double* pIn, size_t sam
pOut[i] = (short)r;
}
}
-DRWAV_API void drwav_alaw_to_s16(drwav_int16* pOut, const drwav_uint8* pIn, size_t sampleCount)
+MA_API void ma_dr_wav_alaw_to_s16(ma_int16* pOut, const ma_uint8* pIn, size_t sampleCount)
{
size_t i;
for (i = 0; i < sampleCount; ++i) {
- pOut[i] = drwav__alaw_to_s16(pIn[i]);
+ pOut[i] = ma_dr_wav__alaw_to_s16(pIn[i]);
}
}
-DRWAV_API void drwav_mulaw_to_s16(drwav_int16* pOut, const drwav_uint8* pIn, size_t sampleCount)
+MA_API void ma_dr_wav_mulaw_to_s16(ma_int16* pOut, const ma_uint8* pIn, size_t sampleCount)
{
size_t i;
for (i = 0; i < sampleCount; ++i) {
- pOut[i] = drwav__mulaw_to_s16(pIn[i]);
+ pOut[i] = ma_dr_wav__mulaw_to_s16(pIn[i]);
}
}
-DRWAV_PRIVATE void drwav__pcm_to_f32(float* pOut, const drwav_uint8* pIn, size_t sampleCount, unsigned int bytesPerSample)
+MA_PRIVATE void ma_dr_wav__pcm_to_f32(float* pOut, const ma_uint8* pIn, size_t sampleCount, unsigned int bytesPerSample)
{
unsigned int i;
if (bytesPerSample == 1) {
- drwav_u8_to_f32(pOut, pIn, sampleCount);
+ ma_dr_wav_u8_to_f32(pOut, pIn, sampleCount);
return;
}
if (bytesPerSample == 2) {
- drwav_s16_to_f32(pOut, (const drwav_int16*)pIn, sampleCount);
+ ma_dr_wav_s16_to_f32(pOut, (const ma_int16*)pIn, sampleCount);
return;
}
if (bytesPerSample == 3) {
- drwav_s24_to_f32(pOut, pIn, sampleCount);
+ ma_dr_wav_s24_to_f32(pOut, pIn, sampleCount);
return;
}
if (bytesPerSample == 4) {
- drwav_s32_to_f32(pOut, (const drwav_int32*)pIn, sampleCount);
+ ma_dr_wav_s32_to_f32(pOut, (const ma_int32*)pIn, sampleCount);
return;
}
if (bytesPerSample > 8) {
- DRWAV_ZERO_MEMORY(pOut, sampleCount * sizeof(*pOut));
+ MA_DR_WAV_ZERO_MEMORY(pOut, sampleCount * sizeof(*pOut));
return;
}
for (i = 0; i < sampleCount; ++i) {
- drwav_uint64 sample = 0;
+ ma_uint64 sample = 0;
unsigned int shift = (8 - bytesPerSample) * 8;
unsigned int j;
for (j = 0; j < bytesPerSample; j += 1) {
- DRWAV_ASSERT(j < 8);
- sample |= (drwav_uint64)(pIn[j]) << shift;
+ MA_DR_WAV_ASSERT(j < 8);
+ sample |= (ma_uint64)(pIn[j]) << shift;
shift += 8;
}
pIn += j;
- *pOut++ = (float)((drwav_int64)sample / 9223372036854775807.0);
+ *pOut++ = (float)((ma_int64)sample / 9223372036854775807.0);
}
}
-DRWAV_PRIVATE void drwav__ieee_to_f32(float* pOut, const drwav_uint8* pIn, size_t sampleCount, unsigned int bytesPerSample)
+MA_PRIVATE void ma_dr_wav__ieee_to_f32(float* pOut, const ma_uint8* pIn, size_t sampleCount, unsigned int bytesPerSample)
{
if (bytesPerSample == 4) {
unsigned int i;
@@ -78540,21 +81013,21 @@ DRWAV_PRIVATE void drwav__ieee_to_f32(float* pOut, const drwav_uint8* pIn, size_
}
return;
} else if (bytesPerSample == 8) {
- drwav_f64_to_f32(pOut, (const double*)pIn, sampleCount);
+ ma_dr_wav_f64_to_f32(pOut, (const double*)pIn, sampleCount);
return;
} else {
- DRWAV_ZERO_MEMORY(pOut, sampleCount * sizeof(*pOut));
+ MA_DR_WAV_ZERO_MEMORY(pOut, sampleCount * sizeof(*pOut));
return;
}
}
-DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_f32__pcm(drwav* pWav, drwav_uint64 framesToRead, float* pBufferOut)
+MA_PRIVATE ma_uint64 ma_dr_wav_read_pcm_frames_f32__pcm(ma_dr_wav* pWav, ma_uint64 framesToRead, float* pBufferOut)
{
- drwav_uint64 totalFramesRead;
- drwav_uint8 sampleData[4096] = {0};
- drwav_uint32 bytesPerFrame;
- drwav_uint32 bytesPerSample;
- drwav_uint64 samplesRead;
- bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
+ ma_uint64 totalFramesRead;
+ ma_uint8 sampleData[4096] = {0};
+ ma_uint32 bytesPerFrame;
+ ma_uint32 bytesPerSample;
+ ma_uint64 samplesRead;
+ bytesPerFrame = ma_dr_wav_get_bytes_per_pcm_frame(pWav);
if (bytesPerFrame == 0) {
return 0;
}
@@ -78564,54 +81037,89 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_f32__pcm(drwav* pWav, drwav_uin
}
totalFramesRead = 0;
while (framesToRead > 0) {
- drwav_uint64 framesToReadThisIteration = drwav_min(framesToRead, sizeof(sampleData)/bytesPerFrame);
- drwav_uint64 framesRead = drwav_read_pcm_frames(pWav, framesToReadThisIteration, sampleData);
+ ma_uint64 framesToReadThisIteration = ma_dr_wav_min(framesToRead, sizeof(sampleData)/bytesPerFrame);
+ ma_uint64 framesRead = ma_dr_wav_read_pcm_frames(pWav, framesToReadThisIteration, sampleData);
if (framesRead == 0) {
break;
}
- DRWAV_ASSERT(framesRead <= framesToReadThisIteration);
+ MA_DR_WAV_ASSERT(framesRead <= framesToReadThisIteration);
samplesRead = framesRead * pWav->channels;
if ((samplesRead * bytesPerSample) > sizeof(sampleData)) {
- DRWAV_ASSERT(DRWAV_FALSE);
+ MA_DR_WAV_ASSERT(MA_FALSE);
break;
}
- drwav__pcm_to_f32(pBufferOut, sampleData, (size_t)samplesRead, bytesPerSample);
+ ma_dr_wav__pcm_to_f32(pBufferOut, sampleData, (size_t)samplesRead, bytesPerSample);
pBufferOut += samplesRead;
framesToRead -= framesRead;
totalFramesRead += framesRead;
}
return totalFramesRead;
}
-DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_f32__msadpcm_ima(drwav* pWav, drwav_uint64 framesToRead, float* pBufferOut)
+MA_PRIVATE ma_uint64 ma_dr_wav_read_pcm_frames_f32__msadpcm_ima(ma_dr_wav* pWav, ma_uint64 framesToRead, float* pBufferOut)
{
- drwav_uint64 totalFramesRead;
- drwav_int16 samples16[2048];
+ ma_uint64 totalFramesRead;
+ ma_int16 samples16[2048];
totalFramesRead = 0;
while (framesToRead > 0) {
- drwav_uint64 framesToReadThisIteration = drwav_min(framesToRead, drwav_countof(samples16)/pWav->channels);
- drwav_uint64 framesRead = drwav_read_pcm_frames_s16(pWav, framesToReadThisIteration, samples16);
+ ma_uint64 framesToReadThisIteration = ma_dr_wav_min(framesToRead, ma_dr_wav_countof(samples16)/pWav->channels);
+ ma_uint64 framesRead = ma_dr_wav_read_pcm_frames_s16(pWav, framesToReadThisIteration, samples16);
if (framesRead == 0) {
break;
}
- DRWAV_ASSERT(framesRead <= framesToReadThisIteration);
- drwav_s16_to_f32(pBufferOut, samples16, (size_t)(framesRead*pWav->channels));
+ MA_DR_WAV_ASSERT(framesRead <= framesToReadThisIteration);
+ ma_dr_wav_s16_to_f32(pBufferOut, samples16, (size_t)(framesRead*pWav->channels));
pBufferOut += framesRead*pWav->channels;
framesToRead -= framesRead;
totalFramesRead += framesRead;
}
return totalFramesRead;
}
-DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_f32__ieee(drwav* pWav, drwav_uint64 framesToRead, float* pBufferOut)
+MA_PRIVATE ma_uint64 ma_dr_wav_read_pcm_frames_f32__ieee(ma_dr_wav* pWav, ma_uint64 framesToRead, float* pBufferOut)
{
- drwav_uint64 totalFramesRead;
- drwav_uint8 sampleData[4096] = {0};
- drwav_uint32 bytesPerFrame;
- drwav_uint32 bytesPerSample;
- drwav_uint64 samplesRead;
- if (pWav->translatedFormatTag == DR_WAVE_FORMAT_IEEE_FLOAT && pWav->bitsPerSample == 32) {
- return drwav_read_pcm_frames(pWav, framesToRead, pBufferOut);
+ ma_uint64 totalFramesRead;
+ ma_uint8 sampleData[4096] = {0};
+ ma_uint32 bytesPerFrame;
+ ma_uint32 bytesPerSample;
+ ma_uint64 samplesRead;
+ if (pWav->translatedFormatTag == MA_DR_WAVE_FORMAT_IEEE_FLOAT && pWav->bitsPerSample == 32) {
+ return ma_dr_wav_read_pcm_frames(pWav, framesToRead, pBufferOut);
+ }
+ bytesPerFrame = ma_dr_wav_get_bytes_per_pcm_frame(pWav);
+ if (bytesPerFrame == 0) {
+ return 0;
+ }
+ bytesPerSample = bytesPerFrame / pWav->channels;
+ if (bytesPerSample == 0 || (bytesPerFrame % pWav->channels) != 0) {
+ return 0;
}
- bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
+ totalFramesRead = 0;
+ while (framesToRead > 0) {
+ ma_uint64 framesToReadThisIteration = ma_dr_wav_min(framesToRead, sizeof(sampleData)/bytesPerFrame);
+ ma_uint64 framesRead = ma_dr_wav_read_pcm_frames(pWav, framesToReadThisIteration, sampleData);
+ if (framesRead == 0) {
+ break;
+ }
+ MA_DR_WAV_ASSERT(framesRead <= framesToReadThisIteration);
+ samplesRead = framesRead * pWav->channels;
+ if ((samplesRead * bytesPerSample) > sizeof(sampleData)) {
+ MA_DR_WAV_ASSERT(MA_FALSE);
+ break;
+ }
+ ma_dr_wav__ieee_to_f32(pBufferOut, sampleData, (size_t)samplesRead, bytesPerSample);
+ pBufferOut += samplesRead;
+ framesToRead -= framesRead;
+ totalFramesRead += framesRead;
+ }
+ return totalFramesRead;
+}
+MA_PRIVATE ma_uint64 ma_dr_wav_read_pcm_frames_f32__alaw(ma_dr_wav* pWav, ma_uint64 framesToRead, float* pBufferOut)
+{
+ ma_uint64 totalFramesRead;
+ ma_uint8 sampleData[4096] = {0};
+ ma_uint32 bytesPerFrame;
+ ma_uint32 bytesPerSample;
+ ma_uint64 samplesRead;
+ bytesPerFrame = ma_dr_wav_get_bytes_per_pcm_frame(pWav);
if (bytesPerFrame == 0) {
return 0;
}
@@ -78621,32 +81129,42 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_f32__ieee(drwav* pWav, drwav_ui
}
totalFramesRead = 0;
while (framesToRead > 0) {
- drwav_uint64 framesToReadThisIteration = drwav_min(framesToRead, sizeof(sampleData)/bytesPerFrame);
- drwav_uint64 framesRead = drwav_read_pcm_frames(pWav, framesToReadThisIteration, sampleData);
+ ma_uint64 framesToReadThisIteration = ma_dr_wav_min(framesToRead, sizeof(sampleData)/bytesPerFrame);
+ ma_uint64 framesRead = ma_dr_wav_read_pcm_frames(pWav, framesToReadThisIteration, sampleData);
if (framesRead == 0) {
break;
}
- DRWAV_ASSERT(framesRead <= framesToReadThisIteration);
+ MA_DR_WAV_ASSERT(framesRead <= framesToReadThisIteration);
samplesRead = framesRead * pWav->channels;
if ((samplesRead * bytesPerSample) > sizeof(sampleData)) {
- DRWAV_ASSERT(DRWAV_FALSE);
+ MA_DR_WAV_ASSERT(MA_FALSE);
break;
}
- drwav__ieee_to_f32(pBufferOut, sampleData, (size_t)samplesRead, bytesPerSample);
+ ma_dr_wav_alaw_to_f32(pBufferOut, sampleData, (size_t)samplesRead);
+ #ifdef MA_DR_WAV_LIBSNDFILE_COMPAT
+ {
+ if (pWav->container == ma_dr_wav_container_aiff) {
+ ma_uint64 iSample;
+ for (iSample = 0; iSample < samplesRead; iSample += 1) {
+ pBufferOut[iSample] = -pBufferOut[iSample];
+ }
+ }
+ }
+ #endif
pBufferOut += samplesRead;
framesToRead -= framesRead;
totalFramesRead += framesRead;
}
return totalFramesRead;
}
-DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_f32__alaw(drwav* pWav, drwav_uint64 framesToRead, float* pBufferOut)
+MA_PRIVATE ma_uint64 ma_dr_wav_read_pcm_frames_f32__mulaw(ma_dr_wav* pWav, ma_uint64 framesToRead, float* pBufferOut)
{
- drwav_uint64 totalFramesRead;
- drwav_uint8 sampleData[4096] = {0};
- drwav_uint32 bytesPerFrame;
- drwav_uint32 bytesPerSample;
- drwav_uint64 samplesRead;
- bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
+ ma_uint64 totalFramesRead;
+ ma_uint8 sampleData[4096] = {0};
+ ma_uint32 bytesPerFrame;
+ ma_uint32 bytesPerSample;
+ ma_uint64 samplesRead;
+ bytesPerFrame = ma_dr_wav_get_bytes_per_pcm_frame(pWav);
if (bytesPerFrame == 0) {
return 0;
}
@@ -78656,32 +81174,277 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_f32__alaw(drwav* pWav, drwav_ui
}
totalFramesRead = 0;
while (framesToRead > 0) {
- drwav_uint64 framesToReadThisIteration = drwav_min(framesToRead, sizeof(sampleData)/bytesPerFrame);
- drwav_uint64 framesRead = drwav_read_pcm_frames(pWav, framesToReadThisIteration, sampleData);
+ ma_uint64 framesToReadThisIteration = ma_dr_wav_min(framesToRead, sizeof(sampleData)/bytesPerFrame);
+ ma_uint64 framesRead = ma_dr_wav_read_pcm_frames(pWav, framesToReadThisIteration, sampleData);
if (framesRead == 0) {
break;
}
- DRWAV_ASSERT(framesRead <= framesToReadThisIteration);
+ MA_DR_WAV_ASSERT(framesRead <= framesToReadThisIteration);
samplesRead = framesRead * pWav->channels;
if ((samplesRead * bytesPerSample) > sizeof(sampleData)) {
- DRWAV_ASSERT(DRWAV_FALSE);
+ MA_DR_WAV_ASSERT(MA_FALSE);
break;
}
- drwav_alaw_to_f32(pBufferOut, sampleData, (size_t)samplesRead);
+ ma_dr_wav_mulaw_to_f32(pBufferOut, sampleData, (size_t)samplesRead);
+ #ifdef MA_DR_WAV_LIBSNDFILE_COMPAT
+ {
+ if (pWav->container == ma_dr_wav_container_aiff) {
+ ma_uint64 iSample;
+ for (iSample = 0; iSample < samplesRead; iSample += 1) {
+ pBufferOut[iSample] = -pBufferOut[iSample];
+ }
+ }
+ }
+ #endif
pBufferOut += samplesRead;
framesToRead -= framesRead;
totalFramesRead += framesRead;
}
return totalFramesRead;
}
-DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_f32__mulaw(drwav* pWav, drwav_uint64 framesToRead, float* pBufferOut)
+MA_API ma_uint64 ma_dr_wav_read_pcm_frames_f32(ma_dr_wav* pWav, ma_uint64 framesToRead, float* pBufferOut)
+{
+ if (pWav == NULL || framesToRead == 0) {
+ return 0;
+ }
+ if (pBufferOut == NULL) {
+ return ma_dr_wav_read_pcm_frames(pWav, framesToRead, NULL);
+ }
+ if (framesToRead * pWav->channels * sizeof(float) > MA_SIZE_MAX) {
+ framesToRead = MA_SIZE_MAX / sizeof(float) / pWav->channels;
+ }
+ if (pWav->translatedFormatTag == MA_DR_WAVE_FORMAT_PCM) {
+ return ma_dr_wav_read_pcm_frames_f32__pcm(pWav, framesToRead, pBufferOut);
+ }
+ if (pWav->translatedFormatTag == MA_DR_WAVE_FORMAT_ADPCM || pWav->translatedFormatTag == MA_DR_WAVE_FORMAT_DVI_ADPCM) {
+ return ma_dr_wav_read_pcm_frames_f32__msadpcm_ima(pWav, framesToRead, pBufferOut);
+ }
+ if (pWav->translatedFormatTag == MA_DR_WAVE_FORMAT_IEEE_FLOAT) {
+ return ma_dr_wav_read_pcm_frames_f32__ieee(pWav, framesToRead, pBufferOut);
+ }
+ if (pWav->translatedFormatTag == MA_DR_WAVE_FORMAT_ALAW) {
+ return ma_dr_wav_read_pcm_frames_f32__alaw(pWav, framesToRead, pBufferOut);
+ }
+ if (pWav->translatedFormatTag == MA_DR_WAVE_FORMAT_MULAW) {
+ return ma_dr_wav_read_pcm_frames_f32__mulaw(pWav, framesToRead, pBufferOut);
+ }
+ return 0;
+}
+MA_API ma_uint64 ma_dr_wav_read_pcm_frames_f32le(ma_dr_wav* pWav, ma_uint64 framesToRead, float* pBufferOut)
+{
+ ma_uint64 framesRead = ma_dr_wav_read_pcm_frames_f32(pWav, framesToRead, pBufferOut);
+ if (pBufferOut != NULL && ma_dr_wav__is_little_endian() == MA_FALSE) {
+ ma_dr_wav__bswap_samples_f32(pBufferOut, framesRead*pWav->channels);
+ }
+ return framesRead;
+}
+MA_API ma_uint64 ma_dr_wav_read_pcm_frames_f32be(ma_dr_wav* pWav, ma_uint64 framesToRead, float* pBufferOut)
{
- drwav_uint64 totalFramesRead;
- drwav_uint8 sampleData[4096] = {0};
- drwav_uint32 bytesPerFrame;
- drwav_uint32 bytesPerSample;
- drwav_uint64 samplesRead;
- bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
+ ma_uint64 framesRead = ma_dr_wav_read_pcm_frames_f32(pWav, framesToRead, pBufferOut);
+ if (pBufferOut != NULL && ma_dr_wav__is_little_endian() == MA_TRUE) {
+ ma_dr_wav__bswap_samples_f32(pBufferOut, framesRead*pWav->channels);
+ }
+ return framesRead;
+}
+MA_API void ma_dr_wav_u8_to_f32(float* pOut, const ma_uint8* pIn, size_t sampleCount)
+{
+ size_t i;
+ if (pOut == NULL || pIn == NULL) {
+ return;
+ }
+#ifdef MA_DR_WAV_LIBSNDFILE_COMPAT
+ for (i = 0; i < sampleCount; ++i) {
+ *pOut++ = (pIn[i] / 256.0f) * 2 - 1;
+ }
+#else
+ for (i = 0; i < sampleCount; ++i) {
+ float x = pIn[i];
+ x = x * 0.00784313725490196078f;
+ x = x - 1;
+ *pOut++ = x;
+ }
+#endif
+}
+MA_API void ma_dr_wav_s16_to_f32(float* pOut, const ma_int16* pIn, size_t sampleCount)
+{
+ size_t i;
+ if (pOut == NULL || pIn == NULL) {
+ return;
+ }
+ for (i = 0; i < sampleCount; ++i) {
+ *pOut++ = pIn[i] * 0.000030517578125f;
+ }
+}
+MA_API void ma_dr_wav_s24_to_f32(float* pOut, const ma_uint8* pIn, size_t sampleCount)
+{
+ size_t i;
+ if (pOut == NULL || pIn == NULL) {
+ return;
+ }
+ for (i = 0; i < sampleCount; ++i) {
+ double x;
+ ma_uint32 a = ((ma_uint32)(pIn[i*3+0]) << 8);
+ ma_uint32 b = ((ma_uint32)(pIn[i*3+1]) << 16);
+ ma_uint32 c = ((ma_uint32)(pIn[i*3+2]) << 24);
+ x = (double)((ma_int32)(a | b | c) >> 8);
+ *pOut++ = (float)(x * 0.00000011920928955078125);
+ }
+}
+MA_API void ma_dr_wav_s32_to_f32(float* pOut, const ma_int32* pIn, size_t sampleCount)
+{
+ size_t i;
+ if (pOut == NULL || pIn == NULL) {
+ return;
+ }
+ for (i = 0; i < sampleCount; ++i) {
+ *pOut++ = (float)(pIn[i] / 2147483648.0);
+ }
+}
+MA_API void ma_dr_wav_f64_to_f32(float* pOut, const double* pIn, size_t sampleCount)
+{
+ size_t i;
+ if (pOut == NULL || pIn == NULL) {
+ return;
+ }
+ for (i = 0; i < sampleCount; ++i) {
+ *pOut++ = (float)pIn[i];
+ }
+}
+MA_API void ma_dr_wav_alaw_to_f32(float* pOut, const ma_uint8* pIn, size_t sampleCount)
+{
+ size_t i;
+ if (pOut == NULL || pIn == NULL) {
+ return;
+ }
+ for (i = 0; i < sampleCount; ++i) {
+ *pOut++ = ma_dr_wav__alaw_to_s16(pIn[i]) / 32768.0f;
+ }
+}
+MA_API void ma_dr_wav_mulaw_to_f32(float* pOut, const ma_uint8* pIn, size_t sampleCount)
+{
+ size_t i;
+ if (pOut == NULL || pIn == NULL) {
+ return;
+ }
+ for (i = 0; i < sampleCount; ++i) {
+ *pOut++ = ma_dr_wav__mulaw_to_s16(pIn[i]) / 32768.0f;
+ }
+}
+MA_PRIVATE void ma_dr_wav__pcm_to_s32(ma_int32* pOut, const ma_uint8* pIn, size_t totalSampleCount, unsigned int bytesPerSample)
+{
+ unsigned int i;
+ if (bytesPerSample == 1) {
+ ma_dr_wav_u8_to_s32(pOut, pIn, totalSampleCount);
+ return;
+ }
+ if (bytesPerSample == 2) {
+ ma_dr_wav_s16_to_s32(pOut, (const ma_int16*)pIn, totalSampleCount);
+ return;
+ }
+ if (bytesPerSample == 3) {
+ ma_dr_wav_s24_to_s32(pOut, pIn, totalSampleCount);
+ return;
+ }
+ if (bytesPerSample == 4) {
+ for (i = 0; i < totalSampleCount; ++i) {
+ *pOut++ = ((const ma_int32*)pIn)[i];
+ }
+ return;
+ }
+ if (bytesPerSample > 8) {
+ MA_DR_WAV_ZERO_MEMORY(pOut, totalSampleCount * sizeof(*pOut));
+ return;
+ }
+ for (i = 0; i < totalSampleCount; ++i) {
+ ma_uint64 sample = 0;
+ unsigned int shift = (8 - bytesPerSample) * 8;
+ unsigned int j;
+ for (j = 0; j < bytesPerSample; j += 1) {
+ MA_DR_WAV_ASSERT(j < 8);
+ sample |= (ma_uint64)(pIn[j]) << shift;
+ shift += 8;
+ }
+ pIn += j;
+ *pOut++ = (ma_int32)((ma_int64)sample >> 32);
+ }
+}
+MA_PRIVATE void ma_dr_wav__ieee_to_s32(ma_int32* pOut, const ma_uint8* pIn, size_t totalSampleCount, unsigned int bytesPerSample)
+{
+ if (bytesPerSample == 4) {
+ ma_dr_wav_f32_to_s32(pOut, (const float*)pIn, totalSampleCount);
+ return;
+ } else if (bytesPerSample == 8) {
+ ma_dr_wav_f64_to_s32(pOut, (const double*)pIn, totalSampleCount);
+ return;
+ } else {
+ MA_DR_WAV_ZERO_MEMORY(pOut, totalSampleCount * sizeof(*pOut));
+ return;
+ }
+}
+MA_PRIVATE ma_uint64 ma_dr_wav_read_pcm_frames_s32__pcm(ma_dr_wav* pWav, ma_uint64 framesToRead, ma_int32* pBufferOut)
+{
+ ma_uint64 totalFramesRead;
+ ma_uint8 sampleData[4096] = {0};
+ ma_uint32 bytesPerFrame;
+ ma_uint32 bytesPerSample;
+ ma_uint64 samplesRead;
+ if (pWav->translatedFormatTag == MA_DR_WAVE_FORMAT_PCM && pWav->bitsPerSample == 32) {
+ return ma_dr_wav_read_pcm_frames(pWav, framesToRead, pBufferOut);
+ }
+ bytesPerFrame = ma_dr_wav_get_bytes_per_pcm_frame(pWav);
+ if (bytesPerFrame == 0) {
+ return 0;
+ }
+ bytesPerSample = bytesPerFrame / pWav->channels;
+ if (bytesPerSample == 0 || (bytesPerFrame % pWav->channels) != 0) {
+ return 0;
+ }
+ totalFramesRead = 0;
+ while (framesToRead > 0) {
+ ma_uint64 framesToReadThisIteration = ma_dr_wav_min(framesToRead, sizeof(sampleData)/bytesPerFrame);
+ ma_uint64 framesRead = ma_dr_wav_read_pcm_frames(pWav, framesToReadThisIteration, sampleData);
+ if (framesRead == 0) {
+ break;
+ }
+ MA_DR_WAV_ASSERT(framesRead <= framesToReadThisIteration);
+ samplesRead = framesRead * pWav->channels;
+ if ((samplesRead * bytesPerSample) > sizeof(sampleData)) {
+ MA_DR_WAV_ASSERT(MA_FALSE);
+ break;
+ }
+ ma_dr_wav__pcm_to_s32(pBufferOut, sampleData, (size_t)samplesRead, bytesPerSample);
+ pBufferOut += samplesRead;
+ framesToRead -= framesRead;
+ totalFramesRead += framesRead;
+ }
+ return totalFramesRead;
+}
+MA_PRIVATE ma_uint64 ma_dr_wav_read_pcm_frames_s32__msadpcm_ima(ma_dr_wav* pWav, ma_uint64 framesToRead, ma_int32* pBufferOut)
+{
+ ma_uint64 totalFramesRead = 0;
+ ma_int16 samples16[2048];
+ while (framesToRead > 0) {
+ ma_uint64 framesToReadThisIteration = ma_dr_wav_min(framesToRead, ma_dr_wav_countof(samples16)/pWav->channels);
+ ma_uint64 framesRead = ma_dr_wav_read_pcm_frames_s16(pWav, framesToReadThisIteration, samples16);
+ if (framesRead == 0) {
+ break;
+ }
+ MA_DR_WAV_ASSERT(framesRead <= framesToReadThisIteration);
+ ma_dr_wav_s16_to_s32(pBufferOut, samples16, (size_t)(framesRead*pWav->channels));
+ pBufferOut += framesRead*pWav->channels;
+ framesToRead -= framesRead;
+ totalFramesRead += framesRead;
+ }
+ return totalFramesRead;
+}
+MA_PRIVATE ma_uint64 ma_dr_wav_read_pcm_frames_s32__ieee(ma_dr_wav* pWav, ma_uint64 framesToRead, ma_int32* pBufferOut)
+{
+ ma_uint64 totalFramesRead;
+ ma_uint8 sampleData[4096] = {0};
+ ma_uint32 bytesPerFrame;
+ ma_uint32 bytesPerSample;
+ ma_uint64 samplesRead;
+ bytesPerFrame = ma_dr_wav_get_bytes_per_pcm_frame(pWav);
if (bytesPerFrame == 0) {
return 0;
}
@@ -78691,214 +81454,32 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_f32__mulaw(drwav* pWav, drwav_u
}
totalFramesRead = 0;
while (framesToRead > 0) {
- drwav_uint64 framesToReadThisIteration = drwav_min(framesToRead, sizeof(sampleData)/bytesPerFrame);
- drwav_uint64 framesRead = drwav_read_pcm_frames(pWav, framesToReadThisIteration, sampleData);
+ ma_uint64 framesToReadThisIteration = ma_dr_wav_min(framesToRead, sizeof(sampleData)/bytesPerFrame);
+ ma_uint64 framesRead = ma_dr_wav_read_pcm_frames(pWav, framesToReadThisIteration, sampleData);
if (framesRead == 0) {
break;
}
- DRWAV_ASSERT(framesRead <= framesToReadThisIteration);
+ MA_DR_WAV_ASSERT(framesRead <= framesToReadThisIteration);
samplesRead = framesRead * pWav->channels;
if ((samplesRead * bytesPerSample) > sizeof(sampleData)) {
- DRWAV_ASSERT(DRWAV_FALSE);
+ MA_DR_WAV_ASSERT(MA_FALSE);
break;
}
- drwav_mulaw_to_f32(pBufferOut, sampleData, (size_t)samplesRead);
+ ma_dr_wav__ieee_to_s32(pBufferOut, sampleData, (size_t)samplesRead, bytesPerSample);
pBufferOut += samplesRead;
framesToRead -= framesRead;
totalFramesRead += framesRead;
}
return totalFramesRead;
}
-DRWAV_API drwav_uint64 drwav_read_pcm_frames_f32(drwav* pWav, drwav_uint64 framesToRead, float* pBufferOut)
+MA_PRIVATE ma_uint64 ma_dr_wav_read_pcm_frames_s32__alaw(ma_dr_wav* pWav, ma_uint64 framesToRead, ma_int32* pBufferOut)
{
- if (pWav == NULL || framesToRead == 0) {
- return 0;
- }
- if (pBufferOut == NULL) {
- return drwav_read_pcm_frames(pWav, framesToRead, NULL);
- }
- if (framesToRead * pWav->channels * sizeof(float) > DRWAV_SIZE_MAX) {
- framesToRead = DRWAV_SIZE_MAX / sizeof(float) / pWav->channels;
- }
- if (pWav->translatedFormatTag == DR_WAVE_FORMAT_PCM) {
- return drwav_read_pcm_frames_f32__pcm(pWav, framesToRead, pBufferOut);
- }
- if (pWav->translatedFormatTag == DR_WAVE_FORMAT_ADPCM || pWav->translatedFormatTag == DR_WAVE_FORMAT_DVI_ADPCM) {
- return drwav_read_pcm_frames_f32__msadpcm_ima(pWav, framesToRead, pBufferOut);
- }
- if (pWav->translatedFormatTag == DR_WAVE_FORMAT_IEEE_FLOAT) {
- return drwav_read_pcm_frames_f32__ieee(pWav, framesToRead, pBufferOut);
- }
- if (pWav->translatedFormatTag == DR_WAVE_FORMAT_ALAW) {
- return drwav_read_pcm_frames_f32__alaw(pWav, framesToRead, pBufferOut);
- }
- if (pWav->translatedFormatTag == DR_WAVE_FORMAT_MULAW) {
- return drwav_read_pcm_frames_f32__mulaw(pWav, framesToRead, pBufferOut);
- }
- return 0;
-}
-DRWAV_API drwav_uint64 drwav_read_pcm_frames_f32le(drwav* pWav, drwav_uint64 framesToRead, float* pBufferOut)
-{
- drwav_uint64 framesRead = drwav_read_pcm_frames_f32(pWav, framesToRead, pBufferOut);
- if (pBufferOut != NULL && drwav__is_little_endian() == DRWAV_FALSE) {
- drwav__bswap_samples_f32(pBufferOut, framesRead*pWav->channels);
- }
- return framesRead;
-}
-DRWAV_API drwav_uint64 drwav_read_pcm_frames_f32be(drwav* pWav, drwav_uint64 framesToRead, float* pBufferOut)
-{
- drwav_uint64 framesRead = drwav_read_pcm_frames_f32(pWav, framesToRead, pBufferOut);
- if (pBufferOut != NULL && drwav__is_little_endian() == DRWAV_TRUE) {
- drwav__bswap_samples_f32(pBufferOut, framesRead*pWav->channels);
- }
- return framesRead;
-}
-DRWAV_API void drwav_u8_to_f32(float* pOut, const drwav_uint8* pIn, size_t sampleCount)
-{
- size_t i;
- if (pOut == NULL || pIn == NULL) {
- return;
- }
-#ifdef DR_WAV_LIBSNDFILE_COMPAT
- for (i = 0; i < sampleCount; ++i) {
- *pOut++ = (pIn[i] / 256.0f) * 2 - 1;
- }
-#else
- for (i = 0; i < sampleCount; ++i) {
- float x = pIn[i];
- x = x * 0.00784313725490196078f;
- x = x - 1;
- *pOut++ = x;
- }
-#endif
-}
-DRWAV_API void drwav_s16_to_f32(float* pOut, const drwav_int16* pIn, size_t sampleCount)
-{
- size_t i;
- if (pOut == NULL || pIn == NULL) {
- return;
- }
- for (i = 0; i < sampleCount; ++i) {
- *pOut++ = pIn[i] * 0.000030517578125f;
- }
-}
-DRWAV_API void drwav_s24_to_f32(float* pOut, const drwav_uint8* pIn, size_t sampleCount)
-{
- size_t i;
- if (pOut == NULL || pIn == NULL) {
- return;
- }
- for (i = 0; i < sampleCount; ++i) {
- double x;
- drwav_uint32 a = ((drwav_uint32)(pIn[i*3+0]) << 8);
- drwav_uint32 b = ((drwav_uint32)(pIn[i*3+1]) << 16);
- drwav_uint32 c = ((drwav_uint32)(pIn[i*3+2]) << 24);
- x = (double)((drwav_int32)(a | b | c) >> 8);
- *pOut++ = (float)(x * 0.00000011920928955078125);
- }
-}
-DRWAV_API void drwav_s32_to_f32(float* pOut, const drwav_int32* pIn, size_t sampleCount)
-{
- size_t i;
- if (pOut == NULL || pIn == NULL) {
- return;
- }
- for (i = 0; i < sampleCount; ++i) {
- *pOut++ = (float)(pIn[i] / 2147483648.0);
- }
-}
-DRWAV_API void drwav_f64_to_f32(float* pOut, const double* pIn, size_t sampleCount)
-{
- size_t i;
- if (pOut == NULL || pIn == NULL) {
- return;
- }
- for (i = 0; i < sampleCount; ++i) {
- *pOut++ = (float)pIn[i];
- }
-}
-DRWAV_API void drwav_alaw_to_f32(float* pOut, const drwav_uint8* pIn, size_t sampleCount)
-{
- size_t i;
- if (pOut == NULL || pIn == NULL) {
- return;
- }
- for (i = 0; i < sampleCount; ++i) {
- *pOut++ = drwav__alaw_to_s16(pIn[i]) / 32768.0f;
- }
-}
-DRWAV_API void drwav_mulaw_to_f32(float* pOut, const drwav_uint8* pIn, size_t sampleCount)
-{
- size_t i;
- if (pOut == NULL || pIn == NULL) {
- return;
- }
- for (i = 0; i < sampleCount; ++i) {
- *pOut++ = drwav__mulaw_to_s16(pIn[i]) / 32768.0f;
- }
-}
-DRWAV_PRIVATE void drwav__pcm_to_s32(drwav_int32* pOut, const drwav_uint8* pIn, size_t totalSampleCount, unsigned int bytesPerSample)
-{
- unsigned int i;
- if (bytesPerSample == 1) {
- drwav_u8_to_s32(pOut, pIn, totalSampleCount);
- return;
- }
- if (bytesPerSample == 2) {
- drwav_s16_to_s32(pOut, (const drwav_int16*)pIn, totalSampleCount);
- return;
- }
- if (bytesPerSample == 3) {
- drwav_s24_to_s32(pOut, pIn, totalSampleCount);
- return;
- }
- if (bytesPerSample == 4) {
- for (i = 0; i < totalSampleCount; ++i) {
- *pOut++ = ((const drwav_int32*)pIn)[i];
- }
- return;
- }
- if (bytesPerSample > 8) {
- DRWAV_ZERO_MEMORY(pOut, totalSampleCount * sizeof(*pOut));
- return;
- }
- for (i = 0; i < totalSampleCount; ++i) {
- drwav_uint64 sample = 0;
- unsigned int shift = (8 - bytesPerSample) * 8;
- unsigned int j;
- for (j = 0; j < bytesPerSample; j += 1) {
- DRWAV_ASSERT(j < 8);
- sample |= (drwav_uint64)(pIn[j]) << shift;
- shift += 8;
- }
- pIn += j;
- *pOut++ = (drwav_int32)((drwav_int64)sample >> 32);
- }
-}
-DRWAV_PRIVATE void drwav__ieee_to_s32(drwav_int32* pOut, const drwav_uint8* pIn, size_t totalSampleCount, unsigned int bytesPerSample)
-{
- if (bytesPerSample == 4) {
- drwav_f32_to_s32(pOut, (const float*)pIn, totalSampleCount);
- return;
- } else if (bytesPerSample == 8) {
- drwav_f64_to_s32(pOut, (const double*)pIn, totalSampleCount);
- return;
- } else {
- DRWAV_ZERO_MEMORY(pOut, totalSampleCount * sizeof(*pOut));
- return;
- }
-}
-DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s32__pcm(drwav* pWav, drwav_uint64 framesToRead, drwav_int32* pBufferOut)
-{
- drwav_uint64 totalFramesRead;
- drwav_uint8 sampleData[4096] = {0};
- drwav_uint32 bytesPerFrame;
- drwav_uint32 bytesPerSample;
- drwav_uint64 samplesRead;
- if (pWav->translatedFormatTag == DR_WAVE_FORMAT_PCM && pWav->bitsPerSample == 32) {
- return drwav_read_pcm_frames(pWav, framesToRead, pBufferOut);
- }
- bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
+ ma_uint64 totalFramesRead;
+ ma_uint8 sampleData[4096] = {0};
+ ma_uint32 bytesPerFrame;
+ ma_uint32 bytesPerSample;
+ ma_uint64 samplesRead;
+ bytesPerFrame = ma_dr_wav_get_bytes_per_pcm_frame(pWav);
if (bytesPerFrame == 0) {
return 0;
}
@@ -78908,85 +81489,42 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s32__pcm(drwav* pWav, drwav_uin
}
totalFramesRead = 0;
while (framesToRead > 0) {
- drwav_uint64 framesToReadThisIteration = drwav_min(framesToRead, sizeof(sampleData)/bytesPerFrame);
- drwav_uint64 framesRead = drwav_read_pcm_frames(pWav, framesToReadThisIteration, sampleData);
+ ma_uint64 framesToReadThisIteration = ma_dr_wav_min(framesToRead, sizeof(sampleData)/bytesPerFrame);
+ ma_uint64 framesRead = ma_dr_wav_read_pcm_frames(pWav, framesToReadThisIteration, sampleData);
if (framesRead == 0) {
break;
}
- DRWAV_ASSERT(framesRead <= framesToReadThisIteration);
+ MA_DR_WAV_ASSERT(framesRead <= framesToReadThisIteration);
samplesRead = framesRead * pWav->channels;
if ((samplesRead * bytesPerSample) > sizeof(sampleData)) {
- DRWAV_ASSERT(DRWAV_FALSE);
- break;
- }
- drwav__pcm_to_s32(pBufferOut, sampleData, (size_t)samplesRead, bytesPerSample);
- pBufferOut += samplesRead;
- framesToRead -= framesRead;
- totalFramesRead += framesRead;
- }
- return totalFramesRead;
-}
-DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s32__msadpcm_ima(drwav* pWav, drwav_uint64 framesToRead, drwav_int32* pBufferOut)
-{
- drwav_uint64 totalFramesRead = 0;
- drwav_int16 samples16[2048];
- while (framesToRead > 0) {
- drwav_uint64 framesToReadThisIteration = drwav_min(framesToRead, drwav_countof(samples16)/pWav->channels);
- drwav_uint64 framesRead = drwav_read_pcm_frames_s16(pWav, framesToReadThisIteration, samples16);
- if (framesRead == 0) {
+ MA_DR_WAV_ASSERT(MA_FALSE);
break;
}
- DRWAV_ASSERT(framesRead <= framesToReadThisIteration);
- drwav_s16_to_s32(pBufferOut, samples16, (size_t)(framesRead*pWav->channels));
- pBufferOut += framesRead*pWav->channels;
- framesToRead -= framesRead;
- totalFramesRead += framesRead;
- }
- return totalFramesRead;
-}
-DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s32__ieee(drwav* pWav, drwav_uint64 framesToRead, drwav_int32* pBufferOut)
-{
- drwav_uint64 totalFramesRead;
- drwav_uint8 sampleData[4096] = {0};
- drwav_uint32 bytesPerFrame;
- drwav_uint32 bytesPerSample;
- drwav_uint64 samplesRead;
- bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
- if (bytesPerFrame == 0) {
- return 0;
- }
- bytesPerSample = bytesPerFrame / pWav->channels;
- if (bytesPerSample == 0 || (bytesPerFrame % pWav->channels) != 0) {
- return 0;
- }
- totalFramesRead = 0;
- while (framesToRead > 0) {
- drwav_uint64 framesToReadThisIteration = drwav_min(framesToRead, sizeof(sampleData)/bytesPerFrame);
- drwav_uint64 framesRead = drwav_read_pcm_frames(pWav, framesToReadThisIteration, sampleData);
- if (framesRead == 0) {
- break;
- }
- DRWAV_ASSERT(framesRead <= framesToReadThisIteration);
- samplesRead = framesRead * pWav->channels;
- if ((samplesRead * bytesPerSample) > sizeof(sampleData)) {
- DRWAV_ASSERT(DRWAV_FALSE);
- break;
+ ma_dr_wav_alaw_to_s32(pBufferOut, sampleData, (size_t)samplesRead);
+ #ifdef MA_DR_WAV_LIBSNDFILE_COMPAT
+ {
+ if (pWav->container == ma_dr_wav_container_aiff) {
+ ma_uint64 iSample;
+ for (iSample = 0; iSample < samplesRead; iSample += 1) {
+ pBufferOut[iSample] = -pBufferOut[iSample];
+ }
+ }
}
- drwav__ieee_to_s32(pBufferOut, sampleData, (size_t)samplesRead, bytesPerSample);
+ #endif
pBufferOut += samplesRead;
framesToRead -= framesRead;
totalFramesRead += framesRead;
}
return totalFramesRead;
}
-DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s32__alaw(drwav* pWav, drwav_uint64 framesToRead, drwav_int32* pBufferOut)
+MA_PRIVATE ma_uint64 ma_dr_wav_read_pcm_frames_s32__mulaw(ma_dr_wav* pWav, ma_uint64 framesToRead, ma_int32* pBufferOut)
{
- drwav_uint64 totalFramesRead;
- drwav_uint8 sampleData[4096] = {0};
- drwav_uint32 bytesPerFrame;
- drwav_uint32 bytesPerSample;
- drwav_uint64 samplesRead;
- bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
+ ma_uint64 totalFramesRead;
+ ma_uint8 sampleData[4096] = {0};
+ ma_uint32 bytesPerFrame;
+ ma_uint32 bytesPerSample;
+ ma_uint64 samplesRead;
+ bytesPerFrame = ma_dr_wav_get_bytes_per_pcm_frame(pWav);
if (bytesPerFrame == 0) {
return 0;
}
@@ -78996,104 +81534,79 @@ DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s32__alaw(drwav* pWav, drwav_ui
}
totalFramesRead = 0;
while (framesToRead > 0) {
- drwav_uint64 framesToReadThisIteration = drwav_min(framesToRead, sizeof(sampleData)/bytesPerFrame);
- drwav_uint64 framesRead = drwav_read_pcm_frames(pWav, framesToReadThisIteration, sampleData);
+ ma_uint64 framesToReadThisIteration = ma_dr_wav_min(framesToRead, sizeof(sampleData)/bytesPerFrame);
+ ma_uint64 framesRead = ma_dr_wav_read_pcm_frames(pWav, framesToReadThisIteration, sampleData);
if (framesRead == 0) {
break;
}
- DRWAV_ASSERT(framesRead <= framesToReadThisIteration);
+ MA_DR_WAV_ASSERT(framesRead <= framesToReadThisIteration);
samplesRead = framesRead * pWav->channels;
if ((samplesRead * bytesPerSample) > sizeof(sampleData)) {
- DRWAV_ASSERT(DRWAV_FALSE);
- break;
- }
- drwav_alaw_to_s32(pBufferOut, sampleData, (size_t)samplesRead);
- pBufferOut += samplesRead;
- framesToRead -= framesRead;
- totalFramesRead += framesRead;
- }
- return totalFramesRead;
-}
-DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s32__mulaw(drwav* pWav, drwav_uint64 framesToRead, drwav_int32* pBufferOut)
-{
- drwav_uint64 totalFramesRead;
- drwav_uint8 sampleData[4096] = {0};
- drwav_uint32 bytesPerFrame;
- drwav_uint32 bytesPerSample;
- drwav_uint64 samplesRead;
- bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
- if (bytesPerFrame == 0) {
- return 0;
- }
- bytesPerSample = bytesPerFrame / pWav->channels;
- if (bytesPerSample == 0 || (bytesPerFrame % pWav->channels) != 0) {
- return 0;
- }
- totalFramesRead = 0;
- while (framesToRead > 0) {
- drwav_uint64 framesToReadThisIteration = drwav_min(framesToRead, sizeof(sampleData)/bytesPerFrame);
- drwav_uint64 framesRead = drwav_read_pcm_frames(pWav, framesToReadThisIteration, sampleData);
- if (framesRead == 0) {
+ MA_DR_WAV_ASSERT(MA_FALSE);
break;
}
- DRWAV_ASSERT(framesRead <= framesToReadThisIteration);
- samplesRead = framesRead * pWav->channels;
- if ((samplesRead * bytesPerSample) > sizeof(sampleData)) {
- DRWAV_ASSERT(DRWAV_FALSE);
- break;
+ ma_dr_wav_mulaw_to_s32(pBufferOut, sampleData, (size_t)samplesRead);
+ #ifdef MA_DR_WAV_LIBSNDFILE_COMPAT
+ {
+ if (pWav->container == ma_dr_wav_container_aiff) {
+ ma_uint64 iSample;
+ for (iSample = 0; iSample < samplesRead; iSample += 1) {
+ pBufferOut[iSample] = -pBufferOut[iSample];
+ }
+ }
}
- drwav_mulaw_to_s32(pBufferOut, sampleData, (size_t)samplesRead);
+ #endif
pBufferOut += samplesRead;
framesToRead -= framesRead;
totalFramesRead += framesRead;
}
return totalFramesRead;
}
-DRWAV_API drwav_uint64 drwav_read_pcm_frames_s32(drwav* pWav, drwav_uint64 framesToRead, drwav_int32* pBufferOut)
+MA_API ma_uint64 ma_dr_wav_read_pcm_frames_s32(ma_dr_wav* pWav, ma_uint64 framesToRead, ma_int32* pBufferOut)
{
if (pWav == NULL || framesToRead == 0) {
return 0;
}
if (pBufferOut == NULL) {
- return drwav_read_pcm_frames(pWav, framesToRead, NULL);
+ return ma_dr_wav_read_pcm_frames(pWav, framesToRead, NULL);
}
- if (framesToRead * pWav->channels * sizeof(drwav_int32) > DRWAV_SIZE_MAX) {
- framesToRead = DRWAV_SIZE_MAX / sizeof(drwav_int32) / pWav->channels;
+ if (framesToRead * pWav->channels * sizeof(ma_int32) > MA_SIZE_MAX) {
+ framesToRead = MA_SIZE_MAX / sizeof(ma_int32) / pWav->channels;
}
- if (pWav->translatedFormatTag == DR_WAVE_FORMAT_PCM) {
- return drwav_read_pcm_frames_s32__pcm(pWav, framesToRead, pBufferOut);
+ if (pWav->translatedFormatTag == MA_DR_WAVE_FORMAT_PCM) {
+ return ma_dr_wav_read_pcm_frames_s32__pcm(pWav, framesToRead, pBufferOut);
}
- if (pWav->translatedFormatTag == DR_WAVE_FORMAT_ADPCM || pWav->translatedFormatTag == DR_WAVE_FORMAT_DVI_ADPCM) {
- return drwav_read_pcm_frames_s32__msadpcm_ima(pWav, framesToRead, pBufferOut);
+ if (pWav->translatedFormatTag == MA_DR_WAVE_FORMAT_ADPCM || pWav->translatedFormatTag == MA_DR_WAVE_FORMAT_DVI_ADPCM) {
+ return ma_dr_wav_read_pcm_frames_s32__msadpcm_ima(pWav, framesToRead, pBufferOut);
}
- if (pWav->translatedFormatTag == DR_WAVE_FORMAT_IEEE_FLOAT) {
- return drwav_read_pcm_frames_s32__ieee(pWav, framesToRead, pBufferOut);
+ if (pWav->translatedFormatTag == MA_DR_WAVE_FORMAT_IEEE_FLOAT) {
+ return ma_dr_wav_read_pcm_frames_s32__ieee(pWav, framesToRead, pBufferOut);
}
- if (pWav->translatedFormatTag == DR_WAVE_FORMAT_ALAW) {
- return drwav_read_pcm_frames_s32__alaw(pWav, framesToRead, pBufferOut);
+ if (pWav->translatedFormatTag == MA_DR_WAVE_FORMAT_ALAW) {
+ return ma_dr_wav_read_pcm_frames_s32__alaw(pWav, framesToRead, pBufferOut);
}
- if (pWav->translatedFormatTag == DR_WAVE_FORMAT_MULAW) {
- return drwav_read_pcm_frames_s32__mulaw(pWav, framesToRead, pBufferOut);
+ if (pWav->translatedFormatTag == MA_DR_WAVE_FORMAT_MULAW) {
+ return ma_dr_wav_read_pcm_frames_s32__mulaw(pWav, framesToRead, pBufferOut);
}
return 0;
}
-DRWAV_API drwav_uint64 drwav_read_pcm_frames_s32le(drwav* pWav, drwav_uint64 framesToRead, drwav_int32* pBufferOut)
+MA_API ma_uint64 ma_dr_wav_read_pcm_frames_s32le(ma_dr_wav* pWav, ma_uint64 framesToRead, ma_int32* pBufferOut)
{
- drwav_uint64 framesRead = drwav_read_pcm_frames_s32(pWav, framesToRead, pBufferOut);
- if (pBufferOut != NULL && drwav__is_little_endian() == DRWAV_FALSE) {
- drwav__bswap_samples_s32(pBufferOut, framesRead*pWav->channels);
+ ma_uint64 framesRead = ma_dr_wav_read_pcm_frames_s32(pWav, framesToRead, pBufferOut);
+ if (pBufferOut != NULL && ma_dr_wav__is_little_endian() == MA_FALSE) {
+ ma_dr_wav__bswap_samples_s32(pBufferOut, framesRead*pWav->channels);
}
return framesRead;
}
-DRWAV_API drwav_uint64 drwav_read_pcm_frames_s32be(drwav* pWav, drwav_uint64 framesToRead, drwav_int32* pBufferOut)
+MA_API ma_uint64 ma_dr_wav_read_pcm_frames_s32be(ma_dr_wav* pWav, ma_uint64 framesToRead, ma_int32* pBufferOut)
{
- drwav_uint64 framesRead = drwav_read_pcm_frames_s32(pWav, framesToRead, pBufferOut);
- if (pBufferOut != NULL && drwav__is_little_endian() == DRWAV_TRUE) {
- drwav__bswap_samples_s32(pBufferOut, framesRead*pWav->channels);
+ ma_uint64 framesRead = ma_dr_wav_read_pcm_frames_s32(pWav, framesToRead, pBufferOut);
+ if (pBufferOut != NULL && ma_dr_wav__is_little_endian() == MA_TRUE) {
+ ma_dr_wav__bswap_samples_s32(pBufferOut, framesRead*pWav->channels);
}
return framesRead;
}
-DRWAV_API void drwav_u8_to_s32(drwav_int32* pOut, const drwav_uint8* pIn, size_t sampleCount)
+MA_API void ma_dr_wav_u8_to_s32(ma_int32* pOut, const ma_uint8* pIn, size_t sampleCount)
{
size_t i;
if (pOut == NULL || pIn == NULL) {
@@ -79103,7 +81616,7 @@ DRWAV_API void drwav_u8_to_s32(drwav_int32* pOut, const drwav_uint8* pIn, size_t
*pOut++ = ((int)pIn[i] - 128) << 24;
}
}
-DRWAV_API void drwav_s16_to_s32(drwav_int32* pOut, const drwav_int16* pIn, size_t sampleCount)
+MA_API void ma_dr_wav_s16_to_s32(ma_int32* pOut, const ma_int16* pIn, size_t sampleCount)
{
size_t i;
if (pOut == NULL || pIn == NULL) {
@@ -79113,7 +81626,7 @@ DRWAV_API void drwav_s16_to_s32(drwav_int32* pOut, const drwav_int16* pIn, size_
*pOut++ = pIn[i] << 16;
}
}
-DRWAV_API void drwav_s24_to_s32(drwav_int32* pOut, const drwav_uint8* pIn, size_t sampleCount)
+MA_API void ma_dr_wav_s24_to_s32(ma_int32* pOut, const ma_uint8* pIn, size_t sampleCount)
{
size_t i;
if (pOut == NULL || pIn == NULL) {
@@ -79123,73 +81636,73 @@ DRWAV_API void drwav_s24_to_s32(drwav_int32* pOut, const drwav_uint8* pIn, size_
unsigned int s0 = pIn[i*3 + 0];
unsigned int s1 = pIn[i*3 + 1];
unsigned int s2 = pIn[i*3 + 2];
- drwav_int32 sample32 = (drwav_int32)((s0 << 8) | (s1 << 16) | (s2 << 24));
+ ma_int32 sample32 = (ma_int32)((s0 << 8) | (s1 << 16) | (s2 << 24));
*pOut++ = sample32;
}
}
-DRWAV_API void drwav_f32_to_s32(drwav_int32* pOut, const float* pIn, size_t sampleCount)
+MA_API void ma_dr_wav_f32_to_s32(ma_int32* pOut, const float* pIn, size_t sampleCount)
{
size_t i;
if (pOut == NULL || pIn == NULL) {
return;
}
for (i = 0; i < sampleCount; ++i) {
- *pOut++ = (drwav_int32)(2147483648.0 * pIn[i]);
+ *pOut++ = (ma_int32)(2147483648.0 * pIn[i]);
}
}
-DRWAV_API void drwav_f64_to_s32(drwav_int32* pOut, const double* pIn, size_t sampleCount)
+MA_API void ma_dr_wav_f64_to_s32(ma_int32* pOut, const double* pIn, size_t sampleCount)
{
size_t i;
if (pOut == NULL || pIn == NULL) {
return;
}
for (i = 0; i < sampleCount; ++i) {
- *pOut++ = (drwav_int32)(2147483648.0 * pIn[i]);
+ *pOut++ = (ma_int32)(2147483648.0 * pIn[i]);
}
}
-DRWAV_API void drwav_alaw_to_s32(drwav_int32* pOut, const drwav_uint8* pIn, size_t sampleCount)
+MA_API void ma_dr_wav_alaw_to_s32(ma_int32* pOut, const ma_uint8* pIn, size_t sampleCount)
{
size_t i;
if (pOut == NULL || pIn == NULL) {
return;
}
for (i = 0; i < sampleCount; ++i) {
- *pOut++ = ((drwav_int32)drwav__alaw_to_s16(pIn[i])) << 16;
+ *pOut++ = ((ma_int32)ma_dr_wav__alaw_to_s16(pIn[i])) << 16;
}
}
-DRWAV_API void drwav_mulaw_to_s32(drwav_int32* pOut, const drwav_uint8* pIn, size_t sampleCount)
+MA_API void ma_dr_wav_mulaw_to_s32(ma_int32* pOut, const ma_uint8* pIn, size_t sampleCount)
{
size_t i;
if (pOut == NULL || pIn == NULL) {
return;
}
for (i= 0; i < sampleCount; ++i) {
- *pOut++ = ((drwav_int32)drwav__mulaw_to_s16(pIn[i])) << 16;
+ *pOut++ = ((ma_int32)ma_dr_wav__mulaw_to_s16(pIn[i])) << 16;
}
}
-DRWAV_PRIVATE drwav_int16* drwav__read_pcm_frames_and_close_s16(drwav* pWav, unsigned int* channels, unsigned int* sampleRate, drwav_uint64* totalFrameCount)
+MA_PRIVATE ma_int16* ma_dr_wav__read_pcm_frames_and_close_s16(ma_dr_wav* pWav, unsigned int* channels, unsigned int* sampleRate, ma_uint64* totalFrameCount)
{
- drwav_uint64 sampleDataSize;
- drwav_int16* pSampleData;
- drwav_uint64 framesRead;
- DRWAV_ASSERT(pWav != NULL);
- sampleDataSize = pWav->totalPCMFrameCount * pWav->channels * sizeof(drwav_int16);
- if (sampleDataSize > DRWAV_SIZE_MAX) {
- drwav_uninit(pWav);
+ ma_uint64 sampleDataSize;
+ ma_int16* pSampleData;
+ ma_uint64 framesRead;
+ MA_DR_WAV_ASSERT(pWav != NULL);
+ sampleDataSize = pWav->totalPCMFrameCount * pWav->channels * sizeof(ma_int16);
+ if (sampleDataSize > MA_SIZE_MAX) {
+ ma_dr_wav_uninit(pWav);
return NULL;
}
- pSampleData = (drwav_int16*)drwav__malloc_from_callbacks((size_t)sampleDataSize, &pWav->allocationCallbacks);
+ pSampleData = (ma_int16*)ma_dr_wav__malloc_from_callbacks((size_t)sampleDataSize, &pWav->allocationCallbacks);
if (pSampleData == NULL) {
- drwav_uninit(pWav);
+ ma_dr_wav_uninit(pWav);
return NULL;
}
- framesRead = drwav_read_pcm_frames_s16(pWav, (size_t)pWav->totalPCMFrameCount, pSampleData);
+ framesRead = ma_dr_wav_read_pcm_frames_s16(pWav, (size_t)pWav->totalPCMFrameCount, pSampleData);
if (framesRead != pWav->totalPCMFrameCount) {
- drwav__free_from_callbacks(pSampleData, &pWav->allocationCallbacks);
- drwav_uninit(pWav);
+ ma_dr_wav__free_from_callbacks(pSampleData, &pWav->allocationCallbacks);
+ ma_dr_wav_uninit(pWav);
return NULL;
}
- drwav_uninit(pWav);
+ ma_dr_wav_uninit(pWav);
if (sampleRate) {
*sampleRate = pWav->sampleRate;
}
@@ -79201,29 +81714,29 @@ DRWAV_PRIVATE drwav_int16* drwav__read_pcm_frames_and_close_s16(drwav* pWav, uns
}
return pSampleData;
}
-DRWAV_PRIVATE float* drwav__read_pcm_frames_and_close_f32(drwav* pWav, unsigned int* channels, unsigned int* sampleRate, drwav_uint64* totalFrameCount)
+MA_PRIVATE float* ma_dr_wav__read_pcm_frames_and_close_f32(ma_dr_wav* pWav, unsigned int* channels, unsigned int* sampleRate, ma_uint64* totalFrameCount)
{
- drwav_uint64 sampleDataSize;
+ ma_uint64 sampleDataSize;
float* pSampleData;
- drwav_uint64 framesRead;
- DRWAV_ASSERT(pWav != NULL);
+ ma_uint64 framesRead;
+ MA_DR_WAV_ASSERT(pWav != NULL);
sampleDataSize = pWav->totalPCMFrameCount * pWav->channels * sizeof(float);
- if (sampleDataSize > DRWAV_SIZE_MAX) {
- drwav_uninit(pWav);
+ if (sampleDataSize > MA_SIZE_MAX) {
+ ma_dr_wav_uninit(pWav);
return NULL;
}
- pSampleData = (float*)drwav__malloc_from_callbacks((size_t)sampleDataSize, &pWav->allocationCallbacks);
+ pSampleData = (float*)ma_dr_wav__malloc_from_callbacks((size_t)sampleDataSize, &pWav->allocationCallbacks);
if (pSampleData == NULL) {
- drwav_uninit(pWav);
+ ma_dr_wav_uninit(pWav);
return NULL;
}
- framesRead = drwav_read_pcm_frames_f32(pWav, (size_t)pWav->totalPCMFrameCount, pSampleData);
+ framesRead = ma_dr_wav_read_pcm_frames_f32(pWav, (size_t)pWav->totalPCMFrameCount, pSampleData);
if (framesRead != pWav->totalPCMFrameCount) {
- drwav__free_from_callbacks(pSampleData, &pWav->allocationCallbacks);
- drwav_uninit(pWav);
+ ma_dr_wav__free_from_callbacks(pSampleData, &pWav->allocationCallbacks);
+ ma_dr_wav_uninit(pWav);
return NULL;
}
- drwav_uninit(pWav);
+ ma_dr_wav_uninit(pWav);
if (sampleRate) {
*sampleRate = pWav->sampleRate;
}
@@ -79235,29 +81748,29 @@ DRWAV_PRIVATE float* drwav__read_pcm_frames_and_close_f32(drwav* pWav, unsigned
}
return pSampleData;
}
-DRWAV_PRIVATE drwav_int32* drwav__read_pcm_frames_and_close_s32(drwav* pWav, unsigned int* channels, unsigned int* sampleRate, drwav_uint64* totalFrameCount)
+MA_PRIVATE ma_int32* ma_dr_wav__read_pcm_frames_and_close_s32(ma_dr_wav* pWav, unsigned int* channels, unsigned int* sampleRate, ma_uint64* totalFrameCount)
{
- drwav_uint64 sampleDataSize;
- drwav_int32* pSampleData;
- drwav_uint64 framesRead;
- DRWAV_ASSERT(pWav != NULL);
- sampleDataSize = pWav->totalPCMFrameCount * pWav->channels * sizeof(drwav_int32);
- if (sampleDataSize > DRWAV_SIZE_MAX) {
- drwav_uninit(pWav);
+ ma_uint64 sampleDataSize;
+ ma_int32* pSampleData;
+ ma_uint64 framesRead;
+ MA_DR_WAV_ASSERT(pWav != NULL);
+ sampleDataSize = pWav->totalPCMFrameCount * pWav->channels * sizeof(ma_int32);
+ if (sampleDataSize > MA_SIZE_MAX) {
+ ma_dr_wav_uninit(pWav);
return NULL;
}
- pSampleData = (drwav_int32*)drwav__malloc_from_callbacks((size_t)sampleDataSize, &pWav->allocationCallbacks);
+ pSampleData = (ma_int32*)ma_dr_wav__malloc_from_callbacks((size_t)sampleDataSize, &pWav->allocationCallbacks);
if (pSampleData == NULL) {
- drwav_uninit(pWav);
+ ma_dr_wav_uninit(pWav);
return NULL;
}
- framesRead = drwav_read_pcm_frames_s32(pWav, (size_t)pWav->totalPCMFrameCount, pSampleData);
+ framesRead = ma_dr_wav_read_pcm_frames_s32(pWav, (size_t)pWav->totalPCMFrameCount, pSampleData);
if (framesRead != pWav->totalPCMFrameCount) {
- drwav__free_from_callbacks(pSampleData, &pWav->allocationCallbacks);
- drwav_uninit(pWav);
+ ma_dr_wav__free_from_callbacks(pSampleData, &pWav->allocationCallbacks);
+ ma_dr_wav_uninit(pWav);
return NULL;
}
- drwav_uninit(pWav);
+ ma_dr_wav_uninit(pWav);
if (sampleRate) {
*sampleRate = pWav->sampleRate;
}
@@ -79269,9 +81782,9 @@ DRWAV_PRIVATE drwav_int32* drwav__read_pcm_frames_and_close_s32(drwav* pWav, uns
}
return pSampleData;
}
-DRWAV_API drwav_int16* drwav_open_and_read_pcm_frames_s16(drwav_read_proc onRead, drwav_seek_proc onSeek, void* pUserData, unsigned int* channelsOut, unsigned int* sampleRateOut, drwav_uint64* totalFrameCountOut, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_int16* ma_dr_wav_open_and_read_pcm_frames_s16(ma_dr_wav_read_proc onRead, ma_dr_wav_seek_proc onSeek, void* pUserData, unsigned int* channelsOut, unsigned int* sampleRateOut, ma_uint64* totalFrameCountOut, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drwav wav;
+ ma_dr_wav wav;
if (channelsOut) {
*channelsOut = 0;
}
@@ -79281,14 +81794,14 @@ DRWAV_API drwav_int16* drwav_open_and_read_pcm_frames_s16(drwav_read_proc onRead
if (totalFrameCountOut) {
*totalFrameCountOut = 0;
}
- if (!drwav_init(&wav, onRead, onSeek, pUserData, pAllocationCallbacks)) {
+ if (!ma_dr_wav_init(&wav, onRead, onSeek, pUserData, pAllocationCallbacks)) {
return NULL;
}
- return drwav__read_pcm_frames_and_close_s16(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
+ return ma_dr_wav__read_pcm_frames_and_close_s16(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
}
-DRWAV_API float* drwav_open_and_read_pcm_frames_f32(drwav_read_proc onRead, drwav_seek_proc onSeek, void* pUserData, unsigned int* channelsOut, unsigned int* sampleRateOut, drwav_uint64* totalFrameCountOut, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_API float* ma_dr_wav_open_and_read_pcm_frames_f32(ma_dr_wav_read_proc onRead, ma_dr_wav_seek_proc onSeek, void* pUserData, unsigned int* channelsOut, unsigned int* sampleRateOut, ma_uint64* totalFrameCountOut, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drwav wav;
+ ma_dr_wav wav;
if (channelsOut) {
*channelsOut = 0;
}
@@ -79298,14 +81811,14 @@ DRWAV_API float* drwav_open_and_read_pcm_frames_f32(drwav_read_proc onRead, drwa
if (totalFrameCountOut) {
*totalFrameCountOut = 0;
}
- if (!drwav_init(&wav, onRead, onSeek, pUserData, pAllocationCallbacks)) {
+ if (!ma_dr_wav_init(&wav, onRead, onSeek, pUserData, pAllocationCallbacks)) {
return NULL;
}
- return drwav__read_pcm_frames_and_close_f32(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
+ return ma_dr_wav__read_pcm_frames_and_close_f32(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
}
-DRWAV_API drwav_int32* drwav_open_and_read_pcm_frames_s32(drwav_read_proc onRead, drwav_seek_proc onSeek, void* pUserData, unsigned int* channelsOut, unsigned int* sampleRateOut, drwav_uint64* totalFrameCountOut, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_int32* ma_dr_wav_open_and_read_pcm_frames_s32(ma_dr_wav_read_proc onRead, ma_dr_wav_seek_proc onSeek, void* pUserData, unsigned int* channelsOut, unsigned int* sampleRateOut, ma_uint64* totalFrameCountOut, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drwav wav;
+ ma_dr_wav wav;
if (channelsOut) {
*channelsOut = 0;
}
@@ -79315,15 +81828,15 @@ DRWAV_API drwav_int32* drwav_open_and_read_pcm_frames_s32(drwav_read_proc onRead
if (totalFrameCountOut) {
*totalFrameCountOut = 0;
}
- if (!drwav_init(&wav, onRead, onSeek, pUserData, pAllocationCallbacks)) {
+ if (!ma_dr_wav_init(&wav, onRead, onSeek, pUserData, pAllocationCallbacks)) {
return NULL;
}
- return drwav__read_pcm_frames_and_close_s32(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
+ return ma_dr_wav__read_pcm_frames_and_close_s32(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
}
-#ifndef DR_WAV_NO_STDIO
-DRWAV_API drwav_int16* drwav_open_file_and_read_pcm_frames_s16(const char* filename, unsigned int* channelsOut, unsigned int* sampleRateOut, drwav_uint64* totalFrameCountOut, const drwav_allocation_callbacks* pAllocationCallbacks)
+#ifndef MA_DR_WAV_NO_STDIO
+MA_API ma_int16* ma_dr_wav_open_file_and_read_pcm_frames_s16(const char* filename, unsigned int* channelsOut, unsigned int* sampleRateOut, ma_uint64* totalFrameCountOut, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drwav wav;
+ ma_dr_wav wav;
if (channelsOut) {
*channelsOut = 0;
}
@@ -79333,14 +81846,14 @@ DRWAV_API drwav_int16* drwav_open_file_and_read_pcm_frames_s16(const char* filen
if (totalFrameCountOut) {
*totalFrameCountOut = 0;
}
- if (!drwav_init_file(&wav, filename, pAllocationCallbacks)) {
+ if (!ma_dr_wav_init_file(&wav, filename, pAllocationCallbacks)) {
return NULL;
}
- return drwav__read_pcm_frames_and_close_s16(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
+ return ma_dr_wav__read_pcm_frames_and_close_s16(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
}
-DRWAV_API float* drwav_open_file_and_read_pcm_frames_f32(const char* filename, unsigned int* channelsOut, unsigned int* sampleRateOut, drwav_uint64* totalFrameCountOut, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_API float* ma_dr_wav_open_file_and_read_pcm_frames_f32(const char* filename, unsigned int* channelsOut, unsigned int* sampleRateOut, ma_uint64* totalFrameCountOut, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drwav wav;
+ ma_dr_wav wav;
if (channelsOut) {
*channelsOut = 0;
}
@@ -79350,14 +81863,14 @@ DRWAV_API float* drwav_open_file_and_read_pcm_frames_f32(const char* filename, u
if (totalFrameCountOut) {
*totalFrameCountOut = 0;
}
- if (!drwav_init_file(&wav, filename, pAllocationCallbacks)) {
+ if (!ma_dr_wav_init_file(&wav, filename, pAllocationCallbacks)) {
return NULL;
}
- return drwav__read_pcm_frames_and_close_f32(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
+ return ma_dr_wav__read_pcm_frames_and_close_f32(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
}
-DRWAV_API drwav_int32* drwav_open_file_and_read_pcm_frames_s32(const char* filename, unsigned int* channelsOut, unsigned int* sampleRateOut, drwav_uint64* totalFrameCountOut, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_int32* ma_dr_wav_open_file_and_read_pcm_frames_s32(const char* filename, unsigned int* channelsOut, unsigned int* sampleRateOut, ma_uint64* totalFrameCountOut, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drwav wav;
+ ma_dr_wav wav;
if (channelsOut) {
*channelsOut = 0;
}
@@ -79367,15 +81880,15 @@ DRWAV_API drwav_int32* drwav_open_file_and_read_pcm_frames_s32(const char* filen
if (totalFrameCountOut) {
*totalFrameCountOut = 0;
}
- if (!drwav_init_file(&wav, filename, pAllocationCallbacks)) {
+ if (!ma_dr_wav_init_file(&wav, filename, pAllocationCallbacks)) {
return NULL;
}
- return drwav__read_pcm_frames_and_close_s32(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
+ return ma_dr_wav__read_pcm_frames_and_close_s32(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
}
-#ifndef DR_WAV_NO_WCHAR
-DRWAV_API drwav_int16* drwav_open_file_and_read_pcm_frames_s16_w(const wchar_t* filename, unsigned int* channelsOut, unsigned int* sampleRateOut, drwav_uint64* totalFrameCountOut, const drwav_allocation_callbacks* pAllocationCallbacks)
+#ifndef MA_DR_WAV_NO_WCHAR
+MA_API ma_int16* ma_dr_wav_open_file_and_read_pcm_frames_s16_w(const wchar_t* filename, unsigned int* channelsOut, unsigned int* sampleRateOut, ma_uint64* totalFrameCountOut, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drwav wav;
+ ma_dr_wav wav;
if (sampleRateOut) {
*sampleRateOut = 0;
}
@@ -79385,14 +81898,14 @@ DRWAV_API drwav_int16* drwav_open_file_and_read_pcm_frames_s16_w(const wchar_t*
if (totalFrameCountOut) {
*totalFrameCountOut = 0;
}
- if (!drwav_init_file_w(&wav, filename, pAllocationCallbacks)) {
+ if (!ma_dr_wav_init_file_w(&wav, filename, pAllocationCallbacks)) {
return NULL;
}
- return drwav__read_pcm_frames_and_close_s16(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
+ return ma_dr_wav__read_pcm_frames_and_close_s16(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
}
-DRWAV_API float* drwav_open_file_and_read_pcm_frames_f32_w(const wchar_t* filename, unsigned int* channelsOut, unsigned int* sampleRateOut, drwav_uint64* totalFrameCountOut, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_API float* ma_dr_wav_open_file_and_read_pcm_frames_f32_w(const wchar_t* filename, unsigned int* channelsOut, unsigned int* sampleRateOut, ma_uint64* totalFrameCountOut, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drwav wav;
+ ma_dr_wav wav;
if (sampleRateOut) {
*sampleRateOut = 0;
}
@@ -79402,14 +81915,14 @@ DRWAV_API float* drwav_open_file_and_read_pcm_frames_f32_w(const wchar_t* filena
if (totalFrameCountOut) {
*totalFrameCountOut = 0;
}
- if (!drwav_init_file_w(&wav, filename, pAllocationCallbacks)) {
+ if (!ma_dr_wav_init_file_w(&wav, filename, pAllocationCallbacks)) {
return NULL;
}
- return drwav__read_pcm_frames_and_close_f32(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
+ return ma_dr_wav__read_pcm_frames_and_close_f32(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
}
-DRWAV_API drwav_int32* drwav_open_file_and_read_pcm_frames_s32_w(const wchar_t* filename, unsigned int* channelsOut, unsigned int* sampleRateOut, drwav_uint64* totalFrameCountOut, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_int32* ma_dr_wav_open_file_and_read_pcm_frames_s32_w(const wchar_t* filename, unsigned int* channelsOut, unsigned int* sampleRateOut, ma_uint64* totalFrameCountOut, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drwav wav;
+ ma_dr_wav wav;
if (sampleRateOut) {
*sampleRateOut = 0;
}
@@ -79419,16 +81932,16 @@ DRWAV_API drwav_int32* drwav_open_file_and_read_pcm_frames_s32_w(const wchar_t*
if (totalFrameCountOut) {
*totalFrameCountOut = 0;
}
- if (!drwav_init_file_w(&wav, filename, pAllocationCallbacks)) {
+ if (!ma_dr_wav_init_file_w(&wav, filename, pAllocationCallbacks)) {
return NULL;
}
- return drwav__read_pcm_frames_and_close_s32(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
+ return ma_dr_wav__read_pcm_frames_and_close_s32(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
}
#endif
#endif
-DRWAV_API drwav_int16* drwav_open_memory_and_read_pcm_frames_s16(const void* data, size_t dataSize, unsigned int* channelsOut, unsigned int* sampleRateOut, drwav_uint64* totalFrameCountOut, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_int16* ma_dr_wav_open_memory_and_read_pcm_frames_s16(const void* data, size_t dataSize, unsigned int* channelsOut, unsigned int* sampleRateOut, ma_uint64* totalFrameCountOut, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drwav wav;
+ ma_dr_wav wav;
if (channelsOut) {
*channelsOut = 0;
}
@@ -79438,14 +81951,14 @@ DRWAV_API drwav_int16* drwav_open_memory_and_read_pcm_frames_s16(const void* dat
if (totalFrameCountOut) {
*totalFrameCountOut = 0;
}
- if (!drwav_init_memory(&wav, data, dataSize, pAllocationCallbacks)) {
+ if (!ma_dr_wav_init_memory(&wav, data, dataSize, pAllocationCallbacks)) {
return NULL;
}
- return drwav__read_pcm_frames_and_close_s16(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
+ return ma_dr_wav__read_pcm_frames_and_close_s16(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
}
-DRWAV_API float* drwav_open_memory_and_read_pcm_frames_f32(const void* data, size_t dataSize, unsigned int* channelsOut, unsigned int* sampleRateOut, drwav_uint64* totalFrameCountOut, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_API float* ma_dr_wav_open_memory_and_read_pcm_frames_f32(const void* data, size_t dataSize, unsigned int* channelsOut, unsigned int* sampleRateOut, ma_uint64* totalFrameCountOut, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drwav wav;
+ ma_dr_wav wav;
if (channelsOut) {
*channelsOut = 0;
}
@@ -79455,14 +81968,14 @@ DRWAV_API float* drwav_open_memory_and_read_pcm_frames_f32(const void* data, siz
if (totalFrameCountOut) {
*totalFrameCountOut = 0;
}
- if (!drwav_init_memory(&wav, data, dataSize, pAllocationCallbacks)) {
+ if (!ma_dr_wav_init_memory(&wav, data, dataSize, pAllocationCallbacks)) {
return NULL;
}
- return drwav__read_pcm_frames_and_close_f32(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
+ return ma_dr_wav__read_pcm_frames_and_close_f32(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
}
-DRWAV_API drwav_int32* drwav_open_memory_and_read_pcm_frames_s32(const void* data, size_t dataSize, unsigned int* channelsOut, unsigned int* sampleRateOut, drwav_uint64* totalFrameCountOut, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_int32* ma_dr_wav_open_memory_and_read_pcm_frames_s32(const void* data, size_t dataSize, unsigned int* channelsOut, unsigned int* sampleRateOut, ma_uint64* totalFrameCountOut, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drwav wav;
+ ma_dr_wav wav;
if (channelsOut) {
*channelsOut = 0;
}
@@ -79472,66 +81985,66 @@ DRWAV_API drwav_int32* drwav_open_memory_and_read_pcm_frames_s32(const void* dat
if (totalFrameCountOut) {
*totalFrameCountOut = 0;
}
- if (!drwav_init_memory(&wav, data, dataSize, pAllocationCallbacks)) {
+ if (!ma_dr_wav_init_memory(&wav, data, dataSize, pAllocationCallbacks)) {
return NULL;
}
- return drwav__read_pcm_frames_and_close_s32(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
+ return ma_dr_wav__read_pcm_frames_and_close_s32(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
}
#endif
-DRWAV_API void drwav_free(void* p, const drwav_allocation_callbacks* pAllocationCallbacks)
+MA_API void ma_dr_wav_free(void* p, const ma_allocation_callbacks* pAllocationCallbacks)
{
if (pAllocationCallbacks != NULL) {
- drwav__free_from_callbacks(p, pAllocationCallbacks);
+ ma_dr_wav__free_from_callbacks(p, pAllocationCallbacks);
} else {
- drwav__free_default(p, NULL);
+ ma_dr_wav__free_default(p, NULL);
}
}
-DRWAV_API drwav_uint16 drwav_bytes_to_u16(const drwav_uint8* data)
+MA_API ma_uint16 ma_dr_wav_bytes_to_u16(const ma_uint8* data)
{
- return ((drwav_uint16)data[0] << 0) | ((drwav_uint16)data[1] << 8);
+ return ((ma_uint16)data[0] << 0) | ((ma_uint16)data[1] << 8);
}
-DRWAV_API drwav_int16 drwav_bytes_to_s16(const drwav_uint8* data)
+MA_API ma_int16 ma_dr_wav_bytes_to_s16(const ma_uint8* data)
{
- return (drwav_int16)drwav_bytes_to_u16(data);
+ return (ma_int16)ma_dr_wav_bytes_to_u16(data);
}
-DRWAV_API drwav_uint32 drwav_bytes_to_u32(const drwav_uint8* data)
+MA_API ma_uint32 ma_dr_wav_bytes_to_u32(const ma_uint8* data)
{
- return ((drwav_uint32)data[0] << 0) | ((drwav_uint32)data[1] << 8) | ((drwav_uint32)data[2] << 16) | ((drwav_uint32)data[3] << 24);
+ return ma_dr_wav_bytes_to_u32_le(data);
}
-DRWAV_API float drwav_bytes_to_f32(const drwav_uint8* data)
+MA_API float ma_dr_wav_bytes_to_f32(const ma_uint8* data)
{
union {
- drwav_uint32 u32;
+ ma_uint32 u32;
float f32;
} value;
- value.u32 = drwav_bytes_to_u32(data);
+ value.u32 = ma_dr_wav_bytes_to_u32(data);
return value.f32;
}
-DRWAV_API drwav_int32 drwav_bytes_to_s32(const drwav_uint8* data)
+MA_API ma_int32 ma_dr_wav_bytes_to_s32(const ma_uint8* data)
{
- return (drwav_int32)drwav_bytes_to_u32(data);
+ return (ma_int32)ma_dr_wav_bytes_to_u32(data);
}
-DRWAV_API drwav_uint64 drwav_bytes_to_u64(const drwav_uint8* data)
+MA_API ma_uint64 ma_dr_wav_bytes_to_u64(const ma_uint8* data)
{
return
- ((drwav_uint64)data[0] << 0) | ((drwav_uint64)data[1] << 8) | ((drwav_uint64)data[2] << 16) | ((drwav_uint64)data[3] << 24) |
- ((drwav_uint64)data[4] << 32) | ((drwav_uint64)data[5] << 40) | ((drwav_uint64)data[6] << 48) | ((drwav_uint64)data[7] << 56);
+ ((ma_uint64)data[0] << 0) | ((ma_uint64)data[1] << 8) | ((ma_uint64)data[2] << 16) | ((ma_uint64)data[3] << 24) |
+ ((ma_uint64)data[4] << 32) | ((ma_uint64)data[5] << 40) | ((ma_uint64)data[6] << 48) | ((ma_uint64)data[7] << 56);
}
-DRWAV_API drwav_int64 drwav_bytes_to_s64(const drwav_uint8* data)
+MA_API ma_int64 ma_dr_wav_bytes_to_s64(const ma_uint8* data)
{
- return (drwav_int64)drwav_bytes_to_u64(data);
+ return (ma_int64)ma_dr_wav_bytes_to_u64(data);
}
-DRWAV_API drwav_bool32 drwav_guid_equal(const drwav_uint8 a[16], const drwav_uint8 b[16])
+MA_API ma_bool32 ma_dr_wav_guid_equal(const ma_uint8 a[16], const ma_uint8 b[16])
{
int i;
for (i = 0; i < 16; i += 1) {
if (a[i] != b[i]) {
- return DRWAV_FALSE;
+ return MA_FALSE;
}
}
- return DRWAV_TRUE;
+ return MA_TRUE;
}
-DRWAV_API drwav_bool32 drwav_fourcc_equal(const drwav_uint8* a, const char* b)
+MA_API ma_bool32 ma_dr_wav_fourcc_equal(const ma_uint8* a, const char* b)
{
return
a[0] == b[0] &&
@@ -79544,14 +82057,14 @@ DRWAV_API drwav_bool32 drwav_fourcc_equal(const drwav_uint8* a, const char* b)
#endif
#endif
/* dr_wav_c end */
-#endif /* DRWAV_IMPLEMENTATION */
+#endif /* MA_DR_WAV_IMPLEMENTATION */
#endif /* MA_NO_WAV */
#if !defined(MA_NO_FLAC) && !defined(MA_NO_DECODING)
-#if !defined(DR_FLAC_IMPLEMENTATION) && !defined(DRFLAC_IMPLEMENTATION) /* For backwards compatibility. Will be removed in version 0.11 for cleanliness. */
+#if !defined(MA_DR_FLAC_IMPLEMENTATION) && !defined(MA_DR_FLAC_IMPLEMENTATION) /* For backwards compatibility. Will be removed in version 0.11 for cleanliness. */
/* dr_flac_c begin */
-#ifndef dr_flac_c
-#define dr_flac_c
+#ifndef ma_dr_flac_c
+#define ma_dr_flac_c
#if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)))
#pragma GCC diagnostic push
#if __GNUC__ >= 7
@@ -79572,85 +82085,60 @@ DRWAV_API drwav_bool32 drwav_fourcc_equal(const drwav_uint8* a, const char* b)
#endif
#include
#include
-#ifdef _MSC_VER
- #define DRFLAC_INLINE __forceinline
-#elif defined(__GNUC__)
- #if defined(__STRICT_ANSI__)
- #define DRFLAC_GNUC_INLINE_HINT __inline__
- #else
- #define DRFLAC_GNUC_INLINE_HINT inline
- #endif
- #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 2)) || defined(__clang__)
- #define DRFLAC_INLINE DRFLAC_GNUC_INLINE_HINT __attribute__((always_inline))
- #else
- #define DRFLAC_INLINE DRFLAC_GNUC_INLINE_HINT
- #endif
-#elif defined(__WATCOMC__)
- #define DRFLAC_INLINE __inline
-#else
- #define DRFLAC_INLINE
-#endif
-#if defined(__x86_64__) || defined(_M_X64)
- #define DRFLAC_X64
-#elif defined(__i386) || defined(_M_IX86)
- #define DRFLAC_X86
-#elif defined(__arm__) || defined(_M_ARM) || defined(__arm64) || defined(__arm64__) || defined(__aarch64__) || defined(_M_ARM64)
- #define DRFLAC_ARM
-#endif
-#if !defined(DR_FLAC_NO_SIMD)
- #if defined(DRFLAC_X64) || defined(DRFLAC_X86)
+#if !defined(MA_DR_FLAC_NO_SIMD)
+ #if defined(MA_X64) || defined(MA_X86)
#if defined(_MSC_VER) && !defined(__clang__)
- #if _MSC_VER >= 1400 && !defined(DRFLAC_NO_SSE2)
- #define DRFLAC_SUPPORT_SSE2
+ #if _MSC_VER >= 1400 && !defined(MA_DR_FLAC_NO_SSE2)
+ #define MA_DR_FLAC_SUPPORT_SSE2
#endif
- #if _MSC_VER >= 1600 && !defined(DRFLAC_NO_SSE41)
- #define DRFLAC_SUPPORT_SSE41
+ #if _MSC_VER >= 1600 && !defined(MA_DR_FLAC_NO_SSE41)
+ #define MA_DR_FLAC_SUPPORT_SSE41
#endif
#elif defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
- #if defined(__SSE2__) && !defined(DRFLAC_NO_SSE2)
- #define DRFLAC_SUPPORT_SSE2
+ #if defined(__SSE2__) && !defined(MA_DR_FLAC_NO_SSE2)
+ #define MA_DR_FLAC_SUPPORT_SSE2
#endif
- #if defined(__SSE4_1__) && !defined(DRFLAC_NO_SSE41)
- #define DRFLAC_SUPPORT_SSE41
+ #if defined(__SSE4_1__) && !defined(MA_DR_FLAC_NO_SSE41)
+ #define MA_DR_FLAC_SUPPORT_SSE41
#endif
#endif
#if !defined(__GNUC__) && !defined(__clang__) && defined(__has_include)
- #if !defined(DRFLAC_SUPPORT_SSE2) && !defined(DRFLAC_NO_SSE2) && __has_include()
- #define DRFLAC_SUPPORT_SSE2
+ #if !defined(MA_DR_FLAC_SUPPORT_SSE2) && !defined(MA_DR_FLAC_NO_SSE2) && __has_include()
+ #define MA_DR_FLAC_SUPPORT_SSE2
#endif
- #if !defined(DRFLAC_SUPPORT_SSE41) && !defined(DRFLAC_NO_SSE41) && __has_include()
- #define DRFLAC_SUPPORT_SSE41
+ #if !defined(MA_DR_FLAC_SUPPORT_SSE41) && !defined(MA_DR_FLAC_NO_SSE41) && __has_include()
+ #define MA_DR_FLAC_SUPPORT_SSE41
#endif
#endif
- #if defined(DRFLAC_SUPPORT_SSE41)
+ #if defined(MA_DR_FLAC_SUPPORT_SSE41)
#include
- #elif defined(DRFLAC_SUPPORT_SSE2)
+ #elif defined(MA_DR_FLAC_SUPPORT_SSE2)
#include
#endif
#endif
- #if defined(DRFLAC_ARM)
- #if !defined(DRFLAC_NO_NEON) && (defined(__ARM_NEON) || defined(__aarch64__) || defined(_M_ARM64))
- #define DRFLAC_SUPPORT_NEON
+ #if defined(MA_ARM)
+ #if !defined(MA_DR_FLAC_NO_NEON) && (defined(__ARM_NEON) || defined(__aarch64__) || defined(_M_ARM64))
+ #define MA_DR_FLAC_SUPPORT_NEON
#include
#endif
#endif
#endif
-#if !defined(DR_FLAC_NO_SIMD) && (defined(DRFLAC_X86) || defined(DRFLAC_X64))
+#if !defined(MA_DR_FLAC_NO_SIMD) && (defined(MA_X86) || defined(MA_X64))
#if defined(_MSC_VER) && !defined(__clang__)
#if _MSC_VER >= 1400
#include
- static void drflac__cpuid(int info[4], int fid)
+ static void ma_dr_flac__cpuid(int info[4], int fid)
{
__cpuid(info, fid);
}
#else
- #define DRFLAC_NO_CPUID
+ #define MA_DR_FLAC_NO_CPUID
#endif
#else
#if defined(__GNUC__) || defined(__clang__)
- static void drflac__cpuid(int info[4], int fid)
+ static void ma_dr_flac__cpuid(int info[4], int fid)
{
- #if defined(DRFLAC_X86) && defined(__PIC__)
+ #if defined(MA_X86) && defined(__PIC__)
__asm__ __volatile__ (
"xchg{l} {%%}ebx, %k1;"
"cpuid;"
@@ -79664,100 +82152,100 @@ DRWAV_API drwav_bool32 drwav_fourcc_equal(const drwav_uint8* a, const char* b)
#endif
}
#else
- #define DRFLAC_NO_CPUID
+ #define MA_DR_FLAC_NO_CPUID
#endif
#endif
#else
- #define DRFLAC_NO_CPUID
+ #define MA_DR_FLAC_NO_CPUID
#endif
-static DRFLAC_INLINE drflac_bool32 drflac_has_sse2(void)
+static MA_INLINE ma_bool32 ma_dr_flac_has_sse2(void)
{
-#if defined(DRFLAC_SUPPORT_SSE2)
- #if (defined(DRFLAC_X64) || defined(DRFLAC_X86)) && !defined(DRFLAC_NO_SSE2)
- #if defined(DRFLAC_X64)
- return DRFLAC_TRUE;
+#if defined(MA_DR_FLAC_SUPPORT_SSE2)
+ #if (defined(MA_X64) || defined(MA_X86)) && !defined(MA_DR_FLAC_NO_SSE2)
+ #if defined(MA_X64)
+ return MA_TRUE;
#elif (defined(_M_IX86_FP) && _M_IX86_FP == 2) || defined(__SSE2__)
- return DRFLAC_TRUE;
+ return MA_TRUE;
#else
- #if defined(DRFLAC_NO_CPUID)
- return DRFLAC_FALSE;
+ #if defined(MA_DR_FLAC_NO_CPUID)
+ return MA_FALSE;
#else
int info[4];
- drflac__cpuid(info, 1);
+ ma_dr_flac__cpuid(info, 1);
return (info[3] & (1 << 26)) != 0;
#endif
#endif
#else
- return DRFLAC_FALSE;
+ return MA_FALSE;
#endif
#else
- return DRFLAC_FALSE;
+ return MA_FALSE;
#endif
}
-static DRFLAC_INLINE drflac_bool32 drflac_has_sse41(void)
+static MA_INLINE ma_bool32 ma_dr_flac_has_sse41(void)
{
-#if defined(DRFLAC_SUPPORT_SSE41)
- #if (defined(DRFLAC_X64) || defined(DRFLAC_X86)) && !defined(DRFLAC_NO_SSE41)
+#if defined(MA_DR_FLAC_SUPPORT_SSE41)
+ #if (defined(MA_X64) || defined(MA_X86)) && !defined(MA_DR_FLAC_NO_SSE41)
#if defined(__SSE4_1__) || defined(__AVX__)
- return DRFLAC_TRUE;
+ return MA_TRUE;
#else
- #if defined(DRFLAC_NO_CPUID)
- return DRFLAC_FALSE;
+ #if defined(MA_DR_FLAC_NO_CPUID)
+ return MA_FALSE;
#else
int info[4];
- drflac__cpuid(info, 1);
+ ma_dr_flac__cpuid(info, 1);
return (info[2] & (1 << 19)) != 0;
#endif
#endif
#else
- return DRFLAC_FALSE;
+ return MA_FALSE;
#endif
#else
- return DRFLAC_FALSE;
+ return MA_FALSE;
#endif
}
-#if defined(_MSC_VER) && _MSC_VER >= 1500 && (defined(DRFLAC_X86) || defined(DRFLAC_X64)) && !defined(__clang__)
- #define DRFLAC_HAS_LZCNT_INTRINSIC
+#if defined(_MSC_VER) && _MSC_VER >= 1500 && (defined(MA_X86) || defined(MA_X64)) && !defined(__clang__)
+ #define MA_DR_FLAC_HAS_LZCNT_INTRINSIC
#elif (defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)))
- #define DRFLAC_HAS_LZCNT_INTRINSIC
+ #define MA_DR_FLAC_HAS_LZCNT_INTRINSIC
#elif defined(__clang__)
#if defined(__has_builtin)
#if __has_builtin(__builtin_clzll) || __has_builtin(__builtin_clzl)
- #define DRFLAC_HAS_LZCNT_INTRINSIC
+ #define MA_DR_FLAC_HAS_LZCNT_INTRINSIC
#endif
#endif
#endif
#if defined(_MSC_VER) && _MSC_VER >= 1400 && !defined(__clang__)
- #define DRFLAC_HAS_BYTESWAP16_INTRINSIC
- #define DRFLAC_HAS_BYTESWAP32_INTRINSIC
- #define DRFLAC_HAS_BYTESWAP64_INTRINSIC
+ #define MA_DR_FLAC_HAS_BYTESWAP16_INTRINSIC
+ #define MA_DR_FLAC_HAS_BYTESWAP32_INTRINSIC
+ #define MA_DR_FLAC_HAS_BYTESWAP64_INTRINSIC
#elif defined(__clang__)
#if defined(__has_builtin)
#if __has_builtin(__builtin_bswap16)
- #define DRFLAC_HAS_BYTESWAP16_INTRINSIC
+ #define MA_DR_FLAC_HAS_BYTESWAP16_INTRINSIC
#endif
#if __has_builtin(__builtin_bswap32)
- #define DRFLAC_HAS_BYTESWAP32_INTRINSIC
+ #define MA_DR_FLAC_HAS_BYTESWAP32_INTRINSIC
#endif
#if __has_builtin(__builtin_bswap64)
- #define DRFLAC_HAS_BYTESWAP64_INTRINSIC
+ #define MA_DR_FLAC_HAS_BYTESWAP64_INTRINSIC
#endif
#endif
#elif defined(__GNUC__)
#if ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
- #define DRFLAC_HAS_BYTESWAP32_INTRINSIC
- #define DRFLAC_HAS_BYTESWAP64_INTRINSIC
+ #define MA_DR_FLAC_HAS_BYTESWAP32_INTRINSIC
+ #define MA_DR_FLAC_HAS_BYTESWAP64_INTRINSIC
#endif
#if ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))
- #define DRFLAC_HAS_BYTESWAP16_INTRINSIC
+ #define MA_DR_FLAC_HAS_BYTESWAP16_INTRINSIC
#endif
#elif defined(__WATCOMC__) && defined(__386__)
- #define DRFLAC_HAS_BYTESWAP16_INTRINSIC
- #define DRFLAC_HAS_BYTESWAP32_INTRINSIC
- #define DRFLAC_HAS_BYTESWAP64_INTRINSIC
- extern __inline drflac_uint16 _watcom_bswap16(drflac_uint16);
- extern __inline drflac_uint32 _watcom_bswap32(drflac_uint32);
- extern __inline drflac_uint64 _watcom_bswap64(drflac_uint64);
+ #define MA_DR_FLAC_HAS_BYTESWAP16_INTRINSIC
+ #define MA_DR_FLAC_HAS_BYTESWAP32_INTRINSIC
+ #define MA_DR_FLAC_HAS_BYTESWAP64_INTRINSIC
+ extern __inline ma_uint16 _watcom_bswap16(ma_uint16);
+ extern __inline ma_uint32 _watcom_bswap32(ma_uint32);
+ extern __inline ma_uint64 _watcom_bswap64(ma_uint64);
#pragma aux _watcom_bswap16 = \
"xchg al, ah" \
parm [ax] \
@@ -79776,185 +82264,129 @@ static DRFLAC_INLINE drflac_bool32 drflac_has_sse41(void)
value [eax edx] \
modify nomemory;
#endif
-#ifndef DRFLAC_ASSERT
+#ifndef MA_DR_FLAC_ASSERT
#include
-#define DRFLAC_ASSERT(expression) assert(expression)
-#endif
-#ifndef DRFLAC_MALLOC
-#define DRFLAC_MALLOC(sz) malloc((sz))
-#endif
-#ifndef DRFLAC_REALLOC
-#define DRFLAC_REALLOC(p, sz) realloc((p), (sz))
-#endif
-#ifndef DRFLAC_FREE
-#define DRFLAC_FREE(p) free((p))
-#endif
-#ifndef DRFLAC_COPY_MEMORY
-#define DRFLAC_COPY_MEMORY(dst, src, sz) memcpy((dst), (src), (sz))
-#endif
-#ifndef DRFLAC_ZERO_MEMORY
-#define DRFLAC_ZERO_MEMORY(p, sz) memset((p), 0, (sz))
-#endif
-#ifndef DRFLAC_ZERO_OBJECT
-#define DRFLAC_ZERO_OBJECT(p) DRFLAC_ZERO_MEMORY((p), sizeof(*(p)))
-#endif
-#define DRFLAC_MAX_SIMD_VECTOR_SIZE 64
-typedef drflac_int32 drflac_result;
-#define DRFLAC_SUCCESS 0
-#define DRFLAC_ERROR -1
-#define DRFLAC_INVALID_ARGS -2
-#define DRFLAC_INVALID_OPERATION -3
-#define DRFLAC_OUT_OF_MEMORY -4
-#define DRFLAC_OUT_OF_RANGE -5
-#define DRFLAC_ACCESS_DENIED -6
-#define DRFLAC_DOES_NOT_EXIST -7
-#define DRFLAC_ALREADY_EXISTS -8
-#define DRFLAC_TOO_MANY_OPEN_FILES -9
-#define DRFLAC_INVALID_FILE -10
-#define DRFLAC_TOO_BIG -11
-#define DRFLAC_PATH_TOO_LONG -12
-#define DRFLAC_NAME_TOO_LONG -13
-#define DRFLAC_NOT_DIRECTORY -14
-#define DRFLAC_IS_DIRECTORY -15
-#define DRFLAC_DIRECTORY_NOT_EMPTY -16
-#define DRFLAC_END_OF_FILE -17
-#define DRFLAC_NO_SPACE -18
-#define DRFLAC_BUSY -19
-#define DRFLAC_IO_ERROR -20
-#define DRFLAC_INTERRUPT -21
-#define DRFLAC_UNAVAILABLE -22
-#define DRFLAC_ALREADY_IN_USE -23
-#define DRFLAC_BAD_ADDRESS -24
-#define DRFLAC_BAD_SEEK -25
-#define DRFLAC_BAD_PIPE -26
-#define DRFLAC_DEADLOCK -27
-#define DRFLAC_TOO_MANY_LINKS -28
-#define DRFLAC_NOT_IMPLEMENTED -29
-#define DRFLAC_NO_MESSAGE -30
-#define DRFLAC_BAD_MESSAGE -31
-#define DRFLAC_NO_DATA_AVAILABLE -32
-#define DRFLAC_INVALID_DATA -33
-#define DRFLAC_TIMEOUT -34
-#define DRFLAC_NO_NETWORK -35
-#define DRFLAC_NOT_UNIQUE -36
-#define DRFLAC_NOT_SOCKET -37
-#define DRFLAC_NO_ADDRESS -38
-#define DRFLAC_BAD_PROTOCOL -39
-#define DRFLAC_PROTOCOL_UNAVAILABLE -40
-#define DRFLAC_PROTOCOL_NOT_SUPPORTED -41
-#define DRFLAC_PROTOCOL_FAMILY_NOT_SUPPORTED -42
-#define DRFLAC_ADDRESS_FAMILY_NOT_SUPPORTED -43
-#define DRFLAC_SOCKET_NOT_SUPPORTED -44
-#define DRFLAC_CONNECTION_RESET -45
-#define DRFLAC_ALREADY_CONNECTED -46
-#define DRFLAC_NOT_CONNECTED -47
-#define DRFLAC_CONNECTION_REFUSED -48
-#define DRFLAC_NO_HOST -49
-#define DRFLAC_IN_PROGRESS -50
-#define DRFLAC_CANCELLED -51
-#define DRFLAC_MEMORY_ALREADY_MAPPED -52
-#define DRFLAC_AT_END -53
-#define DRFLAC_CRC_MISMATCH -128
-#define DRFLAC_SUBFRAME_CONSTANT 0
-#define DRFLAC_SUBFRAME_VERBATIM 1
-#define DRFLAC_SUBFRAME_FIXED 8
-#define DRFLAC_SUBFRAME_LPC 32
-#define DRFLAC_SUBFRAME_RESERVED 255
-#define DRFLAC_RESIDUAL_CODING_METHOD_PARTITIONED_RICE 0
-#define DRFLAC_RESIDUAL_CODING_METHOD_PARTITIONED_RICE2 1
-#define DRFLAC_CHANNEL_ASSIGNMENT_INDEPENDENT 0
-#define DRFLAC_CHANNEL_ASSIGNMENT_LEFT_SIDE 8
-#define DRFLAC_CHANNEL_ASSIGNMENT_RIGHT_SIDE 9
-#define DRFLAC_CHANNEL_ASSIGNMENT_MID_SIDE 10
-#define DRFLAC_SEEKPOINT_SIZE_IN_BYTES 18
-#define DRFLAC_CUESHEET_TRACK_SIZE_IN_BYTES 36
-#define DRFLAC_CUESHEET_TRACK_INDEX_SIZE_IN_BYTES 12
-#define drflac_align(x, a) ((((x) + (a) - 1) / (a)) * (a))
-DRFLAC_API void drflac_version(drflac_uint32* pMajor, drflac_uint32* pMinor, drflac_uint32* pRevision)
+#define MA_DR_FLAC_ASSERT(expression) assert(expression)
+#endif
+#ifndef MA_DR_FLAC_MALLOC
+#define MA_DR_FLAC_MALLOC(sz) malloc((sz))
+#endif
+#ifndef MA_DR_FLAC_REALLOC
+#define MA_DR_FLAC_REALLOC(p, sz) realloc((p), (sz))
+#endif
+#ifndef MA_DR_FLAC_FREE
+#define MA_DR_FLAC_FREE(p) free((p))
+#endif
+#ifndef MA_DR_FLAC_COPY_MEMORY
+#define MA_DR_FLAC_COPY_MEMORY(dst, src, sz) memcpy((dst), (src), (sz))
+#endif
+#ifndef MA_DR_FLAC_ZERO_MEMORY
+#define MA_DR_FLAC_ZERO_MEMORY(p, sz) memset((p), 0, (sz))
+#endif
+#ifndef MA_DR_FLAC_ZERO_OBJECT
+#define MA_DR_FLAC_ZERO_OBJECT(p) MA_DR_FLAC_ZERO_MEMORY((p), sizeof(*(p)))
+#endif
+#define MA_DR_FLAC_MAX_SIMD_VECTOR_SIZE 64
+#define MA_DR_FLAC_SUBFRAME_CONSTANT 0
+#define MA_DR_FLAC_SUBFRAME_VERBATIM 1
+#define MA_DR_FLAC_SUBFRAME_FIXED 8
+#define MA_DR_FLAC_SUBFRAME_LPC 32
+#define MA_DR_FLAC_SUBFRAME_RESERVED 255
+#define MA_DR_FLAC_RESIDUAL_CODING_METHOD_PARTITIONED_RICE 0
+#define MA_DR_FLAC_RESIDUAL_CODING_METHOD_PARTITIONED_RICE2 1
+#define MA_DR_FLAC_CHANNEL_ASSIGNMENT_INDEPENDENT 0
+#define MA_DR_FLAC_CHANNEL_ASSIGNMENT_LEFT_SIDE 8
+#define MA_DR_FLAC_CHANNEL_ASSIGNMENT_RIGHT_SIDE 9
+#define MA_DR_FLAC_CHANNEL_ASSIGNMENT_MID_SIDE 10
+#define MA_DR_FLAC_SEEKPOINT_SIZE_IN_BYTES 18
+#define MA_DR_FLAC_CUESHEET_TRACK_SIZE_IN_BYTES 36
+#define MA_DR_FLAC_CUESHEET_TRACK_INDEX_SIZE_IN_BYTES 12
+#define ma_dr_flac_align(x, a) ((((x) + (a) - 1) / (a)) * (a))
+MA_API void ma_dr_flac_version(ma_uint32* pMajor, ma_uint32* pMinor, ma_uint32* pRevision)
{
if (pMajor) {
- *pMajor = DRFLAC_VERSION_MAJOR;
+ *pMajor = MA_DR_FLAC_VERSION_MAJOR;
}
if (pMinor) {
- *pMinor = DRFLAC_VERSION_MINOR;
+ *pMinor = MA_DR_FLAC_VERSION_MINOR;
}
if (pRevision) {
- *pRevision = DRFLAC_VERSION_REVISION;
+ *pRevision = MA_DR_FLAC_VERSION_REVISION;
}
}
-DRFLAC_API const char* drflac_version_string(void)
+MA_API const char* ma_dr_flac_version_string(void)
{
- return DRFLAC_VERSION_STRING;
+ return MA_DR_FLAC_VERSION_STRING;
}
#if defined(__has_feature)
#if __has_feature(thread_sanitizer)
- #define DRFLAC_NO_THREAD_SANITIZE __attribute__((no_sanitize("thread")))
+ #define MA_DR_FLAC_NO_THREAD_SANITIZE __attribute__((no_sanitize("thread")))
#else
- #define DRFLAC_NO_THREAD_SANITIZE
+ #define MA_DR_FLAC_NO_THREAD_SANITIZE
#endif
#else
- #define DRFLAC_NO_THREAD_SANITIZE
+ #define MA_DR_FLAC_NO_THREAD_SANITIZE
#endif
-#if defined(DRFLAC_HAS_LZCNT_INTRINSIC)
-static drflac_bool32 drflac__gIsLZCNTSupported = DRFLAC_FALSE;
+#if defined(MA_DR_FLAC_HAS_LZCNT_INTRINSIC)
+static ma_bool32 ma_dr_flac__gIsLZCNTSupported = MA_FALSE;
#endif
-#ifndef DRFLAC_NO_CPUID
-static drflac_bool32 drflac__gIsSSE2Supported = DRFLAC_FALSE;
-static drflac_bool32 drflac__gIsSSE41Supported = DRFLAC_FALSE;
-DRFLAC_NO_THREAD_SANITIZE static void drflac__init_cpu_caps(void)
+#ifndef MA_DR_FLAC_NO_CPUID
+static ma_bool32 ma_dr_flac__gIsSSE2Supported = MA_FALSE;
+static ma_bool32 ma_dr_flac__gIsSSE41Supported = MA_FALSE;
+MA_DR_FLAC_NO_THREAD_SANITIZE static void ma_dr_flac__init_cpu_caps(void)
{
- static drflac_bool32 isCPUCapsInitialized = DRFLAC_FALSE;
+ static ma_bool32 isCPUCapsInitialized = MA_FALSE;
if (!isCPUCapsInitialized) {
-#if defined(DRFLAC_HAS_LZCNT_INTRINSIC)
+#if defined(MA_DR_FLAC_HAS_LZCNT_INTRINSIC)
int info[4] = {0};
- drflac__cpuid(info, 0x80000001);
- drflac__gIsLZCNTSupported = (info[2] & (1 << 5)) != 0;
+ ma_dr_flac__cpuid(info, 0x80000001);
+ ma_dr_flac__gIsLZCNTSupported = (info[2] & (1 << 5)) != 0;
#endif
- drflac__gIsSSE2Supported = drflac_has_sse2();
- drflac__gIsSSE41Supported = drflac_has_sse41();
- isCPUCapsInitialized = DRFLAC_TRUE;
+ ma_dr_flac__gIsSSE2Supported = ma_dr_flac_has_sse2();
+ ma_dr_flac__gIsSSE41Supported = ma_dr_flac_has_sse41();
+ isCPUCapsInitialized = MA_TRUE;
}
}
#else
-static drflac_bool32 drflac__gIsNEONSupported = DRFLAC_FALSE;
-static DRFLAC_INLINE drflac_bool32 drflac__has_neon(void)
+static ma_bool32 ma_dr_flac__gIsNEONSupported = MA_FALSE;
+static MA_INLINE ma_bool32 ma_dr_flac__has_neon(void)
{
-#if defined(DRFLAC_SUPPORT_NEON)
- #if defined(DRFLAC_ARM) && !defined(DRFLAC_NO_NEON)
+#if defined(MA_DR_FLAC_SUPPORT_NEON)
+ #if defined(MA_ARM) && !defined(MA_DR_FLAC_NO_NEON)
#if (defined(__ARM_NEON) || defined(__aarch64__) || defined(_M_ARM64))
- return DRFLAC_TRUE;
+ return MA_TRUE;
#else
- return DRFLAC_FALSE;
+ return MA_FALSE;
#endif
#else
- return DRFLAC_FALSE;
+ return MA_FALSE;
#endif
#else
- return DRFLAC_FALSE;
+ return MA_FALSE;
#endif
}
-DRFLAC_NO_THREAD_SANITIZE static void drflac__init_cpu_caps(void)
+MA_DR_FLAC_NO_THREAD_SANITIZE static void ma_dr_flac__init_cpu_caps(void)
{
- drflac__gIsNEONSupported = drflac__has_neon();
-#if defined(DRFLAC_HAS_LZCNT_INTRINSIC) && defined(DRFLAC_ARM) && (defined(__ARM_ARCH) && __ARM_ARCH >= 5)
- drflac__gIsLZCNTSupported = DRFLAC_TRUE;
+ ma_dr_flac__gIsNEONSupported = ma_dr_flac__has_neon();
+#if defined(MA_DR_FLAC_HAS_LZCNT_INTRINSIC) && defined(MA_ARM) && (defined(__ARM_ARCH) && __ARM_ARCH >= 5)
+ ma_dr_flac__gIsLZCNTSupported = MA_TRUE;
#endif
}
#endif
-static DRFLAC_INLINE drflac_bool32 drflac__is_little_endian(void)
+static MA_INLINE ma_bool32 ma_dr_flac__is_little_endian(void)
{
-#if defined(DRFLAC_X86) || defined(DRFLAC_X64)
- return DRFLAC_TRUE;
+#if defined(MA_X86) || defined(MA_X64)
+ return MA_TRUE;
#elif defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && __BYTE_ORDER == __LITTLE_ENDIAN
- return DRFLAC_TRUE;
+ return MA_TRUE;
#else
int n = 1;
return (*(char*)&n) == 1;
#endif
}
-static DRFLAC_INLINE drflac_uint16 drflac__swap_endian_uint16(drflac_uint16 n)
+static MA_INLINE ma_uint16 ma_dr_flac__swap_endian_uint16(ma_uint16 n)
{
-#ifdef DRFLAC_HAS_BYTESWAP16_INTRINSIC
+#ifdef MA_DR_FLAC_HAS_BYTESWAP16_INTRINSIC
#if defined(_MSC_VER) && !defined(__clang__)
return _byteswap_ushort(n);
#elif defined(__GNUC__) || defined(__clang__)
@@ -79969,16 +82401,16 @@ static DRFLAC_INLINE drflac_uint16 drflac__swap_endian_uint16(drflac_uint16 n)
((n & 0x00FF) << 8);
#endif
}
-static DRFLAC_INLINE drflac_uint32 drflac__swap_endian_uint32(drflac_uint32 n)
+static MA_INLINE ma_uint32 ma_dr_flac__swap_endian_uint32(ma_uint32 n)
{
-#ifdef DRFLAC_HAS_BYTESWAP32_INTRINSIC
+#ifdef MA_DR_FLAC_HAS_BYTESWAP32_INTRINSIC
#if defined(_MSC_VER) && !defined(__clang__)
return _byteswap_ulong(n);
#elif defined(__GNUC__) || defined(__clang__)
- #if defined(DRFLAC_ARM) && (defined(__ARM_ARCH) && __ARM_ARCH >= 6) && !defined(DRFLAC_64BIT)
- drflac_uint32 r;
+ #if defined(MA_ARM) && (defined(__ARM_ARCH) && __ARM_ARCH >= 6) && !defined(__ARM_ARCH_6M__) && !defined(MA_64BIT)
+ ma_uint32 r;
__asm__ __volatile__ (
- #if defined(DRFLAC_64BIT)
+ #if defined(MA_64BIT)
"rev %w[out], %w[in]" : [out]"=r"(r) : [in]"r"(n)
#else
"rev %[out], %[in]" : [out]"=r"(r) : [in]"r"(n)
@@ -80000,9 +82432,9 @@ static DRFLAC_INLINE drflac_uint32 drflac__swap_endian_uint32(drflac_uint32 n)
((n & 0x000000FF) << 24);
#endif
}
-static DRFLAC_INLINE drflac_uint64 drflac__swap_endian_uint64(drflac_uint64 n)
+static MA_INLINE ma_uint64 ma_dr_flac__swap_endian_uint64(ma_uint64 n)
{
-#ifdef DRFLAC_HAS_BYTESWAP64_INTRINSIC
+#ifdef MA_DR_FLAC_HAS_BYTESWAP64_INTRINSIC
#if defined(_MSC_VER) && !defined(__clang__)
return _byteswap_uint64(n);
#elif defined(__GNUC__) || defined(__clang__)
@@ -80013,64 +82445,64 @@ static DRFLAC_INLINE drflac_uint64 drflac__swap_endian_uint64(drflac_uint64 n)
#error "This compiler does not support the byte swap intrinsic."
#endif
#else
- return ((n & ((drflac_uint64)0xFF000000 << 32)) >> 56) |
- ((n & ((drflac_uint64)0x00FF0000 << 32)) >> 40) |
- ((n & ((drflac_uint64)0x0000FF00 << 32)) >> 24) |
- ((n & ((drflac_uint64)0x000000FF << 32)) >> 8) |
- ((n & ((drflac_uint64)0xFF000000 )) << 8) |
- ((n & ((drflac_uint64)0x00FF0000 )) << 24) |
- ((n & ((drflac_uint64)0x0000FF00 )) << 40) |
- ((n & ((drflac_uint64)0x000000FF )) << 56);
+ return ((n & ((ma_uint64)0xFF000000 << 32)) >> 56) |
+ ((n & ((ma_uint64)0x00FF0000 << 32)) >> 40) |
+ ((n & ((ma_uint64)0x0000FF00 << 32)) >> 24) |
+ ((n & ((ma_uint64)0x000000FF << 32)) >> 8) |
+ ((n & ((ma_uint64)0xFF000000 )) << 8) |
+ ((n & ((ma_uint64)0x00FF0000 )) << 24) |
+ ((n & ((ma_uint64)0x0000FF00 )) << 40) |
+ ((n & ((ma_uint64)0x000000FF )) << 56);
#endif
}
-static DRFLAC_INLINE drflac_uint16 drflac__be2host_16(drflac_uint16 n)
+static MA_INLINE ma_uint16 ma_dr_flac__be2host_16(ma_uint16 n)
{
- if (drflac__is_little_endian()) {
- return drflac__swap_endian_uint16(n);
+ if (ma_dr_flac__is_little_endian()) {
+ return ma_dr_flac__swap_endian_uint16(n);
}
return n;
}
-static DRFLAC_INLINE drflac_uint32 drflac__be2host_32(drflac_uint32 n)
+static MA_INLINE ma_uint32 ma_dr_flac__be2host_32(ma_uint32 n)
{
- if (drflac__is_little_endian()) {
- return drflac__swap_endian_uint32(n);
+ if (ma_dr_flac__is_little_endian()) {
+ return ma_dr_flac__swap_endian_uint32(n);
}
return n;
}
-static DRFLAC_INLINE drflac_uint32 drflac__be2host_32_ptr_unaligned(const void* pData)
+static MA_INLINE ma_uint32 ma_dr_flac__be2host_32_ptr_unaligned(const void* pData)
{
- const drflac_uint8* pNum = (drflac_uint8*)pData;
+ const ma_uint8* pNum = (ma_uint8*)pData;
return *(pNum) << 24 | *(pNum+1) << 16 | *(pNum+2) << 8 | *(pNum+3);
}
-static DRFLAC_INLINE drflac_uint64 drflac__be2host_64(drflac_uint64 n)
+static MA_INLINE ma_uint64 ma_dr_flac__be2host_64(ma_uint64 n)
{
- if (drflac__is_little_endian()) {
- return drflac__swap_endian_uint64(n);
+ if (ma_dr_flac__is_little_endian()) {
+ return ma_dr_flac__swap_endian_uint64(n);
}
return n;
}
-static DRFLAC_INLINE drflac_uint32 drflac__le2host_32(drflac_uint32 n)
+static MA_INLINE ma_uint32 ma_dr_flac__le2host_32(ma_uint32 n)
{
- if (!drflac__is_little_endian()) {
- return drflac__swap_endian_uint32(n);
+ if (!ma_dr_flac__is_little_endian()) {
+ return ma_dr_flac__swap_endian_uint32(n);
}
return n;
}
-static DRFLAC_INLINE drflac_uint32 drflac__le2host_32_ptr_unaligned(const void* pData)
+static MA_INLINE ma_uint32 ma_dr_flac__le2host_32_ptr_unaligned(const void* pData)
{
- const drflac_uint8* pNum = (drflac_uint8*)pData;
+ const ma_uint8* pNum = (ma_uint8*)pData;
return *pNum | *(pNum+1) << 8 | *(pNum+2) << 16 | *(pNum+3) << 24;
}
-static DRFLAC_INLINE drflac_uint32 drflac__unsynchsafe_32(drflac_uint32 n)
+static MA_INLINE ma_uint32 ma_dr_flac__unsynchsafe_32(ma_uint32 n)
{
- drflac_uint32 result = 0;
+ ma_uint32 result = 0;
result |= (n & 0x7F000000) >> 3;
result |= (n & 0x007F0000) >> 2;
result |= (n & 0x00007F00) >> 1;
result |= (n & 0x0000007F) >> 0;
return result;
}
-static drflac_uint8 drflac__crc8_table[] = {
+static ma_uint8 ma_dr_flac__crc8_table[] = {
0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15, 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D,
0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65, 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D,
0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5, 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD,
@@ -80088,7 +82520,7 @@ static drflac_uint8 drflac__crc8_table[] = {
0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB, 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83,
0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB, 0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3
};
-static drflac_uint16 drflac__crc16_table[] = {
+static ma_uint16 ma_dr_flac__crc16_table[] = {
0x0000, 0x8005, 0x800F, 0x000A, 0x801B, 0x001E, 0x0014, 0x8011,
0x8033, 0x0036, 0x003C, 0x8039, 0x0028, 0x802D, 0x8027, 0x0022,
0x8063, 0x0066, 0x006C, 0x8069, 0x0078, 0x807D, 0x8077, 0x0072,
@@ -80122,22 +82554,22 @@ static drflac_uint16 drflac__crc16_table[] = {
0x0220, 0x8225, 0x822F, 0x022A, 0x823B, 0x023E, 0x0234, 0x8231,
0x8213, 0x0216, 0x021C, 0x8219, 0x0208, 0x820D, 0x8207, 0x0202
};
-static DRFLAC_INLINE drflac_uint8 drflac_crc8_byte(drflac_uint8 crc, drflac_uint8 data)
+static MA_INLINE ma_uint8 ma_dr_flac_crc8_byte(ma_uint8 crc, ma_uint8 data)
{
- return drflac__crc8_table[crc ^ data];
+ return ma_dr_flac__crc8_table[crc ^ data];
}
-static DRFLAC_INLINE drflac_uint8 drflac_crc8(drflac_uint8 crc, drflac_uint32 data, drflac_uint32 count)
+static MA_INLINE ma_uint8 ma_dr_flac_crc8(ma_uint8 crc, ma_uint32 data, ma_uint32 count)
{
-#ifdef DR_FLAC_NO_CRC
+#ifdef MA_DR_FLAC_NO_CRC
(void)crc;
(void)data;
(void)count;
return 0;
#else
#if 0
- drflac_uint8 p = 0x07;
+ ma_uint8 p = 0x07;
for (int i = count-1; i >= 0; --i) {
- drflac_uint8 bit = (data & (1 << i)) >> i;
+ ma_uint8 bit = (data & (1 << i)) >> i;
if (crc & 0x80) {
crc = ((crc << 1) | bit) ^ p;
} else {
@@ -80146,75 +82578,75 @@ static DRFLAC_INLINE drflac_uint8 drflac_crc8(drflac_uint8 crc, drflac_uint32 da
}
return crc;
#else
- drflac_uint32 wholeBytes;
- drflac_uint32 leftoverBits;
- drflac_uint64 leftoverDataMask;
- static drflac_uint64 leftoverDataMaskTable[8] = {
+ ma_uint32 wholeBytes;
+ ma_uint32 leftoverBits;
+ ma_uint64 leftoverDataMask;
+ static ma_uint64 leftoverDataMaskTable[8] = {
0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F
};
- DRFLAC_ASSERT(count <= 32);
+ MA_DR_FLAC_ASSERT(count <= 32);
wholeBytes = count >> 3;
leftoverBits = count - (wholeBytes*8);
leftoverDataMask = leftoverDataMaskTable[leftoverBits];
switch (wholeBytes) {
- case 4: crc = drflac_crc8_byte(crc, (drflac_uint8)((data & (0xFF000000UL << leftoverBits)) >> (24 + leftoverBits)));
- case 3: crc = drflac_crc8_byte(crc, (drflac_uint8)((data & (0x00FF0000UL << leftoverBits)) >> (16 + leftoverBits)));
- case 2: crc = drflac_crc8_byte(crc, (drflac_uint8)((data & (0x0000FF00UL << leftoverBits)) >> ( 8 + leftoverBits)));
- case 1: crc = drflac_crc8_byte(crc, (drflac_uint8)((data & (0x000000FFUL << leftoverBits)) >> ( 0 + leftoverBits)));
- case 0: if (leftoverBits > 0) crc = (drflac_uint8)((crc << leftoverBits) ^ drflac__crc8_table[(crc >> (8 - leftoverBits)) ^ (data & leftoverDataMask)]);
+ case 4: crc = ma_dr_flac_crc8_byte(crc, (ma_uint8)((data & (0xFF000000UL << leftoverBits)) >> (24 + leftoverBits)));
+ case 3: crc = ma_dr_flac_crc8_byte(crc, (ma_uint8)((data & (0x00FF0000UL << leftoverBits)) >> (16 + leftoverBits)));
+ case 2: crc = ma_dr_flac_crc8_byte(crc, (ma_uint8)((data & (0x0000FF00UL << leftoverBits)) >> ( 8 + leftoverBits)));
+ case 1: crc = ma_dr_flac_crc8_byte(crc, (ma_uint8)((data & (0x000000FFUL << leftoverBits)) >> ( 0 + leftoverBits)));
+ case 0: if (leftoverBits > 0) crc = (ma_uint8)((crc << leftoverBits) ^ ma_dr_flac__crc8_table[(crc >> (8 - leftoverBits)) ^ (data & leftoverDataMask)]);
}
return crc;
#endif
#endif
}
-static DRFLAC_INLINE drflac_uint16 drflac_crc16_byte(drflac_uint16 crc, drflac_uint8 data)
+static MA_INLINE ma_uint16 ma_dr_flac_crc16_byte(ma_uint16 crc, ma_uint8 data)
{
- return (crc << 8) ^ drflac__crc16_table[(drflac_uint8)(crc >> 8) ^ data];
+ return (crc << 8) ^ ma_dr_flac__crc16_table[(ma_uint8)(crc >> 8) ^ data];
}
-static DRFLAC_INLINE drflac_uint16 drflac_crc16_cache(drflac_uint16 crc, drflac_cache_t data)
+static MA_INLINE ma_uint16 ma_dr_flac_crc16_cache(ma_uint16 crc, ma_dr_flac_cache_t data)
{
-#ifdef DRFLAC_64BIT
- crc = drflac_crc16_byte(crc, (drflac_uint8)((data >> 56) & 0xFF));
- crc = drflac_crc16_byte(crc, (drflac_uint8)((data >> 48) & 0xFF));
- crc = drflac_crc16_byte(crc, (drflac_uint8)((data >> 40) & 0xFF));
- crc = drflac_crc16_byte(crc, (drflac_uint8)((data >> 32) & 0xFF));
+#ifdef MA_64BIT
+ crc = ma_dr_flac_crc16_byte(crc, (ma_uint8)((data >> 56) & 0xFF));
+ crc = ma_dr_flac_crc16_byte(crc, (ma_uint8)((data >> 48) & 0xFF));
+ crc = ma_dr_flac_crc16_byte(crc, (ma_uint8)((data >> 40) & 0xFF));
+ crc = ma_dr_flac_crc16_byte(crc, (ma_uint8)((data >> 32) & 0xFF));
#endif
- crc = drflac_crc16_byte(crc, (drflac_uint8)((data >> 24) & 0xFF));
- crc = drflac_crc16_byte(crc, (drflac_uint8)((data >> 16) & 0xFF));
- crc = drflac_crc16_byte(crc, (drflac_uint8)((data >> 8) & 0xFF));
- crc = drflac_crc16_byte(crc, (drflac_uint8)((data >> 0) & 0xFF));
+ crc = ma_dr_flac_crc16_byte(crc, (ma_uint8)((data >> 24) & 0xFF));
+ crc = ma_dr_flac_crc16_byte(crc, (ma_uint8)((data >> 16) & 0xFF));
+ crc = ma_dr_flac_crc16_byte(crc, (ma_uint8)((data >> 8) & 0xFF));
+ crc = ma_dr_flac_crc16_byte(crc, (ma_uint8)((data >> 0) & 0xFF));
return crc;
}
-static DRFLAC_INLINE drflac_uint16 drflac_crc16_bytes(drflac_uint16 crc, drflac_cache_t data, drflac_uint32 byteCount)
+static MA_INLINE ma_uint16 ma_dr_flac_crc16_bytes(ma_uint16 crc, ma_dr_flac_cache_t data, ma_uint32 byteCount)
{
switch (byteCount)
{
-#ifdef DRFLAC_64BIT
- case 8: crc = drflac_crc16_byte(crc, (drflac_uint8)((data >> 56) & 0xFF));
- case 7: crc = drflac_crc16_byte(crc, (drflac_uint8)((data >> 48) & 0xFF));
- case 6: crc = drflac_crc16_byte(crc, (drflac_uint8)((data >> 40) & 0xFF));
- case 5: crc = drflac_crc16_byte(crc, (drflac_uint8)((data >> 32) & 0xFF));
+#ifdef MA_64BIT
+ case 8: crc = ma_dr_flac_crc16_byte(crc, (ma_uint8)((data >> 56) & 0xFF));
+ case 7: crc = ma_dr_flac_crc16_byte(crc, (ma_uint8)((data >> 48) & 0xFF));
+ case 6: crc = ma_dr_flac_crc16_byte(crc, (ma_uint8)((data >> 40) & 0xFF));
+ case 5: crc = ma_dr_flac_crc16_byte(crc, (ma_uint8)((data >> 32) & 0xFF));
#endif
- case 4: crc = drflac_crc16_byte(crc, (drflac_uint8)((data >> 24) & 0xFF));
- case 3: crc = drflac_crc16_byte(crc, (drflac_uint8)((data >> 16) & 0xFF));
- case 2: crc = drflac_crc16_byte(crc, (drflac_uint8)((data >> 8) & 0xFF));
- case 1: crc = drflac_crc16_byte(crc, (drflac_uint8)((data >> 0) & 0xFF));
+ case 4: crc = ma_dr_flac_crc16_byte(crc, (ma_uint8)((data >> 24) & 0xFF));
+ case 3: crc = ma_dr_flac_crc16_byte(crc, (ma_uint8)((data >> 16) & 0xFF));
+ case 2: crc = ma_dr_flac_crc16_byte(crc, (ma_uint8)((data >> 8) & 0xFF));
+ case 1: crc = ma_dr_flac_crc16_byte(crc, (ma_uint8)((data >> 0) & 0xFF));
}
return crc;
}
#if 0
-static DRFLAC_INLINE drflac_uint16 drflac_crc16__32bit(drflac_uint16 crc, drflac_uint32 data, drflac_uint32 count)
+static MA_INLINE ma_uint16 ma_dr_flac_crc16__32bit(ma_uint16 crc, ma_uint32 data, ma_uint32 count)
{
-#ifdef DR_FLAC_NO_CRC
+#ifdef MA_DR_FLAC_NO_CRC
(void)crc;
(void)data;
(void)count;
return 0;
#else
#if 0
- drflac_uint16 p = 0x8005;
+ ma_uint16 p = 0x8005;
for (int i = count-1; i >= 0; --i) {
- drflac_uint16 bit = (data & (1ULL << i)) >> i;
+ ma_uint16 bit = (data & (1ULL << i)) >> i;
if (r & 0x8000) {
r = ((r << 1) | bit) ^ p;
} else {
@@ -80223,433 +82655,433 @@ static DRFLAC_INLINE drflac_uint16 drflac_crc16__32bit(drflac_uint16 crc, drflac
}
return crc;
#else
- drflac_uint32 wholeBytes;
- drflac_uint32 leftoverBits;
- drflac_uint64 leftoverDataMask;
- static drflac_uint64 leftoverDataMaskTable[8] = {
+ ma_uint32 wholeBytes;
+ ma_uint32 leftoverBits;
+ ma_uint64 leftoverDataMask;
+ static ma_uint64 leftoverDataMaskTable[8] = {
0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F
};
- DRFLAC_ASSERT(count <= 64);
+ MA_DR_FLAC_ASSERT(count <= 64);
wholeBytes = count >> 3;
leftoverBits = count & 7;
leftoverDataMask = leftoverDataMaskTable[leftoverBits];
switch (wholeBytes) {
default:
- case 4: crc = drflac_crc16_byte(crc, (drflac_uint8)((data & (0xFF000000UL << leftoverBits)) >> (24 + leftoverBits)));
- case 3: crc = drflac_crc16_byte(crc, (drflac_uint8)((data & (0x00FF0000UL << leftoverBits)) >> (16 + leftoverBits)));
- case 2: crc = drflac_crc16_byte(crc, (drflac_uint8)((data & (0x0000FF00UL << leftoverBits)) >> ( 8 + leftoverBits)));
- case 1: crc = drflac_crc16_byte(crc, (drflac_uint8)((data & (0x000000FFUL << leftoverBits)) >> ( 0 + leftoverBits)));
- case 0: if (leftoverBits > 0) crc = (crc << leftoverBits) ^ drflac__crc16_table[(crc >> (16 - leftoverBits)) ^ (data & leftoverDataMask)];
+ case 4: crc = ma_dr_flac_crc16_byte(crc, (ma_uint8)((data & (0xFF000000UL << leftoverBits)) >> (24 + leftoverBits)));
+ case 3: crc = ma_dr_flac_crc16_byte(crc, (ma_uint8)((data & (0x00FF0000UL << leftoverBits)) >> (16 + leftoverBits)));
+ case 2: crc = ma_dr_flac_crc16_byte(crc, (ma_uint8)((data & (0x0000FF00UL << leftoverBits)) >> ( 8 + leftoverBits)));
+ case 1: crc = ma_dr_flac_crc16_byte(crc, (ma_uint8)((data & (0x000000FFUL << leftoverBits)) >> ( 0 + leftoverBits)));
+ case 0: if (leftoverBits > 0) crc = (crc << leftoverBits) ^ ma_dr_flac__crc16_table[(crc >> (16 - leftoverBits)) ^ (data & leftoverDataMask)];
}
return crc;
#endif
#endif
}
-static DRFLAC_INLINE drflac_uint16 drflac_crc16__64bit(drflac_uint16 crc, drflac_uint64 data, drflac_uint32 count)
+static MA_INLINE ma_uint16 ma_dr_flac_crc16__64bit(ma_uint16 crc, ma_uint64 data, ma_uint32 count)
{
-#ifdef DR_FLAC_NO_CRC
+#ifdef MA_DR_FLAC_NO_CRC
(void)crc;
(void)data;
(void)count;
return 0;
#else
- drflac_uint32 wholeBytes;
- drflac_uint32 leftoverBits;
- drflac_uint64 leftoverDataMask;
- static drflac_uint64 leftoverDataMaskTable[8] = {
+ ma_uint32 wholeBytes;
+ ma_uint32 leftoverBits;
+ ma_uint64 leftoverDataMask;
+ static ma_uint64 leftoverDataMaskTable[8] = {
0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F
};
- DRFLAC_ASSERT(count <= 64);
+ MA_DR_FLAC_ASSERT(count <= 64);
wholeBytes = count >> 3;
leftoverBits = count & 7;
leftoverDataMask = leftoverDataMaskTable[leftoverBits];
switch (wholeBytes) {
default:
- case 8: crc = drflac_crc16_byte(crc, (drflac_uint8)((data & (((drflac_uint64)0xFF000000 << 32) << leftoverBits)) >> (56 + leftoverBits)));
- case 7: crc = drflac_crc16_byte(crc, (drflac_uint8)((data & (((drflac_uint64)0x00FF0000 << 32) << leftoverBits)) >> (48 + leftoverBits)));
- case 6: crc = drflac_crc16_byte(crc, (drflac_uint8)((data & (((drflac_uint64)0x0000FF00 << 32) << leftoverBits)) >> (40 + leftoverBits)));
- case 5: crc = drflac_crc16_byte(crc, (drflac_uint8)((data & (((drflac_uint64)0x000000FF << 32) << leftoverBits)) >> (32 + leftoverBits)));
- case 4: crc = drflac_crc16_byte(crc, (drflac_uint8)((data & (((drflac_uint64)0xFF000000 ) << leftoverBits)) >> (24 + leftoverBits)));
- case 3: crc = drflac_crc16_byte(crc, (drflac_uint8)((data & (((drflac_uint64)0x00FF0000 ) << leftoverBits)) >> (16 + leftoverBits)));
- case 2: crc = drflac_crc16_byte(crc, (drflac_uint8)((data & (((drflac_uint64)0x0000FF00 ) << leftoverBits)) >> ( 8 + leftoverBits)));
- case 1: crc = drflac_crc16_byte(crc, (drflac_uint8)((data & (((drflac_uint64)0x000000FF ) << leftoverBits)) >> ( 0 + leftoverBits)));
- case 0: if (leftoverBits > 0) crc = (crc << leftoverBits) ^ drflac__crc16_table[(crc >> (16 - leftoverBits)) ^ (data & leftoverDataMask)];
+ case 8: crc = ma_dr_flac_crc16_byte(crc, (ma_uint8)((data & (((ma_uint64)0xFF000000 << 32) << leftoverBits)) >> (56 + leftoverBits)));
+ case 7: crc = ma_dr_flac_crc16_byte(crc, (ma_uint8)((data & (((ma_uint64)0x00FF0000 << 32) << leftoverBits)) >> (48 + leftoverBits)));
+ case 6: crc = ma_dr_flac_crc16_byte(crc, (ma_uint8)((data & (((ma_uint64)0x0000FF00 << 32) << leftoverBits)) >> (40 + leftoverBits)));
+ case 5: crc = ma_dr_flac_crc16_byte(crc, (ma_uint8)((data & (((ma_uint64)0x000000FF << 32) << leftoverBits)) >> (32 + leftoverBits)));
+ case 4: crc = ma_dr_flac_crc16_byte(crc, (ma_uint8)((data & (((ma_uint64)0xFF000000 ) << leftoverBits)) >> (24 + leftoverBits)));
+ case 3: crc = ma_dr_flac_crc16_byte(crc, (ma_uint8)((data & (((ma_uint64)0x00FF0000 ) << leftoverBits)) >> (16 + leftoverBits)));
+ case 2: crc = ma_dr_flac_crc16_byte(crc, (ma_uint8)((data & (((ma_uint64)0x0000FF00 ) << leftoverBits)) >> ( 8 + leftoverBits)));
+ case 1: crc = ma_dr_flac_crc16_byte(crc, (ma_uint8)((data & (((ma_uint64)0x000000FF ) << leftoverBits)) >> ( 0 + leftoverBits)));
+ case 0: if (leftoverBits > 0) crc = (crc << leftoverBits) ^ ma_dr_flac__crc16_table[(crc >> (16 - leftoverBits)) ^ (data & leftoverDataMask)];
}
return crc;
#endif
}
-static DRFLAC_INLINE drflac_uint16 drflac_crc16(drflac_uint16 crc, drflac_cache_t data, drflac_uint32 count)
+static MA_INLINE ma_uint16 ma_dr_flac_crc16(ma_uint16 crc, ma_dr_flac_cache_t data, ma_uint32 count)
{
-#ifdef DRFLAC_64BIT
- return drflac_crc16__64bit(crc, data, count);
+#ifdef MA_64BIT
+ return ma_dr_flac_crc16__64bit(crc, data, count);
#else
- return drflac_crc16__32bit(crc, data, count);
+ return ma_dr_flac_crc16__32bit(crc, data, count);
#endif
}
#endif
-#ifdef DRFLAC_64BIT
-#define drflac__be2host__cache_line drflac__be2host_64
+#ifdef MA_64BIT
+#define ma_dr_flac__be2host__cache_line ma_dr_flac__be2host_64
#else
-#define drflac__be2host__cache_line drflac__be2host_32
-#endif
-#define DRFLAC_CACHE_L1_SIZE_BYTES(bs) (sizeof((bs)->cache))
-#define DRFLAC_CACHE_L1_SIZE_BITS(bs) (sizeof((bs)->cache)*8)
-#define DRFLAC_CACHE_L1_BITS_REMAINING(bs) (DRFLAC_CACHE_L1_SIZE_BITS(bs) - (bs)->consumedBits)
-#define DRFLAC_CACHE_L1_SELECTION_MASK(_bitCount) (~((~(drflac_cache_t)0) >> (_bitCount)))
-#define DRFLAC_CACHE_L1_SELECTION_SHIFT(bs, _bitCount) (DRFLAC_CACHE_L1_SIZE_BITS(bs) - (_bitCount))
-#define DRFLAC_CACHE_L1_SELECT(bs, _bitCount) (((bs)->cache) & DRFLAC_CACHE_L1_SELECTION_MASK(_bitCount))
-#define DRFLAC_CACHE_L1_SELECT_AND_SHIFT(bs, _bitCount) (DRFLAC_CACHE_L1_SELECT((bs), (_bitCount)) >> DRFLAC_CACHE_L1_SELECTION_SHIFT((bs), (_bitCount)))
-#define DRFLAC_CACHE_L1_SELECT_AND_SHIFT_SAFE(bs, _bitCount)(DRFLAC_CACHE_L1_SELECT((bs), (_bitCount)) >> (DRFLAC_CACHE_L1_SELECTION_SHIFT((bs), (_bitCount)) & (DRFLAC_CACHE_L1_SIZE_BITS(bs)-1)))
-#define DRFLAC_CACHE_L2_SIZE_BYTES(bs) (sizeof((bs)->cacheL2))
-#define DRFLAC_CACHE_L2_LINE_COUNT(bs) (DRFLAC_CACHE_L2_SIZE_BYTES(bs) / sizeof((bs)->cacheL2[0]))
-#define DRFLAC_CACHE_L2_LINES_REMAINING(bs) (DRFLAC_CACHE_L2_LINE_COUNT(bs) - (bs)->nextL2Line)
-#ifndef DR_FLAC_NO_CRC
-static DRFLAC_INLINE void drflac__reset_crc16(drflac_bs* bs)
+#define ma_dr_flac__be2host__cache_line ma_dr_flac__be2host_32
+#endif
+#define MA_DR_FLAC_CACHE_L1_SIZE_BYTES(bs) (sizeof((bs)->cache))
+#define MA_DR_FLAC_CACHE_L1_SIZE_BITS(bs) (sizeof((bs)->cache)*8)
+#define MA_DR_FLAC_CACHE_L1_BITS_REMAINING(bs) (MA_DR_FLAC_CACHE_L1_SIZE_BITS(bs) - (bs)->consumedBits)
+#define MA_DR_FLAC_CACHE_L1_SELECTION_MASK(_bitCount) (~((~(ma_dr_flac_cache_t)0) >> (_bitCount)))
+#define MA_DR_FLAC_CACHE_L1_SELECTION_SHIFT(bs, _bitCount) (MA_DR_FLAC_CACHE_L1_SIZE_BITS(bs) - (_bitCount))
+#define MA_DR_FLAC_CACHE_L1_SELECT(bs, _bitCount) (((bs)->cache) & MA_DR_FLAC_CACHE_L1_SELECTION_MASK(_bitCount))
+#define MA_DR_FLAC_CACHE_L1_SELECT_AND_SHIFT(bs, _bitCount) (MA_DR_FLAC_CACHE_L1_SELECT((bs), (_bitCount)) >> MA_DR_FLAC_CACHE_L1_SELECTION_SHIFT((bs), (_bitCount)))
+#define MA_DR_FLAC_CACHE_L1_SELECT_AND_SHIFT_SAFE(bs, _bitCount)(MA_DR_FLAC_CACHE_L1_SELECT((bs), (_bitCount)) >> (MA_DR_FLAC_CACHE_L1_SELECTION_SHIFT((bs), (_bitCount)) & (MA_DR_FLAC_CACHE_L1_SIZE_BITS(bs)-1)))
+#define MA_DR_FLAC_CACHE_L2_SIZE_BYTES(bs) (sizeof((bs)->cacheL2))
+#define MA_DR_FLAC_CACHE_L2_LINE_COUNT(bs) (MA_DR_FLAC_CACHE_L2_SIZE_BYTES(bs) / sizeof((bs)->cacheL2[0]))
+#define MA_DR_FLAC_CACHE_L2_LINES_REMAINING(bs) (MA_DR_FLAC_CACHE_L2_LINE_COUNT(bs) - (bs)->nextL2Line)
+#ifndef MA_DR_FLAC_NO_CRC
+static MA_INLINE void ma_dr_flac__reset_crc16(ma_dr_flac_bs* bs)
{
bs->crc16 = 0;
bs->crc16CacheIgnoredBytes = bs->consumedBits >> 3;
}
-static DRFLAC_INLINE void drflac__update_crc16(drflac_bs* bs)
+static MA_INLINE void ma_dr_flac__update_crc16(ma_dr_flac_bs* bs)
{
if (bs->crc16CacheIgnoredBytes == 0) {
- bs->crc16 = drflac_crc16_cache(bs->crc16, bs->crc16Cache);
+ bs->crc16 = ma_dr_flac_crc16_cache(bs->crc16, bs->crc16Cache);
} else {
- bs->crc16 = drflac_crc16_bytes(bs->crc16, bs->crc16Cache, DRFLAC_CACHE_L1_SIZE_BYTES(bs) - bs->crc16CacheIgnoredBytes);
+ bs->crc16 = ma_dr_flac_crc16_bytes(bs->crc16, bs->crc16Cache, MA_DR_FLAC_CACHE_L1_SIZE_BYTES(bs) - bs->crc16CacheIgnoredBytes);
bs->crc16CacheIgnoredBytes = 0;
}
}
-static DRFLAC_INLINE drflac_uint16 drflac__flush_crc16(drflac_bs* bs)
+static MA_INLINE ma_uint16 ma_dr_flac__flush_crc16(ma_dr_flac_bs* bs)
{
- DRFLAC_ASSERT((DRFLAC_CACHE_L1_BITS_REMAINING(bs) & 7) == 0);
- if (DRFLAC_CACHE_L1_BITS_REMAINING(bs) == 0) {
- drflac__update_crc16(bs);
+ MA_DR_FLAC_ASSERT((MA_DR_FLAC_CACHE_L1_BITS_REMAINING(bs) & 7) == 0);
+ if (MA_DR_FLAC_CACHE_L1_BITS_REMAINING(bs) == 0) {
+ ma_dr_flac__update_crc16(bs);
} else {
- bs->crc16 = drflac_crc16_bytes(bs->crc16, bs->crc16Cache >> DRFLAC_CACHE_L1_BITS_REMAINING(bs), (bs->consumedBits >> 3) - bs->crc16CacheIgnoredBytes);
+ bs->crc16 = ma_dr_flac_crc16_bytes(bs->crc16, bs->crc16Cache >> MA_DR_FLAC_CACHE_L1_BITS_REMAINING(bs), (bs->consumedBits >> 3) - bs->crc16CacheIgnoredBytes);
bs->crc16CacheIgnoredBytes = bs->consumedBits >> 3;
}
return bs->crc16;
}
#endif
-static DRFLAC_INLINE drflac_bool32 drflac__reload_l1_cache_from_l2(drflac_bs* bs)
+static MA_INLINE ma_bool32 ma_dr_flac__reload_l1_cache_from_l2(ma_dr_flac_bs* bs)
{
size_t bytesRead;
size_t alignedL1LineCount;
- if (bs->nextL2Line < DRFLAC_CACHE_L2_LINE_COUNT(bs)) {
+ if (bs->nextL2Line < MA_DR_FLAC_CACHE_L2_LINE_COUNT(bs)) {
bs->cache = bs->cacheL2[bs->nextL2Line++];
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
if (bs->unalignedByteCount > 0) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
- bytesRead = bs->onRead(bs->pUserData, bs->cacheL2, DRFLAC_CACHE_L2_SIZE_BYTES(bs));
+ bytesRead = bs->onRead(bs->pUserData, bs->cacheL2, MA_DR_FLAC_CACHE_L2_SIZE_BYTES(bs));
bs->nextL2Line = 0;
- if (bytesRead == DRFLAC_CACHE_L2_SIZE_BYTES(bs)) {
+ if (bytesRead == MA_DR_FLAC_CACHE_L2_SIZE_BYTES(bs)) {
bs->cache = bs->cacheL2[bs->nextL2Line++];
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
- alignedL1LineCount = bytesRead / DRFLAC_CACHE_L1_SIZE_BYTES(bs);
- bs->unalignedByteCount = bytesRead - (alignedL1LineCount * DRFLAC_CACHE_L1_SIZE_BYTES(bs));
+ alignedL1LineCount = bytesRead / MA_DR_FLAC_CACHE_L1_SIZE_BYTES(bs);
+ bs->unalignedByteCount = bytesRead - (alignedL1LineCount * MA_DR_FLAC_CACHE_L1_SIZE_BYTES(bs));
if (bs->unalignedByteCount > 0) {
bs->unalignedCache = bs->cacheL2[alignedL1LineCount];
}
if (alignedL1LineCount > 0) {
- size_t offset = DRFLAC_CACHE_L2_LINE_COUNT(bs) - alignedL1LineCount;
+ size_t offset = MA_DR_FLAC_CACHE_L2_LINE_COUNT(bs) - alignedL1LineCount;
size_t i;
for (i = alignedL1LineCount; i > 0; --i) {
bs->cacheL2[i-1 + offset] = bs->cacheL2[i-1];
}
- bs->nextL2Line = (drflac_uint32)offset;
+ bs->nextL2Line = (ma_uint32)offset;
bs->cache = bs->cacheL2[bs->nextL2Line++];
- return DRFLAC_TRUE;
+ return MA_TRUE;
} else {
- bs->nextL2Line = DRFLAC_CACHE_L2_LINE_COUNT(bs);
- return DRFLAC_FALSE;
+ bs->nextL2Line = MA_DR_FLAC_CACHE_L2_LINE_COUNT(bs);
+ return MA_FALSE;
}
}
-static drflac_bool32 drflac__reload_cache(drflac_bs* bs)
+static ma_bool32 ma_dr_flac__reload_cache(ma_dr_flac_bs* bs)
{
size_t bytesRead;
-#ifndef DR_FLAC_NO_CRC
- drflac__update_crc16(bs);
+#ifndef MA_DR_FLAC_NO_CRC
+ ma_dr_flac__update_crc16(bs);
#endif
- if (drflac__reload_l1_cache_from_l2(bs)) {
- bs->cache = drflac__be2host__cache_line(bs->cache);
+ if (ma_dr_flac__reload_l1_cache_from_l2(bs)) {
+ bs->cache = ma_dr_flac__be2host__cache_line(bs->cache);
bs->consumedBits = 0;
-#ifndef DR_FLAC_NO_CRC
+#ifndef MA_DR_FLAC_NO_CRC
bs->crc16Cache = bs->cache;
#endif
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
bytesRead = bs->unalignedByteCount;
if (bytesRead == 0) {
- bs->consumedBits = DRFLAC_CACHE_L1_SIZE_BITS(bs);
- return DRFLAC_FALSE;
+ bs->consumedBits = MA_DR_FLAC_CACHE_L1_SIZE_BITS(bs);
+ return MA_FALSE;
}
- DRFLAC_ASSERT(bytesRead < DRFLAC_CACHE_L1_SIZE_BYTES(bs));
- bs->consumedBits = (drflac_uint32)(DRFLAC_CACHE_L1_SIZE_BYTES(bs) - bytesRead) * 8;
- bs->cache = drflac__be2host__cache_line(bs->unalignedCache);
- bs->cache &= DRFLAC_CACHE_L1_SELECTION_MASK(DRFLAC_CACHE_L1_BITS_REMAINING(bs));
+ MA_DR_FLAC_ASSERT(bytesRead < MA_DR_FLAC_CACHE_L1_SIZE_BYTES(bs));
+ bs->consumedBits = (ma_uint32)(MA_DR_FLAC_CACHE_L1_SIZE_BYTES(bs) - bytesRead) * 8;
+ bs->cache = ma_dr_flac__be2host__cache_line(bs->unalignedCache);
+ bs->cache &= MA_DR_FLAC_CACHE_L1_SELECTION_MASK(MA_DR_FLAC_CACHE_L1_BITS_REMAINING(bs));
bs->unalignedByteCount = 0;
-#ifndef DR_FLAC_NO_CRC
+#ifndef MA_DR_FLAC_NO_CRC
bs->crc16Cache = bs->cache >> bs->consumedBits;
bs->crc16CacheIgnoredBytes = bs->consumedBits >> 3;
#endif
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
-static void drflac__reset_cache(drflac_bs* bs)
+static void ma_dr_flac__reset_cache(ma_dr_flac_bs* bs)
{
- bs->nextL2Line = DRFLAC_CACHE_L2_LINE_COUNT(bs);
- bs->consumedBits = DRFLAC_CACHE_L1_SIZE_BITS(bs);
+ bs->nextL2Line = MA_DR_FLAC_CACHE_L2_LINE_COUNT(bs);
+ bs->consumedBits = MA_DR_FLAC_CACHE_L1_SIZE_BITS(bs);
bs->cache = 0;
bs->unalignedByteCount = 0;
bs->unalignedCache = 0;
-#ifndef DR_FLAC_NO_CRC
+#ifndef MA_DR_FLAC_NO_CRC
bs->crc16Cache = 0;
bs->crc16CacheIgnoredBytes = 0;
#endif
}
-static DRFLAC_INLINE drflac_bool32 drflac__read_uint32(drflac_bs* bs, unsigned int bitCount, drflac_uint32* pResultOut)
+static MA_INLINE ma_bool32 ma_dr_flac__read_uint32(ma_dr_flac_bs* bs, unsigned int bitCount, ma_uint32* pResultOut)
{
- DRFLAC_ASSERT(bs != NULL);
- DRFLAC_ASSERT(pResultOut != NULL);
- DRFLAC_ASSERT(bitCount > 0);
- DRFLAC_ASSERT(bitCount <= 32);
- if (bs->consumedBits == DRFLAC_CACHE_L1_SIZE_BITS(bs)) {
- if (!drflac__reload_cache(bs)) {
- return DRFLAC_FALSE;
+ MA_DR_FLAC_ASSERT(bs != NULL);
+ MA_DR_FLAC_ASSERT(pResultOut != NULL);
+ MA_DR_FLAC_ASSERT(bitCount > 0);
+ MA_DR_FLAC_ASSERT(bitCount <= 32);
+ if (bs->consumedBits == MA_DR_FLAC_CACHE_L1_SIZE_BITS(bs)) {
+ if (!ma_dr_flac__reload_cache(bs)) {
+ return MA_FALSE;
}
}
- if (bitCount <= DRFLAC_CACHE_L1_BITS_REMAINING(bs)) {
-#ifdef DRFLAC_64BIT
- *pResultOut = (drflac_uint32)DRFLAC_CACHE_L1_SELECT_AND_SHIFT(bs, bitCount);
+ if (bitCount <= MA_DR_FLAC_CACHE_L1_BITS_REMAINING(bs)) {
+#ifdef MA_64BIT
+ *pResultOut = (ma_uint32)MA_DR_FLAC_CACHE_L1_SELECT_AND_SHIFT(bs, bitCount);
bs->consumedBits += bitCount;
bs->cache <<= bitCount;
#else
- if (bitCount < DRFLAC_CACHE_L1_SIZE_BITS(bs)) {
- *pResultOut = (drflac_uint32)DRFLAC_CACHE_L1_SELECT_AND_SHIFT(bs, bitCount);
+ if (bitCount < MA_DR_FLAC_CACHE_L1_SIZE_BITS(bs)) {
+ *pResultOut = (ma_uint32)MA_DR_FLAC_CACHE_L1_SELECT_AND_SHIFT(bs, bitCount);
bs->consumedBits += bitCount;
bs->cache <<= bitCount;
} else {
- *pResultOut = (drflac_uint32)bs->cache;
- bs->consumedBits = DRFLAC_CACHE_L1_SIZE_BITS(bs);
+ *pResultOut = (ma_uint32)bs->cache;
+ bs->consumedBits = MA_DR_FLAC_CACHE_L1_SIZE_BITS(bs);
bs->cache = 0;
}
#endif
- return DRFLAC_TRUE;
+ return MA_TRUE;
} else {
- drflac_uint32 bitCountHi = DRFLAC_CACHE_L1_BITS_REMAINING(bs);
- drflac_uint32 bitCountLo = bitCount - bitCountHi;
- drflac_uint32 resultHi;
- DRFLAC_ASSERT(bitCountHi > 0);
- DRFLAC_ASSERT(bitCountHi < 32);
- resultHi = (drflac_uint32)DRFLAC_CACHE_L1_SELECT_AND_SHIFT(bs, bitCountHi);
- if (!drflac__reload_cache(bs)) {
- return DRFLAC_FALSE;
- }
- if (bitCountLo > DRFLAC_CACHE_L1_BITS_REMAINING(bs)) {
- return DRFLAC_FALSE;
- }
- *pResultOut = (resultHi << bitCountLo) | (drflac_uint32)DRFLAC_CACHE_L1_SELECT_AND_SHIFT(bs, bitCountLo);
+ ma_uint32 bitCountHi = MA_DR_FLAC_CACHE_L1_BITS_REMAINING(bs);
+ ma_uint32 bitCountLo = bitCount - bitCountHi;
+ ma_uint32 resultHi;
+ MA_DR_FLAC_ASSERT(bitCountHi > 0);
+ MA_DR_FLAC_ASSERT(bitCountHi < 32);
+ resultHi = (ma_uint32)MA_DR_FLAC_CACHE_L1_SELECT_AND_SHIFT(bs, bitCountHi);
+ if (!ma_dr_flac__reload_cache(bs)) {
+ return MA_FALSE;
+ }
+ if (bitCountLo > MA_DR_FLAC_CACHE_L1_BITS_REMAINING(bs)) {
+ return MA_FALSE;
+ }
+ *pResultOut = (resultHi << bitCountLo) | (ma_uint32)MA_DR_FLAC_CACHE_L1_SELECT_AND_SHIFT(bs, bitCountLo);
bs->consumedBits += bitCountLo;
bs->cache <<= bitCountLo;
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
}
-static drflac_bool32 drflac__read_int32(drflac_bs* bs, unsigned int bitCount, drflac_int32* pResult)
+static ma_bool32 ma_dr_flac__read_int32(ma_dr_flac_bs* bs, unsigned int bitCount, ma_int32* pResult)
{
- drflac_uint32 result;
- DRFLAC_ASSERT(bs != NULL);
- DRFLAC_ASSERT(pResult != NULL);
- DRFLAC_ASSERT(bitCount > 0);
- DRFLAC_ASSERT(bitCount <= 32);
- if (!drflac__read_uint32(bs, bitCount, &result)) {
- return DRFLAC_FALSE;
+ ma_uint32 result;
+ MA_DR_FLAC_ASSERT(bs != NULL);
+ MA_DR_FLAC_ASSERT(pResult != NULL);
+ MA_DR_FLAC_ASSERT(bitCount > 0);
+ MA_DR_FLAC_ASSERT(bitCount <= 32);
+ if (!ma_dr_flac__read_uint32(bs, bitCount, &result)) {
+ return MA_FALSE;
}
if (bitCount < 32) {
- drflac_uint32 signbit;
+ ma_uint32 signbit;
signbit = ((result >> (bitCount-1)) & 0x01);
result |= (~signbit + 1) << bitCount;
}
- *pResult = (drflac_int32)result;
- return DRFLAC_TRUE;
+ *pResult = (ma_int32)result;
+ return MA_TRUE;
}
-#ifdef DRFLAC_64BIT
-static drflac_bool32 drflac__read_uint64(drflac_bs* bs, unsigned int bitCount, drflac_uint64* pResultOut)
+#ifdef MA_64BIT
+static ma_bool32 ma_dr_flac__read_uint64(ma_dr_flac_bs* bs, unsigned int bitCount, ma_uint64* pResultOut)
{
- drflac_uint32 resultHi;
- drflac_uint32 resultLo;
- DRFLAC_ASSERT(bitCount <= 64);
- DRFLAC_ASSERT(bitCount > 32);
- if (!drflac__read_uint32(bs, bitCount - 32, &resultHi)) {
- return DRFLAC_FALSE;
+ ma_uint32 resultHi;
+ ma_uint32 resultLo;
+ MA_DR_FLAC_ASSERT(bitCount <= 64);
+ MA_DR_FLAC_ASSERT(bitCount > 32);
+ if (!ma_dr_flac__read_uint32(bs, bitCount - 32, &resultHi)) {
+ return MA_FALSE;
}
- if (!drflac__read_uint32(bs, 32, &resultLo)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_uint32(bs, 32, &resultLo)) {
+ return MA_FALSE;
}
- *pResultOut = (((drflac_uint64)resultHi) << 32) | ((drflac_uint64)resultLo);
- return DRFLAC_TRUE;
+ *pResultOut = (((ma_uint64)resultHi) << 32) | ((ma_uint64)resultLo);
+ return MA_TRUE;
}
#endif
#if 0
-static drflac_bool32 drflac__read_int64(drflac_bs* bs, unsigned int bitCount, drflac_int64* pResultOut)
+static ma_bool32 ma_dr_flac__read_int64(ma_dr_flac_bs* bs, unsigned int bitCount, ma_int64* pResultOut)
{
- drflac_uint64 result;
- drflac_uint64 signbit;
- DRFLAC_ASSERT(bitCount <= 64);
- if (!drflac__read_uint64(bs, bitCount, &result)) {
- return DRFLAC_FALSE;
+ ma_uint64 result;
+ ma_uint64 signbit;
+ MA_DR_FLAC_ASSERT(bitCount <= 64);
+ if (!ma_dr_flac__read_uint64(bs, bitCount, &result)) {
+ return MA_FALSE;
}
signbit = ((result >> (bitCount-1)) & 0x01);
result |= (~signbit + 1) << bitCount;
- *pResultOut = (drflac_int64)result;
- return DRFLAC_TRUE;
+ *pResultOut = (ma_int64)result;
+ return MA_TRUE;
}
#endif
-static drflac_bool32 drflac__read_uint16(drflac_bs* bs, unsigned int bitCount, drflac_uint16* pResult)
+static ma_bool32 ma_dr_flac__read_uint16(ma_dr_flac_bs* bs, unsigned int bitCount, ma_uint16* pResult)
{
- drflac_uint32 result;
- DRFLAC_ASSERT(bs != NULL);
- DRFLAC_ASSERT(pResult != NULL);
- DRFLAC_ASSERT(bitCount > 0);
- DRFLAC_ASSERT(bitCount <= 16);
- if (!drflac__read_uint32(bs, bitCount, &result)) {
- return DRFLAC_FALSE;
+ ma_uint32 result;
+ MA_DR_FLAC_ASSERT(bs != NULL);
+ MA_DR_FLAC_ASSERT(pResult != NULL);
+ MA_DR_FLAC_ASSERT(bitCount > 0);
+ MA_DR_FLAC_ASSERT(bitCount <= 16);
+ if (!ma_dr_flac__read_uint32(bs, bitCount, &result)) {
+ return MA_FALSE;
}
- *pResult = (drflac_uint16)result;
- return DRFLAC_TRUE;
+ *pResult = (ma_uint16)result;
+ return MA_TRUE;
}
#if 0
-static drflac_bool32 drflac__read_int16(drflac_bs* bs, unsigned int bitCount, drflac_int16* pResult)
-{
- drflac_int32 result;
- DRFLAC_ASSERT(bs != NULL);
- DRFLAC_ASSERT(pResult != NULL);
- DRFLAC_ASSERT(bitCount > 0);
- DRFLAC_ASSERT(bitCount <= 16);
- if (!drflac__read_int32(bs, bitCount, &result)) {
- return DRFLAC_FALSE;
+static ma_bool32 ma_dr_flac__read_int16(ma_dr_flac_bs* bs, unsigned int bitCount, ma_int16* pResult)
+{
+ ma_int32 result;
+ MA_DR_FLAC_ASSERT(bs != NULL);
+ MA_DR_FLAC_ASSERT(pResult != NULL);
+ MA_DR_FLAC_ASSERT(bitCount > 0);
+ MA_DR_FLAC_ASSERT(bitCount <= 16);
+ if (!ma_dr_flac__read_int32(bs, bitCount, &result)) {
+ return MA_FALSE;
}
- *pResult = (drflac_int16)result;
- return DRFLAC_TRUE;
+ *pResult = (ma_int16)result;
+ return MA_TRUE;
}
#endif
-static drflac_bool32 drflac__read_uint8(drflac_bs* bs, unsigned int bitCount, drflac_uint8* pResult)
+static ma_bool32 ma_dr_flac__read_uint8(ma_dr_flac_bs* bs, unsigned int bitCount, ma_uint8* pResult)
{
- drflac_uint32 result;
- DRFLAC_ASSERT(bs != NULL);
- DRFLAC_ASSERT(pResult != NULL);
- DRFLAC_ASSERT(bitCount > 0);
- DRFLAC_ASSERT(bitCount <= 8);
- if (!drflac__read_uint32(bs, bitCount, &result)) {
- return DRFLAC_FALSE;
+ ma_uint32 result;
+ MA_DR_FLAC_ASSERT(bs != NULL);
+ MA_DR_FLAC_ASSERT(pResult != NULL);
+ MA_DR_FLAC_ASSERT(bitCount > 0);
+ MA_DR_FLAC_ASSERT(bitCount <= 8);
+ if (!ma_dr_flac__read_uint32(bs, bitCount, &result)) {
+ return MA_FALSE;
}
- *pResult = (drflac_uint8)result;
- return DRFLAC_TRUE;
+ *pResult = (ma_uint8)result;
+ return MA_TRUE;
}
-static drflac_bool32 drflac__read_int8(drflac_bs* bs, unsigned int bitCount, drflac_int8* pResult)
+static ma_bool32 ma_dr_flac__read_int8(ma_dr_flac_bs* bs, unsigned int bitCount, ma_int8* pResult)
{
- drflac_int32 result;
- DRFLAC_ASSERT(bs != NULL);
- DRFLAC_ASSERT(pResult != NULL);
- DRFLAC_ASSERT(bitCount > 0);
- DRFLAC_ASSERT(bitCount <= 8);
- if (!drflac__read_int32(bs, bitCount, &result)) {
- return DRFLAC_FALSE;
+ ma_int32 result;
+ MA_DR_FLAC_ASSERT(bs != NULL);
+ MA_DR_FLAC_ASSERT(pResult != NULL);
+ MA_DR_FLAC_ASSERT(bitCount > 0);
+ MA_DR_FLAC_ASSERT(bitCount <= 8);
+ if (!ma_dr_flac__read_int32(bs, bitCount, &result)) {
+ return MA_FALSE;
}
- *pResult = (drflac_int8)result;
- return DRFLAC_TRUE;
+ *pResult = (ma_int8)result;
+ return MA_TRUE;
}
-static drflac_bool32 drflac__seek_bits(drflac_bs* bs, size_t bitsToSeek)
+static ma_bool32 ma_dr_flac__seek_bits(ma_dr_flac_bs* bs, size_t bitsToSeek)
{
- if (bitsToSeek <= DRFLAC_CACHE_L1_BITS_REMAINING(bs)) {
- bs->consumedBits += (drflac_uint32)bitsToSeek;
+ if (bitsToSeek <= MA_DR_FLAC_CACHE_L1_BITS_REMAINING(bs)) {
+ bs->consumedBits += (ma_uint32)bitsToSeek;
bs->cache <<= bitsToSeek;
- return DRFLAC_TRUE;
+ return MA_TRUE;
} else {
- bitsToSeek -= DRFLAC_CACHE_L1_BITS_REMAINING(bs);
- bs->consumedBits += DRFLAC_CACHE_L1_BITS_REMAINING(bs);
+ bitsToSeek -= MA_DR_FLAC_CACHE_L1_BITS_REMAINING(bs);
+ bs->consumedBits += MA_DR_FLAC_CACHE_L1_BITS_REMAINING(bs);
bs->cache = 0;
-#ifdef DRFLAC_64BIT
- while (bitsToSeek >= DRFLAC_CACHE_L1_SIZE_BITS(bs)) {
- drflac_uint64 bin;
- if (!drflac__read_uint64(bs, DRFLAC_CACHE_L1_SIZE_BITS(bs), &bin)) {
- return DRFLAC_FALSE;
+#ifdef MA_64BIT
+ while (bitsToSeek >= MA_DR_FLAC_CACHE_L1_SIZE_BITS(bs)) {
+ ma_uint64 bin;
+ if (!ma_dr_flac__read_uint64(bs, MA_DR_FLAC_CACHE_L1_SIZE_BITS(bs), &bin)) {
+ return MA_FALSE;
}
- bitsToSeek -= DRFLAC_CACHE_L1_SIZE_BITS(bs);
+ bitsToSeek -= MA_DR_FLAC_CACHE_L1_SIZE_BITS(bs);
}
#else
- while (bitsToSeek >= DRFLAC_CACHE_L1_SIZE_BITS(bs)) {
- drflac_uint32 bin;
- if (!drflac__read_uint32(bs, DRFLAC_CACHE_L1_SIZE_BITS(bs), &bin)) {
- return DRFLAC_FALSE;
+ while (bitsToSeek >= MA_DR_FLAC_CACHE_L1_SIZE_BITS(bs)) {
+ ma_uint32 bin;
+ if (!ma_dr_flac__read_uint32(bs, MA_DR_FLAC_CACHE_L1_SIZE_BITS(bs), &bin)) {
+ return MA_FALSE;
}
- bitsToSeek -= DRFLAC_CACHE_L1_SIZE_BITS(bs);
+ bitsToSeek -= MA_DR_FLAC_CACHE_L1_SIZE_BITS(bs);
}
#endif
while (bitsToSeek >= 8) {
- drflac_uint8 bin;
- if (!drflac__read_uint8(bs, 8, &bin)) {
- return DRFLAC_FALSE;
+ ma_uint8 bin;
+ if (!ma_dr_flac__read_uint8(bs, 8, &bin)) {
+ return MA_FALSE;
}
bitsToSeek -= 8;
}
if (bitsToSeek > 0) {
- drflac_uint8 bin;
- if (!drflac__read_uint8(bs, (drflac_uint32)bitsToSeek, &bin)) {
- return DRFLAC_FALSE;
+ ma_uint8 bin;
+ if (!ma_dr_flac__read_uint8(bs, (ma_uint32)bitsToSeek, &bin)) {
+ return MA_FALSE;
}
bitsToSeek = 0;
}
- DRFLAC_ASSERT(bitsToSeek == 0);
- return DRFLAC_TRUE;
+ MA_DR_FLAC_ASSERT(bitsToSeek == 0);
+ return MA_TRUE;
}
}
-static drflac_bool32 drflac__find_and_seek_to_next_sync_code(drflac_bs* bs)
+static ma_bool32 ma_dr_flac__find_and_seek_to_next_sync_code(ma_dr_flac_bs* bs)
{
- DRFLAC_ASSERT(bs != NULL);
- if (!drflac__seek_bits(bs, DRFLAC_CACHE_L1_BITS_REMAINING(bs) & 7)) {
- return DRFLAC_FALSE;
+ MA_DR_FLAC_ASSERT(bs != NULL);
+ if (!ma_dr_flac__seek_bits(bs, MA_DR_FLAC_CACHE_L1_BITS_REMAINING(bs) & 7)) {
+ return MA_FALSE;
}
for (;;) {
- drflac_uint8 hi;
-#ifndef DR_FLAC_NO_CRC
- drflac__reset_crc16(bs);
+ ma_uint8 hi;
+#ifndef MA_DR_FLAC_NO_CRC
+ ma_dr_flac__reset_crc16(bs);
#endif
- if (!drflac__read_uint8(bs, 8, &hi)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_uint8(bs, 8, &hi)) {
+ return MA_FALSE;
}
if (hi == 0xFF) {
- drflac_uint8 lo;
- if (!drflac__read_uint8(bs, 6, &lo)) {
- return DRFLAC_FALSE;
+ ma_uint8 lo;
+ if (!ma_dr_flac__read_uint8(bs, 6, &lo)) {
+ return MA_FALSE;
}
if (lo == 0x3E) {
- return DRFLAC_TRUE;
+ return MA_TRUE;
} else {
- if (!drflac__seek_bits(bs, DRFLAC_CACHE_L1_BITS_REMAINING(bs) & 7)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__seek_bits(bs, MA_DR_FLAC_CACHE_L1_BITS_REMAINING(bs) & 7)) {
+ return MA_FALSE;
}
}
}
}
}
-#if defined(DRFLAC_HAS_LZCNT_INTRINSIC)
-#define DRFLAC_IMPLEMENT_CLZ_LZCNT
+#if defined(MA_DR_FLAC_HAS_LZCNT_INTRINSIC)
+#define MA_DR_FLAC_IMPLEMENT_CLZ_LZCNT
#endif
-#if defined(_MSC_VER) && _MSC_VER >= 1400 && (defined(DRFLAC_X64) || defined(DRFLAC_X86)) && !defined(__clang__)
-#define DRFLAC_IMPLEMENT_CLZ_MSVC
+#if defined(_MSC_VER) && _MSC_VER >= 1400 && (defined(MA_X64) || defined(MA_X86)) && !defined(__clang__)
+#define MA_DR_FLAC_IMPLEMENT_CLZ_MSVC
#endif
#if defined(__WATCOMC__) && defined(__386__)
-#define DRFLAC_IMPLEMENT_CLZ_WATCOM
+#define MA_DR_FLAC_IMPLEMENT_CLZ_WATCOM
#endif
#ifdef __MRC__
#include
-#define DRFLAC_IMPLEMENT_CLZ_MRC
+#define MA_DR_FLAC_IMPLEMENT_CLZ_MRC
#endif
-static DRFLAC_INLINE drflac_uint32 drflac__clz_software(drflac_cache_t x)
+static MA_INLINE ma_uint32 ma_dr_flac__clz_software(ma_dr_flac_cache_t x)
{
- drflac_uint32 n;
- static drflac_uint32 clz_table_4[] = {
+ ma_uint32 n;
+ static ma_uint32 clz_table_4[] = {
0,
4,
3, 3,
@@ -80661,11 +83093,11 @@ static DRFLAC_INLINE drflac_uint32 drflac__clz_software(drflac_cache_t x)
}
n = clz_table_4[x >> (sizeof(x)*8 - 4)];
if (n == 0) {
-#ifdef DRFLAC_64BIT
- if ((x & ((drflac_uint64)0xFFFFFFFF << 32)) == 0) { n = 32; x <<= 32; }
- if ((x & ((drflac_uint64)0xFFFF0000 << 32)) == 0) { n += 16; x <<= 16; }
- if ((x & ((drflac_uint64)0xFF000000 << 32)) == 0) { n += 8; x <<= 8; }
- if ((x & ((drflac_uint64)0xF0000000 << 32)) == 0) { n += 4; x <<= 4; }
+#ifdef MA_64BIT
+ if ((x & ((ma_uint64)0xFFFFFFFF << 32)) == 0) { n = 32; x <<= 32; }
+ if ((x & ((ma_uint64)0xFFFF0000 << 32)) == 0) { n += 16; x <<= 16; }
+ if ((x & ((ma_uint64)0xFF000000 << 32)) == 0) { n += 8; x <<= 8; }
+ if ((x & ((ma_uint64)0xF0000000 << 32)) == 0) { n += 4; x <<= 4; }
#else
if ((x & 0xFFFF0000) == 0) { n = 16; x <<= 16; }
if ((x & 0xFF000000) == 0) { n += 8; x <<= 8; }
@@ -80675,52 +83107,52 @@ static DRFLAC_INLINE drflac_uint32 drflac__clz_software(drflac_cache_t x)
}
return n - 1;
}
-#ifdef DRFLAC_IMPLEMENT_CLZ_LZCNT
-static DRFLAC_INLINE drflac_bool32 drflac__is_lzcnt_supported(void)
+#ifdef MA_DR_FLAC_IMPLEMENT_CLZ_LZCNT
+static MA_INLINE ma_bool32 ma_dr_flac__is_lzcnt_supported(void)
{
-#if defined(DRFLAC_HAS_LZCNT_INTRINSIC) && defined(DRFLAC_ARM) && (defined(__ARM_ARCH) && __ARM_ARCH >= 5)
- return DRFLAC_TRUE;
+#if defined(MA_DR_FLAC_HAS_LZCNT_INTRINSIC) && defined(MA_ARM) && (defined(__ARM_ARCH) && __ARM_ARCH >= 5)
+ return MA_TRUE;
#elif defined(__MRC__)
- return DRFLAC_TRUE;
+ return MA_TRUE;
#else
- #ifdef DRFLAC_HAS_LZCNT_INTRINSIC
- return drflac__gIsLZCNTSupported;
+ #ifdef MA_DR_FLAC_HAS_LZCNT_INTRINSIC
+ return ma_dr_flac__gIsLZCNTSupported;
#else
- return DRFLAC_FALSE;
+ return MA_FALSE;
#endif
#endif
}
-static DRFLAC_INLINE drflac_uint32 drflac__clz_lzcnt(drflac_cache_t x)
+static MA_INLINE ma_uint32 ma_dr_flac__clz_lzcnt(ma_dr_flac_cache_t x)
{
#if defined(_MSC_VER)
- #ifdef DRFLAC_64BIT
- return (drflac_uint32)__lzcnt64(x);
+ #ifdef MA_64BIT
+ return (ma_uint32)__lzcnt64(x);
#else
- return (drflac_uint32)__lzcnt(x);
+ return (ma_uint32)__lzcnt(x);
#endif
#else
#if defined(__GNUC__) || defined(__clang__)
- #if defined(DRFLAC_X64)
+ #if defined(MA_X64)
{
- drflac_uint64 r;
+ ma_uint64 r;
__asm__ __volatile__ (
"lzcnt{ %1, %0| %0, %1}" : "=r"(r) : "r"(x) : "cc"
);
- return (drflac_uint32)r;
+ return (ma_uint32)r;
}
- #elif defined(DRFLAC_X86)
+ #elif defined(MA_X86)
{
- drflac_uint32 r;
+ ma_uint32 r;
__asm__ __volatile__ (
"lzcnt{l %1, %0| %0, %1}" : "=r"(r) : "r"(x) : "cc"
);
return r;
}
- #elif defined(DRFLAC_ARM) && (defined(__ARM_ARCH) && __ARM_ARCH >= 5) && !defined(DRFLAC_64BIT)
+ #elif defined(MA_ARM) && (defined(__ARM_ARCH) && __ARM_ARCH >= 5) && !defined(__ARM_ARCH_6M__) && !defined(MA_64BIT)
{
unsigned int r;
__asm__ __volatile__ (
- #if defined(DRFLAC_64BIT)
+ #if defined(MA_64BIT)
"clz %w[out], %w[in]" : [out]"=r"(r) : [in]"r"(x)
#else
"clz %[out], %[in]" : [out]"=r"(r) : [in]"r"(x)
@@ -80732,10 +83164,10 @@ static DRFLAC_INLINE drflac_uint32 drflac__clz_lzcnt(drflac_cache_t x)
if (x == 0) {
return sizeof(x)*8;
}
- #ifdef DRFLAC_64BIT
- return (drflac_uint32)__builtin_clzll((drflac_uint64)x);
+ #ifdef MA_64BIT
+ return (ma_uint32)__builtin_clzll((ma_uint64)x);
#else
- return (drflac_uint32)__builtin_clzl((drflac_uint32)x);
+ return (ma_uint32)__builtin_clzl((ma_uint32)x);
#endif
#endif
#else
@@ -80744,15 +83176,15 @@ static DRFLAC_INLINE drflac_uint32 drflac__clz_lzcnt(drflac_cache_t x)
#endif
}
#endif
-#ifdef DRFLAC_IMPLEMENT_CLZ_MSVC
+#ifdef MA_DR_FLAC_IMPLEMENT_CLZ_MSVC
#include
-static DRFLAC_INLINE drflac_uint32 drflac__clz_msvc(drflac_cache_t x)
+static MA_INLINE ma_uint32 ma_dr_flac__clz_msvc(ma_dr_flac_cache_t x)
{
- drflac_uint32 n;
+ ma_uint32 n;
if (x == 0) {
return sizeof(x)*8;
}
-#ifdef DRFLAC_64BIT
+#ifdef MA_64BIT
_BitScanReverse64((unsigned long*)&n, x);
#else
_BitScanReverse((unsigned long*)&n, x);
@@ -80760,16 +83192,16 @@ static DRFLAC_INLINE drflac_uint32 drflac__clz_msvc(drflac_cache_t x)
return sizeof(x)*8 - n - 1;
}
#endif
-#ifdef DRFLAC_IMPLEMENT_CLZ_WATCOM
-static __inline drflac_uint32 drflac__clz_watcom (drflac_uint32);
-#ifdef DRFLAC_IMPLEMENT_CLZ_WATCOM_LZCNT
-#pragma aux drflac__clz_watcom_lzcnt = \
+#ifdef MA_DR_FLAC_IMPLEMENT_CLZ_WATCOM
+static __inline ma_uint32 ma_dr_flac__clz_watcom (ma_uint32);
+#ifdef MA_DR_FLAC_IMPLEMENT_CLZ_WATCOM_LZCNT
+#pragma aux ma_dr_flac__clz_watcom_lzcnt = \
"db 0F3h, 0Fh, 0BDh, 0C0h" \
parm [eax] \
value [eax] \
modify nomemory;
#else
-#pragma aux drflac__clz_watcom = \
+#pragma aux ma_dr_flac__clz_watcom = \
"bsr eax, eax" \
"xor eax, 31" \
parm [eax] nomemory \
@@ -80777,103 +83209,103 @@ static __inline drflac_uint32 drflac__clz_watcom (drflac_uint32);
modify exact [eax] nomemory;
#endif
#endif
-static DRFLAC_INLINE drflac_uint32 drflac__clz(drflac_cache_t x)
+static MA_INLINE ma_uint32 ma_dr_flac__clz(ma_dr_flac_cache_t x)
{
-#ifdef DRFLAC_IMPLEMENT_CLZ_LZCNT
- if (drflac__is_lzcnt_supported()) {
- return drflac__clz_lzcnt(x);
+#ifdef MA_DR_FLAC_IMPLEMENT_CLZ_LZCNT
+ if (ma_dr_flac__is_lzcnt_supported()) {
+ return ma_dr_flac__clz_lzcnt(x);
} else
#endif
{
-#ifdef DRFLAC_IMPLEMENT_CLZ_MSVC
- return drflac__clz_msvc(x);
-#elif defined(DRFLAC_IMPLEMENT_CLZ_WATCOM_LZCNT)
- return drflac__clz_watcom_lzcnt(x);
-#elif defined(DRFLAC_IMPLEMENT_CLZ_WATCOM)
- return (x == 0) ? sizeof(x)*8 : drflac__clz_watcom(x);
+#ifdef MA_DR_FLAC_IMPLEMENT_CLZ_MSVC
+ return ma_dr_flac__clz_msvc(x);
+#elif defined(MA_DR_FLAC_IMPLEMENT_CLZ_WATCOM_LZCNT)
+ return ma_dr_flac__clz_watcom_lzcnt(x);
+#elif defined(MA_DR_FLAC_IMPLEMENT_CLZ_WATCOM)
+ return (x == 0) ? sizeof(x)*8 : ma_dr_flac__clz_watcom(x);
#elif defined(__MRC__)
return __cntlzw(x);
#else
- return drflac__clz_software(x);
+ return ma_dr_flac__clz_software(x);
#endif
}
}
-static DRFLAC_INLINE drflac_bool32 drflac__seek_past_next_set_bit(drflac_bs* bs, unsigned int* pOffsetOut)
+static MA_INLINE ma_bool32 ma_dr_flac__seek_past_next_set_bit(ma_dr_flac_bs* bs, unsigned int* pOffsetOut)
{
- drflac_uint32 zeroCounter = 0;
- drflac_uint32 setBitOffsetPlus1;
+ ma_uint32 zeroCounter = 0;
+ ma_uint32 setBitOffsetPlus1;
while (bs->cache == 0) {
- zeroCounter += (drflac_uint32)DRFLAC_CACHE_L1_BITS_REMAINING(bs);
- if (!drflac__reload_cache(bs)) {
- return DRFLAC_FALSE;
+ zeroCounter += (ma_uint32)MA_DR_FLAC_CACHE_L1_BITS_REMAINING(bs);
+ if (!ma_dr_flac__reload_cache(bs)) {
+ return MA_FALSE;
}
}
if (bs->cache == 1) {
- *pOffsetOut = zeroCounter + (drflac_uint32)DRFLAC_CACHE_L1_BITS_REMAINING(bs) - 1;
- if (!drflac__reload_cache(bs)) {
- return DRFLAC_FALSE;
+ *pOffsetOut = zeroCounter + (ma_uint32)MA_DR_FLAC_CACHE_L1_BITS_REMAINING(bs) - 1;
+ if (!ma_dr_flac__reload_cache(bs)) {
+ return MA_FALSE;
}
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
- setBitOffsetPlus1 = drflac__clz(bs->cache);
+ setBitOffsetPlus1 = ma_dr_flac__clz(bs->cache);
setBitOffsetPlus1 += 1;
- if (setBitOffsetPlus1 > DRFLAC_CACHE_L1_BITS_REMAINING(bs)) {
- return DRFLAC_FALSE;
+ if (setBitOffsetPlus1 > MA_DR_FLAC_CACHE_L1_BITS_REMAINING(bs)) {
+ return MA_FALSE;
}
bs->consumedBits += setBitOffsetPlus1;
bs->cache <<= setBitOffsetPlus1;
*pOffsetOut = zeroCounter + setBitOffsetPlus1 - 1;
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
-static drflac_bool32 drflac__seek_to_byte(drflac_bs* bs, drflac_uint64 offsetFromStart)
+static ma_bool32 ma_dr_flac__seek_to_byte(ma_dr_flac_bs* bs, ma_uint64 offsetFromStart)
{
- DRFLAC_ASSERT(bs != NULL);
- DRFLAC_ASSERT(offsetFromStart > 0);
+ MA_DR_FLAC_ASSERT(bs != NULL);
+ MA_DR_FLAC_ASSERT(offsetFromStart > 0);
if (offsetFromStart > 0x7FFFFFFF) {
- drflac_uint64 bytesRemaining = offsetFromStart;
- if (!bs->onSeek(bs->pUserData, 0x7FFFFFFF, drflac_seek_origin_start)) {
- return DRFLAC_FALSE;
+ ma_uint64 bytesRemaining = offsetFromStart;
+ if (!bs->onSeek(bs->pUserData, 0x7FFFFFFF, ma_dr_flac_seek_origin_start)) {
+ return MA_FALSE;
}
bytesRemaining -= 0x7FFFFFFF;
while (bytesRemaining > 0x7FFFFFFF) {
- if (!bs->onSeek(bs->pUserData, 0x7FFFFFFF, drflac_seek_origin_current)) {
- return DRFLAC_FALSE;
+ if (!bs->onSeek(bs->pUserData, 0x7FFFFFFF, ma_dr_flac_seek_origin_current)) {
+ return MA_FALSE;
}
bytesRemaining -= 0x7FFFFFFF;
}
if (bytesRemaining > 0) {
- if (!bs->onSeek(bs->pUserData, (int)bytesRemaining, drflac_seek_origin_current)) {
- return DRFLAC_FALSE;
+ if (!bs->onSeek(bs->pUserData, (int)bytesRemaining, ma_dr_flac_seek_origin_current)) {
+ return MA_FALSE;
}
}
} else {
- if (!bs->onSeek(bs->pUserData, (int)offsetFromStart, drflac_seek_origin_start)) {
- return DRFLAC_FALSE;
+ if (!bs->onSeek(bs->pUserData, (int)offsetFromStart, ma_dr_flac_seek_origin_start)) {
+ return MA_FALSE;
}
}
- drflac__reset_cache(bs);
- return DRFLAC_TRUE;
+ ma_dr_flac__reset_cache(bs);
+ return MA_TRUE;
}
-static drflac_result drflac__read_utf8_coded_number(drflac_bs* bs, drflac_uint64* pNumberOut, drflac_uint8* pCRCOut)
+static ma_result ma_dr_flac__read_utf8_coded_number(ma_dr_flac_bs* bs, ma_uint64* pNumberOut, ma_uint8* pCRCOut)
{
- drflac_uint8 crc;
- drflac_uint64 result;
- drflac_uint8 utf8[7] = {0};
+ ma_uint8 crc;
+ ma_uint64 result;
+ ma_uint8 utf8[7] = {0};
int byteCount;
int i;
- DRFLAC_ASSERT(bs != NULL);
- DRFLAC_ASSERT(pNumberOut != NULL);
- DRFLAC_ASSERT(pCRCOut != NULL);
+ MA_DR_FLAC_ASSERT(bs != NULL);
+ MA_DR_FLAC_ASSERT(pNumberOut != NULL);
+ MA_DR_FLAC_ASSERT(pCRCOut != NULL);
crc = *pCRCOut;
- if (!drflac__read_uint8(bs, 8, utf8)) {
+ if (!ma_dr_flac__read_uint8(bs, 8, utf8)) {
*pNumberOut = 0;
- return DRFLAC_AT_END;
+ return MA_AT_END;
}
- crc = drflac_crc8(crc, utf8[0], 8);
+ crc = ma_dr_flac_crc8(crc, utf8[0], 8);
if ((utf8[0] & 0x80) == 0) {
*pNumberOut = utf8[0];
*pCRCOut = crc;
- return DRFLAC_SUCCESS;
+ return MA_SUCCESS;
}
if ((utf8[0] & 0xE0) == 0xC0) {
byteCount = 2;
@@ -80889,26 +83321,26 @@ static drflac_result drflac__read_utf8_coded_number(drflac_bs* bs, drflac_uint64
byteCount = 7;
} else {
*pNumberOut = 0;
- return DRFLAC_CRC_MISMATCH;
+ return MA_CRC_MISMATCH;
}
- DRFLAC_ASSERT(byteCount > 1);
- result = (drflac_uint64)(utf8[0] & (0xFF >> (byteCount + 1)));
+ MA_DR_FLAC_ASSERT(byteCount > 1);
+ result = (ma_uint64)(utf8[0] & (0xFF >> (byteCount + 1)));
for (i = 1; i < byteCount; ++i) {
- if (!drflac__read_uint8(bs, 8, utf8 + i)) {
+ if (!ma_dr_flac__read_uint8(bs, 8, utf8 + i)) {
*pNumberOut = 0;
- return DRFLAC_AT_END;
+ return MA_AT_END;
}
- crc = drflac_crc8(crc, utf8[i], 8);
+ crc = ma_dr_flac_crc8(crc, utf8[i], 8);
result = (result << 6) | (utf8[i] & 0x3F);
}
*pNumberOut = result;
*pCRCOut = crc;
- return DRFLAC_SUCCESS;
+ return MA_SUCCESS;
}
-static DRFLAC_INLINE drflac_uint32 drflac__ilog2_u32(drflac_uint32 x)
+static MA_INLINE ma_uint32 ma_dr_flac__ilog2_u32(ma_uint32 x)
{
#if 1
- drflac_uint32 result = 0;
+ ma_uint32 result = 0;
while (x > 0) {
result += 1;
x >>= 1;
@@ -80916,17 +83348,17 @@ static DRFLAC_INLINE drflac_uint32 drflac__ilog2_u32(drflac_uint32 x)
return result;
#endif
}
-static DRFLAC_INLINE drflac_bool32 drflac__use_64_bit_prediction(drflac_uint32 bitsPerSample, drflac_uint32 order, drflac_uint32 precision)
+static MA_INLINE ma_bool32 ma_dr_flac__use_64_bit_prediction(ma_uint32 bitsPerSample, ma_uint32 order, ma_uint32 precision)
{
- return bitsPerSample + precision + drflac__ilog2_u32(order) > 32;
+ return bitsPerSample + precision + ma_dr_flac__ilog2_u32(order) > 32;
}
#if defined(__clang__)
__attribute__((no_sanitize("signed-integer-overflow")))
#endif
-static DRFLAC_INLINE drflac_int32 drflac__calculate_prediction_32(drflac_uint32 order, drflac_int32 shift, const drflac_int32* coefficients, drflac_int32* pDecodedSamples)
+static MA_INLINE ma_int32 ma_dr_flac__calculate_prediction_32(ma_uint32 order, ma_int32 shift, const ma_int32* coefficients, ma_int32* pDecodedSamples)
{
- drflac_int32 prediction = 0;
- DRFLAC_ASSERT(order <= 32);
+ ma_int32 prediction = 0;
+ MA_DR_FLAC_ASSERT(order <= 32);
switch (order)
{
case 32: prediction += coefficients[31] * pDecodedSamples[-32];
@@ -80962,188 +83394,188 @@ static DRFLAC_INLINE drflac_int32 drflac__calculate_prediction_32(drflac_uint32
case 2: prediction += coefficients[ 1] * pDecodedSamples[- 2];
case 1: prediction += coefficients[ 0] * pDecodedSamples[- 1];
}
- return (drflac_int32)(prediction >> shift);
+ return (ma_int32)(prediction >> shift);
}
-static DRFLAC_INLINE drflac_int32 drflac__calculate_prediction_64(drflac_uint32 order, drflac_int32 shift, const drflac_int32* coefficients, drflac_int32* pDecodedSamples)
+static MA_INLINE ma_int32 ma_dr_flac__calculate_prediction_64(ma_uint32 order, ma_int32 shift, const ma_int32* coefficients, ma_int32* pDecodedSamples)
{
- drflac_int64 prediction;
- DRFLAC_ASSERT(order <= 32);
-#ifndef DRFLAC_64BIT
+ ma_int64 prediction;
+ MA_DR_FLAC_ASSERT(order <= 32);
+#ifndef MA_64BIT
if (order == 8)
{
- prediction = coefficients[0] * (drflac_int64)pDecodedSamples[-1];
- prediction += coefficients[1] * (drflac_int64)pDecodedSamples[-2];
- prediction += coefficients[2] * (drflac_int64)pDecodedSamples[-3];
- prediction += coefficients[3] * (drflac_int64)pDecodedSamples[-4];
- prediction += coefficients[4] * (drflac_int64)pDecodedSamples[-5];
- prediction += coefficients[5] * (drflac_int64)pDecodedSamples[-6];
- prediction += coefficients[6] * (drflac_int64)pDecodedSamples[-7];
- prediction += coefficients[7] * (drflac_int64)pDecodedSamples[-8];
+ prediction = coefficients[0] * (ma_int64)pDecodedSamples[-1];
+ prediction += coefficients[1] * (ma_int64)pDecodedSamples[-2];
+ prediction += coefficients[2] * (ma_int64)pDecodedSamples[-3];
+ prediction += coefficients[3] * (ma_int64)pDecodedSamples[-4];
+ prediction += coefficients[4] * (ma_int64)pDecodedSamples[-5];
+ prediction += coefficients[5] * (ma_int64)pDecodedSamples[-6];
+ prediction += coefficients[6] * (ma_int64)pDecodedSamples[-7];
+ prediction += coefficients[7] * (ma_int64)pDecodedSamples[-8];
}
else if (order == 7)
{
- prediction = coefficients[0] * (drflac_int64)pDecodedSamples[-1];
- prediction += coefficients[1] * (drflac_int64)pDecodedSamples[-2];
- prediction += coefficients[2] * (drflac_int64)pDecodedSamples[-3];
- prediction += coefficients[3] * (drflac_int64)pDecodedSamples[-4];
- prediction += coefficients[4] * (drflac_int64)pDecodedSamples[-5];
- prediction += coefficients[5] * (drflac_int64)pDecodedSamples[-6];
- prediction += coefficients[6] * (drflac_int64)pDecodedSamples[-7];
+ prediction = coefficients[0] * (ma_int64)pDecodedSamples[-1];
+ prediction += coefficients[1] * (ma_int64)pDecodedSamples[-2];
+ prediction += coefficients[2] * (ma_int64)pDecodedSamples[-3];
+ prediction += coefficients[3] * (ma_int64)pDecodedSamples[-4];
+ prediction += coefficients[4] * (ma_int64)pDecodedSamples[-5];
+ prediction += coefficients[5] * (ma_int64)pDecodedSamples[-6];
+ prediction += coefficients[6] * (ma_int64)pDecodedSamples[-7];
}
else if (order == 3)
{
- prediction = coefficients[0] * (drflac_int64)pDecodedSamples[-1];
- prediction += coefficients[1] * (drflac_int64)pDecodedSamples[-2];
- prediction += coefficients[2] * (drflac_int64)pDecodedSamples[-3];
+ prediction = coefficients[0] * (ma_int64)pDecodedSamples[-1];
+ prediction += coefficients[1] * (ma_int64)pDecodedSamples[-2];
+ prediction += coefficients[2] * (ma_int64)pDecodedSamples[-3];
}
else if (order == 6)
{
- prediction = coefficients[0] * (drflac_int64)pDecodedSamples[-1];
- prediction += coefficients[1] * (drflac_int64)pDecodedSamples[-2];
- prediction += coefficients[2] * (drflac_int64)pDecodedSamples[-3];
- prediction += coefficients[3] * (drflac_int64)pDecodedSamples[-4];
- prediction += coefficients[4] * (drflac_int64)pDecodedSamples[-5];
- prediction += coefficients[5] * (drflac_int64)pDecodedSamples[-6];
+ prediction = coefficients[0] * (ma_int64)pDecodedSamples[-1];
+ prediction += coefficients[1] * (ma_int64)pDecodedSamples[-2];
+ prediction += coefficients[2] * (ma_int64)pDecodedSamples[-3];
+ prediction += coefficients[3] * (ma_int64)pDecodedSamples[-4];
+ prediction += coefficients[4] * (ma_int64)pDecodedSamples[-5];
+ prediction += coefficients[5] * (ma_int64)pDecodedSamples[-6];
}
else if (order == 5)
{
- prediction = coefficients[0] * (drflac_int64)pDecodedSamples[-1];
- prediction += coefficients[1] * (drflac_int64)pDecodedSamples[-2];
- prediction += coefficients[2] * (drflac_int64)pDecodedSamples[-3];
- prediction += coefficients[3] * (drflac_int64)pDecodedSamples[-4];
- prediction += coefficients[4] * (drflac_int64)pDecodedSamples[-5];
+ prediction = coefficients[0] * (ma_int64)pDecodedSamples[-1];
+ prediction += coefficients[1] * (ma_int64)pDecodedSamples[-2];
+ prediction += coefficients[2] * (ma_int64)pDecodedSamples[-3];
+ prediction += coefficients[3] * (ma_int64)pDecodedSamples[-4];
+ prediction += coefficients[4] * (ma_int64)pDecodedSamples[-5];
}
else if (order == 4)
{
- prediction = coefficients[0] * (drflac_int64)pDecodedSamples[-1];
- prediction += coefficients[1] * (drflac_int64)pDecodedSamples[-2];
- prediction += coefficients[2] * (drflac_int64)pDecodedSamples[-3];
- prediction += coefficients[3] * (drflac_int64)pDecodedSamples[-4];
+ prediction = coefficients[0] * (ma_int64)pDecodedSamples[-1];
+ prediction += coefficients[1] * (ma_int64)pDecodedSamples[-2];
+ prediction += coefficients[2] * (ma_int64)pDecodedSamples[-3];
+ prediction += coefficients[3] * (ma_int64)pDecodedSamples[-4];
}
else if (order == 12)
{
- prediction = coefficients[0] * (drflac_int64)pDecodedSamples[-1];
- prediction += coefficients[1] * (drflac_int64)pDecodedSamples[-2];
- prediction += coefficients[2] * (drflac_int64)pDecodedSamples[-3];
- prediction += coefficients[3] * (drflac_int64)pDecodedSamples[-4];
- prediction += coefficients[4] * (drflac_int64)pDecodedSamples[-5];
- prediction += coefficients[5] * (drflac_int64)pDecodedSamples[-6];
- prediction += coefficients[6] * (drflac_int64)pDecodedSamples[-7];
- prediction += coefficients[7] * (drflac_int64)pDecodedSamples[-8];
- prediction += coefficients[8] * (drflac_int64)pDecodedSamples[-9];
- prediction += coefficients[9] * (drflac_int64)pDecodedSamples[-10];
- prediction += coefficients[10] * (drflac_int64)pDecodedSamples[-11];
- prediction += coefficients[11] * (drflac_int64)pDecodedSamples[-12];
+ prediction = coefficients[0] * (ma_int64)pDecodedSamples[-1];
+ prediction += coefficients[1] * (ma_int64)pDecodedSamples[-2];
+ prediction += coefficients[2] * (ma_int64)pDecodedSamples[-3];
+ prediction += coefficients[3] * (ma_int64)pDecodedSamples[-4];
+ prediction += coefficients[4] * (ma_int64)pDecodedSamples[-5];
+ prediction += coefficients[5] * (ma_int64)pDecodedSamples[-6];
+ prediction += coefficients[6] * (ma_int64)pDecodedSamples[-7];
+ prediction += coefficients[7] * (ma_int64)pDecodedSamples[-8];
+ prediction += coefficients[8] * (ma_int64)pDecodedSamples[-9];
+ prediction += coefficients[9] * (ma_int64)pDecodedSamples[-10];
+ prediction += coefficients[10] * (ma_int64)pDecodedSamples[-11];
+ prediction += coefficients[11] * (ma_int64)pDecodedSamples[-12];
}
else if (order == 2)
{
- prediction = coefficients[0] * (drflac_int64)pDecodedSamples[-1];
- prediction += coefficients[1] * (drflac_int64)pDecodedSamples[-2];
+ prediction = coefficients[0] * (ma_int64)pDecodedSamples[-1];
+ prediction += coefficients[1] * (ma_int64)pDecodedSamples[-2];
}
else if (order == 1)
{
- prediction = coefficients[0] * (drflac_int64)pDecodedSamples[-1];
+ prediction = coefficients[0] * (ma_int64)pDecodedSamples[-1];
}
else if (order == 10)
{
- prediction = coefficients[0] * (drflac_int64)pDecodedSamples[-1];
- prediction += coefficients[1] * (drflac_int64)pDecodedSamples[-2];
- prediction += coefficients[2] * (drflac_int64)pDecodedSamples[-3];
- prediction += coefficients[3] * (drflac_int64)pDecodedSamples[-4];
- prediction += coefficients[4] * (drflac_int64)pDecodedSamples[-5];
- prediction += coefficients[5] * (drflac_int64)pDecodedSamples[-6];
- prediction += coefficients[6] * (drflac_int64)pDecodedSamples[-7];
- prediction += coefficients[7] * (drflac_int64)pDecodedSamples[-8];
- prediction += coefficients[8] * (drflac_int64)pDecodedSamples[-9];
- prediction += coefficients[9] * (drflac_int64)pDecodedSamples[-10];
+ prediction = coefficients[0] * (ma_int64)pDecodedSamples[-1];
+ prediction += coefficients[1] * (ma_int64)pDecodedSamples[-2];
+ prediction += coefficients[2] * (ma_int64)pDecodedSamples[-3];
+ prediction += coefficients[3] * (ma_int64)pDecodedSamples[-4];
+ prediction += coefficients[4] * (ma_int64)pDecodedSamples[-5];
+ prediction += coefficients[5] * (ma_int64)pDecodedSamples[-6];
+ prediction += coefficients[6] * (ma_int64)pDecodedSamples[-7];
+ prediction += coefficients[7] * (ma_int64)pDecodedSamples[-8];
+ prediction += coefficients[8] * (ma_int64)pDecodedSamples[-9];
+ prediction += coefficients[9] * (ma_int64)pDecodedSamples[-10];
}
else if (order == 9)
{
- prediction = coefficients[0] * (drflac_int64)pDecodedSamples[-1];
- prediction += coefficients[1] * (drflac_int64)pDecodedSamples[-2];
- prediction += coefficients[2] * (drflac_int64)pDecodedSamples[-3];
- prediction += coefficients[3] * (drflac_int64)pDecodedSamples[-4];
- prediction += coefficients[4] * (drflac_int64)pDecodedSamples[-5];
- prediction += coefficients[5] * (drflac_int64)pDecodedSamples[-6];
- prediction += coefficients[6] * (drflac_int64)pDecodedSamples[-7];
- prediction += coefficients[7] * (drflac_int64)pDecodedSamples[-8];
- prediction += coefficients[8] * (drflac_int64)pDecodedSamples[-9];
+ prediction = coefficients[0] * (ma_int64)pDecodedSamples[-1];
+ prediction += coefficients[1] * (ma_int64)pDecodedSamples[-2];
+ prediction += coefficients[2] * (ma_int64)pDecodedSamples[-3];
+ prediction += coefficients[3] * (ma_int64)pDecodedSamples[-4];
+ prediction += coefficients[4] * (ma_int64)pDecodedSamples[-5];
+ prediction += coefficients[5] * (ma_int64)pDecodedSamples[-6];
+ prediction += coefficients[6] * (ma_int64)pDecodedSamples[-7];
+ prediction += coefficients[7] * (ma_int64)pDecodedSamples[-8];
+ prediction += coefficients[8] * (ma_int64)pDecodedSamples[-9];
}
else if (order == 11)
{
- prediction = coefficients[0] * (drflac_int64)pDecodedSamples[-1];
- prediction += coefficients[1] * (drflac_int64)pDecodedSamples[-2];
- prediction += coefficients[2] * (drflac_int64)pDecodedSamples[-3];
- prediction += coefficients[3] * (drflac_int64)pDecodedSamples[-4];
- prediction += coefficients[4] * (drflac_int64)pDecodedSamples[-5];
- prediction += coefficients[5] * (drflac_int64)pDecodedSamples[-6];
- prediction += coefficients[6] * (drflac_int64)pDecodedSamples[-7];
- prediction += coefficients[7] * (drflac_int64)pDecodedSamples[-8];
- prediction += coefficients[8] * (drflac_int64)pDecodedSamples[-9];
- prediction += coefficients[9] * (drflac_int64)pDecodedSamples[-10];
- prediction += coefficients[10] * (drflac_int64)pDecodedSamples[-11];
+ prediction = coefficients[0] * (ma_int64)pDecodedSamples[-1];
+ prediction += coefficients[1] * (ma_int64)pDecodedSamples[-2];
+ prediction += coefficients[2] * (ma_int64)pDecodedSamples[-3];
+ prediction += coefficients[3] * (ma_int64)pDecodedSamples[-4];
+ prediction += coefficients[4] * (ma_int64)pDecodedSamples[-5];
+ prediction += coefficients[5] * (ma_int64)pDecodedSamples[-6];
+ prediction += coefficients[6] * (ma_int64)pDecodedSamples[-7];
+ prediction += coefficients[7] * (ma_int64)pDecodedSamples[-8];
+ prediction += coefficients[8] * (ma_int64)pDecodedSamples[-9];
+ prediction += coefficients[9] * (ma_int64)pDecodedSamples[-10];
+ prediction += coefficients[10] * (ma_int64)pDecodedSamples[-11];
}
else
{
int j;
prediction = 0;
for (j = 0; j < (int)order; ++j) {
- prediction += coefficients[j] * (drflac_int64)pDecodedSamples[-j-1];
+ prediction += coefficients[j] * (ma_int64)pDecodedSamples[-j-1];
}
}
#endif
-#ifdef DRFLAC_64BIT
+#ifdef MA_64BIT
prediction = 0;
switch (order)
{
- case 32: prediction += coefficients[31] * (drflac_int64)pDecodedSamples[-32];
- case 31: prediction += coefficients[30] * (drflac_int64)pDecodedSamples[-31];
- case 30: prediction += coefficients[29] * (drflac_int64)pDecodedSamples[-30];
- case 29: prediction += coefficients[28] * (drflac_int64)pDecodedSamples[-29];
- case 28: prediction += coefficients[27] * (drflac_int64)pDecodedSamples[-28];
- case 27: prediction += coefficients[26] * (drflac_int64)pDecodedSamples[-27];
- case 26: prediction += coefficients[25] * (drflac_int64)pDecodedSamples[-26];
- case 25: prediction += coefficients[24] * (drflac_int64)pDecodedSamples[-25];
- case 24: prediction += coefficients[23] * (drflac_int64)pDecodedSamples[-24];
- case 23: prediction += coefficients[22] * (drflac_int64)pDecodedSamples[-23];
- case 22: prediction += coefficients[21] * (drflac_int64)pDecodedSamples[-22];
- case 21: prediction += coefficients[20] * (drflac_int64)pDecodedSamples[-21];
- case 20: prediction += coefficients[19] * (drflac_int64)pDecodedSamples[-20];
- case 19: prediction += coefficients[18] * (drflac_int64)pDecodedSamples[-19];
- case 18: prediction += coefficients[17] * (drflac_int64)pDecodedSamples[-18];
- case 17: prediction += coefficients[16] * (drflac_int64)pDecodedSamples[-17];
- case 16: prediction += coefficients[15] * (drflac_int64)pDecodedSamples[-16];
- case 15: prediction += coefficients[14] * (drflac_int64)pDecodedSamples[-15];
- case 14: prediction += coefficients[13] * (drflac_int64)pDecodedSamples[-14];
- case 13: prediction += coefficients[12] * (drflac_int64)pDecodedSamples[-13];
- case 12: prediction += coefficients[11] * (drflac_int64)pDecodedSamples[-12];
- case 11: prediction += coefficients[10] * (drflac_int64)pDecodedSamples[-11];
- case 10: prediction += coefficients[ 9] * (drflac_int64)pDecodedSamples[-10];
- case 9: prediction += coefficients[ 8] * (drflac_int64)pDecodedSamples[- 9];
- case 8: prediction += coefficients[ 7] * (drflac_int64)pDecodedSamples[- 8];
- case 7: prediction += coefficients[ 6] * (drflac_int64)pDecodedSamples[- 7];
- case 6: prediction += coefficients[ 5] * (drflac_int64)pDecodedSamples[- 6];
- case 5: prediction += coefficients[ 4] * (drflac_int64)pDecodedSamples[- 5];
- case 4: prediction += coefficients[ 3] * (drflac_int64)pDecodedSamples[- 4];
- case 3: prediction += coefficients[ 2] * (drflac_int64)pDecodedSamples[- 3];
- case 2: prediction += coefficients[ 1] * (drflac_int64)pDecodedSamples[- 2];
- case 1: prediction += coefficients[ 0] * (drflac_int64)pDecodedSamples[- 1];
- }
-#endif
- return (drflac_int32)(prediction >> shift);
+ case 32: prediction += coefficients[31] * (ma_int64)pDecodedSamples[-32];
+ case 31: prediction += coefficients[30] * (ma_int64)pDecodedSamples[-31];
+ case 30: prediction += coefficients[29] * (ma_int64)pDecodedSamples[-30];
+ case 29: prediction += coefficients[28] * (ma_int64)pDecodedSamples[-29];
+ case 28: prediction += coefficients[27] * (ma_int64)pDecodedSamples[-28];
+ case 27: prediction += coefficients[26] * (ma_int64)pDecodedSamples[-27];
+ case 26: prediction += coefficients[25] * (ma_int64)pDecodedSamples[-26];
+ case 25: prediction += coefficients[24] * (ma_int64)pDecodedSamples[-25];
+ case 24: prediction += coefficients[23] * (ma_int64)pDecodedSamples[-24];
+ case 23: prediction += coefficients[22] * (ma_int64)pDecodedSamples[-23];
+ case 22: prediction += coefficients[21] * (ma_int64)pDecodedSamples[-22];
+ case 21: prediction += coefficients[20] * (ma_int64)pDecodedSamples[-21];
+ case 20: prediction += coefficients[19] * (ma_int64)pDecodedSamples[-20];
+ case 19: prediction += coefficients[18] * (ma_int64)pDecodedSamples[-19];
+ case 18: prediction += coefficients[17] * (ma_int64)pDecodedSamples[-18];
+ case 17: prediction += coefficients[16] * (ma_int64)pDecodedSamples[-17];
+ case 16: prediction += coefficients[15] * (ma_int64)pDecodedSamples[-16];
+ case 15: prediction += coefficients[14] * (ma_int64)pDecodedSamples[-15];
+ case 14: prediction += coefficients[13] * (ma_int64)pDecodedSamples[-14];
+ case 13: prediction += coefficients[12] * (ma_int64)pDecodedSamples[-13];
+ case 12: prediction += coefficients[11] * (ma_int64)pDecodedSamples[-12];
+ case 11: prediction += coefficients[10] * (ma_int64)pDecodedSamples[-11];
+ case 10: prediction += coefficients[ 9] * (ma_int64)pDecodedSamples[-10];
+ case 9: prediction += coefficients[ 8] * (ma_int64)pDecodedSamples[- 9];
+ case 8: prediction += coefficients[ 7] * (ma_int64)pDecodedSamples[- 8];
+ case 7: prediction += coefficients[ 6] * (ma_int64)pDecodedSamples[- 7];
+ case 6: prediction += coefficients[ 5] * (ma_int64)pDecodedSamples[- 6];
+ case 5: prediction += coefficients[ 4] * (ma_int64)pDecodedSamples[- 5];
+ case 4: prediction += coefficients[ 3] * (ma_int64)pDecodedSamples[- 4];
+ case 3: prediction += coefficients[ 2] * (ma_int64)pDecodedSamples[- 3];
+ case 2: prediction += coefficients[ 1] * (ma_int64)pDecodedSamples[- 2];
+ case 1: prediction += coefficients[ 0] * (ma_int64)pDecodedSamples[- 1];
+ }
+#endif
+ return (ma_int32)(prediction >> shift);
}
#if 0
-static drflac_bool32 drflac__decode_samples_with_residual__rice__reference(drflac_bs* bs, drflac_uint32 bitsPerSample, drflac_uint32 count, drflac_uint8 riceParam, drflac_uint32 lpcOrder, drflac_int32 lpcShift, drflac_uint32 lpcPrecision, const drflac_int32* coefficients, drflac_int32* pSamplesOut)
+static ma_bool32 ma_dr_flac__decode_samples_with_residual__rice__reference(ma_dr_flac_bs* bs, ma_uint32 bitsPerSample, ma_uint32 count, ma_uint8 riceParam, ma_uint32 lpcOrder, ma_int32 lpcShift, ma_uint32 lpcPrecision, const ma_int32* coefficients, ma_int32* pSamplesOut)
{
- drflac_uint32 i;
- DRFLAC_ASSERT(bs != NULL);
- DRFLAC_ASSERT(pSamplesOut != NULL);
+ ma_uint32 i;
+ MA_DR_FLAC_ASSERT(bs != NULL);
+ MA_DR_FLAC_ASSERT(pSamplesOut != NULL);
for (i = 0; i < count; ++i) {
- drflac_uint32 zeroCounter = 0;
+ ma_uint32 zeroCounter = 0;
for (;;) {
- drflac_uint8 bit;
- if (!drflac__read_uint8(bs, 1, &bit)) {
- return DRFLAC_FALSE;
+ ma_uint8 bit;
+ if (!ma_dr_flac__read_uint8(bs, 1, &bit)) {
+ return MA_FALSE;
}
if (bit == 0) {
zeroCounter += 1;
@@ -81151,10 +83583,10 @@ static drflac_bool32 drflac__decode_samples_with_residual__rice__reference(drfla
break;
}
}
- drflac_uint32 decodedRice;
+ ma_uint32 decodedRice;
if (riceParam > 0) {
- if (!drflac__read_uint32(bs, riceParam, &decodedRice)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_uint32(bs, riceParam, &decodedRice)) {
+ return MA_FALSE;
}
} else {
decodedRice = 0;
@@ -81165,24 +83597,24 @@ static drflac_bool32 drflac__decode_samples_with_residual__rice__reference(drfla
} else {
decodedRice = (decodedRice >> 1);
}
- if (drflac__use_64_bit_prediction(bitsPerSample, lpcOrder, lpcPrecision)) {
- pSamplesOut[i] = decodedRice + drflac__calculate_prediction_64(lpcOrder, lpcShift, coefficients, pSamplesOut + i);
+ if (ma_dr_flac__use_64_bit_prediction(bitsPerSample, lpcOrder, lpcPrecision)) {
+ pSamplesOut[i] = decodedRice + ma_dr_flac__calculate_prediction_64(lpcOrder, lpcShift, coefficients, pSamplesOut + i);
} else {
- pSamplesOut[i] = decodedRice + drflac__calculate_prediction_32(lpcOrder, lpcShift, coefficients, pSamplesOut + i);
+ pSamplesOut[i] = decodedRice + ma_dr_flac__calculate_prediction_32(lpcOrder, lpcShift, coefficients, pSamplesOut + i);
}
}
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
#endif
#if 0
-static drflac_bool32 drflac__read_rice_parts__reference(drflac_bs* bs, drflac_uint8 riceParam, drflac_uint32* pZeroCounterOut, drflac_uint32* pRiceParamPartOut)
+static ma_bool32 ma_dr_flac__read_rice_parts__reference(ma_dr_flac_bs* bs, ma_uint8 riceParam, ma_uint32* pZeroCounterOut, ma_uint32* pRiceParamPartOut)
{
- drflac_uint32 zeroCounter = 0;
- drflac_uint32 decodedRice;
+ ma_uint32 zeroCounter = 0;
+ ma_uint32 decodedRice;
for (;;) {
- drflac_uint8 bit;
- if (!drflac__read_uint8(bs, 1, &bit)) {
- return DRFLAC_FALSE;
+ ma_uint8 bit;
+ if (!ma_dr_flac__read_uint8(bs, 1, &bit)) {
+ return MA_FALSE;
}
if (bit == 0) {
zeroCounter += 1;
@@ -81191,142 +83623,142 @@ static drflac_bool32 drflac__read_rice_parts__reference(drflac_bs* bs, drflac_ui
}
}
if (riceParam > 0) {
- if (!drflac__read_uint32(bs, riceParam, &decodedRice)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_uint32(bs, riceParam, &decodedRice)) {
+ return MA_FALSE;
}
} else {
decodedRice = 0;
}
*pZeroCounterOut = zeroCounter;
*pRiceParamPartOut = decodedRice;
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
#endif
#if 0
-static DRFLAC_INLINE drflac_bool32 drflac__read_rice_parts(drflac_bs* bs, drflac_uint8 riceParam, drflac_uint32* pZeroCounterOut, drflac_uint32* pRiceParamPartOut)
-{
- drflac_cache_t riceParamMask;
- drflac_uint32 zeroCounter;
- drflac_uint32 setBitOffsetPlus1;
- drflac_uint32 riceParamPart;
- drflac_uint32 riceLength;
- DRFLAC_ASSERT(riceParam > 0);
- riceParamMask = DRFLAC_CACHE_L1_SELECTION_MASK(riceParam);
+static MA_INLINE ma_bool32 ma_dr_flac__read_rice_parts(ma_dr_flac_bs* bs, ma_uint8 riceParam, ma_uint32* pZeroCounterOut, ma_uint32* pRiceParamPartOut)
+{
+ ma_dr_flac_cache_t riceParamMask;
+ ma_uint32 zeroCounter;
+ ma_uint32 setBitOffsetPlus1;
+ ma_uint32 riceParamPart;
+ ma_uint32 riceLength;
+ MA_DR_FLAC_ASSERT(riceParam > 0);
+ riceParamMask = MA_DR_FLAC_CACHE_L1_SELECTION_MASK(riceParam);
zeroCounter = 0;
while (bs->cache == 0) {
- zeroCounter += (drflac_uint32)DRFLAC_CACHE_L1_BITS_REMAINING(bs);
- if (!drflac__reload_cache(bs)) {
- return DRFLAC_FALSE;
+ zeroCounter += (ma_uint32)MA_DR_FLAC_CACHE_L1_BITS_REMAINING(bs);
+ if (!ma_dr_flac__reload_cache(bs)) {
+ return MA_FALSE;
}
}
- setBitOffsetPlus1 = drflac__clz(bs->cache);
+ setBitOffsetPlus1 = ma_dr_flac__clz(bs->cache);
zeroCounter += setBitOffsetPlus1;
setBitOffsetPlus1 += 1;
riceLength = setBitOffsetPlus1 + riceParam;
- if (riceLength < DRFLAC_CACHE_L1_BITS_REMAINING(bs)) {
- riceParamPart = (drflac_uint32)((bs->cache & (riceParamMask >> setBitOffsetPlus1)) >> DRFLAC_CACHE_L1_SELECTION_SHIFT(bs, riceLength));
+ if (riceLength < MA_DR_FLAC_CACHE_L1_BITS_REMAINING(bs)) {
+ riceParamPart = (ma_uint32)((bs->cache & (riceParamMask >> setBitOffsetPlus1)) >> MA_DR_FLAC_CACHE_L1_SELECTION_SHIFT(bs, riceLength));
bs->consumedBits += riceLength;
bs->cache <<= riceLength;
} else {
- drflac_uint32 bitCountLo;
- drflac_cache_t resultHi;
+ ma_uint32 bitCountLo;
+ ma_dr_flac_cache_t resultHi;
bs->consumedBits += riceLength;
- bs->cache <<= setBitOffsetPlus1 & (DRFLAC_CACHE_L1_SIZE_BITS(bs)-1);
- bitCountLo = bs->consumedBits - DRFLAC_CACHE_L1_SIZE_BITS(bs);
- resultHi = DRFLAC_CACHE_L1_SELECT_AND_SHIFT(bs, riceParam);
- if (bs->nextL2Line < DRFLAC_CACHE_L2_LINE_COUNT(bs)) {
-#ifndef DR_FLAC_NO_CRC
- drflac__update_crc16(bs);
-#endif
- bs->cache = drflac__be2host__cache_line(bs->cacheL2[bs->nextL2Line++]);
+ bs->cache <<= setBitOffsetPlus1 & (MA_DR_FLAC_CACHE_L1_SIZE_BITS(bs)-1);
+ bitCountLo = bs->consumedBits - MA_DR_FLAC_CACHE_L1_SIZE_BITS(bs);
+ resultHi = MA_DR_FLAC_CACHE_L1_SELECT_AND_SHIFT(bs, riceParam);
+ if (bs->nextL2Line < MA_DR_FLAC_CACHE_L2_LINE_COUNT(bs)) {
+#ifndef MA_DR_FLAC_NO_CRC
+ ma_dr_flac__update_crc16(bs);
+#endif
+ bs->cache = ma_dr_flac__be2host__cache_line(bs->cacheL2[bs->nextL2Line++]);
bs->consumedBits = 0;
-#ifndef DR_FLAC_NO_CRC
+#ifndef MA_DR_FLAC_NO_CRC
bs->crc16Cache = bs->cache;
#endif
} else {
- if (!drflac__reload_cache(bs)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__reload_cache(bs)) {
+ return MA_FALSE;
}
- if (bitCountLo > DRFLAC_CACHE_L1_BITS_REMAINING(bs)) {
- return DRFLAC_FALSE;
+ if (bitCountLo > MA_DR_FLAC_CACHE_L1_BITS_REMAINING(bs)) {
+ return MA_FALSE;
}
}
- riceParamPart = (drflac_uint32)(resultHi | DRFLAC_CACHE_L1_SELECT_AND_SHIFT_SAFE(bs, bitCountLo));
+ riceParamPart = (ma_uint32)(resultHi | MA_DR_FLAC_CACHE_L1_SELECT_AND_SHIFT_SAFE(bs, bitCountLo));
bs->consumedBits += bitCountLo;
bs->cache <<= bitCountLo;
}
pZeroCounterOut[0] = zeroCounter;
pRiceParamPartOut[0] = riceParamPart;
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
#endif
-static DRFLAC_INLINE drflac_bool32 drflac__read_rice_parts_x1(drflac_bs* bs, drflac_uint8 riceParam, drflac_uint32* pZeroCounterOut, drflac_uint32* pRiceParamPartOut)
+static MA_INLINE ma_bool32 ma_dr_flac__read_rice_parts_x1(ma_dr_flac_bs* bs, ma_uint8 riceParam, ma_uint32* pZeroCounterOut, ma_uint32* pRiceParamPartOut)
{
- drflac_uint32 riceParamPlus1 = riceParam + 1;
- drflac_uint32 riceParamPlus1Shift = DRFLAC_CACHE_L1_SELECTION_SHIFT(bs, riceParamPlus1);
- drflac_uint32 riceParamPlus1MaxConsumedBits = DRFLAC_CACHE_L1_SIZE_BITS(bs) - riceParamPlus1;
- drflac_cache_t bs_cache = bs->cache;
- drflac_uint32 bs_consumedBits = bs->consumedBits;
- drflac_uint32 lzcount = drflac__clz(bs_cache);
+ ma_uint32 riceParamPlus1 = riceParam + 1;
+ ma_uint32 riceParamPlus1Shift = MA_DR_FLAC_CACHE_L1_SELECTION_SHIFT(bs, riceParamPlus1);
+ ma_uint32 riceParamPlus1MaxConsumedBits = MA_DR_FLAC_CACHE_L1_SIZE_BITS(bs) - riceParamPlus1;
+ ma_dr_flac_cache_t bs_cache = bs->cache;
+ ma_uint32 bs_consumedBits = bs->consumedBits;
+ ma_uint32 lzcount = ma_dr_flac__clz(bs_cache);
if (lzcount < sizeof(bs_cache)*8) {
pZeroCounterOut[0] = lzcount;
extract_rice_param_part:
bs_cache <<= lzcount;
bs_consumedBits += lzcount;
if (bs_consumedBits <= riceParamPlus1MaxConsumedBits) {
- pRiceParamPartOut[0] = (drflac_uint32)(bs_cache >> riceParamPlus1Shift);
+ pRiceParamPartOut[0] = (ma_uint32)(bs_cache >> riceParamPlus1Shift);
bs_cache <<= riceParamPlus1;
bs_consumedBits += riceParamPlus1;
} else {
- drflac_uint32 riceParamPartHi;
- drflac_uint32 riceParamPartLo;
- drflac_uint32 riceParamPartLoBitCount;
- riceParamPartHi = (drflac_uint32)(bs_cache >> riceParamPlus1Shift);
+ ma_uint32 riceParamPartHi;
+ ma_uint32 riceParamPartLo;
+ ma_uint32 riceParamPartLoBitCount;
+ riceParamPartHi = (ma_uint32)(bs_cache >> riceParamPlus1Shift);
riceParamPartLoBitCount = bs_consumedBits - riceParamPlus1MaxConsumedBits;
- DRFLAC_ASSERT(riceParamPartLoBitCount > 0 && riceParamPartLoBitCount < 32);
- if (bs->nextL2Line < DRFLAC_CACHE_L2_LINE_COUNT(bs)) {
- #ifndef DR_FLAC_NO_CRC
- drflac__update_crc16(bs);
+ MA_DR_FLAC_ASSERT(riceParamPartLoBitCount > 0 && riceParamPartLoBitCount < 32);
+ if (bs->nextL2Line < MA_DR_FLAC_CACHE_L2_LINE_COUNT(bs)) {
+ #ifndef MA_DR_FLAC_NO_CRC
+ ma_dr_flac__update_crc16(bs);
#endif
- bs_cache = drflac__be2host__cache_line(bs->cacheL2[bs->nextL2Line++]);
+ bs_cache = ma_dr_flac__be2host__cache_line(bs->cacheL2[bs->nextL2Line++]);
bs_consumedBits = riceParamPartLoBitCount;
- #ifndef DR_FLAC_NO_CRC
+ #ifndef MA_DR_FLAC_NO_CRC
bs->crc16Cache = bs_cache;
#endif
} else {
- if (!drflac__reload_cache(bs)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__reload_cache(bs)) {
+ return MA_FALSE;
}
- if (riceParamPartLoBitCount > DRFLAC_CACHE_L1_BITS_REMAINING(bs)) {
- return DRFLAC_FALSE;
+ if (riceParamPartLoBitCount > MA_DR_FLAC_CACHE_L1_BITS_REMAINING(bs)) {
+ return MA_FALSE;
}
bs_cache = bs->cache;
bs_consumedBits = bs->consumedBits + riceParamPartLoBitCount;
}
- riceParamPartLo = (drflac_uint32)(bs_cache >> (DRFLAC_CACHE_L1_SELECTION_SHIFT(bs, riceParamPartLoBitCount)));
+ riceParamPartLo = (ma_uint32)(bs_cache >> (MA_DR_FLAC_CACHE_L1_SELECTION_SHIFT(bs, riceParamPartLoBitCount)));
pRiceParamPartOut[0] = riceParamPartHi | riceParamPartLo;
bs_cache <<= riceParamPartLoBitCount;
}
} else {
- drflac_uint32 zeroCounter = (drflac_uint32)(DRFLAC_CACHE_L1_SIZE_BITS(bs) - bs_consumedBits);
+ ma_uint32 zeroCounter = (ma_uint32)(MA_DR_FLAC_CACHE_L1_SIZE_BITS(bs) - bs_consumedBits);
for (;;) {
- if (bs->nextL2Line < DRFLAC_CACHE_L2_LINE_COUNT(bs)) {
- #ifndef DR_FLAC_NO_CRC
- drflac__update_crc16(bs);
+ if (bs->nextL2Line < MA_DR_FLAC_CACHE_L2_LINE_COUNT(bs)) {
+ #ifndef MA_DR_FLAC_NO_CRC
+ ma_dr_flac__update_crc16(bs);
#endif
- bs_cache = drflac__be2host__cache_line(bs->cacheL2[bs->nextL2Line++]);
+ bs_cache = ma_dr_flac__be2host__cache_line(bs->cacheL2[bs->nextL2Line++]);
bs_consumedBits = 0;
- #ifndef DR_FLAC_NO_CRC
+ #ifndef MA_DR_FLAC_NO_CRC
bs->crc16Cache = bs_cache;
#endif
} else {
- if (!drflac__reload_cache(bs)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__reload_cache(bs)) {
+ return MA_FALSE;
}
bs_cache = bs->cache;
bs_consumedBits = bs->consumedBits;
}
- lzcount = drflac__clz(bs_cache);
+ lzcount = ma_dr_flac__clz(bs_cache);
zeroCounter += lzcount;
if (lzcount < sizeof(bs_cache)*8) {
break;
@@ -81337,15 +83769,15 @@ static DRFLAC_INLINE drflac_bool32 drflac__read_rice_parts_x1(drflac_bs* bs, drf
}
bs->cache = bs_cache;
bs->consumedBits = bs_consumedBits;
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
-static DRFLAC_INLINE drflac_bool32 drflac__seek_rice_parts(drflac_bs* bs, drflac_uint8 riceParam)
+static MA_INLINE ma_bool32 ma_dr_flac__seek_rice_parts(ma_dr_flac_bs* bs, ma_uint8 riceParam)
{
- drflac_uint32 riceParamPlus1 = riceParam + 1;
- drflac_uint32 riceParamPlus1MaxConsumedBits = DRFLAC_CACHE_L1_SIZE_BITS(bs) - riceParamPlus1;
- drflac_cache_t bs_cache = bs->cache;
- drflac_uint32 bs_consumedBits = bs->consumedBits;
- drflac_uint32 lzcount = drflac__clz(bs_cache);
+ ma_uint32 riceParamPlus1 = riceParam + 1;
+ ma_uint32 riceParamPlus1MaxConsumedBits = MA_DR_FLAC_CACHE_L1_SIZE_BITS(bs) - riceParamPlus1;
+ ma_dr_flac_cache_t bs_cache = bs->cache;
+ ma_uint32 bs_consumedBits = bs->consumedBits;
+ ma_uint32 lzcount = ma_dr_flac__clz(bs_cache);
if (lzcount < sizeof(bs_cache)*8) {
extract_rice_param_part:
bs_cache <<= lzcount;
@@ -81354,23 +83786,23 @@ static DRFLAC_INLINE drflac_bool32 drflac__seek_rice_parts(drflac_bs* bs, drflac
bs_cache <<= riceParamPlus1;
bs_consumedBits += riceParamPlus1;
} else {
- drflac_uint32 riceParamPartLoBitCount = bs_consumedBits - riceParamPlus1MaxConsumedBits;
- DRFLAC_ASSERT(riceParamPartLoBitCount > 0 && riceParamPartLoBitCount < 32);
- if (bs->nextL2Line < DRFLAC_CACHE_L2_LINE_COUNT(bs)) {
- #ifndef DR_FLAC_NO_CRC
- drflac__update_crc16(bs);
+ ma_uint32 riceParamPartLoBitCount = bs_consumedBits - riceParamPlus1MaxConsumedBits;
+ MA_DR_FLAC_ASSERT(riceParamPartLoBitCount > 0 && riceParamPartLoBitCount < 32);
+ if (bs->nextL2Line < MA_DR_FLAC_CACHE_L2_LINE_COUNT(bs)) {
+ #ifndef MA_DR_FLAC_NO_CRC
+ ma_dr_flac__update_crc16(bs);
#endif
- bs_cache = drflac__be2host__cache_line(bs->cacheL2[bs->nextL2Line++]);
+ bs_cache = ma_dr_flac__be2host__cache_line(bs->cacheL2[bs->nextL2Line++]);
bs_consumedBits = riceParamPartLoBitCount;
- #ifndef DR_FLAC_NO_CRC
+ #ifndef MA_DR_FLAC_NO_CRC
bs->crc16Cache = bs_cache;
#endif
} else {
- if (!drflac__reload_cache(bs)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__reload_cache(bs)) {
+ return MA_FALSE;
}
- if (riceParamPartLoBitCount > DRFLAC_CACHE_L1_BITS_REMAINING(bs)) {
- return DRFLAC_FALSE;
+ if (riceParamPartLoBitCount > MA_DR_FLAC_CACHE_L1_BITS_REMAINING(bs)) {
+ return MA_FALSE;
}
bs_cache = bs->cache;
bs_consumedBits = bs->consumedBits + riceParamPartLoBitCount;
@@ -81379,23 +83811,23 @@ static DRFLAC_INLINE drflac_bool32 drflac__seek_rice_parts(drflac_bs* bs, drflac
}
} else {
for (;;) {
- if (bs->nextL2Line < DRFLAC_CACHE_L2_LINE_COUNT(bs)) {
- #ifndef DR_FLAC_NO_CRC
- drflac__update_crc16(bs);
+ if (bs->nextL2Line < MA_DR_FLAC_CACHE_L2_LINE_COUNT(bs)) {
+ #ifndef MA_DR_FLAC_NO_CRC
+ ma_dr_flac__update_crc16(bs);
#endif
- bs_cache = drflac__be2host__cache_line(bs->cacheL2[bs->nextL2Line++]);
+ bs_cache = ma_dr_flac__be2host__cache_line(bs->cacheL2[bs->nextL2Line++]);
bs_consumedBits = 0;
- #ifndef DR_FLAC_NO_CRC
+ #ifndef MA_DR_FLAC_NO_CRC
bs->crc16Cache = bs_cache;
#endif
} else {
- if (!drflac__reload_cache(bs)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__reload_cache(bs)) {
+ return MA_FALSE;
}
bs_cache = bs->cache;
bs_consumedBits = bs->consumedBits;
}
- lzcount = drflac__clz(bs_cache);
+ lzcount = ma_dr_flac__clz(bs_cache);
if (lzcount < sizeof(bs_cache)*8) {
break;
}
@@ -81404,26 +83836,26 @@ static DRFLAC_INLINE drflac_bool32 drflac__seek_rice_parts(drflac_bs* bs, drflac
}
bs->cache = bs_cache;
bs->consumedBits = bs_consumedBits;
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
-static drflac_bool32 drflac__decode_samples_with_residual__rice__scalar_zeroorder(drflac_bs* bs, drflac_uint32 bitsPerSample, drflac_uint32 count, drflac_uint8 riceParam, drflac_uint32 order, drflac_int32 shift, const drflac_int32* coefficients, drflac_int32* pSamplesOut)
+static ma_bool32 ma_dr_flac__decode_samples_with_residual__rice__scalar_zeroorder(ma_dr_flac_bs* bs, ma_uint32 bitsPerSample, ma_uint32 count, ma_uint8 riceParam, ma_uint32 order, ma_int32 shift, const ma_int32* coefficients, ma_int32* pSamplesOut)
{
- drflac_uint32 t[2] = {0x00000000, 0xFFFFFFFF};
- drflac_uint32 zeroCountPart0;
- drflac_uint32 riceParamPart0;
- drflac_uint32 riceParamMask;
- drflac_uint32 i;
- DRFLAC_ASSERT(bs != NULL);
- DRFLAC_ASSERT(pSamplesOut != NULL);
+ ma_uint32 t[2] = {0x00000000, 0xFFFFFFFF};
+ ma_uint32 zeroCountPart0;
+ ma_uint32 riceParamPart0;
+ ma_uint32 riceParamMask;
+ ma_uint32 i;
+ MA_DR_FLAC_ASSERT(bs != NULL);
+ MA_DR_FLAC_ASSERT(pSamplesOut != NULL);
(void)bitsPerSample;
(void)order;
(void)shift;
(void)coefficients;
- riceParamMask = (drflac_uint32)~((~0UL) << riceParam);
+ riceParamMask = (ma_uint32)~((~0UL) << riceParam);
i = 0;
while (i < count) {
- if (!drflac__read_rice_parts_x1(bs, riceParam, &zeroCountPart0, &riceParamPart0)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_rice_parts_x1(bs, riceParam, &zeroCountPart0, &riceParamPart0)) {
+ return MA_FALSE;
}
riceParamPart0 &= riceParamMask;
riceParamPart0 |= (zeroCountPart0 << riceParam);
@@ -81431,36 +83863,36 @@ static drflac_bool32 drflac__decode_samples_with_residual__rice__scalar_zeroorde
pSamplesOut[i] = riceParamPart0;
i += 1;
}
- return DRFLAC_TRUE;
-}
-static drflac_bool32 drflac__decode_samples_with_residual__rice__scalar(drflac_bs* bs, drflac_uint32 bitsPerSample, drflac_uint32 count, drflac_uint8 riceParam, drflac_uint32 lpcOrder, drflac_int32 lpcShift, drflac_uint32 lpcPrecision, const drflac_int32* coefficients, drflac_int32* pSamplesOut)
-{
- drflac_uint32 t[2] = {0x00000000, 0xFFFFFFFF};
- drflac_uint32 zeroCountPart0 = 0;
- drflac_uint32 zeroCountPart1 = 0;
- drflac_uint32 zeroCountPart2 = 0;
- drflac_uint32 zeroCountPart3 = 0;
- drflac_uint32 riceParamPart0 = 0;
- drflac_uint32 riceParamPart1 = 0;
- drflac_uint32 riceParamPart2 = 0;
- drflac_uint32 riceParamPart3 = 0;
- drflac_uint32 riceParamMask;
- const drflac_int32* pSamplesOutEnd;
- drflac_uint32 i;
- DRFLAC_ASSERT(bs != NULL);
- DRFLAC_ASSERT(pSamplesOut != NULL);
+ return MA_TRUE;
+}
+static ma_bool32 ma_dr_flac__decode_samples_with_residual__rice__scalar(ma_dr_flac_bs* bs, ma_uint32 bitsPerSample, ma_uint32 count, ma_uint8 riceParam, ma_uint32 lpcOrder, ma_int32 lpcShift, ma_uint32 lpcPrecision, const ma_int32* coefficients, ma_int32* pSamplesOut)
+{
+ ma_uint32 t[2] = {0x00000000, 0xFFFFFFFF};
+ ma_uint32 zeroCountPart0 = 0;
+ ma_uint32 zeroCountPart1 = 0;
+ ma_uint32 zeroCountPart2 = 0;
+ ma_uint32 zeroCountPart3 = 0;
+ ma_uint32 riceParamPart0 = 0;
+ ma_uint32 riceParamPart1 = 0;
+ ma_uint32 riceParamPart2 = 0;
+ ma_uint32 riceParamPart3 = 0;
+ ma_uint32 riceParamMask;
+ const ma_int32* pSamplesOutEnd;
+ ma_uint32 i;
+ MA_DR_FLAC_ASSERT(bs != NULL);
+ MA_DR_FLAC_ASSERT(pSamplesOut != NULL);
if (lpcOrder == 0) {
- return drflac__decode_samples_with_residual__rice__scalar_zeroorder(bs, bitsPerSample, count, riceParam, lpcOrder, lpcShift, coefficients, pSamplesOut);
+ return ma_dr_flac__decode_samples_with_residual__rice__scalar_zeroorder(bs, bitsPerSample, count, riceParam, lpcOrder, lpcShift, coefficients, pSamplesOut);
}
- riceParamMask = (drflac_uint32)~((~0UL) << riceParam);
+ riceParamMask = (ma_uint32)~((~0UL) << riceParam);
pSamplesOutEnd = pSamplesOut + (count & ~3);
- if (drflac__use_64_bit_prediction(bitsPerSample, lpcOrder, lpcPrecision)) {
+ if (ma_dr_flac__use_64_bit_prediction(bitsPerSample, lpcOrder, lpcPrecision)) {
while (pSamplesOut < pSamplesOutEnd) {
- if (!drflac__read_rice_parts_x1(bs, riceParam, &zeroCountPart0, &riceParamPart0) ||
- !drflac__read_rice_parts_x1(bs, riceParam, &zeroCountPart1, &riceParamPart1) ||
- !drflac__read_rice_parts_x1(bs, riceParam, &zeroCountPart2, &riceParamPart2) ||
- !drflac__read_rice_parts_x1(bs, riceParam, &zeroCountPart3, &riceParamPart3)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_rice_parts_x1(bs, riceParam, &zeroCountPart0, &riceParamPart0) ||
+ !ma_dr_flac__read_rice_parts_x1(bs, riceParam, &zeroCountPart1, &riceParamPart1) ||
+ !ma_dr_flac__read_rice_parts_x1(bs, riceParam, &zeroCountPart2, &riceParamPart2) ||
+ !ma_dr_flac__read_rice_parts_x1(bs, riceParam, &zeroCountPart3, &riceParamPart3)) {
+ return MA_FALSE;
}
riceParamPart0 &= riceParamMask;
riceParamPart1 &= riceParamMask;
@@ -81474,19 +83906,19 @@ static drflac_bool32 drflac__decode_samples_with_residual__rice__scalar(drflac_b
riceParamPart1 = (riceParamPart1 >> 1) ^ t[riceParamPart1 & 0x01];
riceParamPart2 = (riceParamPart2 >> 1) ^ t[riceParamPart2 & 0x01];
riceParamPart3 = (riceParamPart3 >> 1) ^ t[riceParamPart3 & 0x01];
- pSamplesOut[0] = riceParamPart0 + drflac__calculate_prediction_64(lpcOrder, lpcShift, coefficients, pSamplesOut + 0);
- pSamplesOut[1] = riceParamPart1 + drflac__calculate_prediction_64(lpcOrder, lpcShift, coefficients, pSamplesOut + 1);
- pSamplesOut[2] = riceParamPart2 + drflac__calculate_prediction_64(lpcOrder, lpcShift, coefficients, pSamplesOut + 2);
- pSamplesOut[3] = riceParamPart3 + drflac__calculate_prediction_64(lpcOrder, lpcShift, coefficients, pSamplesOut + 3);
+ pSamplesOut[0] = riceParamPart0 + ma_dr_flac__calculate_prediction_64(lpcOrder, lpcShift, coefficients, pSamplesOut + 0);
+ pSamplesOut[1] = riceParamPart1 + ma_dr_flac__calculate_prediction_64(lpcOrder, lpcShift, coefficients, pSamplesOut + 1);
+ pSamplesOut[2] = riceParamPart2 + ma_dr_flac__calculate_prediction_64(lpcOrder, lpcShift, coefficients, pSamplesOut + 2);
+ pSamplesOut[3] = riceParamPart3 + ma_dr_flac__calculate_prediction_64(lpcOrder, lpcShift, coefficients, pSamplesOut + 3);
pSamplesOut += 4;
}
} else {
while (pSamplesOut < pSamplesOutEnd) {
- if (!drflac__read_rice_parts_x1(bs, riceParam, &zeroCountPart0, &riceParamPart0) ||
- !drflac__read_rice_parts_x1(bs, riceParam, &zeroCountPart1, &riceParamPart1) ||
- !drflac__read_rice_parts_x1(bs, riceParam, &zeroCountPart2, &riceParamPart2) ||
- !drflac__read_rice_parts_x1(bs, riceParam, &zeroCountPart3, &riceParamPart3)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_rice_parts_x1(bs, riceParam, &zeroCountPart0, &riceParamPart0) ||
+ !ma_dr_flac__read_rice_parts_x1(bs, riceParam, &zeroCountPart1, &riceParamPart1) ||
+ !ma_dr_flac__read_rice_parts_x1(bs, riceParam, &zeroCountPart2, &riceParamPart2) ||
+ !ma_dr_flac__read_rice_parts_x1(bs, riceParam, &zeroCountPart3, &riceParamPart3)) {
+ return MA_FALSE;
}
riceParamPart0 &= riceParamMask;
riceParamPart1 &= riceParamMask;
@@ -81500,33 +83932,33 @@ static drflac_bool32 drflac__decode_samples_with_residual__rice__scalar(drflac_b
riceParamPart1 = (riceParamPart1 >> 1) ^ t[riceParamPart1 & 0x01];
riceParamPart2 = (riceParamPart2 >> 1) ^ t[riceParamPart2 & 0x01];
riceParamPart3 = (riceParamPart3 >> 1) ^ t[riceParamPart3 & 0x01];
- pSamplesOut[0] = riceParamPart0 + drflac__calculate_prediction_32(lpcOrder, lpcShift, coefficients, pSamplesOut + 0);
- pSamplesOut[1] = riceParamPart1 + drflac__calculate_prediction_32(lpcOrder, lpcShift, coefficients, pSamplesOut + 1);
- pSamplesOut[2] = riceParamPart2 + drflac__calculate_prediction_32(lpcOrder, lpcShift, coefficients, pSamplesOut + 2);
- pSamplesOut[3] = riceParamPart3 + drflac__calculate_prediction_32(lpcOrder, lpcShift, coefficients, pSamplesOut + 3);
+ pSamplesOut[0] = riceParamPart0 + ma_dr_flac__calculate_prediction_32(lpcOrder, lpcShift, coefficients, pSamplesOut + 0);
+ pSamplesOut[1] = riceParamPart1 + ma_dr_flac__calculate_prediction_32(lpcOrder, lpcShift, coefficients, pSamplesOut + 1);
+ pSamplesOut[2] = riceParamPart2 + ma_dr_flac__calculate_prediction_32(lpcOrder, lpcShift, coefficients, pSamplesOut + 2);
+ pSamplesOut[3] = riceParamPart3 + ma_dr_flac__calculate_prediction_32(lpcOrder, lpcShift, coefficients, pSamplesOut + 3);
pSamplesOut += 4;
}
}
i = (count & ~3);
while (i < count) {
- if (!drflac__read_rice_parts_x1(bs, riceParam, &zeroCountPart0, &riceParamPart0)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_rice_parts_x1(bs, riceParam, &zeroCountPart0, &riceParamPart0)) {
+ return MA_FALSE;
}
riceParamPart0 &= riceParamMask;
riceParamPart0 |= (zeroCountPart0 << riceParam);
riceParamPart0 = (riceParamPart0 >> 1) ^ t[riceParamPart0 & 0x01];
- if (drflac__use_64_bit_prediction(bitsPerSample, lpcOrder, lpcPrecision)) {
- pSamplesOut[0] = riceParamPart0 + drflac__calculate_prediction_64(lpcOrder, lpcShift, coefficients, pSamplesOut + 0);
+ if (ma_dr_flac__use_64_bit_prediction(bitsPerSample, lpcOrder, lpcPrecision)) {
+ pSamplesOut[0] = riceParamPart0 + ma_dr_flac__calculate_prediction_64(lpcOrder, lpcShift, coefficients, pSamplesOut + 0);
} else {
- pSamplesOut[0] = riceParamPart0 + drflac__calculate_prediction_32(lpcOrder, lpcShift, coefficients, pSamplesOut + 0);
+ pSamplesOut[0] = riceParamPart0 + ma_dr_flac__calculate_prediction_32(lpcOrder, lpcShift, coefficients, pSamplesOut + 0);
}
i += 1;
pSamplesOut += 1;
}
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
-#if defined(DRFLAC_SUPPORT_SSE2)
-static DRFLAC_INLINE __m128i drflac__mm_packs_interleaved_epi32(__m128i a, __m128i b)
+#if defined(MA_DR_FLAC_SUPPORT_SSE2)
+static MA_INLINE __m128i ma_dr_flac__mm_packs_interleaved_epi32(__m128i a, __m128i b)
{
__m128i r;
r = _mm_packs_epi32(a, b);
@@ -81536,42 +83968,42 @@ static DRFLAC_INLINE __m128i drflac__mm_packs_interleaved_epi32(__m128i a, __m12
return r;
}
#endif
-#if defined(DRFLAC_SUPPORT_SSE41)
-static DRFLAC_INLINE __m128i drflac__mm_not_si128(__m128i a)
+#if defined(MA_DR_FLAC_SUPPORT_SSE41)
+static MA_INLINE __m128i ma_dr_flac__mm_not_si128(__m128i a)
{
return _mm_xor_si128(a, _mm_cmpeq_epi32(_mm_setzero_si128(), _mm_setzero_si128()));
}
-static DRFLAC_INLINE __m128i drflac__mm_hadd_epi32(__m128i x)
+static MA_INLINE __m128i ma_dr_flac__mm_hadd_epi32(__m128i x)
{
__m128i x64 = _mm_add_epi32(x, _mm_shuffle_epi32(x, _MM_SHUFFLE(1, 0, 3, 2)));
__m128i x32 = _mm_shufflelo_epi16(x64, _MM_SHUFFLE(1, 0, 3, 2));
return _mm_add_epi32(x64, x32);
}
-static DRFLAC_INLINE __m128i drflac__mm_hadd_epi64(__m128i x)
+static MA_INLINE __m128i ma_dr_flac__mm_hadd_epi64(__m128i x)
{
return _mm_add_epi64(x, _mm_shuffle_epi32(x, _MM_SHUFFLE(1, 0, 3, 2)));
}
-static DRFLAC_INLINE __m128i drflac__mm_srai_epi64(__m128i x, int count)
+static MA_INLINE __m128i ma_dr_flac__mm_srai_epi64(__m128i x, int count)
{
__m128i lo = _mm_srli_epi64(x, count);
__m128i hi = _mm_srai_epi32(x, count);
hi = _mm_and_si128(hi, _mm_set_epi32(0xFFFFFFFF, 0, 0xFFFFFFFF, 0));
return _mm_or_si128(lo, hi);
}
-static drflac_bool32 drflac__decode_samples_with_residual__rice__sse41_32(drflac_bs* bs, drflac_uint32 count, drflac_uint8 riceParam, drflac_uint32 order, drflac_int32 shift, const drflac_int32* coefficients, drflac_int32* pSamplesOut)
+static ma_bool32 ma_dr_flac__decode_samples_with_residual__rice__sse41_32(ma_dr_flac_bs* bs, ma_uint32 count, ma_uint8 riceParam, ma_uint32 order, ma_int32 shift, const ma_int32* coefficients, ma_int32* pSamplesOut)
{
int i;
- drflac_uint32 riceParamMask;
- drflac_int32* pDecodedSamples = pSamplesOut;
- drflac_int32* pDecodedSamplesEnd = pSamplesOut + (count & ~3);
- drflac_uint32 zeroCountParts0 = 0;
- drflac_uint32 zeroCountParts1 = 0;
- drflac_uint32 zeroCountParts2 = 0;
- drflac_uint32 zeroCountParts3 = 0;
- drflac_uint32 riceParamParts0 = 0;
- drflac_uint32 riceParamParts1 = 0;
- drflac_uint32 riceParamParts2 = 0;
- drflac_uint32 riceParamParts3 = 0;
+ ma_uint32 riceParamMask;
+ ma_int32* pDecodedSamples = pSamplesOut;
+ ma_int32* pDecodedSamplesEnd = pSamplesOut + (count & ~3);
+ ma_uint32 zeroCountParts0 = 0;
+ ma_uint32 zeroCountParts1 = 0;
+ ma_uint32 zeroCountParts2 = 0;
+ ma_uint32 zeroCountParts3 = 0;
+ ma_uint32 riceParamParts0 = 0;
+ ma_uint32 riceParamParts1 = 0;
+ ma_uint32 riceParamParts2 = 0;
+ ma_uint32 riceParamParts3 = 0;
__m128i coefficients128_0;
__m128i coefficients128_4;
__m128i coefficients128_8;
@@ -81579,8 +84011,8 @@ static drflac_bool32 drflac__decode_samples_with_residual__rice__sse41_32(drflac
__m128i samples128_4;
__m128i samples128_8;
__m128i riceParamMask128;
- const drflac_uint32 t[2] = {0x00000000, 0xFFFFFFFF};
- riceParamMask = (drflac_uint32)~((~0UL) << riceParam);
+ const ma_uint32 t[2] = {0x00000000, 0xFFFFFFFF};
+ riceParamMask = (ma_uint32)~((~0UL) << riceParam);
riceParamMask128 = _mm_set1_epi32(riceParamMask);
coefficients128_0 = _mm_setzero_si128();
coefficients128_4 = _mm_setzero_si128();
@@ -81634,39 +84066,39 @@ static drflac_bool32 drflac__decode_samples_with_residual__rice__sse41_32(drflac
#else
switch (order)
{
- case 12: ((drflac_int32*)&coefficients128_8)[0] = coefficients[11]; ((drflac_int32*)&samples128_8)[0] = pDecodedSamples[-12];
- case 11: ((drflac_int32*)&coefficients128_8)[1] = coefficients[10]; ((drflac_int32*)&samples128_8)[1] = pDecodedSamples[-11];
- case 10: ((drflac_int32*)&coefficients128_8)[2] = coefficients[ 9]; ((drflac_int32*)&samples128_8)[2] = pDecodedSamples[-10];
- case 9: ((drflac_int32*)&coefficients128_8)[3] = coefficients[ 8]; ((drflac_int32*)&samples128_8)[3] = pDecodedSamples[- 9];
- case 8: ((drflac_int32*)&coefficients128_4)[0] = coefficients[ 7]; ((drflac_int32*)&samples128_4)[0] = pDecodedSamples[- 8];
- case 7: ((drflac_int32*)&coefficients128_4)[1] = coefficients[ 6]; ((drflac_int32*)&samples128_4)[1] = pDecodedSamples[- 7];
- case 6: ((drflac_int32*)&coefficients128_4)[2] = coefficients[ 5]; ((drflac_int32*)&samples128_4)[2] = pDecodedSamples[- 6];
- case 5: ((drflac_int32*)&coefficients128_4)[3] = coefficients[ 4]; ((drflac_int32*)&samples128_4)[3] = pDecodedSamples[- 5];
- case 4: ((drflac_int32*)&coefficients128_0)[0] = coefficients[ 3]; ((drflac_int32*)&samples128_0)[0] = pDecodedSamples[- 4];
- case 3: ((drflac_int32*)&coefficients128_0)[1] = coefficients[ 2]; ((drflac_int32*)&samples128_0)[1] = pDecodedSamples[- 3];
- case 2: ((drflac_int32*)&coefficients128_0)[2] = coefficients[ 1]; ((drflac_int32*)&samples128_0)[2] = pDecodedSamples[- 2];
- case 1: ((drflac_int32*)&coefficients128_0)[3] = coefficients[ 0]; ((drflac_int32*)&samples128_0)[3] = pDecodedSamples[- 1];
+ case 12: ((ma_int32*)&coefficients128_8)[0] = coefficients[11]; ((ma_int32*)&samples128_8)[0] = pDecodedSamples[-12];
+ case 11: ((ma_int32*)&coefficients128_8)[1] = coefficients[10]; ((ma_int32*)&samples128_8)[1] = pDecodedSamples[-11];
+ case 10: ((ma_int32*)&coefficients128_8)[2] = coefficients[ 9]; ((ma_int32*)&samples128_8)[2] = pDecodedSamples[-10];
+ case 9: ((ma_int32*)&coefficients128_8)[3] = coefficients[ 8]; ((ma_int32*)&samples128_8)[3] = pDecodedSamples[- 9];
+ case 8: ((ma_int32*)&coefficients128_4)[0] = coefficients[ 7]; ((ma_int32*)&samples128_4)[0] = pDecodedSamples[- 8];
+ case 7: ((ma_int32*)&coefficients128_4)[1] = coefficients[ 6]; ((ma_int32*)&samples128_4)[1] = pDecodedSamples[- 7];
+ case 6: ((ma_int32*)&coefficients128_4)[2] = coefficients[ 5]; ((ma_int32*)&samples128_4)[2] = pDecodedSamples[- 6];
+ case 5: ((ma_int32*)&coefficients128_4)[3] = coefficients[ 4]; ((ma_int32*)&samples128_4)[3] = pDecodedSamples[- 5];
+ case 4: ((ma_int32*)&coefficients128_0)[0] = coefficients[ 3]; ((ma_int32*)&samples128_0)[0] = pDecodedSamples[- 4];
+ case 3: ((ma_int32*)&coefficients128_0)[1] = coefficients[ 2]; ((ma_int32*)&samples128_0)[1] = pDecodedSamples[- 3];
+ case 2: ((ma_int32*)&coefficients128_0)[2] = coefficients[ 1]; ((ma_int32*)&samples128_0)[2] = pDecodedSamples[- 2];
+ case 1: ((ma_int32*)&coefficients128_0)[3] = coefficients[ 0]; ((ma_int32*)&samples128_0)[3] = pDecodedSamples[- 1];
}
#endif
while (pDecodedSamples < pDecodedSamplesEnd) {
__m128i prediction128;
__m128i zeroCountPart128;
__m128i riceParamPart128;
- if (!drflac__read_rice_parts_x1(bs, riceParam, &zeroCountParts0, &riceParamParts0) ||
- !drflac__read_rice_parts_x1(bs, riceParam, &zeroCountParts1, &riceParamParts1) ||
- !drflac__read_rice_parts_x1(bs, riceParam, &zeroCountParts2, &riceParamParts2) ||
- !drflac__read_rice_parts_x1(bs, riceParam, &zeroCountParts3, &riceParamParts3)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_rice_parts_x1(bs, riceParam, &zeroCountParts0, &riceParamParts0) ||
+ !ma_dr_flac__read_rice_parts_x1(bs, riceParam, &zeroCountParts1, &riceParamParts1) ||
+ !ma_dr_flac__read_rice_parts_x1(bs, riceParam, &zeroCountParts2, &riceParamParts2) ||
+ !ma_dr_flac__read_rice_parts_x1(bs, riceParam, &zeroCountParts3, &riceParamParts3)) {
+ return MA_FALSE;
}
zeroCountPart128 = _mm_set_epi32(zeroCountParts3, zeroCountParts2, zeroCountParts1, zeroCountParts0);
riceParamPart128 = _mm_set_epi32(riceParamParts3, riceParamParts2, riceParamParts1, riceParamParts0);
riceParamPart128 = _mm_and_si128(riceParamPart128, riceParamMask128);
riceParamPart128 = _mm_or_si128(riceParamPart128, _mm_slli_epi32(zeroCountPart128, riceParam));
- riceParamPart128 = _mm_xor_si128(_mm_srli_epi32(riceParamPart128, 1), _mm_add_epi32(drflac__mm_not_si128(_mm_and_si128(riceParamPart128, _mm_set1_epi32(0x01))), _mm_set1_epi32(0x01)));
+ riceParamPart128 = _mm_xor_si128(_mm_srli_epi32(riceParamPart128, 1), _mm_add_epi32(ma_dr_flac__mm_not_si128(_mm_and_si128(riceParamPart128, _mm_set1_epi32(0x01))), _mm_set1_epi32(0x01)));
if (order <= 4) {
for (i = 0; i < 4; i += 1) {
prediction128 = _mm_mullo_epi32(coefficients128_0, samples128_0);
- prediction128 = drflac__mm_hadd_epi32(prediction128);
+ prediction128 = ma_dr_flac__mm_hadd_epi32(prediction128);
prediction128 = _mm_srai_epi32(prediction128, shift);
prediction128 = _mm_add_epi32(riceParamPart128, prediction128);
samples128_0 = _mm_alignr_epi8(prediction128, samples128_0, 4);
@@ -81676,7 +84108,7 @@ static drflac_bool32 drflac__decode_samples_with_residual__rice__sse41_32(drflac
for (i = 0; i < 4; i += 1) {
prediction128 = _mm_mullo_epi32(coefficients128_4, samples128_4);
prediction128 = _mm_add_epi32(prediction128, _mm_mullo_epi32(coefficients128_0, samples128_0));
- prediction128 = drflac__mm_hadd_epi32(prediction128);
+ prediction128 = ma_dr_flac__mm_hadd_epi32(prediction128);
prediction128 = _mm_srai_epi32(prediction128, shift);
prediction128 = _mm_add_epi32(riceParamPart128, prediction128);
samples128_4 = _mm_alignr_epi8(samples128_0, samples128_4, 4);
@@ -81688,7 +84120,7 @@ static drflac_bool32 drflac__decode_samples_with_residual__rice__sse41_32(drflac
prediction128 = _mm_mullo_epi32(coefficients128_8, samples128_8);
prediction128 = _mm_add_epi32(prediction128, _mm_mullo_epi32(coefficients128_4, samples128_4));
prediction128 = _mm_add_epi32(prediction128, _mm_mullo_epi32(coefficients128_0, samples128_0));
- prediction128 = drflac__mm_hadd_epi32(prediction128);
+ prediction128 = ma_dr_flac__mm_hadd_epi32(prediction128);
prediction128 = _mm_srai_epi32(prediction128, shift);
prediction128 = _mm_add_epi32(riceParamPart128, prediction128);
samples128_8 = _mm_alignr_epi8(samples128_4, samples128_8, 4);
@@ -81702,32 +84134,32 @@ static drflac_bool32 drflac__decode_samples_with_residual__rice__sse41_32(drflac
}
i = (count & ~3);
while (i < (int)count) {
- if (!drflac__read_rice_parts_x1(bs, riceParam, &zeroCountParts0, &riceParamParts0)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_rice_parts_x1(bs, riceParam, &zeroCountParts0, &riceParamParts0)) {
+ return MA_FALSE;
}
riceParamParts0 &= riceParamMask;
riceParamParts0 |= (zeroCountParts0 << riceParam);
riceParamParts0 = (riceParamParts0 >> 1) ^ t[riceParamParts0 & 0x01];
- pDecodedSamples[0] = riceParamParts0 + drflac__calculate_prediction_32(order, shift, coefficients, pDecodedSamples);
+ pDecodedSamples[0] = riceParamParts0 + ma_dr_flac__calculate_prediction_32(order, shift, coefficients, pDecodedSamples);
i += 1;
pDecodedSamples += 1;
}
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
-static drflac_bool32 drflac__decode_samples_with_residual__rice__sse41_64(drflac_bs* bs, drflac_uint32 count, drflac_uint8 riceParam, drflac_uint32 order, drflac_int32 shift, const drflac_int32* coefficients, drflac_int32* pSamplesOut)
+static ma_bool32 ma_dr_flac__decode_samples_with_residual__rice__sse41_64(ma_dr_flac_bs* bs, ma_uint32 count, ma_uint8 riceParam, ma_uint32 order, ma_int32 shift, const ma_int32* coefficients, ma_int32* pSamplesOut)
{
int i;
- drflac_uint32 riceParamMask;
- drflac_int32* pDecodedSamples = pSamplesOut;
- drflac_int32* pDecodedSamplesEnd = pSamplesOut + (count & ~3);
- drflac_uint32 zeroCountParts0 = 0;
- drflac_uint32 zeroCountParts1 = 0;
- drflac_uint32 zeroCountParts2 = 0;
- drflac_uint32 zeroCountParts3 = 0;
- drflac_uint32 riceParamParts0 = 0;
- drflac_uint32 riceParamParts1 = 0;
- drflac_uint32 riceParamParts2 = 0;
- drflac_uint32 riceParamParts3 = 0;
+ ma_uint32 riceParamMask;
+ ma_int32* pDecodedSamples = pSamplesOut;
+ ma_int32* pDecodedSamplesEnd = pSamplesOut + (count & ~3);
+ ma_uint32 zeroCountParts0 = 0;
+ ma_uint32 zeroCountParts1 = 0;
+ ma_uint32 zeroCountParts2 = 0;
+ ma_uint32 zeroCountParts3 = 0;
+ ma_uint32 riceParamParts0 = 0;
+ ma_uint32 riceParamParts1 = 0;
+ ma_uint32 riceParamParts2 = 0;
+ ma_uint32 riceParamParts3 = 0;
__m128i coefficients128_0;
__m128i coefficients128_4;
__m128i coefficients128_8;
@@ -81736,9 +84168,9 @@ static drflac_bool32 drflac__decode_samples_with_residual__rice__sse41_64(drflac
__m128i samples128_8;
__m128i prediction128;
__m128i riceParamMask128;
- const drflac_uint32 t[2] = {0x00000000, 0xFFFFFFFF};
- DRFLAC_ASSERT(order <= 12);
- riceParamMask = (drflac_uint32)~((~0UL) << riceParam);
+ const ma_uint32 t[2] = {0x00000000, 0xFFFFFFFF};
+ MA_DR_FLAC_ASSERT(order <= 12);
+ riceParamMask = (ma_uint32)~((~0UL) << riceParam);
riceParamMask128 = _mm_set1_epi32(riceParamMask);
prediction128 = _mm_setzero_si128();
coefficients128_0 = _mm_setzero_si128();
@@ -81793,34 +84225,34 @@ static drflac_bool32 drflac__decode_samples_with_residual__rice__sse41_64(drflac
#else
switch (order)
{
- case 12: ((drflac_int32*)&coefficients128_8)[0] = coefficients[11]; ((drflac_int32*)&samples128_8)[0] = pDecodedSamples[-12];
- case 11: ((drflac_int32*)&coefficients128_8)[1] = coefficients[10]; ((drflac_int32*)&samples128_8)[1] = pDecodedSamples[-11];
- case 10: ((drflac_int32*)&coefficients128_8)[2] = coefficients[ 9]; ((drflac_int32*)&samples128_8)[2] = pDecodedSamples[-10];
- case 9: ((drflac_int32*)&coefficients128_8)[3] = coefficients[ 8]; ((drflac_int32*)&samples128_8)[3] = pDecodedSamples[- 9];
- case 8: ((drflac_int32*)&coefficients128_4)[0] = coefficients[ 7]; ((drflac_int32*)&samples128_4)[0] = pDecodedSamples[- 8];
- case 7: ((drflac_int32*)&coefficients128_4)[1] = coefficients[ 6]; ((drflac_int32*)&samples128_4)[1] = pDecodedSamples[- 7];
- case 6: ((drflac_int32*)&coefficients128_4)[2] = coefficients[ 5]; ((drflac_int32*)&samples128_4)[2] = pDecodedSamples[- 6];
- case 5: ((drflac_int32*)&coefficients128_4)[3] = coefficients[ 4]; ((drflac_int32*)&samples128_4)[3] = pDecodedSamples[- 5];
- case 4: ((drflac_int32*)&coefficients128_0)[0] = coefficients[ 3]; ((drflac_int32*)&samples128_0)[0] = pDecodedSamples[- 4];
- case 3: ((drflac_int32*)&coefficients128_0)[1] = coefficients[ 2]; ((drflac_int32*)&samples128_0)[1] = pDecodedSamples[- 3];
- case 2: ((drflac_int32*)&coefficients128_0)[2] = coefficients[ 1]; ((drflac_int32*)&samples128_0)[2] = pDecodedSamples[- 2];
- case 1: ((drflac_int32*)&coefficients128_0)[3] = coefficients[ 0]; ((drflac_int32*)&samples128_0)[3] = pDecodedSamples[- 1];
+ case 12: ((ma_int32*)&coefficients128_8)[0] = coefficients[11]; ((ma_int32*)&samples128_8)[0] = pDecodedSamples[-12];
+ case 11: ((ma_int32*)&coefficients128_8)[1] = coefficients[10]; ((ma_int32*)&samples128_8)[1] = pDecodedSamples[-11];
+ case 10: ((ma_int32*)&coefficients128_8)[2] = coefficients[ 9]; ((ma_int32*)&samples128_8)[2] = pDecodedSamples[-10];
+ case 9: ((ma_int32*)&coefficients128_8)[3] = coefficients[ 8]; ((ma_int32*)&samples128_8)[3] = pDecodedSamples[- 9];
+ case 8: ((ma_int32*)&coefficients128_4)[0] = coefficients[ 7]; ((ma_int32*)&samples128_4)[0] = pDecodedSamples[- 8];
+ case 7: ((ma_int32*)&coefficients128_4)[1] = coefficients[ 6]; ((ma_int32*)&samples128_4)[1] = pDecodedSamples[- 7];
+ case 6: ((ma_int32*)&coefficients128_4)[2] = coefficients[ 5]; ((ma_int32*)&samples128_4)[2] = pDecodedSamples[- 6];
+ case 5: ((ma_int32*)&coefficients128_4)[3] = coefficients[ 4]; ((ma_int32*)&samples128_4)[3] = pDecodedSamples[- 5];
+ case 4: ((ma_int32*)&coefficients128_0)[0] = coefficients[ 3]; ((ma_int32*)&samples128_0)[0] = pDecodedSamples[- 4];
+ case 3: ((ma_int32*)&coefficients128_0)[1] = coefficients[ 2]; ((ma_int32*)&samples128_0)[1] = pDecodedSamples[- 3];
+ case 2: ((ma_int32*)&coefficients128_0)[2] = coefficients[ 1]; ((ma_int32*)&samples128_0)[2] = pDecodedSamples[- 2];
+ case 1: ((ma_int32*)&coefficients128_0)[3] = coefficients[ 0]; ((ma_int32*)&samples128_0)[3] = pDecodedSamples[- 1];
}
#endif
while (pDecodedSamples < pDecodedSamplesEnd) {
__m128i zeroCountPart128;
__m128i riceParamPart128;
- if (!drflac__read_rice_parts_x1(bs, riceParam, &zeroCountParts0, &riceParamParts0) ||
- !drflac__read_rice_parts_x1(bs, riceParam, &zeroCountParts1, &riceParamParts1) ||
- !drflac__read_rice_parts_x1(bs, riceParam, &zeroCountParts2, &riceParamParts2) ||
- !drflac__read_rice_parts_x1(bs, riceParam, &zeroCountParts3, &riceParamParts3)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_rice_parts_x1(bs, riceParam, &zeroCountParts0, &riceParamParts0) ||
+ !ma_dr_flac__read_rice_parts_x1(bs, riceParam, &zeroCountParts1, &riceParamParts1) ||
+ !ma_dr_flac__read_rice_parts_x1(bs, riceParam, &zeroCountParts2, &riceParamParts2) ||
+ !ma_dr_flac__read_rice_parts_x1(bs, riceParam, &zeroCountParts3, &riceParamParts3)) {
+ return MA_FALSE;
}
zeroCountPart128 = _mm_set_epi32(zeroCountParts3, zeroCountParts2, zeroCountParts1, zeroCountParts0);
riceParamPart128 = _mm_set_epi32(riceParamParts3, riceParamParts2, riceParamParts1, riceParamParts0);
riceParamPart128 = _mm_and_si128(riceParamPart128, riceParamMask128);
riceParamPart128 = _mm_or_si128(riceParamPart128, _mm_slli_epi32(zeroCountPart128, riceParam));
- riceParamPart128 = _mm_xor_si128(_mm_srli_epi32(riceParamPart128, 1), _mm_add_epi32(drflac__mm_not_si128(_mm_and_si128(riceParamPart128, _mm_set1_epi32(1))), _mm_set1_epi32(1)));
+ riceParamPart128 = _mm_xor_si128(_mm_srli_epi32(riceParamPart128, 1), _mm_add_epi32(ma_dr_flac__mm_not_si128(_mm_and_si128(riceParamPart128, _mm_set1_epi32(1))), _mm_set1_epi32(1)));
for (i = 0; i < 4; i += 1) {
prediction128 = _mm_xor_si128(prediction128, prediction128);
switch (order)
@@ -81838,8 +84270,8 @@ static drflac_bool32 drflac__decode_samples_with_residual__rice__sse41_64(drflac
case 2:
case 1: prediction128 = _mm_add_epi64(prediction128, _mm_mul_epi32(_mm_shuffle_epi32(coefficients128_0, _MM_SHUFFLE(3, 3, 2, 2)), _mm_shuffle_epi32(samples128_0, _MM_SHUFFLE(3, 3, 2, 2))));
}
- prediction128 = drflac__mm_hadd_epi64(prediction128);
- prediction128 = drflac__mm_srai_epi64(prediction128, shift);
+ prediction128 = ma_dr_flac__mm_hadd_epi64(prediction128);
+ prediction128 = ma_dr_flac__mm_srai_epi64(prediction128, shift);
prediction128 = _mm_add_epi32(riceParamPart128, prediction128);
samples128_8 = _mm_alignr_epi8(samples128_4, samples128_8, 4);
samples128_4 = _mm_alignr_epi8(samples128_0, samples128_4, 4);
@@ -81851,103 +84283,103 @@ static drflac_bool32 drflac__decode_samples_with_residual__rice__sse41_64(drflac
}
i = (count & ~3);
while (i < (int)count) {
- if (!drflac__read_rice_parts_x1(bs, riceParam, &zeroCountParts0, &riceParamParts0)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_rice_parts_x1(bs, riceParam, &zeroCountParts0, &riceParamParts0)) {
+ return MA_FALSE;
}
riceParamParts0 &= riceParamMask;
riceParamParts0 |= (zeroCountParts0 << riceParam);
riceParamParts0 = (riceParamParts0 >> 1) ^ t[riceParamParts0 & 0x01];
- pDecodedSamples[0] = riceParamParts0 + drflac__calculate_prediction_64(order, shift, coefficients, pDecodedSamples);
+ pDecodedSamples[0] = riceParamParts0 + ma_dr_flac__calculate_prediction_64(order, shift, coefficients, pDecodedSamples);
i += 1;
pDecodedSamples += 1;
}
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
-static drflac_bool32 drflac__decode_samples_with_residual__rice__sse41(drflac_bs* bs, drflac_uint32 bitsPerSample, drflac_uint32 count, drflac_uint8 riceParam, drflac_uint32 lpcOrder, drflac_int32 lpcShift, drflac_uint32 lpcPrecision, const drflac_int32* coefficients, drflac_int32* pSamplesOut)
+static ma_bool32 ma_dr_flac__decode_samples_with_residual__rice__sse41(ma_dr_flac_bs* bs, ma_uint32 bitsPerSample, ma_uint32 count, ma_uint8 riceParam, ma_uint32 lpcOrder, ma_int32 lpcShift, ma_uint32 lpcPrecision, const ma_int32* coefficients, ma_int32* pSamplesOut)
{
- DRFLAC_ASSERT(bs != NULL);
- DRFLAC_ASSERT(pSamplesOut != NULL);
+ MA_DR_FLAC_ASSERT(bs != NULL);
+ MA_DR_FLAC_ASSERT(pSamplesOut != NULL);
if (lpcOrder > 0 && lpcOrder <= 12) {
- if (drflac__use_64_bit_prediction(bitsPerSample, lpcOrder, lpcPrecision)) {
- return drflac__decode_samples_with_residual__rice__sse41_64(bs, count, riceParam, lpcOrder, lpcShift, coefficients, pSamplesOut);
+ if (ma_dr_flac__use_64_bit_prediction(bitsPerSample, lpcOrder, lpcPrecision)) {
+ return ma_dr_flac__decode_samples_with_residual__rice__sse41_64(bs, count, riceParam, lpcOrder, lpcShift, coefficients, pSamplesOut);
} else {
- return drflac__decode_samples_with_residual__rice__sse41_32(bs, count, riceParam, lpcOrder, lpcShift, coefficients, pSamplesOut);
+ return ma_dr_flac__decode_samples_with_residual__rice__sse41_32(bs, count, riceParam, lpcOrder, lpcShift, coefficients, pSamplesOut);
}
} else {
- return drflac__decode_samples_with_residual__rice__scalar(bs, bitsPerSample, count, riceParam, lpcOrder, lpcShift, lpcPrecision, coefficients, pSamplesOut);
+ return ma_dr_flac__decode_samples_with_residual__rice__scalar(bs, bitsPerSample, count, riceParam, lpcOrder, lpcShift, lpcPrecision, coefficients, pSamplesOut);
}
}
#endif
-#if defined(DRFLAC_SUPPORT_NEON)
-static DRFLAC_INLINE void drflac__vst2q_s32(drflac_int32* p, int32x4x2_t x)
+#if defined(MA_DR_FLAC_SUPPORT_NEON)
+static MA_INLINE void ma_dr_flac__vst2q_s32(ma_int32* p, int32x4x2_t x)
{
vst1q_s32(p+0, x.val[0]);
vst1q_s32(p+4, x.val[1]);
}
-static DRFLAC_INLINE void drflac__vst2q_u32(drflac_uint32* p, uint32x4x2_t x)
+static MA_INLINE void ma_dr_flac__vst2q_u32(ma_uint32* p, uint32x4x2_t x)
{
vst1q_u32(p+0, x.val[0]);
vst1q_u32(p+4, x.val[1]);
}
-static DRFLAC_INLINE void drflac__vst2q_f32(float* p, float32x4x2_t x)
+static MA_INLINE void ma_dr_flac__vst2q_f32(float* p, float32x4x2_t x)
{
vst1q_f32(p+0, x.val[0]);
vst1q_f32(p+4, x.val[1]);
}
-static DRFLAC_INLINE void drflac__vst2q_s16(drflac_int16* p, int16x4x2_t x)
+static MA_INLINE void ma_dr_flac__vst2q_s16(ma_int16* p, int16x4x2_t x)
{
vst1q_s16(p, vcombine_s16(x.val[0], x.val[1]));
}
-static DRFLAC_INLINE void drflac__vst2q_u16(drflac_uint16* p, uint16x4x2_t x)
+static MA_INLINE void ma_dr_flac__vst2q_u16(ma_uint16* p, uint16x4x2_t x)
{
vst1q_u16(p, vcombine_u16(x.val[0], x.val[1]));
}
-static DRFLAC_INLINE int32x4_t drflac__vdupq_n_s32x4(drflac_int32 x3, drflac_int32 x2, drflac_int32 x1, drflac_int32 x0)
+static MA_INLINE int32x4_t ma_dr_flac__vdupq_n_s32x4(ma_int32 x3, ma_int32 x2, ma_int32 x1, ma_int32 x0)
{
- drflac_int32 x[4];
+ ma_int32 x[4];
x[3] = x3;
x[2] = x2;
x[1] = x1;
x[0] = x0;
return vld1q_s32(x);
}
-static DRFLAC_INLINE int32x4_t drflac__valignrq_s32_1(int32x4_t a, int32x4_t b)
+static MA_INLINE int32x4_t ma_dr_flac__valignrq_s32_1(int32x4_t a, int32x4_t b)
{
return vextq_s32(b, a, 1);
}
-static DRFLAC_INLINE uint32x4_t drflac__valignrq_u32_1(uint32x4_t a, uint32x4_t b)
+static MA_INLINE uint32x4_t ma_dr_flac__valignrq_u32_1(uint32x4_t a, uint32x4_t b)
{
return vextq_u32(b, a, 1);
}
-static DRFLAC_INLINE int32x2_t drflac__vhaddq_s32(int32x4_t x)
+static MA_INLINE int32x2_t ma_dr_flac__vhaddq_s32(int32x4_t x)
{
int32x2_t r = vadd_s32(vget_high_s32(x), vget_low_s32(x));
return vpadd_s32(r, r);
}
-static DRFLAC_INLINE int64x1_t drflac__vhaddq_s64(int64x2_t x)
+static MA_INLINE int64x1_t ma_dr_flac__vhaddq_s64(int64x2_t x)
{
return vadd_s64(vget_high_s64(x), vget_low_s64(x));
}
-static DRFLAC_INLINE int32x4_t drflac__vrevq_s32(int32x4_t x)
+static MA_INLINE int32x4_t ma_dr_flac__vrevq_s32(int32x4_t x)
{
return vrev64q_s32(vcombine_s32(vget_high_s32(x), vget_low_s32(x)));
}
-static DRFLAC_INLINE int32x4_t drflac__vnotq_s32(int32x4_t x)
+static MA_INLINE int32x4_t ma_dr_flac__vnotq_s32(int32x4_t x)
{
return veorq_s32(x, vdupq_n_s32(0xFFFFFFFF));
}
-static DRFLAC_INLINE uint32x4_t drflac__vnotq_u32(uint32x4_t x)
+static MA_INLINE uint32x4_t ma_dr_flac__vnotq_u32(uint32x4_t x)
{
return veorq_u32(x, vdupq_n_u32(0xFFFFFFFF));
}
-static drflac_bool32 drflac__decode_samples_with_residual__rice__neon_32(drflac_bs* bs, drflac_uint32 count, drflac_uint8 riceParam, drflac_uint32 order, drflac_int32 shift, const drflac_int32* coefficients, drflac_int32* pSamplesOut)
+static ma_bool32 ma_dr_flac__decode_samples_with_residual__rice__neon_32(ma_dr_flac_bs* bs, ma_uint32 count, ma_uint8 riceParam, ma_uint32 order, ma_int32 shift, const ma_int32* coefficients, ma_int32* pSamplesOut)
{
int i;
- drflac_uint32 riceParamMask;
- drflac_int32* pDecodedSamples = pSamplesOut;
- drflac_int32* pDecodedSamplesEnd = pSamplesOut + (count & ~3);
- drflac_uint32 zeroCountParts[4];
- drflac_uint32 riceParamParts[4];
+ ma_uint32 riceParamMask;
+ ma_int32* pDecodedSamples = pSamplesOut;
+ ma_int32* pDecodedSamplesEnd = pSamplesOut + (count & ~3);
+ ma_uint32 zeroCountParts[4];
+ ma_uint32 riceParamParts[4];
int32x4_t coefficients128_0;
int32x4_t coefficients128_4;
int32x4_t coefficients128_8;
@@ -81958,16 +84390,16 @@ static drflac_bool32 drflac__decode_samples_with_residual__rice__neon_32(drflac_
int32x4_t riceParam128;
int32x2_t shift64;
uint32x4_t one128;
- const drflac_uint32 t[2] = {0x00000000, 0xFFFFFFFF};
- riceParamMask = (drflac_uint32)~((~0UL) << riceParam);
+ const ma_uint32 t[2] = {0x00000000, 0xFFFFFFFF};
+ riceParamMask = (ma_uint32)~((~0UL) << riceParam);
riceParamMask128 = vdupq_n_u32(riceParamMask);
riceParam128 = vdupq_n_s32(riceParam);
shift64 = vdup_n_s32(-shift);
one128 = vdupq_n_u32(1);
{
int runningOrder = order;
- drflac_int32 tempC[4] = {0, 0, 0, 0};
- drflac_int32 tempS[4] = {0, 0, 0, 0};
+ ma_int32 tempC[4] = {0, 0, 0, 0};
+ ma_int32 tempS[4] = {0, 0, 0, 0};
if (runningOrder >= 4) {
coefficients128_0 = vld1q_s32(coefficients + 0);
samples128_0 = vld1q_s32(pSamplesOut - 4);
@@ -82010,58 +84442,58 @@ static drflac_bool32 drflac__decode_samples_with_residual__rice__neon_32(drflac_
samples128_8 = vld1q_s32(tempS);
runningOrder = 0;
}
- coefficients128_0 = drflac__vrevq_s32(coefficients128_0);
- coefficients128_4 = drflac__vrevq_s32(coefficients128_4);
- coefficients128_8 = drflac__vrevq_s32(coefficients128_8);
+ coefficients128_0 = ma_dr_flac__vrevq_s32(coefficients128_0);
+ coefficients128_4 = ma_dr_flac__vrevq_s32(coefficients128_4);
+ coefficients128_8 = ma_dr_flac__vrevq_s32(coefficients128_8);
}
while (pDecodedSamples < pDecodedSamplesEnd) {
int32x4_t prediction128;
int32x2_t prediction64;
uint32x4_t zeroCountPart128;
uint32x4_t riceParamPart128;
- if (!drflac__read_rice_parts_x1(bs, riceParam, &zeroCountParts[0], &riceParamParts[0]) ||
- !drflac__read_rice_parts_x1(bs, riceParam, &zeroCountParts[1], &riceParamParts[1]) ||
- !drflac__read_rice_parts_x1(bs, riceParam, &zeroCountParts[2], &riceParamParts[2]) ||
- !drflac__read_rice_parts_x1(bs, riceParam, &zeroCountParts[3], &riceParamParts[3])) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_rice_parts_x1(bs, riceParam, &zeroCountParts[0], &riceParamParts[0]) ||
+ !ma_dr_flac__read_rice_parts_x1(bs, riceParam, &zeroCountParts[1], &riceParamParts[1]) ||
+ !ma_dr_flac__read_rice_parts_x1(bs, riceParam, &zeroCountParts[2], &riceParamParts[2]) ||
+ !ma_dr_flac__read_rice_parts_x1(bs, riceParam, &zeroCountParts[3], &riceParamParts[3])) {
+ return MA_FALSE;
}
zeroCountPart128 = vld1q_u32(zeroCountParts);
riceParamPart128 = vld1q_u32(riceParamParts);
riceParamPart128 = vandq_u32(riceParamPart128, riceParamMask128);
riceParamPart128 = vorrq_u32(riceParamPart128, vshlq_u32(zeroCountPart128, riceParam128));
- riceParamPart128 = veorq_u32(vshrq_n_u32(riceParamPart128, 1), vaddq_u32(drflac__vnotq_u32(vandq_u32(riceParamPart128, one128)), one128));
+ riceParamPart128 = veorq_u32(vshrq_n_u32(riceParamPart128, 1), vaddq_u32(ma_dr_flac__vnotq_u32(vandq_u32(riceParamPart128, one128)), one128));
if (order <= 4) {
for (i = 0; i < 4; i += 1) {
prediction128 = vmulq_s32(coefficients128_0, samples128_0);
- prediction64 = drflac__vhaddq_s32(prediction128);
+ prediction64 = ma_dr_flac__vhaddq_s32(prediction128);
prediction64 = vshl_s32(prediction64, shift64);
prediction64 = vadd_s32(prediction64, vget_low_s32(vreinterpretq_s32_u32(riceParamPart128)));
- samples128_0 = drflac__valignrq_s32_1(vcombine_s32(prediction64, vdup_n_s32(0)), samples128_0);
- riceParamPart128 = drflac__valignrq_u32_1(vdupq_n_u32(0), riceParamPart128);
+ samples128_0 = ma_dr_flac__valignrq_s32_1(vcombine_s32(prediction64, vdup_n_s32(0)), samples128_0);
+ riceParamPart128 = ma_dr_flac__valignrq_u32_1(vdupq_n_u32(0), riceParamPart128);
}
} else if (order <= 8) {
for (i = 0; i < 4; i += 1) {
prediction128 = vmulq_s32(coefficients128_4, samples128_4);
prediction128 = vmlaq_s32(prediction128, coefficients128_0, samples128_0);
- prediction64 = drflac__vhaddq_s32(prediction128);
+ prediction64 = ma_dr_flac__vhaddq_s32(prediction128);
prediction64 = vshl_s32(prediction64, shift64);
prediction64 = vadd_s32(prediction64, vget_low_s32(vreinterpretq_s32_u32(riceParamPart128)));
- samples128_4 = drflac__valignrq_s32_1(samples128_0, samples128_4);
- samples128_0 = drflac__valignrq_s32_1(vcombine_s32(prediction64, vdup_n_s32(0)), samples128_0);
- riceParamPart128 = drflac__valignrq_u32_1(vdupq_n_u32(0), riceParamPart128);
+ samples128_4 = ma_dr_flac__valignrq_s32_1(samples128_0, samples128_4);
+ samples128_0 = ma_dr_flac__valignrq_s32_1(vcombine_s32(prediction64, vdup_n_s32(0)), samples128_0);
+ riceParamPart128 = ma_dr_flac__valignrq_u32_1(vdupq_n_u32(0), riceParamPart128);
}
} else {
for (i = 0; i < 4; i += 1) {
prediction128 = vmulq_s32(coefficients128_8, samples128_8);
prediction128 = vmlaq_s32(prediction128, coefficients128_4, samples128_4);
prediction128 = vmlaq_s32(prediction128, coefficients128_0, samples128_0);
- prediction64 = drflac__vhaddq_s32(prediction128);
+ prediction64 = ma_dr_flac__vhaddq_s32(prediction128);
prediction64 = vshl_s32(prediction64, shift64);
prediction64 = vadd_s32(prediction64, vget_low_s32(vreinterpretq_s32_u32(riceParamPart128)));
- samples128_8 = drflac__valignrq_s32_1(samples128_4, samples128_8);
- samples128_4 = drflac__valignrq_s32_1(samples128_0, samples128_4);
- samples128_0 = drflac__valignrq_s32_1(vcombine_s32(prediction64, vdup_n_s32(0)), samples128_0);
- riceParamPart128 = drflac__valignrq_u32_1(vdupq_n_u32(0), riceParamPart128);
+ samples128_8 = ma_dr_flac__valignrq_s32_1(samples128_4, samples128_8);
+ samples128_4 = ma_dr_flac__valignrq_s32_1(samples128_0, samples128_4);
+ samples128_0 = ma_dr_flac__valignrq_s32_1(vcombine_s32(prediction64, vdup_n_s32(0)), samples128_0);
+ riceParamPart128 = ma_dr_flac__valignrq_u32_1(vdupq_n_u32(0), riceParamPart128);
}
}
vst1q_s32(pDecodedSamples, samples128_0);
@@ -82069,26 +84501,26 @@ static drflac_bool32 drflac__decode_samples_with_residual__rice__neon_32(drflac_
}
i = (count & ~3);
while (i < (int)count) {
- if (!drflac__read_rice_parts_x1(bs, riceParam, &zeroCountParts[0], &riceParamParts[0])) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_rice_parts_x1(bs, riceParam, &zeroCountParts[0], &riceParamParts[0])) {
+ return MA_FALSE;
}
riceParamParts[0] &= riceParamMask;
riceParamParts[0] |= (zeroCountParts[0] << riceParam);
riceParamParts[0] = (riceParamParts[0] >> 1) ^ t[riceParamParts[0] & 0x01];
- pDecodedSamples[0] = riceParamParts[0] + drflac__calculate_prediction_32(order, shift, coefficients, pDecodedSamples);
+ pDecodedSamples[0] = riceParamParts[0] + ma_dr_flac__calculate_prediction_32(order, shift, coefficients, pDecodedSamples);
i += 1;
pDecodedSamples += 1;
}
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
-static drflac_bool32 drflac__decode_samples_with_residual__rice__neon_64(drflac_bs* bs, drflac_uint32 count, drflac_uint8 riceParam, drflac_uint32 order, drflac_int32 shift, const drflac_int32* coefficients, drflac_int32* pSamplesOut)
+static ma_bool32 ma_dr_flac__decode_samples_with_residual__rice__neon_64(ma_dr_flac_bs* bs, ma_uint32 count, ma_uint8 riceParam, ma_uint32 order, ma_int32 shift, const ma_int32* coefficients, ma_int32* pSamplesOut)
{
int i;
- drflac_uint32 riceParamMask;
- drflac_int32* pDecodedSamples = pSamplesOut;
- drflac_int32* pDecodedSamplesEnd = pSamplesOut + (count & ~3);
- drflac_uint32 zeroCountParts[4];
- drflac_uint32 riceParamParts[4];
+ ma_uint32 riceParamMask;
+ ma_int32* pDecodedSamples = pSamplesOut;
+ ma_int32* pDecodedSamplesEnd = pSamplesOut + (count & ~3);
+ ma_uint32 zeroCountParts[4];
+ ma_uint32 riceParamParts[4];
int32x4_t coefficients128_0;
int32x4_t coefficients128_4;
int32x4_t coefficients128_8;
@@ -82102,16 +84534,16 @@ static drflac_bool32 drflac__decode_samples_with_residual__rice__neon_64(drflac_
int64x2_t prediction128 = { 0 };
uint32x4_t zeroCountPart128;
uint32x4_t riceParamPart128;
- const drflac_uint32 t[2] = {0x00000000, 0xFFFFFFFF};
- riceParamMask = (drflac_uint32)~((~0UL) << riceParam);
+ const ma_uint32 t[2] = {0x00000000, 0xFFFFFFFF};
+ riceParamMask = (ma_uint32)~((~0UL) << riceParam);
riceParamMask128 = vdupq_n_u32(riceParamMask);
riceParam128 = vdupq_n_s32(riceParam);
shift64 = vdup_n_s64(-shift);
one128 = vdupq_n_u32(1);
{
int runningOrder = order;
- drflac_int32 tempC[4] = {0, 0, 0, 0};
- drflac_int32 tempS[4] = {0, 0, 0, 0};
+ ma_int32 tempC[4] = {0, 0, 0, 0};
+ ma_int32 tempS[4] = {0, 0, 0, 0};
if (runningOrder >= 4) {
coefficients128_0 = vld1q_s32(coefficients + 0);
samples128_0 = vld1q_s32(pSamplesOut - 4);
@@ -82154,22 +84586,22 @@ static drflac_bool32 drflac__decode_samples_with_residual__rice__neon_64(drflac_
samples128_8 = vld1q_s32(tempS);
runningOrder = 0;
}
- coefficients128_0 = drflac__vrevq_s32(coefficients128_0);
- coefficients128_4 = drflac__vrevq_s32(coefficients128_4);
- coefficients128_8 = drflac__vrevq_s32(coefficients128_8);
+ coefficients128_0 = ma_dr_flac__vrevq_s32(coefficients128_0);
+ coefficients128_4 = ma_dr_flac__vrevq_s32(coefficients128_4);
+ coefficients128_8 = ma_dr_flac__vrevq_s32(coefficients128_8);
}
while (pDecodedSamples < pDecodedSamplesEnd) {
- if (!drflac__read_rice_parts_x1(bs, riceParam, &zeroCountParts[0], &riceParamParts[0]) ||
- !drflac__read_rice_parts_x1(bs, riceParam, &zeroCountParts[1], &riceParamParts[1]) ||
- !drflac__read_rice_parts_x1(bs, riceParam, &zeroCountParts[2], &riceParamParts[2]) ||
- !drflac__read_rice_parts_x1(bs, riceParam, &zeroCountParts[3], &riceParamParts[3])) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_rice_parts_x1(bs, riceParam, &zeroCountParts[0], &riceParamParts[0]) ||
+ !ma_dr_flac__read_rice_parts_x1(bs, riceParam, &zeroCountParts[1], &riceParamParts[1]) ||
+ !ma_dr_flac__read_rice_parts_x1(bs, riceParam, &zeroCountParts[2], &riceParamParts[2]) ||
+ !ma_dr_flac__read_rice_parts_x1(bs, riceParam, &zeroCountParts[3], &riceParamParts[3])) {
+ return MA_FALSE;
}
zeroCountPart128 = vld1q_u32(zeroCountParts);
riceParamPart128 = vld1q_u32(riceParamParts);
riceParamPart128 = vandq_u32(riceParamPart128, riceParamMask128);
riceParamPart128 = vorrq_u32(riceParamPart128, vshlq_u32(zeroCountPart128, riceParam128));
- riceParamPart128 = veorq_u32(vshrq_n_u32(riceParamPart128, 1), vaddq_u32(drflac__vnotq_u32(vandq_u32(riceParamPart128, one128)), one128));
+ riceParamPart128 = veorq_u32(vshrq_n_u32(riceParamPart128, 1), vaddq_u32(ma_dr_flac__vnotq_u32(vandq_u32(riceParamPart128, one128)), one128));
for (i = 0; i < 4; i += 1) {
int64x1_t prediction64;
prediction128 = veorq_s64(prediction128, prediction128);
@@ -82188,156 +84620,156 @@ static drflac_bool32 drflac__decode_samples_with_residual__rice__neon_64(drflac_
case 2:
case 1: prediction128 = vaddq_s64(prediction128, vmull_s32(vget_high_s32(coefficients128_0), vget_high_s32(samples128_0)));
}
- prediction64 = drflac__vhaddq_s64(prediction128);
+ prediction64 = ma_dr_flac__vhaddq_s64(prediction128);
prediction64 = vshl_s64(prediction64, shift64);
prediction64 = vadd_s64(prediction64, vdup_n_s64(vgetq_lane_u32(riceParamPart128, 0)));
- samples128_8 = drflac__valignrq_s32_1(samples128_4, samples128_8);
- samples128_4 = drflac__valignrq_s32_1(samples128_0, samples128_4);
- samples128_0 = drflac__valignrq_s32_1(vcombine_s32(vreinterpret_s32_s64(prediction64), vdup_n_s32(0)), samples128_0);
- riceParamPart128 = drflac__valignrq_u32_1(vdupq_n_u32(0), riceParamPart128);
+ samples128_8 = ma_dr_flac__valignrq_s32_1(samples128_4, samples128_8);
+ samples128_4 = ma_dr_flac__valignrq_s32_1(samples128_0, samples128_4);
+ samples128_0 = ma_dr_flac__valignrq_s32_1(vcombine_s32(vreinterpret_s32_s64(prediction64), vdup_n_s32(0)), samples128_0);
+ riceParamPart128 = ma_dr_flac__valignrq_u32_1(vdupq_n_u32(0), riceParamPart128);
}
vst1q_s32(pDecodedSamples, samples128_0);
pDecodedSamples += 4;
}
i = (count & ~3);
while (i < (int)count) {
- if (!drflac__read_rice_parts_x1(bs, riceParam, &zeroCountParts[0], &riceParamParts[0])) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_rice_parts_x1(bs, riceParam, &zeroCountParts[0], &riceParamParts[0])) {
+ return MA_FALSE;
}
riceParamParts[0] &= riceParamMask;
riceParamParts[0] |= (zeroCountParts[0] << riceParam);
riceParamParts[0] = (riceParamParts[0] >> 1) ^ t[riceParamParts[0] & 0x01];
- pDecodedSamples[0] = riceParamParts[0] + drflac__calculate_prediction_64(order, shift, coefficients, pDecodedSamples);
+ pDecodedSamples[0] = riceParamParts[0] + ma_dr_flac__calculate_prediction_64(order, shift, coefficients, pDecodedSamples);
i += 1;
pDecodedSamples += 1;
}
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
-static drflac_bool32 drflac__decode_samples_with_residual__rice__neon(drflac_bs* bs, drflac_uint32 bitsPerSample, drflac_uint32 count, drflac_uint8 riceParam, drflac_uint32 lpcOrder, drflac_int32 lpcShift, drflac_uint32 lpcPrecision, const drflac_int32* coefficients, drflac_int32* pSamplesOut)
+static ma_bool32 ma_dr_flac__decode_samples_with_residual__rice__neon(ma_dr_flac_bs* bs, ma_uint32 bitsPerSample, ma_uint32 count, ma_uint8 riceParam, ma_uint32 lpcOrder, ma_int32 lpcShift, ma_uint32 lpcPrecision, const ma_int32* coefficients, ma_int32* pSamplesOut)
{
- DRFLAC_ASSERT(bs != NULL);
- DRFLAC_ASSERT(pSamplesOut != NULL);
+ MA_DR_FLAC_ASSERT(bs != NULL);
+ MA_DR_FLAC_ASSERT(pSamplesOut != NULL);
if (lpcOrder > 0 && lpcOrder <= 12) {
- if (drflac__use_64_bit_prediction(bitsPerSample, lpcOrder, lpcPrecision)) {
- return drflac__decode_samples_with_residual__rice__neon_64(bs, count, riceParam, lpcOrder, lpcShift, coefficients, pSamplesOut);
+ if (ma_dr_flac__use_64_bit_prediction(bitsPerSample, lpcOrder, lpcPrecision)) {
+ return ma_dr_flac__decode_samples_with_residual__rice__neon_64(bs, count, riceParam, lpcOrder, lpcShift, coefficients, pSamplesOut);
} else {
- return drflac__decode_samples_with_residual__rice__neon_32(bs, count, riceParam, lpcOrder, lpcShift, coefficients, pSamplesOut);
+ return ma_dr_flac__decode_samples_with_residual__rice__neon_32(bs, count, riceParam, lpcOrder, lpcShift, coefficients, pSamplesOut);
}
} else {
- return drflac__decode_samples_with_residual__rice__scalar(bs, bitsPerSample, count, riceParam, lpcOrder, lpcShift, lpcPrecision, coefficients, pSamplesOut);
+ return ma_dr_flac__decode_samples_with_residual__rice__scalar(bs, bitsPerSample, count, riceParam, lpcOrder, lpcShift, lpcPrecision, coefficients, pSamplesOut);
}
}
#endif
-static drflac_bool32 drflac__decode_samples_with_residual__rice(drflac_bs* bs, drflac_uint32 bitsPerSample, drflac_uint32 count, drflac_uint8 riceParam, drflac_uint32 lpcOrder, drflac_int32 lpcShift, drflac_uint32 lpcPrecision, const drflac_int32* coefficients, drflac_int32* pSamplesOut)
+static ma_bool32 ma_dr_flac__decode_samples_with_residual__rice(ma_dr_flac_bs* bs, ma_uint32 bitsPerSample, ma_uint32 count, ma_uint8 riceParam, ma_uint32 lpcOrder, ma_int32 lpcShift, ma_uint32 lpcPrecision, const ma_int32* coefficients, ma_int32* pSamplesOut)
{
-#if defined(DRFLAC_SUPPORT_SSE41)
- if (drflac__gIsSSE41Supported) {
- return drflac__decode_samples_with_residual__rice__sse41(bs, bitsPerSample, count, riceParam, lpcOrder, lpcShift, lpcPrecision, coefficients, pSamplesOut);
+#if defined(MA_DR_FLAC_SUPPORT_SSE41)
+ if (ma_dr_flac__gIsSSE41Supported) {
+ return ma_dr_flac__decode_samples_with_residual__rice__sse41(bs, bitsPerSample, count, riceParam, lpcOrder, lpcShift, lpcPrecision, coefficients, pSamplesOut);
} else
-#elif defined(DRFLAC_SUPPORT_NEON)
- if (drflac__gIsNEONSupported) {
- return drflac__decode_samples_with_residual__rice__neon(bs, bitsPerSample, count, riceParam, lpcOrder, lpcShift, lpcPrecision, coefficients, pSamplesOut);
+#elif defined(MA_DR_FLAC_SUPPORT_NEON)
+ if (ma_dr_flac__gIsNEONSupported) {
+ return ma_dr_flac__decode_samples_with_residual__rice__neon(bs, bitsPerSample, count, riceParam, lpcOrder, lpcShift, lpcPrecision, coefficients, pSamplesOut);
} else
#endif
{
#if 0
- return drflac__decode_samples_with_residual__rice__reference(bs, bitsPerSample, count, riceParam, lpcOrder, lpcShift, lpcPrecision, coefficients, pSamplesOut);
+ return ma_dr_flac__decode_samples_with_residual__rice__reference(bs, bitsPerSample, count, riceParam, lpcOrder, lpcShift, lpcPrecision, coefficients, pSamplesOut);
#else
- return drflac__decode_samples_with_residual__rice__scalar(bs, bitsPerSample, count, riceParam, lpcOrder, lpcShift, lpcPrecision, coefficients, pSamplesOut);
+ return ma_dr_flac__decode_samples_with_residual__rice__scalar(bs, bitsPerSample, count, riceParam, lpcOrder, lpcShift, lpcPrecision, coefficients, pSamplesOut);
#endif
}
}
-static drflac_bool32 drflac__read_and_seek_residual__rice(drflac_bs* bs, drflac_uint32 count, drflac_uint8 riceParam)
+static ma_bool32 ma_dr_flac__read_and_seek_residual__rice(ma_dr_flac_bs* bs, ma_uint32 count, ma_uint8 riceParam)
{
- drflac_uint32 i;
- DRFLAC_ASSERT(bs != NULL);
+ ma_uint32 i;
+ MA_DR_FLAC_ASSERT(bs != NULL);
for (i = 0; i < count; ++i) {
- if (!drflac__seek_rice_parts(bs, riceParam)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__seek_rice_parts(bs, riceParam)) {
+ return MA_FALSE;
}
}
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
#if defined(__clang__)
__attribute__((no_sanitize("signed-integer-overflow")))
#endif
-static drflac_bool32 drflac__decode_samples_with_residual__unencoded(drflac_bs* bs, drflac_uint32 bitsPerSample, drflac_uint32 count, drflac_uint8 unencodedBitsPerSample, drflac_uint32 lpcOrder, drflac_int32 lpcShift, drflac_uint32 lpcPrecision, const drflac_int32* coefficients, drflac_int32* pSamplesOut)
+static ma_bool32 ma_dr_flac__decode_samples_with_residual__unencoded(ma_dr_flac_bs* bs, ma_uint32 bitsPerSample, ma_uint32 count, ma_uint8 unencodedBitsPerSample, ma_uint32 lpcOrder, ma_int32 lpcShift, ma_uint32 lpcPrecision, const ma_int32* coefficients, ma_int32* pSamplesOut)
{
- drflac_uint32 i;
- DRFLAC_ASSERT(bs != NULL);
- DRFLAC_ASSERT(unencodedBitsPerSample <= 31);
- DRFLAC_ASSERT(pSamplesOut != NULL);
+ ma_uint32 i;
+ MA_DR_FLAC_ASSERT(bs != NULL);
+ MA_DR_FLAC_ASSERT(unencodedBitsPerSample <= 31);
+ MA_DR_FLAC_ASSERT(pSamplesOut != NULL);
for (i = 0; i < count; ++i) {
if (unencodedBitsPerSample > 0) {
- if (!drflac__read_int32(bs, unencodedBitsPerSample, pSamplesOut + i)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_int32(bs, unencodedBitsPerSample, pSamplesOut + i)) {
+ return MA_FALSE;
}
} else {
pSamplesOut[i] = 0;
}
- if (drflac__use_64_bit_prediction(bitsPerSample, lpcOrder, lpcPrecision)) {
- pSamplesOut[i] += drflac__calculate_prediction_64(lpcOrder, lpcShift, coefficients, pSamplesOut + i);
+ if (ma_dr_flac__use_64_bit_prediction(bitsPerSample, lpcOrder, lpcPrecision)) {
+ pSamplesOut[i] += ma_dr_flac__calculate_prediction_64(lpcOrder, lpcShift, coefficients, pSamplesOut + i);
} else {
- pSamplesOut[i] += drflac__calculate_prediction_32(lpcOrder, lpcShift, coefficients, pSamplesOut + i);
+ pSamplesOut[i] += ma_dr_flac__calculate_prediction_32(lpcOrder, lpcShift, coefficients, pSamplesOut + i);
}
}
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
-static drflac_bool32 drflac__decode_samples_with_residual(drflac_bs* bs, drflac_uint32 bitsPerSample, drflac_uint32 blockSize, drflac_uint32 lpcOrder, drflac_int32 lpcShift, drflac_uint32 lpcPrecision, const drflac_int32* coefficients, drflac_int32* pDecodedSamples)
+static ma_bool32 ma_dr_flac__decode_samples_with_residual(ma_dr_flac_bs* bs, ma_uint32 bitsPerSample, ma_uint32 blockSize, ma_uint32 lpcOrder, ma_int32 lpcShift, ma_uint32 lpcPrecision, const ma_int32* coefficients, ma_int32* pDecodedSamples)
{
- drflac_uint8 residualMethod;
- drflac_uint8 partitionOrder;
- drflac_uint32 samplesInPartition;
- drflac_uint32 partitionsRemaining;
- DRFLAC_ASSERT(bs != NULL);
- DRFLAC_ASSERT(blockSize != 0);
- DRFLAC_ASSERT(pDecodedSamples != NULL);
- if (!drflac__read_uint8(bs, 2, &residualMethod)) {
- return DRFLAC_FALSE;
+ ma_uint8 residualMethod;
+ ma_uint8 partitionOrder;
+ ma_uint32 samplesInPartition;
+ ma_uint32 partitionsRemaining;
+ MA_DR_FLAC_ASSERT(bs != NULL);
+ MA_DR_FLAC_ASSERT(blockSize != 0);
+ MA_DR_FLAC_ASSERT(pDecodedSamples != NULL);
+ if (!ma_dr_flac__read_uint8(bs, 2, &residualMethod)) {
+ return MA_FALSE;
}
- if (residualMethod != DRFLAC_RESIDUAL_CODING_METHOD_PARTITIONED_RICE && residualMethod != DRFLAC_RESIDUAL_CODING_METHOD_PARTITIONED_RICE2) {
- return DRFLAC_FALSE;
+ if (residualMethod != MA_DR_FLAC_RESIDUAL_CODING_METHOD_PARTITIONED_RICE && residualMethod != MA_DR_FLAC_RESIDUAL_CODING_METHOD_PARTITIONED_RICE2) {
+ return MA_FALSE;
}
pDecodedSamples += lpcOrder;
- if (!drflac__read_uint8(bs, 4, &partitionOrder)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_uint8(bs, 4, &partitionOrder)) {
+ return MA_FALSE;
}
if (partitionOrder > 8) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
if ((blockSize / (1 << partitionOrder)) < lpcOrder) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
samplesInPartition = (blockSize / (1 << partitionOrder)) - lpcOrder;
partitionsRemaining = (1 << partitionOrder);
for (;;) {
- drflac_uint8 riceParam = 0;
- if (residualMethod == DRFLAC_RESIDUAL_CODING_METHOD_PARTITIONED_RICE) {
- if (!drflac__read_uint8(bs, 4, &riceParam)) {
- return DRFLAC_FALSE;
+ ma_uint8 riceParam = 0;
+ if (residualMethod == MA_DR_FLAC_RESIDUAL_CODING_METHOD_PARTITIONED_RICE) {
+ if (!ma_dr_flac__read_uint8(bs, 4, &riceParam)) {
+ return MA_FALSE;
}
if (riceParam == 15) {
riceParam = 0xFF;
}
- } else if (residualMethod == DRFLAC_RESIDUAL_CODING_METHOD_PARTITIONED_RICE2) {
- if (!drflac__read_uint8(bs, 5, &riceParam)) {
- return DRFLAC_FALSE;
+ } else if (residualMethod == MA_DR_FLAC_RESIDUAL_CODING_METHOD_PARTITIONED_RICE2) {
+ if (!ma_dr_flac__read_uint8(bs, 5, &riceParam)) {
+ return MA_FALSE;
}
if (riceParam == 31) {
riceParam = 0xFF;
}
}
if (riceParam != 0xFF) {
- if (!drflac__decode_samples_with_residual__rice(bs, bitsPerSample, samplesInPartition, riceParam, lpcOrder, lpcShift, lpcPrecision, coefficients, pDecodedSamples)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__decode_samples_with_residual__rice(bs, bitsPerSample, samplesInPartition, riceParam, lpcOrder, lpcShift, lpcPrecision, coefficients, pDecodedSamples)) {
+ return MA_FALSE;
}
} else {
- drflac_uint8 unencodedBitsPerSample = 0;
- if (!drflac__read_uint8(bs, 5, &unencodedBitsPerSample)) {
- return DRFLAC_FALSE;
+ ma_uint8 unencodedBitsPerSample = 0;
+ if (!ma_dr_flac__read_uint8(bs, 5, &unencodedBitsPerSample)) {
+ return MA_FALSE;
}
- if (!drflac__decode_samples_with_residual__unencoded(bs, bitsPerSample, samplesInPartition, unencodedBitsPerSample, lpcOrder, lpcShift, lpcPrecision, coefficients, pDecodedSamples)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__decode_samples_with_residual__unencoded(bs, bitsPerSample, samplesInPartition, unencodedBitsPerSample, lpcOrder, lpcShift, lpcPrecision, coefficients, pDecodedSamples)) {
+ return MA_FALSE;
}
}
pDecodedSamples += samplesInPartition;
@@ -82349,62 +84781,62 @@ static drflac_bool32 drflac__decode_samples_with_residual(drflac_bs* bs, drflac_
samplesInPartition = blockSize / (1 << partitionOrder);
}
}
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
-static drflac_bool32 drflac__read_and_seek_residual(drflac_bs* bs, drflac_uint32 blockSize, drflac_uint32 order)
+static ma_bool32 ma_dr_flac__read_and_seek_residual(ma_dr_flac_bs* bs, ma_uint32 blockSize, ma_uint32 order)
{
- drflac_uint8 residualMethod;
- drflac_uint8 partitionOrder;
- drflac_uint32 samplesInPartition;
- drflac_uint32 partitionsRemaining;
- DRFLAC_ASSERT(bs != NULL);
- DRFLAC_ASSERT(blockSize != 0);
- if (!drflac__read_uint8(bs, 2, &residualMethod)) {
- return DRFLAC_FALSE;
+ ma_uint8 residualMethod;
+ ma_uint8 partitionOrder;
+ ma_uint32 samplesInPartition;
+ ma_uint32 partitionsRemaining;
+ MA_DR_FLAC_ASSERT(bs != NULL);
+ MA_DR_FLAC_ASSERT(blockSize != 0);
+ if (!ma_dr_flac__read_uint8(bs, 2, &residualMethod)) {
+ return MA_FALSE;
}
- if (residualMethod != DRFLAC_RESIDUAL_CODING_METHOD_PARTITIONED_RICE && residualMethod != DRFLAC_RESIDUAL_CODING_METHOD_PARTITIONED_RICE2) {
- return DRFLAC_FALSE;
+ if (residualMethod != MA_DR_FLAC_RESIDUAL_CODING_METHOD_PARTITIONED_RICE && residualMethod != MA_DR_FLAC_RESIDUAL_CODING_METHOD_PARTITIONED_RICE2) {
+ return MA_FALSE;
}
- if (!drflac__read_uint8(bs, 4, &partitionOrder)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_uint8(bs, 4, &partitionOrder)) {
+ return MA_FALSE;
}
if (partitionOrder > 8) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
if ((blockSize / (1 << partitionOrder)) <= order) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
samplesInPartition = (blockSize / (1 << partitionOrder)) - order;
partitionsRemaining = (1 << partitionOrder);
for (;;)
{
- drflac_uint8 riceParam = 0;
- if (residualMethod == DRFLAC_RESIDUAL_CODING_METHOD_PARTITIONED_RICE) {
- if (!drflac__read_uint8(bs, 4, &riceParam)) {
- return DRFLAC_FALSE;
+ ma_uint8 riceParam = 0;
+ if (residualMethod == MA_DR_FLAC_RESIDUAL_CODING_METHOD_PARTITIONED_RICE) {
+ if (!ma_dr_flac__read_uint8(bs, 4, &riceParam)) {
+ return MA_FALSE;
}
if (riceParam == 15) {
riceParam = 0xFF;
}
- } else if (residualMethod == DRFLAC_RESIDUAL_CODING_METHOD_PARTITIONED_RICE2) {
- if (!drflac__read_uint8(bs, 5, &riceParam)) {
- return DRFLAC_FALSE;
+ } else if (residualMethod == MA_DR_FLAC_RESIDUAL_CODING_METHOD_PARTITIONED_RICE2) {
+ if (!ma_dr_flac__read_uint8(bs, 5, &riceParam)) {
+ return MA_FALSE;
}
if (riceParam == 31) {
riceParam = 0xFF;
}
}
if (riceParam != 0xFF) {
- if (!drflac__read_and_seek_residual__rice(bs, samplesInPartition, riceParam)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_and_seek_residual__rice(bs, samplesInPartition, riceParam)) {
+ return MA_FALSE;
}
} else {
- drflac_uint8 unencodedBitsPerSample = 0;
- if (!drflac__read_uint8(bs, 5, &unencodedBitsPerSample)) {
- return DRFLAC_FALSE;
+ ma_uint8 unencodedBitsPerSample = 0;
+ if (!ma_dr_flac__read_uint8(bs, 5, &unencodedBitsPerSample)) {
+ return MA_FALSE;
}
- if (!drflac__seek_bits(bs, unencodedBitsPerSample * samplesInPartition)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__seek_bits(bs, unencodedBitsPerSample * samplesInPartition)) {
+ return MA_FALSE;
}
}
if (partitionsRemaining == 1) {
@@ -82413,36 +84845,36 @@ static drflac_bool32 drflac__read_and_seek_residual(drflac_bs* bs, drflac_uint32
partitionsRemaining -= 1;
samplesInPartition = blockSize / (1 << partitionOrder);
}
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
-static drflac_bool32 drflac__decode_samples__constant(drflac_bs* bs, drflac_uint32 blockSize, drflac_uint32 subframeBitsPerSample, drflac_int32* pDecodedSamples)
+static ma_bool32 ma_dr_flac__decode_samples__constant(ma_dr_flac_bs* bs, ma_uint32 blockSize, ma_uint32 subframeBitsPerSample, ma_int32* pDecodedSamples)
{
- drflac_uint32 i;
- drflac_int32 sample;
- if (!drflac__read_int32(bs, subframeBitsPerSample, &sample)) {
- return DRFLAC_FALSE;
+ ma_uint32 i;
+ ma_int32 sample;
+ if (!ma_dr_flac__read_int32(bs, subframeBitsPerSample, &sample)) {
+ return MA_FALSE;
}
for (i = 0; i < blockSize; ++i) {
pDecodedSamples[i] = sample;
}
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
-static drflac_bool32 drflac__decode_samples__verbatim(drflac_bs* bs, drflac_uint32 blockSize, drflac_uint32 subframeBitsPerSample, drflac_int32* pDecodedSamples)
+static ma_bool32 ma_dr_flac__decode_samples__verbatim(ma_dr_flac_bs* bs, ma_uint32 blockSize, ma_uint32 subframeBitsPerSample, ma_int32* pDecodedSamples)
{
- drflac_uint32 i;
+ ma_uint32 i;
for (i = 0; i < blockSize; ++i) {
- drflac_int32 sample;
- if (!drflac__read_int32(bs, subframeBitsPerSample, &sample)) {
- return DRFLAC_FALSE;
+ ma_int32 sample;
+ if (!ma_dr_flac__read_int32(bs, subframeBitsPerSample, &sample)) {
+ return MA_FALSE;
}
pDecodedSamples[i] = sample;
}
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
-static drflac_bool32 drflac__decode_samples__fixed(drflac_bs* bs, drflac_uint32 blockSize, drflac_uint32 subframeBitsPerSample, drflac_uint8 lpcOrder, drflac_int32* pDecodedSamples)
+static ma_bool32 ma_dr_flac__decode_samples__fixed(ma_dr_flac_bs* bs, ma_uint32 blockSize, ma_uint32 subframeBitsPerSample, ma_uint8 lpcOrder, ma_int32* pDecodedSamples)
{
- drflac_uint32 i;
- static drflac_int32 lpcCoefficientsTable[5][4] = {
+ ma_uint32 i;
+ static ma_int32 lpcCoefficientsTable[5][4] = {
{0, 0, 0, 0},
{1, 0, 0, 0},
{2, -1, 0, 0},
@@ -82450,122 +84882,122 @@ static drflac_bool32 drflac__decode_samples__fixed(drflac_bs* bs, drflac_uint32
{4, -6, 4, -1}
};
for (i = 0; i < lpcOrder; ++i) {
- drflac_int32 sample;
- if (!drflac__read_int32(bs, subframeBitsPerSample, &sample)) {
- return DRFLAC_FALSE;
+ ma_int32 sample;
+ if (!ma_dr_flac__read_int32(bs, subframeBitsPerSample, &sample)) {
+ return MA_FALSE;
}
pDecodedSamples[i] = sample;
}
- if (!drflac__decode_samples_with_residual(bs, subframeBitsPerSample, blockSize, lpcOrder, 0, 4, lpcCoefficientsTable[lpcOrder], pDecodedSamples)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__decode_samples_with_residual(bs, subframeBitsPerSample, blockSize, lpcOrder, 0, 4, lpcCoefficientsTable[lpcOrder], pDecodedSamples)) {
+ return MA_FALSE;
}
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
-static drflac_bool32 drflac__decode_samples__lpc(drflac_bs* bs, drflac_uint32 blockSize, drflac_uint32 bitsPerSample, drflac_uint8 lpcOrder, drflac_int32* pDecodedSamples)
+static ma_bool32 ma_dr_flac__decode_samples__lpc(ma_dr_flac_bs* bs, ma_uint32 blockSize, ma_uint32 bitsPerSample, ma_uint8 lpcOrder, ma_int32* pDecodedSamples)
{
- drflac_uint8 i;
- drflac_uint8 lpcPrecision;
- drflac_int8 lpcShift;
- drflac_int32 coefficients[32];
+ ma_uint8 i;
+ ma_uint8 lpcPrecision;
+ ma_int8 lpcShift;
+ ma_int32 coefficients[32];
for (i = 0; i < lpcOrder; ++i) {
- drflac_int32 sample;
- if (!drflac__read_int32(bs, bitsPerSample, &sample)) {
- return DRFLAC_FALSE;
+ ma_int32 sample;
+ if (!ma_dr_flac__read_int32(bs, bitsPerSample, &sample)) {
+ return MA_FALSE;
}
pDecodedSamples[i] = sample;
}
- if (!drflac__read_uint8(bs, 4, &lpcPrecision)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_uint8(bs, 4, &lpcPrecision)) {
+ return MA_FALSE;
}
if (lpcPrecision == 15) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
lpcPrecision += 1;
- if (!drflac__read_int8(bs, 5, &lpcShift)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_int8(bs, 5, &lpcShift)) {
+ return MA_FALSE;
}
if (lpcShift < 0) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
- DRFLAC_ZERO_MEMORY(coefficients, sizeof(coefficients));
+ MA_DR_FLAC_ZERO_MEMORY(coefficients, sizeof(coefficients));
for (i = 0; i < lpcOrder; ++i) {
- if (!drflac__read_int32(bs, lpcPrecision, coefficients + i)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_int32(bs, lpcPrecision, coefficients + i)) {
+ return MA_FALSE;
}
}
- if (!drflac__decode_samples_with_residual(bs, bitsPerSample, blockSize, lpcOrder, lpcShift, lpcPrecision, coefficients, pDecodedSamples)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__decode_samples_with_residual(bs, bitsPerSample, blockSize, lpcOrder, lpcShift, lpcPrecision, coefficients, pDecodedSamples)) {
+ return MA_FALSE;
}
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
-static drflac_bool32 drflac__read_next_flac_frame_header(drflac_bs* bs, drflac_uint8 streaminfoBitsPerSample, drflac_frame_header* header)
+static ma_bool32 ma_dr_flac__read_next_flac_frame_header(ma_dr_flac_bs* bs, ma_uint8 streaminfoBitsPerSample, ma_dr_flac_frame_header* header)
{
- const drflac_uint32 sampleRateTable[12] = {0, 88200, 176400, 192000, 8000, 16000, 22050, 24000, 32000, 44100, 48000, 96000};
- const drflac_uint8 bitsPerSampleTable[8] = {0, 8, 12, (drflac_uint8)-1, 16, 20, 24, (drflac_uint8)-1};
- DRFLAC_ASSERT(bs != NULL);
- DRFLAC_ASSERT(header != NULL);
+ const ma_uint32 sampleRateTable[12] = {0, 88200, 176400, 192000, 8000, 16000, 22050, 24000, 32000, 44100, 48000, 96000};
+ const ma_uint8 bitsPerSampleTable[8] = {0, 8, 12, (ma_uint8)-1, 16, 20, 24, (ma_uint8)-1};
+ MA_DR_FLAC_ASSERT(bs != NULL);
+ MA_DR_FLAC_ASSERT(header != NULL);
for (;;) {
- drflac_uint8 crc8 = 0xCE;
- drflac_uint8 reserved = 0;
- drflac_uint8 blockingStrategy = 0;
- drflac_uint8 blockSize = 0;
- drflac_uint8 sampleRate = 0;
- drflac_uint8 channelAssignment = 0;
- drflac_uint8 bitsPerSample = 0;
- drflac_bool32 isVariableBlockSize;
- if (!drflac__find_and_seek_to_next_sync_code(bs)) {
- return DRFLAC_FALSE;
- }
- if (!drflac__read_uint8(bs, 1, &reserved)) {
- return DRFLAC_FALSE;
+ ma_uint8 crc8 = 0xCE;
+ ma_uint8 reserved = 0;
+ ma_uint8 blockingStrategy = 0;
+ ma_uint8 blockSize = 0;
+ ma_uint8 sampleRate = 0;
+ ma_uint8 channelAssignment = 0;
+ ma_uint8 bitsPerSample = 0;
+ ma_bool32 isVariableBlockSize;
+ if (!ma_dr_flac__find_and_seek_to_next_sync_code(bs)) {
+ return MA_FALSE;
+ }
+ if (!ma_dr_flac__read_uint8(bs, 1, &reserved)) {
+ return MA_FALSE;
}
if (reserved == 1) {
continue;
}
- crc8 = drflac_crc8(crc8, reserved, 1);
- if (!drflac__read_uint8(bs, 1, &blockingStrategy)) {
- return DRFLAC_FALSE;
+ crc8 = ma_dr_flac_crc8(crc8, reserved, 1);
+ if (!ma_dr_flac__read_uint8(bs, 1, &blockingStrategy)) {
+ return MA_FALSE;
}
- crc8 = drflac_crc8(crc8, blockingStrategy, 1);
- if (!drflac__read_uint8(bs, 4, &blockSize)) {
- return DRFLAC_FALSE;
+ crc8 = ma_dr_flac_crc8(crc8, blockingStrategy, 1);
+ if (!ma_dr_flac__read_uint8(bs, 4, &blockSize)) {
+ return MA_FALSE;
}
if (blockSize == 0) {
continue;
}
- crc8 = drflac_crc8(crc8, blockSize, 4);
- if (!drflac__read_uint8(bs, 4, &sampleRate)) {
- return DRFLAC_FALSE;
+ crc8 = ma_dr_flac_crc8(crc8, blockSize, 4);
+ if (!ma_dr_flac__read_uint8(bs, 4, &sampleRate)) {
+ return MA_FALSE;
}
- crc8 = drflac_crc8(crc8, sampleRate, 4);
- if (!drflac__read_uint8(bs, 4, &channelAssignment)) {
- return DRFLAC_FALSE;
+ crc8 = ma_dr_flac_crc8(crc8, sampleRate, 4);
+ if (!ma_dr_flac__read_uint8(bs, 4, &channelAssignment)) {
+ return MA_FALSE;
}
if (channelAssignment > 10) {
continue;
}
- crc8 = drflac_crc8(crc8, channelAssignment, 4);
- if (!drflac__read_uint8(bs, 3, &bitsPerSample)) {
- return DRFLAC_FALSE;
+ crc8 = ma_dr_flac_crc8(crc8, channelAssignment, 4);
+ if (!ma_dr_flac__read_uint8(bs, 3, &bitsPerSample)) {
+ return MA_FALSE;
}
if (bitsPerSample == 3 || bitsPerSample == 7) {
continue;
}
- crc8 = drflac_crc8(crc8, bitsPerSample, 3);
- if (!drflac__read_uint8(bs, 1, &reserved)) {
- return DRFLAC_FALSE;
+ crc8 = ma_dr_flac_crc8(crc8, bitsPerSample, 3);
+ if (!ma_dr_flac__read_uint8(bs, 1, &reserved)) {
+ return MA_FALSE;
}
if (reserved == 1) {
continue;
}
- crc8 = drflac_crc8(crc8, reserved, 1);
+ crc8 = ma_dr_flac_crc8(crc8, reserved, 1);
isVariableBlockSize = blockingStrategy == 1;
if (isVariableBlockSize) {
- drflac_uint64 pcmFrameNumber;
- drflac_result result = drflac__read_utf8_coded_number(bs, &pcmFrameNumber, &crc8);
- if (result != DRFLAC_SUCCESS) {
- if (result == DRFLAC_AT_END) {
- return DRFLAC_FALSE;
+ ma_uint64 pcmFrameNumber;
+ ma_result result = ma_dr_flac__read_utf8_coded_number(bs, &pcmFrameNumber, &crc8);
+ if (result != MA_SUCCESS) {
+ if (result == MA_AT_END) {
+ return MA_FALSE;
} else {
continue;
}
@@ -82573,61 +85005,61 @@ static drflac_bool32 drflac__read_next_flac_frame_header(drflac_bs* bs, drflac_u
header->flacFrameNumber = 0;
header->pcmFrameNumber = pcmFrameNumber;
} else {
- drflac_uint64 flacFrameNumber = 0;
- drflac_result result = drflac__read_utf8_coded_number(bs, &flacFrameNumber, &crc8);
- if (result != DRFLAC_SUCCESS) {
- if (result == DRFLAC_AT_END) {
- return DRFLAC_FALSE;
+ ma_uint64 flacFrameNumber = 0;
+ ma_result result = ma_dr_flac__read_utf8_coded_number(bs, &flacFrameNumber, &crc8);
+ if (result != MA_SUCCESS) {
+ if (result == MA_AT_END) {
+ return MA_FALSE;
} else {
continue;
}
}
- header->flacFrameNumber = (drflac_uint32)flacFrameNumber;
+ header->flacFrameNumber = (ma_uint32)flacFrameNumber;
header->pcmFrameNumber = 0;
}
- DRFLAC_ASSERT(blockSize > 0);
+ MA_DR_FLAC_ASSERT(blockSize > 0);
if (blockSize == 1) {
header->blockSizeInPCMFrames = 192;
} else if (blockSize <= 5) {
- DRFLAC_ASSERT(blockSize >= 2);
+ MA_DR_FLAC_ASSERT(blockSize >= 2);
header->blockSizeInPCMFrames = 576 * (1 << (blockSize - 2));
} else if (blockSize == 6) {
- if (!drflac__read_uint16(bs, 8, &header->blockSizeInPCMFrames)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_uint16(bs, 8, &header->blockSizeInPCMFrames)) {
+ return MA_FALSE;
}
- crc8 = drflac_crc8(crc8, header->blockSizeInPCMFrames, 8);
+ crc8 = ma_dr_flac_crc8(crc8, header->blockSizeInPCMFrames, 8);
header->blockSizeInPCMFrames += 1;
} else if (blockSize == 7) {
- if (!drflac__read_uint16(bs, 16, &header->blockSizeInPCMFrames)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_uint16(bs, 16, &header->blockSizeInPCMFrames)) {
+ return MA_FALSE;
}
- crc8 = drflac_crc8(crc8, header->blockSizeInPCMFrames, 16);
+ crc8 = ma_dr_flac_crc8(crc8, header->blockSizeInPCMFrames, 16);
if (header->blockSizeInPCMFrames == 0xFFFF) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
header->blockSizeInPCMFrames += 1;
} else {
- DRFLAC_ASSERT(blockSize >= 8);
+ MA_DR_FLAC_ASSERT(blockSize >= 8);
header->blockSizeInPCMFrames = 256 * (1 << (blockSize - 8));
}
if (sampleRate <= 11) {
header->sampleRate = sampleRateTable[sampleRate];
} else if (sampleRate == 12) {
- if (!drflac__read_uint32(bs, 8, &header->sampleRate)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_uint32(bs, 8, &header->sampleRate)) {
+ return MA_FALSE;
}
- crc8 = drflac_crc8(crc8, header->sampleRate, 8);
+ crc8 = ma_dr_flac_crc8(crc8, header->sampleRate, 8);
header->sampleRate *= 1000;
} else if (sampleRate == 13) {
- if (!drflac__read_uint32(bs, 16, &header->sampleRate)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_uint32(bs, 16, &header->sampleRate)) {
+ return MA_FALSE;
}
- crc8 = drflac_crc8(crc8, header->sampleRate, 16);
+ crc8 = ma_dr_flac_crc8(crc8, header->sampleRate, 16);
} else if (sampleRate == 14) {
- if (!drflac__read_uint32(bs, 16, &header->sampleRate)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_uint32(bs, 16, &header->sampleRate)) {
+ return MA_FALSE;
}
- crc8 = drflac_crc8(crc8, header->sampleRate, 16);
+ crc8 = ma_dr_flac_crc8(crc8, header->sampleRate, 16);
header->sampleRate *= 10;
} else {
continue;
@@ -82638,286 +85070,286 @@ static drflac_bool32 drflac__read_next_flac_frame_header(drflac_bs* bs, drflac_u
header->bitsPerSample = streaminfoBitsPerSample;
}
if (header->bitsPerSample != streaminfoBitsPerSample) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
- if (!drflac__read_uint8(bs, 8, &header->crc8)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_uint8(bs, 8, &header->crc8)) {
+ return MA_FALSE;
}
-#ifndef DR_FLAC_NO_CRC
+#ifndef MA_DR_FLAC_NO_CRC
if (header->crc8 != crc8) {
continue;
}
#endif
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
}
-static drflac_bool32 drflac__read_subframe_header(drflac_bs* bs, drflac_subframe* pSubframe)
+static ma_bool32 ma_dr_flac__read_subframe_header(ma_dr_flac_bs* bs, ma_dr_flac_subframe* pSubframe)
{
- drflac_uint8 header;
+ ma_uint8 header;
int type;
- if (!drflac__read_uint8(bs, 8, &header)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_uint8(bs, 8, &header)) {
+ return MA_FALSE;
}
if ((header & 0x80) != 0) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
type = (header & 0x7E) >> 1;
if (type == 0) {
- pSubframe->subframeType = DRFLAC_SUBFRAME_CONSTANT;
+ pSubframe->subframeType = MA_DR_FLAC_SUBFRAME_CONSTANT;
} else if (type == 1) {
- pSubframe->subframeType = DRFLAC_SUBFRAME_VERBATIM;
+ pSubframe->subframeType = MA_DR_FLAC_SUBFRAME_VERBATIM;
} else {
if ((type & 0x20) != 0) {
- pSubframe->subframeType = DRFLAC_SUBFRAME_LPC;
- pSubframe->lpcOrder = (drflac_uint8)(type & 0x1F) + 1;
+ pSubframe->subframeType = MA_DR_FLAC_SUBFRAME_LPC;
+ pSubframe->lpcOrder = (ma_uint8)(type & 0x1F) + 1;
} else if ((type & 0x08) != 0) {
- pSubframe->subframeType = DRFLAC_SUBFRAME_FIXED;
- pSubframe->lpcOrder = (drflac_uint8)(type & 0x07);
+ pSubframe->subframeType = MA_DR_FLAC_SUBFRAME_FIXED;
+ pSubframe->lpcOrder = (ma_uint8)(type & 0x07);
if (pSubframe->lpcOrder > 4) {
- pSubframe->subframeType = DRFLAC_SUBFRAME_RESERVED;
+ pSubframe->subframeType = MA_DR_FLAC_SUBFRAME_RESERVED;
pSubframe->lpcOrder = 0;
}
} else {
- pSubframe->subframeType = DRFLAC_SUBFRAME_RESERVED;
+ pSubframe->subframeType = MA_DR_FLAC_SUBFRAME_RESERVED;
}
}
- if (pSubframe->subframeType == DRFLAC_SUBFRAME_RESERVED) {
- return DRFLAC_FALSE;
+ if (pSubframe->subframeType == MA_DR_FLAC_SUBFRAME_RESERVED) {
+ return MA_FALSE;
}
pSubframe->wastedBitsPerSample = 0;
if ((header & 0x01) == 1) {
unsigned int wastedBitsPerSample;
- if (!drflac__seek_past_next_set_bit(bs, &wastedBitsPerSample)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__seek_past_next_set_bit(bs, &wastedBitsPerSample)) {
+ return MA_FALSE;
}
- pSubframe->wastedBitsPerSample = (drflac_uint8)wastedBitsPerSample + 1;
+ pSubframe->wastedBitsPerSample = (ma_uint8)wastedBitsPerSample + 1;
}
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
-static drflac_bool32 drflac__decode_subframe(drflac_bs* bs, drflac_frame* frame, int subframeIndex, drflac_int32* pDecodedSamplesOut)
+static ma_bool32 ma_dr_flac__decode_subframe(ma_dr_flac_bs* bs, ma_dr_flac_frame* frame, int subframeIndex, ma_int32* pDecodedSamplesOut)
{
- drflac_subframe* pSubframe;
- drflac_uint32 subframeBitsPerSample;
- DRFLAC_ASSERT(bs != NULL);
- DRFLAC_ASSERT(frame != NULL);
+ ma_dr_flac_subframe* pSubframe;
+ ma_uint32 subframeBitsPerSample;
+ MA_DR_FLAC_ASSERT(bs != NULL);
+ MA_DR_FLAC_ASSERT(frame != NULL);
pSubframe = frame->subframes + subframeIndex;
- if (!drflac__read_subframe_header(bs, pSubframe)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_subframe_header(bs, pSubframe)) {
+ return MA_FALSE;
}
subframeBitsPerSample = frame->header.bitsPerSample;
- if ((frame->header.channelAssignment == DRFLAC_CHANNEL_ASSIGNMENT_LEFT_SIDE || frame->header.channelAssignment == DRFLAC_CHANNEL_ASSIGNMENT_MID_SIDE) && subframeIndex == 1) {
+ if ((frame->header.channelAssignment == MA_DR_FLAC_CHANNEL_ASSIGNMENT_LEFT_SIDE || frame->header.channelAssignment == MA_DR_FLAC_CHANNEL_ASSIGNMENT_MID_SIDE) && subframeIndex == 1) {
subframeBitsPerSample += 1;
- } else if (frame->header.channelAssignment == DRFLAC_CHANNEL_ASSIGNMENT_RIGHT_SIDE && subframeIndex == 0) {
+ } else if (frame->header.channelAssignment == MA_DR_FLAC_CHANNEL_ASSIGNMENT_RIGHT_SIDE && subframeIndex == 0) {
subframeBitsPerSample += 1;
}
if (subframeBitsPerSample > 32) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
if (pSubframe->wastedBitsPerSample >= subframeBitsPerSample) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
subframeBitsPerSample -= pSubframe->wastedBitsPerSample;
pSubframe->pSamplesS32 = pDecodedSamplesOut;
switch (pSubframe->subframeType)
{
- case DRFLAC_SUBFRAME_CONSTANT:
+ case MA_DR_FLAC_SUBFRAME_CONSTANT:
{
- drflac__decode_samples__constant(bs, frame->header.blockSizeInPCMFrames, subframeBitsPerSample, pSubframe->pSamplesS32);
+ ma_dr_flac__decode_samples__constant(bs, frame->header.blockSizeInPCMFrames, subframeBitsPerSample, pSubframe->pSamplesS32);
} break;
- case DRFLAC_SUBFRAME_VERBATIM:
+ case MA_DR_FLAC_SUBFRAME_VERBATIM:
{
- drflac__decode_samples__verbatim(bs, frame->header.blockSizeInPCMFrames, subframeBitsPerSample, pSubframe->pSamplesS32);
+ ma_dr_flac__decode_samples__verbatim(bs, frame->header.blockSizeInPCMFrames, subframeBitsPerSample, pSubframe->pSamplesS32);
} break;
- case DRFLAC_SUBFRAME_FIXED:
+ case MA_DR_FLAC_SUBFRAME_FIXED:
{
- drflac__decode_samples__fixed(bs, frame->header.blockSizeInPCMFrames, subframeBitsPerSample, pSubframe->lpcOrder, pSubframe->pSamplesS32);
+ ma_dr_flac__decode_samples__fixed(bs, frame->header.blockSizeInPCMFrames, subframeBitsPerSample, pSubframe->lpcOrder, pSubframe->pSamplesS32);
} break;
- case DRFLAC_SUBFRAME_LPC:
+ case MA_DR_FLAC_SUBFRAME_LPC:
{
- drflac__decode_samples__lpc(bs, frame->header.blockSizeInPCMFrames, subframeBitsPerSample, pSubframe->lpcOrder, pSubframe->pSamplesS32);
+ ma_dr_flac__decode_samples__lpc(bs, frame->header.blockSizeInPCMFrames, subframeBitsPerSample, pSubframe->lpcOrder, pSubframe->pSamplesS32);
} break;
- default: return DRFLAC_FALSE;
+ default: return MA_FALSE;
}
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
-static drflac_bool32 drflac__seek_subframe(drflac_bs* bs, drflac_frame* frame, int subframeIndex)
+static ma_bool32 ma_dr_flac__seek_subframe(ma_dr_flac_bs* bs, ma_dr_flac_frame* frame, int subframeIndex)
{
- drflac_subframe* pSubframe;
- drflac_uint32 subframeBitsPerSample;
- DRFLAC_ASSERT(bs != NULL);
- DRFLAC_ASSERT(frame != NULL);
+ ma_dr_flac_subframe* pSubframe;
+ ma_uint32 subframeBitsPerSample;
+ MA_DR_FLAC_ASSERT(bs != NULL);
+ MA_DR_FLAC_ASSERT(frame != NULL);
pSubframe = frame->subframes + subframeIndex;
- if (!drflac__read_subframe_header(bs, pSubframe)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_subframe_header(bs, pSubframe)) {
+ return MA_FALSE;
}
subframeBitsPerSample = frame->header.bitsPerSample;
- if ((frame->header.channelAssignment == DRFLAC_CHANNEL_ASSIGNMENT_LEFT_SIDE || frame->header.channelAssignment == DRFLAC_CHANNEL_ASSIGNMENT_MID_SIDE) && subframeIndex == 1) {
+ if ((frame->header.channelAssignment == MA_DR_FLAC_CHANNEL_ASSIGNMENT_LEFT_SIDE || frame->header.channelAssignment == MA_DR_FLAC_CHANNEL_ASSIGNMENT_MID_SIDE) && subframeIndex == 1) {
subframeBitsPerSample += 1;
- } else if (frame->header.channelAssignment == DRFLAC_CHANNEL_ASSIGNMENT_RIGHT_SIDE && subframeIndex == 0) {
+ } else if (frame->header.channelAssignment == MA_DR_FLAC_CHANNEL_ASSIGNMENT_RIGHT_SIDE && subframeIndex == 0) {
subframeBitsPerSample += 1;
}
if (pSubframe->wastedBitsPerSample >= subframeBitsPerSample) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
subframeBitsPerSample -= pSubframe->wastedBitsPerSample;
pSubframe->pSamplesS32 = NULL;
switch (pSubframe->subframeType)
{
- case DRFLAC_SUBFRAME_CONSTANT:
+ case MA_DR_FLAC_SUBFRAME_CONSTANT:
{
- if (!drflac__seek_bits(bs, subframeBitsPerSample)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__seek_bits(bs, subframeBitsPerSample)) {
+ return MA_FALSE;
}
} break;
- case DRFLAC_SUBFRAME_VERBATIM:
+ case MA_DR_FLAC_SUBFRAME_VERBATIM:
{
unsigned int bitsToSeek = frame->header.blockSizeInPCMFrames * subframeBitsPerSample;
- if (!drflac__seek_bits(bs, bitsToSeek)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__seek_bits(bs, bitsToSeek)) {
+ return MA_FALSE;
}
} break;
- case DRFLAC_SUBFRAME_FIXED:
+ case MA_DR_FLAC_SUBFRAME_FIXED:
{
unsigned int bitsToSeek = pSubframe->lpcOrder * subframeBitsPerSample;
- if (!drflac__seek_bits(bs, bitsToSeek)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__seek_bits(bs, bitsToSeek)) {
+ return MA_FALSE;
}
- if (!drflac__read_and_seek_residual(bs, frame->header.blockSizeInPCMFrames, pSubframe->lpcOrder)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_and_seek_residual(bs, frame->header.blockSizeInPCMFrames, pSubframe->lpcOrder)) {
+ return MA_FALSE;
}
} break;
- case DRFLAC_SUBFRAME_LPC:
+ case MA_DR_FLAC_SUBFRAME_LPC:
{
- drflac_uint8 lpcPrecision;
+ ma_uint8 lpcPrecision;
unsigned int bitsToSeek = pSubframe->lpcOrder * subframeBitsPerSample;
- if (!drflac__seek_bits(bs, bitsToSeek)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__seek_bits(bs, bitsToSeek)) {
+ return MA_FALSE;
}
- if (!drflac__read_uint8(bs, 4, &lpcPrecision)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_uint8(bs, 4, &lpcPrecision)) {
+ return MA_FALSE;
}
if (lpcPrecision == 15) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
lpcPrecision += 1;
bitsToSeek = (pSubframe->lpcOrder * lpcPrecision) + 5;
- if (!drflac__seek_bits(bs, bitsToSeek)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__seek_bits(bs, bitsToSeek)) {
+ return MA_FALSE;
}
- if (!drflac__read_and_seek_residual(bs, frame->header.blockSizeInPCMFrames, pSubframe->lpcOrder)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_and_seek_residual(bs, frame->header.blockSizeInPCMFrames, pSubframe->lpcOrder)) {
+ return MA_FALSE;
}
} break;
- default: return DRFLAC_FALSE;
+ default: return MA_FALSE;
}
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
-static DRFLAC_INLINE drflac_uint8 drflac__get_channel_count_from_channel_assignment(drflac_int8 channelAssignment)
+static MA_INLINE ma_uint8 ma_dr_flac__get_channel_count_from_channel_assignment(ma_int8 channelAssignment)
{
- drflac_uint8 lookup[] = {1, 2, 3, 4, 5, 6, 7, 8, 2, 2, 2};
- DRFLAC_ASSERT(channelAssignment <= 10);
+ ma_uint8 lookup[] = {1, 2, 3, 4, 5, 6, 7, 8, 2, 2, 2};
+ MA_DR_FLAC_ASSERT(channelAssignment <= 10);
return lookup[channelAssignment];
}
-static drflac_result drflac__decode_flac_frame(drflac* pFlac)
+static ma_result ma_dr_flac__decode_flac_frame(ma_dr_flac* pFlac)
{
int channelCount;
int i;
- drflac_uint8 paddingSizeInBits;
- drflac_uint16 desiredCRC16;
-#ifndef DR_FLAC_NO_CRC
- drflac_uint16 actualCRC16;
+ ma_uint8 paddingSizeInBits;
+ ma_uint16 desiredCRC16;
+#ifndef MA_DR_FLAC_NO_CRC
+ ma_uint16 actualCRC16;
#endif
- DRFLAC_ZERO_MEMORY(pFlac->currentFLACFrame.subframes, sizeof(pFlac->currentFLACFrame.subframes));
+ MA_DR_FLAC_ZERO_MEMORY(pFlac->currentFLACFrame.subframes, sizeof(pFlac->currentFLACFrame.subframes));
if (pFlac->currentFLACFrame.header.blockSizeInPCMFrames > pFlac->maxBlockSizeInPCMFrames) {
- return DRFLAC_ERROR;
+ return MA_ERROR;
}
- channelCount = drflac__get_channel_count_from_channel_assignment(pFlac->currentFLACFrame.header.channelAssignment);
+ channelCount = ma_dr_flac__get_channel_count_from_channel_assignment(pFlac->currentFLACFrame.header.channelAssignment);
if (channelCount != (int)pFlac->channels) {
- return DRFLAC_ERROR;
+ return MA_ERROR;
}
for (i = 0; i < channelCount; ++i) {
- if (!drflac__decode_subframe(&pFlac->bs, &pFlac->currentFLACFrame, i, pFlac->pDecodedSamples + (pFlac->currentFLACFrame.header.blockSizeInPCMFrames * i))) {
- return DRFLAC_ERROR;
+ if (!ma_dr_flac__decode_subframe(&pFlac->bs, &pFlac->currentFLACFrame, i, pFlac->pDecodedSamples + (pFlac->currentFLACFrame.header.blockSizeInPCMFrames * i))) {
+ return MA_ERROR;
}
}
- paddingSizeInBits = (drflac_uint8)(DRFLAC_CACHE_L1_BITS_REMAINING(&pFlac->bs) & 7);
+ paddingSizeInBits = (ma_uint8)(MA_DR_FLAC_CACHE_L1_BITS_REMAINING(&pFlac->bs) & 7);
if (paddingSizeInBits > 0) {
- drflac_uint8 padding = 0;
- if (!drflac__read_uint8(&pFlac->bs, paddingSizeInBits, &padding)) {
- return DRFLAC_AT_END;
+ ma_uint8 padding = 0;
+ if (!ma_dr_flac__read_uint8(&pFlac->bs, paddingSizeInBits, &padding)) {
+ return MA_AT_END;
}
}
-#ifndef DR_FLAC_NO_CRC
- actualCRC16 = drflac__flush_crc16(&pFlac->bs);
+#ifndef MA_DR_FLAC_NO_CRC
+ actualCRC16 = ma_dr_flac__flush_crc16(&pFlac->bs);
#endif
- if (!drflac__read_uint16(&pFlac->bs, 16, &desiredCRC16)) {
- return DRFLAC_AT_END;
+ if (!ma_dr_flac__read_uint16(&pFlac->bs, 16, &desiredCRC16)) {
+ return MA_AT_END;
}
-#ifndef DR_FLAC_NO_CRC
+#ifndef MA_DR_FLAC_NO_CRC
if (actualCRC16 != desiredCRC16) {
- return DRFLAC_CRC_MISMATCH;
+ return MA_CRC_MISMATCH;
}
#endif
pFlac->currentFLACFrame.pcmFramesRemaining = pFlac->currentFLACFrame.header.blockSizeInPCMFrames;
- return DRFLAC_SUCCESS;
+ return MA_SUCCESS;
}
-static drflac_result drflac__seek_flac_frame(drflac* pFlac)
+static ma_result ma_dr_flac__seek_flac_frame(ma_dr_flac* pFlac)
{
int channelCount;
int i;
- drflac_uint16 desiredCRC16;
-#ifndef DR_FLAC_NO_CRC
- drflac_uint16 actualCRC16;
+ ma_uint16 desiredCRC16;
+#ifndef MA_DR_FLAC_NO_CRC
+ ma_uint16 actualCRC16;
#endif
- channelCount = drflac__get_channel_count_from_channel_assignment(pFlac->currentFLACFrame.header.channelAssignment);
+ channelCount = ma_dr_flac__get_channel_count_from_channel_assignment(pFlac->currentFLACFrame.header.channelAssignment);
for (i = 0; i < channelCount; ++i) {
- if (!drflac__seek_subframe(&pFlac->bs, &pFlac->currentFLACFrame, i)) {
- return DRFLAC_ERROR;
+ if (!ma_dr_flac__seek_subframe(&pFlac->bs, &pFlac->currentFLACFrame, i)) {
+ return MA_ERROR;
}
}
- if (!drflac__seek_bits(&pFlac->bs, DRFLAC_CACHE_L1_BITS_REMAINING(&pFlac->bs) & 7)) {
- return DRFLAC_ERROR;
+ if (!ma_dr_flac__seek_bits(&pFlac->bs, MA_DR_FLAC_CACHE_L1_BITS_REMAINING(&pFlac->bs) & 7)) {
+ return MA_ERROR;
}
-#ifndef DR_FLAC_NO_CRC
- actualCRC16 = drflac__flush_crc16(&pFlac->bs);
+#ifndef MA_DR_FLAC_NO_CRC
+ actualCRC16 = ma_dr_flac__flush_crc16(&pFlac->bs);
#endif
- if (!drflac__read_uint16(&pFlac->bs, 16, &desiredCRC16)) {
- return DRFLAC_AT_END;
+ if (!ma_dr_flac__read_uint16(&pFlac->bs, 16, &desiredCRC16)) {
+ return MA_AT_END;
}
-#ifndef DR_FLAC_NO_CRC
+#ifndef MA_DR_FLAC_NO_CRC
if (actualCRC16 != desiredCRC16) {
- return DRFLAC_CRC_MISMATCH;
+ return MA_CRC_MISMATCH;
}
#endif
- return DRFLAC_SUCCESS;
+ return MA_SUCCESS;
}
-static drflac_bool32 drflac__read_and_decode_next_flac_frame(drflac* pFlac)
+static ma_bool32 ma_dr_flac__read_and_decode_next_flac_frame(ma_dr_flac* pFlac)
{
- DRFLAC_ASSERT(pFlac != NULL);
+ MA_DR_FLAC_ASSERT(pFlac != NULL);
for (;;) {
- drflac_result result;
- if (!drflac__read_next_flac_frame_header(&pFlac->bs, pFlac->bitsPerSample, &pFlac->currentFLACFrame.header)) {
- return DRFLAC_FALSE;
+ ma_result result;
+ if (!ma_dr_flac__read_next_flac_frame_header(&pFlac->bs, pFlac->bitsPerSample, &pFlac->currentFLACFrame.header)) {
+ return MA_FALSE;
}
- result = drflac__decode_flac_frame(pFlac);
- if (result != DRFLAC_SUCCESS) {
- if (result == DRFLAC_CRC_MISMATCH) {
+ result = ma_dr_flac__decode_flac_frame(pFlac);
+ if (result != MA_SUCCESS) {
+ if (result == MA_CRC_MISMATCH) {
continue;
} else {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
}
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
}
-static void drflac__get_pcm_frame_range_of_current_flac_frame(drflac* pFlac, drflac_uint64* pFirstPCMFrame, drflac_uint64* pLastPCMFrame)
+static void ma_dr_flac__get_pcm_frame_range_of_current_flac_frame(ma_dr_flac* pFlac, ma_uint64* pFirstPCMFrame, ma_uint64* pLastPCMFrame)
{
- drflac_uint64 firstPCMFrame;
- drflac_uint64 lastPCMFrame;
- DRFLAC_ASSERT(pFlac != NULL);
+ ma_uint64 firstPCMFrame;
+ ma_uint64 lastPCMFrame;
+ MA_DR_FLAC_ASSERT(pFlac != NULL);
firstPCMFrame = pFlac->currentFLACFrame.header.pcmFrameNumber;
if (firstPCMFrame == 0) {
- firstPCMFrame = ((drflac_uint64)pFlac->currentFLACFrame.header.flacFrameNumber) * pFlac->maxBlockSizeInPCMFrames;
+ firstPCMFrame = ((ma_uint64)pFlac->currentFLACFrame.header.flacFrameNumber) * pFlac->maxBlockSizeInPCMFrames;
}
lastPCMFrame = firstPCMFrame + pFlac->currentFLACFrame.header.blockSizeInPCMFrames;
if (lastPCMFrame > 0) {
@@ -82930,32 +85362,32 @@ static void drflac__get_pcm_frame_range_of_current_flac_frame(drflac* pFlac, drf
*pLastPCMFrame = lastPCMFrame;
}
}
-static drflac_bool32 drflac__seek_to_first_frame(drflac* pFlac)
+static ma_bool32 ma_dr_flac__seek_to_first_frame(ma_dr_flac* pFlac)
{
- drflac_bool32 result;
- DRFLAC_ASSERT(pFlac != NULL);
- result = drflac__seek_to_byte(&pFlac->bs, pFlac->firstFLACFramePosInBytes);
- DRFLAC_ZERO_MEMORY(&pFlac->currentFLACFrame, sizeof(pFlac->currentFLACFrame));
+ ma_bool32 result;
+ MA_DR_FLAC_ASSERT(pFlac != NULL);
+ result = ma_dr_flac__seek_to_byte(&pFlac->bs, pFlac->firstFLACFramePosInBytes);
+ MA_DR_FLAC_ZERO_MEMORY(&pFlac->currentFLACFrame, sizeof(pFlac->currentFLACFrame));
pFlac->currentPCMFrame = 0;
return result;
}
-static DRFLAC_INLINE drflac_result drflac__seek_to_next_flac_frame(drflac* pFlac)
+static MA_INLINE ma_result ma_dr_flac__seek_to_next_flac_frame(ma_dr_flac* pFlac)
{
- DRFLAC_ASSERT(pFlac != NULL);
- return drflac__seek_flac_frame(pFlac);
+ MA_DR_FLAC_ASSERT(pFlac != NULL);
+ return ma_dr_flac__seek_flac_frame(pFlac);
}
-static drflac_uint64 drflac__seek_forward_by_pcm_frames(drflac* pFlac, drflac_uint64 pcmFramesToSeek)
+static ma_uint64 ma_dr_flac__seek_forward_by_pcm_frames(ma_dr_flac* pFlac, ma_uint64 pcmFramesToSeek)
{
- drflac_uint64 pcmFramesRead = 0;
+ ma_uint64 pcmFramesRead = 0;
while (pcmFramesToSeek > 0) {
if (pFlac->currentFLACFrame.pcmFramesRemaining == 0) {
- if (!drflac__read_and_decode_next_flac_frame(pFlac)) {
+ if (!ma_dr_flac__read_and_decode_next_flac_frame(pFlac)) {
break;
}
} else {
if (pFlac->currentFLACFrame.pcmFramesRemaining > pcmFramesToSeek) {
pcmFramesRead += pcmFramesToSeek;
- pFlac->currentFLACFrame.pcmFramesRemaining -= (drflac_uint32)pcmFramesToSeek;
+ pFlac->currentFLACFrame.pcmFramesRemaining -= (ma_uint32)pcmFramesToSeek;
pcmFramesToSeek = 0;
} else {
pcmFramesRead += pFlac->currentFLACFrame.pcmFramesRemaining;
@@ -82967,107 +85399,107 @@ static drflac_uint64 drflac__seek_forward_by_pcm_frames(drflac* pFlac, drflac_ui
pFlac->currentPCMFrame += pcmFramesRead;
return pcmFramesRead;
}
-static drflac_bool32 drflac__seek_to_pcm_frame__brute_force(drflac* pFlac, drflac_uint64 pcmFrameIndex)
+static ma_bool32 ma_dr_flac__seek_to_pcm_frame__brute_force(ma_dr_flac* pFlac, ma_uint64 pcmFrameIndex)
{
- drflac_bool32 isMidFrame = DRFLAC_FALSE;
- drflac_uint64 runningPCMFrameCount;
- DRFLAC_ASSERT(pFlac != NULL);
+ ma_bool32 isMidFrame = MA_FALSE;
+ ma_uint64 runningPCMFrameCount;
+ MA_DR_FLAC_ASSERT(pFlac != NULL);
if (pcmFrameIndex >= pFlac->currentPCMFrame) {
runningPCMFrameCount = pFlac->currentPCMFrame;
if (pFlac->currentPCMFrame == 0 && pFlac->currentFLACFrame.pcmFramesRemaining == 0) {
- if (!drflac__read_next_flac_frame_header(&pFlac->bs, pFlac->bitsPerSample, &pFlac->currentFLACFrame.header)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_next_flac_frame_header(&pFlac->bs, pFlac->bitsPerSample, &pFlac->currentFLACFrame.header)) {
+ return MA_FALSE;
}
} else {
- isMidFrame = DRFLAC_TRUE;
+ isMidFrame = MA_TRUE;
}
} else {
runningPCMFrameCount = 0;
- if (!drflac__seek_to_first_frame(pFlac)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__seek_to_first_frame(pFlac)) {
+ return MA_FALSE;
}
- if (!drflac__read_next_flac_frame_header(&pFlac->bs, pFlac->bitsPerSample, &pFlac->currentFLACFrame.header)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_next_flac_frame_header(&pFlac->bs, pFlac->bitsPerSample, &pFlac->currentFLACFrame.header)) {
+ return MA_FALSE;
}
}
for (;;) {
- drflac_uint64 pcmFrameCountInThisFLACFrame;
- drflac_uint64 firstPCMFrameInFLACFrame = 0;
- drflac_uint64 lastPCMFrameInFLACFrame = 0;
- drflac__get_pcm_frame_range_of_current_flac_frame(pFlac, &firstPCMFrameInFLACFrame, &lastPCMFrameInFLACFrame);
+ ma_uint64 pcmFrameCountInThisFLACFrame;
+ ma_uint64 firstPCMFrameInFLACFrame = 0;
+ ma_uint64 lastPCMFrameInFLACFrame = 0;
+ ma_dr_flac__get_pcm_frame_range_of_current_flac_frame(pFlac, &firstPCMFrameInFLACFrame, &lastPCMFrameInFLACFrame);
pcmFrameCountInThisFLACFrame = (lastPCMFrameInFLACFrame - firstPCMFrameInFLACFrame) + 1;
if (pcmFrameIndex < (runningPCMFrameCount + pcmFrameCountInThisFLACFrame)) {
- drflac_uint64 pcmFramesToDecode = pcmFrameIndex - runningPCMFrameCount;
+ ma_uint64 pcmFramesToDecode = pcmFrameIndex - runningPCMFrameCount;
if (!isMidFrame) {
- drflac_result result = drflac__decode_flac_frame(pFlac);
- if (result == DRFLAC_SUCCESS) {
- return drflac__seek_forward_by_pcm_frames(pFlac, pcmFramesToDecode) == pcmFramesToDecode;
+ ma_result result = ma_dr_flac__decode_flac_frame(pFlac);
+ if (result == MA_SUCCESS) {
+ return ma_dr_flac__seek_forward_by_pcm_frames(pFlac, pcmFramesToDecode) == pcmFramesToDecode;
} else {
- if (result == DRFLAC_CRC_MISMATCH) {
+ if (result == MA_CRC_MISMATCH) {
goto next_iteration;
} else {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
}
} else {
- return drflac__seek_forward_by_pcm_frames(pFlac, pcmFramesToDecode) == pcmFramesToDecode;
+ return ma_dr_flac__seek_forward_by_pcm_frames(pFlac, pcmFramesToDecode) == pcmFramesToDecode;
}
} else {
if (!isMidFrame) {
- drflac_result result = drflac__seek_to_next_flac_frame(pFlac);
- if (result == DRFLAC_SUCCESS) {
+ ma_result result = ma_dr_flac__seek_to_next_flac_frame(pFlac);
+ if (result == MA_SUCCESS) {
runningPCMFrameCount += pcmFrameCountInThisFLACFrame;
} else {
- if (result == DRFLAC_CRC_MISMATCH) {
+ if (result == MA_CRC_MISMATCH) {
goto next_iteration;
} else {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
}
} else {
runningPCMFrameCount += pFlac->currentFLACFrame.pcmFramesRemaining;
pFlac->currentFLACFrame.pcmFramesRemaining = 0;
- isMidFrame = DRFLAC_FALSE;
+ isMidFrame = MA_FALSE;
}
if (pcmFrameIndex == pFlac->totalPCMFrameCount && runningPCMFrameCount == pFlac->totalPCMFrameCount) {
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
}
next_iteration:
- if (!drflac__read_next_flac_frame_header(&pFlac->bs, pFlac->bitsPerSample, &pFlac->currentFLACFrame.header)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_next_flac_frame_header(&pFlac->bs, pFlac->bitsPerSample, &pFlac->currentFLACFrame.header)) {
+ return MA_FALSE;
}
}
}
-#if !defined(DR_FLAC_NO_CRC)
-#define DRFLAC_BINARY_SEARCH_APPROX_COMPRESSION_RATIO 0.6f
-static drflac_bool32 drflac__seek_to_approximate_flac_frame_to_byte(drflac* pFlac, drflac_uint64 targetByte, drflac_uint64 rangeLo, drflac_uint64 rangeHi, drflac_uint64* pLastSuccessfulSeekOffset)
+#if !defined(MA_DR_FLAC_NO_CRC)
+#define MA_DR_FLAC_BINARY_SEARCH_APPROX_COMPRESSION_RATIO 0.6f
+static ma_bool32 ma_dr_flac__seek_to_approximate_flac_frame_to_byte(ma_dr_flac* pFlac, ma_uint64 targetByte, ma_uint64 rangeLo, ma_uint64 rangeHi, ma_uint64* pLastSuccessfulSeekOffset)
{
- DRFLAC_ASSERT(pFlac != NULL);
- DRFLAC_ASSERT(pLastSuccessfulSeekOffset != NULL);
- DRFLAC_ASSERT(targetByte >= rangeLo);
- DRFLAC_ASSERT(targetByte <= rangeHi);
+ MA_DR_FLAC_ASSERT(pFlac != NULL);
+ MA_DR_FLAC_ASSERT(pLastSuccessfulSeekOffset != NULL);
+ MA_DR_FLAC_ASSERT(targetByte >= rangeLo);
+ MA_DR_FLAC_ASSERT(targetByte <= rangeHi);
*pLastSuccessfulSeekOffset = pFlac->firstFLACFramePosInBytes;
for (;;) {
- drflac_uint64 lastTargetByte = targetByte;
- if (!drflac__seek_to_byte(&pFlac->bs, targetByte)) {
+ ma_uint64 lastTargetByte = targetByte;
+ if (!ma_dr_flac__seek_to_byte(&pFlac->bs, targetByte)) {
if (targetByte == 0) {
- drflac__seek_to_first_frame(pFlac);
- return DRFLAC_FALSE;
+ ma_dr_flac__seek_to_first_frame(pFlac);
+ return MA_FALSE;
}
targetByte = rangeLo + ((rangeHi - rangeLo)/2);
rangeHi = targetByte;
} else {
- DRFLAC_ZERO_MEMORY(&pFlac->currentFLACFrame, sizeof(pFlac->currentFLACFrame));
+ MA_DR_FLAC_ZERO_MEMORY(&pFlac->currentFLACFrame, sizeof(pFlac->currentFLACFrame));
#if 1
- if (!drflac__read_and_decode_next_flac_frame(pFlac)) {
+ if (!ma_dr_flac__read_and_decode_next_flac_frame(pFlac)) {
targetByte = rangeLo + ((rangeHi - rangeLo)/2);
rangeHi = targetByte;
} else {
break;
}
#else
- if (!drflac__read_next_flac_frame_header(&pFlac->bs, pFlac->bitsPerSample, &pFlac->currentFLACFrame.header)) {
+ if (!ma_dr_flac__read_next_flac_frame_header(&pFlac->bs, pFlac->bitsPerSample, &pFlac->currentFLACFrame.header)) {
targetByte = rangeLo + ((rangeHi - rangeLo)/2);
rangeHi = targetByte;
} else {
@@ -83076,48 +85508,48 @@ static drflac_bool32 drflac__seek_to_approximate_flac_frame_to_byte(drflac* pFla
#endif
}
if(targetByte == lastTargetByte) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
}
- drflac__get_pcm_frame_range_of_current_flac_frame(pFlac, &pFlac->currentPCMFrame, NULL);
- DRFLAC_ASSERT(targetByte <= rangeHi);
+ ma_dr_flac__get_pcm_frame_range_of_current_flac_frame(pFlac, &pFlac->currentPCMFrame, NULL);
+ MA_DR_FLAC_ASSERT(targetByte <= rangeHi);
*pLastSuccessfulSeekOffset = targetByte;
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
-static drflac_bool32 drflac__decode_flac_frame_and_seek_forward_by_pcm_frames(drflac* pFlac, drflac_uint64 offset)
+static ma_bool32 ma_dr_flac__decode_flac_frame_and_seek_forward_by_pcm_frames(ma_dr_flac* pFlac, ma_uint64 offset)
{
#if 0
- if (drflac__decode_flac_frame(pFlac) != DRFLAC_SUCCESS) {
- if (drflac__read_and_decode_next_flac_frame(pFlac) == DRFLAC_FALSE) {
- return DRFLAC_FALSE;
+ if (ma_dr_flac__decode_flac_frame(pFlac) != MA_SUCCESS) {
+ if (ma_dr_flac__read_and_decode_next_flac_frame(pFlac) == MA_FALSE) {
+ return MA_FALSE;
}
}
#endif
- return drflac__seek_forward_by_pcm_frames(pFlac, offset) == offset;
+ return ma_dr_flac__seek_forward_by_pcm_frames(pFlac, offset) == offset;
}
-static drflac_bool32 drflac__seek_to_pcm_frame__binary_search_internal(drflac* pFlac, drflac_uint64 pcmFrameIndex, drflac_uint64 byteRangeLo, drflac_uint64 byteRangeHi)
+static ma_bool32 ma_dr_flac__seek_to_pcm_frame__binary_search_internal(ma_dr_flac* pFlac, ma_uint64 pcmFrameIndex, ma_uint64 byteRangeLo, ma_uint64 byteRangeHi)
{
- drflac_uint64 targetByte;
- drflac_uint64 pcmRangeLo = pFlac->totalPCMFrameCount;
- drflac_uint64 pcmRangeHi = 0;
- drflac_uint64 lastSuccessfulSeekOffset = (drflac_uint64)-1;
- drflac_uint64 closestSeekOffsetBeforeTargetPCMFrame = byteRangeLo;
- drflac_uint32 seekForwardThreshold = (pFlac->maxBlockSizeInPCMFrames != 0) ? pFlac->maxBlockSizeInPCMFrames*2 : 4096;
- targetByte = byteRangeLo + (drflac_uint64)(((drflac_int64)((pcmFrameIndex - pFlac->currentPCMFrame) * pFlac->channels * pFlac->bitsPerSample)/8.0f) * DRFLAC_BINARY_SEARCH_APPROX_COMPRESSION_RATIO);
+ ma_uint64 targetByte;
+ ma_uint64 pcmRangeLo = pFlac->totalPCMFrameCount;
+ ma_uint64 pcmRangeHi = 0;
+ ma_uint64 lastSuccessfulSeekOffset = (ma_uint64)-1;
+ ma_uint64 closestSeekOffsetBeforeTargetPCMFrame = byteRangeLo;
+ ma_uint32 seekForwardThreshold = (pFlac->maxBlockSizeInPCMFrames != 0) ? pFlac->maxBlockSizeInPCMFrames*2 : 4096;
+ targetByte = byteRangeLo + (ma_uint64)(((ma_int64)((pcmFrameIndex - pFlac->currentPCMFrame) * pFlac->channels * pFlac->bitsPerSample)/8.0f) * MA_DR_FLAC_BINARY_SEARCH_APPROX_COMPRESSION_RATIO);
if (targetByte > byteRangeHi) {
targetByte = byteRangeHi;
}
for (;;) {
- if (drflac__seek_to_approximate_flac_frame_to_byte(pFlac, targetByte, byteRangeLo, byteRangeHi, &lastSuccessfulSeekOffset)) {
- drflac_uint64 newPCMRangeLo;
- drflac_uint64 newPCMRangeHi;
- drflac__get_pcm_frame_range_of_current_flac_frame(pFlac, &newPCMRangeLo, &newPCMRangeHi);
+ if (ma_dr_flac__seek_to_approximate_flac_frame_to_byte(pFlac, targetByte, byteRangeLo, byteRangeHi, &lastSuccessfulSeekOffset)) {
+ ma_uint64 newPCMRangeLo;
+ ma_uint64 newPCMRangeHi;
+ ma_dr_flac__get_pcm_frame_range_of_current_flac_frame(pFlac, &newPCMRangeLo, &newPCMRangeHi);
if (pcmRangeLo == newPCMRangeLo) {
- if (!drflac__seek_to_approximate_flac_frame_to_byte(pFlac, closestSeekOffsetBeforeTargetPCMFrame, closestSeekOffsetBeforeTargetPCMFrame, byteRangeHi, &lastSuccessfulSeekOffset)) {
+ if (!ma_dr_flac__seek_to_approximate_flac_frame_to_byte(pFlac, closestSeekOffsetBeforeTargetPCMFrame, closestSeekOffsetBeforeTargetPCMFrame, byteRangeHi, &lastSuccessfulSeekOffset)) {
break;
}
- if (drflac__decode_flac_frame_and_seek_forward_by_pcm_frames(pFlac, pcmFrameIndex - pFlac->currentPCMFrame)) {
- return DRFLAC_TRUE;
+ if (ma_dr_flac__decode_flac_frame_and_seek_forward_by_pcm_frames(pFlac, pcmFrameIndex - pFlac->currentPCMFrame)) {
+ return MA_TRUE;
} else {
break;
}
@@ -83125,13 +85557,13 @@ static drflac_bool32 drflac__seek_to_pcm_frame__binary_search_internal(drflac* p
pcmRangeLo = newPCMRangeLo;
pcmRangeHi = newPCMRangeHi;
if (pcmRangeLo <= pcmFrameIndex && pcmRangeHi >= pcmFrameIndex) {
- if (drflac__decode_flac_frame_and_seek_forward_by_pcm_frames(pFlac, pcmFrameIndex - pFlac->currentPCMFrame) ) {
- return DRFLAC_TRUE;
+ if (ma_dr_flac__decode_flac_frame_and_seek_forward_by_pcm_frames(pFlac, pcmFrameIndex - pFlac->currentPCMFrame) ) {
+ return MA_TRUE;
} else {
break;
}
} else {
- const float approxCompressionRatio = (drflac_int64)(lastSuccessfulSeekOffset - pFlac->firstFLACFramePosInBytes) / ((drflac_int64)(pcmRangeLo * pFlac->channels * pFlac->bitsPerSample)/8.0f);
+ const float approxCompressionRatio = (ma_int64)(lastSuccessfulSeekOffset - pFlac->firstFLACFramePosInBytes) / ((ma_int64)(pcmRangeLo * pFlac->channels * pFlac->bitsPerSample)/8.0f);
if (pcmRangeLo > pcmFrameIndex) {
byteRangeHi = lastSuccessfulSeekOffset;
if (byteRangeLo > byteRangeHi) {
@@ -83143,8 +85575,8 @@ static drflac_bool32 drflac__seek_to_pcm_frame__binary_search_internal(drflac* p
}
} else {
if ((pcmFrameIndex - pcmRangeLo) < seekForwardThreshold) {
- if (drflac__decode_flac_frame_and_seek_forward_by_pcm_frames(pFlac, pcmFrameIndex - pFlac->currentPCMFrame)) {
- return DRFLAC_TRUE;
+ if (ma_dr_flac__decode_flac_frame_and_seek_forward_by_pcm_frames(pFlac, pcmFrameIndex - pFlac->currentPCMFrame)) {
+ return MA_TRUE;
} else {
break;
}
@@ -83153,7 +85585,7 @@ static drflac_bool32 drflac__seek_to_pcm_frame__binary_search_internal(drflac* p
if (byteRangeHi < byteRangeLo) {
byteRangeHi = byteRangeLo;
}
- targetByte = lastSuccessfulSeekOffset + (drflac_uint64)(((drflac_int64)((pcmFrameIndex-pcmRangeLo) * pFlac->channels * pFlac->bitsPerSample)/8.0f) * approxCompressionRatio);
+ targetByte = lastSuccessfulSeekOffset + (ma_uint64)(((ma_int64)((pcmFrameIndex-pcmRangeLo) * pFlac->channels * pFlac->bitsPerSample)/8.0f) * approxCompressionRatio);
if (targetByte > byteRangeHi) {
targetByte = byteRangeHi;
}
@@ -83167,37 +85599,37 @@ static drflac_bool32 drflac__seek_to_pcm_frame__binary_search_internal(drflac* p
break;
}
}
- drflac__seek_to_first_frame(pFlac);
- return DRFLAC_FALSE;
+ ma_dr_flac__seek_to_first_frame(pFlac);
+ return MA_FALSE;
}
-static drflac_bool32 drflac__seek_to_pcm_frame__binary_search(drflac* pFlac, drflac_uint64 pcmFrameIndex)
+static ma_bool32 ma_dr_flac__seek_to_pcm_frame__binary_search(ma_dr_flac* pFlac, ma_uint64 pcmFrameIndex)
{
- drflac_uint64 byteRangeLo;
- drflac_uint64 byteRangeHi;
- drflac_uint32 seekForwardThreshold = (pFlac->maxBlockSizeInPCMFrames != 0) ? pFlac->maxBlockSizeInPCMFrames*2 : 4096;
- if (drflac__seek_to_first_frame(pFlac) == DRFLAC_FALSE) {
- return DRFLAC_FALSE;
+ ma_uint64 byteRangeLo;
+ ma_uint64 byteRangeHi;
+ ma_uint32 seekForwardThreshold = (pFlac->maxBlockSizeInPCMFrames != 0) ? pFlac->maxBlockSizeInPCMFrames*2 : 4096;
+ if (ma_dr_flac__seek_to_first_frame(pFlac) == MA_FALSE) {
+ return MA_FALSE;
}
if (pcmFrameIndex < seekForwardThreshold) {
- return drflac__seek_forward_by_pcm_frames(pFlac, pcmFrameIndex) == pcmFrameIndex;
+ return ma_dr_flac__seek_forward_by_pcm_frames(pFlac, pcmFrameIndex) == pcmFrameIndex;
}
byteRangeLo = pFlac->firstFLACFramePosInBytes;
- byteRangeHi = pFlac->firstFLACFramePosInBytes + (drflac_uint64)((drflac_int64)(pFlac->totalPCMFrameCount * pFlac->channels * pFlac->bitsPerSample)/8.0f);
- return drflac__seek_to_pcm_frame__binary_search_internal(pFlac, pcmFrameIndex, byteRangeLo, byteRangeHi);
+ byteRangeHi = pFlac->firstFLACFramePosInBytes + (ma_uint64)((ma_int64)(pFlac->totalPCMFrameCount * pFlac->channels * pFlac->bitsPerSample)/8.0f);
+ return ma_dr_flac__seek_to_pcm_frame__binary_search_internal(pFlac, pcmFrameIndex, byteRangeLo, byteRangeHi);
}
#endif
-static drflac_bool32 drflac__seek_to_pcm_frame__seek_table(drflac* pFlac, drflac_uint64 pcmFrameIndex)
+static ma_bool32 ma_dr_flac__seek_to_pcm_frame__seek_table(ma_dr_flac* pFlac, ma_uint64 pcmFrameIndex)
{
- drflac_uint32 iClosestSeekpoint = 0;
- drflac_bool32 isMidFrame = DRFLAC_FALSE;
- drflac_uint64 runningPCMFrameCount;
- drflac_uint32 iSeekpoint;
- DRFLAC_ASSERT(pFlac != NULL);
+ ma_uint32 iClosestSeekpoint = 0;
+ ma_bool32 isMidFrame = MA_FALSE;
+ ma_uint64 runningPCMFrameCount;
+ ma_uint32 iSeekpoint;
+ MA_DR_FLAC_ASSERT(pFlac != NULL);
if (pFlac->pSeekpoints == NULL || pFlac->seekpointCount == 0) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
if (pFlac->pSeekpoints[0].firstPCMFrame > pcmFrameIndex) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
for (iSeekpoint = 0; iSeekpoint < pFlac->seekpointCount; ++iSeekpoint) {
if (pFlac->pSeekpoints[iSeekpoint].firstPCMFrame >= pcmFrameIndex) {
@@ -83206,31 +85638,31 @@ static drflac_bool32 drflac__seek_to_pcm_frame__seek_table(drflac* pFlac, drflac
iClosestSeekpoint = iSeekpoint;
}
if (pFlac->pSeekpoints[iClosestSeekpoint].pcmFrameCount == 0 || pFlac->pSeekpoints[iClosestSeekpoint].pcmFrameCount > pFlac->maxBlockSizeInPCMFrames) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
if (pFlac->pSeekpoints[iClosestSeekpoint].firstPCMFrame > pFlac->totalPCMFrameCount && pFlac->totalPCMFrameCount > 0) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
-#if !defined(DR_FLAC_NO_CRC)
+#if !defined(MA_DR_FLAC_NO_CRC)
if (pFlac->totalPCMFrameCount > 0) {
- drflac_uint64 byteRangeLo;
- drflac_uint64 byteRangeHi;
- byteRangeHi = pFlac->firstFLACFramePosInBytes + (drflac_uint64)((drflac_int64)(pFlac->totalPCMFrameCount * pFlac->channels * pFlac->bitsPerSample)/8.0f);
+ ma_uint64 byteRangeLo;
+ ma_uint64 byteRangeHi;
+ byteRangeHi = pFlac->firstFLACFramePosInBytes + (ma_uint64)((ma_int64)(pFlac->totalPCMFrameCount * pFlac->channels * pFlac->bitsPerSample)/8.0f);
byteRangeLo = pFlac->firstFLACFramePosInBytes + pFlac->pSeekpoints[iClosestSeekpoint].flacFrameOffset;
if (iClosestSeekpoint < pFlac->seekpointCount-1) {
- drflac_uint32 iNextSeekpoint = iClosestSeekpoint + 1;
+ ma_uint32 iNextSeekpoint = iClosestSeekpoint + 1;
if (pFlac->pSeekpoints[iClosestSeekpoint].flacFrameOffset >= pFlac->pSeekpoints[iNextSeekpoint].flacFrameOffset || pFlac->pSeekpoints[iNextSeekpoint].pcmFrameCount == 0) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
- if (pFlac->pSeekpoints[iNextSeekpoint].firstPCMFrame != (((drflac_uint64)0xFFFFFFFF << 32) | 0xFFFFFFFF)) {
+ if (pFlac->pSeekpoints[iNextSeekpoint].firstPCMFrame != (((ma_uint64)0xFFFFFFFF << 32) | 0xFFFFFFFF)) {
byteRangeHi = pFlac->firstFLACFramePosInBytes + pFlac->pSeekpoints[iNextSeekpoint].flacFrameOffset - 1;
}
}
- if (drflac__seek_to_byte(&pFlac->bs, pFlac->firstFLACFramePosInBytes + pFlac->pSeekpoints[iClosestSeekpoint].flacFrameOffset)) {
- if (drflac__read_next_flac_frame_header(&pFlac->bs, pFlac->bitsPerSample, &pFlac->currentFLACFrame.header)) {
- drflac__get_pcm_frame_range_of_current_flac_frame(pFlac, &pFlac->currentPCMFrame, NULL);
- if (drflac__seek_to_pcm_frame__binary_search_internal(pFlac, pcmFrameIndex, byteRangeLo, byteRangeHi)) {
- return DRFLAC_TRUE;
+ if (ma_dr_flac__seek_to_byte(&pFlac->bs, pFlac->firstFLACFramePosInBytes + pFlac->pSeekpoints[iClosestSeekpoint].flacFrameOffset)) {
+ if (ma_dr_flac__read_next_flac_frame_header(&pFlac->bs, pFlac->bitsPerSample, &pFlac->currentFLACFrame.header)) {
+ ma_dr_flac__get_pcm_frame_range_of_current_flac_frame(pFlac, &pFlac->currentPCMFrame, NULL);
+ if (ma_dr_flac__seek_to_pcm_frame__binary_search_internal(pFlac, pcmFrameIndex, byteRangeLo, byteRangeHi)) {
+ return MA_TRUE;
}
}
}
@@ -83239,173 +85671,173 @@ static drflac_bool32 drflac__seek_to_pcm_frame__seek_table(drflac* pFlac, drflac
if (pcmFrameIndex >= pFlac->currentPCMFrame && pFlac->pSeekpoints[iClosestSeekpoint].firstPCMFrame <= pFlac->currentPCMFrame) {
runningPCMFrameCount = pFlac->currentPCMFrame;
if (pFlac->currentPCMFrame == 0 && pFlac->currentFLACFrame.pcmFramesRemaining == 0) {
- if (!drflac__read_next_flac_frame_header(&pFlac->bs, pFlac->bitsPerSample, &pFlac->currentFLACFrame.header)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_next_flac_frame_header(&pFlac->bs, pFlac->bitsPerSample, &pFlac->currentFLACFrame.header)) {
+ return MA_FALSE;
}
} else {
- isMidFrame = DRFLAC_TRUE;
+ isMidFrame = MA_TRUE;
}
} else {
runningPCMFrameCount = pFlac->pSeekpoints[iClosestSeekpoint].firstPCMFrame;
- if (!drflac__seek_to_byte(&pFlac->bs, pFlac->firstFLACFramePosInBytes + pFlac->pSeekpoints[iClosestSeekpoint].flacFrameOffset)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__seek_to_byte(&pFlac->bs, pFlac->firstFLACFramePosInBytes + pFlac->pSeekpoints[iClosestSeekpoint].flacFrameOffset)) {
+ return MA_FALSE;
}
- if (!drflac__read_next_flac_frame_header(&pFlac->bs, pFlac->bitsPerSample, &pFlac->currentFLACFrame.header)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_next_flac_frame_header(&pFlac->bs, pFlac->bitsPerSample, &pFlac->currentFLACFrame.header)) {
+ return MA_FALSE;
}
}
for (;;) {
- drflac_uint64 pcmFrameCountInThisFLACFrame;
- drflac_uint64 firstPCMFrameInFLACFrame = 0;
- drflac_uint64 lastPCMFrameInFLACFrame = 0;
- drflac__get_pcm_frame_range_of_current_flac_frame(pFlac, &firstPCMFrameInFLACFrame, &lastPCMFrameInFLACFrame);
+ ma_uint64 pcmFrameCountInThisFLACFrame;
+ ma_uint64 firstPCMFrameInFLACFrame = 0;
+ ma_uint64 lastPCMFrameInFLACFrame = 0;
+ ma_dr_flac__get_pcm_frame_range_of_current_flac_frame(pFlac, &firstPCMFrameInFLACFrame, &lastPCMFrameInFLACFrame);
pcmFrameCountInThisFLACFrame = (lastPCMFrameInFLACFrame - firstPCMFrameInFLACFrame) + 1;
if (pcmFrameIndex < (runningPCMFrameCount + pcmFrameCountInThisFLACFrame)) {
- drflac_uint64 pcmFramesToDecode = pcmFrameIndex - runningPCMFrameCount;
+ ma_uint64 pcmFramesToDecode = pcmFrameIndex - runningPCMFrameCount;
if (!isMidFrame) {
- drflac_result result = drflac__decode_flac_frame(pFlac);
- if (result == DRFLAC_SUCCESS) {
- return drflac__seek_forward_by_pcm_frames(pFlac, pcmFramesToDecode) == pcmFramesToDecode;
+ ma_result result = ma_dr_flac__decode_flac_frame(pFlac);
+ if (result == MA_SUCCESS) {
+ return ma_dr_flac__seek_forward_by_pcm_frames(pFlac, pcmFramesToDecode) == pcmFramesToDecode;
} else {
- if (result == DRFLAC_CRC_MISMATCH) {
+ if (result == MA_CRC_MISMATCH) {
goto next_iteration;
} else {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
}
} else {
- return drflac__seek_forward_by_pcm_frames(pFlac, pcmFramesToDecode) == pcmFramesToDecode;
+ return ma_dr_flac__seek_forward_by_pcm_frames(pFlac, pcmFramesToDecode) == pcmFramesToDecode;
}
} else {
if (!isMidFrame) {
- drflac_result result = drflac__seek_to_next_flac_frame(pFlac);
- if (result == DRFLAC_SUCCESS) {
+ ma_result result = ma_dr_flac__seek_to_next_flac_frame(pFlac);
+ if (result == MA_SUCCESS) {
runningPCMFrameCount += pcmFrameCountInThisFLACFrame;
} else {
- if (result == DRFLAC_CRC_MISMATCH) {
+ if (result == MA_CRC_MISMATCH) {
goto next_iteration;
} else {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
}
} else {
runningPCMFrameCount += pFlac->currentFLACFrame.pcmFramesRemaining;
pFlac->currentFLACFrame.pcmFramesRemaining = 0;
- isMidFrame = DRFLAC_FALSE;
+ isMidFrame = MA_FALSE;
}
if (pcmFrameIndex == pFlac->totalPCMFrameCount && runningPCMFrameCount == pFlac->totalPCMFrameCount) {
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
}
next_iteration:
- if (!drflac__read_next_flac_frame_header(&pFlac->bs, pFlac->bitsPerSample, &pFlac->currentFLACFrame.header)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__read_next_flac_frame_header(&pFlac->bs, pFlac->bitsPerSample, &pFlac->currentFLACFrame.header)) {
+ return MA_FALSE;
}
}
}
-#ifndef DR_FLAC_NO_OGG
+#ifndef MA_DR_FLAC_NO_OGG
typedef struct
{
- drflac_uint8 capturePattern[4];
- drflac_uint8 structureVersion;
- drflac_uint8 headerType;
- drflac_uint64 granulePosition;
- drflac_uint32 serialNumber;
- drflac_uint32 sequenceNumber;
- drflac_uint32 checksum;
- drflac_uint8 segmentCount;
- drflac_uint8 segmentTable[255];
-} drflac_ogg_page_header;
+ ma_uint8 capturePattern[4];
+ ma_uint8 structureVersion;
+ ma_uint8 headerType;
+ ma_uint64 granulePosition;
+ ma_uint32 serialNumber;
+ ma_uint32 sequenceNumber;
+ ma_uint32 checksum;
+ ma_uint8 segmentCount;
+ ma_uint8 segmentTable[255];
+} ma_dr_flac_ogg_page_header;
#endif
typedef struct
{
- drflac_read_proc onRead;
- drflac_seek_proc onSeek;
- drflac_meta_proc onMeta;
- drflac_container container;
+ ma_dr_flac_read_proc onRead;
+ ma_dr_flac_seek_proc onSeek;
+ ma_dr_flac_meta_proc onMeta;
+ ma_dr_flac_container container;
void* pUserData;
void* pUserDataMD;
- drflac_uint32 sampleRate;
- drflac_uint8 channels;
- drflac_uint8 bitsPerSample;
- drflac_uint64 totalPCMFrameCount;
- drflac_uint16 maxBlockSizeInPCMFrames;
- drflac_uint64 runningFilePos;
- drflac_bool32 hasStreamInfoBlock;
- drflac_bool32 hasMetadataBlocks;
- drflac_bs bs;
- drflac_frame_header firstFrameHeader;
-#ifndef DR_FLAC_NO_OGG
- drflac_uint32 oggSerial;
- drflac_uint64 oggFirstBytePos;
- drflac_ogg_page_header oggBosHeader;
-#endif
-} drflac_init_info;
-static DRFLAC_INLINE void drflac__decode_block_header(drflac_uint32 blockHeader, drflac_uint8* isLastBlock, drflac_uint8* blockType, drflac_uint32* blockSize)
-{
- blockHeader = drflac__be2host_32(blockHeader);
- *isLastBlock = (drflac_uint8)((blockHeader & 0x80000000UL) >> 31);
- *blockType = (drflac_uint8)((blockHeader & 0x7F000000UL) >> 24);
+ ma_uint32 sampleRate;
+ ma_uint8 channels;
+ ma_uint8 bitsPerSample;
+ ma_uint64 totalPCMFrameCount;
+ ma_uint16 maxBlockSizeInPCMFrames;
+ ma_uint64 runningFilePos;
+ ma_bool32 hasStreamInfoBlock;
+ ma_bool32 hasMetadataBlocks;
+ ma_dr_flac_bs bs;
+ ma_dr_flac_frame_header firstFrameHeader;
+#ifndef MA_DR_FLAC_NO_OGG
+ ma_uint32 oggSerial;
+ ma_uint64 oggFirstBytePos;
+ ma_dr_flac_ogg_page_header oggBosHeader;
+#endif
+} ma_dr_flac_init_info;
+static MA_INLINE void ma_dr_flac__decode_block_header(ma_uint32 blockHeader, ma_uint8* isLastBlock, ma_uint8* blockType, ma_uint32* blockSize)
+{
+ blockHeader = ma_dr_flac__be2host_32(blockHeader);
+ *isLastBlock = (ma_uint8)((blockHeader & 0x80000000UL) >> 31);
+ *blockType = (ma_uint8)((blockHeader & 0x7F000000UL) >> 24);
*blockSize = (blockHeader & 0x00FFFFFFUL);
}
-static DRFLAC_INLINE drflac_bool32 drflac__read_and_decode_block_header(drflac_read_proc onRead, void* pUserData, drflac_uint8* isLastBlock, drflac_uint8* blockType, drflac_uint32* blockSize)
+static MA_INLINE ma_bool32 ma_dr_flac__read_and_decode_block_header(ma_dr_flac_read_proc onRead, void* pUserData, ma_uint8* isLastBlock, ma_uint8* blockType, ma_uint32* blockSize)
{
- drflac_uint32 blockHeader;
+ ma_uint32 blockHeader;
*blockSize = 0;
if (onRead(pUserData, &blockHeader, 4) != 4) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
- drflac__decode_block_header(blockHeader, isLastBlock, blockType, blockSize);
- return DRFLAC_TRUE;
+ ma_dr_flac__decode_block_header(blockHeader, isLastBlock, blockType, blockSize);
+ return MA_TRUE;
}
-static drflac_bool32 drflac__read_streaminfo(drflac_read_proc onRead, void* pUserData, drflac_streaminfo* pStreamInfo)
+static ma_bool32 ma_dr_flac__read_streaminfo(ma_dr_flac_read_proc onRead, void* pUserData, ma_dr_flac_streaminfo* pStreamInfo)
{
- drflac_uint32 blockSizes;
- drflac_uint64 frameSizes = 0;
- drflac_uint64 importantProps;
- drflac_uint8 md5[16];
+ ma_uint32 blockSizes;
+ ma_uint64 frameSizes = 0;
+ ma_uint64 importantProps;
+ ma_uint8 md5[16];
if (onRead(pUserData, &blockSizes, 4) != 4) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
if (onRead(pUserData, &frameSizes, 6) != 6) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
if (onRead(pUserData, &importantProps, 8) != 8) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
if (onRead(pUserData, md5, sizeof(md5)) != sizeof(md5)) {
- return DRFLAC_FALSE;
- }
- blockSizes = drflac__be2host_32(blockSizes);
- frameSizes = drflac__be2host_64(frameSizes);
- importantProps = drflac__be2host_64(importantProps);
- pStreamInfo->minBlockSizeInPCMFrames = (drflac_uint16)((blockSizes & 0xFFFF0000) >> 16);
- pStreamInfo->maxBlockSizeInPCMFrames = (drflac_uint16) (blockSizes & 0x0000FFFF);
- pStreamInfo->minFrameSizeInPCMFrames = (drflac_uint32)((frameSizes & (((drflac_uint64)0x00FFFFFF << 16) << 24)) >> 40);
- pStreamInfo->maxFrameSizeInPCMFrames = (drflac_uint32)((frameSizes & (((drflac_uint64)0x00FFFFFF << 16) << 0)) >> 16);
- pStreamInfo->sampleRate = (drflac_uint32)((importantProps & (((drflac_uint64)0x000FFFFF << 16) << 28)) >> 44);
- pStreamInfo->channels = (drflac_uint8 )((importantProps & (((drflac_uint64)0x0000000E << 16) << 24)) >> 41) + 1;
- pStreamInfo->bitsPerSample = (drflac_uint8 )((importantProps & (((drflac_uint64)0x0000001F << 16) << 20)) >> 36) + 1;
- pStreamInfo->totalPCMFrameCount = ((importantProps & ((((drflac_uint64)0x0000000F << 16) << 16) | 0xFFFFFFFF)));
- DRFLAC_COPY_MEMORY(pStreamInfo->md5, md5, sizeof(md5));
- return DRFLAC_TRUE;
-}
-static void* drflac__malloc_default(size_t sz, void* pUserData)
+ return MA_FALSE;
+ }
+ blockSizes = ma_dr_flac__be2host_32(blockSizes);
+ frameSizes = ma_dr_flac__be2host_64(frameSizes);
+ importantProps = ma_dr_flac__be2host_64(importantProps);
+ pStreamInfo->minBlockSizeInPCMFrames = (ma_uint16)((blockSizes & 0xFFFF0000) >> 16);
+ pStreamInfo->maxBlockSizeInPCMFrames = (ma_uint16) (blockSizes & 0x0000FFFF);
+ pStreamInfo->minFrameSizeInPCMFrames = (ma_uint32)((frameSizes & (((ma_uint64)0x00FFFFFF << 16) << 24)) >> 40);
+ pStreamInfo->maxFrameSizeInPCMFrames = (ma_uint32)((frameSizes & (((ma_uint64)0x00FFFFFF << 16) << 0)) >> 16);
+ pStreamInfo->sampleRate = (ma_uint32)((importantProps & (((ma_uint64)0x000FFFFF << 16) << 28)) >> 44);
+ pStreamInfo->channels = (ma_uint8 )((importantProps & (((ma_uint64)0x0000000E << 16) << 24)) >> 41) + 1;
+ pStreamInfo->bitsPerSample = (ma_uint8 )((importantProps & (((ma_uint64)0x0000001F << 16) << 20)) >> 36) + 1;
+ pStreamInfo->totalPCMFrameCount = ((importantProps & ((((ma_uint64)0x0000000F << 16) << 16) | 0xFFFFFFFF)));
+ MA_DR_FLAC_COPY_MEMORY(pStreamInfo->md5, md5, sizeof(md5));
+ return MA_TRUE;
+}
+static void* ma_dr_flac__malloc_default(size_t sz, void* pUserData)
{
(void)pUserData;
- return DRFLAC_MALLOC(sz);
+ return MA_DR_FLAC_MALLOC(sz);
}
-static void* drflac__realloc_default(void* p, size_t sz, void* pUserData)
+static void* ma_dr_flac__realloc_default(void* p, size_t sz, void* pUserData)
{
(void)pUserData;
- return DRFLAC_REALLOC(p, sz);
+ return MA_DR_FLAC_REALLOC(p, sz);
}
-static void drflac__free_default(void* p, void* pUserData)
+static void ma_dr_flac__free_default(void* p, void* pUserData)
{
(void)pUserData;
- DRFLAC_FREE(p);
+ MA_DR_FLAC_FREE(p);
}
-static void* drflac__malloc_from_callbacks(size_t sz, const drflac_allocation_callbacks* pAllocationCallbacks)
+static void* ma_dr_flac__malloc_from_callbacks(size_t sz, const ma_allocation_callbacks* pAllocationCallbacks)
{
if (pAllocationCallbacks == NULL) {
return NULL;
@@ -83418,7 +85850,7 @@ static void* drflac__malloc_from_callbacks(size_t sz, const drflac_allocation_ca
}
return NULL;
}
-static void* drflac__realloc_from_callbacks(void* p, size_t szNew, size_t szOld, const drflac_allocation_callbacks* pAllocationCallbacks)
+static void* ma_dr_flac__realloc_from_callbacks(void* p, size_t szNew, size_t szOld, const ma_allocation_callbacks* pAllocationCallbacks)
{
if (pAllocationCallbacks == NULL) {
return NULL;
@@ -83433,14 +85865,14 @@ static void* drflac__realloc_from_callbacks(void* p, size_t szNew, size_t szOld,
return NULL;
}
if (p != NULL) {
- DRFLAC_COPY_MEMORY(p2, p, szOld);
+ MA_DR_FLAC_COPY_MEMORY(p2, p, szOld);
pAllocationCallbacks->onFree(p, pAllocationCallbacks->pUserData);
}
return p2;
}
return NULL;
}
-static void drflac__free_from_callbacks(void* p, const drflac_allocation_callbacks* pAllocationCallbacks)
+static void ma_dr_flac__free_from_callbacks(void* p, const ma_allocation_callbacks* pAllocationCallbacks)
{
if (p == NULL || pAllocationCallbacks == NULL) {
return;
@@ -83449,18 +85881,18 @@ static void drflac__free_from_callbacks(void* p, const drflac_allocation_callbac
pAllocationCallbacks->onFree(p, pAllocationCallbacks->pUserData);
}
}
-static drflac_bool32 drflac__read_and_decode_metadata(drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_meta_proc onMeta, void* pUserData, void* pUserDataMD, drflac_uint64* pFirstFramePos, drflac_uint64* pSeektablePos, drflac_uint32* pSeekpointCount, drflac_allocation_callbacks* pAllocationCallbacks)
+static ma_bool32 ma_dr_flac__read_and_decode_metadata(ma_dr_flac_read_proc onRead, ma_dr_flac_seek_proc onSeek, ma_dr_flac_meta_proc onMeta, void* pUserData, void* pUserDataMD, ma_uint64* pFirstFramePos, ma_uint64* pSeektablePos, ma_uint32* pSeekpointCount, ma_allocation_callbacks* pAllocationCallbacks)
{
- drflac_uint64 runningFilePos = 42;
- drflac_uint64 seektablePos = 0;
- drflac_uint32 seektableSize = 0;
+ ma_uint64 runningFilePos = 42;
+ ma_uint64 seektablePos = 0;
+ ma_uint32 seektableSize = 0;
for (;;) {
- drflac_metadata metadata;
- drflac_uint8 isLastBlock = 0;
- drflac_uint8 blockType;
- drflac_uint32 blockSize;
- if (drflac__read_and_decode_block_header(onRead, pUserData, &isLastBlock, &blockType, &blockSize) == DRFLAC_FALSE) {
- return DRFLAC_FALSE;
+ ma_dr_flac_metadata metadata;
+ ma_uint8 isLastBlock = 0;
+ ma_uint8 blockType = 0;
+ ma_uint32 blockSize;
+ if (ma_dr_flac__read_and_decode_block_header(onRead, pUserData, &isLastBlock, &blockType, &blockSize) == MA_FALSE) {
+ return MA_FALSE;
}
runningFilePos += 4;
metadata.type = blockType;
@@ -83468,159 +85900,159 @@ static drflac_bool32 drflac__read_and_decode_metadata(drflac_read_proc onRead, d
metadata.rawDataSize = 0;
switch (blockType)
{
- case DRFLAC_METADATA_BLOCK_TYPE_APPLICATION:
+ case MA_DR_FLAC_METADATA_BLOCK_TYPE_APPLICATION:
{
if (blockSize < 4) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
if (onMeta) {
- void* pRawData = drflac__malloc_from_callbacks(blockSize, pAllocationCallbacks);
+ void* pRawData = ma_dr_flac__malloc_from_callbacks(blockSize, pAllocationCallbacks);
if (pRawData == NULL) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
if (onRead(pUserData, pRawData, blockSize) != blockSize) {
- drflac__free_from_callbacks(pRawData, pAllocationCallbacks);
- return DRFLAC_FALSE;
+ ma_dr_flac__free_from_callbacks(pRawData, pAllocationCallbacks);
+ return MA_FALSE;
}
metadata.pRawData = pRawData;
metadata.rawDataSize = blockSize;
- metadata.data.application.id = drflac__be2host_32(*(drflac_uint32*)pRawData);
- metadata.data.application.pData = (const void*)((drflac_uint8*)pRawData + sizeof(drflac_uint32));
- metadata.data.application.dataSize = blockSize - sizeof(drflac_uint32);
+ metadata.data.application.id = ma_dr_flac__be2host_32(*(ma_uint32*)pRawData);
+ metadata.data.application.pData = (const void*)((ma_uint8*)pRawData + sizeof(ma_uint32));
+ metadata.data.application.dataSize = blockSize - sizeof(ma_uint32);
onMeta(pUserDataMD, &metadata);
- drflac__free_from_callbacks(pRawData, pAllocationCallbacks);
+ ma_dr_flac__free_from_callbacks(pRawData, pAllocationCallbacks);
}
} break;
- case DRFLAC_METADATA_BLOCK_TYPE_SEEKTABLE:
+ case MA_DR_FLAC_METADATA_BLOCK_TYPE_SEEKTABLE:
{
seektablePos = runningFilePos;
seektableSize = blockSize;
if (onMeta) {
- drflac_uint32 seekpointCount;
- drflac_uint32 iSeekpoint;
+ ma_uint32 seekpointCount;
+ ma_uint32 iSeekpoint;
void* pRawData;
- seekpointCount = blockSize/DRFLAC_SEEKPOINT_SIZE_IN_BYTES;
- pRawData = drflac__malloc_from_callbacks(seekpointCount * sizeof(drflac_seekpoint), pAllocationCallbacks);
+ seekpointCount = blockSize/MA_DR_FLAC_SEEKPOINT_SIZE_IN_BYTES;
+ pRawData = ma_dr_flac__malloc_from_callbacks(seekpointCount * sizeof(ma_dr_flac_seekpoint), pAllocationCallbacks);
if (pRawData == NULL) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
for (iSeekpoint = 0; iSeekpoint < seekpointCount; ++iSeekpoint) {
- drflac_seekpoint* pSeekpoint = (drflac_seekpoint*)pRawData + iSeekpoint;
- if (onRead(pUserData, pSeekpoint, DRFLAC_SEEKPOINT_SIZE_IN_BYTES) != DRFLAC_SEEKPOINT_SIZE_IN_BYTES) {
- drflac__free_from_callbacks(pRawData, pAllocationCallbacks);
- return DRFLAC_FALSE;
+ ma_dr_flac_seekpoint* pSeekpoint = (ma_dr_flac_seekpoint*)pRawData + iSeekpoint;
+ if (onRead(pUserData, pSeekpoint, MA_DR_FLAC_SEEKPOINT_SIZE_IN_BYTES) != MA_DR_FLAC_SEEKPOINT_SIZE_IN_BYTES) {
+ ma_dr_flac__free_from_callbacks(pRawData, pAllocationCallbacks);
+ return MA_FALSE;
}
- pSeekpoint->firstPCMFrame = drflac__be2host_64(pSeekpoint->firstPCMFrame);
- pSeekpoint->flacFrameOffset = drflac__be2host_64(pSeekpoint->flacFrameOffset);
- pSeekpoint->pcmFrameCount = drflac__be2host_16(pSeekpoint->pcmFrameCount);
+ pSeekpoint->firstPCMFrame = ma_dr_flac__be2host_64(pSeekpoint->firstPCMFrame);
+ pSeekpoint->flacFrameOffset = ma_dr_flac__be2host_64(pSeekpoint->flacFrameOffset);
+ pSeekpoint->pcmFrameCount = ma_dr_flac__be2host_16(pSeekpoint->pcmFrameCount);
}
metadata.pRawData = pRawData;
metadata.rawDataSize = blockSize;
metadata.data.seektable.seekpointCount = seekpointCount;
- metadata.data.seektable.pSeekpoints = (const drflac_seekpoint*)pRawData;
+ metadata.data.seektable.pSeekpoints = (const ma_dr_flac_seekpoint*)pRawData;
onMeta(pUserDataMD, &metadata);
- drflac__free_from_callbacks(pRawData, pAllocationCallbacks);
+ ma_dr_flac__free_from_callbacks(pRawData, pAllocationCallbacks);
}
} break;
- case DRFLAC_METADATA_BLOCK_TYPE_VORBIS_COMMENT:
+ case MA_DR_FLAC_METADATA_BLOCK_TYPE_VORBIS_COMMENT:
{
if (blockSize < 8) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
if (onMeta) {
void* pRawData;
const char* pRunningData;
const char* pRunningDataEnd;
- drflac_uint32 i;
- pRawData = drflac__malloc_from_callbacks(blockSize, pAllocationCallbacks);
+ ma_uint32 i;
+ pRawData = ma_dr_flac__malloc_from_callbacks(blockSize, pAllocationCallbacks);
if (pRawData == NULL) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
if (onRead(pUserData, pRawData, blockSize) != blockSize) {
- drflac__free_from_callbacks(pRawData, pAllocationCallbacks);
- return DRFLAC_FALSE;
+ ma_dr_flac__free_from_callbacks(pRawData, pAllocationCallbacks);
+ return MA_FALSE;
}
metadata.pRawData = pRawData;
metadata.rawDataSize = blockSize;
pRunningData = (const char*)pRawData;
pRunningDataEnd = (const char*)pRawData + blockSize;
- metadata.data.vorbis_comment.vendorLength = drflac__le2host_32_ptr_unaligned(pRunningData); pRunningData += 4;
- if ((pRunningDataEnd - pRunningData) - 4 < (drflac_int64)metadata.data.vorbis_comment.vendorLength) {
- drflac__free_from_callbacks(pRawData, pAllocationCallbacks);
- return DRFLAC_FALSE;
+ metadata.data.vorbis_comment.vendorLength = ma_dr_flac__le2host_32_ptr_unaligned(pRunningData); pRunningData += 4;
+ if ((pRunningDataEnd - pRunningData) - 4 < (ma_int64)metadata.data.vorbis_comment.vendorLength) {
+ ma_dr_flac__free_from_callbacks(pRawData, pAllocationCallbacks);
+ return MA_FALSE;
}
metadata.data.vorbis_comment.vendor = pRunningData; pRunningData += metadata.data.vorbis_comment.vendorLength;
- metadata.data.vorbis_comment.commentCount = drflac__le2host_32_ptr_unaligned(pRunningData); pRunningData += 4;
- if ((pRunningDataEnd - pRunningData) / sizeof(drflac_uint32) < metadata.data.vorbis_comment.commentCount) {
- drflac__free_from_callbacks(pRawData, pAllocationCallbacks);
- return DRFLAC_FALSE;
+ metadata.data.vorbis_comment.commentCount = ma_dr_flac__le2host_32_ptr_unaligned(pRunningData); pRunningData += 4;
+ if ((pRunningDataEnd - pRunningData) / sizeof(ma_uint32) < metadata.data.vorbis_comment.commentCount) {
+ ma_dr_flac__free_from_callbacks(pRawData, pAllocationCallbacks);
+ return MA_FALSE;
}
metadata.data.vorbis_comment.pComments = pRunningData;
for (i = 0; i < metadata.data.vorbis_comment.commentCount; ++i) {
- drflac_uint32 commentLength;
+ ma_uint32 commentLength;
if (pRunningDataEnd - pRunningData < 4) {
- drflac__free_from_callbacks(pRawData, pAllocationCallbacks);
- return DRFLAC_FALSE;
+ ma_dr_flac__free_from_callbacks(pRawData, pAllocationCallbacks);
+ return MA_FALSE;
}
- commentLength = drflac__le2host_32_ptr_unaligned(pRunningData); pRunningData += 4;
- if (pRunningDataEnd - pRunningData < (drflac_int64)commentLength) {
- drflac__free_from_callbacks(pRawData, pAllocationCallbacks);
- return DRFLAC_FALSE;
+ commentLength = ma_dr_flac__le2host_32_ptr_unaligned(pRunningData); pRunningData += 4;
+ if (pRunningDataEnd - pRunningData < (ma_int64)commentLength) {
+ ma_dr_flac__free_from_callbacks(pRawData, pAllocationCallbacks);
+ return MA_FALSE;
}
pRunningData += commentLength;
}
onMeta(pUserDataMD, &metadata);
- drflac__free_from_callbacks(pRawData, pAllocationCallbacks);
+ ma_dr_flac__free_from_callbacks(pRawData, pAllocationCallbacks);
}
} break;
- case DRFLAC_METADATA_BLOCK_TYPE_CUESHEET:
+ case MA_DR_FLAC_METADATA_BLOCK_TYPE_CUESHEET:
{
if (blockSize < 396) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
if (onMeta) {
void* pRawData;
const char* pRunningData;
const char* pRunningDataEnd;
size_t bufferSize;
- drflac_uint8 iTrack;
- drflac_uint8 iIndex;
+ ma_uint8 iTrack;
+ ma_uint8 iIndex;
void* pTrackData;
- pRawData = drflac__malloc_from_callbacks(blockSize, pAllocationCallbacks);
+ pRawData = ma_dr_flac__malloc_from_callbacks(blockSize, pAllocationCallbacks);
if (pRawData == NULL) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
if (onRead(pUserData, pRawData, blockSize) != blockSize) {
- drflac__free_from_callbacks(pRawData, pAllocationCallbacks);
- return DRFLAC_FALSE;
+ ma_dr_flac__free_from_callbacks(pRawData, pAllocationCallbacks);
+ return MA_FALSE;
}
metadata.pRawData = pRawData;
metadata.rawDataSize = blockSize;
pRunningData = (const char*)pRawData;
pRunningDataEnd = (const char*)pRawData + blockSize;
- DRFLAC_COPY_MEMORY(metadata.data.cuesheet.catalog, pRunningData, 128); pRunningData += 128;
- metadata.data.cuesheet.leadInSampleCount = drflac__be2host_64(*(const drflac_uint64*)pRunningData); pRunningData += 8;
+ MA_DR_FLAC_COPY_MEMORY(metadata.data.cuesheet.catalog, pRunningData, 128); pRunningData += 128;
+ metadata.data.cuesheet.leadInSampleCount = ma_dr_flac__be2host_64(*(const ma_uint64*)pRunningData); pRunningData += 8;
metadata.data.cuesheet.isCD = (pRunningData[0] & 0x80) != 0; pRunningData += 259;
metadata.data.cuesheet.trackCount = pRunningData[0]; pRunningData += 1;
metadata.data.cuesheet.pTrackData = NULL;
{
const char* pRunningDataSaved = pRunningData;
- bufferSize = metadata.data.cuesheet.trackCount * DRFLAC_CUESHEET_TRACK_SIZE_IN_BYTES;
+ bufferSize = metadata.data.cuesheet.trackCount * MA_DR_FLAC_CUESHEET_TRACK_SIZE_IN_BYTES;
for (iTrack = 0; iTrack < metadata.data.cuesheet.trackCount; ++iTrack) {
- drflac_uint8 indexCount;
- drflac_uint32 indexPointSize;
- if (pRunningDataEnd - pRunningData < DRFLAC_CUESHEET_TRACK_SIZE_IN_BYTES) {
- drflac__free_from_callbacks(pRawData, pAllocationCallbacks);
- return DRFLAC_FALSE;
+ ma_uint8 indexCount;
+ ma_uint32 indexPointSize;
+ if (pRunningDataEnd - pRunningData < MA_DR_FLAC_CUESHEET_TRACK_SIZE_IN_BYTES) {
+ ma_dr_flac__free_from_callbacks(pRawData, pAllocationCallbacks);
+ return MA_FALSE;
}
pRunningData += 35;
indexCount = pRunningData[0];
pRunningData += 1;
- bufferSize += indexCount * sizeof(drflac_cuesheet_track_index);
- indexPointSize = indexCount * DRFLAC_CUESHEET_TRACK_INDEX_SIZE_IN_BYTES;
- if (pRunningDataEnd - pRunningData < (drflac_int64)indexPointSize) {
- drflac__free_from_callbacks(pRawData, pAllocationCallbacks);
- return DRFLAC_FALSE;
+ bufferSize += indexCount * sizeof(ma_dr_flac_cuesheet_track_index);
+ indexPointSize = indexCount * MA_DR_FLAC_CUESHEET_TRACK_INDEX_SIZE_IN_BYTES;
+ if (pRunningDataEnd - pRunningData < (ma_int64)indexPointSize) {
+ ma_dr_flac__free_from_callbacks(pRawData, pAllocationCallbacks);
+ return MA_FALSE;
}
pRunningData += indexPointSize;
}
@@ -83628,125 +86060,125 @@ static drflac_bool32 drflac__read_and_decode_metadata(drflac_read_proc onRead, d
}
{
char* pRunningTrackData;
- pTrackData = drflac__malloc_from_callbacks(bufferSize, pAllocationCallbacks);
+ pTrackData = ma_dr_flac__malloc_from_callbacks(bufferSize, pAllocationCallbacks);
if (pTrackData == NULL) {
- drflac__free_from_callbacks(pRawData, pAllocationCallbacks);
- return DRFLAC_FALSE;
+ ma_dr_flac__free_from_callbacks(pRawData, pAllocationCallbacks);
+ return MA_FALSE;
}
pRunningTrackData = (char*)pTrackData;
for (iTrack = 0; iTrack < metadata.data.cuesheet.trackCount; ++iTrack) {
- drflac_uint8 indexCount;
- DRFLAC_COPY_MEMORY(pRunningTrackData, pRunningData, DRFLAC_CUESHEET_TRACK_SIZE_IN_BYTES);
- pRunningData += DRFLAC_CUESHEET_TRACK_SIZE_IN_BYTES-1;
- pRunningTrackData += DRFLAC_CUESHEET_TRACK_SIZE_IN_BYTES-1;
+ ma_uint8 indexCount;
+ MA_DR_FLAC_COPY_MEMORY(pRunningTrackData, pRunningData, MA_DR_FLAC_CUESHEET_TRACK_SIZE_IN_BYTES);
+ pRunningData += MA_DR_FLAC_CUESHEET_TRACK_SIZE_IN_BYTES-1;
+ pRunningTrackData += MA_DR_FLAC_CUESHEET_TRACK_SIZE_IN_BYTES-1;
indexCount = pRunningData[0];
pRunningData += 1;
pRunningTrackData += 1;
for (iIndex = 0; iIndex < indexCount; ++iIndex) {
- drflac_cuesheet_track_index* pTrackIndex = (drflac_cuesheet_track_index*)pRunningTrackData;
- DRFLAC_COPY_MEMORY(pRunningTrackData, pRunningData, DRFLAC_CUESHEET_TRACK_INDEX_SIZE_IN_BYTES);
- pRunningData += DRFLAC_CUESHEET_TRACK_INDEX_SIZE_IN_BYTES;
- pRunningTrackData += sizeof(drflac_cuesheet_track_index);
- pTrackIndex->offset = drflac__be2host_64(pTrackIndex->offset);
+ ma_dr_flac_cuesheet_track_index* pTrackIndex = (ma_dr_flac_cuesheet_track_index*)pRunningTrackData;
+ MA_DR_FLAC_COPY_MEMORY(pRunningTrackData, pRunningData, MA_DR_FLAC_CUESHEET_TRACK_INDEX_SIZE_IN_BYTES);
+ pRunningData += MA_DR_FLAC_CUESHEET_TRACK_INDEX_SIZE_IN_BYTES;
+ pRunningTrackData += sizeof(ma_dr_flac_cuesheet_track_index);
+ pTrackIndex->offset = ma_dr_flac__be2host_64(pTrackIndex->offset);
}
}
metadata.data.cuesheet.pTrackData = pTrackData;
}
- drflac__free_from_callbacks(pRawData, pAllocationCallbacks);
+ ma_dr_flac__free_from_callbacks(pRawData, pAllocationCallbacks);
pRawData = NULL;
onMeta(pUserDataMD, &metadata);
- drflac__free_from_callbacks(pTrackData, pAllocationCallbacks);
+ ma_dr_flac__free_from_callbacks(pTrackData, pAllocationCallbacks);
pTrackData = NULL;
}
} break;
- case DRFLAC_METADATA_BLOCK_TYPE_PICTURE:
+ case MA_DR_FLAC_METADATA_BLOCK_TYPE_PICTURE:
{
if (blockSize < 32) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
if (onMeta) {
void* pRawData;
const char* pRunningData;
const char* pRunningDataEnd;
- pRawData = drflac__malloc_from_callbacks(blockSize, pAllocationCallbacks);
+ pRawData = ma_dr_flac__malloc_from_callbacks(blockSize, pAllocationCallbacks);
if (pRawData == NULL) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
if (onRead(pUserData, pRawData, blockSize) != blockSize) {
- drflac__free_from_callbacks(pRawData, pAllocationCallbacks);
- return DRFLAC_FALSE;
+ ma_dr_flac__free_from_callbacks(pRawData, pAllocationCallbacks);
+ return MA_FALSE;
}
metadata.pRawData = pRawData;
metadata.rawDataSize = blockSize;
pRunningData = (const char*)pRawData;
pRunningDataEnd = (const char*)pRawData + blockSize;
- metadata.data.picture.type = drflac__be2host_32_ptr_unaligned(pRunningData); pRunningData += 4;
- metadata.data.picture.mimeLength = drflac__be2host_32_ptr_unaligned(pRunningData); pRunningData += 4;
- if ((pRunningDataEnd - pRunningData) - 24 < (drflac_int64)metadata.data.picture.mimeLength) {
- drflac__free_from_callbacks(pRawData, pAllocationCallbacks);
- return DRFLAC_FALSE;
+ metadata.data.picture.type = ma_dr_flac__be2host_32_ptr_unaligned(pRunningData); pRunningData += 4;
+ metadata.data.picture.mimeLength = ma_dr_flac__be2host_32_ptr_unaligned(pRunningData); pRunningData += 4;
+ if ((pRunningDataEnd - pRunningData) - 24 < (ma_int64)metadata.data.picture.mimeLength) {
+ ma_dr_flac__free_from_callbacks(pRawData, pAllocationCallbacks);
+ return MA_FALSE;
}
metadata.data.picture.mime = pRunningData; pRunningData += metadata.data.picture.mimeLength;
- metadata.data.picture.descriptionLength = drflac__be2host_32_ptr_unaligned(pRunningData); pRunningData += 4;
- if ((pRunningDataEnd - pRunningData) - 20 < (drflac_int64)metadata.data.picture.descriptionLength) {
- drflac__free_from_callbacks(pRawData, pAllocationCallbacks);
- return DRFLAC_FALSE;
+ metadata.data.picture.descriptionLength = ma_dr_flac__be2host_32_ptr_unaligned(pRunningData); pRunningData += 4;
+ if ((pRunningDataEnd - pRunningData) - 20 < (ma_int64)metadata.data.picture.descriptionLength) {
+ ma_dr_flac__free_from_callbacks(pRawData, pAllocationCallbacks);
+ return MA_FALSE;
}
metadata.data.picture.description = pRunningData; pRunningData += metadata.data.picture.descriptionLength;
- metadata.data.picture.width = drflac__be2host_32_ptr_unaligned(pRunningData); pRunningData += 4;
- metadata.data.picture.height = drflac__be2host_32_ptr_unaligned(pRunningData); pRunningData += 4;
- metadata.data.picture.colorDepth = drflac__be2host_32_ptr_unaligned(pRunningData); pRunningData += 4;
- metadata.data.picture.indexColorCount = drflac__be2host_32_ptr_unaligned(pRunningData); pRunningData += 4;
- metadata.data.picture.pictureDataSize = drflac__be2host_32_ptr_unaligned(pRunningData); pRunningData += 4;
- metadata.data.picture.pPictureData = (const drflac_uint8*)pRunningData;
- if (pRunningDataEnd - pRunningData < (drflac_int64)metadata.data.picture.pictureDataSize) {
- drflac__free_from_callbacks(pRawData, pAllocationCallbacks);
- return DRFLAC_FALSE;
+ metadata.data.picture.width = ma_dr_flac__be2host_32_ptr_unaligned(pRunningData); pRunningData += 4;
+ metadata.data.picture.height = ma_dr_flac__be2host_32_ptr_unaligned(pRunningData); pRunningData += 4;
+ metadata.data.picture.colorDepth = ma_dr_flac__be2host_32_ptr_unaligned(pRunningData); pRunningData += 4;
+ metadata.data.picture.indexColorCount = ma_dr_flac__be2host_32_ptr_unaligned(pRunningData); pRunningData += 4;
+ metadata.data.picture.pictureDataSize = ma_dr_flac__be2host_32_ptr_unaligned(pRunningData); pRunningData += 4;
+ metadata.data.picture.pPictureData = (const ma_uint8*)pRunningData;
+ if (pRunningDataEnd - pRunningData < (ma_int64)metadata.data.picture.pictureDataSize) {
+ ma_dr_flac__free_from_callbacks(pRawData, pAllocationCallbacks);
+ return MA_FALSE;
}
onMeta(pUserDataMD, &metadata);
- drflac__free_from_callbacks(pRawData, pAllocationCallbacks);
+ ma_dr_flac__free_from_callbacks(pRawData, pAllocationCallbacks);
}
} break;
- case DRFLAC_METADATA_BLOCK_TYPE_PADDING:
+ case MA_DR_FLAC_METADATA_BLOCK_TYPE_PADDING:
{
if (onMeta) {
metadata.data.padding.unused = 0;
- if (!onSeek(pUserData, blockSize, drflac_seek_origin_current)) {
- isLastBlock = DRFLAC_TRUE;
+ if (!onSeek(pUserData, blockSize, ma_dr_flac_seek_origin_current)) {
+ isLastBlock = MA_TRUE;
} else {
onMeta(pUserDataMD, &metadata);
}
}
} break;
- case DRFLAC_METADATA_BLOCK_TYPE_INVALID:
+ case MA_DR_FLAC_METADATA_BLOCK_TYPE_INVALID:
{
if (onMeta) {
- if (!onSeek(pUserData, blockSize, drflac_seek_origin_current)) {
- isLastBlock = DRFLAC_TRUE;
+ if (!onSeek(pUserData, blockSize, ma_dr_flac_seek_origin_current)) {
+ isLastBlock = MA_TRUE;
}
}
} break;
default:
{
if (onMeta) {
- void* pRawData = drflac__malloc_from_callbacks(blockSize, pAllocationCallbacks);
+ void* pRawData = ma_dr_flac__malloc_from_callbacks(blockSize, pAllocationCallbacks);
if (pRawData == NULL) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
if (onRead(pUserData, pRawData, blockSize) != blockSize) {
- drflac__free_from_callbacks(pRawData, pAllocationCallbacks);
- return DRFLAC_FALSE;
+ ma_dr_flac__free_from_callbacks(pRawData, pAllocationCallbacks);
+ return MA_FALSE;
}
metadata.pRawData = pRawData;
metadata.rawDataSize = blockSize;
onMeta(pUserDataMD, &metadata);
- drflac__free_from_callbacks(pRawData, pAllocationCallbacks);
+ ma_dr_flac__free_from_callbacks(pRawData, pAllocationCallbacks);
}
} break;
}
if (onMeta == NULL && blockSize > 0) {
- if (!onSeek(pUserData, blockSize, drflac_seek_origin_current)) {
- isLastBlock = DRFLAC_TRUE;
+ if (!onSeek(pUserData, blockSize, ma_dr_flac_seek_origin_current)) {
+ isLastBlock = MA_TRUE;
}
}
runningFilePos += blockSize;
@@ -83755,44 +86187,44 @@ static drflac_bool32 drflac__read_and_decode_metadata(drflac_read_proc onRead, d
}
}
*pSeektablePos = seektablePos;
- *pSeekpointCount = seektableSize / DRFLAC_SEEKPOINT_SIZE_IN_BYTES;
+ *pSeekpointCount = seektableSize / MA_DR_FLAC_SEEKPOINT_SIZE_IN_BYTES;
*pFirstFramePos = runningFilePos;
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
-static drflac_bool32 drflac__init_private__native(drflac_init_info* pInit, drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_meta_proc onMeta, void* pUserData, void* pUserDataMD, drflac_bool32 relaxed)
+static ma_bool32 ma_dr_flac__init_private__native(ma_dr_flac_init_info* pInit, ma_dr_flac_read_proc onRead, ma_dr_flac_seek_proc onSeek, ma_dr_flac_meta_proc onMeta, void* pUserData, void* pUserDataMD, ma_bool32 relaxed)
{
- drflac_uint8 isLastBlock;
- drflac_uint8 blockType;
- drflac_uint32 blockSize;
+ ma_uint8 isLastBlock;
+ ma_uint8 blockType;
+ ma_uint32 blockSize;
(void)onSeek;
- pInit->container = drflac_container_native;
- if (!drflac__read_and_decode_block_header(onRead, pUserData, &isLastBlock, &blockType, &blockSize)) {
- return DRFLAC_FALSE;
+ pInit->container = ma_dr_flac_container_native;
+ if (!ma_dr_flac__read_and_decode_block_header(onRead, pUserData, &isLastBlock, &blockType, &blockSize)) {
+ return MA_FALSE;
}
- if (blockType != DRFLAC_METADATA_BLOCK_TYPE_STREAMINFO || blockSize != 34) {
+ if (blockType != MA_DR_FLAC_METADATA_BLOCK_TYPE_STREAMINFO || blockSize != 34) {
if (!relaxed) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
} else {
- pInit->hasStreamInfoBlock = DRFLAC_FALSE;
- pInit->hasMetadataBlocks = DRFLAC_FALSE;
- if (!drflac__read_next_flac_frame_header(&pInit->bs, 0, &pInit->firstFrameHeader)) {
- return DRFLAC_FALSE;
+ pInit->hasStreamInfoBlock = MA_FALSE;
+ pInit->hasMetadataBlocks = MA_FALSE;
+ if (!ma_dr_flac__read_next_flac_frame_header(&pInit->bs, 0, &pInit->firstFrameHeader)) {
+ return MA_FALSE;
}
if (pInit->firstFrameHeader.bitsPerSample == 0) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
pInit->sampleRate = pInit->firstFrameHeader.sampleRate;
- pInit->channels = drflac__get_channel_count_from_channel_assignment(pInit->firstFrameHeader.channelAssignment);
+ pInit->channels = ma_dr_flac__get_channel_count_from_channel_assignment(pInit->firstFrameHeader.channelAssignment);
pInit->bitsPerSample = pInit->firstFrameHeader.bitsPerSample;
pInit->maxBlockSizeInPCMFrames = 65535;
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
} else {
- drflac_streaminfo streaminfo;
- if (!drflac__read_streaminfo(onRead, pUserData, &streaminfo)) {
- return DRFLAC_FALSE;
+ ma_dr_flac_streaminfo streaminfo;
+ if (!ma_dr_flac__read_streaminfo(onRead, pUserData, &streaminfo)) {
+ return MA_FALSE;
}
- pInit->hasStreamInfoBlock = DRFLAC_TRUE;
+ pInit->hasStreamInfoBlock = MA_TRUE;
pInit->sampleRate = streaminfo.sampleRate;
pInit->channels = streaminfo.channels;
pInit->bitsPerSample = streaminfo.bitsPerSample;
@@ -83800,26 +86232,26 @@ static drflac_bool32 drflac__init_private__native(drflac_init_info* pInit, drfla
pInit->maxBlockSizeInPCMFrames = streaminfo.maxBlockSizeInPCMFrames;
pInit->hasMetadataBlocks = !isLastBlock;
if (onMeta) {
- drflac_metadata metadata;
- metadata.type = DRFLAC_METADATA_BLOCK_TYPE_STREAMINFO;
+ ma_dr_flac_metadata metadata;
+ metadata.type = MA_DR_FLAC_METADATA_BLOCK_TYPE_STREAMINFO;
metadata.pRawData = NULL;
metadata.rawDataSize = 0;
metadata.data.streaminfo = streaminfo;
onMeta(pUserDataMD, &metadata);
}
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
}
-#ifndef DR_FLAC_NO_OGG
-#define DRFLAC_OGG_MAX_PAGE_SIZE 65307
-#define DRFLAC_OGG_CAPTURE_PATTERN_CRC32 1605413199
+#ifndef MA_DR_FLAC_NO_OGG
+#define MA_DR_FLAC_OGG_MAX_PAGE_SIZE 65307
+#define MA_DR_FLAC_OGG_CAPTURE_PATTERN_CRC32 1605413199
typedef enum
{
- drflac_ogg_recover_on_crc_mismatch,
- drflac_ogg_fail_on_crc_mismatch
-} drflac_ogg_crc_mismatch_recovery;
-#ifndef DR_FLAC_NO_CRC
-static drflac_uint32 drflac__crc32_table[] = {
+ ma_dr_flac_ogg_recover_on_crc_mismatch,
+ ma_dr_flac_ogg_fail_on_crc_mismatch
+} ma_dr_flac_ogg_crc_mismatch_recovery;
+#ifndef MA_DR_FLAC_NO_CRC
+static ma_uint32 ma_dr_flac__crc32_table[] = {
0x00000000L, 0x04C11DB7L, 0x09823B6EL, 0x0D4326D9L,
0x130476DCL, 0x17C56B6BL, 0x1A864DB2L, 0x1E475005L,
0x2608EDB8L, 0x22C9F00FL, 0x2F8AD6D6L, 0x2B4BCB61L,
@@ -83886,63 +86318,63 @@ static drflac_uint32 drflac__crc32_table[] = {
0xBCB4666DL, 0xB8757BDAL, 0xB5365D03L, 0xB1F740B4L
};
#endif
-static DRFLAC_INLINE drflac_uint32 drflac_crc32_byte(drflac_uint32 crc32, drflac_uint8 data)
+static MA_INLINE ma_uint32 ma_dr_flac_crc32_byte(ma_uint32 crc32, ma_uint8 data)
{
-#ifndef DR_FLAC_NO_CRC
- return (crc32 << 8) ^ drflac__crc32_table[(drflac_uint8)((crc32 >> 24) & 0xFF) ^ data];
+#ifndef MA_DR_FLAC_NO_CRC
+ return (crc32 << 8) ^ ma_dr_flac__crc32_table[(ma_uint8)((crc32 >> 24) & 0xFF) ^ data];
#else
(void)data;
return crc32;
#endif
}
#if 0
-static DRFLAC_INLINE drflac_uint32 drflac_crc32_uint32(drflac_uint32 crc32, drflac_uint32 data)
+static MA_INLINE ma_uint32 ma_dr_flac_crc32_uint32(ma_uint32 crc32, ma_uint32 data)
{
- crc32 = drflac_crc32_byte(crc32, (drflac_uint8)((data >> 24) & 0xFF));
- crc32 = drflac_crc32_byte(crc32, (drflac_uint8)((data >> 16) & 0xFF));
- crc32 = drflac_crc32_byte(crc32, (drflac_uint8)((data >> 8) & 0xFF));
- crc32 = drflac_crc32_byte(crc32, (drflac_uint8)((data >> 0) & 0xFF));
+ crc32 = ma_dr_flac_crc32_byte(crc32, (ma_uint8)((data >> 24) & 0xFF));
+ crc32 = ma_dr_flac_crc32_byte(crc32, (ma_uint8)((data >> 16) & 0xFF));
+ crc32 = ma_dr_flac_crc32_byte(crc32, (ma_uint8)((data >> 8) & 0xFF));
+ crc32 = ma_dr_flac_crc32_byte(crc32, (ma_uint8)((data >> 0) & 0xFF));
return crc32;
}
-static DRFLAC_INLINE drflac_uint32 drflac_crc32_uint64(drflac_uint32 crc32, drflac_uint64 data)
+static MA_INLINE ma_uint32 ma_dr_flac_crc32_uint64(ma_uint32 crc32, ma_uint64 data)
{
- crc32 = drflac_crc32_uint32(crc32, (drflac_uint32)((data >> 32) & 0xFFFFFFFF));
- crc32 = drflac_crc32_uint32(crc32, (drflac_uint32)((data >> 0) & 0xFFFFFFFF));
+ crc32 = ma_dr_flac_crc32_uint32(crc32, (ma_uint32)((data >> 32) & 0xFFFFFFFF));
+ crc32 = ma_dr_flac_crc32_uint32(crc32, (ma_uint32)((data >> 0) & 0xFFFFFFFF));
return crc32;
}
#endif
-static DRFLAC_INLINE drflac_uint32 drflac_crc32_buffer(drflac_uint32 crc32, drflac_uint8* pData, drflac_uint32 dataSize)
+static MA_INLINE ma_uint32 ma_dr_flac_crc32_buffer(ma_uint32 crc32, ma_uint8* pData, ma_uint32 dataSize)
{
- drflac_uint32 i;
+ ma_uint32 i;
for (i = 0; i < dataSize; ++i) {
- crc32 = drflac_crc32_byte(crc32, pData[i]);
+ crc32 = ma_dr_flac_crc32_byte(crc32, pData[i]);
}
return crc32;
}
-static DRFLAC_INLINE drflac_bool32 drflac_ogg__is_capture_pattern(drflac_uint8 pattern[4])
+static MA_INLINE ma_bool32 ma_dr_flac_ogg__is_capture_pattern(ma_uint8 pattern[4])
{
return pattern[0] == 'O' && pattern[1] == 'g' && pattern[2] == 'g' && pattern[3] == 'S';
}
-static DRFLAC_INLINE drflac_uint32 drflac_ogg__get_page_header_size(drflac_ogg_page_header* pHeader)
+static MA_INLINE ma_uint32 ma_dr_flac_ogg__get_page_header_size(ma_dr_flac_ogg_page_header* pHeader)
{
return 27 + pHeader->segmentCount;
}
-static DRFLAC_INLINE drflac_uint32 drflac_ogg__get_page_body_size(drflac_ogg_page_header* pHeader)
+static MA_INLINE ma_uint32 ma_dr_flac_ogg__get_page_body_size(ma_dr_flac_ogg_page_header* pHeader)
{
- drflac_uint32 pageBodySize = 0;
+ ma_uint32 pageBodySize = 0;
int i;
for (i = 0; i < pHeader->segmentCount; ++i) {
pageBodySize += pHeader->segmentTable[i];
}
return pageBodySize;
}
-static drflac_result drflac_ogg__read_page_header_after_capture_pattern(drflac_read_proc onRead, void* pUserData, drflac_ogg_page_header* pHeader, drflac_uint32* pBytesRead, drflac_uint32* pCRC32)
+static ma_result ma_dr_flac_ogg__read_page_header_after_capture_pattern(ma_dr_flac_read_proc onRead, void* pUserData, ma_dr_flac_ogg_page_header* pHeader, ma_uint32* pBytesRead, ma_uint32* pCRC32)
{
- drflac_uint8 data[23];
- drflac_uint32 i;
- DRFLAC_ASSERT(*pCRC32 == DRFLAC_OGG_CAPTURE_PATTERN_CRC32);
+ ma_uint8 data[23];
+ ma_uint32 i;
+ MA_DR_FLAC_ASSERT(*pCRC32 == MA_DR_FLAC_OGG_CAPTURE_PATTERN_CRC32);
if (onRead(pUserData, data, 23) != 23) {
- return DRFLAC_AT_END;
+ return MA_AT_END;
}
*pBytesRead += 23;
pHeader->capturePattern[0] = 'O';
@@ -83951,44 +86383,44 @@ static drflac_result drflac_ogg__read_page_header_after_capture_pattern(drflac_r
pHeader->capturePattern[3] = 'S';
pHeader->structureVersion = data[0];
pHeader->headerType = data[1];
- DRFLAC_COPY_MEMORY(&pHeader->granulePosition, &data[ 2], 8);
- DRFLAC_COPY_MEMORY(&pHeader->serialNumber, &data[10], 4);
- DRFLAC_COPY_MEMORY(&pHeader->sequenceNumber, &data[14], 4);
- DRFLAC_COPY_MEMORY(&pHeader->checksum, &data[18], 4);
+ MA_DR_FLAC_COPY_MEMORY(&pHeader->granulePosition, &data[ 2], 8);
+ MA_DR_FLAC_COPY_MEMORY(&pHeader->serialNumber, &data[10], 4);
+ MA_DR_FLAC_COPY_MEMORY(&pHeader->sequenceNumber, &data[14], 4);
+ MA_DR_FLAC_COPY_MEMORY(&pHeader->checksum, &data[18], 4);
pHeader->segmentCount = data[22];
data[18] = 0;
data[19] = 0;
data[20] = 0;
data[21] = 0;
for (i = 0; i < 23; ++i) {
- *pCRC32 = drflac_crc32_byte(*pCRC32, data[i]);
+ *pCRC32 = ma_dr_flac_crc32_byte(*pCRC32, data[i]);
}
if (onRead(pUserData, pHeader->segmentTable, pHeader->segmentCount) != pHeader->segmentCount) {
- return DRFLAC_AT_END;
+ return MA_AT_END;
}
*pBytesRead += pHeader->segmentCount;
for (i = 0; i < pHeader->segmentCount; ++i) {
- *pCRC32 = drflac_crc32_byte(*pCRC32, pHeader->segmentTable[i]);
+ *pCRC32 = ma_dr_flac_crc32_byte(*pCRC32, pHeader->segmentTable[i]);
}
- return DRFLAC_SUCCESS;
+ return MA_SUCCESS;
}
-static drflac_result drflac_ogg__read_page_header(drflac_read_proc onRead, void* pUserData, drflac_ogg_page_header* pHeader, drflac_uint32* pBytesRead, drflac_uint32* pCRC32)
+static ma_result ma_dr_flac_ogg__read_page_header(ma_dr_flac_read_proc onRead, void* pUserData, ma_dr_flac_ogg_page_header* pHeader, ma_uint32* pBytesRead, ma_uint32* pCRC32)
{
- drflac_uint8 id[4];
+ ma_uint8 id[4];
*pBytesRead = 0;
if (onRead(pUserData, id, 4) != 4) {
- return DRFLAC_AT_END;
+ return MA_AT_END;
}
*pBytesRead += 4;
for (;;) {
- if (drflac_ogg__is_capture_pattern(id)) {
- drflac_result result;
- *pCRC32 = DRFLAC_OGG_CAPTURE_PATTERN_CRC32;
- result = drflac_ogg__read_page_header_after_capture_pattern(onRead, pUserData, pHeader, pBytesRead, pCRC32);
- if (result == DRFLAC_SUCCESS) {
- return DRFLAC_SUCCESS;
+ if (ma_dr_flac_ogg__is_capture_pattern(id)) {
+ ma_result result;
+ *pCRC32 = MA_DR_FLAC_OGG_CAPTURE_PATTERN_CRC32;
+ result = ma_dr_flac_ogg__read_page_header_after_capture_pattern(onRead, pUserData, pHeader, pBytesRead, pCRC32);
+ if (result == MA_SUCCESS) {
+ return MA_SUCCESS;
} else {
- if (result == DRFLAC_CRC_MISMATCH) {
+ if (result == MA_CRC_MISMATCH) {
continue;
} else {
return result;
@@ -83999,7 +86431,7 @@ static drflac_result drflac_ogg__read_page_header(drflac_read_proc onRead, void*
id[1] = id[2];
id[2] = id[3];
if (onRead(pUserData, &id[3], 1) != 1) {
- return DRFLAC_AT_END;
+ return MA_AT_END;
}
*pBytesRead += 1;
}
@@ -84007,91 +86439,91 @@ static drflac_result drflac_ogg__read_page_header(drflac_read_proc onRead, void*
}
typedef struct
{
- drflac_read_proc onRead;
- drflac_seek_proc onSeek;
+ ma_dr_flac_read_proc onRead;
+ ma_dr_flac_seek_proc onSeek;
void* pUserData;
- drflac_uint64 currentBytePos;
- drflac_uint64 firstBytePos;
- drflac_uint32 serialNumber;
- drflac_ogg_page_header bosPageHeader;
- drflac_ogg_page_header currentPageHeader;
- drflac_uint32 bytesRemainingInPage;
- drflac_uint32 pageDataSize;
- drflac_uint8 pageData[DRFLAC_OGG_MAX_PAGE_SIZE];
-} drflac_oggbs;
-static size_t drflac_oggbs__read_physical(drflac_oggbs* oggbs, void* bufferOut, size_t bytesToRead)
+ ma_uint64 currentBytePos;
+ ma_uint64 firstBytePos;
+ ma_uint32 serialNumber;
+ ma_dr_flac_ogg_page_header bosPageHeader;
+ ma_dr_flac_ogg_page_header currentPageHeader;
+ ma_uint32 bytesRemainingInPage;
+ ma_uint32 pageDataSize;
+ ma_uint8 pageData[MA_DR_FLAC_OGG_MAX_PAGE_SIZE];
+} ma_dr_flac_oggbs;
+static size_t ma_dr_flac_oggbs__read_physical(ma_dr_flac_oggbs* oggbs, void* bufferOut, size_t bytesToRead)
{
size_t bytesActuallyRead = oggbs->onRead(oggbs->pUserData, bufferOut, bytesToRead);
oggbs->currentBytePos += bytesActuallyRead;
return bytesActuallyRead;
}
-static drflac_bool32 drflac_oggbs__seek_physical(drflac_oggbs* oggbs, drflac_uint64 offset, drflac_seek_origin origin)
+static ma_bool32 ma_dr_flac_oggbs__seek_physical(ma_dr_flac_oggbs* oggbs, ma_uint64 offset, ma_dr_flac_seek_origin origin)
{
- if (origin == drflac_seek_origin_start) {
+ if (origin == ma_dr_flac_seek_origin_start) {
if (offset <= 0x7FFFFFFF) {
- if (!oggbs->onSeek(oggbs->pUserData, (int)offset, drflac_seek_origin_start)) {
- return DRFLAC_FALSE;
+ if (!oggbs->onSeek(oggbs->pUserData, (int)offset, ma_dr_flac_seek_origin_start)) {
+ return MA_FALSE;
}
oggbs->currentBytePos = offset;
- return DRFLAC_TRUE;
+ return MA_TRUE;
} else {
- if (!oggbs->onSeek(oggbs->pUserData, 0x7FFFFFFF, drflac_seek_origin_start)) {
- return DRFLAC_FALSE;
+ if (!oggbs->onSeek(oggbs->pUserData, 0x7FFFFFFF, ma_dr_flac_seek_origin_start)) {
+ return MA_FALSE;
}
oggbs->currentBytePos = offset;
- return drflac_oggbs__seek_physical(oggbs, offset - 0x7FFFFFFF, drflac_seek_origin_current);
+ return ma_dr_flac_oggbs__seek_physical(oggbs, offset - 0x7FFFFFFF, ma_dr_flac_seek_origin_current);
}
} else {
while (offset > 0x7FFFFFFF) {
- if (!oggbs->onSeek(oggbs->pUserData, 0x7FFFFFFF, drflac_seek_origin_current)) {
- return DRFLAC_FALSE;
+ if (!oggbs->onSeek(oggbs->pUserData, 0x7FFFFFFF, ma_dr_flac_seek_origin_current)) {
+ return MA_FALSE;
}
oggbs->currentBytePos += 0x7FFFFFFF;
offset -= 0x7FFFFFFF;
}
- if (!oggbs->onSeek(oggbs->pUserData, (int)offset, drflac_seek_origin_current)) {
- return DRFLAC_FALSE;
+ if (!oggbs->onSeek(oggbs->pUserData, (int)offset, ma_dr_flac_seek_origin_current)) {
+ return MA_FALSE;
}
oggbs->currentBytePos += offset;
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
}
-static drflac_bool32 drflac_oggbs__goto_next_page(drflac_oggbs* oggbs, drflac_ogg_crc_mismatch_recovery recoveryMethod)
+static ma_bool32 ma_dr_flac_oggbs__goto_next_page(ma_dr_flac_oggbs* oggbs, ma_dr_flac_ogg_crc_mismatch_recovery recoveryMethod)
{
- drflac_ogg_page_header header;
+ ma_dr_flac_ogg_page_header header;
for (;;) {
- drflac_uint32 crc32 = 0;
- drflac_uint32 bytesRead;
- drflac_uint32 pageBodySize;
-#ifndef DR_FLAC_NO_CRC
- drflac_uint32 actualCRC32;
+ ma_uint32 crc32 = 0;
+ ma_uint32 bytesRead;
+ ma_uint32 pageBodySize;
+#ifndef MA_DR_FLAC_NO_CRC
+ ma_uint32 actualCRC32;
#endif
- if (drflac_ogg__read_page_header(oggbs->onRead, oggbs->pUserData, &header, &bytesRead, &crc32) != DRFLAC_SUCCESS) {
- return DRFLAC_FALSE;
+ if (ma_dr_flac_ogg__read_page_header(oggbs->onRead, oggbs->pUserData, &header, &bytesRead, &crc32) != MA_SUCCESS) {
+ return MA_FALSE;
}
oggbs->currentBytePos += bytesRead;
- pageBodySize = drflac_ogg__get_page_body_size(&header);
- if (pageBodySize > DRFLAC_OGG_MAX_PAGE_SIZE) {
+ pageBodySize = ma_dr_flac_ogg__get_page_body_size(&header);
+ if (pageBodySize > MA_DR_FLAC_OGG_MAX_PAGE_SIZE) {
continue;
}
if (header.serialNumber != oggbs->serialNumber) {
- if (pageBodySize > 0 && !drflac_oggbs__seek_physical(oggbs, pageBodySize, drflac_seek_origin_current)) {
- return DRFLAC_FALSE;
+ if (pageBodySize > 0 && !ma_dr_flac_oggbs__seek_physical(oggbs, pageBodySize, ma_dr_flac_seek_origin_current)) {
+ return MA_FALSE;
}
continue;
}
- if (drflac_oggbs__read_physical(oggbs, oggbs->pageData, pageBodySize) != pageBodySize) {
- return DRFLAC_FALSE;
+ if (ma_dr_flac_oggbs__read_physical(oggbs, oggbs->pageData, pageBodySize) != pageBodySize) {
+ return MA_FALSE;
}
oggbs->pageDataSize = pageBodySize;
-#ifndef DR_FLAC_NO_CRC
- actualCRC32 = drflac_crc32_buffer(crc32, oggbs->pageData, oggbs->pageDataSize);
+#ifndef MA_DR_FLAC_NO_CRC
+ actualCRC32 = ma_dr_flac_crc32_buffer(crc32, oggbs->pageData, oggbs->pageDataSize);
if (actualCRC32 != header.checksum) {
- if (recoveryMethod == drflac_ogg_recover_on_crc_mismatch) {
+ if (recoveryMethod == ma_dr_flac_ogg_recover_on_crc_mismatch) {
continue;
} else {
- drflac_oggbs__goto_next_page(oggbs, drflac_ogg_recover_on_crc_mismatch);
- return DRFLAC_FALSE;
+ ma_dr_flac_oggbs__goto_next_page(oggbs, ma_dr_flac_ogg_recover_on_crc_mismatch);
+ return MA_FALSE;
}
}
#else
@@ -84099,17 +86531,17 @@ static drflac_bool32 drflac_oggbs__goto_next_page(drflac_oggbs* oggbs, drflac_og
#endif
oggbs->currentPageHeader = header;
oggbs->bytesRemainingInPage = pageBodySize;
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
}
#if 0
-static drflac_uint8 drflac_oggbs__get_current_segment_index(drflac_oggbs* oggbs, drflac_uint8* pBytesRemainingInSeg)
+static ma_uint8 ma_dr_flac_oggbs__get_current_segment_index(ma_dr_flac_oggbs* oggbs, ma_uint8* pBytesRemainingInSeg)
{
- drflac_uint32 bytesConsumedInPage = drflac_ogg__get_page_body_size(&oggbs->currentPageHeader) - oggbs->bytesRemainingInPage;
- drflac_uint8 iSeg = 0;
- drflac_uint32 iByte = 0;
+ ma_uint32 bytesConsumedInPage = ma_dr_flac_ogg__get_page_body_size(&oggbs->currentPageHeader) - oggbs->bytesRemainingInPage;
+ ma_uint8 iSeg = 0;
+ ma_uint32 iByte = 0;
while (iByte < bytesConsumedInPage) {
- drflac_uint8 segmentSize = oggbs->currentPageHeader.segmentTable[iSeg];
+ ma_uint8 segmentSize = oggbs->currentPageHeader.segmentTable[iSeg];
if (iByte + segmentSize > bytesConsumedInPage) {
break;
} else {
@@ -84117,92 +86549,92 @@ static drflac_uint8 drflac_oggbs__get_current_segment_index(drflac_oggbs* oggbs,
iByte += segmentSize;
}
}
- *pBytesRemainingInSeg = oggbs->currentPageHeader.segmentTable[iSeg] - (drflac_uint8)(bytesConsumedInPage - iByte);
+ *pBytesRemainingInSeg = oggbs->currentPageHeader.segmentTable[iSeg] - (ma_uint8)(bytesConsumedInPage - iByte);
return iSeg;
}
-static drflac_bool32 drflac_oggbs__seek_to_next_packet(drflac_oggbs* oggbs)
+static ma_bool32 ma_dr_flac_oggbs__seek_to_next_packet(ma_dr_flac_oggbs* oggbs)
{
for (;;) {
- drflac_bool32 atEndOfPage = DRFLAC_FALSE;
- drflac_uint8 bytesRemainingInSeg;
- drflac_uint8 iFirstSeg = drflac_oggbs__get_current_segment_index(oggbs, &bytesRemainingInSeg);
- drflac_uint32 bytesToEndOfPacketOrPage = bytesRemainingInSeg;
- for (drflac_uint8 iSeg = iFirstSeg; iSeg < oggbs->currentPageHeader.segmentCount; ++iSeg) {
- drflac_uint8 segmentSize = oggbs->currentPageHeader.segmentTable[iSeg];
+ ma_bool32 atEndOfPage = MA_FALSE;
+ ma_uint8 bytesRemainingInSeg;
+ ma_uint8 iFirstSeg = ma_dr_flac_oggbs__get_current_segment_index(oggbs, &bytesRemainingInSeg);
+ ma_uint32 bytesToEndOfPacketOrPage = bytesRemainingInSeg;
+ for (ma_uint8 iSeg = iFirstSeg; iSeg < oggbs->currentPageHeader.segmentCount; ++iSeg) {
+ ma_uint8 segmentSize = oggbs->currentPageHeader.segmentTable[iSeg];
if (segmentSize < 255) {
if (iSeg == oggbs->currentPageHeader.segmentCount-1) {
- atEndOfPage = DRFLAC_TRUE;
+ atEndOfPage = MA_TRUE;
}
break;
}
bytesToEndOfPacketOrPage += segmentSize;
}
- drflac_oggbs__seek_physical(oggbs, bytesToEndOfPacketOrPage, drflac_seek_origin_current);
+ ma_dr_flac_oggbs__seek_physical(oggbs, bytesToEndOfPacketOrPage, ma_dr_flac_seek_origin_current);
oggbs->bytesRemainingInPage -= bytesToEndOfPacketOrPage;
if (atEndOfPage) {
- if (!drflac_oggbs__goto_next_page(oggbs)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac_oggbs__goto_next_page(oggbs)) {
+ return MA_FALSE;
}
if ((oggbs->currentPageHeader.headerType & 0x01) == 0) {
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
} else {
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
}
}
-static drflac_bool32 drflac_oggbs__seek_to_next_frame(drflac_oggbs* oggbs)
+static ma_bool32 ma_dr_flac_oggbs__seek_to_next_frame(ma_dr_flac_oggbs* oggbs)
{
- return drflac_oggbs__seek_to_next_packet(oggbs);
+ return ma_dr_flac_oggbs__seek_to_next_packet(oggbs);
}
#endif
-static size_t drflac__on_read_ogg(void* pUserData, void* bufferOut, size_t bytesToRead)
+static size_t ma_dr_flac__on_read_ogg(void* pUserData, void* bufferOut, size_t bytesToRead)
{
- drflac_oggbs* oggbs = (drflac_oggbs*)pUserData;
- drflac_uint8* pRunningBufferOut = (drflac_uint8*)bufferOut;
+ ma_dr_flac_oggbs* oggbs = (ma_dr_flac_oggbs*)pUserData;
+ ma_uint8* pRunningBufferOut = (ma_uint8*)bufferOut;
size_t bytesRead = 0;
- DRFLAC_ASSERT(oggbs != NULL);
- DRFLAC_ASSERT(pRunningBufferOut != NULL);
+ MA_DR_FLAC_ASSERT(oggbs != NULL);
+ MA_DR_FLAC_ASSERT(pRunningBufferOut != NULL);
while (bytesRead < bytesToRead) {
size_t bytesRemainingToRead = bytesToRead - bytesRead;
if (oggbs->bytesRemainingInPage >= bytesRemainingToRead) {
- DRFLAC_COPY_MEMORY(pRunningBufferOut, oggbs->pageData + (oggbs->pageDataSize - oggbs->bytesRemainingInPage), bytesRemainingToRead);
+ MA_DR_FLAC_COPY_MEMORY(pRunningBufferOut, oggbs->pageData + (oggbs->pageDataSize - oggbs->bytesRemainingInPage), bytesRemainingToRead);
bytesRead += bytesRemainingToRead;
- oggbs->bytesRemainingInPage -= (drflac_uint32)bytesRemainingToRead;
+ oggbs->bytesRemainingInPage -= (ma_uint32)bytesRemainingToRead;
break;
}
if (oggbs->bytesRemainingInPage > 0) {
- DRFLAC_COPY_MEMORY(pRunningBufferOut, oggbs->pageData + (oggbs->pageDataSize - oggbs->bytesRemainingInPage), oggbs->bytesRemainingInPage);
+ MA_DR_FLAC_COPY_MEMORY(pRunningBufferOut, oggbs->pageData + (oggbs->pageDataSize - oggbs->bytesRemainingInPage), oggbs->bytesRemainingInPage);
bytesRead += oggbs->bytesRemainingInPage;
pRunningBufferOut += oggbs->bytesRemainingInPage;
oggbs->bytesRemainingInPage = 0;
}
- DRFLAC_ASSERT(bytesRemainingToRead > 0);
- if (!drflac_oggbs__goto_next_page(oggbs, drflac_ogg_recover_on_crc_mismatch)) {
+ MA_DR_FLAC_ASSERT(bytesRemainingToRead > 0);
+ if (!ma_dr_flac_oggbs__goto_next_page(oggbs, ma_dr_flac_ogg_recover_on_crc_mismatch)) {
break;
}
}
return bytesRead;
}
-static drflac_bool32 drflac__on_seek_ogg(void* pUserData, int offset, drflac_seek_origin origin)
+static ma_bool32 ma_dr_flac__on_seek_ogg(void* pUserData, int offset, ma_dr_flac_seek_origin origin)
{
- drflac_oggbs* oggbs = (drflac_oggbs*)pUserData;
+ ma_dr_flac_oggbs* oggbs = (ma_dr_flac_oggbs*)pUserData;
int bytesSeeked = 0;
- DRFLAC_ASSERT(oggbs != NULL);
- DRFLAC_ASSERT(offset >= 0);
- if (origin == drflac_seek_origin_start) {
- if (!drflac_oggbs__seek_physical(oggbs, (int)oggbs->firstBytePos, drflac_seek_origin_start)) {
- return DRFLAC_FALSE;
+ MA_DR_FLAC_ASSERT(oggbs != NULL);
+ MA_DR_FLAC_ASSERT(offset >= 0);
+ if (origin == ma_dr_flac_seek_origin_start) {
+ if (!ma_dr_flac_oggbs__seek_physical(oggbs, (int)oggbs->firstBytePos, ma_dr_flac_seek_origin_start)) {
+ return MA_FALSE;
}
- if (!drflac_oggbs__goto_next_page(oggbs, drflac_ogg_fail_on_crc_mismatch)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac_oggbs__goto_next_page(oggbs, ma_dr_flac_ogg_fail_on_crc_mismatch)) {
+ return MA_FALSE;
}
- return drflac__on_seek_ogg(pUserData, offset, drflac_seek_origin_current);
+ return ma_dr_flac__on_seek_ogg(pUserData, offset, ma_dr_flac_seek_origin_current);
}
- DRFLAC_ASSERT(origin == drflac_seek_origin_current);
+ MA_DR_FLAC_ASSERT(origin == ma_dr_flac_seek_origin_current);
while (bytesSeeked < offset) {
int bytesRemainingToSeek = offset - bytesSeeked;
- DRFLAC_ASSERT(bytesRemainingToSeek >= 0);
+ MA_DR_FLAC_ASSERT(bytesRemainingToSeek >= 0);
if (oggbs->bytesRemainingInPage >= (size_t)bytesRemainingToSeek) {
bytesSeeked += bytesRemainingToSeek;
(void)bytesSeeked;
@@ -84213,39 +86645,39 @@ static drflac_bool32 drflac__on_seek_ogg(void* pUserData, int offset, drflac_see
bytesSeeked += (int)oggbs->bytesRemainingInPage;
oggbs->bytesRemainingInPage = 0;
}
- DRFLAC_ASSERT(bytesRemainingToSeek > 0);
- if (!drflac_oggbs__goto_next_page(oggbs, drflac_ogg_fail_on_crc_mismatch)) {
- return DRFLAC_FALSE;
+ MA_DR_FLAC_ASSERT(bytesRemainingToSeek > 0);
+ if (!ma_dr_flac_oggbs__goto_next_page(oggbs, ma_dr_flac_ogg_fail_on_crc_mismatch)) {
+ return MA_FALSE;
}
}
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
-static drflac_bool32 drflac_ogg__seek_to_pcm_frame(drflac* pFlac, drflac_uint64 pcmFrameIndex)
+static ma_bool32 ma_dr_flac_ogg__seek_to_pcm_frame(ma_dr_flac* pFlac, ma_uint64 pcmFrameIndex)
{
- drflac_oggbs* oggbs = (drflac_oggbs*)pFlac->_oggbs;
- drflac_uint64 originalBytePos;
- drflac_uint64 runningGranulePosition;
- drflac_uint64 runningFrameBytePos;
- drflac_uint64 runningPCMFrameCount;
- DRFLAC_ASSERT(oggbs != NULL);
+ ma_dr_flac_oggbs* oggbs = (ma_dr_flac_oggbs*)pFlac->_oggbs;
+ ma_uint64 originalBytePos;
+ ma_uint64 runningGranulePosition;
+ ma_uint64 runningFrameBytePos;
+ ma_uint64 runningPCMFrameCount;
+ MA_DR_FLAC_ASSERT(oggbs != NULL);
originalBytePos = oggbs->currentBytePos;
- if (!drflac__seek_to_byte(&pFlac->bs, pFlac->firstFLACFramePosInBytes)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac__seek_to_byte(&pFlac->bs, pFlac->firstFLACFramePosInBytes)) {
+ return MA_FALSE;
}
oggbs->bytesRemainingInPage = 0;
runningGranulePosition = 0;
for (;;) {
- if (!drflac_oggbs__goto_next_page(oggbs, drflac_ogg_recover_on_crc_mismatch)) {
- drflac_oggbs__seek_physical(oggbs, originalBytePos, drflac_seek_origin_start);
- return DRFLAC_FALSE;
+ if (!ma_dr_flac_oggbs__goto_next_page(oggbs, ma_dr_flac_ogg_recover_on_crc_mismatch)) {
+ ma_dr_flac_oggbs__seek_physical(oggbs, originalBytePos, ma_dr_flac_seek_origin_start);
+ return MA_FALSE;
}
- runningFrameBytePos = oggbs->currentBytePos - drflac_ogg__get_page_header_size(&oggbs->currentPageHeader) - oggbs->pageDataSize;
+ runningFrameBytePos = oggbs->currentBytePos - ma_dr_flac_ogg__get_page_header_size(&oggbs->currentPageHeader) - oggbs->pageDataSize;
if (oggbs->currentPageHeader.granulePosition >= pcmFrameIndex) {
break;
}
if ((oggbs->currentPageHeader.headerType & 0x01) == 0) {
if (oggbs->currentPageHeader.segmentTable[0] >= 2) {
- drflac_uint8 firstBytesInPage[2];
+ ma_uint8 firstBytesInPage[2];
firstBytesInPage[0] = oggbs->pageData[0];
firstBytesInPage[1] = oggbs->pageData[1];
if ((firstBytesInPage[0] == 0xFF) && (firstBytesInPage[1] & 0xFC) == 0xF8) {
@@ -84255,120 +86687,120 @@ static drflac_bool32 drflac_ogg__seek_to_pcm_frame(drflac* pFlac, drflac_uint64
}
}
}
- if (!drflac_oggbs__seek_physical(oggbs, runningFrameBytePos, drflac_seek_origin_start)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac_oggbs__seek_physical(oggbs, runningFrameBytePos, ma_dr_flac_seek_origin_start)) {
+ return MA_FALSE;
}
- if (!drflac_oggbs__goto_next_page(oggbs, drflac_ogg_recover_on_crc_mismatch)) {
- return DRFLAC_FALSE;
+ if (!ma_dr_flac_oggbs__goto_next_page(oggbs, ma_dr_flac_ogg_recover_on_crc_mismatch)) {
+ return MA_FALSE;
}
runningPCMFrameCount = runningGranulePosition;
for (;;) {
- drflac_uint64 firstPCMFrameInFLACFrame = 0;
- drflac_uint64 lastPCMFrameInFLACFrame = 0;
- drflac_uint64 pcmFrameCountInThisFrame;
- if (!drflac__read_next_flac_frame_header(&pFlac->bs, pFlac->bitsPerSample, &pFlac->currentFLACFrame.header)) {
- return DRFLAC_FALSE;
+ ma_uint64 firstPCMFrameInFLACFrame = 0;
+ ma_uint64 lastPCMFrameInFLACFrame = 0;
+ ma_uint64 pcmFrameCountInThisFrame;
+ if (!ma_dr_flac__read_next_flac_frame_header(&pFlac->bs, pFlac->bitsPerSample, &pFlac->currentFLACFrame.header)) {
+ return MA_FALSE;
}
- drflac__get_pcm_frame_range_of_current_flac_frame(pFlac, &firstPCMFrameInFLACFrame, &lastPCMFrameInFLACFrame);
+ ma_dr_flac__get_pcm_frame_range_of_current_flac_frame(pFlac, &firstPCMFrameInFLACFrame, &lastPCMFrameInFLACFrame);
pcmFrameCountInThisFrame = (lastPCMFrameInFLACFrame - firstPCMFrameInFLACFrame) + 1;
if (pcmFrameIndex == pFlac->totalPCMFrameCount && (runningPCMFrameCount + pcmFrameCountInThisFrame) == pFlac->totalPCMFrameCount) {
- drflac_result result = drflac__decode_flac_frame(pFlac);
- if (result == DRFLAC_SUCCESS) {
+ ma_result result = ma_dr_flac__decode_flac_frame(pFlac);
+ if (result == MA_SUCCESS) {
pFlac->currentPCMFrame = pcmFrameIndex;
pFlac->currentFLACFrame.pcmFramesRemaining = 0;
- return DRFLAC_TRUE;
+ return MA_TRUE;
} else {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
}
if (pcmFrameIndex < (runningPCMFrameCount + pcmFrameCountInThisFrame)) {
- drflac_result result = drflac__decode_flac_frame(pFlac);
- if (result == DRFLAC_SUCCESS) {
- drflac_uint64 pcmFramesToDecode = (size_t)(pcmFrameIndex - runningPCMFrameCount);
+ ma_result result = ma_dr_flac__decode_flac_frame(pFlac);
+ if (result == MA_SUCCESS) {
+ ma_uint64 pcmFramesToDecode = (size_t)(pcmFrameIndex - runningPCMFrameCount);
if (pcmFramesToDecode == 0) {
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
pFlac->currentPCMFrame = runningPCMFrameCount;
- return drflac__seek_forward_by_pcm_frames(pFlac, pcmFramesToDecode) == pcmFramesToDecode;
+ return ma_dr_flac__seek_forward_by_pcm_frames(pFlac, pcmFramesToDecode) == pcmFramesToDecode;
} else {
- if (result == DRFLAC_CRC_MISMATCH) {
+ if (result == MA_CRC_MISMATCH) {
continue;
} else {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
}
} else {
- drflac_result result = drflac__seek_to_next_flac_frame(pFlac);
- if (result == DRFLAC_SUCCESS) {
+ ma_result result = ma_dr_flac__seek_to_next_flac_frame(pFlac);
+ if (result == MA_SUCCESS) {
runningPCMFrameCount += pcmFrameCountInThisFrame;
} else {
- if (result == DRFLAC_CRC_MISMATCH) {
+ if (result == MA_CRC_MISMATCH) {
continue;
} else {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
}
}
}
}
-static drflac_bool32 drflac__init_private__ogg(drflac_init_info* pInit, drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_meta_proc onMeta, void* pUserData, void* pUserDataMD, drflac_bool32 relaxed)
+static ma_bool32 ma_dr_flac__init_private__ogg(ma_dr_flac_init_info* pInit, ma_dr_flac_read_proc onRead, ma_dr_flac_seek_proc onSeek, ma_dr_flac_meta_proc onMeta, void* pUserData, void* pUserDataMD, ma_bool32 relaxed)
{
- drflac_ogg_page_header header;
- drflac_uint32 crc32 = DRFLAC_OGG_CAPTURE_PATTERN_CRC32;
- drflac_uint32 bytesRead = 0;
+ ma_dr_flac_ogg_page_header header;
+ ma_uint32 crc32 = MA_DR_FLAC_OGG_CAPTURE_PATTERN_CRC32;
+ ma_uint32 bytesRead = 0;
(void)relaxed;
- pInit->container = drflac_container_ogg;
+ pInit->container = ma_dr_flac_container_ogg;
pInit->oggFirstBytePos = 0;
- if (drflac_ogg__read_page_header_after_capture_pattern(onRead, pUserData, &header, &bytesRead, &crc32) != DRFLAC_SUCCESS) {
- return DRFLAC_FALSE;
+ if (ma_dr_flac_ogg__read_page_header_after_capture_pattern(onRead, pUserData, &header, &bytesRead, &crc32) != MA_SUCCESS) {
+ return MA_FALSE;
}
pInit->runningFilePos += bytesRead;
for (;;) {
int pageBodySize;
if ((header.headerType & 0x02) == 0) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
- pageBodySize = drflac_ogg__get_page_body_size(&header);
+ pageBodySize = ma_dr_flac_ogg__get_page_body_size(&header);
if (pageBodySize == 51) {
- drflac_uint32 bytesRemainingInPage = pageBodySize;
- drflac_uint8 packetType;
+ ma_uint32 bytesRemainingInPage = pageBodySize;
+ ma_uint8 packetType;
if (onRead(pUserData, &packetType, 1) != 1) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
bytesRemainingInPage -= 1;
if (packetType == 0x7F) {
- drflac_uint8 sig[4];
+ ma_uint8 sig[4];
if (onRead(pUserData, sig, 4) != 4) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
bytesRemainingInPage -= 4;
if (sig[0] == 'F' && sig[1] == 'L' && sig[2] == 'A' && sig[3] == 'C') {
- drflac_uint8 mappingVersion[2];
+ ma_uint8 mappingVersion[2];
if (onRead(pUserData, mappingVersion, 2) != 2) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
if (mappingVersion[0] != 1) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
- if (!onSeek(pUserData, 2, drflac_seek_origin_current)) {
- return DRFLAC_FALSE;
+ if (!onSeek(pUserData, 2, ma_dr_flac_seek_origin_current)) {
+ return MA_FALSE;
}
if (onRead(pUserData, sig, 4) != 4) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
if (sig[0] == 'f' && sig[1] == 'L' && sig[2] == 'a' && sig[3] == 'C') {
- drflac_streaminfo streaminfo;
- drflac_uint8 isLastBlock;
- drflac_uint8 blockType;
- drflac_uint32 blockSize;
- if (!drflac__read_and_decode_block_header(onRead, pUserData, &isLastBlock, &blockType, &blockSize)) {
- return DRFLAC_FALSE;
+ ma_dr_flac_streaminfo streaminfo;
+ ma_uint8 isLastBlock;
+ ma_uint8 blockType;
+ ma_uint32 blockSize;
+ if (!ma_dr_flac__read_and_decode_block_header(onRead, pUserData, &isLastBlock, &blockType, &blockSize)) {
+ return MA_FALSE;
}
- if (blockType != DRFLAC_METADATA_BLOCK_TYPE_STREAMINFO || blockSize != 34) {
- return DRFLAC_FALSE;
+ if (blockType != MA_DR_FLAC_METADATA_BLOCK_TYPE_STREAMINFO || blockSize != 34) {
+ return MA_FALSE;
}
- if (drflac__read_streaminfo(onRead, pUserData, &streaminfo)) {
- pInit->hasStreamInfoBlock = DRFLAC_TRUE;
+ if (ma_dr_flac__read_streaminfo(onRead, pUserData, &streaminfo)) {
+ pInit->hasStreamInfoBlock = MA_TRUE;
pInit->sampleRate = streaminfo.sampleRate;
pInit->channels = streaminfo.channels;
pInit->bitsPerSample = streaminfo.bitsPerSample;
@@ -84376,8 +86808,8 @@ static drflac_bool32 drflac__init_private__ogg(drflac_init_info* pInit, drflac_r
pInit->maxBlockSizeInPCMFrames = streaminfo.maxBlockSizeInPCMFrames;
pInit->hasMetadataBlocks = !isLastBlock;
if (onMeta) {
- drflac_metadata metadata;
- metadata.type = DRFLAC_METADATA_BLOCK_TYPE_STREAMINFO;
+ ma_dr_flac_metadata metadata;
+ metadata.type = MA_DR_FLAC_METADATA_BLOCK_TYPE_STREAMINFO;
metadata.pRawData = NULL;
metadata.rawDataSize = 0;
metadata.data.streaminfo = streaminfo;
@@ -84389,44 +86821,44 @@ static drflac_bool32 drflac__init_private__ogg(drflac_init_info* pInit, drflac_r
pInit->oggBosHeader = header;
break;
} else {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
} else {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
} else {
- if (!onSeek(pUserData, bytesRemainingInPage, drflac_seek_origin_current)) {
- return DRFLAC_FALSE;
+ if (!onSeek(pUserData, bytesRemainingInPage, ma_dr_flac_seek_origin_current)) {
+ return MA_FALSE;
}
}
} else {
- if (!onSeek(pUserData, bytesRemainingInPage, drflac_seek_origin_current)) {
- return DRFLAC_FALSE;
+ if (!onSeek(pUserData, bytesRemainingInPage, ma_dr_flac_seek_origin_current)) {
+ return MA_FALSE;
}
}
} else {
- if (!onSeek(pUserData, pageBodySize, drflac_seek_origin_current)) {
- return DRFLAC_FALSE;
+ if (!onSeek(pUserData, pageBodySize, ma_dr_flac_seek_origin_current)) {
+ return MA_FALSE;
}
}
pInit->runningFilePos += pageBodySize;
- if (drflac_ogg__read_page_header(onRead, pUserData, &header, &bytesRead, &crc32) != DRFLAC_SUCCESS) {
- return DRFLAC_FALSE;
+ if (ma_dr_flac_ogg__read_page_header(onRead, pUserData, &header, &bytesRead, &crc32) != MA_SUCCESS) {
+ return MA_FALSE;
}
pInit->runningFilePos += bytesRead;
}
- pInit->hasMetadataBlocks = DRFLAC_TRUE;
- return DRFLAC_TRUE;
+ pInit->hasMetadataBlocks = MA_TRUE;
+ return MA_TRUE;
}
#endif
-static drflac_bool32 drflac__init_private(drflac_init_info* pInit, drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_meta_proc onMeta, drflac_container container, void* pUserData, void* pUserDataMD)
+static ma_bool32 ma_dr_flac__init_private(ma_dr_flac_init_info* pInit, ma_dr_flac_read_proc onRead, ma_dr_flac_seek_proc onSeek, ma_dr_flac_meta_proc onMeta, ma_dr_flac_container container, void* pUserData, void* pUserDataMD)
{
- drflac_bool32 relaxed;
- drflac_uint8 id[4];
+ ma_bool32 relaxed;
+ ma_uint8 id[4];
if (pInit == NULL || onRead == NULL || onSeek == NULL) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
- DRFLAC_ZERO_MEMORY(pInit, sizeof(*pInit));
+ MA_DR_FLAC_ZERO_MEMORY(pInit, sizeof(*pInit));
pInit->onRead = onRead;
pInit->onSeek = onSeek;
pInit->onMeta = onMeta;
@@ -84436,29 +86868,29 @@ static drflac_bool32 drflac__init_private(drflac_init_info* pInit, drflac_read_p
pInit->bs.onRead = onRead;
pInit->bs.onSeek = onSeek;
pInit->bs.pUserData = pUserData;
- drflac__reset_cache(&pInit->bs);
- relaxed = container != drflac_container_unknown;
+ ma_dr_flac__reset_cache(&pInit->bs);
+ relaxed = container != ma_dr_flac_container_unknown;
for (;;) {
if (onRead(pUserData, id, 4) != 4) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
pInit->runningFilePos += 4;
if (id[0] == 'I' && id[1] == 'D' && id[2] == '3') {
- drflac_uint8 header[6];
- drflac_uint8 flags;
- drflac_uint32 headerSize;
+ ma_uint8 header[6];
+ ma_uint8 flags;
+ ma_uint32 headerSize;
if (onRead(pUserData, header, 6) != 6) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
pInit->runningFilePos += 6;
flags = header[1];
- DRFLAC_COPY_MEMORY(&headerSize, header+2, 4);
- headerSize = drflac__unsynchsafe_32(drflac__be2host_32(headerSize));
+ MA_DR_FLAC_COPY_MEMORY(&headerSize, header+2, 4);
+ headerSize = ma_dr_flac__unsynchsafe_32(ma_dr_flac__be2host_32(headerSize));
if (flags & 0x10) {
headerSize += 10;
}
- if (!onSeek(pUserData, headerSize, drflac_seek_origin_current)) {
- return DRFLAC_FALSE;
+ if (!onSeek(pUserData, headerSize, ma_dr_flac_seek_origin_current)) {
+ return MA_FALSE;
}
pInit->runningFilePos += headerSize;
} else {
@@ -84466,56 +86898,56 @@ static drflac_bool32 drflac__init_private(drflac_init_info* pInit, drflac_read_p
}
}
if (id[0] == 'f' && id[1] == 'L' && id[2] == 'a' && id[3] == 'C') {
- return drflac__init_private__native(pInit, onRead, onSeek, onMeta, pUserData, pUserDataMD, relaxed);
+ return ma_dr_flac__init_private__native(pInit, onRead, onSeek, onMeta, pUserData, pUserDataMD, relaxed);
}
-#ifndef DR_FLAC_NO_OGG
+#ifndef MA_DR_FLAC_NO_OGG
if (id[0] == 'O' && id[1] == 'g' && id[2] == 'g' && id[3] == 'S') {
- return drflac__init_private__ogg(pInit, onRead, onSeek, onMeta, pUserData, pUserDataMD, relaxed);
+ return ma_dr_flac__init_private__ogg(pInit, onRead, onSeek, onMeta, pUserData, pUserDataMD, relaxed);
}
#endif
if (relaxed) {
- if (container == drflac_container_native) {
- return drflac__init_private__native(pInit, onRead, onSeek, onMeta, pUserData, pUserDataMD, relaxed);
+ if (container == ma_dr_flac_container_native) {
+ return ma_dr_flac__init_private__native(pInit, onRead, onSeek, onMeta, pUserData, pUserDataMD, relaxed);
}
-#ifndef DR_FLAC_NO_OGG
- if (container == drflac_container_ogg) {
- return drflac__init_private__ogg(pInit, onRead, onSeek, onMeta, pUserData, pUserDataMD, relaxed);
+#ifndef MA_DR_FLAC_NO_OGG
+ if (container == ma_dr_flac_container_ogg) {
+ return ma_dr_flac__init_private__ogg(pInit, onRead, onSeek, onMeta, pUserData, pUserDataMD, relaxed);
}
#endif
}
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
-static void drflac__init_from_info(drflac* pFlac, const drflac_init_info* pInit)
+static void ma_dr_flac__init_from_info(ma_dr_flac* pFlac, const ma_dr_flac_init_info* pInit)
{
- DRFLAC_ASSERT(pFlac != NULL);
- DRFLAC_ASSERT(pInit != NULL);
- DRFLAC_ZERO_MEMORY(pFlac, sizeof(*pFlac));
+ MA_DR_FLAC_ASSERT(pFlac != NULL);
+ MA_DR_FLAC_ASSERT(pInit != NULL);
+ MA_DR_FLAC_ZERO_MEMORY(pFlac, sizeof(*pFlac));
pFlac->bs = pInit->bs;
pFlac->onMeta = pInit->onMeta;
pFlac->pUserDataMD = pInit->pUserDataMD;
pFlac->maxBlockSizeInPCMFrames = pInit->maxBlockSizeInPCMFrames;
pFlac->sampleRate = pInit->sampleRate;
- pFlac->channels = (drflac_uint8)pInit->channels;
- pFlac->bitsPerSample = (drflac_uint8)pInit->bitsPerSample;
+ pFlac->channels = (ma_uint8)pInit->channels;
+ pFlac->bitsPerSample = (ma_uint8)pInit->bitsPerSample;
pFlac->totalPCMFrameCount = pInit->totalPCMFrameCount;
pFlac->container = pInit->container;
}
-static drflac* drflac_open_with_metadata_private(drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_meta_proc onMeta, drflac_container container, void* pUserData, void* pUserDataMD, const drflac_allocation_callbacks* pAllocationCallbacks)
-{
- drflac_init_info init;
- drflac_uint32 allocationSize;
- drflac_uint32 wholeSIMDVectorCountPerChannel;
- drflac_uint32 decodedSamplesAllocationSize;
-#ifndef DR_FLAC_NO_OGG
- drflac_oggbs* pOggbs = NULL;
-#endif
- drflac_uint64 firstFramePos;
- drflac_uint64 seektablePos;
- drflac_uint32 seekpointCount;
- drflac_allocation_callbacks allocationCallbacks;
- drflac* pFlac;
- drflac__init_cpu_caps();
- if (!drflac__init_private(&init, onRead, onSeek, onMeta, container, pUserData, pUserDataMD)) {
+static ma_dr_flac* ma_dr_flac_open_with_metadata_private(ma_dr_flac_read_proc onRead, ma_dr_flac_seek_proc onSeek, ma_dr_flac_meta_proc onMeta, ma_dr_flac_container container, void* pUserData, void* pUserDataMD, const ma_allocation_callbacks* pAllocationCallbacks)
+{
+ ma_dr_flac_init_info init;
+ ma_uint32 allocationSize;
+ ma_uint32 wholeSIMDVectorCountPerChannel;
+ ma_uint32 decodedSamplesAllocationSize;
+#ifndef MA_DR_FLAC_NO_OGG
+ ma_dr_flac_oggbs* pOggbs = NULL;
+#endif
+ ma_uint64 firstFramePos;
+ ma_uint64 seektablePos;
+ ma_uint32 seekpointCount;
+ ma_allocation_callbacks allocationCallbacks;
+ ma_dr_flac* pFlac;
+ ma_dr_flac__init_cpu_caps();
+ if (!ma_dr_flac__init_private(&init, onRead, onSeek, onMeta, container, pUserData, pUserDataMD)) {
return NULL;
}
if (pAllocationCallbacks != NULL) {
@@ -84525,27 +86957,27 @@ static drflac* drflac_open_with_metadata_private(drflac_read_proc onRead, drflac
}
} else {
allocationCallbacks.pUserData = NULL;
- allocationCallbacks.onMalloc = drflac__malloc_default;
- allocationCallbacks.onRealloc = drflac__realloc_default;
- allocationCallbacks.onFree = drflac__free_default;
+ allocationCallbacks.onMalloc = ma_dr_flac__malloc_default;
+ allocationCallbacks.onRealloc = ma_dr_flac__realloc_default;
+ allocationCallbacks.onFree = ma_dr_flac__free_default;
}
- allocationSize = sizeof(drflac);
- if ((init.maxBlockSizeInPCMFrames % (DRFLAC_MAX_SIMD_VECTOR_SIZE / sizeof(drflac_int32))) == 0) {
- wholeSIMDVectorCountPerChannel = (init.maxBlockSizeInPCMFrames / (DRFLAC_MAX_SIMD_VECTOR_SIZE / sizeof(drflac_int32)));
+ allocationSize = sizeof(ma_dr_flac);
+ if ((init.maxBlockSizeInPCMFrames % (MA_DR_FLAC_MAX_SIMD_VECTOR_SIZE / sizeof(ma_int32))) == 0) {
+ wholeSIMDVectorCountPerChannel = (init.maxBlockSizeInPCMFrames / (MA_DR_FLAC_MAX_SIMD_VECTOR_SIZE / sizeof(ma_int32)));
} else {
- wholeSIMDVectorCountPerChannel = (init.maxBlockSizeInPCMFrames / (DRFLAC_MAX_SIMD_VECTOR_SIZE / sizeof(drflac_int32))) + 1;
+ wholeSIMDVectorCountPerChannel = (init.maxBlockSizeInPCMFrames / (MA_DR_FLAC_MAX_SIMD_VECTOR_SIZE / sizeof(ma_int32))) + 1;
}
- decodedSamplesAllocationSize = wholeSIMDVectorCountPerChannel * DRFLAC_MAX_SIMD_VECTOR_SIZE * init.channels;
+ decodedSamplesAllocationSize = wholeSIMDVectorCountPerChannel * MA_DR_FLAC_MAX_SIMD_VECTOR_SIZE * init.channels;
allocationSize += decodedSamplesAllocationSize;
- allocationSize += DRFLAC_MAX_SIMD_VECTOR_SIZE;
-#ifndef DR_FLAC_NO_OGG
- if (init.container == drflac_container_ogg) {
- allocationSize += sizeof(drflac_oggbs);
- pOggbs = (drflac_oggbs*)drflac__malloc_from_callbacks(sizeof(*pOggbs), &allocationCallbacks);
+ allocationSize += MA_DR_FLAC_MAX_SIMD_VECTOR_SIZE;
+#ifndef MA_DR_FLAC_NO_OGG
+ if (init.container == ma_dr_flac_container_ogg) {
+ allocationSize += sizeof(ma_dr_flac_oggbs);
+ pOggbs = (ma_dr_flac_oggbs*)ma_dr_flac__malloc_from_callbacks(sizeof(*pOggbs), &allocationCallbacks);
if (pOggbs == NULL) {
return NULL;
}
- DRFLAC_ZERO_MEMORY(pOggbs, sizeof(*pOggbs));
+ MA_DR_FLAC_ZERO_MEMORY(pOggbs, sizeof(*pOggbs));
pOggbs->onRead = onRead;
pOggbs->onSeek = onSeek;
pOggbs->pUserData = pUserData;
@@ -84560,49 +86992,49 @@ static drflac* drflac_open_with_metadata_private(drflac_read_proc onRead, drflac
seektablePos = 0;
seekpointCount = 0;
if (init.hasMetadataBlocks) {
- drflac_read_proc onReadOverride = onRead;
- drflac_seek_proc onSeekOverride = onSeek;
+ ma_dr_flac_read_proc onReadOverride = onRead;
+ ma_dr_flac_seek_proc onSeekOverride = onSeek;
void* pUserDataOverride = pUserData;
-#ifndef DR_FLAC_NO_OGG
- if (init.container == drflac_container_ogg) {
- onReadOverride = drflac__on_read_ogg;
- onSeekOverride = drflac__on_seek_ogg;
+#ifndef MA_DR_FLAC_NO_OGG
+ if (init.container == ma_dr_flac_container_ogg) {
+ onReadOverride = ma_dr_flac__on_read_ogg;
+ onSeekOverride = ma_dr_flac__on_seek_ogg;
pUserDataOverride = (void*)pOggbs;
}
#endif
- if (!drflac__read_and_decode_metadata(onReadOverride, onSeekOverride, onMeta, pUserDataOverride, pUserDataMD, &firstFramePos, &seektablePos, &seekpointCount, &allocationCallbacks)) {
- #ifndef DR_FLAC_NO_OGG
- drflac__free_from_callbacks(pOggbs, &allocationCallbacks);
+ if (!ma_dr_flac__read_and_decode_metadata(onReadOverride, onSeekOverride, onMeta, pUserDataOverride, pUserDataMD, &firstFramePos, &seektablePos, &seekpointCount, &allocationCallbacks)) {
+ #ifndef MA_DR_FLAC_NO_OGG
+ ma_dr_flac__free_from_callbacks(pOggbs, &allocationCallbacks);
#endif
return NULL;
}
- allocationSize += seekpointCount * sizeof(drflac_seekpoint);
+ allocationSize += seekpointCount * sizeof(ma_dr_flac_seekpoint);
}
- pFlac = (drflac*)drflac__malloc_from_callbacks(allocationSize, &allocationCallbacks);
+ pFlac = (ma_dr_flac*)ma_dr_flac__malloc_from_callbacks(allocationSize, &allocationCallbacks);
if (pFlac == NULL) {
- #ifndef DR_FLAC_NO_OGG
- drflac__free_from_callbacks(pOggbs, &allocationCallbacks);
+ #ifndef MA_DR_FLAC_NO_OGG
+ ma_dr_flac__free_from_callbacks(pOggbs, &allocationCallbacks);
#endif
return NULL;
}
- drflac__init_from_info(pFlac, &init);
+ ma_dr_flac__init_from_info(pFlac, &init);
pFlac->allocationCallbacks = allocationCallbacks;
- pFlac->pDecodedSamples = (drflac_int32*)drflac_align((size_t)pFlac->pExtraData, DRFLAC_MAX_SIMD_VECTOR_SIZE);
-#ifndef DR_FLAC_NO_OGG
- if (init.container == drflac_container_ogg) {
- drflac_oggbs* pInternalOggbs = (drflac_oggbs*)((drflac_uint8*)pFlac->pDecodedSamples + decodedSamplesAllocationSize + (seekpointCount * sizeof(drflac_seekpoint)));
- DRFLAC_COPY_MEMORY(pInternalOggbs, pOggbs, sizeof(*pOggbs));
- drflac__free_from_callbacks(pOggbs, &allocationCallbacks);
+ pFlac->pDecodedSamples = (ma_int32*)ma_dr_flac_align((size_t)pFlac->pExtraData, MA_DR_FLAC_MAX_SIMD_VECTOR_SIZE);
+#ifndef MA_DR_FLAC_NO_OGG
+ if (init.container == ma_dr_flac_container_ogg) {
+ ma_dr_flac_oggbs* pInternalOggbs = (ma_dr_flac_oggbs*)((ma_uint8*)pFlac->pDecodedSamples + decodedSamplesAllocationSize + (seekpointCount * sizeof(ma_dr_flac_seekpoint)));
+ MA_DR_FLAC_COPY_MEMORY(pInternalOggbs, pOggbs, sizeof(*pOggbs));
+ ma_dr_flac__free_from_callbacks(pOggbs, &allocationCallbacks);
pOggbs = NULL;
- pFlac->bs.onRead = drflac__on_read_ogg;
- pFlac->bs.onSeek = drflac__on_seek_ogg;
+ pFlac->bs.onRead = ma_dr_flac__on_read_ogg;
+ pFlac->bs.onSeek = ma_dr_flac__on_seek_ogg;
pFlac->bs.pUserData = (void*)pInternalOggbs;
pFlac->_oggbs = (void*)pInternalOggbs;
}
#endif
pFlac->firstFLACFramePosInBytes = firstFramePos;
-#ifndef DR_FLAC_NO_OGG
- if (init.container == drflac_container_ogg)
+#ifndef MA_DR_FLAC_NO_OGG
+ if (init.container == ma_dr_flac_container_ogg)
{
pFlac->pSeekpoints = NULL;
pFlac->seekpointCount = 0;
@@ -84612,24 +87044,24 @@ static drflac* drflac_open_with_metadata_private(drflac_read_proc onRead, drflac
{
if (seektablePos != 0) {
pFlac->seekpointCount = seekpointCount;
- pFlac->pSeekpoints = (drflac_seekpoint*)((drflac_uint8*)pFlac->pDecodedSamples + decodedSamplesAllocationSize);
- DRFLAC_ASSERT(pFlac->bs.onSeek != NULL);
- DRFLAC_ASSERT(pFlac->bs.onRead != NULL);
- if (pFlac->bs.onSeek(pFlac->bs.pUserData, (int)seektablePos, drflac_seek_origin_start)) {
- drflac_uint32 iSeekpoint;
+ pFlac->pSeekpoints = (ma_dr_flac_seekpoint*)((ma_uint8*)pFlac->pDecodedSamples + decodedSamplesAllocationSize);
+ MA_DR_FLAC_ASSERT(pFlac->bs.onSeek != NULL);
+ MA_DR_FLAC_ASSERT(pFlac->bs.onRead != NULL);
+ if (pFlac->bs.onSeek(pFlac->bs.pUserData, (int)seektablePos, ma_dr_flac_seek_origin_start)) {
+ ma_uint32 iSeekpoint;
for (iSeekpoint = 0; iSeekpoint < seekpointCount; iSeekpoint += 1) {
- if (pFlac->bs.onRead(pFlac->bs.pUserData, pFlac->pSeekpoints + iSeekpoint, DRFLAC_SEEKPOINT_SIZE_IN_BYTES) == DRFLAC_SEEKPOINT_SIZE_IN_BYTES) {
- pFlac->pSeekpoints[iSeekpoint].firstPCMFrame = drflac__be2host_64(pFlac->pSeekpoints[iSeekpoint].firstPCMFrame);
- pFlac->pSeekpoints[iSeekpoint].flacFrameOffset = drflac__be2host_64(pFlac->pSeekpoints[iSeekpoint].flacFrameOffset);
- pFlac->pSeekpoints[iSeekpoint].pcmFrameCount = drflac__be2host_16(pFlac->pSeekpoints[iSeekpoint].pcmFrameCount);
+ if (pFlac->bs.onRead(pFlac->bs.pUserData, pFlac->pSeekpoints + iSeekpoint, MA_DR_FLAC_SEEKPOINT_SIZE_IN_BYTES) == MA_DR_FLAC_SEEKPOINT_SIZE_IN_BYTES) {
+ pFlac->pSeekpoints[iSeekpoint].firstPCMFrame = ma_dr_flac__be2host_64(pFlac->pSeekpoints[iSeekpoint].firstPCMFrame);
+ pFlac->pSeekpoints[iSeekpoint].flacFrameOffset = ma_dr_flac__be2host_64(pFlac->pSeekpoints[iSeekpoint].flacFrameOffset);
+ pFlac->pSeekpoints[iSeekpoint].pcmFrameCount = ma_dr_flac__be2host_16(pFlac->pSeekpoints[iSeekpoint].pcmFrameCount);
} else {
pFlac->pSeekpoints = NULL;
pFlac->seekpointCount = 0;
break;
}
}
- if (!pFlac->bs.onSeek(pFlac->bs.pUserData, (int)pFlac->firstFLACFramePosInBytes, drflac_seek_origin_start)) {
- drflac__free_from_callbacks(pFlac, &allocationCallbacks);
+ if (!pFlac->bs.onSeek(pFlac->bs.pUserData, (int)pFlac->firstFLACFramePosInBytes, ma_dr_flac_seek_origin_start)) {
+ ma_dr_flac__free_from_callbacks(pFlac, &allocationCallbacks);
return NULL;
}
} else {
@@ -84641,18 +87073,18 @@ static drflac* drflac_open_with_metadata_private(drflac_read_proc onRead, drflac
if (!init.hasStreamInfoBlock) {
pFlac->currentFLACFrame.header = init.firstFrameHeader;
for (;;) {
- drflac_result result = drflac__decode_flac_frame(pFlac);
- if (result == DRFLAC_SUCCESS) {
+ ma_result result = ma_dr_flac__decode_flac_frame(pFlac);
+ if (result == MA_SUCCESS) {
break;
} else {
- if (result == DRFLAC_CRC_MISMATCH) {
- if (!drflac__read_next_flac_frame_header(&pFlac->bs, pFlac->bitsPerSample, &pFlac->currentFLACFrame.header)) {
- drflac__free_from_callbacks(pFlac, &allocationCallbacks);
+ if (result == MA_CRC_MISMATCH) {
+ if (!ma_dr_flac__read_next_flac_frame_header(&pFlac->bs, pFlac->bitsPerSample, &pFlac->currentFLACFrame.header)) {
+ ma_dr_flac__free_from_callbacks(pFlac, &allocationCallbacks);
return NULL;
}
continue;
} else {
- drflac__free_from_callbacks(pFlac, &allocationCallbacks);
+ ma_dr_flac__free_from_callbacks(pFlac, &allocationCallbacks);
return NULL;
}
}
@@ -84660,555 +87092,43 @@ static drflac* drflac_open_with_metadata_private(drflac_read_proc onRead, drflac
}
return pFlac;
}
-#ifndef DR_FLAC_NO_STDIO
+#ifndef MA_DR_FLAC_NO_STDIO
#include
-#ifndef DR_FLAC_NO_WCHAR
+#ifndef MA_DR_FLAC_NO_WCHAR
#include
#endif
-#include
-static drflac_result drflac_result_from_errno(int e)
-{
- switch (e)
- {
- case 0: return DRFLAC_SUCCESS;
- #ifdef EPERM
- case EPERM: return DRFLAC_INVALID_OPERATION;
- #endif
- #ifdef ENOENT
- case ENOENT: return DRFLAC_DOES_NOT_EXIST;
- #endif
- #ifdef ESRCH
- case ESRCH: return DRFLAC_DOES_NOT_EXIST;
- #endif
- #ifdef EINTR
- case EINTR: return DRFLAC_INTERRUPT;
- #endif
- #ifdef EIO
- case EIO: return DRFLAC_IO_ERROR;
- #endif
- #ifdef ENXIO
- case ENXIO: return DRFLAC_DOES_NOT_EXIST;
- #endif
- #ifdef E2BIG
- case E2BIG: return DRFLAC_INVALID_ARGS;
- #endif
- #ifdef ENOEXEC
- case ENOEXEC: return DRFLAC_INVALID_FILE;
- #endif
- #ifdef EBADF
- case EBADF: return DRFLAC_INVALID_FILE;
- #endif
- #ifdef ECHILD
- case ECHILD: return DRFLAC_ERROR;
- #endif
- #ifdef EAGAIN
- case EAGAIN: return DRFLAC_UNAVAILABLE;
- #endif
- #ifdef ENOMEM
- case ENOMEM: return DRFLAC_OUT_OF_MEMORY;
- #endif
- #ifdef EACCES
- case EACCES: return DRFLAC_ACCESS_DENIED;
- #endif
- #ifdef EFAULT
- case EFAULT: return DRFLAC_BAD_ADDRESS;
- #endif
- #ifdef ENOTBLK
- case ENOTBLK: return DRFLAC_ERROR;
- #endif
- #ifdef EBUSY
- case EBUSY: return DRFLAC_BUSY;
- #endif
- #ifdef EEXIST
- case EEXIST: return DRFLAC_ALREADY_EXISTS;
- #endif
- #ifdef EXDEV
- case EXDEV: return DRFLAC_ERROR;
- #endif
- #ifdef ENODEV
- case ENODEV: return DRFLAC_DOES_NOT_EXIST;
- #endif
- #ifdef ENOTDIR
- case ENOTDIR: return DRFLAC_NOT_DIRECTORY;
- #endif
- #ifdef EISDIR
- case EISDIR: return DRFLAC_IS_DIRECTORY;
- #endif
- #ifdef EINVAL
- case EINVAL: return DRFLAC_INVALID_ARGS;
- #endif
- #ifdef ENFILE
- case ENFILE: return DRFLAC_TOO_MANY_OPEN_FILES;
- #endif
- #ifdef EMFILE
- case EMFILE: return DRFLAC_TOO_MANY_OPEN_FILES;
- #endif
- #ifdef ENOTTY
- case ENOTTY: return DRFLAC_INVALID_OPERATION;
- #endif
- #ifdef ETXTBSY
- case ETXTBSY: return DRFLAC_BUSY;
- #endif
- #ifdef EFBIG
- case EFBIG: return DRFLAC_TOO_BIG;
- #endif
- #ifdef ENOSPC
- case ENOSPC: return DRFLAC_NO_SPACE;
- #endif
- #ifdef ESPIPE
- case ESPIPE: return DRFLAC_BAD_SEEK;
- #endif
- #ifdef EROFS
- case EROFS: return DRFLAC_ACCESS_DENIED;
- #endif
- #ifdef EMLINK
- case EMLINK: return DRFLAC_TOO_MANY_LINKS;
- #endif
- #ifdef EPIPE
- case EPIPE: return DRFLAC_BAD_PIPE;
- #endif
- #ifdef EDOM
- case EDOM: return DRFLAC_OUT_OF_RANGE;
- #endif
- #ifdef ERANGE
- case ERANGE: return DRFLAC_OUT_OF_RANGE;
- #endif
- #ifdef EDEADLK
- case EDEADLK: return DRFLAC_DEADLOCK;
- #endif
- #ifdef ENAMETOOLONG
- case ENAMETOOLONG: return DRFLAC_PATH_TOO_LONG;
- #endif
- #ifdef ENOLCK
- case ENOLCK: return DRFLAC_ERROR;
- #endif
- #ifdef ENOSYS
- case ENOSYS: return DRFLAC_NOT_IMPLEMENTED;
- #endif
- #ifdef ENOTEMPTY
- case ENOTEMPTY: return DRFLAC_DIRECTORY_NOT_EMPTY;
- #endif
- #ifdef ELOOP
- case ELOOP: return DRFLAC_TOO_MANY_LINKS;
- #endif
- #ifdef ENOMSG
- case ENOMSG: return DRFLAC_NO_MESSAGE;
- #endif
- #ifdef EIDRM
- case EIDRM: return DRFLAC_ERROR;
- #endif
- #ifdef ECHRNG
- case ECHRNG: return DRFLAC_ERROR;
- #endif
- #ifdef EL2NSYNC
- case EL2NSYNC: return DRFLAC_ERROR;
- #endif
- #ifdef EL3HLT
- case EL3HLT: return DRFLAC_ERROR;
- #endif
- #ifdef EL3RST
- case EL3RST: return DRFLAC_ERROR;
- #endif
- #ifdef ELNRNG
- case ELNRNG: return DRFLAC_OUT_OF_RANGE;
- #endif
- #ifdef EUNATCH
- case EUNATCH: return DRFLAC_ERROR;
- #endif
- #ifdef ENOCSI
- case ENOCSI: return DRFLAC_ERROR;
- #endif
- #ifdef EL2HLT
- case EL2HLT: return DRFLAC_ERROR;
- #endif
- #ifdef EBADE
- case EBADE: return DRFLAC_ERROR;
- #endif
- #ifdef EBADR
- case EBADR: return DRFLAC_ERROR;
- #endif
- #ifdef EXFULL
- case EXFULL: return DRFLAC_ERROR;
- #endif
- #ifdef ENOANO
- case ENOANO: return DRFLAC_ERROR;
- #endif
- #ifdef EBADRQC
- case EBADRQC: return DRFLAC_ERROR;
- #endif
- #ifdef EBADSLT
- case EBADSLT: return DRFLAC_ERROR;
- #endif
- #ifdef EBFONT
- case EBFONT: return DRFLAC_INVALID_FILE;
- #endif
- #ifdef ENOSTR
- case ENOSTR: return DRFLAC_ERROR;
- #endif
- #ifdef ENODATA
- case ENODATA: return DRFLAC_NO_DATA_AVAILABLE;
- #endif
- #ifdef ETIME
- case ETIME: return DRFLAC_TIMEOUT;
- #endif
- #ifdef ENOSR
- case ENOSR: return DRFLAC_NO_DATA_AVAILABLE;
- #endif
- #ifdef ENONET
- case ENONET: return DRFLAC_NO_NETWORK;
- #endif
- #ifdef ENOPKG
- case ENOPKG: return DRFLAC_ERROR;
- #endif
- #ifdef EREMOTE
- case EREMOTE: return DRFLAC_ERROR;
- #endif
- #ifdef ENOLINK
- case ENOLINK: return DRFLAC_ERROR;
- #endif
- #ifdef EADV
- case EADV: return DRFLAC_ERROR;
- #endif
- #ifdef ESRMNT
- case ESRMNT: return DRFLAC_ERROR;
- #endif
- #ifdef ECOMM
- case ECOMM: return DRFLAC_ERROR;
- #endif
- #ifdef EPROTO
- case EPROTO: return DRFLAC_ERROR;
- #endif
- #ifdef EMULTIHOP
- case EMULTIHOP: return DRFLAC_ERROR;
- #endif
- #ifdef EDOTDOT
- case EDOTDOT: return DRFLAC_ERROR;
- #endif
- #ifdef EBADMSG
- case EBADMSG: return DRFLAC_BAD_MESSAGE;
- #endif
- #ifdef EOVERFLOW
- case EOVERFLOW: return DRFLAC_TOO_BIG;
- #endif
- #ifdef ENOTUNIQ
- case ENOTUNIQ: return DRFLAC_NOT_UNIQUE;
- #endif
- #ifdef EBADFD
- case EBADFD: return DRFLAC_ERROR;
- #endif
- #ifdef EREMCHG
- case EREMCHG: return DRFLAC_ERROR;
- #endif
- #ifdef ELIBACC
- case ELIBACC: return DRFLAC_ACCESS_DENIED;
- #endif
- #ifdef ELIBBAD
- case ELIBBAD: return DRFLAC_INVALID_FILE;
- #endif
- #ifdef ELIBSCN
- case ELIBSCN: return DRFLAC_INVALID_FILE;
- #endif
- #ifdef ELIBMAX
- case ELIBMAX: return DRFLAC_ERROR;
- #endif
- #ifdef ELIBEXEC
- case ELIBEXEC: return DRFLAC_ERROR;
- #endif
- #ifdef EILSEQ
- case EILSEQ: return DRFLAC_INVALID_DATA;
- #endif
- #ifdef ERESTART
- case ERESTART: return DRFLAC_ERROR;
- #endif
- #ifdef ESTRPIPE
- case ESTRPIPE: return DRFLAC_ERROR;
- #endif
- #ifdef EUSERS
- case EUSERS: return DRFLAC_ERROR;
- #endif
- #ifdef ENOTSOCK
- case ENOTSOCK: return DRFLAC_NOT_SOCKET;
- #endif
- #ifdef EDESTADDRREQ
- case EDESTADDRREQ: return DRFLAC_NO_ADDRESS;
- #endif
- #ifdef EMSGSIZE
- case EMSGSIZE: return DRFLAC_TOO_BIG;
- #endif
- #ifdef EPROTOTYPE
- case EPROTOTYPE: return DRFLAC_BAD_PROTOCOL;
- #endif
- #ifdef ENOPROTOOPT
- case ENOPROTOOPT: return DRFLAC_PROTOCOL_UNAVAILABLE;
- #endif
- #ifdef EPROTONOSUPPORT
- case EPROTONOSUPPORT: return DRFLAC_PROTOCOL_NOT_SUPPORTED;
- #endif
- #ifdef ESOCKTNOSUPPORT
- case ESOCKTNOSUPPORT: return DRFLAC_SOCKET_NOT_SUPPORTED;
- #endif
- #ifdef EOPNOTSUPP
- case EOPNOTSUPP: return DRFLAC_INVALID_OPERATION;
- #endif
- #ifdef EPFNOSUPPORT
- case EPFNOSUPPORT: return DRFLAC_PROTOCOL_FAMILY_NOT_SUPPORTED;
- #endif
- #ifdef EAFNOSUPPORT
- case EAFNOSUPPORT: return DRFLAC_ADDRESS_FAMILY_NOT_SUPPORTED;
- #endif
- #ifdef EADDRINUSE
- case EADDRINUSE: return DRFLAC_ALREADY_IN_USE;
- #endif
- #ifdef EADDRNOTAVAIL
- case EADDRNOTAVAIL: return DRFLAC_ERROR;
- #endif
- #ifdef ENETDOWN
- case ENETDOWN: return DRFLAC_NO_NETWORK;
- #endif
- #ifdef ENETUNREACH
- case ENETUNREACH: return DRFLAC_NO_NETWORK;
- #endif
- #ifdef ENETRESET
- case ENETRESET: return DRFLAC_NO_NETWORK;
- #endif
- #ifdef ECONNABORTED
- case ECONNABORTED: return DRFLAC_NO_NETWORK;
- #endif
- #ifdef ECONNRESET
- case ECONNRESET: return DRFLAC_CONNECTION_RESET;
- #endif
- #ifdef ENOBUFS
- case ENOBUFS: return DRFLAC_NO_SPACE;
- #endif
- #ifdef EISCONN
- case EISCONN: return DRFLAC_ALREADY_CONNECTED;
- #endif
- #ifdef ENOTCONN
- case ENOTCONN: return DRFLAC_NOT_CONNECTED;
- #endif
- #ifdef ESHUTDOWN
- case ESHUTDOWN: return DRFLAC_ERROR;
- #endif
- #ifdef ETOOMANYREFS
- case ETOOMANYREFS: return DRFLAC_ERROR;
- #endif
- #ifdef ETIMEDOUT
- case ETIMEDOUT: return DRFLAC_TIMEOUT;
- #endif
- #ifdef ECONNREFUSED
- case ECONNREFUSED: return DRFLAC_CONNECTION_REFUSED;
- #endif
- #ifdef EHOSTDOWN
- case EHOSTDOWN: return DRFLAC_NO_HOST;
- #endif
- #ifdef EHOSTUNREACH
- case EHOSTUNREACH: return DRFLAC_NO_HOST;
- #endif
- #ifdef EALREADY
- case EALREADY: return DRFLAC_IN_PROGRESS;
- #endif
- #ifdef EINPROGRESS
- case EINPROGRESS: return DRFLAC_IN_PROGRESS;
- #endif
- #ifdef ESTALE
- case ESTALE: return DRFLAC_INVALID_FILE;
- #endif
- #ifdef EUCLEAN
- case EUCLEAN: return DRFLAC_ERROR;
- #endif
- #ifdef ENOTNAM
- case ENOTNAM: return DRFLAC_ERROR;
- #endif
- #ifdef ENAVAIL
- case ENAVAIL: return DRFLAC_ERROR;
- #endif
- #ifdef EISNAM
- case EISNAM: return DRFLAC_ERROR;
- #endif
- #ifdef EREMOTEIO
- case EREMOTEIO: return DRFLAC_IO_ERROR;
- #endif
- #ifdef EDQUOT
- case EDQUOT: return DRFLAC_NO_SPACE;
- #endif
- #ifdef ENOMEDIUM
- case ENOMEDIUM: return DRFLAC_DOES_NOT_EXIST;
- #endif
- #ifdef EMEDIUMTYPE
- case EMEDIUMTYPE: return DRFLAC_ERROR;
- #endif
- #ifdef ECANCELED
- case ECANCELED: return DRFLAC_CANCELLED;
- #endif
- #ifdef ENOKEY
- case ENOKEY: return DRFLAC_ERROR;
- #endif
- #ifdef EKEYEXPIRED
- case EKEYEXPIRED: return DRFLAC_ERROR;
- #endif
- #ifdef EKEYREVOKED
- case EKEYREVOKED: return DRFLAC_ERROR;
- #endif
- #ifdef EKEYREJECTED
- case EKEYREJECTED: return DRFLAC_ERROR;
- #endif
- #ifdef EOWNERDEAD
- case EOWNERDEAD: return DRFLAC_ERROR;
- #endif
- #ifdef ENOTRECOVERABLE
- case ENOTRECOVERABLE: return DRFLAC_ERROR;
- #endif
- #ifdef ERFKILL
- case ERFKILL: return DRFLAC_ERROR;
- #endif
- #ifdef EHWPOISON
- case EHWPOISON: return DRFLAC_ERROR;
- #endif
- default: return DRFLAC_ERROR;
- }
-}
-static drflac_result drflac_fopen(FILE** ppFile, const char* pFilePath, const char* pOpenMode)
-{
-#if defined(_MSC_VER) && _MSC_VER >= 1400
- errno_t err;
-#endif
- if (ppFile != NULL) {
- *ppFile = NULL;
- }
- if (pFilePath == NULL || pOpenMode == NULL || ppFile == NULL) {
- return DRFLAC_INVALID_ARGS;
- }
-#if defined(_MSC_VER) && _MSC_VER >= 1400
- err = fopen_s(ppFile, pFilePath, pOpenMode);
- if (err != 0) {
- return drflac_result_from_errno(err);
- }
-#else
-#if defined(_WIN32) || defined(__APPLE__)
- *ppFile = fopen(pFilePath, pOpenMode);
-#else
- #if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64 && defined(_LARGEFILE64_SOURCE)
- *ppFile = fopen64(pFilePath, pOpenMode);
- #else
- *ppFile = fopen(pFilePath, pOpenMode);
- #endif
-#endif
- if (*ppFile == NULL) {
- drflac_result result = drflac_result_from_errno(errno);
- if (result == DRFLAC_SUCCESS) {
- result = DRFLAC_ERROR;
- }
- return result;
- }
-#endif
- return DRFLAC_SUCCESS;
-}
-#if defined(_WIN32)
- #if defined(_MSC_VER) || defined(__MINGW64__) || (!defined(__STRICT_ANSI__) && !defined(_NO_EXT_KEYS))
- #define DRFLAC_HAS_WFOPEN
- #endif
-#endif
-#ifndef DR_FLAC_NO_WCHAR
-static drflac_result drflac_wfopen(FILE** ppFile, const wchar_t* pFilePath, const wchar_t* pOpenMode, const drflac_allocation_callbacks* pAllocationCallbacks)
-{
- if (ppFile != NULL) {
- *ppFile = NULL;
- }
- if (pFilePath == NULL || pOpenMode == NULL || ppFile == NULL) {
- return DRFLAC_INVALID_ARGS;
- }
-#if defined(DRFLAC_HAS_WFOPEN)
- {
- #if defined(_MSC_VER) && _MSC_VER >= 1400
- errno_t err = _wfopen_s(ppFile, pFilePath, pOpenMode);
- if (err != 0) {
- return drflac_result_from_errno(err);
- }
- #else
- *ppFile = _wfopen(pFilePath, pOpenMode);
- if (*ppFile == NULL) {
- return drflac_result_from_errno(errno);
- }
- #endif
- (void)pAllocationCallbacks;
- }
-#else
- #if defined(__DJGPP__)
- {
- }
- #else
- {
- mbstate_t mbs;
- size_t lenMB;
- const wchar_t* pFilePathTemp = pFilePath;
- char* pFilePathMB = NULL;
- char pOpenModeMB[32] = {0};
- DRFLAC_ZERO_OBJECT(&mbs);
- lenMB = wcsrtombs(NULL, &pFilePathTemp, 0, &mbs);
- if (lenMB == (size_t)-1) {
- return drflac_result_from_errno(errno);
- }
- pFilePathMB = (char*)drflac__malloc_from_callbacks(lenMB + 1, pAllocationCallbacks);
- if (pFilePathMB == NULL) {
- return DRFLAC_OUT_OF_MEMORY;
- }
- pFilePathTemp = pFilePath;
- DRFLAC_ZERO_OBJECT(&mbs);
- wcsrtombs(pFilePathMB, &pFilePathTemp, lenMB + 1, &mbs);
- {
- size_t i = 0;
- for (;;) {
- if (pOpenMode[i] == 0) {
- pOpenModeMB[i] = '\0';
- break;
- }
- pOpenModeMB[i] = (char)pOpenMode[i];
- i += 1;
- }
- }
- *ppFile = fopen(pFilePathMB, pOpenModeMB);
- drflac__free_from_callbacks(pFilePathMB, pAllocationCallbacks);
- }
- #endif
- if (*ppFile == NULL) {
- return DRFLAC_ERROR;
- }
-#endif
- return DRFLAC_SUCCESS;
-}
-#endif
-static size_t drflac__on_read_stdio(void* pUserData, void* bufferOut, size_t bytesToRead)
+static size_t ma_dr_flac__on_read_stdio(void* pUserData, void* bufferOut, size_t bytesToRead)
{
return fread(bufferOut, 1, bytesToRead, (FILE*)pUserData);
}
-static drflac_bool32 drflac__on_seek_stdio(void* pUserData, int offset, drflac_seek_origin origin)
+static ma_bool32 ma_dr_flac__on_seek_stdio(void* pUserData, int offset, ma_dr_flac_seek_origin origin)
{
- DRFLAC_ASSERT(offset >= 0);
- return fseek((FILE*)pUserData, offset, (origin == drflac_seek_origin_current) ? SEEK_CUR : SEEK_SET) == 0;
+ MA_DR_FLAC_ASSERT(offset >= 0);
+ return fseek((FILE*)pUserData, offset, (origin == ma_dr_flac_seek_origin_current) ? SEEK_CUR : SEEK_SET) == 0;
}
-DRFLAC_API drflac* drflac_open_file(const char* pFileName, const drflac_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_dr_flac* ma_dr_flac_open_file(const char* pFileName, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drflac* pFlac;
+ ma_dr_flac* pFlac;
FILE* pFile;
- if (drflac_fopen(&pFile, pFileName, "rb") != DRFLAC_SUCCESS) {
+ if (ma_fopen(&pFile, pFileName, "rb") != MA_SUCCESS) {
return NULL;
}
- pFlac = drflac_open(drflac__on_read_stdio, drflac__on_seek_stdio, (void*)pFile, pAllocationCallbacks);
+ pFlac = ma_dr_flac_open(ma_dr_flac__on_read_stdio, ma_dr_flac__on_seek_stdio, (void*)pFile, pAllocationCallbacks);
if (pFlac == NULL) {
fclose(pFile);
return NULL;
}
return pFlac;
}
-#ifndef DR_FLAC_NO_WCHAR
-DRFLAC_API drflac* drflac_open_file_w(const wchar_t* pFileName, const drflac_allocation_callbacks* pAllocationCallbacks)
+#ifndef MA_DR_FLAC_NO_WCHAR
+MA_API ma_dr_flac* ma_dr_flac_open_file_w(const wchar_t* pFileName, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drflac* pFlac;
+ ma_dr_flac* pFlac;
FILE* pFile;
- if (drflac_wfopen(&pFile, pFileName, L"rb", pAllocationCallbacks) != DRFLAC_SUCCESS) {
+ if (ma_wfopen(&pFile, pFileName, L"rb", pAllocationCallbacks) != MA_SUCCESS) {
return NULL;
}
- pFlac = drflac_open(drflac__on_read_stdio, drflac__on_seek_stdio, (void*)pFile, pAllocationCallbacks);
+ pFlac = ma_dr_flac_open(ma_dr_flac__on_read_stdio, ma_dr_flac__on_seek_stdio, (void*)pFile, pAllocationCallbacks);
if (pFlac == NULL) {
fclose(pFile);
return NULL;
@@ -85216,29 +87136,29 @@ DRFLAC_API drflac* drflac_open_file_w(const wchar_t* pFileName, const drflac_all
return pFlac;
}
#endif
-DRFLAC_API drflac* drflac_open_file_with_metadata(const char* pFileName, drflac_meta_proc onMeta, void* pUserData, const drflac_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_dr_flac* ma_dr_flac_open_file_with_metadata(const char* pFileName, ma_dr_flac_meta_proc onMeta, void* pUserData, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drflac* pFlac;
+ ma_dr_flac* pFlac;
FILE* pFile;
- if (drflac_fopen(&pFile, pFileName, "rb") != DRFLAC_SUCCESS) {
+ if (ma_fopen(&pFile, pFileName, "rb") != MA_SUCCESS) {
return NULL;
}
- pFlac = drflac_open_with_metadata_private(drflac__on_read_stdio, drflac__on_seek_stdio, onMeta, drflac_container_unknown, (void*)pFile, pUserData, pAllocationCallbacks);
+ pFlac = ma_dr_flac_open_with_metadata_private(ma_dr_flac__on_read_stdio, ma_dr_flac__on_seek_stdio, onMeta, ma_dr_flac_container_unknown, (void*)pFile, pUserData, pAllocationCallbacks);
if (pFlac == NULL) {
fclose(pFile);
return pFlac;
}
return pFlac;
}
-#ifndef DR_FLAC_NO_WCHAR
-DRFLAC_API drflac* drflac_open_file_with_metadata_w(const wchar_t* pFileName, drflac_meta_proc onMeta, void* pUserData, const drflac_allocation_callbacks* pAllocationCallbacks)
+#ifndef MA_DR_FLAC_NO_WCHAR
+MA_API ma_dr_flac* ma_dr_flac_open_file_with_metadata_w(const wchar_t* pFileName, ma_dr_flac_meta_proc onMeta, void* pUserData, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drflac* pFlac;
+ ma_dr_flac* pFlac;
FILE* pFile;
- if (drflac_wfopen(&pFile, pFileName, L"rb", pAllocationCallbacks) != DRFLAC_SUCCESS) {
+ if (ma_wfopen(&pFile, pFileName, L"rb", pAllocationCallbacks) != MA_SUCCESS) {
return NULL;
}
- pFlac = drflac_open_with_metadata_private(drflac__on_read_stdio, drflac__on_seek_stdio, onMeta, drflac_container_unknown, (void*)pFile, pUserData, pAllocationCallbacks);
+ pFlac = ma_dr_flac_open_with_metadata_private(ma_dr_flac__on_read_stdio, ma_dr_flac__on_seek_stdio, onMeta, ma_dr_flac_container_unknown, (void*)pFile, pUserData, pAllocationCallbacks);
if (pFlac == NULL) {
fclose(pFile);
return pFlac;
@@ -85247,61 +87167,61 @@ DRFLAC_API drflac* drflac_open_file_with_metadata_w(const wchar_t* pFileName, dr
}
#endif
#endif
-static size_t drflac__on_read_memory(void* pUserData, void* bufferOut, size_t bytesToRead)
+static size_t ma_dr_flac__on_read_memory(void* pUserData, void* bufferOut, size_t bytesToRead)
{
- drflac__memory_stream* memoryStream = (drflac__memory_stream*)pUserData;
+ ma_dr_flac__memory_stream* memoryStream = (ma_dr_flac__memory_stream*)pUserData;
size_t bytesRemaining;
- DRFLAC_ASSERT(memoryStream != NULL);
- DRFLAC_ASSERT(memoryStream->dataSize >= memoryStream->currentReadPos);
+ MA_DR_FLAC_ASSERT(memoryStream != NULL);
+ MA_DR_FLAC_ASSERT(memoryStream->dataSize >= memoryStream->currentReadPos);
bytesRemaining = memoryStream->dataSize - memoryStream->currentReadPos;
if (bytesToRead > bytesRemaining) {
bytesToRead = bytesRemaining;
}
if (bytesToRead > 0) {
- DRFLAC_COPY_MEMORY(bufferOut, memoryStream->data + memoryStream->currentReadPos, bytesToRead);
+ MA_DR_FLAC_COPY_MEMORY(bufferOut, memoryStream->data + memoryStream->currentReadPos, bytesToRead);
memoryStream->currentReadPos += bytesToRead;
}
return bytesToRead;
}
-static drflac_bool32 drflac__on_seek_memory(void* pUserData, int offset, drflac_seek_origin origin)
+static ma_bool32 ma_dr_flac__on_seek_memory(void* pUserData, int offset, ma_dr_flac_seek_origin origin)
{
- drflac__memory_stream* memoryStream = (drflac__memory_stream*)pUserData;
- DRFLAC_ASSERT(memoryStream != NULL);
- DRFLAC_ASSERT(offset >= 0);
- if (offset > (drflac_int64)memoryStream->dataSize) {
- return DRFLAC_FALSE;
+ ma_dr_flac__memory_stream* memoryStream = (ma_dr_flac__memory_stream*)pUserData;
+ MA_DR_FLAC_ASSERT(memoryStream != NULL);
+ MA_DR_FLAC_ASSERT(offset >= 0);
+ if (offset > (ma_int64)memoryStream->dataSize) {
+ return MA_FALSE;
}
- if (origin == drflac_seek_origin_current) {
+ if (origin == ma_dr_flac_seek_origin_current) {
if (memoryStream->currentReadPos + offset <= memoryStream->dataSize) {
memoryStream->currentReadPos += offset;
} else {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
} else {
- if ((drflac_uint32)offset <= memoryStream->dataSize) {
+ if ((ma_uint32)offset <= memoryStream->dataSize) {
memoryStream->currentReadPos = offset;
} else {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
}
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
-DRFLAC_API drflac* drflac_open_memory(const void* pData, size_t dataSize, const drflac_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_dr_flac* ma_dr_flac_open_memory(const void* pData, size_t dataSize, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drflac__memory_stream memoryStream;
- drflac* pFlac;
- memoryStream.data = (const drflac_uint8*)pData;
+ ma_dr_flac__memory_stream memoryStream;
+ ma_dr_flac* pFlac;
+ memoryStream.data = (const ma_uint8*)pData;
memoryStream.dataSize = dataSize;
memoryStream.currentReadPos = 0;
- pFlac = drflac_open(drflac__on_read_memory, drflac__on_seek_memory, &memoryStream, pAllocationCallbacks);
+ pFlac = ma_dr_flac_open(ma_dr_flac__on_read_memory, ma_dr_flac__on_seek_memory, &memoryStream, pAllocationCallbacks);
if (pFlac == NULL) {
return NULL;
}
pFlac->memoryStream = memoryStream;
-#ifndef DR_FLAC_NO_OGG
- if (pFlac->container == drflac_container_ogg)
+#ifndef MA_DR_FLAC_NO_OGG
+ if (pFlac->container == ma_dr_flac_container_ogg)
{
- drflac_oggbs* oggbs = (drflac_oggbs*)pFlac->_oggbs;
+ ma_dr_flac_oggbs* oggbs = (ma_dr_flac_oggbs*)pFlac->_oggbs;
oggbs->pUserData = &pFlac->memoryStream;
}
else
@@ -85311,22 +87231,22 @@ DRFLAC_API drflac* drflac_open_memory(const void* pData, size_t dataSize, const
}
return pFlac;
}
-DRFLAC_API drflac* drflac_open_memory_with_metadata(const void* pData, size_t dataSize, drflac_meta_proc onMeta, void* pUserData, const drflac_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_dr_flac* ma_dr_flac_open_memory_with_metadata(const void* pData, size_t dataSize, ma_dr_flac_meta_proc onMeta, void* pUserData, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drflac__memory_stream memoryStream;
- drflac* pFlac;
- memoryStream.data = (const drflac_uint8*)pData;
+ ma_dr_flac__memory_stream memoryStream;
+ ma_dr_flac* pFlac;
+ memoryStream.data = (const ma_uint8*)pData;
memoryStream.dataSize = dataSize;
memoryStream.currentReadPos = 0;
- pFlac = drflac_open_with_metadata_private(drflac__on_read_memory, drflac__on_seek_memory, onMeta, drflac_container_unknown, &memoryStream, pUserData, pAllocationCallbacks);
+ pFlac = ma_dr_flac_open_with_metadata_private(ma_dr_flac__on_read_memory, ma_dr_flac__on_seek_memory, onMeta, ma_dr_flac_container_unknown, &memoryStream, pUserData, pAllocationCallbacks);
if (pFlac == NULL) {
return NULL;
}
pFlac->memoryStream = memoryStream;
-#ifndef DR_FLAC_NO_OGG
- if (pFlac->container == drflac_container_ogg)
+#ifndef MA_DR_FLAC_NO_OGG
+ if (pFlac->container == ma_dr_flac_container_ogg)
{
- drflac_oggbs* oggbs = (drflac_oggbs*)pFlac->_oggbs;
+ ma_dr_flac_oggbs* oggbs = (ma_dr_flac_oggbs*)pFlac->_oggbs;
oggbs->pUserData = &pFlac->memoryStream;
}
else
@@ -85336,104 +87256,104 @@ DRFLAC_API drflac* drflac_open_memory_with_metadata(const void* pData, size_t da
}
return pFlac;
}
-DRFLAC_API drflac* drflac_open(drflac_read_proc onRead, drflac_seek_proc onSeek, void* pUserData, const drflac_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_dr_flac* ma_dr_flac_open(ma_dr_flac_read_proc onRead, ma_dr_flac_seek_proc onSeek, void* pUserData, const ma_allocation_callbacks* pAllocationCallbacks)
{
- return drflac_open_with_metadata_private(onRead, onSeek, NULL, drflac_container_unknown, pUserData, pUserData, pAllocationCallbacks);
+ return ma_dr_flac_open_with_metadata_private(onRead, onSeek, NULL, ma_dr_flac_container_unknown, pUserData, pUserData, pAllocationCallbacks);
}
-DRFLAC_API drflac* drflac_open_relaxed(drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_container container, void* pUserData, const drflac_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_dr_flac* ma_dr_flac_open_relaxed(ma_dr_flac_read_proc onRead, ma_dr_flac_seek_proc onSeek, ma_dr_flac_container container, void* pUserData, const ma_allocation_callbacks* pAllocationCallbacks)
{
- return drflac_open_with_metadata_private(onRead, onSeek, NULL, container, pUserData, pUserData, pAllocationCallbacks);
+ return ma_dr_flac_open_with_metadata_private(onRead, onSeek, NULL, container, pUserData, pUserData, pAllocationCallbacks);
}
-DRFLAC_API drflac* drflac_open_with_metadata(drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_meta_proc onMeta, void* pUserData, const drflac_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_dr_flac* ma_dr_flac_open_with_metadata(ma_dr_flac_read_proc onRead, ma_dr_flac_seek_proc onSeek, ma_dr_flac_meta_proc onMeta, void* pUserData, const ma_allocation_callbacks* pAllocationCallbacks)
{
- return drflac_open_with_metadata_private(onRead, onSeek, onMeta, drflac_container_unknown, pUserData, pUserData, pAllocationCallbacks);
+ return ma_dr_flac_open_with_metadata_private(onRead, onSeek, onMeta, ma_dr_flac_container_unknown, pUserData, pUserData, pAllocationCallbacks);
}
-DRFLAC_API drflac* drflac_open_with_metadata_relaxed(drflac_read_proc onRead, drflac_seek_proc onSeek, drflac_meta_proc onMeta, drflac_container container, void* pUserData, const drflac_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_dr_flac* ma_dr_flac_open_with_metadata_relaxed(ma_dr_flac_read_proc onRead, ma_dr_flac_seek_proc onSeek, ma_dr_flac_meta_proc onMeta, ma_dr_flac_container container, void* pUserData, const ma_allocation_callbacks* pAllocationCallbacks)
{
- return drflac_open_with_metadata_private(onRead, onSeek, onMeta, container, pUserData, pUserData, pAllocationCallbacks);
+ return ma_dr_flac_open_with_metadata_private(onRead, onSeek, onMeta, container, pUserData, pUserData, pAllocationCallbacks);
}
-DRFLAC_API void drflac_close(drflac* pFlac)
+MA_API void ma_dr_flac_close(ma_dr_flac* pFlac)
{
if (pFlac == NULL) {
return;
}
-#ifndef DR_FLAC_NO_STDIO
- if (pFlac->bs.onRead == drflac__on_read_stdio) {
+#ifndef MA_DR_FLAC_NO_STDIO
+ if (pFlac->bs.onRead == ma_dr_flac__on_read_stdio) {
fclose((FILE*)pFlac->bs.pUserData);
}
-#ifndef DR_FLAC_NO_OGG
- if (pFlac->container == drflac_container_ogg) {
- drflac_oggbs* oggbs = (drflac_oggbs*)pFlac->_oggbs;
- DRFLAC_ASSERT(pFlac->bs.onRead == drflac__on_read_ogg);
- if (oggbs->onRead == drflac__on_read_stdio) {
+#ifndef MA_DR_FLAC_NO_OGG
+ if (pFlac->container == ma_dr_flac_container_ogg) {
+ ma_dr_flac_oggbs* oggbs = (ma_dr_flac_oggbs*)pFlac->_oggbs;
+ MA_DR_FLAC_ASSERT(pFlac->bs.onRead == ma_dr_flac__on_read_ogg);
+ if (oggbs->onRead == ma_dr_flac__on_read_stdio) {
fclose((FILE*)oggbs->pUserData);
}
}
#endif
#endif
- drflac__free_from_callbacks(pFlac, &pFlac->allocationCallbacks);
+ ma_dr_flac__free_from_callbacks(pFlac, &pFlac->allocationCallbacks);
}
#if 0
-static DRFLAC_INLINE void drflac_read_pcm_frames_s32__decode_left_side__reference(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int32* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s32__decode_left_side__reference(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int32* pOutputSamples)
{
- drflac_uint64 i;
+ ma_uint64 i;
for (i = 0; i < frameCount; ++i) {
- drflac_uint32 left = (drflac_uint32)pInputSamples0[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample);
- drflac_uint32 side = (drflac_uint32)pInputSamples1[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample);
- drflac_uint32 right = left - side;
- pOutputSamples[i*2+0] = (drflac_int32)left;
- pOutputSamples[i*2+1] = (drflac_int32)right;
+ ma_uint32 left = (ma_uint32)pInputSamples0[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample);
+ ma_uint32 side = (ma_uint32)pInputSamples1[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample);
+ ma_uint32 right = left - side;
+ pOutputSamples[i*2+0] = (ma_int32)left;
+ pOutputSamples[i*2+1] = (ma_int32)right;
}
}
#endif
-static DRFLAC_INLINE void drflac_read_pcm_frames_s32__decode_left_side__scalar(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int32* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s32__decode_left_side__scalar(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int32* pOutputSamples)
{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
for (i = 0; i < frameCount4; ++i) {
- drflac_uint32 left0 = pInputSamples0U32[i*4+0] << shift0;
- drflac_uint32 left1 = pInputSamples0U32[i*4+1] << shift0;
- drflac_uint32 left2 = pInputSamples0U32[i*4+2] << shift0;
- drflac_uint32 left3 = pInputSamples0U32[i*4+3] << shift0;
- drflac_uint32 side0 = pInputSamples1U32[i*4+0] << shift1;
- drflac_uint32 side1 = pInputSamples1U32[i*4+1] << shift1;
- drflac_uint32 side2 = pInputSamples1U32[i*4+2] << shift1;
- drflac_uint32 side3 = pInputSamples1U32[i*4+3] << shift1;
- drflac_uint32 right0 = left0 - side0;
- drflac_uint32 right1 = left1 - side1;
- drflac_uint32 right2 = left2 - side2;
- drflac_uint32 right3 = left3 - side3;
- pOutputSamples[i*8+0] = (drflac_int32)left0;
- pOutputSamples[i*8+1] = (drflac_int32)right0;
- pOutputSamples[i*8+2] = (drflac_int32)left1;
- pOutputSamples[i*8+3] = (drflac_int32)right1;
- pOutputSamples[i*8+4] = (drflac_int32)left2;
- pOutputSamples[i*8+5] = (drflac_int32)right2;
- pOutputSamples[i*8+6] = (drflac_int32)left3;
- pOutputSamples[i*8+7] = (drflac_int32)right3;
+ ma_uint32 left0 = pInputSamples0U32[i*4+0] << shift0;
+ ma_uint32 left1 = pInputSamples0U32[i*4+1] << shift0;
+ ma_uint32 left2 = pInputSamples0U32[i*4+2] << shift0;
+ ma_uint32 left3 = pInputSamples0U32[i*4+3] << shift0;
+ ma_uint32 side0 = pInputSamples1U32[i*4+0] << shift1;
+ ma_uint32 side1 = pInputSamples1U32[i*4+1] << shift1;
+ ma_uint32 side2 = pInputSamples1U32[i*4+2] << shift1;
+ ma_uint32 side3 = pInputSamples1U32[i*4+3] << shift1;
+ ma_uint32 right0 = left0 - side0;
+ ma_uint32 right1 = left1 - side1;
+ ma_uint32 right2 = left2 - side2;
+ ma_uint32 right3 = left3 - side3;
+ pOutputSamples[i*8+0] = (ma_int32)left0;
+ pOutputSamples[i*8+1] = (ma_int32)right0;
+ pOutputSamples[i*8+2] = (ma_int32)left1;
+ pOutputSamples[i*8+3] = (ma_int32)right1;
+ pOutputSamples[i*8+4] = (ma_int32)left2;
+ pOutputSamples[i*8+5] = (ma_int32)right2;
+ pOutputSamples[i*8+6] = (ma_int32)left3;
+ pOutputSamples[i*8+7] = (ma_int32)right3;
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- drflac_uint32 left = pInputSamples0U32[i] << shift0;
- drflac_uint32 side = pInputSamples1U32[i] << shift1;
- drflac_uint32 right = left - side;
- pOutputSamples[i*2+0] = (drflac_int32)left;
- pOutputSamples[i*2+1] = (drflac_int32)right;
- }
-}
-#if defined(DRFLAC_SUPPORT_SSE2)
-static DRFLAC_INLINE void drflac_read_pcm_frames_s32__decode_left_side__sse2(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int32* pOutputSamples)
-{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
- DRFLAC_ASSERT(pFlac->bitsPerSample <= 24);
+ ma_uint32 left = pInputSamples0U32[i] << shift0;
+ ma_uint32 side = pInputSamples1U32[i] << shift1;
+ ma_uint32 right = left - side;
+ pOutputSamples[i*2+0] = (ma_int32)left;
+ pOutputSamples[i*2+1] = (ma_int32)right;
+ }
+}
+#if defined(MA_DR_FLAC_SUPPORT_SSE2)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s32__decode_left_side__sse2(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int32* pOutputSamples)
+{
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ MA_DR_FLAC_ASSERT(pFlac->bitsPerSample <= 24);
for (i = 0; i < frameCount4; ++i) {
__m128i left = _mm_slli_epi32(_mm_loadu_si128((const __m128i*)pInputSamples0 + i), shift0);
__m128i side = _mm_slli_epi32(_mm_loadu_si128((const __m128i*)pInputSamples1 + i), shift1);
@@ -85442,26 +87362,26 @@ static DRFLAC_INLINE void drflac_read_pcm_frames_s32__decode_left_side__sse2(drf
_mm_storeu_si128((__m128i*)(pOutputSamples + i*8 + 4), _mm_unpackhi_epi32(left, right));
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- drflac_uint32 left = pInputSamples0U32[i] << shift0;
- drflac_uint32 side = pInputSamples1U32[i] << shift1;
- drflac_uint32 right = left - side;
- pOutputSamples[i*2+0] = (drflac_int32)left;
- pOutputSamples[i*2+1] = (drflac_int32)right;
+ ma_uint32 left = pInputSamples0U32[i] << shift0;
+ ma_uint32 side = pInputSamples1U32[i] << shift1;
+ ma_uint32 right = left - side;
+ pOutputSamples[i*2+0] = (ma_int32)left;
+ pOutputSamples[i*2+1] = (ma_int32)right;
}
}
#endif
-#if defined(DRFLAC_SUPPORT_NEON)
-static DRFLAC_INLINE void drflac_read_pcm_frames_s32__decode_left_side__neon(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int32* pOutputSamples)
+#if defined(MA_DR_FLAC_SUPPORT_NEON)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s32__decode_left_side__neon(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int32* pOutputSamples)
{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
int32x4_t shift0_4;
int32x4_t shift1_4;
- DRFLAC_ASSERT(pFlac->bitsPerSample <= 24);
+ MA_DR_FLAC_ASSERT(pFlac->bitsPerSample <= 24);
shift0_4 = vdupq_n_s32(shift0);
shift1_4 = vdupq_n_s32(shift1);
for (i = 0; i < frameCount4; ++i) {
@@ -85471,97 +87391,97 @@ static DRFLAC_INLINE void drflac_read_pcm_frames_s32__decode_left_side__neon(drf
left = vshlq_u32(vld1q_u32(pInputSamples0U32 + i*4), shift0_4);
side = vshlq_u32(vld1q_u32(pInputSamples1U32 + i*4), shift1_4);
right = vsubq_u32(left, side);
- drflac__vst2q_u32((drflac_uint32*)pOutputSamples + i*8, vzipq_u32(left, right));
+ ma_dr_flac__vst2q_u32((ma_uint32*)pOutputSamples + i*8, vzipq_u32(left, right));
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- drflac_uint32 left = pInputSamples0U32[i] << shift0;
- drflac_uint32 side = pInputSamples1U32[i] << shift1;
- drflac_uint32 right = left - side;
- pOutputSamples[i*2+0] = (drflac_int32)left;
- pOutputSamples[i*2+1] = (drflac_int32)right;
+ ma_uint32 left = pInputSamples0U32[i] << shift0;
+ ma_uint32 side = pInputSamples1U32[i] << shift1;
+ ma_uint32 right = left - side;
+ pOutputSamples[i*2+0] = (ma_int32)left;
+ pOutputSamples[i*2+1] = (ma_int32)right;
}
}
#endif
-static DRFLAC_INLINE void drflac_read_pcm_frames_s32__decode_left_side(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int32* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s32__decode_left_side(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int32* pOutputSamples)
{
-#if defined(DRFLAC_SUPPORT_SSE2)
- if (drflac__gIsSSE2Supported && pFlac->bitsPerSample <= 24) {
- drflac_read_pcm_frames_s32__decode_left_side__sse2(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+#if defined(MA_DR_FLAC_SUPPORT_SSE2)
+ if (ma_dr_flac__gIsSSE2Supported && pFlac->bitsPerSample <= 24) {
+ ma_dr_flac_read_pcm_frames_s32__decode_left_side__sse2(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
} else
-#elif defined(DRFLAC_SUPPORT_NEON)
- if (drflac__gIsNEONSupported && pFlac->bitsPerSample <= 24) {
- drflac_read_pcm_frames_s32__decode_left_side__neon(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+#elif defined(MA_DR_FLAC_SUPPORT_NEON)
+ if (ma_dr_flac__gIsNEONSupported && pFlac->bitsPerSample <= 24) {
+ ma_dr_flac_read_pcm_frames_s32__decode_left_side__neon(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
} else
#endif
{
#if 0
- drflac_read_pcm_frames_s32__decode_left_side__reference(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+ ma_dr_flac_read_pcm_frames_s32__decode_left_side__reference(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
#else
- drflac_read_pcm_frames_s32__decode_left_side__scalar(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+ ma_dr_flac_read_pcm_frames_s32__decode_left_side__scalar(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
#endif
}
}
#if 0
-static DRFLAC_INLINE void drflac_read_pcm_frames_s32__decode_right_side__reference(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int32* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s32__decode_right_side__reference(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int32* pOutputSamples)
{
- drflac_uint64 i;
+ ma_uint64 i;
for (i = 0; i < frameCount; ++i) {
- drflac_uint32 side = (drflac_uint32)pInputSamples0[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample);
- drflac_uint32 right = (drflac_uint32)pInputSamples1[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample);
- drflac_uint32 left = right + side;
- pOutputSamples[i*2+0] = (drflac_int32)left;
- pOutputSamples[i*2+1] = (drflac_int32)right;
+ ma_uint32 side = (ma_uint32)pInputSamples0[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample);
+ ma_uint32 right = (ma_uint32)pInputSamples1[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample);
+ ma_uint32 left = right + side;
+ pOutputSamples[i*2+0] = (ma_int32)left;
+ pOutputSamples[i*2+1] = (ma_int32)right;
}
}
#endif
-static DRFLAC_INLINE void drflac_read_pcm_frames_s32__decode_right_side__scalar(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int32* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s32__decode_right_side__scalar(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int32* pOutputSamples)
{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
for (i = 0; i < frameCount4; ++i) {
- drflac_uint32 side0 = pInputSamples0U32[i*4+0] << shift0;
- drflac_uint32 side1 = pInputSamples0U32[i*4+1] << shift0;
- drflac_uint32 side2 = pInputSamples0U32[i*4+2] << shift0;
- drflac_uint32 side3 = pInputSamples0U32[i*4+3] << shift0;
- drflac_uint32 right0 = pInputSamples1U32[i*4+0] << shift1;
- drflac_uint32 right1 = pInputSamples1U32[i*4+1] << shift1;
- drflac_uint32 right2 = pInputSamples1U32[i*4+2] << shift1;
- drflac_uint32 right3 = pInputSamples1U32[i*4+3] << shift1;
- drflac_uint32 left0 = right0 + side0;
- drflac_uint32 left1 = right1 + side1;
- drflac_uint32 left2 = right2 + side2;
- drflac_uint32 left3 = right3 + side3;
- pOutputSamples[i*8+0] = (drflac_int32)left0;
- pOutputSamples[i*8+1] = (drflac_int32)right0;
- pOutputSamples[i*8+2] = (drflac_int32)left1;
- pOutputSamples[i*8+3] = (drflac_int32)right1;
- pOutputSamples[i*8+4] = (drflac_int32)left2;
- pOutputSamples[i*8+5] = (drflac_int32)right2;
- pOutputSamples[i*8+6] = (drflac_int32)left3;
- pOutputSamples[i*8+7] = (drflac_int32)right3;
+ ma_uint32 side0 = pInputSamples0U32[i*4+0] << shift0;
+ ma_uint32 side1 = pInputSamples0U32[i*4+1] << shift0;
+ ma_uint32 side2 = pInputSamples0U32[i*4+2] << shift0;
+ ma_uint32 side3 = pInputSamples0U32[i*4+3] << shift0;
+ ma_uint32 right0 = pInputSamples1U32[i*4+0] << shift1;
+ ma_uint32 right1 = pInputSamples1U32[i*4+1] << shift1;
+ ma_uint32 right2 = pInputSamples1U32[i*4+2] << shift1;
+ ma_uint32 right3 = pInputSamples1U32[i*4+3] << shift1;
+ ma_uint32 left0 = right0 + side0;
+ ma_uint32 left1 = right1 + side1;
+ ma_uint32 left2 = right2 + side2;
+ ma_uint32 left3 = right3 + side3;
+ pOutputSamples[i*8+0] = (ma_int32)left0;
+ pOutputSamples[i*8+1] = (ma_int32)right0;
+ pOutputSamples[i*8+2] = (ma_int32)left1;
+ pOutputSamples[i*8+3] = (ma_int32)right1;
+ pOutputSamples[i*8+4] = (ma_int32)left2;
+ pOutputSamples[i*8+5] = (ma_int32)right2;
+ pOutputSamples[i*8+6] = (ma_int32)left3;
+ pOutputSamples[i*8+7] = (ma_int32)right3;
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- drflac_uint32 side = pInputSamples0U32[i] << shift0;
- drflac_uint32 right = pInputSamples1U32[i] << shift1;
- drflac_uint32 left = right + side;
- pOutputSamples[i*2+0] = (drflac_int32)left;
- pOutputSamples[i*2+1] = (drflac_int32)right;
- }
-}
-#if defined(DRFLAC_SUPPORT_SSE2)
-static DRFLAC_INLINE void drflac_read_pcm_frames_s32__decode_right_side__sse2(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int32* pOutputSamples)
-{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
- DRFLAC_ASSERT(pFlac->bitsPerSample <= 24);
+ ma_uint32 side = pInputSamples0U32[i] << shift0;
+ ma_uint32 right = pInputSamples1U32[i] << shift1;
+ ma_uint32 left = right + side;
+ pOutputSamples[i*2+0] = (ma_int32)left;
+ pOutputSamples[i*2+1] = (ma_int32)right;
+ }
+}
+#if defined(MA_DR_FLAC_SUPPORT_SSE2)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s32__decode_right_side__sse2(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int32* pOutputSamples)
+{
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ MA_DR_FLAC_ASSERT(pFlac->bitsPerSample <= 24);
for (i = 0; i < frameCount4; ++i) {
__m128i side = _mm_slli_epi32(_mm_loadu_si128((const __m128i*)pInputSamples0 + i), shift0);
__m128i right = _mm_slli_epi32(_mm_loadu_si128((const __m128i*)pInputSamples1 + i), shift1);
@@ -85570,26 +87490,26 @@ static DRFLAC_INLINE void drflac_read_pcm_frames_s32__decode_right_side__sse2(dr
_mm_storeu_si128((__m128i*)(pOutputSamples + i*8 + 4), _mm_unpackhi_epi32(left, right));
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- drflac_uint32 side = pInputSamples0U32[i] << shift0;
- drflac_uint32 right = pInputSamples1U32[i] << shift1;
- drflac_uint32 left = right + side;
- pOutputSamples[i*2+0] = (drflac_int32)left;
- pOutputSamples[i*2+1] = (drflac_int32)right;
+ ma_uint32 side = pInputSamples0U32[i] << shift0;
+ ma_uint32 right = pInputSamples1U32[i] << shift1;
+ ma_uint32 left = right + side;
+ pOutputSamples[i*2+0] = (ma_int32)left;
+ pOutputSamples[i*2+1] = (ma_int32)right;
}
}
#endif
-#if defined(DRFLAC_SUPPORT_NEON)
-static DRFLAC_INLINE void drflac_read_pcm_frames_s32__decode_right_side__neon(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int32* pOutputSamples)
+#if defined(MA_DR_FLAC_SUPPORT_NEON)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s32__decode_right_side__neon(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int32* pOutputSamples)
{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
int32x4_t shift0_4;
int32x4_t shift1_4;
- DRFLAC_ASSERT(pFlac->bitsPerSample <= 24);
+ MA_DR_FLAC_ASSERT(pFlac->bitsPerSample <= 24);
shift0_4 = vdupq_n_s32(shift0);
shift1_4 = vdupq_n_s32(shift1);
for (i = 0; i < frameCount4; ++i) {
@@ -85599,74 +87519,74 @@ static DRFLAC_INLINE void drflac_read_pcm_frames_s32__decode_right_side__neon(dr
side = vshlq_u32(vld1q_u32(pInputSamples0U32 + i*4), shift0_4);
right = vshlq_u32(vld1q_u32(pInputSamples1U32 + i*4), shift1_4);
left = vaddq_u32(right, side);
- drflac__vst2q_u32((drflac_uint32*)pOutputSamples + i*8, vzipq_u32(left, right));
+ ma_dr_flac__vst2q_u32((ma_uint32*)pOutputSamples + i*8, vzipq_u32(left, right));
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- drflac_uint32 side = pInputSamples0U32[i] << shift0;
- drflac_uint32 right = pInputSamples1U32[i] << shift1;
- drflac_uint32 left = right + side;
- pOutputSamples[i*2+0] = (drflac_int32)left;
- pOutputSamples[i*2+1] = (drflac_int32)right;
+ ma_uint32 side = pInputSamples0U32[i] << shift0;
+ ma_uint32 right = pInputSamples1U32[i] << shift1;
+ ma_uint32 left = right + side;
+ pOutputSamples[i*2+0] = (ma_int32)left;
+ pOutputSamples[i*2+1] = (ma_int32)right;
}
}
#endif
-static DRFLAC_INLINE void drflac_read_pcm_frames_s32__decode_right_side(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int32* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s32__decode_right_side(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int32* pOutputSamples)
{
-#if defined(DRFLAC_SUPPORT_SSE2)
- if (drflac__gIsSSE2Supported && pFlac->bitsPerSample <= 24) {
- drflac_read_pcm_frames_s32__decode_right_side__sse2(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+#if defined(MA_DR_FLAC_SUPPORT_SSE2)
+ if (ma_dr_flac__gIsSSE2Supported && pFlac->bitsPerSample <= 24) {
+ ma_dr_flac_read_pcm_frames_s32__decode_right_side__sse2(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
} else
-#elif defined(DRFLAC_SUPPORT_NEON)
- if (drflac__gIsNEONSupported && pFlac->bitsPerSample <= 24) {
- drflac_read_pcm_frames_s32__decode_right_side__neon(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+#elif defined(MA_DR_FLAC_SUPPORT_NEON)
+ if (ma_dr_flac__gIsNEONSupported && pFlac->bitsPerSample <= 24) {
+ ma_dr_flac_read_pcm_frames_s32__decode_right_side__neon(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
} else
#endif
{
#if 0
- drflac_read_pcm_frames_s32__decode_right_side__reference(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+ ma_dr_flac_read_pcm_frames_s32__decode_right_side__reference(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
#else
- drflac_read_pcm_frames_s32__decode_right_side__scalar(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+ ma_dr_flac_read_pcm_frames_s32__decode_right_side__scalar(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
#endif
}
}
#if 0
-static DRFLAC_INLINE void drflac_read_pcm_frames_s32__decode_mid_side__reference(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int32* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s32__decode_mid_side__reference(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int32* pOutputSamples)
{
- for (drflac_uint64 i = 0; i < frameCount; ++i) {
- drflac_uint32 mid = pInputSamples0U32[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 side = pInputSamples1U32[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ for (ma_uint64 i = 0; i < frameCount; ++i) {
+ ma_uint32 mid = pInputSamples0U32[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 side = pInputSamples1U32[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
mid = (mid << 1) | (side & 0x01);
- pOutputSamples[i*2+0] = (drflac_int32)((drflac_uint32)((drflac_int32)(mid + side) >> 1) << unusedBitsPerSample);
- pOutputSamples[i*2+1] = (drflac_int32)((drflac_uint32)((drflac_int32)(mid - side) >> 1) << unusedBitsPerSample);
+ pOutputSamples[i*2+0] = (ma_int32)((ma_uint32)((ma_int32)(mid + side) >> 1) << unusedBitsPerSample);
+ pOutputSamples[i*2+1] = (ma_int32)((ma_uint32)((ma_int32)(mid - side) >> 1) << unusedBitsPerSample);
}
}
#endif
-static DRFLAC_INLINE void drflac_read_pcm_frames_s32__decode_mid_side__scalar(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int32* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s32__decode_mid_side__scalar(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int32* pOutputSamples)
{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_int32 shift = unusedBitsPerSample;
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_int32 shift = unusedBitsPerSample;
if (shift > 0) {
shift -= 1;
for (i = 0; i < frameCount4; ++i) {
- drflac_uint32 temp0L;
- drflac_uint32 temp1L;
- drflac_uint32 temp2L;
- drflac_uint32 temp3L;
- drflac_uint32 temp0R;
- drflac_uint32 temp1R;
- drflac_uint32 temp2R;
- drflac_uint32 temp3R;
- drflac_uint32 mid0 = pInputSamples0U32[i*4+0] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 mid1 = pInputSamples0U32[i*4+1] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 mid2 = pInputSamples0U32[i*4+2] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 mid3 = pInputSamples0U32[i*4+3] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 side0 = pInputSamples1U32[i*4+0] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
- drflac_uint32 side1 = pInputSamples1U32[i*4+1] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
- drflac_uint32 side2 = pInputSamples1U32[i*4+2] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
- drflac_uint32 side3 = pInputSamples1U32[i*4+3] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 temp0L;
+ ma_uint32 temp1L;
+ ma_uint32 temp2L;
+ ma_uint32 temp3L;
+ ma_uint32 temp0R;
+ ma_uint32 temp1R;
+ ma_uint32 temp2R;
+ ma_uint32 temp3R;
+ ma_uint32 mid0 = pInputSamples0U32[i*4+0] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 mid1 = pInputSamples0U32[i*4+1] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 mid2 = pInputSamples0U32[i*4+2] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 mid3 = pInputSamples0U32[i*4+3] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 side0 = pInputSamples1U32[i*4+0] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 side1 = pInputSamples1U32[i*4+1] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 side2 = pInputSamples1U32[i*4+2] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 side3 = pInputSamples1U32[i*4+3] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
mid0 = (mid0 << 1) | (side0 & 0x01);
mid1 = (mid1 << 1) | (side1 & 0x01);
mid2 = (mid2 << 1) | (side2 & 0x01);
@@ -85679,72 +87599,72 @@ static DRFLAC_INLINE void drflac_read_pcm_frames_s32__decode_mid_side__scalar(dr
temp1R = (mid1 - side1) << shift;
temp2R = (mid2 - side2) << shift;
temp3R = (mid3 - side3) << shift;
- pOutputSamples[i*8+0] = (drflac_int32)temp0L;
- pOutputSamples[i*8+1] = (drflac_int32)temp0R;
- pOutputSamples[i*8+2] = (drflac_int32)temp1L;
- pOutputSamples[i*8+3] = (drflac_int32)temp1R;
- pOutputSamples[i*8+4] = (drflac_int32)temp2L;
- pOutputSamples[i*8+5] = (drflac_int32)temp2R;
- pOutputSamples[i*8+6] = (drflac_int32)temp3L;
- pOutputSamples[i*8+7] = (drflac_int32)temp3R;
+ pOutputSamples[i*8+0] = (ma_int32)temp0L;
+ pOutputSamples[i*8+1] = (ma_int32)temp0R;
+ pOutputSamples[i*8+2] = (ma_int32)temp1L;
+ pOutputSamples[i*8+3] = (ma_int32)temp1R;
+ pOutputSamples[i*8+4] = (ma_int32)temp2L;
+ pOutputSamples[i*8+5] = (ma_int32)temp2R;
+ pOutputSamples[i*8+6] = (ma_int32)temp3L;
+ pOutputSamples[i*8+7] = (ma_int32)temp3R;
}
} else {
for (i = 0; i < frameCount4; ++i) {
- drflac_uint32 temp0L;
- drflac_uint32 temp1L;
- drflac_uint32 temp2L;
- drflac_uint32 temp3L;
- drflac_uint32 temp0R;
- drflac_uint32 temp1R;
- drflac_uint32 temp2R;
- drflac_uint32 temp3R;
- drflac_uint32 mid0 = pInputSamples0U32[i*4+0] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 mid1 = pInputSamples0U32[i*4+1] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 mid2 = pInputSamples0U32[i*4+2] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 mid3 = pInputSamples0U32[i*4+3] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 side0 = pInputSamples1U32[i*4+0] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
- drflac_uint32 side1 = pInputSamples1U32[i*4+1] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
- drflac_uint32 side2 = pInputSamples1U32[i*4+2] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
- drflac_uint32 side3 = pInputSamples1U32[i*4+3] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 temp0L;
+ ma_uint32 temp1L;
+ ma_uint32 temp2L;
+ ma_uint32 temp3L;
+ ma_uint32 temp0R;
+ ma_uint32 temp1R;
+ ma_uint32 temp2R;
+ ma_uint32 temp3R;
+ ma_uint32 mid0 = pInputSamples0U32[i*4+0] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 mid1 = pInputSamples0U32[i*4+1] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 mid2 = pInputSamples0U32[i*4+2] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 mid3 = pInputSamples0U32[i*4+3] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 side0 = pInputSamples1U32[i*4+0] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 side1 = pInputSamples1U32[i*4+1] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 side2 = pInputSamples1U32[i*4+2] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 side3 = pInputSamples1U32[i*4+3] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
mid0 = (mid0 << 1) | (side0 & 0x01);
mid1 = (mid1 << 1) | (side1 & 0x01);
mid2 = (mid2 << 1) | (side2 & 0x01);
mid3 = (mid3 << 1) | (side3 & 0x01);
- temp0L = (drflac_uint32)((drflac_int32)(mid0 + side0) >> 1);
- temp1L = (drflac_uint32)((drflac_int32)(mid1 + side1) >> 1);
- temp2L = (drflac_uint32)((drflac_int32)(mid2 + side2) >> 1);
- temp3L = (drflac_uint32)((drflac_int32)(mid3 + side3) >> 1);
- temp0R = (drflac_uint32)((drflac_int32)(mid0 - side0) >> 1);
- temp1R = (drflac_uint32)((drflac_int32)(mid1 - side1) >> 1);
- temp2R = (drflac_uint32)((drflac_int32)(mid2 - side2) >> 1);
- temp3R = (drflac_uint32)((drflac_int32)(mid3 - side3) >> 1);
- pOutputSamples[i*8+0] = (drflac_int32)temp0L;
- pOutputSamples[i*8+1] = (drflac_int32)temp0R;
- pOutputSamples[i*8+2] = (drflac_int32)temp1L;
- pOutputSamples[i*8+3] = (drflac_int32)temp1R;
- pOutputSamples[i*8+4] = (drflac_int32)temp2L;
- pOutputSamples[i*8+5] = (drflac_int32)temp2R;
- pOutputSamples[i*8+6] = (drflac_int32)temp3L;
- pOutputSamples[i*8+7] = (drflac_int32)temp3R;
+ temp0L = (ma_uint32)((ma_int32)(mid0 + side0) >> 1);
+ temp1L = (ma_uint32)((ma_int32)(mid1 + side1) >> 1);
+ temp2L = (ma_uint32)((ma_int32)(mid2 + side2) >> 1);
+ temp3L = (ma_uint32)((ma_int32)(mid3 + side3) >> 1);
+ temp0R = (ma_uint32)((ma_int32)(mid0 - side0) >> 1);
+ temp1R = (ma_uint32)((ma_int32)(mid1 - side1) >> 1);
+ temp2R = (ma_uint32)((ma_int32)(mid2 - side2) >> 1);
+ temp3R = (ma_uint32)((ma_int32)(mid3 - side3) >> 1);
+ pOutputSamples[i*8+0] = (ma_int32)temp0L;
+ pOutputSamples[i*8+1] = (ma_int32)temp0R;
+ pOutputSamples[i*8+2] = (ma_int32)temp1L;
+ pOutputSamples[i*8+3] = (ma_int32)temp1R;
+ pOutputSamples[i*8+4] = (ma_int32)temp2L;
+ pOutputSamples[i*8+5] = (ma_int32)temp2R;
+ pOutputSamples[i*8+6] = (ma_int32)temp3L;
+ pOutputSamples[i*8+7] = (ma_int32)temp3R;
}
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- drflac_uint32 mid = pInputSamples0U32[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 side = pInputSamples1U32[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 mid = pInputSamples0U32[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 side = pInputSamples1U32[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
mid = (mid << 1) | (side & 0x01);
- pOutputSamples[i*2+0] = (drflac_int32)((drflac_uint32)((drflac_int32)(mid + side) >> 1) << unusedBitsPerSample);
- pOutputSamples[i*2+1] = (drflac_int32)((drflac_uint32)((drflac_int32)(mid - side) >> 1) << unusedBitsPerSample);
+ pOutputSamples[i*2+0] = (ma_int32)((ma_uint32)((ma_int32)(mid + side) >> 1) << unusedBitsPerSample);
+ pOutputSamples[i*2+1] = (ma_int32)((ma_uint32)((ma_int32)(mid - side) >> 1) << unusedBitsPerSample);
}
}
-#if defined(DRFLAC_SUPPORT_SSE2)
-static DRFLAC_INLINE void drflac_read_pcm_frames_s32__decode_mid_side__sse2(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int32* pOutputSamples)
+#if defined(MA_DR_FLAC_SUPPORT_SSE2)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s32__decode_mid_side__sse2(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int32* pOutputSamples)
{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_int32 shift = unusedBitsPerSample;
- DRFLAC_ASSERT(pFlac->bitsPerSample <= 24);
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_int32 shift = unusedBitsPerSample;
+ MA_DR_FLAC_ASSERT(pFlac->bitsPerSample <= 24);
if (shift == 0) {
for (i = 0; i < frameCount4; ++i) {
__m128i mid;
@@ -85760,11 +87680,11 @@ static DRFLAC_INLINE void drflac_read_pcm_frames_s32__decode_mid_side__sse2(drfl
_mm_storeu_si128((__m128i*)(pOutputSamples + i*8 + 4), _mm_unpackhi_epi32(left, right));
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- drflac_uint32 mid = pInputSamples0U32[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 side = pInputSamples1U32[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 mid = pInputSamples0U32[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 side = pInputSamples1U32[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
mid = (mid << 1) | (side & 0x01);
- pOutputSamples[i*2+0] = (drflac_int32)(mid + side) >> 1;
- pOutputSamples[i*2+1] = (drflac_int32)(mid - side) >> 1;
+ pOutputSamples[i*2+0] = (ma_int32)(mid + side) >> 1;
+ pOutputSamples[i*2+1] = (ma_int32)(mid - side) >> 1;
}
} else {
shift -= 1;
@@ -85782,27 +87702,27 @@ static DRFLAC_INLINE void drflac_read_pcm_frames_s32__decode_mid_side__sse2(drfl
_mm_storeu_si128((__m128i*)(pOutputSamples + i*8 + 4), _mm_unpackhi_epi32(left, right));
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- drflac_uint32 mid = pInputSamples0U32[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 side = pInputSamples1U32[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 mid = pInputSamples0U32[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 side = pInputSamples1U32[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
mid = (mid << 1) | (side & 0x01);
- pOutputSamples[i*2+0] = (drflac_int32)((mid + side) << shift);
- pOutputSamples[i*2+1] = (drflac_int32)((mid - side) << shift);
+ pOutputSamples[i*2+0] = (ma_int32)((mid + side) << shift);
+ pOutputSamples[i*2+1] = (ma_int32)((mid - side) << shift);
}
}
}
#endif
-#if defined(DRFLAC_SUPPORT_NEON)
-static DRFLAC_INLINE void drflac_read_pcm_frames_s32__decode_mid_side__neon(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int32* pOutputSamples)
+#if defined(MA_DR_FLAC_SUPPORT_NEON)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s32__decode_mid_side__neon(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int32* pOutputSamples)
{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_int32 shift = unusedBitsPerSample;
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_int32 shift = unusedBitsPerSample;
int32x4_t wbpsShift0_4;
int32x4_t wbpsShift1_4;
uint32x4_t one4;
- DRFLAC_ASSERT(pFlac->bitsPerSample <= 24);
+ MA_DR_FLAC_ASSERT(pFlac->bitsPerSample <= 24);
wbpsShift0_4 = vdupq_n_s32(pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample);
wbpsShift1_4 = vdupq_n_s32(pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample);
one4 = vdupq_n_u32(1);
@@ -85817,14 +87737,14 @@ static DRFLAC_INLINE void drflac_read_pcm_frames_s32__decode_mid_side__neon(drfl
mid = vorrq_u32(vshlq_n_u32(mid, 1), vandq_u32(side, one4));
left = vshrq_n_s32(vreinterpretq_s32_u32(vaddq_u32(mid, side)), 1);
right = vshrq_n_s32(vreinterpretq_s32_u32(vsubq_u32(mid, side)), 1);
- drflac__vst2q_s32(pOutputSamples + i*8, vzipq_s32(left, right));
+ ma_dr_flac__vst2q_s32(pOutputSamples + i*8, vzipq_s32(left, right));
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- drflac_uint32 mid = pInputSamples0U32[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 side = pInputSamples1U32[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 mid = pInputSamples0U32[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 side = pInputSamples1U32[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
mid = (mid << 1) | (side & 0x01);
- pOutputSamples[i*2+0] = (drflac_int32)(mid + side) >> 1;
- pOutputSamples[i*2+1] = (drflac_int32)(mid - side) >> 1;
+ pOutputSamples[i*2+0] = (ma_int32)(mid + side) >> 1;
+ pOutputSamples[i*2+1] = (ma_int32)(mid - side) >> 1;
}
} else {
int32x4_t shift4;
@@ -85840,86 +87760,86 @@ static DRFLAC_INLINE void drflac_read_pcm_frames_s32__decode_mid_side__neon(drfl
mid = vorrq_u32(vshlq_n_u32(mid, 1), vandq_u32(side, one4));
left = vreinterpretq_s32_u32(vshlq_u32(vaddq_u32(mid, side), shift4));
right = vreinterpretq_s32_u32(vshlq_u32(vsubq_u32(mid, side), shift4));
- drflac__vst2q_s32(pOutputSamples + i*8, vzipq_s32(left, right));
+ ma_dr_flac__vst2q_s32(pOutputSamples + i*8, vzipq_s32(left, right));
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- drflac_uint32 mid = pInputSamples0U32[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 side = pInputSamples1U32[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 mid = pInputSamples0U32[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 side = pInputSamples1U32[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
mid = (mid << 1) | (side & 0x01);
- pOutputSamples[i*2+0] = (drflac_int32)((mid + side) << shift);
- pOutputSamples[i*2+1] = (drflac_int32)((mid - side) << shift);
+ pOutputSamples[i*2+0] = (ma_int32)((mid + side) << shift);
+ pOutputSamples[i*2+1] = (ma_int32)((mid - side) << shift);
}
}
}
#endif
-static DRFLAC_INLINE void drflac_read_pcm_frames_s32__decode_mid_side(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int32* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s32__decode_mid_side(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int32* pOutputSamples)
{
-#if defined(DRFLAC_SUPPORT_SSE2)
- if (drflac__gIsSSE2Supported && pFlac->bitsPerSample <= 24) {
- drflac_read_pcm_frames_s32__decode_mid_side__sse2(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+#if defined(MA_DR_FLAC_SUPPORT_SSE2)
+ if (ma_dr_flac__gIsSSE2Supported && pFlac->bitsPerSample <= 24) {
+ ma_dr_flac_read_pcm_frames_s32__decode_mid_side__sse2(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
} else
-#elif defined(DRFLAC_SUPPORT_NEON)
- if (drflac__gIsNEONSupported && pFlac->bitsPerSample <= 24) {
- drflac_read_pcm_frames_s32__decode_mid_side__neon(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+#elif defined(MA_DR_FLAC_SUPPORT_NEON)
+ if (ma_dr_flac__gIsNEONSupported && pFlac->bitsPerSample <= 24) {
+ ma_dr_flac_read_pcm_frames_s32__decode_mid_side__neon(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
} else
#endif
{
#if 0
- drflac_read_pcm_frames_s32__decode_mid_side__reference(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+ ma_dr_flac_read_pcm_frames_s32__decode_mid_side__reference(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
#else
- drflac_read_pcm_frames_s32__decode_mid_side__scalar(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+ ma_dr_flac_read_pcm_frames_s32__decode_mid_side__scalar(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
#endif
}
}
#if 0
-static DRFLAC_INLINE void drflac_read_pcm_frames_s32__decode_independent_stereo__reference(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int32* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s32__decode_independent_stereo__reference(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int32* pOutputSamples)
{
- for (drflac_uint64 i = 0; i < frameCount; ++i) {
- pOutputSamples[i*2+0] = (drflac_int32)((drflac_uint32)pInputSamples0[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample));
- pOutputSamples[i*2+1] = (drflac_int32)((drflac_uint32)pInputSamples1[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample));
+ for (ma_uint64 i = 0; i < frameCount; ++i) {
+ pOutputSamples[i*2+0] = (ma_int32)((ma_uint32)pInputSamples0[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample));
+ pOutputSamples[i*2+1] = (ma_int32)((ma_uint32)pInputSamples1[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample));
}
}
#endif
-static DRFLAC_INLINE void drflac_read_pcm_frames_s32__decode_independent_stereo__scalar(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int32* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s32__decode_independent_stereo__scalar(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int32* pOutputSamples)
{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
for (i = 0; i < frameCount4; ++i) {
- drflac_uint32 tempL0 = pInputSamples0U32[i*4+0] << shift0;
- drflac_uint32 tempL1 = pInputSamples0U32[i*4+1] << shift0;
- drflac_uint32 tempL2 = pInputSamples0U32[i*4+2] << shift0;
- drflac_uint32 tempL3 = pInputSamples0U32[i*4+3] << shift0;
- drflac_uint32 tempR0 = pInputSamples1U32[i*4+0] << shift1;
- drflac_uint32 tempR1 = pInputSamples1U32[i*4+1] << shift1;
- drflac_uint32 tempR2 = pInputSamples1U32[i*4+2] << shift1;
- drflac_uint32 tempR3 = pInputSamples1U32[i*4+3] << shift1;
- pOutputSamples[i*8+0] = (drflac_int32)tempL0;
- pOutputSamples[i*8+1] = (drflac_int32)tempR0;
- pOutputSamples[i*8+2] = (drflac_int32)tempL1;
- pOutputSamples[i*8+3] = (drflac_int32)tempR1;
- pOutputSamples[i*8+4] = (drflac_int32)tempL2;
- pOutputSamples[i*8+5] = (drflac_int32)tempR2;
- pOutputSamples[i*8+6] = (drflac_int32)tempL3;
- pOutputSamples[i*8+7] = (drflac_int32)tempR3;
+ ma_uint32 tempL0 = pInputSamples0U32[i*4+0] << shift0;
+ ma_uint32 tempL1 = pInputSamples0U32[i*4+1] << shift0;
+ ma_uint32 tempL2 = pInputSamples0U32[i*4+2] << shift0;
+ ma_uint32 tempL3 = pInputSamples0U32[i*4+3] << shift0;
+ ma_uint32 tempR0 = pInputSamples1U32[i*4+0] << shift1;
+ ma_uint32 tempR1 = pInputSamples1U32[i*4+1] << shift1;
+ ma_uint32 tempR2 = pInputSamples1U32[i*4+2] << shift1;
+ ma_uint32 tempR3 = pInputSamples1U32[i*4+3] << shift1;
+ pOutputSamples[i*8+0] = (ma_int32)tempL0;
+ pOutputSamples[i*8+1] = (ma_int32)tempR0;
+ pOutputSamples[i*8+2] = (ma_int32)tempL1;
+ pOutputSamples[i*8+3] = (ma_int32)tempR1;
+ pOutputSamples[i*8+4] = (ma_int32)tempL2;
+ pOutputSamples[i*8+5] = (ma_int32)tempR2;
+ pOutputSamples[i*8+6] = (ma_int32)tempL3;
+ pOutputSamples[i*8+7] = (ma_int32)tempR3;
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- pOutputSamples[i*2+0] = (drflac_int32)(pInputSamples0U32[i] << shift0);
- pOutputSamples[i*2+1] = (drflac_int32)(pInputSamples1U32[i] << shift1);
+ pOutputSamples[i*2+0] = (ma_int32)(pInputSamples0U32[i] << shift0);
+ pOutputSamples[i*2+1] = (ma_int32)(pInputSamples1U32[i] << shift1);
}
}
-#if defined(DRFLAC_SUPPORT_SSE2)
-static DRFLAC_INLINE void drflac_read_pcm_frames_s32__decode_independent_stereo__sse2(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int32* pOutputSamples)
+#if defined(MA_DR_FLAC_SUPPORT_SSE2)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s32__decode_independent_stereo__sse2(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int32* pOutputSamples)
{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
for (i = 0; i < frameCount4; ++i) {
__m128i left = _mm_slli_epi32(_mm_loadu_si128((const __m128i*)pInputSamples0 + i), shift0);
__m128i right = _mm_slli_epi32(_mm_loadu_si128((const __m128i*)pInputSamples1 + i), shift1);
@@ -85927,20 +87847,20 @@ static DRFLAC_INLINE void drflac_read_pcm_frames_s32__decode_independent_stereo_
_mm_storeu_si128((__m128i*)(pOutputSamples + i*8 + 4), _mm_unpackhi_epi32(left, right));
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- pOutputSamples[i*2+0] = (drflac_int32)(pInputSamples0U32[i] << shift0);
- pOutputSamples[i*2+1] = (drflac_int32)(pInputSamples1U32[i] << shift1);
+ pOutputSamples[i*2+0] = (ma_int32)(pInputSamples0U32[i] << shift0);
+ pOutputSamples[i*2+1] = (ma_int32)(pInputSamples1U32[i] << shift1);
}
}
#endif
-#if defined(DRFLAC_SUPPORT_NEON)
-static DRFLAC_INLINE void drflac_read_pcm_frames_s32__decode_independent_stereo__neon(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int32* pOutputSamples)
+#if defined(MA_DR_FLAC_SUPPORT_NEON)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s32__decode_independent_stereo__neon(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int32* pOutputSamples)
{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
int32x4_t shift4_0 = vdupq_n_s32(shift0);
int32x4_t shift4_1 = vdupq_n_s32(shift1);
for (i = 0; i < frameCount4; ++i) {
@@ -85948,87 +87868,87 @@ static DRFLAC_INLINE void drflac_read_pcm_frames_s32__decode_independent_stereo_
int32x4_t right;
left = vreinterpretq_s32_u32(vshlq_u32(vld1q_u32(pInputSamples0U32 + i*4), shift4_0));
right = vreinterpretq_s32_u32(vshlq_u32(vld1q_u32(pInputSamples1U32 + i*4), shift4_1));
- drflac__vst2q_s32(pOutputSamples + i*8, vzipq_s32(left, right));
+ ma_dr_flac__vst2q_s32(pOutputSamples + i*8, vzipq_s32(left, right));
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- pOutputSamples[i*2+0] = (drflac_int32)(pInputSamples0U32[i] << shift0);
- pOutputSamples[i*2+1] = (drflac_int32)(pInputSamples1U32[i] << shift1);
+ pOutputSamples[i*2+0] = (ma_int32)(pInputSamples0U32[i] << shift0);
+ pOutputSamples[i*2+1] = (ma_int32)(pInputSamples1U32[i] << shift1);
}
}
#endif
-static DRFLAC_INLINE void drflac_read_pcm_frames_s32__decode_independent_stereo(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int32* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s32__decode_independent_stereo(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int32* pOutputSamples)
{
-#if defined(DRFLAC_SUPPORT_SSE2)
- if (drflac__gIsSSE2Supported && pFlac->bitsPerSample <= 24) {
- drflac_read_pcm_frames_s32__decode_independent_stereo__sse2(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+#if defined(MA_DR_FLAC_SUPPORT_SSE2)
+ if (ma_dr_flac__gIsSSE2Supported && pFlac->bitsPerSample <= 24) {
+ ma_dr_flac_read_pcm_frames_s32__decode_independent_stereo__sse2(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
} else
-#elif defined(DRFLAC_SUPPORT_NEON)
- if (drflac__gIsNEONSupported && pFlac->bitsPerSample <= 24) {
- drflac_read_pcm_frames_s32__decode_independent_stereo__neon(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+#elif defined(MA_DR_FLAC_SUPPORT_NEON)
+ if (ma_dr_flac__gIsNEONSupported && pFlac->bitsPerSample <= 24) {
+ ma_dr_flac_read_pcm_frames_s32__decode_independent_stereo__neon(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
} else
#endif
{
#if 0
- drflac_read_pcm_frames_s32__decode_independent_stereo__reference(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+ ma_dr_flac_read_pcm_frames_s32__decode_independent_stereo__reference(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
#else
- drflac_read_pcm_frames_s32__decode_independent_stereo__scalar(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+ ma_dr_flac_read_pcm_frames_s32__decode_independent_stereo__scalar(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
#endif
}
}
-DRFLAC_API drflac_uint64 drflac_read_pcm_frames_s32(drflac* pFlac, drflac_uint64 framesToRead, drflac_int32* pBufferOut)
+MA_API ma_uint64 ma_dr_flac_read_pcm_frames_s32(ma_dr_flac* pFlac, ma_uint64 framesToRead, ma_int32* pBufferOut)
{
- drflac_uint64 framesRead;
- drflac_uint32 unusedBitsPerSample;
+ ma_uint64 framesRead;
+ ma_uint32 unusedBitsPerSample;
if (pFlac == NULL || framesToRead == 0) {
return 0;
}
if (pBufferOut == NULL) {
- return drflac__seek_forward_by_pcm_frames(pFlac, framesToRead);
+ return ma_dr_flac__seek_forward_by_pcm_frames(pFlac, framesToRead);
}
- DRFLAC_ASSERT(pFlac->bitsPerSample <= 32);
+ MA_DR_FLAC_ASSERT(pFlac->bitsPerSample <= 32);
unusedBitsPerSample = 32 - pFlac->bitsPerSample;
framesRead = 0;
while (framesToRead > 0) {
if (pFlac->currentFLACFrame.pcmFramesRemaining == 0) {
- if (!drflac__read_and_decode_next_flac_frame(pFlac)) {
+ if (!ma_dr_flac__read_and_decode_next_flac_frame(pFlac)) {
break;
}
} else {
- unsigned int channelCount = drflac__get_channel_count_from_channel_assignment(pFlac->currentFLACFrame.header.channelAssignment);
- drflac_uint64 iFirstPCMFrame = pFlac->currentFLACFrame.header.blockSizeInPCMFrames - pFlac->currentFLACFrame.pcmFramesRemaining;
- drflac_uint64 frameCountThisIteration = framesToRead;
+ unsigned int channelCount = ma_dr_flac__get_channel_count_from_channel_assignment(pFlac->currentFLACFrame.header.channelAssignment);
+ ma_uint64 iFirstPCMFrame = pFlac->currentFLACFrame.header.blockSizeInPCMFrames - pFlac->currentFLACFrame.pcmFramesRemaining;
+ ma_uint64 frameCountThisIteration = framesToRead;
if (frameCountThisIteration > pFlac->currentFLACFrame.pcmFramesRemaining) {
frameCountThisIteration = pFlac->currentFLACFrame.pcmFramesRemaining;
}
if (channelCount == 2) {
- const drflac_int32* pDecodedSamples0 = pFlac->currentFLACFrame.subframes[0].pSamplesS32 + iFirstPCMFrame;
- const drflac_int32* pDecodedSamples1 = pFlac->currentFLACFrame.subframes[1].pSamplesS32 + iFirstPCMFrame;
+ const ma_int32* pDecodedSamples0 = pFlac->currentFLACFrame.subframes[0].pSamplesS32 + iFirstPCMFrame;
+ const ma_int32* pDecodedSamples1 = pFlac->currentFLACFrame.subframes[1].pSamplesS32 + iFirstPCMFrame;
switch (pFlac->currentFLACFrame.header.channelAssignment)
{
- case DRFLAC_CHANNEL_ASSIGNMENT_LEFT_SIDE:
+ case MA_DR_FLAC_CHANNEL_ASSIGNMENT_LEFT_SIDE:
{
- drflac_read_pcm_frames_s32__decode_left_side(pFlac, frameCountThisIteration, unusedBitsPerSample, pDecodedSamples0, pDecodedSamples1, pBufferOut);
+ ma_dr_flac_read_pcm_frames_s32__decode_left_side(pFlac, frameCountThisIteration, unusedBitsPerSample, pDecodedSamples0, pDecodedSamples1, pBufferOut);
} break;
- case DRFLAC_CHANNEL_ASSIGNMENT_RIGHT_SIDE:
+ case MA_DR_FLAC_CHANNEL_ASSIGNMENT_RIGHT_SIDE:
{
- drflac_read_pcm_frames_s32__decode_right_side(pFlac, frameCountThisIteration, unusedBitsPerSample, pDecodedSamples0, pDecodedSamples1, pBufferOut);
+ ma_dr_flac_read_pcm_frames_s32__decode_right_side(pFlac, frameCountThisIteration, unusedBitsPerSample, pDecodedSamples0, pDecodedSamples1, pBufferOut);
} break;
- case DRFLAC_CHANNEL_ASSIGNMENT_MID_SIDE:
+ case MA_DR_FLAC_CHANNEL_ASSIGNMENT_MID_SIDE:
{
- drflac_read_pcm_frames_s32__decode_mid_side(pFlac, frameCountThisIteration, unusedBitsPerSample, pDecodedSamples0, pDecodedSamples1, pBufferOut);
+ ma_dr_flac_read_pcm_frames_s32__decode_mid_side(pFlac, frameCountThisIteration, unusedBitsPerSample, pDecodedSamples0, pDecodedSamples1, pBufferOut);
} break;
- case DRFLAC_CHANNEL_ASSIGNMENT_INDEPENDENT:
+ case MA_DR_FLAC_CHANNEL_ASSIGNMENT_INDEPENDENT:
default:
{
- drflac_read_pcm_frames_s32__decode_independent_stereo(pFlac, frameCountThisIteration, unusedBitsPerSample, pDecodedSamples0, pDecodedSamples1, pBufferOut);
+ ma_dr_flac_read_pcm_frames_s32__decode_independent_stereo(pFlac, frameCountThisIteration, unusedBitsPerSample, pDecodedSamples0, pDecodedSamples1, pBufferOut);
} break;
}
} else {
- drflac_uint64 i;
+ ma_uint64 i;
for (i = 0; i < frameCountThisIteration; ++i) {
unsigned int j;
for (j = 0; j < channelCount; ++j) {
- pBufferOut[(i*channelCount)+j] = (drflac_int32)((drflac_uint32)(pFlac->currentFLACFrame.subframes[j].pSamplesS32[iFirstPCMFrame + i]) << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[j].wastedBitsPerSample));
+ pBufferOut[(i*channelCount)+j] = (ma_int32)((ma_uint32)(pFlac->currentFLACFrame.subframes[j].pSamplesS32[iFirstPCMFrame + i]) << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[j].wastedBitsPerSample));
}
}
}
@@ -86036,47 +87956,47 @@ DRFLAC_API drflac_uint64 drflac_read_pcm_frames_s32(drflac* pFlac, drflac_uint64
pBufferOut += frameCountThisIteration * channelCount;
framesToRead -= frameCountThisIteration;
pFlac->currentPCMFrame += frameCountThisIteration;
- pFlac->currentFLACFrame.pcmFramesRemaining -= (drflac_uint32)frameCountThisIteration;
+ pFlac->currentFLACFrame.pcmFramesRemaining -= (ma_uint32)frameCountThisIteration;
}
}
return framesRead;
}
#if 0
-static DRFLAC_INLINE void drflac_read_pcm_frames_s16__decode_left_side__reference(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int16* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s16__decode_left_side__reference(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int16* pOutputSamples)
{
- drflac_uint64 i;
+ ma_uint64 i;
for (i = 0; i < frameCount; ++i) {
- drflac_uint32 left = (drflac_uint32)pInputSamples0[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample);
- drflac_uint32 side = (drflac_uint32)pInputSamples1[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample);
- drflac_uint32 right = left - side;
+ ma_uint32 left = (ma_uint32)pInputSamples0[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample);
+ ma_uint32 side = (ma_uint32)pInputSamples1[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample);
+ ma_uint32 right = left - side;
left >>= 16;
right >>= 16;
- pOutputSamples[i*2+0] = (drflac_int16)left;
- pOutputSamples[i*2+1] = (drflac_int16)right;
+ pOutputSamples[i*2+0] = (ma_int16)left;
+ pOutputSamples[i*2+1] = (ma_int16)right;
}
}
#endif
-static DRFLAC_INLINE void drflac_read_pcm_frames_s16__decode_left_side__scalar(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int16* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s16__decode_left_side__scalar(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int16* pOutputSamples)
{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
for (i = 0; i < frameCount4; ++i) {
- drflac_uint32 left0 = pInputSamples0U32[i*4+0] << shift0;
- drflac_uint32 left1 = pInputSamples0U32[i*4+1] << shift0;
- drflac_uint32 left2 = pInputSamples0U32[i*4+2] << shift0;
- drflac_uint32 left3 = pInputSamples0U32[i*4+3] << shift0;
- drflac_uint32 side0 = pInputSamples1U32[i*4+0] << shift1;
- drflac_uint32 side1 = pInputSamples1U32[i*4+1] << shift1;
- drflac_uint32 side2 = pInputSamples1U32[i*4+2] << shift1;
- drflac_uint32 side3 = pInputSamples1U32[i*4+3] << shift1;
- drflac_uint32 right0 = left0 - side0;
- drflac_uint32 right1 = left1 - side1;
- drflac_uint32 right2 = left2 - side2;
- drflac_uint32 right3 = left3 - side3;
+ ma_uint32 left0 = pInputSamples0U32[i*4+0] << shift0;
+ ma_uint32 left1 = pInputSamples0U32[i*4+1] << shift0;
+ ma_uint32 left2 = pInputSamples0U32[i*4+2] << shift0;
+ ma_uint32 left3 = pInputSamples0U32[i*4+3] << shift0;
+ ma_uint32 side0 = pInputSamples1U32[i*4+0] << shift1;
+ ma_uint32 side1 = pInputSamples1U32[i*4+1] << shift1;
+ ma_uint32 side2 = pInputSamples1U32[i*4+2] << shift1;
+ ma_uint32 side3 = pInputSamples1U32[i*4+3] << shift1;
+ ma_uint32 right0 = left0 - side0;
+ ma_uint32 right1 = left1 - side1;
+ ma_uint32 right2 = left2 - side2;
+ ma_uint32 right3 = left3 - side3;
left0 >>= 16;
left1 >>= 16;
left2 >>= 16;
@@ -86085,66 +88005,66 @@ static DRFLAC_INLINE void drflac_read_pcm_frames_s16__decode_left_side__scalar(d
right1 >>= 16;
right2 >>= 16;
right3 >>= 16;
- pOutputSamples[i*8+0] = (drflac_int16)left0;
- pOutputSamples[i*8+1] = (drflac_int16)right0;
- pOutputSamples[i*8+2] = (drflac_int16)left1;
- pOutputSamples[i*8+3] = (drflac_int16)right1;
- pOutputSamples[i*8+4] = (drflac_int16)left2;
- pOutputSamples[i*8+5] = (drflac_int16)right2;
- pOutputSamples[i*8+6] = (drflac_int16)left3;
- pOutputSamples[i*8+7] = (drflac_int16)right3;
+ pOutputSamples[i*8+0] = (ma_int16)left0;
+ pOutputSamples[i*8+1] = (ma_int16)right0;
+ pOutputSamples[i*8+2] = (ma_int16)left1;
+ pOutputSamples[i*8+3] = (ma_int16)right1;
+ pOutputSamples[i*8+4] = (ma_int16)left2;
+ pOutputSamples[i*8+5] = (ma_int16)right2;
+ pOutputSamples[i*8+6] = (ma_int16)left3;
+ pOutputSamples[i*8+7] = (ma_int16)right3;
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- drflac_uint32 left = pInputSamples0U32[i] << shift0;
- drflac_uint32 side = pInputSamples1U32[i] << shift1;
- drflac_uint32 right = left - side;
+ ma_uint32 left = pInputSamples0U32[i] << shift0;
+ ma_uint32 side = pInputSamples1U32[i] << shift1;
+ ma_uint32 right = left - side;
left >>= 16;
right >>= 16;
- pOutputSamples[i*2+0] = (drflac_int16)left;
- pOutputSamples[i*2+1] = (drflac_int16)right;
+ pOutputSamples[i*2+0] = (ma_int16)left;
+ pOutputSamples[i*2+1] = (ma_int16)right;
}
}
-#if defined(DRFLAC_SUPPORT_SSE2)
-static DRFLAC_INLINE void drflac_read_pcm_frames_s16__decode_left_side__sse2(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int16* pOutputSamples)
+#if defined(MA_DR_FLAC_SUPPORT_SSE2)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s16__decode_left_side__sse2(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int16* pOutputSamples)
{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
- DRFLAC_ASSERT(pFlac->bitsPerSample <= 24);
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ MA_DR_FLAC_ASSERT(pFlac->bitsPerSample <= 24);
for (i = 0; i < frameCount4; ++i) {
__m128i left = _mm_slli_epi32(_mm_loadu_si128((const __m128i*)pInputSamples0 + i), shift0);
__m128i side = _mm_slli_epi32(_mm_loadu_si128((const __m128i*)pInputSamples1 + i), shift1);
__m128i right = _mm_sub_epi32(left, side);
left = _mm_srai_epi32(left, 16);
right = _mm_srai_epi32(right, 16);
- _mm_storeu_si128((__m128i*)(pOutputSamples + i*8), drflac__mm_packs_interleaved_epi32(left, right));
+ _mm_storeu_si128((__m128i*)(pOutputSamples + i*8), ma_dr_flac__mm_packs_interleaved_epi32(left, right));
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- drflac_uint32 left = pInputSamples0U32[i] << shift0;
- drflac_uint32 side = pInputSamples1U32[i] << shift1;
- drflac_uint32 right = left - side;
+ ma_uint32 left = pInputSamples0U32[i] << shift0;
+ ma_uint32 side = pInputSamples1U32[i] << shift1;
+ ma_uint32 right = left - side;
left >>= 16;
right >>= 16;
- pOutputSamples[i*2+0] = (drflac_int16)left;
- pOutputSamples[i*2+1] = (drflac_int16)right;
+ pOutputSamples[i*2+0] = (ma_int16)left;
+ pOutputSamples[i*2+1] = (ma_int16)right;
}
}
#endif
-#if defined(DRFLAC_SUPPORT_NEON)
-static DRFLAC_INLINE void drflac_read_pcm_frames_s16__decode_left_side__neon(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int16* pOutputSamples)
+#if defined(MA_DR_FLAC_SUPPORT_NEON)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s16__decode_left_side__neon(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int16* pOutputSamples)
{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
int32x4_t shift0_4;
int32x4_t shift1_4;
- DRFLAC_ASSERT(pFlac->bitsPerSample <= 24);
+ MA_DR_FLAC_ASSERT(pFlac->bitsPerSample <= 24);
shift0_4 = vdupq_n_s32(shift0);
shift1_4 = vdupq_n_s32(shift1);
for (i = 0; i < frameCount4; ++i) {
@@ -86156,74 +88076,74 @@ static DRFLAC_INLINE void drflac_read_pcm_frames_s16__decode_left_side__neon(drf
right = vsubq_u32(left, side);
left = vshrq_n_u32(left, 16);
right = vshrq_n_u32(right, 16);
- drflac__vst2q_u16((drflac_uint16*)pOutputSamples + i*8, vzip_u16(vmovn_u32(left), vmovn_u32(right)));
+ ma_dr_flac__vst2q_u16((ma_uint16*)pOutputSamples + i*8, vzip_u16(vmovn_u32(left), vmovn_u32(right)));
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- drflac_uint32 left = pInputSamples0U32[i] << shift0;
- drflac_uint32 side = pInputSamples1U32[i] << shift1;
- drflac_uint32 right = left - side;
+ ma_uint32 left = pInputSamples0U32[i] << shift0;
+ ma_uint32 side = pInputSamples1U32[i] << shift1;
+ ma_uint32 right = left - side;
left >>= 16;
right >>= 16;
- pOutputSamples[i*2+0] = (drflac_int16)left;
- pOutputSamples[i*2+1] = (drflac_int16)right;
+ pOutputSamples[i*2+0] = (ma_int16)left;
+ pOutputSamples[i*2+1] = (ma_int16)right;
}
}
#endif
-static DRFLAC_INLINE void drflac_read_pcm_frames_s16__decode_left_side(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int16* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s16__decode_left_side(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int16* pOutputSamples)
{
-#if defined(DRFLAC_SUPPORT_SSE2)
- if (drflac__gIsSSE2Supported && pFlac->bitsPerSample <= 24) {
- drflac_read_pcm_frames_s16__decode_left_side__sse2(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+#if defined(MA_DR_FLAC_SUPPORT_SSE2)
+ if (ma_dr_flac__gIsSSE2Supported && pFlac->bitsPerSample <= 24) {
+ ma_dr_flac_read_pcm_frames_s16__decode_left_side__sse2(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
} else
-#elif defined(DRFLAC_SUPPORT_NEON)
- if (drflac__gIsNEONSupported && pFlac->bitsPerSample <= 24) {
- drflac_read_pcm_frames_s16__decode_left_side__neon(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+#elif defined(MA_DR_FLAC_SUPPORT_NEON)
+ if (ma_dr_flac__gIsNEONSupported && pFlac->bitsPerSample <= 24) {
+ ma_dr_flac_read_pcm_frames_s16__decode_left_side__neon(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
} else
#endif
{
#if 0
- drflac_read_pcm_frames_s16__decode_left_side__reference(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+ ma_dr_flac_read_pcm_frames_s16__decode_left_side__reference(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
#else
- drflac_read_pcm_frames_s16__decode_left_side__scalar(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+ ma_dr_flac_read_pcm_frames_s16__decode_left_side__scalar(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
#endif
}
}
#if 0
-static DRFLAC_INLINE void drflac_read_pcm_frames_s16__decode_right_side__reference(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int16* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s16__decode_right_side__reference(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int16* pOutputSamples)
{
- drflac_uint64 i;
+ ma_uint64 i;
for (i = 0; i < frameCount; ++i) {
- drflac_uint32 side = (drflac_uint32)pInputSamples0[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample);
- drflac_uint32 right = (drflac_uint32)pInputSamples1[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample);
- drflac_uint32 left = right + side;
+ ma_uint32 side = (ma_uint32)pInputSamples0[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample);
+ ma_uint32 right = (ma_uint32)pInputSamples1[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample);
+ ma_uint32 left = right + side;
left >>= 16;
right >>= 16;
- pOutputSamples[i*2+0] = (drflac_int16)left;
- pOutputSamples[i*2+1] = (drflac_int16)right;
+ pOutputSamples[i*2+0] = (ma_int16)left;
+ pOutputSamples[i*2+1] = (ma_int16)right;
}
}
#endif
-static DRFLAC_INLINE void drflac_read_pcm_frames_s16__decode_right_side__scalar(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int16* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s16__decode_right_side__scalar(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int16* pOutputSamples)
{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
for (i = 0; i < frameCount4; ++i) {
- drflac_uint32 side0 = pInputSamples0U32[i*4+0] << shift0;
- drflac_uint32 side1 = pInputSamples0U32[i*4+1] << shift0;
- drflac_uint32 side2 = pInputSamples0U32[i*4+2] << shift0;
- drflac_uint32 side3 = pInputSamples0U32[i*4+3] << shift0;
- drflac_uint32 right0 = pInputSamples1U32[i*4+0] << shift1;
- drflac_uint32 right1 = pInputSamples1U32[i*4+1] << shift1;
- drflac_uint32 right2 = pInputSamples1U32[i*4+2] << shift1;
- drflac_uint32 right3 = pInputSamples1U32[i*4+3] << shift1;
- drflac_uint32 left0 = right0 + side0;
- drflac_uint32 left1 = right1 + side1;
- drflac_uint32 left2 = right2 + side2;
- drflac_uint32 left3 = right3 + side3;
+ ma_uint32 side0 = pInputSamples0U32[i*4+0] << shift0;
+ ma_uint32 side1 = pInputSamples0U32[i*4+1] << shift0;
+ ma_uint32 side2 = pInputSamples0U32[i*4+2] << shift0;
+ ma_uint32 side3 = pInputSamples0U32[i*4+3] << shift0;
+ ma_uint32 right0 = pInputSamples1U32[i*4+0] << shift1;
+ ma_uint32 right1 = pInputSamples1U32[i*4+1] << shift1;
+ ma_uint32 right2 = pInputSamples1U32[i*4+2] << shift1;
+ ma_uint32 right3 = pInputSamples1U32[i*4+3] << shift1;
+ ma_uint32 left0 = right0 + side0;
+ ma_uint32 left1 = right1 + side1;
+ ma_uint32 left2 = right2 + side2;
+ ma_uint32 left3 = right3 + side3;
left0 >>= 16;
left1 >>= 16;
left2 >>= 16;
@@ -86232,66 +88152,66 @@ static DRFLAC_INLINE void drflac_read_pcm_frames_s16__decode_right_side__scalar(
right1 >>= 16;
right2 >>= 16;
right3 >>= 16;
- pOutputSamples[i*8+0] = (drflac_int16)left0;
- pOutputSamples[i*8+1] = (drflac_int16)right0;
- pOutputSamples[i*8+2] = (drflac_int16)left1;
- pOutputSamples[i*8+3] = (drflac_int16)right1;
- pOutputSamples[i*8+4] = (drflac_int16)left2;
- pOutputSamples[i*8+5] = (drflac_int16)right2;
- pOutputSamples[i*8+6] = (drflac_int16)left3;
- pOutputSamples[i*8+7] = (drflac_int16)right3;
+ pOutputSamples[i*8+0] = (ma_int16)left0;
+ pOutputSamples[i*8+1] = (ma_int16)right0;
+ pOutputSamples[i*8+2] = (ma_int16)left1;
+ pOutputSamples[i*8+3] = (ma_int16)right1;
+ pOutputSamples[i*8+4] = (ma_int16)left2;
+ pOutputSamples[i*8+5] = (ma_int16)right2;
+ pOutputSamples[i*8+6] = (ma_int16)left3;
+ pOutputSamples[i*8+7] = (ma_int16)right3;
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- drflac_uint32 side = pInputSamples0U32[i] << shift0;
- drflac_uint32 right = pInputSamples1U32[i] << shift1;
- drflac_uint32 left = right + side;
+ ma_uint32 side = pInputSamples0U32[i] << shift0;
+ ma_uint32 right = pInputSamples1U32[i] << shift1;
+ ma_uint32 left = right + side;
left >>= 16;
right >>= 16;
- pOutputSamples[i*2+0] = (drflac_int16)left;
- pOutputSamples[i*2+1] = (drflac_int16)right;
+ pOutputSamples[i*2+0] = (ma_int16)left;
+ pOutputSamples[i*2+1] = (ma_int16)right;
}
}
-#if defined(DRFLAC_SUPPORT_SSE2)
-static DRFLAC_INLINE void drflac_read_pcm_frames_s16__decode_right_side__sse2(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int16* pOutputSamples)
+#if defined(MA_DR_FLAC_SUPPORT_SSE2)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s16__decode_right_side__sse2(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int16* pOutputSamples)
{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
- DRFLAC_ASSERT(pFlac->bitsPerSample <= 24);
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ MA_DR_FLAC_ASSERT(pFlac->bitsPerSample <= 24);
for (i = 0; i < frameCount4; ++i) {
__m128i side = _mm_slli_epi32(_mm_loadu_si128((const __m128i*)pInputSamples0 + i), shift0);
__m128i right = _mm_slli_epi32(_mm_loadu_si128((const __m128i*)pInputSamples1 + i), shift1);
__m128i left = _mm_add_epi32(right, side);
left = _mm_srai_epi32(left, 16);
right = _mm_srai_epi32(right, 16);
- _mm_storeu_si128((__m128i*)(pOutputSamples + i*8), drflac__mm_packs_interleaved_epi32(left, right));
+ _mm_storeu_si128((__m128i*)(pOutputSamples + i*8), ma_dr_flac__mm_packs_interleaved_epi32(left, right));
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- drflac_uint32 side = pInputSamples0U32[i] << shift0;
- drflac_uint32 right = pInputSamples1U32[i] << shift1;
- drflac_uint32 left = right + side;
+ ma_uint32 side = pInputSamples0U32[i] << shift0;
+ ma_uint32 right = pInputSamples1U32[i] << shift1;
+ ma_uint32 left = right + side;
left >>= 16;
right >>= 16;
- pOutputSamples[i*2+0] = (drflac_int16)left;
- pOutputSamples[i*2+1] = (drflac_int16)right;
+ pOutputSamples[i*2+0] = (ma_int16)left;
+ pOutputSamples[i*2+1] = (ma_int16)right;
}
}
#endif
-#if defined(DRFLAC_SUPPORT_NEON)
-static DRFLAC_INLINE void drflac_read_pcm_frames_s16__decode_right_side__neon(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int16* pOutputSamples)
+#if defined(MA_DR_FLAC_SUPPORT_NEON)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s16__decode_right_side__neon(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int16* pOutputSamples)
{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
int32x4_t shift0_4;
int32x4_t shift1_4;
- DRFLAC_ASSERT(pFlac->bitsPerSample <= 24);
+ MA_DR_FLAC_ASSERT(pFlac->bitsPerSample <= 24);
shift0_4 = vdupq_n_s32(shift0);
shift1_4 = vdupq_n_s32(shift1);
for (i = 0; i < frameCount4; ++i) {
@@ -86303,76 +88223,76 @@ static DRFLAC_INLINE void drflac_read_pcm_frames_s16__decode_right_side__neon(dr
left = vaddq_u32(right, side);
left = vshrq_n_u32(left, 16);
right = vshrq_n_u32(right, 16);
- drflac__vst2q_u16((drflac_uint16*)pOutputSamples + i*8, vzip_u16(vmovn_u32(left), vmovn_u32(right)));
+ ma_dr_flac__vst2q_u16((ma_uint16*)pOutputSamples + i*8, vzip_u16(vmovn_u32(left), vmovn_u32(right)));
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- drflac_uint32 side = pInputSamples0U32[i] << shift0;
- drflac_uint32 right = pInputSamples1U32[i] << shift1;
- drflac_uint32 left = right + side;
+ ma_uint32 side = pInputSamples0U32[i] << shift0;
+ ma_uint32 right = pInputSamples1U32[i] << shift1;
+ ma_uint32 left = right + side;
left >>= 16;
right >>= 16;
- pOutputSamples[i*2+0] = (drflac_int16)left;
- pOutputSamples[i*2+1] = (drflac_int16)right;
+ pOutputSamples[i*2+0] = (ma_int16)left;
+ pOutputSamples[i*2+1] = (ma_int16)right;
}
}
#endif
-static DRFLAC_INLINE void drflac_read_pcm_frames_s16__decode_right_side(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int16* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s16__decode_right_side(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int16* pOutputSamples)
{
-#if defined(DRFLAC_SUPPORT_SSE2)
- if (drflac__gIsSSE2Supported && pFlac->bitsPerSample <= 24) {
- drflac_read_pcm_frames_s16__decode_right_side__sse2(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+#if defined(MA_DR_FLAC_SUPPORT_SSE2)
+ if (ma_dr_flac__gIsSSE2Supported && pFlac->bitsPerSample <= 24) {
+ ma_dr_flac_read_pcm_frames_s16__decode_right_side__sse2(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
} else
-#elif defined(DRFLAC_SUPPORT_NEON)
- if (drflac__gIsNEONSupported && pFlac->bitsPerSample <= 24) {
- drflac_read_pcm_frames_s16__decode_right_side__neon(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+#elif defined(MA_DR_FLAC_SUPPORT_NEON)
+ if (ma_dr_flac__gIsNEONSupported && pFlac->bitsPerSample <= 24) {
+ ma_dr_flac_read_pcm_frames_s16__decode_right_side__neon(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
} else
#endif
{
#if 0
- drflac_read_pcm_frames_s16__decode_right_side__reference(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+ ma_dr_flac_read_pcm_frames_s16__decode_right_side__reference(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
#else
- drflac_read_pcm_frames_s16__decode_right_side__scalar(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+ ma_dr_flac_read_pcm_frames_s16__decode_right_side__scalar(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
#endif
}
}
#if 0
-static DRFLAC_INLINE void drflac_read_pcm_frames_s16__decode_mid_side__reference(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int16* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s16__decode_mid_side__reference(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int16* pOutputSamples)
{
- for (drflac_uint64 i = 0; i < frameCount; ++i) {
- drflac_uint32 mid = (drflac_uint32)pInputSamples0[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 side = (drflac_uint32)pInputSamples1[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ for (ma_uint64 i = 0; i < frameCount; ++i) {
+ ma_uint32 mid = (ma_uint32)pInputSamples0[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 side = (ma_uint32)pInputSamples1[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
mid = (mid << 1) | (side & 0x01);
- pOutputSamples[i*2+0] = (drflac_int16)(((drflac_uint32)((drflac_int32)(mid + side) >> 1) << unusedBitsPerSample) >> 16);
- pOutputSamples[i*2+1] = (drflac_int16)(((drflac_uint32)((drflac_int32)(mid - side) >> 1) << unusedBitsPerSample) >> 16);
+ pOutputSamples[i*2+0] = (ma_int16)(((ma_uint32)((ma_int32)(mid + side) >> 1) << unusedBitsPerSample) >> 16);
+ pOutputSamples[i*2+1] = (ma_int16)(((ma_uint32)((ma_int32)(mid - side) >> 1) << unusedBitsPerSample) >> 16);
}
}
#endif
-static DRFLAC_INLINE void drflac_read_pcm_frames_s16__decode_mid_side__scalar(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int16* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s16__decode_mid_side__scalar(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int16* pOutputSamples)
{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_uint32 shift = unusedBitsPerSample;
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_uint32 shift = unusedBitsPerSample;
if (shift > 0) {
shift -= 1;
for (i = 0; i < frameCount4; ++i) {
- drflac_uint32 temp0L;
- drflac_uint32 temp1L;
- drflac_uint32 temp2L;
- drflac_uint32 temp3L;
- drflac_uint32 temp0R;
- drflac_uint32 temp1R;
- drflac_uint32 temp2R;
- drflac_uint32 temp3R;
- drflac_uint32 mid0 = pInputSamples0U32[i*4+0] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 mid1 = pInputSamples0U32[i*4+1] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 mid2 = pInputSamples0U32[i*4+2] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 mid3 = pInputSamples0U32[i*4+3] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 side0 = pInputSamples1U32[i*4+0] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
- drflac_uint32 side1 = pInputSamples1U32[i*4+1] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
- drflac_uint32 side2 = pInputSamples1U32[i*4+2] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
- drflac_uint32 side3 = pInputSamples1U32[i*4+3] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 temp0L;
+ ma_uint32 temp1L;
+ ma_uint32 temp2L;
+ ma_uint32 temp3L;
+ ma_uint32 temp0R;
+ ma_uint32 temp1R;
+ ma_uint32 temp2R;
+ ma_uint32 temp3R;
+ ma_uint32 mid0 = pInputSamples0U32[i*4+0] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 mid1 = pInputSamples0U32[i*4+1] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 mid2 = pInputSamples0U32[i*4+2] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 mid3 = pInputSamples0U32[i*4+3] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 side0 = pInputSamples1U32[i*4+0] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 side1 = pInputSamples1U32[i*4+1] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 side2 = pInputSamples1U32[i*4+2] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 side3 = pInputSamples1U32[i*4+3] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
mid0 = (mid0 << 1) | (side0 & 0x01);
mid1 = (mid1 << 1) | (side1 & 0x01);
mid2 = (mid2 << 1) | (side2 & 0x01);
@@ -86393,45 +88313,45 @@ static DRFLAC_INLINE void drflac_read_pcm_frames_s16__decode_mid_side__scalar(dr
temp1R >>= 16;
temp2R >>= 16;
temp3R >>= 16;
- pOutputSamples[i*8+0] = (drflac_int16)temp0L;
- pOutputSamples[i*8+1] = (drflac_int16)temp0R;
- pOutputSamples[i*8+2] = (drflac_int16)temp1L;
- pOutputSamples[i*8+3] = (drflac_int16)temp1R;
- pOutputSamples[i*8+4] = (drflac_int16)temp2L;
- pOutputSamples[i*8+5] = (drflac_int16)temp2R;
- pOutputSamples[i*8+6] = (drflac_int16)temp3L;
- pOutputSamples[i*8+7] = (drflac_int16)temp3R;
+ pOutputSamples[i*8+0] = (ma_int16)temp0L;
+ pOutputSamples[i*8+1] = (ma_int16)temp0R;
+ pOutputSamples[i*8+2] = (ma_int16)temp1L;
+ pOutputSamples[i*8+3] = (ma_int16)temp1R;
+ pOutputSamples[i*8+4] = (ma_int16)temp2L;
+ pOutputSamples[i*8+5] = (ma_int16)temp2R;
+ pOutputSamples[i*8+6] = (ma_int16)temp3L;
+ pOutputSamples[i*8+7] = (ma_int16)temp3R;
}
} else {
for (i = 0; i < frameCount4; ++i) {
- drflac_uint32 temp0L;
- drflac_uint32 temp1L;
- drflac_uint32 temp2L;
- drflac_uint32 temp3L;
- drflac_uint32 temp0R;
- drflac_uint32 temp1R;
- drflac_uint32 temp2R;
- drflac_uint32 temp3R;
- drflac_uint32 mid0 = pInputSamples0U32[i*4+0] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 mid1 = pInputSamples0U32[i*4+1] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 mid2 = pInputSamples0U32[i*4+2] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 mid3 = pInputSamples0U32[i*4+3] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 side0 = pInputSamples1U32[i*4+0] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
- drflac_uint32 side1 = pInputSamples1U32[i*4+1] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
- drflac_uint32 side2 = pInputSamples1U32[i*4+2] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
- drflac_uint32 side3 = pInputSamples1U32[i*4+3] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 temp0L;
+ ma_uint32 temp1L;
+ ma_uint32 temp2L;
+ ma_uint32 temp3L;
+ ma_uint32 temp0R;
+ ma_uint32 temp1R;
+ ma_uint32 temp2R;
+ ma_uint32 temp3R;
+ ma_uint32 mid0 = pInputSamples0U32[i*4+0] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 mid1 = pInputSamples0U32[i*4+1] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 mid2 = pInputSamples0U32[i*4+2] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 mid3 = pInputSamples0U32[i*4+3] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 side0 = pInputSamples1U32[i*4+0] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 side1 = pInputSamples1U32[i*4+1] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 side2 = pInputSamples1U32[i*4+2] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 side3 = pInputSamples1U32[i*4+3] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
mid0 = (mid0 << 1) | (side0 & 0x01);
mid1 = (mid1 << 1) | (side1 & 0x01);
mid2 = (mid2 << 1) | (side2 & 0x01);
mid3 = (mid3 << 1) | (side3 & 0x01);
- temp0L = ((drflac_int32)(mid0 + side0) >> 1);
- temp1L = ((drflac_int32)(mid1 + side1) >> 1);
- temp2L = ((drflac_int32)(mid2 + side2) >> 1);
- temp3L = ((drflac_int32)(mid3 + side3) >> 1);
- temp0R = ((drflac_int32)(mid0 - side0) >> 1);
- temp1R = ((drflac_int32)(mid1 - side1) >> 1);
- temp2R = ((drflac_int32)(mid2 - side2) >> 1);
- temp3R = ((drflac_int32)(mid3 - side3) >> 1);
+ temp0L = ((ma_int32)(mid0 + side0) >> 1);
+ temp1L = ((ma_int32)(mid1 + side1) >> 1);
+ temp2L = ((ma_int32)(mid2 + side2) >> 1);
+ temp3L = ((ma_int32)(mid3 + side3) >> 1);
+ temp0R = ((ma_int32)(mid0 - side0) >> 1);
+ temp1R = ((ma_int32)(mid1 - side1) >> 1);
+ temp2R = ((ma_int32)(mid2 - side2) >> 1);
+ temp3R = ((ma_int32)(mid3 - side3) >> 1);
temp0L >>= 16;
temp1L >>= 16;
temp2L >>= 16;
@@ -86440,33 +88360,33 @@ static DRFLAC_INLINE void drflac_read_pcm_frames_s16__decode_mid_side__scalar(dr
temp1R >>= 16;
temp2R >>= 16;
temp3R >>= 16;
- pOutputSamples[i*8+0] = (drflac_int16)temp0L;
- pOutputSamples[i*8+1] = (drflac_int16)temp0R;
- pOutputSamples[i*8+2] = (drflac_int16)temp1L;
- pOutputSamples[i*8+3] = (drflac_int16)temp1R;
- pOutputSamples[i*8+4] = (drflac_int16)temp2L;
- pOutputSamples[i*8+5] = (drflac_int16)temp2R;
- pOutputSamples[i*8+6] = (drflac_int16)temp3L;
- pOutputSamples[i*8+7] = (drflac_int16)temp3R;
+ pOutputSamples[i*8+0] = (ma_int16)temp0L;
+ pOutputSamples[i*8+1] = (ma_int16)temp0R;
+ pOutputSamples[i*8+2] = (ma_int16)temp1L;
+ pOutputSamples[i*8+3] = (ma_int16)temp1R;
+ pOutputSamples[i*8+4] = (ma_int16)temp2L;
+ pOutputSamples[i*8+5] = (ma_int16)temp2R;
+ pOutputSamples[i*8+6] = (ma_int16)temp3L;
+ pOutputSamples[i*8+7] = (ma_int16)temp3R;
}
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- drflac_uint32 mid = pInputSamples0U32[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 side = pInputSamples1U32[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 mid = pInputSamples0U32[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 side = pInputSamples1U32[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
mid = (mid << 1) | (side & 0x01);
- pOutputSamples[i*2+0] = (drflac_int16)(((drflac_uint32)((drflac_int32)(mid + side) >> 1) << unusedBitsPerSample) >> 16);
- pOutputSamples[i*2+1] = (drflac_int16)(((drflac_uint32)((drflac_int32)(mid - side) >> 1) << unusedBitsPerSample) >> 16);
+ pOutputSamples[i*2+0] = (ma_int16)(((ma_uint32)((ma_int32)(mid + side) >> 1) << unusedBitsPerSample) >> 16);
+ pOutputSamples[i*2+1] = (ma_int16)(((ma_uint32)((ma_int32)(mid - side) >> 1) << unusedBitsPerSample) >> 16);
}
}
-#if defined(DRFLAC_SUPPORT_SSE2)
-static DRFLAC_INLINE void drflac_read_pcm_frames_s16__decode_mid_side__sse2(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int16* pOutputSamples)
+#if defined(MA_DR_FLAC_SUPPORT_SSE2)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s16__decode_mid_side__sse2(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int16* pOutputSamples)
{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_uint32 shift = unusedBitsPerSample;
- DRFLAC_ASSERT(pFlac->bitsPerSample <= 24);
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_uint32 shift = unusedBitsPerSample;
+ MA_DR_FLAC_ASSERT(pFlac->bitsPerSample <= 24);
if (shift == 0) {
for (i = 0; i < frameCount4; ++i) {
__m128i mid;
@@ -86480,14 +88400,14 @@ static DRFLAC_INLINE void drflac_read_pcm_frames_s16__decode_mid_side__sse2(drfl
right = _mm_srai_epi32(_mm_sub_epi32(mid, side), 1);
left = _mm_srai_epi32(left, 16);
right = _mm_srai_epi32(right, 16);
- _mm_storeu_si128((__m128i*)(pOutputSamples + i*8), drflac__mm_packs_interleaved_epi32(left, right));
+ _mm_storeu_si128((__m128i*)(pOutputSamples + i*8), ma_dr_flac__mm_packs_interleaved_epi32(left, right));
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- drflac_uint32 mid = pInputSamples0U32[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 side = pInputSamples1U32[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 mid = pInputSamples0U32[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 side = pInputSamples1U32[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
mid = (mid << 1) | (side & 0x01);
- pOutputSamples[i*2+0] = (drflac_int16)(((drflac_int32)(mid + side) >> 1) >> 16);
- pOutputSamples[i*2+1] = (drflac_int16)(((drflac_int32)(mid - side) >> 1) >> 16);
+ pOutputSamples[i*2+0] = (ma_int16)(((ma_int32)(mid + side) >> 1) >> 16);
+ pOutputSamples[i*2+1] = (ma_int16)(((ma_int32)(mid - side) >> 1) >> 16);
}
} else {
shift -= 1;
@@ -86503,29 +88423,29 @@ static DRFLAC_INLINE void drflac_read_pcm_frames_s16__decode_mid_side__sse2(drfl
right = _mm_slli_epi32(_mm_sub_epi32(mid, side), shift);
left = _mm_srai_epi32(left, 16);
right = _mm_srai_epi32(right, 16);
- _mm_storeu_si128((__m128i*)(pOutputSamples + i*8), drflac__mm_packs_interleaved_epi32(left, right));
+ _mm_storeu_si128((__m128i*)(pOutputSamples + i*8), ma_dr_flac__mm_packs_interleaved_epi32(left, right));
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- drflac_uint32 mid = pInputSamples0U32[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 side = pInputSamples1U32[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 mid = pInputSamples0U32[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 side = pInputSamples1U32[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
mid = (mid << 1) | (side & 0x01);
- pOutputSamples[i*2+0] = (drflac_int16)(((mid + side) << shift) >> 16);
- pOutputSamples[i*2+1] = (drflac_int16)(((mid - side) << shift) >> 16);
+ pOutputSamples[i*2+0] = (ma_int16)(((mid + side) << shift) >> 16);
+ pOutputSamples[i*2+1] = (ma_int16)(((mid - side) << shift) >> 16);
}
}
}
#endif
-#if defined(DRFLAC_SUPPORT_NEON)
-static DRFLAC_INLINE void drflac_read_pcm_frames_s16__decode_mid_side__neon(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int16* pOutputSamples)
+#if defined(MA_DR_FLAC_SUPPORT_NEON)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s16__decode_mid_side__neon(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int16* pOutputSamples)
{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_uint32 shift = unusedBitsPerSample;
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_uint32 shift = unusedBitsPerSample;
int32x4_t wbpsShift0_4;
int32x4_t wbpsShift1_4;
- DRFLAC_ASSERT(pFlac->bitsPerSample <= 24);
+ MA_DR_FLAC_ASSERT(pFlac->bitsPerSample <= 24);
wbpsShift0_4 = vdupq_n_s32(pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample);
wbpsShift1_4 = vdupq_n_s32(pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample);
if (shift == 0) {
@@ -86541,14 +88461,14 @@ static DRFLAC_INLINE void drflac_read_pcm_frames_s16__decode_mid_side__neon(drfl
right = vshrq_n_s32(vreinterpretq_s32_u32(vsubq_u32(mid, side)), 1);
left = vshrq_n_s32(left, 16);
right = vshrq_n_s32(right, 16);
- drflac__vst2q_s16(pOutputSamples + i*8, vzip_s16(vmovn_s32(left), vmovn_s32(right)));
+ ma_dr_flac__vst2q_s16(pOutputSamples + i*8, vzip_s16(vmovn_s32(left), vmovn_s32(right)));
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- drflac_uint32 mid = pInputSamples0U32[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 side = pInputSamples1U32[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 mid = pInputSamples0U32[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 side = pInputSamples1U32[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
mid = (mid << 1) | (side & 0x01);
- pOutputSamples[i*2+0] = (drflac_int16)(((drflac_int32)(mid + side) >> 1) >> 16);
- pOutputSamples[i*2+1] = (drflac_int16)(((drflac_int32)(mid - side) >> 1) >> 16);
+ pOutputSamples[i*2+0] = (ma_int16)(((ma_int32)(mid + side) >> 1) >> 16);
+ pOutputSamples[i*2+1] = (ma_int16)(((ma_int32)(mid - side) >> 1) >> 16);
}
} else {
int32x4_t shift4;
@@ -86566,63 +88486,63 @@ static DRFLAC_INLINE void drflac_read_pcm_frames_s16__decode_mid_side__neon(drfl
right = vreinterpretq_s32_u32(vshlq_u32(vsubq_u32(mid, side), shift4));
left = vshrq_n_s32(left, 16);
right = vshrq_n_s32(right, 16);
- drflac__vst2q_s16(pOutputSamples + i*8, vzip_s16(vmovn_s32(left), vmovn_s32(right)));
+ ma_dr_flac__vst2q_s16(pOutputSamples + i*8, vzip_s16(vmovn_s32(left), vmovn_s32(right)));
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- drflac_uint32 mid = pInputSamples0U32[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 side = pInputSamples1U32[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 mid = pInputSamples0U32[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 side = pInputSamples1U32[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
mid = (mid << 1) | (side & 0x01);
- pOutputSamples[i*2+0] = (drflac_int16)(((mid + side) << shift) >> 16);
- pOutputSamples[i*2+1] = (drflac_int16)(((mid - side) << shift) >> 16);
+ pOutputSamples[i*2+0] = (ma_int16)(((mid + side) << shift) >> 16);
+ pOutputSamples[i*2+1] = (ma_int16)(((mid - side) << shift) >> 16);
}
}
}
#endif
-static DRFLAC_INLINE void drflac_read_pcm_frames_s16__decode_mid_side(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int16* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s16__decode_mid_side(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int16* pOutputSamples)
{
-#if defined(DRFLAC_SUPPORT_SSE2)
- if (drflac__gIsSSE2Supported && pFlac->bitsPerSample <= 24) {
- drflac_read_pcm_frames_s16__decode_mid_side__sse2(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+#if defined(MA_DR_FLAC_SUPPORT_SSE2)
+ if (ma_dr_flac__gIsSSE2Supported && pFlac->bitsPerSample <= 24) {
+ ma_dr_flac_read_pcm_frames_s16__decode_mid_side__sse2(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
} else
-#elif defined(DRFLAC_SUPPORT_NEON)
- if (drflac__gIsNEONSupported && pFlac->bitsPerSample <= 24) {
- drflac_read_pcm_frames_s16__decode_mid_side__neon(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+#elif defined(MA_DR_FLAC_SUPPORT_NEON)
+ if (ma_dr_flac__gIsNEONSupported && pFlac->bitsPerSample <= 24) {
+ ma_dr_flac_read_pcm_frames_s16__decode_mid_side__neon(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
} else
#endif
{
#if 0
- drflac_read_pcm_frames_s16__decode_mid_side__reference(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+ ma_dr_flac_read_pcm_frames_s16__decode_mid_side__reference(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
#else
- drflac_read_pcm_frames_s16__decode_mid_side__scalar(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+ ma_dr_flac_read_pcm_frames_s16__decode_mid_side__scalar(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
#endif
}
}
#if 0
-static DRFLAC_INLINE void drflac_read_pcm_frames_s16__decode_independent_stereo__reference(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int16* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s16__decode_independent_stereo__reference(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int16* pOutputSamples)
{
- for (drflac_uint64 i = 0; i < frameCount; ++i) {
- pOutputSamples[i*2+0] = (drflac_int16)((drflac_int32)((drflac_uint32)pInputSamples0[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample)) >> 16);
- pOutputSamples[i*2+1] = (drflac_int16)((drflac_int32)((drflac_uint32)pInputSamples1[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample)) >> 16);
+ for (ma_uint64 i = 0; i < frameCount; ++i) {
+ pOutputSamples[i*2+0] = (ma_int16)((ma_int32)((ma_uint32)pInputSamples0[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample)) >> 16);
+ pOutputSamples[i*2+1] = (ma_int16)((ma_int32)((ma_uint32)pInputSamples1[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample)) >> 16);
}
}
#endif
-static DRFLAC_INLINE void drflac_read_pcm_frames_s16__decode_independent_stereo__scalar(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int16* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s16__decode_independent_stereo__scalar(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int16* pOutputSamples)
{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
for (i = 0; i < frameCount4; ++i) {
- drflac_uint32 tempL0 = pInputSamples0U32[i*4+0] << shift0;
- drflac_uint32 tempL1 = pInputSamples0U32[i*4+1] << shift0;
- drflac_uint32 tempL2 = pInputSamples0U32[i*4+2] << shift0;
- drflac_uint32 tempL3 = pInputSamples0U32[i*4+3] << shift0;
- drflac_uint32 tempR0 = pInputSamples1U32[i*4+0] << shift1;
- drflac_uint32 tempR1 = pInputSamples1U32[i*4+1] << shift1;
- drflac_uint32 tempR2 = pInputSamples1U32[i*4+2] << shift1;
- drflac_uint32 tempR3 = pInputSamples1U32[i*4+3] << shift1;
+ ma_uint32 tempL0 = pInputSamples0U32[i*4+0] << shift0;
+ ma_uint32 tempL1 = pInputSamples0U32[i*4+1] << shift0;
+ ma_uint32 tempL2 = pInputSamples0U32[i*4+2] << shift0;
+ ma_uint32 tempL3 = pInputSamples0U32[i*4+3] << shift0;
+ ma_uint32 tempR0 = pInputSamples1U32[i*4+0] << shift1;
+ ma_uint32 tempR1 = pInputSamples1U32[i*4+1] << shift1;
+ ma_uint32 tempR2 = pInputSamples1U32[i*4+2] << shift1;
+ ma_uint32 tempR3 = pInputSamples1U32[i*4+3] << shift1;
tempL0 >>= 16;
tempL1 >>= 16;
tempL2 >>= 16;
@@ -86631,51 +88551,51 @@ static DRFLAC_INLINE void drflac_read_pcm_frames_s16__decode_independent_stereo_
tempR1 >>= 16;
tempR2 >>= 16;
tempR3 >>= 16;
- pOutputSamples[i*8+0] = (drflac_int16)tempL0;
- pOutputSamples[i*8+1] = (drflac_int16)tempR0;
- pOutputSamples[i*8+2] = (drflac_int16)tempL1;
- pOutputSamples[i*8+3] = (drflac_int16)tempR1;
- pOutputSamples[i*8+4] = (drflac_int16)tempL2;
- pOutputSamples[i*8+5] = (drflac_int16)tempR2;
- pOutputSamples[i*8+6] = (drflac_int16)tempL3;
- pOutputSamples[i*8+7] = (drflac_int16)tempR3;
+ pOutputSamples[i*8+0] = (ma_int16)tempL0;
+ pOutputSamples[i*8+1] = (ma_int16)tempR0;
+ pOutputSamples[i*8+2] = (ma_int16)tempL1;
+ pOutputSamples[i*8+3] = (ma_int16)tempR1;
+ pOutputSamples[i*8+4] = (ma_int16)tempL2;
+ pOutputSamples[i*8+5] = (ma_int16)tempR2;
+ pOutputSamples[i*8+6] = (ma_int16)tempL3;
+ pOutputSamples[i*8+7] = (ma_int16)tempR3;
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- pOutputSamples[i*2+0] = (drflac_int16)((pInputSamples0U32[i] << shift0) >> 16);
- pOutputSamples[i*2+1] = (drflac_int16)((pInputSamples1U32[i] << shift1) >> 16);
+ pOutputSamples[i*2+0] = (ma_int16)((pInputSamples0U32[i] << shift0) >> 16);
+ pOutputSamples[i*2+1] = (ma_int16)((pInputSamples1U32[i] << shift1) >> 16);
}
}
-#if defined(DRFLAC_SUPPORT_SSE2)
-static DRFLAC_INLINE void drflac_read_pcm_frames_s16__decode_independent_stereo__sse2(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int16* pOutputSamples)
+#if defined(MA_DR_FLAC_SUPPORT_SSE2)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s16__decode_independent_stereo__sse2(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int16* pOutputSamples)
{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
for (i = 0; i < frameCount4; ++i) {
__m128i left = _mm_slli_epi32(_mm_loadu_si128((const __m128i*)pInputSamples0 + i), shift0);
__m128i right = _mm_slli_epi32(_mm_loadu_si128((const __m128i*)pInputSamples1 + i), shift1);
left = _mm_srai_epi32(left, 16);
right = _mm_srai_epi32(right, 16);
- _mm_storeu_si128((__m128i*)(pOutputSamples + i*8), drflac__mm_packs_interleaved_epi32(left, right));
+ _mm_storeu_si128((__m128i*)(pOutputSamples + i*8), ma_dr_flac__mm_packs_interleaved_epi32(left, right));
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- pOutputSamples[i*2+0] = (drflac_int16)((pInputSamples0U32[i] << shift0) >> 16);
- pOutputSamples[i*2+1] = (drflac_int16)((pInputSamples1U32[i] << shift1) >> 16);
+ pOutputSamples[i*2+0] = (ma_int16)((pInputSamples0U32[i] << shift0) >> 16);
+ pOutputSamples[i*2+1] = (ma_int16)((pInputSamples1U32[i] << shift1) >> 16);
}
}
#endif
-#if defined(DRFLAC_SUPPORT_NEON)
-static DRFLAC_INLINE void drflac_read_pcm_frames_s16__decode_independent_stereo__neon(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int16* pOutputSamples)
+#if defined(MA_DR_FLAC_SUPPORT_NEON)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s16__decode_independent_stereo__neon(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int16* pOutputSamples)
{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
int32x4_t shift0_4 = vdupq_n_s32(shift0);
int32x4_t shift1_4 = vdupq_n_s32(shift1);
for (i = 0; i < frameCount4; ++i) {
@@ -86685,88 +88605,88 @@ static DRFLAC_INLINE void drflac_read_pcm_frames_s16__decode_independent_stereo_
right = vreinterpretq_s32_u32(vshlq_u32(vld1q_u32(pInputSamples1U32 + i*4), shift1_4));
left = vshrq_n_s32(left, 16);
right = vshrq_n_s32(right, 16);
- drflac__vst2q_s16(pOutputSamples + i*8, vzip_s16(vmovn_s32(left), vmovn_s32(right)));
+ ma_dr_flac__vst2q_s16(pOutputSamples + i*8, vzip_s16(vmovn_s32(left), vmovn_s32(right)));
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- pOutputSamples[i*2+0] = (drflac_int16)((pInputSamples0U32[i] << shift0) >> 16);
- pOutputSamples[i*2+1] = (drflac_int16)((pInputSamples1U32[i] << shift1) >> 16);
+ pOutputSamples[i*2+0] = (ma_int16)((pInputSamples0U32[i] << shift0) >> 16);
+ pOutputSamples[i*2+1] = (ma_int16)((pInputSamples1U32[i] << shift1) >> 16);
}
}
#endif
-static DRFLAC_INLINE void drflac_read_pcm_frames_s16__decode_independent_stereo(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, drflac_int16* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_s16__decode_independent_stereo(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, ma_int16* pOutputSamples)
{
-#if defined(DRFLAC_SUPPORT_SSE2)
- if (drflac__gIsSSE2Supported && pFlac->bitsPerSample <= 24) {
- drflac_read_pcm_frames_s16__decode_independent_stereo__sse2(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+#if defined(MA_DR_FLAC_SUPPORT_SSE2)
+ if (ma_dr_flac__gIsSSE2Supported && pFlac->bitsPerSample <= 24) {
+ ma_dr_flac_read_pcm_frames_s16__decode_independent_stereo__sse2(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
} else
-#elif defined(DRFLAC_SUPPORT_NEON)
- if (drflac__gIsNEONSupported && pFlac->bitsPerSample <= 24) {
- drflac_read_pcm_frames_s16__decode_independent_stereo__neon(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+#elif defined(MA_DR_FLAC_SUPPORT_NEON)
+ if (ma_dr_flac__gIsNEONSupported && pFlac->bitsPerSample <= 24) {
+ ma_dr_flac_read_pcm_frames_s16__decode_independent_stereo__neon(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
} else
#endif
{
#if 0
- drflac_read_pcm_frames_s16__decode_independent_stereo__reference(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+ ma_dr_flac_read_pcm_frames_s16__decode_independent_stereo__reference(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
#else
- drflac_read_pcm_frames_s16__decode_independent_stereo__scalar(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+ ma_dr_flac_read_pcm_frames_s16__decode_independent_stereo__scalar(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
#endif
}
}
-DRFLAC_API drflac_uint64 drflac_read_pcm_frames_s16(drflac* pFlac, drflac_uint64 framesToRead, drflac_int16* pBufferOut)
+MA_API ma_uint64 ma_dr_flac_read_pcm_frames_s16(ma_dr_flac* pFlac, ma_uint64 framesToRead, ma_int16* pBufferOut)
{
- drflac_uint64 framesRead;
- drflac_uint32 unusedBitsPerSample;
+ ma_uint64 framesRead;
+ ma_uint32 unusedBitsPerSample;
if (pFlac == NULL || framesToRead == 0) {
return 0;
}
if (pBufferOut == NULL) {
- return drflac__seek_forward_by_pcm_frames(pFlac, framesToRead);
+ return ma_dr_flac__seek_forward_by_pcm_frames(pFlac, framesToRead);
}
- DRFLAC_ASSERT(pFlac->bitsPerSample <= 32);
+ MA_DR_FLAC_ASSERT(pFlac->bitsPerSample <= 32);
unusedBitsPerSample = 32 - pFlac->bitsPerSample;
framesRead = 0;
while (framesToRead > 0) {
if (pFlac->currentFLACFrame.pcmFramesRemaining == 0) {
- if (!drflac__read_and_decode_next_flac_frame(pFlac)) {
+ if (!ma_dr_flac__read_and_decode_next_flac_frame(pFlac)) {
break;
}
} else {
- unsigned int channelCount = drflac__get_channel_count_from_channel_assignment(pFlac->currentFLACFrame.header.channelAssignment);
- drflac_uint64 iFirstPCMFrame = pFlac->currentFLACFrame.header.blockSizeInPCMFrames - pFlac->currentFLACFrame.pcmFramesRemaining;
- drflac_uint64 frameCountThisIteration = framesToRead;
+ unsigned int channelCount = ma_dr_flac__get_channel_count_from_channel_assignment(pFlac->currentFLACFrame.header.channelAssignment);
+ ma_uint64 iFirstPCMFrame = pFlac->currentFLACFrame.header.blockSizeInPCMFrames - pFlac->currentFLACFrame.pcmFramesRemaining;
+ ma_uint64 frameCountThisIteration = framesToRead;
if (frameCountThisIteration > pFlac->currentFLACFrame.pcmFramesRemaining) {
frameCountThisIteration = pFlac->currentFLACFrame.pcmFramesRemaining;
}
if (channelCount == 2) {
- const drflac_int32* pDecodedSamples0 = pFlac->currentFLACFrame.subframes[0].pSamplesS32 + iFirstPCMFrame;
- const drflac_int32* pDecodedSamples1 = pFlac->currentFLACFrame.subframes[1].pSamplesS32 + iFirstPCMFrame;
+ const ma_int32* pDecodedSamples0 = pFlac->currentFLACFrame.subframes[0].pSamplesS32 + iFirstPCMFrame;
+ const ma_int32* pDecodedSamples1 = pFlac->currentFLACFrame.subframes[1].pSamplesS32 + iFirstPCMFrame;
switch (pFlac->currentFLACFrame.header.channelAssignment)
{
- case DRFLAC_CHANNEL_ASSIGNMENT_LEFT_SIDE:
+ case MA_DR_FLAC_CHANNEL_ASSIGNMENT_LEFT_SIDE:
{
- drflac_read_pcm_frames_s16__decode_left_side(pFlac, frameCountThisIteration, unusedBitsPerSample, pDecodedSamples0, pDecodedSamples1, pBufferOut);
+ ma_dr_flac_read_pcm_frames_s16__decode_left_side(pFlac, frameCountThisIteration, unusedBitsPerSample, pDecodedSamples0, pDecodedSamples1, pBufferOut);
} break;
- case DRFLAC_CHANNEL_ASSIGNMENT_RIGHT_SIDE:
+ case MA_DR_FLAC_CHANNEL_ASSIGNMENT_RIGHT_SIDE:
{
- drflac_read_pcm_frames_s16__decode_right_side(pFlac, frameCountThisIteration, unusedBitsPerSample, pDecodedSamples0, pDecodedSamples1, pBufferOut);
+ ma_dr_flac_read_pcm_frames_s16__decode_right_side(pFlac, frameCountThisIteration, unusedBitsPerSample, pDecodedSamples0, pDecodedSamples1, pBufferOut);
} break;
- case DRFLAC_CHANNEL_ASSIGNMENT_MID_SIDE:
+ case MA_DR_FLAC_CHANNEL_ASSIGNMENT_MID_SIDE:
{
- drflac_read_pcm_frames_s16__decode_mid_side(pFlac, frameCountThisIteration, unusedBitsPerSample, pDecodedSamples0, pDecodedSamples1, pBufferOut);
+ ma_dr_flac_read_pcm_frames_s16__decode_mid_side(pFlac, frameCountThisIteration, unusedBitsPerSample, pDecodedSamples0, pDecodedSamples1, pBufferOut);
} break;
- case DRFLAC_CHANNEL_ASSIGNMENT_INDEPENDENT:
+ case MA_DR_FLAC_CHANNEL_ASSIGNMENT_INDEPENDENT:
default:
{
- drflac_read_pcm_frames_s16__decode_independent_stereo(pFlac, frameCountThisIteration, unusedBitsPerSample, pDecodedSamples0, pDecodedSamples1, pBufferOut);
+ ma_dr_flac_read_pcm_frames_s16__decode_independent_stereo(pFlac, frameCountThisIteration, unusedBitsPerSample, pDecodedSamples0, pDecodedSamples1, pBufferOut);
} break;
}
} else {
- drflac_uint64 i;
+ ma_uint64 i;
for (i = 0; i < frameCountThisIteration; ++i) {
unsigned int j;
for (j = 0; j < channelCount; ++j) {
- drflac_int32 sampleS32 = (drflac_int32)((drflac_uint32)(pFlac->currentFLACFrame.subframes[j].pSamplesS32[iFirstPCMFrame + i]) << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[j].wastedBitsPerSample));
- pBufferOut[(i*channelCount)+j] = (drflac_int16)(sampleS32 >> 16);
+ ma_int32 sampleS32 = (ma_int32)((ma_uint32)(pFlac->currentFLACFrame.subframes[j].pSamplesS32[iFirstPCMFrame + i]) << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[j].wastedBitsPerSample));
+ pBufferOut[(i*channelCount)+j] = (ma_int16)(sampleS32 >> 16);
}
}
}
@@ -86774,74 +88694,74 @@ DRFLAC_API drflac_uint64 drflac_read_pcm_frames_s16(drflac* pFlac, drflac_uint64
pBufferOut += frameCountThisIteration * channelCount;
framesToRead -= frameCountThisIteration;
pFlac->currentPCMFrame += frameCountThisIteration;
- pFlac->currentFLACFrame.pcmFramesRemaining -= (drflac_uint32)frameCountThisIteration;
+ pFlac->currentFLACFrame.pcmFramesRemaining -= (ma_uint32)frameCountThisIteration;
}
}
return framesRead;
}
#if 0
-static DRFLAC_INLINE void drflac_read_pcm_frames_f32__decode_left_side__reference(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, float* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_f32__decode_left_side__reference(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, float* pOutputSamples)
{
- drflac_uint64 i;
+ ma_uint64 i;
for (i = 0; i < frameCount; ++i) {
- drflac_uint32 left = (drflac_uint32)pInputSamples0[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample);
- drflac_uint32 side = (drflac_uint32)pInputSamples1[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample);
- drflac_uint32 right = left - side;
- pOutputSamples[i*2+0] = (float)((drflac_int32)left / 2147483648.0);
- pOutputSamples[i*2+1] = (float)((drflac_int32)right / 2147483648.0);
+ ma_uint32 left = (ma_uint32)pInputSamples0[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample);
+ ma_uint32 side = (ma_uint32)pInputSamples1[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample);
+ ma_uint32 right = left - side;
+ pOutputSamples[i*2+0] = (float)((ma_int32)left / 2147483648.0);
+ pOutputSamples[i*2+1] = (float)((ma_int32)right / 2147483648.0);
}
}
#endif
-static DRFLAC_INLINE void drflac_read_pcm_frames_f32__decode_left_side__scalar(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, float* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_f32__decode_left_side__scalar(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, float* pOutputSamples)
{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
float factor = 1 / 2147483648.0;
for (i = 0; i < frameCount4; ++i) {
- drflac_uint32 left0 = pInputSamples0U32[i*4+0] << shift0;
- drflac_uint32 left1 = pInputSamples0U32[i*4+1] << shift0;
- drflac_uint32 left2 = pInputSamples0U32[i*4+2] << shift0;
- drflac_uint32 left3 = pInputSamples0U32[i*4+3] << shift0;
- drflac_uint32 side0 = pInputSamples1U32[i*4+0] << shift1;
- drflac_uint32 side1 = pInputSamples1U32[i*4+1] << shift1;
- drflac_uint32 side2 = pInputSamples1U32[i*4+2] << shift1;
- drflac_uint32 side3 = pInputSamples1U32[i*4+3] << shift1;
- drflac_uint32 right0 = left0 - side0;
- drflac_uint32 right1 = left1 - side1;
- drflac_uint32 right2 = left2 - side2;
- drflac_uint32 right3 = left3 - side3;
- pOutputSamples[i*8+0] = (drflac_int32)left0 * factor;
- pOutputSamples[i*8+1] = (drflac_int32)right0 * factor;
- pOutputSamples[i*8+2] = (drflac_int32)left1 * factor;
- pOutputSamples[i*8+3] = (drflac_int32)right1 * factor;
- pOutputSamples[i*8+4] = (drflac_int32)left2 * factor;
- pOutputSamples[i*8+5] = (drflac_int32)right2 * factor;
- pOutputSamples[i*8+6] = (drflac_int32)left3 * factor;
- pOutputSamples[i*8+7] = (drflac_int32)right3 * factor;
+ ma_uint32 left0 = pInputSamples0U32[i*4+0] << shift0;
+ ma_uint32 left1 = pInputSamples0U32[i*4+1] << shift0;
+ ma_uint32 left2 = pInputSamples0U32[i*4+2] << shift0;
+ ma_uint32 left3 = pInputSamples0U32[i*4+3] << shift0;
+ ma_uint32 side0 = pInputSamples1U32[i*4+0] << shift1;
+ ma_uint32 side1 = pInputSamples1U32[i*4+1] << shift1;
+ ma_uint32 side2 = pInputSamples1U32[i*4+2] << shift1;
+ ma_uint32 side3 = pInputSamples1U32[i*4+3] << shift1;
+ ma_uint32 right0 = left0 - side0;
+ ma_uint32 right1 = left1 - side1;
+ ma_uint32 right2 = left2 - side2;
+ ma_uint32 right3 = left3 - side3;
+ pOutputSamples[i*8+0] = (ma_int32)left0 * factor;
+ pOutputSamples[i*8+1] = (ma_int32)right0 * factor;
+ pOutputSamples[i*8+2] = (ma_int32)left1 * factor;
+ pOutputSamples[i*8+3] = (ma_int32)right1 * factor;
+ pOutputSamples[i*8+4] = (ma_int32)left2 * factor;
+ pOutputSamples[i*8+5] = (ma_int32)right2 * factor;
+ pOutputSamples[i*8+6] = (ma_int32)left3 * factor;
+ pOutputSamples[i*8+7] = (ma_int32)right3 * factor;
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- drflac_uint32 left = pInputSamples0U32[i] << shift0;
- drflac_uint32 side = pInputSamples1U32[i] << shift1;
- drflac_uint32 right = left - side;
- pOutputSamples[i*2+0] = (drflac_int32)left * factor;
- pOutputSamples[i*2+1] = (drflac_int32)right * factor;
- }
-}
-#if defined(DRFLAC_SUPPORT_SSE2)
-static DRFLAC_INLINE void drflac_read_pcm_frames_f32__decode_left_side__sse2(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, float* pOutputSamples)
-{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_uint32 shift0 = (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample) - 8;
- drflac_uint32 shift1 = (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample) - 8;
+ ma_uint32 left = pInputSamples0U32[i] << shift0;
+ ma_uint32 side = pInputSamples1U32[i] << shift1;
+ ma_uint32 right = left - side;
+ pOutputSamples[i*2+0] = (ma_int32)left * factor;
+ pOutputSamples[i*2+1] = (ma_int32)right * factor;
+ }
+}
+#if defined(MA_DR_FLAC_SUPPORT_SSE2)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_f32__decode_left_side__sse2(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, float* pOutputSamples)
+{
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_uint32 shift0 = (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample) - 8;
+ ma_uint32 shift1 = (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample) - 8;
__m128 factor;
- DRFLAC_ASSERT(pFlac->bitsPerSample <= 24);
+ MA_DR_FLAC_ASSERT(pFlac->bitsPerSample <= 24);
factor = _mm_set1_ps(1.0f / 8388608.0f);
for (i = 0; i < frameCount4; ++i) {
__m128i left = _mm_slli_epi32(_mm_loadu_si128((const __m128i*)pInputSamples0 + i), shift0);
@@ -86853,27 +88773,27 @@ static DRFLAC_INLINE void drflac_read_pcm_frames_f32__decode_left_side__sse2(drf
_mm_storeu_ps(pOutputSamples + i*8 + 4, _mm_unpackhi_ps(leftf, rightf));
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- drflac_uint32 left = pInputSamples0U32[i] << shift0;
- drflac_uint32 side = pInputSamples1U32[i] << shift1;
- drflac_uint32 right = left - side;
- pOutputSamples[i*2+0] = (drflac_int32)left / 8388608.0f;
- pOutputSamples[i*2+1] = (drflac_int32)right / 8388608.0f;
+ ma_uint32 left = pInputSamples0U32[i] << shift0;
+ ma_uint32 side = pInputSamples1U32[i] << shift1;
+ ma_uint32 right = left - side;
+ pOutputSamples[i*2+0] = (ma_int32)left / 8388608.0f;
+ pOutputSamples[i*2+1] = (ma_int32)right / 8388608.0f;
}
}
#endif
-#if defined(DRFLAC_SUPPORT_NEON)
-static DRFLAC_INLINE void drflac_read_pcm_frames_f32__decode_left_side__neon(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, float* pOutputSamples)
+#if defined(MA_DR_FLAC_SUPPORT_NEON)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_f32__decode_left_side__neon(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, float* pOutputSamples)
{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_uint32 shift0 = (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample) - 8;
- drflac_uint32 shift1 = (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample) - 8;
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_uint32 shift0 = (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample) - 8;
+ ma_uint32 shift1 = (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample) - 8;
float32x4_t factor4;
int32x4_t shift0_4;
int32x4_t shift1_4;
- DRFLAC_ASSERT(pFlac->bitsPerSample <= 24);
+ MA_DR_FLAC_ASSERT(pFlac->bitsPerSample <= 24);
factor4 = vdupq_n_f32(1.0f / 8388608.0f);
shift0_4 = vdupq_n_s32(shift0);
shift1_4 = vdupq_n_s32(shift1);
@@ -86888,99 +88808,99 @@ static DRFLAC_INLINE void drflac_read_pcm_frames_f32__decode_left_side__neon(drf
right = vsubq_u32(left, side);
leftf = vmulq_f32(vcvtq_f32_s32(vreinterpretq_s32_u32(left)), factor4);
rightf = vmulq_f32(vcvtq_f32_s32(vreinterpretq_s32_u32(right)), factor4);
- drflac__vst2q_f32(pOutputSamples + i*8, vzipq_f32(leftf, rightf));
+ ma_dr_flac__vst2q_f32(pOutputSamples + i*8, vzipq_f32(leftf, rightf));
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- drflac_uint32 left = pInputSamples0U32[i] << shift0;
- drflac_uint32 side = pInputSamples1U32[i] << shift1;
- drflac_uint32 right = left - side;
- pOutputSamples[i*2+0] = (drflac_int32)left / 8388608.0f;
- pOutputSamples[i*2+1] = (drflac_int32)right / 8388608.0f;
+ ma_uint32 left = pInputSamples0U32[i] << shift0;
+ ma_uint32 side = pInputSamples1U32[i] << shift1;
+ ma_uint32 right = left - side;
+ pOutputSamples[i*2+0] = (ma_int32)left / 8388608.0f;
+ pOutputSamples[i*2+1] = (ma_int32)right / 8388608.0f;
}
}
#endif
-static DRFLAC_INLINE void drflac_read_pcm_frames_f32__decode_left_side(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, float* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_f32__decode_left_side(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, float* pOutputSamples)
{
-#if defined(DRFLAC_SUPPORT_SSE2)
- if (drflac__gIsSSE2Supported && pFlac->bitsPerSample <= 24) {
- drflac_read_pcm_frames_f32__decode_left_side__sse2(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+#if defined(MA_DR_FLAC_SUPPORT_SSE2)
+ if (ma_dr_flac__gIsSSE2Supported && pFlac->bitsPerSample <= 24) {
+ ma_dr_flac_read_pcm_frames_f32__decode_left_side__sse2(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
} else
-#elif defined(DRFLAC_SUPPORT_NEON)
- if (drflac__gIsNEONSupported && pFlac->bitsPerSample <= 24) {
- drflac_read_pcm_frames_f32__decode_left_side__neon(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+#elif defined(MA_DR_FLAC_SUPPORT_NEON)
+ if (ma_dr_flac__gIsNEONSupported && pFlac->bitsPerSample <= 24) {
+ ma_dr_flac_read_pcm_frames_f32__decode_left_side__neon(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
} else
#endif
{
#if 0
- drflac_read_pcm_frames_f32__decode_left_side__reference(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+ ma_dr_flac_read_pcm_frames_f32__decode_left_side__reference(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
#else
- drflac_read_pcm_frames_f32__decode_left_side__scalar(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+ ma_dr_flac_read_pcm_frames_f32__decode_left_side__scalar(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
#endif
}
}
#if 0
-static DRFLAC_INLINE void drflac_read_pcm_frames_f32__decode_right_side__reference(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, float* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_f32__decode_right_side__reference(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, float* pOutputSamples)
{
- drflac_uint64 i;
+ ma_uint64 i;
for (i = 0; i < frameCount; ++i) {
- drflac_uint32 side = (drflac_uint32)pInputSamples0[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample);
- drflac_uint32 right = (drflac_uint32)pInputSamples1[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample);
- drflac_uint32 left = right + side;
- pOutputSamples[i*2+0] = (float)((drflac_int32)left / 2147483648.0);
- pOutputSamples[i*2+1] = (float)((drflac_int32)right / 2147483648.0);
+ ma_uint32 side = (ma_uint32)pInputSamples0[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample);
+ ma_uint32 right = (ma_uint32)pInputSamples1[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample);
+ ma_uint32 left = right + side;
+ pOutputSamples[i*2+0] = (float)((ma_int32)left / 2147483648.0);
+ pOutputSamples[i*2+1] = (float)((ma_int32)right / 2147483648.0);
}
}
#endif
-static DRFLAC_INLINE void drflac_read_pcm_frames_f32__decode_right_side__scalar(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, float* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_f32__decode_right_side__scalar(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, float* pOutputSamples)
{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
float factor = 1 / 2147483648.0;
for (i = 0; i < frameCount4; ++i) {
- drflac_uint32 side0 = pInputSamples0U32[i*4+0] << shift0;
- drflac_uint32 side1 = pInputSamples0U32[i*4+1] << shift0;
- drflac_uint32 side2 = pInputSamples0U32[i*4+2] << shift0;
- drflac_uint32 side3 = pInputSamples0U32[i*4+3] << shift0;
- drflac_uint32 right0 = pInputSamples1U32[i*4+0] << shift1;
- drflac_uint32 right1 = pInputSamples1U32[i*4+1] << shift1;
- drflac_uint32 right2 = pInputSamples1U32[i*4+2] << shift1;
- drflac_uint32 right3 = pInputSamples1U32[i*4+3] << shift1;
- drflac_uint32 left0 = right0 + side0;
- drflac_uint32 left1 = right1 + side1;
- drflac_uint32 left2 = right2 + side2;
- drflac_uint32 left3 = right3 + side3;
- pOutputSamples[i*8+0] = (drflac_int32)left0 * factor;
- pOutputSamples[i*8+1] = (drflac_int32)right0 * factor;
- pOutputSamples[i*8+2] = (drflac_int32)left1 * factor;
- pOutputSamples[i*8+3] = (drflac_int32)right1 * factor;
- pOutputSamples[i*8+4] = (drflac_int32)left2 * factor;
- pOutputSamples[i*8+5] = (drflac_int32)right2 * factor;
- pOutputSamples[i*8+6] = (drflac_int32)left3 * factor;
- pOutputSamples[i*8+7] = (drflac_int32)right3 * factor;
+ ma_uint32 side0 = pInputSamples0U32[i*4+0] << shift0;
+ ma_uint32 side1 = pInputSamples0U32[i*4+1] << shift0;
+ ma_uint32 side2 = pInputSamples0U32[i*4+2] << shift0;
+ ma_uint32 side3 = pInputSamples0U32[i*4+3] << shift0;
+ ma_uint32 right0 = pInputSamples1U32[i*4+0] << shift1;
+ ma_uint32 right1 = pInputSamples1U32[i*4+1] << shift1;
+ ma_uint32 right2 = pInputSamples1U32[i*4+2] << shift1;
+ ma_uint32 right3 = pInputSamples1U32[i*4+3] << shift1;
+ ma_uint32 left0 = right0 + side0;
+ ma_uint32 left1 = right1 + side1;
+ ma_uint32 left2 = right2 + side2;
+ ma_uint32 left3 = right3 + side3;
+ pOutputSamples[i*8+0] = (ma_int32)left0 * factor;
+ pOutputSamples[i*8+1] = (ma_int32)right0 * factor;
+ pOutputSamples[i*8+2] = (ma_int32)left1 * factor;
+ pOutputSamples[i*8+3] = (ma_int32)right1 * factor;
+ pOutputSamples[i*8+4] = (ma_int32)left2 * factor;
+ pOutputSamples[i*8+5] = (ma_int32)right2 * factor;
+ pOutputSamples[i*8+6] = (ma_int32)left3 * factor;
+ pOutputSamples[i*8+7] = (ma_int32)right3 * factor;
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- drflac_uint32 side = pInputSamples0U32[i] << shift0;
- drflac_uint32 right = pInputSamples1U32[i] << shift1;
- drflac_uint32 left = right + side;
- pOutputSamples[i*2+0] = (drflac_int32)left * factor;
- pOutputSamples[i*2+1] = (drflac_int32)right * factor;
- }
-}
-#if defined(DRFLAC_SUPPORT_SSE2)
-static DRFLAC_INLINE void drflac_read_pcm_frames_f32__decode_right_side__sse2(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, float* pOutputSamples)
-{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_uint32 shift0 = (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample) - 8;
- drflac_uint32 shift1 = (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample) - 8;
+ ma_uint32 side = pInputSamples0U32[i] << shift0;
+ ma_uint32 right = pInputSamples1U32[i] << shift1;
+ ma_uint32 left = right + side;
+ pOutputSamples[i*2+0] = (ma_int32)left * factor;
+ pOutputSamples[i*2+1] = (ma_int32)right * factor;
+ }
+}
+#if defined(MA_DR_FLAC_SUPPORT_SSE2)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_f32__decode_right_side__sse2(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, float* pOutputSamples)
+{
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_uint32 shift0 = (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample) - 8;
+ ma_uint32 shift1 = (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample) - 8;
__m128 factor;
- DRFLAC_ASSERT(pFlac->bitsPerSample <= 24);
+ MA_DR_FLAC_ASSERT(pFlac->bitsPerSample <= 24);
factor = _mm_set1_ps(1.0f / 8388608.0f);
for (i = 0; i < frameCount4; ++i) {
__m128i side = _mm_slli_epi32(_mm_loadu_si128((const __m128i*)pInputSamples0 + i), shift0);
@@ -86992,27 +88912,27 @@ static DRFLAC_INLINE void drflac_read_pcm_frames_f32__decode_right_side__sse2(dr
_mm_storeu_ps(pOutputSamples + i*8 + 4, _mm_unpackhi_ps(leftf, rightf));
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- drflac_uint32 side = pInputSamples0U32[i] << shift0;
- drflac_uint32 right = pInputSamples1U32[i] << shift1;
- drflac_uint32 left = right + side;
- pOutputSamples[i*2+0] = (drflac_int32)left / 8388608.0f;
- pOutputSamples[i*2+1] = (drflac_int32)right / 8388608.0f;
+ ma_uint32 side = pInputSamples0U32[i] << shift0;
+ ma_uint32 right = pInputSamples1U32[i] << shift1;
+ ma_uint32 left = right + side;
+ pOutputSamples[i*2+0] = (ma_int32)left / 8388608.0f;
+ pOutputSamples[i*2+1] = (ma_int32)right / 8388608.0f;
}
}
#endif
-#if defined(DRFLAC_SUPPORT_NEON)
-static DRFLAC_INLINE void drflac_read_pcm_frames_f32__decode_right_side__neon(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, float* pOutputSamples)
+#if defined(MA_DR_FLAC_SUPPORT_NEON)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_f32__decode_right_side__neon(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, float* pOutputSamples)
{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_uint32 shift0 = (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample) - 8;
- drflac_uint32 shift1 = (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample) - 8;
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_uint32 shift0 = (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample) - 8;
+ ma_uint32 shift1 = (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample) - 8;
float32x4_t factor4;
int32x4_t shift0_4;
int32x4_t shift1_4;
- DRFLAC_ASSERT(pFlac->bitsPerSample <= 24);
+ MA_DR_FLAC_ASSERT(pFlac->bitsPerSample <= 24);
factor4 = vdupq_n_f32(1.0f / 8388608.0f);
shift0_4 = vdupq_n_s32(shift0);
shift1_4 = vdupq_n_s32(shift1);
@@ -87027,75 +88947,75 @@ static DRFLAC_INLINE void drflac_read_pcm_frames_f32__decode_right_side__neon(dr
left = vaddq_u32(right, side);
leftf = vmulq_f32(vcvtq_f32_s32(vreinterpretq_s32_u32(left)), factor4);
rightf = vmulq_f32(vcvtq_f32_s32(vreinterpretq_s32_u32(right)), factor4);
- drflac__vst2q_f32(pOutputSamples + i*8, vzipq_f32(leftf, rightf));
+ ma_dr_flac__vst2q_f32(pOutputSamples + i*8, vzipq_f32(leftf, rightf));
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- drflac_uint32 side = pInputSamples0U32[i] << shift0;
- drflac_uint32 right = pInputSamples1U32[i] << shift1;
- drflac_uint32 left = right + side;
- pOutputSamples[i*2+0] = (drflac_int32)left / 8388608.0f;
- pOutputSamples[i*2+1] = (drflac_int32)right / 8388608.0f;
+ ma_uint32 side = pInputSamples0U32[i] << shift0;
+ ma_uint32 right = pInputSamples1U32[i] << shift1;
+ ma_uint32 left = right + side;
+ pOutputSamples[i*2+0] = (ma_int32)left / 8388608.0f;
+ pOutputSamples[i*2+1] = (ma_int32)right / 8388608.0f;
}
}
#endif
-static DRFLAC_INLINE void drflac_read_pcm_frames_f32__decode_right_side(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, float* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_f32__decode_right_side(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, float* pOutputSamples)
{
-#if defined(DRFLAC_SUPPORT_SSE2)
- if (drflac__gIsSSE2Supported && pFlac->bitsPerSample <= 24) {
- drflac_read_pcm_frames_f32__decode_right_side__sse2(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+#if defined(MA_DR_FLAC_SUPPORT_SSE2)
+ if (ma_dr_flac__gIsSSE2Supported && pFlac->bitsPerSample <= 24) {
+ ma_dr_flac_read_pcm_frames_f32__decode_right_side__sse2(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
} else
-#elif defined(DRFLAC_SUPPORT_NEON)
- if (drflac__gIsNEONSupported && pFlac->bitsPerSample <= 24) {
- drflac_read_pcm_frames_f32__decode_right_side__neon(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+#elif defined(MA_DR_FLAC_SUPPORT_NEON)
+ if (ma_dr_flac__gIsNEONSupported && pFlac->bitsPerSample <= 24) {
+ ma_dr_flac_read_pcm_frames_f32__decode_right_side__neon(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
} else
#endif
{
#if 0
- drflac_read_pcm_frames_f32__decode_right_side__reference(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+ ma_dr_flac_read_pcm_frames_f32__decode_right_side__reference(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
#else
- drflac_read_pcm_frames_f32__decode_right_side__scalar(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+ ma_dr_flac_read_pcm_frames_f32__decode_right_side__scalar(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
#endif
}
}
#if 0
-static DRFLAC_INLINE void drflac_read_pcm_frames_f32__decode_mid_side__reference(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, float* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_f32__decode_mid_side__reference(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, float* pOutputSamples)
{
- for (drflac_uint64 i = 0; i < frameCount; ++i) {
- drflac_uint32 mid = (drflac_uint32)pInputSamples0[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 side = (drflac_uint32)pInputSamples1[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ for (ma_uint64 i = 0; i < frameCount; ++i) {
+ ma_uint32 mid = (ma_uint32)pInputSamples0[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 side = (ma_uint32)pInputSamples1[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
mid = (mid << 1) | (side & 0x01);
- pOutputSamples[i*2+0] = (float)((((drflac_int32)(mid + side) >> 1) << (unusedBitsPerSample)) / 2147483648.0);
- pOutputSamples[i*2+1] = (float)((((drflac_int32)(mid - side) >> 1) << (unusedBitsPerSample)) / 2147483648.0);
+ pOutputSamples[i*2+0] = (float)((((ma_int32)(mid + side) >> 1) << (unusedBitsPerSample)) / 2147483648.0);
+ pOutputSamples[i*2+1] = (float)((((ma_int32)(mid - side) >> 1) << (unusedBitsPerSample)) / 2147483648.0);
}
}
#endif
-static DRFLAC_INLINE void drflac_read_pcm_frames_f32__decode_mid_side__scalar(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, float* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_f32__decode_mid_side__scalar(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, float* pOutputSamples)
{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_uint32 shift = unusedBitsPerSample;
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_uint32 shift = unusedBitsPerSample;
float factor = 1 / 2147483648.0;
if (shift > 0) {
shift -= 1;
for (i = 0; i < frameCount4; ++i) {
- drflac_uint32 temp0L;
- drflac_uint32 temp1L;
- drflac_uint32 temp2L;
- drflac_uint32 temp3L;
- drflac_uint32 temp0R;
- drflac_uint32 temp1R;
- drflac_uint32 temp2R;
- drflac_uint32 temp3R;
- drflac_uint32 mid0 = pInputSamples0U32[i*4+0] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 mid1 = pInputSamples0U32[i*4+1] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 mid2 = pInputSamples0U32[i*4+2] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 mid3 = pInputSamples0U32[i*4+3] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 side0 = pInputSamples1U32[i*4+0] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
- drflac_uint32 side1 = pInputSamples1U32[i*4+1] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
- drflac_uint32 side2 = pInputSamples1U32[i*4+2] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
- drflac_uint32 side3 = pInputSamples1U32[i*4+3] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 temp0L;
+ ma_uint32 temp1L;
+ ma_uint32 temp2L;
+ ma_uint32 temp3L;
+ ma_uint32 temp0R;
+ ma_uint32 temp1R;
+ ma_uint32 temp2R;
+ ma_uint32 temp3R;
+ ma_uint32 mid0 = pInputSamples0U32[i*4+0] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 mid1 = pInputSamples0U32[i*4+1] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 mid2 = pInputSamples0U32[i*4+2] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 mid3 = pInputSamples0U32[i*4+3] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 side0 = pInputSamples1U32[i*4+0] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 side1 = pInputSamples1U32[i*4+1] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 side2 = pInputSamples1U32[i*4+2] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 side3 = pInputSamples1U32[i*4+3] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
mid0 = (mid0 << 1) | (side0 & 0x01);
mid1 = (mid1 << 1) | (side1 & 0x01);
mid2 = (mid2 << 1) | (side2 & 0x01);
@@ -87108,74 +89028,74 @@ static DRFLAC_INLINE void drflac_read_pcm_frames_f32__decode_mid_side__scalar(dr
temp1R = (mid1 - side1) << shift;
temp2R = (mid2 - side2) << shift;
temp3R = (mid3 - side3) << shift;
- pOutputSamples[i*8+0] = (drflac_int32)temp0L * factor;
- pOutputSamples[i*8+1] = (drflac_int32)temp0R * factor;
- pOutputSamples[i*8+2] = (drflac_int32)temp1L * factor;
- pOutputSamples[i*8+3] = (drflac_int32)temp1R * factor;
- pOutputSamples[i*8+4] = (drflac_int32)temp2L * factor;
- pOutputSamples[i*8+5] = (drflac_int32)temp2R * factor;
- pOutputSamples[i*8+6] = (drflac_int32)temp3L * factor;
- pOutputSamples[i*8+7] = (drflac_int32)temp3R * factor;
+ pOutputSamples[i*8+0] = (ma_int32)temp0L * factor;
+ pOutputSamples[i*8+1] = (ma_int32)temp0R * factor;
+ pOutputSamples[i*8+2] = (ma_int32)temp1L * factor;
+ pOutputSamples[i*8+3] = (ma_int32)temp1R * factor;
+ pOutputSamples[i*8+4] = (ma_int32)temp2L * factor;
+ pOutputSamples[i*8+5] = (ma_int32)temp2R * factor;
+ pOutputSamples[i*8+6] = (ma_int32)temp3L * factor;
+ pOutputSamples[i*8+7] = (ma_int32)temp3R * factor;
}
} else {
for (i = 0; i < frameCount4; ++i) {
- drflac_uint32 temp0L;
- drflac_uint32 temp1L;
- drflac_uint32 temp2L;
- drflac_uint32 temp3L;
- drflac_uint32 temp0R;
- drflac_uint32 temp1R;
- drflac_uint32 temp2R;
- drflac_uint32 temp3R;
- drflac_uint32 mid0 = pInputSamples0U32[i*4+0] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 mid1 = pInputSamples0U32[i*4+1] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 mid2 = pInputSamples0U32[i*4+2] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 mid3 = pInputSamples0U32[i*4+3] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 side0 = pInputSamples1U32[i*4+0] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
- drflac_uint32 side1 = pInputSamples1U32[i*4+1] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
- drflac_uint32 side2 = pInputSamples1U32[i*4+2] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
- drflac_uint32 side3 = pInputSamples1U32[i*4+3] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 temp0L;
+ ma_uint32 temp1L;
+ ma_uint32 temp2L;
+ ma_uint32 temp3L;
+ ma_uint32 temp0R;
+ ma_uint32 temp1R;
+ ma_uint32 temp2R;
+ ma_uint32 temp3R;
+ ma_uint32 mid0 = pInputSamples0U32[i*4+0] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 mid1 = pInputSamples0U32[i*4+1] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 mid2 = pInputSamples0U32[i*4+2] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 mid3 = pInputSamples0U32[i*4+3] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 side0 = pInputSamples1U32[i*4+0] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 side1 = pInputSamples1U32[i*4+1] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 side2 = pInputSamples1U32[i*4+2] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 side3 = pInputSamples1U32[i*4+3] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
mid0 = (mid0 << 1) | (side0 & 0x01);
mid1 = (mid1 << 1) | (side1 & 0x01);
mid2 = (mid2 << 1) | (side2 & 0x01);
mid3 = (mid3 << 1) | (side3 & 0x01);
- temp0L = (drflac_uint32)((drflac_int32)(mid0 + side0) >> 1);
- temp1L = (drflac_uint32)((drflac_int32)(mid1 + side1) >> 1);
- temp2L = (drflac_uint32)((drflac_int32)(mid2 + side2) >> 1);
- temp3L = (drflac_uint32)((drflac_int32)(mid3 + side3) >> 1);
- temp0R = (drflac_uint32)((drflac_int32)(mid0 - side0) >> 1);
- temp1R = (drflac_uint32)((drflac_int32)(mid1 - side1) >> 1);
- temp2R = (drflac_uint32)((drflac_int32)(mid2 - side2) >> 1);
- temp3R = (drflac_uint32)((drflac_int32)(mid3 - side3) >> 1);
- pOutputSamples[i*8+0] = (drflac_int32)temp0L * factor;
- pOutputSamples[i*8+1] = (drflac_int32)temp0R * factor;
- pOutputSamples[i*8+2] = (drflac_int32)temp1L * factor;
- pOutputSamples[i*8+3] = (drflac_int32)temp1R * factor;
- pOutputSamples[i*8+4] = (drflac_int32)temp2L * factor;
- pOutputSamples[i*8+5] = (drflac_int32)temp2R * factor;
- pOutputSamples[i*8+6] = (drflac_int32)temp3L * factor;
- pOutputSamples[i*8+7] = (drflac_int32)temp3R * factor;
+ temp0L = (ma_uint32)((ma_int32)(mid0 + side0) >> 1);
+ temp1L = (ma_uint32)((ma_int32)(mid1 + side1) >> 1);
+ temp2L = (ma_uint32)((ma_int32)(mid2 + side2) >> 1);
+ temp3L = (ma_uint32)((ma_int32)(mid3 + side3) >> 1);
+ temp0R = (ma_uint32)((ma_int32)(mid0 - side0) >> 1);
+ temp1R = (ma_uint32)((ma_int32)(mid1 - side1) >> 1);
+ temp2R = (ma_uint32)((ma_int32)(mid2 - side2) >> 1);
+ temp3R = (ma_uint32)((ma_int32)(mid3 - side3) >> 1);
+ pOutputSamples[i*8+0] = (ma_int32)temp0L * factor;
+ pOutputSamples[i*8+1] = (ma_int32)temp0R * factor;
+ pOutputSamples[i*8+2] = (ma_int32)temp1L * factor;
+ pOutputSamples[i*8+3] = (ma_int32)temp1R * factor;
+ pOutputSamples[i*8+4] = (ma_int32)temp2L * factor;
+ pOutputSamples[i*8+5] = (ma_int32)temp2R * factor;
+ pOutputSamples[i*8+6] = (ma_int32)temp3L * factor;
+ pOutputSamples[i*8+7] = (ma_int32)temp3R * factor;
}
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- drflac_uint32 mid = pInputSamples0U32[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 side = pInputSamples1U32[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 mid = pInputSamples0U32[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 side = pInputSamples1U32[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
mid = (mid << 1) | (side & 0x01);
- pOutputSamples[i*2+0] = (drflac_int32)((drflac_uint32)((drflac_int32)(mid + side) >> 1) << unusedBitsPerSample) * factor;
- pOutputSamples[i*2+1] = (drflac_int32)((drflac_uint32)((drflac_int32)(mid - side) >> 1) << unusedBitsPerSample) * factor;
+ pOutputSamples[i*2+0] = (ma_int32)((ma_uint32)((ma_int32)(mid + side) >> 1) << unusedBitsPerSample) * factor;
+ pOutputSamples[i*2+1] = (ma_int32)((ma_uint32)((ma_int32)(mid - side) >> 1) << unusedBitsPerSample) * factor;
}
}
-#if defined(DRFLAC_SUPPORT_SSE2)
-static DRFLAC_INLINE void drflac_read_pcm_frames_f32__decode_mid_side__sse2(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, float* pOutputSamples)
+#if defined(MA_DR_FLAC_SUPPORT_SSE2)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_f32__decode_mid_side__sse2(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, float* pOutputSamples)
{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_uint32 shift = unusedBitsPerSample - 8;
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_uint32 shift = unusedBitsPerSample - 8;
float factor;
__m128 factor128;
- DRFLAC_ASSERT(pFlac->bitsPerSample <= 24);
+ MA_DR_FLAC_ASSERT(pFlac->bitsPerSample <= 24);
factor = 1.0f / 8388608.0f;
factor128 = _mm_set1_ps(factor);
if (shift == 0) {
@@ -87197,11 +89117,11 @@ static DRFLAC_INLINE void drflac_read_pcm_frames_f32__decode_mid_side__sse2(drfl
_mm_storeu_ps(pOutputSamples + i*8 + 4, _mm_unpackhi_ps(leftf, rightf));
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- drflac_uint32 mid = pInputSamples0U32[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 side = pInputSamples1U32[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 mid = pInputSamples0U32[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 side = pInputSamples1U32[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
mid = (mid << 1) | (side & 0x01);
- pOutputSamples[i*2+0] = ((drflac_int32)(mid + side) >> 1) * factor;
- pOutputSamples[i*2+1] = ((drflac_int32)(mid - side) >> 1) * factor;
+ pOutputSamples[i*2+0] = ((ma_int32)(mid + side) >> 1) * factor;
+ pOutputSamples[i*2+1] = ((ma_int32)(mid - side) >> 1) * factor;
}
} else {
shift -= 1;
@@ -87223,29 +89143,29 @@ static DRFLAC_INLINE void drflac_read_pcm_frames_f32__decode_mid_side__sse2(drfl
_mm_storeu_ps(pOutputSamples + i*8 + 4, _mm_unpackhi_ps(leftf, rightf));
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- drflac_uint32 mid = pInputSamples0U32[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 side = pInputSamples1U32[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 mid = pInputSamples0U32[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 side = pInputSamples1U32[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
mid = (mid << 1) | (side & 0x01);
- pOutputSamples[i*2+0] = (drflac_int32)((mid + side) << shift) * factor;
- pOutputSamples[i*2+1] = (drflac_int32)((mid - side) << shift) * factor;
+ pOutputSamples[i*2+0] = (ma_int32)((mid + side) << shift) * factor;
+ pOutputSamples[i*2+1] = (ma_int32)((mid - side) << shift) * factor;
}
}
}
#endif
-#if defined(DRFLAC_SUPPORT_NEON)
-static DRFLAC_INLINE void drflac_read_pcm_frames_f32__decode_mid_side__neon(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, float* pOutputSamples)
+#if defined(MA_DR_FLAC_SUPPORT_NEON)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_f32__decode_mid_side__neon(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, float* pOutputSamples)
{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_uint32 shift = unusedBitsPerSample - 8;
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_uint32 shift = unusedBitsPerSample - 8;
float factor;
float32x4_t factor4;
int32x4_t shift4;
int32x4_t wbps0_4;
int32x4_t wbps1_4;
- DRFLAC_ASSERT(pFlac->bitsPerSample <= 24);
+ MA_DR_FLAC_ASSERT(pFlac->bitsPerSample <= 24);
factor = 1.0f / 8388608.0f;
factor4 = vdupq_n_f32(factor);
wbps0_4 = vdupq_n_s32(pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample);
@@ -87263,14 +89183,14 @@ static DRFLAC_INLINE void drflac_read_pcm_frames_f32__decode_mid_side__neon(drfl
righti = vshrq_n_s32(vreinterpretq_s32_u32(vsubq_u32(mid, side)), 1);
leftf = vmulq_f32(vcvtq_f32_s32(lefti), factor4);
rightf = vmulq_f32(vcvtq_f32_s32(righti), factor4);
- drflac__vst2q_f32(pOutputSamples + i*8, vzipq_f32(leftf, rightf));
+ ma_dr_flac__vst2q_f32(pOutputSamples + i*8, vzipq_f32(leftf, rightf));
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- drflac_uint32 mid = pInputSamples0U32[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 side = pInputSamples1U32[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 mid = pInputSamples0U32[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 side = pInputSamples1U32[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
mid = (mid << 1) | (side & 0x01);
- pOutputSamples[i*2+0] = ((drflac_int32)(mid + side) >> 1) * factor;
- pOutputSamples[i*2+1] = ((drflac_int32)(mid - side) >> 1) * factor;
+ pOutputSamples[i*2+0] = ((ma_int32)(mid + side) >> 1) * factor;
+ pOutputSamples[i*2+1] = ((ma_int32)(mid - side) >> 1) * factor;
}
} else {
shift -= 1;
@@ -87289,87 +89209,87 @@ static DRFLAC_INLINE void drflac_read_pcm_frames_f32__decode_mid_side__neon(drfl
righti = vreinterpretq_s32_u32(vshlq_u32(vsubq_u32(mid, side), shift4));
leftf = vmulq_f32(vcvtq_f32_s32(lefti), factor4);
rightf = vmulq_f32(vcvtq_f32_s32(righti), factor4);
- drflac__vst2q_f32(pOutputSamples + i*8, vzipq_f32(leftf, rightf));
+ ma_dr_flac__vst2q_f32(pOutputSamples + i*8, vzipq_f32(leftf, rightf));
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- drflac_uint32 mid = pInputSamples0U32[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 side = pInputSamples1U32[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint32 mid = pInputSamples0U32[i] << pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 side = pInputSamples1U32[i] << pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
mid = (mid << 1) | (side & 0x01);
- pOutputSamples[i*2+0] = (drflac_int32)((mid + side) << shift) * factor;
- pOutputSamples[i*2+1] = (drflac_int32)((mid - side) << shift) * factor;
+ pOutputSamples[i*2+0] = (ma_int32)((mid + side) << shift) * factor;
+ pOutputSamples[i*2+1] = (ma_int32)((mid - side) << shift) * factor;
}
}
}
#endif
-static DRFLAC_INLINE void drflac_read_pcm_frames_f32__decode_mid_side(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, float* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_f32__decode_mid_side(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, float* pOutputSamples)
{
-#if defined(DRFLAC_SUPPORT_SSE2)
- if (drflac__gIsSSE2Supported && pFlac->bitsPerSample <= 24) {
- drflac_read_pcm_frames_f32__decode_mid_side__sse2(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+#if defined(MA_DR_FLAC_SUPPORT_SSE2)
+ if (ma_dr_flac__gIsSSE2Supported && pFlac->bitsPerSample <= 24) {
+ ma_dr_flac_read_pcm_frames_f32__decode_mid_side__sse2(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
} else
-#elif defined(DRFLAC_SUPPORT_NEON)
- if (drflac__gIsNEONSupported && pFlac->bitsPerSample <= 24) {
- drflac_read_pcm_frames_f32__decode_mid_side__neon(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+#elif defined(MA_DR_FLAC_SUPPORT_NEON)
+ if (ma_dr_flac__gIsNEONSupported && pFlac->bitsPerSample <= 24) {
+ ma_dr_flac_read_pcm_frames_f32__decode_mid_side__neon(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
} else
#endif
{
#if 0
- drflac_read_pcm_frames_f32__decode_mid_side__reference(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+ ma_dr_flac_read_pcm_frames_f32__decode_mid_side__reference(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
#else
- drflac_read_pcm_frames_f32__decode_mid_side__scalar(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+ ma_dr_flac_read_pcm_frames_f32__decode_mid_side__scalar(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
#endif
}
}
#if 0
-static DRFLAC_INLINE void drflac_read_pcm_frames_f32__decode_independent_stereo__reference(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, float* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_f32__decode_independent_stereo__reference(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, float* pOutputSamples)
{
- for (drflac_uint64 i = 0; i < frameCount; ++i) {
- pOutputSamples[i*2+0] = (float)((drflac_int32)((drflac_uint32)pInputSamples0[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample)) / 2147483648.0);
- pOutputSamples[i*2+1] = (float)((drflac_int32)((drflac_uint32)pInputSamples1[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample)) / 2147483648.0);
+ for (ma_uint64 i = 0; i < frameCount; ++i) {
+ pOutputSamples[i*2+0] = (float)((ma_int32)((ma_uint32)pInputSamples0[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample)) / 2147483648.0);
+ pOutputSamples[i*2+1] = (float)((ma_int32)((ma_uint32)pInputSamples1[i] << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample)) / 2147483648.0);
}
}
#endif
-static DRFLAC_INLINE void drflac_read_pcm_frames_f32__decode_independent_stereo__scalar(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, float* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_f32__decode_independent_stereo__scalar(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, float* pOutputSamples)
{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
- drflac_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_uint32 shift0 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample;
+ ma_uint32 shift1 = unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample;
float factor = 1 / 2147483648.0;
for (i = 0; i < frameCount4; ++i) {
- drflac_uint32 tempL0 = pInputSamples0U32[i*4+0] << shift0;
- drflac_uint32 tempL1 = pInputSamples0U32[i*4+1] << shift0;
- drflac_uint32 tempL2 = pInputSamples0U32[i*4+2] << shift0;
- drflac_uint32 tempL3 = pInputSamples0U32[i*4+3] << shift0;
- drflac_uint32 tempR0 = pInputSamples1U32[i*4+0] << shift1;
- drflac_uint32 tempR1 = pInputSamples1U32[i*4+1] << shift1;
- drflac_uint32 tempR2 = pInputSamples1U32[i*4+2] << shift1;
- drflac_uint32 tempR3 = pInputSamples1U32[i*4+3] << shift1;
- pOutputSamples[i*8+0] = (drflac_int32)tempL0 * factor;
- pOutputSamples[i*8+1] = (drflac_int32)tempR0 * factor;
- pOutputSamples[i*8+2] = (drflac_int32)tempL1 * factor;
- pOutputSamples[i*8+3] = (drflac_int32)tempR1 * factor;
- pOutputSamples[i*8+4] = (drflac_int32)tempL2 * factor;
- pOutputSamples[i*8+5] = (drflac_int32)tempR2 * factor;
- pOutputSamples[i*8+6] = (drflac_int32)tempL3 * factor;
- pOutputSamples[i*8+7] = (drflac_int32)tempR3 * factor;
+ ma_uint32 tempL0 = pInputSamples0U32[i*4+0] << shift0;
+ ma_uint32 tempL1 = pInputSamples0U32[i*4+1] << shift0;
+ ma_uint32 tempL2 = pInputSamples0U32[i*4+2] << shift0;
+ ma_uint32 tempL3 = pInputSamples0U32[i*4+3] << shift0;
+ ma_uint32 tempR0 = pInputSamples1U32[i*4+0] << shift1;
+ ma_uint32 tempR1 = pInputSamples1U32[i*4+1] << shift1;
+ ma_uint32 tempR2 = pInputSamples1U32[i*4+2] << shift1;
+ ma_uint32 tempR3 = pInputSamples1U32[i*4+3] << shift1;
+ pOutputSamples[i*8+0] = (ma_int32)tempL0 * factor;
+ pOutputSamples[i*8+1] = (ma_int32)tempR0 * factor;
+ pOutputSamples[i*8+2] = (ma_int32)tempL1 * factor;
+ pOutputSamples[i*8+3] = (ma_int32)tempR1 * factor;
+ pOutputSamples[i*8+4] = (ma_int32)tempL2 * factor;
+ pOutputSamples[i*8+5] = (ma_int32)tempR2 * factor;
+ pOutputSamples[i*8+6] = (ma_int32)tempL3 * factor;
+ pOutputSamples[i*8+7] = (ma_int32)tempR3 * factor;
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- pOutputSamples[i*2+0] = (drflac_int32)(pInputSamples0U32[i] << shift0) * factor;
- pOutputSamples[i*2+1] = (drflac_int32)(pInputSamples1U32[i] << shift1) * factor;
+ pOutputSamples[i*2+0] = (ma_int32)(pInputSamples0U32[i] << shift0) * factor;
+ pOutputSamples[i*2+1] = (ma_int32)(pInputSamples1U32[i] << shift1) * factor;
}
}
-#if defined(DRFLAC_SUPPORT_SSE2)
-static DRFLAC_INLINE void drflac_read_pcm_frames_f32__decode_independent_stereo__sse2(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, float* pOutputSamples)
+#if defined(MA_DR_FLAC_SUPPORT_SSE2)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_f32__decode_independent_stereo__sse2(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, float* pOutputSamples)
{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_uint32 shift0 = (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample) - 8;
- drflac_uint32 shift1 = (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample) - 8;
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_uint32 shift0 = (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample) - 8;
+ ma_uint32 shift1 = (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample) - 8;
float factor = 1.0f / 8388608.0f;
__m128 factor128 = _mm_set1_ps(factor);
for (i = 0; i < frameCount4; ++i) {
@@ -87385,20 +89305,20 @@ static DRFLAC_INLINE void drflac_read_pcm_frames_f32__decode_independent_stereo_
_mm_storeu_ps(pOutputSamples + i*8 + 4, _mm_unpackhi_ps(leftf, rightf));
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- pOutputSamples[i*2+0] = (drflac_int32)(pInputSamples0U32[i] << shift0) * factor;
- pOutputSamples[i*2+1] = (drflac_int32)(pInputSamples1U32[i] << shift1) * factor;
+ pOutputSamples[i*2+0] = (ma_int32)(pInputSamples0U32[i] << shift0) * factor;
+ pOutputSamples[i*2+1] = (ma_int32)(pInputSamples1U32[i] << shift1) * factor;
}
}
#endif
-#if defined(DRFLAC_SUPPORT_NEON)
-static DRFLAC_INLINE void drflac_read_pcm_frames_f32__decode_independent_stereo__neon(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, float* pOutputSamples)
+#if defined(MA_DR_FLAC_SUPPORT_NEON)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_f32__decode_independent_stereo__neon(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, float* pOutputSamples)
{
- drflac_uint64 i;
- drflac_uint64 frameCount4 = frameCount >> 2;
- const drflac_uint32* pInputSamples0U32 = (const drflac_uint32*)pInputSamples0;
- const drflac_uint32* pInputSamples1U32 = (const drflac_uint32*)pInputSamples1;
- drflac_uint32 shift0 = (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample) - 8;
- drflac_uint32 shift1 = (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample) - 8;
+ ma_uint64 i;
+ ma_uint64 frameCount4 = frameCount >> 2;
+ const ma_uint32* pInputSamples0U32 = (const ma_uint32*)pInputSamples0;
+ const ma_uint32* pInputSamples1U32 = (const ma_uint32*)pInputSamples1;
+ ma_uint32 shift0 = (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[0].wastedBitsPerSample) - 8;
+ ma_uint32 shift1 = (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[1].wastedBitsPerSample) - 8;
float factor = 1.0f / 8388608.0f;
float32x4_t factor4 = vdupq_n_f32(factor);
int32x4_t shift0_4 = vdupq_n_s32(shift0);
@@ -87412,87 +89332,87 @@ static DRFLAC_INLINE void drflac_read_pcm_frames_f32__decode_independent_stereo_
righti = vreinterpretq_s32_u32(vshlq_u32(vld1q_u32(pInputSamples1U32 + i*4), shift1_4));
leftf = vmulq_f32(vcvtq_f32_s32(lefti), factor4);
rightf = vmulq_f32(vcvtq_f32_s32(righti), factor4);
- drflac__vst2q_f32(pOutputSamples + i*8, vzipq_f32(leftf, rightf));
+ ma_dr_flac__vst2q_f32(pOutputSamples + i*8, vzipq_f32(leftf, rightf));
}
for (i = (frameCount4 << 2); i < frameCount; ++i) {
- pOutputSamples[i*2+0] = (drflac_int32)(pInputSamples0U32[i] << shift0) * factor;
- pOutputSamples[i*2+1] = (drflac_int32)(pInputSamples1U32[i] << shift1) * factor;
+ pOutputSamples[i*2+0] = (ma_int32)(pInputSamples0U32[i] << shift0) * factor;
+ pOutputSamples[i*2+1] = (ma_int32)(pInputSamples1U32[i] << shift1) * factor;
}
}
#endif
-static DRFLAC_INLINE void drflac_read_pcm_frames_f32__decode_independent_stereo(drflac* pFlac, drflac_uint64 frameCount, drflac_uint32 unusedBitsPerSample, const drflac_int32* pInputSamples0, const drflac_int32* pInputSamples1, float* pOutputSamples)
+static MA_INLINE void ma_dr_flac_read_pcm_frames_f32__decode_independent_stereo(ma_dr_flac* pFlac, ma_uint64 frameCount, ma_uint32 unusedBitsPerSample, const ma_int32* pInputSamples0, const ma_int32* pInputSamples1, float* pOutputSamples)
{
-#if defined(DRFLAC_SUPPORT_SSE2)
- if (drflac__gIsSSE2Supported && pFlac->bitsPerSample <= 24) {
- drflac_read_pcm_frames_f32__decode_independent_stereo__sse2(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+#if defined(MA_DR_FLAC_SUPPORT_SSE2)
+ if (ma_dr_flac__gIsSSE2Supported && pFlac->bitsPerSample <= 24) {
+ ma_dr_flac_read_pcm_frames_f32__decode_independent_stereo__sse2(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
} else
-#elif defined(DRFLAC_SUPPORT_NEON)
- if (drflac__gIsNEONSupported && pFlac->bitsPerSample <= 24) {
- drflac_read_pcm_frames_f32__decode_independent_stereo__neon(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+#elif defined(MA_DR_FLAC_SUPPORT_NEON)
+ if (ma_dr_flac__gIsNEONSupported && pFlac->bitsPerSample <= 24) {
+ ma_dr_flac_read_pcm_frames_f32__decode_independent_stereo__neon(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
} else
#endif
{
#if 0
- drflac_read_pcm_frames_f32__decode_independent_stereo__reference(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+ ma_dr_flac_read_pcm_frames_f32__decode_independent_stereo__reference(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
#else
- drflac_read_pcm_frames_f32__decode_independent_stereo__scalar(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
+ ma_dr_flac_read_pcm_frames_f32__decode_independent_stereo__scalar(pFlac, frameCount, unusedBitsPerSample, pInputSamples0, pInputSamples1, pOutputSamples);
#endif
}
}
-DRFLAC_API drflac_uint64 drflac_read_pcm_frames_f32(drflac* pFlac, drflac_uint64 framesToRead, float* pBufferOut)
+MA_API ma_uint64 ma_dr_flac_read_pcm_frames_f32(ma_dr_flac* pFlac, ma_uint64 framesToRead, float* pBufferOut)
{
- drflac_uint64 framesRead;
- drflac_uint32 unusedBitsPerSample;
+ ma_uint64 framesRead;
+ ma_uint32 unusedBitsPerSample;
if (pFlac == NULL || framesToRead == 0) {
return 0;
}
if (pBufferOut == NULL) {
- return drflac__seek_forward_by_pcm_frames(pFlac, framesToRead);
+ return ma_dr_flac__seek_forward_by_pcm_frames(pFlac, framesToRead);
}
- DRFLAC_ASSERT(pFlac->bitsPerSample <= 32);
+ MA_DR_FLAC_ASSERT(pFlac->bitsPerSample <= 32);
unusedBitsPerSample = 32 - pFlac->bitsPerSample;
framesRead = 0;
while (framesToRead > 0) {
if (pFlac->currentFLACFrame.pcmFramesRemaining == 0) {
- if (!drflac__read_and_decode_next_flac_frame(pFlac)) {
+ if (!ma_dr_flac__read_and_decode_next_flac_frame(pFlac)) {
break;
}
} else {
- unsigned int channelCount = drflac__get_channel_count_from_channel_assignment(pFlac->currentFLACFrame.header.channelAssignment);
- drflac_uint64 iFirstPCMFrame = pFlac->currentFLACFrame.header.blockSizeInPCMFrames - pFlac->currentFLACFrame.pcmFramesRemaining;
- drflac_uint64 frameCountThisIteration = framesToRead;
+ unsigned int channelCount = ma_dr_flac__get_channel_count_from_channel_assignment(pFlac->currentFLACFrame.header.channelAssignment);
+ ma_uint64 iFirstPCMFrame = pFlac->currentFLACFrame.header.blockSizeInPCMFrames - pFlac->currentFLACFrame.pcmFramesRemaining;
+ ma_uint64 frameCountThisIteration = framesToRead;
if (frameCountThisIteration > pFlac->currentFLACFrame.pcmFramesRemaining) {
frameCountThisIteration = pFlac->currentFLACFrame.pcmFramesRemaining;
}
if (channelCount == 2) {
- const drflac_int32* pDecodedSamples0 = pFlac->currentFLACFrame.subframes[0].pSamplesS32 + iFirstPCMFrame;
- const drflac_int32* pDecodedSamples1 = pFlac->currentFLACFrame.subframes[1].pSamplesS32 + iFirstPCMFrame;
+ const ma_int32* pDecodedSamples0 = pFlac->currentFLACFrame.subframes[0].pSamplesS32 + iFirstPCMFrame;
+ const ma_int32* pDecodedSamples1 = pFlac->currentFLACFrame.subframes[1].pSamplesS32 + iFirstPCMFrame;
switch (pFlac->currentFLACFrame.header.channelAssignment)
{
- case DRFLAC_CHANNEL_ASSIGNMENT_LEFT_SIDE:
+ case MA_DR_FLAC_CHANNEL_ASSIGNMENT_LEFT_SIDE:
{
- drflac_read_pcm_frames_f32__decode_left_side(pFlac, frameCountThisIteration, unusedBitsPerSample, pDecodedSamples0, pDecodedSamples1, pBufferOut);
+ ma_dr_flac_read_pcm_frames_f32__decode_left_side(pFlac, frameCountThisIteration, unusedBitsPerSample, pDecodedSamples0, pDecodedSamples1, pBufferOut);
} break;
- case DRFLAC_CHANNEL_ASSIGNMENT_RIGHT_SIDE:
+ case MA_DR_FLAC_CHANNEL_ASSIGNMENT_RIGHT_SIDE:
{
- drflac_read_pcm_frames_f32__decode_right_side(pFlac, frameCountThisIteration, unusedBitsPerSample, pDecodedSamples0, pDecodedSamples1, pBufferOut);
+ ma_dr_flac_read_pcm_frames_f32__decode_right_side(pFlac, frameCountThisIteration, unusedBitsPerSample, pDecodedSamples0, pDecodedSamples1, pBufferOut);
} break;
- case DRFLAC_CHANNEL_ASSIGNMENT_MID_SIDE:
+ case MA_DR_FLAC_CHANNEL_ASSIGNMENT_MID_SIDE:
{
- drflac_read_pcm_frames_f32__decode_mid_side(pFlac, frameCountThisIteration, unusedBitsPerSample, pDecodedSamples0, pDecodedSamples1, pBufferOut);
+ ma_dr_flac_read_pcm_frames_f32__decode_mid_side(pFlac, frameCountThisIteration, unusedBitsPerSample, pDecodedSamples0, pDecodedSamples1, pBufferOut);
} break;
- case DRFLAC_CHANNEL_ASSIGNMENT_INDEPENDENT:
+ case MA_DR_FLAC_CHANNEL_ASSIGNMENT_INDEPENDENT:
default:
{
- drflac_read_pcm_frames_f32__decode_independent_stereo(pFlac, frameCountThisIteration, unusedBitsPerSample, pDecodedSamples0, pDecodedSamples1, pBufferOut);
+ ma_dr_flac_read_pcm_frames_f32__decode_independent_stereo(pFlac, frameCountThisIteration, unusedBitsPerSample, pDecodedSamples0, pDecodedSamples1, pBufferOut);
} break;
}
} else {
- drflac_uint64 i;
+ ma_uint64 i;
for (i = 0; i < frameCountThisIteration; ++i) {
unsigned int j;
for (j = 0; j < channelCount; ++j) {
- drflac_int32 sampleS32 = (drflac_int32)((drflac_uint32)(pFlac->currentFLACFrame.subframes[j].pSamplesS32[iFirstPCMFrame + i]) << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[j].wastedBitsPerSample));
+ ma_int32 sampleS32 = (ma_int32)((ma_uint32)(pFlac->currentFLACFrame.subframes[j].pSamplesS32[iFirstPCMFrame + i]) << (unusedBitsPerSample + pFlac->currentFLACFrame.subframes[j].wastedBitsPerSample));
pBufferOut[(i*channelCount)+j] = (float)(sampleS32 / 2147483648.0);
}
}
@@ -87506,111 +89426,102 @@ DRFLAC_API drflac_uint64 drflac_read_pcm_frames_f32(drflac* pFlac, drflac_uint64
}
return framesRead;
}
-DRFLAC_API drflac_bool32 drflac_seek_to_pcm_frame(drflac* pFlac, drflac_uint64 pcmFrameIndex)
+MA_API ma_bool32 ma_dr_flac_seek_to_pcm_frame(ma_dr_flac* pFlac, ma_uint64 pcmFrameIndex)
{
if (pFlac == NULL) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
if (pFlac->currentPCMFrame == pcmFrameIndex) {
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
if (pFlac->firstFLACFramePosInBytes == 0) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
if (pcmFrameIndex == 0) {
pFlac->currentPCMFrame = 0;
- return drflac__seek_to_first_frame(pFlac);
+ return ma_dr_flac__seek_to_first_frame(pFlac);
} else {
- drflac_bool32 wasSuccessful = DRFLAC_FALSE;
- drflac_uint64 originalPCMFrame = pFlac->currentPCMFrame;
+ ma_bool32 wasSuccessful = MA_FALSE;
+ ma_uint64 originalPCMFrame = pFlac->currentPCMFrame;
if (pcmFrameIndex > pFlac->totalPCMFrameCount) {
pcmFrameIndex = pFlac->totalPCMFrameCount;
}
if (pcmFrameIndex > pFlac->currentPCMFrame) {
- drflac_uint32 offset = (drflac_uint32)(pcmFrameIndex - pFlac->currentPCMFrame);
+ ma_uint32 offset = (ma_uint32)(pcmFrameIndex - pFlac->currentPCMFrame);
if (pFlac->currentFLACFrame.pcmFramesRemaining > offset) {
pFlac->currentFLACFrame.pcmFramesRemaining -= offset;
pFlac->currentPCMFrame = pcmFrameIndex;
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
} else {
- drflac_uint32 offsetAbs = (drflac_uint32)(pFlac->currentPCMFrame - pcmFrameIndex);
- drflac_uint32 currentFLACFramePCMFrameCount = pFlac->currentFLACFrame.header.blockSizeInPCMFrames;
- drflac_uint32 currentFLACFramePCMFramesConsumed = currentFLACFramePCMFrameCount - pFlac->currentFLACFrame.pcmFramesRemaining;
+ ma_uint32 offsetAbs = (ma_uint32)(pFlac->currentPCMFrame - pcmFrameIndex);
+ ma_uint32 currentFLACFramePCMFrameCount = pFlac->currentFLACFrame.header.blockSizeInPCMFrames;
+ ma_uint32 currentFLACFramePCMFramesConsumed = currentFLACFramePCMFrameCount - pFlac->currentFLACFrame.pcmFramesRemaining;
if (currentFLACFramePCMFramesConsumed > offsetAbs) {
pFlac->currentFLACFrame.pcmFramesRemaining += offsetAbs;
pFlac->currentPCMFrame = pcmFrameIndex;
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
}
-#ifndef DR_FLAC_NO_OGG
- if (pFlac->container == drflac_container_ogg)
+#ifndef MA_DR_FLAC_NO_OGG
+ if (pFlac->container == ma_dr_flac_container_ogg)
{
- wasSuccessful = drflac_ogg__seek_to_pcm_frame(pFlac, pcmFrameIndex);
+ wasSuccessful = ma_dr_flac_ogg__seek_to_pcm_frame(pFlac, pcmFrameIndex);
}
else
#endif
{
if (!pFlac->_noSeekTableSeek) {
- wasSuccessful = drflac__seek_to_pcm_frame__seek_table(pFlac, pcmFrameIndex);
+ wasSuccessful = ma_dr_flac__seek_to_pcm_frame__seek_table(pFlac, pcmFrameIndex);
}
-#if !defined(DR_FLAC_NO_CRC)
+#if !defined(MA_DR_FLAC_NO_CRC)
if (!wasSuccessful && !pFlac->_noBinarySearchSeek && pFlac->totalPCMFrameCount > 0) {
- wasSuccessful = drflac__seek_to_pcm_frame__binary_search(pFlac, pcmFrameIndex);
+ wasSuccessful = ma_dr_flac__seek_to_pcm_frame__binary_search(pFlac, pcmFrameIndex);
}
#endif
if (!wasSuccessful && !pFlac->_noBruteForceSeek) {
- wasSuccessful = drflac__seek_to_pcm_frame__brute_force(pFlac, pcmFrameIndex);
+ wasSuccessful = ma_dr_flac__seek_to_pcm_frame__brute_force(pFlac, pcmFrameIndex);
}
}
if (wasSuccessful) {
pFlac->currentPCMFrame = pcmFrameIndex;
} else {
- if (drflac_seek_to_pcm_frame(pFlac, originalPCMFrame) == DRFLAC_FALSE) {
- drflac_seek_to_pcm_frame(pFlac, 0);
+ if (ma_dr_flac_seek_to_pcm_frame(pFlac, originalPCMFrame) == MA_FALSE) {
+ ma_dr_flac_seek_to_pcm_frame(pFlac, 0);
}
}
return wasSuccessful;
}
}
-#if defined(SIZE_MAX)
- #define DRFLAC_SIZE_MAX SIZE_MAX
-#else
- #if defined(DRFLAC_64BIT)
- #define DRFLAC_SIZE_MAX ((drflac_uint64)0xFFFFFFFFFFFFFFFF)
- #else
- #define DRFLAC_SIZE_MAX 0xFFFFFFFF
- #endif
-#endif
-#define DRFLAC_DEFINE_FULL_READ_AND_CLOSE(extension, type) \
-static type* drflac__full_read_and_close_ ## extension (drflac* pFlac, unsigned int* channelsOut, unsigned int* sampleRateOut, drflac_uint64* totalPCMFrameCountOut)\
+#define MA_DR_FLAC_DEFINE_FULL_READ_AND_CLOSE(extension, type) \
+static type* ma_dr_flac__full_read_and_close_ ## extension (ma_dr_flac* pFlac, unsigned int* channelsOut, unsigned int* sampleRateOut, ma_uint64* totalPCMFrameCountOut)\
{ \
type* pSampleData = NULL; \
- drflac_uint64 totalPCMFrameCount; \
+ ma_uint64 totalPCMFrameCount; \
\
- DRFLAC_ASSERT(pFlac != NULL); \
+ MA_DR_FLAC_ASSERT(pFlac != NULL); \
\
totalPCMFrameCount = pFlac->totalPCMFrameCount; \
\
if (totalPCMFrameCount == 0) { \
type buffer[4096]; \
- drflac_uint64 pcmFramesRead; \
+ ma_uint64 pcmFramesRead; \
size_t sampleDataBufferSize = sizeof(buffer); \
\
- pSampleData = (type*)drflac__malloc_from_callbacks(sampleDataBufferSize, &pFlac->allocationCallbacks); \
+ pSampleData = (type*)ma_dr_flac__malloc_from_callbacks(sampleDataBufferSize, &pFlac->allocationCallbacks); \
if (pSampleData == NULL) { \
goto on_error; \
} \
\
- while ((pcmFramesRead = (drflac_uint64)drflac_read_pcm_frames_##extension(pFlac, sizeof(buffer)/sizeof(buffer[0])/pFlac->channels, buffer)) > 0) { \
+ while ((pcmFramesRead = (ma_uint64)ma_dr_flac_read_pcm_frames_##extension(pFlac, sizeof(buffer)/sizeof(buffer[0])/pFlac->channels, buffer)) > 0) { \
if (((totalPCMFrameCount + pcmFramesRead) * pFlac->channels * sizeof(type)) > sampleDataBufferSize) { \
type* pNewSampleData; \
size_t newSampleDataBufferSize; \
\
newSampleDataBufferSize = sampleDataBufferSize * 2; \
- pNewSampleData = (type*)drflac__realloc_from_callbacks(pSampleData, newSampleDataBufferSize, sampleDataBufferSize, &pFlac->allocationCallbacks); \
+ pNewSampleData = (type*)ma_dr_flac__realloc_from_callbacks(pSampleData, newSampleDataBufferSize, sampleDataBufferSize, &pFlac->allocationCallbacks); \
if (pNewSampleData == NULL) { \
- drflac__free_from_callbacks(pSampleData, &pFlac->allocationCallbacks); \
+ ma_dr_flac__free_from_callbacks(pSampleData, &pFlac->allocationCallbacks); \
goto on_error; \
} \
\
@@ -87618,43 +89529,43 @@ static type* drflac__full_read_and_close_ ## extension (drflac* pFlac, unsigned
pSampleData = pNewSampleData; \
} \
\
- DRFLAC_COPY_MEMORY(pSampleData + (totalPCMFrameCount*pFlac->channels), buffer, (size_t)(pcmFramesRead*pFlac->channels*sizeof(type))); \
+ MA_DR_FLAC_COPY_MEMORY(pSampleData + (totalPCMFrameCount*pFlac->channels), buffer, (size_t)(pcmFramesRead*pFlac->channels*sizeof(type))); \
totalPCMFrameCount += pcmFramesRead; \
} \
\
\
- DRFLAC_ZERO_MEMORY(pSampleData + (totalPCMFrameCount*pFlac->channels), (size_t)(sampleDataBufferSize - totalPCMFrameCount*pFlac->channels*sizeof(type))); \
+ MA_DR_FLAC_ZERO_MEMORY(pSampleData + (totalPCMFrameCount*pFlac->channels), (size_t)(sampleDataBufferSize - totalPCMFrameCount*pFlac->channels*sizeof(type))); \
} else { \
- drflac_uint64 dataSize = totalPCMFrameCount*pFlac->channels*sizeof(type); \
- if (dataSize > (drflac_uint64)DRFLAC_SIZE_MAX) { \
+ ma_uint64 dataSize = totalPCMFrameCount*pFlac->channels*sizeof(type); \
+ if (dataSize > (ma_uint64)MA_SIZE_MAX) { \
goto on_error; \
} \
\
- pSampleData = (type*)drflac__malloc_from_callbacks((size_t)dataSize, &pFlac->allocationCallbacks); \
+ pSampleData = (type*)ma_dr_flac__malloc_from_callbacks((size_t)dataSize, &pFlac->allocationCallbacks); \
if (pSampleData == NULL) { \
goto on_error; \
} \
\
- totalPCMFrameCount = drflac_read_pcm_frames_##extension(pFlac, pFlac->totalPCMFrameCount, pSampleData); \
+ totalPCMFrameCount = ma_dr_flac_read_pcm_frames_##extension(pFlac, pFlac->totalPCMFrameCount, pSampleData); \
} \
\
if (sampleRateOut) *sampleRateOut = pFlac->sampleRate; \
if (channelsOut) *channelsOut = pFlac->channels; \
if (totalPCMFrameCountOut) *totalPCMFrameCountOut = totalPCMFrameCount; \
\
- drflac_close(pFlac); \
+ ma_dr_flac_close(pFlac); \
return pSampleData; \
\
on_error: \
- drflac_close(pFlac); \
+ ma_dr_flac_close(pFlac); \
return NULL; \
}
-DRFLAC_DEFINE_FULL_READ_AND_CLOSE(s32, drflac_int32)
-DRFLAC_DEFINE_FULL_READ_AND_CLOSE(s16, drflac_int16)
-DRFLAC_DEFINE_FULL_READ_AND_CLOSE(f32, float)
-DRFLAC_API drflac_int32* drflac_open_and_read_pcm_frames_s32(drflac_read_proc onRead, drflac_seek_proc onSeek, void* pUserData, unsigned int* channelsOut, unsigned int* sampleRateOut, drflac_uint64* totalPCMFrameCountOut, const drflac_allocation_callbacks* pAllocationCallbacks)
+MA_DR_FLAC_DEFINE_FULL_READ_AND_CLOSE(s32, ma_int32)
+MA_DR_FLAC_DEFINE_FULL_READ_AND_CLOSE(s16, ma_int16)
+MA_DR_FLAC_DEFINE_FULL_READ_AND_CLOSE(f32, float)
+MA_API ma_int32* ma_dr_flac_open_and_read_pcm_frames_s32(ma_dr_flac_read_proc onRead, ma_dr_flac_seek_proc onSeek, void* pUserData, unsigned int* channelsOut, unsigned int* sampleRateOut, ma_uint64* totalPCMFrameCountOut, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drflac* pFlac;
+ ma_dr_flac* pFlac;
if (channelsOut) {
*channelsOut = 0;
}
@@ -87664,15 +89575,15 @@ DRFLAC_API drflac_int32* drflac_open_and_read_pcm_frames_s32(drflac_read_proc on
if (totalPCMFrameCountOut) {
*totalPCMFrameCountOut = 0;
}
- pFlac = drflac_open(onRead, onSeek, pUserData, pAllocationCallbacks);
+ pFlac = ma_dr_flac_open(onRead, onSeek, pUserData, pAllocationCallbacks);
if (pFlac == NULL) {
return NULL;
}
- return drflac__full_read_and_close_s32(pFlac, channelsOut, sampleRateOut, totalPCMFrameCountOut);
+ return ma_dr_flac__full_read_and_close_s32(pFlac, channelsOut, sampleRateOut, totalPCMFrameCountOut);
}
-DRFLAC_API drflac_int16* drflac_open_and_read_pcm_frames_s16(drflac_read_proc onRead, drflac_seek_proc onSeek, void* pUserData, unsigned int* channelsOut, unsigned int* sampleRateOut, drflac_uint64* totalPCMFrameCountOut, const drflac_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_int16* ma_dr_flac_open_and_read_pcm_frames_s16(ma_dr_flac_read_proc onRead, ma_dr_flac_seek_proc onSeek, void* pUserData, unsigned int* channelsOut, unsigned int* sampleRateOut, ma_uint64* totalPCMFrameCountOut, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drflac* pFlac;
+ ma_dr_flac* pFlac;
if (channelsOut) {
*channelsOut = 0;
}
@@ -87682,15 +89593,15 @@ DRFLAC_API drflac_int16* drflac_open_and_read_pcm_frames_s16(drflac_read_proc on
if (totalPCMFrameCountOut) {
*totalPCMFrameCountOut = 0;
}
- pFlac = drflac_open(onRead, onSeek, pUserData, pAllocationCallbacks);
+ pFlac = ma_dr_flac_open(onRead, onSeek, pUserData, pAllocationCallbacks);
if (pFlac == NULL) {
return NULL;
}
- return drflac__full_read_and_close_s16(pFlac, channelsOut, sampleRateOut, totalPCMFrameCountOut);
+ return ma_dr_flac__full_read_and_close_s16(pFlac, channelsOut, sampleRateOut, totalPCMFrameCountOut);
}
-DRFLAC_API float* drflac_open_and_read_pcm_frames_f32(drflac_read_proc onRead, drflac_seek_proc onSeek, void* pUserData, unsigned int* channelsOut, unsigned int* sampleRateOut, drflac_uint64* totalPCMFrameCountOut, const drflac_allocation_callbacks* pAllocationCallbacks)
+MA_API float* ma_dr_flac_open_and_read_pcm_frames_f32(ma_dr_flac_read_proc onRead, ma_dr_flac_seek_proc onSeek, void* pUserData, unsigned int* channelsOut, unsigned int* sampleRateOut, ma_uint64* totalPCMFrameCountOut, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drflac* pFlac;
+ ma_dr_flac* pFlac;
if (channelsOut) {
*channelsOut = 0;
}
@@ -87700,16 +89611,16 @@ DRFLAC_API float* drflac_open_and_read_pcm_frames_f32(drflac_read_proc onRead, d
if (totalPCMFrameCountOut) {
*totalPCMFrameCountOut = 0;
}
- pFlac = drflac_open(onRead, onSeek, pUserData, pAllocationCallbacks);
+ pFlac = ma_dr_flac_open(onRead, onSeek, pUserData, pAllocationCallbacks);
if (pFlac == NULL) {
return NULL;
}
- return drflac__full_read_and_close_f32(pFlac, channelsOut, sampleRateOut, totalPCMFrameCountOut);
+ return ma_dr_flac__full_read_and_close_f32(pFlac, channelsOut, sampleRateOut, totalPCMFrameCountOut);
}
-#ifndef DR_FLAC_NO_STDIO
-DRFLAC_API drflac_int32* drflac_open_file_and_read_pcm_frames_s32(const char* filename, unsigned int* channels, unsigned int* sampleRate, drflac_uint64* totalPCMFrameCount, const drflac_allocation_callbacks* pAllocationCallbacks)
+#ifndef MA_DR_FLAC_NO_STDIO
+MA_API ma_int32* ma_dr_flac_open_file_and_read_pcm_frames_s32(const char* filename, unsigned int* channels, unsigned int* sampleRate, ma_uint64* totalPCMFrameCount, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drflac* pFlac;
+ ma_dr_flac* pFlac;
if (sampleRate) {
*sampleRate = 0;
}
@@ -87719,15 +89630,15 @@ DRFLAC_API drflac_int32* drflac_open_file_and_read_pcm_frames_s32(const char* fi
if (totalPCMFrameCount) {
*totalPCMFrameCount = 0;
}
- pFlac = drflac_open_file(filename, pAllocationCallbacks);
+ pFlac = ma_dr_flac_open_file(filename, pAllocationCallbacks);
if (pFlac == NULL) {
return NULL;
}
- return drflac__full_read_and_close_s32(pFlac, channels, sampleRate, totalPCMFrameCount);
+ return ma_dr_flac__full_read_and_close_s32(pFlac, channels, sampleRate, totalPCMFrameCount);
}
-DRFLAC_API drflac_int16* drflac_open_file_and_read_pcm_frames_s16(const char* filename, unsigned int* channels, unsigned int* sampleRate, drflac_uint64* totalPCMFrameCount, const drflac_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_int16* ma_dr_flac_open_file_and_read_pcm_frames_s16(const char* filename, unsigned int* channels, unsigned int* sampleRate, ma_uint64* totalPCMFrameCount, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drflac* pFlac;
+ ma_dr_flac* pFlac;
if (sampleRate) {
*sampleRate = 0;
}
@@ -87737,15 +89648,15 @@ DRFLAC_API drflac_int16* drflac_open_file_and_read_pcm_frames_s16(const char* fi
if (totalPCMFrameCount) {
*totalPCMFrameCount = 0;
}
- pFlac = drflac_open_file(filename, pAllocationCallbacks);
+ pFlac = ma_dr_flac_open_file(filename, pAllocationCallbacks);
if (pFlac == NULL) {
return NULL;
}
- return drflac__full_read_and_close_s16(pFlac, channels, sampleRate, totalPCMFrameCount);
+ return ma_dr_flac__full_read_and_close_s16(pFlac, channels, sampleRate, totalPCMFrameCount);
}
-DRFLAC_API float* drflac_open_file_and_read_pcm_frames_f32(const char* filename, unsigned int* channels, unsigned int* sampleRate, drflac_uint64* totalPCMFrameCount, const drflac_allocation_callbacks* pAllocationCallbacks)
+MA_API float* ma_dr_flac_open_file_and_read_pcm_frames_f32(const char* filename, unsigned int* channels, unsigned int* sampleRate, ma_uint64* totalPCMFrameCount, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drflac* pFlac;
+ ma_dr_flac* pFlac;
if (sampleRate) {
*sampleRate = 0;
}
@@ -87755,16 +89666,16 @@ DRFLAC_API float* drflac_open_file_and_read_pcm_frames_f32(const char* filename,
if (totalPCMFrameCount) {
*totalPCMFrameCount = 0;
}
- pFlac = drflac_open_file(filename, pAllocationCallbacks);
+ pFlac = ma_dr_flac_open_file(filename, pAllocationCallbacks);
if (pFlac == NULL) {
return NULL;
}
- return drflac__full_read_and_close_f32(pFlac, channels, sampleRate, totalPCMFrameCount);
+ return ma_dr_flac__full_read_and_close_f32(pFlac, channels, sampleRate, totalPCMFrameCount);
}
#endif
-DRFLAC_API drflac_int32* drflac_open_memory_and_read_pcm_frames_s32(const void* data, size_t dataSize, unsigned int* channels, unsigned int* sampleRate, drflac_uint64* totalPCMFrameCount, const drflac_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_int32* ma_dr_flac_open_memory_and_read_pcm_frames_s32(const void* data, size_t dataSize, unsigned int* channels, unsigned int* sampleRate, ma_uint64* totalPCMFrameCount, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drflac* pFlac;
+ ma_dr_flac* pFlac;
if (sampleRate) {
*sampleRate = 0;
}
@@ -87774,15 +89685,15 @@ DRFLAC_API drflac_int32* drflac_open_memory_and_read_pcm_frames_s32(const void*
if (totalPCMFrameCount) {
*totalPCMFrameCount = 0;
}
- pFlac = drflac_open_memory(data, dataSize, pAllocationCallbacks);
+ pFlac = ma_dr_flac_open_memory(data, dataSize, pAllocationCallbacks);
if (pFlac == NULL) {
return NULL;
}
- return drflac__full_read_and_close_s32(pFlac, channels, sampleRate, totalPCMFrameCount);
+ return ma_dr_flac__full_read_and_close_s32(pFlac, channels, sampleRate, totalPCMFrameCount);
}
-DRFLAC_API drflac_int16* drflac_open_memory_and_read_pcm_frames_s16(const void* data, size_t dataSize, unsigned int* channels, unsigned int* sampleRate, drflac_uint64* totalPCMFrameCount, const drflac_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_int16* ma_dr_flac_open_memory_and_read_pcm_frames_s16(const void* data, size_t dataSize, unsigned int* channels, unsigned int* sampleRate, ma_uint64* totalPCMFrameCount, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drflac* pFlac;
+ ma_dr_flac* pFlac;
if (sampleRate) {
*sampleRate = 0;
}
@@ -87792,15 +89703,15 @@ DRFLAC_API drflac_int16* drflac_open_memory_and_read_pcm_frames_s16(const void*
if (totalPCMFrameCount) {
*totalPCMFrameCount = 0;
}
- pFlac = drflac_open_memory(data, dataSize, pAllocationCallbacks);
+ pFlac = ma_dr_flac_open_memory(data, dataSize, pAllocationCallbacks);
if (pFlac == NULL) {
return NULL;
}
- return drflac__full_read_and_close_s16(pFlac, channels, sampleRate, totalPCMFrameCount);
+ return ma_dr_flac__full_read_and_close_s16(pFlac, channels, sampleRate, totalPCMFrameCount);
}
-DRFLAC_API float* drflac_open_memory_and_read_pcm_frames_f32(const void* data, size_t dataSize, unsigned int* channels, unsigned int* sampleRate, drflac_uint64* totalPCMFrameCount, const drflac_allocation_callbacks* pAllocationCallbacks)
+MA_API float* ma_dr_flac_open_memory_and_read_pcm_frames_f32(const void* data, size_t dataSize, unsigned int* channels, unsigned int* sampleRate, ma_uint64* totalPCMFrameCount, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drflac* pFlac;
+ ma_dr_flac* pFlac;
if (sampleRate) {
*sampleRate = 0;
}
@@ -87810,21 +89721,21 @@ DRFLAC_API float* drflac_open_memory_and_read_pcm_frames_f32(const void* data, s
if (totalPCMFrameCount) {
*totalPCMFrameCount = 0;
}
- pFlac = drflac_open_memory(data, dataSize, pAllocationCallbacks);
+ pFlac = ma_dr_flac_open_memory(data, dataSize, pAllocationCallbacks);
if (pFlac == NULL) {
return NULL;
}
- return drflac__full_read_and_close_f32(pFlac, channels, sampleRate, totalPCMFrameCount);
+ return ma_dr_flac__full_read_and_close_f32(pFlac, channels, sampleRate, totalPCMFrameCount);
}
-DRFLAC_API void drflac_free(void* p, const drflac_allocation_callbacks* pAllocationCallbacks)
+MA_API void ma_dr_flac_free(void* p, const ma_allocation_callbacks* pAllocationCallbacks)
{
if (pAllocationCallbacks != NULL) {
- drflac__free_from_callbacks(p, pAllocationCallbacks);
+ ma_dr_flac__free_from_callbacks(p, pAllocationCallbacks);
} else {
- drflac__free_default(p, NULL);
+ ma_dr_flac__free_default(p, NULL);
}
}
-DRFLAC_API void drflac_init_vorbis_comment_iterator(drflac_vorbis_comment_iterator* pIter, drflac_uint32 commentCount, const void* pComments)
+MA_API void ma_dr_flac_init_vorbis_comment_iterator(ma_dr_flac_vorbis_comment_iterator* pIter, ma_uint32 commentCount, const void* pComments)
{
if (pIter == NULL) {
return;
@@ -87832,9 +89743,9 @@ DRFLAC_API void drflac_init_vorbis_comment_iterator(drflac_vorbis_comment_iterat
pIter->countRemaining = commentCount;
pIter->pRunningData = (const char*)pComments;
}
-DRFLAC_API const char* drflac_next_vorbis_comment(drflac_vorbis_comment_iterator* pIter, drflac_uint32* pCommentLengthOut)
+MA_API const char* ma_dr_flac_next_vorbis_comment(ma_dr_flac_vorbis_comment_iterator* pIter, ma_uint32* pCommentLengthOut)
{
- drflac_int32 length;
+ ma_int32 length;
const char* pComment;
if (pCommentLengthOut) {
*pCommentLengthOut = 0;
@@ -87842,7 +89753,7 @@ DRFLAC_API const char* drflac_next_vorbis_comment(drflac_vorbis_comment_iterator
if (pIter == NULL || pIter->countRemaining == 0 || pIter->pRunningData == NULL) {
return NULL;
}
- length = drflac__le2host_32_ptr_unaligned(pIter->pRunningData);
+ length = ma_dr_flac__le2host_32_ptr_unaligned(pIter->pRunningData);
pIter->pRunningData += 4;
pComment = pIter->pRunningData;
pIter->pRunningData += length;
@@ -87852,7 +89763,7 @@ DRFLAC_API const char* drflac_next_vorbis_comment(drflac_vorbis_comment_iterator
}
return pComment;
}
-DRFLAC_API void drflac_init_cuesheet_track_iterator(drflac_cuesheet_track_iterator* pIter, drflac_uint32 trackCount, const void* pTrackData)
+MA_API void ma_dr_flac_init_cuesheet_track_iterator(ma_dr_flac_cuesheet_track_iterator* pIter, ma_uint32 trackCount, const void* pTrackData)
{
if (pIter == NULL) {
return;
@@ -87860,127 +89771,127 @@ DRFLAC_API void drflac_init_cuesheet_track_iterator(drflac_cuesheet_track_iterat
pIter->countRemaining = trackCount;
pIter->pRunningData = (const char*)pTrackData;
}
-DRFLAC_API drflac_bool32 drflac_next_cuesheet_track(drflac_cuesheet_track_iterator* pIter, drflac_cuesheet_track* pCuesheetTrack)
+MA_API ma_bool32 ma_dr_flac_next_cuesheet_track(ma_dr_flac_cuesheet_track_iterator* pIter, ma_dr_flac_cuesheet_track* pCuesheetTrack)
{
- drflac_cuesheet_track cuesheetTrack;
+ ma_dr_flac_cuesheet_track cuesheetTrack;
const char* pRunningData;
- drflac_uint64 offsetHi;
- drflac_uint64 offsetLo;
+ ma_uint64 offsetHi;
+ ma_uint64 offsetLo;
if (pIter == NULL || pIter->countRemaining == 0 || pIter->pRunningData == NULL) {
- return DRFLAC_FALSE;
+ return MA_FALSE;
}
pRunningData = pIter->pRunningData;
- offsetHi = drflac__be2host_32(*(const drflac_uint32*)pRunningData); pRunningData += 4;
- offsetLo = drflac__be2host_32(*(const drflac_uint32*)pRunningData); pRunningData += 4;
+ offsetHi = ma_dr_flac__be2host_32(*(const ma_uint32*)pRunningData); pRunningData += 4;
+ offsetLo = ma_dr_flac__be2host_32(*(const ma_uint32*)pRunningData); pRunningData += 4;
cuesheetTrack.offset = offsetLo | (offsetHi << 32);
cuesheetTrack.trackNumber = pRunningData[0]; pRunningData += 1;
- DRFLAC_COPY_MEMORY(cuesheetTrack.ISRC, pRunningData, sizeof(cuesheetTrack.ISRC)); pRunningData += 12;
+ MA_DR_FLAC_COPY_MEMORY(cuesheetTrack.ISRC, pRunningData, sizeof(cuesheetTrack.ISRC)); pRunningData += 12;
cuesheetTrack.isAudio = (pRunningData[0] & 0x80) != 0;
cuesheetTrack.preEmphasis = (pRunningData[0] & 0x40) != 0; pRunningData += 14;
cuesheetTrack.indexCount = pRunningData[0]; pRunningData += 1;
- cuesheetTrack.pIndexPoints = (const drflac_cuesheet_track_index*)pRunningData; pRunningData += cuesheetTrack.indexCount * sizeof(drflac_cuesheet_track_index);
+ cuesheetTrack.pIndexPoints = (const ma_dr_flac_cuesheet_track_index*)pRunningData; pRunningData += cuesheetTrack.indexCount * sizeof(ma_dr_flac_cuesheet_track_index);
pIter->pRunningData = pRunningData;
pIter->countRemaining -= 1;
if (pCuesheetTrack) {
*pCuesheetTrack = cuesheetTrack;
}
- return DRFLAC_TRUE;
+ return MA_TRUE;
}
#if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)))
#pragma GCC diagnostic pop
#endif
#endif
/* dr_flac_c end */
-#endif /* DRFLAC_IMPLEMENTATION */
+#endif /* MA_DR_FLAC_IMPLEMENTATION */
#endif /* MA_NO_FLAC */
#if !defined(MA_NO_MP3) && !defined(MA_NO_DECODING)
-#if !defined(DR_MP3_IMPLEMENTATION) && !defined(DRMP3_IMPLEMENTATION) /* For backwards compatibility. Will be removed in version 0.11 for cleanliness. */
+#if !defined(MA_DR_MP3_IMPLEMENTATION) && !defined(MA_DR_MP3_IMPLEMENTATION) /* For backwards compatibility. Will be removed in version 0.11 for cleanliness. */
/* dr_mp3_c begin */
-#ifndef dr_mp3_c
-#define dr_mp3_c
+#ifndef ma_dr_mp3_c
+#define ma_dr_mp3_c
#include
#include
#include
-DRMP3_API void drmp3_version(drmp3_uint32* pMajor, drmp3_uint32* pMinor, drmp3_uint32* pRevision)
+MA_API void ma_dr_mp3_version(ma_uint32* pMajor, ma_uint32* pMinor, ma_uint32* pRevision)
{
if (pMajor) {
- *pMajor = DRMP3_VERSION_MAJOR;
+ *pMajor = MA_DR_MP3_VERSION_MAJOR;
}
if (pMinor) {
- *pMinor = DRMP3_VERSION_MINOR;
+ *pMinor = MA_DR_MP3_VERSION_MINOR;
}
if (pRevision) {
- *pRevision = DRMP3_VERSION_REVISION;
+ *pRevision = MA_DR_MP3_VERSION_REVISION;
}
}
-DRMP3_API const char* drmp3_version_string(void)
+MA_API const char* ma_dr_mp3_version_string(void)
{
- return DRMP3_VERSION_STRING;
+ return MA_DR_MP3_VERSION_STRING;
}
#if defined(__TINYC__)
-#define DR_MP3_NO_SIMD
-#endif
-#define DRMP3_OFFSET_PTR(p, offset) ((void*)((drmp3_uint8*)(p) + (offset)))
-#define DRMP3_MAX_FREE_FORMAT_FRAME_SIZE 2304
-#ifndef DRMP3_MAX_FRAME_SYNC_MATCHES
-#define DRMP3_MAX_FRAME_SYNC_MATCHES 10
-#endif
-#define DRMP3_MAX_L3_FRAME_PAYLOAD_BYTES DRMP3_MAX_FREE_FORMAT_FRAME_SIZE
-#define DRMP3_MAX_BITRESERVOIR_BYTES 511
-#define DRMP3_SHORT_BLOCK_TYPE 2
-#define DRMP3_STOP_BLOCK_TYPE 3
-#define DRMP3_MODE_MONO 3
-#define DRMP3_MODE_JOINT_STEREO 1
-#define DRMP3_HDR_SIZE 4
-#define DRMP3_HDR_IS_MONO(h) (((h[3]) & 0xC0) == 0xC0)
-#define DRMP3_HDR_IS_MS_STEREO(h) (((h[3]) & 0xE0) == 0x60)
-#define DRMP3_HDR_IS_FREE_FORMAT(h) (((h[2]) & 0xF0) == 0)
-#define DRMP3_HDR_IS_CRC(h) (!((h[1]) & 1))
-#define DRMP3_HDR_TEST_PADDING(h) ((h[2]) & 0x2)
-#define DRMP3_HDR_TEST_MPEG1(h) ((h[1]) & 0x8)
-#define DRMP3_HDR_TEST_NOT_MPEG25(h) ((h[1]) & 0x10)
-#define DRMP3_HDR_TEST_I_STEREO(h) ((h[3]) & 0x10)
-#define DRMP3_HDR_TEST_MS_STEREO(h) ((h[3]) & 0x20)
-#define DRMP3_HDR_GET_STEREO_MODE(h) (((h[3]) >> 6) & 3)
-#define DRMP3_HDR_GET_STEREO_MODE_EXT(h) (((h[3]) >> 4) & 3)
-#define DRMP3_HDR_GET_LAYER(h) (((h[1]) >> 1) & 3)
-#define DRMP3_HDR_GET_BITRATE(h) ((h[2]) >> 4)
-#define DRMP3_HDR_GET_SAMPLE_RATE(h) (((h[2]) >> 2) & 3)
-#define DRMP3_HDR_GET_MY_SAMPLE_RATE(h) (DRMP3_HDR_GET_SAMPLE_RATE(h) + (((h[1] >> 3) & 1) + ((h[1] >> 4) & 1))*3)
-#define DRMP3_HDR_IS_FRAME_576(h) ((h[1] & 14) == 2)
-#define DRMP3_HDR_IS_LAYER_1(h) ((h[1] & 6) == 6)
-#define DRMP3_BITS_DEQUANTIZER_OUT -1
-#define DRMP3_MAX_SCF (255 + DRMP3_BITS_DEQUANTIZER_OUT*4 - 210)
-#define DRMP3_MAX_SCFI ((DRMP3_MAX_SCF + 3) & ~3)
-#define DRMP3_MIN(a, b) ((a) > (b) ? (b) : (a))
-#define DRMP3_MAX(a, b) ((a) < (b) ? (b) : (a))
-#if !defined(DR_MP3_NO_SIMD)
-#if !defined(DR_MP3_ONLY_SIMD) && (defined(_M_X64) || defined(__x86_64__) || defined(__aarch64__) || defined(_M_ARM64))
-#define DR_MP3_ONLY_SIMD
+#define MA_DR_MP3_NO_SIMD
+#endif
+#define MA_DR_MP3_OFFSET_PTR(p, offset) ((void*)((ma_uint8*)(p) + (offset)))
+#define MA_DR_MP3_MAX_FREE_FORMAT_FRAME_SIZE 2304
+#ifndef MA_DR_MP3_MAX_FRAME_SYNC_MATCHES
+#define MA_DR_MP3_MAX_FRAME_SYNC_MATCHES 10
+#endif
+#define MA_DR_MP3_MAX_L3_FRAME_PAYLOAD_BYTES MA_DR_MP3_MAX_FREE_FORMAT_FRAME_SIZE
+#define MA_DR_MP3_MAX_BITRESERVOIR_BYTES 511
+#define MA_DR_MP3_SHORT_BLOCK_TYPE 2
+#define MA_DR_MP3_STOP_BLOCK_TYPE 3
+#define MA_DR_MP3_MODE_MONO 3
+#define MA_DR_MP3_MODE_JOINT_STEREO 1
+#define MA_DR_MP3_HDR_SIZE 4
+#define MA_DR_MP3_HDR_IS_MONO(h) (((h[3]) & 0xC0) == 0xC0)
+#define MA_DR_MP3_HDR_IS_MS_STEREO(h) (((h[3]) & 0xE0) == 0x60)
+#define MA_DR_MP3_HDR_IS_FREE_FORMAT(h) (((h[2]) & 0xF0) == 0)
+#define MA_DR_MP3_HDR_IS_CRC(h) (!((h[1]) & 1))
+#define MA_DR_MP3_HDR_TEST_PADDING(h) ((h[2]) & 0x2)
+#define MA_DR_MP3_HDR_TEST_MPEG1(h) ((h[1]) & 0x8)
+#define MA_DR_MP3_HDR_TEST_NOT_MPEG25(h) ((h[1]) & 0x10)
+#define MA_DR_MP3_HDR_TEST_I_STEREO(h) ((h[3]) & 0x10)
+#define MA_DR_MP3_HDR_TEST_MS_STEREO(h) ((h[3]) & 0x20)
+#define MA_DR_MP3_HDR_GET_STEREO_MODE(h) (((h[3]) >> 6) & 3)
+#define MA_DR_MP3_HDR_GET_STEREO_MODE_EXT(h) (((h[3]) >> 4) & 3)
+#define MA_DR_MP3_HDR_GET_LAYER(h) (((h[1]) >> 1) & 3)
+#define MA_DR_MP3_HDR_GET_BITRATE(h) ((h[2]) >> 4)
+#define MA_DR_MP3_HDR_GET_SAMPLE_RATE(h) (((h[2]) >> 2) & 3)
+#define MA_DR_MP3_HDR_GET_MY_SAMPLE_RATE(h) (MA_DR_MP3_HDR_GET_SAMPLE_RATE(h) + (((h[1] >> 3) & 1) + ((h[1] >> 4) & 1))*3)
+#define MA_DR_MP3_HDR_IS_FRAME_576(h) ((h[1] & 14) == 2)
+#define MA_DR_MP3_HDR_IS_LAYER_1(h) ((h[1] & 6) == 6)
+#define MA_DR_MP3_BITS_DEQUANTIZER_OUT -1
+#define MA_DR_MP3_MAX_SCF (255 + MA_DR_MP3_BITS_DEQUANTIZER_OUT*4 - 210)
+#define MA_DR_MP3_MAX_SCFI ((MA_DR_MP3_MAX_SCF + 3) & ~3)
+#define MA_DR_MP3_MIN(a, b) ((a) > (b) ? (b) : (a))
+#define MA_DR_MP3_MAX(a, b) ((a) < (b) ? (b) : (a))
+#if !defined(MA_DR_MP3_NO_SIMD)
+#if !defined(MA_DR_MP3_ONLY_SIMD) && (defined(_M_X64) || defined(__x86_64__) || defined(__aarch64__) || defined(_M_ARM64))
+#define MA_DR_MP3_ONLY_SIMD
#endif
#if ((defined(_MSC_VER) && _MSC_VER >= 1400) && defined(_M_X64)) || ((defined(__i386) || defined(_M_IX86) || defined(__i386__) || defined(__x86_64__)) && ((defined(_M_IX86_FP) && _M_IX86_FP == 2) || defined(__SSE2__)))
#if defined(_MSC_VER)
#include
#endif
#include
-#define DRMP3_HAVE_SSE 1
-#define DRMP3_HAVE_SIMD 1
-#define DRMP3_VSTORE _mm_storeu_ps
-#define DRMP3_VLD _mm_loadu_ps
-#define DRMP3_VSET _mm_set1_ps
-#define DRMP3_VADD _mm_add_ps
-#define DRMP3_VSUB _mm_sub_ps
-#define DRMP3_VMUL _mm_mul_ps
-#define DRMP3_VMAC(a, x, y) _mm_add_ps(a, _mm_mul_ps(x, y))
-#define DRMP3_VMSB(a, x, y) _mm_sub_ps(a, _mm_mul_ps(x, y))
-#define DRMP3_VMUL_S(x, s) _mm_mul_ps(x, _mm_set1_ps(s))
-#define DRMP3_VREV(x) _mm_shuffle_ps(x, x, _MM_SHUFFLE(0, 1, 2, 3))
-typedef __m128 drmp3_f4;
-#if defined(_MSC_VER) || defined(DR_MP3_ONLY_SIMD)
-#define drmp3_cpuid __cpuid
+#define MA_DR_MP3_HAVE_SSE 1
+#define MA_DR_MP3_HAVE_SIMD 1
+#define MA_DR_MP3_VSTORE _mm_storeu_ps
+#define MA_DR_MP3_VLD _mm_loadu_ps
+#define MA_DR_MP3_VSET _mm_set1_ps
+#define MA_DR_MP3_VADD _mm_add_ps
+#define MA_DR_MP3_VSUB _mm_sub_ps
+#define MA_DR_MP3_VMUL _mm_mul_ps
+#define MA_DR_MP3_VMAC(a, x, y) _mm_add_ps(a, _mm_mul_ps(x, y))
+#define MA_DR_MP3_VMSB(a, x, y) _mm_sub_ps(a, _mm_mul_ps(x, y))
+#define MA_DR_MP3_VMUL_S(x, s) _mm_mul_ps(x, _mm_set1_ps(s))
+#define MA_DR_MP3_VREV(x) _mm_shuffle_ps(x, x, _MM_SHUFFLE(0, 1, 2, 3))
+typedef __m128 ma_dr_mp3_f4;
+#if defined(_MSC_VER) || defined(MA_DR_MP3_ONLY_SIMD)
+#define ma_dr_mp3_cpuid __cpuid
#else
-static __inline__ __attribute__((always_inline)) void drmp3_cpuid(int CPUInfo[], const int InfoType)
+static __inline__ __attribute__((always_inline)) void ma_dr_mp3_cpuid(int CPUInfo[], const int InfoType)
{
#if defined(__PIC__)
__asm__ __volatile__(
@@ -88004,9 +89915,9 @@ static __inline__ __attribute__((always_inline)) void drmp3_cpuid(int CPUInfo[],
#endif
}
#endif
-static int drmp3_have_simd(void)
+static int ma_dr_mp3_have_simd(void)
{
-#ifdef DR_MP3_ONLY_SIMD
+#ifdef MA_DR_MP3_ONLY_SIMD
return 1;
#else
static int g_have_simd;
@@ -88018,10 +89929,10 @@ static int drmp3_have_simd(void)
#endif
if (g_have_simd)
goto end;
- drmp3_cpuid(CPUInfo, 0);
+ ma_dr_mp3_cpuid(CPUInfo, 0);
if (CPUInfo[0] > 0)
{
- drmp3_cpuid(CPUInfo, 1);
+ ma_dr_mp3_cpuid(CPUInfo, 1);
g_have_simd = (CPUInfo[3] & (1 << 26)) + 1;
return g_have_simd - 1;
}
@@ -88031,108 +89942,108 @@ static int drmp3_have_simd(void)
}
#elif defined(__ARM_NEON) || defined(__aarch64__) || defined(_M_ARM64)
#include
-#define DRMP3_HAVE_SSE 0
-#define DRMP3_HAVE_SIMD 1
-#define DRMP3_VSTORE vst1q_f32
-#define DRMP3_VLD vld1q_f32
-#define DRMP3_VSET vmovq_n_f32
-#define DRMP3_VADD vaddq_f32
-#define DRMP3_VSUB vsubq_f32
-#define DRMP3_VMUL vmulq_f32
-#define DRMP3_VMAC(a, x, y) vmlaq_f32(a, x, y)
-#define DRMP3_VMSB(a, x, y) vmlsq_f32(a, x, y)
-#define DRMP3_VMUL_S(x, s) vmulq_f32(x, vmovq_n_f32(s))
-#define DRMP3_VREV(x) vcombine_f32(vget_high_f32(vrev64q_f32(x)), vget_low_f32(vrev64q_f32(x)))
-typedef float32x4_t drmp3_f4;
-static int drmp3_have_simd(void)
+#define MA_DR_MP3_HAVE_SSE 0
+#define MA_DR_MP3_HAVE_SIMD 1
+#define MA_DR_MP3_VSTORE vst1q_f32
+#define MA_DR_MP3_VLD vld1q_f32
+#define MA_DR_MP3_VSET vmovq_n_f32
+#define MA_DR_MP3_VADD vaddq_f32
+#define MA_DR_MP3_VSUB vsubq_f32
+#define MA_DR_MP3_VMUL vmulq_f32
+#define MA_DR_MP3_VMAC(a, x, y) vmlaq_f32(a, x, y)
+#define MA_DR_MP3_VMSB(a, x, y) vmlsq_f32(a, x, y)
+#define MA_DR_MP3_VMUL_S(x, s) vmulq_f32(x, vmovq_n_f32(s))
+#define MA_DR_MP3_VREV(x) vcombine_f32(vget_high_f32(vrev64q_f32(x)), vget_low_f32(vrev64q_f32(x)))
+typedef float32x4_t ma_dr_mp3_f4;
+static int ma_dr_mp3_have_simd(void)
{
return 1;
}
#else
-#define DRMP3_HAVE_SSE 0
-#define DRMP3_HAVE_SIMD 0
-#ifdef DR_MP3_ONLY_SIMD
-#error DR_MP3_ONLY_SIMD used, but SSE/NEON not enabled
+#define MA_DR_MP3_HAVE_SSE 0
+#define MA_DR_MP3_HAVE_SIMD 0
+#ifdef MA_DR_MP3_ONLY_SIMD
+#error MA_DR_MP3_ONLY_SIMD used, but SSE/NEON not enabled
#endif
#endif
#else
-#define DRMP3_HAVE_SIMD 0
+#define MA_DR_MP3_HAVE_SIMD 0
#endif
-#if defined(__ARM_ARCH) && (__ARM_ARCH >= 6) && !defined(__aarch64__) && !defined(_M_ARM64)
-#define DRMP3_HAVE_ARMV6 1
-static __inline__ __attribute__((always_inline)) drmp3_int32 drmp3_clip_int16_arm(drmp3_int32 a)
+#if defined(__ARM_ARCH) && (__ARM_ARCH >= 6) && !defined(__aarch64__) && !defined(_M_ARM64) && !defined(__ARM_ARCH_6M__)
+#define MA_DR_MP3_HAVE_ARMV6 1
+static __inline__ __attribute__((always_inline)) ma_int32 ma_dr_mp3_clip_int16_arm(ma_int32 a)
{
- drmp3_int32 x = 0;
+ ma_int32 x = 0;
__asm__ ("ssat %0, #16, %1" : "=r"(x) : "r"(a));
return x;
}
#else
-#define DRMP3_HAVE_ARMV6 0
+#define MA_DR_MP3_HAVE_ARMV6 0
#endif
-#ifndef DRMP3_ASSERT
+#ifndef MA_DR_MP3_ASSERT
#include
-#define DRMP3_ASSERT(expression) assert(expression)
+#define MA_DR_MP3_ASSERT(expression) assert(expression)
#endif
-#ifndef DRMP3_COPY_MEMORY
-#define DRMP3_COPY_MEMORY(dst, src, sz) memcpy((dst), (src), (sz))
+#ifndef MA_DR_MP3_COPY_MEMORY
+#define MA_DR_MP3_COPY_MEMORY(dst, src, sz) memcpy((dst), (src), (sz))
#endif
-#ifndef DRMP3_MOVE_MEMORY
-#define DRMP3_MOVE_MEMORY(dst, src, sz) memmove((dst), (src), (sz))
+#ifndef MA_DR_MP3_MOVE_MEMORY
+#define MA_DR_MP3_MOVE_MEMORY(dst, src, sz) memmove((dst), (src), (sz))
#endif
-#ifndef DRMP3_ZERO_MEMORY
-#define DRMP3_ZERO_MEMORY(p, sz) memset((p), 0, (sz))
+#ifndef MA_DR_MP3_ZERO_MEMORY
+#define MA_DR_MP3_ZERO_MEMORY(p, sz) memset((p), 0, (sz))
#endif
-#define DRMP3_ZERO_OBJECT(p) DRMP3_ZERO_MEMORY((p), sizeof(*(p)))
-#ifndef DRMP3_MALLOC
-#define DRMP3_MALLOC(sz) malloc((sz))
+#define MA_DR_MP3_ZERO_OBJECT(p) MA_DR_MP3_ZERO_MEMORY((p), sizeof(*(p)))
+#ifndef MA_DR_MP3_MALLOC
+#define MA_DR_MP3_MALLOC(sz) malloc((sz))
#endif
-#ifndef DRMP3_REALLOC
-#define DRMP3_REALLOC(p, sz) realloc((p), (sz))
+#ifndef MA_DR_MP3_REALLOC
+#define MA_DR_MP3_REALLOC(p, sz) realloc((p), (sz))
#endif
-#ifndef DRMP3_FREE
-#define DRMP3_FREE(p) free((p))
+#ifndef MA_DR_MP3_FREE
+#define MA_DR_MP3_FREE(p) free((p))
#endif
typedef struct
{
- const drmp3_uint8 *buf;
+ const ma_uint8 *buf;
int pos, limit;
-} drmp3_bs;
+} ma_dr_mp3_bs;
typedef struct
{
float scf[3*64];
- drmp3_uint8 total_bands, stereo_bands, bitalloc[64], scfcod[64];
-} drmp3_L12_scale_info;
+ ma_uint8 total_bands, stereo_bands, bitalloc[64], scfcod[64];
+} ma_dr_mp3_L12_scale_info;
typedef struct
{
- drmp3_uint8 tab_offset, code_tab_width, band_count;
-} drmp3_L12_subband_alloc;
+ ma_uint8 tab_offset, code_tab_width, band_count;
+} ma_dr_mp3_L12_subband_alloc;
typedef struct
{
- const drmp3_uint8 *sfbtab;
- drmp3_uint16 part_23_length, big_values, scalefac_compress;
- drmp3_uint8 global_gain, block_type, mixed_block_flag, n_long_sfb, n_short_sfb;
- drmp3_uint8 table_select[3], region_count[3], subblock_gain[3];
- drmp3_uint8 preflag, scalefac_scale, count1_table, scfsi;
-} drmp3_L3_gr_info;
+ const ma_uint8 *sfbtab;
+ ma_uint16 part_23_length, big_values, scalefac_compress;
+ ma_uint8 global_gain, block_type, mixed_block_flag, n_long_sfb, n_short_sfb;
+ ma_uint8 table_select[3], region_count[3], subblock_gain[3];
+ ma_uint8 preflag, scalefac_scale, count1_table, scfsi;
+} ma_dr_mp3_L3_gr_info;
typedef struct
{
- drmp3_bs bs;
- drmp3_uint8 maindata[DRMP3_MAX_BITRESERVOIR_BYTES + DRMP3_MAX_L3_FRAME_PAYLOAD_BYTES];
- drmp3_L3_gr_info gr_info[4];
+ ma_dr_mp3_bs bs;
+ ma_uint8 maindata[MA_DR_MP3_MAX_BITRESERVOIR_BYTES + MA_DR_MP3_MAX_L3_FRAME_PAYLOAD_BYTES];
+ ma_dr_mp3_L3_gr_info gr_info[4];
float grbuf[2][576], scf[40], syn[18 + 15][2*32];
- drmp3_uint8 ist_pos[2][39];
-} drmp3dec_scratch;
-static void drmp3_bs_init(drmp3_bs *bs, const drmp3_uint8 *data, int bytes)
+ ma_uint8 ist_pos[2][39];
+} ma_dr_mp3dec_scratch;
+static void ma_dr_mp3_bs_init(ma_dr_mp3_bs *bs, const ma_uint8 *data, int bytes)
{
bs->buf = data;
bs->pos = 0;
bs->limit = bytes*8;
}
-static drmp3_uint32 drmp3_bs_get_bits(drmp3_bs *bs, int n)
+static ma_uint32 ma_dr_mp3_bs_get_bits(ma_dr_mp3_bs *bs, int n)
{
- drmp3_uint32 next, cache = 0, s = bs->pos & 7;
+ ma_uint32 next, cache = 0, s = bs->pos & 7;
int shl = n + s;
- const drmp3_uint8 *p = bs->buf + (bs->pos >> 3);
+ const ma_uint8 *p = bs->buf + (bs->pos >> 3);
if ((bs->pos += n) > bs->limit)
return 0;
next = *p++ & (255 >> s);
@@ -88143,72 +90054,72 @@ static drmp3_uint32 drmp3_bs_get_bits(drmp3_bs *bs, int n)
}
return cache | (next >> -shl);
}
-static int drmp3_hdr_valid(const drmp3_uint8 *h)
+static int ma_dr_mp3_hdr_valid(const ma_uint8 *h)
{
return h[0] == 0xff &&
((h[1] & 0xF0) == 0xf0 || (h[1] & 0xFE) == 0xe2) &&
- (DRMP3_HDR_GET_LAYER(h) != 0) &&
- (DRMP3_HDR_GET_BITRATE(h) != 15) &&
- (DRMP3_HDR_GET_SAMPLE_RATE(h) != 3);
+ (MA_DR_MP3_HDR_GET_LAYER(h) != 0) &&
+ (MA_DR_MP3_HDR_GET_BITRATE(h) != 15) &&
+ (MA_DR_MP3_HDR_GET_SAMPLE_RATE(h) != 3);
}
-static int drmp3_hdr_compare(const drmp3_uint8 *h1, const drmp3_uint8 *h2)
+static int ma_dr_mp3_hdr_compare(const ma_uint8 *h1, const ma_uint8 *h2)
{
- return drmp3_hdr_valid(h2) &&
+ return ma_dr_mp3_hdr_valid(h2) &&
((h1[1] ^ h2[1]) & 0xFE) == 0 &&
((h1[2] ^ h2[2]) & 0x0C) == 0 &&
- !(DRMP3_HDR_IS_FREE_FORMAT(h1) ^ DRMP3_HDR_IS_FREE_FORMAT(h2));
+ !(MA_DR_MP3_HDR_IS_FREE_FORMAT(h1) ^ MA_DR_MP3_HDR_IS_FREE_FORMAT(h2));
}
-static unsigned drmp3_hdr_bitrate_kbps(const drmp3_uint8 *h)
+static unsigned ma_dr_mp3_hdr_bitrate_kbps(const ma_uint8 *h)
{
- static const drmp3_uint8 halfrate[2][3][15] = {
+ static const ma_uint8 halfrate[2][3][15] = {
{ { 0,4,8,12,16,20,24,28,32,40,48,56,64,72,80 }, { 0,4,8,12,16,20,24,28,32,40,48,56,64,72,80 }, { 0,16,24,28,32,40,48,56,64,72,80,88,96,112,128 } },
{ { 0,16,20,24,28,32,40,48,56,64,80,96,112,128,160 }, { 0,16,24,28,32,40,48,56,64,80,96,112,128,160,192 }, { 0,16,32,48,64,80,96,112,128,144,160,176,192,208,224 } },
};
- return 2*halfrate[!!DRMP3_HDR_TEST_MPEG1(h)][DRMP3_HDR_GET_LAYER(h) - 1][DRMP3_HDR_GET_BITRATE(h)];
+ return 2*halfrate[!!MA_DR_MP3_HDR_TEST_MPEG1(h)][MA_DR_MP3_HDR_GET_LAYER(h) - 1][MA_DR_MP3_HDR_GET_BITRATE(h)];
}
-static unsigned drmp3_hdr_sample_rate_hz(const drmp3_uint8 *h)
+static unsigned ma_dr_mp3_hdr_sample_rate_hz(const ma_uint8 *h)
{
static const unsigned g_hz[3] = { 44100, 48000, 32000 };
- return g_hz[DRMP3_HDR_GET_SAMPLE_RATE(h)] >> (int)!DRMP3_HDR_TEST_MPEG1(h) >> (int)!DRMP3_HDR_TEST_NOT_MPEG25(h);
+ return g_hz[MA_DR_MP3_HDR_GET_SAMPLE_RATE(h)] >> (int)!MA_DR_MP3_HDR_TEST_MPEG1(h) >> (int)!MA_DR_MP3_HDR_TEST_NOT_MPEG25(h);
}
-static unsigned drmp3_hdr_frame_samples(const drmp3_uint8 *h)
+static unsigned ma_dr_mp3_hdr_frame_samples(const ma_uint8 *h)
{
- return DRMP3_HDR_IS_LAYER_1(h) ? 384 : (1152 >> (int)DRMP3_HDR_IS_FRAME_576(h));
+ return MA_DR_MP3_HDR_IS_LAYER_1(h) ? 384 : (1152 >> (int)MA_DR_MP3_HDR_IS_FRAME_576(h));
}
-static int drmp3_hdr_frame_bytes(const drmp3_uint8 *h, int free_format_size)
+static int ma_dr_mp3_hdr_frame_bytes(const ma_uint8 *h, int free_format_size)
{
- int frame_bytes = drmp3_hdr_frame_samples(h)*drmp3_hdr_bitrate_kbps(h)*125/drmp3_hdr_sample_rate_hz(h);
- if (DRMP3_HDR_IS_LAYER_1(h))
+ int frame_bytes = ma_dr_mp3_hdr_frame_samples(h)*ma_dr_mp3_hdr_bitrate_kbps(h)*125/ma_dr_mp3_hdr_sample_rate_hz(h);
+ if (MA_DR_MP3_HDR_IS_LAYER_1(h))
{
frame_bytes &= ~3;
}
return frame_bytes ? frame_bytes : free_format_size;
}
-static int drmp3_hdr_padding(const drmp3_uint8 *h)
+static int ma_dr_mp3_hdr_padding(const ma_uint8 *h)
{
- return DRMP3_HDR_TEST_PADDING(h) ? (DRMP3_HDR_IS_LAYER_1(h) ? 4 : 1) : 0;
+ return MA_DR_MP3_HDR_TEST_PADDING(h) ? (MA_DR_MP3_HDR_IS_LAYER_1(h) ? 4 : 1) : 0;
}
-#ifndef DR_MP3_ONLY_MP3
-static const drmp3_L12_subband_alloc *drmp3_L12_subband_alloc_table(const drmp3_uint8 *hdr, drmp3_L12_scale_info *sci)
+#ifndef MA_DR_MP3_ONLY_MP3
+static const ma_dr_mp3_L12_subband_alloc *ma_dr_mp3_L12_subband_alloc_table(const ma_uint8 *hdr, ma_dr_mp3_L12_scale_info *sci)
{
- const drmp3_L12_subband_alloc *alloc;
- int mode = DRMP3_HDR_GET_STEREO_MODE(hdr);
- int nbands, stereo_bands = (mode == DRMP3_MODE_MONO) ? 0 : (mode == DRMP3_MODE_JOINT_STEREO) ? (DRMP3_HDR_GET_STEREO_MODE_EXT(hdr) << 2) + 4 : 32;
- if (DRMP3_HDR_IS_LAYER_1(hdr))
+ const ma_dr_mp3_L12_subband_alloc *alloc;
+ int mode = MA_DR_MP3_HDR_GET_STEREO_MODE(hdr);
+ int nbands, stereo_bands = (mode == MA_DR_MP3_MODE_MONO) ? 0 : (mode == MA_DR_MP3_MODE_JOINT_STEREO) ? (MA_DR_MP3_HDR_GET_STEREO_MODE_EXT(hdr) << 2) + 4 : 32;
+ if (MA_DR_MP3_HDR_IS_LAYER_1(hdr))
{
- static const drmp3_L12_subband_alloc g_alloc_L1[] = { { 76, 4, 32 } };
+ static const ma_dr_mp3_L12_subband_alloc g_alloc_L1[] = { { 76, 4, 32 } };
alloc = g_alloc_L1;
nbands = 32;
- } else if (!DRMP3_HDR_TEST_MPEG1(hdr))
+ } else if (!MA_DR_MP3_HDR_TEST_MPEG1(hdr))
{
- static const drmp3_L12_subband_alloc g_alloc_L2M2[] = { { 60, 4, 4 }, { 44, 3, 7 }, { 44, 2, 19 } };
+ static const ma_dr_mp3_L12_subband_alloc g_alloc_L2M2[] = { { 60, 4, 4 }, { 44, 3, 7 }, { 44, 2, 19 } };
alloc = g_alloc_L2M2;
nbands = 30;
} else
{
- static const drmp3_L12_subband_alloc g_alloc_L2M1[] = { { 0, 4, 3 }, { 16, 4, 8 }, { 32, 3, 12 }, { 40, 2, 7 } };
- int sample_rate_idx = DRMP3_HDR_GET_SAMPLE_RATE(hdr);
- unsigned kbps = drmp3_hdr_bitrate_kbps(hdr) >> (int)(mode != DRMP3_MODE_MONO);
+ static const ma_dr_mp3_L12_subband_alloc g_alloc_L2M1[] = { { 0, 4, 3 }, { 16, 4, 8 }, { 32, 3, 12 }, { 40, 2, 7 } };
+ int sample_rate_idx = MA_DR_MP3_HDR_GET_SAMPLE_RATE(hdr);
+ unsigned kbps = ma_dr_mp3_hdr_bitrate_kbps(hdr) >> (int)(mode != MA_DR_MP3_MODE_MONO);
if (!kbps)
{
kbps = 192;
@@ -88217,7 +90128,7 @@ static const drmp3_L12_subband_alloc *drmp3_L12_subband_alloc_table(const drmp3_
nbands = 27;
if (kbps < 56)
{
- static const drmp3_L12_subband_alloc g_alloc_L2M1_lowrate[] = { { 44, 4, 2 }, { 44, 3, 10 } };
+ static const ma_dr_mp3_L12_subband_alloc g_alloc_L2M1_lowrate[] = { { 44, 4, 2 }, { 44, 3, 10 } };
alloc = g_alloc_L2M1_lowrate;
nbands = sample_rate_idx == 2 ? 12 : 8;
} else if (kbps >= 96 && sample_rate_idx != 1)
@@ -88225,15 +90136,15 @@ static const drmp3_L12_subband_alloc *drmp3_L12_subband_alloc_table(const drmp3_
nbands = 30;
}
}
- sci->total_bands = (drmp3_uint8)nbands;
- sci->stereo_bands = (drmp3_uint8)DRMP3_MIN(stereo_bands, nbands);
+ sci->total_bands = (ma_uint8)nbands;
+ sci->stereo_bands = (ma_uint8)MA_DR_MP3_MIN(stereo_bands, nbands);
return alloc;
}
-static void drmp3_L12_read_scalefactors(drmp3_bs *bs, drmp3_uint8 *pba, drmp3_uint8 *scfcod, int bands, float *scf)
+static void ma_dr_mp3_L12_read_scalefactors(ma_dr_mp3_bs *bs, ma_uint8 *pba, ma_uint8 *scfcod, int bands, float *scf)
{
static const float g_deq_L12[18*3] = {
-#define DRMP3_DQ(x) 9.53674316e-07f/x, 7.56931807e-07f/x, 6.00777173e-07f/x
- DRMP3_DQ(3),DRMP3_DQ(7),DRMP3_DQ(15),DRMP3_DQ(31),DRMP3_DQ(63),DRMP3_DQ(127),DRMP3_DQ(255),DRMP3_DQ(511),DRMP3_DQ(1023),DRMP3_DQ(2047),DRMP3_DQ(4095),DRMP3_DQ(8191),DRMP3_DQ(16383),DRMP3_DQ(32767),DRMP3_DQ(65535),DRMP3_DQ(3),DRMP3_DQ(5),DRMP3_DQ(9)
+#define MA_DR_MP3_DQ(x) 9.53674316e-07f/x, 7.56931807e-07f/x, 6.00777173e-07f/x
+ MA_DR_MP3_DQ(3),MA_DR_MP3_DQ(7),MA_DR_MP3_DQ(15),MA_DR_MP3_DQ(31),MA_DR_MP3_DQ(63),MA_DR_MP3_DQ(127),MA_DR_MP3_DQ(255),MA_DR_MP3_DQ(511),MA_DR_MP3_DQ(1023),MA_DR_MP3_DQ(2047),MA_DR_MP3_DQ(4095),MA_DR_MP3_DQ(8191),MA_DR_MP3_DQ(16383),MA_DR_MP3_DQ(32767),MA_DR_MP3_DQ(65535),MA_DR_MP3_DQ(3),MA_DR_MP3_DQ(5),MA_DR_MP3_DQ(9)
};
int i, m;
for (i = 0; i < bands; i++)
@@ -88245,16 +90156,16 @@ static void drmp3_L12_read_scalefactors(drmp3_bs *bs, drmp3_uint8 *pba, drmp3_ui
{
if (mask & m)
{
- int b = drmp3_bs_get_bits(bs, 6);
+ int b = ma_dr_mp3_bs_get_bits(bs, 6);
s = g_deq_L12[ba*3 - 6 + b % 3]*(int)(1 << 21 >> b/3);
}
*scf++ = s;
}
}
}
-static void drmp3_L12_read_scale_info(const drmp3_uint8 *hdr, drmp3_bs *bs, drmp3_L12_scale_info *sci)
+static void ma_dr_mp3_L12_read_scale_info(const ma_uint8 *hdr, ma_dr_mp3_bs *bs, ma_dr_mp3_L12_scale_info *sci)
{
- static const drmp3_uint8 g_bitalloc_code_tab[] = {
+ static const ma_uint8 g_bitalloc_code_tab[] = {
0,17, 3, 4, 5,6,7, 8,9,10,11,12,13,14,15,16,
0,17,18, 3,19,4,5, 6,7, 8, 9,10,11,12,13,16,
0,17,18, 3,19,4,5,16,
@@ -88263,12 +90174,12 @@ static void drmp3_L12_read_scale_info(const drmp3_uint8 *hdr, drmp3_bs *bs, drmp
0,17,18, 3,19,4,5, 6,7, 8, 9,10,11,12,13,14,
0, 2, 3, 4, 5,6,7, 8,9,10,11,12,13,14,15,16
};
- const drmp3_L12_subband_alloc *subband_alloc = drmp3_L12_subband_alloc_table(hdr, sci);
+ const ma_dr_mp3_L12_subband_alloc *subband_alloc = ma_dr_mp3_L12_subband_alloc_table(hdr, sci);
int i, k = 0, ba_bits = 0;
- const drmp3_uint8 *ba_code_tab = g_bitalloc_code_tab;
+ const ma_uint8 *ba_code_tab = g_bitalloc_code_tab;
for (i = 0; i < sci->total_bands; i++)
{
- drmp3_uint8 ba;
+ ma_uint8 ba;
if (i == k)
{
k += subband_alloc->band_count;
@@ -88276,25 +90187,25 @@ static void drmp3_L12_read_scale_info(const drmp3_uint8 *hdr, drmp3_bs *bs, drmp
ba_code_tab = g_bitalloc_code_tab + subband_alloc->tab_offset;
subband_alloc++;
}
- ba = ba_code_tab[drmp3_bs_get_bits(bs, ba_bits)];
+ ba = ba_code_tab[ma_dr_mp3_bs_get_bits(bs, ba_bits)];
sci->bitalloc[2*i] = ba;
if (i < sci->stereo_bands)
{
- ba = ba_code_tab[drmp3_bs_get_bits(bs, ba_bits)];
+ ba = ba_code_tab[ma_dr_mp3_bs_get_bits(bs, ba_bits)];
}
sci->bitalloc[2*i + 1] = sci->stereo_bands ? ba : 0;
}
for (i = 0; i < 2*sci->total_bands; i++)
{
- sci->scfcod[i] = (drmp3_uint8)(sci->bitalloc[i] ? DRMP3_HDR_IS_LAYER_1(hdr) ? 2 : drmp3_bs_get_bits(bs, 2) : 6);
+ sci->scfcod[i] = (ma_uint8)(sci->bitalloc[i] ? MA_DR_MP3_HDR_IS_LAYER_1(hdr) ? 2 : ma_dr_mp3_bs_get_bits(bs, 2) : 6);
}
- drmp3_L12_read_scalefactors(bs, sci->bitalloc, sci->scfcod, sci->total_bands*2, sci->scf);
+ ma_dr_mp3_L12_read_scalefactors(bs, sci->bitalloc, sci->scfcod, sci->total_bands*2, sci->scf);
for (i = sci->stereo_bands; i < sci->total_bands; i++)
{
sci->bitalloc[2*i + 1] = 0;
}
}
-static int drmp3_L12_dequantize_granule(float *grbuf, drmp3_bs *bs, drmp3_L12_scale_info *sci, int group_size)
+static int ma_dr_mp3_L12_dequantize_granule(float *grbuf, ma_dr_mp3_bs *bs, ma_dr_mp3_L12_scale_info *sci, int group_size)
{
int i, j, k, choff = 576;
for (j = 0; j < 4; j++)
@@ -88310,12 +90221,12 @@ static int drmp3_L12_dequantize_granule(float *grbuf, drmp3_bs *bs, drmp3_L12_sc
int half = (1 << (ba - 1)) - 1;
for (k = 0; k < group_size; k++)
{
- dst[k] = (float)((int)drmp3_bs_get_bits(bs, ba) - half);
+ dst[k] = (float)((int)ma_dr_mp3_bs_get_bits(bs, ba) - half);
}
} else
{
unsigned mod = (2 << (ba - 17)) + 1;
- unsigned code = drmp3_bs_get_bits(bs, mod + 2 - (mod >> 3));
+ unsigned code = ma_dr_mp3_bs_get_bits(bs, mod + 2 - (mod >> 3));
for (k = 0; k < group_size; k++, code /= mod)
{
dst[k] = (float)((int)(code % mod - mod/2));
@@ -88328,10 +90239,10 @@ static int drmp3_L12_dequantize_granule(float *grbuf, drmp3_bs *bs, drmp3_L12_sc
}
return group_size*4;
}
-static void drmp3_L12_apply_scf_384(drmp3_L12_scale_info *sci, const float *scf, float *dst)
+static void ma_dr_mp3_L12_apply_scf_384(ma_dr_mp3_L12_scale_info *sci, const float *scf, float *dst)
{
int i, k;
- DRMP3_COPY_MEMORY(dst + 576 + sci->stereo_bands*18, dst + sci->stereo_bands*18, (sci->total_bands - sci->stereo_bands)*18*sizeof(float));
+ MA_DR_MP3_COPY_MEMORY(dst + 576 + sci->stereo_bands*18, dst + sci->stereo_bands*18, (sci->total_bands - sci->stereo_bands)*18*sizeof(float));
for (i = 0; i < sci->total_bands; i++, dst += 18, scf += 6)
{
for (k = 0; k < 12; k++)
@@ -88342,9 +90253,9 @@ static void drmp3_L12_apply_scf_384(drmp3_L12_scale_info *sci, const float *scf,
}
}
#endif
-static int drmp3_L3_read_side_info(drmp3_bs *bs, drmp3_L3_gr_info *gr, const drmp3_uint8 *hdr)
+static int ma_dr_mp3_L3_read_side_info(ma_dr_mp3_bs *bs, ma_dr_mp3_L3_gr_info *gr, const ma_uint8 *hdr)
{
- static const drmp3_uint8 g_scf_long[8][23] = {
+ static const ma_uint8 g_scf_long[8][23] = {
{ 6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54,0 },
{ 12,12,12,12,12,12,16,20,24,28,32,40,48,56,64,76,90,2,2,2,2,2,0 },
{ 6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54,0 },
@@ -88354,7 +90265,7 @@ static int drmp3_L3_read_side_info(drmp3_bs *bs, drmp3_L3_gr_info *gr, const drm
{ 4,4,4,4,4,4,6,6,6,8,10,12,16,18,22,28,34,40,46,54,54,192,0 },
{ 4,4,4,4,4,4,6,6,8,10,12,16,20,24,30,38,46,56,68,84,102,26,0 }
};
- static const drmp3_uint8 g_scf_short[8][40] = {
+ static const ma_uint8 g_scf_short[8][40] = {
{ 4,4,4,4,4,4,4,4,4,6,6,6,8,8,8,10,10,10,12,12,12,14,14,14,18,18,18,24,24,24,30,30,30,40,40,40,18,18,18,0 },
{ 8,8,8,8,8,8,8,8,8,12,12,12,16,16,16,20,20,20,24,24,24,28,28,28,36,36,36,2,2,2,2,2,2,2,2,2,26,26,26,0 },
{ 4,4,4,4,4,4,4,4,4,6,6,6,6,6,6,8,8,8,10,10,10,14,14,14,18,18,18,26,26,26,32,32,32,42,42,42,18,18,18,0 },
@@ -88364,7 +90275,7 @@ static int drmp3_L3_read_side_info(drmp3_bs *bs, drmp3_L3_gr_info *gr, const drm
{ 4,4,4,4,4,4,4,4,4,4,4,4,6,6,6,6,6,6,10,10,10,12,12,12,14,14,14,16,16,16,20,20,20,26,26,26,66,66,66,0 },
{ 4,4,4,4,4,4,4,4,4,4,4,4,6,6,6,8,8,8,12,12,12,16,16,16,20,20,20,26,26,26,34,34,34,42,42,42,12,12,12,0 }
};
- static const drmp3_uint8 g_scf_mixed[8][40] = {
+ static const ma_uint8 g_scf_mixed[8][40] = {
{ 6,6,6,6,6,6,6,6,6,8,8,8,10,10,10,12,12,12,14,14,14,18,18,18,24,24,24,30,30,30,40,40,40,18,18,18,0 },
{ 12,12,12,4,4,4,8,8,8,12,12,12,16,16,16,20,20,20,24,24,24,28,28,28,36,36,36,2,2,2,2,2,2,2,2,2,26,26,26,0 },
{ 6,6,6,6,6,6,6,6,6,6,6,6,8,8,8,10,10,10,14,14,14,18,18,18,26,26,26,32,32,32,42,42,42,18,18,18,0 },
@@ -88376,46 +90287,46 @@ static int drmp3_L3_read_side_info(drmp3_bs *bs, drmp3_L3_gr_info *gr, const drm
};
unsigned tables, scfsi = 0;
int main_data_begin, part_23_sum = 0;
- int gr_count = DRMP3_HDR_IS_MONO(hdr) ? 1 : 2;
- int sr_idx = DRMP3_HDR_GET_MY_SAMPLE_RATE(hdr); sr_idx -= (sr_idx != 0);
- if (DRMP3_HDR_TEST_MPEG1(hdr))
+ int gr_count = MA_DR_MP3_HDR_IS_MONO(hdr) ? 1 : 2;
+ int sr_idx = MA_DR_MP3_HDR_GET_MY_SAMPLE_RATE(hdr); sr_idx -= (sr_idx != 0);
+ if (MA_DR_MP3_HDR_TEST_MPEG1(hdr))
{
gr_count *= 2;
- main_data_begin = drmp3_bs_get_bits(bs, 9);
- scfsi = drmp3_bs_get_bits(bs, 7 + gr_count);
+ main_data_begin = ma_dr_mp3_bs_get_bits(bs, 9);
+ scfsi = ma_dr_mp3_bs_get_bits(bs, 7 + gr_count);
} else
{
- main_data_begin = drmp3_bs_get_bits(bs, 8 + gr_count) >> gr_count;
+ main_data_begin = ma_dr_mp3_bs_get_bits(bs, 8 + gr_count) >> gr_count;
}
do
{
- if (DRMP3_HDR_IS_MONO(hdr))
+ if (MA_DR_MP3_HDR_IS_MONO(hdr))
{
scfsi <<= 4;
}
- gr->part_23_length = (drmp3_uint16)drmp3_bs_get_bits(bs, 12);
+ gr->part_23_length = (ma_uint16)ma_dr_mp3_bs_get_bits(bs, 12);
part_23_sum += gr->part_23_length;
- gr->big_values = (drmp3_uint16)drmp3_bs_get_bits(bs, 9);
+ gr->big_values = (ma_uint16)ma_dr_mp3_bs_get_bits(bs, 9);
if (gr->big_values > 288)
{
return -1;
}
- gr->global_gain = (drmp3_uint8)drmp3_bs_get_bits(bs, 8);
- gr->scalefac_compress = (drmp3_uint16)drmp3_bs_get_bits(bs, DRMP3_HDR_TEST_MPEG1(hdr) ? 4 : 9);
+ gr->global_gain = (ma_uint8)ma_dr_mp3_bs_get_bits(bs, 8);
+ gr->scalefac_compress = (ma_uint16)ma_dr_mp3_bs_get_bits(bs, MA_DR_MP3_HDR_TEST_MPEG1(hdr) ? 4 : 9);
gr->sfbtab = g_scf_long[sr_idx];
gr->n_long_sfb = 22;
gr->n_short_sfb = 0;
- if (drmp3_bs_get_bits(bs, 1))
+ if (ma_dr_mp3_bs_get_bits(bs, 1))
{
- gr->block_type = (drmp3_uint8)drmp3_bs_get_bits(bs, 2);
+ gr->block_type = (ma_uint8)ma_dr_mp3_bs_get_bits(bs, 2);
if (!gr->block_type)
{
return -1;
}
- gr->mixed_block_flag = (drmp3_uint8)drmp3_bs_get_bits(bs, 1);
+ gr->mixed_block_flag = (ma_uint8)ma_dr_mp3_bs_get_bits(bs, 1);
gr->region_count[0] = 7;
gr->region_count[1] = 255;
- if (gr->block_type == DRMP3_SHORT_BLOCK_TYPE)
+ if (gr->block_type == MA_DR_MP3_SHORT_BLOCK_TYPE)
{
scfsi &= 0x0F0F;
if (!gr->mixed_block_flag)
@@ -88427,31 +90338,31 @@ static int drmp3_L3_read_side_info(drmp3_bs *bs, drmp3_L3_gr_info *gr, const drm
} else
{
gr->sfbtab = g_scf_mixed[sr_idx];
- gr->n_long_sfb = DRMP3_HDR_TEST_MPEG1(hdr) ? 8 : 6;
+ gr->n_long_sfb = MA_DR_MP3_HDR_TEST_MPEG1(hdr) ? 8 : 6;
gr->n_short_sfb = 30;
}
}
- tables = drmp3_bs_get_bits(bs, 10);
+ tables = ma_dr_mp3_bs_get_bits(bs, 10);
tables <<= 5;
- gr->subblock_gain[0] = (drmp3_uint8)drmp3_bs_get_bits(bs, 3);
- gr->subblock_gain[1] = (drmp3_uint8)drmp3_bs_get_bits(bs, 3);
- gr->subblock_gain[2] = (drmp3_uint8)drmp3_bs_get_bits(bs, 3);
+ gr->subblock_gain[0] = (ma_uint8)ma_dr_mp3_bs_get_bits(bs, 3);
+ gr->subblock_gain[1] = (ma_uint8)ma_dr_mp3_bs_get_bits(bs, 3);
+ gr->subblock_gain[2] = (ma_uint8)ma_dr_mp3_bs_get_bits(bs, 3);
} else
{
gr->block_type = 0;
gr->mixed_block_flag = 0;
- tables = drmp3_bs_get_bits(bs, 15);
- gr->region_count[0] = (drmp3_uint8)drmp3_bs_get_bits(bs, 4);
- gr->region_count[1] = (drmp3_uint8)drmp3_bs_get_bits(bs, 3);
+ tables = ma_dr_mp3_bs_get_bits(bs, 15);
+ gr->region_count[0] = (ma_uint8)ma_dr_mp3_bs_get_bits(bs, 4);
+ gr->region_count[1] = (ma_uint8)ma_dr_mp3_bs_get_bits(bs, 3);
gr->region_count[2] = 255;
}
- gr->table_select[0] = (drmp3_uint8)(tables >> 10);
- gr->table_select[1] = (drmp3_uint8)((tables >> 5) & 31);
- gr->table_select[2] = (drmp3_uint8)((tables) & 31);
- gr->preflag = (drmp3_uint8)(DRMP3_HDR_TEST_MPEG1(hdr) ? drmp3_bs_get_bits(bs, 1) : (gr->scalefac_compress >= 500));
- gr->scalefac_scale = (drmp3_uint8)drmp3_bs_get_bits(bs, 1);
- gr->count1_table = (drmp3_uint8)drmp3_bs_get_bits(bs, 1);
- gr->scfsi = (drmp3_uint8)((scfsi >> 12) & 15);
+ gr->table_select[0] = (ma_uint8)(tables >> 10);
+ gr->table_select[1] = (ma_uint8)((tables >> 5) & 31);
+ gr->table_select[2] = (ma_uint8)((tables) & 31);
+ gr->preflag = (ma_uint8)(MA_DR_MP3_HDR_TEST_MPEG1(hdr) ? ma_dr_mp3_bs_get_bits(bs, 1) : (gr->scalefac_compress >= 500));
+ gr->scalefac_scale = (ma_uint8)ma_dr_mp3_bs_get_bits(bs, 1);
+ gr->count1_table = (ma_uint8)ma_dr_mp3_bs_get_bits(bs, 1);
+ gr->scfsi = (ma_uint8)((scfsi >> 12) & 15);
scfsi <<= 4;
gr++;
} while(--gr_count);
@@ -88461,7 +90372,7 @@ static int drmp3_L3_read_side_info(drmp3_bs *bs, drmp3_L3_gr_info *gr, const drm
}
return main_data_begin;
}
-static void drmp3_L3_read_scalefactors(drmp3_uint8 *scf, drmp3_uint8 *ist_pos, const drmp3_uint8 *scf_size, const drmp3_uint8 *scf_count, drmp3_bs *bitbuf, int scfsi)
+static void ma_dr_mp3_L3_read_scalefactors(ma_uint8 *scf, ma_uint8 *ist_pos, const ma_uint8 *scf_size, const ma_uint8 *scf_count, ma_dr_mp3_bs *bitbuf, int scfsi)
{
int i, k;
for (i = 0; i < 4 && scf_count[i]; i++, scfsi *= 2)
@@ -88469,22 +90380,22 @@ static void drmp3_L3_read_scalefactors(drmp3_uint8 *scf, drmp3_uint8 *ist_pos, c
int cnt = scf_count[i];
if (scfsi & 8)
{
- DRMP3_COPY_MEMORY(scf, ist_pos, cnt);
+ MA_DR_MP3_COPY_MEMORY(scf, ist_pos, cnt);
} else
{
int bits = scf_size[i];
if (!bits)
{
- DRMP3_ZERO_MEMORY(scf, cnt);
- DRMP3_ZERO_MEMORY(ist_pos, cnt);
+ MA_DR_MP3_ZERO_MEMORY(scf, cnt);
+ MA_DR_MP3_ZERO_MEMORY(ist_pos, cnt);
} else
{
int max_scf = (scfsi < 0) ? (1 << bits) - 1 : -1;
for (k = 0; k < cnt; k++)
{
- int s = drmp3_bs_get_bits(bitbuf, bits);
- ist_pos[k] = (drmp3_uint8)(s == max_scf ? -1 : s);
- scf[k] = (drmp3_uint8)s;
+ int s = ma_dr_mp3_bs_get_bits(bitbuf, bits);
+ ist_pos[k] = (ma_uint8)(s == max_scf ? -1 : s);
+ scf[k] = (ma_uint8)s;
}
}
}
@@ -88493,86 +90404,86 @@ static void drmp3_L3_read_scalefactors(drmp3_uint8 *scf, drmp3_uint8 *ist_pos, c
}
scf[0] = scf[1] = scf[2] = 0;
}
-static float drmp3_L3_ldexp_q2(float y, int exp_q2)
+static float ma_dr_mp3_L3_ldexp_q2(float y, int exp_q2)
{
static const float g_expfrac[4] = { 9.31322575e-10f,7.83145814e-10f,6.58544508e-10f,5.53767716e-10f };
int e;
do
{
- e = DRMP3_MIN(30*4, exp_q2);
+ e = MA_DR_MP3_MIN(30*4, exp_q2);
y *= g_expfrac[e & 3]*(1 << 30 >> (e >> 2));
} while ((exp_q2 -= e) > 0);
return y;
}
-static void drmp3_L3_decode_scalefactors(const drmp3_uint8 *hdr, drmp3_uint8 *ist_pos, drmp3_bs *bs, const drmp3_L3_gr_info *gr, float *scf, int ch)
+static void ma_dr_mp3_L3_decode_scalefactors(const ma_uint8 *hdr, ma_uint8 *ist_pos, ma_dr_mp3_bs *bs, const ma_dr_mp3_L3_gr_info *gr, float *scf, int ch)
{
- static const drmp3_uint8 g_scf_partitions[3][28] = {
+ static const ma_uint8 g_scf_partitions[3][28] = {
{ 6,5,5, 5,6,5,5,5,6,5, 7,3,11,10,0,0, 7, 7, 7,0, 6, 6,6,3, 8, 8,5,0 },
{ 8,9,6,12,6,9,9,9,6,9,12,6,15,18,0,0, 6,15,12,0, 6,12,9,6, 6,18,9,0 },
{ 9,9,6,12,9,9,9,9,9,9,12,6,18,18,0,0,12,12,12,0,12, 9,9,6,15,12,9,0 }
};
- const drmp3_uint8 *scf_partition = g_scf_partitions[!!gr->n_short_sfb + !gr->n_long_sfb];
- drmp3_uint8 scf_size[4], iscf[40];
+ const ma_uint8 *scf_partition = g_scf_partitions[!!gr->n_short_sfb + !gr->n_long_sfb];
+ ma_uint8 scf_size[4], iscf[40];
int i, scf_shift = gr->scalefac_scale + 1, gain_exp, scfsi = gr->scfsi;
float gain;
- if (DRMP3_HDR_TEST_MPEG1(hdr))
+ if (MA_DR_MP3_HDR_TEST_MPEG1(hdr))
{
- static const drmp3_uint8 g_scfc_decode[16] = { 0,1,2,3, 12,5,6,7, 9,10,11,13, 14,15,18,19 };
+ static const ma_uint8 g_scfc_decode[16] = { 0,1,2,3, 12,5,6,7, 9,10,11,13, 14,15,18,19 };
int part = g_scfc_decode[gr->scalefac_compress];
- scf_size[1] = scf_size[0] = (drmp3_uint8)(part >> 2);
- scf_size[3] = scf_size[2] = (drmp3_uint8)(part & 3);
+ scf_size[1] = scf_size[0] = (ma_uint8)(part >> 2);
+ scf_size[3] = scf_size[2] = (ma_uint8)(part & 3);
} else
{
- static const drmp3_uint8 g_mod[6*4] = { 5,5,4,4,5,5,4,1,4,3,1,1,5,6,6,1,4,4,4,1,4,3,1,1 };
- int k, modprod, sfc, ist = DRMP3_HDR_TEST_I_STEREO(hdr) && ch;
+ static const ma_uint8 g_mod[6*4] = { 5,5,4,4,5,5,4,1,4,3,1,1,5,6,6,1,4,4,4,1,4,3,1,1 };
+ int k, modprod, sfc, ist = MA_DR_MP3_HDR_TEST_I_STEREO(hdr) && ch;
sfc = gr->scalefac_compress >> ist;
for (k = ist*3*4; sfc >= 0; sfc -= modprod, k += 4)
{
for (modprod = 1, i = 3; i >= 0; i--)
{
- scf_size[i] = (drmp3_uint8)(sfc / modprod % g_mod[k + i]);
+ scf_size[i] = (ma_uint8)(sfc / modprod % g_mod[k + i]);
modprod *= g_mod[k + i];
}
}
scf_partition += k;
scfsi = -16;
}
- drmp3_L3_read_scalefactors(iscf, ist_pos, scf_size, scf_partition, bs, scfsi);
+ ma_dr_mp3_L3_read_scalefactors(iscf, ist_pos, scf_size, scf_partition, bs, scfsi);
if (gr->n_short_sfb)
{
int sh = 3 - scf_shift;
for (i = 0; i < gr->n_short_sfb; i += 3)
{
- iscf[gr->n_long_sfb + i + 0] = (drmp3_uint8)(iscf[gr->n_long_sfb + i + 0] + (gr->subblock_gain[0] << sh));
- iscf[gr->n_long_sfb + i + 1] = (drmp3_uint8)(iscf[gr->n_long_sfb + i + 1] + (gr->subblock_gain[1] << sh));
- iscf[gr->n_long_sfb + i + 2] = (drmp3_uint8)(iscf[gr->n_long_sfb + i + 2] + (gr->subblock_gain[2] << sh));
+ iscf[gr->n_long_sfb + i + 0] = (ma_uint8)(iscf[gr->n_long_sfb + i + 0] + (gr->subblock_gain[0] << sh));
+ iscf[gr->n_long_sfb + i + 1] = (ma_uint8)(iscf[gr->n_long_sfb + i + 1] + (gr->subblock_gain[1] << sh));
+ iscf[gr->n_long_sfb + i + 2] = (ma_uint8)(iscf[gr->n_long_sfb + i + 2] + (gr->subblock_gain[2] << sh));
}
} else if (gr->preflag)
{
- static const drmp3_uint8 g_preamp[10] = { 1,1,1,1,2,2,3,3,3,2 };
+ static const ma_uint8 g_preamp[10] = { 1,1,1,1,2,2,3,3,3,2 };
for (i = 0; i < 10; i++)
{
- iscf[11 + i] = (drmp3_uint8)(iscf[11 + i] + g_preamp[i]);
+ iscf[11 + i] = (ma_uint8)(iscf[11 + i] + g_preamp[i]);
}
}
- gain_exp = gr->global_gain + DRMP3_BITS_DEQUANTIZER_OUT*4 - 210 - (DRMP3_HDR_IS_MS_STEREO(hdr) ? 2 : 0);
- gain = drmp3_L3_ldexp_q2(1 << (DRMP3_MAX_SCFI/4), DRMP3_MAX_SCFI - gain_exp);
+ gain_exp = gr->global_gain + MA_DR_MP3_BITS_DEQUANTIZER_OUT*4 - 210 - (MA_DR_MP3_HDR_IS_MS_STEREO(hdr) ? 2 : 0);
+ gain = ma_dr_mp3_L3_ldexp_q2(1 << (MA_DR_MP3_MAX_SCFI/4), MA_DR_MP3_MAX_SCFI - gain_exp);
for (i = 0; i < (int)(gr->n_long_sfb + gr->n_short_sfb); i++)
{
- scf[i] = drmp3_L3_ldexp_q2(gain, iscf[i] << scf_shift);
+ scf[i] = ma_dr_mp3_L3_ldexp_q2(gain, iscf[i] << scf_shift);
}
}
-static const float g_drmp3_pow43[129 + 16] = {
+static const float g_ma_dr_mp3_pow43[129 + 16] = {
0,-1,-2.519842f,-4.326749f,-6.349604f,-8.549880f,-10.902724f,-13.390518f,-16.000000f,-18.720754f,-21.544347f,-24.463781f,-27.473142f,-30.567351f,-33.741992f,-36.993181f,
0,1,2.519842f,4.326749f,6.349604f,8.549880f,10.902724f,13.390518f,16.000000f,18.720754f,21.544347f,24.463781f,27.473142f,30.567351f,33.741992f,36.993181f,40.317474f,43.711787f,47.173345f,50.699631f,54.288352f,57.937408f,61.644865f,65.408941f,69.227979f,73.100443f,77.024898f,81.000000f,85.024491f,89.097188f,93.216975f,97.382800f,101.593667f,105.848633f,110.146801f,114.487321f,118.869381f,123.292209f,127.755065f,132.257246f,136.798076f,141.376907f,145.993119f,150.646117f,155.335327f,160.060199f,164.820202f,169.614826f,174.443577f,179.305980f,184.201575f,189.129918f,194.090580f,199.083145f,204.107210f,209.162385f,214.248292f,219.364564f,224.510845f,229.686789f,234.892058f,240.126328f,245.389280f,250.680604f,256.000000f,261.347174f,266.721841f,272.123723f,277.552547f,283.008049f,288.489971f,293.998060f,299.532071f,305.091761f,310.676898f,316.287249f,321.922592f,327.582707f,333.267377f,338.976394f,344.709550f,350.466646f,356.247482f,362.051866f,367.879608f,373.730522f,379.604427f,385.501143f,391.420496f,397.362314f,403.326427f,409.312672f,415.320884f,421.350905f,427.402579f,433.475750f,439.570269f,445.685987f,451.822757f,457.980436f,464.158883f,470.357960f,476.577530f,482.817459f,489.077615f,495.357868f,501.658090f,507.978156f,514.317941f,520.677324f,527.056184f,533.454404f,539.871867f,546.308458f,552.764065f,559.238575f,565.731879f,572.243870f,578.774440f,585.323483f,591.890898f,598.476581f,605.080431f,611.702349f,618.342238f,625.000000f,631.675540f,638.368763f,645.079578f
};
-static float drmp3_L3_pow_43(int x)
+static float ma_dr_mp3_L3_pow_43(int x)
{
float frac;
int sign, mult = 256;
if (x < 129)
{
- return g_drmp3_pow43[16 + x];
+ return g_ma_dr_mp3_pow43[16 + x];
}
if (x < 1024)
{
@@ -88581,11 +90492,11 @@ static float drmp3_L3_pow_43(int x)
}
sign = 2*x & 64;
frac = (float)((x & 63) - sign) / ((x & ~63) + sign);
- return g_drmp3_pow43[16 + ((x + sign) >> 6)]*(1.f + frac*((4.f/3) + frac*(2.f/9)))*mult;
+ return g_ma_dr_mp3_pow43[16 + ((x + sign) >> 6)]*(1.f + frac*((4.f/3) + frac*(2.f/9)))*mult;
}
-static void drmp3_L3_huffman(float *dst, drmp3_bs *bs, const drmp3_L3_gr_info *gr_info, const float *scf, int layer3gr_limit)
+static void ma_dr_mp3_L3_huffman(float *dst, ma_dr_mp3_bs *bs, const ma_dr_mp3_L3_gr_info *gr_info, const float *scf, int layer3gr_limit)
{
- static const drmp3_int16 tabs[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ static const ma_int16 tabs[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
785,785,785,785,784,784,784,784,513,513,513,513,513,513,513,513,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,
-255,1313,1298,1282,785,785,785,785,784,784,784,784,769,769,769,769,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,290,288,
-255,1313,1298,1282,769,769,769,769,529,529,529,529,529,529,529,529,528,528,528,528,528,528,528,528,512,512,512,512,512,512,512,512,290,288,
@@ -88601,61 +90512,61 @@ static void drmp3_L3_huffman(float *dst, drmp3_bs *bs, const drmp3_L3_gr_info *g
-250,-1179,-1579,-1836,-1996,-2124,-2253,-2333,-2413,-2477,-2542,-2574,-2607,-2622,-2655,1314,1313,1298,1312,1282,785,785,785,785,1040,1040,1025,1025,768,768,768,768,-766,-798,-830,-862,-895,-911,-927,-943,-959,-975,-991,-1007,-1023,-1039,-1055,-1070,1724,1647,-1103,-1119,1631,1767,1662,1738,1708,1723,-1135,1780,1615,1779,1599,1677,1646,1778,1583,-1151,1777,1567,1737,1692,1765,1722,1707,1630,1751,1661,1764,1614,1736,1676,1763,1750,1645,1598,1721,1691,1762,1706,1582,1761,1566,-1167,1749,1629,767,766,751,765,494,494,735,764,719,749,734,763,447,447,748,718,477,506,431,491,446,476,461,505,415,430,475,445,504,399,460,489,414,503,383,474,429,459,502,502,746,752,488,398,501,473,413,472,486,271,480,270,-1439,-1455,1357,-1471,-1487,-1503,1341,1325,-1519,1489,1463,1403,1309,-1535,1372,1448,1418,1476,1356,1462,1387,-1551,1475,1340,1447,1402,1386,-1567,1068,1068,1474,1461,455,380,468,440,395,425,410,454,364,467,466,464,453,269,409,448,268,432,1371,1473,1432,1417,1308,1460,1355,1446,1459,1431,1083,1083,1401,1416,1458,1445,1067,1067,1370,1457,1051,1051,1291,1430,1385,1444,1354,1415,1400,1443,1082,1082,1173,1113,1186,1066,1185,1050,-1967,1158,1128,1172,1097,1171,1081,-1983,1157,1112,416,266,375,400,1170,1142,1127,1065,793,793,1169,1033,1156,1096,1141,1111,1155,1080,1126,1140,898,898,808,808,897,897,792,792,1095,1152,1032,1125,1110,1139,1079,1124,882,807,838,881,853,791,-2319,867,368,263,822,852,837,866,806,865,-2399,851,352,262,534,534,821,836,594,594,549,549,593,593,533,533,848,773,579,579,564,578,548,563,276,276,577,576,306,291,516,560,305,305,275,259,
-251,-892,-2058,-2620,-2828,-2957,-3023,-3039,1041,1041,1040,1040,769,769,769,769,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,-511,-527,-543,-559,1530,-575,-591,1528,1527,1407,1526,1391,1023,1023,1023,1023,1525,1375,1268,1268,1103,1103,1087,1087,1039,1039,1523,-604,815,815,815,815,510,495,509,479,508,463,507,447,431,505,415,399,-734,-782,1262,-815,1259,1244,-831,1258,1228,-847,-863,1196,-879,1253,987,987,748,-767,493,493,462,477,414,414,686,669,478,446,461,445,474,429,487,458,412,471,1266,1264,1009,1009,799,799,-1019,-1276,-1452,-1581,-1677,-1757,-1821,-1886,-1933,-1997,1257,1257,1483,1468,1512,1422,1497,1406,1467,1496,1421,1510,1134,1134,1225,1225,1466,1451,1374,1405,1252,1252,1358,1480,1164,1164,1251,1251,1238,1238,1389,1465,-1407,1054,1101,-1423,1207,-1439,830,830,1248,1038,1237,1117,1223,1148,1236,1208,411,426,395,410,379,269,1193,1222,1132,1235,1221,1116,976,976,1192,1162,1177,1220,1131,1191,963,963,-1647,961,780,-1663,558,558,994,993,437,408,393,407,829,978,813,797,947,-1743,721,721,377,392,844,950,828,890,706,706,812,859,796,960,948,843,934,874,571,571,-1919,690,555,689,421,346,539,539,944,779,918,873,932,842,903,888,570,570,931,917,674,674,-2575,1562,-2591,1609,-2607,1654,1322,1322,1441,1441,1696,1546,1683,1593,1669,1624,1426,1426,1321,1321,1639,1680,1425,1425,1305,1305,1545,1668,1608,1623,1667,1592,1638,1666,1320,1320,1652,1607,1409,1409,1304,1304,1288,1288,1664,1637,1395,1395,1335,1335,1622,1636,1394,1394,1319,1319,1606,1621,1392,1392,1137,1137,1137,1137,345,390,360,375,404,373,1047,-2751,-2767,-2783,1062,1121,1046,-2799,1077,-2815,1106,1061,789,789,1105,1104,263,355,310,340,325,354,352,262,339,324,1091,1076,1029,1090,1060,1075,833,833,788,788,1088,1028,818,818,803,803,561,561,531,531,816,771,546,546,289,274,288,258,
-253,-317,-381,-446,-478,-509,1279,1279,-811,-1179,-1451,-1756,-1900,-2028,-2189,-2253,-2333,-2414,-2445,-2511,-2526,1313,1298,-2559,1041,1041,1040,1040,1025,1025,1024,1024,1022,1007,1021,991,1020,975,1019,959,687,687,1018,1017,671,671,655,655,1016,1015,639,639,758,758,623,623,757,607,756,591,755,575,754,559,543,543,1009,783,-575,-621,-685,-749,496,-590,750,749,734,748,974,989,1003,958,988,973,1002,942,987,957,972,1001,926,986,941,971,956,1000,910,985,925,999,894,970,-1071,-1087,-1102,1390,-1135,1436,1509,1451,1374,-1151,1405,1358,1480,1420,-1167,1507,1494,1389,1342,1465,1435,1450,1326,1505,1310,1493,1373,1479,1404,1492,1464,1419,428,443,472,397,736,526,464,464,486,457,442,471,484,482,1357,1449,1434,1478,1388,1491,1341,1490,1325,1489,1463,1403,1309,1477,1372,1448,1418,1433,1476,1356,1462,1387,-1439,1475,1340,1447,1402,1474,1324,1461,1371,1473,269,448,1432,1417,1308,1460,-1711,1459,-1727,1441,1099,1099,1446,1386,1431,1401,-1743,1289,1083,1083,1160,1160,1458,1445,1067,1067,1370,1457,1307,1430,1129,1129,1098,1098,268,432,267,416,266,400,-1887,1144,1187,1082,1173,1113,1186,1066,1050,1158,1128,1143,1172,1097,1171,1081,420,391,1157,1112,1170,1142,1127,1065,1169,1049,1156,1096,1141,1111,1155,1080,1126,1154,1064,1153,1140,1095,1048,-2159,1125,1110,1137,-2175,823,823,1139,1138,807,807,384,264,368,263,868,838,853,791,867,822,852,837,866,806,865,790,-2319,851,821,836,352,262,850,805,849,-2399,533,533,835,820,336,261,578,548,563,577,532,532,832,772,562,562,547,547,305,275,560,515,290,290,288,258 };
- static const drmp3_uint8 tab32[] = { 130,162,193,209,44,28,76,140,9,9,9,9,9,9,9,9,190,254,222,238,126,94,157,157,109,61,173,205};
- static const drmp3_uint8 tab33[] = { 252,236,220,204,188,172,156,140,124,108,92,76,60,44,28,12 };
- static const drmp3_int16 tabindex[2*16] = { 0,32,64,98,0,132,180,218,292,364,426,538,648,746,0,1126,1460,1460,1460,1460,1460,1460,1460,1460,1842,1842,1842,1842,1842,1842,1842,1842 };
- static const drmp3_uint8 g_linbits[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,4,6,8,10,13,4,5,6,7,8,9,11,13 };
-#define DRMP3_PEEK_BITS(n) (bs_cache >> (32 - (n)))
-#define DRMP3_FLUSH_BITS(n) { bs_cache <<= (n); bs_sh += (n); }
-#define DRMP3_CHECK_BITS while (bs_sh >= 0) { bs_cache |= (drmp3_uint32)*bs_next_ptr++ << bs_sh; bs_sh -= 8; }
-#define DRMP3_BSPOS ((bs_next_ptr - bs->buf)*8 - 24 + bs_sh)
+ static const ma_uint8 tab32[] = { 130,162,193,209,44,28,76,140,9,9,9,9,9,9,9,9,190,254,222,238,126,94,157,157,109,61,173,205};
+ static const ma_uint8 tab33[] = { 252,236,220,204,188,172,156,140,124,108,92,76,60,44,28,12 };
+ static const ma_int16 tabindex[2*16] = { 0,32,64,98,0,132,180,218,292,364,426,538,648,746,0,1126,1460,1460,1460,1460,1460,1460,1460,1460,1842,1842,1842,1842,1842,1842,1842,1842 };
+ static const ma_uint8 g_linbits[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,4,6,8,10,13,4,5,6,7,8,9,11,13 };
+#define MA_DR_MP3_PEEK_BITS(n) (bs_cache >> (32 - (n)))
+#define MA_DR_MP3_FLUSH_BITS(n) { bs_cache <<= (n); bs_sh += (n); }
+#define MA_DR_MP3_CHECK_BITS while (bs_sh >= 0) { bs_cache |= (ma_uint32)*bs_next_ptr++ << bs_sh; bs_sh -= 8; }
+#define MA_DR_MP3_BSPOS ((bs_next_ptr - bs->buf)*8 - 24 + bs_sh)
float one = 0.0f;
int ireg = 0, big_val_cnt = gr_info->big_values;
- const drmp3_uint8 *sfb = gr_info->sfbtab;
- const drmp3_uint8 *bs_next_ptr = bs->buf + bs->pos/8;
- drmp3_uint32 bs_cache = (((bs_next_ptr[0]*256u + bs_next_ptr[1])*256u + bs_next_ptr[2])*256u + bs_next_ptr[3]) << (bs->pos & 7);
+ const ma_uint8 *sfb = gr_info->sfbtab;
+ const ma_uint8 *bs_next_ptr = bs->buf + bs->pos/8;
+ ma_uint32 bs_cache = (((bs_next_ptr[0]*256u + bs_next_ptr[1])*256u + bs_next_ptr[2])*256u + bs_next_ptr[3]) << (bs->pos & 7);
int pairs_to_decode, np, bs_sh = (bs->pos & 7) - 8;
bs_next_ptr += 4;
while (big_val_cnt > 0)
{
int tab_num = gr_info->table_select[ireg];
int sfb_cnt = gr_info->region_count[ireg++];
- const drmp3_int16 *codebook = tabs + tabindex[tab_num];
+ const ma_int16 *codebook = tabs + tabindex[tab_num];
int linbits = g_linbits[tab_num];
if (linbits)
{
do
{
np = *sfb++ / 2;
- pairs_to_decode = DRMP3_MIN(big_val_cnt, np);
+ pairs_to_decode = MA_DR_MP3_MIN(big_val_cnt, np);
one = *scf++;
do
{
int j, w = 5;
- int leaf = codebook[DRMP3_PEEK_BITS(w)];
+ int leaf = codebook[MA_DR_MP3_PEEK_BITS(w)];
while (leaf < 0)
{
- DRMP3_FLUSH_BITS(w);
+ MA_DR_MP3_FLUSH_BITS(w);
w = leaf & 7;
- leaf = codebook[DRMP3_PEEK_BITS(w) - (leaf >> 3)];
+ leaf = codebook[MA_DR_MP3_PEEK_BITS(w) - (leaf >> 3)];
}
- DRMP3_FLUSH_BITS(leaf >> 8);
+ MA_DR_MP3_FLUSH_BITS(leaf >> 8);
for (j = 0; j < 2; j++, dst++, leaf >>= 4)
{
int lsb = leaf & 0x0F;
if (lsb == 15)
{
- lsb += DRMP3_PEEK_BITS(linbits);
- DRMP3_FLUSH_BITS(linbits);
- DRMP3_CHECK_BITS;
- *dst = one*drmp3_L3_pow_43(lsb)*((drmp3_int32)bs_cache < 0 ? -1: 1);
+ lsb += MA_DR_MP3_PEEK_BITS(linbits);
+ MA_DR_MP3_FLUSH_BITS(linbits);
+ MA_DR_MP3_CHECK_BITS;
+ *dst = one*ma_dr_mp3_L3_pow_43(lsb)*((ma_int32)bs_cache < 0 ? -1: 1);
} else
{
- *dst = g_drmp3_pow43[16 + lsb - 16*(bs_cache >> 31)]*one;
+ *dst = g_ma_dr_mp3_pow43[16 + lsb - 16*(bs_cache >> 31)]*one;
}
- DRMP3_FLUSH_BITS(lsb ? 1 : 0);
+ MA_DR_MP3_FLUSH_BITS(lsb ? 1 : 0);
}
- DRMP3_CHECK_BITS;
+ MA_DR_MP3_CHECK_BITS;
} while (--pairs_to_decode);
} while ((big_val_cnt -= np) > 0 && --sfb_cnt >= 0);
} else
@@ -88663,68 +90574,68 @@ static void drmp3_L3_huffman(float *dst, drmp3_bs *bs, const drmp3_L3_gr_info *g
do
{
np = *sfb++ / 2;
- pairs_to_decode = DRMP3_MIN(big_val_cnt, np);
+ pairs_to_decode = MA_DR_MP3_MIN(big_val_cnt, np);
one = *scf++;
do
{
int j, w = 5;
- int leaf = codebook[DRMP3_PEEK_BITS(w)];
+ int leaf = codebook[MA_DR_MP3_PEEK_BITS(w)];
while (leaf < 0)
{
- DRMP3_FLUSH_BITS(w);
+ MA_DR_MP3_FLUSH_BITS(w);
w = leaf & 7;
- leaf = codebook[DRMP3_PEEK_BITS(w) - (leaf >> 3)];
+ leaf = codebook[MA_DR_MP3_PEEK_BITS(w) - (leaf >> 3)];
}
- DRMP3_FLUSH_BITS(leaf >> 8);
+ MA_DR_MP3_FLUSH_BITS(leaf >> 8);
for (j = 0; j < 2; j++, dst++, leaf >>= 4)
{
int lsb = leaf & 0x0F;
- *dst = g_drmp3_pow43[16 + lsb - 16*(bs_cache >> 31)]*one;
- DRMP3_FLUSH_BITS(lsb ? 1 : 0);
+ *dst = g_ma_dr_mp3_pow43[16 + lsb - 16*(bs_cache >> 31)]*one;
+ MA_DR_MP3_FLUSH_BITS(lsb ? 1 : 0);
}
- DRMP3_CHECK_BITS;
+ MA_DR_MP3_CHECK_BITS;
} while (--pairs_to_decode);
} while ((big_val_cnt -= np) > 0 && --sfb_cnt >= 0);
}
}
for (np = 1 - big_val_cnt;; dst += 4)
{
- const drmp3_uint8 *codebook_count1 = (gr_info->count1_table) ? tab33 : tab32;
- int leaf = codebook_count1[DRMP3_PEEK_BITS(4)];
+ const ma_uint8 *codebook_count1 = (gr_info->count1_table) ? tab33 : tab32;
+ int leaf = codebook_count1[MA_DR_MP3_PEEK_BITS(4)];
if (!(leaf & 8))
{
leaf = codebook_count1[(leaf >> 3) + (bs_cache << 4 >> (32 - (leaf & 3)))];
}
- DRMP3_FLUSH_BITS(leaf & 7);
- if (DRMP3_BSPOS > layer3gr_limit)
+ MA_DR_MP3_FLUSH_BITS(leaf & 7);
+ if (MA_DR_MP3_BSPOS > layer3gr_limit)
{
break;
}
-#define DRMP3_RELOAD_SCALEFACTOR if (!--np) { np = *sfb++/2; if (!np) break; one = *scf++; }
-#define DRMP3_DEQ_COUNT1(s) if (leaf & (128 >> s)) { dst[s] = ((drmp3_int32)bs_cache < 0) ? -one : one; DRMP3_FLUSH_BITS(1) }
- DRMP3_RELOAD_SCALEFACTOR;
- DRMP3_DEQ_COUNT1(0);
- DRMP3_DEQ_COUNT1(1);
- DRMP3_RELOAD_SCALEFACTOR;
- DRMP3_DEQ_COUNT1(2);
- DRMP3_DEQ_COUNT1(3);
- DRMP3_CHECK_BITS;
+#define MA_DR_MP3_RELOAD_SCALEFACTOR if (!--np) { np = *sfb++/2; if (!np) break; one = *scf++; }
+#define MA_DR_MP3_DEQ_COUNT1(s) if (leaf & (128 >> s)) { dst[s] = ((ma_int32)bs_cache < 0) ? -one : one; MA_DR_MP3_FLUSH_BITS(1) }
+ MA_DR_MP3_RELOAD_SCALEFACTOR;
+ MA_DR_MP3_DEQ_COUNT1(0);
+ MA_DR_MP3_DEQ_COUNT1(1);
+ MA_DR_MP3_RELOAD_SCALEFACTOR;
+ MA_DR_MP3_DEQ_COUNT1(2);
+ MA_DR_MP3_DEQ_COUNT1(3);
+ MA_DR_MP3_CHECK_BITS;
}
bs->pos = layer3gr_limit;
}
-static void drmp3_L3_midside_stereo(float *left, int n)
+static void ma_dr_mp3_L3_midside_stereo(float *left, int n)
{
int i = 0;
float *right = left + 576;
-#if DRMP3_HAVE_SIMD
- if (drmp3_have_simd())
+#if MA_DR_MP3_HAVE_SIMD
+ if (ma_dr_mp3_have_simd())
{
for (; i < n - 3; i += 4)
{
- drmp3_f4 vl = DRMP3_VLD(left + i);
- drmp3_f4 vr = DRMP3_VLD(right + i);
- DRMP3_VSTORE(left + i, DRMP3_VADD(vl, vr));
- DRMP3_VSTORE(right + i, DRMP3_VSUB(vl, vr));
+ ma_dr_mp3_f4 vl = MA_DR_MP3_VLD(left + i);
+ ma_dr_mp3_f4 vr = MA_DR_MP3_VLD(right + i);
+ MA_DR_MP3_VSTORE(left + i, MA_DR_MP3_VADD(vl, vr));
+ MA_DR_MP3_VSTORE(right + i, MA_DR_MP3_VSUB(vl, vr));
}
#ifdef __GNUC__
if (__builtin_constant_p(n % 4 == 0) && n % 4 == 0)
@@ -88740,7 +90651,7 @@ static void drmp3_L3_midside_stereo(float *left, int n)
right[i] = a - b;
}
}
-static void drmp3_L3_intensity_stereo_band(float *left, int n, float kl, float kr)
+static void ma_dr_mp3_L3_intensity_stereo_band(float *left, int n, float kl, float kr)
{
int i;
for (i = 0; i < n; i++)
@@ -88749,7 +90660,7 @@ static void drmp3_L3_intensity_stereo_band(float *left, int n, float kl, float k
left[i] = left[i]*kl;
}
}
-static void drmp3_L3_stereo_top_band(const float *right, const drmp3_uint8 *sfb, int nbands, int max_band[3])
+static void ma_dr_mp3_L3_stereo_top_band(const float *right, const ma_uint8 *sfb, int nbands, int max_band[3])
{
int i, k;
max_band[0] = max_band[1] = max_band[2] = -1;
@@ -88766,57 +90677,57 @@ static void drmp3_L3_stereo_top_band(const float *right, const drmp3_uint8 *sfb,
right += sfb[i];
}
}
-static void drmp3_L3_stereo_process(float *left, const drmp3_uint8 *ist_pos, const drmp3_uint8 *sfb, const drmp3_uint8 *hdr, int max_band[3], int mpeg2_sh)
+static void ma_dr_mp3_L3_stereo_process(float *left, const ma_uint8 *ist_pos, const ma_uint8 *sfb, const ma_uint8 *hdr, int max_band[3], int mpeg2_sh)
{
static const float g_pan[7*2] = { 0,1,0.21132487f,0.78867513f,0.36602540f,0.63397460f,0.5f,0.5f,0.63397460f,0.36602540f,0.78867513f,0.21132487f,1,0 };
- unsigned i, max_pos = DRMP3_HDR_TEST_MPEG1(hdr) ? 7 : 64;
+ unsigned i, max_pos = MA_DR_MP3_HDR_TEST_MPEG1(hdr) ? 7 : 64;
for (i = 0; sfb[i]; i++)
{
unsigned ipos = ist_pos[i];
if ((int)i > max_band[i % 3] && ipos < max_pos)
{
- float kl, kr, s = DRMP3_HDR_TEST_MS_STEREO(hdr) ? 1.41421356f : 1;
- if (DRMP3_HDR_TEST_MPEG1(hdr))
+ float kl, kr, s = MA_DR_MP3_HDR_TEST_MS_STEREO(hdr) ? 1.41421356f : 1;
+ if (MA_DR_MP3_HDR_TEST_MPEG1(hdr))
{
kl = g_pan[2*ipos];
kr = g_pan[2*ipos + 1];
} else
{
kl = 1;
- kr = drmp3_L3_ldexp_q2(1, (ipos + 1) >> 1 << mpeg2_sh);
+ kr = ma_dr_mp3_L3_ldexp_q2(1, (ipos + 1) >> 1 << mpeg2_sh);
if (ipos & 1)
{
kl = kr;
kr = 1;
}
}
- drmp3_L3_intensity_stereo_band(left, sfb[i], kl*s, kr*s);
- } else if (DRMP3_HDR_TEST_MS_STEREO(hdr))
+ ma_dr_mp3_L3_intensity_stereo_band(left, sfb[i], kl*s, kr*s);
+ } else if (MA_DR_MP3_HDR_TEST_MS_STEREO(hdr))
{
- drmp3_L3_midside_stereo(left, sfb[i]);
+ ma_dr_mp3_L3_midside_stereo(left, sfb[i]);
}
left += sfb[i];
}
}
-static void drmp3_L3_intensity_stereo(float *left, drmp3_uint8 *ist_pos, const drmp3_L3_gr_info *gr, const drmp3_uint8 *hdr)
+static void ma_dr_mp3_L3_intensity_stereo(float *left, ma_uint8 *ist_pos, const ma_dr_mp3_L3_gr_info *gr, const ma_uint8 *hdr)
{
int max_band[3], n_sfb = gr->n_long_sfb + gr->n_short_sfb;
int i, max_blocks = gr->n_short_sfb ? 3 : 1;
- drmp3_L3_stereo_top_band(left + 576, gr->sfbtab, n_sfb, max_band);
+ ma_dr_mp3_L3_stereo_top_band(left + 576, gr->sfbtab, n_sfb, max_band);
if (gr->n_long_sfb)
{
- max_band[0] = max_band[1] = max_band[2] = DRMP3_MAX(DRMP3_MAX(max_band[0], max_band[1]), max_band[2]);
+ max_band[0] = max_band[1] = max_band[2] = MA_DR_MP3_MAX(MA_DR_MP3_MAX(max_band[0], max_band[1]), max_band[2]);
}
for (i = 0; i < max_blocks; i++)
{
- int default_pos = DRMP3_HDR_TEST_MPEG1(hdr) ? 3 : 0;
+ int default_pos = MA_DR_MP3_HDR_TEST_MPEG1(hdr) ? 3 : 0;
int itop = n_sfb - max_blocks + i;
int prev = itop - max_blocks;
- ist_pos[itop] = (drmp3_uint8)(max_band[i] >= prev ? default_pos : ist_pos[prev]);
+ ist_pos[itop] = (ma_uint8)(max_band[i] >= prev ? default_pos : ist_pos[prev]);
}
- drmp3_L3_stereo_process(left, ist_pos, gr->sfbtab, hdr, max_band, gr[1].scalefac_compress & 1);
+ ma_dr_mp3_L3_stereo_process(left, ist_pos, gr->sfbtab, hdr, max_band, gr[1].scalefac_compress & 1);
}
-static void drmp3_L3_reorder(float *grbuf, float *scratch, const drmp3_uint8 *sfb)
+static void ma_dr_mp3_L3_reorder(float *grbuf, float *scratch, const ma_uint8 *sfb)
{
int i, len;
float *src = grbuf, *dst = scratch;
@@ -88829,9 +90740,9 @@ static void drmp3_L3_reorder(float *grbuf, float *scratch, const drmp3_uint8 *sf
*dst++ = src[2*len];
}
}
- DRMP3_COPY_MEMORY(grbuf, scratch, (dst - scratch)*sizeof(float));
+ MA_DR_MP3_COPY_MEMORY(grbuf, scratch, (dst - scratch)*sizeof(float));
}
-static void drmp3_L3_antialias(float *grbuf, int nbands)
+static void ma_dr_mp3_L3_antialias(float *grbuf, int nbands)
{
static const float g_aa[2][8] = {
{0.85749293f,0.88174200f,0.94962865f,0.98331459f,0.99551782f,0.99916056f,0.99989920f,0.99999316f},
@@ -88840,20 +90751,20 @@ static void drmp3_L3_antialias(float *grbuf, int nbands)
for (; nbands > 0; nbands--, grbuf += 18)
{
int i = 0;
-#if DRMP3_HAVE_SIMD
- if (drmp3_have_simd()) for (; i < 8; i += 4)
+#if MA_DR_MP3_HAVE_SIMD
+ if (ma_dr_mp3_have_simd()) for (; i < 8; i += 4)
{
- drmp3_f4 vu = DRMP3_VLD(grbuf + 18 + i);
- drmp3_f4 vd = DRMP3_VLD(grbuf + 14 - i);
- drmp3_f4 vc0 = DRMP3_VLD(g_aa[0] + i);
- drmp3_f4 vc1 = DRMP3_VLD(g_aa[1] + i);
- vd = DRMP3_VREV(vd);
- DRMP3_VSTORE(grbuf + 18 + i, DRMP3_VSUB(DRMP3_VMUL(vu, vc0), DRMP3_VMUL(vd, vc1)));
- vd = DRMP3_VADD(DRMP3_VMUL(vu, vc1), DRMP3_VMUL(vd, vc0));
- DRMP3_VSTORE(grbuf + 14 - i, DRMP3_VREV(vd));
+ ma_dr_mp3_f4 vu = MA_DR_MP3_VLD(grbuf + 18 + i);
+ ma_dr_mp3_f4 vd = MA_DR_MP3_VLD(grbuf + 14 - i);
+ ma_dr_mp3_f4 vc0 = MA_DR_MP3_VLD(g_aa[0] + i);
+ ma_dr_mp3_f4 vc1 = MA_DR_MP3_VLD(g_aa[1] + i);
+ vd = MA_DR_MP3_VREV(vd);
+ MA_DR_MP3_VSTORE(grbuf + 18 + i, MA_DR_MP3_VSUB(MA_DR_MP3_VMUL(vu, vc0), MA_DR_MP3_VMUL(vd, vc1)));
+ vd = MA_DR_MP3_VADD(MA_DR_MP3_VMUL(vu, vc1), MA_DR_MP3_VMUL(vd, vc0));
+ MA_DR_MP3_VSTORE(grbuf + 14 - i, MA_DR_MP3_VREV(vd));
}
#endif
-#ifndef DR_MP3_ONLY_SIMD
+#ifndef MA_DR_MP3_ONLY_SIMD
for(; i < 8; i++)
{
float u = grbuf[18 + i];
@@ -88864,7 +90775,7 @@ static void drmp3_L3_antialias(float *grbuf, int nbands)
#endif
}
}
-static void drmp3_L3_dct3_9(float *y)
+static void ma_dr_mp3_L3_dct3_9(float *y)
{
float s0, s1, s2, s3, s4, s5, s6, s7, s8, t0, t2, t4;
s0 = y[0]; s2 = y[2]; s4 = y[4]; s6 = y[6]; s8 = y[8];
@@ -88897,7 +90808,7 @@ static void drmp3_L3_dct3_9(float *y)
y[7] = s2 - s1;
y[8] = s4 + s7;
}
-static void drmp3_L3_imdct36(float *grbuf, float *overlap, const float *window, int nbands)
+static void ma_dr_mp3_L3_imdct36(float *grbuf, float *overlap, const float *window, int nbands)
{
int i, j;
static const float g_twid9[18] = {
@@ -88915,28 +90826,28 @@ static void drmp3_L3_imdct36(float *grbuf, float *overlap, const float *window,
si[7 - 2*i] = grbuf[4*i + 4] - grbuf[4*i + 3];
co[2 + 2*i] = -(grbuf[4*i + 3] + grbuf[4*i + 4]);
}
- drmp3_L3_dct3_9(co);
- drmp3_L3_dct3_9(si);
+ ma_dr_mp3_L3_dct3_9(co);
+ ma_dr_mp3_L3_dct3_9(si);
si[1] = -si[1];
si[3] = -si[3];
si[5] = -si[5];
si[7] = -si[7];
i = 0;
-#if DRMP3_HAVE_SIMD
- if (drmp3_have_simd()) for (; i < 8; i += 4)
+#if MA_DR_MP3_HAVE_SIMD
+ if (ma_dr_mp3_have_simd()) for (; i < 8; i += 4)
{
- drmp3_f4 vovl = DRMP3_VLD(overlap + i);
- drmp3_f4 vc = DRMP3_VLD(co + i);
- drmp3_f4 vs = DRMP3_VLD(si + i);
- drmp3_f4 vr0 = DRMP3_VLD(g_twid9 + i);
- drmp3_f4 vr1 = DRMP3_VLD(g_twid9 + 9 + i);
- drmp3_f4 vw0 = DRMP3_VLD(window + i);
- drmp3_f4 vw1 = DRMP3_VLD(window + 9 + i);
- drmp3_f4 vsum = DRMP3_VADD(DRMP3_VMUL(vc, vr1), DRMP3_VMUL(vs, vr0));
- DRMP3_VSTORE(overlap + i, DRMP3_VSUB(DRMP3_VMUL(vc, vr0), DRMP3_VMUL(vs, vr1)));
- DRMP3_VSTORE(grbuf + i, DRMP3_VSUB(DRMP3_VMUL(vovl, vw0), DRMP3_VMUL(vsum, vw1)));
- vsum = DRMP3_VADD(DRMP3_VMUL(vovl, vw1), DRMP3_VMUL(vsum, vw0));
- DRMP3_VSTORE(grbuf + 14 - i, DRMP3_VREV(vsum));
+ ma_dr_mp3_f4 vovl = MA_DR_MP3_VLD(overlap + i);
+ ma_dr_mp3_f4 vc = MA_DR_MP3_VLD(co + i);
+ ma_dr_mp3_f4 vs = MA_DR_MP3_VLD(si + i);
+ ma_dr_mp3_f4 vr0 = MA_DR_MP3_VLD(g_twid9 + i);
+ ma_dr_mp3_f4 vr1 = MA_DR_MP3_VLD(g_twid9 + 9 + i);
+ ma_dr_mp3_f4 vw0 = MA_DR_MP3_VLD(window + i);
+ ma_dr_mp3_f4 vw1 = MA_DR_MP3_VLD(window + 9 + i);
+ ma_dr_mp3_f4 vsum = MA_DR_MP3_VADD(MA_DR_MP3_VMUL(vc, vr1), MA_DR_MP3_VMUL(vs, vr0));
+ MA_DR_MP3_VSTORE(overlap + i, MA_DR_MP3_VSUB(MA_DR_MP3_VMUL(vc, vr0), MA_DR_MP3_VMUL(vs, vr1)));
+ MA_DR_MP3_VSTORE(grbuf + i, MA_DR_MP3_VSUB(MA_DR_MP3_VMUL(vovl, vw0), MA_DR_MP3_VMUL(vsum, vw1)));
+ vsum = MA_DR_MP3_VADD(MA_DR_MP3_VMUL(vovl, vw1), MA_DR_MP3_VMUL(vsum, vw0));
+ MA_DR_MP3_VSTORE(grbuf + 14 - i, MA_DR_MP3_VREV(vsum));
}
#endif
for (; i < 9; i++)
@@ -88949,7 +90860,7 @@ static void drmp3_L3_imdct36(float *grbuf, float *overlap, const float *window,
}
}
}
-static void drmp3_L3_idct3(float x0, float x1, float x2, float *dst)
+static void ma_dr_mp3_L3_idct3(float x0, float x1, float x2, float *dst)
{
float m1 = x1*0.86602540f;
float a1 = x0 - x2*0.5f;
@@ -88957,13 +90868,13 @@ static void drmp3_L3_idct3(float x0, float x1, float x2, float *dst)
dst[0] = a1 + m1;
dst[2] = a1 - m1;
}
-static void drmp3_L3_imdct12(float *x, float *dst, float *overlap)
+static void ma_dr_mp3_L3_imdct12(float *x, float *dst, float *overlap)
{
static const float g_twid3[6] = { 0.79335334f,0.92387953f,0.99144486f, 0.60876143f,0.38268343f,0.13052619f };
float co[3], si[3];
int i;
- drmp3_L3_idct3(-x[0], x[6] + x[3], x[12] + x[9], co);
- drmp3_L3_idct3(x[15], x[12] - x[9], x[6] - x[3], si);
+ ma_dr_mp3_L3_idct3(-x[0], x[6] + x[3], x[12] + x[9], co);
+ ma_dr_mp3_L3_idct3(x[15], x[12] - x[9], x[6] - x[3], si);
si[1] = -si[1];
for (i = 0; i < 3; i++)
{
@@ -88974,26 +90885,26 @@ static void drmp3_L3_imdct12(float *x, float *dst, float *overlap)
dst[5 - i] = ovl*g_twid3[5 - i] + sum*g_twid3[2 - i];
}
}
-static void drmp3_L3_imdct_short(float *grbuf, float *overlap, int nbands)
+static void ma_dr_mp3_L3_imdct_short(float *grbuf, float *overlap, int nbands)
{
for (;nbands > 0; nbands--, overlap += 9, grbuf += 18)
{
float tmp[18];
- DRMP3_COPY_MEMORY(tmp, grbuf, sizeof(tmp));
- DRMP3_COPY_MEMORY(grbuf, overlap, 6*sizeof(float));
- drmp3_L3_imdct12(tmp, grbuf + 6, overlap + 6);
- drmp3_L3_imdct12(tmp + 1, grbuf + 12, overlap + 6);
- drmp3_L3_imdct12(tmp + 2, overlap, overlap + 6);
+ MA_DR_MP3_COPY_MEMORY(tmp, grbuf, sizeof(tmp));
+ MA_DR_MP3_COPY_MEMORY(grbuf, overlap, 6*sizeof(float));
+ ma_dr_mp3_L3_imdct12(tmp, grbuf + 6, overlap + 6);
+ ma_dr_mp3_L3_imdct12(tmp + 1, grbuf + 12, overlap + 6);
+ ma_dr_mp3_L3_imdct12(tmp + 2, overlap, overlap + 6);
}
}
-static void drmp3_L3_change_sign(float *grbuf)
+static void ma_dr_mp3_L3_change_sign(float *grbuf)
{
int b, i;
for (b = 0, grbuf += 18; b < 32; b += 2, grbuf += 36)
for (i = 1; i < 18; i += 2)
grbuf[i] = -grbuf[i];
}
-static void drmp3_L3_imdct_gr(float *grbuf, float *overlap, unsigned block_type, unsigned n_long_bands)
+static void ma_dr_mp3_L3_imdct_gr(float *grbuf, float *overlap, unsigned block_type, unsigned n_long_bands)
{
static const float g_mdct_window[2][18] = {
{ 0.99904822f,0.99144486f,0.97629601f,0.95371695f,0.92387953f,0.88701083f,0.84339145f,0.79335334f,0.73727734f,0.04361938f,0.13052619f,0.21643961f,0.30070580f,0.38268343f,0.46174861f,0.53729961f,0.60876143f,0.67559021f },
@@ -89001,159 +90912,159 @@ static void drmp3_L3_imdct_gr(float *grbuf, float *overlap, unsigned block_type,
};
if (n_long_bands)
{
- drmp3_L3_imdct36(grbuf, overlap, g_mdct_window[0], n_long_bands);
+ ma_dr_mp3_L3_imdct36(grbuf, overlap, g_mdct_window[0], n_long_bands);
grbuf += 18*n_long_bands;
overlap += 9*n_long_bands;
}
- if (block_type == DRMP3_SHORT_BLOCK_TYPE)
- drmp3_L3_imdct_short(grbuf, overlap, 32 - n_long_bands);
+ if (block_type == MA_DR_MP3_SHORT_BLOCK_TYPE)
+ ma_dr_mp3_L3_imdct_short(grbuf, overlap, 32 - n_long_bands);
else
- drmp3_L3_imdct36(grbuf, overlap, g_mdct_window[block_type == DRMP3_STOP_BLOCK_TYPE], 32 - n_long_bands);
+ ma_dr_mp3_L3_imdct36(grbuf, overlap, g_mdct_window[block_type == MA_DR_MP3_STOP_BLOCK_TYPE], 32 - n_long_bands);
}
-static void drmp3_L3_save_reservoir(drmp3dec *h, drmp3dec_scratch *s)
+static void ma_dr_mp3_L3_save_reservoir(ma_dr_mp3dec *h, ma_dr_mp3dec_scratch *s)
{
int pos = (s->bs.pos + 7)/8u;
int remains = s->bs.limit/8u - pos;
- if (remains > DRMP3_MAX_BITRESERVOIR_BYTES)
+ if (remains > MA_DR_MP3_MAX_BITRESERVOIR_BYTES)
{
- pos += remains - DRMP3_MAX_BITRESERVOIR_BYTES;
- remains = DRMP3_MAX_BITRESERVOIR_BYTES;
+ pos += remains - MA_DR_MP3_MAX_BITRESERVOIR_BYTES;
+ remains = MA_DR_MP3_MAX_BITRESERVOIR_BYTES;
}
if (remains > 0)
{
- DRMP3_MOVE_MEMORY(h->reserv_buf, s->maindata + pos, remains);
+ MA_DR_MP3_MOVE_MEMORY(h->reserv_buf, s->maindata + pos, remains);
}
h->reserv = remains;
}
-static int drmp3_L3_restore_reservoir(drmp3dec *h, drmp3_bs *bs, drmp3dec_scratch *s, int main_data_begin)
+static int ma_dr_mp3_L3_restore_reservoir(ma_dr_mp3dec *h, ma_dr_mp3_bs *bs, ma_dr_mp3dec_scratch *s, int main_data_begin)
{
int frame_bytes = (bs->limit - bs->pos)/8;
- int bytes_have = DRMP3_MIN(h->reserv, main_data_begin);
- DRMP3_COPY_MEMORY(s->maindata, h->reserv_buf + DRMP3_MAX(0, h->reserv - main_data_begin), DRMP3_MIN(h->reserv, main_data_begin));
- DRMP3_COPY_MEMORY(s->maindata + bytes_have, bs->buf + bs->pos/8, frame_bytes);
- drmp3_bs_init(&s->bs, s->maindata, bytes_have + frame_bytes);
+ int bytes_have = MA_DR_MP3_MIN(h->reserv, main_data_begin);
+ MA_DR_MP3_COPY_MEMORY(s->maindata, h->reserv_buf + MA_DR_MP3_MAX(0, h->reserv - main_data_begin), MA_DR_MP3_MIN(h->reserv, main_data_begin));
+ MA_DR_MP3_COPY_MEMORY(s->maindata + bytes_have, bs->buf + bs->pos/8, frame_bytes);
+ ma_dr_mp3_bs_init(&s->bs, s->maindata, bytes_have + frame_bytes);
return h->reserv >= main_data_begin;
}
-static void drmp3_L3_decode(drmp3dec *h, drmp3dec_scratch *s, drmp3_L3_gr_info *gr_info, int nch)
+static void ma_dr_mp3_L3_decode(ma_dr_mp3dec *h, ma_dr_mp3dec_scratch *s, ma_dr_mp3_L3_gr_info *gr_info, int nch)
{
int ch;
for (ch = 0; ch < nch; ch++)
{
int layer3gr_limit = s->bs.pos + gr_info[ch].part_23_length;
- drmp3_L3_decode_scalefactors(h->header, s->ist_pos[ch], &s->bs, gr_info + ch, s->scf, ch);
- drmp3_L3_huffman(s->grbuf[ch], &s->bs, gr_info + ch, s->scf, layer3gr_limit);
+ ma_dr_mp3_L3_decode_scalefactors(h->header, s->ist_pos[ch], &s->bs, gr_info + ch, s->scf, ch);
+ ma_dr_mp3_L3_huffman(s->grbuf[ch], &s->bs, gr_info + ch, s->scf, layer3gr_limit);
}
- if (DRMP3_HDR_TEST_I_STEREO(h->header))
+ if (MA_DR_MP3_HDR_TEST_I_STEREO(h->header))
{
- drmp3_L3_intensity_stereo(s->grbuf[0], s->ist_pos[1], gr_info, h->header);
- } else if (DRMP3_HDR_IS_MS_STEREO(h->header))
+ ma_dr_mp3_L3_intensity_stereo(s->grbuf[0], s->ist_pos[1], gr_info, h->header);
+ } else if (MA_DR_MP3_HDR_IS_MS_STEREO(h->header))
{
- drmp3_L3_midside_stereo(s->grbuf[0], 576);
+ ma_dr_mp3_L3_midside_stereo(s->grbuf[0], 576);
}
for (ch = 0; ch < nch; ch++, gr_info++)
{
int aa_bands = 31;
- int n_long_bands = (gr_info->mixed_block_flag ? 2 : 0) << (int)(DRMP3_HDR_GET_MY_SAMPLE_RATE(h->header) == 2);
+ int n_long_bands = (gr_info->mixed_block_flag ? 2 : 0) << (int)(MA_DR_MP3_HDR_GET_MY_SAMPLE_RATE(h->header) == 2);
if (gr_info->n_short_sfb)
{
aa_bands = n_long_bands - 1;
- drmp3_L3_reorder(s->grbuf[ch] + n_long_bands*18, s->syn[0], gr_info->sfbtab + gr_info->n_long_sfb);
+ ma_dr_mp3_L3_reorder(s->grbuf[ch] + n_long_bands*18, s->syn[0], gr_info->sfbtab + gr_info->n_long_sfb);
}
- drmp3_L3_antialias(s->grbuf[ch], aa_bands);
- drmp3_L3_imdct_gr(s->grbuf[ch], h->mdct_overlap[ch], gr_info->block_type, n_long_bands);
- drmp3_L3_change_sign(s->grbuf[ch]);
+ ma_dr_mp3_L3_antialias(s->grbuf[ch], aa_bands);
+ ma_dr_mp3_L3_imdct_gr(s->grbuf[ch], h->mdct_overlap[ch], gr_info->block_type, n_long_bands);
+ ma_dr_mp3_L3_change_sign(s->grbuf[ch]);
}
}
-static void drmp3d_DCT_II(float *grbuf, int n)
+static void ma_dr_mp3d_DCT_II(float *grbuf, int n)
{
static const float g_sec[24] = {
10.19000816f,0.50060302f,0.50241929f,3.40760851f,0.50547093f,0.52249861f,2.05778098f,0.51544732f,0.56694406f,1.48416460f,0.53104258f,0.64682180f,1.16943991f,0.55310392f,0.78815460f,0.97256821f,0.58293498f,1.06067765f,0.83934963f,0.62250412f,1.72244716f,0.74453628f,0.67480832f,5.10114861f
};
int i, k = 0;
-#if DRMP3_HAVE_SIMD
- if (drmp3_have_simd()) for (; k < n; k += 4)
+#if MA_DR_MP3_HAVE_SIMD
+ if (ma_dr_mp3_have_simd()) for (; k < n; k += 4)
{
- drmp3_f4 t[4][8], *x;
+ ma_dr_mp3_f4 t[4][8], *x;
float *y = grbuf + k;
for (x = t[0], i = 0; i < 8; i++, x++)
{
- drmp3_f4 x0 = DRMP3_VLD(&y[i*18]);
- drmp3_f4 x1 = DRMP3_VLD(&y[(15 - i)*18]);
- drmp3_f4 x2 = DRMP3_VLD(&y[(16 + i)*18]);
- drmp3_f4 x3 = DRMP3_VLD(&y[(31 - i)*18]);
- drmp3_f4 t0 = DRMP3_VADD(x0, x3);
- drmp3_f4 t1 = DRMP3_VADD(x1, x2);
- drmp3_f4 t2 = DRMP3_VMUL_S(DRMP3_VSUB(x1, x2), g_sec[3*i + 0]);
- drmp3_f4 t3 = DRMP3_VMUL_S(DRMP3_VSUB(x0, x3), g_sec[3*i + 1]);
- x[0] = DRMP3_VADD(t0, t1);
- x[8] = DRMP3_VMUL_S(DRMP3_VSUB(t0, t1), g_sec[3*i + 2]);
- x[16] = DRMP3_VADD(t3, t2);
- x[24] = DRMP3_VMUL_S(DRMP3_VSUB(t3, t2), g_sec[3*i + 2]);
+ ma_dr_mp3_f4 x0 = MA_DR_MP3_VLD(&y[i*18]);
+ ma_dr_mp3_f4 x1 = MA_DR_MP3_VLD(&y[(15 - i)*18]);
+ ma_dr_mp3_f4 x2 = MA_DR_MP3_VLD(&y[(16 + i)*18]);
+ ma_dr_mp3_f4 x3 = MA_DR_MP3_VLD(&y[(31 - i)*18]);
+ ma_dr_mp3_f4 t0 = MA_DR_MP3_VADD(x0, x3);
+ ma_dr_mp3_f4 t1 = MA_DR_MP3_VADD(x1, x2);
+ ma_dr_mp3_f4 t2 = MA_DR_MP3_VMUL_S(MA_DR_MP3_VSUB(x1, x2), g_sec[3*i + 0]);
+ ma_dr_mp3_f4 t3 = MA_DR_MP3_VMUL_S(MA_DR_MP3_VSUB(x0, x3), g_sec[3*i + 1]);
+ x[0] = MA_DR_MP3_VADD(t0, t1);
+ x[8] = MA_DR_MP3_VMUL_S(MA_DR_MP3_VSUB(t0, t1), g_sec[3*i + 2]);
+ x[16] = MA_DR_MP3_VADD(t3, t2);
+ x[24] = MA_DR_MP3_VMUL_S(MA_DR_MP3_VSUB(t3, t2), g_sec[3*i + 2]);
}
for (x = t[0], i = 0; i < 4; i++, x += 8)
{
- drmp3_f4 x0 = x[0], x1 = x[1], x2 = x[2], x3 = x[3], x4 = x[4], x5 = x[5], x6 = x[6], x7 = x[7], xt;
- xt = DRMP3_VSUB(x0, x7); x0 = DRMP3_VADD(x0, x7);
- x7 = DRMP3_VSUB(x1, x6); x1 = DRMP3_VADD(x1, x6);
- x6 = DRMP3_VSUB(x2, x5); x2 = DRMP3_VADD(x2, x5);
- x5 = DRMP3_VSUB(x3, x4); x3 = DRMP3_VADD(x3, x4);
- x4 = DRMP3_VSUB(x0, x3); x0 = DRMP3_VADD(x0, x3);
- x3 = DRMP3_VSUB(x1, x2); x1 = DRMP3_VADD(x1, x2);
- x[0] = DRMP3_VADD(x0, x1);
- x[4] = DRMP3_VMUL_S(DRMP3_VSUB(x0, x1), 0.70710677f);
- x5 = DRMP3_VADD(x5, x6);
- x6 = DRMP3_VMUL_S(DRMP3_VADD(x6, x7), 0.70710677f);
- x7 = DRMP3_VADD(x7, xt);
- x3 = DRMP3_VMUL_S(DRMP3_VADD(x3, x4), 0.70710677f);
- x5 = DRMP3_VSUB(x5, DRMP3_VMUL_S(x7, 0.198912367f));
- x7 = DRMP3_VADD(x7, DRMP3_VMUL_S(x5, 0.382683432f));
- x5 = DRMP3_VSUB(x5, DRMP3_VMUL_S(x7, 0.198912367f));
- x0 = DRMP3_VSUB(xt, x6); xt = DRMP3_VADD(xt, x6);
- x[1] = DRMP3_VMUL_S(DRMP3_VADD(xt, x7), 0.50979561f);
- x[2] = DRMP3_VMUL_S(DRMP3_VADD(x4, x3), 0.54119611f);
- x[3] = DRMP3_VMUL_S(DRMP3_VSUB(x0, x5), 0.60134488f);
- x[5] = DRMP3_VMUL_S(DRMP3_VADD(x0, x5), 0.89997619f);
- x[6] = DRMP3_VMUL_S(DRMP3_VSUB(x4, x3), 1.30656302f);
- x[7] = DRMP3_VMUL_S(DRMP3_VSUB(xt, x7), 2.56291556f);
+ ma_dr_mp3_f4 x0 = x[0], x1 = x[1], x2 = x[2], x3 = x[3], x4 = x[4], x5 = x[5], x6 = x[6], x7 = x[7], xt;
+ xt = MA_DR_MP3_VSUB(x0, x7); x0 = MA_DR_MP3_VADD(x0, x7);
+ x7 = MA_DR_MP3_VSUB(x1, x6); x1 = MA_DR_MP3_VADD(x1, x6);
+ x6 = MA_DR_MP3_VSUB(x2, x5); x2 = MA_DR_MP3_VADD(x2, x5);
+ x5 = MA_DR_MP3_VSUB(x3, x4); x3 = MA_DR_MP3_VADD(x3, x4);
+ x4 = MA_DR_MP3_VSUB(x0, x3); x0 = MA_DR_MP3_VADD(x0, x3);
+ x3 = MA_DR_MP3_VSUB(x1, x2); x1 = MA_DR_MP3_VADD(x1, x2);
+ x[0] = MA_DR_MP3_VADD(x0, x1);
+ x[4] = MA_DR_MP3_VMUL_S(MA_DR_MP3_VSUB(x0, x1), 0.70710677f);
+ x5 = MA_DR_MP3_VADD(x5, x6);
+ x6 = MA_DR_MP3_VMUL_S(MA_DR_MP3_VADD(x6, x7), 0.70710677f);
+ x7 = MA_DR_MP3_VADD(x7, xt);
+ x3 = MA_DR_MP3_VMUL_S(MA_DR_MP3_VADD(x3, x4), 0.70710677f);
+ x5 = MA_DR_MP3_VSUB(x5, MA_DR_MP3_VMUL_S(x7, 0.198912367f));
+ x7 = MA_DR_MP3_VADD(x7, MA_DR_MP3_VMUL_S(x5, 0.382683432f));
+ x5 = MA_DR_MP3_VSUB(x5, MA_DR_MP3_VMUL_S(x7, 0.198912367f));
+ x0 = MA_DR_MP3_VSUB(xt, x6); xt = MA_DR_MP3_VADD(xt, x6);
+ x[1] = MA_DR_MP3_VMUL_S(MA_DR_MP3_VADD(xt, x7), 0.50979561f);
+ x[2] = MA_DR_MP3_VMUL_S(MA_DR_MP3_VADD(x4, x3), 0.54119611f);
+ x[3] = MA_DR_MP3_VMUL_S(MA_DR_MP3_VSUB(x0, x5), 0.60134488f);
+ x[5] = MA_DR_MP3_VMUL_S(MA_DR_MP3_VADD(x0, x5), 0.89997619f);
+ x[6] = MA_DR_MP3_VMUL_S(MA_DR_MP3_VSUB(x4, x3), 1.30656302f);
+ x[7] = MA_DR_MP3_VMUL_S(MA_DR_MP3_VSUB(xt, x7), 2.56291556f);
}
if (k > n - 3)
{
-#if DRMP3_HAVE_SSE
-#define DRMP3_VSAVE2(i, v) _mm_storel_pi((__m64 *)(void*)&y[i*18], v)
+#if MA_DR_MP3_HAVE_SSE
+#define MA_DR_MP3_VSAVE2(i, v) _mm_storel_pi((__m64 *)(void*)&y[i*18], v)
#else
-#define DRMP3_VSAVE2(i, v) vst1_f32((float32_t *)&y[(i)*18], vget_low_f32(v))
+#define MA_DR_MP3_VSAVE2(i, v) vst1_f32((float32_t *)&y[(i)*18], vget_low_f32(v))
#endif
for (i = 0; i < 7; i++, y += 4*18)
{
- drmp3_f4 s = DRMP3_VADD(t[3][i], t[3][i + 1]);
- DRMP3_VSAVE2(0, t[0][i]);
- DRMP3_VSAVE2(1, DRMP3_VADD(t[2][i], s));
- DRMP3_VSAVE2(2, DRMP3_VADD(t[1][i], t[1][i + 1]));
- DRMP3_VSAVE2(3, DRMP3_VADD(t[2][1 + i], s));
- }
- DRMP3_VSAVE2(0, t[0][7]);
- DRMP3_VSAVE2(1, DRMP3_VADD(t[2][7], t[3][7]));
- DRMP3_VSAVE2(2, t[1][7]);
- DRMP3_VSAVE2(3, t[3][7]);
+ ma_dr_mp3_f4 s = MA_DR_MP3_VADD(t[3][i], t[3][i + 1]);
+ MA_DR_MP3_VSAVE2(0, t[0][i]);
+ MA_DR_MP3_VSAVE2(1, MA_DR_MP3_VADD(t[2][i], s));
+ MA_DR_MP3_VSAVE2(2, MA_DR_MP3_VADD(t[1][i], t[1][i + 1]));
+ MA_DR_MP3_VSAVE2(3, MA_DR_MP3_VADD(t[2][1 + i], s));
+ }
+ MA_DR_MP3_VSAVE2(0, t[0][7]);
+ MA_DR_MP3_VSAVE2(1, MA_DR_MP3_VADD(t[2][7], t[3][7]));
+ MA_DR_MP3_VSAVE2(2, t[1][7]);
+ MA_DR_MP3_VSAVE2(3, t[3][7]);
} else
{
-#define DRMP3_VSAVE4(i, v) DRMP3_VSTORE(&y[(i)*18], v)
+#define MA_DR_MP3_VSAVE4(i, v) MA_DR_MP3_VSTORE(&y[(i)*18], v)
for (i = 0; i < 7; i++, y += 4*18)
{
- drmp3_f4 s = DRMP3_VADD(t[3][i], t[3][i + 1]);
- DRMP3_VSAVE4(0, t[0][i]);
- DRMP3_VSAVE4(1, DRMP3_VADD(t[2][i], s));
- DRMP3_VSAVE4(2, DRMP3_VADD(t[1][i], t[1][i + 1]));
- DRMP3_VSAVE4(3, DRMP3_VADD(t[2][1 + i], s));
+ ma_dr_mp3_f4 s = MA_DR_MP3_VADD(t[3][i], t[3][i + 1]);
+ MA_DR_MP3_VSAVE4(0, t[0][i]);
+ MA_DR_MP3_VSAVE4(1, MA_DR_MP3_VADD(t[2][i], s));
+ MA_DR_MP3_VSAVE4(2, MA_DR_MP3_VADD(t[1][i], t[1][i + 1]));
+ MA_DR_MP3_VSAVE4(3, MA_DR_MP3_VADD(t[2][1 + i], s));
}
- DRMP3_VSAVE4(0, t[0][7]);
- DRMP3_VSAVE4(1, DRMP3_VADD(t[2][7], t[3][7]));
- DRMP3_VSAVE4(2, t[1][7]);
- DRMP3_VSAVE4(3, t[3][7]);
+ MA_DR_MP3_VSAVE4(0, t[0][7]);
+ MA_DR_MP3_VSAVE4(1, MA_DR_MP3_VADD(t[2][7], t[3][7]));
+ MA_DR_MP3_VSAVE4(2, t[1][7]);
+ MA_DR_MP3_VSAVE4(3, t[3][7]);
}
} else
#endif
-#ifdef DR_MP3_ONLY_SIMD
+#ifdef MA_DR_MP3_ONLY_SIMD
{}
#else
for (; k < n; k++)
@@ -89214,31 +91125,31 @@ static void drmp3d_DCT_II(float *grbuf, int n)
}
#endif
}
-#ifndef DR_MP3_FLOAT_OUTPUT
-typedef drmp3_int16 drmp3d_sample_t;
-static drmp3_int16 drmp3d_scale_pcm(float sample)
+#ifndef MA_DR_MP3_FLOAT_OUTPUT
+typedef ma_int16 ma_dr_mp3d_sample_t;
+static ma_int16 ma_dr_mp3d_scale_pcm(float sample)
{
- drmp3_int16 s;
-#if DRMP3_HAVE_ARMV6
- drmp3_int32 s32 = (drmp3_int32)(sample + .5f);
+ ma_int16 s;
+#if MA_DR_MP3_HAVE_ARMV6
+ ma_int32 s32 = (ma_int32)(sample + .5f);
s32 -= (s32 < 0);
- s = (drmp3_int16)drmp3_clip_int16_arm(s32);
+ s = (ma_int16)ma_dr_mp3_clip_int16_arm(s32);
#else
- if (sample >= 32766.5) return (drmp3_int16) 32767;
- if (sample <= -32767.5) return (drmp3_int16)-32768;
- s = (drmp3_int16)(sample + .5f);
+ if (sample >= 32766.5) return (ma_int16) 32767;
+ if (sample <= -32767.5) return (ma_int16)-32768;
+ s = (ma_int16)(sample + .5f);
s -= (s < 0);
#endif
return s;
}
#else
-typedef float drmp3d_sample_t;
-static float drmp3d_scale_pcm(float sample)
+typedef float ma_dr_mp3d_sample_t;
+static float ma_dr_mp3d_scale_pcm(float sample)
{
return sample*(1.f/32768.f);
}
#endif
-static void drmp3d_synth_pair(drmp3d_sample_t *pcm, int nch, const float *z)
+static void ma_dr_mp3d_synth_pair(ma_dr_mp3d_sample_t *pcm, int nch, const float *z)
{
float a;
a = (z[14*64] - z[ 0]) * 29;
@@ -89249,7 +91160,7 @@ static void drmp3d_synth_pair(drmp3d_sample_t *pcm, int nch, const float *z)
a += (z[ 5*64] + z[ 9*64]) * 6574;
a += (z[ 8*64] - z[ 6*64]) * 37489;
a += z[ 7*64] * 75038;
- pcm[0] = drmp3d_scale_pcm(a);
+ pcm[0] = ma_dr_mp3d_scale_pcm(a);
z += 2;
a = z[14*64] * 104;
a += z[12*64] * 1567;
@@ -89259,13 +91170,13 @@ static void drmp3d_synth_pair(drmp3d_sample_t *pcm, int nch, const float *z)
a += z[ 4*64] * -45;
a += z[ 2*64] * 146;
a += z[ 0*64] * -5;
- pcm[16*nch] = drmp3d_scale_pcm(a);
+ pcm[16*nch] = ma_dr_mp3d_scale_pcm(a);
}
-static void drmp3d_synth(float *xl, drmp3d_sample_t *dstl, int nch, float *lins)
+static void ma_dr_mp3d_synth(float *xl, ma_dr_mp3d_sample_t *dstl, int nch, float *lins)
{
int i;
float *xr = xl + 576*(nch - 1);
- drmp3d_sample_t *dstr = dstl + (nch - 1);
+ ma_dr_mp3d_sample_t *dstr = dstl + (nch - 1);
static const float g_win[] = {
-1,26,-31,208,218,401,-519,2063,2000,4788,-5517,7134,5959,35640,-39336,74992,
-1,24,-35,202,222,347,-581,2080,1952,4425,-5879,7640,5288,33791,-41176,74856,
@@ -89293,18 +91204,18 @@ static void drmp3d_synth(float *xl, drmp3d_sample_t *dstl, int nch, float *lins)
zlin[4*31 + 1] = xr[1 + 18*16];
zlin[4*31 + 2] = xl[1];
zlin[4*31 + 3] = xr[1];
- drmp3d_synth_pair(dstr, nch, lins + 4*15 + 1);
- drmp3d_synth_pair(dstr + 32*nch, nch, lins + 4*15 + 64 + 1);
- drmp3d_synth_pair(dstl, nch, lins + 4*15);
- drmp3d_synth_pair(dstl + 32*nch, nch, lins + 4*15 + 64);
-#if DRMP3_HAVE_SIMD
- if (drmp3_have_simd()) for (i = 14; i >= 0; i--)
+ ma_dr_mp3d_synth_pair(dstr, nch, lins + 4*15 + 1);
+ ma_dr_mp3d_synth_pair(dstr + 32*nch, nch, lins + 4*15 + 64 + 1);
+ ma_dr_mp3d_synth_pair(dstl, nch, lins + 4*15);
+ ma_dr_mp3d_synth_pair(dstl + 32*nch, nch, lins + 4*15 + 64);
+#if MA_DR_MP3_HAVE_SIMD
+ if (ma_dr_mp3_have_simd()) for (i = 14; i >= 0; i--)
{
-#define DRMP3_VLOAD(k) drmp3_f4 w0 = DRMP3_VSET(*w++); drmp3_f4 w1 = DRMP3_VSET(*w++); drmp3_f4 vz = DRMP3_VLD(&zlin[4*i - 64*k]); drmp3_f4 vy = DRMP3_VLD(&zlin[4*i - 64*(15 - k)]);
-#define DRMP3_V0(k) { DRMP3_VLOAD(k) b = DRMP3_VADD(DRMP3_VMUL(vz, w1), DRMP3_VMUL(vy, w0)) ; a = DRMP3_VSUB(DRMP3_VMUL(vz, w0), DRMP3_VMUL(vy, w1)); }
-#define DRMP3_V1(k) { DRMP3_VLOAD(k) b = DRMP3_VADD(b, DRMP3_VADD(DRMP3_VMUL(vz, w1), DRMP3_VMUL(vy, w0))); a = DRMP3_VADD(a, DRMP3_VSUB(DRMP3_VMUL(vz, w0), DRMP3_VMUL(vy, w1))); }
-#define DRMP3_V2(k) { DRMP3_VLOAD(k) b = DRMP3_VADD(b, DRMP3_VADD(DRMP3_VMUL(vz, w1), DRMP3_VMUL(vy, w0))); a = DRMP3_VADD(a, DRMP3_VSUB(DRMP3_VMUL(vy, w1), DRMP3_VMUL(vz, w0))); }
- drmp3_f4 a, b;
+#define MA_DR_MP3_VLOAD(k) ma_dr_mp3_f4 w0 = MA_DR_MP3_VSET(*w++); ma_dr_mp3_f4 w1 = MA_DR_MP3_VSET(*w++); ma_dr_mp3_f4 vz = MA_DR_MP3_VLD(&zlin[4*i - 64*k]); ma_dr_mp3_f4 vy = MA_DR_MP3_VLD(&zlin[4*i - 64*(15 - k)]);
+#define MA_DR_MP3_V0(k) { MA_DR_MP3_VLOAD(k) b = MA_DR_MP3_VADD(MA_DR_MP3_VMUL(vz, w1), MA_DR_MP3_VMUL(vy, w0)) ; a = MA_DR_MP3_VSUB(MA_DR_MP3_VMUL(vz, w0), MA_DR_MP3_VMUL(vy, w1)); }
+#define MA_DR_MP3_V1(k) { MA_DR_MP3_VLOAD(k) b = MA_DR_MP3_VADD(b, MA_DR_MP3_VADD(MA_DR_MP3_VMUL(vz, w1), MA_DR_MP3_VMUL(vy, w0))); a = MA_DR_MP3_VADD(a, MA_DR_MP3_VSUB(MA_DR_MP3_VMUL(vz, w0), MA_DR_MP3_VMUL(vy, w1))); }
+#define MA_DR_MP3_V2(k) { MA_DR_MP3_VLOAD(k) b = MA_DR_MP3_VADD(b, MA_DR_MP3_VADD(MA_DR_MP3_VMUL(vz, w1), MA_DR_MP3_VMUL(vy, w0))); a = MA_DR_MP3_VADD(a, MA_DR_MP3_VSUB(MA_DR_MP3_VMUL(vy, w1), MA_DR_MP3_VMUL(vz, w0))); }
+ ma_dr_mp3_f4 a, b;
zlin[4*i] = xl[18*(31 - i)];
zlin[4*i + 1] = xr[18*(31 - i)];
zlin[4*i + 2] = xl[1 + 18*(31 - i)];
@@ -89313,28 +91224,28 @@ static void drmp3d_synth(float *xl, drmp3d_sample_t *dstl, int nch, float *lins)
zlin[4*i + 64 + 1] = xr[1 + 18*(1 + i)];
zlin[4*i - 64 + 2] = xl[18*(1 + i)];
zlin[4*i - 64 + 3] = xr[18*(1 + i)];
- DRMP3_V0(0) DRMP3_V2(1) DRMP3_V1(2) DRMP3_V2(3) DRMP3_V1(4) DRMP3_V2(5) DRMP3_V1(6) DRMP3_V2(7)
+ MA_DR_MP3_V0(0) MA_DR_MP3_V2(1) MA_DR_MP3_V1(2) MA_DR_MP3_V2(3) MA_DR_MP3_V1(4) MA_DR_MP3_V2(5) MA_DR_MP3_V1(6) MA_DR_MP3_V2(7)
{
-#ifndef DR_MP3_FLOAT_OUTPUT
-#if DRMP3_HAVE_SSE
- static const drmp3_f4 g_max = { 32767.0f, 32767.0f, 32767.0f, 32767.0f };
- static const drmp3_f4 g_min = { -32768.0f, -32768.0f, -32768.0f, -32768.0f };
+#ifndef MA_DR_MP3_FLOAT_OUTPUT
+#if MA_DR_MP3_HAVE_SSE
+ static const ma_dr_mp3_f4 g_max = { 32767.0f, 32767.0f, 32767.0f, 32767.0f };
+ static const ma_dr_mp3_f4 g_min = { -32768.0f, -32768.0f, -32768.0f, -32768.0f };
__m128i pcm8 = _mm_packs_epi32(_mm_cvtps_epi32(_mm_max_ps(_mm_min_ps(a, g_max), g_min)),
_mm_cvtps_epi32(_mm_max_ps(_mm_min_ps(b, g_max), g_min)));
- dstr[(15 - i)*nch] = (drmp3_int16)_mm_extract_epi16(pcm8, 1);
- dstr[(17 + i)*nch] = (drmp3_int16)_mm_extract_epi16(pcm8, 5);
- dstl[(15 - i)*nch] = (drmp3_int16)_mm_extract_epi16(pcm8, 0);
- dstl[(17 + i)*nch] = (drmp3_int16)_mm_extract_epi16(pcm8, 4);
- dstr[(47 - i)*nch] = (drmp3_int16)_mm_extract_epi16(pcm8, 3);
- dstr[(49 + i)*nch] = (drmp3_int16)_mm_extract_epi16(pcm8, 7);
- dstl[(47 - i)*nch] = (drmp3_int16)_mm_extract_epi16(pcm8, 2);
- dstl[(49 + i)*nch] = (drmp3_int16)_mm_extract_epi16(pcm8, 6);
+ dstr[(15 - i)*nch] = (ma_int16)_mm_extract_epi16(pcm8, 1);
+ dstr[(17 + i)*nch] = (ma_int16)_mm_extract_epi16(pcm8, 5);
+ dstl[(15 - i)*nch] = (ma_int16)_mm_extract_epi16(pcm8, 0);
+ dstl[(17 + i)*nch] = (ma_int16)_mm_extract_epi16(pcm8, 4);
+ dstr[(47 - i)*nch] = (ma_int16)_mm_extract_epi16(pcm8, 3);
+ dstr[(49 + i)*nch] = (ma_int16)_mm_extract_epi16(pcm8, 7);
+ dstl[(47 - i)*nch] = (ma_int16)_mm_extract_epi16(pcm8, 2);
+ dstl[(49 + i)*nch] = (ma_int16)_mm_extract_epi16(pcm8, 6);
#else
int16x4_t pcma, pcmb;
- a = DRMP3_VADD(a, DRMP3_VSET(0.5f));
- b = DRMP3_VADD(b, DRMP3_VSET(0.5f));
- pcma = vqmovn_s32(vqaddq_s32(vcvtq_s32_f32(a), vreinterpretq_s32_u32(vcltq_f32(a, DRMP3_VSET(0)))));
- pcmb = vqmovn_s32(vqaddq_s32(vcvtq_s32_f32(b), vreinterpretq_s32_u32(vcltq_f32(b, DRMP3_VSET(0)))));
+ a = MA_DR_MP3_VADD(a, MA_DR_MP3_VSET(0.5f));
+ b = MA_DR_MP3_VADD(b, MA_DR_MP3_VSET(0.5f));
+ pcma = vqmovn_s32(vqaddq_s32(vcvtq_s32_f32(a), vreinterpretq_s32_u32(vcltq_f32(a, MA_DR_MP3_VSET(0)))));
+ pcmb = vqmovn_s32(vqaddq_s32(vcvtq_s32_f32(b), vreinterpretq_s32_u32(vcltq_f32(b, MA_DR_MP3_VSET(0)))));
vst1_lane_s16(dstr + (15 - i)*nch, pcma, 1);
vst1_lane_s16(dstr + (17 + i)*nch, pcmb, 1);
vst1_lane_s16(dstl + (15 - i)*nch, pcma, 0);
@@ -89345,14 +91256,14 @@ static void drmp3d_synth(float *xl, drmp3d_sample_t *dstl, int nch, float *lins)
vst1_lane_s16(dstl + (49 + i)*nch, pcmb, 2);
#endif
#else
- #if DRMP3_HAVE_SSE
- static const drmp3_f4 g_scale = { 1.0f/32768.0f, 1.0f/32768.0f, 1.0f/32768.0f, 1.0f/32768.0f };
+ #if MA_DR_MP3_HAVE_SSE
+ static const ma_dr_mp3_f4 g_scale = { 1.0f/32768.0f, 1.0f/32768.0f, 1.0f/32768.0f, 1.0f/32768.0f };
#else
- const drmp3_f4 g_scale = vdupq_n_f32(1.0f/32768.0f);
+ const ma_dr_mp3_f4 g_scale = vdupq_n_f32(1.0f/32768.0f);
#endif
- a = DRMP3_VMUL(a, g_scale);
- b = DRMP3_VMUL(b, g_scale);
-#if DRMP3_HAVE_SSE
+ a = MA_DR_MP3_VMUL(a, g_scale);
+ b = MA_DR_MP3_VMUL(b, g_scale);
+#if MA_DR_MP3_HAVE_SSE
_mm_store_ss(dstr + (15 - i)*nch, _mm_shuffle_ps(a, a, _MM_SHUFFLE(1, 1, 1, 1)));
_mm_store_ss(dstr + (17 + i)*nch, _mm_shuffle_ps(b, b, _MM_SHUFFLE(1, 1, 1, 1)));
_mm_store_ss(dstl + (15 - i)*nch, _mm_shuffle_ps(a, a, _MM_SHUFFLE(0, 0, 0, 0)));
@@ -89375,15 +91286,15 @@ static void drmp3d_synth(float *xl, drmp3d_sample_t *dstl, int nch, float *lins)
}
} else
#endif
-#ifdef DR_MP3_ONLY_SIMD
+#ifdef MA_DR_MP3_ONLY_SIMD
{}
#else
for (i = 14; i >= 0; i--)
{
-#define DRMP3_LOAD(k) float w0 = *w++; float w1 = *w++; float *vz = &zlin[4*i - k*64]; float *vy = &zlin[4*i - (15 - k)*64];
-#define DRMP3_S0(k) { int j; DRMP3_LOAD(k); for (j = 0; j < 4; j++) b[j] = vz[j]*w1 + vy[j]*w0, a[j] = vz[j]*w0 - vy[j]*w1; }
-#define DRMP3_S1(k) { int j; DRMP3_LOAD(k); for (j = 0; j < 4; j++) b[j] += vz[j]*w1 + vy[j]*w0, a[j] += vz[j]*w0 - vy[j]*w1; }
-#define DRMP3_S2(k) { int j; DRMP3_LOAD(k); for (j = 0; j < 4; j++) b[j] += vz[j]*w1 + vy[j]*w0, a[j] += vy[j]*w1 - vz[j]*w0; }
+#define MA_DR_MP3_LOAD(k) float w0 = *w++; float w1 = *w++; float *vz = &zlin[4*i - k*64]; float *vy = &zlin[4*i - (15 - k)*64];
+#define MA_DR_MP3_S0(k) { int j; MA_DR_MP3_LOAD(k); for (j = 0; j < 4; j++) b[j] = vz[j]*w1 + vy[j]*w0, a[j] = vz[j]*w0 - vy[j]*w1; }
+#define MA_DR_MP3_S1(k) { int j; MA_DR_MP3_LOAD(k); for (j = 0; j < 4; j++) b[j] += vz[j]*w1 + vy[j]*w0, a[j] += vz[j]*w0 - vy[j]*w1; }
+#define MA_DR_MP3_S2(k) { int j; MA_DR_MP3_LOAD(k); for (j = 0; j < 4; j++) b[j] += vz[j]*w1 + vy[j]*w0, a[j] += vy[j]*w1 - vz[j]*w0; }
float a[4], b[4];
zlin[4*i] = xl[18*(31 - i)];
zlin[4*i + 1] = xr[18*(31 - i)];
@@ -89393,31 +91304,31 @@ static void drmp3d_synth(float *xl, drmp3d_sample_t *dstl, int nch, float *lins)
zlin[4*(i + 16) + 1] = xr[1 + 18*(1 + i)];
zlin[4*(i - 16) + 2] = xl[18*(1 + i)];
zlin[4*(i - 16) + 3] = xr[18*(1 + i)];
- DRMP3_S0(0) DRMP3_S2(1) DRMP3_S1(2) DRMP3_S2(3) DRMP3_S1(4) DRMP3_S2(5) DRMP3_S1(6) DRMP3_S2(7)
- dstr[(15 - i)*nch] = drmp3d_scale_pcm(a[1]);
- dstr[(17 + i)*nch] = drmp3d_scale_pcm(b[1]);
- dstl[(15 - i)*nch] = drmp3d_scale_pcm(a[0]);
- dstl[(17 + i)*nch] = drmp3d_scale_pcm(b[0]);
- dstr[(47 - i)*nch] = drmp3d_scale_pcm(a[3]);
- dstr[(49 + i)*nch] = drmp3d_scale_pcm(b[3]);
- dstl[(47 - i)*nch] = drmp3d_scale_pcm(a[2]);
- dstl[(49 + i)*nch] = drmp3d_scale_pcm(b[2]);
+ MA_DR_MP3_S0(0) MA_DR_MP3_S2(1) MA_DR_MP3_S1(2) MA_DR_MP3_S2(3) MA_DR_MP3_S1(4) MA_DR_MP3_S2(5) MA_DR_MP3_S1(6) MA_DR_MP3_S2(7)
+ dstr[(15 - i)*nch] = ma_dr_mp3d_scale_pcm(a[1]);
+ dstr[(17 + i)*nch] = ma_dr_mp3d_scale_pcm(b[1]);
+ dstl[(15 - i)*nch] = ma_dr_mp3d_scale_pcm(a[0]);
+ dstl[(17 + i)*nch] = ma_dr_mp3d_scale_pcm(b[0]);
+ dstr[(47 - i)*nch] = ma_dr_mp3d_scale_pcm(a[3]);
+ dstr[(49 + i)*nch] = ma_dr_mp3d_scale_pcm(b[3]);
+ dstl[(47 - i)*nch] = ma_dr_mp3d_scale_pcm(a[2]);
+ dstl[(49 + i)*nch] = ma_dr_mp3d_scale_pcm(b[2]);
}
#endif
}
-static void drmp3d_synth_granule(float *qmf_state, float *grbuf, int nbands, int nch, drmp3d_sample_t *pcm, float *lins)
+static void ma_dr_mp3d_synth_granule(float *qmf_state, float *grbuf, int nbands, int nch, ma_dr_mp3d_sample_t *pcm, float *lins)
{
int i;
for (i = 0; i < nch; i++)
{
- drmp3d_DCT_II(grbuf + 576*i, nbands);
+ ma_dr_mp3d_DCT_II(grbuf + 576*i, nbands);
}
- DRMP3_COPY_MEMORY(lins, qmf_state, sizeof(float)*15*64);
+ MA_DR_MP3_COPY_MEMORY(lins, qmf_state, sizeof(float)*15*64);
for (i = 0; i < nbands; i += 2)
{
- drmp3d_synth(grbuf + i, pcm + 32*nch*i, nch, lins + i*64);
+ ma_dr_mp3d_synth(grbuf + i, pcm + 32*nch*i, nch, lins + i*64);
}
-#ifndef DR_MP3_NONSTANDARD_BUT_LOGICAL
+#ifndef MA_DR_MP3_NONSTANDARD_BUT_LOGICAL
if (nch == 1)
{
for (i = 0; i < 15*64; i += 2)
@@ -89427,38 +91338,38 @@ static void drmp3d_synth_granule(float *qmf_state, float *grbuf, int nbands, int
} else
#endif
{
- DRMP3_COPY_MEMORY(qmf_state, lins + nbands*64, sizeof(float)*15*64);
+ MA_DR_MP3_COPY_MEMORY(qmf_state, lins + nbands*64, sizeof(float)*15*64);
}
}
-static int drmp3d_match_frame(const drmp3_uint8 *hdr, int mp3_bytes, int frame_bytes)
+static int ma_dr_mp3d_match_frame(const ma_uint8 *hdr, int mp3_bytes, int frame_bytes)
{
int i, nmatch;
- for (i = 0, nmatch = 0; nmatch < DRMP3_MAX_FRAME_SYNC_MATCHES; nmatch++)
+ for (i = 0, nmatch = 0; nmatch < MA_DR_MP3_MAX_FRAME_SYNC_MATCHES; nmatch++)
{
- i += drmp3_hdr_frame_bytes(hdr + i, frame_bytes) + drmp3_hdr_padding(hdr + i);
- if (i + DRMP3_HDR_SIZE > mp3_bytes)
+ i += ma_dr_mp3_hdr_frame_bytes(hdr + i, frame_bytes) + ma_dr_mp3_hdr_padding(hdr + i);
+ if (i + MA_DR_MP3_HDR_SIZE > mp3_bytes)
return nmatch > 0;
- if (!drmp3_hdr_compare(hdr, hdr + i))
+ if (!ma_dr_mp3_hdr_compare(hdr, hdr + i))
return 0;
}
return 1;
}
-static int drmp3d_find_frame(const drmp3_uint8 *mp3, int mp3_bytes, int *free_format_bytes, int *ptr_frame_bytes)
+static int ma_dr_mp3d_find_frame(const ma_uint8 *mp3, int mp3_bytes, int *free_format_bytes, int *ptr_frame_bytes)
{
int i, k;
- for (i = 0; i < mp3_bytes - DRMP3_HDR_SIZE; i++, mp3++)
+ for (i = 0; i < mp3_bytes - MA_DR_MP3_HDR_SIZE; i++, mp3++)
{
- if (drmp3_hdr_valid(mp3))
+ if (ma_dr_mp3_hdr_valid(mp3))
{
- int frame_bytes = drmp3_hdr_frame_bytes(mp3, *free_format_bytes);
- int frame_and_padding = frame_bytes + drmp3_hdr_padding(mp3);
- for (k = DRMP3_HDR_SIZE; !frame_bytes && k < DRMP3_MAX_FREE_FORMAT_FRAME_SIZE && i + 2*k < mp3_bytes - DRMP3_HDR_SIZE; k++)
+ int frame_bytes = ma_dr_mp3_hdr_frame_bytes(mp3, *free_format_bytes);
+ int frame_and_padding = frame_bytes + ma_dr_mp3_hdr_padding(mp3);
+ for (k = MA_DR_MP3_HDR_SIZE; !frame_bytes && k < MA_DR_MP3_MAX_FREE_FORMAT_FRAME_SIZE && i + 2*k < mp3_bytes - MA_DR_MP3_HDR_SIZE; k++)
{
- if (drmp3_hdr_compare(mp3, mp3 + k))
+ if (ma_dr_mp3_hdr_compare(mp3, mp3 + k))
{
- int fb = k - drmp3_hdr_padding(mp3);
- int nextfb = fb + drmp3_hdr_padding(mp3 + k);
- if (i + k + nextfb + DRMP3_HDR_SIZE > mp3_bytes || !drmp3_hdr_compare(mp3, mp3 + k + nextfb))
+ int fb = k - ma_dr_mp3_hdr_padding(mp3);
+ int nextfb = fb + ma_dr_mp3_hdr_padding(mp3 + k);
+ if (i + k + nextfb + MA_DR_MP3_HDR_SIZE > mp3_bytes || !ma_dr_mp3_hdr_compare(mp3, mp3 + k + nextfb))
continue;
frame_and_padding = k;
frame_bytes = fb;
@@ -89466,7 +91377,7 @@ static int drmp3d_find_frame(const drmp3_uint8 *mp3, int mp3_bytes, int *free_fo
}
}
if ((frame_bytes && i + frame_and_padding <= mp3_bytes &&
- drmp3d_match_frame(mp3, mp3_bytes - i, frame_bytes)) ||
+ ma_dr_mp3d_match_frame(mp3, mp3_bytes - i, frame_bytes)) ||
(!i && frame_and_padding == mp3_bytes))
{
*ptr_frame_bytes = frame_and_padding;
@@ -89478,28 +91389,28 @@ static int drmp3d_find_frame(const drmp3_uint8 *mp3, int mp3_bytes, int *free_fo
*ptr_frame_bytes = 0;
return mp3_bytes;
}
-DRMP3_API void drmp3dec_init(drmp3dec *dec)
+MA_API void ma_dr_mp3dec_init(ma_dr_mp3dec *dec)
{
dec->header[0] = 0;
}
-DRMP3_API int drmp3dec_decode_frame(drmp3dec *dec, const drmp3_uint8 *mp3, int mp3_bytes, void *pcm, drmp3dec_frame_info *info)
+MA_API int ma_dr_mp3dec_decode_frame(ma_dr_mp3dec *dec, const ma_uint8 *mp3, int mp3_bytes, void *pcm, ma_dr_mp3dec_frame_info *info)
{
int i = 0, igr, frame_size = 0, success = 1;
- const drmp3_uint8 *hdr;
- drmp3_bs bs_frame[1];
- drmp3dec_scratch scratch;
- if (mp3_bytes > 4 && dec->header[0] == 0xff && drmp3_hdr_compare(dec->header, mp3))
+ const ma_uint8 *hdr;
+ ma_dr_mp3_bs bs_frame[1];
+ ma_dr_mp3dec_scratch scratch;
+ if (mp3_bytes > 4 && dec->header[0] == 0xff && ma_dr_mp3_hdr_compare(dec->header, mp3))
{
- frame_size = drmp3_hdr_frame_bytes(mp3, dec->free_format_bytes) + drmp3_hdr_padding(mp3);
- if (frame_size != mp3_bytes && (frame_size + DRMP3_HDR_SIZE > mp3_bytes || !drmp3_hdr_compare(mp3, mp3 + frame_size)))
+ frame_size = ma_dr_mp3_hdr_frame_bytes(mp3, dec->free_format_bytes) + ma_dr_mp3_hdr_padding(mp3);
+ if (frame_size != mp3_bytes && (frame_size + MA_DR_MP3_HDR_SIZE > mp3_bytes || !ma_dr_mp3_hdr_compare(mp3, mp3 + frame_size)))
{
frame_size = 0;
}
}
if (!frame_size)
{
- DRMP3_ZERO_MEMORY(dec, sizeof(drmp3dec));
- i = drmp3d_find_frame(mp3, mp3_bytes, &dec->free_format_bytes, &frame_size);
+ MA_DR_MP3_ZERO_MEMORY(dec, sizeof(ma_dr_mp3dec));
+ i = ma_dr_mp3d_find_frame(mp3, mp3_bytes, &dec->free_format_bytes, &frame_size);
if (!frame_size || i + frame_size > mp3_bytes)
{
info->frame_bytes = i;
@@ -89507,96 +91418,96 @@ DRMP3_API int drmp3dec_decode_frame(drmp3dec *dec, const drmp3_uint8 *mp3, int m
}
}
hdr = mp3 + i;
- DRMP3_COPY_MEMORY(dec->header, hdr, DRMP3_HDR_SIZE);
+ MA_DR_MP3_COPY_MEMORY(dec->header, hdr, MA_DR_MP3_HDR_SIZE);
info->frame_bytes = i + frame_size;
- info->channels = DRMP3_HDR_IS_MONO(hdr) ? 1 : 2;
- info->hz = drmp3_hdr_sample_rate_hz(hdr);
- info->layer = 4 - DRMP3_HDR_GET_LAYER(hdr);
- info->bitrate_kbps = drmp3_hdr_bitrate_kbps(hdr);
- drmp3_bs_init(bs_frame, hdr + DRMP3_HDR_SIZE, frame_size - DRMP3_HDR_SIZE);
- if (DRMP3_HDR_IS_CRC(hdr))
+ info->channels = MA_DR_MP3_HDR_IS_MONO(hdr) ? 1 : 2;
+ info->hz = ma_dr_mp3_hdr_sample_rate_hz(hdr);
+ info->layer = 4 - MA_DR_MP3_HDR_GET_LAYER(hdr);
+ info->bitrate_kbps = ma_dr_mp3_hdr_bitrate_kbps(hdr);
+ ma_dr_mp3_bs_init(bs_frame, hdr + MA_DR_MP3_HDR_SIZE, frame_size - MA_DR_MP3_HDR_SIZE);
+ if (MA_DR_MP3_HDR_IS_CRC(hdr))
{
- drmp3_bs_get_bits(bs_frame, 16);
+ ma_dr_mp3_bs_get_bits(bs_frame, 16);
}
if (info->layer == 3)
{
- int main_data_begin = drmp3_L3_read_side_info(bs_frame, scratch.gr_info, hdr);
+ int main_data_begin = ma_dr_mp3_L3_read_side_info(bs_frame, scratch.gr_info, hdr);
if (main_data_begin < 0 || bs_frame->pos > bs_frame->limit)
{
- drmp3dec_init(dec);
+ ma_dr_mp3dec_init(dec);
return 0;
}
- success = drmp3_L3_restore_reservoir(dec, bs_frame, &scratch, main_data_begin);
+ success = ma_dr_mp3_L3_restore_reservoir(dec, bs_frame, &scratch, main_data_begin);
if (success && pcm != NULL)
{
- for (igr = 0; igr < (DRMP3_HDR_TEST_MPEG1(hdr) ? 2 : 1); igr++, pcm = DRMP3_OFFSET_PTR(pcm, sizeof(drmp3d_sample_t)*576*info->channels))
+ for (igr = 0; igr < (MA_DR_MP3_HDR_TEST_MPEG1(hdr) ? 2 : 1); igr++, pcm = MA_DR_MP3_OFFSET_PTR(pcm, sizeof(ma_dr_mp3d_sample_t)*576*info->channels))
{
- DRMP3_ZERO_MEMORY(scratch.grbuf[0], 576*2*sizeof(float));
- drmp3_L3_decode(dec, &scratch, scratch.gr_info + igr*info->channels, info->channels);
- drmp3d_synth_granule(dec->qmf_state, scratch.grbuf[0], 18, info->channels, (drmp3d_sample_t*)pcm, scratch.syn[0]);
+ MA_DR_MP3_ZERO_MEMORY(scratch.grbuf[0], 576*2*sizeof(float));
+ ma_dr_mp3_L3_decode(dec, &scratch, scratch.gr_info + igr*info->channels, info->channels);
+ ma_dr_mp3d_synth_granule(dec->qmf_state, scratch.grbuf[0], 18, info->channels, (ma_dr_mp3d_sample_t*)pcm, scratch.syn[0]);
}
}
- drmp3_L3_save_reservoir(dec, &scratch);
+ ma_dr_mp3_L3_save_reservoir(dec, &scratch);
} else
{
-#ifdef DR_MP3_ONLY_MP3
+#ifdef MA_DR_MP3_ONLY_MP3
return 0;
#else
- drmp3_L12_scale_info sci[1];
+ ma_dr_mp3_L12_scale_info sci[1];
if (pcm == NULL) {
- return drmp3_hdr_frame_samples(hdr);
+ return ma_dr_mp3_hdr_frame_samples(hdr);
}
- drmp3_L12_read_scale_info(hdr, bs_frame, sci);
- DRMP3_ZERO_MEMORY(scratch.grbuf[0], 576*2*sizeof(float));
+ ma_dr_mp3_L12_read_scale_info(hdr, bs_frame, sci);
+ MA_DR_MP3_ZERO_MEMORY(scratch.grbuf[0], 576*2*sizeof(float));
for (i = 0, igr = 0; igr < 3; igr++)
{
- if (12 == (i += drmp3_L12_dequantize_granule(scratch.grbuf[0] + i, bs_frame, sci, info->layer | 1)))
+ if (12 == (i += ma_dr_mp3_L12_dequantize_granule(scratch.grbuf[0] + i, bs_frame, sci, info->layer | 1)))
{
i = 0;
- drmp3_L12_apply_scf_384(sci, sci->scf + igr, scratch.grbuf[0]);
- drmp3d_synth_granule(dec->qmf_state, scratch.grbuf[0], 12, info->channels, (drmp3d_sample_t*)pcm, scratch.syn[0]);
- DRMP3_ZERO_MEMORY(scratch.grbuf[0], 576*2*sizeof(float));
- pcm = DRMP3_OFFSET_PTR(pcm, sizeof(drmp3d_sample_t)*384*info->channels);
+ ma_dr_mp3_L12_apply_scf_384(sci, sci->scf + igr, scratch.grbuf[0]);
+ ma_dr_mp3d_synth_granule(dec->qmf_state, scratch.grbuf[0], 12, info->channels, (ma_dr_mp3d_sample_t*)pcm, scratch.syn[0]);
+ MA_DR_MP3_ZERO_MEMORY(scratch.grbuf[0], 576*2*sizeof(float));
+ pcm = MA_DR_MP3_OFFSET_PTR(pcm, sizeof(ma_dr_mp3d_sample_t)*384*info->channels);
}
if (bs_frame->pos > bs_frame->limit)
{
- drmp3dec_init(dec);
+ ma_dr_mp3dec_init(dec);
return 0;
}
}
#endif
}
- return success*drmp3_hdr_frame_samples(dec->header);
+ return success*ma_dr_mp3_hdr_frame_samples(dec->header);
}
-DRMP3_API void drmp3dec_f32_to_s16(const float *in, drmp3_int16 *out, size_t num_samples)
+MA_API void ma_dr_mp3dec_f32_to_s16(const float *in, ma_int16 *out, size_t num_samples)
{
size_t i = 0;
-#if DRMP3_HAVE_SIMD
+#if MA_DR_MP3_HAVE_SIMD
size_t aligned_count = num_samples & ~7;
for(; i < aligned_count; i+=8)
{
- drmp3_f4 scale = DRMP3_VSET(32768.0f);
- drmp3_f4 a = DRMP3_VMUL(DRMP3_VLD(&in[i ]), scale);
- drmp3_f4 b = DRMP3_VMUL(DRMP3_VLD(&in[i+4]), scale);
-#if DRMP3_HAVE_SSE
- drmp3_f4 s16max = DRMP3_VSET( 32767.0f);
- drmp3_f4 s16min = DRMP3_VSET(-32768.0f);
+ ma_dr_mp3_f4 scale = MA_DR_MP3_VSET(32768.0f);
+ ma_dr_mp3_f4 a = MA_DR_MP3_VMUL(MA_DR_MP3_VLD(&in[i ]), scale);
+ ma_dr_mp3_f4 b = MA_DR_MP3_VMUL(MA_DR_MP3_VLD(&in[i+4]), scale);
+#if MA_DR_MP3_HAVE_SSE
+ ma_dr_mp3_f4 s16max = MA_DR_MP3_VSET( 32767.0f);
+ ma_dr_mp3_f4 s16min = MA_DR_MP3_VSET(-32768.0f);
__m128i pcm8 = _mm_packs_epi32(_mm_cvtps_epi32(_mm_max_ps(_mm_min_ps(a, s16max), s16min)),
_mm_cvtps_epi32(_mm_max_ps(_mm_min_ps(b, s16max), s16min)));
- out[i ] = (drmp3_int16)_mm_extract_epi16(pcm8, 0);
- out[i+1] = (drmp3_int16)_mm_extract_epi16(pcm8, 1);
- out[i+2] = (drmp3_int16)_mm_extract_epi16(pcm8, 2);
- out[i+3] = (drmp3_int16)_mm_extract_epi16(pcm8, 3);
- out[i+4] = (drmp3_int16)_mm_extract_epi16(pcm8, 4);
- out[i+5] = (drmp3_int16)_mm_extract_epi16(pcm8, 5);
- out[i+6] = (drmp3_int16)_mm_extract_epi16(pcm8, 6);
- out[i+7] = (drmp3_int16)_mm_extract_epi16(pcm8, 7);
+ out[i ] = (ma_int16)_mm_extract_epi16(pcm8, 0);
+ out[i+1] = (ma_int16)_mm_extract_epi16(pcm8, 1);
+ out[i+2] = (ma_int16)_mm_extract_epi16(pcm8, 2);
+ out[i+3] = (ma_int16)_mm_extract_epi16(pcm8, 3);
+ out[i+4] = (ma_int16)_mm_extract_epi16(pcm8, 4);
+ out[i+5] = (ma_int16)_mm_extract_epi16(pcm8, 5);
+ out[i+6] = (ma_int16)_mm_extract_epi16(pcm8, 6);
+ out[i+7] = (ma_int16)_mm_extract_epi16(pcm8, 7);
#else
int16x4_t pcma, pcmb;
- a = DRMP3_VADD(a, DRMP3_VSET(0.5f));
- b = DRMP3_VADD(b, DRMP3_VSET(0.5f));
- pcma = vqmovn_s32(vqaddq_s32(vcvtq_s32_f32(a), vreinterpretq_s32_u32(vcltq_f32(a, DRMP3_VSET(0)))));
- pcmb = vqmovn_s32(vqaddq_s32(vcvtq_s32_f32(b), vreinterpretq_s32_u32(vcltq_f32(b, DRMP3_VSET(0)))));
+ a = MA_DR_MP3_VADD(a, MA_DR_MP3_VSET(0.5f));
+ b = MA_DR_MP3_VADD(b, MA_DR_MP3_VSET(0.5f));
+ pcma = vqmovn_s32(vqaddq_s32(vcvtq_s32_f32(a), vreinterpretq_s32_u32(vcltq_f32(a, MA_DR_MP3_VSET(0)))));
+ pcmb = vqmovn_s32(vqaddq_s32(vcvtq_s32_f32(b), vreinterpretq_s32_u32(vcltq_f32(b, MA_DR_MP3_VSET(0)))));
vst1_lane_s16(out+i , pcma, 0);
vst1_lane_s16(out+i+1, pcma, 1);
vst1_lane_s16(out+i+2, pcma, 2);
@@ -89612,78 +91523,69 @@ DRMP3_API void drmp3dec_f32_to_s16(const float *in, drmp3_int16 *out, size_t num
{
float sample = in[i] * 32768.0f;
if (sample >= 32766.5)
- out[i] = (drmp3_int16) 32767;
+ out[i] = (ma_int16) 32767;
else if (sample <= -32767.5)
- out[i] = (drmp3_int16)-32768;
+ out[i] = (ma_int16)-32768;
else
{
- short s = (drmp3_int16)(sample + .5f);
+ short s = (ma_int16)(sample + .5f);
s -= (s < 0);
out[i] = s;
}
}
}
-#if defined(SIZE_MAX)
- #define DRMP3_SIZE_MAX SIZE_MAX
-#else
- #if defined(_WIN64) || defined(_LP64) || defined(__LP64__)
- #define DRMP3_SIZE_MAX ((drmp3_uint64)0xFFFFFFFFFFFFFFFF)
- #else
- #define DRMP3_SIZE_MAX 0xFFFFFFFF
- #endif
+#ifndef MA_DR_MP3_SEEK_LEADING_MP3_FRAMES
+#define MA_DR_MP3_SEEK_LEADING_MP3_FRAMES 2
#endif
-#ifndef DRMP3_SEEK_LEADING_MP3_FRAMES
-#define DRMP3_SEEK_LEADING_MP3_FRAMES 2
+#define MA_DR_MP3_MIN_DATA_CHUNK_SIZE 16384
+#ifndef MA_DR_MP3_DATA_CHUNK_SIZE
+#define MA_DR_MP3_DATA_CHUNK_SIZE (MA_DR_MP3_MIN_DATA_CHUNK_SIZE*4)
#endif
-#define DRMP3_MIN_DATA_CHUNK_SIZE 16384
-#ifndef DRMP3_DATA_CHUNK_SIZE
-#define DRMP3_DATA_CHUNK_SIZE (DRMP3_MIN_DATA_CHUNK_SIZE*4)
+#define MA_DR_MP3_COUNTOF(x) (sizeof(x) / sizeof(x[0]))
+#define MA_DR_MP3_CLAMP(x, lo, hi) (MA_DR_MP3_MAX(lo, MA_DR_MP3_MIN(x, hi)))
+#ifndef MA_DR_MP3_PI_D
+#define MA_DR_MP3_PI_D 3.14159265358979323846264
#endif
-#define DRMP3_COUNTOF(x) (sizeof(x) / sizeof(x[0]))
-#define DRMP3_CLAMP(x, lo, hi) (DRMP3_MAX(lo, DRMP3_MIN(x, hi)))
-#ifndef DRMP3_PI_D
-#define DRMP3_PI_D 3.14159265358979323846264
-#endif
-#define DRMP3_DEFAULT_RESAMPLER_LPF_ORDER 2
-static DRMP3_INLINE float drmp3_mix_f32(float x, float y, float a)
+#define MA_DR_MP3_DEFAULT_RESAMPLER_LPF_ORDER 2
+static MA_INLINE float ma_dr_mp3_mix_f32(float x, float y, float a)
{
return x*(1-a) + y*a;
}
-static DRMP3_INLINE float drmp3_mix_f32_fast(float x, float y, float a)
+static MA_INLINE float ma_dr_mp3_mix_f32_fast(float x, float y, float a)
{
float r0 = (y - x);
float r1 = r0*a;
return x + r1;
}
-static DRMP3_INLINE drmp3_uint32 drmp3_gcf_u32(drmp3_uint32 a, drmp3_uint32 b)
+static MA_INLINE ma_uint32 ma_dr_mp3_gcf_u32(ma_uint32 a, ma_uint32 b)
{
for (;;) {
if (b == 0) {
break;
} else {
- drmp3_uint32 t = a;
+ ma_uint32 t = a;
a = b;
b = t % a;
}
}
return a;
}
-static void* drmp3__malloc_default(size_t sz, void* pUserData)
+static void* ma_dr_mp3__malloc_default(size_t sz, void* pUserData)
{
(void)pUserData;
- return DRMP3_MALLOC(sz);
+ return MA_DR_MP3_MALLOC(sz);
}
-static void* drmp3__realloc_default(void* p, size_t sz, void* pUserData)
+static void* ma_dr_mp3__realloc_default(void* p, size_t sz, void* pUserData)
{
(void)pUserData;
- return DRMP3_REALLOC(p, sz);
+ return MA_DR_MP3_REALLOC(p, sz);
}
-static void drmp3__free_default(void* p, void* pUserData)
+static void ma_dr_mp3__free_default(void* p, void* pUserData)
{
(void)pUserData;
- DRMP3_FREE(p);
+ MA_DR_MP3_FREE(p);
}
-static void* drmp3__malloc_from_callbacks(size_t sz, const drmp3_allocation_callbacks* pAllocationCallbacks)
+static void* ma_dr_mp3__malloc_from_callbacks(size_t sz, const ma_allocation_callbacks* pAllocationCallbacks)
{
if (pAllocationCallbacks == NULL) {
return NULL;
@@ -89696,7 +91598,7 @@ static void* drmp3__malloc_from_callbacks(size_t sz, const drmp3_allocation_call
}
return NULL;
}
-static void* drmp3__realloc_from_callbacks(void* p, size_t szNew, size_t szOld, const drmp3_allocation_callbacks* pAllocationCallbacks)
+static void* ma_dr_mp3__realloc_from_callbacks(void* p, size_t szNew, size_t szOld, const ma_allocation_callbacks* pAllocationCallbacks)
{
if (pAllocationCallbacks == NULL) {
return NULL;
@@ -89711,14 +91613,14 @@ static void* drmp3__realloc_from_callbacks(void* p, size_t szNew, size_t szOld,
return NULL;
}
if (p != NULL) {
- DRMP3_COPY_MEMORY(p2, p, szOld);
+ MA_DR_MP3_COPY_MEMORY(p2, p, szOld);
pAllocationCallbacks->onFree(p, pAllocationCallbacks->pUserData);
}
return p2;
}
return NULL;
}
-static void drmp3__free_from_callbacks(void* p, const drmp3_allocation_callbacks* pAllocationCallbacks)
+static void ma_dr_mp3__free_from_callbacks(void* p, const ma_allocation_callbacks* pAllocationCallbacks)
{
if (p == NULL || pAllocationCallbacks == NULL) {
return;
@@ -89727,111 +91629,114 @@ static void drmp3__free_from_callbacks(void* p, const drmp3_allocation_callbacks
pAllocationCallbacks->onFree(p, pAllocationCallbacks->pUserData);
}
}
-static drmp3_allocation_callbacks drmp3_copy_allocation_callbacks_or_defaults(const drmp3_allocation_callbacks* pAllocationCallbacks)
+static ma_allocation_callbacks ma_dr_mp3_copy_allocation_callbacks_or_defaults(const ma_allocation_callbacks* pAllocationCallbacks)
{
if (pAllocationCallbacks != NULL) {
return *pAllocationCallbacks;
} else {
- drmp3_allocation_callbacks allocationCallbacks;
+ ma_allocation_callbacks allocationCallbacks;
allocationCallbacks.pUserData = NULL;
- allocationCallbacks.onMalloc = drmp3__malloc_default;
- allocationCallbacks.onRealloc = drmp3__realloc_default;
- allocationCallbacks.onFree = drmp3__free_default;
+ allocationCallbacks.onMalloc = ma_dr_mp3__malloc_default;
+ allocationCallbacks.onRealloc = ma_dr_mp3__realloc_default;
+ allocationCallbacks.onFree = ma_dr_mp3__free_default;
return allocationCallbacks;
}
}
-static size_t drmp3__on_read(drmp3* pMP3, void* pBufferOut, size_t bytesToRead)
+static size_t ma_dr_mp3__on_read(ma_dr_mp3* pMP3, void* pBufferOut, size_t bytesToRead)
{
size_t bytesRead = pMP3->onRead(pMP3->pUserData, pBufferOut, bytesToRead);
pMP3->streamCursor += bytesRead;
return bytesRead;
}
-static drmp3_bool32 drmp3__on_seek(drmp3* pMP3, int offset, drmp3_seek_origin origin)
+static ma_bool32 ma_dr_mp3__on_seek(ma_dr_mp3* pMP3, int offset, ma_dr_mp3_seek_origin origin)
{
- DRMP3_ASSERT(offset >= 0);
+ MA_DR_MP3_ASSERT(offset >= 0);
if (!pMP3->onSeek(pMP3->pUserData, offset, origin)) {
- return DRMP3_FALSE;
+ return MA_FALSE;
}
- if (origin == drmp3_seek_origin_start) {
- pMP3->streamCursor = (drmp3_uint64)offset;
+ if (origin == ma_dr_mp3_seek_origin_start) {
+ pMP3->streamCursor = (ma_uint64)offset;
} else {
pMP3->streamCursor += offset;
}
- return DRMP3_TRUE;
+ return MA_TRUE;
}
-static drmp3_bool32 drmp3__on_seek_64(drmp3* pMP3, drmp3_uint64 offset, drmp3_seek_origin origin)
+static ma_bool32 ma_dr_mp3__on_seek_64(ma_dr_mp3* pMP3, ma_uint64 offset, ma_dr_mp3_seek_origin origin)
{
if (offset <= 0x7FFFFFFF) {
- return drmp3__on_seek(pMP3, (int)offset, origin);
+ return ma_dr_mp3__on_seek(pMP3, (int)offset, origin);
}
- if (!drmp3__on_seek(pMP3, 0x7FFFFFFF, drmp3_seek_origin_start)) {
- return DRMP3_FALSE;
+ if (!ma_dr_mp3__on_seek(pMP3, 0x7FFFFFFF, ma_dr_mp3_seek_origin_start)) {
+ return MA_FALSE;
}
offset -= 0x7FFFFFFF;
while (offset > 0) {
if (offset <= 0x7FFFFFFF) {
- if (!drmp3__on_seek(pMP3, (int)offset, drmp3_seek_origin_current)) {
- return DRMP3_FALSE;
+ if (!ma_dr_mp3__on_seek(pMP3, (int)offset, ma_dr_mp3_seek_origin_current)) {
+ return MA_FALSE;
}
offset = 0;
} else {
- if (!drmp3__on_seek(pMP3, 0x7FFFFFFF, drmp3_seek_origin_current)) {
- return DRMP3_FALSE;
+ if (!ma_dr_mp3__on_seek(pMP3, 0x7FFFFFFF, ma_dr_mp3_seek_origin_current)) {
+ return MA_FALSE;
}
offset -= 0x7FFFFFFF;
}
}
- return DRMP3_TRUE;
+ return MA_TRUE;
}
-static drmp3_uint32 drmp3_decode_next_frame_ex__callbacks(drmp3* pMP3, drmp3d_sample_t* pPCMFrames)
+static ma_uint32 ma_dr_mp3_decode_next_frame_ex__callbacks(ma_dr_mp3* pMP3, ma_dr_mp3d_sample_t* pPCMFrames)
{
- drmp3_uint32 pcmFramesRead = 0;
- DRMP3_ASSERT(pMP3 != NULL);
- DRMP3_ASSERT(pMP3->onRead != NULL);
+ ma_uint32 pcmFramesRead = 0;
+ MA_DR_MP3_ASSERT(pMP3 != NULL);
+ MA_DR_MP3_ASSERT(pMP3->onRead != NULL);
if (pMP3->atEnd) {
return 0;
}
for (;;) {
- drmp3dec_frame_info info;
- if (pMP3->dataSize < DRMP3_MIN_DATA_CHUNK_SIZE) {
+ ma_dr_mp3dec_frame_info info;
+ if (pMP3->dataSize < MA_DR_MP3_MIN_DATA_CHUNK_SIZE) {
size_t bytesRead;
if (pMP3->pData != NULL) {
- DRMP3_MOVE_MEMORY(pMP3->pData, pMP3->pData + pMP3->dataConsumed, pMP3->dataSize);
+ MA_DR_MP3_MOVE_MEMORY(pMP3->pData, pMP3->pData + pMP3->dataConsumed, pMP3->dataSize);
}
pMP3->dataConsumed = 0;
- if (pMP3->dataCapacity < DRMP3_DATA_CHUNK_SIZE) {
- drmp3_uint8* pNewData;
+ if (pMP3->dataCapacity < MA_DR_MP3_DATA_CHUNK_SIZE) {
+ ma_uint8* pNewData;
size_t newDataCap;
- newDataCap = DRMP3_DATA_CHUNK_SIZE;
- pNewData = (drmp3_uint8*)drmp3__realloc_from_callbacks(pMP3->pData, newDataCap, pMP3->dataCapacity, &pMP3->allocationCallbacks);
+ newDataCap = MA_DR_MP3_DATA_CHUNK_SIZE;
+ pNewData = (ma_uint8*)ma_dr_mp3__realloc_from_callbacks(pMP3->pData, newDataCap, pMP3->dataCapacity, &pMP3->allocationCallbacks);
if (pNewData == NULL) {
return 0;
}
pMP3->pData = pNewData;
pMP3->dataCapacity = newDataCap;
}
- bytesRead = drmp3__on_read(pMP3, pMP3->pData + pMP3->dataSize, (pMP3->dataCapacity - pMP3->dataSize));
+ bytesRead = ma_dr_mp3__on_read(pMP3, pMP3->pData + pMP3->dataSize, (pMP3->dataCapacity - pMP3->dataSize));
if (bytesRead == 0) {
if (pMP3->dataSize == 0) {
- pMP3->atEnd = DRMP3_TRUE;
+ pMP3->atEnd = MA_TRUE;
return 0;
}
}
pMP3->dataSize += bytesRead;
}
if (pMP3->dataSize > INT_MAX) {
- pMP3->atEnd = DRMP3_TRUE;
+ pMP3->atEnd = MA_TRUE;
+ return 0;
+ }
+ MA_DR_MP3_ASSERT(pMP3->pData != NULL);
+ MA_DR_MP3_ASSERT(pMP3->dataCapacity > 0);
+ if (pMP3->pData == NULL) {
return 0;
}
- DRMP3_ASSERT(pMP3->pData != NULL);
- DRMP3_ASSERT(pMP3->dataCapacity > 0);
- pcmFramesRead = drmp3dec_decode_frame(&pMP3->decoder, pMP3->pData + pMP3->dataConsumed, (int)pMP3->dataSize, pPCMFrames, &info);
+ pcmFramesRead = ma_dr_mp3dec_decode_frame(&pMP3->decoder, pMP3->pData + pMP3->dataConsumed, (int)pMP3->dataSize, pPCMFrames, &info);
if (info.frame_bytes > 0) {
pMP3->dataConsumed += (size_t)info.frame_bytes;
pMP3->dataSize -= (size_t)info.frame_bytes;
}
if (pcmFramesRead > 0) {
- pcmFramesRead = drmp3_hdr_frame_samples(pMP3->decoder.header);
+ pcmFramesRead = ma_dr_mp3_hdr_frame_samples(pMP3->decoder.header);
pMP3->pcmFramesConsumedInMP3Frame = 0;
pMP3->pcmFramesRemainingInMP3Frame = pcmFramesRead;
pMP3->mp3FrameChannels = info.channels;
@@ -89839,22 +91744,22 @@ static drmp3_uint32 drmp3_decode_next_frame_ex__callbacks(drmp3* pMP3, drmp3d_sa
break;
} else if (info.frame_bytes == 0) {
size_t bytesRead;
- DRMP3_MOVE_MEMORY(pMP3->pData, pMP3->pData + pMP3->dataConsumed, pMP3->dataSize);
+ MA_DR_MP3_MOVE_MEMORY(pMP3->pData, pMP3->pData + pMP3->dataConsumed, pMP3->dataSize);
pMP3->dataConsumed = 0;
if (pMP3->dataCapacity == pMP3->dataSize) {
- drmp3_uint8* pNewData;
+ ma_uint8* pNewData;
size_t newDataCap;
- newDataCap = pMP3->dataCapacity + DRMP3_DATA_CHUNK_SIZE;
- pNewData = (drmp3_uint8*)drmp3__realloc_from_callbacks(pMP3->pData, newDataCap, pMP3->dataCapacity, &pMP3->allocationCallbacks);
+ newDataCap = pMP3->dataCapacity + MA_DR_MP3_DATA_CHUNK_SIZE;
+ pNewData = (ma_uint8*)ma_dr_mp3__realloc_from_callbacks(pMP3->pData, newDataCap, pMP3->dataCapacity, &pMP3->allocationCallbacks);
if (pNewData == NULL) {
return 0;
}
pMP3->pData = pNewData;
pMP3->dataCapacity = newDataCap;
}
- bytesRead = drmp3__on_read(pMP3, pMP3->pData + pMP3->dataSize, (pMP3->dataCapacity - pMP3->dataSize));
+ bytesRead = ma_dr_mp3__on_read(pMP3, pMP3->pData + pMP3->dataSize, (pMP3->dataCapacity - pMP3->dataSize));
if (bytesRead == 0) {
- pMP3->atEnd = DRMP3_TRUE;
+ pMP3->atEnd = MA_TRUE;
return 0;
}
pMP3->dataSize += bytesRead;
@@ -89862,19 +91767,19 @@ static drmp3_uint32 drmp3_decode_next_frame_ex__callbacks(drmp3* pMP3, drmp3d_sa
};
return pcmFramesRead;
}
-static drmp3_uint32 drmp3_decode_next_frame_ex__memory(drmp3* pMP3, drmp3d_sample_t* pPCMFrames)
+static ma_uint32 ma_dr_mp3_decode_next_frame_ex__memory(ma_dr_mp3* pMP3, ma_dr_mp3d_sample_t* pPCMFrames)
{
- drmp3_uint32 pcmFramesRead = 0;
- drmp3dec_frame_info info;
- DRMP3_ASSERT(pMP3 != NULL);
- DRMP3_ASSERT(pMP3->memory.pData != NULL);
+ ma_uint32 pcmFramesRead = 0;
+ ma_dr_mp3dec_frame_info info;
+ MA_DR_MP3_ASSERT(pMP3 != NULL);
+ MA_DR_MP3_ASSERT(pMP3->memory.pData != NULL);
if (pMP3->atEnd) {
return 0;
}
for (;;) {
- pcmFramesRead = drmp3dec_decode_frame(&pMP3->decoder, pMP3->memory.pData + pMP3->memory.currentReadPos, (int)(pMP3->memory.dataSize - pMP3->memory.currentReadPos), pPCMFrames, &info);
+ pcmFramesRead = ma_dr_mp3dec_decode_frame(&pMP3->decoder, pMP3->memory.pData + pMP3->memory.currentReadPos, (int)(pMP3->memory.dataSize - pMP3->memory.currentReadPos), pPCMFrames, &info);
if (pcmFramesRead > 0) {
- pcmFramesRead = drmp3_hdr_frame_samples(pMP3->decoder.header);
+ pcmFramesRead = ma_dr_mp3_hdr_frame_samples(pMP3->decoder.header);
pMP3->pcmFramesConsumedInMP3Frame = 0;
pMP3->pcmFramesRemainingInMP3Frame = pcmFramesRead;
pMP3->mp3FrameChannels = info.channels;
@@ -89889,25 +91794,25 @@ static drmp3_uint32 drmp3_decode_next_frame_ex__memory(drmp3* pMP3, drmp3d_sampl
pMP3->memory.currentReadPos += (size_t)info.frame_bytes;
return pcmFramesRead;
}
-static drmp3_uint32 drmp3_decode_next_frame_ex(drmp3* pMP3, drmp3d_sample_t* pPCMFrames)
+static ma_uint32 ma_dr_mp3_decode_next_frame_ex(ma_dr_mp3* pMP3, ma_dr_mp3d_sample_t* pPCMFrames)
{
if (pMP3->memory.pData != NULL && pMP3->memory.dataSize > 0) {
- return drmp3_decode_next_frame_ex__memory(pMP3, pPCMFrames);
+ return ma_dr_mp3_decode_next_frame_ex__memory(pMP3, pPCMFrames);
} else {
- return drmp3_decode_next_frame_ex__callbacks(pMP3, pPCMFrames);
+ return ma_dr_mp3_decode_next_frame_ex__callbacks(pMP3, pPCMFrames);
}
}
-static drmp3_uint32 drmp3_decode_next_frame(drmp3* pMP3)
+static ma_uint32 ma_dr_mp3_decode_next_frame(ma_dr_mp3* pMP3)
{
- DRMP3_ASSERT(pMP3 != NULL);
- return drmp3_decode_next_frame_ex(pMP3, (drmp3d_sample_t*)pMP3->pcmFrames);
+ MA_DR_MP3_ASSERT(pMP3 != NULL);
+ return ma_dr_mp3_decode_next_frame_ex(pMP3, (ma_dr_mp3d_sample_t*)pMP3->pcmFrames);
}
#if 0
-static drmp3_uint32 drmp3_seek_next_frame(drmp3* pMP3)
+static ma_uint32 ma_dr_mp3_seek_next_frame(ma_dr_mp3* pMP3)
{
- drmp3_uint32 pcmFrameCount;
- DRMP3_ASSERT(pMP3 != NULL);
- pcmFrameCount = drmp3_decode_next_frame_ex(pMP3, NULL);
+ ma_uint32 pcmFrameCount;
+ MA_DR_MP3_ASSERT(pMP3 != NULL);
+ pcmFrameCount = ma_dr_mp3_decode_next_frame_ex(pMP3, NULL);
if (pcmFrameCount == 0) {
return 0;
}
@@ -89917,55 +91822,55 @@ static drmp3_uint32 drmp3_seek_next_frame(drmp3* pMP3)
return pcmFrameCount;
}
#endif
-static drmp3_bool32 drmp3_init_internal(drmp3* pMP3, drmp3_read_proc onRead, drmp3_seek_proc onSeek, void* pUserData, const drmp3_allocation_callbacks* pAllocationCallbacks)
+static ma_bool32 ma_dr_mp3_init_internal(ma_dr_mp3* pMP3, ma_dr_mp3_read_proc onRead, ma_dr_mp3_seek_proc onSeek, void* pUserData, const ma_allocation_callbacks* pAllocationCallbacks)
{
- DRMP3_ASSERT(pMP3 != NULL);
- DRMP3_ASSERT(onRead != NULL);
- drmp3dec_init(&pMP3->decoder);
+ MA_DR_MP3_ASSERT(pMP3 != NULL);
+ MA_DR_MP3_ASSERT(onRead != NULL);
+ ma_dr_mp3dec_init(&pMP3->decoder);
pMP3->onRead = onRead;
pMP3->onSeek = onSeek;
pMP3->pUserData = pUserData;
- pMP3->allocationCallbacks = drmp3_copy_allocation_callbacks_or_defaults(pAllocationCallbacks);
+ pMP3->allocationCallbacks = ma_dr_mp3_copy_allocation_callbacks_or_defaults(pAllocationCallbacks);
if (pMP3->allocationCallbacks.onFree == NULL || (pMP3->allocationCallbacks.onMalloc == NULL && pMP3->allocationCallbacks.onRealloc == NULL)) {
- return DRMP3_FALSE;
+ return MA_FALSE;
}
- if (drmp3_decode_next_frame(pMP3) == 0) {
- drmp3__free_from_callbacks(pMP3->pData, &pMP3->allocationCallbacks);
- return DRMP3_FALSE;
+ if (ma_dr_mp3_decode_next_frame(pMP3) == 0) {
+ ma_dr_mp3__free_from_callbacks(pMP3->pData, &pMP3->allocationCallbacks);
+ return MA_FALSE;
}
pMP3->channels = pMP3->mp3FrameChannels;
pMP3->sampleRate = pMP3->mp3FrameSampleRate;
- return DRMP3_TRUE;
+ return MA_TRUE;
}
-DRMP3_API drmp3_bool32 drmp3_init(drmp3* pMP3, drmp3_read_proc onRead, drmp3_seek_proc onSeek, void* pUserData, const drmp3_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_bool32 ma_dr_mp3_init(ma_dr_mp3* pMP3, ma_dr_mp3_read_proc onRead, ma_dr_mp3_seek_proc onSeek, void* pUserData, const ma_allocation_callbacks* pAllocationCallbacks)
{
if (pMP3 == NULL || onRead == NULL) {
- return DRMP3_FALSE;
+ return MA_FALSE;
}
- DRMP3_ZERO_OBJECT(pMP3);
- return drmp3_init_internal(pMP3, onRead, onSeek, pUserData, pAllocationCallbacks);
+ MA_DR_MP3_ZERO_OBJECT(pMP3);
+ return ma_dr_mp3_init_internal(pMP3, onRead, onSeek, pUserData, pAllocationCallbacks);
}
-static size_t drmp3__on_read_memory(void* pUserData, void* pBufferOut, size_t bytesToRead)
+static size_t ma_dr_mp3__on_read_memory(void* pUserData, void* pBufferOut, size_t bytesToRead)
{
- drmp3* pMP3 = (drmp3*)pUserData;
+ ma_dr_mp3* pMP3 = (ma_dr_mp3*)pUserData;
size_t bytesRemaining;
- DRMP3_ASSERT(pMP3 != NULL);
- DRMP3_ASSERT(pMP3->memory.dataSize >= pMP3->memory.currentReadPos);
+ MA_DR_MP3_ASSERT(pMP3 != NULL);
+ MA_DR_MP3_ASSERT(pMP3->memory.dataSize >= pMP3->memory.currentReadPos);
bytesRemaining = pMP3->memory.dataSize - pMP3->memory.currentReadPos;
if (bytesToRead > bytesRemaining) {
bytesToRead = bytesRemaining;
}
if (bytesToRead > 0) {
- DRMP3_COPY_MEMORY(pBufferOut, pMP3->memory.pData + pMP3->memory.currentReadPos, bytesToRead);
+ MA_DR_MP3_COPY_MEMORY(pBufferOut, pMP3->memory.pData + pMP3->memory.currentReadPos, bytesToRead);
pMP3->memory.currentReadPos += bytesToRead;
}
return bytesToRead;
}
-static drmp3_bool32 drmp3__on_seek_memory(void* pUserData, int byteOffset, drmp3_seek_origin origin)
+static ma_bool32 ma_dr_mp3__on_seek_memory(void* pUserData, int byteOffset, ma_dr_mp3_seek_origin origin)
{
- drmp3* pMP3 = (drmp3*)pUserData;
- DRMP3_ASSERT(pMP3 != NULL);
- if (origin == drmp3_seek_origin_current) {
+ ma_dr_mp3* pMP3 = (ma_dr_mp3*)pUserData;
+ MA_DR_MP3_ASSERT(pMP3 != NULL);
+ if (origin == ma_dr_mp3_seek_origin_current) {
if (byteOffset > 0) {
if (pMP3->memory.currentReadPos + byteOffset > pMP3->memory.dataSize) {
byteOffset = (int)(pMP3->memory.dataSize - pMP3->memory.currentReadPos);
@@ -89977,585 +91882,75 @@ static drmp3_bool32 drmp3__on_seek_memory(void* pUserData, int byteOffset, drmp3
}
pMP3->memory.currentReadPos += byteOffset;
} else {
- if ((drmp3_uint32)byteOffset <= pMP3->memory.dataSize) {
+ if ((ma_uint32)byteOffset <= pMP3->memory.dataSize) {
pMP3->memory.currentReadPos = byteOffset;
} else {
pMP3->memory.currentReadPos = pMP3->memory.dataSize;
}
}
- return DRMP3_TRUE;
+ return MA_TRUE;
}
-DRMP3_API drmp3_bool32 drmp3_init_memory(drmp3* pMP3, const void* pData, size_t dataSize, const drmp3_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_bool32 ma_dr_mp3_init_memory(ma_dr_mp3* pMP3, const void* pData, size_t dataSize, const ma_allocation_callbacks* pAllocationCallbacks)
{
if (pMP3 == NULL) {
- return DRMP3_FALSE;
+ return MA_FALSE;
}
- DRMP3_ZERO_OBJECT(pMP3);
+ MA_DR_MP3_ZERO_OBJECT(pMP3);
if (pData == NULL || dataSize == 0) {
- return DRMP3_FALSE;
+ return MA_FALSE;
}
- pMP3->memory.pData = (const drmp3_uint8*)pData;
+ pMP3->memory.pData = (const ma_uint8*)pData;
pMP3->memory.dataSize = dataSize;
pMP3->memory.currentReadPos = 0;
- return drmp3_init_internal(pMP3, drmp3__on_read_memory, drmp3__on_seek_memory, pMP3, pAllocationCallbacks);
+ return ma_dr_mp3_init_internal(pMP3, ma_dr_mp3__on_read_memory, ma_dr_mp3__on_seek_memory, pMP3, pAllocationCallbacks);
}
-#ifndef DR_MP3_NO_STDIO
+#ifndef MA_DR_MP3_NO_STDIO
#include
#include
-#include
-static drmp3_result drmp3_result_from_errno(int e)
-{
- switch (e)
- {
- case 0: return DRMP3_SUCCESS;
- #ifdef EPERM
- case EPERM: return DRMP3_INVALID_OPERATION;
- #endif
- #ifdef ENOENT
- case ENOENT: return DRMP3_DOES_NOT_EXIST;
- #endif
- #ifdef ESRCH
- case ESRCH: return DRMP3_DOES_NOT_EXIST;
- #endif
- #ifdef EINTR
- case EINTR: return DRMP3_INTERRUPT;
- #endif
- #ifdef EIO
- case EIO: return DRMP3_IO_ERROR;
- #endif
- #ifdef ENXIO
- case ENXIO: return DRMP3_DOES_NOT_EXIST;
- #endif
- #ifdef E2BIG
- case E2BIG: return DRMP3_INVALID_ARGS;
- #endif
- #ifdef ENOEXEC
- case ENOEXEC: return DRMP3_INVALID_FILE;
- #endif
- #ifdef EBADF
- case EBADF: return DRMP3_INVALID_FILE;
- #endif
- #ifdef ECHILD
- case ECHILD: return DRMP3_ERROR;
- #endif
- #ifdef EAGAIN
- case EAGAIN: return DRMP3_UNAVAILABLE;
- #endif
- #ifdef ENOMEM
- case ENOMEM: return DRMP3_OUT_OF_MEMORY;
- #endif
- #ifdef EACCES
- case EACCES: return DRMP3_ACCESS_DENIED;
- #endif
- #ifdef EFAULT
- case EFAULT: return DRMP3_BAD_ADDRESS;
- #endif
- #ifdef ENOTBLK
- case ENOTBLK: return DRMP3_ERROR;
- #endif
- #ifdef EBUSY
- case EBUSY: return DRMP3_BUSY;
- #endif
- #ifdef EEXIST
- case EEXIST: return DRMP3_ALREADY_EXISTS;
- #endif
- #ifdef EXDEV
- case EXDEV: return DRMP3_ERROR;
- #endif
- #ifdef ENODEV
- case ENODEV: return DRMP3_DOES_NOT_EXIST;
- #endif
- #ifdef ENOTDIR
- case ENOTDIR: return DRMP3_NOT_DIRECTORY;
- #endif
- #ifdef EISDIR
- case EISDIR: return DRMP3_IS_DIRECTORY;
- #endif
- #ifdef EINVAL
- case EINVAL: return DRMP3_INVALID_ARGS;
- #endif
- #ifdef ENFILE
- case ENFILE: return DRMP3_TOO_MANY_OPEN_FILES;
- #endif
- #ifdef EMFILE
- case EMFILE: return DRMP3_TOO_MANY_OPEN_FILES;
- #endif
- #ifdef ENOTTY
- case ENOTTY: return DRMP3_INVALID_OPERATION;
- #endif
- #ifdef ETXTBSY
- case ETXTBSY: return DRMP3_BUSY;
- #endif
- #ifdef EFBIG
- case EFBIG: return DRMP3_TOO_BIG;
- #endif
- #ifdef ENOSPC
- case ENOSPC: return DRMP3_NO_SPACE;
- #endif
- #ifdef ESPIPE
- case ESPIPE: return DRMP3_BAD_SEEK;
- #endif
- #ifdef EROFS
- case EROFS: return DRMP3_ACCESS_DENIED;
- #endif
- #ifdef EMLINK
- case EMLINK: return DRMP3_TOO_MANY_LINKS;
- #endif
- #ifdef EPIPE
- case EPIPE: return DRMP3_BAD_PIPE;
- #endif
- #ifdef EDOM
- case EDOM: return DRMP3_OUT_OF_RANGE;
- #endif
- #ifdef ERANGE
- case ERANGE: return DRMP3_OUT_OF_RANGE;
- #endif
- #ifdef EDEADLK
- case EDEADLK: return DRMP3_DEADLOCK;
- #endif
- #ifdef ENAMETOOLONG
- case ENAMETOOLONG: return DRMP3_PATH_TOO_LONG;
- #endif
- #ifdef ENOLCK
- case ENOLCK: return DRMP3_ERROR;
- #endif
- #ifdef ENOSYS
- case ENOSYS: return DRMP3_NOT_IMPLEMENTED;
- #endif
- #ifdef ENOTEMPTY
- case ENOTEMPTY: return DRMP3_DIRECTORY_NOT_EMPTY;
- #endif
- #ifdef ELOOP
- case ELOOP: return DRMP3_TOO_MANY_LINKS;
- #endif
- #ifdef ENOMSG
- case ENOMSG: return DRMP3_NO_MESSAGE;
- #endif
- #ifdef EIDRM
- case EIDRM: return DRMP3_ERROR;
- #endif
- #ifdef ECHRNG
- case ECHRNG: return DRMP3_ERROR;
- #endif
- #ifdef EL2NSYNC
- case EL2NSYNC: return DRMP3_ERROR;
- #endif
- #ifdef EL3HLT
- case EL3HLT: return DRMP3_ERROR;
- #endif
- #ifdef EL3RST
- case EL3RST: return DRMP3_ERROR;
- #endif
- #ifdef ELNRNG
- case ELNRNG: return DRMP3_OUT_OF_RANGE;
- #endif
- #ifdef EUNATCH
- case EUNATCH: return DRMP3_ERROR;
- #endif
- #ifdef ENOCSI
- case ENOCSI: return DRMP3_ERROR;
- #endif
- #ifdef EL2HLT
- case EL2HLT: return DRMP3_ERROR;
- #endif
- #ifdef EBADE
- case EBADE: return DRMP3_ERROR;
- #endif
- #ifdef EBADR
- case EBADR: return DRMP3_ERROR;
- #endif
- #ifdef EXFULL
- case EXFULL: return DRMP3_ERROR;
- #endif
- #ifdef ENOANO
- case ENOANO: return DRMP3_ERROR;
- #endif
- #ifdef EBADRQC
- case EBADRQC: return DRMP3_ERROR;
- #endif
- #ifdef EBADSLT
- case EBADSLT: return DRMP3_ERROR;
- #endif
- #ifdef EBFONT
- case EBFONT: return DRMP3_INVALID_FILE;
- #endif
- #ifdef ENOSTR
- case ENOSTR: return DRMP3_ERROR;
- #endif
- #ifdef ENODATA
- case ENODATA: return DRMP3_NO_DATA_AVAILABLE;
- #endif
- #ifdef ETIME
- case ETIME: return DRMP3_TIMEOUT;
- #endif
- #ifdef ENOSR
- case ENOSR: return DRMP3_NO_DATA_AVAILABLE;
- #endif
- #ifdef ENONET
- case ENONET: return DRMP3_NO_NETWORK;
- #endif
- #ifdef ENOPKG
- case ENOPKG: return DRMP3_ERROR;
- #endif
- #ifdef EREMOTE
- case EREMOTE: return DRMP3_ERROR;
- #endif
- #ifdef ENOLINK
- case ENOLINK: return DRMP3_ERROR;
- #endif
- #ifdef EADV
- case EADV: return DRMP3_ERROR;
- #endif
- #ifdef ESRMNT
- case ESRMNT: return DRMP3_ERROR;
- #endif
- #ifdef ECOMM
- case ECOMM: return DRMP3_ERROR;
- #endif
- #ifdef EPROTO
- case EPROTO: return DRMP3_ERROR;
- #endif
- #ifdef EMULTIHOP
- case EMULTIHOP: return DRMP3_ERROR;
- #endif
- #ifdef EDOTDOT
- case EDOTDOT: return DRMP3_ERROR;
- #endif
- #ifdef EBADMSG
- case EBADMSG: return DRMP3_BAD_MESSAGE;
- #endif
- #ifdef EOVERFLOW
- case EOVERFLOW: return DRMP3_TOO_BIG;
- #endif
- #ifdef ENOTUNIQ
- case ENOTUNIQ: return DRMP3_NOT_UNIQUE;
- #endif
- #ifdef EBADFD
- case EBADFD: return DRMP3_ERROR;
- #endif
- #ifdef EREMCHG
- case EREMCHG: return DRMP3_ERROR;
- #endif
- #ifdef ELIBACC
- case ELIBACC: return DRMP3_ACCESS_DENIED;
- #endif
- #ifdef ELIBBAD
- case ELIBBAD: return DRMP3_INVALID_FILE;
- #endif
- #ifdef ELIBSCN
- case ELIBSCN: return DRMP3_INVALID_FILE;
- #endif
- #ifdef ELIBMAX
- case ELIBMAX: return DRMP3_ERROR;
- #endif
- #ifdef ELIBEXEC
- case ELIBEXEC: return DRMP3_ERROR;
- #endif
- #ifdef EILSEQ
- case EILSEQ: return DRMP3_INVALID_DATA;
- #endif
- #ifdef ERESTART
- case ERESTART: return DRMP3_ERROR;
- #endif
- #ifdef ESTRPIPE
- case ESTRPIPE: return DRMP3_ERROR;
- #endif
- #ifdef EUSERS
- case EUSERS: return DRMP3_ERROR;
- #endif
- #ifdef ENOTSOCK
- case ENOTSOCK: return DRMP3_NOT_SOCKET;
- #endif
- #ifdef EDESTADDRREQ
- case EDESTADDRREQ: return DRMP3_NO_ADDRESS;
- #endif
- #ifdef EMSGSIZE
- case EMSGSIZE: return DRMP3_TOO_BIG;
- #endif
- #ifdef EPROTOTYPE
- case EPROTOTYPE: return DRMP3_BAD_PROTOCOL;
- #endif
- #ifdef ENOPROTOOPT
- case ENOPROTOOPT: return DRMP3_PROTOCOL_UNAVAILABLE;
- #endif
- #ifdef EPROTONOSUPPORT
- case EPROTONOSUPPORT: return DRMP3_PROTOCOL_NOT_SUPPORTED;
- #endif
- #ifdef ESOCKTNOSUPPORT
- case ESOCKTNOSUPPORT: return DRMP3_SOCKET_NOT_SUPPORTED;
- #endif
- #ifdef EOPNOTSUPP
- case EOPNOTSUPP: return DRMP3_INVALID_OPERATION;
- #endif
- #ifdef EPFNOSUPPORT
- case EPFNOSUPPORT: return DRMP3_PROTOCOL_FAMILY_NOT_SUPPORTED;
- #endif
- #ifdef EAFNOSUPPORT
- case EAFNOSUPPORT: return DRMP3_ADDRESS_FAMILY_NOT_SUPPORTED;
- #endif
- #ifdef EADDRINUSE
- case EADDRINUSE: return DRMP3_ALREADY_IN_USE;
- #endif
- #ifdef EADDRNOTAVAIL
- case EADDRNOTAVAIL: return DRMP3_ERROR;
- #endif
- #ifdef ENETDOWN
- case ENETDOWN: return DRMP3_NO_NETWORK;
- #endif
- #ifdef ENETUNREACH
- case ENETUNREACH: return DRMP3_NO_NETWORK;
- #endif
- #ifdef ENETRESET
- case ENETRESET: return DRMP3_NO_NETWORK;
- #endif
- #ifdef ECONNABORTED
- case ECONNABORTED: return DRMP3_NO_NETWORK;
- #endif
- #ifdef ECONNRESET
- case ECONNRESET: return DRMP3_CONNECTION_RESET;
- #endif
- #ifdef ENOBUFS
- case ENOBUFS: return DRMP3_NO_SPACE;
- #endif
- #ifdef EISCONN
- case EISCONN: return DRMP3_ALREADY_CONNECTED;
- #endif
- #ifdef ENOTCONN
- case ENOTCONN: return DRMP3_NOT_CONNECTED;
- #endif
- #ifdef ESHUTDOWN
- case ESHUTDOWN: return DRMP3_ERROR;
- #endif
- #ifdef ETOOMANYREFS
- case ETOOMANYREFS: return DRMP3_ERROR;
- #endif
- #ifdef ETIMEDOUT
- case ETIMEDOUT: return DRMP3_TIMEOUT;
- #endif
- #ifdef ECONNREFUSED
- case ECONNREFUSED: return DRMP3_CONNECTION_REFUSED;
- #endif
- #ifdef EHOSTDOWN
- case EHOSTDOWN: return DRMP3_NO_HOST;
- #endif
- #ifdef EHOSTUNREACH
- case EHOSTUNREACH: return DRMP3_NO_HOST;
- #endif
- #ifdef EALREADY
- case EALREADY: return DRMP3_IN_PROGRESS;
- #endif
- #ifdef EINPROGRESS
- case EINPROGRESS: return DRMP3_IN_PROGRESS;
- #endif
- #ifdef ESTALE
- case ESTALE: return DRMP3_INVALID_FILE;
- #endif
- #ifdef EUCLEAN
- case EUCLEAN: return DRMP3_ERROR;
- #endif
- #ifdef ENOTNAM
- case ENOTNAM: return DRMP3_ERROR;
- #endif
- #ifdef ENAVAIL
- case ENAVAIL: return DRMP3_ERROR;
- #endif
- #ifdef EISNAM
- case EISNAM: return DRMP3_ERROR;
- #endif
- #ifdef EREMOTEIO
- case EREMOTEIO: return DRMP3_IO_ERROR;
- #endif
- #ifdef EDQUOT
- case EDQUOT: return DRMP3_NO_SPACE;
- #endif
- #ifdef ENOMEDIUM
- case ENOMEDIUM: return DRMP3_DOES_NOT_EXIST;
- #endif
- #ifdef EMEDIUMTYPE
- case EMEDIUMTYPE: return DRMP3_ERROR;
- #endif
- #ifdef ECANCELED
- case ECANCELED: return DRMP3_CANCELLED;
- #endif
- #ifdef ENOKEY
- case ENOKEY: return DRMP3_ERROR;
- #endif
- #ifdef EKEYEXPIRED
- case EKEYEXPIRED: return DRMP3_ERROR;
- #endif
- #ifdef EKEYREVOKED
- case EKEYREVOKED: return DRMP3_ERROR;
- #endif
- #ifdef EKEYREJECTED
- case EKEYREJECTED: return DRMP3_ERROR;
- #endif
- #ifdef EOWNERDEAD
- case EOWNERDEAD: return DRMP3_ERROR;
- #endif
- #ifdef ENOTRECOVERABLE
- case ENOTRECOVERABLE: return DRMP3_ERROR;
- #endif
- #ifdef ERFKILL
- case ERFKILL: return DRMP3_ERROR;
- #endif
- #ifdef EHWPOISON
- case EHWPOISON: return DRMP3_ERROR;
- #endif
- default: return DRMP3_ERROR;
- }
-}
-static drmp3_result drmp3_fopen(FILE** ppFile, const char* pFilePath, const char* pOpenMode)
-{
-#if defined(_MSC_VER) && _MSC_VER >= 1400
- errno_t err;
-#endif
- if (ppFile != NULL) {
- *ppFile = NULL;
- }
- if (pFilePath == NULL || pOpenMode == NULL || ppFile == NULL) {
- return DRMP3_INVALID_ARGS;
- }
-#if defined(_MSC_VER) && _MSC_VER >= 1400
- err = fopen_s(ppFile, pFilePath, pOpenMode);
- if (err != 0) {
- return drmp3_result_from_errno(err);
- }
-#else
-#if defined(_WIN32) || defined(__APPLE__)
- *ppFile = fopen(pFilePath, pOpenMode);
-#else
- #if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64 && defined(_LARGEFILE64_SOURCE)
- *ppFile = fopen64(pFilePath, pOpenMode);
- #else
- *ppFile = fopen(pFilePath, pOpenMode);
- #endif
-#endif
- if (*ppFile == NULL) {
- drmp3_result result = drmp3_result_from_errno(errno);
- if (result == DRMP3_SUCCESS) {
- result = DRMP3_ERROR;
- }
- return result;
- }
-#endif
- return DRMP3_SUCCESS;
-}
-#if defined(_WIN32)
- #if defined(_MSC_VER) || defined(__MINGW64__) || (!defined(__STRICT_ANSI__) && !defined(_NO_EXT_KEYS))
- #define DRMP3_HAS_WFOPEN
- #endif
-#endif
-static drmp3_result drmp3_wfopen(FILE** ppFile, const wchar_t* pFilePath, const wchar_t* pOpenMode, const drmp3_allocation_callbacks* pAllocationCallbacks)
-{
- if (ppFile != NULL) {
- *ppFile = NULL;
- }
- if (pFilePath == NULL || pOpenMode == NULL || ppFile == NULL) {
- return DRMP3_INVALID_ARGS;
- }
-#if defined(DRMP3_HAS_WFOPEN)
- {
- #if defined(_MSC_VER) && _MSC_VER >= 1400
- errno_t err = _wfopen_s(ppFile, pFilePath, pOpenMode);
- if (err != 0) {
- return drmp3_result_from_errno(err);
- }
- #else
- *ppFile = _wfopen(pFilePath, pOpenMode);
- if (*ppFile == NULL) {
- return drmp3_result_from_errno(errno);
- }
- #endif
- (void)pAllocationCallbacks;
- }
-#else
- #if defined(__DJGPP__)
- {
- }
- #else
- {
- mbstate_t mbs;
- size_t lenMB;
- const wchar_t* pFilePathTemp = pFilePath;
- char* pFilePathMB = NULL;
- char pOpenModeMB[32] = {0};
- DRMP3_ZERO_OBJECT(&mbs);
- lenMB = wcsrtombs(NULL, &pFilePathTemp, 0, &mbs);
- if (lenMB == (size_t)-1) {
- return drmp3_result_from_errno(errno);
- }
- pFilePathMB = (char*)drmp3__malloc_from_callbacks(lenMB + 1, pAllocationCallbacks);
- if (pFilePathMB == NULL) {
- return DRMP3_OUT_OF_MEMORY;
- }
- pFilePathTemp = pFilePath;
- DRMP3_ZERO_OBJECT(&mbs);
- wcsrtombs(pFilePathMB, &pFilePathTemp, lenMB + 1, &mbs);
- {
- size_t i = 0;
- for (;;) {
- if (pOpenMode[i] == 0) {
- pOpenModeMB[i] = '\0';
- break;
- }
- pOpenModeMB[i] = (char)pOpenMode[i];
- i += 1;
- }
- }
- *ppFile = fopen(pFilePathMB, pOpenModeMB);
- drmp3__free_from_callbacks(pFilePathMB, pAllocationCallbacks);
- }
- #endif
- if (*ppFile == NULL) {
- return DRMP3_ERROR;
- }
-#endif
- return DRMP3_SUCCESS;
-}
-static size_t drmp3__on_read_stdio(void* pUserData, void* pBufferOut, size_t bytesToRead)
+static size_t ma_dr_mp3__on_read_stdio(void* pUserData, void* pBufferOut, size_t bytesToRead)
{
return fread(pBufferOut, 1, bytesToRead, (FILE*)pUserData);
}
-static drmp3_bool32 drmp3__on_seek_stdio(void* pUserData, int offset, drmp3_seek_origin origin)
+static ma_bool32 ma_dr_mp3__on_seek_stdio(void* pUserData, int offset, ma_dr_mp3_seek_origin origin)
{
- return fseek((FILE*)pUserData, offset, (origin == drmp3_seek_origin_current) ? SEEK_CUR : SEEK_SET) == 0;
+ return fseek((FILE*)pUserData, offset, (origin == ma_dr_mp3_seek_origin_current) ? SEEK_CUR : SEEK_SET) == 0;
}
-DRMP3_API drmp3_bool32 drmp3_init_file(drmp3* pMP3, const char* pFilePath, const drmp3_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_bool32 ma_dr_mp3_init_file(ma_dr_mp3* pMP3, const char* pFilePath, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drmp3_bool32 result;
+ ma_bool32 result;
FILE* pFile;
- if (drmp3_fopen(&pFile, pFilePath, "rb") != DRMP3_SUCCESS) {
- return DRMP3_FALSE;
+ if (ma_fopen(&pFile, pFilePath, "rb") != MA_SUCCESS) {
+ return MA_FALSE;
}
- result = drmp3_init(pMP3, drmp3__on_read_stdio, drmp3__on_seek_stdio, (void*)pFile, pAllocationCallbacks);
- if (result != DRMP3_TRUE) {
+ result = ma_dr_mp3_init(pMP3, ma_dr_mp3__on_read_stdio, ma_dr_mp3__on_seek_stdio, (void*)pFile, pAllocationCallbacks);
+ if (result != MA_TRUE) {
fclose(pFile);
return result;
}
- return DRMP3_TRUE;
+ return MA_TRUE;
}
-DRMP3_API drmp3_bool32 drmp3_init_file_w(drmp3* pMP3, const wchar_t* pFilePath, const drmp3_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_bool32 ma_dr_mp3_init_file_w(ma_dr_mp3* pMP3, const wchar_t* pFilePath, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drmp3_bool32 result;
+ ma_bool32 result;
FILE* pFile;
- if (drmp3_wfopen(&pFile, pFilePath, L"rb", pAllocationCallbacks) != DRMP3_SUCCESS) {
- return DRMP3_FALSE;
+ if (ma_wfopen(&pFile, pFilePath, L"rb", pAllocationCallbacks) != MA_SUCCESS) {
+ return MA_FALSE;
}
- result = drmp3_init(pMP3, drmp3__on_read_stdio, drmp3__on_seek_stdio, (void*)pFile, pAllocationCallbacks);
- if (result != DRMP3_TRUE) {
+ result = ma_dr_mp3_init(pMP3, ma_dr_mp3__on_read_stdio, ma_dr_mp3__on_seek_stdio, (void*)pFile, pAllocationCallbacks);
+ if (result != MA_TRUE) {
fclose(pFile);
return result;
}
- return DRMP3_TRUE;
+ return MA_TRUE;
}
#endif
-DRMP3_API void drmp3_uninit(drmp3* pMP3)
+MA_API void ma_dr_mp3_uninit(ma_dr_mp3* pMP3)
{
if (pMP3 == NULL) {
return;
}
-#ifndef DR_MP3_NO_STDIO
- if (pMP3->onRead == drmp3__on_read_stdio) {
+#ifndef MA_DR_MP3_NO_STDIO
+ if (pMP3->onRead == ma_dr_mp3__on_read_stdio) {
FILE* pFile = (FILE*)pMP3->pUserData;
if (pFile != NULL) {
fclose(pFile);
@@ -90563,14 +91958,14 @@ DRMP3_API void drmp3_uninit(drmp3* pMP3)
}
}
#endif
- drmp3__free_from_callbacks(pMP3->pData, &pMP3->allocationCallbacks);
+ ma_dr_mp3__free_from_callbacks(pMP3->pData, &pMP3->allocationCallbacks);
}
-#if defined(DR_MP3_FLOAT_OUTPUT)
-static void drmp3_f32_to_s16(drmp3_int16* dst, const float* src, drmp3_uint64 sampleCount)
+#if defined(MA_DR_MP3_FLOAT_OUTPUT)
+static void ma_dr_mp3_f32_to_s16(ma_int16* dst, const float* src, ma_uint64 sampleCount)
{
- drmp3_uint64 i;
- drmp3_uint64 i4;
- drmp3_uint64 sampleCount4;
+ ma_uint64 i;
+ ma_uint64 i4;
+ ma_uint64 sampleCount4;
i = 0;
sampleCount4 = sampleCount >> 2;
for (i4 = 0; i4 < sampleCount4; i4 += 1) {
@@ -90586,24 +91981,24 @@ static void drmp3_f32_to_s16(drmp3_int16* dst, const float* src, drmp3_uint64 sa
x1 = x1 * 32767.0f;
x2 = x2 * 32767.0f;
x3 = x3 * 32767.0f;
- dst[i+0] = (drmp3_int16)x0;
- dst[i+1] = (drmp3_int16)x1;
- dst[i+2] = (drmp3_int16)x2;
- dst[i+3] = (drmp3_int16)x3;
+ dst[i+0] = (ma_int16)x0;
+ dst[i+1] = (ma_int16)x1;
+ dst[i+2] = (ma_int16)x2;
+ dst[i+3] = (ma_int16)x3;
i += 4;
}
for (; i < sampleCount; i += 1) {
float x = src[i];
x = ((x < -1) ? -1 : ((x > 1) ? 1 : x));
x = x * 32767.0f;
- dst[i] = (drmp3_int16)x;
+ dst[i] = (ma_int16)x;
}
}
#endif
-#if !defined(DR_MP3_FLOAT_OUTPUT)
-static void drmp3_s16_to_f32(float* dst, const drmp3_int16* src, drmp3_uint64 sampleCount)
+#if !defined(MA_DR_MP3_FLOAT_OUTPUT)
+static void ma_dr_mp3_s16_to_f32(float* dst, const ma_int16* src, ma_uint64 sampleCount)
{
- drmp3_uint64 i;
+ ma_uint64 i;
for (i = 0; i < sampleCount; i += 1) {
float x = (float)src[i];
x = x * 0.000030517578125f;
@@ -90611,22 +92006,22 @@ static void drmp3_s16_to_f32(float* dst, const drmp3_int16* src, drmp3_uint64 sa
}
}
#endif
-static drmp3_uint64 drmp3_read_pcm_frames_raw(drmp3* pMP3, drmp3_uint64 framesToRead, void* pBufferOut)
+static ma_uint64 ma_dr_mp3_read_pcm_frames_raw(ma_dr_mp3* pMP3, ma_uint64 framesToRead, void* pBufferOut)
{
- drmp3_uint64 totalFramesRead = 0;
- DRMP3_ASSERT(pMP3 != NULL);
- DRMP3_ASSERT(pMP3->onRead != NULL);
+ ma_uint64 totalFramesRead = 0;
+ MA_DR_MP3_ASSERT(pMP3 != NULL);
+ MA_DR_MP3_ASSERT(pMP3->onRead != NULL);
while (framesToRead > 0) {
- drmp3_uint32 framesToConsume = (drmp3_uint32)DRMP3_MIN(pMP3->pcmFramesRemainingInMP3Frame, framesToRead);
+ ma_uint32 framesToConsume = (ma_uint32)MA_DR_MP3_MIN(pMP3->pcmFramesRemainingInMP3Frame, framesToRead);
if (pBufferOut != NULL) {
- #if defined(DR_MP3_FLOAT_OUTPUT)
- float* pFramesOutF32 = (float*)DRMP3_OFFSET_PTR(pBufferOut, sizeof(float) * totalFramesRead * pMP3->channels);
- float* pFramesInF32 = (float*)DRMP3_OFFSET_PTR(&pMP3->pcmFrames[0], sizeof(float) * pMP3->pcmFramesConsumedInMP3Frame * pMP3->mp3FrameChannels);
- DRMP3_COPY_MEMORY(pFramesOutF32, pFramesInF32, sizeof(float) * framesToConsume * pMP3->channels);
+ #if defined(MA_DR_MP3_FLOAT_OUTPUT)
+ float* pFramesOutF32 = (float*)MA_DR_MP3_OFFSET_PTR(pBufferOut, sizeof(float) * totalFramesRead * pMP3->channels);
+ float* pFramesInF32 = (float*)MA_DR_MP3_OFFSET_PTR(&pMP3->pcmFrames[0], sizeof(float) * pMP3->pcmFramesConsumedInMP3Frame * pMP3->mp3FrameChannels);
+ MA_DR_MP3_COPY_MEMORY(pFramesOutF32, pFramesInF32, sizeof(float) * framesToConsume * pMP3->channels);
#else
- drmp3_int16* pFramesOutS16 = (drmp3_int16*)DRMP3_OFFSET_PTR(pBufferOut, sizeof(drmp3_int16) * totalFramesRead * pMP3->channels);
- drmp3_int16* pFramesInS16 = (drmp3_int16*)DRMP3_OFFSET_PTR(&pMP3->pcmFrames[0], sizeof(drmp3_int16) * pMP3->pcmFramesConsumedInMP3Frame * pMP3->mp3FrameChannels);
- DRMP3_COPY_MEMORY(pFramesOutS16, pFramesInS16, sizeof(drmp3_int16) * framesToConsume * pMP3->channels);
+ ma_int16* pFramesOutS16 = (ma_int16*)MA_DR_MP3_OFFSET_PTR(pBufferOut, sizeof(ma_int16) * totalFramesRead * pMP3->channels);
+ ma_int16* pFramesInS16 = (ma_int16*)MA_DR_MP3_OFFSET_PTR(&pMP3->pcmFrames[0], sizeof(ma_int16) * pMP3->pcmFramesConsumedInMP3Frame * pMP3->mp3FrameChannels);
+ MA_DR_MP3_COPY_MEMORY(pFramesOutS16, pFramesInS16, sizeof(ma_int16) * framesToConsume * pMP3->channels);
#endif
}
pMP3->currentPCMFrame += framesToConsume;
@@ -90637,125 +92032,125 @@ static drmp3_uint64 drmp3_read_pcm_frames_raw(drmp3* pMP3, drmp3_uint64 framesTo
if (framesToRead == 0) {
break;
}
- DRMP3_ASSERT(pMP3->pcmFramesRemainingInMP3Frame == 0);
- if (drmp3_decode_next_frame(pMP3) == 0) {
+ MA_DR_MP3_ASSERT(pMP3->pcmFramesRemainingInMP3Frame == 0);
+ if (ma_dr_mp3_decode_next_frame(pMP3) == 0) {
break;
}
}
return totalFramesRead;
}
-DRMP3_API drmp3_uint64 drmp3_read_pcm_frames_f32(drmp3* pMP3, drmp3_uint64 framesToRead, float* pBufferOut)
+MA_API ma_uint64 ma_dr_mp3_read_pcm_frames_f32(ma_dr_mp3* pMP3, ma_uint64 framesToRead, float* pBufferOut)
{
if (pMP3 == NULL || pMP3->onRead == NULL) {
return 0;
}
-#if defined(DR_MP3_FLOAT_OUTPUT)
- return drmp3_read_pcm_frames_raw(pMP3, framesToRead, pBufferOut);
+#if defined(MA_DR_MP3_FLOAT_OUTPUT)
+ return ma_dr_mp3_read_pcm_frames_raw(pMP3, framesToRead, pBufferOut);
#else
{
- drmp3_int16 pTempS16[8192];
- drmp3_uint64 totalPCMFramesRead = 0;
+ ma_int16 pTempS16[8192];
+ ma_uint64 totalPCMFramesRead = 0;
while (totalPCMFramesRead < framesToRead) {
- drmp3_uint64 framesJustRead;
- drmp3_uint64 framesRemaining = framesToRead - totalPCMFramesRead;
- drmp3_uint64 framesToReadNow = DRMP3_COUNTOF(pTempS16) / pMP3->channels;
+ ma_uint64 framesJustRead;
+ ma_uint64 framesRemaining = framesToRead - totalPCMFramesRead;
+ ma_uint64 framesToReadNow = MA_DR_MP3_COUNTOF(pTempS16) / pMP3->channels;
if (framesToReadNow > framesRemaining) {
framesToReadNow = framesRemaining;
}
- framesJustRead = drmp3_read_pcm_frames_raw(pMP3, framesToReadNow, pTempS16);
+ framesJustRead = ma_dr_mp3_read_pcm_frames_raw(pMP3, framesToReadNow, pTempS16);
if (framesJustRead == 0) {
break;
}
- drmp3_s16_to_f32((float*)DRMP3_OFFSET_PTR(pBufferOut, sizeof(float) * totalPCMFramesRead * pMP3->channels), pTempS16, framesJustRead * pMP3->channels);
+ ma_dr_mp3_s16_to_f32((float*)MA_DR_MP3_OFFSET_PTR(pBufferOut, sizeof(float) * totalPCMFramesRead * pMP3->channels), pTempS16, framesJustRead * pMP3->channels);
totalPCMFramesRead += framesJustRead;
}
return totalPCMFramesRead;
}
#endif
}
-DRMP3_API drmp3_uint64 drmp3_read_pcm_frames_s16(drmp3* pMP3, drmp3_uint64 framesToRead, drmp3_int16* pBufferOut)
+MA_API ma_uint64 ma_dr_mp3_read_pcm_frames_s16(ma_dr_mp3* pMP3, ma_uint64 framesToRead, ma_int16* pBufferOut)
{
if (pMP3 == NULL || pMP3->onRead == NULL) {
return 0;
}
-#if !defined(DR_MP3_FLOAT_OUTPUT)
- return drmp3_read_pcm_frames_raw(pMP3, framesToRead, pBufferOut);
+#if !defined(MA_DR_MP3_FLOAT_OUTPUT)
+ return ma_dr_mp3_read_pcm_frames_raw(pMP3, framesToRead, pBufferOut);
#else
{
float pTempF32[4096];
- drmp3_uint64 totalPCMFramesRead = 0;
+ ma_uint64 totalPCMFramesRead = 0;
while (totalPCMFramesRead < framesToRead) {
- drmp3_uint64 framesJustRead;
- drmp3_uint64 framesRemaining = framesToRead - totalPCMFramesRead;
- drmp3_uint64 framesToReadNow = DRMP3_COUNTOF(pTempF32) / pMP3->channels;
+ ma_uint64 framesJustRead;
+ ma_uint64 framesRemaining = framesToRead - totalPCMFramesRead;
+ ma_uint64 framesToReadNow = MA_DR_MP3_COUNTOF(pTempF32) / pMP3->channels;
if (framesToReadNow > framesRemaining) {
framesToReadNow = framesRemaining;
}
- framesJustRead = drmp3_read_pcm_frames_raw(pMP3, framesToReadNow, pTempF32);
+ framesJustRead = ma_dr_mp3_read_pcm_frames_raw(pMP3, framesToReadNow, pTempF32);
if (framesJustRead == 0) {
break;
}
- drmp3_f32_to_s16((drmp3_int16*)DRMP3_OFFSET_PTR(pBufferOut, sizeof(drmp3_int16) * totalPCMFramesRead * pMP3->channels), pTempF32, framesJustRead * pMP3->channels);
+ ma_dr_mp3_f32_to_s16((ma_int16*)MA_DR_MP3_OFFSET_PTR(pBufferOut, sizeof(ma_int16) * totalPCMFramesRead * pMP3->channels), pTempF32, framesJustRead * pMP3->channels);
totalPCMFramesRead += framesJustRead;
}
return totalPCMFramesRead;
}
#endif
}
-static void drmp3_reset(drmp3* pMP3)
+static void ma_dr_mp3_reset(ma_dr_mp3* pMP3)
{
- DRMP3_ASSERT(pMP3 != NULL);
+ MA_DR_MP3_ASSERT(pMP3 != NULL);
pMP3->pcmFramesConsumedInMP3Frame = 0;
pMP3->pcmFramesRemainingInMP3Frame = 0;
pMP3->currentPCMFrame = 0;
pMP3->dataSize = 0;
- pMP3->atEnd = DRMP3_FALSE;
- drmp3dec_init(&pMP3->decoder);
+ pMP3->atEnd = MA_FALSE;
+ ma_dr_mp3dec_init(&pMP3->decoder);
}
-static drmp3_bool32 drmp3_seek_to_start_of_stream(drmp3* pMP3)
+static ma_bool32 ma_dr_mp3_seek_to_start_of_stream(ma_dr_mp3* pMP3)
{
- DRMP3_ASSERT(pMP3 != NULL);
- DRMP3_ASSERT(pMP3->onSeek != NULL);
- if (!drmp3__on_seek(pMP3, 0, drmp3_seek_origin_start)) {
- return DRMP3_FALSE;
+ MA_DR_MP3_ASSERT(pMP3 != NULL);
+ MA_DR_MP3_ASSERT(pMP3->onSeek != NULL);
+ if (!ma_dr_mp3__on_seek(pMP3, 0, ma_dr_mp3_seek_origin_start)) {
+ return MA_FALSE;
}
- drmp3_reset(pMP3);
- return DRMP3_TRUE;
+ ma_dr_mp3_reset(pMP3);
+ return MA_TRUE;
}
-static drmp3_bool32 drmp3_seek_forward_by_pcm_frames__brute_force(drmp3* pMP3, drmp3_uint64 frameOffset)
+static ma_bool32 ma_dr_mp3_seek_forward_by_pcm_frames__brute_force(ma_dr_mp3* pMP3, ma_uint64 frameOffset)
{
- drmp3_uint64 framesRead;
-#if defined(DR_MP3_FLOAT_OUTPUT)
- framesRead = drmp3_read_pcm_frames_f32(pMP3, frameOffset, NULL);
+ ma_uint64 framesRead;
+#if defined(MA_DR_MP3_FLOAT_OUTPUT)
+ framesRead = ma_dr_mp3_read_pcm_frames_f32(pMP3, frameOffset, NULL);
#else
- framesRead = drmp3_read_pcm_frames_s16(pMP3, frameOffset, NULL);
+ framesRead = ma_dr_mp3_read_pcm_frames_s16(pMP3, frameOffset, NULL);
#endif
if (framesRead != frameOffset) {
- return DRMP3_FALSE;
+ return MA_FALSE;
}
- return DRMP3_TRUE;
+ return MA_TRUE;
}
-static drmp3_bool32 drmp3_seek_to_pcm_frame__brute_force(drmp3* pMP3, drmp3_uint64 frameIndex)
+static ma_bool32 ma_dr_mp3_seek_to_pcm_frame__brute_force(ma_dr_mp3* pMP3, ma_uint64 frameIndex)
{
- DRMP3_ASSERT(pMP3 != NULL);
+ MA_DR_MP3_ASSERT(pMP3 != NULL);
if (frameIndex == pMP3->currentPCMFrame) {
- return DRMP3_TRUE;
+ return MA_TRUE;
}
if (frameIndex < pMP3->currentPCMFrame) {
- if (!drmp3_seek_to_start_of_stream(pMP3)) {
- return DRMP3_FALSE;
+ if (!ma_dr_mp3_seek_to_start_of_stream(pMP3)) {
+ return MA_FALSE;
}
}
- DRMP3_ASSERT(frameIndex >= pMP3->currentPCMFrame);
- return drmp3_seek_forward_by_pcm_frames__brute_force(pMP3, (frameIndex - pMP3->currentPCMFrame));
+ MA_DR_MP3_ASSERT(frameIndex >= pMP3->currentPCMFrame);
+ return ma_dr_mp3_seek_forward_by_pcm_frames__brute_force(pMP3, (frameIndex - pMP3->currentPCMFrame));
}
-static drmp3_bool32 drmp3_find_closest_seek_point(drmp3* pMP3, drmp3_uint64 frameIndex, drmp3_uint32* pSeekPointIndex)
+static ma_bool32 ma_dr_mp3_find_closest_seek_point(ma_dr_mp3* pMP3, ma_uint64 frameIndex, ma_uint32* pSeekPointIndex)
{
- drmp3_uint32 iSeekPoint;
- DRMP3_ASSERT(pSeekPointIndex != NULL);
+ ma_uint32 iSeekPoint;
+ MA_DR_MP3_ASSERT(pSeekPointIndex != NULL);
*pSeekPointIndex = 0;
if (frameIndex < pMP3->pSeekPoints[0].pcmFrameIndex) {
- return DRMP3_FALSE;
+ return MA_FALSE;
}
for (iSeekPoint = 0; iSeekPoint < pMP3->seekPointCount; ++iSeekPoint) {
if (pMP3->pSeekPoints[iSeekPoint].pcmFrameIndex > frameIndex) {
@@ -90763,18 +92158,18 @@ static drmp3_bool32 drmp3_find_closest_seek_point(drmp3* pMP3, drmp3_uint64 fram
}
*pSeekPointIndex = iSeekPoint;
}
- return DRMP3_TRUE;
+ return MA_TRUE;
}
-static drmp3_bool32 drmp3_seek_to_pcm_frame__seek_table(drmp3* pMP3, drmp3_uint64 frameIndex)
+static ma_bool32 ma_dr_mp3_seek_to_pcm_frame__seek_table(ma_dr_mp3* pMP3, ma_uint64 frameIndex)
{
- drmp3_seek_point seekPoint;
- drmp3_uint32 priorSeekPointIndex;
- drmp3_uint16 iMP3Frame;
- drmp3_uint64 leftoverFrames;
- DRMP3_ASSERT(pMP3 != NULL);
- DRMP3_ASSERT(pMP3->pSeekPoints != NULL);
- DRMP3_ASSERT(pMP3->seekPointCount > 0);
- if (drmp3_find_closest_seek_point(pMP3, frameIndex, &priorSeekPointIndex)) {
+ ma_dr_mp3_seek_point seekPoint;
+ ma_uint32 priorSeekPointIndex;
+ ma_uint16 iMP3Frame;
+ ma_uint64 leftoverFrames;
+ MA_DR_MP3_ASSERT(pMP3 != NULL);
+ MA_DR_MP3_ASSERT(pMP3->pSeekPoints != NULL);
+ MA_DR_MP3_ASSERT(pMP3->seekPointCount > 0);
+ if (ma_dr_mp3_find_closest_seek_point(pMP3, frameIndex, &priorSeekPointIndex)) {
seekPoint = pMP3->pSeekPoints[priorSeekPointIndex];
} else {
seekPoint.seekPosInBytes = 0;
@@ -90782,71 +92177,71 @@ static drmp3_bool32 drmp3_seek_to_pcm_frame__seek_table(drmp3* pMP3, drmp3_uint6
seekPoint.mp3FramesToDiscard = 0;
seekPoint.pcmFramesToDiscard = 0;
}
- if (!drmp3__on_seek_64(pMP3, seekPoint.seekPosInBytes, drmp3_seek_origin_start)) {
- return DRMP3_FALSE;
+ if (!ma_dr_mp3__on_seek_64(pMP3, seekPoint.seekPosInBytes, ma_dr_mp3_seek_origin_start)) {
+ return MA_FALSE;
}
- drmp3_reset(pMP3);
+ ma_dr_mp3_reset(pMP3);
for (iMP3Frame = 0; iMP3Frame < seekPoint.mp3FramesToDiscard; ++iMP3Frame) {
- drmp3_uint32 pcmFramesRead;
- drmp3d_sample_t* pPCMFrames;
+ ma_uint32 pcmFramesRead;
+ ma_dr_mp3d_sample_t* pPCMFrames;
pPCMFrames = NULL;
if (iMP3Frame == seekPoint.mp3FramesToDiscard-1) {
- pPCMFrames = (drmp3d_sample_t*)pMP3->pcmFrames;
+ pPCMFrames = (ma_dr_mp3d_sample_t*)pMP3->pcmFrames;
}
- pcmFramesRead = drmp3_decode_next_frame_ex(pMP3, pPCMFrames);
+ pcmFramesRead = ma_dr_mp3_decode_next_frame_ex(pMP3, pPCMFrames);
if (pcmFramesRead == 0) {
- return DRMP3_FALSE;
+ return MA_FALSE;
}
}
pMP3->currentPCMFrame = seekPoint.pcmFrameIndex - seekPoint.pcmFramesToDiscard;
leftoverFrames = frameIndex - pMP3->currentPCMFrame;
- return drmp3_seek_forward_by_pcm_frames__brute_force(pMP3, leftoverFrames);
+ return ma_dr_mp3_seek_forward_by_pcm_frames__brute_force(pMP3, leftoverFrames);
}
-DRMP3_API drmp3_bool32 drmp3_seek_to_pcm_frame(drmp3* pMP3, drmp3_uint64 frameIndex)
+MA_API ma_bool32 ma_dr_mp3_seek_to_pcm_frame(ma_dr_mp3* pMP3, ma_uint64 frameIndex)
{
if (pMP3 == NULL || pMP3->onSeek == NULL) {
- return DRMP3_FALSE;
+ return MA_FALSE;
}
if (frameIndex == 0) {
- return drmp3_seek_to_start_of_stream(pMP3);
+ return ma_dr_mp3_seek_to_start_of_stream(pMP3);
}
if (pMP3->pSeekPoints != NULL && pMP3->seekPointCount > 0) {
- return drmp3_seek_to_pcm_frame__seek_table(pMP3, frameIndex);
+ return ma_dr_mp3_seek_to_pcm_frame__seek_table(pMP3, frameIndex);
} else {
- return drmp3_seek_to_pcm_frame__brute_force(pMP3, frameIndex);
+ return ma_dr_mp3_seek_to_pcm_frame__brute_force(pMP3, frameIndex);
}
}
-DRMP3_API drmp3_bool32 drmp3_get_mp3_and_pcm_frame_count(drmp3* pMP3, drmp3_uint64* pMP3FrameCount, drmp3_uint64* pPCMFrameCount)
+MA_API ma_bool32 ma_dr_mp3_get_mp3_and_pcm_frame_count(ma_dr_mp3* pMP3, ma_uint64* pMP3FrameCount, ma_uint64* pPCMFrameCount)
{
- drmp3_uint64 currentPCMFrame;
- drmp3_uint64 totalPCMFrameCount;
- drmp3_uint64 totalMP3FrameCount;
+ ma_uint64 currentPCMFrame;
+ ma_uint64 totalPCMFrameCount;
+ ma_uint64 totalMP3FrameCount;
if (pMP3 == NULL) {
- return DRMP3_FALSE;
+ return MA_FALSE;
}
if (pMP3->onSeek == NULL) {
- return DRMP3_FALSE;
+ return MA_FALSE;
}
currentPCMFrame = pMP3->currentPCMFrame;
- if (!drmp3_seek_to_start_of_stream(pMP3)) {
- return DRMP3_FALSE;
+ if (!ma_dr_mp3_seek_to_start_of_stream(pMP3)) {
+ return MA_FALSE;
}
totalPCMFrameCount = 0;
totalMP3FrameCount = 0;
for (;;) {
- drmp3_uint32 pcmFramesInCurrentMP3Frame;
- pcmFramesInCurrentMP3Frame = drmp3_decode_next_frame_ex(pMP3, NULL);
+ ma_uint32 pcmFramesInCurrentMP3Frame;
+ pcmFramesInCurrentMP3Frame = ma_dr_mp3_decode_next_frame_ex(pMP3, NULL);
if (pcmFramesInCurrentMP3Frame == 0) {
break;
}
totalPCMFrameCount += pcmFramesInCurrentMP3Frame;
totalMP3FrameCount += 1;
}
- if (!drmp3_seek_to_start_of_stream(pMP3)) {
- return DRMP3_FALSE;
+ if (!ma_dr_mp3_seek_to_start_of_stream(pMP3)) {
+ return MA_FALSE;
}
- if (!drmp3_seek_to_pcm_frame(pMP3, currentPCMFrame)) {
- return DRMP3_FALSE;
+ if (!ma_dr_mp3_seek_to_pcm_frame(pMP3, currentPCMFrame)) {
+ return MA_FALSE;
}
if (pMP3FrameCount != NULL) {
*pMP3FrameCount = totalMP3FrameCount;
@@ -90854,89 +92249,89 @@ DRMP3_API drmp3_bool32 drmp3_get_mp3_and_pcm_frame_count(drmp3* pMP3, drmp3_uint
if (pPCMFrameCount != NULL) {
*pPCMFrameCount = totalPCMFrameCount;
}
- return DRMP3_TRUE;
+ return MA_TRUE;
}
-DRMP3_API drmp3_uint64 drmp3_get_pcm_frame_count(drmp3* pMP3)
+MA_API ma_uint64 ma_dr_mp3_get_pcm_frame_count(ma_dr_mp3* pMP3)
{
- drmp3_uint64 totalPCMFrameCount;
- if (!drmp3_get_mp3_and_pcm_frame_count(pMP3, NULL, &totalPCMFrameCount)) {
+ ma_uint64 totalPCMFrameCount;
+ if (!ma_dr_mp3_get_mp3_and_pcm_frame_count(pMP3, NULL, &totalPCMFrameCount)) {
return 0;
}
return totalPCMFrameCount;
}
-DRMP3_API drmp3_uint64 drmp3_get_mp3_frame_count(drmp3* pMP3)
+MA_API ma_uint64 ma_dr_mp3_get_mp3_frame_count(ma_dr_mp3* pMP3)
{
- drmp3_uint64 totalMP3FrameCount;
- if (!drmp3_get_mp3_and_pcm_frame_count(pMP3, &totalMP3FrameCount, NULL)) {
+ ma_uint64 totalMP3FrameCount;
+ if (!ma_dr_mp3_get_mp3_and_pcm_frame_count(pMP3, &totalMP3FrameCount, NULL)) {
return 0;
}
return totalMP3FrameCount;
}
-static void drmp3__accumulate_running_pcm_frame_count(drmp3* pMP3, drmp3_uint32 pcmFrameCountIn, drmp3_uint64* pRunningPCMFrameCount, float* pRunningPCMFrameCountFractionalPart)
+static void ma_dr_mp3__accumulate_running_pcm_frame_count(ma_dr_mp3* pMP3, ma_uint32 pcmFrameCountIn, ma_uint64* pRunningPCMFrameCount, float* pRunningPCMFrameCountFractionalPart)
{
float srcRatio;
float pcmFrameCountOutF;
- drmp3_uint32 pcmFrameCountOut;
+ ma_uint32 pcmFrameCountOut;
srcRatio = (float)pMP3->mp3FrameSampleRate / (float)pMP3->sampleRate;
- DRMP3_ASSERT(srcRatio > 0);
+ MA_DR_MP3_ASSERT(srcRatio > 0);
pcmFrameCountOutF = *pRunningPCMFrameCountFractionalPart + (pcmFrameCountIn / srcRatio);
- pcmFrameCountOut = (drmp3_uint32)pcmFrameCountOutF;
+ pcmFrameCountOut = (ma_uint32)pcmFrameCountOutF;
*pRunningPCMFrameCountFractionalPart = pcmFrameCountOutF - pcmFrameCountOut;
*pRunningPCMFrameCount += pcmFrameCountOut;
}
typedef struct
{
- drmp3_uint64 bytePos;
- drmp3_uint64 pcmFrameIndex;
-} drmp3__seeking_mp3_frame_info;
-DRMP3_API drmp3_bool32 drmp3_calculate_seek_points(drmp3* pMP3, drmp3_uint32* pSeekPointCount, drmp3_seek_point* pSeekPoints)
+ ma_uint64 bytePos;
+ ma_uint64 pcmFrameIndex;
+} ma_dr_mp3__seeking_mp3_frame_info;
+MA_API ma_bool32 ma_dr_mp3_calculate_seek_points(ma_dr_mp3* pMP3, ma_uint32* pSeekPointCount, ma_dr_mp3_seek_point* pSeekPoints)
{
- drmp3_uint32 seekPointCount;
- drmp3_uint64 currentPCMFrame;
- drmp3_uint64 totalMP3FrameCount;
- drmp3_uint64 totalPCMFrameCount;
+ ma_uint32 seekPointCount;
+ ma_uint64 currentPCMFrame;
+ ma_uint64 totalMP3FrameCount;
+ ma_uint64 totalPCMFrameCount;
if (pMP3 == NULL || pSeekPointCount == NULL || pSeekPoints == NULL) {
- return DRMP3_FALSE;
+ return MA_FALSE;
}
seekPointCount = *pSeekPointCount;
if (seekPointCount == 0) {
- return DRMP3_FALSE;
+ return MA_FALSE;
}
currentPCMFrame = pMP3->currentPCMFrame;
- if (!drmp3_get_mp3_and_pcm_frame_count(pMP3, &totalMP3FrameCount, &totalPCMFrameCount)) {
- return DRMP3_FALSE;
+ if (!ma_dr_mp3_get_mp3_and_pcm_frame_count(pMP3, &totalMP3FrameCount, &totalPCMFrameCount)) {
+ return MA_FALSE;
}
- if (totalMP3FrameCount < DRMP3_SEEK_LEADING_MP3_FRAMES+1) {
+ if (totalMP3FrameCount < MA_DR_MP3_SEEK_LEADING_MP3_FRAMES+1) {
seekPointCount = 1;
pSeekPoints[0].seekPosInBytes = 0;
pSeekPoints[0].pcmFrameIndex = 0;
pSeekPoints[0].mp3FramesToDiscard = 0;
pSeekPoints[0].pcmFramesToDiscard = 0;
} else {
- drmp3_uint64 pcmFramesBetweenSeekPoints;
- drmp3__seeking_mp3_frame_info mp3FrameInfo[DRMP3_SEEK_LEADING_MP3_FRAMES+1];
- drmp3_uint64 runningPCMFrameCount = 0;
+ ma_uint64 pcmFramesBetweenSeekPoints;
+ ma_dr_mp3__seeking_mp3_frame_info mp3FrameInfo[MA_DR_MP3_SEEK_LEADING_MP3_FRAMES+1];
+ ma_uint64 runningPCMFrameCount = 0;
float runningPCMFrameCountFractionalPart = 0;
- drmp3_uint64 nextTargetPCMFrame;
- drmp3_uint32 iMP3Frame;
- drmp3_uint32 iSeekPoint;
+ ma_uint64 nextTargetPCMFrame;
+ ma_uint32 iMP3Frame;
+ ma_uint32 iSeekPoint;
if (seekPointCount > totalMP3FrameCount-1) {
- seekPointCount = (drmp3_uint32)totalMP3FrameCount-1;
+ seekPointCount = (ma_uint32)totalMP3FrameCount-1;
}
pcmFramesBetweenSeekPoints = totalPCMFrameCount / (seekPointCount+1);
- if (!drmp3_seek_to_start_of_stream(pMP3)) {
- return DRMP3_FALSE;
+ if (!ma_dr_mp3_seek_to_start_of_stream(pMP3)) {
+ return MA_FALSE;
}
- for (iMP3Frame = 0; iMP3Frame < DRMP3_SEEK_LEADING_MP3_FRAMES+1; ++iMP3Frame) {
- drmp3_uint32 pcmFramesInCurrentMP3FrameIn;
- DRMP3_ASSERT(pMP3->streamCursor >= pMP3->dataSize);
+ for (iMP3Frame = 0; iMP3Frame < MA_DR_MP3_SEEK_LEADING_MP3_FRAMES+1; ++iMP3Frame) {
+ ma_uint32 pcmFramesInCurrentMP3FrameIn;
+ MA_DR_MP3_ASSERT(pMP3->streamCursor >= pMP3->dataSize);
mp3FrameInfo[iMP3Frame].bytePos = pMP3->streamCursor - pMP3->dataSize;
mp3FrameInfo[iMP3Frame].pcmFrameIndex = runningPCMFrameCount;
- pcmFramesInCurrentMP3FrameIn = drmp3_decode_next_frame_ex(pMP3, NULL);
+ pcmFramesInCurrentMP3FrameIn = ma_dr_mp3_decode_next_frame_ex(pMP3, NULL);
if (pcmFramesInCurrentMP3FrameIn == 0) {
- return DRMP3_FALSE;
+ return MA_FALSE;
}
- drmp3__accumulate_running_pcm_frame_count(pMP3, pcmFramesInCurrentMP3FrameIn, &runningPCMFrameCount, &runningPCMFrameCountFractionalPart);
+ ma_dr_mp3__accumulate_running_pcm_frame_count(pMP3, pcmFramesInCurrentMP3FrameIn, &runningPCMFrameCount, &runningPCMFrameCountFractionalPart);
}
nextTargetPCMFrame = 0;
for (iSeekPoint = 0; iSeekPoint < seekPointCount; ++iSeekPoint) {
@@ -90945,43 +92340,43 @@ DRMP3_API drmp3_bool32 drmp3_calculate_seek_points(drmp3* pMP3, drmp3_uint32* pS
if (nextTargetPCMFrame < runningPCMFrameCount) {
pSeekPoints[iSeekPoint].seekPosInBytes = mp3FrameInfo[0].bytePos;
pSeekPoints[iSeekPoint].pcmFrameIndex = nextTargetPCMFrame;
- pSeekPoints[iSeekPoint].mp3FramesToDiscard = DRMP3_SEEK_LEADING_MP3_FRAMES;
- pSeekPoints[iSeekPoint].pcmFramesToDiscard = (drmp3_uint16)(nextTargetPCMFrame - mp3FrameInfo[DRMP3_SEEK_LEADING_MP3_FRAMES-1].pcmFrameIndex);
+ pSeekPoints[iSeekPoint].mp3FramesToDiscard = MA_DR_MP3_SEEK_LEADING_MP3_FRAMES;
+ pSeekPoints[iSeekPoint].pcmFramesToDiscard = (ma_uint16)(nextTargetPCMFrame - mp3FrameInfo[MA_DR_MP3_SEEK_LEADING_MP3_FRAMES-1].pcmFrameIndex);
break;
} else {
size_t i;
- drmp3_uint32 pcmFramesInCurrentMP3FrameIn;
- for (i = 0; i < DRMP3_COUNTOF(mp3FrameInfo)-1; ++i) {
+ ma_uint32 pcmFramesInCurrentMP3FrameIn;
+ for (i = 0; i < MA_DR_MP3_COUNTOF(mp3FrameInfo)-1; ++i) {
mp3FrameInfo[i] = mp3FrameInfo[i+1];
}
- mp3FrameInfo[DRMP3_COUNTOF(mp3FrameInfo)-1].bytePos = pMP3->streamCursor - pMP3->dataSize;
- mp3FrameInfo[DRMP3_COUNTOF(mp3FrameInfo)-1].pcmFrameIndex = runningPCMFrameCount;
- pcmFramesInCurrentMP3FrameIn = drmp3_decode_next_frame_ex(pMP3, NULL);
+ mp3FrameInfo[MA_DR_MP3_COUNTOF(mp3FrameInfo)-1].bytePos = pMP3->streamCursor - pMP3->dataSize;
+ mp3FrameInfo[MA_DR_MP3_COUNTOF(mp3FrameInfo)-1].pcmFrameIndex = runningPCMFrameCount;
+ pcmFramesInCurrentMP3FrameIn = ma_dr_mp3_decode_next_frame_ex(pMP3, NULL);
if (pcmFramesInCurrentMP3FrameIn == 0) {
pSeekPoints[iSeekPoint].seekPosInBytes = mp3FrameInfo[0].bytePos;
pSeekPoints[iSeekPoint].pcmFrameIndex = nextTargetPCMFrame;
- pSeekPoints[iSeekPoint].mp3FramesToDiscard = DRMP3_SEEK_LEADING_MP3_FRAMES;
- pSeekPoints[iSeekPoint].pcmFramesToDiscard = (drmp3_uint16)(nextTargetPCMFrame - mp3FrameInfo[DRMP3_SEEK_LEADING_MP3_FRAMES-1].pcmFrameIndex);
+ pSeekPoints[iSeekPoint].mp3FramesToDiscard = MA_DR_MP3_SEEK_LEADING_MP3_FRAMES;
+ pSeekPoints[iSeekPoint].pcmFramesToDiscard = (ma_uint16)(nextTargetPCMFrame - mp3FrameInfo[MA_DR_MP3_SEEK_LEADING_MP3_FRAMES-1].pcmFrameIndex);
break;
}
- drmp3__accumulate_running_pcm_frame_count(pMP3, pcmFramesInCurrentMP3FrameIn, &runningPCMFrameCount, &runningPCMFrameCountFractionalPart);
+ ma_dr_mp3__accumulate_running_pcm_frame_count(pMP3, pcmFramesInCurrentMP3FrameIn, &runningPCMFrameCount, &runningPCMFrameCountFractionalPart);
}
}
}
- if (!drmp3_seek_to_start_of_stream(pMP3)) {
- return DRMP3_FALSE;
+ if (!ma_dr_mp3_seek_to_start_of_stream(pMP3)) {
+ return MA_FALSE;
}
- if (!drmp3_seek_to_pcm_frame(pMP3, currentPCMFrame)) {
- return DRMP3_FALSE;
+ if (!ma_dr_mp3_seek_to_pcm_frame(pMP3, currentPCMFrame)) {
+ return MA_FALSE;
}
}
*pSeekPointCount = seekPointCount;
- return DRMP3_TRUE;
+ return MA_TRUE;
}
-DRMP3_API drmp3_bool32 drmp3_bind_seek_table(drmp3* pMP3, drmp3_uint32 seekPointCount, drmp3_seek_point* pSeekPoints)
+MA_API ma_bool32 ma_dr_mp3_bind_seek_table(ma_dr_mp3* pMP3, ma_uint32 seekPointCount, ma_dr_mp3_seek_point* pSeekPoints)
{
if (pMP3 == NULL) {
- return DRMP3_FALSE;
+ return MA_FALSE;
}
if (seekPointCount == 0 || pSeekPoints == NULL) {
pMP3->seekPointCount = 0;
@@ -90990,25 +92385,25 @@ DRMP3_API drmp3_bool32 drmp3_bind_seek_table(drmp3* pMP3, drmp3_uint32 seekPoint
pMP3->seekPointCount = seekPointCount;
pMP3->pSeekPoints = pSeekPoints;
}
- return DRMP3_TRUE;
+ return MA_TRUE;
}
-static float* drmp3__full_read_and_close_f32(drmp3* pMP3, drmp3_config* pConfig, drmp3_uint64* pTotalFrameCount)
+static float* ma_dr_mp3__full_read_and_close_f32(ma_dr_mp3* pMP3, ma_dr_mp3_config* pConfig, ma_uint64* pTotalFrameCount)
{
- drmp3_uint64 totalFramesRead = 0;
- drmp3_uint64 framesCapacity = 0;
+ ma_uint64 totalFramesRead = 0;
+ ma_uint64 framesCapacity = 0;
float* pFrames = NULL;
float temp[4096];
- DRMP3_ASSERT(pMP3 != NULL);
+ MA_DR_MP3_ASSERT(pMP3 != NULL);
for (;;) {
- drmp3_uint64 framesToReadRightNow = DRMP3_COUNTOF(temp) / pMP3->channels;
- drmp3_uint64 framesJustRead = drmp3_read_pcm_frames_f32(pMP3, framesToReadRightNow, temp);
+ ma_uint64 framesToReadRightNow = MA_DR_MP3_COUNTOF(temp) / pMP3->channels;
+ ma_uint64 framesJustRead = ma_dr_mp3_read_pcm_frames_f32(pMP3, framesToReadRightNow, temp);
if (framesJustRead == 0) {
break;
}
if (framesCapacity < totalFramesRead + framesJustRead) {
- drmp3_uint64 oldFramesBufferSize;
- drmp3_uint64 newFramesBufferSize;
- drmp3_uint64 newFramesCap;
+ ma_uint64 oldFramesBufferSize;
+ ma_uint64 newFramesBufferSize;
+ ma_uint64 newFramesCap;
float* pNewFrames;
newFramesCap = framesCapacity * 2;
if (newFramesCap < totalFramesRead + framesJustRead) {
@@ -91016,18 +92411,18 @@ static float* drmp3__full_read_and_close_f32(drmp3* pMP3, drmp3_config* pConfig,
}
oldFramesBufferSize = framesCapacity * pMP3->channels * sizeof(float);
newFramesBufferSize = newFramesCap * pMP3->channels * sizeof(float);
- if (newFramesBufferSize > (drmp3_uint64)DRMP3_SIZE_MAX) {
+ if (newFramesBufferSize > (ma_uint64)MA_SIZE_MAX) {
break;
}
- pNewFrames = (float*)drmp3__realloc_from_callbacks(pFrames, (size_t)newFramesBufferSize, (size_t)oldFramesBufferSize, &pMP3->allocationCallbacks);
+ pNewFrames = (float*)ma_dr_mp3__realloc_from_callbacks(pFrames, (size_t)newFramesBufferSize, (size_t)oldFramesBufferSize, &pMP3->allocationCallbacks);
if (pNewFrames == NULL) {
- drmp3__free_from_callbacks(pFrames, &pMP3->allocationCallbacks);
+ ma_dr_mp3__free_from_callbacks(pFrames, &pMP3->allocationCallbacks);
break;
}
pFrames = pNewFrames;
framesCapacity = newFramesCap;
}
- DRMP3_COPY_MEMORY(pFrames + totalFramesRead*pMP3->channels, temp, (size_t)(framesJustRead*pMP3->channels*sizeof(float)));
+ MA_DR_MP3_COPY_MEMORY(pFrames + totalFramesRead*pMP3->channels, temp, (size_t)(framesJustRead*pMP3->channels*sizeof(float)));
totalFramesRead += framesJustRead;
if (framesJustRead != framesToReadRightNow) {
break;
@@ -91037,48 +92432,48 @@ static float* drmp3__full_read_and_close_f32(drmp3* pMP3, drmp3_config* pConfig,
pConfig->channels = pMP3->channels;
pConfig->sampleRate = pMP3->sampleRate;
}
- drmp3_uninit(pMP3);
+ ma_dr_mp3_uninit(pMP3);
if (pTotalFrameCount) {
*pTotalFrameCount = totalFramesRead;
}
return pFrames;
}
-static drmp3_int16* drmp3__full_read_and_close_s16(drmp3* pMP3, drmp3_config* pConfig, drmp3_uint64* pTotalFrameCount)
+static ma_int16* ma_dr_mp3__full_read_and_close_s16(ma_dr_mp3* pMP3, ma_dr_mp3_config* pConfig, ma_uint64* pTotalFrameCount)
{
- drmp3_uint64 totalFramesRead = 0;
- drmp3_uint64 framesCapacity = 0;
- drmp3_int16* pFrames = NULL;
- drmp3_int16 temp[4096];
- DRMP3_ASSERT(pMP3 != NULL);
+ ma_uint64 totalFramesRead = 0;
+ ma_uint64 framesCapacity = 0;
+ ma_int16* pFrames = NULL;
+ ma_int16 temp[4096];
+ MA_DR_MP3_ASSERT(pMP3 != NULL);
for (;;) {
- drmp3_uint64 framesToReadRightNow = DRMP3_COUNTOF(temp) / pMP3->channels;
- drmp3_uint64 framesJustRead = drmp3_read_pcm_frames_s16(pMP3, framesToReadRightNow, temp);
+ ma_uint64 framesToReadRightNow = MA_DR_MP3_COUNTOF(temp) / pMP3->channels;
+ ma_uint64 framesJustRead = ma_dr_mp3_read_pcm_frames_s16(pMP3, framesToReadRightNow, temp);
if (framesJustRead == 0) {
break;
}
if (framesCapacity < totalFramesRead + framesJustRead) {
- drmp3_uint64 newFramesBufferSize;
- drmp3_uint64 oldFramesBufferSize;
- drmp3_uint64 newFramesCap;
- drmp3_int16* pNewFrames;
+ ma_uint64 newFramesBufferSize;
+ ma_uint64 oldFramesBufferSize;
+ ma_uint64 newFramesCap;
+ ma_int16* pNewFrames;
newFramesCap = framesCapacity * 2;
if (newFramesCap < totalFramesRead + framesJustRead) {
newFramesCap = totalFramesRead + framesJustRead;
}
- oldFramesBufferSize = framesCapacity * pMP3->channels * sizeof(drmp3_int16);
- newFramesBufferSize = newFramesCap * pMP3->channels * sizeof(drmp3_int16);
- if (newFramesBufferSize > (drmp3_uint64)DRMP3_SIZE_MAX) {
+ oldFramesBufferSize = framesCapacity * pMP3->channels * sizeof(ma_int16);
+ newFramesBufferSize = newFramesCap * pMP3->channels * sizeof(ma_int16);
+ if (newFramesBufferSize > (ma_uint64)MA_SIZE_MAX) {
break;
}
- pNewFrames = (drmp3_int16*)drmp3__realloc_from_callbacks(pFrames, (size_t)newFramesBufferSize, (size_t)oldFramesBufferSize, &pMP3->allocationCallbacks);
+ pNewFrames = (ma_int16*)ma_dr_mp3__realloc_from_callbacks(pFrames, (size_t)newFramesBufferSize, (size_t)oldFramesBufferSize, &pMP3->allocationCallbacks);
if (pNewFrames == NULL) {
- drmp3__free_from_callbacks(pFrames, &pMP3->allocationCallbacks);
+ ma_dr_mp3__free_from_callbacks(pFrames, &pMP3->allocationCallbacks);
break;
}
pFrames = pNewFrames;
framesCapacity = newFramesCap;
}
- DRMP3_COPY_MEMORY(pFrames + totalFramesRead*pMP3->channels, temp, (size_t)(framesJustRead*pMP3->channels*sizeof(drmp3_int16)));
+ MA_DR_MP3_COPY_MEMORY(pFrames + totalFramesRead*pMP3->channels, temp, (size_t)(framesJustRead*pMP3->channels*sizeof(ma_int16)));
totalFramesRead += framesJustRead;
if (framesJustRead != framesToReadRightNow) {
break;
@@ -91088,81 +92483,81 @@ static drmp3_int16* drmp3__full_read_and_close_s16(drmp3* pMP3, drmp3_config* pC
pConfig->channels = pMP3->channels;
pConfig->sampleRate = pMP3->sampleRate;
}
- drmp3_uninit(pMP3);
+ ma_dr_mp3_uninit(pMP3);
if (pTotalFrameCount) {
*pTotalFrameCount = totalFramesRead;
}
return pFrames;
}
-DRMP3_API float* drmp3_open_and_read_pcm_frames_f32(drmp3_read_proc onRead, drmp3_seek_proc onSeek, void* pUserData, drmp3_config* pConfig, drmp3_uint64* pTotalFrameCount, const drmp3_allocation_callbacks* pAllocationCallbacks)
+MA_API float* ma_dr_mp3_open_and_read_pcm_frames_f32(ma_dr_mp3_read_proc onRead, ma_dr_mp3_seek_proc onSeek, void* pUserData, ma_dr_mp3_config* pConfig, ma_uint64* pTotalFrameCount, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drmp3 mp3;
- if (!drmp3_init(&mp3, onRead, onSeek, pUserData, pAllocationCallbacks)) {
+ ma_dr_mp3 mp3;
+ if (!ma_dr_mp3_init(&mp3, onRead, onSeek, pUserData, pAllocationCallbacks)) {
return NULL;
}
- return drmp3__full_read_and_close_f32(&mp3, pConfig, pTotalFrameCount);
+ return ma_dr_mp3__full_read_and_close_f32(&mp3, pConfig, pTotalFrameCount);
}
-DRMP3_API drmp3_int16* drmp3_open_and_read_pcm_frames_s16(drmp3_read_proc onRead, drmp3_seek_proc onSeek, void* pUserData, drmp3_config* pConfig, drmp3_uint64* pTotalFrameCount, const drmp3_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_int16* ma_dr_mp3_open_and_read_pcm_frames_s16(ma_dr_mp3_read_proc onRead, ma_dr_mp3_seek_proc onSeek, void* pUserData, ma_dr_mp3_config* pConfig, ma_uint64* pTotalFrameCount, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drmp3 mp3;
- if (!drmp3_init(&mp3, onRead, onSeek, pUserData, pAllocationCallbacks)) {
+ ma_dr_mp3 mp3;
+ if (!ma_dr_mp3_init(&mp3, onRead, onSeek, pUserData, pAllocationCallbacks)) {
return NULL;
}
- return drmp3__full_read_and_close_s16(&mp3, pConfig, pTotalFrameCount);
+ return ma_dr_mp3__full_read_and_close_s16(&mp3, pConfig, pTotalFrameCount);
}
-DRMP3_API float* drmp3_open_memory_and_read_pcm_frames_f32(const void* pData, size_t dataSize, drmp3_config* pConfig, drmp3_uint64* pTotalFrameCount, const drmp3_allocation_callbacks* pAllocationCallbacks)
+MA_API float* ma_dr_mp3_open_memory_and_read_pcm_frames_f32(const void* pData, size_t dataSize, ma_dr_mp3_config* pConfig, ma_uint64* pTotalFrameCount, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drmp3 mp3;
- if (!drmp3_init_memory(&mp3, pData, dataSize, pAllocationCallbacks)) {
+ ma_dr_mp3 mp3;
+ if (!ma_dr_mp3_init_memory(&mp3, pData, dataSize, pAllocationCallbacks)) {
return NULL;
}
- return drmp3__full_read_and_close_f32(&mp3, pConfig, pTotalFrameCount);
+ return ma_dr_mp3__full_read_and_close_f32(&mp3, pConfig, pTotalFrameCount);
}
-DRMP3_API drmp3_int16* drmp3_open_memory_and_read_pcm_frames_s16(const void* pData, size_t dataSize, drmp3_config* pConfig, drmp3_uint64* pTotalFrameCount, const drmp3_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_int16* ma_dr_mp3_open_memory_and_read_pcm_frames_s16(const void* pData, size_t dataSize, ma_dr_mp3_config* pConfig, ma_uint64* pTotalFrameCount, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drmp3 mp3;
- if (!drmp3_init_memory(&mp3, pData, dataSize, pAllocationCallbacks)) {
+ ma_dr_mp3 mp3;
+ if (!ma_dr_mp3_init_memory(&mp3, pData, dataSize, pAllocationCallbacks)) {
return NULL;
}
- return drmp3__full_read_and_close_s16(&mp3, pConfig, pTotalFrameCount);
+ return ma_dr_mp3__full_read_and_close_s16(&mp3, pConfig, pTotalFrameCount);
}
-#ifndef DR_MP3_NO_STDIO
-DRMP3_API float* drmp3_open_file_and_read_pcm_frames_f32(const char* filePath, drmp3_config* pConfig, drmp3_uint64* pTotalFrameCount, const drmp3_allocation_callbacks* pAllocationCallbacks)
+#ifndef MA_DR_MP3_NO_STDIO
+MA_API float* ma_dr_mp3_open_file_and_read_pcm_frames_f32(const char* filePath, ma_dr_mp3_config* pConfig, ma_uint64* pTotalFrameCount, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drmp3 mp3;
- if (!drmp3_init_file(&mp3, filePath, pAllocationCallbacks)) {
+ ma_dr_mp3 mp3;
+ if (!ma_dr_mp3_init_file(&mp3, filePath, pAllocationCallbacks)) {
return NULL;
}
- return drmp3__full_read_and_close_f32(&mp3, pConfig, pTotalFrameCount);
+ return ma_dr_mp3__full_read_and_close_f32(&mp3, pConfig, pTotalFrameCount);
}
-DRMP3_API drmp3_int16* drmp3_open_file_and_read_pcm_frames_s16(const char* filePath, drmp3_config* pConfig, drmp3_uint64* pTotalFrameCount, const drmp3_allocation_callbacks* pAllocationCallbacks)
+MA_API ma_int16* ma_dr_mp3_open_file_and_read_pcm_frames_s16(const char* filePath, ma_dr_mp3_config* pConfig, ma_uint64* pTotalFrameCount, const ma_allocation_callbacks* pAllocationCallbacks)
{
- drmp3 mp3;
- if (!drmp3_init_file(&mp3, filePath, pAllocationCallbacks)) {
+ ma_dr_mp3 mp3;
+ if (!ma_dr_mp3_init_file(&mp3, filePath, pAllocationCallbacks)) {
return NULL;
}
- return drmp3__full_read_and_close_s16(&mp3, pConfig, pTotalFrameCount);
+ return ma_dr_mp3__full_read_and_close_s16(&mp3, pConfig, pTotalFrameCount);
}
#endif
-DRMP3_API void* drmp3_malloc(size_t sz, const drmp3_allocation_callbacks* pAllocationCallbacks)
+MA_API void* ma_dr_mp3_malloc(size_t sz, const ma_allocation_callbacks* pAllocationCallbacks)
{
if (pAllocationCallbacks != NULL) {
- return drmp3__malloc_from_callbacks(sz, pAllocationCallbacks);
+ return ma_dr_mp3__malloc_from_callbacks(sz, pAllocationCallbacks);
} else {
- return drmp3__malloc_default(sz, NULL);
+ return ma_dr_mp3__malloc_default(sz, NULL);
}
}
-DRMP3_API void drmp3_free(void* p, const drmp3_allocation_callbacks* pAllocationCallbacks)
+MA_API void ma_dr_mp3_free(void* p, const ma_allocation_callbacks* pAllocationCallbacks)
{
if (pAllocationCallbacks != NULL) {
- drmp3__free_from_callbacks(p, pAllocationCallbacks);
+ ma_dr_mp3__free_from_callbacks(p, pAllocationCallbacks);
} else {
- drmp3__free_default(p, NULL);
+ ma_dr_mp3__free_default(p, NULL);
}
}
#endif
/* dr_mp3_c end */
-#endif /* DRMP3_IMPLEMENTATION */
+#endif /* MA_DR_MP3_IMPLEMENTATION */
#endif /* MA_NO_MP3 */
@@ -91207,7 +92602,7 @@ For more information, please refer to
===============================================================================
ALTERNATIVE 2 - MIT No Attribution
===============================================================================
-Copyright 2020 David Reid
+Copyright 2023 David Reid
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in