-
Notifications
You must be signed in to change notification settings - Fork 0
/
stochastic.py
67 lines (47 loc) · 1.66 KB
/
stochastic.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
import click
import os
from subprocess import call
def stoch(filename, outfile, params):
import essentia
import essentia.streaming as es
loader = es.EasyLoader(filename=filename)
fcut = es.FrameCutter(
frameSize=params['frameSize'], hopSize=params['hopSize'])
stochAnal = es.StochasticModelAnal(
fftSize=params['frameSize'],
hopSize=params['hopSize'],
stocf=params['stocf'])
stochSynth = es.StochasticModelSynth(
fftSize=params['frameSize'],
hopSize=params['hopSize'],
stocf=params['stocf'])
pool = essentia.Pool()
loader.audio >> fcut.signal
fcut.frame >> stochAnal.frame
stochAnal.stocenv >> stochSynth.stocenv
stochSynth.frame >> (pool, 'frames')
# do the processing
essentia.run(loader)
outaudio = pool['frames'].flatten()
outvector = es.VectorInput(outaudio)
awrite = es.MonoWriter(filename=outfile)
outvector.data >> awrite.audio
essentia.run(outvector)
@click.command()
@click.argument('filename', type=click.Path(True))
@click.option(
'--framesize', default=2048, help='framesize power of 2', type=int)
@click.option('--hopsize', default=512, help='hopsize', type=int)
@click.option('--stocf', default=0.1, help='stochastic factor', type=float)
def cli(filename, framesize, hopsize, stocf):
params = {'frameSize': framesize, 'hopSize': hopsize, 'stocf': stocf}
outfile = os.path.join(
os.path.dirname('.'),
'snd',
os.path.splitext(os.path.basename(filename))[0] + '-stoch.wav')
# process
stoch(filename, outfile, params)
# listen
call(['afplay', outfile])
if __name__ == '__main__':
cli()