author Jim Hague <>
Tue, 06 Sep 2016 20:48:32 +0100
changeset 567 cb7a4eff9d5b
parent 400 f1c4abe4fc75
child 748 ce5c7214f9aa
permissions -rwxr-xr-x
Have learner tunes play only the melody. Do this by telling timidity to mute all tracks but the first.

# Make audio required for the website but not for the book.
# They go into web/<book>.

if [ $# != 1 ]; then
    echo "Usage: <book dir name>"
    exit 1



mkdir -p $builddir

# Make MP3 and OGG files for the input .abc. Since we're listening to
# a doorbell playing the tunes, go for lowest quality (and hence smallest)
# MP3 and OGG. $1 is the input filename, $2 is optional args for timidity.
    name=`basename $1 .abc`

    abc2midi $1 -o $builddir/${name}.mid
    timidity -OwM $2 -o $builddir/${name}.wav $builddir/${name}.mid
    lame -m m -V 9 --quiet $builddir/${name}.wav $builddir/${name}.mp3
    # Timidity can generate OGG directly. But we need to generate WAV
    # for lame, and oggenc produces smaller output. OGG is needed for
    # Firefox's audio tag. FF doesn't support MP3, some others support
    # MP3 but not OGG.
    oggenc -Q -q 0 -o $builddir/${name}.ogg $builddir/${name}.wav

    rm $builddir/${name}.wav

# Make audio for a new tempo for the abc file $1, giving the output files
# the same name with a prefix $2. The new tempo is the original tempo
# (120 used if not specified), multiplied by $3 and divided by $4.
# These audio files are for Learner use; I've found that having the
# chords thumping away can make it hard to distinguish the melody, so
# arrange for timidity to mute everything except the melody track.
    name=`basename $filename .abc`

    # Prepare new speed audio files.
    # The tempo is either a plain number, or <notelen>=<number>.
    tempo=`$dir/ --field Q $1`
    if [ -z $tempo ]; then
        echo "Warning: $1 has no tempo. Using 120."
    pos=`expr index $tempo '='`
    # Calculate new tempo.
    newtempo=$(( ( $numtempo * $3 ) / $4 ))
    # Insert new tempo and delete old. Old may not exist,
    # so do this rather than overwrite.
    sed -e "/^Q:/d" -e "/^K:/aQ: ${notelenprefix}${newtempo}" $1 > $builddir/$newspeedfilename
    makeaudiofiles $builddir/$newspeedfilename --mute=0,-1
    rm $builddir/$newspeedfilename

# Generate audio files and slow speed (currently half speed) audio files.
find $booke -name "*.abc" | sort |
    while read filename
        makeaudiofiles $filename

        # Now make 1/4, 1/2 and 3/4 speed audio.
        makeaudiofortempo $filename "veryslow" 1 4
        makeaudiofortempo $filename "slow" 2 4
        makeaudiofortempo $filename "littleslow" 3 4
        makeaudiofortempo $filename "normal" 4 4