codec2_codec2 now compiles inside Asterisk build system, but still need to hack Aster...
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 27 Mar 2012 03:04:19 +0000 (03:04 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 27 Mar 2012 03:04:19 +0000 (03:04 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@354 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/asterisk/README
codec2-dev/asterisk/codec_codec2.c
codec2-dev/asterisk/ex_codec2.h [new file with mode: 0644]

index 5563802ec2082844f9cc196b2b45f953b5b43260..12701c12f205d37d452c343ccae8db21e9862246 100644 (file)
@@ -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
index 79d65f24579cb32dba6ca32d85133e18f9b8cc9b..5c0efada82589c42d4a829c4e638c6a018c410f6 100644 (file)
@@ -18,7 +18,6 @@
  */
 
 /*** MODULEINFO
-       <depend>Codec 2</depend>
        <support_level>core</support_level>
  ***/
 
 #include "asterisk/module.h"
 #include "asterisk/utils.h"
 
-#include "../formats/msgsm.h"
+#include <codec2.h>
 
 #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 (file)
index 0000000..98b6214
--- /dev/null
@@ -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;
+}