Exemple #1
0
int symb_testindex(symb_data S)
{
  set index=set_constr(_E);
  tensor t; SpinTensor s; Etens e;
  int i,c;
  int first=1;


  switch(S.type)
  {  case errortp: case numbertp: case polytp: case vectortp: case indextp: 
     return 0;
  }

  if(S.type==errortp || S.expr.p==NULL)  return 0;
  
  switch(S.type)
  {  case tenstp : 
        
       for(t=S.expr.t;t;t=t->next)  
       {set   ind=set_constr(_E); 
         for(i=0; i<maxIndex; i++) if(t->tens[i]) set_add1(&ind,i+1);
         if(first) index=ind; else  if(!set_eq(index,ind)) return 1; 
         first=0;         
       }   return 0;

     case spintp :
     for(s=S.expr.s;s;s=s->next)
     { set  ind=set_constr(_E);
       for(i=0; i<s->l; i++) {  c=s->g[i];if(c>0)  set_add1(&ind,c);}
       t=s->tcoef;            
       for(i=0; i<maxIndex; i++)  if(t->tens[i]) set_add1(&ind,i+1);
       if(first) index=ind; else  if(!set_eq(index,ind)) return 1;    
       first=0;
     } return 0;                

     case etenstp:
     for(e=S.expr.et;e;e=e->next)
     { set  ind=set_constr(_E);
          
       for(i=0;i<4;i++) {  c=e->eps[i]; if(c>0)  set_add1(&ind,c);}
       t=e->tcoef;
       for(i=0; i<maxIndex; i++)  if(t->tens[i]) set_add1(&ind,i+1);
       if(first) index=ind; else  if(!set_eq(index,ind)) return 1; 
       first=0;
    } return 0;   
      
  }
  return 1;   
} 
Exemple #2
0
symb_data symb_sum(symb_data S1, int del1, symb_data S2, int del2)
{
  symb_data ans={{NULL},errortp}, s1,s2;
  set index1,index2;
    
  if( S1.type==errortp || S2.type==errortp  
    ||S1.type==indextp || S2.type==indextp) return ans; 
 
  if(S1.expr.p==NULL)
  { if(del2) return S2; else return symb_copy(S2);}

  if(S2.expr.p==NULL)
  { if(del1) return S1; else return symb_copy(S1);}

 
  index1= symb_index(S1);
  index2= symb_index(S2); 
  
  if(!set_eq(index1,index2)) 
  {  
      printf("index problem\n");
      set_print(index1);
       set_print(index2);
        return ans;
         
  }

  if(S1.expr.p==S2.expr.p)
  { S2=symb_copy(S2); 
    del1=(del1||del2);
    del2=1;
  }

  if(S1.type<S2.type)
  {  symb_data S=S1;
     int del=del1;
     S1=S2; S2=S;
     del1=del2; del2=del;
  }
  
  if(S1.type>S2.type)                      
  {    
    s2=symb_typeUp(S2,del2,S1.type);
    if(s2.type==errortp) return ans; 
  } else 
  if(del2) s2=S2; else s2=symb_copy(S2);   
  if(del1) s1=S1; else s1=symb_copy(S1); 

  switch(s1.type)
  {      
     case numbertp : 
     case polytp   : sewpoly(&s1.expr.p,&s2.expr.p);   break;         
     case vectortp :
     case tenstp   : sewtens(&s1.expr.t,&s2.expr.t);   break;
     case spintp   : addSpin(&s1.expr.s,s2.expr.s);    break;
     case etenstp  : addEtens(&s1.expr.et,s2.expr.et); break;
   } 
 
   return s1;
}
Exemple #3
0
void
AudioProcessor::set_state(const AudioProcessorState *state)
{
  if (!state) return;

  // Channel order
  set_input_order(state->input_order);
  set_output_order(state->output_order);
  // Master gain
  set_master(state->master);
  // AGC
  set_auto_gain(state->auto_gain);
  set_normalize(state->normalize);
  set_attack(state->attack);
  set_release(state->release);
  // DRC
  set_drc(state->drc);
  set_drc_power(state->drc_power);
  // Matrix
  // (!) Auto matrix option must be set before setting the matrix
  // because when auto matrix is on, mixer rejects the new matrix.
  set_auto_matrix(state->auto_matrix);
  set_matrix(state->matrix);
  // Automatrix options
  set_normalize_matrix(state->normalize_matrix);
  set_voice_control(state->voice_control);
  set_expand_stereo(state->expand_stereo);
  // Automatrix levels
  set_clev(state->clev);
  set_slev(state->slev);
  set_lfelev(state->lfelev);
  // Input/output gains
  set_input_gains(state->input_gains);
  set_output_gains(state->output_gains);
  // SRC
  set_src_quality(state->src_quality);
  set_src_att(state->src_att);
  // Eqalizer
  set_eq(state->eq);
  if (state->eq_master_bands)
    set_eq_bands(CH_NONE, state->eq_master_bands, state->eq_master_nbands);
  for (int ch = 0; ch < CH_NAMES; ch++)
    if (state->eq_bands[ch])
      set_eq_bands(ch, state->eq_bands[ch], state->eq_nbands[ch]);
  // Bass redirection
  set_bass_redir(state->bass_redir);
  set_bass_freq(state->bass_freq);
  set_bass_channels(state->bass_channels);
  // Delays
  set_delay(state->delay);
  set_delay_units(state->delay_units);
  set_delays(state->delays);
  // Dithering
  set_dithering(state->dithering);
}
Exemple #4
0
/*
 * Assign loop iterations to tiles simply inheriting a seed loop partitioning
 * provided to the inspector.
 */
static int* inherit(loop_t* seedLoop, int tileSize, map_list* partitionings,
                    int* nCore, int* nExec, int* nNonExec, int nThreads)
{
  map_t* partitioning = NULL;
  map_list::const_iterator it, end;
  for (it = partitionings->begin(), end = partitionings->end(); it != end; it++) {
    if (set_eq(seedLoop->set, (*it)->inSet)) {
      partitioning = *it;
      break;
    }
  }
  if (! partitioning) {
    return NULL;
  }

  int setCore = seedLoop->set->core;
  int setSize = seedLoop->set->size;
  int* indMap = new int[setSize];

  ASSERT(partitioning->size == setSize, "Set partitioning size and seed loop size don't match");

  // need to work on a copy because we can't modify an array provided by the user
  memcpy (indMap, partitioning->values, sizeof(int)*setSize);

  // restrict partitions to the core region
  std::fill (indMap + setCore, indMap + setSize, 0);
  std::set<int> partitions (indMap, indMap + setCore);
  // ensure the set of partitions IDs is compact (i.e., if we have a partitioning
  // 0: {0,1,...}, 1: {4,5,...}, 2: {}, 3: {6,10,...} ...
  // we instead want to have
  // 0: {0,1,...}, 1: {4,5,...}, 2: {6,10,...}, ...
  int i;
  std::map<int, int> mapper;
  std::set<int>::const_iterator sIt, sEnd;
  for (i = 0, sIt = partitions.begin(), sEnd = partitions.end(); sIt != sEnd; sIt++, i++) {
    mapper[*sIt] = i;
  }
  for (i = 0; i < setCore; i++) {
    indMap[i] = mapper[indMap[i]];
  }
  *nCore = partitions.size();

  // partition the exec halo region
  chunk_halo (seedLoop, tileSize, *nCore - 1, indMap, nExec, nNonExec, nThreads);

  return indMap;
}
Exemple #5
0
/*
 * Assign loop iterations to tiles carving partitions out of /seedLoop/ using
 * the METIS library.
 */
