Changeset e253a86 for python/demos


Ignore:
Timestamp:
Mar 6, 2013, 9:49:32 PM (12 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, pitchshift, sampler, timestretch, yinfft+
Children:
eadc00b
Parents:
043c48c
Message:

demos/demo_source.py: indent, add samplerate and hop_size options

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/demos/demo_source.py

    r043c48c re253a86  
    55
    66if __name__ == '__main__':
    7   if len(sys.argv) < 2:
    8     print 'usage: %s <inputfile>' % sys.argv[0]
    9     sys.exit(1)
    10   f = source(sys.argv[1], 1, 256)
    11   samplerate = f.get_samplerate()
    12   total_frames, read = 0, 256
    13   while read:
    14     vec, read = f()
    15     total_frames += read
    16   print "read", total_frames / float(samplerate), "seconds from", f.uri
     7    if len(sys.argv) < 2:
     8        print 'usage: %s <inputfile> [samplerate] [hop_size]' % sys.argv[0]
     9        sys.exit(1)
     10    samplerate = 0
     11    hop_size = 256
     12    if len(sys.argv) > 2: samplerate = int(sys.argv[2])
     13    if len(sys.argv) > 3: hop_size = int(sys.argv[3])
     14
     15    f = source(sys.argv[1], samplerate, hop_size)
     16    samplerate = f.samplerate
     17
     18    total_frames, read = 0, f.hop_size
     19    while read:
     20        vec, read = f()
     21        total_frames += read
     22        if read < f.hop_size: break
     23    print "read", "%.2fs" % (total_frames / float(samplerate) ),
     24    print "(", total_frames, "frames", "in",
     25    print total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")",
     26    print "from", f.uri
Note: See TracChangeset for help on using the changeset viewer.