A program to automatically tune a guitar. Written by Justin Reidhead and Steven Swenson
Dependencies: FFT FrequencyFinder Motor NewTextLCD PinDetect mbed strings
strings/strings.cpp@14:fd59e7acf2e5, 2012-04-26 (annotated)
- Committer:
- melangeaddict
- Date:
- Thu Apr 26 22:20:53 2012 +0000
- Revision:
- 14:fd59e7acf2e5
- Parent:
- 5:c0fd99f07536
98% Completed; Good step numbers up and down;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
melangeaddict | 2:9c0a83c5ded5 | 1 | #include "strings.h" |
melangeaddict | 2:9c0a83c5ded5 | 2 | |
melangeaddict | 3:c672e782f19b | 3 | strings::strings() { |
melangeaddict | 2:9c0a83c5ded5 | 4 | |
melangeaddict | 3:c672e782f19b | 5 | } |
melangeaddict | 3:c672e782f19b | 6 | |
melangeaddict | 3:c672e782f19b | 7 | strings::strings(int string_num) { |
melangeaddict | 3:c672e782f19b | 8 | set_values(string_num); |
melangeaddict | 3:c672e782f19b | 9 | } |
melangeaddict | 3:c672e782f19b | 10 | |
melangeaddict | 3:c672e782f19b | 11 | strings::~strings(void) { |
melangeaddict | 3:c672e782f19b | 12 | |
melangeaddict | 3:c672e782f19b | 13 | } |
melangeaddict | 3:c672e782f19b | 14 | |
melangeaddict | 3:c672e782f19b | 15 | void strings::set_values(int string_num) { |
melangeaddict | 2:9c0a83c5ded5 | 16 | index=4; |
melangeaddict | 3:c672e782f19b | 17 | switch (string_num) { |
melangeaddict | 3:c672e782f19b | 18 | case 6: |
melangeaddict | 3:c672e782f19b | 19 | frequencies[0]=65.4; |
melangeaddict | 3:c672e782f19b | 20 | frequencies[1]=69.3; |
melangeaddict | 3:c672e782f19b | 21 | frequencies[2]=73.4; |
melangeaddict | 3:c672e782f19b | 22 | frequencies[3]=77.7; |
melangeaddict | 3:c672e782f19b | 23 | frequencies[4]=82.4; |
melangeaddict | 3:c672e782f19b | 24 | frequencies[5]=87.3; |
melangeaddict | 3:c672e782f19b | 25 | frequencies[6]=92.5; |
melangeaddict | 3:c672e782f19b | 26 | frequencies[7]=98; |
melangeaddict | 3:c672e782f19b | 27 | frequencies[8]=103.8; |
melangeaddict | 3:c672e782f19b | 28 | notes[0]="C"; |
melangeaddict | 3:c672e782f19b | 29 | notes[1]="C#"; |
melangeaddict | 3:c672e782f19b | 30 | notes[2]="D"; |
melangeaddict | 3:c672e782f19b | 31 | notes[3]="D#"; |
melangeaddict | 3:c672e782f19b | 32 | notes[4]="E"; |
melangeaddict | 3:c672e782f19b | 33 | notes[5]="F"; |
melangeaddict | 3:c672e782f19b | 34 | notes[6]="F#"; |
melangeaddict | 3:c672e782f19b | 35 | notes[7]="G"; |
melangeaddict | 3:c672e782f19b | 36 | notes[8]="G#"; |
melangeaddict | 3:c672e782f19b | 37 | break; |
melangeaddict | 2:9c0a83c5ded5 | 38 | |
melangeaddict | 3:c672e782f19b | 39 | case 5: |
melangeaddict | 3:c672e782f19b | 40 | frequencies[0]=87.3; |
melangeaddict | 3:c672e782f19b | 41 | frequencies[1]=92.5; |
melangeaddict | 3:c672e782f19b | 42 | frequencies[2]=98; |
melangeaddict | 3:c672e782f19b | 43 | frequencies[3]=103.8; |
melangeaddict | 3:c672e782f19b | 44 | frequencies[4]=110; |
melangeaddict | 3:c672e782f19b | 45 | frequencies[5]=116.5; |
melangeaddict | 3:c672e782f19b | 46 | frequencies[6]=123.4; |
melangeaddict | 3:c672e782f19b | 47 | frequencies[7]=130.8; |
melangeaddict | 3:c672e782f19b | 48 | frequencies[8]=138.6; |
melangeaddict | 3:c672e782f19b | 49 | notes[0]="F"; |
melangeaddict | 3:c672e782f19b | 50 | notes[1]="F#"; |
melangeaddict | 3:c672e782f19b | 51 | notes[2]="G"; |
melangeaddict | 3:c672e782f19b | 52 | notes[3]="G#"; |
melangeaddict | 3:c672e782f19b | 53 | notes[4]="A"; |
melangeaddict | 3:c672e782f19b | 54 | notes[5]="A#"; |
melangeaddict | 3:c672e782f19b | 55 | notes[6]="B"; |
melangeaddict | 3:c672e782f19b | 56 | notes[7]="C"; |
melangeaddict | 3:c672e782f19b | 57 | notes[8]="C#"; |
melangeaddict | 3:c672e782f19b | 58 | break; |
melangeaddict | 2:9c0a83c5ded5 | 59 | |
melangeaddict | 3:c672e782f19b | 60 | case 4: |
melangeaddict | 3:c672e782f19b | 61 | frequencies[0]=116.5; |
melangeaddict | 3:c672e782f19b | 62 | frequencies[1]=123.4; |
melangeaddict | 3:c672e782f19b | 63 | frequencies[2]=130.8; |
melangeaddict | 3:c672e782f19b | 64 | frequencies[3]=138.6; |
melangeaddict | 3:c672e782f19b | 65 | frequencies[4]=146.8; |
melangeaddict | 3:c672e782f19b | 66 | frequencies[5]=155.56; |
melangeaddict | 3:c672e782f19b | 67 | frequencies[6]=164.8; |
melangeaddict | 3:c672e782f19b | 68 | frequencies[7]=174.6; |
melangeaddict | 3:c672e782f19b | 69 | frequencies[8]=184.9; |
melangeaddict | 3:c672e782f19b | 70 | notes[0]="A#"; |
melangeaddict | 3:c672e782f19b | 71 | notes[1]="B"; |
melangeaddict | 3:c672e782f19b | 72 | notes[2]="C"; |
melangeaddict | 3:c672e782f19b | 73 | notes[3]="C#"; |
melangeaddict | 3:c672e782f19b | 74 | notes[4]="D"; |
melangeaddict | 3:c672e782f19b | 75 | notes[5]="D#"; |
melangeaddict | 3:c672e782f19b | 76 | notes[6]="E"; |
melangeaddict | 3:c672e782f19b | 77 | notes[7]="F"; |
melangeaddict | 3:c672e782f19b | 78 | notes[8]="F#"; |
melangeaddict | 3:c672e782f19b | 79 | break; |
melangeaddict | 2:9c0a83c5ded5 | 80 | |
melangeaddict | 3:c672e782f19b | 81 | case 3: |
melangeaddict | 3:c672e782f19b | 82 | frequencies[0]=155.6; |
melangeaddict | 3:c672e782f19b | 83 | frequencies[1]=164.8; |
melangeaddict | 3:c672e782f19b | 84 | frequencies[2]=174.6; |
melangeaddict | 3:c672e782f19b | 85 | frequencies[3]=184.9; |
melangeaddict | 3:c672e782f19b | 86 | frequencies[4]=195.9; |
melangeaddict | 3:c672e782f19b | 87 | frequencies[5]=207.6; |
melangeaddict | 3:c672e782f19b | 88 | frequencies[6]=220; |
melangeaddict | 3:c672e782f19b | 89 | frequencies[7]=233.1; |
melangeaddict | 3:c672e782f19b | 90 | frequencies[8]=246.9; |
melangeaddict | 3:c672e782f19b | 91 | notes[0]="D#"; |
melangeaddict | 3:c672e782f19b | 92 | notes[1]="E"; |
melangeaddict | 3:c672e782f19b | 93 | notes[2]="F"; |
melangeaddict | 3:c672e782f19b | 94 | notes[3]="F#"; |
melangeaddict | 3:c672e782f19b | 95 | notes[4]="G"; |
melangeaddict | 3:c672e782f19b | 96 | notes[5]="G#"; |
melangeaddict | 3:c672e782f19b | 97 | notes[6]="A"; |
melangeaddict | 3:c672e782f19b | 98 | notes[7]="A#"; |
melangeaddict | 3:c672e782f19b | 99 | notes[8]="B"; |
melangeaddict | 3:c672e782f19b | 100 | break; |
melangeaddict | 2:9c0a83c5ded5 | 101 | |
melangeaddict | 3:c672e782f19b | 102 | case 2: |
melangeaddict | 3:c672e782f19b | 103 | frequencies[0]=195.9; |
melangeaddict | 3:c672e782f19b | 104 | frequencies[1]=207.6; |
melangeaddict | 3:c672e782f19b | 105 | frequencies[2]=220; |
melangeaddict | 3:c672e782f19b | 106 | frequencies[3]=233.1; |
melangeaddict | 3:c672e782f19b | 107 | frequencies[4]=246.9; |
melangeaddict | 3:c672e782f19b | 108 | frequencies[5]=261.6; |
melangeaddict | 3:c672e782f19b | 109 | frequencies[6]=277.1; |
melangeaddict | 3:c672e782f19b | 110 | frequencies[7]=293.6; |
melangeaddict | 3:c672e782f19b | 111 | frequencies[8]=311.1; |
melangeaddict | 3:c672e782f19b | 112 | notes[0]="G"; |
melangeaddict | 3:c672e782f19b | 113 | notes[1]="G#"; |
melangeaddict | 3:c672e782f19b | 114 | notes[2]="A"; |
melangeaddict | 3:c672e782f19b | 115 | notes[3]="A#"; |
melangeaddict | 3:c672e782f19b | 116 | notes[4]="B"; |
melangeaddict | 3:c672e782f19b | 117 | notes[5]="C"; |
melangeaddict | 3:c672e782f19b | 118 | notes[6]="C#"; |
melangeaddict | 3:c672e782f19b | 119 | notes[7]="D"; |
melangeaddict | 3:c672e782f19b | 120 | notes[8]="D#"; |
melangeaddict | 3:c672e782f19b | 121 | break; |
melangeaddict | 2:9c0a83c5ded5 | 122 | |
melangeaddict | 3:c672e782f19b | 123 | case 1: |
melangeaddict | 3:c672e782f19b | 124 | frequencies[0]=261.6; |
melangeaddict | 3:c672e782f19b | 125 | frequencies[1]=277.1; |
melangeaddict | 3:c672e782f19b | 126 | frequencies[2]=293.6; |
melangeaddict | 3:c672e782f19b | 127 | frequencies[3]=311.1; |
melangeaddict | 3:c672e782f19b | 128 | frequencies[4]=329.6; |
melangeaddict | 3:c672e782f19b | 129 | frequencies[5]=349.2; |
melangeaddict | 3:c672e782f19b | 130 | frequencies[6]=369.9; |
melangeaddict | 3:c672e782f19b | 131 | frequencies[7]=391.9; |
melangeaddict | 3:c672e782f19b | 132 | frequencies[8]=415.3; |
melangeaddict | 3:c672e782f19b | 133 | notes[0]="C"; |
melangeaddict | 3:c672e782f19b | 134 | notes[1]="C#"; |
melangeaddict | 3:c672e782f19b | 135 | notes[2]="D"; |
melangeaddict | 3:c672e782f19b | 136 | notes[3]="D#"; |
melangeaddict | 3:c672e782f19b | 137 | notes[4]="E"; |
melangeaddict | 3:c672e782f19b | 138 | notes[5]="F"; |
melangeaddict | 3:c672e782f19b | 139 | notes[6]="F#"; |
melangeaddict | 3:c672e782f19b | 140 | notes[7]="G"; |
melangeaddict | 3:c672e782f19b | 141 | notes[8]="G#"; |
melangeaddict | 3:c672e782f19b | 142 | break; |
melangeaddict | 2:9c0a83c5ded5 | 143 | |
melangeaddict | 3:c672e782f19b | 144 | default: |
melangeaddict | 2:9c0a83c5ded5 | 145 | break; |
melangeaddict | 2:9c0a83c5ded5 | 146 | } |
melangeaddict | 2:9c0a83c5ded5 | 147 | } |
melangeaddict | 2:9c0a83c5ded5 | 148 | |
melangeaddict | 3:c672e782f19b | 149 | void strings::inc_index() { |
melangeaddict | 2:9c0a83c5ded5 | 150 | index++; |
melangeaddict | 4:e370f322a697 | 151 | if (index>=9) |
melangeaddict | 2:9c0a83c5ded5 | 152 | index=0; |
melangeaddict | 2:9c0a83c5ded5 | 153 | } |
melangeaddict | 2:9c0a83c5ded5 | 154 | |
melangeaddict | 5:c0fd99f07536 | 155 | void strings::reset_index(){ |
melangeaddict | 5:c0fd99f07536 | 156 | index=4; |
melangeaddict | 5:c0fd99f07536 | 157 | } |
melangeaddict | 5:c0fd99f07536 | 158 | |
melangeaddict | 4:e370f322a697 | 159 | char* strings::get_note() { |
melangeaddict | 2:9c0a83c5ded5 | 160 | return notes[index]; |
melangeaddict | 2:9c0a83c5ded5 | 161 | } |
melangeaddict | 2:9c0a83c5ded5 | 162 | |
melangeaddict | 3:c672e782f19b | 163 | float strings::get_freq() { |
melangeaddict | 2:9c0a83c5ded5 | 164 | return frequencies[index]; |
melangeaddict | 2:9c0a83c5ded5 | 165 | } |