mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-18 23:05:26 +02:00
fix: Properly limit amplitudes
This commit is contained in:
parent
8c45a863e7
commit
584f4fc216
@ -9,7 +9,7 @@ import java.util.concurrent.Executors
|
||||
import java.util.concurrent.ScheduledExecutorService
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
abstract class ExtraRecorderInformationService: RecorderService() {
|
||||
abstract class ExtraRecorderInformationService : RecorderService() {
|
||||
abstract fun getAmplitudeAmount(): Int
|
||||
abstract fun getAmplitude(): Int
|
||||
|
||||
@ -30,7 +30,11 @@ abstract class ExtraRecorderInformationService: RecorderService() {
|
||||
|
||||
// Delete old amplitudes
|
||||
if (amplitudes.size > getAmplitudeAmount()) {
|
||||
amplitudes.drop(amplitudes.size - getAmplitudeAmount())
|
||||
// Should be more efficient than dropping the elements, getting a new list
|
||||
// clearing old list and adding new elements to it
|
||||
repeat(amplitudes.size - getAmplitudeAmount()) {
|
||||
amplitudes.removeAt(0)
|
||||
}
|
||||
}
|
||||
|
||||
handler.postDelayed(::updateAmplitude, 100)
|
||||
|
@ -38,7 +38,7 @@ fun RealtimeAudioVisualizer(
|
||||
audioRecorder: AudioRecorderModel,
|
||||
) {
|
||||
val scope = rememberCoroutineScope()
|
||||
val amplitudes = audioRecorder.amplitudes!!
|
||||
val amplitudes = audioRecorder.amplitudes
|
||||
val primary = MaterialTheme.colorScheme.primary
|
||||
val primaryMuted = primary.copy(alpha = 0.3f)
|
||||
|
||||
@ -63,7 +63,7 @@ fun RealtimeAudioVisualizer(
|
||||
}
|
||||
|
||||
val configuration = LocalConfiguration.current
|
||||
val screenWidth = with (LocalDensity.current) {configuration.screenWidthDp.dp.toPx()}
|
||||
val screenWidth = with(LocalDensity.current) { configuration.screenWidthDp.dp.toPx() }
|
||||
|
||||
LaunchedEffect(screenWidth) {
|
||||
// Add 1 to allow the visualizer to overflow the screen
|
||||
@ -86,9 +86,10 @@ fun RealtimeAudioVisualizer(
|
||||
val isOverThreshold = offset >= GROW_START_INDEX
|
||||
val horizontalProgress = (
|
||||
clamp(horizontalValue, GROW_START, GROW_END)
|
||||
- GROW_START) / (GROW_END - GROW_START)
|
||||
- GROW_START) / (GROW_END - GROW_START)
|
||||
val amplitudePercentage = (amplitude.toFloat() / MAX_AMPLITUDE).coerceAtMost(1f)
|
||||
val boxHeight = (height * amplitudePercentage * horizontalProgress).coerceAtLeast(15f)
|
||||
val boxHeight =
|
||||
(height * amplitudePercentage * horizontalProgress).coerceAtLeast(15f)
|
||||
|
||||
drawRoundRect(
|
||||
color = if (amplitudePercentage > 0.05f && isOverThreshold) primary else primaryMuted,
|
||||
|
Loading…
x
Reference in New Issue
Block a user