文件操作与WAV音频播放实验程序解析.docx

上传人:b****6 文档编号:15390460 上传时间:2023-07-04 格式:DOCX 页数:46 大小:26.42KB
下载 相关 举报
文件操作与WAV音频播放实验程序解析.docx_第1页
第1页 / 共46页
文件操作与WAV音频播放实验程序解析.docx_第2页
第2页 / 共46页
文件操作与WAV音频播放实验程序解析.docx_第3页
第3页 / 共46页
文件操作与WAV音频播放实验程序解析.docx_第4页
第4页 / 共46页
文件操作与WAV音频播放实验程序解析.docx_第5页
第5页 / 共46页
文件操作与WAV音频播放实验程序解析.docx_第6页
第6页 / 共46页
文件操作与WAV音频播放实验程序解析.docx_第7页
第7页 / 共46页
文件操作与WAV音频播放实验程序解析.docx_第8页
第8页 / 共46页
文件操作与WAV音频播放实验程序解析.docx_第9页
第9页 / 共46页
文件操作与WAV音频播放实验程序解析.docx_第10页
第10页 / 共46页
文件操作与WAV音频播放实验程序解析.docx_第11页
第11页 / 共46页
文件操作与WAV音频播放实验程序解析.docx_第12页
第12页 / 共46页
文件操作与WAV音频播放实验程序解析.docx_第13页
第13页 / 共46页
文件操作与WAV音频播放实验程序解析.docx_第14页
第14页 / 共46页
文件操作与WAV音频播放实验程序解析.docx_第15页
第15页 / 共46页
文件操作与WAV音频播放实验程序解析.docx_第16页
第16页 / 共46页
文件操作与WAV音频播放实验程序解析.docx_第17页
第17页 / 共46页
文件操作与WAV音频播放实验程序解析.docx_第18页
第18页 / 共46页
文件操作与WAV音频播放实验程序解析.docx_第19页
第19页 / 共46页
文件操作与WAV音频播放实验程序解析.docx_第20页
第20页 / 共46页
亲,该文档总共46页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

文件操作与WAV音频播放实验程序解析.docx

《文件操作与WAV音频播放实验程序解析.docx》由会员分享,可在线阅读,更多相关《文件操作与WAV音频播放实验程序解析.docx(46页珍藏版)》请在冰点文库上搜索。

文件操作与WAV音频播放实验程序解析.docx

文件操作与WAV音频播放实验程序解析

//文件操作与WAV音频播放实验程序解析

//头文件

#include

#include"inc/hw_memmap.h"

#include"inc/hw_types.h"

#include"driverlib/fpu.h"

#include"driverlib/gpio.h"

#include"driverlib/interrupt.h"

#include"driverlib/rom.h"

#include"driverlib/sysctl.h"

#include"driverlib/systick.h"

#include"driverlib/pin_map.h"

#include"driverlib/ssi.h"

#include"grlib/grlib.h"

#include"utils/cmdline.h"

#include"utils/uartstdio.h"

#include"fatfs/src/ff.h"

#include"fatfs/src/diskio.h"

#include"drivers/cfal96x64x16.h"

#include"drivers/buttons.h"

//*****************************************************************************

//Definesthesizeofthebuffersthatholdthepath,ortemporarydatafrom

//theSDcard.Therearetwobuffersallocatedofthissize.Thebuffersize

//mustbelargeenoughtoholdthelongestexpectedfullpathname,including

//thefilename,andatrailingnullcharacter.

//*****************************************************************************

#definePATH_BUF_SIZE80

//*****************************************************************************

//Definesthesizeofthebufferthatholdsthecommandline.

//*****************************************************************************

#defineCMD_BUF_SIZE64

//*****************************************************************************

//Thisbufferholdsthefullpathtothecurrentworkingdirectory.Initially

//itisroot("/").

//*****************************************************************************

staticcharg_cCwdBuf[PATH_BUF_SIZE]="/";

//*****************************************************************************

//Atemporarydatabufferusedwhenmanipulatingfilepaths,orreadingdata

//fromtheSDcard.

//*****************************************************************************

staticcharg_cTmpBuf[PATH_BUF_SIZE];

//*****************************************************************************

//Aflagtoindicatetheselectbuttonwaspressed.

//*****************************************************************************

