libsent/src/adin/adin_mic_o2.c

説明を見る。
00001 
00034 /*
00035  * Copyright (c) 1991-2006 Kawahara Lab., Kyoto University
00036  * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology
00037  * Copyright (c) 2005-2006 Julius project team, Nagoya Institute of Technology
00038  * All rights reserved
00039  */
00040 
00041 #include <sent/stddefs.h>
00042 #include <sent/adin.h>
00043 
00044 /* sound header */
00045 #include <audio.h>
00046 static ALconfig ac;             
00047 static ALport aport;            
00048 
00056 static boolean
00057 adin_o2_setup_global(double rate)
00058 {
00059   int device;
00060   ALpv setPVbuf[4];
00061 
00062   setPVbuf[0].param   = AL_INTERFACE;
00063   setPVbuf[0].value.i = alGetResourceByName(AL_SYSTEM, "Microphone", AL_INTERFACE_TYPE);
00064   setPVbuf[1].param   = AL_MASTER_CLOCK;
00065   setPVbuf[1].value.i = AL_CRYSTAL_MCLK_TYPE;
00066   setPVbuf[2].param   = AL_RATE;
00067   setPVbuf[2].value.ll= alDoubleToFixed(rate);
00068   device = alGetResourceByName(AL_SYSTEM, "Microphone", AL_DEVICE_TYPE);
00069   if (alSetParams(device, setPVbuf, 3) < 0) {
00070     return FALSE;
00071   } else {
00072     return TRUE;
00073   }
00074 }
00075 
00084 boolean
00085 adin_mic_standby(int sfreq, void *dummy)
00086 {
00087   long rate;
00088   long prec = AL_SAMPLE_16;
00089   long encd = AL_SAMPFMT_TWOSCOMP;
00090   long chan = AL_MONO;
00091 
00092   /* global setup */
00093   rate = sfreq;
00094   if (adin_o2_setup_global((double)rate) == FALSE) { /* failed */
00095     j_printerr("cannot setup microphone device (global)\n");
00096     return(FALSE);
00097   }
00098 
00099   /* local parameter setup */
00100   if ((ac = ALnewconfig()) == 0) {
00101     j_printerr("cannot config microphone device (local)\n");
00102     return(FALSE);
00103   }
00104   ALsetqueuesize(ac, rate * 2 * 1); /* 2 sec. of mono. */
00105   ALsetwidth(ac, prec);
00106   ALsetchannels(ac, chan);
00107   ALsetsampfmt(ac, encd);
00108 
00109   j_printf("local microphone port successfully initialized\n");
00110   return(TRUE);
00111 }
00112   
00118 boolean
00119 adin_mic_start()
00120 {
00121   /* open audio port */
00122   aport = ALopenport("mic","r",ac);
00123   if (aport == (ALport)(0)) {
00124     j_printerr("cannot open microphone audio port for reading\n");
00125     return(FALSE);
00126   }
00127 
00128   return(TRUE);
00129 }
00130 
00136 boolean
00137 adin_mic_stop()
00138 {
00139   /* close audio port */
00140   ALcloseport(aport);
00141   return(TRUE);
00142 }
00143 
00156 int
00157 adin_mic_read(SP16 *buf, int sampnum)
00158 {
00159   long cnt;
00160 
00161   cnt = ALgetfilled(aport);     /* get samples currently stored in queue */
00162   if (cnt > sampnum) cnt = sampnum;
00163   if (ALreadsamps(aport, buf, cnt) < 0) { /* get them */
00164     j_printerr("Error: failed to read sample\n");
00165     return(-2);                 /* return negative on error */
00166   }
00167   return cnt;
00168 }

Juliusに対してTue Dec 26 16:19:28 2006に生成されました。  doxygen 1.5.0