Recent

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

Aruna

  • Sr. Member
  • ****
  • Posts: 353
Re: Create a sine wave audio tone - Linux
« Reply #30 on: August 15, 2024, 06:51:17 pm »
Re-hello.
Note that playing https url will work only with fpc 3.3.1.
I did try using fpc 322 but it did not work.  :-X
It works fine with my fpc 3.2.0 please see the attached screenshot.
Debian GNU/Linux 11 (bullseye)
https://pascal.chat/

Fred vS

  • Hero Member
  • *****
  • Posts: 3299
    • StrumPract is the musicians best friend
Re: Create a sine wave audio tone - Linux
« Reply #31 on: August 15, 2024, 06:58:01 pm »
Ha ?
Could you try with fpc 3.2.2 ?
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: 3299
    • StrumPract is the musicians best friend
Re: Create a sine wave audio tone - Linux
« Reply #32 on: August 15, 2024, 07:33:11 pm »
Hello.

I did reinstall fpc via fpcupdeluxe.
With fpc 3.2.2 https url cannot be accessed.

But the good news is that with fpc 3.2.3. (fixes of fpc 3.2.2) it works.  ;D

[EDIT] Did try with fpc 3.2.0 but here https url cannot be accessed.
Only fpc 3.2.3 and fpc 3.3.1 can do it.
« Last Edit: August 15, 2024, 07:58:52 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

TRon

  • Hero Member
  • *****
  • Posts: 3129
Re: Create a sine wave audio tone - Linux
« Reply #33 on: August 21, 2024, 03:13:54 am »
Only fpc 3.2.3 and fpc 3.3.1 can do it.
Free pascal < 3.2.3 is perfectly capable of accessing https URL's

But besides that, you can also make use of a library that does it for you in case the compiler doesn't (curl/wget/ffpmpeg/etc).

@Aruna:
I have attached a 123-liner (including references, instructions and a lot of white-space) mp3 stream url player depending on libao, libmpg123 and libcurl. To my knowledge these are all cross-platform libraries (win, mac, lin). But due to the simplicity it only supports mp3 streams (which was, if not mistaken, your initial goal).

If you want to know how to play a sine then you can use the libao example from their webpage/package (see references).

Thank you DJ for your headers.
« Last Edit: August 21, 2024, 03:15:52 am by TRon »
All software is open source (as long as you can read assembler)

Fred vS

  • Hero Member
  • *****
  • Posts: 3299
    • StrumPract is the musicians best friend
Re: Create a sine wave audio tone - Linux
« Reply #34 on: August 21, 2024, 03:53:32 am »
Only fpc 3.2.3 and fpc 3.3.1 can do it.
Free pascal < 3.2.3 is perfectly capable of accessing https URL's

Hum, if I may, only on old Linux distros.
For example last XUbuntu, with fpc 3.2.2 I am not able to connect https radio-webstreaming.
But with fpc 3.3.1 and fixes fpc 3.2.3 it works.
I did try on older Debian 10 and there with fpc 3.2.2. I can connect  https radio-webstreaming.
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

TRon

  • Hero Member
  • *****
  • Posts: 3129
Re: Create a sine wave audio tone - Linux
« Reply #35 on: August 21, 2024, 04:12:31 am »
Hum, if I may,
Yes, you may my friend  :)

Quote
only on old Linux distros.
Let's try avoid any misconception in that one small statement.

What exactly do you mean by that ? Only on old linux distro's it doesn't work or on old linux distro's it does work ?

I run a semi-rolling debian bookworm (Linux 6.1.0-23-amd64 x86_64) and as an example https works with FPC 3.2.0 and 3.2.2 (the older 3.0.4 does not have opensslsockets unit so i would have to check with some other code)

Quote
For example last XUbuntu, with fpc 3.2.2 I am not able to connect https radio-webstreaming.
But with fpc 3.3.1 and fixes fpc 3.2.3 it works.
I did try on older Debian 10 and there with fpc 3.2.2. I can connect  https radio-webstreaming.
That is very strange. XUbuntu is afaik also based on Debian.

What ssl libraries does your XUbuntu have installed ?
Code: [Select]
$ openssl version -a
and:
$ openssl ciphers -v | awk '{print $2}' | sort | uniq
All software is open source (as long as you can read assembler)

Fred vS

  • Hero Member
  • *****
  • Posts: 3299
    • StrumPract is the musicians best friend
