forked from gegel/pairphone
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmelpe_dec.c
55 lines (45 loc) · 1.12 KB
/
melpe_dec.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 "melpe/melpe.h"
// decode
int main(int argc, char *argv[])
{
FILE *fin;
FILE *fout;
unsigned char txbuf[11]; //buffer for encoded melpe frame or silency descryptor
unsigned char temp;
short spbuf[540]; //buffer for accumulate resampled voice up to melpe frame
if (argc < 3)
{
fprintf(stderr, "MELPe decoder with VAD.\n");
fprintf(stderr, "Usage: %s melpe_bitstream pcm_samples\n", argv[0]);
return -1;
}
fin = fopen(argv[1], "r");
fout = fopen(argv[2], "w");
if (!fin || !fout)
{
fprintf(stderr, "File could not be opened.\n");
return -1;
}
melpe_i();
while ( fread(txbuf, 1, 1, fin) == 1 )
{
if (txbuf[0] & 2) // VAD flag
{
memset(spbuf, 0, 540 * 2);
}
else
{
temp = txbuf[0];
fread(txbuf+1, 1, 10, fin);
txbuf[0] = txbuf[10];
txbuf[10] = temp;
melpe_s(spbuf, txbuf);
}
fwrite(spbuf, 2, 540, fout);
}
fclose(fin);
fclose(fout);
return 0;
}