filter_frequencies.c 2.14 KB
Newer Older
Tilman Steinweg's avatar
Tilman Steinweg committed
1
/*-----------------------------------------------------------------------------------------
2
 * Copyright (C) 2016  For the list of authors, see file AUTHORS.
Tilman Steinweg's avatar
Tilman Steinweg committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
 *
 * This file is part of DENISE.
 * 
 * DENISE 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, version 2.0 of the License only.
 * 
 * DENISE 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 DENISE. See file COPYING and/or <http://www.gnu.org/licenses/gpl-2.0.html>.
-----------------------------------------------------------------------------------------*/

/* 
   Reading filter frequencies for the time domain filter from FREQ_FILE.
   
   T. Metz 02,2014 
*/

#include "fd.h"

float *filter_frequencies(int *nfrq){

extern char FREQ_FILE[STRING_SIZE];
extern FILE *FP;

FILE *freqf;
char cline[256];
int IT=1;
float *FC;


/*----------------------------------- open FREQ_FILE ------------------------------*/
fprintf(FP,"\n\n ------------------- FREQUENCY FILTERING --------------------------\n");

freqf=fopen(FREQ_FILE,"r");

if (freqf==NULL) err(" Freqency file could not be opened !");
*nfrq=0;

fprintf(FP,"\n Reading frequencies from %s \n",FREQ_FILE);

/*----------------------Read Number of requencies defined in FREQ_FILE-------------*/
fscanf(freqf,"%i",nfrq);

/*----------------------------alocate frequency array------------------------------*/
FC=vector(1,*nfrq);
//FC = malloc((*nfrq+1) * sizeof(float));

rewind (freqf);
fprintf(FP," Number of freqencies specified: %d \n",*nfrq);

/*----------------------Read frequencies from FREQ_FILE----------------------------*/
for (IT=1;IT<=(*nfrq);IT++){
      fgets(cline,255,freqf);
      fscanf(freqf,"%f",&FC[IT]);
      //Read only numbers from FREQ_FILE 
      if(FC[IT]==0){
      IT=IT-1;}else{
      fprintf(FP,"\n %d. %.2f Hz",IT,FC[IT]);
      }
}

fclose(freqf);

return(FC);
}