Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/feliwir/SharpAudio
Audio playback/capturing engine for C#
https://github.com/feliwir/SharpAudio
audio csharp music netcore netstandard openal sound wrapper xaudio
Last synced: 1 day ago
JSON representation
Audio playback/capturing engine for C#
- Host: GitHub
- URL: https://github.com/feliwir/SharpAudio
- Owner: feliwir
- License: mit
- Created: 2018-10-09T19:46:51.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-21T07:58:11.000Z (over 1 year ago)
- Last Synced: 2024-11-07T19:36:21.857Z (5 days ago)
- Topics: audio, csharp, music, netcore, netstandard, openal, sound, wrapper, xaudio
- Language: C#
- Size: 20.4 MB
- Stars: 174
- Watchers: 11
- Forks: 19
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SharpAudio
SharpAudio is a cross-platform, backend-agnostic library to playback sounds in .NET. It achieves that by wrapping the platform specific backends.Supported backends:
- XAudio2
- OpenAL# Build status
![Build Status](https://github.com/feliwir/SharpAudio/workflows/CI/badge.svg?branch=master&event=push)
![Nuget](https://img.shields.io/nuget/v/SharpAudio)# Example
SharpAudio provides a low-level interface that wraps audio sources & buffers:
```csharp
var engine = AudioEngine.CreateDefault();
var buffer = engine.CreateBuffer();
var source = engine.CreateSource();// Play a 1s long sound at 440hz
AudioFormat format;
format.BitsPerSample = 16;
format.Channels = 1;
format.SampleRate = 44100;
float freq = 440.0f;
var size = format.SampleRate;
var samples = new short[size];for (int i = 0; i < size; i++)
{
samples[i] = (short)(32760 * Math.Sin((2 * Math.PI * freq) / size * i));
}buffer.BufferData(samples, format);
source.QueueBuffer(buffer);
source.Play();
```A high level interface that can load and play sound files is provided in the SharpAudio.Codec package:
```csharp
var engine = AudioEngine.CreateDefault();
var soundStream = new SoundStream(File.OpenRead("test.mp3"), engine);soundStream.Volume = 0.5f;
soundStream.Play();
```The following sound formats are supported at the moment:
- `.wav` (PCM & ADPCM)
- `.mp3`
- `.ogg` (WIP: Vorbis & Opus)