chris@164: /* chris@164: * chris@164: * 1-D string consisting of two waveguides and junction chris@164: * chris@164: * Christian Heinrichs 04/2015 chris@164: * chris@164: */ chris@164: chris@164: #include "String.h" chris@164: #include "Junction.h" chris@164: #include "Waveguide.h" chris@164: chris@164: #include "../include/Utilities.h" chris@164: #include chris@164: #include chris@164: #include chris@164: #include chris@164: chris@164: String::String(){ chris@164: chris@164: wg_l = Waveguide(); chris@164: wg_r = Waveguide(); chris@164: junction = Junction(); chris@164: chris@164: junction.setPluckPosition(0.5); chris@164: chris@164: _previous_l = 0; chris@164: _previous_r = 0; chris@164: chris@164: } chris@164: chris@164: float String::update(float in) { chris@164: chris@164: // 1. send excitation signal and previous waveguide outputs into junction chris@164: chris@164: junction.update(in,_previous_l,_previous_r); chris@164: chris@164: // 2. save new waveguide outputs for next iteration chris@164: chris@164: _previous_l = wg_l.update(junction.getOutput(0)); chris@164: _previous_r = wg_r.update(junction.getOutput(1)); chris@164: chris@164: // 3. use right waveguide as output chris@164: chris@164: //rt_printf("BANANA %f ",_readPtr); chris@164: //rt_printf("%f\n",_previous_r); chris@164: chris@164: return _previous_r; chris@164: } chris@164: chris@164: float String::getPlectrumDisplacement() { chris@164: chris@164: return junction.getExcitationDisplacement(); chris@164: chris@164: } chris@164: chris@164: void String::setPluckPosition(float pluckPos){ chris@164: chris@164: junction.setPluckPosition(pluckPos); chris@164: chris@164: } chris@164: chris@164: void String::setGlobalPosition(float pos) { chris@164: chris@164: _globalPosition = pos; chris@164: chris@164: } chris@164: chris@164: float String::getGlobalPosition() { chris@164: chris@164: return _globalPosition; chris@164: chris@164: } chris@164: chris@164: void String::setMidinote(float midinote) { chris@164: chris@164: float frequency = 440.0f*(float)powf(2,(midinote-57)/12.0f); chris@164: chris@164: junction.setFrequency(frequency); chris@164: wg_l.setFrequency(frequency); chris@164: wg_r.setFrequency(frequency); chris@164: chris@164: } chris@164: chris@164: void String::setFrequency(float frequency) { chris@164: chris@164: junction.setFrequency(frequency); chris@164: wg_l.setFrequency(frequency); chris@164: wg_r.setFrequency(frequency); chris@164: chris@164: }