\doxysection{rec\+\_\+win32.\+c}
\label{rec__win32_8c_source}\index{src/libsphinxad/rec\_win32.c@{src/libsphinxad/rec\_win32.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\ }
\DoxyCodeLine{00038\ \textcolor{comment}{/*}}
\DoxyCodeLine{00039\ \textcolor{comment}{\ *\ rec.c\ -\/-\/\ low\ level\ audio\ recording\ for\ Windows\ NT/95.}}
\DoxyCodeLine{00040\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00041\ \textcolor{comment}{\ *\ HISTORY}}
\DoxyCodeLine{00042\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00043\ \textcolor{comment}{\ *\ 19-\/Jan-\/1999\ \ M\ K\ Ravishankar\ (rkm@cs.cmu.edu)\ at\ Carnegie\ Mellon\ University}}
\DoxyCodeLine{00044\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Added\ AD\_\ return\ codes.\ \ Added\ ad\_open\_sps\_bufsize(),\ and}}
\DoxyCodeLine{00045\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ ad\_rec\_t.n\_buf.}}
\DoxyCodeLine{00046\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00047\ \textcolor{comment}{\ *\ 07-\/Mar-\/98\ \ \ \ M\ K\ Ravishankar\ (rkm@cs.cmu.edu)\ at\ Carnegie\ Mellon\ University}}
\DoxyCodeLine{00048\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Added\ ad\_open\_sps(),\ and\ made\ ad\_open()\ call\ it.}}
\DoxyCodeLine{00049\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00050\ \textcolor{comment}{\ *\ 10-\/Jun-\/96\ \ \ \ M\ K\ Ravishankar\ (rkm@cs.cmu.edu)\ at\ Carnegie\ Mellon\ University}}
\DoxyCodeLine{00051\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Added\ ad\_rec\_t\ type\ to\ all\ calls.}}
\DoxyCodeLine{00052\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00053\ \textcolor{comment}{\ *\ 03-\/Jun-\/96\ \ \ \ M\ K\ Ravishankar\ (rkm@cs.cmu.edu)\ at\ Carnegie\ Mellon\ University}}
\DoxyCodeLine{00054\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Created.}}
\DoxyCodeLine{00055\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00056\ }
\DoxyCodeLine{00057\ }
\DoxyCodeLine{00058\ \textcolor{preprocessor}{\#include\ <windows.h>}}
\DoxyCodeLine{00059\ \textcolor{preprocessor}{\#include\ <mmsystem.h>}}
\DoxyCodeLine{00060\ \textcolor{preprocessor}{\#include\ <stdio.h>}}
\DoxyCodeLine{00061\ \textcolor{preprocessor}{\#include\ <stdlib.h>}}
\DoxyCodeLine{00062\ \textcolor{preprocessor}{\#include\ <string.h>}}
\DoxyCodeLine{00063\ }
\DoxyCodeLine{00064\ \textcolor{preprocessor}{\#include\ "{}sphinxbase/prim\_type.h"{}}}
\DoxyCodeLine{00065\ \textcolor{preprocessor}{\#include\ "{}sphinxbase/ad.h"{}}}
\DoxyCodeLine{00066\ }
\DoxyCodeLine{00067\ }
\DoxyCodeLine{00068\ \textcolor{preprocessor}{\#define\ DEFAULT\_N\_WI\_BUF\ \ \ \ \ \ \ \ 32\ \ \ \ \ \ }\textcolor{comment}{/*\ \#Recording\ bufs\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00069\ \textcolor{preprocessor}{\#define\ WI\_BUFSIZE\ \ \ \ \ \ \ \ \ \ \ \ \ \ 2500\ \ \ \ }\textcolor{comment}{/*\ Samples/buf\ (Why\ this\ specific\ value??}}
\DoxyCodeLine{00070\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ So\ that\ at\ reasonable\ sampling\ rates}}
\DoxyCodeLine{00071\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ data\ is\ returned\ frequently\ enough.)\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00072\ }
\DoxyCodeLine{00073\ \textcolor{comment}{/*\ Silvio\ Moioli:\ using\ OutputDebugStringW\ instead\ of\ OutputDebugString\ */}}
\DoxyCodeLine{00074\ \textcolor{preprocessor}{\#ifdef\ \_WIN32\_WCE}}
\DoxyCodeLine{00075\ \textcolor{preprocessor}{\#include\ "{}ckd\_alloc.h"{}}}
\DoxyCodeLine{00076\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00077\ wavein\_error(\textcolor{keywordtype}{char}\ *src,\ int32\ ret)}
\DoxyCodeLine{00078\ \{}
\DoxyCodeLine{00079\ \ \ \ \ TCHAR\ errbuf[512];}
\DoxyCodeLine{00080\ \ \ \ \ \textcolor{keywordtype}{wchar\_t}*\ werrbuf;}
\DoxyCodeLine{00081\ \ \ \ \ \textcolor{keywordtype}{size\_t}\ len;}
\DoxyCodeLine{00082\ }
\DoxyCodeLine{00083\ \ \ \ \ waveOutGetErrorText(ret,\ errbuf,\ \textcolor{keyword}{sizeof}(errbuf));}
\DoxyCodeLine{00084\ \ \ \ \ len\ =\ mbstowcs(NULL,\ errbuf,\ 0)\ +\ 1;}
\DoxyCodeLine{00085\ \ \ \ \ werrbuf\ =\ ckd\_calloc(len,\ \textcolor{keyword}{sizeof}(*werrbuf));}
\DoxyCodeLine{00086\ \ \ \ \ mbstowcs(werrbuf,\ errbuf,\ len);}
\DoxyCodeLine{00087\ }
\DoxyCodeLine{00088\ \ \ \ \ OutputDebugStringW(werrbuf);}
\DoxyCodeLine{00089\ \}}
\DoxyCodeLine{00090\ }
\DoxyCodeLine{00091\ \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{00092\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00093\ wavein\_error(\textcolor{keywordtype}{char}\ *src,\ int32\ ret)}
\DoxyCodeLine{00094\ \{}
\DoxyCodeLine{00095\ \ \ \ \ \textcolor{keywordtype}{char}\ errbuf[1024];}
\DoxyCodeLine{00096\ }
\DoxyCodeLine{00097\ \ \ \ \ waveInGetErrorText(ret,\ errbuf,\ \textcolor{keyword}{sizeof}(errbuf));}
\DoxyCodeLine{00098\ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}\%s\ error\ \%d:\ \%s\(\backslash\)n"{}},\ src,\ ret,\ errbuf);}
\DoxyCodeLine{00099\ \}}
\DoxyCodeLine{00100\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00101\ }
\DoxyCodeLine{00102\ }
\DoxyCodeLine{00103\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00104\ wavein\_free\_buf(ad\_wbuf\_t\ *\ b)}
\DoxyCodeLine{00105\ \{}
\DoxyCodeLine{00106\ \ \ \ \ GlobalUnlock(b-\/>h\_whdr);}
\DoxyCodeLine{00107\ \ \ \ \ GlobalFree(b-\/>h\_whdr);}
\DoxyCodeLine{00108\ \ \ \ \ GlobalUnlock(b-\/>h\_buf);}
\DoxyCodeLine{00109\ \ \ \ \ GlobalFree(b-\/>h\_buf);}
\DoxyCodeLine{00110\ \}}
\DoxyCodeLine{00111\ }
\DoxyCodeLine{00112\ }
\DoxyCodeLine{00113\ \textcolor{keyword}{static}\ int32}
\DoxyCodeLine{00114\ wavein\_alloc\_buf(ad\_wbuf\_t\ *\ b,\ int32\ samples\_per\_buf)}
\DoxyCodeLine{00115\ \{}
\DoxyCodeLine{00116\ \ \ \ \ HGLOBAL\ h\_buf;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ handle\ to\ data\ buffer\ */}}
\DoxyCodeLine{00117\ \ \ \ \ LPSTR\ p\_buf;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ pointer\ to\ data\ buffer\ */}}
\DoxyCodeLine{00118\ \ \ \ \ HGLOBAL\ h\_whdr;\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ handle\ to\ header\ */}}
\DoxyCodeLine{00119\ \ \ \ \ LPWAVEHDR\ p\_whdr;\ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ pointer\ to\ header\ */}}
\DoxyCodeLine{00120\ }
\DoxyCodeLine{00121\ \ \ \ \ \textcolor{comment}{/*\ Allocate\ data\ buffer\ */}}
\DoxyCodeLine{00122\ \ \ \ \ h\_buf\ =}
\DoxyCodeLine{00123\ \ \ \ \ \ \ \ \ GlobalAlloc(GMEM\_MOVEABLE\ |\ GMEM\_SHARE,}
\DoxyCodeLine{00124\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ samples\_per\_buf\ *\ \textcolor{keyword}{sizeof}(int16));}
\DoxyCodeLine{00125\ \ \ \ \ \textcolor{keywordflow}{if}\ (!h\_buf)\ \{}
\DoxyCodeLine{00126\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}GlobalAlloc\ failed\(\backslash\)n"{}});}
\DoxyCodeLine{00127\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00128\ \ \ \ \ \}}
\DoxyCodeLine{00129\ \ \ \ \ \textcolor{keywordflow}{if}\ ((p\_buf\ =\ GlobalLock(h\_buf))\ ==\ NULL)\ \{}
\DoxyCodeLine{00130\ \ \ \ \ \ \ \ \ GlobalFree(h\_buf);}
\DoxyCodeLine{00131\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}GlobalLock\ failed\(\backslash\)n"{}});}
\DoxyCodeLine{00132\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00133\ \ \ \ \ \}}
\DoxyCodeLine{00134\ }
\DoxyCodeLine{00135\ \ \ \ \ \textcolor{comment}{/*\ Allocate\ WAVEHDR\ structure\ */}}
\DoxyCodeLine{00136\ \ \ \ \ h\_whdr\ =\ GlobalAlloc(GMEM\_MOVEABLE\ |\ GMEM\_SHARE,\ \textcolor{keyword}{sizeof}(WAVEHDR));}
\DoxyCodeLine{00137\ \ \ \ \ \textcolor{keywordflow}{if}\ (h\_whdr\ ==\ NULL)\ \{}
\DoxyCodeLine{00138\ \ \ \ \ \ \ \ \ GlobalUnlock(h\_buf);}
\DoxyCodeLine{00139\ \ \ \ \ \ \ \ \ GlobalFree(h\_buf);}
\DoxyCodeLine{00140\ }
\DoxyCodeLine{00141\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}GlobalAlloc\ failed\(\backslash\)n"{}});}
\DoxyCodeLine{00142\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00143\ \ \ \ \ \}}
\DoxyCodeLine{00144\ \ \ \ \ \textcolor{keywordflow}{if}\ ((p\_whdr\ =\ GlobalLock(h\_whdr))\ ==\ NULL)\ \{}
\DoxyCodeLine{00145\ \ \ \ \ \ \ \ \ GlobalUnlock(h\_buf);}
\DoxyCodeLine{00146\ \ \ \ \ \ \ \ \ GlobalFree(h\_buf);}
\DoxyCodeLine{00147\ \ \ \ \ \ \ \ \ GlobalFree(h\_whdr);}
\DoxyCodeLine{00148\ }
\DoxyCodeLine{00149\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}GlobalLock\ failed\(\backslash\)n"{}});}
\DoxyCodeLine{00150\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00151\ \ \ \ \ \}}
\DoxyCodeLine{00152\ }
\DoxyCodeLine{00153\ \ \ \ \ b-\/>h\_buf\ =\ h\_buf;}
\DoxyCodeLine{00154\ \ \ \ \ b-\/>p\_buf\ =\ p\_buf;}
\DoxyCodeLine{00155\ \ \ \ \ b-\/>h\_whdr\ =\ h\_whdr;}
\DoxyCodeLine{00156\ \ \ \ \ b-\/>p\_whdr\ =\ p\_whdr;}
\DoxyCodeLine{00157\ }
\DoxyCodeLine{00158\ \ \ \ \ p\_whdr-\/>lpData\ =\ p\_buf;}
\DoxyCodeLine{00159\ \ \ \ \ p\_whdr-\/>dwBufferLength\ =\ samples\_per\_buf\ *\ \textcolor{keyword}{sizeof}(int16);}
\DoxyCodeLine{00160\ \ \ \ \ p\_whdr-\/>dwUser\ =\ 0L;}
\DoxyCodeLine{00161\ \ \ \ \ p\_whdr-\/>dwFlags\ =\ 0L;}
\DoxyCodeLine{00162\ \ \ \ \ p\_whdr-\/>dwLoops\ =\ 0L;}
\DoxyCodeLine{00163\ }
\DoxyCodeLine{00164\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00165\ \}}
\DoxyCodeLine{00166\ }
\DoxyCodeLine{00167\ }
\DoxyCodeLine{00168\ \textcolor{keyword}{static}\ int32}
\DoxyCodeLine{00169\ wavein\_enqueue\_buf(HWAVEIN\ h,\ LPWAVEHDR\ whdr)}
\DoxyCodeLine{00170\ \{}
\DoxyCodeLine{00171\ \ \ \ \ int32\ st;}
\DoxyCodeLine{00172\ }
\DoxyCodeLine{00173\ \ \ \ \ \textcolor{keywordflow}{if}\ ((st\ =\ waveInPrepareHeader(h,\ whdr,\ \textcolor{keyword}{sizeof}(WAVEHDR)))\ !=\ 0)\ \{}
\DoxyCodeLine{00174\ \ \ \ \ \ \ \ \ wavein\_error(\textcolor{stringliteral}{"{}waveInPrepareHeader"{}},\ st);}
\DoxyCodeLine{00175\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00176\ \ \ \ \ \}}
\DoxyCodeLine{00177\ \ \ \ \ \textcolor{keywordflow}{if}\ ((st\ =\ waveInAddBuffer(h,\ whdr,\ \textcolor{keyword}{sizeof}(WAVEHDR)))\ !=\ 0)\ \{}
\DoxyCodeLine{00178\ \ \ \ \ \ \ \ \ wavein\_error(\textcolor{stringliteral}{"{}waveInAddBuffer"{}},\ st);}
\DoxyCodeLine{00179\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00180\ \ \ \ \ \}}
\DoxyCodeLine{00181\ }
\DoxyCodeLine{00182\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00183\ \}}
\DoxyCodeLine{00184\ }
\DoxyCodeLine{00185\ }
\DoxyCodeLine{00186\ \textcolor{keyword}{static}\ HWAVEIN}
\DoxyCodeLine{00187\ wavein\_open(int32\ samples\_per\_sec,\ int32\ bytes\_per\_sample)}
\DoxyCodeLine{00188\ \{}
\DoxyCodeLine{00189\ \ \ \ \ WAVEFORMATEX\ wfmt;}
\DoxyCodeLine{00190\ \ \ \ \ int32\ st;}
\DoxyCodeLine{00191\ \ \ \ \ HWAVEIN\ h;}
\DoxyCodeLine{00192\ }
\DoxyCodeLine{00193\ \ \ \ \ \textcolor{keywordflow}{if}\ (bytes\_per\_sample\ !=\ \textcolor{keyword}{sizeof}(int16))\ \{}
\DoxyCodeLine{00194\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}bytes/sample\ !=\ \%d\(\backslash\)n"{}},\ \textcolor{keyword}{sizeof}(int16));}
\DoxyCodeLine{00195\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00196\ \ \ \ \ \}}
\DoxyCodeLine{00197\ }
\DoxyCodeLine{00198\ \ \ \ \ wfmt.wFormatTag\ =\ WAVE\_FORMAT\_PCM;}
\DoxyCodeLine{00199\ \ \ \ \ wfmt.nChannels\ =\ 1;}
\DoxyCodeLine{00200\ \ \ \ \ wfmt.nSamplesPerSec\ =\ samples\_per\_sec;}
\DoxyCodeLine{00201\ \ \ \ \ wfmt.nAvgBytesPerSec\ =\ samples\_per\_sec\ *\ bytes\_per\_sample;}
\DoxyCodeLine{00202\ \ \ \ \ wfmt.nBlockAlign\ =\ bytes\_per\_sample;}
\DoxyCodeLine{00203\ \ \ \ \ wfmt.wBitsPerSample\ =\ 8\ *\ bytes\_per\_sample;}
\DoxyCodeLine{00204\ }
\DoxyCodeLine{00205\ \ \ \ \ \textcolor{comment}{/*\ There\ should\ be\ a\ check\ here\ for\ a\ device\ of\ the\ desired\ type;\ later...\ */}}
\DoxyCodeLine{00206\ }
\DoxyCodeLine{00207\ \ \ \ \ st\ =\ waveInOpen((LPHWAVEIN)\ \&\ h,\ WAVE\_MAPPER,}
\DoxyCodeLine{00208\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (LPWAVEFORMATEX)\ \&\ wfmt,\ (DWORD)\ 0L,\ 0L,}
\DoxyCodeLine{00209\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (DWORD)\ CALLBACK\_NULL);}
\DoxyCodeLine{00210\ \ \ \ \ \textcolor{keywordflow}{if}\ (st\ !=\ 0)\ \{}
\DoxyCodeLine{00211\ \ \ \ \ \ \ \ \ wavein\_error(\textcolor{stringliteral}{"{}waveInOpen"{}},\ st);}
\DoxyCodeLine{00212\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00213\ \ \ \ \ \}}
\DoxyCodeLine{00214\ }
\DoxyCodeLine{00215\ \ \ \ \ \textcolor{keywordflow}{return}\ h;}
\DoxyCodeLine{00216\ \}}
\DoxyCodeLine{00217\ }
\DoxyCodeLine{00218\ }
\DoxyCodeLine{00219\ \textcolor{keyword}{static}\ int32}
\DoxyCodeLine{00220\ wavein\_close(ad\_rec\_t\ *\ r)}
\DoxyCodeLine{00221\ \{}
\DoxyCodeLine{00222\ \ \ \ \ int32\ i,\ st;}
\DoxyCodeLine{00223\ }
\DoxyCodeLine{00224\ \ \ \ \ \textcolor{comment}{/*\ Unprepare\ all\ buffers;\ multiple\ unprepares\ of\ the\ same\ buffer\ are\ benign\ */}}
\DoxyCodeLine{00225\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ r-\/>n\_buf;\ i++)\ \{}
\DoxyCodeLine{00226\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Unpreparing\ an\ unprepared\ buffer,\ on\ the\ other\ hand,\ fails}}
\DoxyCodeLine{00227\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ \ \ on\ Win98/WinME,\ though\ this\ is\ not\ documented\ -\/\ dhuggins@cs,}}
\DoxyCodeLine{00228\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ \ \ 2004-\/07-\/14\ */}}
\DoxyCodeLine{00229\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (!(r-\/>wi\_buf[i].p\_whdr-\/>dwFlags\ \&\ WHDR\_PREPARED))}
\DoxyCodeLine{00230\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{continue};}
\DoxyCodeLine{00231\ \ \ \ \ \ \ \ \ st\ =\ waveInUnprepareHeader(r-\/>h\_wavein,}
\DoxyCodeLine{00232\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>wi\_buf[i].p\_whdr,\ \textcolor{keyword}{sizeof}(WAVEHDR));}
\DoxyCodeLine{00233\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (st\ !=\ 0)\ \{}
\DoxyCodeLine{00234\ \ \ \ \ \ \ \ \ \ \ \ \ wavein\_error(\textcolor{stringliteral}{"{}waveInUnprepareHeader"{}},\ st);}
\DoxyCodeLine{00235\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00236\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00237\ \ \ \ \ \}}
\DoxyCodeLine{00238\ }
\DoxyCodeLine{00239\ \ \ \ \ \textcolor{comment}{/*\ Free\ buffers\ */}}
\DoxyCodeLine{00240\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ r-\/>n\_buf;\ i++)}
\DoxyCodeLine{00241\ \ \ \ \ \ \ \ \ wavein\_free\_buf(\&(r-\/>wi\_buf[i]));}
\DoxyCodeLine{00242\ \ \ \ \ free(r-\/>wi\_buf);}
\DoxyCodeLine{00243\ }
\DoxyCodeLine{00244\ \ \ \ \ \textcolor{keywordflow}{if}\ ((st\ =\ waveInClose(r-\/>h\_wavein))\ !=\ 0)\ \{}
\DoxyCodeLine{00245\ \ \ \ \ \ \ \ \ wavein\_error(\textcolor{stringliteral}{"{}waveInClose"{}},\ st);}
\DoxyCodeLine{00246\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00247\ \ \ \ \ \}}
\DoxyCodeLine{00248\ }
\DoxyCodeLine{00249\ \ \ \ \ free(r);}
\DoxyCodeLine{00250\ }
\DoxyCodeLine{00251\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00252\ \}}
\DoxyCodeLine{00253\ }
\DoxyCodeLine{00254\ }
\DoxyCodeLine{00255\ ad\_rec\_t\ *}
\DoxyCodeLine{00256\ ad\_open\_sps\_bufsize(int32\ sps,\ int32\ bufsize\_msec)}
\DoxyCodeLine{00257\ \{}
\DoxyCodeLine{00258\ \ \ \ \ ad\_rec\_t\ *r;}
\DoxyCodeLine{00259\ \ \ \ \ int32\ i,\ j;}
\DoxyCodeLine{00260\ \ \ \ \ HWAVEIN\ h;}
\DoxyCodeLine{00261\ }
\DoxyCodeLine{00262\ \ \ \ \ \textcolor{keywordflow}{if}\ ((h\ =\ wavein\_open(sps,\ \textcolor{keyword}{sizeof}(int16)))\ ==\ NULL)}
\DoxyCodeLine{00263\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00264\ }
\DoxyCodeLine{00265\ \ \ \ \ \textcolor{keywordflow}{if}\ ((r\ =\ (ad\_rec\_t\ *)\ malloc(\textcolor{keyword}{sizeof}(ad\_rec\_t)))\ ==\ NULL)\ \{}
\DoxyCodeLine{00266\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}malloc(\%d)\ failed\(\backslash\)n"{}},\ \textcolor{keyword}{sizeof}(ad\_rec\_t));}
\DoxyCodeLine{00267\ \ \ \ \ \ \ \ \ waveInClose(h);}
\DoxyCodeLine{00268\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00269\ \ \ \ \ \}}
\DoxyCodeLine{00270\ }
\DoxyCodeLine{00271\ \ \ \ \ r-\/>n\_buf\ =\ ((sps\ *\ bufsize\_msec)\ /\ 1000)\ /\ WI\_BUFSIZE;}
\DoxyCodeLine{00272\ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>n\_buf\ <\ DEFAULT\_N\_WI\_BUF)}
\DoxyCodeLine{00273\ \ \ \ \ \ \ \ \ r-\/>n\_buf\ =\ DEFAULT\_N\_WI\_BUF;}
\DoxyCodeLine{00274\ \ \ \ \ printf(\textcolor{stringliteral}{"{}Allocating\ \%d\ buffers\ of\ \%d\ samples\ each\(\backslash\)n"{}},\ r-\/>n\_buf,}
\DoxyCodeLine{00275\ \ \ \ \ \ \ \ \ \ \ \ WI\_BUFSIZE);}
\DoxyCodeLine{00276\ }
\DoxyCodeLine{00277\ \ \ \ \ \textcolor{keywordflow}{if}\ ((r-\/>wi\_buf\ =}
\DoxyCodeLine{00278\ \ \ \ \ \ \ \ \ \ (ad\_wbuf\_t\ *)\ calloc(r-\/>n\_buf,\ \textcolor{keyword}{sizeof}(ad\_wbuf\_t)))\ ==\ NULL)\ \{}
\DoxyCodeLine{00279\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}calloc(\%d,\%d)\ failed\(\backslash\)n"{}},\ r-\/>n\_buf,}
\DoxyCodeLine{00280\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{sizeof}(ad\_wbuf\_t));}
\DoxyCodeLine{00281\ \ \ \ \ \ \ \ \ free(r);}
\DoxyCodeLine{00282\ \ \ \ \ \ \ \ \ waveInClose(h);}
\DoxyCodeLine{00283\ }
\DoxyCodeLine{00284\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00285\ \ \ \ \ \}}
\DoxyCodeLine{00286\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ r-\/>n\_buf;\ i++)\ \{}
\DoxyCodeLine{00287\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (wavein\_alloc\_buf(\&(r-\/>wi\_buf[i]),\ WI\_BUFSIZE)\ <\ 0)\ \{}
\DoxyCodeLine{00288\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (j\ =\ 0;\ j\ <\ i;\ j++)}
\DoxyCodeLine{00289\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ wavein\_free\_buf(\&(r-\/>wi\_buf[j]));}
\DoxyCodeLine{00290\ \ \ \ \ \ \ \ \ \ \ \ \ free(r-\/>wi\_buf);}
\DoxyCodeLine{00291\ \ \ \ \ \ \ \ \ \ \ \ \ free(r);}
\DoxyCodeLine{00292\ \ \ \ \ \ \ \ \ \ \ \ \ waveInClose(h);}
\DoxyCodeLine{00293\ }
\DoxyCodeLine{00294\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00295\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00296\ \ \ \ \ \}}
\DoxyCodeLine{00297\ }
\DoxyCodeLine{00298\ \ \ \ \ r-\/>h\_wavein\ =\ h;}
\DoxyCodeLine{00299\ \ \ \ \ r-\/>opened\ =\ 1;}
\DoxyCodeLine{00300\ \ \ \ \ r-\/>recording\ =\ 0;}
\DoxyCodeLine{00301\ \ \ \ \ r-\/>curbuf\ =\ r-\/>n\_buf\ -\/\ 1;\ \ \ \textcolor{comment}{/*\ current\ buffer\ with\ data\ for\ application\ */}}
\DoxyCodeLine{00302\ \ \ \ \ r-\/>curlen\ =\ 0;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ \#samples\ in\ curbuf\ remaining\ to\ be\ consumed\ */}}
\DoxyCodeLine{00303\ \ \ \ \ r-\/>lastbuf\ =\ r-\/>curbuf;}
\DoxyCodeLine{00304\ \ \ \ \ r-\/>sps\ =\ sps;}
\DoxyCodeLine{00305\ \ \ \ \ r-\/>bps\ =\ \textcolor{keyword}{sizeof}(int16);\ \ \ \ \ \textcolor{comment}{/*\ HACK!!\ Hardwired\ value\ for\ bytes/sec\ */}}
\DoxyCodeLine{00306\ }
\DoxyCodeLine{00307\ \ \ \ \ \textcolor{keywordflow}{return}\ r;}
\DoxyCodeLine{00308\ \}}
\DoxyCodeLine{00309\ }
\DoxyCodeLine{00310\ \textcolor{comment}{/*\ FIXME:\ Dummy\ function,\ doesn't\ actually\ use\ dev.\ */}}
\DoxyCodeLine{00311\ ad\_rec\_t\ *}
\DoxyCodeLine{00312\ ad\_open\_dev(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *dev,\ int32\ sps)}
\DoxyCodeLine{00313\ \{}
\DoxyCodeLine{00314\ \ \ \ \ \textcolor{keywordflow}{return}\ (ad\_open\_sps\_bufsize}
\DoxyCodeLine{00315\ \ \ \ \ \ \ \ \ \ \ \ \ (sps,\ WI\_BUFSIZE\ *\ DEFAULT\_N\_WI\_BUF\ *\ 1000\ /\ sps));}
\DoxyCodeLine{00316\ \}}
\DoxyCodeLine{00317\ }
\DoxyCodeLine{00318\ }
\DoxyCodeLine{00319\ ad\_rec\_t\ *}
\DoxyCodeLine{00320\ ad\_open\_sps(int32\ sps)}
\DoxyCodeLine{00321\ \{}
\DoxyCodeLine{00322\ \ \ \ \ \textcolor{keywordflow}{return}\ (ad\_open\_sps\_bufsize}
\DoxyCodeLine{00323\ \ \ \ \ \ \ \ \ \ \ \ \ (sps,\ WI\_BUFSIZE\ *\ DEFAULT\_N\_WI\_BUF\ *\ 1000\ /\ sps));}
\DoxyCodeLine{00324\ \}}
\DoxyCodeLine{00325\ }
\DoxyCodeLine{00326\ }
\DoxyCodeLine{00327\ ad\_rec\_t\ *}
\DoxyCodeLine{00328\ ad\_open(\textcolor{keywordtype}{void})}
\DoxyCodeLine{00329\ \{}
\DoxyCodeLine{00330\ \ \ \ \ \textcolor{keywordflow}{return}\ (ad\_open\_sps(DEFAULT\_SAMPLES\_PER\_SEC));\ \ \ \ \ \ \textcolor{comment}{/*\ HACK!!\ Rename\ this\ constant\ */}}
\DoxyCodeLine{00331\ \}}
\DoxyCodeLine{00332\ }
\DoxyCodeLine{00333\ }
\DoxyCodeLine{00334\ int32}
\DoxyCodeLine{00335\ ad\_close(ad\_rec\_t\ *\ r)}
\DoxyCodeLine{00336\ \{}
\DoxyCodeLine{00337\ \ \ \ \ \textcolor{keywordflow}{if}\ (!r-\/>opened)}
\DoxyCodeLine{00338\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ AD\_ERR\_NOT\_OPEN;}
\DoxyCodeLine{00339\ }
\DoxyCodeLine{00340\ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>recording)}
\DoxyCodeLine{00341\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (ad\_stop\_rec(r)\ <\ 0)}
\DoxyCodeLine{00342\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ AD\_ERR\_WAVE;}
\DoxyCodeLine{00343\ }
\DoxyCodeLine{00344\ \ \ \ \ \textcolor{keywordflow}{if}\ (wavein\_close(r)\ <\ 0)}
\DoxyCodeLine{00345\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ AD\_ERR\_WAVE;}
\DoxyCodeLine{00346\ }
\DoxyCodeLine{00347\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00348\ \}}
\DoxyCodeLine{00349\ }
\DoxyCodeLine{00350\ }
\DoxyCodeLine{00351\ int32}
\DoxyCodeLine{00352\ ad\_start\_rec(ad\_rec\_t\ *\ r)}
\DoxyCodeLine{00353\ \{}
\DoxyCodeLine{00354\ \ \ \ \ int32\ i;}
\DoxyCodeLine{00355\ }
\DoxyCodeLine{00356\ \ \ \ \ \textcolor{keywordflow}{if}\ ((!r-\/>opened)\ ||\ r-\/>recording)}
\DoxyCodeLine{00357\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00358\ }
\DoxyCodeLine{00359\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ r-\/>n\_buf;\ i++)}
\DoxyCodeLine{00360\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (wavein\_enqueue\_buf(r-\/>h\_wavein,\ r-\/>wi\_buf[i].p\_whdr)\ <\ 0)}
\DoxyCodeLine{00361\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ AD\_ERR\_WAVE;}
\DoxyCodeLine{00362\ \ \ \ \ r-\/>curbuf\ =\ r-\/>n\_buf\ -\/\ 1;\ \ \ \textcolor{comment}{/*\ current\ buffer\ with\ data\ for\ application\ */}}
\DoxyCodeLine{00363\ \ \ \ \ r-\/>curlen\ =\ 0;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ \#samples\ in\ curbuf\ remaining\ to\ be\ consumed\ */}}
\DoxyCodeLine{00364\ }
\DoxyCodeLine{00365\ \ \ \ \ \textcolor{keywordflow}{if}\ (waveInStart(r-\/>h\_wavein)\ !=\ 0)}
\DoxyCodeLine{00366\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ AD\_ERR\_WAVE;}
\DoxyCodeLine{00367\ }
\DoxyCodeLine{00368\ \ \ \ \ r-\/>recording\ =\ 1;}
\DoxyCodeLine{00369\ }
\DoxyCodeLine{00370\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00371\ \}}
\DoxyCodeLine{00372\ }
\DoxyCodeLine{00373\ }
\DoxyCodeLine{00374\ int32}
\DoxyCodeLine{00375\ ad\_stop\_rec(ad\_rec\_t\ *\ r)}
\DoxyCodeLine{00376\ \{}
\DoxyCodeLine{00377\ \ \ \ \ int32\ i,\ st;}
\DoxyCodeLine{00378\ }
\DoxyCodeLine{00379\ \ \ \ \ \textcolor{keywordflow}{if}\ ((!r-\/>opened)\ ||\ (!r-\/>recording))}
\DoxyCodeLine{00380\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00381\ }
\DoxyCodeLine{00382\ \ \ \ \ \textcolor{keywordflow}{if}\ (waveInStop(r-\/>h\_wavein)\ !=\ 0)}
\DoxyCodeLine{00383\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ AD\_ERR\_WAVE;}
\DoxyCodeLine{00384\ }
\DoxyCodeLine{00385\ \ \ \ \ \textcolor{keywordflow}{if}\ ((st\ =\ waveInReset(r-\/>h\_wavein))\ !=\ 0)\ \{}
\DoxyCodeLine{00386\ \ \ \ \ \ \ \ \ wavein\_error(\textcolor{stringliteral}{"{}waveInReset"{}},\ st);}
\DoxyCodeLine{00387\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ AD\_ERR\_WAVE;}
\DoxyCodeLine{00388\ \ \ \ \ \}}
\DoxyCodeLine{00389\ }
\DoxyCodeLine{00390\ \ \ \ \ \textcolor{comment}{/*\ Wait\ until\ all\ buffers\ marked\ done\ */}}
\DoxyCodeLine{00391\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ r-\/>n\_buf;\ i++)}
\DoxyCodeLine{00392\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{while}\ (!(r-\/>wi\_buf[i].p\_whdr-\/>dwFlags\ \&\ WHDR\_DONE));}
\DoxyCodeLine{00393\ }
\DoxyCodeLine{00394\ \ \ \ \ \textcolor{keywordflow}{if}\ ((r-\/>lastbuf\ =\ r-\/>curbuf\ -\/\ 1)\ <\ 0)}
\DoxyCodeLine{00395\ \ \ \ \ \ \ \ \ r-\/>lastbuf\ =\ r-\/>n\_buf\ -\/\ 1;}
\DoxyCodeLine{00396\ }
\DoxyCodeLine{00397\ \ \ \ \ r-\/>recording\ =\ 0;}
\DoxyCodeLine{00398\ }
\DoxyCodeLine{00399\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00400\ \}}
\DoxyCodeLine{00401\ }
\DoxyCodeLine{00402\ }
\DoxyCodeLine{00403\ int32}
\DoxyCodeLine{00404\ ad\_read(ad\_rec\_t\ *\ r,\ int16\ *\ buf,\ int32\ max)}
\DoxyCodeLine{00405\ \{}
\DoxyCodeLine{00406\ \ \ \ \ int32\ t,\ st,\ len;}
\DoxyCodeLine{00407\ \ \ \ \ LPWAVEHDR\ whdr;}
\DoxyCodeLine{00408\ \ \ \ \ int16\ *sysbufp;}
\DoxyCodeLine{00409\ }
\DoxyCodeLine{00410\ \ \ \ \ \textcolor{keywordflow}{if}\ (!r-\/>opened)}
\DoxyCodeLine{00411\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ AD\_ERR\_NOT\_OPEN;}
\DoxyCodeLine{00412\ }
\DoxyCodeLine{00413\ \ \ \ \ \textcolor{comment}{/*\ Check\ if\ all\ recorded\ data\ exhausted\ */}}
\DoxyCodeLine{00414\ \ \ \ \ \textcolor{keywordflow}{if}\ ((!r-\/>recording)\ \&\&\ (r-\/>curbuf\ ==\ r-\/>lastbuf)}
\DoxyCodeLine{00415\ \ \ \ \ \ \ \ \ \&\&\ (r-\/>curlen\ ==\ 0))}
\DoxyCodeLine{00416\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ AD\_EOF;}
\DoxyCodeLine{00417\ }
\DoxyCodeLine{00418\ \ \ \ \ len\ =\ 0;}
\DoxyCodeLine{00419\ \ \ \ \ \textcolor{keywordflow}{while}\ (max\ >\ 0)\ \{}
\DoxyCodeLine{00420\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Look\ for\ next\ buffer\ with\ recording\ data\ */}}
\DoxyCodeLine{00421\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>curlen\ ==\ 0)\ \{}
\DoxyCodeLine{00422\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ No\ current\ buffer\ with\ data;\ get\ next\ buffer\ in\ sequence\ if\ available\ */}}
\DoxyCodeLine{00423\ \ \ \ \ \ \ \ \ \ \ \ \ t\ =\ r-\/>curbuf\ +\ 1;}
\DoxyCodeLine{00424\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (t\ >=\ r-\/>n\_buf)}
\DoxyCodeLine{00425\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ t\ =\ 0;}
\DoxyCodeLine{00426\ }
\DoxyCodeLine{00427\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (!(r-\/>wi\_buf[t].p\_whdr-\/>dwFlags\ \&\ WHDR\_DONE))}
\DoxyCodeLine{00428\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ len;}
\DoxyCodeLine{00429\ }
\DoxyCodeLine{00430\ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>curbuf\ =\ t;}
\DoxyCodeLine{00431\ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>curlen\ =\ r-\/>wi\_buf[t].p\_whdr-\/>dwBytesRecorded\ >>\ 1;}
\DoxyCodeLine{00432\ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>curoff\ =\ 0;}
\DoxyCodeLine{00433\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00434\ }
\DoxyCodeLine{00435\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Copy\ data\ from\ curbuf\ to\ buf\ */}}
\DoxyCodeLine{00436\ \ \ \ \ \ \ \ \ whdr\ =\ r-\/>wi\_buf[r-\/>curbuf].p\_whdr;}
\DoxyCodeLine{00437\ \ \ \ \ \ \ \ \ t\ =\ (max\ <\ r-\/>curlen)\ ?\ max\ :\ r-\/>curlen;\ \ \ \ \ \ \ \ \textcolor{comment}{/*\ \#Samples\ to\ copy\ */}}
\DoxyCodeLine{00438\ }
\DoxyCodeLine{00439\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (t\ >\ 0)\ \{}
\DoxyCodeLine{00440\ \ \ \ \ \ \ \ \ \ \ \ \ sysbufp\ =\ (int16\ *)\ (whdr-\/>lpData);}
\DoxyCodeLine{00441\ \ \ \ \ \ \ \ \ \ \ \ \ memcpy(buf,\ sysbufp\ +\ r-\/>curoff,\ t\ *\ \textcolor{keyword}{sizeof}(int16));}
\DoxyCodeLine{00442\ }
\DoxyCodeLine{00443\ \ \ \ \ \ \ \ \ \ \ \ \ buf\ +=\ t;}
\DoxyCodeLine{00444\ \ \ \ \ \ \ \ \ \ \ \ \ max\ -\/=\ t;}
\DoxyCodeLine{00445\ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>curoff\ +=\ t;}
\DoxyCodeLine{00446\ \ \ \ \ \ \ \ \ \ \ \ \ r-\/>curlen\ -\/=\ t;}
\DoxyCodeLine{00447\ \ \ \ \ \ \ \ \ \ \ \ \ len\ +=\ t;}
\DoxyCodeLine{00448\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00449\ }
\DoxyCodeLine{00450\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ If\ curbuf\ empty\ recycle\ it\ to\ system\ if\ still\ recording\ */}}
\DoxyCodeLine{00451\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>curlen\ ==\ 0)\ \{}
\DoxyCodeLine{00452\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (r-\/>recording)\ \{}
\DoxyCodeLine{00453\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Return\ empty\ buffer\ to\ system\ */}}
\DoxyCodeLine{00454\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ st\ =\ waveInUnprepareHeader(r-\/>h\_wavein,}
\DoxyCodeLine{00455\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ whdr,\ \textcolor{keyword}{sizeof}(WAVEHDR));}
\DoxyCodeLine{00456\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (st\ !=\ 0)\ \{}
\DoxyCodeLine{00457\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ wavein\_error(\textcolor{stringliteral}{"{}waveInUnprepareHeader"{}},\ st);}
\DoxyCodeLine{00458\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ AD\_ERR\_WAVE;}
\DoxyCodeLine{00459\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00460\ }
\DoxyCodeLine{00461\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (wavein\_enqueue\_buf(r-\/>h\_wavein,\ whdr)\ <\ 0)}
\DoxyCodeLine{00462\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ AD\_ERR\_WAVE;}
\DoxyCodeLine{00463\ }
\DoxyCodeLine{00464\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00465\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (r-\/>curbuf\ ==\ r-\/>lastbuf)\ \{}
\DoxyCodeLine{00466\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ len;}
\DoxyCodeLine{00467\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00468\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00469\ \ \ \ \ \}}
\DoxyCodeLine{00470\ }
\DoxyCodeLine{00471\ \ \ \ \ \textcolor{keywordflow}{return}\ len;}
\DoxyCodeLine{00472\ \}}

\end{DoxyCode}
