# `TuningFork.Xwma`
[🔗](https://github.com/jaman/tuning_fork/blob/v0.1.12/tuning_fork/lib/tuning_fork/xwma.ex#L1)

xWMA audio — WMA v2 packets with a table of how much each decodes to, as XACT wave
banks and `.xwma` files hold it — wrapped as a file and decoded to PCM.

    riff = TuningFork.Xwma.riff(packets, %{channels: 2, rate: 44_100, bytes_per_second: 12_000, block_align: 4459, seek: table})
    {:ok, pcm, %{rate: 44_100, channels: 2}} = TuningFork.Xwma.decode(riff)

A file is `RIFF`/`XWMA` with a `fmt ` chunk (format tag `0x0161`, the channels, rate,
average bytes per second, packet size and 16 bits per sample), a `dpds` chunk (the
seek table: the decoded byte count at the end of each packet, little-endian 32-bit)
and a `data` chunk of the packets.

## Decoders

Decoding goes to the first available `TuningFork.Xwma.Decoder` of
`config :tuning_fork, :xwma_decoders`. Without that setting the list is
`TuningFork.Wma` — present when a package that decodes WMA itself is a dependency —
then `TuningFork.Xwma.Ffmpeg`, the machine's `ffmpeg`. With none available,
`decode/1` returns `{:error, :no_decoder}`.

Each file is decoded once; the PCM is kept in `TuningFork.Sample.Fetch.dir/0`.

# `format`

```elixir
@type format() :: %{
  channels: pos_integer(),
  rate: pos_integer(),
  bytes_per_second: pos_integer(),
  block_align: pos_integer(),
  seek: [non_neg_integer()]
}
```

# `available?`

```elixir
@spec available?() :: boolean()
```

Whether this machine can decode xWMA.

# `decode`

```elixir
@spec decode(binary()) ::
  {:ok, binary(), %{rate: pos_integer(), channels: pos_integer()}}
  | {:error, term()}
```

The audio of an `.xwma` file as signed 16-bit little-endian interleaved PCM, with its
rate and channel count, from the first decoder that can run. Fails with
`{:error, :no_decoder}` or the decoder's own error.

# `decoders`

```elixir
@spec decoders() :: [module()]
```

The decoders that can run here, in the order they are tried.

# `riff`

```elixir
@spec riff(binary(), format()) :: binary()
```

An `.xwma` file of `packets` in `format`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
