Debian Codegraph @

codecs/codec_alaw.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_alaw.c - translate between signed linear and alaw
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/config.h"
34 #include "asterisk/translate.h"
35 #include "asterisk/alaw.h"
36 #include "asterisk/utils.h"
37
38 #define BUFFER_SAMPLES 8096 /* size for the translation buffers */
39
40 /* Sample frame data */
41 #include "asterisk/slin.h"
42 #include "ex_alaw.h"
43
44 /*! \brief decode frame into lin and fill output buffer. */
45 static int alawtolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
46 {
47 int i = f->samples;
48 unsigned char *src = f->data.ptr;
49 int16_t *dst = pvt->outbuf.i16 + pvt->samples;
50
51 pvt->samples += i;
52 pvt->datalen += i * 2; /* 2 bytes/sample */
53
54 while (i--)
55 *dst++ = AST_ALAW(*src++);
56
57 return 0;
58 }
59
60 /*! \brief convert and store input samples in output buffer */
61 static int lintoalaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
62 {
63 int i = f->samples;
64 char *dst = pvt->outbuf.c + pvt->samples;
65 int16_t *src = f->data.ptr;
66
67 pvt->samples += i;
68 pvt->datalen += i; /* 1 byte/sample */
69
70 while (i--)
71 *dst++ = AST_LIN2A(*src++);
72
73 return 0;
74 }
75
76 static struct ast_translator alawtolin = {
77 .name = "alawtolin",
78 .src_codec = {
79 .name = "alaw",
80 .type = AST_MEDIA_TYPE_AUDIO,
81 .sample_rate = 8000,
82 },
83 .dst_codec = {
84 .name = "slin",
85 .type = AST_MEDIA_TYPE_AUDIO,
86 .sample_rate = 8000,
87 },
88 .format = "slin",
89 .framein = alawtolin_framein,
90 .sample = alaw_sample,
91 .buffer_samples = BUFFER_SAMPLES,
92 .buf_size = BUFFER_SAMPLES * 2,
93 };
94
95 static struct ast_translator lintoalaw = {
96 .name = "lintoalaw",
97 .src_codec = {
98 .name = "slin",
99 .type = AST_MEDIA_TYPE_AUDIO,
100 .sample_rate = 8000,
101 },
102 .dst_codec = {
103 .name = "alaw",
104 .type = AST_MEDIA_TYPE_AUDIO,
105 .sample_rate = 8000,
106 },
107 .format = "alaw",
108 .framein = lintoalaw_framein,
109 .sample = slin8_sample,
110 .buffer_samples = BUFFER_SAMPLES,
111 .buf_size = BUFFER_SAMPLES,
112 };
113
114 static int unload_module(void)
115 {
116 int res;
117
118 res = ast_unregister_translator(&lintoalaw);
119 res |= ast_unregister_translator(&alawtolin);
120
121 return res;
122 }
123
124 static int load_module(void)
125 {
126 int res;
127
128 res = ast_register_translator(&alawtolin);
129 res |= ast_register_translator(&lintoalaw);
130
131 if (res) {
132 unload_module();
133 return AST_MODULE_LOAD_DECLINE;
134 }
135
136 return AST_MODULE_LOAD_SUCCESS;
137 }
138
139 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "A-law Coder/Decoder",
140 .support_level = AST_MODULE_SUPPORT_CORE,
141 .load = load_module,
142 .unload = unload_module,
143 );