aboutsummaryrefslogtreecommitdiff
path: root/pcm.c
diff options
context:
space:
mode:
authorSimon Wilson <simonwilson@google.com>2011-06-15 17:19:01 -0700
committerSimon Wilson <simonwilson@google.com>2011-06-15 17:19:01 -0700
commitbc03b620835886fb4de50ef1499200a9ca80a999 (patch)
tree5d70a8b34377d4dd3ce945b6731da154e9b9a263 /pcm.c
parent193b1c3b26493078d5898a5fb7208e8c495f40f2 (diff)
pcm: fix TODOs for 32 bit support
Diffstat (limited to 'pcm.c')
-rw-r--r--pcm.c50
1 files changed, 26 insertions, 24 deletions
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)
{