#include #include #include #include #include #include #include int main(int argn, char *arg[]) { int i; int16_t sample1[48000*2*2]; int16_t sample2[48000*2*2]; u_int8_t *ptr1, *ptr2; int ret, out, req; int fd; int tmp; ptr1 = (u_int8_t *)sample1; ptr2 = (u_int8_t *)sample2; fd = open("/dev/dsp", O_WRONLY | O_NONBLOCK); tmp=0; ioctl(fd, SNDCTL_DSP_RESET, &tmp); tmp=2; ioctl(fd, SNDCTL_DSP_STEREO, &tmp); tmp=16; ioctl(fd, SNDCTL_DSP_SAMPLESIZE, &tmp); tmp=48000; ioctl(fd, SNDCTL_DSP_SPEED, &tmp); usleep(500000); for (i=0;i<48000*2;i++) { sample1[i*2 ]=20000.0*sin(2.0*M_PI*440.0*((double)i)/48000.0); sample1[i*2+1]=20000.0*sin(2.0*M_PI*445.0*((double)i)/48000.0); } for (i=0;i<48000*2;i++) { sample2[i*2 ]=20000.0*sin(2.0*M_PI*660.0*((double)i)/48000.0); sample2[i*2+1]=20000.0*sin(2.0*M_PI*665.0*((double)i)/48000.0); } // play the first tone out = 0; req = 48000*2*2*2; while (out!=req) { ret = write(fd, ptr1+out, req-out); if (ret!=-1) out += ret; usleep(10); } // wait for dac drain do ioctl(fd, SNDCTL_DSP_GETODELAY, &tmp); while (tmp>0); // Wait more to be certain that it's drained usleep(500000); // Try to play the second tone out = 0; req = 48000*2*2*2; while (out!=req) { ret = write(fd, ptr2+out, req-out); if (ret!=-1) out += ret; usleep(10); } do ioctl(fd, SNDCTL_DSP_GETODELAY, &tmp); while (tmp>0); usleep(500000); close(fd); return 0; }