# GetSampleCountForCaptureFrame()

> Returns the number of sample frames available since the last time AudioRenderer.Render was called. This count depends on the frame capture rate.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/7000.0/script-reference/unityengine.md)
* **Assembly:** UnityEngine.AudioModule

```csharp
public static int GetSampleCountForCaptureFrame()
```

### Returns

| Type                                                       | Description                                                                                                  |
| ---------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | Number of sample frames available since the last recorded frame, or 0 if the engine isn't in recording mode. |

### Remarks

A sample frame holds one sample for each output channel. Multiply this count by the channel count of the current speaker mode to get the length of the buffer that [AudioRenderer.Render](/engine/7000.0/script-reference/unityengine/audiorenderer/render.md) fills.

The count follows [Time.captureDeltaTime](/engine/7000.0/script-reference/unityengine/time/capturedeltatime.md) when that property is non-zero, and [Time.deltaTime](/engine/7000.0/script-reference/unityengine/time/deltatime.md) otherwise.

Call [AudioRenderer.Render](/engine/7000.0/script-reference/unityengine/audiorenderer/render.md) on every frame, including the frames that report 0. Unity discards the audio for any frame you skip, and only [AudioRenderer.Render](/engine/7000.0/script-reference/unityengine/audiorenderer/render.md) carries the leftover samples forward to the next frame.

### Examples

```csharp
using Unity.Collections;
using UnityEngine;

public class SampleCountExample : MonoBehaviour
{
    void Update()
    {
        // Assumes AudioRenderer.Start has already been called.
        int sampleFrames = AudioRenderer.GetSampleCountForCaptureFrame();

        AudioConfiguration config = AudioSettings.GetConfiguration();
        AudioSpeakerMode speakerMode = config.speakerMode;
        int channels = speakerMode.ChannelCount();

        NativeArray<float> buffer = new NativeArray<float>(
            sampleFrames * channels, Allocator.Temp);

        // Render runs even when the count is zero, so that the next
        // frame reports the samples accumulated so far.
        AudioRenderer.Render(buffer);
        buffer.Dispose();
    }
}
```
