1#!/bin/sh
2
3# Thanks to Reynir H. Stefánsson for the original version of this script.
4
5# In marine radio, a Mayday emergency call is transmitted preceded by a
6# 30-second alert sound.  The alert sound comprises two audio tones at
7# 1300Hz and 2100Hz alternating at a rate of 4Hz.  This script shows how SoX
8# can be used to construct an audio file containing the alert sound.
9
10# This is a `Bourne shell' (sh) script but it should be simple to translate
11# this to another scripting language if you do not have access to sh.
12
13# If you run this script, you may want to hit Ctrl-C fairly soon after the
14# alert tone starts playing---it's not a pleasant sound!
15
16# The synth effect is used to generate each of the tones; "-e mu-law -r 8000"
17# selects u-law 8kHz sampling-rate audio (i.e. relatively low fidelity,
18# suitable for the marine radio transmission channel); each tone is
19# generated at a length of 0.25 seconds to give the required 4Hz
20# alternation.
21
22# Note the use of `raw' as the intermediary file format; a self-describing
23# (header) format would just get in the way here.  The self-describing
24# header is added only at the final stage.
25
26# ---------------------------------------------------------------------------
27
28SOX=../src/sox
29
30rm -f 2tones.ul    # Make sure we append to a file that's initially empty
31
32for freq in 1300 2100; do
33  $SOX -e mu-law -r 8000 -n -t raw - synth 0.25 sine $freq gain -3 >> 2tones.ul
34done
35
36$SOX -c 1 -r 8000 2tones.ul alert.au repeat - trim 0 30
37                   # Repeat to fill 30 seconds and add a file header
38rm 2tones.ul       # Tidy up intermediate file
39
40$SOX alert.au -d
41