staticvolatileunsignedcharbSelectPressed=0;

staticvolatileunsignedcharbUpPressed=0;

staticvolatileunsignedcharbDownPressed=0;

staticvolatileunsignedcharbLeftPressed=0;

staticvolatileunsignedcharbRightPressed=0;

//*****************************************************************************

//Thebufferthatholdsthecommandline.

//*****************************************************************************

staticcharg_cCmdBuf[CMD_BUF_SIZE];

//*****************************************************************************

//ThefollowingaredatastructuresusedbyFatFs.

//*****************************************************************************

staticFATFSg_sFatFs;

staticDIRg_sDirObject;

staticFILINFOg_sFileInfo;

staticFILg_sFileObject;

tRectanglesRect;

chartmp[100];

charcover[20]="";

//*****************************************************************************

//AstructurethatholdsamappingbetweenanFRESULTnumericalcode,anda

//stringrepresentation.FRESULTcodesarereturnedfromtheFatFsFATfile

//systemdriver.

//*****************************************************************************

typedefstruct

{

FRESULTfresult;

char*pcResultStr;

}

tFresultString;

//wav文件头数据类型

typedefstruct_tagMsWavPcmHeader44{

charChunkID[4];//"RIFF";The"RIFF"themainchunk;

unsignedlongChunkSize;//FileSize-8;Thesizefollowingthisdata

charFormat[4];//"WAVE";The"WAVE"formatconsistsoftwosubchunks:

"fmt"and"data"

charSubChunk1ID[4];//"fmt"

unsignedlongSubChunk1Size;//16forPCM.Thisisthesizeoftherestofthesubchunkwhichfollowsthisdata.

unsignedshortAudioFormat;//1forPCM.Linearquantization

unsignedshortNumChannels;//1->Mono,2->stereo,etc..

unsignedlongSampleRate;//8000,11025,16000,44100,48000,etc..

unsignedlongByteRate;//=SampleRate*NumChannels*BitsPerSample/8

unsignedshortBlockAlign;//=NumChannels*BitsPerSample/8

unsignedshortBitsPerSample;//8->8bits,16->16bits,etc..

charSubChunk2ID[4];//"data"

unsignedlongSubChun2Size;//=NumSamples*NumChannels*BitsPerSample/8.Thesizeofdata

}wav_pcm_header44;

 

//*****************************************************************************

//Amacrotomakeiteasytoaddresultcodestothetable.

//*****************************************************************************

#defineFRESULT_ENTRY(f){(f),(#f)}

//*****************************************************************************

//AtablethatholdsamappingbetweenthenumericalFRESULTcodeandit's

//nameasastring.Thisisusedforlookinguperrorcodesforprintingto

//theconsole.

//*****************************************************************************

tFresultStringg_sFresultStrings[]=

{

FRESULT_ENTRY(FR_OK),

FRESULT_ENTRY(FR_NOT_READY),

FRESULT_ENTRY(FR_NO_FILE),

FRESULT_ENTRY(FR_NO_PATH),

FRESULT_ENTRY(FR_INVALID_NAME),

FRESULT_ENTRY(FR_INVALID_DRIVE),

FRESULT_ENTRY(FR_DENIED),

FRESULT_ENTRY(FR_EXIST),

FRESULT_ENTRY(FR_RW_ERROR),

FRESULT_ENTRY(FR_WRITE_PROTECTED),

FRESULT_ENTRY(FR_NOT_ENABLED),

FRESULT_ENTRY(FR_NO_FILESYSTEM),

FRESULT_ENTRY(FR_INVALID_OBJECT),

FRESULT_ENTRY(FR_MKFS_ABORTED)

};

//*****************************************************************************

//Amacrothatholdsthenumberofresultcodes.

//*****************************************************************************

#defineNUM_FRESULT_CODES(sizeof(g_sFresultStrings)/sizeof(tFresultString))

//*****************************************************************************

//GraphicscontextusedtoshowtextontheCSTNdisplay.

//*****************************************************************************

tContextg_sContext;

//*****************************************************************************

//Thisfunctionreturnsastringrepresentationofanerrorcodethatwas

//returnedfromafunctioncalltoFatFs.Itcanbeusedforprintinghuman

//readableerrormessages.

//*****************************************************************************

constchar*

