mirror of
https://github.com/kavishdevar/librepods.git
synced 2026-04-21 13:42:03 +00:00
"clean up" ai comments - will redocument later
This commit is contained in:
@@ -79,9 +79,6 @@ class GestureDetector(
|
|||||||
while (verticalAvgBuffer.size < 3) verticalAvgBuffer.add(0.0)
|
while (verticalAvgBuffer.size < 3) verticalAvgBuffer.add(0.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Start head gesture detection
|
|
||||||
*/
|
|
||||||
fun startDetection(doNotStop: Boolean = false, onGestureDetected: (Boolean) -> Unit) {
|
fun startDetection(doNotStop: Boolean = false, onGestureDetected: (Boolean) -> Unit) {
|
||||||
if (isRunning) return
|
if (isRunning) return
|
||||||
|
|
||||||
@@ -123,9 +120,6 @@ class GestureDetector(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Stop head gesture detection
|
|
||||||
*/
|
|
||||||
fun stopDetection(doNotStop: Boolean = false) {
|
fun stopDetection(doNotStop: Boolean = false) {
|
||||||
if (!isRunning) return
|
if (!isRunning) return
|
||||||
|
|
||||||
@@ -139,9 +133,6 @@ class GestureDetector(
|
|||||||
gestureDetectedCallback = null
|
gestureDetectedCallback = null
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Process head orientation data received from AirPods
|
|
||||||
*/
|
|
||||||
@RequiresApi(Build.VERSION_CODES.R)
|
@RequiresApi(Build.VERSION_CODES.R)
|
||||||
fun processHeadOrientation(horizontal: Int, vertical: Int) {
|
fun processHeadOrientation(horizontal: Int, vertical: Int) {
|
||||||
if (!isRunning) return
|
if (!isRunning) return
|
||||||
@@ -192,9 +183,6 @@ class GestureDetector(
|
|||||||
detectPeaksAndTroughs()
|
detectPeaksAndTroughs()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply moving average smoothing
|
|
||||||
*/
|
|
||||||
private fun applySmoothing(newValue: Double, buffer: MutableList<Double>): Double {
|
private fun applySmoothing(newValue: Double, buffer: MutableList<Double>): Double {
|
||||||
synchronized(buffer) {
|
synchronized(buffer) {
|
||||||
buffer.add(newValue)
|
buffer.add(newValue)
|
||||||
@@ -203,9 +191,7 @@ class GestureDetector(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Detect motion direction changes
|
|
||||||
*/
|
|
||||||
private fun detectPeaksAndTroughs() {
|
private fun detectPeaksAndTroughs() {
|
||||||
if (horizontalBuffer.size < 4 || verticalBuffer.size < 4) return
|
if (horizontalBuffer.size < 4 || verticalBuffer.size < 4) return
|
||||||
|
|
||||||
@@ -231,9 +217,6 @@ class GestureDetector(
|
|||||||
)?.let { verticalIncreasing = it }
|
)?.let { verticalIncreasing = it }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Process direction changes and detect peaks/troughs
|
|
||||||
*/
|
|
||||||
private fun processDirectionChanges(
|
private fun processDirectionChanges(
|
||||||
buffer: List<Double>,
|
buffer: List<Double>,
|
||||||
isIncreasing: Boolean?,
|
isIncreasing: Boolean?,
|
||||||
@@ -297,9 +280,6 @@ class GestureDetector(
|
|||||||
return increasing
|
return increasing
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculate variance of a list of values
|
|
||||||
*/
|
|
||||||
private fun calculateVariance(values: List<Double>): Double {
|
private fun calculateVariance(values: List<Double>): Double {
|
||||||
if (values.size <= 1) return 0.0
|
if (values.size <= 1) return 0.0
|
||||||
|
|
||||||
@@ -308,9 +288,7 @@ class GestureDetector(
|
|||||||
return squaredDiffs.average()
|
return squaredDiffs.average()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculate how consistent the timing between peaks is
|
|
||||||
*/
|
|
||||||
private fun calculateRhythmConsistency(): Double {
|
private fun calculateRhythmConsistency(): Double {
|
||||||
if (peakIntervals.size < 2) return 0.0
|
if (peakIntervals.size < 2) return 0.0
|
||||||
|
|
||||||
@@ -322,9 +300,7 @@ class GestureDetector(
|
|||||||
return max(0.0, consistency)
|
return max(0.0, consistency)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculate confidence score for gesture detection
|
|
||||||
*/
|
|
||||||
private fun calculateConfidenceScore(extremes: List<Triple<Int, Double, Long>>, isVertical: Boolean): Double {
|
private fun calculateConfidenceScore(extremes: List<Triple<Int, Double, Long>>, isVertical: Boolean): Double {
|
||||||
if (extremes.size < getRequiredExtremes()) return 0.0
|
if (extremes.size < getRequiredExtremes()) return 0.0
|
||||||
|
|
||||||
@@ -361,11 +337,6 @@ class GestureDetector(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculate the required number of extremes based on movement speed
|
|
||||||
* - Fast movements (short intervals) require more evidence (5 extremes)
|
|
||||||
* - Slow, deliberate movements need fewer evidence points (3 extremes)
|
|
||||||
*/
|
|
||||||
private fun getRequiredExtremes(): Int {
|
private fun getRequiredExtremes(): Int {
|
||||||
if (movementSpeedIntervals.isEmpty()) return MIN_REQUIRED_EXTREMES
|
if (movementSpeedIntervals.isEmpty()) return MIN_REQUIRED_EXTREMES
|
||||||
|
|
||||||
@@ -379,9 +350,6 @@ class GestureDetector(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Detect gestures based on collected motion data
|
|
||||||
*/
|
|
||||||
private fun detectGestures(): Boolean? {
|
private fun detectGestures(): Boolean? {
|
||||||
val requiredExtremes = getRequiredExtremes()
|
val requiredExtremes = getRequiredExtremes()
|
||||||
Log.d(TAG, "Current required extremes: $requiredExtremes")
|
Log.d(TAG, "Current required extremes: $requiredExtremes")
|
||||||
@@ -415,9 +383,6 @@ class GestureDetector(
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Clear all buffers and tracking data
|
|
||||||
*/
|
|
||||||
private fun clearData() {
|
private fun clearData() {
|
||||||
horizontalBuffer.clear()
|
horizontalBuffer.clear()
|
||||||
verticalBuffer.clear()
|
verticalBuffer.clear()
|
||||||
@@ -434,8 +399,5 @@ class GestureDetector(
|
|||||||
lastSignificantMotionTime = 0L
|
lastSignificantMotionTime = 0L
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Extension function for power calculation
|
|
||||||
*/
|
|
||||||
private fun Double.pow(exponent: Int): Double = this.pow(exponent.toDouble())
|
private fun Double.pow(exponent: Int): Double = this.pow(exponent.toDouble())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,12 +15,6 @@ import androidx.annotation.RequiresApi
|
|||||||
import me.kavishdevar.aln.R
|
import me.kavishdevar.aln.R
|
||||||
import java.util.concurrent.atomic.AtomicBoolean
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
|
|
||||||
/**
|
|
||||||
* Audio feedback for head gestures using efficient SoundPool API
|
|
||||||
* - Simple audio cues for direction
|
|
||||||
* - Strict channel separation for clarity
|
|
||||||
* - Optimized for low latency
|
|
||||||
*/
|
|
||||||
@RequiresApi(Build.VERSION_CODES.Q)
|
@RequiresApi(Build.VERSION_CODES.Q)
|
||||||
class GestureFeedback(private val context: Context) {
|
class GestureFeedback(private val context: Context) {
|
||||||
|
|
||||||
@@ -115,10 +109,6 @@ class GestureFeedback(private val context: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Play directional feedback sound with appropriate channel separation
|
|
||||||
* Optimized for minimal latency
|
|
||||||
*/
|
|
||||||
@RequiresApi(Build.VERSION_CODES.R)
|
@RequiresApi(Build.VERSION_CODES.R)
|
||||||
fun playDirectional(isVertical: Boolean, value: Double) {
|
fun playDirectional(isVertical: Boolean, value: Double) {
|
||||||
if (!soundsLoaded.get()) {
|
if (!soundsLoaded.get()) {
|
||||||
@@ -197,9 +187,6 @@ class GestureFeedback(private val context: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Play confirmation sound for completed gesture
|
|
||||||
*/
|
|
||||||
fun playConfirmation(isYes: Boolean) {
|
fun playConfirmation(isYes: Boolean) {
|
||||||
if (currentHorizontalStreamId > 0) {
|
if (currentHorizontalStreamId > 0) {
|
||||||
soundPool.stop(currentHorizontalStreamId)
|
soundPool.stop(currentHorizontalStreamId)
|
||||||
@@ -215,9 +202,6 @@ class GestureFeedback(private val context: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Clean up resources
|
|
||||||
*/
|
|
||||||
fun release() {
|
fun release() {
|
||||||
try {
|
try {
|
||||||
soundPool.release()
|
soundPool.release()
|
||||||
|
|||||||
Reference in New Issue
Block a user