Author Topic: Using the Bass_FX add-on in a Delphi project  (Read 629 times)

Willicious

  • Posts: 16
I'm currently working on a project which uses the Bass.dll plugin.

It's already installed, and at present just makes use of the basic plugin for playing audio files. Ideally, I'd like to use one of the add-ons (specifically, one which can pitch/tune the audio up or down during playback, such as Bass_FX).

I could do with some help getting started specifically with the add-on; I've located the .pas file in the Bass_FX folder, but there doesn't seem to be a .dll anywhere.

Also, once I've managed to get the add-on in the correct place, how do I call it for use?

Chris

  • Posts: 2217
Re: Using the Bass_FX add-on in a Delphi project
« Reply #1 on: 22 Mar '23 - 10:59 »
Hi, just redownload bass_fx24 https://www.un4seen.com/download.php?z/0/bass_fx24
and take a look inside the Delphi Subdirectory. There are some Delphi Demos.

Willicious

  • Posts: 16
Re: Using the Bass_FX add-on in a Delphi project
« Reply #2 on: 23 Mar '23 - 03:34 »
I get error "File not found ...\bass.pas" when I try to run the example project. In spite of this, both bass.pas and bass_fx.pas show up in the project explorer:



N.B. I also have both bass.dll and bass_fx.dll in the example project folder.

Willicious

  • Posts: 16
Re: Using the Bass_FX add-on in a Delphi project
« Reply #3 on: 23 Mar '23 - 04:03 »
Managed to grab the bass.pas file from another project and placed it into the example project folder. This seemed to satisfy the error, but now the .exe generates this error message when running:



All files associated with the example project are in the same folder, "...Delphi\Tempo":


Chris

  • Posts: 2217
Re: Using the Bass_FX add-on in a Delphi project
« Reply #4 on: 23 Mar '23 - 14:07 »
Hi
the most Demos are based on Delphi 7 (at this time was PChar = PAnsichar)
so on modern Delphi Versions PChar = PWidechar so you must add Bass_Unicode as flag on the StreamCreateFile call.
I have add a Demo that will work/compile fine with modern Delphi Versions.

Willicious

  • Posts: 16
Re: Using the Bass_FX add-on in a Delphi project
« Reply #5 on: 26 Mar '23 - 00:58 »
I have add a Demo that will work/compile fine with modern Delphi Versions.

Brilliant, this works. Thank you!  :)

So, I have added bass_fx.dll to my own project's bin folder. If I want to use the pitch shifter to change the pitch of a sound within the project, how do I call it?

Apologies for the noob question, but I really would be guessing if I went ahead and starting throwing lines of code in...

Chris

  • Posts: 2217
Re: Using the Bass_FX add-on in a Delphi project
« Reply #6 on: 26 Mar '23 - 14:36 »
e.g something like this
// onformcreate
 
Code: [Select]
// check the correct BASS was loaded
  If (HiWord(BASS_GetVersion()) <> BASSVERSION) then
  begin
    application.MessageBox
      ('An incorrect version of BASS.DLL was loaded (2.4 is required)',
      'Incorrect BASS.DLL', MB_ICONERROR or MB_OK);
    application.Terminate;
  end;

  // check the correct BASS_FX was loaded
  If (HiWord(BASS_FX_GetVersion()) <> BASSVERSION) then
  begin
    application.MessageBox
      ('An incorrect version of BASS_FX.DLL was loaded (2.4 is required)',
      'Incorrect BASS_FX.DLL', MB_ICONERROR or MB_OK);
    application.Terminate;
  end;

  // setup output - default device, 44100hz, stereo, 16 bits
  If BASS_Init(-1, 44100, 0, frmTempo.handle, nil) = false then
  begin
    Error('Couldnt Initialize Digital Output');
    application.Terminate;
  end;
//
// load audiofile
Code: [Select]
chan := BASS_StreamCreateFile(false, PChar(od.Filename), 0, 0,   BASS_STREAM_DECODE or BASS_Unicode);
if chan <> 0 then
  chan := BASS_FX_TempoCreate(chan, BASS_SAMPLE_LOOP or BASS_FX_FREESOURCE);

