Index: uspace/Makefile
===================================================================
--- uspace/Makefile	(revision 950110eedb4177666897cb1e24a6cf4168e29741)
+++ uspace/Makefile	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
@@ -206,4 +206,5 @@
 	lib/usbhid \
 	lib/usbvirt \
+	lib/pcm \
 	lib/posix
 
Index: uspace/Makefile.common
===================================================================
--- uspace/Makefile.common	(revision 950110eedb4177666897cb1e24a6cf4168e29741)
+++ uspace/Makefile.common	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
@@ -124,4 +124,5 @@
 LIBDRV_PREFIX = $(LIB_PREFIX)/drv
 LIBHOUND_PREFIX = $(LIB_PREFIX)/hound
+LIBPCM_PREFIX = $(LIB_PREFIX)/pcm
 LIBNET_PREFIX = $(LIB_PREFIX)/net
 LIBNIC_PREFIX = $(LIB_PREFIX)/nic
Index: uspace/app/dplay/Makefile
===================================================================
--- uspace/app/dplay/Makefile	(revision 950110eedb4177666897cb1e24a6cf4168e29741)
+++ uspace/app/dplay/Makefile	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
@@ -34,5 +34,5 @@
 
 EXTRA_CFLAGS = \
-	-I$(LIBDRV_PREFIX)/include
+	-I$(LIBDRV_PREFIX)/include -I$(LIBPCM_PREFIX)/include
 
 SOURCES = \
Index: uspace/app/dplay/wave.h
===================================================================
--- uspace/app/dplay/wave.h	(revision 950110eedb4177666897cb1e24a6cf4168e29741)
+++ uspace/app/dplay/wave.h	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
@@ -37,5 +37,5 @@
 #include <stdint.h>
 #include <bool.h>
