AudioMixer
The central mixing engine. Combines multiple audio sources, applies master effects, and drives audio output. Namespace: OwnaudioNET.Mixing
Constructor
C#
// bufferSizeInFrames: use 1024 for complex multi-track setups
var mixer = new AudioMixer(OwnaudioNet.Engine!.UnderlyingEngine, bufferSizeInFrames: 512);| Parameter | Type | Default | Description |
|---|---|---|---|
engine | IAudioEngine | â | From OwnaudioNet.Engine.UnderlyingEngine. |
bufferSizeInFrames | int | 512 | Internal mix buffer. Use 1024 for 20+ tracks. |
Properties
| Property | Type | Description |
|---|---|---|
MixerId | Guid | Unique identifier. |
Config | AudioConfig | Audio configuration in use. |
IsRunning | bool | Whether the mix thread is active. |
SourceCount | int | Number of active sources. |
MasterVolume | float | Master output volume (0.0 â 1.0). Settable at any time. |
LeftPeak / RightPeak | float | Real-time peak levels (0.0 â 1.0) for VU metering. |
TotalMixedFrames | long | Total frames processed since last Start(). |
TotalUnderruns | long | Total buffer underruns since last Start(). |
IsRecording | bool | Whether WAV recording is active. |
MasterClock | MasterClock | Timeline clock for synchronized multi-track sync. |
RenderingMode | ClockMode | Realtime (default) or Offline. |
Lifecycle
C#
mixer.Start(); // begin audio processing
mixer.Pause(); // freeze mix thread
mixer.Stop(); // stop and clear all sources
mixer.Seek(double positionInSec); // seek master clock + all attached sources
mixer.Dispose(); // release all resourcesSource Management
C#
// Add and immediately start
mixer.AddSource(source);
// Add without starting â launch all at once for tight sync
mixer.AddSourcePrepared(vocals);
mixer.AddSourcePrepared(backing);
mixer.StartPreparedSources(startPosition: 0.0); // atomic start
// Remove
mixer.RemoveSource(source); // by reference
mixer.RemoveSource(sourceGuid); // by ID
mixer.ClearSources(); // remove + stop all
// Query
IAudioSource[] all = mixer.GetSources();AddSource() and RemoveSource() are lock-free hot-swap operations â safe to call while the mixer is running.
Maximum simultaneous sources per mixer: AudioConstants.MaxAudioSources = 25
Master Effects
Effects applied to the final mixed signal in the order they are added. See Effects for the full effect list.
C#
// Add effects in chain order
mixer.AddMasterEffect(new CompressorEffect { Ratio = 4f });
mixer.AddMasterEffect(new ReverbEffect { RoomSize = 0.5f, Mix = 0.2f });
mixer.AddMasterEffect(new LimiterEffect());
// Manage
mixer.RemoveMasterEffect(effect); // returns bool
mixer.ClearMasterEffects();
IEffectProcessor[] fx = mixer.GetMasterEffects();The effect must have IsReady == true before adding. For VST3 effects, call await host.InitializeAudioAsync() first.
Recording
Records the final mixed output â post master-effects â to a WAV file.
C#
mixer.StartRecording("session.wav"); // start capturing
// ... playback ...
mixer.StopRecording(); // finalize and close the WAV fileVU Metering
C#
// Update at ~10Hz (100ms timer)
_vuTimer = new Timer(_ =>
{
// Master bus
float leftDb = 20f * MathF.Log10(Math.Max(mixer.LeftPeak, 1e-6f));
float rightDb = 20f * MathF.Log10(Math.Max(mixer.RightPeak, 1e-6f));
MasterLeftDb = Math.Max(leftDb, -60f);
MasterRightDb = Math.Max(rightDb, -60f);
// Per-track (if source is BaseAudioSource)
var (l, r) = source.OutputLevels;
TrackLeftDb = 20f * MathF.Log10(Math.Max(l, 1e-6f));
}, null, 0, 100);Events
| Event | Args | Description |
|---|---|---|
PlaybackEnded | EventArgs | All sources reached EndOfStream. |
BufferUnderrun | BufferUnderrunEventArgs | Mix thread couldn't fill buffer in time. |
SourceError | AudioErrorEventArgs | An error occurred in one of the sources. |
TrackDropout | TrackDropoutEventArgs | A source missed its master clock deadline. |
C#
mixer.PlaybackEnded += (_, _) =>
{
// All tracks finished â update UI state
};
mixer.BufferUnderrun += (_, e) =>
{
Console.WriteLine($"Underrun: {e.MissedFrames} frames at position {e.Position}");
};
mixer.TrackDropout += (_, e) =>
{
Console.WriteLine($"Dropout on {e.TrackName}: {e.Reason} ({e.MissedFrames} frames)");
};