-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdecode.c
61 lines (53 loc) · 1.45 KB
/
decode.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
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "g711codec.h"
int main( int argc, char *argv[] )
{
if(argc < 3)
{
printf("==> Usage:\n\tdecode [src.g711a] [dest.pcm]\n");
//printf("==> Usage:\n\tdecode [src.g711u] [dest.pcm]\n");
return 0;
}
FILE *pInFile = fopen(argv[1], "rb");
FILE *pOutFile = fopen(argv[2], "wb");
if (NULL == pInFile || NULL == pOutFile)
{
printf("open file failed\n");
return 0;
}
struct stat s_buf;
int status = 0;
status = stat( argv[1], &s_buf );
printf("file_size = %d\n", s_buf.st_size);
int Ret = 0;
int Read = 0;
int DataLen = s_buf.st_size;
printf("datalen = %d, %s, %d\n", DataLen, __func__, __LINE__);
unsigned char ucInBuff[ DataLen + 1 ];
unsigned char ucOutBuff[ 2*DataLen + 1 ];
memset( ucInBuff, 0, sizeof(ucInBuff) );
memset( ucOutBuff, 0, sizeof(ucOutBuff) );
Read = fread( ucInBuff, 1, DataLen, pInFile );
printf("Read = %d, Ret = %d\n", Read, Ret);
if (Read)
{
Ret = G711a2PCM( (char *)ucInBuff, (char *)ucOutBuff, Read, 0 );
//Ret = G711u2PCM( (char *)ucInBuff, (char *)ucOutBuff, Read, 0 );
printf("Read = %d, Ret = %d, %s, %d\n", Read, Ret, __func__, __LINE__);
fwrite( ucOutBuff, 1, Ret, pOutFile );
memset( ucInBuff, 0, sizeof(ucInBuff) );
memset( ucOutBuff, 0, sizeof(ucOutBuff) );
}
else
{
printf("fread error !\n");
return -1;
}
fclose(pInFile);
fclose(pOutFile);
return 0;
}