NanoKVMGo.Microphone (nano_kvm_go v0.4.0)

Copy Markdown View Source

The microphone the target computer sees, with the :microphone function of the USB gadget (see NanoKVMGo.USB).

play/2 sends it PCM: interleaved samples in the microphone's format, the channels and sample size the gadget set it up with, at the rate the target chose. format/1 tells that format, and subscribers hear of it. The nano_kvm_go_playback port program keeps the microphone's stream running: between samples the target hears silence, and samples that come in faster than the target takes them are dropped once more than 200 ms wait, so the sound never lags. The program runs while there are subscribers, and from play/2 until :idle_ms without samples.

Messages

Subscribers receive {NanoKVMGo.Microphone, {:format, format}}, a NanoKVMGo.Audio.format/0, when the program starts, when subscribing to a running one, and when the target chooses another rate. Samples sent in the old format until then play at the wrong speed.

Options

  • :name - the name to register, NanoKVMGo.Microphone by default
  • :device - the ALSA playback device, "hw:CARD=UAC2Gadget,DEV=0" by default
  • :idle_ms - how long to keep the stream without samples and subscribers, 10 s by default
  • :program - the port program, the library's nano_kvm_go_playback by default

Summary

Types

A message to subscribers, see the module documentation.

Functions

Returns a specification to start this module under a supervisor.

The format of the running stream, nil without one.

Plays samples on the microphone, in its format, any number of frames.

Starts the process. See the module documentation for the options.

Sends the format to the caller until it unsubscribes or exits, and keeps the stream running meanwhile.

Stops sending to the caller.

Types

message()

@type message() :: {NanoKVMGo.Microphone, {:format, NanoKVMGo.Audio.format()}}

A message to subscribers, see the module documentation.

option()

@type option() ::
  {:name, GenServer.name()}
  | {:device, String.t()}
  | {:idle_ms, pos_integer()}
  | {:program, Path.t()}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

format(server \\ __MODULE__)

@spec format(GenServer.server()) :: NanoKVMGo.Audio.format() | nil

The format of the running stream, nil without one.

play(server \\ __MODULE__, pcm)

@spec play(GenServer.server(), binary()) :: :ok

Plays samples on the microphone, in its format, any number of frames.

start_link(opts \\ [])

@spec start_link([option()]) :: GenServer.on_start()

Starts the process. See the module documentation for the options.

subscribe(server \\ __MODULE__)

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

Sends the format to the caller until it unsubscribes or exits, and keeps the stream running meanwhile.

unsubscribe(server \\ __MODULE__)

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

Stops sending to the caller.