Browse Source

update:加一些audio的调试信息

alienwalker 3 years ago
parent
commit
9d96c78418
3 changed files with 32 additions and 20 deletions
  1. 29 17
      application/src/luat_audio_air105.c
  2. 1 2
      bsp/air105/hal/core_spi.c
  3. 2 1
      bsp/audio/include/audio_ll_drv.h

+ 29 - 17
application/src/luat_audio_air105.c

@@ -29,7 +29,12 @@
 #include "mp3_decode/minimp3.h"
 #define LUAT_LOG_TAG "audio"
 #include "luat_log.h"
-
+//#define __DECODE_DEBUG__
+#ifdef __DECODE_DEBUG__
+#define STEP(X)	Stream->DecodeStep=X
+#else
+#define STEP(X)
+#endif
 #define MP3_FRAME_LEN 4 * 1152
 static Audio_StreamStruct prvAudioStream;
 static int32_t luat_audio_wav_decode(void *pData, void *pParam)
@@ -60,16 +65,18 @@ static int32_t luat_audio_mp3_decode(void *pData, void *pParam)
 	uint32_t pos;
 	int read_len;
 	int result;
-	uint32_t is_not_end = 1;
 	mp3dec_frame_info_t info;
 	mp3dec_t *mp3_decoder = (mp3dec_t *)pParam;
 	Audio_StreamStruct *Stream = (Audio_StreamStruct *)pData;
 	Stream->AudioDataBuffer.Pos = 0;
 
-	while ((llist_num(&Stream->DataHead) < 3) && is_not_end && !Stream->IsStop)
+	STEP(1);
+	while ((llist_num(&Stream->DataHead) < 4) && Stream->IsFileNotEnd && !Stream->IsStop)
 	{
-		while (( Stream->AudioDataBuffer.Pos < (Stream->AudioDataBuffer.MaxLen >> 1) ) && is_not_end && !Stream->IsStop)
+		STEP(2);
+		while (( Stream->AudioDataBuffer.Pos < (Stream->AudioDataBuffer.MaxLen - MP3_FRAME_LEN * 2) ) && Stream->IsFileNotEnd && !Stream->IsStop)
 		{
+			STEP(3);
 			if (Stream->FileDataBuffer.Pos < MINIMP3_MAX_SAMPLES_PER_FRAME)
 			{
 				read_len = luat_fs_fread(Stream->FileDataBuffer.Data + Stream->FileDataBuffer.Pos, MINIMP3_MAX_SAMPLES_PER_FRAME, 1, Stream->fd);
@@ -79,40 +86,40 @@ static int32_t luat_audio_mp3_decode(void *pData, void *pParam)
 				}
 				else
 				{
-					is_not_end = 0;
+					Stream->IsFileNotEnd = 0;
 				}
 			}
 			pos = 0;
+			STEP(4);
 			do
 			{
 				memset(&info, 0, sizeof(info));
-
+				STEP(5);
 				result = mp3dec_decode_frame(mp3_decoder, Stream->FileDataBuffer.Data + pos, Stream->FileDataBuffer.Pos - pos,
 						Stream->AudioDataBuffer.Data + Stream->AudioDataBuffer.Pos, &info);
-
+				STEP(6);
 				if (result > 0)
 				{
 					Stream->AudioDataBuffer.Pos += (result * info.channels * 2);
 				}
-				else
-				{
-					DBG("no mp3!");
-				}
 				pos += info.frame_bytes;
-				if (Stream->AudioDataBuffer.Pos >= (Stream->AudioDataBuffer.MaxLen >> 1))
+				if (Stream->AudioDataBuffer.Pos >= (Stream->AudioDataBuffer.MaxLen - MP3_FRAME_LEN * 2))
 				{
 					break;
 				}
-			} while ( ((Stream->FileDataBuffer.Pos - pos) >= (MINIMP3_MAX_SAMPLES_PER_FRAME * is_not_end + 1)) && !Stream->IsStop);
+			} while ( ((Stream->FileDataBuffer.Pos - pos) >= (MINIMP3_MAX_SAMPLES_PER_FRAME * Stream->IsFileNotEnd + 1)) && !Stream->IsStop);
+			STEP(7);
 			OS_BufferRemove(&Stream->FileDataBuffer, pos);
 		}
 		if (!Stream->IsStop)
 		{
+			STEP(8);
 			Audio_WriteRaw(Stream, Stream->AudioDataBuffer.Data, Stream->AudioDataBuffer.Pos);
+			STEP(9);
 		}
 		Stream->AudioDataBuffer.Pos = 0;
 	}
