krmax44 / clef.ninja

Train reading music the fun way.
https://clef.ninja
MIT License
4 stars 0 forks source link

Note recognition from sound #6

Open niccokunzmann opened 4 years ago

niccokunzmann commented 4 years ago

I would like to the app recognize the sound I play on the guitar. A lot for reading: http://www.dspguide.com

This is what I worked on: https://github.com/niccokunzmann/positioning_system

Essentially, you multiply the audio signal with a sine and a cosine wave of the note. You sum it up over the time span when you like to recognize it. This results in the square strength of the note. If you use integers, you do not loose precision and the operations do not cost much. You can reply here or write @niccokunzmann to ask me.

krmax44 commented 4 years ago

Great input, thanks :pray:

krmax44 commented 4 years ago

@niccokunzmann I've think I understood most of your code (quite well documented, thanks a lot!) and I'm currently trying to port it to the app. I'm unsure though what samples per wave cycle are:

https://github.com/niccokunzmann/positioning_system/blob/ffeb9d52eefcba551493703791fc4474d61cf96c/wave_detection/wave_detection.ino#L57

Is it just another word for sample rate or does it mean something completely different?

krmax44 commented 4 years ago

I'm able to detect 8000Hz, take a look :tada: https://d1o1i.csb.app Testing it with a tone generator app, I get spikes up to 80,000, where as a couple hundreds of Hz less (aka a semitone), I only get peaks of 6,000. With no tone, it's sitting at ~1,000. Pretty neat!

The only thing I now have to figure out is how to change the frequency that I want to detect (which seems to be determined by the samples per wave cycles that I don't understand yet).

niccokunzmann commented 4 years ago

A usual sampling rate would be 44khz = 44000 values of microphone positions called "samples". If you want to have a 440 hz tone "a", your samples per wave length is 100. 100*440 = 44000. This means that the sine wave of the 400hz tone will start again after 100 samples.

The reason why I pre-compute the sine wave is that the sin() command is quite costly.

Could I bring clarity?

niccokunzmann commented 4 years ago

There should be several challenges ahead until this works smoothly in the app - overtone, tone disctinction, disctinction of tones from silence, ...

krmax44 commented 4 years ago

Yup, that makes sense! I'll give it a shot tomorrow. I'm worried about those issues as well, but I hope I can come up with some solutions around them (collecting averages, listening for more than one frequency, user calibration) and well... also implement them. Thanks for your help!

niccokunzmann commented 4 years ago

I will be there watching and helping. Once this works, I take my guitar to use the webapp.