source: python/aubio/task/cut.py @ a300cef

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

use os.path in task.cut to derive default output filenames
use os.path in task.cut to derive default output filenames

  • Property mode set to 100644
File size: 1.5 KB
Line 
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                """
9                from os.path import basename,splitext
10                task.__init__(self,input,output=None,params=params)
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)
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
36                        self.fileo = sndfile("%s%s%09.5f%s%s" % (self.soundoutbase,".",
37                                self.frameread*self.params.step,".",self.soundoutext),model=self.filei)
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.