> For the complete documentation index, see [llms.txt](https://axongenesis.gitbook.io/timeflow/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://axongenesis.gitbook.io/timeflow/reference/behaviors/audio/audio-sample.md).

# Audio Sample

Sample a region of audio frequencies to drive motion

Use this behavior to generate audio amplitude from a range of frequencies to drive audio-reactive behaviors. This requires an [Audio Spectrum](/timeflow/reference/behaviors/audio/audio-spectrum.md) to provide the spectrum data for calculation.&#x20;

{% hint style="info" %}
Add multiple instances of Audio Sample to separate low, mid, and high frequencies.
{% endhint %}

{% hint style="success" %}
To add a new Audio Sample instance to the selected game object, select:

#### Tools > Timeflow > Add > Audio Sample

If no object is selected, a new one is created.
{% endhint %}

<figure><img src="https://2067910529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC3dOuetlQfYgK5FPUKgn%2Fuploads%2FsNGsqwHjanCzSjsaPY06%2Fimage.png?alt=media&amp;token=bdb5de99-7a8d-48d5-881f-53f7c561d65f" alt=""><figcaption><p>Each instance of Audio Sample has an Amplitude channel outputting the final calculation.</p></figcaption></figure>

{% hint style="info" %}
Use [Channel Link](/timeflow/user-guide/timeflow-view/channel-link.md) to link behaviors to Amplitude to drive audio-reactive effects.
{% endhint %}

## Audio Sample Editor

Select the object to view its settings in the Inspector.

<figure><img src="https://2067910529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC3dOuetlQfYgK5FPUKgn%2Fuploads%2FmGs1qVWOg2rWwtby7dul%2Fimage.png?alt=media&amp;token=c6c4b9d5-2fae-44e7-8582-4d570a2fd6b0" alt=""><figcaption></figcaption></figure>

For common features, please see [Menu Bar](/timeflow/user-guide/timeflow-editor/menu-bar.md) and [Update Settings](/timeflow/user-guide/timeflow-editor/update-settings.md).

## Spectrum

Assign the [Audio Spectrum](/timeflow/reference/behaviors/audio/audio-spectrum.md) to provide spectrum data for this sample.

### Mode

* **Average:** calculates the average amplitude value over the frequency range.
* **Maximum:** returns the maximum value over the frequency range.

{% hint style="info" %}
Average is usually preferred since it results in a more stable calculation over time, whereas Maximum will jump any time there is a spike in the
{% endhint %}

### Register

If this button appears, click it to register this Audio Sample to receive data from the Audio Spectrum. This might occur if the Audio Spectrum reference has been changed.&#x20;

## Frequency Range

Set the range of frequencies to sample, from about 20Hz to 20000Hz.&#x20;

{% hint style="info" %}
Frequencies are distributed logarithmically from low to high. For lower frequencies, a smaller range is usually best, while higher ranges may span larger values.&#x20;
{% endhint %}

{% hint style="success" %}

#### Example Ranges

Each audio track will vary, however as a general guide for frequencies:

* **Sub Bass:** 0 - 30Hz
* **Kick Drum:** 80 - 120Hz
* **Mid Range:** 800 - 1200Hz
* **High Range:** 1500 - 3000Hz
  {% endhint %}

{% hint style="success" %}
To help identify active frequency ranges in the audio, use the [graph display](/timeflow/reference/behaviors/audio/audio-spectrum.md#graph-in-camera-view) in Audio Spectrum and adjust the range to preview.
{% endhint %}

### Threshold

Sets the minimum amplitude or lower threshold (RMS) for detecting changes in amplitude. Everything below this level is ignored.

{% hint style="success" %}
Use Threshold similar to a gate filter, only reacting to spikes in the audio above the minimum audio range. This is helpful to filter out low level noise and isolate specific instruments.
{% endhint %}

## Decay Rate

Sets time in seconds for amplitude to decrease, effectively applying temporal smoothing. Set to 0 to disable.

{% hint style="success" %}
Use this to sustain audio-reactive hits a bit longer after the initial impulse of an increase in amplitude. Since spectrum data can by very dynamic and change dramatically from one frame to the next, this helps stabilize amplitude values over time.
{% endhint %}

### Multiply

Scales the final amplitude.

{% hint style="success" %}
Use Multiply to overall increase or decrease the intensity of the amplitude calculated.&#x20;
{% endhint %}

## Apply to Scale

Scales the current object by the final amplitude. This is primarily a preview function however may be used in production as well.&#x20;

{% hint style="info" %}
To map Audio Sample to additional properties, use [Audio Reactive](/timeflow/reference/behaviors/audio/audio-reactive.md) or [Channel Link](/timeflow/user-guide/timeflow-view/channel-link.md) to route the Amplitude value where desired.&#x20;
{% endhint %}

## Set Shader Property

If enabled, the named global property is set with the current amplitude on each update affecting all shaders with the named property.&#x20;

<figure><img src="https://2067910529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC3dOuetlQfYgK5FPUKgn%2Fuploads%2FNYTSKV5FUC4CWNzNLq05%2Fimage.png?alt=media&amp;token=c6c85a6e-bd1d-4b8d-a87a-f03279a95df7" alt=""><figcaption></figcaption></figure>

{% hint style="success" %}
This is an efficient way to animate properties across all materials using specific shaders.&#x20;
{% endhint %}

{% hint style="info" %}
To target a global property defined in Shader Graph, make sure the variable name matches exactly and is not exposed in the editor. &#x20;
{% endhint %}

## Use Baked Data

Audio sampling data may be "baked" meaning that its values are recorded and stored for subsequent replays without reprocessing audio. This may be advantageous for performance and to overcome any limitations with real-time audio processing and target devices.&#x20;

<figure><img src="https://2067910529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC3dOuetlQfYgK5FPUKgn%2Fuploads%2FitvuMjn1yWIJeiaKM69w%2Fimage.png?alt=media&amp;token=581c6662-8339-4e73-9657-015d787e09a3" alt=""><figcaption></figcaption></figure>

### Start Baking

Click to enable recording of data for the Audio Sample. The UI displays in red while capturing.

<figure><img src="https://2067910529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC3dOuetlQfYgK5FPUKgn%2Fuploads%2F1SyUCZL4AJO0VYF8rGlv%2Fimage.png?alt=media&amp;token=9371742c-1fb7-4cc4-9d14-f7289e889922" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
Data is only recorded when Timeflow is played in edit mode.
{% endhint %}

{% hint style="success" %}
To record data, rewind Timeflow and play it from the beginning (while still in edit mode). Data is only recorded on the frames played. Any areas of the timeline not capture are left empty and have no effect during playback.&#x20;
{% endhint %}

{% hint style="success" %}
Click Stop Baking when done recording. The baked data is now used in place of audio sampling as long as Use Baked Data is enabled.
{% endhint %}

### Start / Stop All

Use these buttons to enable / disable recording on all instances of Audio Sample in the scene.&#x20;

{% hint style="info" %}
The bulk operation to start, stop, turn off, and clear all are useful when preparing scenes for rendering and then removing all the baked data when finished.&#x20;
{% endhint %}

### Turn Off All

Disables Use Baked Data for all Audio Sample instances in the scene.

### Clear All

Clears all baked data and turns off Used Baked Data for all Audio Sample instances.

{% hint style="danger" %}

#### Baking Required for Rendering!

When using Render to Disk to render frame-by-frame output, audio sampling must be pre-baked since audio cannot play regularly while rendering. Failing to bake data on Audio Sample instances results in audio-reactive behaviors not reacting.
{% endhint %}
