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?
... uses
bass, bass_fx;
type
...
TjustPlayer = class(TForm)
...
public
const
frequencies: array[0..9] of single = (80, 160, 320, 600, 1000, 3000, 6000, 12000, 14000, 16000);
var
musicStream : Thandle;
eq: BASS_BFX_PEAKEQ;
fxHandles: array[0..9] of cardinal;
...
and here are the procedures to control equalizer:
procedure TJustPlayer.InitEqualizer;
var
i: Integer;
begin
if musicStream = 0 then Exit;
ResetEqualizer;
for i := 0 to 9 do
begin
FillChar(eq, SizeOf(eq), 0);
eq.lBand := 0;
eq.fBandwidth := 18;
eq.fQ := 0;
eq.fCenter := Frequencies[i];
eq.fGain := 0;
eq.lChannel := BASS_BFX_CHANALL;
fxHandles[i] := BASS_ChannelSetFX(musicStream, BASS_FX_BFX_PEAKEQ, 2);
if fxHandles[i] <> 0 then
BASS_FXSetParameters(fxHandles[i], @eq);
end;
end;
procedure TJustPlayer.ApplyEqualizerBand(bandIndex: Integer; freq: Single; gainValue: Integer);
begin
if musicStream = 0 then Exit;
if (bandIndex < 0) or (bandIndex > 9) then
begin
ShowMessage('Incorrect band index: ' + IntToStr(bandIndex));
Exit;
end;
if fxHandles[bandIndex] = 0 then
begin
fxHandles[bandIndex] := BASS_ChannelSetFX(musicStream, BASS_FX_BFX_PEAKEQ, 0);
if fxHandles[bandIndex] = 0 then
begin
ShowMessage('Cannot Apply Effect: ' + IntToStr(BASS_ErrorGetCode));
Exit;
end;
end;
FillChar(eq, SizeOf(eq), 0);
eq.lBand := bandIndex;
eq.fCenter := freq;
eq.fGain := gainValue;
eq.fQ := 1.0;
eq.lChannel := BASS_BFX_CHANALL;
if not BASS_FXSetParameters(fxHandles[bandIndex], @eq) then
begin
ShowMessage('Equalizer Error: ' + IntToStr(BASS_ErrorGetCode));
end;
end;
procedure TJustPlayer.ResetEqualizer;
var
i: Integer;
begin
if musicStream = 0 then Exit;
for i := 0 to 9 do
begin
if fxHandles[i] <> 0 then
begin
BASS_ChannelRemoveFX(musicStream, fxHandles[i]);
fxHandles[i] := 0;
end;
end;
end;
Finally I'm trying to apply effect(s) this way
procedure TjustPlayer.applyButtonClick(Sender: TObject);
begin
ApplyEqualizerBand(0, single(frequencies[1]), 15 - Equalizer.TrackBar1.position);
//...
ApplyEqualizerBand(9, single(frequencies[9]), 15 - Equalizer.TrackBar10.position);
//All 10 trackbars are set min=0, max=30
end;
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.