Discussion:
[fpc-pascal]Beep in Linux
Aitor Santamaría Merino
2002-07-03 09:22:29 UTC
Permalink
Hi,

Does anyone know how to use the PC speaker to produce a beep in Linux,
just as

write (#7);

will work under DOS and Win32?

Aitor
A.J. Venter
2002-07-03 09:21:03 UTC
Permalink
mmmm,
I wrote a small proggie quickly that used the ncurses wrapper and called the beep routine from curses (man beep)
IE:
program beeptest;
USes NCurses;

Begin
Beep;
End.

It compiled fine, but throws an error 216 (General Protection Fault) when I tried to run it (I tried it as root as well so it isn't permissions)

This seems to mean one of three things:
A> There is a catch to using the beep from ncurses - anybody know how it is used in C ?
B> There is a bug in the latest version of ncurses
C> There is a bug in the ncurses wrapper unit

In case of option C, my guess is it probably has to do with changes in the newer versions of ncurses.

All that said there is another option - asuming you do not considder the use of the speaker vital, but can settle on a soundcard.
Almost every distribution includes a commandline mp3 and wav player and most also include oggvorbis support.

THen you could use the shell procedure from the Linux unit to run such a commandline tool and play an audible warning from a sound file, perhaps
one more userfriendly than a beep.

For example for Ogg Vorbis with your warning stored in warning.ogg the command is:
shell ('ogg123 warning.ogg');
etc.

If you wish to be able to play the sound without waiting for it to finished (e.g. in the background such as for games)
the easiest way (since it requires no library imports) is to use a player command and run it through assignstream.

Ciao
A.J.
Post by Aitor Santamaría Merino
Hi,
Does anyone know how to use the PC speaker to produce a beep in Linux,
just as
write (#7);
will work under DOS and Win32?
Aitor
_______________________________________________
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Aitor Santamaría
2002-07-03 09:52:43 UTC
Permalink
Post by A.J. Venter
mmmm,
I wrote a small proggie quickly that used the ncurses wrapper and called the beep routine from curses (man beep)
program beeptest;
USes NCurses;
Begin
Beep;
End.
I wondered if certain platform independent Beep procedure would exist.
That's what I was looking for, thanks!
It's a pitty to be a problem there, though...
Post by A.J. Venter
All that said there is another option - asuming you do not considder the use of the speaker vital, but can settle on a soundcard.
Almost every distribution includes a commandline mp3 and wav player and most also include oggvorbis support.
These are too many assumptions for my taste :)

Aitor
A.J. Venter
2002-07-03 09:55:03 UTC
Permalink
Post by Aitor Santamaría
Post by A.J. Venter
All that said there is another option - asuming you do not considder the
use of the speaker vital, but can settle on a soundcard. Almost every
distribution includes a commandline mp3 and wav player and most also
include oggvorbis support.
These are too many assumptions for my taste :)
True,
However you do not need to make assumptions by need, soundcards are now almost standard equipment so that one is
relatively safe, as for the rest the simple way around it is to use create an install script for your program to configure it.

You could write a makefile for this, or use a shell script, the latter having the advantage that it can be coupled with most package managers
such as deb or rpm.

In bash the script could be something like:

#!/bin/bash

echo "Installing binaries:"
echo -n "Directory to install to:"
read INSTALLDIR
cp myapp $INSTALLDIR
...
echo "Configuring program"
echo -n "What sound format would you like [mp3,ogg,wav] :"
read SOUNDFORMAT
echo -n "Where do you want the sound file installed ?"
READ SOUNDDIR
mv mysoundfile.$SOUNDFORMAT SOUNDDIR
echo -n "Type the commandline for play $SOUNDFORMAT files:"
read SOUNDCMD
echo "Creating configuration file /etc/myapp.conf"
echo "$SOUNDCMD" > /etc/myapp.conf
echo "$SOUNDFORMAT" >> /etc/myapp.conf

echo "All done"

Then you merely read the two lines in /etc/myapp.conf into two strings and do:
shell (sound_command + ' mysoundfile.' + soundformat);

Thus is my suggestion, I hope it is helpful, if not perhaps it may be at some time in the future.

Ciao
A.J. Venter
Ken J. Wright
2002-07-04 04:31:39 UTC
Permalink
The ncrt unit includes the sound() procedure which just does a simple beep.
Note that the frequency parameter is ignored and the nosound() procedure
is not required to turn it off.

Ken
Post by Aitor Santamaría Merino
Hi,
Does anyone know how to use the PC speaker to produce a beep in Linux,
just as
write (#7);
will work under DOS and Win32?
Aitor
_______________________________________________
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Loading...