[Asterisk-video] if2 bit stuffing in app_h324m

Francesco Emmi francesco.emmi at a-tono.com
Tue Jul 31 10:50:59 CDT 2007


Klaus Darilion wrote:
> Ok. Can you please help me to understand the bit encodings?
> 
> I think I understand the RFC 4867 format - e.g: mode 7 uses 244 bits. 
> Network order with most significant byte/bit first. Thus
>
So, let' s suppose we are dealing with mode 7 and you have a IF1 frame. 
It's 244 bits long. So 31 bytes ( with 4 bits stuffing at the end ) + 1 
header byte containing amr mode (a total of 32 bytes):

3c 08 5a 5f 8c 44 50 44 4c cd 45 2f 25 75 43 13 80 00 01 19 e0 8a 22 10
00 00 de 51 3e 87 3d 80

Suppose buf[32] contains this amr MIME frame. So


mode = (buf[0] >> 3) & 0x0f = 7
b0 = buf[1] & (1 << 7)
b1 = buf[1] & (1 << 6)
...
b6 = buf[1] & (1 << 1)
b7 = buf[2] & (1 << 0)
...
b243 = buf[31] & (1 << 5)
b244 = buf[31] & (1 << 4)
Last 4 bits of buf[31] are zero suffing.

This means that b0...b244 is just
08 5a 5f 8c 44 50 44 4c cd 45 2f 25 75 43 13 80 00 01 19 e0 8a 22 10
00 00 de 51 3e 87 3d 80 without last 4 bits.


> 
> Then, if this is transformed to if2 - I would think it should be following:
> 
> AMR mode bit 0  ->  buf[0] | (1 << 7)
> AMR mode bit 1  ->  buf[0] | (1 << 6)
> AMR mode bit 2  ->  buf[0] | (1 << 5)
> AMR mode bit 3  ->  buf[0] | (1 << 4)
> 
> AMR bit 0  ->  buf[0] | (1 << 3)
> AMR bit 1  ->  buf[0] | (1 << 2)
> AMR bit 2  ->  buf[0] | (1 << 1)
> AMR bit 3  ->  buf[0] | (1 << 0)
> AMR bit 4  ->  buf[1] | (1 << 7)
> AMR bit 5  ->  buf[1] | (1 << 6)
> AMR bit 6  ->  buf[1] | (1 << 5)
> AMR bit 7  ->  buf[1] | (1 << 4)
> AMR bit 8  ->  buf[1] | (1 << 3)
> AMR bit 9  ->  buf[1] | (1 << 2)
> ...
> 
> AMR bit 242  ->  buf[30] | (1 << 1)
> AMR bit 243  ->  buf[30] | (1 << 0)
> 
> 
> Is this correct?
> 
>
The Correct way is just a bit more complicated. Let say bn the n-th amr 
bit , buf an array containing MIME (if1) frame  and REV(buf[i]) the bit 
reverse of buf[i]:

if2[0] = ((b3 b2 b1 b0 )& 0xF0) | (mode & 0x0f) = (REV(buf[1]) & 0xF0) | 
  (mode & 0x0f)
if2[1] = (b11 b10 b9 b8 b7 b6 b5 b4)=(REV(buf[2]) & 0xF0) | REV(buf[1] & 
0x0f)
if2[2] =(b19 b18 b17 b16 b15 b14 b13 b12)=REV(buf[3]&0xF0) | 
REV(buf[2])&0x0f
...
if2[29]=(b235 b234 b233 b232 b231 b230 b229 b228) = ...

if2[30] = (b243 b242 b241 b240 b239 b238 b237 b236) = 		 
      REV(b[31])&0xf0 | REV(b[30])&0x0f

Notice that we are not using b[31]&0x0f as it contains only zero padding.

I hope this helps you. (I believe it is simpler to do that to explain :-) )

Regards
Francesco
-- 
____________________________________________
Francesco Emmi
A-Tono
Largo Paisiello 5 - 95124 Catania
Tel.: (+39) 095 7365312
http: www.a-tono.com

Information in this email is confidential and may be privileged.
It is intended for the addresses only. If you have received it in error,
please notify the sender immediately and delete it from your system.
You should not otherwise copy it, retransmit it or use or disclose its
content to anyone.
Thank you for your co-operation.



More information about the asterisk-video mailing list