Pages: [1]   Go Down
Author Topic: Note Detector  (Read 4955 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay! So, while I was thinking about  audio spectrum analyzers (which is another project I wish to do), I thought of a note detector! Now I know these already are a thing. But not the one I've thought up, I want to make a note detector, setup like an audio spectrum analyzer, ya know with the LED bars and everything. But instead of frequency's can it do notes? Say you plug it into your computer through the audio jack and you play a song, and it display's what notes are being played and the DB's as well. If you need me to clarify I would be glad to. And if you know how to make it work, please inform me! 
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12465
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

you can determine the frequency (google FFT) then you can use a lookup table to find the nearest note.

or read - http://www.instructables.com/id/Reliable-Frequency-Detection-Using-DSP-Techniques -
plus
Code:
//
//    FILE: nearestSearchInArray.ino
//  AUTHOR: Rob Tillaart
// VERSION: 0.1.00
// PURPOSE: demo
//    DATE: 2013-12-27
//     URL:
//
// Released to the public domain
//

int ar[5] = {
  100, 300, 500, 700, 900 };

void setup()
{
  Serial.begin(115200);
  Serial.println("Start ");
}

void loop()
{
  int x = analogRead(A0);

  int y = search(x);
  Serial.print(x);
  Serial.print(" -> ");
  Serial.println(y);
}

int search(int x)
{
  // initially the first one is the best.
  int idx = 0;
  int minDistance = abs(x - ar[0]);
  for (int i=0; i<5; i++)
  {
    int d = abs(x - ar[i]);
    if (d < minDistance)
    {
      idx = i;
      minDistance = d;
    }
  }
  return ar[idx]; // minDistance;  // or idx;  if you want the index
}


Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Awesome! thanks for the great code! now. All I need is to know how to build it. The arduino has only so many inputs for the LED's. If I would want to make LED bars with many segments per bar. how would I get them to all operate?
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12465
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

google multiplexer arduino

Or google arduino shiftOut()
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: