2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
21 * \brief codec_alaw.c - translate between signed linear and alaw
28 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
30 #include "asterisk/module.h"
31 #include "asterisk/config.h"
32 #include "asterisk/translate.h"
33 #include "asterisk/alaw.h"
34 #include "asterisk/utils.h"
36 #define BUFFER_SAMPLES 8096 /* size for the translation buffers */
38 /* Sample frame data */
39 #include "asterisk/slin.h"
42 /*! \brief decode frame into lin and fill output buffer. */
43 static int alawtolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
46 unsigned char *src = f->data.ptr;
47 int16_t *dst = pvt->outbuf.i16 + pvt->samples;
50 pvt->datalen += i * 2; /* 2 bytes/sample */
53 *dst++ = AST_ALAW(*src++);
58 /*! \brief convert and store input samples in output buffer */
59 static int lintoalaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
62 char *dst = pvt->outbuf.c + pvt->samples;
63 int16_t *src = f->data.ptr;
66 pvt->datalen += i; /* 1 byte/sample */
69 *dst++ = AST_LIN2A(*src++);
74 static struct ast_translator alawtolin = {
76 .srcfmt = AST_FORMAT_ALAW,
77 .dstfmt = AST_FORMAT_SLINEAR,
78 .framein = alawtolin_framein,
79 .sample = alaw_sample,
80 .buffer_samples = BUFFER_SAMPLES,
81 .buf_size = BUFFER_SAMPLES * 2,
84 static struct ast_translator lintoalaw = {
86 .srcfmt = AST_FORMAT_SLINEAR,
87 .dstfmt = AST_FORMAT_ALAW,
88 .framein = lintoalaw_framein,
89 .sample = slin8_sample,
90 .buffer_samples = BUFFER_SAMPLES,
91 .buf_size = BUFFER_SAMPLES,
94 /*! \brief standard module stuff */
96 static int reload(void)
98 return AST_MODULE_LOAD_SUCCESS;
101 static int unload_module(void)
105 res = ast_unregister_translator(&lintoalaw);
106 res |= ast_unregister_translator(&alawtolin);
111 static int load_module(void)
115 res = ast_register_translator(&alawtolin);
117 res = ast_register_translator(&lintoalaw);
119 ast_unregister_translator(&alawtolin);
121 return AST_MODULE_LOAD_FAILURE;
122 return AST_MODULE_LOAD_SUCCESS;
125 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "A-law Coder/Decoder",
127 .unload = unload_module,