Recent

Author Topic: BASS Audio Equalizer  (Read 709 times)

pcurtis

  • Full Member
  • ***
  • Posts: 118
BASS Audio Equalizer
« on: June 15, 2020, 09:56:48 am »
Hi All,

I am experimenting with BASS and trying to create an equalizer. I have searched the web and managed to come up with this :-

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, ComCtrls,
  9.   StdCtrls, bass, TplSliderUnit;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     Label1: TLabel;
  17.     Label2: TLabel;
  18.     Label3: TLabel;
  19.     Label4: TLabel;
  20.     Label5: TLabel;
  21.     Label6: TLabel;
  22.     plSlider1: TplSlider;
  23.     plSlider10: TplSlider;
  24.     plSlider2: TplSlider;
  25.     plSlider3: TplSlider;
  26.     plSlider4: TplSlider;
  27.     plSlider5: TplSlider;
  28.     plSlider6: TplSlider;
  29.     plSlider7: TplSlider;
  30.     plSlider8: TplSlider;
  31.     plSlider9: TplSlider;
  32.     procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
  33.     procedure FormCreate(Sender: TObject);
  34.     procedure SliderChange(Sender: TObject);
  35.   private
  36.  
  37.   public
  38.  
  39.   end;
  40.  
  41. var
  42.   Form1: TForm1;
  43.   strs : THandle;
  44.   p : BASS_DX8_PARAMEQ;
  45.   fx: array[0..10] of integer;
  46.   EQEnable: Boolean;
  47.   pR: BASS_DX8_REVERB;
  48.  
  49. implementation
  50.  
  51. {$R *.lfm}
  52.  
  53. { TForm1 }
  54.  
  55. procedure TForm1.FormCreate(Sender: TObject);
  56. begin
  57.   BASS_Init(-1, 44100, 0, Handle, nil);
  58.   //BASS_SetConfig(BASS_CONFIG_BUFFER, 5000);
  59.   BASS_SetVolume(0.1);
  60.  
  61.   if BASS_ChannelIsActive(strs) <> 0 then
  62.     BASS_ChannelStop(strs);
  63.  
  64.   strs := BASS_StreamCreateFile(False, pwidechar('a.mp3'), 0, 0, BASS_UNICODE);
  65.  
  66.   BASS_ChannelPlay(strs, False);
  67.  
  68.   fx[0] := BASS_ChannelSetFX(strs, BASS_FX_DX8_PARAMEQ, 1);
  69.   fx[1] := BASS_ChannelSetFX(strs, BASS_FX_DX8_PARAMEQ, 1);
  70.   fx[2] := BASS_ChannelSetFX(strs, BASS_FX_DX8_PARAMEQ, 1);
  71.   fx[3] := BASS_ChannelSetFX(strs, BASS_FX_DX8_PARAMEQ, 1);
  72.   fx[4] := BASS_ChannelSetFX(strs, BASS_FX_DX8_PARAMEQ, 1);
  73.   fx[5] := BASS_ChannelSetFX(strs, BASS_FX_DX8_PARAMEQ, 1);
  74.   fx[6] := BASS_ChannelSetFX(strs, BASS_FX_DX8_PARAMEQ, 1);
  75.   fx[7] := BASS_ChannelSetFX(strs, BASS_FX_DX8_PARAMEQ, 1);
  76.   fx[8] := BASS_ChannelSetFX(strs, BASS_FX_DX8_PARAMEQ, 1);
  77.   fx[9] := BASS_ChannelSetFX(strs, BASS_FX_DX8_PARAMEQ, 1);
  78.   fx[10] := BASS_ChannelSetFX(strs, BASS_FX_DX8_REVERB, 1);
  79.  
  80.   //Apply EQ Settings to song
  81.     p.fGain := 0;
  82.     p.fBandwidth := 18;
  83.     p.fCenter := 80;
  84.     BASS_FXSetParameters(fx[0], @p);
  85.     p.fCenter := 170;
  86.     BASS_FXSetParameters(fx[1], @p);
  87.     p.fCenter := 310;
  88.     BASS_FXSetParameters(fx[2], @p);
  89.     p.fCenter := 600;
  90.     BASS_FXSetParameters(fx[3], @p);
  91.     p.fCenter := 1000;
  92.     BASS_FXSetParameters(fx[4], @p);
  93.     p.fCenter := 3000;
  94.     BASS_FXSetParameters(fx[5], @p);
  95.     p.fCenter := 7000;
  96.     BASS_FXSetParameters(fx[6], @p);
  97.     p.fCenter := 12000;
  98.     BASS_FXSetParameters(fx[7], @p);
  99.     p.fCenter := 14000;
  100.     BASS_FXSetParameters(fx[8], @p);
  101.     p.fCenter := 16000;
  102.     BASS_FXSetParameters(fx[9], @p);
  103.  
  104.     BASS_FXGetParameters(fx[10], @pR);
  105.     pR.fReverbMix := -96;
  106.     pR.fReverbTime := 1500;
  107.     pR.fHighFreqRTRatio := 0.1;
  108.     BASS_FXSetParameters(fx[10], @pR);
  109.  
  110. end;
  111.  
  112. procedure TForm1.SliderChange(Sender: TObject);
  113. var
  114.   CENTER : integer;
  115.   GAIN : integer;
  116.   INDEX : integer;
  117. begin
  118.   CENTER:=(Sender as TplSlider).Frequency;
  119.   GAIN:=(Sender as TplSlider).Value;
  120.   INDEX:=(Sender as TplSlider).Index;
  121.  
  122.   Label2.Caption:=inttostr(GAIN);
  123.   Label4.Caption:=inttostr(CENTER);
  124.   Label6.Caption:=inttostr(INDEX);
  125.  
  126.   p.fGain := GAIN;
  127.   p.fBandwidth := 18;
  128.   p.fCenter := CENTER;
  129.   BASS_FXSetParameters(fx[INDEX], @p);
  130. end;
  131.  
  132. procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
  133. begin
  134.   BASS_Stop();
  135. end;
  136.  
  137. end.
  138.  

