#include #include #include #include #include #include #define SAMPLING_RATE 44100.0 #define CHANNELS_NUMBER 1 #define N 1024 #define real double typedef real frame[N]; typedef complex spectrum[N]; /* input */ static char *SOUND_FILE_NAME_READ = "tmp-in.raw"; static real cache_in[N/2]; FILE * sound_file_open_read (char *sound_file_name) { #define MAX_CMD 256 char cmd[MAX_CMD]; assert (sound_file_name); snprintf (cmd, MAX_CMD, "sox %s -c %d -r %d -e signed-integer -b 16 %s", sound_file_name, CHANNELS_NUMBER, (int)SAMPLING_RATE, SOUND_FILE_NAME_READ); system (cmd); bzero (cache_in, N/2*sizeof(real)); return fopen (SOUND_FILE_NAME_READ, "rb"); } void sound_file_close_read (FILE *fp) { assert (fp); fclose (fp); unlink (SOUND_FILE_NAME_READ); } int sound_file_read (FILE *fp, frame s) { int result; int i; static short tmp[N/2*CHANNELS_NUMBER]; assert (fp && s); for (i=0; i 1) ? 32767 : (short) (v * 32767); cache_out[i] = s[N/2+i]; int channel; for (channel=0; channel\n", argv[0]); exit (EXIT_FAILURE); } /* init */ //fft_init (); input = sound_file_open_read (argv[1]); output = sound_file_open_write (); /* process */ while (sound_file_read (input, s)) { /* ANALYSIS */ sound_file_write (s, output); } /* exit */ sound_file_close_write (output); sound_file_close_read (input); //fft_exit (); exit (EXIT_SUCCESS); return 0; }