Estrol.Miniaudio-CS 1.1.0

dotnet add package Estrol.Miniaudio-CS --version 1.1.0
                    
NuGet\Install-Package Estrol.Miniaudio-CS -Version 1.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Estrol.Miniaudio-CS" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Estrol.Miniaudio-CS" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Estrol.Miniaudio-CS" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Estrol.Miniaudio-CS --version 1.1.0
                    
#r "nuget: Estrol.Miniaudio-CS, 1.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Estrol.Miniaudio-CS@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Estrol.Miniaudio-CS&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Estrol.Miniaudio-CS&version=1.1.0
                    
Install as a Cake Tool

Miniaudio-CS

Auto-generated C# bindings for miniaudio

Miniaudio version: 0.11.23

Fork feature: Optional Ogg vorbis support via minivorbis

Example

High-level engine & sound example:

using System.Runtime.InteropServices;
using Miniaudio;

internal class Program
{
    public unsafe static void Main(string[] args)
    {
        // It is recommended to allocate native memory for miniaudio structures.
        ma_engine* engine = (ma_engine*)NativeMemory.Alloc((nuint)sizeof(ma_engine));
        ma.engine_init(null, engine);

        // When calling a function that accepts a string of type "sbyte*",
        // always convert the string to ANSI encoding first.
        string filePath1 = "music.mp3";
        ma_sound* sound1 = (ma_sound*)NativeMemory.Alloc((nuint)sizeof(ma_sound));
        nint filePath1_Ansi = Marshal.StringToHGlobalAnsi(filePath1);
        ma.sound_init_from_file(engine, (sbyte*)filePath1_Ansi, 0, null, null, sound1);
        Marshal.FreeHGlobal(filePath1_Ansi);
        ma.sound_start(sound1);

        // Note that ANSI encoding does not support certain characters.
        // It is more recommended to use the following methods.

        Console.ReadKey();
        ma.sound_stop(sound1);

        string filePath2 = "😄.wav";
        ma_sound* sound2 = (ma_sound*)NativeMemory.Alloc((nuint)sizeof(ma_sound));
        fixed (void* p = filePath2) // or Marshal.StringToHGlobalUni(filePath2);
        {
            ma.sound_init_from_file_w(engine, (ushort*)p, (uint)ma_sound_flags.MA_SOUND_FLAG_LOOPING, null, null, sound2);
        }
        ma.sound_start(sound2);

        Console.ReadKey();
        ma.sound_stop(sound2);

        // Clean up
        ma.engine_uninit(engine);
        NativeMemory.Free(engine);
        NativeMemory.Free(sound1);
        NativeMemory.Free(sound2);
    }
}

Low-level decoder & device example:

using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using Miniaudio;

internal class Program
{
    static readonly unsafe ma_decoder* decoder;

    public unsafe static void Main(string[] args)
    {
        ma_device* device = (ma_device*)NativeMemory.Alloc((nuint)sizeof(ma_device));
        ma_device_config config = ma.device_config_init(ma_device_type.ma_device_type_playback);

        // Add libvorbis & ogg support
        ma.decoder_config_set_libvorbis_backend(&config);

        config.playback.format = ma_format.ma_format_f32;
        config.playback.channels = 2;
        config.sampleRate = 44100;
        config.dataCallback = &DataCallback;
        config.pUserData = null;

        ma.device_init(null, &config, device);
        ma_decoder_config decoderConfig = ma.decoder_config_init(ma_format.ma_format_f32, 2, 44100);
        decoder = (ma_decoder*)NativeMemory.Alloc((nuint)sizeof(ma_decoder));

        fixed (byte* p = Encoding.ASCII.GetBytes("music.mp3"))
        {
            ma.decoder_init_file((sbyte*)p, &decoderConfig, decoder);
        }

        ma.device_start(device);

        Console.ReadKey();
        
        ma.device_uninit(device);
        NativeMemory.Free(device);

        ma.decoder_uninit(decoder);
        NativeMemory.Free(decoder);
    }

    [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]
    internal static unsafe void DataCallback(ma_device* device, void* output, void* input, uint frameCount)
    {
        if (decoder == null)
        {
            return;
        }

        ulong framesRead = 0;
        ma_result result = ma.decoder_read_pcm_frames(decoder, output, frameCount, &framesRead);
        if (result != ma_result.MA_SUCCESS || framesRead == 0)
        {
            // Close the device
            ma.device_stop(device);
        }
    }
}

Generate Bindings (Miniaudio.cs)

dotnet tool install --global ClangSharpPInvokeGenerator
git clone https://github.com/Estrol/Miniaudio-CS --recursive
cd Miniaudio-CS/GenerateBindings
ClangSharpPInvokeGenerator @generate.gen

Build Native Library

actions

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 182 1/1/2026
1.0.61 146 1/1/2026
1.0.6 151 12/31/2025
1.0.5 244 12/7/2025