-
+	STEP(0);
 	return 0;
 }
 
@@ -140,6 +147,7 @@ int32_t luat_audio_app_cb(void *pData, void *pParam)
 
 int32_t luat_audio_play_cb(void *pData, void *pParam)
 {
+	Audio_StreamStruct *Stream = (Audio_StreamStruct *)pData;
 	if (pParam == INVALID_HANDLE_VALUE)
 	{
 	    rtos_msg_t msg = {0};
@@ -153,7 +161,10 @@ int32_t luat_audio_play_cb(void *pData, void *pParam)
 		if (!prvAudioStream.IsStop)
 		{
 			prvAudioStream.waitRequire++;
-			ASSERT(prvAudioStream.waitRequire < 3);
+			if (prvAudioStream.waitRequire > 2)
+			{
+				DBG("%d,%d,%u,%u", prvAudioStream.waitRequire, prvAudioStream.DecodeStep,prvAudioStream.FileDataBuffer.Pos,prvAudioStream.AudioDataBuffer.Pos);
+			}
 			Core_ServiceRunUserAPIWithFile(luat_audio_decode_run, &prvAudioStream, prvAudioStream.CoderParam);
 		}
 	}
@@ -228,7 +239,7 @@ int luat_audio_play_stop(uint8_t multimedia_id)
 
 uint8_t luat_audio_is_finish(uint8_t multimedia_id)
 {
-	ASSERT(prvAudioStream.waitRequire < 4);
+	ASSERT(prvAudioStream.waitRequire < 5);
 	return !prvAudioStream.waitRequire;
 }
 
@@ -282,7 +293,7 @@ int luat_audio_play_file(uint8_t multimedia_id, const char *path)
 			num_channels = info.channels;
 			sample_rate = info.hz;
 			len = (num_channels * sample_rate >> 2);	//一次时间为1/16秒
-			OS_ReInitBuffer(&prvAudioStream.AudioDataBuffer, len * 2);	//防止溢出,需要多一点空间
+			OS_ReInitBuffer(&prvAudioStream.AudioDataBuffer, len + MP3_FRAME_LEN * 2);	//防止溢出,需要多一点空间
 			prvAudioStream.Decoder = luat_audio_mp3_decode;
 		}
 		else
@@ -336,6 +347,7 @@ int luat_audio_play_file(uint8_t multimedia_id, const char *path)
 			prvAudioStream.IsPlaying = 1;
 			prvAudioStream.pParam = multimedia_id;
 			prvAudioStream.Decoder(&prvAudioStream, prvAudioStream.CoderParam);
+			prvAudioStream.IsFileNotEnd = 1;
 			if (!llist_num(&prvAudioStream.DataHead))
 			{
 				prvAudioStream.fd = NULL;

+ 1 - 2
bsp/air105/hal/core_spi.c

@@ -385,7 +385,6 @@ static void HSPI_MasterInit(uint8_t SpiID, uint8_t Mode, uint32_t Speed)
 	SPI->CR0 = ctrl;
 	SPI->DCR = 30|(1 << 7);
 	prvSPI[SpiID].Speed = (SystemCoreClock >> 1) / div;
-
 	ISR_SetHandler(prvSPI[SpiID].IrqLine, HSPI_IrqHandle, (uint32_t)SpiID);
 #ifdef __BUILD_OS__
 	ISR_SetPriority(prvSPI[SpiID].IrqLine, IRQ_MAX_PRIORITY + 1);
@@ -781,7 +780,7 @@ static int32_t prvSPI_BlockTransfer(uint8_t SpiID, const uint8_t *TxData, uint8_
 int32_t SPI_BlockTransfer(uint8_t SpiID, const uint8_t *TxData, uint8_t *RxData, uint32_t Len)
 {
 #ifdef __BUILD_OS__
-	if (  OS_CheckInIrq() || ((prvSPI[SpiID].Speed >> 3) >= (Len * 100000)))
+	if (  (Len <= 16) || OS_CheckInIrq() || ((prvSPI[SpiID].Speed >> 3) >= (Len * 100000)))
 	{
 		prvSPI[SpiID].IsBlockMode = 0;
 #endif

+ 2 - 1
bsp/audio/include/audio_ll_drv.h

@@ -41,7 +41,8 @@ typedef struct
 	uint8_t IsPause;
 	uint8_t IsStop;
 	uint8_t IsPlaying;
-
+	uint8_t IsFileNotEnd;
+	uint8_t DecodeStep;
 }Audio_StreamStruct;
 
 void Audio_GlobalInit(void);