Recent

Author Topic: Notification beep under Linux  (Read 11181 times)

kupferstecher

  • Hero Member
  • *****
  • Posts: 583
Notification beep under Linux
« on: October 15, 2016, 07:19:59 pm »
In my application I want to implement a sound notification. I used the procedure Sound(Hz: Word) and NoSound, which is fine under Windows, but doesn't work under Linux. When calling the procedure there is no sound but also no error or anything. Is there any other way of creating a sound with definable frequency? Using a 'wav' or 'mp3' wouldn't do, as then I have to provide one for each frequency...

Thanks for any suggestions!


RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Notification beep under Linux
« Reply #1 on: October 15, 2016, 08:01:22 pm »
http://breakoutbox.de/pascal/pascal.html

BASS.dll
http://www.un4seen.com/

EDIT:
I found this...

Code: Pascal  [Select][+][-]
  1. Procedure FillSinus(Freq: Single; Length: Single);
  2.   Var
  3.    Samples: Array Of SmallInt;
  4.    I      : Integer;
  5.  Begin
  6.   SetLength(Samples, Round(Length*44000));
  7.  
  8.    For I:= 0 To High(Samples)
  9.    Do Samples[I]:= Round(30000*Sin(I/44000*2*Pi/Freq));
  10.  
  11.   // BASS or SDL_MIX or whatever... // Exchange with your library...
  12.   SoundLibrary_Upload_Data(@Samples[0], Length(Samples), SoundLibrary_Format_16bit_Signed, 44000);
  13.  End;
  14.  
« Last Edit: October 15, 2016, 08:11:38 pm by SoE »
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

kupferstecher

  • Hero Member
  • *****
  • Posts: 583
Re: Notification beep under Linux
« Reply #2 on: October 15, 2016, 10:41:33 pm »
Thanks for the suggestions, I'll have a try!

Fred vS

  • Hero Member
  • *****
  • Posts: 3158
    • StrumPract is the musicians best friend
Re: Notification beep under Linux
« Reply #3 on: October 17, 2016, 03:17:58 pm »
Hello.

For Linux that uses alsa library:

Code: Pascal  [Select][+][-]
  1. speaker-test -t sine -f 1000 -l 1

The beep duration will be arbitrary, but can be controlled as follows:

Code: Pascal  [Select][+][-]
  1. ( speaker-test -t sine -f 1000 )& pid=$! ; sleep 0.1s ; kill -9 $pid

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

kupferstecher

  • Hero Member
  • *****
  • Posts: 583
Re: Notification beep under Linux
« Reply #4 on: October 24, 2016, 08:21:17 pm »
Fred, thanks for the simple solution. In the shell it works, but how can I call it from within the programm without pausing the programm execution?

Actually I'd prefer (but it's not a must) a solution which a start and a stop command and not passing a time when starting.
So I also tried to use PortAudio which is in the link from SoE. But unfortunately I couldn't work out how to do static linking. Any further ideas?

Fred vS

  • Hero Member
  • *****
  • Posts: 3158
    • StrumPract is the musicians best friend
Re: Notification beep under Linux
« Reply #5 on: October 25, 2016, 05:48:11 pm »
Quote
... but how can I call it from within the programm without pausing the programm execution?

Hello.
You may use Threads for this.

Quote
So I also tried to use PortAudio which is in the link from SoE. But unfortunately I couldn't work out how to do static linking. Any further ideas?

You may try https://github.com/fredvs/uos, it uses PortAudio dynamically loaded.
All the libraries for Linux, Windows, OSX and FreeBSD are included in uos package.

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

mica

  • Full Member
  • ***
  • Posts: 196
« Last Edit: October 25, 2016, 07:51:23 pm by mica »

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Notification beep under Linux
« Reply #7 on: October 25, 2016, 07:47:12 pm »
Beep?

http://www.freepascal.org/docs-html/rtl/sysutils/beep.html

Quote
Description

