Recent

Author Topic: (SOLVED)Is There a Manner to Play a Sound CrossPlatform With a Free Library???  (Read 5955 times)

lazer

  • Sr. Member
  • ****
  • Posts: 269
the rest of that path is some kind of AI hallucination.
AI hallucination? Both Lazarus and FPC do not use any AI (except for the aissist package which is not installed by default). What are you doing?

AI hallucination was supposed to be humouristic. I view of that crazy path it invented it was like a hand with seven fingers.

lazer

  • Sr. Member
  • ****
  • Posts: 269
I previously had this code working with uos but after the system update it get silence.

The code is not simple and easy to follow and I would rather have something like WP's trimmed down single file to debug than 3 megs to trawl through.

It may be a more complete and more capable solution where that is needed.

lazer

  • Sr. Member
  • ****
  • Posts: 269
the rest of that path is some kind of AI hallucination.
AI hallucination? Both Lazarus and FPC do not use any AI (except for the aissist package which is not installed by default). What are you doing?

The question is what is Lazarus doing.
Code: Pascal  [Select][+][-]
  1. The file "/builddir/build/BUILD/fpc-3.2.2-build/fpcbuild-3.2.2/fpcsrc/rtl/inc/astrings.inc" was not found.

It sure wasn't me which fed it that string of garbage.

The file it is looking for is in /usr/share     :  /usr/share/fpcsrc/rtl/inc/astrings.inc !
« Last Edit: September 03, 2025, 10:10:42 pm by lazer »

Fred vS

  • Hero Member
  • *****
  • Posts: 3721
    • StrumPract is the musicians best friend
I previously had this code working with uos but after the system update it get silence.

If you have problems with the uos provided libraries, you can use the system ones, just use 'system' as the library path.

Example:
 
Code: Pascal  [Select][+][-]
  1.  resu  := uos_LoadLib(PChar('system'), PChar('system'), PChar('system'), nil, nil, nil, nil);
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

lazer

  • Sr. Member
  • ****
  • Posts: 269
Hi Fred thanks for the suggestion.

