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

Banish all locks #1053

Merged
merged 4 commits into from
Aug 16, 2014
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
6 changes: 4 additions & 2 deletions include/EnvelopeAndLfoParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
*
*/

#ifndef _ENVELOPE_AND_LFO_PARAMETERS_H
#define _ENVELOPE_AND_LFO_PARAMETERS_H
#ifndef ENVELOPE_AND_LFO_PARAMETERS_H
#define ENVELOPE_AND_LFO_PARAMETERS_H

#include <QtCore/QVector>

Expand Down Expand Up @@ -138,6 +138,8 @@ public slots:
f_cnt_t m_rFrames;
sample_t * m_pahdEnv;
sample_t * m_rEnv;
f_cnt_t m_pahdBufSize;
f_cnt_t m_rBufSize;


FloatModel m_lfoPredelayModel;
Expand Down
2 changes: 2 additions & 0 deletions include/InstrumentTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ protected slots:
QMutex m_notesMutex;

int m_runningMidiNotes[NumKeys];
QMutex m_midiNotesMutex;

bool m_sustainPedalPressed;

bool m_silentBuffersProcessed;
Expand Down
13 changes: 12 additions & 1 deletion include/Mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,16 @@ class EXPORT Mixer : public QObject
{
m_inputFramesMutex.unlock();
}

void lockPlayHandleRemoval()
{
m_playHandleRemovalMutex.lock();
}

void unlockPlayHandleRemoval()
{
m_playHandleRemovalMutex.unlock();
}

// audio-buffer-mgm
void bufferToPort( const sampleFrame * _buf,
Expand Down Expand Up @@ -449,7 +459,8 @@ class EXPORT Mixer : public QObject

QMutex m_globalMutex;
QMutex m_inputFramesMutex;


QMutex m_playHandleRemovalMutex;

fifo * m_fifo;
fifoWriter * m_fifoWriter;
Expand Down
3 changes: 2 additions & 1 deletion include/NotePlayHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ class EXPORT NotePlayHandle : public PlayHandle, public note
// release of note
NotePlayHandleList m_subNotes; // used for chords and arpeggios
volatile bool m_released; // indicates whether note is released
bool m_hasParent;
bool m_hasParent; // indicates whether note has parent
NotePlayHandle * m_parent; // parent note
bool m_hadChildren;
bool m_muted; // indicates whether note is muted
track* m_bbTrack; // related BB track
Expand Down
15 changes: 14 additions & 1 deletion include/PlayHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <QtCore/QThread>
#include <QtCore/QVector>
#include <QtCore/QMutex>

#include "ThreadableJob.h"
#include "lmms_basics.h"
Expand Down Expand Up @@ -84,7 +85,18 @@ class PlayHandle : public ThreadableJob
return !isFinished();
}


void lock()
{
m_processingLock.lock();
}
void unlock()
{
m_processingLock.unlock();
}
bool tryLock()
{
return m_processingLock.tryLock();
}
virtual void play( sampleFrame* buffer ) = 0;
virtual bool isFinished( void ) const = 0;

Expand All @@ -108,6 +120,7 @@ class PlayHandle : public ThreadableJob
Type m_type;
f_cnt_t m_offset;
const QThread* m_affinity;
QMutex m_processingLock;

} ;

Expand Down
15 changes: 14 additions & 1 deletion include/track.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class trackContentObject : public Model, public JournallingObject
{
return m_length;
}

virtual void movePosition( const MidiTime & _pos );
virtual void changeLength( const MidiTime & _length );

Expand Down Expand Up @@ -508,6 +508,18 @@ class EXPORT track : public Model, public JournallingObject
m_height = _height;
}

void lock()
{
m_processingLock.lock();
}
void unlock()
{
m_processingLock.unlock();
}
bool tryLock()
{
return m_processingLock.tryLock();
}

public slots:
virtual void setName( const QString & _new_name )
Expand All @@ -533,6 +545,7 @@ public slots:

tcoVector m_trackContentObjects;

QMutex m_processingLock;

friend class trackView;