It seems to work, but I feel that it isn't absolutely right.

CAN anyone give any hint, tips, pointers, ...

My main concern (I think) is around

Code: Pascal  [Select][+][-]
  1.   fx[0] := BASS_ChannelSetFX(strs, BASS_FX_DX8_PARAMEQ, 1);
  2.   fx[1] := BASS_ChannelSetFX(strs, BASS_FX_DX8_PARAMEQ, 1);
  3.   fx[2] := BASS_ChannelSetFX(strs, BASS_FX_DX8_PARAMEQ, 1);
  4.   fx[3] := BASS_ChannelSetFX(strs, BASS_FX_DX8_PARAMEQ, 1);
  5.   fx[4] := BASS_ChannelSetFX(strs, BASS_FX_DX8_PARAMEQ, 1);
  6.   fx[5] := BASS_ChannelSetFX(strs, BASS_FX_DX8_PARAMEQ, 1);
  7.   fx[6] := BASS_ChannelSetFX(strs, BASS_FX_DX8_PARAMEQ, 1);
  8.   fx[7] := BASS_ChannelSetFX(strs, BASS_FX_DX8_PARAMEQ, 1);
  9.   fx[8] := BASS_ChannelSetFX(strs, BASS_FX_DX8_PARAMEQ, 1);
  10.   fx[9] := BASS_ChannelSetFX(strs, BASS_FX_DX8_PARAMEQ, 1);
  11.   fx[10] := BASS_ChannelSetFX(strs, BASS_FX_DX8_REVERB, 1);
  12.  

I just don't feel its right.

Anticipating your feedback.

Phil.
Windows 10 / Linux Mint 20
Laz 2.0.8
FPC 3.0.4

winni

  • Hero Member
  • *****
  • Posts: 1600
Re: BASS Audio Equalizer
« Reply #1 on: June 15, 2020, 12:37:46 pm »
Hi!

You forgot to set the Bandwidth of every Eq- Channel.
The way you do it now every channel works on the whole audio spectrum (~16 .. 20000 Hz) with a specific center.

Code: Pascal  [Select][+][-]
  1. var  eq  : BASS_BFX_PEAKEQ;
  2.       fxEQ : DWord = 0;
  3.      ok : boolean;
  4.  
  5. begin
  6. fxEQ := BASS_ChannelSetFX(B_Stream, BASS_FX_BFX_PEAKEQ, 0);
  7.  with eq do begin
  8.       fCenter := ....; // 128,256,512, .....
  9.       fBandwidth :=  fCenter/2;
  10.       fGain :=  ..... ;
  11.       lChannel := BASS_BFX_CHANALL; // left&right and suround at once
  12.  end;
  13. ok := BASS_FXSetParameters(fxEQ, @eq);      
  14. ....
  15. end;
  16.  
This has to be done for every channel.

btw: The channels are typically set up by doubling the center frequency of the last channel like

