| 69 | |
| 70 | |
| 71 | bool waveShaperEffect::processAudioBuffer( sampleFrame * _buf, |
| 72 | const fpp_t _frames ) |
| 73 | { |
| 74 | if( !isEnabled() || !isRunning () ) |
| 75 | { |
| 76 | return( false ); |
| 77 | } |
| 78 | |
| 79 | // variables for effect |
| 80 | int i = 0; |
| 81 | |
| 82 | double out_sum = 0.0; |
| 83 | const float d = dryLevel(); |
| 84 | const float w = wetLevel(); |
| 85 | float input = m_wsControls.m_inputModel.value(); |
| 86 | float output = m_wsControls.m_outputModel.value(); |
| 87 | const float * samples = m_wsControls.m_wavegraphModel.samples(); |
| 88 | const bool clip = m_wsControls.m_clipModel.value(); |
| 89 | |
| 90 | ValueBuffer *inputBuffer = m_wsControls.m_inputModel.valueBuffer(); |
| 91 | ValueBuffer *outputBufer = m_wsControls.m_outputModel.valueBuffer(); |
| 92 | |
| 93 | int inputInc = inputBuffer ? 1 : 0; |
| 94 | int outputInc = outputBufer ? 1 : 0; |
| 95 | |
| 96 | const float *inputPtr = inputBuffer ? &( inputBuffer->values()[ 0 ] ) : &input; |
| 97 | const float *outputPtr = outputBufer ? &( outputBufer->values()[ 0 ] ) : &output; |
| 98 | |
| 99 | for( fpp_t f = 0; f < _frames; ++f ) |
| 100 | { |
| 101 | float s[2] = { _buf[f][0], _buf[f][1] }; |
| 102 | |
| 103 | // apply input gain |
| 104 | s[0] *= *inputPtr; |
| 105 | s[1] *= *inputPtr; |
| 106 | |
| 107 | // clip if clip enabled |
| 108 | if( clip ) |
| 109 | { |
| 110 | s[0] = qBound( -1.0f, s[0], 1.0f ); |
| 111 | s[1] = qBound( -1.0f, s[1], 1.0f ); |
| 112 | } |
| 113 | |
| 114 | // start effect |
| 115 | |
| 116 | for( i=0; i <= 1; ++i ) |
| 117 | { |
| 118 | const int lookup = static_cast<int>( qAbs( s[i] ) * 200.0f ); |
| 119 | const float frac = fraction( qAbs( s[i] ) * 200.0f ); |
| 120 | const float posneg = s[i] < 0 ? -1.0f : 1.0f; |
| 121 | |
| 122 | if( lookup < 1 ) |
| 123 | { |
| 124 | s[i] = frac * samples[0] * posneg; |
| 125 | } |
| 126 | else if( lookup < 200 ) |
| 127 | { |
| 128 | s[i] = linearInterpolate( samples[ lookup - 1 ], |
no test coverage detected