`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`.
See [[Project Setup and Troubleshooting]] for details on adding `vaudio.dll` to your C# project and resolving any errors that may occur.
> 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, and then create an instance of a [[RaytracingContext]]. More details are in [[Creating a Raytracing Context]].
<div data-tabs="a" markdown="1"><div data-tab="C#" markdown="1">
```cs
using vaudio;
public class Game
{
RaytracingContext context;
public Game()
{
var settings = new RaytracingContextSettings()
{
worldPosition = new Vector3F(0, 0, 0),
worldSize = new Vector3F(50, 50, 50),
renderingEnabled = true,
reverbRayCount = 1000,
occlusionRayCount = 500,
permeationRayCount = 300,
trailBounceCount = 8,
maxVoices = 16,
...
};
context = new RaytracingContext(settings);
}
}
```
</div><div data-tab="C" markdown="1">
```c
int main(void)
{
// Customise settings
RaytracingContextSettings* settings = raytracing_context_settings_create();
settings->world_position = vector3f_create(0, 0, 0);
settings->world_size = vector3f_create(50, 50, 50);
settings->reverb_ray_count = 1000;
settings->occlusion_ray_count = 500;
settings->permeation_ray_count = 300;
settings->trail_bounce_count = 8;
settings->max_voices = 16;
// Validate settings
ValidationResult result = validate_raytracing_context_settings(settings);
if (!result.is_valid)
{
printf(result.error_message);
return 1;
}
// Create the raytracing context
RaytracingContext* context = raytracing_context_create(settings);
// Free settings
raytracing_context_settings_free(settings);
settings = NULL;
}
```
</div></div>
Step 2 - create a copy of your game's world using low-poly primitives. Read more: [[Primitives]].
<div data-tabs="b" markdown="1"><div data-tab="C#" markdown="1">
```cs
// Create a rectangular prism
var prism = new PrismPrimitive()
{
// Set its material
material = MaterialType.Metal,
// Scale it
size = new Vector3F(15),
// Rotate and position it
transform = Matrix4F.CreateRotationX(MathF.PI / 4) *
Matrix4F.CreateTranslation(32, 32, 32)
};
context.AddPrimitive(prism);
```
</div><div data-tab="C" markdown="1">
```c
// Create a rectangular prism
PrismPrimitive* prism = prism_primitive_create();
primitive_set_material((Primitive*)prism, MATERIAL_METAL);
prism_primitive_set_size(prism, vector3f_create(15, 15, 15));
Matrix4F rotation = matrix4f_create_rotation_x(PI / 4.0f);
Matrix4F translate = matrix4f_create_translation(32, 32, 32);
Matrix4F transform = matrix4f_multiply(rotation, translate);
prism_primitive_set_transform(prism, transform);
raytracing_context_add_primitive(context, (Primitive*)prism);
```
</div></div>
Step 3 - create a [[Voice]], and provide a callback that will be invoked when the voice is raytraced. Read more: [[Voices]].
<div data-tabs="c" markdown="1"><div data-tab="C#" markdown="1">
```cs
var voice = context.CreateVoice(new StaticPositionF(8, 8, 8));
voice.OnRaytracingComplete = () =>
{
// Check low-pass filter gains
var gainLF = (int)(voice.filter.gainLF * 100);
var gainHF = (int)(voice.filter.gainHF * 100);
Console.WriteLine(
quot;The voice has {gainLF}% LF gain");
Console.WriteLine(quot;The voice has {gainHF}% HF gain");
// PSEUDOCODE - play a sound
Godot.PlaySound(SoundType.Explosion, new Vector3F(8, 8, 8), filter);
};
```
</div><div data-tab="C" markdown="1">
```c
// Callback function
void on_raytracing_complete_callback(Voice* voice)
{
// Check low-pass filter gains
int gainLF = (int)(voice->filter->gainLF * 100);
int gainHF = (int)(voice->filter->gainHF * 100);
printf("The voice has %d%% LF gain\n", gainLF);
printf("The voice has %d%% HF gain\n", gainHF);
// PSEUDOCODE - play a sound
unreal_play_sound(...);
}
// Create a voice
Voice* voice = raytracing_context_create_voice(context, 0, vector3f_create(8, 8, 8));
voice->on_raytracing_complete = on_raytracing_complete_callback;
```
</div></div>
Step 4 - update the context every frame. This will perform raytracing and handle input for the debug rendering window. Read more: [[Raytracing Lifecycle]].
<div data-tabs="d" markdown="1"><div data-tab="C#" markdown="1">
```cs
public void Update()
{
// Update the listener's position
context.UpdateListener(new Vector3F(20, 20, 20));
// Perform raytracing on background threads
context.Update();
}
```
</div><div data-tab="C" markdown="1">
```c
void Update()
{
// Update the listener's position
raytracing_context_set_listener_position(context, vector3f_create(20, 20, 20));
// Perform raytracing on background threads
raytracing_context_update(context);
}
```
</div></div>
Step 5 - access reverb properties. Read more: [[Reverb]].
<div data-tabs="e" markdown="1"><div data-tab="C#" markdown="1">
```cs
// Must wait until raytracing has completed at least once
if (context.ReverbCalculated)
{
// Access reverb properties
var outside = context.ProcessedReverb.OutsidePercent;
Console.WriteLine(quot;The listener is {(int)(outside * 100)}% outside.");
// Access pre-calculated EAX properties
var diffusion = context.ListenerEAX.Diffusion;
}
```
</div><div data-tab="C" markdown="1">
```c
// Must wait until raytracing has completed at least once
if (raytracing_context_is_reverb_calculated(context))
{
// Access reverb properties
ProcessedReverbResults* processed = raytracing_context_get_processed_reverb(context);
var outside = processed->outside_percent;
printf("Outside percent: %d\n", outside);
// Access pre-calculated EAX properties
EAXReverbResults* listenerEAX = raytracing_context_get_listener_eax(context);
printf("EAX diffusion: %d\n", listenerEAX->diffusion);
}
```
</div></div>
Continue reading:
- [[Full Code Example]]
- [[Creating a Raytracing Context]]
- [[Updating Raytracing Settings]]
- [[Voices]]
- [[Primitives]]
- [[Reverb]]
- [[Materials]]
Advanced:
- [[Raytracing Lifecycle]]
- [[Trail-Based Raytracing]]
- [[Threading Architecture]]
- [[Per-Voice Reverb]]