Showing the changes to python (1 of 2 files). Show all
Unified · Split
| @@ -7,7 +7,7 @@ · 6 unmodified lines | |||
| 7 | from aubio.aubioclass import * | 7 | from aubio.aubioclass import * |
| 8 | import sys | 8 | import sys |
| 9 | 9 | ||
| 10 | bufsize = 1024 | 10 | bufsize = 512 |
| 11 | hopsize = bufsize/2 | 11 | hopsize = bufsize/2 |
| 12 | 12 | ||
| 13 | def getonsets(filein,threshold): | 13 | def getonsets(filein,threshold): |
| @@ -28,12 +28,11 @@ def getonsets(filein,threshold): · 14 unmodified lines | |||
| 28 | ovalist.append(val) | 28 | ovalist.append(val) |
| 29 | ovalist.pop(0) | 29 | ovalist.pop(0) |
| 30 | if (isonset == 1): | 30 | if (isonset == 1): |
| 31 | print frameread | ||
| 32 | i=len(ovalist)-1 | 31 | i=len(ovalist)-1 |
| 33 | # find local minima | 32 | # find local minima |
| 34 | while ovalist[i-1] < ovalist[i] and i > 0: | 33 | while ovalist[i-1] < ovalist[i] and i > 0: |
| 35 | i -= 1 | 34 | i -= 1 |
| 36 | now = (frameread-i+1)*hopsize/(srate+0.) | 35 | now = (frameread+1-i)*hopsize/(srate+0.) |
| 37 | #del fileo | 36 | #del fileo |
| 38 | #fileo = sndfile("%s%f%s" % ("/tmp/",now,filein[-4:]),model=filei) | 37 | #fileo = sndfile("%s%f%s" % ("/tmp/",now,filein[-4:]),model=filei) |
| 39 | mylist.append(now) | 38 | mylist.append(now) |
| @@ -50,14 +49,30 @@ def cutfile(filein,onsets): · 10 unmodified lines | |||
| 50 | newname = "%s%f%s" % ("/tmp/",0.0000000,filein[-4:]) | 49 | newname = "%s%f%s" % ("/tmp/",0.0000000,filein[-4:]) |
| 51 | fileo = sndfile(newname,model=filei) | 50 | fileo = sndfile(newname,model=filei) |
| 52 | myvec = fvec(hopsize,channels) | 51 | myvec = fvec(hopsize,channels) |
| 52 | mycopy = fvec(hopsize,channels) | ||
| 53 | while(readsize==hopsize): | 53 | while(readsize==hopsize): |
| 54 | readsize = filei.read(hopsize,myvec) | 54 | readsize = filei.read(hopsize,myvec) |
| 55 | now = (frameread)*hopsize/(srate+0.) | 55 | now = (frameread)*hopsize/(srate+0.) |
| 56 | writesize = fileo.write(readsize,myvec) | 56 | # write to current file |
| 57 | if len(onsets) and now == onsets[0]: | 57 | if len(onsets) and now >= onsets[0]: |
| 58 | onsets.pop(0) | 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 | del fileo | 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 | frameread += 1 | 76 | frameread += 1 |
| 62 | del fileo | 77 | del fileo |
| 63 | 78 | ||