Bladeren bron

添加调音器音分值计算公式

Pq 1 jaar geleden
bovenliggende
commit
198e929027

+ 8 - 1
musictuner/src/main/java/com/cooleshow/musictuner/MusicTunerActivity.java

@@ -159,7 +159,14 @@ public class MusicTunerActivity extends BaseActivity<ActivityMusicTunerLayoutBin
     private long getDifferenceText(String diff) {
         try {
             double aDouble = Double.valueOf(diff);
-            return Math.round(aDouble);
+            long round = Math.round(aDouble);
+            if (round > 50) {
+                round = 50;
+            }
+            if (round < -50) {
+                round = -50;
+            }
+            return round;
         } catch (Exception e) {
             e.printStackTrace();
         }

+ 1 - 1
musictuner/src/main/java/com/cooleshow/musictuner/constants/MusicTunerConstants.java

@@ -17,5 +17,5 @@ public class MusicTunerConstants {
             "B♭", "C", "F",
             "B♭", "C", "B♭"};
 
-    public final static int CORRECT_VALUE_RANGE =3;//音频值差值正确值范围
+    public final static int CORRECT_VALUE_RANGE =10;//音频值差值正确值范围
 }

+ 15 - 1
musictuner/src/main/java/com/cooleshow/musictuner/utils/VoiceDataUtils.java

@@ -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;