Asterisk - The Open Source Telephony Project GIT-master-f36a736
Data Structures | Macros | Functions | Variables
codec_lpc10.c File Reference

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 "asterisk/linkedlists.h"
#include "lpc10/lpc10.h"
#include "asterisk/slin.h"
#include "ex_lpc10.h"
Include dependency graph for codec_lpc10.c:

Go to the source code of this file.

Data Structures

struct  lpc10_coder_pvt
 

Macros

#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)
 
struct ast_moduleAST_MODULE_SELF_SYM (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_framelintolpc10_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 unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "LPC10 2.4kbps Coder/Decoder" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_translator lintolpc10
 
static struct ast_translator lpc10tolin
 

Detailed Description

Translate between signed linear and LPC10 (Linear Predictor Code)

Definition in file codec_lpc10.c.

Macro Definition Documentation

◆ BUFFER_SAMPLES

#define BUFFER_SAMPLES   8000

Definition at line 55 of file codec_lpc10.c.

◆ LPC10_BYTES_IN_COMPRESSED_FRAME

#define LPC10_BYTES_IN_COMPRESSED_FRAME   (LPC10_BITS_IN_COMPRESSED_FRAME + 7)/8

Definition at line 53 of file codec_lpc10.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 285 of file codec_lpc10.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 285 of file codec_lpc10.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 285 of file codec_lpc10.c.

◆ build_bits()

static void build_bits ( unsigned char *  c,
INT32 *  bits 
)
static

Definition at line 95 of file codec_lpc10.c.

96{
97 unsigned char mask=0x80;
98 int x;
99 *c = 0;
100 for (x=0;x<LPC10_BITS_IN_COMPRESSED_FRAME;x++) {
101 if (bits[x])
102 *c |= mask;
103 mask = mask >> 1;
104 if ((x % 8)==7) {
105 c++;
106 *c = 0;
107 mask = 0x80;
108 }
109 }
110}
#define LPC10_BITS_IN_COMPRESSED_FRAME
Definition: lpc10.h:37
static struct test_val c

References c, and LPC10_BITS_IN_COMPRESSED_FRAME.

Referenced by lintolpc10_frameout().

◆ extract_bits()

static void extract_bits ( INT32 *  bits,
unsigned char *  c 
)
static

Definition at line 81 of file codec_lpc10.c.

82{
83 int x;
84 for (x=0;x<LPC10_BITS_IN_COMPRESSED_FRAME;x++) {
85 if (*c & (0x80 >> (x & 7)))
86 bits[x] = 1;
87 else
88 bits[x] = 0;
89 if ((x & 7) == 7)
90 c++;
91 }
92}

References c, and LPC10_BITS_IN_COMPRESSED_FRAME.

Referenced by lpc10tolin_framein().

◆ lintolpc10_framein()

static int lintolpc10_framein ( struct ast_trans_pvt pvt,
struct ast_frame f 
)
static

Definition at line 145 of file codec_lpc10.c.

146{
147 struct lpc10_coder_pvt *tmp = pvt->pvt;
148
149 /* Just add the frames to our stream */
150 if (pvt->samples + f->samples > BUFFER_SAMPLES) {
151 ast_log(LOG_WARNING, "Out of buffer space\n");
152 return -1;
153 }
154 memcpy(tmp->buf + pvt->samples, f->data.ptr, f->datalen);
155 pvt->samples += f->samples;
156 return 0;
157}
#define ast_log
Definition: astobj2.c:42
static int tmp()
Definition: bt_open.c:389
#define BUFFER_SAMPLES
Definition: codec_lpc10.c:55
#define LOG_WARNING
union ast_frame::@226 data
void * pvt
Definition: translate.h:219

References ast_log, BUFFER_SAMPLES, ast_frame::data, ast_frame::datalen, LOG_WARNING, ast_frame::ptr, ast_trans_pvt::pvt, ast_frame::samples, ast_trans_pvt::samples, and tmp().

◆ lintolpc10_frameout()

static struct ast_frame * lintolpc10_frameout ( struct ast_trans_pvt pvt)
static

Definition at line 159 of file codec_lpc10.c.

160{
161 struct lpc10_coder_pvt *tmp = pvt->pvt;
162 struct ast_frame *result = NULL;
163 struct ast_frame *last = NULL;
164 int samples = 0; /* output samples */
165
166 while (pvt->samples >= LPC10_SAMPLES_PER_FRAME) {
167 struct ast_frame *current;
168 float tmpbuf[LPC10_SAMPLES_PER_FRAME];
169 INT32 bits[LPC10_BITS_IN_COMPRESSED_FRAME]; /* XXX what ??? */
170 int x;
171
172 /* Encode a frame of data */
173 for (x=0;x<LPC10_SAMPLES_PER_FRAME;x++)
174 tmpbuf[x] = (float)tmp->buf[x + samples] / 32768.0;
175 lpc10_encode(tmpbuf, bits, tmp->lpc10.enc);
176 build_bits(pvt->outbuf.uc, bits);
177
180 /* Use one of the two left over bits to record if this is a 22 or 23 ms frame...
181 important for IAX use */
182 tmp->longer = 1 - tmp->longer;
183
185 if (!current) {
186 continue;
187 } else if (last) {
189 } else {
190 result = current;
191 }
192 last = current;
193 }
194
195 /* Move the data at the end of the buffer to the front */
196 if (samples) {
197 memmove(tmp->buf, tmp->buf + samples, pvt->samples * 2);
198 }
199
200 return result;
201}
struct sla_ringing_trunk * last
Definition: app_sla.c:332
static PGresult * result
Definition: cel_pgsql.c:84
static void build_bits(unsigned char *c, INT32 *bits)
Definition: codec_lpc10.c:95
#define LPC10_BYTES_IN_COMPRESSED_FRAME
Definition: codec_lpc10.c:53
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
Definition: linkedlists.h:439
#define LPC10_SAMPLES_PER_FRAME
Definition: lpc10.h:36
int lpc10_encode(real *speech, INT32 *bits, struct lpc10_encoder_state *st)
Definition: lpcenc.c:108
size_t current
Definition: main/cli.c:113
#define NULL
Definition: resample.c:96
Data structure associated with a single frame of data.
unsigned char * uc
Definition: translate.h:222
union ast_trans_pvt::@287 outbuf
struct ast_frame * ast_trans_frameout(struct ast_trans_pvt *pvt, int datalen, int samples)
generic frameout function
Definition: translate.c:439

References AST_LIST_NEXT, ast_trans_frameout(), build_bits(), current, last, LPC10_BITS_IN_COMPRESSED_FRAME, LPC10_BYTES_IN_COMPRESSED_FRAME, lpc10_encode(), LPC10_SAMPLES_PER_FRAME, NULL, ast_trans_pvt::outbuf, ast_trans_pvt::pvt, result, ast_frame::samples, ast_trans_pvt::samples, tmp(), and ast_trans_pvt::uc.

◆ load_module()

static int load_module ( void  )
static

Definition at line 266 of file codec_lpc10.c.

267{
268 int res;
269
272
273 if (res) {
276 }
277
279}
static struct ast_translator lpc10tolin
Definition: codec_lpc10.c:211
static struct ast_translator lintolpc10
Definition: codec_lpc10.c:233
static int unload_module(void)
Definition: codec_lpc10.c:256
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
#define ast_register_translator(t)
See __ast_register_translator()
Definition: translate.h:258

References AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_register_translator, lintolpc10, lpc10tolin, and unload_module().

◆ lpc10_dec_new()

static int lpc10_dec_new ( struct ast_trans_pvt pvt)
static

Definition at line 74 of file codec_lpc10.c.

75{
76 struct lpc10_coder_pvt *tmp = pvt->pvt;
77
78 return (tmp->lpc10.dec = create_lpc10_decoder_state()) ? 0 : -1;
79}
struct lpc10_decoder_state * create_lpc10_decoder_state(void)
Definition: lpcini.c:369

References create_lpc10_decoder_state(), ast_trans_pvt::pvt, and tmp().

◆ lpc10_destroy()

static void lpc10_destroy ( struct ast_trans_pvt arg)
static

Definition at line 204 of file codec_lpc10.c.

205{
206 struct lpc10_coder_pvt *pvt = arg->pvt;
207 /* Enc and DEC are both just allocated, so they can be freed */
208 ast_free(pvt->lpc10.enc);
209}
#define ast_free(a)
Definition: astmm.h:180
union lpc10_coder_pvt::@146 lpc10
struct lpc10_encoder_state * enc
Definition: codec_lpc10.c:59

References ast_free, lpc10_coder_pvt::enc, lpc10_coder_pvt::lpc10, and ast_trans_pvt::pvt.

◆ lpc10_enc_new()

static int lpc10_enc_new ( struct ast_trans_pvt pvt)
static

Definition at line 67 of file codec_lpc10.c.

68{
69 struct lpc10_coder_pvt *tmp = pvt->pvt;
70
71 return (tmp->lpc10.enc = create_lpc10_encoder_state()) ? 0 : -1;
72}
struct lpc10_encoder_state * create_lpc10_encoder_state(void)
Definition: lpcini.c:258

References create_lpc10_encoder_state(), ast_trans_pvt::pvt, and tmp().

◆ lpc10tolin_framein()

static int lpc10tolin_framein ( struct ast_trans_pvt pvt,
struct ast_frame f 
)
static

Definition at line 112 of file codec_lpc10.c.

113{
114 struct lpc10_coder_pvt *tmp = pvt->pvt;
115 int16_t *dst = pvt->outbuf.i16;
116 int len = 0;
117
118 while (len + LPC10_BYTES_IN_COMPRESSED_FRAME <= f->datalen) {
119 int x;
120 float tmpbuf[LPC10_SAMPLES_PER_FRAME];
121 INT32 bits[LPC10_BITS_IN_COMPRESSED_FRAME]; /* XXX see note */
123 ast_log(LOG_WARNING, "Out of buffer space\n");
124 return -1;
125 }
126 extract_bits(bits, f->data.ptr + len);
127 if (lpc10_decode(bits, tmpbuf, tmp->lpc10.dec)) {
128 ast_log(LOG_WARNING, "Invalid lpc10 data\n");
129 return -1;
130 }
131 for (x=0;x<LPC10_SAMPLES_PER_FRAME;x++) {
132 /* Convert to a short between -1.0 and 1.0 */
133 dst[pvt->samples + x] = (int16_t)(32768.0 * tmpbuf[x]);
134 }
135
139 }
140 if (len != f->datalen)
141 printf("Decoded %d, expected %d\n", len, f->datalen);
142 return 0;
143}
static void extract_bits(INT32 *bits, unsigned char *c)
Definition: codec_lpc10.c:81
short int16_t
Definition: db.h:59
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
int lpc10_decode(INT32 *bits, real *speech, struct lpc10_decoder_state *st)
Definition: lpcdec.c:113
int datalen
actual space used in outbuf
Definition: translate.h:218
int16_t * i16
Definition: translate.h:223

