Author: sayer Date: 2008-07-02 22:06:44 +0200 (Wed, 02 Jul 2008) New Revision: 1033
Added: trunk/core/plug-in/g722/ trunk/core/plug-in/g722/Makefile trunk/core/plug-in/g722/Readme.g722codec trunk/core/plug-in/g722/g722.c Modified: trunk/core/amci/codecs.h trunk/core/plug-in/Makefile Log: g.722 codec from spandsp in 8khz compatibility mode Modified: trunk/core/amci/codecs.h =================================================================== --- trunk/core/amci/codecs.h 2008-06-30 07:04:27 UTC (rev 1032) +++ trunk/core/amci/codecs.h 2008-07-02 20:06:44 UTC (rev 1033) @@ -53,4 +53,6 @@ #define CODEC_G726_40 11 #define CODEC_L16 12 + +#define CODEC_G722_NB 13 #endif Modified: trunk/core/plug-in/Makefile =================================================================== --- trunk/core/plug-in/Makefile 2008-06-30 07:04:27 UTC (rev 1032) +++ trunk/core/plug-in/Makefile 2008-07-02 20:06:44 UTC (rev 1033) @@ -1,6 +1,6 @@ include ../../Makefile.defs -exclude_modules ?= +exclude_modules ?= g722 #echo modules = $(filter-out $(subst ;, ,$(exclude_modules)) \ Added: trunk/core/plug-in/g722/Makefile =================================================================== --- trunk/core/plug-in/g722/Makefile 2008-06-30 07:04:27 UTC (rev 1032) +++ trunk/core/plug-in/g722/Makefile 2008-07-02 20:06:44 UTC (rev 1033) @@ -0,0 +1,14 @@ +plug_in_name = g722 + +SPANDSP_INC= +#/usr/include/ +SPANDSP_LIB = -lspandsp + +module_ldflags = $(SPEEX_LIB) +module_cflags = -ansi # -DNOFPU + +ifdef NOFPU + module_cflags += -DNOFPU +endif + +include ../Makefile.audio_module Added: trunk/core/plug-in/g722/Readme.g722codec =================================================================== --- trunk/core/plug-in/g722/Readme.g722codec 2008-06-30 07:04:27 UTC (rev 1032) +++ trunk/core/plug-in/g722/Readme.g722codec 2008-07-02 20:06:44 UTC (rev 1033) @@ -0,0 +1,10 @@ +This is a wrapper around the g722 codec from the spandsp library. + +G.722 is an ADPCM wideband (16khz) codec. Here the NB compatibility +mode is used - it is decoded in and encoded from 8khz. + +See +http://www.soft-switch.org/spandsp-modules.html + and +http://www.soft-switch.org/spandsp-doc/g722_page.html +for details about spandsp. \ No newline at end of file Added: trunk/core/plug-in/g722/g722.c =================================================================== --- trunk/core/plug-in/g722/g722.c 2008-06-30 07:04:27 UTC (rev 1032) +++ trunk/core/plug-in/g722/g722.c 2008-07-02 20:06:44 UTC (rev 1033) @@ -0,0 +1,148 @@ +/* + This is a simple interface to the spandsp's g722 implementation. + This uses the 8khz compatibility mode - audio is encodec and decoded + in 8khz. + + Copyright (C) 2008 iptego GmbH + + This code is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation. + + This code is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include <string.h> +#include <stdlib.h> + +#include "amci.h" +#include "codecs.h" +#include <math.h> +typedef unsigned char uint8_t; +typedef signed short int16_t; + +#include "spandsp/g722.h" +#include "../../log.h" + + +int Pcm16_2_G722NB( unsigned char* out_buf, unsigned char* in_buf, unsigned int size, + unsigned int channels, unsigned int rate, long h_codec ); +int G722NB_2_Pcm16( unsigned char* out_buf, unsigned char* in_buf, unsigned int size, + unsigned int channels, unsigned int rate, long h_codec ); + +long G722NB_create(const char* format_parameters, amci_codec_fmt_info_t* format_description); +void G722NB_destroy(long handle); + +static unsigned int G722NB_bytes2samples(long, unsigned int); +static unsigned int G722NB_samples2bytes(long, unsigned int); + +BEGIN_EXPORTS("g722", AMCI_NO_MODULEINIT, AMCI_NO_MODULEDESTROY) + +BEGIN_CODECS +CODEC(CODEC_G722_NB, Pcm16_2_G722NB, G722NB_2_Pcm16, AMCI_NO_CODEC_PLC, + G722NB_create, G722NB_destroy, + G722NB_bytes2samples, G722NB_samples2bytes) +END_CODECS + +BEGIN_PAYLOADS +PAYLOAD(9, "g722", 8000, 1, CODEC_G722_NB, AMCI_PT_AUDIO_FRAME) +END_PAYLOADS + +BEGIN_FILE_FORMATS +END_FILE_FORMATS + +END_EXPORTS + +typedef struct { + g722_encode_state_t encode_state; + g722_decode_state_t decode_state; +} G722State; + + +long G722NB_create(const char* format_parameters, amci_codec_fmt_info_t* format_description) +{ + G722State* gs; + + gs = (G722State*) calloc(1, sizeof(G722State)); + if (!gs) { + ERROR("error allocating memory for G722 codec state\n"); + return 0; + } + + if (!g722_encode_init(&gs->encode_state, + 64000, G722_SAMPLE_RATE_8000)) { + ERROR("error initializing G722 encoder\n"); + free(gs); + return 0; + } + + if (!g722_decode_init(&gs->decode_state, + 64000, G722_SAMPLE_RATE_8000)) { + ERROR("error initializing G722 decoder\n"); + free(gs); + return 0; + } + + return (long)gs; +} + +void G722NB_destroy(long handle) +{ +} + +static unsigned int G722NB_bytes2samples(long h_codec, unsigned int num_bytes) { + return num_bytes; +} + +static unsigned int G722NB_samples2bytes(long h_codec, unsigned int num_samples) { + return num_samples; +} + + +int Pcm16_2_G722NB( unsigned char* out_buf, unsigned char* in_buf, unsigned int size, + unsigned int channels, unsigned int rate, long h_codec ) +{ + G722State* gs; + + if (channels!=1) { + ERROR("only supports 1 channel\n"); + return 0; + } + + if (rate != 8000) { + ERROR("only supports NB (8khz)\n"); + return 0; + } + + gs = (G722State*) h_codec; + + return g722_encode(&gs->encode_state, out_buf, (signed short*)in_buf, size >> 1); +} + +int G722NB_2_Pcm16( unsigned char* out_buf, unsigned char* in_buf, unsigned int size, + unsigned int channels, unsigned int rate, long h_codec ) +{ + + G722State* gs; + + if (channels!=1) { + ERROR("only supports 1 channel\n"); + return 0; + } + + if (rate != 8000) { + ERROR("only supports NB (8khz)\n"); + return 0; + } + + gs = (G722State*) h_codec; + + return g722_decode(&gs->decode_state, (signed short*)out_buf, in_buf, size) << 1; +} _______________________________________________ Semsdev mailing list [email protected] http://lists.iptel.org/mailman/listinfo/semsdev
