wavex v0.5.0 Wavex.Chunk.Data

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

Functions

Read a data chunk

Link to this section Types

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

Link to this section Functions

Read a data chunk.

Examples

iex> Wavex.Chunk.Data.read(<<
...>   0x64, 0x61, 0x74, 0x61, #  d     a     t     a
...>   0x08, 0x00, 0x00, 0x00, #  8
...>   0x00, 0x00, 0x00, 0x00, #  0
...>   0x00, 0x00, 0x00, 0x00  #  0
...> >>)
{:ok, %Wavex.Chunk.Data{size: 8, 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.Chunk.Data.read(<<
...>   0x64, 0x61, 0x74, 0x20, #  d     a     t     \s 
...>   0x08, 0x00, 0x00, 0x00, #  8
...>   0x00, 0x00, 0x00, 0x00, #  0
...>   0x00, 0x00, 0x00, 0x00  #  0
...> >>)
{:error, %Wavex.Error.UnexpectedFourCC{expected: "data", actual: "dat "}}