Huge structural changes
Well, this commit got a bit out of hand, what with 26 files changed. Oh well. Basically, we're using the buffermanager to dispense temporary buffers for playhandles and audioports to use. This allows us to change the way playhandles work. Earlier, playhandles of the same track were waiting in line to push their output to the audioport. This was of course inefficient, so now they just register themselves to the port, then the port handles mixing the buffers. Caveat: this is still a work in progress, the vol/pan knobs on instruments are temporarily non-functional - will be fixed in the next commit, but I have to get some sleep now.
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
|
||||
#include "Mixer.h"
|
||||
#include "MemoryManager.h"
|
||||
#include "PlayHandle.h"
|
||||
|
||||
class EffectChain;
|
||||
|
||||
@@ -41,38 +42,21 @@ public:
|
||||
AudioPort( const QString & _name, bool _has_effect_chain = true );
|
||||
virtual ~AudioPort();
|
||||
|
||||
inline sampleFrame * firstBuffer()
|
||||
inline sampleFrame * buffer()
|
||||
{
|
||||
return m_firstBuffer;
|
||||
return m_portBuffer;
|
||||
}
|
||||
|
||||
inline sampleFrame * secondBuffer()
|
||||
inline void lockBuffer()
|
||||
{
|
||||
return m_secondBuffer;
|
||||
m_portBufferLock.lock();
|
||||
}
|
||||
|
||||
inline void lockFirstBuffer()
|
||||
inline void unlockBuffer()
|
||||
{
|
||||
m_firstBufferLock.lock();
|
||||
m_portBufferLock.unlock();
|
||||
}
|
||||
|
||||
inline void lockSecondBuffer()
|
||||
{
|
||||
m_secondBufferLock.lock();
|
||||
}
|
||||
|
||||
inline void unlockFirstBuffer()
|
||||
{
|
||||
m_firstBufferLock.unlock();
|
||||
}
|
||||
|
||||
inline void unlockSecondBuffer()
|
||||
{
|
||||
m_secondBufferLock.unlock();
|
||||
}
|
||||
|
||||
void nextPeriod();
|
||||
|
||||
|
||||
// indicate whether JACK & Co should provide output-buffer at ext. port
|
||||
inline bool extOutputEnabled() const
|
||||
@@ -112,28 +96,20 @@ public:
|
||||
bool processEffects();
|
||||
|
||||
// ThreadableJob stuff
|
||||
virtual void doProcessing( sampleFrame * );
|
||||
virtual void doProcessing();
|
||||
virtual bool requiresProcessing() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
enum bufferUsages
|
||||
{
|
||||
NoUsage,
|
||||
FirstBuffer,
|
||||
BothBuffers
|
||||
} ;
|
||||
|
||||
void addPlayHandle( PlayHandle * handle );
|
||||
void removePlayHandle( PlayHandle * handle );
|
||||
|
||||
private:
|
||||
volatile bufferUsages m_bufferUsage;
|
||||
volatile bool m_bufferUsage;
|
||||
|
||||
sampleFrame * m_firstBuffer;
|
||||
sampleFrame * m_secondBuffer;
|
||||
QMutex m_firstBufferLock;
|
||||
QMutex m_secondBufferLock;
|
||||
sampleFrame * m_portBuffer;
|
||||
QMutex m_portBufferLock;
|
||||
|
||||
bool m_extOutputEnabled;
|
||||
fx_ch_t m_nextFxChannel;
|
||||
@@ -142,6 +118,8 @@ private:
|
||||
|
||||
EffectChain * m_effects;
|
||||
|
||||
PlayHandleList m_playHandles;
|
||||
QMutex m_playHandleLock;
|
||||
|
||||
friend class Mixer;
|
||||
friend class MixerWorkerThread;
|
||||
|
||||
@@ -34,8 +34,8 @@
|
||||
#include <QtCore/QReadWriteLock>
|
||||
|
||||
|
||||
const int BM_INITIAL_BUFFERS = 256;
|
||||
const int BM_INCREMENT = 16;
|
||||
const int BM_INITIAL_BUFFERS = 512;
|
||||
//const int BM_INCREMENT = 64;
|
||||
|
||||
class BufferManager
|
||||
{
|
||||
@@ -43,12 +43,16 @@ public:
|
||||
static void init();
|
||||
static sampleFrame * acquire();
|
||||
static void release( sampleFrame * buf );
|
||||
static void extend( int c );
|
||||
static void refresh();
|
||||
// static void extend( int c );
|
||||
|
||||
private:
|
||||
static sampleFrame ** s_available;
|
||||
static QAtomicInt s_availableIndex;
|
||||
static QReadWriteLock s_mutex;
|
||||
|
||||
static sampleFrame ** s_released;
|
||||
static QAtomicInt s_releasedIndex;
|
||||
// static QReadWriteLock s_mutex;
|
||||
static int s_size;
|
||||
};
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ class FxChannel : public ThreadableJob
|
||||
void processed();
|
||||
|
||||
private:
|
||||
virtual void doProcessing( sampleFrame * _working_buffer );
|
||||
virtual void doProcessing();
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -33,11 +33,7 @@
|
||||
class InstrumentPlayHandle : public PlayHandle
|
||||
{
|
||||
public:
|
||||
InstrumentPlayHandle( Instrument* instrument ) :
|
||||
PlayHandle( TypeInstrumentPlayHandle ),
|
||||
m_instrument( instrument )
|
||||
{
|
||||
}
|
||||
InstrumentPlayHandle( Instrument * instrument, InstrumentTrack* instrumentTrack );
|
||||
|
||||
virtual ~InstrumentPlayHandle()
|
||||
{
|
||||
@@ -88,6 +84,7 @@ public:
|
||||
|
||||
private:
|
||||
Instrument* m_instrument;
|
||||
InstrumentTrack * m_instrumentTrack;
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
@@ -321,11 +321,6 @@ public:
|
||||
}
|
||||
|
||||
// audio-buffer-mgm
|
||||
void bufferToPort( const sampleFrame * _buf,
|
||||
const fpp_t _frames,
|
||||
stereoVolumeVector _volume_vector,
|
||||
AudioPort * _port );
|
||||
|
||||
static void clearAudioBuffer( sampleFrame * _ab,
|
||||
const f_cnt_t _frames,
|
||||
const f_cnt_t _offset = 0 );
|
||||
|
||||
@@ -63,7 +63,7 @@ public:
|
||||
|
||||
void addJob( ThreadableJob * _job );
|
||||
|
||||
void run( sampleFrame * _buffer );
|
||||
void run();
|
||||
void wait();
|
||||
|
||||
private:
|
||||
@@ -115,7 +115,6 @@ private:
|
||||
static QWaitCondition * queueReadyWaitCond;
|
||||
static QList<MixerWorkerThread *> workerThreads;
|
||||
|
||||
sampleFrame * m_workingBuf;
|
||||
volatile bool m_quit;
|
||||
|
||||
} ;
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
#include "lmms_basics.h"
|
||||
|
||||
class track;
|
||||
|
||||
class AudioPort;
|
||||
|
||||
class PlayHandle : public ThreadableJob
|
||||
{
|
||||
@@ -48,12 +48,7 @@ public:
|
||||
} ;
|
||||
typedef Types Type;
|
||||
|
||||
PlayHandle( const Type type, f_cnt_t offset = 0 ) :
|
||||
m_type( type ),
|
||||
m_offset( offset ),
|
||||
m_affinity( QThread::currentThread() )
|
||||
{
|
||||
}
|
||||
PlayHandle( const Type type, f_cnt_t offset = 0 );
|
||||
|
||||
PlayHandle & operator = ( PlayHandle & p )
|
||||
{
|
||||
@@ -63,9 +58,7 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual ~PlayHandle()
|
||||
{
|
||||
}
|
||||
virtual ~PlayHandle();
|
||||
|
||||
virtual bool affinityMatters() const
|
||||
{
|
||||
@@ -83,10 +76,7 @@ public:
|
||||
}
|
||||
|
||||
// required for ThreadableJob
|
||||
virtual void doProcessing( sampleFrame* buffer )
|
||||
{
|
||||
play( buffer );
|
||||
}
|
||||
virtual void doProcessing();
|
||||
|
||||
virtual bool requiresProcessing() const
|
||||
{
|
||||
@@ -106,7 +96,7 @@ public:
|
||||
return m_processingLock.tryLock();
|
||||
}
|
||||
virtual void play( sampleFrame* buffer ) = 0;
|
||||
virtual bool isFinished( void ) const = 0;
|
||||
virtual bool isFinished() const = 0;
|
||||
|
||||
// returns the frameoffset at the start of the playhandle,
|
||||
// ie. how many empty frames should be inserted at the start of the first period
|
||||
@@ -123,12 +113,41 @@ public:
|
||||
|
||||
virtual bool isFromTrack( const track * _track ) const = 0;
|
||||
|
||||
bool usesBuffer() const
|
||||
{
|
||||
return m_usesBuffer;
|
||||
}
|
||||
|
||||
void setUsesBuffer( const bool b )
|
||||
{
|
||||
m_usesBuffer = b;
|
||||
}
|
||||
|
||||
AudioPort * audioPort()
|
||||
{
|
||||
return m_audioPort;
|
||||
}
|
||||
|
||||
void setAudioPort( AudioPort * port )
|
||||
{
|
||||
m_audioPort = port;
|
||||
}
|
||||
|
||||
void releaseBuffer();
|
||||
|
||||
sampleFrame * buffer()
|
||||
{
|
||||
return m_playHandleBuffer;
|
||||
}
|
||||
|
||||
private:
|
||||
Type m_type;
|
||||
f_cnt_t m_offset;
|
||||
QThread* m_affinity;
|
||||
QMutex m_processingLock;
|
||||
sampleFrame * m_playHandleBuffer;
|
||||
bool m_usesBuffer;
|
||||
AudioPort * m_audioPort;
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _PRESET_PREVIEW_PLAY_HANDLE_H
|
||||
#define _PRESET_PREVIEW_PLAY_HANDLE_H
|
||||
#ifndef PRESET_PREVIEW_PLAY_HANDLE_H
|
||||
#define PRESET_PREVIEW_PLAY_HANDLE_H
|
||||
|
||||
#include "NotePlayHandle.h"
|
||||
|
||||
|
||||
@@ -82,7 +82,6 @@ private:
|
||||
f_cnt_t m_frame;
|
||||
SampleBuffer::handleState m_state;
|
||||
|
||||
AudioPort * m_audioPort;
|
||||
const bool m_ownAudioPort;
|
||||
|
||||
FloatModel m_defaultVolumeModel;
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _THREADABLE_JOB_H
|
||||
#define _THREADABLE_JOB_H
|
||||
#ifndef THREADABLE_JOB_H
|
||||
#define THREADABLE_JOB_H
|
||||
|
||||
#include <QtCore/QAtomicInt>
|
||||
|
||||
@@ -67,11 +67,11 @@ public:
|
||||
m_state = Done;
|
||||
}
|
||||
|
||||
void process( sampleFrame* workingBuffer = NULL )
|
||||
void process()
|
||||
{
|
||||
if( m_state.testAndSetOrdered( Queued, InProgress ) )
|
||||
{
|
||||
doProcessing( workingBuffer );
|
||||
doProcessing();
|
||||
m_state = Done;
|
||||
}
|
||||
}
|
||||
@@ -80,7 +80,7 @@ public:
|
||||
|
||||
|
||||
protected:
|
||||
virtual void doProcessing( sampleFrame* workingBuffer) = 0;
|
||||
virtual void doProcessing() = 0;
|
||||
|
||||
QAtomicInt m_state;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user