Compare commits
15 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
e0f5676e48 | |
|
|
913728bf97 | |
|
|
53601f6b3a | |
|
|
795c8ea75b | |
|
|
a0bd601464 | |
|
|
31b1475995 | |
|
|
57a2f9e940 | |
|
|
edca668e4d | |
|
|
f68ec6eff2 | |
|
|
015bbd47aa | |
|
|
b3cea166c1 | |
|
|
8c0ce81289 | |
|
|
5c4b3997ed | |
|
|
f48f3d0ec8 | |
|
|
12e1bf0995 |
16
Makefile
16
Makefile
|
|
@ -1,15 +1,29 @@
|
|||
-include .config
|
||||
|
||||
PREFIX ?= /usr/local
|
||||
INSTALL ?= install
|
||||
|
||||
BINDIR ?= $(PREFIX)/bin
|
||||
MANDIR ?= $(PREFIX)/share/man
|
||||
|
||||
CFLAGS ?= -O3
|
||||
|
||||
CFLAGS += -Wall
|
||||
LDLIBS += -lm
|
||||
|
||||
.PHONY: clean dist
|
||||
.PHONY: clean install dist
|
||||
|
||||
bpm: bpm.o
|
||||
|
||||
clean:
|
||||
rm -f bpm *.o
|
||||
|
||||
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
|
||||
V=$$(git describe) && git archive --prefix=bpm-tools-$$V/ HEAD \
|
||||
|
|
|
|||
16
README
16
README
|
|
@ -1,9 +1,23 @@
|
|||
bpm-tools: Tempo (Beats Per Minute) analysis tools
|
||||
|
||||
(C) Copyright 2012 Mark Hills <mark@pogo.org.uk>
|
||||
(C) Copyright 2013 Mark Hills <mark@xwax.org>
|
||||
|
||||
See the COPYING file for licensing terms.
|
||||
|
||||
This software is distributed from the following site:
|
||||
|
||||
http://www.pogo.org.uk/~mark/bpm-tools/
|
||||
|
||||
The build is controlled via Makefile variables. In general
|
||||
you should be able to build using:
|
||||
|
||||
$ make
|
||||
$ make install
|
||||
|
||||
To change the target prefix, for example:
|
||||
|
||||
$ make install PREFIX=/opt/bpm-tools
|
||||
|
||||
The Makefile picks up additional variables from a .config file
|
||||
in the source directory. You will prefer to use this if you want
|
||||
to control build flags for testing and debugging.
|
||||
|
|
|
|||
29
bpm-graph
29
bpm-graph
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# Copyright (C) 2012 Mark Hills <mark@pogo.org.uk>
|
||||
# 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"
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
.so man1/bpm-graph.1
|
||||
11
bpm-tag
11
bpm-tag
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# Copyright (C) 2012 Mark Hills <mark@pogo.org.uk>
|
||||
# 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 0.0-beta (C) Copyright 2011 Mark Hills <mark@pogo.org.uk>
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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
7
bpm.c
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2012 Mark Hills <mark@pogo.org.uk>
|
||||
* 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@pogo.org.uk>"
|
||||
#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");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue