11# TinyAudio
22
3- TinyAudio is a cross-platform audio output library. Its main goal to provide unified access to
3+ TinyAudio is a cross-platform audio output library. Its main goal is to provide unified access to
44a default sound output device of your operating system as easy as possible, covering as many platforms
55such as PC (Windows, Linux, macOS), Mobile Devices (Android, iOS), and WebAssembly.
66
77## What this crate can do
88
99The crate just takes the data you've prepared and sends it to a default operating system's sound output
1010device. It uses floating-point audio samples and converts them to the closest supported platform-dependent
11- format automatically. The crate guarantees, that the intermediate data buffer will always be of requested size.
11+ format automatically. The crate guarantees that the intermediate data buffer will always be of requested size.
1212Use this crate, if you need to play your audio samples as easy as possible.
1313
1414## What this crate cannot do
@@ -21,29 +21,53 @@ selection, querying of supported formats, input capturing (i.e. from microphone)
2121
2222| Windows | Linux | macOS | WebAssembly | Android | iOS |
2323| ---------| -------| -------| -------------| ---------| -----|
24- | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
24+ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
2525
2626## How it works
2727
2828The crate internally creates an audio output context and uses a user-defined callback to supply the device
2929with samples to play. The callback will be called periodically to generate new data; it will be called util
30- the device instance is "alive". In other words this crate performs the simplest audio streaming.
30+ the device instance is "alive". In other words, this crate performs the simplest audio streaming.
3131
3232## Android details
3333
34- This crate uses ` AAudio ` for audio output on Android platform. ` AAudio ` is quite new API, which was added in ~ 2017
34+ This crate uses ` AAudio ` for audio output on Android platform. ` AAudio ` is quite new API, which was added in ~ 2017
3535(in Android 8.1 Oreo). This means that you have to use ` API Level 26+ ` to get the crate up and running. Also, you must
36- initialize an audio device only after your application has gained focus (` GainedFocus ` event in ` android-activity ` crate),
37- otherwise device creation will fail. See ` android-examples `
38- [ directory] ( https://github.com/mrDIMAS/tinyaudio/tree/main/android-examples ) for examples.
36+ initialize an audio device only after your application has gained focus (` GainedFocus ` event in ` android-activity `
37+ crate), otherwise device creation will fail. See ` android-examples `
38+ [ directory] ( https://github.com/mrDIMAS/tinyaudio/tree/main/android-examples ) for examples.
3939
4040## WebAssembly details
4141
42- Most of the web browsers nowadays requires a "confirmation" action from a user (usually a button click or something similar) to
43- allow a web page to play an audio. This means that you must initialize an audio device _ only_ after some action on
44- a web page that runs your WebAssembly package. In the simplest scenario it could be a simple button with a callback
45- that initializes an audio device. See ` wasm-examples ` [ directory] ( https://github.com/mrDIMAS/tinyaudio/tree/main/wasm-examples )
46- for examples.
42+ Most of the web browsers nowadays require a "confirmation" action from a user (usually a button click or something
43+ similar) to allow a web page to play an audio. This means that you must initialize an audio device _ only_ after some
44+ action on
45+ a web page that runs your WebAssembly package. In the simplest scenario, it could be a simple button with a callback
46+ that initializes an audio device. See ` wasm-examples `
47+ [ directory] ( https://github.com/mrDIMAS/tinyaudio/tree/main/wasm-examples ) for examples.
48+
49+ ## Linux details
50+
51+ Do not forget to install the required development libraries, otherwise the crate won't compile:
52+
53+ ``` shell
54+ sudo apt-get install libasound2-dev libudev-dev pkg-config
55+ ```
56+
57+ ### Backends
58+
59+ Linux supports two audio "backends" - ` ALSA ` and ` PulseAudio ` . By default, this crate uses ` ALSA ` , but this can be
60+ changed by specifying the ` pulse ` feature:
61+
62+ ``` toml
63+ tinyaudio = { version = " 2" , default-features = false , features = [" pulse" ] }
64+ ```
65+
66+ ` PulseAudio ` backend requires ` libpulse-dev ` to be installed:
67+
68+ ``` shell
69+ sudo apt-get install libpulse-dev
70+ ```
4771
4872## Examples
4973
@@ -110,7 +134,7 @@ from `cpal` with the example from the above code snippet. The next main differen
110134that the size of the output buffer will be exactly the same as requested during the creation of audio stream, while
111135` TinyAudio ` strictly guarantees this. Having a buffer of fixed size could be mandatory for some algorithms (such as
112136HRTF). That last main difference is fixed sample format - it is guaranteed to be ` f32 ` . This simplifies a lot of
113- algorithms and have almost the same performance as with integer samples on relatively modern hardware.
137+ algorithms and has almost the same performance as with integer samples on relatively modern hardware.
114138
115139Feature-parity with ` cpal ` is not a goal for this library, its main goal is to do one particular task, but do it as well
116140as possible.
0 commit comments