Axis network video cameras (such Axis 214) provide an API to retrieve audio data over HTTP.
Different content-types are available. If the MIME type is “audio/basic”, the audio data is encoded using G.711 mu-law at 64kbits/s.
This compression transforms 2 bytes of PCM data to 1 byte.
Here is an easy-way to convert the encoded audio data to PCM (to convert to WAV for example) :
unsigned short mulaw_decode(unsigned char mulaw) { mulaw = ~mulaw;
int sign = mulaw & 0x80;
int exponent = (mulaw & 0x70) >> 4;
int data = mulaw & 0x0f;
data |= 0x10;
data <<= 1;
data += 1;
data <<= exponent + 2;
data -= 0x84;
return (short)(sign == 0 ? data : -data);
}
That is great code.
I need C\C++ code for the opposite conversion – from PCM to mu-law. The PCM audio is 8 bit x 8KHz. The resulting mu-law should be 8 bit x 8KHz, 64 Kbit sampling rate. Thank you.
Don’t have it… this is getting old
sox can do it: http://sox.sourceforge.net/