diff -u -r -N ./Makefile /tmp/codec_g729/Makefile --- ./Makefile 2004-09-01 02:52:08.000000000 +0100 +++ /tmp/codec_g729/Makefile 2004-09-18 03:35:06.000000000 +0100 @@ -13,15 +13,17 @@ IPPLIBS=-L$(IPPROOT)/sharedlib -lippsc -lippsr -lipps -lippcore -L$(IPPROOT)/sharedlib/linux32 -lguide # Compiler Specifics -CCOPTS=-c -O2 +CCOPTS=-c -O2 CCDEFS=-D__unix__ -Dlinux -Dlinux32 -DNDEBUG -DLINUX32 -DNO_SCRATCH_MEMORY_USED CCINCLS=-I./include -I./vm/include $(IPPINCLS) LNKOUT=-o LNKOPTS= -LNKLIBS=$(IPPLIBS) -lpthread -lm +LNKLIBS=$(IPPLIBS) -lpthread -lm -build: prepare_directory build_encoder build_decoder; @echo "Done" +SOLINKOPTS=-shared -Xlinker -x + +build: prepare_directory build_codec ; @echo "Done" ##### api object ##### CPPSRC_API=$(wildcard ./api/*$(CPPSFX)) @@ -30,9 +32,19 @@ CPPSRC_VM=$(wildcard ./vm/src/*$(CPPSFX)) OBJECT_VM=$(patsubst %$(CPPSFX), %$(OBJSFX), $(CPPSRC_VM)) +############ Asterisk Codec ############ +OBJECT_CODEC=./bin/codec_g729.so +CPPSRC_CODEC=$(wildcard ./samples/util_e$(CPPSFX) ./samples/util_d$(CPPSFX) ./samples/codec_g729.c ) +OBJSRC_CODEC=$(patsubst %$(CPPSFX), %$(OBJSFX), $(CPPSRC_CODEC)) + +build_codec: $(OBJECT_CODEC) ; @echo "done Asterisk codec" + +$(OBJECT_CODEC): $(OBJSRC_CODEC) $(OBJECT_API) + $(CC) $(SOLINKOPTS) -o $@ $^ $(LNKLIBS) + ##### link encoder example programs ##### OBJECT_ENCODER=./bin/g729fpencoder$(EXESFX) -CPPSRC_ENCODER=$(wildcard ./samples/encoder$(CPPSFX) ./samples/util_e$(CPPSFX) ) +CPPSRC_ENCODER=$(wildcard ./samples/encoder$(CPPSFX) ./samples/util_e$(CPPSFX) ./samples/my_enc.c) OBJSRC_ENCODER=$(patsubst %$(CPPSFX), %$(OBJSFX), $(CPPSRC_ENCODER)) build_encoder: $(OBJECT_ENCODER) ; @echo "done encoder" @@ -42,7 +54,7 @@ ##### link decoder example programs ##### OBJECT_DECODER=./bin/g729fpdecoder$(EXESFX) -CPPSRC_DECODER=$(wildcard ./samples/decoder$(CPPSFX) ./samples/util_d$(CPPSFX) ) +CPPSRC_DECODER=$(wildcard ./samples/decoder$(CPPSFX) ./samples/util_d$(CPPSFX) ./samples/my_dec.c) OBJSRC_DECODER=$(patsubst %$(CPPSFX), %$(OBJSFX), $(CPPSRC_DECODER)) build_decoder: $(OBJECT_DECODER) ; @echo "done decoder" @@ -51,7 +63,7 @@ $(CC) -o$@ $(LNKOPTS) $^ $(LNKLIBS) ##### compile encoder & decoder objects all together ##### -OBJECTS=$(OBJECT_API) $(OBJECT_VM)$(OBJSRC_ENCODER) $(OBJSRC_DECODER) +OBJECTS=$(OBJECT_API) $(OBJECT_VM) $(OBJSRC_CODEC) $(OBJECTS): %$(OBJSFX): %$(CPPSFX) $(CC) $(CCINCLS) $(CCDEFS) $(CCOPTS) -o$@ $< diff -u -r -N ./itu/bitstrea.txt /tmp/codec_g729/itu/bitstrea.txt --- ./itu/bitstrea.txt 1970-01-01 01:00:00.000000000 +0100 +++ /tmp/codec_g729/itu/bitstrea.txt 2004-09-17 19:51:06.000000000 +0100 @@ -0,0 +1,360 @@ +/* + ITU-T G.729 Annex I - Reference C code for fixed point + implementation of G.729 Annex I + Version 1.1 of October 1999 +*/ + +TITLE +----- + +This file describes the G.729 Annex I bitstream format. + +BITSTREAM FORMAT +---------------- + +For rate 6.4 kbit/s, the bitstreamfile contains sixty-six 16-bit words +for each 10 ms speech frame. + +There, the first word is the syncword SYNC_WORD and the second word is +the framesize contains the value 64 (66 less 2). + +The next 64 words contain the following parameters: + +001 LPC1- MA predictor switch +002 LPC1- 1st codebook 7 bit +003 LPC1- +004 LPC1- +005 LPC1- +006 LPC1- +007 LPC1- +008 LPC1- +009 LPC2- 2nd codebook low 5 bit +010 LPC2- +011 LPC2- +012 LPC2- +013 LPC2- +014 LPC2- 2nd codebook high 5 bit +015 LPC2- +016 LPC2- +017 LPC2- +018 LPC2- +019 M_1 pitch period 8 bit +020 M_1 +021 M_1 +022 M_1 +023 M_1 +024 M_1 +025 M_1 +026 M_1 +027 CB1_0 codebook: one pulse in track 1 4 bits +028 CB1_0 +029 CB1_0 +030 CB1_0 +031 CB1_1 codebook: two pulses in track 2 5 bit +032 CB1_1 +033 CB1_1 +034 CB1_1 +035 CB1_1 +036 CB1_S codebook: sign 2 bits +037 CB1_S +038 G_1 pitch and codebook gains 6 bits +039 G_1 +040 G_1 +041 G_1 +042 G_1 +043 G_1 +044 M_2 pitch period (relative) 5 bit +045 M_2 +046 M_2 +047 M_2 +048 CB2_0 codebook: one pulse in track 1 4 bits +049 CB2_0 +050 CB2_0 +051 CB2_0 +052 CB2_1 codebook: two pulses in track 2 5 bit +053 CB2_1 +054 CB2_1 +055 CB2_1 +056 CB2_1 +057 CB2_S codebook: sign 2 bits +058 CB2_S +059 G_2 pitch and codebook gains 6 bits +060 G_2 +061 G_2 +062 G_2 +063 G_2 +064 G_2 + +For the rate 11.8 kbit/s, the bitstreamfile contains one-hundred and twenty 16-bit words for each 10 ms speech frame. + +The first word is the syncword SYNC_WORD and the second word is the +framesize contains the value 118 (120 less 2). + +The next 118 words contain the following parameters: +001 mode - Backward /forward switch, + = BIT_0 for forward mode + = BIT_1 for backward mode +002 parity bit for mode + +In forward mode, the next 116 words are: +003 LPC1- MA predictor switch +004 LPC1- 1st codebook 7 bit +005 LPC1- +006 LPC1- +007 LPC1- +008 LPC1- +009 LPC1- +010 LPC1- +011 LPC2- 2nd codebook low 5 bit +012 LPC2- +013 LPC2- +014 LPC2- +015 LPC2- +016 LPC2- 2nd codebook high 5 bit +017 LPC2- +018 LPC2- +019 LPC2- +020 LPC2- +021 M_1 pitch period 8 bit +022 M_1 +023 M_1 +024 M_1 +025 M_1 +026 M_1 +027 M_1 +028 M_1 +029 parity check on 1st period 1 bit +030 CB1_1_0 codebook: two pulses in track 0 7 bits +031 CB1_1_0 +032 CB1_1_0 +033 CB1_1_0 +034 CB1_1_0 +035 CB1_1_0 +036 CB1_1_0 +037 CB1_1_1 codebook: two pulses in track 1 7 bit +038 CB1_1_1 +039 CB1_1_1 +040 CB1_1_1 +041 CB1_1_1 +042 CB1_1_1 +043 CB1_1_1 +044 CB1_1_2 codebook: two pulses in track 2 7 bit +045 CB1_1_2 +046 CB1_1_2 +047 CB1_1_2 +048 CB1_1_2 +049 CB1_1_2 +050 CB1_1_2 +051 CB1_1_3 codebook: two pulses in track 3 7 bits +052 CB1_1_3 +053 CB1_1_3 +054 CB1_1_3 +055 CB1_1_3 +056 CB1_1_3 +057 CB1_1_3 +058 CB1_1_4 codebook: two pulses in track 4 7 bits +059 CB1_1_4 +060 CB1_1_4 +061 CB1_1_4 +062 CB1_1_4 +063 CB1_1_4 +064 CB1_1_4 +065 G_1 pitch and codebook gains 3 bit stage 1 +066 G_1 +067 G_1 +068 G_1 pitch and codebook gains 4 bit stage 2 +069 G_1 +070 G_1 +071 G_1 +072 M_2 pitch period (relative) 5 bit +073 M_2 +074 M_2 +075 M_2 +076 M_2 +077 CB1_2_0 codebook: two pulses in track 0 7 bits +078 CB1_2_0 +079 CB1_2_0 +080 CB1_2_0 +081 CB1_2_0 +082 CB1_2_0 +083 CB1_2_0 +084 CB1_2_1 codebook: two pulses in track 1 7 bit +085 CB1_2_1 +086 CB1_2_1 +087 CB1_2_1 +088 CB1_2_1 +089 CB1_2_1 +090 CB1_2_1 +091 CB1_2_2 codebook: two pulses in track 2 7 bit +092 CB1_2_2 +093 CB1_2_2 +094 CB1_2_2 +095 CB1_2_2 +096 CB1_2_2 +097 CB1_2_2 +098 CB1_2_3 codebook: two pulses in track 3 7 bits +099 CB1_2_3 +100 CB1_2_3 +101 CB1_2_3 +102 CB1_2_3 +103 CB1_2_3 +104 CB1_2_3 +105 CB1_2_4 codebook: two pulses in track 4 7 bits +106 CB1_2_4 +107 CB1_2_4 +108 CB1_2_4 +109 CB1_2_4 +110 CB1_2_4 +111 CB1_2_4 +112 G_2 pitch and codebook gains 3 bit stage 1 +113 G_2 +114 G_2 +115 G_2 pitch and codebook gains 4 bit stage 2 +116 G_2 +117 G_2 +118 G_2 + +Alternatively, when in backward mode, the next 116 words are: +003 M_1 pitch period 8 bit +004 M_1 +005 M_1 +006 M_1 +007 M_1 +008 M_1 +009 M_1 +010 M_1 +011 parity check on 1st period 1 bit +012 CB2_1_0 codebook: track index + pulses 1, 6, and 11 13 bits +013 CB2_1_0 +014 CB2_1_0 +015 CB2_1_0 +016 CB2_1_0 +017 CB2_1_0 +018 CB2_1_0 +019 CB2_1_0 +020 CB2_1_0 +021 CB2_1_0 +022 CB2_1_0 +023 CB2_1_0 +024 CB2_1_0 +025 CB2_1_1 codebook: pulses 2, 7, and 12 10 bit +026 CB2_1_1 +027 CB2_1_1 +028 CB2_1_1 +029 CB2_1_1 +030 CB2_1_1 +031 CB2_1_1 +032 CB2_1_1 +033 CB2_1_1 +034 CB2_1_1 +035 CB2_1_2 codebook: pulses 3 and 8 7 bit +036 CB2_1_2 +037 CB2_1_2 +038 CB2_1_2 +039 CB2_1_2 +040 CB2_1_2 +041 CB2_1_2 +042 CB2_1_3 codebook: pulses 4 and 9 7 bits +043 CB2_1_3 +044 CB2_1_3 +045 CB2_1_3 +046 CB2_1_3 +047 CB2_1_3 +048 CB2_1_3 +049 CB2_1_4 codebook: pulses 5 and 10 7 bits +050 CB2_1_4 +051 CB2_1_4 +052 CB2_1_4 +053 CB2_1_4 +054 CB2_1_4 +055 CB2_1_4 +056 G_1 pitch and codebook gains 3 bit stage 1 +057 G_1 +058 G_1 +059 G_1 pitch and codebook gains 4 bit stage 2 +060 G_1 +061 G_1 +062 G_1 +063 M_2 pitch period (relative) 5 bit +064 M_2 +065 M_2 +066 M_2 +067 M_2 +068 CB2_2_0 codebook: track index + pulses 1, 6, and 11 13 bits +069 CB2_2_0 +070 CB2_2_0 +071 CB2_2_0 +072 CB2_2_0 +073 CB2_2_0 +074 CB2_2_0 +075 CB2_2_0 +076 CB2_2_0 +077 CB2_2_0 +078 CB2_2_0 +079 CB2_2_0 +080 CB2_2_0 +081 CB2_2_1 codebook: pulses 2, 7, and 12 10 bit +082 CB2_2_1 +083 CB2_2_1 +084 CB2_2_1 +085 CB2_2_1 +086 CB2_2_1 +087 CB2_2_1 +088 CB2_2_1 +089 CB2_2_1 +090 CB2_2_1 +091 CB2_2_2 codebook: pulses 3 and 8 7 bit +092 CB2_2_2 +093 CB2_2_2 +094 CB2_2_2 +095 CB2_2_2 +096 CB2_2_2 +097 CB2_2_2 +098 CB2_2_3 codebook: pulses 4 and 9 7 bits +099 CB2_2_3 +100 CB2_2_3 +101 CB2_2_3 +102 CB2_2_3 +103 CB2_2_3 +104 CB2_2_3 +105 CB2_2_4 codebook: pulses 5 and 10 7 bits +106 CB2_2_4 +107 CB2_2_4 +108 CB2_2_4 +109 CB2_2_4 +110 CB2_2_4 +111 CB2_2_4 +112 G_2 pitch and codebook gains 3 bit stage 1 +113 G_2 +114 G_2 +115 G_2 pitch and codebook gains 4 bit stage 2 +116 G_2 +117 G_2 +118 G_2 + +For SID frame, the bitstreamfile contains 17 (or 18) 16-bit words for +each 10 ms speech frame. + +The first word is the syncword SYNC_WORD and the second word is the +framesize which will contain either the value 15 or the value 16 +[15=17-2;16=18-2]. + +The next 15 (or 16) words contain the following parameters: +001 LPC1- SID MA predictor switch +002 LPC1- SID Lsp : 1st stage 5 bit +003 LPC1- +004 LPC1- +005 LPC1- +006 LPC1- +007 LPC2- SID Lsp : 2nd stage 4 bit +008 LPC2- +009 LPC2- +010 LPC2- +011 GAIN- SID gain : 5 bit +012 GAIN- +013 GAIN- +014 GAIN- +015 GAIN- +(016 BIT_0) + +-- [END] -- Binary files ./itu/g0729e.doc and /tmp/codec_g729/itu/g0729e.doc differ Binary files ./itu/g0729nae.doc and /tmp/codec_g729/itu/g0729nae.doc differ Binary files ./itu/g0729nbe.doc and /tmp/codec_g729/itu/g0729nbe.doc differ diff -u -r -N ./itu/readme.txt /tmp/codec_g729/itu/readme.txt --- ./itu/readme.txt 1970-01-01 01:00:00.000000000 +0100 +++ /tmp/codec_g729/itu/readme.txt 2004-09-17 19:51:55.000000000 +0100 @@ -0,0 +1,165 @@ +1 - TITLE +--------- +/* + ITU-T G.729 Annex I - Reference C code for fixed point + implementation of G.729 CS-ACELP at 6.4 kbit/s 8 kbit/s + and 11.8 kb/s with DTX functionality + (integration of Annexes B, D and E) + Version 1.1 of october 1999 +*/ + +2 - VERSION +----------- +This is version 1.1 +ITU-T G.729/Annex I was approved on 02/2000 + +3 - COPYRIGHT AND INTELLECTUAL PROPERTY +--------------------------------------- + +This software package is provided as part of ITU-T Recommendation G.729 Annex I. + + ITU-T G.729 Annex I fixed point ANSI C source code + Copyright (C) 1999, AT&T, France Telecom, NTT, University of + Sherbrooke, Conexant, Ericsson. All rights reserved. + + Original Copyright (c) 1995, AT&T, France Telecom, NTT, + Universite de Sherbrooke. + All rights reserved. + + + Copyright (c) 1996, AT&T, France Telecom, NTT, Rockwell International, + Universite de Sherbrooke. + All rights reserved. + + + Copyright (c) 1997, Ericsson, NTT. + All rights reserved. + + + Copyright (c) 1997, France Telecom, Universite de Sherbrooke. + All rights reserved. + +The copy of the source C code, version 1.1, is given under Copyright of the +authors, only for the purpose of establishing the specification of a codec. + +All rights are reserved. Any other use of the material is prohibited. + +4 - SUPPORT +------------ +For distribution of update software, please contact: + + Sales Department + ITU + Place des Nations + CH-1211 Geneve 20 + SWITZERLAND + email: sales@itu.int + +For reporting problems, please contact TSB helpdesk service at: + + TSB Helpdesk service + ITU + Place des Nations + CH-1211 Geneve 20 + SWITZERLAND + fax: +41 22 730 5853 + email: tsbedh@itu.int + +5 - TECHNICAL DETAILS +--------------------- + +5.1 - COMPILATION +----------------- +Edit the file typedef.h to comply to your target platform + +For UNIX systems the following makefiles are provided + + coderi.mak + decoderi.mak + +Edit the makefiles coderi.mak and decoderi.mak to set the proper options +for your system. +The command to compile and link all code on a UNIX system is + + make -f coderi.mak + make -f decoderi.mak + +For other platforms, the *.mak files can be used to work out the +compilation procedures. + +This code has been successfully compiled and run on the following +platforms: + +Platform Operating System Compiler +----------------------------------------------------------------------------- +DEC ALPHA OSF/1 DEC OSF/1 cc +PC DOS 6.21 Borland 3.1 + Watcom 9.6 + Microsoft 8 +PC Window95 MS Visual C++ 5.0 + CYGWIN32 gcc egcs-2.91.57 +PC WindowNT4 MS Visual C++ 6.0 +HP-UX B.10.01 gcc +SGI-IRIX IRIX 5.3 SGI Rel 5.3 cc + +5.2 - DESCRIPTION +----------------- +This package includes the files needed to build the fixed point +version of G.729 annex I codec with lower and higher bit rate +extensions at 6.4 kbit/s and 11.8 kbit/s and with dtx functionality + +It also includes: +- the PC executable (coderi.exe and decoderi.exe): +- a batch file (test.bat) and testvectors to validate the correct + execution of the G.729 annex I (ANSI-C software version 1.1). The + binary reference files are in PC format (for more details see + readmetv.txt). + +5.3 - USAGE +----------- +coderi inputfile bitstreamfile dtx_option rate_option +decoderi bitstreamfile outputfile + +The following files are used or generated + inputfile 8 kHz sampled data file 16 bit PCM (binary) + outputfile 8 kHz sampled data file 16 bit PCM (binary) + bitstreamfile binary file containing bitstream + +The following parameters are used for the encoder + dtx_option = 0 dtx disabled (default) + = 1 dtx enabled + rate_option = 0 : lower rate (6.4 kb/s) + = 1 : G729 (8.0 kb/s) + = 2 : higher rate (11.8 kb/s) + = file_rate_name : a binary file of 16 bit + word containing either 0, 1 or 2 to + select the rate on a frame by frame + basis the default is 1 (8 kb/s) + + +5.4 - BITSTREAM FORMAT +---------------------- +The bitstream file contains for each 10 ms speech frame, For rate 8 +kbit/s, 82 16-bit words or for rate 6.4 kbit/s, 66 16-bit words, or +for rate 11.8 kbit/s, 120 16-bit words, or for SID frame, 17(or 18) +16-bit words, or for not transmitted frame, 2 16-bit words. + +The first word is the synchronization word SYNC_WORD. The second word +contains the value serial_size which is 80 for rate 8 kbit/s, 64 for +rate 6.4 kbit/s, 118 for rate 11.8 kbit/s, 15( or 16) for SID frame, 0 +for Non-transmitted frame. + +For the rate 8 kbit/s, the next 80 words contain the parameters as +described in G729 recommendation text. For the other rates, the next +"serial_size" words are described in bitstrea.txt. + +Bitstream information - all parameters start with MSB. The bits are +defined as follows: + +#define SYNC_WORD (short)0x6b21 +#define BIT_0 (short)0x007f /* definition of zero-bit in bit-stream */ +#define BIT_1 (short)0x0081 /* definition of one-bit in bit-stream */ + +A bad frame is indicated by setting all "serial_size" bits to zero. +Except, for not transmitted frame, where the synchronization word +SYNC_WORD is set to (short)0x6B20. + +--[END] + diff -u -r -N ./samples/codec_g729.c /tmp/codec_g729/samples/codec_g729.c --- ./samples/codec_g729.c 1970-01-01 01:00:00.000000000 +0100 +++ /tmp/codec_g729/samples/codec_g729.c 2004-09-24 14:13:07.000000000 +0100 @@ -0,0 +1,349 @@ +/* + * G729 codec for Asterisk + * + * Based on sample applications from Intel Performance Primitives (IPP) + * libraries. + * + * For Intel IPP licensing, see http://www.intel.com + * + * For G.729(,A,B) royalty payments, see http://www.sipro.com + * WARNING: please make sure you are sitting down before looking + * at their price list. + * + * This source file is Copyright (C) 2004 Ready Technology Limited + * This code is provided for educational purposes and is not warranted + * to be fit for commercial use. There is no warranty of any kind. + * + * Author: daniel@readytechnology.co.uk + */ + +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "usc.h" +#include +#include +#include +#include "encoder.h" +#include "decoder.h" + +#include "slin_g729_ex.h" +#include "g729_slin_ex.h" + +AST_MUTEX_DEFINE_STATIC(localuser_lock); + +static int localusecnt=0; + +static char *tdesc = "G729/PCM16 (signed linear) Codec Translator, based on IPP"; + +static USC_Fxns *USC_CODEC_Fxns; + +struct ast_translator_pvt { + + struct ast_frame f; + + USC_CodecInfo pInfo; + + USC_Handle codec; /* the encoder or decoder handle */ + USC_MemBank* pBanks; + + + USC_PCMStream pcmStream; /* Signed linear data */ + USC_Bitstream bitStream; /* G.729 bits */ + + int nbanks; + int maxbitsize; + int inFrameSize; + int outFrameSize; + + short pcm_buf[8000]; + unsigned char bitstream_buf[1000]; + + int tail; +}; + +#define g729_coder_pvt ast_translator_pvt + +static struct ast_translator_pvt *lintog729_new(void) { + int i; + struct g729_coder_pvt *tmp; + tmp = malloc(sizeof(struct g729_coder_pvt)); + if(tmp) { + USC_CODEC_Fxns->std.GetInfo((USC_Handle)NULL, &tmp->pInfo); + ((USC_Option*)tmp->pInfo.params)->modes.truncate = 1; + ((USC_Option*)tmp->pInfo.params)->direction = 0; + ((USC_Option*)tmp->pInfo.params)->modes.vad = 0; + USC_CODEC_Fxns->std.NumAlloc(tmp->pInfo.params, &(tmp->nbanks)); + tmp->pBanks = (USC_MemBank*)ippsMalloc_8u(sizeof(USC_MemBank)*(tmp->nbanks)); + USC_CODEC_Fxns->std.MemAlloc(tmp->pInfo.params, tmp->pBanks); + for(i=0; inbanks;i++) { + if(!(tmp->pBanks[i].pMem = ippsMalloc_8u(tmp->pBanks->nbytes))) { + printf("\nLow memory: %d bytes not allocated\n",tmp->pBanks->nbytes); + return NULL; + } + } + + tmp->inFrameSize = getInFrameSize(); + tmp->outFrameSize = getOutFrameSize(); + + /* tmp->bitstream_buf = ippsMalloc_8s(tmp->pInfo.maxbitsize); */ + + tmp->pcmStream.bitrate = tmp->pInfo.params->modes.bitrate; + tmp->maxbitsize = tmp->pInfo.maxbitsize; + USC_CODEC_Fxns->std.Init(tmp->pInfo.params, tmp->pBanks, &(tmp->codec)); + + ippCoreSetFlushToZero( 1, NULL ); + tmp->pcmStream.pcmType.bitPerSample = tmp->pInfo.pcmType->bitPerSample; + tmp->pcmStream.pcmType.sample_frequency = tmp->pInfo.pcmType->sample_frequency; + tmp->bitStream.nbytes = tmp->maxbitsize; + tmp->bitStream.pBuffer = tmp->bitstream_buf; + + USC_CODEC_Fxns->std.Reinit(&((USC_Option*)tmp->pInfo.params)->modes, tmp->codec); + + tmp->tail = 0; + localusecnt++; + } + return tmp; +} + +static struct ast_translator_pvt *g729tolin_new(void) { + int i; + struct g729_coder_pvt *tmp; + tmp = malloc(sizeof(struct g729_coder_pvt)); + if(tmp) { + USC_CODEC_Fxns->std.GetInfo((USC_Handle)NULL, &(tmp->pInfo)); + ((USC_Option*)tmp->pInfo.params)->modes.bitrate = 0; + ((USC_Option*)tmp->pInfo.params)->modes.truncate = 1; + ((USC_Option*)tmp->pInfo.params)->direction = 1; + + /* tmp->bitstream_buf = ippsMalloc_8s(size); */ + + USC_CODEC_Fxns->std.NumAlloc(tmp->pInfo.params, &tmp->nbanks); + tmp->pBanks = (USC_MemBank*)ippsMalloc_8u(sizeof(USC_MemBank)*(tmp->nbanks)); + USC_CODEC_Fxns->std.MemAlloc(tmp->pInfo.params, tmp->pBanks); + for(i=0; inbanks;i++) { + if(!(tmp->pBanks[i].pMem = ippsMalloc_8u(tmp->pBanks->nbytes))) { + printf("\nLow memory: %d bytes not allocated\n", tmp->pBanks->nbytes); + return NULL; + } + } + + tmp->outFrameSize = getOutFrameSize(); + + /* pcm_buf ippsMalloc_8s(getOutFrameSize()); */ + + tmp->maxbitsize = tmp->pInfo.maxbitsize; + USC_CODEC_Fxns->std.Init(tmp->pInfo.params, tmp->pBanks, &(tmp->codec)); + + ippCoreSetFlushToZero( 1, NULL ); + + tmp->bitStream.nbytes = tmp->maxbitsize; + tmp->bitStream.bitrate = 0; + tmp->bitStream.frametype = 3; + tmp->pcmStream.pBuffer = tmp->pcm_buf; + tmp->pcmStream.pcmType.bitPerSample = 0; + tmp->pcmStream.pcmType.sample_frequency = 0; + + USC_CODEC_Fxns->std.Reinit(&((USC_Option*)tmp->pInfo.params)->modes, tmp->codec); + + tmp->tail = 0; + localusecnt++; + } + return tmp; +} + +static struct ast_frame *lintog729_sample(void) { + static struct ast_frame f; + f.frametype = AST_FRAME_VOICE; + f.subclass = AST_FORMAT_SLINEAR; + f.datalen = sizeof(slin_g729_ex); + f.samples = sizeof(slin_g729_ex) / 2; + f.mallocd = 0; + f.offset = 0; + f.src = __PRETTY_FUNCTION__; + f.data = slin_g729_ex; + return &f; +} + +static struct ast_frame *g729tolin_sample(void) { + static struct ast_frame f; + f.frametype = AST_FRAME_VOICE; + f.subclass = AST_FORMAT_G729A; + f.datalen = sizeof(g729_slin_ex); + f.samples = 240; + f.mallocd = 0; + f.offset = 0; + f.src = __PRETTY_FUNCTION__; + f.data = g729_slin_ex; + return &f; +} + +/** + * Retrieve a frame that has already been decompressed + */ +static struct ast_frame *g729tolin_frameout(struct ast_translator_pvt *tmp) { + if(!tmp->tail) + return NULL; + tmp->f.frametype = AST_FRAME_VOICE; + tmp->f.subclass = AST_FORMAT_SLINEAR; + tmp->f.datalen = tmp->tail * 2; + tmp->f.samples = tmp->tail; + tmp->f.mallocd = 0; + tmp->f.offset = AST_FRIENDLY_OFFSET; + tmp->f.src = __PRETTY_FUNCTION__; + tmp->f.data = tmp->pcm_buf; + tmp->tail = 0; + return &tmp->f; +} + +/** + * Accept a frame and decode it at the end of the current buffer + */ +static int g729tolin_framein(struct ast_translator_pvt *tmp, struct ast_frame *f) { + int x, i; + if(f->datalen % 10) { + ast_log(LOG_WARNING, "Received a G.729 frame that was %d bytes from %s\n", f->datalen, f->src); + return -1; + } + + for(x = 0; x < f->datalen; x += 10) { + if(tmp->tail + 80 < sizeof(tmp->pcm_buf) / 2) { + /* decode the frame */ + tmp->bitStream.pBuffer = f->data + x; + tmp->pcmStream.pBuffer = tmp->pcm_buf + tmp->tail; + USC_CODEC_Fxns->std.Decode (tmp->codec, &tmp->bitStream, &tmp->pcmStream); + + tmp->tail += 80; + } else { + ast_log(LOG_WARNING, "Out of G.729 buffer space\n"); + return -1; + } + } + return 0; +} + +static int lintog729_framein(struct ast_translator_pvt *tmp, struct ast_frame *f) { + if(tmp->tail + f->datalen/2 < sizeof(tmp->pcm_buf) / 2) { + memcpy((tmp->pcm_buf + tmp->tail), f->data, f->datalen); + tmp->tail += f->datalen/2; + } else { + ast_log(LOG_WARNING, "Out of buffer space\n"); + return -1; + } + return 0; +} + +static struct ast_frame *lintog729_frameout(struct ast_translator_pvt *tmp) { + + + int x = 0, i; + if(tmp->tail < 80) + return NULL; + tmp->f.frametype = AST_FRAME_VOICE; + tmp->f.subclass = AST_FORMAT_G729A; + tmp->f.mallocd = 0; + tmp->f.offset = AST_FRIENDLY_OFFSET; + tmp->f.src = __PRETTY_FUNCTION__; + tmp->f.data = tmp->bitstream_buf; + while(tmp->tail >= 80) { + if((x+1) * 10 >= sizeof(tmp->bitstream_buf)) { + ast_log(LOG_WARNING, "Out of buffer space\n"); + break; + } + /* Copy the frame to workspace, then encode it */ + tmp->pcmStream.pBuffer = tmp->pcm_buf; + tmp->bitStream.pBuffer = tmp->bitstream_buf + (x * 10); + USC_CODEC_Fxns->std.Encode (tmp->codec, &tmp->pcmStream, &tmp->bitStream); + + tmp->tail -= 80; + if(tmp->tail) + memmove(tmp->pcm_buf, tmp->pcm_buf + 80, tmp->tail * 2); + x++; + } + tmp->f.datalen = x * 10; + tmp->f.samples = x * 80; + + + return &(tmp->f); +} + +static void g729_release(struct ast_translator_pvt *pvt) { + int i; + for(i = 0; i < pvt->nbanks; i++) { + if(!pvt->pBanks[i].pMem) + ippsFree(pvt->pBanks[i].pMem); + pvt->pBanks[i].pMem=NULL; + } + if(!pvt->pBanks) + ippsFree(pvt->pBanks); + free(pvt); + localusecnt--; +} + +static struct ast_translator g729tolin = { + "g729tolin", + AST_FORMAT_G729A, AST_FORMAT_SLINEAR, + g729tolin_new, + g729tolin_framein, + g729tolin_frameout, + g729_release, + g729tolin_sample }; + +static struct ast_translator lintog729 = { + "lintog729", + AST_FORMAT_SLINEAR, AST_FORMAT_G729A, + lintog729_new, + lintog729_framein, + lintog729_frameout, + g729_release, + lintog729_sample }; + +int load_module(void) { + USC_CODEC_Fxns = USC_GetCodecByName (); + int res; + res = ast_register_translator(&g729tolin); + if(!res) + res = ast_register_translator(&lintog729); + else + ast_unregister_translator(&g729tolin); + return res; +} + +int unload_module(void) { + int res; + ast_mutex_lock(&localuser_lock); + res = ast_unregister_translator(&lintog729); + if(!res) + res = ast_unregister_translator(&g729tolin); + if(localusecnt) + res = -1; + ast_mutex_unlock(&localuser_lock); + return res; +} + +char *description(void) { + return tdesc; +} + +int usecount(void) { + int res; + STANDARD_USECOUNT(res); + return res; +} + +char *key() { + return ASTERISK_GPL_KEY; +} + diff -u -r -N ./samples/decoder.c /tmp/codec_g729/samples/decoder.c --- ./samples/decoder.c 2004-09-01 02:52:08.000000000 +0100 +++ /tmp/codec_g729/samples/decoder.c 2004-09-18 01:15:44.000000000 +0100 @@ -161,7 +161,7 @@ // Purpose: process command line and run multiple decode threads */ -int main(int argc, char *argv[]) +int main1(int argc, char *argv[]) { int n_repeat = 1; int n_thread = 1; diff -u -r -N ./samples/encoder.c /tmp/codec_g729/samples/encoder.c --- ./samples/encoder.c 2004-09-01 02:52:08.000000000 +0100 +++ /tmp/codec_g729/samples/encoder.c 2004-09-18 01:15:44.000000000 +0100 @@ -172,7 +172,7 @@ // USC encoder main program : // Purpose: process command line and run multiple encode threads */ -int main(int argc, char *argv[]) +int main1(int argc, char *argv[]) { int n_repeat = 1; int n_thread = 1; diff -u -r -N ./samples/g729_slin_ex.h /tmp/codec_g729/samples/g729_slin_ex.h --- ./samples/g729_slin_ex.h 1970-01-01 01:00:00.000000000 +0100 +++ /tmp/codec_g729/samples/g729_slin_ex.h 2004-09-18 02:11:28.000000000 +0100 @@ -0,0 +1,7 @@ +/* + * One frame of raw G729 data + */ + +static unsigned char g729_slin_ex[] = { + 0xf9, 0xa3, 0xc9, 0xe0, 0x0, 0xfa, 0xdd, 0xa9, 0x97, 0x7d }; + diff -u -r -N ./samples/gen_test.c /tmp/codec_g729/samples/gen_test.c --- ./samples/gen_test.c 1970-01-01 01:00:00.000000000 +0100 +++ /tmp/codec_g729/samples/gen_test.c 2004-09-18 02:11:05.000000000 +0100 @@ -0,0 +1,16 @@ + +#include + +int main(int argc, char *argv[]) { + + int i; + + FILE *f = fopen("test1.g729", "r"); + for(i = 0; i < 10; i++) + printf("0x%x, ", fgetc(f)); + fclose(f); + + return 0; + +} + diff -u -r -N ./samples/my_dec.c /tmp/codec_g729/samples/my_dec.c --- ./samples/my_dec.c 1970-01-01 01:00:00.000000000 +0100 +++ /tmp/codec_g729/samples/my_dec.c 2004-09-18 01:15:44.000000000 +0100 @@ -0,0 +1,94 @@ + +#include +#include +#include +#include +#include "usc.h" +#include +#include +#include +#include "decoder.h" + + +int main(int argc, char *argv[]) { + + char *bitstream_buf; + char *buf_out; + char *p; + char *f; + long file_size; + int i; + + USC_Fxns *USC_CODEC_Fxns; + USC_CodecInfo pInfo; + USC_Handle decoder; + + USC_Bitstream in; + USC_PCMStream out; + USC_MemBank* pBanks; + + int nbanks = 0; + int maxbitsize; + int inFrameSize = 10; + int outFrameSize; + + USC_CODEC_Fxns = USC_GetCodecByName (); + USC_CODEC_Fxns->std.GetInfo((USC_Handle)NULL, &pInfo); /* codec info */ + + ((USC_Option*)pInfo.params)->modes.bitrate = 0; + ((USC_Option*)pInfo.params)->modes.truncate = 1; + ((USC_Option*)pInfo.params)->direction = 1; + + FILE *f_in = fopen("test2.g729", "r"); + FILE *f_out = fopen("test2.raw", "w"); + + fseek(f_in, 0, SEEK_END); + file_size = ftell(f_in); + fseek(f_in, 0, SEEK_SET); + + bitstream_buf = ippsMalloc_8s(file_size); + fread(bitstream_buf, file_size, 1, f_in); + p = bitstream_buf; + f = bitstream_buf + file_size; + + USC_CODEC_Fxns->std.NumAlloc(pInfo.params, &nbanks); + pBanks = (USC_MemBank*)ippsMalloc_8u(sizeof(USC_MemBank)*nbanks); + USC_CODEC_Fxns->std.MemAlloc(pInfo.params, pBanks); + for(i=0; inbytes))) { + printf("\nLow memory: %d bytes not allocated\n",pBanks->nbytes); + return -1; + } + } + + outFrameSize = getOutFrameSize(); + + buf_out = ippsMalloc_8s(getOutFrameSize()); + + maxbitsize = pInfo.maxbitsize; + USC_CODEC_Fxns->std.Init(pInfo.params, pBanks, &decoder); + + ippCoreSetFlushToZero( 1, NULL ); + + in.nbytes = maxbitsize; + in.bitrate = 0; + in.frametype = 3; + out.pBuffer = buf_out; + out.pcmType.bitPerSample = 0; + out.pcmType.sample_frequency = 0; + + USC_CODEC_Fxns->std.Reinit(&((USC_Option*)pInfo.params)->modes, decoder); + + while(p < f) { + in.pBuffer = p; + USC_CODEC_Fxns->std.Decode (decoder, &in, &out); + fwrite(out.pBuffer, outFrameSize, 1, f_out); + + p += inFrameSize; + } + + fclose(f_out); + fclose(f_in); + +} + diff -u -r -N ./samples/my_enc.c /tmp/codec_g729/samples/my_enc.c --- ./samples/my_enc.c 1970-01-01 01:00:00.000000000 +0100 +++ /tmp/codec_g729/samples/my_enc.c 2004-09-18 01:15:44.000000000 +0100 @@ -0,0 +1,93 @@ + +#include +#include +#include +#include +#include "usc.h" +#include +#include +#include +#include "encoder.h" + + +int main(int argc, char *argv[]) { + + char *buf_in; + char *bitstream_buf; + char *p; + char *f; + long file_size; + int i; + + USC_Fxns *USC_CODEC_Fxns; + USC_CodecInfo pInfo; + USC_Handle encoder; + + USC_PCMStream in; + USC_Bitstream out; + USC_MemBank* pBanks; + + int nbanks = 0; + int maxbitsize; + int inFrameSize; + int outFrameSize = 0; + + USC_CODEC_Fxns = USC_GetCodecByName (); + USC_CODEC_Fxns->std.GetInfo((USC_Handle)NULL, &pInfo); /* codec info */ + ((USC_Option*)pInfo.params)->modes.truncate = 1; + ((USC_Option*)pInfo.params)->direction = 0; + ((USC_Option*)pInfo.params)->modes.vad = 0; + + FILE *f_in = fopen("test1.raw", "r"); + FILE *f_out = fopen("test1.g729", "w"); + + fseek(f_in, 0, SEEK_END); + file_size = ftell(f_in); + fseek(f_in, 0, SEEK_SET); + + buf_in = ippsMalloc_8s(file_size); + fread(buf_in, file_size, 1, f_in); + p = buf_in; + f = buf_in + file_size; + + USC_CODEC_Fxns->std.NumAlloc(pInfo.params, &nbanks); + pBanks = (USC_MemBank*)ippsMalloc_8u(sizeof(USC_MemBank)*nbanks); + USC_CODEC_Fxns->std.MemAlloc(pInfo.params, pBanks); + for(i=0; inbytes))) { + printf("\nLow memory: %d bytes not allocated\n",pBanks->nbytes); + return -1; + } + } + + inFrameSize = getInFrameSize(); + outFrameSize = getOutFrameSize(); + + bitstream_buf = ippsMalloc_8s(pInfo.maxbitsize); + + in.bitrate = pInfo.params->modes.bitrate; + maxbitsize = pInfo.maxbitsize; + USC_CODEC_Fxns->std.Init(pInfo.params, pBanks, &encoder); + + ippCoreSetFlushToZero( 1, NULL ); + in.pcmType.bitPerSample = pInfo.pcmType->bitPerSample; + in.pcmType.sample_frequency = pInfo.pcmType->sample_frequency; + out.nbytes = maxbitsize; + out.pBuffer = bitstream_buf; + + USC_CODEC_Fxns->std.Reinit(&((USC_Option*)pInfo.params)->modes, encoder); + + while(p < f) { + in.pBuffer = p; + USC_CODEC_Fxns->std.Encode (encoder, &in, &out); + fwrite(out.pBuffer, 10, 1, f_out); + p += inFrameSize; + } + + fclose(f_out); + fclose(f_in); + + return 0; +} + + diff -u -r -N ./samples/slin_g729_ex.h /tmp/codec_g729/samples/slin_g729_ex.h --- ./samples/slin_g729_ex.h 1970-01-01 01:00:00.000000000 +0100 +++ /tmp/codec_g729/samples/slin_g729_ex.h 2004-09-18 02:04:54.000000000 +0100 @@ -0,0 +1,30 @@ +/* + * Signed 16 bit audio data + * + */ +static signed short slin_g729_ex[] = { +0x0873, 0x06d9, 0x038c, 0x0588, 0x0409, 0x033d, 0x0311, 0xff6c, 0xfeef, 0xfd3e, +0xfdff, 0xff7a, 0xff6d, 0xffec, 0xff36, 0xfd62, 0xfda7, 0xfc6c, 0xfe67, 0xffe1, +0x003d, 0x01cc, 0x0065, 0x002a, 0xff83, 0xfed9, 0xffba, 0xfece, 0xff42, 0xff16, +0xfe85, 0xff31, 0xff02, 0xfdff, 0xfe32, 0xfe3f, 0xfed5, 0xff65, 0xffd4, 0x005b, +0xff88, 0xff01, 0xfebd, 0xfe95, 0xff46, 0xffe1, 0x00e2, 0x0165, 0x017e, 0x01c9, +0x0182, 0x0146, 0x00f9, 0x00ab, 0x006f, 0xffe8, 0xffd8, 0xffc4, 0xffb2, 0xfff9, +0xfffe, 0x0023, 0x0018, 0x000b, 0x001a, 0xfff7, 0x0014, 0x000b, 0x0004, 0x000b, +0xfff1, 0xff4f, 0xff3f, 0xff42, 0xff5e, 0xffd4, 0x0014, 0x0067, 0x0051, 0x003b, +0x0034, 0xfff9, 0x000d, 0xff54, 0xff54, 0xff52, 0xff3f, 0xffcc, 0xffe6, 0x00fc, +0x00fa, 0x00e4, 0x00f3, 0x0021, 0x0011, 0xffa1, 0xffab, 0xffdb, 0xffa5, 0x0009, +0xffd2, 0xffe6, 0x0007, 0x0096, 0x00e4, 0x00bf, 0x00ce, 0x0048, 0xffe8, 0xffab, +0xff8f, 0xffc3, 0xffc1, 0xfffc, 0x0002, 0xfff1, 0x000b, 0x00a7, 0x00c5, 0x00cc, +0x015e, 0x00e4, 0x0094, 0x0029, 0xffc7, 0xffc3, 0xff86, 0xffe4, 0xffe6, 0xffec, +0x000f, 0xffe3, 0x0028, 0x004b, 0xffaf, 0xffcb, 0xfedd, 0xfef8, 0xfe83, 0xfeba, +0xff94, 0xff94, 0xffbe, 0xffa8, 0xff0d, 0xff32, 0xff58, 0x0021, 0x0087, 0x00be, +0x0115, 0x007e, 0x0052, 0xfff0, 0xffc9, 0xffe8, 0xffc4, 0x0014, 0xfff0, 0xfff5, +0xfffe, 0xffda, 0x000b, 0x0010, 0x006f, 0x006f, 0x0052, 0x0045, 0xffee, 0xffea, +0xffcb, 0xffdf, 0xfffc, 0xfff0, 0x0012, 0xfff7, 0xfffe, 0x0018, 0x0050, 0x0066, +0x0047, 0x0028, 0xfff7, 0xffe8, 0xffec, 0x0007, 0x001d, 0x0016, 0x00c4, 0x0093, +0x007d, 0x0052, 0x00a5, 0x0091, 0x003c, 0x0041, 0xffd1, 0xffda, 0xffc6, 0xfff0, +0x001d, 0xfffe, 0x0024, 0xffee, 0xfff3, 0xfff0, 0xffea, 0x0012, 0xfff3, 0xfff7, +0xffda, 0xffca, 0xffda, 0xffdf, 0xfff3, 0xfff7, 0xff54, 0xff7c, 0xff8c, 0xffb9, +0x0012, 0x0012, 0x004c, 0x0007, 0xff50, 0xff66, 0xff54, 0xffa9, 0xffdc, 0xfff9, +0x0038, 0xfff9, 0x00d2, 0x0096, 0x008a, 0x0079, 0xfff5, 0x0019, 0xffad, 0xfffc }; + diff -u -r -N ./samples/util_e.c /tmp/codec_g729/samples/util_e.c --- ./samples/util_e.c 2004-09-01 02:52:08.000000000 +0100 +++ /tmp/codec_g729/samples/util_e.c 2004-09-18 03:36:00.000000000 +0100 @@ -26,7 +26,7 @@ */ #include "util_e.h" -USC_Fxns* USC_GetCodecByName (void) +USC_Fxns* USC_GetCodecByName_xx2 (void) { return &USC_G729FP_Fxns; } @@ -68,7 +68,7 @@ return 0; } -int text2rate(char *strRate, char **rat_buff, int *nRates, USC_CodecInfo *pInfo) +int text2rate_xx1(char *strRate, char **rat_buff, int *nRates, USC_CodecInfo *pInfo) { if(!strcmp(strRate,"A")){ ((USC_Option*)pInfo->params)->modes.bitrate=G729A_CODEC; @@ -128,7 +128,7 @@ return(G729_SPEECH_FRAME*sizeof(short)); } -int getOutFrameSize(void) +int getOutFrameSize_xx3(void) { return(BITSTREAM_FILE_FRAME_SIZE*sizeof(short)); } diff -u -r -N ./samples/util_e.h /tmp/codec_g729/samples/util_e.h --- ./samples/util_e.h 2004-09-01 02:52:08.000000000 +0100 +++ /tmp/codec_g729/samples/util_e.h 2004-09-18 03:35:47.000000000 +0100 @@ -85,11 +85,11 @@ /* GetCodecByName() - quest codec functions table by codec name */ -USC_Fxns* USC_GetCodecByName(void); -int text2rate(char *strRate, char **rat_buff, int *nRates, USC_CodecInfo *pInfo); +USC_Fxns* USC_GetCodecByName_xx2(void); +int text2rate_xx1(char *strRate, char **rat_buff, int *nRates, USC_CodecInfo *pInfo); int checkVad(char *strVad, int *mode); int getInFrameSize(void); -int getOutFrameSize(void); +int getOutFrameSize_xx3(void); int Bits2Ref(USC_PCMStream in, USC_Bitstream out, char *out_buff_cur); #endif /*UTIL_E_H*/