请教下,播放flac音乐时,屏幕有干扰,是怎么回事啊 ?
刚开始时貌似有地方卡住了的感觉,会发出卡卡卡的使用,但是过一会就好了,声音就正常播放了,只是屏幕有干扰发生,不知道是怎么情况 ???
播放部分代码如下:
int flac_play_song(char* path)
{
FLACContext fc;
int fd;
int n;
int bytesleft;
int consumed;
char tmp[20];
static volatile int8_t i;
unsigned char *filebuf;
unsigned short *temp_buffer;
char value=0;
uint8_t res;
int16_t *PCM_buffer0=0;
int16_t *PCM_buffer1=0;
uint8_t *p8;
UINT br;
u32 flac_fptr=0;
char PlayAddr[100] = {0};
strcpy(PlayAddr, (const char *)path);
audiodev.file = (FIL*)mymalloc(SRAMDTCM,sizeof(FIL));
res=f_open(audiodev.file,(char*)PlayAddr,FA_READ); //读取文件错误
if(res!=FR_OK)
{
myfree(SRAMDTCM, audiodev.file);
return 0xff;
}
flacctrl = mymalloc(SRAMDTCM,sizeof(__flacctrl));
/* Read the metadata and position the file pointer at the start of the
first audio frame */
flac_init(audiodev.file, flacctrl, &fc);
dump_headers(&fc);
f_lseek (audiodev.file , audiodev.file->fptr);
printf("波特率:%dKbps
",fc.bitrate);
printf("采样率:%d
",fc.samplerate);
if (fc.length/1000%60>=10)
printf("总时间:%d:%d
",fc.length/1000/60, fc.length/1000%60);
else
printf(tmp,"总时间:%d:0%d
",fc.length/1000/60, fc.length/1000%60);
printf("块大小:%d
",fc.max_blocksize);
PCM_buffer0 = (int16_t *)mymalloc(SRAMEX,MAX_BLOCKSIZE * MAX_CHANNELS * 2);
PCM_buffer1 = (int16_t *)mymalloc(SRAMEX,MAX_BLOCKSIZE * MAX_CHANNELS * 2);
filebuf = (uint8_t *)mymalloc(SRAMEX,MAX_FRAMESIZE * 2); //内存分配.
if (filebuf==NULL)
{
printf("
no mem!!
");
goto fail;
}
temp_buffer= (unsigned short *)mymalloc(SRAMEX,MAX_FRAMESIZE * MAX_CHANNELS * 2); //内存分配.
if((fc.min_blocksize != fc.max_blocksize) || (fc.max_blocksize > MAX_BLOCKSIZE ) || (fc.max_framesize > MAX_FRAMESIZE))
{
printf("
Oo Do not support this file!!
");
printf("You can choose another Converter.Such as foobar2000 ^_^
");
goto fail;
}
audiodev.i2sbuf1 = (uint8_t *)PCM_buffer0;
audiodev.i2sbuf2 = (uint8_t *)PCM_buffer1;
FLAC_Stop();
FLAC_EnterPlayMode(); //进入播放模式
FLAC_SaiConfInit(flacctrl->bps, flacctrl->samplerate, flacctrl->outsamples);
__LTDC_drv->LTDC_DispStringAt(5, 375, LCD_COLOR_BLUE, //显示当前播放的 .wav文件名字
LCD_COLOR_WHITE,
&FontAscii8x16,
(const uint8_t *)PlayAddr);
f_read(audiodev.file,filebuf,MAX_FRAMESIZE,&br);//读取最大帧长数据
bytesleft = br;
flac_fptr = audiodev.file->fptr; //记录当前的文件位置.
FLAC_Start(); //开始播放
while (bytesleft)
{
while(audiodev.AudioTransferEnd==0)//等待传输完成
{
};
audiodev.AudioTransferEnd=0;
if(audiodev.AudioSwitchBuf == 0)
{
p8 = audiodev.i2sbuf1;
}
else
{
p8 = audiodev.i2sbuf2;
}
fc.decoded0 = (int32_t *)p8;
fc.decoded1 = (int32_t *)temp_buffer;
flac_decode_frame(&fc,filebuf,bytesleft,(int16_t *)p8);
consumed=fc.gb.index/8;
rt_memmove(filebuf,&filebuf[consumed],bytesleft-consumed);
bytesleft-=consumed;
f_read(audiodev.file, &filebuf[bytesleft],MAX_FRAMESIZE-bytesleft, &br);
if (br > 0)
{
bytesleft+=br;
}
flac_fptr=audiodev.file->fptr; //记录当前的文件位置.
while(audiodev.status&(1<<1)) //正常播放中
{
FLAC_MsgShow(audiodev.file); //得到总时间和当前播放的时间
audiodev.totsec=flacctrl->totsec; //参数传递
audiodev.cursec=flacctrl->cursec;
audiodev.bitrate=flacctrl->bitrate;
audiodev.samplerate=flacctrl->samplerate;
audiodev.bps=flacctrl->bps;
if(audiodev.status&0X01)break; //没有按下暂停
// else
// HAL_Delay(5); // delay_ms(1000/OS_TICKS_PER_SEC);
}
if((audiodev.status&(1<<1))==0) //请求结束播放/播放完成
{
break;
}
}
fail:
Getmemtablestatus(); //获取内存块状态
f_close(audiodev.file);
myfree(SRAMDTCM,audiodev.file);
myfree(SRAMDTCM,flacctrl);
myfree(SRAMEX,PCM_buffer0);
myfree(SRAMEX,PCM_buffer1);
myfree(SRAMEX,filebuf);
myfree(SRAMEX,temp_buffer);
return value;
}
具体效果你可以看看这个视频
http://v.youku.com/v_show/id_XMz ... j.8428770.3416059.1
播放其他的 wav, mp3 都是完全没有任何问题的,而且只要不播放 flac ,显示完全正常
你这么来说,我个人猜测,是不是屏幕的数据线受到干扰。。。
一周热门 更多>