#include #include #include #include #include #include #include #include extern const char *__progname; static int afd = -1; static signed short int data[65536]; static int ptr; static int len; /* QSIZE should be a bit more than enough samples to fill up DELAY at 8kHz */ #define QSIZE 250 /* samples */ #define DELAY 20000 /* usec */ static int scount[QSIZE]; static void readsound(void) { int c1; int c2; len = 0; ptr = 0; while (1) { if (len >= 65536) break; c1 = getchar(); if (c1 == EOF) break; c2 = getchar(); if (c2 == EOF) break; data[len++] = (c1 << 8) | c2; } bzero(&scount,sizeof(scount)); } /* mulaw seems to be a floating-point format that splits up eight bits as sign(1), exponent(3), mantissa(4) - and for then some incomprehensible reason bit-complements the whole thing. */ static unsigned char linear_to_ulaw(signed long int linear) { unsigned char sign; unsigned char exp; unsigned char mant; static unsigned exptbl[128] = { 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4, 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 }; if (linear < 0) { linear = - linear; sign = 0x80; } else { sign = 0; } linear += 0x84; /* where does this magic number come from?? */ if (linear > 32767) linear = 32767; exp = exptbl[linear>>8]; mant = (linear >> (exp+3)) & 0xf; return(~(sign|(exp<<4)|mant)); } static void playsome(int n) { signed long int linear[QSIZE]; unsigned char ulaw[QSIZE]; int i; int j; int c; if (n < 1) return; for (i=0;i= c) j = 0; } ptr = j; for (i=0;i 50) { fprintf(stderr,"%s: audio blocksize too large\n",__progname); exit(1); } while (1) { if (ioctl(afd,AUDIO_GETINFO,&ai) < 0) { fprintf(stderr,"%s: AUDIO_GETINFO: %s\n",__progname,strerror(errno)); exit(1); } playsome(QSIZE-ai.play.seek); wait.tv_sec = 0; wait.tv_usec = DELAY; if (select(1,0,0,0,&wait) < 0) { if (errno == EINTR) continue; fprintf(stderr,"%s: select: %s\n",__progname,strerror(errno)); exit(1); } } }