Asterisk - The Open Source Telephony Project GIT-master-f3e88d3
codec_ulaw.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_ulaw.c - translate between signed linear and ulaw
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/ulaw.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_ulaw.h"
43
44/*! \brief convert and store samples in outbuf */
45static int ulawtolin_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 /* convert and copy in outbuf */
55 while (i--)
56 *dst++ = AST_MULAW(*src++);
57
58 return 0;
59}
60
61/*! \brief convert and store samples in outbuf */
62static int lintoulaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
63{
64 int i = f->samples;
65 char *dst = pvt->outbuf.c + pvt->samples;
66 int16_t *src = f->data.ptr;
67
68 pvt->samples += i;
69 pvt->datalen += i; /* 1 byte/sample */
70
71 while (i--)
72 *dst++ = AST_LIN2MU(*src++);
73
74 return 0;
75}
76
77/*!
78 * \brief The complete translator for ulawToLin.
79 */
80
81static struct ast_translator ulawtolin = {
82 .name = "ulawtolin",
83 .src_codec = {
84 .name = "ulaw",
86 .sample_rate = 8000,
87 },
88 .dst_codec = {
89 .name = "slin",
91 .sample_rate = 8000,
92 },
93 .format = "slin",
94 .framein = ulawtolin_framein,
95 .sample = ulaw_sample,
96 .buffer_samples = BUFFER_SAMPLES,
97 .buf_size = BUFFER_SAMPLES * 2,
98};
99
100/*!
101 * \brief The complete translator for LinToulaw.
102 */
103
104static struct ast_translator lintoulaw = {
105 .name = "lintoulaw",
106 .src_codec = {
107 .name = "slin",
108 .type = AST_MEDIA_TYPE_AUDIO,
109 .sample_rate = 8000,
110 },
111 .dst_codec = {
112 .name = "ulaw",
113 .type = AST_MEDIA_TYPE_AUDIO,
114 .sample_rate = 8000,
115 },
116 .format = "ulaw",
117 .framein = lintoulaw_framein,
118 .sample = slin8_sample,
119 .buf_size = BUFFER_SAMPLES,
120 .buffer_samples = BUFFER_SAMPLES,
121};
122
123static int unload_module(void)
124{
125 int res;
126
129
130 return res;
131}
132
133static int load_module(void)
134{
135 int res;
136
139
140 if (res) {
143 }
144
146}
147
149 .support_level = AST_MODULE_SUPPORT_CORE,
150 .load = load_module,
151 .unload = unload_module,
Asterisk main include file. File version handling, generic pbx functions.
@ AST_MEDIA_TYPE_AUDIO
Definition: codec.h:32
#define BUFFER_SAMPLES
Definition: codec_ulaw.c:38
static struct ast_translator lintoulaw
The complete translator for LinToulaw.
Definition: codec_ulaw.c:104
static int ulawtolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
convert and store samples in outbuf
Definition: codec_ulaw.c:45
static struct ast_translator ulawtolin
The complete translator for ulawToLin.
Definition: codec_ulaw.c:81
static int load_module(void)
Definition: codec_ulaw.c:133
static int unload_module(void)
Definition: codec_ulaw.c:123
static int lintoulaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
convert and store samples in outbuf
Definition: codec_ulaw.c:62
short int16_t
Definition: db.h:59
8-bit data
static struct ast_frame * ulaw_sample(void)
Definition: ex_ulaw.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
u-Law to Signed linear conversion
#define AST_MULAW(a)
Definition: ulaw.h:85
#define AST_LIN2MU(a)
Definition: ulaw.h:49
Utility functions.