Skip to content

Commit

Permalink
in progress: #27
Browse files Browse the repository at this point in the history
  • Loading branch information
rabitt committed Jan 18, 2016
1 parent 0023b07 commit c704cda
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions medleydb/annotate/generate_has_bleed_annotations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"""Script to create stem level has_bleed annotations."""
import argparse
import os
import csv

import numpy as np
import librosa

import medleydb

import matplotlib.pyplot as plt

def make_audio_stack(mtrack, fs=22050):
stems = mtrack.stems
n_stems = len(stems)

print "loading stem 1..."
stem1_audio, fs = librosa.load(stems[1].file_path, fs)
n_samples = len(stem1_audio)

audio_stack = np.zeros((n_stems, n_samples))

for stem_idx in stems.keys():
if stem_idx == 1:
audio_stack[0, :] = stem1_audio
else:
print "loading stem %s..." % stem_idx
audio_path = stems[stem_idx].file_path
audio_stack[stem_idx-1, :], _ = librosa.load(audio_path, fs)

return audio_stack, fs, n_samples


def compute_bleed_estimation_matrix(audio_stack, fs, n_samples):
print "computing svd..."
U, S, V = np.linalg.svd(audio_stack, full_matrices=False)
plt.subplot(2,1,1)
plt.imshow(U, interpolation='nearest')
plt.colorbar()
plt.subplot(2,1,2)
plt.imshow(np.diag(S), interpolation='nearest')
plt.colorbar()
plt.show()

# time_split = 30*fs
# i = 0
# while i < n_samples:
#




def main(args):
mtrack = medleydb.MultiTrack(args.track_id)
audio_stack, fs, n_samples = make_audio_stack(mtrack)
compute_bleed_estimation_matrix(audio_stack, fs, n_samples)
# melody1 = create_melody1_annotation(mtrack)
# melody2 = create_melody2_annotation(mtrack)
# melody3 = create_melody3_annotation(mtrack)
# if args.write_output:
# write_melodies_to_csv(mtrack, melody1, melody2, melody3)


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="")
parser.add_argument("track_id",
type=str,
help="MedleyDB track id. Ex. MusicDelta_Rock")
parser.add_argument("write_output",
type=bool,
default=True,
help="If true, write the output to a file")

main(parser.parse_args())

0 comments on commit c704cda

Please sign in to comment.