-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathraw_to_syx.c
88 lines (68 loc) · 1.62 KB
/
raw_to_syx.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../libanalogrytm/inc_ar.h"
#define BUF_SIZE (1024 * 1024 * 4u)
static void load_file(sU8 *syx, const char *fname, sU32 *retSize) {
FILE *fh;
*retSize = 0;
fh = fopen(fname, "rb");
if(NULL != fh)
{
long sz;
fseek(fh, 0, SEEK_END);
sz = ftell(fh);
fseek(fh, 0, SEEK_SET);
if(sz <= BUF_SIZE)
{
*retSize = (sU32) fread(syx, 1, sz, fh);
if(*retSize > BUF_SIZE)
{
*retSize = 0;
}
}
fclose(fh);
}
}
static void save_file(sU8 *data, sU32 dataSize, const char *fname) {
FILE *fh;
fh = fopen(fname, "wb");
if(NULL != fh)
{
(void)fwrite(data, 1, dataSize, fh);
fclose(fh);
}
}
static void tc_pattern_raw_to_syx(sU8 *raw, sU8 *syx, const char *fname) {
sU32 rawSz;
sU32 syxSz;
ar_sysex_meta_t meta;
char outfname[2048];
sprintf(outfname,"%s.syx",fname);
S_U16_SET(meta.container_version,257);
meta.dev_id = 0;
meta.obj_type = 2;
meta.obj_nr = 128;
ar_error_t err;
load_file(raw, fname, &rawSz);
err = ar_pattern_raw_to_syx(syx, raw, rawSz, &syxSz, &meta);
if (AR_ERR_OK == err) {
save_file(syx, syxSz, outfname);
printf("done\n");
} else {
printf("error: %u\n", err);
}
}
int main(int argc, char**argv) {
sU8 *buf = malloc(BUF_SIZE * 3);
sU8 *syx = buf + BUF_SIZE;
sU8 *resyx = buf + (BUF_SIZE * 2);
(void)argc;
(void)argv;
memset(buf, 0xCC, BUF_SIZE * 3);
for (int i = 1; i < argc; i++) {
tc_pattern_raw_to_syx(buf, syx, argv[i]);
}
free(buf);
return 0;
}