Analizing an audio file?

Started by
5 comments, last by DeadXorAlive 17 years, 11 months ago
Okay so I have an idea for a program I want to make. It would require analizing an audio file. I would need to know the pitch of any specific part. The pitch can be determined by the frequency of the soundwave incase you didn't know. I was wondering how you could see what the frequency of any specific part of an audio file is? I'd perfer to know how to do this in either C++ or Java. Also if it is possible could you analize an audio file in realtime while it is being recorded? Or would it need to be a pre-existing audio file?
Advertisement
Well, you'd basically just have to load the data in manually. Basically you'd create a few different 'loaders' which would handle some specific format and would then convert them into one general form (e.g. PCM). There are resources all over the web that generally describe the file structures of various audio formats (there's likely to be a lot of code on how to load them to).

Once you have the raw data, you could scan through the it like any other array.

As far as doing it real-time, I don't see any reason why you couldn't. You would be buffering in chunks of audio data which could be scanned just like from a file, though the scanning would be done chunk at a time.
You'd also probably want to separate your recording into a separate thread to the data scanning.

Whether using java/c++ it's all the same. The 'file' method just requires that you know how to deal with binary files. The 'recording' method's complexity is really all in the recording itself (which you could probably find a nice API to do it for you anyway).
cool thanks.

Quote:Original post by JavaMava
I was wondering how you could see what the frequency of any specific part of an audio file is?


Look up (fast) fourier transform which can be used to transform your samples from the time domain to the frequency domain.
JavaMava do you think you could post your source code after you're done? I've been wanting to write a program to analyze an audio file...

Just a word of warning...
Pitch extraction from audio can be quite complicated.

Pitch == Frequency only for a very simple waveform, like a sine wave.

For anything more complex, like speech or music, it gets much more difficult to find the fundimental pitch from the many frequency components that will be present at any given time.

Some parts of the audio may have no pitch at all (unvoiced speech, noise), and some parts may have several equally promenent pitched elements forcing an arbtrary choice by your algorithm, and requiring tracking over a longer period of time.

At the very least you will need several tens of milliseconds worth of audio data to get an accurate pitch estimate, possibly several hundred; so you have to expect some latency if you are doing it in realtime.

The best algorithm to use depends on what sort of audio data you are analyzing (music?, speech?, singing? etc), but google should point you in the right direction. Try Pitch Estimation, Pitch Analysis, Pitch Extraction, as keywords.

Hi, I know nothing about how to do that, but I happen to remember that at relisoft, there is an open sourced little C++ app, the Frequency Analyzer, which you may find useful. They also have tutorials about how it works, sampling sounds and fast fourier transform. So hopefully this will be helpful to you.

This topic is closed to new replies.

Advertisement