From sumomo @ users.sourceforge.jp Thu Jul 2 18:19:06 2009 From: sumomo @ users.sourceforge.jp (sumomo @ users.sourceforge.jp) Date: Thu, 02 Jul 2009 18:19:06 +0900 Subject: [Julius-cvs 418] CVS update: julius4/libjulius/src Message-ID: <1246526346.770958.17466.nullmailer@users.sourceforge.jp> Index: julius4/libjulius/src/confnet.c diff -u julius4/libjulius/src/confnet.c:1.3 julius4/libjulius/src/confnet.c:1.4 --- julius4/libjulius/src/confnet.c:1.3 Wed Feb 13 17:46:36 2008 +++ julius4/libjulius/src/confnet.c Thu Jul 2 18:19:06 2009 @@ -16,7 +16,7 @@ * @author Akinobu Lee * @date Thu Aug 16 00:15:51 2007 * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * */ /* @@ -355,7 +355,7 @@ if (c->words) { free(c->words); } - c->words = (WORD_ID *)mymalloc(sizeof(WORD_ID) * c->wgnum + 1); + c->words = (WORD_ID *)mymalloc(sizeof(WORD_ID) * (c->wgnum + 1)); c->wordsnum = 0; for(i=0;iwgnum;i++) { for(j=0;jwordsnum;j++) { From sumomo @ users.sourceforge.jp Fri Jul 3 02:05:20 2009 From: sumomo @ users.sourceforge.jp (sumomo @ users.sourceforge.jp) Date: Fri, 03 Jul 2009 02:05:20 +0900 Subject: [Julius-cvs 419] CVS update: julius4/libjulius/include/julius Message-ID: <1246554320.347384.4885.nullmailer@users.sourceforge.jp> Index: julius4/libjulius/include/julius/extern.h diff -u julius4/libjulius/include/julius/extern.h:1.13 julius4/libjulius/include/julius/extern.h:1.14 --- julius4/libjulius/include/julius/extern.h:1.13 Wed Mar 18 16:05:30 2009 +++ julius4/libjulius/include/julius/extern.h Fri Jul 3 02:05:20 2009 @@ -12,7 +12,7 @@ * @author Akinobu LEE * @date Mon Mar 7 23:19:14 2005 * - * $Revision: 1.13 $ + * $Revision: 1.14 $ * */ /* @@ -271,7 +271,7 @@ boolean adin_thread_cancel(Recog *recog); int adin_go(int (*ad_process)(SP16 *, int, Recog *), int (*ad_check)(Recog *), Recog *recog); boolean adin_standby(ADIn *a, int freq, void *arg); -boolean adin_begin(ADIn *a); +boolean adin_begin(ADIn *a, char *file_or_dev_name); boolean adin_end(ADIn *a); void adin_free_param(Recog *recog); Index: julius4/libjulius/include/julius/recog.h diff -u julius4/libjulius/include/julius/recog.h:1.8 julius4/libjulius/include/julius/recog.h:1.9 --- julius4/libjulius/include/julius/recog.h:1.8 Wed Mar 18 16:05:30 2009 +++ julius4/libjulius/include/julius/recog.h Fri Jul 3 02:05:20 2009 @@ -70,7 +70,7 @@ * @author Akinobu Lee * @date Fri Feb 16 13:42:28 2007 * - * $Revision: 1.8 $ + * $Revision: 1.9 $ * */ /* @@ -336,7 +336,7 @@ /// Pointer to function for device initialization (call once on startup) boolean (*ad_standby)(int, void *); /// Pointer to function to open audio stream for capturing - boolean (*ad_begin)(); + boolean (*ad_begin)(char *); /// Pointer to function to close audio stream capturing boolean (*ad_end)(); /// Pointer to function to begin / restart recording From sumomo @ users.sourceforge.jp Fri Jul 3 02:05:20 2009 From: sumomo @ users.sourceforge.jp (sumomo @ users.sourceforge.jp) Date: Fri, 03 Jul 2009 02:05:20 +0900 Subject: [Julius-cvs 420] CVS update: julius4/plugin Message-ID: <1246554320.722618.4947.nullmailer@users.sourceforge.jp> Index: julius4/plugin/adin_oss.c diff -u julius4/plugin/adin_oss.c:1.2 julius4/plugin/adin_oss.c:1.3 --- julius4/plugin/adin_oss.c:1.2 Wed Mar 18 16:05:31 2009 +++ julius4/plugin/adin_oss.c Fri Jul 3 02:05:20 2009 @@ -53,7 +53,7 @@ * @author Akinobu Lee * @date Thu Aug 7 14:28:37 2008 * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * */ @@ -421,6 +421,8 @@ * If this function returns FALSE, Julius will exit recognition loop. * * JuliusLib: this will be called at j_open_stream(). + * + * @param pathname [in] file / device name to open or NULL for default * * @return TRUE on success, FALSE on failure. * @@ -434,11 +436,13 @@ * * JuliusLib: この関数は j_open_stream() 内で呼ばれる. * + * @param pathname [in] 開くファイルあるいはデバイス名,NULL ならデフォルト + * * @return 成功時 TRUE,失敗時 FALSE を返す. * */ boolean -adin_open() +adin_open(char *pathname) { /* do open the device */ int fmt; @@ -447,8 +451,8 @@ int s; char buf[2]; - if ((audio_fd = open("/dev/dsp", O_RDONLY)) == -1) { - printf("Error: cannot open /dev/dsp\n"); + if ((audio_fd = open(pathname ? pathname : "/dev/dsp", O_RDONLY)) == -1) { + printf("Error: cannot open %s\n", pathname ? pathname : "/dev/dsp"); return FALSE; } fmt = AFMT_S16_LE; /* 16bit signed (little endian) */ From sumomo @ users.sourceforge.jp Fri Jul 3 02:05:20 2009 From: sumomo @ users.sourceforge.jp (sumomo @ users.sourceforge.jp) Date: Fri, 03 Jul 2009 02:05:20 +0900 Subject: [Julius-cvs 421] CVS update: julius4/libsent/include/sent Message-ID: <1246554320.508247.4905.nullmailer@users.sourceforge.jp> Index: julius4/libsent/include/sent/adin.h diff -u julius4/libsent/include/sent/adin.h:1.5 julius4/libsent/include/sent/adin.h:1.6 --- julius4/libsent/include/sent/adin.h:1.5 Wed Mar 18 16:05:30 2009 +++ julius4/libsent/include/sent/adin.h Fri Jul 3 02:05:20 2009 @@ -19,7 +19,7 @@ * @author Akinobu LEE * @date Thu Feb 10 17:22:36 2005 * - * $Revision: 1.5 $ + * $Revision: 1.6 $ */ /* * Copyright (c) 1991-2007 Kawahara Lab., Kyoto University @@ -146,31 +146,31 @@ /* adin/adin_mic_*.c */ boolean adin_mic_standby(int freq, void *arg); -boolean adin_mic_begin(); +boolean adin_mic_begin(char *pathname); boolean adin_mic_end(); int adin_mic_read(SP16 *buf, int sampnum); char *adin_mic_input_name(); /* adin/adin_mic_linux_alsa.c */ boolean adin_alsa_standby(int freq, void *arg); -boolean adin_alsa_begin(); +boolean adin_alsa_begin(char *pathname); boolean adin_alsa_end(); int adin_alsa_read(SP16 *buf, int sampnum); char *adin_alsa_input_name(); /* adin/adin_mic_linux_oss.c */ boolean adin_oss_standby(int freq, void *arg); -boolean adin_oss_begin(); +boolean adin_oss_begin(char *pathname); boolean adin_oss_end(); int adin_oss_read(SP16 *buf, int sampnum); char *adin_oss_input_name(); /* adin/adin_esd.c */ boolean adin_esd_standby(int freq, void *arg); -boolean adin_esd_begin(); +boolean adin_esd_begin(char *pathname); boolean adin_esd_end(); int adin_esd_read(SP16 *buf, int sampnum); char *adin_esd_input_name(); /* adin/adin_netaudio.c and adin/adin_na.c */ boolean adin_netaudio_standby(int freq, void *arg); -boolean adin_netaudio_begin(); +boolean adin_netaudio_begin(char *pathname); boolean adin_netaudio_end(); int adin_netaudio_read(SP16 *buf, int sampnum); char *adin_netaudio_input_name(); @@ -181,11 +181,11 @@ /* adin/adin_file.c */ boolean adin_file_standby(int freq, void *arg); -boolean adin_file_begin(); +boolean adin_file_begin(char *pathname); int adin_file_read(SP16 *buf, int sampnum); boolean adin_file_end(); boolean adin_stdin_standby(int freq, void *arg); -boolean adin_stdin_begin(); +boolean adin_stdin_begin(char *pathname); int adin_stdin_read(SP16 *buf, int sampnum); char *adin_file_get_current_filename(); char *adin_stdin_input_name(); @@ -193,7 +193,7 @@ /* adin/adin_sndfile.c */ #ifdef HAVE_LIBSNDFILE boolean adin_sndfile_standby(int freq, void *arg); -boolean adin_sndfile_begin(); +boolean adin_sndfile_begin(char *pathname); int adin_sndfile_read(SP16 *buf, int sampnum); boolean adin_sndfile_end(); char *adin_sndfile_get_current_filename(); @@ -201,7 +201,7 @@ /* adin/adin_tcpip.c */ boolean adin_tcpip_standby(int freq, void *arg); -boolean adin_tcpip_begin(); +boolean adin_tcpip_begin(char *pathname); boolean adin_tcpip_end(); int adin_tcpip_read(SP16 *buf, int sampnum); boolean adin_tcpip_send_pause(); From sumomo @ users.sourceforge.jp Fri Jul 3 02:05:20 2009 From: sumomo @ users.sourceforge.jp (sumomo @ users.sourceforge.jp) Date: Fri, 03 Jul 2009 02:05:20 +0900 Subject: [Julius-cvs 422] CVS update: julius4/libjulius/src Message-ID: <1246554320.426080.4898.nullmailer@users.sourceforge.jp> Index: julius4/libjulius/src/adin-cut.c diff -u julius4/libjulius/src/adin-cut.c:1.10 julius4/libjulius/src/adin-cut.c:1.11 --- julius4/libjulius/src/adin-cut.c:1.10 Sat Jan 17 16:53:47 2009 +++ julius4/libjulius/src/adin-cut.c Fri Jul 3 02:05:20 2009 @@ -95,7 +95,7 @@ * @author Akinobu LEE * @date Sat Feb 12 13:20:53 2005 * - * $Revision: 1.10 $ + * $Revision: 1.11 $ * */ /* @@ -1277,6 +1277,7 @@ * * * @param a [in] A/D-in work area + * @param file_or_dev_name [in] device / file path to open or NULL for default * * @return TRUE on success, FALSE on failure. * @@ -1285,12 +1286,12 @@ * */ boolean -adin_begin(ADIn *a) +adin_begin(ADIn *a, char *file_or_dev_name) { if (debug2_flag && a->input_side_segment) jlog("Stat: adin_begin: skip\n"); if (a->input_side_segment == FALSE) { if (a->need_zmean) zmean_reset(); - if (a->ad_begin != NULL) return(a->ad_begin()); + if (a->ad_begin != NULL) return(a->ad_begin(file_or_dev_name)); } return TRUE; } Index: julius4/libjulius/src/m_adin.c diff -u julius4/libjulius/src/m_adin.c:1.9 julius4/libjulius/src/m_adin.c:1.10 --- julius4/libjulius/src/m_adin.c:1.9 Thu Mar 19 20:02:23 2009 +++ julius4/libjulius/src/m_adin.c Fri Jul 3 02:05:20 2009 @@ -12,7 +12,7 @@ * @author Akinobu LEE * @date Fri Mar 18 16:17:23 2005 * - * $Revision: 1.9 $ + * $Revision: 1.10 $ * */ /* @@ -263,7 +263,7 @@ adin->enable_thread = (*func)(2); adin->ad_standby = (boolean (*)(int, void *)) plugin_get_func(sid, "adin_standby"); - adin->ad_begin = (boolean (*)()) plugin_get_func(sid, "adin_open"); + adin->ad_begin = (boolean (*)(char *)) plugin_get_func(sid, "adin_open"); adin->ad_end = (boolean (*)()) plugin_get_func(sid, "adin_close"); adin->ad_resume = (boolean (*)()) plugin_get_func(sid, "adin_resume"); adin->ad_pause = (boolean (*)()) plugin_get_func(sid, "adin_pause"); Index: julius4/libjulius/src/recogmain.c diff -u julius4/libjulius/src/recogmain.c:1.12 julius4/libjulius/src/recogmain.c:1.13 --- julius4/libjulius/src/recogmain.c:1.12 Wed Mar 18 16:05:30 2009 +++ julius4/libjulius/src/recogmain.c Fri Jul 3 02:05:20 2009 @@ -12,7 +12,7 @@ * @author Akinobu Lee * @date Wed Aug 8 14:53:53 2007 * - * $Revision: 1.12 $ + * $Revision: 1.13 $ * */ @@ -499,7 +499,7 @@ if (jconf->input.type == INPUT_WAVEFORM) { /* begin A/D input */ - if (adin_begin(recog->adin) == FALSE) { + if (adin_begin(recog->adin, file_or_dev_name) == FALSE) { return -2; } /* create A/D-in thread here */ From sumomo @ users.sourceforge.jp Fri Jul 3 02:05:20 2009 From: sumomo @ users.sourceforge.jp (sumomo @ users.sourceforge.jp) Date: Fri, 03 Jul 2009 02:05:20 +0900 Subject: [Julius-cvs 423] CVS update: julius4/libsent/src/adin Message-ID: <1246554320.655848.4940.nullmailer@users.sourceforge.jp> 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 #include @@ -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 #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 + +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 /* see man audio_device(3) */ #include +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 /***********************************/ From sumomo @ users.sourceforge.jp Sat Jul 4 23:11:42 2009 From: sumomo @ users.sourceforge.jp (sumomo @ users.sourceforge.jp) Date: Sat, 04 Jul 2009 23:11:42 +0900 Subject: [Julius-cvs 424] CVS update: julius4/libjulius/include/julius Message-ID: <1246716702.892405.9593.nullmailer@users.sourceforge.jp> Index: julius4/libjulius/include/julius/extern.h diff -u julius4/libjulius/include/julius/extern.h:1.14 julius4/libjulius/include/julius/extern.h:1.15 --- julius4/libjulius/include/julius/extern.h:1.14 Fri Jul 3 02:05:20 2009 +++ julius4/libjulius/include/julius/extern.h Sat Jul 4 23:11:42 2009 @@ -12,7 +12,7 @@ * @author Akinobu LEE * @date Mon Mar 7 23:19:14 2005 * - * $Revision: 1.14 $ + * $Revision: 1.15 $ * */ /* @@ -102,6 +102,8 @@ void segment_set_last_nword(NODE *hypo, RecogProcess *r); void pass2_finalize_on_no_result(RecogProcess *r, boolean use_1pass_as_final); void wchmm_fbs(HTK_Param *param, RecogProcess *r, int cate_bgn, int cate_num); +void wchmm_fbs_prepare(RecogProcess *r); +void wchmm_fbs_free(RecogProcess *r); /* search_bestfirst_v?.c */ void clear_stocker(StackDecode *s); Index: julius4/libjulius/include/julius/recog.h diff -u julius4/libjulius/include/julius/recog.h:1.9 julius4/libjulius/include/julius/recog.h:1.10 --- julius4/libjulius/include/julius/recog.h:1.9 Fri Jul 3 02:05:20 2009 +++ julius4/libjulius/include/julius/recog.h Sat Jul 4 23:11:42 2009 @@ -70,7 +70,7 @@ * @author Akinobu Lee * @date Fri Feb 16 13:42:28 2007 * - * $Revision: 1.9 $ + * $Revision: 1.10 $ * */ /* @@ -238,6 +238,8 @@ short *wef; ///< Work area for word-end frame tokens for v2 LOGPROB *wes; ///< Work area for word-end score tokens for v2 #endif + WORD_ID *cnword; ///< Work area for N-gram computation + WORD_ID *cnwordrev; ///< Work area for N-gram computation } StackDecode; From sumomo @ users.sourceforge.jp Sat Jul 4 23:11:43 2009 From: sumomo @ users.sourceforge.jp (sumomo @ users.sourceforge.jp) Date: Sat, 04 Jul 2009 23:11:43 +0900 Subject: [Julius-cvs 425] CVS update: julius4/libsent/include/sent Message-ID: <1246716703.086437.9620.nullmailer@users.sourceforge.jp> Index: julius4/libsent/include/sent/ngram2.h diff -u julius4/libsent/include/sent/ngram2.h:1.6 julius4/libsent/include/sent/ngram2.h:1.7 --- julius4/libsent/include/sent/ngram2.h:1.6 Tue Feb 10 17:15:48 2009 +++ julius4/libsent/include/sent/ngram2.h Sat Jul 4 23:11:43 2009 @@ -5,8 +5,7 @@ * @brief Definitions for word N-gram * * This file defines a structure for word N-gram language model. - * Julius now support N-gram for arbitrary N (maximum number of N is defined - * as MAX_N, and N should be >= 2). + * Julius now support N-gram for arbitrary N. * * Both direction of forward (left-to-right) N-gram and backward * (right-to-left) N-gram is supported. Since the final recognition @@ -57,7 +56,6 @@ * * このファイルには単語N-gram言語モデルを格納するための構造体定義が * 含まれています.Julius はN-gramにおいて任意の N をサポートしました. - * (N の上限値は MAX_N で定義されています) * * 通常の前向き (left-to-right) と後向き (right-to-left) の N-gram が * サポートされています.認識の最終パス(第2パス)は後向きに行われるので, @@ -97,7 +95,7 @@ * @author Akinobu LEE * @date Fri Feb 11 15:04:02 2005 * - * $Revision: 1.6 $ + * $Revision: 1.7 $ * */ /* @@ -113,8 +111,6 @@ #include #include -#define MAX_N 10 ///< Maximum number of N for N-gram - typedef unsigned int NNID; ///< Type definition for N-gram entry ID (full) #define NNID_INVALID 0xffffffff ///< Value to indicate no id (full) #define NNID_MAX 0xfffffffe ///< Value of maximum value (full) @@ -180,7 +176,7 @@ LOGPROB unk_num_log; ///< Log10 value of @a unk_num, used for calculating probability of unknown words boolean isopen; ///< TRUE if dictionary has unknown words, which does not appear in this N-gram - NGRAM_TUPLE_INFO d[MAX_N]; ///< Main body of N-gram info + NGRAM_TUPLE_INFO *d; ///< Main body of N-gram info /* for pass1 */ LOGPROB *bo_wt_1; ///< back-off weights for 2-gram on 1st pass From sumomo @ users.sourceforge.jp Sat Jul 4 23:11:43 2009 From: sumomo @ users.sourceforge.jp (sumomo @ users.sourceforge.jp) Date: Sat, 04 Jul 2009 23:11:43 +0900 Subject: [Julius-cvs 426] CVS update: julius4/libsent/src/util Message-ID: <1246716703.264100.9638.nullmailer@users.sourceforge.jp> Index: julius4/libsent/src/util/confout.c diff -u julius4/libsent/src/util/confout.c:1.5 julius4/libsent/src/util/confout.c:1.6 --- julius4/libsent/src/util/confout.c:1.5 Mon Jul 7 14:50:12 2008 +++ julius4/libsent/src/util/confout.c Sat Jul 4 23:11:43 2009 @@ -12,7 +12,7 @@ * @author Akinobu LEE * @date Thu Feb 17 15:34:39 2005 * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * */ /* @@ -80,7 +80,6 @@ confout_lm(FILE *strm) { fprintf(strm, " - Language Model\n"); - fprintf(strm, " Max. # of N for N-gram : %d\n", MAX_N); #ifdef CLASS_NGRAM fprintf(strm, " class N-gram support : yes\n"); #else From sumomo @ users.sourceforge.jp Sat Jul 4 23:11:43 2009 From: sumomo @ users.sourceforge.jp (sumomo @ users.sourceforge.jp) Date: Sat, 04 Jul 2009 23:11:43 +0900 Subject: [Julius-cvs 427] CVS update: julius4/libjulius/src Message-ID: <1246716703.011040.9613.nullmailer@users.sourceforge.jp> Index: julius4/libjulius/src/instance.c diff -u julius4/libjulius/src/instance.c:1.3 julius4/libjulius/src/instance.c:1.4 --- julius4/libjulius/src/instance.c:1.3 Thu Sep 25 14:00:06 2008 +++ julius4/libjulius/src/instance.c Sat Jul 4 23:11:42 2009 @@ -12,7 +12,7 @@ * @author Akinobu Lee * @date Sun Oct 28 18:06:20 2007 * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * */ /* @@ -299,15 +299,7 @@ { /* not free jconf, am, lm here */ /* free part of StackDecode work area */ -#ifdef CONFIDENVE_MEASURE -#ifdef CM_MULTIPLE_ALPHA - free(process->pass2.cmsumlist); -#endif -#ifdef CM_NBEST; - free(process->pass2.sentcm); - free(process->pass2.wordcm); -#endif -#endif + wchmm_fbs_free(process); /* free wchmm */ if (process->wchmm) wchmm_free(process->wchmm); /* free backtrellis */ Index: julius4/libjulius/src/m_fusion.c diff -u julius4/libjulius/src/m_fusion.c:1.13 julius4/libjulius/src/m_fusion.c:1.14 --- julius4/libjulius/src/m_fusion.c:1.13 Tue Feb 10 17:15:48 2009 +++ julius4/libjulius/src/m_fusion.c Sat Jul 4 23:11:42 2009 @@ -20,7 +20,7 @@ * @author Akinobu Lee * @date Thu May 12 13:31:47 2005 * - * $Revision: 1.13 $ + * $Revision: 1.14 $ * */ /* @@ -1115,6 +1115,9 @@ p->backtrellis = (BACKTRELLIS *)mymalloc(sizeof(BACKTRELLIS)); bt_init(p->backtrellis); + /* prepare work area for 2nd pass */ + wchmm_fbs_prepare(p); + jlog("STAT: SR%02d %s composed\n", sconf->id, sconf->name); if (sconf->sw.start_inactive) { Index: julius4/libjulius/src/ngram_decode.c diff -u julius4/libjulius/src/ngram_decode.c:1.3 julius4/libjulius/src/ngram_decode.c:1.4 --- julius4/libjulius/src/ngram_decode.c:1.3 Wed Feb 13 17:45:27 2008 +++ julius4/libjulius/src/ngram_decode.c Sat Jul 4 23:11:42 2009 @@ -35,7 +35,7 @@ * @author Akinobu Lee * @date Fri Jul 8 14:57:51 2005 * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * */ /* @@ -198,10 +198,9 @@ int w_old = WORD_INVALID; #endif int num; - WORD_ID cnword[MAX_N]; ///< Last two non-transparent words - WORD_ID cnwordrev[MAX_N]; ///< Last two non-transparent words int cnnum; ///< Num of found non-transparent words (<=2) int last_trans; ///< Num of skipped transparent words + StackDecode *dwrk; BACKTRELLIS *bt; WORD_INFO *winfo; @@ -215,6 +214,7 @@ lm_weight2 = r->config->lmp.lm_weight2; lm_penalty2 = r->config->lmp.lm_penalty2; lm_penalty_trans = r->config->lmp.lm_penalty_trans; + dwrk = &(r->pass2); /* set word contexts to cnword[] from 1 considering transparent words */ if (ngram) { @@ -222,7 +222,7 @@ last_trans = 0; for(i=hypo->seqnum-1;i>=0;i--) { if (! winfo->is_transparent[hypo->seq[i]]) { - cnword[cnnum+1] = hypo->seq[i]; + dwrk->cnword[cnnum+1] = hypo->seq[i]; cnnum++; if (cnnum >= ngram->n - 1) break; } else { @@ -231,14 +231,14 @@ } if (ngram->dir == DIR_RL) { for(i=0;icnwordrev[cnnum-1-i] = dwrk->cnword[i+1]; } } /* use ngram id */ if (ngram->dir == DIR_RL) { - for(i=0;iwton[cnwordrev[i]]; + for(i=0;icnwordrev[i] = winfo->wton[dwrk->cnwordrev[i]]; } else { - for(i=0;iwton[cnword[i+1]]; + for(i=0;icnword[i+1] = winfo->wton[dwrk->cnword[i+1]]; } } @@ -264,11 +264,11 @@ /* compute N-gram probability */ if (ngram->dir == DIR_RL) { /* just compute N-gram prob of the word candidate */ - cnwordrev[cnnum] = winfo->wton[w]; - rawscore = ngram_prob(ngram, cnnum + 1, cnwordrev); + dwrk->cnwordrev[cnnum] = winfo->wton[w]; + rawscore = ngram_prob(ngram, cnnum + 1, dwrk->cnwordrev); } else { - cnword[0] = winfo->wton[w]; - rawscore = ngram_forw2back(ngram, cnword, cnnum + 1); + dwrk->cnword[0] = winfo->wton[w]; + rawscore = ngram_forw2back(ngram, dwrk->cnword, cnnum + 1); } #ifdef CLASS_NGRAM rawscore += winfo->cprob[w]; Index: julius4/libjulius/src/search_bestfirst_main.c diff -u julius4/libjulius/src/search_bestfirst_main.c:1.8 julius4/libjulius/src/search_bestfirst_main.c:1.9 --- julius4/libjulius/src/search_bestfirst_main.c:1.8 Sun Nov 16 21:28:04 2008 +++ julius4/libjulius/src/search_bestfirst_main.c Sat Jul 4 23:11:42 2009 @@ -35,7 +35,7 @@ * @author Akinobu Lee * @date Thu Sep 08 11:51:12 2005 * - * $Revision: 1.8 $ + * $Revision: 1.9 $ * */ /* @@ -2264,4 +2264,94 @@ clear_stocker(dwrk); } +/** + * + * 第2パス用のワークエリアを確保・初期化する. + * + * ここで確保されるのは認識・パラメータに依らない値のみ. + * + * @param r [i/o] 認識処理インスタンス + * + * + * Initialize and allocate work area for 2nd pass. + * + * This function only contains input / parameter dependent initialization. + * + * @param r [in] recognition process instance + * + */ +void +wchmm_fbs_prepare(RecogProcess *r) +{ + StackDecode *dwrk; + dwrk = &(r->pass2); + + /* N-gram 用ワークエリアを確保 */ + /* malloc work area for N-gram */ + if (r->lmtype == LM_PROB && r->lm->ngram) { + dwrk->cnword = (WORD_ID *)mymalloc(sizeof(WORD_ID) * r->lm->ngram->n); + dwrk->cnwordrev = (WORD_ID *)mymalloc(sizeof(WORD_ID) * r->lm->ngram->n); + } else { + dwrk->cnword = dwrk->cnwordrev = NULL; + } + dwrk->stocker_root = NULL; +#ifdef CONFIDENVE_MEASURE +#ifdef CM_MULTIPLE_ALPHA + dwrk->cmsumlist = NULL; +#endif +#ifdef CM_NBEST; + dwrk->sentcm = NULL; + dwrk->wordcm = NULL; +#endif +#endif +} + +/** + * + * 第2パス用のワークエリアを解放する. + * + * ここで解放されるのは認識・パラメータに依らない値のみ. + * + * @param r [i/o] 認識処理インスタンス + * + * + * Free the work area for 2nd pass. + * + * This function only concerns input / parameter dependent work area. + * + * @param r [in] recognition process instance + * + */ +void +wchmm_fbs_free(RecogProcess *r) +{ + StackDecode *dwrk; + dwrk = &(r->pass2); + + if (r->lmtype == LM_PROB && r->lm->ngram) { + free(dwrk->cnword); + free(dwrk->cnwordrev); + dwrk->cnword = dwrk->cnwordrev = NULL; + } + +#ifdef CONFIDENVE_MEASURE +#ifdef CM_MULTIPLE_ALPHA + if (dwrk->cmsumlist) { + free(dwrk->cmsumlist); + dwrk->cmsumlist = NULL; + } +#endif +#ifdef CM_NBEST; + if (dwrk->sentcm) { + free(dwrk->sentcm); + dwrk->sentcm = NULL; + } + if (dwrk->wordcm) { + free(dwrk->wordcm); + dwrk->wordcm = NULL; + } +#endif +#endif +} + /* end of file */ From sumomo @ users.sourceforge.jp Sat Jul 4 23:11:43 2009 From: sumomo @ users.sourceforge.jp (sumomo @ users.sourceforge.jp) Date: Sat, 04 Jul 2009 23:11:43 +0900 Subject: [Julius-cvs 428] CVS update: julius4/libsent/src/ngram Message-ID: <1246716703.196096.9631.nullmailer@users.sourceforge.jp> Index: julius4/libsent/src/ngram/ngram_malloc.c diff -u julius4/libsent/src/ngram/ngram_malloc.c:1.3 julius4/libsent/src/ngram/ngram_malloc.c:1.4 --- julius4/libsent/src/ngram/ngram_malloc.c:1.3 Tue Feb 10 02:27:46 2009 +++ julius4/libsent/src/ngram/ngram_malloc.c Sat Jul 4 23:11:43 2009 @@ -12,7 +12,7 @@ * @author Akinobu LEE * @date Wed Feb 16 16:48:56 2005 * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * */ /* @@ -36,6 +36,8 @@ NGRAM_INFO *new; new = (NGRAM_INFO *)mymalloc(sizeof(NGRAM_INFO)); + new->n = 0; + new->d = NULL; new->bo_wt_1 = NULL; new->p_2 = NULL; new->bos_eos_swap = FALSE; @@ -84,8 +86,11 @@ if (ndata->bo_wt_1) free(ndata->bo_wt_1); if (ndata->p_2) free(ndata->p_2); /* free n-gram */ - for(i=0;in;i++) { - free_ngram_tuple(&(ndata->d[i])); + if (ndata->d) { + for(i=0;in;i++) { + free_ngram_tuple(&(ndata->d[i])); + } + free(ndata->d); } /* free name index tree */ free_ptree(ndata->root); Index: julius4/libsent/src/ngram/ngram_read_arpa.c diff -u julius4/libsent/src/ngram/ngram_read_arpa.c:1.15 julius4/libsent/src/ngram/ngram_read_arpa.c:1.16 --- julius4/libsent/src/ngram/ngram_read_arpa.c:1.15 Tue Feb 10 17:15:48 2009 +++ julius4/libsent/src/ngram/ngram_read_arpa.c Sat Jul 4 23:11:43 2009 @@ -20,7 +20,7 @@ * @author Akinobu LEE * @date Wed Feb 16 16:52:24 2005 * - * $Revision: 1.15 $ + * $Revision: 1.16 $ * */ /* @@ -30,7 +30,7 @@ * All rights reserved */ -/* $Id: ngram_read_arpa.c,v 1.15 2009/02/10 08:15:48 sumomo Exp $ */ +/* $Id: ngram_read_arpa.c,v 1.16 2009/07/04 14:11:43 sumomo Exp $ */ /* words should be alphabetically sorted */ @@ -45,33 +45,32 @@ * Set number of N-gram entries, for reading the first LR 2-gram. * * @param fp [in] file pointer - * @param num [out] set the values to this buffer + * @param numlist [out] set the values to this buffer (malloc) * * @return the value of N, or -1 on error. */ static int -get_total_info(FILE *fp, NNID num[]) +get_total_info(FILE *fp, NNID **numlist) { char *p; int n; int maxn; unsigned long entry_num; + int numnum; maxn = 0; + numnum = 10; + *numlist = (NNID *)mymalloc(sizeof(NNID) * numnum); + while (getl(buf, sizeof(buf), fp) != NULL && buf[0] != '\\') { if (strnmatch(buf, "ngram", 5)) { /* n-gram num */ - p = strtok(buf, "="); - n = p[strlen(p)-1] - '0'; - if (n > MAX_N) { - jlog("Error: too long N-gram (N=%d)\n", n); - jlog("Error: current maximum length of N-gram is set to %d\n", MAX_N); - jlog("Error: you can expand the limit by setting MAX_N in \"sent/ngram.h\"\n"); - return -1; - } - p = strtok(NULL, "="); + //p = strtok(buf, " ="); + //n = atoi(p); + //p = strtok(NULL, " ="); //entry_num = atol(p); - sscanf(p, "%lu", &entry_num); + //sscanf(p, "%lu", &entry_num); + sscanf(buf, "ngram %d = %lu", &n, &entry_num); /* check maximum number */ if (entry_num > NNID_MAX) { jlog("Error: too big %d-gram (exceeds %d bit)\n", n, sizeof(NNID) * 8); @@ -81,8 +80,12 @@ if (entry_num == 0) { jlog("Warning: empty %d-gram, skipped\n", n); } else { - num[n-1] = entry_num; if (maxn < n) maxn = n; + if (n >= numnum) { + numnum *= 2; + *numlist = (NNID *)myrealloc(*numlist, sizeof(NNID) * numnum); + } + (*numlist)[n-1] = entry_num; } } } @@ -330,8 +333,8 @@ set_ngram(FILE *fp, NGRAM_INFO *ndata, int n) { NNID i; - WORD_ID w[MAX_N]; - WORD_ID w_last[MAX_N]; + WORD_ID *w; + WORD_ID *w_last; LOGPROB p, bowt; NNID nnid; NNID cid, cid_last; @@ -346,6 +349,9 @@ return FALSE; } + w = (WORD_ID *)mymalloc(sizeof(WORD_ID) * n); + w_last = (WORD_ID *)mymalloc(sizeof(WORD_ID) * n); + t = &(ndata->d[n-1]); tprev = &(ndata->d[n-2]); @@ -391,6 +397,7 @@ /* N-gram probability */ if ((s = strtok(buf, DELM)) == NULL) { jlog("Error: ngram_read_arpa: %d-gram: failed to parse, corrupted or invalid data?\n", n); + free(w_last); free(w); return FALSE; } p = (LOGPROB)atof(s); @@ -398,6 +405,7 @@ for(i=0;iis24bit) { if (t->bgn_upper[cid] != NNID_INVALID_UPPER) { jlog("Error: ngram_read_arpa: %d-gram #%d: \"%s\": word order is not the same as 1-gram\n", n, nnid+1, pbuf); + free(w_last); free(w); return FALSE; } ntmp = nnid & 0xffff; @@ -449,6 +458,7 @@ } else { if (t->bgn[cid] != NNID_INVALID) { jlog("Error: ngram_read_arpa: %d-gram #%d: \"%s\": word order is not the same as 1-gram\n", n, nnid+1, pbuf); + free(w_last); free(w); return FALSE; } t->bgn[cid] = nnid; @@ -465,6 +475,7 @@ continue; } else if (w_last[n-1] != WORD_INVALID && w[n-1] < w_last[n-1]) { jlog("Error: ngram_read_arpa: %d-gram #%d: \"%s\": word order is not the same as 1-gram\n", n, nnid+1, pbuf); + free(w_last); free(w); return FALSE; } @@ -490,6 +501,7 @@ /* check total num */ if (nnid > t->totalnum) { jlog("Error: ngram_read_arpa: %d-gram: read num (%d) not match the header value (%d)\n", n, nnid, t->totalnum); + free(w_last); free(w); return FALSE; } } @@ -508,6 +520,7 @@ jlog("Stat: ngram_read_arpa: %d-gram read %d end\n", n, nnid); } + free(w_last); free(w); return ok_p; } @@ -525,7 +538,7 @@ ngram_read_arpa(FILE *fp, NGRAM_INFO *ndata, boolean addition) { int i, n; - NNID num[MAX_N]; + NNID *num; /* source file is not a binary N-gram */ ndata->from_bin = FALSE; @@ -537,15 +550,23 @@ if (addition) { /* reading additional forward 2-gram for the 1st pass */ + + if (ndata->n < 2) { + jlog("Error: base N-gram should be longer than 2-gram\n"); + return FALSE; + } + /* read n-gram total info */ - n = get_total_info(fp, num); + n = get_total_info(fp, &num); if (n == -1) { /* error */ + free(num); return FALSE; } /* check N limit */ if (n < 2) { jlog("Error: forward N-gram for pass1 is does not contain 2-gram\n"); + free(num); return FALSE; } if (n > 2) { @@ -558,6 +579,9 @@ jlog("Warning: ngram_read_arpa: %d-gram total num differ between forward N-gram and backward N-gram, may cause some error\n", i+1); } } + + free(num); + /* read additional 1-gram data */ if (!strnmatch(buf,"\\1-grams",8)) { jlog("Error: ngram_read_arpa: 1-gram not found for additional LR 2-gram\n"); @@ -581,14 +605,18 @@ } else { /* read n-gram total info */ - n = get_total_info(fp, num); + n = get_total_info(fp, &num); if (n == -1) { /* error */ + free(num); return FALSE; } jlog("Stat: ngram_read_arpa: this is %d-gram file\n", n); + ndata->d = (NGRAM_TUPLE_INFO *)mymalloc(sizeof(NGRAM_TUPLE_INFO) * n); + memset(ndata->d, 0, sizeof(NGRAM_TUPLE_INFO) * n); for(i=0;id[i].totalnum = num[i]; } + free(num); /* set word num */ if (ndata->d[0].totalnum > MAX_WORD_NUM) { Index: julius4/libsent/src/ngram/ngram_read_bin.c diff -u julius4/libsent/src/ngram/ngram_read_bin.c:1.6 julius4/libsent/src/ngram/ngram_read_bin.c:1.7 --- julius4/libsent/src/ngram/ngram_read_bin.c:1.6 Tue Feb 10 17:15:48 2009 +++ julius4/libsent/src/ngram/ngram_read_bin.c Sat Jul 4 23:11:43 2009 @@ -48,7 +48,7 @@ * @author Akinobu LEE * @date Wed Feb 16 17:12:08 2005 * - * $Revision: 1.6 $ + * $Revision: 1.7 $ * */ /* @@ -253,14 +253,9 @@ jlog("Stat: ngram_read_bin_v5: this is %s %d-gram file\n", (ndata->dir == DIR_LR) ? "forward" : "backward", ndata->n); - if (ndata->n > MAX_N) { - jlog("Error: ngram_read_bin_v5: too long N-gram (N=%d)\n", n); - jlog("Error: ngram_read_bin_v5: current maximum length of N-gram is set to %d\n", MAX_N); - jlog("Error: ngram_read_bin_v5: you can expand the limit by setting MAX_N in \"sent/ngram.h\"\n"); - return FALSE; - } - /* read total info and set max_word_num */ + ndata->d = (NGRAM_TUPLE_INFO *)mymalloc(sizeof(NGRAM_TUPLE_INFO) * ndata->n); + memset(ndata->d, 0, sizeof(NGRAM_TUPLE_INFO) * ndata->n); for(n=0;nn;n++) { rdn(fp, &(ndata->d[n].totalnum), sizeof(NNID), 1); } @@ -374,6 +369,8 @@ ndata->dir = DIR_RL; /* read total info and set max_word_num */ + ndata->d = (NGRAM_TUPLE_INFO *)mymalloc(sizeof(NGRAM_TUPLE_INFO) * ndata->n); + memset(ndata->d, 0, sizeof(NGRAM_TUPLE_INFO) * ndata->n); for(n=0;nn;n++) { rdn(fp, &(ndata->d[n].totalnum), sizeof(NNID), 1); } From sumomo @ users.sourceforge.jp Sun Jul 5 23:12:18 2009 From: sumomo @ users.sourceforge.jp (sumomo @ users.sourceforge.jp) Date: Sun, 05 Jul 2009 23:12:18 +0900 Subject: [Julius-cvs 429] CVS update: julius4/libjulius/include/julius Message-ID: <1246803138.975745.21373.nullmailer@users.sourceforge.jp> Index: julius4/libjulius/include/julius/recog.h diff -u julius4/libjulius/include/julius/recog.h:1.10 julius4/libjulius/include/julius/recog.h:1.11 --- julius4/libjulius/include/julius/recog.h:1.10 Sat Jul 4 23:11:42 2009 +++ julius4/libjulius/include/julius/recog.h Sun Jul 5 23:12:18 2009 @@ -70,7 +70,7 @@ * @author Akinobu Lee * @date Fri Feb 16 13:42:28 2007 * - * $Revision: 1.10 $ + * $Revision: 1.11 $ * */ /* @@ -424,10 +424,10 @@ boolean input_side_segment; ///< TRUE if segmentation requested by ad_read - unsigned int total_captured_len; - unsigned int last_trigger_sample; + unsigned int total_captured_len; ///< Total number of recorded samples from start until now + unsigned int last_trigger_sample; ///< Last speech area was triggeed at this sample - char current_input_name[MAXPATHLEN]; + char current_input_name[MAXPATHLEN]; ///< File or device name of current input } ADIn; From sumomo @ users.sourceforge.jp Sun Jul 5 23:12:19 2009 From: sumomo @ users.sourceforge.jp (sumomo @ users.sourceforge.jp) Date: Sun, 05 Jul 2009 23:12:19 +0900 Subject: [Julius-cvs 430] CVS update: julius4/libjulius/src Message-ID: <1246803139.053389.21381.nullmailer@users.sourceforge.jp> Index: julius4/libjulius/src/adin-cut.c diff -u julius4/libjulius/src/adin-cut.c:1.11 julius4/libjulius/src/adin-cut.c:1.12 --- julius4/libjulius/src/adin-cut.c:1.11 Fri Jul 3 02:05:20 2009 +++ julius4/libjulius/src/adin-cut.c Sun Jul 5 23:12:18 2009 @@ -95,7 +95,7 @@ * @author Akinobu LEE * @date Sat Feb 12 13:20:53 2005 * - * $Revision: 1.11 $ + * $Revision: 1.12 $ * */ /* @@ -194,8 +194,6 @@ adin->rehash = FALSE; - adin->total_captured_len = 0; - return TRUE; } @@ -1290,6 +1288,7 @@ { if (debug2_flag && a->input_side_segment) jlog("Stat: adin_begin: skip\n"); if (a->input_side_segment == FALSE) { + a->total_captured_len = 0; if (a->need_zmean) zmean_reset(); if (a->ad_begin != NULL) return(a->ad_begin(file_or_dev_name)); } From sumomo @ users.sourceforge.jp Mon Jul 6 23:54:40 2009 From: sumomo @ users.sourceforge.jp (sumomo @ users.sourceforge.jp) Date: Mon, 06 Jul 2009 23:54:40 +0900 Subject: [Julius-cvs 431] CVS update: julius4/plugin Message-ID: <1246892080.948919.21975.nullmailer@users.sourceforge.jp> Index: julius4/plugin/00readme-ja.txt diff -u julius4/plugin/00readme-ja.txt:1.1 julius4/plugin/00readme-ja.txt:1.2 --- julius4/plugin/00readme-ja.txt:1.1 Thu Sep 25 14:00:08 2008 +++ julius4/plugin/00readme-ja.txt Mon Jul 6 23:54:40 2009 @@ -25,11 +25,19 @@ ? ?????????????????? -?????????????? .jpi ??? -?????タ????????????????? -gcc ???????????????????????? +?????????????? .jpi ???タ?????????????? +????Linux ? cygwin ?????????????????????? - % gcc -shared -o adin_oss.jpi adin_oss.c + % gcc -shared -o result.jpi result.c + +cygwin ???????????????cygwin ?????????????? +-mno-cygwin ?????? + + % gcc -shared -mno-cygwin -o result.jpi result.c + +Mac OS X (darwin) ????????????????? + + % gcc -bundle -flat_namespace -undefined suppress -o result.jpi result.c ? Julius ??????????????? @@ -42,11 +50,25 @@ ??????????????w???????????? -? ????? +? ?????????result.jpi? + +result.c ???ッ?????????????????P????????? +Julius ????????????????????????? + + % cd plugin (????????) + % make result.jpi + % cd .. + % ./julius/julius ... -plugindir plugin + +???Mac OS X ???????? Makefile.darwin ???????? + + % make -f Makefile.darwin result.jpi -??? adin_oss.c ??OSS API ??????????????????? -Julius ????? "-input myadin" ???????? +? ?????????????????????? + +adin_oss.c ??OSS API ???????????????????? +Julius ????? "-input myadin" ???????? Julius ????????????????????????? % cd plugin (????????) @@ -57,3 +79,5 @@ ????????????? adintool ? adinrec ?????????D % ./adinrec/adinrec -plugindir plugin -input myadin + + Index: julius4/plugin/00readme.txt diff -u julius4/plugin/00readme.txt:1.1 julius4/plugin/00readme.txt:1.2 --- julius4/plugin/00readme.txt:1.1 Thu Sep 25 14:00:08 2008 +++ julius4/plugin/00readme.txt Mon Jul 6 23:54:40 2009 @@ -26,9 +26,18 @@ The source should be compiled into a dynamic shared object. The object file should have a suffix of ".jpi". -For example, you can compile "adin_oss.c" using gcc like this: - % gcc -shared -o adin_oss.jpi adin_oss.c +On Linux and cygwin, you can compile with gcc like this: + + % gcc -shared -o result.jpi result.c + +If you compile on cygwin and want it to run without cygwin, you can do + + % gcc -shared -mno-cygwin -o result.jpi result.c + +On Mac OS X: + + % gcc -bundle -flat_namespace -undefined suppress -o result.jpi result.c How to use Index: julius4/plugin/Makefile diff -u julius4/plugin/Makefile:1.2 julius4/plugin/Makefile:1.3 --- julius4/plugin/Makefile:1.2 Wed Mar 18 16:05:31 2009 +++ julius4/plugin/Makefile Mon Jul 6 23:54:40 2009 @@ -11,7 +11,7 @@ J_CFLAGS=-I../libsent/include -I../libjulius/include `../libsent/libsent-config --cflags` `../libjulius/libjulius-config --cflags` J_LDFLAGS=-L../libjulius `../libjulius/libjulius-config --libs` -L../libsent `../libsent/libsent-config --libs` -all: adin_oss.jpi audio_postprocess.jpi fvin.jpi feature_postprocess.jpi calcmix.jpi generic_callback.jpi result.jpi htkout.jpi +all: adin_oss.jpi audio_postprocess.jpi fvin.jpi feature_postprocess.jpi calcmix.jpi generic_callback.jpi result.jpi calcmix.jpi: calcmix.c $(CC) $(CFLAGS) $(J_CFLAGS) -o calcmix.jpi $(LDFLAGS) $(J_LDFLAGS) calcmix.c @@ -19,8 +19,5 @@ generic_callback.jpi: generic_callback.c $(CC) $(CFLAGS) $(J_CFLAGS) -o generic_callback.jpi generic_callback.c $(LDFLAGS) $(J_LDFLAGS) -htkout.jpi: htkout.c - $(CC) $(CFLAGS) $(J_CFLAGS) -o htkout.jpi htkout.c $(LDFLAGS) $(J_LDFLAGS) - clean: rm *.jpi Index: julius4/plugin/Makefile.darwin diff -u /dev/null julius4/plugin/Makefile.darwin:1.1 --- /dev/null Mon Jul 6 23:54:40 2009 +++ julius4/plugin/Makefile.darwin Mon Jul 6 23:54:40 2009 @@ -0,0 +1,23 @@ +SHELL=/bin/sh + +.SUFFIXES: +.SUFFIXES: .c .jpi +.c.jpi: + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< + +CC=gcc +CFLAGS=-bundle -flat_namespace -undefined suppress +LDFLAGS= +J_CFLAGS=-I../libsent/include -I../libjulius/include `../libsent/libsent-config --cflags` `../libjulius/libjulius-config --cflags` +J_LDFLAGS=-L../libjulius `../libjulius/libjulius-config --libs` -L../libsent `../libsent/libsent-config --libs` + +all: audio_postprocess.jpi fvin.jpi feature_postprocess.jpi calcmix.jpi generic_callback.jpi result.jpi + +calcmix.jpi: calcmix.c + $(CC) $(CFLAGS) $(J_CFLAGS) -o calcmix.jpi $(LDFLAGS) $(J_LDFLAGS) calcmix.c + +generic_callback.jpi: generic_callback.c + $(CC) $(CFLAGS) $(J_CFLAGS) -o generic_callback.jpi generic_callback.c $(LDFLAGS) $(J_LDFLAGS) + +clean: + rm *.jpi From sumomo @ users.sourceforge.jp Wed Jul 8 00:15:24 2009 From: sumomo @ users.sourceforge.jp (sumomo @ users.sourceforge.jp) Date: Wed, 08 Jul 2009 00:15:24 +0900 Subject: [Julius-cvs 432] CVS update: julius4/mkss Message-ID: <1246979724.457789.11646.nullmailer@users.sourceforge.jp> Index: julius4/mkss/mkss.c diff -u julius4/mkss/mkss.c:1.3 julius4/mkss/mkss.c:1.4 --- julius4/mkss/mkss.c:1.3 Fri May 15 12:22:53 2009 +++ julius4/mkss/mkss.c Wed Jul 8 00:15:24 2009 @@ -8,7 +8,7 @@ /* * mkss --- compute average spectrum of mic input for SS in Julius * - * $Id: mkss.c,v 1.3 2009/05/15 03:22:53 sumomo Exp $ + * $Id: mkss.c,v 1.4 2009/07/07 15:15:24 sumomo Exp $ * */ @@ -126,13 +126,16 @@ filename = argv[argc-1]; } + /* set default as same as "-input mic" */ + jconf->input.type = INPUT_WAVEFORM; + jconf->input.speech_input = SP_MIC; + jconf->input.device = SP_INPUT_DEFAULT; /* process config and load them */ if (j_config_load_args(jconf, argc-1, argv) == -1) { fprintf(stderr, "Error reading arguments\n"); return -1; } /* force some default values */ - jconf->input.speech_input = SP_MIC; /* mic input */ jconf->detect.silence_cut = 0; /* disable silence cut */ jconf->preprocess.strip_zero_sample = TRUE; /* strip zero samples */ jconf->detect.level_thres = 0; /* no VAD, record all */ From sumomo @ users.sourceforge.jp Wed Jul 29 18:32:36 2009 From: sumomo @ users.sourceforge.jp (sumomo @ users.sourceforge.jp) Date: Wed, 29 Jul 2009 18:32:36 +0900 Subject: [Julius-cvs 433] CVS update: julius4/libjulius/src Message-ID: <1248859956.404620.12817.nullmailer@users.sourceforge.jp> Index: julius4/libjulius/src/multi-gram.c diff -u julius4/libjulius/src/multi-gram.c:1.8 julius4/libjulius/src/multi-gram.c:1.9 --- julius4/libjulius/src/multi-gram.c:1.8 Fri Nov 14 13:12:12 2008 +++ julius4/libjulius/src/multi-gram.c Wed Jul 29 18:32:36 2009 @@ -47,7 +47,7 @@ * @author Akinobu Lee * @date Sat Jun 18 23:45:18 2005 * - * $Revision: 1.8 $ + * $Revision: 1.9 $ * */ /* @@ -244,7 +244,7 @@ * * 新たな文法を,文法リストに追加する. * 現在インスタンスが保持している文法のリストは lm->grammars に保存される. - * 追加した文法には,newbie, active のフラグがセットされ,次回の + * 追加した文法には,newbie と inactive のフラグがセットされ,次回の * 文法更新チェック時に更新対象となる. * * @param dfa [in] 追加登録する文法のDFA情報 @@ -258,7 +258,7 @@ * Add a new grammar to the current list of grammars. * The list of grammars which the LM instance keeps currently is * at lm->grammars. - * The new grammar is flaged at "newbie" and "active", to be treated + * The new grammar is flagged at "newbie" and "inactive", to be treated * properly at the next grammar update check. * * @param dfa [in] DFA information of the new grammar. @@ -289,9 +289,10 @@ new->id = lm->gram_maxid; new->dfa = dfa; new->winfo = winfo; - new->hook = MULTIGRAM_DEFAULT; + /* will be setup and activated after multigram_update() is called once */ + new->hook = MULTIGRAM_DEFAULT | MULTIGRAM_ACTIVATE; new->newbie = TRUE; /* need to setup */ - new->active = TRUE; /* default: active */ + new->active = FALSE; /* default: inactive */ /* the new grammar is now added to gramlist */ new->next = lm->grammars;