Exemplo n.º 1
0
void audioCallback(int event, void* user, void *info)
{
    int len;
    AudioTrack::Buffer *buffer = static_cast<AudioTrack::Buffer *>(info);
    aml_audio_dec_t *audec = static_cast<aml_audio_dec_t *>(user);

    int resample_enable;
	af_resampe_ctl_t *paf_resampe_ctl;
	short data_in[MAX_NUMSAMPS_PERCH*DEFALT_NUMCH], *data_out;
	short outbuftmp16[MAX_NUMSAMPS_PERCH*DEFALT_NUMCH];
    int NumSamp_in,NumSamp_out,NumCh,NumSampRequir=0;
	static int print_flag=0;
	int outbuf_offset=0;
	int dsp_format_changed_flag=0;
	static int pcm_left_len=-1;
    if (event != AudioTrack::EVENT_MORE_DATA) {
        adec_print("audioCallback: event = %d \n", event);
        return;
    }

    if (buffer == NULL || buffer->size == 0) {
        adec_print("audioCallback: Wrong buffer\n");
        return;
    }

    adec_refresh_pts(audec);

    if (audec->adsp_ops.dsp_on) {
        //------------------------------------------
        NumCh=buffer->channelCount;		
        resample_enable= af_get_reample_enable_flag();
		paf_resampe_ctl=af_resampler_ctx_get();
        data_out=buffer->i16;
		NumSamp_out = buffer->size/sizeof(short);
		NumSampRequir=NumSamp_out;
		//adec_print("resample_enable = %d\n",resample_enable);
		//adec_print("REQURE_NUM-----------------------------%d\n",NumSamp_out);
		//adec_print("PCM_IN_OUTSAMPBUF:%d\n",paf_resampe_ctl->OutSampReserveLen);
        if(resample_enable){    
			   int pcm_cnt=0;
			   if (!paf_resampe_ctl->InitFlag)
                   af_resample_set_SampsNumRatio(paf_resampe_ctl);
			   af_get_pcm_in_resampler(paf_resampe_ctl,data_out+outbuf_offset,&NumSampRequir);
			   
			   //adec_print("RETURN_SIZE_1:%d    OutSampReserve=%d \n",NumSampRequir,paf_resampe_ctl->OutSampReserveLen);

			   outbuf_offset += NumSampRequir;
			   NumSamp_out   -= NumSampRequir;
			   while(NumSamp_out >= DEFALT_NUMSAMPS_PERCH*NumCh)
			   {   
			       int delta_input_sampsnum=af_get_delta_inputsampnum(paf_resampe_ctl,NumCh);
			       NumSamp_in =dsp_pcm_read(audec,(char*)data_in,delta_input_sampsnum*sizeof(short));	
				   af_resample_process_linear_inner(paf_resampe_ctl,data_in, &NumSamp_in,data_out+outbuf_offset,&pcm_cnt,NumCh);

				   //adec_print("RETURN_SIZE_2:%d    OutSampReserve=%d \n",pcm_cnt,paf_resampe_ctl->OutSampReserveLen);

				   if(pcm_cnt==0)
				   	  goto resample_out;
				   outbuf_offset += pcm_cnt;
				   NumSamp_out   -= pcm_cnt;
			   }
			   
               if(NumSamp_out>0)
			   {
			       int delta_input_sampsnum=af_get_delta_inputsampnum(paf_resampe_ctl,NumCh);
			       NumSamp_in =dsp_pcm_read(audec,(char*)data_in,delta_input_sampsnum*sizeof(short));				   
            	   af_resample_process_linear_inner(paf_resampe_ctl,data_in, &NumSamp_in,outbuftmp16,&pcm_cnt,NumCh);
                   if(pcm_cnt==0)
				   	   goto resample_out;

				   //adec_print("RETURN_SIZE_3:%d    OutSampReserve=%d \n",NumSamp_out,pcm_cnt-NumSamp_out);
   
				   memcpy(data_out+outbuf_offset,outbuftmp16,NumSamp_out*sizeof(short));
				   outbuf_offset +=NumSamp_out;
                   memcpy(paf_resampe_ctl->OutSampReserveBuf,outbuftmp16+NumSamp_out,(pcm_cnt-NumSamp_out)*sizeof(short));
                   paf_resampe_ctl->OutSampReserveLen = (pcm_cnt-NumSamp_out);
			   }
			   
		}else{
              if(paf_resampe_ctl->OutSampReserveLen > 0){
			      af_get_pcm_in_resampler(paf_resampe_ctl,data_out+outbuf_offset,&NumSampRequir);
				  //adec_print("RETURN_SIZE_4:%d    OutSampReserve=%d \n",NumSampRequir,paf_resampe_ctl->OutSampReserveLen);
			      outbuf_offset += NumSampRequir;
			      NumSamp_out   -= NumSampRequir;
				  NumSampRequir  =  NumSamp_out;
              } 

			  if(paf_resampe_ctl->ResevedSampsValid > 0){
                  af_get_unpro_inputsampnum(paf_resampe_ctl,data_out+outbuf_offset,&NumSampRequir);
				  //adec_print("RETURN_SIZE_5:%d    OutSampReserve=%d \n",NumSampRequir,paf_resampe_ctl->ResevedSampsValid);
				  outbuf_offset += NumSampRequir;
			      NumSamp_out   -= NumSampRequir;
			  }
			  
              if((paf_resampe_ctl->OutSampReserveLen==0) && (paf_resampe_ctl->ResevedSampsValid==0))
                  af_resample_stop_process(paf_resampe_ctl);

			  if(NumSamp_out > 0){
			  	  len=audec->adsp_ops.dsp_read(&audec->adsp_ops, (char*)(data_out+outbuf_offset),NumSamp_out*sizeof(short));
                  outbuf_offset += len/sizeof(short);
			  }
        }
	resample_out:
		
	    buffer->size=outbuf_offset*sizeof(short);
		//------------------------------------
        dsp_format_changed_flag=audiodsp_format_update(audec);
	    if(dsp_format_changed_flag>0){
			pcm_left_len=audiodsp_get_pcm_left_len();
			//audiodsp_set_format_changed_flag(1);
	    }
		if(pcm_left_len>=0){
			if(pcm_left_len>buffer->size){
				pcm_left_len-=buffer->size;
				memset((char*)(data_out),0,buffer->size);
			}else if(pcm_left_len<=buffer->size){
			    memset((char*)(data_out),0,pcm_left_len);
				pcm_left_len=-1;	
				//adec_reset_track(audec);
			
			}
		}
		//---------------------------------------------
    } else {
        adec_print("audioCallback: dsp not work!\n");
    }

    return;
}
Exemplo n.º 2
0
void af_resample_api_normal(char *buffer, unsigned int *size,int Chnum, aml_audio_dec_t *audec)
{
	int len;
	int resample_enable;
	af_resampe_ctl_t *paf_resampe_ctl;
	short data_in[MAX_NUMSAMPS_PERCH*DEFALT_NUMCH], *data_out;
	short outbuftmp16[MAX_NUMSAMPS_PERCH*DEFALT_NUMCH];
    int NumSamp_in,NumSamp_out,NumCh,NumSampRequir=0;
	static int print_flag=0;
	int outbuf_offset=0;
	int dsp_format_changed_flag=0;
	static int pcm_left_len=-1;
       //------------------------------------------
        NumCh=Chnum;//buffer->channelCount;		
        resample_enable= af_get_resample_enable_flag();
		paf_resampe_ctl=af_resampler_ctx_get();
        data_out=date_temp;//buffer->i16
		NumSamp_out = *size/sizeof(short);//buffer->size/sizeof(short);
		if(NumSamp_out>MAXCH_NUMBER*MAXFRAMESIZE)
			NumSamp_out=MAXCH_NUMBER*MAXFRAMESIZE;
		NumSampRequir=NumSamp_out;
		int resample_type=af_get_resample_type();
		
		//adec_print("REQURE_NUM-----------------------------%d\n",NumSamp_out);
		
		//-------------------------------
		//add this part for support rapid Resample_Type covet:
		if (resample_enable)
		 {   
		 	if(paf_resampe_ctl->LastResamType!=resample_type)
		 	{ 
				adec_print("ReSample Type Changed: FromTYpe/%d ToType/%d \n",
					         paf_resampe_ctl->LastResamType,resample_type);
			    if((paf_resampe_ctl->OutSampReserveLen==0) // to ensure phase continue:
		   	      && (paf_resampe_ctl->ResevedSampsValid==0))
		        {   
					adec_print("ReSample Type Changed: ENABLE");
                    af_resample_stop_process(paf_resampe_ctl);
		        }else{
		            adec_print("ReSample Type Changed DISABLE:");
					adec_print("  OutSampSaved/%d InSampSaved/%d in Resampler!",
						        paf_resampe_ctl->OutSampReserveLen,paf_resampe_ctl->ResevedSampsValid);
		   	        resample_enable=0;
		        }

		 	 }
		 }
        //-------------------------------
        if(resample_enable){    
			   int pcm_cnt=0;
			   if (!paf_resampe_ctl->InitFlag)
                   af_resample_set_SampsNumRatio(paf_resampe_ctl);
			   af_get_pcm_in_resampler(paf_resampe_ctl,data_out+outbuf_offset,&NumSampRequir);
			   
			   //adec_print("RETURN_SIZE_1:%d    OutSampReserve=%d \n",NumSampRequir,paf_resampe_ctl->OutSampReserveLen);

			   outbuf_offset += NumSampRequir;
			   NumSamp_out   -= NumSampRequir;
			   while(NumSamp_out >= DEFALT_NUMSAMPS_PERCH*NumCh)
			   {   
			       int delta_input_sampsnum=af_get_delta_inputsampnum(paf_resampe_ctl,NumCh);
			       NumSamp_in =dsp_pcm_read(audec,(char*)data_in,delta_input_sampsnum*sizeof(short));	
				   af_resample_process_linear_inner(paf_resampe_ctl,data_in, &NumSamp_in,data_out+outbuf_offset,&pcm_cnt,NumCh);

				   //adec_print("RETURN_SIZE_2:%d    OutSampReserve=%d \n",pcm_cnt,paf_resampe_ctl->OutSampReserveLen);

				   if(pcm_cnt==0)
				   	  goto resample_out;
				   outbuf_offset += pcm_cnt;
				   NumSamp_out   -= pcm_cnt;
			   }
			   
               if(NumSamp_out>0)
			   {
			       int delta_input_sampsnum=af_get_delta_inputsampnum(paf_resampe_ctl,NumCh);
			       NumSamp_in =dsp_pcm_read(audec,(char*)data_in,delta_input_sampsnum*sizeof(short));				   
            	   af_resample_process_linear_inner(paf_resampe_ctl,data_in, &NumSamp_in,outbuftmp16,&pcm_cnt,NumCh);
                   if(pcm_cnt==0)
				   	   goto resample_out;

				   //adec_print("RETURN_SIZE_3:%d    OutSampReserve=%d \n",NumSamp_out,pcm_cnt-NumSamp_out);
   
				   memcpy(data_out+outbuf_offset,outbuftmp16,NumSamp_out*sizeof(short));
				   outbuf_offset +=NumSamp_out;
                   memcpy(paf_resampe_ctl->OutSampReserveBuf,outbuftmp16+NumSamp_out,(pcm_cnt-NumSamp_out)*sizeof(short));
                   paf_resampe_ctl->OutSampReserveLen = (pcm_cnt-NumSamp_out);
			   }
			   
		}else{
              if(paf_resampe_ctl->OutSampReserveLen > 0){
			      af_get_pcm_in_resampler(paf_resampe_ctl,data_out+outbuf_offset,&NumSampRequir);
				  //adec_print("RETURN_SIZE_4:%d    OutSampReserve=%d \n",NumSampRequir,paf_resampe_ctl->OutSampReserveLen);
			      outbuf_offset += NumSampRequir;
			      NumSamp_out   -= NumSampRequir;
				  NumSampRequir  =  NumSamp_out;
              } 

			  if(paf_resampe_ctl->ResevedSampsValid > 0){
                  af_get_unpro_inputsampnum(paf_resampe_ctl,data_out+outbuf_offset,&NumSampRequir);
				  //adec_print("RETURN_SIZE_5:%d    OutSampReserve=%d \n",NumSampRequir,paf_resampe_ctl->ResevedSampsValid);
				  outbuf_offset += NumSampRequir;
			      NumSamp_out   -= NumSampRequir;
			  }
			  
              if((paf_resampe_ctl->OutSampReserveLen==0) && (paf_resampe_ctl->ResevedSampsValid==0))
                  af_resample_stop_process(paf_resampe_ctl);

			  if(NumSamp_out > 0){
			  	  len=audec->adsp_ops.dsp_read(&audec->adsp_ops, (char*)(data_out+outbuf_offset),NumSamp_out*sizeof(short));
                  outbuf_offset += len/sizeof(short);
                  audec->pcm_bytes_readed +=len;
			  }
        }
	resample_out:
		
	    *size=outbuf_offset*sizeof(short);
		memcpy(buffer,data_out,*size);
		//------------------------------------
        dsp_format_changed_flag=audiodsp_format_update(audec);
	    if(dsp_format_changed_flag>0){
			pcm_left_len=audiodsp_get_pcm_left_len();
	    }
		if(pcm_left_len>=0){
			if(pcm_left_len>(*size)){
				pcm_left_len-=(*size);
				memset((char*)(data_out),0,*size);
			}else if(pcm_left_len<=(*size)){
			    memset((char*)(data_out),0,pcm_left_len);
				pcm_left_len=-1;	
			
			}
		}
		//dump_pcm_bin("/data/post1.pcm",(char*)(buffer->i16),buffer->size);
		//---------------------------------------------

}