64, 128, 256,512 .... 
or
100, 200, 400, 800, ...


Winni

PS.: Volume of 0.1 is too little for Rock'n'Roll ......

pcurtis

  • Full Member
  • ***
  • Posts: 118
Re: BASS Audio Equalizer
« Reply #2 on: June 15, 2020, 01:08:03 pm »
Hi there!

Thanks for the reply.

I'm not quite sure how to implement your suggestions.

First I will change the centers to 16000, 8000, 4000, 2000, 1000, 500, 250, 128, 64.

Volume 0.1 is because I am located in a medical center - Multiple Sclerosis, so 0.1 is only for testing.

It seems that you use a different system to me.

What system is best? BASS_FX_BFX_PEAKEQ or BASS_FX_DX8_PARAMEQ

I use BASS 2.4, the type BASS_FX_BFX_PEAKEQ is not defined in my bass.pas

What libraries and headers do I need?

How can I implement this in my code - if its not being too cheeky.
« Last Edit: June 15, 2020, 01:49:31 pm by pcurtis »
Windows 10 / Linux Mint 20
Laz 2.0.8
FPC 3.0.4

winni

  • Hero Member
  • *****
  • Posts: 1600
Re: BASS Audio Equalizer
« Reply #3 on: June 15, 2020, 02:05:39 pm »
Hi!

You need to download the BASS_FX module.
It comes with the (delphi) interface unit BASS_FX.
and then

uses .....BASS_FX,.....;

I am also using BASS_FX version 2.4 
It seems it has not changed since 2014.

I have not worked fpr a long time with BASS, but don't hesitate to ask.
Everything works fine with BASS, except the dump CD module ....

Winni


pcurtis

  • Full Member
  • ***
  • Posts: 118
Re: BASS Audio Equalizer
« Reply #4 on: June 15, 2020, 02:21:15 pm »
Did you mean something like

Code: Pascal  [Select][+][-]
  1.   strs := BASS_StreamCreateFile(False, pwidechar('a.mp3'), 0, 0, BASS_UNICODE);
  2.  
  3.   BASS_ChannelPlay(strs, False);
  4.  
  5.   fx[0] := BASS_ChannelSetFX(strs, BASS_FX_BFX_PEAKEQ, 0);
  6.   fx[1] := BASS_ChannelSetFX(strs, BASS_FX_BFX_PEAKEQ, 0);
  7.   fx[2] := BASS_ChannelSetFX(strs, BASS_FX_BFX_PEAKEQ, 0);
  8.   fx[3] := BASS_ChannelSetFX(strs, BASS_FX_BFX_PEAKEQ, 0);
  9.   fx[4] := BASS_ChannelSetFX(strs, BASS_FX_BFX_PEAKEQ, 0);
  10.   fx[5] := BASS_ChannelSetFX(strs, BASS_FX_BFX_PEAKEQ, 0);
  11.   fx[6] := BASS_ChannelSetFX(strs, BASS_FX_BFX_PEAKEQ, 0);
  12.   fx[7] := BASS_ChannelSetFX(strs, BASS_FX_BFX_PEAKEQ, 0);
  13.   fx[8] := BASS_ChannelSetFX(strs, BASS_FX_BFX_PEAKEQ, 0);
  14.  
  15.   p.fGain := 0;
  16.  
  17.   p.fCenter := 64;
  18.   p.fBandwidth := p.fCenter/2;
  19.   p.lChannel := BASS_BFX_CHANALL;
  20.   BASS_FXSetParameters(fx[0], @p);
  21.  
  22.   p.fCenter := 128;
  23.   p.fBandwidth := p.fCenter/2;
  24.   p.lChannel := BASS_BFX_CHANALL;
  25.   BASS_FXSetParameters(fx[1], @p);
  26.  
  27.   p.fCenter := 250;
  28.   p.fBandwidth := p.fCenter/2;
  29.   p.lChannel := BASS_BFX_CHANALL;
  30.   BASS_FXSetParameters(fx[2], @p);
  31.  
  32.   p.fCenter := 500;
  33.   p.fBandwidth := p.fCenter/2;
  34.   p.lChannel := BASS_BFX_CHANALL;
  35.   BASS_FXSetParameters(fx[3], @p);
  36.  
  37.   p.fCenter := 1000;
  38.   p.fBandwidth := p.fCenter/2;
  39.   p.lChannel := BASS_BFX_CHANALL;
  40.   BASS_FXSetParameters(fx[4], @p);
  41.  
  42.   p.fCenter := 2000;
  43.   p.fBandwidth := p.fCenter/2;
  44.   p.lChannel := BASS_BFX_CHANALL;
  45.   BASS_FXSetParameters(fx[5], @p);
  46.  
  47.   p.fCenter := 4000;
  48.   p.fBandwidth := p.fCenter/2;
  49.   p.lChannel := BASS_BFX_CHANALL;
  50.   BASS_FXSetParameters(fx[6], @p);
  51.  
  52.   p.fCenter := 8000;
  53.   p.fBandwidth := p.fCenter/2;
  54.   p.lChannel := BASS_BFX_CHANALL;
  55.   BASS_FXSetParameters(fx[7], @p);
  56.  
  57.   p.fCenter := 16000;
  58.   p.fBandwidth := p.fCenter/2;
  59.   p.lChannel := BASS_BFX_CHANALL;
  60.   BASS_FXSetParameters(fx[8], @p);
  61.  
