TuningFork.Pattern.Ahead (TuningFork v0.1.11)

Copy Markdown View Source

A TuningFork.Pattern.Player rendered ahead of time in a process of its own, so the stage takes its chunks ready-made and the pattern's synthesis runs on another core.

{:ok, ahead} = TuningFork.Pattern.Ahead.start_link(player: player, chunk: 256, channels: 2)
pcm = TuningFork.Pattern.Ahead.next(ahead)
TuningFork.Pattern.Ahead.apply(ahead, &TuningFork.Pattern.Player.gain(&1, 0.5))

Up to :depth chunks are kept rendered (default 8); next/1 returns the oldest and renders one on the spot when none is ready. A change made with apply/2 reaches the player at the render frontier, at most :depth chunks ahead of what next/1 has handed out.

Summary

Functions

Change the player with fun from the render frontier on.

Returns a specification to start this module under a supervisor.

Where the player has reached at the render frontier, in cycles.

The next chunk.

How many chunks are rendered and waiting.

Start rendering :player in chunks of :chunk frames for :channels channels, :depth chunks ahead.

Stop rendering.

Functions

apply(ahead, fun)

Change the player with fun from the render frontier on.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

cycle(ahead)

@spec cycle(GenServer.server()) :: float()

Where the player has reached at the render frontier, in cycles.

next(ahead)

@spec next(GenServer.server()) :: binary()

The next chunk.

rendered(ahead)

@spec rendered(GenServer.server()) :: non_neg_integer()

How many chunks are rendered and waiting.

start_link(opts)

@spec start_link(keyword()) :: GenServer.on_start()

Start rendering :player in chunks of :chunk frames for :channels channels, :depth chunks ahead.

stop(ahead)

@spec stop(GenServer.server()) :: :ok

Stop rendering.