Asterisk - The Open Source Telephony Project GIT-master-f36a736
codec_alaw.c
Go to the documentation of this file.
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/*** 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. */
45static 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 */
61static 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
76static struct ast_translator alawtolin = {
77 .name = "alawtolin",
78 .src_codec = {
79 .name = "alaw",
81 .sample_rate = 8000,
82 },
83 .dst_codec = {
84 .name = "slin",
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
95static struct ast_translator lintoalaw = {
96 .name = "lintoalaw",
97 .src_codec = {
98 .name = "slin",
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
114static int unload_module(void)
115{
116 int res;
117
120
121 return res;
122}
123
124static int load_module(void)
125{
126 int res;
127
130
131 if (res) {
134 }
135
137}
138
140 .support_level = AST_MODULE_SUPPORT_CORE,
141 .load = load_module,
142 .unload = unload_module,
A-Law to Signed linear conversion.
#define AST_LIN2A(a)
Definition: alaw.h:50
#define AST_ALAW(a)
Definition: alaw.h:84
Asterisk main include file. File version handling, generic pbx functions.
@ AST_MEDIA_TYPE_AUDIO
Definition: codec.h:32
#define BUFFER_SAMPLES
Definition: codec_alaw.c:38
static int lintoalaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
convert and store input samples in output buffer
Definition: codec_alaw.c:61
static struct ast_translator alawtolin
Definition: codec_alaw.c:76
static struct ast_translator lintoalaw
Definition: codec_alaw.c:95
static int alawtolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
decode frame into lin and fill output buffer.
Definition: codec_alaw.c:45
static int load_module(void)
Definition: codec_alaw.c:124
static int unload_module(void)
Definition: codec_alaw.c:114
short int16_t
Definition: db.h:59
8-bit data
static struct ast_frame * alaw_sample(void)
Definition: ex_alaw.h:26
Configuration File Parser.
Asterisk module definitions.
@ AST_MODFLAG_DEFAULT
Definition: module.h:329
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
Definition: module.h:557
@ AST_MODULE_SUPPORT_CORE
Definition: module.h:121
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
static struct ast_frame * slin8_sample(void)
Definition: slin.h:64
Data structure associated with a single frame of data.
union ast_frame::@226 data
Default structure for translators, with the basic fields and buffers, all allocated as part of the sa...
Definition: translate.h:213
int datalen
actual space used in outbuf
Definition: translate.h:218
union ast_trans_pvt::@287 outbuf
int16_t * i16
Definition: translate.h:223
Descriptor of a translator.
Definition: translate.h:137
char name[80]
Definition: translate.h:138
Support for translation of data formats. translate.c.
#define ast_register_translator(t)
See __ast_register_translator()
Definition: translate.h:258
int ast_unregister_translator(struct ast_translator *t)
Unregister a translator Unregisters the given translator.
Definition: translate.c:1350
Utility functions.