pyACA: Documentation 0.3.1
Source Code for Audio Content Analysis
Loading...
Searching...
No Matches
Functions | Variables
pyACA.computeBeatHisto Namespace Reference

Functions

 computeBeatHisto (x, f_s, cMethod='FFT', afWindow=None, iBlockLength=1024, iHopLength=8)
 computes a simple beat histogram
 
 computeBeatHistoCl (cInPath, cOutPath)
 

Variables

 parser = argparse.ArgumentParser(description='Compute simple beat histogram of wav file')
 
 metavar
 
 required
 
 help
 
 args = parser.parse_args()
 
 cInPath = args.infile
 
 cOutPath = args.outfile
 

Function Documentation

◆ computeBeatHisto()

computeBeatHisto ( x,
f_s,
cMethod = 'FFT',
afWindow = None,
iBlockLength = 1024,
iHopLength = 8 )

computes a simple beat histogram

Parameters
xarray with floating point audio data (dimension samples x channels)
f_ssample rate of audio data
cMethodmethod of beat histogram computation ('Corr' or 'FFT'(default))
afWindowFFT window of length iBlockLength (Hann will be used if 'None')
iBlockLengthinternal block length (default: 1024 samples)
iHopLengthinternal hop length (default: 8 samples)
Returns
T: beat histogram
Bpm: BPM axis ticks

Definition at line 23 of file computeBeatHisto.py.

23def computeBeatHisto(x, f_s, cMethod='FFT', afWindow=None, iBlockLength=1024, iHopLength=8):
24 # compute window function for FFT
25 if afWindow is None:
26 afWindow = ToolComputeHann(iBlockLength)
27
28 assert (afWindow.shape[0] == iBlockLength), "parameter error: invalid window dimension"
29
30 # pre-processing
31 x = ToolPreprocAudio(x)
32
33 # novelty function
34 [d, t, peaks] = computeNoveltyFunction('Flux', x, f_s, afWindow, iBlockLength, iHopLength)
35
36 if cMethod == 'Corr':
37 # compute autocorrelation of result
38 r_dd = np.correlate(d, d, "full") / np.dot(d, d)
39 r_dd = r_dd[np.arange(d.shape[0], r_dd.size)]
40
41 Bpm = np.flip(60 / t[np.arange(1, t.shape[0])])
42 T = np.flip(r_dd)
43
44 elif cMethod == 'FFT':
45 # compute the magnitude spectrum of result
46 iHistoLength = 65536
47 afWindow = np.zeros(2*iHistoLength)
48 afWindow[np.arange(0, iHistoLength)] = ToolComputeHann(iHistoLength)
49 f_s = f_s / iHopLength
50 if len(d) < 2 * iHistoLength:
51 d = [d, np.zeros([1, 2 * iHistoLength - len(d)])]
52
53 [D, f, t] = computeSpectrogram(d, f_s, afWindow, 2*iHistoLength, iHistoLength/4)
54
55 T = D.mean(axis=1, keepdims=True)
56
57 # restrict Bpm range
58 Bpm = f * 60
59 lIdx = np.argwhere(Bpm < 30)[-1]
60 hIdx = np.argwhere(Bpm > 200)[0]
61 T = T[np.arange(lIdx, hIdx)]
62 Bpm = Bpm[np.arange(lIdx, hIdx)]
63 else:
64 T = 0
65 Bpm = 0
66
67 return T, Bpm
68
69

◆ computeBeatHistoCl()

computeBeatHistoCl ( cInPath,
cOutPath )

Definition at line 70 of file computeBeatHisto.py.

70def computeBeatHistoCl(cInPath, cOutPath):
71 [f_s, afAudioData] = ToolReadAudio(cInPath)
72
73 [T, Bpm] = computeBeatHisto(afAudioData, f_s)
74
75 result = np.vstack((T, Bpm))
76
77 np.savetxt(cOutPath, result)
78
79

Variable Documentation

◆ args

args = parser.parse_args()

Definition at line 89 of file computeBeatHisto.py.

◆ cInPath

str cInPath = args.infile

Definition at line 90 of file computeBeatHisto.py.

◆ cOutPath

str cOutPath = args.outfile

Definition at line 91 of file computeBeatHisto.py.

◆ help

help

Definition at line 85 of file computeBeatHisto.py.

◆ metavar

metavar

Definition at line 84 of file computeBeatHisto.py.

◆ parser

parser = argparse.ArgumentParser(description='Compute simple beat histogram of wav file')

Definition at line 83 of file computeBeatHisto.py.

◆ required

required

Definition at line 84 of file computeBeatHisto.py.