libjulius/src/m_adin.c

説明を見る。
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->silence_cut_default = FALSE;
00051     a->enable_thread       = FALSE;
00052 #else  /* ~HAVE_LIBSNDFILE */
00053     /* built-in RAW/WAV reader */
00054     a->ad_standby          = adin_file_standby;
00055     a->ad_begin            = adin_file_begin;
00056     a->ad_end              = adin_file_end;
00057     a->ad_resume           = NULL;
00058     a->ad_pause            = NULL;
00059     a->ad_terminate        = NULL;
00060     a->ad_read             = adin_file_read;
00061     a->silence_cut_default = FALSE;
00062     a->enable_thread       = FALSE;
00063 #endif
00064     break;
00065 #ifdef USE_MIC
00066   case SP_MIC:
00067     /* microphone input */
00068     a->ad_resume           = NULL;
00069     a->ad_pause            = NULL;
00070     a->ad_terminate        = NULL;
00071     a->silence_cut_default = TRUE;
00072     a->enable_thread       = TRUE;
00073     switch(dev) {
00074     case SP_INPUT_DEFAULT:
00075       a->ad_standby          = adin_mic_standby;
00076       a->ad_begin            = adin_mic_begin;
00077       a->ad_end              = adin_mic_end;
00078       a->ad_read             = adin_mic_read;
00079       break;
00080 #ifdef HAS_ALSA
00081     case SP_INPUT_ALSA:
00082       a->ad_standby          = adin_alsa_standby;
00083       a->ad_begin            = adin_alsa_begin;
00084       a->ad_end              = adin_alsa_end;
00085       a->ad_read             = adin_alsa_read;
00086       break;
00087 #endif
00088 #ifdef HAS_OSS
00089     case SP_INPUT_OSS:
00090       a->ad_standby          = adin_oss_standby;
00091       a->ad_begin            = adin_oss_begin;
00092       a->ad_end              = adin_oss_end;
00093       a->ad_read             = adin_oss_read;
00094       break;
00095 #endif
00096 #ifdef HAS_ESD
00097     case SP_INPUT_ESD:
00098       a->ad_standby          = adin_esd_standby;
00099       a->ad_begin            = adin_esd_begin;
00100       a->ad_end              = adin_esd_end;
00101       a->ad_read             = adin_esd_read;
00102       break;
00103 #endif
00104     default:
00105       jlog("ERROR: m_adin: invalid input device specified\n");
00106     }
00107     break;
00108 #endif
00109 #ifdef USE_NETAUDIO
00110   case SP_NETAUDIO:
00111     /* DatLink/NetAudio input */
00112     a->ad_standby          = adin_netaudio_standby;
00113     a->ad_begin            = adin_netaudio_begin;
00114     a->ad_end              = adin_netaudio_end;
00115     a->ad_resume           = NULL;
00116     a->ad_pause            = NULL;
00117     a->ad_terminate        = NULL;
00118     a->ad_read             = adin_netaudio_read;
00119     a->silence_cut_default = TRUE;
00120     a->enable_thread       = TRUE;
00121     break;
00122 #endif
00123   case SP_ADINNET:
00124     /* adinnet network input */
00125     a->ad_standby          = adin_tcpip_standby;
00126     a->ad_begin            = adin_tcpip_begin;
00127     a->ad_end              = adin_tcpip_end;
00128     a->ad_resume           = adin_tcpip_send_resume;
00129     a->ad_pause            = adin_tcpip_send_pause;
00130     a->ad_terminate        = adin_tcpip_send_terminate;
00131     a->ad_read             = adin_tcpip_read;
00132     a->silence_cut_default = FALSE;
00133     a->enable_thread       = FALSE;
00134     break;
00135   case SP_STDIN:
00136     /* standard input */
00137     a->ad_standby          = adin_stdin_standby;
00138     a->ad_begin            = adin_stdin_begin;
00139     a->ad_end              = NULL;
00140     a->ad_resume           = NULL;
00141     a->ad_pause            = NULL;
00142     a->ad_terminate        = NULL;
00143     a->ad_read             = adin_stdin_read;
00144     a->silence_cut_default = FALSE;
00145     a->enable_thread       = FALSE;
00146     break;
00147   case SP_MFCFILE:
00148     /* MFC_FILE is not waveform, so special handling on main routine should be done */
00149     break;
00150   default:
00151     return FALSE;
00152   }
00153 
00154   return TRUE;
00155 }
00156 
00157 
00174 static boolean
00175 adin_setup_all(ADIn *adin, Jconf *jconf, void *arg)
00176 {
00177 
00178   if (jconf->input.use_ds48to16) {
00179     if (jconf->input.use_ds48to16 && jconf->input.sfreq != 16000) {
00180       jlog("ERROR: m_adin: in 48kHz input mode, target sampling rate should be 16k!\n");
00181       return FALSE;
00182     }
00183     /* setup for 1/3 down sampling */
00184     adin->ds = ds48to16_new();
00185     adin->down_sample = TRUE;
00186     /* set device sampling rate to 48kHz */
00187     if (adin_standby(adin, 48000, arg) == FALSE) { /* fail */
00188       jlog("ERROR: m_adin: failed to ready input device\n");
00189       return FALSE;
00190     }
00191   } else {
00192     adin->ds = NULL;
00193     adin->down_sample = FALSE;
00194     if (adin_standby(adin, jconf->input.sfreq, arg) == FALSE) { /* fail */
00195       jlog("ERROR: m_adin: failed to ready input device\n");
00196       return FALSE;
00197     }
00198   }
00199 
00200   /* set parameter for recording/silence detection */
00201   if (adin_setup_param(adin, jconf) == FALSE) {
00202     jlog("ERROR: m_adin: failed to set parameter for input device\n");
00203     return FALSE;
00204   }
00205 
00206   adin->input_side_segment = FALSE;
00207 
00208   return TRUE;
00209 }
00210 
00227 boolean
00228 adin_initialize(Recog *recog)
00229 {
00230   char *arg = NULL;
00231   ADIn *adin;
00232   Jconf *jconf;
00233 #ifdef ENABLE_PLUGIN
00234   FUNC_INT func;
00235   int sid;
00236 #endif
00237 
00238   adin = recog->adin;
00239   jconf = recog->jconf;
00240 
00241   jlog("STAT: ###### initialize input device\n");
00242 
00243   /* select input device: file, mic, netaudio, etc... */
00244 #ifdef ENABLE_PLUGIN
00245   sid = jconf->input.plugin_source;
00246   if (sid >= 0) {
00247     /* set plugin properties and functions to adin */
00248     func = (FUNC_INT) plugin_get_func(sid, "adin_get_configuration");
00249     if (func == NULL) {
00250       jlog("ERROR: invalid plugin: adin_get_configuration() not exist\n");
00251       return FALSE;
00252     }
00253     adin->silence_cut_default = (*func)(1);
00254     adin->enable_thread = (*func)(2);
00255 
00256     adin->ad_standby       = (boolean (*)(int, void *)) plugin_get_func(sid, "adin_standby");
00257     adin->ad_begin         = (boolean (*)()) plugin_get_func(sid, "adin_open");
00258     adin->ad_end           = (boolean (*)()) plugin_get_func(sid, "adin_close");
00259     adin->ad_resume        = (boolean (*)()) plugin_get_func(sid, "adin_resume");
00260     adin->ad_pause         = (boolean (*)()) plugin_get_func(sid, "adin_pause");
00261     adin->ad_terminate     = (boolean (*)()) plugin_get_func(sid, "adin_terminate");
00262     adin->ad_read          = (int (*)(SP16 *, int)) plugin_get_func(sid, "adin_read");
00263     if (adin->ad_read == NULL) {
00264       jlog("ERROR: m_adin: selected plugin has no function adin_read()\n");
00265       return FALSE;
00266     }
00267   } else {
00268 #endif
00269     /* built-in */
00270     if (adin_select(adin, jconf->input.speech_input, jconf->input.device) == FALSE) {
00271       jlog("ERROR: m_adin: failed to select input device\n");
00272       return FALSE;
00273     }
00274 
00275     /* set sampling frequency and device-dependent configuration
00276        (argument is device-dependent) */
00277     switch(jconf->input.speech_input) {
00278     case SP_ADINNET:            /* arg: port number */
00279       arg = mymalloc(100);
00280       sprintf(arg, "%d", jconf->input.adinnet_port);
00281       break;
00282     case SP_RAWFILE:            /* arg: filename of file list (if any) */
00283       if (jconf->input.inputlist_filename != NULL) {
00284         arg = mymalloc(strlen(jconf->input.inputlist_filename)+1);
00285         strcpy(arg, jconf->input.inputlist_filename);
00286       } else {
00287         arg = NULL;
00288       }
00289       break;
00290     case SP_STDIN:
00291       arg = NULL;
00292       break;
00293 #ifdef USE_NETAUDIO
00294     case SP_NETAUDIO:           /* netaudio server/port name */
00295       arg = mymalloc(strlen(jconf->input.netaudio_devname)+1);
00296       strcpy(arg, jconf->input.netaudio_devname);
00297       break;
00298 #endif
00299     }
00300 #ifdef ENABLE_PLUGIN
00301   }
00302 #endif
00303 
00304   if (adin_setup_all(adin, jconf, arg) == FALSE) {
00305     return FALSE;
00306   }
00307 
00308   if (arg != NULL) free(arg);
00309 
00310   return TRUE;
00311 }
00312 
00313 /* end of file */

Juliusに対してThu Jul 23 12:16:22 2009に生成されました。  doxygen 1.5.1