xref: /freebsd/usr.sbin/spkrtest/spkrtest.sh (revision 349cc55c9796c4596a5b9904cd3281af295f878f)
1#!/bin/sh
2
3#
4# SPDX-License-Identifier: BSD-2-Clause-FreeBSD
5#
6# Copyright (c) 2002  The FreeBSD Project
7# All rights reserved.
8#
9# Redistribution and use in source and binary forms, with or without
10# modification, are permitted provided that the following conditions
11# are met:
12# 1. Redistributions of source code must retain the above copyright
13#    notice, this list of conditions and the following disclaimer.
14# 2. Redistributions in binary form must reproduce the above copyright
15#    notice, this list of conditions and the following disclaimer in the
16#    documentation and/or other materials provided with the distribution.
17#
18# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28# SUCH DAMAGE.
29#
30
31#
32# Inspired on spkrtest.pl, rewritten from scratch to remove perl dependency
33# $VER: spkrtest 0.3 (9.5.2002) Riccardo "VIC" Torrini <riccardo@torrini.org>
34# $FreeBSD$
35#
36
37cleanExit() {
38	rm -f ${choices}
39	exit ${1:-0}
40}
41
42trap 'cleanExit 1' 1 2 3 5 15	# HUP, INT, QUIT, TRAP, TERM
43
44choices=${TMP:-/tmp}/_spkrtest_choices.$$
45speaker=/dev/speaker
46
47test -w ${speaker}
48if [ $? -ne 0 ]
49then
50	echo "You have no write access to $speaker or the speaker device is"
51	echo "not enabled in kernel. Cannot play any melody! See spkr(4)."
52	sleep 2
53	cleanExit 1
54fi
55
56/usr/bin/bsddialog --title " Speaker test " --checklist \
57	"Please select the melodies you wish to play (space for select)" \
58	0 0 0 \
59	reveille "Reveille" off \
60	contact "Contact theme from Close Encounters" off \
61	dance "Lord of the Dance (aka Simple Gifts)" off \
62	loony "Loony Toons theme" off \
63	sinister "Standard villain's entrance music" off \
64	rightstuff "A trope from 'The Right Stuff' score by Bill Conti" off \
65	toccata "Opening bars of Bach's Toccata and Fugue in D Minor" off \
66	startrek "Opening bars of the theme from Star Trek Classic" off \
67		2> ${choices} || cleanExit 0
68
69echo ""
70tunes="`cat ${choices}`"
71for tune in ${tunes:-DEFAULT}
72do
73	case ${tune:-NULL} in
74	DEFAULT)
75		title="(default melody)"
76		music="ec"
77		;;
78	reveille)
79		title="Reveille"
80		music="t255l8c.f.afc~c.f.afc~c.f.afc.f.a..f.~c.f.afc~c.f.afc~c.f.afc~c.f.."
81		;;
82	contact)
83		title="Contact theme from Close Encounters"
84		music="<cd<a#~<a#>f"
85		;;
86	dance)
87		title="Lord of the Dance (aka Simple Gifts)"
88		music="t240<cfcfgagaa#b#>dc<a#a.~fg.gaa#.agagegc.~cfcfgagaa#b#>dc<a#a.~fg.gga.agfgfgf."
89		;;
90	loony)
91		title="Loony Toons theme"
92		music="t255cf8f8edc<a>~cf8f8edd#e~ce8cdce8cd.<a>c8c8c#def8af8"
93		;;
94	sinister)
95		title="standard villain's entrance music"
96		music="mst200o2ola.l8bc.~a.~>l2d#"
97		;;
98	rightstuff)
99		title="a trope from 'The Right Stuff' score by Bill Conti"
100		music="olcega.a8f>cd2bgc.c8dee2"
101		;;
102	toccata)
103		title="opening bars of Bach's Toccata and Fugue in D Minor"
104		music="msl16oldcd4mll8pcb-agf+4.g4p4<msl16dcd4mll8pa.a+f+4p16g4"
105		;;
106	startrek)
107		title="opening bars of the theme from Star Trek Classic"
108		music="l2b.f+.p16a.c+.p l4mn<b.>e8a2mspg+e8c+f+8b2"
109		;;
110	esac
111	echo "Title: ${title}"
112	echo ${music} > ${speaker}
113	sleep 1
114done
115cleanExit 0
116