Translate between signed linear and LPC10 (Linear Predictor Code) More...
#include "asterisk.h"
#include "asterisk/translate.h"
#include "asterisk/config.h"
#include "asterisk/module.h"
#include "asterisk/utils.h"
#include "lpc10/lpc10.h"
#include "asterisk/slin.h"
#include "ex_lpc10.h"
Go to the source code of this file.
Data Structures | |
struct | lpc10_coder_pvt |
Defines | |
#define | BUFFER_SAMPLES 8000 |
#define | LPC10_BYTES_IN_COMPRESSED_FRAME (LPC10_BITS_IN_COMPRESSED_FRAME + 7)/8 |
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
static void | build_bits (unsigned char *c, INT32 *bits) |
static void | extract_bits (INT32 *bits, unsigned char *c) |
static int | lintolpc10_framein (struct ast_trans_pvt *pvt, struct ast_frame *f) |
static struct ast_frame * | lintolpc10_frameout (struct ast_trans_pvt *pvt) |
static int | load_module (void) |
static int | lpc10_dec_new (struct ast_trans_pvt *pvt) |
static void | lpc10_destroy (struct ast_trans_pvt *arg) |
static int | lpc10_enc_new (struct ast_trans_pvt *pvt) |
static int | lpc10tolin_framein (struct ast_trans_pvt *pvt, struct ast_frame *f) |
static int | reload (void) |
static int | unload_module (void) |
Variables | |
static struct ast_module_info __MODULE_INFO_SECTION | __mod_info = { __MODULE_INFO_GLOBALS .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "LPC10 2.4kbps Coder/Decoder" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .reload = reload, } |
static struct ast_module_info * | ast_module_info = &__mod_info |
static struct ast_translator | lintolpc10 |
static struct ast_translator | lpc10tolin |
Translate between signed linear and LPC10 (Linear Predictor Code)
Definition in file codec_lpc10.c.
#define BUFFER_SAMPLES 8000 |
Definition at line 52 of file codec_lpc10.c.
Referenced by lintolpc10_framein(), and lpc10tolin_framein().
#define LPC10_BYTES_IN_COMPRESSED_FRAME (LPC10_BITS_IN_COMPRESSED_FRAME + 7)/8 |
Definition at line 50 of file codec_lpc10.c.
Referenced by lintolpc10_frameout(), and lpc10tolin_framein().
static void __reg_module | ( | void | ) | [static] |
Definition at line 255 of file codec_lpc10.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 255 of file codec_lpc10.c.
static void build_bits | ( | unsigned char * | c, |
INT32 * | bits | ||
) | [static] |
Definition at line 92 of file codec_lpc10.c.
Referenced by lintolpc10_frameout().
{ unsigned char mask=0x80; int x; *c = 0; for (x=0;x<LPC10_BITS_IN_COMPRESSED_FRAME;x++) { if (bits[x]) *c |= mask; mask = mask >> 1; if ((x % 8)==7) { c++; *c = 0; mask = 0x80; } } }
static void extract_bits | ( | INT32 * | bits, |
unsigned char * | c | ||
) | [static] |
Definition at line 78 of file codec_lpc10.c.
Referenced by lpc10tolin_framein().
{ int x; for (x=0;x<LPC10_BITS_IN_COMPRESSED_FRAME;x++) { if (*c & (0x80 >> (x & 7))) bits[x] = 1; else bits[x] = 0; if ((x & 7) == 7) c++; } }
static int lintolpc10_framein | ( | struct ast_trans_pvt * | pvt, |
struct ast_frame * | f | ||
) | [static] |
Definition at line 142 of file codec_lpc10.c.
References ast_log(), lpc10_coder_pvt::buf, BUFFER_SAMPLES, ast_frame::data, ast_frame::datalen, LOG_WARNING, ast_frame::ptr, ast_trans_pvt::pvt, ast_frame::samples, and ast_trans_pvt::samples.
{ struct lpc10_coder_pvt *tmp = pvt->pvt; /* Just add the frames to our stream */ if (pvt->samples + f->samples > BUFFER_SAMPLES) { ast_log(LOG_WARNING, "Out of buffer space\n"); return -1; } memcpy(tmp->buf + pvt->samples, f->data.ptr, f->datalen); pvt->samples += f->samples; return 0; }
static struct ast_frame* lintolpc10_frameout | ( | struct ast_trans_pvt * | pvt | ) | [static, read] |
Definition at line 156 of file codec_lpc10.c.
References ast_trans_frameout(), lpc10_coder_pvt::buf, build_bits(), lpc10_coder_pvt::enc, lpc10_coder_pvt::longer, lpc10_coder_pvt::lpc10, LPC10_BYTES_IN_COMPRESSED_FRAME, ast_trans_pvt::outbuf, ast_trans_pvt::pvt, ast_trans_pvt::samples, and ast_trans_pvt::uc.
{ struct lpc10_coder_pvt *tmp = pvt->pvt; int x; int datalen = 0; /* output frame */ int samples = 0; /* output samples */ float tmpbuf[LPC10_SAMPLES_PER_FRAME]; INT32 bits[LPC10_BITS_IN_COMPRESSED_FRAME]; /* XXX what ??? */ /* We can't work on anything less than a frame in size */ if (pvt->samples < LPC10_SAMPLES_PER_FRAME) return NULL; while (pvt->samples >= LPC10_SAMPLES_PER_FRAME) { /* Encode a frame of data */ for (x=0;x<LPC10_SAMPLES_PER_FRAME;x++) tmpbuf[x] = (float)tmp->buf[x + samples] / 32768.0; lpc10_encode(tmpbuf, bits, tmp->lpc10.enc); build_bits(pvt->outbuf.uc + datalen, bits); datalen += LPC10_BYTES_IN_COMPRESSED_FRAME; samples += LPC10_SAMPLES_PER_FRAME; pvt->samples -= LPC10_SAMPLES_PER_FRAME; /* Use one of the two left over bits to record if this is a 22 or 23 ms frame... important for IAX use */ tmp->longer = 1 - tmp->longer; } /* Move the data at the end of the buffer to the front */ if (pvt->samples) memmove(tmp->buf, tmp->buf + samples, pvt->samples * 2); return ast_trans_frameout(pvt, datalen, samples); }
static int load_module | ( | void | ) | [static] |
Definition at line 237 of file codec_lpc10.c.
References AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, ast_register_translator, and ast_unregister_translator().
{ int res; res = ast_register_translator(&lpc10tolin); if (!res) res = ast_register_translator(&lintolpc10); else ast_unregister_translator(&lpc10tolin); if (res) return AST_MODULE_LOAD_FAILURE; return AST_MODULE_LOAD_SUCCESS; }
static int lpc10_dec_new | ( | struct ast_trans_pvt * | pvt | ) | [static] |
Definition at line 71 of file codec_lpc10.c.
References lpc10_coder_pvt::dec, lpc10_coder_pvt::lpc10, and ast_trans_pvt::pvt.
{ struct lpc10_coder_pvt *tmp = pvt->pvt; return (tmp->lpc10.dec = create_lpc10_decoder_state()) ? 0 : -1; }
static void lpc10_destroy | ( | struct ast_trans_pvt * | arg | ) | [static] |
Definition at line 187 of file codec_lpc10.c.
References ast_free, lpc10_coder_pvt::enc, lpc10_coder_pvt::lpc10, and ast_trans_pvt::pvt.
{ struct lpc10_coder_pvt *pvt = arg->pvt; /* Enc and DEC are both just allocated, so they can be freed */ ast_free(pvt->lpc10.enc); }
static int lpc10_enc_new | ( | struct ast_trans_pvt * | pvt | ) | [static] |
Definition at line 64 of file codec_lpc10.c.
References lpc10_coder_pvt::enc, lpc10_coder_pvt::lpc10, and ast_trans_pvt::pvt.
{ struct lpc10_coder_pvt *tmp = pvt->pvt; return (tmp->lpc10.enc = create_lpc10_encoder_state()) ? 0 : -1; }
static int lpc10tolin_framein | ( | struct ast_trans_pvt * | pvt, |
struct ast_frame * | f | ||
) | [static] |
Definition at line 109 of file codec_lpc10.c.
References ast_log(), BUFFER_SAMPLES, ast_frame::data, ast_frame::datalen, ast_trans_pvt::datalen, lpc10_coder_pvt::dec, extract_bits(), ast_trans_pvt::i16, len(), LOG_WARNING, lpc10_coder_pvt::lpc10, LPC10_BYTES_IN_COMPRESSED_FRAME, ast_trans_pvt::outbuf, ast_frame::ptr, ast_trans_pvt::pvt, and ast_trans_pvt::samples.
{ struct lpc10_coder_pvt *tmp = pvt->pvt; int16_t *dst = pvt->outbuf.i16; int len = 0; while (len + LPC10_BYTES_IN_COMPRESSED_FRAME <= f->datalen) { int x; float tmpbuf[LPC10_SAMPLES_PER_FRAME]; INT32 bits[LPC10_BITS_IN_COMPRESSED_FRAME]; /* XXX see note */ if (pvt->samples + LPC10_SAMPLES_PER_FRAME > BUFFER_SAMPLES) { ast_log(LOG_WARNING, "Out of buffer space\n"); return -1; } extract_bits(bits, f->data.ptr + len); if (lpc10_decode(bits, tmpbuf, tmp->lpc10.dec)) { ast_log(LOG_WARNING, "Invalid lpc10 data\n"); return -1; } for (x=0;x<LPC10_SAMPLES_PER_FRAME;x++) { /* Convert to a short between -1.0 and 1.0 */ dst[pvt->samples + x] = (int16_t)(32768.0 * tmpbuf[x]); } pvt->samples += LPC10_SAMPLES_PER_FRAME; pvt->datalen += 2*LPC10_SAMPLES_PER_FRAME; len += LPC10_BYTES_IN_COMPRESSED_FRAME; } if (len != f->datalen) printf("Decoded %d, expected %d\n", len, f->datalen); return 0; }
static int reload | ( | void | ) | [static] |
Definition at line 221 of file codec_lpc10.c.
References AST_MODULE_LOAD_SUCCESS.
{ return AST_MODULE_LOAD_SUCCESS; }
static int unload_module | ( | void | ) | [static] |
Definition at line 227 of file codec_lpc10.c.
References ast_unregister_translator().
{ int res; res = ast_unregister_translator(&lintolpc10); res |= ast_unregister_translator(&lpc10tolin); return res; }
struct ast_module_info __MODULE_INFO_SECTION __mod_info = { __MODULE_INFO_GLOBALS .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "LPC10 2.4kbps Coder/Decoder" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .reload = reload, } [static] |
Definition at line 255 of file codec_lpc10.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 255 of file codec_lpc10.c.
struct ast_translator lintolpc10 [static] |
Definition at line 207 of file codec_lpc10.c.
struct ast_translator lpc10tolin [static] |
Definition at line 194 of file codec_lpc10.c.