Index: uspace/app/wavplay/Makefile
===================================================================
--- uspace/app/wavplay/Makefile	(revision 57e8b3ba054d7a008b430e7b6b67994b03197240)
+++ uspace/app/wavplay/Makefile	(revision eceb300f1af5b2c6d6ef5514075ff83891dc86a0)
@@ -31,6 +31,8 @@
 
 LIBS = \
+	$(LIBHOUND_PREFIX)/libhound.a
 
 EXTRA_CFLAGS = \
+	-I $(LIBHOUND_PREFIX)/include
 
 SOURCES = \
Index: uspace/app/wavplay/wavplay.c
===================================================================
--- uspace/app/wavplay/wavplay.c	(revision 57e8b3ba054d7a008b430e7b6b67994b03197240)
+++ uspace/app/wavplay/wavplay.c	(revision eceb300f1af5b2c6d6ef5514075ff83891dc86a0)
@@ -34,53 +34,35 @@
  */
 
-#include <async.h>
 #include <assert.h>
 #include <errno.h>
+#include <fibril_synch.h>
 #include <str_error.h>
-#include <str.h>
-#include <devman.h>
-#include <fibril_synch.h>
 #include <stdio.h>
-#include <sys/mman.h>
-#include <loc.h>
+
+#include <hound/client.h>
 
 #include <pcm_sample_format.h>
 
 #include <stdio.h>
-#include <macros.h>
 
 #include "wave.h"
 
-#define SERVICE "audio/hound"
-#define DEFAULT_DEVICE "default" //"devices/\\hw\\pci0\\00:01.0\\sb16\\pcm"
-#define SUBBUFFERS 2
 #define NAME_MAX 32
 char name[NAME_MAX + 1];
 
 typedef struct {
-	struct {
-		void *base;
-		size_t size;
-		unsigned id;
-		void* position;
-	} buffer;
 	FILE* source;
 	volatile bool playing;
 	fibril_mutex_t mutex;
 	fibril_condvar_t cv;
-	async_exch_t *server;
+	hound_sess_t *server;
 } playback_t;
 
-static void playback_initialize(playback_t *pb, async_exch_t *exch)
+static void playback_initialize(playback_t *pb, hound_sess_t *sess)
 {
-	assert(exch);
 	assert(pb);
-	pb->buffer.id = 0;
-	pb->buffer.base = NULL;
-	pb->buffer.size = 0;
-	pb->buffer.position = NULL;
 	pb->playing = false;
 	pb->source = NULL;
-	pb->server = exch;
+	pb->server = sess;
 	fibril_mutex_initialize(&pb->mutex);
 	fibril_condvar_initialize(&pb->cv);
@@ -88,46 +70,26 @@
 
 
-static void data_callback(ipc_callid_t iid, ipc_call_t *icall, void* arg)
+static void data_callback(void* arg, void *buffer, ssize_t size)
 {
-	async_answer_0(iid, EOK);
 	playback_t *pb = arg;
+	assert(pb);
 
-	while (1) {
-		size_t size = 0;
-		if (!async_data_read_receive(&iid, &size)) {
-			printf("Data request failed");
-			continue;
+	if (size > 0) {
+		const ssize_t bytes =
+		    fread(buffer, sizeof(uint8_t), size, pb->source);
+		printf("%zu bytes ready\n", bytes);
+		if (bytes < size) {
+			printf(" requested: %zd ready: %zd zero: %zd\n",
+				size, bytes, size - bytes);
+			bzero(buffer + bytes, size - bytes);
 		}
-//		printf("Server asked for more(%zu) data\n", size);
-		if (pb->buffer.size < size) {
-			printf("Reallocating buffer: %zu -> %zu\n",
-			    pb->buffer.size, size);
-			pb->buffer.base = realloc(pb->buffer.base, size);
-			pb->buffer.size = size;
-		}
-		const size_t bytes = fread(pb->buffer.base, sizeof(uint8_t),
-		   size, pb->source);
-//		printf("%zu bytes ready\n", bytes);
-		if (bytes < pb->buffer.size) {
-			bzero(pb->buffer.base + bytes, size - bytes);
-		}
-		async_data_read_finalize(iid, pb->buffer.base, size);
 		if (bytes == 0) {
-			/* Disconnect */
-			aid_t id = async_send_0(pb->server,
-			    IPC_FIRST_USER_METHOD + 5, NULL);
-			async_data_write_start(pb->server, name, str_size(name) + 1);
-			async_data_write_start(pb->server, DEFAULT_DEVICE,
-			    1+str_size(DEFAULT_DEVICE));
-			async_wait_for(id, NULL);
-
-			printf("\nPlayback terminated\n");
-			fibril_mutex_lock(&pb->mutex);
 			pb->playing = false;
 			fibril_condvar_signal(&pb->cv);
-			fibril_mutex_unlock(&pb->mutex);
-			return;
 		}
-
+	} else {
+		printf("Got error %s.\n", str_error(size));
+		pb->playing = false;
+		fibril_condvar_signal(&pb->cv);
 	}
 }
@@ -137,36 +99,24 @@
 	assert(pb);
 	/* Create playback client */
-	aid_t id = async_send_3(pb->server, IPC_FIRST_USER_METHOD, channels,
-	    rate, format, NULL);
-	int ret = async_data_write_start(pb->server, name, str_size(name) + 1);
+	int ret = hound_register_playback(pb->server, name, channels, rate,
+	    format, data_callback, pb);
 	if (ret != EOK) {
-		printf("Failed to send client name: %s\n", str_error(ret));
-		async_forget(id);
-		return;
-	}
-	ret = async_connect_to_me(pb->server, 0, 0, 0, data_callback, pb);
-	if (ret != EOK) {
-		printf("Failed to establish callback: %s\n", str_error(ret));
-		async_forget(id);
-		return;
-	}
-	async_wait_for(id, (sysarg_t*)&ret);
-	if (ret != EOK) {
-		printf("Failed to create client: %s\n", str_error(ret));
-		async_forget(id);
+		printf("Failed to register playback: %s\n", str_error(ret));
 		return;
 	}
 
 	/* Connect */
-	id = async_send_0(pb->server, IPC_FIRST_USER_METHOD + 4, NULL);
-	async_data_write_start(pb->server, name, str_size(name) + 1);
-	async_data_write_start(pb->server, DEFAULT_DEVICE, 1+str_size(DEFAULT_DEVICE));
-	async_wait_for(id, NULL);
+	ret = hound_create_connection(pb->server, name, DEFAULT_SINK);
+	if (ret == EOK) {
+		fibril_mutex_lock(&pb->mutex);
+		for (pb->playing = true; pb->playing;
+		    fibril_condvar_wait(&pb->cv, &pb->mutex));
+		fibril_mutex_unlock(&pb->mutex);
 
-	fibril_mutex_lock(&pb->mutex);
+		hound_destroy_connection(pb->server, name, DEFAULT_SINK);
+	} else
+		printf("Failed to connect: %s\n", str_error(ret));
 
-	for (pb->playing = true; pb->playing;
-	    fibril_condvar_wait(&pb->cv, &pb->mutex));
-	fibril_mutex_unlock(&pb->mutex);
+	hound_unregister_playback(pb->server, name);
 }
 
@@ -177,11 +127,4 @@
 	const char *file = argv[1];
 
-	service_id_t id = 0;
-	int ret = loc_service_get_id(SERVICE, &id, 0);
-	if (ret != EOK) {
-		printf("Failed to get hound service id\n");
-		return 1;
-	}
-
 	task_id_t tid = task_get_id();
 	snprintf(name, NAME_MAX, "%s%" PRIu64 ":%s", argv[0], tid, file);
@@ -189,5 +132,5 @@
 	printf("Client name: %s\n", name);
 
-	async_sess_t *sess = loc_service_connect(EXCHANGE_SERIALIZE, id, 0);
+	hound_sess_t *sess = hound_get_session();
 	if (!sess) {
 		printf("Failed to connect to hound service\n");
@@ -195,19 +138,11 @@
 	}
 
-	async_exch_t *exch = async_exchange_begin(sess);
-	if (!exch) {
-		printf("Failed to create exchange\n");
-		async_hangup(sess);
-		return 1;
-	}
-
-
 	playback_t pb;
-	playback_initialize(&pb, exch);
+	playback_initialize(&pb, sess);
 	pb.source = fopen(file, "rb");
 	if (pb.source == NULL) {
-		ret = ENOENT;
 		printf("Failed to open %s.\n", file);
-		goto cleanup;
+		hound_release_session(sess);
+		return 1;
 	}
 	wave_header_t header;
@@ -216,19 +151,16 @@
 	pcm_sample_format_t format;
 	const char *error;
-	ret = wav_parse_header(&header, NULL, NULL, &channels, &rate, &format,
-	    &error);
+	const int ret = wav_parse_header(&header, NULL, NULL, &channels, &rate,
+	    &format, &error);
 	if (ret != EOK) {
 		printf("Error parsing wav header: %s.\n", error);
 		fclose(pb.source);
-		goto cleanup;
+		hound_release_session(sess);
+		return 1;
 	}
 
 	play(&pb, channels, rate, format);
 
-cleanup:
-	async_exchange_end(exch);
-
-	async_hangup(sess);
-
+	hound_release_session(sess);
 	return 0;
 }
