diff --git a/app/build.gradle b/app/build.gradle index c17931d..564954f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -21,7 +21,7 @@ android { minSdkVersion 23 targetSdkVersion 26 versionCode 1 - versionName "0.8.0" + versionName "0.8.1" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" // Enabling multidex support. multiDexEnabled true diff --git a/app/src/main/java/com/chrhsmt/sisheng/FirstScreen.kt b/app/src/main/java/com/chrhsmt/sisheng/FirstScreen.kt index 05e4e7f..37fd4f2 100644 --- a/app/src/main/java/com/chrhsmt/sisheng/FirstScreen.kt +++ b/app/src/main/java/com/chrhsmt/sisheng/FirstScreen.kt @@ -130,7 +130,7 @@ class FirstScreen : AppCompatActivity() { private fun setUpReadWriteExternalStorage() { val dir = ExternalMedia.getExternalDirectoryPath(this) - if (ExternalMedia.isExternalStorageWritable() && dir.canWrite()) { + if (ExternalMedia.isExternalStorageWritable() && dir != null && dir!!.canWrite()) { Toast.makeText(this, "SDカードへの書き込みが可能です", Toast.LENGTH_SHORT).show() Log.d(TAG, String.format("External media path: %s", dir.absoluteFile)) } else { diff --git a/app/src/main/java/com/chrhsmt/sisheng/Settings.kt b/app/src/main/java/com/chrhsmt/sisheng/Settings.kt index f328def..de53b48 100644 --- a/app/src/main/java/com/chrhsmt/sisheng/Settings.kt +++ b/app/src/main/java/com/chrhsmt/sisheng/Settings.kt @@ -21,6 +21,8 @@ object Settings { var baseLogarithmForPoint: Int = 5 // ポイント成功閾値 var pointSuccessThreshold: Int = 80 + // ノイズのバッファカウントの閾値 + var freqNoizeCountThreashold: Int = 2 // Raspberry pi var raspberrypiHost: String = "" diff --git a/app/src/main/java/com/chrhsmt/sisheng/persistence/ExternalMedia.kt b/app/src/main/java/com/chrhsmt/sisheng/persistence/ExternalMedia.kt index 4851ec9..54a0210 100644 --- a/app/src/main/java/com/chrhsmt/sisheng/persistence/ExternalMedia.kt +++ b/app/src/main/java/com/chrhsmt/sisheng/persistence/ExternalMedia.kt @@ -24,12 +24,16 @@ object ExternalMedia { return Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state) } - fun getExternalDirectoryPath(context: Context): File { + fun getExternalDirectoryPath(context: Context): File? { val dirs = context.getExternalFilesDirs(android.os.Environment.DIRECTORY_MUSIC) if (dirs.size >= 2 && !dirs.last().mkdirs()) { Log.e(TAG, "Directory not created"); } - this.saveDir = dirs.last() - return dirs.last() + if (dirs.size > 1) { + this.saveDir = dirs.last() + return dirs.last() + } else { + return null + } } } \ No newline at end of file diff --git a/app/src/main/java/com/chrhsmt/sisheng/point/PointCalculator.kt b/app/src/main/java/com/chrhsmt/sisheng/point/PointCalculator.kt index f399b32..c3a659f 100644 --- a/app/src/main/java/com/chrhsmt/sisheng/point/PointCalculator.kt +++ b/app/src/main/java/com/chrhsmt/sisheng/point/PointCalculator.kt @@ -8,6 +8,7 @@ import de.qaware.chronix.distance.DistanceFunctionFactory import de.qaware.chronix.dtw.FastDTW import de.qaware.chronix.dtw.TimeWarpInfo import de.qaware.chronix.timeseries.MultivariateTimeSeries +import java.util.* /** * Created by chihiro on 2017/10/10. @@ -91,6 +92,50 @@ abstract class PointCalculator { } + /** + * Removing noises. + * @freqList List of frequency + */ + fun removeNoises(freqList: MutableList) { + + val noizeMaxLength = Settings.freqNoizeCountThreashold + val freqSize = freqList.size + val noizeIndexList: MutableList = arrayListOf() + + // 反転したListのインスタンスでループ + freqList.reversed().forEachIndexed { index, fl -> + // 実Index + val realIndex = freqSize - 1 - index + + if (fl > 0) { + // ノイズ発見、indexにする + noizeIndexList.add(realIndex) + } + + if (noizeIndexList.size > noizeMaxLength) { + // ノイズ判定サイズを超えたものはノイズとみなさないのでクリアー + noizeIndexList.clear() + } + + if (fl <= 0) { + // 無音 + if (noizeIndexList.size <= noizeMaxLength) { + noizeIndexList.forEach { i -> + // 除去(後ろから) + freqList.removeAt(i) + } + } + noizeIndexList.clear() + } + + if (realIndex == 0 && noizeIndexList.isNotEmpty()) { + noizeIndexList.forEach { i -> + freqList.removeAt(i) + } + } + } + } + fun calcDistance(analyzedFreqList: List, exampleFrequencies: List): TimeWarpInfo { // chronix.fastdtw diff --git a/app/src/main/java/com/chrhsmt/sisheng/point/SimplePointCalculator.kt b/app/src/main/java/com/chrhsmt/sisheng/point/SimplePointCalculator.kt index 1ee776e..84060c4 100644 --- a/app/src/main/java/com/chrhsmt/sisheng/point/SimplePointCalculator.kt +++ b/app/src/main/java/com/chrhsmt/sisheng/point/SimplePointCalculator.kt @@ -14,8 +14,13 @@ open class SimplePointCalculator : PointCalculator() { override fun calc(frequencies: MutableList, testFrequencies: MutableList): Point { var analyzedFreqList: MutableList = this.copy(frequencies) + // 調整(男女差) this.adjustFrequencies(analyzedFreqList) + // ノイズ除去 + this.removeNoises(analyzedFreqList) + + // 無音除去 analyzedFreqList = this.removeLastSilence(analyzedFreqList) this.minimizeSilence(analyzedFreqList) val exampleFrequencies = this.removeLastSilence(testFrequencies)