|
@@ -2,6 +2,7 @@ package com.cooleshow.musictuner.utils;
|
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
+import com.cooleshow.base.utils.LOG;
|
|
|
import com.cooleshow.musictuner.bean.VoiceToneBean;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
@@ -96,10 +97,23 @@ public class VoiceDataUtils {
|
|
|
resultPosition = end;
|
|
|
}
|
|
|
VoiceToneBean voiceToneBean = buildBean(resultPosition, getBeforePosition(resultPosition - 1), getAfterPosition(resultPosition + 1));
|
|
|
- voiceToneBean.difference = String.valueOf(targetVoiceFrequencyValue - ALL_VOICE_SAMPLES[resultPosition]);
|
|
|
+// voiceToneBean.difference = String.valueOf(targetVoiceFrequencyValue - ALL_VOICE_SAMPLES[resultPosition]);
|
|
|
+ voiceToneBean.difference = String.valueOf(calculateFineTune(targetVoiceFrequencyValue, ALL_VOICE_SAMPLES[resultPosition]));
|
|
|
return voiceToneBean;
|
|
|
}
|
|
|
|
|
|
+ private double calculateFineTune(float currentHz, double targetHz) {
|
|
|
+// double result = 1200 * Math.log(currentHz / REF_FREQ) / LOG_TWO;
|
|
|
+ double v = log2(currentHz / targetHz);
|
|
|
+ double result = v * 1200;
|
|
|
+ LOG.i("pq", "calculateFineTune result:" + result);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private double log2(double n) {
|
|
|
+ return Math.log(n) / Math.log(2);
|
|
|
+ }
|
|
|
+
|
|
|
private int getBeforePosition(int pos) {
|
|
|
if (pos < 0) {
|
|
|
pos = 0;
|