Skip to content

Commit

Permalink
Optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
chn-dev committed Sep 4, 2024
1 parent 96f9128 commit 6d61256
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
38 changes: 28 additions & 10 deletions src/SamplerEngine/Voice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,27 @@ double Voice::getPanning() const
}


/*----------------------------------------------------------------------------*/
/*! 2024-09-04
Retrieve the current amplitude for the left and right channel, taking into
account any modulations.
\param lAmp Reference to the double variable to retrieve the left channel's amp
\param rAmp Reference to the double variable to retrieve the right channel't amp
*/
/*----------------------------------------------------------------------------*/
void Voice::getLRAmp( double &lAmp, double &rAmp ) const
{
double panning = getPanning();
lAmp = getLeftAmp( panning ) * m_pSample->getGain();
rAmp = getRightAmp( panning ) * m_pSample->getGain();
if( m_pSample->getPlayMode() != Sample::PlayModeShot )
{
lAmp *= m_pAEG->getValue();
rAmp *= m_pAEG->getValue();
}
}


/*----------------------------------------------------------------------------*/
/*! 2024-06-28
Process the voice.
Expand Down Expand Up @@ -370,6 +391,10 @@ bool Voice::process( float *pL, float *pR, size_t nSamples, double sampleRate, d
m_LFOs[i]->getSettings( *m_pSample->getLFO( i ) );
}

double lAmp;
double rAmp;
getLRAmp( lAmp, rAmp );

for( size_t i = 0; i < nSamples; i++ )
{
if( !handleLoop() )
Expand All @@ -379,15 +404,8 @@ bool Voice::process( float *pL, float *pR, size_t nSamples, double sampleRate, d
{
if( m_pAEG->hasEnded() && m_pSample->getPlayMode() != Sample::PlayModeShot )
return( false );
}

double panning = getPanning();
double lAmp = getLeftAmp( panning ) * m_pSample->getGain();
double rAmp = getRightAmp( panning ) * m_pSample->getGain();
if( m_pSample->getPlayMode() != Sample::PlayModeShot )
{
lAmp *= m_pAEG->getValue();
rAmp *= m_pAEG->getValue();
getLRAmp( lAmp, rAmp );
}

int o = (int)m_Ofs;
Expand Down Expand Up @@ -420,7 +438,7 @@ Convert a panning value to a gain value for the left channel
\return Left channel's gain value
*/
/*----------------------------------------------------------------------------*/
double Voice::getLeftAmp( double pan )
double Voice::getLeftAmp( double pan ) const
{
if( pan < -1.0f )
pan = -1.0f;
Expand All @@ -447,7 +465,7 @@ Convert a panning value to a gain value for the right channel
\return Right channel's gain value
*/
/*----------------------------------------------------------------------------*/
double Voice::getRightAmp( double pan )
double Voice::getRightAmp( double pan ) const
{
if( pan < -1.0f )
pan = -1.0f;
Expand Down
5 changes: 3 additions & 2 deletions src/SamplerEngine/Voice.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ namespace SamplerEngine

private:
double getPanning() const;
double getLeftAmp( double pan );
double getRightAmp( double pan );
double getLeftAmp( double pan ) const;
double getRightAmp( double pan ) const;
void getLRAmp( double &lAmp, double &rAmp ) const;

const Part *m_pPart;
const Sample *m_pSample;
Expand Down
7 changes: 7 additions & 0 deletions src/SamplerEngine/WaveFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ WaveFile *WaveFile::fromXml( xmlNode *pe )
}


/*----------------------------------------------------------------------------*/
/*! 2024-09-04
\return A lambda function
[]( const WaveFile, int nChannel, uint32_t nSample )
for reading a float sample value from a WaveFile object.
*/
/*----------------------------------------------------------------------------*/
std::function<float( const WaveFile *, int, uint32_t )> WaveFile::getToFloatLambdaFunction() const
{

Expand Down

0 comments on commit 6d61256

Please sign in to comment.