00001 #include "d_lpc10.h"
00002 #include <math.h>
00003 #include <stdlib.h>
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifdef VIEW_EXCIT
00021
00022 FLOAT kexc[25] = {
00023 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00024 0, 0, 0, 0, 0, 728, 0, 0, 0, 0,
00025 0, 0, 0, 0, 0
00026 };
00027 #else
00028 FLOAT kexc[25] = {
00029 8, -16, 26, -48, 86, -162, 294, -502, 718, -728,
00030 184, 672, -610, -672, 184, 728, 718, 502, 294, 162,
00031 86, 48, 26, 16, 8
00032 };
00033 #endif
00034
00035
00036 static INDEX ipo = 0;
00037
00038 #ifdef VIEW_EXCIT
00039
00040 static FLOAT a0 = .125, a1 = 0, a2 = 0, b0 = 0, b1 = 0, b2 = 0;
00041 #else
00042 static FLOAT a0 = .125, a1 = .75, a2 = .125, b0 = -.125, b1 = .25, b2 = -.125;
00043 #endif
00044
00045 static FLOAT rmso = 0.0, lpi1 = 0.0, lpi2 = 0.0, hpi1 = 0.0, hpi2 = 0.0;
00046
00047 VOID bsynz(FLOAT coef[], INDEX ip, BOOL iv, FLOAT sout[], FLOAT rms,
00048 FLOAT ratio, FLOAT g2pass)
00049 {
00050 INDEX px, i, j, k;
00051 FLOAT lpi0, hpi0;
00052 FLOAT pulse, sscale, xssq, sum, sum2, ssq, gain, xy;
00053
00054
00055 xy = (FLOAT)(MMIN((rmso / (rms + .000001)), 8.0));
00056 rmso = rms;
00057 for (i = 0; i < ORDER; i++)
00058 exc2[i] = exc2[ipo + i] * xy;
00059
00060 ipo = ip;
00061
00062 if (iv == 0) {
00063
00064
00065
00066 for (i = 0; i < ip; i++)
00067 exc[ORDER + i] = (FLOAT)(Rrandom() >> 6);
00068
00069
00070
00071
00072
00073
00074 px = (INDEX) ((Rrandom() + 32768L) * (ip - 1) >> 16) + ORDER + 1;
00075 pulse = (FLOAT)(ratio * 85.5);
00076 if (pulse > 2000)
00077 pulse = 2000;
00078 exc[px - 1] += pulse;
00079 exc[px] -= pulse;
00080 }
00081 else {
00082 sscale = (FLOAT)(sqrt((FLOAT)ip) * 0.144341801);
00083 for (i = 0; i < ip; i++) {
00084 lpi0 = (i < 25) ? sscale * kexc[i] : 0;
00085 hpi0 = (FLOAT)(Rrandom() >> 6);
00086 exc[ORDER + i] = a0 * lpi0 + a1 * lpi1 + a2 * lpi2 +
00087 b0 * hpi0 + b1 * hpi1 + b2 * hpi2;
00088 lpi2 = lpi1;
00089 lpi1 = lpi0;
00090 hpi2 = hpi1;
00091 hpi1 = hpi0;
00092 }
00093 }
00094
00095
00096
00097 xssq = 0;
00098 for (i = 0; i < ip; i++) {
00099 k = ORDER + i;
00100
00101
00102 sum = 0;
00103 sum2 = 0;
00104 for (j = 0; j < ORDER; j++) {
00105 sum += coef[j] * exc[k - j - 1];
00106 sum2 += coef[j] * exc2[k - j - 1];
00107 }
00108
00109 #ifdef VIEW_EXCIT
00110
00111 exc2[k] = exc[k];
00112 (void)g2pass;
00113 #else
00114 exc2[k] = sum * g2pass + exc[k] + sum2;
00115 #endif
00116
00117 xssq = xssq + exc2[k] * exc2[k];
00118 }
00119
00120 if (ip>MAXPIT) exit(1);
00121 for (i = 0; i < ORDER; i++) {
00122 exc[i] = exc[ip + i];
00123
00124 }
00125
00126
00127
00128 ssq = rms * rms * ip;
00129 gain = (FLOAT)(sqrt(ssq / xssq));
00130
00131 #ifdef VIEW_EXCIT
00132
00133 gain *= 0.5;
00134 #endif
00135
00136 for (i = 0; i < ip; i++)
00137 sout[i] = gain * exc2[ORDER + i];
00138 }
00139
00140