Re: Create a sine wave audio tone - Linux
« Reply #36 on: August 21, 2024, 04:25:11 am »
What exactly do you mean by that ? Only on old linux distro's it doesn't work or on old linux distro's it does work ?
This one: on old linux distro's it does work

What ssl libraries does your XUbuntu have installed ?
Code: [Select]
$ openssl version -a
and:
$ openssl ciphers -v | awk '{print $2}' | sort | uniq

Code: Pascal  [Select][+][-]
  1. $ openssl version -a
Quote
fred@fred-IdeaPad:~$ openssl version -a
OpenSSL 3.0.2 15 Mar 2022 (Library: OpenSSL 3.0.2 15 Mar 2022)
built on: Fri Feb 16 08:51:30 2024 UTC
platform: debian-amd64
options:  bn(64,64)
compiler: gcc -fPIC -pthread -m64 -Wa,--noexecstack -Wall -Wa,--noexecstack -g -O2 -ffile-prefix-map=/build/openssl-olCZw9/openssl-3.0.2=. -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -DOPENSSL_TLS_SECURITY_LEVEL=2 -DOPENSSL_USE_NODELETE -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_BUILDING_OPENSSL -DNDEBUG -Wdate-time -D_FORTIFY_SOURCE=2
OPENSSLDIR: "/usr/lib/ssl"
ENGINESDIR: "/usr/lib/x86_64-linux-gnu/engines-3"
MODULESDIR: "/usr/lib/x86_64-linux-gnu/ossl-modules"
Seeding source: os-specific
CPUINFO: OPENSSL_ia32cap=0x7ffaf3ffffebffff:0x984007bc239c27eb

Code: Pascal  [Select][+][-]
  1. $ openssl ciphers -v | awk '{print $2}' | sort | uniq
Quote
fred@fred-IdeaPad:~$  openssl ciphers -v | awk '{print $2}' | sort | uniq
SSLv3
TLSv1
TLSv1.2
TLSv1.3


But besides that, you can also make use of a library that does it for you in case the compiler doesn't (curl/wget/ffpmpeg/etc).
Yes, thanks but the compiler that I use does it perfectly, it is fpc helped only by light dynamically loaded Portaudio and mpg123 libraries.  ;)
https://github.com/fredvs/swp/releases/
« Last Edit: August 21, 2024, 04:43:16 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

TRon

  • Hero Member
  • *****
  • Posts: 3129
Re: Create a sine wave audio tone - Linux
« Reply #37 on: August 21, 2024, 04:44:46 am »
Thank you for posting the results of those two commands Fred vS.

That makes it even stranger as everything seems to be in place.

I take it you have the libssl-dev package installed on that particular machine as well so that the compiler is able to pick up on the latest version of openssl ?

Quote
Yes, thanks but the compiler that I use does it perfectly, it is fpc helped only by light dynamically loaded Portaudio and mpg123 libraries.  ;)
https://github.com/fredvs/swp/releases/
Ah, that is a nice little project indeed. Thank you for keeping the spirit of MSE alive.
« Last Edit: August 21, 2024, 04:50:19 am by TRon »
All software is open source (as long as you can read assembler)

Fred vS

  • Hero Member
  • *****
  • Posts: 3299
    • StrumPract is the musicians best friend
Re: Create a sine wave audio tone - Linux
« Reply #38 on: August 21, 2024, 05:04:44 am »
I take it you have the openssl-dev package installed on that particular machine as well so that the compiler is able to pick up on the latest version of openssl ?
I must admit that I have very little knowledge of anything related to SSL.
It is the package installed by the distro and upgraded with apt upgrade.
On my old Debian 10 the web-radio-player project can play https if compiled with fpc 3.2.2.
But not on XUbuntu 24.0.
If compiled with fpc > 3.2.2 it can play https on XUbuntu 24.0.

https://github.com/fredvs/swp/releases/
Ah, that is a nice little project indeed. Thank you for keeping the spirit of MSE alive.
Thanks TRon!
MSE is a wonderful project that will never die. ;)

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

TRon

  • Hero Member
  • *****
  • Posts: 3129
Re: Create a sine wave audio tone - Linux
« Reply #39 on: August 21, 2024, 05:13:45 am »
Sorry fred, I amended my previous post before you had a chance to actually see it.

Try apt search libssl-dev to check if the dev package was setup correctly. The package should create links so that anything that tries to open an older version of libopenssl get redirected to the newer one. That is the only thing I can think of that might perhaps be missing on your setup

(my openssl is actually OpenSSL 3.0.13 30 Jan 2024 (Library: OpenSSL 3.0.13 30 Jan 2024)

Quote
MSE is a wonderful project that will never die. ;)
And with that the original creator and author so +1.
All software is open source (as long as you can read assembler)

Fred vS

  • Hero Member
  • *****
  • Posts: 3299
    • StrumPract is the musicians best friend
Re: Create a sine wave audio tone - Linux
« Reply #40 on: August 21, 2024, 05:49:25 am »
Try apt search libssl-dev
Code: [Select]
fred@fred-IdeaPad:~$ apt search libssl-dev
Sorting... Done
Full Text Search... Done
libssl-dev/jammy-updates,jammy-security 3.0.2-0ubuntu1.17 amd64
  Secure Sockets Layer toolkit - development files

perl-openssl-defaults/jammy,now 5build2 amd64 [installed,automatic]
  version compatibility baseline for Perl OpenSSL packages
But dont worry, I am happy with fpc > 3.2.2. (And even more when fpc 3.2.4 is released  :-X )

MSE is a wonderful project that will never die. ;)
Quote
And with that the original creator and author so +1.
Yes, Martin's soul continues to guide us forever.
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

TRon

  • Hero Member
  • *****
  • Posts: 3129
Re: Create a sine wave audio tone - Linux
« Reply #41 on: August 21, 2024, 06:03:27 am »
But dont worry, I am happy with fpc > 3.2.2. (And even more when fpc 3.2.4 is released  :-X )
That is ofc your choice and is all good  :)

But at least you know why it acts different with multiple compiler versions amongst different setups. The older compilers most probably tries to load a too old openssl, one that usually uses old unsupported encryption libraries and thus the connection fails.

a simple sudo apt install libssl-dev should be able to solve that or as you figured out a more updated compiler that adds support for loading newer versions of libopenssl.
All software is open source (as long as you can read assembler)

Aruna

  • Sr. Member
  • ****
  • Posts: 353
Re: Create a sine wave audio tone - Linux
« Reply #42 on: August 21, 2024, 05:20:23 pm »
@Aruna:
I have attached a 123-liner
LOL ( I needed to laugh so thank you  :) )

(including references, instructions and a lot of white-space) mp3 stream url player depending on libao, libmpg123 and libcurl.
  In your instructions it says
Code: Pascal  [Select][+][-]
  1. // Original headers were slightly modified in order to compile this project.
what did you have to slightly modify and why?

It also says
Code: Pascal  [Select][+][-]
  1. //(*) be very careful with installing libcurl-dev because depending on your [snip]
Whenever I encounter 'be very careful' it gives me the shudders. So to test your 123-liner, I have to come up with a secure sandbox or turn to Virtualbox. I tried to compile and the screenshot tells me I was right about missing dependency hell :-) and your 'be very careful' has me thinking maybe I should definitely do this in Virtualbox?

To my knowledge these are all cross-platform libraries (win, mac, lin). But due to the simplicity it only supports mp3 streams (which was, if not mistaken, your initial goal).
They may all be cross-platform but my common sense (whatever remains of it ) tells me this is gonna be dependency hell, so don't do it. But my curiosity tell's me go ahead learn something new :-) My initial goal was to get some internet radio streams to play and some of them have *.m3u8 files some have urls that end in port number and path (:2020/stream/hirufmgarden) which I really have no idea what format they use?

If you want to know how to play a sine then you can use the libao example from their webpage/package (see references).
Thank you I will go through the libao examples and see if my currently fried brain is able to comprehend what they have done.

Thank you DJ for your headers.
Who is DJ? Oh almost forgot
Code: Pascal  [Select][+][-]
  1. MPG123_NEED_MORE:
  2.       begin
  3.         // intentionally left blank;
  4.       end;
Why left intentionally blank?  ::)


Debian GNU/Linux 11 (bullseye)
https://pascal.chat/

Aruna

  • Sr. Member
  • ****
  • Posts: 353
Re: Create a sine wave audio tone - Linux
« Reply #43 on: August 21, 2024, 05:23:46 pm »
@TRon Very impressive stuff btw ( am just saying ) wish I could do something like playurl ( someday.. )
Debian GNU/Linux 11 (bullseye)
https://pascal.chat/

TRon

  • Hero Member
  • *****
  • Posts: 3129
Re: Create a sine wave audio tone - Linux
« Reply #44 on: August 22, 2024, 02:40:31 am »
what did you have to slightly modify and why?
mpg123:
- added support for linking against linux libmp3 library

