Pārlūkot izejas kodu

T555_V03022
* 优化速度及音量评分算法

wangjianlin 3 gadi atpakaļ
vecāks
revīzija
6793d9ce9e

BIN
Released/T555_V03022.rar


+ 4 - 1
Released/releasenote.txt

@@ -80,4 +80,7 @@ V03020
 V03021
 1、POC更新为V03010
 2、优化FOTA界面
-3、评分界面修改为三个评分:设备评分,速度评分和音量评分
+3、评分界面修改为三个评分:设备评分,速度评分和音量评分
+
+V03022
+1、优化速度及音量评分算法

+ 64 - 57
app/learn/learnAudio.c

@@ -10,7 +10,7 @@ LEARN_REC_DEF learnAudio={NULL};
 
 typedef struct{
 	unsigned short maxVolume;//最大音量
-	unsigned short avSpeed;//录音平均语速
+	float avSpeed;//录音平均语速
 	int64_t time;//记录录音时长
 	unsigned char charactorNum;//单词个数
 }LEARN_REC_RESULT_DEF;//录音结果
@@ -27,20 +27,26 @@ static void initRecResult(unsigned char charaNum){
 	recordResult.charactorNum=charaNum;
 }
 static void recordResultMake(void){
-	int64_t time=nwy_get_ms();
-	time = (time-recordResult.time)/1000;
+	int64_t time;
+	float tmp;
+	time=nwy_get_ms();
+	time = time-recordResult.time;
 	if(time<1) time=1;//最小为1秒
-	recordResult.avSpeed = recordResult.charactorNum/time;//单词/秒
-	MSG_INFO(1, "Chara speed:%d,%d", recordResult.avSpeed, time);
+	tmp=recordResult.charactorNum;
+	recordResult.avSpeed = 1000*tmp/time;//单词/秒
+	MSG_INFO(1, "Chara speed:%.1f,num:%d,t:%lldms", recordResult.avSpeed, recordResult.charactorNum,time);
 }
 /*获取本次录音过程中的最大音量值*/
 unsigned short learnGetRecordMaxVolume(void){
 	//return (recordResult.maxVolume*LEV_NUM/0x7FFF);
 	return recordResult.maxVolume;
 }
+#define SPEED_FACTOR 4
 /*获取本次录音的语速:单词/秒*/
