www.pudn.com > lpc.zip > lpc_both.c
#ifdef LOWRATE #include "defines.h" #endif /* LOWRATE */ /*********************************************************************** * * NSA LPC-10 Voice Coder * * Unix C Version * * 5 November 1990 * *************************************************************************/ /* Explanation of #ifdefs: sun - to compile if running on the sun workstation _TMS320C30 - to compile if running on the C30 BITS - for saving bitstream information on the PC disk TURBO - uses functions/routines from the Turbo C library TREES - uses JSC's tree search routines */ #include#include "lpcdefs.h" #include "config.ch" #include "common.h" #include "ourstuff.h" #ifdef _TMS320C30 #include #endif /* _TMS320C30 */ #ifdef sun #define DISK 1 #endif #define BUFSIZE 600 int_type count=0; float min1=100000., min2=100000., min3=100000.; float max1=-100000., max2=-100000., max3=-100000.; int_type myint = 0; int_type sw; #ifdef _TMS320C30 AIC_Driver aic_driver; void *aic_speech; #endif /* _TMS320C30 */ int_type tau_i[LTAU] = { 20,21,22,23,24,25,26,27,28,29,30,31,32,33,34, 35,36,37,38,39,40,42,44,46,48,50,52,54,56,58,60,62,64,66, 68,70,72,74,76,78,80,84,88,92,96,100,104,108,112,116,120, 124,128,132,136,140,144,148,152,156 }; int nframe, nfb, nbits, nunsfm, iclip, maxosp, NFBLK; FILE *fbi, *fbo, *fopen(); /* analys */ int_type *inbuf_i, *pebuf_i, *lpbuf_i, *ivbuf_i; int_type lparray_i[LBUFH-LBUFL+1], ivarray_i[PWINH-PWINL+1]; int_type pearray_i[SBUFH-SBUFL+1], inarray_i[SBUFH-SBUFL+1]; int_type vwin_i[2][AF], awin_i[2][AF], voibuf_i[2][AF+1]; int_type rmsbuf_i[AF], psi_i[MAXORD], rcbuf_i[MAXORD][AF]; int_type amdf_i[LTAU]; int_type phi_i[MAXORD][MAXORD]; long_type phi_l[MAXORD][MAXORD], psi_l[MAXORD]; /* bsynz.c */ /*float exc[MAXPIT+MAXORD], exc2[MAXPIT+MAXORD]; float noise[MAXPIT+MAXORD]; */ int_type exc_i[MAXPIT+MAXORD]; long_type exc2_l[MAXPIT+MAXORD]; int_type noise_i[MAXPIT+MAXORD]; /* decode.c */ /*int drc[3][MAXORD], dpit[3], drms[3];*/ int_type drc_i[3][MAXORD], dpit_i[3], drms_i[3]; /* dyptrk */ int_type s_i[60]; int_type p_i[60][2]; /* onset */ int_type l2buf_i[16]; /* synths.c */ /*int ipiti[11], ivuv[11]; float rci[MAXORD][11], rmsi[11], pc[MAXORD]; */ int_type ipiti_i[11], ivuv_i[11]; int_type rci_i[MAXORD][11], rmsi_i[11], pc_i[MAXORD]; main(argc,argv) int argc; char *argv[]; { int_type pitch_i; int_type rms_i, rc_i[MAXORD]; int_type len; int_type voice_i[2]; FILE *fp; #if NOQUANT int_type i,j, l=0; #endif #ifdef sun short eof, done=0; static float speech[MAXFRM+MAXPIT]; static int_type speech_i[MAXFRM+MAXPIT]; #endif /* sun */ #ifdef ANALOG static float lpc_speech[MAXFRM+MAXPIT]; float *speech; #endif /* ANALOG */ #ifdef PCM printf("********** PCM Only in Main Processing loop ***********\n"); #endif /* PCM */ #ifdef sun #ifndef FLEXIBLE setup(); #else setup(argc,argv); #endif /* FLEXIBLE */ #endif /* sun */ #ifdef _TMS320C30 setup(); #endif /* _TMS320C30 */ initialize1_i(); initialize2_i(); if(!(fp=fopen("dam9.dat","wb"))) { printf("Can not open dam9.dat output file.\n"); exit(1); } #ifdef TURBO #ifdef NOQUANT printf("**** No Quantization ****\n"); #endif /* NOQUANT */ #ifdef ANALYZER printf("**** Analyzer Only ****\n"); #endif /* ANALYZER */ #ifdef SYNTHESIZER printf("**** Synthesizer Only ****\n"); #endif /* SYNTHESIZER */ #ifndef LOWRATE printf("Linear Predictive Coding at 2400 bps\n\n"); #endif /* LOWRATE */ #ifdef LOWRATE_600 printf("Linear Predictive Coding with vector quantization at 600 bps \n\n"); printf("\tUsing "); #endif /* LOWRATE_600 */ #ifdef LOWRATE_800 printf("Linear Predictive Coding with vector quantization at 800 bps \n\n"); printf("\tUsing "); #ifndef TREES printf("full search\n"); #else /* TREES */ printf("tree search with"); #endif /* TREES */ #ifdef TREE_2x12 printf("2 12-bit codebooks "); #endif /* TREE_2x12 */ #ifdef UTREE_8 printf("(Upper tree 8-bits) "); #endif /* UTREE_8 */ #ifdef UTREE_7 printf("(Upper tree 7-bits) "); #endif /* UTREE_7 */ #ifdef UTREE_12 printf("(Upper tree 12-bits) "); #endif /* UTREE_12 */ #ifdef LTREE_9 printf("(Lower tree 9-bits) "); #endif /* LTREE_9 */ #ifdef LTREE_12 printf("(Lower tree 12-bits) "); #endif /* LTREE_12 */ #endif /* LOWRATE_800 */ #ifdef LOWRATE_1200 printf("Linear Predictive Coding with vector quantization at 1200 bps \n\n"); #endif /* LOWRATE_1200 */ /* ---------------------- main processing loop begins -------------------*/ #ifdef _TMS320C30 printf("\nPress any key to discontinue vocoding ...."); while(!kbhit()) #endif /* _TMS320C30 */ #endif /* TURBO */ #ifndef TURBO #ifdef _TMS320C30 while(1) #endif /* _TMS320C30 */ #endif /* !TURBO */ #ifdef sun while(!done) #endif /* sun */ { #if LOWRATE nfb++; if (nfb >= NFBLK) nfb = 0; #endif /* LOWRATE */ #ifndef SYNTHESIZER #ifdef ANALOG /* Read, Pre-process, and Analyze input speech */ while(!AIC_get(aic_driver, (Ptr *)&aic_speech)) { } float_buffer(aic_speech, LFRAME); scale_down(aic_speech, LFRAME); speech = (float *) aic_speech; #endif /* ANALOG */ #ifdef DISK if (fdi != NULL) diskio(0,fdi,speech,LFRAME,&eof,"",0); if(eof==END) break; /* Do 9 bit quantization for hp100 */ for(sw=0; sw = 1) && (*pitch <= LTAU)) *ptau = tau_i[*pitch-1]; else *ptau = 0; } #endif /*----------------------------------------------------------------------*/ buf_man(inbuffer, outbuffer, len) float outbuffer[], inbuffer[]; int len; { static float big_buffer[BUFSIZE]; static int sptr=0, eptr=360, first=1; int i; /* Initialize pseudo-circular buffer */ if(first) { first = 0; for(i=0;i<360;i++) big_buffer[i] = 0.0; } /* write new data to end of buffer */ for(i=0;i