00001 #include "c_lpc10.h" 00002 00003 /**********************************************************/ 00004 /* Main analisys loop. 00005 00006 Constants: 00007 . NF - Number of frames 00008 . AF - Frame in which analysis is done 00009 . OSLEN - Length of the onset buffer 00010 . LTAU - Number of pitch lags 00011 . SBUFL, SBUFH - Start and end index of speech buffers 00012 . LBUFL, LBUFH - Start and end index of LPF speech buffer 00013 . MINWIN, MAXWIN - Min and Max length of voicing (and analysis) windows 00014 . PWLEN, PWINH, PWINL - Length, upper and lower limits of pitch window 00015 . DVWINL, DVWINH - Default lower and upper limits of voicing window 00016 00017 Data Buffers: 00018 . inbuf - Raw speech (with DC bias removed each frame) 00019 . pebuf - Preemphasized speech 00020 . lpbuf - Low pass speech buffer 00021 . ivbuf - Inverse filtered speech 00022 . osbuf - Indexes of onsets in speech buffers 00023 . vwin - Voicing window indices 00024 . awin - Analysis window indices 00025 . ewin - Energy window indices 00026 . voibuf - Voicing decisions on windows in {vwin} 00027 . rmsbuf - RMS energy 00028 . rcbuf - Reflection Coefficients 00029 00030 Pitch is handled separately from the above parameters. The following 00031 variables deal with pitch: 00032 . midx - Encoded initial pitch estimate for analysis frame 00033 . pitch - The encoded pitch value (index into {tau}) for the present 00034 . frame (delayed and smoothed by dyptrk) */ 00035 00036 VOID analys( VOID ) 00037 { 00038 static FLOAT abuf[MAXWIN]; 00039 static FLOAT psi[ORDER]; 00040 static FLOAT amdf[LTAU]; 00041 static FLOAT phi[ORDER][ORDER]; 00042 INDEX ewin[2]; 00043 INDEX lanal, midx, minptr, maxptr, mintau; 00044 FLOAT ivrc[2]; 00045 00046 /* Calculations are done on future frame due to requirements 00047 of the pitch tracker. Delay RMS and RC's 2 frames to give 00048 current frame parameters on return: */ 00049 00050 /* Place Voicing Window */ 00051 preemp(g_inbuf+(SBUFH-LFRAME+1), g_pebuf+(SBUFH-LFRAME+1), LFRAME, g_zpre); 00052 onset(g_pebuf, g_osbuf, &g_osptr); 00053 placev(g_osbuf, g_osptr, &g_obound[AF-1], g_vwin); 00054 00055 /* The Pitch Extraction algorithm estimates the pitch for a frame 00056 of speech by locating the minimum of the average magnitude difference 00057 function (AMDF). The AMDF operates on low-pass, inverse filtered 00058 speech (The low-pass filter is an 800 Hz, 31 tap, equiripple, FIR 00059 filter and the inverse filter is a 2nd-order LPC filter). The pitch 00060 estimate is later refined by dynamic programming (dyptrk). However, 00061 since some of dyptrk's parameters are a function of the voicing 00062 decisions, a voicing decision must precede the final pitch estimation. 00063 See subroutines lpfilt31(), ivfilt(), and tbdm(). */ 00064 lpfilt31(g_inbuf+LBUFH-PWLEN-1, g_lpbuf+LBUFH-PWLEN+1); 00065 ivfilt(g_lpbuf+PWINL, g_ivbuf+PWINL, ivrc); 00066 tbdm(g_ivbuf+PWINL, G_tau, amdf, &minptr, &maxptr, &mintau); 00067 00068 /* Voicing decisions are made for each half frame of input speech. 00069 An initial voicing classification is made for each half of the 00070 analysis frame, and the voicing decisions for the present frame 00071 are finalized. See subroutine voicin(). 00072 The voicing detector (voicin()) classifies the input signal as 00073 unvoiced (including silence) or voiced using the AMDF windowed 00074 maximum-to-minimum ratio, the zero crossing rate, energy measures, 00075 reflection coefficients, and prediction gains. 00076 The pitch and voicing rules (dyptrk()) apply smoothing and isolated 00077 corrections to the pitch and voicing estimates and, in the process, 00078 introduce two frames of delay into the corrected pitch estimates and 00079 voicing decisions. */ 00080 /* first half */ 00081 voicin(g_vwin, g_inbuf, g_lpbuf, 0, amdf[minptr], amdf[maxptr], mintau, ivrc, g_obound, g_voibuf); 00082 /* second half */ 00083 voicin(g_vwin, g_inbuf, g_lpbuf, 1, amdf[minptr], amdf[maxptr], mintau, ivrc, g_obound, g_voibuf); 00084 /* Find the minimum cost pitch decision over several frames given 00085 the current voicing decision and the AMDF array. tau[midx] is the 00086 initial pitch computed for frame AF (ipitch, decoded from {midx})*/ 00087 dyptrk(amdf, minptr, g_voibuf[AF][1], &g_pitch, &midx); 00088 00089 /* Place spectrum analysis and energy windows. 00090 {awin} marks start/end of analysis window. {ewin} marks start/end 00091 of energy calculation window. Both are refered to {pebuf} buffer. */ 00092 placea(G_tau[midx], g_voibuf, g_obound[AF-1], g_vwin, g_awin, ewin); 00093 /* analysis window length */ 00094 lanal = g_awin[AF-1][1] - g_awin[AF-1][0] + 1; 00095 /* Remove short term DC bias over the analysis window. Put result in {abuf}, 00096 which will hold directly the {lanal} elements of the analysis frame. */ 00097 dcbias(lanal, g_pebuf + g_awin[AF-1][0], abuf); 00098 /* Compute RMS over integer number of pitch periods within the analysis window. */ 00099 g_rmsbuf[AF-1] = energy_sqrt(ewin[1] - ewin[0] + 1, 00100 abuf + (ewin[0] - g_awin[AF-1][0])); 00101 00102 /* Matrix load and invert, check RC's for stability */ 00103 mload(lanal, abuf, phi, psi); 00104 00105 invert(phi, psi, g_rcbuf[AF-1]); 00106 rcchk(g_rcbuf[AF-2], g_rcbuf[AF-1]); 00107 } 00108 00109 /**********************************************************/ 00110