Jelajahi Sumber

CPU工程更新:
1.优化了音频播放demo遍历非RIFF标准wav格式文件头时,得不到正确音频参数导致的播放异常问题。

helen 6 bulan lalu
induk
melakukan
2757e85be4
1 mengubah file dengan 32 tambahan dan 4 penghapusan
  1. 32 4
      amt630hv160-freertos-beta/demo/audio_test_demo.c

+ 32 - 4
amt630hv160-freertos-beta/demo/audio_test_demo.c

@@ -74,8 +74,22 @@ static int wavplay_parse_header(void *file, struct wav_info *info)
 	if (info->fmt_block.fmt_size > sizeof(struct WAVE_FORMAT_DEF))
 		RomFileSeek((RomFile *)file, info->fmt_block.fmt_size - sizeof(struct WAVE_FORMAT_DEF), SEEK_CUR);
 
-	if (RomFileRead((RomFile *)file, &(info->data_block), sizeof(struct DATA_BLOCK_DEF)) <= 0)
-		goto __exit;
+	max_sub_chunk = 8;
+	while(1)
+	{
+		if (RomFileRead((RomFile *)file, &(info->data_block),  sizeof(struct DATA_BLOCK_DEF)) <= 0)
+			goto __exit;
+
+		if(memcmp(info->data_block.data_id, "data", 4) == 0)
+			break;	/* "data" sub-chunk fond */
+
+		/* sub-chunk "data" not fond, seek to the next sub-chunk */
+		RomFileSeek((RomFile *)file, info->data_block.data_size, SEEK_CUR);
+
+		/* timeout */
+		if(max_sub_chunk-- <= 0)
+			goto __exit;
+	};
 #else
 	if (ff_fread(&(info->header), sizeof(struct RIFF_HEADER_DEF), 1, (FF_FILE *)file) <= 0)
 		goto __exit;
@@ -99,8 +113,22 @@ static int wavplay_parse_header(void *file, struct wav_info *info)
 	if (info->fmt_block.fmt_size > sizeof(struct WAVE_FORMAT_DEF))
 		ff_fseek((FF_FILE *)file, info->fmt_block.fmt_size - sizeof(struct WAVE_FORMAT_DEF), FF_SEEK_CUR);
 
-	if (ff_fread(&(info->data_block), sizeof(struct DATA_BLOCK_DEF), 1, (FF_FILE *)file) <= 0)
-		goto __exit;
+	max_sub_chunk = 8;
+	while(1)
+	{
+		if (ff_fread(&(info->data_block),  sizeof(struct DATA_BLOCK_DEF), 1, (FF_FILE *)file) <= 0)
+			goto __exit;
+
+		if(memcmp(info->data_block.data_id, "data", 4) == 0)
+			break;	// "data" sub-chunk fond.
+
+		/* sub-chunk "fmt " not fond, seek to the next sub-chunk */
+		ff_fseek((FF_FILE *)file, info->data_block.data_size, FF_SEEK_CUR);
+
+		/* timeout */
+		if(max_sub_chunk-- <= 0)
+			goto __exit;
+	};
 #endif
 
 	return 0;