gizhw:audio
PCM sound on any platform. devices lists each sound device by an id the platform gives and a name; open takes the id, the direction and the wanted rate, channels and sample format. Linux plays and captures through ALSA (gizhw:alsa). A platform without a backend fails each call with the class and the platform named.
import * as Audio from "gizhw:audio";Types
Info
type Info = { id: string; name: string; }A sound device: id opens it (an ALSA PCM name on Linux, "default" first), name is the card's own name.
id:stringname:string
Wanted
type Wanted = { rate: i64; channels: i64; format: string; }What open asks for: a rate in Hz, a channel count and a sample format; "s16le" (16-bit little-endian, the channels interleaved) is the one every backend gives.
rate:i64channels:i64format:string
Stream
type StreamAn open stream: its direction and the rate, channels and format of its frames.
capture:boolrate:i64channels:i64format:string
Functions
devices
function devices(sys: System): Vec<Info> throws stringThe sound devices of this machine: the platform's default device first, then one for each card.
Effects: fail, io.
open
function open(sys: System, id: string, capture: bool, wanted: Wanted): Stream throws stringThe sound device id (from devices), open for capture or for playback.
Effects: fail, io.
Methods
Stream.frameBytes
function Stream.frameBytes(self: Stream): i64The bytes of one frame (all channels of one instant).
Effects: fail.
Stream.play
function Stream.play(self: Stream, samples: bytes): i64 throws stringPlays samples (whole frames); gives the frames played.
Effects: fail, io.
Stream.capture
function Stream.capture(self: Stream, frames: i64): bytes throws stringCaptures frames frames; gives their bytes.
Effects: fail, io.
Stream.close
function Stream.close(self: Stream): voidCloses the stream.
Effects: fail, io.