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

Functions

 computeNoveltyFunction (cNoveltyName, x, f_s, afWindow=None, iBlockLength=4096, iHopLength=512)
 computes the novelty function for onset detection supported novelty measures are: 'Flux', 'Laroche', 'Hainsworth'
 
 computeNoveltyFunctionCl (cPath, cNoveltyName)
 main
 

Variables

 parser = argparse.ArgumentParser(description='Compute key of wav file')
 
 metavar
 
 required
 
 help
 
 args = parser.parse_args()
 
 cInPath = args.infile
 
 cNoveltyName = args.noveltyname
 
 bPlotOutput = args.plotoutput
 

Function Documentation

◆ computeNoveltyFunction()

computeNoveltyFunction ( cNoveltyName,
x,
f_s,
afWindow = None,
iBlockLength = 4096,
iHopLength = 512 )

computes the novelty function for onset detection supported novelty measures are: 'Flux', 'Laroche', 'Hainsworth'

Parameters
cNoveltyNamename of the novelty measure
xarray with floating point audio data (dimension samples x channels)
f_ssample rate of audio data
afWindowFFT window of length iBlockLength (default: hann), can be [] empty
iBlockLengthinternal block length (default: 4096 samples)
iHopLengthinternal hop length (default: 2048 samples)
Returns
d: novelty function
t: time stamps
iPeaks: indices of picked onset times

Definition at line 32 of file computeNoveltyFunction.py.

32def computeNoveltyFunction(cNoveltyName, x, f_s, afWindow=None, iBlockLength=4096, iHopLength=512):
33
34 # compute window function for FFT
35 if afWindow is None:
36 afWindow = ToolComputeHann(iBlockLength)
37
38 assert(afWindow.shape[0] == iBlockLength), "parameter error: invalid window dimension"
39
40 hNoveltyFunc = getattr(pyACA, "Novelty" + cNoveltyName)
41
42 # lp initialization
43 fLenSmoothLpInS = 0.07
44 fLenThreshLpInS = 0.14
45 iLenSmoothLp = np.max([2, math.ceil(fLenSmoothLpInS * f_s / iHopLength)])
46 iLenThreshLp = np.max([2, math.ceil(fLenThreshLpInS * f_s / iHopLength)])
47
48 # pre-processing
49 x = ToolPreprocAudio(x)
50
51 # in the real world, we would do this block by block...
52 [X, f, t] = computeSpectrogram(x, f_s, None, iBlockLength, iHopLength)
53
54 # novelty function
55 d = hNoveltyFunc(X, f_s)
56
57 # smooth novelty function
58 b = np.ones(iLenSmoothLp) / iLenSmoothLp
59 d = filtfilt(b, 1, d)
60 d[d < 0] = 0
61
62 # compute threshold
63 iLenThreshLp = min(iLenThreshLp, np.floor(len(d)/3))
64 b = np.ones(iLenThreshLp) / iLenThreshLp
65 G_T = .4 * np.mean(d[np.arange(1, d.shape[0])]) + filtfilt(b, 1, d)
66
67 # find local maxima above the threshold
68 iPeaks = find_peaks(d - G_T, height=0)
69
70 return d, t, iPeaks[0]
71
72

◆ computeNoveltyFunctionCl()

computeNoveltyFunctionCl ( cPath,
cNoveltyName )

main

Definition at line 75 of file computeNoveltyFunction.py.

75def computeNoveltyFunctionCl(cPath, cNoveltyName):
76
77 [f_s, x] = ToolReadAudio(cPath)
78 # afAudioData = np.sin(2*np.pi * np.arange(f_s*1)*440./f_s)
79 [d, t, iPeaks] = computeNoveltyFunction(cNoveltyName, x, f_s)
80
81 # plot feature output
82 if bPlotOutput:
83 plt.plot(t, d)
84 return d, t, iPeaks
85
86

Variable Documentation

◆ args

args = parser.parse_args()

Definition at line 99 of file computeNoveltyFunction.py.

◆ bPlotOutput

bool bPlotOutput = args.plotoutput

Definition at line 102 of file computeNoveltyFunction.py.

◆ cInPath

str cInPath = args.infile

Definition at line 100 of file computeNoveltyFunction.py.

◆ cNoveltyName

str cNoveltyName = args.noveltyname

Definition at line 101 of file computeNoveltyFunction.py.

◆ help

help

Definition at line 92 of file computeNoveltyFunction.py.

◆ metavar

metavar

Definition at line 91 of file computeNoveltyFunction.py.

◆ parser

parser = argparse.ArgumentParser(description='Compute key of wav file')

Definition at line 90 of file computeNoveltyFunction.py.

◆ required

required

Definition at line 91 of file computeNoveltyFunction.py.