Recent

Author Topic: Analyzing audio from specific source in real-time  (Read 3120 times)

backprop

  • Full Member
  • ***
  • Posts: 129
Analyzing audio from specific source in real-time
« on: March 08, 2025, 09:05:32 pm »
I need to create real-time FFT analyzer of the audio signal from specific source. I.e.from microphone, Line-In, audio-mix (i.e., current speaker output) or similar. Is there a way to do that with Lazarus and what exactly is needed for Linux? Requirement is not to force anyone to download additional drivers etc., but use just ALSA.

hukka

  • New Member
  • *
  • Posts: 45
    • Github
Re: Analyzing audio from specific source in real-time
« Reply #1 on: March 08, 2025, 09:41:29 pm »
My recommendation would be to use the BASS library: https://www.un4seen.com/bass.html
You can request FFT data via the BASS_ChannelGetData call: https://www.un4seen.com/doc/#bass/BASS_ChannelGetData.html

Fred vS

  • Hero Member
  • *****
  • Posts: 3720
    • StrumPract is the musicians best friend
Re: Analyzing audio from specific source in real-time
« Reply #2 on: March 08, 2025, 10:20:30 pm »
Hello.

uos audio library does it, see /uos/examples/consolespectrum.pas.

It uses portaudio library who is installed by default on nearly all Linux distro.
But, because uos load dynamically libraries, you may use the one provided in uos package.

Image from StrumPract and WavvieW both using uos.
« Last Edit: March 08, 2025, 10:44:07 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

backprop

  • Full Member
  • ***
  • Posts: 129
Re: Analyzing audio from specific source in real-time
« Reply #3 on: March 09, 2025, 02:24:38 am »
WavvieW looks exactly what I searching for. However, there is two problems:

1. There is no .lpi file in and I have no idea how to compile it.
2. It seems it uses custom libraries which shouldn't, as that is big security risk. Is there a source code for these libraries to be created?

Fred vS

  • Hero Member
  • *****
  • Posts: 3720
    • StrumPract is the musicians best friend
Re: Analyzing audio from specific source in real-time
« Reply #4 on: March 09, 2025, 02:51:17 am »
WavvieW looks exactly what I searching for. However, there is two problems:

1. There is no .lpi file in and I have no idea how to compile it.
2. It seems it uses custom libraries which shouldn't, as that is big security risk. Is there a source code for these libraries to be created?

Hello.

About 1. There is no .lpi file, the project uses MSEgui widgetset and MSEide (or ideU) as IDE to load the .prj project-file.

