Skip to content

Commit

Permalink
Merge branch 'release/0.9.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
chihiro hashimoto committed Oct 4, 2018
2 parents 4dd9d5e + e4a576b commit 91712fd
Show file tree
Hide file tree
Showing 26 changed files with 1,279 additions and 43 deletions.
Binary file added .idea/caches/build_file_checksums.ser
Binary file not shown.
29 changes: 29 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ if (hasProperty("env")) {

android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
buildToolsVersion '28.0.2'
defaultConfig {
applicationId "com.chrhsmt.sisheng"
minSdkVersion 23
targetSdkVersion 26
versionCode 1
versionName "0.8.4"
versionCode 2
versionName "0.9.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// Enabling multidex support.
multiDexEnabled true
Expand All @@ -36,7 +36,7 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.0.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
Expand Down
16 changes: 15 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:largeHeap="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen">
<activity
android:name=".MainActivity"
Expand All @@ -29,6 +29,7 @@

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

</activity>
<activity
android:name=".ReibunActivity"
Expand All @@ -39,7 +40,20 @@
<activity
android:name=".ResultActivity"
android:screenOrientation="landscape" />
<activity
android:name=".debug.AnalyzeActivity"
android:label="@string/title_activity_analyze">
<!-- 初期画面の設定
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
-->
</activity>
<activity
android:name=".debug.CompareActivity"
android:screenOrientation="landscape" />
</application>

</manifest>
97 changes: 82 additions & 15 deletions app/src/main/java/com/chrhsmt/sisheng/AudioService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ class AudioService : AudioServiceInterface {
private val TAG: String = "AudioService"

private val activity: Activity
private val chart: Chart
private var chart: Chart? = null
private var audioDispatcher: AudioDispatcher? = null
private var analyzeThread: Thread? = null
private var isRunning: Boolean = false

private var frequencies: MutableList<Float> = ArrayList<Float>()
private var testFrequencies: MutableList<Float> = ArrayList<Float>()

constructor(chart: Chart, activity: Activity) {
constructor(chart: Chart?, activity: Activity) {
this.activity = activity
this.chart = chart
// Setting ffmpeg
Expand All @@ -70,7 +70,8 @@ class AudioService : AudioServiceInterface {
override fun startAudioRecord() {
// 既存データをクリア
this.frequencies.clear()
this.chart.clearDateSet(MICROPHONE_DATA_SET_LABEL_NAME)
this.chart?.clearDateSet(MICROPHONE_DATA_SET_LABEL_NAME)


// マイクロフォンバッファサイズの計算
val microphoneBufferSize = AudioRecord.getMinBufferSize(
Expand All @@ -87,18 +88,22 @@ class AudioService : AudioServiceInterface {
}

@SuppressLint("WrongConstant")
override fun testPlay(fileName: String, playback: Boolean, callback: Runnable?) {
override fun testPlay(fileName: String, path: String?, playback: Boolean, callback: Runnable?, async: Boolean, labelName: String) {

this.testFrequencies.clear()
this.chart.clear()
this.chart?.clear()

Thread(Runnable {
val run = Runnable {

val path = this.copyAudioFile(fileName)
val audioPath: String = if (path == null) {
this.copyAudioFile(fileName)
} else {
path
}

this.startRecord(
AudioDispatcherFactory.fromPipe(
path,
audioPath,
AUDIO_FILE_SAMPLING_RATE,
BUFFER_SIZE,
0
Expand All @@ -107,9 +112,38 @@ class AudioService : AudioServiceInterface {
playback = playback,
samplingRate = AUDIO_FILE_SAMPLING_RATE,
targetList = this.testFrequencies,
labelName = "SampleAudio",
labelName = labelName,
callback = callback
)
}
if (async) {
Thread(run).start()
} else {
run.run()
}

}

@SuppressLint("WrongConstant")
override fun debugTestPlay(fileName: String, path: String, playback: Boolean, callback: Runnable?) {

Thread(Runnable {

this.startRecord(
AudioDispatcherFactory.fromPipe(
path,
AUDIO_FILE_SAMPLING_RATE,
BUFFER_SIZE,
0
),
false,
playback = playback,
samplingRate = AUDIO_FILE_SAMPLING_RATE,
targetList = this.frequencies,
labelName = "RecordedSampleAudio",
callback = callback,
color = Color.rgb(255, 10, 10)
)
}).start()

}
Expand Down Expand Up @@ -161,6 +195,24 @@ class AudioService : AudioServiceInterface {
return point
}

@Throws(AudioServiceException::class)
fun analyze(calculator: PointCalculator) : Point {
val point = calculator.calc(this.frequencies, this.testFrequencies)
if (point.base <= this.testFrequencies.size) {
// 録音が失敗している場合
throw AudioServiceException("不好意思,我听不懂")
}
return point
}

override fun clearTestFrequencies() {
this.testFrequencies.clear()
}

override fun clearFrequencies() {
this.frequencies.clear()
}

override fun clear() {
this.frequencies.clear()
this.testFrequencies.clear()
Expand Down Expand Up @@ -210,7 +262,7 @@ class AudioService : AudioServiceInterface {
}
}
this@AudioService.activity.runOnUiThread {
chart.addEntry(pitch, name = labelName, color = color)
chart?.addEntry(pitch, name = labelName, color = color)
}
}
}
Expand All @@ -228,10 +280,15 @@ class AudioService : AudioServiceInterface {

if (shouldRecord) {
ExternalMedia.saveDir?.takeIf { it -> it.canWrite() }?.let { it ->
val dateString = SimpleDateFormat("yyyy-MM-dd_HH_mm_ss").format(Date())
val id = Regex("^mfsz/(\\d)_[f|m].wav$").find(Settings.sampleAudioFileName!!)?.groups?.last()?.value
val dateString = SimpleDateFormat("yyyy-MM-dd").format(Date())
val directory = File(it, dateString)
if (!directory.isDirectory) {
directory.mkdir()
}
val dateTimeString = SimpleDateFormat("yyyy-MM-dd_HH_mm_ss").format(Date())
val id = Regex("^mfsz/(\\d+)_[f|m].wav$").find(Settings.sampleAudioFileName!!)?.groups?.last()?.value
val sex = Settings.sex!!.first().toLowerCase()
val newFile = File(it, String.format("%s-%s-%s.wav", dateString, id, sex))
val newFile = File(directory, String.format("%s-%s-%s.wav", dateTimeString, id, sex))
val format = TarsosDSPAudioFormat(AUDIO_FILE_SAMPLING_RATE.toFloat(), 16, 1, true, false)
val writeProcessor: AudioProcessor = WriterProcessor(format, RandomAccessFile(newFile, "rw"))
dispatcher.addAudioProcessor(writeProcessor)
Expand All @@ -255,8 +312,8 @@ class AudioService : AudioServiceInterface {
}

private fun stopRecord() {
this.audioDispatcher!!.stop()
this.analyzeThread!!.interrupt()
this.audioDispatcher?.stop()
this.analyzeThread?.interrupt()
this.isRunning = false
this@AudioService.activity.runOnUiThread {
this.activity.button?.text = "開始"
Expand Down Expand Up @@ -291,4 +348,14 @@ class AudioService : AudioServiceInterface {

return path
}

fun getTestFreq(): MutableList<Float> {
return this.testFrequencies
}

fun addOtherChart(freqs: MutableList<Float>?, labelName: String, color: Int) {
freqs?.forEach { fl ->
chart?.addEntry(fl, name = labelName, color = color)
}
}
}
10 changes: 9 additions & 1 deletion app/src/main/java/com/chrhsmt/sisheng/AudioServiceInterface.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@ import com.chrhsmt.sisheng.point.Point
*/
interface AudioServiceInterface {
fun startAudioRecord()
fun testPlay(fileName: String, playback: Boolean = true, callback: Runnable? = null)
fun testPlay(fileName: String,
path: String? = null,
playback: Boolean = true,
callback: Runnable? = null,
async: Boolean = true,
labelName: String = "SampleAudio")
fun debugTestPlay(fileName: String, path: String, playback: Boolean = false, callback: Runnable?)
fun attemptPlay(fileName: String)
fun stop()
fun analyze() : Point
fun analyze(klassName: String) : Point
fun clear()
fun clearTestFrequencies()
fun clearFrequencies()
fun isRunning(): Boolean
}
17 changes: 15 additions & 2 deletions app/src/main/java/com/chrhsmt/sisheng/AudioServiceMock.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.chrhsmt.sisheng.ui.Chart
* Created by hkimura on 2017/10/30.
*/
class AudioServiceMock : AudioServiceInterface {

private val TAG: String = "AudioServiceMock"

private val activity: Activity
Expand All @@ -26,10 +27,13 @@ class AudioServiceMock : AudioServiceInterface {
// NOP
}

override fun testPlay(fileName: String, playback: Boolean, callback: Runnable?) {
override fun testPlay(fileName: String, path: String?, playback: Boolean, callback: Runnable?, async: Boolean, labelName: String) {
this.isRunning = true
}

override fun debugTestPlay(fileName: String, path: String, playback: Boolean, callback: Runnable?) {
}

override fun attemptPlay(fileName: String) {
this.isRunning = true
}
Expand All @@ -53,13 +57,22 @@ class AudioServiceMock : AudioServiceInterface {
80,
5.0,
5.0,
1)
1,
null)
}

override fun clear() {
// NOP
}

override fun clearFrequencies() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}

override fun clearTestFrequencies() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}

override fun isRunning(): Boolean {
return this.isRunning
}
Expand Down
Loading

0 comments on commit 91712fd

Please sign in to comment.