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
|
static short seg_uend[8] = {0x3F, 0x7F, 0xFF, 0x1FF,
0x3FF, 0x7FF, 0xFFF, 0x1FFF};
static int search( int val, short *table, int size)
{
int i;
for (i = 0; i < size; i++)
{
if (val <= *table++)
return (i);
}
return (size);
}
unsigned char CG711::encodeULaw(short pcm_val)
{
static int exp_lut[256] = {0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,
4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7};
int sign, exponent, mantissa;
unsigned char ulawbyte;
// Get the sample into sign-magnitude. */
sign = (pcm_val >> 8) & 0x80; // set aside the sign */
if (sign != 0) pcm_val = -pcm_val; // get magnitude */
if (pcm_val > CLIP) pcm_val = CLIP; // clip the magnitude */
// Convert from 16 bit linear to ulaw. */
pcm_val = pcm_val + BIAS;
exponent = exp_lut[(pcm_val >> 7) & 0xFF];
mantissa = (pcm_val >> (exponent + 3)) & 0x0F;
ulawbyte = ~(sign | (exponent << 4) | mantissa);
#ifdef ZEROTRAP
if (ulawbyte == 0) ulawbyte = 0x02; // optional CCITT trap */
#endif
return(ulawbyte);
}
//Diese Methode rufe ich aus meiner Funktion folgendermaßen auf.
for(int i = 0; i < size2; i++)
newPacket.m_payload[i] = g711.encodeULaw(downsampledAudio[i]);
//downsampledAudio ist mein vorher reduzierter Buffer
|