|
@@ -15,6 +15,8 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
import javax.sound.sampled.AudioFormat;
|
|
|
|
|
|
+import com.yonge.audio.utils.ArrayUtil;
|
|
|
+import org.apache.commons.lang.ArrayUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
@@ -43,6 +45,9 @@ public class UserChannelContext {
|
|
|
private final static int MAX_FREQUECY = 2000;
|
|
|
|
|
|
private FastYin detector;
|
|
|
+
|
|
|
+ // 低频
|
|
|
+ private FastYin lowDetector;
|
|
|
|
|
|
private String user;
|
|
|
|
|
@@ -127,6 +132,7 @@ public class UserChannelContext {
|
|
|
hardLevel = HardLevelEnum.valueOf(heardLevel);
|
|
|
if(detector == null){
|
|
|
detector = new FastYin(sampleRate, bufferSize);
|
|
|
+ lowDetector = new FastYin(sampleRate,bufferSize * 4);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -325,28 +331,40 @@ public class UserChannelContext {
|
|
|
|
|
|
//YINPitchDetector frequencyDetector = new YINPitchDetector(samples.length , audioFormat.getSampleRate());
|
|
|
//int playFrequency = (int) frequencyDetector.getFrequency(samples);
|
|
|
-
|
|
|
+
|
|
|
+ double durationTime = 1000 * (samples.length * 2) / audioFormat.getSampleRate() / (audioFormat.getSampleSizeInBits() / 8);
|
|
|
+
|
|
|
+ playTime += durationTime;
|
|
|
+
|
|
|
+ // 获取当前音符信息
|
|
|
+ MusicXmlNote musicXmlNote = getCurrentMusicNote(null,null);
|
|
|
+
|
|
|
+ if (musicXmlNote == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
int playFrequency = -1;
|
|
|
+
|
|
|
if(!percussionList.contains(subjectId)){
|
|
|
- playFrequency = (int)detector.getPitch(samples).getPitch();
|
|
|
- LOGGER.info("频率 {}",playFrequency);
|
|
|
+ if (musicXmlNote.getFrequency() < MIN_FREQUECY) {
|
|
|
+ float[] floats = ArrayUtils.addAll(samples, samples);
|
|
|
+ float[] lowSamples = ArrayUtils.addAll(floats,floats);
|
|
|
+
|
|
|
+ playFrequency = (int) lowDetector.getPitch(lowSamples).getPitch();
|
|
|
+
|
|
|
+ } else {
|
|
|
+ playFrequency = (int) detector.getPitch(samples).getPitch();
|
|
|
+ }
|
|
|
+ if (playFrequency != -1) {
|
|
|
+ LOGGER.info("频率 {}", playFrequency);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
-
|
|
|
- playTime += durationTime;
|
|
|
-
|
|
|
- // 获取当前音符信息
|
|
|
- MusicXmlNote musicXmlNote = getCurrentMusicNote(null,null);
|
|
|
|
|
|
- if (musicXmlNote == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
|
|
|
//取出当前处理中的音符信息
|
|
|
NoteAnalysis noteAnalysis = getProcessingNote();
|