chris@164: /* chris@164: * chris@164: * Excitation Junction for two waveguides chris@164: * chris@164: * Christian Heinrichs 04/2015 chris@164: * chris@164: */ chris@164: chris@164: #include "Junction.h" chris@164: #include "../include/Utilities.h" chris@164: chris@164: Junction::Junction() { chris@164: chris@164: setFrequency(440); chris@164: _dt = 1.0/44100.0; chris@164: chris@164: // initialize variables chris@164: for(int i=0;i=WG_BUFFER_SIZE) chris@164: _readPtr=0; chris@164: chris@164: // 2. add excitation sample into buffer chris@164: chris@164: _buffer_l[(_readPtr+_delay_l+WG_BUFFER_SIZE)%WG_BUFFER_SIZE] = excitation; chris@164: _buffer_r[(_readPtr+_delay_r+WG_BUFFER_SIZE)%WG_BUFFER_SIZE] = excitation; chris@164: chris@164: // 3. feed right input to left output and vice versa chris@164: chris@164: _buffer_l[_readPtr] += right; chris@164: _buffer_r[_readPtr] += left; chris@164: chris@164: // 4. store excitation value for later use chris@164: _excitation = excitation; chris@164: chris@164: } chris@164: chris@164: float Junction::getOutput(int direction) { chris@164: chris@164: if(direction = 0) chris@164: return _buffer_l[_readPtr]; chris@164: else chris@164: return _buffer_r[_readPtr]; chris@164: chris@164: } chris@164: chris@164: float Junction::getExcitationDisplacement() { chris@164: chris@164: // string displacement and excitation force chris@164: // use delayed value to account for excitation position chris@164: float in = _buffer_l[(_readPtr+_delay_l+WG_BUFFER_SIZE)%WG_BUFFER_SIZE] + _excitation; chris@164: chris@164: // integrate total force chris@164: float out = 0.00001 * in + 0.99999 * _lastPlectrumDisplacement; chris@164: chris@164: // store variable for next iteration chris@164: _lastPlectrumDisplacement = out; chris@164: chris@164: // multiply by delta time chris@164: return out * _dt; chris@164: chris@164: } chris@164: chris@164: void Junction::setPluckPosition(float pluckPos){ chris@164: chris@164: pluckPos = constrain(pluckPos,0,1); chris@164: _delay_l = pluckPos * _periodInSamples; chris@164: _delay_r = (1-pluckPos) * _periodInSamples; chris@164: chris@164: } chris@164: chris@164: void Junction::setPeriod(float period) { chris@164: chris@164: _periodInMilliseconds = period; chris@164: chris@164: } chris@164: chris@164: void Junction::setFrequency(float frequency) { chris@164: chris@164: _periodInMilliseconds = 1000.0/frequency; chris@164: _periodInSamples = (int)(_periodInMilliseconds * 44.1); chris@164: chris@164: }