Popularity
1.0
Growing
Activity
0.0
Declining
6
1
3

Description

A cross-platform audio playback library that targets .NET Standard 2.1. The main purpose of this project is to provide easy to use API for playing and streaming audio especially in desktop environment.

Behind the scene, it uses FFmpeg to decode audio frames (so it is possible to play video files by taking only audio stream). And PortAudio for sending buffer data or samples to output device using blocking calls mechanism.

Programming language: C#
License: MIT License
Tags: Cross-platform     Media     audio     sound     Codec    

Bufdio alternatives and similar packages

Based on the "Media" category.
Alternatively, view Bufdio alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of Bufdio or a related project?

Add another 'Media' Package

README

Bufdio

NuGet

A cross-platform audio playback library that targets .NET Standard 2.1. The main purpose of this project is to provides an easy to use API for playing and streaming audio file.

It uses FFmpeg to decode audio frames (so, it is possible to play audio stream from a video file). And PortAudio for writing audio stream to output device.

Example

Bufdio Sample

Getting Started

This repository include pre-compiled PortAudio binaries for Windows, Linux, macOS that can be found at the libs directory. However, we can construct PortAudio and FFmpeg by using system-wide libraries.

BufdioLib.InitializePortAudio("path/to/portaudio");
BufdioLib.InitializeFFmpeg("path/to/ffmpeg/libraries");

// Or just use system-wide libraries
BufdioLib.InitializePortAudio();
BufdioLib.InitializeFFmpeg();

With PortAudio initialized, now we can retrieve available output devices.

var defaultDevice = BufdioLib.DefaultOutputDevice;
Console.WriteLine(defaultDevice.Name);
Console.WriteLine(defaultDevice.MaxOutputChannels);
Console.WriteLine(defaultDevice.DefaultSampleRate);
Console.WriteLine(defaultDevice.DefaultHighOutputLatency);

// Retrieve all available output devices
foreach (var device in BufdioLib.OutputDevices)
{
    Console.WriteLine(device.Name);
}

Playing Audio Files

Bufdio provides high level interface for loading audio and control its playback state.

using IAudioPlayer player = new AudioPlayer();

// Methods
player.LoadAsync("audio-url-or-path");
player.LoadAsync(stream);
player.Play();
player.Pause();
player.Stop();
player.Seek(TimeSpan.FromSeconds(2));

// Properties
player.Volume;
player.CustomSampleProcessor;
player.Logger;

// Properties (read-only)
player.State;
player.IsSeeking;
player.IsLoaded;
player.Duration;
player.Position;

// Events
player.StateChanged += OnStateChanged;
player.PositionChanged += OnPositionChanged;

Generate Sine Wave

Bufdio also exposes low level IAudioEngine interface for sending or writing samples to an output device.

const int SampleRate = 8000;
const float Frequency = 350f;
const float Amplitude = 0.35f * short.MaxValue;

var samples = new float[SampleRate];
var options = new AudioEngineOptions(1, SampleRate);

using IAudioEngine engine = new PortAudioEngine(options);

for (var i = 0; i < samples.Length; i++)
{
    samples[i] = (float)(Amplitude * Math.Sin(2 * Math.PI * i * Frequency / SampleRate));
}

Console.WriteLine("Playing 10 times with 1 second delay..");

for (var i = 0; i < 10; i++)
{
    engine.Send(samples);
    Thread.Sleep(1000);
}

TODO

  • Still need more unit tests

Credits

Similar Projects

License

Bufdio is licenced under the MIT license.


*Note that all licence references and agreements mentioned in the Bufdio README section above are relevant to that project's source code only.