音乐频谱显示 FFT of waveIn audio signals. Free source code and programming help

论坛 期权论坛     
选择匿名的用户   2021-5-30 01:24   187   0
导读:
<br>
<br>
<ul class="download"><li><a href="http://www.codeproject.com/KB/audio-video/waveInFFT/waveinFFT_demo.zip"><u><font color="#0000ff">Download demo project - 33.3 KB</font></u></a> </li></ul>
<p><img height="357" src="https://beijingoptbbs.oss-cn-beijing.aliyuncs.com/cs/5606289-c6e1c907d4b559926918a2888a65b0ef.jpg" width="486"></p>
<p><img height="357" src="https://beijingoptbbs.oss-cn-beijing.aliyuncs.com/cs/5606289-95b5652b510928353fa751a6083e700d.jpg" width="486"></p>
<p><img height="357" src="https://beijingoptbbs.oss-cn-beijing.aliyuncs.com/cs/5606289-44c4a5aa1c954770065c88a2d86f8432.jpg" width="486"></p>
<p><img height="357" src="https://beijingoptbbs.oss-cn-beijing.aliyuncs.com/cs/5606289-247dfc4600008d86b01f2fa77874a713.jpg" width="486"></p>
<p><img height="357" src="https://beijingoptbbs.oss-cn-beijing.aliyuncs.com/cs/5606289-6b6a8f8ef12a83a36f872bb01a7f3230.jpg" width="486"></p>
<p><img height="357" src="https://beijingoptbbs.oss-cn-beijing.aliyuncs.com/cs/5606289-9b92efd4a3a43df8a4ee39218c1bdd94.jpg" width="486"></p>
<p><img height="357" src="https://beijingoptbbs.oss-cn-beijing.aliyuncs.com/cs/5606289-ad4acf3a5c833d499d096954904d3e99.jpg" width="486"></p>
<h2>Introduction</h2>
<p>The Fast Fourier Transform (FFT) allows users to view the spectrum content of an audio signal. The FFT code presented here was written by <a href="http://www.intersrv.com/~dcross/fft.html" rel="noopener noreferrer" target="_blank"><u><font color="#0000ff">Don Cross</font></u></a>, his homepage appears to have subsequently been taken down. Rather than explain the mathematical theory of the FFT, I will attempt to explain its usefulness as it relates to audio signals.</p>
<p>The FFT allows users to obtain the spectral makeup of an audio signal, obtain the decibels of its various frequencies, or obtain the intensity of its various frequencies. Spectral viewers (shown in the image above), Equalizers, or VU-Meters may all use the FFT in order to display their results. The difference between them then depends upon one of a couple of equations that take the real and imaginary components of the FFT, and return either the intensity or decibel levels to be used in the graphed result. The following code takes both the real and imaginary components of the FFT result, and returns the intensity and decibels.</p>
<pre class="blockcode"><span class="code-keyword"><font color="#0000ff">inline</font></span> <span class="code-keyword"><font color="#0000ff">double</font></span> GetFrequencyIntensity(<span class="code-keyword"><font color="#0000ff">double</font></span> re, <span class="code-keyword"><font color="#0000ff">double</font></span> im)
{
    <span class="code-keyword"><font color="#0000ff">return</font></span> sqrt((re*re)&#43;(im*im));
}
<span class="code-preprocessor"><font color="#000080">#define</font></span> mag_sqrd(re,im) (re*re&#43;im*im)
<span class="code-preprocessor"><font color="#000080">#define</font></span> Decibels(re,im) ((re &#61;&#61; <span class="code-digit"><font color="#000080">0</font></span> &amp;&amp; im &#61;&#61; <span class="code-digit"><font color="#000080">0</font></span>) ? (<span class="code-digit"><font color="#000080">0</font></span>) :
        <span class="code-digit"><font color="#000080">10</font></span>.<span class="code-digit"><font color="#000080">0</font></span> * log10(<span class="code-keyword"><font color="#0000ff">double</font></span>(mag_sqrd(re,im))))
<span class="code-preprocessor"><font color="#000080">#define</font></span> Amplitude(re,im,len) (GetFrequencyIntensity(re,im)/(len))
<span class="code-preprocessor"><font color="#000080">#define</font></span> AmplitudeScaled(re,im,len,scale) ((<span class="code-keyword"><font color="#0000ff">int</font></span>)Amplitude(re,im,len)%scale)</pre>
<p>The FFT uses the audio signal as its real component, and uses a <code><font color="#990000" size="3">NULL</font></code> pointer for its imaginary component indicating that the imaginary data does not exist. Upon its return, the FFT will return both the real and imaginary data components based upon the data given as the real component. The is mirrored with the return samples so that <code><font size="3"><span class="code-digit"><font color="#000080">0</font></span><font color="#990000">-FFT_LEN/2</font></font></code> contains the data, and <code><font color="#990000" size="3">FFT_LEN/2</font></code> to <code><font color="#990000" size="3">FFT_LEN</font></code> contains a reverse of the data. This mistake was corrected in my code. The code that performs the FFT follows:</p>
<div class="precollapse" id="premain1" style="WIDTH: 100%">
<img height="9" src="https://beijingoptbbs.oss-cn-beijing.aliyuncs.com/cs/5606289-74fd2798202fde65c452efa4582b9818.gif" width="9">
<span id="precollapse1" style="MARGIN-BOTTOM: 0px; CURSOR: pointer"> Collapse</span>
</div>
<pre id="pre1" style="MARGIN-TOP: 0px">    DWORD nCount &#61; <span class="code-digit"><font color="#000080">0</font></span>;
    <span class="code-keyword"><font color="#0000ff">for</font></span> (DWORD dw &#61; <span class="code-digit"><font color="#000080">0</font></span>; dw <span class="code-keyword"><font color="#0000ff">&lt;</font></span> FFT_LEN; dw&#43;&#43;)
    {
        {
            <span class="code-comment"><em><font color="#008000">//</font></em></span><span class="code-comment"><em><font color="#008000">copy audio signal to fft real component for left chann
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP