From 55d749ff23c6cd448822b920f81933ac8e63b673 Mon Sep 17 00:00:00 2001 From: Brian West Date: Wed, 13 Feb 2008 00:44:51 +0000 Subject: [PATCH] update voipcodecs git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7600 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- libs/voipcodecs/src/gsm0610_decode.c | 37 +++++++++---------- libs/voipcodecs/src/gsm0610_encode.c | 37 ++++++++++--------- libs/voipcodecs/src/gsm0610_local.h | 2 +- libs/voipcodecs/src/voipcodecs/gsm0610.h | 14 +++---- .../codecs/mod_voipcodecs/mod_voipcodecs.c | 4 +- 5 files changed, 47 insertions(+), 47 deletions(-) diff --git a/libs/voipcodecs/src/gsm0610_decode.c b/libs/voipcodecs/src/gsm0610_decode.c index ce852dc9ec..a99e5052fb 100644 --- a/libs/voipcodecs/src/gsm0610_decode.c +++ b/libs/voipcodecs/src/gsm0610_decode.c @@ -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, &[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, &[samples], frame); + samples += GSM0610_FRAME_LEN; + decode_a_frame(s, &[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, &[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 ------------------------------------------------------------*/ diff --git a/libs/voipcodecs/src/gsm0610_encode.c b/libs/voipcodecs/src/gsm0610_encode.c index f6209fb202..3eea687aa9 100644 --- a/libs/voipcodecs/src/gsm0610_encode.c +++ b/libs/voipcodecs/src/gsm0610_encode.c @@ -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, &[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, &[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 ------------------------------------------------------------*/ diff --git a/libs/voipcodecs/src/gsm0610_local.h b/libs/voipcodecs/src/gsm0610_local.h index 066ec4184d..018c4c3ae6 100644 --- a/libs/voipcodecs/src/gsm0610_local.h +++ b/libs/voipcodecs/src/gsm0610_local.h @@ -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. * diff --git a/libs/voipcodecs/src/voipcodecs/gsm0610.h b/libs/voipcodecs/src/voipcodecs/gsm0610.h index 83e05e89f5..1c45c4918c 100644 --- a/libs/voipcodecs/src/voipcodecs/gsm0610.h +++ b/libs/voipcodecs/src/voipcodecs/gsm0610.h @@ -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); diff --git a/src/mod/codecs/mod_voipcodecs/mod_voipcodecs.c b/src/mod/codecs/mod_voipcodecs/mod_voipcodecs.c index f44623489a..55c3e5743d 100644 --- a/src/mod/codecs/mod_voipcodecs/mod_voipcodecs.c +++ b/src/mod/codecs/mod_voipcodecs/mod_voipcodecs.c @@ -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; }