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_a_mu.c - translate between alaw and ulaw directly
28 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
30 #include "asterisk/module.h"
31 #include "asterisk/translate.h"
32 #include "asterisk/alaw.h"
33 #include "asterisk/ulaw.h"
34 #include "asterisk/utils.h"
36 #define BUFFER_SAMPLES 8000 /* size for the translation buffers */
38 static unsigned char mu2a[256];
39 static unsigned char a2mu[256];
41 /* Sample frame data */
45 /*! \brief convert frame data and store into the buffer */
46 static int alawtoulaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
49 unsigned char *src = f->data.ptr;
50 unsigned char *dst = pvt->outbuf.uc + pvt->samples;
56 *dst++ = a2mu[*src++];
61 /*! \brief convert frame data and store into the buffer */
62 static int ulawtoalaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
65 unsigned char *src = f->data.ptr;
66 unsigned char *dst = pvt->outbuf.uc + pvt->samples;
72 *dst++ = mu2a[*src++];
77 static struct ast_translator alawtoulaw = {
79 .srcfmt = AST_FORMAT_ALAW,
80 .dstfmt = AST_FORMAT_ULAW,
81 .framein = alawtoulaw_framein,
82 .sample = alaw_sample,
83 .buffer_samples = BUFFER_SAMPLES,
84 .buf_size = BUFFER_SAMPLES,
87 static struct ast_translator ulawtoalaw = {
89 .srcfmt = AST_FORMAT_ULAW,
90 .dstfmt = AST_FORMAT_ALAW,
91 .framein = ulawtoalaw_framein,
92 .sample = ulaw_sample,
93 .buffer_samples = BUFFER_SAMPLES,
94 .buf_size = BUFFER_SAMPLES,
97 /*! \brief standard module glue */
99 static int unload_module(void)
103 res = ast_unregister_translator(&ulawtoalaw);
104 res |= ast_unregister_translator(&alawtoulaw);
109 static int load_module(void)
114 for (x=0;x<256;x++) {
115 mu2a[x] = AST_LIN2A(AST_MULAW(x));
116 a2mu[x] = AST_LIN2MU(AST_ALAW(x));
118 res = ast_register_translator(&alawtoulaw);
120 res = ast_register_translator(&ulawtoalaw);
122 ast_unregister_translator(&alawtoulaw);
124 return AST_MODULE_LOAD_FAILURE;
125 return AST_MODULE_LOAD_SUCCESS;
128 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "A-law and Mulaw direct Coder/Decoder");