arduino-audio-tools
Loading...
Searching...
No Matches
WAVHeader Class Reference

Parser for Wav header data for details see https://de.wikipedia.org/wiki/RIFF_WAVE. More...

#include <CodecWAV.h>

Public Member Functions

 WAVHeader ()=default
WAVAudioInfo & audioInfo ()
 provides the info from the header
size_t available ()
 number of bytes available in the header buffer
void clear ()
 Reset internal stored header information and buffer.
void dumpHeader ()
 Debug helper: dumps header bytes as printable characters.
int getDataPos ()
 Determines the data start position using the data tag.
bool isDataComplete ()
 Returns true if the header is complete (containd data tag).
bool isOverflow ()
bool parse ()
 Call when header data write is complete to parse the data.
void setAudioInfo (WAVAudioInfo info)
 Sets the info in the header.
int write (uint8_t *data, size_t data_len)
bool writeHeader (Print *out)
 Just write a wav header to the indicated outputbu.
bool writeHeader (Print *out, const WAVAudioInfo &info)
 Just write a wav header with explicit info to the indicated output.

Static Public Member Functions

static int extraHeaderBytes (const WAVAudioInfo &info)

Protected Member Functions

bool eof ()
int getChar ()
uint32_t getChar32 ()
int indexOf (const char *str)
void logInfo ()
uint16_t read_int16 ()
uint32_t read_int32 ()
uint32_t read_tag ()
void seek (long int offset, int origin)
bool setPos (const char *id)
void skip (int n)
size_t tell ()
void write16 (BaseBuffer< uint8_t > &buffer, uint16_t value)
void write32 (BaseBuffer< uint8_t > &buffer, uint64_t value)
void writeDataHeader (BaseBuffer< uint8_t > &buffer, const WAVAudioInfo &info)
void writeFactChunk (BaseBuffer< uint8_t > &buffer, const WAVAudioInfo &info)
void writeFMT (BaseBuffer< uint8_t > &buffer, const WAVAudioInfo &info)
void writeRiffHeader (BaseBuffer< uint8_t > &buffer, const WAVAudioInfo &info)

Static Protected Member Functions

static uint16_t samplesPerBlock (const WAVAudioInfo &info)

Protected Attributes

SingleBuffer< uint8_t > buffer { 200 }
size_t data_pos = 0
WAVAudioInfo headerInfo

Detailed Description

Parser for Wav header data for details see https://de.wikipedia.org/wiki/RIFF_WAVE.

Logic notes for WAVAudioInfo size fields:

  • file_size stores the full RIFF file size in bytes. In the RIFF header this is written/read as chunk_size = file_size - 8.
  • data_length stores the WAV payload size (data chunk length).
  • is_streamed indicates unknown/unbounded payload length.

Parsing behavior:

  • RIFF chunk_size is normalized to full file_size by adding 8.
  • If parsed data_length is 0 or very large (>= 0x7fff0000), the stream is treated as streamed (is_streamed=true) and data_length is normalized to ~0.

Writing behavior:

  • RIFF writes file_size - 8 into the chunk-size field.
  • If data_length==0 in non-streamed mode, it is derived from file_size - 36 (standard WAV relationship).
  • In streamed mode, data_length is written as max (~0) when not set.
Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ WAVHeader()

WAVHeader ( )
default

Member Function Documentation

◆ audioInfo()

WAVAudioInfo & audioInfo ( )
inline

provides the info from the header

◆ available()

size_t available ( )
inline

number of bytes available in the header buffer

◆ clear()

void clear ( )
inline

Reset internal stored header information and buffer.

◆ dumpHeader()

void dumpHeader ( )
inline

Debug helper: dumps header bytes as printable characters.

◆ eof()

bool eof ( )
inlineprotected

◆ extraHeaderBytes()

int extraHeaderBytes ( const WAVAudioInfo & info)
inlinestatic

