---
title: "Start audio at a specific position in C#"
url: https://recursiveai.org/oneaudio/cookbook/start-audio-clip-at-offset/
description: "Start audio playback from a position in C# with OneAudio. Set the starting frame of a clip and see what happens at the end of a loop or one-shot."
version: "1.8.0"
---

# Start audio at a specific position in C#

**oneaudio** is a free, open-source audio library for .NET from Recursive AI. MIT or Apache-2.0, no bundled native binaries.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneAudio) · [GitHub](https://github.com/recursive-ai-oss/oneaudio-csharp) · [Docs](https://recursiveai.org/oneaudio/docs/) · [Download example (.zip)](https://recursiveai.org/oneaudio/cookbook/start-audio-clip-at-offset/start-audio-clip-at-offset.zip)

Set `StartOffsetFrame` to skip the start of an in-memory audio clip. Multiply seconds by the clip’s sample rate: 0.5 s at 48 kHz is frame 24,000.

```shell
dotnet add package RecursiveAI.OneAudio
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using OneAudio;

var format = new AudioFormat(48000, 1);
var mixer = new AudioMixer(new()
{
    SampleRate = 48000, Channels = 1
});
var clip = new AudioClip(format,
    [0.125f, 0.25f, 0.5f, 0.75f]);
var voice = mixer.Play(new(clip)
{
    StartOffsetFrame = 2
});
if (!voice.IsValid)
    throw new InvalidOperationException(
        "No voice.");
var output = new float[4];
mixer.Render(output);
foreach (float sample in output)
{
    string text = FormattableString
        .Invariant($"{sample:F2}");
    Console.WriteLine(text);
}
```

A negative offset throws `ArgumentOutOfRangeException`. A streaming source accepts offset `0`, but `Play` throws `ArgumentException` for a positive offset on that source.

Unzip [the example](https://recursiveai.org/oneaudio/cookbook/start-audio-clip-at-offset/start-audio-clip-at-offset.zip), then `dotnet run`.

The clip contains four generated mono frames. The mixer starts at frame 2, plays the last two frames, and fills the rest of the output block with silence. No file or audio device is needed.

```text
0.50
0.75
0.00
0.00
```

## Variations

**Start exactly at the loop end.** Replace `StartOffsetFrame = 2` inside the `Play` initializer with these settings. The loop covers frames 1 and 2; it doesn’t include frame 3.

```csharp
Loop = true,
LoopStartFrame = 1,
LoopEndFrame = 3,
StartOffsetFrame = 3
```

```text
0.25
0.50
0.25
0.50
```

**Start one frame later on the mixer clock.** Add `StartAtFrame` in the same initializer. On this fresh mixer, the first output frame is silent; the clip still starts at frame 2.

```csharp
StartOffsetFrame = 2,
StartAtFrame = 1
```

```text
0.00
0.50
0.75
0.00
```

## Related recipes

- [Mix audio in C#](https://recursiveai.org/oneaudio/cookbook/mix-audio/)
- [Start a sound partway through in OneGame](https://recursiveai.org/onegame/cookbook/start-sound-at-offset/)

## The short answer

Set `PlayParams.StartOffsetFrame` when you call `AudioMixer.Play` with an `AudioClip`. This is a zero-based position in the source clip, so `2` begins on the third frame. It sets the position for the new voice without cutting samples out of the clip. You can play the same clip from different positions on separate calls.

## How do you start audio at a specific time in C#?

Multiply the starting time in seconds by the **clip’s** sample rate, then choose a whole frame. At 48,000 Hz, a start time of half a second is frame 24,000. A frame contains one sample per channel at that position, so the offset is 24,000 for a stereo clip too, not 48,000. Use the source rate even if the mixer runs at a different rate or you set `Pitch` to change playback speed.

Inside the `Play` initializer, for an offset of half the clip’s sample rate in frames:

```csharp
StartOffsetFrame = format.SampleRate / 2
```

With the four-frame clip above, that skips the whole clip and prints four zeros. With a clip longer than half a second, it starts at the half-second point (rounded down to a whole frame). To delay *when* the sound starts instead, set `StartAtFrame`, which uses the mixer’s output clock. You can set both to schedule a cue that starts partway through the source.

## What happens if the start position is at the end of the audio?

A one-shot at or beyond the clip’s frame count plays nothing. A loop with a nonempty body wraps at **or past** its exclusive end. For the recipe’s loop `[1, 3)`, offset 3 wraps to frame 1 and offset 4 wraps to frame 2. An offset before the loop start plays the intro before repeating the loop body; it isn’t moved forward to the loop start.

For streaming audio, leave `StartOffsetFrame` at `0`. If the decoder supports seeking, [seek it before creating the streaming source](https://recursiveai.org/oneaudio/cookbook/seek-to-sample-in-mp3/). The mixer’s clip offset isn’t a general seek control for a stream or for a voice that’s already playing. See the [OneAudio API reference](https://recursiveai.org/oneaudio/docs/api/) for the clip and streaming source APIs.