Beep sounds the system bell, if one is available. The actual beep is produced by the OnBeep callback. The Sysutils unit itself contains no implementation of this call.

kupferstecher

  • Hero Member
  • *****
  • Posts: 583
Re: Notification beep under Linux
« Reply #8 on: October 26, 2016, 10:10:16 pm »
Hello

You may use Threads for this.
OK, that would be a way to go, thanks! It just feels rather like a workaround than a solution.

You may try https://github.com/fredvs/uos, it uses PortAudio dynamically loaded.
I saw that before when searching for that topic, but I don't like that it loads dynamically. I just want to have a bare programm binary. So for the little feature of the beep I don't want to change that.

or fpsystem with beep?

http://www.freepascal.org/docs-html/rtl/unix/fpsystem.html
https://www.kirrus.co.uk/2010/09/linux-beep-music/
Thats basically the same as suggested by Fred, isn't? It seems fpSystem also waits until the command is finished.

Quote
Beep sounds the system bell, if one is available. The actual beep is produced by the OnBeep callback. The Sysutils unit itself contains no implementation of this call.
I didn't try that. It might be similar to the procedures Sound and NoSound, which are actually available in Linux, but just don't generate any beep.

Seems its not possible to get the perfect solution...

cpicanco

  • Hero Member
  • *****
  • Posts: 618
  • Behavioral Scientist and Programmer
    • Portfolio
Re: Notification beep under Linux
« Reply #9 on: January 26, 2017, 01:35:09 am »
I would recommend SDL2 (https://www.libsdl.org/) instead of BASS. There is a binding for free pascal here: https://github.com/sysrpl/Bare.Game/blob/master/source/bare.interop.sdl2.pas

SDL2 is LGPL (both binding and library)

BASS is proprietary.

__

edit.: I need to correct myself SDL2 uses this license: http://www.gzip.org/zlib/zlib_license.html
« Last Edit: January 26, 2017, 02:28:38 am by cpicanco »
Be mindful and excellent with each other.
https://github.com/cpicanco/

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: Notification beep under Linux
« Reply #10 on: January 26, 2017, 08:39:23 am »
You may use Threads for this.
OK, that would be a way to go, thanks! It just feels rather like a workaround than a solution.
Maybe this won't feel like a workaround:
http://forum.lazarus.freepascal.org/index.php/topic,35526.msg235087.html
http://wiki.freepascal.org/Executing_External_Programs

You may try https://github.com/fredvs/uos, it uses PortAudio dynamically loaded.
I saw that before when searching for that topic, but I don't like that it loads dynamically. I just want to have a bare programm binary. So for the little feature of the beep I don't want to change that.
Then you might want to consider static linking:
http://forum.lazarus.freepascal.org/index.php/topic,35543.msg235150.html
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

Thaddy

  • Hero Member
  • *****
  • Posts: 14157
  • Probably until I exterminate Putin.
Re: Notification beep under Linux
« Reply #11 on: January 26, 2017, 09:25:54 am »
If you have aplay/alsa installed and a nice wav available, this is all you need:
Code: Pascal  [Select][+][-]
  1. program untitled;
  2. {$ifdef fpc}{$mode delphi}{$H+}{$endif}
  3.  
  4. uses sysutils,process;
  5. // implements OnBeep
  6. procedure BeepMe;
  7. var s:string;
  8. begin
  9.   runcommand('/usr/bin/aplay', ['/home/pi/beep-02.wav'],s);
  10. end;
  11.  
  12. begin
  13.   OnBeep := BeepMe; //Assign beepme to onbeep ( global event in sysutils)
  14.   Beep;
  15. end.
  16.  

The wiki has a more elaborate function: http://wiki.freepascal.org/Play_Sound_Multiplatform that you can hook to OnBeep
« Last Edit: January 26, 2017, 01:04:42 pm by Thaddy »
Specialize a type, not a var.

 

TinyPortal © 2005-2018