/* * moosynth.c * * Work out how to synthesize a cow * * (c) 2008 Thomas White * * This file is part of OpenMooCow - accelerometer moobox simulator * * OpenMooCow is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * OpenMooCow is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with OpenMooCow. If not, see . * */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fh; double *data; fftw_complex *ft; struct stat statbuf; fftw_plan plan; int samples; int16_t *sdata; int i, max_fq, c; double max_am, next_max_am, max_ph; const int ncomp = 20; int components[ncomp]; if ( argc != 2 ) { fprintf(stderr, "Syntax: %s \n", argv[0]); return 1; } /* Determine size of data */ if ( stat(argv[1], &statbuf) == -1 ) { fprintf(stderr, "Couldn't stat file '%s'\n", argv[1]); return 1; } samples = statbuf.st_size/2; /* Two bytes per sample, one channel */ printf("File size: %lli bytes\n", (long long int)statbuf.st_size); /* Read the data in */ fh = fopen(argv[1], "rb"); if ( fh == NULL ) { fprintf(stderr, "Couldn't open file '%s'\n", argv[1]); return 1; } sdata = malloc(samples*2); fread(sdata, 2, samples, fh); fclose(fh); data = fftw_malloc(samples*sizeof(double)); ft = fftw_malloc(samples*sizeof(fftw_complex)); for ( i=0; i max_am) && (am < next_max_am) ) { max_am = am; max_fq = i; max_ph = ph; } } printf("%2i %6i Hz %14.2f %+7.1f\n", c+1, (44100/samples)*max_fq, max_am, 180*(max_ph/M_PI)); components[c] = max_fq; next_max_am = max_am; } for ( i=0; i