Julius 4.2
|
00001 00027 /* 00028 * Copyright (c) 2010-2011 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 #ifdef HAS_PULSEAUDIO 00036 #include <pulse/simple.h> 00037 #include <pulse/error.h> 00038 00039 #define BUFSIZE 512 00040 static pa_simple *s = NULL; 00041 static int srate; 00042 static char name_buf[] = "PulseAudio default device"; 00043 #endif 00044 00053 boolean 00054 adin_pulseaudio_standby(int sfreq, void *dummy) 00055 { 00056 #ifndef HAS_PULSEAUDIO 00057 jlog("Error: PulseAudio not compiled in\n"); 00058 return FALSE; 00059 #else 00060 srate = sfreq; 00061 return TRUE; 00062 #endif 00063 } 00064 00073 boolean 00074 adin_pulseaudio_begin(char *arg) 00075 { 00076 #ifndef HAS_PULSEAUDIO 00077 jlog("Error: PulseAudio not compiled in\n"); 00078 return FALSE; 00079 #else 00080 pa_sample_spec ss; 00081 int error; 00082 00083 ss.format = PA_SAMPLE_S16LE; 00084 ss.rate = srate; 00085 ss.channels = 1; 00086 00087 if (!(s = pa_simple_new(NULL, "Julius", PA_STREAM_RECORD, NULL, "record", &ss, NULL, NULL, &error))) { 00088 jlog("Error: adin_pulseaudio: pa_simple_new() failed: %s\n", pa_strerror(error)); 00089 return FALSE; 00090 } 00091 return TRUE; 00092 #endif 00093 } 00094 00100 boolean 00101 adin_pulseaudio_end() 00102 { 00103 #ifndef HAS_PULSEAUDIO 00104 jlog("Error: PulseAudio not compiled in\n"); 00105 return FALSE; 00106 #else 00107 if (s != NULL) { 00108 pa_simple_free(s); 00109 s = NULL; 00110 } 00111 return TRUE; 00112 #endif 00113 } 00114 00127 int 00128 adin_pulseaudio_read(SP16 *buf, int sampnum) 00129 { 00130 #ifndef HAS_PULSEAUDIO 00131 return -2; 00132 #else 00133 00134 int error; 00135 int cnt, bufsize; 00136 00137 bufsize = sampnum * sizeof(SP16); 00138 if (bufsize > BUFSIZE) bufsize = BUFSIZE; 00139 00140 if (pa_simple_read(s, buf, bufsize, &error) < 0) { 00141 jlog("Error: adin_pulseaudio: pa_simple_read() failed: %s\n", pa_strerror(error)); 00142 return (-2); 00143 } 00144 00145 cnt = bufsize / sizeof(SP16); 00146 00147 return(cnt); 00148 00149 #endif 00150 } 00151 00159 char * 00160 adin_pulseaudio_input_name() 00161 { 00162 #ifndef HAS_PULSEAUDIO 00163 return NULL; 00164 #else 00165 return(name_buf); 00166 #endif 00167 }