SoundFontInfoLib  2.21.6
Library for parsing and rendering SF2 files
SF2::IO::Chunk Class Reference

Represents a tagged chunk of a file. More...

#include <Chunk.hpp>

Inherited by SF2::IO::ChunkList.

Public Member Functions

 Chunk (Tag tag, uint32_t size, Pos pos)
 Constructor. More...
 
Tag tag () const
 Obtain the Tag type for the chunk. More...
 
size_t size () const
 Obtain the size of the chunk data. More...
 
Pos begin () const
 Obtain the location of the first byte of the chunk data. More...
 
Pos end () const
 Obtain the location right after the last byte of chunk data. More...
 
Pos advance () const
 Obtain the file position of the next chunk in the file after this one. More...
 
std::string extract () const
 Treat the chunk data as a string of ASCII characters with a max length of 256 characters. More...
 
std::shared_ptr< int16_t > extractSamples () const
 Read samples into a new buffer. More...
 

Detailed Description

Represents a tagged chunk of a file.

A chunk starts with a 4-byte value that is taken as 4 ASCII characters. The 4-byte value uniquely identifies the type of data held in the chunk. The next entry in the chunk layout is an unsigned 4-byte value indicating the number of bytes in the chunk. The chunk records the position of its data in the file. It does not hold any internal data apart from the chunk tag and size.

Constructor & Destructor Documentation

◆ Chunk()

SF2::IO::Chunk::Chunk ( Tag  tag,
uint32_t  size,
Pos  pos 
)
inline

Constructor.

Parameters
tagthe chunk's Tag type
sizethe number of bytes held by the chunk
posthe file position where the contents of the chunk is to be found

Member Function Documentation

◆ advance()

Pos SF2::IO::Chunk::advance ( ) const
inline

Obtain the file position of the next chunk in the file after this one.

Returns
Pos instance

References SF2::IO::Pos::advance().

◆ begin()

Pos SF2::IO::Chunk::begin ( ) const
inline

Obtain the location of the first byte of the chunk data.

Returns
Pos instance

Referenced by extract(), and extractSamples().

◆ end()

Pos SF2::IO::Chunk::end ( ) const
inline

Obtain the location right after the last byte of chunk data.

Returns
Pos instance

References SF2::IO::Pos::advance().

◆ extract()

std::string SF2::IO::Chunk::extract ( ) const
inline

Treat the chunk data as a string of ASCII characters with a max length of 256 characters.

The result is sanitized: leading/trailing spaces are removed, non-ASCII characters are converted to '_' (the SF2 spec is pre-Unicode).

Returns
chunk contents as std::string value

References begin(), SF2::IO::Pos::readInto(), size(), and SF2::IO::trim_property().

◆ extractSamples()

std::shared_ptr<int16_t> SF2::IO::Chunk::extractSamples ( ) const
inline

Read samples into a new buffer.

Returns
new buffer containing the 16-bit audio samples

References begin(), SF2::IO::Pos::readInto(), and size().

◆ size()

size_t SF2::IO::Chunk::size ( ) const
inline

Obtain the size of the chunk data.

Returns
Tag type

Referenced by extract(), and extractSamples().

◆ tag()

Tag SF2::IO::Chunk::tag ( ) const
inline

Obtain the Tag type for the chunk.

Returns
Tag type

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