File: peakdump.c

package info (click to toggle)
ardour 1:5.12.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 74,708 kB
  • sloc: cpp: 512,951; xml: 123,656; ansic: 65,010; python: 22,599; sh: 5,368; asm: 1,347; perl: 888; php: 770; makefile: 253; objc: 28
file content (49 lines) | stat: -rw-r--r-- 933 bytes parent folder | download | duplicates (2)
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
// gcc -o peakdump peakdump.c -Wall -O3 -lm
// inspect ardour .peak files

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define _FPP 256

int main (int argc, char **argv) {
	int c = 0, d = 0;
	float thresh = -1.f;

	if (argc < 2 || argc > 3) {
		fprintf(stderr, "usage: %s [threshold] <peakfile>\n", argv[0]);
		return -1;
	}

	if (argc == 3) {
		thresh = atof(argv[1]);
	}

	FILE *F = fopen(argv[argc-1], "r");

	if (!F) {
		fprintf(stderr, "Cannot open file '%s'\n", argv[argc-1]);
		return -1;
	}

	printf("   #    )   audio sample range   :   MIN    MAX\n");
	while (!feof(F)) {
		struct PeakData {
			float min;
			float max;
		} buf;

		if (fread(&buf, sizeof(struct PeakData), 1, F) <= 0) {
			break;
		}
		if (fabsf(buf.min) > thresh || fabsf(buf.max) > thresh) {
			printf("%8d) %10d - %10d: %+.3f %+.3f\n", ++d,
					_FPP * c, _FPP * (c + 1) - 1,
					buf.min, buf.max);
		}
		++c;
	}
	fclose(F);
	return 0;
}