Recent

Author Topic: Generate square / sinusoidal waves  (Read 4707 times)

Fred vS

  • Hero Member
  • *****
  • Posts: 3168
    • StrumPract is the musicians best friend
Re: Generate square / sinusoidal waves
« Reply #30 on: January 17, 2021, 08:01:40 pm »
Ok, very last try.

First copy the directory /uos/examples/lib and paste into the directory of your project.
Paste also the units that are in /uos/src/ into the directory of your project.
For this project you will need only uos.pas, uos_flat.pas and uos_portaudio.pas.

Then in your form unit:

Code: Pascal  [Select][+][-]
  1. unit yourfromunit;
  2.  
  3. {$mode objfpc}{$H+}
  4. interface
  5.  
  6. uses
  7.     ... // add all the other units needed for your project
  8.    uos_flat;
  9.  
  10.   ...
  11.  
  12. type
  13.   { TForm1 }
  14.   TForm1 = class(TForm)  
  15.    // all included Formcreate and Formdestroy
  16.  
  17.   ....
  18.  
  19. var
  20.   Form1: TForm1;
  21.     ... // all your variables
  22.        // this for uos
  23.      res: integer;
  24.      PlayerIndex1, inindex1: integer;
  25.  
  26. implementation
  27.  
  28. ... // all your methods
  29.  
  30. procedure TForm1.FormCreate(Sender: TObject);
  31. var
  32.   PA_FileName: string;
  33. begin
  34. // load the library
  35.   PA_FileName := './lib/Linux/arm_raspberrypi/libportaudio-arm.so';
  36.   res := uos_LoadLib(PChar(PA_FileName), nil, nil, nil, nil, nil);
  37. end;
  38.      
  39. ...
  40.  
  41. procedure TForm1.Button1Click(Sender: TObject);
  42. begin
  43.   if res = 0 then
  44.     begin
  45.       //// Create the player.
  46.       //// PlayerIndex : from 0 to what your computer can do !
  47.       //// If PlayerIndex exists already, it will be overwriten...
  48.       PlayerIndex1 := 0;
  49.       inindex1     := -1;
  50.  
  51.       if uos_CreatePlayer(PlayerIndex1) then
  52.         inindex1 :=
  53.          uos_AddFromSynth(PlayerIndex1, -1, -1, -1, 420, 420, -1, -1, -1, -1, -1, 0, -1, -1, -1);
  54.  
  55.       if uos_AddIntoDevOut(PlayerIndex1,-1,0.3,-1,-1, 0,-1,-1) > - 1 then
  56.        /////// everything is ready, here we are, lets play it...
  57.         uos_Play(PlayerIndex1);
  58.    end;
  59.  end;
  60.  
  61. procedure TForm1.FormDestroy(Sender: TObject);
  62.   begin
  63.    uos_free();
  64.   end;
  65. ...

Please check in uos source the parameters of each method.
« Last Edit: January 17, 2021, 08:28:13 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

Ramses

  • New Member
  • *
  • Posts: 41
Re: Generate square / sinusoidal waves
« Reply #31 on: January 17, 2021, 08:49:08 pm »
Ok, i have do everything you told me, the program compile and run, but when i press the buton i got
Quote
Error: Project raised exception class 'External:SIGSEGV'.