Number of header bytes preceeding the 'data' chunk's payload, beyond the 36 bytes of a standard PCM header (12 byte RIFF + 24 byte fmt + 8 byte data tag/size = 36 + sizeof('fmt ' extension) + sizeof('fact' chunk)). Only non-zero for ADPCM formats when ext_adpcm_header is enabled.

◆ getChar()

int getChar ( )
inlineprotected

◆ getChar32()

uint32_t getChar32 ( )
inlineprotected

◆ getDataPos()

int getDataPos ( )
inline

Determines the data start position using the data tag.

◆ indexOf()

int indexOf ( const char * str)
inlineprotected

◆ isDataComplete()

bool isDataComplete ( )
inline

Returns true if the header is complete (containd data tag).

◆ isOverflow()

bool isOverflow ( )
inline

True if the header buffer has grown to its maximum allowed size (MAX_WAV_HEADER_LEN_LIMIT) without finding the 'data' chunk - indicates a malformed or unusually large header that will never complete.

◆ logInfo()

void logInfo ( )
inlineprotected

◆ parse()

bool parse ( )
inline

Call when header data write is complete to parse the data.

◆ read_int16()

uint16_t read_int16 ( )
inlineprotected

◆ read_int32()

uint32_t read_int32 ( )
inlineprotected

◆ read_tag()

uint32_t read_tag ( )
inlineprotected

◆ samplesPerBlock()

uint16_t samplesPerBlock ( const WAVAudioInfo & info)
inlinestaticprotected

Number of samples encoded in a single block, for ADPCM formats (assumes 4 bits per sample as used by MS/IMA ADPCM).

◆ seek()

void seek ( long int offset,
int origin )
inlineprotected

◆ setAudioInfo()

void setAudioInfo ( WAVAudioInfo info)
inline

Sets the info in the header.

◆ setPos()

bool setPos ( const char * id)
inlineprotected

◆ skip()

void skip ( int n)
inlineprotected

◆ tell()

size_t tell ( )
inlineprotected

◆ write()

int write ( uint8_t * data,
size_t data_len )
inline

Adds data to the wav header data buffer and make it available for parsing. The buffer grows automatically (up to MAX_WAV_HEADER_LEN_LIMIT) if the header does not fit into the initial MAX_WAV_HEADER_LEN bytes - e.g. because of LIST/bext/other metadata chunks before 'data'.

◆ write16()

void write16 ( BaseBuffer< uint8_t > & buffer,
uint16_t value )
inlineprotected

◆ write32()

void write32 ( BaseBuffer< uint8_t > & buffer,
uint64_t value )
inlineprotected

◆ writeDataHeader()

void writeDataHeader ( BaseBuffer< uint8_t > & buffer,
const WAVAudioInfo & info )
inlineprotected

◆ writeFactChunk()

void writeFactChunk ( BaseBuffer< uint8_t > & buffer,
const WAVAudioInfo & info )
inlineprotected

'fact' chunk: required for compressed (e.g. ADPCM) formats, holds the total number of samples (per channel) in the data chunk.

◆ writeFMT()

void writeFMT ( BaseBuffer< uint8_t > & buffer,
const WAVAudioInfo & info )
inlineprotected

◆ writeHeader() [1/2]

bool writeHeader ( Print * out)
inline

Just write a wav header to the indicated outputbu.

◆ writeHeader() [2/2]

bool writeHeader ( Print * out,
const WAVAudioInfo & info )
inline

Just write a wav header with explicit info to the indicated output.

◆ writeRiffHeader()

void writeRiffHeader ( BaseBuffer< uint8_t > & buffer,
const WAVAudioInfo & info )
inlineprotected

Member Data Documentation

◆ buffer

SingleBuffer<uint8_t> buffer { 200 }
protected

◆ data_pos

size_t data_pos = 0
protected

◆ headerInfo

WAVAudioInfo headerInfo
protected

The documentation for this class was generated from the following file: