Forum > Audio and Video
Equalizer with Bass.dll problems
(1/1)
Soulrender:
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 [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---... usesbass, bass_fx;type...TjustPlayer = class(TForm)...publicconst frequencies: array[0..9] of single = (80, 160, 320, 600, 1000, 3000, 6000, 12000, 14000, 16000);varmusicStream : Thandle;eq: BASS_BFX_PEAKEQ;fxHandles: array[0..9] of cardinal; ...
and here are the procedures to control equalizer:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- 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
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- 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=30end;
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:
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:
Thank You so much, I adjusted my code basing on your work and everything started working as I wanted. :)
Navigation
[0] Message Index