Skip to content
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

(Re)move identical calls to InstrumentTrack::processAudioBuffer #6867

Merged
merged 5 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 7 additions & 36 deletions include/InstrumentPlayHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,62 +26,33 @@
#define LMMS_INSTRUMENT_PLAY_HANDLE_H

#include "PlayHandle.h"
#include "Instrument.h"
#include "NotePlayHandle.h"
#include "lmms_export.h"

namespace lmms
{

class Instrument;
class InstrumentTrack;

class LMMS_EXPORT InstrumentPlayHandle : public PlayHandle
{
public:
InstrumentPlayHandle( Instrument * instrument, InstrumentTrack* instrumentTrack );
InstrumentPlayHandle(Instrument * instrument, InstrumentTrack* instrumentTrack);

~InstrumentPlayHandle() override = default;


void play( sampleFrame * _working_buffer ) override
{
// ensure that all our nph's have been processed first
ConstNotePlayHandleList nphv = NotePlayHandle::nphsOfInstrumentTrack( m_instrument->instrumentTrack(), true );

bool nphsLeft;
do
{
nphsLeft = false;
for( const NotePlayHandle * constNotePlayHandle : nphv )
{
NotePlayHandle * notePlayHandle = const_cast<NotePlayHandle *>( constNotePlayHandle );
if( notePlayHandle->state() != ThreadableJob::ProcessingState::Done &&
!notePlayHandle->isFinished())
{
nphsLeft = true;
notePlayHandle->process();
}
}
}
while( nphsLeft );

m_instrument->play( _working_buffer );
}
void play(sampleFrame * working_buffer) override;

bool isFinished() const override
{
return false;
}

bool isFromTrack( const Track* _track ) const override
{
return m_instrument->isFromTrack( _track );
}

bool isFromTrack(const Track* track) const override;

private:
Instrument* m_instrument;

} ;

};

} // namespace lmms

Expand Down
3 changes: 0 additions & 3 deletions plugins/AudioFileProcessor/AudioFileProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,6 @@ void AudioFileProcessor::playNote( NotePlayHandle * _n,
static_cast<SampleBuffer::LoopMode>( m_loopModel.value() ) ) )
{
applyRelease( _working_buffer, _n );
instrumentTrack()->processAudioBuffer( _working_buffer,
frames + offset, _n );

emit isPlaying( ((handleState *)_n->m_pluginData)->frameIndex() );
}
else
Expand Down
2 changes: 0 additions & 2 deletions plugins/BitInvader/BitInvader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,6 @@ void BitInvader::playNote( NotePlayHandle * _n,
}

applyRelease( _working_buffer, _n );

instrumentTrack()->processAudioBuffer( _working_buffer, frames + offset, _n );
}


Expand Down
3 changes: 0 additions & 3 deletions plugins/CarlaBase/Carla.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,6 @@ void CarlaInstrument::play(sampleFrame* workingBuffer)

if (fHandle == nullptr)
{
instrumentTrack()->processAudioBuffer(workingBuffer, bufsize, nullptr);
return;
}

Expand Down Expand Up @@ -556,8 +555,6 @@ void CarlaInstrument::play(sampleFrame* workingBuffer)
workingBuffer[i][0] = buf1[i];
workingBuffer[i][1] = buf2[i];
}

instrumentTrack()->processAudioBuffer(workingBuffer, bufsize, nullptr);
}

bool CarlaInstrument::handleMidiEvent(const MidiEvent& event, const TimePos&, f_cnt_t offset)
Expand Down
1 change: 0 additions & 1 deletion plugins/FreeBoy/FreeBoy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@ void FreeBoyInstrument::playNote(NotePlayHandle* nph, sampleFrame* workingBuffer
}
framesLeft -= count;
}
instrumentTrack()->processAudioBuffer(workingBuffer, frames + offset, nph);
}


Expand Down
2 changes: 0 additions & 2 deletions plugins/GigPlayer/GigPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,6 @@ void GigInstrument::play( sampleFrame * _working_buffer )
_working_buffer[i][0] *= m_gain.value();
_working_buffer[i][1] *= m_gain.value();
}

instrumentTrack()->processAudioBuffer( _working_buffer, frames, nullptr );
}


Expand Down
2 changes: 0 additions & 2 deletions plugins/Kicker/Kicker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,6 @@ void KickerInstrument::playNote( NotePlayHandle * _n,
_working_buffer[f+offset][1] *= fac;
}
}

instrumentTrack()->processAudioBuffer( _working_buffer, frames + offset, _n );
}


Expand Down
1 change: 0 additions & 1 deletion plugins/Lb302/Lb302.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,6 @@ void Lb302Synth::play( sampleFrame * _working_buffer )
const fpp_t frames = Engine::audioEngine()->framesPerPeriod();

process( _working_buffer, frames );
instrumentTrack()->processAudioBuffer( _working_buffer, frames, nullptr );
// release_frame = 0; //removed for issue # 1432
}

Expand Down
2 changes: 0 additions & 2 deletions plugins/Lv2Instrument/Lv2Instrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,6 @@ void Lv2Instrument::play(sampleFrame *buf)

copyModelsToLmms();
copyBuffersToLmms(buf, fpp);

instrumentTrack()->processAudioBuffer(buf, fpp, nullptr);
}


Expand Down
2 changes: 0 additions & 2 deletions plugins/Monstro/Monstro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1040,8 +1040,6 @@ void MonstroInstrument::playNote( NotePlayHandle * _n,
ms->renderOutput( frames, _working_buffer + offset );

//applyRelease( _working_buffer, _n ); // we have our own release

instrumentTrack()->processAudioBuffer( _working_buffer, frames + offset, _n );
}

void MonstroInstrument::deleteNotePluginData( NotePlayHandle * _n )
Expand Down
2 changes: 0 additions & 2 deletions plugins/Nes/Nes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,6 @@ void NesInstrument::playNote( NotePlayHandle * n, sampleFrame * workingBuffer )
nes->renderOutput( workingBuffer + offset, frames );

applyRelease( workingBuffer, n );

instrumentTrack()->processAudioBuffer( workingBuffer, frames + offset, n );
}


Expand Down
4 changes: 0 additions & 4 deletions plugins/OpulenZ/OpulenZ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,6 @@ void OpulenzInstrument::play( sampleFrame * _working_buffer )
}
}
emulatorMutex.unlock();

// Throw the data to the track...
instrumentTrack()->processAudioBuffer( _working_buffer, frameCount, nullptr );

}


Expand Down
2 changes: 0 additions & 2 deletions plugins/Organic/Organic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,6 @@ void OrganicInstrument::playNote( NotePlayHandle * _n,
}

// -- --

instrumentTrack()->processAudioBuffer( _working_buffer, frames + offset, _n );
}


Expand Down
2 changes: 0 additions & 2 deletions plugins/Patman/Patman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,6 @@ void PatmanInstrument::playNote( NotePlayHandle * _n,
play_freq, m_loopedModel.value() ? SampleBuffer::LoopMode::On : SampleBuffer::LoopMode::Off ) )
{
applyRelease( _working_buffer, _n );
instrumentTrack()->processAudioBuffer( _working_buffer,
frames + offset, _n );
}
else
{
Expand Down
2 changes: 0 additions & 2 deletions plugins/Sf2Player/Sf2Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,6 @@ void Sf2Instrument::play( sampleFrame * _working_buffer )
if( m_playingNotes.isEmpty() )
{
renderFrames( frames, _working_buffer );
instrumentTrack()->processAudioBuffer( _working_buffer, frames, nullptr );
return;
}

Expand Down Expand Up @@ -906,7 +905,6 @@ void Sf2Instrument::play( sampleFrame * _working_buffer )
{
renderFrames( frames - currentFrame, _working_buffer + currentFrame );
}
instrumentTrack()->processAudioBuffer( _working_buffer, frames, nullptr );
}


Expand Down
3 changes: 0 additions & 3 deletions plugins/Sfxr/Sfxr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,6 @@ void SfxrInstrument::playNote( NotePlayHandle * _n, sampleFrame * _working_buffe
delete[] pitchedBuffer;

applyRelease( _working_buffer, _n );

instrumentTrack()->processAudioBuffer( _working_buffer, frameNum + offset, _n );

}


Expand Down
2 changes: 0 additions & 2 deletions plugins/Sid/SidInstrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,6 @@ void SidInstrument::playNote( NotePlayHandle * _n,
_working_buffer[frame+offset][ch] = s;
}
}

instrumentTrack()->processAudioBuffer( _working_buffer, frames + offset, _n );
}


Expand Down
2 changes: 0 additions & 2 deletions plugins/Stk/Mallets/Mallets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,6 @@ void MalletsInstrument::playNote( NotePlayHandle * _n,
_working_buffer[frame][1] = ps->nextSampleRight() *
( m_scalers[p] + add_scale );
}

instrumentTrack()->processAudioBuffer( _working_buffer, frames + offset, _n );
}


Expand Down
2 changes: 0 additions & 2 deletions plugins/TripleOscillator/TripleOscillator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,6 @@ void TripleOscillator::playNote( NotePlayHandle * _n,

applyFadeIn(_working_buffer, _n);
applyRelease( _working_buffer, _n );

instrumentTrack()->processAudioBuffer( _working_buffer, frames + offset, _n );
}


Expand Down
4 changes: 0 additions & 4 deletions plugins/Vestige/Vestige.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,6 @@ void VestigeInstrument::play( sampleFrame * _buf )
{
if (!m_pluginMutex.tryLock(Engine::getSong()->isExporting() ? -1 : 0)) {return;}

const fpp_t frames = Engine::audioEngine()->framesPerPeriod();

if( m_plugin == nullptr )
{
m_pluginMutex.unlock();
Expand All @@ -409,8 +407,6 @@ void VestigeInstrument::play( sampleFrame * _buf )

m_plugin->process( nullptr, _buf );

instrumentTrack()->processAudioBuffer( _buf, frames, nullptr );

m_pluginMutex.unlock();
}

Expand Down
2 changes: 0 additions & 2 deletions plugins/Vibed/Vibed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,6 @@ void Vibed::playNote(NotePlayHandle* n, sampleFrame* workingBuffer)
}
}
}

