Julius 4.2
|
00001 00018 /* 00019 * Copyright (c) 1991-2011 Kawahara Lab., Kyoto University 00020 * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology 00021 * Copyright (c) 2005-2011 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 #ifdef HAS_PULSEAUDIO 00111 case SP_INPUT_PULSEAUDIO: 00112 a->ad_standby = adin_pulseaudio_standby; 00113 a->ad_begin = adin_pulseaudio_begin; 00114 a->ad_end = adin_pulseaudio_end; 00115 a->ad_read = adin_pulseaudio_read; 00116 a->ad_input_name = adin_pulseaudio_input_name; 00117 break; 00118 #endif 00119 default: 00120 jlog("ERROR: m_adin: invalid input device specified\n"); 00121 } 00122 break; 00123 #endif 00124 #ifdef USE_NETAUDIO 00125 case SP_NETAUDIO: 00126 /* DatLink/NetAudio input */ 00127 a->ad_standby = adin_netaudio_standby; 00128 a->ad_begin = adin_netaudio_begin; 00129 a->ad_end = adin_netaudio_end; 00130 a->ad_resume = NULL; 00131 a->ad_pause = NULL; 00132 a->ad_terminate = NULL; 00133 a->ad_read = adin_netaudio_read; 00134 a->ad_input_name = adin_netaudio_input_name; 00135 a->silence_cut_default = TRUE; 00136 a->enable_thread = TRUE; 00137 break; 00138 #endif 00139 case SP_ADINNET: 00140 /* adinnet network input */ 00141 a->ad_standby = adin_tcpip_standby; 00142 a->ad_begin = adin_tcpip_begin; 00143 a->ad_end = adin_tcpip_end; 00144 a->ad_resume = adin_tcpip_send_resume; 00145 a->ad_pause = adin_tcpip_send_pause; 00146 a->ad_terminate = adin_tcpip_send_terminate; 00147 a->ad_read = adin_tcpip_read; 00148 a->ad_input_name = adin_tcpip_input_name; 00149 a->silence_cut_default = FALSE; 00150 a->enable_thread = FALSE; 00151 break; 00152 case SP_STDIN: 00153 /* standard input */ 00154 a->ad_standby = adin_stdin_standby; 00155 a->ad_begin = adin_stdin_begin; 00156 a->ad_end = NULL; 00157 a->ad_resume = NULL; 00158 a->ad_pause = NULL; 00159 a->ad_terminate = NULL; 00160 a->ad_read = adin_stdin_read; 00161 a->ad_input_name = adin_stdin_input_name; 00162 a->silence_cut_default = FALSE; 00163 a->enable_thread = FALSE; 00164 break; 00165 case SP_MFCFILE: 00166 /* MFC_FILE is not waveform, so special handling on main routine should be done */ 00167 break; 00168 default: 00169 jlog("Error: m_adin: unknown input ID\n"); 00170 return FALSE; 00171 } 00172 00173 return TRUE; 00174 } 00175 00176 00193 static boolean 00194 adin_setup_all(ADIn *adin, Jconf *jconf, void *arg) 00195 { 00196 00197 if (jconf->input.use_ds48to16) { 00198 if (jconf->input.use_ds48to16 && jconf->input.sfreq != 16000) { 00199 jlog("ERROR: m_adin: in 48kHz input mode, target sampling rate should be 16k!\n"); 00200 return FALSE; 00201 } 00202 /* setup for 1/3 down sampling */ 00203 adin->ds = ds48to16_new(); 00204 adin->down_sample = TRUE; 00205 /* set device sampling rate to 48kHz */ 00206 if (adin_standby(adin, 48000, arg) == FALSE) { /* fail */ 00207 jlog("ERROR: m_adin: failed to ready input device\n"); 00208 return FALSE; 00209 } 00210 } else { 00211 adin->ds = NULL; 00212 adin->down_sample = FALSE; 00213 if (adin_standby(adin, jconf->input.sfreq, arg) == FALSE) { /* fail */ 00214 jlog("ERROR: m_adin: failed to ready input device\n"); 00215 return FALSE; 00216 } 00217 } 00218 00219 /* set parameter for recording/silence detection */ 00220 if (adin_setup_param(adin, jconf) == FALSE) { 00221 jlog("ERROR: m_adin: failed to set parameter for input device\n"); 00222 return FALSE; 00223 } 00224 00225 adin->input_side_segment = FALSE; 00226 00227 return TRUE; 00228 } 00229 00246 boolean 00247 adin_initialize(Recog *recog) 00248 { 00249 char *arg = NULL; 00250 ADIn *adin; 00251 Jconf *jconf; 00252 #ifdef ENABLE_PLUGIN 00253 FUNC_INT func; 00254 int sid; 00255 #endif 00256 00257 adin = recog->adin; 00258 jconf = recog->jconf; 00259 00260 jlog("STAT: ###### initialize input device\n"); 00261 00262 /* select input device: file, mic, netaudio, etc... */ 00263 #ifdef ENABLE_PLUGIN 00264 sid = jconf->input.plugin_source; 00265 if (sid >= 0) { 00266 /* set plugin properties and functions to adin */ 00267 func = (FUNC_INT) plugin_get_func(sid, "adin_get_configuration"); 00268 if (func == NULL) { 00269 jlog("ERROR: invalid plugin: adin_get_configuration() not exist\n"); 00270 return FALSE; 00271 } 00272 adin->silence_cut_default = (*func)(1); 00273 adin->enable_thread = (*func)(2); 00274 00275 adin->ad_standby = (boolean (*)(int, void *)) plugin_get_func(sid, "adin_standby"); 00276 adin->ad_begin = (boolean (*)(char *)) plugin_get_func(sid, "adin_open"); 00277 adin->ad_end = (boolean (*)()) plugin_get_func(sid, "adin_close"); 00278 adin->ad_resume = (boolean (*)()) plugin_get_func(sid, "adin_resume"); 00279 adin->ad_pause = (boolean (*)()) plugin_get_func(sid, "adin_pause"); 00280 adin->ad_terminate = (boolean (*)()) plugin_get_func(sid, "adin_terminate"); 00281 adin->ad_read = (int (*)(SP16 *, int)) plugin_get_func(sid, "adin_read"); 00282 adin->ad_input_name = (char * (*)()) plugin_get_func(sid, "adin_input_name"); 00283 if (adin->ad_read == NULL) { 00284 jlog("ERROR: m_adin: selected plugin has no function adin_read()\n"); 00285 return FALSE; 00286 } 00287 } else { 00288 #endif 00289 /* built-in */ 00290 if (adin_select(adin, jconf->input.speech_input, jconf->input.device) == FALSE) { 00291 jlog("ERROR: m_adin: failed to select input device\n"); 00292 return FALSE; 00293 } 00294 00295 /* set sampling frequency and device-dependent configuration 00296 (argument is device-dependent) */ 00297 switch(jconf->input.speech_input) { 00298 case SP_ADINNET: /* arg: port number */ 00299 arg = mymalloc(100); 00300 sprintf(arg, "%d", jconf->input.adinnet_port); 00301 break; 00302 case SP_RAWFILE: /* arg: filename of file list (if any) */ 00303 if (jconf->input.inputlist_filename != NULL) { 00304 arg = mymalloc(strlen(jconf->input.inputlist_filename)+1); 00305 strcpy(arg, jconf->input.inputlist_filename); 00306 } else { 00307 arg = NULL; 00308 } 00309 break; 00310 case SP_STDIN: 00311 arg = NULL; 00312 break; 00313 #ifdef USE_NETAUDIO 00314 case SP_NETAUDIO: /* netaudio server/port name */ 00315 arg = mymalloc(strlen(jconf->input.netaudio_devname)+1); 00316 strcpy(arg, jconf->input.netaudio_devname); 00317 break; 00318 #endif 00319 } 00320 #ifdef ENABLE_PLUGIN 00321 } 00322 #endif 00323 00324 if (adin_setup_all(adin, jconf, arg) == FALSE) { 00325 return FALSE; 00326 } 00327 00328 if (arg != NULL) free(arg); 00329 00330 return TRUE; 00331 } 00332 00333 /* end of file */