Compare commits

...

11 Commits
0.2 ... master

Author SHA1 Message Date
encoded e0f5676e48 Allows bpm-tag to operate on m4a files.
Tags are written using mp4tags and read using mp4info, both of
which are part of the mp4v2 project, whose code is available at
https://code.google.com/p/mp4v2/
2014-05-23 22:10:28 +01:00
Mark Hills 913728bf97 More descriptive error 2013-05-21 21:38:33 +01:00
Mark Hills 53601f6b3a Widen the range used in the graph 2013-05-21 21:36:16 +01:00
Mark Hills 795c8ea75b Always use set -u to avoid confusion 2013-05-21 21:35:51 +01:00
Mark Hills a0bd601464 Plug xwax as the main use case 2013-05-21 21:34:32 +01:00
Mark Hills 31b1475995 Provide a value for the zero-data case
Really this just suppresses the compiler warning that 'trough' is
not used.
2013-05-21 21:29:50 +01:00
Mark Hills 57a2f9e940 Help message 2013-05-21 21:28:14 +01:00
Mark Hills edca668e4d Default optimisation 2013-05-21 21:22:39 +01:00
Mark Hills f68ec6eff2 Update copyright 2013-05-21 21:21:49 +01:00
Mark Hills 015bbd47aa Add man page 2013-05-21 21:21:28 +01:00
Mark Hills b3cea166c1 Use command name 2013-05-21 20:58:30 +01:00
8 changed files with 116 additions and 13 deletions

View File

@ -4,6 +4,9 @@ PREFIX ?= /usr/local
INSTALL ?= install
BINDIR ?= $(PREFIX)/bin
MANDIR ?= $(PREFIX)/share/man
CFLAGS ?= -O3
CFLAGS += -Wall
LDLIBS += -lm
@ -18,6 +21,8 @@ clean:
install:
$(INSTALL) -d $(DESTDIR)$(BINDIR)
$(INSTALL) -t $(DESTDIR)$(BINDIR) bpm bpm-graph bpm-tag
$(INSTALL) -d $(DESTDIR)$(MANDIR)/man1
$(INSTALL) -t $(DESTDIR)$(MANDIR)/man1 bpm.1 bpm-graph.1 bpm-tag.1
dist:
mkdir -p dist

2
README
View File

@ -1,6 +1,6 @@
bpm-tools: Tempo (Beats Per Minute) analysis tools
(C) Copyright 2012 Mark Hills <mark@xwax.org>
(C) Copyright 2013 Mark Hills <mark@xwax.org>
See the COPYING file for licensing terms.

View File

@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (C) 2012 Mark Hills <mark@xwax.org>
# Copyright (C) 2013 Mark Hills <mark@xwax.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -21,22 +21,37 @@
# View graph of BPM analysis
#
set -e
set -eu
if [ -z "$1" ]; then
echo "Usage: $0 <file>" >&2
usage()
{
cat <<END
bpm-graph (C) Copyright 2013 Mark Hills <mark@xwax.org>
Usage: bpm-graph <file>
Display tempo analysis data
See the bpm-graph(1) man page for more information.
END
}
if [ -z "${1-}" ] || [ "$1" = "-h" ]; then
usage >&2
exit 1
fi
set -u
FILE="$1"
shift
if ! which gnuplot > /dev/null 2>&1; then
echo "$0: requires gnuplot to be installed" >&1
exit 1
fi
TMP=`mktemp -t bpm.XXXXXX` || exit 1
trap "rm $TMP" 0
sox "$FILE" -r 44100 -e float -c 1 -t raw - | bpm -m 60 -x 180 -g $TMP
sox "$FILE" -r 44100 -e float -c 1 -t raw - | bpm -m 60 -x 220 -g $TMP
gnuplot -p <<END
set style data lines
set ylabel "Difference"

1
bpm-graph.1 Normal file
View File

@ -0,0 +1 @@
.so man1/bpm-graph.1

11
bpm-tag
View File

@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (C) 2012 Mark Hills <mark@xwax.org>
# Copyright (C) 2013 Mark Hills <mark@xwax.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -26,7 +26,7 @@ set -e
usage()
{
cat <<END
bpm-tag (C) Copyright 2012 Mark Hills <mark@xwax.org>
bpm-tag (C) Copyright 2013 Mark Hills <mark@xwax.org>
Usage: bpm-tag [options] <file>
Tag an audio file with tempo (in beats-per-minute, BPM)
@ -37,6 +37,7 @@ Tag an audio file with tempo (in beats-per-minute, BPM)
-x Maximum detected BPM
-h Display this help message and exit
See the bpm-tag(1) man page for more information and examples.
END
}
@ -92,6 +93,9 @@ case "$FILE" in
*.ogg)
BPM=`vorbiscomment "$FILE" | sed -n 's/^BPM=//p'`
;;
*.m4a)
BPM=`mp4info "$FILE" | sed -n 's/^\s*BPM://p'`
;;
*)
echo "$FILE: file extension not known" >&2
exit 1
@ -128,6 +132,9 @@ case "$FILE" in
*.ogg)
vorbiscomment -at "BPM=$BPM" "$FILE"
;;
*.m4a)
mp4tags -tempo "$BPM" "$FILE"
;;
*)
echo "$FILE: don't know how to tag this type of file" >&2
exit 1

1
bpm-tag.1 Normal file
View File

@ -0,0 +1 @@
.so man1/bpm.1

73
bpm.1 Normal file
View File

@ -0,0 +1,73 @@
.TH BPM "1"
.SH NAME
bpm-tools \- calculate the tempo of music files
.SH SYNOPSIS
.B bpm-tag
[\fIoptions\fR] \fIfile\fR
.B bpm-graph
\fIfile\fR
.B bpm
[\fIoptions\fR] < \fIfile.raw\fR
.SH DESCRIPTION
The
.B bpm-tools
commands are used to automatically calculate the tempo (in
beats-per-minute) of music, optionally displaying an analysis
and adding it to file 'tags'. The data from these tags can be
especially useful for navigating a music library in DJ software
such as
.B xwax(1).
The
.B bpm
command implements the algorithm on raw data, but
the most commonly used command is
.B bpm-tag.
.SH OPTIONS
Options are described by the commands themselves. Use one of the
following for more information:
.sp
.RS
bpm-tag -h
bpm-graph -h
bpm -h
.RE
.SH EXAMPLES
.P
Tag a file with its tempo:
.sp
.RS
bpm-tag "Daft Punk - Get Lucky.mp3"
.RE
.P
Calculate and display the tempo of a file without modifying it:
.sp
.RS
bpm-tag -f -n "Gwen Guthrie - Padlock.flac"
.RE
.P
Tag a file, with a hint to look for a fast tempo:
.sp
.RS
bpm-tag -m 120 -x 200 "Roni Size - Brown Paper Bag.oga"
.RE
.SH HOMEPAGE
http://www.pogo.org.uk/~mark/bpm-tools/
.SH AUTHOR
Mark Hills <mark@xwax.org>

7
bpm.c
View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2012 Mark Hills <mark@xwax.org>
* Copyright (C) 2013 Mark Hills <mark@xwax.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -25,7 +25,7 @@
#include <sysexits.h>
#include <unistd.h>
#define BANNER "bpm (C) Copyright 2012 Mark Hills <mark@xwax.org>"
#define BANNER "bpm (C) Copyright 2013 Mark Hills <mark@xwax.org>"
#define NAME "bpm"
#define RATE 44100 /* of input data */
@ -141,6 +141,7 @@ double scan_for_bpm(float nrg[], size_t len,
step = (slowest - fastest) / steps;
height = INFINITY;
trough = NAN;
for (interval = fastest; interval <= slowest; interval += step) {
double t;
@ -186,7 +187,7 @@ void usage(FILE *f)
RATE, RATE);
fprintf(f, "To view autodifference or energy data:\n"
" $ sox [...] | ./tempo -g file.dat\n"
" $ sox [...] | " NAME " -g file.dat\n"
" $ gnuplot\n"
" gnuplot> plot \"file.dat\"\n\n");
}