{"id":16376620,"url":"https://github.com/udoprog/audio","last_synced_at":"2025-10-25T04:33:47.477Z","repository":{"id":48059418,"uuid":"351938681","full_name":"udoprog/audio","owner":"udoprog","description":"A crate for working with audio in Rust","archived":false,"fork":false,"pushed_at":"2024-09-12T14:41:01.000Z","size":1156,"stargazers_count":78,"open_issues_count":17,"forks_count":11,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-12-19T09:07:54.031Z","etag":null,"topics":["alsa","audio","rust","wasapi"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/udoprog.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","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}},"created_at":"2021-03-26T23:40:51.000Z","updated_at":"2024-10-15T13:06:37.000Z","dependencies_parsed_at":"2023-11-06T07:41:16.051Z","dependency_job_id":"18811961-8dac-43eb-a6d5-b01ef97fb2b0","html_url":"https://github.com/udoprog/audio","commit_stats":{"total_commits":203,"total_committers":2,"mean_commits":101.5,"dds":"0.054187192118226646","last_synced_commit":"dae9e00a59e6b1d96ddda3313742a518bedc4aad"},"previous_names":["udoprog/rotary"],"tags_count":36,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/udoprog%2Faudio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/udoprog%2Faudio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/udoprog%2Faudio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/udoprog%2Faudio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/udoprog","download_url":"https://codeload.github.com/udoprog/audio/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247312054,"owners_count":20918341,"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":["alsa","audio","rust","wasapi"],"created_at":"2024-10-11T03:25:20.535Z","updated_at":"2025-10-25T04:33:42.420Z","avatar_url":"https://github.com/udoprog.png","language":"Rust","readme":"# audio\n\n[\u003cimg alt=\"github\" src=\"https://img.shields.io/badge/github-udoprog/audio-8da0cb?style=for-the-badge\u0026logo=github\" height=\"20\"\u003e](https://github.com/udoprog/audio)\n[\u003cimg alt=\"crates.io\" src=\"https://img.shields.io/crates/v/audio.svg?style=for-the-badge\u0026color=fc8d62\u0026logo=rust\" height=\"20\"\u003e](https://crates.io/crates/audio)\n[\u003cimg alt=\"docs.rs\" src=\"https://img.shields.io/badge/docs.rs-audio-66c2a5?style=for-the-badge\u0026logoColor=white\u0026logo=data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDUxMiA1MTIiPjxwYXRoIGZpbGw9IiNmNWY1ZjUiIGQ9Ik00ODguNiAyNTAuMkwzOTIgMjE0VjEwNS41YzAtMTUtOS4zLTI4LjQtMjMuNC0zMy43bC0xMDAtMzcuNWMtOC4xLTMuMS0xNy4xLTMuMS0yNS4zIDBsLTEwMCAzNy41Yy0xNC4xIDUuMy0yMy40IDE4LjctMjMuNCAzMy43VjIxNGwtOTYuNiAzNi4yQzkuMyAyNTUuNSAwIDI2OC45IDAgMjgzLjlWMzk0YzAgMTMuNiA3LjcgMjYuMSAxOS45IDMyLjJsMTAwIDUwYzEwLjEgNS4xIDIyLjEgNS4xIDMyLjIgMGwxMDMuOS01MiAxMDMuOSA1MmMxMC4xIDUuMSAyMi4xIDUuMSAzMi4yIDBsMTAwLTUwYzEyLjItNi4xIDE5LjktMTguNiAxOS45LTMyLjJWMjgzLjljMC0xNS05LjMtMjguNC0yMy40LTMzLjd6TTM1OCAyMTQuOGwtODUgMzEuOXYtNjguMmw4NS0zN3Y3My4zek0xNTQgMTA0LjFsMTAyLTM4LjIgMTAyIDM4LjJ2LjZsLTEwMiA0MS40LTEwMi00MS40di0uNnptODQgMjkxLjFsLTg1IDQyLjV2LTc5LjFsODUtMzguOHY3NS40em0wLTExMmwtMTAyIDQxLjQtMTAyLTQxLjR2LS42bDEwMi0zOC4yIDEwMiAzOC4ydi42em0yNDAgMTEybC04NSA0Mi41di03OS4xbDg1LTM4Ljh2NzUuNHptMC0xMTJsLTEwMiA0MS40LTEwMi00MS40di0uNmwxMDItMzguMiAxMDIgMzguMnYuNnoiPjwvcGF0aD48L3N2Zz4K\" height=\"20\"\u003e](https://docs.rs/audio)\n[\u003cimg alt=\"build status\" src=\"https://img.shields.io/github/actions/workflow/status/udoprog/audio/ci.yml?branch=main\u0026style=for-the-badge\" height=\"20\"\u003e](https://github.com/udoprog/audio/actions?query=branch%3Amain)\n\nA crate for working with audio in Rust.\n\nThis is made up of several parts, each can be used independently of each\nother:\n\n* [audio-core] - The core crate, which defines traits that allows for\n  interacting with audio buffers independent of their layout in memory.\n* [audio] - This crate, which provides a collection of high-quality audio\n  buffers which implements the traits provided in [audio-core].\n* [audio-device] - A crate for interacting with audio devices in idiomatic\n  Rust.\n* [audio-generator] - A crate for generating audio.\n\nAudio buffers provided by this crate have zero or more channels that can be\niterated over. A channel is simply a sequence of samples. The samples within\neach channel at one moment in time are a frame. A buffer can store channels\nin various ways in memory, as detailed in the next section.\n\n\u003cbr\u003e\n\n## Buffers\n\nThis crate provides several structs for storing buffers of multichannel\naudio. The examples represent how the two channels `[1, 2, 3, 4]` and `[5,\n6, 7, 8]` are stored in memory:\n\n* [Dynamic]: each channel is stored in its own heap allocation. So `[1, 2,\n  3, 4]` and `[5, 6, 7, 8]`. This may be more performant when resizing\n  freqently. Generally prefer one of the other buffer types for better CPU\n  cache locality.\n* [Interleaved]: samples of each channel are interleaved in one heap\n  allocation. So `[1, 5, 2, 6, 3, 7, 4, 8]`.\n* [Sequential]: each channel is stored one after the other in one heap\n  allocation. So `[1, 2, 3, 4, 5, 6, 7, 8]`.\n\nThese all implement the [Buf] and [BufMut] traits, allowing library authors\nto abstract over any one specific format. The exact channel and frame count\nof a buffer is known as its *topology*. The following example allocates\nbuffers with 4 frames and 2 channels. The buffers are arranged in memory\ndifferently, but data is copied into them using the same API.\n\n```rust\nuse audio::{BufMut, ChannelMut};\n\nlet mut dynamic = audio::dynamic![[0i16; 4]; 2];\nlet mut interleaved = audio::interleaved![[0i16; 4]; 2];\nlet mut sequential = audio::sequential![[0i16; 4]; 2];\n\naudio::channel::copy_iter(0i16.., dynamic.get_mut(0).unwrap());\naudio::channel::copy_iter(0i16.., interleaved.get_mut(0).unwrap());\naudio::channel::copy_iter(0i16.., sequential.get_mut(0).unwrap());\n```\n\nWe also support [wrapping][wrap] external buffers so that they can\ninteroperate like other audio buffers.\n\n\u003cbr\u003e\n\n## Example: [play-mp3]\n\nPlay an mp3 file with [minimp3-rs], [cpal], and [rubato] for resampling.\n\nThis example can handle with any channel and sample rate configuration.\n\n```bash\ncargo run --release --package audio-examples --bin play-mp3 -- path/to/file.mp3\n```\n\n\u003cbr\u003e\n\n## Examples\n\n```rust\nuse rand::Rng;\n\nlet mut buf = audio::buf::Dynamic::\u003cf32\u003e::new();\n\nbuf.resize_channels(2);\nbuf.resize_frames(2048);\n\n/// Fill both channels with random noise.\nlet mut rng = rand::thread_rng();\nrng.fill(\u0026mut buf[0]);\nrng.fill(\u0026mut buf[1]);\n```\n\nFor convenience we also provide several macros for constructing various\nforms of dynamic audio buffers. These should mostly be used for testing.\n\n```rust\nlet mut buf = audio::buf::Dynamic::\u003cf32\u003e::with_topology(4, 8);\n\nfor mut channel in \u0026mut buf {\n    for f in channel.iter_mut() {\n        *f = 2.0;\n    }\n}\n\nassert_eq! {\n    buf,\n    audio::dynamic![[2.0; 8]; 4],\n};\n\nassert_eq! {\n    buf,\n    audio::dynamic![[2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0]; 4],\n};\n```\n\n[audio-core]: https://docs.rs/audio-core\n[audio-device]: https://docs.rs/audio-device\n[audio-generator]: https://docs.rs/audio-generator\n[audio]: https://docs.rs/audio\n[Buf]: https://docs.rs/audio-core/latest/audio_core/trait.Buf.html\n[BufMut]: https://docs.rs/audio-core/latest/audio_core/trait.BufMut.html\n[cpal]: https://github.com/RustAudio/cpal\n[Dynamic::resize]: https://docs.rs/audio/latest/audio/dynamic/struct.Dynamic.html#method.resize\n[dynamic!]: https://docs.rs/audio/latest/audio/macros/macro.dynamic.html\n[Dynamic]: https://docs.rs/audio/latest/audio/dynamic/struct.Dynamic.html\n[Interleaved]: https://docs.rs/audio/latest/audio/interleaved/struct.Interleaved.html\n[minimp3-rs]: https://github.com/germangb/minimp3-rs\n[play-mp3]: https://github.com/udoprog/audio/tree/main/examples/src/bin/play-mp3.rs\n[rubato]: https://github.com/HEnquist/rubato\n[Sequential]: https://docs.rs/audio/latest/audio/sequential/struct.Sequential.html\n[wrap]: https://docs.rs/audio/latest/audio/wrap/index.html\n","funding_links":[],"categories":["Rust"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fudoprog%2Faudio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fudoprog%2Faudio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fudoprog%2Faudio/lists"}