TuningFork.Sink.Speaker (TuningForkSpeaker v0.1.11)

Copy Markdown View Source

A TuningFork.Sink that plays through the machine's audio device.

{:ok, stage} = TuningFork.Stage.start_link(sink: TuningFork.Sink.Speaker, chunk: 256)

Summary

Functions

Whether this machine can play sound.

Open the device. Returns {:ok, state} or {:error, :unavailable} when this machine has no audio device.

Frames currently queued for playback.

Queue PCM for playback. Blocks until no more than :lead frames are queued before adding more, then writes all of pcm. Returns :ok or {:error, reason}.

Functions

available?()

@spec available?() :: boolean()

Whether this machine can play sound.

open(opts)

Open the device. Returns {:ok, state} or {:error, :unavailable} when this machine has no audio device.

Options:

  • :rate — samples per second, default 44100
  • :channels — default 2; TuningFork.Stage passes its own
  • :lead — frames kept queued ahead of playback, default 512
  • :buffer — ring size in frames, default 4096; must be larger than :lead

queued(map)

@spec queued(map()) :: non_neg_integer()

Frames currently queued for playback.

write(state, pcm)

Queue PCM for playback. Blocks until no more than :lead frames are queued before adding more, then writes all of pcm. Returns :ok or {:error, reason}.