\doxysection{ad\+\_\+alsa.\+c}
\label{ad__alsa_8c_source}\index{src/libsphinxad/ad\_alsa.c@{src/libsphinxad/ad\_alsa.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}{/*\ -\/*-\/\ mode:c;\ indent-\/tabs-\/mode:t;\ c-\/basic-\/offset:4;\ comment-\/column:40\ -\/*-\/}}
\DoxyCodeLine{00038\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00039\ \textcolor{comment}{\ *\ Sphinx\ II\ libad\ (Linux)}}
\DoxyCodeLine{00040\ \textcolor{comment}{\ *\ \string^\string^\string^\string^\string^\string^\string^\string^\string^\string^\string^\string^\string^\string^\string^\string^\string^\string^\string^\string^\string^\string^\string^}}
\DoxyCodeLine{00041\ \textcolor{comment}{\ *\ \$Id:\ ad\_alsa.c,v\ 1.6\ 2001/12/11\ 00:24:48\ lenzo\ Exp\ \$}}
\DoxyCodeLine{00042\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00043\ \textcolor{comment}{\ *\ John\ G.\ Dorsey\ (jd5q+@andrew.cmu.edu)}}
\DoxyCodeLine{00044\ \textcolor{comment}{\ *\ Engineering\ Design\ Research\ Center}}
\DoxyCodeLine{00045\ \textcolor{comment}{\ *\ Carnegie\ Mellon\ University}}
\DoxyCodeLine{00046\ \textcolor{comment}{\ *\ ***************************************************************************}}
\DoxyCodeLine{00047\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00048\ \textcolor{comment}{\ *\ REVISION\ HISTORY}}
\DoxyCodeLine{00049\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00050\ \textcolor{comment}{\ *\ 18-\/Mar-\/2006\ \ David\ Huggins-\/Daines\ <dhuggins@cs.cmu.edu>}}
\DoxyCodeLine{00051\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Update\ this\ to\ the\ ALSA\ 1.0\ API.}}
\DoxyCodeLine{00052\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00053\ \textcolor{comment}{\ *\ 12-\/Dec-\/2000\ \ David\ Huggins-\/Daines\ <dhd@cepstral.com>\ at\ Cepstral\ LLC}}
\DoxyCodeLine{00054\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Make\ this\ at\ least\ compile\ with\ the\ new\ ALSA\ API.}}
\DoxyCodeLine{00055\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00056\ \textcolor{comment}{\ *\ 05-\/Nov-\/1999\ \ Sean\ Levy\ (snl@stalphonsos.com)\ at\ St.\ Alphonsos,\ LLC.}}
\DoxyCodeLine{00057\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Ported\ to\ ALSA\ so\ I\ can\ actually\ get\ working\ full-\/duplex.}}
\DoxyCodeLine{00058\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00059\ \textcolor{comment}{\ *\ 09-\/Aug-\/1999\ \ Kevin\ Lenzo\ (lenzo@cs.cmu.edu)\ at\ Cernegie\ Mellon\ University.}}
\DoxyCodeLine{00060\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Incorporated\ nickr@cs.cmu.edu's\ changes\ (marked\ below)\ and}}
\DoxyCodeLine{00061\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ SPS\_EPSILON\ to\ allow\ for\ sample\ rates\ that\ are\ "{}close\ enough"{}.}}
\DoxyCodeLine{00062\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00063\ \textcolor{comment}{\ *\ 15-\/Jun-\/1999\ \ M.\ K.\ Ravishankar\ (rkm@cs.cmu.edu)\ at\ Carnegie\ Mellon\ Univ.}}
\DoxyCodeLine{00064\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Consolidated\ all\ ad\ functions\ into}}
\DoxyCodeLine{00065\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ this\ one\ file.\ \ Added\ ad\_open\_sps().}}
\DoxyCodeLine{00066\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Other\ cosmetic\ changes\ for\ consistency\ (e.g.,\ use\ of\ err.h).}}
\DoxyCodeLine{00067\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00068\ \textcolor{comment}{\ *\ 18-\/May-\/1999\ \ Kevin\ Lenzo\ (lenzo@cs.cmu.edu)\ added\ <errno.h>.}}
\DoxyCodeLine{00069\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00070\ }
\DoxyCodeLine{00071\ }
\DoxyCodeLine{00072\ \textcolor{preprocessor}{\#include\ <fcntl.h>}}
\DoxyCodeLine{00073\ \textcolor{preprocessor}{\#include\ <stdio.h>}}
\DoxyCodeLine{00074\ \textcolor{preprocessor}{\#include\ <stdlib.h>}}
\DoxyCodeLine{00075\ \textcolor{preprocessor}{\#include\ <string.h>}}
\DoxyCodeLine{00076\ \textcolor{preprocessor}{\#include\ <alsa/asoundlib.h>}}
\DoxyCodeLine{00077\ \textcolor{preprocessor}{\#include\ <errno.h>}}
\DoxyCodeLine{00078\ \textcolor{preprocessor}{\#include\ <config.h>}}
\DoxyCodeLine{00079\ \textcolor{preprocessor}{\#include\ <unistd.h>}}
\DoxyCodeLine{00080\ }
\DoxyCodeLine{00081\ \textcolor{preprocessor}{\#include\ "{}prim\_type.h"{}}}
\DoxyCodeLine{00082\ \textcolor{preprocessor}{\#include\ "{}ad.h"{}}}
\DoxyCodeLine{00083\ }
\DoxyCodeLine{00084\ }
\DoxyCodeLine{00085\ \textcolor{preprocessor}{\#define\ AUDIO\_FORMAT\ SND\_PCM\_SFMT\_S16\_LE\ \ \ \ \ \ \ \ }\textcolor{comment}{/*\ 16-\/bit\ signed,\ little\ endian\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00086\ \textcolor{preprocessor}{\#define\ INPUT\_GAIN\ \ \ (85)}}
\DoxyCodeLine{00087\ \textcolor{preprocessor}{\#define\ SPS\_EPSILON\ \ \ 200}}
\DoxyCodeLine{00088\ }
\DoxyCodeLine{00089\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{int}}
\DoxyCodeLine{00090\ setparams(int32\ sps,\ snd\_pcm\_t\ *\ handle)}
\DoxyCodeLine{00091\ \{}
\DoxyCodeLine{00092\ \ \ \ \ snd\_pcm\_hw\_params\_t\ *hwparams;}
\DoxyCodeLine{00093\ \ \ \ \ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{int}\ out\_sps,\ buffer\_time,\ period\_time;}
\DoxyCodeLine{00094\ \ \ \ \ \textcolor{keywordtype}{int}\ err;}
\DoxyCodeLine{00095\ }
\DoxyCodeLine{00096\ \ \ \ \ snd\_pcm\_hw\_params\_alloca(\&hwparams);}
\DoxyCodeLine{00097\ \ \ \ \ err\ =\ snd\_pcm\_hw\_params\_any(handle,\ hwparams);}
\DoxyCodeLine{00098\ \ \ \ \ \textcolor{keywordflow}{if}\ (err\ <\ 0)\ \{}
\DoxyCodeLine{00099\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}Can\ not\ configure\ this\ PCM\ device:\ \%s\(\backslash\)n"{}},}
\DoxyCodeLine{00100\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ snd\_strerror(err));}
\DoxyCodeLine{00101\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00102\ \ \ \ \ \}}
\DoxyCodeLine{00103\ }
\DoxyCodeLine{00104\ \ \ \ \ err\ =}
\DoxyCodeLine{00105\ \ \ \ \ \ \ \ \ snd\_pcm\_hw\_params\_set\_access(handle,\ hwparams,}
\DoxyCodeLine{00106\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ SND\_PCM\_ACCESS\_RW\_INTERLEAVED);}
\DoxyCodeLine{00107\ \ \ \ \ \textcolor{keywordflow}{if}\ (err\ <\ 0)\ \{}
\DoxyCodeLine{00108\ \ \ \ \ \ \ \ \ fprintf(stderr,}
\DoxyCodeLine{00109\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}Failed\ to\ set\ PCM\ device\ to\ interleaved:\ \%s\(\backslash\)n"{}},}
\DoxyCodeLine{00110\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ snd\_strerror(err));}
\DoxyCodeLine{00111\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00112\ \ \ \ \ \}}
\DoxyCodeLine{00113\ }
\DoxyCodeLine{00114\ \ \ \ \ err\ =}
\DoxyCodeLine{00115\ \ \ \ \ \ \ \ \ snd\_pcm\_hw\_params\_set\_format(handle,\ hwparams,\ SND\_PCM\_FORMAT\_S16);}
\DoxyCodeLine{00116\ \ \ \ \ \textcolor{keywordflow}{if}\ (err\ <\ 0)\ \{}
\DoxyCodeLine{00117\ \ \ \ \ \ \ \ \ fprintf(stderr,}
\DoxyCodeLine{00118\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}Failed\ to\ set\ PCM\ device\ to\ 16-\/bit\ signed\ PCM:\ \%s\(\backslash\)n"{}},}
\DoxyCodeLine{00119\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ snd\_strerror(err));}
\DoxyCodeLine{00120\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00121\ \ \ \ \ \}}
\DoxyCodeLine{00122\ }
\DoxyCodeLine{00123\ \ \ \ \ err\ =\ snd\_pcm\_hw\_params\_set\_channels(handle,\ hwparams,\ 1);}
\DoxyCodeLine{00124\ \ \ \ \ \textcolor{keywordflow}{if}\ (err\ <\ 0)\ \{}
\DoxyCodeLine{00125\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}Failed\ to\ set\ PCM\ device\ to\ mono:\ \%s\(\backslash\)n"{}},}
\DoxyCodeLine{00126\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ snd\_strerror(err));}
\DoxyCodeLine{00127\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00128\ \ \ \ \ \}}
\DoxyCodeLine{00129\ }
\DoxyCodeLine{00130\ \ \ \ \ out\_sps\ =\ sps;}
\DoxyCodeLine{00131\ \ \ \ \ err\ =}
\DoxyCodeLine{00132\ \ \ \ \ \ \ \ \ snd\_pcm\_hw\_params\_set\_rate\_near(handle,\ hwparams,\ \&out\_sps,\ NULL);}
\DoxyCodeLine{00133\ \ \ \ \ \textcolor{keywordflow}{if}\ (err\ <\ 0)\ \{}
\DoxyCodeLine{00134\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}Failed\ to\ set\ sampling\ rate:\ \%s\(\backslash\)n"{}},}
\DoxyCodeLine{00135\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ snd\_strerror(err));}
\DoxyCodeLine{00136\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00137\ \ \ \ \ \}}
\DoxyCodeLine{00138\ \ \ \ \ \textcolor{keywordflow}{if}\ (abs(out\_sps\ -\/\ sps)\ >\ SPS\_EPSILON)\ \{}
\DoxyCodeLine{00139\ \ \ \ \ \ \ \ \ fprintf(stderr,}
\DoxyCodeLine{00140\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}Available\ samping\ rate\ \%d\ is\ too\ far\ from\ requested\ \%d\(\backslash\)n"{}},}
\DoxyCodeLine{00141\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ out\_sps,\ sps);}
\DoxyCodeLine{00142\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00143\ \ \ \ \ \}}
\DoxyCodeLine{00144\ }
\DoxyCodeLine{00145\ \ \ \ \ \textcolor{comment}{/*\ Set\ buffer\ time\ to\ the\ maximum.\ */}}
\DoxyCodeLine{00146\ \ \ \ \ err\ =\ snd\_pcm\_hw\_params\_get\_buffer\_time\_max(hwparams,\ \&buffer\_time,\ 0);}
\DoxyCodeLine{00147\ \ \ \ \ period\_time\ =\ buffer\_time\ /\ 4;}
\DoxyCodeLine{00148\ \ \ \ \ err\ =\ snd\_pcm\_hw\_params\_set\_period\_time\_near(handle,\ hwparams,}
\DoxyCodeLine{00149\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \&period\_time,\ 0);}
\DoxyCodeLine{00150\ \ \ \ \ \textcolor{keywordflow}{if}\ (err\ <\ 0)\ \{}
\DoxyCodeLine{00151\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}Failed\ to\ set\ period\ time\ to\ \%u:\ \%s\(\backslash\)n"{}},}
\DoxyCodeLine{00152\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ period\_time,\ snd\_strerror(err));}
\DoxyCodeLine{00153\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00154\ \ \ \ \ \}}
\DoxyCodeLine{00155\ \ \ \ \ err\ =\ snd\_pcm\_hw\_params\_set\_buffer\_time\_near(handle,\ hwparams,}
\DoxyCodeLine{00156\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \&buffer\_time,\ 0);}
\DoxyCodeLine{00157\ \ \ \ \ \textcolor{keywordflow}{if}\ (err\ <\ 0)\ \{}
\DoxyCodeLine{00158\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}Failed\ to\ set\ buffer\ time\ to\ \%u:\ \%s\(\backslash\)n"{}},}
\DoxyCodeLine{00159\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ buffer\_time,\ snd\_strerror(err));}
\DoxyCodeLine{00160\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00161\ \ \ \ \ \}}
\DoxyCodeLine{00162\ }
\DoxyCodeLine{00163\ \ \ \ \ err\ =\ snd\_pcm\_hw\_params(handle,\ hwparams);}
\DoxyCodeLine{00164\ \ \ \ \ \textcolor{keywordflow}{if}\ (err\ <\ 0)\ \{}
\DoxyCodeLine{00165\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}Failed\ to\ set\ hwparams:\ \%s\(\backslash\)n"{}},\ snd\_strerror(err));}
\DoxyCodeLine{00166\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00167\ \ \ \ \ \}}
\DoxyCodeLine{00168\ }
\DoxyCodeLine{00169\ \ \ \ \ err\ =\ snd\_pcm\_nonblock(handle,\ 1);}
\DoxyCodeLine{00170\ \ \ \ \ \textcolor{keywordflow}{if}\ (err\ <\ 0)\ \{}
\DoxyCodeLine{00171\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}Failed\ to\ set\ non-\/blocking\ mode:\ \%s\(\backslash\)n"{}},}
\DoxyCodeLine{00172\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ snd\_strerror(err));}
\DoxyCodeLine{00173\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00174\ \ \ \ \ \}}
\DoxyCodeLine{00175\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00176\ \}}
\DoxyCodeLine{00177\ }
\DoxyCodeLine{00178\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{int}}
\DoxyCodeLine{00179\ setlevels(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *dev)}
\DoxyCodeLine{00180\ \{}
\DoxyCodeLine{00181\ \ \ \ \ snd\_mixer\_t\ *handle;}
\DoxyCodeLine{00182\ \ \ \ \ snd\_mixer\_selem\_id\_t\ *sid;}
\DoxyCodeLine{00183\ \ \ \ \ snd\_mixer\_elem\_t\ *elem;}
\DoxyCodeLine{00184\ \ \ \ \ \textcolor{keywordtype}{int}\ err;}
\DoxyCodeLine{00185\ \ \ \ \ \textcolor{keywordtype}{char}\ *mixer\_dev,\ *c;}
\DoxyCodeLine{00186\ }
\DoxyCodeLine{00187\ \ \ \ \ \textcolor{comment}{/*\ Basically\ we\ just\ want\ to\ turn\ on\ Mic\ capture.\ */}}
\DoxyCodeLine{00188\ \ \ \ \ \textcolor{keywordflow}{if}\ ((err\ =\ snd\_mixer\_open(\&handle,\ 0))\ <\ 0)\ \{}
\DoxyCodeLine{00189\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}Mixer\ open\ failed:\ \%s\(\backslash\)n"{}},\ snd\_strerror(err));}
\DoxyCodeLine{00190\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00191\ \ \ \ \ \}}
\DoxyCodeLine{00192\ }
\DoxyCodeLine{00193\ \ \ \ \ mixer\_dev\ =\ strdup(dev);}
\DoxyCodeLine{00194\ \ \ \ \ \textcolor{keywordflow}{if}\ (strncmp(mixer\_dev,\ \textcolor{stringliteral}{"{}plug"{}},\ 4)\ ==\ 0)}
\DoxyCodeLine{00195\ \ \ \ \ \ \ \ \ memmove(mixer\_dev,\ mixer\_dev\ +\ 4,\ strlen(mixer\_dev)\ -\/\ 4\ +\ 1);}
\DoxyCodeLine{00196\ \ \ \ \ \textcolor{keywordflow}{if}\ ((c\ =\ strchr(mixer\_dev,\ \textcolor{charliteral}{','})))}
\DoxyCodeLine{00197\ \ \ \ \ \ \ \ \ *c\ =\ \textcolor{charliteral}{'\(\backslash\)0'};}
\DoxyCodeLine{00198\ \ \ \ \ \textcolor{keywordflow}{if}\ ((err\ =\ snd\_mixer\_attach(handle,\ mixer\_dev))\ <\ 0)\ \{}
\DoxyCodeLine{00199\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}Mixer\ attach\ to\ \%s\ failed:\ \%s\(\backslash\)n"{}},}
\DoxyCodeLine{00200\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ mixer\_dev,\ snd\_strerror(err));}
\DoxyCodeLine{00201\ \ \ \ \ \ \ \ \ free(mixer\_dev);}
\DoxyCodeLine{00202\ \ \ \ \ \ \ \ \ snd\_mixer\_close(handle);}
\DoxyCodeLine{00203\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00204\ \ \ \ \ \}}
\DoxyCodeLine{00205\ \ \ \ \ free(mixer\_dev);}
\DoxyCodeLine{00206\ \ \ \ \ \textcolor{keywordflow}{if}\ ((err\ =\ snd\_mixer\_selem\_register(handle,\ NULL,\ NULL))\ <\ 0)\ \{}
\DoxyCodeLine{00207\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}Mixer\ register\ failed:\ \%s\(\backslash\)n"{}},\ snd\_strerror(err));}
\DoxyCodeLine{00208\ \ \ \ \ \ \ \ \ snd\_mixer\_close(handle);}
\DoxyCodeLine{00209\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00210\ \ \ \ \ \}}
\DoxyCodeLine{00211\ \ \ \ \ \textcolor{keywordflow}{if}\ ((err\ =\ snd\_mixer\_load(handle))\ <\ 0)\ \{}
\DoxyCodeLine{00212\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}Mixer\ load\ failed:\ \%s\(\backslash\)n"{}},\ snd\_strerror(err));}
\DoxyCodeLine{00213\ \ \ \ \ \ \ \ \ snd\_mixer\_close(handle);}
\DoxyCodeLine{00214\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00215\ \ \ \ \ \}}
\DoxyCodeLine{00216\ \ \ \ \ snd\_mixer\_selem\_id\_alloca(\&sid);}
\DoxyCodeLine{00217\ \ \ \ \ snd\_mixer\_selem\_id\_set\_name(sid,\ \textcolor{stringliteral}{"{}Mic"{}});}
\DoxyCodeLine{00218\ \ \ \ \ \textcolor{keywordflow}{if}\ ((elem\ =\ snd\_mixer\_find\_selem(handle,\ sid))\ ==\ NULL)\ \{}
\DoxyCodeLine{00219\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}Warning:\ Could\ not\ find\ Mic\ element\(\backslash\)n"{}});}
\DoxyCodeLine{00220\ \ \ \ \ \}}
\DoxyCodeLine{00221\ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00222\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (snd\_mixer\_selem\_has\_capture\_switch(elem))\ \{}
\DoxyCodeLine{00223\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((err\ =\ snd\_mixer\_selem\_set\_capture\_switch\_all(elem,\ 1))\ <\ 0)\ \{\ }
\DoxyCodeLine{00224\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(stderr,}
\DoxyCodeLine{00225\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}Failed\ to\ enable\ microphone\ capture:\ \%s\(\backslash\)n"{}},}
\DoxyCodeLine{00226\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ snd\_strerror(err));}
\DoxyCodeLine{00227\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ snd\_mixer\_close(handle);\ }
\DoxyCodeLine{00228\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00229\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00230\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00231\ \ \ \ \ \}}
\DoxyCodeLine{00232\ \ \ \ \ snd\_mixer\_selem\_id\_set\_name(sid,\ \textcolor{stringliteral}{"{}Capture"{}});}
\DoxyCodeLine{00233\ \ \ \ \ \textcolor{keywordflow}{if}\ ((elem\ =\ snd\_mixer\_find\_selem(handle,\ sid))\ ==\ NULL)\ \{}
\DoxyCodeLine{00234\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}Warning:\ Could\ not\ find\ Capture\ element\(\backslash\)n"{}});}
\DoxyCodeLine{00235\ \ \ \ \ \}}
\DoxyCodeLine{00236\ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00237\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (snd\_mixer\_selem\_has\_capture\_switch(elem))\ \{}
\DoxyCodeLine{00238\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((err\ =\ snd\_mixer\_selem\_set\_capture\_switch\_all(elem,\ 1))\ <\ 0)\ \{}
\DoxyCodeLine{00239\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(stderr,}
\DoxyCodeLine{00240\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}Failed\ to\ enable\ microphone\ capture:\ \%s\(\backslash\)n"{}},}
\DoxyCodeLine{00241\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ snd\_strerror(err));}
\DoxyCodeLine{00242\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ snd\_mixer\_close(handle);}
\DoxyCodeLine{00243\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00244\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00245\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00246\ \ \ \ \ \}}
\DoxyCodeLine{00247\ }
\DoxyCodeLine{00248\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00249\ \}}
\DoxyCodeLine{00250\ }
\DoxyCodeLine{00251\ ad\_rec\_t\ *}
\DoxyCodeLine{00252\ ad\_open\_dev(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *dev,\ int32\ sps)}
\DoxyCodeLine{00253\ \{}
\DoxyCodeLine{00254\ \ \ \ \ ad\_rec\_t\ *handle;}
\DoxyCodeLine{00255\ \ \ \ \ snd\_pcm\_t\ *dspH;}
\DoxyCodeLine{00256\ }
\DoxyCodeLine{00257\ \ \ \ \ \textcolor{keywordtype}{int}\ err;}
\DoxyCodeLine{00258\ }
\DoxyCodeLine{00259\ \ \ \ \ \textcolor{keywordflow}{if}\ (dev\ ==\ NULL)}
\DoxyCodeLine{00260\ \ \ \ \ \ \ \ \ dev\ =\ DEFAULT\_DEVICE;}
\DoxyCodeLine{00261\ }
\DoxyCodeLine{00262\ \ \ \ \ err\ =\ snd\_pcm\_open(\&dspH,\ dev,\ SND\_PCM\_STREAM\_CAPTURE,\ 0);}
\DoxyCodeLine{00263\ \ \ \ \ \textcolor{keywordflow}{if}\ (err\ <\ 0)\ \{}
\DoxyCodeLine{00264\ \ \ \ \ \ \ \ \ fprintf(stderr,}
\DoxyCodeLine{00265\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}Error\ opening\ audio\ device\ \%s\ for\ capture:\ \%s\(\backslash\)n"{}},}
\DoxyCodeLine{00266\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ dev,\ snd\_strerror(err));}
\DoxyCodeLine{00267\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00268\ \ \ \ \ \}}
\DoxyCodeLine{00269\ }
\DoxyCodeLine{00270\ \ \ \ \ \textcolor{keywordflow}{if}\ (setparams(sps,\ dspH)\ <\ 0)\ \{}
\DoxyCodeLine{00271\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00272\ \ \ \ \ \}}
\DoxyCodeLine{00273\ \ \ \ \ \textcolor{keywordflow}{if}\ (setlevels(dev)\ <\ 0)\ \{}
\DoxyCodeLine{00274\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00275\ \ \ \ \ \}}
\DoxyCodeLine{00276\ \ \ \ \ \textcolor{keywordflow}{if}\ ((handle\ =\ (ad\_rec\_t\ *)\ calloc(1,\ \textcolor{keyword}{sizeof}(ad\_rec\_t)))\ ==\ NULL)\ \{}
\DoxyCodeLine{00277\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}calloc(\%d)\ failed\(\backslash\)n"{}},\ (\textcolor{keywordtype}{int})\textcolor{keyword}{sizeof}(ad\_rec\_t));}
\DoxyCodeLine{00278\ \ \ \ \ \ \ \ \ abort();}
\DoxyCodeLine{00279\ \ \ \ \ \}}
\DoxyCodeLine{00280\ }
\DoxyCodeLine{00281\ \ \ \ \ handle-\/>dspH\ =\ dspH;}
\DoxyCodeLine{00282\ \ \ \ \ handle-\/>recording\ =\ 0;}
\DoxyCodeLine{00283\ \ \ \ \ handle-\/>sps\ =\ sps;}
\DoxyCodeLine{00284\ \ \ \ \ handle-\/>bps\ =\ \textcolor{keyword}{sizeof}(int16);}
\DoxyCodeLine{00285\ }
\DoxyCodeLine{00286\ \ \ \ \ \textcolor{keywordflow}{return}\ (handle);}
\DoxyCodeLine{00287\ \}}
\DoxyCodeLine{00288\ }
\DoxyCodeLine{00289\ ad\_rec\_t\ *}
\DoxyCodeLine{00290\ ad\_open\_sps(int32\ sps)}
\DoxyCodeLine{00291\ \{}
\DoxyCodeLine{00292\ \ \ \ \ \textcolor{keywordflow}{return}\ ad\_open\_dev(DEFAULT\_DEVICE,\ sps);}
\DoxyCodeLine{00293\ \}}
\DoxyCodeLine{00294\ }
\DoxyCodeLine{00295\ ad\_rec\_t\ *}
\DoxyCodeLine{00296\ ad\_open(\textcolor{keywordtype}{void})}
\DoxyCodeLine{00297\ \{}
\DoxyCodeLine{00298\ \ \ \ \ \textcolor{keywordflow}{return}\ ad\_open\_sps(DEFAULT\_SAMPLES\_PER\_SEC);}
\DoxyCodeLine{00299\ \}}
\DoxyCodeLine{00300\ }
\DoxyCodeLine{00301\ }
\DoxyCodeLine{00302\ int32}
\DoxyCodeLine{00303\ ad\_close(ad\_rec\_t\ *\ handle)}
\DoxyCodeLine{00304\ \{}
\DoxyCodeLine{00305\ \ \ \ \ \textcolor{keywordflow}{if}\ (handle-\/>dspH\ ==\ NULL)}
\DoxyCodeLine{00306\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ AD\_ERR\_NOT\_OPEN;}
\DoxyCodeLine{00307\ }
\DoxyCodeLine{00308\ \ \ \ \ \textcolor{keywordflow}{if}\ (handle-\/>recording)\ \{}
\DoxyCodeLine{00309\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (ad\_stop\_rec(handle)\ <\ 0)}
\DoxyCodeLine{00310\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ AD\_ERR\_GEN;}
\DoxyCodeLine{00311\ \ \ \ \ \}}
\DoxyCodeLine{00312\ \ \ \ \ snd\_pcm\_close(handle-\/>dspH);}
\DoxyCodeLine{00313\ \ \ \ \ free(handle);}
\DoxyCodeLine{00314\ }
\DoxyCodeLine{00315\ \ \ \ \ \textcolor{keywordflow}{return}\ (0);}
\DoxyCodeLine{00316\ \}}
\DoxyCodeLine{00317\ }
\DoxyCodeLine{00318\ }
\DoxyCodeLine{00319\ int32}
\DoxyCodeLine{00320\ ad\_start\_rec(ad\_rec\_t\ *\ handle)}
\DoxyCodeLine{00321\ \{}
\DoxyCodeLine{00322\ \ \ \ \ \textcolor{keywordtype}{int}\ err;}
\DoxyCodeLine{00323\ }
\DoxyCodeLine{00324\ \ \ \ \ \textcolor{keywordflow}{if}\ (handle-\/>dspH\ ==\ NULL)}
\DoxyCodeLine{00325\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ AD\_ERR\_NOT\_OPEN;}
\DoxyCodeLine{00326\ }
\DoxyCodeLine{00327\ \ \ \ \ \textcolor{keywordflow}{if}\ (handle-\/>recording)}
\DoxyCodeLine{00328\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ AD\_ERR\_GEN;}
\DoxyCodeLine{00329\ }
\DoxyCodeLine{00330\ \ \ \ \ err\ =\ snd\_pcm\_prepare(handle-\/>dspH);}
\DoxyCodeLine{00331\ \ \ \ \ \textcolor{keywordflow}{if}\ (err\ <\ 0)\ \{}
\DoxyCodeLine{00332\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}snd\_pcm\_prepare\ failed:\ \%s\(\backslash\)n"{}},\ snd\_strerror(err));}
\DoxyCodeLine{00333\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ AD\_ERR\_GEN;}
\DoxyCodeLine{00334\ \ \ \ \ \}}
\DoxyCodeLine{00335\ \ \ \ \ err\ =\ snd\_pcm\_start(handle-\/>dspH);}
\DoxyCodeLine{00336\ \ \ \ \ \textcolor{keywordflow}{if}\ (err\ <\ 0)\ \{}
\DoxyCodeLine{00337\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}snd\_pcm\_start\ failed:\ \%s\(\backslash\)n"{}},\ snd\_strerror(err));}
\DoxyCodeLine{00338\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ AD\_ERR\_GEN;}
\DoxyCodeLine{00339\ \ \ \ \ \}}
\DoxyCodeLine{00340\ \ \ \ \ handle-\/>recording\ =\ 1;}
\DoxyCodeLine{00341\ }
\DoxyCodeLine{00342\ \ \ \ \ \textcolor{keywordflow}{return}\ (0);}
\DoxyCodeLine{00343\ \}}
\DoxyCodeLine{00344\ }
\DoxyCodeLine{00345\ }
\DoxyCodeLine{00346\ int32}
\DoxyCodeLine{00347\ ad\_stop\_rec(ad\_rec\_t\ *\ handle)}
\DoxyCodeLine{00348\ \{}
\DoxyCodeLine{00349\ \ \ \ \ \textcolor{keywordtype}{int}\ err;}
\DoxyCodeLine{00350\ }
\DoxyCodeLine{00351\ \ \ \ \ \textcolor{keywordflow}{if}\ (handle-\/>dspH\ ==\ NULL)}
\DoxyCodeLine{00352\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ AD\_ERR\_NOT\_OPEN;}
\DoxyCodeLine{00353\ }
\DoxyCodeLine{00354\ \ \ \ \ \textcolor{keywordflow}{if}\ (!handle-\/>recording)}
\DoxyCodeLine{00355\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ AD\_ERR\_GEN;}
\DoxyCodeLine{00356\ }
\DoxyCodeLine{00357\ \ \ \ \ err\ =\ snd\_pcm\_drop(handle-\/>dspH);}
\DoxyCodeLine{00358\ \ \ \ \ \textcolor{keywordflow}{if}\ (err\ <\ 0)\ \{}
\DoxyCodeLine{00359\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}snd\_pcm\_drop\ failed:\ \%s\(\backslash\)n"{}},\ snd\_strerror(err));}
\DoxyCodeLine{00360\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ AD\_ERR\_GEN;}
\DoxyCodeLine{00361\ \ \ \ \ \}}
\DoxyCodeLine{00362\ \ \ \ \ handle-\/>recording\ =\ 0;}
\DoxyCodeLine{00363\ }
\DoxyCodeLine{00364\ \ \ \ \ \textcolor{keywordflow}{return}\ (0);}
\DoxyCodeLine{00365\ \}}
\DoxyCodeLine{00366\ }
\DoxyCodeLine{00367\ }
\DoxyCodeLine{00368\ int32}
\DoxyCodeLine{00369\ ad\_read(ad\_rec\_t\ *\ handle,\ int16\ *\ buf,\ int32\ max)}
\DoxyCodeLine{00370\ \{}
\DoxyCodeLine{00371\ \ \ \ \ int32\ length,\ err;}
\DoxyCodeLine{00372\ }
\DoxyCodeLine{00373\ \ \ \ \ \textcolor{keywordflow}{if}\ (!handle-\/>recording)\ \{}
\DoxyCodeLine{00374\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}Recording\ is\ stopped,\ start\ recording\ with\ ad\_start\_rec\(\backslash\)n"{}});}
\DoxyCodeLine{00375\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ AD\_EOF;}
\DoxyCodeLine{00376\ \ \ \ \ \}}
\DoxyCodeLine{00377\ }
\DoxyCodeLine{00378\ \ \ \ \ length\ =\ snd\_pcm\_readi(handle-\/>dspH,\ buf,\ max);}
\DoxyCodeLine{00379\ \ \ \ \ \textcolor{keywordflow}{if}\ (length\ ==\ -\/EAGAIN)\ \{}
\DoxyCodeLine{00380\ \ \ \ \ \ \ \ \ length\ =\ 0;}
\DoxyCodeLine{00381\ \ \ \ \ \}}
\DoxyCodeLine{00382\ \ \ \ \ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (length\ ==\ -\/EPIPE)\ \{}
\DoxyCodeLine{00383\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}Input\ overrun,\ read\ calls\ are\ too\ rare\ (non-\/fatal)\(\backslash\)n"{}});}
\DoxyCodeLine{00384\ \ \ \ \ \ \ \ \ err\ =\ snd\_pcm\_prepare(handle-\/>dspH);}
\DoxyCodeLine{00385\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (err\ <\ 0)\ \{}
\DoxyCodeLine{00386\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}Can't\ recover\ from\ underrun:\ \%s\(\backslash\)n"{}},}
\DoxyCodeLine{00387\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ snd\_strerror(err));}
\DoxyCodeLine{00388\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ AD\_ERR\_GEN;}
\DoxyCodeLine{00389\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00390\ \ \ \ \ \ \ \ \ length\ =\ 0;}
\DoxyCodeLine{00391\ \ \ \ \ \}}
\DoxyCodeLine{00392\ \ \ \ \ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (length\ ==\ -\/ESTRPIPE)\ \{}
\DoxyCodeLine{00393\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}Resuming\ sound\ driver\ (non-\/fatal)\(\backslash\)n"{}});}
\DoxyCodeLine{00394\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{while}\ ((err\ =\ snd\_pcm\_resume(handle-\/>dspH))\ ==\ -\/EAGAIN)}
\DoxyCodeLine{00395\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ usleep(10000);\ \textcolor{comment}{/*\ Wait\ for\ the\ driver\ to\ wake\ up\ */}}
\DoxyCodeLine{00396\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (err\ <\ 0)\ \{}
\DoxyCodeLine{00397\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ err\ =\ snd\_pcm\_prepare(handle-\/>dspH);}
\DoxyCodeLine{00398\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (err\ <\ 0)\ \{}
\DoxyCodeLine{00399\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}Can't\ recover\ from\ underrun:\ \%s\(\backslash\)n"{}},}
\DoxyCodeLine{00400\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ snd\_strerror(err));}
\DoxyCodeLine{00401\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ AD\_ERR\_GEN;}
\DoxyCodeLine{00402\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00403\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00404\ \ \ \ \ \ \ \ \ length\ =\ 0;}
\DoxyCodeLine{00405\ \ \ \ \ \}}
\DoxyCodeLine{00406\ \ \ \ \ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (length\ <\ 0)\ \{}
\DoxyCodeLine{00407\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}Audio\ read\ error:\ \%s\(\backslash\)n"{}},}
\DoxyCodeLine{00408\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ snd\_strerror(length));}
\DoxyCodeLine{00409\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ AD\_ERR\_GEN;}
\DoxyCodeLine{00410\ \ \ \ \ \}}
\DoxyCodeLine{00411\ \ \ \ \ \textcolor{keywordflow}{return}\ length;}
\DoxyCodeLine{00412\ \}}

\end{DoxyCode}
