Recent

Author Topic: Create a sine wave audio tone - Linux  (Read 3623 times)

Aruna

  • Sr. Member
  • ****
  • Posts: 456
Create a sine wave audio tone - Linux
« on: August 12, 2024, 02:46:12 pm »
Hi, I have put together a small demo that draws a sine wave and allows you to control the Frequency and Amplitude. Please see the screenshot attached. The source is in the attached zip file. If I now wish to listen to the actual wave being drawn how would I go about doing this, please? I am on Linux Debian and using aplay.

Another thing, if I want this to work seamlessly on all platforms ( Linux, Windows, MacOS, and others) what is the best approach?
Debian GNU/Linux 11 (bullseye)
https://pascal.chat/

Fred vS

  • Hero Member
  • *****
  • Posts: 3326
    • StrumPract is the musicians best friend
Re: Create a sine wave audio tone - Linux
« Reply #1 on: August 12, 2024, 03:41:08 pm »
Hello.
You may use uos: https://github.com/fredvs/uos
Take a look at /uos/examples/consolesynth.lpi
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

Jonax

  • New Member
  • *
  • Posts: 17
Re: Create a sine wave audio tone - Linux
« Reply #2 on: August 12, 2024, 03:49:32 pm »
Nice design and nice to see a fellow Debian user. I tried your code and got no complaints or errors
As for the sound I have no idea. I never use sound in my programming.  O:-)

Aruna

  • Sr. Member
  • ****
  • Posts: 456
Re: Create a sine wave audio tone - Linux
« Reply #3 on: August 12, 2024, 11:51:54 pm »
Hello.
You may use uos: https://github.com/fredvs/uos
Take a look at /uos/examples/consolesynth.lpi
Hello and thank you. I went through briefly and your uos looks pretty comprehensive. I have to test it as soon as I get some time. I will checkout /uos/examples/consolesynth.lpi thank you once again.
Debian GNU/Linux 11 (bullseye)
https://pascal.chat/

Aruna

  • Sr. Member
  • ****
  • Posts: 456
Re: Create a sine wave audio tone - Linux
« Reply #4 on: August 12, 2024, 11:56:47 pm »
Nice design and nice to see a fellow Debian user. I tried your code and got no complaints or errors
As for the sound I have no idea. I never use sound in my programming.  O:-)
Hi @Jonax thank you for the kind words and for testing my code. Sound used cautiously and in moderation can take your app to another level. I will attach a demo soon you can test drive.
Debian GNU/Linux 11 (bullseye)
https://pascal.chat/

Fred vS

  • Hero Member
  • *****
  • Posts: 3326
    • StrumPract is the musicians best friend
Re: Create a sine wave audio tone - Linux
« Reply #5 on: August 13, 2024, 02:41:45 am »
Hello.
You may use uos: https://github.com/fredvs/uos
Take a look at /uos/examples/consolesynth.lpi
Hello and thank you. I went through briefly and your uos looks pretty comprehensive. I have to test it as soon as I get some time. I will checkout /uos/examples/consolesynth.lpi thank you once again.

Hello.
In attachment your project using uos.
Just copy the directory /uos/examples/lib into the root directory of your sinewave project.
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

Aruna

  • Sr. Member
  • ****
  • Posts: 456
Re: Create a sine wave audio tone - Linux
« Reply #6 on: August 13, 2024, 02:54:21 am »
Hello.
In attachment your project using uos.
Just copy the directory /uos/examples/lib into the root directory of your sinewave project.
So the *.so files as shown in the attached screenshot yes?
Debian GNU/Linux 11 (bullseye)
https://pascal.chat/

Fred vS

  • Hero Member
  • *****
  • Posts: 3326
    • StrumPract is the musicians best friend
Re: Create a sine wave audio tone - Linux
« Reply #7 on: August 13, 2024, 03:09:51 am »
Hello.
In attachment your project using uos.
Just copy the directory /uos/examples/lib into the root directory of your sinewave project.
So the *.so files as shown in the attached screenshot yes?

It depends of what OS you are using.
For Linux amd64: uos/examples/lib/Linux/64bit/
In the code I give, all the OS are checked.

