BatchCollection.py
def precomputeBatchFeatures(args):
    """
    Precompute all of the features for a file, including
    MFCCs, HPCPs, all beats/tempos at different levels,
    blocked features at different tempo levels, and the
    self-similarity W matrix for each feature.  Save all of
    this to a .mat file
    :param audiofilename: Path to audio file
    :param scratchDir: Path to directory to which to store features
    :param hopSize: Hop size of STFT windows for features
    :param lifterexp: MFCC lifter parameter
    :param Kappa: Kappa for W matrix for similarity fusion
    :param CSMTypes: Dictionary of types of features and
        associated cross-similarity comparisons to do
    :param FeatureParams: Dictionary of parameters for computing
                        features using BlockWindowFeatures.py
    :param TempoLevels: An array of tempo biases.  If this array
        contains a 0, compute Madmom tempos.  Otherwise, do
        dynamic programming beat tracking with that bias
    :param PFeatures: Precomputed features
    """
    (audiofilename, scratchDir, hopSize, Kappa, CSMTypes, FeatureParams, TempoLevels, PFeatures) = args
    tic = time.time()
    filename = getMatFilename(scratchDir, audiofilename)
    if os.path.exists(filename):
        print("Skipping...")
        return
    print("Computing features for %s..."%audiofilename)

    Fs = 22050
    XAudio = np.array([])
    lifterexp = 0.6
    if 'XMFCC' in PFeatures:
        XMFCC = PFeatures['XMFCC']
    else:
        if XAudio.size == 0:
            (XAudio, Fs) = getAudioLibrosa(audiofilename)
            print("Fs = %i"%Fs)
        NMFCC = 20
        if 'NMFCC' in FeatureParams:
            NMFCC = FeatureParams['NMFCC']
        lifterexp = 0.6
        if 'lifterexp' in FeatureParams:
            lifterexp = FeatureParams['lifterexp']
        winSize = Fs/2
        XMFCC = getMFCCsLibrosa(XAudio, Fs, winSize, hopSize, lifterexp = lifterexp, NMFCC = NMFCC)
        #XMFCC = getMFCCsLowMem(XAudio, Fs, winSize, hopSize, lifterexp = lifterexp, NMFCC = NMFCC)['XMFCC']

    if 'XChroma' in PFeatures:
        XChroma = PFeatures['XChroma']
    else:
        if XAudio.size == 0:
            (XAudio, Fs) = getAudioLibrosa(audiofilename)
            print("Fs = %i"%Fs)
        #XChroma = getHPCP(XAudio, Fs, hopSize*4, hopSize, NChromaBins = 12)
        XChroma = getHPCPEssentia(XAudio, Fs, hopSize*4, hopSize, NChromaBins = 12)

    #Computed blocked features at different tempo levels
    winSize = Fs/2
    ret = {'hopSize':hopSize, 'winSize':winSize, 'lifterexp':lifterexp}
    tempos = []
    if 'NTempos' in PFeatures:
        #If tempos have been precomputed, load them in
        NTempos = PFeatures['NTempos']
        for i in range(NTempos):
            ret['tempos%i'%i] = PFeatures['tempos%i'%i]
            ret['beats%i'%i] = PFeatures['beats%i'%i]
            tempos.append(ret['tempos%i'%i])
    else:
        #Otherwise, compute tempos / beat intervals
        tempos = getBatchBeats(TempoLevels, audiofilename, XAudio, Fs, hopSize, ret)
    for tidx in range(len(tempos)):
        tempo = ret['tempos%i'%tidx]
        beats = ret['beats%i'%tidx]
        print("XMFCC.shape = ", XMFCC.shape)
        (Feats, O) = getBlockWindowFeatures((XAudio, Fs, tempo, beats, hopSize, FeatureParams), XMFCC, XChroma)
        ret['ChromaMean%i'%tidx] = O['ChromaMean']

        #Precompute the W for the SSM part for similarity network fusion
        for F in Feats:
            ret['%s%i'%(F, tidx)] = Feats[F]
            SSM = getCSMType(Feats[F], O, Feats[F], O, CSMTypes[F])
            K = int(0.5*Kappa*SSM.shape[0])
            ret['W%s%i'%(F, tidx)] = getW(SSM, K)

    ret['NTempos'] = len(tempos)
    print("%i Unique Tempos"%len(tempos))
    print("Elapsed Time: %g"%(time.time() - tic))
    sio.savemat(filename, ret)

    Precompute all of the features for a file, including
    MFCCs, HPCPs, all beats/tempos at different levels,
    blocked features at different tempo levels, and the
    self-similarity W matrix for each feature.  Save all of
    this to a .mat file
    :param audiofilename: Path to audio file
    :param scratchDir: Path to directory to which to store features
    :param hopSize: Hop size of STFT windows for features
    :param lifterexp: MFCC lifter parameter
    :param Kappa: Kappa for W matrix for similarity fusion
    :param CSMTypes: Dictionary of types of features and
        associated cross-similarity comparisons to do
    :param FeatureParams: Dictionary of parameters for computing
                        features using BlockWindowFeatures.py
    :param TempoLevels: An array of tempo biases.  If this array
        contains a 0, compute Madmom tempos.  Otherwise, do
        dynamic programming beat tracking with that bias
    :param PFeatures: Precomputed features
    
