annotate examples/10-Instruments/airharp/String.cpp @ 464:8fcfbfb32aa0 prerelease

Examples reorder with subdirectories. Added header to each project. Moved Doxygen to bottom of render.cpp.
author Robert Jack <robert.h.jack@gmail.com>
date Mon, 20 Jun 2016 16:20:38 +0100
parents
children 8f8809c77dda
rev   line source
robert@464 1 /*
robert@464 2 *
robert@464 3 * 1-D string consisting of two waveguides and junction
robert@464 4 *
robert@464 5 * Christian Heinrichs 04/2015
robert@464 6 *
robert@464 7 */
robert@464 8
robert@464 9 #include "String.h"
robert@464 10 #include "Junction.h"
robert@464 11 #include "Waveguide.h"
robert@464 12
robert@464 13 #include "../include/Utilities.h"
robert@464 14 #include <rtdk.h>
robert@464 15 #include <cmath>
robert@464 16 #include <stdio.h>
robert@464 17 #include <cstdlib>
robert@464 18
robert@464 19 String::String(){
robert@464 20
robert@464 21 wg_l = Waveguide();
robert@464 22 wg_r = Waveguide();
robert@464 23 junction = Junction();
robert@464 24
robert@464 25 junction.setPluckPosition(0.5);
robert@464 26
robert@464 27 _previous_l = 0;
robert@464 28 _previous_r = 0;
robert@464 29
robert@464 30 }
robert@464 31
robert@464 32 float String::update(float in) {
robert@464 33
robert@464 34 // 1. send excitation signal and previous waveguide outputs into junction
robert@464 35
robert@464 36 junction.update(in,_previous_l,_previous_r);
robert@464 37
robert@464 38 // 2. save new waveguide outputs for next iteration
robert@464 39
robert@464 40 _previous_l = wg_l.update(junction.getOutput(0));
robert@464 41 _previous_r = wg_r.update(junction.getOutput(1));
robert@464 42
robert@464 43 // 3. use right waveguide as output
robert@464 44
robert@464 45 //rt_printf("BANANA %f ",_readPtr);
robert@464 46 //rt_printf("%f\n",_previous_r);
robert@464 47
robert@464 48 return _previous_r;
robert@464 49 }
robert@464 50
robert@464 51 float String::getPlectrumDisplacement() {
robert@464 52
robert@464 53 return junction.getExcitationDisplacement();
robert@464 54
robert@464 55 }
robert@464 56
robert@464 57 void String::setPluckPosition(float pluckPos){
robert@464 58
robert@464 59 junction.setPluckPosition(pluckPos);
robert@464 60
robert@464 61 }
robert@464 62
robert@464 63 void String::setGlobalPosition(float pos) {
robert@464 64
robert@464 65 _globalPosition = pos;
robert@464 66
robert@464 67 }
robert@464 68
robert@464 69 float String::getGlobalPosition() {
robert@464 70
robert@464 71 return _globalPosition;
robert@464 72
robert@464 73 }
robert@464 74
robert@464 75 void String::setMidinote(float midinote) {
robert@464 76
robert@464 77 float frequency = 440.0f*(float)powf(2,(midinote-57)/12.0f);
robert@464 78
robert@464 79 junction.setFrequency(frequency);
robert@464 80 wg_l.setFrequency(frequency);
robert@464 81 wg_r.setFrequency(frequency);
robert@464 82
robert@464 83 }
robert@464 84
robert@464 85 void String::setFrequency(float frequency) {
robert@464 86
robert@464 87 junction.setFrequency(frequency);
robert@464 88 wg_l.setFrequency(frequency);
robert@464 89 wg_r.setFrequency(frequency);
robert@464 90
robert@464 91 }