www.pudn.com > lpc.zip > bsynz_i.c
/****************************************************************** * * BSYNZ Version 49 * ****************************************************************** * * Synthesize One Pitch Epoch * * Inputs: * COEF - Predictor coefficients * IP - Pitch period (number of samples to synthesize) * IV - Voicing for the current epoch * RMS - Energy for the current epoch * ORDER - Synthesizer filter order (number of PC's) * RATIO - Energy slope for plosives * G2PASS- Sharpening factor for 2 pass synthesis * Outputs: * SOUT - Synthesized speech */ #include "ourstuff.h" #include "config.ch" /*#include "common.h"*/ #include "lpcdefs.h" #includeint_type kexc_i[25]={ 8,-16,26,-48,86,-162,294,-502,718,-728, 184,672,-610,-672,184,728,718,502,294,162, 86,48,26,16,8 }; extern int_type exc_i[MAXPIT+MAXORD], exc2_i[MAXPIT+MAXORD]; extern long_type exc_l[MAXPIT+MAXORD], exc2_l[MAXPIT+MAXORD]; bsynz_i( coef, ip, iv, sout, rms, ratio, g2pass ) int_type ip, iv; int_type coef[], sout[], g2pass, rms, ratio; { int_type px; static int_type ipo=0; int_type i, j, k; int_type noise[MAXPIT+MAXORD]; int_type lpi0, hpi0; int_type a0=1, a1=6, a2=1, b0=-1, b1=2, b2=-1; int_type pulse, sscale, gain; int_type xy; static int_type rmso=0, lpi1=0, lpi2=0, hpi1=0, hpi2=0; long_type xssq, ssq, sum; /* Calculate history scale factor XY and scale filter state */ xy = mmin((rmso<<12)/(mmax(rms,1)), 32767); /* printf("(i) %f %f %f\n",xy/4096.,rmso/32.,rms/32.); */ rmso = rms; for(i=0;i >12); } ipo = ip; if(iv==0) { /* printf("(i) unvoiced\n"); */ /* Generate white noise for unvoiced */ for(i=0;i > 3; /* printf("(i) exc_i[ORDER+%d] = %d\n",i,exc_i[ORDER+i]>>3); */ } /* Impulse doublet excitation for plosives */ px = (((long_type)(Rrandom_i()+32768)*(long_type)(ip-1))>>16) + ORDER + 1; /*pulse = PESCL*(ratio*.25)*342;*/ pulse = (ratio>1497) ? 16000 : (((long_type)ratio*(long_type)5472)>>9); exc_i[px-1] += pulse; exc_i[px] -= pulse; /* printf("(i) %d %f %f %f\n",px,pulse/8.,exc_i[px-1]/8.,exc_i[px]/8.); */ /* Load voiced excitation */ } else { /* printf("(i) voiced\n"); */ /*sscale = sqrt((float)ip)/6.928;*/ sscale = ((int)(8192.*sqrt((float)ip)))*1182 >> 13; /* printf("(i) sscale = %f (%d)\n",sscale/8192.,ip); */ for(i=0;i > 10; lpi0 = exc_i[ORDER+i]<<1; exc_i[ORDER+i] = ((a0*exc_i[ORDER+i] >> 3) + (((long_type)a1*(long_type)lpi1) >> 4) + (((long_type)a2*(long_type)lpi2) >> 4)); /* printf("(i) exc_i[ORDER+%d] = %f\n",i,exc_i[ORDER+i]/8.); */ /*lpi3 = lpi2;*/ lpi2 = lpi1; lpi1 = lpi0; } for(i=0;i >3) + (((long_type)b1*(long_type)hpi1)>>3) + (((long_type)b2*(long_type)hpi2)>>3)); /*hpi3 = hpi2; */ /* printf("(i) noise[ORDER+%d] = %f\n",i,noise[ORDER+i]/64.); */ hpi2 = hpi1; hpi1 = hpi0; } for(i=0;i >3; /* printf("(i) exc_i[ORDER+%d] = %f\n",i,exc_i[ORDER+i]/8.); */ } } /* Synthesis filters: * Modify the excitation with all-zero filter 1 + G*SUM */ xssq = 0; for(i=0;i >3))>>12); /* if(j==0) printf("(i) %d sum = %d %f %f\n", k,sum,coef[j]/4096., exc_i[k-j-1]/8.); */ } sum = ((long_type)sum*(long_type)g2pass) >> 14; exc2_l[k] = sum + (exc_i[k]>>3); /* printf("(i) exc2_l[%d] = %d %f %f %f\n", k,exc2_l[k],coef[ORDER-1]/4096., exc_i[k]/8.,g2pass/16384.); */ } /* Synthesize using the all pole filter 1 / (1 - SUM) */ for(i=0;i >12; /* printf("(i) exc2_l[%d] = %d (%f)\n",k,exc2_l[k],sum/4096.); */ xssq = xssq + (((long_type)exc2_l[k]*(long_type)exc2_l[k]) >> 7); /* printf("(i) %d %d\n",k,xssq*4); */ } /* Save filter history for next epoch */ for(i=0;i >5)*(long_type)ip)>>5; gain = (int_type)(16384.*sqrt((ssq/(double)(xssq>>3))/1024.)); gain = gain; /* printf("(i) %d %d %f %f %d\n",ssq, xssq*128, gain/16384.,rms/32.,ip); */ for(i=0;i >11; /* printf("(i) %d: sout (%f) = %f * %f\n",i,sout[i]/8.,gain/16384., exc2_l[ORDER+i]/8.); */ } }