|
hydrogen 1.2.3
|
Waveform based sampler. More...
#include <Sampler.h>
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. | |
| ~Sampler () | |
| Interpolation::InterpolateMode | getInterpolateMode () |
| std::shared_ptr< Instrument > | getPlaybackTrackInstrument () const |
| int | getPlayingNotesNumber () |
| const std::vector< Note * > | getPlayingNotesQueue () const |
| std::shared_ptr< Instrument > | getPreviewInstrument () const |
| void | handleSongSizeChange () |
| Recalculates all note starts and positions to make them valid again after the song size changed, e.g. | |
| void | handleTimelineOrTempoChange () |
| Recalculates all note starts to make them valid again after a TempoMarker was added to or deleted from the #Timeline or the latter was activated. | |
| bool | isInstrumentPlaying (std::shared_ptr< Instrument > pInstr) |
| bool | isRenderingNotes () const |
| void | midiKeyboardNoteOff (int key) |
| void | noteOff (Note *pNote) |
| Stop playing a note. | |
| void | noteOn (Note *pNote) |
| Start playing a note. | |
| void | preview_instrument (std::shared_ptr< Instrument > pInstr) |
| void | preview_sample (std::shared_ptr< Sample > pSample, int length) |
| Preview, uses only the first layer. | |
| void | process (uint32_t nFrames) |
| void | reinitializePlaybackTrack () |
| Loading of the playback track. | |
| void | setInterpolateMode (Interpolation::InterpolateMode mode) |
| void | stopPlayingNotes (std::shared_ptr< Instrument > pInstr=nullptr) |
Public Member Functions inherited from Object< Sampler > | |
| Object () | |
| Object (const Object< Sampler > &other) | |
Public Member Functions inherited from Base | |
| Base () | |
| Base (const Base &other) | |
| virtual const char * | class_name () const |
| void | Print (bool bShort=true) const |
| Prints content of toQString() via DEBUGLOG. | |
| virtual QString | toQString (const QString &sPrefix="", bool bShort=true) const |
| Formatted string version for debugging purposes. | |
Static Public Member Functions | |
| static float | getRatioPan (float fPan_L, float fPan_R) |
| This function is used to load old version files (v<=1.1). | |
| static float | linearConstKNormPanLaw (float fPan, float k) |
| static float | linearConstPowerPanLaw (float fPan) |
| static float | linearConstSumPanLaw (float fPan) |
| static float | linearStraightPolygonalPanLaw (float fPan) |
| static float | polarConstKNormPanLaw (float fPan, float k) |
| static float | polarConstPowerPanLaw (float fPan) |
| static float | polarConstSumPanLaw (float fPan) |
| static float | polarStraightPolygonalPanLaw (float fPan) |
| static float | quadraticConstKNormPanLaw (float fPan, float k) |
| static float | quadraticConstPowerPanLaw (float fPan) |
| static float | quadraticConstSumPanLaw (float fPan) |
| static float | quadraticStraightPolygonalPanLaw (float fPan) |
| static float | ratioConstKNormPanLaw (float fPan, float k) |
| static float | ratioConstPowerPanLaw (float fPan) |
| static float | ratioConstSumPanLaw (float fPan) |
| static float | ratioStraightPolygonalPanLaw (float fPan) |
Static Public Member Functions inherited from Base | |
| static const char * | _class_name () |
| return the class name | |
| static QString | base_clock (const QString &sMsg) |
| Measures the current time and stores it in __last_clock. | |
| static QString | base_clock_in (const QString &sMsg) |
| static int | bootstrap (Logger *logger, bool count=false) |
| must be called before any Object instantiation ! | |
| static bool | count_active () |
| static int | getAliveObjectCount () |
| static object_map_t | getObjectMap () |
| static Logger * | logger () |
| return the logger instance | |
| static int | objects_count () |
| static void | printObjectMapDiff (object_map_t map) |
| Creates the difference between a snapshot of the object map and its current state and prints it to std::cout. | |
| static void | set_count (bool flag) |
| enable/disable class instances counting | |
| static void | write_objects_map_to (std::ostream &out, object_map_t *map=nullptr) |
| output the full objects map to a given ostream | |
| static void | write_objects_map_to_cerr () |
| output objects map to stderr | |
Data Fields | |
| float * | m_pMainOut_L |
| sampler main out (left channel) | |
| float * | m_pMainOut_R |
| sampler main out (right channel) | |
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 | |
Static Public Attributes inherited from Base | |
| static QString | sPrintIndention = " " |
| String used to format the debugging string output of some core classes. | |
Private Member Functions | |
| float | panLaw (float fPan, std::shared_ptr< Song > pSong) |
| function to direct the computation to the selected pan law function | |
| bool | processPlaybackTrack (int nBufferSize) |
| bool | renderNote (Note *pNote, unsigned nBufferSize) |
| Render a note. | |
| bool | renderNoteResample (std::shared_ptr< Sample > pSample, Note *pNote, std::shared_ptr< SelectedLayerInfo > pSelectedLayerInfo, std::shared_ptr< InstrumentComponent > pCompo, std::shared_ptr< DrumkitComponent > pDrumCompo, int nBufferSize, int nInitialBufferPos, float cost_L, float cost_R, float cost_track_L, float cost_track_R, float fLayerPitch) |
Private Attributes | |
| Interpolation::InterpolateMode | m_interpolateMode |
| int | m_nMaxLayers |
| Maximum number of layers to be used in the Instrument editor. | |
| int | m_nPlayBackSamplePosition |
| std::vector< Note * > | m_playingNotesQueue |
| std::shared_ptr< Instrument > | m_pPlaybackTrackInstrument |
| Instrument used for the playback track feature. | |
| std::shared_ptr< Instrument > | m_pPreviewInstrument |
| Instrument used for the preview feature. | |
| std::vector< Note * > | m_queuedNoteOffs |
Additional Inherited Members | |
Protected Member Functions inherited from Object< Sampler > | |
| ~Object () | |
Protected Member Functions inherited from Base | |
| ~Base () | |
Static Protected Member Functions inherited from Base | |
| static void | registerClass (const char *name, const atomic_obj_cpt_t *counters) |
Static Protected Attributes inherited from Base | |
| static bool | __count = false |
| should we count class instances | |
| static timeval | __last_clock = { 0, 0 } |
| static Logger * | __logger = nullptr |
| enum PAN_LAW_TYPES |
PAN LAWS The following pan law functions return pan_L (==L, which is the gain for Left channel).
For the right channel use: R(p) == pan_R(p) = pan_L(-p) == L(-p)
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:
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,
Some pan laws use expensive math functions like pow() and sqrt(). Pan laws can be approximated by polynomials, e.g. with degree = 2, to adjust the center compensation, but then you cannot control the interpretation of the fPan argument exactly.
| Sampler | ( | ) |
Constructor of the Sampler.
It is called by AudioEngine::AudioEngine() and stored in AudioEngine::m_pSampler.
Definition at line 70 of file Sampler.cpp.
| ~Sampler | ( | ) |
Definition at line 95 of file Sampler.cpp.
|
inline |
|
inline |
|
inline |
|
inline |
|
static |
This function is used to load old version files (v<=1.1).
It 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). Default output is 0 (=central pan) if arguments are invalid. --—Historical Note--— Originally (version <= 1.0) pan_L,pan_R were actually gains for each channel; "instrument" and "note" pans were multiplied as in a gain CHAIN in each separate channel, so the chain killed the signal if instrument and note pans were hard-sided to opposites sides! In v1.1, pan_L and pan_R were still the members of Note/Instrument representing the pan knob position, still using the ratioStraightPolygonalPanLaw() for the correspondence (up to constant multiplication), but pan_L,pan_R were reconverted to single parameter in the Sampler, and fPan was used in the selected pan law.
Definition at line 257 of file Sampler.cpp.
| void handleSongSizeChange | ( | ) |
Recalculates all note starts and positions to make them valid again after the song size changed, e.g.
a pattern was inserted or it's length was changed.
Definition at line 487 of file Sampler.cpp.
| void handleTimelineOrTempoChange | ( | ) |
Recalculates all note starts to make them valid again after a TempoMarker was added to or deleted from the #Timeline or the latter was activated.
Definition at line 426 of file Sampler.cpp.
| bool isInstrumentPlaying | ( | std::shared_ptr< Instrument > | pInstr | ) |
Definition at line 1424 of file Sampler.cpp.
| bool isRenderingNotes | ( | ) | const |
Definition at line 186 of file Sampler.cpp.
|
static |
Definition at line 358 of file Sampler.cpp.
|
static |
Definition at line 307 of file Sampler.cpp.
|
static |
Definition at line 312 of file Sampler.cpp.
|
static |
Definition at line 298 of file Sampler.cpp.
| void midiKeyboardNoteOff | ( | int | key | ) |
Definition at line 229 of file Sampler.cpp.
| 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()
Definition at line 241 of file Sampler.cpp.
| void noteOn | ( | Note * | pNote | ) |
Start playing a note.
Definition at line 190 of file Sampler.cpp.
|
inlineprivate |
function to direct the computation to the selected pan law function
Definition at line 385 of file Sampler.cpp.
|
static |
Definition at line 368 of file Sampler.cpp.
|
static |
Definition at line 327 of file Sampler.cpp.
|
static |
Definition at line 333 of file Sampler.cpp.
|
static |
Definition at line 317 of file Sampler.cpp.
| void preview_instrument | ( | std::shared_ptr< Instrument > | pInstr | ) |
Definition at line 1398 of file Sampler.cpp.
| void preview_sample | ( | std::shared_ptr< Sample > | pSample, |
| int | length ) |
Preview, uses only the first layer.
Definition at line 1368 of file Sampler.cpp.
| void process | ( | uint32_t | nFrames | ) |
Definition at line 111 of file Sampler.cpp.
|
private |
Definition at line 803 of file Sampler.cpp.
|
static |
Definition at line 363 of file Sampler.cpp.
|
static |
Definition at line 348 of file Sampler.cpp.
|
static |
Definition at line 353 of file Sampler.cpp.
|
static |
Definition at line 339 of file Sampler.cpp.
|
static |
Definition at line 375 of file Sampler.cpp.
|
static |
Definition at line 280 of file Sampler.cpp.
|
static |
Definition at line 289 of file Sampler.cpp.
|
static |
Definition at line 271 of file Sampler.cpp.
| void reinitializePlaybackTrack | ( | ) |
Loading of the playback track.
The playback track is added to m_pPlaybackTrackInstrument as a new InstrumentLayer containing the loaded Sample. If Song::__playback_track_filename is empty, the layer will be loaded with a nullptr instead.
Definition at line 1436 of file Sampler.cpp.
|
private |
Render a note.
Definition at line 517 of file Sampler.cpp.
|
private |
Definition at line 993 of file Sampler.cpp.
|
inline |
| void stopPlayingNotes | ( | std::shared_ptr< Instrument > | pInstr = nullptr | ) |
Definition at line 1341 of file Sampler.cpp.
|
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
|
private |
|
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.
|
private |
Instrument used for the playback track feature.
|
private |
Instrument used for the preview feature.