INNER CODE UNIT · Kotlin
normalizedAmplitude
Ayush0Chaudhary/blurr · app/src/main/java/com/blurr/voice/AudioWaveView.kt:98
val normalizedAmplitude = ((rmsdB - MIN_DB_VALUE) / (MAX_DB_VALUE - MIN_DB_VALUE)).coerceIn(0f, 2.0f)
// Call the existing method to update the wave's appearance
setRealtimeAmplitude(normalizedAmplitude)
}
/**
* Instantly sets the amplitude for real-time visualization.
* @param amplitude The raw amplitude from the visualizer (0.0 to 1.0).
*/
fun setRealtimeAmplitude(amplitude: Float) {
val scaledAmplitude = amplitude.pow(1.5f).coerceIn(0.0f, 1.0f)
val targetAmplitude = minIdleAmplitude + (scaledAmplitude * maxWaveHeightScale)
amplitudeAnimator?.cancel()
amplitudeAnimator = ValueAnimator.ofFloat(audioAmplitude, targetAmplitude).apply {
duration = realtimeAmplitudeTransitionDuration // Use short duration for responsiveness
interpolator = AccelerateDecelerateInterpolator()