Lazarus

Programming => Graphics and Multimedia => Audio and Video => Topic started by: ron77 on September 04, 2021, 11:29:43 am

Title: help trying to use Bass on ubuntu
Post by: ron77 on September 04, 2021, 11:29:43 am
hello i'm on ubuntu 20.04 with lazarus...

i've downloaded Bass to try and play music or just to test if it's working:

Copied libbass.so to /usr/lib and ran sudo ldconfig. No errors.

now I am trying to compile this code but I get errors

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, bass;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     procedure FormCreate(Sender: TObject);
  16.   private
  17.  
  18.   public
  19.  
  20.   end;
  21.  
  22. var
  23.   Form1: TForm1;
  24.  
  25. implementation
  26.  
  27. {$R *.lfm}
  28.  
  29. { TForm1 }
  30.  
  31. procedure TForm1.FormCreate(Sender: TObject);
  32. begin
  33.  
  34.   if not BASS_Init(-1, 44100, 0, Pointer(Handle), nil) then showMessage ('Error');
  35.  
  36. end;
  37.  
  38. end.
  39.  

the errors I get are these:

Code: Pascal  [Select][+][-]
  1. Compile Project, Target: project1: Exit code 1, Errors: 1
  2. linker: /usr/bin/ld: skipping incompatible /lib//libbass.so when searching for -lbass
  3. linker: /usr/bin/ld: skipping incompatible /usr/lib//libbass.so when searching for -lbass
  4. linker: /usr/bin/ld: skipping incompatible /lib/libbass.so when searching for -lbass
  5. linker: /usr/bin/ld: skipping incompatible /usr/lib/libbass.so when searching for -lbass
  6. linker: /usr/bin/ld: cannot find -lbass
  7. project1.lpr(21,1) Error: Error while linking
  8.  

so is libbass.io library compatible with ubuntu linux?
what am I doing wrong?
thank you any help will be appreciated...
Title: Re: help trying to use Bass on ubuntu
Post by: ron77 on September 04, 2021, 11:36:53 am
i seem to forgot that this thread belong to sound more then graphics

[Edit - moved - Trev]
Title: Re: help trying to use Bass on ubuntu
Post by: winni on September 04, 2021, 02:04:12 pm
Hi!

Do you try to link the libbass.so static?

Don't do that.

It is a dynamic link library.

To call Bass_init is enough to inform the project about the library.

Winni
Title: Re: help trying to use Bass on ubuntu
Post by: ron77 on September 04, 2021, 02:23:29 pm
Hello.
How do I dynamically link the library?  :o

I downloaded the bass24-linux version and library.so was there in the unzipped  folder I just copied it to usr/lib/ and sudo idconfig and in project option I added the bass.pas file

How do I dynamically link a library compare to static?
Title: Re: help trying to use Bass on ubuntu
Post by: Fred vS on September 04, 2021, 02:28:53 pm
Hello.
How do I dynamically link the library?  :o

I downloaded the bass24-linux version and library.so was there in the unzipped  folder I ju)st copied it to usr/lib/ and sudo idconfig and in project option I added the bass.pas file

How do I dynamically link a library compare to static?

There is this one:
https://forum.lazarus.freepascal.org/index.php/topic,9859.msg48712.html#msg48712

(But I am not sure it is still up-to-date, it dates from 2010.)
Title: Re: help trying to use Bass on ubuntu
Post by: winni on September 04, 2021, 02:28:57 pm
Hi!

There are more files called libbass.so in the zip file.

Did you take the one from the directory x64  ??

Winni
Title: Re: help trying to use Bass on ubuntu
Post by: ron77 on September 04, 2021, 02:50:12 pm
hello...

yes you were correct there is another under x64 folder and when I copied it to the project folder it compiled and run :)...

now I'm trying to run this code to plat a wave file but no sound and it gives an warning too...

