plugin/adin_oss.c

説明を見る。
00001 
00059 /***************************************************************************/
00060 
00061 #include <stdio.h>
00062 #include <stdlib.h>
00063 #include <string.h>
00064 #include "plugin_defs.h"
00065 
00075 #define PLUGIN_TITLE "A/D-in plugin for Julius"
00076 
00088 #define INPUT_OPT "myadin"
00089 
00112 int
00113 initialize()
00114 {
00115   return 0;
00116 }
00117 
00154 int
00155 get_plugin_info(int opcode, char *buf, int buflen)
00156 {
00157   switch(opcode) {
00158   case 0:
00159     /* plugin description string */
00160     strncpy(buf, PLUGIN_TITLE, buflen);
00161     break;
00162   }
00163 
00164   return 0;
00165 }
00166 
00167 /************************************************************************/
00168 /************************************************************************/
00169 /* A/D-in plugin functions */
00170 
00199 void
00200 adin_get_optname(char *buf, int buflen)
00201 {
00202   strncpy(buf, INPUT_OPT, buflen);
00203 }
00204 
00309 int
00310 adin_get_configuration(int opcode)
00311 {
00312   /* For your convenience, UNCOMMENT ONE OF THEM BELOW that match your needs */
00313 
00314   /* typical values for live microphone/line input */
00315   switch(opcode) {
00316   case 0:       
00317     return 1;
00318   case 1:
00319     return 1;
00320   case 2:
00321     return 1;
00322   }
00323   /* typical values for offline file input */
00324   /* 
00325    * switch(opcode) {
00326    * case 0:       
00327    *   return 0;
00328    * case 1:
00329    *   return 0;
00330    * case 2:
00331    *   return 0;
00332    * }
00333    */
00334   /* typical setting for tcpip input */
00335   /* assuming speech to be segmented at sender */
00336   /* 
00337    * switch(opcode) {
00338    * case 0:       
00339    *   return 1;
00340    * case 1:
00341    *   return 0;
00342    * case 2:
00343    *   return 0;
00344    * }
00345    */
00346   /* typical setting for tcpip input */
00347   /* assuming receiving continous speech stream and segmented
00348      should be done at Julius side */
00349   /* 
00350    * switch(opcode) {
00351    * case 0:       
00352    *   return 1;
00353    * case 1:
00354    *   return 1;
00355    * case 2:
00356    *   return 0;
00357    * }
00358    */
00359 }
00360  
00361 
00362 /************************************************************************/
00363 
00364 #include <sys/types.h>
00365 #include <sys/stat.h>
00366 #include <fcntl.h>
00367 #include <sys/soundcard.h>
00368 static int audio_fd;
00369 static int freq;
00370 
00404 boolean
00405 adin_standby(int sfreq, void *dummy)
00406 {
00407   /* store the frequency */
00408   freq = sfreq;
00409   return TRUE;
00410 }
00411  
00439 boolean
00440 adin_open()
00441 {
00442   /* do open the device */
00443   int fmt;
00444   int stereo;
00445   int ret;
00446   int s;
00447   char buf[2];
00448 
00449   if ((audio_fd = open("/dev/dsp", O_RDONLY)) == -1) {
00450     printf("Error: cannot open /dev/dsp\n");
00451     return FALSE;
00452   }
00453   fmt = AFMT_S16_LE;               /* 16bit signed (little endian) */
00454   if (ioctl(audio_fd, SNDCTL_DSP_SETFMT, &fmt) == -1) {
00455     printf("Error: failed set format to 16bit signed\n");
00456     return FALSE;
00457   }
00458   stereo = 0;                   /* mono */
00459   ret = ioctl(audio_fd, SNDCTL_DSP_STEREO, &stereo);
00460   if (ret == -1 || stereo != 0) {
00461     stereo = 1;
00462     ret = ioctl(audio_fd, SNDCTL_DSP_CHANNELS, &stereo);
00463     if (ret == -1 || stereo != 1) {
00464       printf("Error: failed to set monoral channel\n");
00465       return FALSE;
00466     }
00467   }
00468   s = freq;
00469   if (ioctl(audio_fd, SNDCTL_DSP_SPEED, &s) == -1) {
00470     printf("Erorr: failed to set sample rate to %dHz\n", freq);
00471     return FALSE;
00472   }
00473 
00474   /* start recording... */
00475   read(audio_fd, buf, 2);
00476 
00477   return(TRUE);
00478 }
00479 
00582 int
00583 adin_read(SP16 *buf, int sampnum)
00584 {
00585   audio_buf_info info;
00586   int size, cnt;
00587 
00588   /* get sample num that can be read without blocking */
00589   if (ioctl(audio_fd, SNDCTL_DSP_GETISPACE, &info) == -1) {
00590     printf("Error: adin_oss: failed to get number of samples in the buffer\n");
00591     return(ADIN_ERROR);
00592   }
00593   /* get them as much as possible */
00594   size = sampnum * sizeof(SP16);
00595   if (size > info.bytes) size = info.bytes;
00596   size &= ~ 1;          /* Force 16bit alignment */
00597   cnt = read(audio_fd, buf, size);
00598   if ( cnt < 0 ) {
00599     printf("Error: adin_oss: failed to read samples\n");
00600     return (ADIN_ERROR);
00601   }
00602   cnt /= sizeof(short);
00603     
00604   return(cnt);
00605 }
00606 
00642 boolean
00643 adin_close()
00644 {
00645   close(audio_fd);
00646   return TRUE;
00647 }
00648 
00649 /************************************************************************/
00650 
00695 boolean
00696 adin_terminate()
00697 {
00698   printf("terminate request\n");
00699   return TRUE;
00700 }
00701 
00751 boolean
00752 adin_pause()
00753 {
00754   printf("pause request\n");
00755   return TRUE;
00756 }
00757 
00798 boolean
00799 adin_resume()
00800 {
00801   printf("resume request\n");
00802   return TRUE;
00803 }
00804 
00805 /* end of file */

Juliusに対してThu Jul 23 12:16:23 2009に生成されました。  doxygen 1.5.1