BUFF_MAX_SS=1024;
void Audio_Play(uint32_t I2S_AudioFreq)
{ uint16_t res,i=0;
uint8_t buffer_switch = 1;
XferCplt = 0;
printf("Welcome to use UDA1380 I2S test:
");
// UDA1380_Configuration();
f_lseek(&fileR, WaveCounter);
f_read (&fileR, buffer1, BUFF_MAX_SS, &BytesRead);
f_read (&fileR, buffer2, BUFF_MAX_SS, &BytesRead);
I2S_AudioFreq_Config(I2S_AudioFreq);
/* Start playing wave */
res=HAL_I2S_Transmit_DMA(&hi2s2,buffer1, BUFF_MAX_SS/2);
printf(" >WaveDataLength : %fM
",(float)WaveDataLength/1000/1000);
while(WaveDataLength != 0)
{
while(XferCplt == 0) //DMA传输完成中断里 XferCplt == 1
{
/* wait for DMA transfert complete */
/* You can write some code for operate on UDA1380 */
}
XferCplt = 0;
if(buffer_switch == 0)
{
/* Play data from buffer1 */
HAL_I2S_Transmit_DMA(&hi2s2,buffer_ctl.tmp1, BUFF_MAX_SS);
/* Store data in buffer2 */
res=f_read (&fileR, buffer2, BUFF_MAX_SS, &BytesRead);
for(i=0;i<512;i++)
{
buffer_ctl.tmp2=buffer2;
}
buffer_switch = 1;
}
else
{
/* Play data from buffer2 */
HAL_I2S_Transmit_DMA(&hi2s2,buffer_ctl.tmp2, BUFF_MAX_SS);
/* Store data in buffer1 */
res=f_read (&fileR, buffer1, BUFF_MAX_SS, &BytesRead);
for(i=0;i<512;i++)
{
buffer_ctl.tmp1=buffer1;
}
buffer_switch = 0;
}
if(BytesRead!=1024||res!=0)
{
break;
}
}
printf(&quot;Transfer Complete
&quot;);
} |