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 (Mu data is okay) */
43 #include "ulaw_slin_ex.h"
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
= (unsigned char *)pvt
->outbuf
+ 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
= (unsigned char *)pvt
->outbuf
+ pvt
->samples
;
72 *dst
++ = mu2a
[*src
++];
78 * alawToLin_Sample. Just random data, somehow...
80 static struct ast_frame
*alawtoulaw_sample(void)
82 static struct ast_frame f
;
83 f
.frametype
= AST_FRAME_VOICE
;
84 f
.subclass
= AST_FORMAT_ALAW
;
85 f
.datalen
= sizeof(ulaw_slin_ex
);
86 f
.samples
= sizeof(ulaw_slin_ex
);
89 f
.src
= __PRETTY_FUNCTION__
;
90 f
.data
.ptr
= ulaw_slin_ex
; /* XXX what ? */
94 static struct ast_frame
*ulawtoalaw_sample(void)
96 static struct ast_frame f
;
97 f
.frametype
= AST_FRAME_VOICE
;
98 f
.subclass
= AST_FORMAT_ULAW
;
99 f
.datalen
= sizeof(ulaw_slin_ex
);
100 f
.samples
= sizeof(ulaw_slin_ex
);
103 f
.src
= __PRETTY_FUNCTION__
;
104 f
.data
.ptr
= ulaw_slin_ex
;
108 static struct ast_translator alawtoulaw
= {
109 .name
= "alawtoulaw",
110 .srcfmt
= AST_FORMAT_ALAW
,
111 .dstfmt
= AST_FORMAT_ULAW
,
112 .framein
= alawtoulaw_framein
,
113 .sample
= alawtoulaw_sample
,
114 .buffer_samples
= BUFFER_SAMPLES
,
115 .buf_size
= BUFFER_SAMPLES
,
118 static struct ast_translator ulawtoalaw
= {
119 .name
= "ulawtoalaw",
120 .srcfmt
= AST_FORMAT_ULAW
,
121 .dstfmt
= AST_FORMAT_ALAW
,
122 .framein
= ulawtoalaw_framein
,
123 .sample
= ulawtoalaw_sample
,
124 .buffer_samples
= BUFFER_SAMPLES
,
125 .buf_size
= BUFFER_SAMPLES
,
128 /*! \brief standard module glue */
130 static int unload_module(void)
134 res
= ast_unregister_translator(&ulawtoalaw
);
135 res
|= ast_unregister_translator(&alawtoulaw
);
140 static int load_module(void)
145 for (x
=0;x
<256;x
++) {
146 mu2a
[x
] = AST_LIN2A(AST_MULAW(x
));
147 a2mu
[x
] = AST_LIN2MU(AST_ALAW(x
));
149 res
= ast_register_translator(&alawtoulaw
);
151 res
= ast_register_translator(&ulawtoalaw
);
153 ast_unregister_translator(&alawtoulaw
);
155 return AST_MODULE_LOAD_FAILURE
;
156 return AST_MODULE_LOAD_SUCCESS
;
159 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY
, "A-law and Mulaw direct Coder/Decoder");