Refactoring: Remove duplicate code (#4310)
This commit is contained in:
@@ -125,48 +125,9 @@ public:
|
||||
*/
|
||||
static inline sample_t oscillate( float _ph, float _wavelen, Waveforms _wave )
|
||||
{
|
||||
// high wavelen/ low freq
|
||||
if( _wavelen > TLENS[ MAXTBL ] )
|
||||
{
|
||||
const int t = MAXTBL;
|
||||
const int tlen = TLENS[t];
|
||||
const float ph = fraction( _ph );
|
||||
const float lookupf = ph * static_cast<float>( tlen );
|
||||
const int lookup = static_cast<int>( lookupf );
|
||||
const float ip = fraction( lookupf );
|
||||
|
||||
const sample_t s1 = s_waveforms[ _wave ].sampleAt( t, lookup );
|
||||
const sample_t s2 = s_waveforms[ _wave ].sampleAt( t, ( lookup + 1 ) % tlen );
|
||||
const int lm = lookup == 0 ? tlen - 1 : lookup - 1;
|
||||
const sample_t s0 = s_waveforms[ _wave ].sampleAt( t, lm );
|
||||
const sample_t s3 = s_waveforms[ _wave ].sampleAt( t, ( lookup + 2 ) % tlen );
|
||||
const sample_t sr = optimal4pInterpolate( s0, s1, s2, s3, ip );
|
||||
|
||||
return sr;
|
||||
}
|
||||
// low wavelen/ high freq
|
||||
if( _wavelen < 3.0f )
|
||||
{
|
||||
const int t = 0;
|
||||
const int tlen = TLENS[t];
|
||||
const float ph = fraction( _ph );
|
||||
const float lookupf = ph * static_cast<float>( tlen );
|
||||
const int lookup = static_cast<int>( lookupf );
|
||||
const float ip = fraction( lookupf );
|
||||
|
||||
const sample_t s1 = s_waveforms[ _wave ].sampleAt( t, lookup );
|
||||
const sample_t s2 = s_waveforms[ _wave ].sampleAt( t, ( lookup + 1 ) % tlen );
|
||||
const int lm = lookup == 0 ? tlen - 1 : lookup - 1;
|
||||
const sample_t s0 = s_waveforms[ _wave ].sampleAt( t, lm );
|
||||
const sample_t s3 = s_waveforms[ _wave ].sampleAt( t, ( lookup + 2 ) % tlen );
|
||||
const sample_t sr = optimal4pInterpolate( s0, s1, s2, s3, ip );
|
||||
|
||||
return sr;
|
||||
}
|
||||
|
||||
// get the next higher tlen
|
||||
int t = MAXTBL - 1;
|
||||
while( _wavelen < TLENS[t] ) { t--; }
|
||||
int t = 0;
|
||||
while( t < MAXTBL && _wavelen >= TLENS[t+1] ) { t++; }
|
||||
|
||||
int tlen = TLENS[t];
|
||||
const float ph = fraction( _ph );
|
||||
|
||||
@@ -245,15 +245,37 @@ namespace DspEffectLibrary
|
||||
} ;
|
||||
|
||||
|
||||
class FoldbackDistortion : public MonoBase<FoldbackDistortion>
|
||||
template<class T>
|
||||
class DistortionBase : public MonoBase<T>
|
||||
{
|
||||
public:
|
||||
FoldbackDistortion( float threshold, float gain ) :
|
||||
DistortionBase( float threshold, float gain ) :
|
||||
m_threshold( threshold ),
|
||||
m_gain( gain )
|
||||
{
|
||||
}
|
||||
|
||||
void setThreshold( float threshold )
|
||||
{
|
||||
m_threshold = threshold;
|
||||
}
|
||||
|
||||
void setGain( float gain )
|
||||
{
|
||||
m_gain = gain;
|
||||
}
|
||||
|
||||
protected:
|
||||
float m_threshold;
|
||||
float m_gain;
|
||||
};
|
||||
|
||||
|
||||
class FoldbackDistortion : public DistortionBase<FoldbackDistortion>
|
||||
{
|
||||
public:
|
||||
using DistortionBase<FoldbackDistortion>::DistortionBase;
|
||||
|
||||
sample_t nextSample( sample_t in )
|
||||
{
|
||||
if( in >= m_threshold || in < -m_threshold )
|
||||
@@ -262,54 +284,18 @@ namespace DspEffectLibrary
|
||||
}
|
||||
return in * m_gain;
|
||||
}
|
||||
|
||||
void setThreshold( float threshold )
|
||||
{
|
||||
m_threshold = threshold;
|
||||
}
|
||||
|
||||
void setGain( float gain )
|
||||
{
|
||||
m_gain = gain;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
float m_threshold;
|
||||
float m_gain;
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
class Distortion : public MonoBase<Distortion>
|
||||
class Distortion : public DistortionBase<Distortion>
|
||||
{
|
||||
public:
|
||||
Distortion( float threshold, float gain ) :
|
||||
m_threshold( threshold ),
|
||||
m_gain( gain )
|
||||
{
|
||||
}
|
||||
using DistortionBase<Distortion>::DistortionBase;
|
||||
|
||||
sample_t nextSample( sample_t in )
|
||||
{
|
||||
return m_gain * ( in * ( fabsf( in )+m_threshold ) / ( in*in +( m_threshold-1 )* fabsf( in ) + 1 ) );
|
||||
}
|
||||
|
||||
void setThreshold( float threshold )
|
||||
{
|
||||
m_threshold = threshold;
|
||||
}
|
||||
|
||||
void setGain( float gain )
|
||||
{
|
||||
m_gain = gain;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
float m_threshold;
|
||||
float m_gain;
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
@@ -334,6 +334,11 @@ private:
|
||||
uint16_t getPluginInputs( const LADSPA_Descriptor * _descriptor );
|
||||
uint16_t getPluginOutputs( const LADSPA_Descriptor * _descriptor );
|
||||
|
||||
const LADSPA_PortDescriptor* getPortDescriptor( const ladspa_key_t& _plugin,
|
||||
uint32_t _port );
|
||||
const LADSPA_PortRangeHint* getPortRangeHint( const ladspa_key_t& _plugin,
|
||||
uint32_t _port );
|
||||
|
||||
typedef QMap<ladspa_key_t, ladspaManagerDescription *>
|
||||
ladspaManagerMapType;
|
||||
ladspaManagerMapType m_ladspaManagerMap;
|
||||
|
||||
@@ -64,6 +64,8 @@ private:
|
||||
QString pathForTrack( const Track *track, int num );
|
||||
void restoreMutedState();
|
||||
|
||||
void render( QString outputPath );
|
||||
|
||||
const Mixer::qualitySettings m_qualitySettings;
|
||||
const Mixer::qualitySettings m_oldQualitySettings;
|
||||
const OutputSettings m_outputSettings;
|
||||
|
||||
@@ -103,12 +103,12 @@ public:
|
||||
} ;
|
||||
|
||||
|
||||
SampleBuffer();
|
||||
// constructor which either loads sample _audio_file or decodes
|
||||
// base64-data out of string
|
||||
SampleBuffer( const QString & _audio_file = QString(),
|
||||
bool _is_base64_data = false );
|
||||
SampleBuffer( const QString & _audio_file, bool _is_base64_data = false );
|
||||
SampleBuffer( const sampleFrame * _data, const f_cnt_t _frames );
|
||||
SampleBuffer( const f_cnt_t _frames );
|
||||
explicit SampleBuffer( const f_cnt_t _frames );
|
||||
|
||||
virtual ~SampleBuffer();
|
||||
|
||||
|
||||
@@ -38,8 +38,8 @@ class AudioPort;
|
||||
class SamplePlayHandle : public PlayHandle
|
||||
{
|
||||
public:
|
||||
SamplePlayHandle( const QString& sampleFile );
|
||||
SamplePlayHandle( SampleBuffer* sampleBuffer );
|
||||
SamplePlayHandle( const QString& sampleFile );
|
||||
SamplePlayHandle( SampleTCO* tco );
|
||||
virtual ~SamplePlayHandle();
|
||||
|
||||
|
||||
@@ -438,6 +438,7 @@ private slots:
|
||||
void cloneTrack();
|
||||
void removeTrack();
|
||||
void updateMenu();
|
||||
void toggleRecording(bool on);
|
||||
void recordingOn();
|
||||
void recordingOff();
|
||||
void clearTrack();
|
||||
|
||||
@@ -69,25 +69,6 @@ private slots:
|
||||
|
||||
|
||||
private:
|
||||
struct VstSyncData
|
||||
{
|
||||
bool isPlaying;
|
||||
float ppqPos;
|
||||
int timeSigNumer;
|
||||
int timeSigDenom;
|
||||
bool isCycle;
|
||||
bool hasSHM;
|
||||
float cycleStart;
|
||||
float cycleEnd;
|
||||
int m_bufferSize;
|
||||
int m_sampleRate;
|
||||
int m_bpm;
|
||||
|
||||
#ifdef VST_SNC_LATENCY
|
||||
float m_latency;
|
||||
#endif
|
||||
} ;
|
||||
|
||||
VstSyncData* m_syncData;
|
||||
|
||||
int m_shmID;
|
||||
|
||||
Reference in New Issue
Block a user