|
发表于 2008-1-17 09:15:15
|
显示全部楼层
alien2006
你手上的那块PCB,ST原配的TFT本来是有一个演示程序的,播放的时候除了会有画面,还会有声音,声音也是WAV格式。
APE格式不了解,不是非常清楚是否M3够用
/*******************************************************************************
* Function Name : WavePlayer_WaveParsing
* Description : Checks the format of the .WAV file and gets information about
* the audio format. This is done by reading the value of a
* number of parameters stored in the file header and comparing
* these to the values expected authenticates the format of a
* standard .WAV file (44 bytes will be read). If it is a valid
* .WAV file format, it continues reading the header to determine
* the audio format such as the sample rate and the sampled data
* size. If the audio format is supported by this application,
* it retrieves the audio format in WAVE_Format structure and
* returns a zero value. Otherwise the function fails and the
* return value is nonzero.In this case, the return value specifies
* the cause of the function fails. The error codes that can be
* returned by this function are declared in the header file.
* Input : None
* Output : None
* Return : Zero value if the function succeed, otherwise it return
* a nonzero value which specifies the error code.
*******************************************************************************/
static ErrorCode WavePlayer_WaveParsing(u32 ReadAddress)
{
u32 index = 0;
u32 Temp = 0x00;
u32 ExtraFormatBytes = 0;
/* Start a read data byte sequence from the Flash starting from @ReadAddress */
SPI_FLASH_StartReadSequence(ReadAddress);
/* Read chunkID, must be 'RIFF' ----------------------------------------------*/
Temp = ReadUnit(4, BigEndian);
if(Temp != ChunkID)
{
return(Unvalid_RIFF_ID);
}
/* Read the file length ----------------------------------------------------*/
WAVE_Format.RIFFchunksize = ReadUnit(4, LittleEndian);
/* Read the file format, must be 'WAVE' ------------------------------------*/
Temp = ReadUnit(4, BigEndian);
if(Temp != FileFormat)
{
return(Unvalid_WAVE_Format);
}
/* Read the format chunk, must be'fmt ' --------------------------------------*/
Temp = ReadUnit(4, BigEndian);
if(Temp != FormatID)
{
return(Unvalid_FormatChunk_ID);
}
/* Read the length of the 'fmt' data, must be 0x10 -------------------------*/
Temp = ReadUnit(4, LittleEndian);
if(Temp != 0x10)
{
ExtraFormatBytes = 1;
}
/* Read the audio format, must be 0x01 (PCM) -------------------------------*/
WAVE_Format.FormatTag = ReadUnit(2, LittleEndian);
if(WAVE_Format.FormatTag != WAVE_FORMAT_PCM)
{
return(Unsupporetd_FormatTag);
}
/* Read the number of channels, must be 0x01 (Mono) ------------------------*/
WAVE_Format.NumChannels = ReadUnit(2, LittleEndian);
if(WAVE_Format.NumChannels != Channel_Mono)
{
return(Unsupporetd_Number_Of_Channel);
}
/* Read the Sample Rate ----------------------------------------------------*/
WAVE_Format.SampleRate = ReadUnit(4, LittleEndian);
/* Update the OCA value according to the .WAV file Sample Rate */
switch(WAVE_Format.SampleRate)
{
case SampleRate_8000 : TIM2ARRValue = 9000; break; /* 8KHz = 72MHz / 9000 */
case SampleRate_11025: TIM2ARRValue = 6531; break; /* 11.025KHz = 72MHz / 6531 */
case SampleRate_22050: TIM2ARRValue = 3265; break; /* 22.05KHz = 72MHz / 3265 */
case SampleRate_44100: TIM2ARRValue = 1633; break; /* 44.1KHz = 72MHz / 1633 */
default: return(Unsupporetd_Sample_Rate);
}
/* Read the Byte Rate ------------------------------------------------------*/
WAVE_Format.ByteRate = ReadUnit(4, LittleEndian);
/* Read the block alignment ------------------------------------------------*/
WAVE_Format.BlockAlign = ReadUnit(2, LittleEndian);
/* Read the number of bits per sample --------------------------------------*/
WAVE_Format.BitsPerSample = ReadUnit(2, LittleEndian);
if(WAVE_Format.BitsPerSample != Bits_Per_Sample_8)
{
return(Unsupporetd_Bits_Per_Sample);
}
SpeechDataOffset = 36;
/* If there is Extra format bytes, these bytes will be defined in "Fact Chunk" */
if(ExtraFormatBytes == 1)
{
/* Read th Extra format bytes, must be 0x00 ------------------------------*/
Temp = ReadUnit(2, LittleEndian);
if(Temp != 0x00)
{
return(Unsupporetd_ExtraFormatBytes);
}
/* Read the Fact chunk, must be 'fact' -----------------------------------*/
Temp = ReadUnit(4, BigEndian);
if(Temp != FactID)
{
return(Unvalid_FactChunk_ID);
}
/* Read Fact chunk data Size ---------------------------------------------*/
Temp = ReadUnit(4, LittleEndian);
SpeechDataOffset += 10 + Temp;
/* Increment SPI Flash read address by Temp bytes by reading Temp dummy bytes */
for(index = 0; index < Temp; index++)
{
SPI_FLASH_SendByte(Dummy_Byte);
}
}
/* Read the Data chunk, must be 'data' ---------------------------------------*/
Temp = ReadUnit(4, BigEndian);
if(Temp != DataID)
{
return(Unvalid_DataChunk_ID);
}
/* Read the number of sample data ------------------------------------------*/
WAVE_Format.DataSize = ReadUnit(4, LittleEndian);
SpeechDataOffset += 8;
return(Valid_WAVE_File);
} |
|