Playing MP3 with multi-media library bass. dll [12]-drawing Dynamic Spectrum FFT

Source: Internet
Author: User
In this example:


Code file:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, classes, extctrls, comctrls; Type tform1 = Class (tform) opendialog1: topendialog; timer1: ttimer; Timer: timer; button1: tbutton; button2: tbutton; button3: tbutton; Procedure formcreate (Sender: tobject); Procedure button1click (Sender: tobject ); procedure button2click (Sender: tobject ); Procedure button3click (Sender: tobject); Procedure formdestroy (Sender: tobject); Procedure paintbox1paint (Sender: tobject); Procedure future (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} uses bass; var HS: hstream; {stream handle} fftdata: array [0 .. 512] of single; bit: tbitmap; fftpeacks: array [0 .. 128] of integer; fftfalloff: array [0 .. 128] of integer; Procedure tform1.formcreate (Sender: tobject); begin timer1.enabled: = false; timer1.interval: = 30; bit: = tbitmap. create; paintbox1.align: = altop; If hiword (bass_getversion) bassversion then MessageBox (0, '"Bass. the DLL file version is not suitable! ', Nil, mb_iconerror); if not bass_init (-1, 44100, 0, 0, nil) Then showmessage ('initialization error'); end; {open} procedure tform1.button1click (Sender: tobject); var mp3path: ansistring; begin bass_streamfree (HS); opendialog1.filter: = 'mp3 file (*. MP3) | *. MP3 | WAV file (*. wav) | * WAV '; If opendialog1.execute then mp3path: = ansistring (opendialog1.filename); HS: = bass_streamcreatefile (false, pansichar (mp3path), 0, 0, 0 ); if HS bass_active_playing then exit; bass_channelgetdata (HS, @ fftdata, bass_data_fft1024); bit. width: = paintbox1.width; bit. height: = paintbox1.height; bit. canvas. brush. color: = clblack; bit. canvas. fillrect (rect (0, 0, bit. width, bit. height); bit. canvas. pen. color: = cllime; for I: = 0 to length (fftdata)-1 do begin di: = trunc (ABS (fftdata [I]) * 500); If Di> bit. height then di: = bit. height; If Di> = fftpeacks [I] Then fftpeacks [I]: = di else fftpeacks [I]: = fftpeacks [I]-1; if Di> = fftfalloff [I] Then fftfalloff [I]: = di else fftfalloff [I]: = fftfalloff [I]-3; if (bit. height-fftpeacks [I])> bit. height then fftpeacks [I]: = 0; If (bit. height-fftfalloff [I])> bit. height then fftfalloff [I]: = 0; // bit. canvas. moveTo (I, bit. height); // bit. canvas. lineto (I, bit. height-fftfalloff [I]); // bit. canvas. pixels [I, bit. height-fftpeacks [I]: = bit. canvas. pen. color; bit. canvas. pen. color: = bit. canvas. pen. color; bit. canvas. moveTo (I * (W + 1), bit. height-fftpeacks [I]); bit. canvas. lineto (I * (W + 1) + W, bit. height-fftpeacks [I]); bit. canvas. pen. color: = bit. canvas. pen. color; bit. canvas. brush. color: = bit. canvas. pen. color; bit. canvas. rectangle (I * (W + 1), bit. height-fftfalloff [I], I * (W + 1) + W, bit. height); end; bitblt (paintbox1.canvas. handle, 0, 0, paintbox1.width, paintbox1.height, bit. canvas. handle, 0, 0, srccopy); end.
 

Form file:

object Form1: TForm1  Left = 222  Top = 114  Caption = 'Form1'  ClientHeight = 154  ClientWidth = 476  Color = clBtnFace  Font.Charset = DEFAULT_CHARSET  Font.Color = clWindowText  Font.Height = -11  Font.Name = 'Tahoma'  Font.Style = []  OldCreateOrder = False  Position = poDesigned  OnCreate = FormCreate  OnDestroy = FormDestroy  PixelsPerInch = 96  TextHeight = 13  object PaintBox1: TPaintBox    Left = 16    Top = 0    Width = 105    Height = 105    OnPaint = PaintBox1Paint  end  object Button1: TButton    Left = 109    Top = 117    Width = 75    Height = 25    Caption = #25171#24320    TabOrder = 0    OnClick = Button1Click  end  object Button2: TButton    Left = 206    Top = 117    Width = 75    Height = 25    Caption = #25773#25918    TabOrder = 1    OnClick = Button2Click  end  object Button3: TButton    Left = 303    Top = 117    Width = 75    Height = 25    Caption = #26242#20572    TabOrder = 2    OnClick = Button3Click  end  object OpenDialog1: TOpenDialog    Left = 128    Top = 24  end  object Timer1: TTimer    OnTimer = Timer1Timer    Left = 128    Top = 72  endend
 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.