2 <a href="https://miniaud.io"><img src="https://miniaud.io/img/miniaudio_wide.png" alt="miniaudio" width="1280"></a>
6 <h4 align="center">A single file library for audio playback and capture.</h4>
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>
14 <a href="#examples">Examples</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>
26 This example shows one way to play a sound using the high level API.
29 #define MINIAUDIO_IMPLEMENTATION
30 #include "../miniaudio.h"
34 int main(int argc, char** argv)
40 printf("No input file.");
44 result = ma_engine_init(NULL, &engine);
45 if (result != MA_SUCCESS) {
46 printf("Failed to initialize audio engine.");
50 ma_engine_play_sound(&engine, argv[1], NULL);
52 printf("Press Enter to quit...");
55 ma_engine_uninit(&engine);
61 This example shows how to decode and play a sound using the low level API.
64 #define MINIAUDIO_IMPLEMENTATION
65 #include "../miniaudio.h"
69 void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount)
71 ma_decoder* pDecoder = (ma_decoder*)pDevice->pUserData;
72 if (pDecoder == NULL) {
76 ma_decoder_read_pcm_frames(pDecoder, pOutput, frameCount);
81 int main(int argc, char** argv)
85 ma_device_config deviceConfig;
89 printf("No input file.\n");
93 result = ma_decoder_init_file(argv[1], NULL, &decoder);
94 if (result != MA_SUCCESS) {
98 deviceConfig = ma_device_config_init(ma_device_type_playback);
99 deviceConfig.playback.format = decoder.outputFormat;
100 deviceConfig.playback.channels = decoder.outputChannels;
101 deviceConfig.sampleRate = decoder.outputSampleRate;
102 deviceConfig.dataCallback = data_callback;
103 deviceConfig.pUserData = &decoder;
105 if (ma_device_init(NULL, &deviceConfig, &device) != MA_SUCCESS) {
106 printf("Failed to open playback device.\n");
107 ma_decoder_uninit(&decoder);
111 if (ma_device_start(&device) != MA_SUCCESS) {
112 printf("Failed to start playback device.\n");
113 ma_device_uninit(&device);
114 ma_decoder_uninit(&decoder);
118 printf("Press Enter to quit...");
121 ma_device_uninit(&device);
122 ma_decoder_uninit(&decoder);
128 More examples can be found in the [examples](examples) folder or online here: https://miniaud.io/docs/examples/
133 Online documentation can be found here: https://miniaud.io/docs/
135 Documentation can also be found at the top of [miniaudio.h](https://raw.githubusercontent.com/mackron/miniaudio/master/miniaudio.h)
136 which is always the most up-to-date and authoritive source of information on how to use miniaudio. All other
137 documentation is generated from this in-code documentation.
161 - audio(4) (NetBSD and OpenBSD)
163 - AAudio (Android 8.0+)
164 - OpenSL|ES (Android only)
165 - Web Audio (Emscripten)
172 - Your choice of either public domain or [MIT No Attribution](https://github.com/aws/mit-0).
173 - Entirely contained within a single file for easy integration into your source tree.
174 - No external dependencies except for the C standard library and backend libraries.
175 - Written in C and compilable as C++, enabling miniaudio to work on almost all compilers.
176 - Supports all major desktop and mobile platforms, with multiple backends for maximum compatibility.
177 - A low level API with direct access to the raw audio data.
178 - A high level API with sound management and effects, including 3D spatialization.
179 - Supports playback, capture, full-duplex and loopback (WASAPI only).
180 - Device enumeration for connecting to specific devices, not just defaults.
181 - Connect to multiple devices at once.
182 - Shared and exclusive mode on supported backends.
183 - Resource management for loading and streaming sounds.
184 - A node graph system for advanced mixing and effect processing.
185 - Data conversion (sample format conversion, channel conversion and resampling).
188 - Low-pass (first, second and high order)
189 - High-pass (first, second and high order)
190 - Band-pass (second and high order)
195 - Waveform generation (sine, square, triangle, sawtooth).
196 - Noise generation (white, pink, Brownian).
201 - Vorbis via stb_vorbis (not built in - must be included separately).
206 Refer to the [Programming Manual](https://miniaud.io/docs/manual/) for a more complete description of
207 available features in miniaudio.
212 Do the following in one source file:
214 #define MINIAUDIO_IMPLEMENTATION
215 #include "miniaudio.h"
217 Then just compile. There's no need to install any dependencies. On Windows and macOS there's no need to link
218 to anything. On Linux just link to -lpthread, -lm and -ldl. On BSD just link to -lpthread and -lm. On iOS you
219 need to compile as Objective-C.
221 If you prefer separate .h and .c files, you can find a split version of miniaudio in the extras/miniaudio_split
222 folder. From here you can use miniaudio as a traditional .c and .h library - just add miniaudio.c to your source
223 tree like any other source file and include miniaudio.h like a normal header. If you prefer compiling as a
224 single translation unit (AKA unity builds), you can just #include the .c file in your main source file:
226 #include "miniaudio.c"
228 Note that the split version is auto-generated using a tool and is based on the main file in the root directory.
229 If you want to contribute, please make the change in the main file.
233 Vorbis decoding is enabled via stb_vorbis. To use it, you need to include the header section of stb_vorbis
234 before the implementation of miniaudio. You can enable Vorbis by doing the following:
237 #define STB_VORBIS_HEADER_ONLY
238 #include "extras/stb_vorbis.c" /* Enables Vorbis decoding. */
240 #define MINIAUDIO_IMPLEMENTATION
241 #include "miniaudio.h"
243 /* stb_vorbis implementation must come after the implementation of miniaudio. */
244 #undef STB_VORBIS_HEADER_ONLY
245 #include "extras/stb_vorbis.c"
251 The projects below offer bindings for other languages which you may be interested in. Note that these
252 are unofficial and are not maintained as part of this repository. If you encounter a binding-specific
253 bug, please post a bug report to the specific project. If you've written your own bindings let me know
254 and I'll consider adding it to this list.
258 Go | [malgo](https://github.com/gen2brain/malgo)
259 Python | [pyminiaudio](https://github.com/irmen/pyminiaudio)
260 Rust | [miniaudio-rs](https://github.com/ExPixel/miniaudio-rs)