Julius 4.2
plugin/adin_oss.c
説明を見る。
00001 
00060 /***************************************************************************/
00061 
00062 #include <stdio.h>
00063 #include <stdlib.h>
00064 #include <string.h>
00065 #include "plugin_defs.h"
00066 
00076 #define PLUGIN_TITLE "A/D-in plugin for Julius"
00077 
00089 #define INPUT_OPT "myadin"
00090 
00113 int
00114 initialize()
00115 {
00116   return 0;
00117 }
00118 
00155 int
00156 get_plugin_info(int opcode, char *buf, int buflen)
00157 {
00158   switch(opcode) {
00159   case 0:
00160     /* plugin description string */
00161     strncpy(buf, PLUGIN_TITLE, buflen);
00162     break;
00163   }
00164 
00165   return 0;
00166 }
00167 
00168 /************************************************************************/
00169 /************************************************************************/
00170 /* A/D-in plugin functions */
00171 
00200 void
00201 adin_get_optname(char *buf, int buflen)
00202 {
00203   strncpy(buf, INPUT_OPT, buflen);
00204 }
00205 
00310 int
00311 adin_get_configuration(int opcode)
00312 {
00313   /* For your convenience, UNCOMMENT ONE OF THEM BELOW that match your needs */
00314 
00315   /* typical values for live microphone/line input */
00316   switch(opcode) {
00317   case 0:       
00318     return 1;
00319   case 1:
00320     return 1;
00321   case 2:
00322     return 1;
00323   }
00324   /* typical values for offline file input */
00325   /* 
00326    * switch(opcode) {
00327    * case 0:       
00328    *   return 0;
00329    * case 1:
00330    *   return 0;
00331    * case 2:
00332    *   return 0;
00333    * }
00334    */
00335   /* typical setting for tcpip input */
00336   /* assuming speech to be segmented at sender */
00337   /* 
00338    * switch(opcode) {
00339    * case 0:       
00340    *   return 1;
00341    * case 1:
00342    *   return 0;
00343    * case 2:
00344    *   return 0;
00345    * }
00346    */
00347   /* typical setting for tcpip input */
00348   /* assuming receiving continous speech stream and segmented
00349      should be done at Julius side */
00350   /* 
00351    * switch(opcode) {
00352    * case 0:       
00353    *   return 1;
00354    * case 1:
00355    *   return 1;
00356    * case 2:
00357    *   return 0;
00358    * }
00359    */
00360 }
00361  
00362 
00363 /************************************************************************/
00364 
00365 #include <sys/types.h>
00366 #include <sys/stat.h>
00367 #include <fcntl.h>
00368 #include <sys/soundcard.h>
00369 static int audio_fd;
00370 static int freq;
00371 
00405 boolean
00406 adin_standby(int sfreq, void *dummy)
00407 {
00408   /* store the frequency */
00409   freq = sfreq;
00410   return TRUE;
00411 }
00412  
00444 boolean
00445 adin_open(char *pathname)
00446 {
00447   /* do open the device */
00448   int fmt;
00449   int stereo;
00450   int ret;
00451   int s;
00452   char buf[2];
00453 
00454   if ((audio_fd = open(pathname ? pathname : "/dev/dsp", O_RDONLY)) == -1) {
00455     printf("Error: cannot open %s\n", pathname ? pathname : "/dev/dsp");
00456     return FALSE;
00457   }
00458   fmt = AFMT_S16_LE;               /* 16bit signed (little endian) */
00459   if (ioctl(audio_fd, SNDCTL_DSP_SETFMT, &fmt) == -1) {
00460     printf("Error: failed set format to 16bit signed\n");
00461     return FALSE;
00462   }
00463   stereo = 0;                   /* mono */
00464   ret = ioctl(audio_fd, SNDCTL_DSP_STEREO, &stereo);
00465   if (ret == -1 || stereo != 0) {
00466     stereo = 1;
00467     ret = ioctl(audio_fd, SNDCTL_DSP_CHANNELS, &stereo);
00468     if (ret == -1 || stereo != 1) {
00469       printf("Error: failed to set monoral channel\n");
00470       return FALSE;
00471     }
00472   }
00473   s = freq;
00474   if (ioctl(audio_fd, SNDCTL_DSP_SPEED, &s) == -1) {
00475     printf("Erorr: failed to set sample rate to %dHz\n", freq);
00476     return FALSE;
00477   }
00478 
00479   /* start recording... */
00480   read(audio_fd, buf, 2);
00481 
00482   return(TRUE);
00483 }
00484 
00587 int
00588 adin_read(SP16 *buf, int sampnum)
00589 {
00590   audio_buf_info info;
00591   int size, cnt;
00592 
00593   /* get sample num that can be read without blocking */
00594   if (ioctl(audio_fd, SNDCTL_DSP_GETISPACE, &info) == -1) {
00595     printf("Error: adin_oss: failed to get number of samples in the buffer\n");
00596     return(ADIN_ERROR);
00597   }
00598   /* get them as much as possible */
00599   size = sampnum * sizeof(SP16);
00600   if (size > info.bytes) size = info.bytes;
00601   size &= ~ 1;          /* Force 16bit alignment */
00602   cnt = read(audio_fd, buf, size);
00603   if ( cnt < 0 ) {
00604     printf("Error: adin_oss: failed to read samples\n");
00605     return (ADIN_ERROR);
00606   }
00607   cnt /= sizeof(short);
00608     
00609   return(cnt);
00610 }
00611 
00647 boolean
00648 adin_close()
00649 {
00650   close(audio_fd);
00651   return TRUE;
00652 }
00653 
00654 /************************************************************************/
00655 
00700 boolean
00701 adin_terminate()
00702 {
00703   printf("terminate request\n");
00704   return TRUE;
00705 }
00706 
00756 boolean
00757 adin_pause()
00758 {
00759   printf("pause request\n");
00760   return TRUE;
00761 }
00762 
00803 boolean
00804 adin_resume()
00805 {
00806   printf("resume request\n");
00807   return TRUE;
00808 }
00809 
00825 char *
00826 adin_input_name()
00827 {
00828   printf("input name function was called\n");
00829   return("default");
00830 }
00831 
00832 
00833 /* end of file */