c#中利用Bass.dll聲音處理類庫繪制頻譜圖


通過引用Bass.Net.dll這個聲音處理類庫就可以輕松的獲取頻譜圖數據並繪制頻譜圖。

 1 public void DrawFFT(Graphics g)
 2         {
 3             if (Bass.BASS_ChannelIsActive(SystemFont.Stream) == BASSActive.BASS_ACTIVE_PLAYING)
 4             {
 5                 Bass.BASS_ChannelGetData(SystemFont.Stream, SystemFont.FFTDatas,(int)BASSData.BASS_DATA_FFT1024);
 6                 for (SystemFont.i = 0; SystemFont.i < SystemFont.FFTDatas.Length-1; SystemFont.i++)
 7                 {
 8                     SystemFont.Di = (int)(Math.Abs(SystemFont.FFTDatas[SystemFont.i]) * 1792);
 9                     if (SystemFont.Di > this.Height)
10                         SystemFont.Di = this.Height;
11                     if (SystemFont.Di >= SystemFont.FFTPeacks[SystemFont.i])
12                         SystemFont.FFTPeacks[SystemFont.i] = SystemFont.Di;
13                     else
14                         SystemFont.FFTPeacks[SystemFont.i] = SystemFont.FFTPeacks[SystemFont.i] - 1;
15                     if (SystemFont.Di >= SystemFont.FFTFall[SystemFont.i])
16                         SystemFont.FFTFall[SystemFont.i] = SystemFont.Di;
17                     else
18                         SystemFont.FFTFall[SystemFont.i] = SystemFont.FFTFall[SystemFont.i]-1;
19                     if ((this.Height - SystemFont.FFTPeacks[SystemFont.i]) > this.Height)
20                         SystemFont.FFTPeacks[SystemFont.i] = this.Height;
21                     if ((this.Height - SystemFont.FFTFall[SystemFont.i]) > this.Height)
22                         SystemFont.FFTFall[SystemFont.i] = this.Height;
23                     g.FillRectangle(solidBrush, SystemFont.i * (w+2), this.Height - SystemFont.FFTFall[SystemFont.i],w, this.Height);
24                 }
25             }
26             else
27             {
28                 return;
29             }
30         }

效果如下:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM