Recent

Author Topic: Lazarus simple sound  (Read 11617 times)

openscoreboard

  • New Member
  • *
  • Posts: 30
  • openscoreboard
Lazarus simple sound
« on: December 26, 2015, 03:13:55 pm »
Hello:

Im buiding a open scoreboard for linux (raspeberry pi), windows and mac.

http://sourceforge.net/projects/open-scoreboard/?source=directory


I need play wav file, but all components that used no work for me (ACS, PLAYSOUND, FPSOUND)

Only uos (United Ope'nLib of Sound) work in sample but i dont know include in my source.

can anybody help me?

Thanks...


openscoreboard

  • New Member
  • *
  • Posts: 30
  • openscoreboard
Re: Lazarus simple sound
« Reply #1 on: December 26, 2015, 03:30:00 pm »
I forget...

S.O: Lubuntu 14.04 64bits

Lazarus: 1.2.4+dfsg2

FPC:2.6.4

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1290
Re: Lazarus simple sound
« Reply #2 on: December 26, 2015, 05:46:17 pm »
hello,
Fred vS (developer of uos) said this to use uos with Lazarus :
Quote
The steps to use uos are like this.
1- Create a new application.
2- In the directory of that new application, paste uos.pas, lazdyn_libsndfile.pas, lazdyn_portaudio.pas and lazdyn_mpg123.pas
3- Add in your uses section : uos
4- Develop your program.
5- Compile it.
6- Run it.

Edit :  oops sorry   :-X   forget this , no lazdyn files in the last release of uos.

« Last Edit: December 26, 2015, 06:04:36 pm by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1290
Re: Lazarus simple sound
« Reply #3 on: December 27, 2015, 12:17:34 am »
hello,
here is how to use uos library in your project :

1 - Download uos files from here (download ZIP)
2 - In your project folder create a new folder  uos_lib
3 - In this new folder put all the files which are in the src folder of uos and the folders Linux, FreeBSD, Windows, Mac (you can only copy the folder for your O.S). Those folders are in Examples/lib of uos.
4 - In your project option add uos_lib in the other unit files ("-Fu")
5 - in your program create a procedure to load uos library, something like this :
Code: Pascal  [Select][+][-]
  1. uses uos_flat;
  2. {$R *.lfm}
  3. var uos_lib_OK : Boolean;
  4. procedure Load_uos;
  5. var
  6.   res: integer;
  7.   ordir, opath, PA_FileName, SF_FileName, MPG_FileName: string;
  8.   begin
  9.     ordir := application.Location;
  10. {$IFDEF Windows}
  11.      {$if defined(cpu64)}
  12.     PA_FileName := ordir + 'uos_lib\Windows\64bit\LibPortaudio-64.dll';
  13.     SF_FileName := ordir + 'uos_lib\Windows\64bit\LibSndFile-64.dll';
  14.     MPG_FileName := ordir + 'uos_lib\Windows\64bit\LibMpg123-64.dll';
  15. {$else}
  16.     PA_FileName := ordir + 'uos_lib\Windows\32bit\LibPortaudio-32.dll';
  17.     SF_FileName := ordir + 'uos_lib\Windows\32bit\LibSndFile-32.dll';
  18.     MPG_FileName := ordir + 'uos_lib\Windows\32bit\LibMpg123-32.dll';
  19.    {$endif}
  20.  {$ENDIF}
  21.  
  22.  {$IFDEF linux}
  23.     {$if defined(cpu64)}
  24.     PA_FileName := ordir + 'uos_lib/Linux/64bit/LibPortaudio-64.so';
  25.     SF_FileName := ordir + 'uos_lib/Linux/64bit/LibSndFile-64.so';
  26.     MPG_FileName := ordir + 'uos_lib/Linux/64bit/LibMpg123-64.so';
  27.     {$else}
  28.     PA_FileName := ordir + 'uos_lib/Linux/32bit/LibPortaudio-32.so';
  29.     SF_FileName := ordir + 'uos_lib/Linux/32bit/LibSndFile-32.so';
  30.     MPG_FileName := ordir + 'uos_lib/Linux/32bit/LibMpg123-32.so';
  31. {$endif}
  32.  {$ENDIF}
  33.  
  34.  {$IFDEF freebsd}
  35.     {$if defined(cpu64)}
  36.     PA_FileName := ordir + 'uos_lib/freeBSD/64bit/libportaudio-64.so';
  37.     SF_FileName := ordir + 'uos_lib/freeBSD/64bit/libsndfile-64.so';
  38.     MPG_FileName := ordir + 'uos_lib/freeBSD/64bit/libmpg123-64.so';
  39.     {$else}
  40.     PA_FileName := ordir + 'uos_lib/freeBSD/32bit/libportaudio-32.so';
  41.     SF_FileName := ordir + 'uos_lib/freeBSD/32bit/libsndfile-32.so';
  42.     MPG_FileName := ordir + 'uos_lib/freeBSD/32bit/libmpg123-32.so';
  43. {$endif}
  44.  {$ENDIF}
  45.  
  46.  
  47.             {$IFDEF Darwin}
  48.     opath := ordir;
  49.     opath := copy(opath, 1, Pos('/UOS', opath) - 1);
  50.     PA_FileName := opath + '/uos_lib/Mac/32bit/LibPortaudio-32.dylib';
  51.     SF_FileName := opath + '/uos_lib/Mac/32bit/LibSndFile-32.dylib';
  52.     MPG_FileName := opath + '/uos_lib/Mac/32bit/LibMpg123-32.dylib';
  53.              {$ENDIF}
  54.  
  55.     // Load the libraries
  56.     // function uos_LoadLib(PortAudioFileName: Pchar; SndFileFileName: Pchar; Mpg123FileName: Pchar; SoundTouchFileName: Pchar) : integer;
  57.  
  58.    res := uos_LoadLib(Pchar(PA_FileName), Pchar(SF_FileName), Pchar(MPG_FileName), nil) ;
  59.  
  60.   //  writeln('Result of loading (if 0 => ok ) : ' + IntToStr(res));
  61.  
  62.    if res = 0 then uos_lib_OK := True else
  63.      begin
  64.      uos_lib_OK := False;
  65.      ShowMessage('uos LoadLib Error');
  66.      end;
  67.      end;

and for example to play a sound file :   
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var  PlayerIndex1: cardinal;
  3.      In1Index : integer;
  4. begin
  5.  if uos_lib_OK then
  6.   begin
  7.   PlayerIndex1 := 0;
  8.   uos_CreatePlayer(PlayerIndex1); //// Create the player
  9.  
  10.   In1Index := uos_AddFromFile(PlayerIndex1,(pchar(pathEdit.FileName)));
  11.  
  12.     uos_AddIntoDevOut(PlayerIndex1, -1, -1, uos_InputGetSampleRate(PlayerIndex1, In1Index), -1, -1, -1);
  13.     // play File
  14.     uos_Play(PlayerIndex1);
  15.    end;
  16. end;

Works under Ubuntu 14.04  64 bits Lazarus 1.4.0 

Friendly, J.P
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

openscoreboard

  • New Member
  • *
  • Posts: 30
  • openscoreboard
Re: Lazarus simple sound
« Reply #4 on: December 27, 2015, 06:41:31 pm »
Thanks Jurassic Pork.

1 Donwload
2,3 Copy files
4 add path uos_lib (-Fu)
5 Always error compiling

Error Indentifier not found "uos_loadlib", "uos_Createplayer", etc

add unit uos_flat, uos but  no work...  %)

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
  9.  
  10. (* uos, uos_flat  NOT WORK error not find unit*)
  11.  
  12. type
  13.  
  14.   { TForm1 }
  15.  
  16.   TForm1 = class(TForm)
  17.     Button1: TButton;
  18.     procedure Button1Click(Sender: TObject);
  19.   private
  20.     { private declarations }
  21.   public
  22.     { public declarations }
  23.   end;
  24.  
  25. var
  26.   Form1: TForm1;
  27.   var uos_lib_OK : Boolean;
  28.  
  29. implementation
  30.  
  31. {$R *.lfm}
  32.  
  33. { TForm1 }
  34.  
  35.  
  36.  
  37. (* CLICK BUTTON LOAD LIBRARY AND SOUND *)
  38.  
  39.  
  40. procedure TForm1.Button1Click(Sender: TObject);
  41.  
  42. var  PlayerIndex1: cardinal;
  43.      In1Index : integer;
  44.  
  45.      res: integer;
  46.      ordir, opath, PA_FileName, SF_FileName, MPG_FileName: string;
  47.  
  48. begin
  49.  
  50.  
  51.  
  52.  
  53.      (********************************************************************)
  54.      (********************* START LOAD LIBRARY LINUX *********************)
  55.      (********************************************************************)
  56.  
  57.     ordir := application.Location;
  58.  
  59.  {$IFDEF linux}
  60.     {$if defined(cpu64)}
  61.     PA_FileName := ordir + 'uos_lib/Linux/64bit/LibPortaudio-64.so';
  62.     SF_FileName := ordir + 'uos_lib/Linux/64bit/LibSndFile-64.so';
  63.     MPG_FileName := ordir + 'uos_lib/Linux/64bit/LibMpg123-64.so';
  64.     {$else}
  65.     PA_FileName := ordir + 'uos_lib/Linux/32bit/LibPortaudio-32.so';
  66.     SF_FileName := ordir + 'uos_lib/Linux/32bit/LibSndFile-32.so';
  67.     MPG_FileName := ordir + 'uos_lib/Linux/32bit/LibMpg123-32.so';
  68. {$endif}
  69.  
  70. {$ENDIF}
  71.  
  72.     // Load the libraries
  73.     // function uos_LoadLib(PortAudioFileName: Pchar; SndFileFileName: Pchar; Mpg123FileName: Pchar; SoundTouchFileName: Pchar) : integer;
  74.  
  75.    res := uos_LoadLib(Pchar(PA_FileName), Pchar(SF_FileName), Pchar(MPG_FileName), nil) ;
  76.  
  77.   //  writeln('Result of loading (if 0 => ok ) : ' + IntToStr(res));
  78.  
  79.    if res = 0 then uos_lib_OK := True else
  80.      begin
  81.      uos_lib_OK := False;
  82.      ShowMessage('uos LoadLib Error');
  83.      end;
  84.    (********************************************************************)
  85.    (************************* END LOAD LIBRARY LINUX********************)
  86.    (********************************************************************)
  87.  
  88.  
  89.  
  90.  
  91.      (********************************************************************)
  92.      (************************ START SOUND  ******************************)
  93.      (********************************************************************)
  94.    if uos_lib_OK then
  95.   begin
  96.   PlayerIndex1 := 0;
  97.   uos_CreatePlayer(PlayerIndex1); //// Create the player
  98.  
  99.   In1Index := uos_AddFromFile(PlayerIndex1,(pchar('test.wav')));
  100.  
  101.     uos_AddIntoDevOut(PlayerIndex1, -1, -1, uos_InputGetSampleRate(PlayerIndex1, In1Index), -1, -1, -1);
  102.     // play File
  103.     uos_Play(PlayerIndex1);
  104.    end;
  105. end;
  106.  
  107. end.
  108.  

Fred vS

  • Hero Member
  • *****
  • Posts: 3826
    • StrumPract is the musicians best friend
Re: Lazarus simple sound
« Reply #5 on: December 27, 2015, 06:58:56 pm »
@ Jurassic Pork => I really appreciate your good vibration.

@  openscoreboard => Like Jurassic Pork explained, Copy all the files in /uos/src/ into the directory of your project and add uos_flat in uses section of code..

If you only want to play wav files, you only need portaudio and sndfile libraries.

The libraries are in /uos/examples/lib/, for Windows, Linux, Mac and FreeBSD.

To load only portaudio and sndfile =>
Code: Pascal  [Select][+][-]
  1. uos_loadlib(directory_of_PortAudio, directory_of_SndFile, nil, nil);

Fre;D
« Last Edit: December 27, 2015, 07:46:37 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

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1290
Re: Lazarus simple sound
« Reply #6 on: December 27, 2015, 11:59:36 pm »
hello,
openscoreboard, try to compile the project in attachments, and say me if it works.
« Last Edit: December 28, 2015, 12:06:38 am by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

RWC

  • Jr. Member
  • **
  • Posts: 92
Re: Lazarus simple sound
« Reply #7 on: December 28, 2015, 12:11:24 am »
@ Jurassic Pork & @Fred vS
This is brilliant information, thanks to you both & I wouldn't mind knowing what Blaazen knows about audio. I guess I'll be able to loadfromfile & play a PCM Windows WAV file but would I be able to store the audio in a block of memory or write the 2 16bit stereo channels as 32bit pixels since TBGRABitmap allow the access of it's memory array via Asm and I want to use the data to generate my land terrain and play the sound track while flying through it. Thanks again, RWC
LAZARUS  : Lazarus-1.4.2-fpc-2.6.4-win32. OS   : Windows Vista 32bit Home Premium SP2.
CPU  : Intel Core2 Quad CPU Q6600 2.4GHz. RAM : 3GB. PCIE : NVIDIA GeForce GT610. Audo : NVIDIA HD Audio.

