Mercurial > hg > beaglert
annotate projects/airharp/String.cpp @ 164:40badaff5729 heavy-updated
- added more pd/heavy examples
- removed heavy-specific flags from Makefile
- added air-harp cpp example project
author | chnrx <chris.heinrichs@gmail.com> |
---|---|
date | Thu, 03 Dec 2015 16:19:33 +0000 |
parents | |
children |
rev | line source |
---|---|
chris@164 | 1 /* |
chris@164 | 2 * |
chris@164 | 3 * 1-D string consisting of two waveguides and junction |
chris@164 | 4 * |
chris@164 | 5 * Christian Heinrichs 04/2015 |
chris@164 | 6 * |
chris@164 | 7 */ |
chris@164 | 8 |
chris@164 | 9 #include "String.h" |
chris@164 | 10 #include "Junction.h" |
chris@164 | 11 #include "Waveguide.h" |
chris@164 | 12 |
chris@164 | 13 #include "../include/Utilities.h" |
chris@164 | 14 #include <rtdk.h> |
chris@164 | 15 #include <cmath> |
chris@164 | 16 #include <stdio.h> |
chris@164 | 17 #include <cstdlib> |
chris@164 | 18 |
chris@164 | 19 String::String(){ |
chris@164 | 20 |
chris@164 | 21 wg_l = Waveguide(); |
chris@164 | 22 wg_r = Waveguide(); |
chris@164 | 23 junction = Junction(); |
chris@164 | 24 |
chris@164 | 25 junction.setPluckPosition(0.5); |
chris@164 | 26 |
chris@164 | 27 _previous_l = 0; |
chris@164 | 28 _previous_r = 0; |
chris@164 | 29 |
chris@164 | 30 } |
chris@164 | 31 |
chris@164 | 32 float String::update(float in) { |
chris@164 | 33 |
chris@164 | 34 // 1. send excitation signal and previous waveguide outputs into junction |
chris@164 | 35 |
chris@164 | 36 junction.update(in,_previous_l,_previous_r); |
chris@164 | 37 |
chris@164 | 38 // 2. save new waveguide outputs for next iteration |
chris@164 | 39 |
chris@164 | 40 _previous_l = wg_l.update(junction.getOutput(0)); |
chris@164 | 41 _previous_r = wg_r.update(junction.getOutput(1)); |
chris@164 | 42 |
chris@164 | 43 // 3. use right waveguide as output |
chris@164 | 44 |
chris@164 | 45 //rt_printf("BANANA %f ",_readPtr); |
chris@164 | 46 //rt_printf("%f\n",_previous_r); |
chris@164 | 47 |
chris@164 | 48 return _previous_r; |
chris@164 | 49 } |
chris@164 | 50 |
chris@164 | 51 float String::getPlectrumDisplacement() { |
chris@164 | 52 |
chris@164 | 53 return junction.getExcitationDisplacement(); |
chris@164 | 54 |
chris@164 | 55 } |
chris@164 | 56 |
chris@164 | 57 void String::setPluckPosition(float pluckPos){ |
chris@164 | 58 |
chris@164 | 59 junction.setPluckPosition(pluckPos); |
chris@164 | 60 |
chris@164 | 61 } |
chris@164 | 62 |
chris@164 | 63 void String::setGlobalPosition(float pos) { |
chris@164 | 64 |
chris@164 | 65 _globalPosition = pos; |
chris@164 | 66 |
chris@164 | 67 } |
chris@164 | 68 |
chris@164 | 69 float String::getGlobalPosition() { |
chris@164 | 70 |
chris@164 | 71 return _globalPosition; |
chris@164 | 72 |
chris@164 | 73 } |
chris@164 | 74 |
chris@164 | 75 void String::setMidinote(float midinote) { |
chris@164 | 76 |
chris@164 | 77 float frequency = 440.0f*(float)powf(2,(midinote-57)/12.0f); |
chris@164 | 78 |
chris@164 | 79 junction.setFrequency(frequency); |
chris@164 | 80 wg_l.setFrequency(frequency); |
chris@164 | 81 wg_r.setFrequency(frequency); |
chris@164 | 82 |
chris@164 | 83 } |
chris@164 | 84 |
chris@164 | 85 void String::setFrequency(float frequency) { |
chris@164 | 86 |
chris@164 | 87 junction.setFrequency(frequency); |
chris@164 | 88 wg_l.setFrequency(frequency); |
chris@164 | 89 wg_r.setFrequency(frequency); |
chris@164 | 90 |
chris@164 | 91 } |