hydrogen 1.1.1
Sampler Class Reference

Waveform based sampler. More...

#include <Sampler.h>

Inheritance diagram for Sampler:
Object

Public Types

enum  PAN_LAW_TYPES {
  RATIO_STRAIGHT_POLYGONAL = 0 , RATIO_CONST_POWER , RATIO_CONST_SUM , LINEAR_STRAIGHT_POLYGONAL ,
  LINEAR_CONST_POWER , LINEAR_CONST_SUM , POLAR_STRAIGHT_POLYGONAL , POLAR_CONST_POWER ,
  POLAR_CONST_SUM , QUADRATIC_STRAIGHT_POLYGONAL , QUADRATIC_CONST_POWER , QUADRATIC_CONST_SUM ,
  LINEAR_CONST_K_NORM , RATIO_CONST_K_NORM , POLAR_CONST_K_NORM , QUADRATIC_CONST_K_NORM
}
 PAN LAWS The following pan law functions return pan_L (==L, which is the gain for Left channel). More...
 

Public Member Functions

 Sampler ()
 Constructor of the Sampler. More...
 
 ~Sampler ()
 
void process (uint32_t nFrames, Song *pSong)
 
void noteOn (Note *pNote)
 Start playing a note. More...
 
void noteOff (Note *pNote)
 Stop playing a note. More...
 
void midiKeyboardNoteOff (int key)
 
void stopPlayingNotes (Instrument *pInstr=nullptr)
 
int getPlayingNotesNumber ()
 
void preview_sample (std::shared_ptr< Sample > pSample, int length)
 Preview, uses only the first layer. More...
 
void preview_instrument (Instrument *pInstr)
 
void setPlayingNotelength (Instrument *pInstrument, unsigned long ticks, unsigned long noteOnTick)
 
bool isInstrumentPlaying (Instrument *pInstr)
 
void setInterpolateMode (Interpolation::InterpolateMode mode)
 
InstrumentgetPreviewInstrument () const
 
InstrumentgetPlaybackTrackInstrument () const
 
Interpolation::InterpolateMode getInterpolateMode ()
 
void reinitializePlaybackTrack ()
 Loading of the playback track. More...
 
- Public Member Functions inherited from Object
 ~Object ()
 destructor More...
 
 Object (const Object &obj)
 copy constructor More...
 
 Object (const char *class_name)
 constructor More...
 
const char * class_name () const
 return the class name More...
 
virtual QString toQString (const QString &sPrefix, bool bShort=true) const
 Formatted string version for debugging purposes. More...
 
void Print (bool bShort=true) const
 Prints content of toQString() via DEBUGLOG. More...
 

Static Public Member Functions

static float ratioStraightPolygonalPanLaw (float fPan)
 
static float ratioConstPowerPanLaw (float fPan)
 
static float ratioConstSumPanLaw (float fPan)
 
static float linearStraightPolygonalPanLaw (float fPan)
 
static float linearConstPowerPanLaw (float fPan)
 
static float linearConstSumPanLaw (float fPan)
 
static float polarStraightPolygonalPanLaw (float fPan)
 
static float polarConstPowerPanLaw (float fPan)
 
static float polarConstSumPanLaw (float fPan)
 
static float quadraticStraightPolygonalPanLaw (float fPan)
 
static float quadraticConstPowerPanLaw (float fPan)
 
static float quadraticConstSumPanLaw (float fPan)
 
static float linearConstKNormPanLaw (float fPan, float k)
 
static float polarConstKNormPanLaw (float fPan, float k)
 
static float ratioConstKNormPanLaw (float fPan, float k)
 
static float quadraticConstKNormPanLaw (float fPan, float k)
 
static float getRatioPan (float fPan_L, float fPan_R)
 This necessary function returns the single pan parameter in [-1,1] from the L,R gains as it was input from the GUI (up to scale and translation, which is arbitrary) More...
 
- Static Public Member Functions inherited from Object
static void set_count (bool flag)
 enable/disable class instances counting More...
 
static bool count_active ()
 return true if class instances counting is enabled More...
 