-#include <pcm_sample_format.h>
+#include <pcm/sample_format.h>
 
 /** Wave file header format.
Index: uspace/app/drec/Makefile
===================================================================
--- uspace/app/drec/Makefile	(revision 950110eedb4177666897cb1e24a6cf4168e29741)
+++ uspace/app/drec/Makefile	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
@@ -34,5 +34,5 @@
 
 EXTRA_CFLAGS = \
-	-I$(LIBDRV_PREFIX)/include
+	-I$(LIBDRV_PREFIX)/include -I$(LIBPCM_PREFIX)/include
 
 SOURCES = \
Index: uspace/app/drec/drec.c
===================================================================
--- uspace/app/drec/drec.c	(revision 950110eedb4177666897cb1e24a6cf4168e29741)
+++ uspace/app/drec/drec.c	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
@@ -47,5 +47,5 @@
 #include <stdio.h>
 #include <macros.h>
-#include <pcm_sample_format.h>
+#include <pcm/sample_format.h>
 
 #include "wave.h"
Index: uspace/app/drec/wave.h
===================================================================
--- uspace/app/drec/wave.h	(revision 950110eedb4177666897cb1e24a6cf4168e29741)
+++ uspace/app/drec/wave.h	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
@@ -36,6 +36,5 @@
 
 #include <stdint.h>
-#include <bool.h>
-#include <pcm_sample_format.h>
+#include <pcm/sample_format.h>
 
 /** Wave file header format.
Index: uspace/app/wavplay/Makefile
===================================================================
--- uspace/app/wavplay/Makefile	(revision 950110eedb4177666897cb1e24a6cf4168e29741)
+++ uspace/app/wavplay/Makefile	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
@@ -34,5 +34,5 @@
 
 EXTRA_CFLAGS = \
-	-I $(LIBHOUND_PREFIX)/include
+	-I$(LIBHOUND_PREFIX)/include -I$(LIBPCM_PREFIX)/include
 
 SOURCES = \
Index: uspace/app/wavplay/wave.h
===================================================================
--- uspace/app/wavplay/wave.h	(revision 950110eedb4177666897cb1e24a6cf4168e29741)
+++ uspace/app/wavplay/wave.h	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
@@ -36,6 +36,5 @@
 
 #include <stdint.h>
-#include <bool.h>
-#include <pcm_sample_format.h>
+#include <pcm/sample_format.h>
 
 /** Wave file header format.
Index: uspace/app/wavplay/wavplay.c
===================================================================
--- uspace/app/wavplay/wavplay.c	(revision 950110eedb4177666897cb1e24a6cf4168e29741)
+++ uspace/app/wavplay/wavplay.c	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
@@ -39,10 +39,6 @@
 #include <str_error.h>
 #include <stdio.h>
-
 #include <hound/client.h>
-
-#include <pcm_sample_format.h>
-
-#include <stdio.h>
+#include <pcm/sample_format.h>
 
 #include "wave.h"
Index: uspace/drv/audio/sb16/Makefile
===================================================================
--- uspace/drv/audio/sb16/Makefile	(revision 950110eedb4177666897cb1e24a6cf4168e29741)
+++ uspace/drv/audio/sb16/Makefile	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
@@ -33,5 +33,5 @@
 
 EXTRA_CFLAGS += \
-	-I$(LIBDRV_PREFIX)/include
+	-I$(LIBDRV_PREFIX)/include -I$(LIBPCM_PREFIX)/include
 
 BINARY = sb16
Index: uspace/drv/audio/sb16/dsp.h
===================================================================
--- uspace/drv/audio/sb16/dsp.h	(revision 950110eedb4177666897cb1e24a6cf4168e29741)
+++ uspace/drv/audio/sb16/dsp.h	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
@@ -38,5 +38,5 @@
 #include <libarch/ddi.h>
 #include <errno.h>
-#include <pcm_sample_format.h>
+#include <pcm/sample_format.h>
 
 #include "registers.h"
Index: uspace/drv/audio/sb16/pcm_iface.c
===================================================================
--- uspace/drv/audio/sb16/pcm_iface.c	(revision 950110eedb4177666897cb1e24a6cf4168e29741)
+++ uspace/drv/audio/sb16/pcm_iface.c	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
@@ -36,5 +36,5 @@
 #include <errno.h>
 #include <audio_pcm_iface.h>
-#include <pcm_sample_format.h>
+#include <pcm/sample_format.h>
 
 #include "dsp.h"
Index: pace/lib/c/include/pcm_sample_format.h
===================================================================
--- uspace/lib/c/include/pcm_sample_format.h	(revision 950110eedb4177666897cb1e24a6cf4168e29741)
+++ 	(revision )
@@ -1,174 +1,0 @@
-/*
- * Copyright (c) 2012 Jan Vesely
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup audio
- * @brief PCM sample format
- * @{
- */
-/** @file
- */
-
-#ifndef PCM_SAMPLE_FORMAT_H_
-#define PCM_SAMPLE_FORMAT_H_
-
-#include <bool.h>
-
-typedef enum {
-	PCM_SAMPLE_UINT8,
-	PCM_SAMPLE_SINT8,
-	PCM_SAMPLE_UINT16_LE,
-	PCM_SAMPLE_UINT16_BE,
-	PCM_SAMPLE_SINT16_LE,
-	PCM_SAMPLE_SINT16_BE,
-	PCM_SAMPLE_UINT24_LE,
-	PCM_SAMPLE_UINT24_BE,
-	PCM_SAMPLE_SINT24_LE,
-	PCM_SAMPLE_SINT24_BE,
-	PCM_SAMPLE_UINT24_32_LE,
-	PCM_SAMPLE_UINT24_32_BE,
-	PCM_SAMPLE_SINT24_32_LE,
-	PCM_SAMPLE_SINT24_32_BE,
-	PCM_SAMPLE_UINT32_LE,
-	PCM_SAMPLE_UINT32_BE,
-	PCM_SAMPLE_SINT32_LE,
-	PCM_SAMPLE_SINT32_BE,
-	PCM_SAMPLE_FLOAT32,
-	PCM_SAMPLE_FORMAT_LAST = PCM_SAMPLE_FLOAT32,
-} pcm_sample_format_t;
-
-static inline bool pcm_sample_format_is_signed(pcm_sample_format_t format)
-{
-	switch(format) {
-	case PCM_SAMPLE_SINT8:
-	case PCM_SAMPLE_SINT16_LE:
-	case PCM_SAMPLE_SINT16_BE:
-	case PCM_SAMPLE_SINT24_LE:
-	case PCM_SAMPLE_SINT24_BE:
-	case PCM_SAMPLE_SINT24_32_LE:
-	case PCM_SAMPLE_SINT24_32_BE:
-	case PCM_SAMPLE_SINT32_LE:
-	case PCM_SAMPLE_SINT32_BE:
-		return true;
-	case PCM_SAMPLE_UINT8:
-	case PCM_SAMPLE_UINT16_LE:
-	case PCM_SAMPLE_UINT16_BE:
-	case PCM_SAMPLE_UINT24_LE:
-	case PCM_SAMPLE_UINT24_BE:
-	case PCM_SAMPLE_UINT24_32_LE:
-	case PCM_SAMPLE_UINT24_32_BE:
-	case PCM_SAMPLE_UINT32_LE:
-	case PCM_SAMPLE_UINT32_BE:
-	case PCM_SAMPLE_FLOAT32:
-	default:
-		return false;
-	}
-}
-
-static inline size_t pcm_sample_format_size(pcm_sample_format_t format)
-{
-	switch(format) {
-	case PCM_SAMPLE_UINT8:
-	case PCM_SAMPLE_SINT8:
-		return 1;
-	case PCM_SAMPLE_UINT16_LE:
-	case PCM_SAMPLE_UINT16_BE:
-	case PCM_SAMPLE_SINT16_LE:
-	case PCM_SAMPLE_SINT16_BE:
-		return 2;
-	case PCM_SAMPLE_UINT24_LE:
-	case PCM_SAMPLE_UINT24_BE:
-	case PCM_SAMPLE_SINT24_LE:
-	case PCM_SAMPLE_SINT24_BE:
-		return 3;
-	case PCM_SAMPLE_UINT24_32_LE:
-	case PCM_SAMPLE_UINT24_32_BE:
-	case PCM_SAMPLE_SINT24_32_LE:
-	case PCM_SAMPLE_SINT24_32_BE:
-	case PCM_SAMPLE_UINT32_LE:
-	case PCM_SAMPLE_UINT32_BE:
-	case PCM_SAMPLE_SINT32_LE:
-	case PCM_SAMPLE_SINT32_BE:
-	case PCM_SAMPLE_FLOAT32:
-		return 4;
-	default:
-		return 0;
-	}
-}
-
-static inline const char * pcm_sample_format_str(pcm_sample_format_t format)
-{
-	switch(format) {
-	case PCM_SAMPLE_UINT8:
-		return "8 bit unsinged";
-	case PCM_SAMPLE_SINT8:
-		return "8 bit singed";
-	case PCM_SAMPLE_UINT16_LE:
-		return "16 bit unsigned(LE)";
-	case PCM_SAMPLE_SINT16_LE:
-		return "16 bit singed(LE)";
-	case PCM_SAMPLE_UINT16_BE:
-		return "16 bit unsigned(BE)";
-	case PCM_SAMPLE_SINT16_BE:
-		return "16 bit signed(BE)";
-	case PCM_SAMPLE_UINT24_LE:
-		return "24 bit unsigned(LE)";
-	case PCM_SAMPLE_SINT24_LE:
-		return "24 bit signed(LE)";
-	case PCM_SAMPLE_UINT24_BE:
-		return "24 bit unsigned(BE)";
-	case PCM_SAMPLE_SINT24_BE:
-		return "24 bit signed(BE)";
-	case PCM_SAMPLE_UINT24_32_LE:
-		return "24 bit(4byte aligned) unsigned(LE)";
-	case PCM_SAMPLE_UINT24_32_BE:
-		return "24 bit(4byte aligned) unsigned(BE)";
-	case PCM_SAMPLE_SINT24_32_LE:
-		return "24 bit(4byte aligned) signed(LE)";
-	case PCM_SAMPLE_SINT24_32_BE:
-		return "24 bit(4byte aligned) signed(BE)";
-	case PCM_SAMPLE_UINT32_LE:
-		return "32 bit unsigned(LE)";
-	case PCM_SAMPLE_UINT32_BE:
-		return "32 bit unsigned(BE)";
-	case PCM_SAMPLE_SINT32_LE:
-		return "32 bit signed(LE)";
-	case PCM_SAMPLE_SINT32_BE:
-		return "32 bit signed(BE)";
-	case PCM_SAMPLE_FLOAT32:
-		return "32 bit float";
-	default:
-		return "Unknown sample format";
-	}
-}
-
-#endif
-
-/**
- * @}
- */
-
Index: uspace/lib/drv/Makefile
===================================================================
--- uspace/lib/drv/Makefile	(revision 950110eedb4177666897cb1e24a6cf4168e29741)
+++ uspace/lib/drv/Makefile	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
@@ -29,5 +29,5 @@
 
 USPACE_PREFIX = ../..
-EXTRA_CFLAGS = -Iinclude -I$(LIBUSB_PREFIX)/include
+EXTRA_CFLAGS = -Iinclude -I$(LIBUSB_PREFIX)/include -I$(LIBPCM_PREFIX)/include
 LIBRARY = libdrv
 
Index: uspace/lib/drv/include/audio_pcm_iface.h
===================================================================
--- uspace/lib/drv/include/audio_pcm_iface.h	(revision 950110eedb4177666897cb1e24a6cf4168e29741)
+++ uspace/lib/drv/include/audio_pcm_iface.h	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
@@ -40,5 +40,5 @@
 #include <bool.h>
 #include <loc.h>
-#include <pcm_sample_format.h>
+#include <pcm/sample_format.h>
 
 #include "ddf/driver.h"
Index: uspace/lib/hound/Makefile
===================================================================
--- uspace/lib/hound/Makefile	(revision 950110eedb4177666897cb1e24a6cf4168e29741)
+++ uspace/lib/hound/Makefile	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
@@ -28,5 +28,5 @@
 
 USPACE_PREFIX = ../..
-EXTRA_CFLAGS = -Iinclude/hound
+EXTRA_CFLAGS = -Iinclude/hound -I$(LIBPCM_PREFIX)/include
 LIBRARY = libhound
 
Index: uspace/lib/hound/include/hound/client.h
===================================================================
--- uspace/lib/hound/include/hound/client.h	(revision 950110eedb4177666897cb1e24a6cf4168e29741)
+++ uspace/lib/hound/include/hound/client.h	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
@@ -39,5 +39,5 @@
 #include <async.h>
 #include <bool.h>
-#include <pcm_sample_format.h>
+#include <pcm/sample_format.h>
 
 #define DEFAULT_SINK "default"
Index: uspace/lib/hound/include/hound/server.h
===================================================================
--- uspace/lib/hound/include/hound/server.h	(revision 950110eedb4177666897cb1e24a6cf4168e29741)
+++ uspace/lib/hound/include/hound/server.h	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
@@ -40,5 +40,5 @@
 #include <bool.h>
 #include <loc.h>
-#include <pcm_sample_format.h>
+#include <pcm/sample_format.h>
 
 enum {
Index: uspace/lib/pcm/Makefile
===================================================================
--- uspace/lib/pcm/Makefile	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
+++ uspace/lib/pcm/Makefile	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
@@ -0,0 +1,37 @@
+#
+# Copyright (c) 2012 Jan Vesely
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+USPACE_PREFIX = ../..
+EXTRA_CFLAGS = -Iinclude/pcm -Iinclude
+LIBRARY = libpcm
+
+SOURCES = \
+	src/format.c
+include $(USPACE_PREFIX)/Makefile.common
+
+
Index: uspace/lib/pcm/include/pcm/format.h
===================================================================
--- uspace/lib/pcm/include/pcm/format.h	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
+++ uspace/lib/pcm/include/pcm/format.h	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2012 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup audio
+ * @brief HelenOS sound server
+ * @{
+ */
+/** @file
+ */
+
+#ifndef PCM_FORMAT_H_
+#define PCM_FORMAT_H_
+
+#include <assert.h>
+#include <bool.h>
+#include <pcm/sample_format.h>
+
+typedef struct {
+	unsigned channels;
+	unsigned sampling_rate;
+	pcm_sample_format_t sample_format;
+} pcm_format_t;
+
+static const pcm_format_t AUDIO_FORMAT_DEFAULT = {
+	.channels = 2,
+	.sampling_rate = 44100,
+	.sample_format = PCM_SAMPLE_SINT16_LE,
+	};
+
+static const pcm_format_t AUDIO_FORMAT_ANY = {
+	.channels = 0,
+	.sampling_rate = 0,
+	.sample_format = 0,
+	};
+
+static inline size_t pcm_format_frame_size(const pcm_format_t *a)
+{
+	return a->channels * pcm_sample_format_size(a->sample_format);
+}
+
+bool pcm_format_same(const pcm_format_t *a, const pcm_format_t* b);
+static inline bool pcm_format_is_any(const pcm_format_t *f)
+{
+	return pcm_format_same(f, &AUDIO_FORMAT_ANY);
+}
+int pcm_format_convert_and_mix(void *dst, size_t dst_size, const void *src,
+    size_t src_size, const pcm_format_t *sf, const pcm_format_t *df);
+int pcm_format_mix(void *dst, const void *src, size_t size, const pcm_format_t *f);
+int pcm_format_convert(pcm_format_t a, void* srca, size_t sizea,
+    pcm_format_t b, void* srcb, size_t *sizeb);
+
+#endif
+
+/**
+ * @}
+ */
Index: uspace/lib/pcm/include/pcm/sample_format.h
===================================================================
--- uspace/lib/pcm/include/pcm/sample_format.h	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
+++ uspace/lib/pcm/include/pcm/sample_format.h	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
@@ -0,0 +1,174 @@
+/*
+ * Copyright (c) 2012 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup audio
+ * @brief PCM sample format
+ * @{
+ */
+/** @file
+ */
+
+#ifndef PCM_SAMPLE_FORMAT_H_
+#define PCM_SAMPLE_FORMAT_H_
+
+#include <bool.h>
+
+typedef enum {
+	PCM_SAMPLE_UINT8,
+	PCM_SAMPLE_SINT8,
+	PCM_SAMPLE_UINT16_LE,
+	PCM_SAMPLE_UINT16_BE,
+	PCM_SAMPLE_SINT16_LE,
+	PCM_SAMPLE_SINT16_BE,
+	PCM_SAMPLE_UINT24_LE,
+	PCM_SAMPLE_UINT24_BE,
+	PCM_SAMPLE_SINT24_LE,
+	PCM_SAMPLE_SINT24_BE,
+	PCM_SAMPLE_UINT24_32_LE,
+	PCM_SAMPLE_UINT24_32_BE,
+	PCM_SAMPLE_SINT24_32_LE,
+	PCM_SAMPLE_SINT24_32_BE,
+	PCM_SAMPLE_UINT32_LE,
+	PCM_SAMPLE_UINT32_BE,
+	PCM_SAMPLE_SINT32_LE,
+	PCM_SAMPLE_SINT32_BE,
+	PCM_SAMPLE_FLOAT32,
+	PCM_SAMPLE_FORMAT_LAST = PCM_SAMPLE_FLOAT32,
+} pcm_sample_format_t;
+
+static inline bool pcm_sample_format_is_signed(pcm_sample_format_t format)
+{
+	switch(format) {
+	case PCM_SAMPLE_SINT8:
+	case PCM_SAMPLE_SINT16_LE:
+	case PCM_SAMPLE_SINT16_BE:
+	case PCM_SAMPLE_SINT24_LE:
+	case PCM_SAMPLE_SINT24_BE:
+	case PCM_SAMPLE_SINT24_32_LE:
+	case PCM_SAMPLE_SINT24_32_BE:
+	case PCM_SAMPLE_SINT32_LE:
+	case PCM_SAMPLE_SINT32_BE:
+		return true;
+	case PCM_SAMPLE_UINT8:
+	case PCM_SAMPLE_UINT16_LE:
+	case PCM_SAMPLE_UINT16_BE:
+	case PCM_SAMPLE_UINT24_LE:
+	case PCM_SAMPLE_UINT24_BE:
+	case PCM_SAMPLE_UINT24_32_LE:
+	case PCM_SAMPLE_UINT24_32_BE:
+	case PCM_SAMPLE_UINT32_LE:
+	case PCM_SAMPLE_UINT32_BE:
+	case PCM_SAMPLE_FLOAT32:
+	default:
+		return false;
+	}
+}
+
+static inline size_t pcm_sample_format_size(pcm_sample_format_t format)
+{
+	switch(format) {
+	case PCM_SAMPLE_UINT8:
+	case PCM_SAMPLE_SINT8:
+		return 1;
+	case PCM_SAMPLE_UINT16_LE:
+	case PCM_SAMPLE_UINT16_BE:
+	case PCM_SAMPLE_SINT16_LE:
+	case PCM_SAMPLE_SINT16_BE:
+		return 2;
+	case PCM_SAMPLE_UINT24_LE:
+	case PCM_SAMPLE_UINT24_BE:
+	case PCM_SAMPLE_SINT24_LE:
+	case PCM_SAMPLE_SINT24_BE:
+		return 3;
+	case PCM_SAMPLE_UINT24_32_LE:
+	case PCM_SAMPLE_UINT24_32_BE:
+	case PCM_SAMPLE_SINT24_32_LE:
+	case PCM_SAMPLE_SINT24_32_BE:
+	case PCM_SAMPLE_UINT32_LE:
+	case PCM_SAMPLE_UINT32_BE:
+	case PCM_SAMPLE_SINT32_LE:
+	case PCM_SAMPLE_SINT32_BE:
+	case PCM_SAMPLE_FLOAT32:
+		return 4;
+	default:
+		return 0;
+	}
+}
+
+static inline const char * pcm_sample_format_str(pcm_sample_format_t format)
+{
+	switch(format) {
+	case PCM_SAMPLE_UINT8:
+		return "8 bit unsinged";
+	case PCM_SAMPLE_SINT8:
+		return "8 bit singed";
+	case PCM_SAMPLE_UINT16_LE:
+		return "16 bit unsigned(LE)";
+	case PCM_SAMPLE_SINT16_LE:
+		return "16 bit singed(LE)";
+	case PCM_SAMPLE_UINT16_BE:
+		return "16 bit unsigned(BE)";
+	case PCM_SAMPLE_SINT16_BE:
+		return "16 bit signed(BE)";
+	case PCM_SAMPLE_UINT24_LE:
+		return "24 bit unsigned(LE)";
+	case PCM_SAMPLE_SINT24_LE:
+		return "24 bit signed(LE)";
+	case PCM_SAMPLE_UINT24_BE:
+		return "24 bit unsigned(BE)";
+	case PCM_SAMPLE_SINT24_BE:
+		return "24 bit signed(BE)";
+	case PCM_SAMPLE_UINT24_32_LE:
+		return "24 bit(4byte aligned) unsigned(LE)";
+	case PCM_SAMPLE_UINT24_32_BE:
+		return "24 bit(4byte aligned) unsigned(BE)";
+	case PCM_SAMPLE_SINT24_32_LE:
+		return "24 bit(4byte aligned) signed(LE)";
+	case PCM_SAMPLE_SINT24_32_BE:
+		return "24 bit(4byte aligned) signed(BE)";
+	case PCM_SAMPLE_UINT32_LE:
+		return "32 bit unsigned(LE)";
+	case PCM_SAMPLE_UINT32_BE:
+		return "32 bit unsigned(BE)";
+	case PCM_SAMPLE_SINT32_LE:
+		return "32 bit signed(LE)";
+	case PCM_SAMPLE_SINT32_BE:
+		return "32 bit signed(BE)";
+	case PCM_SAMPLE_FLOAT32:
+		return "32 bit float";
+	default:
+		return "Unknown sample format";
+	}
+}
+
+#endif
+
+/**
+ * @}
+ */
+
Index: uspace/lib/pcm/src/format.c
===================================================================
--- uspace/lib/pcm/src/format.c	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
+++ uspace/lib/pcm/src/format.c	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
@@ -0,0 +1,236 @@
+/*
+ * Copyright (c) 2012 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup audio
+ * @brief HelenOS sound server
+ * @{
+ */
+/** @file
+ */
+
+#include <assert.h>
+#include <byteorder.h>
+#include <errno.h>
+#include <macros.h>
+#include <stdio.h>
+
+#include "format.h"
+
+#define uint8_t_le2host(x) (x)
+#define host2uint8_t_le(x) (x)
+#define uint8_t_be2host(x) (x)
+#define host2uint8_t_be(x) (x)
+
+#define int8_t_le2host(x) (x)
+#define host2int8_t_le(x) (x)
+
+#define int16_t_le2host(x) uint16_t_le2host(x)
+#define host2int16_t_le(x) host2uint16_t_le(x)
+
+#define int32_t_le2host(x) uint32_t_le2host(x)
+#define host2int32_t_le(x) host2uint32_t_le(x)
+
+#define int8_t_be2host(x) (x)
+#define host2int8_t_be(x) (x)
+
+#define int16_t_be2host(x) uint16_t_be2host(x)
+#define host2int16_t_be(x) host2uint16_t_be(x)
+
+#define int32_t_be2host(x) uint32_t_be2host(x)
+#define host2int32_t_be(x) host2uint32_t_be(x)
+
+// TODO float endian?
+#define float_le2host(x) (x)
+#define float_be2host(x) (x)
+
+#define host2float_le(x) (x)
+#define host2float_be(x) (x)
+
+#define from(x, type, endian) (float)(type ## _ ## endian ## 2host(x))
+#define to(x, type, endian) (float)(host2 ## type ## _ ## endian(x))
+
+static float get_normalized_sample(const void *buffer, size_t size,
+    unsigned frame, unsigned channel, const pcm_format_t *f);
+
+bool pcm_format_same(const pcm_format_t *a, const pcm_format_t* b)
+{
+	assert(a);
+	assert(b);
+	return
+	    a->sampling_rate == b->sampling_rate &&
+	    a->channels == b->channels &&
+	    a->sample_format == b->sample_format;
+}
+
+int pcm_format_mix(void *dst, const void *src, size_t size, const pcm_format_t *f)
+{
+	return pcm_format_convert_and_mix(dst, size, src, size, f, f);
+}
+int pcm_format_convert_and_mix(void *dst, size_t dst_size, const void *src,
+    size_t src_size, const pcm_format_t *sf, const pcm_format_t *df)
+{
+	if (!dst || !src || !sf || !df)
+		return EINVAL;
+	const size_t src_frame_size = pcm_format_frame_size(sf);
+	if ((src_size % src_frame_size) != 0)
+		return EINVAL;
+
+	const size_t dst_frame_size = pcm_format_frame_size(df);
+	if ((src_size % dst_frame_size) != 0)
+		return EINVAL;
+
+	/* This is so ugly it eats kittens, and puppies, and ducklings,
+	 * and all little fluffy things...
+	 */
+#define LOOP_ADD(type, endian, low, high) \
+do { \
+	const unsigned frame_count = dst_size / dst_frame_size; \
+	for (size_t i = 0; i < frame_count; ++i) { \
+		for (unsigned j = 0; j < df->channels; ++j) { \
+			const float a = \
+			    get_normalized_sample(dst, src_size, i, j, df);\
+			const float b = \
+			    get_normalized_sample(src, dst_size, i, j, sf);\
+			float c = (a + b); \
+			if (c < -1.0) c = -1.0; \
+			if (c > 1.0) c = 1.0; \
+			c += 1.0; \
+			c *= ((float)(type)high - (float)(type)low) / 2; \
+			c += (float)(type)low; \
+			type *dst_buf = dst; \
+			const unsigned pos = i * df->channels  + j; \
+			if (pos < (dst_size / sizeof(type))) \
+				dst_buf[pos] = to((type)c, type, endian); \
+		} \
+	} \
+} while (0)
+
+	switch (df->sample_format) {
+	case PCM_SAMPLE_UINT8:
+		LOOP_ADD(uint8_t, le, UINT8_MIN, UINT8_MAX); break;
+	case PCM_SAMPLE_SINT8:
+		LOOP_ADD(uint8_t, le, INT8_MIN, INT8_MAX); break;
+	case PCM_SAMPLE_UINT16_LE:
+		LOOP_ADD(uint16_t, le, UINT16_MIN, UINT16_MAX); break;
+	case PCM_SAMPLE_SINT16_LE:
+		LOOP_ADD(int16_t, le, INT16_MIN, INT16_MAX); break;
+	case PCM_SAMPLE_UINT16_BE:
+		LOOP_ADD(uint16_t, be, UINT16_MIN, UINT16_MAX); break;
+	case PCM_SAMPLE_SINT16_BE:
+		LOOP_ADD(int16_t, be, INT16_MIN, INT16_MAX); break;
+	case PCM_SAMPLE_UINT24_32_LE:
+	case PCM_SAMPLE_UINT32_LE: // TODO this are not right for 24bit
+		LOOP_ADD(uint32_t, le, UINT32_MIN, UINT32_MAX); break;
+	case PCM_SAMPLE_SINT24_32_LE:
+	case PCM_SAMPLE_SINT32_LE:
+		LOOP_ADD(int32_t, le, INT32_MIN, INT32_MAX); break;
+	case PCM_SAMPLE_UINT24_32_BE:
+	case PCM_SAMPLE_UINT32_BE:
+		LOOP_ADD(uint32_t, be, UINT32_MIN, UINT32_MAX); break;
+	case PCM_SAMPLE_SINT24_32_BE:
+	case PCM_SAMPLE_SINT32_BE:
+		LOOP_ADD(int32_t, be, INT32_MIN, INT32_MAX); break;
+	case PCM_SAMPLE_UINT24_LE:
+	case PCM_SAMPLE_SINT24_LE:
+	case PCM_SAMPLE_UINT24_BE:
+	case PCM_SAMPLE_SINT24_BE:
+	case PCM_SAMPLE_FLOAT32:
+	default:
+		return ENOTSUP;
+	}
+	return EOK;
+#undef LOOP_ADD
+}
+
+/** Converts all sample formats to float <-1,1> */
+static float get_normalized_sample(const void *buffer, size_t size,
+    unsigned frame, unsigned channel, const pcm_format_t *f)
+{
+	assert(f);
+	if (channel >= f->channels)
+		return 0.0f;
+#define GET(type, endian, low, high) \
+do { \
+	const type *src = buffer; \
+	const size_t sample_count = size / sizeof(type); \
+	const size_t sample_pos = frame * f->channels + channel; \
+	if (sample_pos >= sample_count) {\
+		return 0.0f; \
+	} \
+	float sample = from(src[sample_pos], type, endian); \
+	/* This makes it positive */ \
+	sample -= (float)(type)low; \
+	if (sample < 0.0f) { \
+		printf("SUB MIN failed\n"); \
+	} \
+	/* This makes it <0,2> */ \
+	sample /= (((float)(type)high - (float)(type)low) / 2.0f); \
+	if (sample > 2.0) { \
+		printf("DIV RANGE failed\n"); \
+	} \
+	return sample - 1.0f; \
+} while (0)
+
+	switch (f->sample_format) {
+	case PCM_SAMPLE_UINT8:
+		GET(uint8_t, le, UINT8_MIN, UINT8_MAX);
+	case PCM_SAMPLE_SINT8:
+		GET(int8_t, le, INT8_MIN, INT8_MAX);
+	case PCM_SAMPLE_UINT16_LE:
+		GET(uint16_t, le, UINT16_MIN, UINT16_MAX);
+	case PCM_SAMPLE_SINT16_LE:
+		GET(int16_t, le, INT16_MIN, INT16_MAX);
+	case PCM_SAMPLE_UINT16_BE:
+		GET(uint16_t, be, UINT16_MIN, UINT16_MAX);
+	case PCM_SAMPLE_SINT16_BE:
+		GET(int16_t, be, INT16_MIN, INT16_MAX);
+	case PCM_SAMPLE_UINT24_32_LE:
+	case PCM_SAMPLE_UINT32_LE:
+		GET(uint32_t, le, UINT32_MIN, UINT32_MAX);
+	case PCM_SAMPLE_SINT24_32_LE:
+	case PCM_SAMPLE_SINT32_LE:
+		GET(int32_t, le, INT32_MIN, INT32_MAX);
+	case PCM_SAMPLE_UINT24_32_BE:
+	case PCM_SAMPLE_UINT32_BE:
+		GET(uint32_t, be, UINT32_MIN, UINT32_MAX);
+	case PCM_SAMPLE_SINT24_32_BE:
+	case PCM_SAMPLE_SINT32_BE:
+		GET(int32_t, le, INT32_MIN, INT32_MAX);
+	case PCM_SAMPLE_UINT24_LE:
+	case PCM_SAMPLE_SINT24_LE:
+	case PCM_SAMPLE_UINT24_BE:
+	case PCM_SAMPLE_SINT24_BE:
+	case PCM_SAMPLE_FLOAT32:
+	default: ;
+	}
+	return 0;
+#undef GET
+}
+/**
+ * @}
+ */
Index: uspace/srv/audio/hound/Makefile
===================================================================
--- uspace/srv/audio/hound/Makefile	(revision 950110eedb4177666897cb1e24a6cf4168e29741)
+++ uspace/srv/audio/hound/Makefile	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
@@ -33,14 +33,15 @@
 	-DNAME="\"hound\"" \
 	-I$(LIBDRV_PREFIX)/include \
-	-I$(LIBHOUND_PREFIX)/include
+	-I$(LIBHOUND_PREFIX)/include \
+	-I$(LIBPCM_PREFIX)/include
 
 LIBS = \
 	$(LIBDRV_PREFIX)/libdrv.a \
-	$(LIBHOUND_PREFIX)/libhound.a
+	$(LIBHOUND_PREFIX)/libhound.a \
+	$(LIBPCM_PREFIX)/libpcm.a
 
 SOURCES = \
 	audio_client.c \
 	audio_device.c \
-	audio_format.c \
 	audio_sink.c \
 	audio_source.c \
Index: uspace/srv/audio/hound/audio_client.c
===================================================================
--- uspace/srv/audio/hound/audio_client.c	(revision 950110eedb4177666897cb1e24a6cf4168e29741)
+++ uspace/srv/audio/hound/audio_client.c	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
@@ -43,5 +43,5 @@
 
 static void init_common(audio_client_t *client, const char *name,
-    const audio_format_t *f, async_sess_t *sess)
+    const pcm_format_t *f, async_sess_t *sess)
 {
 	link_initialize(&client->link);
@@ -60,5 +60,5 @@
 
 audio_client_t *audio_client_get_playback(
-    const char *name, const audio_format_t *f, async_sess_t *sess)
+    const char *name, const pcm_format_t *f, async_sess_t *sess)
 {
 	audio_client_t *client = malloc(sizeof(audio_client_t));
@@ -73,5 +73,5 @@
 
 audio_client_t *audio_client_get_recording(
-    const char *name, const audio_format_t *f, async_sess_t *sess)
+    const char *name, const pcm_format_t *f, async_sess_t *sess)
 {
 	audio_client_t *client = malloc(sizeof(audio_client_t));
Index: uspace/srv/audio/hound/audio_client.h
===================================================================
--- uspace/srv/audio/hound/audio_client.h	(revision 950110eedb4177666897cb1e24a6cf4168e29741)
+++ uspace/srv/audio/hound/audio_client.h	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
@@ -39,6 +39,6 @@
 #include <adt/list.h>
 #include <async.h>
+#include <pcm/format.h>
 
-#include "audio_format.h"
 #include "audio_source.h"
 #include "audio_sink.h"
@@ -49,5 +49,5 @@
 	audio_source_t source;
 	audio_sink_t sink;
-	audio_format_t format;
+	pcm_format_t format;
 	async_sess_t *sess;
 	async_exch_t *exch;
@@ -62,7 +62,7 @@
 
 audio_client_t *audio_client_get_playback(
-    const char *name, const audio_format_t *f, async_sess_t *sess);
+    const char *name, const pcm_format_t *f, async_sess_t *sess);
 audio_client_t *audio_client_get_recording(
-    const char *name, const audio_format_t *f, async_sess_t *sess);
+    const char *name, const pcm_format_t *f, async_sess_t *sess);
 void audio_client_destroy(audio_client_t *client);
 
Index: uspace/srv/audio/hound/audio_device.c
===================================================================
--- uspace/srv/audio/hound/audio_device.c	(revision 950110eedb4177666897cb1e24a6cf4168e29741)
+++ uspace/srv/audio/hound/audio_device.c	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
@@ -109,5 +109,5 @@
 
 		const unsigned frames = dev->buffer.size /
-		    (BUFFER_PARTS * audio_format_frame_size(&dev->sink.format));
+		    (BUFFER_PARTS * pcm_format_frame_size(&dev->sink.format));
 		ret = audio_pcm_start_playback(dev->sess, frames,
 		    dev->sink.format.channels, dev->sink.format.sampling_rate,
@@ -152,5 +152,5 @@
 		}
 		const unsigned frames = dev->buffer.size /
-		    (BUFFER_PARTS * audio_format_frame_size(&dev->sink.format));
+		    (BUFFER_PARTS * pcm_format_frame_size(&dev->sink.format));
 		ret = audio_pcm_start_record(dev->sess, frames,
 		    dev->sink.format.channels, dev->sink.format.sampling_rate,
Index: pace/srv/audio/hound/audio_format.c
===================================================================
--- uspace/srv/audio/hound/audio_format.c	(revision 950110eedb4177666897cb1e24a6cf4168e29741)
+++ 	(revision )
@@ -1,236 +1,0 @@
-/*
- * Copyright (c) 2012 Jan Vesely
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup audio
- * @brief HelenOS sound server
- * @{
- */
-/** @file
- */
-
-#include <assert.h>
-#include <byteorder.h>
-#include <errno.h>
-#include <macros.h>
-#include <stdio.h>
-
-#include "audio_format.h"
-
-#define uint8_t_le2host(x) (x)
-#define host2uint8_t_le(x) (x)
-#define uint8_t_be2host(x) (x)
-#define host2uint8_t_be(x) (x)
-
-#define int8_t_le2host(x) (x)
-#define host2int8_t_le(x) (x)
-
-#define int16_t_le2host(x) uint16_t_le2host(x)
-#define host2int16_t_le(x) host2uint16_t_le(x)
-
-#define int32_t_le2host(x) uint32_t_le2host(x)
-#define host2int32_t_le(x) host2uint32_t_le(x)
-
-#define int8_t_be2host(x) (x)
-#define host2int8_t_be(x) (x)
-
-#define int16_t_be2host(x) uint16_t_be2host(x)
-#define host2int16_t_be(x) host2uint16_t_be(x)
-
-#define int32_t_be2host(x) uint32_t_be2host(x)
-#define host2int32_t_be(x) host2uint32_t_be(x)
-
-// TODO float endian?
-#define float_le2host(x) (x)
-#define float_be2host(x) (x)
-
-#define host2float_le(x) (x)
-#define host2float_be(x) (x)
-
-#define from(x, type, endian) (float)(type ## _ ## endian ## 2host(x))
-#define to(x, type, endian) (float)(host2 ## type ## _ ## endian(x))
-
-static float get_normalized_sample(const void *buffer, size_t size,
-    unsigned frame, unsigned channel, const audio_format_t *f);
-
-bool audio_format_same(const audio_format_t *a, const audio_format_t* b)
-{
-	assert(a);
-	assert(b);
-	return
-	    a->sampling_rate == b->sampling_rate &&
-	    a->channels == b->channels &&
-	    a->sample_format == b->sample_format;
-}
-
-int audio_format_mix(void *dst, const void *src, size_t size, const audio_format_t *f)
-{
-	return audio_format_convert_and_mix(dst, size, src, size, f, f);
-}
-int audio_format_convert_and_mix(void *dst, size_t dst_size, const void *src,
-    size_t src_size, const audio_format_t *sf, const audio_format_t *df)
-{
-	if (!dst || !src || !sf || !df)
-		return EINVAL;
-	const size_t src_frame_size = audio_format_frame_size(sf);
-	if ((src_size % src_frame_size) != 0)
-		return EINVAL;
-
-	const size_t dst_frame_size = audio_format_frame_size(df);
-	if ((src_size % dst_frame_size) != 0)
-		return EINVAL;
-
-	/* This is so ugly it eats kittens, and puppies, and ducklings,
-	 * and all little fluffy things...
-	 */
-#define LOOP_ADD(type, endian, low, high) \
-do { \
-	const unsigned frame_count = dst_size / dst_frame_size; \
-	for (size_t i = 0; i < frame_count; ++i) { \
-		for (unsigned j = 0; j < df->channels; ++j) { \
-			const float a = \
-			    get_normalized_sample(dst, src_size, i, j, df);\
-			const float b = \
-			    get_normalized_sample(src, dst_size, i, j, sf);\
-			float c = (a + b); \
-			if (c < -1.0) c = -1.0; \
-			if (c > 1.0) c = 1.0; \
-			c += 1.0; \
-			c *= ((float)(type)high - (float)(type)low) / 2; \
-			c += (float)(type)low; \
-			type *dst_buf = dst; \
-			const unsigned pos = i * df->channels  + j; \
-			if (pos < (dst_size / sizeof(type))) \
-				dst_buf[pos] = to((type)c, type, endian); \
-		} \
-	} \
-} while (0)
-
-	switch (df->sample_format) {
-	case PCM_SAMPLE_UINT8:
-		LOOP_ADD(uint8_t, le, UINT8_MIN, UINT8_MAX); break;
-	case PCM_SAMPLE_SINT8:
-		LOOP_ADD(uint8_t, le, INT8_MIN, INT8_MAX); break;
-	case PCM_SAMPLE_UINT16_LE:
-		LOOP_ADD(uint16_t, le, UINT16_MIN, UINT16_MAX); break;
-	case PCM_SAMPLE_SINT16_LE:
-		LOOP_ADD(int16_t, le, INT16_MIN, INT16_MAX); break;
-	case PCM_SAMPLE_UINT16_BE:
-		LOOP_ADD(uint16_t, be, UINT16_MIN, UINT16_MAX); break;
-	case PCM_SAMPLE_SINT16_BE:
-		LOOP_ADD(int16_t, be, INT16_MIN, INT16_MAX); break;
-	case PCM_SAMPLE_UINT24_32_LE:
-	case PCM_SAMPLE_UINT32_LE: // TODO this are not right for 24bit
-		LOOP_ADD(uint32_t, le, UINT32_MIN, UINT32_MAX); break;
-	case PCM_SAMPLE_SINT24_32_LE:
-	case PCM_SAMPLE_SINT32_LE:
-		LOOP_ADD(int32_t, le, INT32_MIN, INT32_MAX); break;
-	case PCM_SAMPLE_UINT24_32_BE:
-	case PCM_SAMPLE_UINT32_BE:
-		LOOP_ADD(uint32_t, be, UINT32_MIN, UINT32_MAX); break;
-	case PCM_SAMPLE_SINT24_32_BE:
-	case PCM_SAMPLE_SINT32_BE:
-		LOOP_ADD(int32_t, be, INT32_MIN, INT32_MAX); break;
-	case PCM_SAMPLE_UINT24_LE:
-	case PCM_SAMPLE_SINT24_LE:
-	case PCM_SAMPLE_UINT24_BE:
-	case PCM_SAMPLE_SINT24_BE:
-	case PCM_SAMPLE_FLOAT32:
-	default:
-		return ENOTSUP;
-	}
-	return EOK;
-#undef LOOP_ADD
-}
-
-/** Converts all sample formats to float <-1,1> */
-static float get_normalized_sample(const void *buffer, size_t size,
-    unsigned frame, unsigned channel, const audio_format_t *f)
-{
-	assert(f);
-	if (channel >= f->channels)
-		return 0.0f;
-#define GET(type, endian, low, high) \
-do { \
-	const type *src = buffer; \
-	const size_t sample_count = size / sizeof(type); \
-	const size_t sample_pos = frame * f->channels + channel; \
-	if (sample_pos >= sample_count) {\
-		return 0.0f; \
-	} \
-	float sample = from(src[sample_pos], type, endian); \
-	/* This makes it positive */ \
-	sample -= (float)(type)low; \
-	if (sample < 0.0f) { \
-		printf("SUB MIN failed\n"); \
-	} \
-	/* This makes it <0,2> */ \
-	sample /= (((float)(type)high - (float)(type)low) / 2.0f); \
-	if (sample > 2.0) { \
-		printf("DIV RANGE failed\n"); \
-	} \
-	return sample - 1.0f; \
-} while (0)
-
-	switch (f->sample_format) {
-	case PCM_SAMPLE_UINT8:
-		GET(uint8_t, le, UINT8_MIN, UINT8_MAX);
-	case PCM_SAMPLE_SINT8:
-		GET(int8_t, le, INT8_MIN, INT8_MAX);
-	case PCM_SAMPLE_UINT16_LE:
-		GET(uint16_t, le, UINT16_MIN, UINT16_MAX);
-	case PCM_SAMPLE_SINT16_LE:
-		GET(int16_t, le, INT16_MIN, INT16_MAX);
-	case PCM_SAMPLE_UINT16_BE:
-		GET(uint16_t, be, UINT16_MIN, UINT16_MAX);
-	case PCM_SAMPLE_SINT16_BE:
-		GET(int16_t, be, INT16_MIN, INT16_MAX);
-	case PCM_SAMPLE_UINT24_32_LE:
-	case PCM_SAMPLE_UINT32_LE:
-		GET(uint32_t, le, UINT32_MIN, UINT32_MAX);
-	case PCM_SAMPLE_SINT24_32_LE:
-	case PCM_SAMPLE_SINT32_LE:
-		GET(int32_t, le, INT32_MIN, INT32_MAX);
-	case PCM_SAMPLE_UINT24_32_BE:
-	case PCM_SAMPLE_UINT32_BE:
-		GET(uint32_t, be, UINT32_MIN, UINT32_MAX);
-	case PCM_SAMPLE_SINT24_32_BE:
-	case PCM_SAMPLE_SINT32_BE:
-		GET(int32_t, le, INT32_MIN, INT32_MAX);
-	case PCM_SAMPLE_UINT24_LE:
-	case PCM_SAMPLE_SINT24_LE:
-	case PCM_SAMPLE_UINT24_BE:
-	case PCM_SAMPLE_SINT24_BE:
-	case PCM_SAMPLE_FLOAT32:
-	default: ;
-	}
-	return 0;
-#undef GET
-}
-/**
- * @}
- */
Index: pace/srv/audio/hound/audio_format.h
===================================================================
--- uspace/srv/audio/hound/audio_format.h	(revision 950110eedb4177666897cb1e24a6cf4168e29741)
+++ 	(revision )
@@ -1,83 +1,0 @@
-/*
- * Copyright (c) 2012 Jan Vesely
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup audio
- * @brief HelenOS sound server
- * @{
- */
-/** @file
- */
-
-#ifndef AUDIO_FORMAT_H_
-#define AUDIO_FORMAT_H_
-
-#include <assert.h>
-#include <bool.h>
-#include <pcm_sample_format.h>
-
-
-typedef struct {
-	unsigned channels;
-	unsigned sampling_rate;
-	pcm_sample_format_t sample_format;
-} audio_format_t;
-
-static const audio_format_t AUDIO_FORMAT_DEFAULT = {
-	.channels = 2,
-	.sampling_rate = 44100,
-	.sample_format = PCM_SAMPLE_SINT16_LE,
-	};
-
-static const audio_format_t AUDIO_FORMAT_ANY = {
-	.channels = 0,
-	.sampling_rate = 0,
-	.sample_format = 0,
-	};
-
-
-static inline size_t audio_format_frame_size(const audio_format_t *a)
-{
-	return a->channels * pcm_sample_format_size(a->sample_format);
-}
-
-bool audio_format_same(const audio_format_t *a, const audio_format_t* b);
-static inline bool audio_format_is_any(const audio_format_t *f)
-{
-	return audio_format_same(f, &AUDIO_FORMAT_ANY);
-}
-int audio_format_convert_and_mix(void *dst, size_t dst_size, const void *src,
-    size_t src_size, const audio_format_t *sf, const audio_format_t *df);
-int audio_format_mix(void *dst, const void *src, size_t size, const audio_format_t *f);
-int audio_format_convert(audio_format_t a, void* srca, size_t sizea,
-    audio_format_t b, void* srcb, size_t *sizeb);
-
-#endif
-
-/**
- * @}
- */
Index: uspace/srv/audio/hound/audio_sink.c
===================================================================
--- uspace/srv/audio/hound/audio_sink.c	(revision 950110eedb4177666897cb1e24a6cf4168e29741)
+++ uspace/srv/audio/hound/audio_sink.c	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
@@ -46,5 +46,5 @@
 int audio_sink_init(audio_sink_t *sink, const char *name,
     void *private_data, int (*connection_change)(audio_sink_t *, bool),
-    int (*check_format)(audio_sink_t *sink), const audio_format_t *f)
+    int (*check_format)(audio_sink_t *sink), const pcm_format_t *f)
 {
 	assert(sink);
@@ -79,10 +79,10 @@
 	list_append(&source->link, &sink->sources);
 
-	const audio_format_t old_format = sink->format;
+	const pcm_format_t old_format = sink->format;
 
 	/* The first source for me */
 	if (list_count(&sink->sources) == 1) {
 		/* Set audio format according to the first source */
-		if (audio_format_is_any(&sink->format)) {
+		if (pcm_format_is_any(&sink->format)) {
 			int ret = audio_sink_set_format(sink, &source->format);
 			if (ret != EOK)
@@ -110,15 +110,15 @@
 }
 
-int audio_sink_set_format(audio_sink_t *sink, const audio_format_t *format)
+int audio_sink_set_format(audio_sink_t *sink, const pcm_format_t *format)
 {
 	assert(sink);
 	assert(format);
-	if (!audio_format_is_any(&sink->format)) {
+	if (!pcm_format_is_any(&sink->format)) {
 		log_debug("Sink %s already has a format", sink->name);
 		return EEXISTS;
 	}
-	const audio_format_t old_format;
+	const pcm_format_t old_format;
 
-	if (audio_format_is_any(format)) {
+	if (pcm_format_is_any(format)) {
 		log_verbose("Setting DEFAULT format for sink %s", sink->name);
 		sink->format = AUDIO_FORMAT_DEFAULT;
Index: uspace/srv/audio/hound/audio_sink.h
===================================================================
--- uspace/srv/audio/hound/audio_sink.h	(revision 950110eedb4177666897cb1e24a6cf4168e29741)
+++ uspace/srv/audio/hound/audio_sink.h	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
@@ -41,7 +41,7 @@
 #include <bool.h>
 #include <fibril.h>
+#include <pcm/format.h>
 
 #include "audio_source.h"
-#include "audio_format.h"
 
 typedef struct audio_sink audio_sink_t;
@@ -51,5 +51,5 @@
 	list_t sources;
 	const char *name;
-	audio_format_t format;
+	pcm_format_t format;
 	void *private_data;
 	int (*connection_change)(audio_sink_t *, bool);
@@ -64,8 +64,8 @@
 int audio_sink_init(audio_sink_t *sink, const char *name,
     void *private_data, int (*connection_change)(audio_sink_t *, bool),
-    int (*check_format)(audio_sink_t *), const audio_format_t *f);
+    int (*check_format)(audio_sink_t *), const pcm_format_t *f);
 void audio_sink_fini(audio_sink_t *sink);
 
-int audio_sink_set_format(audio_sink_t *sink, const audio_format_t *format);
+int audio_sink_set_format(audio_sink_t *sink, const pcm_format_t *format);
 int audio_sink_add_source(audio_sink_t *sink, audio_source_t *source);
 int audio_sink_remove_source(audio_sink_t *sink, audio_source_t *source);
Index: uspace/srv/audio/hound/audio_source.c
===================================================================
--- uspace/srv/audio/hound/audio_source.c	(revision 950110eedb4177666897cb1e24a6cf4168e29741)
+++ uspace/srv/audio/hound/audio_source.c	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
@@ -49,5 +49,5 @@
     int (*connection_change)(audio_source_t *),
     int (*update_available_data)(audio_source_t *, size_t),
-    const audio_format_t *f)
+    const pcm_format_t *f)
 {
 	assert(source);
@@ -82,10 +82,10 @@
 	assert(source);
 	audio_sink_t *old_sink = source->connected_sink;
-	const audio_format_t old_format = source->format;
+	const pcm_format_t old_format = source->format;
 
 	source->connected_sink = sink;
-	if (audio_format_is_any(&source->format)) {
+	if (pcm_format_is_any(&source->format)) {
 		assert(sink);
-		assert(!audio_format_is_any(&sink->format));
+		assert(!pcm_format_is_any(&sink->format));
 		source->format = sink->format;
 	}
@@ -102,5 +102,5 @@
 
 int audio_source_add_self(audio_source_t *source, void *buffer, size_t size,
-    const audio_format_t *f)
+    const pcm_format_t *f)
 {
 	assert(source);
@@ -120,6 +120,6 @@
 		return ENOTSUP;
 	}
-	const size_t src_frame_size = audio_format_frame_size(&source->format);
-	const size_t dst_frames = size / audio_format_frame_size(f);
+	const size_t src_frame_size = pcm_format_frame_size(&source->format);
+	const size_t dst_frames = size / pcm_format_frame_size(f);
 
 	if (source->available_data.position == NULL ||
@@ -135,5 +135,5 @@
 	}
 
-	const int ret = audio_format_convert_and_mix(buffer, size,
+	const int ret = pcm_format_convert_and_mix(buffer, size,
 	       source->available_data.position, source->available_data.size,
 	       &source->format, f);
Index: uspace/srv/audio/hound/audio_source.h
===================================================================
--- uspace/srv/audio/hound/audio_source.h	(revision 950110eedb4177666897cb1e24a6cf4168e29741)
+++ uspace/srv/audio/hound/audio_source.h	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
@@ -39,8 +39,5 @@
 #include <adt/list.h>
 #include <bool.h>
-#include <pcm_sample_format.h>
-
-
-#include "audio_format.h"
+#include <pcm/format.h>
 
 struct audio_sink;
@@ -50,5 +47,5 @@
 	link_t link;
 	const char *name;
-	audio_format_t format;
+	pcm_format_t format;
 	void *private_data;
 	int (*connection_change)(audio_source_t *source);
@@ -70,10 +67,10 @@
     int (*connection_change)(audio_source_t *),
     int (*update_available_data)(audio_source_t *, size_t),
-    const audio_format_t *f);
+    const pcm_format_t *f);
 void audio_source_fini(audio_source_t *source);
 int audio_source_connected(audio_source_t *source, struct audio_sink *sink);
 int audio_source_add_self(audio_source_t *source, void *buffer, size_t size,
-    const audio_format_t *f);
-static inline const audio_format_t *audio_source_format(const audio_source_t *s)
+    const pcm_format_t *f);
+static inline const pcm_format_t *audio_source_format(const audio_source_t *s)
 {
 	assert(s);
Index: uspace/srv/audio/hound/hound.h
===================================================================
--- uspace/srv/audio/hound/hound.h	(revision 950110eedb4177666897cb1e24a6cf4168e29741)
+++ uspace/srv/audio/hound/hound.h	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
@@ -42,8 +42,8 @@
 #include <errno.h>
 #include <fibril_synch.h>
+#include <pcm/format.h>
 
 #include "audio_source.h"
 #include "audio_sink.h"
-#include "audio_format.h"
 
 
Index: uspace/srv/audio/hound/main.c
===================================================================
--- uspace/srv/audio/hound/main.c	(revision 950110eedb4177666897cb1e24a6cf4168e29741)
+++ uspace/srv/audio/hound/main.c	(revision ea6c83870417e73e052e92cb12eed894e739dbca)
@@ -71,5 +71,5 @@
 	LIST_INITIALIZE(local_playback);
 	LIST_INITIALIZE(local_recording);
-	audio_format_t format = {0};
+	pcm_format_t format = {0};
 	const char *name = NULL;
 	async_sess_t *sess = NULL;
