Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect string when pitch-tracking on electric guitar?

Hi I'm a noob in audio related coding and I'm working in a pitch tracking DLL that I will use to try to create a sort of open-source version of the video-game Rocksmith as a learning experience.

So far I have managed to get the FFT to work so I can detect pitch frequency (Hz) then by using an algorithm and the table below I can manage to determine the octave (2th to 6th) and the note (C to B) for played note.

The next step is to detect the string so I can determine the fret.

enter image description here

I've been thinking about it and in theory I can work with this, I will know when the user is playing the right note but the game could be "Hack" because by just using the Hz the game is not able to detect if a note is played in the right string. For example 5th string + 1th fret = C4 261.63Hz is equals to 6th string + 5th fret = C4 261.63Hz.

The chances of having an user playing a note in the wrong string and getting it right is low, but I think it would be really good to know the string so I can provide to the users some error feedback when they play the wrong string (Like you should go a string up or down).

Do you know what can I do to detect the string? Thanks in advance :)

[edit]

The guitar and strings that we are using affect the timbre so analyzing the timbre seems to not be a easy way of detecting strings:

"Variations in timbre on your guitar are produced by an enormous number of factors from pickup design and position, the natural resonances and damping in your guitar due to the wood used (that's a different sort of timber!) and its construction and shape, the gauge and age of your strings, your playing technique, where you fret and pluck the string, and so on."

like image 814
Remo H. Jansen Avatar asked Sep 09 '13 08:09

Remo H. Jansen


1 Answers

This might be a little bit late because the post is one years old. But here's a solution, which I found out after long research for pitch detecting a guitar.

THIS IS WHY FFT DOESN'T WORK :

You cannot use FFT since the result gives you a linear array, and the sound is calculated logarithmically (exponential distance between notes). Plus, FFT gives you an array of bins in which your frequency COULD BE, it doesnt give you the precise result.

THIS IS WHAT I SUGGEST :

Use dywapitchtrack. it's a library that uses a wavelet algorythm, which works directly on your wave instead of calculating large bins like FFT.

description: The dywapitchtrack is based on a custom-tailored algorithm which is of very high quality: both very accurate (precision < 0.05 semitones), very low latency (< 23 ms) and very low error rate. It has been thoroughly tested on human voice. It can best be described as a dynamic wavelet algorithm (dywa):

DOWNLOAD : https://github.com/inniyah/sndpeek/tree/master/src/dywapitchtrack

USE(C++): put the .c and .h where you need it and import it in your project

include the header file

//Create a dywapitchtracker Object
dywapitchtracker pitchtracker;

//Initialise the object with this function
dywapitch_inittracking(&pitchtracker);

When your buffer is full (buffer needs to be at 44100 resolution and power of 2 of length, mine is 2048):

//use this function with your buffer
double thePitch = dywapitch_computepitch(&pitchtracker, yourBuffer, 0, 2048);

And voilà, thePitch contains precisely what you need. (feel free to ask question if something is unclear)

like image 61
s.1.618 Avatar answered Sep 22 '22 16:09

s.1.618