justinsalamon / scaper

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

Custom audio filters / transformations (e.g. "plugins") #38

Open FunkMonkey opened 5 years ago

FunkMonkey commented 5 years ago

It would be nice if Scaper could provide a way to add custom audio filters to the events and backgrounds. I imagine something like this:

add_event(label, source_file, source_time, event_time, event_duration, transformations)

Where transformations is a list of functions or objects that transform the audio signal in sequence.

transformations = [ SomeTransform(), LowPass(4), TimeStretch('uniform', 0.8, 1.2), PitchShift('uniform', -2, 2) ] 

What do you think?

justinsalamon commented 5 years ago

Thanks for the suggestion - I think it's a great idea.

To make this API proposal truly flexible and extensible I think it would be important to support custom transformations (i.e. not just the "built-in" ones), i.e. the user should be able to define a transformation subclass based on an expected API so they can implement a transformation of their choice (I think this is what you are proposing too, right?).

Beyond the actual implementation (tests and logic around timing information are going to be critical here), this probably merits some brainstorming to come up with a clean API design - currently the supported transformations are hard-coded, I think it would have to be replaced entirely with a template transformation class and a process/API for subclassing it. Open to suggestions!

p.s - I'm a little pushed for time right now so apologies if I'm slow to respond, should have more time in the near future.