From 58a3ef85a2196212856d74dac4e599ac970d9ea6 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Tue, 27 Mar 2012 03:04:19 +0000 Subject: [PATCH] codec2_codec2 now compiles inside Asterisk build system, but still need to hack Asterisk core to handle Codec 2 frames git-svn-id: https://svn.code.sf.net/p/freetel/code@354 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/asterisk/README | 9 ++++++--- codec2-dev/asterisk/codec_codec2.c | 31 ++++++++++++++++-------------- codec2-dev/asterisk/ex_codec2.h | 28 +++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 17 deletions(-) create mode 100644 codec2-dev/asterisk/ex_codec2.h diff --git a/codec2-dev/asterisk/README b/codec2-dev/asterisk/README index 5563802e..12701c12 100644 --- a/codec2-dev/asterisk/README +++ b/codec2-dev/asterisk/README @@ -5,9 +5,12 @@ todo: [ ] Patches for configure macro [ ] document + + make install codec 2 somewhere + + ./configure Asterisk with Codec2 include and ibrary + CFLAGS=-I/home/david/tmp/codec2/include ./configure + install instructions + Asterisk version + configuration and demo - patch configure.ac - autoconf - + + AST_FORMAT_GSM + + patch frames.h, AST_FORMAT_CODEC2 + + support for different Codec 2 bit rates diff --git a/codec2-dev/asterisk/codec_codec2.c b/codec2-dev/asterisk/codec_codec2.c index 79d65f24..5c0efada 100644 --- a/codec2-dev/asterisk/codec_codec2.c +++ b/codec2-dev/asterisk/codec_codec2.c @@ -18,7 +18,6 @@ */ /*** MODULEINFO - Codec 2 core ***/ @@ -29,24 +28,28 @@ #include "asterisk/module.h" #include "asterisk/utils.h" -#include "../formats/msgsm.h" +#include #define BUFFER_SAMPLES 8000 #define CODEC2_SAMPLES 160 #define CODEC2_FRAME_LEN 7 /* Sample frame data */ + #include "asterisk/slin.h" #include "ex_codec2.h" struct codec2_translator_pvt { /* both codec2tolin and codec2togsm */ struct CODEC2 *codec2; - int16_t buf[BUFFER_SAMPLES]; /* lintocodec2, temporary storage */ + short buf[BUFFER_SAMPLES]; /* lintocodec2, temporary storage */ }; static int codec2_new(struct ast_trans_pvt *pvt) { - pvt->pvt->codec2 = codec2_create(CODEC2_MODE_2500); + struct codec2_translator_pvt *tmp = pvt->pvt; + + tmp->codec2 = codec2_create(CODEC2_MODE_2500); + return 0; } @@ -64,7 +67,7 @@ static int codec2tolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f) len = CODEC2_SAMPLES; src = f->data.ptr + x; - codec2_decode(codec2, dst + pvt->samples, src); + codec2_decode(tmp->codec2, dst + pvt->samples, src); pvt->samples += CODEC2_SAMPLES; pvt->datalen += 2 * CODEC2_SAMPLES; @@ -73,7 +76,7 @@ static int codec2tolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f) } /*! \brief store samples into working buffer for later decode */ -static int codec2togsm_framein(struct ast_trans_pvt *pvt, struct ast_frame *f) +static int lintocodec2_framein(struct ast_trans_pvt *pvt, struct ast_frame *f) { struct codec2_translator_pvt *tmp = pvt->pvt; @@ -87,9 +90,9 @@ static int codec2togsm_framein(struct ast_trans_pvt *pvt, struct ast_frame *f) } /*! \brief encode and produce a frame */ -static struct ast_frame *codec2togsm_frameout(struct ast_trans_pvt *pvt) +static struct ast_frame *lintocodec2_frameout(struct ast_trans_pvt *pvt) { - struct gsm_translator_pvt *tmp = pvt->pvt; + struct codec2_translator_pvt *tmp = pvt->pvt; int datalen = 0; int samples = 0; @@ -97,11 +100,11 @@ static struct ast_frame *codec2togsm_frameout(struct ast_trans_pvt *pvt) if (pvt->samples < CODEC2_SAMPLES) return NULL; while (pvt->samples >= CODEC2_SAMPLES) { - /* Encode a frame of data */ - codec2_encode(tmp->codec2, pvt->outbuf.c + datalen, tmp->buf + samples); - datalen += CODEC2_FRAME_LEN; - samples += CODEC2_SAMPLES; - pvt->samples -= CODEC2_SAMPLES; + /* Encode a frame of data */ + codec2_encode(tmp->codec2, (unsigned char*)(pvt->outbuf.c + datalen), tmp->buf + samples); + datalen += CODEC2_FRAME_LEN; + samples += CODEC2_SAMPLES; + pvt->samples -= CODEC2_SAMPLES; } /* Move the data at the end of the buffer to the front */ @@ -115,7 +118,7 @@ static void codec2_destroy_stuff(struct ast_trans_pvt *pvt) { struct codec2_translator_pvt *tmp = pvt->pvt; if (tmp->codec2) - codec2_destroy(tmp->gsm); + codec2_destroy(tmp->codec2); } static struct ast_translator codec2tolin = { diff --git a/codec2-dev/asterisk/ex_codec2.h b/codec2-dev/asterisk/ex_codec2.h new file mode 100644 index 00000000..98b6214d --- /dev/null +++ b/codec2-dev/asterisk/ex_codec2.h @@ -0,0 +1,28 @@ +/*! \file + * \brief 8-bit raw data + * + * Copyright (C) 2012, 2012 Ed W and David Rowe + * + * Distributed under the terms of the GNU General Public License + * + */ + +static uint8_t ex_codec2[] = { + 0x3e,0x06,0x4a,0xbb,0x9e,0x40,0xc0 +}; + +static struct ast_frame *codec2_sample(void) +{ + static struct ast_frame f = { + .frametype = AST_FRAME_VOICE, + .subclass.codec = AST_FORMAT_CODEC2, + .datalen = sizeof(ex_codec2), + .samples = CODEC2_SAMPLES, + .mallocd = 0, + .offset = 0, + .src = __PRETTY_FUNCTION__, + .data.ptr = ex_codec2, + }; + + return &f; +} -- 2.25.1