-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsong-PCset.py
89 lines (71 loc) · 2.64 KB
/
song-PCset.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/local/bin/python
# -*- coding: UTF-8 -*-
import sys
import numpy as np
from matplotlib import pyplot as plt
import essentia.standard as esst
filename = sys.argv[1]
#filename = '/Users/angel/Datasets/ShaatSongs/Radiohead - Idioteque.mp3'
filename = '/Users/angel/Desktop/A-E-C#.wav'
samplerate = 44100 # try with different sampling rates!
framesize = 4096
hopsize = framesize
minfreq = 32.3
maxfreq = 3720
maxpeaks = 3
magthres = 10 # independent from input units! antes tenía 90
absmt = abs(magthres)
orderby = 'frequency'
weight = 'none' # string ∈ {none,cosine,squaredCosine}
partials = 0
bandpreset = False
normalize = False
""" DSP: FrameGenerator -> Windowing -> Spectrum -> Spectral Peaks -> HPCP """
# window type = {hamming,hann,triangular,square,blackmanharris62,blackmanharris70,blackmanharris74,blackmanharris92}
# perhaps HERE convert linear units to Db's??
loader = esst.MonoLoader(filename=filename,
sampleRate=samplerate)
window = esst.Windowing(type='blackmanharris92',
size=framesize)
rfft = esst.Spectrum(size=framesize)
peaks = esst.SpectralPeaks(minFrequency=minfreq,
maxFrequency=maxfreq,
maxPeaks=maxpeaks,
magnitudeThreshold=magthres,
sampleRate=samplerate,
orderBy=orderby)
hpcp = esst.HPCP(bandPreset=bandpreset,
harmonics=partials,
normalized=normalize,
minFrequency=minfreq,
maxFrequency=maxfreq,
sampleRate=samplerate,
weightType=weight)
audio = loader()
peakF = []
peakA = []
chroma = []
absmt = abs(magthres)
for frame in esst.FrameGenerator(audio, frameSize=framesize, hopSize=hopsize):
p1, p2 = peaks(92+(8.685889638065209 * np.log(0.000000000001+rfft(window(frame)))))
# p1, p2 = peaks(rfft(window(frame)))
peakF.append(p1)
peakA.append(p2)
chroma.append(hpcp(p1,p2))
"""
# PLOTTING THE CHROMAGRAM
chroma = np.array(chroma).T
plt.imshow(chroma, aspect='auto', origin='lower', interpolation='nearest')
plt.show()
chroma = np.array(chroma).T
"""
# RAW STRATEGY #1: MEAN OF ALL THE CHROMA CLASSES INTO A SINGLE 12-D VECTOR
# ==========================================================================
suma = [0] * 12
for vector in chroma:
suma = np.add(suma,vector)
suma = np.divide(suma,np.max(suma))
plt.bar(range(12), suma, width=0.8)
plt.title('HPCP')
plt.xticks(np.add(range(12), 0.4), ('A', 'Bb', 'B', 'C', 'C#', 'D', 'Eb', 'E', 'F', 'F#', 'G', 'Ab'))
plt.show()