diff makeWebAudio.sh @ 395:b855c35f1257 build-default-174

Automated merge with ssh://hg.cryhavoc.org.uk/dottes
author Jim Hague <jim.hague@acm.org>
date Sun, 01 Sep 2013 23:13:22 +0100
parents ae9c05d2aafd
children aeef7b1ca0ad
line wrap: on
line diff
--- a/makeWebAudio.sh	Sun Sep 01 21:05:39 2013 +0100
+++ b/makeWebAudio.sh	Sun Sep 01 23:13:22 2013 +0100
@@ -16,25 +16,52 @@
 
 mkdir -p $builddir
 
-# Now, for each tune, make the tune bitmap and sound. Do this to temp
-# files and rename into place to make updates as atomic as possible.
+# Make MP3 and OGG files for the input .abc. In case we're generating
+# to a live site (which we won't be), do this to temp files and rename
+# into place to make updates as atomic as possible.
+makeaudiofiles()
+{
+    name=`basename $1 .abc`
+    tmpname=${name}.tmp
+
+    abc2midi $1 -o $builddir/${tmpname}.mid
+    timidity -OwM -o $builddir/${tmpname}.wav $builddir/${tmpname}.mid
+    lame -m m -V 9 --quiet $builddir/${tmpname}.wav $builddir/${tmpname}.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/${tmpname}.ogg $builddir/${tmpname}.wav
+
+    mv $builddir/${tmpname}.mid $builddir/${name}.mid
+    mv $builddir/${tmpname}.mp3 $builddir/${name}.mp3
+    mv $builddir/${tmpname}.ogg $builddir/${name}.ogg
+    rm $builddir/${tmpname}.wav
+}
+
+# Generate audio files and slow speed (currently half speed) audio files.
 find $booke -name "*.abc" | sort |
     while read filename
     do
+        makeaudiofiles $filename
+
         name=`basename $filename .abc`
-        tmpname=${name}.tmp
+        slowspeedfilename="slowspeed-${name}.abc"
 
-        abc2midi $filename -o $builddir/${tmpname}.mid
-        timidity -Ow -o $builddir/${tmpname}.wav $builddir/${tmpname}.mid
-        lame --quiet $builddir/${tmpname}.wav $builddir/${tmpname}.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 -o $builddir/${tmpname}.ogg $builddir/${tmpname}.wav
-
-        mv $builddir/${tmpname}.mid $builddir/${name}.mid
-        mv $builddir/${tmpname}.mp3 $builddir/${name}.mp3
-        mv $builddir/${tmpname}.ogg $builddir/${name}.ogg
-        rm $builddir/${tmpname}.wav
+        # Prepare slow speed audio files.
+        # The tempo is either a plain number, or <notelen>=<number>.
+        tempo=`$dir/abcfield.py --field Q $filename`
+        if [ -z $tempo ]; then
+            echo "Warning: $filename has no tempo. Using 120."
+            tempo="120"
+        fi
+        pos=`expr index $tempo '='`
+        numtempo=${tempo:pos}
+        notelenprefix=${tempo:0:pos}
+        # Make new tempo half original speed.
+        newtempo=$(( $numtempo / 2 ))
+        # 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}" $filename > $builddir/$slowspeedfilename
+        makeaudiofiles $builddir/$slowspeedfilename
     done