Discussion:
[Lazarus] Beep?
Donald Ziesig via Lazarus
2018-03-26 02:02:14 UTC
Permalink
Hi Everyone!

I am using Lazarus 1.8 on Linux Mint.  I would like to use the
Windows.Beep( Freq, Duration) function, or (if not available)
SysUtils.Beep subprograms.

Simplest problem.  SysUtils.Beep compiles and links but is silent.

Slightly more difficult (according to StackOverflow)

I should be able to insert (manually) Windows in the uses clause, then
call the windows.beep( f, d) function, but fcp can't find Windows even
though there are several windows.pp files in the fpcscr directories.

Failing that, the article says:

|functionBeep(dwFreq,dwDuration:DWORD):BOOL;stdcall;external'kernel32.dll';|

should work, but it causes a linker error after compilation.  I don't
have lernel32.dll on my Linux system.

A long time ago, I used the Windows.Beep (on windows) to produce Morse
Code error messages while debugging visual components.  I would like to
do that now if possible, but on Linux.

Any suggestions would be appreciated.

Thanks,

Don Ziesig
Carlos E. R. via Lazarus
2018-03-26 04:09:27 UTC
Permalink
Post by Donald Ziesig via Lazarus
Hi Everyone!
I am using Lazarus 1.8 on Linux Mint.  I would like to use the
Windows.Beep( Freq, Duration) function, or (if not available)
SysUtils.Beep subprograms.
AFAIK, you can not call Windows functions in Linux.
--
Cheers / Saludos,

Carlos E. R.
(from 42.3 x86_64 "Malachite" at Telcontar)
Carlos E. R. via Lazarus
2018-03-29 10:12:48 UTC
Permalink
Post by Carlos E. R. via Lazarus
Post by Donald Ziesig via Lazarus
Hi Everyone!
I am using Lazarus 1.8 on Linux Mint.  I would like to use the
Windows.Beep( Freq, Duration) function, or (if not available)
SysUtils.Beep subprograms.
AFAIK, you can not call Windows functions in Linux.
Further, my understanding is that the loudspeaker is associated to the
terminal in Linux. You can not thus beep from a daemon, something that
would be useful. We apparently do not get access to program the chip as in
MsDOS, nor freq,duration.


Here I post an attempt I did back on 2005. It doesn't compile, and this
moment I can't check why. Nor, of course, do I remember what I was trying.

program beeper;

uses linux;

var
Saved43, Saved61: byte;
LoadClock: word;
frequency: word;
duration: real;
RequestedDuration, RemainingDuration: timespec;

