From bc03b620835886fb4de50ef1499200a9ca80a999 Mon Sep 17 00:00:00 2001 From: Simon Wilson Date: Wed, 15 Jun 2011 17:19:01 -0700 Subject: pcm: fix TODOs for 32 bit support --- pcm.c | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) (limited to 'pcm.c') diff --git a/pcm.c b/pcm.c index 1fab6f4..adc0495 100644 --- a/pcm.c +++ b/pcm.c @@ -165,6 +165,28 @@ static int oops(struct pcm *pcm, int e, const char *fmt, ...) return -1; } +static unsigned int pcm_format_to_alsa(enum pcm_format format) +{ + switch (format) { + case PCM_FORMAT_S32_LE: + return SNDRV_PCM_FORMAT_S32_LE; + default: + case PCM_FORMAT_S16_LE: + return SNDRV_PCM_FORMAT_S16_LE; + }; +} + +static unsigned int pcm_format_to_bits(enum pcm_format format) +{ + switch (format) { + case PCM_FORMAT_S32_LE: + return 32; + default: + case PCM_FORMAT_S16_LE: + return 16; + }; +} + int pcm_write(struct pcm *pcm, void *data, unsigned int count) { struct snd_xferi x; @@ -173,7 +195,8 @@ int pcm_write(struct pcm *pcm, void *data, unsigned int count) return -EINVAL; x.buf = data; - x.frames = count / (pcm->config.channels * 2); /* TODO: handle 32bit */ + x.frames = count / (pcm->config.channels * + pcm_format_to_bits(pcm->config.format) / 8); for (;;) { if (!pcm->running) { @@ -205,7 +228,8 @@ int pcm_read(struct pcm *pcm, void *data, unsigned int count) return -EINVAL; x.buf = data; - x.frames = count / (pcm->config.channels * 2); /* TODO: handle 32bit */ + x.frames = count / (pcm->config.channels * + pcm_format_to_bits(pcm->config.format) / 8); for (;;) { if (!pcm->running) { @@ -245,28 +269,6 @@ int pcm_close(struct pcm *pcm) return 0; } -static unsigned int pcm_format_to_alsa(enum pcm_format format) -{ - switch (format) { - case PCM_FORMAT_S32_LE: - return SNDRV_PCM_FORMAT_S32_LE; - default: - case PCM_FORMAT_S16_LE: - return SNDRV_PCM_FORMAT_S16_LE; - }; -} - -static unsigned int pcm_format_to_bits(enum pcm_format format) -{ - switch (format) { - case PCM_FORMAT_S32_LE: - return 32; - default: - case PCM_FORMAT_S16_LE: - return 16; - }; -} - struct pcm *pcm_open(unsigned int card, unsigned int device, unsigned int flags, struct pcm_config *config) { -- cgit v1.2.3