mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-19 07:15:25 +02:00
fix: Store minimum amount of amplitudes to reduce memory
This commit is contained in:
parent
44a8193118
commit
2eb19ac5c4
@ -56,6 +56,7 @@ class RecorderService: Service() {
|
|||||||
private var onAmplitudeUpdate: () -> Unit = {}
|
private var onAmplitudeUpdate: () -> Unit = {}
|
||||||
|
|
||||||
private var counter = 0
|
private var counter = 0
|
||||||
|
var maxAmplitudes = 1000
|
||||||
|
|
||||||
var settings: Settings? = null
|
var settings: Settings? = null
|
||||||
private set
|
private set
|
||||||
@ -241,6 +242,11 @@ class RecorderService: Service() {
|
|||||||
val amplitude = mediaRecorder!!.maxAmplitude
|
val amplitude = mediaRecorder!!.maxAmplitude
|
||||||
amplitudes.add(amplitude)
|
amplitudes.add(amplitude)
|
||||||
|
|
||||||
|
// Delete old amplitudes
|
||||||
|
if (amplitudes.size > maxAmplitudes) {
|
||||||
|
amplitudes.removeRange(0, amplitudes.size - maxAmplitudes)
|
||||||
|
}
|
||||||
|
|
||||||
onAmplitudeUpdate()
|
onAmplitudeUpdate()
|
||||||
handler.postDelayed(::updateAmplitude, AMPLITUDE_UPDATE_INTERVAL)
|
handler.postDelayed(::updateAmplitude, AMPLITUDE_UPDATE_INTERVAL)
|
||||||
}
|
}
|
||||||
|
@ -16,11 +16,14 @@ import androidx.compose.ui.geometry.CornerRadius
|
|||||||
import androidx.compose.ui.geometry.Offset
|
import androidx.compose.ui.geometry.Offset
|
||||||
import androidx.compose.ui.geometry.Size
|
import androidx.compose.ui.geometry.Size
|
||||||
import androidx.compose.ui.graphics.drawscope.translate
|
import androidx.compose.ui.graphics.drawscope.translate
|
||||||
|
import androidx.compose.ui.platform.LocalConfiguration
|
||||||
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import app.myzel394.alibi.services.RecorderService
|
import app.myzel394.alibi.services.RecorderService
|
||||||
import app.myzel394.alibi.ui.MAX_AMPLITUDE
|
import app.myzel394.alibi.ui.MAX_AMPLITUDE
|
||||||
import app.myzel394.alibi.ui.utils.clamp
|
import app.myzel394.alibi.ui.utils.clamp
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlin.math.ceil
|
||||||
|
|
||||||
private const val BOX_WIDTH = 15f
|
private const val BOX_WIDTH = 15f
|
||||||
private const val BOX_GAP = 15f
|
private const val BOX_GAP = 15f
|
||||||
@ -58,6 +61,13 @@ fun RealtimeAudioVisualizer(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val configuration = LocalConfiguration.current
|
||||||
|
val screenWidth = with (LocalDensity.current) {configuration.screenWidthDp.dp.toPx()}
|
||||||
|
|
||||||
|
LaunchedEffect(screenWidth) {
|
||||||
|
service.maxAmplitudes = ceil(screenWidth.toInt() / BOX_DIFF).toInt()
|
||||||
|
}
|
||||||
|
|
||||||
Canvas(
|
Canvas(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user