-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce allocations to improve performance. #3868
Changes from all commits
ed24343
0a9aba9
474b042
7d6745f
316be79
01fcab8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -233,8 +233,9 @@ void organicInstrument::playNote( NotePlayHandle * _n, | |
|
||
if( _n->totalFramesPlayed() == 0 || _n->m_pluginData == NULL ) | ||
{ | ||
Oscillator * oscs_l[m_numOscillators]; | ||
Oscillator * oscs_r[m_numOscillators]; | ||
Oscillator * oscs_all = MM_ALLOC( Oscillator, m_numOscillators*2 ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seeing that Oscillator* oscs_all = new Oscillator[m_numOscillators * 2] |
||
Oscillator * oscs_l = oscs_all; | ||
Oscillator * oscs_r = oscs_all + m_numOscillators; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this alternative is clearer to readers, but I'll leave it up to you Oscillator * oscs_l = & oscs_all[0];
Oscillator * oscs_r = & oscs_all[m_numOscillators]; |
||
|
||
_n->m_pluginData = new oscPtr; | ||
|
||
|
@@ -250,15 +251,15 @@ void organicInstrument::playNote( NotePlayHandle * _n, | |
if( i == m_numOscillators - 1 ) | ||
{ | ||
// create left oscillator | ||
oscs_l[i] = new Oscillator( | ||
new (&oscs_l[i]) Oscillator( | ||
&m_osc[i]->m_waveShape, | ||
&m_modulationAlgo, | ||
_n->frequency(), | ||
m_osc[i]->m_detuningLeft, | ||
static_cast<oscPtr *>( _n->m_pluginData )->phaseOffsetLeft[i], | ||
m_osc[i]->m_volumeLeft ); | ||
// create right oscillator | ||
oscs_r[i] = new Oscillator( | ||
new (&oscs_r[i]) Oscillator( | ||
&m_osc[i]->m_waveShape, | ||
&m_modulationAlgo, | ||
_n->frequency(), | ||
|
@@ -269,30 +270,30 @@ void organicInstrument::playNote( NotePlayHandle * _n, | |
else | ||
{ | ||
// create left oscillator | ||
oscs_l[i] = new Oscillator( | ||
new (&oscs_l[i]) Oscillator( | ||
&m_osc[i]->m_waveShape, | ||
&m_modulationAlgo, | ||
_n->frequency(), | ||
m_osc[i]->m_detuningLeft, | ||
static_cast<oscPtr *>( _n->m_pluginData )->phaseOffsetLeft[i], | ||
m_osc[i]->m_volumeLeft, | ||
oscs_l[i + 1] ); | ||
&oscs_l[i + 1] ); | ||
// create right oscillator | ||
oscs_r[i] = new Oscillator( | ||
new (&oscs_r[i]) Oscillator( | ||
&m_osc[i]->m_waveShape, | ||
&m_modulationAlgo, | ||
_n->frequency(), | ||
m_osc[i]->m_detuningRight, | ||
static_cast<oscPtr *>( _n->m_pluginData )->phaseOffsetRight[i], | ||
m_osc[i]->m_volumeRight, | ||
oscs_r[i + 1] ); | ||
&oscs_r[i + 1] ); | ||
} | ||
|
||
|
||
} | ||
|
||
static_cast<oscPtr *>( _n->m_pluginData )->oscLeft = oscs_l[0]; | ||
static_cast<oscPtr *>( _n->m_pluginData )->oscRight = oscs_r[0]; | ||
static_cast<oscPtr *>( _n->m_pluginData )->oscLeft = &oscs_l[0]; | ||
static_cast<oscPtr *>( _n->m_pluginData )->oscRight = &oscs_r[0]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
Oscillator * osc_l = static_cast<oscPtr *>( _n->m_pluginData )->oscLeft; | ||
|
@@ -325,11 +326,7 @@ void organicInstrument::playNote( NotePlayHandle * _n, | |
|
||
void organicInstrument::deleteNotePluginData( NotePlayHandle * _n ) | ||
{ | ||
delete static_cast<Oscillator *>( static_cast<oscPtr *>( | ||
_n->m_pluginData )->oscLeft ); | ||
delete static_cast<Oscillator *>( static_cast<oscPtr *>( | ||
_n->m_pluginData )->oscRight ); | ||
|
||
MM_FREE( static_cast<oscPtr *>(_n->m_pluginData )->oscLeft); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In analogy to the allocation, this should be written as delete[] static_cast<oscPtr *>(_n->m_pluginData )->oscLeft Using |
||
delete static_cast<oscPtr *>( _n->m_pluginData ); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -300,23 +300,24 @@ void TripleOscillator::playNote( NotePlayHandle * _n, | |
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comments apply to |
||
if( _n->totalFramesPlayed() == 0 || _n->m_pluginData == NULL ) | ||
{ | ||
Oscillator * oscs_l[NUM_OF_OSCILLATORS]; | ||
Oscillator * oscs_r[NUM_OF_OSCILLATORS]; | ||
auto allOscs = MM_ALLOC( Oscillator, NUM_OF_OSCILLATORS*2 ); | ||
Oscillator * oscs_l = allOscs; | ||
Oscillator * oscs_r = allOscs + NUM_OF_OSCILLATORS; | ||
|
||
for( int i = NUM_OF_OSCILLATORS - 1; i >= 0; --i ) | ||
{ | ||
|
||
// the last oscs needs no sub-oscs... | ||
if( i == NUM_OF_OSCILLATORS - 1 ) | ||
{ | ||
oscs_l[i] = new Oscillator( | ||
new (&oscs_l[i]) Oscillator( | ||
&m_osc[i]->m_waveShapeModel, | ||
&m_osc[i]->m_modulationAlgoModel, | ||
_n->frequency(), | ||
m_osc[i]->m_detuningLeft, | ||
m_osc[i]->m_phaseOffsetLeft, | ||
m_osc[i]->m_volumeLeft ); | ||
oscs_r[i] = new Oscillator( | ||
new (&oscs_r[i])Oscillator( | ||
&m_osc[i]->m_waveShapeModel, | ||
&m_osc[i]->m_modulationAlgoModel, | ||
_n->frequency(), | ||
|
@@ -326,33 +327,32 @@ void TripleOscillator::playNote( NotePlayHandle * _n, | |
} | ||
else | ||
{ | ||
oscs_l[i] = new Oscillator( | ||
new (&oscs_l[i]) Oscillator( | ||
&m_osc[i]->m_waveShapeModel, | ||
&m_osc[i]->m_modulationAlgoModel, | ||
_n->frequency(), | ||
m_osc[i]->m_detuningLeft, | ||
m_osc[i]->m_phaseOffsetLeft, | ||
m_osc[i]->m_volumeLeft, | ||
oscs_l[i + 1] ); | ||
oscs_r[i] = new Oscillator( | ||
&oscs_l[i + 1] ); | ||
new (&oscs_r[i]) Oscillator( | ||
&m_osc[i]->m_waveShapeModel, | ||
&m_osc[i]->m_modulationAlgoModel, | ||
_n->frequency(), | ||
m_osc[i]->m_detuningRight, | ||
m_osc[i]->m_phaseOffsetRight, | ||
m_osc[i]->m_volumeRight, | ||
oscs_r[i + 1] ); | ||
&oscs_r[i + 1] ); | ||
} | ||
|
||
oscs_l[i]->setUserWave( m_osc[i]->m_sampleBuffer ); | ||
oscs_r[i]->setUserWave( m_osc[i]->m_sampleBuffer ); | ||
oscs_l[i].setUserWave( m_osc[i]->m_sampleBuffer ); | ||
oscs_r[i].setUserWave( m_osc[i]->m_sampleBuffer ); | ||
|
||
} | ||
|
||
_n->m_pluginData = new oscPtr; | ||
static_cast<oscPtr *>( _n->m_pluginData )->oscLeft = oscs_l[0]; | ||
static_cast< oscPtr *>( _n->m_pluginData )->oscRight = | ||
oscs_r[0]; | ||
static_cast<oscPtr *>( _n->m_pluginData )->oscLeft = &oscs_l[0]; | ||
static_cast<oscPtr *>( _n->m_pluginData )->oscRight = &oscs_r[0]; | ||
} | ||
|
||
Oscillator * osc_l = static_cast<oscPtr *>( _n->m_pluginData )->oscLeft; | ||
|
@@ -374,10 +374,9 @@ void TripleOscillator::playNote( NotePlayHandle * _n, | |
|
||
void TripleOscillator::deleteNotePluginData( NotePlayHandle * _n ) | ||
{ | ||
delete static_cast<Oscillator *>( static_cast<oscPtr *>( | ||
_n->m_pluginData )->oscLeft ); | ||
delete static_cast<Oscillator *>( static_cast<oscPtr *>( | ||
_n->m_pluginData )->oscRight ); | ||
auto ptr = static_cast<oscPtr*>(_n->m_pluginData)->oscLeft; | ||
//It is safe to simply free the oscillators because they don't own anything. | ||
MM_FREE( ptr ); | ||
delete static_cast<oscPtr *>( _n->m_pluginData ); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this override needed? Isn't this the default implementation?