*/
/*** 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;
}
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;
}
/*! \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;
}
/*! \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;
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 */
{
struct codec2_translator_pvt *tmp = pvt->pvt;
if (tmp->codec2)
- codec2_destroy(tmp->gsm);
+ codec2_destroy(tmp->codec2);
}
static struct ast_translator codec2tolin = {
--- /dev/null
+/*! \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;
+}