| 1 |
/***************************************************/ |
| 2 |
/*! \class Effect |
| 3 |
\brief STK abstract effects parent class. |
| 4 |
|
| 5 |
This class provides common functionality for |
| 6 |
STK effects subclasses. |
| 7 |
|
| 8 |
by Perry R. Cook and Gary P. Scavone, 1995 - 2005. |
| 9 |
*/ |
| 10 |
/***************************************************/ |
| 11 |
|
| 12 |
#include "Effect.h" |
| 13 |
#include <math.h> |
| 14 |
|
| 15 |
using namespace Nyq; |
| 16 |
|
| 17 |
Effect :: Effect() |
| 18 |
{ |
| 19 |
} |
| 20 |
|
| 21 |
Effect :: ~Effect() |
| 22 |
{ |
| 23 |
} |
| 24 |
|
| 25 |
void Effect :: setEffectMix(StkFloat mix) |
| 26 |
{ |
| 27 |
if ( mix < 0.0 ) { |
| 28 |
errorString_ << "Effect::setEffectMix: mix parameter is less than zero ... setting to zero!"; |
| 29 |
handleError( StkError::WARNING ); |
| 30 |
effectMix_ = 0.0; |
| 31 |
} |
| 32 |
else if ( mix > 1.0 ) { |
| 33 |
errorString_ << "Effect::setEffectMix: mix parameter is greater than 1.0 ... setting to one!"; |
| 34 |
handleError( StkError::WARNING ); |
| 35 |
effectMix_ = 1.0; |
| 36 |
} |
| 37 |
else |
| 38 |
effectMix_ = mix; |
| 39 |
} |
| 40 |
|
| 41 |
StkFloat Effect :: lastOut() const |
| 42 |
{ |
| 43 |
return (lastOutput_[0] + lastOutput_[1]) * 0.5; |
| 44 |
} |
| 45 |
|
| 46 |
StkFloat Effect :: lastOutLeft() const |
| 47 |
{ |
| 48 |
return lastOutput_[0]; |
| 49 |
} |
| 50 |
|
| 51 |
StkFloat Effect :: lastOutRight() const |
| 52 |
{ |
| 53 |
return lastOutput_[1]; |
| 54 |
} |
| 55 |
|
| 56 |
StkFloat Effect :: tick( StkFloat input ) |
| 57 |
{ |
| 58 |
return computeSample( input ); |
| 59 |
} |
| 60 |
|
| 61 |
StkFrames& Effect :: tick( StkFrames& frames, unsigned int channel ) |
| 62 |
{ |
| 63 |
if ( channel >= frames.channels() ) { |
| 64 |
errorString_ << "Effect::tick(): channel and StkFrames arguments are incompatible!"; |
| 65 |
handleError( StkError::FUNCTION_ARGUMENT ); |
| 66 |
} |
| 67 |
|
| 68 |
if ( frames.channels() == 1 ) { |
| 69 |
for ( unsigned int i=0; i<frames.frames(); i++ ) |
| 70 |
frames[i] = computeSample( frames[i] ); |
| 71 |
} |
| 72 |
else if ( frames.interleaved() ) { |
| 73 |
unsigned int hop = frames.channels(); |
| 74 |
unsigned int index = channel; |
| 75 |
for ( unsigned int i=0; i<frames.frames(); i++ ) { |
| 76 |
frames[index] = computeSample( frames[index] ); |
| 77 |
index += hop; |
| 78 |
} |
| 79 |
} |
| 80 |
else { |
| 81 |
unsigned int iStart = channel * frames.frames(); |
| 82 |
for ( unsigned int i=0; i<frames.frames(); i++, iStart++ ) |
| 83 |
frames[iStart] = computeSample( frames[iStart] ); |
| 84 |
} |
| 85 |
|
| 86 |
return frames; |
| 87 |
} |
| 88 |
|
| 89 |
bool Effect :: isPrime(int number) |
| 90 |
{ |
| 91 |
if (number == 2) return true; |
| 92 |
if (number & 1) { |
| 93 |
for (int i=3; i<(int)sqrt((double)number)+1; i+=2) |
| 94 |
if ( (number % i) == 0) return false; |
| 95 |
return true; // prime |
| 96 |
} |
| 97 |
else return false; // even |
| 98 |
} |