Hi, this is my first post here and was hoping you guys may be able to help me out :-) I'm currently working on a project at uni to transcribe musical notes from a recording. At the minute I'm trying to calculate the frequency of a single note from a wave file. So far using C++ I have read in the headers etc and have reached the data chunk. However, I'm not sure what I need to do with the data to be able to perform an FFT! Can I just read each bit of the data into an array and do an FFT on that or does the bits per sample have to be taken into account (eg put 16bits into each array element if the bps is 16)? I am currently using the implementation of the fft outline at http://www.codeproject.com/cpp/howtofft.asp and have had some successes. Currently analysis a clip of Middle C (freq 261Hz) I get a result of 449hz but analysis the same note from a recording of my guitar yields crazy results such as 16000hz (!) and I don't know what could be the issue.
WAVE file analysis and FFT
Started by ●October 21, 2007
Reply by ●October 21, 20072007-10-21
On Sun, 21 Oct 2007 19:20:19 -0500, Irie wrote:> Hi, this is my first post here and was hoping you guys may be able to help > me out :-) I'm currently working on a project at uni to transcribe musical > notes from a recording. At the minute I'm trying to calculate the frequency > of a single note from a wave file. So far using C++ I have read in the > headers etc and have reached the data chunk. However, I'm not sure what I > need to do with the data to be able to perform an FFT! Can I just read each > bit of the data into an array and do an FFT on that or does the bits per > sample have to be taken into account (eg put 16bits into each array > element if the bps is 16)?Your array needs to be of properly formed samples, so yes you need to take the bits/sample into account. Like good lab practice, good programming practice involving data acquisition says that you should make a check plot. So once you've gotten your data, toss it up on a graph and compare it to what you see on an oscilloscope clipped onto the microphone leads, to make sure it looks about right. Then do your FFT.> I am currently using the implementation of the fft outline at > http://www.codeproject.com/cpp/howtofft.asp and have had some successes. > Currently analysis a clip of Middle C (freq 261Hz) I get a result of > 449hz but analysis the same note from a recording of my guitar yields > crazy results such as 16000hz (!) and I don't know what could be the > issue.In the first case it sounds like you're not reporting your sample rate correctly to the FFT routine, or like your data is crap. In the second case, it sounds like crap data. Were I going to do something like this, I'd use Scilab or MATLAB to prototype my algorithms. Only when I had them working in mathemagic land would I start messing around with C or C++. For mathematically intensive work like this there's about a 10:1 ratio of effective work that you can get done with one of the above programs vs. flailing around with doing the math in C or C++. -- Tim Wescott Control systems and communications consulting http://www.wescottdesign.com Need to learn how to apply control theory in your embedded system? "Applied Control Theory for Embedded Systems" by Tim Wescott Elsevier/Newnes, http://www.wescottdesign.com/actfes/actfes.html
Reply by ●October 22, 20072007-10-22
Hello, I have some Matlab example code here, maybe it's useful: http://www.elisanet.fi/mnentwig/webroot/FFT_peaksearch_audio_example/index.html -mn
Reply by ●October 22, 20072007-10-22
Irie wrote:> Hi, this is my first post here and was hoping you guys may be able to help > me out :-) I'm currently working on a project at uni to transcribe musical > notes from a recording. At the minute I'm trying to calculate the > frequency of a single note from a wave file. So far using C++ I have read > in the > headers etc and have reached the data chunk. However, I'm not sure what I > need to do with the data to be able to perform an FFT! Can I just read > each bit of the data into an array and do an FFT on that or does the bits > per sample have to be taken into account (eg put 16bits into each array > element if the bps is 16)?You have to take care of the bps. I recommend to use libsndfile for reading audio files, then you don't have to care about these details: http://www.mega-nerd.com/libsndfile Tschau Andreas -- Andreas H�nnebeck | email: acmh@gmx.de ----- privat ---- | www : http://www.huennebeck-online.de Fax/Anrufbeantworter: 0721/151-284301 GPG-Key: http://www.huennebeck-online.de/public_keys/andreas.asc PGP-Key: http://www.huennebeck-online.de/public_keys/pgp_andreas.asc
Reply by ●October 22, 20072007-10-22
On Oct 21, 5:20 pm, "Irie" <headshredder...@yahoo.co.uk> wrote:> Hi, this is my first post here and was hoping you guys may be able to help > me out :-) I'm currently working on a project at uni to transcribe musical > notes from a recording. At the minute I'm trying to calculate the frequency > of a single note from a wave file. So far using C++ I have read in the > headers etc and have reached the data chunk. However, I'm not sure what I > need to do with the data to be able to perform an FFT! Can I just read each > bit of the data into an array and do an FFT on that or does the bits per > sample have to be taken into account (eg put 16bits into each array > element if the bps is 16)? > > I am currently using the implementation of the fft outline athttp://www.codeproject.com/cpp/howtofft.aspand have had some successes. > Currently analysis a clip of Middle C (freq 261Hz) I get a result of 449hz > but analysis the same note from a recording of my guitar yields crazy > results such as 16000hz (!) and I don't know what could be the issue.Even after you get your file format parsing and FFT algorithms debugged, there is another bigger issue. The result from a single FFT and the frequencies for "notes from a recording" are often neither identically nor even simply related, even more so for guitar recordings. You may have to consider transients, interfering resonances, evolving harmonic content, string inharmonicity, microphone frequency response curves, and FFT windowing artifacts, among other effects. IMHO. YMMV. -- rhn A.T nicholson d.0.t C-o-M
Reply by ●October 22, 20072007-10-22
Irie wrote:> Hi, this is my first post here and was hoping you guys may be able to help > me out :-)I hope this is your first and last post here.> I'm currently working on a project at uni to transcribe musical > notes from a recording.Forget it it will never work. VLV
Reply by ●October 23, 20072007-10-23
Change your project to another one. It will never work properly. One can't simply decompose music artwork into FFT. To handle ART one has to apply similar level math ART. So, it's much better just to play/ learn these music yourself ... Nordic regards, Yuri
Reply by ●October 23, 20072007-10-23
I could imagine that building a tool to *assist* writing down musical scores is well within the scope of a project work: - understand FFT and related things - demonstrate what can be done - discuss the limitations Tracking a monophonic tune is rather straightforward (there is plenty of "prior art" on the web). A general solution that works with Britney Spears is a completely different problem. -mn PS: If I were to give the task for a study project (not a real thesis!), my requirements could be as follows: - FFT-based waterfall display in sync with audio playback - connect a MIDI keyboard - when pushing a note on the keyboard, show the fundamental and harmonics on the waterfall display
Reply by ●October 23, 20072007-10-23
Sure, it could be basic tone analyzer project. Use MATLAB to open and fft audio files first, it reads them directly. Yuri
Reply by ●October 23, 20072007-10-23
On Oct 22, 1:45 pm, Vladimir Vassilevsky <antispam_bo...@hotmail.com> wrote:> > I'm currently working on a project at uni to transcribe musical > > notes from a recording. > > Forget it it will never work....which is exactly why this might be a good student project assignment. One can learn a lot from projects which fail, or projects that look like they might work given very simple test cases but not in the general case or in the real world. This type of project has the additional feature that it might require a multidisciplinary study of several fields, perhaps including some basic music theory, perceptual psychology, the physics of sound, dsp as well as statistical pattern matching techniques, programming file handlers, and etc. IMHO. YMMV. -- rhn A.T nicholson d.0.t C-o-M






