メインページ | モジュール | データ構造 | Directories | ファイル一覧 | データフィールド | グローバル | 関連ページ

adin_mic_sun4.c

説明を見る。
00001 
00039 /*
00040  * Copyright (c) 1991-2006 Kawahara Lab., Kyoto University
00041  * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology
00042  * Copyright (c) 2005-2006 Julius project team, Nagoya Institute of Technology, Nagoya Institute of Technology
00043  * All rights reserved
00044  */
00045 
00046 #define J_DEF_VOLUME 20         
00047 
00048 #include <sent/stddefs.h>
00049 #include <sent/adin.h>
00050 
00051 #include <sys/types.h>
00052 #include <sys/stat.h>
00053 #include <fcntl.h>
00054 #include <errno.h>
00055 #include <stropts.h>
00056 #include <poll.h>
00057 
00059 #define DEFAULT_DEVICE "/dev/audio"
00060 
00061 static int volume = J_DEF_VOLUME;
00062 
00063 /* sound header */
00064 #include <multimedia/libaudio.h>/* see man audio_device(3) */
00065 #include <multimedia/audio_device.h>
00066 static int afd;                 
00067 static struct pollfd pfd;       
00068 static audio_info_t ainfo;      
00069 
00078 boolean
00079 adin_mic_standby(int sfreq, void *dummy)
00080 {
00081   char *defaultdev = DEFAULT_DEVICE;
00082   char *devname;
00083   Audio_hdr Dev_hdr, old_hdr;
00084   double vol;
00085 
00086   /* get device name if specified in $AUDIODEV */
00087   if ((devname = getenv("AUDIODEV")) == NULL) {
00088     devname = defaultdev;
00089   }
00090 
00091   /* open the device */
00092   if ((afd = open(devname, O_RDONLY)) == -1) {
00093     if (errno == EBUSY) {
00094       j_printerr("audio device %s is busy\n", devname);
00095       return(FALSE);
00096     } else {
00097       j_printerr("unable to open %s\n",devname);
00098       return(FALSE);
00099     }
00100   }
00101 
00102   /* set recording port to microphone */
00103   AUDIO_INITINFO(&ainfo);
00104   ainfo.record.port = AUDIO_MICROPHONE;
00105   if (ioctl(afd, AUDIO_SETINFO, &ainfo) == -1) {
00106     perror("Audio_set_info");
00107     return(FALSE);
00108   }
00109 
00110   /* set recording parameters */
00111   if (audio_get_record_config(afd, &Dev_hdr) != AUDIO_SUCCESS) {
00112     j_printerr("get_config error\n"); return(FALSE);
00113   }
00114   Dev_hdr.sample_rate = sfreq;
00115   Dev_hdr.samples_per_unit = 1; /* ? I don't know this param. ? */
00116   Dev_hdr.bytes_per_unit = 2;
00117   Dev_hdr.channels = 1;
00118   Dev_hdr.encoding = AUDIO_ENCODING_LINEAR;
00119   if (audio_set_record_config(afd, &Dev_hdr) != AUDIO_SUCCESS) {
00120     j_printerr("set_config error\n"); return(FALSE);
00121   }
00122 
00123   /* set volume */
00124   vol = (float)volume / (float)100;
00125   if (audio_set_record_gain(afd, &vol) != AUDIO_SUCCESS) {
00126     j_printerr("cannot set record volume\n");
00127     return(FALSE);
00128   }
00129 
00130   /* flush buffer */
00131   if((ioctl(afd , I_FLUSH , FLUSHRW)) == -1) {
00132     j_printerr("cannot flush input buffer\n");
00133     return(FALSE);
00134   }
00135   
00136   /* setup polling */
00137   pfd.fd = afd;
00138   pfd.events = POLLIN;
00139 
00140   /* pause transfer */
00141   if (audio_pause_record(afd) == AUDIO_ERR_NOEFFECT) {
00142     j_printerr("cannot pause audio\n");
00143     return(FALSE);
00144   }
00145 
00146   return(TRUE);
00147 }
00148 
00154 boolean
00155 adin_mic_start()
00156 {
00157   /* resume input */
00158   if (audio_resume_record(afd) == AUDIO_ERR_NOEFFECT) {
00159     j_printerr("cannot resume audio\n");
00160     return(FALSE);
00161   }
00162   return(TRUE);
00163 }
00164 
00170 boolean
00171 adin_mic_stop()
00172 {
00173   /* pause input */
00174   if (audio_pause_record(afd) == AUDIO_ERR_NOEFFECT) {
00175     j_printerr("cannot pause audio\n");
00176     return(FALSE);
00177   }
00178   return(TRUE);
00179 }
00180 
00193 int
00194 adin_mic_read(SP16 *buf, int sampnum)
00195 {
00196   int bytes;
00197   int len;
00198 
00199   /* SunOS4.x needs special dealing when no samples are found */
00200   len = sampnum * sizeof(SP16);
00201   bytes = 0;
00202   while(bytes < len) {
00203     bytes = read(afd, buf, len);
00204     if (bytes < 0) {
00205       if (errno != EAGAIN) {    /* error */
00206         perror("adin_mic_read: failed to read sample");
00207         return(-2);
00208       } else {                  /* retry */
00209         poll(&pfd, 1L, -1);
00210       }
00211     }
00212   }
00213   if (bytes < 0) {
00214     perror("adin_mic_read: failed to read sample");
00215     return(-2);
00216   }
00217   return(bytes / sizeof(SP16)); /* success */
00218 }

Juliusに対してTue Mar 28 16:20:50 2006に生成されました。  doxygen 1.4.2