ontrackbar change // trackbar has minmax values -30 +30
Code: [Select]
BASS_ChannelSetAttribute(chan, BASS_ATTRIB_TEMPO_PITCH, fTrackbar.position);

Willicious

  • Posts: 16
Re: Using the Bass_FX add-on in a Delphi project
« Reply #7 on: 3 Apr '23 - 05:07 »
OK great, thanks for this! I have found where BASS gets loaded in the project. The syntax is slightly different from your example, but the info is all there:

Code: [Select]
{Sound.pas unit}

constructor TSoundManager.Create;
begin
inherited;

  if FileExists(AppPath + 'bass.dll') then
  begin
    Load_BASSDLL(AppPath + 'bass.dll');
    fIsBassLoaded := BASS_Init(-1, 44100, BASS_DEVICE_NOSPEAKER, 0, nil);
    if not fIsBassLoaded then
    ShowMessage('BASS.DLL could not initialize. The app will run but music and sound will not play.');
  end else begin
    ShowMessage('BASS.DLL not found. The app will run but music and sound will not play.');
    fIsBassLoaded := false;
  end;

I've then copypasted the following in order to check for bass_fx.dll (NOTE: I tried changing Load_BASSDLL to something else, but it gives me an undeclared identifier error, so I left it as Load_BASSDLL. I get no errors, and sound plays fine in the app, so I assume this is OK):

Code: [Select]
{Sound.pas unit cont...}

  if FileExists(AppPath + 'bass_fx.dll') then
  begin
    Load_BASSDLL(AppPath + 'bass_fx.dll');
  end else begin
    ShowMessage('BASS_FX.DLL not found. The app will run but music and sound will not play.');
  end;
end;

So far so good, the app makes the checks for both bass and bass_fx (I tried removing each file and the message pops up as expected).

The next bit is the tough part. I want to call the pitch shifter for a particular function within the project. Namely, there are (-/+) buttons which change a value by -1 and +1 respectively. Pressing either button currently cues a short sound effect which plays each time the number value is changed (also, the values continue to change if either button is held down).

As the value is shifted up, I want the sound to pitch up by (e.g. 0.25), and as the value is shifted down, I want to pitch it down by (e.g. 0.25).

Here's the code that cues the sound effect:

Code: [Select]
{Game.pas unit}

procedure TGame.ChangeValue(aValue: Integer);
begin
  if (aValue <> currValue) then currValue := aValue;

  CueSoundEffect(SFX_CHANGE_RR);
end;

As you can see, it's fairly basic at present. I need to input code here that tells the app to pitch shift up with each increase in value, and down with each decrease in value.

Any suggestions/help you can give me with this will be much appreciated!
« Last Edit: 3 Apr '23 - 05:13 by Willicious »

Chris

  • Posts: 2217
Re: Using the Bass_FX add-on in a Delphi project
« Reply #8 on: 3 Apr '23 - 12:06 »
So far I know is the TSoundManager  a old Delphi Class from 2006 !


So the Question is do you want to load the Libs as Static or dynamic  DLL´s ?
My Example was Static.
It would not be recommend to use that old (outdated) class .
If you want to load dynamic the you can use the  "Delphi dynamic loading API" Units.
You can download them here.

Willicious

  • Posts: 16
Re: Using the Bass_FX add-on in a Delphi project
« Reply #9 on: 4 Apr '23 - 03:12 »
So the Question is do you want to load the Libs as Static or dynamic  DLL´s ?

Whichever is easiest to use! I've downloaded the link you shared, thank you for that. I have no idea what I'm doing with it at this stage though, I'm very much a beginner to all this.

It would not be recommend to use that old (outdated) class

I'm all for updating, but I would probably need a bit of guidance to do this. The project is quite large and many units depend on the SoundManager class. I guess I could create a branch and have a play around with it, that way the existing class is still intact if it all goes wrong.

Are you thinking that updating the class might make it easier to implement the more advanced sound-processing functions?

Your help with this is invaluable, btw. Thank you for your quick replies.