Mercurial > hg > simscene-py
changeset 38:a0eb120940b1
allow patterns to use other patterns as events
author | Emmanouil Theofanis Chourdakis <e.t.chourdakis@qmul.ac.uk> |
---|---|
date | Thu, 05 Oct 2017 15:45:41 +0100 |
parents | 41cc77e844fe |
children | fa69ba6556ee |
files | python/simscene.py |
diffstat | 1 files changed, 14 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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])