libsent/src/adin/adin_esd.c

Go to the documentation of this file.
00001 
00027 /*
00028  * Copyright (c) 2004-2005 Shikano Lab., Nara Institute of Science and Technology
00029  * Copyright (c) 2005-2007 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 /* sound header */
00037 #include <esd.h>
00038 
00039 static int sock;                
00040 static char name_buf[ESD_NAME_MAX]; 
00041 static int latency = 50;        
00042 
00051 boolean
00052 adin_mic_standby(int sfreq, void *dummy)
00053 {
00054   esd_format_t format = ESD_BITS16 | ESD_MONO | ESD_STREAM | ESD_RECORD;
00055 
00056   /* generate uniq ID */
00057   snprintf(name_buf, ESD_NAME_MAX, "julius%d", getpid());
00058 
00059   /* open stream */
00060   jlog("adin_esd: opening socket, format = 0x%08x at %d Hz id=%s\n", format, sfreq, name_buf);
00061   sock = esd_record_stream_fallback(format, sfreq, NULL, name_buf);
00062   if (sock <= 0) {
00063     jlog("Error: adin_esd: failed to connect to esd\n");
00064     return FALSE;
00065   }
00066 
00067   return TRUE;
00068 }
00069  
00075 boolean
00076 adin_mic_begin()
00077 {
00078   return(TRUE);
00079 }
00080 
00086 boolean
00087 adin_mic_end()
00088 {
00089   return TRUE;
00090 }
00091 
00104 int
00105 adin_mic_read(SP16 *buf, int sampnum)
00106 {
00107   int size, cnt;
00108 
00109   size = sampnum;
00110   if (size > ESD_BUF_SIZE) size = ESD_BUF_SIZE;
00111   size *= sizeof(SP16);
00112 
00113   while((cnt = read(sock, buf, size)) <= 0) {
00114     if (cnt < 0) {
00115       perror("adin_mic_read: read error\n");
00116       return ( -2 );
00117     }
00118     usleep(latency * 1000);
00119   }
00120   cnt /= sizeof(SP16);
00121   return(cnt);
00122 }

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