• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/H06-Oct-2020-6646

examples/H06-Oct-2020-887569

extras/H06-Oct-2020-91,71271,224

research/H03-May-2022-10,4526,671

resources/branding/H06-Oct-2020-

tests/H06-Oct-2020-3,0122,302

tools/audioconverter/H06-Oct-2020-331237

website/H03-May-2022-201177

.gitignoreH A D06-Oct-2020202 1212

CONTRIBUTING.mdH A D06-Oct-20205.2 KiB8966

LICENSEH A D06-Oct-20202.5 KiB4739

README.mdH A D06-Oct-20207.3 KiB233194

miniaudio.hH A D06-Oct-20202.6 MiB63,21349,729

README.md

1<h1 align="center">
2    <a href="https://miniaud.io"><img src="https://miniaud.io/img/miniaudio_wide.png" alt="miniaudio" width="1280"></a>
3    <br>
4</h1>
5
6<h4 align="center">A single file library for audio playback and capture.</h4>
7
8<p align="center">
9    <a href="https://discord.gg/9vpqbjU"><img src="https://img.shields.io/discord/712952679415939085?label=discord&logo=discord" alt="discord"></a>
10    <a href="https://twitter.com/mackron"><img src="https://img.shields.io/twitter/follow/mackron?style=flat&label=twitter&color=1da1f2&logo=twitter" alt="twitter"></a>
11</p>
12
13<p align="center">
14    <a href="#example">Example</a> -
15    <a href="#documentation">Documentation</a> -
16    <a href="#supported-platforms">Supported Platforms</a> -
17    <a href="#backends">Backends</a> -
18    <a href="#major-features">Major Features</a> -
19    <a href="#building">Building</a> -
20    <a href="#unofficial-bindings">Unofficial Bindings</a>
21</p>
22
23Example
24=======
25This example shows how to decode and play a sound.
26
27```c
28#define MINIAUDIO_IMPLEMENTATION
29#include "../miniaudio.h"
30
31#include <stdio.h>
32
33void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount)
34{
35    ma_decoder* pDecoder = (ma_decoder*)pDevice->pUserData;
36    if (pDecoder == NULL) {
37        return;
38    }
39
40    ma_decoder_read_pcm_frames(pDecoder, pOutput, frameCount);
41
42    (void)pInput;
43}
44
45int main(int argc, char** argv)
46{
47    ma_result result;
48    ma_decoder decoder;
49    ma_device_config deviceConfig;
50    ma_device device;
51
52    if (argc < 2) {
53        printf("No input file.\n");
54        return -1;
55    }
56
57    result = ma_decoder_init_file(argv[1], NULL, &decoder);
58    if (result != MA_SUCCESS) {
59        return -2;
60    }
61
62    deviceConfig = ma_device_config_init(ma_device_type_playback);
63    deviceConfig.playback.format   = decoder.outputFormat;
64    deviceConfig.playback.channels = decoder.outputChannels;
65    deviceConfig.sampleRate        = decoder.outputSampleRate;
66    deviceConfig.dataCallback      = data_callback;
67    deviceConfig.pUserData         = &decoder;
68
69    if (ma_device_init(NULL, &deviceConfig, &device) != MA_SUCCESS) {
70        printf("Failed to open playback device.\n");
71        ma_decoder_uninit(&decoder);
72        return -3;
73    }
74
75    if (ma_device_start(&device) != MA_SUCCESS) {
76        printf("Failed to start playback device.\n");
77        ma_device_uninit(&device);
78        ma_decoder_uninit(&decoder);
79        return -4;
80    }
81
82    printf("Press Enter to quit...");
83    getchar();
84
85    ma_device_uninit(&device);
86    ma_decoder_uninit(&decoder);
87
88    return 0;
89}
90```
91More examples can be found in the [examples](examples) folder or online here: https://miniaud.io/docs/examples/
92
93
94Documentation
95=============
96Online documentation can be found here: https://miniaud.io/docs/
97
98Documentation can also be found at the top of [miniaudio.h](https://raw.githubusercontent.com/mackron/miniaudio/master/miniaudio.h)
99which is always the most up-to-date and authoritive source of information on how to use miniaudio. All other
100documentation is generated from this in-code documentation.
101
102
103Supported Platforms
104===================
105- Windows (XP+), UWP
106- macOS, iOS
107- Linux
108- BSD
109- Android
110- Raspberry Pi
111- Emscripten / HTML5
112
113
114Backends
115========
116- WASAPI
117- DirectSound
118- WinMM
119- Core Audio (Apple)
120- ALSA
121- PulseAudio
122- JACK
123- sndio (OpenBSD)
124- audio(4) (NetBSD and OpenBSD)
125- OSS (FreeBSD)
126- AAudio (Android 8.0+)
127- OpenSL|ES (Android only)
128- Web Audio (Emscripten)
129- Null (Silence)
130
131
132Major Features
133==============
134- Your choice of either public domain or [MIT No Attribution](https://github.com/aws/mit-0).
135- Entirely contained within a single file for easy integration into your source tree.
136- No external dependencies except for the C standard library and backend libraries.
137- Written in C and compilable as C++, enabling miniaudio to work on almost all compilers.
138- Supports all major desktop and mobile platforms, with multiple backends for maximum compatibility.
139- Supports playback, capture, full-duplex and loopback (WASAPI only).
140- Device enumeration for connecting to specific devices, not just defaults.
141- Connect to multiple devices at once.
142- Shared and exclusive mode on supported backends.
143- Backend-specific configuration options.
144- Device capability querying.
145- Automatic data conversion between your application and the internal device.
146- Sample format conversion with optional dithering.
147- Channel conversion and channel mapping.
148- Resampling with support for multiple algorithms.
149  - Simple linear resampling with anti-aliasing.
150  - Optional Speex resampling (must opt-in).
151- Filters.
152  - Biquad
153  - Low-pass (first, second and high order)
154  - High-pass (first, second and high order)
155  - Second order band-pass
156  - Second order notch
157  - Second order peaking
158  - Second order low shelf
159  - Second order high shelf
160- Waveform generation.
161  - Sine
162  - Square
163  - Triangle
164  - Sawtooth
165- Noise generation.
166  - White
167  - Pink
168  - Brownian
169- Decoding
170  - WAV
171  - FLAC
172  - MP3
173  - Vorbis via stb_vorbis (not built in - must be included separately).
174- Encoding
175  - WAV
176- Lock free ring buffer (single producer, single consumer).
177
178Refer to the [Programming Manual](https://miniaud.io/docs/manual/) for a more complete description of
179available features in miniaudio.
180
181
182Building
183========
184Do the following in one source file:
185```c
186#define MINIAUDIO_IMPLEMENTATION
187#include "miniaudio.h"
188```
189Then just compile. There's no need to install any dependencies. On Windows and macOS there's no need to link
190to anything. On Linux just link to -lpthread, -lm and -ldl. On BSD just link to -lpthread and -lm. On iOS you
191need to compile as Objective-C.
192
193If you prefer separate .h and .c files, you can find a split version of miniaudio in the extras/miniaudio_split
194folder. From here you can use miniaudio as a traditional .c and .h library - just add miniaudio.c to your source
195tree like any other source file and include miniaudio.h like a normal header. If you prefer compiling as a
196single translation unit (AKA unity builds), you can just #include the .c file in your main source file:
197```c
198#include "miniaudio.c"
199```
200Note that the split version is auto-generated using a tool and is based on the main file in the root directory.
201If you want to contribute, please make the change in the main file.
202
203Vorbis Decoding
204---------------
205Vorbis decoding is enabled via stb_vorbis. To use it, you need to include the header section of stb_vorbis
206before the implementation of miniaudio. You can enable Vorbis by doing the following:
207
208```c
209#define STB_VORBIS_HEADER_ONLY
210#include "extras/stb_vorbis.c"    /* Enables Vorbis decoding. */
211
212#define MINIAUDIO_IMPLEMENTATION
213#include "miniaudio.h"
214
215/* stb_vorbis implementation must come after the implementation of miniaudio. */
216#undef STB_VORBIS_HEADER_ONLY
217#include "extras/stb_vorbis.c"
218```
219
220
221Unofficial Bindings
222===================
223The projects below offer bindings for other languages which you may be interested in. Note that these
224are unofficial and are not maintained as part of this repository. If you encounter a binding-specific
225bug, please post a bug report to the specific project. If you've written your own bindings let me know
226and I'll consider adding it to this list.
227
228Language | Project
229---------|--------
230Go       | [malgo](https://github.com/gen2brain/malgo)
231Python   | [pyminiaudio](https://github.com/irmen/pyminiaudio)
232Rust     | [miniaudio-rs](https://github.com/ExPixel/miniaudio-rs)
233