Mercurial > hg > beaglert
annotate examples/10-Instruments/airharp/String.cpp @ 556:ce391098f321 prerelease tip
THIS PROJECT HAS MOVED TO https://github.com/BelaPlatform/bela
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Sat, 25 Jun 2016 20:21:00 +0100 |
parents | 8f8809c77dda |
children |
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 return _previous_r; |
robert@464 | 46 } |
robert@464 | 47 |
robert@464 | 48 float String::getPlectrumDisplacement() { |
robert@464 | 49 |
robert@464 | 50 return junction.getExcitationDisplacement(); |
robert@464 | 51 |
robert@464 | 52 } |
robert@464 | 53 |
robert@464 | 54 void String::setPluckPosition(float pluckPos){ |
robert@464 | 55 |
robert@464 | 56 junction.setPluckPosition(pluckPos); |
robert@464 | 57 |
robert@464 | 58 } |
robert@464 | 59 |
robert@464 | 60 void String::setGlobalPosition(float pos) { |
robert@464 | 61 |
robert@464 | 62 _globalPosition = pos; |
robert@464 | 63 |
robert@464 | 64 } |
robert@464 | 65 |
robert@464 | 66 float String::getGlobalPosition() { |
robert@464 | 67 |
robert@464 | 68 return _globalPosition; |
robert@464 | 69 |
robert@464 | 70 } |
robert@464 | 71 |
robert@464 | 72 void String::setMidinote(float midinote) { |
robert@464 | 73 |
robert@464 | 74 float frequency = 440.0f*(float)powf(2,(midinote-57)/12.0f); |
robert@464 | 75 |
robert@464 | 76 junction.setFrequency(frequency); |
robert@464 | 77 wg_l.setFrequency(frequency); |
robert@464 | 78 wg_r.setFrequency(frequency); |
robert@464 | 79 |
robert@464 | 80 } |
robert@464 | 81 |
robert@464 | 82 void String::setFrequency(float frequency) { |
robert@464 | 83 |
robert@464 | 84 junction.setFrequency(frequency); |
robert@464 | 85 wg_l.setFrequency(frequency); |
robert@464 | 86 wg_r.setFrequency(frequency); |
robert@464 | 87 |
robert@464 | 88 } |