wavex v0.2.16 Wavex.DataChunk

Reading a data chunk.

A data chunk normally contains:

  • a "data" FourCC,
  • the size of the actual audio data,
  • the actual audio data.

Link to this section Summary

Link to this section Types

Link to this type t()
t() :: %Wavex.DataChunk{data: binary(), size: non_neg_integer()}

Link to this section Functions

Link to this function read(binary, block_align)

Read a data chunk.

Examples

iex> Wavex.DataChunk.read(<<
...>   0x64, 0x61, 0x74, 0x61, #  d     a     t     a
...>   0x02, 0x00, 0x00, 0x00, #  2
...>   0x00, 0x00, 0x00, 0x00, #  0
...>   0x00, 0x00, 0x00, 0x00  #  0
...> >>, 4)
{:ok, %Wavex.DataChunk{size: 2, data: <<0, 0, 0, 0, 0, 0, 0, 0>>}}

Caveat

“data” FourCC

Bytes 1-4 must read "data" to indicate a data chunk. A different value results in an error.

iex> Wavex.DataChunk.read(<<"dat ", 2, 0, 0, 0, 0, 0, 0>>, 1)
{:error, %Wavex.Error.UnexpectedFourCC{expected: "data", actual: "dat "}}