Re: Extract data from AIFF file to compute FFT
Re: Extract data from AIFF file to compute FFT
- Subject: Re: Extract data from AIFF file to compute FFT
- From: "Mikael Hakman" <email@hidden>
- Date: Mon, 4 Aug 2008 15:57:40 +0200
- Organization: Datakonsulten AB
Hello Francois,
Your question consists of 3 separate smaller questions.
1. How to extract audio data from an AIFF file?
2. How to convert these data into representation suitable for 3 below?
3. Should you use FFT or other math in implementation of a tuning tool?
Answer to 2 above depends on the answer to 3 and also on a particular
implementation of the algorithm you choose - there are floating point
(double type) and fixed point/integer (int/long type) implementations for
most mathematical algorithms.
FFT (Fast Fourier Transform) is an algorithm for computing DFT (Discrete
Fourier Transform). There are other algorithms for computing DFT. Every such
algorithm has different properties (speed, efficiency, memory requirements,
precision, flexibility, robustness etc.) that make it more suitable for some
tasks and less suitable for others. For example, I'm often using
correlation-based DFT, which has, for my purposes, good balance between all
these properties but is much slower than FFT.
Contrary to common belief, DFT doesn't compute which frequencies at which
levels (amplitudes) are present in a digital signal. DFT computes levels for
frequencies in a given discrete set of frequencies that when summed give the
best approximation of the digital signal. The set of these frequencies is
given by number of samples (N) submitted to the algorithm, and sample rate
(SR). DFT computes amplitudes for following frequencies SR/N, 2*SR/N,
3*SR/N. (N/2 -1)*SR/N. For SR=48000 samples/second and N=4800 samples, DFT
gives you amplitudes (and phases) for 10 Hz, 20 Hz, 30 Hz.23990 Hz sine
waves that when summed up approximate your 4800 samples in the best way.
This doesn't mean that your signal must to, has to, or actually contains
these precise frequencies. Most often it will not.
A special property of FFT (but not the other DFT algorithms) is that the
number of samples it works on must be an integer power of 2. Such as N=1024
for example, which is the reason why FFT computes such an uneven frequency
set.
Both above facts together make FFT less suitable for tuning application, as
others here have pointed out, especially on limited CPU capacity hardware.
If you could compute 65536 or more points FFT (as pro FFT-analyzers do) then
it would work ok. Brian's zero-crossing/period length method is certainly
one possible way, even if, as he points out, you get problems with false
crossing due to harmonic contents, and also due to noise. Remember also that
real-life signal from a guitar or other instrument is not like a theoretical
steady-state sine wave. It has an attack time, a decay time, and it
fluctuates in amplitude all the time.
I would probably choose a correlation based method, given limited CPU
resources of an iPhone. You compute a theoretical sine wave of the desired
frequency. Then you compute correlation between this and your real signal.
You then repeatedly adjust your key and repeat measurement. When computed
correlation reaches its maximum then the real signal (the string) is at the
same frequency as you're theoretically computing. This method could probably
be extended to tuning all strings at the same time and playing a
specific/specified accord.
Regards/Mikael
Sunday, August 03, 2008 10:58 PM, Francois Baronnet wrote:
Hi all,
I'm willing to develop some tuning tool (guitar & ukulele) for iPhone.
I'm facing some issues with the record part: I'd like to record sound for
2
or 3 seconds (this part is ok) and then extract from it the principal
frequency.
Some people said to me to compute the Fast Fourier Transform.
Reading this mailing list I found how to find sound data chunks in some
AIFF
file (here:
http://lists.apple.com/archives/coreaudio-api/2003/Feb/msg00244.html).
But one point is missing: in all theses chunks of sound, what do I should
send to my FFT function? I heard of arrays of complex numbers, but I'm a
bit
confused...
Thanks in advance for any help.
--
François Baronnet
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden