From e41775afc7df66350e2dacbbf1bf41e909982438 Mon Sep 17 00:00:00 2001 From: Willian Z Date: Mon, 10 Apr 2017 17:31:12 -0400 Subject: [PATCH 01/11] Added Virtual env ignore --- .gitignore | 15 +++++++++++++++ README.md | 6 ++++++ 2 files changed, 21 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b484656 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ + + + +# Virtualenv +# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/ +.Python +[Bb]in +[Ii]nclude +[Ll]ib +[Ll]ib64 +[Ll]ocal +[Ss]cripts +pyvenv.cfg +.venv +pip-selfcheck.json diff --git a/README.md b/README.md index ee438fe..931745f 100644 --- a/README.md +++ b/README.md @@ -10,3 +10,9 @@ Process .wav file to determine the Beats Per Minute. Dependencies: scipy, numpy, pywt, matplotlib +## Installation + +### Activate virtual environment +``` bash +source ./bin/activate +``` From 79f0610e442ac54671bbd536278d782014531741 Mon Sep 17 00:00:00 2001 From: Willian Z Date: Mon, 10 Apr 2017 17:32:53 -0400 Subject: [PATCH 02/11] Ignore data --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b484656..f1ad435 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ - +# Data +data/ # Virtualenv # http://iamzed.com/2009/05/07/a-primer-on-virtualenv/ From 1dfe8d8123663eaa4553972f080a9812467357d4 Mon Sep 17 00:00:00 2001 From: Willian Z Date: Mon, 10 Apr 2017 17:33:50 -0400 Subject: [PATCH 03/11] Fix indexing problem --- bpm_detection/bpm_detection.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bpm_detection/bpm_detection.py b/bpm_detection/bpm_detection.py index 8419d06..7459e07 100644 --- a/bpm_detection/bpm_detection.py +++ b/bpm_detection/bpm_detection.py @@ -50,8 +50,8 @@ def bpm_detector(data,fs): cD_sum = [] levels = 4 max_decimation = 2**(levels-1); - min_ndx = 60./ 220 * (fs/max_decimation) - max_ndx = 60./ 40 * (fs/max_decimation) + min_ndx = int(60./ 220 * (fs/max_decimation)) + max_ndx = int(60./ 40 * (fs/max_decimation)) for loop in range(0,levels): cD = [] From 79e7dface3e5d53a8ca8dc8308127d0091609f7e Mon Sep 17 00:00:00 2001 From: Willian Z Date: Mon, 10 Apr 2017 17:35:54 -0400 Subject: [PATCH 04/11] Add test script --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 931745f..a2dba55 100644 --- a/README.md +++ b/README.md @@ -16,3 +16,8 @@ Dependencies: scipy, numpy, pywt, matplotlib ``` bash source ./bin/activate ``` + +## Test +``` bash +python ./bpm_detection/bpm_detection.py --filename ./data/*.wav +``` From 139cd56f93eb28458af9a604adce72d5a5074218 Mon Sep 17 00:00:00 2001 From: Willian Z Date: Mon, 10 Apr 2017 17:36:22 -0400 Subject: [PATCH 05/11] Move Original readme --- README.md | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index a2dba55..ab907aa 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,6 @@ BPM Detector in Python ======================= -Implementation of a Beats Per Minute (BPM) detection algorithm, as presented in the paper of G. Tzanetakis, G. Essl and P. Cook titled: "Audio Analysis using the Discrete Wavelet Transform". -You can find it here: http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.63.5712 - -Based on the work done in the MATLAB code located at github.com/panagiop/the-BPM-detector-python. - -Process .wav file to determine the Beats Per Minute. - -Dependencies: scipy, numpy, pywt, matplotlib ## Installation @@ -21,3 +13,14 @@ source ./bin/activate ``` bash python ./bpm_detection/bpm_detection.py --filename ./data/*.wav ``` + +## Original Readme +Implementation of a Beats Per Minute (BPM) detection algorithm, as presented in the paper of G. Tzanetakis, G. Essl and P. Cook titled: "Audio Analysis using the Discrete Wavelet Transform". + +You can find it here: http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.63.5712 + +Based on the work done in the MATLAB code located at github.com/panagiop/the-BPM-detector-python. + +Process .wav file to determine the Beats Per Minute. + +Dependencies: scipy, numpy, pywt, matplotlib From 3bfaa5e2d64fdaf9d237b6cd58d9f2d42e799e7f Mon Sep 17 00:00:00 2001 From: Willian Z Date: Mon, 10 Apr 2017 17:44:12 -0400 Subject: [PATCH 06/11] Added Dependency script --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index ab907aa..c9892e5 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,15 @@ BPM Detector in Python source ./bin/activate ``` +### Dependencies +``` bash +pip install --upgrade numpy +pip install --upgrade PyWavelets +pip install --upgrade scipy +pip install --upgrade pdb +pip install --upgrade matplotlib +``` + ## Test ``` bash python ./bpm_detection/bpm_detection.py --filename ./data/*.wav From 443a609467f4f8b5e738e2f41f52087a740376c6 Mon Sep 17 00:00:00 2001 From: Willian Z Date: Mon, 10 Apr 2017 17:52:21 -0400 Subject: [PATCH 07/11] Added help for other audio formats --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index c9892e5..825dafa 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,13 @@ pip install --upgrade matplotlib python ./bpm_detection/bpm_detection.py --filename ./data/*.wav ``` +## Help + +### Converting mp3 +``` bash +mpg123 -w [path/to/original.mp3] [./data/wavfile.wav] +``` + ## Original Readme Implementation of a Beats Per Minute (BPM) detection algorithm, as presented in the paper of G. Tzanetakis, G. Essl and P. Cook titled: "Audio Analysis using the Discrete Wavelet Transform". From 183ea183a24e8c809e8b75c260586ff7f2c5108d Mon Sep 17 00:00:00 2001 From: Willian Z Date: Tue, 11 Apr 2017 09:05:39 -0400 Subject: [PATCH 08/11] Add output timing point --- bpm_detection/bpm_detection.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/bpm_detection/bpm_detection.py b/bpm_detection/bpm_detection.py index 7459e07..5ed8878 100644 --- a/bpm_detection/bpm_detection.py +++ b/bpm_detection/bpm_detection.py @@ -52,7 +52,7 @@ def bpm_detector(data,fs): max_decimation = 2**(levels-1); min_ndx = int(60./ 220 * (fs/max_decimation)) max_ndx = int(60./ 40 * (fs/max_decimation)) - + for loop in range(0,levels): cD = [] # 1) DWT @@ -90,14 +90,13 @@ def bpm_detector(data,fs): midpoint = len(correl) / 2 correl_midpoint_tmp = correl[midpoint:] peak_ndx = peak_detect(correl_midpoint_tmp[min_ndx:max_ndx]); + if len(peak_ndx) > 1: return no_audio_data() peak_ndx_adjusted = peak_ndx[0]+min_ndx; bpm = 60./ peak_ndx_adjusted * (fs/max_decimation) - print bpm - return bpm,correl - + return bpm,correl,peak_ndx[0][0] if __name__ == '__main__': parser = argparse.ArgumentParser(description='Process .wav file to determine the Beats Per Minute.') @@ -112,13 +111,14 @@ def bpm_detector(data,fs): data = [] correl=[] bpm = 0 - n=0; + #n=0; nsamps = len(samps) - window_samps = int(args.window*fs) - samps_ndx = 0; #first sample in window_ndx + window_samps = int(args.window*fs) # second * frame/second = frames + samps_ndx = 0; #first sample in window_ndx # frames max_window_ndx = nsamps / window_samps; bpms = numpy.zeros(max_window_ndx) + last_bpm = None #iterate through all windows for window_ndx in xrange(0,max_window_ndx): @@ -128,15 +128,23 @@ def bpm_detector(data,fs): if not ((len(data) % window_samps) == 0): raise AssertionError( str(len(data) ) ) - bpm, correl_temp = bpm_detector(data,fs) + bpm, correl_temp, first_ndx = bpm_detector(data,fs) if bpm == None: continue + + time_value = 1.0*(samps_ndx+first_ndx)/fs #frames / (frame/second) = second + bpm_value = bpm[0] + if last_bpm != bpm_value: + last_bpm = bpm_value + + print "(Time, BPM): %.2f, %.2f"% (time_value, bpm_value) + bpms[window_ndx] = bpm correl = correl_temp #iterate at the end of the loop samps_ndx = samps_ndx+window_samps; - n=n+1; #counter for debug... + #n=n+1; #counter for debug... bpm = numpy.median(bpms) print 'Completed. Estimated Beats Per Minute:', bpm From e3e61c31d8efc3fbc21f7986a9abe5cbedbac3f9 Mon Sep 17 00:00:00 2001 From: ly976 Date: Fri, 21 Apr 2017 15:48:06 -0400 Subject: [PATCH 09/11] add test --- bpm_detection/bpm_detection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bpm_detection/bpm_detection.py b/bpm_detection/bpm_detection.py index 5ed8878..59fc8f2 100644 --- a/bpm_detection/bpm_detection.py +++ b/bpm_detection/bpm_detection.py @@ -12,7 +12,7 @@ def read_wav(filename): except IOError, e: print e return - + # test eddit # typ = choose_type( wf.getsampwidth() ) #TODO: implement choose_type nsamps = wf.getnframes(); assert(nsamps > 0); From cbe7e7ef4f8fe85716abf0a8bc8da3bbd843c5cf Mon Sep 17 00:00:00 2001 From: nakami Date: Sun, 3 Dec 2017 05:47:01 +0100 Subject: [PATCH 10/11] Refactor dependencies installation; Install via requirements.txt --- README.md | 11 ++++++----- requirements.txt | 5 +++++ 2 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 requirements.txt diff --git a/README.md b/README.md index 825dafa..45de219 100644 --- a/README.md +++ b/README.md @@ -10,12 +10,13 @@ source ./bin/activate ``` ### Dependencies +- numpy +- PyWavelets +- scipy +- pdb +- matplotlib ``` bash -pip install --upgrade numpy -pip install --upgrade PyWavelets -pip install --upgrade scipy -pip install --upgrade pdb -pip install --upgrade matplotlib +pip install -r requirements.txt ``` ## Test diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..528dfc4 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +numpy +PyWavelets +scipy +pdb +matplotlib \ No newline at end of file From e40ae16b25d943123e3d4b2621f64d1c9eb7da2b Mon Sep 17 00:00:00 2001 From: nakami Date: Sun, 3 Dec 2017 06:00:08 +0100 Subject: [PATCH 11/11] Remove pdb from dependencies; part of "The Python Standard Library" --- README.md | 1 - requirements.txt | 1 - 2 files changed, 2 deletions(-) diff --git a/README.md b/README.md index 45de219..eb7553b 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,6 @@ source ./bin/activate - numpy - PyWavelets - scipy -- pdb - matplotlib ``` bash pip install -r requirements.txt diff --git a/requirements.txt b/requirements.txt index 528dfc4..27edeb9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,4 @@ numpy PyWavelets scipy -pdb matplotlib \ No newline at end of file