[Julius-cvs 423] CVS update: julius4/libsent/src/adin

アーカイブの一覧に戻る

sumom****@users***** sumom****@users*****
2009年 7月 3日 (金) 02:05:20 JST


Index: julius4/libsent/src/adin/adin_esd.c
diff -u julius4/libsent/src/adin/adin_esd.c:1.4 julius4/libsent/src/adin/adin_esd.c:1.5
--- julius4/libsent/src/adin/adin_esd.c:1.4	Wed Mar 18 16:05:30 2009
+++ julius4/libsent/src/adin/adin_esd.c	Fri Jul  3 02:05:20 2009
@@ -21,7 +21,7 @@
  * @author Akinobu LEE
  * @date   Sun Feb 13 16:18:26 2005
  *
- * $Revision: 1.4 $
+ * $Revision: 1.5 $
  * 
  */
 /*
@@ -76,11 +76,14 @@
  
 /** 
  * Start recording.
+ * @a pathname is dummy.
+ *
+ * @param pathname [in] path name to open or NULL for default
  * 
  * @return TRUE on success, FALSE on failure.
  */
 boolean
-adin_esd_begin()
+adin_esd_begin(char *pathname)
 {
   return(TRUE);
 }
Index: julius4/libsent/src/adin/adin_file.c
diff -u julius4/libsent/src/adin/adin_file.c:1.6 julius4/libsent/src/adin/adin_file.c:1.7
--- julius4/libsent/src/adin/adin_file.c:1.6	Wed Mar 18 16:05:30 2009
+++ julius4/libsent/src/adin/adin_file.c	Fri Jul  3 02:05:20 2009
@@ -56,7 +56,7 @@
  * @author Akinobu LEE
  * @date   Sun Feb 13 13:31:20 2005
  *
- * $Revision: 1.6 $
+ * $Revision: 1.7 $
  * 
  */
 /*
@@ -350,13 +350,26 @@
  * will be read from the listfile.  Otherwise, the
  * filename will be obtained from stdin.  Then the file will be opened here.
  * 
+ * @param filename [in] file name to open or NULL for prompt
+ * 
  * @return TRUE on success, FALSE on failure.
  */
 boolean
