Пример #1
0
def main(mf_name):
    coll = mar_collection.MarCollection(mf_name)
    filenames = coll.get_filenames()

    bpm_mf_name = os.path.basename(mf_name)
    bpm_mf_name = bpm_mf_name.replace(".mf", "-echonest_bpm.mf")
    bpm_coll = mar_collection.MarCollection(bpm_mf_name)

    for filename in filenames:
        #print filename
        #continue
        bpm = echonest_upload(filename)
        bpm_coll.set_item(filename, bpm)

    bpm_coll.write()
Пример #2
0
def scheirer_collection(queue, datum, detected_mf_template):
    mf_filename = datum[0]
    output_dir = datum[1]
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)

    mf_basename = os.path.basename(
        os.path.splitext(mf_filename)[0])
    dirname = os.path.join(output_dir, mf_basename)
    if not os.path.exists(dirname):
        os.makedirs(dirname)
    os.chdir(dirname)

    detected_mf_filename = '%s-%s.mf' % (mf_basename, detected_mf_template)
    out = open(detected_mf_filename, 'w')
    coll = mar_collection.MarCollection(mf_filename)
    problems = 0
    for audio_filename in coll.get_filenames():
        bpm = single_file_scheirer(
            audio_filename)
        if bpm < 0:
            problems += 1
        out.write("%s\t%s\n" % (audio_filename, bpm))
    out.close()
    
    ### generate a wrong.mf for each collection
    cmd = "tempo -pi %s -m PREDICTED %s" % (
        detected_mf_filename, mf_filename)
    subprocess.check_call(cmd, shell=True)

    queue.put( (mf_filename, problems) )
Пример #3
0
def process_mfs(ground_mf, detected_mf, limit=None):
    # load ground truth
    ground_coll = mar_collection.MarCollection(ground_mf)
    ground_bpms = {}
    for dat in ground_coll.data:
        filename = dat[0]
        bpm_ground = float(dat[1])
        ground_bpms[filename] = bpm_ground

    user_coll = mar_collection.MarCollection(detected_mf)
    good = 0
    i = 0
    for dat in user_coll.data:
        #for dat in user_coll.data[:5]:
        filename = dat[0]
        cand_bpms = dat[1]
        bpm_ground = ground_bpms[filename]
        if "," in cand_bpms:
            cand_bpms = [float(a) for a in cand_bpms.split(',')]
        correct = False
        if limit is not None and limit is not 0:
            cand_bpms = cand_bpms[:limit]

        if limit == 0:
            for bpm_detected in cand_bpms[:1]:
                corr = exact_accuracy(bpm_detected, bpm_ground)
                if corr:
                    correct = True
            if correct:
                good += 1
            i += 1
        else:
            for bpm_detected in cand_bpms:
                corr = extended_harmonic_accuracy(bpm_detected, bpm_ground)
                if corr:
                    correct = True
            if correct:
                good += 1
            i += 1
        #print cand_bpms
    #print "Accuracy: %.2f (%i/%i)" % (100*float(good) / i, good, i)
    accuracy = 100 * float(good) / len(user_coll.data)
    return accuracy
Пример #4
0
def bpm_of_mf(defs, mf_filename, print_info=False):
    coll = mar_collection.MarCollection(mf_filename)
    new_filename = os.path.basename(mf_filename[:-3] + "-my-%i-%i.mf") % (
        defs.OPTIONS_ONSET, defs.OPTIONS_BH)
    newer = mar_collection.MarCollection(new_filename)
    #out = open('detailed-cands.txt', 'w')
    num_files = len(coll.data)
    i = 0
    good = 0
    for dat in coll.data:
        filename = dat[0]
        bpm_ground = float(dat[1])
        #print filename
        bpm_detect, cands = bpm_of_file(defs, filename)
        #out.write("%s\t%s\n" % (filename, cands))
        bpm_label = str(bpm_detect)
        #bpm_label = ','.join([str("%.3f") % f for f in cands])
        #print filename
        #print cands
        #print bpm_label
        newer.set_item(filename, bpm_label)
        i += 1
        #print "%i / %i" % (i, num_files)
        #acc = evaluate_bpms.extended_harmonic_accuracy(bpm_detect, bpm_ground)
        acc = evaluate_bpms.major_extended_harmonic_accuracy(
            bpm_detect, bpm_ground)
        if acc:
            good += 1
        accuracy = 100 * float(good) / i
        if print_info:
            print "Accuracy: %.2f (%i/%i)" % (accuracy, good, i),
            if not acc:
                print "\tground: %.2f\tdetected: %.2f" % (bpm_ground,
                                                          bpm_detect),
                print filename
            print

    newer.write()
    #out.close()

    return accuracy
