\doxysection{play\+\_\+win32.\+c}
\label{play__win32_8c_source}\index{src/libsphinxad/play\_win32.c@{src/libsphinxad/play\_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}{\ *\ HISTORY}}
\DoxyCodeLine{00040\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00041\ \textcolor{comment}{\ *\ 17-\/Apr-\/98\ \ \ \ M\ K\ Ravishankar\ (rkm@cs.cmu.edu)\ at\ Carnegie\ Mellon\ University}}
\DoxyCodeLine{00042\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Added\ ad\_open\_play\_sps(),\ and\ made\ ad\_open\_play()\ call\ it.}}
\DoxyCodeLine{00043\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00044\ \textcolor{comment}{\ *\ 10-\/Jun-\/96\ \ \ \ M\ K\ Ravishankar\ (rkm@cs.cmu.edu)\ at\ Carnegie\ Mellon\ University}}
\DoxyCodeLine{00045\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Added\ ad\_play\_t\ type\ to\ all\ calls.}}
\DoxyCodeLine{00046\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00047\ \textcolor{comment}{\ *\ 03-\/Jun-\/96\ \ \ \ M\ K\ Ravishankar\ (rkm@cs.cmu.edu)\ at\ Carnegie\ Mellon\ University}}
\DoxyCodeLine{00048\ \textcolor{comment}{\ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ Created.}}
\DoxyCodeLine{00049\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00050\ }
\DoxyCodeLine{00051\ }
\DoxyCodeLine{00052\ \textcolor{preprocessor}{\#include\ <windows.h>}}
\DoxyCodeLine{00053\ \textcolor{preprocessor}{\#include\ <mmsystem.h>}}
\DoxyCodeLine{00054\ \textcolor{preprocessor}{\#include\ <stdio.h>}}
\DoxyCodeLine{00055\ \textcolor{preprocessor}{\#include\ <stdlib.h>}}
\DoxyCodeLine{00056\ \textcolor{preprocessor}{\#include\ <string.h>}}
\DoxyCodeLine{00057\ }
\DoxyCodeLine{00058\ \textcolor{preprocessor}{\#include\ "{}sphinxbase/prim\_type.h"{}}}
\DoxyCodeLine{00059\ \textcolor{preprocessor}{\#include\ "{}sphinxbase/ad.h"{}}}
\DoxyCodeLine{00060\ }
\DoxyCodeLine{00061\ }
\DoxyCodeLine{00062\ \textcolor{preprocessor}{\#define\ WO\_BUFSIZE\ \ \ \ \ \ 3200\ \ \ \ }\textcolor{comment}{/*\ Samples/buf\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00063\ \textcolor{preprocessor}{\#define\ N\_WO\_BUF\ \ \ \ \ \ \ \ 2\ \ \ \ \ \ \ }\textcolor{comment}{/*\ \#Playback\ bufs\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00064\ }
\DoxyCodeLine{00065\ \textcolor{comment}{/*\ Silvio\ Moioli:\ using\ OutputDebugStringW\ instead\ of\ OutputDebugString\ */}}
\DoxyCodeLine{00066\ \textcolor{preprocessor}{\#ifdef\ \_WIN32\_WCE}}
\DoxyCodeLine{00067\ \textcolor{preprocessor}{\#include\ "{}ckd\_alloc.h"{}}}
\DoxyCodeLine{00068\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00069\ waveout\_error(\textcolor{keywordtype}{char}\ *src,\ int32\ ret)}
\DoxyCodeLine{00070\ \{}
\DoxyCodeLine{00071\ \ \ \ \ TCHAR\ errbuf[512];}
\DoxyCodeLine{00072\ \ \ \ \ \textcolor{keywordtype}{wchar\_t}*\ werrbuf;}
\DoxyCodeLine{00073\ \ \ \ \ \textcolor{keywordtype}{size\_t}\ len;}
\DoxyCodeLine{00074\ }
\DoxyCodeLine{00075\ \ \ \ \ waveOutGetErrorText(ret,\ errbuf,\ \textcolor{keyword}{sizeof}(errbuf));}
\DoxyCodeLine{00076\ \ \ \ \ len\ =\ mbstowcs(NULL,\ errbuf,\ 0)\ +\ 1;}
\DoxyCodeLine{00077\ \ \ \ \ werrbuf\ =\ ckd\_calloc(len,\ \textcolor{keyword}{sizeof}(*werrbuf));}
\DoxyCodeLine{00078\ \ \ \ \ mbstowcs(werrbuf,\ errbuf,\ len);}
\DoxyCodeLine{00079\ }
\DoxyCodeLine{00080\ \ \ \ \ OutputDebugStringW(werrbuf);}
\DoxyCodeLine{00081\ \ \}}
\DoxyCodeLine{00082\ }
\DoxyCodeLine{00083\ \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{00084\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00085\ waveout\_error(\textcolor{keywordtype}{char}\ *src,\ int32\ ret)}
\DoxyCodeLine{00086\ \{}
\DoxyCodeLine{00087\ \ \ \ \ \textcolor{keywordtype}{char}\ errbuf[1024];}
\DoxyCodeLine{00088\ }
\DoxyCodeLine{00089\ \ \ \ \ waveOutGetErrorText(ret,\ errbuf,\ \textcolor{keyword}{sizeof}(errbuf));}
\DoxyCodeLine{00090\ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}\%s\ error\ \%d:\ \%s\(\backslash\)n"{}},\ src,\ ret,\ errbuf);}
\DoxyCodeLine{00091\ \}}
\DoxyCodeLine{00092\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00093\ }
\DoxyCodeLine{00094\ }
\DoxyCodeLine{00095\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00096\ waveout\_free\_buf(ad\_wbuf\_t\ *\ b)}
\DoxyCodeLine{00097\ \{}
\DoxyCodeLine{00098\ \ \ \ \ GlobalUnlock(b-\/>h\_whdr);}
\DoxyCodeLine{00099\ \ \ \ \ GlobalFree(b-\/>h\_whdr);}
\DoxyCodeLine{00100\ \ \ \ \ GlobalUnlock(b-\/>h\_buf);}
\DoxyCodeLine{00101\ \ \ \ \ GlobalFree(b-\/>h\_buf);}
\DoxyCodeLine{00102\ \}}
\DoxyCodeLine{00103\ }
\DoxyCodeLine{00104\ }
\DoxyCodeLine{00105\ \textcolor{keyword}{static}\ int32}
\DoxyCodeLine{00106\ waveout\_alloc\_buf(ad\_wbuf\_t\ *\ b,\ int32\ samples\_per\_buf)}
\DoxyCodeLine{00107\ \{}
\DoxyCodeLine{00108\ \ \ \ \ HGLOBAL\ h\_buf;}
\DoxyCodeLine{00109\ \ \ \ \ LPSTR\ p\_buf;}
\DoxyCodeLine{00110\ \ \ \ \ HGLOBAL\ h\_whdr;}
\DoxyCodeLine{00111\ \ \ \ \ LPWAVEHDR\ p\_whdr;}
\DoxyCodeLine{00112\ }
\DoxyCodeLine{00113\ \ \ \ \ \textcolor{comment}{/*\ Allocate\ data\ buffer\ */}}
\DoxyCodeLine{00114\ \ \ \ \ h\_buf\ =}
\DoxyCodeLine{00115\ \ \ \ \ \ \ \ \ GlobalAlloc(GMEM\_MOVEABLE\ |\ GMEM\_SHARE,}
\DoxyCodeLine{00116\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ samples\_per\_buf\ *\ \textcolor{keyword}{sizeof}(int16));}
\DoxyCodeLine{00117\ \ \ \ \ \textcolor{keywordflow}{if}\ (!h\_buf)\ \{}
\DoxyCodeLine{00118\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}GlobalAlloc\ failed\(\backslash\)n"{}});}
\DoxyCodeLine{00119\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00120\ \ \ \ \ \}}
\DoxyCodeLine{00121\ \ \ \ \ \textcolor{keywordflow}{if}\ ((p\_buf\ =\ GlobalLock(h\_buf))\ ==\ NULL)\ \{}
\DoxyCodeLine{00122\ \ \ \ \ \ \ \ \ GlobalFree(h\_buf);}
\DoxyCodeLine{00123\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}GlobalLock\ failed\(\backslash\)n"{}});}
\DoxyCodeLine{00124\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00125\ \ \ \ \ \}}
\DoxyCodeLine{00126\ }
\DoxyCodeLine{00127\ \ \ \ \ \textcolor{comment}{/*\ Allocate\ WAVEHDR\ structure\ */}}
\DoxyCodeLine{00128\ \ \ \ \ h\_whdr\ =\ GlobalAlloc(GMEM\_MOVEABLE\ |\ GMEM\_SHARE,\ \textcolor{keyword}{sizeof}(WAVEHDR));}
\DoxyCodeLine{00129\ \ \ \ \ \textcolor{keywordflow}{if}\ (h\_whdr\ ==\ NULL)\ \{}
\DoxyCodeLine{00130\ \ \ \ \ \ \ \ \ GlobalUnlock(h\_buf);}
\DoxyCodeLine{00131\ \ \ \ \ \ \ \ \ GlobalFree(h\_buf);}
\DoxyCodeLine{00132\ }
\DoxyCodeLine{00133\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}GlobalAlloc\ failed\(\backslash\)n"{}});}
\DoxyCodeLine{00134\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00135\ \ \ \ \ \}}
\DoxyCodeLine{00136\ \ \ \ \ \textcolor{keywordflow}{if}\ ((p\_whdr\ =\ GlobalLock(h\_whdr))\ ==\ NULL)\ \{}
\DoxyCodeLine{00137\ \ \ \ \ \ \ \ \ GlobalUnlock(h\_buf);}
\DoxyCodeLine{00138\ \ \ \ \ \ \ \ \ GlobalFree(h\_buf);}
\DoxyCodeLine{00139\ \ \ \ \ \ \ \ \ GlobalFree(h\_whdr);}
\DoxyCodeLine{00140\ }
\DoxyCodeLine{00141\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}GlobalLock\ failed\(\backslash\)n"{}});}
\DoxyCodeLine{00142\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00143\ \ \ \ \ \}}
\DoxyCodeLine{00144\ }
\DoxyCodeLine{00145\ \ \ \ \ b-\/>h\_buf\ =\ h\_buf;}
\DoxyCodeLine{00146\ \ \ \ \ b-\/>p\_buf\ =\ p\_buf;}
\DoxyCodeLine{00147\ \ \ \ \ b-\/>h\_whdr\ =\ h\_whdr;}
\DoxyCodeLine{00148\ \ \ \ \ b-\/>p\_whdr\ =\ p\_whdr;}
\DoxyCodeLine{00149\ }
\DoxyCodeLine{00150\ \ \ \ \ p\_whdr-\/>lpData\ =\ p\_buf;}
\DoxyCodeLine{00151\ \ \ \ \ p\_whdr-\/>dwBufferLength\ =\ samples\_per\_buf\ *\ \textcolor{keyword}{sizeof}(int16);}
\DoxyCodeLine{00152\ \ \ \ \ p\_whdr-\/>dwUser\ =\ 0L;}
\DoxyCodeLine{00153\ \ \ \ \ p\_whdr-\/>dwFlags\ =\ 0L;}
\DoxyCodeLine{00154\ \ \ \ \ p\_whdr-\/>dwLoops\ =\ 0L;}
\DoxyCodeLine{00155\ }
\DoxyCodeLine{00156\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00157\ \}}
\DoxyCodeLine{00158\ }
\DoxyCodeLine{00159\ }
\DoxyCodeLine{00160\ \textcolor{keyword}{static}\ int32}
\DoxyCodeLine{00161\ waveout\_enqueue\_buf(HWAVEOUT\ h,\ LPWAVEHDR\ whdr)}
\DoxyCodeLine{00162\ \{}
\DoxyCodeLine{00163\ \ \ \ \ int32\ st;}
\DoxyCodeLine{00164\ }
\DoxyCodeLine{00165\ \ \ \ \ \textcolor{keywordflow}{if}\ ((st\ =\ waveOutPrepareHeader(h,\ whdr,\ \textcolor{keyword}{sizeof}(WAVEHDR)))\ !=\ 0)\ \{}
\DoxyCodeLine{00166\ \ \ \ \ \ \ \ \ waveout\_error(\textcolor{stringliteral}{"{}waveOutPrepareHeader"{}},\ st);}
\DoxyCodeLine{00167\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00168\ \ \ \ \ \}}
\DoxyCodeLine{00169\ }
\DoxyCodeLine{00170\ \ \ \ \ \textcolor{keywordflow}{if}\ ((st\ =\ waveOutWrite(h,\ whdr,\ \textcolor{keyword}{sizeof}(WAVEHDR)))\ !=\ 0)\ \{}
\DoxyCodeLine{00171\ \ \ \ \ \ \ \ \ waveout\_error(\textcolor{stringliteral}{"{}waveOutWrite"{}},\ st);}
\DoxyCodeLine{00172\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00173\ \ \ \ \ \}}
\DoxyCodeLine{00174\ }
\DoxyCodeLine{00175\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00176\ \}}
\DoxyCodeLine{00177\ }
\DoxyCodeLine{00178\ }
\DoxyCodeLine{00179\ \textcolor{keyword}{static}\ HWAVEOUT}
\DoxyCodeLine{00180\ waveout\_open(int32\ samples\_per\_sec,\ int32\ bytes\_per\_sample)}
\DoxyCodeLine{00181\ \{}
\DoxyCodeLine{00182\ \ \ \ \ WAVEFORMATEX\ wfmt;}
\DoxyCodeLine{00183\ \ \ \ \ int32\ st;}
\DoxyCodeLine{00184\ \ \ \ \ HWAVEOUT\ h;}
\DoxyCodeLine{00185\ }
\DoxyCodeLine{00186\ \ \ \ \ \textcolor{keywordflow}{if}\ (bytes\_per\_sample\ !=\ \textcolor{keyword}{sizeof}(int16))\ \{}
\DoxyCodeLine{00187\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}bytes/sample\ !=\ \%d\(\backslash\)n"{}},\ \textcolor{keyword}{sizeof}(int16));}
\DoxyCodeLine{00188\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00189\ \ \ \ \ \}}
\DoxyCodeLine{00190\ }
\DoxyCodeLine{00191\ \ \ \ \ wfmt.wFormatTag\ =\ WAVE\_FORMAT\_PCM;}
\DoxyCodeLine{00192\ \ \ \ \ wfmt.nChannels\ =\ 1;}
\DoxyCodeLine{00193\ \ \ \ \ wfmt.nSamplesPerSec\ =\ samples\_per\_sec;}
\DoxyCodeLine{00194\ \ \ \ \ wfmt.nAvgBytesPerSec\ =\ samples\_per\_sec\ *\ bytes\_per\_sample;}
\DoxyCodeLine{00195\ \ \ \ \ wfmt.nBlockAlign\ =\ bytes\_per\_sample;}
\DoxyCodeLine{00196\ \ \ \ \ wfmt.wBitsPerSample\ =\ 8\ *\ bytes\_per\_sample;}
\DoxyCodeLine{00197\ \ \ \ \ wfmt.cbSize\ =\ 0;}
\DoxyCodeLine{00198\ }
\DoxyCodeLine{00199\ \ \ \ \ \textcolor{comment}{/*\ There\ should\ be\ a\ check\ here\ for\ a\ device\ of\ the\ desired\ type;\ later...\ */}}
\DoxyCodeLine{00200\ }
\DoxyCodeLine{00201\ \ \ \ \ st\ =\ waveOutOpen((LPHWAVEOUT)\ \&\ h,\ WAVE\_MAPPER,}
\DoxyCodeLine{00202\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (LPWAVEFORMATEX)\ \&\ wfmt,\ (DWORD)\ 0L,\ 0L,}
\DoxyCodeLine{00203\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (DWORD)\ CALLBACK\_NULL);}
\DoxyCodeLine{00204\ \ \ \ \ \textcolor{keywordflow}{if}\ (st\ !=\ 0)\ \{}
\DoxyCodeLine{00205\ \ \ \ \ \ \ \ \ waveout\_error(\textcolor{stringliteral}{"{}waveOutOpen"{}},\ st);}
\DoxyCodeLine{00206\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00207\ \ \ \ \ \}}
\DoxyCodeLine{00208\ }
\DoxyCodeLine{00209\ \ \ \ \ \textcolor{keywordflow}{return}\ h;}
\DoxyCodeLine{00210\ \}}
\DoxyCodeLine{00211\ }
\DoxyCodeLine{00212\ }
\DoxyCodeLine{00213\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00214\ waveout\_mem\_cleanup(ad\_play\_t\ *\ p,\ int32\ n\_buf)}
\DoxyCodeLine{00215\ \{}
\DoxyCodeLine{00216\ \ \ \ \ int32\ i;}
\DoxyCodeLine{00217\ }
\DoxyCodeLine{00218\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ n\_buf;\ i++)}
\DoxyCodeLine{00219\ \ \ \ \ \ \ \ \ waveout\_free\_buf(\&(p-\/>wo\_buf[i]));}
\DoxyCodeLine{00220\ \ \ \ \ \textcolor{keywordflow}{if}\ (p-\/>wo\_buf)}
\DoxyCodeLine{00221\ \ \ \ \ \ \ \ \ free(p-\/>wo\_buf);}
\DoxyCodeLine{00222\ \ \ \ \ \textcolor{keywordflow}{if}\ (p-\/>busy)}
\DoxyCodeLine{00223\ \ \ \ \ \ \ \ \ free(p-\/>busy);}
\DoxyCodeLine{00224\ \}}
\DoxyCodeLine{00225\ }
\DoxyCodeLine{00226\ }
\DoxyCodeLine{00227\ \textcolor{keyword}{static}\ int32}
\DoxyCodeLine{00228\ waveout\_close(ad\_play\_t\ *\ p)}
\DoxyCodeLine{00229\ \{}
\DoxyCodeLine{00230\ \ \ \ \ int32\ st;}
\DoxyCodeLine{00231\ }
\DoxyCodeLine{00232\ \ \ \ \ waveout\_mem\_cleanup(p,\ N\_WO\_BUF);}
\DoxyCodeLine{00233\ }
\DoxyCodeLine{00234\ \ \ \ \ \textcolor{keywordflow}{if}\ ((st\ =\ waveOutClose(p-\/>h\_waveout))\ !=\ 0)\ \{}
\DoxyCodeLine{00235\ \ \ \ \ \ \ \ \ waveout\_error(\textcolor{stringliteral}{"{}waveOutClose"{}},\ st);}
\DoxyCodeLine{00236\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00237\ \ \ \ \ \}}
\DoxyCodeLine{00238\ }
\DoxyCodeLine{00239\ \ \ \ \ free(p);}
\DoxyCodeLine{00240\ }
\DoxyCodeLine{00241\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00242\ \}}
\DoxyCodeLine{00243\ }
\DoxyCodeLine{00244\ }
\DoxyCodeLine{00245\ ad\_play\_t\ *}
\DoxyCodeLine{00246\ ad\_open\_play\_sps(int32\ sps)}
\DoxyCodeLine{00247\ \{}
\DoxyCodeLine{00248\ \ \ \ \ ad\_play\_t\ *p;}
\DoxyCodeLine{00249\ \ \ \ \ int32\ i;}
\DoxyCodeLine{00250\ \ \ \ \ HWAVEOUT\ h;}
\DoxyCodeLine{00251\ }
\DoxyCodeLine{00252\ \ \ \ \ \textcolor{keywordflow}{if}\ ((h\ =\ waveout\_open(sps,\ \textcolor{keyword}{sizeof}(int16)))\ ==\ NULL)}
\DoxyCodeLine{00253\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00254\ }
\DoxyCodeLine{00255\ \ \ \ \ \textcolor{keywordflow}{if}\ ((p\ =\ (ad\_play\_t\ *)\ calloc(1,\ \textcolor{keyword}{sizeof}(ad\_play\_t)))\ ==\ NULL)\ \{}
\DoxyCodeLine{00256\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}calloc(1,\%d)\ failed\(\backslash\)n"{}},\ \textcolor{keyword}{sizeof}(ad\_play\_t));}
\DoxyCodeLine{00257\ \ \ \ \ \ \ \ \ waveOutClose(h);}
\DoxyCodeLine{00258\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00259\ \ \ \ \ \}}
\DoxyCodeLine{00260\ \ \ \ \ \textcolor{keywordflow}{if}\ ((p-\/>wo\_buf\ =}
\DoxyCodeLine{00261\ \ \ \ \ \ \ \ \ \ (ad\_wbuf\_t\ *)\ calloc(N\_WO\_BUF,\ \textcolor{keyword}{sizeof}(ad\_wbuf\_t)))\ ==\ NULL)\ \{}
\DoxyCodeLine{00262\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}calloc(\%d,\%d)\ failed\(\backslash\)n"{}},\ N\_WO\_BUF,}
\DoxyCodeLine{00263\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{sizeof}(ad\_wbuf\_t));}
\DoxyCodeLine{00264\ \ \ \ \ \ \ \ \ free(p);}
\DoxyCodeLine{00265\ \ \ \ \ \ \ \ \ waveOutClose(h);}
\DoxyCodeLine{00266\ }
\DoxyCodeLine{00267\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00268\ \ \ \ \ \}}
\DoxyCodeLine{00269\ \ \ \ \ \textcolor{keywordflow}{if}\ ((p-\/>busy\ =\ (\textcolor{keywordtype}{char}\ *)\ calloc(N\_WO\_BUF,\ \textcolor{keyword}{sizeof}(\textcolor{keywordtype}{char})))\ ==\ NULL)\ \{}
\DoxyCodeLine{00270\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}calloc(\%d,\%d)\ failed\(\backslash\)n"{}},\ N\_WO\_BUF,\ \textcolor{keyword}{sizeof}(\textcolor{keywordtype}{char}));}
\DoxyCodeLine{00271\ \ \ \ \ \ \ \ \ waveout\_mem\_cleanup(p,\ 0);}
\DoxyCodeLine{00272\ \ \ \ \ \ \ \ \ free(p);}
\DoxyCodeLine{00273\ \ \ \ \ \ \ \ \ waveOutClose(h);}
\DoxyCodeLine{00274\ }
\DoxyCodeLine{00275\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00276\ \ \ \ \ \}}
\DoxyCodeLine{00277\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ N\_WO\_BUF;\ i++)\ \{}
\DoxyCodeLine{00278\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (waveout\_alloc\_buf(\&(p-\/>wo\_buf[i]),\ WO\_BUFSIZE)\ <\ 0)\ \{}
\DoxyCodeLine{00279\ \ \ \ \ \ \ \ \ \ \ \ \ waveout\_mem\_cleanup(p,\ i);}
\DoxyCodeLine{00280\ \ \ \ \ \ \ \ \ \ \ \ \ free(p);}
\DoxyCodeLine{00281\ \ \ \ \ \ \ \ \ \ \ \ \ waveOutClose(h);}
\DoxyCodeLine{00282\ }
\DoxyCodeLine{00283\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00284\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00285\ \ \ \ \ \}}
\DoxyCodeLine{00286\ }
\DoxyCodeLine{00287\ \ \ \ \ p-\/>h\_waveout\ =\ h;}
\DoxyCodeLine{00288\ \ \ \ \ p-\/>playing\ =\ 0;}
\DoxyCodeLine{00289\ \ \ \ \ p-\/>opened\ =\ 1;}
\DoxyCodeLine{00290\ \ \ \ \ p-\/>nxtbuf\ =\ 0;}
\DoxyCodeLine{00291\ \ \ \ \ p-\/>sps\ =\ sps;}
\DoxyCodeLine{00292\ \ \ \ \ p-\/>bps\ =\ \textcolor{keyword}{sizeof}(int16);\ \ \ \ \ \textcolor{comment}{/*\ HACK!!\ Hardwired\ value\ for\ bytes/sec\ */}}
\DoxyCodeLine{00293\ }
\DoxyCodeLine{00294\ \ \ \ \ \textcolor{keywordflow}{return}\ p;}
\DoxyCodeLine{00295\ \}}
\DoxyCodeLine{00296\ }
\DoxyCodeLine{00297\ }
\DoxyCodeLine{00298\ ad\_play\_t\ *}
\DoxyCodeLine{00299\ ad\_open\_play(\textcolor{keywordtype}{void})}
\DoxyCodeLine{00300\ \{}
\DoxyCodeLine{00301\ \ \ \ \ \textcolor{keywordflow}{return}\ (ad\_open\_play\_sps(DEFAULT\_SAMPLES\_PER\_SEC));}
\DoxyCodeLine{00302\ \}}
\DoxyCodeLine{00303\ }
\DoxyCodeLine{00304\ }
\DoxyCodeLine{00305\ int32}
\DoxyCodeLine{00306\ ad\_close\_play(ad\_play\_t\ *\ p)}
\DoxyCodeLine{00307\ \{}
\DoxyCodeLine{00308\ \ \ \ \ \textcolor{keywordflow}{if}\ (!p-\/>opened)}
\DoxyCodeLine{00309\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00310\ }
\DoxyCodeLine{00311\ \ \ \ \ \textcolor{keywordflow}{if}\ (p-\/>playing)}
\DoxyCodeLine{00312\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (ad\_stop\_play(p)\ <\ 0)}
\DoxyCodeLine{00313\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00314\ }
\DoxyCodeLine{00315\ \ \ \ \ \textcolor{keywordflow}{if}\ (waveout\_close(p)\ <\ 0)}
\DoxyCodeLine{00316\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00317\ }
\DoxyCodeLine{00318\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00319\ \}}
\DoxyCodeLine{00320\ }
\DoxyCodeLine{00321\ }
\DoxyCodeLine{00322\ int32}
\DoxyCodeLine{00323\ ad\_start\_play(ad\_play\_t\ *\ p)}
\DoxyCodeLine{00324\ \{}
\DoxyCodeLine{00325\ \ \ \ \ int32\ i;}
\DoxyCodeLine{00326\ }
\DoxyCodeLine{00327\ \ \ \ \ \textcolor{keywordflow}{if}\ ((!p-\/>opened)\ ||\ p-\/>playing)}
\DoxyCodeLine{00328\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00329\ }
\DoxyCodeLine{00330\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ N\_WO\_BUF;\ i++)}
\DoxyCodeLine{00331\ \ \ \ \ \ \ \ \ p-\/>busy[i]\ =\ 0;}
\DoxyCodeLine{00332\ \ \ \ \ p-\/>nxtbuf\ =\ 0;}
\DoxyCodeLine{00333\ \ \ \ \ p-\/>playing\ =\ 1;}
\DoxyCodeLine{00334\ }
\DoxyCodeLine{00335\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00336\ \}}
\DoxyCodeLine{00337\ }
\DoxyCodeLine{00338\ }
\DoxyCodeLine{00339\ int32}
\DoxyCodeLine{00340\ ad\_stop\_play(ad\_play\_t\ *\ p)}
\DoxyCodeLine{00341\ \{}
\DoxyCodeLine{00342\ \ \ \ \ int32\ i,\ st;}
\DoxyCodeLine{00343\ \ \ \ \ LPWAVEHDR\ whdr;}
\DoxyCodeLine{00344\ }
\DoxyCodeLine{00345\ \ \ \ \ \textcolor{keywordflow}{if}\ ((!p-\/>opened)\ ||\ (!p-\/>playing))}
\DoxyCodeLine{00346\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00347\ }
\DoxyCodeLine{00348\ \textcolor{preprocessor}{\#if\ 0}}
\DoxyCodeLine{00349\ \ \ \ \ whdr-\/>dwUser\ =\ (plen\ <=\ 0)\ ?\ 1\ :\ 0;}
\DoxyCodeLine{00350\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00351\ }
\DoxyCodeLine{00352\ \ \ \ \ \textcolor{comment}{/*\ Wait\ for\ all\ buffers\ to\ be\ emptied\ and\ unprepare\ them\ */}}
\DoxyCodeLine{00353\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ N\_WO\_BUF;\ i++)\ \{}
\DoxyCodeLine{00354\ \ \ \ \ \ \ \ \ whdr\ =\ p-\/>wo\_buf[i].p\_whdr;}
\DoxyCodeLine{00355\ }
\DoxyCodeLine{00356\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{while}\ (p-\/>busy[i]\ \&\&\ (!(whdr-\/>dwFlags\ \&\ WHDR\_DONE)))}
\DoxyCodeLine{00357\ \ \ \ \ \ \ \ \ \ \ \ \ Sleep(100);}
\DoxyCodeLine{00358\ }
\DoxyCodeLine{00359\ \ \ \ \ \ \ \ \ st\ =\ waveOutUnprepareHeader(p-\/>h\_waveout,\ whdr,\ \textcolor{keyword}{sizeof}(WAVEHDR));}
\DoxyCodeLine{00360\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (st\ !=\ 0)\ \{}
\DoxyCodeLine{00361\ \ \ \ \ \ \ \ \ \ \ \ \ waveout\_error(\textcolor{stringliteral}{"{}waveOutUnprepareHeader"{}},\ st);}
\DoxyCodeLine{00362\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00363\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00364\ }
\DoxyCodeLine{00365\ \ \ \ \ \ \ \ \ p-\/>busy[i]\ =\ 0;}
\DoxyCodeLine{00366\ \ \ \ \ \}}
\DoxyCodeLine{00367\ }
\DoxyCodeLine{00368\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00369\ \}}
\DoxyCodeLine{00370\ }
\DoxyCodeLine{00371\ }
\DoxyCodeLine{00372\ int32}
\DoxyCodeLine{00373\ ad\_write(ad\_play\_t\ *\ p,\ int16\ *\ buf,\ int32\ size)}
\DoxyCodeLine{00374\ \{}
\DoxyCodeLine{00375\ \ \ \ \ int32\ i,\ k,\ len,\ st;}
\DoxyCodeLine{00376\ \ \ \ \ LPWAVEHDR\ whdr;}
\DoxyCodeLine{00377\ }
\DoxyCodeLine{00378\ \ \ \ \ \textcolor{keywordflow}{if}\ ((!p-\/>opened)\ ||\ (!p-\/>playing))}
\DoxyCodeLine{00379\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00380\ }
\DoxyCodeLine{00381\ \ \ \ \ len\ =\ 0;}
\DoxyCodeLine{00382\ }
\DoxyCodeLine{00383\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ (i\ <\ N\_WO\_BUF)\ \&\&\ (size\ >\ 0);\ i++)\ \{}
\DoxyCodeLine{00384\ \ \ \ \ \ \ \ \ whdr\ =\ p-\/>wo\_buf[p-\/>nxtbuf].p\_whdr;}
\DoxyCodeLine{00385\ }
\DoxyCodeLine{00386\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (p-\/>busy[p-\/>nxtbuf])\ \{}
\DoxyCodeLine{00387\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (!(whdr-\/>dwFlags\ \&\ WHDR\_DONE))}
\DoxyCodeLine{00388\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ len;}
\DoxyCodeLine{00389\ }
\DoxyCodeLine{00390\ \ \ \ \ \ \ \ \ \ \ \ \ st\ =\ waveOutUnprepareHeader(p-\/>h\_waveout,\ whdr,}
\DoxyCodeLine{00391\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{sizeof}(WAVEHDR));}
\DoxyCodeLine{00392\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (st\ !=\ 0)\ \{}
\DoxyCodeLine{00393\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ waveout\_error(\textcolor{stringliteral}{"{}waveOutUnprepareHeader"{}},\ st);}
\DoxyCodeLine{00394\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00395\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00396\ }
\DoxyCodeLine{00397\ \ \ \ \ \ \ \ \ \ \ \ \ p-\/>busy[p-\/>nxtbuf]\ =\ 0;}
\DoxyCodeLine{00398\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00399\ }
\DoxyCodeLine{00400\ \ \ \ \ \ \ \ \ k\ =\ (size\ >\ WO\_BUFSIZE)\ ?\ WO\_BUFSIZE\ :\ size;}
\DoxyCodeLine{00401\ }
\DoxyCodeLine{00402\ \ \ \ \ \ \ \ \ whdr-\/>dwBufferLength\ =\ k\ *\ \textcolor{keyword}{sizeof}(int16);}
\DoxyCodeLine{00403\ \ \ \ \ \ \ \ \ memcpy(whdr-\/>lpData,\ (LPSTR)\ buf,\ k\ *\ \textcolor{keyword}{sizeof}(int16));}
\DoxyCodeLine{00404\ }
\DoxyCodeLine{00405\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (waveout\_enqueue\_buf(p-\/>h\_waveout,\ whdr)\ <\ 0)}
\DoxyCodeLine{00406\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00407\ }
\DoxyCodeLine{00408\ \ \ \ \ \ \ \ \ buf\ +=\ k;}
\DoxyCodeLine{00409\ \ \ \ \ \ \ \ \ size\ -\/=\ k;}
\DoxyCodeLine{00410\ \ \ \ \ \ \ \ \ len\ +=\ k;}
\DoxyCodeLine{00411\ }
\DoxyCodeLine{00412\ \ \ \ \ \ \ \ \ p-\/>busy[(p-\/>nxtbuf)++]\ =\ 1;}
\DoxyCodeLine{00413\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (p-\/>nxtbuf\ >=\ N\_WO\_BUF)}
\DoxyCodeLine{00414\ \ \ \ \ \ \ \ \ \ \ \ \ p-\/>nxtbuf\ =\ 0;}
\DoxyCodeLine{00415\ \ \ \ \ \}}
\DoxyCodeLine{00416\ }
\DoxyCodeLine{00417\ \ \ \ \ \textcolor{keywordflow}{return}\ len;}
\DoxyCodeLine{00418\ \}}

\end{DoxyCode}
