Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/lib/aubio/slicing.py

    r2c8ada6 rf9400d0  
    55
    66_max_timestamp = 1e120
    7 
    87
    98def slice_source_at_stamps(source_file, timestamps, timestamps_end=None,
     
    7473    """
    7574
    76     if not timestamps:
     75    if timestamps is None or len(timestamps) == 0:
    7776        raise ValueError("no timestamps given")
    7877
     
    9190
    9291    regions = list(zip(timestamps, timestamps_end))
     92    #print regions
    9393
    9494    source_base_name, _ = os.path.splitext(os.path.basename(source_file))
     
    9898        source_base_name = os.path.join(output_dir, source_base_name)
    9999
    100     def _new_sink_name(source_base_name, timestamp, samplerate):
    101         # create name based on a timestamp in samples, converted in seconds
     100    def new_sink_name(source_base_name, timestamp, samplerate):
     101        """ create a sink based on a timestamp in samples, converted in seconds """
    102102        timestamp_seconds = timestamp / float(samplerate)
    103103        return source_base_name + "_%011.6f" % timestamp_seconds + '.wav'
     
    114114        vec, read = _source.do_multi()
    115115        # if the total number of frames read will exceed the next region start
    116         while regions and total_frames + read >= regions[0][0]:
     116        while len(regions) and total_frames + read >= regions[0][0]:
     117            #print "getting", regions[0], "at", total_frames
    117118            # get next region
    118119            start_stamp, end_stamp = regions.pop(0)
    119120            # create a name for the sink
    120             new_sink_path = _new_sink_name(source_base_name, start_stamp,
    121                                            samplerate)
     121            new_sink_path = new_sink_name(source_base_name, start_stamp, samplerate)
    122122            # create its sink
    123123            _sink = sink(new_sink_path, samplerate, _source.channels)
    124124            # create a dictionary containing all this
    125             new_slice = {'start_stamp': start_stamp, 'end_stamp': end_stamp,
    126                          'sink': _sink}
     125            new_slice = {'start_stamp': start_stamp, 'end_stamp': end_stamp, 'sink': _sink}
    127126            # append the dictionary to the current list of slices
    128127            slices.append(new_slice)
     
    136135            # number of samples yet to written be until end of region
    137136            remaining = end_stamp - total_frames + 1
     137            #print current_slice, remaining, start
    138138            # not enough frames remaining, time to split
    139139            if remaining < read:
     
    141141                    # write remaining samples from current region
    142142                    _sink.do_multi(vec[:, start:remaining], remaining - start)
     143                    #print("closing region", "remaining", remaining)
    143144                    # close this file
    144145                    _sink.close()
     
    149150        # remove old slices
    150151        slices = list(filter(lambda s: s['end_stamp'] > total_frames,
    151                              slices))
     152            slices))
    152153        if read < hopsize:
    153154            break
Note: See TracChangeset for help on using the changeset viewer.