Skip to content

Short Clips

Axwabo edited this page Feb 6, 2026 · 6 revisions

Short Clips

Important

Do not use short clips for long files. stream them instead.

When you want to play short sounds (e.g. sound effects), it's best to use short clips instead of streaming them. Reading and seeking is faster when audio files are in memory.

The ShortClipCache class stores these clips after loading them. Lookups are case-insensitive (will match regardless of case).

Extension methods help to play the clips back.

The ClipName struct can be implicitly be converted from a string, so you can pass a string to methods that have this parameter.

  • UseShortClip replaces the AudioPlayer's SampleProvider with the clip
  • MixShortClip adds a clip to the player's Mixer
  • EnqueueShortClip plays the clip after the previous input (queues it)
Example

Register clips when your plugin loads.

If you have to dynamically load clips on a specific event, there might be some lag due to reading files to the end.

using SecretLabNAudio.Core.FileReading;

// the file name without the extension will be the clip's name
ShortClipCache.AddFromFile("/path/to/clip.wav");
ShortClipCache.AddFromFile("/path/to/clip2.wav");

// custom clip name
ShortClipCache.AddFromFile("/path/to/clip3.wav", "CustomName");

// keep the file extension
ShortClipCache.AddFromFile(("/path/to/clip4.wav", false));
// same as above
ShortClipCache.AddFromFile(new ClipName("/path/to/clip4.wav", false));

Play the clips one by one:

using SecretLabNAudio.Core;
using SecretLabNAudio.Core.Extensions;
using SecretLabNAudio.Core.Pools;

AudioPlayerPool.Rent(SpeakerSettings.GloballyAudible)
    .UseShortClip("clip", 0.8f) // 80% volume
    .EnqueueShortClip("clip2") // plays after clip.wav
    .EnqueueShortClip("customName") // plays after clip2.wav
    .EnqueueShortClip(("clip4.wav", false)) // plays after clip3.wav
    .PoolOnEnd();

Loading Short Clips

Use the methods in the ShortClipCache class to add clips from files. Clips will automatically be mixed down and resampled, no need to convert them to 48000 Hz mono Ogg Vorbis files.

  • AddAllFromDirectory adds all clips from a specific directory
  • AddAllFromPaths adds clips of the given paths, with an optional base directory
  • AddFromFile loads a single clip

Most methods have a ClipName overload - you can pass a string to them directly. If you don't want to trim the extensions when adding the file, pass trimExtension: false or create a ClipName struct with the matching property.

Pass a maxDuration parameter to prevent adding clips longer than a threshold.

Getting Started

Playing Audio

Advanced

Audio Processors

v1 Guides

Caution

v1 will be out of support soon.

Clone this wiki locally