# HG changeset patch # User Emmanouil Theofanis Chourdakis # Date 1507214741 -3600 # Node ID a0eb120940b19e40f2abed90f9d8182dca982027 # Parent 41cc77e844fe2c50ab9e004d532d7c8e12e0fd34 allow patterns to use other patterns as events diff -r 41cc77e844fe -r a0eb120940b1 python/simscene.py --- a/python/simscene.py Thu Oct 05 15:15:07 2017 +0100 +++ b/python/simscene.py Thu Oct 05 15:45:41 2017 +0100 @@ -61,16 +61,26 @@ for n in range(len(pattern)): # Try loading the file, sampleid = pattern['sampleid'].loc[n] - candidates = glob.glob('{}/event/{}*wav'.format(input_path,sampleid)) - chosen_fname = random.sample(candidates, 1)[0] + candidates = [] + for pattern_format in ['xls', 'json', 'txt', 'csv']: + candidates += glob.glob('{}/pattern/{}*.{}'.format(input_path, sampleid, pattern_format)) - logging.debug('Loading {}'.format(chosen_fname)) + if len(candidates) == 0: + candidates = glob.glob('{}/event/{}*wav'.format(input_path,sampleid)) + chosen_fname = random.sample(candidates, 1)[0] + + wav, SR = librosa.load(chosen_fname, sr=sr) + else: + chosen_fname = random.sample(candidates, 1)[0] + + logging.debug('Loading {}'.format(chosen_fname)) + wav, SR = render_pattern(chosen_fname, input_path) + # For each sound in the pattern file, place it starting from starttime + an offset # with a mean value of 0 and standard deviation of offset_stddev. The first event can # not start earlier than time 0. If endtime is defined (not nan), then cut the event at # end time. - wav, SR = librosa.load(chosen_fname, sr=sr) # Read and assign an amplitude amplitude_mean = float(pattern['amplitude'].loc[n])