{"id":41766075,"url":"https://github.com/beardgame/audio","last_synced_at":"2026-01-25T02:35:10.478Z","repository":{"id":6451816,"uuid":"42373380","full_name":"beardgame/audio","owner":"beardgame","description":"A basic audio library to be used in conjunction with OpenTK. Contains basic sound loading, playing, and streaming, and related functionality mostly aimed at games.","archived":false,"fork":false,"pushed_at":"2025-05-15T16:32:16.000Z","size":8032,"stargazers_count":7,"open_issues_count":8,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-15T17:35:06.734Z","etag":null,"topics":["audio","audio-library","c-sharp","hacktoberfest","openal","opentk"],"latest_commit_sha":null,"homepage":"","language":"C#","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/beardgame.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2015-09-12T21:16:03.000Z","updated_at":"2025-05-15T16:32:20.000Z","dependencies_parsed_at":"2023-09-27T20:57:29.743Z","dependency_job_id":"9e997ecb-f624-4771-9037-24b9e164ff81","html_url":"https://github.com/beardgame/audio","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/beardgame/audio","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beardgame%2Faudio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beardgame%2Faudio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beardgame%2Faudio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beardgame%2Faudio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/beardgame","download_url":"https://codeload.github.com/beardgame/audio/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beardgame%2Faudio/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28742520,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-25T01:40:51.112Z","status":"online","status_checked_at":"2026-01-25T02:00:06.841Z","response_time":113,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","audio-library","c-sharp","hacktoberfest","openal","opentk"],"created_at":"2026-01-25T02:35:10.410Z","updated_at":"2026-01-25T02:35:10.471Z","avatar_url":"https://github.com/beardgame.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bearded.Audio\n\n[![Build \u0026 test status](https://github.com/beardgame/audio/actions/workflows/dotnet-build.yml/badge.svg)](https://github.com/beardgame/audio/actions/workflows/dotnet-build.yml)\n\n## Introduction\n\nBearded.Audio is a basic audio library aimed to improve interfacing with OpenAL when working with sound in your application. The main use case for this library is use in games, but it should be usable for other applications as well.\n\nThe library uses [OpenTK](https://github.com/opentk/opentk) to interface with OpenAL, and supports loading, playing, and streaming audio using a more object-oriented interface.\n\nPull requests welcome.\n\n## Installation\n\nThe `Bearded.Audio` package is available on NuGet.\n\n## Glossary\n\n* `Listener`: entity in a virtual world that represents the properties of the person listening to the sounds. OpenAL only supports a single listener.\n* `Source`: entity in a virtual world that can play sounds from buffers. These sounds are picked up by the virtual listener. Sources can optionally have properties such as positions and velocity, allowing one to simulate sound in a three-dimensional environment.\n* `Buffer`: space on the sound card or reserved for the software OpenAL implementation for audio data.\n\n## Getting started\n\nThe quickest way to get going is to take a look at the `Bearded.Audio.Example` project, which shows a working example of loading and playing a sound.\n\nTo make a sound play, there are a few steps that have to be done:\n\n1. Load the sound data from a file into a sound buffer.\n2. Create a source from which the sound can be played.\n3. Enqueue the sound buffer into the source.\n4. Play the source.\n\nBefore any audio-related code can be executed, the `AudioContext` needs to be initialized:\n\n```cs\nAudioContext.Initialize();\n```\n\nThis will make sure there is an audio-device that can play the sounds. The `AudioContext` is a singleton, so you only need to initialize it once. However, note that the `AudioContext` uses the `ALContext` from OpenTK under the hood which is thread-specific. If you plan on using multiple threads in your game, make sure the `AudioContext` is initialized on the thread that is used to execute audio code.\n\nNext, we need to load the audio data from a file into the sound buffers. A sound buffer is some reserved space on the sound card (similar to, for example, vertex buffers in graphics programming). For this reason, loading the data to the buffer is split in two steps. First we load the audio data from a file into application memory, and then we write the data to the buffer. This separation can be useful because the total size of the buffers is limited. Decompression of the audio files may be slow, so by keeping the audio data fully uncompressed in memory we make sure audio is ready to go when you need it, as copying to buffers is relatively fast.\n\n```cs\nvar data = SoundBufferData.FromWav(\"assets/pew.wav\");\nvar buffer = new SoundBuffer(data);\n```\n\nThe first line creates a wrapper object for the data just loaded. This data is immutable after loading. The second line makes the sound buffer. Under the hood this reserves enough buffer space to fit the data and copies it immediately. Buffers can be overwritten or filled over time, which can be useful for streaming audio.\n\nAll sounds played through OpenAL come from a source. Sources can be given positions, velocities, and more to simulate a 3D environment. However, for most use cases you don't need to engage with these. Creating a new source is simple:\n\n```cs\nvar source = new Source();\n```\n\nA source can be played, but we need to tell it what buffers it should read the data from. We can use the sound buffers we created previously:\n\n```cs\nsource.QueueBuffer(buffer);\n```\n\nThis will tell the source to play these buffers next. You can queue multiple buffers in a row. To make the source start playing the sounds, there is a simple `Play` method:\n\n```cs\nsource.Play();\n```\n\nNow the sound will play, but after it is done we may want to clean up. To wait until the source is finished playing, we can do something like the following loop:\n\n```cs\nwhile (!source.FinishedPlaying) {\n    Thread.Sleep(100);\n}\n```\n\nOf course in an actual application you may want to link this to an existing update loop or something similar.\n\nThe source keeps track of the number of buffers it has queued in total, and the number of buffers it has played. If those are the same, we know the source has no more buffers to play. At this point we can safely dispose it.\n\n```cs\nsource.Dispose()\n```\n\nThis will clean up a slot for a new source to be created. Alternatively, we can reuse the source. The `DequeueProcessedBuffers` will clear all the buffers already played from the source buffer queue:\n\n```\nsource.DequeueProcessedBuffers();\n```\n\nThis means we can reuse the dequeued buffers for new data or dispose them.\n\nThe total example could look something like:\n\n```cs\nAudioContext.Initialize();\n\nvar data = SoundBufferData.FromWav(\"assets/pew.wav\");\nvar buffer = new SoundBuffer(data);\n\nvar source = new Source();\nsource.QueueBuffer(buffer);\nsource.Play();\n\nwhile (!source.FinishedPlaying) {\n    Thread.Sleep(100);\n}\n\nsource.Dispose();\nAudioContext.Instance.Dispose();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeardgame%2Faudio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeardgame%2Faudio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeardgame%2Faudio/lists"}