\doxysection{cont\+\_\+ad\+\_\+base.\+c}
\label{cont__ad__base_8c_source}\index{src/libsphinxad/cont\_ad\_base.c@{src/libsphinxad/cont\_ad\_base.c}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{comment}{/*\ -\/*-\/\ c-\/basic-\/offset:\ 4;\ indent-\/tabs-\/mode:\ nil\ -\/*-\/\ */}}
\DoxyCodeLine{00002\ \textcolor{comment}{/*\ ====================================================================}}
\DoxyCodeLine{00003\ \textcolor{comment}{\ *\ Copyright\ (c)\ 1999-\/2001\ Carnegie\ Mellon\ University.\ \ All\ rights}}
\DoxyCodeLine{00004\ \textcolor{comment}{\ *\ reserved.}}
\DoxyCodeLine{00005\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00006\ \textcolor{comment}{\ *\ Redistribution\ and\ use\ in\ source\ and\ binary\ forms,\ with\ or\ without}}
\DoxyCodeLine{00007\ \textcolor{comment}{\ *\ modification,\ are\ permitted\ provided\ that\ the\ following\ conditions}}
\DoxyCodeLine{00008\ \textcolor{comment}{\ *\ are\ met:}}
\DoxyCodeLine{00009\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00010\ \textcolor{comment}{\ *\ 1.\ Redistributions\ of\ source\ code\ must\ retain\ the\ above\ copyright}}
\DoxyCodeLine{00011\ \textcolor{comment}{\ *\ \ \ \ notice,\ this\ list\ of\ conditions\ and\ the\ following\ disclaimer.\ }}
\DoxyCodeLine{00012\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00013\ \textcolor{comment}{\ *\ 2.\ Redistributions\ in\ binary\ form\ must\ reproduce\ the\ above\ copyright}}
\DoxyCodeLine{00014\ \textcolor{comment}{\ *\ \ \ \ notice,\ this\ list\ of\ conditions\ and\ the\ following\ disclaimer\ in}}
\DoxyCodeLine{00015\ \textcolor{comment}{\ *\ \ \ \ the\ documentation\ and/or\ other\ materials\ provided\ with\ the}}
\DoxyCodeLine{00016\ \textcolor{comment}{\ *\ \ \ \ distribution.}}
\DoxyCodeLine{00017\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00018\ \textcolor{comment}{\ *\ This\ work\ was\ supported\ in\ part\ by\ funding\ from\ the\ Defense\ Advanced\ }}
\DoxyCodeLine{00019\ \textcolor{comment}{\ *\ Research\ Projects\ Agency\ and\ the\ National\ Science\ Foundation\ of\ the\ }}
\DoxyCodeLine{00020\ \textcolor{comment}{\ *\ United\ States\ of\ America,\ and\ the\ CMU\ Sphinx\ Speech\ Consortium.}}
\DoxyCodeLine{00021\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00022\ \textcolor{comment}{\ *\ THIS\ SOFTWARE\ IS\ PROVIDED\ BY\ CARNEGIE\ MELLON\ UNIVERSITY\ \`{}\`{}AS\ IS''\ AND\ }}
\DoxyCodeLine{00023\ \textcolor{comment}{\ *\ ANY\ EXPRESSED\ OR\ IMPLIED\ WARRANTIES,\ INCLUDING,\ BUT\ NOT\ LIMITED\ TO,\ }}
\DoxyCodeLine{00024\ \textcolor{comment}{\ *\ THE\ IMPLIED\ WARRANTIES\ OF\ MERCHANTABILITY\ AND\ FITNESS\ FOR\ A\ PARTICULAR}}
\DoxyCodeLine{00025\ \textcolor{comment}{\ *\ PURPOSE\ ARE\ DISCLAIMED.\ \ IN\ NO\ EVENT\ SHALL\ CARNEGIE\ MELLON\ UNIVERSITY}}
\DoxyCodeLine{00026\ \textcolor{comment}{\ *\ NOR\ ITS\ EMPLOYEES\ BE\ LIABLE\ FOR\ ANY\ DIRECT,\ INDIRECT,\ INCIDENTAL,}}
\DoxyCodeLine{00027\ \textcolor{comment}{\ *\ SPECIAL,\ EXEMPLARY,\ OR\ CONSEQUENTIAL\ DAMAGES\ (INCLUDING,\ BUT\ NOT\ }}
\DoxyCodeLine{00028\ \textcolor{comment}{\ *\ LIMITED\ TO,\ PROCUREMENT\ OF\ SUBSTITUTE\ GOODS\ OR\ SERVICES;\ LOSS\ OF\ USE,\ }}
\DoxyCodeLine{00029\ \textcolor{comment}{\ *\ DATA,\ OR\ PROFITS;\ OR\ BUSINESS\ INTERRUPTION)\ HOWEVER\ CAUSED\ AND\ ON\ ANY\ }}
\DoxyCodeLine{00030\ \textcolor{comment}{\ *\ THEORY\ OF\ LIABILITY,\ WHETHER\ IN\ CONTRACT,\ STRICT\ LIABILITY,\ OR\ TORT\ }}
\DoxyCodeLine{00031\ \textcolor{comment}{\ *\ (INCLUDING\ NEGLIGENCE\ OR\ OTHERWISE)\ ARISING\ IN\ ANY\ WAY\ OUT\ OF\ THE\ USE\ }}
\DoxyCodeLine{00032\ \textcolor{comment}{\ *\ OF\ THIS\ SOFTWARE,\ EVEN\ IF\ ADVISED\ OF\ THE\ POSSIBILITY\ OF\ SUCH\ DAMAGE.}}
\DoxyCodeLine{00033\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00034\ \textcolor{comment}{\ *\ ====================================================================}}
\DoxyCodeLine{00035\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00036\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00037\ \textcolor{comment}{/*}}
\DoxyCodeLine{00038\ \textcolor{comment}{\ *\ cont\_ad.c\ -\/-\/\ Continuous\ A/D\ listening\ and\ silence\ filtering\ module.}}
\DoxyCodeLine{00039\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00040\ \textcolor{comment}{\ *\ HISTORY}}
\DoxyCodeLine{00041\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00042\ \textcolor{comment}{\ *\ \$Log:\ cont\_ad\_base.c,v\ \$}}
\DoxyCodeLine{00043\ \textcolor{comment}{\ *\ Revision\ 1.14\ \ 2005/07/02\ 03:51:32\ \ rkm}}
\DoxyCodeLine{00044\ \textcolor{comment}{\ *\ Slowed\ down\ power\ histogram\ decay\ rate}}
\DoxyCodeLine{00045\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00046\ \textcolor{comment}{\ *\ Revision\ 1.13\ \ 2005/06/30\ 00:27:17\ \ rkm}}
\DoxyCodeLine{00047\ \textcolor{comment}{\ *\ Fixed\ silence\ handling\ in\ rawmode;\ added\ extra\ state\ variables}}
\DoxyCodeLine{00048\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00049\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00050\ \textcolor{comment}{\ *\ 28-\/Jun-\/2005\ \ M\ K\ Ravishankar\ (rkm@cs.cmu.edu)\ at\ Carnegie\ Mellon\ University.}}
\DoxyCodeLine{00051\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ -\/\ Changed\ rawmode\ handling\ to\ simply\ copy\ data\ even\ for\ silence}}
\DoxyCodeLine{00052\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ segments.}}
\DoxyCodeLine{00053\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ -\/\ Moved\ definitions\ of\ CONT\_AD\_STATE\_\{SIL,SPEECH\}\ from\ .c\ to\ .h.}}
\DoxyCodeLine{00054\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00055\ \textcolor{comment}{\ *\ Revision\ 1.12\ \ 2005/06/29\ 23:48:04\ \ egouvea}}
\DoxyCodeLine{00056\ \textcolor{comment}{\ *\ Revert\ changes:\ variables\ defined\ in\ cont\_ad\_base.c\ should\ not\ be\ accessible\ by\ the\ application}}
\DoxyCodeLine{00057\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00058\ \textcolor{comment}{\ *\ Revision\ 1.10\ \ 2005/02/13\ 01:29:48\ \ rkm}}
\DoxyCodeLine{00059\ \textcolor{comment}{\ *\ Fixed\ cont\_ad\_read\ to\ never\ cross\ sil/speech\ boundary,\ and\ rawmode}}
\DoxyCodeLine{00060\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00061\ \textcolor{comment}{\ *\ Revision\ 1.9\ \ 2005/02/01\ 22:21:19\ \ rkm}}
\DoxyCodeLine{00062\ \textcolor{comment}{\ *\ Added\ raw\ data\ logging,\ and\ raw\ data\ pass-\/through\ mode\ to\ cont\_ad}}
\DoxyCodeLine{00063\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00064\ \textcolor{comment}{\ *\ Revision\ 1.8\ \ 2004/07/23\ 23:36:34\ \ egouvea}}
\DoxyCodeLine{00065\ \textcolor{comment}{\ *\ Ravi's\ merge,\ with\ the\ latest\ fixes\ in\ the\ FSG\ code,\ and\ making\ the\ log\ files\ generated\ by\ FSG,\ LM,\ and\ allphone\ have\ the\ same\ 'look\ and\ feel',\ with\ the\ backtrace\ information\ presented\ consistently}}
\DoxyCodeLine{00066\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00067\ \textcolor{comment}{\ *\ 23-\/Jul-\/2004\ \ M\ K\ Ravishankar\ (rkm@cs.cmu.edu)\ at\ Carnegie\ Mellon\ University}}
\DoxyCodeLine{00068\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Changed\ default\ adapt\_rate\ from\ 0.5\ to\ 0.2.}}
\DoxyCodeLine{00069\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00070\ \textcolor{comment}{\ *\ Revision\ 1.7\ \ 2004/07/16\ 00:57:12\ \ egouvea}}
\DoxyCodeLine{00071\ \textcolor{comment}{\ *\ Added\ Ravi's\ implementation\ of\ FSG\ support.}}
\DoxyCodeLine{00072\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00073\ \textcolor{comment}{\ *\ Revision\ 1.2\ \ 2004/06/23\ 20:31:18\ \ rkm}}
\DoxyCodeLine{00074\ \textcolor{comment}{\ *\ Added\ adapt\_rate\ parameter;\ restructured\ frame\ processing\ to\ include\ threshold\ update}}
\DoxyCodeLine{00075\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00076\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00077\ \textcolor{comment}{\ *\ 23-\/Oct-\/98\ \ \ \ M\ K\ Ravishankar\ (rkm@cs.cmu.edu)\ at\ Carnegie\ Mellon\ University}}
\DoxyCodeLine{00078\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Small\ change\ in\ the\ way\ the\ noiselevel\ is\ updated\ in\ find\_thresh().}}
\DoxyCodeLine{00079\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00080\ \textcolor{comment}{\ *\ 26-\/Aug-\/98\ \ \ \ M\ K\ Ravishankar\ (rkm@cs.cmu.edu)\ at\ Carnegie\ Mellon\ University}}
\DoxyCodeLine{00081\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Separated\ computation\ of\ "{}frame\ power"{}\ into\ a\ separate\ low-\/level}}
\DoxyCodeLine{00082\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ function.}}
\DoxyCodeLine{00083\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00084\ \textcolor{comment}{\ *\ 13-\/Jul-\/98\ \ \ \ M\ K\ Ravishankar\ (rkm@cs.cmu.edu)\ at\ Carnegie\ Mellon\ University}}
\DoxyCodeLine{00085\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Modified\ to\ allow\ frame\ size\ to\ depend\ on\ audio\ sampling\ rate.}}
\DoxyCodeLine{00086\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00087\ \textcolor{comment}{\ *\ 01-\/Jul-\/98\ \ \ \ M\ K\ Ravishankar\ (rkm@cs.cmu.edu)\ at\ Carnegie\ Mellon\ University}}
\DoxyCodeLine{00088\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Changed\ CONT\_AD\_DELTA\_SPEECH\ back\ to\ 20.}}
\DoxyCodeLine{00089\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00090\ \textcolor{comment}{\ *\ 30-\/Jun-\/98\ \ \ \ M\ K\ Ravishankar\ (rkm@cs.cmu.edu)\ at\ Carnegie\ Mellon\ University}}
\DoxyCodeLine{00091\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Changed\ CONT\_AD\_DELTA\_SPEECH\ from\ 10\ to\ 15.}}
\DoxyCodeLine{00092\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Added\ FILE*\ argument\ to\ cont\_ad\_powhist\_dump().}}
\DoxyCodeLine{00093\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00094\ \textcolor{comment}{\ *\ 19-\/Jun-\/98\ \ \ \ M\ K\ Ravishankar\ (rkm@cs.cmu.edu)\ at\ Carnegie\ Mellon\ University}}
\DoxyCodeLine{00095\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Changed\ CONT\_AD\_DELTA\_SPEECH\ from\ 20\ to\ 10,\ to\ increase\ sensitivity}}
\DoxyCodeLine{00096\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ to\ very\ short\ utterances.}}
\DoxyCodeLine{00097\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00098\ \textcolor{comment}{\ *\ 16-\/Jan-\/98\ \ \ \ Paul\ Placeway\ (pwp@cs.cmu.edu)\ at\ Carnegie\ Mellon\ University}}
\DoxyCodeLine{00099\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Changed\ to\ use\ dB\ instead\ of\ the\ weird\ power\ measure.}}
\DoxyCodeLine{00100\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Changed\ analysis\ window\ size,\ tuned\ default\ settings\ of\ most}}
\DoxyCodeLine{00101\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ parameters\ to\ make\ the\ system\ less\ sensitive\ to\ noise,\ changed}}
\DoxyCodeLine{00102\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ the\ histogram\ update\ frequency\ and\ decay\ to\ make\ the\ system}}
\DoxyCodeLine{00103\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ adapt\ more\ rapidly\ to\ changes\ in\ the\ environment.}}
\DoxyCodeLine{00104\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Added\ cont\_ad\_set\_params()\ and\ cont\_ad\_get\_params().}}
\DoxyCodeLine{00105\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00106\ \textcolor{comment}{\ *\ 28-\/Jul-\/96\ \ \ \ M\ K\ Ravishankar\ (rkm@cs.cmu.edu)\ at\ Carnegie\ Mellon\ University}}
\DoxyCodeLine{00107\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Added\ FRMPOW2SIGLVL,\ max\_siglvl(),\ and\ cont\_ad\_t.siglvl.}}
\DoxyCodeLine{00108\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Changed\ min\ signal\ energy/frame\ to\ CONT\_AD\_SPF.}}
\DoxyCodeLine{00109\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00110\ \textcolor{comment}{\ *\ 27-\/Jun-\/96\ \ \ \ M\ K\ Ravishankar\ (rkm@cs.cmu.edu)\ at\ Carnegie\ Mellon\ University}}
\DoxyCodeLine{00111\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Added\ the\ option\ for\ cont\_ad\_read\ to\ return\ -\/1\ on\ EOF.}}
\DoxyCodeLine{00112\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00113\ \textcolor{comment}{\ *\ 21-\/Jun-\/96\ \ \ \ M\ K\ Ravishankar\ (rkm@cs.cmu.edu)\ at\ Carnegie\ Mellon\ University}}
\DoxyCodeLine{00114\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Added\ cont\_ad\_set\_thresh().}}
\DoxyCodeLine{00115\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Bugfix:\ n\_other\ is\ recomputed\ after\ updating\ thresholds.}}
\DoxyCodeLine{00116\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00117\ \textcolor{comment}{\ *\ 20-\/Jun-\/96\ \ \ \ M\ K\ Ravishankar\ (rkm@cs.cmu.edu)\ at\ Carnegie\ Mellon\ University}}
\DoxyCodeLine{00118\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Separated\ thresholds\ for\ speech\ and\ silence.}}
\DoxyCodeLine{00119\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Fixed\ bug\ in\ moving\ analysis\ window\ upon\ transition\ to\ speech\ state.}}
\DoxyCodeLine{00120\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00121\ \textcolor{comment}{\ *\ 17-\/Jun-\/96\ \ \ \ M\ K\ Ravishankar\ (rkm@cs.cmu.edu)\ at\ Carnegie\ Mellon\ University}}
\DoxyCodeLine{00122\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Created,\ based\ loosely\ on\ Steve\ Reed's\ original\ implementation.}}
\DoxyCodeLine{00123\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00124\ }
\DoxyCodeLine{00125\ \textcolor{comment}{/*}}
\DoxyCodeLine{00126\ \textcolor{comment}{\ *\ This\ module\ is\ intended\ to\ be\ interposed\ as\ a\ filter\ between\ any\ raw\ A/D\ source\ and\ the}}
\DoxyCodeLine{00127\ \textcolor{comment}{\ *\ application\ to\ remove\ silence\ regions.\ \ It\ is\ initialized\ with\ a\ raw\ A/D\ source\ function}}
\DoxyCodeLine{00128\ \textcolor{comment}{\ *\ (during\ the\ cont\_ad\_init\ call).\ \ Filtered\ A/D\ data\ can\ be\ read\ by\ the\ application\ using}}
\DoxyCodeLine{00129\ \textcolor{comment}{\ *\ the\ cont\_ad\_read\ function.\ \ This\ module\ assumes\ that\ the\ A/D\ source\ function\ supplies\ an}}
\DoxyCodeLine{00130\ \textcolor{comment}{\ *\ endless\ stream\ of\ data.\ \ The\ application\ is\ responsible\ for\ setting\ up\ the\ A/D\ source,}}
\DoxyCodeLine{00131\ \textcolor{comment}{\ *\ turning\ recording\ on\ and\ off\ as\ it\ desires.\ \ It\ is\ also\ responsible\ for\ invoking\ the}}
\DoxyCodeLine{00132\ \textcolor{comment}{\ *\ cont\_ad\_read\ function\ frequently\ enough\ to\ avoid\ buffer\ overruns\ and\ dropping\ A/D\ data.}}
\DoxyCodeLine{00133\ \textcolor{comment}{\ *\ This\ continuous\ listening\ module\ has\ an\ internal\ buffer\ of\ about\ 4\ sec.}}
\DoxyCodeLine{00134\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00135\ \textcolor{comment}{\ *\ This\ module\ must\ be\ initialized\ and\ calibrated\ at\ first\ (cont\_ad\_init\ and\ cont\_ad\_calib}}
\DoxyCodeLine{00136\ \textcolor{comment}{\ *\ functions).\ \ Raw\ samples\ are\ grouped\ into\ frames,\ the\ signal\ power\ in\ each\ frame\ is}}
\DoxyCodeLine{00137\ \textcolor{comment}{\ *\ computed\ and\ accumulated\ in\ a\ histogram.\ \ The\ module\ is\ always\ in\ one\ of\ two\ states:}}
\DoxyCodeLine{00138\ \textcolor{comment}{\ *\ SILENCE\ or\ SPEECH.\ \ Transitions\ between\ the\ two\ states\ are\ detected\ by\ looking\ for\ a}}
\DoxyCodeLine{00139\ \textcolor{comment}{\ *\ contiguous\ window\ of\ several\ frames\ that\ is\ predominantly\ of\ the\ other\ type.\ \ The\ type}}
\DoxyCodeLine{00140\ \textcolor{comment}{\ *\ is\ determined\ by\ comparing\ frame\ power\ to\ either\ of\ two\ thresholds,\ thresh\_sil\ and}}
\DoxyCodeLine{00141\ \textcolor{comment}{\ *\ thresh\_speech,\ as\ appropriate\ for\ the\ current\ state.\ \ These\ thresholds\ are\ set\ from\ the}}
\DoxyCodeLine{00142\ \textcolor{comment}{\ *\ first\ peak\ in\ the\ low-\/end\ of\ the\ power\ histogram,\ and\ are\ updated\ every\ few\ seconds.}}
\DoxyCodeLine{00143\ \textcolor{comment}{\ *\ Separate\ thresholds\ are\ used\ to\ provide\ some\ hysteresis.}}
\DoxyCodeLine{00144\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00145\ \textcolor{comment}{\ *\ The\ module\ maintains\ a\ linked\ list\ of\ speech\ (non-\/silence)\ segments\ not\ yet\ read\ by\ the}}
\DoxyCodeLine{00146\ \textcolor{comment}{\ *\ application.\ \ The\ cont\_ad\_read\ function\ returns\ speech\ data,\ if\ any\ available,\ by}}
\DoxyCodeLine{00147\ \textcolor{comment}{\ *\ following\ this\ list.\ \ It\ also\ updates\ an\ "{}absolute"{}\ timestamp\ at\ the\ end\ of\ the}}
\DoxyCodeLine{00148\ \textcolor{comment}{\ *\ cont\_ad\_read\ operation.\ \ The\ timestamp\ indicates\ the\ total\ \#samples\ of\ A/D\ data\ read}}
\DoxyCodeLine{00149\ \textcolor{comment}{\ *\ until\ this\ point,\ including\ data\ discarded\ as\ silence\ frames.\ \ The\ application\ is}}
\DoxyCodeLine{00150\ \textcolor{comment}{\ *\ responsible\ for\ using\ this\ timestamp\ to\ make\ any\ policy\ decisions\ regarding\ utterance}}
\DoxyCodeLine{00151\ \textcolor{comment}{\ *\ boundaries\ or\ whatever.}}
\DoxyCodeLine{00152\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00153\ }
\DoxyCodeLine{00154\ \textcolor{preprocessor}{\#include\ <stdio.h>}}
\DoxyCodeLine{00155\ \textcolor{preprocessor}{\#include\ <stdlib.h>}}
\DoxyCodeLine{00156\ \textcolor{preprocessor}{\#include\ <string.h>}}
\DoxyCodeLine{00157\ \textcolor{preprocessor}{\#include\ <assert.h>}}
\DoxyCodeLine{00158\ \textcolor{preprocessor}{\#include\ <math.h>}}
\DoxyCodeLine{00159\ }
\DoxyCodeLine{00160\ \textcolor{preprocessor}{\#ifdef\ HAVE\_CONFIG\_H}}
\DoxyCodeLine{00161\ \textcolor{preprocessor}{\#include\ <config.h>}}
\DoxyCodeLine{00162\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00163\ }
\DoxyCodeLine{00164\ \textcolor{preprocessor}{\#ifdef\ \_MSC\_VER}}
\DoxyCodeLine{00165\ \textcolor{preprocessor}{\#pragma\ warning\ (disable:\ 4305)}}
\DoxyCodeLine{00166\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00167\ }
\DoxyCodeLine{00168\ \textcolor{preprocessor}{\#include\ "{}sphinxbase/prim\_type.h"{}}}
\DoxyCodeLine{00169\ \textcolor{preprocessor}{\#include\ "{}sphinxbase/ad.h"{}}}
\DoxyCodeLine{00170\ \textcolor{preprocessor}{\#include\ "{}sphinxbase/cont\_ad.h"{}}}
\DoxyCodeLine{00171\ \textcolor{preprocessor}{\#include\ "{}sphinxbase/err.h"{}}}
\DoxyCodeLine{00172\ }
\DoxyCodeLine{00173\ }
\DoxyCodeLine{00174\ \textcolor{preprocessor}{\#ifndef\ \_ABS}}
\DoxyCodeLine{00175\ \textcolor{preprocessor}{\#define\ \_ABS(x)\ ((x)\ >=\ 0\ ?\ (x)\ :\ -\/(x))}}
\DoxyCodeLine{00176\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00177\ }
\DoxyCodeLine{00178\ }
\DoxyCodeLine{00179\ \textcolor{comment}{/*\ Various\ parameters,\ including\ defaults\ for\ many\ cont\_ad\_t\ member\ variables\ */}}
\DoxyCodeLine{00180\ }
\DoxyCodeLine{00181\ \textcolor{preprocessor}{\#define\ CONT\_AD\_ADFRMSIZE\ \ \ \ \ \ \ 256\ \ \ \ \ }\textcolor{comment}{/*\ \#Frames\ of\ internal\ A/D\ buffer\ maintained\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00182\ }
\DoxyCodeLine{00183\ \textcolor{preprocessor}{\#define\ CONT\_AD\_POWHISTSIZE\ \ \ \ \ 98\ \ \ \ \ \ }\textcolor{comment}{/*\ \#Powhist\ bins:\ \string~\ FRMPOW(65536\string^2*CONT\_AD\_SPF)\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00184\ \textcolor{comment}{/*\ Maximum\ level\ is\ 96.3\ dB\ full-\/scale;\ 97\ for\ safety,\ plus\ 1\ for\ zero-\/based\ */}}
\DoxyCodeLine{00185\ }
\DoxyCodeLine{00186\ \textcolor{preprocessor}{\#define\ CONT\_AD\_CALIB\_FRAMES\ \ \ \ (CONT\_AD\_POWHISTSIZE\ *\ 2)}}
\DoxyCodeLine{00187\ }
\DoxyCodeLine{00188\ \textcolor{preprocessor}{\#define\ CONT\_AD\_THRESH\_UPDATE\ \ \ 100\ \ \ \ \ }\textcolor{comment}{/*\ Update\ thresholds\ approx\ every\ so\ many\ frames\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00189\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ PWP:\ update\ was\ 200\ frames,\ or\ 3.2\ seconds.\ \ Now\ about\ every\ 1.6\ sec.\ */}}
\DoxyCodeLine{00190\ }
\DoxyCodeLine{00191\ \textcolor{preprocessor}{\#define\ CONT\_AD\_ADAPT\_RATE\ \ \ \ \ \ 0.2\ \ \ \ \ }\textcolor{comment}{/*\ Interpolation\ of\ new\ and\ old\ noiselevel\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00192\ }
\DoxyCodeLine{00193\ \textcolor{preprocessor}{\#define\ CONT\_AD\_SPS\ \ \ \ \ \ \ \ \ \ \ \ \ 16000}}
\DoxyCodeLine{00194\ }
\DoxyCodeLine{00195\ \textcolor{preprocessor}{\#define\ CONT\_AD\_DEFAULT\_NOISE\ \ \ 30\ \ \ \ \ \ }\textcolor{comment}{/*\ Default\ background\ noise\ power\ level\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00196\ \textcolor{preprocessor}{\#define\ CONT\_AD\_DELTA\_SIL\ \ \ \ \ \ \ 10\ \ \ \ \ \ }\textcolor{comment}{/*\ Initial\ default\ for\ cont\_ad\_t.delta\_sil\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00197\ \textcolor{preprocessor}{\#define\ CONT\_AD\_DELTA\_SPEECH\ \ \ \ 17\ \ \ \ \ \ }\textcolor{comment}{/*\ Initial\ default\ for\ cont\_ad\_t.delta\_speech\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00198\ \textcolor{preprocessor}{\#define\ CONT\_AD\_MIN\_NOISE\ \ \ \ \ \ \ 2\ \ \ \ \ \ \ }\textcolor{comment}{/*\ Expected\ minimum\ background\ noise\ level\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00199\ \textcolor{preprocessor}{\#define\ CONT\_AD\_MAX\_NOISE\ \ \ \ \ \ \ 70\ \ \ \ \ \ }\textcolor{comment}{/*\ Maximum\ background\ noise\ level\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00200\ }
\DoxyCodeLine{00201\ \textcolor{preprocessor}{\#define\ CONT\_AD\_HIST\_INERTIA\ \ \ \ 3\ \ \ \ \ \ \ }\textcolor{comment}{/*\ Used\ in\ decaying\ the\ power\ histogram\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00202\ }
\DoxyCodeLine{00203\ \textcolor{preprocessor}{\#define\ CONT\_AD\_WINSIZE\ \ \ \ \ \ \ \ \ 21\ \ \ \ \ \ }\textcolor{comment}{/*\ Analysis\ window\ for\ state\ transitions\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00204\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ rkm\ had\ 16\ */}}
\DoxyCodeLine{00205\ }
\DoxyCodeLine{00206\ \textcolor{preprocessor}{\#define\ CONT\_AD\_SPEECH\_ONSET\ \ \ \ 9\ \ \ \ \ \ \ }\textcolor{comment}{/*\ Min\ \#speech\ frames\ in\ analysis\ window\ for}}
\DoxyCodeLine{00207\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ SILENCE\ -\/>\ SPEECH\ state\ transition\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00208\ \textcolor{comment}{/*}}
\DoxyCodeLine{00209\ \textcolor{comment}{\ *\ SReed\ had\ 100\ ms\ ==\ 6.25\ fr\ contiguous;\ rkm\ had\ 9\ (out\ of\ 16+10)\ with\ a}}
\DoxyCodeLine{00210\ \textcolor{comment}{\ *\ lower\ threshold.}}
\DoxyCodeLine{00211\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00212\ }
\DoxyCodeLine{00213\ \textcolor{preprocessor}{\#define\ CONT\_AD\_SIL\_ONSET\ \ \ \ \ \ \ 18\ \ \ \ \ \ }\textcolor{comment}{/*\ Min\ \#silence\ frames\ in\ analysis\ window\ for}}
\DoxyCodeLine{00214\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ SPEECH\ -\/>\ SILENCE\ state\ transition}}
\DoxyCodeLine{00215\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ MUST\ BE\ <=\ CONT\_AD\_WINSIZE\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00216\ \textcolor{comment}{/*}}
\DoxyCodeLine{00217\ \textcolor{comment}{\ *\ SReed\ had\ 400\ ms\ ==\ 25\ fr\ contiguous;\ rkm\ had\ 14\ out\ of\ 16}}
\DoxyCodeLine{00218\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00219\ }
\DoxyCodeLine{00220\ \textcolor{preprocessor}{\#define\ CONT\_AD\_LEADER\ \ \ \ \ \ \ \ \ \ 5\ \ \ \ \ \ \ }\textcolor{comment}{/*\ On\ transition\ to\ SPEECH\ state,\ so\ many\ frames}}
\DoxyCodeLine{00221\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ BEFORE\ window\ included\ in\ speech\ data\ (>0)\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00222\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ SReed\ had\ 200\ ms\ ==\ 12.5\ fr;\ rkm\ had\ 5\ */}}
\DoxyCodeLine{00223\ }
\DoxyCodeLine{00224\ \textcolor{preprocessor}{\#define\ CONT\_AD\_TRAILER\ \ \ \ \ \ \ \ \ 10\ \ \ \ \ \ }\textcolor{comment}{/*\ On\ transition\ to\ SILENCE\ state,\ so\ many\ frames}}
\DoxyCodeLine{00225\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ of\ silence\ included\ in\ speech\ data\ (>0).}}
\DoxyCodeLine{00226\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ NOTE:\ Ensure\ (0\ <\ TRAILER+LEADER\ <=\ WINSIZE)\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00227\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ SReed\ had\ 100\ ms\ ==\ 6.25\ fr;\ rkm\ had\ 10\ */}}
\DoxyCodeLine{00228\ }
\DoxyCodeLine{00229\ }
\DoxyCodeLine{00230\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00231\ cont\_ad\_powhist\_dump(FILE\ *\ fp,\ cont\_ad\_t\ *\ r)}
\DoxyCodeLine{00232\ \{}
\DoxyCodeLine{00233\ \ \ \ \ int32\ i,\ j;}
\DoxyCodeLine{00234\ }
\DoxyCodeLine{00235\ \ \ \ \ fprintf(fp,\ \textcolor{stringliteral}{"{}PowHist:\(\backslash\)n"{}});}
\DoxyCodeLine{00236\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0,\ j\ =\ 0;\ i\ <\ CONT\_AD\_POWHISTSIZE;\ i++)\ \{}
\DoxyCodeLine{00237\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>pow\_hist[i]\ >\ 0)\ \{}
\DoxyCodeLine{00238\ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(fp,\ \textcolor{stringliteral}{"{}\(\backslash\)t\%3d\ \%6d\(\backslash\)n"{}},\ i,\ r-\/>pow\_hist[i]);}
\DoxyCodeLine{00239\ \ \ \ \ \ \ \ \ \ \ \ \ j\ =\ i;}
\DoxyCodeLine{00240\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00241\ \ \ \ \ \}}
\DoxyCodeLine{00242\ }
\DoxyCodeLine{00243\ \ \ \ \ fprintf(fp,\ \textcolor{stringliteral}{"{}PH[\%7.2f]:"{}},}
\DoxyCodeLine{00244\ \ \ \ \ \ \ \ \ \ \ \ \ (\textcolor{keywordtype}{double})\ (r-\/>tot\_frm\ *\ r-\/>spf)\ /\ (\textcolor{keywordtype}{double})\ (r-\/>sps));}
\DoxyCodeLine{00245\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <=\ j;\ i++)}
\DoxyCodeLine{00246\ \ \ \ \ \ \ \ \ fprintf(fp,\ \textcolor{stringliteral}{"{}\ \%2d"{}},\ r-\/>pow\_hist[i]);}
\DoxyCodeLine{00247\ \ \ \ \ fprintf(fp,\ \textcolor{stringliteral}{"{}\(\backslash\)n"{}});}
\DoxyCodeLine{00248\ }
\DoxyCodeLine{00249\ \ \ \ \ fflush(fp);}
\DoxyCodeLine{00250\ \}}
\DoxyCodeLine{00251\ }
\DoxyCodeLine{00252\ }
\DoxyCodeLine{00253\ \textcolor{comment}{/*}}
\DoxyCodeLine{00254\ \textcolor{comment}{\ *\ Compute\ frame\ power.\ \ Interface\ deliberately\ kept\ low\ level\ to\ allow\ arbitrary}}
\DoxyCodeLine{00255\ \textcolor{comment}{\ *\ users\ to\ call\ this\ function\ with\ appropriate\ data.}}
\DoxyCodeLine{00256\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00257\ int32}
\DoxyCodeLine{00258\ cont\_ad\_frame\_pow(int16\ *\ buf,\ int32\ *\ prev,\ int32\ spf)}
\DoxyCodeLine{00259\ \{}
\DoxyCodeLine{00260\ \ \ \ \ \textcolor{keywordtype}{double}\ sumsq,\ v;}
\DoxyCodeLine{00261\ \ \ \ \ int32\ i;}
\DoxyCodeLine{00262\ \ \ \ \ int32\ p;}
\DoxyCodeLine{00263\ }
\DoxyCodeLine{00264\ \ \ \ \ sumsq\ =\ 0.0;}
\DoxyCodeLine{00265\ \ \ \ \ p\ =\ *prev;}
\DoxyCodeLine{00266\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ spf;\ i++)\ \{}
\DoxyCodeLine{00267\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Note:\ pre-\/emphasis\ done\ to\ remove\ low-\/frequency\ noise.\ */}}
\DoxyCodeLine{00268\ \ \ \ \ \ \ \ \ v\ =\ (double)\ (buf[i]\ -\/\ p);}
\DoxyCodeLine{00269\ \ \ \ \ \ \ \ \ sumsq\ +=\ v\ *\ v;}
\DoxyCodeLine{00270\ \ \ \ \ \ \ \ \ p\ =\ buf[i];}
\DoxyCodeLine{00271\ \ \ \ \ \}}
\DoxyCodeLine{00272\ \ \ \ \ *prev\ =\ p;}
\DoxyCodeLine{00273\ }
\DoxyCodeLine{00274\ \ \ \ \ \textcolor{keywordflow}{if}\ (sumsq\ <\ spf)\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Make\ sure\ FRMPOW(sumsq)\ >=\ 0\ */}}
\DoxyCodeLine{00275\ \ \ \ \ \ \ \ \ sumsq\ =\ spf;}
\DoxyCodeLine{00276\ }
\DoxyCodeLine{00277\ \ \ \ \ \textcolor{comment}{/*}}
\DoxyCodeLine{00278\ \textcolor{comment}{\ \ \ \ \ *\ PWP:\ Units\ changed\ to\ dB}}
\DoxyCodeLine{00279\ \textcolor{comment}{\ \ \ \ \ *}}
\DoxyCodeLine{00280\ \textcolor{comment}{\ \ \ \ \ *\ Now\ the\ units\ of\ measurement\ of\ an\ input\ sample\ are\ volts\ (really!),}}
\DoxyCodeLine{00281\ \textcolor{comment}{\ \ \ \ \ *\ so\ the\ power\ in\ dB\ is\ p\ =\ 20*log10(samp).\ \ Further,\ we\ want\ the\ RMS}}
\DoxyCodeLine{00282\ \textcolor{comment}{\ \ \ \ \ *\ (root-\/mean-\/squared)\ average\ power\ across\ the\ frame.}}
\DoxyCodeLine{00283\ \textcolor{comment}{\ \ \ \ \ *}}
\DoxyCodeLine{00284\ \textcolor{comment}{\ \ \ \ \ *\ "{}sumsq"{}\ is\ the\ sum\ of\ the\ sum\ of\ the\ squares,\ so\ we\ want}}
\DoxyCodeLine{00285\ \textcolor{comment}{\ \ \ \ \ *}}
\DoxyCodeLine{00286\ \textcolor{comment}{\ \ \ \ \ *\ \ \ i\ =\ 20\ *\ log10(\ sqrt\ (\ sumsq\ /\ n\_samps)\ )}}
\DoxyCodeLine{00287\ \textcolor{comment}{\ \ \ \ \ *}}
\DoxyCodeLine{00288\ \textcolor{comment}{\ \ \ \ \ *\ (Stephen\ Reed's\ code\ actually\ had\ }}
\DoxyCodeLine{00289\ \textcolor{comment}{\ \ \ \ \ *\ \ \ \ i\ =\ 20\ *\ log10(\ sqrt\ (sumsq)\ /\ n\_samps\ )}}
\DoxyCodeLine{00290\ \textcolor{comment}{\ \ \ \ \ *\ \ but\ this\ only\ produced\ an\ additive\ error.)}}
\DoxyCodeLine{00291\ \textcolor{comment}{\ \ \ \ \ *}}
\DoxyCodeLine{00292\ \textcolor{comment}{\ \ \ \ \ *\ i\ =\ 20\ *\ log10(\ sqrt\ (\ sumsq\ /\ n\_samps)\ )}}
\DoxyCodeLine{00293\ \textcolor{comment}{\ \ \ \ \ *\ \ \ =\ 20\ *\ log10(\ (\ sumsq\ /\ n\_samps)\ \string^\ 0.5\ )}}
\DoxyCodeLine{00294\ \textcolor{comment}{\ \ \ \ \ *\ \ \ =\ 20\ *\ log10(\ (\ sumsq\ /\ n\_samps)\ )\ *\ 0.5\ )}}
\DoxyCodeLine{00295\ \textcolor{comment}{\ \ \ \ \ *\ \ \ =\ 10\ *\ log10(\ (\ sumsq\ /\ n\_samps)\ )}}
\DoxyCodeLine{00296\ \textcolor{comment}{\ \ \ \ \ *\ \ \ =\ 10\ *\ (\ log10(\ sumsq)\ -\/\ log10(n\_samps)\ )}}
\DoxyCodeLine{00297\ \textcolor{comment}{\ \ \ \ \ */}}
\DoxyCodeLine{00298\ \ \ \ \ i\ =\ (int32)\ ((10.0\ *\ (log10(sumsq)\ -\/\ log10((\textcolor{keywordtype}{double})\ spf)))\ +\ 0.5);}
\DoxyCodeLine{00299\ \ \ \ \ \textcolor{keywordflow}{if}\ (i\ <\ 0)}
\DoxyCodeLine{00300\ \ \ \ \ \ \ \ \ i\ =\ 0;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ trim\ lower\ bound\ again\ to\ be\ safe.\ */}}
\DoxyCodeLine{00301\ \ \ \ \ assert(i\ <\ 97);}
\DoxyCodeLine{00302\ }
\DoxyCodeLine{00303\ \ \ \ \ \textcolor{keywordflow}{return}\ (i);}
\DoxyCodeLine{00304\ \}}
\DoxyCodeLine{00305\ }
\DoxyCodeLine{00306\ }
\DoxyCodeLine{00307\ \textcolor{comment}{/*}}
\DoxyCodeLine{00308\ \textcolor{comment}{\ *\ Classify\ frame\ (id=frm,\ starting\ at\ sample\ position\ s)\ as\ sil/nonsil.\ \ Classification}}
\DoxyCodeLine{00309\ \textcolor{comment}{\ *\ done\ in\ isolation,\ independent\ of\ any\ other\ frame,\ based\ only\ on\ power\ histogram.}}
\DoxyCodeLine{00310\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00311\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00312\ compute\_frame\_pow(cont\_ad\_t\ *\ r,\ int32\ frm)}
\DoxyCodeLine{00313\ \{}
\DoxyCodeLine{00314\ \ \ \ \ int32\ i;}
\DoxyCodeLine{00315\ }
\DoxyCodeLine{00316\ \ \ \ \ i\ =\ cont\_ad\_frame\_pow(r-\/>adbuf\ +\ (frm\ *\ r-\/>spf),\ \&(r-\/>prev\_sample),}
\DoxyCodeLine{00317\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>spf);}
\DoxyCodeLine{00318\ }
\DoxyCodeLine{00319\ \ \ \ \ r-\/>frm\_pow[frm]\ =\ (char)\ i;}
\DoxyCodeLine{00320\ \ \ \ \ (r-\/>pow\_hist[i])++;}
\DoxyCodeLine{00321\ \ \ \ \ r-\/>thresh\_update-\/-\/;}
\DoxyCodeLine{00322\ \}}
\DoxyCodeLine{00323\ }
\DoxyCodeLine{00324\ }
\DoxyCodeLine{00325\ \textcolor{comment}{/*\ PWP:\ \$\$\$\ check\ this\ */}}
\DoxyCodeLine{00326\ \textcolor{comment}{/*}}
\DoxyCodeLine{00327\ \textcolor{comment}{\ *\ PWP:\ in\ SReed's\ code,\ decay\ was\ done\ by\ zeroing\ the\ histogram,}}
\DoxyCodeLine{00328\ \textcolor{comment}{\ *\ i.e.\ no\ history.}}
\DoxyCodeLine{00329\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00330\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00331\ decay\_hist(cont\_ad\_t\ *\ r)}
\DoxyCodeLine{00332\ \{}
\DoxyCodeLine{00333\ \ \ \ \ int32\ i;}
\DoxyCodeLine{00334\ }
\DoxyCodeLine{00335\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ CONT\_AD\_POWHISTSIZE;\ i++)}
\DoxyCodeLine{00336\ \ \ \ \ \ \ \ \ r-\/>pow\_hist[i]\ -\/=\ (r-\/>pow\_hist[i]\ >>\ CONT\_AD\_HIST\_INERTIA);}
\DoxyCodeLine{00337\ \}}
\DoxyCodeLine{00338\ }
\DoxyCodeLine{00339\ }
\DoxyCodeLine{00340\ \textcolor{comment}{/*}}
\DoxyCodeLine{00341\ \textcolor{comment}{\ *\ Find\ silence\ threshold\ from\ power\ histogram.}}
\DoxyCodeLine{00342\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00343\ \textcolor{keyword}{static}\ int32}
\DoxyCodeLine{00344\ find\_thresh(cont\_ad\_t\ *\ r)}
\DoxyCodeLine{00345\ \{}
\DoxyCodeLine{00346\ \ \ \ \ int32\ i,\ j,\ max,\ th;}
\DoxyCodeLine{00347\ \ \ \ \ int32\ old\_noise\_level,\ old\_thresh\_sil,\ old\_thresh\_speech;}
\DoxyCodeLine{00348\ }
\DoxyCodeLine{00349\ \ \ \ \ \textcolor{keywordflow}{if}\ (!r-\/>auto\_thresh)}
\DoxyCodeLine{00350\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00351\ }
\DoxyCodeLine{00352\ \ \ \ \ \textcolor{comment}{/*}}
\DoxyCodeLine{00353\ \textcolor{comment}{\ \ \ \ \ *\ Find\ smallest\ non-\/zero\ histogram\ entry,\ but\ starting\ at\ some\ minimum\ power.}}
\DoxyCodeLine{00354\ \textcolor{comment}{\ \ \ \ \ *\ Power\ lower\ than\ CONT\_AD\_MIN\_NOISE\ indicates\ bad\ A/D\ input\ (eg,\ mic\ off...).}}
\DoxyCodeLine{00355\ \textcolor{comment}{\ \ \ \ \ *\ Too\ high\ a\ minimum\ power\ is\ also\ bad.}}
\DoxyCodeLine{00356\ \textcolor{comment}{\ \ \ \ \ */}}
\DoxyCodeLine{00357\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ r-\/>min\_noise;}
\DoxyCodeLine{00358\ \ \ \ \ \ \ \ \ \ (i\ <\ CONT\_AD\_POWHISTSIZE)\ \&\&\ (r-\/>pow\_hist[i]\ ==\ 0);\ i++);}
\DoxyCodeLine{00359\ \ \ \ \ \textcolor{keywordflow}{if}\ (i\ >\ r-\/>max\_noise)\ \ \ \ \ \ \ \textcolor{comment}{/*\ Bad\ signal?\ */}}
\DoxyCodeLine{00360\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00361\ }
\DoxyCodeLine{00362\ \ \ \ \ \textcolor{comment}{/*\ PWP:\ Hmmmmm....\ SReed's\ code\ looks\ over\ the\ lower\ 20\ dB\ */}}
\DoxyCodeLine{00363\ \ \ \ \ \textcolor{comment}{/*\ PWP:\ 1/14/98\ \ Made\ to\ work\ like\ Stephen\ Reed's\ code\ */}}
\DoxyCodeLine{00364\ }
\DoxyCodeLine{00365\ \ \ \ \ \textcolor{comment}{/*\ This\ method\ of\ detecting\ the\ noise\ level\ is\ VERY\ unsatisfactory\ */}}
\DoxyCodeLine{00366\ \ \ \ \ max\ =\ 0;}
\DoxyCodeLine{00367\ \ \ \ \ \textcolor{keywordflow}{for}\ (j\ =\ i,\ th\ =\ i;\ (j\ <\ CONT\_AD\_POWHISTSIZE)\ \&\&\ (j\ <\ i\ +\ 20);\ j++)\ \{\ \ \ \ \ \ \ \textcolor{comment}{/*\ PWP:\ was\ i+6,\ which\ was\ 9\ dB\ */}}
\DoxyCodeLine{00368\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (max\ <\ r-\/>pow\_hist[j])\ \{}
\DoxyCodeLine{00369\ \ \ \ \ \ \ \ \ \ \ \ \ max\ =\ r-\/>pow\_hist[j];}
\DoxyCodeLine{00370\ \ \ \ \ \ \ \ \ \ \ \ \ th\ =\ j;}
\DoxyCodeLine{00371\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00372\ \ \ \ \ \}}
\DoxyCodeLine{00373\ }
\DoxyCodeLine{00374\ \ \ \ \ \textcolor{comment}{/*\ "{}Don't\ change\ the\ threshold\ too\ fast"{}\ */}}
\DoxyCodeLine{00375\ \ \ \ \ old\_noise\_level\ =\ r-\/>noise\_level;}
\DoxyCodeLine{00376\ \ \ \ \ old\_thresh\_sil\ =\ r-\/>thresh\_sil;}
\DoxyCodeLine{00377\ \ \ \ \ old\_thresh\_speech\ =\ r-\/>thresh\_speech;}
\DoxyCodeLine{00378\ \ \ \ \ \textcolor{comment}{/*\ r-\/>noise\_level\ =\ (int32)\ (th\ *\ r-\/>adapt\_rate\ +\ r-\/>noise\_level\ *\ (1.0\ -\/\ r-\/>adapt\_rate));\ */}}
\DoxyCodeLine{00379\ \ \ \ \ r-\/>noise\_level\ =}
\DoxyCodeLine{00380\ \ \ \ \ \ \ \ \ (int32)\ (r-\/>noise\_level\ +}
\DoxyCodeLine{00381\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>adapt\_rate\ *\ (th\ -\/\ r-\/>noise\_level)\ +\ 0.5);}
\DoxyCodeLine{00382\ }
\DoxyCodeLine{00383\ \ \ \ \ \textcolor{comment}{/*\ update\ thresholds\ */}}
\DoxyCodeLine{00384\ \ \ \ \ r-\/>thresh\_sil\ =\ r-\/>noise\_level\ +\ r-\/>delta\_sil;}
\DoxyCodeLine{00385\ \ \ \ \ r-\/>thresh\_speech\ =\ r-\/>noise\_level\ +\ r-\/>delta\_speech;}
\DoxyCodeLine{00386\ }
\DoxyCodeLine{00387\ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>logfp)\ \{}
\DoxyCodeLine{00388\ \ \ \ \ \ \ \ \ fprintf(r-\/>logfp,}
\DoxyCodeLine{00389\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}\%7.2fs\ \%8df:\ NoisePeak:\ \%d,\ Noiselevel:\ \%d\ -\/>\ \%d,\ Th-\/Sil:\ \%d\ -\/>\ \%d,\ Th-\/Sp:\ \%d\ -\/>\ \%d\(\backslash\)n"{}},}
\DoxyCodeLine{00390\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (\textcolor{keywordtype}{double})\ (r-\/>tot\_frm\ *\ r-\/>spf)\ /\ (\textcolor{keywordtype}{double})\ (r-\/>sps),}
\DoxyCodeLine{00391\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>tot\_frm,\ th,\ old\_noise\_level,\ r-\/>noise\_level,}
\DoxyCodeLine{00392\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ old\_thresh\_sil,\ r-\/>thresh\_sil,\ old\_thresh\_speech,}
\DoxyCodeLine{00393\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>thresh\_speech);}
\DoxyCodeLine{00394\ }
\DoxyCodeLine{00395\ \ \ \ \ \ \ \ \ cont\_ad\_powhist\_dump(r-\/>logfp,\ r);}
\DoxyCodeLine{00396\ }
\DoxyCodeLine{00397\ \ \ \ \ \ \ \ \ fflush(r-\/>logfp);}
\DoxyCodeLine{00398\ \ \ \ \ \}}
\DoxyCodeLine{00399\ }
\DoxyCodeLine{00400\ \ \ \ \ \textcolor{comment}{/*}}
\DoxyCodeLine{00401\ \textcolor{comment}{\ \ \ \ \ *\ PWP:\ in\ SReed's\ original,\ he\ cleared\ the\ histogram\ here.}}
\DoxyCodeLine{00402\ \textcolor{comment}{\ \ \ \ \ *\ I\ can't\ fathom\ why.}}
\DoxyCodeLine{00403\ \textcolor{comment}{\ \ \ \ \ */}}
\DoxyCodeLine{00404\ }
\DoxyCodeLine{00405\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00406\ \}}
\DoxyCodeLine{00407\ }
\DoxyCodeLine{00408\ }
\DoxyCodeLine{00409\ \textcolor{comment}{/*}}
\DoxyCodeLine{00410\ \textcolor{comment}{\ *\ Silence\ to\ speech\ transition}}
\DoxyCodeLine{00411\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00412\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00413\ sil2speech\_transition(cont\_ad\_t\ *r,\ \textcolor{keywordtype}{int}\ frm)}
\DoxyCodeLine{00414\ \{}
\DoxyCodeLine{00415\ \ \ \ \ spseg\_t\ *seg;}
\DoxyCodeLine{00416\ }
\DoxyCodeLine{00417\ \ \ \ \ \textcolor{comment}{/*\ Speech\ detected;\ create\ speech\ segment\ description\ */}}
\DoxyCodeLine{00418\ \ \ \ \ seg\ =\ malloc(\textcolor{keyword}{sizeof}(*seg));}
\DoxyCodeLine{00419\ }
\DoxyCodeLine{00420\ \ \ \ \ seg-\/>startfrm\ =\ r-\/>win\_startfrm\ -\/\ r-\/>leader;}
\DoxyCodeLine{00421\ \ \ \ \ \textcolor{keywordflow}{if}\ (seg-\/>startfrm\ <\ 0)}
\DoxyCodeLine{00422\ \ \ \ \ \ \ \ \ seg-\/>startfrm\ +=\ CONT\_AD\_ADFRMSIZE;}
\DoxyCodeLine{00423\ \ \ \ \ seg-\/>nfrm\ =\ r-\/>leader\ +\ r-\/>winsize;}
\DoxyCodeLine{00424\ \ \ \ \ seg-\/>next\ =\ NULL;}
\DoxyCodeLine{00425\ }
\DoxyCodeLine{00426\ \ \ \ \ \textcolor{keywordflow}{if}\ (!r-\/>spseg\_head)}
\DoxyCodeLine{00427\ \ \ \ \ \ \ \ \ r-\/>spseg\_head\ =\ seg;}
\DoxyCodeLine{00428\ \ \ \ \ \textcolor{keywordflow}{else}}
\DoxyCodeLine{00429\ \ \ \ \ \ \ \ \ r-\/>spseg\_tail-\/>next\ =\ seg;}
\DoxyCodeLine{00430\ \ \ \ \ r-\/>spseg\_tail\ =\ seg;}
\DoxyCodeLine{00431\ }
\DoxyCodeLine{00432\ \ \ \ \ r-\/>tail\_state\ =\ CONT\_AD\_STATE\_SPEECH;}
\DoxyCodeLine{00433\ }
\DoxyCodeLine{00434\ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>logfp)\ \{}
\DoxyCodeLine{00435\ \ \ \ \ \ \ \ \ int32\ n;}
\DoxyCodeLine{00436\ }
\DoxyCodeLine{00437\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Where\ (in\ absolute\ time)\ this\ speech\ segment\ starts\ */}}
\DoxyCodeLine{00438\ \ \ \ \ \ \ \ \ n\ =\ frm\ -\/\ seg-\/>startfrm;}
\DoxyCodeLine{00439\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (n\ <\ 0)}
\DoxyCodeLine{00440\ \ \ \ \ \ \ \ \ \ \ \ \ n\ +=\ CONT\_AD\_ADFRMSIZE;}
\DoxyCodeLine{00441\ \ \ \ \ \ \ \ \ n\ =\ r-\/>tot\_frm\ -\/\ n\ -\/\ 1;}
\DoxyCodeLine{00442\ }
\DoxyCodeLine{00443\ \ \ \ \ \ \ \ \ fprintf(r-\/>logfp,}
\DoxyCodeLine{00444\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}\%7.2fs\ \%8d[\%3d]f:\ Sil\ -\/>\ Sp\ detect;\ seg\ start:\ \%7.2fs\ \%8d\(\backslash\)n"{}},}
\DoxyCodeLine{00445\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (\textcolor{keywordtype}{double})\ (r-\/>tot\_frm\ *}
\DoxyCodeLine{00446\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>spf)\ /}
\DoxyCodeLine{00447\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (\textcolor{keywordtype}{double})\ (r-\/>sps),}
\DoxyCodeLine{00448\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>tot\_frm,\ frm,}
\DoxyCodeLine{00449\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (\textcolor{keywordtype}{double})\ (n\ *\ r-\/>spf)\ /\ (\textcolor{keywordtype}{double})\ (r-\/>sps),\ n);}
\DoxyCodeLine{00450\ \ \ \ \ \}}
\DoxyCodeLine{00451\ }
\DoxyCodeLine{00452\ \ \ \ \ \textcolor{comment}{/*\ Now\ in\ SPEECH\ state;\ want\ to\ look\ for\ silence\ from\ end\ of\ this\ window\ */}}
\DoxyCodeLine{00453\ \ \ \ \ r-\/>win\_validfrm\ =\ 1;}
\DoxyCodeLine{00454\ \ \ \ \ r-\/>win\_startfrm\ =\ frm;}
\DoxyCodeLine{00455\ }
\DoxyCodeLine{00456\ \ \ \ \ \textcolor{comment}{/*\ Count\ \#sil\ frames\ remaining\ in\ reduced\ window\ (of\ 1\ frame)\ */}}
\DoxyCodeLine{00457\ \ \ \ \ r-\/>n\_other\ =\ (r-\/>frm\_pow[frm]\ <=\ r-\/>thresh\_sil)\ ?\ 1\ :\ 0;}
\DoxyCodeLine{00458\ \}}
\DoxyCodeLine{00459\ }
\DoxyCodeLine{00460\ \textcolor{comment}{/*}}
\DoxyCodeLine{00461\ \textcolor{comment}{\ *\ Speech\ to\ silence\ transition}}
\DoxyCodeLine{00462\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00463\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00464\ speech2sil\_transition(cont\_ad\_t\ *r,\ \textcolor{keywordtype}{int}\ frm)}
\DoxyCodeLine{00465\ \{}
\DoxyCodeLine{00466\ \ \ \ \ \textcolor{keywordtype}{int}\ f;}
\DoxyCodeLine{00467\ }
\DoxyCodeLine{00468\ \ \ \ \ \textcolor{comment}{/*\ End\ of\ speech\ detected;\ speech-\/>sil\ transition\ */}}
\DoxyCodeLine{00469\ \ \ \ \ r-\/>spseg\_tail-\/>nfrm\ +=\ r-\/>trailer;}
\DoxyCodeLine{00470\ }
\DoxyCodeLine{00471\ \ \ \ \ r-\/>tail\_state\ =\ CONT\_AD\_STATE\_SIL;}
\DoxyCodeLine{00472\ }
\DoxyCodeLine{00473\ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>logfp)\ \{}
\DoxyCodeLine{00474\ \ \ \ \ \ \ \ \ int32\ n;}
\DoxyCodeLine{00475\ }
\DoxyCodeLine{00476\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Where\ (in\ absolute\ time)\ this\ speech\ segment\ ends\ */}}
\DoxyCodeLine{00477\ \ \ \ \ \ \ \ \ n\ =\ r-\/>spseg\_tail-\/>startfrm\ +\ r-\/>spseg\_tail-\/>nfrm\ -\/\ 1;}
\DoxyCodeLine{00478\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (n\ >=\ CONT\_AD\_ADFRMSIZE)}
\DoxyCodeLine{00479\ \ \ \ \ \ \ \ \ \ \ \ \ n\ -\/=\ CONT\_AD\_ADFRMSIZE;}
\DoxyCodeLine{00480\ \ \ \ \ \ \ \ \ n\ =\ frm\ -\/\ n;}
\DoxyCodeLine{00481\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (n\ <\ 0)}
\DoxyCodeLine{00482\ \ \ \ \ \ \ \ \ \ \ \ \ n\ +=\ CONT\_AD\_ADFRMSIZE;}
\DoxyCodeLine{00483\ \ \ \ \ \ \ \ \ n\ =\ r-\/>tot\_frm\ -\/\ n;}
\DoxyCodeLine{00484\ }
\DoxyCodeLine{00485\ \ \ \ \ \ \ \ \ fprintf(r-\/>logfp,}
\DoxyCodeLine{00486\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}\%7.2fs\ \%8d[\%3d]f:\ Sp\ -\/>\ Sil\ detect;\ seg\ end:\ \%7.2fs\ \%8d\(\backslash\)n"{}},}
\DoxyCodeLine{00487\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (\textcolor{keywordtype}{double})\ (r-\/>tot\_frm\ *\ r-\/>spf)\ /}
\DoxyCodeLine{00488\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (\textcolor{keywordtype}{double})\ (r-\/>sps),\ r-\/>tot\_frm,\ frm,}
\DoxyCodeLine{00489\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (\textcolor{keywordtype}{double})\ (n\ *\ r-\/>spf)\ /\ (\textcolor{keywordtype}{double})\ (r-\/>sps),\ n);}
\DoxyCodeLine{00490\ \ \ \ \ \}}
\DoxyCodeLine{00491\ }
\DoxyCodeLine{00492\ \ \ \ \ \textcolor{comment}{/*\ Now\ in\ SILENCE\ state;\ start\ looking\ for\ speech\ trailer+leader\ frames\ later\ */}}
\DoxyCodeLine{00493\ \ \ \ \ r-\/>win\_validfrm\ -\/=\ (r-\/>trailer\ +\ r-\/>leader\ -\/\ 1);}
\DoxyCodeLine{00494\ \ \ \ \ r-\/>win\_startfrm\ +=\ (r-\/>trailer\ +\ r-\/>leader\ -\/\ 1);}
\DoxyCodeLine{00495\ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>win\_startfrm\ >=\ CONT\_AD\_ADFRMSIZE)}
\DoxyCodeLine{00496\ \ \ \ \ \ \ \ \ r-\/>win\_startfrm\ -\/=\ CONT\_AD\_ADFRMSIZE;}
\DoxyCodeLine{00497\ }
\DoxyCodeLine{00498\ \ \ \ \ \textcolor{comment}{/*\ Count\ \#speech\ frames\ remaining\ in\ reduced\ window\ */}}
\DoxyCodeLine{00499\ \ \ \ \ r-\/>n\_other\ =\ 0;}
\DoxyCodeLine{00500\ \ \ \ \ \textcolor{keywordflow}{for}\ (f\ =\ r-\/>win\_startfrm;;)\ \{}
\DoxyCodeLine{00501\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>frm\_pow[f]\ >=\ r-\/>thresh\_speech)}
\DoxyCodeLine{00502\ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>n\_other++;}
\DoxyCodeLine{00503\ }
\DoxyCodeLine{00504\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (f\ ==\ frm)}
\DoxyCodeLine{00505\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00506\ }
\DoxyCodeLine{00507\ \ \ \ \ \ \ \ \ f++;}
\DoxyCodeLine{00508\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (f\ >=\ CONT\_AD\_ADFRMSIZE)}
\DoxyCodeLine{00509\ \ \ \ \ \ \ \ \ \ \ \ \ f\ =\ 0;}
\DoxyCodeLine{00510\ \ \ \ \ \}}
\DoxyCodeLine{00511\ \}}
\DoxyCodeLine{00512\ }
\DoxyCodeLine{00513\ }
\DoxyCodeLine{00514\ \textcolor{comment}{/*}}
\DoxyCodeLine{00515\ \textcolor{comment}{\ *\ Main\ silence/speech\ region\ detection\ routine.\ \ If\ currently\ in}}
\DoxyCodeLine{00516\ \textcolor{comment}{\ *\ SILENCE\ state,\ switch\ to\ SPEECH\ state\ if\ a\ window\ (r-\/>winsize)}}
\DoxyCodeLine{00517\ \textcolor{comment}{\ *\ of\ frames\ is\ mostly\ non-\/silence.\ \ If\ in\ SPEECH\ state,\ switch\ to}}
\DoxyCodeLine{00518\ \textcolor{comment}{\ *\ SILENCE\ state\ if\ the\ window\ is\ mostly\ silence.}}
\DoxyCodeLine{00519\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00520\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00521\ boundary\_detect(cont\_ad\_t\ *\ r,\ int32\ frm)}
\DoxyCodeLine{00522\ \{}
\DoxyCodeLine{00523\ \ \ \ \ assert(r-\/>n\_other\ >=\ 0);}
\DoxyCodeLine{00524\ }
\DoxyCodeLine{00525\ \ \ \ \ r-\/>win\_validfrm++;}
\DoxyCodeLine{00526\ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>tail\_state\ ==\ CONT\_AD\_STATE\_SIL)\ \{}
\DoxyCodeLine{00527\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>frm\_pow[frm]\ >=\ r-\/>thresh\_speech)}
\DoxyCodeLine{00528\ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>n\_other++;}
\DoxyCodeLine{00529\ \ \ \ \ \}}
\DoxyCodeLine{00530\ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00531\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>frm\_pow[frm]\ <=\ r-\/>thresh\_sil)}
\DoxyCodeLine{00532\ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>n\_other++;}
\DoxyCodeLine{00533\ \ \ \ \ \}}
\DoxyCodeLine{00534\ }
\DoxyCodeLine{00535\ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>logfp)\ \{}
\DoxyCodeLine{00536\ \ \ \ \ \ \ \ \ fprintf(r-\/>logfp,}
\DoxyCodeLine{00537\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}\%7.2fs\ \%8d[\%3d]f:\ P:\ \%2d,\ N:\ \%2d,\ T+:\ \%2d,\ T-\/:\ \%2d,\ \#O:\ \%2d,\ \%s\(\backslash\)n"{}},}
\DoxyCodeLine{00538\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (\textcolor{keywordtype}{double})\ (r-\/>tot\_frm\ *\ r-\/>spf)\ /\ (\textcolor{keywordtype}{double})\ (r-\/>sps),}
\DoxyCodeLine{00539\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>tot\_frm,\ frm,\ r-\/>frm\_pow[frm],\ r-\/>noise\_level,}
\DoxyCodeLine{00540\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>thresh\_speech,\ r-\/>thresh\_sil,\ r-\/>n\_other,}
\DoxyCodeLine{00541\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (r-\/>tail\_state\ ==\ CONT\_AD\_STATE\_SIL)\ ?\ \textcolor{stringliteral}{"{}-\/-\/"{}}\ :\ \textcolor{stringliteral}{"{}Sp"{}});}
\DoxyCodeLine{00542\ \ \ \ \ \}}
\DoxyCodeLine{00543\ }
\DoxyCodeLine{00544\ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>win\_validfrm\ <\ r-\/>winsize)\ \ \ \textcolor{comment}{/*\ Not\ reached\ full\ analysis\ window\ size\ */}}
\DoxyCodeLine{00545\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return};}
\DoxyCodeLine{00546\ \ \ \ \ assert(r-\/>win\_validfrm\ ==\ r-\/>winsize);}
\DoxyCodeLine{00547\ }
\DoxyCodeLine{00548\ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>tail\_state\ ==\ CONT\_AD\_STATE\_SIL)\ \{\ \ \ \textcolor{comment}{/*\ Currently\ in\ SILENCE\ state\ */}}
\DoxyCodeLine{00549\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>n\_frm\ >=\ r-\/>winsize\ +\ r-\/>leader}
\DoxyCodeLine{00550\ \ \ \ \ \ \ \ \ \ \ \ \ \&\&\ r-\/>n\_other\ >=\ r-\/>speech\_onset)\ \{}
\DoxyCodeLine{00551\ \ \ \ \ \ \ \ \ \ \ \ \ sil2speech\_transition(r,\ frm);}
\DoxyCodeLine{00552\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00553\ \ \ \ \ \}}
\DoxyCodeLine{00554\ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00555\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>n\_other\ >=\ r-\/>sil\_onset)\ \{}
\DoxyCodeLine{00556\ \ \ \ \ \ \ \ \ \ \ \ \ speech2sil\_transition(r,\ frm);}
\DoxyCodeLine{00557\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00558\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00559\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ In\ speech\ state,\ and\ staying\ there;\ add\ this\ frame\ to\ segment\ */}}
\DoxyCodeLine{00560\ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>spseg\_tail-\/>nfrm++;}
\DoxyCodeLine{00561\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00562\ \ \ \ \ \}}
\DoxyCodeLine{00563\ }
\DoxyCodeLine{00564\ \ \ \ \ \textcolor{comment}{/*}}
\DoxyCodeLine{00565\ \textcolor{comment}{\ \ \ \ \ *\ Get\ rid\ of\ oldest\ frame\ in\ analysis\ window.\ \ Not\ quite\ correct;}}
\DoxyCodeLine{00566\ \textcolor{comment}{\ \ \ \ \ *\ thresholds\ could\ have\ changed\ over\ the\ window;\ should\ preserve}}
\DoxyCodeLine{00567\ \textcolor{comment}{\ \ \ \ \ *\ the\ original\ speech/silence\ label\ for\ the\ frame\ and\ undo\ it.\ \ Later..}}
\DoxyCodeLine{00568\ \textcolor{comment}{\ \ \ \ \ */}}
\DoxyCodeLine{00569\ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>tail\_state\ ==\ CONT\_AD\_STATE\_SIL)\ \{}
\DoxyCodeLine{00570\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>frm\_pow[r-\/>win\_startfrm]\ >=\ r-\/>thresh\_speech)\ \{}
\DoxyCodeLine{00571\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>n\_other\ >\ 0)}
\DoxyCodeLine{00572\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>n\_other-\/-\/;}
\DoxyCodeLine{00573\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00574\ \ \ \ \ \}}
\DoxyCodeLine{00575\ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00576\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>frm\_pow[r-\/>win\_startfrm]\ <=\ r-\/>thresh\_sil)\ \{}
\DoxyCodeLine{00577\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>n\_other\ >\ 0)}
\DoxyCodeLine{00578\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>n\_other-\/-\/;}
\DoxyCodeLine{00579\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00580\ \ \ \ \ \}}
\DoxyCodeLine{00581\ \ \ \ \ r-\/>win\_validfrm-\/-\/;}
\DoxyCodeLine{00582\ \ \ \ \ r-\/>win\_startfrm++;}
\DoxyCodeLine{00583\ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>win\_startfrm\ >=\ CONT\_AD\_ADFRMSIZE)}
\DoxyCodeLine{00584\ \ \ \ \ \ \ \ \ r-\/>win\_startfrm\ =\ 0;}
\DoxyCodeLine{00585\ }
\DoxyCodeLine{00586\ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>logfp)}
\DoxyCodeLine{00587\ \ \ \ \ \ \ \ \ fflush(r-\/>logfp);}
\DoxyCodeLine{00588\ \}}
\DoxyCodeLine{00589\ }
\DoxyCodeLine{00590\ }
\DoxyCodeLine{00591\ \textcolor{keyword}{static}\ int32}
\DoxyCodeLine{00592\ max\_siglvl(cont\_ad\_t\ *\ r,\ int32\ startfrm,\ int32\ nfrm)}
\DoxyCodeLine{00593\ \{}
\DoxyCodeLine{00594\ \ \ \ \ int32\ siglvl,\ i,\ f;}
\DoxyCodeLine{00595\ }
\DoxyCodeLine{00596\ \ \ \ \ siglvl\ =\ 0;}
\DoxyCodeLine{00597\ \ \ \ \ \textcolor{keywordflow}{if}\ (nfrm\ >\ 0)\ \{}
\DoxyCodeLine{00598\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0,\ f\ =\ startfrm;\ i\ <\ nfrm;\ i++,\ f++)\ \{}
\DoxyCodeLine{00599\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (f\ >=\ CONT\_AD\_ADFRMSIZE)}
\DoxyCodeLine{00600\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ f\ -\/=\ CONT\_AD\_ADFRMSIZE;}
\DoxyCodeLine{00601\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>frm\_pow[f]\ >\ siglvl)}
\DoxyCodeLine{00602\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ siglvl\ =\ r-\/>frm\_pow[f];}
\DoxyCodeLine{00603\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00604\ \ \ \ \ \}}
\DoxyCodeLine{00605\ \ \ \ \ \textcolor{keywordflow}{return}\ siglvl;}
\DoxyCodeLine{00606\ \}}
\DoxyCodeLine{00607\ }
\DoxyCodeLine{00608\ }
\DoxyCodeLine{00609\ \textcolor{preprocessor}{\#if\ 0}}
\DoxyCodeLine{00610\ \textcolor{comment}{/*}}
\DoxyCodeLine{00611\ \textcolor{comment}{\ *\ RKM(2005/01/31):\ Where\ did\ this\ come\ from?\ \ If\ needed,\ it\ should\ be\ called}}
\DoxyCodeLine{00612\ \textcolor{comment}{\ *\ cont\_ad\_get\_audio\_data.}}
\DoxyCodeLine{00613\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00614\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00615\ get\_audio\_data(cont\_ad\_t\ *\ r,\ int16\ *\ buf,\ int32\ max)}
\DoxyCodeLine{00616\ \{}
\DoxyCodeLine{00617\ \}}
\DoxyCodeLine{00618\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00619\ }
\DoxyCodeLine{00620\ }
\DoxyCodeLine{00621\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00622\ cont\_ad\_read\_log(cont\_ad\_t\ *\ r,\ int32\ retval)}
\DoxyCodeLine{00623\ \{}
\DoxyCodeLine{00624\ \ \ \ \ spseg\_t\ *seg;}
\DoxyCodeLine{00625\ }
\DoxyCodeLine{00626\ \ \ \ \ fprintf(r-\/>logfp,\ \textcolor{stringliteral}{"{}return\ from\ cont\_ad\_read()\ -\/>\ \%d:\(\backslash\)n"{}},\ retval);}
\DoxyCodeLine{00627\ \ \ \ \ fprintf(r-\/>logfp,\ \textcolor{stringliteral}{"{}\(\backslash\)tstate:\ \%d\(\backslash\)n"{}},\ r-\/>state);}
\DoxyCodeLine{00628\ \ \ \ \ fprintf(r-\/>logfp,\ \textcolor{stringliteral}{"{}\(\backslash\)tread\_ts:\ \%d\ (\%.2fs)\(\backslash\)n"{}},}
\DoxyCodeLine{00629\ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>read\_ts,\ (float32)\ r-\/>read\_ts\ /\ (float32)\ r-\/>sps);}
\DoxyCodeLine{00630\ \ \ \ \ fprintf(r-\/>logfp,\ \textcolor{stringliteral}{"{}\(\backslash\)tseglen:\ \%d\ (\%.2fs)\(\backslash\)n"{}},}
\DoxyCodeLine{00631\ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>seglen,\ (float32)\ r-\/>seglen\ /\ (float32)\ r-\/>sps);}
\DoxyCodeLine{00632\ \ \ \ \ fprintf(r-\/>logfp,\ \textcolor{stringliteral}{"{}\(\backslash\)tsiglvl:\ \%d\(\backslash\)n"{}},\ r-\/>siglvl);}
\DoxyCodeLine{00633\ \ \ \ \ fprintf(r-\/>logfp,\ \textcolor{stringliteral}{"{}\(\backslash\)theadfrm:\ \%d\(\backslash\)n"{}},\ r-\/>headfrm);}
\DoxyCodeLine{00634\ \ \ \ \ fprintf(r-\/>logfp,\ \textcolor{stringliteral}{"{}\(\backslash\)tn\_frm:\ \%d\(\backslash\)n"{}},\ r-\/>n\_frm);}
\DoxyCodeLine{00635\ \ \ \ \ fprintf(r-\/>logfp,\ \textcolor{stringliteral}{"{}\(\backslash\)tn\_sample:\ \%d\(\backslash\)n"{}},\ r-\/>n\_sample);}
\DoxyCodeLine{00636\ \ \ \ \ fprintf(r-\/>logfp,\ \textcolor{stringliteral}{"{}\(\backslash\)twin\_startfrm:\ \%d\(\backslash\)n"{}},\ r-\/>win\_startfrm);}
\DoxyCodeLine{00637\ \ \ \ \ fprintf(r-\/>logfp,\ \textcolor{stringliteral}{"{}\(\backslash\)twin\_validfrm:\ \%d\(\backslash\)n"{}},\ r-\/>win\_validfrm);}
\DoxyCodeLine{00638\ \ \ \ \ fprintf(r-\/>logfp,\ \textcolor{stringliteral}{"{}\(\backslash\)tnoise\_level:\ \%d\(\backslash\)n"{}},\ r-\/>noise\_level);}
\DoxyCodeLine{00639\ \ \ \ \ fprintf(r-\/>logfp,\ \textcolor{stringliteral}{"{}\(\backslash\)tthresh\_sil:\ \%d\(\backslash\)n"{}},\ r-\/>thresh\_sil);}
\DoxyCodeLine{00640\ \ \ \ \ fprintf(r-\/>logfp,\ \textcolor{stringliteral}{"{}\(\backslash\)tthresh\_speech:\ \%d\(\backslash\)n"{}},\ r-\/>thresh\_speech);}
\DoxyCodeLine{00641\ \ \ \ \ fprintf(r-\/>logfp,\ \textcolor{stringliteral}{"{}\(\backslash\)tn\_other:\ \%d\(\backslash\)n"{}},\ r-\/>n\_other);}
\DoxyCodeLine{00642\ \ \ \ \ fprintf(r-\/>logfp,\ \textcolor{stringliteral}{"{}\(\backslash\)ttail\_state:\ \%d\(\backslash\)n"{}},\ r-\/>tail\_state);}
\DoxyCodeLine{00643\ \ \ \ \ fprintf(r-\/>logfp,\ \textcolor{stringliteral}{"{}\(\backslash\)ttot\_frm:\ \%d\(\backslash\)n"{}},\ r-\/>tot\_frm);}
\DoxyCodeLine{00644\ }
\DoxyCodeLine{00645\ \ \ \ \ fprintf(r-\/>logfp,\ \textcolor{stringliteral}{"{}\(\backslash\)tspseg:"{}});}
\DoxyCodeLine{00646\ \ \ \ \ \textcolor{keywordflow}{for}\ (seg\ =\ r-\/>spseg\_head;\ seg;\ seg\ =\ seg-\/>next)}
\DoxyCodeLine{00647\ \ \ \ \ \ \ \ \ fprintf(r-\/>logfp,\ \textcolor{stringliteral}{"{}\ \%d[\%d]"{}},\ seg-\/>startfrm,\ seg-\/>nfrm);}
\DoxyCodeLine{00648\ \ \ \ \ fprintf(r-\/>logfp,\ \textcolor{stringliteral}{"{}\(\backslash\)n"{}});}
\DoxyCodeLine{00649\ }
\DoxyCodeLine{00650\ \ \ \ \ fflush(r-\/>logfp);}
\DoxyCodeLine{00651\ \}}
\DoxyCodeLine{00652\ }
\DoxyCodeLine{00653\ }
\DoxyCodeLine{00654\ \textcolor{comment}{/*}}
\DoxyCodeLine{00655\ \textcolor{comment}{\ *\ Copy\ data\ from\ r-\/>adbuf[sf],\ for\ nf\ frames,\ into\ buf.}}
\DoxyCodeLine{00656\ \textcolor{comment}{\ *\ All\ length\ checks\ must\ have\ been\ completed\ before\ this\ call;\ hence,\ this}}
\DoxyCodeLine{00657\ \textcolor{comment}{\ *\ function\ will\ copy\ exactly\ the\ specified\ number\ of\ frames.}}
\DoxyCodeLine{00658\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00659\ \textcolor{comment}{\ *\ Return\ value:\ Index\ of\ frame\ just\ after\ the\ segment\ copied,\ possibly\ wrapped}}
\DoxyCodeLine{00660\ \textcolor{comment}{\ *\ around\ to\ 0.}}
\DoxyCodeLine{00661\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00662\ \textcolor{keyword}{static}\ int32}
\DoxyCodeLine{00663\ buf\_copy(cont\_ad\_t\ *\ r,\ int32\ sf,\ int32\ nf,\ int16\ *\ buf)}
\DoxyCodeLine{00664\ \{}
\DoxyCodeLine{00665\ \ \ \ \ int32\ f,\ l;}
\DoxyCodeLine{00666\ }
\DoxyCodeLine{00667\ \ \ \ \ assert((sf\ >=\ 0)\ \&\&\ (sf\ <\ CONT\_AD\_ADFRMSIZE));}
\DoxyCodeLine{00668\ \ \ \ \ assert(nf\ >=\ 0);}
\DoxyCodeLine{00669\ }
\DoxyCodeLine{00670\ \ \ \ \ \textcolor{keywordflow}{if}\ (sf\ +\ nf\ >\ CONT\_AD\_ADFRMSIZE)\ \{}
\DoxyCodeLine{00671\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Amount\ to\ be\ copied\ wraps\ around\ adbuf;\ copy\ in\ two\ stages\ */}}
\DoxyCodeLine{00672\ \ \ \ \ \ \ \ \ f\ =\ CONT\_AD\_ADFRMSIZE\ -\/\ sf;}
\DoxyCodeLine{00673\ \ \ \ \ \ \ \ \ l\ =\ (f\ *\ r-\/>spf);}
\DoxyCodeLine{00674\ \ \ \ \ \ \ \ \ memcpy(buf,\ r-\/>adbuf\ +\ (sf\ *\ r-\/>spf),\ l\ *\ \textcolor{keyword}{sizeof}(int16));}
\DoxyCodeLine{00675\ }
\DoxyCodeLine{00676\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>logfp)\ \{}
\DoxyCodeLine{00677\ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(r-\/>logfp,}
\DoxyCodeLine{00678\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}return\ \%d\ speech\ frames\ [\%d..\%d];\ \%d\ samples\(\backslash\)n"{}},}
\DoxyCodeLine{00679\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ f,\ sf,\ sf\ +\ f\ -\/\ 1,\ l);}
\DoxyCodeLine{00680\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00681\ }
\DoxyCodeLine{00682\ \ \ \ \ \ \ \ \ buf\ +=\ l;}
\DoxyCodeLine{00683\ \ \ \ \ \ \ \ \ sf\ =\ 0;}
\DoxyCodeLine{00684\ \ \ \ \ \ \ \ \ nf\ -\/=\ f;}
\DoxyCodeLine{00685\ \ \ \ \ \}}
\DoxyCodeLine{00686\ }
\DoxyCodeLine{00687\ \ \ \ \ \textcolor{keywordflow}{if}\ (nf\ >\ 0)\ \{}
\DoxyCodeLine{00688\ \ \ \ \ \ \ \ \ l\ =\ (nf\ *\ r-\/>spf);}
\DoxyCodeLine{00689\ \ \ \ \ \ \ \ \ memcpy(buf,\ r-\/>adbuf\ +\ (sf\ *\ r-\/>spf),\ l\ *\ \textcolor{keyword}{sizeof}(int16));}
\DoxyCodeLine{00690\ }
\DoxyCodeLine{00691\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>logfp)\ \{}
\DoxyCodeLine{00692\ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(r-\/>logfp,}
\DoxyCodeLine{00693\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}return\ \%d\ speech\ frames\ [\%d..\%d];\ \%d\ samples\(\backslash\)n"{}},}
\DoxyCodeLine{00694\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ nf,\ sf,\ sf\ +\ nf\ -\/\ 1,\ l);}
\DoxyCodeLine{00695\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00696\ \ \ \ \ \}}
\DoxyCodeLine{00697\ }
\DoxyCodeLine{00698\ \ \ \ \ \textcolor{keywordflow}{if}\ ((sf\ +\ nf)\ >=\ CONT\_AD\_ADFRMSIZE)\ \{}
\DoxyCodeLine{00699\ \ \ \ \ \ \ \ \ assert((sf\ +\ nf)\ ==\ CONT\_AD\_ADFRMSIZE);}
\DoxyCodeLine{00700\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00701\ \ \ \ \ \}}
\DoxyCodeLine{00702\ \ \ \ \ \textcolor{keywordflow}{else}}
\DoxyCodeLine{00703\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ (sf\ +\ nf);}
\DoxyCodeLine{00704\ \}}
\DoxyCodeLine{00705\ }
\DoxyCodeLine{00706\ int32}
\DoxyCodeLine{00707\ cont\_ad\_buffer\_space(cont\_ad\_t\ *r)}
\DoxyCodeLine{00708\ \{}
\DoxyCodeLine{00709\ \ \ \ \ \textcolor{keywordflow}{return}\ r-\/>adbufsize\ -\/\ r-\/>n\_sample;}
\DoxyCodeLine{00710\ \}}
\DoxyCodeLine{00711\ }
\DoxyCodeLine{00712\ \textcolor{comment}{/*}}
\DoxyCodeLine{00713\ \textcolor{comment}{\ *\ Read\ as\ much\ data\ as\ possible\ from\ r-\/>adfunc\ into\ r-\/>adbuf.}}
\DoxyCodeLine{00714\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00715\ \textcolor{keyword}{static}\ int32}
\DoxyCodeLine{00716\ cont\_ad\_read\_internal(cont\_ad\_t\ *r,\ int16\ *buf,\ int32\ max)}
\DoxyCodeLine{00717\ \{}
\DoxyCodeLine{00718\ \ \ \ \ int32\ head,\ tail,\ len,\ l;}
\DoxyCodeLine{00719\ }
\DoxyCodeLine{00720\ \ \ \ \ \textcolor{comment}{/*}}
\DoxyCodeLine{00721\ \textcolor{comment}{\ \ \ \ \ *\ First\ read\ as\ much\ of\ raw\ A/D\ as\ possible\ and\ available.\ \ adbuf\ is\ not}}
\DoxyCodeLine{00722\ \textcolor{comment}{\ \ \ \ \ *\ really\ a\ circular\ buffer,\ so\ may\ have\ to\ read\ in\ two\ steps\ for\ wrapping}}
\DoxyCodeLine{00723\ \textcolor{comment}{\ \ \ \ \ *\ around.}}
\DoxyCodeLine{00724\ \textcolor{comment}{\ \ \ \ \ */}}
\DoxyCodeLine{00725\ \ \ \ \ head\ =\ r-\/>headfrm\ *\ r-\/>spf;}
\DoxyCodeLine{00726\ \ \ \ \ tail\ =\ head\ +\ r-\/>n\_sample;}
\DoxyCodeLine{00727\ \ \ \ \ len\ =\ r-\/>n\_sample\ -\/\ (r-\/>n\_frm\ *\ r-\/>spf);\ \ \ \ \textcolor{comment}{/*\ \#partial\ frame\ samples\ at\ the\ tail\ */}}
\DoxyCodeLine{00728\ \ \ \ \ assert((len\ >=\ 0)\ \&\&\ (len\ <\ r-\/>spf));}
\DoxyCodeLine{00729\ }
\DoxyCodeLine{00730\ \ \ \ \ \textcolor{keywordflow}{if}\ ((tail\ <\ r-\/>adbufsize)\ \&\&\ (!r-\/>eof))\ \{}
\DoxyCodeLine{00731\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>adfunc)\ \{}
\DoxyCodeLine{00732\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((l\ =}
\DoxyCodeLine{00733\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (*(r-\/>adfunc))\ (r-\/>ad,\ r-\/>adbuf\ +\ tail,}
\DoxyCodeLine{00734\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>adbufsize\ -\/\ tail))\ <\ 0)\ \{}
\DoxyCodeLine{00735\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>eof\ =\ 1;}
\DoxyCodeLine{00736\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ l\ =\ 0;}
\DoxyCodeLine{00737\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00738\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00739\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00740\ \ \ \ \ \ \ \ \ \ \ \ \ l\ =\ r-\/>adbufsize\ -\/\ tail;}
\DoxyCodeLine{00741\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (l\ >\ max)\ \{}
\DoxyCodeLine{00742\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ l\ =\ max;}
\DoxyCodeLine{00743\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ max\ =\ 0;}
\DoxyCodeLine{00744\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00745\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00746\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ max\ -\/=\ l;}
\DoxyCodeLine{00747\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00748\ \ \ \ \ \ \ \ \ \ \ \ \ memcpy(r-\/>adbuf\ +\ tail,\ buf,\ l\ *\ \textcolor{keyword}{sizeof}(int16));}
\DoxyCodeLine{00749\ \ \ \ \ \ \ \ \ \ \ \ \ buf\ +=\ l;}
\DoxyCodeLine{00750\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00751\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((l\ >\ 0)\ \&\&\ r-\/>rawfp)\ \{}
\DoxyCodeLine{00752\ \ \ \ \ \ \ \ \ \ \ \ \ fwrite(r-\/>adbuf\ +\ tail,\ \textcolor{keyword}{sizeof}(int16),\ l,\ r-\/>rawfp);}
\DoxyCodeLine{00753\ \ \ \ \ \ \ \ \ \ \ \ \ fflush(r-\/>rawfp);}
\DoxyCodeLine{00754\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00755\ }
\DoxyCodeLine{00756\ \ \ \ \ \ \ \ \ tail\ +=\ l;}
\DoxyCodeLine{00757\ \ \ \ \ \ \ \ \ len\ +=\ l;}
\DoxyCodeLine{00758\ \ \ \ \ \ \ \ \ r-\/>n\_sample\ +=\ l;}
\DoxyCodeLine{00759\ \ \ \ \ \}}
\DoxyCodeLine{00760\ \ \ \ \ \textcolor{keywordflow}{if}\ ((tail\ >=\ r-\/>adbufsize)\ \&\&\ (!r-\/>eof))\ \{}
\DoxyCodeLine{00761\ \ \ \ \ \ \ \ \ tail\ -\/=\ r-\/>adbufsize;}
\DoxyCodeLine{00762\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (tail\ <\ head)\ \{}
\DoxyCodeLine{00763\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>adfunc)\ \{}
\DoxyCodeLine{00764\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((l\ =}
\DoxyCodeLine{00765\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (*(r-\/>adfunc))\ (r-\/>ad,}
\DoxyCodeLine{00766\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>adbuf\ +\ tail,\ head\ -\/\ tail))\ <\ 0)\ \{}
\DoxyCodeLine{00767\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>eof\ =\ 1;}
\DoxyCodeLine{00768\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ l\ =\ 0;}
\DoxyCodeLine{00769\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00770\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00771\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00772\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ l\ =\ head\ -\/\ tail;}
\DoxyCodeLine{00773\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (l\ >\ max)}
\DoxyCodeLine{00774\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ l\ =\ max;}
\DoxyCodeLine{00775\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ memcpy(r-\/>adbuf\ +\ tail,\ buf,\ l\ *\ \textcolor{keyword}{sizeof}(int16));}
\DoxyCodeLine{00776\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00777\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((l\ >\ 0)\ \&\&\ r-\/>rawfp)\ \{}
\DoxyCodeLine{00778\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ fwrite(r-\/>adbuf\ +\ tail,\ \textcolor{keyword}{sizeof}(int16),\ l,\ r-\/>rawfp);}
\DoxyCodeLine{00779\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ fflush(r-\/>rawfp);}
\DoxyCodeLine{00780\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00781\ }
\DoxyCodeLine{00782\ \ \ \ \ \ \ \ \ \ \ \ \ tail\ +=\ l;}
\DoxyCodeLine{00783\ \ \ \ \ \ \ \ \ \ \ \ \ len\ +=\ l;}
\DoxyCodeLine{00784\ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>n\_sample\ +=\ l;}
\DoxyCodeLine{00785\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00786\ \ \ \ \ \}}
\DoxyCodeLine{00787\ }
\DoxyCodeLine{00788\ \ \ \ \ \textcolor{keywordflow}{return}\ len;}
\DoxyCodeLine{00789\ \}}
\DoxyCodeLine{00790\ }
\DoxyCodeLine{00791\ \textcolor{comment}{/*}}
\DoxyCodeLine{00792\ \textcolor{comment}{\ *\ Classify\ incoming\ frames\ as\ silence\ or\ speech.}}
\DoxyCodeLine{00793\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00794\ int32}
\DoxyCodeLine{00795\ cont\_ad\_classify(cont\_ad\_t\ *r,\ int32\ len)}
\DoxyCodeLine{00796\ \{}
\DoxyCodeLine{00797\ \ \ \ \ int32\ tailfrm;}
\DoxyCodeLine{00798\ }
\DoxyCodeLine{00799\ \ \ \ \ tailfrm\ =\ (r-\/>headfrm\ +\ r-\/>n\_frm);\ \ \textcolor{comment}{/*\ Next\ free\ frame\ slot\ to\ be\ filled\ */}}
\DoxyCodeLine{00800\ \ \ \ \ \textcolor{keywordflow}{if}\ (tailfrm\ >=\ CONT\_AD\_ADFRMSIZE)}
\DoxyCodeLine{00801\ \ \ \ \ \ \ \ \ tailfrm\ -\/=\ CONT\_AD\_ADFRMSIZE;}
\DoxyCodeLine{00802\ }
\DoxyCodeLine{00803\ \ \ \ \ \textcolor{keywordflow}{for}\ (;\ len\ >=\ r-\/>spf;\ len\ -\/=\ r-\/>spf)\ \{}
\DoxyCodeLine{00804\ \ \ \ \ \ \ \ \ compute\_frame\_pow(r,\ tailfrm);}
\DoxyCodeLine{00805\ \ \ \ \ \ \ \ \ r-\/>n\_frm++;}
\DoxyCodeLine{00806\ \ \ \ \ \ \ \ \ r-\/>tot\_frm++;}
\DoxyCodeLine{00807\ }
\DoxyCodeLine{00808\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*}}
\DoxyCodeLine{00809\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ *\ Find\ speech/sil\ state\ change,\ if\ any.\ \ Also,\ if\ staying\ in\ speech\ state}}
\DoxyCodeLine{00810\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ *\ add\ this\ frame\ to\ current\ speech\ segment.}}
\DoxyCodeLine{00811\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ */}}
\DoxyCodeLine{00812\ \ \ \ \ \ \ \ \ boundary\_detect(r,\ tailfrm);}
\DoxyCodeLine{00813\ }
\DoxyCodeLine{00814\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (++tailfrm\ >=\ CONT\_AD\_ADFRMSIZE)}
\DoxyCodeLine{00815\ \ \ \ \ \ \ \ \ \ \ \ \ tailfrm\ =\ 0;}
\DoxyCodeLine{00816\ }
\DoxyCodeLine{00817\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Update\ thresholds\ if\ time\ to\ do\ so\ */}}
\DoxyCodeLine{00818\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>thresh\_update\ <=\ 0)\ \{}
\DoxyCodeLine{00819\ \ \ \ \ \ \ \ \ \ \ \ \ int32\ i,\ f;}
\DoxyCodeLine{00820\ \ \ \ \ \ \ \ \ \ \ \ \ find\_thresh(r);}
\DoxyCodeLine{00821\ \ \ \ \ \ \ \ \ \ \ \ \ decay\_hist(r);}
\DoxyCodeLine{00822\ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>thresh\_update\ =\ CONT\_AD\_THRESH\_UPDATE;}
\DoxyCodeLine{00823\ }
\DoxyCodeLine{00824\ \textcolor{preprocessor}{\#if\ 1}}
\DoxyCodeLine{00825\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*}}
\DoxyCodeLine{00826\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ \ \ \ \ *\ Since\ threshold\ has\ been\ updated,\ recompute\ r-\/>n\_other.}}
\DoxyCodeLine{00827\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ \ \ \ \ *\ (RKM:\ Is\ this\ really\ necessary?\ \ Comment\ out??)}}
\DoxyCodeLine{00828\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ \ \ \ \ */}}
\DoxyCodeLine{00829\ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>n\_other\ =\ 0;}
\DoxyCodeLine{00830\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>tail\_state\ ==\ CONT\_AD\_STATE\_SIL)\ \{}
\DoxyCodeLine{00831\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ r-\/>win\_validfrm,\ f\ =\ r-\/>win\_startfrm;\ i\ >\ 0;\ -\/-\/i)\ \{}
\DoxyCodeLine{00832\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>frm\_pow[f]\ >=\ r-\/>thresh\_speech)}
\DoxyCodeLine{00833\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>n\_other++;}
\DoxyCodeLine{00834\ }
\DoxyCodeLine{00835\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ f++;}
\DoxyCodeLine{00836\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (f\ >=\ CONT\_AD\_ADFRMSIZE)}
\DoxyCodeLine{00837\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ f\ =\ 0;}
\DoxyCodeLine{00838\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00839\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00840\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00841\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ r-\/>win\_validfrm,\ f\ =\ r-\/>win\_startfrm;\ i\ >\ 0;\ -\/-\/i)\ \{}
\DoxyCodeLine{00842\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>frm\_pow[f]\ <=\ r-\/>thresh\_sil)}
\DoxyCodeLine{00843\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>n\_other++;}
\DoxyCodeLine{00844\ }
\DoxyCodeLine{00845\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ f++;}
\DoxyCodeLine{00846\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (f\ >=\ CONT\_AD\_ADFRMSIZE)}
\DoxyCodeLine{00847\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ f\ =\ 0;}
\DoxyCodeLine{00848\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00849\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00850\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00851\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00852\ \ \ \ \ \}}
\DoxyCodeLine{00853\ }
\DoxyCodeLine{00854\ \ \ \ \ \textcolor{keywordflow}{return}\ r-\/>tail\_state;}
\DoxyCodeLine{00855\ \}}
\DoxyCodeLine{00856\ }
\DoxyCodeLine{00857\ \textcolor{comment}{/*}}
\DoxyCodeLine{00858\ \textcolor{comment}{\ *\ Main\ function\ called\ by\ the\ application\ to\ filter\ out\ silence\ regions.}}
\DoxyCodeLine{00859\ \textcolor{comment}{\ *\ Maintains\ a\ linked\ list\ of\ speech\ segments\ pointing\ into\ r-\/>adbuf\ and\ feeds}}
\DoxyCodeLine{00860\ \textcolor{comment}{\ *\ data\ to\ application\ from\ them.}}
\DoxyCodeLine{00861\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00862\ int32}
\DoxyCodeLine{00863\ cont\_ad\_read(cont\_ad\_t\ *\ r,\ int16\ *\ buf,\ int32\ max)}
\DoxyCodeLine{00864\ \{}
\DoxyCodeLine{00865\ \ \ \ \ int32\ flen,\ len,\ retval,\ newstate;}
\DoxyCodeLine{00866\ \ \ \ \ spseg\_t\ *seg;}
\DoxyCodeLine{00867\ }
\DoxyCodeLine{00868\ \ \ \ \ \textcolor{keywordflow}{if}\ ((r\ ==\ NULL)\ ||\ (buf\ ==\ NULL))}
\DoxyCodeLine{00869\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00870\ }
\DoxyCodeLine{00871\ \ \ \ \ \textcolor{keywordflow}{if}\ (max\ <\ r-\/>spf)\ \{}
\DoxyCodeLine{00872\ \ \ \ \ \ \ \ \ E\_ERROR}
\DoxyCodeLine{00873\ \ \ \ \ \ \ \ \ \ \ \ \ (\textcolor{stringliteral}{"{}cont\_ad\_read\ requires\ buffer\ of\ at\ least\ \%d\ samples\(\backslash\)n"{}},}
\DoxyCodeLine{00874\ \ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>spf);}
\DoxyCodeLine{00875\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00876\ \ \ \ \ \}}
\DoxyCodeLine{00877\ }
\DoxyCodeLine{00878\ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>logfp)\ \{}
\DoxyCodeLine{00879\ \ \ \ \ \ \ \ \ fprintf(r-\/>logfp,\ \textcolor{stringliteral}{"{}cont\_ad\_read(,,\ \%d)\(\backslash\)n"{}},\ max);}
\DoxyCodeLine{00880\ \ \ \ \ \ \ \ \ fflush(r-\/>logfp);}
\DoxyCodeLine{00881\ \ \ \ \ \}}
\DoxyCodeLine{00882\ }
\DoxyCodeLine{00883\ \ \ \ \ \textcolor{comment}{/*\ Read\ data\ from\ adfunc\ or\ from\ buf.\ */}}
\DoxyCodeLine{00884\ \ \ \ \ len\ =\ cont\_ad\_read\_internal(r,\ buf,\ max);}
\DoxyCodeLine{00885\ }
\DoxyCodeLine{00886\ \ \ \ \ \textcolor{comment}{/*\ Compute\ frame\ power\ for\ unprocessed+new\ data\ and\ find\ speech/silence\ boundaries\ */}}
\DoxyCodeLine{00887\ \ \ \ \ cont\_ad\_classify(r,\ len);}
\DoxyCodeLine{00888\ }
\DoxyCodeLine{00889\ \ \ \ \ \textcolor{comment}{/*}}
\DoxyCodeLine{00890\ \textcolor{comment}{\ \ \ \ \ *\ If\ eof\ on\ input\ data\ source,\ cleanup\ the\ final\ segment.}}
\DoxyCodeLine{00891\ \textcolor{comment}{\ \ \ \ \ */}}
\DoxyCodeLine{00892\ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>eof)\ \{}
\DoxyCodeLine{00893\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>tail\_state\ ==\ CONT\_AD\_STATE\_SPEECH)\ \{}
\DoxyCodeLine{00894\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*}}
\DoxyCodeLine{00895\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ \ \ \ \ *\ Still\ inside\ a\ speech\ segment\ when\ input\ data\ got\ over.\ \ Absort\ any}}
\DoxyCodeLine{00896\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ \ \ \ \ *\ remaining\ frames\ into\ the\ final\ speech\ segment.}}
\DoxyCodeLine{00897\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ \ \ \ \ */}}
\DoxyCodeLine{00898\ \ \ \ \ \ \ \ \ \ \ \ \ assert(r-\/>spseg\_tail\ !=\ NULL);}
\DoxyCodeLine{00899\ }
\DoxyCodeLine{00900\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Absorb\ frames\ still\ in\ analysis\ window\ into\ final\ speech\ seg\ */}}
\DoxyCodeLine{00901\ \ \ \ \ \ \ \ \ \ \ \ \ assert((r-\/>win\_validfrm\ >=\ 0)}
\DoxyCodeLine{00902\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \&\&\ (r-\/>win\_validfrm\ <\ r-\/>winsize));}
\DoxyCodeLine{00903\ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>spseg\_tail-\/>nfrm\ +=\ r-\/>win\_validfrm;}
\DoxyCodeLine{00904\ }
\DoxyCodeLine{00905\ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>tail\_state\ =\ CONT\_AD\_STATE\_SIL;}
\DoxyCodeLine{00906\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00907\ }
\DoxyCodeLine{00908\ \ \ \ \ \ \ \ \ r-\/>win\_startfrm\ +=\ r-\/>win\_validfrm;}
\DoxyCodeLine{00909\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>win\_startfrm\ >=\ CONT\_AD\_ADFRMSIZE)}
\DoxyCodeLine{00910\ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>win\_startfrm\ -\/=\ CONT\_AD\_ADFRMSIZE;}
\DoxyCodeLine{00911\ \ \ \ \ \ \ \ \ r-\/>win\_validfrm\ =\ 0;}
\DoxyCodeLine{00912\ \ \ \ \ \ \ \ \ r-\/>n\_other\ =\ 0;}
\DoxyCodeLine{00913\ \ \ \ \ \}}
\DoxyCodeLine{00914\ }
\DoxyCodeLine{00915\ \ \ \ \ \textcolor{comment}{/*}}
\DoxyCodeLine{00916\ \textcolor{comment}{\ \ \ \ \ *\ At\ last\ ready\ to\ copy\ speech\ data,\ if\ any,\ into\ caller's\ buffer.\ \ Raw}}
\DoxyCodeLine{00917\ \textcolor{comment}{\ \ \ \ \ *\ speech\ data\ is\ segmented\ into\ alternating\ speech\ and\ silence\ segments.}}
\DoxyCodeLine{00918\ \textcolor{comment}{\ \ \ \ \ *\ But\ any\ single\ call\ to\ cont\_ad\_read\ will\ never\ cross\ a\ speech/silence}}
\DoxyCodeLine{00919\ \textcolor{comment}{\ \ \ \ \ *\ boundary.}}
\DoxyCodeLine{00920\ \textcolor{comment}{\ \ \ \ \ */}}
\DoxyCodeLine{00921\ \ \ \ \ seg\ =\ r-\/>spseg\_head;\ \ \ \ \ \ \ \ \textcolor{comment}{/*\ first\ speech\ segment\ available,\ if\ any\ */}}
\DoxyCodeLine{00922\ }
\DoxyCodeLine{00923\ \ \ \ \ \textcolor{keywordflow}{if}\ ((seg\ ==\ NULL)\ ||\ (r-\/>headfrm\ !=\ seg-\/>startfrm))\ \{}
\DoxyCodeLine{00924\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*}}
\DoxyCodeLine{00925\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ *\ Either\ no\ speech\ data\ available,\ or\ inside\ a\ silence\ segment.\ \ Find}}
\DoxyCodeLine{00926\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ *\ length\ of\ silence\ segment.}}
\DoxyCodeLine{00927\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ */}}
\DoxyCodeLine{00928\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (seg\ ==\ NULL)\ \{}
\DoxyCodeLine{00929\ \ \ \ \ \ \ \ \ \ \ \ \ assert(r-\/>tail\_state\ ==\ CONT\_AD\_STATE\_SIL);}
\DoxyCodeLine{00930\ }
\DoxyCodeLine{00931\ \ \ \ \ \ \ \ \ \ \ \ \ flen\ =}
\DoxyCodeLine{00932\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (r-\/>eof)\ ?\ r-\/>n\_frm\ :\ r-\/>n\_frm\ -\/\ (r-\/>winsize\ +}
\DoxyCodeLine{00933\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>leader\ -\/\ 1);}
\DoxyCodeLine{00934\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (flen\ <\ 0)}
\DoxyCodeLine{00935\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ flen\ =\ 0;}
\DoxyCodeLine{00936\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00937\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00938\ \ \ \ \ \ \ \ \ \ \ \ \ flen\ =\ seg-\/>startfrm\ -\/\ r-\/>headfrm;}
\DoxyCodeLine{00939\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (flen\ <\ 0)}
\DoxyCodeLine{00940\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ flen\ +=\ CONT\_AD\_ADFRMSIZE;}
\DoxyCodeLine{00941\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00942\ }
\DoxyCodeLine{00943\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>rawmode)\ \{}
\DoxyCodeLine{00944\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Restrict\ silence\ segment\ to\ user\ buffer\ size,\ integral\ \#frames\ */}}
\DoxyCodeLine{00945\ \ \ \ \ \ \ \ \ \ \ \ \ int32\ f\ =\ max\ /\ r-\/>spf;}
\DoxyCodeLine{00946\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (flen\ >\ f)}
\DoxyCodeLine{00947\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ flen\ =\ f;}
\DoxyCodeLine{00948\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00949\ }
\DoxyCodeLine{00950\ \ \ \ \ \ \ \ \ newstate\ =\ CONT\_AD\_STATE\_SIL;}
\DoxyCodeLine{00951\ \ \ \ \ \}}
\DoxyCodeLine{00952\ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00953\ \ \ \ \ \ \ \ \ flen\ =\ max\ /\ r-\/>spf;\ \ \ \ \textcolor{comment}{/*\ truncate\ read-\/size\ to\ integral\ \#frames\ */}}
\DoxyCodeLine{00954\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (flen\ >\ seg-\/>nfrm)}
\DoxyCodeLine{00955\ \ \ \ \ \ \ \ \ \ \ \ \ flen\ =\ seg-\/>nfrm;\ \ \ \textcolor{comment}{/*\ truncate\ further\ to\ this\ segment\ size\ */}}
\DoxyCodeLine{00956\ }
\DoxyCodeLine{00957\ \ \ \ \ \ \ \ \ newstate\ =\ CONT\_AD\_STATE\_SPEECH;}
\DoxyCodeLine{00958\ \ \ \ \ \}}
\DoxyCodeLine{00959\ }
\DoxyCodeLine{00960\ \ \ \ \ len\ =\ flen\ *\ r-\/>spf;\ \ \ \ \ \ \ \ \textcolor{comment}{/*\ \#samples\ being\ consumed\ */}}
\DoxyCodeLine{00961\ }
\DoxyCodeLine{00962\ \ \ \ \ r-\/>siglvl\ =\ max\_siglvl(r,\ r-\/>headfrm,\ flen);}
\DoxyCodeLine{00963\ }
\DoxyCodeLine{00964\ \ \ \ \ \textcolor{keywordflow}{if}\ ((newstate\ ==\ CONT\_AD\_STATE\_SIL)\ \&\&\ (!r-\/>rawmode))\ \{}
\DoxyCodeLine{00965\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Skip\ silence\ data\ */}}
\DoxyCodeLine{00966\ \ \ \ \ \ \ \ \ r-\/>headfrm\ +=\ flen;}
\DoxyCodeLine{00967\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>headfrm\ >=\ CONT\_AD\_ADFRMSIZE)}
\DoxyCodeLine{00968\ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>headfrm\ -\/=\ CONT\_AD\_ADFRMSIZE;}
\DoxyCodeLine{00969\ }
\DoxyCodeLine{00970\ \ \ \ \ \ \ \ \ retval\ =\ 0;\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ \#samples\ being\ copied/returned\ */}}
\DoxyCodeLine{00971\ \ \ \ \ \}}
\DoxyCodeLine{00972\ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00973\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Copy\ speech/silence(in\ rawmode)\ data\ */}}
\DoxyCodeLine{00974\ \ \ \ \ \ \ \ \ r-\/>headfrm\ =\ buf\_copy(r,\ r-\/>headfrm,\ flen,\ buf);}
\DoxyCodeLine{00975\ }
\DoxyCodeLine{00976\ \ \ \ \ \ \ \ \ retval\ =\ len;\ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ \#samples\ being\ copied/returned\ */}}
\DoxyCodeLine{00977\ \ \ \ \ \}}
\DoxyCodeLine{00978\ }
\DoxyCodeLine{00979\ \ \ \ \ r-\/>n\_frm\ -\/=\ flen;}
\DoxyCodeLine{00980\ \ \ \ \ r-\/>n\_sample\ -\/=\ len;}
\DoxyCodeLine{00981\ \ \ \ \ assert((r-\/>n\_frm\ >=\ 0)\ \&\&\ (r-\/>n\_sample\ >=\ 0));}
\DoxyCodeLine{00982\ \ \ \ \ assert(r-\/>win\_validfrm\ <=\ r-\/>n\_frm);}
\DoxyCodeLine{00983\ }
\DoxyCodeLine{00984\ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>state\ ==\ newstate)}
\DoxyCodeLine{00985\ \ \ \ \ \ \ \ \ r-\/>seglen\ +=\ len;}
\DoxyCodeLine{00986\ \ \ \ \ \textcolor{keywordflow}{else}}
\DoxyCodeLine{00987\ \ \ \ \ \ \ \ \ r-\/>seglen\ =\ len;}
\DoxyCodeLine{00988\ \ \ \ \ r-\/>state\ =\ newstate;}
\DoxyCodeLine{00989\ }
\DoxyCodeLine{00990\ \ \ \ \ \textcolor{keywordflow}{if}\ (newstate\ ==\ CONT\_AD\_STATE\_SPEECH)\ \{}
\DoxyCodeLine{00991\ \ \ \ \ \ \ \ \ seg-\/>startfrm\ =\ r-\/>headfrm;}
\DoxyCodeLine{00992\ \ \ \ \ \ \ \ \ assert(seg-\/>startfrm\ >=\ 0);}
\DoxyCodeLine{00993\ \ \ \ \ \ \ \ \ seg-\/>nfrm\ -\/=\ flen;}
\DoxyCodeLine{00994\ }
\DoxyCodeLine{00995\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Free\ seg\ if\ empty\ and\ not\ recording\ into\ it\ */}}
\DoxyCodeLine{00996\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((seg-\/>nfrm\ ==\ 0)}
\DoxyCodeLine{00997\ \ \ \ \ \ \ \ \ \ \ \ \ \&\&\ (seg-\/>next\ ||\ (r-\/>tail\_state\ ==\ CONT\_AD\_STATE\_SIL)))\ \{}
\DoxyCodeLine{00998\ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>spseg\_head\ =\ seg-\/>next;}
\DoxyCodeLine{00999\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (seg-\/>next\ ==\ NULL)}
\DoxyCodeLine{01000\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>spseg\_tail\ =\ NULL;}
\DoxyCodeLine{01001\ \ \ \ \ \ \ \ \ \ \ \ \ free(seg);}
\DoxyCodeLine{01002\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{01003\ \ \ \ \ \}}
\DoxyCodeLine{01004\ }
\DoxyCodeLine{01005\ \ \ \ \ \textcolor{comment}{/*\ Update\ timestamp.\ \ Total\ raw\ A/D\ read\ -\/\ those\ remaining\ to\ be\ consumed\ */}}
\DoxyCodeLine{01006\ \ \ \ \ r-\/>read\_ts\ =\ (r-\/>tot\_frm\ -\/\ r-\/>n\_frm)\ *\ r-\/>spf;}
\DoxyCodeLine{01007\ }
\DoxyCodeLine{01008\ \ \ \ \ \textcolor{keywordflow}{if}\ (retval\ ==\ 0)}
\DoxyCodeLine{01009\ \ \ \ \ \ \ \ \ retval\ =\ (r-\/>eof\ \&\&\ (r-\/>spseg\_head\ ==\ NULL))\ ?\ -\/1\ :\ 0;}
\DoxyCodeLine{01010\ }
\DoxyCodeLine{01011\ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>logfp)}
\DoxyCodeLine{01012\ \ \ \ \ \ \ \ \ cont\_ad\_read\_log(r,\ retval);}
\DoxyCodeLine{01013\ }
\DoxyCodeLine{01014\ \ \ \ \ \textcolor{keywordflow}{return}\ retval;}
\DoxyCodeLine{01015\ \}}
\DoxyCodeLine{01016\ }
\DoxyCodeLine{01017\ }
\DoxyCodeLine{01018\ \textcolor{comment}{/*}}
\DoxyCodeLine{01019\ \textcolor{comment}{\ *\ Calibrate\ input\ channel\ for\ silence\ threshold.}}
\DoxyCodeLine{01020\ \textcolor{comment}{\ */}}
\DoxyCodeLine{01021\ int32}
\DoxyCodeLine{01022\ cont\_ad\_calib(cont\_ad\_t\ *\ r)}
\DoxyCodeLine{01023\ \{}
\DoxyCodeLine{01024\ \ \ \ \ int32\ i,\ s,\ k,\ len,\ tailfrm;}
\DoxyCodeLine{01025\ }
\DoxyCodeLine{01026\ \ \ \ \ \textcolor{keywordflow}{if}\ (r\ ==\ NULL)}
\DoxyCodeLine{01027\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{01028\ }
\DoxyCodeLine{01029\ \ \ \ \ \textcolor{comment}{/*\ clear\ histogram\ */}}
\DoxyCodeLine{01030\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ CONT\_AD\_POWHISTSIZE;\ i++)}
\DoxyCodeLine{01031\ \ \ \ \ \ \ \ \ r-\/>pow\_hist[i]\ =\ 0;}
\DoxyCodeLine{01032\ \ \ \ \ tailfrm\ =\ r-\/>headfrm\ +\ r-\/>n\_frm;}
\DoxyCodeLine{01033\ \ \ \ \ \textcolor{keywordflow}{if}\ (tailfrm\ >=\ CONT\_AD\_ADFRMSIZE)}
\DoxyCodeLine{01034\ \ \ \ \ \ \ \ \ tailfrm\ -\/=\ CONT\_AD\_ADFRMSIZE;}
\DoxyCodeLine{01035\ \ \ \ \ s\ =\ (tailfrm\ *\ r-\/>spf);}
\DoxyCodeLine{01036\ }
\DoxyCodeLine{01037\ \ \ \ \ \textcolor{keywordflow}{for}\ (r-\/>n\_calib\_frame\ =\ 0;}
\DoxyCodeLine{01038\ \ \ \ \ \ \ \ \ \ r-\/>n\_calib\_frame\ <\ CONT\_AD\_CALIB\_FRAMES;}
\DoxyCodeLine{01039\ \ \ \ \ \ \ \ \ \ ++r-\/>n\_calib\_frame)\ \{}
\DoxyCodeLine{01040\ \ \ \ \ \ \ \ \ len\ =\ r-\/>spf;}
\DoxyCodeLine{01041\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{while}\ (len\ >\ 0)\ \{}
\DoxyCodeLine{01042\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*Trouble\ */}}
\DoxyCodeLine{01043\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((k\ =\ (*(r-\/>adfunc))\ (r-\/>ad,\ r-\/>adbuf\ +\ s,\ len))\ <\ 0)}
\DoxyCodeLine{01044\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{01045\ \ \ \ \ \ \ \ \ \ \ \ \ len\ -\/=\ k;}
\DoxyCodeLine{01046\ \ \ \ \ \ \ \ \ \ \ \ \ s\ +=\ k;}
\DoxyCodeLine{01047\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{01048\ \ \ \ \ \ \ \ \ s\ -\/=\ r-\/>spf;}
\DoxyCodeLine{01049\ }
\DoxyCodeLine{01050\ \ \ \ \ \ \ \ \ compute\_frame\_pow(r,\ tailfrm);}
\DoxyCodeLine{01051\ \ \ \ \ \}}
\DoxyCodeLine{01052\ }
\DoxyCodeLine{01053\ \ \ \ \ r-\/>thresh\_update\ =\ CONT\_AD\_THRESH\_UPDATE;}
\DoxyCodeLine{01054\ \ \ \ \ \textcolor{keywordflow}{return}\ find\_thresh(r);}
\DoxyCodeLine{01055\ \}}
\DoxyCodeLine{01056\ }
\DoxyCodeLine{01057\ int32}
\DoxyCodeLine{01058\ cont\_ad\_calib\_size(cont\_ad\_t\ *r)}
\DoxyCodeLine{01059\ \{}
\DoxyCodeLine{01060\ \ \ \ \ \textcolor{keywordflow}{return}\ r-\/>spf\ *\ CONT\_AD\_CALIB\_FRAMES;}
\DoxyCodeLine{01061\ \}}
\DoxyCodeLine{01062\ }
\DoxyCodeLine{01063\ int32}
\DoxyCodeLine{01064\ cont\_ad\_calib\_loop(cont\_ad\_t\ *\ r,\ int16\ *\ buf,\ int32\ max)}
\DoxyCodeLine{01065\ \{}
\DoxyCodeLine{01066\ \ \ \ \ int32\ i,\ s,\ len,\ tailfrm;}
\DoxyCodeLine{01067\ }
\DoxyCodeLine{01068\ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>n\_calib\_frame\ ==\ CONT\_AD\_CALIB\_FRAMES)\ \{}
\DoxyCodeLine{01069\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ If\ calibration\ previously\ succeeded,\ then\ this\ is\ a}}
\DoxyCodeLine{01070\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ *\ recalibration,\ so\ start\ again.\ */}}
\DoxyCodeLine{01071\ \ \ \ \ \ \ \ \ r-\/>n\_calib\_frame\ =\ 0;}
\DoxyCodeLine{01072\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ clear\ histogram\ */}}
\DoxyCodeLine{01073\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ CONT\_AD\_POWHISTSIZE;\ i++)}
\DoxyCodeLine{01074\ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>pow\_hist[i]\ =\ 0;}
\DoxyCodeLine{01075\ \ \ \ \ \}}
\DoxyCodeLine{01076\ }
\DoxyCodeLine{01077\ \ \ \ \ tailfrm\ =\ r-\/>headfrm\ +\ r-\/>n\_frm;}
\DoxyCodeLine{01078\ \ \ \ \ \textcolor{keywordflow}{if}\ (tailfrm\ >=\ CONT\_AD\_ADFRMSIZE)}
\DoxyCodeLine{01079\ \ \ \ \ \ \ \ \ tailfrm\ -\/=\ CONT\_AD\_ADFRMSIZE;}
\DoxyCodeLine{01080\ \ \ \ \ s\ =\ (tailfrm\ *\ r-\/>spf);}
\DoxyCodeLine{01081\ }
\DoxyCodeLine{01082\ \ \ \ \ len\ =\ r-\/>spf;}
\DoxyCodeLine{01083\ \ \ \ \ \textcolor{keywordflow}{for}\ (;\ r-\/>n\_calib\_frame\ <\ CONT\_AD\_CALIB\_FRAMES;}
\DoxyCodeLine{01084\ \ \ \ \ \ \ \ \ \ ++r-\/>n\_calib\_frame)\ \{}
\DoxyCodeLine{01085\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (max\ <\ len)}
\DoxyCodeLine{01086\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 1;}
\DoxyCodeLine{01087\ \ \ \ \ \ \ \ \ memcpy(r-\/>adbuf\ +\ s,\ buf,\ len\ *\ \textcolor{keyword}{sizeof}(int16));}
\DoxyCodeLine{01088\ \ \ \ \ \ \ \ \ max\ -\/=\ len;}
\DoxyCodeLine{01089\ \ \ \ \ \ \ \ \ buf\ +=\ len;}
\DoxyCodeLine{01090\ \ \ \ \ \ \ \ \ compute\_frame\_pow(r,\ tailfrm);}
\DoxyCodeLine{01091\ \ \ \ \ \}}
\DoxyCodeLine{01092\ }
\DoxyCodeLine{01093\ \ \ \ \ r-\/>thresh\_update\ =\ CONT\_AD\_THRESH\_UPDATE;}
\DoxyCodeLine{01094\ \ \ \ \ \textcolor{keywordflow}{return}\ find\_thresh(r);}
\DoxyCodeLine{01095\ \}}
\DoxyCodeLine{01096\ }
\DoxyCodeLine{01097\ }
\DoxyCodeLine{01098\ \textcolor{comment}{/*\ PWP\ 1/14/98\ -\/-\/\ modified\ for\ compatibility\ with\ old\ code\ */}}
\DoxyCodeLine{01099\ int32}
\DoxyCodeLine{01100\ cont\_ad\_set\_thresh(cont\_ad\_t\ *\ r,\ int32\ sil,\ int32\ speech)}
\DoxyCodeLine{01101\ \{}
\DoxyCodeLine{01102\ \ \ \ \ \textcolor{keywordflow}{if}\ (r\ ==\ NULL)}
\DoxyCodeLine{01103\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{01104\ }
\DoxyCodeLine{01105\ \ \ \ \ \textcolor{keywordflow}{if}\ ((sil\ <\ 0)\ ||\ (speech\ <\ 0))\ \{}
\DoxyCodeLine{01106\ \ \ \ \ \ \ \ \ fprintf(stderr,}
\DoxyCodeLine{01107\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}cont\_ad\_set\_thresh:\ invalid\ threshold\ arguments:\ \%d,\ \%d\(\backslash\)n"{}},}
\DoxyCodeLine{01108\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ sil,\ speech);}
\DoxyCodeLine{01109\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{01110\ \ \ \ \ \}}
\DoxyCodeLine{01111\ \ \ \ \ r-\/>delta\_sil\ =\ (3\ *\ sil)\ /\ 2;}
\DoxyCodeLine{01112\ \ \ \ \ r-\/>delta\_speech\ =\ (3\ *\ speech)\ /\ 2;}
\DoxyCodeLine{01113\ }
\DoxyCodeLine{01114\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{01115\ \}}
\DoxyCodeLine{01116\ }
\DoxyCodeLine{01117\ }
\DoxyCodeLine{01118\ \textcolor{comment}{/*}}
\DoxyCodeLine{01119\ \textcolor{comment}{\ *\ PWP\ 1/14/98\ -\/-\/\ set\ the\ changable\ params.}}
\DoxyCodeLine{01120\ \textcolor{comment}{\ *}}
\DoxyCodeLine{01121\ \textcolor{comment}{\ *\ \ \ delta\_sil,\ delta\_speech,\ min\_noise,\ and\ max\_noise\ are\ in\ dB,}}
\DoxyCodeLine{01122\ \textcolor{comment}{\ *\ \ \ winsize,\ speech\_onset,\ sil\_onset,\ leader\ and\ trailer\ are\ in\ frames\ of}}
\DoxyCodeLine{01123\ \textcolor{comment}{\ *\ \ \ 16\ ms\ length\ (256\ samples\ @\ 16kHz\ sampling).}}
\DoxyCodeLine{01124\ \textcolor{comment}{\ */}}
\DoxyCodeLine{01125\ int32}
\DoxyCodeLine{01126\ cont\_ad\_set\_params(cont\_ad\_t\ *\ r,\ int32\ delta\_sil,}
\DoxyCodeLine{01127\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ int32\ delta\_speech,\ int32\ min\_noise,}
\DoxyCodeLine{01128\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ int32\ max\_noise,\ int32\ winsize,}
\DoxyCodeLine{01129\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ int32\ speech\_onset,\ int32\ sil\_onset,\ int32\ leader,}
\DoxyCodeLine{01130\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ int32\ trailer,\ float32\ adapt\_rate)}
\DoxyCodeLine{01131\ \{}
\DoxyCodeLine{01132\ \ \ \ \ \textcolor{keywordflow}{if}\ ((delta\_sil\ <\ 0)\ ||\ (delta\_speech\ <\ 0)\ ||\ (min\_noise\ <\ 0)}
\DoxyCodeLine{01133\ \ \ \ \ \ \ \ \ ||\ (max\_noise\ <\ 0))\ \{}
\DoxyCodeLine{01134\ \ \ \ \ \ \ \ \ E\_ERROR(\textcolor{stringliteral}{"{}threshold\ arguments:\ "{}}}
\DoxyCodeLine{01135\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}\%d,\ \%d,\ \%d,\ \%d\ must\ all\ be\ >=0\(\backslash\)n"{}},\ delta\_sil,}
\DoxyCodeLine{01136\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ delta\_speech,\ min\_noise,\ max\_noise);}
\DoxyCodeLine{01137\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{01138\ \ \ \ \ \}}
\DoxyCodeLine{01139\ }
\DoxyCodeLine{01140\ \ \ \ \ \textcolor{keywordflow}{if}\ ((speech\_onset\ >\ winsize)\ ||\ (speech\_onset\ <=\ 0)}
\DoxyCodeLine{01141\ \ \ \ \ \ \ \ \ ||\ (winsize\ <=\ 0))\ \{}
\DoxyCodeLine{01142\ \ \ \ \ \ \ \ \ E\_ERROR}
\DoxyCodeLine{01143\ \ \ \ \ \ \ \ \ \ \ \ \ (\textcolor{stringliteral}{"{}speech\_onset,\ \%d,\ must\ be\ <=\ winsize,\ \%d,\ and\ both\ >0\(\backslash\)n"{}},}
\DoxyCodeLine{01144\ \ \ \ \ \ \ \ \ \ \ \ \ \ speech\_onset,\ winsize);}
\DoxyCodeLine{01145\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{01146\ \ \ \ \ \}}
\DoxyCodeLine{01147\ }
\DoxyCodeLine{01148\ \ \ \ \ \textcolor{keywordflow}{if}\ ((sil\_onset\ >\ winsize)\ ||\ (sil\_onset\ <=\ 0)\ ||\ (winsize\ <=\ 0))\ \{}
\DoxyCodeLine{01149\ \ \ \ \ \ \ \ \ E\_ERROR}
\DoxyCodeLine{01150\ \ \ \ \ \ \ \ \ \ \ \ \ (\textcolor{stringliteral}{"{}sil\_onset,\ \%d,\ must\ be\ <=\ winsize,\ \%d,\ and\ both\ >0\(\backslash\)n"{}},}
\DoxyCodeLine{01151\ \ \ \ \ \ \ \ \ \ \ \ \ \ sil\_onset,\ winsize);}
\DoxyCodeLine{01152\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{01153\ \ \ \ \ \}}
\DoxyCodeLine{01154\ }
\DoxyCodeLine{01155\ \ \ \ \ \textcolor{keywordflow}{if}\ (((leader\ +\ trailer)\ >\ winsize)\ ||\ (leader\ <=\ 0)}
\DoxyCodeLine{01156\ \ \ \ \ \ \ \ \ ||\ (trailer\ <=\ 0))\ \{}
\DoxyCodeLine{01157\ \ \ \ \ \ \ \ \ E\_ERROR}
\DoxyCodeLine{01158\ \ \ \ \ \ \ \ \ \ \ \ \ (\textcolor{stringliteral}{"{}leader,\ \%d,\ plus\ trailer,\ \%d,\ must\ be\ <=\ winsize,\ \%d,\ and\ both\ >0\(\backslash\)n"{}},}
\DoxyCodeLine{01159\ \ \ \ \ \ \ \ \ \ \ \ \ \ leader,\ trailer,\ winsize);}
\DoxyCodeLine{01160\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{01161\ \ \ \ \ \}}
\DoxyCodeLine{01162\ }
\DoxyCodeLine{01163\ \ \ \ \ \textcolor{keywordflow}{if}\ ((adapt\_rate\ <\ 0.0)\ ||\ (adapt\_rate\ >\ 1.0))\ \{}
\DoxyCodeLine{01164\ \ \ \ \ \ \ \ \ E\_ERROR(\textcolor{stringliteral}{"{}adapt\_rate,\ \%e;\ must\ be\ in\ range\ 0..1\(\backslash\)n"{}},\ adapt\_rate);}
\DoxyCodeLine{01165\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{01166\ \ \ \ \ \}}
\DoxyCodeLine{01167\ }
\DoxyCodeLine{01168\ \ \ \ \ \textcolor{keywordflow}{if}\ (r\ ==\ NULL)}
\DoxyCodeLine{01169\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{01170\ }
\DoxyCodeLine{01171\ \ \ \ \ r-\/>delta\_sil\ =\ delta\_sil;}
\DoxyCodeLine{01172\ \ \ \ \ r-\/>delta\_speech\ =\ delta\_speech;}
\DoxyCodeLine{01173\ \ \ \ \ r-\/>min\_noise\ =\ min\_noise;}
\DoxyCodeLine{01174\ \ \ \ \ r-\/>max\_noise\ =\ max\_noise;}
\DoxyCodeLine{01175\ }
\DoxyCodeLine{01176\ \ \ \ \ r-\/>winsize\ =\ winsize;}
\DoxyCodeLine{01177\ \ \ \ \ r-\/>speech\_onset\ =\ speech\_onset;}
\DoxyCodeLine{01178\ \ \ \ \ r-\/>sil\_onset\ =\ sil\_onset;}
\DoxyCodeLine{01179\ \ \ \ \ r-\/>leader\ =\ leader;}
\DoxyCodeLine{01180\ \ \ \ \ r-\/>trailer\ =\ trailer;}
\DoxyCodeLine{01181\ }
\DoxyCodeLine{01182\ \ \ \ \ r-\/>adapt\_rate\ =\ adapt\_rate;}
\DoxyCodeLine{01183\ }
\DoxyCodeLine{01184\ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>win\_validfrm\ >=\ r-\/>winsize)}
\DoxyCodeLine{01185\ \ \ \ \ \ \ \ \ r-\/>win\_validfrm\ =\ r-\/>winsize\ -\/\ 1;}
\DoxyCodeLine{01186\ }
\DoxyCodeLine{01187\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{01188\ \}}
\DoxyCodeLine{01189\ }
\DoxyCodeLine{01190\ }
\DoxyCodeLine{01191\ \textcolor{comment}{/*}}
\DoxyCodeLine{01192\ \textcolor{comment}{\ *\ PWP\ 1/14/98\ -\/-\/\ get\ the\ changable\ params.}}
\DoxyCodeLine{01193\ \textcolor{comment}{\ *}}
\DoxyCodeLine{01194\ \textcolor{comment}{\ *\ \ \ delta\_sil,\ delta\_speech,\ min\_noise,\ and\ max\_noise\ are\ in\ dB,}}
\DoxyCodeLine{01195\ \textcolor{comment}{\ *\ \ \ winsize,\ speech\_onset,\ sil\_onset,\ leader\ and\ trailer\ are\ in\ frames\ of}}
\DoxyCodeLine{01196\ \textcolor{comment}{\ *\ \ \ 16\ ms\ length\ (256\ samples\ @\ 16kHz\ sampling).}}
\DoxyCodeLine{01197\ \textcolor{comment}{\ */}}
\DoxyCodeLine{01198\ int32}
\DoxyCodeLine{01199\ cont\_ad\_get\_params(cont\_ad\_t\ *\ r,\ int32\ *\ delta\_sil,}
\DoxyCodeLine{01200\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ int32\ *\ delta\_speech,\ int32\ *\ min\_noise,}
\DoxyCodeLine{01201\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ int32\ *\ max\_noise,\ int32\ *\ winsize,}
\DoxyCodeLine{01202\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ int32\ *\ speech\_onset,\ int32\ *\ sil\_onset,}
\DoxyCodeLine{01203\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ int32\ *\ leader,\ int32\ *\ trailer,\ float32\ *\ adapt\_rate)}
\DoxyCodeLine{01204\ \{}
\DoxyCodeLine{01205\ \ \ \ \ \textcolor{keywordflow}{if}\ (!delta\_sil\ ||\ !delta\_speech\ ||\ !min\_noise\ ||\ !max\_noise}
\DoxyCodeLine{01206\ \ \ \ \ \ \ \ \ ||\ !winsize\ ||\ !speech\_onset\ ||\ !sil\_onset\ ||\ !leader}
\DoxyCodeLine{01207\ \ \ \ \ \ \ \ \ ||\ !trailer\ ||\ !adapt\_rate)\ \{}
\DoxyCodeLine{01208\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}cont\_ad\_get\_params:\ some\ param\ slots\ are\ NULL\(\backslash\)n"{}});}
\DoxyCodeLine{01209\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ (-\/1);}
\DoxyCodeLine{01210\ \ \ \ \ \}}
\DoxyCodeLine{01211\ }
\DoxyCodeLine{01212\ \ \ \ \ \textcolor{keywordflow}{if}\ (r\ ==\ NULL)}
\DoxyCodeLine{01213\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{01214\ }
\DoxyCodeLine{01215\ \ \ \ \ *delta\_sil\ =\ r-\/>delta\_sil;}
\DoxyCodeLine{01216\ \ \ \ \ *delta\_speech\ =\ r-\/>delta\_speech;}
\DoxyCodeLine{01217\ \ \ \ \ *min\_noise\ =\ r-\/>min\_noise;}
\DoxyCodeLine{01218\ \ \ \ \ *max\_noise\ =\ r-\/>max\_noise;}
\DoxyCodeLine{01219\ }
\DoxyCodeLine{01220\ \ \ \ \ *winsize\ =\ r-\/>winsize;}
\DoxyCodeLine{01221\ \ \ \ \ *speech\_onset\ =\ r-\/>speech\_onset;}
\DoxyCodeLine{01222\ \ \ \ \ *sil\_onset\ =\ r-\/>sil\_onset;}
\DoxyCodeLine{01223\ \ \ \ \ *leader\ =\ r-\/>leader;}
\DoxyCodeLine{01224\ \ \ \ \ *trailer\ =\ r-\/>trailer;}
\DoxyCodeLine{01225\ }
\DoxyCodeLine{01226\ \ \ \ \ *adapt\_rate\ =\ r-\/>adapt\_rate;}
\DoxyCodeLine{01227\ }
\DoxyCodeLine{01228\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{01229\ \}}
\DoxyCodeLine{01230\ }
\DoxyCodeLine{01231\ }
\DoxyCodeLine{01232\ \textcolor{comment}{/*}}
\DoxyCodeLine{01233\ \textcolor{comment}{\ *\ Reset,\ discarded\ any\ accumulated\ speech.}}
\DoxyCodeLine{01234\ \textcolor{comment}{\ */}}
\DoxyCodeLine{01235\ int32}
\DoxyCodeLine{01236\ cont\_ad\_reset(cont\_ad\_t\ *\ r)}
\DoxyCodeLine{01237\ \{}
\DoxyCodeLine{01238\ \ \ \ \ spseg\_t\ *seg;}
\DoxyCodeLine{01239\ }
\DoxyCodeLine{01240\ \ \ \ \ \textcolor{keywordflow}{if}\ (r\ ==\ NULL)}
\DoxyCodeLine{01241\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{01242\ }
\DoxyCodeLine{01243\ \ \ \ \ \textcolor{keywordflow}{while}\ (r-\/>spseg\_head)\ \{}
\DoxyCodeLine{01244\ \ \ \ \ \ \ \ \ seg\ =\ r-\/>spseg\_head;}
\DoxyCodeLine{01245\ \ \ \ \ \ \ \ \ r-\/>spseg\_head\ =\ seg-\/>next;}
\DoxyCodeLine{01246\ \ \ \ \ \ \ \ \ free(seg);}
\DoxyCodeLine{01247\ \ \ \ \ \}}
\DoxyCodeLine{01248\ \ \ \ \ r-\/>spseg\_tail\ =\ NULL;}
\DoxyCodeLine{01249\ }
\DoxyCodeLine{01250\ \ \ \ \ r-\/>headfrm\ =\ 0;}
\DoxyCodeLine{01251\ \ \ \ \ r-\/>n\_frm\ =\ 0;}
\DoxyCodeLine{01252\ \ \ \ \ r-\/>n\_sample\ =\ 0;}
\DoxyCodeLine{01253\ \ \ \ \ r-\/>win\_startfrm\ =\ 0;}
\DoxyCodeLine{01254\ \ \ \ \ r-\/>win\_validfrm\ =\ 0;}
\DoxyCodeLine{01255\ \ \ \ \ r-\/>n\_other\ =\ 0;}
\DoxyCodeLine{01256\ }
\DoxyCodeLine{01257\ \ \ \ \ r-\/>tail\_state\ =\ CONT\_AD\_STATE\_SIL;}
\DoxyCodeLine{01258\ }
\DoxyCodeLine{01259\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{01260\ \}}
\DoxyCodeLine{01261\ }
\DoxyCodeLine{01262\ }
\DoxyCodeLine{01263\ int32}
\DoxyCodeLine{01264\ cont\_ad\_close(cont\_ad\_t\ *\ cont)}
\DoxyCodeLine{01265\ \{}
\DoxyCodeLine{01266\ \ \ \ \ \textcolor{keywordflow}{if}\ (cont\ ==\ NULL)}
\DoxyCodeLine{01267\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{01268\ }
\DoxyCodeLine{01269\ \ \ \ \ cont\_ad\_reset(cont);\ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Frees\ any\ remaining\ speech\ segments\ */}}
\DoxyCodeLine{01270\ }
\DoxyCodeLine{01271\ \ \ \ \ free(cont-\/>adbuf);}
\DoxyCodeLine{01272\ \ \ \ \ free(cont-\/>pow\_hist);}
\DoxyCodeLine{01273\ \ \ \ \ free(cont-\/>frm\_pow);}
\DoxyCodeLine{01274\ \ \ \ \ free(cont);}
\DoxyCodeLine{01275\ }
\DoxyCodeLine{01276\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{01277\ \}}
\DoxyCodeLine{01278\ }
\DoxyCodeLine{01279\ }
\DoxyCodeLine{01280\ int32}
\DoxyCodeLine{01281\ cont\_ad\_detach(cont\_ad\_t\ *\ c)}
\DoxyCodeLine{01282\ \{}
\DoxyCodeLine{01283\ \ \ \ \ \textcolor{keywordflow}{if}\ (c\ ==\ NULL)}
\DoxyCodeLine{01284\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{01285\ }
\DoxyCodeLine{01286\ \ \ \ \ c-\/>ad\ =\ NULL;}
\DoxyCodeLine{01287\ \ \ \ \ c-\/>adfunc\ =\ NULL;}
\DoxyCodeLine{01288\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{01289\ \}}
\DoxyCodeLine{01290\ }
\DoxyCodeLine{01291\ }
\DoxyCodeLine{01292\ int32}
\DoxyCodeLine{01293\ cont\_ad\_attach(cont\_ad\_t\ *\ c,\ ad\_rec\_t\ *\ a,}
\DoxyCodeLine{01294\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ int32(*func)\ (ad\_rec\_t\ *,\ int16\ *,\ int32))}
\DoxyCodeLine{01295\ \{}
\DoxyCodeLine{01296\ \ \ \ \ \textcolor{keywordflow}{if}\ (c\ ==\ NULL)}
\DoxyCodeLine{01297\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{01298\ }
\DoxyCodeLine{01299\ \ \ \ \ c-\/>ad\ =\ a;}
\DoxyCodeLine{01300\ \ \ \ \ c-\/>adfunc\ =\ func;}
\DoxyCodeLine{01301\ \ \ \ \ c-\/>eof\ =\ 0;}
\DoxyCodeLine{01302\ }
\DoxyCodeLine{01303\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{01304\ \}}
\DoxyCodeLine{01305\ }
\DoxyCodeLine{01306\ }
\DoxyCodeLine{01307\ int32}
\DoxyCodeLine{01308\ cont\_set\_thresh(cont\_ad\_t\ *\ r,\ int32\ silence,\ int32\ speech)}
\DoxyCodeLine{01309\ \{}
\DoxyCodeLine{01310\ \ \ \ \ int32\ i,\ f;}
\DoxyCodeLine{01311\ }
\DoxyCodeLine{01312\ \ \ \ \ r-\/>thresh\_speech\ =\ speech;}
\DoxyCodeLine{01313\ \ \ \ \ r-\/>thresh\_sil\ =\ silence;}
\DoxyCodeLine{01314\ }
\DoxyCodeLine{01315\ \ \ \ \ \textcolor{comment}{/*\ Since\ threshold\ has\ been\ updated,\ recompute\ r-\/>n\_other\ */}}
\DoxyCodeLine{01316\ \ \ \ \ r-\/>n\_other\ =\ 0;}
\DoxyCodeLine{01317\ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>tail\_state\ ==\ CONT\_AD\_STATE\_SIL)\ \{}
\DoxyCodeLine{01318\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ r-\/>win\_validfrm,\ f\ =\ r-\/>win\_startfrm;\ i\ >\ 0;\ -\/-\/i)\ \{}
\DoxyCodeLine{01319\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>frm\_pow[f]\ >=\ r-\/>thresh\_speech)}
\DoxyCodeLine{01320\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>n\_other++;}
\DoxyCodeLine{01321\ }
\DoxyCodeLine{01322\ \ \ \ \ \ \ \ \ \ \ \ \ f++;}
\DoxyCodeLine{01323\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (f\ >=\ CONT\_AD\_ADFRMSIZE)}
\DoxyCodeLine{01324\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ f\ =\ 0;}
\DoxyCodeLine{01325\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{01326\ \ \ \ \ \}}
\DoxyCodeLine{01327\ \ \ \ \ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (r-\/>tail\_state\ ==\ CONT\_AD\_STATE\_SPEECH)\ \{}
\DoxyCodeLine{01328\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ r-\/>win\_validfrm,\ f\ =\ r-\/>win\_startfrm;\ i\ >\ 0;\ -\/-\/i)\ \{}
\DoxyCodeLine{01329\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>frm\_pow[f]\ <=\ r-\/>thresh\_sil)}
\DoxyCodeLine{01330\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>n\_other++;}
\DoxyCodeLine{01331\ }
\DoxyCodeLine{01332\ \ \ \ \ \ \ \ \ \ \ \ \ f++;}
\DoxyCodeLine{01333\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (f\ >=\ CONT\_AD\_ADFRMSIZE)}
\DoxyCodeLine{01334\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ f\ =\ 0;}
\DoxyCodeLine{01335\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{01336\ \ \ \ \ \}}
\DoxyCodeLine{01337\ }
\DoxyCodeLine{01338\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{01339\ \}}
\DoxyCodeLine{01340\ }
\DoxyCodeLine{01341\ }
\DoxyCodeLine{01342\ \textcolor{comment}{/*}}
\DoxyCodeLine{01343\ \textcolor{comment}{\ *\ Set\ the\ file\ pointer\ for\ dumping\ the\ raw\ input\ audio\ stream.}}
\DoxyCodeLine{01344\ \textcolor{comment}{\ */}}
\DoxyCodeLine{01345\ int32}
\DoxyCodeLine{01346\ cont\_ad\_set\_rawfp(cont\_ad\_t\ *\ r,\ FILE\ *\ fp)}
\DoxyCodeLine{01347\ \{}
\DoxyCodeLine{01348\ \ \ \ \ \textcolor{keywordflow}{if}\ (r\ ==\ NULL)}
\DoxyCodeLine{01349\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{01350\ }
\DoxyCodeLine{01351\ \ \ \ \ r-\/>rawfp\ =\ fp;}
\DoxyCodeLine{01352\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{01353\ \}}
\DoxyCodeLine{01354\ }
\DoxyCodeLine{01355\ }
\DoxyCodeLine{01356\ \textcolor{comment}{/*}}
\DoxyCodeLine{01357\ \textcolor{comment}{\ *\ Set\ the\ file\ pointer\ for\ logging\ cont\_ad\ progress.}}
\DoxyCodeLine{01358\ \textcolor{comment}{\ */}}
\DoxyCodeLine{01359\ int32}
\DoxyCodeLine{01360\ cont\_ad\_set\_logfp(cont\_ad\_t\ *\ r,\ FILE\ *\ fp)}
\DoxyCodeLine{01361\ \{}
\DoxyCodeLine{01362\ \ \ \ \ \textcolor{keywordflow}{if}\ (r\ ==\ NULL)}
\DoxyCodeLine{01363\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{01364\ }
\DoxyCodeLine{01365\ \ \ \ \ r-\/>logfp\ =\ fp;}
\DoxyCodeLine{01366\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{01367\ \}}
\DoxyCodeLine{01368\ }
\DoxyCodeLine{01369\ }
\DoxyCodeLine{01370\ \textcolor{comment}{/*}}
\DoxyCodeLine{01371\ \textcolor{comment}{\ *\ One-\/time\ initialization.}}
\DoxyCodeLine{01372\ \textcolor{comment}{\ */}}
\DoxyCodeLine{01373\ cont\_ad\_t\ *}
\DoxyCodeLine{01374\ cont\_ad\_init(ad\_rec\_t\ *\ a,\ int32(*func)\ (ad\_rec\_t\ *,\ int16\ *,\ int32))}
\DoxyCodeLine{01375\ \{}
\DoxyCodeLine{01376\ \ \ \ \ cont\_ad\_t\ *r;}
\DoxyCodeLine{01377\ }
\DoxyCodeLine{01378\ \ \ \ \ \textcolor{keywordflow}{if}\ ((r\ =\ malloc(\textcolor{keyword}{sizeof}(*r)))\ ==\ NULL)\ \{}
\DoxyCodeLine{01379\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}allocation\ of\ cont\_ad\_t\ failed"{}});}
\DoxyCodeLine{01380\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{01381\ \ \ \ \ \}}
\DoxyCodeLine{01382\ }
\DoxyCodeLine{01383\ \ \ \ \ r-\/>ad\ =\ a;}
\DoxyCodeLine{01384\ \ \ \ \ r-\/>adfunc\ =\ func;}
\DoxyCodeLine{01385\ \ \ \ \ r-\/>eof\ =\ 0;}
\DoxyCodeLine{01386\ \ \ \ \ r-\/>rawmode\ =\ 0;}
\DoxyCodeLine{01387\ }
\DoxyCodeLine{01388\ \ \ \ \ \textcolor{keywordflow}{if}\ (a\ !=\ NULL)}
\DoxyCodeLine{01389\ \ \ \ \ \ \ \ \ r-\/>sps\ =\ a-\/>sps;}
\DoxyCodeLine{01390\ \ \ \ \ \textcolor{keywordflow}{else}}
\DoxyCodeLine{01391\ \ \ \ \ \ \ \ \ r-\/>sps\ =\ CONT\_AD\_SPS;}
\DoxyCodeLine{01392\ }
\DoxyCodeLine{01393\ \ \ \ \ \textcolor{comment}{/*\ Set\ samples/frame\ such\ that\ when\ sps=16000,\ spf=256\ */}}
\DoxyCodeLine{01394\ \ \ \ \ r-\/>spf\ =\ (r-\/>sps\ *\ 256)\ /\ CONT\_AD\_SPS;}
\DoxyCodeLine{01395\ \ \ \ \ r-\/>adbufsize\ =\ CONT\_AD\_ADFRMSIZE\ *\ r-\/>spf;}
\DoxyCodeLine{01396\ }
\DoxyCodeLine{01397\ \ \ \ \ \textcolor{keywordflow}{if}\ ((r-\/>adbuf\ =\ malloc(r-\/>adbufsize\ *\ \textcolor{keyword}{sizeof}(*r-\/>adbuf)))\ ==\ NULL)\ \{}
\DoxyCodeLine{01398\ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}allocation\ of\ audio\ buffer\ failed"{}});}
\DoxyCodeLine{01399\ \ \ \ \ \ \ \ \ free(r);}
\DoxyCodeLine{01400\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{01401\ \ \ \ \ \}}
\DoxyCodeLine{01402\ \ \ \ \ \textcolor{keywordflow}{if}\ ((r-\/>pow\_hist\ =}
\DoxyCodeLine{01403\ \ \ \ \ \ \ \ \ \ calloc(CONT\_AD\_POWHISTSIZE,\ \textcolor{keyword}{sizeof}(*r-\/>pow\_hist)))\ ==\ NULL)\ \{}
\DoxyCodeLine{01404\ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}allocation\ of\ power\ history\ buffer\ failed"{}});}
\DoxyCodeLine{01405\ \ \ \ \ \ \ \ \ free(r-\/>adbuf);}
\DoxyCodeLine{01406\ \ \ \ \ \ \ \ \ free(r);}
\DoxyCodeLine{01407\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{01408\ \ \ \ \ \}}
\DoxyCodeLine{01409\ \ \ \ \ \textcolor{keywordflow}{if}\ ((r-\/>frm\_pow\ =}
\DoxyCodeLine{01410\ \ \ \ \ \ \ \ \ \ calloc(CONT\_AD\_ADFRMSIZE,\ \textcolor{keyword}{sizeof}(*r-\/>frm\_pow)))\ ==\ NULL)\ \{}
\DoxyCodeLine{01411\ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}allocation\ of\ frame\ power\ buffer\ failed"{}});}
\DoxyCodeLine{01412\ \ \ \ \ \ \ \ \ free(r-\/>pow\_hist);}
\DoxyCodeLine{01413\ \ \ \ \ \ \ \ \ free(r-\/>adbuf);}
\DoxyCodeLine{01414\ \ \ \ \ \ \ \ \ free(r);}
\DoxyCodeLine{01415\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{01416\ \ \ \ \ \}}
\DoxyCodeLine{01417\ }
\DoxyCodeLine{01418\ \ \ \ \ r-\/>state\ =\ CONT\_AD\_STATE\_SIL;}
\DoxyCodeLine{01419\ \ \ \ \ r-\/>read\_ts\ =\ 0;}
\DoxyCodeLine{01420\ \ \ \ \ r-\/>seglen\ =\ 0;}
\DoxyCodeLine{01421\ \ \ \ \ r-\/>siglvl\ =\ 0;}
\DoxyCodeLine{01422\ \ \ \ \ r-\/>prev\_sample\ =\ 0;}
\DoxyCodeLine{01423\ \ \ \ \ r-\/>tot\_frm\ =\ 0;}
\DoxyCodeLine{01424\ \ \ \ \ r-\/>noise\_level\ =\ CONT\_AD\_DEFAULT\_NOISE;}
\DoxyCodeLine{01425\ }
\DoxyCodeLine{01426\ \ \ \ \ r-\/>auto\_thresh\ =\ 1;}
\DoxyCodeLine{01427\ \ \ \ \ r-\/>delta\_sil\ =\ CONT\_AD\_DELTA\_SIL;}
\DoxyCodeLine{01428\ \ \ \ \ r-\/>delta\_speech\ =\ CONT\_AD\_DELTA\_SPEECH;}
\DoxyCodeLine{01429\ \ \ \ \ r-\/>min\_noise\ =\ CONT\_AD\_MIN\_NOISE;}
\DoxyCodeLine{01430\ \ \ \ \ r-\/>max\_noise\ =\ CONT\_AD\_MAX\_NOISE;}
\DoxyCodeLine{01431\ \ \ \ \ r-\/>winsize\ =\ CONT\_AD\_WINSIZE;}
\DoxyCodeLine{01432\ \ \ \ \ r-\/>speech\_onset\ =\ CONT\_AD\_SPEECH\_ONSET;}
\DoxyCodeLine{01433\ \ \ \ \ r-\/>sil\_onset\ =\ CONT\_AD\_SIL\_ONSET;}
\DoxyCodeLine{01434\ \ \ \ \ r-\/>leader\ =\ CONT\_AD\_LEADER;}
\DoxyCodeLine{01435\ \ \ \ \ r-\/>trailer\ =\ CONT\_AD\_TRAILER;}
\DoxyCodeLine{01436\ }
\DoxyCodeLine{01437\ \ \ \ \ r-\/>thresh\_sil\ =\ r-\/>noise\_level\ +\ r-\/>delta\_sil;}
\DoxyCodeLine{01438\ \ \ \ \ r-\/>thresh\_speech\ =\ r-\/>noise\_level\ +\ r-\/>delta\_speech;}
\DoxyCodeLine{01439\ \ \ \ \ r-\/>thresh\_update\ =\ CONT\_AD\_THRESH\_UPDATE;}
\DoxyCodeLine{01440\ \ \ \ \ r-\/>adapt\_rate\ =\ CONT\_AD\_ADAPT\_RATE;}
\DoxyCodeLine{01441\ }
\DoxyCodeLine{01442\ \ \ \ \ r-\/>tail\_state\ =\ CONT\_AD\_STATE\_SIL;}
\DoxyCodeLine{01443\ }
\DoxyCodeLine{01444\ \ \ \ \ r-\/>spseg\_head\ =\ NULL;}
\DoxyCodeLine{01445\ \ \ \ \ r-\/>spseg\_tail\ =\ NULL;}
\DoxyCodeLine{01446\ }
\DoxyCodeLine{01447\ \ \ \ \ r-\/>rawfp\ =\ NULL;}
\DoxyCodeLine{01448\ \ \ \ \ r-\/>logfp\ =\ NULL;}
\DoxyCodeLine{01449\ }
\DoxyCodeLine{01450\ \ \ \ \ r-\/>n\_calib\_frame\ =\ 0;}
\DoxyCodeLine{01451\ }
\DoxyCodeLine{01452\ \ \ \ \ cont\_ad\_reset(r);}
\DoxyCodeLine{01453\ }
\DoxyCodeLine{01454\ \ \ \ \ \textcolor{keywordflow}{return}\ r;}
\DoxyCodeLine{01455\ \}}
\DoxyCodeLine{01456\ }
\DoxyCodeLine{01457\ }
\DoxyCodeLine{01458\ cont\_ad\_t\ *}
\DoxyCodeLine{01459\ cont\_ad\_init\_rawmode(ad\_rec\_t\ *\ a,}
\DoxyCodeLine{01460\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ int32(*func)\ (ad\_rec\_t\ *,\ int16\ *,\ int32))}
\DoxyCodeLine{01461\ \{}
\DoxyCodeLine{01462\ \ \ \ \ cont\_ad\_t\ *r;}
\DoxyCodeLine{01463\ }
\DoxyCodeLine{01464\ \ \ \ \ r\ =\ cont\_ad\_init(a,\ func);}
\DoxyCodeLine{01465\ \ \ \ \ r-\/>rawmode\ =\ 1;}
\DoxyCodeLine{01466\ }
\DoxyCodeLine{01467\ \ \ \ \ \textcolor{keywordflow}{return}\ r;}
\DoxyCodeLine{01468\ \}}

\end{DoxyCode}
