\section{include/sphinxbase/cont\+\_\+ad.h File Reference}
\label{cont__ad_8h}\index{include/sphinxbase/cont\+\_\+ad.\+h@{include/sphinxbase/cont\+\_\+ad.\+h}}


Continuous A/\+D listening and silence filtering module.  


{\ttfamily \#include $<$sphinxbase/sphinxbase\+\_\+export.\+h$>$}\\*
{\ttfamily \#include $<$sphinxbase/prim\+\_\+type.\+h$>$}\\*
{\ttfamily \#include $<$sphinxbase/ad.\+h$>$}\\*
{\ttfamily \#include $<$stdio.\+h$>$}\\*
\subsection*{Data Structures}
\begin{DoxyCompactItemize}
\item 
struct {\bf spseg\+\_\+s}
\item 
struct {\bf cont\+\_\+ad\+\_\+t}
\begin{DoxyCompactList}\small\item\em Continuous listening module or object Continuous listening module or object. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Macros}
\begin{DoxyCompactItemize}
\item 
\#define {\bfseries C\+O\+N\+T\+\_\+\+A\+D\+\_\+\+S\+T\+A\+T\+E\+\_\+\+S\+I\+L}~0\label{cont__ad_8h_a2b7422b8273b64e5c9909f0d4ed2a109}

\item 
\#define {\bfseries C\+O\+N\+T\+\_\+\+A\+D\+\_\+\+S\+T\+A\+T\+E\+\_\+\+S\+P\+E\+E\+C\+H}~1\label{cont__ad_8h_aa9664991fbf6001a8ee29e9be7dd667c}

\end{DoxyCompactItemize}
\subsection*{Typedefs}
\begin{DoxyCompactItemize}
\item 
typedef struct {\bf spseg\+\_\+s} {\bfseries spseg\+\_\+t}\label{cont__ad_8h_a5153bcdd6b0bb75c8c37482a3c312c3d}

\end{DoxyCompactItemize}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T {\bf cont\+\_\+ad\+\_\+t} $\ast$ {\bf cont\+\_\+ad\+\_\+init} ({\bf ad\+\_\+rec\+\_\+t} $\ast$ad, int32($\ast$adfunc)({\bf ad\+\_\+rec\+\_\+t} $\ast$ad, int16 $\ast$buf, int32 max))
\begin{DoxyCompactList}\small\item\em Initialize a continuous listening/silence filtering object. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T {\bf cont\+\_\+ad\+\_\+t} $\ast$ {\bf cont\+\_\+ad\+\_\+init\+\_\+rawmode} ({\bf ad\+\_\+rec\+\_\+t} $\ast$ad, int32($\ast$adfunc)({\bf ad\+\_\+rec\+\_\+t} $\ast$ad, int16 $\ast$buf, int32 max))
\begin{DoxyCompactList}\small\item\em Initializes a continuous listening object which simply passes data through (!) \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int32 {\bf cont\+\_\+ad\+\_\+read} ({\bf cont\+\_\+ad\+\_\+t} $\ast$r, int16 $\ast$buf, int32 max)
\begin{DoxyCompactList}\small\item\em Read raw audio data into the silence filter. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int32 {\bf cont\+\_\+ad\+\_\+buffer\+\_\+space} ({\bf cont\+\_\+ad\+\_\+t} $\ast$r)\label{cont__ad_8h_a680721acc14ac191bbae3a4940ed357d}

\begin{DoxyCompactList}\small\item\em Get the maximum number of samples which can be passed into \doxyref{cont\+\_\+ad\+\_\+read()}{p.}{cont__ad_8h_ae664132adc514db01a1d5c1209ded4ba}. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int32 {\bf cont\+\_\+ad\+\_\+calib} ({\bf cont\+\_\+ad\+\_\+t} $\ast$cont)
\begin{DoxyCompactList}\small\item\em Calibrate the silence filter. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int32 {\bf cont\+\_\+ad\+\_\+calib\+\_\+loop} ({\bf cont\+\_\+ad\+\_\+t} $\ast$r, int16 $\ast$buf, int32 max)
\begin{DoxyCompactList}\small\item\em Calibrate the silence filter without an audio device. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int32 {\bf cont\+\_\+ad\+\_\+calib\+\_\+size} ({\bf cont\+\_\+ad\+\_\+t} $\ast$r)
\begin{DoxyCompactList}\small\item\em Get the number of samples required to calibrate the silence filter. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int32 {\bf cont\+\_\+ad\+\_\+set\+\_\+thresh} ({\bf cont\+\_\+ad\+\_\+t} $\ast$cont, int32 sil, int32 sp)
\begin{DoxyCompactList}\small\item\em Set silence and speech threshold parameters. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int32 {\bf cont\+\_\+ad\+\_\+set\+\_\+params} ({\bf cont\+\_\+ad\+\_\+t} $\ast$r, int32 delta\+\_\+sil, int32 delta\+\_\+speech, int32 min\+\_\+noise, int32 max\+\_\+noise, int32 winsize, int32 speech\+\_\+onset, int32 sil\+\_\+onset, int32 leader, int32 trailer, float32 adapt\+\_\+rate)
\begin{DoxyCompactList}\small\item\em Set the changable parameters. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int32 {\bf cont\+\_\+ad\+\_\+get\+\_\+params} ({\bf cont\+\_\+ad\+\_\+t} $\ast$r, int32 $\ast$delta\+\_\+sil, int32 $\ast$delta\+\_\+speech, int32 $\ast$min\+\_\+noise, int32 $\ast$max\+\_\+noise, int32 $\ast$winsize, int32 $\ast$speech\+\_\+onset, int32 $\ast$sil\+\_\+onset, int32 $\ast$leader, int32 $\ast$trailer, float32 $\ast$adapt\+\_\+rate)
\begin{DoxyCompactList}\small\item\em P\+W\+P 1/14/98 -- get the changable params. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int32 {\bf cont\+\_\+ad\+\_\+reset} ({\bf cont\+\_\+ad\+\_\+t} $\ast$cont)
\begin{DoxyCompactList}\small\item\em Reset, discarding any accumulated speech segments. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int32 {\bf cont\+\_\+ad\+\_\+close} ({\bf cont\+\_\+ad\+\_\+t} $\ast$cont)\label{cont__ad_8h_a381c3df971d43a20e8e8b8da43d2872d}

\begin{DoxyCompactList}\small\item\em Close the continuous listening object. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T void {\bf cont\+\_\+ad\+\_\+powhist\+\_\+dump} (F\+I\+L\+E $\ast$fp, {\bf cont\+\_\+ad\+\_\+t} $\ast$cont)
\begin{DoxyCompactList}\small\item\em Dump the power histogram. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int32 {\bf cont\+\_\+ad\+\_\+detach} ({\bf cont\+\_\+ad\+\_\+t} $\ast$c)
\begin{DoxyCompactList}\small\item\em Detach the given continuous listening module from the associated audio device. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int32 {\bf cont\+\_\+ad\+\_\+attach} ({\bf cont\+\_\+ad\+\_\+t} $\ast$c, {\bf ad\+\_\+rec\+\_\+t} $\ast$a, int32($\ast$func)({\bf ad\+\_\+rec\+\_\+t} $\ast$, int16 $\ast$, int32))
\begin{DoxyCompactList}\small\item\em Attach the continuous listening module to the given audio device/function. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int32 {\bf cont\+\_\+ad\+\_\+set\+\_\+rawfp} ({\bf cont\+\_\+ad\+\_\+t} $\ast$c, F\+I\+L\+E $\ast$fp)
\begin{DoxyCompactList}\small\item\em Set a file for dumping raw audio input. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int32 {\bf cont\+\_\+ad\+\_\+set\+\_\+logfp} ({\bf cont\+\_\+ad\+\_\+t} $\ast$c, F\+I\+L\+E $\ast$fp)
\begin{DoxyCompactList}\small\item\em Set the file to which cont\+\_\+ad logs its progress. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int32 {\bf cont\+\_\+set\+\_\+thresh} ({\bf cont\+\_\+ad\+\_\+t} $\ast$r, int32 silence, int32 speech)
\begin{DoxyCompactList}\small\item\em Set the silence and speech thresholds. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}
Continuous A/\+D listening and silence filtering module. 

This module is intended to be interposed as a filter between any raw A/\+D source and the application to remove silence regions. Its main purpose is to remove regions of silence from the raw input speech. It is initialized with a raw A/\+D source function (during the cont\+\_\+ad\+\_\+init call). The application is responsible for setting up the A/\+D source, turning recording on and off as it desires. Filtered A/\+D data can be read by the application using the cont\+\_\+ad\+\_\+read function.

In other words, the application calls cont\+\_\+ad\+\_\+read instead of the raw A/\+D source function (e.\+g., ad\+\_\+read in libad) to obtain filtered A/\+D data with silence regions removed. This module itself does not enforce any other structural changes to the application.

The cont\+\_\+ad\+\_\+read function also updates an \char`\"{}absolute\char`\"{} timestamp (see \doxyref{cont\+\_\+ad\+\_\+t.\+read\+\_\+ts}{p.}{structcont__ad__t_a7b71e87abfcb3ca4ae73af34c86f955e}) at the end of each invocation. The timestamp indicates the total number of samples of A/\+D data read until this point, including data discarded as silence frames. The application is responsible for using this timestamp to make any policy decisions regarding utterance boundaries or whatever. 

Definition in file {\bf cont\+\_\+ad.\+h}.



\subsection{Function Documentation}
\index{cont\+\_\+ad.\+h@{cont\+\_\+ad.\+h}!cont\+\_\+ad\+\_\+attach@{cont\+\_\+ad\+\_\+attach}}
\index{cont\+\_\+ad\+\_\+attach@{cont\+\_\+ad\+\_\+attach}!cont\+\_\+ad.\+h@{cont\+\_\+ad.\+h}}
\subsubsection[{cont\+\_\+ad\+\_\+attach}]{\setlength{\rightskip}{0pt plus 5cm}S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int32 cont\+\_\+ad\+\_\+attach (
\begin{DoxyParamCaption}
\item[{{\bf cont\+\_\+ad\+\_\+t} $\ast$}]{c, }
\item[{{\bf ad\+\_\+rec\+\_\+t} $\ast$}]{a, }
\item[{int32($\ast$)({\bf ad\+\_\+rec\+\_\+t} $\ast$, int16 $\ast$, int32)}]{func}
\end{DoxyParamCaption}
)}\label{cont__ad_8h_a41e7f8c5925dba26dd51e8f7a3d16404}


Attach the continuous listening module to the given audio device/function. 

(Like cont\+\_\+ad\+\_\+init, but without the calibration.) \begin{DoxyReturn}{Returns}
0 if successful, -\/1 otherwise. 
\end{DoxyReturn}


Definition at line 1293 of file cont\+\_\+ad\+\_\+base.\+c.



References cont\+\_\+ad\+\_\+t\+::ad, and cont\+\_\+ad\+\_\+t\+::eof.

\index{cont\+\_\+ad.\+h@{cont\+\_\+ad.\+h}!cont\+\_\+ad\+\_\+calib@{cont\+\_\+ad\+\_\+calib}}
\index{cont\+\_\+ad\+\_\+calib@{cont\+\_\+ad\+\_\+calib}!cont\+\_\+ad.\+h@{cont\+\_\+ad.\+h}}
\subsubsection[{cont\+\_\+ad\+\_\+calib}]{\setlength{\rightskip}{0pt plus 5cm}S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int32 cont\+\_\+ad\+\_\+calib (
\begin{DoxyParamCaption}
\item[{{\bf cont\+\_\+ad\+\_\+t} $\ast$}]{cont}
\end{DoxyParamCaption}
)}\label{cont__ad_8h_a7a1d0eaf8292a4549b00a97163999321}


Calibrate the silence filter. 

Calibration to determine an initial silence threshold. This function can be called any number of times. It should be called at least once immediately after cont\+\_\+ad\+\_\+init. The silence threshold is also updated internally once in a while, so this function only needs to be called in the middle if there is a definite change in the recording environment. The application is responsible for making sure that the raw audio source is turned on before the calibration. Return value\+: 0 if successful, $<$0 otherwise. 
\begin{DoxyParams}{Parameters}
{\em cont} & In\+: object pointer returned by cont\+\_\+ad\+\_\+init \\
\hline
\end{DoxyParams}


Definition at line 1022 of file cont\+\_\+ad\+\_\+base.\+c.



References cont\+\_\+ad\+\_\+t\+::ad, cont\+\_\+ad\+\_\+t\+::adbuf, cont\+\_\+ad\+\_\+t\+::headfrm, cont\+\_\+ad\+\_\+t\+::n\+\_\+calib\+\_\+frame, cont\+\_\+ad\+\_\+t\+::n\+\_\+frm, cont\+\_\+ad\+\_\+t\+::pow\+\_\+hist, cont\+\_\+ad\+\_\+t\+::spf, and cont\+\_\+ad\+\_\+t\+::thresh\+\_\+update.

\index{cont\+\_\+ad.\+h@{cont\+\_\+ad.\+h}!cont\+\_\+ad\+\_\+calib\+\_\+loop@{cont\+\_\+ad\+\_\+calib\+\_\+loop}}
\index{cont\+\_\+ad\+\_\+calib\+\_\+loop@{cont\+\_\+ad\+\_\+calib\+\_\+loop}!cont\+\_\+ad.\+h@{cont\+\_\+ad.\+h}}
\subsubsection[{cont\+\_\+ad\+\_\+calib\+\_\+loop}]{\setlength{\rightskip}{0pt plus 5cm}S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int32 cont\+\_\+ad\+\_\+calib\+\_\+loop (
\begin{DoxyParamCaption}
\item[{{\bf cont\+\_\+ad\+\_\+t} $\ast$}]{r, }
\item[{int16 $\ast$}]{buf, }
\item[{int32}]{max}
\end{DoxyParamCaption}
)}\label{cont__ad_8h_a8a575044cf22d96a5ec8fb20410b0065}


Calibrate the silence filter without an audio device. 

If the application has not passed an audio device into the silence filter at initialisation, this routine can be used to calibrate the filter. The buf (of length max samples) should contain audio data for calibration. This data is assumed to be completely consumed. More than one call may be necessary to fully calibrate. Return value\+: 0 if successful, $<$0 on failure, $>$0 if calibration not complete. 

Definition at line 1064 of file cont\+\_\+ad\+\_\+base.\+c.



References cont\+\_\+ad\+\_\+t\+::adbuf, cont\+\_\+ad\+\_\+t\+::headfrm, cont\+\_\+ad\+\_\+t\+::n\+\_\+calib\+\_\+frame, cont\+\_\+ad\+\_\+t\+::n\+\_\+frm, cont\+\_\+ad\+\_\+t\+::pow\+\_\+hist, cont\+\_\+ad\+\_\+t\+::spf, and cont\+\_\+ad\+\_\+t\+::thresh\+\_\+update.

\index{cont\+\_\+ad.\+h@{cont\+\_\+ad.\+h}!cont\+\_\+ad\+\_\+calib\+\_\+size@{cont\+\_\+ad\+\_\+calib\+\_\+size}}
\index{cont\+\_\+ad\+\_\+calib\+\_\+size@{cont\+\_\+ad\+\_\+calib\+\_\+size}!cont\+\_\+ad.\+h@{cont\+\_\+ad.\+h}}
\subsubsection[{cont\+\_\+ad\+\_\+calib\+\_\+size}]{\setlength{\rightskip}{0pt plus 5cm}S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int32 cont\+\_\+ad\+\_\+calib\+\_\+size (
\begin{DoxyParamCaption}
\item[{{\bf cont\+\_\+ad\+\_\+t} $\ast$}]{r}
\end{DoxyParamCaption}
)}\label{cont__ad_8h_a6a86e16fb673748be753e2a281ce837a}


Get the number of samples required to calibrate the silence filter. 

Since, as mentioned above, the calibration data is assumed to be fully consumed, it may be desirable to \char`\"{}hold onto\char`\"{} this data in case it contains useful speech. This function returns the number of samples required to calibrate the silence filter, which is useful in allocating a buffer to store this data.

\begin{DoxyReturn}{Returns}
Number of samples required for successful calibration. 
\end{DoxyReturn}


Definition at line 1058 of file cont\+\_\+ad\+\_\+base.\+c.



References cont\+\_\+ad\+\_\+t\+::spf.

\index{cont\+\_\+ad.\+h@{cont\+\_\+ad.\+h}!cont\+\_\+ad\+\_\+detach@{cont\+\_\+ad\+\_\+detach}}
\index{cont\+\_\+ad\+\_\+detach@{cont\+\_\+ad\+\_\+detach}!cont\+\_\+ad.\+h@{cont\+\_\+ad.\+h}}
\subsubsection[{cont\+\_\+ad\+\_\+detach}]{\setlength{\rightskip}{0pt plus 5cm}S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int32 cont\+\_\+ad\+\_\+detach (
\begin{DoxyParamCaption}
\item[{{\bf cont\+\_\+ad\+\_\+t} $\ast$}]{c}
\end{DoxyParamCaption}
)}\label{cont__ad_8h_a8f8284f329d1c0e04856ec9d13020dc4}


Detach the given continuous listening module from the associated audio device. 

\begin{DoxyReturn}{Returns}
0 if successful, -\/1 otherwise. 
\end{DoxyReturn}


Definition at line 1281 of file cont\+\_\+ad\+\_\+base.\+c.



References cont\+\_\+ad\+\_\+t\+::ad.

\index{cont\+\_\+ad.\+h@{cont\+\_\+ad.\+h}!cont\+\_\+ad\+\_\+get\+\_\+params@{cont\+\_\+ad\+\_\+get\+\_\+params}}
\index{cont\+\_\+ad\+\_\+get\+\_\+params@{cont\+\_\+ad\+\_\+get\+\_\+params}!cont\+\_\+ad.\+h@{cont\+\_\+ad.\+h}}
\subsubsection[{cont\+\_\+ad\+\_\+get\+\_\+params}]{\setlength{\rightskip}{0pt plus 5cm}S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int32 cont\+\_\+ad\+\_\+get\+\_\+params (
\begin{DoxyParamCaption}
\item[{{\bf cont\+\_\+ad\+\_\+t} $\ast$}]{r, }
\item[{int32 $\ast$}]{delta\+\_\+sil, }
\item[{int32 $\ast$}]{delta\+\_\+speech, }
\item[{int32 $\ast$}]{min\+\_\+noise, }
\item[{int32 $\ast$}]{max\+\_\+noise, }
\item[{int32 $\ast$}]{winsize, }
\item[{int32 $\ast$}]{speech\+\_\+onset, }
\item[{int32 $\ast$}]{sil\+\_\+onset, }
\item[{int32 $\ast$}]{leader, }
\item[{int32 $\ast$}]{trailer, }
\item[{float32 $\ast$}]{adapt\+\_\+rate}
\end{DoxyParamCaption}
)}\label{cont__ad_8h_aedd013bc2c6aca14fba02049ed7645d7}


P\+W\+P 1/14/98 -- get the changable params. 

delta\+\_\+sil, delta\+\_\+speech, min\+\_\+noise, and max\+\_\+noise are in d\+B, winsize, speech\+\_\+onset, sil\+\_\+onset, leader and trailer are in frames of 16 ms length (256 samples @ 16k\+Hz sampling). 

Definition at line 1199 of file cont\+\_\+ad\+\_\+base.\+c.



References cont\+\_\+ad\+\_\+t\+::adapt\+\_\+rate, cont\+\_\+ad\+\_\+t\+::delta\+\_\+sil, cont\+\_\+ad\+\_\+t\+::delta\+\_\+speech, cont\+\_\+ad\+\_\+t\+::leader, cont\+\_\+ad\+\_\+t\+::max\+\_\+noise, cont\+\_\+ad\+\_\+t\+::min\+\_\+noise, cont\+\_\+ad\+\_\+t\+::sil\+\_\+onset, cont\+\_\+ad\+\_\+t\+::speech\+\_\+onset, cont\+\_\+ad\+\_\+t\+::trailer, and cont\+\_\+ad\+\_\+t\+::winsize.

\index{cont\+\_\+ad.\+h@{cont\+\_\+ad.\+h}!cont\+\_\+ad\+\_\+init@{cont\+\_\+ad\+\_\+init}}
\index{cont\+\_\+ad\+\_\+init@{cont\+\_\+ad\+\_\+init}!cont\+\_\+ad.\+h@{cont\+\_\+ad.\+h}}
\subsubsection[{cont\+\_\+ad\+\_\+init}]{\setlength{\rightskip}{0pt plus 5cm}S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T {\bf cont\+\_\+ad\+\_\+t}$\ast$ cont\+\_\+ad\+\_\+init (
\begin{DoxyParamCaption}
\item[{{\bf ad\+\_\+rec\+\_\+t} $\ast$}]{ad, }
\item[{int32($\ast$)({\bf ad\+\_\+rec\+\_\+t} $\ast$ad, int16 $\ast$buf, int32 max)}]{adfunc}
\end{DoxyParamCaption}
)}\label{cont__ad_8h_af28bf56f17d5cfebf4d960ebed44ca64}


Initialize a continuous listening/silence filtering object. 

One time initialization of a continuous listening/silence filtering object/module. This can work in either \char`\"{}stream mode\char`\"{}, where it reads data from an audio device represented by {\ttfamily \doxyref{ad\+\_\+rec\+\_\+t}{p.}{structad__rec__t}}, or in \char`\"{}block mode\char`\"{}, where it filters out silence regions from blocks of data passed into it.


\begin{DoxyParams}{Parameters}
{\em ad} & An audio device to read from, or N\+U\+L\+L to operate in block mode. \\
\hline
{\em adfunc} & The function used to read audio from {\ttfamily ad}, or N\+U\+L\+L to operate in block mode. This is usually ad\+\_\+read(). \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
A pointer to a R\+E\+A\+D-\/\+O\+N\+L\+Y structure used in other calls to the object. If any error occurs, the return value is N\+U\+L\+L. 
\end{DoxyReturn}

\begin{DoxyParams}{Parameters}
{\em ad} & In\+: The A/\+D source object to be filtered \\
\hline
{\em adfunc} & In\+: adfunc = source function to be invoked to obtain raw A/\+D data. See \doxyref{ad.\+h}{p.}{ad_8h} for the required prototype definition. \\
\hline
\end{DoxyParams}
\index{cont\+\_\+ad.\+h@{cont\+\_\+ad.\+h}!cont\+\_\+ad\+\_\+init\+\_\+rawmode@{cont\+\_\+ad\+\_\+init\+\_\+rawmode}}
\index{cont\+\_\+ad\+\_\+init\+\_\+rawmode@{cont\+\_\+ad\+\_\+init\+\_\+rawmode}!cont\+\_\+ad.\+h@{cont\+\_\+ad.\+h}}
\subsubsection[{cont\+\_\+ad\+\_\+init\+\_\+rawmode}]{\setlength{\rightskip}{0pt plus 5cm}S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T {\bf cont\+\_\+ad\+\_\+t}$\ast$ cont\+\_\+ad\+\_\+init\+\_\+rawmode (
\begin{DoxyParamCaption}
\item[{{\bf ad\+\_\+rec\+\_\+t} $\ast$}]{ad, }
\item[{int32($\ast$)({\bf ad\+\_\+rec\+\_\+t} $\ast$ad, int16 $\ast$buf, int32 max)}]{adfunc}
\end{DoxyParamCaption}
)}\label{cont__ad_8h_a1a9bbf961917827f5d03adcd409dda35}


Initializes a continuous listening object which simply passes data through (!) 

Like cont\+\_\+ad\+\_\+init, but put the module in raw mode; i.\+e., all data is passed through, unfiltered. (By special request.) \index{cont\+\_\+ad.\+h@{cont\+\_\+ad.\+h}!cont\+\_\+ad\+\_\+powhist\+\_\+dump@{cont\+\_\+ad\+\_\+powhist\+\_\+dump}}
\index{cont\+\_\+ad\+\_\+powhist\+\_\+dump@{cont\+\_\+ad\+\_\+powhist\+\_\+dump}!cont\+\_\+ad.\+h@{cont\+\_\+ad.\+h}}
\subsubsection[{cont\+\_\+ad\+\_\+powhist\+\_\+dump}]{\setlength{\rightskip}{0pt plus 5cm}S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T void cont\+\_\+ad\+\_\+powhist\+\_\+dump (
\begin{DoxyParamCaption}
\item[{F\+I\+L\+E $\ast$}]{fp, }
\item[{{\bf cont\+\_\+ad\+\_\+t} $\ast$}]{cont}
\end{DoxyParamCaption}
)}\label{cont__ad_8h_a288394cd94a4992bec9d3911cc875767}


Dump the power histogram. 

For debugging... 

Definition at line 231 of file cont\+\_\+ad\+\_\+base.\+c.



References cont\+\_\+ad\+\_\+t\+::pow\+\_\+hist, cont\+\_\+ad\+\_\+t\+::spf, cont\+\_\+ad\+\_\+t\+::sps, and cont\+\_\+ad\+\_\+t\+::tot\+\_\+frm.

\index{cont\+\_\+ad.\+h@{cont\+\_\+ad.\+h}!cont\+\_\+ad\+\_\+read@{cont\+\_\+ad\+\_\+read}}
\index{cont\+\_\+ad\+\_\+read@{cont\+\_\+ad\+\_\+read}!cont\+\_\+ad.\+h@{cont\+\_\+ad.\+h}}
\subsubsection[{cont\+\_\+ad\+\_\+read}]{\setlength{\rightskip}{0pt plus 5cm}S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int32 cont\+\_\+ad\+\_\+read (
\begin{DoxyParamCaption}
\item[{{\bf cont\+\_\+ad\+\_\+t} $\ast$}]{r, }
\item[{int16 $\ast$}]{buf, }
\item[{int32}]{max}
\end{DoxyParamCaption}
)}\label{cont__ad_8h_ae664132adc514db01a1d5c1209ded4ba}


Read raw audio data into the silence filter. 

The main read routine for reading speech/silence segmented audio data. Audio data is copied into the caller provided buffer, much like a file read routine.

In \char`\"{}block mode\char`\"{}, i.\+e. if N\+U\+L\+L was passed as a read function to {\ttfamily cont\+\_\+ad\+\_\+init}, the data in {\ttfamily buf} is taken as input, and any non-\/silence data is written back to {\ttfamily buf} on exit. In this case, you must take care that {\ttfamily max} does not overflow the internal buffer of the silence filter. The available number of samples can be obtained by calling \doxyref{cont\+\_\+ad\+\_\+buffer\+\_\+space()}{p.}{cont__ad_8h_a680721acc14ac191bbae3a4940ed357d}. Any excess data will be discarded.

In normal mode, only speech segments are copied; silence segments are dropped. In rawmode (cont\+\_\+ad module initialized using \doxyref{cont\+\_\+ad\+\_\+init\+\_\+rawmode()}{p.}{cont__ad_8h_a1a9bbf961917827f5d03adcd409dda35}), all data are passed through to the caller. But, in either case, any single call to cont\+\_\+ad\+\_\+read will never return data that crosses a speech/silence segment boundary.

The following variables are updated for use by the caller (see \doxyref{cont\+\_\+ad\+\_\+t}{p.}{structcont__ad__t} above)\+: \doxyref{cont\+\_\+ad\+\_\+t.\+state}{p.}{structcont__ad__t_a5d9420ea711733d1eea9b8f29a638fdb}, \doxyref{cont\+\_\+ad\+\_\+t.\+read\+\_\+ts}{p.}{structcont__ad__t_a7b71e87abfcb3ca4ae73af34c86f955e}, \doxyref{cont\+\_\+ad\+\_\+t.\+seglen}{p.}{structcont__ad__t_a478939247e09a8ae142c8996ec17d8c8}, \doxyref{cont\+\_\+ad\+\_\+t.\+siglvl}{p.}{structcont__ad__t_a5524c052dcd0a3d1a1c3b1fc2134b62e}.

Return value\+: Number of samples actually read, possibly 0; $<$0 if E\+O\+F on A/\+D source. 
\begin{DoxyParams}{Parameters}
{\em r} & In\+: Object pointer returned by cont\+\_\+ad\+\_\+init \\
\hline
{\em buf} & In/\+Out\+: In block mode, contains input data. On return, buf contains A/\+D data returned by this function, if any. \\
\hline
{\em max} & In\+: Maximum number of samples to be filled into buf. N\+O\+T\+E\+: max must be at least 256; otherwise the functions returns -\/1. \\
\hline
\end{DoxyParams}


Definition at line 863 of file cont\+\_\+ad\+\_\+base.\+c.



References E\+\_\+\+E\+R\+R\+O\+R, cont\+\_\+ad\+\_\+t\+::eof, cont\+\_\+ad\+\_\+t\+::headfrm, cont\+\_\+ad\+\_\+t\+::leader, cont\+\_\+ad\+\_\+t\+::logfp, cont\+\_\+ad\+\_\+t\+::n\+\_\+frm, cont\+\_\+ad\+\_\+t\+::n\+\_\+other, cont\+\_\+ad\+\_\+t\+::n\+\_\+sample, cont\+\_\+ad\+\_\+t\+::rawmode, cont\+\_\+ad\+\_\+t\+::read\+\_\+ts, cont\+\_\+ad\+\_\+t\+::seglen, cont\+\_\+ad\+\_\+t\+::siglvl, cont\+\_\+ad\+\_\+t\+::spf, cont\+\_\+ad\+\_\+t\+::spseg\+\_\+head, cont\+\_\+ad\+\_\+t\+::spseg\+\_\+tail, cont\+\_\+ad\+\_\+t\+::state, cont\+\_\+ad\+\_\+t\+::tail\+\_\+state, cont\+\_\+ad\+\_\+t\+::tot\+\_\+frm, cont\+\_\+ad\+\_\+t\+::win\+\_\+startfrm, cont\+\_\+ad\+\_\+t\+::win\+\_\+validfrm, and cont\+\_\+ad\+\_\+t\+::winsize.

\index{cont\+\_\+ad.\+h@{cont\+\_\+ad.\+h}!cont\+\_\+ad\+\_\+reset@{cont\+\_\+ad\+\_\+reset}}
\index{cont\+\_\+ad\+\_\+reset@{cont\+\_\+ad\+\_\+reset}!cont\+\_\+ad.\+h@{cont\+\_\+ad.\+h}}
\subsubsection[{cont\+\_\+ad\+\_\+reset}]{\setlength{\rightskip}{0pt plus 5cm}S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int32 cont\+\_\+ad\+\_\+reset (
\begin{DoxyParamCaption}
\item[{{\bf cont\+\_\+ad\+\_\+t} $\ast$}]{cont}
\end{DoxyParamCaption}
)}\label{cont__ad_8h_a12a017ea8a96dc54445e937bb9de24ae}


Reset, discarding any accumulated speech segments. 

\begin{DoxyReturn}{Returns}
0 if successful, $<$0 otherwise. 
\end{DoxyReturn}


Definition at line 1236 of file cont\+\_\+ad\+\_\+base.\+c.



References cont\+\_\+ad\+\_\+t\+::headfrm, cont\+\_\+ad\+\_\+t\+::n\+\_\+frm, cont\+\_\+ad\+\_\+t\+::n\+\_\+other, cont\+\_\+ad\+\_\+t\+::n\+\_\+sample, cont\+\_\+ad\+\_\+t\+::spseg\+\_\+head, cont\+\_\+ad\+\_\+t\+::spseg\+\_\+tail, cont\+\_\+ad\+\_\+t\+::tail\+\_\+state, cont\+\_\+ad\+\_\+t\+::win\+\_\+startfrm, and cont\+\_\+ad\+\_\+t\+::win\+\_\+validfrm.



Referenced by cont\+\_\+ad\+\_\+close().

\index{cont\+\_\+ad.\+h@{cont\+\_\+ad.\+h}!cont\+\_\+ad\+\_\+set\+\_\+logfp@{cont\+\_\+ad\+\_\+set\+\_\+logfp}}
\index{cont\+\_\+ad\+\_\+set\+\_\+logfp@{cont\+\_\+ad\+\_\+set\+\_\+logfp}!cont\+\_\+ad.\+h@{cont\+\_\+ad.\+h}}
\subsubsection[{cont\+\_\+ad\+\_\+set\+\_\+logfp}]{\setlength{\rightskip}{0pt plus 5cm}S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int32 cont\+\_\+ad\+\_\+set\+\_\+logfp (
\begin{DoxyParamCaption}
\item[{{\bf cont\+\_\+ad\+\_\+t} $\ast$}]{c, }
\item[{F\+I\+L\+E $\ast$}]{fp}
\end{DoxyParamCaption}
)}\label{cont__ad_8h_a16c5810eb19ed89522ef4c3394bbfe83}


Set the file to which cont\+\_\+ad logs its progress. 

Mainly for debugging. If {\ttfamily fp} is N\+U\+L\+L, logging is turned off.

\begin{DoxyReturn}{Returns}
0 if successful, -\/1 otherwise. 
\end{DoxyReturn}


Definition at line 1360 of file cont\+\_\+ad\+\_\+base.\+c.



References cont\+\_\+ad\+\_\+t\+::logfp.

\index{cont\+\_\+ad.\+h@{cont\+\_\+ad.\+h}!cont\+\_\+ad\+\_\+set\+\_\+params@{cont\+\_\+ad\+\_\+set\+\_\+params}}
\index{cont\+\_\+ad\+\_\+set\+\_\+params@{cont\+\_\+ad\+\_\+set\+\_\+params}!cont\+\_\+ad.\+h@{cont\+\_\+ad.\+h}}
\subsubsection[{cont\+\_\+ad\+\_\+set\+\_\+params}]{\setlength{\rightskip}{0pt plus 5cm}S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int32 cont\+\_\+ad\+\_\+set\+\_\+params (
\begin{DoxyParamCaption}
\item[{{\bf cont\+\_\+ad\+\_\+t} $\ast$}]{r, }
\item[{int32}]{delta\+\_\+sil, }
\item[{int32}]{delta\+\_\+speech, }
\item[{int32}]{min\+\_\+noise, }
\item[{int32}]{max\+\_\+noise, }
\item[{int32}]{winsize, }
\item[{int32}]{speech\+\_\+onset, }
\item[{int32}]{sil\+\_\+onset, }
\item[{int32}]{leader, }
\item[{int32}]{trailer, }
\item[{float32}]{adapt\+\_\+rate}
\end{DoxyParamCaption}
)}\label{cont__ad_8h_aa402397c575922ea352afe5e66c02a34}


Set the changable parameters. 

delta\+\_\+sil, delta\+\_\+speech, min\+\_\+noise, and max\+\_\+noise are in d\+B, winsize, speech\+\_\+onset, sil\+\_\+onset, leader and trailer are in frames of 16 ms length (256 samples @ 16k\+Hz sampling). 

Definition at line 1126 of file cont\+\_\+ad\+\_\+base.\+c.



References cont\+\_\+ad\+\_\+t\+::adapt\+\_\+rate, cont\+\_\+ad\+\_\+t\+::delta\+\_\+sil, cont\+\_\+ad\+\_\+t\+::delta\+\_\+speech, E\+\_\+\+E\+R\+R\+O\+R, cont\+\_\+ad\+\_\+t\+::leader, cont\+\_\+ad\+\_\+t\+::max\+\_\+noise, cont\+\_\+ad\+\_\+t\+::min\+\_\+noise, cont\+\_\+ad\+\_\+t\+::sil\+\_\+onset, cont\+\_\+ad\+\_\+t\+::speech\+\_\+onset, cont\+\_\+ad\+\_\+t\+::trailer, cont\+\_\+ad\+\_\+t\+::win\+\_\+validfrm, and cont\+\_\+ad\+\_\+t\+::winsize.

\index{cont\+\_\+ad.\+h@{cont\+\_\+ad.\+h}!cont\+\_\+ad\+\_\+set\+\_\+rawfp@{cont\+\_\+ad\+\_\+set\+\_\+rawfp}}
\index{cont\+\_\+ad\+\_\+set\+\_\+rawfp@{cont\+\_\+ad\+\_\+set\+\_\+rawfp}!cont\+\_\+ad.\+h@{cont\+\_\+ad.\+h}}
\subsubsection[{cont\+\_\+ad\+\_\+set\+\_\+rawfp}]{\setlength{\rightskip}{0pt plus 5cm}S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int32 cont\+\_\+ad\+\_\+set\+\_\+rawfp (
\begin{DoxyParamCaption}
\item[{{\bf cont\+\_\+ad\+\_\+t} $\ast$}]{c, }
\item[{F\+I\+L\+E $\ast$}]{fp}
\end{DoxyParamCaption}
)}\label{cont__ad_8h_a662ed7c409479060e3b5ac8eb7bd1865}


Set a file for dumping raw audio input. 

The application can ask cont\+\_\+ad to dump the raw audio input that cont\+\_\+ad processes to a file. Use this function to give the F\+I\+L\+E$\ast$ to the cont\+\_\+ad object. If invoked with fp == N\+U\+L\+L, dumping is turned off. The application is responsible for opening and closing the file. If fp is non-\/\+N\+U\+L\+L, cont\+\_\+ad assumes the file pointer is valid and opened for writing.

\begin{DoxyReturn}{Returns}
0 if successful, -\/1 otherwise. 
\end{DoxyReturn}


Definition at line 1346 of file cont\+\_\+ad\+\_\+base.\+c.



References cont\+\_\+ad\+\_\+t\+::rawfp.

\index{cont\+\_\+ad.\+h@{cont\+\_\+ad.\+h}!cont\+\_\+ad\+\_\+set\+\_\+thresh@{cont\+\_\+ad\+\_\+set\+\_\+thresh}}
\index{cont\+\_\+ad\+\_\+set\+\_\+thresh@{cont\+\_\+ad\+\_\+set\+\_\+thresh}!cont\+\_\+ad.\+h@{cont\+\_\+ad.\+h}}
\subsubsection[{cont\+\_\+ad\+\_\+set\+\_\+thresh}]{\setlength{\rightskip}{0pt plus 5cm}S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int32 cont\+\_\+ad\+\_\+set\+\_\+thresh (
\begin{DoxyParamCaption}
\item[{{\bf cont\+\_\+ad\+\_\+t} $\ast$}]{cont, }
\item[{int32}]{sil, }
\item[{int32}]{sp}
\end{DoxyParamCaption}
)}\label{cont__ad_8h_af9a8f9f66bbfd1ce48fe9366fafcc40d}


Set silence and speech threshold parameters. 

The silence threshold is the max power level, R\+E\+L\+A\+T\+I\+V\+E to the peak background noise level, in any silence frame. Similarly, the speech threshold is the min power level, R\+E\+L\+A\+T\+I\+V\+E to the peak background noise level, in any speech frame. In general, silence threshold $<$= speech threshold. Increasing the thresholds (say, from the default value of 2 to 3 or 4) reduces the sensitivity to background noise, but may also increase the chances of clipping actual speech. \begin{DoxyReturn}{Returns}
\+: 0 if successful, $<$0 otherwise. 
\end{DoxyReturn}

\begin{DoxyParams}{Parameters}
{\em cont} & In\+: Object ptr from cont\+\_\+ad\+\_\+init \\
\hline
{\em sil} & In\+: silence threshold (default 2) \\
\hline
{\em sp} & In\+: speech threshold (default 2) \\
\hline
\end{DoxyParams}


Definition at line 1100 of file cont\+\_\+ad\+\_\+base.\+c.



References cont\+\_\+ad\+\_\+t\+::delta\+\_\+sil, and cont\+\_\+ad\+\_\+t\+::delta\+\_\+speech.

\index{cont\+\_\+ad.\+h@{cont\+\_\+ad.\+h}!cont\+\_\+set\+\_\+thresh@{cont\+\_\+set\+\_\+thresh}}
\index{cont\+\_\+set\+\_\+thresh@{cont\+\_\+set\+\_\+thresh}!cont\+\_\+ad.\+h@{cont\+\_\+ad.\+h}}
\subsubsection[{cont\+\_\+set\+\_\+thresh}]{\setlength{\rightskip}{0pt plus 5cm}S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int32 cont\+\_\+set\+\_\+thresh (
\begin{DoxyParamCaption}
\item[{{\bf cont\+\_\+ad\+\_\+t} $\ast$}]{r, }
\item[{int32}]{silence, }
\item[{int32}]{speech}
\end{DoxyParamCaption}
)}\label{cont__ad_8h_a382fe6375eae57a532c524d68bc3dd24}


Set the silence and speech thresholds. 

For this to remain permanently in effect, the auto\+\_\+thresh field of the continuous listening module should be set to F\+A\+L\+S\+E or 0. Otherwise the thresholds may be modified by the noise-\/ level adaptation. 

Definition at line 1308 of file cont\+\_\+ad\+\_\+base.\+c.



References cont\+\_\+ad\+\_\+t\+::frm\+\_\+pow, cont\+\_\+ad\+\_\+t\+::n\+\_\+other, cont\+\_\+ad\+\_\+t\+::tail\+\_\+state, cont\+\_\+ad\+\_\+t\+::thresh\+\_\+sil, cont\+\_\+ad\+\_\+t\+::thresh\+\_\+speech, cont\+\_\+ad\+\_\+t\+::win\+\_\+startfrm, and cont\+\_\+ad\+\_\+t\+::win\+\_\+validfrm.