here is the code:
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, bass;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     procedure FormCreate(Sender: TObject);
  16.   private
  17.  
  18.   public
  19.  
  20.   end;
  21.  
  22. var
  23.   Form1: TForm1;
  24.  
  25. implementation
  26.  
  27. {$R *.lfm}
  28.  
  29. { TForm1 }
  30.  
  31. procedure TForm1.FormCreate(Sender: TObject);
  32.  
  33.  
  34.   //if not BASS_Init(-1, 44100, 0, Pointer(Handle), nil) then showMessage ('Error');
  35.   var
  36.     B_Stream: DWord;
  37.     err: Integer;
  38.     B_Volume,B_Pan : single;
  39. begin
  40.  
  41. BASS_Init(-1, 44100, 0, Pointer(Handle), nil);
  42.  
  43. B_Stream := BASS_StreamCreateFile(False, PChar('d1.wav'), 0, 0, BASS_STREAM_PRESCAN OR BASS_SAMPLE_FLOAT );
  44.  
  45. BASS_ChannelStop(B_Stream);
  46. BASS_StreamFree(B_Stream);
  47.  
  48.  
  49.  
  50. // OR:
  51. // B_Stream := BASS_StreamCreateURL(Pchar(URL),0,BASS_Sample_Float,NIL,Nil);
  52.  
  53. err := BASS_ErrorGetCode;
  54. if err <>  0 then begin showMessage ('ERROR '+IntToStr(err)); exit; end;
  55.  
  56. B_Volume := 0.5;
  57. B_Pan := 0;
  58. BASS_ChannelSetAttribute(B_Stream, BASS_ATTRIB_VOL, B_Volume);
  59. BASS_ChannelSetAttribute(B_Stream, BASS_ATTRIB_PAN, B_PAN);
  60. BASS_ChannelPlay(B_Stream , false);
  61. end;
  62.  
  63.  
  64.  
  65.  
  66. end.
  67.  

here is the warning:

Code: Pascal  [Select][+][-]
  1. Compile Project, Target: project1: Success, Hints: 1
  2. unit1.pas(41,25) Hint: Conversion between ordinals and pointers is not portable
  3.  
Title: Re: help trying to use Bass on ubuntu
Post by: winni on September 04, 2021, 03:25:23 pm
Hi!

*  Did you do another sudo ldconfig   ??

* Do a

Code: Pascal  [Select][+][-]
  1. BASS_Init(-1, 44100, 0, @Handle, nil);

Winni
Title: Re: help trying to use Bass on ubuntu
Post by: ron77 on September 04, 2021, 03:40:39 pm
hi :)

no i did not i just added the bass.pas and libbass.so lib to project folder

I tried your suggestion but got an error:
Code: Pascal  [Select][+][-]
  1. Compile Project, Target: project1: Exit code 1, Errors: 1
  2. unit1.pas(41,26) Error: Variable identifier expected
  3.  
Title: Re: help trying to use Bass on ubuntu
Post by: winni on September 04, 2021, 03:48:28 pm
hi :)

no i did not i just added the bass.pas and libbass.so lib to project folder

I tried your suggestion but got an error:
Code: Pascal  [Select][+][-]
  1. Compile Project, Target: project1: Exit code 1, Errors: 1
  2. unit1.pas(41,26) Error: Variable identifier expected
  3.  

Hi!

You are on Linux! Don't use old Windows habbits!

The libbass.so has to reside in one of the dedicated library folders  - not in your project folder!!!!
Grrrr!

Winni
Title: Re: help trying to use Bass on ubuntu
Post by: ron77 on September 04, 2021, 03:54:49 pm
okay i copied libbass.so to usr/lib/ and did sudo idconfig

now here is the code :

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, bass;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     procedure FormCreate(Sender: TObject);
  16.   private
  17.  
  18.   public
  19.  
  20.   end;
  21.  
  22. var
  23.   Form1: TForm1;
  24.  
  25. implementation
  26.  
  27. {$R *.lfm}
  28.  
  29. { TForm1 }
  30.  
  31. procedure TForm1.FormCreate(Sender: TObject);
  32.  
  33.  
  34.   //if not BASS_Init(-1, 44100, 0, Pointer(Handle), nil) then showMessage ('Error');
  35.   var
  36.     B_Stream: DWord;
  37.     err: Integer;
  38.     B_Volume,B_Pan : single;
  39. begin
  40.  
  41. BASS_Init(-1, 44100, 0, @Handle, nil); // <------- line of the error!!!!
  42.  
  43. B_Stream := BASS_StreamCreateFile(False, PChar('d1.wav'), 0, 0, BASS_STREAM_PRESCAN OR BASS_SAMPLE_FLOAT );
  44.  
  45. BASS_ChannelStop(B_Stream);
  46. BASS_StreamFree(B_Stream);
  47.  
  48.  
  49.  
  50. // OR:
  51. // B_Stream := BASS_StreamCreateURL(Pchar(URL),0,BASS_Sample_Float,NIL,Nil);
  52.  
  53. err := BASS_ErrorGetCode;
  54. if err <>  0 then begin showMessage ('ERROR '+IntToStr(err)); exit; end;
  55.  
  56. B_Volume := 0.5;
  57. B_Pan := 0;
  58. BASS_ChannelSetAttribute(B_Stream, BASS_ATTRIB_VOL, B_Volume);
  59. BASS_ChannelSetAttribute(B_Stream, BASS_ATTRIB_PAN, B_PAN);
  60. BASS_ChannelPlay(B_Stream , false);
  61. end;
  62.  
  63.  
  64.  
  65.  
  66. end.
  67.  

