Arduino STK  4.6.2
Effect.h
1 #ifndef STK_EFFECT_H
2 #define STK_EFFECT_H
3 
4 #include "Stk.h"
5 #include <cmath>
6 
7 namespace stk {
8 
9 /***************************************************/
19 /***************************************************/
20 
21 class Effect : public Stk
22 {
23  public:
25  Effect( void ) { lastFrame_.resize( 1, 1, 0.0 ); };
26 
28  unsigned int channelsOut( void ) const { return lastFrame_.channels(); };
29 
31  const StkFrames& lastFrame( void ) const { return lastFrame_; };
32 
34  virtual void clear() = 0;
35 
37  virtual void setEffectMix( StkFloat mix );
38 
40  virtual StkFloat tick (StkFloat input, unsigned int channel=0)=0;
41 
42 
43  protected:
44 
45  // Returns true if argument value is prime.
46  bool isPrime( unsigned int number );
47 
48  StkFrames lastFrame_;
49  StkFloat effectMix_;
50 
51 };
52 
53 inline void Effect :: setEffectMix( StkFloat mix )
54 {
55  if ( mix < 0.0 ) {
56  oStream_ << "Effect::setEffectMix: mix parameter is less than zero ... setting to zero!";
57  handleError( StkError::WARNING );
58  effectMix_ = 0.0;
59  }
60  else if ( mix > 1.0 ) {
61  oStream_ << "Effect::setEffectMix: mix parameter is greater than 1.0 ... setting to one!";
62  handleError( StkError::WARNING );
63  effectMix_ = 1.0;
64  }
65  else
66  effectMix_ = mix;
67 }
68 
69 inline bool Effect :: isPrime( unsigned int number )
70 {
71  if ( number == 2 ) return true;
72  if ( number & 1 ) {
73  for ( int i=3; i<(int)sqrt((double)number)+1; i+=2 )
74  if ( (number % i) == 0 ) return false;
75  return true; // prime
76  }
77  else return false; // even
78 }
79 
80 } // stk namespace
81 
82 #endif
83 
STK abstract effects parent class.
Definition: Effect.h:22
virtual void clear()=0
Reset and clear all internal state.
virtual StkFloat tick(StkFloat input, unsigned int channel=0)=0
Support tick! (pschatzmann)
const StkFrames & lastFrame(void) const
Return an StkFrames reference to the last output sample frame.
Definition: Effect.h:31
virtual void setEffectMix(StkFloat mix)
Set the mixture of input and "effected" levels in the output (0.0 = input only, 1....
Definition: Effect.h:53
Effect(void)
Class constructor.
Definition: Effect.h:25
unsigned int channelsOut(void) const
Return the number of output channels for the class.
Definition: Effect.h:28
An STK class to handle vectorized audio data.
Definition: Stk.h:287
unsigned int channels(void) const
Return the number of channels represented by the data.
Definition: Stk.h:415
void resize(size_t nFrames, unsigned int nChannels=1)
Resize self to represent the specified number of channels and frames.
STK base class.
Definition: Stk.h:144
static void handleError(const char *message, StkError::Type type)
Static function for error reporting and handling using c-strings.
The STK namespace.
Definition: ADSR.h:8