My code now is:

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,uos_flat;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     procedure FormCreate(Sender: TObject);
  17.     procedure Button1Click(Sender: TObject);
  18.     procedure FormDestroy(Sender: TObject);
  19.   private
  20.  
  21.   public
  22.  
  23.   end;
  24.  
  25. var
  26.   Form1: TForm1;
  27.      res: integer;
  28.      PlayerIndex1, inindex1: integer;
  29.  
  30. implementation
  31.  
  32. {$R *.lfm}
  33.  
  34. { TForm1 }
  35.  
  36. procedure TForm1.FormCreate(Sender: TObject);
  37. var
  38.   PA_FileName: string;
  39. begin
  40. // load the library
  41.   PA_FileName := './lib/Linux/arm_raspberrypi/libportaudio-arm.so';
  42.   res := uos_LoadLib(PChar(PA_FileName), nil, nil, nil, nil, nil);
  43. end;
  44.  
  45.  
  46.  
  47. procedure TForm1.Button1Click(Sender: TObject);
  48. begin
  49.   if res = 0 then
  50.     begin
  51.       //// Create the player.
  52.       //// PlayerIndex : from 0 to what your computer can do !
  53.       //// If PlayerIndex exists already, it will be overwriten...
  54.       PlayerIndex1 := 0;
  55.       inindex1     := -1;
  56.  
  57.       if uos_CreatePlayer(PlayerIndex1) then
  58.         inindex1 :=
  59.          uos_AddFromSynth(PlayerIndex1, -1, -1, -1, 420, 420, -1, -1, -1, -1, -1, 0, -1, -1, -1);
  60.  
  61.       if uos_AddIntoDevOut(PlayerIndex1,-1,0.3,-1,-1, 0,-1,-1) > - 1 then
  62.        /////// everything is ready, here we are, lets play it...
  63.         uos_Play(PlayerIndex1);
  64.    end;
  65.  end;
  66.  
  67. procedure TForm1.FormDestroy(Sender: TObject);
  68.   begin
  69.    uos_free();
  70.   end;
  71.  
  72. end.  
  73.  

Fred vS

  • Hero Member
  • *****
  • Posts: 3168
    • StrumPract is the musicians best friend
Re: Generate square / sinusoidal waves
« Reply #32 on: January 17, 2021, 09:26:19 pm »
Hello.

Hum, it should work.

What is the code of your main program, did you add cthreads unit like this ?:

Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   cthreads, // THIS ADDED (remove the if ... end if there are added)
  7.   Interfaces,
  8.   Forms, Unit1
  9.   { you can add units after this };
  10.  
  11. {$R *.res}
  12.  
  13. begin
  14.   RequireDerivedFormResource:=True;
  15.   Application.Scaled:=True;
  16.   Application.Initialize;
  17.   Application.CreateForm(TForm1, Form1);
  18.   Application.Run;
  19. end.  
     
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

Ramses

  • New Member
  • *
  • Posts: 41
Re: Generate square / sinusoidal waves
« Reply #33 on: January 17, 2021, 09:46:36 pm »
What is the code of your main program, did you add cthreads unit like this ?:


i removed the "if...end" so now it is exactly like your exemple, but still get the exact same error: "Error: Project raised exception class 'External:SIGSEGV'"

Here is my main program:

Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   cthreads,
  7.   Interfaces, // this includes the LCL widgetset
  8.   Forms, Unit1
  9.   { you can add units after this };
  10.  
  11. {$R *.res}
  12.  
  13. begin
  14.   RequireDerivedFormResource:=True;
  15.   Application.Scaled:=True;
  16.   Application.Initialize;
  17.   Application.CreateForm(TForm1, Form1);
  18.   Application.Run;
  19. end.  
  20.  

I tried to found what section of the code raise the error, and the error appear at this line: "uos_CreatePlayer(PlayerIndex1)"

Fred vS

  • Hero Member
  • *****
  • Posts: 3168
    • StrumPract is the musicians best friend
Re: Generate square / sinusoidal waves
« Reply #34 on: January 17, 2021, 09:57:32 pm »
Hello.

Could you try the project in attachment?
Just unzip it and load project1.lpi + complile + run.

Here it works.


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

Ramses

  • New Member
  • *
  • Posts: 41
Re: Generate square / sinusoidal waves
« Reply #35 on: January 17, 2021, 10:14:19 pm »
Just unzip it and load project1.lpi + complile + run.

Worked perfectly here...

dont know why my project doesnt work, maybe i forgot to copy some files??

anyway thanks a lot for that, now because your project work perfectly, i can start building what i want on this code!

it look like my issue is finally fixed now!

Thanks for that, and how mutch for the trouble?

Fred vS

  • Hero Member
  • *****
  • Posts: 3168
    • StrumPract is the musicians best friend
Re: Generate square / sinusoidal waves
« Reply #36 on: January 17, 2021, 10:18:35 pm »
Hello Ramses.

Nice that you make it work.  ;D

Fre;D
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

 

TinyPortal © 2005-2018