new kicker-plugin and extended effect-lib
git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@442 0778d3d1-df1d-0410-868b-ea421aaaa00d
This commit is contained in:
@@ -29,31 +29,58 @@
|
||||
#include "templates.h"
|
||||
#include "types.h"
|
||||
|
||||
|
||||
namespace effectLib
|
||||
{
|
||||
|
||||
template<typename SAMPLE> class monoBypass;
|
||||
template<typename SAMPLE> class stereoBypass;
|
||||
|
||||
|
||||
template<typename SAMPLE = sample_t>
|
||||
class monoBase
|
||||
{
|
||||
public:
|
||||
typedef SAMPLE sampleType;
|
||||
typedef monoBypass<SAMPLE> bypassType;
|
||||
|
||||
virtual ~monoBase()
|
||||
{
|
||||
}
|
||||
virtual SAMPLE nextSample( const SAMPLE _in ) const = 0;
|
||||
virtual void process( SAMPLE * * _buf,
|
||||
const f_cnt_t _frames ) const
|
||||
{
|
||||
for( f_cnt_t f = 0; f < _frames; ++f )
|
||||
{
|
||||
_buf[f][0] = nextSample( _buf[f][0] );
|
||||
}
|
||||
}
|
||||
} ;
|
||||
|
||||
template<typename SAMPLE = sample_t>
|
||||
class stereoBase
|
||||
{
|
||||
public:
|
||||
typedef SAMPLE sampleType;
|
||||
typedef stereoBypass<SAMPLE> bypassType;
|
||||
|
||||
virtual ~stereoBase()
|
||||
{
|
||||
}
|
||||
typedef SAMPLE sampleType;
|
||||
virtual void nextSample( SAMPLE & _in_left,
|
||||
SAMPLE & _in_right ) const = 0;
|
||||
virtual void process( SAMPLE * * _buf,
|
||||
const f_cnt_t _frames ) const
|
||||
{
|
||||
for( f_cnt_t f = 0; f < _frames; ++f )
|
||||
{
|
||||
nextSample( _buf[f][0], _buf[f][1] );
|
||||
}
|
||||
}
|
||||
} ;
|
||||
|
||||
|
||||
template<class FXL, class FXR = FXL>
|
||||
class monoToStereoAdaptor : public stereoBase<typename FXL::sampleType>
|
||||
{
|
||||
@@ -119,6 +146,69 @@ namespace effectLib
|
||||
} ;
|
||||
|
||||
|
||||
template<typename SAMPLE = sample_t>
|
||||
class monoBypass : public monoBase<SAMPLE>
|
||||
{
|
||||
public:
|
||||
virtual SAMPLE nextSample( const SAMPLE _in ) const
|
||||
{
|
||||
return( _in );
|
||||
}
|
||||
} ;
|
||||
|
||||
|
||||
template<typename SAMPLE = sample_t>
|
||||
class stereoBypass : public stereoBase<SAMPLE>
|
||||
{
|
||||
public:
|
||||
virtual void nextSample( SAMPLE &, SAMPLE & ) const
|
||||
{
|
||||
}
|
||||
} ;
|
||||
|
||||
|
||||
/* convenient class to build up static FX-chains, for example
|
||||
|
||||
using namespace effectLib;
|
||||
chain<monoToStereoAdaptor<bassBoost<> >,
|
||||
chain<stereoEnhancer<>,
|
||||
monoToStereoAdaptor<foldbackDistortion<> > > >
|
||||
fxchain( bassBoost<>( 60.0, 1.0, 4.0f ),
|
||||
chain<stereoEnhancer<>,
|
||||
monoToStereoAdaptor<foldbackDistortion<> > >(
|
||||
stereoEnhancer<>( 1.0 ),
|
||||
foldbackDistortion<>( 1.0f, 1.0f ) ) );
|
||||
|
||||
// now you can do simple calls such as which will process a bass-boost-,
|
||||
// stereo-enhancer- and foldback-distortion-effect on your buffer
|
||||
fx_chain.process( (sample_t * *) buf, frames );
|
||||
*/
|
||||
|
||||
template<class FX0, class FX1 = typename FX0::bypassType>
|
||||
class chain : public FX0::bypassType
|
||||
{
|
||||
public:
|
||||
typedef typename FX0::sampleType sampleType;
|
||||
chain( const FX0 & _fx0, const FX1 & _fx1 = FX1() ) :
|
||||
m_FX0( _fx0 ),
|
||||
m_FX1( _fx1 )
|
||||
{
|
||||
}
|
||||
|
||||
virtual void process( sampleType * * _buf,
|
||||
const f_cnt_t _frames ) const
|
||||
{
|
||||
m_FX0.process( _buf, _frames );
|
||||
m_FX1.process( _buf, _frames );
|
||||
}
|
||||
|
||||
private:
|
||||
FX0 m_FX0;
|
||||
FX1 m_FX1;
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
template<typename SAMPLE>
|
||||
inline SAMPLE saturate( const SAMPLE _x )
|
||||
{
|
||||
@@ -184,6 +274,49 @@ namespace effectLib
|
||||
} ;
|
||||
|
||||
|
||||
template<typename SAMPLE = sample_t>
|
||||
class foldbackDistortion : public monoBase<SAMPLE>
|
||||
{
|
||||
public:
|
||||
foldbackDistortion( const float _threshold,
|
||||
const float _gain ) :
|
||||
m_threshold( _threshold ),
|
||||
m_gain( _gain )
|
||||
{
|
||||
}
|
||||
|
||||
virtual SAMPLE nextSample( const SAMPLE _in ) const
|
||||
{
|
||||
if( _in >= m_threshold || _in < -m_threshold )
|
||||
{
|
||||
return( ( fabsf( fabsf(
|
||||
fmodf( _in - m_threshold,
|
||||
m_threshold*4 ) ) -
|
||||
m_threshold*2 ) -
|
||||
m_threshold ) *
|
||||
m_gain );
|
||||
}
|
||||
return( _in * m_gain );
|
||||
}
|
||||
|
||||
void setThreshold( const float _threshold )
|
||||
{
|
||||
m_threshold = _threshold;
|
||||
}
|
||||
|
||||
void setGain( const float _gain )
|
||||
{
|
||||
m_gain = _gain;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
float m_threshold;
|
||||
float m_gain;
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
template<typename SAMPLE = sample_t>
|
||||
class stereoEnhancer : public stereoBase<SAMPLE>
|
||||
{
|
||||
|
||||
80
include/sweep_oscillator.h
Normal file
80
include/sweep_oscillator.h
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* sweep_oscillator.h - sweep-oscillator
|
||||
*
|
||||
* Copyright (c) 2006 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
*
|
||||
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this program (see COPYING); if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _SWEEP_OSCILLATOR_H
|
||||
#define _SWEEP_OSCILLATOR_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "oscillator.h"
|
||||
#include "effect_lib.h"
|
||||
|
||||
|
||||
template<class FX = effectLib::stereoBypass<> >
|
||||
class sweepOscillator
|
||||
{
|
||||
public:
|
||||
sweepOscillator( const FX & _fx = FX() ) :
|
||||
m_phase( 0.0f ),
|
||||
m_FX( _fx )
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~sweepOscillator()
|
||||
{
|
||||
}
|
||||
|
||||
void update( sampleFrame * _ab, const fpab_t _frames,
|
||||
const float _freq1, const float _freq2,
|
||||
const float _sample_rate )
|
||||
{
|
||||
const float df = _freq2 - _freq1;
|
||||
for( fpab_t frame = 0; frame < _frames; ++frame )
|
||||
{
|
||||
sample_t s = oscillator::sinSample( m_phase );
|
||||
for( ch_cnt_t ch = 0; ch < DEFAULT_CHANNELS; ++ch )
|
||||
{
|
||||
_ab[frame][ch] = s;
|
||||
}
|
||||
m_FX.nextSample( _ab[frame][0], _ab[frame][1] );
|
||||
m_phase += ( _freq1 + ( frame * df / _frames ) ) /
|
||||
_sample_rate;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
float m_phase;
|
||||
FX m_FX;
|
||||
|
||||
inline sample_t getSample( const float _sample );
|
||||
inline void FASTCALL recalcPhase( void );
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user