SF2cute  0.1
Modern C++ Library for SoundFont 2
sf2cute::SFSample Class Reference

The SFSample class represents a sample header and data. More...

#include <sample.hpp>

Public Member Functions

 SFSample ()
 Constructs a new empty SFSample.
 
 SFSample (std::string name)
 Constructs a new empty SFSample using the specified name. More...
 
 SFSample (std::string name, std::vector< int16_t > data, uint32_t start_loop, uint32_t end_loop, uint32_t sample_rate, uint8_t original_key, int8_t correction)
 Constructs a new SFSample. More...
 
 SFSample (std::string name, std::vector< int16_t > data, uint32_t start_loop, uint32_t end_loop, uint32_t sample_rate, uint8_t original_key, int8_t correction, std::weak_ptr< SFSample > link, SFSampleLink type)
 Constructs a new SFSample with a sample link. More...
 
 SFSample (const SFSample &origin)
 Constructs a new copy of specified SFSample. More...
 
SFSampleoperator= (const SFSample &origin)
 Copy-assigns a new value to the SFSample, replacing its current contents. More...
 
 SFSample (SFSample &&origin)=default
 Acquires the contents of specified SFSample. More...
 
SFSampleoperator= (SFSample &&origin)=default
 Move-assigns a new value to the SFSample, replacing its current contents. More...
 
 ~SFSample ()=default
 Destructs the SFSample.
 
const std::string & name () const noexcept
 Returns the name of this sample. More...
 
void set_name (std::string name)
 Sets the name of this sample. More...
 
uint32_t start_loop () const noexcept
 Returns the starting point of the loop of this sample. More...
 
void set_start_loop (uint32_t start_loop)
 Sets the starting point of the loop of this sample. More...
 
uint32_t end_loop () const noexcept
 Returns the ending point of the loop of this sample. More...
 
void set_end_loop (uint32_t end_loop)
 Sets the ending point of the loop of this sample. More...
 
uint32_t sample_rate () const noexcept
 Returns the sample rate. More...
 
void set_sample_rate (uint32_t sample_rate)
 Sets the sample rate. More...
 
uint8_t original_key () const noexcept
 Returns the original MIDI key number of this sample. More...
 
void set_original_key (uint8_t original_key)
 Sets the original MIDI key number of this sample. More...
 
int8_t correction () const noexcept
 Returns the pitch correction. More...
 
void set_correction (int8_t correction)
 Sets the pitch correction. More...
 
std::shared_ptr< SFSamplelink () const noexcept
 Returns the associated right or left stereo sample. More...
 
bool has_link () const noexcept
 Returns true if this sample has an associated sample. More...
 
void set_link (std::weak_ptr< SFSample > link)
 Sets the associated right or left stereo sample. More...
 
void reset_link () noexcept
 Resets the associated right or left stereo sample.
 
SFSampleLink type () const noexcept
 Returns both the type of sample and the whether the sample is located in RAM or ROM memory. More...
 
void set_type (SFSampleLink type)
 Sets both the type of sample and the whether the sample is located in RAM or ROM memory. More...
 
const std::vector< int16_t > & data () const noexcept
 Returns the sample data. More...
 
bool has_parent_file () const noexcept
 Returns true if this sample has a parent file. More...
 
SoundFontparent_file () const noexcept
 Returns the parent file. More...
 

Static Public Member Functions

template<typename... Args>
static std::shared_ptr< SFSampleNew (Args &&...args)
 Constructs a new SFSample. More...
 

Static Public Attributes

static constexpr std::string::size_type kMaxNameLength = 20 - 1
 Maximum length of sample name (excluding the terminator byte), in terms of bytes.
 
static constexpr uint32_t kTerminatorSampleLength = 46
 The length of terminator samples, in sample data points.
 

Friends

class SoundFont
 
class SoundFontWriter
 

Detailed Description

The SFSample class represents a sample header and data.

Remarks
This class represents the official sfSample type and sample data stored in "smpl" chunk.
See also
"6.1 Sample Data Format in the smpl Sub-chunk". In SoundFont Technical Specification 2.04.
"7.10 The SHDR Sub-chunk". In SoundFont Technical Specification 2.04.

Constructor & Destructor Documentation

sf2cute::SFSample::SFSample ( std::string  name)
explicit

Constructs a new empty SFSample using the specified name.

Parameters
namethe name of the sample.
sf2cute::SFSample::SFSample ( std::string  name,
std::vector< int16_t >  data,
uint32_t  start_loop,
uint32_t  end_loop,
uint32_t  sample_rate,
uint8_t  original_key,
int8_t  correction 
)

Constructs a new SFSample.

Parameters
namethe name of the sample.
datathe sample data
start_loopthe beginning index of the loop, in sample data points, inclusive.
end_loopthe ending index of the loop, in sample data points, exclusive.
sample_ratethe sample rate, in hertz.
original_keythe MIDI key number of the recorded pitch of the sample.
correctionthe pitch correction that should be applied to the sample, in cents.
sf2cute::SFSample::SFSample ( std::string  name,
std::vector< int16_t >  data,
uint32_t  start_loop,
uint32_t  end_loop,
uint32_t  sample_rate,
uint8_t  original_key,
int8_t  correction,
std::weak_ptr< SFSample link,
SFSampleLink  type 
)

