🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

Miniaudio-CS

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

Miniaudio-CS

Package Description

1.0.4
NuGet
Version published
Maintainers
1
Created
Source

Miniaudio-CS

Auto-generated C# bindings for miniaudio

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);
    }
}

Generate Bindings (Miniaudio.cs)

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

Build Native Library

actions

Keywords

audio

FAQs

Package last updated on 11 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts