-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathg711.c
95 lines (80 loc) · 2.76 KB
/
g711.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
89
90
91
92
93
94
#include <stdio.h>
#include "g711codec.h"
/*
* function: convert PCM audio format to g711 alaw/ulaw.(zqj)
* InAudioData: PCM data prepared for encoding to g711 alaw/ulaw.
* OutAudioData: encoded g711 alaw/ulaw.
* DataLen: PCM data size.
* reserve: reserved param, no use.
*/
/*alaw*/
int PCM2G711a( char *InAudioData, char *OutAudioData, int DataLen, int reserve )
{
//check params.
if( (NULL == InAudioData) && (NULL == OutAudioData) && (0 == DataLen) )
{
printf("Error, empty data or transmit failed, exit !\n");
return -1;
}
printf("DataLen = %d, %s, %d\n", DataLen, __func__, __LINE__);
int Retaen = 0;
printf("G711a encode start......\n");
Retaen = g711a_encode( (unsigned char *)OutAudioData, (short*)InAudioData, DataLen/2 );
printf("Retaen = %d, %s, %d\n", Retaen, __func__, __LINE__);
return Retaen; //index successfully encoded data len.
}
/*ulaw*/
int PCM2G711u( char *InAudioData, char *OutAudioData, int DataLen, int reserve )
{
//check params.
if( (NULL == InAudioData) && (NULL == OutAudioData) && (0 == DataLen) )
{
printf("Error, empty data or transmit failed, exit !\n");
return -1;
}
printf("DataLen = %d, %s, %d\n", DataLen, __func__, __LINE__);
int Retuen = 0;
printf("G711u encode start......\n");
Retuen = g711u_encode( (unsigned char *)OutAudioData, (short*)InAudioData, DataLen/2 );
printf("Retuen = %d, %s, %d\n", Retuen, __func__, __LINE__);
return Retuen;
}
/*
* function: convert g711 alaw audio format to PCM.(zqj)
* InAudioData: g711 alaw data prepared for encoding to PCM.
* OutAudioData: encoded PCM audio data.
* DataLen: g711a data size.
* reserve: reserved param, no use.
*/
/*alaw*/
int G711a2PCM( char *InAudioData, char *OutAudioData, int DataLen, int reserve )
{
//check param.
if( (NULL == InAudioData) && (NULL == OutAudioData) && (0 == DataLen) )
{
printf("Error, empty data or transmit failed, exit !\n");
return -1;
}
printf("DataLen = %d, %s, %d\n", DataLen, __func__, __LINE__);
int Retade = 0;
printf("G711a decode start......\n");
Retade = g711a_decode( (short*)OutAudioData, (unsigned char *)InAudioData, DataLen );
printf("Retade = %d, %s, %d\n", Retade, __func__, __LINE__);
return Retade; //index successfully decoded data len.
}
/*ulaw*/
int G711u2PCM( char *InAudioData, char *OutAudioData, int DataLen, int reserve )
{
//check param.
if( (NULL == InAudioData) && (NULL == OutAudioData) && (0 == DataLen) )
{
printf("Error, empty data or transmit failed, exit !\n");
return -1;
}
printf("DataLen = %d, %s, %d\n", DataLen, __func__, __LINE__);
int Retude = 0;
printf("G711u decode start......\n");
Retude = g711u_decode( (short*)OutAudioData, (unsigned char *)InAudioData, DataLen );
printf("Retude = %d, %s, %d\n", Retude, __func__, __LINE__);
return Retude;
}