48 #include "asterisk/slin.h"
56 #define LPC10_BYTES_IN_COMPRESSED_FRAME (LPC10_BITS_IN_COMPRESSED_FRAME + 7)/8
58 #define BUFFER_SAMPLES 8000
66 short buf[BUFFER_SAMPLES];
74 return (tmp->lpc10.enc = create_lpc10_encoder_state()) ? 0 : -1;
81 return (tmp->lpc10.dec = create_lpc10_decoder_state()) ? 0 : -1;
84 static void extract_bits(INT32 *bits,
unsigned char *c)
87 for (x=0;x<LPC10_BITS_IN_COMPRESSED_FRAME;x++) {
88 if (*c & (0x80 >> (x & 7)))
98 static void build_bits(
unsigned char *c, INT32 *bits)
100 unsigned char mask=0x80;
103 for (x=0;x<LPC10_BITS_IN_COMPRESSED_FRAME;x++) {
118 int16_t *dst = pvt->outbuf.i16;
121 while (len + LPC10_BYTES_IN_COMPRESSED_FRAME <= f->datalen) {
123 float tmpbuf[LPC10_SAMPLES_PER_FRAME];
124 INT32 bits[LPC10_BITS_IN_COMPRESSED_FRAME];
125 if (pvt->
samples + LPC10_SAMPLES_PER_FRAME > BUFFER_SAMPLES) {
126 ast_log(LOG_WARNING,
"Out of buffer space\n");
129 extract_bits(bits, f->
data.ptr + len);
130 if (lpc10_decode(bits, tmpbuf, tmp->lpc10.dec)) {
131 ast_log(LOG_WARNING,
"Invalid lpc10 data\n");
134 for (x=0;x<LPC10_SAMPLES_PER_FRAME;x++) {
136 dst[pvt->
samples + x] = (int16_t)(32768.0 * tmpbuf[x]);
139 pvt->
samples += LPC10_SAMPLES_PER_FRAME;
140 pvt->
datalen += 2*LPC10_SAMPLES_PER_FRAME;
141 len += LPC10_BYTES_IN_COMPRESSED_FRAME;
144 printf(
"Decoded %d, expected %d\n", len, f->
datalen);
154 ast_log(LOG_WARNING,
"Out of buffer space\n");
169 while (pvt->
samples >= LPC10_SAMPLES_PER_FRAME) {
171 float tmpbuf[LPC10_SAMPLES_PER_FRAME];
172 INT32 bits[LPC10_BITS_IN_COMPRESSED_FRAME];
176 for (x=0;x<LPC10_SAMPLES_PER_FRAME;x++)
177 tmpbuf[x] = (
float)tmp->buf[x +
samples] / 32768.0;
178 lpc10_encode(tmpbuf, bits, tmp->lpc10.enc);
179 build_bits(pvt->outbuf.
uc, bits);
181 samples += LPC10_SAMPLES_PER_FRAME;
182 pvt->
samples -= LPC10_SAMPLES_PER_FRAME;
185 tmp->longer = 1 - tmp->longer;
187 current =
ast_trans_frameout(pvt, LPC10_BYTES_IN_COMPRESSED_FRAME, LPC10_SAMPLES_PER_FRAME);
200 memmove(tmp->buf, tmp->buf + samples, pvt->
samples * 2);
211 ast_free(pvt->lpc10.enc);
215 .
name =
"lpc10tolin",
218 .type = AST_MEDIA_TYPE_AUDIO,
223 .type = AST_MEDIA_TYPE_AUDIO,
227 .newpvt = lpc10_dec_new,
228 .framein = lpc10tolin_framein,
229 .destroy = lpc10_destroy,
230 .sample = lpc10_sample,
232 .buffer_samples = BUFFER_SAMPLES,
233 .buf_size = BUFFER_SAMPLES * 2,
237 .
name =
"lintolpc10",
240 .type = AST_MEDIA_TYPE_AUDIO,
245 .type = AST_MEDIA_TYPE_AUDIO,
249 .newpvt = lpc10_enc_new,
250 .framein = lintolpc10_framein,
251 .frameout = lintolpc10_frameout,
252 .destroy = lpc10_destroy,
253 .sample = slin8_sample,
255 .buffer_samples = BUFFER_SAMPLES,
256 .buf_size = LPC10_BYTES_IN_COMPRESSED_FRAME * (1 + BUFFER_SAMPLES / LPC10_SAMPLES_PER_FRAME),
259 static int unload_module(
void)
269 static int load_module(
void)
284 AST_MODULE_INFO(
ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT,
"LPC10 2.4kbps Coder/Decoder",
285 .support_level = AST_MODULE_SUPPORT_CORE,
287 .unload = unload_module,
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.
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
Configuration File Parser.
#define ast_register_translator(t)
See __ast_register_translator()
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
Copyright (C) 2008, Digium, Inc.
Module has failed to load, may be in an inconsistent state.
Data structure associated with a single frame of data.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.