Skip to content

Commit

Permalink
Improve random sensors mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Danand committed Mar 16, 2024
1 parent 7a2ae3d commit 338bebe
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,11 @@ class SignalProcessorSensors(private val sensorsState: MutableState<Sensors>) :
initRandomizedPhases()
}

private val initRandomizedMapping = {
Random.nextInt(0, this.sensorGetters.count())
private val mappingIndices: Array<Int> = Array(this.sensorGetters.count()) {
it
}

private val mapping: Array<Int> = Array(this.synths.count()) {
initRandomizedMapping()
}
private val mapping: IntArray = initializeMapping(this.synths.count(), mappingIndices)

private val sensorGetterMinValues = FloatArray(this.sensorGetters.count())

Expand Down Expand Up @@ -103,7 +101,7 @@ class SignalProcessorSensors(private val sensorsState: MutableState<Sensors>) :
)

if (angularSpeedMagnitude > 10) {
randomizeMapping(this.mapping, initRandomizedMapping)
randomizeMapping(this.mapping, this.mappingIndices)
}

val accelerationMagnitude = magnitude(
Expand Down Expand Up @@ -176,9 +174,17 @@ class SignalProcessorSensors(private val sensorsState: MutableState<Sensors>) :
return sampleValueTotal
}

private fun randomizeMapping(mapping: Array<Int>, init: () -> Int) {
private fun initializeMapping(amount: Int, mappingIndices: Array<Int>): IntArray {
val mapping = IntArray(amount)
randomizeMapping(mapping, mappingIndices)
return mapping
}

private fun randomizeMapping(mapping: IntArray, mappingIndices: Array<Int>) {
mappingIndices.shuffle()

for (index in mapping.indices) {
mapping[index] = init()
mapping[index] = mappingIndices[index]
}
}

Expand Down

0 comments on commit 338bebe

Please sign in to comment.