source: python.old/aubio/task/cut.py @ dd15573

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since dd15573 was b554e41, checked in by Paul Brossier <piem@piem.org>, 12 years ago

moved out old python interface

  • Property mode set to 100644
File size: 1.5 KB
RevLine 
[13c3fba]1from task import task
2from aubio.aubioclass import *
3
4class taskcut(task):
5        def __init__(self,input,slicetimes,params=None,output=None):
6                """ open the input file and initialize arguments
7                parameters should be set *before* calling this method.
8                """
[cf34922]9                from os.path import basename,splitext
[13c3fba]10                task.__init__(self,input,output=None,params=params)
[cf34922]11                self.soundoutbase, self.soundoutext = splitext(basename(self.input))
12                self.newname   = "%s%s%09.5f%s%s" % (self.soundoutbase,".",
13                                        self.frameread*self.params.step,".",self.soundoutext)
[13c3fba]14                self.fileo      = sndfile(self.newname,model=self.filei)
15                self.myvec      = fvec(self.params.hopsize,self.channels)
16                self.mycopy     = fvec(self.params.hopsize,self.channels)
17                self.slicetimes = slicetimes
18
19        def __call__(self):
20                task.__call__(self)
21                # write to current file
22                if len(self.slicetimes) and self.frameread >= self.slicetimes[0][0]:
23                        self.slicetimes.pop(0)
24                        # write up to 1st zero crossing
25                        zerocross = 0
26                        while ( abs( self.myvec.get(zerocross,0) ) > self.params.zerothres ):
27                                zerocross += 1
28                        writesize = self.fileo.write(zerocross,self.myvec)
29                        fromcross = 0
30                        while (zerocross < self.readsize):
31                                for i in range(self.channels):
32                                        self.mycopy.set(self.myvec.get(zerocross,i),fromcross,i)
33                                        fromcross += 1
34                                        zerocross += 1
35                        del self.fileo
[cf34922]36                        self.fileo = sndfile("%s%s%09.5f%s%s" % (self.soundoutbase,".",
37                                self.frameread*self.params.step,".",self.soundoutext),model=self.filei)
[13c3fba]38                        writesize = self.fileo.write(fromcross,self.mycopy)
39                else:
40                        writesize = self.fileo.write(self.readsize,self.myvec)
41
42
Note: See TracBrowser for help on using the repository browser.