How do I make an EQ in Delphi.

Started by bbo,

bbo

Hi.

First of all sorry for my bad English  :-[

I'm completly new to BASS , but i'll like to make a (x) band Eqlizer in Delphi. I've found some sample code for VB, but i can't figure out how to make it work in Delphi.

Could someone please show me how to do this with a bit of sourcecode plaese..... :-*

Kind regards
Benny

bigjim

#1
Using direct 8 fx and delphi its quite easy:

You say an x band but you can modify the code below to an x number depending on cpu I think.
I'm not saying this is the perfect way to do it- but it works ;D

First remember to add bass to the uses list at the top of the project

Place 3 trackbars on your form:
trackbar1
trackbar2
trackbar3
for each one
orientate them vertically
set min to -15 and max to 15

add to the var section at the top of the new project:

 
  low : BASS_FXPARAMEQ; // 1st band of eq
  lhnd : HFX; // 1st band handle
  mid : BASS_FXPARAMEQ; // 2nd band of eq
  mhnd : HFX; // 2nd band handle
  high : BASS_FXPARAMEQ; // 3rd band of eq
  hhnd : HFX; // 3rd band handle
  streamh : DWORD; // Stream handle

Add this to the list of procedures

procedure upeq; // Update EQ

To form load or place on a button put:

Bass_Init(-1, 44100, 0, Form1.handle); //Init bass on default device
Bass_Start; // Start Bass
streamh := Bass_StreamCreateFile(FALSE, pChar('one.mp3'), 0, 0, 0); // Load a mp3
Bass_StreamPlay(streamh, FALSE, 0); // Play the mp3
//////////////////// Set the EQ objects to the stream
lhnd := BASS_ChannelSetFX(streamh, BASS_FX_PARAMEQ);
mhnd := BASS_ChannelSetFX(streamh, BASS_FX_PARAMEQ);
hhnd := BASS_ChannelSetFX(streamh, BASS_FX_PARAMEQ);
//////////////////// Set 1st band settings
low.fCenter := 125;
low.fBandwidth := 5;
low.fGain := 0;
//////////////////// Set 2nd band settings
mid.fCenter := 1000;
mid.fBandwidth := 5;
mid.fGain := 0;
//////////////////// Set 3rd band settings
high.fCenter := 8000;
high.fBandwidth := 5;
high.fGain := 0;
//////////////////// // Apply Settings to song
BASS_FXSetParameters(lhnd, @low);
BASS_FXSetParameters(mhnd, @mid);
BASS_FXSetParameters(hhnd, @high);

On Form Destroy:

Bass_Free; // Free Bass

Under each of the trackbars OnChange event place:

upeq; // Update EQ

Finally make the new proc upeq:

procedure TForm1.upeq;
begin
////////// Set each eq instance to the correct gain
low.fGain := -trackbar1.Position;
mid.fGain := -trackbar2.Position;
high.fGain := -trackbar3.Position;
////////// Update Band Settings
BASS_FXSetParameters(lhnd, @low);
BASS_FXSetParameters(mhnd, @mid);
BASS_FXSetParameters(hhnd, @high);
//////////
end;

Right this works in delphi- but I'm sure theres a quicker or maybe easier way- or maybe not. I've just made up the band settings so it wont sound too spectacular. use your own or look at the thread off yesterday or the day before about band settings.

Hope this helps.

bbo

Hi'

Thanks for helping out, but it don't seems to work. The code runs without any exceptions, but nothing seem to happend whe i change the scrollbar possitions :( ..
Any suggentions??

Kind regards
Benny

Atilla

Try getting the return value of the function and see if it actually applies the settings. In the bass documentation you will find everything you need, including why it may not apply the settings. There are certain condititons, which you have to be famiiliar with.

bigjim

OOps I made a mistake ::)- I put
lowf.gain := 15-trackbar1.position;
and so on-

Ive changed it above it should have been
lowf.gain := -trackbar1.position;

In the example I used the new DMO effects for which you have to be using directX 8 or above and bass 1.7
I feel these effects have many advantages compared to the normal directx effects.

A little checklist to why it mightn't be working...
*) Did u set the scrollbar max and mix to 15 and -15 respectively?
*) Did U remeber to put upeq; under each trackbars on change event?
*) Got DirectX 8?
*) Got Bass 1.7?

Hope this helps...

bbo

Hi'

Stupid me  ::)

It did the work...Now it's fine. Thanks alot....

Regards Benny

bbo

Hi again...

Now at the end...

How do I add more scrollbars to this project.... :-/

Regards Benny

bigjim

just use:

var
band1, band2, band3, band4, band5 : BASS_FXPARAMEQ;
band1h, band2h, band3, band4h, band5h : DWORD;

assign as many instances of a BASS_FXPARAMEQ as you need.
Be sure to make each one a handle.

Just set each FX handle to the stream as before:

band1h := BASS_ChannelSetFX(streamh, BASS_FX_PARAMEQ);
band2h := BASS_ChannelSetFX(streamh, BASS_FX_PARAMEQ);
etc...

Set each Bass_FXParameq parameters as before- or store them in array for easier access later:

band1.fCenter := 125;
band1.fBandwidth := 5;
band1.fGain := 0;
band2.fCenter := 125;
band2.fBandwidth := 5;
band2.fGain := 0;
etc...

Then add as many trackbars with upeq under each one and in upeq something like:

band1.fGain := -Trackbar1.Position;
band2.fGain := -Trackbar2.Position;
etc...
BASS_FXSetParameters(band1h, @band1);
BASS_FXSetParameters(band2h, @band2);
etc...

Basically just as before but with more trackbars- more fx handles and more ParamEQ instances.

Ingolf2

I would use an array of bands, and then set up various methods to initialize and change the band values. In that way, you can simply change a constant value like BAND_COUNT to change the amount of bands to use.

There was another thread here with a good example on this, don't know where.

bigjim

Ingolf2

I had no question, I was commenting your post...