Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of GT_Tuner by
Revision 1:ae7d0cf78b3e, committed 2011-10-26
- Comitter:
- adurand
- Date:
- Wed Oct 26 02:01:28 2011 +0000
- Parent:
- 0:490e67fb09c2
- Child:
- 2:0b7bf57470c4
- Commit message:
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Oct 24 23:03:27 2011 +0000
+++ b/main.cpp Wed Oct 26 02:01:28 2011 +0000
@@ -8,7 +8,7 @@
#include "mbed.h"
#include "adc.h"
#include "NokiaLCD.h"
-
+#include <math.h>
#define PI 3.1415
#define SAMPLE_RATE 24000
@@ -20,8 +20,8 @@
//LCD and Other Random Variables
NokiaLCD lcd(p5, p7, p8, p9, NokiaLCD::LCD6610); // mosi, sclk, cs, rst, type
int string_select = 0;
-float high, high1, high2, high3, high4, high5, high6, high7, high8, in_tune, in_tune1, in_tune2, in_tune3,
-low, low1, low2, low3, low4, low5, low6, low7, low8, note;
+float high, high1, in_tune, in_tune1, in_tune2, in_tune3,
+low, low1, note, low_mod, high_mod;
char* key;
int Counter = 0;
int Buffer[6000];
@@ -112,30 +112,31 @@
SAMPLE_RATE, actual_rate);
printf("We did %i samples\n",Counter);
- high1 = goertzelFilter(Buffer, (note+18), Counter);
- high2 = goertzelFilter(Buffer, (note+16), Counter);
- high3 = goertzelFilter(Buffer, (note+14), Counter);
- high4 = goertzelFilter(Buffer, (note+12), Counter);
- high5 = goertzelFilter(Buffer, (note+10), Counter);
- high6 = goertzelFilter(Buffer, (note+8), Counter);
- high7 = goertzelFilter(Buffer, (note+6), Counter);
- high8 = goertzelFilter(Buffer, (note+4), Counter);
- in_tune1 = goertzelFilter(Buffer, (note+0.5), Counter);
+high = 0;
+low = 0;
+for (int i=3; i<46; i+=3) {
+ high1 = goertzelFilter(Buffer, (note + i ), Counter);
+ if (high1 > high) high=high1;
+}
+for (int i=3; i<46; i+=3) {
+ low1 = goertzelFilter(Buffer, (note - i ), Counter);
+ if (low1 > low) low=low1;
+}
+ in_tune1 = goertzelFilter(Buffer, (note+1), Counter);
in_tune2 = goertzelFilter(Buffer, note, Counter);
- in_tune3 = goertzelFilter(Buffer, (note-0.5), Counter);
- low1 = goertzelFilter(Buffer, (note-4), Counter);
- low2 = goertzelFilter(Buffer, (note-6), Counter);
- low3 = goertzelFilter(Buffer, (note-8), Counter);
- low4 = goertzelFilter(Buffer, (note-10), Counter);
- low5 = goertzelFilter(Buffer, (note-12), Counter);
- low6 = goertzelFilter(Buffer, (note-14), Counter);
- low7 = goertzelFilter(Buffer, (note-16), Counter);
- low8 = goertzelFilter(Buffer, (note-18), Counter);
-
- in_tune = (in_tune1 + in_tune2 + in_tune3)/3;
- high = (high1 + high2 + high3 + high4 + high5 + high6 + high7 + high8)/8;
- low = (low1 + low2 + low3 + low4 + low5 + low6 + low7 + low8)/8;
-
+ in_tune3 = goertzelFilter(Buffer, (note-1), Counter);
+
+ if ((in_tune1 > in_tune2) && (in_tune1 > in_tune3)) in_tune = in_tune1;
+ else if ((in_tune2 > in_tune1) && (in_tune2 > in_tune3)) in_tune = in_tune2;
+ else in_tune = in_tune3;
+ // printf("high = %.2f, low = %.2f, in_tune = %.2f", high, low, in_tune);
+// high_mod = high/in_tune;
+ // low_mod = low/in_tune;
+ // if ((high_mod > .8)&&(low_mod > .8)) {
+ // led_high = 0;
+ // led_ok = 0;
+ // led_low = 0;
+ // }
if ((in_tune > high) && (in_tune > low)) {
led_high = 0;
led_ok = 1;
@@ -152,9 +153,8 @@
led_high = 0;
led_ok = 0;
led_low = 0;
-
}
-
+
// Display on the LCD
lcd.locate(0,1);
lcd.printf("::Guitar Tuner::");
@@ -166,7 +166,7 @@
if (led_ok) lcd.printf("In Tune!");
else if (led_low) lcd.printf("Too Low ");
else if (led_high) lcd.printf("Too High");
- else lcd.printf("~~~~~");
+ else lcd.printf("~~~~~~~~");
Counter = 0;
