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$")
31 #include <netinet/in.h>
37 #include "asterisk/lock.h"
38 #include "asterisk/logger.h"
39 #include "asterisk/module.h"
40 #include "asterisk/translate.h"
41 #include "asterisk/channel.h"
42 #include "asterisk/alaw.h"
43 #include "asterisk/ulaw.h"
44 #include "asterisk/utils.h"
46 #define BUFFER_SAMPLES 8000 /* size for the translation buffers */
48 static unsigned char mu2a
[256];
49 static unsigned char a2mu
[256];
51 /* Sample frame data (Mu data is okay) */
53 #include "ulaw_slin_ex.h"
55 /*! \brief convert frame data and store into the buffer */
56 static int alawtoulaw_framein(struct ast_trans_pvt
*pvt
, struct ast_frame
*f
)
59 unsigned char *src
= f
->data
;
60 unsigned char *dst
= (unsigned char *)pvt
->outbuf
+ pvt
->samples
;
66 *dst
++ = a2mu
[*src
++];
71 /*! \brief convert frame data and store into the buffer */
72 static int ulawtoalaw_framein(struct ast_trans_pvt
*pvt
, struct ast_frame
*f
)
75 unsigned char *src
= f
->data
;
76 unsigned char *dst
= (unsigned char *)pvt
->outbuf
+ pvt
->samples
;
82 *dst
++ = mu2a
[*src
++];
88 * alawToLin_Sample. Just random data, somehow...
90 static struct ast_frame
*alawtoulaw_sample(void)
92 static struct ast_frame f
;
93 f
.frametype
= AST_FRAME_VOICE
;
94 f
.subclass
= AST_FORMAT_ALAW
;
95 f
.datalen
= sizeof(ulaw_slin_ex
);
96 f
.samples
= sizeof(ulaw_slin_ex
);
99 f
.src
= __PRETTY_FUNCTION__
;
100 f
.data
= ulaw_slin_ex
; /* XXX what ? */
104 static struct ast_frame
*ulawtoalaw_sample(void)
106 static struct ast_frame f
;
107 f
.frametype
= AST_FRAME_VOICE
;
108 f
.subclass
= AST_FORMAT_ULAW
;
109 f
.datalen
= sizeof(ulaw_slin_ex
);
110 f
.samples
= sizeof(ulaw_slin_ex
);
113 f
.src
= __PRETTY_FUNCTION__
;
114 f
.data
= ulaw_slin_ex
;
118 static struct ast_translator alawtoulaw
= {
119 .name
= "alawtoulaw",
120 .srcfmt
= AST_FORMAT_ALAW
,
121 .dstfmt
= AST_FORMAT_ULAW
,
122 .framein
= alawtoulaw_framein
,
123 .sample
= alawtoulaw_sample
,
124 .buffer_samples
= BUFFER_SAMPLES
,
125 .buf_size
= BUFFER_SAMPLES
,
128 static struct ast_translator ulawtoalaw
= {
129 .name
= "ulawtoalaw",
130 .srcfmt
= AST_FORMAT_ULAW
,
131 .dstfmt
= AST_FORMAT_ALAW
,
132 .framein
= ulawtoalaw_framein
,
133 .sample
= ulawtoalaw_sample
,
134 .buffer_samples
= BUFFER_SAMPLES
,
135 .buf_size
= BUFFER_SAMPLES
,
138 /*! \brief standard module glue */
140 static int unload_module(void)
144 res
= ast_unregister_translator(&ulawtoalaw
);
145 res
|= ast_unregister_translator(&alawtoulaw
);
150 static int load_module(void)
155 for (x
=0;x
<256;x
++) {
156 mu2a
[x
] = AST_LIN2A(AST_MULAW(x
));
157 a2mu
[x
] = AST_LIN2MU(AST_ALAW(x
));
159 res
= ast_register_translator(&alawtoulaw
);
161 res
= ast_register_translator(&ulawtoalaw
);
163 ast_unregister_translator(&alawtoulaw
);
168 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY
, "A-law and Mulaw direct Coder/Decoder");