Changeset 71f98f1 for python


Ignore:
Timestamp:
May 23, 2005, 12:40:33 AM (19 years ago)
Author:
Paul Brossier <piem@altern.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:
296c33a
Parents:
2cdae81
Message:

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

Location:
python
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • python/aubio/aubioclass.py

    r2cdae81 r71f98f1  
    5555
    5656class onsetdetection:
     57    """ class for aubio_onsetdetection """
    5758    def __init__(self,type,buf,chan):
    5859        self.od = new_aubio_onsetdetection(type,buf,chan)
     
    6364
    6465class peakpick:
     66    """ class for aubio_peakpicker """
    6567    def __init__(self,threshold=0.1):
    6668        self.pp = new_aubio_peakpicker(threshold)
     
    7173
    7274class onsetpick:
     75    """ superclass for aubio_pvoc + aubio_onsetdetection + aubio_peakpicker """
    7376    def __init__(self,bufsize,hopsize,channels,myvec,threshold,mode='dual'):
    7477        self.myfft    = cvec(bufsize,channels)
     
    152155        return mylist
    153156
    154 
    155157def getonsets(filein,threshold=0.2,silence=-70.,bufsize=1024,hopsize=512,mode='dual'):
    156158        frameread = 0
     
    185187        return mylist
    186188
    187 
    188189class pitchpick:
    189190    def __init__(self,bufsize,hopsize,channels,myvec,srate):
  • python/aubiocut

    r2cdae81 r71f98f1  
    66
    77from aubio.aubioclass import *
    8 import sys
    98
    109bufsize   = 1024
    1110hopsize   = bufsize/2
    1211
     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
    1347
    14 def cutfile(filein,onsets):
    15         frameread = 0
    16         zerothres = 0.002
    17         readsize  = hopsize
    18         filei     = sndfile(filein)
    19         framestep = hopsize/(filei.samplerate()+0.)
    20         channels  = filei.channels()
    21         newname   = "%s%f%s" % ("/tmp/",0.0000000,filein[-4:])
    22         fileo     = sndfile(newname,model=filei)
    23         myvec     = fvec(hopsize,channels)
    24         mycopy    = fvec(hopsize,channels)
    25         while(readsize==hopsize):
    26                 readsize = filei.read(hopsize,myvec)
    27                 # write to current file
    28                 if len(onsets) and frameread >= onsets[0]:
    29                     onsets.pop(0)
    30                     # write up to 1st zero crossing
    31                     zerocross = 0
    32                     while ( abs( myvec.get(zerocross,0) ) > zerothres ):
    33                         zerocross += 1
    34                     writesize = fileo.write(zerocross,myvec)
    35                     fromcross = 0
    36                     while (zerocross < readsize):
    37                         for i in range(channels):
    38                                 mycopy.set(myvec.get(zerocross,i),fromcross,i)
    39                         fromcross += 1
    40                         zerocross += 1
    41                     del fileo
    42                     fileo = sndfile("%s%s%f%s%s" %
    43                         (filein.split(".")[0].split("/")[-1],".",
    44                         frameread*framestep,".",filein.split(".")[-1]),model=filei)
    45                     writesize = fileo.write(fromcross,mycopy)
    46                 else:
    47                     writesize = fileo.write(readsize,myvec)
    48                 frameread += 1
    49         del fileo
    50 
     48import sys
    5149filename  = sys.argv[1]
    52 threshold = sys.argv[2]
     50threshold = 0.2
     51if (len(sys.argv) > 2): threshold = sys.argv[2]
    5352onsets    = getonsets(filename,threshold)
    5453cutfile(filename,onsets)
Note: See TracChangeset for help on using the changeset viewer.