update voipcodecs

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7600 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Brian West 2008-02-13 00:44:51 +00:00
parent c0b192bedc
commit 55d749ff23
5 changed files with 47 additions and 47 deletions

View File

@ -26,7 +26,7 @@
* This code is based on the widely used GSM 06.10 code available from
* 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 */
@ -310,50 +310,49 @@ int gsm0610_unpack_voip(gsm0610_frame_t *s, const uint8_t c[33])
}
/*- 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];
const uint8_t *c;
int bytes;
int samples;
int i;
c = code;
for (i = 0; i < quant; i++)
samples = 0;
for (i = 0; i < len; i += bytes)
{
switch (s->packing)
{
default:
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);
amp += GSM0610_FRAME_LEN;
decode_a_frame(s, &amp[samples], frame);
samples += GSM0610_FRAME_LEN;
}
break;
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);
amp += GSM0610_FRAME_LEN;
decode_a_frame(s, amp, frame + 1);
amp += GSM0610_FRAME_LEN;
decode_a_frame(s, &amp[samples], frame);
samples += GSM0610_FRAME_LEN;
decode_a_frame(s, &amp[samples], frame + 1);
samples += GSM0610_FRAME_LEN;
}
break;
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);
amp += GSM0610_FRAME_LEN;
decode_a_frame(s, &amp[samples], frame);
samples += GSM0610_FRAME_LEN;
}
break;
}
/*endswitch*/
if (bytes < 0)
return 0;
c += bytes;
}
/*endwhile*/
return quant*GSM0610_FRAME_LEN;
/*endfor*/
return samples;
}
/*- End of function --------------------------------------------------------*/
/*- End of file ------------------------------------------------------------*/

View File

@ -26,7 +26,7 @@
* This code is based on the widely used GSM 06.10 code available from
* 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 */
@ -156,6 +156,7 @@ int gsm0610_pack_none(uint8_t c[], const gsm0610_frame_t *s)
for (k = 0; k < 13; k++)
c[i++] = (uint8_t) s->xMc[j][k];
}
/*endfor*/
return 76;
}
/*- End of function --------------------------------------------------------*/
@ -206,6 +207,7 @@ int gsm0610_pack_wav49(uint8_t c[], const gsm0610_frame_t *s)
*c++ = sr >> 7;
sr = (sr >> 3) | (s->xMc[i][12] << 13);
}
/*endfor*/
s++;
sr = (sr >> 6) | (s->LARc[0] << 10);
@ -249,6 +251,7 @@ int gsm0610_pack_wav49(uint8_t c[], const gsm0610_frame_t *s)
sr = (sr >> 3) | (s->xMc[i][12] << 13);
*c++ = sr >> 8;
}
/*endfor*/
return 65;
}
/*- End of function --------------------------------------------------------*/
@ -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][12] & 0x7);
}
/*endfor*/
return 33;
}
/*- 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];
uint8_t *c;
int bytes;
int i;
c = code;
for (i = 0; i < quant; i++)
bytes = 0;
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)
{
case GSM0610_PACKING_NONE:
c += gsm0610_pack_none(c, frame);
amp += GSM0610_FRAME_LEN;
break;
case GSM0610_PACKING_WAV49:
amp += GSM0610_FRAME_LEN;
encode_a_frame(s, frame + 1, amp);
amp += GSM0610_FRAME_LEN;
c += gsm0610_pack_wav49(c, frame);
i += GSM0610_FRAME_LEN;
encode_a_frame(s, frame + 1, &amp[i]);
bytes += gsm0610_pack_wav49(&code[bytes], frame);
break;
case GSM0610_PACKING_VOIP:
c += gsm0610_pack_voip(c, frame);
amp += GSM0610_FRAME_LEN;
bytes += gsm0610_pack_voip(&code[bytes], frame);
break;
default:
bytes += gsm0610_pack_none(&code[bytes], frame);
break;
}
/*endswitch*/
}
/*endwhile*/
return (int) (c - code);
/*endfor*/
return bytes;
}
/*- End of function --------------------------------------------------------*/
/*- End of file ------------------------------------------------------------*/

View File

@ -1,5 +1,5 @@
/*
* 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.
*

View File

@ -23,11 +23,11 @@
* along with this program; if not, write to the Free Software
* 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_)
#define _SPANDSP_GSM0610_H_
#if !defined(_VOIPCODECS_GSM0610_H_)
#define _VOIPCODECS_GSM0610_H_
/*! \page gsm0610_page GSM 06.10 encoding and decoding
\section gsm0610_page_sec_1 What does it do?
@ -128,17 +128,17 @@ int gsm0610_set_packing(gsm0610_state_t *s, int packing);
\param s The GSM 06.10 context.
\param code The GSM 06.10 data produced.
\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. */
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.
\param s The GSM 06.10 context.
\param amp The audio sample buffer.
\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. */
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);

View File

@ -158,7 +158,7 @@ static switch_status_t switch_gsm_encode(switch_codec_t *codec,
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;
}
@ -176,7 +176,7 @@ static switch_status_t switch_gsm_decode(switch_codec_t *codec,
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;
}