{"id":16947545,"url":"https://github.com/mrdimas/tinyaudio","last_synced_at":"2025-04-08T01:36:16.345Z","repository":{"id":142715999,"uuid":"612661891","full_name":"mrDIMAS/tinyaudio","owner":"mrDIMAS","description":"TinyAudio is a cross-platform audio output library","archived":false,"fork":false,"pushed_at":"2024-10-21T14:50:57.000Z","size":59,"stargazers_count":173,"open_issues_count":2,"forks_count":8,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-10-22T04:03:06.683Z","etag":null,"topics":["audio","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mrDIMAS.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":"https://boosty.to/fyrox"}},"created_at":"2023-03-11T16:01:05.000Z","updated_at":"2024-10-21T17:18:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"a212073a-dcd8-4917-b46b-fcb377d06177","html_url":"https://github.com/mrDIMAS/tinyaudio","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrDIMAS%2Ftinyaudio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrDIMAS%2Ftinyaudio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrDIMAS%2Ftinyaudio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrDIMAS%2Ftinyaudio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrDIMAS","download_url":"https://codeload.github.com/mrDIMAS/tinyaudio/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247761051,"owners_count":20991531,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["audio","rust"],"created_at":"2024-10-13T21:47:29.232Z","updated_at":"2025-04-08T01:36:16.325Z","avatar_url":"https://github.com/mrDIMAS.png","language":"Rust","funding_links":["https://boosty.to/fyrox"],"categories":[],"sub_categories":[],"readme":"# TinyAudio\n\nTinyAudio is a cross-platform audio output library. Its main goal to provide unified access to\na default sound output device of your operating system as easy as possible, covering as many platforms\nsuch as PC (Windows, Linux, macOS), Mobile Devices (Android, iOS), and WebAssembly.\n\n## What this crate can do\n\nThe crate just takes the data you've prepared and sends it to a default operating system's sound output\ndevice. It uses floating-point audio samples and converts them to the closest supported platform-dependent\nformat automatically. The crate guarantees, that the intermediate data buffer will always be of requested size.\nUse this crate, if you need to play your audio samples as easy as possible.\n\n## What this crate cannot do\n\nIt does not load any sound formats, it doesn't apply any digital signal processing (DSP) techniques, it\ndoesn't do audio spatialization and so on. Also, the crate does not support device enumeration, device\nselection, querying of supported formats, input capturing (i.e. from microphone).\n\n## Supported platforms\n\n| Windows | Linux | macOS | WebAssembly | Android | iOS |\n|---------|-------|-------|-------------|---------|-----|\n| ✅       | ✅     | ✅    | ✅           | ✅       | ✅  |\n\n## How it works\n\nThe crate internally creates an audio output context and uses a user-defined callback to supply the device\nwith samples to play. The callback will be called periodically to generate new data; it will be called util\nthe device instance is \"alive\". In other words this crate performs the simplest audio streaming.\n\n## Android details\n\nThis crate uses `AAudio` for audio output on Android platform. `AAudio` is quite new API, which was added in ~2017 \n(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\ninitialize an audio device only after your application has gained focus (`GainedFocus` event in `android-activity` crate),\notherwise device creation will fail. See `android-examples` \n[directory](https://github.com/mrDIMAS/tinyaudio/tree/main/android-examples) for examples. \n\n## WebAssembly details\n\nMost of the web browsers nowadays requires a \"confirmation\" action from a user (usually a button click or something similar) to \nallow a web page to play an audio. This means that you must initialize an audio device _only_ after some action on\na web page that runs your WebAssembly package. In the simplest scenario it could be a simple button with a callback\nthat initializes an audio device. See `wasm-examples` [directory](https://github.com/mrDIMAS/tinyaudio/tree/main/android-examples)\nfor examples.\n\n## Examples\n\nThe crate is very easy to use, here's a few examples that will help you to start using it right away.\n\n### Initialization\n\nThe simplest possible example that shows how to initialize an output device.\n\n```rust,no_run\nuse tinyaudio::prelude::*;\n\nlet _device = run_output_device(\n    OutputDeviceParameters {\n        channels_count: 2,\n        sample_rate: 44100,\n        channel_sample_count: 4410,\n    },\n    move |_| {\n        // Output silence\n    },\n)\n.unwrap();\n\nstd::thread::sleep(std::time::Duration::from_secs(1));\n```\n\n### Playing a sine wave\n\nA simple example that plays a sine wave of 440 Hz looks like so:\n\n```rust,no_run\n# use tinyaudio::prelude::*;\nlet params = OutputDeviceParameters {\n    channels_count: 2,\n    sample_rate: 44100,\n    channel_sample_count: 4410,\n};\n\nlet _device = run_output_device(params, {\n    let mut clock = 0f32;\n    move |data| {\n        for samples in data.chunks_mut(params.channels_count) {\n            clock = (clock + 1.0) % params.sample_rate as f32;\n            let value =\n                (clock * 440.0 * 2.0 * std::f32::consts::PI / params.sample_rate as f32).sin();\n            for sample in samples {\n                *sample = value;\n            }\n        }\n    }\n})\n.unwrap();\n\nstd::thread::sleep(std::time::Duration::from_secs(5));\n```\n\n## Comparison with alternatives\n\nThe closest alternative is `cpal` which is much more feature-rich, and has more complex API. Initialization of\n`cpal` is quite verbose and could be confusing.\nCompare [this example](https://github.com/RustAudio/cpal/blob/f43d36e55494993bbbde3299af0c53e5cdf4d4cf/examples/beep.rs)\nfrom `cpal` with the example from the above code snippet. The next main difference is that `cpal` does not guarantee\nthat the size of the output buffer will be exactly the same as requested during the creation of audio stream, while\n`TinyAudio` strictly guarantees this. Having a buffer of fixed size could be mandatory for some algorithms (such as\nHRTF). That last main difference is fixed sample format - it is guaranteed to be `f32`. This simplifies a lot of\nalgorithms and have almost the same performance as with integer samples on relatively modern hardware.\n\nFeature-parity with `cpal` is not a goal for this library, its main goal is to do one particular task, but do it as well\nas possible.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrdimas%2Ftinyaudio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrdimas%2Ftinyaudio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrdimas%2Ftinyaudio/lists"}