libsent/src/adin/adin_esd.c

Go to the documentation of this file.
00001 
00026 /*
00027  * Copyright (c) 2004-2005 Shikano Lab., Nara Institute of Science and Technology
00028  * Copyright (c) 2005-2006 Julius project team, Nagoya Institute of Technology
00029  * All rights reserved
00030  */
00031 
00032 #include <sent/stddefs.h>
00033 #include <sent/adin.h>
00034 
00035 /* sound header */
00036 #include <esd.h>
00037 
00038 static int sock;                
00039 static char name_buf[ESD_NAME_MAX]; 
00040 static int latency = 50;        
00041 
00050 boolean
00051 adin_mic_standby(int sfreq, void *dummy)
00052 {
00053   esd_format_t format = ESD_BITS16 | ESD_MONO | ESD_STREAM | ESD_RECORD;
00054 
00055   /* generate uniq ID */
00056   snprintf(name_buf, ESD_NAME_MAX, "julius%d", getpid());
00057 
00058   /* open stream */
00059   j_printf("opening socket, format = 0x%08x at %d Hz id=%s\n", format, sfreq, name_buf);
00060   sock = esd_record_stream_fallback(format, sfreq, NULL, name_buf);
00061   if (sock <= 0) {
00062     j_printerr("adin_mic_standby: failed to connect to esd\n");
00063     return FALSE;
00064   }
00065 
00066   return TRUE;
00067 }
00068  
00074 boolean
00075 adin_mic_start()
00076 {
00077   return(TRUE);
00078 }
00079 
00085 boolean
00086 adin_mic_stop()
00087 {
00088   return TRUE;
00089 }
00090 
00103 int
00104 adin_mic_read(SP16 *buf, int sampnum)
00105 {
00106   int size, cnt;
00107 
00108   size = sampnum;
00109   if (size > ESD_BUF_SIZE) size = ESD_BUF_SIZE;
00110   size *= sizeof(SP16);
00111 
00112   while((cnt = read(sock, buf, size)) <= 0) {
00113     if (cnt < 0) {
00114       perror("adin_mic_read: read error\n");
00115       return ( -2 );
00116     }
00117     usleep(latency * 1000);
00118   }
00119   cnt /= sizeof(SP16);
00120   return(cnt);
00121 }

Generated on Tue Dec 26 16:16:33 2006 for Julius by  doxygen 1.5.0