StringFromFresult(FRESULTfresult)

{

unsignedintuIdx;

//

//Enteralooptosearchtheerrorcodetableforamatchingerrorcode.

//

for(uIdx=0;uIdx

{

//

//Ifamatchisfound,thenreturnthestringnameoftheerrorcode.

//

if(g_sFresultStrings[uIdx].fresult==fresult)

{

return(g_sFresultStrings[uIdx].pcResultStr);

}

}

//

//Atthispointnomatchingcodewasfound,soreturnastringindicating

//anunknownerror.

//

return("UNKNOWNERRORCODE");

}

//*****************************************************************************

//ThisisthehandlerforthisSysTickinterrupt.FatFsrequiresatimertick

//every10msforinternaltimingpurposes.

//*****************************************************************************

void

SysTickHandler(void)

{

//

//CalltheFatFsticktimer.

//

unsignedcharucData,ucDelta;

disk_timerproc();

//Getbuttonsstatususingbuttondebouncerdriver

ucData=ButtonsPoll(&ucDelta,0);

//Seeiftheselectbuttonwasjustpressed.

if(BUTTON_PRESSED(SELECT_BUTTON,ucData,ucDelta))

{

bSelectPressed=1;

}

if(BUTTON_RELEASED(SELECT_BUTTON,ucData,ucDelta))

{

bSelectPressed=0;

}

if(BUTTON_PRESSED(UP_BUTTON,ucData,ucDelta))

{

bUpPressed=1;

}

if(BUTTON_RELEASED(UP_BUTTON,ucData,ucDelta))

{

bUpPressed=0;

}

if(BUTTON_PRESSED(DOWN_BUTTON,ucData,ucDelta))

{

bDownPressed=1;

}

if(BUTTON_RELEASED(DOWN_BUTTON,ucData,ucDelta))

{

bDownPressed=0;

}

if(BUTTON_PRESSED(LEFT_BUTTON,ucData,ucDelta))

{

bLeftPressed=1;

}

if(BUTTON_RELEASED(LEFT_BUTTON,ucData,ucDelta))

{

bLeftPressed=0;

}

if(BUTTON_PRESSED(RIGHT_BUTTON,ucData,ucDelta))

{

bRightPressed=1;

}

if(BUTTON_RELEASED(RIGHT_BUTTON,ucData,ucDelta))

{

bRightPressed=0;

}

}

//*****************************************************************************

//Thisfunctionimplementsthe"ls"command.Itopensthecurrentdirectory

//andenumeratesthroughthecontents,andprintsalineforeachitemit

//finds.Itshowsdetailssuchasfileattributes,timeanddate,andthe

//filesize,alongwiththename.Itshowsasummaryoffilesizesattheend

//alongwithfreespace.

//*****************************************************************************

int

Cmd_ls(intargc,char*argv[])

{

unsignedlongulTotalSize;

unsignedlongulFileCount;

unsignedlongulDirCount;

FRESULTfresult;

FATFS*pFatFs;

//Openthecurrentdirectoryforaccess.

fresult=f_opendir(&g_sDirObject,g_cCwdBuf);

//Checkforerrorandreturnifthereisaproblem.

if(fresult!

=FR_OK)

{

return(fresult);

}

ulTotalSize=0;

ulFileCount=0;

ulDirCount=0;

//Giveanextrablanklinebeforethelisting.

UARTprintf("\n");

//Enterlooptoenumeratethroughalldirectoryentries.

for(;;)

{

//Readanentryfromthedirectory.

fresult=f_readdir(&g_sDirObject,&g_sFileInfo);

 

//Checkforerrorandreturnifthereisaproblem.

if(fresult!

=FR_OK)

{

return(fresult);

}

//Ifthefilenameisblank,thenthisistheendofthelisting.

if(!

g_sFileInfo.fname[0])

{

break;

}

//Iftheattribueisdirectory,thenincrementthedirectorycount.

if(g_sFileInfo.fattrib&AM_DIR)

{

ulDirCount++;

}

//Otherwise,itisafile.Incrementthefilecount,andaddinthe

//filesizetothetotal.

else

{

ulFileCount++;

ulTotalSize+=g_sFileInfo.fsize;

}

//Printtheentryinformationonasinglelinewithformatting

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > IT计算机 > 电脑基础知识

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2