-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathphon2spl.c
More file actions
94 lines (75 loc) · 2.82 KB
/
phon2spl.c
File metadata and controls
94 lines (75 loc) · 2.82 KB
1
2
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/***************************************************************************
* Copyright (C) 2014 by Serge Poltavski *
* serge.poltavski@gmail.com *
* *
* This program 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. *
* *
* This program 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 this program. If not, see <http://www.gnu.org/licenses/> *
***************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include "iso226.h"
static const char * const PROGRAMM_NAME = "phon2spl";
static struct option long_options[] = {
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'},
{0, 0, 0, 0}
};
static const char * short_options = "hV";
static void usage() {
puts ("Converts PHON volume to SPL in db, according to ISO 226 equal-loudness level contours.");
printf(" Usage: %s PHON FREQUENCY\n\n", PROGRAMM_NAME);
}
static void parse_options(int argc, char * argv[]) {
int c = 0;
int option_index = 0;
while (1) {
c = getopt_long (argc, argv, short_options, long_options, &option_index);
if (c == -1)
break;
switch (c) {
case 'h':
usage();
exit(EXIT_SUCCESS);
break;
case 'V':
printf("%s %s\n", PROGRAMM_NAME, ISO226_LIBRARY_VERSION);
exit(EXIT_SUCCESS);
break;
case '?':
usage();
exit(EXIT_FAILURE);
break;
}
}
if(argc != 3) {
usage();
exit(EXIT_FAILURE);
}
}
int main(int argc, char * argv[]) {
double fon = 0;
double freq = 0;
double res = 0;
int ret;
parse_options(argc, argv);
fon = strtod(argv[1], NULL);
freq = strtod(argv[2], NULL);
ret = iso226_phon2spl(fon, freq, &res);
if(ret != 0) {
fprintf(stderr, "%s\n", iso226_strerror(ret));
return ret;
}
printf("%f\n", res);
return EXIT_SUCCESS;
}