mirror of
https://github.com/BlackLight/Voxifera.git
synced 2024-11-24 04:25:11 +01:00
Small code optimizations (moved constants to define(s) ) .
This commit is contained in:
parent
c80f671655
commit
8d23b07db0
2 changed files with 7 additions and 7 deletions
11
main.c
11
main.c
|
@ -38,7 +38,7 @@ inline double taylor_cosine( double x, int terms ) {
|
|||
quadrant = x * TWO_O_M_PI; /* 0, 1, 2 o 3 */
|
||||
double x2, r;
|
||||
|
||||
/* tariamo x in modo tale che −π/2 < x < π/2 */
|
||||
/* tariamo x in modo tale che −π < x < π */
|
||||
x = x - quadrant * H_M_PI;
|
||||
quadrant += 1;
|
||||
x = offset[ (quadrant >> 1) & 1 ] - x;
|
||||
|
@ -68,7 +68,6 @@ void helpandusage() {
|
|||
|
||||
int main (int argc, char **argv) {
|
||||
int i, j, dsp, fd, ch, size, recognized;
|
||||
int TOTSIZE = BUF_SIZE*SAMPLE_SIZE;
|
||||
|
||||
char *line, *tmp, *cmd = NULL, *fname = NULL, *device = NULL;
|
||||
char **match = NULL;
|
||||
|
@ -76,8 +75,6 @@ int main (int argc, char **argv) {
|
|||
double deviance;
|
||||
double *neutral, *trans;
|
||||
double value, sum = 0.0;
|
||||
double PIconst = (D_M_PI/TOTSIZE);
|
||||
double coeff = 1.0 / TOTSIZE;
|
||||
double t, v;
|
||||
|
||||
FILE *fp;
|
||||
|
@ -140,21 +137,21 @@ int main (int argc, char **argv) {
|
|||
for( j = 0; j < TOTSIZE; ++j ){
|
||||
v += buf[j];
|
||||
}
|
||||
v *= coeff;
|
||||
v *= M_COEFF;
|
||||
v -= neutral[0];
|
||||
v = (v >= 0) ? v : -v;
|
||||
trans[0] = log(v);
|
||||
|
||||
double init = buf[0];
|
||||
for( i = 1; i < TOTSIZE; ++i ) {
|
||||
t = PIconst * i;
|
||||
t = M_FACTOR * i;
|
||||
v = init;
|
||||
/* dato che ho inizializzato v a buf[0] e sono sicuro che t != 0,
|
||||
* posso partire da j = 1 . */
|
||||
for( j = 1; j < TOTSIZE; ++j ){
|
||||
v += buf[j] * taylor_cosine( t * j, 10 );
|
||||
}
|
||||
v *= coeff;
|
||||
v *= M_COEFF;
|
||||
v -= neutral[i];
|
||||
v = (v >= 0) ? v : -v;
|
||||
trans[i] = log(v);
|
||||
|
|
3
vocal.h
3
vocal.h
|
@ -37,6 +37,9 @@
|
|||
|
||||
#define BUF_SIZE 2
|
||||
#define SAMPLE_SIZE (int) (LENGTH*RATE*SIZE*CHANNELS/8)
|
||||
#define TOTSIZE 16000 /* BUF_SIZE * SAMPLE_SIZE */
|
||||
#define M_FACTOR 0.000392699 /* D_M_PI / TOTSIZE */
|
||||
#define M_COEFF 0.0000625 /* 1.0 / TOTSIZE */
|
||||
|
||||
#ifndef M_PI
|
||||
# define M_PI 3.14159265358979323846
|
||||
|
|
Loading…
Reference in a new issue