From 6c7495ba44d73c05b5c2fc6d0c0a9577a8ff5278 Mon Sep 17 00:00:00 2001 From: markster Date: Thu, 25 Jul 2002 21:07:47 +0000 Subject: Version 0.3.0 from FTP git-svn-id: http://svn.digium.com/svn/zaptel/trunk@95 5390a7c7-147a-4af0-8ec9-7488f05a26cb --- ztmonitor.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'ztmonitor.c') diff --git a/ztmonitor.c b/ztmonitor.c index d10f47e..2a6cca9 100755 --- a/ztmonitor.c +++ b/ztmonitor.c @@ -46,12 +46,18 @@ #endif #include +#define BUFFERS 4 + +#define FRAG_SIZE 8 + int audio_open(void) { int fd; int speed = 8000; int fmt = AFMT_S16_LE; int stereo = 0; + int fragsize = (BUFFERS << 16) | (FRAG_SIZE); + struct audio_buf_info ispace, ospace; fd = open("/dev/dsp", O_WRONLY); if (fd < 0) { fprintf(stderr, "Unable to open /dev/dsp: %s\n", strerror(errno)); @@ -77,6 +83,25 @@ int audio_open(void) } if (speed != 8000) fprintf(stderr, "Warning: Requested 8000 Hz, got %d\n", speed); + if (ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &fragsize)) { + fprintf(stderr, "Sound card won't let me set fragment size to 10 64-byte buffers (%x)\n" + "so sound may be choppy: %s.\n", fragsize, strerror(errno)); + } + bzero(&ispace, sizeof(ispace)); + bzero(&ospace, sizeof(ospace)); + + if (ioctl(fd, SNDCTL_DSP_GETISPACE, &ispace)) { + /* They don't support block size stuff, so just return but notify the user */ + fprintf(stderr, "Sound card won't let me know the input buffering...\n"); + } + if (ioctl(fd, SNDCTL_DSP_GETOSPACE, &ospace)) { + /* They don't support block size stuff, so just return but notify the user */ + fprintf(stderr, "Sound card won't let me know the output buffering...\n"); + } + fprintf(stderr, "New input space: %d of %d %d byte fragments (%d bytes left)\n", + ispace.fragments, ispace.fragstotal, ispace.fragsize, ispace.bytes); + fprintf(stderr, "New output space: %d of %d %d byte fragments (%d bytes left)\n", + ospace.fragments, ospace.fragstotal, ospace.fragsize, ospace.bytes); return fd; } -- cgit v1.2.3