A program to automatically tune a guitar. Written by Justin Reidhead and Steven Swenson

Dependencies:   FFT FrequencyFinder Motor NewTextLCD PinDetect mbed strings

Files at this revision

API Documentation at this revision

Comitter:
melangeaddict
Date:
Wed Aug 13 00:37:33 2014 +0000
Parent:
14:fd59e7acf2e5
Commit message:
Final version of Guitar Tuner by Justin Reidhead and Steven Swenson

Changed in this revision

FFT.lib Show annotated file Show diff for this revision Revisions of this file
FrequencyFinder.lib Show annotated file Show diff for this revision Revisions of this file
FrequencyFinder/.lib Show diff for this revision Revisions of this file
FrequencyFinder/FrequencyFinder.cpp Show diff for this revision Revisions of this file
FrequencyFinder/FrequencyFinder.h Show diff for this revision Revisions of this file
Motor.lib Show annotated file Show diff for this revision Revisions of this file
Motor/.lib Show diff for this revision Revisions of this file
Motor/Motor.cpp Show diff for this revision Revisions of this file
Motor/Motor.h Show diff for this revision Revisions of this file
NewTextLCD.lib Show annotated file Show diff for this revision Revisions of this file
PinDetect.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
mbed.lib Show diff for this revision Revisions of this file
strings.lib Show annotated file Show diff for this revision Revisions of this file
strings/.lib Show diff for this revision Revisions of this file
strings/strings.cpp Show diff for this revision Revisions of this file
strings/strings.h Show diff for this revision Revisions of this file
--- a/FFT.lib	Thu Apr 26 22:20:53 2012 +0000
+++ b/FFT.lib	Wed Aug 13 00:37:33 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/Suky/libraries/FFT/lmedn0
\ No newline at end of file
+http://mbed.org/users/Suky/code/FFT/#e3af07c00c13
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FrequencyFinder.lib	Wed Aug 13 00:37:33 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/melangeaddict/code/FrequencyFinder/#78c2ee8ea962
--- a/FrequencyFinder/.lib	Thu Apr 26 22:20:53 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
- 
\ No newline at end of file
--- a/FrequencyFinder/FrequencyFinder.cpp	Thu Apr 26 22:20:53 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,107 +0,0 @@
-#include "FrequencyFinder.h"
-
-using namespace std;
-
-FrequencyFinder::FrequencyFinder(PinName input) : _signal_in(input), _dc_offset(p18) {
-    index=0;
-    peak=0;
-    frequency_final=0;
-}
-
-FrequencyFinder::~FrequencyFinder() {
-    ticker.detach();
-}
-
-float FrequencyFinder::find_frequency() {
-    initialize_array();
-    ticker.attach_us(this, &FrequencyFinder::get_data,500);
-
-    wait(1);
-    ticker.detach();
-
-    copy_data();
-
-    vRealFFT(signal_array,size);
-
-    take_abs();
-
-    int peak = find_peak();
-
-    float frequency_final=((float)peak)/4.1;
-
-    return frequency_final;
-}
-
-void FrequencyFinder::get_data() {
-    if (index<size) {
-        signal_array[index]=_signal_in.read();//-0.5;
-        index++;
-    }
-}
-
-void FrequencyFinder::take_abs() {
-//takes the absolute value of the signal
-    for (int j=0; j<size; j++) {
-        signal_array[j]=abs(signal_array[j]);
-        if (j<200)//~48Hz
-            signal_array[j]=0;
-        else if (j<400)//~97Hz
-            signal_array[j]=signal_array[j]*3;
-        else if (j<550)//~
-            signal_array[j]=signal_array[j]*6;
-        else if (j<900)//~219Hz
-            signal_array[j]=signal_array[j]*10;
-        else if (j<1200)//292Hz
-            signal_array[j]=signal_array[j]*12;
-        else
-            signal_array[j]=signal_array[j]*30;
-    }
-}
-
-int FrequencyFinder::find_peak() {
-    int i=0;
-
-    for (int j=0; j<size; j++) {
-        if ((signal_array[i]-signal_array[i-1])>100 ) {
-            while (
-                (signal_array[i]<=signal_array[i+1]) &&
-                (signal_array[i]<=signal_array[i+2]) &&
-                (signal_array[i]<=signal_array[i+3]) &&
-                (signal_array[i]<=signal_array[i+4])) {
-                i++;
-            }
-            return FrequencyFinder::find_max(i);
-        }
-        i++;
-    }
-    return FrequencyFinder::find_max(i);
-}
-
-int FrequencyFinder::find_max(int position) {
-    int index1=position-20;
-    int index2=position+20;
-    float max=signal_array[index1];
-    int max_index=0;
-
-    for (int a=index1; a<index2; a++) {
-        if (signal_array[a]>max) {
-            max=signal_array[a];
-            max_index=a;
-        }
-    }
-
-    return max_index;
-}
-
-void FrequencyFinder::initialize_array() {
-    index=0;
-    for (int w=0; w<size; w++) {
-        signal_array[w]=0;
-    }
-}
-
-void FrequencyFinder::copy_data() {
-    for (int i=0; i<size/2; i++) {
-        signal_array[i+(size/2)]=signal_array[i];
-    }
-}
\ No newline at end of file
--- a/FrequencyFinder/FrequencyFinder.h	Thu Apr 26 22:20:53 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-#pragma once
-#include "mbed.h"
-#include "FFT.h"
-
-#include "NewTextLCD.h"
-
-using namespace std;
-
-const int size=4096;
-
-class FrequencyFinder{
-public:
-
-FrequencyFinder(PinName input);
-~FrequencyFinder();
-
-float find_frequency();
-void get_data();
-void take_abs();
-int find_peak();
-int find_max(int);
-void initialize_array();
-void copy_data();
-
-private:
-    float signal_array[size];
-    int index;
-    int peak;
-    int frequency_final;
-    
-    Ticker ticker;
-    AnalogIn _signal_in;
-    AnalogOut _dc_offset;
-   
-};
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Motor.lib	Wed Aug 13 00:37:33 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/melangeaddict/code/Motor/#278f07b2be46
--- a/Motor/.lib	Thu Apr 26 22:20:53 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
- 
\ No newline at end of file
--- a/Motor/Motor.cpp	Thu Apr 26 22:20:53 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-#include "Motor.h"
-
-Motor::Motor(PinName enable,PinName direction,PinName step) : _enable(enable), _direction(direction), _step(step) {
-_enable=1;
-}
-
-Motor::~Motor() {
-}
-
-void Motor::motor_turn(int direction, int steps) {
-    _enable=0;
-    float freq=600;//frequency of PWM signal to drive stepper motor
-    _step.period(1/freq);
-    _step.write(.5);
-    _direction=direction;
-    wait(steps*(1/freq));
-    _step.write(0);
-    _enable=1;
-}
\ No newline at end of file
--- a/Motor/Motor.h	Thu Apr 26 22:20:53 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
-#pragma once
-#include "mbed.h"
-#include "string.h"
-
-using namespace std;
-
-class Motor {
-
-public:
-
-    Motor(PinName enable,PinName direction,PinName step);
-    ~Motor();
-
-    void motor_turn(int, int);
-
-private:
-    DigitalOut _enable;
-    DigitalOut _direction;
-    PwmOut _step;
-};
\ No newline at end of file
--- a/NewTextLCD.lib	Thu Apr 26 22:20:53 2012 +0000
+++ b/NewTextLCD.lib	Wed Aug 13 00:37:33 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/erik_kedo/libraries/NewTextLCD/lornxk
\ No newline at end of file
+http://mbed.org/users/erik_kedo/code/NewTextLCD/#fb402d95983d
--- a/PinDetect.lib	Thu Apr 26 22:20:53 2012 +0000
+++ b/PinDetect.lib	Wed Aug 13 00:37:33 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/AjK/libraries/PinDetect/lkyxpw
\ No newline at end of file
+http://mbed.org/users/AjK/code/PinDetect/#cb3afc45028b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Aug 13 00:37:33 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/737756e0b479
\ No newline at end of file
--- a/mbed.lib	Thu Apr 26 22:20:53 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/projects/libraries/svn/mbed/trunk@43
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/strings.lib	Wed Aug 13 00:37:33 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/melangeaddict/code/strings/#ed8fce1752f7
--- a/strings/.lib	Thu Apr 26 22:20:53 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
- 
\ No newline at end of file
--- a/strings/strings.cpp	Thu Apr 26 22:20:53 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,165 +0,0 @@
-#include "strings.h"
-
-strings::strings() {
-
-}
-
-strings::strings(int string_num) {
-    set_values(string_num);
-}
-
-strings::~strings(void) {
-
-}
-
-void strings::set_values(int string_num) {
-    index=4;
-    switch (string_num) {
-        case 6:
-            frequencies[0]=65.4;
-            frequencies[1]=69.3;
-            frequencies[2]=73.4;
-            frequencies[3]=77.7;
-            frequencies[4]=82.4;
-            frequencies[5]=87.3;
-            frequencies[6]=92.5;
-            frequencies[7]=98;
-            frequencies[8]=103.8;
-            notes[0]="C";
-            notes[1]="C#";
-            notes[2]="D";
-            notes[3]="D#";
-            notes[4]="E";
-            notes[5]="F";
-            notes[6]="F#";
-            notes[7]="G";
-            notes[8]="G#";
-            break;
-
-        case 5:
-            frequencies[0]=87.3;
-            frequencies[1]=92.5;
-            frequencies[2]=98;
-            frequencies[3]=103.8;
-            frequencies[4]=110;
-            frequencies[5]=116.5;
-            frequencies[6]=123.4;
-            frequencies[7]=130.8;
-            frequencies[8]=138.6;
-            notes[0]="F";
-            notes[1]="F#";
-            notes[2]="G";
-            notes[3]="G#";
-            notes[4]="A";
-            notes[5]="A#";
-            notes[6]="B";
-            notes[7]="C";
-            notes[8]="C#";
-            break;
-
-        case 4:
-            frequencies[0]=116.5;
-            frequencies[1]=123.4;
-            frequencies[2]=130.8;
-            frequencies[3]=138.6;
-            frequencies[4]=146.8;
-            frequencies[5]=155.56;
-            frequencies[6]=164.8;
-            frequencies[7]=174.6;
-            frequencies[8]=184.9;
-            notes[0]="A#";
-            notes[1]="B";
-            notes[2]="C";
-            notes[3]="C#";
-            notes[4]="D";
-            notes[5]="D#";
-            notes[6]="E";
-            notes[7]="F";
-            notes[8]="F#";
-            break;
-
-        case 3:
-            frequencies[0]=155.6;
-            frequencies[1]=164.8;
-            frequencies[2]=174.6;
-            frequencies[3]=184.9;
-            frequencies[4]=195.9;
-            frequencies[5]=207.6;
-            frequencies[6]=220;
-            frequencies[7]=233.1;
-            frequencies[8]=246.9;
-            notes[0]="D#";
-            notes[1]="E";
-            notes[2]="F";
-            notes[3]="F#";
-            notes[4]="G";
-            notes[5]="G#";
-            notes[6]="A";
-            notes[7]="A#";
-            notes[8]="B";
-            break;
-
-        case 2:
-            frequencies[0]=195.9;
-            frequencies[1]=207.6;
-            frequencies[2]=220;
-            frequencies[3]=233.1;
-            frequencies[4]=246.9;
-            frequencies[5]=261.6;
-            frequencies[6]=277.1;
-            frequencies[7]=293.6;
-            frequencies[8]=311.1;
-            notes[0]="G";
-            notes[1]="G#";
-            notes[2]="A";
-            notes[3]="A#";
-            notes[4]="B";
-            notes[5]="C";
-            notes[6]="C#";
-            notes[7]="D";
-            notes[8]="D#";
-            break;
-
-        case 1:
-            frequencies[0]=261.6;
-            frequencies[1]=277.1;
-            frequencies[2]=293.6;
-            frequencies[3]=311.1;
-            frequencies[4]=329.6;
-            frequencies[5]=349.2;
-            frequencies[6]=369.9;
-            frequencies[7]=391.9;
-            frequencies[8]=415.3;
-            notes[0]="C";
-            notes[1]="C#";
-            notes[2]="D";
-            notes[3]="D#";
-            notes[4]="E";
-            notes[5]="F";
-            notes[6]="F#";
-            notes[7]="G";
-            notes[8]="G#";
-            break;
-
-        default:
-            break;
-    }
-}
-
-void strings::inc_index() {
-    index++;
-    if (index>=9)
-        index=0;
-}
-
-void strings::reset_index(){
-    index=4;
-}
-
-char* strings::get_note() {
-    return notes[index];
-}
-
-float strings::get_freq() {
-    return frequencies[index];
-}
--- a/strings/strings.h	Thu Apr 26 22:20:53 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,24 +0,0 @@
-#pragma once
-#include "string"
-
-class strings
-{
-public:
-    strings(int string_num);
-    strings();
-    ~strings(void);
-
-    void inc_index();
-    void reset_index();
-    char* get_note();
-    float get_freq();
-    
-    protected:
-    void set_values(int string_num);
-
-private:
-    float frequencies[9];
-    char *notes [9];
-    int index;
-    float threshold[6];
-};