| 1 |
#!/bin/sh |
| 2 |
# |
| 3 |
# Copyright (C) 2013 Mark Hills <[email protected]> |
| 4 |
# |
| 5 |
# This program is free software; you can redistribute it and/or |
| 6 |
# modify it under the terms of the GNU General Public License |
| 7 |
# version 2, as published by the Free Software Foundation. |
| 8 |
# |
| 9 |
# This program is distributed in the hope that it will be useful, but |
| 10 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 |
# General Public License version 2 for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License |
| 15 |
# version 2 along with this program; if not, write to the Free |
| 16 |
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
| 17 |
# MA 02110-1301, USA. |
| 18 |
# |
| 19 |
|
| 20 |
# |
| 21 |
# View graph of BPM analysis |
| 22 |
# |
| 23 |
|
| 24 |
set -eu |
| 25 |
|
| 26 |
usage() |
| 27 |
{ |
| 28 |
cat <<END |
| 29 |
bpm-graph (C) Copyright 2013 Mark Hills <[email protected]> |
| 30 |
|
| 31 |
Usage: bpm-graph <file> |
| 32 |
Display tempo analysis data |
| 33 |
|
| 34 |
See the bpm-graph(1) man page for more information. |
| 35 |
END |
| 36 |
} |
| 37 |
|
| 38 |
if [ -z "${1-}" ] || [ "$1" = "-h" ]; then |
| 39 |
usage >&2 |
| 40 |
exit 1 |
| 41 |
fi |
| 42 |
|
| 43 |
FILE="$1" |
| 44 |
shift |
| 45 |
|
| 46 |
if ! which gnuplot > /dev/null 2>&1; then |
| 47 |
echo "$0: requires gnuplot to be installed" >&1 |
| 48 |
exit 1 |
| 49 |
fi |
| 50 |
|
| 51 |
TMP=`mktemp -t bpm.XXXXXX` || exit 1 |
| 52 |
trap "rm $TMP" 0 |
| 53 |
|
| 54 |
sox "$FILE" -r 44100 -e float -c 1 -t raw - | bpm -m 60 -x 220 -g $TMP |
| 55 |
gnuplot -p <<END |
| 56 |
set style data lines |
| 57 |
set ylabel "Difference" |
| 58 |
set xlabel "Offset (Beats per minute)" |
| 59 |
plot "$TMP" title "`echo "$FILE" | sed -e 's:\":\\\\":g'`" |
| 60 |
END |