⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adin_mic_sun4.c

📁 julius version 4.12.about sound recognition.
💻 C
字号:
/** * @file   adin_mic_sun4.c *  * <JA> * @brief  マイク掐蜗 (Sun4) * * SunOS 4.x でマイク掐蜗を蝗脱するための你レベル不兰掐蜗簇眶ですˉ * SunOS 4.x のマシンではデフォルトでこのファイルが蝗脱されますˉ * * Sun SunOS 4.1.3 で瓢侯澄千をしていますˉSolaris2.x については * adin_mic_sol2.c を告枉布さいˉ * * 弹瓢稿オ〖ディオ掐蜗はマイクに极瓢弄に磊り仑わり·ボリュ〖ムは * J_DEF_VOLUME の猛に肋年されますˉ * * デフォルトのデバイス叹は "/dev/audio" ですˉ茨董恃眶 AUDIODEV に * デバイス叹を回年することで·戮のデバイス叹を蝗脱できますˉ * </JA> * <EN> * @brief  Microphone input on Sun4 * * Low level I/O functions for microphone input on SunOS 4.x machines. * This file is used as default on SunOS 4.x machines. * * Tested on SunOS 4.1.3. * * The microphone input device will be automatically selected by Julius * on startup, and volume will be set to J_DEF_VOLUME. *  * The default device name is "/dev/audio", which can be changed by setting * environment variable AUDIODEV. * </EN> *  * @author Akinobu LEE * @date   Sun Feb 13 18:56:13 2005 * * $Revision: 1.2 $ *  *//* * Copyright (c) 1991-2007 Kawahara Lab., Kyoto University * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology * Copyright (c) 2005-2007 Julius project team, Nagoya Institute of Technology * All rights reserved */#define J_DEF_VOLUME 20		///< Recording volume (range=0-99)#include <sent/stddefs.h>#include <sent/adin.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <errno.h>#include <stropts.h>#include <poll.h>/// Default device name, can be overridden by AUDIODEV environment variable#define DEFAULT_DEVICE "/dev/audio"/// Default volumestatic int volume = J_DEF_VOLUME;/* sound header */#include <multimedia/libaudio.h>/* see man audio_device(3) */#include <multimedia/audio_device.h>static int afd;			///< Audio file descriptorstatic struct pollfd pfd;	///< File descriptor for pollingstatic audio_info_t ainfo;	///< Audio info/**  * Device initialization: check device capability and open for recording. *  * @param sfreq [in] required sampling frequency. * @param dummy [in] a dummy data *  * @return TRUE on success, FALSE on failure. */booleanadin_mic_standby(int sfreq, void *dummy){  char *defaultdev = DEFAULT_DEVICE;  char *devname;  Audio_hdr Dev_hdr, old_hdr;  double vol;  /* get device name if specified in $AUDIODEV */  if ((devname = getenv("AUDIODEV")) == NULL) {    devname = defaultdev;    jlog("Stat: adin_sun4: device name = %s\n", devname);  } else {    jlog("Stat: adin_sun4: device name obtained from AUDIODEV: %s\n", devname);  }  /* open the device */  if ((afd = open(devname, O_RDONLY)) == -1) {    if (errno == EBUSY) {      jlog("Error: adin_sun4: audio device %s is busy\n", devname);      return(FALSE);    } else {      jlog("Error: adin_sun4: unable to open %s\n",devname);      return(FALSE);    }  }  /* set recording port to microphone */  AUDIO_INITINFO(&ainfo);  ainfo.record.port = AUDIO_MICROPHONE;  if (ioctl(afd, AUDIO_SETINFO, &ainfo) == -1) {    jlog("Error: adin_sun4: failed to set recording port\n");    return(FALSE);  }  /* set recording parameters */  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.samples_per_unit = 1; /* ? I don't know this param. ? */  Dev_hdr.bytes_per_unit = 2;  Dev_hdr.channels = 1;  Dev_hdr.encoding = AUDIO_ENCODING_LINEAR;  if (audio_set_record_config(afd, &Dev_hdr) != AUDIO_SUCCESS) {    jlog("Error: adin_sun4: failed to set recording config\n"); return(FALSE);  }  /* set volume */  vol = (float)volume / (float)100;  if (audio_set_record_gain(afd, &vol) != AUDIO_SUCCESS) {    jlog("Error: adin_sun4: failed to set recording volume\n");    return(FALSE);  }  /* flush buffer */  if((ioctl(afd , I_FLUSH , FLUSHRW)) == -1) {    jlog("Error: adin_sun4: cannot flush input buffer\n");    return(FALSE);  }    /* setup polling */  pfd.fd = afd;  pfd.events = POLLIN;  /* pause transfer */  if (audio_pause_record(afd) == AUDIO_ERR_NOEFFECT) {    jlog("Error: adin_sun4: cannot pause audio\n");    return(FALSE);  }  return(TRUE);}/**  * Start recording. *  * @return TRUE on success, FALSE on failure. */booleanadin_mic_begin(){  /* resume input */  if (audio_resume_record(afd) == AUDIO_ERR_NOEFFECT) {    jlog("Error: adin_sun4: cannot resume audio\n");    return(FALSE);  }  return(TRUE);}/**  * Stop recording. *  * @return TRUE on success, FALSE on failure. */booleanadin_mic_end(){  /* pause input */  if (audio_pause_record(afd) == AUDIO_ERR_NOEFFECT) {    jlog("Error: adin_sun4: cannot pause audio\n");    return(FALSE);  }  return(TRUE);}/** * @brief  Read samples from device *  * Try to read @a sampnum samples and returns actual number of recorded * samples currently available.  This function will block until * at least one sample can be obtained. *  * @param buf [out] samples obtained in this function * @param sampnum [in] wanted number of samples to be read *  * @return actural number of read samples, -2 if an error occured. */intadin_mic_read(SP16 *buf, int sampnum){  int bytes;  int len;  /* SunOS4.x needs special dealing when no samples are found */  len = sampnum * sizeof(SP16);  bytes = 0;  while(bytes < len) {    bytes = read(afd, buf, len);    if (bytes < 0) {      if (errno != EAGAIN) {	/* error */	jlog("Erorr: adin_sun4: failed to read sample\n");	return(-2);      } else {			/* retry */	poll(&pfd, 1L, -1);      }    }  }  if (bytes < 0) {    jlog("Error: adin_sun4: failed to read sample\n");    return(-2);  }  return(bytes / sizeof(SP16)); /* success */}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -