Julius 4.1.5
|
00001 00018 /* 00019 * Copyright (c) 1991-2007 Kawahara Lab., Kyoto University 00020 * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology 00021 * Copyright (c) 2005-2007 Julius project team, Nagoya Institute of Technology 00022 * All rights reserved 00023 */ 00024 00025 #include <julius/julius.h> 00026 00027 00036 static boolean 00037 adin_select(ADIn *a, int source, int dev) 00038 { 00039 switch(source) { 00040 case SP_RAWFILE: 00041 #ifdef HAVE_LIBSNDFILE 00042 /* libsndfile interface */ 00043 a->ad_standby = adin_sndfile_standby; 00044 a->ad_begin = adin_sndfile_begin; 00045 a->ad_end = adin_sndfile_end; 00046 a->ad_resume = NULL; 00047 a->ad_pause = NULL; 00048 a->ad_terminate = NULL; 00049 a->ad_read = adin_sndfile_read; 00050 a->ad_input_name = adin_sndfile_get_current_filename; 00051 a->silence_cut_default = FALSE; 00052 a->enable_thread = FALSE; 00053 #else /* ~HAVE_LIBSNDFILE */ 00054 /* built-in RAW/WAV reader */ 00055 a->ad_standby = adin_file_standby; 00056 a->ad_begin = adin_file_begin; 00057 a->ad_end = adin_file_end; 00058 a->ad_resume = NULL; 00059 a->ad_pause = NULL; 00060 a->ad_terminate = NULL; 00061 a->ad_read = adin_file_read; 00062 a->ad_input_name = adin_file_get_current_filename; 00063 a->silence_cut_default = FALSE; 00064 a->enable_thread = FALSE; 00065 #endif 00066 break; 00067 #ifdef USE_MIC 00068 case SP_MIC: 00069 /* microphone input */ 00070 a->ad_resume = NULL; 00071 a->ad_pause = NULL; 00072 a->ad_terminate = NULL; 00073 a->silence_cut_default = TRUE; 00074 a->enable_thread = TRUE; 00075 switch(dev) { 00076 case SP_INPUT_DEFAULT: 00077 a->ad_standby = adin_mic_standby; 00078 a->ad_begin = adin_mic_begin; 00079 a->ad_end = adin_mic_end; 00080 a->ad_read = adin_mic_read; 00081 a->ad_input_name = adin_mic_input_name; 00082 break; 00083 #ifdef HAS_ALSA 00084 case SP_INPUT_ALSA: 00085 a->ad_standby = adin_alsa_standby; 00086 a->ad_begin = adin_alsa_begin; 00087 a->ad_end = adin_alsa_end; 00088 a->ad_read = adin_alsa_read; 00089 a->ad_input_name = adin_alsa_input_name; 00090 break; 00091 #endif 00092 #ifdef HAS_OSS 00093 case SP_INPUT_OSS: 00094 a->ad_standby = adin_oss_standby; 00095 a->ad_begin = adin_oss_begin; 00096 a->ad_end = adin_oss_end; 00097 a->ad_read = adin_oss_read; 00098 a->ad_input_name = adin_oss_input_name; 00099 break; 00100 #endif 00101 #ifdef HAS_ESD 00102 case SP_INPUT_ESD: 00103 a->ad_standby = adin_esd_standby; 00104 a->ad_begin = adin_esd_begin; 00105 a->ad_end = adin_esd_end; 00106 a->ad_read = adin_esd_read; 00107 a->ad_input_name = adin_esd_input_name; 00108 break; 00109 #endif 00110 default: 00111 jlog("ERROR: m_adin: invalid input device specified\n"); 00112 } 00113 break; 00114 #endif 00115 #ifdef USE_NETAUDIO 00116 case SP_NETAUDIO: 00117 /* DatLink/NetAudio input */ 00118 a->ad_standby = adin_netaudio_standby; 00119 a->ad_begin = adin_netaudio_begin; 00120 a->ad_end = adin_netaudio_end; 00121 a->ad_resume = NULL; 00122 a->ad_pause = NULL; 00123 a->ad_terminate = NULL; 00124 a->ad_read = adin_netaudio_read; 00125 a->ad_input_name = adin_netaudio_input_name; 00126 a->silence_cut_default = TRUE; 00127 a->enable_thread = TRUE; 00128 break; 00129 #endif 00130 case SP_ADINNET: 00131 /* adinnet network input */ 00132 a->ad_standby = adin_tcpip_standby; 00133 a->ad_begin = adin_tcpip_begin; 00134 a->ad_end = adin_tcpip_end; 00135 a->ad_resume = adin_tcpip_send_resume; 00136 a->ad_pause = adin_tcpip_send_pause; 00137 a->ad_terminate = adin_tcpip_send_terminate; 00138 a->ad_read = adin_tcpip_read; 00139 a->ad_input_name = adin_tcpip_input_name; 00140 a->silence_cut_default = FALSE; 00141 a->enable_thread = FALSE; 00142 break; 00143 case SP_STDIN: 00144 /* standard input */ 00145 a->ad_standby = adin_stdin_standby; 00146 a->ad_begin = adin_stdin_begin; 00147 a->ad_end = NULL; 00148 a->ad_resume = NULL; 00149 a->ad_pause = NULL; 00150 a->ad_terminate = NULL; 00151 a->ad_read = adin_stdin_read; 00152 a->ad_input_name = adin_stdin_input_name; 00153 a->silence_cut_default = FALSE; 00154 a->enable_thread = FALSE; 00155 break; 00156 case SP_MFCFILE: 00157 /* MFC_FILE is not waveform, so special handling on main routine should be done */ 00158 break; 00159 default: 00160 jlog("Error: m_adin: unknown input ID\n"); 00161 return FALSE; 00162 } 00163 00164 return TRUE; 00165 } 00166 00167 00184 static boolean 00185 adin_setup_all(ADIn *adin, Jconf *jconf, void *arg) 00186 { 00187 00188 if (jconf->input.use_ds48to16) { 00189 if (jconf->input.use_ds48to16 && jconf->input.sfreq != 16000) { 00190 jlog("ERROR: m_adin: in 48kHz input mode, target sampling rate should be 16k!\n"); 00191 return FALSE; 00192 } 00193 /* setup for 1/3 down sampling */ 00194 adin->ds = ds48to16_new(); 00195 adin->down_sample = TRUE; 00196 /* set device sampling rate to 48kHz */ 00197 if (adin_standby(adin, 48000, arg) == FALSE) { /* fail */ 00198 jlog("ERROR: m_adin: failed to ready input device\n"); 00199 return FALSE; 00200 } 00201 } else { 00202 adin->ds = NULL; 00203 adin->down_sample = FALSE; 00204 if (adin_standby(adin, jconf->input.sfreq, arg) == FALSE) { /* fail */ 00205 jlog("ERROR: m_adin: failed to ready input device\n"); 00206 return FALSE; 00207 } 00208 } 00209 00210 /* set parameter for recording/silence detection */ 00211 if (adin_setup_param(adin, jconf) == FALSE) { 00212 jlog("ERROR: m_adin: failed to set parameter for input device\n"); 00213 return FALSE; 00214 } 00215 00216 adin->input_side_segment = FALSE; 00217 00218 return TRUE; 00219 } 00220 00237 boolean 00238 adin_initialize(Recog *recog) 00239 { 00240 char *arg = NULL; 00241 ADIn *adin; 00242 Jconf *jconf; 00243 #ifdef ENABLE_PLUGIN 00244 FUNC_INT func; 00245 int sid; 00246 #endif 00247 00248 adin = recog->adin; 00249 jconf = recog->jconf; 00250 00251 jlog("STAT: ###### initialize input device\n"); 00252 00253 /* select input device: file, mic, netaudio, etc... */ 00254 #ifdef ENABLE_PLUGIN 00255 sid = jconf->input.plugin_source; 00256 if (sid >= 0) { 00257 /* set plugin properties and functions to adin */ 00258 func = (FUNC_INT) plugin_get_func(sid, "adin_get_configuration"); 00259 if (func == NULL) { 00260 jlog("ERROR: invalid plugin: adin_get_configuration() not exist\n"); 00261 return FALSE; 00262 } 00263 adin->silence_cut_default = (*func)(1); 00264 adin->enable_thread = (*func)(2); 00265 00266 adin->ad_standby = (boolean (*)(int, void *)) plugin_get_func(sid, "adin_standby"); 00267 adin->ad_begin = (boolean (*)(char *)) plugin_get_func(sid, "adin_open"); 00268 adin->ad_end = (boolean (*)()) plugin_get_func(sid, "adin_close"); 00269 adin->ad_resume = (boolean (*)()) plugin_get_func(sid, "adin_resume"); 00270 adin->ad_pause = (boolean (*)()) plugin_get_func(sid, "adin_pause"); 00271 adin->ad_terminate = (boolean (*)()) plugin_get_func(sid, "adin_terminate"); 00272 adin->ad_read = (int (*)(SP16 *, int)) plugin_get_func(sid, "adin_read"); 00273 adin->ad_input_name = (char * (*)()) plugin_get_func(sid, "adin_input_name"); 00274 if (adin->ad_read == NULL) { 00275 jlog("ERROR: m_adin: selected plugin has no function adin_read()\n"); 00276 return FALSE; 00277 } 00278 } else { 00279 #endif 00280 /* built-in */ 00281 if (adin_select(adin, jconf->input.speech_input, jconf->input.device) == FALSE) { 00282 jlog("ERROR: m_adin: failed to select input device\n"); 00283 return FALSE; 00284 } 00285 00286 /* set sampling frequency and device-dependent configuration 00287 (argument is device-dependent) */ 00288 switch(jconf->input.speech_input) { 00289 case SP_ADINNET: /* arg: port number */ 00290 arg = mymalloc(100); 00291 sprintf(arg, "%d", jconf->input.adinnet_port); 00292 break; 00293 case SP_RAWFILE: /* arg: filename of file list (if any) */ 00294 if (jconf->input.inputlist_filename != NULL) { 00295 arg = mymalloc(strlen(jconf->input.inputlist_filename)+1); 00296 strcpy(arg, jconf->input.inputlist_filename); 00297 } else { 00298 arg = NULL; 00299 } 00300 break; 00301 case SP_STDIN: 00302 arg = NULL; 00303 break; 00304 #ifdef USE_NETAUDIO 00305 case SP_NETAUDIO: /* netaudio server/port name */ 00306 arg = mymalloc(strlen(jconf->input.netaudio_devname)+1); 00307 strcpy(arg, jconf->input.netaudio_devname); 00308 break; 00309 #endif 00310 } 00311 #ifdef ENABLE_PLUGIN 00312 } 00313 #endif 00314 00315 if (adin_setup_all(adin, jconf, arg) == FALSE) { 00316 return FALSE; 00317 } 00318 00319 if (arg != NULL) free(arg); 00320 00321 return TRUE; 00322 } 00323 00324 /* end of file */