Getting Started

vaudio.dll is the main Raytraced Audio DLL. There are other .dll files in the SDK that are used to render the debug window. When shipping Vercidium Audio with your games in future, you will only need to include vaudio.dll.

Please note that this SDK does not handle audio playback. Instead it provides the low pass filter and reverb properties that must be applied to each sound, in your engine / audio API of choice

Quick Start

Step 1 - add vaudio.dll as a dependency to your C# project

Step 2 - create an instance of a RaytracingContext. Read more: Creating a Raytracing Context.

using vaudio;

public class Game
{
    RaytracingContext context;
    
    public Game()
    {
        context = new RaytracingContext()
        {
            WorldSize = new Vector3F(100),
            RenderingEnabled = true,
        };
    }
}

Step 2 - create a copy of your game's world using low-poly primitives. Read more: Primitives.

var prism = new PrismPrimitive()
{
    // Every primitive must have a material
    material = MaterialType.Metal,
    
    // Scale must be separate from transform
    size = new Vector3F(15),

    // Rotate and position it
    transform = Matrix4F.CreateRotationX(MathF.PI / 4) *
                Matrix4F.CreateTranslation(32, 32, 32)
};

context.AddPrimitive(prism);

Step 3 - create a listener emitter that casts occlusion rays towards a target emitter. Read more: Emitters.

var listener = new Emitter()
{
    Position = new Vector3F(4),
    ReverbRayCount = 128,
    ReverbBounceCount = 64,
    OcclusionRayCount = 256,
    OcclusionBounceCount = 8,
};

context.AddEmitter(listener);

var target = new Emitter()
{
    Position = new Vector3F(8),
    ReverbRayCount = 32,
    ReverbBounceCount = 64,
};

context.AddEmitter(target);

// Cast occlusion rays towards the emitter
listener.AddTarget(target);

// This callback is invoked when listener raytraces target
target.OnRaytracedByAnotherEmitter = (Emitter other) =>
{
    var filter = other.GetFilter(target);

    // Check low-pass filter gains
    var gainLF = (int)(filter.gainLF * 100);
    var gainHF = (int)(filter.gainHF * 100);
    
    Console.WriteLine($"The target has {gainLF}% LF gain");
    Console.WriteLine($"The target has {gainHF}% HF gain");

    // PSEUDOCODE - play a sound
    Godot.PlaySound(SoundType.Explosion,target.position, filter);
};

Step 4 - update the context every frame. This will perform raytracing and handle input for the debug rendering window.

public void Update()
{
    // Update the listener's position
    listener.Position = new Vector3F(20, 20, 20);
    
    // Perform raytracing on background threads and invoke callbacks
    context.Update();
}

Step 5 - access reverb properties. Read more: Reverb.

context.OnReverbUpdated = () =>
{
    // Access reverb properties
    var outside = context.ProcessedReverb.OutsidePercent;
    Console.WriteLine($"The listener is {(int)(outside * 100)}% outside.");    

    // Access precalculated EAX properties
    var diffusion = listener.EAX.DecayTime;
}

Step 6 - access ambient results. Read more: Ambience.

emitter.OnRaytracingComplete = () =>
{
    var ambientGainLF = context.AmbientFilter.GainLF;
    var ambientGainHF = context.AmbientFilter.GainHF;
}

Continue reading:

Advanced: