justinsalamon / scaper

A library for soundscape synthesis and augmentation
BSD 3-Clause "New" or "Revised" License
377 stars 55 forks source link

Fades of length 0 fail #124

Closed pseeth closed 4 years ago

pseeth commented 4 years ago

If you set

sc.fade_in_len = 0.0
sc.fade_out_len = 0.0

you hit the following error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-141-4a2c6fbfb5de> in <module>
      1 with warnings.catch_warnings():
      2     warnings.filterwarnings('ignore')
----> 3     soundscape_audio, soundscape_jam, annotation_list, event_audio_list = sc.generate()

~/miniconda3/envs/ismir-2020/lib/python3.8/site-packages/scaper/core.py in generate(self, audio_path, jams_path, allow_repeated_label, allow_repeated_source, reverb, save_isolated_events, isolated_events_path, disable_sox_warnings, no_audio, txt_path, txt_sep, disable_instantiation_warnings)
   2112         if not no_audio:
   2113             soundscape_audio, event_audio_list = \
-> 2114                 self._generate_audio(audio_path, ann, reverb=reverb,
   2115                                      save_isolated_events=save_isolated_events,
   2116                                      isolated_events_path=isolated_events_path,

~/miniconda3/envs/ismir-2020/lib/python3.8/site-packages/scaper/core.py in _generate_audio(self, audio_path, ann, reverb, save_isolated_events, isolated_events_path, disable_sox_warnings)
   1904 
   1905                         event_audio[:fade_in_samples] *= fade_in_window
-> 1906                         event_audio[-fade_out_samples:] *= fade_out_window
   1907 
   1908                         # Pad with silence before/after event to match the

ValueError: operands could not be broadcast together with shapes (220499,1) (0,1) (220499,1) 

The fix should only reach this code if the fade lengths are greater than zero. Will make a quick PR to address this.

pseeth commented 4 years ago

Closed by #125