Mercurial > hg > beaglert
comparison 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 |
comparison
equal
deleted
inserted
replaced
463:c47709e8b5c9 | 464:8fcfbfb32aa0 |
---|---|
1 /* | |
2 * | |
3 * 1-D string consisting of two waveguides and junction | |
4 * | |
5 * Christian Heinrichs 04/2015 | |
6 * | |
7 */ | |
8 | |
9 #include "String.h" | |
10 #include "Junction.h" | |
11 #include "Waveguide.h" | |
12 | |
13 #include "../include/Utilities.h" | |
14 #include <rtdk.h> | |
15 #include <cmath> | |
16 #include <stdio.h> | |
17 #include <cstdlib> | |
18 | |
19 String::String(){ | |
20 | |
21 wg_l = Waveguide(); | |
22 wg_r = Waveguide(); | |
23 junction = Junction(); | |
24 | |
25 junction.setPluckPosition(0.5); | |
26 | |
27 _previous_l = 0; | |
28 _previous_r = 0; | |
29 | |
30 } | |
31 | |
32 float String::update(float in) { | |
33 | |
34 // 1. send excitation signal and previous waveguide outputs into junction | |
35 | |
36 junction.update(in,_previous_l,_previous_r); | |
37 | |
38 // 2. save new waveguide outputs for next iteration | |
39 | |
40 _previous_l = wg_l.update(junction.getOutput(0)); | |
41 _previous_r = wg_r.update(junction.getOutput(1)); | |
42 | |
43 // 3. use right waveguide as output | |
44 | |
45 //rt_printf("BANANA %f ",_readPtr); | |
46 //rt_printf("%f\n",_previous_r); | |
47 | |
48 return _previous_r; | |
49 } | |
50 | |
51 float String::getPlectrumDisplacement() { | |
52 | |
53 return junction.getExcitationDisplacement(); | |
54 | |
55 } | |
56 | |
57 void String::setPluckPosition(float pluckPos){ | |
58 | |
59 junction.setPluckPosition(pluckPos); | |
60 | |
61 } | |
62 | |
63 void String::setGlobalPosition(float pos) { | |
64 | |
65 _globalPosition = pos; | |
66 | |
67 } | |
68 | |
69 float String::getGlobalPosition() { | |
70 | |
71 return _globalPosition; | |
72 | |
73 } | |
74 | |
75 void String::setMidinote(float midinote) { | |
76 | |
77 float frequency = 440.0f*(float)powf(2,(midinote-57)/12.0f); | |
78 | |
79 junction.setFrequency(frequency); | |
80 wg_l.setFrequency(frequency); | |
81 wg_r.setFrequency(frequency); | |
82 | |
83 } | |
84 | |
85 void String::setFrequency(float frequency) { | |
86 | |
87 junction.setFrequency(frequency); | |
88 wg_l.setFrequency(frequency); | |
89 wg_r.setFrequency(frequency); | |
90 | |
91 } |