i still get error

Code: Pascal  [Select][+][-]
  1. Compile Project, Target: project1: Exit code 1, Errors: 1
  2. unit1.pas(41,26) Error: Variable identifier expected
  3.  
Title: Re: help trying to use Bass on ubuntu
Post by: winni on September 04, 2021, 04:53:12 pm
Hi!

I got no compiler error on this line:

Code: Pascal  [Select][+][-]
  1. BASS_Init(-1, 44100, 0, @Handle, nil);


As a workaround you can use

Code: Pascal  [Select][+][-]
  1. BASS_Init(-1, 44100, 0, nil, nil);

And:

In your FormCreate you only should do the BASS_init.

The rest of you could should be in an ButtonClick.

While Formcreate is executed there is a lot of stuff initialized. Though you cannot rely on that everythind is ready .

Winni
Title: Re: help trying to use Bass on ubuntu
Post by: ron77 on September 04, 2021, 05:11:59 pm
hi :)

okay i did as follow with my code:
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, bass;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     procedure Button1Click(Sender: TObject);
  17.     procedure FormCreate(Sender: TObject);
  18.   private
  19.  
  20.   public
  21.  
  22.   end;
  23.  
  24. var
  25.   Form1: TForm1;
  26.     B_Stream: DWord;
  27.     err: Integer;
  28.     B_Volume,B_Pan : single;
  29.  
  30. implementation
  31.  
  32. {$R *.lfm}
  33.  
  34. { TForm1 }
  35.  
  36. procedure TForm1.FormCreate(Sender: TObject);
  37.  
  38.  
  39.   //if not BASS_Init(-1, 44100, 0, Pointer(Handle), nil) then showMessage ('Error');
  40.  
  41. begin
  42.  
  43. BASS_Init(-1, 44100, 0, nil, nil);
  44. //BASS_Init(-1, 44100, 0, Pointer(Handle), nil);
  45.  
  46.  
  47. end;
  48.  
  49. procedure TForm1.Button1Click(Sender: TObject);
  50. begin
  51.      B_Stream := BASS_StreamCreateFile(False, PChar('./d1.wav'), 0, 0, BASS_STREAM_PRESCAN OR BASS_SAMPLE_FLOAT );
  52.  
  53. BASS_ChannelStop(B_Stream);
  54. BASS_StreamFree(B_Stream);
  55.  
  56.  
  57.  
  58. // OR:
  59. // B_Stream := BASS_StreamCreateURL(Pchar(URL),0,BASS_Sample_Float,NIL,Nil);
  60.  
  61. err := BASS_ErrorGetCode;
  62. if err <>  0 then begin showMessage ('ERROR '+IntToStr(err)); exit; end;
  63.  
  64. B_Volume := 0.5;
  65. B_Pan := 0;
  66. BASS_ChannelSetAttribute(B_Stream, BASS_ATTRIB_VOL, B_Volume);
  67. BASS_ChannelSetAttribute(B_Stream, BASS_ATTRIB_PAN, B_PAN);
  68. BASS_ChannelPlay(B_Stream , false);
  69. end;
  70.  
  71.  
  72.  
  73.  
  74. end.
  75.  

and when I press the button a messagebox pop with "ERROR 5"
Title: Re: help trying to use Bass on ubuntu
Post by: winni on September 04, 2021, 05:29:49 pm
Hi!

Is './d1.wav' in your project directory?

Winni
Title: Re: help trying to use Bass on ubuntu
Post by: ron77 on September 04, 2021, 05:34:25 pm
yes it is i checked
Title: Re: help trying to use Bass on ubuntu
Post by: winni on September 04, 2021, 05:42:19 pm
Hi!

BASS_STREAM_PRESCAN  is needed for mp3 or ogg but not for wav

Before you start the next question start reading the bass.chm !!!!

