Remove unnecessary code relating to PLC.
[asterisk/asterisk.git] / codecs / codec_alaw.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2005, Digium, Inc.
5  *
6  * Mark Spencer <markster@digium.com>
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 #include "asterisk.h"
27
28 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
29
30 #include "asterisk/module.h"
31 #include "asterisk/config.h"
32 #include "asterisk/translate.h"
33 #include "asterisk/alaw.h"
34 #include "asterisk/utils.h"
35
36 #define BUFFER_SAMPLES   8096   /* size for the translation buffers */
37
38 /* Sample frame data */
39 #include "asterisk/slin.h"
40 #include "ex_alaw.h"
41
42 /*! \brief decode frame into lin and fill output buffer. */
43 static int alawtolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
44 {
45         int i = f->samples;
46         unsigned char *src = f->data.ptr;
47         int16_t *dst = pvt->outbuf.i16 + pvt->samples;
48
49         pvt->samples += i;
50         pvt->datalen += i * 2;  /* 2 bytes/sample */
51         
52         while (i--)
53                 *dst++ = AST_ALAW(*src++);
54
55         return 0;
56 }
57
58 /*! \brief convert and store input samples in output buffer */
59 static int lintoalaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
60 {
61         int i = f->samples;
62         char *dst = pvt->outbuf.c + pvt->samples;
63         int16_t *src = f->data.ptr;
64
65         pvt->samples += i;
66         pvt->datalen += i;      /* 1 byte/sample */
67
68         while (i--) 
69                 *dst++ = AST_LIN2A(*src++);
70
71         return 0;
72 }
73
74 static struct ast_translator alawtolin = {
75         .name = "alawtolin",
76         .srcfmt = AST_FORMAT_ALAW,
77         .dstfmt = AST_FORMAT_SLINEAR,
78         .framein = alawtolin_framein,
79         .sample = alaw_sample,
80         .buffer_samples = BUFFER_SAMPLES,
81         .buf_size = BUFFER_SAMPLES * 2,
82 };
83
84 static struct ast_translator lintoalaw = {
85         "lintoalaw",
86         .srcfmt = AST_FORMAT_SLINEAR,
87         .dstfmt = AST_FORMAT_ALAW,
88         .framein = lintoalaw_framein,
89         .sample = slin8_sample,
90         .buffer_samples = BUFFER_SAMPLES,
91         .buf_size = BUFFER_SAMPLES,
92 };
93
94 /*! \brief standard module stuff */
95
96 static int reload(void)
97 {
98         return AST_MODULE_LOAD_SUCCESS;
99 }
100
101 static int unload_module(void)
102 {
103         int res;
104
105         res = ast_unregister_translator(&lintoalaw);
106         res |= ast_unregister_translator(&alawtolin);
107
108         return res;
109 }
110
111 static int load_module(void)
112 {
113         int res;
114
115         res = ast_register_translator(&alawtolin);
116         if (!res)
117                 res = ast_register_translator(&lintoalaw);
118         else
119                 ast_unregister_translator(&alawtolin);
120         if (res)
121                 return AST_MODULE_LOAD_FAILURE;
122         return AST_MODULE_LOAD_SUCCESS;
123 }
124
125 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "A-law Coder/Decoder",
126                 .load = load_module,
127                 .unload = unload_module,
128                 .reload = reload,
129                );