Skip to content
Snippets Groups Projects
codec_alaw.c 3.05 KiB
Newer Older
  • Learn to ignore specific revisions
  • /*
     * Asterisk -- An open source telephony toolkit.
     *
     * Copyright (C) 1999 - 2005, Digium, Inc.
    
    Mark Spencer's avatar
    Mark Spencer committed
     *
    
     * Mark Spencer <markster@digium.com>
    
    Mark Spencer's avatar
    Mark Spencer committed
     *
    
     * See http://www.asterisk.org for more information about
     * the Asterisk project. Please do not directly contact
     * any of the maintainers of this project for assistance;
     * the project provides a web site, mailing lists and IRC
     * channels for your use.
    
    Mark Spencer's avatar
    Mark Spencer committed
     *
     * This program is free software, distributed under the terms of
    
     * the GNU General Public License Version 2. See the LICENSE file
     * at the top of the source tree.
     */
    
    
     * \brief codec_alaw.c - translate between signed linear and alaw
    
    Russell Bryant's avatar
    Russell Bryant committed
     * \ingroup codecs
    
    /*** MODULEINFO
    	<support_level>core</support_level>
     ***/
    
    
    #include "asterisk/module.h"
    #include "asterisk/config.h"
    #include "asterisk/translate.h"
    #include "asterisk/alaw.h"
    
    #include "asterisk/utils.h"
    
    #define BUFFER_SAMPLES   8096	/* size for the translation buffers */
    
    /* Sample frame data */
    #include "asterisk/slin.h"
    #include "ex_alaw.h"
    
    /*! \brief decode frame into lin and fill output buffer. */
    static int alawtolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
    
    Mark Spencer's avatar
    Mark Spencer committed
    {
    
    	int16_t *dst = pvt->outbuf.i16 + pvt->samples;
    
    
    	pvt->samples += i;
    	pvt->datalen += i * 2;	/* 2 bytes/sample */
    
    	while (i--)
    		*dst++ = AST_ALAW(*src++);
    
    /*! \brief convert and store input samples in output buffer */
    static int lintoalaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
    
    Mark Spencer's avatar
    Mark Spencer committed
    {
    
    	char *dst = pvt->outbuf.c + pvt->samples;
    
    
    	pvt->samples += i;
    	pvt->datalen += i;	/* 1 byte/sample */
    
    Mark Spencer's avatar
    Mark Spencer committed
    }
    
    static struct ast_translator alawtolin = {
    
    	.src_codec = {
    		.name = "alaw",
    		.type = AST_MEDIA_TYPE_AUDIO,
    		.sample_rate = 8000,
    	},
    	.dst_codec = {
    		.name = "slin",
    		.type = AST_MEDIA_TYPE_AUDIO,
    		.sample_rate = 8000,
    	},
    	.format = "slin",
    
    	.buffer_samples = BUFFER_SAMPLES,
    	.buf_size = BUFFER_SAMPLES * 2,
    
    Mark Spencer's avatar
    Mark Spencer committed
    };
    
    static struct ast_translator lintoalaw = {
    
    	.name = "lintoalaw",
    	.src_codec = {
    		.name = "slin",
    		.type = AST_MEDIA_TYPE_AUDIO,
    		.sample_rate = 8000,
    	},
    	.dst_codec = {
    		.name = "alaw",
    		.type = AST_MEDIA_TYPE_AUDIO,
    		.sample_rate = 8000,
    	},
    	.format = "alaw",
    
    	.buffer_samples = BUFFER_SAMPLES,
    	.buf_size = BUFFER_SAMPLES,
    
    static int unload_module(void)
    
    Mark Spencer's avatar
    Mark Spencer committed
    {
    
    	res = ast_unregister_translator(&lintoalaw);
    
    	res |= ast_unregister_translator(&alawtolin);
    
    static int load_module(void)
    
    Mark Spencer's avatar
    Mark Spencer committed
    {
    
    
    	res = ast_register_translator(&alawtolin);
    
    	res |= ast_register_translator(&lintoalaw);
    
    	if (res) {
    		unload_module();
    
    		return AST_MODULE_LOAD_DECLINE;
    
    	return AST_MODULE_LOAD_SUCCESS;
    
    Mark Spencer's avatar
    Mark Spencer committed
    }
    
    AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "A-law Coder/Decoder",
    
    	.support_level = AST_MODULE_SUPPORT_CORE,
    	.load = load_module,
    	.unload = unload_module,
    );