References ast_log, BUFFER_SAMPLES, ast_frame::data, ast_frame::datalen, ast_trans_pvt::datalen, extract_bits(), ast_trans_pvt::i16, len(), LOG_WARNING, LPC10_BITS_IN_COMPRESSED_FRAME, LPC10_BYTES_IN_COMPRESSED_FRAME, lpc10_decode(), LPC10_SAMPLES_PER_FRAME, ast_trans_pvt::outbuf, ast_frame::ptr, ast_trans_pvt::pvt, ast_trans_pvt::samples, and tmp().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 256 of file codec_lpc10.c.

257{
258 int res;
259
262
263 return res;
264}
int ast_unregister_translator(struct ast_translator *t)
Unregister a translator Unregisters the given translator.
Definition: translate.c:1350

References ast_unregister_translator(), lintolpc10, and lpc10tolin.

Referenced by load_module().

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "LPC10 2.4kbps Coder/Decoder" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, }
static

Definition at line 285 of file codec_lpc10.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 285 of file codec_lpc10.c.

◆ lintolpc10

struct ast_translator lintolpc10
static

Definition at line 233 of file codec_lpc10.c.

Referenced by load_module(), and unload_module().

◆ lpc10tolin

struct ast_translator lpc10tolin
static

Definition at line 211 of file codec_lpc10.c.

Referenced by load_module(), and unload_module().