Showing the changes to python (1 of 2 files). Show all
Unified · Split
| @@ -7,7 +7,7 @@ · 6 unmodified lines | ||
| 7 | 7 | from aubio.aubioclass import * |
| 8 | 8 | import sys |
| 9 | 9 | |
| 10 | −bufsize = 1024 | |
| 10 | +bufsize = 512 | |
| 11 | 11 | hopsize = bufsize/2 |
| 12 | 12 | |
| 13 | 13 | def getonsets(filein,threshold): |
| @@ -28,12 +28,11 @@ def getonsets(filein,threshold): · 14 unmodified lines | ||
| 28 | 28 | ovalist.append(val) |
| 29 | 29 | ovalist.pop(0) |
| 30 | 30 | if (isonset == 1): |
| 31 | − print frameread | |
| 32 | 31 | i=len(ovalist)-1 |
| 33 | 32 | # find local minima |
| 34 | 33 | while ovalist[i-1] < ovalist[i] and i > 0: |
| 35 | 34 | i -= 1 |
| 36 | − now = (frameread-i+1)*hopsize/(srate+0.) | |
| 35 | + now = (frameread+1-i)*hopsize/(srate+0.) | |
| 37 | 36 | #del fileo |
| 38 | 37 | #fileo = sndfile("%s%f%s" % ("/tmp/",now,filein[-4:]),model=filei) |
| 39 | 38 | mylist.append(now) |
| @@ -50,14 +49,30 @@ def cutfile(filein,onsets): · 10 unmodified lines | ||
| 50 | 49 | newname = "%s%f%s" % ("/tmp/",0.0000000,filein[-4:]) |
| 51 | 50 | fileo = sndfile(newname,model=filei) |
| 52 | 51 | myvec = fvec(hopsize,channels) |
| 52 | + mycopy = fvec(hopsize,channels) | |
| 53 | 53 | while(readsize==hopsize): |
| 54 | 54 | readsize = filei.read(hopsize,myvec) |
| 55 | 55 | now = (frameread)*hopsize/(srate+0.) |
| 56 | − writesize = fileo.write(readsize,myvec) | |
| 57 | − if len(onsets) and now == onsets[0]: | |
| 56 | + # write to current file | |
| 57 | + if len(onsets) and now >= onsets[0]: | |
| 58 | 58 | onsets.pop(0) |
| 59 | + # write up to 1st zero crossing | |
| 60 | + zerocross = 0 | |
| 61 | + while ( abs( myvec.get(zerocross,0) ) > 0.002 ): | |
| 62 | + zerocross += 1 | |
| 63 | + writesize = fileo.write(zerocross,myvec) | |
| 64 | + fromcross = 0 | |
| 65 | + while (zerocross < readsize): | |
| 66 | + mycopy.set(myvec.get(zerocross,0),fromcross,0) | |
| 67 | + fromcross += 1 | |
| 68 | + zerocross += 1 | |
| 59 | 69 | del fileo |
| 60 | − fileo = sndfile("%s%f%s%s" % ("/tmp/",now,".",filein.split(".")[-1]),model=filei) | |
| 70 | + fileo = sndfile("%s%s%f%s%s" % | |
| 71 | + (filein.split(".")[0].split("/")[-1],".",now,".",filein.split(".")[-1]),model=filei) | |
| 72 | + # write after 1st zero crossing to new file | |
| 73 | + writesize = fileo.write(fromcross,mycopy) | |
| 74 | + else: | |
| 75 | + writesize = fileo.write(readsize,myvec) | |
| 61 | 76 | frameread += 1 |
| 62 | 77 | del fileo |
| 63 | 78 | |