Expand Down
28 changes: 19 additions & 9 deletions src/core/EnvelopeAndLfoParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,12 @@ EnvelopeAndLfoParameters::EnvelopeAndLfoParameters(
m_releaseModel( 0.1, 0.0, 2.0, 0.001, this, tr( "Release" ) ),
m_amountModel( 0.0, -1.0, 1.0, 0.005, this, tr( "Modulation" ) ),
m_valueForZeroAmount( _value_for_zero_amount ),
m_pahdFrames( 0 ),
m_rFrames( 0 ),
m_pahdEnv( NULL ),
m_rEnv( NULL ),
m_pahdBufSize( 0 ),
m_rBufSize( 0 ),
m_lfoPredelayModel( 0.0, 0.0, 1.0, 0.001, this, tr( "LFO Predelay" ) ),
m_lfoAttackModel( 0.0, 0.0, 1.0, 0.001, this, tr( "LFO Attack" ) ),
m_lfoSpeedModel( 0.1, 0.001, 1.0, 0.0001,
Expand Down Expand Up @@ -399,8 +403,6 @@ void EnvelopeAndLfoParameters::loadSettings( const QDomElement & _this )

void EnvelopeAndLfoParameters::updateSampleVars()
{
engine::mixer()->lock();

const float frames_per_env_seg = SECS_PER_ENV_SEGMENT *
engine::mixer()->processingSampleRate();
// TODO: Remove the expKnobVals, time should be linear
Expand Down Expand Up @@ -436,15 +438,24 @@ void EnvelopeAndLfoParameters::updateSampleVars()

if( static_cast<int>( floorf( m_amount * 1000.0f ) ) == 0 )
{
//m_pahdFrames = 0;
m_rFrames = 0;
}

delete[] m_pahdEnv;
delete[] m_rEnv;

m_pahdEnv = new sample_t[m_pahdFrames];
m_rEnv = new sample_t[m_rFrames];
// if the buffers are too small, make bigger ones - so we only alloc new memory when necessary
if( m_pahdBufSize < m_pahdFrames )
{
sample_t * tmp = m_pahdEnv;
m_pahdEnv = new sample_t[m_pahdFrames];
delete tmp;
m_pahdBufSize = m_pahdFrames;
}
if( m_rBufSize < m_rFrames )
{
sample_t * tmp = m_rEnv;
m_rEnv = new sample_t[m_rFrames];
delete tmp;
m_rBufSize = m_rFrames;
}

const float aa = m_amountAdd;
for( f_cnt_t i = 0; i < predelay_frames; ++i )
Expand Down Expand Up @@ -523,7 +534,6 @@ void EnvelopeAndLfoParameters::updateSampleVars()

emit dataChanged();

engine::mixer()->unlock();
}


Expand Down
49 changes: 13 additions & 36 deletions src/core/InstrumentSoundShaping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ InstrumentSoundShaping::InstrumentSoundShaping(
m_filterModel.addItem( tr( "RC LowPass 24dB" ), new PixmapLoader( "filter_lp" ) );
m_filterModel.addItem( tr( "RC BandPass 24dB" ), new PixmapLoader( "filter_bp" ) );
m_filterModel.addItem( tr( "RC HighPass 24dB" ), new PixmapLoader( "filter_hp" ) );
m_filterModel.addItem( tr( "Vocal Formant Filter" ), new PixmapLoader( "filter_hp" ) );
m_filterModel.addItem( tr( "Vocal Formant Filter" ), new PixmapLoader( "filter_hp" ) );
}


Expand Down Expand Up @@ -146,6 +146,9 @@ void InstrumentSoundShaping::processAudioBuffer( sampleFrame* buffer,

if( m_filterEnabledModel.value() )
{
float cutBuffer [frames];
float resBuffer [frames];

int old_filter_cut = 0;
int old_filter_res = 0;

Expand All @@ -155,27 +158,13 @@ void InstrumentSoundShaping::processAudioBuffer( sampleFrame* buffer,
}
n->m_filter->setFilterType( m_filterModel.value() );

#ifdef __GNUC__
float cut_buf[frames];
float res_buf[frames];
#else
float * cut_buf = NULL;
float * res_buf = NULL;
#endif

if( m_envLfoParameters[Cut]->isUsed() )
{
#ifndef __GNUC__
cut_buf = new float[frames];
#endif
m_envLfoParameters[Cut]->fillLevel( cut_buf, envTotalFrames, envReleaseBegin, frames );
m_envLfoParameters[Cut]->fillLevel( cutBuffer, envTotalFrames, envReleaseBegin, frames );
}
if( m_envLfoParameters[Resonance]->isUsed() )
{
#ifndef __GNUC__
res_buf = new float[frames];
#endif
m_envLfoParameters[Resonance]->fillLevel( res_buf, envTotalFrames, envReleaseBegin, frames );
m_envLfoParameters[Resonance]->fillLevel( resBuffer, envTotalFrames, envReleaseBegin, frames );
}

const float fcv = m_filterCutModel.value();
Expand All @@ -186,10 +175,10 @@ void InstrumentSoundShaping::processAudioBuffer( sampleFrame* buffer,
{
for( fpp_t frame = 0; frame < frames; ++frame )
{
const float new_cut_val = EnvelopeAndLfoParameters::expKnobVal( cut_buf[frame] ) *
const float new_cut_val = EnvelopeAndLfoParameters::expKnobVal( cutBuffer[frame] ) *
CUT_FREQ_MULTIPLIER + fcv;

const float new_res_val = frv + RES_MULTIPLIER * res_buf[frame];
const float new_res_val = frv + RES_MULTIPLIER * resBuffer[frame];

if( static_cast<int>( new_cut_val ) != old_filter_cut ||
static_cast<int>( new_res_val*RES_PRECISION ) != old_filter_res )
Expand All @@ -207,7 +196,7 @@ void InstrumentSoundShaping::processAudioBuffer( sampleFrame* buffer,
{
for( fpp_t frame = 0; frame < frames; ++frame )
{
float new_cut_val = EnvelopeAndLfoParameters::expKnobVal( cut_buf[frame] ) *
float new_cut_val = EnvelopeAndLfoParameters::expKnobVal( cutBuffer[frame] ) *
CUT_FREQ_MULTIPLIER + fcv;

if( static_cast<int>( new_cut_val ) != old_filter_cut )
Expand All @@ -224,7 +213,7 @@ void InstrumentSoundShaping::processAudioBuffer( sampleFrame* buffer,
{
for( fpp_t frame = 0; frame < frames; ++frame )
{
float new_res_val = frv + RES_MULTIPLIER * res_buf[frame];
float new_res_val = frv + RES_MULTIPLIER * resBuffer[frame];

if( static_cast<int>( new_res_val*RES_PRECISION ) != old_filter_res )
{
Expand All @@ -246,32 +235,20 @@ void InstrumentSoundShaping::processAudioBuffer( sampleFrame* buffer,
buffer[frame][1] = n->m_filter->update( buffer[frame][1], 1 );
}
}

#ifndef __GNUC__
delete[] cut_buf;
delete[] res_buf;
#endif
}

if( m_envLfoParameters[Volume]->isUsed() )
{
#ifdef __GNUC__
float vol_buf[frames];
#else
float * vol_buf = new float[frames];
#endif
m_envLfoParameters[Volume]->fillLevel( vol_buf, envTotalFrames, envReleaseBegin, frames );
float volBuffer [frames];
m_envLfoParameters[Volume]->fillLevel( volBuffer, envTotalFrames, envReleaseBegin, frames );

for( fpp_t frame = 0; frame < frames; ++frame )
{
float vol_level = vol_buf[frame];
float vol_level = volBuffer[frame];
vol_level = vol_level * vol_level;
buffer[frame][0] = vol_level * buffer[frame][0];
buffer[frame][1] = vol_level * buffer[frame][1];
}
#ifndef __GNUC__
delete[] vol_buf;
#endif
}

/* else if( m_envLfoParameters[Volume]->isUsed() == false && m_envLfoParameters[PANNING]->isUsed() )
Expand Down
Loading