Start at 0.5 seconds into cue.wav from the zip, skipping its silent intro.
dotnet add package RecursiveAI.OneGame.AudioRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
using OneGame.Audio; using var audio = AudioService.Create( new AudioServiceOptions { Capture = true }); using var wav = File.OpenRead("cue.wav"); var cue = audio.LoadSound(wav, "cue"); audio.Play(cue, new PlayOptions { StartOffsetSeconds = 0.5 }); audio.Advance(audio.Format.SampleRate / 20); Console.WriteLine(audio.Capture!.Peak > 0);
TrueTrue means the first 50 milliseconds contain sound. Remove Capture = true and the Advance and WriteLine calls to play through your game’s audio output.
Unzip the example, then dotnet run.
The full program
The included cue.wav is a one-second mono WAV: silence from 0 to 0.25 s, a 440 Hz tone from 0.25 to 0.75 s, then silence to 1 s. The program mixes the first 50 milliseconds of each play request. Starting at zero leaves that entire capture silent; starting halfway lands on the tone.
using System.Globalization; using OneGame.Audio; CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; Measure("Clip start", new PlayOptions()); Measure("Half second", new PlayOptions { StartOffsetSeconds = 0.5 }); Measure("Halfway", new PlayOptions { StartOffsetFraction = 0.5 }); Measure("Past the end", new PlayOptions { StartOffsetSeconds = 1.5 }); Measure("Loop wraps", new PlayOptions { Loop = true, StartOffsetSeconds = 1.5 }); static void Measure(string label, PlayOptions options) { using var audio = AudioService.Create(new AudioServiceOptions { Capture = true }); using var file = File.OpenRead("cue.wav"); var cue = audio.LoadSound(file, "cue"); audio.Play(cue, options); audio.Advance(audio.Format.SampleRate / 20); var play = audio.GetPlayLog().Single(); Console.WriteLine($"{label}: seconds={play.StartOffsetSeconds}, fraction={play.StartOffsetFraction}, " + $"nonzero samples={audio.Capture!.Peak > 0}"); }
Clip start: seconds=0, fraction=0, nonzero samples=False Half second: seconds=0.5, fraction=0, nonzero samples=True Halfway: seconds=0, fraction=0.5, nonzero samples=True Past the end: seconds=1.5, fraction=0, nonzero samples=False Loop wraps: seconds=1.5, fraction=0, nonzero samples=True
If a one-shot is silent, check its duration: an offset at or past the end produces no sound. The logged values are the options used for the request, not the final wrapped playback position.
Variations
Start halfway through a clip of any length
Use the same audio and cue as above; use this play call instead of the seconds-based call:
audio.Play(cue, new PlayOptions { StartOffsetFraction = 0.5 });
Wrap the first play into a loop
The zip’s one-second cue starts at 0.5 seconds when you loop it with a 1.5-second offset:
audio.Play(cue, new PlayOptions { Loop = true, StartOffsetSeconds = 1.5 });
Related recipes
The short answer
Pass StartOffsetSeconds or StartOffsetFraction in PlayOptions when you call AudioService.Play. The number describes where to begin inside the clip, not how long to wait before the sound starts. Use seconds to hit a known cue point, or a fraction such as 0.5 to start halfway through whichever clip is loaded.
How do I start a sound at a specific second?
Measure the offset from the beginning of the original clip, before pitch changes. If the cue begins at half a second in the WAV, the same offset locates that cue even when the voice plays at a different pitch. If you set both fields, OneGame adds the seconds to the requested fraction of the clip’s duration and rounds to a source frame. Negative and non-finite inputs are treated as zero. A fade-in, if requested, starts from the offset rather than from the beginning of the file.
The scenario sound expectation accepts offset and offset-fraction filters, so a scenario can distinguish a cue that started at the beginning from one that requested the middle. Capture mode answers a separate question: whether the mixer actually produced samples that aren’t silent.
Can I start a loop in the middle and still loop the whole clip?
Yes. The offset applies to the first pass. Playback continues to the loop end, then returns to the loop start rather than to the offset. A one-second loop started 0.5 seconds in plays its last half-second first, then repeats from the beginning of that loop. An offset of 1.5 seconds wraps to the same point. With looping off, the same out-of-range offset ends the voice immediately.
This is useful when two looping beds should begin out of phase: load the clip once and vary the offset in each play request. It doesn’t edit the WAV or define new loop boundaries. If you’re working with the mixer directly and know the offset in source frames rather than in seconds or clip fractions, use OneAudio’s frame-offset API.