hh,mm,ss, msec, usec: word;
begin
(*
if paramcount <> 2 then begin
writeln('Produces a beep of the indicated frequency and
duration.');
writeln('Usage: beeper frequency duration');
halt(1);
end;


frequency:= round(ParamStr(1));
duration:= ParamStr(2);
*)

frequency:= 500;
duration:= 1.2;


RequestedDuration.tv_sec:= trunc(duration);
RequestedDuration.tv_nsec:= trunc(frac(duration)*1e9);

{ioperm(from, num, value)}
writeln($61, ' ', $42);
writeln(ioperm($61, 1, 1), ' ', ioperm($42, 2, 1));

{timer prepare}
ReadPort($43, Saved43);
writeln('43h', ' ', Saved43);
writeport($43, byte($B6)); {Channel 2, LSB/MSB}

LoadClock:= 1193180 div frequency;
writeport($42, Lo(LoadClock));
writeport($42, Hi(LoadClock));

ReadPort($61, Saved61);
writeln('61h', ' ', Saved61);
writeport($61, byte(Saved61 or $3)); {Speaker on}


{Select(0, nil, nil, nil, 1000);}
gettime(hh,mm,ss, msec, usec);
writeln(hh,':', mm, ':', ss, '.', msec, ' ', usec);
nanosleep(RequestedDuration, RemainingDuration);
gettime(hh,mm,ss, msec, usec);
writeln(hh,':', mm, ':', ss, '.', msec, ' ', usec);

writeport($61, Saved61); {Speaker off}

end.


I also have copies of some c code I got from fidonet posts that I can look
at another day, in assembler. I don't remember if they worked, probably
not.


- --
Cheers,
Carlos E. R.
(from openSUSE 42.3 x86_64 "Malachite" at Telcontar)
Donald Ziesig via Lazarus
2018-03-29 13:42:28 UTC
Permalink
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Post by Carlos E. R. via Lazarus
Post by Donald Ziesig via Lazarus
Hi Everyone!
I am using Lazarus 1.8 on Linux Mint.  I would like to use the
Windows.Beep( Freq, Duration) function, or (if not available)
SysUtils.Beep subprograms.
AFAIK, you can not call Windows functions in Linux.
Further, my understanding is that the loudspeaker is associated to the
terminal in Linux. You can not thus beep from a daemon, something that
would be useful. We apparently do not get access to program the chip
as in MsDOS, nor freq,duration.
Here I post an attempt I did back on 2005. It doesn't compile, and
this moment I can't check why. Nor, of course, do I remember what I
was trying.
program beeper;
uses linux;
var
        Saved43, Saved61: byte;
        LoadClock: word;
        frequency: word;
        duration:  real;
        RequestedDuration, RemainingDuration: timespec;
        hh,mm,ss, msec, usec: word;
begin
(*
        if paramcount <> 2 then begin
                writeln('Produces a beep of the indicated frequency
and duration.');
                writeln('Usage: beeper frequency duration');
                halt(1);
        end;
        frequency:= round(ParamStr(1));
        duration:= ParamStr(2);
*)
        frequency:= 500;
        duration:=  1.2;
        RequestedDuration.tv_sec:=      trunc(duration);
        RequestedDuration.tv_nsec:=     trunc(frac(duration)*1e9);
        {ioperm(from, num, value)}
        writeln($61, '   ', $42);
        writeln(ioperm($61, 1, 1), ' ', ioperm($42, 2, 1));
                {timer prepare}
        ReadPort($43, Saved43);
        writeln('43h', ' ', Saved43);
        writeport($43, byte($B6));      {Channel 2, LSB/MSB}
        LoadClock:= 1193180 div frequency;
        writeport($42, Lo(LoadClock));
        writeport($42, Hi(LoadClock));
        ReadPort($61, Saved61);
        writeln('61h', ' ', Saved61);
        writeport($61, byte(Saved61 or $3));    {Speaker on}
                {Select(0, nil, nil, nil, 1000);}
        gettime(hh,mm,ss, msec, usec);
        writeln(hh,':', mm, ':', ss, '.', msec, ' ', usec);
        nanosleep(RequestedDuration, RemainingDuration);
        gettime(hh,mm,ss, msec, usec);
        writeln(hh,':', mm, ':', ss, '.', msec, ' ', usec);
        writeport($61, Saved61);        {Speaker off}
end.
I also have copies of some c code I got from fidonet posts that I can
look at another day, in assembler. I don't remember if they worked,
probably not.
- -- Cheers,
       Carlos E. R.
       (from openSUSE 42.3 x86_64 "Malachite" at Telcontar)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
iEYEARECAAYFAlq8vCgACgkQtTMYHG2NR9W0MQCfW3PJfWFopnrWMV9V+bCcA1ZQ
2goAn3C6b2V2kwsunTiqB5o1vIQIaF8H
=v6dw
-----END PGP SIGNATURE-----
Thanks Carlos!

I am presently recovering from surgery and taking medication for pain. 
I will try your suggestion once my pain is gone and I can think straight
;-).

Don

Marc Santhoff via Lazarus
2018-03-26 19:59:13 UTC
Permalink
(sending again from the subscribed mail address...
if moderation is active, please drop the other mail - sorry and thanks)
Post by Donald Ziesig via Lazarus
Any suggestions would be appreciated.
Make sure your computer can beep? (speaker connected, etc.)

Try "writeln(#07)"?

Check if X has beeps switched off ("xset -b")?

HTH anyhow,
Marc
--
Marc Santhoff <***@web.de>
--
Landmesser John via Lazarus
2018-03-27 06:11:24 UTC
Permalink
perhaps:

* A simple visual component to play WAVe files in Windows or Linux
* For more information, see: http://wiki.freepascal.org/TPlaySound
Post by Donald Ziesig via Lazarus
Hi Everyone!
I am using Lazarus 1.8 on Linux Mint.  I would like to use the
Windows.Beep( Freq, Duration) function, or (if not available)
SysUtils.Beep subprograms.
Simplest problem.  SysUtils.Beep compiles and links but is silent.
Slightly more difficult (according to StackOverflow)
I should be able to insert (manually) Windows in the uses clause, then
call the windows.beep( f, d) function, but fcp can't find Windows even
though there are several windows.pp files in the fpcscr directories.
|functionBeep(dwFreq,dwDuration:DWORD):BOOL;stdcall;external'kernel32.dll';|
should work, but it causes a linker error after compilation.  I don't
have lernel32.dll on my Linux system.
A long time ago, I used the Windows.Beep (on windows) to produce Morse
Code error messages while debugging visual components.  I would like
to do that now if possible, but on Linux.
Any suggestions would be appreciated.
Thanks,
Don Ziesig
Loading...