-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
adpcm-encode.c
45 lines (38 loc) · 873 Bytes
/
adpcm-encode.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
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "adpcm.h"
int main(int argc, char **argv) {
struct adpcm_status st;
adpcm_init(&st);
FILE *fin = stdin;
if(argc >= 2) {
fin = fopen(argv[1], "rb");
if(!fin) {
fprintf(stderr, "Could not open input file %s: %s (%d)\n", argv[1], strerror(errno), errno);
return 1;
}
}
FILE *fout = stdout;
if(argc >= 3) {
fout = fopen(argv[2], "wb");
if(!fout) {
fprintf(stderr, "Could not open output file %s: %s (%d)\n", argv[2], strerror(errno), errno);
return 1;
}
}
while(!feof(fin)) {
int16_t i;
fread(&i, sizeof(i), 1, fin);
i /= 16;
uint8_t u1 = adpcm_encode(i, &st);
fread(&i, sizeof(i), 1, fin);
i /= 16;
uint8_t u2 = adpcm_encode(i, &st);
uint8_t u = (u2 << 4) | (u1 & 0x0f);
fwrite(&u, 1, 1, fout);
}
return 0;
}