46 #define BUFFER_SAMPLES 8096
49 #include "asterisk/slin.h"
56 static int indsft[8] = { -1, -1, -1, -1, 2, 4, 6, 8 };
62 static int stpsz[49] = {
63 16, 17, 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, 50, 55, 60, 66, 73,
64 80, 88, 97, 107, 118, 130, 143, 157, 173, 190, 209, 230, 253, 279,
65 307, 337, 371, 408, 449, 494, 544, 598, 658, 724, 796, 876, 963,
66 1060, 1166, 1282, 1411, 1552
97 step = stpsz[state->ssindex];
99 sign = encoded & 0x08;
102 diff = (((encoded << 1) + 1) * step) >> 3;
111 if ((encoded >> 1) & step & 0x1)
117 if (state->next_flag & 0x1)
119 else if (state->next_flag & 0x2)
122 state->signal += diff;
124 if (state->signal > 2047)
125 state->signal = 2047;
126 else if (state->signal < -2047)
127 state->signal = -2047;
129 state->next_flag = 0;
133 state->zero_count = 0;
134 else if (++(state->zero_count) == 24) {
135 state->zero_count = 0;
136 if (state->signal > 0)
137 state->next_flag = 0x1;
138 else if (state->signal < 0)
139 state->next_flag = 0x2;
143 state->ssindex += indsft[encoded];
144 if (state->ssindex < 0)
146 else if (state->ssindex > 48)
149 return state->signal << 4;
164 static inline int adpcm(
short csig,
struct adpcm_state *state)
175 step = stpsz[state->ssindex];
176 diff = csig - state->signal;
180 encoded = (-diff << 2) / step;
185 encoded = (diff << 2) / step;
210 decode(encoded, state);
220 int16_t
inbuf[BUFFER_SAMPLES];
233 unsigned char *src = f->
data.ptr;
234 int16_t *dst = pvt->outbuf.i16 + pvt->
samples;
237 *dst++ = decode((*src >> 4) & 0xf, &tmp->state);
238 *dst++ = decode(*src++ & 0x0f, &tmp->state);
268 for (i = 0; i < pvt->
samples; i += 2) {
270 (adpcm(tmp->inbuf[i ], &tmp->state) << 4) |
271 (adpcm(tmp->inbuf[i+1], &tmp->state) );
282 tmp->inbuf[0] = tmp->inbuf[samples - 1];
290 .
name =
"adpcmtolin",
293 .type = AST_MEDIA_TYPE_AUDIO,
298 .type = AST_MEDIA_TYPE_AUDIO,
303 .sample = adpcm_sample,
305 .buffer_samples = BUFFER_SAMPLES,
306 .buf_size = BUFFER_SAMPLES * 2,
310 .
name =
"lintoadpcm",
313 .type = AST_MEDIA_TYPE_AUDIO,
318 .type = AST_MEDIA_TYPE_AUDIO,
324 .sample = slin8_sample,
326 .buffer_samples = BUFFER_SAMPLES,
327 .buf_size = BUFFER_SAMPLES/ 2,
330 static int unload_module(
void)
340 static int load_module(
void)
355 AST_MODULE_INFO(
ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT,
"Adaptive Differential PCM Coder/Decoder",
356 .support_level = AST_MODULE_SUPPORT_CORE,
358 .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 locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
Workspace for translating ADPCM signals to signed linear.
Descriptor of a translator.
Support for translation of data formats. translate.c.
static int inbuf(struct baseio *bio, FILE *fi)
utility used by inchar(), for base_encode()
static int lintoadpcm_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
fill input buffer with 16-bit signed linear PCM values.
Configuration File Parser.
static struct ast_frame * lintoadpcm_frameout(struct ast_trans_pvt *pvt)
convert inbuf and store into frame
#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
Module has failed to load, may be in an inconsistent state.
static int adpcmtolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
decode 4-bit adpcm frame data and store in output buffer
Data structure associated with a single frame of data.
Workspace for translating signed linear signals to ADPCM.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.