// file: fbc_do_fft.C // // Function to perform FFT on all of the file. // #include "fbc.h" int fbc_do_fft_C(char* input_file, float sample_frequency, int fft_num, char* output_fft){ // open the input file // FILE* fp_in = fopen(input_file, "r"); if (fp_in == NULL) { printf("%s: error opening input file\n", input_file); return L_FALSE; } // create the output file // FILE* fp_out = fopen(output_fft, "w"); if (fp_out == NULL) { printf("%s: error creating output file\n", output_fft); return L_FALSE; } // compute the size of the file (this makes the code a little easier) // fseek(fp_in, 0, 2); int size_in_samples = ftell(fp_in) / sizeof(short int); rewind(fp_in); // compute frame duration so that there will be only one frame // compute window duration so that it is 1.5 times the frame duration float frame_duration = size_in_samples / sample_frequency - 1; float window_duration = size_in_samples / sample_frequency; // There will only be 1 frame // float num_frames = fbc_round_C((size_in_samples / sample_frequency) / frame_duration); int frame_number = 1; // Compute the number of samples in each window and each frame // int window_dur_samples = (int)fbc_round_C(window_duration * sample_frequency); int frame_dur_samples = (int)fbc_round_C(frame_duration * sample_frequency); // Determine if the number of samples in a frame is a value that is // 4^x. This is a requirement for the input to the Radix-4 FFT. The // input array for the fft must be of this size. The array will // be zero padded to all proper processing to the fft. // int powerofx = 0; while(pow(4,powerofx) < window_dur_samples){ powerofx = powerofx + 1; } int powerof_4_size = pow(4,powerofx); // Allocate buffers // float* buffer_in = (float*)malloc(window_dur_samples * sizeof(float)); double* fft_out = (double*)malloc(2 * powerof_4_size * sizeof(double)); double* temp_buffer_out = (double*)malloc(powerof_4_size * sizeof(double)); // // read the data // if (fbc_read_0_C(buffer_in, fp_in, frame_number, sample_frequency, frame_duration, window_duration) == L_FALSE) { printf("error reading data\n"); return L_FALSE; } // Copy buffer_out to temp_buffer_out to cure problem with data types // between the functions // for (int count1=0; count1