static int* metis(loop_t* seedLoop, int tileSize, map_list* meshMaps,
                  int* nCore, int* nExec, int* nNonExec, int nThreads)
{
  int i;
  int setCore = seedLoop->set->core;
  int setSize = seedLoop->set->size;

  // use the mesh description to find a suitable map for partitioning through METIS
  map_t* map = NULL;
  map_list::const_iterator it, end;
  for (it = meshMaps->begin(), end = meshMaps->end(); it != end; it++) {
    if (set_eq(seedLoop->set, (*it)->inSet) || set_eq(seedLoop->set, (*it)->outSet)) {
      map = *it;
      break;
    }
  }
  if (! map) {
    // unfortunate scenario: the user provided a mesh description, but the loop picked
    // as seed has an iteration space which is not part of the mesh description.
    // will have to revert to chunk partitioning
    return NULL;
  }

  // now partition through METIS:
  // ... mesh geometry
  int nElements = map->inSet->size;
  int nNodes = map->outSet->size;
  int nParts = nElements / tileSize;
  int arity = map->size / nElements;
  // ... data needed for partitioning
  int* indMap = new int[nElements];
  int* indNodesMap = new int[nNodes];
  int* adjncy = map->values;
  int* offsets = new int[nElements+1]();
  for (i = 1; i < nElements+1; i++) {
    offsets[i] = offsets[i-1] + arity;
  }
  // ... options
  int result, objval, ncon = 1;
  int options[METIS_NOPTIONS];
  METIS_SetDefaultOptions(options);
  options[METIS_OPTION_NUMBERING] = 0;
  options[METIS_OPTION_CONTIG] = 1;
  // ... do partition!
  result = (arity == 2) ?
    METIS_PartGraphKway (&nNodes, &ncon, offsets, adjncy, NULL, NULL, NULL,
                         &nParts, NULL, NULL, options, &objval, indMap) :
    METIS_PartMeshNodal (&nElements, &nNodes, offsets, adjncy, NULL, NULL,
                         &nParts, NULL, options, &objval, indMap, indNodesMap);
  ASSERT(result == METIS_OK, "Invalid METIS partitioning");

  // what's the target iteration set ?
  if (set_eq(seedLoop->set, map->inSet)) {
    delete[] indNodesMap;
  }
  else {
    // note: must be set_eq(seedLoop->set, map-outSet)
    delete[] indMap;
    indMap = indNodesMap;
  }
  delete[] offsets;

  // restrict partitions to the core region
  std::fill (indMap + setCore, indMap + setSize, 0);
  std::set<int> partitions (indMap, indMap + setCore);
  // ensure the set of partitions IDs is compact (i.e., if we have a partitioning
  // 0: {0,1,...}, 1: {4,5,...}, 2: {}, 3: {6,10,...} ...
  // we instead want to have
  // 0: {0,1,...}, 1: {4,5,...}, 2: {6,10,...}, ...
  std::map<int, int> mapper;
  std::set<int>::const_iterator sIt, sEnd;
  for (i = 0, sIt = partitions.begin(), sEnd = partitions.end(); sIt != sEnd; sIt++, i++) {
    mapper[*sIt] = i;
  }
  for (i = 0; i < setCore; i++) {
    indMap[i] = mapper[indMap[i]];
  }
  *nCore = partitions.size();

  // partition the exec halo region
  chunk_halo (seedLoop, tileSize, *nCore - 1, indMap, nExec, nNonExec, nThreads);

  return indMap;
}
Exemple #6
0
void music_play(void)
{
    u8 key;
    u8 file_end_time;

#ifdef ADKEY_SELECT_MODE
    mode_switch_protect_bit=0;
#endif	
    while (1)
    {	   		
		if (play_status == MUSIC_PLAY)
		{
			dac_out_select(DAC_DECODE);
		}
		//suspend_sdmmc();

		key = get_msg();
		
#ifdef USE_USB_PROG_PLAY_MODE
		if(usb_play_prog_mode){
			
			usb_prog_hdlr(key);
			if((key==INFO_HALF_SECOND)||(key==(INFO_MODE | KEY_SHORT_UP))||(key==(INFO_NEXT_FIL | KEY_SHORT_UP))||(key==(INFO_PREV_FIL | KEY_SHORT_UP))){
				key = 0xFF;
			}		
		}
#endif	

        switch (key)
        {
        case INFO_NEXT_SYS_MODE:
		return;
		
        case INIT_PLAY:                                 //开始解码播放
            	file_end_time = 0;
            	stop_decode();
		playpoint_flag = 0;
              if(playpoint_filenum)
		{
		    playpoint_flag = 1;
			given_file_number = playpoint_filenum;
		}
#if FILE_ENCRYPTION
            password_start(0);
#endif
            	if (!fs_getfile_bynumber(given_file_number))
            	{
			put_msg_lifo(INFO_NEXT_FIL | KEY_SHORT_UP);
                	break;
            	}

            	if (!start_decode())
            	{
			put_msg_lifo(INFO_NEXT_FIL | KEY_SHORT_UP);
            	}	
#ifdef USE_USB_PROG_PLAY_MODE
		if(usb_prog_icon_bit){
			usb_prog_play=1;
		}
#endif
				
            	break;

        case SEL_GIVEN_DEVICE_GIVEN_FILE:              ///<获取指定设备的指定文件
		get_music_file2();
            	break;
        case INFO_STOP| KEY_SHORT_UP :
#ifdef USE_USB_PROG_PLAY_MODE

		if(usb_prog_play){
				
				usb_prog_play=0;
				usb_play_prog_index =0;
				
				flush_all_msg();
				stop_decode();
				Disp_Con(DISP_STOP);
   			 //printf(" ---> usb_prog_icon_bit	%x \r\n",(u16)usb_prog_icon_bit);
				play_mode  =REPEAT_OFF;
				
				break;
		}
		usb_prog_mode_cls();
#endif

		if((get_device_online_status()==0)){
			break;
		}

		Mute_Ext_PA(MUTE);            
		disp_play_filenum_timer=6;
		play_mode  =REPEAT_OFF;

		flush_all_msg();
		stop_decode();
		Disp_Con(DISP_STOP);			
		break;
        case INFO_NEXT_FIL | KEY_SHORT_UP:
			
#ifdef USE_FOLDER_SELECT_FUNC
		if(folder_select){
			
			select_folder_file(FIND_NEXT_DIR);
		       Disp_Con(DISP_DIR);	
			break;			   
		}
#endif
		disp_play_filenum_timer=10;

		get_music_file1(GET_NEXT_FILE);
            	break;

        case INFO_PREV_FIL | KEY_SHORT_UP:
			
#ifdef USE_FOLDER_SELECT_FUNC
		if(folder_select){
			
			select_folder_file(FIND_PREV_DIR);
		       Disp_Con(DISP_DIR);	
			break;
		}
#endif		

		if(rew_play_timer>0){

			rew_play_timer=0;
                	put_msg_lifo(INIT_PLAY);
		}
		else
		{
			disp_play_filenum_timer=10;
			get_music_file1(GET_PREV_FILE);
		}
            	break;
        case INFO_NEXT_FIL | KEY_HOLD:
			
		if(play_status)
		{
			ff_fr_step = FAST_FARWORD_STEP;
			play_status = MUSIC_FF_FR;
#if (FF_FR_MUSIC)
			if(0 == decode_cmd)
#endif
			{			
				analog_vol_set(0);
				decode_cmd = 0xf0;
			}
            	}
		break;
        case INFO_PREV_FIL | KEY_HOLD:
	       if(music_type == 2)    //wav文件不支持断点记忆,故可以快退
	       { 
	             playpoint_flag =0;
	       }
			
		if(!playpoint_flag) 				//读取断点信息后不支持快退
		{
			if(play_status)
			{
				ff_fr_step = -FAST_FARWORD_STEP;
				play_status = MUSIC_FF_FR;
#if (FF_FR_MUSIC)
				if(0 == decode_cmd)
#endif					
				{
					analog_vol_set(0);
					decode_cmd = 0xf1;
				}
			}    
		}
		break;

        case DECODE_MSG_DISK_ERR:
#ifdef MP3_UART_ENABLE
			sys_printf(" DECODE_MSG_DISK_ERR");
#endif
			
		get_music_file3();
            	break;

        case DECODE_MSG_FILE_END:               ////*将文件结束的消息放到半秒消息中处理,防止单曲循环遇到错误歌曲无法手动切换下一首,或遇到错误歌曲无法到上一首,每首歌曲至少播放约5S*/
		if (get_music_play_time() < 5)
		{
			file_end_time = 7 - (u8)get_music_play_time();
            	}
		else
		{	

#ifdef MP3_UART_ENABLE
			sys_printf(" DECODE_MSG_FILE_END");
#endif
		
			get_music_file1(GET_PLAY_FILE);
		}
		break;
    	case MSG_USB_DISK_IN  :
		Disp_Con(DISP_SCAN_DISK);	
        	disp_scenario = DISP_NORMAL;
	 	//Add_Func_To_List(USB_DEV);
        	given_device = BIT(USB_DISK);
        	put_msg_lifo(SEL_GIVEN_DEVICE_GIVEN_FILE);	
	break;   
	
        case INFO_NEXTMODE:                     ///<下一个模式
		//work_mode = SYS_IDLE;
            //return;
	        stop_decode();
#ifdef NO_DEV_SHOW_NO_DEV
#ifdef USE_USB_PROG_PLAY_MODE
		usb_prog_mode_cls();
#endif
		folder_select=0;
		folder_mode_select=0;
		Disp_Con(DISP_NODEVICE);
#else
             	Disp_Con(DISP_RTC);
		disp_scenario = DISP_RTC_SCEN;
#endif		
		break;
        case INFO_PLAY | KEY_SHORT_UP :
			
#if defined(USE_TIMER_POWER_OFF_FUNC)
		if(timer_setting_enable){
			timer_pwr_setting();
			break;
		}
#endif		
		if((get_device_online_status()&0x03)==0){
			break;
	     }		
            if (DISP_DWORD_NUMBER == curr_menu)
            {
                	Disp_Con(DISP_NULL);
			put_msg_fifo(INFO_PICK_SONG | KEY_SHORT_UP);
                	break;
            }
			
            if (play_status == MUSIC_PAUSE)
            {
			Mute_Ext_PA(UNMUTE);
			play_status = MUSIC_PLAY;
			Disp_Con(DISP_PLAY);
                	mad_control(MAD_PLAY,0);
			if(music_type == 1)
				enable_decodeint();
			if(music_type == 2)
				enable_softint();
            }
            else if (play_status == MUSIC_PLAY)
            {
			Mute_Ext_PA(MUTE);            
			play_status = MUSIC_PAUSE;
			if(music_type == 1)
				disable_decodeint();
			Disp_Con(DISP_PAUSE);
                	mad_control(MAD_PAUSE,0);
                	read_usb_remain_data();
			write_playtime(&playpoint_time);	   	//暂停时记忆断点信息(EEPROM)
            }
            else if (play_status == MUSIC_STOP){

			disp_play_filenum_timer=10;
			
#ifdef USE_USB_PROG_PLAY_MODE
			if(usb_play_prog_mode){

				if(usb_prog_tab[0]!=0){
					given_file_number =usb_prog_tab[0];

				}
				else{
					usb_prog_mode_cls();
				}
				usb_play_prog_mode=0;
			}				
#endif
                	put_msg_lifo(INIT_PLAY);
			//Mute_Ext_PA(UNMUTE);

	     }
            break;

        case INFO_PICK_SONG | KEY_SHORT_UP :
            given_file_number = (u16)cfilenum;           
            cfilenum = 0;
	     if ((given_file_number > 0) && (given_file_number <= fs_msg.fileTotal))
            {
                	put_msg_lifo(INIT_PLAY);
                	break;
            }
	     Disp_Con(DISP_ERROR);
            break;
       case INFO_HALF_SECOND :
	   	
#if ((USE_DEVICE == MEMORY_STYLE)&&(FAT_MEMORY))      
            updata_fat_memory();
#endif

#if defined(USE_BAT_MANAGEMENT)
	     bmt_hdlr();
#endif
#ifdef USE_USB_ERP_2_HDLR
	     usb_erp_2_timer_hdlr();
#endif

#if defined(USE_TIMER_POWER_OFF_FUNC)
	       timer_pwr_off_hdlr();
#endif

            set_brightness_fade_out();
	     update_playpoint(&playpoint_time);		//半秒更新断点进度,不写入存储器

#if 1//defined(USE_FOLDER_SELECT_FUNC)
		if(folder_select){
           	 	return_cnt++;
            		if (RETURN_TIME == return_cnt){
				return_cnt=4;
				folder_select=0;
			}
			else{
				break;
			}
		}
#endif		
	    if(adkey_detect){
	   	    adkey_detect=0;
	   	    set_sys_vol(my_music_vol);
	    }

	     if(disp_play_filenum_timer>0)disp_play_filenum_timer--;
		 
            if (file_end_time)
            {
			file_end_time--;
                	if (file_end_time == 0)
			{
                    		get_music_file1(GET_PLAY_FILE);		
			}
            }
#if FF_FR_MUSIC	   ///在每一次快进完成之后,播出半秒左右的声音
	     if ((2 == decode_cmd)&&(play_status == MUSIC_FF_FR))
	     {
			decode_cmd = 0;
			set_eq(eq_mode);
			play_status = MUSIC_PLAY;
	     }

#else
            if ((decode_cmd != 0) && (decode_cmd <= 2))		
            {
                	decode_cmd--;
			set_eq(eq_mode);
                	if (decode_cmd == 0) 					///<快进快退结束后1S,打开主音量
		  	{
				play_status = MUSIC_PLAY;
		   	}
            }
#endif
#ifdef RTC_DISP_IN_IDLE_MODE

	    if(disp_scenario == DISP_RTC_SCEN){

		    	rtc_setting_exit();

			if(curr_menu != DISP_RTC){
            			return_cnt++;
            			if (RETURN_TIME == return_cnt){
					rtc_disp_hdlr();
				}
				break;
			}
			rtc_disp_hdlr();
			break;
	     }
#endif	

#ifdef NO_DEV_SHOW_NO_DEV
		if((get_device_online_status()&0x03)==0){
			Disp_Con(DISP_NODEVICE);
			break;
		}
#endif            

            if (DISP_PLAY == curr_menu)
            {
			rew_play_timer=1;				            
                	disp_file_time();
            }

            return_cnt++;
            if (RETURN_TIME == return_cnt)
            {

#if defined(USE_TIMER_POWER_OFF_FUNC)	
			timer_setting_enable=0;
#endif

                if (DISP_DWORD_NUMBER == curr_menu)
                {
			Disp_Con(DISP_NULL);
                    	put_msg_fifo(INFO_PICK_SONG | KEY_SHORT_UP);
                }
                else
                {
                    if (play_status== MUSIC_PAUSE){
                        if (curr_menu != DISP_PAUSE)
                            Disp_Con(DISP_PAUSE);
                    }
                    else if(play_status== MUSIC_PLAY){
                        if (curr_menu != DISP_PLAY){

				if(disp_play_filenum_timer==0)
                            Disp_Con(DISP_PLAY);
				else
                            Disp_Con(curr_menu);
			   }
                    }
		      else if(play_status== MUSIC_STOP){

                        if (curr_menu != DISP_STOP)
                            Disp_Con(DISP_STOP);
			  }
                }
            }
#if 1//( USE_RTCRAM == MEMORY_STYLE  )
			save_playpoint(2);	   	//2*0.5 = 1s 1s记录一次播放进度,
#endif
		break;

	 case INFO_MODE | KEY_LONG:

		if((get_device_online_status()==0)){
			break;
		}
#if 0		
#ifdef USE_USB_PROG_PLAY_MODE
		if(play_status == MUSIC_STOP){
			usb_prog_play_init();
			break;
		}
#endif
#endif
		folder_mode_select=~folder_mode_select;
		folder_select=folder_mode_select;
		if(folder_mode_select){
#ifdef USE_USB_PROG_PLAY_MODE
			usb_prog_mode_cls();
#endif		
		       Disp_Con(DISP_DIR);	
		}
		else{
		       Disp_Con(DISP_PLAY);	
		}
		break;
	 case INFO_MODE | KEY_SHORT_UP:

		if((get_device_online_status()==0)){
			break;
		}
#ifdef USE_USB_PROG_PLAY_MODE
		if(play_status == MUSIC_STOP){
			usb_prog_play_init();
			break;
		}
#endif
        case INFO_PLAY_MODE :

		//if(usb_play_prog_mode||usb_prog_icon_bit){
		//	 break;
		//}			
		
		play_mode++;
            	if (play_mode > REPEAT_END)
            	{
                	play_mode = REPEAT_HEAD;
            	}
#ifndef NO_PLAY_MODE_STR_DISP				
            write_info(MEM_PLAY_MODE,play_mode);
            Disp_Con(DISP_PLAYMODE);
#endif			
            break;
			
	    case INFO_EQ_UP | KEY_SHORT_UP :
               
	        eq_mode++;
	        if (eq_mode > CLASSIC)
	        {
	            eq_mode = NORMAL;
	        }
	        write_info(MEM_EQ_MODE,eq_mode);
	        set_eq(eq_mode);
	        Disp_Con(DISP_EQ);
	        break;
#if 0			
    	case INFO_MODE | KEY_LONG:
		if(disp_scenario == DISP_RTC_SCEN){

			if(rtc_setting==0){
				rtc_setting = 0x01;
				rtc_set = 3;
	                	rtc_set_cnt=30;
			}
		}			
		break;
#endif		
#if RTC_ENABLE 
	 case INFO_ALM_BELL :					///<闹钟响消息,进入闹钟循环
            	if (play_status)
            	{
				/**/
			if(music_type == 1)
				disable_decodeint();
                
			mad_control(MAD_PAUSE,0);
                	read_usb_remain_data();
            	}
            
		if(alm_bell_mode())
		{
			if (play_status)
		       {
	              	mad_control(MAD_PLAY,0);
				if(music_type == 1)
					enable_decodeint();
				if(music_type == 2)
					enable_softint();			
	            	}
			return;	
		}

            	if (play_status)
            	{
                	mad_control(MAD_PLAY,0);
			if(music_type == 1)
				enable_decodeint();
			if(music_type == 2)
				enable_softint();			
            	}
#ifdef PWR_CTRL_IN_IDLE_MODE

#if defined(PWR_CTRL_WKUP)
		wkup_pin_ctrl(1);
#else
		PWR_CTRL_GPIO_INIT();
		PWR_CTRL_EN();
#endif

#endif
		break;
#endif			
        default :
_HOT_KEY_HDLR:		
            if (!ap_handle_hotkey(key))
                return;
            if ((!play_status) && (!device_check()))
            {
		if(disp_scenario == DISP_NORMAL){

		  	stop_decode();
	             	Disp_Con(DISP_RTC);
			disp_scenario = DISP_RTC_SCEN;
		  }
                play_status = MUSIC_PLAY;
                //return;
            }
        }
    }
}
Exemple #7
0
/*----------------------------------------------------------------------------*/
bool start_decode(void)
{

#ifdef PWR_CTRL_IN_IDLE_MODE

#if defined(PWR_CTRL_WKUP)
	wkup_pin_ctrl(1);
#else
	PWR_CTRL_GPIO_INIT();
	PWR_CTRL_EN();
#endif

#endif

    	if(folder_select){
		Disp_Con(DISP_DIR);
    	}
   	else
	{
		Disp_Con(DISP_FILENUM);
    	}
	
#if FILE_ENCRYPTION
    if((fs_msg.fname[8]== 'S')&&(fs_msg.fname[9]== 'M')&&(fs_msg.fname[10]== 'P'))
    {
        password_start(1);
    }
    else
    {
        password_start(0);
    }
#endif
    mad_control(0,(u16)buffer);
    set_eq(eq_mode);                             //必须在每首歌曲播放前初始化EQ
    music_type = musice_format_check(buffer);

#if EQ_WORK_USE == DSP_EQ
    sysclock_div2(0);
#ifndef NO_SD_DECODE_FUNC						
    sd_speed_init(1, 100);
#endif
#else
	if (music_type == 2) 							//wav
	{
    		sysclock_div2(0);
#ifndef NO_SD_DECODE_FUNC						
    		sd_speed_init(1, 100);
#endif
	}
	else
	{
		sysclock_div2(1);
#ifndef NO_SD_DECODE_FUNC			
    		sd_speed_init(0, 50);
#endif
	}
#endif
    	get_filetag(buffer);
    	my_memset(win_buffer, 0, 512);              //解码前,必须清除buffer
  	write_info(MEM_ACTIVE_DEV,device_active);	
//breakpoint
	load_playpoint();
	write_playpoint_info(device_active);
    	update_playpoint(&playpoint_time);		//半秒更新断点进度,不写入存储器
	write_dev_playtime(device_active);			 //更新断点信息
    	playpoint_filenum = 0;
//breakpoint
	flush_low_msg();
    	play_status = MUSIC_PLAY;
    	decode_cmd = 0;
    	decode_user_exit(0);				  //非正常歌曲可通过按键强行停止解码,每次播放前必须清除
    	enable_softint();					   
    	enable_decode_isr();
    	if (2 == music_type)                   //wav文件,
    	{
     		 delay_10ms(5);
    	}
	set_sys_vol(my_music_vol);
	Mute_Ext_PA(UNMUTE);
	
    	cfilenum = 0;
    	return 1;
}
/*----------------------------------------------------------------------------*/
void usb_audio_massstorage(void)
{
    device_check();
    if (pc_connect)
    {
        input_number_en = 0;
        vol_change_en=1;
        //sd_speed_init(0, 100);
        main_menu = MENU_USBDEV_MAIN;
        disp_port(MENU_USBDEV_MAIN);
        usb_config(USB_DEVICE_CFG);
        write_protect_set(0);                           //不使用写保护功能,如果需要,请根据卡座写保护的状态改变配置
        SYSTEM_CLK_DIV1();
        init_usb_device_hardware();
#if((PLL_IN_HPRC == INPUT_OSC_SELECT) && USE_SOF_PLL)
        {
            u8 flag;
            flag = correct_hprc();
            if(1 == flag)			 ///<限定时间内,校准通过,保存矫正值
            {
                write_hprc_cnt(MEM_PLLCON0, memery_hprc_cnt);
//			deg_string("secuss\n");
            }
            else if(0 == flag)		  ///<校准时USB线拔出
            {
                work_mode = MUSIC_MODE;
                IE1 &= ~BIT(1);
                P3PU &= ~BIT(6);
//			deg_string("unsecuss\n");
                return;
            }
            else if(2 == flag)		 ///<限定时间内,校准失效,可继续相应功能
            {
//			work_mode = MUSIC_MODE;
//			IE1 &= ~BIT(1);
//        	P3PU &= ~BIT(6);
//			return;
            }
        }
#endif
        key_table_sel(0);
        flush_all_msg();
#if ((USB_DEVICE_CFG & USB_SPEAKER) == USB_SPEAKER)
        set_eq(eq_mode);
#endif
        alm_request_cnt = 0;
        set_max_vol(MAX_ANOLOG_VOL,MAX_DIGITAL_VOL);///设置最大音量
        usb_device();
        recording_end();
        dac_mute_control(0,1);		 ///<退出PC后,关掉DAC MUTE。
#if ((USB_DEVICE_CFG & USB_SPEAKER) == USB_SPEAKER)
        main_vol_set(0, CHANGE_VOL_NO_MEM);
#endif
        IE1 &= ~BIT(1);
        P3PU &= ~BIT(6);
    }
    else
    {
        work_mode++;
        Set_Curr_Func(work_mode);
    }
}
/*----------------------------------------------------------------------------*/
void music_play(void)
{
    u8 key;
    u8 res;
	
    while (1)
    {
#if (FF_FR_MUSIC == 0)
        if (play_status == MAD_PLAY)
        {
            dac_out_select(DAC_MUSIC, 0);
        }
#else
        if ((play_status == MAD_PLAY) || (play_status == MAD_FF) || (play_status == MAD_FR))
        {
            dac_out_select(DAC_MUSIC, 0);
        }
#endif
        //suspend_sdmmc();						//可减少SDMMC功耗,但会增加电源波动
        key = app_get_msg();

        switch (key)
        {
        case MSG_CHANGE_WORK_MODE:
            //backup_music_point();
           break;
           // return;

        case MSG_DEVICE_REMOVED:
        	device_check();
        	disk_remove_deal_for_music();
		stop_decode();
	 	dev_remov_timer=8;
		
            break;

        case MSG_MUSIC_NEW_DEVICE_IN:							//有新设备接入
            //backup_music_point();
            flush_all_msg();
            given_file_method = PLAY_FIRST_FILE;
	case MSG_MUSIC_SELECT_NEW_DEVICE:					        //重新选择设备
            res = find_device(given_device);

            if ((res == DEV_INIT_ERR) ||
                    (res == NO_DEFINE_DEV))                    //指定的设备不在线,或初始化失败
            {
			disk_toc_ok=0;
			dev_invalid=1;
		    //Set_Curr_Func(SYS_IDLE);
       	    //put_msg_lifo(MSG_CHANGE_WORK_MODE);      
	            break;
				
                //given_device = DEVICE_AUTO_NEXT;			   //自动选择下一个设备
                //put_msg_lifo(MSG_MUSIC_SELECT_NEW_DEVICE);
                //break;
            }
            else if ((res == NO_EFFECTIVE_DEV) ||
                     (res == NO_DEV_ONLINE))                    //无可播放的设备
            {
#if defined(NO_DEV_DEFAULT_GO_TO_AUX)
		 //Set_Curr_Func(SYS_AUX);
#elif defined(NO_DEV_DEFAULT_GO_TO_IDLE)
		// Set_Curr_Func(SYS_IDLE);
        	 //put_msg_fifo(MSG_NO_DEVICE);	 
#else
		 //Set_Curr_Func(SYS_FMREV);
#endif

			disk_toc_ok=0;
			dev_invalid=1;

		 //Set_Curr_Func(SYS_IDLE);
       	 //put_msg_lifo(MSG_CHANGE_WORK_MODE);      
	        break;

            }
            else
                put_msg_lifo(MSG_MUSIC_SELECT_NEW_FILE);		//找到可用设备

	     first_init_dev =1;

            break;

        case MSG_MUSIC_SELECT_NEW_FILE:

#if 0
            if (device_check() == 0)                                //当前播放设备已经不在线,则自动选取下一个设备
            {
#if 1
			disk_toc_ok=0;
	    	 //Set_Curr_Func(SYS_IDLE);
	        //put_msg_lifo(MSG_CHANGE_WORK_MODE);      
#else            
                given_device = DEVICE_AUTO_NEXT;
                put_msg_lifo(MSG_MUSIC_SELECT_NEW_DEVICE);
#endif				
                break;
            }
#endif
            res = fs_get_filenum(play_mode, given_file_method);

#if 0
            if (res == GET_DEVICE_END)								//下一曲到设备的结束,查找下一个设备的第一首
            {
                given_file_method = PLAY_FIRST_FILE;
                given_device = DEVICE_AUTO_NEXT;
                put_msg_lifo(MSG_MUSIC_SELECT_NEW_DEVICE);
                break;
            }
            else if (res == GET_DEVICE_HEAD)								//上一曲到设备的结束,查找下一个设备的最后一首
            {
                given_file_method = PLAY_LAST_FILE;
                given_device = DEVICE_AUTO_PREV;
                put_msg_lifo(MSG_MUSIC_SELECT_NEW_DEVICE);
                break;
            }
#endif
	     if(res == GET_DEVICE_END){

	              given_file_method = PLAY_FIRST_FILE;	 	
	     		put_msg_lifo(MSG_MUSIC_STOP);
			break;
	     }

            put_msg_lifo(MSG_MUSIC_PLAY_NEW_FILE);
            break;

        case MSG_MUSIC_PLAY_NEW_FILE:									//按文件序号选择文件进行播放

            flush_all_msg();
            stop_decode();
            cipher_ctl(0);
            res = fs_getfile_bynumber(0, &fat_ptr1, given_file_number);
            disp_port(MENU_FILENUM);

            if (res == 0)
            {
                if (given_file_method == PLAY_BREAK_POINT)
                    res = start_decode();
                else
                    res = start_decode();
            }

            if (res != 0)                                       //播放不成功
            {
                play_status = MAD_STOP_WAIT;
                play_delay_time = 0;
                if (given_file_method <= PLAY_BREAK_POINT) 		//重新找下一首
                {
                    given_file_method = PLAY_NEXT_FILE;
                    break;
                }
                else											//重新找上一首
                {
                    given_file_method = PLAY_PREV_FILE;
                    break;
                }
            }
            main_menu = MENU_MUSIC_MAIN;
            write_file_info();

            break;

        case MSG_DECODE_FILE_END:


            if ((dec_msg->play_time >= 5) || (play_status == MAD_FF) || (play_status == MAD_FR))     //当前歌曲的播放时间大于5S时,直接播放下一首
            {         
                	given_file_method = PLAY_AUTO_NEXT;
                	put_msg_lifo(MSG_MUSIC_SELECT_NEW_FILE);
            }
            else													//当前歌曲播放时间小于5S,有可能是不坏歌曲,等待一段时间
            {
                	play_delay_time = 0;
                	given_file_method = PLAY_AUTO_NEXT;
                	play_status = MAD_STOP_WAIT;
            }

    	     if(play_mode == REPEAT_OFF){
			
		    if(given_file_number ==  fs_msg.fileTotal){
				
	            		flush_all_msg();			
				stop_decode();
	    	   }   
    	     }   
            break;

        case MSG_MUSIC_PREV_FILE:												//选择上一个文件进行播放

            given_file_method = PLAY_PREV_FILE;
            put_msg_lifo(MSG_MUSIC_SELECT_NEW_FILE);
            break;

        case MSG_MUSIC_NEXT_FILE:												//选择下一个文件进行播放

            //delay_10ms(30);
            given_file_method = PLAY_NEXT_FILE;
            put_msg_lifo(MSG_MUSIC_SELECT_NEW_FILE);
            break;
#if defined(DECODE_STOP_MODE_ENABLE	)
	case MSG_MUSIC_STOP:

		if(play_status !=MAD_STOP){
            		flush_all_msg();
			stop_decode();
		}
		break;
#endif		
        case MSG_MUSIC_PP:											//暂停和播放
            if (cur_menu == MENU_INPUT_NUMBER)			            //数字输入模式
            {
                put_msg_lifo(MSG_PICH_SONG);
                break;
            }
			
#if defined(DECODE_STOP_MODE_ENABLE	)			
	    if(play_status ==MAD_STOP){
			
	        	device_check();
				
			if(DSA_SEL_DEV == DEVICE_SDMMC0){
				if((device_online&BIT(0))==0){
					break;
				}	
			}
			else if (DSA_SEL_DEV == DEVICE_UDISK){
				if((device_online&BIT(1))==0){
					break;
				}	
			}
			
                    	given_file_method = PLAY_FIRST_FILE;
                    	put_msg_lifo(MSG_MUSIC_SELECT_NEW_FILE);

			play_status = MAD_PLAY;
			break;
	    }
#endif
            if (play_status == MAD_PLAY)
            {
                disp_port(MENU_PAUSE);
                main_menu = MENU_PAUSE;
                mad_control(MAD_PAUSE, 0);
                play_status = MAD_PAUSE;
 // 		  set_play_flash(LED_FLASH_ON);

            }
            else if (play_status == MAD_PAUSE)
            {
                main_menu = MENU_MUSIC_MAIN;
                disp_port(MENU_MUSIC_MAIN);
                mad_control(MAD_PLAY, 0);
                play_status = MAD_PLAY;
 // 		  set_play_flash(LED_FLASH_NOR);				
            }

            flush_all_msg();
            break;

        case MSG_MUSIC_NEXT_EQ:
            if (play_status == MAD_PAUSE)
                break;
            eq_mode++;
            if (eq_mode > CLASSIC)
            {
                eq_mode = NORMAL;
            }
            set_eq(eq_mode);
            disp_port(MENU_SET_EQ);
            break;

        case MSG_NEXT_PLAYMODE:
            if (play_status == MAD_PAUSE)
                break;
            play_mode++;
            if (play_mode > REPEAT_END)
            {
                play_mode = REPEAT_INIT;
            }
            //disp_port(MENU_SET_PLAY_MODE);
            break;

        case MSG_MUTE:												//静音
            break;

#if (FF_FR_EN == 1)
        case MSG_MUSIC_FR:											//启动快退
            if (find_break_point_file_flag)							//如果是记忆播放的歌曲,不能快退
            {

                break;
            }
            if (play_status == MAD_PLAY)
            {
                play_status = MAD_FR;
            }

            break;

        case MSG_MUSIC_FF:											//启动快进
            if (play_status == MAD_PLAY)
            {
                play_status = MAD_FF;
            }
            break;

		case MSG_KEY_CHANGE:
        case MSG_MUSIC_FFR_DONE:									//快进快退结束,恢复播放
            if (play_status == MAD_FR)
            {
                set_eq(eq_mode);
                flush_all_msg();
#if (FF_FR_MUSIC == 0)

                dac_mute_control(0);
#endif
                play_status = MAD_PLAY;
            }
            else if (play_status == MAD_FF)
            {
                set_eq(eq_mode);
                flush_all_msg();
#if (FF_FR_MUSIC == 0)

                dac_mute_control(0);
#endif
                play_status = MAD_PLAY;
            }

            break;
#endif
        case MSG_PICH_SONG:
            if (cur_menu == MENU_INPUT_NUMBER)			           //数字输入模式
            {
                if ((input_number <= fs_msg.fileTotal) && (input_number != 0))			   //输入数字是否有效
                {
                    given_file_number = input_number;
                    given_file_method = PLAY_FIRST_FILE;
                    given_device = DEVICE_AUTO_NEXT;
                    put_msg_lifo(MSG_MUSIC_PLAY_NEW_FILE);
                }
                else
                    disp_port(main_menu);
            }

            break;

#if (MUSIC_SPECTRUM_EN == 1)
        case MSG_100MS:
            if (cur_menu == MENU_MUSIC_MAIN)
            {
                music_spec_cul(1);
                disp_port(MENU_100MS_REFRESH);
            }
            break;
#endif

        case MSG_200MS:
////////////////////////////////////////////////////////////
//快进快退实际的操作在这里完成
#if (FF_FR_EN == 1)
            if (play_status == MAD_FF)
            {
#if (FF_FR_MUSIC == 0)							//如果需要在快进快退过程中听到声音,可以不加此行
                dac_mute_control(1);
#endif
                mad_control(MAD_FF, FF_FR_STEP);
                mad_control(MAD_FAST_FORWARD, 0);
#if (FF_FR_MUSIC == 1)

                dac_mute_control(0,1);
#endif
                mad_control(MAD_PLAY, 0);
            }
            else if (play_status == MAD_FR)
            {
#if (FF_FR_MUSIC == 0)
                dac_mute_control(1);							//如果需要在快进快退过程中听到声音,可以不加此行
#endif
                mad_control(MAD_FR, FF_FR_STEP);
                mad_control(MAD_FAST_REVERASE, 0);
#if (FF_FR_MUSIC == 1)
                dac_mute_control(0,1);
#endif
                mad_control(MAD_PLAY, 0);
            }
            disp_port(MENU_HALF_SEC_REFRESH);
#endif
#if (DISP_DOT_LCD == 1)
            disp_port(MENU_200MS_REFRESH);								//播放时的滚动显示
#endif
            break;

        case MSG_HALF_SECOND:
/////////////////////////////////////////////////////////////
//短歌曲或损坏的歌曲在这里跳到下一首
            if (play_status == MAD_STOP_WAIT)				//等待一段时间再自动选择下一首
            {
                if (play_delay_time < 4)
                    play_delay_time++;
                else
                {
                    put_msg_lifo(MSG_MUSIC_SELECT_NEW_FILE);
                }
            }

		if(dev_remov_timer>0){

			dev_remov_timer--;
			if(dev_remov_timer==0){
			    	 Set_Curr_Func(SYS_IDLE);
			        put_msg_lifo(MSG_CHANGE_WORK_MODE);      
			}
		}
////////////////////////////////////////////////////////////
//显示界面的切换
            if (main_menu_conter < SUB_MENU_TIME)
            {
                main_menu_conter++;
            }
            else if (cur_menu != main_menu)
            {
                if (cur_menu == MENU_INPUT_NUMBER)			//数字输入模式
                {
                    put_msg_lifo(MSG_PICH_SONG);
                    break;
                }
                else
                {
                    cur_menu = main_menu;
                }
                disp_port(cur_menu);
            }
/////////////////////////////////////////////////////////////
//调整显示亮度
            set_brightness_fade_out();
/////////////////////////////////////////////////////////////
//更新实时界面
            disp_port(MENU_HALF_SEC_REFRESH);
            break;
        case MSG_NEXT_FOLDER:
	     select_folder_file(FIND_NEXT_DIR);		
            break;
        case MSG_PREV_FOLDER:
	     select_folder_file(FIND_PREV_DIR);		
            break;
#if 0//RTC_ENABLE
        case MSG_ALM_ON:
            write_next_alm_sec();
            Set_Curr_Func(SYS_RTC);
            put_msg_lifo(MSG_CHANGE_WORK_MODE);
            break;
#endif
        default :
            ap_handle_hotkey(key);
            break;
        }
    }
}
/*----------------------------------------------------------------------------*/
static u8 start_decode(void)
{
    cipher_judge();

    mad_control(MAD_STOP, 0);
    decode_init();									//解码初始化,会将解码的变量及状态清零
    music_type = music_format_check(decode_buffer);	//检查文件格式

    if (music_type == NOT_SUPPORT)					//不支持的格式
    {
        return 1;
    }
    else if (music_type == IS_MP3)					//MP3
    {

        get_music_tag();
        if (!get_mp3_total_time())
            return 1;
    }
    else
        get_music_tag();

    if (dec_msg->total_time == 0)					//总播放时间为0,则不进行播放,如果遇到因为添加了此判断而不能播放的文件,则可去掉此条件
    {
        return 1;
    }

    set_eq(eq_mode);

#if (BREAK_POINT_PLAY_EN == 1)
    if (find_break_point_file_flag) 								//取保存过的断点信息
    {
        find_break_point_file_flag = load_music_point();
    }
#endif
	dsp_set_dcc_flt(14);
    dsp_set_ch_mode(0);
    dsp_set_rinv_mode(0);
    mad_control(MAD_INIT, 0);
    mad_control(MAD_PLAY, 0);
    play_status = MAD_PLAY;
	
    if (device_active == DEVICE_SDMMC0)
    {
	 Set_Curr_Func(SYS_MP3DECODE_SD);
    }
    else if (device_active == DEVICE_UDISK)
    {

	 Set_Curr_Func(SYS_MP3DECODE_USB);
    }	

      if(first_init_dev){
		first_init_dev =0;

		if(play_status !=MAD_STOP){
            		flush_all_msg();
			stop_decode();
		}
		
      }
	disk_toc_ok=1;
	DSA_clr_ID3_info();
 // set_play_flash(LED_FLASH_NOR);
    return 0;
}
void ap_handle_hotkey(u8 key)
{
    u8 res;

    switch (key)
    {

#if ECHO_ENABLE
    case MSG_REV_SW:
        echo_sw();		
        break;
    
	case MSG_REV_STRONG_UP:
	case MSG_REV_STRONG_DOWN:
        if(echo_strong(key))
        {
            disp_port(MENU_REV_STRONG);   
        }
        break;
	
     case MSG_REV_DEEP_UP:
     case MSG_REV_DEEP_DOWN:
        if(echo_deep(key))
        {
            disp_port(MENU_REV_DEEP);
        }
        break;
#endif

     case MSG_ALM_SETUP:
	 	//clr_alarm_func();
	 	break;
     case MSG_SNOOZE_SETUP:
	 	set_snooze_func();
	 	break;
     case MSG_MUTE_UNMUTE:
	 	sys_mute_flag =~sys_mute_flag;
		if(sys_mute_flag){
    			amp_mute(1);
			PT2313_Config(0,VOL_ADJ);
		}
		else{
			PT2313_Config(sys_main_vol,VOL_ADJ);
    			amp_mute(0);
		}
	 	break;
     case MSG_SLEEP_SETUP:
	 	if(work_mode != RTC_MODE){
			timer_pwr_setting();
		}
		break;
     case MSG_SYS_POWERON:
	 	
	 	if(work_mode==RTC_MODE){
			
	 		work_mode= MUSIC_MODE;
		}
		else{
	 		work_mode= RTC_MODE;
		}

		timer_pwr_idx=0;
		
	       put_msg_lifo(MSG_CHANGE_WORK_MODE);
	 	break;

		
    case MSG_USB_DISK_OUT:
    case MSG_SDMMC_OUT:
		
        set_brightness_all_on();
        if( (!device_check() ) && (encode_status >= RECODE_INIT )) //在录音时,活动设备拔出
        {	
            rec_device_out = 1;
            api_stop_encode();
            if(AUX_MODE == work_mode)
	        {
	            main_menu = MENU_AUX;
				disp_port(MENU_AUX);
	        }
#if FM_MODULE 
			else if(FM_RADIO_MODE == work_mode)
	        {
	            main_menu = MENU_FM_MAIN;
                disp_port(MENU_FM_MAIN);
	        }
#endif
            else
            {
                 put_msg_lifo(MSG_MUSIC_NEW_DEVICE_IN);
                 //break;  
            }
		}
        /*
        if((!device_check()) && (REC_MIC_MODE == work_mode))
        {
             put_msg_lifo(MSG_MUSIC_NEW_DEVICE_IN);
             break;   
        }
        */
	    if(MUSIC_MODE != work_mode)
			break;
        put_msg_lifo(MSG_DEVICE_REMOVED);
        disk_remove_deal_for_music();
        break;

#if USB_DEVICE_ENABLE
    case MSG_USB_PC_IN:

    #if ECHO_ENABLE
        if(BUSY == echo_ptr->status)
        {
            close_echo();
        }
    #endif
        break_encode();
        set_brightness_all_on();
        device_check();
        work_mode = USB_DEVICE_MODE;
        put_msg_lifo(MSG_CHANGE_WORK_MODE);
        break;

    case MSG_USB_PC_OUT:
        set_brightness_all_on();
        break;
#endif

    case MSG_AUX_IN :
        break_encode();
        set_brightness_all_on();
#if USB_DEVICE_ENABLE
        if ((AUX_MODE != work_mode) && (work_mode != USB_DEVICE_MODE))
#else
        if (AUX_MODE != work_mode)
#endif
        {
            work_mode = AUX_MODE;
            put_msg_lifo(MSG_CHANGE_WORK_MODE);
        }
        break;

    case MSG_AUX_OUT :
        set_brightness_all_on();

	 if(work_mode != AUX_MODE)break;
	 
        if((RECODE_WORKING == encode_status)||(RECODE_PAUSE == encode_status))
        {	
            break;
        } 

        break_encode();

	 given_device = DEVICE_UDISK;
        given_file_method = PLAY_BREAK_POINT;      
	 put_msg_lifo(MSG_MUSIC_NEW_DEVICE_IN);
		
        break;

    case MSG_SDMMC_IN :
        set_brightness_all_on();
	 device_check();
        if((RECODE_WORKING == encode_status)||(RECODE_PAUSE == encode_status))
        {	
            break;
        } 
        
        break_encode();

#if USB_DEVICE_ENABLE
        if (work_mode == USB_DEVICE_MODE)
            break;
#endif

		given_device = read_info(MEM_ACTIVE_DEV);

		if(given_device == DEVICE_SDMMC0_REC)
			given_device = DEVICE_SDMMC0_REC;
		else
			given_device = DEVICE_SDMMC0;

        given_file_method = PLAY_BREAK_POINT;
        put_msg_lifo(MSG_MUSIC_NEW_DEVICE_IN);
        break;

    case MSG_USB_DISK_IN  :
        set_brightness_all_on();
		device_check();
        if((RECODE_WORKING == encode_status)||(RECODE_PAUSE == encode_status))
        {
            break;
        }
        break_encode();
       
		given_device = read_info(MEM_ACTIVE_DEV);

		if(given_device == DEVICE_UDISK_REC)
			given_device = DEVICE_UDISK_REC;
		else
	    	given_device = DEVICE_UDISK;

        given_file_method = PLAY_BREAK_POINT;      
        put_msg_lifo(MSG_MUSIC_NEW_DEVICE_IN);
        break;

    case MSG_NEXT_WORKMODE:
        break_encode();


	 if(work_mode == MUSIC_MODE){

		device_check();		
	    	if(((device_active &(~VIRTUAL_DEVICE))== DEVICE_UDISK)&&(device_online&DEVICE_SDMMC0)>0){

		    	given_device = DEVICE_SDMMC0;
		       given_file_method = PLAY_BREAK_POINT;      
		        put_msg_lifo(MSG_MUSIC_NEW_DEVICE_IN);
			break;
		}
	 }
	
        work_mode++;
		

	if(work_mode > MAX_WORK_MODE){
		
            work_mode = MUSIC_MODE;

		if(get_device_online_status()&DEVICE_UDISK){
			
	    		given_device = DEVICE_UDISK;
		        given_file_method = PLAY_BREAK_POINT;      
		        put_msg_lifo(MSG_MUSIC_NEW_DEVICE_IN);
		}
		else if(get_device_online_status()&DEVICE_SDMMC0){
			
	    		given_device = DEVICE_SDMMC0;
		        given_file_method = PLAY_BREAK_POINT;      
		        put_msg_lifo(MSG_MUSIC_NEW_DEVICE_IN);
		}
		else{
        		work_mode++;
		}
	}


        put_msg_lifo(MSG_CHANGE_WORK_MODE);
        break;

    case MSG_VOL_UP:
        if (vol_change_en==0)
            break;

	sys_main_vol++;
	sys_main_vol++;
    case MSG_VOL_DOWN:
        if (vol_change_en==0)
            break;
		
	if(sys_main_vol>0)
		sys_main_vol--;

	if(sys_main_vol>MAX_MAIN_VOL){
		sys_main_vol =MAX_MAIN_VOL;
	}
	
	sys_mute_flag =0;
	
	PT2313_Config(sys_main_vol,VOL_ADJ);
	
	 if(sys_main_vol==0){
    		amp_mute(1);
	 }
	 else{
    		amp_mute(0);
	 }		
        dac_mute_control(0,1);					//调节音量时,自动UNMUTE
        write_info(MEM_VOL, sys_main_vol);
        disp_port(MENU_MAIN_VOL);
        break;
		
     case MSG_MUSIC_NEXT_EQ:
	 if(work_mode == RTC_MODE)
	 	break;

            eq_mode++;
            if (eq_mode > CLASSIC)
            {
                eq_mode = NORMAL;
            }

	    PT2313_Config(eq_mode,EQ_ADJ);
			
            set_eq(NORMAL);
            disp_port(MENU_SET_EQ);
            break;
			
    case MSG_100:
		
        if (!input_number_en)
            break;

	if (input_number > 999)
            input_number = 0;

	      key_100_flag = 0xFF;
#ifdef USE_10_PLUS_FUNC				  
	     input_number = input_number+10;
#else
	     input_number = input_number+100;
#endif
        disp_port(MENU_INPUT_NUMBER);
	break;		
	
    case MSG_0:
    case MSG_1:
    case MSG_2:
    case MSG_3:
    case MSG_4:
    case MSG_5:
    case MSG_6:
    case MSG_7:
    case MSG_8:
    case MSG_9:
		
        if (!input_number_en)
            break;		
		
	     if(key_100_flag ==0xFF){
			input_number += key;
			key_100_flag = 0xFE;
	     }
	     else if(key_100_flag ==0xFE){
		 	
			input_number += (input_number%10)*10-(input_number%10)+key;
			key_100_flag = 0x00;
	     }
	     else 
	     {
	     	     	if((input_number)>6553){
				input_number = 0x0000;			
			}
        		input_number = input_number * 10 + key;
			key_100_flag = 0x00;			
	     }
#if 1
	     if (input_number > 9999)
	     {
		       input_number = 0;			
			input_number = input_number *10 + key;
	    }
#endif
        disp_port(MENU_INPUT_NUMBER);
        break;
////////////////录音
    case MSG_REC_KEY_AT_USB:

       if(RTC_MODE == work_mode){
		break;
	}
	   
	if(RECODE_PLAY >= encode_status)
       {		
		rec_device_sel=DEVICE_UDISK;
		api_stop_encode();			
            	put_msg_lifo(MSG_REC_FIND);
	}
        else
        {
            put_msg_lifo(MSG_REC_STOP);
        }		
	break;
	
    case MSG_REC_KEY_AT_SD:

	if(RTC_MODE == work_mode){
		break;
	}
	if(RECODE_PLAY >= encode_status)
       {		
		rec_device_sel=DEVICE_SDMMC0;
       	api_stop_encode();			
            	put_msg_lifo(MSG_REC_FIND);
	}
        else
        {
            put_msg_lifo(MSG_REC_STOP);
        }	
	break;
#if 0	
    case MSG_REC_KEY:	  //录音开始和结束
	if(RECODE_PLAY >= encode_status)
        {
            put_msg_lifo(MSG_REC_FIND);

        }
        else
        {
            put_msg_lifo(MSG_REC_STOP);
        }
        break;
#endif
	case MSG_REC_PP:      //录音暂停和继续录音

        if(RECODE_WORKING == encode_status)
        {
            put_msg_lifo(MSG_REC_PAUSE);
        }
        else if(RECODE_PAUSE == encode_status)
        {

            put_msg_lifo(MSG_REC_CONTINUE);
        }
        break;

    case MSG_ENCODE_END:   //设备写err  或 设备满
	//	deg_str("MSG_ENCODE_END \n");
		if(rec_device_out)		//录音时活动设备拔出,在设备拔出那里处理,在此不做处理
		{
			rec_device_out =0;
			break;
		}

        api_stop_encode();		//停止录音
		put_msg_lifo(MSG_REC_PLAY);
		break;

	 case MSG_ENCODE_FAT_FULL:  //建文件时
	 //	deg_str("MSG_ENCODE_FAT_FULL \n");
		api_stop_encode();		//停止录音
		if(REC_MIC_MODE == work_mode)		//录音时写设备出现问题、设备满
        {
             put_msg_lifo(MSG_MUSIC_NEW_DEVICE_IN);
             break;   
        }
       // break_encode();
        if(AUX_MODE == work_mode)
        {
            main_menu = MENU_AUX;
        }
#if FM_MODULE 
		else if(FM_RADIO_MODE == work_mode)
        {
            main_menu = MENU_FM_MAIN;
        }
#endif
        disp_port(main_menu);
        break;
////////////////录音涉及的各种状态
    case MSG_REC_FIND:
//        if(RECODE_PLAY >= encode_status)
//        {
//            break;
//        }
#if USB_DEVICE_ENABLE
        if(USB_DEVICE_MODE == work_mode)
        {
            break;
        }
#endif
        encode_status = RECODE_INIT;
 
        if(REC_MIC_MODE != work_mode)
        {
            work_mode = REC_MIC_MODE;
            put_msg_lifo(MSG_CHANGE_WORK_MODE);
            given_device = rec_device_sel;//read_info(MEM_ACTIVE_DEV);
            break;
        }
#if 0		
        else //if((MUSIC_MODE != work_mode))
        {
            if (given_device == NO_DEVICE)
            {
                
                given_device = read_info(MEM_ACTIVE_DEV);

            }
        }      
        if( (( given_device & (~VIRTUAL_DEVICE ))  != DEVICE_SDMMC0) 
            && ((given_device & (~VIRTUAL_DEVICE)) != DEVICE_UDISK)
          )
        {
            given_device = DEVICE_SDMMC0;
        }
#endif	
        given_device = rec_device_sel;//read_info(MEM_ACTIVE_DEV);

        sys_clk_div(2);//SYSTEM_CLK_DIV2();

        put_msg_lifo(MSG_MUSIC_SELECT_NEW_DEVICE);
        break;
    case MSG_REC_START:		//开始录音

	rec_device_out = 0;
#if 0
		 rec_sys_set(0);  //0:24M   1:48M
		 sys_clk_div(2);//SYSTEM_CLK_DIV2();  //24 M
#else
	rec_sys_set(1);
	sys_clk_div(1);//SYSTEM_CLK_DIV1();	  //48 M
#endif
        //init_rec_name();

               
        device_active |= VIRTUAL_DEVICE;
        encode_device = device_active;	 //设置录音存储设备

        write_file_info(0);

        set_rec_channel(encode_channel); //设置录音通道  

        set_rec_vol(encode_vol);		 //设置录音音量

		

	if(REC_MIC_MODE == work_mode)
	{	
			kala_dac_off();
//			dac_mute_control(1,1);
#if KALAOK_FUNCTION
			dsp_set_adc_con(0);
			P3HD &=~(1<<6);
#endif
	}

        if(REC_MIC == encode_channel)
        {
            set_rec_track(TRACK_LEFT);
        }
        else
        {
            set_rec_track(TRACK_ALL);
        }
        /**/
        
        CLKGAT |= MP3CLK;// | SPIURCLK;

		
 //     CLKCON0 |= DACCLK;
 //		P3HD &=~(1<<6);
	   
        if(DEVICE_SDMMC0 == (device_active & (~VIRTUAL_DEVICE)))
        {
            CLKGAT |= USBCLK;
        }
        else if(DEVICE_UDISK == (device_active & (~VIRTUAL_DEVICE)))
        {
            CLKGAT |= SDCLK;
        }
#if ECHO_ENABLE
        if(BUSY == echo_ptr->status)
        {
            close_echo();
        }
#endif
        ///0x
        //my_memset(0x4000,0,0x787f-0x4000);
        //my_memset(0x8000,0,0x9c3f-0x8000);

//混响强度 0x400c 取值范围 0-255
//混响深度 0x4015 0x4014   取值范围 0-2048

#if ECHO_ENABLE      
        if(1 != start_encode_echo(IS_MP3))			 //开始录音
#else
        if(1 != start_encode(IS_MP3))			 //开始录音
#endif
        {
		put_msg_lifo(MSG_ENCODE_FAT_FULL);
		break;
	}
#if ECHO_ENABLE  ///<减弱冲击声,打开混响深度和强度
        delay_10ms(20);
        if( REC_MIC == ( encode_channel & 0xf ) ) ///<MIC 下有混响
        {
            set_echo(app_echo.strong, app_echo.deep);
        }
//        app_echo.strong = REC_ECHO_STRONG;
        echo_vol_set(REC_MIC_VOL);

#endif

        /*
        if(REC_MIC_MODE == work_mode)
        {
    		while(!((cmd_ctl_rec(REC_NO_OPT,0)) &  FRIST_ADC_PACKET)) //采数据前的处理
    		{
    
    		}
            delay_10ms(50);//抛弃半秒的数据
        }
		cmd_ctl_rec(ENABLE_REC_DATA,ENABLE_REC_BIT);
        */
        encode_status = RECODE_WORKING;
#if 0//FM_MODULE 
		if(FM_RADIO_MODE != work_mode)
#endif
		{
		 	main_menu = MENU_RECWORKING;//
		}
		disp_port(main_menu);
        //disp_port(MENU_REC);
        break;
    case MSG_REC_STOP:      //停止录音
        api_stop_encode();		//停止录音
        put_msg_lifo(MSG_REC_PLAY);
        break;
    case MSG_REC_PAUSE:     //暂停录音
		encode_status = RECODE_PAUSE;
	
#if  0//FM_MODULE 
		if(FM_RADIO_MODE == work_mode)
			disp_port(MENU_FM_MAIN);
		else
#endif
		{
			main_menu = MENU_REC_PAUSE;	
		  	disp_port(MENU_REC_PAUSE);
		}
		 		
        pause_encode();
        break;
    case MSG_REC_CONTINUE:  //暂停录音之后继续录音
		encode_status = RECODE_WORKING;
	
#if FM_MODULE 
		if(FM_RADIO_MODE == work_mode)
			disp_port(MENU_FM_MAIN);
		else
#endif
		{
		 	main_menu = MENU_RECWORKING;//
		    disp_port(MENU_RECWORKING);
		}
			
        continue_encode();
        break;
    case MSG_REC_PLAY:     //播放最后的录音文件

        encode_status = RECODE_PLAY;
        given_device = encode_device & (~VIRTUAL_DEVICE);

        if( (given_device != DEVICE_SDMMC0) && (given_device != DEVICE_UDISK))
        {
            given_device = DEVICE_SDMMC0;
        }
        given_device |= VIRTUAL_DEVICE;
        if((MUSIC_MODE != work_mode))
        {
            put_msg_lifo(MSG_MUSIC_NEW_DEVICE_IN);
        }
        else
        {
            put_msg_lifo(MSG_MUSIC_SELECT_NEW_DEVICE);
        }
        break;

    case MSG_MUSIC_SELECT_NEW_DEVICE:					        //重新选择设备

        res = find_device(given_device);

        if ((res == DEV_INIT_ERR) ||
                (res == NO_DEFINE_DEV))                    //指定的设备不在线,或初始化失败
        {
		
            given_device = DEVICE_AUTO_NEXT;			   //自动选择下一个设备
            put_msg_lifo(MSG_MUSIC_SELECT_NEW_DEVICE);
            break;
        }
        else if ((res == NO_EFFECTIVE_DEV) ||
                 (res == NO_DEV_ONLINE))                    //无可播放的设备
        {		
            if(RECODE_STOP != encode_status)
            {
                encode_status = RECODE_STOP;
		  if(REC_MIC_MODE == work_mode)
	         {
					put_msg_lifo(MSG_NEXT_WORKMODE);
		  }
                break;
            }
            else
            {	
                put_msg_lifo(MSG_NEXT_WORKMODE);
            }
            break;
        }
        else
        {		
            if(RECODE_PLAY < encode_status)
            {
                put_msg_lifo(MSG_REC_START);
            }
            else
            {
                if(RECODE_PLAY == encode_status)  //去播刚录好的文件
                {
                    encode_status = RECODE_STOP;
#if VIRTUAL_ENABLE
                    given_file_number = encode_filenum;
#else
                    given_file_number = encode_filenum + encode_fristfile - 1;
#endif
                    put_msg_lifo(MSG_MUSIC_PLAY_NEW_FILE);
                }
                else
                {
                    put_msg_lifo(MSG_MUSIC_SELECT_NEW_FILE);		//找到可用设备
                }
            }
            
        }
        break;



    }
}
Exemple #12
0
u8 decode_voicetime_file()
{
	u8 key; 
   	u8 cnt =0;
    	u8 flag;
    	get_time_tobuf();    //获取需要报时的文件

_play_voicetime:
    	voicetime_on = 1;
    	dsp_hi_pro();
    	decodeint_hi_pro();
	f_init(win_buffer, (u16)code_otp_read, 1);
	f_open((u8 *)&fat_file, 0);
    	f_open_dummy_file(0x200);    
    	mad_control(0,(u16)buffer);
    	set_eq(0);                             //必须在每首歌曲播放前初始化EQ
    	music_type = musice_format_check(buffer);
	set_max_vol(MAX_ANALOG_VOL, MAX_DIGITAL_VOL);
    	my_memset(win_buffer, 0, 512);              //解码前,必须清除buffer
	main_vol_set(0, SET_USE_CURRENT_VOL);
    	flush_low_msg();
    	play_status = MUSIC_PLAY;
    	decode_cmd = 0;
    	decode_user_exit(0);
	enable_softint();
    	enable_decode_isr();
	set_device(0);

    	while(1)
	{        
	    key = get_msg();

       	switch (key)
		{    
          case DECODE_MSG_DISK_ERR:
          case DECODE_MSG_FILE_END:
                otp_music_addr = play_buf[cnt];                                   
                cnt++;           
                delay_10ms(20); 
                        
                if(cnt > play_len)
                {
                   cnt= 0;
                   otp_music_addr =0;
                   stop_decode();
    		       return 0;  
                } 
                else
                {
                  goto _play_voicetime; 
                } 	 

		   default :
#if 0		   	
			flag = alm_bell_key(key);
            if(flag)
            {   
                          
               otp_music_addr =0;
               stop_decode();  
               close_alm_bell();                       
              return flag;
            }
#endif	
		break;
		}
	}
}