Changeset ad04467
 Timestamp:
 Nov 3, 2009, 4:06:15 PM (10 years ago)
 Branches:
 feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master, pitchshift, sampler, timestretch, yinfft+
 Children:
 63f3c70
 Parents:
 8bc4800
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

src/pitch/pitchschmitt.c
r8bc4800 rad04467 24 24 #include "pitch/pitchschmitt.h" 25 25 26 smpl_t aubio_schmittS16LE (aubio_pitchschmitt_t *p, uint_t nframes, signed short int *indata); 26 smpl_t aubio_schmittS16LE (aubio_pitchschmitt_t * p, uint_t nframes, 27 signed short int *indata); 27 28 28 struct _aubio_pitchschmitt_t { 29 uint_t blockSize; 30 uint_t rate; 31 signed short int *schmittBuffer; 32 signed short int *schmittPointer; 33 signed short int *buf; 29 struct _aubio_pitchschmitt_t 30 { 31 uint_t blockSize; 32 uint_t rate; 33 signed short int *schmittBuffer; 34 signed short int *schmittPointer; 35 signed short int *buf; 34 36 }; 35 37 36 aubio_pitchschmitt_t * new_aubio_pitchschmitt (uint_t size) 38 aubio_pitchschmitt_t * 39 new_aubio_pitchschmitt (uint_t size) 37 40 { 38 aubio_pitchschmitt_t * p = AUBIO_NEW(aubio_pitchschmitt_t);41 aubio_pitchschmitt_t *p = AUBIO_NEW (aubio_pitchschmitt_t); 39 42 p>blockSize = size; 40 p>schmittBuffer = AUBIO_ARRAY (signed short int,p>blockSize);41 p>buf = AUBIO_ARRAY (signed short int,p>blockSize);43 p>schmittBuffer = AUBIO_ARRAY (signed short int, p>blockSize); 44 p>buf = AUBIO_ARRAY (signed short int, p>blockSize); 42 45 p>schmittPointer = p>schmittBuffer; 43 46 return p; … … 57 60 } 58 61 59 smpl_t aubio_schmittS16LE (aubio_pitchschmitt_t *p, uint_t nframes, signed short int *indata) 62 smpl_t 63 aubio_schmittS16LE (aubio_pitchschmitt_t * p, uint_t nframes, 64 signed short int *indata) 60 65 { 61 66 uint_t i, j; … … 66 71 smpl_t period = 0., trigfact = 0.6; 67 72 68 for (i =0; i<nframes; i++) {73 for (i = 0; i < nframes; i++) { 69 74 *schmittPointer++ = indata[i]; 70 if (schmittPointer schmittBuffer >= (sint_t)blockSize) {75 if (schmittPointer  schmittBuffer >= (sint_t) blockSize) { 71 76 sint_t endpoint, startpoint, t1, t2, A1, A2, tc, schmittTriggered; 72 77 73 78 schmittPointer = schmittBuffer; 74 79 75 for (j=0,A1=0,A2=0; j<blockSize; j++) { 76 if (schmittBuffer[j]>0 && A1<schmittBuffer[j]) A1 = schmittBuffer[j]; 77 if (schmittBuffer[j]<0 && A2<schmittBuffer[j]) A2 = schmittBuffer[j]; 80 for (j = 0, A1 = 0, A2 = 0; j < blockSize; j++) { 81 if (schmittBuffer[j] > 0 && A1 < schmittBuffer[j]) 82 A1 = schmittBuffer[j]; 83 if (schmittBuffer[j] < 0 && A2 < schmittBuffer[j]) 84 A2 = schmittBuffer[j]; 78 85 } 79 t1 = (sint_t)(A1 * trigfact + 0.5);80 t2 =  (sint_t)(A2 * trigfact + 0.5);81 startpoint =0;82 for (j =1; schmittBuffer[j]<=t1 && j<blockSize; j++);83 for (; !(schmittBuffer[j] >=t2 &&84 schmittBuffer[j+1]< t2) && j<blockSize; j++);85 startpoint =j;86 schmittTriggered =0;87 endpoint =startpoint+1;88 for (j=startpoint,tc=0; j<blockSize; j++) {89 90 91 } else if (schmittBuffer[j]>=t2 && schmittBuffer[j+1]<t2) {92 endpoint=j;93 94 95 86 t1 = (sint_t) (A1 * trigfact + 0.5); 87 t2 = (sint_t) (A2 * trigfact + 0.5); 88 startpoint = 0; 89 for (j = 1; schmittBuffer[j] <= t1 && j < blockSize; j++); 90 for (; !(schmittBuffer[j] >= t2 && 91 schmittBuffer[j + 1] < t2) && j < blockSize; j++); 92 startpoint = j; 93 schmittTriggered = 0; 94 endpoint = startpoint + 1; 95 for (j = startpoint, tc = 0; j < blockSize; j++) { 96 if (!schmittTriggered) { 97 schmittTriggered = (schmittBuffer[j] >= t1); 98 } else if (schmittBuffer[j] >= t2 && schmittBuffer[j + 1] < t2) { 99 endpoint = j; 100 tc++; 101 schmittTriggered = 0; 102 } 96 103 } 97 104 if ((endpoint > startpoint) && (tc > 0)) { 98 period = (smpl_t)(endpointstartpoint)/tc;105 period = (smpl_t) (endpoint  startpoint) / tc; 99 106 } 100 107 } 101 108 } 102 109 103 p>schmittBuffer 110 p>schmittBuffer = schmittBuffer; 104 111 p>schmittPointer = schmittPointer; 105 112 return period; 106 113 } 107 114 108 void del_aubio_pitchschmitt (aubio_pitchschmitt_t *p) 115 void 116 del_aubio_pitchschmitt (aubio_pitchschmitt_t * p) 109 117 { 110 AUBIO_FREE (p>schmittBuffer);111 AUBIO_FREE (p);118 AUBIO_FREE (p>schmittBuffer); 119 AUBIO_FREE (p); 112 120 } 113
Note: See TracChangeset
for help on using the changeset viewer.