📄 song_task.c
字号:
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: /* one file openned */
{
if (Feof() == TRUE) /* end of file? */
{
song_stop(); /* stop playing song */
Fclose();
if (file_seek_next(FILE_MP3, song_loop)) /* select next song */
{
song_state = SONG_NEW;
gl_key_press = FALSE; /* no key usage */
}
else
{
song_state = SONG_STOP;
}
}
if (gl_key_press) /* a key is pressed? */
{
switch (gl_key)
{
case KEY_REPEAT_A_B:
if (!repeat_A_B)
{ /* A position */
repeat_A_B = TRUE; /* Detect repeat A/B mode */
file_pos_A = Fget_pos(); /* Get the first position */
if (file_pos_A > (song_frame_size * SONG_PRE_SAMPLING))
file_pos_A -= (song_frame_size * SONG_PRE_SAMPLING);
else
file_pos_A = 0x00;
disp_save_time();
print_repeat(SYMB_REP_A);
}
else
{
mp3_stop(); /* B position */
Fsave_cluster_info(); /* Save cluster info for B position detect */
song_state = SONG_PLAY_A_B_MUTE;
count = gl_cpt_tick;
Fseek(file_pos_A);
disp_recall_time();
Song_save_volume_level(Mp3_get_right_vol());
print_repeat(SYMB_REP_B);
mp3_restart();
}
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:
print_repeat(song_loop);
repeat_A_B = FALSE; /* cancel repeat A/B */
song_state = SONG_DETECT_REPEAT_KEY_NEXT;
break;
case KEY_PREV:
print_repeat(song_loop);
repeat_A_B = FALSE; /* cancel repeat A/B */
song_state = SONG_DETECT_REPEAT_KEY_PREV; /* Key repeat? */
break;
case KEY_INC:
case KEY_INC_LREP:
song_snd_inc(); /* increment selected control */
print_sound_level(); /* display new level */
break;
case KEY_DEC:
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();
if (repeat_A_B)
{
print_repeat(song_loop);
}
song_state = SONG_STOP;
break;
case KEY_LOCK:
print_kbd_lock(); /* print keyboard status */
break;
default:
break;
}
gl_key_press = FALSE; /* ack key usage */
}
break;
}
case SONG_DETECT_REPEAT_KEY_NEXT:
{ /* KEY_NEXT is pressed */
if (Feof() == TRUE) /* end of file? */
{
Fclose();
if (file_seek_next(FILE_MP3, song_loop)) /* select next song */
{
song_pause(); /* pause playing song */
song_state = SONG_NEW;
gl_key_press = FALSE; /* no key usage */
}
else
{
song_stop(); /* stop playing song */
song_state = SONG_STOP;
}
}
if ((MP3STA & (MSK_ERRLAY | MSK_ERRSYN)) != 0)
{
break;
}
if (gl_key_repeat == TRUE)
{
if (gl_key == KEY_FF)
{
if (Fseek((Int32)(song_frame_size) * SONG_SKEEP_FRAME_FFW) == OK) /* Fast Forward Skeep */
{
disp_inc_time(SONG_REPEAT_TIME_FFW);
do
{
status = song_init();
}
while ((status != SONG_NO_ERR) && (status != SONG_SYNC_ERR));
if (status != SONG_NO_ERR)
{
song_state = SONG_PLAY_NEXT_FILE;
}
else
{
mp3_restart(); /* Re-start MP3 */
Aud_song_play(); /* start sample request */
Song_save_volume_level(Mp3_get_right_vol()); /* Save volume level */
song_state = SONG_DETECT_REPEAT_KEY_END;
}
count = gl_cpt_tick;
}
else
{ /* End of file */
song_state = SONG_PLAY_NEXT_FILE;
}
}
}
else
{
song_state = SONG_PLAY_NEXT_FILE;
}
gl_key_press = FALSE;
break;
}
case SONG_DETECT_REPEAT_KEY_PREV:
{ /* KEY_PREV is pressed */
if (Feof() == TRUE) /* end of file? */
{
Fclose();
if (file_seek_next(FILE_MP3, song_loop)) /* select next song */
{
song_pause(); /* pause playing song */
song_state = SONG_NEW;
gl_key_press = FALSE; /* no key usage */
}
else
{
song_stop(); /* stop playing song */
song_state = SONG_STOP;
}
}
if ((MP3STA & (MSK_ERRLAY | MSK_ERRSYN)) != 0)
{
break;
}
if (gl_key_repeat == TRUE)
{
if (gl_key == KEY_FR)
{
if (Fseek(-(Int32)(song_frame_size) * SONG_SKEEP_FRAME_FRW) == OK) /* 1s Fast Rewind */
{
disp_dec_time(SONG_REPEAT_TIME_FRW);
Song_save_volume_level(Mp3_get_right_vol()); /* Save volume level */
song_state = SONG_DETECT_REPEAT_KEY_END;
}
do
{
status = song_init();
}
while ((status != SONG_NO_ERR) && (status != SONG_SYNC_ERR));
if (status != SONG_NO_ERR)
{
song_state = SONG_PLAY_NEXT_FILE;
}
else
{
mp3_restart(); /* Re-start MP3 */
Aud_song_play(); /* start sample request */
}
count = gl_cpt_tick;
}
}
else
{ /* select previous song */
song_pause(); /* pause playing song */
disp_clock_stop(); /* suspend clock timer */
Fclose();
file_seek_prev(FILE_MP3); /* select previous song */
song_state = SONG_NEW;
}
gl_key_press = FALSE;
break;
}
case SONG_DETECT_REPEAT_KEY_END:
{
Mp3_set_right_vol(VOLUME_MIN);
Mp3_set_left_vol(VOLUME_MIN);
if (gl_cpt_tick >= count)
delta_t = gl_cpt_tick - count;
else
delta_t = DISP_TICK_SEC - count + gl_cpt_tick;
if (Feof() == TRUE) /* end of file? */
{
Mp3_set_right_vol(Song_get_saved_volume_level());
Mp3_set_left_vol(Song_get_saved_volume_level());
Fclose();
if (file_seek_next(FILE_MP3, song_loop)) /* select next song */
{
song_pause(); /* pause playing song */
song_state = SONG_IDLE;
gl_key_press = FALSE; /* no key usage */
}
else
{
song_stop(); /* stop playing song */
song_state = SONG_STOP;
}
}
if (delta_t > SONG_MUTE_DURATION) /* Maestro */
{
count = gl_cpt_tick;
song_state = SONG_PLAY_REPEAT_KEY;
}
if ((MP3STA & (MSK_ERRLAY | MSK_ERRSYN)) != 0)
{
count = gl_cpt_tick;
}
break;
}
case SONG_PLAY_REPEAT_KEY:
{
if (gl_cpt_tick >= count)
delta_t = gl_cpt_tick - count;
else
delta_t = DISP_TICK_SEC - count + gl_cpt_tick;
if (Feof() == TRUE) /* end of file? */
{
Fclose();
Mp3_set_right_vol(Song_get_saved_volume_level());
Mp3_set_left_vol(Song_get_saved_volume_level());
if (file_seek_next(FILE_MP3, song_loop)) /* select next song */
{
song_state = SONG_NEW;
gl_key_press = FALSE; /* no key usage */
}
else
{
song_state = SONG_STOP;
}
}
if ((Mp3_get_right_vol() < (Song_get_saved_volume_level() / 2)) && (delta_t > SONG_START_TIME_VOL))
{
if (delta_t % 20)
{
Mp3_set_right_vol(Mp3_get_right_vol() + 1);
Mp3_set_left_vol(Mp3_get_left_vol() + 1);
}
}
if (delta_t > SONG_UNMUTE_PLAY_DURATION)
{
if (gl_key_repeat == TRUE)
{ /* Still key repeat : Fast Forward and Fast Rewind Only */
if (gl_key_press)
{
switch (gl_key)
{
case KEY_FF:
case KEY_LFF:
if (Fseek((Int32)(song_frame_size) * SONG_SKEEP_FRAME_FFW) == OK) /* Fast Forward */
{
do
{
status = song_init();
}
while ((status != SONG_NO_ERR) && (status != SONG_SYNC_ERR));
if (status != SONG_NO_ERR)
{
song_state = SONG_PLAY_NEXT_FILE;
}
else
{
count = gl_cpt_tick;
disp_inc_time(SONG_REPEAT_TIME_FFW); /* Increase display time */
song_state = SONG_DETECT_REPEAT_KEY_END; /* Valid the repeat key in mute mode */
mp3_restart(); /* Re-start MP3 */
Aud_song_play(); /* start sample request */
}
}
else
{
song_state = SONG_PLAY_NEXT_FILE; /* end of file -> next file */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -