Index: uspace/app/wavplay/drec.c
===================================================================
--- uspace/app/wavplay/drec.c	(revision 795e2bfe0ca714517bdac2b7abae8091c5f88ee9)
+++ uspace/app/wavplay/drec.c	(revision 0e4c5f0b7a21f09f35471fba7a626dff3790ce97)
@@ -47,5 +47,5 @@
 
 
-#define BUFFER_PARTS   2
+#define BUFFER_PARTS   16
 
 /** Recording format */
@@ -103,7 +103,7 @@
 			printf("Recording terminated\n");
 			record = false;
+			break;
 		case PCM_EVENT_FRAMES_CAPTURED:
 			printf("%" PRIun " frames\n", IPC_GET_ARG1(call));
-			async_answer_0(callid, EOK);
 			break;
 		default:
@@ -111,5 +111,9 @@
 			async_answer_0(callid, ENOTSUP);
 			continue;
-
+		}
+
+		if (!record) {
+			async_answer_0(callid, EOK);
+			break;
 		}
 
@@ -156,4 +160,8 @@
 	printf("\n");
 	audio_pcm_stop_capture(rec->device);
+	/* XXX Control returns even before we can be sure callbacks finished */
+	printf("Delay before playback termination\n");
+	async_usleep(1000000);
+	printf("Terminate playback\n");
 }
 
Index: uspace/app/wavplay/main.c
===================================================================
--- uspace/app/wavplay/main.c	(revision 795e2bfe0ca714517bdac2b7abae8091c5f88ee9)
+++ uspace/app/wavplay/main.c	(revision 0e4c5f0b7a21f09f35471fba7a626dff3790ce97)
@@ -308,4 +308,5 @@
 			if (direct) {
 				drecord(device, file);
+				continue;
 			} else {
 				printf("Indirect recording is not supported "
Index: uspace/app/wavplay/wave.c
===================================================================
--- uspace/app/wavplay/wave.c	(revision 795e2bfe0ca714517bdac2b7abae8091c5f88ee9)
+++ uspace/app/wavplay/wave.c	(revision 0e4c5f0b7a21f09f35471fba7a626dff3790ce97)
@@ -116,5 +116,5 @@
 		*channels = uint16_t_le2host(header->channels);
 	if (format) {
-		const unsigned size = uint32_t_le2host(header->sample_size);
+		const unsigned size = uint16_t_le2host(header->sample_size);
 		switch (size) {
 		case 8: *format = PCM_SAMPLE_UINT8; break;
@@ -157,5 +157,5 @@
 	header->channels = host2uint32_t_le(format.channels);
 	header->sample_size =
-	    host2uint32_t_le(pcm_sample_format_size(format.sample_format));
+	    host2uint16_t_le(pcm_sample_format_size(format.sample_format) * 8);
 }
 /**
Index: uspace/drv/audio/hdaudio/codec.c
===================================================================
--- uspace/drv/audio/hdaudio/codec.c	(revision 795e2bfe0ca714517bdac2b7abae8091c5f88ee9)
+++ uspace/drv/audio/hdaudio/codec.c	(revision 0e4c5f0b7a21f09f35471fba7a626dff3790ce97)
@@ -437,4 +437,9 @@
 	}
 
+	if ((pcaps & BIT_V(uint32_t, pwc_input)) != 0) {
+		ddf_msg(LVL_NOTE, "PIN %d will enable input", aw);
+	    	pctl = pctl | BIT_V(uint8_t, pctl_in_enable);
+	}
+
 	if ((pcaps & BIT_V(uint32_t, pwc_hpd)) != 0) {
 		ddf_msg(LVL_NOTE, "PIN %d will enable headphone drive", aw);
@@ -503,4 +508,5 @@
 	codec->hda = hda;
 	codec->address = address;
+	codec->in_aw = -1;
 
 	rc = hda_get_subnc(codec, 0, &sfg, &nfg);
@@ -587,4 +593,24 @@
 				ddf_msg(LVL_NOTE, "Output widget %d: rates=0x%x formats=0x%x",
 				    aw, rates, formats);
+			} else if (awtype == awt_audio_input) {
+				if (codec->in_aw < 0) {
+					ddf_msg(LVL_NOTE, "Selected input "
+					    "widget %d\n", aw);
+					codec->in_aw = aw;
+				} else {
+					ddf_msg(LVL_NOTE, "Ignoring input "
+					    "widget %d\n", aw);
+				}
+
+				rc = hda_get_supp_rates(codec, aw, &rates);
+				if (rc != EOK)
+					goto error;
+
+				rc = hda_get_supp_formats(codec, aw, &formats);
+				if (rc != EOK)
+					goto error;
+
+				ddf_msg(LVL_NOTE, "Input widget %d: rates=0x%x formats=0x%x",
+				    aw, rates, formats);
 			}
 
@@ -623,14 +649,35 @@
 		/* Configure converter */
 
-		ddf_msg(LVL_NOTE, "Configure converter format");
+		ddf_msg(LVL_NOTE, "Configure output converter format");
 		rc = hda_set_converter_fmt(codec, out_aw, stream->fmt);
 		if (rc != EOK)
 			goto error;
 
-		ddf_msg(LVL_NOTE, "Configure converter stream, channel");
+		ddf_msg(LVL_NOTE, "Configure output converter stream, channel");
 		rc = hda_set_converter_ctl(codec, out_aw, stream->sid, 0);
 		if (rc != EOK)
 			goto error;
 	}
+
+	return EOK;
+error:
+	return rc;
+}
+
+int hda_in_converter_setup(hda_codec_t *codec, hda_stream_t *stream)
+{
+	int rc;
+
+	/* Configure converter */
+
+	ddf_msg(LVL_NOTE, "Configure input converter format");
+	rc = hda_set_converter_fmt(codec, codec->in_aw, stream->fmt);
+	if (rc != EOK)
+		goto error;
+
+	ddf_msg(LVL_NOTE, "Configure input converter stream, channel");
+	rc = hda_set_converter_ctl(codec, codec->in_aw, stream->sid, 0);
+	if (rc != EOK)
+		goto error;
 
 	return EOK;
Index: uspace/drv/audio/hdaudio/codec.h
===================================================================
--- uspace/drv/audio/hdaudio/codec.h	(revision 795e2bfe0ca714517bdac2b7abae8091c5f88ee9)
+++ uspace/drv/audio/hdaudio/codec.h	(revision 0e4c5f0b7a21f09f35471fba7a626dff3790ce97)
@@ -47,4 +47,5 @@
 	int out_aw_num;
 	int out_aw_sel;
+	int in_aw;
 } hda_codec_t;
 
@@ -52,4 +53,5 @@
 extern void hda_codec_fini(hda_codec_t *);
 extern int hda_out_converter_setup(hda_codec_t *, hda_stream_t *);
+extern int hda_in_converter_setup(hda_codec_t *, hda_stream_t *);
 
 #endif
Index: uspace/drv/audio/hdaudio/hdactl.c
===================================================================
--- uspace/drv/audio/hdaudio/hdactl.c	(revision 795e2bfe0ca714517bdac2b7abae8091c5f88ee9)
+++ uspace/drv/audio/hdaudio/hdactl.c	(revision 0e4c5f0b7a21f09f35471fba7a626dff3790ce97)
@@ -562,5 +562,6 @@
 	ctl->bss = BIT_RANGE_EXTRACT(uint16_t, gcap_bss_h, gcap_bss_l, gcap);
 	ddf_msg(LVL_NOTE, "GCAP: 0x%x (64OK=%d)", gcap, ctl->ok64bit);
-
+	ddf_msg(LVL_NOTE, "iss: %d, oss: %d, bss: %d\n",
+	    ctl->iss, ctl->oss, ctl->bss);
 	/* Give codecs enough time to enumerate themselves */
 	async_usleep(codec_enum_wait_us);
Index: uspace/drv/audio/hdaudio/hdaudio.c
===================================================================
--- uspace/drv/audio/hdaudio/hdaudio.c	(revision 795e2bfe0ca714517bdac2b7abae8091c5f88ee9)
+++ uspace/drv/audio/hdaudio/hdaudio.c	(revision 0e4c5f0b7a21f09f35471fba7a626dff3790ce97)
@@ -385,5 +385,11 @@
 			hda_pcm_event(hda, PCM_EVENT_FRAMES_PLAYED);
 			hda_pcm_event(hda, PCM_EVENT_FRAMES_PLAYED);
+		} else if (hda->capturing) {
+			hda_pcm_event(hda, PCM_EVENT_FRAMES_CAPTURED);
+			hda_pcm_event(hda, PCM_EVENT_FRAMES_CAPTURED);
+			hda_pcm_event(hda, PCM_EVENT_FRAMES_CAPTURED);
+			hda_pcm_event(hda, PCM_EVENT_FRAMES_CAPTURED);
 		}
+
 		hda_unlock(hda);
 	}
Index: uspace/drv/audio/hdaudio/hdaudio.h
===================================================================
--- uspace/drv/audio/hdaudio/hdaudio.h	(revision 795e2bfe0ca714517bdac2b7abae8091c5f88ee9)
+++ uspace/drv/audio/hdaudio/hdaudio.h	(revision 0e4c5f0b7a21f09f35471fba7a626dff3790ce97)
@@ -55,5 +55,7 @@
 	struct hda_ctl *ctl;
 	struct hda_stream *pcm_stream;
+	struct hda_stream_buffers *pcm_buffers;
 	bool playing;
+	bool capturing;
 } hda_t;
 
Index: uspace/drv/audio/hdaudio/pcm_iface.c
===================================================================
--- uspace/drv/audio/hdaudio/pcm_iface.c	(revision 795e2bfe0ca714517bdac2b7abae8091c5f88ee9)
+++ uspace/drv/audio/hdaudio/pcm_iface.c	(revision 0e4c5f0b7a21f09f35471fba7a626dff3790ce97)
@@ -100,11 +100,16 @@
 static unsigned hda_query_cap(ddf_fun_t *fun, audio_cap_t cap)
 {
+	hda_t *hda = fun_to_hda(fun);
+
 	ddf_msg(LVL_NOTE, "hda_query_cap(%d)", cap);
 	switch (cap) {
 	case AUDIO_CAP_PLAYBACK:
 	case AUDIO_CAP_INTERRUPT:
+		/* XXX Only if we have an output converter */
 		return 1;
+	case AUDIO_CAP_CAPTURE:
+		/* Yes if we have an input converter */
+		return hda->ctl->codec->in_aw >= 0;
 	case AUDIO_CAP_BUFFER_POS:
-	case AUDIO_CAP_CAPTURE:
 		return 0;
 	case AUDIO_CAP_MAX_BUFFER:
@@ -148,8 +153,93 @@
 {
 	hda_t *hda = fun_to_hda(fun);
+	int rc;
 
 	hda_lock(hda);
 
 	ddf_msg(LVL_NOTE, "hda_get_buffer(): hda=%p", hda);
+	if (hda->pcm_buffers != NULL) {
+		hda_unlock(hda);
+		return EBUSY;
+	}
+
+	ddf_msg(LVL_NOTE, "hda_get_buffer() - allocate stream buffers");
+	rc = hda_stream_buffers_alloc(hda, &hda->pcm_buffers);
+	if (rc != EOK) {
+		assert(rc == ENOMEM);
+		hda_unlock(hda);
+		return ENOMEM;
+	}
+
+	ddf_msg(LVL_NOTE, "hda_get_buffer() - fill info");
+	/* XXX This is only one buffer */
+	*buffer = hda->pcm_buffers->buf[0];
+	*size = hda->pcm_buffers->bufsize * hda->pcm_buffers->nbuffers;
+
+	ddf_msg(LVL_NOTE, "hda_get_buffer() returing EOK, buffer=%p, size=%zu",
+	    *buffer, *size);
+
+	hda_unlock(hda);
+	return EOK;
+}
+
+static int hda_get_buffer_position(ddf_fun_t *fun, size_t *pos)
+{
+	ddf_msg(LVL_NOTE, "hda_get_buffer_position()");
+	return ENOTSUP;
+}
+
+static int hda_set_event_session(ddf_fun_t *fun, async_sess_t *sess)
+{
+	hda_t *hda = fun_to_hda(fun);
+
+	ddf_msg(LVL_NOTE, "hda_set_event_session()");
+	hda_lock(hda);
+	hda->ev_sess = sess;
+	hda_unlock(hda);
+
+	return EOK;
+}
+
+static async_sess_t *hda_get_event_session(ddf_fun_t *fun)
+{
+	hda_t *hda = fun_to_hda(fun);
+	async_sess_t *sess;
+
+	ddf_msg(LVL_NOTE, "hda_get_event_session()");
+
+	hda_lock(hda);
+	sess = hda->ev_sess;
+	hda_unlock(hda);
+
+	return sess;
+}
+
+static int hda_release_buffer(ddf_fun_t *fun)
+{
+	hda_t *hda = fun_to_hda(fun);
+
+	hda_lock(hda);
+
+	ddf_msg(LVL_NOTE, "hda_release_buffer()");
+	if (hda->pcm_buffers == NULL) {
+		hda_unlock(hda);
+		return EINVAL;
+	}
+
+	hda_stream_buffers_free(hda->pcm_buffers);
+
+	hda_unlock(hda);
+	return EOK;
+}
+
+static int hda_start_playback(ddf_fun_t *fun, unsigned frames,
+    unsigned channels, unsigned rate, pcm_sample_format_t format)
+{
+	hda_t *hda = fun_to_hda(fun);
+	int rc;
+
+	ddf_msg(LVL_NOTE, "hda_start_playback()");
+	hda_lock(hda);
+
 	if (hda->pcm_stream != NULL) {
 		hda_unlock(hda);
@@ -162,91 +252,22 @@
 	fmt = (fmt_base_44khz << fmt_base) | (fmt_bits_16 << fmt_bits_l) | 1;
 
-	ddf_msg(LVL_NOTE, "hda_get_buffer() - create stream");
-	hda->pcm_stream = hda_stream_create(hda, sdir_output, fmt);
+	ddf_msg(LVL_NOTE, "hda_start_playback() - create output stream");
+	hda->pcm_stream = hda_stream_create(hda, sdir_output, hda->pcm_buffers,
+	    fmt);
 	if (hda->pcm_stream == NULL) {
 		hda_unlock(hda);
 		return EIO;
 	}
-
-	ddf_msg(LVL_NOTE, "hda_get_buffer() - fill info");
-	/* XXX This is only one buffer */
-	*buffer = hda->pcm_stream->buf[0];
-	*size = hda->pcm_stream->bufsize * hda->pcm_stream->nbuffers;
-
-	ddf_msg(LVL_NOTE, "hda_get_buffer() retturing EOK, buffer=%p, size=%zu",
-	    *buffer, *size);
-
-	hda_unlock(hda);
-	return EOK;
-}
-
-static int hda_get_buffer_position(ddf_fun_t *fun, size_t *pos)
-{
-	ddf_msg(LVL_NOTE, "hda_get_buffer_position()");
-	return ENOTSUP;
-}
-
-static int hda_set_event_session(ddf_fun_t *fun, async_sess_t *sess)
-{
-	hda_t *hda = fun_to_hda(fun);
-
-	ddf_msg(LVL_NOTE, "hda_set_event_session()");
-	hda_lock(hda);
-	hda->ev_sess = sess;
-	hda_unlock(hda);
-
-	return EOK;
-}
-
-static async_sess_t *hda_get_event_session(ddf_fun_t *fun)
-{
-	hda_t *hda = fun_to_hda(fun);
-	async_sess_t *sess;
-
-	ddf_msg(LVL_NOTE, "hda_get_event_session()");
-
-	hda_lock(hda);
-	sess = hda->ev_sess;
-	hda_unlock(hda);
-
-	return sess;
-}
-
-static int hda_release_buffer(ddf_fun_t *fun)
-{
-	hda_t *hda = fun_to_hda(fun);
-
-	hda_lock(hda);
-
-	ddf_msg(LVL_NOTE, "hda_release_buffer()");
-	if (hda->pcm_stream == NULL) {
-		hda_unlock(hda);
-		return EINVAL;
-	}
-
-	hda_stream_destroy(hda->pcm_stream);
-	hda->pcm_stream = NULL;
-
-	hda_unlock(hda);
-	return EOK;
-}
-
-static int hda_start_playback(ddf_fun_t *fun, unsigned frames,
-    unsigned channels, unsigned rate, pcm_sample_format_t format)
-{
-	hda_t *hda = fun_to_hda(fun);
-	int rc;
-
-	ddf_msg(LVL_NOTE, "hda_start_playback()");
-	hda_lock(hda);
 
 	rc = hda_out_converter_setup(hda->ctl->codec, hda->pcm_stream);
 	if (rc != EOK) {
+		hda_stream_destroy(hda->pcm_stream);
+		hda->pcm_stream = NULL;
 		hda_unlock(hda);
 		return rc;
 	}
 
+	hda->playing = true;
 	hda_stream_start(hda->pcm_stream);
-	hda->playing = true;
 	hda_unlock(hda);
 	return EOK;
@@ -262,4 +283,7 @@
 	hda_stream_reset(hda->pcm_stream);
 	hda->playing = false;
+	hda_stream_destroy(hda->pcm_stream);
+	hda->pcm_stream = NULL;
+
 	hda_unlock(hda);
 
@@ -271,12 +295,57 @@
     unsigned rate, pcm_sample_format_t format)
 {
+	hda_t *hda = fun_to_hda(fun);
+	int rc;
+
 	ddf_msg(LVL_NOTE, "hda_start_capture()");
-	return ENOTSUP;
+	hda_lock(hda);
+
+	if (hda->pcm_stream != NULL) {
+		hda_unlock(hda);
+		return EBUSY;
+	}
+
+	/* XXX Choose appropriate parameters */
+	uint32_t fmt;
+	/* 48 kHz, 16-bits, 1 channel */
+	fmt = (fmt_base_44khz << fmt_base) | (fmt_bits_16 << fmt_bits_l) | 1;
+
+	ddf_msg(LVL_NOTE, "hda_start_capture() - create input stream");
+	hda->pcm_stream = hda_stream_create(hda, sdir_input, hda->pcm_buffers,
+	    fmt);
+	if (hda->pcm_stream == NULL) {
+		hda_unlock(hda);
+		return EIO;
+	}
+
+	rc = hda_in_converter_setup(hda->ctl->codec, hda->pcm_stream);
+	if (rc != EOK) {
+		hda_stream_destroy(hda->pcm_stream);
+		hda->pcm_stream = NULL;
+		hda_unlock(hda);
+		return rc;
+	}
+
+	hda->capturing = true;
+	hda_stream_start(hda->pcm_stream);
+	hda_unlock(hda);
+	return EOK;
 }
 
 static int hda_stop_capture(ddf_fun_t *fun, bool immediate)
 {
+	hda_t *hda = fun_to_hda(fun);
+
 	ddf_msg(LVL_NOTE, "hda_stop_capture()");
-	return ENOTSUP;
+	hda_lock(hda);
+	hda_stream_stop(hda->pcm_stream);
+	hda_stream_reset(hda->pcm_stream);
+	hda->capturing = false;
+	hda_stream_destroy(hda->pcm_stream);
+	hda->pcm_stream = NULL;
+	hda_unlock(hda);
+
+	hda_pcm_event(hda, PCM_EVENT_CAPTURE_TERMINATED);
+	return EOK;
 }
 
Index: uspace/drv/audio/hdaudio/stream.c
===================================================================
--- uspace/drv/audio/hdaudio/stream.c	(revision 795e2bfe0ca714517bdac2b7abae8091c5f88ee9)
+++ uspace/drv/audio/hdaudio/stream.c	(revision 0e4c5f0b7a21f09f35471fba7a626dff3790ce97)
@@ -48,15 +48,22 @@
 #include "stream.h"
 
-static int hda_stream_buffers_alloc(hda_stream_t *stream)
+int hda_stream_buffers_alloc(hda_t *hda, hda_stream_buffers_t **rbufs)
 {
 	void *bdl;
 	void *buffer;
 	uintptr_t buffer_phys;
+	hda_stream_buffers_t *bufs = NULL;
 	size_t i;
 //	size_t j, k;
 	int rc;
 
-	stream->nbuffers = 4;
-	stream->bufsize = 16384;
+	bufs = calloc(1, sizeof(hda_stream_buffers_t));
+	if (bufs == NULL) {
+		rc = ENOMEM;
+		goto error;
+	}
+
+	bufs->nbuffers = 4;
+	bufs->bufsize = 16384;
 
 	/*
@@ -65,28 +72,28 @@
 	 */
 	bdl = AS_AREA_ANY;
-	rc = dmamem_map_anonymous(stream->nbuffers * sizeof(hda_buffer_desc_t),
-	    stream->hda->ctl->ok64bit ? 0 : DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE,
-	    0, &stream->bdl_phys, &bdl);
+	rc = dmamem_map_anonymous(bufs->nbuffers * sizeof(hda_buffer_desc_t),
+	    hda->ctl->ok64bit ? 0 : DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE,
+	    0, &bufs->bdl_phys, &bdl);
 	if (rc != EOK)
 		goto error;
 
-	stream->bdl = bdl;
+	bufs->bdl = bdl;
 
 	/* Allocate arrays of buffer pointers */
 
-	stream->buf = calloc(stream->nbuffers, sizeof(void *));
-	if (stream->buf == NULL)
-		goto error;
-
-	stream->buf_phys = calloc(stream->nbuffers, sizeof(uintptr_t));
-	if (stream->buf_phys == NULL)
+	bufs->buf = calloc(bufs->nbuffers, sizeof(void *));
+	if (bufs->buf == NULL)
+		goto error;
+
+	bufs->buf_phys = calloc(bufs->nbuffers, sizeof(uintptr_t));
+	if (bufs->buf_phys == NULL)
 		goto error;
 
 	/* Allocate buffers */
 /*
-	for (i = 0; i < stream->nbuffers; i++) {
+	for (i = 0; i < bufs->nbuffers; i++) {
 		buffer = AS_AREA_ANY;
-		rc = dmamem_map_anonymous(stream->bufsize,
-		    stream->hda->ctl->ok64bit ? 0 : DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE,
+		rc = dmamem_map_anonymous(bufs->bufsize,
+		    bufs->hda->ctl->ok64bit ? 0 : DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE,
 		    0, &buffer_phys, &buffer);
 		if (rc != EOK)
@@ -96,10 +103,10 @@
 		    (unsigned long long)buffer_phys, buffer);
 
-		stream->buf[i] = buffer;
-		stream->buf_phys[i] = buffer_phys;
+		bufs->buf[i] = buffer;
+		bufs->buf_phys[i] = buffer_phys;
 
 		k = 0;
-		for (j = 0; j < stream->bufsize / 2; j++) {
-			int16_t *bp = stream->buf[i];
+		for (j = 0; j < bufs->bufsize / 2; j++) {
+			int16_t *bp = bufs->buf[i];
 			bp[j] = (k > 128) ? -100 : 100;
 			++k;
@@ -111,6 +118,6 @@
 	/* audio_pcm_iface requires a single contiguous buffer */
 	buffer = AS_AREA_ANY;
-	rc = dmamem_map_anonymous(stream->bufsize * stream->nbuffers,
-	    stream->hda->ctl->ok64bit ? 0 : DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE,
+	rc = dmamem_map_anonymous(bufs->bufsize * bufs->nbuffers,
+	    hda->ctl->ok64bit ? 0 : DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE,
 	    0, &buffer_phys, &buffer);
 	if (rc != EOK) {
@@ -119,14 +126,14 @@
 	}
 
-	for (i = 0; i < stream->nbuffers; i++) {
-		stream->buf[i] = buffer + i * stream->bufsize;
-		stream->buf_phys[i] = buffer_phys + i * stream->bufsize;
+	for (i = 0; i < bufs->nbuffers; i++) {
+		bufs->buf[i] = buffer + i * bufs->bufsize;
+		bufs->buf_phys[i] = buffer_phys + i * bufs->bufsize;
 
 		ddf_msg(LVL_NOTE, "Stream buf phys=0x%llx virt=%p",
-		    (long long unsigned)(uintptr_t)stream->buf[i],
-		    (void *)stream->buf_phys[i]);
+		    (long long unsigned)(uintptr_t)bufs->buf[i],
+		    (void *)bufs->buf_phys[i]);
 /*		k = 0;
-		for (j = 0; j < stream->bufsize / 2; j++) {
-			int16_t *bp = stream->buf[i];
+		for (j = 0; j < bufs->bufsize / 2; j++) {
+			int16_t *bp = bufs->buf[i];
 			bp[j] = (k > 128) ? -10000 : 10000;
 			++k;
@@ -138,18 +145,30 @@
 
 	/* Fill in BDL */
-	for (i = 0; i < stream->nbuffers; i++) {
-		stream->bdl[i].address = host2uint64_t_le(stream->buf_phys[i]);
-		stream->bdl[i].length = host2uint32_t_le(stream->bufsize);
-		stream->bdl[i].flags = BIT_V(uint32_t, bdf_ioc);
-	}
-
+	for (i = 0; i < bufs->nbuffers; i++) {
+		bufs->bdl[i].address = host2uint64_t_le(bufs->buf_phys[i]);
+		bufs->bdl[i].length = host2uint32_t_le(bufs->bufsize);
+		bufs->bdl[i].flags = BIT_V(uint32_t, bdf_ioc);
+	}
+
+	*rbufs = bufs;
 	return EOK;
 error:
+	hda_stream_buffers_free(bufs);
 	return ENOMEM;
 }
 
+void hda_stream_buffers_free(hda_stream_buffers_t *bufs)
+{
+	if (bufs == NULL)
+		return;
+
+	/* XXX */
+	free(bufs);
+}
+
 static void hda_stream_desc_configure(hda_stream_t *stream)
 {
 	hda_sdesc_regs_t *sdregs;
+	hda_stream_buffers_t *bufs = stream->buffers;
 	uint8_t ctl1;
 	uint8_t ctl3;
@@ -161,9 +180,9 @@
 	hda_reg8_write(&sdregs->ctl3, ctl3);
 	hda_reg8_write(&sdregs->ctl1, ctl1);
-	hda_reg32_write(&sdregs->cbl, stream->nbuffers * stream->bufsize);
-	hda_reg16_write(&sdregs->lvi, stream->nbuffers - 1);
+	hda_reg32_write(&sdregs->cbl, bufs->nbuffers * bufs->bufsize);
+	hda_reg16_write(&sdregs->lvi, bufs->nbuffers - 1);
 	hda_reg16_write(&sdregs->fmt, stream->fmt);
-	hda_reg32_write(&sdregs->bdpl, LOWER32(stream->bdl_phys));
-	hda_reg32_write(&sdregs->bdpu, UPPER32(stream->bdl_phys));
+	hda_reg32_write(&sdregs->bdpl, LOWER32(bufs->bdl_phys));
+	hda_reg32_write(&sdregs->bdpu, UPPER32(bufs->bdl_phys));
 }
 
@@ -205,8 +224,8 @@
 
 hda_stream_t *hda_stream_create(hda_t *hda, hda_stream_dir_t dir,
-    uint32_t fmt)
+    hda_stream_buffers_t *bufs, uint32_t fmt)
 {
 	hda_stream_t *stream;
-	int rc;
+	uint8_t sdid;
 
 	stream = calloc(1, sizeof(hda_stream_t));
@@ -214,22 +233,30 @@
 		return NULL;
 
+	sdid = 0;
+
+	switch (dir) {
+	case sdir_input:
+		sdid = 0; /* XXX Allocate - first input SDESC */
+		break;
+	case sdir_output:
+		sdid = hda->ctl->iss; /* XXX Allocate - First output SDESC */
+		break;
+	case sdir_bidi:
+		sdid = hda->ctl->iss + hda->ctl->oss; /* XXX Allocate - First bidi SDESC */
+		break;
+	}
+
 	stream->hda = hda;
 	stream->dir = dir;
 	stream->sid = 1; /* XXX Allocate this */
-	stream->sdid = hda->ctl->iss; /* XXX Allocate - First output SDESC */
+	stream->sdid = sdid;
 	stream->fmt = fmt;
+	stream->buffers = bufs;
 
 	ddf_msg(LVL_NOTE, "snum=%d sdidx=%d", stream->sid, stream->sdid);
-
-	ddf_msg(LVL_NOTE, "Allocate buffers");
-	rc = hda_stream_buffers_alloc(stream);
-	if (rc != EOK)
-		goto error;
 
 	ddf_msg(LVL_NOTE, "Configure stream descriptor");
 	hda_stream_desc_configure(stream);
 	return stream;
-error:
-	return NULL;
 }
 
Index: uspace/drv/audio/hdaudio/stream.h
===================================================================
--- uspace/drv/audio/hdaudio/stream.h	(revision 795e2bfe0ca714517bdac2b7abae8091c5f88ee9)
+++ uspace/drv/audio/hdaudio/stream.h	(revision 0e4c5f0b7a21f09f35471fba7a626dff3790ce97)
@@ -48,12 +48,5 @@
 } hda_stream_dir_t;
 
-typedef struct hda_stream {
-	hda_t *hda;
-	/** Stream ID */
-	uint8_t sid;
-	/** Stream descriptor index */
-	uint8_t sdid;
-	/** Direction */
-	hda_stream_dir_t dir;
+typedef struct hda_stream_buffers {
 	/** Number of buffers */
 	size_t nbuffers;
@@ -68,9 +61,24 @@
 	/** Physical addresses of buffers */
 	uintptr_t *buf_phys;
+} hda_stream_buffers_t;
+
+typedef struct hda_stream {
+	hda_t *hda;
+	/** Stream ID */
+	uint8_t sid;
+	/** Stream descriptor index */
+	uint8_t sdid;
+	/** Direction */
+	hda_stream_dir_t dir;
+	/** Buffers */
+	hda_stream_buffers_t *buffers;
 	/** Stream format */
 	uint32_t fmt;
 } hda_stream_t;
 
-extern hda_stream_t *hda_stream_create(hda_t *, hda_stream_dir_t, uint32_t);
+extern int hda_stream_buffers_alloc(hda_t *, hda_stream_buffers_t **);
+extern void hda_stream_buffers_free(hda_stream_buffers_t *);
+extern hda_stream_t *hda_stream_create(hda_t *, hda_stream_dir_t,
+    hda_stream_buffers_t *, uint32_t);
 extern void hda_stream_destroy(hda_stream_t *);
 extern void hda_stream_start(hda_stream_t *);
