Mercurial > hg > libxtract
annotate tests/xttest_util.cpp @ 267:41fe82c7ff80
Add more F0 tests
author | Jamie Bullock <jamie@jamiebullock.com> |
---|---|
date | Tue, 11 Nov 2014 16:15:28 +0000 |
parents | ecd6f2cf1346 |
children | 446f6d3dc809 |
rev | line source |
---|---|
jamie@264 | 1 |
jamie@264 | 2 |
jamie@264 | 3 #include "xttest_util.hpp" |
jamie@267 | 4 #include "xttest_tables.hpp" |
jamie@264 | 5 |
jamie@264 | 6 #include <random> |
jamie@264 | 7 |
jamie@264 | 8 #include <math.h> |
jamie@264 | 9 #include <stdio.h> |
jamie@264 | 10 |
jamie@264 | 11 |
jamie@264 | 12 #define XTTEST_2PI 6.28318530717958647693 |
jamie@264 | 13 |
jamie@264 | 14 void xttest_gen_sine(double *table, uint32_t tablesize, double samplerate, double frequency, double amplitude) |
jamie@264 | 15 { |
jamie@264 | 16 int samples_per_period = samplerate / frequency; |
jamie@264 | 17 |
jamie@267 | 18 for (uint32_t i = 0; i < tablesize; ++i) |
jamie@264 | 19 { |
jamie@264 | 20 int phase = i % samples_per_period; |
jamie@264 | 21 table[i] = sin((phase / (double)samples_per_period) * XTTEST_2PI) * amplitude; |
jamie@264 | 22 } |
jamie@264 | 23 } |
jamie@264 | 24 |
jamie@264 | 25 void xttest_gen_noise(double *table, uint32_t tablesize, double amplitude) |
jamie@264 | 26 { |
jamie@267 | 27 for (uint32_t i = 0; i < tablesize; ++i) |
jamie@264 | 28 { |
jamie@267 | 29 table[i] = xttest_noise1024[i] * amplitude; |
jamie@264 | 30 } |
jamie@264 | 31 } |
jamie@264 | 32 |
jamie@267 | 33 |
jamie@267 | 34 uint16_t xttest_ftom(double frequency) |
jamie@267 | 35 { |
jamie@267 | 36 return (int)roundf(6900.0 + 1200.0 * log2(frequency / 440.0)); |
jamie@267 | 37 } |
jamie@267 | 38 |
jamie@267 | 39 void xttest_add(double *table1, double *table2, uint32_t tablesize) |
jamie@267 | 40 { |
jamie@267 | 41 for (uint32_t i = 0; i < tablesize; ++i) |
jamie@267 | 42 { |
jamie@267 | 43 table1[i] += table2[i]; |
jamie@267 | 44 } |
jamie@267 | 45 } |
jamie@267 | 46 |
jamie@267 | 47 void xttest_mul(double *table, uint32_t tablesize, double constant) |
jamie@267 | 48 { |
jamie@267 | 49 for (uint32_t i = 0; i < tablesize; ++i) |
jamie@267 | 50 { |
jamie@267 | 51 table[i] *= constant; |
jamie@267 | 52 } |
jamie@267 | 53 } |
jamie@267 | 54 |
jamie@267 | 55 |