yonge 3 years ago
parent
commit
bfaced497e

+ 20 - 4
audio-analysis/src/main/java/com/yonge/nettty/dto/UserChannelContext.java

@@ -32,7 +32,7 @@ public class UserChannelContext {
 	
 	private final static Logger LOGGER = LoggerFactory.getLogger(UserChannelContext.class);
 	
-	private int offsetMS = 300;
+	private int offsetMS = 0;
 	
 	private Long recordId;
 	
@@ -42,6 +42,8 @@ public class UserChannelContext {
 	
 	private int beatByteLength;
 	
+	private boolean handleSwitch;
+	
 	// 曲目与musicxml对应关系
 	private ConcurrentHashMap<Integer, MusicXmlBasicInfo> songMusicXmlMap = new ConcurrentHashMap<Integer, MusicXmlBasicInfo>();
 
@@ -74,7 +76,7 @@ public class UserChannelContext {
 		hardLevel = HardLevelEnum.valueOf(heardLevel);
 	}
 	
-	public byte[] skipHeader(byte[] datas) {
+	public byte[] skipMetronome(byte[] datas) {
 		if (beatByteLength > 0) {
 			if (datas.length <= beatByteLength) {
 				beatByteLength -= datas.length;
@@ -97,6 +99,10 @@ public class UserChannelContext {
 		this.recordId = recordId;
 	}
 
+	public int getOffsetMS() {
+		return offsetMS;
+	}
+
 	public void setOffsetMS(int offsetMS) {
 		this.offsetMS = offsetMS;
 	}
@@ -143,6 +149,7 @@ public class UserChannelContext {
 		receivedTime = 0;
 		offsetMS = 0;
 		lastChunkAnalysisList = new ArrayList<ChunkAnalysis>();
+		handleSwitch = false;
 	}
 	
 	public MusicXmlBasicInfo getMusicXmlBasicInfo(Integer songId){
@@ -259,12 +266,21 @@ public class UserChannelContext {
 		int splDb = (int) Signals.soundPressureLevel(samples);
 		int power = (int) Signals.power(samples);
 		int amplitude = (int) Signals.norm(samples);
+		float rms = Signals.rms(samples);
 		
 		double durationTime = 1000 * (samples.length * 2) / audioFormat.getSampleRate() / (audioFormat.getSampleSizeInBits() / 8);
 		
+		if(handleSwitch == false && rms > 0.01){
+			handleSwitch = true;
+		}
+		
+		if(handleSwitch == false){
+			return;
+		}
+		
 		receivedTime += durationTime;
 		
-		if(receivedTime < offsetMS){
+		if(receivedTime <= offsetMS){
 			return;
 		}
 		
@@ -370,7 +386,7 @@ public class UserChannelContext {
 				}*/
 				//skip = noteAnalysis.getStandardDurationTime() * 0.2;
 				
-				LOGGER.info("Frequency:{}  splDb:{}  Power:{}  amplitude:{}", playFrequency, splDb, power, amplitude);
+				LOGGER.info("Frequency:{}  splDb:{}  Power:{}  amplitude:{}  rms:{}", playFrequency, splDb, power, amplitude, rms);
 				
 				chunkAnalysisList.add(new ChunkAnalysis(playTime - durationTime, playTime, playFrequency, splDb, power, amplitude));
 				

+ 2 - 2
audio-analysis/src/main/java/com/yonge/netty/server/service/AudioCompareHandler.java

@@ -225,7 +225,7 @@ public class AudioCompareHandler implements MessageHandler {
 			
 			Integer offsetTime = dataObj.getInteger("offsetTime");
 			if(offsetTime != null){
-				channelContext.setOffsetMS(offsetTime);
+				//channelContext.setOffsetMS(offsetTime);
 			}
 
 			break;
@@ -269,7 +269,7 @@ public class AudioCompareHandler implements MessageHandler {
 		}
 		waveFileProcessor.process(datas);
 
-		datas = channelContext.skipHeader(datas);
+		datas = channelContext.skipMetronome(datas);
 
 		if (datas.length == 0) {
 			return false;