Recent

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

Fred vS

  • Hero Member
  • *****
  • Posts: 3716
    • StrumPract is the musicians best friend
Hello Lazer.

Quote
Running SimplePlayer with -B

Ah, okay, you tried SimplePlayer, it'll be easier to find the culprit.

First of all, did you use the latest UOS source code: https://github.com/fredvs/uos/archive/refs/heads/main.zip ?

Then, open /uos-main/examples/simpleplayer.lpi, compile, and run it.

When the first window appears, delete the library paths and keep only the first two (PortAudio and libsndfile): (see image1).

Then click "Load these libraries."
If that fails, close the application and restart it, deleting the libsndfile path, then click "Load these libraries."

If it loads, we know the problem is with libsndfile.
Do the same for libportaudio.

Once you've found the problematic library (sndfile or portaudio, or both), try replacing the library path with "system" (see image2).
« Last Edit: September 04, 2025, 04:57:50 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
file LibPortaudio-64.so
LibPortaudio-64.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=4f3d5b980867c2db7df15e08c2104ea112e6e59c, stripped

« Last Edit: September 04, 2025, 05:30:48 pm by lazer »

lazer

  • Sr. Member
  • ****
  • Posts: 269
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;

Ah, I thought it was working code.

Many thanks, that was all it was.  Now I have SOUND again.
My software taks.  :P

Fred vS

  • Hero Member
  • *****
  • Posts: 3716
    • StrumPract is the musicians best friend
@Lazer In case you want to continue the combat with uos...  :-[

file LibPortaudio-64.so
LibPortaudio-64.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=4f3d5b980867c2db7df15e08c2104ea112e6e59c, stripped

Ok, so it seems the problem is from portaudio.

But you did not say yet what distro you used.

In case it is a Debian system (Ubuntu, Mint, etc, ...) could you install portaudio (if not yet installed)?

Code: Pascal  [Select][+][-]
  1. sudo apt install  libportaudio2

And after this use library path for PortAudio "system".
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?

Quote
In case it is a Debian system (Ubuntu, Mint, etc, ...) could you install portaudio (if not yet installed)?

Ah, I thought this was all part of uos.

It turns out I already had portaudio, it was a dep of audacity.
That goes a long way in explaining odd behaviour if there are two copies.
« Last Edit: September 04, 2025, 05:50:37 pm by lazer »

Fred vS

  • Hero Member
  • *****
  • Posts: 3716
    • StrumPract is the musicians best friend
Sorry.

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


Please give the result of this from console so I can try by myself:

Code: Pascal  [Select][+][-]
  1. $ lsb_release -a

and this:

Code: Pascal  [Select][+][-]
  1. $ hostnamectl
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

Fred vS

  • Hero Member
  • *****
  • Posts: 3716
    • StrumPract is the musicians best friend
Ah, I thought this was all part of uos.

It turns out I already had portaudio, it was a dep of audacity.

uos provides all these libraries for your convenience, useful if they are not already installed on the user's system.
Since uos uses dynamic library loading, you can choose which library to load and, of course, the system libraries if already installed.

That goes a long way in explaining odd behaviour if there are two copies.

No, there is no problem if both are loaded together, from audacity (system) and from uos/libs/ for SimplePlayer for example.

The strange thing is your error External: Unknown exception code 32.

« Last Edit: September 04, 2025, 06:17:45 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

serbod

  • Full Member
  • ***
  • Posts: 145
Is There a Manner to Play a Sound CrossPlatform With a Free Library???

https://wiki.freepascal.org/ACS
https://github.com/serbod/acs

Wiki page bit outdated. Now it contain built-in MP3 and FLAC decoders, and can play it on any device without external .DLL or .SO libraries.

Also, I recently ported to Pascal free stb_vorbis source, and it will be added soon.

Guva

  • Full Member
  • ***
  • Posts: 198
  • 🌈 ZX-Spectrum !!!
Is There a Manner to Play a Sound CrossPlatform With a Free Library???

Well, I can suggest this option.
https://github.com/GuvaCode/rAudio_Lazarus
However, you will have to build raudio.a yourself for Mac.
I finally built it as a static library (win64 - fpc 3.3.1 and up).

Raylib is now in line (already working in static)

Example of uploading and playing in a callback:

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4. {$WARN 5024 off : Parameter "$1" not used}
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ComCtrls,
  9.   ExtCtrls, libraudio;
  10.  
  11. type
  12.   { TForm1 }
  13.   TForm1 = class(TForm)
  14.     Button1: TButton;
  15.     Button2: TButton;
  16.     Button3: TButton;
  17.     OpenDialog1: TOpenDialog;
  18.     Timer1: TTimer;
  19.     TrackBar1: TTrackBar;
  20.     procedure Button1Click(Sender: TObject);
  21.     procedure Button2Click(Sender: TObject);
  22.     procedure FormShow(Sender: TObject);
  23.     procedure Timer1Timer(Sender: TObject);
  24.   private
  25.     FStream: TAudioStream;
  26.     class var FMusic: TMusic;
  27.     class var PlayPos: Single;
  28.     class procedure AudioCallback(bufferData: pointer; frames: LongWord); static; cdecl;
  29.   public
  30.  
  31.   end;
  32.  
  33. const
  34.   DEFAULT_FREQ = 44100;
  35.   DEFAULT_BITS = 16;
  36.   DEFAULT_CHANNELS = 2;
  37.   BUFFER_SIZE = 8192 * 2;
  38.  
  39. var
  40.   Form1: TForm1;
  41.  
  42. implementation
  43.  
  44. {$R *.lfm}
  45.  
  46. { TForm1 }
  47.  
  48. procedure TForm1.Button1Click(Sender: TObject);
  49. begin
  50.   If OpenDialog1.Execute then begin
  51.     StopMusicStream(FMusic);
  52.     StopAudioStream(FStream);
  53.     FMusic := LoadMusicStream(PChar(OpenDialog1.FileName));
  54.   end;
  55. end;
  56.  
  57. procedure TForm1.Button2Click(Sender: TObject);
  58. begin
  59.   if IsMusicReady(FMusic) then
  60.   begin
  61.     PlayMusicStream(FMusic);
  62.     PlayAudioStream(FStream);
  63.     TrackBar1.Max := Round(GetMusicTimeLength(FMusic));
  64.   end;
  65. end;
  66.  
  67.  
  68.  
  69. procedure TForm1.FormShow(Sender: TObject);
  70. begin
  71.   InitAudioDevice;
  72.  
  73.   SetAudioStreamBufferSizeDefault(BUFFER_SIZE);
  74.    FStream := LoadAudioStream(DEFAULT_FREQ, DEFAULT_BITS, DEFAULT_CHANNELS);
  75.  
  76.   if not IsAudioStreamReady(FStream) then
  77.      raise Exception.Create('Failed to initialize audio stream');
  78.  
  79.   SetAudioStreamCallback(FStream, @AudioCallback);
  80. end;
  81.  
  82. procedure TForm1.Timer1Timer(Sender: TObject);
  83. begin
  84.   TrackBar1.Position:=Round(PlayPos);
  85. end;
  86.  
  87. class procedure TForm1.AudioCallback(bufferData: pointer; frames: LongWord); cdecl;
  88. begin
  89.   upda]"]>Blockedsicstream(FMusic);
  90.  
  91.   PlayPos := GetMusicTimePlayed(FMusic);
  92. end;
  93.  
  94. end.
  95.  

« Last Edit: November 12, 2025, 07:28:46 pm by Guva »

 

TinyPortal © 2005-2018