song_task.c

来自「MP3设计源代码 使用atmel的单片机」· C语言 代码 · 共 1,081 行 · 第 1/3 页

C
1,081
字号
                    song_state = SONG_DETECT_REPEAT_KEY_END;
                  }
                }
                else
                { /* beg of file: replay same file */
                  Aud_song_play();
                  Mp3_set_right_vol(Song_get_saved_volume_level());
                  Mp3_set_left_vol(Song_get_saved_volume_level());
                  song_state = SONG_PLAY;
                }
                gl_key_press = FALSE;
                break;
            }
          }
        }
        else
        { /* Key changed or end of repeat key */
          Aud_song_play();
          Mp3_set_right_vol(Song_get_saved_volume_level());
          Mp3_set_left_vol(Song_get_saved_volume_level());
          song_state = SONG_PLAY;           /* Go in state SONG PLAY */
        }
      }
      break;
    }


    case SONG_PLAY_A_B_MUTE:                /* one file openned in mode repeat A/B with no sound */
    {
      if (Feob() == TRUE)                   /* Reach B position? */
      {
        mp3_stop();                         /* Stop MP3 */
        Fseek_abs(file_pos_A);        
        mp3_restart();                      /* Re-start MP3 */
      }

      if (gl_cpt_tick >= count)
        delta_t = gl_cpt_tick - count;
      else
        delta_t = DISP_TICK_SEC - count + gl_cpt_tick;  

      if (delta_t > SONG_A_B_MUTE_NB)       /* Nb mute transfert reach? */
      {
        Mp3_set_right_vol(Song_get_saved_volume_level());
        Mp3_set_left_vol(Song_get_saved_volume_level());
        song_state = SONG_PLAY_A_B;         /* Start the state SONG_PLAY_A_B */
      }
      break;
    }


    case SONG_PLAY_A_B:                     /* one file openned in mode repeat A/B */
    {
      if (Feob() == TRUE)                   /* Reach B position */
      {
        mp3_stop();                         /* Stop MP3 */
        Fseek_abs(file_pos_A);              /* Reverse seek */
        song_state = SONG_PLAY_A_B_MUTE;    /* Next state : kill the DAC in mute mode */
        mp3_restart();                      /* Restart MP3 */
        disp_recall_time();                 /* Refresh time */
        count = gl_cpt_tick;
        Song_save_volume_level(Mp3_get_right_vol());/* Save volume level */
        Mp3_set_right_vol(VOLUME_MIN);
        Mp3_set_left_vol(VOLUME_MIN);
      }
      else 
      if (gl_key_press)                     /* a key is pressed? */
      {
        switch (gl_key)
        {
          case KEY_REPEAT_A_B:
            repeat_A_B = FALSE;             /* disable repeat A/B mode */
            song_state = SONG_PLAY;
            print_repeat(song_loop);
            break;

          case KEY_PAUSE:
            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;
            song_state = SONG_NEXT;
            break;

          case KEY_PREV:
            song_pause();                   /* pause playing song */
            disp_clock_stop();              /* suspend clock timer */
            Fclose();
            file_seek_prev(FILE_TYPE);      /* select previous song */
            song_state = SONG_NEW;
            break;

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

          case KEY_DEC:
          case KEY_DEC_REP:
          case KEY_DEC_LREP:
            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_REPEAT:
            song_loop = ~song_loop;         /* display repeat or not */
            print_repeat(song_loop);
            break;

          case KEY_STOP:
            song_stop();                    /* stop playing song */
            Fclose();
            song_state = SONG_STOP;
            break;

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


    case SONG_PAUSE:                        /* one file openned */
    {
      if (gl_key_press)                     /* a key is pressed? */
      {
        switch (gl_key)
        {
          case KEY_PLAY:
            disp_clock_start();             /* restart clock timer */
            Aud_song_play();                /* restart sample request */
            print_state_play();             /* display play icon */
            song_state = SONG_PLAY;
            break;

          case KEY_NEXT:
            song_pause();                   /* pause playing song */
            Fclose();
            loop = TRUE;                    /* keypad action so loop */
            print_repeat(song_loop);
            song_state = SONG_NEXT;
            break;

          case KEY_PREV:
            song_pause();                   /* pause playing song */
            Fclose();
            file_seek_prev(FILE_TYPE);      /* select previous song */
            print_repeat(song_loop);
            song_state = SONG_NEW;
            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_REPEAT:
            song_loop = ~song_loop;         /* display repeat or not */
            print_repeat(song_loop);
            break;

          case KEY_STOP:
            song_stop();                    /* stop playing song */
            Fclose();
            song_state = SONG_STOP;
            break;

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


    case SONG_NEW:
    {
    #if PLAYER_PLAY_MODE == PLAY_DISK
      if (File_type() == FILE_DIR)
      {
        if (file_entry_dir(FILE_MP3 | FILE_DIR) == OK)
        { /* mp3 or dir in sub-dir */
          song_state = SONG_NEW;            /* stay in same state */
        }
        else
        { /* no mp3 or dir in sub-dir */
          song_state = SONG_NEXT;           /* select next */
        }
      }
      else
      { /* file is MP3 */
        song_state = SONG_INIT;             /* new song */
        print_repeat(song_loop);
        print_file_name();                  /* display file name */
      }
      break;
    #else /* PLAYER_MODE == PLAY_DIR */
      song_state = SONG_INIT;               /* new song */
      print_repeat(song_loop);
      print_file_name();                    /* display file name */
      break;
    #endif
    }

    case SONG_NEXT:
    {
      disp_name_stop();                     /* stop scrolling */
    #if PLAYER_PLAY_MODE == PLAY_DISK
      if (file_seek_next(FILE_MP3 | FILE_DIR, FALSE))/* next song or dir */
      { /* mp3 or dir selected */
        song_state = SONG_NEW;
      }
      else
      { /* at end of dir */
        if (File_goto_parent(FILE_MP3 | FILE_DIR) == OK)
        { /* parent exists, point on dir */
          song_state = SONG_NEXT;           /* next will select next file */
        }
        else
        { /* no parent: end of root dir */
          if (loop)
          {
            song_state = SONG_NEW;
          }
          else
          {
            song_stop();
            song_state = SONG_STOP;
          }
        }
      }
      break;
    #else /* PLAYER_MODE == PLAY_DIR */
      if (file_seek_next(FILE_MP3, loop))   /* select next song */
      { /* still some file to play */
        song_state = SONG_NEW;
      }
      else
      { /* end of dir: stop */
        song_stop();
        song_state = SONG_STOP;
      }
      break;
    #endif
    }


    case SONG_STOP:
    {
      disp_clock_reset();                   /* reset clock timer */
      print_repeat(song_loop);
      print_file_name();                    /* display file name */
      song_state = SONG_IDLE;
      break;
    }


    case SONG_NO_SONG:
    {
      if (gl_key_press)                     /* a key is pressed? */
      {
        switch (gl_key)
        {
          case KEY_MEM:
            mem_select_next();              /* select next memory */
            song_state = SONG_START;
            break;

          case KEY_MODE:
            mode_set_init();                /* exit from song task */
            song_state = SONG_START;
            break;
        }
        gl_key_press = FALSE;               /* ack key usage */
      }
      else
      { /* check card presence */
        if (mem_check_card() == KO)
        {
          mem_select_next();
          song_state = SONG_START;          /* card has been unplugged */
        }
      }
      break;
    }

    case SONG_DELETE:
    {
      status = Fdelete();
      disp_clock_reset();                   /* reset clock timer */
      if ((status == DEL_RET_OK) || (status == DEL_RET_ERROR_DIR))
      {
        if (status == DEL_RET_OK)
          Frefresh (FILE_MP3 | FILE_DIR);
        print_file_name();                  /* display file name */
        song_state = SONG_IDLE;
      }
      else
      { /* dir is empty of song & diretory */
        if (File_goto_parent(FILE_MP3 | FILE_DIR) == OK) /* goto parent directory */
        { /* point on sub-dir name */
          print_file_name();                /* display first file name */
          song_state = SONG_IDLE;
        }
        else
        { /* dir is root */
          print_state_blank();              /* select blank icon */
          print_screen(SONG_SCREEN);        /* display voice screen */
          print_sound_level();              /* display volume level */
          song_state = SONG_NO_SONG;
          disp_name_stop();
        }
      }
      break;
    }

    case SONG_ERROR:
    {
      song_stop();                          /* stop playing song */
      Fclose();                             /* close opened file */
      disp_clock_reset();                   /* reset clock timer */
      print_state_error();                  /* display error icon */
      disp_name_stop();
      song_state = SONG_IDLE;
      break;
    }
  }
}

⌨️ 快捷键说明

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