Note that for your project you only need PortAudio library.
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: 3326
    • StrumPract is the musicians best friend
Re: Create a sine wave audio tone - Linux
« Reply #8 on: August 13, 2024, 03:21:03 am »
Yes, copy all the /uos/examples//lib folder into your sinewave_with_sound folder.

When you will have analysed the updated code, you could adapt it and only add the Portaudio library of the OS you want.
« Last Edit: August 13, 2024, 03:23:18 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

Aruna

  • Sr. Member
  • ****
  • Posts: 456
Re: Create a sine wave audio tone - Linux
« Reply #9 on: August 13, 2024, 03:31:32 am »
Yes, copy all the /uos/examples//lib folder into your sinewave_with_sound folder.

When you will have analysed the updated code, you could adapt it and only add the Portaudio library of the OS you want.
Hi @Fred vS I have done as you instructed. The project compiles and runs ok but there is no sound. I think I may be doing something wrong  :-\ Please have a look at the attached screenshots.
Debian GNU/Linux 11 (bullseye)
https://pascal.chat/

Aruna

  • Sr. Member
  • ****
  • Posts: 456
Re: Create a sine wave audio tone - Linux
« Reply #10 on: August 13, 2024, 03:36:26 am »
It depends of what OS you are using.
For Linux amd64: uos/examples/lib/Linux/64bit/
Please see attached screenshot
Debian GNU/Linux 11 (bullseye)
https://pascal.chat/

Fred vS

  • Hero Member
  • *****
  • Posts: 3326
    • StrumPract is the musicians best friend
Re: Create a sine wave audio tone - Linux
« Reply #11 on: August 13, 2024, 03:43:28 am »
OK, you are using linux amd64.

Copy the library /uos/examples/lib/Linux/64bit/LibPortaudio-64.so into the folder /sinewave_with_sound/

And change the code:
Code: Pascal  [Select][+][-]
  1. {$if defined(CPUAMD64) and  defined(linux) }
  2.    PA_FileName := ordir + 'lib/Linux/64bit/LibPortaudio-64.so';
  3.  {$ENDIF}    

with this:

Code: Pascal  [Select][+][-]
  1. {$if defined(CPUAMD64) and  defined(linux) }
  2.    PA_FileName := ordir + 'LibPortaudio-64.so';
  3.  {$ENDIF}
   

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

Aruna

  • Sr. Member
  • ****
  • Posts: 456
Re: Create a sine wave audio tone - Linux
« Reply #12 on: August 13, 2024, 03:50:55 am »
OK, you are using linux amd64.
I have a genuine Intel processor can that be a problem? Is not a amd64

Copy the library /uos/examples/lib/Linux/64bit/LibPortaudio-64.so into the folder /sinewave_with_sound/

And change the code:
Code: Pascal  [Select][+][-]
  1. {$if defined(CPUAMD64) and  defined(linux) }
  2.    PA_FileName := ordir + 'lib/Linux/64bit/LibPortaudio-64.so';
  3.  {$ENDIF}    
with this:

Code: Pascal  [Select][+][-]
  1. {$if defined(CPUAMD64) and  defined(linux) }
  2.    PA_FileName := ordir + 'LibPortaudio-64.so';
  3.  {$ENDIF}
   
Compiles and runs, still no sound :-( Please see the attached screenshot
Debian GNU/Linux 11 (bullseye)
https://pascal.chat/

Fred vS

  • Hero Member
  • *****
  • Posts: 3326
    • StrumPract is the musicians best friend
Re: Create a sine wave audio tone - Linux
« Reply #13 on: August 13, 2024, 03:56:04 am »
No amd64 is the architecture 64 bit, not the mark of the processor.

Strange that you dont get sound, tested here on Linux amd64 intel and it works.
Did you try the uos example consolesynth.lpi ?
With Lazarus, open project and choose it + test.
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

tetrastes

  • Hero Member
  • *****
  • Posts: 529
Re: Create a sine wave audio tone - Linux
« Reply #14 on: August 13, 2024, 01:53:57 pm »
Compiles and runs, still no sound :-( Please see the attached screenshot

If frequency is 5 Hz indeed, you cannot hear it.  ;D

 

TinyPortal © 2005-2018