diff options
Diffstat (limited to 'apps/codecs/dumb/src/it/itorder.c')
-rw-r--r-- | apps/codecs/dumb/src/it/itorder.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/apps/codecs/dumb/src/it/itorder.c b/apps/codecs/dumb/src/it/itorder.c new file mode 100644 index 0000000000..6959f05443 --- /dev/null +++ b/apps/codecs/dumb/src/it/itorder.c | |||
@@ -0,0 +1,63 @@ | |||
1 | /* _______ ____ __ ___ ___ | ||
2 | * \ _ \ \ / \ / \ \ / / ' ' ' | ||
3 | * | | \ \ | | || | \/ | . . | ||
4 | * | | | | | | || ||\ /| | | ||
5 | * | | | | | | || || \/ | | ' ' ' | ||
6 | * | | | | | | || || | | . . | ||
7 | * | |_/ / \ \__// || | | | ||
8 | * /_______/ynamic \____/niversal /__\ /____\usic /| . . ibliotheque | ||
9 | * / \ | ||
10 | * / . \ | ||
11 | * itorder.c - Code to fix invalid patterns in / / \ \ | ||
12 | * the pattern table. | < / \_ | ||
13 | * | \/ /\ / | ||
14 | * By Julien Cugniere. \_ / > / | ||
15 | * | \ / / | ||
16 | * | ' / | ||
17 | * \__/ | ||
18 | */ | ||
19 | |||
20 | |||
21 | |||
22 | #include <stdlib.h> | ||
23 | |||
24 | #include "dumb.h" | ||
25 | #include "internal/it.h" | ||
26 | |||
27 | |||
28 | |||
29 | /* This function ensures that any pattern mentioned in the order table but | ||
30 | * not present in the pattern table is treated as an empty 64 rows pattern. | ||
31 | * This is done by adding such a dummy pattern at the end of the pattern | ||
32 | * table, and redirect invalid orders to it. | ||
33 | * Patterns 254 and 255 are left untouched, unless the signal is an XM. | ||
34 | */ | ||
35 | int _dumb_it_fix_invalid_orders(DUMB_IT_SIGDATA *sigdata) | ||
36 | { | ||
37 | int i; | ||
38 | int found_some = 0; | ||
39 | |||
40 | int first_invalid = sigdata->n_patterns; | ||
41 | int last_invalid = (sigdata->flags & IT_WAS_AN_XM) ? 255 : 253; | ||
42 | |||
43 | for (i = 0; i < sigdata->n_orders; i++) { | ||
44 | if (sigdata->order[i] >= first_invalid && sigdata->order[i] <= last_invalid) { | ||
45 | sigdata->order[i] = sigdata->n_patterns; | ||
46 | found_some = 1; | ||
47 | } | ||
48 | } | ||
49 | |||
50 | if (found_some) { | ||
51 | IT_PATTERN *new_pattern = realloc(sigdata->pattern, sizeof(*sigdata->pattern) * (sigdata->n_patterns + 1)); | ||
52 | if (!new_pattern) | ||
53 | return -1; | ||
54 | |||
55 | new_pattern[sigdata->n_patterns].n_rows = 64; | ||
56 | new_pattern[sigdata->n_patterns].n_entries = 0; | ||
57 | new_pattern[sigdata->n_patterns].entry = NULL; | ||
58 | sigdata->pattern = new_pattern; | ||
59 | sigdata->n_patterns++; | ||
60 | } | ||
61 | |||
62 | return 0; | ||
63 | } | ||