Winni
Title: Re: help trying to use Bass on ubuntu
Post by: winni on September 04, 2021, 09:48:41 pm
Hi!

I made a  very simple MP3 player with BASS for you:

Load File  / Start  / Stop and a volume trackbar.

For some people that is enough.
But I think this may be the start of your further development.

BassTest in the attchment

Winni
Title: Re: help trying to use Bass on ubuntu
Post by: stephanos on December 02, 2021, 10:39:05 pm
I faced a similar problem using bass in Lazarus for Windows.  It might be relevant and helpful.  I placed bass.pas, bass.dll and the mp3 file I was working with in the project folder.  There is a comment in this topic about how that differs in Linux.

Code: Pascal  [Select][+][-]
  1. uses
  2.      bass
  3. var
  4.      EC : integer;   H : HSTREAM;  L_Seconds : double;
  5. begin
  6.      BASS_Init(0, 44100, 0, H, NIL);  // Without this code the code below will not work
  7.  
Notice how the fourth parameter is H.  Also, my objective was to extract data so something in the Init code might need to change in order to stream music.  There is lots about how to configure Init here:
http://www.un4seen.com/doc/#bass/BASS_Init.html

This bit of code will not be new to you.  Now you have BASS_Init, in place it should work. 
Code: Pascal  [Select][+][-]
  1. H := BASS_StreamCreateFile(FALSE, pchar(Utf8Encode('BAILE MINHA MADEIRA.mp3')), 0, 0, BASS_STREAM_DECODE);
  2. EC := BASS_ErrorGetCode();  write('Error Code = ', EC); // Expected and got zero
  3. L_Seconds := BASS_ChannelBytes2Seconds(H, L_Bytes); // copy to a variable the size in bytes
  4. // do other things
  5. BASS_StreamFree(H); // close the stream and free the resources

When
Code: Pascal  [Select][+][-]
  1. H := BASS_StreamCreateFile(FALSE, pchar(Utf8Encode('BAILE MINHA MADEIRA.mp3')), 0, 0, BASS_STREAM_DECODE);
fails, H becomes value: zero.  That zero is not to be confused with error code zero.  What it means is H can be tested to see if it worked:
Code: Pascal  [Select][+][-]
  1. if (H <> 0) then
  2.   do something  // because it worked and a stream was opened
  3. else
  4.   do something else // because a stream was not opened

Before I successfully inserted the BASS_Init line, the ‘H :=’ code did no work.  Use of the
Code: Pascal  [Select][+][-]
  1. EC := BASS_ErrorGetCode();  write('Error Code = ', EC); // Expected and got zero
Immediately after the ‘H :=’ code produced an error number of 8.  As you will see from the documentation website, 8 means ‘BASS_ERROR_INIT ’.  So I was being given a great big hint there about what the problem was.  More on error codes here:
http://www.un4seen.com/doc/#bass/BASS_ErrorGetCode.html (http://www.un4seen.com/doc/#bass/BASS_ErrorGetCode.html)

After I made the executable and put it on my MP3 player it did not work and asked for bass.dll to be present as well.

Finally, there is a dedicated bass forum, which solved this problem for me
http://www.un4seen.com/ (http://www.un4seen.com/)

I hope that helped and was not too late.  My problem was solved yesterday
Title: Re: help trying to use Bass on ubuntu
Post by: winni on December 02, 2021, 11:28:25 pm
Hi!

I told you to read the bass.chm from the download ....

To help you convert the Bass-Errors to strings I made a string-array long time ago.

Perhaps it helps you for development.

