Mercurial > hg > libxtract
comparison src/scalar.c @ 227:cabf2f465d1b
tristimulus1 correction
author | Sean Enderby <sean.enderby@gmail.com> |
---|---|
date | Tue, 25 Feb 2014 13:19:04 +0000 |
parents | 62e797c2974a |
children | cccd314664ac |
comparison
equal
deleted
inserted
replaced
226:223febe2688b | 227:cabf2f465d1b |
---|---|
296 *result = (double)(num / den); | 296 *result = (double)(num / den); |
297 | 297 |
298 return XTRACT_SUCCESS; | 298 return XTRACT_SUCCESS; |
299 } | 299 } |
300 | 300 |
301 /* | |
302 *int xtract_tristimulus_1(const double *data, const int N, const void *argv, double *result) | |
303 *{ | |
304 * | |
305 * int n = N; | |
306 * | |
307 * double den, p1, temp; | |
308 * | |
309 * den = p1 = temp = 0.0; | |
310 * | |
311 * for(n = 0; n < N; n++) | |
312 * { | |
313 * if((temp = data[n])) | |
314 * { | |
315 * den += temp; | |
316 * if(!p1) | |
317 * p1 = temp; | |
318 * } | |
319 * } | |
320 * | |
321 * if(den == 0.0 || p1 == 0.0) | |
322 * { | |
323 * *result = 0.0; | |
324 * return XTRACT_NO_RESULT; | |
325 * } | |
326 * else | |
327 * { | |
328 * *result = p1 / den; | |
329 * return XTRACT_SUCCESS; | |
330 * } | |
331 *} | |
332 * | |
333 *int xtract_tristimulus_2(const double *data, const int N, const void *argv, double *result) | |
334 *{ | |
335 * | |
336 * int n = N; | |
337 * | |
338 * double den, p2, p3, p4, ps, temp; | |
339 * | |
340 * den = p2 = p3 = p4 = ps = temp = 0.0; | |
341 * | |
342 * for(n = 0; n < N; n++) | |
343 * { | |
344 * if((temp = data[n])) | |
345 * { | |
346 * den += temp; | |
347 * if(!p2) | |
348 * p2 = temp; | |
349 * else if(!p3) | |
350 * p3 = temp; | |
351 * else if(!p4) | |
352 * p4 = temp; | |
353 * } | |
354 * } | |
355 * | |
356 * ps = p2 + p3 + p4; | |
357 * | |
358 * if(den == 0.0 || ps == 0.0) | |
359 * { | |
360 * *result = 0.0; | |
361 * return XTRACT_NO_RESULT; | |
362 * } | |
363 * else | |
364 * { | |
365 * *result = ps / den; | |
366 * return XTRACT_SUCCESS; | |
367 * } | |
368 * | |
369 *} | |
370 * | |
371 *int xtract_tristimulus_3(const double *data, const int N, const void *argv, double *result) | |
372 *{ | |
373 * | |
374 * int n = N, count = 0; | |
375 * | |
376 * double den, num, temp; | |
377 * | |
378 * den = num = temp = 0.0; | |
379 * | |
380 * for(n = 0; n < N; n++) | |
381 * { | |
382 * if((temp = data[n])) | |
383 * { | |
384 * den += temp; | |
385 * if(count >= 5) | |
386 * num += temp; | |
387 * count++; | |
388 * } | |
389 * } | |
390 * | |
391 * if(den == 0.0 || num == 0.0) | |
392 * { | |
393 * *result = 0.0; | |
394 * return XTRACT_NO_RESULT; | |
395 * } | |
396 * else | |
397 * { | |
398 * *result = num / den; | |
399 * return XTRACT_SUCCESS; | |
400 * } | |
401 *} | |
402 */ | |
403 | |
301 int xtract_tristimulus_1(const double *data, const int N, const void *argv, double *result) | 404 int xtract_tristimulus_1(const double *data, const int N, const void *argv, double *result) |
302 { | 405 { |
303 | 406 int n = N >> 1, h = 0, i; |
304 int n = N; | 407 double den = 0.0, p1 = 0.0, fund = 0.0, temp = 0.0; |
305 | 408 const double *freqs; |
306 double den, p1, temp; | 409 |
307 | 410 fund = *(double *)argv; |
308 den = p1 = temp = 0.0; | 411 freqs = data + n; |
309 | 412 |
310 for(n = 0; n < N; n++) | 413 for(i = 0; i < n; i++) |
311 { | 414 { |
312 if((temp = data[n])) | 415 if((temp = data[i])) |
313 { | 416 { |
314 den += temp; | 417 den += temp; |
315 if(!p1) | 418 h = round(freqs[i] / fund); |
316 p1 = temp; | 419 if(h == 1) |
420 p1 += temp; | |
317 } | 421 } |
318 } | 422 } |
319 | 423 |
320 if(den == 0.0 || p1 == 0.0) | 424 if(den == 0.0 || p1 == 0.0) |
321 { | 425 { |