mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-19 07:15:25 +02:00
commit
b12aeaeec8
@ -9,7 +9,7 @@ import java.util.concurrent.Executors
|
|||||||
import java.util.concurrent.ScheduledExecutorService
|
import java.util.concurrent.ScheduledExecutorService
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
abstract class ExtraRecorderInformationService: RecorderService() {
|
abstract class ExtraRecorderInformationService : RecorderService() {
|
||||||
abstract fun getAmplitudeAmount(): Int
|
abstract fun getAmplitudeAmount(): Int
|
||||||
abstract fun getAmplitude(): Int
|
abstract fun getAmplitude(): Int
|
||||||
|
|
||||||
@ -30,7 +30,11 @@ abstract class ExtraRecorderInformationService: RecorderService() {
|
|||||||
|
|
||||||
// Delete old amplitudes
|
// Delete old amplitudes
|
||||||
if (amplitudes.size > getAmplitudeAmount()) {
|
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)
|
handler.postDelayed(::updateAmplitude, 100)
|
||||||
|
@ -38,7 +38,7 @@ fun RealtimeAudioVisualizer(
|
|||||||
audioRecorder: AudioRecorderModel,
|
audioRecorder: AudioRecorderModel,
|
||||||
) {
|
) {
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
val amplitudes = audioRecorder.amplitudes!!
|
val amplitudes = audioRecorder.amplitudes
|
||||||
val primary = MaterialTheme.colorScheme.primary
|
val primary = MaterialTheme.colorScheme.primary
|
||||||
val primaryMuted = primary.copy(alpha = 0.3f)
|
val primaryMuted = primary.copy(alpha = 0.3f)
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ fun RealtimeAudioVisualizer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val configuration = LocalConfiguration.current
|
val configuration = LocalConfiguration.current
|
||||||
val screenWidth = with (LocalDensity.current) {configuration.screenWidthDp.dp.toPx()}
|
val screenWidth = with(LocalDensity.current) { configuration.screenWidthDp.dp.toPx() }
|
||||||
|
|
||||||
LaunchedEffect(screenWidth) {
|
LaunchedEffect(screenWidth) {
|
||||||
// Add 1 to allow the visualizer to overflow the screen
|
// Add 1 to allow the visualizer to overflow the screen
|
||||||
@ -88,7 +88,8 @@ fun RealtimeAudioVisualizer(
|
|||||||
clamp(horizontalValue, GROW_START, GROW_END)
|
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 amplitudePercentage = (amplitude.toFloat() / MAX_AMPLITUDE).coerceAtMost(1f)
|
||||||
val boxHeight = (height * amplitudePercentage * horizontalProgress).coerceAtLeast(15f)
|
val boxHeight =
|
||||||
|
(height * amplitudePercentage * horizontalProgress).coerceAtLeast(15f)
|
||||||
|
|
||||||
drawRoundRect(
|
drawRoundRect(
|
||||||
color = if (amplitudePercentage > 0.05f && isOverThreshold) primary else primaryMuted,
|
color = if (amplitudePercentage > 0.05f && isOverThreshold) primary else primaryMuted,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user