Debian Codegraph @

src/equalizer.c

raw
1 /*
2 equalizer: code for loading equalizer settings
3
4 copyright 1995-2019 by the mpg123 project - free software under the terms of the LGPL 2.1
5 see COPYING and AUTHORS files in distribution or http://mpg123.org
6 initially written by Michael Hipp (exported to this file by Thomas Orgis)
7 */
8
9 #include "mpg123app.h"
10 #include "common/debug.h"
11
12 /* Load the settings from the path in the global variable equalfile.
13 If there is no file, restore equalizer defaults.
14 If NO_EQUALIZER is defined, it does nothing else that return zero */
15 int load_equalizer(mpg123_handle *mh)
16 {
17 #ifndef NO_EQUALIZER
18 if(equalfile != NULL)
19 { /* tst; ThOr: not TRUE or FALSE: allocated or not... */
20 FILE *fe;
21 int i;
22 fe = fopen(equalfile,"r");
23 if(fe) {
24 char line[256];
25 for(i=0;i<32;i++) {
26 float e0 = 1.0;
27 float e1 = 1.0; /* %f -> float! */
28 do /* ignore comments */
29 {
30 line[0]=0;
31 if(!fgets(line,255,fe))
32 {
33 error("equalizer file read error");
34 return -1;
35 }
36 }
37 while(line[0]=='#');
38 /* Hm, why not use fscanf? Comments... */
39 sscanf(line,"%f %f",&e0,&e1);
40 /* If scanning failed, we have default 1.0 value. */
41 mpg123_eq(mh, MPG123_LEFT, i, e0);
42 mpg123_eq(mh, MPG123_RIGHT, i, e1);
43 }
44 fclose(fe);
45 }
46 else
47 {
48 merror("Can't open equalizer file '%s'.",equalfile);
49 return -1;
50 }
51 }
52 else mpg123_reset_eq(mh);
53 #endif
54 return 0;
55 }