Julius 4.2
|
00001 00035 /* 00036 * Copyright (c) 1991-2011 Kawahara Lab., Kyoto University 00037 * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology 00038 * Copyright (c) 2005-2011 Julius project team, Nagoya Institute of Technology 00039 * All rights reserved 00040 */ 00041 00042 #include <sent/stddefs.h> 00043 #include <sent/adin.h> 00044 00045 /* sound header */ 00046 #include <audio.h> 00047 static ALconfig ac; 00048 static ALport aport; 00049 00057 static boolean 00058 adin_o2_setup_global(double rate) 00059 { 00060 int device; 00061 ALpv setPVbuf[4]; 00062 00063 setPVbuf[0].param = AL_INTERFACE; 00064 setPVbuf[0].value.i = alGetResourceByName(AL_SYSTEM, "Microphone", AL_INTERFACE_TYPE); 00065 setPVbuf[1].param = AL_MASTER_CLOCK; 00066 setPVbuf[1].value.i = AL_CRYSTAL_MCLK_TYPE; 00067 setPVbuf[2].param = AL_RATE; 00068 setPVbuf[2].value.ll= alDoubleToFixed(rate); 00069 device = alGetResourceByName(AL_SYSTEM, "Microphone", AL_DEVICE_TYPE); 00070 if (alSetParams(device, setPVbuf, 3) < 0) { 00071 return FALSE; 00072 } else { 00073 return TRUE; 00074 } 00075 } 00076 00085 boolean 00086 adin_mic_standby(int sfreq, void *dummy) 00087 { 00088 long rate; 00089 long prec = AL_SAMPLE_16; 00090 long encd = AL_SAMPFMT_TWOSCOMP; 00091 long chan = AL_MONO; 00092 00093 /* global setup */ 00094 rate = sfreq; 00095 if (adin_o2_setup_global((double)rate) == FALSE) { /* failed */ 00096 jlog("Error: adin_o2: cannot setup microphone device (global)\n"); 00097 return(FALSE); 00098 } 00099 00100 /* local parameter setup */ 00101 if ((ac = ALnewconfig()) == 0) { 00102 jlog("Error: adin_o2: cannot config microphone device (local)\n"); 00103 return(FALSE); 00104 } 00105 ALsetqueuesize(ac, rate * 2 * 1); /* 2 sec. of mono. */ 00106 ALsetwidth(ac, prec); 00107 ALsetchannels(ac, chan); 00108 ALsetsampfmt(ac, encd); 00109 00110 jlog("Stat: adin_o2: local microphone port successfully initialized\n"); 00111 return(TRUE); 00112 } 00113 00121 boolean 00122 adin_mic_begin(char *pathname) 00123 { 00124 /* open audio port */ 00125 if (pathname != NULL) { 00126 jlog("Stat: adin_o2: opening audio device \"%s\"\n", pathname); 00127 aport = ALopenport(pathname,"r",ac); 00128 } else { 00129 aport = ALopenport("mic","r",ac); 00130 } 00131 if (aport == (ALport)(0)) { 00132 jlog("Error: adin_o2: cannot open microphone audio port for reading\n"); 00133 return(FALSE); 00134 } 00135 00136 return(TRUE); 00137 } 00138 00144 boolean 00145 adin_mic_end() 00146 { 00147 /* close audio port */ 00148 ALcloseport(aport); 00149 return(TRUE); 00150 } 00151 00164 int 00165 adin_mic_read(SP16 *buf, int sampnum) 00166 { 00167 long cnt; 00168 00169 cnt = ALgetfilled(aport); /* get samples currently stored in queue */ 00170 if (cnt > sampnum) cnt = sampnum; 00171 if (ALreadsamps(aport, buf, cnt) < 0) { /* get them */ 00172 jlog("Error: adin_o2: failed to read sample\n"); 00173 return(-2); /* return negative on error */ 00174 } 00175 return cnt; 00176 } 00177 00185 char * 00186 adin_mic_input_name() 00187 { 00188 return("Microphone"); 00189 } 00190 00191 /* end of file */