2012-03-04 12:39:12 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
2013-02-22 01:09:37 +00:00
|
|
|
# Make audio required for the website but not for the book.
|
2012-03-04 12:39:12 +00:00
|
|
|
# They go into web/<book>.
|
|
|
|
#
|
|
|
|
|
|
|
|
if [ $# != 1 ]; then
|
2013-02-22 01:09:37 +00:00
|
|
|
echo "Usage: makeWebAudio.sh <book dir name>"
|
2012-03-04 12:39:12 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
dir=`pwd`
|
|
|
|
|
|
|
|
booke=$dir/$1
|
2019-08-05 23:25:28 +01:00
|
|
|
basewebdir=$dir/web
|
|
|
|
basetunedir=$basewebdir/tunes
|
2012-03-04 12:39:12 +00:00
|
|
|
|
2013-09-02 11:48:16 +01:00
|
|
|
# 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)
|
2019-08-05 23:25:28 +01:00
|
|
|
# MP3 and OGG. $1 is the input filename, $2 is the output directory,
|
|
|
|
# $3 is optional args for timidity.
|
2013-09-01 23:13:06 +01:00
|
|
|
makeaudiofiles()
|
|
|
|
{
|
|
|
|
name=`basename $1 .abc`
|
2019-08-05 23:25:28 +01:00
|
|
|
tunedir="$2"
|
2013-09-01 23:13:06 +01:00
|
|
|
|
2020-02-19 12:45:04 +00:00
|
|
|
abc2midi $1 -o $tunedir/${name}.tmp.mid -silent
|
2019-08-05 23:25:28 +01:00
|
|
|
mv $tunedir/${name}.tmp.mid $tunedir/${name}.mid
|
2024-01-06 23:12:10 +00:00
|
|
|
timidity --quiet -A100,100 -OwM $3 -o $tunedir/${name}.wav $tunedir/${name}.mid
|
2020-02-19 12:45:04 +00:00
|
|
|
lame -m m -V 9 --silent $tunedir/${name}.wav $tunedir/${name}.tmp.mp3
|
2019-08-05 23:25:28 +01:00
|
|
|
mv $tunedir/${name}.tmp.mp3 $tunedir/${name}.mp3
|
2013-09-01 23:13:06 +01:00
|
|
|
# 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.
|
2019-08-05 23:25:28 +01:00
|
|
|
oggenc -Q -q 0 -o $tunedir/${name}.tmp.ogg $tunedir/${name}.wav
|
|
|
|
mv $tunedir/${name}.tmp.ogg $tunedir/${name}.ogg
|
2013-09-01 23:13:06 +01:00
|
|
|
|
2019-08-05 23:25:28 +01:00
|
|
|
rm $tunedir/${name}.wav
|
2013-09-01 23:13:06 +01:00
|
|
|
}
|
|
|
|
|
2019-08-05 23:25:28 +01:00
|
|
|
# Make audio for a new tempo for the abc file $1, giving the output
|
|
|
|
# files the same name with a prefix $3 in output directory $2. The new
|
|
|
|
# tempo is the original tempo (120 used if not specified), multiplied
|
|
|
|
# by $4 and divided by $5. 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.
|
2013-09-02 10:15:56 +01:00
|
|
|
makeaudiofortempo()
|
|
|
|
{
|
2019-08-05 23:25:28 +01:00
|
|
|
name=`basename $1 .abc`
|
|
|
|
tunedir="$2"
|
|
|
|
newspeedfilename="$3-${name}.abc"
|
|
|
|
mkdir -p $tunedir
|
2013-09-02 10:15:56 +01:00
|
|
|
|
|
|
|
# Prepare new speed audio files.
|
|
|
|
# The tempo is either a plain number, or <notelen>=<number>.
|
|
|
|
tempo=`$dir/abcfield.py --field Q $1`
|
|
|
|
if [ -z $tempo ]; then
|
|
|
|
echo "Warning: $1 has no tempo. Using 120."
|
|
|
|
tempo="120"
|
|
|
|
fi
|
2020-02-19 10:33:55 +00:00
|
|
|
numtempo=${tempo##*=}
|
|
|
|
notelenprefix=${tempo%%=*}
|
|
|
|
if [ "$notelenprefix" = "$numtempo" ]; then
|
|
|
|
notelenprefix=
|
|
|
|
else
|
|
|
|
notelenprefix="${notelenprefix}="
|
|
|
|
fi
|
2013-09-02 10:15:56 +01:00
|
|
|
# Calculate new tempo.
|
2019-08-05 23:25:28 +01:00
|
|
|
newtempo=$(( ( $numtempo * $4 ) / $5 ))
|
2013-09-02 10:15:56 +01:00
|
|
|
# Insert new tempo and delete old. Old may not exist,
|
|
|
|
# so do this rather than overwrite.
|
2020-02-19 10:33:55 +00:00
|
|
|
sed -e "/^Q:/d" -e "/^K:/a\\
|
|
|
|
Q: ${notelenprefix}${newtempo}" $1 > $tunedir/$newspeedfilename
|
2019-08-05 23:25:28 +01:00
|
|
|
makeaudiofiles $tunedir/$newspeedfilename $tunedir --mute=0,-1
|
|
|
|
rm $tunedir/$newspeedfilename
|
2013-09-02 10:15:56 +01:00
|
|
|
}
|
|
|
|
|
2013-09-01 23:13:06 +01:00
|
|
|
# Generate audio files and slow speed (currently half speed) audio files.
|
2020-02-19 11:14:40 +00:00
|
|
|
find $booke -maxdepth 1 -name "*.abc" |
|
2012-03-04 12:39:12 +00:00
|
|
|
while read filename
|
|
|
|
do
|
2019-08-05 23:25:28 +01:00
|
|
|
name=`basename $filename .abc`
|
|
|
|
tunedir=$basetunedir/$name
|
2020-02-18 15:13:38 +00:00
|
|
|
|
2019-08-05 23:25:28 +01:00
|
|
|
mkdir -p $tunedir
|
|
|
|
|
|
|
|
makeaudiofiles $filename $tunedir
|
2013-09-01 23:13:06 +01:00
|
|
|
|
2013-09-02 10:15:56 +01:00
|
|
|
# Now make 1/4, 1/2 and 3/4 speed audio.
|
2019-08-05 23:25:28 +01:00
|
|
|
makeaudiofortempo $filename $tunedir "veryslow" 1 4
|
|
|
|
makeaudiofortempo $filename $tunedir "slow" 2 4
|
|
|
|
makeaudiofortempo $filename $tunedir "littleslow" 3 4
|
|
|
|
makeaudiofortempo $filename $tunedir "normal" 4 4
|
2012-03-04 12:39:12 +00:00
|
|
|
done
|