SoundFontInfoLib  2.21.6
Library for parsing and rendering SF2 files
SF2::Entity::SampleHeader Class Reference

Define the audio samples to be used for playing a specific sound. More...

#include <SampleHeader.hpp>

Public Types

enum  Type {
  monoSample = 1 , rightSample = 2 , leftSample = 4 , linkedSample = 8 ,
  rom = 0x8000
}
 

Public Member Functions

 SampleHeader (IO::Pos &pos)
 Construct new instance from SF2 file. More...
 
 SampleHeader (uint32_t start, uint32_t end, uint32_t loopBegin, uint32_t loopEnd, uint32_t sampleRate, uint8_t key, int8_t adjustment)
 Construct instance for unit tests. More...
 
bool isMono () const
 
bool isRight () const
 
bool isLeft () const
 
bool isROM () const
 
size_t startIndex () const
 
size_t endIndex () const
 
size_t startLoopIndex () const
 
size_t endLoopIndex () const
 
size_t sampleRate () const
 
short originalMIDIKey () const
 
short pitchCorrection () const
 
void dump (const std::string &indent, int index) const
 

Static Public Attributes

constexpr static size_t size = 46
 

Detailed Description

Define the audio samples to be used for playing a specific sound.

Memory layout of a 'shdr' entry. The size of this is defined to be 46 bytes, but due to alignment/padding the struct below is 48 bytes.

The offsets (begin, end, loopBegin, and loopEnd) are indices into a big array of 16-bit integer sample values.

Member Enumeration Documentation

◆ Type

Enumerator
monoSample 
rightSample 
leftSample 
linkedSample 
rom 

Constructor & Destructor Documentation

◆ SampleHeader() [1/2]

SF2::Entity::SampleHeader::SampleHeader ( IO::Pos pos)
inlineexplicit

Construct new instance from SF2 file.

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

◆ SampleHeader() [2/2]

SF2::Entity::SampleHeader::SampleHeader ( uint32_t  start,
uint32_t  end,
uint32_t  loopBegin,
uint32_t  loopEnd,
uint32_t  sampleRate,
uint8_t  key,
int8_t  adjustment 
)
inline

Construct instance for unit tests.

Member Function Documentation

◆ dump()

void SampleHeader::dump ( const std::string &  indent,
int  index 
) const

◆ endIndex()

size_t SF2::Entity::SampleHeader::endIndex ( ) const
inline
Returns
index + 1 of the last sample. According to spec, this is first of 46 0.0 values after the last sample

Referenced by SF2::Render::Sample::Bounds::Bounds().

◆ endLoopIndex()

size_t SF2::Entity::SampleHeader::endLoopIndex ( ) const
inline
Returns
index of the last + 1 of a sample in a loop.

Referenced by SF2::Render::Sample::Bounds::Bounds().

◆ isLeft()

bool SF2::Entity::SampleHeader::isLeft ( ) const
inline
Returns
true if these samples generate for the left channel

References leftSample.

◆ isMono()

bool SF2::Entity::SampleHeader::isMono ( ) const
inline
Returns
true if this sample only has one channel

References monoSample.

◆ isRight()

bool SF2::Entity::SampleHeader::isRight ( ) const
inline
Returns
true if these samples generate for the right channel

References rightSample.

◆ isROM()

bool SF2::Entity::SampleHeader::isROM ( ) const
inline
Returns
true if samples come from a ROM

References rom.

◆ originalMIDIKey()

short SF2::Entity::SampleHeader::originalMIDIKey ( ) const
inline
Returns
the MIDI key (frequency) for the source samples

◆ pitchCorrection()

short SF2::Entity::SampleHeader::pitchCorrection ( ) const
inline
Returns
the pitch correction to apply when playing back the samples

◆ sampleRate()

size_t SF2::Entity::SampleHeader::sampleRate ( ) const
inline
Returns
the sample rate used to record the samples in the SF2 file

◆ startIndex()

size_t SF2::Entity::SampleHeader::startIndex ( ) const
inline
Returns
the index of the first sample

Referenced by SF2::Render::Sample::Bounds::Bounds().

◆ startLoopIndex()

size_t SF2::Entity::SampleHeader::startLoopIndex ( ) const
inline
Returns
index of the first sample in a loop.

Referenced by SF2::Render::Sample::Bounds::Bounds().

Member Data Documentation

◆ size

constexpr static size_t SF2::Entity::SampleHeader::size = 46
staticconstexpr

Referenced by SampleHeader().


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