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