All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] qemu support for S32 and U32 alsa output
@ 2007-02-06 23:24 Lonnie Mendez
  2007-02-10 23:33 ` Thiemo Seufer
  0 siblings, 1 reply; 3+ messages in thread
From: Lonnie Mendez @ 2007-02-06 23:24 UTC (permalink / raw)
  To: qemu-devel; +Cc: infernix

[-- Attachment #1: Type: text/plain, Size: 569 bytes --]

Forwarding this for a user who is not subscribed.
---

Hi,

My M-Audio soundcard (ice1712) did not play nice with qemu's alsa output
since it only accepted S32_LE. I asked some weirdo who has nothing
better to do at 6:50 AM in the #qemu channel on freenode for help, and
he wrote the attached patch.

I've patched this against CVS and also against 0.8.2 with some manual
code hacking (different line offsets), and hereby kindly request that
someone knowledgeable takes a look at it so it can be committed.

Thanks in advance; the patch is attached.

Regards,

infernix

[-- Attachment #2: S32_FMT_for_qemu_cvs_20070206.patch --]
[-- Type: text/x-patch, Size: 15987 bytes --]

? .gdb_history
Index: Makefile.target
===================================================================
RCS file: /cvsroot/qemu/qemu/Makefile.target,v
retrieving revision 1.144
diff -u -r1.144 Makefile.target
--- Makefile.target	2 Feb 2007 03:13:18 -0000	1.144
+++ Makefile.target	6 Feb 2007 03:29:32 -0000
@@ -583,8 +583,8 @@
 include .depend
 endif
 
-ifeq (1, 0)
+ifeq (1, 1)
 audio.o sdlaudio.o dsoundaudio.o ossaudio.o wavaudio.o noaudio.o \
 fmodaudio.o alsaaudio.o mixeng.o sb16.o es1370.o gus.o adlib.o: \
-CFLAGS := $(CFLAGS) -Wall -Werror -W -Wsign-compare
+CFLAGS := $(CFLAGS) -O0 -g # -Wall -Werror -W -Wsign-compare -O0 -g
 endif
Index: audio/alsaaudio.c
===================================================================
RCS file: /cvsroot/qemu/qemu/audio/alsaaudio.c,v
retrieving revision 1.7
diff -u -r1.7 alsaaudio.c
--- audio/alsaaudio.c	4 Jul 2006 21:47:22 -0000	1.7
+++ audio/alsaaudio.c	6 Feb 2007 03:29:32 -0000
@@ -157,6 +157,12 @@
     case AUD_FMT_U16:
         return SND_PCM_FORMAT_U16_LE;
 
+    case AUD_FMT_S32:
+        return SND_PCM_FORMAT_S32_LE;
+
+    case AUD_FMT_U32:
+        return SND_PCM_FORMAT_U32_LE;
+
     default:
         dolog ("Internal logic error: Bad audio format %d\n", fmt);
 #ifdef DEBUG_AUDIO
@@ -199,6 +205,26 @@
         *fmt = AUD_FMT_U16;
         break;
 
+    case SND_PCM_FORMAT_S32_LE:
+        *endianness = 0;
+        *fmt = AUD_FMT_S32;
+        break;
+
+    case SND_PCM_FORMAT_U32_LE:
+        *endianness = 0;
+        *fmt = AUD_FMT_U32;
+        break;
+
+    case SND_PCM_FORMAT_S32_BE:
+        *endianness = 1;
+        *fmt = AUD_FMT_S32;
+        break;
+
+    case SND_PCM_FORMAT_U32_BE:
+        *endianness = 1;
+        *fmt = AUD_FMT_U32;
+        break;
+
     default:
         dolog ("Unrecognized audio format %d\n", alsafmt);
         return -1;
Index: audio/audio.c
===================================================================
RCS file: /cvsroot/qemu/qemu/audio/audio.c,v
retrieving revision 1.15
diff -u -r1.15 audio.c
--- audio/audio.c	3 Aug 2006 20:39:40 -0000	1.15
+++ audio/audio.c	6 Feb 2007 03:29:33 -0000
@@ -166,6 +166,25 @@
 }
 #endif
 
+static inline int audio_bits_to_index (int bits)
+{
+    switch (bits) {
+    case 8:
+        return 0;
+
+    case 16:
+        return 1;
+
+    case 32:
+        return 2;
+
+    default:
+        audio_bug ("bits_to_index", 1);
+        AUD_log (NULL, "invalid bits %d\n", bits);
+        return 0;
+    }
+}
+
 void *audio_calloc (const char *funcname, int nmemb, size_t size)
 {
     int cond;
@@ -227,6 +246,12 @@
 
     case AUD_FMT_S16:
         return "S16";
+
+    case AUD_FMT_U32:
+        return "U32";
+
+    case AUD_FMT_S32:
+        return "S32";
     }
 
     dolog ("Bogus audfmt %d returning S16\n", fmt);
@@ -243,6 +268,10 @@
         *defaultp = 0;
         return AUD_FMT_U16;
     }
+    else if (!strcasecmp (s, "u32")) {
+        *defaultp = 0;
+        return AUD_FMT_U32;
+    }
     else if (!strcasecmp (s, "s8")) {
         *defaultp = 0;
         return AUD_FMT_S8;
@@ -251,6 +280,10 @@
         *defaultp = 0;
         return AUD_FMT_S16;
     }
+    else if (!strcasecmp (s, "s32")) {
+        *defaultp = 0;
+        return AUD_FMT_S32;
+    }
     else {
         dolog ("Bogus audio format `%s' using %s\n",
                s, audio_audfmt_to_string (defval));
@@ -538,6 +571,8 @@
     case AUD_FMT_U8:
     case AUD_FMT_S16:
     case AUD_FMT_U16:
+    case AUD_FMT_S32:
+    case AUD_FMT_U32:
         break;
     default:
         invalid = 1;
@@ -563,6 +598,12 @@
     case AUD_FMT_U16:
         bits = 16;
         break;
+
+    case AUD_FMT_S32:
+        sign = 1;
+    case AUD_FMT_U32:
+        bits = 32;
+        break;
     }
     return info->freq == as->freq
         && info->nchannels == as->nchannels
@@ -573,7 +614,7 @@
 
 void audio_pcm_init_info (struct audio_pcm_info *info, audsettings_t *as)
 {
-    int bits = 8, sign = 0;
+    int bits = 8, sign = 0, shift = 0;
 
     switch (as->fmt) {
     case AUD_FMT_S8:
@@ -585,6 +626,14 @@
         sign = 1;
     case AUD_FMT_U16:
         bits = 16;
+        shift = 1;
+        break;
+
+    case AUD_FMT_S32:
+        sign = 1;
+    case AUD_FMT_U32:
+        bits = 32;
+        shift = 2;
         break;
     }
 
@@ -592,7 +641,7 @@
     info->bits = bits;
     info->sign = sign;
     info->nchannels = as->nchannels;
-    info->shift = (as->nchannels == 2) + (bits == 16);
+    info->shift = (as->nchannels == 2) + shift;
     info->align = (1 << info->shift) - 1;
     info->bytes_per_second = info->freq << info->shift;
     info->swap_endianness = (as->endianness != AUDIO_HOST_ENDIANNESS);
@@ -608,22 +657,49 @@
         memset (buf, 0x00, len << info->shift);
     }
     else {
-        if (info->bits == 8) {
+        switch (info->bits) {
+        case 8:
             memset (buf, 0x80, len << info->shift);
-        }
-        else {
-            int i;
-            uint16_t *p = buf;
-            int shift = info->nchannels - 1;
-            short s = INT16_MAX;
+            break;
 
-            if (info->swap_endianness) {
-                s = bswap16 (s);
+        case 16:
+            {
+                int i;
+                uint16_t *p = buf;
+                int shift = info->nchannels - 1;
+                short s = INT16_MAX;
+
+                if (info->swap_endianness) {
+                    s = bswap16 (s);
+                }
+
+                for (i = 0; i < len << shift; i++) {
+                    p[i] = s;
+                }
             }
+            break;
+
+        case 32:
+            {
+                int i;
+                uint32_t *p = buf;
+                int shift = info->nchannels - 1;
+                int32_t s = INT32_MAX;
+
+                if (info->swap_endianness) {
+                    s = bswap32 (s);
+                }
 
-            for (i = 0; i < len << shift; i++) {
-                p[i] = s;
+                for (i = 0; i < len << shift; i++) {
+                    p[i] = s;
+                }
             }
+            break;
+
+        default:
+            AUD_log (NULL, "audio_pcm_info_clear_buf: invalid bits %d\n",
+                     info->bits);
+            break;
         }
     }
 }
@@ -1811,7 +1887,7 @@
             [hw->info.nchannels == 2]
             [hw->info.sign]
             [hw->info.swap_endianness]
-            [hw->info.bits == 16];
+            [audio_bits_to_index (hw->info.bits)];
 
         LIST_INSERT_HEAD (&s->cap_head, cap, entries);
         LIST_INSERT_HEAD (&cap->cb_head, cb, entries);
Index: audio/audio.h
===================================================================
RCS file: /cvsroot/qemu/qemu/audio/audio.h,v
retrieving revision 1.8
diff -u -r1.8 audio.h
--- audio/audio.h	16 Jul 2006 18:57:03 -0000	1.8
+++ audio/audio.h	6 Feb 2007 03:29:33 -0000
@@ -33,7 +33,9 @@
     AUD_FMT_U8,
     AUD_FMT_S8,
     AUD_FMT_U16,
-    AUD_FMT_S16
+    AUD_FMT_S16,
+    AUD_FMT_U32,
+    AUD_FMT_S32
 } audfmt_e;
 
 #ifdef WORDS_BIGENDIAN
Index: audio/audio_template.h
===================================================================
RCS file: /cvsroot/qemu/qemu/audio/audio_template.h,v
retrieving revision 1.8
diff -u -r1.8 audio_template.h
--- audio/audio_template.h	16 Jul 2006 18:57:03 -0000	1.8
+++ audio/audio_template.h	6 Feb 2007 03:29:33 -0000
@@ -164,7 +164,7 @@
         [sw->info.nchannels == 2]
         [sw->info.sign]
         [sw->info.swap_endianness]
-        [sw->info.bits == 16];
+        [audio_bits_to_index (sw->info.bits)];
 
     sw->name = qemu_strdup (name);
     err = glue (audio_pcm_sw_alloc_resources_, TYPE) (sw);
@@ -288,7 +288,7 @@
         [hw->info.nchannels == 2]
         [hw->info.sign]
         [hw->info.swap_endianness]
-        [hw->info.bits == 16];
+        [audio_bits_to_index (hw->info.bits)];
 
     if (glue (audio_pcm_hw_alloc_resources_, TYPE) (hw)) {
         goto err1;
Index: audio/coreaudio.c
===================================================================
RCS file: /cvsroot/qemu/qemu/audio/coreaudio.c,v
retrieving revision 1.7
diff -u -r1.7 coreaudio.c
--- audio/coreaudio.c	4 Jul 2006 21:47:22 -0000	1.7
+++ audio/coreaudio.c	6 Feb 2007 03:29:33 -0000
@@ -294,7 +294,6 @@
     coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw;
     UInt32 propertySize;
     int err;
-    int bits = 8;
     const char *typ = "playback";
     AudioValueRange frameRange;
 
@@ -305,10 +304,6 @@
         return -1;
     }
 
-    if (as->fmt == AUD_FMT_S16 || as->fmt == AUD_FMT_U16) {
-        bits = 16;
-    }
-
     audio_pcm_init_info (&hw->info, as);
 
     /* open default output device */
Index: audio/mixeng.c
===================================================================
RCS file: /cvsroot/qemu/qemu/audio/mixeng.c,v
retrieving revision 1.4
diff -u -r1.4 mixeng.c
--- audio/mixeng.c	11 Nov 2005 00:03:07 -0000	1.4
+++ audio/mixeng.c	6 Feb 2007 03:29:33 -0000
@@ -82,6 +82,7 @@
 #undef IN_T
 #undef SHIFT
 
+/* Unsigned 16 bit */
 #define IN_T uint16_t
 #define IN_MIN 0
 #define IN_MAX USHRT_MAX
@@ -101,26 +102,72 @@
 #undef IN_T
 #undef SHIFT
 
-t_sample *mixeng_conv[2][2][2][2] = {
+/* Signed 32 bit */
+#define IN_T int32_t
+#define IN_MIN INT32_MIN
+#define IN_MAX INT32_MAX
+#define SIGNED
+#define SHIFT 32
+#define ENDIAN_CONVERSION natural
+#define ENDIAN_CONVERT(v) (v)
+#include "mixeng_template.h"
+#undef ENDIAN_CONVERT
+#undef ENDIAN_CONVERSION
+#define ENDIAN_CONVERSION swap
+#define ENDIAN_CONVERT(v) bswap32 (v)
+#include "mixeng_template.h"
+#undef ENDIAN_CONVERT
+#undef ENDIAN_CONVERSION
+#undef SIGNED
+#undef IN_MAX
+#undef IN_MIN
+#undef IN_T
+#undef SHIFT
+
+/* Unsigned 16 bit */
+#define IN_T uint32_t
+#define IN_MIN 0
+#define IN_MAX UINT32_MAX
+#define SHIFT 32
+#define ENDIAN_CONVERSION natural
+#define ENDIAN_CONVERT(v) (v)
+#include "mixeng_template.h"
+#undef ENDIAN_CONVERT
+#undef ENDIAN_CONVERSION
+#define ENDIAN_CONVERSION swap
+#define ENDIAN_CONVERT(v) bswap32 (v)
+#include "mixeng_template.h"
+#undef ENDIAN_CONVERT
+#undef ENDIAN_CONVERSION
+#undef IN_MAX
+#undef IN_MIN
+#undef IN_T
+#undef SHIFT
+
+t_sample *mixeng_conv[2][2][2][3] = {
     {
         {
             {
                 conv_natural_uint8_t_to_mono,
-                conv_natural_uint16_t_to_mono
+                conv_natural_uint16_t_to_mono,
+                conv_natural_uint32_t_to_mono
             },
             {
                 conv_natural_uint8_t_to_mono,
-                conv_swap_uint16_t_to_mono
+                conv_swap_uint16_t_to_mono,
+                conv_swap_uint32_t_to_mono,
             }
         },
         {
             {
                 conv_natural_int8_t_to_mono,
-                conv_natural_int16_t_to_mono
+                conv_natural_int16_t_to_mono,
+                conv_natural_int32_t_to_mono
             },
             {
                 conv_natural_int8_t_to_mono,
-                conv_swap_int16_t_to_mono
+                conv_swap_int16_t_to_mono,
+                conv_swap_int32_t_to_mono
             }
         }
     },
@@ -128,46 +175,54 @@
         {
             {
                 conv_natural_uint8_t_to_stereo,
-                conv_natural_uint16_t_to_stereo
+                conv_natural_uint16_t_to_stereo,
+                conv_natural_uint32_t_to_stereo
             },
             {
                 conv_natural_uint8_t_to_stereo,
-                conv_swap_uint16_t_to_stereo
+                conv_swap_uint16_t_to_stereo,
+                conv_swap_uint32_t_to_stereo
             }
         },
         {
             {
                 conv_natural_int8_t_to_stereo,
-                conv_natural_int16_t_to_stereo
+                conv_natural_int16_t_to_stereo,
+                conv_natural_int32_t_to_stereo
             },
             {
                 conv_natural_int8_t_to_stereo,
-                conv_swap_int16_t_to_stereo
+                conv_swap_int16_t_to_stereo,
+                conv_swap_int32_t_to_stereo,
             }
         }
     }
 };
 
-f_sample *mixeng_clip[2][2][2][2] = {
+f_sample *mixeng_clip[2][2][2][3] = {
     {
         {
             {
                 clip_natural_uint8_t_from_mono,
-                clip_natural_uint16_t_from_mono
+                clip_natural_uint16_t_from_mono,
+                clip_natural_uint32_t_from_mono
             },
             {
                 clip_natural_uint8_t_from_mono,
-                clip_swap_uint16_t_from_mono
+                clip_swap_uint16_t_from_mono,
+                clip_swap_uint32_t_from_mono
             }
         },
         {
             {
                 clip_natural_int8_t_from_mono,
-                clip_natural_int16_t_from_mono
+                clip_natural_int16_t_from_mono,
+                clip_natural_int32_t_from_mono
             },
             {
                 clip_natural_int8_t_from_mono,
-                clip_swap_int16_t_from_mono
+                clip_swap_int16_t_from_mono,
+                clip_swap_int32_t_from_mono
             }
         }
     },
@@ -175,21 +230,25 @@
         {
             {
                 clip_natural_uint8_t_from_stereo,
-                clip_natural_uint16_t_from_stereo
+                clip_natural_uint16_t_from_stereo,
+                clip_natural_uint32_t_from_stereo
             },
             {
                 clip_natural_uint8_t_from_stereo,
-                clip_swap_uint16_t_from_stereo
+                clip_swap_uint16_t_from_stereo,
+                clip_swap_uint32_t_from_stereo
             }
         },
         {
             {
                 clip_natural_int8_t_from_stereo,
-                clip_natural_int16_t_from_stereo
+                clip_natural_int16_t_from_stereo,
+                clip_natural_int32_t_from_stereo
             },
             {
                 clip_natural_int8_t_from_stereo,
-                clip_swap_int16_t_from_stereo
+                clip_swap_int16_t_from_stereo,
+                clip_swap_int32_t_from_stereo
             }
         }
     }
Index: audio/mixeng.h
===================================================================
RCS file: /cvsroot/qemu/qemu/audio/mixeng.h,v
retrieving revision 1.2
diff -u -r1.2 mixeng.h
--- audio/mixeng.h	30 Oct 2005 18:58:22 -0000	1.2
+++ audio/mixeng.h	6 Feb 2007 03:29:33 -0000
@@ -37,8 +37,8 @@
                          int samples, volume_t *vol);
 typedef void (f_sample) (void *dst, const st_sample_t *src, int samples);
 
-extern t_sample *mixeng_conv[2][2][2][2];
-extern f_sample *mixeng_clip[2][2][2][2];
+extern t_sample *mixeng_conv[2][2][2][3];
+extern f_sample *mixeng_clip[2][2][2][3];
 
 void *st_rate_start (int inrate, int outrate);
 void st_rate_flow (void *opaque, st_sample_t *ibuf, st_sample_t *obuf,
Index: audio/wavaudio.c
===================================================================
RCS file: /cvsroot/qemu/qemu/audio/wavaudio.c,v
retrieving revision 1.9
diff -u -r1.9 wavaudio.c
--- audio/wavaudio.c	5 Aug 2006 21:31:46 -0000	1.9
+++ audio/wavaudio.c	6 Feb 2007 03:29:33 -0000
@@ -131,6 +131,11 @@
     case AUD_FMT_U16:
         bits16 = 1;
         break;
+
+    case AUD_FMT_S32:
+    case AUD_FMT_U32:
+        dolog ("WAVE files can not handle 32bit formats\n");
+        return -1;
     }
 
     hdr[34] = bits16 ? 0x10 : 0x08;
Index: audio/wavcapture.c
===================================================================
RCS file: /cvsroot/qemu/qemu/audio/wavcapture.c,v
retrieving revision 1.7
diff -u -r1.7 wavcapture.c
--- audio/wavcapture.c	7 Aug 2006 21:35:12 -0000	1.7
+++ audio/wavcapture.c	6 Feb 2007 03:29:33 -0000
@@ -37,15 +37,15 @@
     if (wav->f) {
         le_store (rlen, rifflen, 4);
         le_store (dlen, datalen, 4);
-        
+
         qemu_fseek (wav->f, 4, SEEK_SET);
         qemu_put_buffer (wav->f, rlen, 4);
-        
+
         qemu_fseek (wav->f, 32, SEEK_CUR);
         qemu_put_buffer (wav->f, dlen, 4);
         qemu_fclose (wav->f);
     }
-    
+
     qemu_free (wav->path);
 }
 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] qemu support for S32 and U32 alsa output
  2007-02-06 23:24 [Qemu-devel] [PATCH] qemu support for S32 and U32 alsa output Lonnie Mendez
@ 2007-02-10 23:33 ` Thiemo Seufer
  2007-02-10 23:53   ` Lonnie Mendez
  0 siblings, 1 reply; 3+ messages in thread
From: Thiemo Seufer @ 2007-02-10 23:33 UTC (permalink / raw)
  To: Lonnie Mendez; +Cc: infernix, qemu-devel

Lonnie Mendez wrote:
> Forwarding this for a user who is not subscribed.
> ---
> 
> Hi,
> 
> My M-Audio soundcard (ice1712) did not play nice with qemu's alsa output
> since it only accepted S32_LE. I asked some weirdo who has nothing
> better to do at 6:50 AM in the #qemu channel on freenode for help, and
> he wrote the attached patch.
> 
> I've patched this against CVS and also against 0.8.2 with some manual
> code hacking (different line offsets), and hereby kindly request that
> someone knowledgeable takes a look at it so it can be committed.

So ... who is the person to blam^Wcredit for authorship?
The patch looks good elsewise.


Thiemo

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] qemu support for S32 and U32 alsa output
  2007-02-10 23:33 ` Thiemo Seufer
@ 2007-02-10 23:53   ` Lonnie Mendez
  0 siblings, 0 replies; 3+ messages in thread
From: Lonnie Mendez @ 2007-02-10 23:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: infernix

On Sat, 2007-02-10 at 23:33 +0000, Thiemo Seufer wrote:
> So ... who is the person to blam^Wcredit for authorship?
> The patch looks good elsewise.

I believe the author is Vassili Karpov.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-02-10 23:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-06 23:24 [Qemu-devel] [PATCH] qemu support for S32 and U32 alsa output Lonnie Mendez
2007-02-10 23:33 ` Thiemo Seufer
2007-02-10 23:53   ` Lonnie Mendez

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.