/*
 *
 * Based on 7510_dev.c
 *
 */

#include <tinyalsa/audio_mixer_ctrl.h>


struct pcm  *voicePcmOut = NULL;
struct pcm  *voicePcmIn = NULL;

typedef struct
{
    // uint32_t voice_mode;//0, 2/3g;1, volte nb;2 ,volte wb;
    uint32_t clock_rate; //8000, 2/3g;8000, volte nb;16000 ,volte wb;
    uint32_t channel_count;
    uint32_t samples_per_frame;//160, 2/3g;160, volte nb;320 ,volte wb;
    uint32_t bits_per_sample;
} T_voiceCfg;

T_voiceCfg cfgParam = {0,8000,1,160,16};



   
 int voice_PreOpen(T_voiceCfg *cfgParam)
{
	struct mixer *voice_mixer = NULL;
 	struct pcm_config config_voice = {0};

 	/* open mixer dev for codec control */
	voice_mixer = mixer_open(0);
	if(!voice_mixer)
	{
		printf("zte voice_mixer open failed!");
		goto err_ret;
	}

	/* config mixer dev */
   	mix_set_voice_path(voice_mixer, T_OUTPUT_SPEAKER); 
   	mix_set_voice_vol(voice_mixer, T_VOICE_VOL_3_LEVEL);

    /*close mixer */
    mixer_close(voice_mixer);
    voice_mixer = NULL;

    /* open pcm dev for data tranf*/
    config_voice.channels = cfgParam->channel_count;
    config_voice.rate = cfgParam->clock_rate;
    /* buffer num */
    config_voice.period_count = 3;
    /* buffer size */
    config_voice.period_size = cfgParam->samples_per_frame *  cfgParam->bits_per_sample / 8; 
    /* 16-bit signed */
    config_voice.format = PCM_FORMAT_S16_LE; 
	
	//card 0 dev 1
	//23G card 0 dev 2
	voicePcmOut = pcm_open(0, 1, PCM_OUT, &config_voice);
	if(!voicePcmOut || !pcm_is_ready(voicePcmOut))
	{
		printf( "zte voicePcmOut open failed!");	
		goto err_ret;
	}
	
	voicePcmIn = pcm_open(0, 1, PCM_IN, &config_voice);
	if(!voicePcmIn || !pcm_is_ready(voicePcmIn))
	{
		printf( "zte voicePcmIn open failed!");
		goto err_ret;
	}
	
    if(0 != pcm_prepare(voicePcmOut)) 
	{
		printf("zte voicePcmOut pcm_prepare failed!");
		goto err_ret;
	}
		
    if(0 != pcm_prepare(voicePcmIn)) 
	{
		printf("zte voicePcmIn pcm_prepare failed!");
		goto err_ret;
	}
	return 0;
err_ret:
	if(voice_mixer)
	{
		mixer_close(voice_mixer);
    	voice_mixer = NULL;
	}

	if(voicePcmOut)
	{
		pcm_close(voicePcmOut);
    	voicePcmOut = NULL;
	}
	if(voicePcmIn)
	{
		pcm_close(voicePcmIn);
    	voicePcmIn = NULL;
	}
	return -1;
	
}


 void voice_PreClose(void)
{
	if(voicePcmOut)
	{
		pcm_close(voicePcmOut);
    	voicePcmOut = NULL;
	}
	if(voicePcmIn)
	{
		pcm_close(voicePcmIn);
    	voicePcmIn = NULL;
	}
}


