arduino-audio-tools
Loading...
Searching...
No Matches
Public Member Functions | List of all members
WAVFileInfo< FileT > Class Template Reference

Utility for reading and rewriting WAV file metadata in place. More...

#include <WAVFileInfo.h>

Public Member Functions

 WAVFileInfo ()=default
 
bool getInfo (FileT file, WAVAudioInfo &info)
 Reads and parses the WAV header from a file.
 
bool updateSize (FileT file)
 Reads the current WAV header and rewrites it with the actual file size.
 
bool updateSize (FileT file, WAVAudioInfo &info)
 Rewrites the WAV header with the current file size information.
 

Detailed Description

template<typename FileT = File>
class audio_tools::WAVFileInfo< FileT >

Utility for reading and rewriting WAV file metadata in place.

The class parses the existing WAV header, extracts the current audio information, and can rewrite the header with an updated file size so the RIFF and data chunk lengths stay consistent.

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ WAVFileInfo()

template<typename FileT = File>
WAVFileInfo ( )
default

Member Function Documentation

◆ getInfo()

template<typename FileT = File>
bool getInfo ( FileT  file,
WAVAudioInfo info 
)
inline

Reads and parses the WAV header from a file.

The method reads up to MAX_WAV_HEADER_LEN bytes from the beginning of the provided file, parses the WAV header, and copies the extracted audio metadata into info.

Parameters
fileFile-like object that provides read().
infoTarget structure that receives the parsed WAV metadata.
Returns
true if a complete and valid WAV header was parsed successfully; otherwise false.

◆ updateSize() [1/2]

template<typename FileT = File>
bool updateSize ( FileT  file)
inline

Reads the current WAV header and rewrites it with the actual file size.

This overload parses the existing header metadata from the file, seeks back to the beginning of the stream, and then updates the header fields using the current file size.

Parameters
fileFile-like object that provides read(), seek(), size(), and write(). The file must be open in a mode that allows both reading and writing.
Returns
true if the header was read, the file was repositioned, and the updated header was written successfully; otherwise false.

◆ updateSize() [2/2]

template<typename FileT = File>
bool updateSize ( FileT  file,
WAVAudioInfo info 
)
inline

Rewrites the WAV header with the current file size information.

This updates info.file_size from the actual file size and recalculates the payload size before writing a refreshed WAV header back to the file.

Parameters
fileFile-like object that provides size() and write().
infoWAV metadata to update and write back into the file header.
Returns
true if the header was written successfully; otherwise false.

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