libjulius/src/m_adin.c

Go to the documentation of this file.
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)
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_read             = adin_sndfile_read;
00049     a->silence_cut_default = FALSE;
00050     a->enable_thread       = FALSE;
00051 #else  /* ~HAVE_LIBSNDFILE */
00052     /* built-in RAW/WAV reader */
00053     a->ad_standby          = adin_file_standby;
00054     a->ad_begin            = adin_file_begin;
00055     a->ad_end              = adin_file_end;
00056     a->ad_resume           = NULL;
00057     a->ad_pause            = NULL;
00058     a->ad_read             = adin_file_read;
00059     a->silence_cut_default = FALSE;
00060     a->enable_thread       = FALSE;
00061 #endif
00062     break;
00063 #ifdef USE_MIC
00064   case SP_MIC:
00065     /* microphone input */
00066     a->ad_standby          = adin_mic_standby;
00067     a->ad_begin            = adin_mic_begin;
00068     a->ad_end              = adin_mic_end;
00069     a->ad_resume           = NULL;
00070     a->ad_pause            = NULL;
00071     a->ad_read             = adin_mic_read;
00072     a->silence_cut_default = TRUE;
00073     a->enable_thread       = TRUE;
00074     break;
00075 #endif
00076 #ifdef USE_NETAUDIO
00077   case SP_NETAUDIO:
00078     /* DatLink/NetAudio input */
00079     a->ad_standby          = adin_netaudio_standby;
00080     a->ad_begin            = adin_netaudio_begin;
00081     a->ad_end              = adin_netaudio_end;
00082     a->ad_resume           = NULL;
00083     a->ad_pause            = NULL;
00084     a->ad_read             = adin_netaudio_read;
00085     a->silence_cut_default = TRUE;
00086     a->enable_thread       = TRUE;
00087     break;
00088 #endif
00089   case SP_ADINNET:
00090     /* adinnet network input */
00091     a->ad_standby          = adin_tcpip_standby;
00092     a->ad_begin            = adin_tcpip_begin;
00093     a->ad_end              = adin_tcpip_end;
00094     a->ad_resume           = NULL;
00095     a->ad_pause            = NULL;
00096     a->ad_read             = adin_tcpip_read;
00097     a->silence_cut_default = FALSE;
00098     a->enable_thread       = FALSE;
00099     break;
00100   case SP_STDIN:
00101     /* standard input */
00102     a->ad_standby          = adin_stdin_standby;
00103     a->ad_begin            = adin_stdin_begin;
00104     a->ad_end              = NULL;
00105     a->ad_resume           = NULL;
00106     a->ad_pause            = NULL;
00107     a->ad_read             = adin_stdin_read;
00108     a->silence_cut_default = FALSE;
00109     a->enable_thread       = FALSE;
00110     break;
00111   case SP_MFCFILE:
00112     /* MFC_FILE is not waveform, so special handling on main routine should be done */
00113     break;
00114   default:
00115     return FALSE;
00116   }
00117 
00118   return TRUE;
00119 }
00120 
00121 
00138 static boolean
00139 adin_setup_all(ADIn *adin, Jconf *jconf, void *arg)
00140 {
00141 
00142   if (jconf->input.use_ds48to16) {
00143     if (jconf->input.use_ds48to16 && jconf->input.sfreq != 16000) {
00144       jlog("ERROR: m_adin: in 48kHz input mode, target sampling rate should be 16k!\n");
00145       return FALSE;
00146     }
00147     /* setup for 1/3 down sampling */
00148     adin->ds = ds48to16_new();
00149     adin->down_sample = TRUE;
00150     /* set device sampling rate to 48kHz */
00151     if (adin_standby(adin, 48000, arg) == FALSE) { /* fail */
00152       jlog("ERROR: m_adin: failed to ready input device\n");
00153       return FALSE;
00154     }
00155   } else {
00156     adin->down_sample = FALSE;
00157     if (adin_standby(adin, jconf->input.sfreq, arg) == FALSE) { /* fail */
00158       jlog("ERROR: m_adin: failed to ready input device\n");
00159       return FALSE;
00160     }
00161   }
00162 
00163   /* set parameter for recording/silence detection */
00164   adin_setup_param(adin, jconf);
00165 
00166   return TRUE;
00167 }
00168 
00185 boolean
00186 adin_initialize(Recog *recog)
00187 {
00188   char *arg = NULL;
00189   ADIn *adin;
00190   Jconf *jconf;
00191 
00192   adin = recog->adin;
00193   jconf = recog->jconf;
00194 
00195   if (jconf->input.speech_input == SP_MFCFILE) {
00196     return TRUE; /* no need to initialize */
00197   }
00198   
00199   jlog("STAT: ###### initialize input device\n");
00200 
00201   /* select input device: file, mic, netaudio, etc... */
00202   if (adin_select(adin, jconf->input.speech_input) == FALSE) {
00203     jlog("ERROR: m_adin: failed to select input device\n");
00204     return FALSE;
00205   }
00206 
00207   /* set sampling frequency and device-dependent configuration
00208      (argument is device-dependent) */
00209   switch(jconf->input.speech_input) {
00210   case SP_ADINNET:              /* arg: port number */
00211     arg = mymalloc(100);
00212     sprintf(arg, "%d", jconf->input.adinnet_port);
00213     break;
00214   case SP_RAWFILE:              /* arg: filename of file list (if any) */
00215     if (jconf->input.inputlist_filename != NULL) {
00216       arg = mymalloc(strlen(jconf->input.inputlist_filename)+1);
00217       strcpy(arg, jconf->input.inputlist_filename);
00218     } else {
00219       arg = NULL;
00220     }
00221     break;
00222   case SP_STDIN:
00223     arg = NULL;
00224     break;
00225 #ifdef USE_NETAUDIO
00226   case SP_NETAUDIO:             /* netaudio server/port name */
00227     arg = mymalloc(strlen(jconf->input.netaudio_devname)+1);
00228     strcpy(arg, jconf->input.netaudio_devname);
00229     break;
00230 #endif
00231   }
00232 
00233   if (adin_setup_all(adin, jconf, arg) == FALSE) {
00234     return FALSE;
00235   }
00236 
00237   if (arg != NULL) free(arg);
00238 
00239   return TRUE;
00240 }
00241 
00265 boolean
00266 adin_initialize_user(Recog *recog, void *arg)
00267 {
00268   boolean ret;
00269   ADIn *adin;
00270   Jconf *jconf;
00271 
00272   adin = recog->adin;
00273   jconf = recog->jconf;
00274 
00275   jlog("STAT: ###### initialize input device (user defined)\n");
00276   /* skip adin_select() */
00277   ret = adin_setup_all(adin, jconf, arg);
00278   /* create A/D-in thread here */
00279 
00280   return ret;
00281 }
00282 /* end of file */

Generated on Tue Dec 18 15:59:52 2007 for Julius by  doxygen 1.5.4