# gizhw:alsa

the Linux backend of gizhw:audio. PCM audio through ALSA (libasound.so.2, loaded at run time, so no build-time link): play and capture 16-bit little-endian interleaved frames on a PCM name ("default", "hw:0,0"). The library's constants are ALSA's (SND_PCM_STREAM_PLAYBACK 0, SND_PCM_STREAM_CAPTURE 1, SND_PCM_FORMAT_S16_LE 2, SND_PCM_ACCESS_RW_INTERLEAVED 3).

```gizlang
import * as Alsa from "gizhw:alsa";
```

## Types

### `Pcm`

```gizlang
type Pcm
```

An open PCM: the library's snd_pcm_t pointer, the library, the channel count and the rate.

- `channels`: `i64`
- `rate`: `i64`

## Functions

### `frameBytes`

```gizlang
function frameBytes(channels: i64): i64
```

The bytes of one frame (all channels of one instant).

Effects: fail.

### `open`

```gizlang
function open(sys: System, name: string, capture: bool, rate: i64, channels: i64): Pcm throws string
```

Opens PCM `name` for capture or playback at `rate` Hz with `channels` channels.

Effects: fail, io.

### `play`

```gizlang
function play(pcm: Pcm, samples: bytes): i64 throws string
```

Plays `samples` (whole frames); gives the frames played. An underrun is recovered and the write retried once.

Effects: fail, io.

### `capture`

```gizlang
function capture(pcm: Pcm, frames: i64): bytes throws string
```

Captures `frames` frames; gives the bytes read (whole frames).

Effects: fail, io.

### `close`

```gizlang
function close(pcm: Pcm): void
```

Closes the PCM.

Effects: fail, io.

### `cards`

```gizlang
function cards(sys: System): Vec<Device.Device> throws IoError
```

The sound cards the sound class has (their devices; the PCM names are on each card).

Effects: fail, io.

