Delphi with Multimedia library Bass.dll play mp3 [14]

Source: Internet
Author: User
Tags integer

This example effect chart:

Code files:

Unit Unit1;
Interface
Uses
Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms,
Dialogs, Stdctrls, Comctrls, Extctrls;
Type
TForm1 = Class (Tform)
Opendialog1:topendialog;
Button1:tbutton;
Button2:tbutton;
Button3:tbutton;
Panel1:tpanel;
Procedure Formcreate (Sender:tobject);
Procedure Button1Click (Sender:tobject);
Procedure Button2click (Sender:tobject);
Procedure Button3click (Sender:tobject);
Procedure Formdestroy (Sender:tobject);
Private
Procedure Trackchange (Sender:tobject);
End
Var
Form1:tform1;
Implementation
{$R *.DFM}
Uses Bass;
Var
Hs:hstream; {Stream Handle}
parameq:bass_dx8_parameq; {parameter structure of frequency equalizer}
FX:ARRAY[0..5] of Hfx; {DX effect handle}
TRACK:ARRAY[0..5] of Ttrackbar;
Procedure Tform1.formcreate (Sender:tobject);
Var
I:integer;
Begin
Panel1.align: = Alright;
Panel1.bevelouter: = bvlowered;
Panel1.bevelwidth: = 2;
Panel1.caption: = ';
Panel1.width: = 6*24 + 2;
For I: = 0 to 5 do
Begin
Track[i]: = Ttrackbar.create (Self);
Track[i]. Parent: = Panel1;
Track[i]. Orientation: = trvertical;
Track[i]. Width: = 23;
Track[i]. Height: = Panel1.height;
Track[i]. Showselrange: = False;
Track[i]. Left: = i * 24 + 1;
Track[i]. Max: = 15;
Track[i]. Min: =-15;
Track[i]. Position: = 0;
Track[i]. Tag: = i;
Track[i]. OnChange: = Self.trackchange;
End
If HiWord (bass_getversion) <> Bassversion Then
MessageBox (0, "Bass.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;
I:integer;
Begin
Bass_streamfree (HS);
Opendialog1.filter: = ' Mp3 file (*.mp3) |*.mp3| Wav file (*.wav) |*wav ';
If Opendialog1.execute Then
Mp3path: = ansistring (Opendialog1.filename);
{You need to specify the BASS_SAMPLE_FX parameter} for effects such as reverberation
HS: = Bass_streamcreatefile (False, Pansichar (Mp3path), 0, 0, BASS_SAMPLE_FX);
If HS < bass_error_ended Then
Text: = ' Open failed '
ELSE begin
Text: = string (Mp3path);
{Multiple effect handles are required to set multiple frequency ranges}
For I: = 0 to 5 do
Fx[i]: = Bass_channelsetfx (HS, BASS_FX_DX8_PARAMEQ, 1);
End
End
Play
Procedure Tform1.button2click (Sender:tobject);
Begin
Bass_channelplay (HS, False);
End
Suspended
Procedure Tform1.button3click (Sender:tobject);
Begin
Bass_channelpause (HS);
End
Procedure Tform1.formdestroy (Sender:tobject);
Begin
Bass_free;
End
{Dynamically established Ttrackbar events to invoke}
Procedure Tform1.trackchange (Sender:tobject);
Var
I:integer;
Begin
I: = Ttrackbar (Sender). Tag;
Parameq.fbandwidth: = 20; {1-36}
case I of
0:parameq.fcenter: = 100;
1:parameq.fcenter: = 2000;
2:parameq.fcenter: = 4000;
3:parameq.fcenter: = 8000;
4:parameq.fcenter: = 10000;
5:parameq.fcenter: = 12000;
End
Parameq.fgain: =-Ttrackbar (Sender). Position;
Bass_fxsetparameters (Fx[i], @parameq);
End
End.

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.