📄 voice_task.c
字号:
default:
break;
}
gl_key_press = FALSE; /* ack key usage */
}
break;
}
case VOICE_PLAY_PAUSE: /* one file openned */
{
if (gl_key_press) /* a key is pressed? */
{
switch (gl_key)
{
case KEY_PLAY:
disp_clock_start(); /* restart clock timer */
voc_play_start(); /* restart sample request */
print_state_play(); /* display play icon */
voice_state = VOICE_PLAY;
break;
case KEY_NEXT:
voc_play_stop();
Fclose();
file_seek_next(FILE_WAV, TRUE); /* select next message with loop */
print_file_name(); /* display file name */
voice_state = VOICE_IDLE;
break;
case KEY_PREV:
voc_play_stop();
Fclose();
file_seek_prev(FILE_WAV, TRUE); /* select previous message */
print_file_name(); /* display file name */
voice_state = VOICE_IDLE;
break;
case KEY_INC:
voc_inc_volume(); /* increment volume */
print_voice_vol(Voc_get_volume()); /* display new level */
break;
case KEY_DEC:
voc_dec_volume(); /* decrement volume */
print_voice_vol(Voc_get_volume()); /* display new level */
break;
case KEY_STOP:
voc_play_stop(); /* stop playing */
Fclose();
voice_state = VOICE_PLAY_STOP;
break;
default:
break;
}
gl_key_press = FALSE; /* ack key usage */
}
break;
}
case VOICE_PLAY_NEW:
{
voice_state = VOICE_PLAY_INIT; /* new message */
print_file_name(); /* display file name */
break;
}
case VOICE_PLAY_STOP:
{
disp_clock_reset(); /* reset clock timer */
print_file_type(); /* display wav icon */
disp_end_of_play();
voice_state = VOICE_IDLE;
break;
}
case VOICE_NO_MSG:
{
if (gl_key_press) /* a key is pressed? */
{
switch (gl_key)
{
case KEY_MEM:
mem_select_next(); /* select next memory */
voice_state = VOICE_START;
break;
case KEY_PLAY:
print_state_play();
voice_state = VOICE_PLAY_STOP;
break;
case KEY_REC:
voice_state = VOICE_REC_INIT;
break;
case KEY_MODE:
mode_set_init(); /* exit from voice task */
voice_state = VOICE_START;
break;
}
gl_key_press = FALSE; /* ack key usage */
}
else
{ /* check card presence */
if (mem_check_card() == KO)
{
mem_select_next();
voice_state = VOICE_START; /* card has been unplugged */
}
}
break;
}
case VOICE_REC_INIT:
{
disp_clock_reset(); /* reset clock timer */
for (i = 255; i != 0; i--)
{
voice_buffer[i] = 0x00;
}
voice_buffer[0] = 0x00;
if (File_entry_root(FILE_WAV) == OK) /* WAV file in root dir? */
{
do
{
(char *)file_name = File_get_name(); /* Get file name */
if ((file_name[0] == 'V') &&
(file_name[1] == 'O') &&
(file_name[2] == 'I') &&
(file_name[3] == 'C') &&
(file_name[4] == 'E') &&
((file_name[5] >= '0') && (file_name[5] <= '9')) &&
((file_name[6] >= '0') && (file_name[6] <= '9')) &&
((file_name[7] >= '0') && (file_name[7] <= '9'))
)
{
/* Calculate actual index */
i = (Byte)(file_name[5] - '0') * 100;
i += (Byte)(file_name[6] - '0') * 10;
i += (Byte)(file_name[7] - '0') * 1;
voice_buffer[i] = 0xFF;
}
}
while (File_goto_next() == OK); /* Do it still we have not reached the last file */
}
else
{
file_name = buff;
}
i = 0;
if (voice_buffer[i] != 0x00)
{
i++;
while ((voice_buffer[i] != 0x00) && (i != 0)) i++; /* determine a free index */
}
if (voice_buffer[i] == 0) /* Find a free indice ? */
{
file_name[0] = 'V';
file_name[1] = 'O';
file_name[2] = 'I';
file_name[3] = 'C';
file_name[4] = 'E';
file_name[5] = '0' + (i / 100);
file_name[6] = '0' + ((i % 100) / 10);
file_name[7] = '0' + (((i % 100) % 10));
file_name[8] = 'W';
file_name[9] = 'A';
file_name[10] = 'V';
if (Fcreate(file_name, ATTR_FILE) != OK) /* Create file */
{
voice_state = VOICE_ERROR;
}
else
{
print_file_name(); /* display new file name */
voc_cpt = 0;
print_state_record(); /* display record icon */
voc_rec_init();
disp_clock_start(); /* start clock timer */
voice_state = VOICE_RECORD;
}
}
else
{
voice_state = VOICE_ERROR;
}
break;
}
case VOICE_RECORD:
{
while ((Byte)voc_cpt != gl_pointer)
{
Fputc(voice_buffer[(Byte)voc_cpt]);
if (Feod()) /* check end of disk */
{
Voc_rec_stop(); /* stop voice sampling */
voice_state = VOICE_REC_STOP;
break; /* exit while loop */
}
voc_cpt++;
}
if (gl_key_press) /* a key is pressed? */
{
switch (gl_key)
{
case KEY_PAUSE:
disp_clock_stop(); /* suspend clock timer */
Voc_rec_pause();
print_state_pause(); /* display pause icon */
voice_state = VOICE_REC_PAUSE;
break;
case KEY_STOP:
Voc_rec_stop(); /* stop voice sampling */
voice_state = VOICE_REC_STOP;
break;
default:
break;
}
gl_key_press = FALSE; /* ack key usage */
}
break;
}
case VOICE_REC_PAUSE:
{
if (gl_key_press) /* a key is pressed? */
{
switch (gl_key)
{
case KEY_REC:
disp_clock_start(); /* restart clock timer */
print_state_record(); /* display record icon */
Voc_rec_start(); /* restart sampling */
voice_state = VOICE_RECORD;
break;
case KEY_STOP:
Voc_rec_stop(); /* stop voice sampling */
voice_state = VOICE_REC_STOP;
break;
default:
break;
}
gl_key_press = FALSE; /* ack key usage */
}
break;
}
case VOICE_REC_STOP:
{
/* update wave header */
Fseek(-voc_cpt); /* beginning of file */
Fputc(((Byte*)&gl_wav_header)[0]); /* 'R' */
Fputc(((Byte*)&gl_wav_header)[1]); /* 'I' */
Fputc(((Byte*)&gl_wav_header)[2]); /* 'F' */
Fputc(((Byte*)&gl_wav_header)[3]); /* 'F' */
voc_cpt -= 8;
Fputc(((Byte*)&voc_cpt)[3]); /* wave length */
Fputc(((Byte*)&voc_cpt)[2]);
Fputc(((Byte*)&voc_cpt)[1]);
Fputc(((Byte*)&voc_cpt)[0]);
for (i = 8; i != WAV_HEADER_SIZE-4; i++)
{
Fputc(((Byte code *)&gl_wav_header)[i]);
}
voc_cpt -= 36;
Fputc(((Byte*)&voc_cpt)[3]); /* data length */
Fputc(((Byte*)&voc_cpt)[2]);
Fputc(((Byte*)&voc_cpt)[1]);
Fputc(((Byte*)&voc_cpt)[0]);
for (i = 255; i != 0; i--)
{
Fputc(0x80); /* fill first sector data */
}
for (i = 257 - WAV_HEADER_SIZE; i != 0; i--)
{
Fputc(0x80); /* fill first sector data */
}
Fclose();
disp_end_of_play();
disp_clock_reset(); /* reset clock timer */
print_file_type(); /* display wav icon */
voice_state = VOICE_IDLE;
break;
}
case VOICE_ERROR:
{
disp_clock_reset(); /* reset clock timer */
print_state_error(); /* display error icon */
disp_name_stop();
voice_state = VOICE_IDLE;
break;
}
case VOICE_DELETE:
{
i = Fdelete();
if ((i == DEL_RET_OK) || (i == DEL_RET_ERROR_DIR))
{ /* at least 1 *.wav file in root */
Frefresh(FILE_WAV);
print_file_name(); /* display file name */
voice_state = VOICE_IDLE;
}
else
{ /* no more *.wav file */
print_state_blank(); /* select blank icon */
print_screen(VOICE_SCREEN); /* display voice screen */
print_voice_vol(Voc_get_volume()); /* display volume level */
voice_state = VOICE_NO_MSG;
}
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -