Changeset 8d1323b for python/aubio


Ignore:
Timestamp:
Apr 14, 2010, 5:36:49 PM (15 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:
0efce0d
Parents:
16bd78a
Message:

python/aubio: more changes for mono

Location:
python/aubio
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • python/aubio/aubioclass.py

    r16bd78a r8d1323b  
    22
    33class fvec:
    4     def __init__(self,size,chan):
    5         self.vec = new_fvec(size,chan)
     4    def __init__(self,size):
     5        self.vec = new_fvec(size)
    66    def __call__(self):
    77        return self.vec
    88    def __del__(self):
    99        del_fvec(self())
    10     def get(self,pos,chan):
    11         return fvec_read_sample(self(),chan,pos)
    12     def set(self,value,pos,chan):
    13         return fvec_write_sample(self(),value,chan,pos)
    14     def channel(self,chan):
    15         return fvec_get_channel(self(),chan)
     10    def get(self,pos):
     11        return fvec_read_sample(self(),pos)
     12    def set(self,value,pos):
     13        return fvec_write_sample(self(),value,pos)
    1614    def data(self):
    1715        return fvec_get_data(self())
    1816
    1917class cvec:
    20     def __init__(self,size,chan):
    21         self.vec = new_cvec(size,chan)
     18    def __init__(self,size):
     19        self.vec = new_cvec(size)
    2220    def __call__(self):
    2321        return self.vec
    2422    def __del__(self):
    2523        del_cvec(self())
    26     def get(self,pos,chan):
    27         return self.get_norm(pos,chan)
    28     def set(self,val,pos,chan):
    29         self.set_norm(val,chan,pos)
    30     def get_norm(self,pos,chan):
    31         return cvec_read_norm(self(),chan,pos)
    32     def set_norm(self,val,pos,chan):
    33         cvec_write_norm(self(),val,chan,pos)
    34     def get_phas(self,pos,chan):
    35         return cvec_read_phas(self(),chan,pos)
    36     def set_phas(self,val,pos,chan):
    37         cvec_write_phas(self(),val,chan,pos)
     24    def get(self,pos):
     25        return self.get_norm(pos)
     26    def set(self,val,pos):
     27        self.set_norm(val,pos)
     28    def get_norm(self,pos):
     29        return cvec_read_norm(self(),pos)
     30    def set_norm(self,val,pos):
     31        cvec_write_norm(self(),val,pos)
     32    def get_phas(self,pos):
     33        return cvec_read_phas(self(),pos)
     34    def set_phas(self,val,pos):
     35        cvec_write_phas(self(),val,pos)
    3836
    3937class sndfile:
     
    5452        return aubio_sndfile_channels(self.file)
    5553    def read(self,nfram,vecread):
    56         return aubio_sndfile_read(self.file,nfram,vecread())
     54        return aubio_sndfile_read_mono(self.file,nfram,vecread())
    5755    def write(self,nfram,vecwrite):
    5856        return aubio_sndfile_write(self.file,nfram,vecwrite())
    5957
    6058class pvoc:
    61     def __init__(self,buf,hop,chan):
    62         self.pv = new_aubio_pvoc(buf,hop,chan)
     59    def __init__(self,buf,hop):
     60        self.pv = new_aubio_pvoc(buf,hop)
    6361    def __del__(self):
    6462        del_aubio_pvoc(self.pv)
     
    7068class onsetdetection:
    7169    """ class for aubio_specdesc """
    72     def __init__(self,mode,buf,chan):
    73         self.od = new_aubio_specdesc(mode,buf,chan)
     70    def __init__(self,mode,buf):
     71        self.od = new_aubio_specdesc(mode,buf)
    7472    def do(self,tc,tf):
    7573        aubio_specdesc_do(self.od,tc(),tf())
     
    8078    """ class for aubio_peakpicker """
    8179    def __init__(self,threshold=0.1):
    82         self.pp = new_aubio_peakpicker(1)
    83         self.out = new_fvec(1, 1)
     80        self.pp = new_aubio_peakpicker()
     81        self.out = new_fvec(1)
    8482        aubio_peakpicker_set_threshold (self.pp, threshold)
    8583    def do(self,fv):
    8684        aubio_peakpicker_do(self.pp, fv(), self.out)
    87         return fvec_read_sample(self.out, 0, 0)
     85        return fvec_read_sample(self.out, 0)
    8886    def getval(self):
    8987        return aubio_peakpicker_get_adaptive_threshold(self.pp)
     
    9391class onsetpick:
    9492    """ superclass for aubio_pvoc + aubio_specdesc + aubio_peakpicker """
    95     def __init__(self,bufsize,hopsize,channels,myvec,threshold,mode='dual',derivate=False,dcthreshold=0):
    96         self.myfft    = cvec(bufsize,channels)
    97         self.pv       = pvoc(bufsize,hopsize,channels)
     93    def __init__(self,bufsize,hopsize,myvec,threshold,mode='dual',derivate=False,dcthreshold=0):
     94        self.myfft    = cvec(bufsize)
     95        self.pv       = pvoc(bufsize,hopsize)
    9896        if mode in ['dual'] :
    99                 self.myod     = onsetdetection("hfc",bufsize,channels)
    100                 self.myod2    = onsetdetection("mkl",bufsize,channels)
    101                 self.myonset  = fvec(1,channels)
    102                 self.myonset2 = fvec(1,channels)
     97                self.myod     = onsetdetection("hfc",bufsize)
     98                self.myod2    = onsetdetection("mkl",bufsize)
     99                self.myonset  = fvec(1)
     100                self.myonset2 = fvec(1)
    103101        else:
    104                 self.myod     = onsetdetection(mode,bufsize,channels)
    105                 self.myonset  = fvec(1,channels)
     102                self.myod     = onsetdetection(mode,bufsize)
     103                self.myonset  = fvec(1)
    106104        self.mode     = mode
    107105        self.pp       = peakpick(float(threshold))
     
    115113        if self.mode == 'dual':
    116114           self.myod2.do(self.myfft,self.myonset2)
    117            self.myonset.set(self.myonset.get(0,0)*self.myonset2.get(0,0),0,0)
     115           self.myonset.set(self.myonset.get(0)*self.myonset2.get(0),0)
    118116        if self.derivate:
    119            val         = self.myonset.get(0,0)
     117           val         = self.myonset.get(0)
    120118           dval        = val - self.oldval
    121119           self.oldval = val
    122            if dval > 0: self.myonset.set(dval,0,0)
     120           if dval > 0: self.myonset.set(dval,0)
    123121           else:  self.myonset.set(0.,0,0)
    124         isonset, dval = self.pp.do(self.myonset),self.myonset.get(0,0)
     122        isonset, dval = self.pp.do(self.myonset),self.myonset.get(0)
    125123        if self.dcthreshold:
    126124           if dval < self.dcthreshold: isonset = 0
     
    129127class pitch:
    130128    def __init__(self,mode="mcomb",bufsize=2048,hopsize=1024,
    131         channels=1,samplerate=44100.,omode="freq",tolerance=0.1):
    132         self.pitchp = new_aubio_pitch(mode,bufsize,hopsize,channels,
     129        samplerate=44100.,omode="freq",tolerance=0.1):
     130        self.pitchp = new_aubio_pitch(mode,bufsize,hopsize,
    133131            samplerate)
    134         self.mypitch = fvec(1, channels)
     132        self.mypitch = fvec(1)
    135133        aubio_pitch_set_unit(self.pitchp,omode)
    136134        aubio_pitch_set_tolerance(self.pitchp,tolerance)
     
    140138    def __call__(self,myvec):
    141139        aubio_pitch_do(self.pitchp,myvec(), self.mypitch())
    142         return self.mypitch.get(0,0)
     140        return self.mypitch.get(0)
    143141
    144142class filter:
  • python/aubio/task/onset.py

    r16bd78a r8d1323b  
    1010                self.opick = onsetpick(self.params.bufsize,
    1111                        self.params.hopsize,
    12                         self.channels,
    1312                        self.myvec,
    1413                        self.params.threshold,
  • python/aubio/task/pitch.py

    r16bd78a r8d1323b  
    1616                        bufsize=self.params.bufsize,
    1717                        hopsize=self.params.hopsize,
    18                         channels=self.channels,
    1918                        samplerate=self.srate,
    2019                        omode=self.params.omode,
  • python/aubio/task/task.py

    r16bd78a r8d1323b  
    1717                self.filei     = sndfile(self.input)
    1818                self.srate     = self.filei.samplerate()
    19                 self.channels  = self.filei.channels()
    2019                self.params.step = float(self.params.hopsize)/float(self.srate)
    21                 self.myvec     = fvec(self.params.hopsize,self.channels)
     20                self.myvec     = fvec(self.params.hopsize)
    2221                self.output    = output
    2322
Note: See TracChangeset for help on using the changeset viewer.