Changeset 95221ac for python/lib


Ignore:
Timestamp:
Oct 29, 2018, 11:31:40 PM (5 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master
Children:
852fbfe
Parents:
d1b78dc (diff), ab24edb (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'fix/slicing'

Location:
python/lib/aubio
Files:
3 edited

Legend:

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

    rd1b78dc r95221ac  
    248248                action = "store", dest = "cut_until_nslices", default = None,
    249249                help="how many extra slices should be added at the end of each slice")
     250        self.add_argument("--create-first",
     251                action = "store_true", dest = "create_first", default = False,
     252                help="always include first slice")
    250253
    251254# some utilities
  • python/lib/aubio/cut.py

    rd1b78dc r95221ac  
    102102    s = source(source_uri, samplerate, hopsize)
    103103    if samplerate == 0:
    104         samplerate = s.get_samplerate()
     104        samplerate = s.samplerate
    105105        options.samplerate = samplerate
    106106
     
    151151                timestamps, timestamps_end = timestamps_end,
    152152                output_dir = options.output_directory,
    153                 samplerate = options.samplerate)
     153                samplerate = options.samplerate,
     154                create_first = options.create_first)
    154155
    155156def main():
  • python/lib/aubio/slicing.py

    rd1b78dc r95221ac  
    77
    88def slice_source_at_stamps(source_file, timestamps, timestamps_end=None,
    9                            output_dir=None, samplerate=0, hopsize=256):
     9                           output_dir=None, samplerate=0, hopsize=256,
     10                           create_first=False):
    1011    """ slice a sound file at given timestamps """
    1112
     
    1314        raise ValueError("no timestamps given")
    1415
    15     if timestamps[0] != 0:
     16    if timestamps[0] != 0 and create_first:
    1617        timestamps = [0] + timestamps
    1718        if timestamps_end is not None:
     
    1920
    2021    if timestamps_end is not None:
    21         if len(timestamps_end) != len(timestamps):
     22        if len(timestamps_end) == len(timestamps) - 1:
     23            timestamps_end = timestamps_end + [_max_timestamp]
     24        elif len(timestamps_end) != len(timestamps):
    2225            raise ValueError("len(timestamps_end) != len(timestamps)")
    2326    else:
     
    4952        vec, read = _source.do_multi()
    5053        # if the total number of frames read will exceed the next region start
    51         if len(regions) and total_frames + read >= regions[0][0]:
     54        while len(regions) and total_frames + read >= regions[0][0]:
    5255            #print "getting", regions[0], "at", total_frames
    5356            # get next region
     
    7679                    # write remaining samples from current region
    7780                    _sink.do_multi(vec[:, start:remaining], remaining - start)
    78                     #print "closing region", "remaining", remaining
     81                    #print("closing region", "remaining", remaining)
    7982                    # close this file
    8083                    _sink.close()
     
    8386                _sink.do_multi(vec[:, start:read], read - start)
    8487        total_frames += read
     88        # remove old slices
     89        slices = list(filter(lambda s: s['end_stamp'] > total_frames,
     90            slices))
    8591        if read < hopsize:
    8692            break
Note: See TracChangeset for help on using the changeset viewer.