static unsigned objects_count ()
 return the number of objects More...
 
static void write_objects_map_to (std::ostream &out)
 output the full objects map to a given ostream More...
 
static void write_objects_map_to_cerr ()
 output objects map to stderr More...
 
static int bootstrap (Logger *logger, bool count=false)
 must be called before any Object instantiation ! More...
 
static Loggerlogger ()
 return the logger instance More...
 

Data Fields

float * m_pMainOut_L
 sampler main out (left channel) More...
 
float * m_pMainOut_R
 sampler main out (right channel) More...
 

Static Public Attributes

static const float K_NORM_DEFAULT = 1.33333333333333
 default k for pan law with such that L^k + R^k = const must be initialised in Sampler.cpp More...
 
- Static Public Attributes inherited from Object
static QString sPrintIndention = " "
 String used to format the debugging string output of some core classes. More...
 

Private Member Functions

float panLaw (float fPan, Song *pSong)
 function to direct the computation to the selected pan law function More...
 
bool processPlaybackTrack (int nBufferSize)
 
bool isAnyInstrumentSoloed () const
 
bool renderNote (Note *pNote, unsigned nBufferSize, Song *pSong)
 Render a note Return false: the note is not ended Return true: the note is ended. More...
 
bool renderNoteNoResample (std::shared_ptr< Sample > pSample, Note *pNote, SelectedLayerInfo *pSelectedLayerInfo, InstrumentComponent *pCompo, DrumkitComponent *pDrumCompo, int nBufferSize, int nInitialSilence, float cost_L, float cost_R, float cost_track_L, float cost_track_R, Song *pSong)
 
bool renderNoteResample (std::shared_ptr< Sample > pSample, Note *pNote, SelectedLayerInfo *pSelectedLayerInfo, InstrumentComponent *pCompo, DrumkitComponent *pDrumCompo, int nBufferSize, int nInitialSilence, float cost_L, float cost_R, float cost_track_L, float cost_track_R, float fLayerPitch, Song *pSong)
 

Private Attributes

std::vector< Note * > m_playingNotesQueue
 
std::vector< Note * > m_queuedNoteOffs
 
Instrumentm_pPlaybackTrackInstrument
 Instrument used for the playback track feature. More...
 
Instrumentm_pPreviewInstrument
 Instrument used for the preview feature. More...
 
int m_nMaxLayers
 Maximum number of layers to be used in the Instrument editor. More...
 
int m_nPlayBackSamplePosition
 
Interpolation::InterpolateMode m_interpolateMode
 

Additional Inherited Members

- Static Protected Attributes inherited from Object
static Logger__logger = nullptr
 logger instance pointer More...
 

Detailed Description

Waveform based sampler.

Member Enumeration Documentation

◆ PAN_LAW_TYPES

PAN LAWS The following pan law functions return pan_L (==L, which is the gain for Left channel).

They assume a fPan argument domain in [-1;1], and this always happens

thanks to the previously called getRatioPan().

For the right channel use: R(p) == pan_R(p) = pan_L(-p) == L(-p)

thanks to the Left-Right symmetry.

The prefix of the function name tells the interpretation of the fPan argument:

"ratio" parameter: fPan = R/L - 1 if panned to the left, fPan = 1 - L/R if panned to the right.

"linear" parameter (arithmetic mean with linear weights): fPan = ( R - L ) / ( R + L ).

"polar" parameter (polar coordinate in LR plane): fPan = 4 / pi * arctan( R/L ) - 1 if L != 0, fPan = 1 if L == 0.

"quadratic" parameter (arithmetic mean with squared weights): fPan = ( R^2 - L^2 ) / ( R^2 + L^2 ).

Note: using a different fPan interpretation makes the output signal more central or more lateral. From more central to more lateral:

"quadratic" —> "ratio" —> "polar" —> "linear"

