Skip to content

Commit

Permalink
Merge branch 'release/0.8.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
chihiro hashimoto committed Nov 7, 2017
2 parents 883944d + 8bd57bf commit ff18af4
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/chrhsmt/sisheng/FirstScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/chrhsmt/sisheng/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ object Settings {
var baseLogarithmForPoint: Int = 5
// ポイント成功閾値
var pointSuccessThreshold: Int = 80
// ノイズのバッファカウントの閾値
var freqNoizeCountThreashold: Int = 2

// Raspberry pi
var raspberrypiHost: String = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
45 changes: 45 additions & 0 deletions app/src/main/java/com/chrhsmt/sisheng/point/PointCalculator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -91,6 +92,50 @@ abstract class PointCalculator {

}

/**
* Removing noises.
* @freqList List of frequency
*/
fun removeNoises(freqList: MutableList<Float>) {

val noizeMaxLength = Settings.freqNoizeCountThreashold
val freqSize = freqList.size
val noizeIndexList: MutableList<Int> = 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<Float>, exampleFrequencies: List<Float>): TimeWarpInfo {

// chronix.fastdtw
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ open class SimplePointCalculator : PointCalculator() {
override fun calc(frequencies: MutableList<Float>, testFrequencies: MutableList<Float>): Point {

var analyzedFreqList: MutableList<Float> = this.copy(frequencies)
// 調整(男女差)
this.adjustFrequencies(analyzedFreqList)

// ノイズ除去
this.removeNoises(analyzedFreqList)

// 無音除去
analyzedFreqList = this.removeLastSilence(analyzedFreqList)
this.minimizeSilence(analyzedFreqList)
val exampleFrequencies = this.removeLastSilence(testFrequencies)
Expand Down

0 comments on commit ff18af4

Please sign in to comment.