codec_alaw.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2005, Digium, Inc.
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  *
00021  * \brief codec_alaw.c - translate between signed linear and alaw
00022  * 
00023  * \ingroup codecs
00024  */
00025 
00026 /*** MODULEINFO
00027    <support_level>core</support_level>
00028  ***/
00029 
00030 #include "asterisk.h"
00031 
00032 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 419592 $")
00033 
00034 #include "asterisk/module.h"
00035 #include "asterisk/config.h"
00036 #include "asterisk/translate.h"
00037 #include "asterisk/alaw.h"
00038 #include "asterisk/utils.h"
00039 
00040 #define BUFFER_SAMPLES   8096 /* size for the translation buffers */
00041 
00042 /* Sample frame data */
00043 #include "asterisk/slin.h"
00044 #include "ex_alaw.h"
00045 
00046 /*! \brief decode frame into lin and fill output buffer. */
00047 static int alawtolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
00048 {
00049    int i = f->samples;
00050    unsigned char *src = f->data.ptr;
00051    int16_t *dst = pvt->outbuf.i16 + pvt->samples;
00052 
00053    pvt->samples += i;
00054    pvt->datalen += i * 2;  /* 2 bytes/sample */
00055    
00056    while (i--)
00057       *dst++ = AST_ALAW(*src++);
00058 
00059    return 0;
00060 }
00061 
00062 /*! \brief convert and store input samples in output buffer */
00063 static int lintoalaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
00064 {
00065    int i = f->samples;
00066    char *dst = pvt->outbuf.c + pvt->samples;
00067    int16_t *src = f->data.ptr;
00068 
00069    pvt->samples += i;
00070    pvt->datalen += i;   /* 1 byte/sample */
00071 
00072    while (i--) 
00073       *dst++ = AST_LIN2A(*src++);
00074 
00075    return 0;
00076 }
00077 
00078 static struct ast_translator alawtolin = {
00079    .name = "alawtolin",
00080    .src_codec = {
00081       .name = "alaw",
00082       .type = AST_MEDIA_TYPE_AUDIO,
00083       .sample_rate = 8000,
00084    },
00085    .dst_codec = {
00086       .name = "slin",
00087       .type = AST_MEDIA_TYPE_AUDIO,
00088       .sample_rate = 8000,
00089    },
00090    .format = "slin",
00091    .framein = alawtolin_framein,
00092    .sample = alaw_sample,
00093    .buffer_samples = BUFFER_SAMPLES,
00094    .buf_size = BUFFER_SAMPLES * 2,
00095 };
00096 
00097 static struct ast_translator lintoalaw = {
00098    .name = "lintoalaw",
00099    .src_codec = {
00100       .name = "slin",
00101       .type = AST_MEDIA_TYPE_AUDIO,
00102       .sample_rate = 8000,
00103    },
00104    .dst_codec = {
00105       .name = "alaw",
00106       .type = AST_MEDIA_TYPE_AUDIO,
00107       .sample_rate = 8000,
00108    },
00109    .format = "alaw",
00110    .framein = lintoalaw_framein,
00111    .sample = slin8_sample,
00112    .buffer_samples = BUFFER_SAMPLES,
00113    .buf_size = BUFFER_SAMPLES,
00114 };
00115 
00116 static int unload_module(void)
00117 {
00118    int res;
00119 
00120    res = ast_unregister_translator(&lintoalaw);
00121    res |= ast_unregister_translator(&alawtolin);
00122 
00123    return res;
00124 }
00125 
00126 static int load_module(void)
00127 {
00128    int res;
00129 
00130    res = ast_register_translator(&alawtolin);
00131    res |= ast_register_translator(&lintoalaw);
00132 
00133    if (res) {
00134       unload_module();
00135       return AST_MODULE_LOAD_FAILURE;
00136    }
00137 
00138    return AST_MODULE_LOAD_SUCCESS;
00139 }
00140 
00141 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "A-law Coder/Decoder",
00142       .support_level = AST_MODULE_SUPPORT_CORE,
00143       .load = load_module,
00144       .unload = unload_module,
00145           );

Generated on Thu Apr 16 06:27:30 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6