aboutsummaryrefslogtreecommitdiffstats
path: root/test/main.c
blob: 6565ce1c4d67b649da4cb784b7ea0070e02a94c3 (plain) (blame)
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
#include "common.h"

void usage(const char* selfname) {
	fprintf(stderr, "GHA simple utility, usage: %s <FILE> <OFFSET> <LEN> [<EXPECTED_FREQ> <EXPECTED_PHASE> <EXPECTED_MAGNITUDE>]\n", selfname);
	fprintf(stderr, "FILE - input pcm file (raw pcm, mono, 24 bit, 44100 kHz\n");
	fprintf(stderr, "OFFSET - offset in input file, samples\n");
	fprintf(stderr, "LEN - len to process, samples\n");
	fprintf(stderr, "Following options are optional used by test framework:\n");
	fprintf(stderr, "EXPECTED_FREQ - expected angular frequency\n");
	fprintf(stderr, "EXPECTED_PHASE - expected phase (0 - 2Pi)\n");
	fprintf(stderr, "EXPECTED_MAGNITUDE - expected magnitude (0 - 1)\n");
}


int main(int argc, char** argv) {
	if (argc != 4 && argc != 7) {
		usage(argv[0]);
		return 1;
	}

	long long len = atoll(argv[3]);

	gha_ctx_t ctx;

	FLOAT* buf = malloc(len * sizeof(FLOAT));
	if (!buf)
		abort();

	if (load_file(argv[1], len, atoi(argv[2]), 24, buf)) {
		free(buf);
		return 1;
	}


	ctx = gha_create_ctx(len);
	if (!ctx) {
		fprintf(stderr, "Unable to create gha ctx\n");
		free(buf);
		return 1;
	}

	struct gha_info res;
	gha_analyze_one(buf, &res, ctx);

	gha_free_ctx(ctx);
	free(buf);

	if (argc == 7) {
		double freq = atof(argv[4]);
		double phase = atof(argv[5]);
		double magn = atof(argv[6]);
		if (fabs(freq - res.frequency) > 0.001 || compare_phase(phase, res.phase, 0.01) || fabs(magn - res.magnitude) > 0.001)
			return 1;
		return 0;
	} else {
	    fprintf(stderr, "Result: freq: %f, phase: %f, magn: %f\n", res.frequency, res.phase, res.magnitude);
	}

	return 0;
}