srctree

Robin Linden parent be323a80 fb90e3ad
Fix audio frame lengths not being the same everywhere

inlinesplit
domain/src/main/kotlin/av/AudioCapture.kt added: 8, removed: 6, total 2
@@ -46,21 +46,22 @@ private fun findAudioRecord(sampleRate: Int, channels: Int): AudioRecord? {
class AudioCapture private constructor(
private val sampleRate: Int,
private val channels: Int,
private val frameLengthMs: Int,
private val audioRecord: AudioRecord,
) {
fun start() = audioRecord.startRecording()
fun stop() = audioRecord.stop()
fun release() = audioRecord.release()
fun read(): ShortArray {
val bytes = ShortArray((sampleRate * channels * 0.1).toInt()) // E.g. 16-bit, 48kHz, 1 channel, 100ms
val bytes = ShortArray((sampleRate * channels * frameLengthMs / 1000.0).toInt())
audioRecord.read(bytes, 0, bytes.size)
return bytes
}
 
companion object {
fun create(sampleRate: Int, channels: Int): AudioCapture? {
fun create(sampleRate: Int, channels: Int, frameLengthMs: Int): AudioCapture? {
val audioRecord = findAudioRecord(sampleRate, channels) ?: return null
return AudioCapture(sampleRate, channels, audioRecord)
return AudioCapture(sampleRate, channels, frameLengthMs, audioRecord)
}
}
}
 
domain/src/main/kotlin/feature/CallManager.kt added: 8, removed: 6, total 2
@@ -71,7 +71,8 @@ class CallManager @Inject constructor(
 
fun startSendingAudio(): Boolean {
val to = (inCall.value as CallState.InCall?)?.publicKey ?: return false
val recorder = AudioCapture.create(AUDIO_SAMPLING_RATE_HZ, AUDIO_CHANNELS) ?: return false
val recorder =
AudioCapture.create(AUDIO_SAMPLING_RATE_HZ, AUDIO_CHANNELS, AUDIO_SEND_INTERVAL_MS) ?: return false
startAudioSender(recorder, to)
return true
}