示例#1
0
 def test_additional_files(self):
     clean_output()
     mix.mix_multitrack(self.mtrack,
                        OUTPUT_PATH,
                        additional_files=[(self.mtrack.mix_path, 2.1)])
     self.assertTrue(os.path.exists(OUTPUT_PATH))
     clean_output()
示例#2
0
 def test_alt_files(self):
     clean_output()
     mix.mix_multitrack(self.mtrack,
                        OUTPUT_PATH,
                        alternate_files={1: self.mtrack.mix_path})
     self.assertTrue(os.path.exists(OUTPUT_PATH))
     clean_output()
示例#3
0
 def test_alt_weights(self):
     clean_output()
     mix.mix_multitrack(self.mtrack,
                        OUTPUT_PATH,
                        alternate_weights={
                            2: 2.0,
                            4: 0.5
                        })
     self.assertTrue(os.path.exists(OUTPUT_PATH))
     clean_output()
示例#4
0
def remix_drums(mtrack, new_drum, output_path):
    drum_stems = []
    other_stems = []

    # not perfect - doesn't handle more than one drum stems case
    for s in mtrack.stems.values():
        if 'drum set' in s.instrument:
            drum_stems.append(s)
        else:
            other_stems.append(s.stem_idx)

    mix.mix_multitrack(mtrack,
                       output_path,
                       stem_indices=other_stems,
                       additional_files=[(new_drum,
                                          drum_stems[0].mixing_coefficient)])
def make_training_set(output_dir):
    annotations_dir = os.path.join(output_dir, 'annotations')
    audio_dir = os.path.join(output_dir, 'audio')

    if not os.path.exists(annotations_dir):
        os.mkdir(annotations_dir)
    if not os.path.exists(audio_dir):
        os.mkdir(audio_dir)

    mtracks = mdb.load_melody_multitracks()
    for mtrack in mtracks:
        print(mtrack.track_id)

        if mtrack.predominant_stem.instrument not in mix.VOCALS:
            print("no vocals...skipping")
            print("")
            continue

        output_path = os.path.join(audio_dir,
                                   '{}_vocal.wav'.format(mtrack.track_id))
        print([(i, v.instrument) for i, v in mtrack.stems.items()])

        need_remix = False
        stem_indices = mtrack.stems.keys()
        stem_indices.remove(mtrack.predominant_stem.stem_idx)
        for i in stem_indices:
            if mtrack.stems[i].instrument in mix.VOCALS:
                need_remix = True

        if need_remix:
            print("needs remix")
            mix_stems = [
                i for i, v in mtrack.stems.items()
                if v.instrument not in mix.VOCALS
            ]
            mix_stems.append(mtrack.predominant_stem.stem_idx)
            mix.mix_multitrack(mtrack, output_path, stem_indices=mix_stems)
        else:
            print("using orignal mix")
            shutil.copy(mtrack.mix_path, output_path)

        annotation_fpath = os.path.join(annotations_dir,
                                        '{}_vocal.csv'.format(mtrack.track_id))
        shutil.copy(mtrack.melody1_fpath, annotation_fpath)
        print("")
示例#6
0
    def test_one_stem_mix(self):
        clean_output()
        actual_fullpaths, actual_weights = mix.mix_multitrack(self.mtrack,
                                                              OUTPUT_PATH,
                                                              stem_indices=[2])
        self.assertTrue(os.path.exists(OUTPUT_PATH))

        actual_basenames = [os.path.basename(f) for f in actual_fullpaths]
        expected_basenames = ['LizNelson_Rainfall_STEM_02.wav']
        expected_weights = [0.88655832334783]
        self.assertEqual(expected_basenames, actual_basenames)
        self.assertEqual(expected_weights, actual_weights)

        clean_output()
示例#7
0
    def test_defaults(self):
        clean_output()
        actual_fullpaths, actual_weights = mix.mix_multitrack(
            self.mtrack, OUTPUT_PATH)

        self.assertTrue(os.path.exists(OUTPUT_PATH))

        actual_basenames = [os.path.basename(f) for f in actual_fullpaths]
        expected_basenames = [
            'LizNelson_Rainfall_STEM_01.wav', 'LizNelson_Rainfall_STEM_02.wav',
            'LizNelson_Rainfall_STEM_03.wav', 'LizNelson_Rainfall_STEM_04.wav',
            'LizNelson_Rainfall_STEM_05.wav'
        ]
        expected_weights = [
            0.9138225670999782, 0.88655832334783, 0.7820245646673145,
            0.9709353677932278, 0.7734022629465723
        ]
        self.assertEqual(expected_basenames, actual_basenames)
        self.assertEqual(expected_weights, actual_weights)

        clean_output()
示例#8
0
    def test_alt_weights(self):
        clean_output()
        actual_fullpaths, actual_weights = mix.mix_multitrack(
            self.mtrack, OUTPUT_PATH, alternate_weights={
                2: 2.0,
                4: 0.5
            })
        self.assertTrue(os.path.exists(OUTPUT_PATH))

        actual_basenames = [os.path.basename(f) for f in actual_fullpaths]
        expected_basenames = [
            'LizNelson_Rainfall_STEM_01.wav', 'LizNelson_Rainfall_STEM_02.wav',
            'LizNelson_Rainfall_STEM_03.wav', 'LizNelson_Rainfall_STEM_04.wav',
            'LizNelson_Rainfall_STEM_05.wav'
        ]
        expected_weights = [
            0.9138225670999782, 2.0, 0.7820245646673145, 0.5,
            0.7734022629465723
        ]
        self.assertEqual(expected_basenames, actual_basenames)
        self.assertEqual(expected_weights, actual_weights)

        clean_output()
示例#9
0
 def test_one_stem_mix(self):
     clean_output()
     mix.mix_multitrack(self.mtrack, OUTPUT_PATH, stem_indices=[2])
     self.assertTrue(os.path.exists(OUTPUT_PATH))
     clean_output()
示例#10
0
 def test_defaults(self):
     clean_output()
     mix.mix_multitrack(self.mtrack, OUTPUT_PATH)
     self.assertTrue(os.path.exists(OUTPUT_PATH))
     clean_output()
def create_mixes(mtrack, mix_path, mix_path_noguitar, mix_path_nosynth,
                 stem_indices, stem_indices_guitar, stem_indices_piano,
                 altfiles):
    """Render artificial mixes to `mix_path', `mix_path_noguitar', and
    `mix_path_nosynth'.

    Parameters
    ----------
    mtrack : MultiTrack
        medleydb MultiTrack object
    mix_path : str
        Path to save full multif0 mix
    mix_path_noguitar : str
        Path to save no guitar multif0 mix
    mix_path_nosynth : str
        Path to save no synthesized stems multif0 mix
    stem_indices : list
        List of stems to include in the full mix
    stem_indices_guitar : list
        List of guitar stems
    stem_indices_piano : list
        List of piano stems
    altfiles : dict
        Dictionary of replacement files mapping stem id to new path.

    Returns
    -------
    mix_filepaths : list
        List of filepaths included in the full mix
    mix_noguitar_filepaths : list
        List of filepaths included in the no guitar mix
    mix_nosynth_filepaths : list
        List of filepaths included in the no resynth mix

    """
    # create resynth mix
    if len(stem_indices) > 0:
        mix_filepaths, _ = mix.mix_multitrack(mtrack,
                                              mix_path,
                                              stem_indices=stem_indices,
                                              alternate_files=altfiles)
    else:
        mix_filepaths = None
    # create no guitar and no synth mixes
    stem_indices_noguitar = [
        s for s in stem_indices if s not in stem_indices_guitar
    ]
    stem_indices_nosynth = [
        s for s in stem_indices_noguitar if s not in stem_indices_piano
    ]
    altfiles_noguitar = {
        k: v
        for k, v in altfiles.items() if k in stem_indices_noguitar
    }
    altfiles_nosynth = {
        k: v
        for k, v in altfiles.items() if k in stem_indices_nosynth
    }
    if len(stem_indices_noguitar) > 0:
        mix_noguitar_filepaths, _ = mix.mix_multitrack(
            mtrack,
            mix_path_noguitar,
            stem_indices=stem_indices_noguitar,
            alternate_files=altfiles_noguitar)
    else:
        mix_noguitar_filepaths = None

    if len(stem_indices_nosynth) > 0:
        mix_nosynth_filepaths, _ = mix.mix_multitrack(
            mtrack,
            mix_path_nosynth,
            stem_indices=stem_indices_nosynth,
            alternate_files=altfiles_nosynth)
    else:
        mix_nosynth_filepaths = None

    return mix_filepaths, mix_noguitar_filepaths, mix_nosynth_filepaths
def compute_multif0_complete(mtrack, save_dir):
    prefix = "{}_multif0_complete".format(mtrack.track_id)

    input_path = os.path.join(save_dir, 'inputs',
                              "{}_input.npy".format(prefix))
    output_path = os.path.join(save_dir, 'outputs',
                               "{}_output.npy".format(prefix))
    if os.path.exists(input_path) and os.path.exists(output_path):
        print("    > already done!")
        return

    bad_mtrack = False
    for stem in mtrack.stems.values():
        if stem.pitch_estimate_pyin is not None:
            if 'p' in stem.f0_type:
                bad_mtrack = True
    if bad_mtrack:
        print("multitrack has stems with polyphonic instruments")
        return None

    multif0_mix_path = os.path.join(
        save_dir, "{}_multif0_MIX.wav".format(mtrack.track_id))

    if os.path.exists(multif0_mix_path):
        (times, freqs, stems_used,
         stem_annot_activity) = get_all_pitch_annotations(
             mtrack, compute_annot_activity=False)
    else:
        (times, freqs, stems_used,
         stem_annot_activity) = get_all_pitch_annotations(
             mtrack, compute_annot_activity=True)

    if times is not None:
        for i, stem in mtrack.stems.items():
            unvoiced = all([f0_type == 'u' for f0_type in stem.f0_type])
            if unvoiced:
                stems_used.append(i)

        # stems that were manually annotated may not be fully annotated :(
        # silencing out any part of the stem that does not contain
        # annotations just to be safe
        if not os.path.exists(multif0_mix_path):

            alternate_files = {}
            for key in stem_annot_activity.keys():
                new_stem_path = os.path.join(
                    save_dir,
                    "{}_STEM_{}_alt.wav".format(mtrack.track_id, key))
                if not os.path.exists(new_stem_path):
                    create_filtered_stem(mtrack.stems[key].audio_path,
                                         new_stem_path,
                                         stem_annot_activity[key])
                alternate_files[key] = new_stem_path

            mix.mix_multitrack(mtrack,
                               multif0_mix_path,
                               alternate_files=alternate_files,
                               stem_indices=stems_used)

        X, Y, f, t = get_input_output_pairs(
            multif0_mix_path,
            times,
            freqs,
        )
        save_data(save_dir, prefix, X, Y, f, t)

    else:
        print("    {} No multif0 data".format(mtrack.track_id))
示例#13
0
def test_and_gen_mix(track, fn, stem_indices):
    if not os.path.exists(fn):
        print("{} does not exist, generate one.".format(fn))
        mix_multitrack(track, fn, stem_indices=stem_indices)
    return fn