硬件设计:
PCM1770芯片是一款低电压、低功耗带耳机放大的DAC芯片,用其实现音频的DA转换。
四、软件设计
int main(void)
{
USART_Configuration();
printf("\n\r -----------------------------------------") ;
printf("\n\r神舟III号音频播放实验") ;
printf("\n\r -----------------------------------------") ;
printf("\n\r串口初始化完成");
/* I2S GPIO接口配置 */
I2S_GPIO_Config();
/*SPI2接口初始化*/
SPI2_Config();
PCM1770_CS_config();
SPI2_Init_For_PCM1770();
printf("\n\rPCM1770 SPI接口初始化完成");
/*中断向量与中断优先级配置*/
NVIC_Configuration();
I2S_CODEC_Init(OutputDevice_SPEAKER, AUDIO_FILE_ADDRESS);//I2C CODEC初始化
I2S_CODEC_Play(1);
while(1)
{
}
}
在音频播放试验中采用I2S3中断方式来实现音频播放。当I2S3中断时,就进入I2S3的中断服务程序,调用音频播放程序I2S_CODEC_DataTransfer(),因此,我们可以重复听到相同的音频。
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Set the Vector Table base address at 0x08010000 */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0000);
/* SPI2 IRQ Channel configuration */
NVIC_InitStructure.NVIC_IRQChannel = SPI3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void SPI3_IRQHandler(void)
{
//static int IRQcounter = 0;
if ((SPI_I2S_GetITStatus(SPI3, SPI_I2S_IT_TXE) == SET))
{
/* Send data on the SPI3 and Check the current commands */
I2S_CODEC_DataTransfer();
}
}
void I2S_CODEC_DataTransfer(void)
{
/* Send the data read from the memory */
SPI_I2S_SendData(SPI3, (Media_ReadHalfWord(AudioDataIndex)));
/* Increment the index */
//根据波形文件的通道数目增加播放文件指针地址
IncrementVar_AudioDataIndex(WAVE_Format.NumChannels);
}
波形文件的格式:
/* .WAV file format :
Endian Offset Length Contents
big 0 4 bytes 'RIFF' // 0x52494646
little 4 4 bytes
big 8 4 bytes 'WAVE' // 0x57415645
Next, the fmt chunk describes the sample format:
big 12 4 bytes 'fmt ' // 0x666D7420
little 16 4 bytes 0x00000010 // Length of the fmt data (16 bytes)
little 20 2 bytes 0x0001 // Format tag: 1 = PCM
little 22 2 bytes // Channels: 1 = mono, 2 = stereo
little 24 4 bytes // Samples per second: e.g., 22050
little 28 4 bytes // sample rate * block align
little 32 2 bytes // channels * bits/sample / 8
little 34 2 bytes // 8 or 16
Finally, the data chunk contains the sample data:
big 36 4 bytes 'data' // 0x64617461
little 40 4 bytes
little 44 *
|