Commit 3ffdbdc7 authored by David Reid's avatar David Reid

Add miniaudio.c.

This is in preparation for splitting miniaudio into a split .c/h pair,
away from a single header.

`MINIAUDIO_IMPLEMENTATION` is still supported, but will be removed in
version 0.12 and should be considered deprecated. It's recommended to
start the transition to the new .c file.
parent 9b9e71ab
v0.11.22 - TBD v0.11.22 - TBD
===================== =====================
* Starting from version 0.12, miniaudio will be switching to a split .c/h pair, away from a single header. In preparation for this, a file named "miniaudio.c" has been added to repository. Currently this is just a simple wrapper around miniaudio.h and `MINIAUDIO_IMPLEMENTATION`. Nothing has changed in miniaudio.h, however when version 0.12 is released you will need to use miniaudio.c for the implementation. It's recommended you start the transition away from `MINIAUDIO_IMPLEMENTATION` and towards miniaudio.c. If you want to keep building your project as a single translation unit, you can do `#include "miniaudio.c"` which will continue to be supported with version 0.12 and beyond.
* Add `MA_SOUND_FLAG_LOOPING` and `MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_LOOPING` flags. These can be used to initialize sounds and resource managed data sources to loop by default. This is the recommended way to enable looping for streams. The `isLooping` config option in `ma_sound_config` and `ma_resource_manager_data_source_config` has been deprecated. If you are using those, you should switch to the new flag or else you'll get compiler errors when upgrading to a future version. * Add `MA_SOUND_FLAG_LOOPING` and `MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_LOOPING` flags. These can be used to initialize sounds and resource managed data sources to loop by default. This is the recommended way to enable looping for streams. The `isLooping` config option in `ma_sound_config` and `ma_resource_manager_data_source_config` has been deprecated. If you are using those, you should switch to the new flag or else you'll get compiler errors when upgrading to a future version.
* `ma_rb_commit_read()`, `ma_rb_commit_write()`, `ma_pcm_rb_commit_read()` and `ma_pcm_rb_commit_write()` no longer return `MA_AT_END`. The reason for this change is that there's no real notion of an "end" in a ring buffer which makes this result code confusing. In addition, it's possible for these functions to return something other than `MA_SUCCESS` when the operation completed successfully which adds to the confusion. The correct way to check if there is any more room in the ring buffer is to look at the frame count returned by `*rb_acquire_read/write()`. * `ma_rb_commit_read()`, `ma_rb_commit_write()`, `ma_pcm_rb_commit_read()` and `ma_pcm_rb_commit_write()` no longer return `MA_AT_END`. The reason for this change is that there's no real notion of an "end" in a ring buffer which makes this result code confusing. In addition, it's possible for these functions to return something other than `MA_SUCCESS` even when the operation completed successfully which adds to the confusion. The correct way to check if there is any more room in the ring buffer is to look at the frame count returned by `*rb_acquire_read/write()`.
* The `ma_pcm_rb` data source implementation has been modified to pad output data with silence if there is not enough data in the ring buffer to fill the request. What this means is for an `ma_pcm_rb`, `ma_data_source_read_pcm_frames()` should no longer return a frame count of less than what you requested, and will therefore never return `MA_AT_END` which does not make sense for a ring buffer since it does not have the notion of an end. This change should make it much easier to use a ring buffer as the data source for a `ma_sound`. * The `ma_pcm_rb` data source implementation has been modified to pad output data with silence if there is not enough data in the ring buffer to fill the request. What this means is for an `ma_pcm_rb`, `ma_data_source_read_pcm_frames()` should no longer return a frame count of less than what you requested, and will therefore never return `MA_AT_END` which does not make sense for a ring buffer since it does not have the notion of an end. This change should make it much easier to use a ring buffer as the data source for a `ma_sound`.
* Fix a bug relating to node detachment. * Fix a bug relating to node detachment.
* Fix a bug where amplification with `ma_device_set_master_volume()` does not work. * Fix a bug where amplification with `ma_device_set_master_volume()` does not work.
...@@ -14,7 +15,7 @@ v0.11.22 - TBD ...@@ -14,7 +15,7 @@ v0.11.22 - TBD
* AAudio: Fix an error where the device is silenced after rerouting. With this change, miniaudio will no longer give AAudio a hint to use your supplied period size which will therefore result in AAudio using its default latency configuration. If you want AAudio to try to use the period size you supply in the device config, which is the old behaviour, set `aaudio.allowSetBufferCapacity` to true in the device config. Note, however, if you do this you may end up with errors when rerouting between devices. * AAudio: Fix an error where the device is silenced after rerouting. With this change, miniaudio will no longer give AAudio a hint to use your supplied period size which will therefore result in AAudio using its default latency configuration. If you want AAudio to try to use the period size you supply in the device config, which is the old behaviour, set `aaudio.allowSetBufferCapacity` to true in the device config. Note, however, if you do this you may end up with errors when rerouting between devices.
* AAudio: The default minimum SDK version has been increased from 26 to 27 when enabling AAudio. If you need to support version 26, you can use `#define MA_AAUDIO_MIN_ANDROID_SDK_VERSION 26`. * AAudio: The default minimum SDK version has been increased from 26 to 27 when enabling AAudio. If you need to support version 26, you can use `#define MA_AAUDIO_MIN_ANDROID_SDK_VERSION 26`.
* AAudio: Fix ma_device_get_info() implementation. * AAudio: Fix ma_device_get_info() implementation.
* PulseAudio: Allow setting the channel map requested from PulseAudio in device configs * PulseAudio: Allow setting the channel map requested from PulseAudio in device configs.
v0.11.21 - 2023-11-15 v0.11.21 - 2023-11-15
......
...@@ -51,7 +51,6 @@ Examples ...@@ -51,7 +51,6 @@ Examples
This example shows one way to play a sound using the high level API. This example shows one way to play a sound using the high level API.
```c ```c
#define MINIAUDIO_IMPLEMENTATION
#include "miniaudio.h" #include "miniaudio.h"
#include <stdio.h> #include <stdio.h>
...@@ -80,7 +79,6 @@ int main() ...@@ -80,7 +79,6 @@ int main()
This example shows how to decode and play a sound using the low level API. This example shows how to decode and play a sound using the low level API.
```c ```c
#define MINIAUDIO_IMPLEMENTATION
#include "miniaudio.h" #include "miniaudio.h"
#include <stdio.h> #include <stdio.h>
...@@ -149,28 +147,14 @@ More examples can be found in the [examples](examples) folder or online here: ht ...@@ -149,28 +147,14 @@ More examples can be found in the [examples](examples) folder or online here: ht
Building Building
======== ========
Do the following in one source file: Just compile miniaudio.c like any other source file and include miniaudio.h like a normal header. There's no need
```c to install any dependencies. On Windows and macOS there's no need to link to anything. On Linux and BSD just link
#define MINIAUDIO_IMPLEMENTATION to `-lpthread` and `-lm`. On iOS you need to compile as Objective-C. Link to `-ldl` if you get errors about
#include "miniaudio.h" `dlopen()`, etc.
```
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 just link to `-lpthread`, `-lm` and `-ldl`. On BSD just link to `-lpthread` and `-lm`.
On iOS you need to compile as Objective-C.
If you get errors about undefined references to `__sync_val_compare_and_swap_8`, `__atomic_load_8`, etc. you If you get errors about undefined references to `__sync_val_compare_and_swap_8`, `__atomic_load_8`, etc. you
need to link with `-latomic`. need to link with `-latomic`.
If you prefer separate .h and .c files, you can find a split version of miniaudio in the extras/miniaudio_split
folder. From here you can use miniaudio as a traditional .c and .h library - just add miniaudio.c to your source
tree like any other source file and include miniaudio.h like a normal header. If you prefer compiling as a
single translation unit (AKA unity builds), you can just #include the .c file in your main source file:
```c
#include "miniaudio.c"
```
Note that the split version is auto-generated using a tool and is based on the main file in the root directory.
If you want to contribute, please make the change in the main file.
ABI compatibility is not guaranteed between versions so take care if compiling as a DLL/SO. The suggested way ABI compatibility is not guaranteed between versions so take care if compiling as a DLL/SO. The suggested way
to integrate miniaudio is by adding it directly to your source tree. to integrate miniaudio is by adding it directly to your source tree.
......
#define MINIAUDIO_IMPLEMENTATION
#include "miniaudio.h"
...@@ -12,15 +12,18 @@ GitHub: https://github.com/mackron/miniaudio ...@@ -12,15 +12,18 @@ GitHub: https://github.com/mackron/miniaudio
/* /*
1. Introduction 1. Introduction
=============== ===============
miniaudio is a single file library for audio playback and capture. To use it, do the following in To use miniaudio, include "miniaudio.h":
one .c file:
```c ```c
#define MINIAUDIO_IMPLEMENTATION
#include "miniaudio.h" #include "miniaudio.h"
``` ```
You can do `#include "miniaudio.h"` in other parts of the program just like any other header. The implementation is contained in "miniaudio.c". Just compile this like any other source file. You
can include miniaudio.c if you want to compile your project as a single translation unit:
```c
#include "miniaudio.c"
```
miniaudio includes both low level and high level APIs. The low level API is good for those who want miniaudio includes both low level and high level APIs. The low level API is good for those who want
to do all of their mixing themselves and only require a light weight interface to the underlying to do all of their mixing themselves and only require a light weight interface to the underlying
...@@ -483,21 +486,12 @@ link the relevant frameworks but should compile cleanly out of the box with Xcod ...@@ -483,21 +486,12 @@ link the relevant frameworks but should compile cleanly out of the box with Xcod
through the command line requires linking to `-lpthread` and `-lm`. through the command line requires linking to `-lpthread` and `-lm`.
Due to the way miniaudio links to frameworks at runtime, your application may not pass Apple's Due to the way miniaudio links to frameworks at runtime, your application may not pass Apple's
notarization process. To fix this there are two options. The first is to use the notarization process. To fix this there are two options. The first is to compile with
`MA_NO_RUNTIME_LINKING` option, like so: `-DMA_NO_RUNTIME_LINKING` which in turn will require linking with
`-framework CoreFoundation -framework CoreAudio -framework AudioToolbox`. If you get errors about
```c AudioToolbox, try with `-framework AudioUnit` instead. You may get this when using older versions
#ifdef __APPLE__ of iOS. Alternatively, if you would rather keep using runtime linking you can add the following to
#define MA_NO_RUNTIME_LINKING your entitlements.xcent file:
#endif
#define MINIAUDIO_IMPLEMENTATION
#include "miniaudio.h"
```
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:
``` ```
<key>com.apple.security.cs.allow-dyld-environment-variables</key> <key>com.apple.security.cs.allow-dyld-environment-variables</key>
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