Mercurial > hg > midi-score-follower
comparison jnmr/DynamicVector.cpp @ 44:6c8a048720c3
improving functions in dynamic vector - to copy with changing offset in copyvector and the drawvector routine
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Wed, 01 Feb 2012 16:07:09 +0000 |
parents | fa527df85c2c |
children | 43edc8abe2a7 |
comparison
equal
deleted
inserted
replaced
43:732ce4711159 | 44:6c8a048720c3 |
---|---|
28 | 28 |
29 } | 29 } |
30 | 30 |
31 void DynamicVector::copyFromDynamicVector(const DynamicVector& dynamicVec){ | 31 void DynamicVector::copyFromDynamicVector(const DynamicVector& dynamicVec){ |
32 if (dynamicVec.length == length){ | 32 if (dynamicVec.length == length){ |
33 offset = dynamicVec.offset; | |
33 for (int i = 0;i < length;i++) | 34 for (int i = 0;i < length;i++) |
34 array[i] = dynamicVec.array[i]; | 35 array[i] = dynamicVec.array[i]; |
35 } | 36 } |
36 else{ | 37 else{ |
37 printf("CANNOT COPY VECTORS OF NON SAME LENGTH!!\n"); | 38 printf("CANNOT COPY VECTORS OF NON SAME LENGTH!!\n"); |
170 } | 171 } |
171 | 172 |
172 // addGaussianShapeByLookupTable(mean, StdDev, factor); | 173 // addGaussianShapeByLookupTable(mean, StdDev, factor); |
173 } | 174 } |
174 | 175 |
176 | |
177 void DynamicVector::addGaussianShapeFromRealTime(const double& actualTime, const double& StdDev, double factor){ | |
178 | |
179 double mean = getRealTermsAsIndex(actualTime); | |
180 printf("Gaussian realtime %f at index %f\n", actualTime, mean); | |
181 int i; | |
182 double std_dev_factor = (2*StdDev*StdDev); | |
183 factor *= (1/(StdDev*sqrt(2*PI))); | |
184 int maxVal = min((int) array.size(), (int)(mean + 4.8*StdDev)); | |
185 int minVal = max(0, (int)(mean - 4.8*StdDev)); | |
186 | |
187 for (i=minVal;i < maxVal;i++){ | |
188 array[i] += factor*exp(-1*(i-mean)*(i-mean)/(std_dev_factor)); | |
189 } | |
190 | |
191 // addGaussianShapeByLookupTable(mean, StdDev, factor); | |
192 } | |
193 | |
194 | |
175 void DynamicVector::addGaussianShapeByLookupTable(double& mean, double& StdDev, double factor){ | 195 void DynamicVector::addGaussianShapeByLookupTable(double& mean, double& StdDev, double factor){ |
176 int i; | 196 int i; |
177 int lookupIndex ; | 197 int lookupIndex ; |
178 factor *= (1/(StdDev*sqrt(2*PI))); | 198 factor *= (1/(StdDev*sqrt(2*PI))); |
179 for (i=0;i<array.size()-1;i++){ | 199 for (i=0;i<array.size()-1;i++){ |
255 double heightConstant = screenHeight / maxVal; | 275 double heightConstant = screenHeight / maxVal; |
256 int lastHeightPixel = heightConstant * (maxVal - array[startInt-1]); | 276 int lastHeightPixel = heightConstant * (maxVal - array[startInt-1]); |
257 int newHeightPixel; | 277 int newHeightPixel; |
258 for (int i = startInt;i < endInt;i++){ | 278 for (int i = startInt;i < endInt;i++){ |
259 newHeightPixel = (int) heightConstant * (maxVal - array[i]); | 279 newHeightPixel = (int) heightConstant * (maxVal - array[i]); |
260 ofLine (stepSize*(i-1), lastHeightPixel, stepSize*i, newHeightPixel); | 280 int xPos = i - startInt; |
281 ofLine (stepSize*(xPos-1), lastHeightPixel, stepSize*xPos, newHeightPixel); | |
261 lastHeightPixel = newHeightPixel; | 282 lastHeightPixel = newHeightPixel; |
262 } | 283 } |
263 | 284 |
264 } | 285 } |
265 | 286 |