libao:
- removed dependency on unit AcSysUtils to use fpc's dynlibs unit instead
- modified library functions loading to make use of dynlib functions
- updated to match latest libao headers
- reorganized some of the layout of the unit
- commented the intialization and finalization routines

If you literally wish to see what was changed then you could try and use a diff viewer.

I personally use Double Commander's compare files by contents (scroll down to see an example) but any diff viewer that you are comfortable with will do.

Quote
It also says
If you want to play it safe then by all means please do what you are most comfortable with.

I made the comment because whenever you install a dev package it will also install the actual library. That means that it could cause you to inadvertently install the wrong library (for your distro).

The warning is perhaps a bit overkill because in the worse case scenario it is possible to break your (lib)curl installation. In that case a simple re-install will probably solve that but then you would have to know what and  how exactly it was installed (hence the warning).

I do not know if other programs in your distro depend on a specific installation of (lib)curl and might break in the process when messing things up.

Just make sure to know what version of the libcurl library is installed by default (and what crypto libs are used) and install the corresponding dev-package and you should be good to go. If no (lib)curl is installed by default  then just install any libcurl of your choice.

Quote
They may all be cross-platform but my common sense (whatever remains of it ) tells me this is gonna be dependency hell, so don't do it.
For windows you do not have to worry at all as you can download and place the libraries next to your executable for testing purposes. You can then later decide to install them system-wide on a windows system.

I do not know how that works on/for macos but on linux the dependencies should be automatically resolved by your package manager. The only warning is for libcurl because of how some distro's support multiple versions of the library.

Like you suggested yourself: if it all looks a bit too hazardous then use a VM for testing. I do that myself as well for things that I am not familiar with and/or could have a big impact on the current installation.

Quote
Thank you I will go through the libao examples and see if my currently fried brain is able to comprehend what they have done.
Just to make sure, I am/was referring to this example for c.

Quote
My initial goal was to get some internet radio streams to play and some of them have *.m3u8 files some have urls that end in port number and path (:2020/stream/hirufmgarden) which I really have no idea what format they use?
m3u8 and pls files originates from being playlists normally used by mp3 players.

When the internets became popular someone figured out that you can also use such a playlist to store several links to (online) streams. Some lists contain different radio stations while others contain a list of the same station but using different (MP3) bitrates or different kind of stream types (MP3, ogg, asf, wav, flac etc).

Some URL's clearly identifies what kind of stream is behind the URL while others give no clue whatsoever.

If you want to know more then either share the m3u8/pls or use something like VLC to play the stream and use VLC's codec information menu to figure out what kind of stream is actually behind such URL (many other tools can show this information as well, VLC is merely an example).

Quote
Who is DJ?
:)

A fellow member of this forum who gracefully shared his mpg123 header with us (full alias name, DJMaster).

Quote
Why left intentionally blank?
Because there is no good solution to implement here. Best would probably be to display an error message.

The reason for that is how the whole thing is setup.
- libcurl downloads the packets to a buffer which then get passed to the callback
- the callback decodes the mp3 frames that are inside the buffer
- then the decoded frames are send to the audio buffer

In case the MPG123_NEED_MORE status is returned then we need to feed more MP3 data that can be decoded but we are already in the libcurl callback routine which means there is no more data until libcurl calls the callback routine again.

There are (many) more returning message (see here) such as for example MPG123_DONE but why bother handling that for a live-stream (though technically it is possible that a live-stream stops streaming for whatever reason)

The reason to explicitly mention MPG123_NEED_MORE is so that it is possible to determine f.e. a buffer underrun situation (which indirectly implies to increase the libcurl buffer size).

@TRon Very impressive stuff btw ( am just saying ) wish I could do something like playurl ( someday.. )
That is really giving me too much credit :-)

I probably came across this solution on my quest for seeking audio examples. I just found it in one of my catalogs (meaning it was probably copied from somewhere else or in case written in another language converted by me).

I like the example because it is small, clean and to the point.

But it is also not that hard to figure out on yourself. There are plenty of instructions and examples for libmpg123, and the FPC libcurl package has a nice streaming example. I have used mpg123 and libao for ages though I am not that familiar with using libcurl.

In that regards I myself am intrigued by Fred vS' example as that uses fphttpclient, which removes the requirement to use libcurl (just as using a native mp3 decoder would remove the need to depend on libmpg123).

The story of all times: Too much to do, and so little time  :D

Thank you for your interest.
All software is open source (as long as you can read assembler)

 

TinyPortal © 2005-2018