Precompute all of the features for a file, including
MFCCs, HPCPs, all beats/tempos at different levels,
blocked features at different tempo levels, and the
self-similarity W matrix for each feature.  Save all of
this to a .mat file
Precompute all of the features for a file including MFCCs HPCPs all beats / tempos at different levels blocked features at different tempo levels and the self - similarity W matrix for each feature . Save all of this to a . mat file
def precomputeBatchFeatures(args):
    (audiofilename, scratchDir, hopSize, Kappa, CSMTypes, FeatureParams, TempoLevels, PFeatures) = args
    tic = time.time()
    filename = getMatFilename(scratchDir, audiofilename)
    if os.path.exists(filename):
        print("Skipping...")
        return
    print("Computing features for %s..."%audiofilename)
    Fs = 22050
    XAudio = np.array([])
    lifterexp = 0.6
    if 'XMFCC' in PFeatures:
        XMFCC = PFeatures['XMFCC']
    else:
        if XAudio.size == 0:
            (XAudio, Fs) = getAudioLibrosa(audiofilename)
            print("Fs = %i"%Fs)
        NMFCC = 20
        if 'NMFCC' in FeatureParams:
            NMFCC = FeatureParams['NMFCC']
        lifterexp = 0.6
        if 'lifterexp' in FeatureParams:
            lifterexp = FeatureParams['lifterexp']
        winSize = Fs/2
        XMFCC = getMFCCsLibrosa(XAudio, Fs, winSize, hopSize, lifterexp = lifterexp, NMFCC = NMFCC)
    if 'XChroma' in PFeatures:
        XChroma = PFeatures['XChroma']
    else:
        if XAudio.size == 0:
            (XAudio, Fs) = getAudioLibrosa(audiofilename)
            print("Fs = %i"%Fs)
        XChroma = getHPCPEssentia(XAudio, Fs, hopSize*4, hopSize, NChromaBins = 12)
    winSize = Fs/2
    ret = {'hopSize':hopSize, 'winSize':winSize, 'lifterexp':lifterexp}
    tempos = []
    if 'NTempos' in PFeatures:
        NTempos = PFeatures['NTempos']
        for i in range(NTempos):
            ret['tempos%i'%i] = PFeatures['tempos%i'%i]
            ret['beats%i'%i] = PFeatures['beats%i'%i]
            tempos.append(ret['tempos%i'%i])
    else:
        tempos = getBatchBeats(TempoLevels, audiofilename, XAudio, Fs, hopSize, ret)
    for tidx in range(len(tempos)):
        tempo = ret['tempos%i'%tidx]
        beats = ret['beats%i'%tidx]
        print("XMFCC.shape = ", XMFCC.shape)
        (Feats, O) = getBlockWindowFeatures((XAudio, Fs, tempo, beats, hopSize, FeatureParams), XMFCC, XChroma)
        ret['ChromaMean%i'%tidx] = O['ChromaMean']
        for F in Feats:
            ret['%s%i'%(F, tidx)] = Feats[F]
            SSM = getCSMType(Feats[F], O, Feats[F], O, CSMTypes[F])
            K = int(0.5*Kappa*SSM.shape[0])
            ret['W%s%i'%(F, tidx)] = getW(SSM, K)
    ret['NTempos'] = len(tempos)
    print("%i Unique Tempos"%len(tempos))
    print("Elapsed Time: %g"%(time.time() - tic))
    sio.savemat(filename, ret)
