source: python/aubiocut @ 5a1ff62

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 5a1ff62 was 71f98f1, checked in by Paul Brossier <piem@altern.org>, 20 years ago

add aubioplot-onset, minor fixes on aubiocut and aubioclass.py
add aubioplot-onset, minor fixes on aubiocut and aubioclass.py

  • Property mode set to 100755
File size: 1.7 KB
RevLine 
[96fb8ad]1#!/usr/bin/python
2
3""" this file was written by Paul Brossier
4  it is released under the GNU/GPL license.
5"""
6
7from aubio.aubioclass import *
8
[e997b1a]9bufsize   = 1024
[65f1edc]10hopsize   = bufsize/2
11
[71f98f1]12def cutfile(filein,slicetimes,zerothres=0.002):
13    frameread = 0
14    readsize  = hopsize
15    filei     = sndfile(filein)
16    framestep = hopsize/(filei.samplerate()+0.)
17    channels  = filei.channels()
18    newname   = "%s%f%s" % ("/tmp/",0.0000000,filein[-4:])
19    fileo     = sndfile(newname,model=filei)
20    myvec     = fvec(hopsize,channels)
21    mycopy    = fvec(hopsize,channels)
22    while(readsize==hopsize):
23        readsize = filei.read(hopsize,myvec)
24        # write to current file
25        if len(slicetimes) and frameread >= slicetimes[0]:
26            slicetimes.pop(0)
27            # write up to 1st zero crossing
28            zerocross = 0
29            while ( abs( myvec.get(zerocross,0) ) > zerothres ):
30                zerocross += 1
31            writesize = fileo.write(zerocross,myvec)
32            fromcross = 0
33            while (zerocross < readsize):
34                for i in range(channels):
35                        mycopy.set(myvec.get(zerocross,i),fromcross,i)
36                fromcross += 1
37                zerocross += 1
38            del fileo
39            fileo = sndfile("%s%s%f%s%s" % 
40                (filein.split(".")[0].split("/")[-1],".",
41                frameread*framestep,".",filein.split(".")[-1]),model=filei)
42            writesize = fileo.write(fromcross,mycopy)
43        else:
44            writesize = fileo.write(readsize,myvec)
45        frameread += 1
46    del fileo
[96fb8ad]47
[71f98f1]48import sys
[96fb8ad]49filename  = sys.argv[1]
[71f98f1]50threshold = 0.2
51if (len(sys.argv) > 2): threshold = sys.argv[2]
[96fb8ad]52onsets    = getonsets(filename,threshold)
53cutfile(filename,onsets)
Note: See TracBrowser for help on using the repository browser.