diff options
author | Lennart Poettering <lennart@poettering.net> | 2004-06-23 23:40:39 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2004-06-23 23:40:39 +0000 |
commit | c050d7254c13c22baafb71c127e56eb1d5f6ffdb (patch) | |
tree | 54d9104820dfaa7a530f8deabb88fb2c74bbb8ab /src/oss-util.c | |
parent | b9e0fa84f3a327ffc395ac184686a78a95c2bb3b (diff) |
rename oss.[ch] to oss-util.[ch]
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@34 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'src/oss-util.c')
-rw-r--r-- | src/oss-util.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/oss-util.c b/src/oss-util.c new file mode 100644 index 00000000..02bf8cd1 --- /dev/null +++ b/src/oss-util.c @@ -0,0 +1,48 @@ +#include <assert.h> +#include <sys/soundcard.h> +#include <sys/ioctl.h> +#include <stdio.h> +#include <errno.h> +#include <string.h> + +#include "oss.h" + +int oss_auto_format(int fd, struct pa_sample_spec *ss) { + int format, channels, speed; + + assert(fd >= 0 && ss); + + format = AFMT_S16_NE; + if (ioctl(fd, SNDCTL_DSP_SETFMT, &format) < 0 || format != AFMT_S16_NE) { + int f = AFMT_S16_NE == AFMT_S16_LE ? AFMT_S16_BE : AFMT_S16_LE; + format = f; + if (ioctl(fd, SNDCTL_DSP_SETFMT, &format) < 0 || format != f) { + format = AFMT_U8; + if (ioctl(fd, SNDCTL_DSP_SETFMT, &format) < 0 || format != AFMT_U8) { + fprintf(stderr, "SNDCTL_DSP_SETFMT: %s\n", format != AFMT_U8 ? "No supported sample format" : strerror(errno)); + return -1; + } else + ss->format = SAMPLE_U8; + } else + ss->format = f == AFMT_S16_LE ? SAMPLE_S16LE : SAMPLE_S16BE; + } else + ss->format = SAMPLE_S16NE; + + channels = 2; + if (ioctl(fd, SNDCTL_DSP_CHANNELS, &channels) < 0) { + fprintf(stderr, "SNDCTL_DSP_CHANNELS: %s\n", strerror(errno)); + return -1; + } + assert(channels); + ss->channels = channels; + + speed = 44100; + if (ioctl(fd, SNDCTL_DSP_SPEED, &speed) < 0) { + fprintf(stderr, "SNDCTL_DSP_SPEED: %s\n", strerror(errno)); + return -1; + } + assert(speed); + ss->rate = speed; + + return 0; +} |