def test_high_polyphony(): pol_dir = osp.join(absolute_dir_path, "generated", "polyphony") if osp.exists(pol_dir): shutil.rmtree(pol_dir) shutil.copytree(osp.join(absolute_dir_path, "material", "post_processing"), pol_dir) ll = glob.glob(osp.join(pol_dir, "*.jams")) assert len(ll) == 2 save_name = os.path.join(absolute_dir_path, "generated", "final.tsv") rm_high_polyphony(pol_dir, 1, save_name) ll = glob.glob(osp.join(pol_dir, "*.jams")) assert len(ll) == 1, f"Problem rm_high_polyphony {len(ll)} != 1"
events_start=( event_time_dist, event_time_mean, event_time_std, event_time_min, event_time_max, ), events_duration=(event_duration_dist, event_duration_min, event_duration_max), snrs=(snr_dist, snr_min, snr_max), pitch_shifts=(pitch_dist, pitch_min, pitch_max), time_stretches=(time_stretch_dist, time_stretch_min, time_stretch_max), txt_file=True, ) rm_high_polyphony(out_folder_500, 2) out_tsv = osp.join(out_tsv_folder, "500ms.tsv") post_process_txt_labels(out_folder_500, output_folder=out_folder_500, output_tsv=out_tsv) # Generate 2 variants of this dataset jams_to_modify = glob.glob(osp.join(out_folder_500, "*.jams")) # Be careful, if changing the values of the added onset value, # you maybe want to rerun the post_processing_annotations to be sure there is no inconsistency # 5.5s onset files out_folder_5500 = osp.join(base_out_folder, "5500ms") add_onset = 5.0 modif_onset_5s = functools.partial(modify_fg_onset, slice_seconds=add_onset)
pitch_max = 3.0 time_stretch_dist = 'uniform' time_stretch_min = 1 time_stretch_max = 1 out_folder_ls_30 = osp.join(out_folder, "ls_30dB") create_folder(out_folder_ls_30) sg.generate(n_soundscapes, out_folder_ls_30, min_events, max_events, labels=('choose', []), source_files=('choose', []), sources_time=(source_time_dist, source_time), events_start=(evt_time_dist, evt_time_mean, evt_time_std, evt_time_min, evt_time_max), events_duration=(event_duration_dist, event_duration_min, event_duration_max), snrs=('const', 30), pitch_shifts=('uniform', -3.0, 3.0), time_stretches=('uniform', 1, 1), txt_file=True) rm_high_polyphony(out_folder_ls_30, 3) post_process_txt_labels(out_folder_ls_30, output_folder=out_folder_ls_30, output_tsv=args.out_tsv, background_label=True) list_jams = glob.glob(osp.join(out_folder_ls_30, "*.jams")) # We create the same dataset with different background SNR # Be careful, 15 means the background SNR is 15, # so the foreground background snr ratio is between -9dB and 15dB out_folder_ls_15 = osp.join(out_folder, "ls_15dB") modify_jams(list_jams, change_snr, out_folder_ls_15, db_change=-15) # Same for 0dB FBSNR, from original fbsnr [6;30]dB, we go to [-24;0]dB FBSNR out_folder_ls_0 = osp.join(out_folder, "ls_0dB") modify_jams(list_jams, change_snr, out_folder_ls_15, db_change=-30)
sg = SoundscapesGenerator(duration, fg_folder, bg_folder, ref_db=ref_db) sg.generate_by_label_occurence(params, n_soundscapes, outfolder, min_events=1, max_events=1, pitch_shift=('uniform', -3, 3)) if __name__ == '__main__': base_soundbank = osp.join("..", "..", "synthetic") for subset in ["train", "eval"]: soundbank_path = osp.join(base_soundbank, "audio", subset, "soundbank") fg_folder = osp.join(soundbank_path, "foreground/") bg_folder = osp.join(soundbank_path, "background") dataset_path = osp.join("..", "..", "dataset") param_file = osp.join(dataset_path, "metadata", subset, f"event_occurences_{subset}.json") outfolder = osp.join(dataset_path, "audio", subset, "one_event_generated") out_tsv = osp.join(dataset_path, "audio", subset, "one_event_generated.tsv") generate_training(15, fg_folder, bg_folder, param_file, outfolder) rm_high_polyphony(outfolder, 3) post_process_txt_labels(outfolder, output_folder=outfolder, output_tsv=out_tsv)
if random_state is None: random_states = [None for i in range(nproc)] else: random_states = [random_state + i for i in range(nproc)] print(random_states) with multiprocessing.Pool(nproc) as p: p.starmap(generate_multiproc, zip(list_start, numbers, random_states)) # Single process else: sg = SoundscapesGenerator(duration=clip_duration, fg_folder=fg_folder, bg_folder=bg_folder, ref_db=ref_db, samplerate=sample_rate, random_state=random_state) sg.generate_by_label_occurence(label_occurences=co_occur_dict, number=n_soundscapes, out_folder=full_out_folder, save_isolated_events=True, pitch_shift=pitch_shift) # ## # Post processing rm_high_polyphony(full_out_folder, max_polyphony=2) # concat same labels overlapping post_process_txt_labels(full_out_folder, output_folder=full_out_folder, output_tsv=out_tsv, rm_nOn_nOff=True)