45 #include <codec2/codec2.h>
47 #define BUFFER_SAMPLES 8000
48 #define CODEC2_SAMPLES 160
49 #define CODEC2_FRAME_LEN 6
52 #include "asterisk/slin.h"
57 int16_t buf[BUFFER_SAMPLES];
64 tmp->state = codec2_create(CODEC2_MODE_2400);
67 ast_log(LOG_ERROR,
"Error creating Codec 2 conversion\n");
80 for (x = 0; x < f->
datalen; x += CODEC2_FRAME_LEN) {
81 unsigned char *src = f->
data.ptr + x;
82 int16_t *dst = pvt->outbuf.i16 + pvt->
samples;
84 codec2_decode(tmp->state, dst, src);
87 pvt->
datalen += CODEC2_SAMPLES * 2;
112 while (pvt->
samples >= CODEC2_SAMPLES) {
116 codec2_encode(tmp->state, pvt->outbuf.
uc, tmp->buf + samples);
118 samples += CODEC2_SAMPLES;
119 pvt->
samples -= CODEC2_SAMPLES;
135 memmove(tmp->buf, tmp->buf + samples, pvt->
samples * 2);
146 codec2_destroy(tmp->state);
151 .
name =
"codec2tolin",
154 .type = AST_MEDIA_TYPE_AUDIO,
159 .type = AST_MEDIA_TYPE_AUDIO,
163 .newpvt = codec2_new,
165 .destroy = codec2_destroy_stuff,
166 .sample = codec2_sample,
168 .buffer_samples = BUFFER_SAMPLES,
169 .buf_size = BUFFER_SAMPLES * 2,
173 .
name =
"lintocodec2",
176 .type = AST_MEDIA_TYPE_AUDIO,
181 .type = AST_MEDIA_TYPE_AUDIO,
185 .newpvt = codec2_new,
188 .destroy = codec2_destroy_stuff,
189 .sample = slin8_sample,
191 .buffer_samples = BUFFER_SAMPLES,
192 .buf_size = (BUFFER_SAMPLES * CODEC2_FRAME_LEN + CODEC2_SAMPLES - 1) / CODEC2_SAMPLES,
195 static int unload_module(
void)
206 static int load_module(
void)
struct ast_frame * ast_trans_frameout(struct ast_trans_pvt *pvt, int datalen, int samples)
generic frameout function
int datalen
actual space used in outbuf
Asterisk main include file. File version handling, generic pbx functions.
Descriptor of a translator.
Support for translation of data formats. translate.c.
static struct ast_frame * lintocodec2_frameout(struct ast_trans_pvt *pvt)
encode and produce a frame
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
static int lintocodec2_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
store samples into working buffer for later decode
int ast_rtp_engine_unload_format(struct ast_format *format)
Formats requiring the use of a format attribute interface must have that interface registered in orde...
#define ast_register_translator(t)
See __ast_register_translator()
Asterisk internal frame definitions.
int ast_unregister_translator(struct ast_translator *t)
Unregister a translator Unregisters the given translator.
A set of macros to manage forward-linked lists.
Default structure for translators, with the basic fields and buffers, all allocated as part of the sa...
union ast_frame::@224 data
Support for logging to various files, console and syslog Configuration in file logger.conf.
Module has failed to load, may be in an inconsistent state.
Data structure associated with a single frame of data.
int ast_rtp_engine_load_format(struct ast_format *format)
Custom formats declared in codecs.conf at startup must be communicated to the rtp_engine so their mim...
static int codec2tolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
decode and store in outbuf.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Pluggable RTP Architecture.
Asterisk module definitions.