Skip to content

Instantly share code, notes, and snippets.

@tuklusan
Created July 4, 2020 03:53
A linux bash shell script to play westminster chime on internal PC speaker (the speaker connected to the motherboard header, i.e. the one attached to the PC hardware's southbridge - 8253 or 8254 PIT chip)
#!/bin/bash
# ----------
# westminster-pcspkr.sh
#
# Plays the three parts of the Westminster chime at 15, 30 and 45 minutes and
# the whole thing followed by gongs couting the hour at 00 minutes.
#
# Uses the pcspkr kernel module and "beep" utility to play on the internal
# PC speaker / beeper (the one connected to the motherboard and uses the
# 8253/8254 PIT chip to generate audio tones)
#
# Pass one of -00, -15, -30 or -45 on the command line for the corresponding
# chime. -00 takes the hour from system time to count the number of strikes
# after playing the full chime.
#
# Distributed under beerware license revision 42:
# Supratim Sanyal (http://tuklusan.decsystem.org) wrote this file. As long
# as you retain this notice you can do whatever you want with this stuff.
# If we meet some day, and you think this stuff is worth it, you can buy me
# a beer in return.
# ----------
# Westminster Chime
# 15 mins: FAGC
# 30 mins: CGAF
# 45 mins: AGFC
# 00 mins: FAGC CGAF AGFC CGAF <#gongs for hour - all four bells>
# Frequencies in hertz
#CNOTE="523.25"
#FNOTE="698.46"
#GNOTE="783.99"
#ANOTE="880.00"
CNOTE="1046.50"
FNOTE="1396.91"
GNOTE="1567.98"
ANOTE="1760.00"
GONG_20MS="-f ${FNOTE} -l 5 -n -f ${ANOTE} -l 5 -n -f ${GNOTE} -l 5 -n -f ${CNOTE} -l 5"
usage ()
{
echo "usage: $0 {-00|-15|-30|-45}"
echo "example: $0 -45"
echo "Plays Westminster chime at 00, 15, 30, 45 minutes using"
echo "beep command to drive internal PC speaker"
echo "Kernel module pcspkr must be available (modprobe pcspkr)"
echo "Obviously motherboard speaker header must have a speaker!"
echo "MUST RUN AS full root, not even as sudo"
sync;sync;sync
exit 1
}
quarter ()
{
beep -f ${FNOTE} -l 1000 -D 500 \
-n -f ${ANOTE} -l 1000 -D 500 \
-n -f ${GNOTE} -l 1000 -D 500 \
-n -f ${CNOTE} -l 1000 -D 1000
}
half ()
{
beep -f ${CNOTE} -l 1000 -D 500 \
-n -f ${GNOTE} -l 1000 -D 500 \
-n -f ${ANOTE} -l 1000 -D 500 \
-n -f ${FNOTE} -l 1000 -D 1000
}
threequarters ()
{
beep -f ${ANOTE} -l 1000 -D 500 \
-n -f ${GNOTE} -l 1000 -D 500 \
-n -f ${FNOTE} -l 1000 -D 500 \
-n -f ${CNOTE} -l 1000 -D 1000
}
full ()
{
quarter
half
threequarters
half
# and now hit all four bells to signal the hour
# create a 1-second gong beep string alternating four bells 5 msec each
# do this only on the top of the hour, not every time script is invoked
GONG="${GONG_20MS}"
for ii in {1..49}
do
GONG="${GONG} -n ${GONG_20MS}"
done
GONG="${GONG} -D 1000"
HOUR=`date +%l|tr -d '[:space:]'`
for ii in $(eval echo "{1..${HOUR}}")
do
# echo "[$ii] HOUR [${HOUR}]"
beep ${GONG}
done
}
# --- main ---
if [ "$#" -ne 1 ]; then
usage
fi
case $1 in
-15)
quarter
;;
-30)
half
;;
-45)
threequarters
;;
-00)
full
;;
*)
usage
;;
esac
sync;sync;sync
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment