Julius 4.2
|
00001 00041 /* adin_mic_sp.c --- adin microphone library for spAudio 00042 * by Hideki Banno */ 00043 00044 #include <sp/spAudioLib.h> 00045 00046 #include <sent/stddefs.h> 00047 #include <sent/adin.h> 00048 00049 static spAudio audio = NULL; 00050 static long buffer_length = 256; 00051 00052 static float rate; 00053 00062 boolean 00063 adin_mic_standby(int sfreq, void *dummy) 00064 { 00065 rate = sfreq; 00066 if (adin_mic_start() == FALSE) return FALSE; 00067 if (adin_mic_stop() == FALSE) return FALSE; 00068 return TRUE; 00069 } 00070 00078 boolean 00079 adin_mic_begin(char *pathname) 00080 { 00081 if (audio == NULL) { 00082 audio = spInitAudio(); 00083 } 00084 spSetAudioSampleRate(audio, rate); 00085 spSetAudioChannel(audio, 1); 00086 spSetAudioSampleBit(audio, 16); 00087 #ifdef SP_AUDIO_NONBLOCKING 00088 spSetAudioBlockingMode(audio, SP_AUDIO_NONBLOCKING); 00089 #endif 00090 00091 if (!spOpenAudioDevice(audio, "ro")) { 00092 jlog("Error: adin_sp: failed to open device\n"); 00093 return FALSE; 00094 } 00095 00096 return TRUE; 00097 } 00098 00104 boolean 00105 adin_mic_end() 00106 { 00107 spCloseAudioDevice(audio); 00108 return TRUE; 00109 } 00110 00123 int 00124 adin_mic_read(SP16 *buf, int sampnum) 00125 { 00126 long nread; 00127 00128 #ifdef SP_AUDIO_NONBLOCKING 00129 nread = sampnum; 00130 #else 00131 if (sampnum <= buffer_length) { 00132 nread = sampnum; 00133 } else { 00134 nread = buffer_length; 00135 } 00136 #endif 00137 nread = spReadAudio(audio, (short *)buf, nread); 00138 00139 return nread; 00140 } 00141 00149 char * 00150 adin_mic_input_name() 00151 { 00152 return("SP default device"); 00153 }