Windows 10 / Linux Mint 20
Laz 2.0.8
FPC 3.0.4

winni

  • Hero Member
  • *****
  • Posts: 1600
Re: BASS Audio Equalizer
« Reply #5 on: June 15, 2020, 02:34:03 pm »
Hi!

Yes, that looks good to me.
But simplyfy your  code with a loop:

Code: Pascal  [Select][+][-]
  1. var eqCount : integer
  2.       centerF : Integer;
  3.  
  4. ....
  5. CenterF := 64;
  6. for eqCount := 0 to 8 do
  7. begin
  8.  fx[eqCount] := BASS_ChannelSetFX(strs, BASS_FX_BFX_PEAKEQ, 0);
  9. p.fGain := 0;
  10. p.fCenter := CenterF;
  11. p.fBandwidth := p.fCenter/2;
  12. p.lChannel := BASS_BFX_CHANALL;
  13. BASS_FXSetParameters(fx[eqCount], @p);
  14. CenterF := CenterF * 2;
  15. end; // for

Winni


pcurtis

  • Full Member
  • ***
  • Posts: 118
Re: BASS Audio Equalizer
« Reply #6 on: June 15, 2020, 02:44:11 pm »
Do I need to do anything with bass_fx.dll?
Windows 10 / Linux Mint 20
Laz 2.0.8
FPC 3.0.4

winni

  • Hero Member
  • *****
  • Posts: 1600
Re: BASS Audio Equalizer
« Reply #7 on: June 15, 2020, 02:57:41 pm »
Hi!

Windows - it seems.

Put it in the same directory where your bass.dll  resides.

Winni

winni

  • Hero Member
  • *****
  • Posts: 1600
Re: BASS Audio Equalizer
« Reply #8 on: June 15, 2020, 03:04:57 pm »
Hi!

Ooops - I forgot:

You have to initialize  in the TForm1.formcreate  the FX module:

Code: Pascal  [Select][+][-]
  1. var FX : DWord;
  2.  
  3.  
  4. //FX := BASS_PluginLoad (pchar ('libbass_fx.so'),0); Linux
  5. FX := BASS_PluginLoad (pchar ('bass_fx.dll'),0); // Windows
  6. If FX <> 0 then showMessage ('Error loading FX');
  7.  
  8.  

Winni
« Last Edit: June 15, 2020, 03:13:31 pm by winni »

pcurtis

  • Full Member
  • ***
  • Posts: 118
Re: BASS Audio Equalizer
« Reply #9 on: June 15, 2020, 03:49:40 pm »
OK. FYI - "BASS_PluginLoad is only for loading add-ons that provide support for additional file formats, so you can't load BASS_FX that way. You should call a BASS_FX function to force it to be loaded, eg. BASS_FX_GetVersion."

Its working now.

Thanks.
Windows 10 / Linux Mint 20
Laz 2.0.8
FPC 3.0.4

winni

  • Hero Member
  • *****
  • Posts: 1600
Re: BASS Audio Equalizer
« Reply #10 on: June 15, 2020, 03:54:06 pm »
Hi!

Where did you read that infos?

I am loading BASS_FX exact that way - since years without problems.

Winni


winni

  • Hero Member
  • *****
  • Posts: 1600
Re: BASS Audio Equalizer
« Reply #12 on: June 15, 2020, 06:55:31 pm »
Hi!

Thanx for the link.

It seems to be a Windows only issue.
I never had any problems with my way of initializing with Linux.

But it is good to know - just call the version and BASS_FX is initialized.

Winni

 

TinyPortal © 2005-2018