def main(mf_name):
    try:
        _ = os.environ["ECHO_NEST_API_KEY"]
    except:
        print "Need echonest key!  you must run:"
        print "  export ECHO_NEST_API_KEY="
        exit(1)
    coll = mar_collection.MarCollection(mf_name)
    if PROCESS_PROBLEMS:
        filenames_z = coll.get_filenames_matching_label("0")
        filenames_zp = coll.get_filenames_matching_label("0.0")
        filenames = filenames_z + filenames_zp
    else:
        filenames = coll.get_filenames()

    id_mf_name = os.path.basename(mf_name)
    id_mf_name = id_mf_name.replace(".mf", "-echonest_id.mf")
    id_coll = mar_collection.MarCollection(id_mf_name)
    bpm_mf_name = os.path.basename(mf_name)
    bpm_mf_name = bpm_mf_name.replace(".mf", "-echonest_bpm.mf")
    bpm_coll = mar_collection.MarCollection(bpm_mf_name)

    problems = []
    for filename in filenames:
        #print filename
        #continue
        echonest_id, bpm = echonest_upload(filename)
        id_coll.set_item(filename, echonest_id)
        bpm_coll.set_item(filename, bpm)
        if bpm is 0:
            problems.append(filename)

    id_coll.write()
    bpm_coll.write()

    if len(problems) > 0:
        print "*** problems:", len(problems)
        out = open("problems.mf", 'w')
        for p in problems:
            out.write("%s\n" % p)
        out.close()
Пример #6
0
def vamp_qm_default(queue, datum):
    mf_filename = datum[0]
    output_dir = datum[1]
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)

    mf_basename = os.path.basename(os.path.splitext(mf_filename)[0])
    dirname = os.path.join(output_dir, mf_basename)
    if not os.path.exists(dirname):
        os.makedirs(dirname)
    os.chdir(dirname)

    detected_mf_filename_mean = '%s-qm_default_mean.mf' % (mf_basename)
    detected_mf_filename_median = '%s-qm_default_median.mf' % (mf_basename)
    detected_mf_filename_mode = '%s-qm_default_mode.mf' % (mf_basename)
    out_mean = open(detected_mf_filename_mean, 'w')
    out_median = open(detected_mf_filename_median, 'w')
    out_mode = open(detected_mf_filename_mode, 'w')
    coll = mar_collection.MarCollection(mf_filename)
    problems = 0
    for audio_filename in coll.get_filenames():
        result_filename = single_file_generate(audio_filename, dirname)
        bpm_mean, bpm_median, bpm_mode = single_file_evaluate_mean_median(
            audio_filename, result_filename)
        if bpm_mean < 0 or bpm_median < 0:
            problems += 1
        out_mean.write("%s\t%s\n" % (audio_filename, bpm_mean))
        out_median.write("%s\t%s\n" % (audio_filename, bpm_median))
        out_mode.write("%s\t%s\n" % (audio_filename, bpm_mode))
    out_mean.close()
    out_median.close()
    out_mode.close()

    ### generate a wrong.mf for each collection
    cmd = "tempo -pi %s -m PREDICTED %s" % (detected_mf_filename_mean,
                                            mf_filename)
    subprocess.check_call(cmd, shell=True)
    #cmd = "mv %s %s" % ("wrong.mf", "wrong-mean.mf")
    #subprocess.check_call(cmd, shell=True)

    cmd = "tempo -pi %s -m PREDICTED %s" % (detected_mf_filename_median,
                                            mf_filename)
    subprocess.check_call(cmd, shell=True)
    #cmd = "mv %s %s" % ("wrong.mf", "wrong-median.mf")
    #subprocess.check_call(cmd, shell=True)

    cmd = "tempo -pi %s -m PREDICTED %s" % (detected_mf_filename_mode,
                                            mf_filename)
    subprocess.check_call(cmd, shell=True)
    #cmd = "mv %s %s" % ("wrong.mf", "wrong-mode.mf")
    #subprocess.check_call(cmd, shell=True)

    queue.put((mf_filename, problems))
Пример #7
0
#!/usr/bin/env python
import os
import sys
import scipy.io.wavfile
import numpy

import mar_collection

def rewrite_file(filename):
    print "give attention to:\t", filename
    tmp = "tmp_wavfile.wav"
    cmd = "sox \"%s\" -t wavpcm \"%s\"" % (filename, tmp)
    os.system(cmd)
    os.system("cp \"%s\" \"%s\"" % (tmp, filename))



if __name__ == "__main__":
    user_filename = sys.argv[1]
    if user_filename[-3:] == ".mf":
        coll = mar_collection.MarCollection(user_filename)
        for filename in coll.get_filenames():
            try:
                sr, data_unnormalized = scipy.io.wavfile.read(filename)
                maxval = numpy.iinfo(data_unnormalized.dtype).max+1
            except:
                rewrite_file(filename)
            pass


Пример #8
0
    bpm = late_heuristic.late_heuristic(bpm1, bpm2, candidate_bpms[-1][0])

    #bpm_i = summed_beat_histograms.argmax()
    #bpm = histogram_bpms[bpm_i]
    if plot:
        pylab.show()
    #print bpm
    #return bpm, candidate_bpms
    return bpm


if __name__ == "__main__":
    user_filename = sys.argv[1]
    if user_filename[-3:] == ".mf":
        coll = mar_collection.MarCollection(user_filename)
        new_filename = os.path.basename(
            user_filename[:-3] + "-my.mf")
        newer = mar_collection.MarCollection(new_filename)
        #out = open('detailed-cands.txt', 'w')
        num_files = len(coll.data)
        i = 0
        for dat in coll.data:
            filename = dat[0]
            bpm_ground = dat[1]
            #print filename
            bpm_detect = main(filename)
            #out.write("%s\t%s\n" % (filename, cands))
            newer.set_item( filename, bpm_detect)
            i += 1
            print "%i / %i" % (i, num_files)
#!/usr/bin/env python

import sys

import mar_collection

base = sys.argv[1]
new = sys.argv[2]

base_coll = mar_collection.MarCollection(base)
base_coll.merge_mf(new)
base_coll.write()