About 2. WavvieW uses Portaudio lib ( https://www.portaudio.com/ ) for accessing audio devices (in + out) and libmpg123 ( https://www.mpg123.de/) to read mp3 files and libsndfile ( https://libsndfile.github.io/libsndfile/) for ogg, wav, flac, ... audio files.
For fft: libfftw3 library: https://www.fftw.org/.

The binaries of this libraries provided in WavvieW project are there for convenience but can be installed/compiled from source of each repo.

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

backprop

  • Full Member
  • ***
  • Posts: 129
Re: Analyzing audio from specific source in real-time
« Reply #5 on: March 09, 2025, 12:37:34 pm »
It uses many external libs, no native solution, different way to compile all using different IDE...
And all that just to test it. Well, it s just way to complicated.

Thanks anyway.
 
I'm looking for "native" solution, all in pure pascal and no external libs.
« Last Edit: March 09, 2025, 12:40:59 pm by backprop »

Fred vS

  • Hero Member
  • *****
  • Posts: 3720
    • StrumPract is the musicians best friend
Re: Analyzing audio from specific source in real-time
« Reply #6 on: March 09, 2025, 12:49:07 pm »
It uses many external libs, no native solution, different way to compile all using different IDE...
And all that just to test it. Well, it s just way to complicated.

Thanks anyway.
 
I'm looking for "native" solution, all in pure pascal and no external libs.

Good luck finding a pure "native" pascal solution.
By the way, MSEgui is much more "pure pascal" than LCL.
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

backprop

  • Full Member
  • ***
  • Posts: 129
Re: Analyzing audio from specific source in real-time
« Reply #7 on: March 09, 2025, 01:47:30 pm »
Good luck finding a pure "native" pascal solution.
By the way, MSEgui is much more "pure pascal" than LCL.

BTW, it is always a hassle to have many third party libraries which are not a common part of the OS. You depend on them and if they messed up something, your whole project is useless.

No need for FFT lib, there is "native" pascal version. And for reading audio from specific source there should be a way to do that from ALSA directly, avoiding any third party libs.  And then, above all another IDE...

Well, that is too much headache for such, basically, simple task. I do not want to make game nor speech synthesis and recognition software, but simply to analyze real time audio signal from desired source.

« Last Edit: March 09, 2025, 01:59:25 pm by backprop »

Boleeman

  • Hero Member
  • *****
  • Posts: 1006
Re: Analyzing audio from specific source in real-time
« Reply #8 on: March 09, 2025, 02:03:17 pm »
Found a little TLedMeterDemo control for Lazarus at:

https://github.com/Atomek61/LedMeterConfigurator

Could possibly be used in a sound program.


 This control displays one or more numerical values as colored bars made of discrete led elements.


Define the controls styles, define the colors and their ranges and set the levels to be displayed.

    BarCount defines the number of bars
    Orientation is loVertical or loHorizontal
    Style is lsNormal or lsBiDirectional
    Levels[] contains the bars levels as single precision values
    ColorNodes is a collection containing color/level pairs
    SegmentSize defines the height/width of the segments. 0 means quadratic.
    MinLevel defines the minimum level (Mode=lsNormal only)

Fred vS

  • Hero Member
  • *****
  • Posts: 3720
    • StrumPract is the musicians best friend
Re: Analyzing audio from specific source in real-time
« Reply #9 on: March 09, 2025, 02:10:36 pm »
BTW, it is always a hassle to have many third party libraries which are not a common part of the OS. You depend on them and if they messed up something, your whole project is useless.

This is the price to pay if you are using an open source operating system like Linux.
You can of course use ALSA directly, see here: https://github.com/fredvs/alsa_sound/

But if you want to decode audio files, there is no "native" solution, you will need third-party libraries, like libogg, libflac, libmpg123, etc.

No need for FFT lib, there is "native" pascal version. And for reading audio from specific source there should be a way to do that from ALSA directly, avoiding any third party libs.  And then, above all another IDE...

Of course, if you are a FFT and Pascal guru, you can create your own FFT.
I think there is Pascal code for FFT in FPC package.
In uos, there are FFTs used for example to get the frequency spectrum or create an equalizer without using any external  FFT library.

But, if I may, processing the FFT is not the easiest part of audio management.
« Last Edit: March 09, 2025, 02:30:34 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

backprop

  • Full Member
  • ***
  • Posts: 129
Re: Analyzing audio from specific source in real-time
« Reply #10 on: March 09, 2025, 02:49:24 pm »
But if you want to decode audio files, there is no "native" solution, you will need third-party libraries, like libogg, libflac, libmpg123, etc.

No, that is not what is my goal, just to access and analyze raw real-time sound on Linux. And for that, access to ALSA directly is more than suficient, I do not need multi-platform solution.

Fred vS

  • Hero Member
  • *****
  • Posts: 3720
    • StrumPract is the musicians best friend
Re: Analyzing audio from specific source in real-time
« Reply #11 on: March 09, 2025, 02:58:42 pm »
But if you want to decode audio files, there is no "native" solution, you will need third-party libraries, like libogg, libflac, libmpg123, etc.

No, that is not what is my goal, just to access and analyze raw real-time sound on Linux. And for that, access to ALSA directly is more than suficient, I do not need multi-platform solution.

Hmm, maybe, if the user doesn't use pipewire or pulseaudio, this could be enough (that's why I prefer to do like the "tenors" Audacity, VLC, Mixxl, ... who use PortAudio which can manage many audio servers and which is installed by default on many distros).

(I understand your frustrations, I had the same.  :-X)
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: 3720
    • StrumPract is the musicians best friend
Re: Analyzing audio from specific source in real-time
« Reply #12 on: March 09, 2025, 03:22:39 pm »
No need for FFT lib, there is "native" pascal version.

Are you talking about this: https://gitlab.com/freepascal.org/fpc/source/-/blob/main/packages/fftw/src/fftw_s.pas ?

Code: Pascal  [Select][+][-]
  1. {$IFDEF Unix}
  2.   const
  3.     fftwlib = 'fftw3f';
  4. {$ELSE}
  5.   const
  6.     fftwlib = 'libfftw3f';
  7. {$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

Dzandaa

  • Hero Member
  • *****
  • Posts: 501
  • From C# to Lazarus
Re: Analyzing audio from specific source in real-time
« Reply #13 on: March 09, 2025, 05:40:28 pm »
Hi,

Some weeks ago I rewrote a fft program in Pascal for one of my projects.

Included a hamming function.

You can remove it if you don't need it.


If you want to try it.

B->

Regards,
Dzandaa

Fred vS

  • Hero Member
  • *****
  • Posts: 3720
    • StrumPract is the musicians best friend
Re: Analyzing audio from specific source in real-time
« Reply #14 on: March 09, 2025, 05:45:12 pm »
Hi,

Some weeks ago I rewrote a fft program in Pascal for one of my projects.

WoW!
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