Recent

Author Topic: Equalizer with Bass.dll problems  (Read 989 times)

Soulrender

  • Newbie
  • Posts: 2
Equalizer with Bass.dll problems
« on: July 02, 2025, 07:09:24 pm »
Hi, I'm quite new here, but lets get to the point:

I'm trying to write a music player using Bass.dll library and I'm almost done with everything, but I stuck at 10-band equalizer.
I tried different variations of code but nothing seems to work the way I assume, constantly either the equalizer doesn't apply effects or throws from
BASS_ErrorGetCode 19 - illegal parameter, maybe you could point me where are the mistakes in code?

Code: Pascal  [Select][+][-]
  1. ... uses
  2. bass, bass_fx;
  3. type
  4. ...
  5. TjustPlayer = class(TForm)
  6. ...
  7. public
  8. const
  9. frequencies: array[0..9] of single = (80, 160, 320, 600, 1000, 3000, 6000, 12000, 14000, 16000);
  10. var
  11. musicStream : Thandle;
  12. eq: BASS_BFX_PEAKEQ;
  13. fxHandles: array[0..9] of cardinal;
  14. ...
  15.  

and here are the procedures to control equalizer:

Code: Pascal  [Select][+][-]
  1.   procedure TJustPlayer.InitEqualizer;
  2.   var
  3.     i: Integer;
  4.   begin
  5.     if musicStream = 0 then Exit;
  6.  
  7.    
  8.     ResetEqualizer;
  9.  
  10.     for i := 0 to 9 do
  11.     begin
  12.       FillChar(eq, SizeOf(eq), 0);
  13.  
  14.       eq.lBand := 0;
  15.       eq.fBandwidth := 18;
  16.       eq.fQ := 0;            
  17.       eq.fCenter := Frequencies[i];
  18.       eq.fGain := 0;        
  19.       eq.lChannel := BASS_BFX_CHANALL;
  20.  
  21.       fxHandles[i] := BASS_ChannelSetFX(musicStream, BASS_FX_BFX_PEAKEQ, 2);
  22.       if fxHandles[i] <> 0 then
  23.         BASS_FXSetParameters(fxHandles[i], @eq);
  24.     end;
  25.   end;
  26.  
  27. procedure TJustPlayer.ApplyEqualizerBand(bandIndex: Integer; freq: Single; gainValue: Integer);
  28. begin
  29.   if musicStream = 0 then Exit;
  30.  
  31.  
  32.   if (bandIndex < 0) or (bandIndex > 9) then
  33.   begin
  34.     ShowMessage('Incorrect band index: ' + IntToStr(bandIndex));
  35.     Exit;
  36.   end;
  37.  
  38.  
  39.   if fxHandles[bandIndex] = 0 then
  40.   begin
  41.     fxHandles[bandIndex] := BASS_ChannelSetFX(musicStream, BASS_FX_BFX_PEAKEQ, 0);
  42.     if fxHandles[bandIndex] = 0 then
  43.     begin
  44.       ShowMessage('Cannot Apply Effect: ' + IntToStr(BASS_ErrorGetCode));
  45.       Exit;
  46.     end;
  47.   end;
  48.  
  49.   FillChar(eq, SizeOf(eq), 0);
  50.   eq.lBand := bandIndex;
  51.   eq.fCenter := freq;
  52.   eq.fGain := gainValue;
  53.   eq.fQ := 1.0;
  54.   eq.lChannel := BASS_BFX_CHANALL;
  55.  
  56.   if not BASS_FXSetParameters(fxHandles[bandIndex], @eq) then
  57.   begin
  58.     ShowMessage('Equalizer Error: ' + IntToStr(BASS_ErrorGetCode));
  59.   end;
  60. end;
  61.  
  62.   procedure TJustPlayer.ResetEqualizer;
  63.   var
  64.     i: Integer;
  65.   begin
  66.     if musicStream = 0 then Exit;
  67.  
  68.     for i := 0 to 9 do
  69.     begin
  70.       if fxHandles[i] <> 0 then
  71.       begin
  72.         BASS_ChannelRemoveFX(musicStream, fxHandles[i]);
  73.         fxHandles[i] := 0;
  74.       end;
  75.     end;
  76.   end;
  77.  

Finally I'm trying to apply effect(s) this way

Code: Pascal  [Select][+][-]
  1.  
  2. procedure TjustPlayer.applyButtonClick(Sender: TObject);
  3. begin
  4.   ApplyEqualizerBand(0, single(frequencies[1]), 15 - Equalizer.TrackBar1.position);
  5.   //...
  6.   ApplyEqualizerBand(9, single(frequencies[9]), 15 - Equalizer.TrackBar10.position);
  7.   //All 10 trackbars are set min=0, max=30
  8. end;
  9.  
  10.  

I'm struggling with it for few days and I'm out of ideas how to make it work...
I appreciate for any kind of help. Thanks guys.

varianus

  • New Member
  • *
  • Posts: 27
Re: Equalizer with Bass.dll problems
« Reply #1 on: July 03, 2025, 11:28:43 am »
You can take a look at how I implemented the equalizer in Ovoplayer.
It's been a long time since I used BASS but it worked fine at the time.

Here's my code https://github.com/varianus/ovoplayer/blob/master/src/audioengine_bass.pas

Soulrender

  • Newbie
  • Posts: 2
Re: Equalizer with Bass.dll problems
« Reply #2 on: July 03, 2025, 08:02:18 pm »
Thank You so much, I adjusted my code basing on your work and everything started working as I wanted. :)

 

TinyPortal © 2005-2018