|
@@ -38,11 +38,17 @@ public class UserChannelContext {
|
|
|
//打击乐
|
|
|
private final static List<Integer> percussionList = Arrays.asList(23, 113);
|
|
|
|
|
|
+ private FastYin detector;
|
|
|
+
|
|
|
+ private float sampleRate;
|
|
|
+
|
|
|
+ private int bitsPerSample;
|
|
|
+
|
|
|
private String user;
|
|
|
|
|
|
private double standardFrequecy = 442;
|
|
|
|
|
|
- private int offsetMS;
|
|
|
+ private float offsetMS;
|
|
|
|
|
|
private double dynamicOffset;
|
|
|
|
|
@@ -52,7 +58,7 @@ public class UserChannelContext {
|
|
|
|
|
|
private Integer subjectId;
|
|
|
|
|
|
- private int beatDuration;
|
|
|
+ private float beatDuration;
|
|
|
|
|
|
private int beatByteLength;
|
|
|
|
|
@@ -77,8 +83,6 @@ public class UserChannelContext {
|
|
|
|
|
|
private double playTime;
|
|
|
|
|
|
- private double receivedTime;
|
|
|
-
|
|
|
private HardLevelEnum hardLevel = HardLevelEnum.ADVANCED;
|
|
|
|
|
|
private boolean handlerSwitch;
|
|
@@ -118,12 +122,17 @@ public class UserChannelContext {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- public void init(String platform, String heardLevel, int subjectId, int beatDuration) {
|
|
|
+ public void init(String platform, String heardLevel, int subjectId, float beatDuration,float sampleRate, int bitsPerSample, int bufferSize) {
|
|
|
this.platform = platform;
|
|
|
this.subjectId = subjectId;
|
|
|
this.beatDuration = beatDuration;
|
|
|
- this.beatByteLength = WaveformWriter.SAMPLE_RATE * WaveformWriter.BITS_PER_SAMPLE / 8 * beatDuration / 1000;
|
|
|
+ this.beatByteLength = (int) (sampleRate * bitsPerSample / 8 * beatDuration / 1000);
|
|
|
hardLevel = HardLevelEnum.valueOf(heardLevel);
|
|
|
+ if(detector == null){
|
|
|
+ detector = new FastYin(sampleRate, bufferSize);
|
|
|
+ }
|
|
|
+ this.sampleRate = sampleRate;
|
|
|
+ this.bitsPerSample = bitsPerSample;
|
|
|
}
|
|
|
|
|
|
public byte[] skipMetronome(byte[] datas) {
|
|
@@ -132,9 +141,9 @@ public class UserChannelContext {
|
|
|
beatByteLength -= datas.length;
|
|
|
return new byte[0];
|
|
|
}
|
|
|
- if(beatByteLength % 2 != 0){
|
|
|
+ /*if(beatByteLength % 2 != 0){
|
|
|
beatByteLength++;
|
|
|
- }
|
|
|
+ }*/
|
|
|
datas = ArrayUtil.extractByte(datas, beatByteLength, datas.length - 1);
|
|
|
beatByteLength = 0;
|
|
|
}
|
|
@@ -161,14 +170,22 @@ public class UserChannelContext {
|
|
|
this.handlerSwitch = handlerSwitch;
|
|
|
}
|
|
|
|
|
|
- public int getOffsetMS() {
|
|
|
+ public float getOffsetMS() {
|
|
|
return offsetMS;
|
|
|
}
|
|
|
|
|
|
- public void setOffsetMS(int offsetMS) {
|
|
|
+ public void setOffsetMS(float offsetMS) {
|
|
|
this.offsetMS = offsetMS;
|
|
|
}
|
|
|
|
|
|
+ public float getBeatDuration() {
|
|
|
+ return beatDuration;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setBeatDuration(float beatDuration) {
|
|
|
+ this.beatDuration = beatDuration;
|
|
|
+ }
|
|
|
+
|
|
|
public HardLevelEnum getHardLevel() {
|
|
|
return hardLevel;
|
|
|
}
|
|
@@ -202,7 +219,7 @@ public class UserChannelContext {
|
|
|
}
|
|
|
|
|
|
public void resetUserInfo() {
|
|
|
- beatByteLength = WaveformWriter.SAMPLE_RATE * WaveformWriter.BITS_PER_SAMPLE / 8 * beatDuration / 1000;
|
|
|
+ beatByteLength = (int) (sampleRate * bitsPerSample / 8 * beatDuration / 1000);
|
|
|
waveFileProcessor = null;
|
|
|
processingNote = new NoteAnalysis(0,0,-1);
|
|
|
evaluatingSectionIndex = new AtomicInteger(0);
|
|
@@ -212,7 +229,6 @@ public class UserChannelContext {
|
|
|
totalChunkAnalysisList = new ArrayList<ChunkAnalysis>();
|
|
|
recordId = null;
|
|
|
playTime = 0;
|
|
|
- receivedTime = 0;
|
|
|
delayProcessed = false;
|
|
|
dynamicOffset = 0;
|
|
|
handlerSwitch = false;
|
|
@@ -330,10 +346,11 @@ public class UserChannelContext {
|
|
|
//YINPitchDetector frequencyDetector = new YINPitchDetector(samples.length , audioFormat.getSampleRate());
|
|
|
//int playFrequency = (int) frequencyDetector.getFrequency(samples);
|
|
|
|
|
|
- FastYin detector = new FastYin(audioFormat.getSampleRate(), samples.length);
|
|
|
int playFrequency = -1;
|
|
|
if(!percussionList.contains(subjectId)){
|
|
|
playFrequency = (int)detector.getPitch(samples).getPitch();
|
|
|
+ }else{
|
|
|
+ LOGGER.info("subjectId:{}", subjectId);
|
|
|
}
|
|
|
|
|
|
int splDb = (int) Signals.soundPressureLevel(samples);
|
|
@@ -343,12 +360,6 @@ public class UserChannelContext {
|
|
|
|
|
|
double durationTime = 1000 * (samples.length * 2) / audioFormat.getSampleRate() / (audioFormat.getSampleSizeInBits() / 8);
|
|
|
|
|
|
- /*receivedTime += durationTime;
|
|
|
-
|
|
|
- if(receivedTime < offsetMS){
|
|
|
- return;
|
|
|
- }*/
|
|
|
-
|
|
|
playTime += durationTime;
|
|
|
|
|
|
// 获取当前音符信息
|
|
@@ -641,6 +652,8 @@ public class UserChannelContext {
|
|
|
double endTime = musicXmlNote.getTimeStamp() + dynamicOffset + floatingRange;
|
|
|
double startTime = musicXmlNote.getTimeStamp() + dynamicOffset - floatingRange;
|
|
|
|
|
|
+ LOGGER.info("------------floatingRange StartTime:{} EndTime:{}------------", startTime, endTime);
|
|
|
+
|
|
|
List<ChunkAnalysis> chunkAnalysisList = totalChunkAnalysisList.stream().filter(t -> Double.doubleToLongBits(t.getStartTime()) >= Double.doubleToLongBits(startTime) && Double.doubleToLongBits(t.getEndTime()) <= Double.doubleToLongBits(endTime)).collect(Collectors.toList());
|
|
|
|
|
|
double correctedStartTime = queryFirstNoteStartTime(chunkAnalysisList, musicXmlNote);
|
|
@@ -648,6 +661,8 @@ public class UserChannelContext {
|
|
|
|
|
|
chunkAnalysisList = totalChunkAnalysisList.stream().filter(t -> Double.doubleToLongBits(t.getStartTime()) >= Double.doubleToLongBits(correctedStartTime) && Double.doubleToLongBits(t.getEndTime()) <= Double.doubleToLongBits(correctedEndTime)).collect(Collectors.toList());
|
|
|
|
|
|
+ LOGGER.info("------------ correctedStartTime:{} correctedEndTime:{}------------", correctedStartTime, correctedEndTime);
|
|
|
+
|
|
|
//根据完整度取部分有效信号
|
|
|
int elementSize = chunkAnalysisList.size() * hardLevel.getIntegrityRange() / 100;
|
|
|
chunkAnalysisList = chunkAnalysisList.subList(0, elementSize);
|