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
00160 strncpy(buf, PLUGIN_TITLE, buflen);
00161 break;
00162 }
00163
00164 return 0;
00165 }
00166
00167
00168
00169
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
00313
00314
00315 switch(opcode) {
00316 case 0:
00317 return 1;
00318 case 1:
00319 return 1;
00320 case 2:
00321 return 1;
00322 }
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
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
00408 freq = sfreq;
00409 return TRUE;
00410 }
00411
00439 boolean
00440 adin_open()
00441 {
00442
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;
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;
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
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
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
00594 size = sampnum * sizeof(SP16);
00595 if (size > info.bytes) size = info.bytes;
00596 size &= ~ 1;
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