Debian Codegraph @

codecs/codec_a_mu.c

raw symbols SCIP
1 /*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 1999 - 2005, Digium, Inc.
5 *
6 * Mark Spencer <[email protected]>
7 *
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.
13 *
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.
17 */
18
19 /*! \file
20 *
21 * \brief codec_a_mu.c - translate between alaw and ulaw directly
22 *
23 * \ingroup codecs
24 */
25
26 /*** MODULEINFO
27 <support_level>core</support_level>
28 ***/
29
30 #include "asterisk.h"
31
32 #include "asterisk/module.h"
33 #include "asterisk/translate.h"
34 #include "asterisk/alaw.h"
35 #include "asterisk/ulaw.h"
36 #include "asterisk/utils.h"
37
38 #define BUFFER_SAMPLES 8000 /* size for the translation buffers */
39
40 static unsigned char mu2a[256];
41 static unsigned char a2mu[256];
42
43 /* Sample frame data */
44 #include "ex_ulaw.h"
45 #include "ex_alaw.h"
46
47 /*! \brief convert frame data and store into the buffer */
48 static int alawtoulaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
49 {
50 int x = f->samples;
51 unsigned char *src = f->data.ptr;
52 unsigned char *dst = pvt->outbuf.uc + pvt->samples;
53
54 pvt->samples += x;
55 pvt->datalen += x;
56
57 while (x--)
58 *dst++ = a2mu[*src++];
59
60 return 0;
61 }
62
63 /*! \brief convert frame data and store into the buffer */
64 static int ulawtoalaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
65 {
66 int x = f->samples;
67 unsigned char *src = f->data.ptr;
68 unsigned char *dst = pvt->outbuf.uc + pvt->samples;
69
70 pvt->samples += x;
71 pvt->datalen += x;
72
73 while (x--)
74 *dst++ = mu2a[*src++];
75
76 return 0;
77 }
78
79 static struct ast_translator alawtoulaw = {
80 .name = "alawtoulaw",
81 .src_codec = {
82 .name = "alaw",
83 .type = AST_MEDIA_TYPE_AUDIO,
84 .sample_rate = 8000,
85 },
86 .dst_codec = {
87 .name = "ulaw",
88 .type = AST_MEDIA_TYPE_AUDIO,
89 .sample_rate = 8000,
90 },
91 .format = "ulaw",
92 .framein = alawtoulaw_framein,
93 .sample = alaw_sample,
94 .buffer_samples = BUFFER_SAMPLES,
95 .buf_size = BUFFER_SAMPLES,
96 };
97
98 static struct ast_translator ulawtoalaw = {
99 .name = "ulawtoalaw",
100 .src_codec = {
101 .name = "ulaw",
102 .type = AST_MEDIA_TYPE_AUDIO,
103 .sample_rate = 8000,
104 },
105 .dst_codec = {
106 .name = "alaw",
107 .type = AST_MEDIA_TYPE_AUDIO,
108 .sample_rate = 8000,
109 },
110 .format = "alaw",
111 .framein = ulawtoalaw_framein,
112 .sample = ulaw_sample,
113 .buffer_samples = BUFFER_SAMPLES,
114 .buf_size = BUFFER_SAMPLES,
115 };
116
117 /*! \brief standard module glue */
118
119 static int unload_module(void)
120 {
121 int res;
122
123 res = ast_unregister_translator(&ulawtoalaw);
124 res |= ast_unregister_translator(&alawtoulaw);
125
126 return res;
127 }
128
129 static int load_module(void)
130 {
131 int res;
132 int x;
133
134 for (x=0;x<256;x++) {
135 mu2a[x] = AST_LIN2A(AST_MULAW(x));
136 a2mu[x] = AST_LIN2MU(AST_ALAW(x));
137 }
138
139 res = ast_register_translator(&alawtoulaw);
140 res |= ast_register_translator(&ulawtoalaw);
141
142 if (res) {
143 unload_module();
144 return AST_MODULE_LOAD_DECLINE;
145 }
146
147 return AST_MODULE_LOAD_SUCCESS;
148 }
149
150 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "A-law and Mulaw direct Coder/Decoder");