-adin_file_begin()
+adin_file_begin(char *filename)
 {
   boolean readp;
 
+  if (filename != NULL) {
+    /* open the file and exit with its status */
+    if (adin_file_open(filename) == FALSE) {
+      jlog("Error: adin_file: failed to read speech data: \"%s\"\n", filename);
+      return FALSE;
+    }
+    jlog("Stat: adin_file: input speechfile: %s\n", filename);
+    strcpy(speechfilename, filename);
+    return TRUE;
+  }
+
   /* ready to read next input */
   readp = FALSE;
   while(readp == FALSE) {
@@ -483,10 +496,12 @@
 /** 
  * @brief  Begin reading audio data from stdin
  *
+ * @param pathname [in] dummy
+ *
  * @return TRUE on success, FALSE on failure.
  */
 boolean
-adin_stdin_begin()
+adin_stdin_begin(char *pathname)
 {
   if (feof(stdin)) {		/* already reached the end of input stream */
     jlog("Error: adin_stdin: stdin reached EOF\n");
Index: julius4/libsent/src/adin/adin_mic_darwin_coreaudio.c
diff -u julius4/libsent/src/adin/adin_mic_darwin_coreaudio.c:1.3 julius4/libsent/src/adin/adin_mic_darwin_coreaudio.c:1.4
--- julius4/libsent/src/adin/adin_mic_darwin_coreaudio.c:1.3	Wed Mar 18 16:05:30 2009
+++ julius4/libsent/src/adin/adin_mic_darwin_coreaudio.c	Fri Jul  3 02:05:20 2009
@@ -29,7 +29,7 @@
  * @author Masatomo Hashimoto
  * @date   Wed Oct 12 11:31:27 2005
  *
- * $Revision: 1.3 $
+ * $Revision: 1.4 $
  * 
  */
 
@@ -44,7 +44,7 @@
  *
  */
 
-/* $Id: adin_mic_darwin_coreaudio.c,v 1.3 2009/03/18 07:05:30 sumomo Exp $ */
+/* $Id: adin_mic_darwin_coreaudio.c,v 1.4 2009/07/02 17:05:20 sumomo Exp $ */
 
 #include <CoreAudio/CoreAudio.h>
 #include <AudioUnit/AudioUnit.h>
@@ -569,7 +569,7 @@
   return TRUE;
 }
 
-boolean adin_mic_begin(){ return TRUE; }
+boolean adin_mic_begin(char *pathname){ return TRUE; }
 boolean adin_mic_end(){ return TRUE; }
 
 int adin_mic_read(void *buffer, int nsamples) {
Index: julius4/libsent/src/adin/adin_mic_freebsd.c
diff -u julius4/libsent/src/adin/adin_mic_freebsd.c:1.5 julius4/libsent/src/adin/adin_mic_freebsd.c:1.6
--- julius4/libsent/src/adin/adin_mic_freebsd.c:1.5	Wed Mar 18 16:05:30 2009
+++ julius4/libsent/src/adin/adin_mic_freebsd.c	Fri Jul  3 02:05:20 2009
@@ -39,7 +39,7 @@
  * @author Akinobu LEE
  * @date   Sun Feb 13 16:18:26 2005
  *
- * $Revision: 1.5 $
+ * $Revision: 1.6 $
  * 
  */
 /*
@@ -71,6 +71,7 @@
 /// Default device name, can be overridden by AUDIODEV environment variable
 #define DEFAULT_DEVICE "/dev/dsp"
 
+static int srate;		///< Required sampling rate
 static int audio_fd;		///< Audio descriptor
 static boolean need_swap;	///< Whether input samples need byte-swapping
 struct pollfd fds[1];		///< Workarea for polling device
@@ -82,7 +83,7 @@
 static char devname[MAXPATHLEN];		///< Current device name
 
 /** 
- * Device initialization: check device capability and open for recording.
+ * Device initialization: check machine capability
  * 
  * @param sfreq [in] required sampling frequency.
  * @param arg [in] a dummy data
@@ -92,24 +93,29 @@
 boolean
 adin_mic_standby(int sfreq, void *arg)
 {
+  /* store required sampling rate for checking after opening device */
+  srate = sfreq;
+  return TRUE;
+}
+
+/** 
+ * Open the specified device and check capability of the opening device.
+ * 
+ * @param devstr [in] device string to open
+ * 
+ * @return TRUE on success, FALSE on failure.
+ */
+static boolean
+adin_mic_open(char *devstr)
+{
   int fmt, fmt_can, fmt1, fmt2, rfmt; /* sampling format */
   int samplerate;		/* actual sampling rate */
   int stereo;		/* mono */
   char *p;
 
-  /* set device name */
-  if ((p = getenv("AUDIODEV")) == NULL) {
-    strncpy(devname, defaultdev, MAXPATHLEN);
-    jlog("Stat: adin_freebsd: device name = %s\n", devname);
-  } else {
-    jlog("Stat: adin_freebsd: device name obtained from AUDIODEV: %s\n", p);
-  } else {
-    strncpy(devname, p, MAXPATHLEN);
-  }
-
   /* open device */
-  if ((audio_fd = open(devname, O_RDONLY)) == -1) {
-    jlog("Error: adin_freebsd: failed to open %s\n", devname);
+  if ((audio_fd = open(devstr, O_RDONLY)) == -1) {
+    jlog("Error: adin_freebsd: failed to open %s\n", devstr);
     return(FALSE);
   }
 
@@ -149,8 +155,8 @@
 
   /* re-open for recording */
   /* open device */
-  if ((audio_fd = open(devname, O_RDONLY)) == -1) {
-    jlog("Error: adin_freebsd: failed to open %s", devname);
+  if ((audio_fd = open(devstr, O_RDONLY)) == -1) {
+    jlog("Error: adin_freebsd: failed to open %s", devstr);
     return(FALSE);
   }
   /* set format, samplerate, channels */
@@ -174,17 +180,17 @@
     return FALSE;
   }
 
-  samplerate = sfreq;
+  samplerate = srate;
   if (ioctl(audio_fd, SNDCTL_DSP_SPEED, &samplerate) == -1) {
-    jlog("Erorr: adin_freebsd: failed to set sample rate to %dHz\n", sfreq);
+    jlog("Erorr: adin_freebsd: failed to set sample rate to %dHz\n", srate);
     return(FALSE);
   }
-  if (samplerate < sfreq - FREQALLOWRANGE || samplerate > sfreq + FREQALLOWRANGE) {
-    jlog("Error: adin_freebsd: failed to set sampling rate to near %dHz. (%d)\n", sfreq, samplerate);
+  if (samplerate < srate - FREQALLOWRANGE || samplerate > srate + FREQALLOWRANGE) {
+    jlog("Error: adin_freebsd: failed to set sampling rate to near %dHz. (%d)\n", srate, samplerate);
     return FALSE;
   }
-  if (samplerate != sfreq) {
-    jlog("Warning: adin_freebsd: specified sampling rate was %dHz but set to %dHz, \n", sfreq, samplerate);
+  if (samplerate != srate) {
+    jlog("Warning: adin_freebsd: specified sampling rate was %dHz but set to %dHz, \n", srate, samplerate);
   }
 
   /* set polling status */
@@ -193,16 +199,32 @@
   
   return TRUE;
 }
- 
+
+
 /** 
  * Start recording.
+ *
+ * @param pathname [in] path name to open or NULL for default
  * 
  * @return TRUE on success, FALSE on failure.
  */
 boolean
-adin_mic_begin()
+adin_mic_begin(char *pathname)
 {
-  return(TRUE);
+  /* set device name */
+  if (pathname != NULL) {
+    strncpy(devname, pathname, MAXPATHLEN);
+    jlog("Stat: adin_freebsd: device name = %s (from argument)\n", devname);
+  } else if ((p = getenv("AUDIODEV")) != NULL) {
+    strncpy(devname, p, MAXPATHLEN);
+    jlog("Stat: adin_freebsd: device name = %s (from AUDIODEV)\n", devname);
+  } else {
+    strncpy(devname, defaultdev, MAXPATHLEN);
+    jlog("Stat: adin_freebsd: device name = %s (application default)\n", devname);
+  }
+
+  /* open the device */
+  return(adin_mic_open(devname));
 }
 
 /** 
@@ -213,12 +235,7 @@
 boolean
 adin_mic_end()
 {
-  /*
-   * Not reset device on each end of speech, just let the buffer overrun...
-   * Resetting and restarting of recording device sometimes causes
-   * hawling noises at the next recording.
-   * I don't now why, so take the easy way... :-(
-   */
+  if (close(audio_fd) != 0) return FALSE;
   return TRUE;
 }
 
Index: julius4/libsent/src/adin/adin_mic_linux.c
diff -u julius4/libsent/src/adin/adin_mic_linux.c:1.3 julius4/libsent/src/adin/adin_mic_linux.c:1.4
--- julius4/libsent/src/adin/adin_mic_linux.c:1.3	Wed Mar 18 16:05:30 2009
+++ julius4/libsent/src/adin/adin_mic_linux.c	Fri Jul  3 02:05:20 2009
@@ -20,7 +20,7 @@
  * @author Akinobu LEE
  * @date   Sun Feb 13 16:18:26 2005
  *
- * $Revision: 1.3 $
+ * $Revision: 1.4 $
  * 
  */
 /*
@@ -59,17 +59,19 @@
 /** 
  * Start recording.
  * 
+ * @param pathname [in] path name to open or NULL for default
+ * 
  * @return TRUE on success, FALSE on failure.
  */
 boolean
-adin_mic_begin()
+adin_mic_begin(char *pathname)
 {
 #if defined(HAS_ALSA)
-  return(adin_alsa_begin());
+  return(adin_alsa_begin(pathname));
 #elif defined(HAS_OSS)
-  return(adin_oss_begin());
+  return(adin_oss_begin(pathname));
 #elif defined(HAS_ESD)
-  return(adin_esd_begin());
+  return(adin_esd_begin(pathname));
 #else  /* other than Linux */
   jlog("Error: neither of alsa/oss/esd device is available\n");
   return FALSE;
Index: julius4/libsent/src/adin/adin_mic_linux_alsa.c
diff -u julius4/libsent/src/adin/adin_mic_linux_alsa.c:1.10 julius4/libsent/src/adin/adin_mic_linux_alsa.c:1.11
--- julius4/libsent/src/adin/adin_mic_linux_alsa.c:1.10	Wed Mar 18 16:05:30 2009
+++ julius4/libsent/src/adin/adin_mic_linux_alsa.c	Fri Jul  3 02:05:20 2009
@@ -44,7 +44,7 @@
  * @author Akinobu LEE
  * @date   Sun Feb 13 16:18:26 2005
  *
- * $Revision: 1.10 $
+ * $Revision: 1.11 $
  * 
  */
 /*
@@ -69,6 +69,7 @@
 #include <sys/asoundlib.h>
 #endif
 
+static int srate;		///< Required sampling rate
 static snd_pcm_t *handle;	///< Audio handler
 static char pcm_name[MAXPATHLEN]; ///< Name of the PCM device
 static int latency = 32;	///< Lantency time in msec.  You can override this value by specifying environment valuable "LATENCY_MSEC".
@@ -152,7 +153,7 @@
 #endif /* HAS_ALSA */
 
 /** 
- * Device initialization: check device capability and open for recording.
+ * Device initialization: check machine capability
  * 
  * @param sfreq [in] required sampling frequency.
  * @param dummy [in] a dummy data
@@ -166,6 +167,27 @@
   jlog("Error: ALSA not compiled in\n");
   return FALSE;
 #else
+  /* store required sampling rate for checking after opening device */
+  srate = sfreq;
+  return TRUE;
+#endif
+}
+
+
+/** 
+ * Open the specified device and check capability of the opening device.
+ * 
+ * @param devstr [in] device string to open
+ * 
+ * @return TRUE on success, FALSE on failure.
+ */
+static boolean
+adin_alsa_open(char *devstr)
+{
+#ifndef HAS_ALSA
+  jlog("Error: ALSA not compiled in\n");
+  return FALSE;
+#else
   int err;
   snd_pcm_hw_params_t *hwparams; ///< Pointer to device hardware parameters
 #if (SND_LIB_MAJOR == 0)
@@ -174,19 +196,10 @@
   unsigned int actual_rate;		/* sample rate returned by hardware */
 #endif
   int dir = 0;			/* comparison result of exact rate and given rate */
-  char *p;
 
-  /* check $ALSADEV for device name */
-  if ((p = getenv("ALSADEV")) != NULL) {
-    strncpy(pcm_name, p, MAXPATHLEN);
-    jlog("Stat: adin_alsa: device name from ALSADEV: \"%s\"\n", pcm_name);
-  } else {
-    strcpy(pcm_name, "default");
-  }
-
-  /* open device in non-block mode) */
-  if ((err = snd_pcm_open(&handle, pcm_name, SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK)) < 0) {
-    jlog("Error: adin_alsa: cannot open PCM device \"%s\" (%s)\n", pcm_name, snd_strerror(err));
+  /* open the device in non-block mode) */
+  if ((err = snd_pcm_open(&handle, devstr, SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK)) < 0) {
+    jlog("Error: adin_alsa: cannot open PCM device \"%s\" (%s)\n", devstr, snd_strerror(err));
     return(FALSE);
   }
   /* set device to non-block mode */
@@ -240,21 +253,21 @@
   
   /* set sample rate (if the exact rate is not supported by the hardware, use nearest possible rate */
 #if (SND_LIB_MAJOR == 0)
-  actual_rate = snd_pcm_hw_params_set_rate_near(handle, hwparams, sfreq, &dir);
+  actual_rate = snd_pcm_hw_params_set_rate_near(handle, hwparams, srate, &dir);
   if (actual_rate < 0) {
-    jlog("Error: adin_alsa: cannot set PCM device sample rate to %d (%s)\n", sfreq, snd_strerror(actual_rate));
+    jlog("Error: adin_alsa: cannot set PCM device sample rate to %d (%s)\n", srate, snd_strerror(actual_rate));
     return(FALSE);
   }
 #else
-  actual_rate = sfreq;
+  actual_rate = srate;
   err = snd_pcm_hw_params_set_rate_near(handle, hwparams, &actual_rate, &dir);
   if (err < 0) {
-    jlog("Error: adin_alsa: cannot set PCM device sample rate to %d (%s)\n", sfreq, snd_strerror(err));
+    jlog("Error: adin_alsa: cannot set PCM device sample rate to %d (%s)\n", srate, snd_strerror(err));
     return(FALSE);
   }
 #endif
-  if (actual_rate != sfreq) {
-    jlog("Warning: adin_alsa: the exact rate %d Hz is not available by your PCM hardware.\n", sfreq);
+  if (actual_rate != srate) {
+    jlog("Warning: adin_alsa: the exact rate %d Hz is not available by your PCM hardware.\n", srate);
     jlog("Warning: adin_alsa: using %d Hz instead.\n", actual_rate);
   }
   jlog("Stat: capture audio at %dHz\n", actual_rate);
@@ -271,6 +284,7 @@
     boolean has_current_period;
 #endif
     boolean force = FALSE;
+    char *p;
     
     /* set apropriate period size */
     if ((p = getenv("LATENCY_MSEC")) != NULL) {
@@ -368,7 +382,7 @@
 #endif
 
   /* output status */
-  output_card_info(pcm_name, handle);
+  output_card_info(devstr, handle);
 
   return(TRUE);
 #endif /* HAS_ALSA */
@@ -407,17 +421,35 @@
 
 /** 
  * Start recording.
+ *
+ * @param pathname [in] device name to open or NULL for default
  * 
  * @return TRUE on success, FALSE on failure.
  */
 boolean
-adin_alsa_begin()
+adin_alsa_begin(char *pathname)
 {
 #ifndef HAS_ALSA
   return FALSE;
 #else
   int err;
   snd_pcm_state_t status;
+  char *p;
+
+  /* set device name to open to pcm_name */
+  if (pathname != NULL) {
+    strncpy(pcm_name, pathname, MAXPATHLEN);
+    jlog("Stat: adin_alsa: device name from argument: \"%s\"\n", pcm_name);
+  } else if ((p = getenv("ALSADEV")) != NULL) {
+    strncpy(pcm_name, p, MAXPATHLEN);
+    jlog("Stat: adin_alsa: device name from ALSADEV: \"%s\"\n", pcm_name);
+  } else {
+    strcpy(pcm_name, "default");
+  }
+  /* open the device */
+  if (adin_alsa_open(pcm_name) == FALSE) {
+    return FALSE;
+  }
 
   /* check hardware status */
   while(1) {			/* wait till prepared */
@@ -466,6 +498,12 @@
 boolean
 adin_alsa_end()
 {
+  int err;
+
+  if ((err = snd_pcm_close(handle)) < 0) {
+    jlog("Error: adin_alsa: cannot close PCM device (%s)\n", snd_strerror(err));
+    return(FALSE);
+  }
   return(TRUE);
 }
 
Index: julius4/libsent/src/adin/adin_mic_linux_oss.c
diff -u julius4/libsent/src/adin/adin_mic_linux_oss.c:1.6 julius4/libsent/src/adin/adin_mic_linux_oss.c:1.7
--- julius4/libsent/src/adin/adin_mic_linux_oss.c:1.6	Wed Mar 18 16:05:30 2009
+++ julius4/libsent/src/adin/adin_mic_linux_oss.c	Fri Jul  3 02:05:20 2009
@@ -51,7 +51,7 @@
  * @author Akinobu LEE
  * @date   Sun Feb 13 16:18:26 2005
  *
- * $Revision: 1.6 $
+ * $Revision: 1.7 $
  * 
  */
 /*
@@ -98,6 +98,7 @@
  */
 #define MIN_FRAGMENT_SIZE 256
 
+static int srate;		///< Required sampling rate
 static int audio_fd;		///< Audio descriptor
 static boolean need_swap;	///< Whether samples need byte swap
 static int frag_size;		///< Actual data fragment size
@@ -120,24 +121,30 @@
   jlog("Error: OSS not compiled in\n");
   return FALSE;
 #else
+  /* store required sampling rate for checking after opening device */
+  srate = sfreq;
+  return TRUE;
+}
+
+/** 
+ * Open the specified device and check capability of the opening device.
+ * 
+ * @param devstr [in] device string to open
+ * 
+ * @return TRUE on success, FALSE on failure.
+ */
+static boolean
+adin_oss_open(char *devstr)
+{
   int fmt, fmt_can, fmt1, fmt2, rfmt; /* sampling format */
   int samplerate;	/* 16kHz */
   int frag;
   int frag_msec;
   char *env, *p;
 
-  /* set device name */
-  if ((p = getenv("AUDIODEV")) == NULL) {
-    strncpy(devname, defaultdev, MAXPATHLEN);
-    jlog("Stat: adin_oss: device name = %s\n", devname);
-  } else {
-    strncpy(devname, p, MAXPATHLEN);
-    jlog("Stat: adin_oss: device name obtained from AUDIODEV: %s\n", devname);
-  }
-
   /* open device */
-  if ((audio_fd = open(devname, O_RDONLY|O_NONBLOCK)) == -1) {
-    jlog("Error: adin_oss: failed to open %s\n", devname);
+  if ((audio_fd = open(devstr, O_RDONLY|O_NONBLOCK)) == -1) {
+    jlog("Error: adin_oss: failed to open %s\n", devstr);
     return(FALSE);
   }
 
@@ -177,8 +184,8 @@
 
   /* re-open for recording */
   /* open device */
-  if ((audio_fd = open(devname, O_RDONLY)) == -1) {
-    jlog("Error: adin_oss: failed to open %s", devname);
+  if ((audio_fd = open(devstr, O_RDONLY)) == -1) {
+    jlog("Error: adin_oss: failed to open %s", devstr);
     return(FALSE);
   }
 
@@ -200,7 +207,7 @@
     /* get fragment size from MAX_FRAGMENT_MSEC and MIN_FRAGMENT_SIZE */
     f = 0;
     f2 = 1;
-    while (f2 * 1000 / (sfreq * sizeof(SP16)) <= frag_msec
+    while (f2 * 1000 / (srate * sizeof(SP16)) <= frag_msec
 	   || f2 < MIN_FRAGMENT_SIZE) {
       f++;
       f2 *= 2;
@@ -210,7 +217,7 @@
     /* set to device */
     arg = 0x7fff0000 | frag;
     if (ioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &arg)) {
-      jlog("Stat: adin_oss: set fragment size to 2^%d=%d bytes (%d msec)\n", frag, 2 << (frag-1), (2 << (frag-1)) * 1000 / (sfreq * sizeof(SP16)));
+      jlog("Stat: adin_oss: set fragment size to 2^%d=%d bytes (%d msec)\n", frag, 2 << (frag-1), (2 << (frag-1)) * 1000 / (srate * sizeof(SP16)));
     }
   }
   
@@ -309,17 +316,17 @@
     }
   }
 
-  samplerate = sfreq;
+  samplerate = srate;
   if (ioctl(audio_fd, SNDCTL_DSP_SPEED, &samplerate) == -1) {
-    jlog("Erorr: adin_oss: failed to set sample rate to %dHz\n", sfreq);
+    jlog("Erorr: adin_oss: failed to set sample rate to %dHz\n", srate);
     return(FALSE);
   }
-  if (samplerate < sfreq - FREQALLOWRANGE || samplerate > sfreq + FREQALLOWRANGE) {
-    jlog("Error: adin_oss: failed to set sampling rate to near %dHz. (%d)\n", sfreq, samplerate);
+  if (samplerate < srate - FREQALLOWRANGE || samplerate > srate + FREQALLOWRANGE) {
+    jlog("Error: adin_oss: failed to set sampling rate to near %dHz. (%d)\n", srate, samplerate);
     return FALSE;
   }
-  if (samplerate != sfreq) {
-    jlog("Warning: adin_oss: specified sampling rate was %dHz but set to %dHz, \n", sfreq, samplerate);
+  if (samplerate != srate) {
+    jlog("Warning: adin_oss: specified sampling rate was %dHz but set to %dHz, \n", srate, samplerate);
   }
   jlog("Stat: adin_oss: sampling rate = %dHz\n", samplerate);
 
@@ -333,7 +340,7 @@
   } else {
     jlog("Stat: adin_oss: going to set latency to %d msec (from env LATENCY_MSEC)\n", frag_msec);
   }
-  jlog("Stat: adin_oss: audio I/O Latency = %d msec (fragment size = %d samples)\n", frag_size * 1000/ (sfreq * sizeof(SP16)), frag_size / sizeof(SP16));
+  jlog("Stat: adin_oss: audio I/O Latency = %d msec (fragment size = %d samples)\n", frag_size * 1000/ (srate * sizeof(SP16)), frag_size / sizeof(SP16));
 
   return TRUE;
 
@@ -343,12 +350,31 @@
 /** 
  * Start recording.
  * 
+ * @param pathname [in] path name to open or NULL for default
+ * 
  * @return TRUE on success, FALSE on failure.
  */
 boolean
-adin_oss_begin()
+adin_oss_begin(char *pathname)
 {
   char buf[4];
+  char *p;
+
+  /* set device name */
+  if (pathname != NULL) {
+    strncpy(devname, pathname, MAXPATHLEN);
+    jlog("Stat: adin_oss: device name = %s (from argument)\n", devname);
+  } else if ((p = getenv("AUDIODEV")) != NULL) {
+    strncpy(devname, p, MAXPATHLEN);
+    jlog("Stat: adin_oss: device name = %s (from AUDIODEV)\n", devname);
+  } else {
+    strncpy(devname, defaultdev, MAXPATHLEN);
+    jlog("Stat: adin_oss: device name = %s (application default)\n", devname);
+  }
+
+  /* open the device */
+  if (adin_oss_open(devname) == FALSE) return FALSE;
+
   /* Read 1 sample (and ignore it) to tell the audio device start recording.
      (If you knows better way, teach me...) */
   if (stereo_rec) {
@@ -367,12 +393,7 @@
 boolean
 adin_oss_end()
 {
-  /*
-   * Not reset device on each end of speech, just let the buffer overrun...
-   * Resetting and restarting of recording device sometimes causes
-   * hawling noises at the next recording.
-   * I don't now why, so take the easy way... :-(
-   */
+  if (close(audio_fd) != 0) return FALSE;
   return TRUE;
 }
 
Index: julius4/libsent/src/adin/adin_mic_o2.c
diff -u julius4/libsent/src/adin/adin_mic_o2.c:1.3 julius4/libsent/src/adin/adin_mic_o2.c:1.4
--- julius4/libsent/src/adin/adin_mic_o2.c:1.3	Wed Mar 18 16:05:30 2009
+++ julius4/libsent/src/adin/adin_mic_o2.c	Fri Jul  3 02:05:20 2009
@@ -29,7 +29,7 @@
  * @author Akinobu LEE
  * @date   Sun Feb 13 18:42:22 2005
  *
- * $Revision: 1.3 $
+ * $Revision: 1.4 $
  * 
  */
 /*
@@ -114,13 +114,20 @@
 /** 
  * Start recording.
  * 
+ * @param pathname [in] path name to open or NULL for default
+ * 
  * @return TRUE on success, FALSE on failure.
  */
 boolean
-adin_mic_begin()
+adin_mic_begin(char *pathname)
 {
   /* open audio port */
-  aport = ALopenport("mic","r",ac);
+  if (pathname != NULL) {
+    jlog("Stat: adin_o2: opening audio device \"%s\"\n", pathname);
+    aport = ALopenport(pathname,"r",ac);
+  } else {
+    aport = ALopenport("mic","r",ac);
+  }
   if (aport == (ALport)(0)) {
     jlog("Error: adin_o2: cannot open microphone audio port for reading\n");
     return(FALSE);
Index: julius4/libsent/src/adin/adin_mic_sol2.c
diff -u julius4/libsent/src/adin/adin_mic_sol2.c:1.3 julius4/libsent/src/adin/adin_mic_sol2.c:1.4
--- julius4/libsent/src/adin/adin_mic_sol2.c:1.3	Wed Mar 18 16:05:30 2009
+++ julius4/libsent/src/adin/adin_mic_sol2.c	Fri Jul  3 02:05:20 2009
@@ -38,7 +38,7 @@
  * @author Akinobu LEE
  * @date   Sun Feb 13 19:06:46 2005
  *
- * $Revision: 1.3 $
+ * $Revision: 1.4 $
  * 
  */
 /*
@@ -59,6 +59,8 @@
 
 /* sound header */
 #include <sys/audioio.h>
+
+static int srate;		///< Required sampling rate
 static int afd;			///< Audio file descriptor
 static struct audio_info ainfo;	///< Audio format information
 static char *defaultdev = DEFAULT_DEVICE;
@@ -69,7 +71,7 @@
 
 
 /** 
- * Device initialization: check device capability and open for recording.
+ * Device initialization: check device capability
  * 
  * @param sfreq [in] required sampling frequency.
  * @param arg [in] a dummy data
@@ -79,19 +81,24 @@
 boolean
 adin_mic_standby(int sfreq, void *arg)
 {
-  char *p;
-  /* get device name if specified in $AUDIODEV */
-  if ((p = getenv("AUDIODEV")) == NULL) {
-    strncpy(devname, defaultdev, MAXPATHLEN);
-    jlog("Stat: adin_sol2: device name = %s\n", devname);
-  } else {
-    strncpy(devname, p, MAXPATHLEN);
-    jlog("Stat: adin_sol2: device name obtained from AUDIODEV: %s\n", devname);
-  }
+  /* store required sampling rate for checking after opening device */
+  srate = sfreq;
+  return TRUE;
+}
 
+/** 
+ * Open the specified device and check capability of the opening device.
+ * 
+ * @param devstr [in] device string to open
+ * 
+ * @return TRUE on success, FALSE on failure.
+ */
+static boolean
+adin_mic_open(char *devstr)
+{
   /* open the device */
-  if ((afd = open(devname, O_RDONLY)) == -1) {
-    jlog("Error: adin_sol2: failed to open audio device %s\n", devname);
+  if ((afd = open(devstr, O_RDONLY)) == -1) {
+    jlog("Error: adin_sol2: failed to open audio device %s\n", devstr);
     return(FALSE);
   }
 
@@ -126,7 +133,7 @@
     return(FALSE);
   }
   /* set record setting */
-  ainfo.record.sample_rate = sfreq;
+  ainfo.record.sample_rate = srate;
   ainfo.record.channels = 1;
   ainfo.record.precision = 16;
   ainfo.record.encoding = AUDIO_ENCODING_LINEAR;
@@ -142,17 +149,35 @@
   }
 
   return(TRUE);
-
 }
 
 /** 
  * Start recording.
  * 
+ * @param pathname [in] path name to open or NULL for default
+ * 
  * @return TRUE on success, FALSE on failure.
  */
 boolean
-adin_mic_begin()
+adin_mic_begin(char *pathname)
 {
+  char *p;
+
+  /* set device name */
+  if (pathname != NULL) {
+    strncpy(devname, pathname, MAXPATHLEN);
+    jlog("Stat: adin_sol2: device name = %s (from argument)\n", devname);
+  } else if ((p = getenv("AUDIODEV")) != NULL) {
+    strncpy(devname, p, MAXPATHLEN);
+    jlog("Stat: adin_sol2: device name = %s (from AUDIODEV)\n", devname);
+  } else {    
+    strncpy(devname, defaultdev, MAXPATHLEN);
+    jlog("Stat: adin_sol2: device name = %s (application default)\n", devname);
+  }
+
+  /* open the device */
+  if (adin_mic_open(devname) == FALSE) return FALSE;
+
   if (ioctl(afd, AUDIO_GETINFO, &ainfo) == -1) {
     jlog("Error: adin_sol2: failed to get audio status\n");
     return(FALSE);
@@ -174,6 +199,9 @@
 boolean
 adin_mic_end()
 {
+#if 1
+  close(afd);
+#else
   if (ioctl(afd, AUDIO_GETINFO, &ainfo) == -1) {
     jlog("Error: adin_sol2: failed to get audio status\n");
     return(FALSE);
@@ -183,6 +211,7 @@
     jlog("Error: adin_sol2: failed to set audio status\n");
     return(FALSE);
   }
+#endif
   return(TRUE);
 }
 
Index: julius4/libsent/src/adin/adin_mic_sp.c
diff -u julius4/libsent/src/adin/adin_mic_sp.c:1.3 julius4/libsent/src/adin/adin_mic_sp.c:1.4
--- julius4/libsent/src/adin/adin_mic_sp.c:1.3	Wed Mar 18 16:05:30 2009
+++ julius4/libsent/src/adin/adin_mic_sp.c	Fri Jul  3 02:05:20 2009
@@ -35,7 +35,7 @@
  * @author Akinobu LEE
  * @date   Sun Feb 13 19:16:43 2005
  *
- * $Revision: 1.3 $
+ * $Revision: 1.4 $
  * 
  */
 /* adin_mic_sp.c --- adin microphone library for spAudio
@@ -70,11 +70,13 @@
 
 /** 
  * Start recording.
+ *
+ * @param pathname [in] path name to open or NULL for default
  * 
  * @return TRUE on success, FALSE on failure.
  */
 boolean
-adin_mic_begin()
+adin_mic_begin(char *pathname)
 {
   if (audio == NULL) {
     audio = spInitAudio();
Index: julius4/libsent/src/adin/adin_mic_sun4.c
diff -u julius4/libsent/src/adin/adin_mic_sun4.c:1.3 julius4/libsent/src/adin/adin_mic_sun4.c:1.4
--- julius4/libsent/src/adin/adin_mic_sun4.c:1.3	Wed Mar 18 16:05:30 2009
+++ julius4/libsent/src/adin/adin_mic_sun4.c	Fri Jul  3 02:05:20 2009
@@ -34,7 +34,7 @@
  * @author Akinobu LEE
  * @date   Sun Feb 13 18:56:13 2005
  *
- * $Revision: 1.3 $
+ * $Revision: 1.4 $
  * 
  */
 /*
@@ -64,6 +64,7 @@
 /* sound header */
 #include <multimedia/libaudio.h>/* see man audio_device(3) */
 #include <multimedia/audio_device.h>
+static int srate;		///< Required sampling rate
 static int afd;			///< Audio file descriptor
 static struct pollfd pfd;	///< File descriptor for polling
 static audio_info_t ainfo;	///< Audio info
@@ -81,26 +82,31 @@
 boolean
 adin_mic_standby(int sfreq, void *dummy)
 {
+  /* store required sampling rate for checking after opening device */
+  srate = sfreq;
+  return TRUE;
+}
+
+/** 
+ * Open the specified device and check capability of the opening device.
+ * 
+ * @param devstr [in] device string to open
+ * 
+ * @return TRUE on success, FALSE on failure.
+ */
+static boolean
+adin_mic_open(char *devstr)
+{
   Audio_hdr Dev_hdr, old_hdr;
   double vol;
-  char *p;
-
-  /* get device name if specified in $AUDIODEV */
-  if ((p = getenv("AUDIODEV")) == NULL) {
-    strncpy(devname, defaultdev, MAXPATHLEN);
-    jlog("Stat: adin_sun4: device name = %s\n", devname);
-  } else {
-    strncpy(devname, p, MAXPATHLEN);
-    jlog("Stat: adin_sun4: device name obtained from AUDIODEV: %s\n", devname);
-  }
 
   /* open the device */
-  if ((afd = open(devname, O_RDONLY)) == -1) {
+  if ((afd = open(devstr, O_RDONLY)) == -1) {
     if (errno == EBUSY) {
-      jlog("Error: adin_sun4: audio device %s is busy\n", devname);
+      jlog("Error: adin_sun4: audio device %s is busy\n", devstr);
       return(FALSE);
     } else {
-      jlog("Error: adin_sun4: unable to open %s\n",devname);
+      jlog("Error: adin_sun4: unable to open %s\n",devstr);
       return(FALSE);
     }
   }
@@ -117,7 +123,7 @@
   if (audio_get_record_config(afd, &Dev_hdr) != AUDIO_SUCCESS) {
     jlog("Error: adin_sun4: failed to get recording config\n"); return(FALSE);
   }
-  Dev_hdr.sample_rate = sfreq;
+  Dev_hdr.sample_rate = srate;
   Dev_hdr.samples_per_unit = 1; /* ? I don't know this param. ? */
   Dev_hdr.bytes_per_unit = 2;
   Dev_hdr.channels = 1;
@@ -143,11 +149,13 @@
   pfd.fd = afd;
   pfd.events = POLLIN;
 
+#if 0
   /* pause transfer */
   if (audio_pause_record(afd) == AUDIO_ERR_NOEFFECT) {
     jlog("Error: adin_sun4: cannot pause audio\n");
     return(FALSE);
   }
+#endif
 
   return(TRUE);
 }
@@ -155,16 +163,38 @@
 /** 
  * Start recording.
  * 
+ * @param pathname [in] path name to open or NULL for default
+ * 
  * @return TRUE on success, FALSE on failure.
  */
 boolean
-adin_mic_begin()
+adin_mic_begin(char *pathname)
 {
+  char *p;
+
+  /* set device name */
+  if (pathname != NULL) {
+    strncpy(devname, pathname, MAXPATHLEN);
+    jlog("Stat: adin_sun4: device name = %s (from argument)\n", devname);
+  } else if ((p = getenv("AUDIODEV")) != NULL) {
+    strncpy(devname, p, MAXPATHLEN);
+    jlog("Stat: adin_sun4: device name = %s (from AUDIODEV)\n", devname);
+  } else {    
+    strncpy(devname, defaultdev, MAXPATHLEN);
+    jlog("Stat: adin_sun4: device name = %s (application default)\n", devname);
+  }
+
+  /* open the device */
+  if (adin_mic_open(devname) == FALSE) return FALSE;
+
+#if 0
   /* resume input */
   if (audio_resume_record(afd) == AUDIO_ERR_NOEFFECT) {
     jlog("Error: adin_sun4: cannot resume audio\n");
     return(FALSE);
   }
+#endif
+
   return(TRUE);
 }
 
@@ -176,11 +206,15 @@
 boolean
 adin_mic_end()
 {
+#if 1
+  close(afd);
+#else
   /* pause input */
   if (audio_pause_record(afd) == AUDIO_ERR_NOEFFECT) {
     jlog("Error: adin_sun4: cannot pause audio\n");
     return(FALSE);
   }
+#endif
   return(TRUE);
 }
 
Index: julius4/libsent/src/adin/adin_netaudio.c
diff -u julius4/libsent/src/adin/adin_netaudio.c:1.3 julius4/libsent/src/adin/adin_netaudio.c:1.4
--- julius4/libsent/src/adin/adin_netaudio.c:1.3	Wed Mar 18 16:05:30 2009
+++ julius4/libsent/src/adin/adin_netaudio.c	Fri Jul  3 02:05:20 2009
@@ -26,7 +26,7 @@
  * @author Akinobu LEE
  * @date   Sun Feb 13 19:50:55 2005
  *
- * $Revision: 1.3 $
+ * $Revision: 1.4 $
  * 
  */
 /*
@@ -67,10 +67,12 @@
 /** 
  * Start recording.
  * 
+ * @param pathname [in] path name to open or NULL for default
+ * 
  * @return TRUE on success, FALSE on failure.
  */
 boolean
-adin_netaudio_begin()
+adin_netaudio_begin(char *pathname)
 {
   NA_start();
   return(TRUE);
Index: julius4/libsent/src/adin/adin_portaudio.c
diff -u julius4/libsent/src/adin/adin_portaudio.c:1.3 julius4/libsent/src/adin/adin_portaudio.c:1.4
--- julius4/libsent/src/adin/adin_portaudio.c:1.3	Wed Mar 18 16:05:30 2009
+++ julius4/libsent/src/adin/adin_portaudio.c	Fri Jul  3 02:05:20 2009
@@ -44,7 +44,7 @@
  * @author Akinobu LEE
  * @date   Mon Feb 14 12:03:48 2005
  *
- * $Revision: 1.3 $
+ * $Revision: 1.4 $
  * 
  */
 /*
@@ -218,10 +218,12 @@
 /** 
  * Start recording.
  * 
+ * @param pathname [in] path name to open or NULL for default
+ * 
  * @return TRUE on success, FALSE on failure.
  */
 boolean
-adin_mic_begin()
+adin_mic_begin(char *pathname)
 {
   PaError err;
 
Index: julius4/libsent/src/adin/adin_sndfile.c
diff -u julius4/libsent/src/adin/adin_sndfile.c:1.3 julius4/libsent/src/adin/adin_sndfile.c:1.4
--- julius4/libsent/src/adin/adin_sndfile.c:1.3	Tue Dec 18 17:45:50 2007
+++ julius4/libsent/src/adin/adin_sndfile.c	Fri Jul  3 02:05:20 2009
@@ -61,7 +61,7 @@
  * @author Akinobu LEE
  * @date   Mon Feb 14 12:13:27 2005
  *
- * $Revision: 1.3 $
+ * $Revision: 1.4 $
  * 
  */
 /*
@@ -220,19 +220,86 @@
 }
 
 /** 
+ * @brief  Open a file and check the format
+ *
+ * @param filename [in] file name to open
+ * 
+ * @return TRUE on success, FALSE on failure.
+ */
+static boolean
+adin_sndfile_open(char *filename)
+{
+#ifndef HAVE_LIBSNDFILE_VER1
+  sinfo.samplerate = sfreq;
+  sinfo.pcmbitwidth = 16;
+  sinfo.channels = 1;
+#endif
+  sinfo.format = 0x0;
+  if ((sp = 
+#ifdef HAVE_LIBSNDFILE_VER1
+       sf_open(filename, SFM_READ, &sinfo)
+#else
+       sf_open_read(filename, &sinfo)
+#endif
+       ) == NULL) {
+    /* retry assuming raw format */
+    sinfo.samplerate = sfreq;
+    sinfo.channels = 1;
+#ifdef HAVE_LIBSNDFILE_VER1
+    sinfo.format = SF_FORMAT_RAW | SF_FORMAT_PCM_16 | SF_ENDIAN_BIG;
+#else
+    sinfo.pcmbitwidth = 16;
+    sinfo.format = SF_FORMAT_RAW | SF_FORMAT_PCM_BE;
+#endif
+    if ((sp =
+#ifdef HAVE_LIBSNDFILE_VER1
+	 sf_open(filename, SFM_READ, &sinfo)
+#else
+	 sf_open_read(filename, &sinfo)
+#endif
+	 ) == NULL) {
+      sf_perror(sp);
+      jlog("Error: adin_sndfile: failed to open speech data: \"%s\"\n",filename);
+    }
+  }
+  if (sp == NULL) {		/* open failure */
+    return FALSE;
+  }
+  /* check its format */
+  if (! check_format(&sinfo)) {
+    return FALSE;
+  }
+  return TRUE;
+}
+
+/** 
  * @brief  Begin reading audio data from a file.
  *
  * If listfile was specified in adin_sndfile_standby(), the next filename
  * will be read from the listfile.  Otherwise, the
  * filename will be obtained from stdin.  Then the file will be opened here.
+ *
+ * @param filename [in] file name to open or NULL for prompt
  * 
  * @return TRUE on success, FALSE on failure.
  */
 boolean
-adin_sndfile_begin()
+adin_sndfile_begin(char *filename)
 {
   boolean readp;
 
+  if (filename != NULL) {
+    if (adin_sndfile_open(filename) == FALSE) {
+      jlog("Error: adin_sndfile: invalid format: \"%s\"\n", filename);
+      print_format(&sinfo);
+      return FALSE;
+    }
+    jlog("Stat: adin_sndfile: input speechfile: %s\n", filename);
+    print_format(&sinfo);
+    strcpy(speechfilename, filename);
+    return TRUE;
+  }
+
   /* ready to read next input */
   readp = FALSE;
   while(readp == FALSE) {
@@ -250,49 +317,13 @@
 	return (FALSE);	/* end of input */
       }
     }
-    /* open input file */
-#ifndef HAVE_LIBSNDFILE_VER1
-    sinfo.samplerate = sfreq;
-    sinfo.pcmbitwidth = 16;
-    sinfo.channels = 1;
-#endif
-    sinfo.format = 0x0;
-    if ((sp = 
-#ifdef HAVE_LIBSNDFILE_VER1
-	 sf_open(speechfilename, SFM_READ, &sinfo)
-#else
-	 sf_open_read(speechfilename, &sinfo)
-#endif
-	 ) == NULL) {
-      /* retry assuming raw format */
-      sinfo.samplerate = sfreq;
-      sinfo.channels = 1;
-#ifdef HAVE_LIBSNDFILE_VER1
-      sinfo.format = SF_FORMAT_RAW | SF_FORMAT_PCM_16 | SF_ENDIAN_BIG;
-#else
-      sinfo.pcmbitwidth = 16;
-      sinfo.format = SF_FORMAT_RAW | SF_FORMAT_PCM_BE;
-#endif
-      if ((sp =
-#ifdef HAVE_LIBSNDFILE_VER1
-	   sf_open(speechfilename, SFM_READ, &sinfo)
-#else
-	   sf_open_read(speechfilename, &sinfo)
-#endif
-	   ) == NULL) {
-	sf_perror(sp);
-	jlog("Error: adin_sndfile: failed to open speech data: \"%s\"\n",speechfilename);
-      }
-    }
-    if (sp != NULL) {		/* open success */
-      if (! check_format(&sinfo)) {
-	jlog("Error: adin_sndfile: invalid format: \"%s\"\n",speechfilename);
-	print_format(&sinfo);
-      } else {
-	jlog("Stat: adin_sndfile: input speechfile: %s\n",speechfilename);
-	print_format(&sinfo);
-	readp = TRUE;
-      }
+    if (adin_sndfile_open(speechfilename) == FALSE) {
+      jlog("Error: adin_sndfile: invalid format: \"%s\"\n",speechfilename);
+      print_format(&sinfo);
+    } else {
+      jlog("Stat: adin_sndfile: input speechfile: %s\n",speechfilename);
+      print_format(&sinfo);
+      readp = TRUE;
     }
   }
   return TRUE;
Index: julius4/libsent/src/adin/adin_tcpip.c
diff -u julius4/libsent/src/adin/adin_tcpip.c:1.4 julius4/libsent/src/adin/adin_tcpip.c:1.5
--- julius4/libsent/src/adin/adin_tcpip.c:1.4	Wed Mar 18 16:05:30 2009
+++ julius4/libsent/src/adin/adin_tcpip.c	Fri Jul  3 02:05:20 2009
@@ -45,7 +45,7 @@
  * @author Akinobu LEE
  * @date   Mon Feb 14 14:55:03 2005
  *
- * $Revision: 1.4 $
+ * $Revision: 1.5 $
  * 
  */
 /*
@@ -94,10 +94,12 @@
 /** 
  * Wait for connection from adinnet client and begin audio input stream.
  *
+ * @param pathname [in] path name to open or NULL for default
+ * 
  * @return TRUE on success, FALSE on failure.
  */
 boolean
-adin_tcpip_begin()
+adin_tcpip_begin(char *pathname)
 {
 #ifdef FORK_ADINNET
     /***********************************/



Julius-cvs メーリングリストの案内
アーカイブの一覧に戻る