I replaced the previous call as you suggested. (I'm working with WAV files on Linux).

Code: Pascal  [Select][+][-]
  1.   //res := uos_LoadLib(PChar(PA_FileName), PChar(SF_FileName), nil, Nil, Nil, Nil);
  2.   res := uos_LoadLib(PChar('system'), PChar('system'), PChar('system'), Nil, Nil, Nil);
  3.  

Previously I got a non zero result. Now I get an exception.

Code: Pascal  [Select][+][-]
  1. Project hill3 raised exception class 'External: Unknown exception code 32'.
  2.  
  3.  At address 7FB2F1563462


The call to uos_LoadLib  does not return. The exception happens thre.
« Last Edit: September 03, 2025, 10:19:17 pm by lazer »

Fred vS

  • Hero Member
  • *****
  • Posts: 3721
    • StrumPract is the musicians best friend
Hi Fred thanks for the suggestion.

I replaced the previous call as you suggested. (I'm working with WAV files on Linux).

Code: Pascal  [Select][+][-]
  1.   //res := uos_LoadLib(PChar(PA_FileName), PChar(SF_FileName), nil, Nil, Nil, Nil);
  2.   res := uos_LoadLib(PChar('system'), PChar('system'), PChar('system'), Nil, Nil, Nil);
  3.  

Previously I got a non zero result. Now I get an exception.

Code: Pascal  [Select][+][-]
  1. Project hill3 raised exception class 'External: Unknown exception code 32'.
  2.  
  3.  At address 7FB2F1563462


The call to uos_LoadLib  does not return. The exception happens thre.

Hello.

Hum, I never seen that error code 32...
Did you try the uos example SimplePlayer?
Do you get the same error?
What Linux distro are you using, with what cpu?
When do you get that error, at loading of the libraries or when playing?

If you only want to play wav files, only portaudio and sndfile libraries are needed, so:
(Look at the number of parameters)
 
Code: Pascal  [Select][+][-]
  1.  res  := uos_LoadLib(PChar('system'), PChar('system'), nil, nil, nil, nil, nil);
« Last Edit: September 03, 2025, 10:35:44 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

lazer

  • Sr. Member
  • ****
  • Posts: 269
Yes, I realise I only need to first two. I tested that first. Then I thought it better to do exactly what you suggested, so as not to introduce any possible misunderstanding on my end.

I may have edited after you read. I did debug this to determine that the exception happened in uos_LoadLib()
When using the actual filenames instead of 'system' it return -1.
« Last Edit: September 03, 2025, 10:49:34 pm by lazer »

Fred vS

  • Hero Member
  • *****
  • Posts: 3721
    • StrumPract is the musicians best friend
Yes, I realise I only need to first two. I tested that first. Then I thought it better to do exactly what you suggested, so as not to introduce any possible misunderstanding on my end.

I may have edited after you read. I did debug this to determine that the exception happened in uos_LoadLib()

You did not give the distro (Ubuntu, ArchLinux, Debian, etc...) and the cpu (i386, amd64, arm, aarch64, etc...) so It is difficult for me to test.
Also what fpc version are you using, and, important, did you add the -B fpc parameter for compilation?
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

lazer

  • Sr. Member
  • ****
  • Posts: 269
Sorry.

i7-4770K
Fed 42
Lazarus 4.2 (rev Unknown) FPC 3.2.2 x86_64-linux-gtk2

I'm compiling in IDE
I do not set $B explicitly so it should be building $B- , is that correct?
« Last Edit: September 03, 2025, 11:02:49 pm by lazer »

Fred vS

  • Hero Member
  • *****
  • Posts: 3721
    • StrumPract is the musicians best friend
Ok, thanks.

For the -B parameter, in Lazarus, Project Options, Compiler Options, Custom Options add -B (see picture).

Did you try the uos example SimplePlayer ? (In lazarus, Project, Open Project and choose /uos/examples/simpleplayer.lpi.)
Is it working?
https://github.com/fredvs/uos/archive/refs/heads/main.zip
« Last Edit: September 04, 2025, 01:03:46 am by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

lazer

  • Sr. Member
  • ****
  • Posts: 269
Running simpleplayer with -B

Code: Pascal  [Select][+][-]
  1. Error while loading libraries...

I copied each of the library paths from the edit boxes on the window and all point to existing files.

when adding -B , I hit Test button and it picked two instances of duplicated units
Code: Pascal  [Select][+][-]
  1. 3056520 -rw-r--r--. 1 root root 199320 May 10 02:00 /usr/lib64/fpc/3.2.2/units/x86_64-linux/fv/dialogs.ppu
  2. 3029063 -rw-r--r--. 1 root root 467665 Aug  3 02:00 /usr/lib64/lazarus/lcl/units/x86_64-linux/dialogs.ppu
  3.  
  4. 3056540 -rw-r--r--. 1 root root  46296 May 10 02:00 /usr/lib64/fpc/3.2.2/units/x86_64-linux/fv/menus.ppu
  5. 3029159 -rw-r--r--. 1 root root 167537 Aug  3 02:00 /usr/lib64/lazarus/lcl/units/x86_64-linux/menus.ppu
  6.  

These are separate things but if it is flagging them a duplicates it may mean there is search path problem.

Also:
WARNING: orphaned file found:  examples/units/x86_64-linux/simpleplayer_noflat.o
« Last Edit: September 04, 2025, 10:26:31 am by lazer »

lazer

  • Sr. Member
  • ****
  • Posts: 269
Hi Fred.

just returning -1 is not much help. Now I need to start editing and debugging this rather complex code myself just find out what went wrong.

Then I get down to LibPortaudio-64.so which I don't seem to have source for.

That's why I said "not simple and easy to follow".

lazer

  • Sr. Member
  • ****
  • Posts: 269
returning to the segfault in uplaysound
Code: Pascal  [Select][+][-]
  1. {$ifndef FPC_HAS_ANSISTR_ASSIGN}
  2. {$define FPC_HAS_ANSISTR_ASSIGN}
  3. Procedure fpc_AnsiStr_Assign (Var DestS : Pointer;S2 : Pointer);[Public,Alias:'FPC_ANSISTR_ASSIGN'];  compilerproc;
  4. {
  5.   Assigns S2 to S1 (S1:=S2), taking in account reference counts.
  6. }
  7. begin
  8.   if DestS=S2 then
  9.     exit;
  10.  

The test DestS=S2 is segfaulting.

Here's where I effectively call it in assigning the filename.
Code: Pascal  [Select][+][-]
  1. {$mode objfpc}{$H-}  
  2. ...
  3. {$IFDEF PLAYSOUND}
  4. procedure TspellWin.PlayWAVfile(soundfilename:ansistring; flags:integer);
  5. begin
  6.    Application.messagebox(Pchar(soundfilename ),'soundfile.',mb_OK);
  7.   soundplayer.SoundFile:=soundfilename;
  8.   //soundplayer.Execute;
  9. end;
  10. {$ELSE}
  11.  

Code: Pascal  [Select][+][-]
  1. {$mode objfpc}{$H+}
  2. ...
  3.   Tplaysound = class(TComponent)  // wp: changed from: TAboutPlaySound)
  4. ...
  5.     property SoundFile: string read fPathToSoundFile write fPathToSoundFile;
  6.  
  7.  

  Application.messagebox correctly shows the filename is good.

Next line segfaults.


lazer

  • Sr. Member
  • ****
  • Posts: 269
Here's what the call stack looks like.

The file name seems to get passed correctly
« Last Edit: September 04, 2025, 02:07:06 pm by lazer »

wp

  • Hero Member
  • *****
  • Posts: 13266
Did you create the soundplayer? The unit that I sent above is pure runtime code, you must create the player yourself.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   {$IFDEF DARWIN}
  4.   // Copy the folder "sounds" into the Resources folder of the application bundle
  5.   SoundDir := Application.Location + '../Resources/sounds/';
  6.   {$ELSE}
  7.   SoundDir := Application.Location + 'sounds/';
  8.   {$ENDIF}
  9.   soundplayer := TPlaySound.Create(self);
  10. end;

 

TinyPortal © 2005-2018