Setup

Look nice plotting:


In [1]:
## web graphics
%matplotlib inline
## interactive graphics/
#%matplotlib notebook
%config InlineBackend.figure_format = 'png'

science libraries (using autograd instead of tensorflow for easy prototyping)


In [6]:
import autograd.numpy as np
import autograd.scipy as sp
from autograd import grad
from autograd.util import flatten_func
import seaborn as sns
import librosa
from importlib import reload
import matplotlib.pyplot as plt
from librosa.display import specshow
# display more of the array
np.set_printoptions(edgeitems=5)
from librosa.display import waveplot
from pathlib import Path
import src.numpyjson as npjson
dumps = reload(npjson).dumps

#runs arbitrary javascript, client-side
from IPython.display import Javascript

In [12]:
import src.danscriptors.js_play as js_play
js_play = reload(js_play)
js_play.init()


Out[12]:

Doing things


In [11]:
js_play.load('samples/clarinet.mp3')


Out[11]:

In [5]:
import src.danscriptors.array_ops as array_ops
import src.danscriptors.analysis as analysis
array_ops = reload(array_ops)
analysis = reload(analysis)
source_features = analysis.harmonic_index('samples/clarinet.mp3', debug=True, cached=False)


<matplotlib.figure.Figure at 0x10f36bb38>

In [6]:
plt.plot(source_features['harm_rms'].ravel());



In [7]:
k=500
target_features = dict(
    rms=source_features['rms'][:, k],
    peak_f=source_features['peak_f'][:, k],
    peak_power=source_features['peak_power'][:, k],
)

In [8]:
target_features


Out[8]:
{'peak_f': array([ 2347.95336914,  2056.60424805,  1763.6583252 ,  1174.62011719,
          881.91387939,   293.17218018,     0.        ,     0.        ,
            0.        ,     0.        ,     0.        ,     0.        ,
            0.        ,     0.        ,     0.        ,     0.        ], dtype=float32),
 'peak_power': array([   545.89324951,   1182.26416016,    695.11029053,   1789.32507324,
         44836.06640625,   4432.76367188,      0.        ,      0.        ,
             0.        ,      0.        ,      0.        ,      0.        ,
             0.        ,      0.        ,      0.        ,      0.        ], dtype=float32),
 'rms': array([ 6.3510747], dtype=float32)}

In [25]:



Out[25]:
'{"gain": [0.0, 0.0, 0.0, 0.0, 0.0, 0.3950620131106108, 0.0, 0.3539265348793178], "start_sample": [850944, 977920, 960512, 520192, 13312, 731136, 576512, 620544], "rate": [1.08823364228531, 1.0761055571224523, 1.0251383426629188, 2.3896370547510872, 1.0037029391578214, 1.377979731634264, 1.012015946398908, 4.9797203174694085], "start_time": [19.29578231292517, 22.175056689342405, 21.78031746031746, 11.795736961451247, 0.301859410430839, 16.579047619047618, 13.072834467120181, 14.071292517006803], "start_frame": [829, 953, 936, 506, 11, 712, 561, 604]}'

In [29]:
import src.danscriptors.resynthesis as resynthesis
resynthesis = reload(resynthesis)
optimum = resynthesis.harmonic_synthesis(source_features, target_features)
print(optimum)
dumps(optimum)


{'gain': array([ 0.        ,  0.        ,  0.        ,  0.6630733 ,  0.53931284,
        0.        ,  0.        ,  0.        ]), 'start_sample': array([ 900096, 1046528,  881664,  209920,  431104,  549888,  543744,
       1033216]), 'rate': array([ 1.00057572,  1.00151892,  1.00076543,  1.24657211,  1.15257936,
        1.00333286,  1.00712107,  1.00535239]), 'start_time': array([ 20.41034014,  23.73079365,  19.99238095,   4.7600907 ,
         9.77560091,  12.46911565,  12.32979592,  23.42893424]), 'start_frame': array([ 877, 1020,  859,  203,  419,  535,  529, 1007])}
Out[29]:
'{"gain": [0.0, 0.0, 0.0, 0.6630732965887283, 0.5393128418502862, 0.0, 0.0, 0.0], "start_sample": [900096, 1046528, 881664, 209920, 431104, 549888, 543744, 1033216], "rate": [1.000575723591867, 1.001518924573476, 1.0007654286138574, 1.246572114063388, 1.152579363157166, 1.0033328585017602, 1.0071210698607975, 1.005352391088493], "start_time": [20.410340136054423, 23.73079365079365, 19.99238095238095, 4.760090702947846, 9.775600907029478, 12.469115646258503, 12.329795918367347, 23.42893424036281], "start_frame": [877, 1020, 859, 203, 419, 535, 529, 1007]}'

In [30]:
import src.danscriptors.resynthesis as resynthesis
resynthesis = reload(resynthesis)
optimum = resynthesis.harmonic_synthesis(source_features, target_features)
print(optimum)
import src.danscriptors.sc_play as sc_play
sc_play = reload(sc_play)
sc_play.file(str(Path('samples/clarinet.mp3').resolve()))
sc_play.note(**optimum)


{'rate': array([ 1.00057626,  1.00127917,  1.00019046,  0.99735078,  0.99545644,
        1.0814498 ,  1.00238893,  1.00334784]), 'start_sample': array([ 560128,  541696, 1091584,  155648,  258048,  339968,  292864,
        510976]), 'start_time': array([ 12.70131519,  12.28335601,  24.75247166,   3.52943311,
         5.85142857,   7.70902494,   6.64090703,  11.58675737]), 'gain': array([ 0.1454807 ,  0.15893987,  0.14355712,  0.5204893 ,  0.19029164,
        0.70515825,  0.17227941,  0.28286225]), 'start_frame': array([ 545,  527, 1064,  150,  250,  330,  284,  497])}

In [31]:
optimum = resynthesis.harmonic_synthesis(source_features, target_features)
# sc_play.file(str(Path('samples/clarinet.mp3').resolve()))
sc_play.note(**optimum)

In [32]:
plt.plot((source_features['harm_rms']/source_features['rms']).ravel()); # noisiness



In [ ]: