Julius 4.2
libsent/src/adin/adin_esd.c
説明を見る。
00001 
00027 /*
00028  * Copyright (c) 2004-2005 Shikano Lab., Nara Institute of Science and Technology
00029  * Copyright (c) 2005-2011 Julius project team, Nagoya Institute of Technology
00030  * All rights reserved
00031  */
00032 
00033 #include <sent/stddefs.h>
00034 #include <sent/adin.h>
00035 
00036 #ifdef HAS_ESD
00037 
00038 #include <esd.h>
00039 static int sock;                
00040 static char name_buf[ESD_NAME_MAX]; 
00041 static int latency = 50;        
00042 
00043 #endif
00044 
00053 boolean
00054 adin_esd_standby(int sfreq, void *dummy)
00055 {
00056 #ifndef HAS_ESD
00057   jlog("Error: esd not compiled in\n");
00058   return FALSE;
00059 #else
00060   esd_format_t format = ESD_BITS16 | ESD_MONO | ESD_STREAM | ESD_RECORD;
00061 
00062   /* generate uniq ID */
00063   snprintf(name_buf, ESD_NAME_MAX, "julius%d", getpid());
00064 
00065   /* open stream */
00066   jlog("adin_esd: opening socket, format = 0x%08x at %d Hz id=%s\n", format, sfreq, name_buf);
00067   sock = esd_record_stream_fallback(format, sfreq, NULL, name_buf);
00068   if (sock <= 0) {
00069     jlog("Error: adin_esd: failed to connect to esd\n");
00070     return FALSE;
00071   }
00072 
00073   return TRUE;
00074 #endif
00075 }
00076  
00085 boolean
00086 adin_esd_begin(char *pathname)
00087 {
00088   return(TRUE);
00089 }
00090 
00096 boolean
00097 adin_esd_end()
00098 {
00099   return TRUE;
00100 }
00101 
00114 int
00115 adin_esd_read(SP16 *buf, int sampnum)
00116 {
00117 #ifndef HAS_ESD
00118   return -2;
00119 #else
00120   int size, cnt;
00121 
00122   size = sampnum;
00123   if (size > ESD_BUF_SIZE) size = ESD_BUF_SIZE;
00124   size *= sizeof(SP16);
00125 
00126   while((cnt = read(sock, buf, size)) <= 0) {
00127     if (cnt < 0) {
00128       perror("adin_esd_read: read error\n");
00129       return ( -2 );
00130     }
00131     usleep(latency * 1000);
00132   }
00133   cnt /= sizeof(SP16);
00134   return(cnt);
00135 #endif
00136 }
00137 
00145 char *
00146 adin_esd_input_name()
00147 {
00148 #ifndef HAS_ESD
00149   return NULL;
00150 #else
00151   return(name_buf);
00152 #endif
00153 }