def precomputeBatchFeatures ( args ) : ( audiofilename , scratchDir , hopSize , Kappa , CSMTypes , FeatureParams , TempoLevels , PFeatures ) = args tic = time . time ( ) filename = getMatFilename ( scratchDir , audiofilename ) if os . path . exists ( filename ) : print ( "Skipping..." ) return print ( "Computing features for %s..." % audiofilename ) Fs = 22050 XAudio = np . array ( [ ] ) lifterexp = 0.6 if 'XMFCC' in PFeatures : XMFCC = PFeatures [ 'XMFCC' ] else : if XAudio . size == 0 : ( XAudio , Fs ) = getAudioLibrosa ( audiofilename ) print ( "Fs = %i" % Fs ) NMFCC = 20 if 'NMFCC' in FeatureParams : NMFCC = FeatureParams [ 'NMFCC' ] lifterexp = 0.6 if 'lifterexp' in FeatureParams : lifterexp = FeatureParams [ 'lifterexp' ] winSize = Fs / 2 XMFCC = getMFCCsLibrosa ( XAudio , Fs , winSize , hopSize , lifterexp = lifterexp , NMFCC = NMFCC ) if 'XChroma' in PFeatures : XChroma = PFeatures [ 'XChroma' ] else : if XAudio . size == 0 : ( XAudio , Fs ) = getAudioLibrosa ( audiofilename ) print ( "Fs = %i" % Fs ) XChroma = getHPCPEssentia ( XAudio , Fs , hopSize * 4 , hopSize , NChromaBins = 12 ) winSize = Fs / 2 ret = { 'hopSize' : hopSize , 'winSize' : winSize , 'lifterexp' : lifterexp } tempos = [ ] if 'NTempos' in PFeatures : NTempos = PFeatures [ 'NTempos' ] for i in range ( NTempos ) : ret [ 'tempos%i' % i ] = PFeatures [ 'tempos%i' % i ] ret [ 'beats%i' % i ] = PFeatures [ 'beats%i' % i ] tempos . append ( ret [ 'tempos%i' % i ] ) else : tempos = getBatchBeats ( TempoLevels , audiofilename , XAudio , Fs , hopSize , ret ) for tidx in range ( len ( tempos ) ) : tempo = ret [ 'tempos%i' % tidx ] beats = ret [ 'beats%i' % tidx ] print ( "XMFCC.shape = " , XMFCC . shape ) ( Feats , O ) = getBlockWindowFeatures ( ( XAudio , Fs , tempo , beats , hopSize , FeatureParams ) , XMFCC , XChroma ) ret [ 'ChromaMean%i' % tidx ] = O [ 'ChromaMean' ] for F in Feats : ret [ '%s%i' % ( F , tidx ) ] = Feats [ F ] SSM = getCSMType ( Feats [ F ] , O , Feats [ F ] , O , CSMTypes [ F ] ) K = int ( 0.5 * Kappa * SSM . shape [ 0 ] ) ret [ 'W%s%i' % ( F , tidx ) ] = getW ( SSM , K ) ret [ 'NTempos' ] = len ( tempos ) print ( "%i Unique Tempos" % len ( tempos ) ) print ( "Elapsed Time: %g" % ( time . time ( ) - tic ) ) sio . savemat ( filename , ret )
Precompute all of the features for a file, including
MFCCs, HPCPs, all beats/tempos at different levels,
blocked features at different tempo levels, and the
self-similarity W matrix for each feature.
Precompute all of the features for a file including MFCCs HPCPs all beats / tempos at different levels blocked features at different tempo levels and the self - similarity W matrix for each feature .
"""
    Precompute all of the features for a file, including
    MFCCs, HPCPs, all beats/tempos at different levels,
    blocked features at different tempo levels, and the
    self-similarity W matrix for each feature.  Save all of
    this to a .mat file
    :param audiofilename: Path to audio file
    :param scratchDir: Path to directory to which to store features
    :param hopSize: Hop size of STFT windows for features
    :param lifterexp: MFCC lifter parameter
    :param Kappa: Kappa for W matrix for similarity fusion
    :param CSMTypes: Dictionary of types of features and
        associated cross-similarity comparisons to do
    :param FeatureParams: Dictionary of parameters for computing
                        features using BlockWindowFeatures.py
    :param TempoLevels: An array of tempo biases.  If this array
        contains a 0, compute Madmom tempos.  Otherwise, do
        dynamic programming beat tracking with that bias
    :param PFeatures: Precomputed features
    """ #XMFCC = getMFCCsLowMem(XAudio, Fs, winSize, hopSize, lifterexp = lifterexp, NMFCC = NMFCC)['XMFCC'] #XChroma = getHPCP(XAudio, Fs, hopSize*4, hopSize, NChromaBins = 12) #Computed blocked features at different tempo levels #If tempos have been precomputed, load them in #Otherwise, compute tempos / beat intervals #Precompute the W for the SSM part for similarity network fusion
args
audiofilename
Path to audio file
Path to audio file
scratchDir
None
hopSize
Hop size of STFT windows for features
Hop size of STFT windows for features
lifterexp
MFCC lifter parameter
MFCC lifter parameter
Kappa
Kappa for W matrix for similarity fusion
Kappa for W matrix for similarity fusion
CSMTypes
Dictionary of types of features and
associated cross-similarity comparisons to do
Dictionary of types of features and associated cross - similarity comparisons to do
FeatureParams
Dictionary of parameters for computing
features using BlockWindowFeatures.py
Dictionary of parameters for computing features using BlockWindowFeatures . py
TempoLevels
An array of tempo biases.  If this array
contains a 0, compute Madmom tempos.  Otherwise, do
dynamic programming beat tracking with that bias
An array of tempo biases . If this array contains a 0 compute Madmom tempos . Otherwise do dynamic programming beat tracking with that bias
PFeatures
None