Code: Pascal  [Select][+][-]
  1. // comments from Unit Bass
  2. BassErrors : array[-1..46] of string = (
  3.   {-1}          'some other mystery problem',
  4.   {0}           'all is OK',
  5.   {1}           'memory error',
  6.   {2}           'can''t open the file',
  7.   {3}           'can''t find a free sound driver',
  8.   {4}           'the sample buffer was lost',
  9.   {5}           'invalid handle',
  10.   {6}           'unsupported sample format',
  11.   {7}           'invalid position',
  12.   {8}           'BASS_Init has not been successfully called',
  13.   {9}           'BASS_Start has not been successfully called ',
  14.                 '', '',
  15.   {12}          'no CD in drive', //BASS_CD
  16.   {13}          'invalid track number', //BASS_CD
  17.   {14}          'already initialized/paused/whatever',
  18.                 '', '',
  19.   {17}          'not an audio track', // BASS_CD
  20.   {18}          'can''t get a free channel',
  21.   {19}          'an illegal type was specified',
  22.   {20}          'an illegal parameter was specified',
  23.   {21}          'no 3D support',
  24.   {22}          'no EAX support',
  25.   {23}          'illegal device number',
  26.   {24}          'not playing',
  27.   {25}          'illegal sample rate',
  28.                 '',
  29.   {27}          'the stream is not a file stream',
  30.                 '',
  31.   {29}          'no hardware voices available',
  32.                 '',
  33.   {31}          'the MOD music has no sequence data',
  34.   {32}          'no internet connection could be opened',
  35.   {33}          'couldn''t create the file',
  36.   {34}          'effects are not available',
  37.                 '', '',
  38.   {37}          'requested data is not available',
  39.   {38}          'the channel is/isn''t a "decoding channel"',
  40.   {39}          'a sufficient DirectX version is not installed',
  41.   {40}          'connection timedout',
  42.   {41}          'unsupported file format',
  43.   {42}          'unavailable speaker',
  44.   {43}          'invalid BASS version (used by add-ons)',
  45.   {44}          'codec is not available/supported',
  46.   {45}          'the channel/file has ended',
  47.   {46}          'the device is busy'
  48.   );
  49.  

The empty strings belong to the errors of bass modules that I have not explored.

Winni
Title: Re: help trying to use Bass on ubuntu
Post by: stephanos on December 03, 2021, 12:47:56 pm
I faced a similar problem using bass in Lazarus for Windows.  It might be relevant and helpful.  I placed bass.pas, bass.dll and the mp3 file I was working with in the project folder.  There is a comment in this topic about how that differs in Linux.

Code: Pascal  [Select][+][-]
  1. uses
  2.      bass
  3. var
  4.      EC : integer;   H : HSTREAM;  L_Seconds : double;
  5.  
  6. begin
  7.      BASS_Init(0, 44100, 0, H, NIL);  // Without this code the code below will not work

Notice how the fourth parameter in the BASS_Init code is H.  Also, my objective was to extract data so something in the Init code might need to change in order to stream music.  There is lots about how to configure Init here:
http://www.un4seen.com/doc/#bass/BASS_Init.html (http://www.un4seen.com/doc/#bass/BASS_Init.html)

The BASS_Init code will be new to you.  Now you have BASS_Init, in place it should work. 
Code: Pascal  [Select][+][-]
  1. H := BASS_StreamCreateFile(FALSE, pchar(Utf8Encode('BAILE MINHA MADEIRA.mp3')), 0, 0, BASS_STREAM_DECODE);
  2. EC := BASS_ErrorGetCode();  write('Error Code = ', EC); // Expected and got zero
  3. L_Seconds := BASS_ChannelBytes2Seconds(H, L_Bytes); // copy to a variable the size in bytes
  4. // do things
  5. BASS_StreamFree(H); // close the stream and free the resources

When
Code: Pascal  [Select][+][-]
  1. H := BASS_StreamCreateFile(FALSE, pchar(Utf8Encode('BAILE MINHA MADEIRA.mp3')), 0, 0, BASS_STREAM_DECODE);
fails, H becomes value: zero.  That zero is not to be confused with error code zero.  What it means is H can be tested to see if it worked:
Code: Pascal  [Select][+][-]
  1. if (H <> 0) then
  2.   do something  // because it worked and a stream was opened
  3. else
  4.   do something else // because a stream was not opened

Before I successfully inserted the BASS_Init line, the ‘H :=’ code did no work.  Use of the
Code: Pascal  [Select][+][-]
  1. EC := BASS_ErrorGetCode();  write('Error Code = ', EC); // Expected and got zero
Immediately after the ‘H :=’ code produced an error number of 8.  As you will see from the documentation website, 8 means ‘BASS_ERROR_INIT ’.  So I was being given a great big hint there about what the problem was.  More on error codes here:
http://www.un4seen.com/doc/#bass/BASS_ErrorGetCode.html (http://www.un4seen.com/doc/#bass/BASS_ErrorGetCode.html)

After I made the executable and put it on my MP3 player it did not work.  I needed to place bass.dll in the same folder as the EXE.

Finally, there is a dedicated bass forum, which solved this problem for me
Code: Pascal  [Select][+][-]
  1. http://www.un4seen.com/

I hope that helped and was not too late.  My problem was solved yesterday
TinyPortal © 2005-2018