static int voice_test()
{
    int rtn = 0;
    char* name;
    fd_set rfds, wfds;
    Audio_t hPcm_Mic;
    Audio_t hPcm_Spk;
    snd_pcm_channel_params_t params;
    bool bQuit = false;

    /************************ CAPTURE **************************/

    //  configuring capture (mic)
    name = "voice";

    //  get audioman handle
    rtn = audio_manager_get_handle(AUDIO_TYPE_VIDEO_CHAT, getpid(), (bool)false, &hPcm_Mic.hAudioman);
    if(rtn < 0) {
        cli_print("audio_manager_get_handle (mic) failed %s", strerror(-rtn));
        return -1;
     }

    cli_print("Opening %s - for capture", name);
    rtn = snd_pcm_open_name(&hPcm_Mic.pDs, name, SND_PCM_OPEN_CAPTURE);
    if (rtn < 0) {
        (void)audio_manager_free_handle(hPcm_Mic.hAudioman);
        cli_print("snd_pcm_open_name (mic) failed %s", snd_strerror(rtn));
        return -1; // snd_pcm calls return negative values; make positive
    }

    rtn = snd_pcm_set_audioman_handle(hPcm_Mic.pDs, hPcm_Mic.hAudioman);
    if (rtn < 0) {
        (void)snd_pcm_close(hPcm_Mic.pDs);
        (void)audio_manager_free_handle(hPcm_Mic.hAudioman);
        cli_print("snd_pcm_set_audioman_handle (mic) failed %s", snd_strerror(rtn));
        (void)snd_pcm_close(hPcm_Mic.pDs);
        return -1;
    }

    // disable mmap
    (void)snd_pcm_plugin_set_disable(hPcm_Mic.pDs, (unsigned int)PLUGIN_DISABLE_MMAP);

    // set parameters
    memset(&params, 0, sizeof(params));
    params.mode = SND_PCM_MODE_BLOCK;
    params.channel = SND_PCM_CHANNEL_CAPTURE;
    params.start_mode = SND_PCM_START_GO;
    params.stop_mode = SND_PCM_STOP_ROLLOVER;
    params.buf.block.frag_size = fragsize;
    params.buf.block.frags_max = 1;
    params.buf.block.frags_min = 1;
    params.format.rate = 8000; //samplerate;
    params.format.interleave = 1;
    params.format.voices = channels;
    params.format.format = SND_PCM_SFMT_S16_LE;

    rtn = snd_pcm_plugin_params(hPcm_Mic.pDs, &params);
    if (rtn < 0) {
        cli_print("snd_pcm_plugin_params (mic) failed %s", snd_strerror(rtn));
        (void)snd_pcm_close(hPcm_Mic.pDs);
        (void)audio_manager_free_handle(hPcm_Mic.hAudioman);
        return -1;
    }

    // get file descriptor for use with the select() call
    hPcm_Mic.hFD = snd_pcm_file_descriptor(hPcm_Mic.pDs, SND_PCM_CHANNEL_CAPTURE);
    if (hPcm_Mic.hFD < 0) {
        cli_print("snd_pcm_file_descriptor (mic) failed %s", snd_strerror(hPcm_Mic.hFD));
        (void)snd_pcm_close(hPcm_Mic.pDs);
        (void)audio_manager_free_handle(hPcm_Mic.hAudioman);
        return -1;
    }
    // Signal the driver to ready the capture channel
    rtn = snd_pcm_plugin_prepare(hPcm_Mic.pDs, SND_PCM_CHANNEL_CAPTURE);
    if (rtn < 0) {
        cli_print("snd_pcm_plugin_prepare (mic) failed %s", snd_strerror(errno));
        (void)snd_pcm_close(hPcm_Mic.pDs);
        (void)audio_manager_free_handle(hPcm_Mic.hAudioman);
        return -1;
    }
    fragsize = params.buf.block.frag_size;


    /************************ PLAYBACK **************************/

    name = "voice";

    // get and set audioman handle
    rtn = audio_manager_get_handle(AUDIO_TYPE_VIDEO_CHAT, getpid(), (bool)false, &hPcm_Spk.hAudioman);
    if (rtn < 0) {
        cli_print("audioman audio_manager_get_handle (spk) failed %s", strerror(-rtn) );
        (void)snd_pcm_close(hPcm_Mic.pDs);
        (void)audio_manager_free_handle(hPcm_Mic.hAudioman);
        return -1;
    }
#ifdef HANDSET
    // set audio manager handle type
    rtn = audio_manager_set_handle_type(hPcm_Spk.hAudioman, AUDIO_TYPE_VIDEO_CHAT, device_type, device_type);
    if (rtn < 0) {
        (void)snd_pcm_close(hPcm_Mic.pDs);
        (void)audio_manager_free_handle(hPcm_Mic.hAudioman);
        (void)audio_manager_free_handle(hPcm_Spk.hAudioman);
        cli_print("audio_manager_set_handle_type (spk) failed %s", strerror(-rtn));
        return -1;
    }
#endif
    // Create a handle and open a connection to an audio interface specified by name
    cli_print("Opening %s - for playback", name);
    rtn = snd_pcm_open_name(&hPcm_Spk.pDs, name, SND_PCM_OPEN_PLAYBACK);
    if (rtn < 0) {
        cli_print("snd_pcm_open_name (spk) failed %s", snd_strerror(rtn));
        (void)snd_pcm_close(hPcm_Mic.pDs);
        (void)audio_manager_free_handle(hPcm_Mic.hAudioman);
        (void)audio_manager_free_handle(hPcm_Spk.hAudioman);
        return -1;
    }
    rtn = snd_pcm_set_audioman_handle(hPcm_Spk.pDs, hPcm_Spk.hAudioman);
    if (rtn < 0) {
        cli_print("snd_pcm_set_audioman_handle (spk) failed %s", snd_strerror(rtn));
        (void)snd_pcm_close(hPcm_Mic.pDs);
        (void)snd_pcm_close(hPcm_Spk.pDs);
        (void)audio_manager_free_handle(hPcm_Mic.hAudioman);
        (void)audio_manager_free_handle(hPcm_Spk.hAudioman);
        return -1;
    }

    // disable mmap
    (void)snd_pcm_plugin_set_disable(hPcm_Spk.pDs, (unsigned int)PLUGIN_DISABLE_MMAP);

    // set parameters
    memset(&params, 0, sizeof(params));
    params.mode = SND_PCM_MODE_BLOCK;
    params.channel = SND_PCM_CHANNEL_PLAYBACK;
    params.start_mode = SND_PCM_START_GO;
    params.stop_mode = SND_PCM_STOP_ROLLOVER;
    params.buf.block.frag_size = fragsize;
    params.buf.block.frags_max = 1;
    params.buf.block.frags_min = 1;
    params.format.rate = samplerate;
    params.format.interleave = 1;
    params.format.voices = channels;
    params.format.format = SND_PCM_SFMT_S16_LE;

    // Set the configurable parameters for a PCM channel
    rtn = snd_pcm_plugin_params(hPcm_Spk.pDs, &params);
    if (rtn < 0) {
        cli_print("snd_pcm_plugin_params  (spk) failed %s", snd_strerror(rtn));
        (void)snd_pcm_close(hPcm_Mic.pDs);
        (void)snd_pcm_close(hPcm_Spk.pDs);
        (void)audio_manager_free_handle(hPcm_Mic.hAudioman);
        (void)audio_manager_free_handle(hPcm_Spk.hAudioman);
        return -1;
    }

    // get file descriptor for use with the select() call
    hPcm_Spk.hFD = snd_pcm_file_descriptor(hPcm_Spk.pDs, SND_PCM_CHANNEL_PLAYBACK);
    if (hPcm_Spk.hFD < 0) {
        cli_print("snd_pcm_file_descriptor (spk) failed %s", snd_strerror(hPcm_Spk.hFD));
        (void)snd_pcm_close(hPcm_Mic.pDs);
        (void)snd_pcm_close(hPcm_Spk.pDs);
        (void)audio_manager_free_handle(hPcm_Mic.hAudioman);
        (void)audio_manager_free_handle(hPcm_Spk.hAudioman);
        return -1;
    }
    // Signal the driver to ready the playback channel
    rtn = snd_pcm_plugin_prepare(hPcm_Spk.pDs, SND_PCM_CHANNEL_PLAYBACK);
    if (rtn < 0) {
        cli_print("snd_pcm_plugin_prepare  (spk) failed %s", snd_strerror(rtn));
        (void)snd_pcm_close(hPcm_Mic.pDs);
        (void)snd_pcm_close(hPcm_Spk.pDs);
        (void)audio_manager_free_handle(hPcm_Mic.hAudioman);
        (void)audio_manager_free_handle(hPcm_Spk.hAudioman);
        return -1;
    }
    fragsize = params.buf.block.frag_size;

    rtn = snd_pcm_capture_go(hPcm_Mic.pDs);
    if( rtn < 0) {
        cli_print("snd_pcm_capture_go (mic) failed %s", snd_strerror(rtn));
        (void)snd_pcm_close(hPcm_Mic.pDs);
        (void)snd_pcm_close(hPcm_Spk.pDs);
        (void)audio_manager_free_handle(hPcm_Mic.hAudioman);
        (void)audio_manager_free_handle(hPcm_Spk.hAudioman);
        return -1;
    }
    rtn = snd_pcm_playback_go(hPcm_Spk.pDs);
    if (rtn < 0) {
        cli_print("snd_pcm_playback_go (spk) failed %s", snd_strerror(rtn));
        (void)snd_pcm_close(hPcm_Mic.pDs);
        (void)snd_pcm_close(hPcm_Spk.pDs);
        (void)audio_manager_free_handle(hPcm_Mic.hAudioman);
        (void)audio_manager_free_handle(hPcm_Spk.hAudioman);
        return -1;
    }

    /******************* PLAYBACK/RECORD LOOP **************************/
    while(!bQuit)
    {
        int width;
        struct timeval timeout;
        timeout.tv_sec = 0;
        timeout.tv_usec = 350000; // 350 ms

        FD_ZERO(&rfds);
        FD_ZERO(&wfds);
        FD_SET(hPcm_Mic.hFD, &rfds);
        FD_SET(hPcm_Spk.hFD, &wfds);

        width = ((hPcm_Spk.hFD > hPcm_Mic.hFD) ? hPcm_Spk.hFD : hPcm_Mic.hFD) + 1;
        rtn = select(width, &rfds, &wfds, NULL, &timeout);
        if (rtn > 0) {
            if (FD_ISSET(hPcm_Spk.hFD, &wfds)) {
                bQuit = process_write(hPcm_Spk.pDs);
            }
            if (FD_ISSET(hPcm_Mic.hFD, &rfds)) {
                bQuit = process_read(hPcm_Mic.pDs);
            }
        }
        else if (rtn == 0){
            cli_print("select: timed out");
            bQuit = true;
        }
        else { // (rtn < 0)
            cli_print("select: %s", strerror(errno));
            bQuit = true;
        }
    }

    // Ensure audio processing is stopped
    if ((rtn = snd_pcm_plugin_playback_drain(hPcm_Spk.pDs)) < 0) {
        cli_print("snd_pcm_plugin_playback_drain (spk) failed %s", snd_strerror(rtn));
    }
    if ((rtn = snd_pcm_plugin_flush(hPcm_Mic.pDs, SND_PCM_CHANNEL_CAPTURE)) < 0) {
        cli_print("snd_pcm_plugin_flush (mic) failed %s", snd_strerror(rtn));
    }
    if ((rtn = snd_pcm_close(hPcm_Spk.pDs)) < 0) {
        cli_print("snd_pcm_close (spk) failed %s", snd_strerror(rtn));
    }
    if ((rtn = snd_pcm_close(hPcm_Mic.pDs)) < 0) {
        cli_print("snd_pcm_close (mic) failed %s", snd_strerror(rtn));
    }
    if (hPcm_Spk.hAudioman) {
        (void)audio_manager_free_handle(hPcm_Spk.hAudioman);
    }
    if (hPcm_Mic.hAudioman) {
        (void)audio_manager_free_handle(hPcm_Mic.hAudioman);
    }
    return 0;
}
// Initialize audio and report back a few parameters of the channel
int setupAudio( )
{
    int error;
    snd_pcm_channel_info_t pi;
    snd_pcm_channel_params_t pp;
    snd_pcm_channel_setup_t ps;

    //if ((error = snd_pcm_open_name (&playback_handle, "pcmPreferred", SND_PCM_OPEN_PLAYBACK)) < 0) {
    if ((error = snd_pcm_open_name (&playback_handle, "tones", SND_PCM_OPEN_PLAYBACK)) < 0) {
        slogf( _SLOG_SETCODE(_SLOGC_AUDIO, 0), _SLOG_CRITICAL, "Unable to open preferred audio driver\n");
        return -error;
    }

    sample_handle = snd_pcm_file_descriptor( playback_handle, SND_PCM_CHANNEL_PLAYBACK );

    if ((error = snd_pcm_plugin_set_disable (playback_handle, PLUGIN_DISABLE_MMAP)) < 0) {
        slogf( _SLOG_SETCODE(_SLOGC_AUDIO, 0), _SLOG_CRITICAL, "Unable to disable mmap\n");
        snd_pcm_close(playback_handle);
        return -error;
    }

    if ((error = snd_pcm_plugin_set_enable (playback_handle, PLUGIN_ROUTING)) < 0)
    {
        slogf ( _SLOG_SETCODE(_SLOGC_AUDIO, 0), _SLOG_CRITICAL, "snd_pcm_plugin_set_enable failed: %s\n", snd_strerror (error));
        snd_pcm_close(playback_handle);
        return -error;
    }

    // Find what sample rate and format to use
    memset( &pi, 0, sizeof(pi) );
    pi.channel = SND_PCM_CHANNEL_PLAYBACK;
    if ((error = snd_pcm_channel_info (playback_handle, &pi)) < 0) {
        slogf( _SLOG_SETCODE(_SLOGC_AUDIO, 0), _SLOG_CRITICAL, "Unable to get plugin info\n");
        snd_pcm_close(playback_handle);
        return -error;
    }

    // Initialize the playback channel
    memset(&pp, 0, sizeof(pp) );
    pp.mode = SND_PCM_MODE_BLOCK;
    pp.channel = SND_PCM_CHANNEL_PLAYBACK;
    pp.start_mode = SND_PCM_START_FULL;
    pp.stop_mode = SND_PCM_STOP_STOP;
    pp.buf.block.frag_size = pi.max_fragment_size;
    pp.buf.block.frags_max = 3;
    pp.buf.block.frags_min = 1;
    pp.format.interleave = 1;
    pp.format.format =  SND_PCM_SFMT_S16_LE;
    pp.format.rate = 48000;
    pp.format.voices = 2;

    memset( &ps, 0, sizeof( ps ) );
    memset( &group, 0, sizeof( group ) );
    ps.channel = SND_PCM_CHANNEL_PLAYBACK;
    ps.mixer_gid = &group.gid;
    //strcpy(pp.sw_mixer_subchn_name, "Wave playback channel");
    strcpy(pp.sw_mixer_subchn_name, "voice_ringtone");

    if ((error = snd_pcm_plugin_params( playback_handle, &pp)) < 0)
    {
        slogf( _SLOG_SETCODE(_SLOGC_AUDIO, 0), _SLOG_CRITICAL, "Unable to set plugin params\n");
        snd_pcm_close(playback_handle);
        return -error;
    }

    if ((error = snd_pcm_plugin_prepare (playback_handle, SND_PCM_CHANNEL_PLAYBACK)) < 0) {
        slogf( _SLOG_SETCODE(_SLOGC_AUDIO, 0), _SLOG_CRITICAL, "Unable to set prepare plugin\n");
        snd_pcm_close(playback_handle);
        return -error;
    }

    if ((error = snd_pcm_plugin_setup (playback_handle, &ps)) < 0) {
        slogf( _SLOG_SETCODE(_SLOGC_AUDIO, 0), _SLOG_CRITICAL, "Unable to setup plugin\n");
        snd_pcm_close(playback_handle);
        return -error;
    }

    card = ps.mixer_card;
    device = ps.mixer_device;

    if( audioman_handle ) {
        if ((error = snd_pcm_set_audioman_handle (playback_handle, audioman_handle)) < 0) {
            slogf( _SLOG_SETCODE(_SLOGC_AUDIO, 0), _SLOG_CRITICAL, "Unable to set audioman handle \n");
            snd_pcm_close(playback_handle);
            return -error;
        }
    }

    sample_frequency = ps.format.rate;
    frag_samples = ps.buf.block.frag_size / 4;
    frame_size = ps.buf.block.frag_size;
    format = pp.format.format;
/*
    // Only support 16-bit samples for now
    frag_buffer = malloc( ps.buf.block.frag_size * 2 );
    if( frag_buffer == NULL ) {
        slogf( _SLOG_SETCODE(_SLOGC_AUDIO, 0), _SLOG_CRITICAL, "Unable to alloc frag buffer\n");
        snd_pcm_close(playback_handle);
        return ENOMEM;
    }
*/
	fprintf (stderr,"Playback Format %s card = %d\n", snd_pcm_get_format_name (ps.format.format),card);
	fprintf (stderr,"Playback preferred frame_size %d \n", pi.max_fragment_size);
	fprintf (stderr,"Playback frame_size %d \n", ps.buf.block.frag_size);
	fprintf (stderr,"Playback frame_samples %d \n", frag_samples);
	fprintf (stderr,"Playback Rate %d \n", ps.format.rate);

	if (group.gid.name[0] == 0)
	{
		fprintf (stderr,"Playback Mixer Pcm Group [%s] Not Set \n", group.gid.name);
        return -1;
	}
	fprintf (stderr, "Playback Mixer Pcm Group [%s]\n", group.gid.name);

    return EOK;
}