-
Notifications
You must be signed in to change notification settings - Fork 0
/
wav2text.c
46 lines (39 loc) · 805 Bytes
/
wav2text.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
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void) {
FILE *src;
FILE* dst;
int ret;
int cnt;
unsigned char buf[1024];
unsigned char temp_byte;
src = fopen("lovesong.wav", "rb");
cnt = 0;
// skip header
do {
ret = fread(&buf[cnt], 1, 1, src);
if (cnt >= 3 && (buf[cnt - 3] == 'd' &&
buf[cnt - 2] == 'a' &&
buf[cnt - 1] == 't' &&
buf[cnt ] == 'a')) {
// skip sub chunk size
cnt += 4;
break;
}
cnt++;
} while (ret != 0 && cnt < 1024);
dst = fopen("lovesong.h", "w");
do {
ret = fread(&temp_byte, 1, 1, src);
if (ret != 0) {
if (cnt % 16 == 0) {
fprintf(dst, "0x%02x,\n", temp_byte);
}
else {
fprintf(dst, "0x%02x, ", temp_byte);
}
cnt++;
}
} while (ret != 0);
return 0;
}