00001
00027
00028
00029
00030
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
00063 snprintf(name_buf, ESD_NAME_MAX, "julius%d", getpid());
00064
00065
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
00082 boolean
00083 adin_esd_begin()
00084 {
00085 return(TRUE);
00086 }
00087
00093 boolean
00094 adin_esd_end()
00095 {
00096 return TRUE;
00097 }
00098
00111 int
00112 adin_esd_read(SP16 *buf, int sampnum)
00113 {
00114 #ifndef HAS_ESD
00115 return -2;
00116 #else
00117 int size, cnt;
00118
00119 size = sampnum;
00120 if (size > ESD_BUF_SIZE) size = ESD_BUF_SIZE;
00121 size *= sizeof(SP16);
00122
00123 while((cnt = read(sock, buf, size)) <= 0) {
00124 if (cnt < 0) {
00125 perror("adin_esd_read: read error\n");
00126 return ( -2 );
00127 }
00128 usleep(latency * 1000);
00129 }
00130 cnt /= sizeof(SP16);
00131 return(cnt);
00132 #endif
00133 }