Mercurial > hg > audiostuff
comparison intercom/g726/g726_rfc3551.c @ 2:13be24d74cd2
import intercom-0.4.1
| author | Peter Meerwald <pmeerw@cosy.sbg.ac.at> |
|---|---|
| date | Fri, 25 Jun 2010 09:57:52 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:9cadc470e3da | 2:13be24d74cd2 |
|---|---|
| 1 /* g726_rfc3551.c | |
| 2 * | |
| 3 * Copyright (C) DFS Deutsche Flugsicherung (2004, 2005). | |
| 4 * All Rights Reserved. | |
| 5 * Author: Andre Adrian | |
| 6 */ | |
| 7 | |
| 8 | |
| 9 /* RFC3551 | |
| 10 | |
| 11 name of sampling default | |
| 12 encoding sample/frame bits/sample rate ms/frame ms/packet | |
| 13 __________________________________________________________________ | |
| 14 G726-40 sample 5 8,000 20 | |
| 15 G726-32 sample 4 8,000 20 | |
| 16 G726-24 sample 3 8,000 20 | |
| 17 G726-16 sample 2 8,000 20 | |
| 18 | |
| 19 Applications MUST | |
| 20 determine the encoding type of packed codewords from the RTP payload | |
| 21 identifier. | |
| 22 | |
| 23 the first codeword is placed into the first octet | |
| 24 such that the least significant bit of the codeword aligns with the | |
| 25 least significant bit in the octet, the second codeword is then | |
| 26 packed so that its least significant bit coincides with the least | |
| 27 significant unoccupied bit in the octet. When a complete codeword | |
| 28 cannot be placed into an octet, the bits overlapping the octet | |
| 29 boundary are placed into the least significant bits of the next | |
| 30 octet. Packing MUST end with a completely packed final octet. The | |
| 31 number of codewords packed will therefore be a multiple of 8, 2, 8, | |
| 32 and 4 for G726-40, G726-32, G726-24, and G726-16, respectively. An | |
| 33 example of the packing scheme for G726-32 codewords is as shown, | |
| 34 where bit 7 is the least significant bit of the first octet, and bit | |
| 35 A3 is the least significant bit of the first codeword: | |
| 36 | |
| 37 0 1 | |
| 38 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 | |
| 39 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- | |
| 40 |B B B B|A A A A|D D D D|C C C C| ... | |
| 41 |0 1 2 3|0 1 2 3|0 1 2 3|0 1 2 3| | |
| 42 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- | |
| 43 | |
| 44 An example of the packing scheme for G726-24 codewords follows, where | |
| 45 again bit 7 is the least significant bit of the first octet, and bit | |
| 46 A2 is the least significant bit of the first codeword: | |
| 47 | |
| 48 0 1 2 | |
| 49 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 | |
| 50 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- | |
| 51 |C C|B B B|A A A|F|E E E|D D D|C|H H H|G G G|F F| ... | |
| 52 |1 2|0 1 2|0 1 2|2|0 1 2|0 1 2|0|0 1 2|0 1 2|0 1| | |
| 53 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- | |
| 54 | |
| 55 PT encoding media type clock rate channels | |
| 56 name (Hz) | |
| 57 ___________________________________________________ | |
| 58 dyn G726-40 A 8,000 1 | |
| 59 dyn G726-32 A 8,000 1 | |
| 60 dyn G726-24 A 8,000 1 | |
| 61 dyn G726-16 A 8,000 1 | |
| 62 | |
| 63 */ | |
| 64 | |
| 65 #include <string.h> | |
| 66 #include "g711.h" | |
| 67 #include "g726.h" | |
| 68 | |
| 69 /* G.726 subset: 32kBit/s, A-law */ | |
| 70 | |
| 71 static void g726pack(Byte *packed, short *in, int cnt) | |
| 72 { | |
| 73 int i; | |
| 74 for (i = 0; i <= cnt; i += 2, ++packed, ++in) { | |
| 75 *packed = (*in & 0xF); | |
| 76 ++in; | |
| 77 *packed += (*in & 0xF) * 16; | |
| 78 } | |
| 79 } | |
| 80 | |
| 81 static void g726unpack(short *out, Byte *packed, int cnt) | |
| 82 { | |
| 83 int i; | |
| 84 for (i = 0; i <= cnt; i += 2, ++packed, ++out) { | |
| 85 *out = (*packed & 0xF); | |
| 86 ++out; | |
| 87 *out = (*packed & 0xF0) / 16; | |
| 88 } | |
| 89 } | |
| 90 | |
| 91 void g726_initEncode(G726_state *encoder_state) | |
| 92 { | |
| 93 memset(encoder_state, 0, sizeof(G726_state)); | |
| 94 } | |
| 95 | |
| 96 void g726_initDecode(G726_state *decoder_state) | |
| 97 { | |
| 98 memset(decoder_state, 0, sizeof(G726_state)); | |
| 99 } | |
| 100 | |
| 101 short g726_encode( /* (o) Number of bytes encoded */ | |
| 102 G726_state *state, /* (i/o) Encoder instance */ | |
| 103 unsigned char *encoded_data, /* (o) The encoded bytes */ | |
| 104 short *inp_buf /* (i) The signal block to encode */ | |
| 105 ) | |
| 106 { | |
| 107 unsigned char inpb_buf[20*8]; | |
| 108 short out_buf[20*8]; | |
| 109 static char law[] = "1"; | |
| 110 | |
| 111 alaw_compress(20*8, inp_buf, inpb_buf); | |
| 112 G726_encode(inpb_buf, out_buf, 20*8, law, 4, 0, state); | |
| 113 g726pack(encoded_data, out_buf, 20*8); | |
| 114 | |
| 115 return 20*8/2; | |
| 116 } | |
| 117 | |
| 118 short g726_decode( /* (o) Number of decoded samples */ | |
| 119 G726_state *state, /* (i/o) Decoder instance */ | |
| 120 short *decoded_data, /* (o) Decoded signal block */ | |
| 121 unsigned char *encoded_data, /* (i) Encoded bytes */ | |
| 122 short mode /* (i) 0=PL, 1=Normal */ | |
| 123 ) | |
| 124 { | |
| 125 short inp_buf[20*8]; | |
| 126 unsigned char outb_buf[20*8]; | |
| 127 static char law[] = "1"; | |
| 128 | |
| 129 g726unpack(inp_buf, encoded_data, 20*8); | |
| 130 G726_decode(inp_buf, outb_buf, 20*8, law, 4, 0, state); | |
| 131 alaw_expand(20*8, outb_buf, decoded_data); | |
| 132 | |
| 133 return 20*8; | |
| 134 } |
