File: gen_impulse_h.c

package info (click to toggle)
gbsplay 0.0.99-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,044 kB
  • sloc: ansic: 8,360; sh: 1,667; makefile: 534; perl: 99; python: 72; xml: 13
file content (47 lines) | stat: -rw-r--r-- 1,225 bytes parent folder | download
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
/*
 * gbsplay is a Gameboy sound player
 *
 * 2003-2020 (C) by Tobias Diedrich <ranma+gbsplay@tdiedrich.de>
 *
 * Licensed under GNU GPL v1 or, at your option, any later version.
 */

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

#include "impulsegen.h"

#define IMPULSE_N_SHIFT 7 /* 128 shifted impulses */
#define IMPULSE_W_SHIFT 5 /* 32 samples per impulse */
#define IMPULSE_CUTOFF 1.0 /* Cutoff at nyquist limit (no cutoff) */

#define IMPULSE_WIDTH (1 << IMPULSE_W_SHIFT)
#define IMPULSE_W_MASK (IMPULSE_WIDTH - 1)
#define IMPULSE_N (1 << IMPULSE_N_SHIFT)
#define IMPULSE_N_MASK (IMPULSE_N - 1)

int main(int argc, char **argv)
{
	int32_t *impulsetab = gen_impulsetab(IMPULSE_W_SHIFT, IMPULSE_N_SHIFT, IMPULSE_CUTOFF);
	int n = (1 << IMPULSE_N_SHIFT) * (1 << IMPULSE_W_SHIFT);
	int i;

	if (impulsetab == NULL) {
		fprintf(stderr, "Failed to generate impulse table.");
		return 1;
	}

	printf("#define IMPULSE_N_SHIFT %d\n", IMPULSE_N_SHIFT);
	printf("#define IMPULSE_W_SHIFT %d\n", IMPULSE_W_SHIFT);
	printf("static const int32_t base_impulse[] = {");
	for (i=0; i<n; i++) {
		if ((i & IMPULSE_W_MASK) == 0) {
			printf("\n\t");
		}
		printf("%9d,", impulsetab[i]);
	}
	printf("\n};\n");

	return 0;
}