Constructs a new SFSample with a sample link.

Parameters
namethe name of the sample.
datathe sample data
start_loopthe beginning index of the loop, in sample data points, inclusive.
end_loopthe ending index of the loop, in sample data points, exclusive.
sample_ratethe sample rate, in hertz.
original_keythe MIDI key number of the recorded pitch of the sample.
correctionthe pitch correction that should be applied to the sample, in cents.
linkthe associated right or left stereo sample. nullptr is allowed.
typeboth the type of sample and the whether the sample is located in RAM or ROM memory.
sf2cute::SFSample::SFSample ( const SFSample origin)

Constructs a new copy of specified SFSample.

Parameters
origina SFSample object.
sf2cute::SFSample::SFSample ( SFSample &&  origin)
default

Acquires the contents of specified SFSample.

Parameters
origina SFSample object.

Member Function Documentation

int8_t sf2cute::SFSample::correction ( ) const
noexcept

Returns the pitch correction.

Returns
the pitch correction that should be applied to the sample, in cents.
const std::vector<int16_t>& sf2cute::SFSample::data ( ) const
noexcept

Returns the sample data.

Returns
the sample data.
uint32_t sf2cute::SFSample::end_loop ( ) const
noexcept

Returns the ending point of the loop of this sample.

Returns
the ending index of the loop, in sample data points, exclusive.
bool sf2cute::SFSample::has_link ( ) const
noexcept

Returns true if this sample has an associated sample.

Returns
true if this sample has an associated sample.
Remarks
This function returns false if the associated sample has been deleted.
bool sf2cute::SFSample::has_parent_file ( ) const
noexcept

Returns true if this sample has a parent file.

Returns
true if this sample has a parent file.
std::shared_ptr<SFSample> sf2cute::SFSample::link ( ) const
noexcept

Returns the associated right or left stereo sample.

Returns
a pointer to the associated right or left stereo sample.
Remarks
This function returns nullptr if the associated sample has been deleted.
const std::string& sf2cute::SFSample::name ( ) const
noexcept

Returns the name of this sample.

Returns
the name of this sample.
template<typename... Args>
static std::shared_ptr<SFSample> sf2cute::SFSample::New ( Args &&...  args)
inlinestatic

Constructs a new SFSample.

Parameters
argsthe arguments for the SFSample constructor.
Returns
the new SFSample object.
SFSample& sf2cute::SFSample::operator= ( const SFSample origin)

Copy-assigns a new value to the SFSample, replacing its current contents.

Parameters
origina SFSample object.
SFSample& sf2cute::SFSample::operator= ( SFSample &&  origin)
default

Move-assigns a new value to the SFSample, replacing its current contents.

Parameters
origina SFSample object.
uint8_t sf2cute::SFSample::original_key ( ) const
noexcept

Returns the original MIDI key number of this sample.

Returns
the MIDI key number of the recorded pitch of the sample.
SoundFont& sf2cute::SFSample::parent_file ( ) const
noexcept

Returns the parent file.

Returns
a reference to the parent file.
uint32_t sf2cute::SFSample::sample_rate ( ) const
noexcept

Returns the sample rate.

Returns
the sample rate, in hertz.
void sf2cute::SFSample::set_correction ( int8_t  correction)

Sets the pitch correction.

Parameters
correctionthe pitch correction that should be applied to the sample, in cents.
void sf2cute::SFSample::set_end_loop ( uint32_t  end_loop)

Sets the ending point of the loop of this sample.

Parameters
end_loopthe ending index of the loop, in sample data points, exclusive.
void sf2cute::SFSample::set_link ( std::weak_ptr< SFSample link)

Sets the associated right or left stereo sample.

Parameters
linka pointer to the associated right or left stereo sample.
void sf2cute::SFSample::set_name ( std::string  name)

Sets the name of this sample.

Parameters
namethe name of this sample.
void sf2cute::SFSample::set_original_key ( uint8_t  original_key)

Sets the original MIDI key number of this sample.

Parameters
original_keythe MIDI key number of the recorded pitch of the sample.
void sf2cute::SFSample::set_sample_rate ( uint32_t  sample_rate)

Sets the sample rate.

Parameters
sample_ratethe sample rate, in hertz.
void sf2cute::SFSample::set_start_loop ( uint32_t  start_loop)

Sets the starting point of the loop of this sample.

Parameters
start_loopthe beginning index of the loop, in sample data points, inclusive.
void sf2cute::SFSample::set_type ( SFSampleLink  type)

Sets both the type of sample and the whether the sample is located in RAM or ROM memory.

Parameters
typeboth the type of sample and the whether the sample is located in RAM or ROM memory.
uint32_t sf2cute::SFSample::start_loop ( ) const
noexcept

Returns the starting point of the loop of this sample.

Returns
the beginning index of the loop, in sample data points, inclusive.
SFSampleLink sf2cute::SFSample::type ( ) const
noexcept

Returns both the type of sample and the whether the sample is located in RAM or ROM memory.

Returns
both the type of sample and the whether the sample is located in RAM or ROM memory.

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