You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
duff2013 2bd0f198d4 update 9 years ago
examples update 9 years ago
AudioTuner.cpp update 9 years ago
AudioTuner.h update 9 years ago
README.md update 9 years ago
keywords.txt update 9 years ago
library.properties update 9 years ago
revision.md update 9 years ago

README.md

Guitar and Bass Tuner Library v2.2
Teensy 3.1/2

Software algorithm (YIN) for guitar and bass tuning using a Teensy Audio Library. This audio object’s algorithm can be some what memory and processor hungry but will allow you to detect with fairly good accuracy the fundamental frequencies fo from electric guitars and basses.

You can install this as a normal Arduino Library and will work with the Audio Library, no need to edit the Audio libraries source now.

  Hookup Guide - 1.2v DC Bias and High Pass Filter - No Amplification

                   *--------------------------------------------------*   
                   |                                                  |
                   |      Pull Down Resistor            | ' |         |
                   *------------/\/\/\-------------*    |' '|         | 
                   |             47K               |   _|_'_|_        |
                   |                               |  |` ` ` `|       |
                   *---)|+---*                     |  | ` ` ` |       |
                   |  10uF   |                     |  |` ` ` `|       |
   TEENSY 3.1      |         |                     |  | ` ` ` |       |
 _______________   *-/\/\/\--*                     |  |` ` ` `|       |
|GND |_____| Vin|  |  2.2K   |                     |  | ` ` ` |       |
|0  -----   AGND|<-*         |                     |  |` ` ` `|       |
|1 |`````|  3.3V|>---/\/\/\--*--/\/\/\--*          |  | ` ` ` |       |
|2 |     |    23|     10K        47K    |          |  |` ` ` `|       |
|3  -----     22|                       |          |  | ` ` ` |       |
|4 |'|        21|                       |          |   \=====/        |
|5   ------   20|                       |          |    | '`|         |
|6 |::::::::| 19|                       |  REMOVE  |    | S`|         |
|7 |::::::::| 18|                       |    DC    |    | H`|         |
|8 |::::::::| 17|                       |   BIAS   |    | I`|         |
|9   ------A2/16|<---SIGNAL-1.2v-BIAS---*---+|(----*    | E`|>--ANGD--*
|10    ---    15|                    1.2VDC 10uF   |    | L`|
|11   |(`)|   14|                                  |    | D`|
|12    ---    13|                                  |    |  `|
 ---------------                                   |    |===|
                                                   |     \_/
                                                   |     /T\
                                                   |    .-I-.
                                                   *---<\ P /
                                                         \_/

Many optimizations have been done to the YIN algorithm for frequencies between 29-360Hz.

While its still using a brute force method ( n2 ) for finding the fundamental frequency fo, it is tuned to skip certain tau () values and focus mostly on frequencies found in the bass and guitar.

The input is double buffered so while you are processing one buffer it is filling the other to double throughput.

There are a few parameters that can be adjusted to “dial in” the algorithm for better estimations located in AudioTuner.h. The defaults below are what I found that have the best trade off for speed and accuracy.

AudioTuner.h

/****************************************************************/
#define SAMPLE_RATE_44100  1      // 44100    sample rate
#define SAMPLE_RATE_22050  2      // 22050    sample rate
#define SAMPLE_RATE_11025  4      // 11025    sample rate
/****************************************************************/

/****************************************************************
*              Safe to adjust these values below               *
*                                                              *
*  These two parameters define how this object works.          *
*                                                              *
*  1.  NUM_SAMPLES - Size of the buffer. Since object uses     *
*      double buffering this value will be 4x in bytes of      *
*      memory.  !!! Must be power of 2 !!!!                    *
*                                                              *
*  2.  SAMPLE_RATE - Just what it says.                        *
*                                                              *
*  These two parameters work hand in hand. For example if you  *
*  want a high sample rate but do not allocate enough buffer   *
*  space, you will be limit how low of a frequency you can     *
*  measure. If you then increase the buffer you use up         *
*  precious ram and slow down the system since it takes longer *
*  to processes the buffer.                                    *
*                                                              *
*  Play around with these values to find what best suits your  *
*  needs. The max number of buffers you can have is 8192 bins. *
****************************************************************/
// !!! Must be power of 2 !!!!
#define NUM_SAMPLES 2048 // make a power of two

// Use defined sample rates above^
#define SAMPLE_RATE SAMPLE_RATE_22050
/****************************************************************/
YIN Algorithm
  1. Difference Function - Squared difference of the (signal - signal lag())
  2. Cumulative Mean Normalized Difference Function - Calculate the cumulative mean on the normalized difference signal
  3. Absolute Threshold - Fix for subharmonic error with Autocorrelation, choose () that gives a minimum