---
title: Timeline mixing
order: 4
summary: Arrange sounds on a beat grid, on tracks, with pumping and ducking.
---

<!-- Generated by tools/generate-docs.bxs from the BIF classes. Do not edit; change the Javadoc and run it again. -->

Arrange sounds on a beat grid, on tracks, with pumping and ducking.

## audioTimeline

Create a multi track timeline for mixing sounds

```js
audioTimeline( bpm=120, beatsPerBar=4, sampleRate=44100, channels=2 )
```

| Argument | Type | Default | |
|---|---|---|---|
| `bpm` | double | `120` | The tempo in beats per minute. Defaults to 120. |
| `beatsPerBar` | integer | `4` | Beats in one bar. Defaults to 4. |
| `sampleRate` | integer | `44100` | The sample rate of the mix in Hz. Defaults to 44100. |
| `channels` | integer | `2` | 1 for mono or 2 for stereo. Defaults to 2. |

**Returns** The timeline. Use timeline.beat( n ) and timeline.bar( n ) to turn beats and bars into seconds.

## audioAdd

Place a sound on a timeline track

```js
audioAdd( timeline, sound, at=0, track="main", gainDb=0, pan=0 )
```

| Argument | Type | Default | |
|---|---|---|---|
| `timeline` | any | required | The timeline from audioTimeline(). |
| `sound` | any | required | The audio buffer to place. A different sample rate is converted automatically, mono is panned in a stereo timeline. |
| `at` | double | `0` | Where the sound starts, in seconds. Use timeline.beat( n ) or timeline.bar( n ) to place it on the grid. Defaults to 0. |
| `track` | string | `"main"` | The track name, created on first use. Defaults to main. |
| `gainDb` | double | `0` | Gain in decibels. Defaults to 0. |
| `pan` | double | `0` | From -1 (left) to 1 (right). Defaults to 0. |

**Returns** The same timeline, so calls can be chained.

## audioBeats

List moments on the beat grid of a timeline, in seconds

```js
audioBeats( timeline, start=0, end, step=1 )
```

| Argument | Type | Default | |
|---|---|---|---|
| `timeline` | any | required | The timeline from audioTimeline(). |
| `start` | double | `0` | The first beat. Defaults to 0. |
| `end` | double | required | Where to stop, in beats. The end itself is not included. |
| `step` | double | `1` | Beats between moments, for example 0.5 for eighth notes in 4/4. Defaults to 1. |

**Returns** An array of times in seconds, ready for audioAdd( at= ) or audioPump( times= ).

## audioTrackGain

Set the volume of a whole timeline track

```js
audioTrackGain( timeline, track, gainDb )
```

| Argument | Type | Default | |
|---|---|---|---|
| `timeline` | any | required | The timeline from audioTimeline(). |
| `track` | string | required | The track name, created if it does not exist yet. |
| `gainDb` | double | required | The track gain in decibels, applied when the timeline is rendered. |

**Returns** The same timeline, so calls can be chained.

## audioPump

Duck a timeline track at given moments, like a kick drum sidechain

```js
audioPump( timeline, track, times, amountDb=-5, recovery=0.18 )
```

| Argument | Type | Default | |
|---|---|---|---|
| `timeline` | any | required | The timeline from audioTimeline(). |
| `track` | string | required | The track to duck. |
| `times` | array | required | An array of start times in seconds, for example from audioBeats(). |
| `amountDb` | double | `-5` | How far the gain drops at each time, a negative number of decibels. Defaults to -5. |
| `recovery` | double | `0.18` | Seconds the gain takes to return to normal. Defaults to 0.18. |

**Returns** The same timeline, so calls can be chained.

## audioDuck

Duck a timeline track while another track is loud, like music under a voice-over

```js
audioDuck( timeline, track, trigger, amountDb=-12, thresholdDb=-40, attackMs=10, releaseMs=300 )
```

| Argument | Type | Default | |
|---|---|---|---|
| `timeline` | any | required | The timeline from audioTimeline(). |
| `track` | string | required | The track to lower, for example the music. |
| `trigger` | string | required | The track whose level controls the ducking, for example the voice. It must already have sound on it. |
| `amountDb` | double | `-12` | How far to lower the track, a negative number of decibels. Defaults to -12. |
| `thresholdDb` | double | `-40` | The trigger level above which ducking starts, relative to full scale. Defaults to -40. |
| `attackMs` | double | `10` | Milliseconds taken to lower the track. Defaults to 10. |
| `releaseMs` | double | `300` | Milliseconds taken to bring the track back. Defaults to 300. |

**Returns** The same timeline, so calls can be chained.

## audioRender

Mix a timeline down to one audio buffer

```js
audioRender( timeline, tail=0 )
```

| Argument | Type | Default | |
|---|---|---|---|
| `timeline` | any | required | The timeline from audioTimeline(). |
| `tail` | double | `0` | Seconds of silence to leave after the last sound, for example for a fade out. Defaults to 0. |

**Returns** The mixed audio buffer. The timeline is left as it was, so it can be changed and rendered again.

