wavex v0.7.1 Wavex.Chunk.RIFF
Read a RIFF chunk.
Link to this section Summary
Functions
Read a RIFF header
Link to this section Types
Link to this section Functions
Link to this function
read(binary)
read(binary()) :: {:ok, t(), binary()} | {:error, Wavex.Error.UnexpectedEOF.t() | Wavex.Error.UnexpectedFourCC.t()}
Read a RIFF header.
Examples
iex> Wavex.Chunk.RIFF.read(<<
...> 0x52, 0x49, 0x46, 0x46, # R I F F
...> 0x24, 0x08, 0x00, 0x00, # 2084
...> 0x57, 0x41, 0x56, 0x45 # W A V E
...> >>)
{:ok, %Wavex.Chunk.RIFF{size: 2084}, ""}
Caveats
Chunk ID
Bytes 1-4 must read "RIFF"
to indicate the Resource Interchange File Format.
A different value results in an error.
iex> Wavex.Chunk.RIFF.read(<<"RIFX", 0, 0, 0, 0, "WAVE">>)
{:error, %Wavex.Error.UnexpectedFourCC{expected: "RIFF", actual: "RIFX"}}
WAVE ID
Bytes 9-12 must read "WAVE"
to indicate a waveform audio file. A different
value results in an error.
iex> Wavex.Chunk.RIFF.read(<<"RIFF", 0, 0, 0, 0, "AVI ">>)
{:error, %Wavex.Error.UnexpectedFourCC{expected: "WAVE", actual: "AVI "}}
Header size
A binary must be at least 12 bytes to contain a RIFF header.
iex> Wavex.Chunk.RIFF.read(<<"RIFF", 0, 0>>)
{:error, %Wavex.Error.UnexpectedEOF{}}
Generally, the following holds for any x
:
not is_binary(x) or
String.length(x) >= 12 or
Wavex.Chunk.RIFF.read(x) == %Wavex.Error.UnexpectedEOF{}