openscoreboard

  • New Member
  • *
  • Posts: 30
  • openscoreboard
Re: Lazarus simple sound
« Reply #8 on: December 28, 2015, 11:22:17 am »
Thanks @ Jurassic Pork & @Fred vS
I can compiled without errors!!!

....but not sound nothing  to run uos_play  :o



Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1290
Re: Lazarus simple sound
« Reply #9 on: December 28, 2015, 12:00:45 pm »
hello,
what kind of sound do you try to play ?
what is your code for the uos_AddFromFile function ?
have you put the whole path of the file ?
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

openscoreboard

  • New Member
  • *
  • Posts: 30
  • openscoreboard
Re: Lazarus simple sound
« Reply #10 on: December 28, 2015, 01:45:24 pm »
 :D
I got it!

Thanks you for your patience!

my error was path "home\Desktop....." diferent to "home\Escritorio...."  :-[

Thanks again!!!

x2nie

  • Hero Member
  • *****
  • Posts: 515
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
Re: Lazarus simple sound
« Reply #11 on: December 28, 2015, 04:50:51 pm »
Welcome back @Fred  ;) 8-)
When you were logged in, you can see attachments.
Lazarus Github @ UbuntuCinnamon-v22.04.1 + LinuxMintDebianEdition5

 

TinyPortal © 2005-2018