⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 song_task.c

📁 atmel at89c51snd1c mp3芯片方案源码
💻 C
📖 第 1 页 / 共 2 页
字号:

#include "config.h"                         /* system configuration */
#include "lib_mcu\lcd\lcd_drv.h"  
#include "modules\file\file.h"              /* file definition */
#include "lib_mcu\clock\clock.h"            /* clock definition */
#include "lib_mcu\kbd\key_drv.h"
#include "lib_mcu\aud\aud_drv.h"            /* audio driver definition */
#include "lib_mcu\mp3\mp3_drv.h"            /* mp3 driver definition */
#include "song_drv.h"                       /* song driver definition */
#include "song_task.h"                      /* song task definition */ 
#include "lib_mcu\remote\remote_drv.h"
#include "modules\display\disp_task.h"


extern  bdata   bit     gl_key_press;       /* TRUE when a key is decoded */
extern  Byte    gl_key;             /* value of the key pressed */
extern  bit     led_flush;
Byte            song_state;                 /* task state */
static  bit     song_loop;                  /* auto replay */
extern  Byte    mp3_volume;

sbit    LED_RED   = P1 ^ 4;
sbit    LED_GREEN = P1 ^ 5;



/////////////////////////////////////////////////////////////////////////////////
void song_task_init (void)
{
  key_song_task_init();
  song_loop = PLAYER_PLAY_LOOP;             /* default loop playing */
  song_snd_init();                          /* init sound control */
  song_state = SONG_START;
}

/////////////////////////////////////////////////////////////////////////////////
void song_request_data(void)
{  
  Byte  cpt_data;

  if (Mp3_frame_request())
  { 
    cpt_data = 0;
    do
    {
      Mp3_load(Fgetc());                     //send data while requested 
      cpt_data++;
      // workaround for 320Kbs frame support 
      if ((cpt_data & 0x40) == 0x40)
      {
        Mp3_set_full();
        Mp3_reset_full();                   // ack 64 Bytes write 
        break;
      }
    }
    while (Mp3_frame_request());           //  until frame request 

    while (Mp3_frame_request())             // frame request ? 
    { 
      Mp3_load(Fgetc());                    // send data while requested 
    }
  }  

}



/////////////////////////////////////////////////////////////////////////////////
void song_task (void)
{
  bit     loop;

  song_request_data();

  switch (song_state)
  {
    case SONG_START:
    { 
      print_sound_level();                  /* display volume level */
      song_state = SONG_INSTALL;
      break;
    }

    case SONG_INSTALL:
    {
      if (File_entry_root(FILE_MP3 | FILE_DIR) == OK) /* goto root directory */
      {	
          print_file_name();              /* display file name */

          #if PLAYER_PLAY_START == START_STOP
		  //------------------------------------------------------------------<<<<<<<<
          song_state = SONG_IDLE;
          //------------------------------------------------------------------<<<<<<<<
          #else
          //------------------------------------------------------------------<<<<<<<<
          if (File_type() == FILE_DIR)
          { /* file_type is dir */
          #if PLAYER_PLAY_MODE == PLAY_DISK
            song_state = SONG_NEW;      /* enter dir and play */
          #else
            song_state = SONG_NEXT;     /* stay in root dir */
          #endif
          }
          else
          { /* file_type is MP3 */
            song_state = SONG_INIT;
          }
          //------------------------------------------------------------------<<<<<<<<
          #endif
       }
       else
       { /* root is empty of song & diretory */
          song_state = SONG_NO_SONG;
       }

      break;
    }


    case SONG_IDLE:                         /* no file openned */
    { 
      if (gl_key_press)                     /* a key is pressed? */
      {
        switch (gl_key)
        {
          case KEY_PLAY:
            if (File_type() == FILE_DIR)
            {
              file_entry_dir(FILE_MP3 | FILE_DIR);  /* goto sub-directory */ 
              print_file_name();            /* display directory name */
            }
            else
            { /* file_type is MP3 */
              song_state = SONG_INIT;
            }
            break;

          case KEY_NEXT:
            file_seek_next(FILE_MP3 | FILE_DIR, TRUE);  /* select next song with loop */
            print_file_name();              /* display file name */
            break;

          case KEY_PREV:
            file_seek_prev(FILE_MP3 | FILE_DIR, TRUE);  /* select previous song */
            print_file_name();              /* display file name */
            break;

          case KEY_INC:
            song_snd_inc();                 /* increment selected control */
            print_sound_level();            /* display new level */
            break;

          case KEY_DEC:
            song_snd_dec();                 /* decrement selected control */
            print_sound_level();            /* display new level */
            break;

         // case KEY_SOUND:
         //   song_snd_select();              /* select next sound control */
         //   print_sound();                  /* display selected sound icon */
         //   print_sound_level();            /* display new level */
         //   break;

          case KEY_PARENT:
            File_goto_parent(FILE_MP3 | FILE_DIR); /* goto parent directory */ 
            print_file_name();              /* display first file name */
            break;

          default:
            break;
        }
        gl_key_press = FALSE;               /* ack key usage */
      }
      break;
    }


    case SONG_INIT:
    { 	  
      disp_clock_reset();                  /* reset clock timer */
      if (Fopen(READ) == OK)
      {
         if (song_init() != SONG_NO_ERR)     /* init song playing */
         {
           song_stop();                      /* stop playing song */
           Fclose();
           loop = song_loop;
           song_state = SONG_NEXT;
         }
         else
         {  
           song_audio_init();                /* init audio interface */
          // clock_song_init();  
           song_state = SONG_PLL;
         }
      }
      else
      {
        song_state = SONG_ERROR;
      }
      break;
    }


    case SONG_PLL:
    { 
      if (Pll_get_lock())                   /* pll locked? */
      {
        song_start();                       /* start playing song */
        disp_clock_start();                 /* start clock timer */
        print_state_play();                 /* display play icon */
        song_state = SONG_PLAY;
      }
      break;
    }

    case SONG_PLAY:
    {   
      if(led_flush)
	  {
	     LED_RED = 1;
		 LED_GREEN = ~LED_GREEN;
         led_flush = 0;
	  }

      if (Feof() == TRUE)
      { 
        song_stop();                        /* stop playing song */
        Fclose();
        loop = song_loop;
        song_state = SONG_NEXT;
        gl_key_press = FALSE;             /* no key usage */
      }

      if (gl_key_press)                     /* a key is pressed? */	  	  	  	  	  	  	  	  	  	  	  	  
      {
	    gl_key_press = FALSE;
        switch (gl_key)
        {
          case KEY_PLAY:
            Aud_song_pause();               /* suspend sample request */
            disp_clock_stop();              /* suspend clock timer */
            print_state_pause();            /* display pause icon */
            song_state = SONG_PAUSE;
            break;

          case KEY_NEXT:
            song_pause();                   /* pause playing song */
            disp_clock_stop();              /* suspend clock timer */
            Fclose();
            loop = TRUE;                    /* keypad action so loop */
            song_state = SONG_NEXT;
            break;

          case KEY_PREV:
            song_pause();                   /* pause playing song */
            disp_clock_stop();              /* suspend clock timer */
            Fclose();
            loop = TRUE;
            song_state = SONG_PREV;
            break;

          case KEY_INC:
            song_snd_inc();                 /* increment selected control */
            print_sound_level();            /* display new level */
            break;

          case KEY_DEC:
            song_snd_dec();                 /* decrement selected control */
            print_sound_level();            /* display new level */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -