-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdmp_file.c
55 lines (47 loc) · 1.19 KB
/
dmp_file.c
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
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "dmp_file.h"
#include "tools.h"
int dmp_file_load(struct dmp_file *f, uint8_t *data, size_t data_len, int system) {
memset(f, 0, sizeof(struct dmp_file));
if(data[0] != 9) {
fprintf(stderr, "Unsupported version 0x%02x (%d)\n", data[0], data[0]);
return -1;
}
if(data_len < 51) {
fprintf(stderr, "File too short %lu < 51\n", (unsigned long)data_len);
return -1;
}
f->version = data[0];
f->mode = data[1];
if(f->mode == 1) {
uint8_t *p = data + 2;
f->num_operators = *p++ == 0 ? 2 : 4;
f->lfo = *p++;
f->fb = *p++;
f->alg = *p++;
if(system == DMP_FILE_GENESIS) {
f->lfo2 = *p++;
}
for(int i = 0; i < f->num_operators; i++) {
f->operators[i].mult = *p++;
f->operators[i].tl = *p++;
f->operators[i].ar = *p++;
f->operators[i].dr = *p++;
f->operators[i].sl = *p++;
f->operators[i].rr = *p++;
f->operators[i].am = *p++;
if(system == DMP_FILE_GENESIS) {
f->operators[i].ksr = *p++;
f->operators[i].dt = *p++;
f->operators[i].d2r = *p++;
f->operators[i].ssg = *p++;
}
}
} else {
fprintf(stderr, "Unsupported mode %d\n", f->mode);
return -1;
}
return 0;
}