\doxysection{ad\+\_\+oss.\+c}
\label{ad__oss_8c_source}\index{src/libsphinxad/ad\_oss.c@{src/libsphinxad/ad\_oss.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}{/*\ Sphinx\ II\ libad\ (Linux)}}
\DoxyCodeLine{00038\ \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{00039\ \textcolor{comment}{\ *\ \$Id:\ ad\_oss.c,v\ 1.9\ 2004/07/16\ 00:57:12\ egouvea\ Exp\ \$}}
\DoxyCodeLine{00040\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00041\ \textcolor{comment}{\ *\ John\ G.\ Dorsey\ (jd5q+@andrew.cmu.edu)}}
\DoxyCodeLine{00042\ \textcolor{comment}{\ *\ Engineering\ Design\ Research\ Center}}
\DoxyCodeLine{00043\ \textcolor{comment}{\ *\ Carnegie\ Mellon\ University}}
\DoxyCodeLine{00044\ \textcolor{comment}{\ *\ ********************************************************************}}
\DoxyCodeLine{00045\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00046\ \textcolor{comment}{\ *\ REVISION\ HISTORY}}
\DoxyCodeLine{00047\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00048\ \textcolor{comment}{\ *\ 09-\/Aug-\/1999\ \ Kevin\ Lenzo\ (lenzo@cs.cmu.edu)\ at\ Cernegie\ Mellon\ University.}}
\DoxyCodeLine{00049\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Incorporated\ nickr@cs.cmu.edu's\ changes\ (marked\ below)\ and}}
\DoxyCodeLine{00050\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ SPS\_EPSILON\ to\ allow\ for\ sample\ rates\ that\ are\ "{}close\ enough"{}.}}
\DoxyCodeLine{00051\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00052\ \textcolor{comment}{\ *\ 15-\/Jun-\/1999\ \ M.\ K.\ Ravishankar\ (rkm@cs.cmu.edu)\ Consolidated\ all\ ad\ functions\ into}}
\DoxyCodeLine{00053\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ this\ one\ file.\ \ Added\ ad\_open\_sps().}}
\DoxyCodeLine{00054\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Other\ cosmetic\ changes\ for\ consistency\ (e.g.,\ use\ of\ err.h).}}
\DoxyCodeLine{00055\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00056\ \textcolor{comment}{\ *\ 18-\/May-\/1999\ \ Kevin\ Lenzo\ (lenzo@cs.cmu.edu)\ added\ <errno.h>.}}
\DoxyCodeLine{00057\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00058\ }
\DoxyCodeLine{00059\ \textcolor{preprocessor}{\#include\ <fcntl.h>}}
\DoxyCodeLine{00060\ \textcolor{preprocessor}{\#include\ <stdio.h>}}
\DoxyCodeLine{00061\ \textcolor{preprocessor}{\#include\ <stdlib.h>}}
\DoxyCodeLine{00062\ \textcolor{preprocessor}{\#include\ <string.h>}}
\DoxyCodeLine{00063\ \textcolor{preprocessor}{\#include\ <sys/soundcard.h>}}
\DoxyCodeLine{00064\ \textcolor{preprocessor}{\#include\ <sys/ioctl.h>}}
\DoxyCodeLine{00065\ \textcolor{preprocessor}{\#include\ <errno.h>}}
\DoxyCodeLine{00066\ \textcolor{preprocessor}{\#include\ <unistd.h>}}
\DoxyCodeLine{00067\ \textcolor{preprocessor}{\#include\ <config.h>}}
\DoxyCodeLine{00068\ }
\DoxyCodeLine{00069\ \textcolor{preprocessor}{\#include\ "{}prim\_type.h"{}}}
\DoxyCodeLine{00070\ \textcolor{preprocessor}{\#include\ "{}ad.h"{}}}
\DoxyCodeLine{00071\ }
\DoxyCodeLine{00072\ \textcolor{preprocessor}{\#define\ AUDIO\_FORMAT\ AFMT\_S16\_LE\ \ \ \ \ \ \ \ }\textcolor{comment}{/*\ 16-\/bit\ signed,\ little\ endian\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00073\ \textcolor{preprocessor}{\#define\ INPUT\_GAIN\ \ \ (80)}}
\DoxyCodeLine{00074\ }
\DoxyCodeLine{00075\ \textcolor{preprocessor}{\#define\ SPS\_EPSILON\ \ \ 200}}
\DoxyCodeLine{00076\ \textcolor{preprocessor}{\#define\ SAMPLERATE\_TOLERANCE\ 0.01}}
\DoxyCodeLine{00077\ }
\DoxyCodeLine{00078\ ad\_rec\_t\ *}
\DoxyCodeLine{00079\ ad\_open\_dev(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *dev,\ int32\ sps)}
\DoxyCodeLine{00080\ \{}
\DoxyCodeLine{00081\ \ \ \ \ ad\_rec\_t\ *handle;}
\DoxyCodeLine{00082\ \ \ \ \ int32\ dspFD,\ mixerFD;}
\DoxyCodeLine{00083\ \ \ \ \ int32\ nonBlocking\ =\ 1,\ sourceMic\ =\ SOUND\_MASK\_MIC,\ inputGain\ =}
\DoxyCodeLine{00084\ \ \ \ \ \ \ \ \ INPUT\_GAIN,\ devMask\ =\ 0;}
\DoxyCodeLine{00085\ \ \ \ \ int32\ audioFormat\ =\ AUDIO\_FORMAT;}
\DoxyCodeLine{00086\ \ \ \ \ int32\ dspCaps\ =\ 0;}
\DoxyCodeLine{00087\ \ \ \ \ int32\ sampleRate;}
\DoxyCodeLine{00088\ \ \ \ \ int32\ numberChannels\ =\ 1;}
\DoxyCodeLine{00089\ }
\DoxyCodeLine{00090\ \ \ \ \ sampleRate\ =\ sps;}
\DoxyCodeLine{00091\ }
\DoxyCodeLine{00092\ \ \ \ \ \textcolor{keywordflow}{if}\ (dev\ ==\ NULL)}
\DoxyCodeLine{00093\ \ \ \ \ \ \ \ \ dev\ =\ DEFAULT\_DEVICE;}
\DoxyCodeLine{00094\ }
\DoxyCodeLine{00095\ \ \ \ \ \textcolor{comment}{/*\ Used\ to\ have\ O\_NDELAY.\ */}}
\DoxyCodeLine{00096\ \ \ \ \ \textcolor{keywordflow}{if}\ ((dspFD\ =\ open(dev,\ O\_RDONLY))\ <\ 0)\ \{}
\DoxyCodeLine{00097\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (errno\ ==\ EBUSY)}
\DoxyCodeLine{00098\ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}\%s(\%d):\ Audio\ device(\%s)\ busy\(\backslash\)n"{}},}
\DoxyCodeLine{00099\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \_\_FILE\_\_,\ \_\_LINE\_\_,\ dev);}
\DoxyCodeLine{00100\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}}
\DoxyCodeLine{00101\ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(stderr,}
\DoxyCodeLine{00102\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}\%s(\%d):\ Failed\ to\ open\ audio\ device(\%s):\ \%s\(\backslash\)n"{}},}
\DoxyCodeLine{00103\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \_\_FILE\_\_,\ \_\_LINE\_\_,\ dev,\ strerror(errno));}
\DoxyCodeLine{00104\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00105\ \ \ \ \ \}}
\DoxyCodeLine{00106\ }
\DoxyCodeLine{00107\ \ \ \ \ \textcolor{keywordflow}{if}\ (ioctl(dspFD,\ SNDCTL\_DSP\_SYNC,\ 0)\ <\ 0)\ \{}
\DoxyCodeLine{00108\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}Audio\ ioctl(SYNC)\ failed:\ \%s\(\backslash\)n"{}},\ strerror(errno));}
\DoxyCodeLine{00109\ \ \ \ \ \ \ \ \ close(dspFD);}
\DoxyCodeLine{00110\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00111\ \ \ \ \ \}}
\DoxyCodeLine{00112\ }
\DoxyCodeLine{00113\ \ \ \ \ \textcolor{keywordflow}{if}\ (ioctl(dspFD,\ SNDCTL\_DSP\_RESET,\ 0)\ <\ 0)\ \{}
\DoxyCodeLine{00114\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}Audio\ ioctl(RESET)\ failed:\ \%s\(\backslash\)n"{}},}
\DoxyCodeLine{00115\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ strerror(errno));}
\DoxyCodeLine{00116\ \ \ \ \ \ \ \ \ close(dspFD);}
\DoxyCodeLine{00117\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00118\ \ \ \ \ \}}
\DoxyCodeLine{00119\ }
\DoxyCodeLine{00120\ \ \ \ \ \textcolor{keywordflow}{if}\ (ioctl(dspFD,\ SNDCTL\_DSP\_SETFMT,\ \&audioFormat)\ <\ 0)\ \{}
\DoxyCodeLine{00121\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}Audio\ ioctl(SETFMT\ 0x\%x)\ failed:\ \%s\(\backslash\)n"{}},}
\DoxyCodeLine{00122\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ audioFormat,\ strerror(errno));}
\DoxyCodeLine{00123\ \ \ \ \ \ \ \ \ close(dspFD);}
\DoxyCodeLine{00124\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00125\ \ \ \ \ \}}
\DoxyCodeLine{00126\ \ \ \ \ \textcolor{keywordflow}{if}\ (audioFormat\ !=\ AUDIO\_FORMAT)\ \{}
\DoxyCodeLine{00127\ \ \ \ \ \ \ \ \ fprintf(stderr,}
\DoxyCodeLine{00128\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}Audio\ ioctl(SETFMT):\ 0x\%x,\ expected:\ 0x\%x\(\backslash\)n"{}},}
\DoxyCodeLine{00129\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ audioFormat,\ AUDIO\_FORMAT);}
\DoxyCodeLine{00130\ \ \ \ \ \ \ \ \ close(dspFD);}
\DoxyCodeLine{00131\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00132\ \ \ \ \ \}}
\DoxyCodeLine{00133\ }
\DoxyCodeLine{00134\ \ \ \ \ \textcolor{keywordflow}{if}\ (ioctl(dspFD,\ SNDCTL\_DSP\_SPEED,\ \&sampleRate)\ <\ 0)\ \{}
\DoxyCodeLine{00135\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}Audio\ ioctl(SPEED\ \%d)\ failed\ \%s\(\backslash\)n"{}},}
\DoxyCodeLine{00136\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ sampleRate,\ strerror(errno));}
\DoxyCodeLine{00137\ \ \ \ \ \ \ \ \ close(dspFD);}
\DoxyCodeLine{00138\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00139\ \ \ \ \ \}}
\DoxyCodeLine{00140\ \ \ \ \ \textcolor{keywordflow}{if}\ (sampleRate\ !=\ sps)\ \{}
\DoxyCodeLine{00141\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (abs(sampleRate\ -\/\ sps)\ <=\ (sampleRate\ *\ SAMPLERATE\_TOLERANCE))\ \{}
\DoxyCodeLine{00142\ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(stderr,}
\DoxyCodeLine{00143\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}Audio\ ioctl(SPEED)\ not\ perfect,\ but\ is\ acceptable.\ "{}}}
\DoxyCodeLine{00144\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}(Wanted\ \%d,\ but\ got\ \%d)\(\backslash\)n"{}},\ sampleRate,\ sps);}
\DoxyCodeLine{00145\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00146\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00147\ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(stderr,}
\DoxyCodeLine{00148\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}Audio\ ioctl(SPEED):\ \%d,\ expected:\ \%d\(\backslash\)n"{}},}
\DoxyCodeLine{00149\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ sampleRate,\ sps);}
\DoxyCodeLine{00150\ \ \ \ \ \ \ \ \ \ \ \ \ close(dspFD);}
\DoxyCodeLine{00151\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00152\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00153\ \ \ \ \ \}}
\DoxyCodeLine{00154\ }
\DoxyCodeLine{00155\ \ \ \ \ \textcolor{keywordflow}{if}\ (ioctl(dspFD,\ SNDCTL\_DSP\_CHANNELS,\ \&numberChannels)\ <\ 0)\ \{}
\DoxyCodeLine{00156\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}Audio\ ioctl(CHANNELS\ \%d)\ failed\ \%s\(\backslash\)n"{}},}
\DoxyCodeLine{00157\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ numberChannels,\ strerror(errno));}
\DoxyCodeLine{00158\ \ \ \ \ \ \ \ \ close(dspFD);}
\DoxyCodeLine{00159\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00160\ \ \ \ \ \}}
\DoxyCodeLine{00161\ }
\DoxyCodeLine{00162\ \ \ \ \ \textcolor{keywordflow}{if}\ (ioctl(dspFD,\ SNDCTL\_DSP\_NONBLOCK,\ \&nonBlocking)\ <\ 0)\ \{}
\DoxyCodeLine{00163\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}ioctl(NONBLOCK)\ failed:\ \%s\(\backslash\)n"{}},\ strerror(errno));}
\DoxyCodeLine{00164\ \ \ \ \ \ \ \ \ close(dspFD);}
\DoxyCodeLine{00165\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00166\ \ \ \ \ \}}
\DoxyCodeLine{00167\ }
\DoxyCodeLine{00168\ \ \ \ \ \textcolor{keywordflow}{if}\ (ioctl(dspFD,\ SNDCTL\_DSP\_GETCAPS,\ \&dspCaps)\ <\ 0)\ \{}
\DoxyCodeLine{00169\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}ioctl(GETCAPS)\ failed:\ \%s\(\backslash\)n"{}},\ strerror(errno));}
\DoxyCodeLine{00170\ \ \ \ \ \ \ \ \ close(dspFD);}
\DoxyCodeLine{00171\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00172\ \ \ \ \ \}}
\DoxyCodeLine{00173\ \textcolor{preprocessor}{\#if\ 0}}
\DoxyCodeLine{00174\ \ \ \ \ printf(\textcolor{stringliteral}{"{}DSP\ Revision\ \%d:\(\backslash\)n"{}},\ dspCaps\ \&\ DSP\_CAP\_REVISION);}
\DoxyCodeLine{00175\ \ \ \ \ printf(\textcolor{stringliteral}{"{}DSP\ \%s\ duplex\ capability.\(\backslash\)n"{}},}
\DoxyCodeLine{00176\ \ \ \ \ \ \ \ \ \ \ \ (dspCaps\ \&\ DSP\_CAP\_DUPLEX)\ ?\ \textcolor{stringliteral}{"{}has"{}}\ :\ \textcolor{stringliteral}{"{}does\ not\ have"{}});}
\DoxyCodeLine{00177\ \ \ \ \ printf(\textcolor{stringliteral}{"{}DSP\ \%s\ real\ time\ capability.\(\backslash\)n"{}},}
\DoxyCodeLine{00178\ \ \ \ \ \ \ \ \ \ \ \ (dspCaps\ \&\ DSP\_CAP\_REALTIME)\ ?\ \textcolor{stringliteral}{"{}has"{}}\ :\ \textcolor{stringliteral}{"{}does\ not\ have"{}});}
\DoxyCodeLine{00179\ \ \ \ \ printf(\textcolor{stringliteral}{"{}DSP\ \%s\ batch\ capability.\(\backslash\)n"{}},}
\DoxyCodeLine{00180\ \ \ \ \ \ \ \ \ \ \ \ (dspCaps\ \&\ DSP\_CAP\_BATCH)\ ?\ \textcolor{stringliteral}{"{}has"{}}\ :\ \textcolor{stringliteral}{"{}does\ not\ have"{}});}
\DoxyCodeLine{00181\ \ \ \ \ printf(\textcolor{stringliteral}{"{}DSP\ \%s\ coprocessor\ capability.\(\backslash\)n"{}},}
\DoxyCodeLine{00182\ \ \ \ \ \ \ \ \ \ \ \ (dspCaps\ \&\ DSP\_CAP\_COPROC)\ ?\ \textcolor{stringliteral}{"{}has"{}}\ :\ \textcolor{stringliteral}{"{}does\ not\ have"{}});}
\DoxyCodeLine{00183\ \ \ \ \ printf(\textcolor{stringliteral}{"{}DSP\ \%s\ trigger\ capability.\(\backslash\)n"{}},}
\DoxyCodeLine{00184\ \ \ \ \ \ \ \ \ \ \ \ (dspCaps\ \&\ DSP\_CAP\_TRIGGER)\ ?\ \textcolor{stringliteral}{"{}has"{}}\ :\ \textcolor{stringliteral}{"{}does\ not\ have"{}});}
\DoxyCodeLine{00185\ \ \ \ \ printf(\textcolor{stringliteral}{"{}DSP\ \%s\ memory\ map\ capability.\(\backslash\)n"{}},}
\DoxyCodeLine{00186\ \ \ \ \ \ \ \ \ \ \ \ (dspCaps\ \&\ DSP\_CAP\_MMAP)\ ?\ \textcolor{stringliteral}{"{}has"{}}\ :\ \textcolor{stringliteral}{"{}does\ not\ have"{}});}
\DoxyCodeLine{00187\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00188\ }
\DoxyCodeLine{00189\ \ \ \ \ \textcolor{keywordflow}{if}\ ((dspCaps\ \&\ DSP\_CAP\_DUPLEX)}
\DoxyCodeLine{00190\ \ \ \ \ \ \ \ \ \&\&\ (ioctl(dspFD,\ SNDCTL\_DSP\_SETDUPLEX,\ 0)\ <\ 0))}
\DoxyCodeLine{00191\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}ioctl(SETDUPLEX)\ failed:\ \%s\(\backslash\)n"{}},\ strerror(errno));}
\DoxyCodeLine{00192\ }
\DoxyCodeLine{00193\ \ \ \ \ \textcolor{comment}{/*\ Patched\ by\ N.\ Roy\ (nickr@ri.cmu.edu),\ 99/7/23.\ }}
\DoxyCodeLine{00194\ \textcolor{comment}{\ \ \ \ \ \ \ Previously,\ mixer\ was\ set\ through\ dspFD.\ This\ is\ incorrect.\ Should}}
\DoxyCodeLine{00195\ \textcolor{comment}{\ \ \ \ \ \ \ be\ set\ through\ mixerFD,\ /dev/mixer.\ }}
\DoxyCodeLine{00196\ \textcolor{comment}{\ \ \ \ \ \ \ Also,\ only\ the\ left\ channel\ volume\ was\ being\ set.}}
\DoxyCodeLine{00197\ \textcolor{comment}{\ \ \ \ \ */}}
\DoxyCodeLine{00198\ }
\DoxyCodeLine{00199\ \ \ \ \ \textcolor{keywordflow}{if}\ ((mixerFD\ =\ open(\textcolor{stringliteral}{"{}/dev/mixer"{}},\ O\_RDONLY))\ <\ 0)\ \{}
\DoxyCodeLine{00200\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (errno\ ==\ EBUSY)\ \{}
\DoxyCodeLine{00201\ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}\%s\ \%d:\ mixer\ device\ busy.\(\backslash\)n"{}},}
\DoxyCodeLine{00202\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \_\_FILE\_\_,\ \_\_LINE\_\_);}
\DoxyCodeLine{00203\ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}\%s\ \%d:\ Using\ current\ setting.\(\backslash\)n"{}},}
\DoxyCodeLine{00204\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \_\_FILE\_\_,\ \_\_LINE\_\_);}
\DoxyCodeLine{00205\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00206\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00207\ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}\%s\ \%d:\ \%s\(\backslash\)n"{}},\ \_\_FILE\_\_,\ \_\_LINE\_\_,}
\DoxyCodeLine{00208\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ strerror(errno));}
\DoxyCodeLine{00209\ \ \ \ \ \ \ \ \ \ \ \ \ exit(1);}
\DoxyCodeLine{00210\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00211\ \ \ \ \ \}}
\DoxyCodeLine{00212\ }
\DoxyCodeLine{00213\ \ \ \ \ \textcolor{keywordflow}{if}\ (mixerFD\ >=\ 0)\ \{}
\DoxyCodeLine{00214\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (ioctl(mixerFD,\ SOUND\_MIXER\_WRITE\_RECSRC,\ \&sourceMic)\ <\ 0)\ \{}
\DoxyCodeLine{00215\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (errno\ ==\ ENXIO)}
\DoxyCodeLine{00216\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(stderr,}
\DoxyCodeLine{00217\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}\%s\ \%d:\ can't\ set\ mic\ source\ for\ this\ device.\(\backslash\)n"{}},}
\DoxyCodeLine{00218\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \_\_FILE\_\_,\ \_\_LINE\_\_);}
\DoxyCodeLine{00219\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00220\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(stderr,}
\DoxyCodeLine{00221\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}\%s\ \%d:\ mixer\ set\ to\ mic:\ \%s\(\backslash\)n"{}},}
\DoxyCodeLine{00222\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \_\_FILE\_\_,\ \_\_LINE\_\_,\ strerror(errno));}
\DoxyCodeLine{00223\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ exit(1);}
\DoxyCodeLine{00224\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00225\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00226\ }
\DoxyCodeLine{00227\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Set\ the\ same\ gain\ for\ left\ and\ right\ channels.\ */}}
\DoxyCodeLine{00228\ \ \ \ \ \ \ \ \ inputGain\ =\ inputGain\ <<\ 8\ |\ inputGain;}
\DoxyCodeLine{00229\ }
\DoxyCodeLine{00230\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Some\ OSS\ devices\ have\ no\ input\ gain\ control,\ but\ do\ have\ a}}
\DoxyCodeLine{00231\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ \ \ recording\ level\ control.\ \ Find\ out\ if\ this\ is\ one\ of\ them\ and}}
\DoxyCodeLine{00232\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ \ \ adjust\ accordingly.\ */}}
\DoxyCodeLine{00233\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (ioctl(mixerFD,\ SOUND\_MIXER\_READ\_DEVMASK,\ \&devMask)\ <\ 0)\ \{}
\DoxyCodeLine{00234\ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(stderr,}
\DoxyCodeLine{00235\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}\%s\ \%d:\ failed\ to\ read\ device\ mask:\ \%s\(\backslash\)n"{}},}
\DoxyCodeLine{00236\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \_\_FILE\_\_,\ \_\_LINE\_\_,\ strerror(errno));}
\DoxyCodeLine{00237\ \ \ \ \ \ \ \ \ \ \ \ \ exit(1);\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ FIXME:\ not\ a\ well-\/behaved-\/library\ thing\ to\ do!\ */}}
\DoxyCodeLine{00238\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00239\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (devMask\ \&\ SOUND\_MASK\_IGAIN)\ \{}
\DoxyCodeLine{00240\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (ioctl(mixerFD,\ SOUND\_MIXER\_WRITE\_IGAIN,\ \&inputGain)\ <\ 0)\ \{}
\DoxyCodeLine{00241\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(stderr,}
\DoxyCodeLine{00242\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}\%s\ \%d:\ mixer\ input\ gain\ to\ \%d:\ \%s\(\backslash\)n"{}},}
\DoxyCodeLine{00243\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \_\_FILE\_\_,\ \_\_LINE\_\_,\ inputGain,\ strerror(errno));}
\DoxyCodeLine{00244\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ exit(1);}
\DoxyCodeLine{00245\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00246\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00247\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (devMask\ \&\ SOUND\_MASK\_RECLEV)\ \{}
\DoxyCodeLine{00248\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (ioctl(mixerFD,\ SOUND\_MIXER\_WRITE\_RECLEV,\ \&inputGain)\ <\ 0)\ \{}
\DoxyCodeLine{00249\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(stderr,}
\DoxyCodeLine{00250\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}\%s\ \%d:\ mixer\ record\ level\ to\ \%d:\ \%s\(\backslash\)n"{}},}
\DoxyCodeLine{00251\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \_\_FILE\_\_,\ \_\_LINE\_\_,\ inputGain,\ strerror(errno));}
\DoxyCodeLine{00252\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ exit(1);}
\DoxyCodeLine{00253\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00254\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00255\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00256\ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(stderr,}
\DoxyCodeLine{00257\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}\%s\ \%d:\ can't\ set\ input\ gain/recording\ level\ for\ this\ device.\(\backslash\)n"{}},}
\DoxyCodeLine{00258\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \_\_FILE\_\_,\ \_\_LINE\_\_);}
\DoxyCodeLine{00259\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00260\ }
\DoxyCodeLine{00261\ \ \ \ \ \ \ \ \ close(mixerFD);}
\DoxyCodeLine{00262\ \ \ \ \ \}}
\DoxyCodeLine{00263\ }
\DoxyCodeLine{00264\ \ \ \ \ \textcolor{keywordflow}{if}\ ((handle\ =\ (ad\_rec\_t\ *)\ calloc(1,\ \textcolor{keyword}{sizeof}(ad\_rec\_t)))\ ==\ NULL)\ \{}
\DoxyCodeLine{00265\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}calloc(\%ld)\ failed\(\backslash\)n"{}},\ \textcolor{keyword}{sizeof}(ad\_rec\_t));}
\DoxyCodeLine{00266\ \ \ \ \ \ \ \ \ abort();}
\DoxyCodeLine{00267\ \ \ \ \ \}}
\DoxyCodeLine{00268\ }
\DoxyCodeLine{00269\ \ \ \ \ handle-\/>dspFD\ =\ dspFD;}
\DoxyCodeLine{00270\ \ \ \ \ handle-\/>recording\ =\ 0;}
\DoxyCodeLine{00271\ \ \ \ \ handle-\/>sps\ =\ sps;}
\DoxyCodeLine{00272\ \ \ \ \ handle-\/>bps\ =\ \textcolor{keyword}{sizeof}(int16);}
\DoxyCodeLine{00273\ }
\DoxyCodeLine{00274\ \ \ \ \ \textcolor{keywordflow}{return}\ (handle);}
\DoxyCodeLine{00275\ \}}
\DoxyCodeLine{00276\ }
\DoxyCodeLine{00277\ ad\_rec\_t\ *}
\DoxyCodeLine{00278\ ad\_open\_sps(int32\ sps)}
\DoxyCodeLine{00279\ \{}
\DoxyCodeLine{00280\ \ \ \ \ \textcolor{keywordflow}{return}\ ad\_open\_dev(DEFAULT\_DEVICE,\ sps);}
\DoxyCodeLine{00281\ \}}
\DoxyCodeLine{00282\ }
\DoxyCodeLine{00283\ ad\_rec\_t\ *}
\DoxyCodeLine{00284\ ad\_open(\textcolor{keywordtype}{void})}
\DoxyCodeLine{00285\ \{}
\DoxyCodeLine{00286\ \ \ \ \ \textcolor{keywordflow}{return}\ ad\_open\_sps(DEFAULT\_SAMPLES\_PER\_SEC);}
\DoxyCodeLine{00287\ \}}
\DoxyCodeLine{00288\ }
\DoxyCodeLine{00289\ int32}
\DoxyCodeLine{00290\ ad\_close(ad\_rec\_t\ *\ handle)}
\DoxyCodeLine{00291\ \{}
\DoxyCodeLine{00292\ \ \ \ \ \textcolor{keywordflow}{if}\ (handle-\/>dspFD\ <\ 0)}
\DoxyCodeLine{00293\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ AD\_ERR\_NOT\_OPEN;}
\DoxyCodeLine{00294\ }
\DoxyCodeLine{00295\ \ \ \ \ \textcolor{keywordflow}{if}\ (handle-\/>recording)\ \{}
\DoxyCodeLine{00296\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (ad\_stop\_rec(handle)\ <\ 0)}
\DoxyCodeLine{00297\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ AD\_ERR\_GEN;}
\DoxyCodeLine{00298\ \ \ \ \ \}}
\DoxyCodeLine{00299\ }
\DoxyCodeLine{00300\ \ \ \ \ close(handle-\/>dspFD);}
\DoxyCodeLine{00301\ \ \ \ \ free(handle);}
\DoxyCodeLine{00302\ }
\DoxyCodeLine{00303\ \ \ \ \ \textcolor{keywordflow}{return}\ (0);}
\DoxyCodeLine{00304\ \}}
\DoxyCodeLine{00305\ }
\DoxyCodeLine{00306\ int32}
\DoxyCodeLine{00307\ ad\_start\_rec(ad\_rec\_t\ *\ handle)}
\DoxyCodeLine{00308\ \{}
\DoxyCodeLine{00309\ \ \ \ \ \textcolor{keywordflow}{if}\ (handle-\/>dspFD\ <\ 0)}
\DoxyCodeLine{00310\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ AD\_ERR\_NOT\_OPEN;}
\DoxyCodeLine{00311\ }
\DoxyCodeLine{00312\ \ \ \ \ \textcolor{keywordflow}{if}\ (handle-\/>recording)}
\DoxyCodeLine{00313\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ AD\_ERR\_GEN;}
\DoxyCodeLine{00314\ }
\DoxyCodeLine{00315\ \ \ \ \ \textcolor{comment}{/*\ Sample\ rate,\ format,\ input\ mix\ settings,\ \&c.\ are\ configured}}
\DoxyCodeLine{00316\ \textcolor{comment}{\ \ \ \ \ *\ with\ ioctl(2)\ calls\ under\ Linux.\ It\ makes\ more\ sense\ to\ handle}}
\DoxyCodeLine{00317\ \textcolor{comment}{\ \ \ \ \ *\ these\ at\ device\ open\ time\ and\ consider\ the\ state\ of\ the\ device}}
\DoxyCodeLine{00318\ \textcolor{comment}{\ \ \ \ \ *\ to\ be\ fixed\ until\ closed.}}
\DoxyCodeLine{00319\ \textcolor{comment}{\ \ \ \ \ */}}
\DoxyCodeLine{00320\ }
\DoxyCodeLine{00321\ \ \ \ \ handle-\/>recording\ =\ 1;}
\DoxyCodeLine{00322\ }
\DoxyCodeLine{00323\ \ \ \ \ \textcolor{comment}{/*\ rkm@cs:\ This\ doesn't\ actually\ do\ anything.\ \ How\ do\ we\ turn\ recording\ on/off?\ */}}
\DoxyCodeLine{00324\ }
\DoxyCodeLine{00325\ \ \ \ \ \textcolor{keywordflow}{return}\ (0);}
\DoxyCodeLine{00326\ \}}
\DoxyCodeLine{00327\ }
\DoxyCodeLine{00328\ int32}
\DoxyCodeLine{00329\ ad\_stop\_rec(ad\_rec\_t\ *\ handle)}
\DoxyCodeLine{00330\ \{}
\DoxyCodeLine{00331\ \ \ \ \ \textcolor{keywordflow}{if}\ (handle-\/>dspFD\ <\ 0)}
\DoxyCodeLine{00332\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ AD\_ERR\_NOT\_OPEN;}
\DoxyCodeLine{00333\ }
\DoxyCodeLine{00334\ \ \ \ \ \textcolor{keywordflow}{if}\ (!handle-\/>recording)}
\DoxyCodeLine{00335\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ AD\_ERR\_GEN;}
\DoxyCodeLine{00336\ }
\DoxyCodeLine{00337\ \ \ \ \ \textcolor{keywordflow}{if}\ (ioctl(handle-\/>dspFD,\ SNDCTL\_DSP\_SYNC,\ 0)\ <\ 0)\ \{}
\DoxyCodeLine{00338\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}Audio\ ioctl(SYNC)\ failed:\ \%s\(\backslash\)n"{}},\ strerror(errno));}
\DoxyCodeLine{00339\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ AD\_ERR\_GEN;}
\DoxyCodeLine{00340\ \ \ \ \ \}}
\DoxyCodeLine{00341\ }
\DoxyCodeLine{00342\ \ \ \ \ handle-\/>recording\ =\ 0;}
\DoxyCodeLine{00343\ }
\DoxyCodeLine{00344\ \ \ \ \ \textcolor{keywordflow}{return}\ (0);}
\DoxyCodeLine{00345\ \}}
\DoxyCodeLine{00346\ }
\DoxyCodeLine{00347\ int32}
\DoxyCodeLine{00348\ ad\_read(ad\_rec\_t\ *\ handle,\ int16\ *\ buf,\ int32\ max)}
\DoxyCodeLine{00349\ \{}
\DoxyCodeLine{00350\ \ \ \ \ int32\ length;}
\DoxyCodeLine{00351\ }
\DoxyCodeLine{00352\ \ \ \ \ length\ =\ max\ *\ handle-\/>bps;\ \textcolor{comment}{/*\ \#samples\ -\/>\ \#bytes\ */}}
\DoxyCodeLine{00353\ }
\DoxyCodeLine{00354\ \ \ \ \ \textcolor{keywordflow}{if}\ ((length\ =\ read(handle-\/>dspFD,\ buf,\ length))\ >\ 0)\ \{}
\DoxyCodeLine{00355\ \textcolor{preprocessor}{\#if\ 0}}
\DoxyCodeLine{00356\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((length\ \%\ handle-\/>bps)\ !=\ 0)}
\DoxyCodeLine{00357\ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(stderr,}
\DoxyCodeLine{00358\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}Audio\ read\ returned\ non-\/integral\ \#sample\ bytes\ (\%d)\(\backslash\)n"{}},}
\DoxyCodeLine{00359\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ length);}
\DoxyCodeLine{00360\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00361\ \ \ \ \ \ \ \ \ length\ /=\ handle-\/>bps;}
\DoxyCodeLine{00362\ \ \ \ \ \}}
\DoxyCodeLine{00363\ }
\DoxyCodeLine{00364\ \ \ \ \ \textcolor{keywordflow}{if}\ (length\ <\ 0)\ \{}
\DoxyCodeLine{00365\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (errno\ !=\ EAGAIN)\ \{}
\DoxyCodeLine{00366\ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}Audio\ read\ error"{}});}
\DoxyCodeLine{00367\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ AD\_ERR\_GEN;}
\DoxyCodeLine{00368\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00369\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00370\ \ \ \ \ \ \ \ \ \ \ \ \ length\ =\ 0;}
\DoxyCodeLine{00371\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00372\ \ \ \ \ \}}
\DoxyCodeLine{00373\ }
\DoxyCodeLine{00374\ \ \ \ \ \textcolor{keywordflow}{if}\ ((length\ ==\ 0)\ \&\&\ (!handle-\/>recording))}
\DoxyCodeLine{00375\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ AD\_EOF;}
\DoxyCodeLine{00376\ }
\DoxyCodeLine{00377\ \ \ \ \ \textcolor{keywordflow}{return}\ length;}
\DoxyCodeLine{00378\ \}}

\end{DoxyCode}