instrumentTrack()->processAudioBuffer(workingBuffer, frames + offset, n);
}

void Vibed::deleteNotePluginData(NotePlayHandle* n)
Expand Down
2 changes: 0 additions & 2 deletions plugins/Watsyn/Watsyn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,6 @@ void WatsynInstrument::playNote( NotePlayHandle * _n,
}

applyRelease( _working_buffer, _n );

instrumentTrack()->processAudioBuffer( _working_buffer, frames + offset, _n );
}


Expand Down
2 changes: 0 additions & 2 deletions plugins/Xpressive/Xpressive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,6 @@ void Xpressive::playNote(NotePlayHandle* nph, sampleFrame* working_buffer) {
const f_cnt_t offset = nph->noteOffset();

ps->renderOutput(frames, working_buffer + offset);

instrumentTrack()->processAudioBuffer(working_buffer, frames + offset, nph);
}

void Xpressive::deleteNotePluginData(NotePlayHandle* nph) {
Expand Down
1 change: 0 additions & 1 deletion plugins/ZynAddSubFx/ZynAddSubFx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,6 @@ void ZynAddSubFxInstrument::play( sampleFrame * _buf )
m_plugin->processAudio( _buf );
}
m_pluginMutex.unlock();
instrumentTrack()->processAudioBuffer( _buf, Engine::audioEngine()->framesPerPeriod(), nullptr );
}


Expand Down
49 changes: 44 additions & 5 deletions src/core/InstrumentPlayHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,57 @@


#include "InstrumentPlayHandle.h"
#include "Instrument.h"
#include "InstrumentTrack.h"
#include "Engine.h"
#include "AudioEngine.h"

namespace lmms
{


InstrumentPlayHandle::InstrumentPlayHandle( Instrument * instrument, InstrumentTrack* instrumentTrack ) :
PlayHandle( Type::InstrumentPlayHandle ),
m_instrument( instrument )
InstrumentPlayHandle::InstrumentPlayHandle(Instrument * instrument, InstrumentTrack* instrumentTrack) :
PlayHandle(Type::InstrumentPlayHandle),
m_instrument(instrument)
{
setAudioPort( instrumentTrack->audioPort() );
setAudioPort(instrumentTrack->audioPort());
}

void InstrumentPlayHandle::play(sampleFrame * working_buffer)
{
InstrumentTrack * instrumentTrack = m_instrument->instrumentTrack();

// ensure that all our nph's have been processed first
auto nphv = NotePlayHandle::nphsOfInstrumentTrack(instrumentTrack, true);

bool nphsLeft;
do
{
nphsLeft = false;
for (const NotePlayHandle * constNotePlayHandle : nphv)
{
if (constNotePlayHandle->state() != ThreadableJob::ProcessingState::Done &&
!constNotePlayHandle->isFinished())
{
nphsLeft = true;
NotePlayHandle * notePlayHandle = const_cast<NotePlayHandle *>(constNotePlayHandle);
notePlayHandle->process();
}
}
}
while (nphsLeft);

m_instrument->play(working_buffer);

// Process the audio buffer that the instrument has just worked on...
const fpp_t frames = Engine::audioEngine()->framesPerPeriod();
instrumentTrack->processAudioBuffer(working_buffer, frames, nullptr);
}

bool InstrumentPlayHandle::isFromTrack(const Track* track) const
{
return m_instrument->isFromTrack(track);
}


} // namespace lmms
} // namespace lmms
13 changes: 13 additions & 0 deletions src/tracks/InstrumentTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,10 @@ f_cnt_t InstrumentTrack::beatLen( NotePlayHandle * _n ) const

void InstrumentTrack::playNote( NotePlayHandle* n, sampleFrame* workingBuffer )
{
// Note: under certain circumstances the working buffer is a nullptr.
// These cases are triggered in PlayHandle::doProcessing when the play method is called with a nullptr.
// TODO: Find out if we can skip processing at a higher level if the buffer is nullptr.

// arpeggio- and chord-widget has to do its work -> adding sub-notes
// for chords/arpeggios
m_noteStacking.processNote( n );
Expand All @@ -579,6 +583,15 @@ void InstrumentTrack::playNote( NotePlayHandle* n, sampleFrame* workingBuffer )
{
// all is done, so now lets play the note!
m_instrument->playNote( n, workingBuffer );

// This is effectively the same as checking if workingBuffer is not a nullptr.
// Calling processAudioBuffer with a nullptr leads to crashes. Hence the check.
if (n->usesBuffer())
{
const fpp_t frames = n->framesLeftForCurrentPeriod();
const f_cnt_t offset = n->noteOffset();
processAudioBuffer(workingBuffer, frames + offset, n);
}
}
}

Expand Down