# `TuningFork.Sink.Buffer`
[🔗](https://github.com/jaman/tuning_fork/blob/v0.1.11/tuning_fork/lib/tuning_fork/sink/buffer.ex#L1)

A sink that keeps everything written in a caller-owned process, for recording a stage.

    {:ok, tape} = TuningFork.Sink.Buffer.start_link()
    {:ok, _stage} = TuningFork.Stage.start_link(sink: TuningFork.Sink.Buffer,
                                                sink_opts: [into: tape])
    TuningFork.Sink.Buffer.wav(tape) |> then(&File.write!("take.wav", &1))

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `clear`

```elixir
@spec clear(Agent.agent()) :: :ok
```

Throw away what has been recorded. The buffer keeps running.

# `duration`

```elixir
@spec duration(Agent.agent()) :: float()
```

How long the recording runs, in seconds.

# `open`

Open the sink onto a running buffer.

## Options

  * `:into` — the buffer to write to. Required; returns `{:error, :no_buffer_given}`
    without it
  * `:rate` — samples per second, default 44100. Kept for `wav/1` and `duration/1`
  * `:channels` — samples per frame, default 2. Kept the same way

# `start_link`

```elixir
@spec start_link(keyword()) :: Agent.on_start()
```

Start a buffer, linked to the caller.

`opts` are `Agent.start_link/2`'s options, such as `:name`.

# `stop`

```elixir
@spec stop(Agent.agent()) :: :ok
```

Stop the buffer, discarding the recording.

# `take`

```elixir
@spec take(Agent.agent()) :: binary()
```

Everything written so far as one PCM binary, in the order it was written.

# `wav`

```elixir
@spec wav(Agent.agent()) :: binary()
```

Everything written so far as a WAV, at the rate and channels the stage opened with.

# `write`

Append `pcm` to the buffer. Does not sleep.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
