예제 #1
0
def pefac(signal, samplerate):
    with Matlab(arguments=('-nodesktop', '-nosplash', '-nojvm', '-singleCompThread'), print_to_stdout=False) as matlab:
        algopath = pathlib.Path(__file__).parents[0] / 'PEFAC'
        matlab.cd(str(algopath))
        f0, time, prob = matlab.fxpefac(signal, float(samplerate), nargout=3)

    return time.ravel(), f0.ravel(), prob.ravel()
예제 #2
0
def rapt(signal, samplerate):
    with Matlab(arguments=('-nodesktop', '-nosplash', '-nojvm', '-singleCompThread'), print_to_stdout=False) as matlab:
        algopath = pathlib.Path(__file__).parents[0] / 'RAPT'
        matlab.cd(str(algopath))
        f0, times = matlab.fxrapt(signal, float(samplerate), 'u', nargout=2)
        f0 = f0.ravel()
        time = numpy.empty(len(f0)*2)
        time[::2] = (times[:,0]-1)/samplerate
        time[1::2] = times[:,1]/samplerate
        f0s = numpy.empty(len(f0)*2)
        f0s[::2] = f0s[1::2] = f0
        p = numpy.ones(len(f0s))
        p[numpy.isnan(f0s)] = 0

    return time, f0s, p
예제 #3
0
def yin(signal, samplerate):
    if samplerate != 16000:
        signal = resampy.resample(signal, samplerate, 16000)
        samplerate = 16000

    tmpfilepath = pathlib.Path.cwd() / (str(uuid.uuid1()) + '.wav')
    try:
        soundfile.write(str(tmpfilepath), signal, samplerate)

        with Matlab(arguments=('-nodesktop', '-nosplash', '-nojvm', '-singleCompThread'), print_to_stdout=False) as matlab:
            algopath = pathlib.Path(__file__).parents[0] / 'YIN'
            matlab.cd(str(algopath))
            struct = matlab.yin(str(tmpfilepath), nargout=1)
    finally:
        if tmpfilepath.exists():
            tmpfilepath.unlink()

    f0 = 440 * 2**struct['f0'].ravel()
    hopsize = struct['hop']
    time = numpy.arange(len(f0))*hopsize/samplerate
    p = numpy.ones(len(f0))

    return time, f0, p
예제 #4
0
def matlab(request):
    matlab = Matlab(arguments=('-nodesktop', '-nosplash', '-nojvm'))
    yield matlab
    del matlab
예제 #5
0
def matlab(request):
    matlab = Matlab(jvm=False)
    yield matlab
    del matlab