This repository was archived by the owner on Sep 22, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +14
-12
lines changed
audiowave/src/main/kotlin/rm/com/audiowave Expand file tree Collapse file tree 2 files changed +14
-12
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,9 @@ dependencies {
2727 compile fileTree(dir : ' libs' , include : [' *.jar' ])
2828 compile " org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version "
2929 compile ' com.android.support:appcompat-v7:24.2.1'
30- compile ' com.github.alxrm:Audiogram:0.4'
30+ // compile 'com.github.alxrm:Audiogram:0.5'
31+
32+ compile project(' :audiowave' )
3133}
3234repositories {
3335 mavenCentral()
Original file line number Diff line number Diff line change @@ -25,29 +25,29 @@ object Sampler {
2525
2626 fun downSample (data : ByteArray , targetSize : Int ): ByteArray {
2727 val targetSized = ByteArray (targetSize, { 0 })
28- val reducedSample = mutableListOf<Byte >()
29-
3028 var prevDataIndex = 0
29+ var sampledPerChunk = 0F
30+ var sumPerChunk = 0F
3131
3232 if (targetSize >= data.size) {
3333 return targetSized.paste(data)
3434 }
3535
36- data.forEachIndexed { i, byte ->
37- val currentDataIndex = targetSize * i / data.size
36+ for (index in 0 .. data.size) {
37+ val currentDataIndex = targetSize * index / data.size
3838
3939 if (prevDataIndex == currentDataIndex) {
40- reducedSample + = byte.abs
40+ sampledPerChunk + = 1
41+ sumPerChunk + = data[index].abs
4142 } else {
42- targetSized[currentDataIndex - 1 ] = reducedSample.average().toByte()
43- reducedSample.clear()
44- }
43+ targetSized[prevDataIndex] = (sumPerChunk / sampledPerChunk).toByte()
4544
46- prevDataIndex = currentDataIndex
45+ sumPerChunk = 0F
46+ sampledPerChunk = 0F
47+ prevDataIndex = currentDataIndex
48+ }
4749 }
4850
49- targetSized[prevDataIndex] = reducedSample.average().toByte()
50-
5151 return targetSized
5252 }
5353}
You can’t perform that action at this time.
0 commit comments