-
Notifications
You must be signed in to change notification settings - Fork 0
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.
-
UseShortClipreplaces theAudioPlayer'sSampleProviderwith the clip -
MixShortClipadds a clip to the player's Mixer -
EnqueueShortClipplays 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();Tip
See also: supported file formats
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.
-
AddAllFromDirectoryadds all clips from a specific directory -
AddAllFromPathsadds clips of the given paths, with an optional base directory -
AddFromFileloads 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.
- π Home
- πΌ Digital Audio Basics
- π Examples
- π¦ Supported Formats
- β¬οΈ Migrating from v1
- π AudioPlayer
- πΎ Short Clips
- πΏ Streaming From Disk
- ποΈ Speaker Groups
- π Sample Providers
- β»οΈ Pooling
- π© SendEngines
- π§ Personalizing Speakers
- π Monitoring Output
- βοΈ AudioQueue
- πΆ Mixer
- ποΈ ProcessorChain
Caution
v1 will be out of support soon.