00001
00035
00036
00037
00038
00039
00040
00041
00042 #include <sent/stddefs.h>
00043 #include <sent/adin.h>
00044
00045
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
00094 rate = sfreq;
00095 if (adin_o2_setup_global((double)rate) == FALSE) {
00096 jlog("Error: adin_o2: cannot setup microphone device (global)\n");
00097 return(FALSE);
00098 }
00099
00100
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);
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
00119 boolean
00120 adin_mic_begin()
00121 {
00122
00123 aport = ALopenport("mic","r",ac);
00124 if (aport == (ALport)(0)) {
00125 jlog("Error: adin_o2: cannot open microphone audio port for reading\n");
00126 return(FALSE);
00127 }
00128
00129 return(TRUE);
00130 }
00131
00137 boolean
00138 adin_mic_end()
00139 {
00140
00141 ALcloseport(aport);
00142 return(TRUE);
00143 }
00144
00157 int
00158 adin_mic_read(SP16 *buf, int sampnum)
00159 {
00160 long cnt;
00161
00162 cnt = ALgetfilled(aport);
00163 if (cnt > sampnum) cnt = sampnum;
00164 if (ALreadsamps(aport, buf, cnt) < 0) {
00165 jlog("Error: adin_o2: failed to read sample\n");
00166 return(-2);
00167 }
00168 return cnt;
00169 }