Commit d72e7b1f authored by David Reid's avatar David Reid

"mini_al" to "miniaudio".

parent af1c305d
![mini_al](http://dred.io/img/minial_wide.png)
![miniaudio](http://dred.io/img/miniaudio_wide.png)
mini_al is a single file library for audio playback and capture. It's written in C (compilable as C++)
and released into the public domain.
miniaudio (formally mini_al) is a single file library for audio playback and capture. It's written
in C (compilable as C++) and released into the public domain.
Features
......@@ -52,7 +52,7 @@ Building
Do the following in one source file:
```
#define MINI_AL_IMPLEMENTATION
#include "mini_al.h"
#include "miniaudio.h"
```
Then just compile. There's no need to install any dependencies. On Windows and macOS there's no need to link
to anything. On Linux and BSD, just link to -lpthread, -lm and -ldl.
......@@ -70,7 +70,7 @@ Simple Playback Example
#include "../extras/dr_wav.h" // Enables WAV decoding.
#define MINI_AL_IMPLEMENTATION
#include "../mini_al.h"
#include "../miniaudio.h"
#include <stdio.h>
......@@ -133,21 +133,21 @@ int main(int argc, char** argv)
MP3/Vorbis/FLAC/WAV Decoding
============================
mini_al includes a decoding API which supports the following backends:
miniaudio includes a decoding API which supports the following backends:
- FLAC via [dr_flac](https://github.com/mackron/dr_libs/blob/master/dr_flac.h)
- MP3 via [dr_mp3](https://github.com/mackron/dr_libs/blob/master/dr_mp3.h)
- WAV via [dr_wav](https://github.com/mackron/dr_libs/blob/master/dr_wav.h)
- Vorbis via [stb_vorbis](https://github.com/nothings/stb/blob/master/stb_vorbis.c)
Copies of these libraries can be found in the "extras" folder. You may also want to look at the
libraries below, but they are not supported by the mini_al decoder API. If you know of any other
libraries below, but they are not supported by the miniaudio decoder API. If you know of any other
single file libraries I can add to this list, let me know. Preferably public domain or MIT.
- [minimp3](https://github.com/lieff/minimp3)
- [jar_mod](https://github.com/kd7tck/jar/blob/master/jar_mod.h)
- [jar_xm](https://github.com/kd7tck/jar/blob/master/jar_xm.h)
To enable support for a decoding backend, all you need to do is #include the header section of the
relevant backend library before the implementation of mini_al, like so:
relevant backend library before the implementation of miniaudio, like so:
```
#include "dr_flac.h" // Enables FLAC decoding.
......@@ -155,7 +155,7 @@ relevant backend library before the implementation of mini_al, like so:
#include "dr_wav.h" // Enables WAV decoding.
#define MINI_AL_IMPLEMENTATION
#include "mini_al.h"
#include "miniaudio.h"
```
A decoder can be initialized from a file with `mal_decoder_init_file()`, a block of memory with
......@@ -200,7 +200,7 @@ if (result != MAL_SUCCESS) {
}
```
When loading a decoder, mini_al uses a trial and error technique to find the appropriate decoding
When loading a decoder, miniaudio uses a trial and error technique to find the appropriate decoding
backend. This can be unnecessarily inefficient if the type is already known. In this case you can
use the `_wav`, `_mp3`, etc. varients of the aforementioned initialization APIs:
......
#define MINI_AL_IMPLEMENTATION
#include "../mini_al.h"
#include "../miniaudio.h"
#include <stdio.h>
......@@ -7,7 +7,7 @@ void log_callback(mal_context* pContext, mal_device* pDevice, mal_uint32 logLeve
{
(void)pContext;
(void)pDevice;
printf("mini_al: [%s] %s\n", mal_log_level_to_string(logLevel), message);
printf("miniaudio: [%s] %s\n", mal_log_level_to_string(logLevel), message);
}
void data_callback(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 frameCount)
......@@ -44,7 +44,7 @@ int main(int argc, char** argv)
// PulseAudio
// ----------
// PulseAudio allows you to set the name of the application. mini_al exposes this through the following
// PulseAudio allows you to set the name of the application. miniaudio exposes this through the following
// config.
contextConfig.pulse.pApplicationName = "My Application";
......@@ -53,7 +53,7 @@ int main(int argc, char** argv)
contextConfig.pulse.pServerName = "my_server";
// During initialization, PulseAudio can try to automatically start the PulseAudio daemon. This does not
// suit mini_al's trial and error backend initialization architecture so it's disabled by default, but you
// suit miniaudio's trial and error backend initialization architecture so it's disabled by default, but you
// can enable it like so:
contextConfig.pulse.tryAutoSpawn = MAL_TRUE;
......@@ -62,7 +62,7 @@ int main(int argc, char** argv)
// ----
// Typically, ALSA enumerates many devices, which unfortunately is not very friendly for the end user. To
// combat this, mini_al will include only unique card/device pairs by default. The problem with this is that
// combat this, miniaudio will include only unique card/device pairs by default. The problem with this is that
// you lose a bit of flexibility and control. Setting alsa.useVerboseDeviceEnumeration makes it so the ALSA
// backend includes all devices (and there's a lot of them!).
contextConfig.alsa.useVerboseDeviceEnumeration = MAL_TRUE;
......@@ -151,7 +151,7 @@ int main(int argc, char** argv)
// backends support this feature, so this is actually just a hint.
deviceConfig.playback.shareMode = mal_share_mode_exclusive;
// mini_al allows applications to control the mapping of channels. The config below swaps the left and right
// miniaudio allows applications to control the mapping of channels. The config below swaps the left and right
// channels. Normally in an interleaved audio stream, the left channel comes first, but we can change that
// like the following:
deviceConfig.playback.channelMap[0] = MAL_CHANNEL_FRONT_RIGHT;
......@@ -164,7 +164,7 @@ int main(int argc, char** argv)
// here in case it might be useful for others. If you find a bug specific to mmap mode, please report it!
deviceConfig.alsa.noMMap = MAL_TRUE;
// This is not used in this example, but mini_al allows you to directly control the device ID that's used
// This is not used in this example, but miniaudio allows you to directly control the device ID that's used
// for device selection by mal_device_init(). Below is an example for ALSA. In this example it forces
// mal_device_init() to try opening the "hw:0,0" device. This is useful for debugging in case you have
// audio glitches or whatnot with specific devices.
......@@ -173,8 +173,8 @@ int main(int argc, char** argv)
if (context.backend == mal_backend_alsa) {
strcpy(customDeviceID.alsa, "hw:0,0");
// The ALSA backend also supports a mini_al-specific format which looks like this: ":0,0". In this case,
// mini_al will try different plugins depending on the shareMode setting. When using shared mode it will
// The ALSA backend also supports a miniaudio-specific format which looks like this: ":0,0". In this case,
// miniaudio will try different plugins depending on the shareMode setting. When using shared mode it will
// convert ":0,0" to "dmix:0,0"/"dsnoop:0,0". For exclusive mode (or if dmix/dsnoop fails) it will convert
// it to "hw:0,0". This is how the ALSA backend honors the shareMode hint.
strcpy(customDeviceID.alsa, ":0,0");
......
// This example simply captures data from your default microphone until you press Enter. The output is saved to the file specified on the command line.
#define MINI_AL_IMPLEMENTATION
#include "../mini_al.h"
#include "../miniaudio.h"
#define DR_WAV_IMPLEMENTATION
#include "../extras/dr_wav.h"
......
#define MINI_AL_IMPLEMENTATION
#include "../mini_al.h"
#include "../miniaudio.h"
#include <stdio.h>
......
......@@ -6,7 +6,7 @@
#include "../extras/dr_wav.h" // Enables WAV decoding.
#define MINI_AL_IMPLEMENTATION
#include "../mini_al.h"
#include "../miniaudio.h"
#include <stdio.h>
......
#define MINI_AL_IMPLEMENTATION
#include "../mini_al.h"
#include "../miniaudio.h"
#include <stdio.h>
......
This diff is collapsed.
This folder contains code that I'm experimenting with outside of the main mini_al library. It's just for
This folder contains code that I'm experimenting with outside of the main miniaudio library. It's just for
my own research and experimenting which I'm putting into the repository for version control purposes and
to get feedback from the community. You should not consider any of this code to be production quality.
\ No newline at end of file
/*
Consider this code public domain.
This is research into a new resampler for mini_al. Not yet complete.
This is research into a new resampler for miniaudio. Not yet complete.
Requirements:
- Selection of different algorithms. The following at a minimum:
......@@ -46,7 +46,7 @@ Random Notes:
- You cannot change the algorithm after initialization.
- It is recommended to keep the mal_resampler object aligned to MAL_SIMD_ALIGNMENT, though it is not necessary.
- Ratios need to be in the range of MAL_RESAMPLER_MIN_RATIO and MAL_RESAMPLER_MAX_RATIO. This is enough to convert
to and from 8000 and 384000, which is the smallest and largest standard rates supported by mini_al. If you need
to and from 8000 and 384000, which is the smallest and largest standard rates supported by miniaudio. If you need
extreme ratios then you will need to chain resamplers together.
*/
#ifndef mal_resampler_h
......
......@@ -56,7 +56,7 @@ typedef struct
mal_uint32 subbufferStrideInBytes;
volatile mal_uint32 encodedReadOffset; /* Most significant bit is the loop flag. Lower 31 bits contains the actual offset in bytes. */
volatile mal_uint32 encodedWriteOffset; /* Most significant bit is the loop flag. Lower 31 bits contains the actual offset in bytes. */
mal_bool32 ownsBuffer : 1; /* Used to know whether or not mini_al is responsible for free()-ing the buffer. */
mal_bool32 ownsBuffer : 1; /* Used to know whether or not miniaudio is responsible for free()-ing the buffer. */
mal_bool32 clearOnWriteAcquire : 1; /* When set, clears the acquired write buffer before returning from mal_rb_acquire_write(). */
} mal_rb;
......
......@@ -3,7 +3,7 @@
#define MAL_DEBUG_OUTPUT
#define MINI_AL_IMPLEMENTATION
#include "../../mini_al.h"
#include "../../miniaudio.h"
#include "../mal_resampler.h"
#define SAMPLE_RATE_IN 44100
......
......@@ -2,7 +2,7 @@
#define MAL_LOG_LEVEL MAL_LOG_LEVEL_VERBOSE
#define MAL_DEBUG_OUTPUT
#define MINI_AL_IMPLEMENTATION
#include "../mini_al.h"
#include "../miniaudio.h"
int print_context_info(mal_context* pContext)
{
......
#define MAL_DEBUG_OUTPUT
#define MAL_USE_REFERENCE_CONVERSION_APIS
#define MINI_AL_IMPLEMENTATION
#include "../mini_al.h"
#include "../miniaudio.h"
// Two converters are needed here. One for converting f32 samples from the sine wave generator to the input format,
// and another for converting the input format to the output format for device output.
......
......@@ -2,7 +2,7 @@
#define MAL_DEBUG_OUTPUT
#define MINI_AL_IMPLEMENTATION
#include "../mini_al.h"
#include "../miniaudio.h"
#define DR_WAV_IMPLEMENTATION
#include "../extras/dr_wav.h"
......
......@@ -6,7 +6,7 @@
#define MAL_NO_DEVICE_IO
#define MINI_AL_IMPLEMENTATION
#include "../mini_al.h"
#include "../miniaudio.h"
int main(int argc, char** argv)
{
......
#define MINI_AL_IMPLEMENTATION
#include "../mini_al.h"
#include "../miniaudio.h"
typedef enum
{
......
// We're using sigvis for visualizations. This will include mini_al for us, so no need to include mini_al in this file.
// We're using sigvis for visualizations. This will include miniaudio for us, so no need to include miniaudio in this file.
#define NO_SIGVIS
#define MAL_NO_SSE2
......@@ -6,13 +6,13 @@
#ifdef NO_SIGVIS
#define MINI_AL_IMPLEMENTATION
#include "../mini_al.h"
#include "../miniaudio.h"
#else
#define MINI_SIGVIS_IMPLEMENTATION
#include "../tools/mini_sigvis/mini_sigvis.h" // <-- Includes mini_al.
#include "../tools/mini_sigvis/mini_sigvis.h" // <-- Includes miniaudio.
#endif
// There is a usage pattern for resampling that mini_al does not properly support which is where the client continuously
// There is a usage pattern for resampling that miniaudio does not properly support which is where the client continuously
// reads samples until mal_src_read() returns 0. The problem with this pattern is that is consumes the samples sitting
// in the window which are needed to compute the next samples in future calls to mal_src_read() (assuming the client
// has re-filled the resampler's input data).
......
#include <stdio.h>
#define MINI_AL_IMPLEMENTATION
#include "../mini_al.h"
#include "../miniaudio.h"
mal_sine_wave sineWave;
mal_uint32 framesWritten;
......
......@@ -12,7 +12,7 @@
//#define MAL_DEBUG_OUTPUT
#define MINI_AL_IMPLEMENTATION
#include "../mini_al.h"
#include "../miniaudio.h"
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
......
......@@ -376,7 +376,7 @@
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\mini_al.h" />
<ClInclude Include="..\miniaudio.h" />
<ClInclude Include="..\research\mal_resampler.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
......
......@@ -59,7 +59,7 @@
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\mini_al.h">
<ClInclude Include="..\miniaudio.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="..\research\mal_resampler.h">
......
......@@ -95,7 +95,7 @@
latencyHint: 'interactive',
sampleRate: sampleRate,
});
device.webaudioContext.suspend(); // mini_al always starts it's devices in a stopped state.
device.webaudioContext.suspend(); // miniaudio always starts it's devices in a stopped state.
console.log("Sample Rate: " + device.webaudioContext.sampleRate);
device.intermediaryBufferSizeInBytes = channelCount * bufferSizeInFrames * 4;
......
......@@ -6,7 +6,7 @@
#ifndef mini_sigvis_h
#define mini_sigvis_h
#include "../../mini_al.h"
#include "../../miniaudio.h"
#include "../external/dred/source/dred/dtk/dtk.h"
#ifdef __cplusplus
......@@ -83,7 +83,7 @@ float msigvis_channel_get_sample_f32(msigvis_channel* pChannel, mal_uint32 iSamp
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifdef MINI_SIGVIS_IMPLEMENTATION
#define MINI_AL_IMPLEMENTATION
#include "../../mini_al.h"
#include "../../miniaudio.h"
#include "../external/dred/source/dred/dtk/dtk.c"
mal_result msigvis_result_from_dtk(dtk_result resultDTK)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment