/*
 * bluetooth_pcm.c
 *
 * Copyright 2007 Wolfson Microelectronics PLC.
 * Author: Graeme Gregory
 *         graeme.gregory@wolfsonmicro.com or linux@wolfsonmicro.com
 *
 *  This program is free software; you can redistribute  it and/or modify it
 *  under  the terms of  the GNU General  Public License as published by the
 *  Free Software Foundation;  either version 2 of the  License, or (at your
 *  option) any later version.
 *
 *  Revision history
 *    20th Jan 2007   Initial version.
 *
 *  based on pcm_mic.c from alsa-lib
 *
 */

#include <alsa/asoundlib.h>

static char *device = "hw:0,1";			/* playback device */

snd_output_t *output = NULL;

int main(void)
{
    int err;
    unsigned int i;
    snd_pcm_t *phandle,*chandle;

    if ((err = snd_pcm_open(&phandle, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
	printf("Playback open error: %s\n", snd_strerror(err));
	exit(EXIT_FAILURE);
    }
    if ((err = snd_pcm_open(&chandle, device, SND_PCM_STREAM_CAPTURE, 0)) < 0) {
	printf("Playback open error: %s\n", snd_strerror(err));
	exit(EXIT_FAILURE);
    }

    if ((err = snd_pcm_set_params(phandle,
				  SND_PCM_FORMAT_S16_LE,
				  SND_PCM_ACCESS_RW_INTERLEAVED,
				  1,
				  8000,
				  1,
				  500000)) < 0) {	/* 0.5sec */
	printf("Playback open error: %s\n", snd_strerror(err));
	exit(EXIT_FAILURE);
    }

    if ((err = snd_pcm_set_params(chandle,
				  SND_PCM_FORMAT_S16_LE,
				  SND_PCM_ACCESS_RW_INTERLEAVED,
				  1,
				  8000,
				  1,
				  500000)) < 0) { /* 0.5sec */
        printf("Playback open error: %s\n", snd_strerror(err));
        exit(EXIT_FAILURE);
    }

    while(1) sleep(10);

    snd_pcm_close(phandle);
    snd_pcm_close(chandle);

    return 0;
}
