|
楼主 |
发表于 2017-12-26 14:20:34
|
显示全部楼层
- u8 recoder_play(void)
- {
- u8 res;
- u8 key;
- u8 rval=0;
- __WaveHeader *wavhead=0;
- u32 sectorsize=0;
- // u8 sectorsize=0;
- FIL* f_rec=0; //Îļt
- DIR recdir; //Ŀ¼
- u8 *recbuf; //êy¾YÄú′æ
- u16 w;
- u16 idx=0;
- u8 rec_sta=0; //¼òô×′ì¬
- //[7]:0,ûóD¼òô;1,óD¼òô;
- //[6:1]:񜠓
- //[0]:0,ÕyÔú¼òô;1,ÔYí£¼òô;
- u8 *pname=0;
-
- u32 recsec=0; //¼òôê±¼ä
- u8 playFlag=0; //2¥·Å±êÖ¾
-
- while(f_opendir(&recdir,"1:/RECORDER"))//′ò¿a¼òôÎļt¼D
- {
- Show_Str(60,230,240,16,"RECORDERÎļt¼D′íÎó!",16,0);
- delay_ms(20);
- LCD_Fill(60,230,240,246,WHITE); //Çå3yÏÔê¾
- delay_ms(20);
- f_mkdir("1:/RECORDER"); //′′½¨¸ÃĿ¼
- }
-
- f_rec=(FIL *)mymalloc(sizeof(FIL)); //¿a±ùFIL×Ö½úμÄÄú′æÇøóò
- if(f_rec==NULL)rval=1; //éêÇë꧰ü
- wavhead=(__WaveHeader*)mymalloc(sizeof(__WaveHeader));//¿a±ù__WaveHeader×Ö½úμÄÄú′æÇøóò
- if(wavhead==NULL)rval=1;
- recbuf=mymalloc(512);
- if(recbuf==NULL)rval=1;
- pname=mymalloc(30); //éêÇë30¸ö×Ö½úÄú′æ,ààËÆ"0:RECORDER/REC00001.wav"
- if(pname==NULL)rval=1;
- if(rval==0) //Äú′æéêÇëOK
- {
- recoder_enter_rec_mode(1024*recagc);
- while(VS_RD_Reg(SPI_HDAT1)>>8); //μèμ½buf ½ÏÎa¿ÕÏDÔù¿aê¼
- // recoder_show_time(recsec); //ÏÔê¾ê±¼ä
- // recoder_show_agc(recagc); //ÏÔê¾agc
- pname[0]=0; //pnameûóDèÎoÎÎļtÃû
-
- rec_sta|=0X80; //¿aê¼Â¼òô //½øμ½Â¼òô½çÃæ¿aê¼Â¼òô£¬μã»÷è·èÏ°′¼ü±£′æ¼òô2¢·μ»ØéÏò»¸ö½çÃ棬¿éòÔμ÷½úéùòô′óD¡£¬ÂË2¨Ä£ê½
- recoder_new_pathname(pname); //μÃμ½DÂμÄÃû×Ö
- // Show_Str(60,230,240,16,pname+11,16,0); //ÏÔê¾μ±Ç°Â¼òôÎļtÃû×Ö
- recoder_wav_init(wavhead); //3õê¼»ˉwavêy¾Y
- res=f_open(f_rec,(const TCHAR*)pname, FA_CREATE_ALWAYS | FA_WRITE);
- printf("read open res:%d\r\n",res);
- if(res) //Îļt′′½¨ê§°ü
- {
- rec_sta=0; //′′½¨Îļt꧰ü,2»Äü¼òô
- rval=0XFE; //ìáê¾êÇ·ñ′æÔúSD¿¨
- }else res=f_write(f_rec,(const void*)wavhead,sizeof(__WaveHeader),&bw);//D′èëí·êy¾Y
-
- while(1)
- {
-
-
- if(key==KEY0_PRES) //í£Ö1¼òô°′¼ü°′ÏÂ
- {
- if(rec_sta&0X80)//óD¼òô
- {
- wavhead->riff.ChunkSize=sectorsize*512+36; //Õû¸öÎļtμÄ′óD¡-8;
- wavhead->data.ChunkSize=sectorsize*512; //êy¾Y′óD¡
- f_lseek(f_rec,0); //Æ«òÆμ½Îļtí·.
- f_write(f_rec,(const void*)wavhead,sizeof(__WaveHeader),&bw);//D′èëí·êy¾Y
- res=f_close(f_rec);
- printf("read close res:%d\r\n",res);
- sectorsize=0;
- // res=f_closedir(&recdir);
- // printf("close dir :%d\r\n",res);
- }
- rec_sta=0;
- recsec=0;
- LED1=1; //1رÕDS1
- // LCD_Fill(60,230,240,246,WHITE); //Çå3yÏÔê¾,Çå3y֮ǰÏÔê¾μļòôÎļtÃû
- // recoder_show_time(recsec); //ÏÔê¾ê±¼ä
- break;
- }
-
- else if (4==filtermode_Scan(0)) //ÇD»»ÂË2¨Ä£ê½
- {
- turn_filtermode(); //ÇD»»Ä£ê½
- }
- else
- {
- key=KEY_Scan(0);
- // key=KEY1_PRES;
- switch(key)
- {
- //case WKUP_PRES: //STOP&SAVE
- case KEY1_PRES: //AGC+
- case KEY2_PRES: //AGC-
- if(key==KEY1_PRES)recagc++;
- else if(recagc)recagc--;
- if(recagc>15)recagc=15; //·¶Î§ÏT¶¨Îa0~15.0,×Ô¶ˉAGC.ÆäËûAGC±¶êy
- OLED_ShowNum(40,4,recagc,2,16);//6
- VS_WR_Cmd(SPI_AICTRL1,1024*recagc); //éèÖÃÔöòæ,0,×Ô¶ˉÔöòæ.1024Ïàμ±óú1±¶,512Ïàμ±óú0.5±¶
- break;
- }
- }
- ///////////////////////////////////////////////////////////
- //¶áè¡êy¾Y
- if(rec_sta==0X80)//òѾ-Ôú¼òôáË
- {
- w=VS_RD_Reg(SPI_HDAT1);
- if((w>=256)&&(w<896))
- {
- idx=0;
- while(idx<512) //ò»′ζáè¡512×Ö½ú
- {
- w=VS_RD_Reg(SPI_HDAT0);
- recbuf[idx++]=w&0XFF;
- recbuf[idx++]=w>>8;
- }
- res=f_write(f_rec,recbuf,512,&bw);//D′èëÎļt
- printf("write:%d\r\n",res);
- if(res)
- {
- printf("err:%d\r\n",res);
- printf("bw:%d\r\n",bw);
- break;//D′èë3ö′í.
- }
- sectorsize++;//éèÇøêyÔö¼ó1,Ô¼Îa32ms
- if(sectorsize==0x3e8) //ìí¼óèç1ûò½éúíü¼Ç1Øμôé豸£¬Ôú¼Ç¼32soóé豸½«×Ô¶ˉí£Ö1¼òô·μ»ØÖ÷½çÃæ
- {
- wavhead->riff.ChunkSize=sectorsize*512+36; //Õû¸öÎļtμÄ′óD¡-8;
- wavhead->data.ChunkSize=sectorsize*512; //êy¾Y′óD¡
- f_lseek(f_rec,0); //Æ«òÆμ½Îļtí·.
- f_write(f_rec,(const void*)wavhead,sizeof(__WaveHeader),&bw);//D′èëí·êy¾Y
- f_close(f_rec);
- sectorsize=0;
- rec_sta=0;
- break;
- }
-
- }
- }
- }
- }
-
- myfree(wavhead);
- myfree(recbuf);
- myfree(f_rec);
- myfree(pname);
- return rval;
- }
复制代码 |
|