justinsalamon / scaper

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

Explicit control over sound event overlap #63

Open justinsalamon opened 5 years ago

justinsalamon commented 5 years ago

Certain scenarios require limiting the amount of overlapping sound events (or prohibiting it altogether). Right now there is no way to explicitly control for sound overlap.

Proposed solution: add a max_overlap kwarg to generate(), which by default is set to None, meaning any overlap is allowed. If set to 1, it basically means no overlap is allowed, 2 means 2 overlapping sounds, etc. 0 would be an invalid value.

(This would address #62)

pseeth commented 5 years ago

To tag on a bit, a min_overlap could also be nice, to make sure that generated scenes aren't trivial for source separation networks to solve, if using Scaper for the purposes of training separation networks.

justinsalamon commented 5 years ago

Sure! The logic for the two is quite different though - max_overlap just needs to find a place to locate each event such that the constraint isn't violated. min_overlap would basically require adding more and more events until the minimum overlap is reached everywhere. Will probably implement max_overlap first and then min_overlap in a separate PR (once pending PRs are finally merged.. sheesh! this fall hopefully!)

sreenivasaupadhyaya commented 3 years ago

Hi @pseeth @justinsalamon , I was wondering if the max_overlap is already implemented in any branc/version of Scaper already?

If not could you guide me to get it done? Thanks !

justinsalamon commented 3 years ago

@sreenivasaupadhyaya it’s not implemented yet. The feature requires a couple of delicate design decisions. We’re currently blocked on higher priorities, but will try to get to this soon, thanks

Kovalt0 commented 2 years ago

@sreenivasaupadhyaya it’s not implemented yet. The feature requires a couple of delicate design decisions. We’re currently blocked on higher priorities, but will try to get to this soon, thanks

@justinsalamon is this tool already implemented? I am trying to create thousands of audio samples in which they have from 1 to 3 events without overlapping. I managed to implement a for loop that cover the "for _ in range(n_events):" part and it kind of works but still not what I want to do. In the documentation I also couldn't find a way to make it work by setting the onset of each event. I tried with a list, but it stills overlap the sounds.

In this example I created soundscapes with three events, the implementation for creating 1 and 2 events samples is commented.

# """ 1 event"""
# time1 = round(random.uniform(0, 14), 1)
# time_plus = [time1]
# """ """

# """ 2 events """
# time1 = round(random.uniform(0, 4), 1)
# time2 = round(random.uniform(10, 14), 1)
# time_plus = [time1, time2]
# """ """

"""3 events"""
time1 = round(random.uniform(0, 4), 1)
time2 = round(random.uniform(10, 14), 1)
time3 = round(random.uniform(20, 24), 1)
time_plus = [time1, time2, time3]
""" """

# time_plus = [time1, time2, time3]
for event_time in time_plus:
    print('event time is: ', event_time)

    # add random number of foreground events
    n_events = np.random.randint(min_events, max_events+1)
    for _ in range(n_events):
        sc.add_event(label=('choose', []),
                 source_file=('choose', []),
                 source_time=(source_time_dist, source_time),
                 # event_time=(event_time_dist, event_time_mean, event_time_std, event_time_min, event_time_max),
                 # event_time=(event_time_dist, event_time_min, event_time_max),
                 event_time=(event_time_dist, event_time),
                 # event_duration=(event_duration_dist, event_duration_min, event_duration_max),
                 event_duration=(event_duration_dist, event_duration),
                 snr=(snr_dist, snr_min, snr_max),
                 pitch_shift= None, #it accepts None value
                 time_stretch= None) #it accepts None value
pass

Thanks in advance.