After the prefix, the name describes the Image of the pan law in the LR plane. (remember that each pan law is a parametrized curve in LR plane. E.g.: "ConstantSum": it's properly used in an anechoic room, where there are no reflections. Ensures uniform volumes in MONO export, has -6.02 dB center compensation. "ConstantPower": probably makes uniform volumes in a common room, has -3.01 dB center compensation. "ConstantKNorm": L^k + R^k = const generalises constant sum (k = 1) and constant power (k = 2) "StraightPolygonal": one gain is constant while the other varies. It's ideal as BALANCE law of DUAL-channel track, has 0 dB center compensation.

Enumerator
RATIO_STRAIGHT_POLYGONAL 
RATIO_CONST_POWER 
RATIO_CONST_SUM 
LINEAR_STRAIGHT_POLYGONAL 
LINEAR_CONST_POWER 
LINEAR_CONST_SUM 
POLAR_STRAIGHT_POLYGONAL 
POLAR_CONST_POWER 
POLAR_CONST_SUM 
QUADRATIC_STRAIGHT_POLYGONAL 
QUADRATIC_CONST_POWER 
QUADRATIC_CONST_SUM 
LINEAR_CONST_K_NORM 
RATIO_CONST_K_NORM 
POLAR_CONST_K_NORM 
QUADRATIC_CONST_K_NORM 

Constructor & Destructor Documentation

◆ Sampler()

Sampler ( )

Constructor of the Sampler.

It is called by AudioEngine::AudioEngine() and stored in AudioEngine::__sampler.

◆ ~Sampler()

~Sampler ( )

Member Function Documentation

◆ getInterpolateMode()

Interpolation::InterpolateMode getInterpolateMode ( )
inline

◆ getPlaybackTrackInstrument()

Instrument * getPlaybackTrackInstrument ( ) const
inline

◆ getPlayingNotesNumber()

int getPlayingNotesNumber ( )
inline

◆ getPreviewInstrument()

Instrument * getPreviewInstrument ( ) const
inline

◆ getRatioPan()

float getRatioPan ( float  fPan_L,
float  fPan_R 
)
static

This necessary function returns the single pan parameter in [-1,1] from the L,R gains as it was input from the GUI (up to scale and translation, which is arbitrary)

◆ isAnyInstrumentSoloed()

bool isAnyInstrumentSoloed ( ) const
private

◆ isInstrumentPlaying()

bool isInstrumentPlaying ( Instrument pInstr)

◆ linearConstKNormPanLaw()

float linearConstKNormPanLaw ( float  fPan,
float  k 
)
static

◆ linearConstPowerPanLaw()

float linearConstPowerPanLaw ( float  fPan)
static

◆ linearConstSumPanLaw()

float linearConstSumPanLaw ( float  fPan)
static

◆ linearStraightPolygonalPanLaw()

float linearStraightPolygonalPanLaw ( float  fPan)
static

◆ midiKeyboardNoteOff()

void midiKeyboardNoteOff ( int  key)

◆ noteOff()

void noteOff ( Note pNote)

Stop playing a note.

This old note_off function is only used by right click on mixer channel strip play button all other note_off stuff will handle in midi_keyboard_note_off() and note_on()

◆ noteOn()

void noteOn ( Note pNote)

Start playing a note.

◆ panLaw()

float panLaw ( float  fPan,
Song pSong 
)
inlineprivate

function to direct the computation to the selected pan law function

◆ polarConstKNormPanLaw()

float polarConstKNormPanLaw ( float  fPan,
float  k 
)
static

◆ polarConstPowerPanLaw()

float polarConstPowerPanLaw ( float  fPan)
static

◆ polarConstSumPanLaw()

float polarConstSumPanLaw ( float  fPan)
static

◆ polarStraightPolygonalPanLaw()

float polarStraightPolygonalPanLaw ( float  fPan)
static

◆ preview_instrument()

void preview_instrument ( Instrument pInstr)

◆ preview_sample()

void preview_sample ( std::shared_ptr< Sample pSample,
int  length 
)

Preview, uses only the first layer.

◆ process()

void process ( uint32_t  nFrames,
Song pSong 
)

◆ processPlaybackTrack()

bool processPlaybackTrack ( int  nBufferSize)
private

◆ quadraticConstKNormPanLaw()

float quadraticConstKNormPanLaw ( float  fPan,
float  k 
)
static

◆ quadraticConstPowerPanLaw()

float quadraticConstPowerPanLaw ( float  fPan)
static

◆ quadraticConstSumPanLaw()

float quadraticConstSumPanLaw ( float  fPan)
static

◆ quadraticStraightPolygonalPanLaw()

float quadraticStraightPolygonalPanLaw ( float  fPan)
static

◆ ratioConstKNormPanLaw()

float ratioConstKNormPanLaw ( float  fPan,
float  k 
)
static

◆ ratioConstPowerPanLaw()

float ratioConstPowerPanLaw ( float  fPan)
static

◆ ratioConstSumPanLaw()

float ratioConstSumPanLaw ( float  fPan)
static

◆ ratioStraightPolygonalPanLaw()

float ratioStraightPolygonalPanLaw ( float  fPan)
static

◆ reinitializePlaybackTrack()

void reinitializePlaybackTrack ( )

Loading of the playback track.

The playback track is added to #__playback_instrument as a new InstrumentLayer containing the loaded Sample. If Song::__playback_track_filename is empty, the layer will be loaded with a nullptr instead.

◆ renderNote()

bool renderNote ( Note pNote,
unsigned  nBufferSize,
Song pSong 
)
private

Render a note Return false: the note is not ended Return true: the note is ended.

◆ renderNoteNoResample()

bool renderNoteNoResample ( std::shared_ptr< Sample pSample,
Note pNote,
SelectedLayerInfo pSelectedLayerInfo,
InstrumentComponent pCompo,
DrumkitComponent pDrumCompo,
int  nBufferSize,
int  nInitialSilence,
float  cost_L,
float  cost_R,
float  cost_track_L,
float  cost_track_R,
Song pSong 
)
private

◆ renderNoteResample()

bool renderNoteResample ( std::shared_ptr< Sample pSample,
Note pNote,
SelectedLayerInfo pSelectedLayerInfo,
InstrumentComponent pCompo,
DrumkitComponent pDrumCompo,
int  nBufferSize,
int  nInitialSilence,
float  cost_L,
float  cost_R,
float  cost_track_L,
float  cost_track_R,
float  fLayerPitch,
Song pSong 
)
private

◆ setInterpolateMode()

void setInterpolateMode ( Interpolation::InterpolateMode  mode)
inline

◆ setPlayingNotelength()

void setPlayingNotelength ( Instrument pInstrument,
unsigned long  ticks,
unsigned long  noteOnTick 
)

◆ stopPlayingNotes()

void stopPlayingNotes ( Instrument pInstr = nullptr)

Field Documentation

◆ K_NORM_DEFAULT

float const K_NORM_DEFAULT = 1.33333333333333
static

default k for pan law with such that L^k + R^k = const must be initialised in Sampler.cpp

set default k for pan law with -4.5dB center compensation, given L^k + R^k = const it is the mean compromise between constant sum and constant power

◆ m_interpolateMode

Interpolation::InterpolateMode m_interpolateMode
private

◆ m_nMaxLayers

int m_nMaxLayers
private

Maximum number of layers to be used in the Instrument editor.

It will be inferred from InstrumentComponent::m_nMaxLayers, which itself is inferred from Preferences::m_nMaxLayers. Default value assigned in Preferences::Preferences(): 16.

◆ m_nPlayBackSamplePosition

int m_nPlayBackSamplePosition
private

◆ m_playingNotesQueue

std::vector<Note*> m_playingNotesQueue
private

◆ m_pMainOut_L

float* m_pMainOut_L

sampler main out (left channel)

◆ m_pMainOut_R

float* m_pMainOut_R

sampler main out (right channel)

◆ m_pPlaybackTrackInstrument

Instrument* m_pPlaybackTrackInstrument
private

Instrument used for the playback track feature.

◆ m_pPreviewInstrument

Instrument* m_pPreviewInstrument
private

Instrument used for the preview feature.

◆ m_queuedNoteOffs

std::vector<Note*> m_queuedNoteOffs
private