Patchwork [2/2] alsaaudio: add endianness support for VoiceIn

login
register
mail settings
Submitter Michael Walle
Date Jan. 8, 2011, 3:28 p.m.
Message ID <1294500504-10263-2-git-send-email-michael@walle.cc>
Download mbox | patch
Permalink /patch/77957/
State New
Headers show

Comments

Michael Walle - Jan. 8, 2011, 3:28 p.m.
Signed-off-by: Michael Walle <michael@walle.cc>
---
 audio/alsaaudio.c |   26 +++++++++++++++++++-------
 1 files changed, 19 insertions(+), 7 deletions(-)

Patch

diff --git a/audio/alsaaudio.c b/audio/alsaaudio.c
index 0741203..a86aa08 100644
--- a/audio/alsaaudio.c
+++ b/audio/alsaaudio.c
@@ -318,7 +318,7 @@  static int alsa_write (SWVoiceOut *sw, void *buf, int len)
     return audio_pcm_sw_write (sw, buf, len);
 }
 
-static snd_pcm_format_t aud_to_alsafmt (audfmt_e fmt)
+static snd_pcm_format_t aud_to_alsafmt (audfmt_e fmt, int endianness)
 {
     switch (fmt) {
     case AUD_FMT_S8:
@@ -328,16 +328,28 @@  static snd_pcm_format_t aud_to_alsafmt (audfmt_e fmt)
         return SND_PCM_FORMAT_U8;
 
     case AUD_FMT_S16:
-        return SND_PCM_FORMAT_S16_LE;
+        if (endianness)
+            return SND_PCM_FORMAT_S16_BE;
+        else
+            return SND_PCM_FORMAT_S16_LE;
 
     case AUD_FMT_U16:
-        return SND_PCM_FORMAT_U16_LE;
+        if (endianness)
+            return SND_PCM_FORMAT_U16_BE;
+        else
+            return SND_PCM_FORMAT_U16_LE;
 
     case AUD_FMT_S32:
-        return SND_PCM_FORMAT_S32_LE;
+        if (endianness)
+            return SND_PCM_FORMAT_S32_BE;
+        else
+            return SND_PCM_FORMAT_S32_LE;
 
     case AUD_FMT_U32:
-        return SND_PCM_FORMAT_U32_LE;
+        if (endianness)
+            return SND_PCM_FORMAT_U32_BE;
+        else
+            return SND_PCM_FORMAT_U32_LE;
 
     default:
         dolog ("Internal logic error: Bad audio format %d\n", fmt);
@@ -809,7 +821,7 @@  static int alsa_init_out (HWVoiceOut *hw, struct audsettings *as)
     snd_pcm_t *handle;
     struct audsettings obt_as;
 
-    req.fmt = aud_to_alsafmt (as->fmt);
+    req.fmt = aud_to_alsafmt (as->fmt, as->endianness);
     req.freq = as->freq;
     req.nchannels = as->nchannels;
     req.period_size = conf.period_size_out;
@@ -918,7 +930,7 @@  static int alsa_init_in (HWVoiceIn *hw, struct audsettings *as)
     snd_pcm_t *handle;
     struct audsettings obt_as;
 
-    req.fmt = aud_to_alsafmt (as->fmt);
+    req.fmt = aud_to_alsafmt (as->fmt, as->endianness);
     req.freq = as->freq;
     req.nchannels = as->nchannels;
     req.period_size = conf.period_size_in;