diff options
author | Sylvain Munaut <tnt@246tNt.com> | 2013-12-08 19:24:02 +0100 |
---|---|---|
committer | Sylvain Munaut <tnt@246tNt.com> | 2013-12-17 18:15:42 +0100 |
commit | e8730785b39a5881c0233155ecc5fc0bfea935de (patch) | |
tree | dd6ffe64363440cd0765519ad9c75b8e9430d78a /src/codec/codec.c | |
parent | 255a32a391afdc4a04e087c4e2cb467e47069a5a (diff) |
codec: First code import
Lots of fixups still needed before merge into master
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Diffstat (limited to 'src/codec/codec.c')
-rw-r--r-- | src/codec/codec.c | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/src/codec/codec.c b/src/codec/codec.c new file mode 100644 index 0000000..c422b5b --- /dev/null +++ b/src/codec/codec.c @@ -0,0 +1,103 @@ +/* GMR-1 AMBE vocoder */ + +/* (C) 2013 by Sylvain Munaut <tnt@246tNt.com> + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/*! \addtogroup codec + * @{ + */ + +/*! \file codec/codec.c + * \brief Osmocom GMR-1 AMBE vocoder public API implementation + */ + +#include <string.h> +#include <stdint.h> +#include <stdlib.h> + +#include <osmocom/gmr1/codec/codec.h> + +#include "private.h" + + +/*! \brief Structure for GMR1 codec state */ +struct gmr1_codec +{ + struct ambe_decoder dec; /*< \brief decoder state */ +}; + + +/*! \brief Allocates and inits a codec object + * \returns A newly allocated codec, to be freed with \ref gmr1_codec_release + */ +struct gmr1_codec * +gmr1_codec_alloc(void) +{ + struct gmr1_codec *codec; + + codec = calloc(1, sizeof(struct gmr1_codec)); + if (!codec) + return NULL; + + ambe_decode_init(&codec->dec); + + return codec; +} + +/*! \brief Release a codec object created by \ref gmr1_codec_alloc + * \param[in] codec The codec object to release + */ +void +gmr1_codec_release(struct gmr1_codec *codec) +{ + if (!codec) + return; + + ambe_decode_fini(&codec->dec); + + free(codec); +} + +/*! \brief Decodes an AMBE frame to audio + * \param[in] codec Codec object + * \param[out] audio Output audio buffer + * \param[in] N number of audio samples to produce (152..168) + * \param[in] frame Frame data (10 bytes = 80 bits) + * \param[in] bad Bad Frame Indicator. Set to 1 if frame is corrupt + * \returns 0 for success. Negative error code otherwise. + */ +int +gmr1_codec_decode_frame(struct gmr1_codec *codec, + int16_t *audio, int N, + const uint8_t *frame, int bad) +{ + return ambe_decode_frame(&codec->dec, audio, N, frame, bad); +} + +/*! \brief Generates audio for DTX period + * \param[in] codec Codec object + * \param[out] audio Output audio buffer + * \param[in] N number of audio samples to produce (152..168) + */ +int +gmr1_codec_decode_dtx(struct gmr1_codec *codec, + int16_t *audio, int N) +{ + return ambe_decode_dtx(&codec->dec, audio, N); +} + +/*! @} */ |