提交 55d749ff authored 作者: Brian West's avatar Brian West

update voipcodecs

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7600 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 c0b192be
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
* This code is based on the widely used GSM 06.10 code available from * This code is based on the widely used GSM 06.10 code available from
* http://kbs.cs.tu-berlin.de/~jutta/toast.html * http://kbs.cs.tu-berlin.de/~jutta/toast.html
* *
* $Id: gsm0610_decode.c,v 1.15 2008/02/09 15:31:36 steveu Exp $ * $Id: gsm0610_decode.c,v 1.16 2008/02/12 12:27:48 steveu Exp $
*/ */
/*! \file */ /*! \file */
...@@ -310,50 +310,49 @@ int gsm0610_unpack_voip(gsm0610_frame_t *s, const uint8_t c[33]) ...@@ -310,50 +310,49 @@ int gsm0610_unpack_voip(gsm0610_frame_t *s, const uint8_t c[33])
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
int gsm0610_decode(gsm0610_state_t *s, int16_t amp[], const uint8_t code[], int quant) int gsm0610_decode(gsm0610_state_t *s, int16_t amp[], const uint8_t code[], int len)
{ {
gsm0610_frame_t frame[2]; gsm0610_frame_t frame[2];
const uint8_t *c;
int bytes; int bytes;
int samples;
int i; int i;
c = code; samples = 0;
for (i = 0; i < quant; i++) for (i = 0; i < len; i += bytes)
{ {
switch (s->packing) switch (s->packing)
{ {
default: default:
case GSM0610_PACKING_NONE: case GSM0610_PACKING_NONE:
if ((bytes = gsm0610_unpack_none(frame, c)) >= 0) if ((bytes = gsm0610_unpack_none(frame, &code[i])) >= 0)
{ {
decode_a_frame(s, amp, frame); decode_a_frame(s, &amp[samples], frame);
amp += GSM0610_FRAME_LEN; samples += GSM0610_FRAME_LEN;
} }
break; break;
case GSM0610_PACKING_WAV49: case GSM0610_PACKING_WAV49:
if ((bytes = gsm0610_unpack_wav49(frame, c)) >= 0) if ((bytes = gsm0610_unpack_wav49(frame, &code[i])) >= 0)
{ {
decode_a_frame(s, amp, frame); decode_a_frame(s, &amp[samples], frame);
amp += GSM0610_FRAME_LEN; samples += GSM0610_FRAME_LEN;
decode_a_frame(s, amp, frame + 1); decode_a_frame(s, &amp[samples], frame + 1);
amp += GSM0610_FRAME_LEN; samples += GSM0610_FRAME_LEN;
} }
break; break;
case GSM0610_PACKING_VOIP: case GSM0610_PACKING_VOIP:
if ((bytes = gsm0610_unpack_voip(frame, c)) >= 0) if ((bytes = gsm0610_unpack_voip(frame, &code[i])) >= 0)
{ {
decode_a_frame(s, amp, frame); decode_a_frame(s, &amp[samples], frame);
amp += GSM0610_FRAME_LEN; samples += GSM0610_FRAME_LEN;
} }
break; break;
} }
/*endswitch*/ /*endswitch*/
if (bytes < 0) if (bytes < 0)
return 0; return 0;
c += bytes;
} }
/*endwhile*/ /*endfor*/
return quant*GSM0610_FRAME_LEN; return samples;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
/*- End of file ------------------------------------------------------------*/ /*- End of file ------------------------------------------------------------*/
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
* This code is based on the widely used GSM 06.10 code available from * This code is based on the widely used GSM 06.10 code available from
* http://kbs.cs.tu-berlin.de/~jutta/toast.html * http://kbs.cs.tu-berlin.de/~jutta/toast.html
* *
* $Id: gsm0610_encode.c,v 1.18 2008/02/09 15:31:36 steveu Exp $ * $Id: gsm0610_encode.c,v 1.19 2008/02/12 12:27:48 steveu Exp $
*/ */
/*! \file */ /*! \file */
...@@ -156,6 +156,7 @@ int gsm0610_pack_none(uint8_t c[], const gsm0610_frame_t *s) ...@@ -156,6 +156,7 @@ int gsm0610_pack_none(uint8_t c[], const gsm0610_frame_t *s)
for (k = 0; k < 13; k++) for (k = 0; k < 13; k++)
c[i++] = (uint8_t) s->xMc[j][k]; c[i++] = (uint8_t) s->xMc[j][k];
} }
/*endfor*/
return 76; return 76;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
...@@ -206,6 +207,7 @@ int gsm0610_pack_wav49(uint8_t c[], const gsm0610_frame_t *s) ...@@ -206,6 +207,7 @@ int gsm0610_pack_wav49(uint8_t c[], const gsm0610_frame_t *s)
*c++ = sr >> 7; *c++ = sr >> 7;
sr = (sr >> 3) | (s->xMc[i][12] << 13); sr = (sr >> 3) | (s->xMc[i][12] << 13);
} }
/*endfor*/
s++; s++;
sr = (sr >> 6) | (s->LARc[0] << 10); sr = (sr >> 6) | (s->LARc[0] << 10);
...@@ -249,6 +251,7 @@ int gsm0610_pack_wav49(uint8_t c[], const gsm0610_frame_t *s) ...@@ -249,6 +251,7 @@ int gsm0610_pack_wav49(uint8_t c[], const gsm0610_frame_t *s)
sr = (sr >> 3) | (s->xMc[i][12] << 13); sr = (sr >> 3) | (s->xMc[i][12] << 13);
*c++ = sr >> 8; *c++ = sr >> 8;
} }
/*endfor*/
return 65; return 65;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
...@@ -295,41 +298,39 @@ int gsm0610_pack_voip(uint8_t c[33], const gsm0610_frame_t *s) ...@@ -295,41 +298,39 @@ int gsm0610_pack_voip(uint8_t c[33], const gsm0610_frame_t *s)
| ((s->xMc[i][11] & 0x7) << 3) | ((s->xMc[i][11] & 0x7) << 3)
| (s->xMc[i][12] & 0x7); | (s->xMc[i][12] & 0x7);
} }
/*endfor*/
return 33; return 33;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
int gsm0610_encode(gsm0610_state_t *s, uint8_t code[], const int16_t amp[], int quant) int gsm0610_encode(gsm0610_state_t *s, uint8_t code[], const int16_t amp[], int len)
{ {
gsm0610_frame_t frame[2]; gsm0610_frame_t frame[2];
uint8_t *c; int bytes;
int i; int i;
c = code; bytes = 0;
for (i = 0; i < quant; i++) for (i = 0; i < len; i += GSM0610_FRAME_LEN)
{ {
encode_a_frame(s, frame, amp); encode_a_frame(s, frame, &amp[i]);
switch (s->packing) switch (s->packing)
{ {
case GSM0610_PACKING_NONE:
c += gsm0610_pack_none(c, frame);
amp += GSM0610_FRAME_LEN;
break;
case GSM0610_PACKING_WAV49: case GSM0610_PACKING_WAV49:
amp += GSM0610_FRAME_LEN; i += GSM0610_FRAME_LEN;
encode_a_frame(s, frame + 1, amp); encode_a_frame(s, frame + 1, &amp[i]);
amp += GSM0610_FRAME_LEN; bytes += gsm0610_pack_wav49(&code[bytes], frame);
c += gsm0610_pack_wav49(c, frame);
break; break;
case GSM0610_PACKING_VOIP: case GSM0610_PACKING_VOIP:
c += gsm0610_pack_voip(c, frame); bytes += gsm0610_pack_voip(&code[bytes], frame);
amp += GSM0610_FRAME_LEN; break;
default:
bytes += gsm0610_pack_none(&code[bytes], frame);
break; break;
} }
/*endswitch*/ /*endswitch*/
} }
/*endwhile*/ /*endfor*/
return (int) (c - code); return bytes;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
/*- End of file ------------------------------------------------------------*/ /*- End of file ------------------------------------------------------------*/
/* /*
* SpanDSP - a series of DSP components for telephony * VoIPcodecs - a series of DSP components for telephony
* *
* gsm0610_local.h - GSM 06.10 full rate speech codec. * gsm0610_local.h - GSM 06.10 full rate speech codec.
* *
......
...@@ -23,11 +23,11 @@ ...@@ -23,11 +23,11 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* *
* $Id: gsm0610.h,v 1.14 2008/02/09 15:31:36 steveu Exp $ * $Id: gsm0610.h,v 1.15 2008/02/12 12:27:48 steveu Exp $
*/ */
#if !defined(_SPANDSP_GSM0610_H_) #if !defined(_VOIPCODECS_GSM0610_H_)
#define _SPANDSP_GSM0610_H_ #define _VOIPCODECS_GSM0610_H_
/*! \page gsm0610_page GSM 06.10 encoding and decoding /*! \page gsm0610_page GSM 06.10 encoding and decoding
\section gsm0610_page_sec_1 What does it do? \section gsm0610_page_sec_1 What does it do?
...@@ -128,17 +128,17 @@ int gsm0610_set_packing(gsm0610_state_t *s, int packing); ...@@ -128,17 +128,17 @@ int gsm0610_set_packing(gsm0610_state_t *s, int packing);
\param s The GSM 06.10 context. \param s The GSM 06.10 context.
\param code The GSM 06.10 data produced. \param code The GSM 06.10 data produced.
\param amp The audio sample buffer. \param amp The audio sample buffer.
\param quant The number of samples in the buffer. \param len The number of samples in the buffer.
\return The number of bytes of GSM 06.10 data produced. */ \return The number of bytes of GSM 06.10 data produced. */
int gsm0610_encode(gsm0610_state_t *s, uint8_t code[], const int16_t amp[], int quant); int gsm0610_encode(gsm0610_state_t *s, uint8_t code[], const int16_t amp[], int len);
/*! Decode a buffer of GSM 06.10 data to linear PCM. /*! Decode a buffer of GSM 06.10 data to linear PCM.
\param s The GSM 06.10 context. \param s The GSM 06.10 context.
\param amp The audio sample buffer. \param amp The audio sample buffer.
\param code The GSM 06.10 data. \param code The GSM 06.10 data.
\param quant The number of frames of GSM 06.10 data to be decoded. \param len The number of bytes of GSM 06.10 data to be decoded.
\return The number of samples returned. */ \return The number of samples returned. */
int gsm0610_decode(gsm0610_state_t *s, int16_t amp[], const uint8_t code[], int quant); int gsm0610_decode(gsm0610_state_t *s, int16_t amp[], const uint8_t code[], int len);
int gsm0610_pack_none(uint8_t c[], const gsm0610_frame_t *s); int gsm0610_pack_none(uint8_t c[], const gsm0610_frame_t *s);
......
...@@ -158,7 +158,7 @@ static switch_status_t switch_gsm_encode(switch_codec_t *codec, ...@@ -158,7 +158,7 @@ static switch_status_t switch_gsm_encode(switch_codec_t *codec,
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
*encoded_data_len = gsm0610_encode(&context->encoder_object, (uint8_t *) encoded_data, (int16_t *) decoded_data, decoded_data_len / 320); *encoded_data_len = gsm0610_encode(&context->encoder_object, (uint8_t *) encoded_data, (int16_t *) decoded_data, decoded_data_len / 2);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
...@@ -176,7 +176,7 @@ static switch_status_t switch_gsm_decode(switch_codec_t *codec, ...@@ -176,7 +176,7 @@ static switch_status_t switch_gsm_decode(switch_codec_t *codec,
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
*decoded_data_len = (2 * gsm0610_decode(&context->decoder_object, (int16_t *) decoded_data, (uint8_t *) encoded_data, encoded_data_len / 33)); *decoded_data_len = (2 * gsm0610_decode(&context->decoder_object, (int16_t *) decoded_data, (uint8_t *) encoded_data, encoded_data_len));
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论