TuningFork.Sink.Buffer (TuningFork v0.1.11)

Copy Markdown View Source

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))

Summary

Functions

Returns a specification to start this module under a supervisor.

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

How long the recording runs, in seconds.

Open the sink onto a running buffer.

Start a buffer, linked to the caller.

Stop the buffer, discarding the recording.

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

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

Append pcm to the buffer. Does not sleep.

Functions

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clear(buffer)

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

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

duration(buffer)

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

How long the recording runs, in seconds.

open(opts)

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(opts \\ [])

@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(buffer)

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

Stop the buffer, discarding the recording.

take(buffer)

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

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

wav(buffer)

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

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

write(buffer, pcm)

Append pcm to the buffer. Does not sleep.