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