-unsigned char learnGetRecordRecSpeed(void){
-	return recordResult.avSpeed;
+float learnGetRecordRecSpeed(void){
+	float speedscore=getLearnSpeedParam()*recordResult.avSpeed*SPEED_FACTOR;
+	if(speedscore>10) speedscore=10;
+	return speedscore;
 }
 bool learnStartRecord(unsigned char charaNum){
 	//初始化编码器
@@ -218,68 +224,69 @@ static int recordDataCb(unsigned char *pcm, unsigned int len){
 	return 0;
 }
 
+#ifdef SAVE_PCM_SD
+int sdFd=-1;
+void pcmFileOpen(void){
+	int fd;
+	char file[50];
+	if(sdFd>0) return;
+	snprintf(file, sizeof(file), "%s/pcm_low.rec", SD_TOKEN);
+	fd = nwy_sdk_fopen(file, NWY_CREAT | NWY_RDWR|NWY_TRUNC);//清0式
+	if(fd<0){
+		MSG_INFO(1,"open failed");
+		return;
+	}
+	sdFd=fd;
+	MSG_INFO(1,"open ok");
+}
+void pcmFileClose(void){
+	if(sdFd<0){
+		MSG_INFO(1,"no need close");
+		return;
+	}
+	nwy_sdk_fclose(sdFd);
+	MSG_INFO(1,"close ok");
+	sdFd=-1;
+}
+void pcmSaveData(unsigned char *pcm, int len){
+	if(sdFd<0){
+		MSG_INFO(1,"not open");
+		return;
+	}
+	nwy_sdk_fwrite(sdFd, pcm, len);
+}
+#endif
 static void pcmVolProcess(unsigned char *pcm, unsigned int len){
-#if 0
+#ifdef SAVE_PCM_SD
+	pcmSaveData(pcm,len);
+#else
 	//对语音数据进行平均音量分析,分析方法为累加,并求平均值,静音时是为0的值
 #define VOL_SUM_FRAME 5
 #define VOL_SHORT_LEV (VOL_SUM_FRAME*160)
-	static unsigned int pcmSum=0;
-	unsigned short tmp;
-	unsigned int i;
-	unsigned int tVol;
+	short *ptr=(short *)pcm;
+	int i;
 	static unsigned short frameVolNum=0;
-	unsigned int sum=0;
-
+	unsigned int sum=0,tmp;
+	static unsigned int pcmSum=0;
+	//char info[60];
 	if(len != 320) return;
 	for(i=0;i<160;i++){
-		tmp=pcm[2*i+1];//&0x7F;//取绝对值
-		tmp <<= 8;
-		tmp |= pcm[2*i];
+		tmp=abs(ptr[i]);
 		pcmSum += tmp;
-		sum += tmp;
 	}
-	sum /= 160;
-	if(sum > recordResult.maxVolume) recordResult.maxVolume=sum;//计算每一帧的最大音量
-	if(++frameVolNum>=VOL_SUM_FRAME){//1秒得出一个平均音量吧
-		tVol=pcmSum/VOL_SHORT_LEV;
-		tVol *= LEV_NUM;
-		tVol /= 0xfFFF;
-		//MSG_INFO(1, "***%d,%d,%d", pcmSum,VOL_SHORT_LEV,tVol);
-		learnRecSetVol(tVol);
+	if(++frameVolNum>=VOL_SUM_FRAME){
+		sum=pcmSum/VOL_SHORT_LEV;
+		//snprintf(info, sizeof(info), "[0]{%d}",sum);
+		//nwy_usb_serial_send(info, strlen(info));
+		//MSG_INFO(1, "pcm:%d", sum);
+		sum *= (LEV_NUM-1);
+		sum /=10000;
+		if(sum >(LEV_NUM-1)) sum = LEV_NUM-1;
+		learnRecSetVol(sum);
+		if(sum > recordResult.maxVolume) recordResult.maxVolume=sum;//计算每一帧的最大音量
 		pcmSum=0;
 		frameVolNum=0;
 	}
-#else
-	const unsigned short vtable[]={
-		30000,
-		30000+1500,
-		30000+1500*2,
-		30000+1500*3,
-		30000+1500*4,
-		30000+1500*5,
-		30000+1500*6,
-		30000+1500*7,
-		30000+1500*8,
-		30000+1500*9,
-		30000+1500*10,
-	};
-	int i,tmp;
-	unsigned int sum=0,avrPcm,max=0;
-	if(len != 320) return;
-	for(i=0;i<len;i+=2){//求得一帧语音总量
-		tmp=pcm[i+1];
-		tmp <<= 8;
-		tmp &= 0xff00;
-		tmp |= pcm[i];
-		avrPcm = abs(tmp);
-		sum += avrPcm;
-	}
-	sum /= 160;
-	for(i=0;i<11;i++){
-		if(sum<vtable[i]) break;
-	}
-	learnRecSetVol(i);
-	if(i > recordResult.maxVolume) recordResult.maxVolume=i;
 #endif
 }
 

+ 8 - 1
app/learn/learnAudio.h

@@ -60,5 +60,12 @@ void recordSaveTmpToLocal(char *fileName);
 unsigned char *learnGetTmpAudioBuf(void);
 unsigned int learnGetTmpAudioLength(void);
 unsigned short learnGetRecordMaxVolume(void);
-unsigned char learnGetRecordRecSpeed(void);
+float learnGetRecordRecSpeed(void);
+
+//#define SAVE_PCM_SD
+
+#ifdef SAVE_PCM_SD
+void pcmFileOpen(void);
+void pcmFileClose(void);
+#endif
 #endif

+ 5 - 2
app/learn/learnHttp.c

@@ -93,6 +93,7 @@ static void learnEntry(void *param){
 	int pIndex,lLen,pLen,tLen,rLen;
 	unsigned char *postBuf=NULL;
 	char tmp[30];
+	float tmpSpeed;
 	
 	appSleepCtl(ASLEEP_LEARN, 1);
 	boolean http_https=false;//http
@@ -142,13 +143,15 @@ static void learnEntry(void *param){
 		}
 		for(;;){
 			httpinfo.lteStatus=HTTP_STATUS_POST_BUSY;
+			
+			tmpSpeed=learnGetRecordRecSpeed();
 			//先填充必须的一些字段信息,数据未填充,包有效数据长度未填(原始数据,非base64后)
-			snprintf(postBuf, USER_DATA_SIZE, "{\"tid\":%s,\"uid\":%d,\"gid\":%d,\"dsv\":%d,\"dss\":%d,\"fsize\":%d,\"offset\":%d,\"token\":\"%s\",\"data\":\"",
+			snprintf(postBuf, USER_DATA_SIZE, "{\"tid\":%s,\"uid\":%d,\"gid\":%d,\"dsv\":%d,\"dss\":%.1f,\"fsize\":%d,\"offset\":%d,\"token\":\"%s\",\"data\":\"",
 														   learnGetTid(),
 														   getLearnUid(),
 														   getLearnGid(),
 														   learnGetRecordMaxVolume(),
-														   learnGetRecordRecSpeed(),
+														   tmpSpeed,
 														   httpinfo.dlength,
 														   pIndex,
 														   getLearnToken());

+ 17 - 9
app/learn/learnTask.c

@@ -194,6 +194,7 @@ unsigned int getLearnUid(void){return usr.uid;}
 unsigned int getLearnGid(void){return usr.gid;}
 char *getLearnGName(void){return usr.gname;}
 char *getLearnToken(void){return usr.token;}
+double getLearnSpeedParam(void){return usr.scoreSpeedParam;}
 bool isUserInfoReady(void){return usr.ready;}
 void learnUserInfoClear(void){usr.ready=false;}
 /*
@@ -1144,6 +1145,9 @@ void uiShowLearnTaskDetail(char update){
 			break;
 		case LEARN_REC_OT://录音已超过最大时间,停止录音
 			learnRecordDoneProcess();
+		#ifdef SAVE_PCM_SD
+			pcmFileClose();
+		#endif
 			break;
 		case LEARN_REC_PLY://正在播放
 			switch(learnPlyGetResult()){
@@ -1231,6 +1235,9 @@ void uiShowLearnTaskDetailResponse(void){
 				break;
 			case LEARN_REC_BUSY://正在录音,选择停止
 				learnRecordDoneProcess();
+			#ifdef SAVE_PCM_SD
+				pcmFileClose();
+			#endif
 				break;
 			case LEARN_REC_DONE://刚录音完成,选择放弃而返回到任务详情
 				learnRecordBufRelease();
@@ -1258,6 +1265,9 @@ void uiShowLearnTaskDetailResponse(void){
 					learnDetailBackToTaskListMenu();
 					break;
 				}
+			#ifdef SAVE_PCM_SD
+				pcmFileOpen();
+			#endif
 				uiMenuShowBottomIndacitor(NULL, "停止");
 				learnRecSetStatus(LEARN_REC_BUSY);
 				break;
@@ -1294,24 +1304,22 @@ void uiShowLearnTaskDetailResponse(void){
 	}
 }
 static void learnShowResult(void){
-	double devscore;
-	double speedscore;
-	double volumescore;
+	float devscore;
+	float speedscore=learnGetRecordRecSpeed();
+	float volumescore;
 	char info[30];
-	unsigned char speed=learnGetRecordRecSpeed();
 	unsigned int y=UI_CONTENT_SHOW_Y+5;
-	if(speed<=0) speed=1;
-	speedscore=usr.scoreSpeedParam*speed;
+
 	volumescore=usr.scoreVolumeParam*learnGetRecordMaxVolume();
 	devscore=speedscore+volumescore;
 	guiClearRect(0,UI_CONTENT_SHOW_Y,GLCD_WIDTH-1,GLCD_HEIGHT-16-1,guiGetBackColor());
-	snprintf(info, sizeof(info), "设备评分:%f", devscore);
+	snprintf(info, sizeof(info), "设备评分:%.1f", devscore);
 	guiShowStr(5, y, info, FONT_MODE_16X16, REVERSED_NO, COLOR_BLACK, guiGetBackColor());
 	y+= 18;
-	snprintf(info, sizeof(info), "速度评分:%f", speedscore);
+	snprintf(info, sizeof(info), "速度评分:%.1f", speedscore);
 	guiShowStr(5, y, info, FONT_MODE_16X16, REVERSED_NO, COLOR_BLACK, guiGetBackColor());
 	y+= 18;
-	snprintf(info, sizeof(info), "音量评分:%f", volumescore);
+	snprintf(info, sizeof(info), "音量评分:%.1f", volumescore);
 	guiShowStr(5, y, info, FONT_MODE_16X16, REVERSED_NO, COLOR_BLACK, guiGetBackColor());
 	y+= 18;
 }

+ 1 - 0
app/learn/learnTask.h

@@ -40,4 +40,5 @@ void uiShowLearnGroup(char type);
 
 void sdUnmount(void);
 void sdMount(void);
+double getLearnSpeedParam(void);
 #endif

+ 1 - 1
app/ohpoc.h

@@ -7,7 +7,7 @@
 #define OHPOC_APP_NAME "T555"
 //#define OHPOC_APP_NAME "RTL-TEST"
 
-#define OHPOC_VERSION "03021"  //外部OCPU 应用维护
+#define OHPOC_VERSION "03022"  //外部OCPU 应用维护
 #define OHPOC_MODLE	"N58" //作为OPEN时,此值用于FOTA升级标识使用
 #define OHPOC_CUST OHPOC_APP_NAME //作为OPEN时,此值用于FOTA升级标识使用