FreeCalypso > hg > freecalypso-tools
annotate ringtools/fc-pwt-comp.c @ 1006:c3837867f631
Installed-binaries: new standardized packaging aid
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 10 Dec 2023 00:56:31 +0000 |
parents | 16e259bff02b |
children |
rev | line source |
---|---|
867
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This program compiles a FreeCalypso PWT melody from our ASCII source |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * format into the compact binary format that will be uploaded into |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * FC device FFS for use by our BUZM melody player engine. |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * The binary format going into FFS consists of 4-byte records; |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 * each record has the following format: |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 * |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 * 1 byte: PWT note code [0,47] going directly into hw register |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 * 1 byte: tone volume in [1,64] range, or 0 means rest period |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 * 2 bytes LE: tone or rest duration in TDMA frames |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <stdio.h> |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include <stdlib.h> |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 #include <ctype.h> |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 #include <string.h> |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 #include <strings.h> |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 static struct pwt_note { |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 char *name; |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 int code; |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 } pwt_notes_table[] = { |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 {"f4", 47}, /* 349 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 {"fs4", 43}, /* 370 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 {"g4", 39}, /* 392 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 {"gs4", 35}, /* 415 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 {"a4", 31}, /* 440 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 {"as4", 27}, /* 466 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 {"b4", 23}, /* 494 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 {"c5", 19}, /* 523 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 {"cs5", 15}, /* 554 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 {"d5", 11}, /* 587 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 {"ds5", 7}, /* 622 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 {"e5", 3}, /* 659 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 {"f5", 46}, /* 698 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 {"fs5", 42}, /* 740 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 {"g5", 38}, /* 784 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 {"gs5", 34}, /* 831 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 {"a5", 30}, /* 880 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 {"as5", 26}, /* 932 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 {"b5", 22}, /* 988 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 {"c6", 18}, /* 1047 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 {"cs6", 14}, /* 1109 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 {"d6", 10}, /* 1175 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 {"ds6", 6}, /* 1245 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 {"e6", 2}, /* 1319 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 {"f6", 45}, /* 1397 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 {"fs6", 41}, /* 1480 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 {"g6", 37}, /* 1568 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 {"gs6", 33}, /* 1661 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 {"a6", 29}, /* 1760 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 {"as6", 25}, /* 1865 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 {"b6", 21}, /* 1976 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 {"c7", 17}, /* 2093 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 {"cs7", 13}, /* 2217 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 {"d7", 9}, /* 2349 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 {"ds7", 5}, /* 2489 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 {"e7", 1}, /* 2637 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 {"f7", 44}, /* 2794 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 {"fs7", 40}, /* 2960 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 {"g7", 36}, /* 3136 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 {"gs7", 32}, /* 3322 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 {"a7", 28}, /* 3520 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 {"as7", 24}, /* 3729 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 {"b7", 20}, /* 3951 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 {"c8", 16}, /* 4186 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 {"cs8", 12}, /* 4435 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 {"d8", 8}, /* 4699 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 {"ds8", 4}, /* 4978 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 {"e8", 0}, /* 5274 Hz */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 /* table search terminator */ |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 {0, -1} |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 }; |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 char *infname, *outfname; |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 FILE *inf, *outf; |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 char linebuf[256], *fields[3]; |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 int lineno, nfields; |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 parse_line_into_fields() |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 { |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 char *cp; |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 cp = index(linebuf, '\n'); |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 if (!cp) { |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 fprintf(stderr, "%s line %d: missing newline\n", |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 infname, lineno); |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 exit(1); |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 } |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 cp = linebuf; |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 nfields = 0; |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 for (;;) { |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 while (isspace(*cp)) |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 cp++; |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 if (*cp == '\0' || *cp == '#') |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 break; |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 if (nfields >= 3) { |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 fprintf(stderr, "%s line %d: too many fields\n", |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 infname, lineno); |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 exit(1); |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 } |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 fields[nfields++] = cp; |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 while (*cp && !isspace(*cp)) |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 cp++; |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 if (*cp) |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 *cp++ = '\0'; |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 } |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 } |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 emit_record(freq, volume, duration) |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 unsigned freq, volume, duration; |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 { |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 putc(freq, outf); |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 putc(volume, outf); |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 putc(duration & 0xFF, outf); |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 putc(duration >> 8, outf); |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 } |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 process_tone_entry() |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 { |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 struct pwt_note *tp; |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 unsigned note_vol, duration; |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 for (tp = pwt_notes_table; tp->name; tp++) |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 if (!strcmp(tp->name, fields[0])) |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 break; |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 if (tp->code < 0) { |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 fprintf(stderr, "%s line %d: invalid note name\n", |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 infname, lineno); |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 exit(1); |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 } |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 note_vol = strtoul(fields[1], 0, 0); |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 if (note_vol < 1 || note_vol > 64) { |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 fprintf(stderr, "%s line %d: invalid note volume\n", |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 infname, lineno); |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 exit(1); |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 } |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 duration = strtoul(fields[2], 0, 0); |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 if (duration < 1 || duration > 0xFFFF) { |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 fprintf(stderr, |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 "%s line %d: the duration number is out of range\n", |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 infname, lineno); |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 exit(1); |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 } |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 emit_record(tp->code, note_vol, duration); |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 } |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 process_rest_entry() |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 { |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 unsigned duration; |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 duration = strtoul(fields[1], 0, 0); |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 if (duration < 1 || duration > 0xFFFF) { |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 fprintf(stderr, |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 "%s line %d: the duration number is out of range\n", |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 infname, lineno); |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 exit(1); |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 } |
884
8eb1f60f6676
ringtools/fc-pwt-comp.c: rm redundant type cast
Mychaela Falconia <falcon@freecalypso.org>
parents:
867
diff
changeset
|
160 emit_record(0, 0, duration); |
867
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 } |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 main(argc, argv) |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 char **argv; |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 { |
885
16e259bff02b
fc-pwt-comp: explicitly reject empty input
Mychaela Falconia <falcon@freecalypso.org>
parents:
884
diff
changeset
|
166 int nonempty; |
16e259bff02b
fc-pwt-comp: explicitly reject empty input
Mychaela Falconia <falcon@freecalypso.org>
parents:
884
diff
changeset
|
167 |
867
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 if (argc != 3) { |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 fprintf(stderr, "usage: %s src-file bin-file\n", argv[0]); |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 exit(1); |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 } |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 if (strcmp(argv[1], "-")) { |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 infname = argv[1]; |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 inf = fopen(infname, "r"); |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 if (!inf) { |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 perror(infname); |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 exit(1); |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 } |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 } else { |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 infname = "stdin"; |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 inf = stdin; |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 } |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 outfname = argv[2]; |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 outf = fopen(outfname, "w"); |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 if (!outf) { |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 perror(outfname); |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 exit(1); |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 } |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 |
885
16e259bff02b
fc-pwt-comp: explicitly reject empty input
Mychaela Falconia <falcon@freecalypso.org>
parents:
884
diff
changeset
|
190 nonempty = 0; |
867
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) { |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 parse_line_into_fields(); |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 if (!nfields) |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 continue; |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 if (nfields == 3) |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 process_tone_entry(); |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 else if (nfields == 2 && !strcmp(fields[0], "rest")) |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
198 process_rest_entry(); |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 else { |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
200 fprintf(stderr, "%s line %d: invalid syntax\n", |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
201 infname, lineno); |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
202 exit(1); |
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 } |
885
16e259bff02b
fc-pwt-comp: explicitly reject empty input
Mychaela Falconia <falcon@freecalypso.org>
parents:
884
diff
changeset
|
204 nonempty = 1; |
867
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
205 } |
885
16e259bff02b
fc-pwt-comp: explicitly reject empty input
Mychaela Falconia <falcon@freecalypso.org>
parents:
884
diff
changeset
|
206 if (nonempty) |
16e259bff02b
fc-pwt-comp: explicitly reject empty input
Mychaela Falconia <falcon@freecalypso.org>
parents:
884
diff
changeset
|
207 exit(0); |
16e259bff02b
fc-pwt-comp: explicitly reject empty input
Mychaela Falconia <falcon@freecalypso.org>
parents:
884
diff
changeset
|
208 else { |
16e259bff02b
fc-pwt-comp: explicitly reject empty input
Mychaela Falconia <falcon@freecalypso.org>
parents:
884
diff
changeset
|
209 fprintf(stderr, "error: %s is empty\n", infname); |
16e259bff02b
fc-pwt-comp: explicitly reject empty input
Mychaela Falconia <falcon@freecalypso.org>
parents:
884
diff
changeset
|
210 exit(1); |
16e259bff02b
fc-pwt-comp: explicitly reject empty input
Mychaela Falconia <falcon@freecalypso.org>
parents:
884
diff
changeset
|
211 } |
867
dfd98dd46068
ringtools: fc-pwt-comp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 } |