예제 #1
0
def computeNoveltyCurve(filename, pool):
    loader = EasyLoader(filename=filename,
                        sampleRate=pool['samplerate'],
                        startTime=STARTTIME, endTime=ENDTIME,
                        downmix=pool['downmix'])
    fc     = FrameCutter(frameSize=int(pool['framesize']),
                         silentFrames ='noise',
                         hopSize=int(pool['hopsize']),
                         startFromZero=False)
    window = Windowing(type=pool['window'],
                       zeroPhase=False)
    #freqBands = FrequencyBands(frequencyBands=EqBands, sampleRate=pool['samplerate'])
    freqBands = FrequencyBands(sampleRate=pool['samplerate'])
    spec = Spectrum()
    hfc = HFC()

    loader.audio >> fc.signal
    fc.frame >> window.frame >> spec.frame
    spec.spectrum >> freqBands.spectrum
    spec.spectrum >> hfc.spectrum
    freqBands.bands >> (pool, 'frequency_bands')
    hfc.hfc >> (pool, 'hfc')
    essentia.run(loader)

    pool.set('size', loader.audio.totalProduced())
    pool.set('length', pool['size']/pool['samplerate'])

    # compute a weighting curve that is according to frequency bands:
    frequencyBands = pool['frequency_bands']
    nFrames = len(frequencyBands)
    weightCurve= np.sum(frequencyBands, axis=0)
    weightCurve = [val/float(nFrames) for val in weightCurve]

    weightCurve = essentia.normalize(weightCurve)
    #pyplot.plot(weightCurve)
    #pyplot.show()


    noveltyCurve = std.NoveltyCurve(frameRate=pool['framerate'],
                                    weightCurveType=pool['weight'],
                                    weightCurve=weightCurve,
                                    normalize=False)(frequencyBands)
    #for x in noveltyCurve: pool.add('novelty_curve', x)
    #return

    # derivative of hfc seems to help in finding more precise beats...
    hfc = std.MovingAverage(size=int(0.1*pool['framerate']))(pool['hfc'])

    hfc = normalize(hfc)
    noveltyCurve = normalize(noveltyCurve)
    #noveltyCurve = essentia.normalize(noveltyCurve)
    dhfc = derivative(hfc)
    print max(hfc), max(noveltyCurve)
    for i, val in enumerate(dhfc):
        if val< 0: continue
        noveltyCurve[i] += 0.1*val

    # low pass filter novelty curve:
    env = std.Envelope(attackTime=0.001*pool['framerate'],
                       releaseTime=0.001*pool['framerate'])(noveltyCurve)

    # apply median filter:
    windowSize = 60./560.*pool['framerate'] #samples
    size = len(env)
    filtered = zeros(size, dtype='f4')
    for i in range(size):
        start = i-windowSize
        if start < 0: start = 0
        end = start + windowSize
        if end > size:
            end = size
            start = size-windowSize
        window = env[start:end]
        filtered[i] = env[i] - np.median(window) #max(np.median(window), np.mean(window))
        if filtered[i] < 0: filtered[i] = 0

    #pyplot.subplot(311)
    #pyplot.plot(noveltyCurve)
    #pyplot.subplot(312)
    #pyplot.plot(env, 'r')
    #pyplot.subplot(313)
    #pyplot.plot(filtered, 'g')
    #pyplot.show()

    #for x in noveltyCurve: pool.add('novelty_curve', x)
    #for x in filtered: pool.add('novelty_curve', x)
    #filtered = normalize(filtered)
    pool.set('novelty_curve', filtered)
    pool.set('original_novelty_curve', noveltyCurve)
예제 #2
0
def computeNoveltyCurve(filename, pool):
    loader = EasyLoader(filename=filename,
                        sampleRate=pool['samplerate'],
                        startTime=STARTTIME,
                        endTime=ENDTIME,
                        downmix=pool['downmix'])
    fc = FrameCutter(frameSize=int(pool['framesize']),
                     silentFrames='noise',
                     hopSize=int(pool['hopsize']),
                     startFromZero=False)
    window = Windowing(type=pool['window'], zeroPhase=False)
    #freqBands = FrequencyBands(frequencyBands=EqBands, sampleRate=pool['samplerate'])
    freqBands = FrequencyBands(sampleRate=pool['samplerate'])
    spec = Spectrum()
    hfc = HFC()

    loader.audio >> fc.signal
    fc.frame >> window.frame >> spec.frame
    spec.spectrum >> freqBands.spectrum
    spec.spectrum >> hfc.spectrum
    freqBands.bands >> (pool, 'frequency_bands')
    hfc.hfc >> (pool, 'hfc')
    essentia.run(loader)

    pool.set('size', loader.audio.totalProduced())
    pool.set('length', pool['size'] / pool['samplerate'])

    # compute a weighting curve that is according to frequency bands:
    frequencyBands = pool['frequency_bands']
    nFrames = len(frequencyBands)
    weightCurve = np.sum(frequencyBands, axis=0)
    weightCurve = [val / float(nFrames) for val in weightCurve]

    weightCurve = essentia.normalize(weightCurve)
    #pyplot.plot(weightCurve)
    #pyplot.show()

    noveltyCurve = std.NoveltyCurve(frameRate=pool['framerate'],
                                    weightCurveType=pool['weight'],
                                    weightCurve=weightCurve)(frequencyBands)
    #for x in noveltyCurve: pool.add('novelty_curve', x)
    #return

    # derivative of hfc seems to help in finding more precise beats...
    hfc = essentia.normalize(pool['hfc'])
    dhfc = essentia.derivative(hfc)
    for i, val in enumerate(dhfc):
        if val < 0: continue
        noveltyCurve[i] += val

    # low pass filter novelty curve:
    env = std.Envelope(attackTime=2. / pool['framerate'],
                       releaseTime=2. / pool['framerate'])(noveltyCurve)

    # apply median filter:
    windowSize = 8  #samples
    size = len(env)
    filtered = zeros(size)
    for i in range(size):
        start = i - windowSize
        if start < 0: start = 0
        end = start + windowSize
        if end > size:
            end = size
            start = size - windowSize
        filtered[i] = env[i] - np.median(env[start:end])
        if filtered[i] < 0: filtered[i] = 0

    #pyplot.subplot(311)
    #pyplot.plot(noveltyCurve)
    #pyplot.subplot(312)
    #pyplot.plot(env, 'r')
    #pyplot.subplot(313)
    #pyplot.plot(filtered, 'g')
    #pyplot.show()

    #for x in noveltyCurve: pool.add('novelty_curve', x)
    for x in filtered:
        pool.add('novelty_curve', x)